Skip to content

Commit

Permalink
Added fix for ptrace from PR nix-rust#566
Browse files Browse the repository at this point in the history
  • Loading branch information
vincenthage committed Jul 18, 2017
1 parent f8406b8 commit 9e49a89
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/sys/ptrace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub mod ptrace {
pub const PTRACE_O_TRACEVFORKDONE: PtraceOptions = (1 << PTRACE_EVENT_VFORK_DONE);
pub const PTRACE_O_TRACEEXIT: PtraceOptions = (1 << PTRACE_EVENT_EXIT);
pub const PTRACE_O_TRACESECCOMP: PtraceOptions = (1 << PTRACE_EVENT_SECCOMP);


}

mod ffi {
Expand Down
11 changes: 10 additions & 1 deletion src/sys/wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub enum WaitStatus {
Stopped(Pid, Signal),
#[cfg(any(target_os = "linux", target_os = "android"))]
PtraceEvent(Pid, Signal, c_int),
#[cfg(any(target_os = "linux", target_os = "android"))]
PtraceSyscall(Pid),
Continued(Pid),
StillAlive
}
Expand All @@ -56,6 +58,7 @@ pub enum WaitStatus {
mod status {
use sys::signal::Signal;
use libc::c_int;
use libc::SIGTRAP;

pub fn exited(status: i32) -> bool {
(status & 0x7F) == 0
Expand Down Expand Up @@ -88,6 +91,9 @@ mod status {
pub fn stop_additional(status: i32) -> c_int {
(status >> 16) as c_int
}
pub fn syscall_stop(status: i32) -> bool {
((status & 0xFF00) >> 8) == SIGTRAP | 0x80
}

pub fn continued(status: i32) -> bool {
status == 0xFFFF
Expand Down Expand Up @@ -145,6 +151,7 @@ mod status {
target_os = "netbsd"))]
mod status {
use sys::signal::Signal;
use libc::SIGTRAP;

const WCOREFLAG: i32 = 0x80;
const WSTOPPED: i32 = 0x7f;
Expand Down Expand Up @@ -196,7 +203,9 @@ fn decode(pid : Pid, status: i32) -> WaitStatus {
if #[cfg(any(target_os = "linux", target_os = "android"))] {
fn decode_stopped(pid: Pid, status: i32) -> WaitStatus {
let status_additional = status::stop_additional(status);
if status_additional == 0 {
if status::syscall_stop(status) {
WaitStatus::PtraceSyscall(pid)
} else if status_additional == 0 {
WaitStatus::Stopped(pid, status::stop_signal(status))
} else {
WaitStatus::PtraceEvent(pid, status::stop_signal(status), status::stop_additional(status))
Expand Down

0 comments on commit 9e49a89

Please sign in to comment.