| 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 | /// `MAP_DROPPABLE` |
| 109 | const DROPPABLE = c::MAP_DROPPABLE; |
| 110 | |
| 111 | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
| 112 | const _ = !0; |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | bitflags! { |
| 117 | /// `MREMAP_*` flags for use with [`mremap`]. |
| 118 | /// |
| 119 | /// For `MREMAP_FIXED`, see [`mremap_fixed`]. |
| 120 | /// |
| 121 | /// [`mremap`]: crate::mm::mremap |
| 122 | /// [`mremap_fixed`]: crate::mm::mremap_fixed |
| 123 | #[repr (transparent)] |
| 124 | #[derive (Copy, Clone, Eq, PartialEq, Hash, Debug)] |
| 125 | pub struct MremapFlags: u32 { |
| 126 | /// `MREMAP_MAYMOVE` |
| 127 | const MAYMOVE = linux_raw_sys::general::MREMAP_MAYMOVE; |
| 128 | /// `MREMAP_DONTUNMAP` (since Linux 5.7) |
| 129 | const DONTUNMAP = linux_raw_sys::general::MREMAP_DONTUNMAP; |
| 130 | |
| 131 | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
| 132 | const _ = !0; |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | bitflags! { |
| 137 | /// `MS_*` flags for use with [`msync`]. |
| 138 | /// |
| 139 | /// [`msync`]: crate::mm::msync |
| 140 | #[repr (transparent)] |
| 141 | #[derive (Copy, Clone, Eq, PartialEq, Hash, Debug)] |
| 142 | pub struct MsyncFlags: u32 { |
| 143 | /// `MS_SYNC`—Requests an update and waits for it to complete. |
| 144 | const SYNC = linux_raw_sys::general::MS_SYNC; |
| 145 | /// `MS_ASYNC`—Specifies that an update be scheduled, but the call |
| 146 | /// returns immediately. |
| 147 | const ASYNC = linux_raw_sys::general::MS_ASYNC; |
| 148 | /// `MS_INVALIDATE`—Asks to invalidate other mappings of the same |
| 149 | /// file (so that they can be updated with the fresh values just |
| 150 | /// written). |
| 151 | const INVALIDATE = linux_raw_sys::general::MS_INVALIDATE; |
| 152 | |
| 153 | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
| 154 | const _ = !0; |
| 155 | } |
| 156 | } |
| 157 | |
| 158 | bitflags! { |
| 159 | /// `MLOCK_*` flags for use with [`mlock_with`]. |
| 160 | /// |
| 161 | /// [`mlock_with`]: crate::mm::mlock_with |
| 162 | #[repr (transparent)] |
| 163 | #[derive (Copy, Clone, Eq, PartialEq, Hash, Debug)] |
| 164 | pub struct MlockFlags: u32 { |
| 165 | /// `MLOCK_ONFAULT` |
| 166 | const ONFAULT = linux_raw_sys::general::MLOCK_ONFAULT; |
| 167 | |
| 168 | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
| 169 | const _ = !0; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | /// `POSIX_MADV_*` constants for use with [`madvise`]. |
| 174 | /// |
| 175 | /// [`madvise`]: crate::mm::madvise |
| 176 | #[derive (Debug, Copy, Clone, Eq, PartialEq)] |
| 177 | #[repr (u32)] |
| 178 | #[non_exhaustive ] |
| 179 | pub enum Advice { |
| 180 | /// `POSIX_MADV_NORMAL` |
| 181 | Normal = linux_raw_sys::general::MADV_NORMAL, |
| 182 | |
| 183 | /// `POSIX_MADV_SEQUENTIAL` |
| 184 | Sequential = linux_raw_sys::general::MADV_SEQUENTIAL, |
| 185 | |
| 186 | /// `POSIX_MADV_RANDOM` |
| 187 | Random = linux_raw_sys::general::MADV_RANDOM, |
| 188 | |
| 189 | /// `POSIX_MADV_WILLNEED` |
| 190 | WillNeed = linux_raw_sys::general::MADV_WILLNEED, |
| 191 | |
| 192 | /// `MADV_DONTNEED` |
| 193 | LinuxDontNeed = linux_raw_sys::general::MADV_DONTNEED, |
| 194 | |
| 195 | /// `MADV_FREE` (since Linux 4.5) |
| 196 | LinuxFree = linux_raw_sys::general::MADV_FREE, |
| 197 | /// `MADV_REMOVE` |
| 198 | LinuxRemove = linux_raw_sys::general::MADV_REMOVE, |
| 199 | /// `MADV_DONTFORK` |
| 200 | LinuxDontFork = linux_raw_sys::general::MADV_DONTFORK, |
| 201 | /// `MADV_DOFORK` |
| 202 | LinuxDoFork = linux_raw_sys::general::MADV_DOFORK, |
| 203 | /// `MADV_HWPOISON` |
| 204 | LinuxHwPoison = linux_raw_sys::general::MADV_HWPOISON, |
| 205 | /// `MADV_SOFT_OFFLINE` |
| 206 | #[cfg (not(any( |
| 207 | target_arch = "mips" , |
| 208 | target_arch = "mips32r6" , |
| 209 | target_arch = "mips64" , |
| 210 | target_arch = "mips64r6" |
| 211 | )))] |
| 212 | LinuxSoftOffline = linux_raw_sys::general::MADV_SOFT_OFFLINE, |
| 213 | /// `MADV_MERGEABLE` |
| 214 | LinuxMergeable = linux_raw_sys::general::MADV_MERGEABLE, |
| 215 | /// `MADV_UNMERGEABLE` |
| 216 | LinuxUnmergeable = linux_raw_sys::general::MADV_UNMERGEABLE, |
| 217 | /// `MADV_HUGEPAGE` |
| 218 | LinuxHugepage = linux_raw_sys::general::MADV_HUGEPAGE, |
| 219 | /// `MADV_NOHUGEPAGE` |
| 220 | LinuxNoHugepage = linux_raw_sys::general::MADV_NOHUGEPAGE, |
| 221 | /// `MADV_DONTDUMP` (since Linux 3.4) |
| 222 | LinuxDontDump = linux_raw_sys::general::MADV_DONTDUMP, |
| 223 | /// `MADV_DODUMP` (since Linux 3.4) |
| 224 | LinuxDoDump = linux_raw_sys::general::MADV_DODUMP, |
| 225 | /// `MADV_WIPEONFORK` (since Linux 4.14) |
| 226 | LinuxWipeOnFork = linux_raw_sys::general::MADV_WIPEONFORK, |
| 227 | /// `MADV_KEEPONFORK` (since Linux 4.14) |
| 228 | LinuxKeepOnFork = linux_raw_sys::general::MADV_KEEPONFORK, |
| 229 | /// `MADV_COLD` (since Linux 5.4) |
| 230 | LinuxCold = linux_raw_sys::general::MADV_COLD, |
| 231 | /// `MADV_PAGEOUT` (since Linux 5.4) |
| 232 | LinuxPageOut = linux_raw_sys::general::MADV_PAGEOUT, |
| 233 | /// `MADV_POPULATE_READ` (since Linux 5.14) |
| 234 | LinuxPopulateRead = linux_raw_sys::general::MADV_POPULATE_READ, |
| 235 | /// `MADV_POPULATE_WRITE` (since Linux 5.14) |
| 236 | LinuxPopulateWrite = linux_raw_sys::general::MADV_POPULATE_WRITE, |
| 237 | /// `MADV_DONTNEED_LOCKED` (since Linux 5.18) |
| 238 | LinuxDontneedLocked = linux_raw_sys::general::MADV_DONTNEED_LOCKED, |
| 239 | } |
| 240 | |
| 241 | #[allow (non_upper_case_globals)] |
| 242 | impl Advice { |
| 243 | /// `POSIX_MADV_DONTNEED` |
| 244 | /// |
| 245 | /// On Linux, this is mapped to `POSIX_MADV_NORMAL` because Linux's |
| 246 | /// `MADV_DONTNEED` differs from `POSIX_MADV_DONTNEED`. See `LinuxDontNeed` |
| 247 | /// for the Linux behavior. |
| 248 | pub const DontNeed: Self = Self::Normal; |
| 249 | } |
| 250 | |
| 251 | bitflags! { |
| 252 | /// `O_*` flags for use with [`userfaultfd`]. |
| 253 | /// |
| 254 | /// [`userfaultfd`]: crate::mm::userfaultfd |
| 255 | #[repr (transparent)] |
| 256 | #[derive (Copy, Clone, Eq, PartialEq, Hash, Debug)] |
| 257 | pub struct UserfaultfdFlags: c::c_uint { |
| 258 | /// `O_CLOEXEC` |
| 259 | const CLOEXEC = linux_raw_sys::general::O_CLOEXEC; |
| 260 | /// `O_NONBLOCK` |
| 261 | const NONBLOCK = linux_raw_sys::general::O_NONBLOCK; |
| 262 | |
| 263 | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
| 264 | const _ = !0; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | bitflags! { |
| 269 | /// `MCL_*` flags for use with [`mlockall`]. |
| 270 | /// |
| 271 | /// [`mlockall`]: crate::mm::mlockall |
| 272 | #[repr (transparent)] |
| 273 | #[derive (Copy, Clone, Eq, PartialEq, Hash, Debug)] |
| 274 | pub struct MlockAllFlags: u32 { |
| 275 | /// Used together with `MCL_CURRENT`, `MCL_FUTURE`, or both. Mark all |
| 276 | /// current (with `MCL_CURRENT`) or future (with `MCL_FUTURE`) mappings |
| 277 | /// to lock pages when they are faulted in. When used with |
| 278 | /// `MCL_CURRENT`, all present pages are locked, but `mlockall` will |
| 279 | /// not fault in non-present pages. When used with `MCL_FUTURE`, all |
| 280 | /// future mappings will be marked to lock pages when they are faulted |
| 281 | /// in, but they will not be populated by the lock when the mapping is |
| 282 | /// created. `MCL_ONFAULT` must be used with either `MCL_CURRENT` or |
| 283 | /// `MCL_FUTURE` or both. |
| 284 | const ONFAULT = linux_raw_sys::general::MCL_ONFAULT; |
| 285 | /// Lock all pages which will become mapped into the address space of |
| 286 | /// the process in the future. These could be, for instance, new pages |
| 287 | /// required by a growing heap and stack as well as new memory-mapped |
| 288 | /// files or shared memory regions. |
| 289 | const FUTURE = linux_raw_sys::general::MCL_FUTURE; |
| 290 | /// Lock all pages which are currently mapped into the address space of |
| 291 | /// the process. |
| 292 | const CURRENT = linux_raw_sys::general::MCL_CURRENT; |
| 293 | |
| 294 | /// <https://docs.rs/bitflags/*/bitflags/#externally-defined-flags> |
| 295 | const _ = !0; |
| 296 | } |
| 297 | } |
| 298 | |