1use bitflags::bitflags;
6use core::ffi::{c_int, c_ulonglong};
7
8bitflags! {
9 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
11 pub struct CloneFlags: usize {
12 const CSIGNAL = 0x000000FF;
14
15 const VM = 0x00000100;
18 const FS = 0x00000200;
20 const FILES = 0x00000400;
22 const SIGHAND = 0x00000800;
24
25 const PIDFD = 0x00001000;
27 const PTRACE = 0x00002000;
29 const VFORK = 0x00004000;
32 const PARENT = 0x00008000;
34 const THREAD = 0x00010000;
36
37 const NEWNS = 0x00020000;
40 const SYSVSEM = 0x00040000;
42 const SETTLS = 0x00080000;
44 const PARENT_SETTID = 0x00100000;
46 const CHILD_CLEARTID = 0x00200000;
48 const DETACHED = 0x00400000;
50 const UNTRACED = 0x00800000;
52 const CHILD_SETTID = 0x01000000;
54 const NEWCGROUP = 0x02000000;
56 const NEWUTS = 0x04000000;
58 const NEWIPC = 0x08000000;
60 const NEWUSER = 0x10000000;
62 const NEWPID = 0x20000000;
64 const NEWNET = 0x40000000;
66 const IO = 0x80000000;
68
69 const NEWTIME = 0x00000080;
72 }
73}
74
75const ALL_KNOWN_FLAGS: CloneFlags = CloneFlags::all();
77
78const CURRENTLY_SUPPORTED_FLAGS: CloneFlags = CloneFlags::from_bits_truncate(
80 CloneFlags::CSIGNAL.bits()
81 | CloneFlags::VM.bits()
82 | CloneFlags::FS.bits()
83 | CloneFlags::FILES.bits()
84 | CloneFlags::SIGHAND.bits()
85 | CloneFlags::PARENT.bits()
86 | CloneFlags::THREAD.bits()
87 | CloneFlags::PARENT_SETTID.bits()
88 | CloneFlags::CHILD_SETTID.bits(),
89);
90
91impl CloneFlags {
92 pub fn is_supported(&self) -> bool {
94 self.bits() & !CURRENTLY_SUPPORTED_FLAGS.bits() == 0
95 }
96
97 pub fn is_known(&self) -> bool {
99 self.bits() & !ALL_KNOWN_FLAGS.bits() == 0
100 }
101
102 pub fn get_exit_signal(&self) -> u8 {
104 (self.bits() & CloneFlags::CSIGNAL.bits()) as u8
105 }
106}
107
108pub mod clone3_flags {
110 pub const CLEAR_SIGHAND: u64 = 0x100000000; pub const INTO_CGROUP: u64 = 0x200000000; }
113
114#[repr(C)]
119#[derive(Debug, Default)]
120pub struct CloneArgs {
121 pub flags: c_ulonglong, pub pidfd: c_ulonglong, pub child_tid: c_ulonglong, pub parent_tid: c_ulonglong, pub exit_signal: c_ulonglong, pub stack: c_ulonglong, pub stack_size: c_ulonglong, pub tls: c_ulonglong, pub set_tid: c_ulonglong, pub set_tid_size: c_ulonglong, pub cgroup: c_ulonglong, }
133
134pub const CLONE_ARGS_SIZE_VER0: usize = 64;
136pub const CLONE_ARGS_SIZE_VER1: usize = 80;
137pub const CLONE_ARGS_SIZE_VER2: usize = 88;
138
139#[repr(u32)] #[derive(Debug, Clone, Copy, PartialEq, Eq)]
142pub enum SchedulingPolicy {
143 Normal = 0, Fifo = 1, Rr = 2, Batch = 3, Idle = 5, Deadline = 6, Ext = 7, }
151
152pub const SCHED_RESET_ON_FORK: c_int = 0x40000000;
154
155bitflags! {
156 #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
158 pub struct SchedFlags: u32 {
159 const RESET_ON_FORK = 0x01; const RECLAIM = 0x02; const DL_OVERRUN = 0x04; const KEEP_POLICY = 0x08; const KEEP_PARAMS = 0x10; const UTIL_CLAMP_MIN = 0x20; const UTIL_CLAMP_MAX = 0x40; const KEEP_ALL = Self::KEEP_POLICY.bits() | Self::KEEP_PARAMS.bits();
169
170 const UTIL_CLAMP = Self::UTIL_CLAMP_MIN.bits() | Self::UTIL_CLAMP_MAX.bits();
172
173 const ALL = Self::RESET_ON_FORK.bits() |
175 Self::RECLAIM.bits() |
176 Self::DL_OVERRUN.bits() |
177 Self::KEEP_ALL.bits() |
178 Self::UTIL_CLAMP.bits();
179 }
180}