Skip to content

wiggle: copy guest strings from shared memory #5475

Merged
alexcrichton merged 2 commits intobytecodealliance:mainfrom
abrown:wiggle-copied-str-reads
Jan 4, 2023
Merged

wiggle: copy guest strings from shared memory #5475
alexcrichton merged 2 commits intobytecodealliance:mainfrom
abrown:wiggle-copied-str-reads

Conversation

@abrown
Copy link
Member

@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
Member Author

abrown commented Dec 19, 2022

Depends on #5471; review that PR first!

@abrown abrown force-pushed the wiggle-copied-str-reads branch from 9c343b3 to ab11505 Compare December 19, 2022 23:26
@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

Details 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.

abrown added 2 commits January 3, 2023 15:47
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 force-pushed the wiggle-copied-str-reads branch from cef93fe to 4690bfb Compare January 3, 2023 23:53
@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