diff options
author | Bryant Mairs <bryant@mai.rs> | 2017-07-17 16:16:05 -0700 |
---|---|---|
committer | Bryant Mairs <bryant@mai.rs> | 2017-07-17 16:16:05 -0700 |
commit | bba9e436393e3606bfe19a2a1d40c849a9242f4a (patch) | |
tree | 7b156377d7e917b4b7e31efe7080d15564052511 | |
parent | 73ae9e012e65f631dd96f45cf7d25de678958600 (diff) | |
download | nix-bba9e436393e3606bfe19a2a1d40c849a9242f4a.zip |
Refactor ptrace_get_data
The boxing and unboxing was unnecessary and instead the references to the type on
the stack can just be cast.
-rw-r--r-- | src/sys/ptrace.rs | 9 |
1 files changed, 3 insertions, 6 deletions
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 4c3d29b1..73ca9160 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -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> { |