File tree 2 files changed +34
-0
lines changed 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,8 @@ libc_enum! {
146
146
#[ cfg( all( target_os = "linux" , target_env = "gnu" ,
147
147
any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
148
148
PTRACE_SYSEMU_SINGLESTEP ,
149
+ #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
150
+ PTRACE_GET_SYSCALL_INFO ,
149
151
}
150
152
}
151
153
@@ -567,6 +569,12 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
567
569
}
568
570
}
569
571
572
+ /// Get the informations of the syscall that caused the stop.
573
+ #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
574
+ pub fn syscall_info ( pid : Pid ) -> Result < libc:: ptrace_syscall_info > {
575
+ ptrace_get_data :: < libc:: ptrace_syscall_info > ( Request :: PTRACE_GET_SYSCALL_INFO , pid)
576
+ }
577
+
570
578
/// Sets the process as traceable, as with `ptrace(PTRACE_TRACEME, ...)`
571
579
///
572
580
/// Indicates that this process is to be traced by its parent.
Original file line number Diff line number Diff line change @@ -381,3 +381,29 @@ fn test_ptrace_regsets() {
381
381
}
382
382
}
383
383
}
384
+
385
+ #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
386
+ #[ test]
387
+ fn test_ptrace_syscall_info ( ) {
388
+ use nix:: sys:: ptrace;
389
+ use nix:: sys:: wait:: { waitpid, WaitStatus } ;
390
+ use nix:: unistd:: fork;
391
+ use nix:: unistd:: ForkResult :: * ;
392
+
393
+ require_capability ! ( "test_ptrace_interrupt" , CAP_SYS_PTRACE ) ;
394
+
395
+ let _m = crate :: FORK_MTX . lock ( ) ;
396
+ match unsafe { fork ( ) } . expect ( "Error: Fork Failed" ) {
397
+ Child => {
398
+ ptrace:: traceme ( ) . unwrap ( ) ;
399
+ unsafe {
400
+ :: libc:: _exit ( 0 ) ;
401
+ }
402
+ }
403
+ Parent { child } => {
404
+ assert_eq ! ( waitpid( child, None ) , Ok ( WaitStatus :: Exited ( child, 0 ) ) ) ;
405
+ let si = ptrace:: syscall_info ( child) . unwrap ( ) ;
406
+ assert ! ( si. op >= libc:: PTRACE_SYSCALL_INFO_ENTRY ) ;
407
+ }
408
+ }
409
+ }
You can’t perform that action at this time.
0 commit comments