]> git.proxmox.com Git - rustc.git/blob - vendor/rustix-0.37.6/src/backend/libc/process/types.rs
New upstream version 1.74.1+dfsg1
[rustc.git] / vendor / rustix-0.37.6 / src / backend / libc / process / types.rs
1 use super::super::c;
2
3 /// A command for use with [`membarrier`] and [`membarrier_cpu`].
4 ///
5 /// For `MEMBARRIER_CMD_QUERY`, see [`membarrier_query`].
6 ///
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)]
14 #[repr(u32)]
15 pub enum MembarrierCommand {
16 /// `MEMBARRIER_CMD_GLOBAL`
17 #[doc(alias = "Shared")]
18 #[doc(alias = "MEMBARRIER_CMD_SHARED")]
19 Global = 1,
20 /// `MEMBARRIER_CMD_GLOBAL_EXPEDITED`
21 GlobalExpedited = 2,
22 /// `MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED`
23 RegisterGlobalExpedited = 4,
24 /// `MEMBARRIER_CMD_PRIVATE_EXPEDITED`
25 PrivateExpedited = 8,
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,
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(target_os = "fuchsia", target_os = "redox", target_os = "wasi")))]
45 #[derive(Copy, Clone, Debug, Eq, PartialEq)]
46 #[repr(i32)]
47 pub enum Resource {
48 /// `RLIMIT_CPU`
49 Cpu = c::RLIMIT_CPU as c::c_int,
50 /// `RLIMIT_FSIZE`
51 Fsize = c::RLIMIT_FSIZE as c::c_int,
52 /// `RLIMIT_DATA`
53 Data = c::RLIMIT_DATA as c::c_int,
54 /// `RLIMIT_STACK`
55 Stack = c::RLIMIT_STACK as c::c_int,
56 /// `RLIMIT_CORE`
57 #[cfg(not(target_os = "haiku"))]
58 Core = c::RLIMIT_CORE as c::c_int,
59 /// `RLIMIT_RSS`
60 #[cfg(not(any(apple, solarish, target_os = "haiku")))]
61 Rss = c::RLIMIT_RSS as c::c_int,
62 /// `RLIMIT_NPROC`
63 #[cfg(not(any(solarish, target_os = "haiku")))]
64 Nproc = c::RLIMIT_NPROC as c::c_int,
65 /// `RLIMIT_NOFILE`
66 Nofile = c::RLIMIT_NOFILE as c::c_int,
67 /// `RLIMIT_MEMLOCK`
68 #[cfg(not(any(solarish, target_os = "aix", target_os = "haiku")))]
69 Memlock = c::RLIMIT_MEMLOCK as c::c_int,
70 /// `RLIMIT_AS`
71 #[cfg(not(target_os = "openbsd"))]
72 As = c::RLIMIT_AS as c::c_int,
73 /// `RLIMIT_LOCKS`
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,
79 /// `RLIMIT_MSGQUEUE`
80 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
81 Msgqueue = c::RLIMIT_MSGQUEUE as c::c_int,
82 /// `RLIMIT_NICE`
83 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
84 Nice = c::RLIMIT_NICE as c::c_int,
85 /// `RLIMIT_RTPRIO`
86 #[cfg(not(any(bsd, solarish, target_os = "aix", target_os = "haiku")))]
87 Rtprio = c::RLIMIT_RTPRIO as c::c_int,
88 /// `RLIMIT_RTTIME`
89 #[cfg(not(any(
90 bsd,
91 solarish,
92 target_os = "aix",
93 target_os = "android",
94 target_os = "emscripten",
95 target_os = "haiku",
96 )))]
97 Rttime = c::RLIMIT_RTTIME as c::c_int,
98 }
99
100 #[cfg(apple)]
101 impl Resource {
102 /// `RLIMIT_RSS`
103 #[allow(non_upper_case_globals)]
104 pub const Rss: Self = Self::As;
105 }
106
107 /// A signal number for use with [`kill_process`], [`kill_process_group`],
108 /// and [`kill_current_process_group`].
109 ///
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)]
115 #[repr(i32)]
116 pub enum Signal {
117 /// `SIGHUP`
118 Hup = c::SIGHUP,
119 /// `SIGINT`
120 Int = c::SIGINT,
121 /// `SIGQUIT`
122 Quit = c::SIGQUIT,
123 /// `SIGILL`
124 Ill = c::SIGILL,
125 /// `SIGTRAP`
126 Trap = c::SIGTRAP,
127 /// `SIGABRT`, aka `SIGIOT`
128 #[doc(alias = "Iot")]
129 #[doc(alias = "Abrt")]
130 Abort = c::SIGABRT,
131 /// `SIGBUS`
132 Bus = c::SIGBUS,
133 /// `SIGFPE`
134 Fpe = c::SIGFPE,
135 /// `SIGKILL`
136 Kill = c::SIGKILL,
137 /// `SIGUSR1`
138 Usr1 = c::SIGUSR1,
139 /// `SIGSEGV`
140 Segv = c::SIGSEGV,
141 /// `SIGUSR2`
142 Usr2 = c::SIGUSR2,
143 /// `SIGPIPE`
144 Pipe = c::SIGPIPE,
145 /// `SIGALRM`
146 #[doc(alias = "Alrm")]
147 Alarm = c::SIGALRM,
148 /// `SIGTERM`
149 Term = c::SIGTERM,
150 /// `SIGSTKFLT`
151 #[cfg(not(any(
152 bsd,
153 solarish,
154 target_os = "aix",
155 target_os = "haiku",
156 all(
157 any(target_os = "android", target_os = "linux"),
158 any(
159 target_arch = "mips",
160 target_arch = "mips64",
161 target_arch = "sparc",
162 target_arch = "sparc64"
163 ),
164 )
165 )))]
166 Stkflt = c::SIGSTKFLT,
167 /// `SIGCHLD`
168 #[doc(alias = "Chld")]
169 Child = c::SIGCHLD,
170 /// `SIGCONT`
171 Cont = c::SIGCONT,
172 /// `SIGSTOP`
173 Stop = c::SIGSTOP,
174 /// `SIGTSTP`
175 Tstp = c::SIGTSTP,
176 /// `SIGTTIN`
177 Ttin = c::SIGTTIN,
178 /// `SIGTTOU`
179 Ttou = c::SIGTTOU,
180 /// `SIGURG`
181 Urg = c::SIGURG,
182 /// `SIGXCPU`
183 Xcpu = c::SIGXCPU,
184 /// `SIGXFSZ`
185 Xfsz = c::SIGXFSZ,
186 /// `SIGVTALRM`
187 #[doc(alias = "Vtalrm")]
188 Vtalarm = c::SIGVTALRM,
189 /// `SIGPROF`
190 Prof = c::SIGPROF,
191 /// `SIGWINCH`
192 Winch = c::SIGWINCH,
193 /// `SIGIO`, aka `SIGPOLL`
194 #[doc(alias = "Poll")]
195 #[cfg(not(target_os = "haiku"))]
196 Io = c::SIGIO,
197 /// `SIGPWR`
198 #[cfg(not(any(bsd, target_os = "haiku")))]
199 #[doc(alias = "Pwr")]
200 Power = c::SIGPWR,
201 /// `SIGSYS`, aka `SIGUNUSED`
202 #[doc(alias = "Unused")]
203 Sys = c::SIGSYS,
204 /// `SIGEMT`
205 #[cfg(bsd)]
206 Emt = c::SIGEMT,
207 /// `SIGINFO`
208 #[cfg(bsd)]
209 Info = c::SIGINFO,
210 /// `SIGTHR`
211 #[cfg(target_os = "freebsd")]
212 #[doc(alias = "Lwp")]
213 Thr = c::SIGTHR,
214 /// `SIGLIBRT`
215 #[cfg(target_os = "freebsd")]
216 Librt = c::SIGLIBRT,
217 }
218
219 #[cfg(not(target_os = "wasi"))]
220 impl Signal {
221 /// Convert a raw signal number into a `Signal`, if possible.
222 pub fn from_raw(sig: i32) -> Option<Self> {
223 match sig as _ {
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),
239 #[cfg(not(any(
240 bsd,
241 solarish,
242 target_os = "aix",
243 target_os = "haiku",
244 all(
245 any(target_os = "android", target_os = "linux"),
246 any(
247 target_arch = "mips",
248 target_arch = "mips64",
249 target_arch = "sparc",
250 target_arch = "sparc64"
251 ),
252 )
253 )))]
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),
272 #[cfg(bsd)]
273 c::SIGEMT => Some(Self::Emt),
274 #[cfg(bsd)]
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),
280 _ => None,
281 }
282 }
283 }
284
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;
289
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;
307
308 #[cfg(not(target_os = "wasi"))]
309 pub(crate) type RawUname = c::utsname;
310
311 #[cfg(any(
312 target_os = "android",
313 target_os = "dragonfly",
314 target_os = "fuchsia",
315 target_os = "linux",
316 ))]
317 pub(crate) type RawCpuSet = c::cpu_set_t;
318
319 #[cfg(any(
320 target_os = "android",
321 target_os = "dragonfly",
322 target_os = "fuchsia",
323 target_os = "linux",
324 ))]
325 #[inline]
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);
329 set
330 }
331
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;