summaryrefslogtreecommitdiff
path: root/src/sys/ptrace.rs
diff options
context:
space:
mode:
authorMarcin Mielniczuk <marmistrz.dev@zoho.eu>2017-07-26 09:53:11 +0200
committerMarcin Mielniczuk <marmistrz.dev@zoho.eu>2017-07-26 09:53:11 +0200
commitb03011fcc39cb1fce1686f6c4ac180c218d611f3 (patch)
tree79d684e7cb982de60c5f61a34a5bd651f1341920 /src/sys/ptrace.rs
parente08a430226a3b823278795fe8671c264f9ae6594 (diff)
downloadnix-b03011fcc39cb1fce1686f6c4ac180c218d611f3.zip
Mark nix::sys::ptrace::ptrace as unsafe, add safe variants of source routines.
These include: * PTRACE_TRACEME * PTRACE_CONT * PTRACE_ATTACH * PTRACE_SYSCALL
Diffstat (limited to 'src/sys/ptrace.rs')
-rw-r--r--src/sys/ptrace.rs50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/sys/ptrace.rs b/src/sys/ptrace.rs
index 877bfcb0..d83c6e09 100644
--- a/src/sys/ptrace.rs
+++ b/src/sys/ptrace.rs
@@ -70,7 +70,7 @@ mod ffi {
/// Performs a ptrace request. If the request in question is provided by a specialised function
/// this function will return an unsupported operation error.
-pub fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
+pub unsafe fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
use self::ptrace::*;
match request {
@@ -140,3 +140,51 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
Err(e) => Err(e),
}
}
+
+/// Sets the process as traceable with `PTRACE_TRACEME`
+pub fn traceme() -> Result<()> {
+ unsafe {
+ ptrace(
+ ptrace::PTRACE_TRACEME,
+ Pid::from_raw(0),
+ ptr::null_mut(),
+ ptr::null_mut(),
+ ).map(|_| ()) // ignore the useless return value
+ }
+}
+
+/// Makes the `PTRACE_SYSCALL` request to ptrace
+pub fn syscall(pid: Pid) -> Result<()> {
+ unsafe {
+ ptrace(
+ ptrace::PTRACE_SYSCALL,
+ pid,
+ ptr::null_mut(),
+ ptr::null_mut(),
+ ).map(|_| ()) // ignore the useless return value
+ }
+}
+
+/// Makes the `PTRACE_ATTACH` request to ptrace
+pub fn attach(pid: Pid) -> Result<()> {
+ unsafe {
+ ptrace(
+ ptrace::PTRACE_ATTACH,
+ pid,
+ ptr::null_mut(),
+ ptr::null_mut(),
+ ).map(|_| ()) // ignore the useless return value
+ }
+}
+
+/// Makes the `PTRACE_CONT` request to ptrace
+pub fn cont(pid: Pid) -> Result<()> {
+ unsafe {
+ ptrace(
+ ptrace::PTRACE_CONT,
+ pid,
+ ptr::null_mut(),
+ ptr::null_mut(),
+ ).map(|_| ()) // ignore the useless return value
+ }
+}