Skip to content
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

wiggle: copy guest strings from shared memory #5475

Merged
merged 2 commits into from
Jan 4, 2023

Conversation

abrown
Copy link
Contributor

@abrown abrown commented Dec 19, 2022

Along the same lines as #5471, this change adds a new smart pointer,
GuestStrCow, to copy the string bytes over from Wasm memory to the
host when the string is found in shared memory. This is necessary to
maintain Rust guarantees: with shared memory, the bytes backing a
GuestStr could be altered by another thread and this would invalidate
the assumption that we can dereference at any point to &str.
GuestStrCow is essentially a wrapper around GuestStr when the memory
is not shared but copies the memory region into a String when the
memory is shared.

@abrown
Copy link
Contributor Author

abrown commented Dec 19, 2022

Depends on #5471; review that PR first!

@github-actions github-actions bot added the wasi Issues pertaining to WASI label Dec 20, 2022
@github-actions
Copy link

Subscribe to Label Action

cc @kubkon

This issue or pull request has been labeled: "wasi"

Thus the following users have been cc'd because of the following labels:

  • kubkon: wasi

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

crates/wiggle/src/lib.rs Outdated Show resolved Hide resolved
Along the same lines as bytecodealliance#5471, this change adds a new smart pointer,
`GuestStrCow`, to copy the string bytes over from Wasm memory to the
host when the string is found in shared memory. This is necessary to
maintain Rust guarantees: with shared memory, the bytes backing a
`GuestStr` could be altered by another thread and this would invalidate
the assumption that we can dereference at any point to `&str`.
`GuestStrCow` is essentially a wrapper around `GuestStr` when the memory
is not shared but copies the memory region into a `String` when the
memory is shared.

This change updates the uses of Wiggle strings in both wasi-common and
wasi-crypto.
@abrown abrown marked this pull request as ready for review January 3, 2023 23:54
@alexcrichton alexcrichton merged commit 7c67378 into bytecodealliance:main Jan 4, 2023
@abrown abrown deleted the wiggle-copied-str-reads branch January 4, 2023 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi Issues pertaining to WASI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants