X-Git-Url: https://scm.lunaixsky.com/lunaix-os.git/blobdiff_plain/1b471813a2ba287c2ace9cf6c866f330c725b99c..0cf90cca0c924622f3fee8d2a3fafa8238363dc6:/lunaix-os/includes/lunaix/process.h diff --git a/lunaix-os/includes/lunaix/process.h b/lunaix-os/includes/lunaix/process.h index 32b74df..27137a1 100644 --- a/lunaix-os/includes/lunaix/process.h +++ b/lunaix-os/includes/lunaix/process.h @@ -3,7 +3,11 @@ #include #include +#include +#include #include +#include +#include #include #include #include @@ -11,46 +15,100 @@ // 虽然内核不是进程,但为了区分,这里使用Pid=-1来指代内核。这主要是方便物理页所有权检查。 #define KERNEL_PID -1 -#define PROC_STOPPED 0 -#define PROC_RUNNING 1 -#define PROC_TERMNAT 2 -#define PROC_DESTROY 4 -#define PROC_BLOCKED 8 -#define PROC_CREATED 16 +#define PS_READY 0 +#define PS_RUNNING 1 +#define PS_TERMNAT 2 +#define PS_DESTROY 4 +#define PS_BLOCKED 8 +#define PS_CREATED 16 -#define PROC_TERMMASK 0x6 +#define PROC_TERMINATED(state) (state & 0x6) -struct proc_mm +#define PROC_FINPAUSE 1 + +struct proc_sigstate { - heap_context_t u_heap; - struct mm_region* regions; + isr_param proc_regs; + char fxstate[512] __attribute__((aligned(16))); }; +struct proc_sig +{ + void* signal_handler; + int sig_num; + struct proc_sigstate prev_context; +} __attribute__((packed)); + struct proc_info { - pid_t pid; - struct proc_info* parent; - isr_param intr_ctx; + /* + Any change to *critical section*, including layout, size + must be reflected in kernel/asm/x86/interrupt.S to avoid + disaster! + */ + + /* ---- critical section start ---- */ + + pid_t pid; // offset = 0 + struct proc_info* parent; // offset = 4 + isr_param intr_ctx; // offset = 8 + uintptr_t ustack_top; // offset = 84 -> 56 -> 60 + void* page_table; // offset = 88 -> 60 -> 64 + void* fxstate; // offset = 92 -> 64 -> 68 + + /* ---- critical section end ---- */ + + struct llist_header tasks; struct llist_header siblings; struct llist_header children; struct llist_header grp_member; + waitq_t waitqueue; + + struct + { + struct llist_header sleepers; + time_t wakeup_time; + time_t alarm_time; + } sleep; + struct proc_mm mm; - void* page_table; time_t created; uint8_t state; int32_t exit_code; int32_t k_status; + sigset_t sig_pending; + sigset_t sig_mask; + sigset_t sig_inprogress; + int flags; + void* sig_handler[_SIG_NUM]; + struct v_fdtable* fdtable; + struct v_dnode* cwd; pid_t pgid; - struct lx_timer* timer; }; extern volatile struct proc_info* __current; -pid_t -alloc_pid(); +static inline void +block_current() +{ + __current->state = PS_BLOCKED; +} +/** + * @brief 分配并初始化一个进程控制块 + * + * @return struct proc_info* + */ +struct proc_info* +alloc_process(); + +/** + * @brief 初始化进程用户空间 + * + * @param pcb + */ void -init_proc(struct proc_info* pcb); +init_proc_user_space(struct proc_info* pcb); /** * @brief 向系统发布一个进程,使其可以被调度。 @@ -58,7 +116,7 @@ init_proc(struct proc_info* pcb); * @param process */ void -push_process(struct proc_info* process); +commit_process(struct proc_info* process); pid_t destroy_process(pid_t pid);