22
33use std:: { mem, ptr} ;
44use { Errno , Error , Result } ;
5- use libc:: { c_void, c_long, siginfo_t} ;
5+ use libc:: { self , c_void, c_long, siginfo_t} ;
66use :: unistd:: Pid ;
77use sys:: signal:: Signal ;
88
99pub mod ptrace {
1010 use libc:: c_int;
1111
12- pub type PtraceRequest = c_int ;
12+ cfg_if ! {
13+ if #[ cfg( any( all( target_os = "linux" , arch = "s390x" ) ,
14+ all( target_os = "linux" , target_env = "gnu" ) ) ) ] {
15+ pub type PtraceRequest = :: libc:: c_uint;
16+ } else {
17+ pub type PtraceRequest = c_int;
18+ }
19+ }
1320
1421 pub const PTRACE_TRACEME : PtraceRequest = 0 ;
1522 pub const PTRACE_PEEKTEXT : PtraceRequest = 1 ;
@@ -63,14 +70,6 @@ pub mod ptrace {
6370 pub const PTRACE_O_TRACESECCOMP : PtraceOptions = ( 1 << PTRACE_EVENT_SECCOMP ) ;
6471}
6572
66- mod ffi {
67- use libc:: { pid_t, c_int, c_long, c_void} ;
68-
69- extern {
70- pub fn ptrace ( request : c_int , pid : pid_t , addr : * const c_void , data : * const c_void ) -> c_long ;
71- }
72- }
73-
7473/// Performs a ptrace request. If the request in question is provided by a specialised function
7574/// this function will return an unsupported operation error.
7675#[ deprecated(
@@ -90,7 +89,7 @@ pub unsafe fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void
9089fn ptrace_peek ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
9190 let ret = unsafe {
9291 Errno :: clear ( ) ;
93- ffi :: ptrace ( request, pid . into ( ) , addr, data)
92+ libc :: ptrace ( request, libc :: pid_t :: from ( pid ) , addr, data)
9493 } ;
9594 match Errno :: result ( ret) {
9695 Ok ( ..) | Err ( Error :: Sys ( Errno :: UnknownErrno ) ) => Ok ( ret) ,
@@ -105,21 +104,21 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data
105104fn ptrace_get_data < T > ( request : ptrace:: PtraceRequest , pid : Pid ) -> Result < T > {
106105 // Creates an uninitialized pointer to store result in
107106 let data: T = unsafe { mem:: uninitialized ( ) } ;
108- let res = unsafe { ffi :: ptrace ( request, pid . into ( ) , ptr:: null_mut ( ) , & data as * const _ as * const c_void ) } ;
107+ let res = unsafe { libc :: ptrace ( request, libc :: pid_t :: from ( pid ) , ptr:: null_mut :: < T > ( ) , & data as * const _ as * const c_void ) } ;
109108 Errno :: result ( res) ?;
110109 Ok ( data)
111110}
112111
113112unsafe fn ptrace_other ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
114- Errno :: result ( ffi :: ptrace ( request, pid . into ( ) , addr, data) ) . map ( |_| 0 )
113+ Errno :: result ( libc :: ptrace ( request, libc :: pid_t :: from ( pid ) , addr, data) ) . map ( |_| 0 )
115114}
116115
117116/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
118117pub fn setoptions ( pid : Pid , options : ptrace:: PtraceOptions ) -> Result < ( ) > {
119118 use self :: ptrace:: * ;
120119 use std:: ptr;
121120
122- let res = unsafe { ffi :: ptrace ( PTRACE_SETOPTIONS , pid . into ( ) , ptr:: null_mut ( ) , options as * mut c_void ) } ;
121+ let res = unsafe { libc :: ptrace ( PTRACE_SETOPTIONS , libc :: pid_t :: from ( pid ) , ptr:: null_mut :: < libc :: c_void > ( ) , options as * mut c_void ) } ;
123122 Errno :: result ( res) . map ( |_| ( ) )
124123}
125124
@@ -140,7 +139,7 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
140139 use self :: ptrace:: * ;
141140 let ret = unsafe {
142141 Errno :: clear ( ) ;
143- ffi :: ptrace ( PTRACE_SETSIGINFO , pid . into ( ) , ptr:: null_mut ( ) , sig as * const _ as * const c_void )
142+ libc :: ptrace ( PTRACE_SETSIGINFO , libc :: pid_t :: from ( pid ) , ptr:: null_mut :: < libc :: c_void > ( ) , sig as * const _ as * const c_void )
144143 } ;
145144 match Errno :: result ( ret) {
146145 Ok ( _) => Ok ( ( ) ) ,
0 commit comments