@@ -13,113 +13,6 @@ use libc::{c_char, c_int, c_ulong};
13
13
use std:: convert:: TryFrom ;
14
14
use std:: ffi:: { CStr , CString } ;
15
15
16
- pub use self :: PrctlOption :: * ;
17
-
18
- libc_enum ! {
19
- /// Types of prctl options see [prctl(2)](https://man7.org/linux/man-pages/man2/prctl.2.html) for more information.
20
-
21
- #[ repr( i32 ) ]
22
- #[ non_exhaustive]
23
- #[ allow( non_camel_case_types) ]
24
- pub enum PrctlOption {
25
- /// Set the parent-death signal of the calling process to arg2
26
- PR_SET_PDEATHSIG ,
27
- /// Read the current parent-death signal into the location pointed to by arg2
28
- PR_GET_PDEATHSIG ,
29
- /// Return from the function the calling process's dumpable attribute
30
- PR_GET_DUMPABLE ,
31
- /// Set the process's dumpable attribute to arg2
32
- PR_SET_DUMPABLE ,
33
- /// Read the current access control bits into the location pointed to by arg2. PowerPC
34
- /// only.
35
- PR_GET_UNALIGN ,
36
- /// Set unaligned access control bits to arg2. PowerPC only.
37
- PR_SET_UNALIGN ,
38
- /// Set the calling thread's "keep capabilities" flag. arg2 must be either 0 (clear the
39
- /// flag) or 1 (set the flag)
40
- PR_GET_KEEPCAPS ,
41
- /// Return from the function the calling thread's "keep capabilities" flag
42
- PR_SET_KEEPCAPS ,
43
- /// Read floating-point exception mode into the location pointed to by arg2. PowerPC only.
44
- PR_GET_FPEXC ,
45
- /// Set floating-point exception mode to arg2. PowerPC only.
46
- PR_SET_FPEXC ,
47
- /// Return from the function which process timing method is currently in use
48
- PR_GET_TIMING ,
49
- /// Set process timing method to arg2
50
- PR_SET_TIMING ,
51
- /// Set the name of the calling thread (max 16 bytes) to the value in the location pointed
52
- /// to by (char *) arg2
53
- PR_SET_NAME ,
54
- /// Read the name of the calling thread into the buffer pointed to by (char *) arg2
55
- PR_GET_NAME ,
56
- /// Read the endian-ness of the calling process into the location pointed to by arg2.
57
- /// PowerPC only.
58
- PR_GET_ENDIAN ,
59
- /// Set the endian-ness of the calling process to arg2. PowerPC only.
60
- PR_SET_ENDIAN ,
61
- /// Return from the function the secure computing mode of the calling thread
62
- PR_GET_SECCOMP ,
63
- /// Set the "securebits" flags of the calling thread to the value supplied in arg2. See
64
- /// capabilities(7)
65
- PR_SET_SECCOMP ,
66
- /// Return 1 from the function if the capability specified in arg2 is in the calling
67
- /// thread's capability bounding set, or 0 if it is not
68
- PR_CAPBSET_READ ,
69
- /// Drop the capability specified in arg2 from the calling thread's capability bounding set
70
- PR_CAPBSET_DROP ,
71
- /// Read the state of the timestamp counter flag into the location pointed to by arg2
72
- PR_GET_TSC ,
73
- /// Set the state of the timestamp counter flag to arg2
74
- PR_SET_TSC ,
75
- /// Return from the function the "securebits" flags of the calling thread. See
76
- /// capabilities(7)
77
- PR_GET_SECUREBITS ,
78
- /// Set the "securebits" flags of the calling thread to arg2
79
- PR_SET_SECUREBITS ,
80
- /// Set the timer slack value for the calling thread to arg2
81
- PR_SET_TIMERSLACK ,
82
- /// Return from the function the current timer slack value of the calling thread
83
- PR_GET_TIMERSLACK ,
84
- /// Disable all performance counters attached to the calling process
85
- PR_TASK_PERF_EVENTS_DISABLE ,
86
- /// Enable performance counters attached to the calling process
87
- PR_TASK_PERF_EVENTS_ENABLE ,
88
- /// Set the machine check memory corruption kill policy for the calling thread to arg2
89
- PR_MCE_KILL ,
90
- /// Return from the function the current machine check kill policy
91
- PR_MCE_KILL_GET ,
92
- /// Modify certain kernel memory map descriptor fields of the calling process
93
- PR_SET_MM ,
94
- /// Set the process ID that is allowed to ptrace this process. Only relevant when Yama LSM
95
- /// is enabled.
96
- PR_SET_PTRACER ,
97
- /// Set the "child subreaper" attribute of the calling process to arg2
98
- PR_SET_CHILD_SUBREAPER ,
99
- /// Read the "child subreaper" attribute of the calling process into the location pointed
100
- /// to by arg2
101
- PR_GET_CHILD_SUBREAPER ,
102
- /// Set the calling thread's "no new privs" attribute to the value in arg2
103
- PR_SET_NO_NEW_PRIVS ,
104
- /// Return from the function the value of the "no new privs" attribute for the calling
105
- /// thread
106
- PR_GET_NO_NEW_PRIVS ,
107
- /// Read the "clear child tid" address into the location pointed to by (int **) arg2
108
- PR_GET_TID_ADDRESS ,
109
- /// Set the state of the "THP disable" flag for the calling thread to arg2
110
- PR_SET_THP_DISABLE ,
111
- /// return from the function the "THP disable" flag for the calling thread
112
- PR_GET_THP_DISABLE ,
113
- /// Set the MIPS "floating-point mode" for the process to arg2. MIPS only.
114
- PR_SET_FP_MODE ,
115
- /// Return from the function the "floatin-point mode" for the process. MIPS only.
116
- PR_GET_FP_MODE ,
117
- /// Reads or changes the ambient capability set of the calling thread, according to the
118
- /// value of arg2
119
- PR_CAP_AMBIENT ,
120
- }
121
- }
122
-
123
16
libc_enum ! {
124
17
/// The type of hardware memory corruption kill policy for the thread.
125
18
@@ -137,54 +30,54 @@ libc_enum! {
137
30
impl TryFrom <i32 >
138
31
}
139
32
140
- fn prctl_set_bool ( option : PrctlOption , status : bool ) -> Result < ( ) > {
141
- let res = unsafe { libc:: prctl ( option as c_int , status as c_ulong , 0 , 0 , 0 ) } ;
33
+ fn prctl_set_bool ( option : c_int , status : bool ) -> Result < ( ) > {
34
+ let res = unsafe { libc:: prctl ( option, status as c_ulong , 0 , 0 , 0 ) } ;
142
35
Errno :: result ( res) . map ( drop)
143
36
}
144
37
145
38
/// Set the "child subreaper" attribute for this process
146
39
pub fn set_child_subreaper ( attribute : bool ) -> Result < ( ) > {
147
- prctl_set_bool ( PR_SET_CHILD_SUBREAPER , attribute)
40
+ prctl_set_bool ( libc :: PR_SET_CHILD_SUBREAPER , attribute)
148
41
}
149
42
150
43
/// Get the "child subreaper" attribute for this process
151
44
pub fn get_child_subreaper ( ) -> Result < bool > {
152
45
// prctl writes into this var
153
46
let mut subreaper: c_int = 0 ;
154
47
155
- let res = unsafe { libc:: prctl ( PR_GET_CHILD_SUBREAPER as c_int , & mut subreaper, 0 , 0 , 0 ) } ;
48
+ let res = unsafe { libc:: prctl ( libc :: PR_GET_CHILD_SUBREAPER , & mut subreaper, 0 , 0 , 0 ) } ;
156
49
157
50
Errno :: result ( res) . map ( |_| subreaper != 0 )
158
51
}
159
52
160
53
/// Set the dumpable attribute which determines if core dumps are created for this process.
161
54
pub fn set_dumpable ( attribute : bool ) -> Result < ( ) > {
162
- prctl_set_bool ( PR_SET_DUMPABLE , attribute)
55
+ prctl_set_bool ( libc :: PR_SET_DUMPABLE , attribute)
163
56
}
164
57
165
58
/// Get the dumpable attribute for this process.
166
59
pub fn get_dumpable ( ) -> Result < bool > {
167
- let res = unsafe { libc:: prctl ( PR_GET_DUMPABLE as c_int , 0 , 0 , 0 , 0 ) } ;
60
+ let res = unsafe { libc:: prctl ( libc :: PR_GET_DUMPABLE , 0 , 0 , 0 , 0 ) } ;
168
61
169
62
Errno :: result ( res) . map ( |res| res != 0 )
170
63
}
171
64
172
65
/// Set the "keep capabilities" attribute for this process. This causes the thread to retain
173
66
/// capabilities even if it switches its UID to a nonzero value.
174
67
pub fn set_keepcaps ( attribute : bool ) -> Result < ( ) > {
175
- prctl_set_bool ( PR_SET_KEEPCAPS , attribute)
68
+ prctl_set_bool ( libc :: PR_SET_KEEPCAPS , attribute)
176
69
}
177
70
178
71
/// Get the "keep capabilities" attribute for this process
179
72
pub fn get_keepcaps ( ) -> Result < bool > {
180
- let res = unsafe { libc:: prctl ( PR_GET_KEEPCAPS as c_int , 0 , 0 , 0 , 0 ) } ;
73
+ let res = unsafe { libc:: prctl ( libc :: PR_GET_KEEPCAPS , 0 , 0 , 0 , 0 ) } ;
181
74
182
75
Errno :: result ( res) . map ( |res| res != 0 )
183
76
}
184
77
185
78
/// Clear the thread memory corruption kill policy and use the system-wide default
186
79
pub fn clear_mce_kill ( ) -> Result < ( ) > {
187
- let res = unsafe { libc:: prctl ( PR_MCE_KILL as c_int , libc:: PR_MCE_KILL_CLEAR , 0 , 0 , 0 ) } ;
80
+ let res = unsafe { libc:: prctl ( libc :: PR_MCE_KILL , libc:: PR_MCE_KILL_CLEAR , 0 , 0 , 0 ) } ;
188
81
189
82
Errno :: result ( res) . map ( drop)
190
83
}
@@ -193,7 +86,7 @@ pub fn clear_mce_kill() -> Result<()> {
193
86
pub fn set_mce_kill ( policy : PrctlMCEKillPolicy ) -> Result < ( ) > {
194
87
let res = unsafe {
195
88
libc:: prctl (
196
- PR_MCE_KILL as c_int ,
89
+ libc :: PR_MCE_KILL ,
197
90
libc:: PR_MCE_KILL_SET ,
198
91
policy as c_ulong ,
199
92
0 ,
@@ -206,7 +99,7 @@ pub fn set_mce_kill(policy: PrctlMCEKillPolicy) -> Result<()> {
206
99
207
100
/// Get the thread memory corruption kill policy
208
101
pub fn get_mce_kill ( ) -> Result < PrctlMCEKillPolicy > {
209
- let res = unsafe { libc:: prctl ( PR_MCE_KILL_GET as c_int , 0 , 0 , 0 , 0 ) } ;
102
+ let res = unsafe { libc:: prctl ( libc :: PR_MCE_KILL_GET , 0 , 0 , 0 , 0 ) } ;
210
103
211
104
match Errno :: result ( res) {
212
105
Ok ( val) => Ok ( PrctlMCEKillPolicy :: try_from ( val) ?) ,
@@ -222,7 +115,7 @@ pub fn set_pdeathsig<T: Into<Option<Signal>>>(signal: T) -> Result<()> {
222
115
None => 0 ,
223
116
} ;
224
117
225
- let res = unsafe { libc:: prctl ( PR_SET_PDEATHSIG as c_int , sig, 0 , 0 , 0 ) } ;
118
+ let res = unsafe { libc:: prctl ( libc :: PR_SET_PDEATHSIG , sig, 0 , 0 , 0 ) } ;
226
119
227
120
Errno :: result ( res) . map ( drop)
228
121
}
@@ -232,7 +125,7 @@ pub fn get_pdeathsig() -> Result<Option<Signal>> {
232
125
// prctl writes into this var
233
126
let mut sig: c_int = 0 ;
234
127
235
- let res = unsafe { libc:: prctl ( PR_GET_PDEATHSIG as c_int , & mut sig, 0 , 0 , 0 ) } ;
128
+ let res = unsafe { libc:: prctl ( libc :: PR_GET_PDEATHSIG , & mut sig, 0 , 0 , 0 ) } ;
236
129
237
130
match Errno :: result ( res) {
238
131
Ok ( _) => Ok ( match sig {
@@ -244,10 +137,10 @@ pub fn get_pdeathsig() -> Result<Option<Signal>> {
244
137
}
245
138
246
139
/// Set the name of the calling thread (max 15 bytes)
247
- pub fn set_name ( name : & String ) -> Result < ( ) > {
140
+ pub fn set_name ( name : & str ) -> Result < ( ) > {
248
141
let name = CString :: new ( name. as_bytes ( ) ) . unwrap ( ) ;
249
142
250
- let res = unsafe { libc:: prctl ( PR_SET_NAME as c_int , name. as_ptr ( ) , 0 , 0 , 0 ) } ;
143
+ let res = unsafe { libc:: prctl ( libc :: PR_SET_NAME , name. as_ptr ( ) , 0 , 0 , 0 ) } ;
251
144
252
145
Errno :: result ( res) . map ( drop)
253
146
}
@@ -256,7 +149,7 @@ pub fn set_name(name: &String) -> Result<()> {
256
149
pub fn get_name ( ) -> Result < String > {
257
150
let buf = [ 32u8 ; 16 ] ;
258
151
259
- let res = unsafe { libc:: prctl ( PR_GET_NAME as c_int , & buf, 0 , 0 , 0 ) } ;
152
+ let res = unsafe { libc:: prctl ( libc :: PR_GET_NAME , & buf, 0 , 0 , 0 ) } ;
260
153
261
154
let ptr = buf. as_ptr ( ) as * const c_char ;
262
155
let cstr = unsafe { CStr :: from_ptr ( ptr) } ;
0 commit comments