WebAssembly / WASI

WebAssembly System Interface
Other
4.75k stars 243 forks source link

Confusion about WASI's function types. #495

Open abc767234318 opened 1 year ago

abc767234318 commented 1 year ago

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

devsnek commented 1 year ago

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.

abc767234318 commented 1 year ago

Thanks, but where can I get these ABI informations?

jmgurney commented 1 year ago

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

oovm commented 7 months ago

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?

cmplstofB commented 6 months ago

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).