Skip to content

Commit c285b95

Browse files
committed
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.
1 parent 19affae commit c285b95

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/sys/ptrace/linux.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use libc::{self, c_void, c_long, siginfo_t};
77
use ::unistd::Pid;
88
use sys::signal::Signal;
99

10+
pub type AddressType = *mut ::libc::c_void;
1011

1112
cfg_if! {
1213
if #[cfg(any(all(target_os = "linux", arch = "s390x"),
@@ -170,7 +171,7 @@ libc_bitflags! {
170171
since="0.10.0",
171172
note="usages of `ptrace()` should be replaced with the specialized helper functions instead"
172173
)]
173-
pub unsafe fn ptrace(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
174+
pub unsafe fn ptrace(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result<c_long> {
174175
use self::Request::*;
175176
match request {
176177
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
181182
}
182183
}
183184

184-
fn ptrace_peek(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
185+
fn ptrace_peek(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result<c_long> {
185186
let ret = unsafe {
186187
Errno::clear();
187188
libc::ptrace(request as RequestType, libc::pid_t::from(pid), addr, data)
@@ -209,7 +210,7 @@ fn ptrace_get_data<T>(request: Request, pid: Pid) -> Result<T> {
209210
Ok(data)
210211
}
211212

212-
unsafe fn ptrace_other(request: Request, pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<c_long> {
213+
unsafe fn ptrace_other(request: Request, pid: Pid, addr: AddressType, data: *mut c_void) -> Result<c_long> {
213214
Errno::result(libc::ptrace(request as RequestType, libc::pid_t::from(pid), addr, data)).map(|_| 0)
214215
}
215216

@@ -368,12 +369,12 @@ pub fn step<T: Into<Option<Signal>>>(pid: Pid, sig: T) -> Result<()> {
368369

369370

370371
/// Reads a word from a processes memory at the given address
371-
pub fn read(pid: Pid, addr: *mut c_void) -> Result<c_long> {
372+
pub fn read(pid: Pid, addr: AddressType) -> Result<c_long> {
372373
ptrace_peek(Request::PTRACE_PEEKDATA, pid, addr, ptr::null_mut())
373374
}
374375

375376
/// Writes a word into the processes memory at the given address
376-
pub fn write(pid: Pid, addr: *mut c_void, data: *mut c_void) -> Result<()> {
377+
pub fn write(pid: Pid, addr: AddressType, data: *mut c_void) -> Result<()> {
377378
unsafe {
378379
ptrace_other(Request::PTRACE_POKEDATA, pid, addr, data).map(|_| ())
379380
}

0 commit comments

Comments
 (0)