Modify signal.rs and sys_kill to support more signals

This commit is contained in:
liusm18 2022-04-18 21:58:01 +08:00
parent 639643bc5f
commit c8542d6107
3 changed files with 40 additions and 6 deletions

View File

@ -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

View File

@ -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;
}
}

View File

@ -30,6 +30,7 @@ pub struct TaskControlBlockInner {
pub exit_code: i32,
pub fd_table: Vec<Option<Arc<dyn File + Send + Sync>>>,
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()
})
},
});