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 // 所设置的pcb的pid一定为0
30 assert_eq!(unsafe { (*pcb).pid }, 0);
31
32 // 设置init进程的sighand和signal
33 unsafe {
34 (*pcb).sighand = &mut INITIAL_SIGHAND as *mut sighand_struct as usize
35 as *mut crate::include::bindings::bindings::sighand_struct;
36 (*pcb).signal = &mut INITIAL_SIGNALS as *mut signal_struct as usize
37 as *mut crate::include::bindings::bindings::signal_struct;
38 }
39 // 创建新的sig_pending->sigqueue
40 unsafe {
41 (*pcb).sig_pending.signal = 0;
42 (*pcb).sig_pending.sigqueue =
43 Box::leak(Box::new(SigQueue::default())) as *mut SigQueue as *mut c_void;
44 }
45 }
46