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/mm/region.h>
10 #include <lunaix/signal.h>
11 #include <lunaix/timer.h>
12 #include <lunaix/types.h>
15 // 虽然内核不是进程,但为了区分,这里使用Pid=-1来指代内核。这主要是方便物理页所有权检查。
23 Group Dt: whether this process is terminated.
41 #define PS_GrBP (PS_PAUSED | PS_BLOCKED)
42 #define PS_GrDT (PS_TERMNAT | PS_DESTROY)
44 #define PROC_TERMINATED(state) ((state)&PS_GrDT)
45 #define PROC_HANGED(state) ((state)&PS_BLOCKED)
46 #define PROC_RUNNABLE(state) ((state)&PS_PAUSED)
48 #define PROC_FINPAUSE 1
53 char fxstate[512] __attribute__((aligned(16)));
69 struct sigact* inprogress;
70 struct sigact signals[_SIG_NUM];
78 struct proc_sigstate prev_context;
79 } __attribute__((packed));
84 Any change to *critical section*, including layout, size
85 must be reflected in kernel/asm/x86/interrupt.S to avoid
89 /* ---- critical section start ---- */
91 pid_t pid; // offset = 0
92 struct proc_info* parent; // offset = 4
93 isr_param* intr_ctx; // offset = 8
94 ptr_t ustack_top; // offset = 84 -> 56 -> 60 -> 12
95 ptr_t page_table; // offset = 88 -> 60 -> 64 -> 16
96 void* fxstate; // offset = 92 -> 64 -> 68 -> 20
98 /* ---- critical section end ---- */
100 struct llist_header tasks;
101 struct llist_header siblings;
102 struct llist_header children;
103 struct llist_header grp_member;
108 struct llist_header sleepers;
119 struct sighail sigctx;
120 struct v_fdtable* fdtable;
125 extern volatile struct proc_info* __current;
130 __current->state = PS_BLOCKED;
136 __current->state = PS_PAUSED;
142 __current->state = PS_RUNNING;
146 * @brief 分配并初始化一个进程控制块
148 * @return struct proc_info*
159 init_proc_user_space(struct proc_info* pcb);
162 * @brief 向系统发布一个进程,使其可以被调度。
167 commit_process(struct proc_info* process);
170 destroy_process(pid_t pid);
173 copy_kernel_stack(struct proc_info* proc, ptr_t kstack_from);
176 * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
183 * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
194 terminate_proc(int exit_code);
197 orphaned_proc(pid_t pid);
200 get_process(pid_t pid);
203 proc_setsignal(struct proc_info* proc, int signum);
205 #endif /* __LUNAIX_PROCESS_H */