Skip to content

Commit d201af7

Browse files
committed
Remove unnecessary PrctlOption enum
1 parent 56b9fca commit d201af7

File tree

1 file changed

+16
-123
lines changed

1 file changed

+16
-123
lines changed

src/sys/prctl.rs

Lines changed: 16 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -13,113 +13,6 @@ use libc::{c_char, c_int, c_ulong};
1313
use std::convert::TryFrom;
1414
use std::ffi::{CStr, CString};
1515

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-
12316
libc_enum! {
12417
/// The type of hardware memory corruption kill policy for the thread.
12518
@@ -137,54 +30,54 @@ libc_enum! {
13730
impl TryFrom<i32>
13831
}
13932

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) };
14235
Errno::result(res).map(drop)
14336
}
14437

14538
/// Set the "child subreaper" attribute for this process
14639
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)
14841
}
14942

15043
/// Get the "child subreaper" attribute for this process
15144
pub fn get_child_subreaper() -> Result<bool> {
15245
// prctl writes into this var
15346
let mut subreaper: c_int = 0;
15447

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) };
15649

15750
Errno::result(res).map(|_| subreaper != 0)
15851
}
15952

16053
/// Set the dumpable attribute which determines if core dumps are created for this process.
16154
pub fn set_dumpable(attribute: bool) -> Result<()> {
162-
prctl_set_bool(PR_SET_DUMPABLE, attribute)
55+
prctl_set_bool(libc::PR_SET_DUMPABLE, attribute)
16356
}
16457

16558
/// Get the dumpable attribute for this process.
16659
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) };
16861

16962
Errno::result(res).map(|res| res != 0)
17063
}
17164

17265
/// Set the "keep capabilities" attribute for this process. This causes the thread to retain
17366
/// capabilities even if it switches its UID to a nonzero value.
17467
pub fn set_keepcaps(attribute: bool) -> Result<()> {
175-
prctl_set_bool(PR_SET_KEEPCAPS, attribute)
68+
prctl_set_bool(libc::PR_SET_KEEPCAPS, attribute)
17669
}
17770

17871
/// Get the "keep capabilities" attribute for this process
17972
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) };
18174

18275
Errno::result(res).map(|res| res != 0)
18376
}
18477

18578
/// Clear the thread memory corruption kill policy and use the system-wide default
18679
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) };
18881

18982
Errno::result(res).map(drop)
19083
}
@@ -193,7 +86,7 @@ pub fn clear_mce_kill() -> Result<()> {
19386
pub fn set_mce_kill(policy: PrctlMCEKillPolicy) -> Result<()> {
19487
let res = unsafe {
19588
libc::prctl(
196-
PR_MCE_KILL as c_int,
89+
libc::PR_MCE_KILL,
19790
libc::PR_MCE_KILL_SET,
19891
policy as c_ulong,
19992
0,
@@ -206,7 +99,7 @@ pub fn set_mce_kill(policy: PrctlMCEKillPolicy) -> Result<()> {
20699

207100
/// Get the thread memory corruption kill policy
208101
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) };
210103

211104
match Errno::result(res) {
212105
Ok(val) => Ok(PrctlMCEKillPolicy::try_from(val)?),
@@ -222,7 +115,7 @@ pub fn set_pdeathsig<T: Into<Option<Signal>>>(signal: T) -> Result<()> {
222115
None => 0,
223116
};
224117

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) };
226119

227120
Errno::result(res).map(drop)
228121
}
@@ -232,7 +125,7 @@ pub fn get_pdeathsig() -> Result<Option<Signal>> {
232125
// prctl writes into this var
233126
let mut sig: c_int = 0;
234127

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) };
236129

237130
match Errno::result(res) {
238131
Ok(_) => Ok(match sig {
@@ -244,10 +137,10 @@ pub fn get_pdeathsig() -> Result<Option<Signal>> {
244137
}
245138

246139
/// 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<()> {
248141
let name = CString::new(name.as_bytes()).unwrap();
249142

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) };
251144

252145
Errno::result(res).map(drop)
253146
}
@@ -256,7 +149,7 @@ pub fn set_name(name: &String) -> Result<()> {
256149
pub fn get_name() -> Result<String> {
257150
let buf = [32u8; 16];
258151

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) };
260153

261154
let ptr = buf.as_ptr() as *const c_char;
262155
let cstr = unsafe { CStr::from_ptr(ptr) };

0 commit comments

Comments
 (0)