Stream: wasmtime

Topic: clarification about parameters ' wasi functions


view this post on Zulip julia (Sep 12 2022 at 03:29):

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.

view this post on Zulip Alphyr (Sep 12 2022 at 15:07):

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 :

view this post on Zulip julia (Sep 12 2022 at 15:47):

Thanks for helping me!

view this post on Zulip julia (Sep 16 2022 at 07:59):

@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?

view this post on Zulip Alphyr (Sep 19 2022 at 07:32):

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,
}

view this post on Zulip julia (Sep 19 2022 at 23:02):

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

view this post on Zulip Jesús González (Sep 20 2022 at 19:43):

Congrats for the Wasmtime 1.0.0 release!!

view this post on Zulip Pat Hickey (Sep 22 2022 at 00:15):

@julia for places where wiggle is generating types in wasi-common and you can’t read their source, you can use cargo doc

view this post on Zulip julia (Sep 22 2022 at 18:50):

@Pat Hickey will do, thanks!


Last updated: Nov 22 2024 at 17:03 UTC