1 #ifndef __LUNAIX_PROCESS_H
2 #define __LUNAIX_PROCESS_H
4 #include <arch/x86/interrupts.h>
5 #include <lunaix/clock.h>
6 #include <lunaix/ds/waitq.h>
8 #include <lunaix/mm/mm.h>
9 #include <lunaix/signal.h>
10 #include <lunaix/timer.h>
11 #include <lunaix/types.h>
14 // 虽然内核不是进程,但为了区分,这里使用Pid=-1来指代内核。这主要是方便物理页所有权检查。
24 #define PROC_TERMINATED(state) (state & 0x6)
26 #define PROC_FINPAUSE 1
30 heap_context_t u_heap;
31 struct mm_region regions;
37 char fxstate[512] __attribute__((aligned(16)));
44 struct proc_sigstate prev_context;
45 } __attribute__((packed));
50 Any change to *critical section*, including layout, size
51 must be reflected in kernel/asm/x86/interrupt.S to avoid
55 /* ---- critical section start ---- */
57 pid_t pid; // offset = 0
58 struct proc_info* parent; // offset = 4
59 isr_param intr_ctx; // offset = 8
60 uintptr_t ustack_top; // offset = 84
61 void* page_table; // offset = 88
62 void* fxstate; // offset = 92
64 /* ---- critical section end ---- */
66 struct llist_header tasks;
67 struct llist_header siblings;
68 struct llist_header children;
69 struct llist_header grp_member;
74 struct llist_header sleepers;
86 sigset_t sig_inprogress;
88 void* sig_handler[_SIG_NUM];
89 struct v_fdtable* fdtable;
94 extern volatile struct proc_info* __current;
97 * @brief 分配并初始化一个进程控制块
99 * @return struct proc_info*
110 init_proc_user_space(struct proc_info* pcb);
113 * @brief 向系统发布一个进程,使其可以被调度。
118 commit_process(struct proc_info* process);
121 destroy_process(pid_t pid);
124 setup_proc_mem(struct proc_info* proc, uintptr_t kstack_from);
127 * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
134 * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
145 terminate_proc(int exit_code);
148 orphaned_proc(pid_t pid);
151 get_process(pid_t pid);
153 #endif /* __LUNAIX_PROCESS_H */