Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ptrace: add ptrace::seize for Linux #1154

Merged
merged 1 commit into from Nov 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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))

Expand Down
15 changes: 15 additions & 0 deletions src/sys/ptrace/linux.rs
Expand Up @@ -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
Expand Down