Stream: wasi

Topic: How to make a new libc for Wasm


view this post on Zulip Coulson Liang (Apr 16 2024 at 21:51):

I want to make a new libc for compiling C programs into WASM. The hard part for me now is that, in the libc, how to make the eventual syscalls. Like in glibc, for every architecture, there are dedicated assembly code to put arguments into certain registers and make the calls. But how should I do this part for a wasm libc?

I think I can borrow the way wasi-libc does this, so I want to ask where in the wasi-libc defines how syscalls like fd_write are eventually made, if I want to add more syscalls, how to add it?

Eventually I want also write HostFunctions in a runtime like Wasmtime to handle the syscalls made in the libc.

view this post on Zulip IFcoltransG (Apr 16 2024 at 22:59):

Your libc would probably want to target WASI as the underlying system abstraction to begin with. WASI (at least the CLI world) exports low-level functions that your libc can call for files, sockets, clocks, standard streams, exit codes and so on.

view this post on Zulip fitzgen (he/him) (Apr 17 2024 at 18:19):

https://github.com/WebAssembly/wasi-libc can always use some helping hands from people who enjoy hacking on libc impls; at minimum should show you what is involved for targeting wasm and wasi for a libc

WASI libc implementation for WebAssembly. Contribute to WebAssembly/wasi-libc development by creating an account on GitHub.

view this post on Zulip Coulson Liang (Apr 17 2024 at 20:13):

@fitzgen (he/him) Hi, yes, I just want to figure out how wasi-libc implemented the part that actually issuing the syscalls like fd_write into the runtime, no matter Wasmtime or Wasmer then handles this call and make reall syscalls to the host system.
So I want to know which part of wasi-libc is doing the interface between the libc and the runtime? Thank you!

view this post on Zulip fitzgen (he/him) (Apr 17 2024 at 20:54):

It is a function call to an imported function, for example https://github.com/WebAssembly/wasi-libc/blob/9e8c542319242a5e536e14e6046de5968d298038/libc-bottom-half/sources/wasip2.c#L5-L6

WASI libc implementation for WebAssembly. Contribute to WebAssembly/wasi-libc development by creating an account on GitHub.

view this post on Zulip fitzgen (he/him) (Apr 17 2024 at 20:55):

but you almost assuredly don't want to write those functions by hand and all that, instead you want to use wit-bindgen to automatically generate it based on the WIT definitions of the WASI interfaces


Last updated: Nov 22 2024 at 17:03 UTC