From 7d75bbc9d6cfe91b903c91f39ed8b500ec65b8d1 Mon Sep 17 00:00:00 2001 From: sectordistrict <157201659+sectordistrict@users.noreply.github.com> Date: Sun, 15 Sep 2024 08:19:01 +0300 Subject: [PATCH] Add MAP_SHARED_VALIDATE & MAP_SYNC (#2499) * Add MAP_SHARED_VALIDATE & MAP_SYNC This pull adds two flags: MAP_SHARED_VALIDATE & MAP_SYNC implemented on https://github.com/rust-lang/libc The MAP_SHARED_VALIDATE flag was added to linux since 4.15, its a flag that does two things: provide backwards compatibility with old mmap implementations that don't check for flags, and allow new flags to be added. MAP_SYNC, on the other hand, was added to allow mmap to utilize Direct Accses (DAX) on hardware that support it (non-volatile memory devices) or in general: any ram-shaped filesystem. both flags are available on both linux and android. * fix CI * fix CI * add to changelog * do not compile on hurd and uclibc * do not compile on freebsdlike * apply requested conditional compilation fixes * apply requested conditional compilation fixes --- changelog/2499.added.md | 1 + src/sys/mman.rs | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 changelog/2499.added.md diff --git a/changelog/2499.added.md b/changelog/2499.added.md new file mode 100644 index 0000000000..cc2f5fdb0a --- /dev/null +++ b/changelog/2499.added.md @@ -0,0 +1 @@ +`MAP_SHARED_VALIDATE` was added for all linux targets. & `MAP_SYNC` was added for linux with the exclusion of mips architecures, and uclibc diff --git a/src/sys/mman.rs b/src/sys/mman.rs index a64f14f588..305061f2c3 100644 --- a/src/sys/mman.rs +++ b/src/sys/mman.rs @@ -41,6 +41,9 @@ libc_bitflags! { MAP_FILE; /// Share this mapping. Mutually exclusive with `MAP_PRIVATE`. MAP_SHARED; + /// Force mmap to check and fail on unknown flags. This also enables `MAP_SYNC`. + #[cfg(target_os = "linux")] + MAP_SHARED_VALIDATE; /// Create a private copy-on-write mapping. Mutually exclusive with `MAP_SHARED`. MAP_PRIVATE; /// Place the mapping at exactly the address specified in `addr`. @@ -142,6 +145,10 @@ libc_bitflags! { /// Region grows down, like a stack. #[cfg(any(linux_android, freebsdlike, target_os = "openbsd"))] MAP_STACK; + /// Do not write through the page caches, write directly to the file. Used for Direct Access (DAX) enabled file systems. + // Available on Linux glibc and musl, MIPS* target excluded. + #[cfg(all(target_os = "linux", not(any(target_arch = "mips", target_arch = "mips64", target_arch = "mips32r6", target_arch = "mips64r6")), not(target_env = "uclibc")))] + MAP_SYNC; /// Pages in this mapping are not retained in the kernel's memory cache. #[cfg(apple_targets)] MAP_NOCACHE;