Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WASI API considerations #91

Closed
dumblob opened this issue Apr 2, 2019 · 3 comments
Closed

WASI API considerations #91

dumblob opened this issue Apr 2, 2019 · 3 comments
Labels
wasi:api Issues pertaining to the WASI API, not necessarily specific to Wasmtime.

Comments

@dumblob
Copy link

dumblob commented Apr 2, 2019

After looking quickly at the API, I came to conclusion, that it seems to be slightly more unix/POSIX oriented than a really generic API. Maybe there is still time to do something about it 😉.

  1. Drawbridge - a modern API from Microsoft with just 45 syscalls
@sunfishcode sunfishcode added the wasi:api Issues pertaining to the WASI API, not necessarily specific to Wasmtime. label Apr 2, 2019
@sunfishcode
Copy link
Member

Thanks for the link!

Some parts of Drawbridge operate at a different level of abstraction, for example:

VOID *DkVirtualMemoryAlloc(Addr, Size, AllocType, Prot);
DkVirtualMemoryFree(Addr, Size, FreeType);
DkVirtualMemoryProtect(Addr, Size, Prot);
DkStreamMap(StreamHandle, Addr, ProtFlags, Offset, Size);
DkStreamUnmap(Addr);

The reason we didn't approach WASI at this level is that the core WebAssembly platform with linear memory is already at a higher level; some of the issues are described here.

Some parts look somewhat similar to APIs in WASI:

ULONG DkStreamRead(StreamHandle, Offset, Size, Buffer);
ULONG DkStreamWrite(StreamHandle, Offset, Size, Buffer);

although I wasn't able to find detailed documentation on how these and other APIs work.

Drawbridge also appears to offer process checkpointing with serialization, which is useful functionality that WASI may want to consider.

The paper says "our library OS leverages I/O streams to emulate NT file objects and named pipe objects, as well as a proxied interface to networking sockets." There's unfortunately not a lot of detail here, but we have looked at other systems that do similar things, and I can offer some general thoughts:

The paper doesn't have a lot of detail, so I'm making some assumptions here; please feel welcome to correct me if I'm getting something wrong. What the above seems to imply is that Drawbridge in fact does have fairly complex and possibly Windows-specific APIs, which aren't reflected in the absolute number of system calls, because they're being proxied over stream APIs.

In general, I believe WebAssembly pushes us away from APIs that serialize structured data or complex APIs into streams, at least when communicating between WebAssembly modules. This is because WebAssembly has other ways to do this -- modules can just call each other, both ways, directly. While this does mean that the number of system calls might end up higher than it might otherwise be, it doesn't mean that the system has more features or is more complex. In some ways, this simplifies the system because it takes better advantage of WebAssembly's static type checking.

If there are other specific ideas from Drawbridge you think are worth considering, please highlight them!

@dumblob
Copy link
Author

dumblob commented Apr 3, 2019

Yes, checkpointing is an interesting feature (security, deployment, ...). There might be also some more information about the use of the "streaming API" in these places:

Apart from Drawbridge I have some concerns e. g. about the tree-based filesystem-like API (see WebAssembly/WASI#1 (comment) ) and in general about the "too rigid, almost archaic" perception of logical data chunks with serialized data usually called files. The concept of a file might be defined similarly to the following tuple.

name, additional_metadata, metadata_inside, actual_data_inside, serialization_type_of_the_inside, permissions, permissions_scheme

Note name is not included in metadata_inside as metadata_inside are inside of the file - i.e. part of the serialized data chunk. In case of Windows the other "streams" would fit under additional_metadata (e.g. https://blogs.msdn.microsoft.com/ie/2005/03/07/mark-of-the-web/ ). Things like access times, etc. are also under additional_metadata. serialization_type_of_the_inside is more or less a MIME type and its version (e.g. CAD formats evolved over time and have several versions). permissions_scheme might be e.g. ugo|rwx or something more fine-grained like xattr or even more fine-grained (e.g. Samba permissions), etc.

I believe WASI shall abstract over this to simplify things and allow for more straightforward (more efficient) use of the actual data.


As a side note - actually I think there is nothing like a file, but rather just a pair of separate chunks of data: RAW deserialized unfiltered data (e.g. pixels in an image), RAW deserialized unfiltered metadata (just additional information about the set of pixels - e.g. GPS coordinates of their origin on Earth), but no compression, no MIME type, no access rights, nothing like that. All this other stuff is just a matter of filtering (compression/decompression, serialization/deserialization, ...) or matter of surrounding (access times, permissions, ...). But this sounds too radical for WASI, so it's just to show the way 😉.

@sunfishcode
Copy link
Member

Discussion continues at WebAssembly/WASI#28.

kubkon pushed a commit that referenced this issue Nov 7, 2019
* Begin sketching out a new high-level `fs` API.

This is a very preliminary sketch of #83. It doesn't even compile yet,
but it shows a possible high-level structure of such an API.

* Stub out more functionality.

* Switch from a lazy_static WasiCtx to a borrowed one.

* Reformat some comments.

* Code-quote `Self`.

* Implement error translation for Windows.

* Calls to `fd_close` are now unsafe.

* Implement a few more functions.
grishasobol pushed a commit to grishasobol/wasmtime that referenced this issue Nov 29, 2021
This allows zero-copy access to the linear memory.
howjmay pushed a commit to howjmay/wasmtime that referenced this issue Jan 24, 2022
pchickey pushed a commit to pchickey/wasmtime that referenced this issue May 12, 2023
* Rebase on the new wasi-sockets.

This switches to using the wasi-sockets wit files from
WebAssembly/wasi-sockets#16. Many things are still stubbed out with
`todo!()` for now.

* Fix compilation on Windows.
pchickey pushed a commit to pchickey/wasmtime that referenced this issue May 16, 2023
* Rebase on the new wasi-sockets.

This switches to using the wasi-sockets wit files from
WebAssembly/wasi-sockets#16. Many things are still stubbed out with
`todo!()` for now.

* Fix compilation on Windows.
mooori pushed a commit to mooori/wasmtime that referenced this issue Dec 20, 2023
dhil added a commit to dhil/wasmtime that referenced this issue May 22, 2024
This patch adds a basic stack pooling allocator for WasmFX stacks. It is
gated behind a feature flag `wasmfx_pooling_allocator`, which is
disabled by default. By default
stacks are safe, meaning they have a page guard attached. The old unsafe
stacks are gated behind the feature flag `unsafe_wasmfx_stacks`.

In addition, this patch also adds missing WasmFX features to
`wasmtime-c-api` and `wasmtime-c-api-impl`.

Resolves bytecodealliance#91. Resolves bytecodealliance#26.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
wasi:api Issues pertaining to the WASI API, not necessarily specific to Wasmtime.
Projects
None yet
Development

No branches or pull requests

2 participants