From c8542d6107b4ceddd25c6d01031e4780fb00a3ba Mon Sep 17 00:00:00 2001 From: liusm18 Date: Mon, 18 Apr 2022 21:58:01 +0800 Subject: [PATCH] Modify signal.rs and sys_kill to support more signals --- os/src/syscall/process.rs | 7 ++++++- os/src/task/signal.rs | 36 +++++++++++++++++++++++++++++++----- os/src/task/task.rs | 3 +++ 3 files changed, 40 insertions(+), 6 deletions(-) diff --git a/os/src/syscall/process.rs b/os/src/syscall/process.rs index e43db1ec..ede51750 100644 --- a/os/src/syscall/process.rs +++ b/os/src/syscall/process.rs @@ -107,7 +107,12 @@ pub fn sys_waitpid(pid: isize, exit_code_ptr: *mut i32) -> isize { pub fn sys_kill(pid: usize, signal: u32) -> isize { if let Some(task) = pid2task(pid) { if let Some(flag) = SignalFlags::from_bits(signal) { - task.inner_exclusive_access().signals |= flag; + // insert the signal if legal + let mut task_ref = task.inner_exclusive_access(); + if task_ref.pending_signals.contains(flag) { + return -1; + } + task_ref.pending_signals.insert(flag); 0 } else { -1 diff --git a/os/src/task/signal.rs b/os/src/task/signal.rs index 46f1ad9d..d646c19f 100644 --- a/os/src/task/signal.rs +++ b/os/src/task/signal.rs @@ -2,11 +2,37 @@ use bitflags::*; bitflags! { pub struct SignalFlags: u32 { - const SIGINT = 1 << 2; - const SIGILL = 1 << 4; - const SIGABRT = 1 << 6; - const SIGFPE = 1 << 8; - const SIGSEGV = 1 << 11; + const SIGHUP = 1 << 1; + const SIGINT = 1 << 2; + const SIGQUIT = 1 << 3; + const SIGILL = 1 << 4; + const SIGTRAP = 1 << 5; + const SIGABRT = 1 << 6; + const SIGBUS = 1 << 7; + const SIGFPE = 1 << 8; + const SIGKILL = 1 << 9; + const SIGUSR1 = 1 << 10; + const SIGSEGV = 1 << 11; + const SIGUSR2 = 1 << 12; + const SIGPIPE = 1 << 13; + const SIGALRM = 1 << 14; + const SIGTERM = 1 << 15; + const SIGSTKFLT = 1 << 16; + const SIGCHLD = 1 << 17; + const SIGCONT = 1 << 18; + const SIGSTOP = 1 << 19; + const SIGTSTP = 1 << 20; + const SIGTTIN = 1 << 21; + const SIGTTOU = 1 << 22; + const SIGURG = 1 << 23; + const SIGXCPU = 1 << 24; + const SIGXFSZ = 1 << 25; + const SIGVTALRM = 1 << 26; + const SIGPROF = 1 << 27; + const SIGWINCH = 1 << 28; + const SIGIO = 1 << 29; + const SIGPWR = 1 << 30; + const SIGSYS = 1 << 31; } } diff --git a/os/src/task/task.rs b/os/src/task/task.rs index e156638a..f9e4a102 100644 --- a/os/src/task/task.rs +++ b/os/src/task/task.rs @@ -30,6 +30,7 @@ pub struct TaskControlBlockInner { pub exit_code: i32, pub fd_table: Vec>>, pub signals: SignalFlags, + pub pending_signals: SignalFlags } impl TaskControlBlockInner { @@ -92,6 +93,7 @@ impl TaskControlBlock { Some(Arc::new(Stdout)), ], signals: SignalFlags::empty(), + pending_signals: SignalFlags::empty() }) }, }; @@ -194,6 +196,7 @@ impl TaskControlBlock { exit_code: 0, fd_table: new_fd_table, signals: SignalFlags::empty(), + pending_signals: SignalFlags::empty() }) }, });