Skip to content

Commit

Permalink
Add ptrace::syscall in BSD
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio committed Jun 17, 2019
1 parent be06661 commit 26385ee
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/sys/ptrace/bsd.rs
Expand Up @@ -75,6 +75,21 @@ pub fn traceme() -> Result<()> {
unsafe { ptrace_other(Request::PT_TRACE_ME, Pid::from_raw(0), ptr::null_mut(), 0).map(drop) }
}

/// Ask for next syscall, as with `ptrace(PT_SYSCALL, ...)`
///
/// Arranges for the tracee to be stopped at the next entry to or exit from a system call,
/// optionally delivering a signal specified by `sig`.
pub fn syscall<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
let data = match sig.into() {
Some(s) => s as c_int,
None => 0,
};
unsafe {
// Ignore the useless return value
ptrace_other(Request::PT_SYSCALL, pid, 1 as AddressType, data).map(drop)
}
}

/// Attach to a running process, as with `ptrace(PT_ATTACH, ...)`
///
/// Attaches to the process specified in pid, making it a tracee of the calling process.
Expand Down

0 comments on commit 26385ee

Please sign in to comment.