Skip to content

Commit

Permalink
We can only have one mutable borrow at a time after bytecodealliance#…
Browse files Browse the repository at this point in the history
…8277

Co-authored-by: Nick Fitzgerald <fitzgen@gmail.com>
  • Loading branch information
elliottt and fitzgen committed Apr 19, 2024
1 parent 81d7187 commit 60df49b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/wasi-common/src/snapshots/preview_1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,15 @@ impl wasi_snapshot_preview1::WasiSnapshotPreview1 for WasiCtx {
return Ok(0);
}
} else {
// Convert all of the unsafe guest slices to safe ones--this uses
// Wiggle's internal borrow checker to ensure no overlaps. We assume
// here that, because the memory is not shared, there are no other
// threads to access it while it is written to.
// Convert the first unsafe guest slice into a safe one--Wiggle
// can only track mutable borrows for an entire region, and converting
// all guest pointers to slices would cause a runtime borrow-checking
// error. As read is allowed to return less than the requested amount,
// it's valid (though not as efficient) for us to only perform the
// read of the first buffer.
let mut guest_slices: Vec<wiggle::GuestSliceMut<u8>> = iovs
.into_iter()
.take(1)
.map(|iov| Ok(iov.as_slice_mut()?.unwrap()))
.collect::<Result<_, Error>>()?;

Expand Down

0 comments on commit 60df49b

Please sign in to comment.