25b1d60846f2d5649ef2538608286d0cdc78b9fa
[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
10 // 虽然内核不是进程,但为了区分,这里使用Pid=-1来指代内核。这主要是方便物理页所有权检查。
11 #define KERNEL_PID -1
12
13 #define PROC_CREATED 0
14 #define PROC_RUNNING 1
15 #define PROC_STOPPED 2
16 #define PROC_TERMNAT 3
17 #define PROC_DESTROY 4
18
19
20 struct proc_mm {
21     heap_context_t k_heap;
22     heap_context_t u_heap;
23     struct mm_region* region;
24 };
25
26 struct proc_info {
27     pid_t pid;
28     pid_t parent;
29     isr_param intr_ctx;
30     struct proc_mm mm;
31     void* page_table;
32     time_t created;
33     time_t parent_created;
34     uint8_t state;
35     int32_t exit_code;
36     int32_t k_status;
37 };
38
39 extern struct proc_info* __current;
40
41
42 pid_t alloc_pid();
43
44 /**
45  * @brief 向系统发布一个进程,使其可以被调度。
46  * 
47  * @param process 
48  */
49 void push_process(struct proc_info* process);
50
51 void destroy_process(pid_t pid);
52
53 /**
54  * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
55  * 
56  */
57 void dup_proc();
58
59 /**
60  * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
61  * 
62  */
63 void new_proc();
64
65 /**
66  * @brief 终止(退出)当前进程
67  * 
68  */
69 void terminate_process(int exit_code);
70
71 struct proc_info* get_process(pid_t pid);
72
73 #endif /* __LUNAIX_PROCESS_H */