Commit 0e2b0d0f authored by jD91mZM2's avatar jD91mZM2

Fix a few details

parent 3ac1416d
...@@ -22,15 +22,16 @@ macro_rules! with_interrupt_stack { ...@@ -22,15 +22,16 @@ macro_rules! with_interrupt_stack {
unsafe fn $wrapped(stack: *mut InterruptStack) { unsafe fn $wrapped(stack: *mut InterruptStack) {
let _guard = ptrace::set_process_regs(stack); let _guard = ptrace::set_process_regs(stack);
ptrace::breakpoint_callback(PTRACE_STOP_PRE_SYSCALL, None); let not_sysemu = ptrace::breakpoint_callback(PTRACE_STOP_PRE_SYSCALL, None)
let not_sysemu = ptrace::next_breakpoint().map(|b| b & PTRACE_FLAG_SYSEMU != PTRACE_FLAG_SYSEMU); .and_then(|_| ptrace::next_breakpoint().map(|b| b & PTRACE_FLAG_SYSEMU != PTRACE_FLAG_SYSEMU));
if not_sysemu.unwrap_or(true) { if not_sysemu.unwrap_or(true) {
// If not on a sysemu breakpoint // If not on a sysemu breakpoint
let $stack = &mut *stack; let $stack = &mut *stack;
$stack.scratch.rax = $code; $stack.scratch.rax = $code;
ptrace::breakpoint_callback(PTRACE_STOP_POST_SYSCALL, None);
} }
ptrace::breakpoint_callback(PTRACE_STOP_POST_SYSCALL, None);
} }
} }
} }
......
...@@ -133,6 +133,11 @@ pub fn send_event(event: PtraceEvent) -> Option<()> { ...@@ -133,6 +133,11 @@ pub fn send_event(event: PtraceEvent) -> Option<()> {
let mut sessions = sessions_mut(); let mut sessions = sessions_mut();
let session = sessions.get_mut(&context.id)?; let session = sessions.get_mut(&context.id)?;
let breakpoint = session.breakpoint.as_ref()?;
if event.cause & breakpoint.flags != event.cause {
return None;
}
session.events.push_back(event); session.events.push_back(event);
...@@ -209,8 +214,8 @@ pub fn wait(pid: ContextId) -> Result<Option<PtraceEvent>> { ...@@ -209,8 +214,8 @@ pub fn wait(pid: ContextId) -> Result<Option<PtraceEvent>> {
let sessions = sessions(); let sessions = sessions();
match sessions.get(&pid) { match sessions.get(&pid) {
Some(session) if session.breakpoint.as_ref().map(|b| !b.reached).unwrap_or(true) => { Some(session) if session.breakpoint.as_ref().map(|b| !b.reached).unwrap_or(true) => {
if let Some(event) = session.events.front() { if !session.events.is_empty() {
return Ok(Some(event.clone())); return Ok(None);
} }
Arc::clone(&session.tracer) Arc::clone(&session.tracer)
}, },
...@@ -252,21 +257,23 @@ pub fn breakpoint_callback(match_flags: u64, event: Option<PtraceEvent>) -> Opti ...@@ -252,21 +257,23 @@ pub fn breakpoint_callback(match_flags: u64, event: Option<PtraceEvent>) -> Opti
let session = sessions.get_mut(&context.id)?; let session = sessions.get_mut(&context.id)?;
let breakpoint = session.breakpoint.as_mut()?; let breakpoint = session.breakpoint.as_mut()?;
// TODO: How should singlesteps interact with syscalls? How
// does Linux handle this?
if breakpoint.flags & match_flags != match_flags { if breakpoint.flags & match_flags != match_flags {
return None; return None;
} }
session.events.push_back(event.unwrap_or(ptrace_event!(match_flags))); session.events.push_back(event.unwrap_or(ptrace_event!(match_flags)));
// Notify nonblocking tracers
if session.events.len() == 1 {
// If the list of events was previously empty, alert now
proc_trigger_event(session.file_id, EVENT_READ);
}
// In case no tracer is waiting, make sure the next one gets // In case no tracer is waiting, make sure the next one gets
// the memo // the memo
breakpoint.reached = true; breakpoint.reached = true;
session.tracer.notify(); session.tracer.notify();
proc_trigger_event(session.file_id, EVENT_WRITE);
( (
Arc::clone(&session.tracee), Arc::clone(&session.tracee),
......
This diff is collapsed.
Subproject commit 52441c28b1daa6f9febf1bc6588b625b167bd2c3 Subproject commit edf3c008dc0a68245a255945d9a70b02c71991a5
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment