Skip to content

Introduce strongly-typed system primitives#1561

Merged
sunfishcode merged 16 commits intobytecodealliance:masterfrom
kubkon:handle-rights
May 7, 2020
Merged

Introduce strongly-typed system primitives#1561
sunfishcode merged 16 commits intobytecodealliance:masterfrom
kubkon:handle-rights

Conversation

@kubkon
Copy link
Member

@kubkon kubkon commented Apr 20, 2020

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 implementing
a subset of Handle methods, rather than all being an enumeration of some
supertype such as OsHandle. To summarise the structs:

  • OsFile represents a regular file, and implements fd-ops
    of Handle trait
  • OsDir represents a directory, and primarily implements path-ops, plus
    readdir and some common fd-ops such as fdstat, etc.
  • Stdio represents a stdio handle, and implements a subset of fd-ops
    such as fdstat and read_ and write_vectored calls
  • OsOther currently represents anything else and implements a set similar
    to that implemented by Stdio

This 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 OsHandle represent an OS-specific
wrapper for a raw OS handle (Unix fd or Windows handle). Also, since OsDir
is tricky across OSes, we also have a supertype of OsHandle called
OsDirHandle which may store a DIR* stream pointer (mainly BSD). Last but not
least, the Filetype and Rights are now computed when the resource is created,
rather than every time we call Handle::get_file_type and Handle::get_rights.
Finally, in order to facilitate the latter, I've converted EntryRights into
HandleRights and pushed them into each Handle implementor.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

wasi Issues pertaining to WASI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants