From ed943a2809069b76f1dc49481f27155bba99256a Mon Sep 17 00:00:00 2001 From: xd009642 Date: Sun, 7 Oct 2018 17:42:11 +0100 Subject: [PATCH] responded to review comments Enabled ptrace tests for bsds, removed unnecessary cfg, sorted line lengths and removed UnsupportedOperation version of step --- src/sys/ptrace/bsd.rs | 14 +++++--------- src/sys/ptrace/linux.rs | 2 +- test/sys/mod.rs | 3 +-- test/sys/test_ptrace.rs | 8 +++++++- 4 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs index a6cb5762ed..6a1e310456 100644 --- a/src/sys/ptrace/bsd.rs +++ b/src/sys/ptrace/bsd.rs @@ -108,7 +108,9 @@ pub fn cont>>(pid: Pid, sig: T) -> Result<()> { None => 0, }; unsafe { - ptrace_other(Request::PT_CONTINUE, pid, ptr::null_mut(), data).map(|_| ()) // ignore the useless return value + // Ignore the useless return value + ptrace_other(Request::PT_CONTINUE, pid, ptr::null_mut(), data) + .map(|_| ()) } } @@ -149,17 +151,11 @@ pub fn step>>(pid: Pid, sig: T) -> Result<()> { } } -/// Step isn't supported on netbsd or openbsd -#[cfg(any(target_os = "netbsd", target_os = "openbsd"))] -pub fn Step>>(pid: Pid, sig: T) -> Result<()> { - Err(Error::UnsupportedOperation) -} - /// Reads a word from a processes memory at the given address pub fn read(pid: Pid, addr: AddressType) -> Result { unsafe { - // Traditionally there was a difference between reading data or instruction - // memory but not in modern systems. + // Traditionally there was a difference between reading data or + // instruction memory but not in modern systems. ptrace_other(Request::PT_READ_D, pid, addr, 0) } } diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index ce62c73c68..03ab1f1fe2 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -20,7 +20,7 @@ cfg_if! { } libc_enum!{ - #[cfg_attr(not(any(target_env = "musl", target_os = "android", target_os = "macos")), repr(u32))] + #[cfg_attr(not(any(target_env = "musl", target_os = "android")), repr(u32))] #[cfg_attr(any(target_env = "musl", target_os = "android"), repr(i32))] /// Ptrace Request enum defining the action to be taken. pub enum Request { diff --git a/test/sys/mod.rs b/test/sys/mod.rs index bdc079d84c..0e7497e936 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -26,6 +26,5 @@ mod test_uio; #[cfg(target_os = "linux")] mod test_epoll; mod test_pthread; -#[cfg(any(target_os = "android", - target_os = "linux"))] +#[cfg(not(target_os = "ios"))] mod test_ptrace; diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs index debc451755..29536999d7 100644 --- a/test/sys/test_ptrace.rs +++ b/test/sys/test_ptrace.rs @@ -1,7 +1,9 @@ use nix::Error; use nix::errno::Errno; use nix::unistd::getpid; -use nix::sys::ptrace::{self, Options}; +use nix::sys::ptrace; +#[cfg(any(target_os = "android", target_os = "linux"))] +use nix::sys::ptrace::Options; use std::mem; @@ -15,6 +17,7 @@ fn test_ptrace() { // Just make sure ptrace_setoptions can be called at all, for now. #[test] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptrace_setoptions() { let err = ptrace::setoptions(getpid(), Options::PTRACE_O_TRACESYSGOOD).unwrap_err(); assert!(err != Error::UnsupportedOperation); @@ -22,6 +25,7 @@ fn test_ptrace_setoptions() { // Just make sure ptrace_getevent can be called at all, for now. #[test] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptrace_getevent() { let err = ptrace::getevent(getpid()).unwrap_err(); assert!(err != Error::UnsupportedOperation); @@ -29,6 +33,7 @@ fn test_ptrace_getevent() { // Just make sure ptrace_getsiginfo can be called at all, for now. #[test] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptrace_getsiginfo() { if let Err(Error::UnsupportedOperation) = ptrace::getsiginfo(getpid()) { panic!("ptrace_getsiginfo returns Error::UnsupportedOperation!"); @@ -37,6 +42,7 @@ fn test_ptrace_getsiginfo() { // Just make sure ptrace_setsiginfo can be called at all, for now. #[test] +#[cfg(any(target_os = "android", target_os = "linux"))] fn test_ptrace_setsiginfo() { let siginfo = unsafe { mem::uninitialized() }; if let Err(Error::UnsupportedOperation) = ptrace::setsiginfo(getpid(), &siginfo) {