diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-01 04:45:41 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-01 04:45:41 +0000 |
commit | 0ce45876eced99438f89631f63831e75012539c5 (patch) | |
tree | dc604391947282743dbac3d06679c965a0c3c73e /src/sys/ptrace/linux.rs | |
parent | f3bf1df774a6cb89cf04dced385ec073908508b0 (diff) | |
parent | 7f3ee09eec10ef5319a7b1d9c358f50638eb1471 (diff) | |
download | nix-0ce45876eced99438f89631f63831e75012539c5.zip |
Merge #1083
1083: Allow signal injection in ptrace::syscall and ptrace::detach r=asomers a=frangio
Fixes #1049
Should I add tests for this functionality?
By the way, I noticed that the BSD module doesn't have `ptrace::syscall`. I couldn't find a reason behind this in #949. Should we add it?
Co-authored-by: Francisco Giordano <frangio.1@gmail.com>
Diffstat (limited to 'src/sys/ptrace/linux.rs')
-rw-r--r-- | src/sys/ptrace/linux.rs | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index ffe23d71..662425ae 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -289,21 +289,26 @@ pub fn traceme() -> Result<()> { /// Ask for next syscall, as with `ptrace(PTRACE_SYSCALL, ...)` /// -/// Arranges for the tracee to be stopped at the next entry to or exit from a system call. -pub fn syscall(pid: Pid) -> Result<()> { +/// 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 i32 as *mut c_void, + None => ptr::null_mut(), + }; unsafe { ptrace_other( Request::PTRACE_SYSCALL, pid, ptr::null_mut(), - ptr::null_mut(), + data, ).map(drop) // ignore the useless return value } } /// Attach to a running process, as with `ptrace(PTRACE_ATTACH, ...)` /// -/// Attaches to the process specified in pid, making it a tracee of the calling process. +/// Attaches to the process specified by `pid`, making it a tracee of the calling process. pub fn attach(pid: Pid) -> Result<()> { unsafe { ptrace_other( @@ -332,14 +337,19 @@ pub fn seize(pid: Pid, options: Options) -> Result<()> { /// Detaches the current running process, as with `ptrace(PTRACE_DETACH, ...)` /// -/// Detaches from the process specified in pid allowing it to run freely -pub fn detach(pid: Pid) -> Result<()> { +/// Detaches from the process specified by `pid` allowing it to run freely, optionally delivering a +/// signal specified by `sig`. +pub fn detach<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> { + let data = match sig.into() { + Some(s) => s as i32 as *mut c_void, + None => ptr::null_mut(), + }; unsafe { ptrace_other( Request::PTRACE_DETACH, pid, ptr::null_mut(), - ptr::null_mut() + data ).map(drop) } } |