I got confused about parameters of wasi functions.
fd_write function has imported in my wasm module. Its signature shows that it has 5 integers parameters (like below):
(import "wasi_snapshot_preview1" "fd_write" (func $__imported_wasi_snapshot_preview1_fd_write (type 5)))
(type (;5;) (func (param i32 i32 i32 i32) (result i32))
But fd_write signature in witx (and preview_1.rs) shows that it has been implemented with two paramteres:
(@interface func (export "fd_write")
(param $fd $fd)
;;; List of scatter/gather vectors from which to retrieve data.
(param $iovs $ciovec_array)
(result $error (expected $size (error $errno)))
)
I couldn't understand which part of wasmtime is responsible for this parameter transformation and what happen in wasmtime.
Can you please help me with that? Thanks.
A good way to find out this kind of information is to look at an implementation, eg https://docs.rs/wasi/latest/src/wasi/lib_generated.rs.html#1566-1578 :
Thanks for helping me!
@Alphyr I found that some types that use in wasi functions, such as Ciovec type, are defined in WITX specification and generates during compilation of wasmtime. But I need to use these types outside of wasi-common crate. Can you please tell me if it is possible and how?
I don't know a lot about WITX, but maybe you can re-generate WASI structs from the witx files and start from there.
Another solution is to define them yourself, (you can look at code from wasi
to help), eg :
#[repr(C)]
struct Ciovec {
pub buf: i32,
pub buf_len: i32,
}
Thanks for your reply. I could use the types with adding wasi-common crate to dependencies. And then I imported types using the below line:
wasi_common::snapshots::preview_1::types::*;
Also for my first question, I found out the call_interface function in the below file is responsible to do the job.
wasi-common/WASI/tools/witx/src/abi.rs
Congrats for the Wasmtime 1.0.0 release!!
@julia for places where wiggle is generating types in wasi-common and you can’t read their source, you can use cargo doc
@Pat Hickey will do, thanks!
Last updated: Dec 23 2024 at 13:07 UTC