Skip to content

Commit a58d4eb

Browse files
committed
ptrace: add ptrace::seize for Linux
1 parent 5cb526d commit a58d4eb

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ This project adheres to [Semantic Versioning](http://semver.org/).
55

66
## [Unreleased] - ReleaseDate
77
### Added
8+
- Added `ptrace::seize()`: similar to `attach()` on Linux
9+
but with better-defined semantics.
10+
(#[1154](https://github.com/nix-rust/nix/pull/1154))
11+
812
- Added `Signal::as_str()`: returns signal name as `&'static str`
913
(#[1138](https://github.com/nix-rust/nix/pull/1138))
1014

src/sys/ptrace/linux.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,21 @@ pub fn attach(pid: Pid) -> Result<()> {
315315
}
316316
}
317317

318+
/// Attach to a running process, as with `ptrace(PTRACE_SEIZE, ...)`
319+
///
320+
/// Attaches to the process specified in pid, making it a tracee of the calling process.
321+
#[cfg(all(target_os = "linux", not(any(target_arch = "mips", target_arch = "mips64"))))]
322+
pub fn seize(pid: Pid, options: Options) -> Result<()> {
323+
unsafe {
324+
ptrace_other(
325+
Request::PTRACE_SEIZE,
326+
pid,
327+
ptr::null_mut(),
328+
options.bits() as *mut c_void,
329+
).map(drop) // ignore the useless return value
330+
}
331+
}
332+
318333
/// Detaches the current running process, as with `ptrace(PTRACE_DETACH, ...)`
319334
///
320335
/// Detaches from the process specified in pid allowing it to run freely

0 commit comments

Comments
 (0)