@@ -151,7 +151,7 @@ pub fn ptrace_setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
151151 }
152152}
153153
154- //-------------------------- Second part: a low -level wrapper for ptrace ----------------------//
154+ //-------------------------- Second part: a high -level wrapper for ptrace ----------------------//
155155
156156#[ cfg( target_arch = "x86_64" ) ]
157157// We're going to export it anyway
@@ -187,13 +187,15 @@ pub enum Register {
187187 GS = 26 * 8 ,
188188}
189189
190+ type Word = usize ;
191+
190192/// Makes the `PTRACE_SYSCALL` request to ptrace
191193pub fn syscall ( pid : Pid ) -> Result < ( ) > {
192194 ptrace ( ptrace:: PTRACE_SYSCALL , pid, ptr:: null_mut ( ) , ptr:: null_mut ( ) ) . map ( |_| ( ) ) // ignore the useless return value
193195}
194196
195197/// 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 > {
197199 let reg_arg = ( reg as i32 ) as * mut c_void ;
198200 ptrace ( ptrace:: PTRACE_PEEKUSER , pid, reg_arg, ptr:: null_mut ( ) )
199201}
@@ -212,7 +214,7 @@ pub fn traceme() -> Result<()> {
212214///
213215/// This function allows to access arbitrary data in the traced process
214216/// 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 > {
216218 ptrace ( ptrace:: PTRACE_PEEKDATA , pid, addr as * mut c_void , ptr:: null_mut ( ) )
217219}
218220
@@ -221,11 +223,35 @@ pub unsafe fn peekdata(pid: Pid, addr: c_long) -> Result<c_long> {
221223/// This function allows to access arbitrary data in the traced process
222224/// and may crash the inferior or introduce race conditions if used
223225/// 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 < ( ) > {
225227 ptrace (
226228 ptrace:: PTRACE_POKEDATA ,
227229 pid,
228230 addr as * mut c_void ,
229231 val as * mut c_void ,
230232 ) . 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