summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Roundy <roundyd@physics.oregonstate.edu>2015-12-02 15:39:56 -0500
committerCarl Lerche <me@carllerche.com>2015-12-03 13:17:07 -0800
commit1ee6634e8e323ffa3bafc9fe5d03c95d505666ba (patch)
tree7e27e4351a72fb2ac70a20eed6c54e7a123851de /src
parentecb18ff11d53a83ec3501db0a7b1e2dd3020bb12 (diff)
downloadnix-1ee6634e8e323ffa3bafc9fe5d03c95d505666ba.zip
add function for handling PTRACE_SETOPTIONS nicely
Diffstat (limited to 'src')
-rw-r--r--src/sys/ptrace.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs
index 5fd00907..7c8c3e8e 100644
--- a/src/sys/ptrace.rs
+++ b/src/sys/ptrace.rs
@@ -41,6 +41,27 @@ pub mod ptrace {
pub const PTRACE_INTERRUPT: PtraceRequest = 0x4207;
pub const PTRACE_LISTEN: PtraceRequest = 0x4208;
pub const PTRACE_PEEKSIGINFO: PtraceRequest = 0x4209;
+
+ pub type PtraceEvent = c_int;
+
+ pub const PTRACE_EVENT_FORK: PtraceEvent = 1;
+ pub const PTRACE_EVENT_VFORK: PtraceEvent = 2;
+ pub const PTRACE_EVENT_CLONE: PtraceEvent = 3;
+ pub const PTRACE_EVENT_EXEC: PtraceEvent = 4;
+ pub const PTRACE_EVENT_VFORK_DONE: PtraceEvent = 5;
+ pub const PTRACE_EVENT_EXIT: PtraceEvent = 6;
+ pub const PTRACE_EVENT_SECCOMP: PtraceEvent = 6;
+ pub const PTRACE_EVENT_STOP: PtraceEvent = 128;
+
+ pub type PtraceOptions = c_int;
+ pub const PTRACE_O_TRACESYSGOOD: PtraceOptions = 1;
+ pub const PTRACE_O_TRACEFORK: PtraceOptions = (1 << PTRACE_EVENT_FORK);
+ pub const PTRACE_O_TRACEVFORK: PtraceOptions = (1 << PTRACE_EVENT_VFORK);
+ pub const PTRACE_O_TRACECLONE: PtraceOptions = (1 << PTRACE_EVENT_CLONE);
+ pub const PTRACE_O_TRACEEXEC: PtraceOptions = (1 << PTRACE_EVENT_EXEC);
+ 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 {
@@ -77,3 +98,13 @@ fn ptrace_other(request: ptrace::PtraceRequest, pid: pid_t, addr: *mut c_void, d
_ => Ok(0)
}
}
+
+/// Set options, as with ptrace(PTRACE_SETOPTIONS,...).
+pub fn ptrace_setoptions(pid: pid_t, options: ptrace::PtraceOptions) -> Result<()> {
+ use self::ptrace::*;
+ use std::ptr;
+
+ try!(ptrace(PTRACE_SETOPTIONS, pid, ptr::null_mut(), options as *mut c_void));
+ Ok(())
+}
+