Introduce strongly-typed system primitives#1561
Merged
sunfishcode merged 16 commits intobytecodealliance:masterfrom May 7, 2020
Merged
Introduce strongly-typed system primitives#1561sunfishcode merged 16 commits intobytecodealliance:masterfrom
sunfishcode merged 16 commits intobytecodealliance:masterfrom
Conversation
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 commit does a lot of reshuffling and even some more. It introduces
strongly-typed system primitives which are:
OsFile,OsDir,Stdio,and
OsOther. Those primitives are separate structs now, each implementinga subset of
Handlemethods, rather than all being an enumeration of somesupertype such as
OsHandle. To summarise the structs:OsFilerepresents a regular file, and implements fd-opsof
HandletraitOsDirrepresents a directory, and primarily implements path-ops, plusreaddirand some common fd-ops such asfdstat, etc.Stdiorepresents a stdio handle, and implements a subset of fd-opssuch as
fdstatandread_andwrite_vectoredcallsOsOthercurrently represents anything else and implements a set similarto that implemented by
StdioThis commit is effectively an experiment and an excercise into better
understanding what's going on for each OS resource/type under-the-hood.
It's meant to give us some intuition in order to move on with the idea
of having strongly-typed handles in WASI both in the syscall impl as well
as at the libc level.
Some more minor changes include making
OsHandlerepresent an OS-specificwrapper for a raw OS handle (Unix fd or Windows handle). Also, since
OsDiris tricky across OSes, we also have a supertype of
OsHandlecalledOsDirHandlewhich may store aDIR*stream pointer (mainly BSD). Last but notleast, the
FiletypeandRightsare now computed when the resource is created,rather than every time we call
Handle::get_file_typeandHandle::get_rights.Finally, in order to facilitate the latter, I've converted
EntryRightsintoHandleRightsand pushed them into eachHandleimplementor.