summaryrefslogtreecommitdiff
path: root/src/sys/ptrace.rs
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2017-07-19 05:32:22 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2017-07-19 05:32:22 +0000
commit3d24ae9588ebad1e495bedc909a226c84662a4c2 (patch)
tree7bf90108d9ade894cdcfb250e2ea93df7ae6f9f5 /src/sys/ptrace.rs
parent3acc24c1093bf38424c0f0348b71b08b337fbec6 (diff)
parentbba9e436393e3606bfe19a2a1d40c849a9242f4a (diff)
downloadnix-3d24ae9588ebad1e495bedc909a226c84662a4c2.zip
Merge #686
686: Fix special ptraces r=Susurrus In #614 we added specializations of `ptrace()` that added more type safety. As part of this, the `UnsupportedOperation` error was introduced for the requests that are covered by specialized versions so they couldn't be used with the general `ptrace()`. Unfortunately, no tests were added with this PR and so it slipped through that you could not do those operations at all anymore: `ptrace()` reported `UnsupportedOperation` for them and `ptrace_*` called `ptrace`, not `ffi::ptrace` and so also reported `UnsupportedOperation`! Whoops! This minimally-invasive surgery corrects this by adding tests that call all the specialized `ptrace_*` ignoring the return value save checking for `UnsupportedOperation`. It also changes the functions calls to use `ffi::ptrace()` directly to fix the bug. As this was never a bug in a released version of `nix`, there's no need for a changelog entry here.
Diffstat (limited to 'src/sys/ptrace.rs')
-rw-r--r--src/sys/ptrace.rs17
1 files changed, 8 insertions, 9 deletions
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs
index bf395259..73ca9160 100644
--- a/src/sys/ptrace.rs
+++ b/src/sys/ptrace.rs
@@ -91,18 +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
- 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)?;
- // Convert back into the original data format and return unboxed value
- let data: Box<T> = unsafe { mem::transmute(data) };
- Ok(*data)
+ // Creates an uninitialized pointer to store result in
+ 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)?;
+ Ok(data)
}
fn ptrace_other(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
@@ -114,7 +112,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,...)`