First step for ptrace overhaul

This commit is contained in:
jD91mZM2
2019-07-24 21:42:33 +02:00
parent e95cb74d0b
commit 3ac1416dba
9 changed files with 227 additions and 192 deletions
+9 -12
View File
@@ -1,11 +1,12 @@
use alloc::sync::Arc;
use core::mem;
use syscall::data::PtraceEvent;
use syscall::flag::{PTRACE_STOP_SIGNAL, SIG_DFL, SIG_IGN, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU};
use syscall::ptrace_event;
use crate::context::{contexts, switch, Status, WaitpidKey};
use crate::start::usermode;
use crate::{ptrace, syscall};
use crate::syscall::flag::{PTRACE_EVENT_SIGNAL, PTRACE_SIGNAL, SIG_DFL, SIG_IGN, SIGCHLD, SIGCONT, SIGSTOP, SIGTSTP, SIGTTIN, SIGTTOU};
use crate::syscall::data::{PtraceEvent, PtraceEventData};
use crate::ptrace;
pub fn is_user_handled(handler: Option<extern "C" fn(usize)>) -> bool {
let handler = handler.map(|ptr| ptr as usize).unwrap_or(0);
@@ -21,12 +22,10 @@ pub extern "C" fn signal_handler(sig: usize) {
actions[sig]
};
ptrace::send_event(PtraceEvent {
tag: PTRACE_EVENT_SIGNAL,
data: PtraceEventData { signal: sig }
});
let handler = action.sa_handler.map(|ptr| ptr as usize).unwrap_or(0);
ptrace::breakpoint_callback(PTRACE_STOP_SIGNAL, Some(ptrace_event!(PTRACE_STOP_SIGNAL, sig, handler)));
if handler == SIG_DFL {
match sig {
SIGCHLD => {
@@ -92,7 +91,7 @@ pub extern "C" fn signal_handler(sig: usize) {
},
_ => {
// println!("Exit {}", sig);
syscall::exit(sig);
crate::syscall::exit(sig);
}
}
} else if handler == SIG_IGN {
@@ -100,8 +99,6 @@ pub extern "C" fn signal_handler(sig: usize) {
} else {
// println!("Call {:X}", handler);
ptrace::breakpoint_callback(PTRACE_SIGNAL);
unsafe {
let mut sp = crate::USER_SIGSTACK_OFFSET + crate::USER_SIGSTACK_SIZE - 256;
@@ -114,5 +111,5 @@ pub extern "C" fn signal_handler(sig: usize) {
}
}
syscall::sigreturn().unwrap();
crate::syscall::sigreturn().unwrap();
}