Skip to content

Commit 0bf5af5

Browse files
committed
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.
1 parent 46e77b5 commit 0bf5af5

File tree

5 files changed

+20
-10
lines changed

5 files changed

+20
-10
lines changed

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
5757
`Android` ([#631](https://github.com/nix-rust/nix/pull/631)).
5858
- `bind` and `errno_location` now work correctly on `Android`
5959
([#631](https://github.com/nix-rust/nix/pull/631))
60+
- Added `nix::ptrace` on all Linux-kernel-based platforms
61+
[#624](https://github.com/nix-rust/nix/pull/624). Previously it was
62+
only available on x86, x86-64, and ARM, and also not on Android.
6063

6164
## [0.8.1] 2017-04-16
6265

src/sys/mod.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,7 @@ pub mod uio;
5252

5353
pub mod time;
5454

55-
#[cfg(all(target_os = "linux",
56-
any(target_arch = "x86",
57-
target_arch = "x86_64",
58-
target_arch = "arm")),
59-
)]
55+
#[cfg(any(target_os = "linux", target_os = "android"))]
6056
pub mod ptrace;
6157

6258
pub mod select;

src/sys/ptrace.rs

-5
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ use {Errno, Error, Result};
33
use libc::{c_void, c_long, siginfo_t};
44
use ::unistd::Pid;
55

6-
#[cfg(all(target_os = "linux",
7-
any(target_arch = "x86",
8-
target_arch = "x86_64",
9-
target_arch = "arm")),
10-
)]
116
pub mod ptrace {
127
use libc::c_int;
138

test/sys/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ mod test_uio;
1313
#[cfg(target_os = "linux")]
1414
mod test_epoll;
1515
mod test_pthread;
16+
#[cfg(any(target_os = "linux", target_os = "android"))]
17+
mod test_ptrace;

test/sys/test_ptrace.rs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
use nix::Error;
2+
use nix::errno::*;
3+
use nix::unistd::*;
4+
use nix::sys::ptrace::*;
5+
use nix::sys::ptrace::ptrace::*;
6+
use std::ptr;
7+
8+
#[test]
9+
fn test_ptrace() {
10+
// Just make sure ptrace can be called at all, for now.
11+
// FIXME: qemu-user doesn't implement ptrace on all arches, so permit ENOSYS
12+
let err = ptrace(PTRACE_ATTACH, getpid(), ptr::null_mut(), ptr::null_mut()).unwrap_err();
13+
assert!(err == Error::Sys(Errno::EPERM) || err == Error::Sys(Errno::ENOSYS));
14+
}

0 commit comments

Comments
 (0)