1 #[cfg(not(any(target_os = "espidf", target_os = "vita")))]
2 use crate::backend::c;
3 
4 /// A command for use with [`membarrier`] and [`membarrier_cpu`].
5 ///
6 /// For `MEMBARRIER_CMD_QUERY`, see [`membarrier_query`].
7 ///
8 /// [`membarrier`]: crate::process::membarrier
9 /// [`membarrier_cpu`]: crate::process::membarrier_cpu
10 /// [`membarrier_query`]: crate::process::membarrier_query
11 #[cfg(linux_kernel)]
12 #[derive(Copy, Clone, Eq, PartialEq, Debug)]
13 #[repr(u32)]
14 pub enum MembarrierCommand {
15     /// `MEMBARRIER_CMD_GLOBAL`
16     #[doc(alias = "Shared")]
17     #[doc(alias = "MEMBARRIER_CMD_SHARED")]
18     Global = c::MEMBARRIER_CMD_GLOBAL as u32,
19     /// `MEMBARRIER_CMD_GLOBAL_EXPEDITED`
20     GlobalExpedited = c::MEMBARRIER_CMD_GLOBAL_EXPEDITED as u32,
21     /// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED`
22     RegisterGlobalExpedited = c::MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED as u32,
23     /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED`
24     PrivateExpedited = c::MEMBARRIER_CMD_PRIVATE_EXPEDITED as u32,
25     /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED`
26     RegisterPrivateExpedited = c::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED as u32,
27     /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE`
28     PrivateExpeditedSyncCore = c::MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE as u32,
29     /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE`
30     RegisterPrivateExpeditedSyncCore =
31         c::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE as u32,
32     /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10)
33     PrivateExpeditedRseq = c::MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ as u32,
34     /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10)
35     RegisterPrivateExpeditedRseq = c::MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ as u32,
36 }
37 
38 /// A resource value for use with [`getrlimit`], [`setrlimit`], and
39 /// [`prlimit`].
40 ///
41 /// [`getrlimit`]: crate::process::getrlimit
42 /// [`setrlimit`]: crate::process::setrlimit
43 /// [`prlimit`]: crate::process::prlimit
44 #[cfg(not(any(
45     target_os = "espidf",
46     target_os = "fuchsia",
47     target_os = "redox",
48     target_os = "vita",
49     target_os = "wasi"
50 )))]
51 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
52 #[cfg_attr(not(target_os = "l4re"), repr(u32))]
53 #[cfg_attr(target_os = "l4re", repr(u64))]
54 pub enum Resource {
55     /// `RLIMIT_CPU`
56     Cpu = bitcast!(c::RLIMIT_CPU),
57     /// `RLIMIT_FSIZE`
58     Fsize = bitcast!(c::RLIMIT_FSIZE),
59     /// `RLIMIT_DATA`
60     Data = bitcast!(c::RLIMIT_DATA),
61     /// `RLIMIT_STACK`
62     Stack = bitcast!(c::RLIMIT_STACK),
63     /// `RLIMIT_CORE`
64     #[cfg(not(target_os = "haiku"))]
65     Core = bitcast!(c::RLIMIT_CORE),
66     /// `RLIMIT_RSS`
67     // "nto" has `RLIMIT_RSS`, but it has the same value as `RLIMIT_AS`.
68     #[cfg(not(any(apple, solarish, target_os = "nto", target_os = "haiku")))]
69     Rss = bitcast!(c::RLIMIT_RSS),
70     /// `RLIMIT_NPROC`
71     #[cfg(not(any(solarish, target_os = "haiku")))]
72     Nproc = bitcast!(c::RLIMIT_NPROC),
73     /// `RLIMIT_NOFILE`
74     Nofile = bitcast!(c::RLIMIT_NOFILE),
75     /// `RLIMIT_MEMLOCK`
76     #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
77     Memlock = bitcast!(c::RLIMIT_MEMLOCK),
78     /// `RLIMIT_AS`
79     #[cfg(not(target_os = "openbsd"))]
80     As = bitcast!(c::RLIMIT_AS),
81     /// `RLIMIT_LOCKS`
82     #[cfg(not(any(
83         bsd,
84         solarish,
85         target_os = "aix",
86         target_os = "haiku",
87         target_os = "hurd",
88         target_os = "nto"
89     )))]
90     Locks = bitcast!(c::RLIMIT_LOCKS),
91     /// `RLIMIT_SIGPENDING`
92     #[cfg(not(any(
93         bsd,
94         solarish,
95         target_os = "aix",
96         target_os = "haiku",
97         target_os = "hurd",
98         target_os = "nto"
99     )))]
100     Sigpending = bitcast!(c::RLIMIT_SIGPENDING),
101     /// `RLIMIT_MSGQUEUE`
102     #[cfg(not(any(
103         bsd,
104         solarish,
105         target_os = "aix",
106         target_os = "haiku",
107         target_os = "hurd",
108         target_os = "nto"
109     )))]
110     Msgqueue = bitcast!(c::RLIMIT_MSGQUEUE),
111     /// `RLIMIT_NICE`
112     #[cfg(not(any(
113         bsd,
114         solarish,
115         target_os = "aix",
116         target_os = "haiku",
117         target_os = "hurd",
118         target_os = "nto"
119     )))]
120     Nice = bitcast!(c::RLIMIT_NICE),
121     /// `RLIMIT_RTPRIO`
122     #[cfg(not(any(
123         bsd,
124         solarish,
125         target_os = "aix",
126         target_os = "haiku",
127         target_os = "hurd",
128         target_os = "nto"
129     )))]
130     Rtprio = bitcast!(c::RLIMIT_RTPRIO),
131     /// `RLIMIT_RTTIME`
132     #[cfg(not(any(
133         bsd,
134         solarish,
135         target_os = "aix",
136         target_os = "android",
137         target_os = "emscripten",
138         target_os = "haiku",
139         target_os = "hurd",
140         target_os = "nto",
141     )))]
142     Rttime = bitcast!(c::RLIMIT_RTTIME),
143 }
144 
145 #[cfg(apple)]
146 #[allow(non_upper_case_globals)]
147 impl Resource {
148     /// `RLIMIT_RSS`
149     pub const Rss: Self = Self::As;
150 }
151 
152 /// A CPU identifier as a raw integer.
153 #[cfg(linux_kernel)]
154 pub type RawCpuid = u32;
155 #[cfg(freebsdlike)]
156 pub type RawId = c::id_t;
157 
158 #[cfg(any(linux_kernel, target_os = "fuchsia"))]
159 pub(crate) type RawCpuSet = c::cpu_set_t;
160 #[cfg(freebsdlike)]
161 pub(crate) type RawCpuSet = c::cpuset_t;
162 
163 #[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
164 #[inline]
raw_cpu_set_new() -> RawCpuSet165 pub(crate) fn raw_cpu_set_new() -> RawCpuSet {
166     let mut set = unsafe { core::mem::zeroed() };
167     super::cpu_set::CPU_ZERO(&mut set);
168     set
169 }
170 
171 #[cfg(any(freebsdlike, linux_kernel, target_os = "fuchsia"))]
172 pub(crate) const CPU_SETSIZE: usize = c::CPU_SETSIZE as usize;
173