1
1
use std:: { mem, ptr} ;
2
2
use { Errno , Error , Result } ;
3
- use libc:: { c_void, c_long, siginfo_t} ;
3
+ use libc:: { self , c_void, c_long, siginfo_t} ;
4
4
use :: unistd:: Pid ;
5
5
6
6
pub mod ptrace {
7
7
use libc:: c_int;
8
8
9
- pub type PtraceRequest = c_int ;
9
+ /// The datatype used for the `request` argument to `ptrace`
10
+ #[ cfg( any( all( target_os = "linux" , arch = "s390x" ) ,
11
+ all( target_os = "linux" , target_env = "gnu" ) ) ) ]
12
+ #[ doc( hidden) ]
13
+ pub type ptrace_request_type = :: libc:: c_uint ;
14
+
15
+ #[ cfg( not( any( all( target_os = "linux" , arch = "s390x" ) ,
16
+ all( target_os = "linux" , target_env = "gnu" ) ) ) ) ]
17
+ #[ doc( hidden) ]
18
+ pub type ptrace_request_type = :: libc:: c_int ;
19
+
20
+ pub type PtraceRequest = ptrace_request_type ;
10
21
11
22
pub const PTRACE_TRACEME : PtraceRequest = 0 ;
12
23
pub const PTRACE_PEEKTEXT : PtraceRequest = 1 ;
@@ -60,14 +71,6 @@ pub mod ptrace {
60
71
pub const PTRACE_O_TRACESECCOMP : PtraceOptions = ( 1 << PTRACE_EVENT_SECCOMP ) ;
61
72
}
62
73
63
- mod ffi {
64
- use libc:: { pid_t, c_int, c_long, c_void} ;
65
-
66
- extern {
67
- pub fn ptrace ( request : c_int , pid : pid_t , addr : * const c_void , data : * const c_void ) -> c_long ;
68
- }
69
- }
70
-
71
74
/// Performs a ptrace request. If the request in question is provided by a specialised function
72
75
/// this function will return an unsupported operation error.
73
76
pub fn ptrace ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
@@ -83,7 +86,7 @@ pub fn ptrace(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data:
83
86
fn ptrace_peek ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
84
87
let ret = unsafe {
85
88
Errno :: clear ( ) ;
86
- ffi :: ptrace ( request, pid . into ( ) , addr, data)
89
+ libc :: ptrace ( request, Into :: < libc :: pid_t > :: into ( pid ) , addr, data)
87
90
} ;
88
91
match Errno :: result ( ret) {
89
92
Ok ( ..) | Err ( Error :: Sys ( Errno :: UnknownErrno ) ) => Ok ( ret) ,
@@ -98,21 +101,21 @@ fn ptrace_peek(request: ptrace::PtraceRequest, pid: Pid, addr: *mut c_void, data
98
101
fn ptrace_get_data < T > ( request : ptrace:: PtraceRequest , pid : Pid ) -> Result < T > {
99
102
// Creates an uninitialized pointer to store result in
100
103
let data: T = unsafe { mem:: uninitialized ( ) } ;
101
- let res = unsafe { ffi :: ptrace ( request, pid . into ( ) , ptr:: null_mut ( ) , & data as * const _ as * const c_void ) } ;
104
+ let res = unsafe { libc :: ptrace ( request, Into :: < libc :: pid_t > :: into ( pid ) , ptr:: null_mut :: < T > ( ) , & data as * const _ as * const c_void ) } ;
102
105
Errno :: result ( res) ?;
103
106
Ok ( data)
104
107
}
105
108
106
109
fn ptrace_other ( request : ptrace:: PtraceRequest , pid : Pid , addr : * mut c_void , data : * mut c_void ) -> Result < c_long > {
107
- Errno :: result ( unsafe { ffi :: ptrace ( request, pid . into ( ) , addr, data) } ) . map ( |_| 0 )
110
+ Errno :: result ( unsafe { libc :: ptrace ( request, Into :: < libc :: pid_t > :: into ( pid ) , addr, data) } ) . map ( |_| 0 )
108
111
}
109
112
110
113
/// Set options, as with `ptrace(PTRACE_SETOPTIONS,...)`.
111
114
pub fn setoptions ( pid : Pid , options : ptrace:: PtraceOptions ) -> Result < ( ) > {
112
115
use self :: ptrace:: * ;
113
116
use std:: ptr;
114
117
115
- let res = unsafe { ffi :: ptrace ( PTRACE_SETOPTIONS , pid . into ( ) , ptr:: null_mut ( ) , options as * mut c_void ) } ;
118
+ let res = unsafe { libc :: ptrace ( PTRACE_SETOPTIONS , Into :: < libc :: pid_t > :: into ( pid ) , ptr:: null_mut :: < libc :: c_void > ( ) , options as * mut c_void ) } ;
116
119
Errno :: result ( res) . map ( |_| ( ) )
117
120
}
118
121
@@ -133,7 +136,7 @@ pub fn setsiginfo(pid: Pid, sig: &siginfo_t) -> Result<()> {
133
136
use self :: ptrace:: * ;
134
137
let ret = unsafe {
135
138
Errno :: clear ( ) ;
136
- ffi :: ptrace ( PTRACE_SETSIGINFO , pid . into ( ) , ptr:: null_mut ( ) , sig as * const _ as * const c_void )
139
+ libc :: ptrace ( PTRACE_SETSIGINFO , Into :: < libc :: pid_t > :: into ( pid ) , ptr:: null_mut :: < libc :: c_void > ( ) , sig as * const _ as * const c_void )
137
140
} ;
138
141
match Errno :: result ( ret) {
139
142
Ok ( _) => Ok ( ( ) ) ,
0 commit comments