@@ -3,8 +3,6 @@ use {Errno, Error, Result};
3
3
use libc:: { c_void, c_long, siginfo_t} ;
4
4
use :: unistd:: Pid ;
5
5
6
- //------------------ First part: a low-level wrapper for ptrace -----------------//
7
-
8
6
#[ cfg( all( target_os = "linux" ,
9
7
any( target_arch = "x86" ,
10
8
target_arch = "x86_64" ,
@@ -79,6 +77,7 @@ mod ffi {
79
77
/// Performs a `ptrace` request. If the request in question is provided by a specialised function
80
78
/// this function will return an unsupported operation error.
81
79
///
80
+ /// # Safety
82
81
/// When used incorrectly, this function may crash the tracer or the tracee, thus is marked `unsafe`.
83
82
pub unsafe fn ptrace ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
84
83
use self :: ptrace:: * ;
@@ -151,11 +150,8 @@ pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
151
150
}
152
151
}
153
152
154
- //-------------------------- Second part: a high-level wrapper for ptrace ----------------------//
155
-
156
153
#[ cfg( target_arch = "x86_64" ) ]
157
154
// We're going to export it anyway
158
- #[ allow( dead_code) ]
159
155
#[ allow( non_camel_case_types) ]
160
156
pub enum Register {
161
157
R15 = 0 * 8 ,
@@ -202,10 +198,11 @@ pub fn peekuser(pid: Pid, reg: Register) -> Result<Word> {
202
198
unsafe {
203
199
ptrace ( ptrace:: PTRACE_PEEKUSER , pid, reg_arg, ptr:: null_mut ( ) ) . map ( |r| r as Word )
204
200
}
205
- }
201
+ }
206
202
207
203
/// Makes the `PTRACE_POKEUSER` request to ptrace
208
- ///
204
+ ///
205
+ /// # Safety
209
206
/// When incorrectly used, may change the registers to bad values,
210
207
/// causing e.g. memory being corrupted by a syscall, thus is marked unsafe
211
208
pub unsafe fn pokeuser ( pid : Pid , reg : Register , val : Word ) -> Result < ( ) > {
@@ -226,17 +223,19 @@ pub fn traceme() -> Result<()> {
226
223
}
227
224
228
225
/// Makes the `PTRACE_PEEKDATA` request to ptrace
229
- ///
226
+ ///
227
+ /// # Safety
230
228
/// This function allows to access arbitrary data in the traced process
231
229
/// and may crash the inferior if used incorrectly and is thus marked `unsafe`.
232
230
pub unsafe fn peekdata ( pid : Pid , addr : usize ) -> Result < Word > {
233
231
ptrace ( ptrace:: PTRACE_PEEKDATA , pid, addr as * mut c_void , ptr:: null_mut ( ) ) . map ( |r| r as Word )
234
232
}
235
233
236
- /// Makes the `PTRACE_PEEKDATA ` request to ptrace
234
+ /// Makes the `PTRACE_POKEDATA ` request to ptrace
237
235
///
236
+ /// # Safety
238
237
/// This function allows to access arbitrary data in the traced process
239
- /// and may crash the inferior or introduce race conditions if used
238
+ /// and may crash the inferior or introduce race conditions if used
240
239
/// incorrectly and is thus marked `unsafe`.
241
240
pub unsafe fn pokedata ( pid : Pid , addr : usize , val : Word ) -> Result < ( ) > {
242
241
ptrace (
0 commit comments