From 1bca5fc45e19c19d86e383acacfa844acc42eb60 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Wed, 10 Oct 2018 23:12:34 +0100 Subject: [PATCH] Added ptrace::kill Just to check it's not actually different --- src/sys/ptrace/bsd.rs | 8 ++++++++ src/sys/ptrace/linux.rs | 9 +++++++++ test/sys/test_ptrace.rs | 4 ++-- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs index fe07f55b8e..df8508a862 100644 --- a/src/sys/ptrace/bsd.rs +++ b/src/sys/ptrace/bsd.rs @@ -103,6 +103,14 @@ pub fn cont>>(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, ...)` /// diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 03ab1f1fe2..7d6dbfadac 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -320,6 +320,15 @@ pub fn cont>>(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, ...)` /// diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index ed62a88955..62419feedb 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -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"), }