Skip to content

Commit

Permalink
Auto merge of rust-lang#122309 - g-yziquel:issue-122262, r=saethlin
Browse files Browse the repository at this point in the history
Use `MAP_PRIVATE` (not unsound-prone `MAP_SHARED`)

Solves rust-lang#122262
  • Loading branch information
bors committed Mar 16, 2024
2 parents 7aa1de7 + 3fc5ed8 commit 774ae59
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions compiler/rustc_data_structures/src/memmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
}
}

Expand Down

0 comments on commit 774ae59

Please sign in to comment.