1
1
use std:: { mem, ptr} ;
2
2
use { 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 ;
4
5
5
6
#[ cfg( all( target_os = "linux" ,
6
7
any( target_arch = "x86" ,
@@ -74,7 +75,7 @@ mod ffi {
74
75
75
76
/// Performs a ptrace request. If the request in question is provided by a specialised function
76
77
/// 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 > {
78
79
use self :: ptrace:: * ;
79
80
80
81
match request {
@@ -84,10 +85,10 @@ pub fn ptrace(request: ptrace::PtraceRequest, pid: pid_t, addr: *mut c_void, dat
84
85
}
85
86
}
86
87
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 > {
88
89
let ret = unsafe {
89
90
Errno :: clear ( ) ;
90
- ffi:: ptrace ( request, pid, addr, data)
91
+ ffi:: ptrace ( request, pid. into ( ) , addr, data)
91
92
} ;
92
93
match Errno :: result ( ret) {
93
94
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
99
100
/// Some ptrace get requests populate structs or larger elements than c_long
100
101
/// and therefore use the data field to return values. This function handles these
101
102
/// 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 > {
103
104
// Creates an uninitialized pointer to store result in
104
105
let data: Box < T > = Box :: new ( unsafe { mem:: uninitialized ( ) } ) ;
105
106
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> {
109
110
Ok ( * data)
110
111
}
111
112
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 )
114
115
}
115
116
116
117
/// 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 < ( ) > {
118
119
use self :: ptrace:: * ;
119
120
use std:: ptr;
120
121
121
122
ptrace ( PTRACE_SETOPTIONS , pid, ptr:: null_mut ( ) , options as * mut c_void ) . map ( drop)
122
123
}
123
124
124
125
/// 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 > {
126
127
use self :: ptrace:: * ;
127
128
ptrace_get_data :: < c_long > ( PTRACE_GETEVENTMSG , pid)
128
129
}
129
130
130
131
/// 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 > {
132
133
use self :: ptrace:: * ;
133
134
ptrace_get_data :: < siginfo_t > ( PTRACE_GETSIGINFO , pid)
134
135
}
135
136
136
137
/// 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 < ( ) > {
138
139
use self :: ptrace:: * ;
139
140
let ret = unsafe {
140
141
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 )
142
143
} ;
143
144
match Errno :: result ( ret) {
144
145
Ok ( _) => Ok ( ( ) ) ,
0 commit comments