1 use core::ffi::c_void;
2 
3 use alloc::boxed::Box;
4 
5 use crate::{
6     include::bindings::bindings::{atomic_t, process_control_block, spinlock_t},
7     ipc::{signal::DEFAULT_SIGACTION, signal_types::SigQueue},
8 };
9 
10 use crate::ipc::signal_types::{sighand_struct, signal_struct, MAX_SIG_NUM};
11 
12 /// @brief 初始进程的signal结构体
13 #[no_mangle]
14 pub static mut INITIAL_SIGNALS: signal_struct = signal_struct {
15     sig_cnt: atomic_t { value: 0 },
16 };
17 
18 /// @brief 初始进程的sighand结构体
19 #[no_mangle]
20 pub static mut INITIAL_SIGHAND: sighand_struct = sighand_struct {
21     count: REFCOUNT_INIT!(1),
22     siglock: spinlock_t { lock: 1 },
23     action: [DEFAULT_SIGACTION; MAX_SIG_NUM as usize],
24 };
25 
26 /// @brief 初始化pid=0的进程的信号相关的信息
27 #[no_mangle]
initial_proc_init_signal(pcb: *mut process_control_block)28 pub extern "C" fn initial_proc_init_signal(pcb: *mut process_control_block) {
29 
30     // 所设置的pcb的pid一定为0
31     assert_eq!(unsafe { (*pcb).pid }, 0);
32 
33     // 设置init进程的sighand和signal
34     unsafe {
35         (*pcb).sighand = &mut INITIAL_SIGHAND as *mut sighand_struct as usize
36             as *mut crate::include::bindings::bindings::sighand_struct;
37         (*pcb).signal = &mut INITIAL_SIGNALS as *mut signal_struct as usize
38             as *mut crate::include::bindings::bindings::signal_struct;
39     }
40     // 创建新的sig_pending->sigqueue
41     unsafe {
42         (*pcb).sig_pending.signal = 0;
43         (*pcb).sig_pending.sigqueue =
44             Box::leak(Box::new(SigQueue::default())) as *mut SigQueue as *mut c_void;
45     }
46 }
47