]> git.proxmox.com Git - rustc.git/blob - vendor/rustix-0.36.5/src/backend/libc/mm/types.rs
New upstream version 1.70.0+dfsg1
[rustc.git] / vendor / rustix-0.36.5 / src / backend / libc / mm / types.rs
1 use super::super::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::io::mmap
10 pub struct ProtFlags: c::c_int {
11 /// `PROT_READ`
12 const READ = c::PROT_READ;
13 /// `PROT_WRITE`
14 const WRITE = c::PROT_WRITE;
15 /// `PROT_EXEC`
16 const EXEC = c::PROT_EXEC;
17 }
18 }
19
20 bitflags! {
21 /// `PROT_*` flags for use with [`mprotect`].
22 ///
23 /// For `PROT_NONE`, use `MprotectFlags::empty()`.
24 ///
25 /// [`mprotect`]: crate::io::mprotect
26 pub struct MprotectFlags: c::c_int {
27 /// `PROT_READ`
28 const READ = c::PROT_READ;
29 /// `PROT_WRITE`
30 const WRITE = c::PROT_WRITE;
31 /// `PROT_EXEC`
32 const EXEC = c::PROT_EXEC;
33 /// `PROT_GROWSUP`
34 #[cfg(any(target_os = "android", target_os = "linux"))]
35 const GROWSUP = c::PROT_GROWSUP;
36 /// `PROT_GROWSDOWN`
37 #[cfg(any(target_os = "android", target_os = "linux"))]
38 const GROWSDOWN = c::PROT_GROWSDOWN;
39 }
40 }
41
42 bitflags! {
43 /// `MAP_*` flags for use with [`mmap`].
44 ///
45 /// For `MAP_ANONYMOUS` (aka `MAP_ANON`), see [`mmap_anonymous`].
46 ///
47 /// [`mmap`]: crate::io::mmap
48 /// [`mmap_anonymous`]: crates::io::mmap_anonymous
49 pub struct MapFlags: c::c_int {
50 /// `MAP_SHARED`
51 const SHARED = c::MAP_SHARED;
52 /// `MAP_SHARED_VALIDATE`
53 #[cfg(not(any(
54 target_os = "android",
55 target_os = "dragonfly",
56 target_os = "emscripten",
57 target_os = "freebsd",
58 target_os = "fuchsia",
59 target_os = "haiku",
60 target_os = "illumos",
61 target_os = "ios",
62 target_os = "macos",
63 target_os = "netbsd",
64 target_os = "openbsd",
65 target_os = "redox",
66 target_os = "solaris",
67 )))]
68 const SHARED_VALIDATE = c::MAP_SHARED_VALIDATE;
69 /// `MAP_PRIVATE`
70 const PRIVATE = c::MAP_PRIVATE;
71 /// `MAP_DENYWRITE`
72 #[cfg(not(any(
73 target_os = "dragonfly",
74 target_os = "freebsd",
75 target_os = "haiku",
76 target_os = "illumos",
77 target_os = "ios",
78 target_os = "macos",
79 target_os = "netbsd",
80 target_os = "openbsd",
81 target_os = "redox",
82 target_os = "solaris",
83 )))]
84 const DENYWRITE = c::MAP_DENYWRITE;
85 /// `MAP_FIXED`
86 const FIXED = c::MAP_FIXED;
87 /// `MAP_FIXED_NOREPLACE`
88 #[cfg(not(any(
89 target_os = "android",
90 target_os = "dragonfly",
91 target_os = "emscripten",
92 target_os = "freebsd",
93 target_os = "fuchsia",
94 target_os = "haiku",
95 target_os = "illumos",
96 target_os = "ios",
97 target_os = "macos",
98 target_os = "netbsd",
99 target_os = "openbsd",
100 target_os = "redox",
101 target_os = "solaris",
102 )))]
103 const FIXED_NOREPLACE = c::MAP_FIXED_NOREPLACE;
104 /// `MAP_GROWSDOWN`
105 #[cfg(not(any(
106 target_os = "dragonfly",
107 target_os = "freebsd",
108 target_os = "haiku",
109 target_os = "illumos",
110 target_os = "ios",
111 target_os = "macos",
112 target_os = "netbsd",
113 target_os = "openbsd",
114 target_os = "redox",
115 target_os = "solaris",
116 )))]
117 const GROWSDOWN = c::MAP_GROWSDOWN;
118 /// `MAP_HUGETLB`
119 #[cfg(not(any(
120 target_os = "dragonfly",
121 target_os = "freebsd",
122 target_os = "haiku",
123 target_os = "illumos",
124 target_os = "ios",
125 target_os = "macos",
126 target_os = "netbsd",
127 target_os = "openbsd",
128 target_os = "redox",
129 target_os = "solaris",
130 )))]
131 const HUGETLB = c::MAP_HUGETLB;
132 /// `MAP_HUGE_2MB`
133 #[cfg(not(any(
134 target_os = "android",
135 target_os = "dragonfly",
136 target_os = "emscripten",
137 target_os = "freebsd",
138 target_os = "fuchsia",
139 target_os = "haiku",
140 target_os = "illumos",
141 target_os = "ios",
142 target_os = "macos",
143 target_os = "netbsd",
144 target_os = "openbsd",
145 target_os = "redox",
146 target_os = "solaris",
147 )))]
148 const HUGE_2MB = c::MAP_HUGE_2MB;
149 /// `MAP_HUGE_1GB`
150 #[cfg(not(any(
151 target_os = "android",
152 target_os = "dragonfly",
153 target_os = "emscripten",
154 target_os = "freebsd",
155 target_os = "fuchsia",
156 target_os = "haiku",
157 target_os = "illumos",
158 target_os = "ios",
159 target_os = "macos",
160 target_os = "netbsd",
161 target_os = "openbsd",
162 target_os = "redox",
163 target_os = "solaris",
164 )))]
165 const HUGE_1GB = c::MAP_HUGE_1GB;
166 /// `MAP_LOCKED`
167 #[cfg(not(any(
168 target_os = "dragonfly",
169 target_os = "freebsd",
170 target_os = "haiku",
171 target_os = "illumos",
172 target_os = "ios",
173 target_os = "macos",
174 target_os = "netbsd",
175 target_os = "openbsd",
176 target_os = "redox",
177 target_os = "solaris",
178 )))]
179 const LOCKED = c::MAP_LOCKED;
180 /// `MAP_NOCORE`
181 #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
182 const NOCORE = c::MAP_NOCORE;
183 /// `MAP_NORESERVE`
184 #[cfg(not(any(target_os = "dragonfly", target_os = "freebsd", target_os = "redox")))]
185 const NORESERVE = c::MAP_NORESERVE;
186 /// `MAP_NOSYNC`
187 #[cfg(any(target_os = "dragonfly", target_os = "freebsd"))]
188 const NOSYNC = c::MAP_NOSYNC;
189 /// `MAP_POPULATE`
190 #[cfg(not(any(
191 target_os = "dragonfly",
192 target_os = "freebsd",
193 target_os = "haiku",
194 target_os = "illumos",
195 target_os = "ios",
196 target_os = "macos",
197 target_os = "netbsd",
198 target_os = "openbsd",
199 target_os = "redox",
200 target_os = "solaris",
201 )))]
202 const POPULATE = c::MAP_POPULATE;
203 /// `MAP_STACK`
204 #[cfg(not(any(
205 target_os = "dragonfly",
206 target_os = "haiku",
207 target_os = "illumos",
208 target_os = "ios",
209 target_os = "macos",
210 target_os = "netbsd",
211 target_os = "redox",
212 target_os = "solaris",
213 )))]
214 const STACK = c::MAP_STACK;
215 /// `MAP_PREFAULT_READ`
216 #[cfg(target_os = "freebsd")]
217 const PREFAULT_READ = c::MAP_PREFAULT_READ;
218 /// `MAP_SYNC`
219 #[cfg(not(any(
220 target_os = "android",
221 target_os = "dragonfly",
222 target_os = "emscripten",
223 target_os = "freebsd",
224 target_os = "fuchsia",
225 target_os = "haiku",
226 target_os = "illumos",
227 target_os = "ios",
228 target_os = "macos",
229 target_os = "netbsd",
230 target_os = "openbsd",
231 target_os = "redox",
232 target_os = "solaris",
233 all(
234 any(target_os = "android", target_os = "linux"),
235 any(target_arch = "mips", target_arch = "mips64"),
236 )
237 )))]
238 const SYNC = c::MAP_SYNC;
239 /// `MAP_UNINITIALIZED`
240 #[cfg(any())]
241 const UNINITIALIZED = c::MAP_UNINITIALIZED;
242 }
243 }
244
245 #[cfg(target_os = "linux")]
246 bitflags! {
247 /// `MREMAP_*` flags for use with [`mremap`].
248 ///
249 /// For `MREMAP_FIXED`, see [`mremap_fixed`].
250 ///
251 /// [`mremap`]: crate::io::mremap
252 /// [`mremap_fixed`]: crate::io::mremap_fixed
253 pub struct MremapFlags: i32 {
254 /// `MREMAP_MAYMOVE`
255 const MAYMOVE = c::MREMAP_MAYMOVE;
256 }
257 }
258
259 bitflags! {
260 /// `MS_*` flags for use with [`msync`].
261 ///
262 /// [`msync`]: crate::io::msync
263 pub struct MsyncFlags: i32 {
264 /// `MS_SYNC`—Requests an update and waits for it to complete.
265 const SYNC = c::MS_SYNC;
266 /// `MS_ASYNC`—Specifies that an update be scheduled, but the call
267 /// returns immediately.
268 const ASYNC = c::MS_ASYNC;
269 /// `MS_INVALIDATE`—Asks to invalidate other mappings of the same
270 /// file (so that they can be updated with the fresh values just
271 /// written).
272 const INVALIDATE = c::MS_INVALIDATE;
273 }
274 }
275
276 #[cfg(any(target_os = "android", target_os = "linux"))]
277 bitflags! {
278 /// `MLOCK_*` flags for use with [`mlock_with`].
279 ///
280 /// [`mlock_with`]: crate::io::mlock_with
281 pub struct MlockFlags: i32 {
282 /// `MLOCK_ONFAULT`
283 const ONFAULT = c::MLOCK_ONFAULT as _;
284 }
285 }
286
287 /// `POSIX_MADV_*` constants for use with [`madvise`].
288 ///
289 /// [`madvise`]: crate::mm::madvise
290 #[cfg(not(target_os = "redox"))]
291 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
292 #[repr(i32)]
293 #[non_exhaustive]
294 pub enum Advice {
295 /// `POSIX_MADV_NORMAL`
296 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
297 Normal = c::POSIX_MADV_NORMAL,
298
299 /// `POSIX_MADV_NORMAL`
300 #[cfg(any(target_os = "android", target_os = "haiku"))]
301 Normal = c::MADV_NORMAL,
302
303 /// `POSIX_MADV_SEQUENTIAL`
304 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
305 Sequential = c::POSIX_MADV_SEQUENTIAL,
306
307 /// `POSIX_MADV_SEQUENTIAL`
308 #[cfg(any(target_os = "android", target_os = "haiku"))]
309 Sequential = c::MADV_SEQUENTIAL,
310
311 /// `POSIX_MADV_RANDOM`
312 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
313 Random = c::POSIX_MADV_RANDOM,
314
315 /// `POSIX_MADV_RANDOM`
316 #[cfg(any(target_os = "android", target_os = "haiku"))]
317 Random = c::MADV_RANDOM,
318
319 /// `POSIX_MADV_WILLNEED`
320 #[cfg(not(any(target_os = "android", target_os = "haiku")))]
321 WillNeed = c::POSIX_MADV_WILLNEED,
322
323 /// `POSIX_MADV_WILLNEED`
324 #[cfg(any(target_os = "android", target_os = "haiku"))]
325 WillNeed = c::MADV_WILLNEED,
326
327 /// `POSIX_MADV_DONTNEED`
328 #[cfg(not(any(target_os = "android", target_os = "emscripten", target_os = "haiku")))]
329 DontNeed = c::POSIX_MADV_DONTNEED,
330
331 /// `POSIX_MADV_DONTNEED`
332 #[cfg(any(target_os = "android", target_os = "haiku"))]
333 DontNeed = i32::MAX - 1,
334
335 /// `MADV_DONTNEED`
336 // `MADV_DONTNEED` has the same value as `POSIX_MADV_DONTNEED`. We don't
337 // have a separate `posix_madvise` from `madvise`, so we expose a special
338 // value which we special-case.
339 #[cfg(target_os = "linux")]
340 LinuxDontNeed = i32::MAX,
341
342 /// `MADV_DONTNEED`
343 #[cfg(target_os = "android")]
344 LinuxDontNeed = c::MADV_DONTNEED,
345 /// `MADV_FREE`
346 #[cfg(any(target_os = "android", target_os = "linux"))]
347 LinuxFree = c::MADV_FREE,
348 /// `MADV_REMOVE`
349 #[cfg(any(target_os = "android", target_os = "linux"))]
350 LinuxRemove = c::MADV_REMOVE,
351 /// `MADV_DONTFORK`
352 #[cfg(any(target_os = "android", target_os = "linux"))]
353 LinuxDontFork = c::MADV_DONTFORK,
354 /// `MADV_DOFORK`
355 #[cfg(any(target_os = "android", target_os = "linux"))]
356 LinuxDoFork = c::MADV_DOFORK,
357 /// `MADV_HWPOISON`
358 #[cfg(any(target_os = "android", target_os = "linux"))]
359 LinuxHwPoison = c::MADV_HWPOISON,
360 /// `MADV_SOFT_OFFLINE`
361 #[cfg(all(
362 any(target_os = "android", target_os = "linux"),
363 not(any(target_arch = "mips", target_arch = "mips64")),
364 ))]
365 LinuxSoftOffline = c::MADV_SOFT_OFFLINE,
366 /// `MADV_MERGEABLE`
367 #[cfg(any(target_os = "android", target_os = "linux"))]
368 LinuxMergeable = c::MADV_MERGEABLE,
369 /// `MADV_UNMERGEABLE`
370 #[cfg(any(target_os = "android", target_os = "linux"))]
371 LinuxUnmergeable = c::MADV_UNMERGEABLE,
372 /// `MADV_HUGEPAGE` (since Linux 2.6.38)
373 #[cfg(any(target_os = "android", target_os = "linux"))]
374 LinuxHugepage = c::MADV_HUGEPAGE,
375 /// `MADV_NOHUGEPAGE` (since Linux 2.6.38)
376 #[cfg(any(target_os = "android", target_os = "linux"))]
377 LinuxNoHugepage = c::MADV_NOHUGEPAGE,
378 /// `MADV_DONTDUMP` (since Linux 3.4)
379 #[cfg(any(target_os = "android", target_os = "linux"))]
380 LinuxDontDump = c::MADV_DONTDUMP,
381 /// `MADV_DODUMP` (since Linux 3.4)
382 #[cfg(any(target_os = "android", target_os = "linux"))]
383 LinuxDoDump = c::MADV_DODUMP,
384 /// `MADV_WIPEONFORK` (since Linux 4.14)
385 #[cfg(any(target_os = "android", target_os = "linux"))]
386 #[cfg(feature = "mm")]
387 LinuxWipeOnFork = linux_raw_sys::general::MADV_WIPEONFORK as i32,
388 /// `MADV_KEEPONFORK` (since Linux 4.14)
389 #[cfg(any(target_os = "android", target_os = "linux"))]
390 #[cfg(feature = "mm")]
391 LinuxKeepOnFork = linux_raw_sys::general::MADV_KEEPONFORK as i32,
392 /// `MADV_COLD` (since Linux 5.4)
393 #[cfg(any(target_os = "android", target_os = "linux"))]
394 #[cfg(feature = "mm")]
395 LinuxCold = linux_raw_sys::general::MADV_COLD as i32,
396 /// `MADV_PAGEOUT` (since Linux 5.4)
397 #[cfg(any(target_os = "android", target_os = "linux"))]
398 #[cfg(feature = "mm")]
399 LinuxPageOut = linux_raw_sys::general::MADV_PAGEOUT as i32,
400 /// `MADV_POPULATE_READ` (since Linux 5.14)
401 #[cfg(any(target_os = "android", target_os = "linux"))]
402 #[cfg(feature = "mm")]
403 LinuxPopulateRead = linux_raw_sys::general::MADV_POPULATE_READ as i32,
404 /// `MADV_POPULATE_WRITE` (since Linux 5.14)
405 #[cfg(any(target_os = "android", target_os = "linux"))]
406 #[cfg(feature = "mm")]
407 LinuxPopulateWrite = linux_raw_sys::general::MADV_POPULATE_WRITE as i32,
408 }
409
410 #[cfg(target_os = "emscripten")]
411 impl Advice {
412 /// `POSIX_MADV_DONTNEED`
413 #[allow(non_upper_case_globals)]
414 pub const DontNeed: Self = Self::Normal;
415 }
416
417 #[cfg(any(target_os = "android", target_os = "linux"))]
418 bitflags! {
419 /// `O_*` flags for use with [`userfaultfd`].
420 ///
421 /// [`userfaultfd`]: crate::io::userfaultfd
422 pub struct UserfaultfdFlags: c::c_int {
423 /// `O_CLOEXEC`
424 const CLOEXEC = c::O_CLOEXEC;
425 /// `O_NONBLOCK`
426 const NONBLOCK = c::O_NONBLOCK;
427 }
428 }