summaryrefslogtreecommitdiff
path: root/src/sys/ptrace
diff options
context:
space:
mode:
authorFrancisco Giordano <frangio.1@gmail.com>2019-06-09 18:54:48 -0300
committerFrancisco Giordano <frangio.1@gmail.com>2019-12-01 00:10:57 -0300
commit7f3ee09eec10ef5319a7b1d9c358f50638eb1471 (patch)
treedc604391947282743dbac3d06679c965a0c3c73e /src/sys/ptrace
parentf3bf1df774a6cb89cf04dced385ec073908508b0 (diff)
downloadnix-7f3ee09eec10ef5319a7b1d9c358f50638eb1471.zip
Allow signal injection in ptrace::{syscall, detach}
Diffstat (limited to 'src/sys/ptrace')
-rw-r--r--src/sys/ptrace/bsd.rs15
-rw-r--r--src/sys/ptrace/linux.rs24
2 files changed, 28 insertions, 11 deletions
diff --git a/src/sys/ptrace/bsd.rs b/src/sys/ptrace/bsd.rs
index 7797d106..18265d31 100644
--- a/src/sys/ptrace/bsd.rs
+++ b/src/sys/ptrace/bsd.rs
@@ -77,16 +77,23 @@ pub fn traceme() -> Result<()> {
/// Attach to a running process, as with `ptrace(PT_ATTACH, ...)`
///
-/// Attaches to the process specified in pid, making it a tracee of the calling process.
+/// Attaches to the process specified by `pid`, making it a tracee of the calling process.
pub fn attach(pid: Pid) -> Result<()> {
unsafe { ptrace_other(Request::PT_ATTACH, pid, ptr::null_mut(), 0).map(drop) }
}
/// Detaches the current running process, as with `ptrace(PT_DETACH, ...)`
///
-/// Detaches from the process specified in pid allowing it to run freely
-pub fn detach(pid: Pid) -> Result<()> {
- unsafe { ptrace_other(Request::PT_DETACH, pid, ptr::null_mut(), 0).map(drop) }
+/// Detaches from the process specified by `pid` allowing it to run freely, optionally delivering a
+/// signal specified by `sig`.
+pub fn detach<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
+ let data = match sig.into() {
+ Some(s) => s as c_int,
+ None => 0,
+ };
+ unsafe {
+ ptrace_other(Request::PT_DETACH, pid, ptr::null_mut(), data).map(drop)
+ }
}
/// Restart the stopped tracee process, as with `ptrace(PTRACE_CONT, ...)`
diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs
index ffe23d71..662425ae 100644
--- a/src/sys/ptrace/linux.rs
+++ b/src/sys/ptrace/linux.rs
@@ -289,21 +289,26 @@ pub fn traceme() -> Result<()> {
/// Ask for next syscall, as with `ptrace(PTRACE_SYSCALL, ...)`
///
-/// Arranges for the tracee to be stopped at the next entry to or exit from a system call.
-pub fn syscall(pid: Pid) -> Result<()> {
+/// Arranges for the tracee to be stopped at the next entry to or exit from a system call,
+/// optionally delivering a signal specified by `sig`.
+pub fn syscall<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
+ let data = match sig.into() {
+ Some(s) => s as i32 as *mut c_void,
+ None => ptr::null_mut(),
+ };
unsafe {
ptrace_other(
Request::PTRACE_SYSCALL,
pid,
ptr::null_mut(),
- ptr::null_mut(),
+ data,
).map(drop) // ignore the useless return value
}
}
/// Attach to a running process, as with `ptrace(PTRACE_ATTACH, ...)`
///
-/// Attaches to the process specified in pid, making it a tracee of the calling process.
+/// Attaches to the process specified by `pid`, making it a tracee of the calling process.
pub fn attach(pid: Pid) -> Result<()> {
unsafe {
ptrace_other(
@@ -332,14 +337,19 @@ pub fn seize(pid: Pid, options: Options) -> Result<()> {
/// Detaches the current running process, as with `ptrace(PTRACE_DETACH, ...)`
///
-/// Detaches from the process specified in pid allowing it to run freely
-pub fn detach(pid: Pid) -> Result<()> {
+/// Detaches from the process specified by `pid` allowing it to run freely, optionally delivering a
+/// signal specified by `sig`.
+pub fn detach<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
+ let data = match sig.into() {
+ Some(s) => s as i32 as *mut c_void,
+ None => ptr::null_mut(),
+ };
unsafe {
ptrace_other(
Request::PTRACE_DETACH,
pid,
ptr::null_mut(),
- ptr::null_mut()
+ data
).map(drop)
}
}