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(proc) (((proc)->state) & PS_GrDT)
45 #define proc_hanged(proc) (((proc)->state) & PS_BLOCKED)
46 #define proc_runnable(proc) (((proc)->state) & PS_PAUSED)
48 #define PROC_FINPAUSE 1
63 struct sigact* inprogress;
64 struct sigact signals[_SIG_NUM];
72 isr_param* saved_ictx;
73 } __attribute__((packed));
78 Any change to *critical section*, including layout, size
79 must be reflected in kernel/asm/x86/interrupt.S to avoid
83 /* ---- critical section start ---- */
85 pid_t pid; // offset = 0
86 struct proc_info* parent; // offset = 4
87 isr_param* intr_ctx; // offset = 8
88 ptr_t ustack_top; // offset = 84 -> 56 -> 60 -> 12
89 ptr_t page_table; // offset = 88 -> 60 -> 64 -> 16
91 /* ---- critical section end ---- */
93 struct llist_header tasks;
94 struct llist_header siblings;
95 struct llist_header children;
96 struct llist_header grp_member;
101 struct llist_header sleepers;
112 struct sighail sigctx;
113 struct v_fdtable* fdtable;
118 extern volatile struct proc_info* __current;
123 __current->state = PS_BLOCKED;
129 __current->state = PS_PAUSED;
135 __current->state = PS_RUNNING;
139 * @brief 分配并初始化一个进程控制块
141 * @return struct proc_info*
152 init_proc_user_space(struct proc_info* pcb);
155 * @brief 向系统发布一个进程,使其可以被调度。
160 commit_process(struct proc_info* process);
163 destroy_process(pid_t pid);
166 copy_kernel_stack(struct proc_info* proc, ptr_t kstack_from);
169 * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
176 * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
187 terminate_proc(int exit_code);
190 orphaned_proc(pid_t pid);
193 get_process(pid_t pid);
196 proc_setsignal(struct proc_info* proc, int signum);
198 #endif /* __LUNAIX_PROCESS_H */