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

add descriptor table for mapping fds to handles #464

Merged
merged 4 commits into from
Feb 27, 2024

Conversation

dicej
Copy link
Contributor

@dicej dicej commented Jan 11, 2024

This introduces descriptor_table.h and descriptor_table.c, providing a global hashtable for tracking wasi-libc-managed file descriptors.

WASI Preview 2 has no notion of file descriptors and instead uses unforgeable resource handles (which are currently represented as integers at the ABI level, used as indices into per-component tables managed by the host). Moreover, there's not necessarily a one-to-one correspondence between POSIX file descriptors and resource handles (e.g. a TCP connection may require separate handles for reading, writing, and polling the same connection). We use this table to map each POSIX descriptor to a set of one or more handles and any extra state which libc needs to track.

Note that we've added descriptor_table.h to the
libc-bottom-half/headers/public/wasi directory, making it part of the public API. The intention is to give applications access to the mapping, enabling them to convert descriptors to handles and vice-versa should they need to interoperate with both libc and WASI directly.

This introduces `descriptor_table.h` and `descriptor_table.c`, providing a
global hashtable for tracking `wasi-libc`-managed file descriptors.

WASI Preview 2 has no notion of file descriptors and instead uses unforgeable
resource handles.  Moreover, there's not necessarily a one-to-one correspondence
between POSIX file descriptors and resource handles (e.g. a TCP connection may
require separate handles for reading, writing, and polling the same connection).
We use this table to map each POSIX descriptor to a set of one or more handles
and any extra state which libc needs to track.

Note that we've added `descriptor_table.h` to the
libc-bottom-half/headers/public/wasi directory, making it part of the public
API.  The intention is to give applications access to the mapping, enabling them
to convert descriptors to handles and vice-versa should they need to
interoperate with both libc and WASI directly.

Co-authored-by: Dave Bakker <[email protected]>
Signed-off-by: Joel Dice <[email protected]>
The C standard doesn't allow empty structs.  Clang doesn't currently complain,
but we might as well stick to the spec in case it becomes more strict in the
future.

Signed-off-by: Joel Dice <[email protected]>
We're not yet ready to commit to making this API public, so we'll make it
private for now.

I've also expanded a comment in descriptor_table.c to explain the current ABI
for resource handles.

Signed-off-by: Joel Dice <[email protected]>
@dicej
Copy link
Contributor Author

dicej commented Feb 27, 2024

Any remaining concerns about this PR?

@sunfishcode sunfishcode merged commit 09683b3 into WebAssembly:main Feb 27, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants