WebAssembly / WASI

WebAssembly System Interface
Other
4.93k stars 256 forks source link

Composable WASI interfaces #262

Open benbrittain opened 4 years ago

benbrittain commented 4 years ago

I'd like WASI function calls to be routed to an instance based on the origin of the handle. This likely requires some dynamic routing capabilities in the wasm runtime.

As things currently work, a module is aware of all it's imports. As we move to a world of "shared-nothing linking", threads, and having the lifetimes of wasm instances decoupled from each other, an interesting problem arises.

Let's imagine two modules both providing the hypothetical standardized wasi file interface. Module A is an in-memory filesystem written in WASM, Module B is the host filesystem. An instance should be able to receive a handle to either module (or even both at the same time!) and call the standardized ready/write/stat/etc.. interfaces on the handle.

Currently, all WASI calls terminate in the engine, nothing else implements these interfaces. If we'd like other modules to be able to mint these capabilities (and other capabilities potentially not defined by WASI), something needs to route the calls.

sunfishcode commented 8 months ago

This is now partly achieved by having read/write factored out from streamy resources into a dedicated stream type. So instead of having read/write be dynamically routed to files/sockets/bodies, they're now statically routed to the wasi-io stream interface.