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;
58pub const F_DUPFD_CLOEXEC: usize = 1030;
59
60pub const FUTEX_WAIT: usize = 0;
61pub const FUTEX_WAKE: usize = 1;
62pub const FUTEX_REQUEUE: usize = 2;
63pub const FUTEX_WAIT64: usize = 3;
64
65bitflags::bitflags! {
67 #[derive(Clone, Copy, Debug)]
68 pub struct SendFdFlags: usize {
69 const EXCLUSIVE = 1;
75
76 const CLONE = 2;
79 }
80}
81bitflags::bitflags! {
82 #[derive(Clone, Copy, Debug)]
83 pub struct FobtainFdFlags: usize {
84 const MANUAL_FD = 1;
88
89 const EXCLUSIVE = 2;
92
93 const UPPER_TBL = 4;
95
96 const CLOEXEC = 8;
98
99 }
102}
103bitflags::bitflags! {
104 #[derive(Clone, Copy, Debug)]
105 pub struct RecvFdFlags: usize {
106 const MANUAL_FD = 1;
110
111 const UPPER_TBL = 2;
113
114 const CLOEXEC = 4;
116 }
117}
118bitflags::bitflags! {
119 #[derive(Clone, Copy, Debug)]
120 pub struct FmoveFdFlags: usize {
121 const EXCLUSIVE = 1;
127
128 const CLONE = 2;
131 }
132}
133
134bitflags! {
135 pub struct MapFlags: usize {
136 const PROT_NONE = 0x0000_0000;
139
140 const PROT_EXEC = 0x0001_0000;
141 const PROT_WRITE = 0x0002_0000;
142 const PROT_READ = 0x0004_0000;
143
144 const MAP_SHARED = 0x0001;
145 const MAP_PRIVATE = 0x0002;
146
147 const MAP_FIXED = 0x0004;
148 const MAP_FIXED_NOREPLACE = 0x000C;
149
150 const MAP_LAZY = 0x0010;
162 }
163}
164bitflags! {
165 pub struct MunmapFlags: usize {
166 const NEEDS_SYNC = 1;
171 }
172}
173
174pub const MODE_TYPE: u16 = 0xF000;
175pub const MODE_DIR: u16 = 0x4000;
176pub const MODE_FILE: u16 = 0x8000;
177pub const MODE_SYMLINK: u16 = 0xA000;
178pub const MODE_FIFO: u16 = 0x1000;
179pub const MODE_CHR: u16 = 0x2000;
180pub const MODE_SOCK: u16 = 0xC000;
181
182pub const MODE_PERM: u16 = 0x0FFF;
183pub const MODE_SETUID: u16 = 0o4000;
184pub const MODE_SETGID: u16 = 0o2000;
185
186pub const O_RDONLY: usize = 0x0001_0000;
187pub const O_WRONLY: usize = 0x0002_0000;
188pub const O_RDWR: usize = 0x0003_0000;
189pub const O_NONBLOCK: usize = 0x0004_0000;
190pub const O_APPEND: usize = 0x0008_0000;
191pub const O_SHLOCK: usize = 0x0010_0000;
192pub const O_EXLOCK: usize = 0x0020_0000;
193pub const O_ASYNC: usize = 0x0040_0000;
194pub const O_FSYNC: usize = 0x0080_0000;
195pub const O_CLOEXEC: usize = 0x0100_0000;
196pub const O_CREAT: usize = 0x0200_0000;
197pub const O_TRUNC: usize = 0x0400_0000;
198pub const O_EXCL: usize = 0x0800_0000;
199pub const O_DIRECTORY: usize = 0x1000_0000;
200pub const O_STAT: usize = 0x2000_0000;
201pub const O_SYMLINK: usize = 0x4000_0000;
202pub const O_NOFOLLOW: usize = 0x8000_0000;
203pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR;
204pub const O_FCNTL_MASK: usize = O_NONBLOCK | O_APPEND | O_ASYNC | O_FSYNC;
205
206pub const AT_REMOVEDIR: usize = 0x200;
208
209#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
213#[repr(usize)]
214pub enum ContextStatus {
215 Runnable,
216 Blocked,
217 NotYetStarted,
218 Dead,
219 ForceKilled,
220 Stopped,
221 UnhandledExcp,
222 #[default]
223 Other, }
225
226#[derive(Clone, Copy, Debug, Eq, PartialEq)]
227#[repr(usize)]
228pub enum ContextVerb {
229 Stop = 1,
230 Unstop = 2,
231 Interrupt = 3,
232 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 ProcSchemeVerb {
250 Iopl = 255,
251}
252impl ProcSchemeVerb {
253 pub fn try_from_raw(verb: u8) -> Option<Self> {
254 Some(match verb {
255 255 => Self::Iopl,
256 _ => return None,
257 })
258 }
259}
260
261#[derive(Clone, Copy, Debug, Eq, PartialEq)]
262#[repr(usize)]
263pub enum SchemeSocketCall {
264 ObtainFd = 0,
265 MoveFd = 1,
266}
267impl SchemeSocketCall {
268 pub fn try_from_raw(raw: usize) -> Option<Self> {
269 Some(match raw {
270 0 => Self::ObtainFd,
271 1 => Self::MoveFd,
272 _ => return None,
273 })
274 }
275}
276
277#[derive(Clone, Copy, Debug, Eq, PartialEq)]
278#[repr(usize)]
279#[non_exhaustive]
280pub enum FsCall {
281 Connect = 0,
282}
283impl FsCall {
284 pub fn try_from_raw(raw: usize) -> Option<Self> {
285 Some(match raw {
286 0 => Self::Connect,
287 _ => return None,
288 })
289 }
290}
291
292bitflags! {
293 pub struct PtraceFlags: u64 {
294 const PTRACE_STOP_PRE_SYSCALL = 0x0000_0000_0000_0001;
297 const PTRACE_STOP_POST_SYSCALL = 0x0000_0000_0000_0002;
299 const PTRACE_STOP_SINGLESTEP = 0x0000_0000_0000_0004;
302 const PTRACE_STOP_SIGNAL = 0x0000_0000_0000_0008;
305 const PTRACE_STOP_BREAKPOINT = 0x0000_0000_0000_0010;
308 const PTRACE_STOP_EXIT = 0x0000_0000_0000_0020;
310
311 const PTRACE_STOP_MASK = 0x0000_0000_0000_00FF;
312
313
314 const PTRACE_EVENT_CLONE = 0x0000_0000_0000_0100;
317
318 const PTRACE_EVENT_ADDRSPACE_SWITCH = 0x0000_0000_0000_0200;
320
321 const PTRACE_EVENT_MASK = 0x0000_0000_0000_0F00;
322
323 const PTRACE_FLAG_IGNORE = 0x0000_0000_0000_1000;
326
327 const PTRACE_FLAG_MASK = 0x0000_0000_0000_F000;
328 }
329}
330impl Deref for PtraceFlags {
331 type Target = [u8];
332 fn deref(&self) -> &Self::Target {
333 unsafe {
335 slice::from_raw_parts(&self.bits() as *const _ as *const u8, mem::size_of::<u64>())
336 }
337 }
338}
339
340pub const SEEK_SET: usize = 0;
341pub const SEEK_CUR: usize = 1;
342pub const SEEK_END: usize = 2;
343
344pub const SIGCHLD: usize = 17;
345pub const SIGTSTP: usize = 20;
346pub const SIGTTIN: usize = 21;
347pub const SIGTTOU: usize = 22;
348
349pub const ADDRSPACE_OP_MMAP: usize = 0;
350pub const ADDRSPACE_OP_MUNMAP: usize = 1;
351pub const ADDRSPACE_OP_MPROTECT: usize = 2;
352pub const ADDRSPACE_OP_TRANSFER: usize = 3;
353
354bitflags! {
355 pub struct MremapFlags: usize {
356 const FIXED = 1;
357 const FIXED_REPLACE = 3;
358 const KEEP_OLD = 1 << 2;
361 }
363}
364bitflags! {
365 pub struct RwFlags: u32 {
366 const NONBLOCK = 1;
367 const APPEND = 2;
368 }
371}
372bitflags! {
373 pub struct SigcontrolFlags: usize {
374 const INHIBIT_DELIVERY = 1;
378 }
379}
380bitflags! {
381 pub struct CallFlags: usize {
382 const RSVD0 = 1 << 0;
384 const RSVD1 = 1 << 1;
385 const RSVD2 = 1 << 2;
386 const RSVD3 = 1 << 3;
387 const RSVD4 = 1 << 4;
388 const RSVD5 = 1 << 5;
389 const RSVD6 = 1 << 6;
390 const RSVD7 = 1 << 7;
391
392 const CONSUME = 1 << 8;
394
395 const WRITE = 1 << 9;
396 const READ = 1 << 10;
397
398 const FD = 1 << 11;
400 const FD_EXCLUSIVE = 1 << 12;
402 const FD_CLONE = 1 << 13;
403 const FD_UPPER = 1 << 14;
404 const FD_CLOEXEC = 1 << 15;
405 }
406}
407
408pub const UPPER_FDTBL_TAG: usize = 1 << (usize::BITS - 2);