Re:Llama2.rs: One-file Rust implementation of Llama2
by WhyNotHugo on Sunday August 06, 2023 @04:19AM
(#37019973)
It’s not safe under Rust’s definition of safe.
If you map the file into readonly memory and than get references to it, the underlying memory can mutate (eg: by modifying the file itself).
Some operating systems do provide the proper guarantees to make mmap safe, but Rust decided it would be best to assume it's unsafe and maintain a uniform API. Which is probably a good call, it is notoriously difficult to get a readonly mmap to be entirely safe on Linux.
https://docs.rs/mmap-rs/latest/mmap_rs/struct.MmapOptions.ht...