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

Add public API for PTRACE_GETFPREGS and PTRACE_SETFPREGS #1356

Closed
wants to merge 5 commits into from
Closed
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 @@ -7,6 +7,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
### Added
- Added TIMESTAMPNS support for linux
(#[1402](https://github.com/nix-rust/nix/pull/1402))
- Added public API for the `PTRACE_GETFPREGS` and `PTRACE_SETFPREGS` requests.
(#[1356](https://github.com/nix-rust/nix/pull/1356))

### Changed
- Made `forkpty` unsafe, like `fork`
Expand All @@ -32,6 +34,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Added `personality` (#[1331](https://github.com/nix-rust/nix/pull/1331))
- Added limited Fuchsia support (#[1285](https://github.com/nix-rust/nix/pull/1285))
- Added `getpeereid` (#[1342](https://github.com/nix-rust/nix/pull/1342))

### Fixed
- Implemented `IntoIterator` for `Dir`
(#[1333](https://github.com/nix-rust/nix/pull/1333)).

Expand Down
30 changes: 29 additions & 1 deletion src/sys/ptrace/linux.rs
Expand Up @@ -16,7 +16,7 @@ pub type AddressType = *mut ::libc::c_void;
any(target_env = "gnu", target_env = "musl")),
all(target_arch = "x86", target_env = "gnu"))
))]
use libc::user_regs_struct;
use libc::{user_regs_struct, user_fpregs_struct};

cfg_if! {
if #[cfg(any(all(target_os = "linux", target_arch = "s390x"),
Expand Down Expand Up @@ -213,6 +213,34 @@ pub fn setregs(pid: Pid, regs: user_regs_struct) -> Result<()> {
Errno::result(res).map(drop)
}

/// Get floating point registers, as with `ptrace(PTRACE_GETFPREGS, ...)`
#[cfg(all(
target_os = "linux",
any(all(target_arch = "x86_64",
any(target_env = "gnu", target_env = "musl")),
all(target_arch = "x86", target_env = "gnu"))
))]
pub fn getfpregs(pid: Pid) -> Result<user_fpregs_struct> {
ptrace_get_data::<user_fpregs_struct>(Request::PTRACE_GETFPREGS, pid)
}

/// Set floating point registers, as with `ptrace(PTRACE_SETFPREGS)`
#[cfg(all(
target_os = "linux",
any(all(target_arch = "x86_64",
any(target_env = "gnu", target_env = "musl")),
all(target_arch = "x86", target_env = "gnu"))
))]
pub fn setfpregs(pid: Pid, regs: user_fpregs_struct) -> Result<()> {
let res = unsafe {
libc::ptrace(Request::PTRACE_SETFPREGS as RequestType,
libc::pid_t::from(pid),
ptr::null_mut::<c_void>(),
&regs as *const _ as *const c_void)
};
Errno::result(res).map(drop)
}

/// Function for ptrace requests that return values from the data field.
/// Some ptrace get requests populate structs or larger elements than `c_long`
/// and therefore use the data field to return values. This function handles these
Expand Down