feat: pgid support
[lunaix-os.git] / lunaix-os / includes / lunaix / process.h
1 #ifndef __LUNAIX_PROCESS_H
2 #define __LUNAIX_PROCESS_H
3
4 #include <arch/x86/interrupts.h>
5 #include <lunaix/clock.h>
6 #include <lunaix/mm/mm.h>
7 #include <lunaix/timer.h>
8 #include <lunaix/types.h>
9 #include <stdint.h>
10
11 // 虽然内核不是进程,但为了区分,这里使用Pid=-1来指代内核。这主要是方便物理页所有权检查。
12 #define KERNEL_PID -1
13
14 #define PROC_STOPPED 0
15 #define PROC_RUNNING 1
16 #define PROC_TERMNAT 2
17 #define PROC_DESTROY 4
18 #define PROC_BLOCKED 8
19 #define PROC_CREATED 16
20
21 #define PROC_TERMMASK 0x6
22
23 struct proc_mm
24 {
25     heap_context_t u_heap;
26     struct mm_region* regions;
27 };
28
29 struct proc_info
30 {
31     pid_t pid;
32     struct proc_info* parent;
33     isr_param intr_ctx;
34     struct llist_header siblings;
35     struct llist_header children;
36     struct llist_header grp_member;
37     struct proc_mm mm;
38     void* page_table;
39     time_t created;
40     uint8_t state;
41     int32_t exit_code;
42     int32_t k_status;
43     pid_t pgid;
44     struct lx_timer* timer;
45 };
46
47 extern volatile struct proc_info* __current;
48
49 pid_t
50 alloc_pid();
51
52 void
53 init_proc(struct proc_info* pcb);
54
55 /**
56  * @brief 向系统发布一个进程,使其可以被调度。
57  *
58  * @param process
59  */
60 void
61 push_process(struct proc_info* process);
62
63 pid_t
64 destroy_process(pid_t pid);
65
66 void
67 setup_proc_mem(struct proc_info* proc, uintptr_t kstack_from);
68
69 /**
70  * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
71  *
72  */
73 pid_t
74 dup_proc();
75
76 /**
77  * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
78  *
79  */
80 void
81 new_proc();
82
83 /**
84  * @brief 终止(退出)当前进程
85  *
86  */
87 void
88 terminate_proc(int exit_code);
89
90 int
91 orphaned_proc(pid_t pid);
92
93 struct proc_info*
94 get_process(pid_t pid);
95
96 #endif /* __LUNAIX_PROCESS_H */