Skip to content

Commit 832fb9c

Browse files
authored
Rollup merge of rust-lang#114987 - RalfJung:unsound-mmap, r=cjgillot
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.
2 parents 58eefc3 + 132a2c6 commit 832fb9c

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

compiler/rustc_data_structures/src/memmap.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ pub struct Mmap(Vec<u8>);
1111

1212
#[cfg(not(target_arch = "wasm32"))]
1313
impl Mmap {
14+
/// # Safety
15+
///
16+
/// The given file must not be mutated (i.e., not written, not truncated, ...) until the mapping is closed.
17+
///
18+
/// However in practice most callers do not ensure this, so uses of this function are likely unsound.
1419
#[inline]
1520
pub unsafe fn map(file: File) -> io::Result<Self> {
16-
// Safety: this is in fact not safe.
21+
// Safety: the caller must ensure that this is safe.
1722
unsafe { memmap2::Mmap::map(&file).map(Mmap) }
1823
}
1924
}

0 commit comments

Comments
 (0)