From a58d4eb57386803ac45d39aa48da5534a40a087e Mon Sep 17 00:00:00 2001 From: Jeremy Fitzhardinge Date: Sun, 17 Nov 2019 19:04:28 -0800 Subject: [PATCH] ptrace: add ptrace::seize for Linux --- CHANGELOG.md | 4 ++++ src/sys/ptrace/linux.rs | 15 +++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 00a72fdbb4..d0f6b08786 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate ### Added +- Added `ptrace::seize()`: similar to `attach()` on Linux + but with better-defined semantics. + (#[1154](https://github.com/nix-rust/nix/pull/1154)) + - Added `Signal::as_str()`: returns signal name as `&'static str` (#[1138](https://github.com/nix-rust/nix/pull/1138)) diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index b2b984c36b..ffe23d7170 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -315,6 +315,21 @@ pub fn attach(pid: Pid) -> Result<()> { } } +/// Attach to a running process, as with `ptrace(PTRACE_SEIZE, ...)` +/// +/// Attaches to the process specified in pid, making it a tracee of the calling process. +#[cfg(all(target_os = "linux", not(any(target_arch = "mips", target_arch = "mips64"))))] +pub fn seize(pid: Pid, options: Options) -> Result<()> { + unsafe { + ptrace_other( + Request::PTRACE_SEIZE, + pid, + ptr::null_mut(), + options.bits() as *mut c_void, + ).map(drop) // ignore the useless return value + } +} + /// Detaches the current running process, as with `ptrace(PTRACE_DETACH, ...)` /// /// Detaches from the process specified in pid allowing it to run freely