about summary refs log tree commit diff
path: root/compiler
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2024-03-16 09:19:08 +0000
committerbors <bors@rust-lang.org>2024-03-16 09:19:08 +0000
commit774ae599aba35f7b323e77be88923b8f476ee783 (patch)
tree1268f9a9fae09e3d725fd2268052d3164329a989 /compiler
parent7aa1de7ed84e77aa22d1428128fcd4089a3abd13 (diff)
parent3fc5ed8067f98e2cae8c259a2e367024c59a3ad3 (diff)
downloadrust-774ae599aba35f7b323e77be88923b8f476ee783.tar.gz
rust-774ae599aba35f7b323e77be88923b8f476ee783.zip
Auto merge of #122309 - g-yziquel:issue-122262, r=saethlin
Use `MAP_PRIVATE` (not unsound-prone `MAP_SHARED`)

Solves https://github.com/rust-lang/rust/issues/122262
Diffstat (limited to 'compiler')
-rw-r--r--compiler/rustc_data_structures/src/memmap.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/compiler/rustc_data_structures/src/memmap.rs b/compiler/rustc_data_structures/src/memmap.rs
index 30403a61442..c7f66b2fee8 100644
--- a/compiler/rustc_data_structures/src/memmap.rs
+++ b/compiler/rustc_data_structures/src/memmap.rs
@@ -18,8 +18,14 @@ impl Mmap {
     /// However in practice most callers do not ensure this, so uses of this function are likely unsound.
     #[inline]
     pub unsafe fn map(file: File) -> io::Result<Self> {
-        // Safety: the caller must ensure that this is safe.
-        unsafe { memmap2::Mmap::map(&file).map(Mmap) }
+        // By default, memmap2 creates shared mappings, implying that we could see updates to the
+        // file through the mapping. That would violate our precondition; so by requesting a
+        // map_copy_read_only we do not lose anything.
+        // This mapping mode also improves our support for filesystems such as cacheless virtiofs.
+        // For more details see https://github.com/rust-lang/rust/issues/122262
+        //
+        // SAFETY: The caller must ensure that this is safe.
+        unsafe { memmap2::MmapOptions::new().map_copy_read_only(&file).map(Mmap) }
     }
 }