Skip to content

Commit 1ee6634

Browse files
droundycarllerche
authored andcommitted
add function for handling PTRACE_SETOPTIONS nicely
1 parent ecb18ff commit 1ee6634

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/sys/ptrace.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,27 @@ pub mod ptrace {
4141
pub const PTRACE_INTERRUPT: PtraceRequest = 0x4207;
4242
pub const PTRACE_LISTEN: PtraceRequest = 0x4208;
4343
pub const PTRACE_PEEKSIGINFO: PtraceRequest = 0x4209;
44+
45+
pub type PtraceEvent = c_int;
46+
47+
pub const PTRACE_EVENT_FORK: PtraceEvent = 1;
48+
pub const PTRACE_EVENT_VFORK: PtraceEvent = 2;
49+
pub const PTRACE_EVENT_CLONE: PtraceEvent = 3;
50+
pub const PTRACE_EVENT_EXEC: PtraceEvent = 4;
51+
pub const PTRACE_EVENT_VFORK_DONE: PtraceEvent = 5;
52+
pub const PTRACE_EVENT_EXIT: PtraceEvent = 6;
53+
pub const PTRACE_EVENT_SECCOMP: PtraceEvent = 6;
54+
pub const PTRACE_EVENT_STOP: PtraceEvent = 128;
55+
56+
pub type PtraceOptions = c_int;
57+
pub const PTRACE_O_TRACESYSGOOD: PtraceOptions = 1;
58+
pub const PTRACE_O_TRACEFORK: PtraceOptions = (1 << PTRACE_EVENT_FORK);
59+
pub const PTRACE_O_TRACEVFORK: PtraceOptions = (1 << PTRACE_EVENT_VFORK);
60+
pub const PTRACE_O_TRACECLONE: PtraceOptions = (1 << PTRACE_EVENT_CLONE);
61+
pub const PTRACE_O_TRACEEXEC: PtraceOptions = (1 << PTRACE_EVENT_EXEC);
62+
pub const PTRACE_O_TRACEVFORKDONE: PtraceOptions = (1 << PTRACE_EVENT_VFORK_DONE);
63+
pub const PTRACE_O_TRACEEXIT: PtraceOptions = (1 << PTRACE_EVENT_EXIT);
64+
pub const PTRACE_O_TRACESECCOMP: PtraceOptions = (1 << PTRACE_EVENT_SECCOMP);
4465
}
4566

4667
mod ffi {
@@ -77,3 +98,13 @@ fn ptrace_other(request: ptrace::PtraceRequest, pid: pid_t, addr: *mut c_void, d
7798
_ => Ok(0)
7899
}
79100
}
101+
102+
/// Set options, as with ptrace(PTRACE_SETOPTIONS,...).
103+
pub fn ptrace_setoptions(pid: pid_t, options: ptrace::PtraceOptions) -> Result<()> {
104+
use self::ptrace::*;
105+
use std::ptr;
106+
107+
try!(ptrace(PTRACE_SETOPTIONS, pid, ptr::null_mut(), options as *mut c_void));
108+
Ok(())
109+
}
110+

0 commit comments

Comments
 (0)