2
2
3
3
use std:: { mem, ptr} ;
4
4
use { Errno , Error , Result } ;
5
- use libc:: { c_void, c_long, siginfo_t} ;
5
+ use libc:: { self , c_void, c_long, siginfo_t} ;
6
6
use :: unistd:: Pid ;
7
7
use sys:: signal:: Signal ;
8
8
9
9
pub mod ptrace {
10
10
use libc:: c_int;
11
11
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
+ }
13
20
14
21
pub const PTRACE_TRACEME : PtraceRequest = 0 ;
15
22
pub const PTRACE_PEEKTEXT : PtraceRequest = 1 ;
@@ -63,14 +70,6 @@ pub mod ptrace {
63
70
pub const PTRACE_O_TRACESECCOMP : PtraceOptions = ( 1 << PTRACE_EVENT_SECCOMP ) ;
64
71
}
65
72
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
-
74
73
/// Performs a ptrace request. If the request in question is provided by a specialised function
75
74
/// this function will return an unsupported operation error.
76
75
#[ deprecated(
@@ -90,7 +89,7 @@ pub unsafe fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void
90
89
fn ptrace_peek ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
91
90
let ret = unsafe {
92
91
Errno :: clear ( ) ;
93
- ffi :: ptrace ( request, pid . into ( ) , addr, data)
92
+ libc :: ptrace ( request, libc :: pid_t :: from ( pid ) , addr, data)
94
93
} ;
95
94
match Errno :: result ( ret) {
96
95
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
105
104
fn ptrace_get_data < T > ( request : ptrace:: PtraceRequest , pid : Pid ) -> Result < T > {
106
105
// Creates an uninitialized pointer to store result in
107
106
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 ) } ;
109
108
Errno :: result ( res) ?;
110
109
Ok ( data)
111
110
}
112
111
113
112
unsafe 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 )
115
114
}
116
115
117
116
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
118
117
pub fn setoptions ( pid : Pid , options : ptrace:: PtraceOptions ) -> Result < ( ) > {
119
118
use self :: ptrace:: * ;
120
119
use std:: ptr;
121
120
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 ) } ;
123
122
Errno :: result ( res) . map ( |_| ( ) )
124
123
}
125
124
@@ -140,7 +139,7 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
140
139
use self :: ptrace:: * ;
141
140
let ret = unsafe {
142
141
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 )
144
143
} ;
145
144
match Errno :: result ( ret) {
146
145
Ok ( _) => Ok ( ( ) ) ,
0 commit comments