Skip to content

Commit

Permalink
Rollup merge of #114987 - RalfJung:unsound-mmap, r=cjgillot
Browse files Browse the repository at this point in the history
elaborate a bit on the (lack of) safety in 'Mmap::map'

Sadly none of the callers of this function even consider it worth mentioning in their unsafe block that what they are doing is completely unsound.
  • Loading branch information
weihanglo authored Aug 24, 2023
2 parents 58eefc3 + 132a2c6 commit 832fb9c
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion compiler/rustc_data_structures/src/memmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@ pub struct Mmap(Vec<u8>);

#[cfg(not(target_arch = "wasm32"))]
impl Mmap {
/// # Safety
///
/// The given file must not be mutated (i.e., not written, not truncated, ...) until the mapping is closed.
///
/// 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: this is in fact not safe.
// Safety: the caller must ensure that this is safe.
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
}
}
Expand Down

0 comments on commit 832fb9c

Please sign in to comment.