Stream: general

Topic: snapshot 1 witx vs. implementation


view this post on Zulip Vedant Roy (Apr 17 2020 at 15:40):

The snapshot 1 spec says fd_write has 2 parameters: (fd $fd, iovs $ciovec_array) and 2 results: ($error $errno, $nwritten, $size). However, when looking at this tutorial, the fd_write is called with 4 parameters and has 1 return value (the number of bytes written). I'm a bit confused by what is going on. Does someone have some insight?

WebAssembly System Interface. Contribute to WebAssembly/WASI development by creating an account on GitHub.
Standalone JIT-style runtime for WebAssembly, using Cranelift - bytecodealliance/wasmtime

view this post on Zulip bjorn3 (Apr 17 2020 at 15:42):

The tutorial uses wasi_unstable, not wasi_snapshot_preview1.

view this post on Zulip Vedant Roy (Apr 17 2020 at 15:45):

I changed the import value to wasi_snapshot_preview1 and the tutorial code still worked.

view this post on Zulip Dan Gohman (Apr 17 2020 at 15:49):

The witx description has multiple results. Since MVP-level wasm doesn't support multiple return values, when witx is translated into Rust or C bindings, result values after the first one are translated into pointer parameters to store the output in.

view this post on Zulip Dan Gohman (Apr 17 2020 at 15:50):

And, the signature for fd_write includes an array (the iovec array). When translated into a C interface, this is exposed as two parameters, a pointer and a length.

view this post on Zulip Dan Gohman (Apr 17 2020 at 15:52):

At the wasm level, arrays appear as two parameters as well.


Last updated: Nov 22 2024 at 16:03 UTC