From 0bf5af584c11ffa22c452fb89dcbea70c03e018c Mon Sep 17 00:00:00 2001 From: Geoffrey Thomas Date: Tue, 20 Jun 2017 01:13:29 -0400 Subject: [PATCH] Enable ptrace on all Linux platforms Nothing that nix currently binds is architecture-specific, and Android supports ptrace just as much as non-Android Linux. --- CHANGELOG.md | 3 +++ src/sys/mod.rs | 6 +----- src/sys/ptrace.rs | 5 ----- test/sys/mod.rs | 2 ++ test/sys/test_ptrace.rs | 14 ++++++++++++++ 5 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 test/sys/test_ptrace.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 5fa342c48e..15f42a45d3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -57,6 +57,9 @@ This project adheres to [Semantic Versioning](http://semver.org/). `Android` ([#631](https://github.com/nix-rust/nix/pull/631)). - `bind` and `errno_location` now work correctly on `Android` ([#631](https://github.com/nix-rust/nix/pull/631)) +- Added `nix::ptrace` on all Linux-kernel-based platforms + [#624](https://github.com/nix-rust/nix/pull/624). Previously it was + only available on x86, x86-64, and ARM, and also not on Android. ## [0.8.1] 2017-04-16 diff --git a/src/sys/mod.rs b/src/sys/mod.rs index 69632f008f..783b83642b 100644 --- a/src/sys/mod.rs +++ b/src/sys/mod.rs @@ -52,11 +52,7 @@ pub mod uio; pub mod time; -#[cfg(all(target_os = "linux", - any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm")), - )] +#[cfg(any(target_os = "linux", target_os = "android"))] pub mod ptrace; pub mod select; diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs index 17dfee3493..bf395259cf 100644 --- a/src/sys/ptrace.rs +++ b/src/sys/ptrace.rs @@ -3,11 +3,6 @@ use {Errno, Error, Result}; use libc::{c_void, c_long, siginfo_t}; use ::unistd::Pid; -#[cfg(all(target_os = "linux", - any(target_arch = "x86", - target_arch = "x86_64", - target_arch = "arm")), - )] pub mod ptrace { use libc::c_int; diff --git a/test/sys/mod.rs b/test/sys/mod.rs index e93b0d285e..4edb6af036 100644 --- a/test/sys/mod.rs +++ b/test/sys/mod.rs @@ -13,3 +13,5 @@ mod test_uio; #[cfg(target_os = "linux")] mod test_epoll; mod test_pthread; +#[cfg(any(target_os = "linux", target_os = "android"))] +mod test_ptrace; diff --git a/test/sys/test_ptrace.rs b/test/sys/test_ptrace.rs new file mode 100644 index 0000000000..6318495a2d --- /dev/null +++ b/test/sys/test_ptrace.rs @@ -0,0 +1,14 @@ +use nix::Error; +use nix::errno::*; +use nix::unistd::*; +use nix::sys::ptrace::*; +use nix::sys::ptrace::ptrace::*; +use std::ptr; + +#[test] +fn test_ptrace() { + // Just make sure ptrace can be called at all, for now. + // FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS + 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)); +}