efa11666674b9602bdc07100d8bd6bc35fe2896b
[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 u_heap;
22     struct mm_region* region;
23 };
24
25 struct proc_info {
26     pid_t pid;
27     pid_t parent;
28     isr_param intr_ctx;
29     struct proc_mm mm;
30     void* page_table;
31     time_t created;
32     time_t parent_created;
33     uint8_t state;
34     int32_t exit_code;
35     int32_t k_status;
36 };
37
38 extern struct proc_info* __current;
39
40
41 pid_t alloc_pid();
42
43 /**
44  * @brief 向系统发布一个进程,使其可以被调度。
45  * 
46  * @param process 
47  */
48 void push_process(struct proc_info* process);
49
50 void destroy_process(pid_t pid);
51
52 void* dup_pagetable(pid_t pid);
53
54 /**
55  * @brief 复制当前进程(LunaixOS的类 fork (unix) 实现)
56  * 
57  */
58 void dup_proc();
59
60 /**
61  * @brief 创建新进程(LunaixOS的类 CreateProcess (Windows) 实现)
62  * 
63  */
64 void new_proc();
65
66 /**
67  * @brief 终止(退出)当前进程
68  * 
69  */
70 void terminate_process(int exit_code);
71
72 struct proc_info* get_process(pid_t pid);
73
74 #endif /* __LUNAIX_PROCESS_H */