summaryrefslogtreecommitdiff
path: root/src/sys/ptrace
diff options
context:
space:
mode:
authorWill Povell <william_povell@brown.edu>2019-01-09 15:27:04 -0500
committerWill Povell <william_povell@brown.edu>2019-01-09 22:54:46 -0500
commit2a437bf92bad687c072745e4dd85c52558615104 (patch)
tree9316eb7ed69de6ec4d17ae4b4ffa1577a5b5a642 /src/sys/ptrace
parentc2923ea5ea048eaa9024d17ce4f50335a9dd13ab (diff)
downloadnix-2a437bf92bad687c072745e4dd85c52558615104.zip
Added ptrace getregs and setregs
Diffstat (limited to 'src/sys/ptrace')
-rw-r--r--src/sys/ptrace/linux.rs32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs
index f10c6d83..54e453ba 100644
--- a/src/sys/ptrace/linux.rs
+++ b/src/sys/ptrace/linux.rs
@@ -9,6 +9,12 @@ use sys::signal::Signal;
pub type AddressType = *mut ::libc::c_void;
+#[cfg(all(target_os = "linux",
+ any(target_arch = "x86_64",
+ target_arch = "x86"),
+ target_env = "gnu"))]
+use libc::user_regs_struct;
+
cfg_if! {
if #[cfg(any(all(target_os = "linux", target_arch = "s390x"),
all(target_os = "linux", target_env = "gnu")))] {
@@ -192,6 +198,30 @@ fn ptrace_peek(request: Request, pid: Pid, addr: AddressType, data: *mut c_void)
}
}
+/// Get user registers, as with `ptrace(PTRACE_GETREGS, ...)`
+#[cfg(all(target_os = "linux",
+ any(target_arch = "x86_64",
+ target_arch = "x86"),
+ target_env = "gnu"))]
+pub fn getregs(pid: Pid) -> Result<user_regs_struct> {
+ ptrace_get_data::<user_regs_struct>(Request::PTRACE_GETREGS, pid)
+}
+
+/// Set user registers, as with `ptrace(PTRACE_SETREGS, ...)`
+#[cfg(all(target_os = "linux",
+ any(target_arch = "x86_64",
+ target_arch = "x86"),
+ target_env = "gnu"))]
+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::<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
@@ -215,8 +245,6 @@ unsafe fn ptrace_other(request: Request, pid: Pid, addr: AddressType, data: *mut
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
pub fn setoptions(pid: Pid, options: Options) -> Result<()> {
- use std::ptr;
-
let res = unsafe {
libc::ptrace(Request::PTRACE_SETOPTIONS as RequestType,
libc::pid_t::from(pid),