diff options
Diffstat (limited to 'src/sys/ptrace.rs')
-rw-r--r-- | src/sys/ptrace.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index bf395259..4c3d29b1 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -91,15 +91,16 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data } } -/// Function for ptrace requests that return values from the data field. +/// 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 /// requests. fn ptrace_get_data<T>(request: ptrace::PtraceRequest, pid: Pid) -> Result<T> { - // Creates an uninitialized pointer to store result in + // Creates an uninitialized pointer to store result in let data: Box<T> = Box::new(unsafe { mem::uninitialized() }); let data: *mut c_void = unsafe { mem::transmute(data) }; - ptrace(request, pid, ptr::null_mut(), data)?; + let res = unsafe { ffi::ptrace(request, pid.into(), ptr::null_mut(), data) }; + Errno::result(res)?; // Convert back into the original data format and return unboxed value let data: Box<T> = unsafe { mem::transmute(data) }; Ok(*data) @@ -114,7 +115,8 @@ pub fn ptrace_setoptions(pid: Pid, options: ptrace::PtraceOptions) -> Result<()> use self::ptrace::*; use std::ptr; - ptrace(PTRACE_SETOPTIONS, pid, ptr::null_mut(), options as *mut c_void).map(drop) + let res = unsafe { ffi::ptrace(PTRACE_SETOPTIONS, pid.into(), ptr::null_mut(), options as *mut c_void) }; + Errno::result(res).map(|_| ()) } /// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)` |