feat: added ability to identify process vm regions
[lunaix-os.git] / lunaix-os / includes / lunaix / process.h
1 #ifndef __LUNAIX_PROCESS_H
2 #define __LUNAIX_PROCESS_H
3
4 #include <stdint.h>
5 #include <arch/x86/interrupts.h>
6 #include <lunaix/mm/mm.h>
7 #include <lunaix/types.h>
8 #include <lunaix/clock.h>
9 #include <lunaix/timer.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_SPOILED 8
19 #define PROC_BLOCKED 16
20
21
22 struct proc_mm {
23     heap_context_t u_heap;
24     struct mm_region* regions;
25 };
26
27 struct proc_info {
28     pid_t pid;
29     struct proc_info* parent;
30     isr_param intr_ctx;
31     struct proc_mm mm;
32     void* page_table;
33     time_t created;
34     uint8_t state;
35     int32_t exit_code;
36     int32_t k_status;
37     struct lx_timer* timer;
38 };
39
40 extern struct proc_info* __current;
41
42
43 pid_t alloc_pid();
44
45 /**
46  * @brief 向系统发布一个进程,使其可以被调度。
47  * 
48  * @param process 
49  */
50 void push_process(struct proc_info* process);
51
52 void destroy_process(pid_t pid);
53
54 void setup_proc_mem(struct proc_info* proc, uintptr_t kstack_from);
55
56 /**
57  * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
58  * 
59  */
60 void dup_proc();
61
62 /**
63  * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
64  * 
65  */
66 void new_proc();
67
68 /**
69  * @brief 终止(退出)当前进程
70  * 
71  */
72 void terminate_proc(int exit_code);
73
74 int orphaned_proc(pid_t pid);
75
76 struct proc_info* get_process(pid_t pid);
77
78 #endif /* __LUNAIX_PROCESS_H */