-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Better terminology re: safety #13
Comments
Hmm... I'm not the one who wrote this docs, so I don't have any comments here either. |
Related to this, we should probably also discuss safety of the various constructor methods for TLDR, if I create a unique or shared slice reference, I currently need to ensure via outside means that no other process modifies the underlying file with those changes propagating into my mapping, so that an While doing so, we could also stop allowing the |
Yes, I'm also not sure what should happen when we open the same file twice. On the other hand, all memmap methods are unsafe for a reason. |
I agree
I think it's necessary and sufficient that caller guarantees when creating a
There are a couple safe ones (correctly, I think):
If there were helpers on |
Honestly, I don't understand why we have @diwic Hi. Could you clarify why you choose to create |
I don't know the history, but I like the idea of being able to use mmap in a purely-safe way, so I like the idea of having ones that don't expose references (instead only having copying functions). |
Well, they expose raw pointers, which is also not safe. |
You can't use the raw pointers without saying |
Do I understand correctly, that you're suggesting to mark |
Ok... I guess I'm starting to understand the issue =) Would you be interested in making a PR? I bet I will mess it up if I do it myself. |
Sure! |
What would you see as the primary benefit of such an interface compared to say using |
Yeah, just speed, primarily through reduced system call overhead. I saw an article suggesting userland |
So I use MmapRaw for https://github.com/diwic/shmem-ipc - between untrusted processes. So that means, that the other process could at any time change the data, so creating references at any point is potentially unsound. With Mmap / MmapMut it's extremely easy to create such references, it's just a deref away, the compiler could do it without you thinking about it - e g, the That was the reasoning. If you must avoid creating references to the shared data, then Mmap / MmapMut does not have a good API because it makes it too easy to do just that. |
Even if that statement is true in Linux, I'm not sure it is correct for all supported platforms. E g, on Windows, it is recommended to use exceptions, and to which degree exceptions are safe or unsafe in Rust is beyond me... |
@diwic Thanks for the explanation. I agree with this decision. |
The docs for
MmapRaw::as_ptr()
andMmapRaw::as_mut_ptr()
both say:However, this isn't true in the Rust sense of the word safety: if the file is truncated, the memory mapping itself is not changed. So accessing that memory will simply cause the process to be killed with SIGBUS(1) or equivalent. That's not actually a memory safety issue as no memory will actually be read or written.
To avoid confusion, I think it'd be good to keep this warning, but rename the section to something else and describe why truncation isn't directly a memory safety issue.
The text was updated successfully, but these errors were encountered: