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)