1use crate::backend::c;
2use bitflags::bitflags;
3
4bitflags! {
5 #[repr(transparent)]
11 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
12 pub struct ProtFlags: u32 {
13 const READ = bitcast!(c::PROT_READ);
15 const WRITE = bitcast!(c::PROT_WRITE);
17 const EXEC = bitcast!(c::PROT_EXEC);
19
20 const _ = !0;
22 }
23}
24
25bitflags! {
26 #[repr(transparent)]
32 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
33 pub struct MprotectFlags: u32 {
34 const READ = bitcast!(c::PROT_READ);
36 const WRITE = bitcast!(c::PROT_WRITE);
38 const EXEC = bitcast!(c::PROT_EXEC);
40 #[cfg(linux_kernel)]
42 const GROWSUP = bitcast!(c::PROT_GROWSUP);
43 #[cfg(linux_kernel)]
45 const GROWSDOWN = bitcast!(c::PROT_GROWSDOWN);
46 #[cfg(linux_kernel)]
48 const SEM = linux_raw_sys::general::PROT_SEM;
49 #[cfg(all(linux_kernel, target_arch = "aarch64"))]
51 const BTI = linux_raw_sys::general::PROT_BTI;
52 #[cfg(all(linux_kernel, target_arch = "aarch64"))]
54 const MTE = linux_raw_sys::general::PROT_MTE;
55 #[cfg(all(linux_kernel, any(target_arch = "powerpc", target_arch = "powerpc64")))]
57 const SAO = linux_raw_sys::general::PROT_SAO;
58 #[cfg(all(linux_kernel, any(target_arch = "sparc", target_arch = "sparc64")))]
60 const ADI = linux_raw_sys::general::PROT_ADI;
61
62 const _ = !0;
64 }
65}
66
67bitflags! {
68 #[repr(transparent)]
75 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
76 pub struct MapFlags: u32 {
77 const SHARED = bitcast!(c::MAP_SHARED);
79 #[cfg(not(any(
81 bsd,
82 solarish,
83 target_os = "aix",
84 target_os = "android",
85 target_os = "cygwin",
86 target_os = "emscripten",
87 target_os = "fuchsia",
88 target_os = "haiku",
89 target_os = "hurd",
90 target_os = "nto",
91 target_os = "redox",
92 )))]
93 const SHARED_VALIDATE = bitcast!(c::MAP_SHARED_VALIDATE);
94 const PRIVATE = bitcast!(c::MAP_PRIVATE);
96 #[cfg(not(any(
98 bsd,
99 solarish,
100 target_os = "aix",
101 target_os = "cygwin",
102 target_os = "haiku",
103 target_os = "hurd",
104 target_os = "nto",
105 target_os = "redox",
106 )))]
107 const DENYWRITE = bitcast!(c::MAP_DENYWRITE);
108 const FIXED = bitcast!(c::MAP_FIXED);
110 #[cfg(not(any(
112 bsd,
113 solarish,
114 target_os = "aix",
115 target_os = "android",
116 target_os = "cygwin",
117 target_os = "emscripten",
118 target_os = "fuchsia",
119 target_os = "haiku",
120 target_os = "hurd",
121 target_os = "nto",
122 target_os = "redox",
123 )))]
124 const FIXED_NOREPLACE = bitcast!(c::MAP_FIXED_NOREPLACE);
125 #[cfg(not(any(
127 bsd,
128 solarish,
129 target_os = "aix",
130 target_os = "cygwin",
131 target_os = "haiku",
132 target_os = "hurd",
133 target_os = "nto",
134 target_os = "redox",
135 )))]
136 const GROWSDOWN = bitcast!(c::MAP_GROWSDOWN);
137 #[cfg(not(any(
139 bsd,
140 solarish,
141 target_os = "aix",
142 target_os = "cygwin",
143 target_os = "haiku",
144 target_os = "hurd",
145 target_os = "nto",
146 target_os = "redox",
147 )))]
148 const HUGETLB = bitcast!(c::MAP_HUGETLB);
149 #[cfg(not(any(
151 bsd,
152 solarish,
153 target_os = "aix",
154 target_os = "android",
155 target_os = "cygwin",
156 target_os = "emscripten",
157 target_os = "fuchsia",
158 target_os = "haiku",
159 target_os = "hurd",
160 target_os = "nto",
161 target_os = "redox",
162 )))]
163 const HUGE_2MB = bitcast!(c::MAP_HUGE_2MB);
164 #[cfg(not(any(
166 bsd,
167 solarish,
168 target_os = "aix",
169 target_os = "android",
170 target_os = "cygwin",
171 target_os = "emscripten",
172 target_os = "fuchsia",
173 target_os = "haiku",
174 target_os = "hurd",
175 target_os = "nto",
176 target_os = "redox",
177 )))]
178 const HUGE_1GB = bitcast!(c::MAP_HUGE_1GB);
179 #[cfg(not(any(
181 bsd,
182 solarish,
183 target_os = "aix",
184 target_os = "cygwin",
185 target_os = "haiku",
186 target_os = "hurd",
187 target_os = "nto",
188 target_os = "redox",
189 )))]
190 const LOCKED = bitcast!(c::MAP_LOCKED);
191 #[cfg(freebsdlike)]
193 const NOCORE = bitcast!(c::MAP_NOCORE);
194 #[cfg(not(any(
196 freebsdlike,
197 target_os = "aix",
198 target_os = "hurd",
199 target_os = "nto",
200 target_os = "redox",
201 )))]
202 const NORESERVE = bitcast!(c::MAP_NORESERVE);
203 #[cfg(freebsdlike)]
205 const NOSYNC = bitcast!(c::MAP_NOSYNC);
206 #[cfg(not(any(
208 bsd,
209 solarish,
210 target_os = "aix",
211 target_os = "cygwin",
212 target_os = "haiku",
213 target_os = "hurd",
214 target_os = "nto",
215 target_os = "redox",
216 )))]
217 const POPULATE = bitcast!(c::MAP_POPULATE);
218 #[cfg(not(any(
220 apple,
221 solarish,
222 target_os = "aix",
223 target_os = "cygwin",
224 target_os = "haiku",
225 target_os = "hurd",
226 target_os = "redox",
227 )))]
228 const STACK = bitcast!(c::MAP_STACK);
229 #[cfg(target_os = "freebsd")]
231 const PREFAULT_READ = bitcast!(c::MAP_PREFAULT_READ);
232 #[cfg(not(any(
234 bsd,
235 solarish,
236 target_os = "aix",
237 target_os = "android",
238 target_os = "cygwin",
239 target_os = "emscripten",
240 target_os = "fuchsia",
241 target_os = "haiku",
242 target_os = "hurd",
243 target_os = "nto",
244 target_os = "redox",
245 all(
246 linux_kernel,
247 any(target_arch = "mips", target_arch = "mips32r6", target_arch = "mips64", target_arch = "mips64r6"),
248 ),
249 )))]
250 const SYNC = bitcast!(c::MAP_SYNC);
251 #[cfg(any())]
253 const UNINITIALIZED = bitcast!(c::MAP_UNINITIALIZED);
254 #[cfg(linux_kernel)]
256 const DROPPABLE = bitcast!(c::MAP_DROPPABLE);
257
258 const _ = !0;
260 }
261}
262
263#[cfg(any(target_os = "emscripten", target_os = "linux"))]
264bitflags! {
265 #[repr(transparent)]
272 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
273 pub struct MremapFlags: u32 {
274 const MAYMOVE = bitcast!(c::MREMAP_MAYMOVE);
276
277 const _ = !0;
279 }
280}
281
282bitflags! {
283 #[repr(transparent)]
287 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
288 pub struct MsyncFlags: u32 {
289 const SYNC = bitcast!(c::MS_SYNC);
291 const ASYNC = bitcast!(c::MS_ASYNC);
294 const INVALIDATE = bitcast!(c::MS_INVALIDATE);
298
299 const _ = !0;
301 }
302}
303
304#[cfg(linux_kernel)]
305bitflags! {
306 #[repr(transparent)]
310 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
311 pub struct MlockFlags: u32 {
312 const ONFAULT = bitcast!(c::MLOCK_ONFAULT);
314
315 const _ = !0;
317 }
318}
319
320#[cfg(not(target_os = "redox"))]
324#[derive(Debug, Copy, Clone, Eq, PartialEq)]
325#[repr(u32)]
326#[non_exhaustive]
327pub enum Advice {
328 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
330 Normal = bitcast!(c::POSIX_MADV_NORMAL),
331
332 #[cfg(any(target_os = "android", target_os = "haiku"))]
334 Normal = bitcast!(c::MADV_NORMAL),
335
336 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
338 Sequential = bitcast!(c::POSIX_MADV_SEQUENTIAL),
339
340 #[cfg(any(target_os = "android", target_os = "haiku"))]
342 Sequential = bitcast!(c::MADV_SEQUENTIAL),
343
344 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
346 Random = bitcast!(c::POSIX_MADV_RANDOM),
347
348 #[cfg(any(target_os = "android", target_os = "haiku"))]
350 Random = bitcast!(c::MADV_RANDOM),
351
352 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
354 WillNeed = bitcast!(c::POSIX_MADV_WILLNEED),
355
356 #[cfg(any(target_os = "android", target_os = "haiku"))]
358 WillNeed = bitcast!(c::MADV_WILLNEED),
359
360 #[cfg(not(any(
362 target_os = "android",
363 target_os = "emscripten",
364 target_os = "haiku",
365 target_os = "hurd",
366 )))]
367 DontNeed = bitcast!(c::POSIX_MADV_DONTNEED),
368
369 #[cfg(any(target_os = "android", target_os = "haiku"))]
371 DontNeed = bitcast!(i32::MAX - 1),
372
373 #[cfg(target_os = "linux")]
378 LinuxDontNeed = bitcast!(i32::MAX),
379
380 #[cfg(target_os = "android")]
382 LinuxDontNeed = bitcast!(c::MADV_DONTNEED),
383 #[cfg(linux_kernel)]
385 LinuxFree = bitcast!(c::MADV_FREE),
386 #[cfg(linux_kernel)]
388 LinuxRemove = bitcast!(c::MADV_REMOVE),
389 #[cfg(linux_kernel)]
391 LinuxDontFork = bitcast!(c::MADV_DONTFORK),
392 #[cfg(linux_kernel)]
394 LinuxDoFork = bitcast!(c::MADV_DOFORK),
395 #[cfg(linux_kernel)]
397 LinuxHwPoison = bitcast!(c::MADV_HWPOISON),
398 #[cfg(all(
400 linux_kernel,
401 not(any(
402 target_arch = "mips",
403 target_arch = "mips32r6",
404 target_arch = "mips64",
405 target_arch = "mips64r6"
406 ))
407 ))]
408 LinuxSoftOffline = bitcast!(c::MADV_SOFT_OFFLINE),
409 #[cfg(linux_kernel)]
411 LinuxMergeable = bitcast!(c::MADV_MERGEABLE),
412 #[cfg(linux_kernel)]
414 LinuxUnmergeable = bitcast!(c::MADV_UNMERGEABLE),
415 #[cfg(linux_kernel)]
417 LinuxHugepage = bitcast!(c::MADV_HUGEPAGE),
418 #[cfg(linux_kernel)]
420 LinuxNoHugepage = bitcast!(c::MADV_NOHUGEPAGE),
421 #[cfg(linux_kernel)]
423 LinuxDontDump = bitcast!(c::MADV_DONTDUMP),
424 #[cfg(linux_kernel)]
426 LinuxDoDump = bitcast!(c::MADV_DODUMP),
427 #[cfg(linux_kernel)]
429 LinuxWipeOnFork = bitcast!(c::MADV_WIPEONFORK),
430 #[cfg(linux_kernel)]
432 LinuxKeepOnFork = bitcast!(c::MADV_KEEPONFORK),
433 #[cfg(linux_kernel)]
435 LinuxCold = bitcast!(c::MADV_COLD),
436 #[cfg(linux_kernel)]
438 LinuxPageOut = bitcast!(c::MADV_PAGEOUT),
439 #[cfg(linux_kernel)]
441 LinuxPopulateRead = bitcast!(c::MADV_POPULATE_READ),
442 #[cfg(linux_kernel)]
444 LinuxPopulateWrite = bitcast!(c::MADV_POPULATE_WRITE),
445 #[cfg(linux_kernel)]
447 LinuxDontneedLocked = bitcast!(c::MADV_DONTNEED_LOCKED),
448}
449
450#[cfg(target_os = "emscripten")]
451#[allow(non_upper_case_globals)]
452impl Advice {
453 pub const DontNeed: Self = Self::Normal;
455}
456
457#[cfg(linux_kernel)]
458bitflags! {
459 #[repr(transparent)]
463 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
464 pub struct UserfaultfdFlags: u32 {
465 const CLOEXEC = bitcast!(c::O_CLOEXEC);
467 const NONBLOCK = bitcast!(c::O_NONBLOCK);
469
470 const _ = !0;
472 }
473}
474
475#[cfg(any(linux_kernel, freebsdlike, netbsdlike))]
476bitflags! {
477 #[repr(transparent)]
481 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
482 pub struct MlockAllFlags: u32 {
483 #[cfg(linux_kernel)]
493 const ONFAULT = bitcast!(c::MCL_ONFAULT);
494 const FUTURE = bitcast!(c::MCL_FUTURE);
499 const CURRENT = bitcast!(c::MCL_CURRENT);
502
503 const _ = !0;
505 }
506}