Why are memory-mapped files unsafe

35 points cameronm1024

I was looking to use memory-mapped files in Rust, and noticed that in the crate I was using memmap, creating a memory-mapped file is unsafe.

I came across a fork called memmap2, but it is unsafe here as well.

Neither crate's docs contain an explanation as to why it is unsafe, or what invariants I need to uphold to keep my program UB-free and sane.

I'm not very familiar with memory-mapped files in general, is there some feature of them that makes them potentially unsafe to use?