From 5b6be626e29e7f25b30469dce2359ff76badb49d Mon Sep 17 00:00:00 2001 From: carlos <48725664+00xc@users.noreply.github.com> Date: Thu, 10 Dec 2020 12:55:17 +0100 Subject: [PATCH 1/2] Add public API for PTRACE_GETFPREGS and PTRACE_SETFPREGS --- src/sys/ptrace/linux.rs | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) 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 From a39e598de06a5ae90edbb871fccd454c762b5b5c Mon Sep 17 00:00:00 2001 From: carlos <48725664+00xc@users.noreply.github.com> Date: Thu, 10 Dec 2020 14:52:31 +0100 Subject: [PATCH 2/2] Updated changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a110f6500b..2f7692cde4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ This project adheres to [Semantic Versioning](http://semver.org/). ## [Unreleased] - ReleaseDate ### Added - Added `mremap` (#[1306](https://github.com/nix-rust/nix/pull/1306)) +- Added public API for the `PTRACE_GETFPREGS` and `PTRACE_SETFPREGS` requests. + (#[1356](https://github.com/nix-rust/nix/pull/1356)) ### Fixed ### Changed