WASI icon indicating copy to clipboard operation
WASI copied to clipboard

Confusion about WASI's function types.

Open abc767234318 opened this issue 3 years ago • 5 comments

Why are the function types in the wasi API documentation different from the ones I actually compiled in wasm? image
The fd_write function in the above document takes two parameters, but the following figure actually takes four.
image

abc767234318 avatar Sep 29 '22 12:09 abc767234318

this is to do with the actual abi that represents those arguments. the four args are (fd, iovs base pointer, iovs length, bytes written pointer) and the return value is the errno.

devsnek avatar Sep 29 '22 15:09 devsnek

Thanks, but where can I get these ABI informations?

abc767234318 avatar Sep 30 '22 04:09 abc767234318

@abc767234318 the closest I found is: https://github.com/WebAssembly/WASI/blob/0ba0c5e2e37625ca5a6d3e4255a998dfaa3efc52/phases/snapshot/docs.md#-fd_writefd-fd-iovs-ciovec_array---resultsize-errno

But how ciovec_array is laid out isn't explained anywhere that I can find, as ciovec_array link points to something w/ just size and alignment, and no description of how a List is laid out.

jmgurney avatar Dec 22 '22 00:12 jmgurney

What should I do if I want to pass the ref array in the gc proposal?

Do I have to write a loop to copy to linear memory first? Is there a more efficient way of passing it?

oovm avatar Dec 14 '23 02:12 oovm

In addition, the type of $fd is defined to be (handle), https://github.com/WebAssembly/WASI/blob/a7be582112b35e281058f1df7d8628bb30a69c3f/legacy/preview1/witx/typenames.witx#L284 but it seems there are no document that specified how this "handle" value for $fd should be written for example in .wat file.

I found some sentences in another WebAssembly repository that describes "Handle", but it only provides a brief example in the Rust language, without mentioning what "Handle" value is actually are (e.g. replesentation in .wat file).

cmplstofB avatar Jan 09 '24 04:01 cmplstofB