From c285b95c8cb21e88f6868419370315e432b8be78 Mon Sep 17 00:00:00 2001 From: xd009642 Date: Mon, 22 Oct 2018 18:56:36 +0100 Subject: [PATCH 1/2] Added AddressType type This was added to the BSD ptrace API and probably should have been added to tyhe linux API to make it easier to write code for both platforms without the user having to reexport the types to their own crate. --- src/sys/ptrace/linux.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 70404ade29..9821f2aed7 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -7,6 +7,7 @@ use libc::{self, c_void, c_long, siginfo_t}; use ::unistd::Pid; use sys::signal::Signal; +pub type AddressType = *mut ::libc::c_void; cfg_if! { if #[cfg(any(all(target_os = "linux", arch = "s390x"), @@ -170,7 +171,7 @@ libc_bitflags! { since="0.10.0", note="usages of `ptrace()` should be replaced with the specialized helper functions instead" )] -pub unsafe fn ptrace(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result { +pub unsafe fn ptrace(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result { use self::Request::*; match request { PTRACE_PEEKTEXT | PTRACE_PEEKDATA | PTRACE_PEEKUSER | PTRACE_GETSIGINFO | @@ -181,7 +182,7 @@ pub unsafe fn ptrace(request: Request, pid: Pid, addr: *mut c_void, data: *mut c } } -fn ptrace_peek(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result { +fn ptrace_peek(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result { let ret = unsafe { Errno::clear(); libc::ptrace(request as RequestType, libc::pid_t::from(pid), addr, data) @@ -209,7 +210,7 @@ fn ptrace_get_data(request: Request, pid: Pid) -> Result { Ok(data) } -unsafe fn ptrace_other(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result { +unsafe fn ptrace_other(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result { Errno::result(libc::ptrace(request as RequestType, libc::pid_t::from(pid), addr, data)).map(|_| 0) } @@ -368,12 +369,12 @@ pub fn step>>(pid: Pid, sig: T) -> Result<()> { /// Reads a word from a processes memory at the given address -pub fn read(pid: Pid, addr: *mut c_void) -> Result { +pub fn read(pid: Pid, addr: AddressType) -> Result { ptrace_peek(Request::PTRACE_PEEKDATA, pid, addr, ptr::null_mut()) } /// Writes a word into the processes memory at the given address -pub fn write(pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<()> { +pub fn write(pid: Pid, addr: AddressType, data: *mut c_void) -> Result<()> { unsafe { ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(|_| ()) } From 12578ded29b35b84756df55cec65198bd115782b Mon Sep 17 00:00:00 2001 From: xd009642 Date: Mon, 22 Oct 2018 23:20:36 +0100 Subject: [PATCH 2/2] Removed Peek and poke user from unsupportedOp --- CHANGELOG.md | 2 +- src/sys/ptrace/linux.rs | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9d809501ce..dd76763d1d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,7 +27,7 @@ This project adheres to [Semantic Versioning](http://semver.org/). ([#955](https://github.com/nix-rust/nix/pull/955)) - Added support for `ptrace` on BSD operating systems ([#949](https://github.com/nix-rust/nix/pull/949)) - Added `ptrace` functions for reads and writes to tracee memory and ptrace kill - ([#949](https://github.com/nix-rust/nix/pull/949)) + ([#949](https://github.com/nix-rust/nix/pull/949)) ([#958](https://github.com/nix-rust/nix/pull/958)) - Added a `acct` wrapper module for enabling and disabling process accounting ([#952](https://github.com/nix-rust/nix/pull/952)) diff --git a/src/sys/ptrace/linux.rs b/src/sys/ptrace/linux.rs index 9821f2aed7..6bd3970580 100644 --- a/src/sys/ptrace/linux.rs +++ b/src/sys/ptrace/linux.rs @@ -174,10 +174,9 @@ libc_bitflags! { pub unsafe fn ptrace(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result { use self::Request::*; match request { - PTRACE_PEEKTEXT | PTRACE_PEEKDATA | PTRACE_PEEKUSER | PTRACE_GETSIGINFO | + PTRACE_PEEKTEXT | PTRACE_PEEKDATA | PTRACE_GETSIGINFO | PTRACE_GETEVENTMSG | PTRACE_SETSIGINFO | PTRACE_SETOPTIONS | - PTRACE_POKETEXT | PTRACE_POKEDATA | PTRACE_POKEUSER | - PTRACE_KILL => Err(Error::UnsupportedOperation), + PTRACE_POKETEXT | PTRACE_POKEDATA | PTRACE_KILL => Err(Error::UnsupportedOperation), _ => ptrace_other(request, pid, addr, data) } }