Skip to content

Commit

Permalink
u# This is a combination of 2 commits.
Browse files Browse the repository at this point in the history
Added ptrace::kill

Just to check it's not actually different
  • Loading branch information
xd009642 committed Oct 10, 2018
1 parent 1918a7d commit 9d4dad4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
8 changes: 8 additions & 0 deletions src/sys/ptrace/bsd.rs
Expand Up @@ -103,6 +103,14 @@ pub fn cont<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
}
}

/// Issues a kill request as with ptrace(PT_KILL, ..-)
/// This request is equivalent to ptrace(PT_CONTINUE, ..., SIGKILL);
pub fn kill(pid: Pid) -> Result<()> {
unsafe {
ptrace_other(Request::PT_KILL, pid, 0 as AddressType, 0).map(|_| ())
}
}

/// Move the stopped tracee process forward by a single step as with
/// `ptrace(PT_STEP, ...)`
///
Expand Down
9 changes: 9 additions & 0 deletions src/sys/ptrace/linux.rs
Expand Up @@ -320,6 +320,15 @@ pub fn cont<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
}
}


/// Issues a kill request as with ptrace(PTRACE_KILL, ..-)
/// This request is equivalent to ptrace(PTRACE_CONT, ..., SIGKILL);
pub fn kill(pid: Pid) -> Result<()> {
unsafe {
ptrace_other(Request::PTRACE_KILL, pid, ptr::null_mut(), ptr::null_mut()).map(|_| ())
}
}

/// Move the stopped tracee process forward by a single step as with
/// `ptrace(PTRACE_SINGLESTEP, ...)`
///
Expand Down
6 changes: 3 additions & 3 deletions test/sys/test_ptrace.rs
Expand Up @@ -55,7 +55,7 @@ fn test_ptrace_setsiginfo() {
#[test]
fn test_ptrace_cont() {
use nix::sys::ptrace;
use nix::sys::signal::{kill, raise, Signal};
use nix::sys::signal::{raise, Signal};
use nix::sys::wait::{waitpid, WaitStatus};
use nix::unistd::fork;
use nix::unistd::ForkResult::*;
Expand Down Expand Up @@ -87,14 +87,14 @@ fn test_ptrace_cont() {
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP)));
ptrace::cont(child, None).unwrap();
assert_eq!(waitpid(child, None), Ok(WaitStatus::Stopped(child, Signal::SIGTRAP)));
ptrace::cont(child, Signal::SIGKILL).unwrap();
ptrace::kill(pid).unwrap();
match waitpid(child, None) {
Ok(WaitStatus::Signaled(pid, Signal::SIGKILL, _)) if pid == child => {
// Some systems require the tracee is in
// signal-delivery-stop otherwise the signal is discarded
// and the tracee doesn't actually get killed despite
// receiving the signal
let _ = kill(child, None);
//let _ = kill(child, None);
}
_ => panic!("The process should have been killed"),
}
Expand Down

0 comments on commit 9d4dad4

Please sign in to comment.