From 5ffaee2c829d46f6c5ac2414c4cc4c08537ee6b2 Mon Sep 17 00:00:00 2001 From: Josh Abraham Date: Thu, 16 Aug 2018 17:20:48 -1000 Subject: [PATCH] Add the ptrace GET/SETREGS request methods --- src/sys/ptrace.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 4bb7e06f60..e676695510 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -3,7 +3,7 @@ use std::{mem, ptr}; use {Error, Result}; use errno::Errno; -use libc::{self, c_void, c_long, siginfo_t}; +use libc::{self, c_void, c_long, siginfo_t, user_regs_struct}; use ::unistd::Pid; use sys::signal::Signal; @@ -229,6 +229,23 @@ pub fn getevent(pid: Pid) -> Result { ptrace_get_data::(Request::PTRACE_GETEVENTMSG, pid) } +/// Gets tracee GP registers as described by `ptrace(PTRACE_GETREGS,...)` +pub fn getregs(pid: Pid) -> Result { + ptrace_get_data::(Request::PTRACE_GETREGS, pid) +} + +/// Sets tracee GP registers as described by `ptrace(PTRACE_SETREGS,...)` +pub fn setregs(pid: Pid, regs: &user_regs_struct) -> Result<()> { + let res = unsafe { + libc::ptrace(Request::PTRACE_SETREGS as RequestType, + libc::pid_t::from(pid), + ptr::null_mut::(), + regs as *const _ as *const c_void) + }; + + Errno::result(res).map(|_| ()) +} + /// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)` pub fn getsiginfo(pid: Pid) -> Result { ptrace_get_data::(Request::PTRACE_GETSIGINFO, pid)