abrown opened PR #5471 from wiggle-copied-reads
to main
:
This change upgrades
UnsafeGuestSlice
in Wiggle to expose more functionality to be able to usestd::ptr::copy
for writing bytes into Wasm shared memory. Additionally, it adds a newGuestCow
type for delineating between Wasm memory regions that can be borrowed (non-shared memory) or must be copied (shared memory) in order to maintain Rust guarantees.With these in place, it is now possible to implement the
preview1
"read" functions for shared memory. Previously, these would panic if attempting to copy to a shared memory. This change removes the panic and introduces some (rather complex) logic for handling both the shared and non-shared cases:
- if reading into a Wasm non-shared memory, Wiggle guarantees that no other guest pointers will touch the memory region and, in the absence of concurrency,
preview1
can write directly to this memory- if reading into a Wasm shared memory, the memory region can be concurrently modified. At @alexcrichton's request re: Rust safety, this change copies all of the bytes into an intermediate buffer before using
std::ptr::copy
to move them into Wasm memory.<!--
Please ensure that the following steps are all taken care of before submitting
the PR.
[ ] This has been discussed in issue #..., or if not, please tell us why
here.[ ] A short description of what this does, why it is needed; if the
description becomes long, the matter should probably be discussed in an issue
first.[ ] This PR contains test cases, if meaningful.
- [ ] A reviewer from the core maintainer team has been assigned for this PR.
If you don't know who could review this, please indicate so. The list of
suggested reviewers on the right can help you.Please ensure all communication adheres to the code of conduct.
-->
abrown has marked PR #5471 as ready for review.
abrown requested alexcrichton for a review on PR #5471.
abrown updated PR #5471 from wiggle-copied-reads
to main
.
abrown updated PR #5471 from wiggle-copied-reads
to main
.
abrown edited PR #5471 from wiggle-copied-reads
to main
:
This change upgrades
UnsafeGuestSlice
in Wiggle to expose more
functionality to be able to usestd::ptr::copy
for writing bytes into
Wasm shared memory. Additionally, it adds a newGuestCow
type for
delineating between Wasm memory regions that can be borrowed (non-shared
memory) or must be copied (shared memory) in order to maintain Rust
guarantees.With these in place, it is now possible to implement the
preview1
"read" functions for shared memory. Previously, these would panic if
attempting to copy to a shared memory. This change removes the panic and
introduces some (rather complex) logic for handling both the shared and
non-shared cases:
if reading into a Wasm non-shared memory, Wiggle guarantees that no
other guest pointers will touch the memory region and, in the absence
of concurrency, a WASI function can write directly to this memoryif reading into a Wasm shared memory, the memory region can be
concurrently modified. At @alexcrichton's request re: Rust safety,
this change copies all of the bytes into an intermediate buffer before
usingstd::ptr::copy
to move them into Wasm memory.This change only applies to the
preview0
andpreview1
implementations ofwasi-common
. Fixing up other WASI implementations
(esp. wasi-crypto) is left for later.
alexcrichton created PR review comment:
Since
random_get
fills the entire buffer I think this will need toloop
or otherwise this will return an error sincetmp
may be shorter thanbuf
alexcrichton submitted PR review.
alexcrichton created PR review comment:
Could you leave some comments that this is for the
UnsafeCell
inside?
alexcrichton submitted PR review.
alexcrichton created PR review comment:
This
vec!
I think can get removed (just use a[..]
on the stack)
abrown updated PR #5471 from wiggle-copied-reads
to main
.
abrown submitted PR review.
abrown created PR review comment:
You might want to take a look at 652988f since I changed the
GuestPtr
API slightly.
alexcrichton submitted PR review.
abrown has enabled auto merge for PR #5471.
abrown merged PR #5471.
Last updated: Nov 22 2024 at 16:03 UTC