flag.rs 6.97 KB
Newer Older
jD91mZM2's avatar
jD91mZM2 committed
1
use bitflags::bitflags as inner_bitflags;
jD91mZM2's avatar
jD91mZM2 committed
2
use core::{mem, ops::Deref, slice};
jD91mZM2's avatar
jD91mZM2 committed
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

macro_rules! bitflags {
    (
        $(#[$outer:meta])*
        pub struct $BitFlags:ident: $T:ty {
            $(
                $(#[$inner:ident $($args:tt)*])*
                const $Flag:ident = $value:expr;
            )+
        }
    ) => {
        // First, use the inner bitflags
        inner_bitflags! {
            #[derive(Default)]
            $(#[$outer])*
            pub struct $BitFlags: $T {
                $(
                    $(#[$inner $($args)*])*
                    const $Flag = $value;
                )+
            }
        }

        // Secondly, re-export all inner constants
        // (`pub use self::Struct::*` doesn't work)
        $(
            $(#[$inner $($args)*])*
            pub const $Flag: $BitFlags = $BitFlags::$Flag;
        )+
    }
}

bitflags! {
    pub struct CloneFlags: usize {
        const CLONE_VM = 0x100;
        const CLONE_FS = 0x200;
        const CLONE_FILES = 0x400;
        const CLONE_SIGHAND = 0x800;
        const CLONE_VFORK = 0x4000;
        const CLONE_THREAD = 0x10000;
        const CLONE_STACK = 0x1000_0000;
    }
}
Jeremy Soller's avatar
Jeremy Soller committed
46

Jeremy Soller's avatar
Jeremy Soller committed
47
48
49
pub const CLOCK_REALTIME: usize = 1;
pub const CLOCK_MONOTONIC: usize = 4;

jD91mZM2's avatar
jD91mZM2 committed
50
51
52
53
54
55
56
bitflags! {
    pub struct EventFlags: usize {
        const EVENT_NONE = 0;
        const EVENT_READ = 1;
        const EVENT_WRITE = 2;
    }
}
Jeremy Soller's avatar
Jeremy Soller committed
57

Ian Douglas Scott's avatar
Ian Douglas Scott committed
58
pub const F_DUPFD: usize = 0;
Ian Douglas Scott's avatar
Ian Douglas Scott committed
59
60
61
62
pub const F_GETFD: usize = 1;
pub const F_SETFD: usize = 2;
pub const F_GETFL: usize = 3;
pub const F_SETFL: usize = 4;
Jeremy Soller's avatar
Jeremy Soller committed
63

Jeremy Soller's avatar
Jeremy Soller committed
64
65
66
67
pub const FUTEX_WAIT: usize = 0;
pub const FUTEX_WAKE: usize = 1;
pub const FUTEX_REQUEUE: usize = 2;

jD91mZM2's avatar
jD91mZM2 committed
68
69
bitflags! {
    pub struct MapFlags: usize {
jD91mZM2's avatar
jD91mZM2 committed
70
71
72
73
74
        const PROT_NONE = 0x0000_0000;
        const PROT_EXEC = 0x0001_0000;
        const PROT_WRITE = 0x0002_0000;
        const PROT_READ = 0x0004_0000;

jD91mZM2's avatar
jD91mZM2 committed
75
76
77
78
        const MAP_SHARED = 0x0001;
        const MAP_PRIVATE = 0x0002;
    }
}
79

Jeremy Soller's avatar
Jeremy Soller committed
80
pub const MODE_TYPE: u16 = 0xF000;
81
82
pub const MODE_DIR: u16 = 0x4000;
pub const MODE_FILE: u16 = 0x8000;
Ian Douglas Scott's avatar
Ian Douglas Scott committed
83
pub const MODE_SYMLINK: u16 = 0xA000;
Ian Douglas Scott's avatar
Ian Douglas Scott committed
84
pub const MODE_FIFO: u16 = 0x1000;
85
pub const MODE_CHR: u16 = 0x2000;
Jeremy Soller's avatar
Jeremy Soller committed
86
87
88
89

pub const MODE_PERM: u16 = 0x0FFF;
pub const MODE_SETUID: u16 = 0o4000;
pub const MODE_SETGID: u16 = 0o2000;
90

91
92
93
pub const O_RDONLY: usize =     0x0001_0000;
pub const O_WRONLY: usize =     0x0002_0000;
pub const O_RDWR: usize =       0x0003_0000;
Jeremy Soller's avatar
Jeremy Soller committed
94
95
96
97
98
99
100
101
102
103
pub const O_NONBLOCK: usize =   0x0004_0000;
pub const O_APPEND: usize =     0x0008_0000;
pub const O_SHLOCK: usize =     0x0010_0000;
pub const O_EXLOCK: usize =     0x0020_0000;
pub const O_ASYNC: usize =      0x0040_0000;
pub const O_FSYNC: usize =      0x0080_0000;
pub const O_CLOEXEC: usize =    0x0100_0000;
pub const O_CREAT: usize =      0x0200_0000;
pub const O_TRUNC: usize =      0x0400_0000;
pub const O_EXCL: usize =       0x0800_0000;
Jeremy Soller's avatar
Jeremy Soller committed
104
pub const O_DIRECTORY: usize =  0x1000_0000;
105
pub const O_STAT: usize =       0x2000_0000;
Ian Douglas Scott's avatar
Ian Douglas Scott committed
106
pub const O_SYMLINK: usize =    0x4000_0000;
Ian Douglas Scott's avatar
Ian Douglas Scott committed
107
pub const O_NOFOLLOW: usize =   0x8000_0000;
Jeremy Soller's avatar
Jeremy Soller committed
108
pub const O_ACCMODE: usize =    O_RDONLY | O_WRONLY | O_RDWR;
109

jD91mZM2's avatar
jD91mZM2 committed
110
111
112
113
114
115
116
bitflags! {
    pub struct PhysmapFlags: usize {
        const PHYSMAP_WRITE = 0x0000_0001;
        const PHYSMAP_WRITE_COMBINE = 0x0000_0002;
        const PHYSMAP_NO_CACHE = 0x0000_0004;
    }
}
117

jD91mZM2's avatar
jD91mZM2 committed
118
// The top 48 bits of PTRACE_* are reserved, for now
jD91mZM2's avatar
jD91mZM2 committed
119

jD91mZM2's avatar
jD91mZM2 committed
120
121
122
123
124
125
bitflags! {
    pub struct PtraceFlags: u64 {
        const PTRACE_STOP_PRE_SYSCALL = 0x0000_0000_0000_0001;
        const PTRACE_STOP_POST_SYSCALL = 0x0000_0000_0000_0002;
        const PTRACE_STOP_SINGLESTEP = 0x0000_0000_0000_0004;
        const PTRACE_STOP_SIGNAL = 0x0000_0000_0000_0008;
jD91mZM2's avatar
jD91mZM2 committed
126
        const PTRACE_STOP_BREAKPOINT = 0x0000_0000_0000_0010;
jD91mZM2's avatar
jD91mZM2 committed
127
        const PTRACE_STOP_EXIT = 0x0000_0000_0000_0020;
jD91mZM2's avatar
jD91mZM2 committed
128
129
130
131
132
        const PTRACE_STOP_MASK = 0x0000_0000_0000_00FF;

        const PTRACE_EVENT_CLONE = 0x0000_0000_0000_0100;
        const PTRACE_EVENT_MASK = 0x0000_0000_0000_0F00;

jD91mZM2's avatar
jD91mZM2 committed
133
        const PTRACE_FLAG_IGNORE = 0x0000_0000_0000_1000;
jD91mZM2's avatar
jD91mZM2 committed
134
135
136
        const PTRACE_FLAG_MASK = 0x0000_0000_0000_F000;
    }
}
jD91mZM2's avatar
jD91mZM2 committed
137
138
139
140
141
142
143
144
145
146
147
148
impl Deref for PtraceFlags {
    type Target = [u8];
    fn deref(&self) -> &Self::Target {
        // Same as to_ne_bytes but in-place
        unsafe {
            slice::from_raw_parts(
                &self.bits as *const _ as *const u8,
                mem::size_of::<u64>()
            )
        }
    }
}
jD91mZM2's avatar
jD91mZM2 committed
149

150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
pub const SEEK_SET: usize = 0;
pub const SEEK_CUR: usize = 1;
pub const SEEK_END: usize = 2;

pub const SIGHUP: usize =   1;
pub const SIGINT: usize =   2;
pub const SIGQUIT: usize =  3;
pub const SIGILL: usize =   4;
pub const SIGTRAP: usize =  5;
pub const SIGABRT: usize =  6;
pub const SIGBUS: usize =   7;
pub const SIGFPE: usize =   8;
pub const SIGKILL: usize =  9;
pub const SIGUSR1: usize =  10;
pub const SIGSEGV: usize =  11;
pub const SIGUSR2: usize =  12;
pub const SIGPIPE: usize =  13;
pub const SIGALRM: usize =  14;
pub const SIGTERM: usize =  15;
pub const SIGSTKFLT: usize= 16;
pub const SIGCHLD: usize =  17;
pub const SIGCONT: usize =  18;
pub const SIGSTOP: usize =  19;
pub const SIGTSTP: usize =  20;
pub const SIGTTIN: usize =  21;
pub const SIGTTOU: usize =  22;
pub const SIGURG: usize =   23;
pub const SIGXCPU: usize =  24;
pub const SIGXFSZ: usize =  25;
pub const SIGVTALRM: usize= 26;
pub const SIGPROF: usize =  27;
pub const SIGWINCH: usize = 28;
pub const SIGIO: usize =    29;
pub const SIGPWR: usize =   30;
pub const SIGSYS: usize =   31;

Jeremy Soller's avatar
Jeremy Soller committed
186
187
188
pub const SIG_DFL: usize = 0;
pub const SIG_IGN: usize = 1;

Jeremy Soller's avatar
Jeremy Soller committed
189
190
191
192
pub const SIG_BLOCK: usize = 0;
pub const SIG_UNBLOCK: usize = 1;
pub const SIG_SETMASK: usize = 2;

jD91mZM2's avatar
jD91mZM2 committed
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
bitflags! {
    pub struct SigActionFlags: usize {
        const SA_NOCLDSTOP = 0x00000001;
        const SA_NOCLDWAIT = 0x00000002;
        const SA_SIGINFO =   0x00000004;
        const SA_RESTORER =  0x04000000;
        const SA_ONSTACK =   0x08000000;
        const SA_RESTART =   0x10000000;
        const SA_NODEFER =   0x40000000;
        const SA_RESETHAND = 0x80000000;
    }
}

bitflags! {
    pub struct WaitFlags: usize {
        const WNOHANG =    0x01;
        const WUNTRACED =  0x02;
        const WCONTINUED = 0x08;
    }
}
Jeremy Soller's avatar
Jeremy Soller committed
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252

/// True if status indicates the child is stopped.
pub fn wifstopped(status: usize) -> bool {
    (status & 0xff) == 0x7f
}

/// If wifstopped(status), the signal that stopped the child.
pub fn wstopsig(status: usize) -> usize {
    (status >> 8) & 0xff
}

/// True if status indicates the child continued after a stop.
pub fn wifcontinued(status: usize) -> bool {
    status == 0xffff
}

/// True if STATUS indicates termination by a signal.
pub fn wifsignaled(status: usize) -> bool {
    ((status & 0x7f) + 1) as i8 >= 2
}

/// If wifsignaled(status), the terminating signal.
pub fn wtermsig(status: usize) -> usize {
    status & 0x7f
}

/// True if status indicates normal termination.
pub fn wifexited(status: usize) -> bool {
    wtermsig(status) == 0
}

/// If wifexited(status), the exit status.
pub fn wexitstatus(status: usize) -> usize {
    (status >> 8) & 0xff
}

/// True if status indicates a core dump was created.
pub fn wcoredump(status: usize) -> bool {
    (status & 0x80) != 0
}