Skip to content

Commit

Permalink
Refactor ptrace_get_data
Browse files Browse the repository at this point in the history
The boxing and unboxing was unnecessary and instead the references to the type on
the stack can just be cast.
  • Loading branch information
Susurrus committed Jul 17, 2017
1 parent 73ae9e0 commit bba9e43
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/sys/ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,10 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data
/// requests.
fn ptrace_get_data<T>(request: ptrace::PtraceRequest, pid: Pid) -> Result<T> {
// 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) };
let res = unsafe { ffi::ptrace(request, pid.into(), ptr::null_mut(), data) };
let data: T = unsafe { mem::uninitialized() };
let res = unsafe { ffi::ptrace(request, pid.into(), ptr::null_mut(), &data as *const _ as *const c_void) };
Errno::result(res)?;
// Convert back into the original data format and return unboxed value
let data: Box<T> = unsafe { mem::transmute(data) };
Ok(*data)
Ok(data)
}

fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
Expand Down

0 comments on commit bba9e43

Please sign in to comment.