@@ -151,7 +151,7 @@ pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
151
151
}
152
152
}
153
153
154
- //-------------------------- Second part: a low -level wrapper for ptrace ----------------------//
154
+ //-------------------------- Second part: a high -level wrapper for ptrace ----------------------//
155
155
156
156
#[ cfg( target_arch = "x86_64" ) ]
157
157
// We're going to export it anyway
@@ -187,13 +187,15 @@ pub enum Register {
187
187
GS = 26 * 8 ,
188
188
}
189
189
190
+ type Word = usize ;
191
+
190
192
/// Makes the `PTRACE_SYSCALL` request to ptrace
191
193
pub fn syscall ( pid : Pid ) -> Result < ( ) > {
192
194
ptrace ( ptrace:: PTRACE_SYSCALL , pid, ptr:: null_mut ( ) , ptr:: null_mut ( ) ) . map ( |_| ( ) ) // ignore the useless return value
193
195
}
194
196
195
197
/// Makes the `PTRACE_PEEKUSER` request to ptrace
196
- pub fn peekuser ( pid : Pid , reg : Register ) -> Result < c_long > {
198
+ pub fn peekuser ( pid : Pid , reg : Register ) -> Result < Word > {
197
199
let reg_arg = ( reg as i32 ) as * mut c_void ;
198
200
ptrace ( ptrace:: PTRACE_PEEKUSER , pid, reg_arg, ptr:: null_mut ( ) )
199
201
}
@@ -212,7 +214,7 @@ pub fn traceme() -> Result<()> {
212
214
///
213
215
/// This function allows to access arbitrary data in the traced process
214
216
/// and may crash the inferior if used incorrectly and is thus marked `unsafe`.
215
- pub unsafe fn peekdata ( pid : Pid , addr : c_long ) -> Result < c_long > {
217
+ pub unsafe fn peekdata ( pid : Pid , addr : usize ) -> Result < Word > {
216
218
ptrace ( ptrace:: PTRACE_PEEKDATA , pid, addr as * mut c_void , ptr:: null_mut ( ) )
217
219
}
218
220
@@ -221,11 +223,35 @@ pub unsafe fn peekdata(pid: Pid, addr: c_long) -> Result<c_long> {
221
223
/// This function allows to access arbitrary data in the traced process
222
224
/// and may crash the inferior or introduce race conditions if used
223
225
/// incorrectly and is thus marked `unsafe`.
224
- pub unsafe fn pokedata ( pid : Pid , addr : c_long , val : c_long ) -> Result < ( ) > {
226
+ pub unsafe fn pokedata ( pid : Pid , addr : usize , val : Word ) -> Result < ( ) > {
225
227
ptrace (
226
228
ptrace:: PTRACE_POKEDATA ,
227
229
pid,
228
230
addr as * mut c_void ,
229
231
val as * mut c_void ,
230
232
) . map ( |_| ( ) ) // ignore the useless return value
231
- }
233
+ }
234
+
235
+
236
+ #[ cfg( test) ]
237
+ mod tests {
238
+ use super :: * ;
239
+
240
+ #[ test]
241
+ fn test_registry ( ) {
242
+ let mut reg = OverrideRegistry :: new ( ) ;
243
+ let atenter = |_| {
244
+ HandlerData {
245
+ buflen : 0 ,
246
+ bufptr : 0 ,
247
+ }
248
+ } ;
249
+ let atexit = |_, _| { } ;
250
+
251
+ reg. add ( 17 , atenter, atexit) ;
252
+ let el = reg. find ( 17 ) . unwrap ( ) ;
253
+ assert_eq ! ( el. syscall, 17 ) ;
254
+ let len = ( el. atenter ) ( Pid :: from_raw ( 17 ) ) . buflen ;
255
+ assert_eq ! ( len, 0 ) ;
256
+ }
257
+ }
0 commit comments