Skip to content

Commit 7a91a81

Browse files
committed
Auto merge of #438 - chaosagent:wait-ptrace, r=kamalmarhubi
wait: Support ptrace events for Linux Adds new WaitStatus value `PtraceEvent`. Implementation of #273 that only affects Linux/Android.
2 parents 109b0e8 + e6bfbbb commit 7a91a81

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

src/sys/wait.rs

+24-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ pub enum WaitStatus {
4444
Exited(pid_t, i8),
4545
Signaled(pid_t, Signal, bool),
4646
Stopped(pid_t, Signal),
47+
#[cfg(any(target_os = "linux", target_os = "android"))]
48+
PtraceEvent(pid_t, Signal, c_int),
4749
Continued(pid_t),
4850
StillAlive
4951
}
@@ -52,6 +54,7 @@ pub enum WaitStatus {
5254
target_os = "android"))]
5355
mod status {
5456
use sys::signal::Signal;
57+
use libc::c_int;
5558

5659
pub fn exited(status: i32) -> bool {
5760
(status & 0x7F) == 0
@@ -81,6 +84,10 @@ mod status {
8184
Signal::from_c_int((status & 0xFF00) >> 8).unwrap()
8285
}
8386

87+
pub fn stop_additional(status: i32) -> c_int {
88+
(status >> 16) as c_int
89+
}
90+
8491
pub fn continued(status: i32) -> bool {
8592
status == 0xFFFF
8693
}
@@ -184,7 +191,23 @@ fn decode(pid : pid_t, status: i32) -> WaitStatus {
184191
} else if status::signaled(status) {
185192
WaitStatus::Signaled(pid, status::term_signal(status), status::dumped_core(status))
186193
} else if status::stopped(status) {
187-
WaitStatus::Stopped(pid, status::stop_signal(status))
194+
cfg_if! {
195+
if #[cfg(any(target_os = "linux", target_os = "android"))] {
196+
fn decode_stopped(pid: pid_t, status: i32) -> WaitStatus {
197+
let status_additional = status::stop_additional(status);
198+
if status_additional == 0 {
199+
WaitStatus::Stopped(pid, status::stop_signal(status))
200+
} else {
201+
WaitStatus::PtraceEvent(pid, status::stop_signal(status), status::stop_additional(status))
202+
}
203+
}
204+
} else {
205+
fn decode_stopped(pid: pid_t, status: i32) -> WaitStatus {
206+
WaitStatus::Stopped(pid, status::stop_signal(status))
207+
}
208+
}
209+
}
210+
decode_stopped(pid, status)
188211
} else {
189212
assert!(status::continued(status));
190213
WaitStatus::Continued(pid)

0 commit comments

Comments
 (0)