File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,8 @@ libc_enum! {
146146 #[ cfg( all( target_os = "linux" , target_env = "gnu" ,
147147 any( target_arch = "x86" , target_arch = "x86_64" ) ) ) ]
148148 PTRACE_SYSEMU_SINGLESTEP ,
149+ #[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
150+ PTRACE_GET_SYSCALL_INFO ,
149151 }
150152}
151153
@@ -567,6 +569,12 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
567569 }
568570}
569571
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+
570578/// Sets the process as traceable, as with `ptrace(PTRACE_TRACEME, ...)`
571579///
572580/// Indicates that this process is to be traced by its parent.
Original file line number Diff line number Diff line change @@ -381,3 +381,30 @@ fn test_ptrace_regsets() {
381381 }
382382 }
383383}
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+ std:: thread:: sleep ( std:: time:: Duration :: from_millis ( 1000 ) ) ;
400+ unsafe {
401+ :: libc:: _exit ( 0 ) ;
402+ }
403+ }
404+ Parent { child } => {
405+ assert_eq ! ( waitpid( child, None ) , Ok ( WaitStatus :: Exited ( child, 0 ) ) ) ;
406+ let si = ptrace:: syscall_info ( child) . unwrap ( ) ;
407+ assert ! ( si. op >= libc:: PTRACE_SYSCALL_INFO_ENTRY ) ;
408+ }
409+ }
410+ }
You can’t perform that action at this time.
0 commit comments