11use std:: { mem, ptr} ;
22use { Errno , Error , Result } ;
3- use libc:: { pid_t, c_void, c_long, siginfo_t} ;
3+ use libc:: { c_void, c_long, siginfo_t} ;
4+ use :: unistd:: Pid ;
45
56#[ cfg( all( target_os = "linux" ,
67 any( target_arch = "x86" ,
@@ -74,7 +75,7 @@ mod ffi {
7475
7576/// Performs a ptrace request. If the request in question is provided by a specialised function
7677/// this function will return an unsupported operation error.
77- pub fn ptrace ( request : ptrace:: PtraceRequest , pid : pid_t , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
78+ pub fn ptrace ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
7879 use self :: ptrace:: * ;
7980
8081 match request {
@@ -84,10 +85,10 @@ pub fn ptrace(request: ptrace::PtraceRequest, pid: pid_t, addr: *mut c_void, dat
8485 }
8586}
8687
87- fn ptrace_peek ( request : ptrace:: PtraceRequest , pid : pid_t , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
88+ fn ptrace_peek ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
8889 let ret = unsafe {
8990 Errno :: clear ( ) ;
90- ffi:: ptrace ( request, pid, addr, data)
91+ ffi:: ptrace ( request, pid. into ( ) , addr, data)
9192 } ;
9293 match Errno :: result ( ret) {
9394 Ok ( ..) | Err ( Error :: Sys ( Errno :: UnknownErrno ) ) => Ok ( ret) ,
@@ -99,7 +100,7 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: pid_t, addr: *mut c_void, da
99100/// Some ptrace get requests populate structs or larger elements than c_long
100101/// and therefore use the data field to return values. This function handles these
101102/// requests.
102- fn ptrace_get_data < T > ( request : ptrace:: PtraceRequest , pid : pid_t ) -> Result < T > {
103+ fn ptrace_get_data < T > ( request : ptrace:: PtraceRequest , pid : Pid ) -> Result < T > {
103104 // Creates an uninitialized pointer to store result in
104105 let data: Box < T > = Box :: new ( unsafe { mem:: uninitialized ( ) } ) ;
105106 let data: * mut c_void = unsafe { mem:: transmute ( data) } ;
@@ -109,36 +110,36 @@ fn ptrace_get_data<T>(request: ptrace::PtraceRequest, pid: pid_t) -> Result<T> {
109110 Ok ( * data)
110111}
111112
112- fn ptrace_other ( request : ptrace:: PtraceRequest , pid : pid_t , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
113- Errno :: result ( unsafe { ffi:: ptrace ( request, pid, addr, data) } ) . map ( |_| 0 )
113+ fn ptrace_other ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
114+ Errno :: result ( unsafe { ffi:: ptrace ( request, pid. into ( ) , addr, data) } ) . map ( |_| 0 )
114115}
115116
116117/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
117- pub fn ptrace_setoptions ( pid : pid_t , options : ptrace:: PtraceOptions ) -> Result < ( ) > {
118+ pub fn ptrace_setoptions ( pid : Pid , options : ptrace:: PtraceOptions ) -> Result < ( ) > {
118119 use self :: ptrace:: * ;
119120 use std:: ptr;
120121
121122 ptrace ( PTRACE_SETOPTIONS , pid, ptr:: null_mut ( ) , options as * mut c_void ) . map ( drop)
122123}
123124
124125/// Gets a ptrace event as described by `ptrace(PTRACE_GETEVENTMSG,...)`
125- pub fn ptrace_getevent ( pid : pid_t ) -> Result < c_long > {
126+ pub fn ptrace_getevent ( pid : Pid ) -> Result < c_long > {
126127 use self :: ptrace:: * ;
127128 ptrace_get_data :: < c_long > ( PTRACE_GETEVENTMSG , pid)
128129}
129130
130131/// Get siginfo as with `ptrace(PTRACE_GETSIGINFO,...)`
131- pub fn ptrace_getsiginfo ( pid : pid_t ) -> Result < siginfo_t > {
132+ pub fn ptrace_getsiginfo ( pid : Pid ) -> Result < siginfo_t > {
132133 use self :: ptrace:: * ;
133134 ptrace_get_data :: < siginfo_t > ( PTRACE_GETSIGINFO , pid)
134135}
135136
136137/// Set siginfo as with `ptrace(PTRACE_SETSIGINFO,...)`
137- pub fn ptrace_setsiginfo ( pid : pid_t , sig : & siginfo_t ) -> Result < ( ) > {
138+ pub fn ptrace_setsiginfo ( pid : Pid , sig : & siginfo_t ) -> Result < ( ) > {
138139 use self :: ptrace:: * ;
139140 let ret = unsafe {
140141 Errno :: clear ( ) ;
141- ffi:: ptrace ( PTRACE_SETSIGINFO , pid, ptr:: null_mut ( ) , sig as * const _ as * const c_void )
142+ ffi:: ptrace ( PTRACE_SETSIGINFO , pid. into ( ) , ptr:: null_mut ( ) , sig as * const _ as * const c_void )
142143 } ;
143144 match Errno :: result ( ret) {
144145 Ok ( _) => Ok ( ( ) ) ,
0 commit comments