Skip to content

Commit

Permalink
responded to review comments
Browse files Browse the repository at this point in the history
Enabled ptrace tests for bsds, removed unnecessary cfg, sorted line lengths and removed UnsupportedOperation version of step
  • Loading branch information
xd009642 committed Oct 7, 2018
1 parent 0087f07 commit ed943a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 13 deletions.
14 changes: 5 additions & 9 deletions src/sys/ptrace/bsd.rs
Expand Up @@ -108,7 +108,9 @@ pub fn cont<T: Into<Option<Signal>>>(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(|_| ())
}
}

Expand Down Expand Up @@ -149,17 +151,11 @@ pub fn step<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
}
}

/// Step isn't supported on netbsd or openbsd
#[cfg(any(target_os = "netbsd", target_os = "openbsd"))]
pub fn Step<T: Into<Option<Signal>>>(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<c_int> {
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)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sys/ptrace/linux.rs
Expand Up @@ -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 {
Expand Down
3 changes: 1 addition & 2 deletions test/sys/mod.rs
Expand Up @@ -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;
8 changes: 7 additions & 1 deletion 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;

Expand All @@ -15,20 +17,23 @@ 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);
}

// 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);
}

// 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!");
Expand All @@ -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) {
Expand Down

0 comments on commit ed943a2

Please sign in to comment.