diff --git a/CHANGELOG.md b/CHANGELOG.md index 0ead550eb1..e7927e1e10 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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` @@ -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)). diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 8d1dd16e5d..d1199a27f0 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -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"), @@ -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 { + ptrace_get_data::(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::(), + ®s 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