This change upgrades `UnsafeGuestSlice` in Wiggle to expose more functionality to be able to use `std::ptr::copy` for writing bytes into Wasm shared memory. Additionally, it adds a new `GuestCow` 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 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. This change only applies to the `preview0` and `preview1` implementations of `wasi-common`. Fixing up other WASI implementations (esp. wasi-crypto) is left for later.
wiggle
Wiggle is a code generator for the host side of a witx interface. It is
invoked as a Rust procedural macro.
Wiggle is not specialized to any particular WebAssembly runtime. It is usable in at least Wasmtime and Lucet.
Learning more
Read the docs on docs.rs.
There are child crates for integrating with Wasmtime and Lucet.
The wasi-common crate is implemented using Wiggle and the wasmtime-wasi crate integrates wasi-common with the Wasmtime engine.
Andrew Brown wrote a great blog post on using Wiggle with Wasmtime.