3 /// A command for use with [`membarrier`] and [`membarrier_cpu`].
5 /// For `MEMBARRIER_CMD_QUERY`, see [`membarrier_query`].
7 /// [`membarrier`]: crate::process::membarrier
8 /// [`membarrier_cpu`]: crate::process::membarrier_cpu
9 /// [`membarrier_query`]: crate::process::membarrier_query
10 // TODO: These are not yet exposed through libc, so we define the
11 // constants ourselves.
12 #[cfg(any(target_os = "android", target_os = "linux"))]
13 #[derive(Copy, Clone, Eq, PartialEq, Debug)]
15 pub enum MembarrierCommand
{
16 /// `MEMBARRIER_CMD_GLOBAL`
17 #[doc(alias = "Shared")]
18 #[doc(alias = "MEMBARRIER_CMD_SHARED")]
20 /// `MEMBARRIER_CMD_GLOBAL_EXPEDITED`
22 /// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED`
23 RegisterGlobalExpedited
= 4,
24 /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED`
26 /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED`
27 RegisterPrivateExpedited
= 16,
28 /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE`
29 PrivateExpeditedSyncCore
= 32,
30 /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE`
31 RegisterPrivateExpeditedSyncCore
= 64,
32 /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10)
33 PrivateExpeditedRseq
= 128,
34 /// `MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ` (since Linux 5.10)
35 RegisterPrivateExpeditedRseq
= 256,
38 /// A resource value for use with [`getrlimit`], [`setrlimit`], and
41 /// [`getrlimit`]: crate::process::getrlimit
42 /// [`setrlimit`]: crate::process::setrlimit
43 /// [`prlimit`]: crate::process::prlimit
44 #[cfg(not(any(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
45 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
49 Cpu
= c
::RLIMIT_CPU
as c
::c_int
,
51 Fsize
= c
::RLIMIT_FSIZE
as c
::c_int
,
53 Data
= c
::RLIMIT_DATA
as c
::c_int
,
55 Stack
= c
::RLIMIT_STACK
as c
::c_int
,
57 #[cfg(not(target_os = "haiku"))]
58 Core
= c
::RLIMIT_CORE
as c
::c_int
,
60 #[cfg(not(any(apple, solarish, target_os = "haiku")))]
61 Rss
= c
::RLIMIT_RSS
as c
::c_int
,
63 #[cfg(not(any(solarish, target_os = "haiku")))]
64 Nproc
= c
::RLIMIT_NPROC
as c
::c_int
,
66 Nofile
= c
::RLIMIT_NOFILE
as c
::c_int
,
68 #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
69 Memlock
= c
::RLIMIT_MEMLOCK
as c
::c_int
,
71 #[cfg(not(target_os = "openbsd"))]
72 As
= c
::RLIMIT_AS
as c
::c_int
,
74 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
75 Locks
= c
::RLIMIT_LOCKS
as c
::c_int
,
76 /// `RLIMIT_SIGPENDING`
77 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
78 Sigpending
= c
::RLIMIT_SIGPENDING
as c
::c_int
,
80 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
81 Msgqueue
= c
::RLIMIT_MSGQUEUE
as c
::c_int
,
83 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
84 Nice
= c
::RLIMIT_NICE
as c
::c_int
,
86 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
87 Rtprio
= c
::RLIMIT_RTPRIO
as c
::c_int
,
93 target_os
= "android",
94 target_os
= "emscripten",
97 Rttime
= c
::RLIMIT_RTTIME
as c
::c_int
,
103 #[allow(non_upper_case_globals)]
104 pub const Rss
: Self = Self::As
;
107 /// A signal number for use with [`kill_process`], [`kill_process_group`],
108 /// and [`kill_current_process_group`].
110 /// [`kill_process`]: crate::process::kill_process
111 /// [`kill_process_group`]: crate::process::kill_process_group
112 /// [`kill_current_process_group`]: crate::process::kill_current_process_group
113 #[cfg(not(target_os = "wasi"))]
114 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
127 /// `SIGABRT`, aka `SIGIOT`
128 #[doc(alias = "Iot")]
129 #[doc(alias = "Abrt")]
146 #[doc(alias = "Alrm")]
157 any(target_os
= "android", target_os
= "linux"),
159 target_arch
= "mips",
160 target_arch
= "mips64",
161 target_arch
= "sparc",
162 target_arch
= "sparc64"
166 Stkflt
= c
::SIGSTKFLT
,
168 #[doc(alias = "Chld")]
187 #[doc(alias = "Vtalrm")]
188 Vtalarm
= c
::SIGVTALRM
,
193 /// `SIGIO`, aka `SIGPOLL`
194 #[doc(alias = "Poll")]
195 #[cfg(not(target_os = "haiku"))]
198 #[cfg(not(any(bsd, target_os = "haiku")))]
199 #[doc(alias = "Pwr")]
201 /// `SIGSYS`, aka `SIGUNUSED`
202 #[doc(alias = "Unused")]
211 #[cfg(target_os = "freebsd")]
212 #[doc(alias = "Lwp")]
215 #[cfg(target_os = "freebsd")]
219 #[cfg(not(target_os = "wasi"))]
221 /// Convert a raw signal number into a `Signal`, if possible.
222 pub fn from_raw(sig
: i32) -> Option
<Self> {
224 c
::SIGHUP
=> Some(Self::Hup
),
225 c
::SIGINT
=> Some(Self::Int
),
226 c
::SIGQUIT
=> Some(Self::Quit
),
227 c
::SIGILL
=> Some(Self::Ill
),
228 c
::SIGTRAP
=> Some(Self::Trap
),
229 c
::SIGABRT
=> Some(Self::Abort
),
230 c
::SIGBUS
=> Some(Self::Bus
),
231 c
::SIGFPE
=> Some(Self::Fpe
),
232 c
::SIGKILL
=> Some(Self::Kill
),
233 c
::SIGUSR1
=> Some(Self::Usr1
),
234 c
::SIGSEGV
=> Some(Self::Segv
),
235 c
::SIGUSR2
=> Some(Self::Usr2
),
236 c
::SIGPIPE
=> Some(Self::Pipe
),
237 c
::SIGALRM
=> Some(Self::Alarm
),
238 c
::SIGTERM
=> Some(Self::Term
),
245 any(target_os
= "android", target_os
= "linux"),
247 target_arch
= "mips",
248 target_arch
= "mips64",
249 target_arch
= "sparc",
250 target_arch
= "sparc64"
254 c
::SIGSTKFLT
=> Some(Self::Stkflt
),
255 c
::SIGCHLD
=> Some(Self::Child
),
256 c
::SIGCONT
=> Some(Self::Cont
),
257 c
::SIGSTOP
=> Some(Self::Stop
),
258 c
::SIGTSTP
=> Some(Self::Tstp
),
259 c
::SIGTTIN
=> Some(Self::Ttin
),
260 c
::SIGTTOU
=> Some(Self::Ttou
),
261 c
::SIGURG
=> Some(Self::Urg
),
262 c
::SIGXCPU
=> Some(Self::Xcpu
),
263 c
::SIGXFSZ
=> Some(Self::Xfsz
),
264 c
::SIGVTALRM
=> Some(Self::Vtalarm
),
265 c
::SIGPROF
=> Some(Self::Prof
),
266 c
::SIGWINCH
=> Some(Self::Winch
),
267 #[cfg(not(target_os = "haiku"))]
268 c
::SIGIO
=> Some(Self::Io
),
269 #[cfg(not(any(bsd, target_os = "haiku")))]
270 c
::SIGPWR
=> Some(Self::Power
),
271 c
::SIGSYS
=> Some(Self::Sys
),
273 c
::SIGEMT
=> Some(Self::Emt
),
275 c
::SIGINFO
=> Some(Self::Info
),
276 #[cfg(target_os = "freebsd")]
277 c
::SIGTHR
=> Some(Self::Thr
),
278 #[cfg(target_os = "freebsd")]
279 c
::SIGLIBRT
=> Some(Self::Librt
),
285 pub const EXIT_SUCCESS
: c
::c_int
= c
::EXIT_SUCCESS
;
286 pub const EXIT_FAILURE
: c
::c_int
= c
::EXIT_FAILURE
;
287 #[cfg(not(target_os = "wasi"))]
288 pub const EXIT_SIGNALED_SIGABRT
: c
::c_int
= 128 + c
::SIGABRT
;
290 /// A process identifier as a raw integer.
291 #[cfg(not(target_os = "wasi"))]
292 pub type RawPid
= c
::pid_t
;
293 /// A non-zero process identifier as a raw non-zero integer.
294 #[cfg(not(target_os = "wasi"))]
295 pub type RawNonZeroPid
= core
::num
::NonZeroI32
;
296 /// A group identifier as a raw integer.
297 #[cfg(not(target_os = "wasi"))]
298 pub type RawGid
= c
::gid_t
;
299 /// A user identifier as a raw integer.
300 #[cfg(not(target_os = "wasi"))]
301 pub type RawUid
= c
::uid_t
;
302 /// A CPU identifier as a raw integer.
303 #[cfg(any(target_os = "android", target_os = "linux"))]
304 pub type RawCpuid
= u32;
305 #[cfg(target_os = "freebsd")]
306 pub type RawId
= c
::id_t
;
308 #[cfg(not(target_os = "wasi"))]
309 pub(crate) type RawUname
= c
::utsname
;
312 target_os
= "android",
313 target_os
= "dragonfly",
314 target_os
= "fuchsia",
317 pub(crate) type RawCpuSet
= c
::cpu_set_t
;
320 target_os
= "android",
321 target_os
= "dragonfly",
322 target_os
= "fuchsia",
326 pub(crate) fn raw_cpu_set_new() -> RawCpuSet
{
327 let mut set
= unsafe { core::mem::zeroed() }
;
328 super::cpu_set
::CPU_ZERO(&mut set
);
332 #[cfg(any(target_os = "android", target_os = "fuchsia", target_os = "linux"))]
333 pub(crate) const CPU_SETSIZE
: usize = c
::CPU_SETSIZE
as usize;
334 #[cfg(target_os = "dragonfly")]
335 pub(crate) const CPU_SETSIZE
: usize = 256;