Skip to content

fix fd_read and fd_write for wasm32-wasi-threads#7750

Merged
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
dicej:bug-7745
Jan 5, 2024
Merged

fix fd_read and fd_write for wasm32-wasi-threads#7750
alexcrichton merged 1 commit into
bytecodealliance:mainfrom
dicej:bug-7745

Conversation

@dicej
Copy link
Copy Markdown
Contributor

@dicej dicej commented Jan 4, 2024

Previously, first_non_empty_{c}io_vec always returned Ok(None) for buffers residing in shared memories since they cannot, in general, safely be represented as slices. That caused e.g. wasi-libc to spin forever when trying to write to stdout using fd_write since it always got Ok(0) and never made progress.

This commit changes the return type of both functions to use GuestPtr instead of GuestSlice{Mut}, allowing safe access to shared guest memory.

Big thanks to Alex Crichton for narrowing this down and suggesting the fix.

Fixes #7745

Previously, `first_non_empty_{c}io_vec` always returned `Ok(None)` for buffers
residing in shared memories since they cannot, in general, safely be represented
as slices.  That caused e.g. `wasi-libc` to spin forever when trying to write to
stdout using `fd_write` since it always got `Ok(0)` and never made progress.

This commit changes the return type of both functions to use `GuestPtr` instead
of `GuestSlice{Mut}`, allowing safe access to shared guest memory.

Big thanks to Alex Crichton for narrowing this down and suggesting the fix.

Fixes bytecodealliance#7745

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
@dicej dicej requested a review from a team as a code owner January 4, 2024 22:05
@dicej dicej requested review from alexcrichton and pchickey and removed request for a team and pchickey January 4, 2024 22:05
@dicej dicej added this pull request to the merge queue Jan 4, 2024
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jan 5, 2024
@alexcrichton alexcrichton added this pull request to the merge queue Jan 5, 2024
@github-actions github-actions Bot added the wasi Issues pertaining to WASI label Jan 5, 2024
Merged via the queue into bytecodealliance:main with commit c63cf1f Jan 5, 2024
dicej added a commit to dicej/wasmtime that referenced this pull request Jan 5, 2024
…ds` (bytecodealliance#7750)

Previously, `first_non_empty_{c}io_vec` always returned `Ok(None)` for buffers
residing in shared memories since they cannot, in general, safely be represented
as slices.  That caused e.g. `wasi-libc` to spin forever when trying to write to
stdout using `fd_write` since it always got `Ok(0)` and never made progress.

This commit changes the return type of both functions to use `GuestPtr` instead
of `GuestSlice{Mut}`, allowing safe access to shared guest memory.

Big thanks to Alex Crichton for narrowing this down and suggesting the fix.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
dicej added a commit that referenced this pull request Jan 5, 2024
…ds` (#7750) (#7755)

Previously, `first_non_empty_{c}io_vec` always returned `Ok(None)` for buffers
residing in shared memories since they cannot, in general, safely be represented
as slices.  That caused e.g. `wasi-libc` to spin forever when trying to write to
stdout using `fd_write` since it always got `Ok(0)` and never made progress.

This commit changes the return type of both functions to use `GuestPtr` instead
of `GuestSlice{Mut}`, allowing safe access to shared guest memory.

Big thanks to Alex Crichton for narrowing this down and suggesting the fix.

Signed-off-by: Joel Dice <joel.dice@fermyon.com>
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.

Wasmtime loops forever when wasm32-wasi-threads guests write to stdout

3 participants