Comments (4)
PROT_READ + MAP_PRIVATE
is also useful if one then casts the slice into utf8 because this allows an safer usage of mmap (verified const utf8 content (&[u8]
) will stay the same, without violation of Rusts strict aliasing rules).
from memmap-rs.
example usage: https://github.com/zserik/readfilez/blob/master/src/lib.rs
from memmap-rs.
@zseri I am somewhat late to comment on this, but I think
PROT_READ + MAP_PRIVATE is also useful if one then casts the slice into utf8 because this allows an safer usage of mmap (verified const utf8 content (&[u8]) will stay the same, without violation of Rusts strict aliasing rules).
is not correct as the Linux manual page for mmap
says
It is unspecified whether changes made to the file after the mmap() call are visible in the mapped region.
concerning MAP_PRIVATE
, i.e. it ensures that your changes do not propagate to the underlying file, but it does not seem to ensure that changes to the underlying file do not propagate into your mapping, i.e. another process could possibly turn the file contents into invalid UTF-8 after you validated it.
As a result of the discussion at https://users.rust-lang.org/t/how-unsafe-is-mmap/19635, I think we need another mapping mode that is sort of the converse of MAP_PRIVATE
, maybe MAP_SNAPSHOT
, which ensures that if a process has read a page at least once, it will not change even if the underlying file changes. Or alternatively, the unspecified part of the behaviour of MAP_PRIVATE
would need to be strengthened into that direction.
from memmap-rs.
Yeah, I also noticed that... A far bigger problem is also that the underlying file can suddenly become truncated, and if the mapping is then read, it might fail with SIGBUS
.
from memmap-rs.
Related Issues (20)
- Incorrectly uses usize instead of u64 for file offsets HOT 2
- Support madvise. HOT 4
- what happens if we exceed isize::MAX on 32-bit platforms? HOT 10
- Docs should say why file-backed maps are unsafe HOT 4
- Mmap fails for empty files on Windows HOT 21
- Allow mapping memory safely using `volatile` crate? HOT 4
- Use with DirectIO HOT 2
- Possible overflow while mapping large files on 32 bit systems HOT 1
- Should anonymous mappings be MAP_SHARED by default?
- Allow anonymous RWX mappings HOT 1
- Implement StableDeref?
- Expose page_size pub function as part of crate api
- Support `Mmap` on platforms without real mmap support HOT 4
- Is this crate still maintained? HOT 15
- Error when mapping large files on Windows HOT 2
- Code 87 when attempting to write files HOT 1
- Handling IO-Errors during operation (which happen with network shares and connection drops) HOT 3
- ❌ mmap.binary_search EXC_BAD_ACCESS HOT 2
- Safety comments are missing HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from memmap-rs.