Stream: general

Topic: ✔ Passing a file descriptor to WASI


view this post on Zulip Alsan Ali (Mar 10 2022 at 09:08):

The wasi crate has the sock_send and sock_recv functions, both of which takes in a file descriptor as an argument.

How do you get a file descriptor into WASI? I heard about passing file descriptors through Unix domain sockets, but doesn’t that require WASI to bind to a Unix socket first? I couldn’t find any functions for that

view this post on Zulip bjorn3 (Mar 10 2022 at 09:13):

You can use --tcplisten or --listenfd:

view this post on Zulip bjorn3 (Mar 10 2022 at 09:13):

https://github.com/bytecodealliance/wasmtime/pull/3729

As a follow up for #3711, this implements CLI options to insert pre-opened sockets. --listenfd : Inherit environment variables and file descriptors following the systemd listen fd specification (UN...

view this post on Zulip Notification Bot (Mar 11 2022 at 11:29):

Alsan Ali has marked this topic as resolved.

view this post on Zulip Alsan Ali (Mar 12 2022 at 04:31):

Hmm that seems to work for TCP. This will also probably work for Unix domain sockets by using --listenfd. But how do I use the Unix domain socket to pass file descriptors around? The "sendmsg" system call isn't there in the WASI crate.

view this post on Zulip bjorn3 (Mar 12 2022 at 21:13):

I don't think that makes should be done at all. There is no direct mapping between wasi and host fds. Wasi fds may be backed by code running inside of wasmtime and as such those can't be sent to another process over a unix domain socket. Some fds received fron a unix domain socket may be dangerous and as such shouldn't be exposed to wasi.

view this post on Zulip xpepermint (Sep 19 2022 at 15:19):

I'd also be interested in this. I struggle to find examples of wasi+fs in general. Suggestions?

view this post on Zulip Lann Martin (Sep 19 2022 at 17:25):

The WASI interface is still being developed. I've found the best canonical source of information is the wasmtime source code, especially https://docs.rs/wasmtime-wasi/latest/wasmtime_wasi/sync/struct.WasiCtxBuilder.html and the WasiCtx it creates

view this post on Zulip xpepermint (Sep 19 2022 at 19:10):

Lann Martin said:

The WASI interface is still being developed. I've found the best canonical source of information is the wasmtime source code, especially https://docs.rs/wasmtime-wasi/latest/wasmtime_wasi/sync/struct.WasiCtxBuilder.html and the WasiCtx it creates

Yeah, been playing with that but have issues :). Ref: https://github.com/bytecodealliance/wasmtime/issues/4925

I'd kindly ask the community to provide an example of how to pass files and folders to WasiCtx based on the scaffold below: fn main() -> Result<()> { let engine = Engine::default(); le...

Last updated: Nov 22 2024 at 16:03 UTC