Skip to content

Commit 774ae59

Browse files
committed
Auto merge of #122309 - g-yziquel:issue-122262, r=saethlin
Use `MAP_PRIVATE` (not unsound-prone `MAP_SHARED`) Solves #122262
2 parents 7aa1de7 + 3fc5ed8 commit 774ae59

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

compiler/rustc_data_structures/src/memmap.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ impl Mmap {
1818
/// However in practice most callers do not ensure this, so uses of this function are likely unsound.
1919
#[inline]
2020
pub unsafe fn map(file: File) -> io::Result<Self> {
21-
// Safety: the caller must ensure that this is safe.
22-
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
21+
// By default, memmap2 creates shared mappings, implying that we could see updates to the
22+
// file through the mapping. That would violate our precondition; so by requesting a
23+
// map_copy_read_only we do not lose anything.
24+
// This mapping mode also improves our support for filesystems such as cacheless virtiofs.
25+
// For more details see https://github.com/rust-lang/rust/issues/122262
26+
//
27+
// SAFETY: The caller must ensure that this is safe.
28+
unsafe { memmap2::MmapOptions::new().map_copy_read_only(&file).map(Mmap) }
2329
}
2430
}
2531

0 commit comments

Comments
 (0)