add descriptor table for mapping fds to handles#464
Merged
sunfishcode merged 4 commits intoWebAssembly:mainfrom Feb 27, 2024
Merged
add descriptor table for mapping fds to handles#464sunfishcode merged 4 commits intoWebAssembly:mainfrom
sunfishcode merged 4 commits intoWebAssembly:mainfrom
Conversation
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 <github@davebakker.io> Signed-off-by: Joel Dice <joel.dice@fermyon.com>
yamt
reviewed
Jan 23, 2024
sbc100
reviewed
Feb 12, 2024
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 <joel.dice@fermyon.com>
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 <joel.dice@fermyon.com>
Signed-off-by: Joel Dice <joel.dice@fermyon.com>
Contributor
Author
|
Any remaining concerns about this PR? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This introduces
descriptor_table.handdescriptor_table.c, providing a global hashtable for trackingwasi-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.hto thelibc-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.