diff options
-rw-r--r-- | .travis.yml | 7 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/sys/ptrace.rs | 17 | ||||
-rw-r--r-- | test/sys/test_ptrace.rs | 36 |
4 files changed, 50 insertions, 12 deletions
diff --git a/.travis.yml b/.travis.yml index 92234237..935cb1ae 100644 --- a/.travis.yml +++ b/.travis.yml @@ -64,7 +64,7 @@ matrix: rust: 1.13.0 - env: TARGET=mipsel-unknown-linux-gnu rust: 1.13.0 - - env: TARGET=powerpc-unknown-linux-gnu + - env: TARGET=powerpc-unknown-linux-gnu DISABLE_TESTS=1 rust: 1.13.0 - env: TARGET=powerpc64-unknown-linux-gnu rust: 1.13.0 @@ -97,6 +97,11 @@ matrix: rust: beta allow_failures: + # We allow beta to fail here because a bug might crop up in rust that causes it. We will + # however be on the lookout for this and file those bugs with upstream. + - env: TARGET=x86_64-unknown-linux-gnu + rust: beta + # Planning to add these targets, but they can fail for now - env: TARGET=mips64-unknown-linux-gnuabi64 rust: 1.13.0 @@ -58,7 +58,6 @@ Tier 1: * i686-unknown-linux-musl * mips-unknown-linux-gnu * mipsel-unknown-linux-gnu - * powerpc-unknown-linux-gnu * powerpc64-unknown-linux-gnu * powerpc64le-unknown-linux-gnu * x86_64-apple-darwin @@ -76,6 +75,7 @@ Tier 2: * i386-apple-ios * i686-linux-android (requires Rust >= 1.18) * i686-unknown-freebsd + * powerpc-unknown-linux-gnu * x86_64-apple-ios * x86_64-linux-android (requires Rust >= 1.18) * x86_64-unknown-netbsd 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,...)` diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index 6318495a..57b452cb 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -3,7 +3,8 @@ use nix::errno::*; use nix::unistd::*; use nix::sys::ptrace::*; use nix::sys::ptrace::ptrace::*; -use std::ptr; + +use std::{mem, ptr}; #[test] fn test_ptrace() { @@ -12,3 +13,36 @@ fn test_ptrace() { let err = ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err(); assert!(err == Error::Sys(Errno::EPERM) || err == Error::Sys(Errno::ENOSYS)); } + +// Just make sure ptrace_setoptions can be called at all, for now. +#[test] +fn test_ptrace_setoptions() { + let err = ptrace_setoptions(getpid(), PTRACE_O_TRACESYSGOOD).unwrap_err(); + assert!(err != Error::UnsupportedOperation); +} + +// Just make sure ptrace_getevent can be called at all, for now. +#[test] +fn test_ptrace_getevent() { + let err = ptrace_getevent(getpid()).unwrap_err(); + assert!(err != Error::UnsupportedOperation); +} + +// Just make sure ptrace_getsiginfo can be called at all, for now. +#[test] +fn test_ptrace_getsiginfo() { + match ptrace_getsiginfo(getpid()) { + Err(Error::UnsupportedOperation) => panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"), + _ => (), + } +} + +// Just make sure ptrace_setsiginfo can be called at all, for now. +#[test] +fn test_ptrace_setsiginfo() { + let siginfo = unsafe { mem::uninitialized() }; + match ptrace_setsiginfo(getpid(), &siginfo) { + Err(Error::UnsupportedOperation) => panic!("ptrace_setsiginfo returns Error::UnsupportedOperation!"), + _ => (), + } +} |