-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Docs driveby fix for Memory::data
#808
Docs driveby fix for Memory::data
#808
Conversation
Co-Authored-By: Jakub Konka <[email protected]>
The removed doc is true as well. Can we keep it as well? |
Perhaps I'm missing something. Isn't |
Also, should |
This appears to conflict with #812 from @alexcrichton which might answer some of my questions above. |
The exact problem is here https://www.reddit.com/r/rust/comments/e18jcq/how_to_read_and_write_to_memory_in_wasmtime/ , notice discussion around getting |
Agreed that storing the slice reference returned by I was failing to see, however, how At any rate, I think this PR might now be superseded by #812. |
Yes to clarify there's a large number of reasons that this is an To answer your questions though @peterhuene:
Correct!
While true that other threads can't update this, you could still have something like: let ptr = memory.data();
instance.call_export("foo"); // invalidates `ptr` by calling `memory.grow`
println!("{:?}", ptr); // reads stale data (basically this is just a "bland use-after-free")
Due to the aliasing of so many internals here that actually doesn't end up buying us anything. I recently added internal reference counting so you could actually do: let mut memory = ...;
let mut memory2 = memory.clone();
assert_eq!(memory.data(), memory2.data()); // aliasing mutable pointers! Even if we didn't have reference counting you still have the above problem: let mut view = memory.data();
instance.call_export("foo"); // technically referred to by instance, so `view` is still aliased
println!("{:?}", view); // use-after-free The only way Rust's type system would help here is if we would have something like Even if we did that, however, then you couldn't share memories across threads which is something we'd like to support eventually! Overall I think we'll need to stick to "all memory access are |
@pepyakin thanks for putting up this PR! Given @alexcrichton's incoming changes to the API and subsequent updates to the comments to this method, I'm closing this as superseded by #812. Please comment on that PR if the updated doc comments are insufficient to convey the changes made in this PR. Thanks! |
@alexcrichton agreed that there is a general aliasing problem, which is why I thought the change here was a more "general purpose" warning than the previous message. I appreciate the additional detail you've added in #812! |
Reshape the safety warning around mutable aliases instead of threads.