1use bitflags::bitflags as inner_bitflags;
2use core::{mem, ops::Deref, slice};
3
4macro_rules! bitflags {
5 (
6 $(#[$outer:meta])*
7 pub struct $BitFlags:ident: $T:ty {
8 $(
9 $(#[$inner:ident $($args:tt)*])*
10 const $Flag:ident = $value:expr;
11 )+
12 }
13 ) => {
14 inner_bitflags! {
16 #[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Clone, Copy, Default)]
17 $(#[$outer])*
18 pub struct $BitFlags: $T {
19 $(
20 $(#[$inner $($args)*])*
21 const $Flag = $value;
22 )+
23 }
24 }
25
26 impl $BitFlags {
27 #[deprecated = "use the safe `from_bits_retain` method instead"]
28 pub unsafe fn from_bits_unchecked(bits: $T) -> Self {
29 Self::from_bits_retain(bits)
30 }
31 }
32
33 $(
36 $(#[$inner $($args)*])*
37 pub const $Flag: $BitFlags = $BitFlags::$Flag;
38 )+
39 }
40}
41
42pub const CLOCK_REALTIME: usize = 1;
43pub const CLOCK_MONOTONIC: usize = 4;
44
45bitflags! {
46 pub struct EventFlags: usize {
47 const EVENT_NONE = 0;
48 const EVENT_READ = 1;
49 const EVENT_WRITE = 2;
50 }
51}
52
53pub const F_DUPFD: usize = 0;
54pub const F_GETFD: usize = 1;
55pub const F_SETFD: usize = 2;
56pub const F_GETFL: usize = 3;
57pub const F_SETFL: usize = 4;
58
59pub const FUTEX_WAIT: usize = 0;
60pub const FUTEX_WAKE: usize = 1;
61pub const FUTEX_REQUEUE: usize = 2;
62pub const FUTEX_WAIT64: usize = 3;
63
64bitflags::bitflags! {
66 #[derive(Clone, Copy, Debug)]
67 pub struct SendFdFlags: usize {
68 const EXCLUSIVE = 1;
74
75 const CLONE = 2;
78 }
79}
80bitflags::bitflags! {
81 #[derive(Clone, Copy, Debug)]
82 pub struct FobtainFdFlags: usize {
83 const MANUAL_FD = 1;
87
88 const EXCLUSIVE = 2;
91
92 const UPPER_TBL = 4;
94
95 const CLOEXEC = 8;
97
98 }
101}
102bitflags::bitflags! {
103 #[derive(Clone, Copy, Debug)]
104 pub struct RecvFdFlags: usize {
105 const MANUAL_FD = 1;
109
110 const UPPER_TBL = 2;
112
113 const CLOEXEC = 4;
115 }
116}
117bitflags::bitflags! {
118 #[derive(Clone, Copy, Debug)]
119 pub struct FmoveFdFlags: usize {
120 const EXCLUSIVE = 1;
126
127 const CLONE = 2;
130 }
131}
132
133bitflags! {
134 pub struct MapFlags: usize {
135 const PROT_NONE = 0x0000_0000;
138
139 const PROT_EXEC = 0x0001_0000;
140 const PROT_WRITE = 0x0002_0000;
141 const PROT_READ = 0x0004_0000;
142
143 const MAP_SHARED = 0x0001;
144 const MAP_PRIVATE = 0x0002;
145
146 const MAP_FIXED = 0x0004;
147 const MAP_FIXED_NOREPLACE = 0x000C;
148
149 const MAP_LAZY = 0x0010;
161 }
162}
163bitflags! {
164 pub struct MunmapFlags: usize {
165 const NEEDS_SYNC = 1;
170 }
171}
172
173pub const MODE_TYPE: u16 = 0xF000;
174pub const MODE_DIR: u16 = 0x4000;
175pub const MODE_FILE: u16 = 0x8000;
176pub const MODE_SYMLINK: u16 = 0xA000;
177pub const MODE_FIFO: u16 = 0x1000;
178pub const MODE_CHR: u16 = 0x2000;
179pub const MODE_SOCK: u16 = 0xC000;
180
181pub const MODE_PERM: u16 = 0x0FFF;
182pub const MODE_SETUID: u16 = 0o4000;
183pub const MODE_SETGID: u16 = 0o2000;
184
185pub const O_RDONLY: usize = 0x0001_0000;
186pub const O_WRONLY: usize = 0x0002_0000;
187pub const O_RDWR: usize = 0x0003_0000;
188pub const O_NONBLOCK: usize = 0x0004_0000;
189pub const O_APPEND: usize = 0x0008_0000;
190pub const O_SHLOCK: usize = 0x0010_0000;
191pub const O_EXLOCK: usize = 0x0020_0000;
192pub const O_ASYNC: usize = 0x0040_0000;
193pub const O_FSYNC: usize = 0x0080_0000;
194pub const O_CREAT: usize = 0x0200_0000;
195pub const O_TRUNC: usize = 0x0400_0000;
196pub const O_EXCL: usize = 0x0800_0000;
197pub const O_DIRECTORY: usize = 0x1000_0000;
198pub const O_STAT: usize = 0x2000_0000;
199pub const O_SYMLINK: usize = 0x4000_0000;
200pub const O_NOFOLLOW: usize = 0x8000_0000;
201pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;
202pub const O_FCNTL_MASK: usize = O_NONBLOCK | O_APPEND | O_ASYNC | O_FSYNC;
203
204pub const AT_REMOVEDIR: usize = 0x200;
206
207#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
211#[repr(usize)]
212pub enum ContextStatus {
213 Runnable,
214 Blocked,
215 NotYetStarted,
216 Dead,
217 ForceKilled,
218 Stopped,
219 UnhandledExcp,
220 #[default]
221 Other, }
223
224#[derive(Clone, Copy, Debug, Eq, PartialEq)]
225#[repr(usize)]
226#[allow(clippy::enum_clike_unportable_variant)]
227pub enum ContextVerb {
228 Stop = 1,
229 Unstop = 2,
230 Interrupt = 3,
231 ForceKill = usize::MAX,
233}
234impl ContextVerb {
235 pub fn try_from_raw(raw: usize) -> Option<Self> {
236 Some(match raw {
237 1 => Self::Stop,
238 2 => Self::Unstop,
239 3 => Self::Interrupt,
240 usize::MAX => Self::ForceKill,
241 _ => return None,
242 })
243 }
244}
245
246#[derive(Clone, Copy, Debug, Eq, PartialEq)]
248#[repr(u8)]
249pub enum AddrSpaceVerb {
250 MmapMin = 255,
251}
252impl AddrSpaceVerb {
253 pub fn try_from_raw(verb: u8) -> Option<Self> {
254 Some(match verb {
255 255 => Self::MmapMin,
256
257 _ => return None,
258 })
259 }
260}
261
262#[derive(Clone, Copy, Debug, Eq, PartialEq)]
264#[repr(u8)]
265pub enum ProcSchemeVerb {
266 RegsInt = 250,
267 RegsFloat = 251,
268 RegsEnv = 252,
269 SchedAffinity = 253,
270 Start = 254,
271 Iopl = 255,
272}
273impl ProcSchemeVerb {
274 pub fn try_from_raw(verb: u8) -> Option<Self> {
275 Some(match verb {
276 250 => Self::RegsInt,
277 251 => Self::RegsFloat,
278 252 => Self::RegsEnv,
279 253 => Self::SchedAffinity,
280 254 => Self::Start,
281 255 => Self::Iopl,
282 _ => return None,
283 })
284 }
285}
286
287#[derive(Clone, Copy, Debug, Eq, PartialEq)]
288pub enum FileTableVerb {
289 Close = 1,
290 Dup2 = 2,
291 Reserved1 = 3,
292 Resize = 4,
293}
294impl FileTableVerb {
295 pub fn try_from_raw(value: u8) -> Option<Self> {
296 Some(match value {
297 1 => Self::Close,
298 2 => Self::Dup2,
299 3 => Self::Reserved1,
300 4 => Self::Resize,
301 _ => return None,
302 })
303 }
304}
305
306#[derive(Clone, Copy, Debug, Eq, PartialEq)]
308#[repr(u64)]
309pub enum AcpiVerb {
310 ReadRxsdt = 1,
313 CheckShutdown = 2,
315 Msr = 3,
318}
319impl AcpiVerb {
320 pub const fn try_from_raw(value: u64) -> Option<Self> {
321 Some(match value {
322 1 => Self::ReadRxsdt,
323 2 => Self::CheckShutdown,
324 3 => Self::Msr,
325 _ => return None,
326 })
327 }
328}
329
330#[derive(Clone, Copy, Debug, Eq, PartialEq)]
331pub enum NumaVerb {
332 MemPolicy = 1,
333}
334impl NumaVerb {
335 pub fn try_from_raw(value: u64) -> Option<Self> {
336 Some(match value {
337 1 => Self::MemPolicy,
338 _ => return None,
339 })
340 }
341}
342
343#[derive(Clone, Copy, Debug, Eq, PartialEq)]
344#[repr(usize)]
345pub enum SchemeSocketCall {
346 ObtainFd = 0,
347 MoveFd = 1,
348}
349impl SchemeSocketCall {
350 pub fn try_from_raw(raw: usize) -> Option<Self> {
351 Some(match raw {
352 0 => Self::ObtainFd,
353 1 => Self::MoveFd,
354 _ => return None,
355 })
356 }
357}
358
359#[derive(Clone, Copy, Debug, Eq, PartialEq)]
360#[repr(usize)]
361#[non_exhaustive]
362pub enum FsCall {
363 Connect = 0,
364}
365impl FsCall {
366 pub fn try_from_raw(raw: usize) -> Option<Self> {
367 Some(match raw {
368 0 => Self::Connect,
369 _ => return None,
370 })
371 }
372}
373
374bitflags! {
375 pub struct PtraceFlags: u64 {
376 const PTRACE_STOP_PRE_SYSCALL = 0x0000_0000_0000_0001;
379 const PTRACE_STOP_POST_SYSCALL = 0x0000_0000_0000_0002;
381 const PTRACE_STOP_SINGLESTEP = 0x0000_0000_0000_0004;
384 const PTRACE_STOP_SIGNAL = 0x0000_0000_0000_0008;
387 const PTRACE_STOP_BREAKPOINT = 0x0000_0000_0000_0010;
390 const PTRACE_STOP_EXIT = 0x0000_0000_0000_0020;
392
393 const PTRACE_STOP_MASK = 0x0000_0000_0000_00FF;
394
395
396 const PTRACE_EVENT_CLONE = 0x0000_0000_0000_0100;
399
400 const PTRACE_EVENT_ADDRSPACE_SWITCH = 0x0000_0000_0000_0200;
402
403 const PTRACE_EVENT_MASK = 0x0000_0000_0000_0F00;
404
405 const PTRACE_FLAG_IGNORE = 0x0000_0000_0000_1000;
408
409 const PTRACE_FLAG_MASK = 0x0000_0000_0000_F000;
410 }
411}
412impl Deref for PtraceFlags {
413 type Target = [u8];
414 fn deref(&self) -> &Self::Target {
415 unsafe {
417 slice::from_raw_parts(&self.bits() as *const _ as *const u8, mem::size_of::<u64>())
418 }
419 }
420}
421
422pub const SEEK_SET: usize = 0;
423pub const SEEK_CUR: usize = 1;
424pub const SEEK_END: usize = 2;
425
426pub const SIGCHLD: usize = 17;
427pub const SIGTSTP: usize = 20;
428pub const SIGTTIN: usize = 21;
429pub const SIGTTOU: usize = 22;
430
431pub const ADDRSPACE_OP_MMAP: usize = 0;
432pub const ADDRSPACE_OP_MUNMAP: usize = 1;
433pub const ADDRSPACE_OP_MPROTECT: usize = 2;
434pub const ADDRSPACE_OP_TRANSFER: usize = 3;
435
436bitflags! {
437 pub struct MremapFlags: usize {
438 const FIXED = 1;
439 const FIXED_REPLACE = 3;
440 const KEEP_OLD = 1 << 2;
443 }
445}
446bitflags! {
447 pub struct RwFlags: u32 {
448 const NONBLOCK = 1;
449 const APPEND = 2;
450 }
453}
454bitflags! {
455 pub struct SigcontrolFlags: usize {
456 const INHIBIT_DELIVERY = 1;
460 }
461}
462bitflags! {
463 pub struct CallFlags: usize {
464 const RSVD0 = 1 << 0;
466 const RSVD1 = 1 << 1;
467 const RSVD2 = 1 << 2;
468 const RSVD3 = 1 << 3;
469 const RSVD4 = 1 << 4;
470 const RSVD5 = 1 << 5;
471 const RSVD6 = 1 << 6;
472 const RSVD7 = 1 << 7;
473
474 const CONSUME = 1 << 8;
476
477 const WRITE = 1 << 9;
478 const READ = 1 << 10;
479
480 const FD = 1 << 11;
482 const FD_EXCLUSIVE = 1 << 12;
484 const FD_CLONE = 1 << 13;
485 const FD_UPPER = 1 << 14;
486 const FD_CLOEXEC = 1 << 15;
487
488 const STD_FS = 1 << 16;
490
491 const MULTIPLE_FDS = 1 << 17;
493 }
494}
495
496#[repr(u8)]
497#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord)]
498pub enum StdFsCallKind {
499 Fchmod = 1,
501 Fchown = 2,
502 Getdents = 3,
503 Fstat = 4,
504 Fstatvfs = 5,
505 Fsync = 6,
506 Ftruncate = 7,
507 Futimens = 8,
508 Relpathat = 11,
511 Lock = 12,
512 Unlock = 13,
513 GetLock = 14,
514}
515
516impl StdFsCallKind {
517 pub fn try_from_raw(raw: u8) -> Option<Self> {
518 use StdFsCallKind::*;
519
520 Some(match raw {
522 1 => Fchmod,
523 2 => Fchown,
524 3 => Getdents,
525 4 => Fstat,
526 5 => Fstatvfs,
527 6 => Fsync,
528 7 => Ftruncate,
529 8 => Futimens,
530 11 => Relpathat,
533 12 => Lock,
534 13 => Unlock,
535 14 => GetLock,
536 _ => return None,
537 })
538 }
539}
540
541pub const UPPER_FDTBL_TAG: usize = 1 << (usize::BITS - 2);
543
544pub const EVENT_TIMEOUT_ID: usize = usize::MAX - 2;