Skip to content

Commit 9e49a89

Browse files
committed
Added fix for ptrace from PR nix-rust#566
1 parent f8406b8 commit 9e49a89

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/sys/ptrace.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ pub mod ptrace {
5858
pub const PTRACE_O_TRACEVFORKDONE: PtraceOptions = (1 << PTRACE_EVENT_VFORK_DONE);
5959
pub const PTRACE_O_TRACEEXIT: PtraceOptions = (1 << PTRACE_EVENT_EXIT);
6060
pub const PTRACE_O_TRACESECCOMP: PtraceOptions = (1 << PTRACE_EVENT_SECCOMP);
61+
62+
6163
}
6264

6365
mod ffi {

src/sys/wait.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub enum WaitStatus {
4747
Stopped(Pid, Signal),
4848
#[cfg(any(target_os = "linux", target_os = "android"))]
4949
PtraceEvent(Pid, Signal, c_int),
50+
#[cfg(any(target_os = "linux", target_os = "android"))]
51+
PtraceSyscall(Pid),
5052
Continued(Pid),
5153
StillAlive
5254
}
@@ -56,6 +58,7 @@ pub enum WaitStatus {
5658
mod status {
5759
use sys::signal::Signal;
5860
use libc::c_int;
61+
use libc::SIGTRAP;
5962

6063
pub fn exited(status: i32) -> bool {
6164
(status & 0x7F) == 0
@@ -88,6 +91,9 @@ mod status {
8891
pub fn stop_additional(status: i32) -> c_int {
8992
(status >> 16) as c_int
9093
}
94+
pub fn syscall_stop(status: i32) -> bool {
95+
((status & 0xFF00) >> 8) == SIGTRAP | 0x80
96+
}
9197

9298
pub fn continued(status: i32) -> bool {
9399
status == 0xFFFF
@@ -145,6 +151,7 @@ mod status {
145151
target_os = "netbsd"))]
146152
mod status {
147153
use sys::signal::Signal;
154+
use libc::SIGTRAP;
148155

149156
const WCOREFLAG: i32 = 0x80;
150157
const WSTOPPED: i32 = 0x7f;
@@ -196,7 +203,9 @@ fn decode(pid : Pid, status: i32) -> WaitStatus {
196203
if #[cfg(any(target_os = "linux", target_os = "android"))] {
197204
fn decode_stopped(pid: Pid, status: i32) -> WaitStatus {
198205
let status_additional = status::stop_additional(status);
199-
if status_additional == 0 {
206+
if status::syscall_stop(status) {
207+
WaitStatus::PtraceSyscall(pid)
208+
} else if status_additional == 0 {
200209
WaitStatus::Stopped(pid, status::stop_signal(status))
201210
} else {
202211
WaitStatus::PtraceEvent(pid, status::stop_signal(status), status::stop_additional(status))

0 commit comments

Comments
 (0)