1 use crate::backend::c; 2 use bitflags::bitflags; 3 4 bitflags! { 5 /// `PROT_*` flags for use with [`mmap`]. 6 /// 7 /// For `PROT_NONE`, use `ProtFlags::empty()`. 8 /// 9 /// [`mmap`]: crate::mm::mmap 10 #[repr(transparent)] 11 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 12 pub struct ProtFlags: u32 { 13 /// `PROT_READ` 14 const READ = linux_raw_sys::general::PROT_READ; 15 /// `PROT_WRITE` 16 const WRITE = linux_raw_sys::general::PROT_WRITE; 17 /// `PROT_EXEC` 18 const EXEC = linux_raw_sys::general::PROT_EXEC; 19 20 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 21 const _ = !0; 22 } 23 } 24 25 bitflags! { 26 /// `PROT_*` flags for use with [`mprotect`]. 27 /// 28 /// For `PROT_NONE`, use `MprotectFlags::empty()`. 29 /// 30 /// [`mprotect`]: crate::mm::mprotect 31 #[repr(transparent)] 32 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 33 pub struct MprotectFlags: u32 { 34 /// `PROT_READ` 35 const READ = linux_raw_sys::general::PROT_READ; 36 /// `PROT_WRITE` 37 const WRITE = linux_raw_sys::general::PROT_WRITE; 38 /// `PROT_EXEC` 39 const EXEC = linux_raw_sys::general::PROT_EXEC; 40 /// `PROT_GROWSUP` 41 const GROWSUP = linux_raw_sys::general::PROT_GROWSUP; 42 /// `PROT_GROWSDOWN` 43 const GROWSDOWN = linux_raw_sys::general::PROT_GROWSDOWN; 44 /// `PROT_SEM` 45 const SEM = linux_raw_sys::general::PROT_SEM; 46 /// `PROT_BTI` 47 #[cfg(target_arch = "aarch64")] 48 const BTI = linux_raw_sys::general::PROT_BTI; 49 /// `PROT_MTE` 50 #[cfg(target_arch = "aarch64")] 51 const MTE = linux_raw_sys::general::PROT_MTE; 52 /// `PROT_SAO` 53 #[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))] 54 const SAO = linux_raw_sys::general::PROT_SAO; 55 /// `PROT_ADI` 56 #[cfg(any(target_arch = "sparc", target_arch = "sparc64"))] 57 const ADI = linux_raw_sys::general::PROT_ADI; 58 59 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 60 const _ = !0; 61 } 62 } 63 64 bitflags! { 65 /// `MAP_*` flags for use with [`mmap`]. 66 /// 67 /// For `MAP_ANONYMOUS` (aka `MAP_ANON`), see [`mmap_anonymous`]. 68 /// 69 /// [`mmap`]: crate::mm::mmap 70 /// [`mmap_anonymous`]: crates::mm::mmap_anonymous 71 #[repr(transparent)] 72 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 73 pub struct MapFlags: u32 { 74 /// `MAP_SHARED` 75 const SHARED = linux_raw_sys::general::MAP_SHARED; 76 /// `MAP_SHARED_VALIDATE` (since Linux 4.15) 77 const SHARED_VALIDATE = linux_raw_sys::general::MAP_SHARED_VALIDATE; 78 /// `MAP_PRIVATE` 79 const PRIVATE = linux_raw_sys::general::MAP_PRIVATE; 80 /// `MAP_DENYWRITE` 81 const DENYWRITE = linux_raw_sys::general::MAP_DENYWRITE; 82 /// `MAP_FIXED` 83 const FIXED = linux_raw_sys::general::MAP_FIXED; 84 /// `MAP_FIXED_NOREPLACE` (since Linux 4.17) 85 const FIXED_NOREPLACE = linux_raw_sys::general::MAP_FIXED_NOREPLACE; 86 /// `MAP_GROWSDOWN` 87 const GROWSDOWN = linux_raw_sys::general::MAP_GROWSDOWN; 88 /// `MAP_HUGETLB` 89 const HUGETLB = linux_raw_sys::general::MAP_HUGETLB; 90 /// `MAP_HUGE_2MB` (since Linux 3.8) 91 const HUGE_2MB = linux_raw_sys::general::MAP_HUGE_2MB; 92 /// `MAP_HUGE_1GB` (since Linux 3.8) 93 const HUGE_1GB = linux_raw_sys::general::MAP_HUGE_1GB; 94 /// `MAP_LOCKED` 95 const LOCKED = linux_raw_sys::general::MAP_LOCKED; 96 /// `MAP_NORESERVE` 97 const NORESERVE = linux_raw_sys::general::MAP_NORESERVE; 98 /// `MAP_POPULATE` 99 const POPULATE = linux_raw_sys::general::MAP_POPULATE; 100 /// `MAP_STACK` 101 const STACK = linux_raw_sys::general::MAP_STACK; 102 /// `MAP_SYNC` (since Linux 4.15) 103 #[cfg(not(any(target_arch = "mips", target_arch = "mips32r6", target_arch = "mips64", target_arch = "mips64r6")))] 104 const SYNC = linux_raw_sys::general::MAP_SYNC; 105 /// `MAP_UNINITIALIZED` 106 #[cfg(not(any(target_arch = "mips", target_arch = "mips32r6", target_arch = "mips64", target_arch = "mips64r6")))] 107 const UNINITIALIZED = linux_raw_sys::general::MAP_UNINITIALIZED; 108 109 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 110 const _ = !0; 111 } 112 } 113 114 bitflags! { 115 /// `MREMAP_*` flags for use with [`mremap`]. 116 /// 117 /// For `MREMAP_FIXED`, see [`mremap_fixed`]. 118 /// 119 /// [`mremap`]: crate::mm::mremap 120 /// [`mremap_fixed`]: crate::mm::mremap_fixed 121 #[repr(transparent)] 122 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 123 pub struct MremapFlags: u32 { 124 /// `MREMAP_MAYMOVE` 125 const MAYMOVE = linux_raw_sys::general::MREMAP_MAYMOVE; 126 /// `MREMAP_DONTUNMAP` (since Linux 5.7) 127 const DONTUNMAP = linux_raw_sys::general::MREMAP_DONTUNMAP; 128 129 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 130 const _ = !0; 131 } 132 } 133 134 bitflags! { 135 /// `MS_*` flags for use with [`msync`]. 136 /// 137 /// [`msync`]: crate::mm::msync 138 #[repr(transparent)] 139 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 140 pub struct MsyncFlags: u32 { 141 /// `MS_SYNC`—Requests an update and waits for it to complete. 142 const SYNC = linux_raw_sys::general::MS_SYNC; 143 /// `MS_ASYNC`—Specifies that an update be scheduled, but the call 144 /// returns immediately. 145 const ASYNC = linux_raw_sys::general::MS_ASYNC; 146 /// `MS_INVALIDATE`—Asks to invalidate other mappings of the same 147 /// file (so that they can be updated with the fresh values just 148 /// written). 149 const INVALIDATE = linux_raw_sys::general::MS_INVALIDATE; 150 151 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 152 const _ = !0; 153 } 154 } 155 156 bitflags! { 157 /// `MLOCK_*` flags for use with [`mlock_with`]. 158 /// 159 /// [`mlock_with`]: crate::mm::mlock_with 160 #[repr(transparent)] 161 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 162 pub struct MlockFlags: u32 { 163 /// `MLOCK_ONFAULT` 164 const ONFAULT = linux_raw_sys::general::MLOCK_ONFAULT; 165 166 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 167 const _ = !0; 168 } 169 } 170 171 /// `POSIX_MADV_*` constants for use with [`madvise`]. 172 /// 173 /// [`madvise`]: crate::mm::madvise 174 #[derive(Debug, Copy, Clone, Eq, PartialEq)] 175 #[repr(u32)] 176 #[non_exhaustive] 177 pub enum Advice { 178 /// `POSIX_MADV_NORMAL` 179 Normal = linux_raw_sys::general::MADV_NORMAL, 180 181 /// `POSIX_MADV_SEQUENTIAL` 182 Sequential = linux_raw_sys::general::MADV_SEQUENTIAL, 183 184 /// `POSIX_MADV_RANDOM` 185 Random = linux_raw_sys::general::MADV_RANDOM, 186 187 /// `POSIX_MADV_WILLNEED` 188 WillNeed = linux_raw_sys::general::MADV_WILLNEED, 189 190 /// `MADV_DONTNEED` 191 LinuxDontNeed = linux_raw_sys::general::MADV_DONTNEED, 192 193 /// `MADV_FREE` (since Linux 4.5) 194 LinuxFree = linux_raw_sys::general::MADV_FREE, 195 /// `MADV_REMOVE` 196 LinuxRemove = linux_raw_sys::general::MADV_REMOVE, 197 /// `MADV_DONTFORK` 198 LinuxDontFork = linux_raw_sys::general::MADV_DONTFORK, 199 /// `MADV_DOFORK` 200 LinuxDoFork = linux_raw_sys::general::MADV_DOFORK, 201 /// `MADV_HWPOISON` 202 LinuxHwPoison = linux_raw_sys::general::MADV_HWPOISON, 203 /// `MADV_SOFT_OFFLINE` 204 #[cfg(not(any( 205 target_arch = "mips", 206 target_arch = "mips32r6", 207 target_arch = "mips64", 208 target_arch = "mips64r6" 209 )))] 210 LinuxSoftOffline = linux_raw_sys::general::MADV_SOFT_OFFLINE, 211 /// `MADV_MERGEABLE` 212 LinuxMergeable = linux_raw_sys::general::MADV_MERGEABLE, 213 /// `MADV_UNMERGEABLE` 214 LinuxUnmergeable = linux_raw_sys::general::MADV_UNMERGEABLE, 215 /// `MADV_HUGEPAGE` 216 LinuxHugepage = linux_raw_sys::general::MADV_HUGEPAGE, 217 /// `MADV_NOHUGEPAGE` 218 LinuxNoHugepage = linux_raw_sys::general::MADV_NOHUGEPAGE, 219 /// `MADV_DONTDUMP` (since Linux 3.4) 220 LinuxDontDump = linux_raw_sys::general::MADV_DONTDUMP, 221 /// `MADV_DODUMP` (since Linux 3.4) 222 LinuxDoDump = linux_raw_sys::general::MADV_DODUMP, 223 /// `MADV_WIPEONFORK` (since Linux 4.14) 224 LinuxWipeOnFork = linux_raw_sys::general::MADV_WIPEONFORK, 225 /// `MADV_KEEPONFORK` (since Linux 4.14) 226 LinuxKeepOnFork = linux_raw_sys::general::MADV_KEEPONFORK, 227 /// `MADV_COLD` (since Linux 5.4) 228 LinuxCold = linux_raw_sys::general::MADV_COLD, 229 /// `MADV_PAGEOUT` (since Linux 5.4) 230 LinuxPageOut = linux_raw_sys::general::MADV_PAGEOUT, 231 /// `MADV_POPULATE_READ` (since Linux 5.14) 232 LinuxPopulateRead = linux_raw_sys::general::MADV_POPULATE_READ, 233 /// `MADV_POPULATE_WRITE` (since Linux 5.14) 234 LinuxPopulateWrite = linux_raw_sys::general::MADV_POPULATE_WRITE, 235 /// `MADV_DONTNEED_LOCKED` (since Linux 5.18) 236 LinuxDontneedLocked = linux_raw_sys::general::MADV_DONTNEED_LOCKED, 237 } 238 239 #[allow(non_upper_case_globals)] 240 impl Advice { 241 /// `POSIX_MADV_DONTNEED` 242 /// 243 /// On Linux, this is mapped to `POSIX_MADV_NORMAL` because Linux's 244 /// `MADV_DONTNEED` differs from `POSIX_MADV_DONTNEED`. See `LinuxDontNeed` 245 /// for the Linux behavior. 246 pub const DontNeed: Self = Self::Normal; 247 } 248 249 bitflags! { 250 /// `O_*` flags for use with [`userfaultfd`]. 251 /// 252 /// [`userfaultfd`]: crate::mm::userfaultfd 253 #[repr(transparent)] 254 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 255 pub struct UserfaultfdFlags: c::c_uint { 256 /// `O_CLOEXEC` 257 const CLOEXEC = linux_raw_sys::general::O_CLOEXEC; 258 /// `O_NONBLOCK` 259 const NONBLOCK = linux_raw_sys::general::O_NONBLOCK; 260 261 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 262 const _ = !0; 263 } 264 } 265 266 bitflags! { 267 /// `MCL_*` flags for use with [`mlockall`]. 268 /// 269 /// [`mlockall`]: crate::mm::mlockall 270 #[repr(transparent)] 271 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] 272 pub struct MlockAllFlags: u32 { 273 /// Used together with `MCL_CURRENT`, `MCL_FUTURE`, or both. Mark all 274 /// current (with `MCL_CURRENT`) or future (with `MCL_FUTURE`) mappings 275 /// to lock pages when they are faulted in. When used with 276 /// `MCL_CURRENT`, all present pages are locked, but `mlockall` will 277 /// not fault in non-present pages. When used with `MCL_FUTURE`, all 278 /// future mappings will be marked to lock pages when they are faulted 279 /// in, but they will not be populated by the lock when the mapping is 280 /// created. `MCL_ONFAULT` must be used with either `MCL_CURRENT` or 281 /// `MCL_FUTURE` or both. 282 const ONFAULT = linux_raw_sys::general::MCL_ONFAULT; 283 /// Lock all pages which will become mapped into the address space of 284 /// the process in the future. These could be, for instance, new pages 285 /// required by a growing heap and stack as well as new memory-mapped 286 /// files or shared memory regions. 287 const FUTURE = linux_raw_sys::general::MCL_FUTURE; 288 /// Lock all pages which are currently mapped into the address space of 289 /// the process. 290 const CURRENT = linux_raw_sys::general::MCL_CURRENT; 291 292 /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> 293 const _ = !0; 294 } 295 } 296