-
Notifications
You must be signed in to change notification settings - Fork 58
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
Does UnsafeCell::raw_get preserve pointer provenance? #474
Comments
Dumping a bunch of unsafe and raw ptr manipulating code without any comments for what to look at isn't very helpful, I am afraid. Please don't make me reverse engineer your intent from the code. Regarding the questions below the code:
Do you mean #256? |
Yes, sorry for that. I'll try to clarify what I'm trying to do the next time.
Thanks. I hope I didn't get the wrong idea.
Yes. It's interesting to learn that Edit: the shortened example would look like this: fn write_at<T>(slice: &[UnsafeCell<T>], index: usize, value: T) {
assert!(index < slice.len(), "index out of bounds"); // ensure we're able to access slice at `index`
let start = UnsafeCell::raw_get(slice.as_ptr()); // supposedly the normal start pointer that allows both reads and writes for start.add(index)
unsafe { *start.add(index) = value }; // is this sound or ub
} |
Conceptually, what it does is equip the pointer with the permission to mutate -- you have to go through |
This code passes Miri as of now (playground):
Does it mean that raw_get will get to preserve provenance of a pointer going into the future, when Rust will have its own memory model specification?
Afaik Box::leak had the provenance shrinking issue, although it doesn't seem to be the case that pointers ever shrank provenance on their own in any other parts of the language, as long as no intermediate references are created.
The text was updated successfully, but these errors were encountered: