From c92a247c688f336b1030da088c09d37cc2d34eed Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 9 Mar 2021 13:53:23 -0800 Subject: [PATCH] Populate the wasi-io proposal with very preliminary content. This adds very simple I/O streams and I/O arrays witx definitions, which match read/write and pread/pwrite from wasi-filesystem, as a starting point. --- standard/io/docs.md | 1366 ++++++++++++++++++++++++++++++ standard/io/witx/io_arrays.witx | 49 ++ standard/io/witx/io_streams.witx | 32 + standard/io/witx/typenames.witx | 708 ++++++++++++++++ tools/repo_docs.sh | 5 + 5 files changed, 2160 insertions(+) create mode 100644 standard/io/docs.md create mode 100644 standard/io/witx/io_arrays.witx create mode 100644 standard/io/witx/io_streams.witx create mode 100644 standard/io/witx/typenames.witx diff --git a/standard/io/docs.md b/standard/io/docs.md new file mode 100644 index 0000000..0d256d2 --- /dev/null +++ b/standard/io/docs.md @@ -0,0 +1,1366 @@ +# Types +## `size`: `usize` +An array size. + +Note: This is similar to `size_t` in POSIX. + +Size: 4 + +Alignment: 4 + +## `filesize`: `u64` +Non-negative file size or length of a region within a file. + +Size: 8 + +Alignment: 8 + +## `timestamp`: `u64` +Timestamp in nanoseconds. + +Size: 8 + +Alignment: 8 + +## `clockid`: `Variant` +Identifiers for clocks. + +Size: 4 + +Alignment: 4 + +### Variant cases +- `realtime` +The clock measuring real time. Time value zero corresponds with +1970-01-01T00:00:00Z. + +- `monotonic` +The store-wide monotonic clock, which is defined as a clock measuring +real time, whose value cannot be adjusted and which cannot have negative +clock jumps. The epoch of this clock is undefined. The absolute time +value of this clock therefore has no meaning. + +## `errno`: `Variant` +Error codes returned by functions. +Not all of these error codes are returned by the functions provided by this +API; some are used in higher-level library layers, and others are provided +merely for alignment with POSIX. + +Size: 2 + +Alignment: 2 + +### Variant cases +- `success` +No error occurred. System call completed successfully. + +- `2big` +Argument list too long. + +- `access` +Permission denied. + +- `addrinuse` +Address in use. + +- `addrnotavail` +Address not available. + +- `afnosupport` +Address family not supported. + +- `again` +Resource unavailable, or operation would block. + +- `already` +Connection already in progress. + +- `badf` +Bad file descriptor. + +- `badmsg` +Bad message. + +- `busy` +Device or resource busy. + +- `canceled` +Operation canceled. + +- `child` +No child processes. + +- `connaborted` +Connection aborted. + +- `connrefused` +Connection refused. + +- `connreset` +Connection reset. + +- `deadlk` +Resource deadlock would occur. + +- `destaddrreq` +Destination address required. + +- `dom` +Mathematics argument out of domain of function. + +- `dquot` +Reserved. + +- `exist` +File exists. + +- `fault` +Bad address. + +- `fbig` +File too large. + +- `hostunreach` +Host is unreachable. + +- `idrm` +Identifier removed. + +- `ilseq` +Illegal byte sequence. + +- `inprogress` +Operation in progress. + +- `intr` +Interrupted function. + +- `inval` +Invalid argument. + +- `io` +I/O error. + +- `isconn` +Socket is connected. + +- `isdir` +Is a directory. + +- `loop` +Too many levels of symbolic links. + +- `mfile` +File descriptor value too large. + +- `mlink` +Too many links. + +- `msgsize` +Message too large. + +- `multihop` +Reserved. + +- `nametoolong` +Filename too long. + +- `netdown` +Network is down. + +- `netreset` +Connection aborted by network. + +- `netunreach` +Network unreachable. + +- `nfile` +Too many files open in system. + +- `nobufs` +No buffer space available. + +- `nodev` +No such device. + +- `noent` +No such file or directory. + +- `noexec` +Executable file format error. + +- `nolck` +No locks available. + +- `nolink` +Reserved. + +- `nomem` +Not enough space. + +- `nomsg` +No message of the desired type. + +- `noprotoopt` +Protocol not available. + +- `nospc` +No space left on device. + +- `nosys` +Function not supported. + +- `notconn` +The socket is not connected. + +- `notdir` +Not a directory or a symbolic link to a directory. + +- `notempty` +Directory not empty. + +- `notrecoverable` +State not recoverable. + +- `notsock` +Not a socket. + +- `notsup` +Not supported, or operation not supported on socket. + +- `notty` +Inappropriate I/O control operation. + +- `nxio` +No such device or address. + +- `overflow` +Value too large to be stored in data type. + +- `ownerdead` +Previous owner died. + +- `perm` +Operation not permitted. + +- `pipe` +Broken pipe. + +- `proto` +Protocol error. + +- `protonosupport` +Protocol not supported. + +- `prototype` +Protocol wrong type for socket. + +- `range` +Result too large. + +- `rofs` +Read-only file system. + +- `spipe` +Invalid seek. + +- `srch` +No such process. + +- `stale` +Reserved. + +- `timedout` +Connection timed out. + +- `txtbsy` +Text file busy. + +- `xdev` +Cross-device link. + +- `notcapable` +Extension: Capabilities insufficient. + +## `rights`: `Record` +File descriptor rights, determining which actions may be performed. + +Size: 8 + +Alignment: 8 + +### Record members +- `fd_datasync`: `bool` +The right to invoke `fd_datasync`. +If `path_open` is set, includes the right to invoke +`path_open` with [`fdflags::dsync`](#fdflags.dsync). + +Bit: 0 + +- `fd_read`: `bool` +The right to invoke `fd_read` and `sock_recv`. +If [`rights::fd_seek`](#rights.fd_seek) is set, includes the right to invoke `fd_pread`. + +Bit: 1 + +- `fd_seek`: `bool` +The right to invoke `fd_seek`. This flag implies [`rights::fd_tell`](#rights.fd_tell). + +Bit: 2 + +- `fd_fdstat_set_flags`: `bool` +The right to invoke `fd_fdstat_set_flags`. + +Bit: 3 + +- `fd_sync`: `bool` +The right to invoke `fd_sync`. +If `path_open` is set, includes the right to invoke +`path_open` with [`fdflags::rsync`](#fdflags.rsync) and [`fdflags::dsync`](#fdflags.dsync). + +Bit: 4 + +- `fd_tell`: `bool` +The right to invoke `fd_seek` in such a way that the file offset +remains unaltered (i.e., [`whence::cur`](#whence.cur) with offset zero), or to +invoke `fd_tell`. + +Bit: 5 + +- `fd_write`: `bool` +The right to invoke `fd_write` and `sock_send`. +If [`rights::fd_seek`](#rights.fd_seek) is set, includes the right to invoke `fd_pwrite`. + +Bit: 6 + +- `fd_advise`: `bool` +The right to invoke `fd_advise`. + +Bit: 7 + +- `fd_allocate`: `bool` +The right to invoke `fd_allocate`. + +Bit: 8 + +- `path_create_directory`: `bool` +The right to invoke `path_create_directory`. + +Bit: 9 + +- `path_create_file`: `bool` +If `path_open` is set, the right to invoke `path_open` with [`oflags::create`](#oflags.create). + +Bit: 10 + +- `path_link_source`: `bool` +The right to invoke `path_link` with the file descriptor as the +source directory. + +Bit: 11 + +- `path_link_target`: `bool` +The right to invoke `path_link` with the file descriptor as the +target directory. + +Bit: 12 + +- `path_open`: `bool` +The right to invoke `path_open`. + +Bit: 13 + +- `fd_readdir`: `bool` +The right to invoke `fd_readdir`. + +Bit: 14 + +- `path_readlink`: `bool` +The right to invoke `path_readlink`. + +Bit: 15 + +- `path_rename_source`: `bool` +The right to invoke `path_rename` with the file descriptor as the source directory. + +Bit: 16 + +- `path_rename_target`: `bool` +The right to invoke `path_rename` with the file descriptor as the target directory. + +Bit: 17 + +- `path_filestat_get`: `bool` +The right to invoke `path_filestat_get`. + +Bit: 18 + +- `path_filestat_set_size`: `bool` +The right to change a file's size. +If `path_open` is set, includes the right to invoke `path_open` with [`oflags::trunc`](#oflags.trunc). +Note: there is no function named `path_filestat_set_size`. This follows POSIX design, +which only has `ftruncate` and does not provide `ftruncateat`. +While such function would be desirable from the API design perspective, there are virtually +no use cases for it since no code written for POSIX systems would use it. +Moreover, implementing it would require multiple syscalls, leading to inferior performance. + +Bit: 19 + +- `path_filestat_set_times`: `bool` +The right to invoke `path_filestat_set_times`. + +Bit: 20 + +- `path_permissions_set`: `bool` +The right to invoke `path_permissions_set`. + +Bit: 21 + +- `fd_filestat_get`: `bool` +The right to invoke `fd_filestat_get`. + +Bit: 22 + +- `fd_filestat_set_size`: `bool` +The right to invoke `fd_filestat_set_size`. + +Bit: 23 + +- `fd_filestat_set_times`: `bool` +The right to invoke `fd_filestat_set_times`. + +Bit: 24 + +- `fd_permissions_set`: `bool` +The right to invoke `fd_permissions_set`. + +Bit: 25 + +- `path_symlink`: `bool` +The right to invoke `path_symlink`. + +Bit: 26 + +- `path_remove_directory`: `bool` +The right to invoke `path_remove_directory`. + +Bit: 27 + +- `path_unlink_file`: `bool` +The right to invoke `path_unlink_file`. + +Bit: 28 + +- `poll_fd_readwrite`: `bool` +If [`rights::fd_read`](#rights.fd_read) is set, includes the right to invoke `poll_oneoff` to subscribe to [`eventtype::fd_read`](#eventtype.fd_read). +If [`rights::fd_write`](#rights.fd_write) is set, includes the right to invoke `poll_oneoff` to subscribe to [`eventtype::fd_write`](#eventtype.fd_write). + +Bit: 29 + +- `sock_shutdown`: `bool` +The right to invoke `sock_shutdown`. + +Bit: 30 + +## `fd`: `Handle` +A file descriptor handle. + +Size: 4 + +Alignment: 4 + +### Supertypes +## `iovec`: `Record` +A region of memory for scatter/gather reads. + +Size: 8 + +Alignment: 4 + +### Record members +- `buf`: `Pointer` +The address of the buffer to be filled. + +Offset: 0 + +- `buf_len`: [`size`](#size) +The length of the buffer to be filled. + +Offset: 4 + +## `ciovec`: `Record` +A region of memory for scatter/gather writes. + +Size: 8 + +Alignment: 4 + +### Record members +- `buf`: `ConstPointer` +The address of the buffer to be written. + +Offset: 0 + +- `buf_len`: [`size`](#size) +The length of the buffer to be written. + +Offset: 4 + +## `iovec_array`: `List` + +Size: 8 + +Alignment: 4 + +## `ciovec_array`: `List` + +Size: 8 + +Alignment: 4 + +## `filedelta`: `s64` +Relative offset within a file. + +Size: 8 + +Alignment: 8 + +## `whence`: `Variant` +The position relative to which to set the offset of the file descriptor. + +Size: 1 + +Alignment: 1 + +### Variant cases +- `set` +Seek relative to start-of-file. + +- `cur` +Seek relative to current position. + +- `end` +Seek relative to end-of-file. + +## `dircookie`: `u64` +A reference to the offset of a directory entry. + +Size: 8 + +Alignment: 8 + +### Constants +- `start` + +## `dirnamlen`: `u32` +The type for the [`dirent::d_namlen`](#dirent.d_namlen) field of [`dirent`](#dirent). + +Size: 4 + +Alignment: 4 + +## `inode`: `u64` +File serial number that is unique within its file system. + +Size: 8 + +Alignment: 8 + +## `filetype`: `Variant` +The type of a file descriptor or file. + +Size: 1 + +Alignment: 1 + +### Variant cases +- `unknown` +The type of the file descriptor or file is unknown or is different from any of the other types specified. + +- `block_device` +The file descriptor or file refers to a block device inode. + +- `character_device` +The file descriptor or file refers to a character device inode. + +- `directory` +The file descriptor or file refers to a directory inode. + +- `regular_file` +The file descriptor or file refers to a regular file inode. + +- `socket_dgram` +The file descriptor or file refers to a datagram socket. + +- `socket_stream` +The file descriptor or file refers to a byte-stream socket. + +- `symbolic_link` +The file refers to a symbolic link inode. + +- `fifo` +The file descriptor or file refers to a FIFO. + +## `dirent`: `Record` +A directory entry. + +Size: 24 + +Alignment: 8 + +### Record members +- `d_next`: [`dircookie`](#dircookie) +The offset of the next directory entry stored in this directory. + +Offset: 0 + +- `d_ino`: [`inode`](#inode) +The serial number of the file referred to by this directory entry. + +Offset: 8 + +- `d_type`: [`filetype`](#filetype) +The type of the file referred to by this directory entry. + +Offset: 16 + +- `d_namlen`: [`dirnamlen`](#dirnamlen) +The length of the name of the directory entry. + +Offset: 20 + +## `advice`: `Variant` +File or memory access pattern advisory information. + +Size: 1 + +Alignment: 1 + +### Variant cases +- `normal` +The application has no advice to give on its behavior with respect to the specified data. + +- `sequential` +The application expects to access the specified data sequentially from lower offsets to higher offsets. + +- `random` +The application expects to access the specified data in a random order. + +- `willneed` +The application expects to access the specified data in the near future. + +- `dontneed` +The application expects that it will not access the specified data in the near future. + +- `noreuse` +The application expects to access the specified data once and then not reuse it thereafter. + +## `fdflags`: `Record` +File descriptor flags. + +Size: 2 + +Alignment: 2 + +### Record members +- `append`: `bool` +Append mode: Data written to the file is always appended to the file's end. + +Bit: 0 + +- `dsync`: `bool` +Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + +Bit: 1 + +- `nonblock`: `bool` +Non-blocking mode. + +Bit: 2 + +- `rsync`: `bool` +Synchronized read I/O operations. + +Bit: 3 + +- `sync`: `bool` +Write according to synchronized I/O file integrity completion. In +addition to synchronizing the data stored in the file, the implementation +may also synchronously update the file's metadata. + +Bit: 4 + +## `fdstat`: `Record` +File descriptor attributes. + +Size: 24 + +Alignment: 8 + +### Record members +- `fs_filetype`: [`filetype`](#filetype) +File type. + +Offset: 0 + +- `fs_flags`: [`fdflags`](#fdflags) +File descriptor flags. + +Offset: 2 + +- `fs_rights_base`: [`rights`](#rights) +Rights that apply to this file descriptor. + +Offset: 8 + +- `fs_rights_inheriting`: [`rights`](#rights) +Maximum set of rights that may be installed on new file descriptors that +are created through this file descriptor, e.g., through `path_open`. + +Offset: 16 + +## `device`: `u64` +Identifier for a device containing a file system. Can be used in combination +with [`inode`](#inode) to uniquely identify a file or directory in the filesystem. + +Size: 8 + +Alignment: 8 + +## `fstflags`: `Record` +Which file time attributes to adjust. + +Size: 2 + +Alignment: 2 + +### Record members +- `atim`: `bool` +Adjust the last data access timestamp to the value stored in [`filestat::atim`](#filestat.atim). + +Bit: 0 + +- `atim_now`: `bool` +Adjust the last data access timestamp to the time of clock [`clockid::realtime`](#clockid.realtime). + +Bit: 1 + +- `mtim`: `bool` +Adjust the last data modification timestamp to the value stored in [`filestat::mtim`](#filestat.mtim). + +Bit: 2 + +- `mtim_now`: `bool` +Adjust the last data modification timestamp to the time of clock [`clockid::realtime`](#clockid.realtime). + +Bit: 3 + +## `lookupflags`: `Record` +Flags determining the method of how paths are resolved. + +Size: 4 + +Alignment: 4 + +### Record members +- `symlink_follow`: `bool` +As long as the resolved path corresponds to a symbolic link, it is expanded. + +Bit: 0 + +## `oflags`: `Record` +Open flags used by `path_open`. + +Size: 2 + +Alignment: 2 + +### Record members +- `create`: `bool` +Create file if it does not exist. + +Bit: 0 + +- `directory`: `bool` +Fail if not a directory. + +Bit: 1 + +- `excl`: `bool` +Fail if file already exists. + +Bit: 2 + +- `trunc`: `bool` +Truncate file to size 0. + +Bit: 3 + +## `linkcount`: `u64` +Number of hard links to an inode. + +Size: 8 + +Alignment: 8 + +## `permissions`: `Record` +File permissions. This represents the permissions associated with a +file in a filesystem, and don't fully reflect all the conditions +which determine whether a given WASI program can access the file. + +Size: 1 + +Alignment: 1 + +### Record members +- `read`: `bool` +For files, permission to read the file. +For directories, permission to do `readdir` and access files +within the directory. + +Note: This is similar to the read bit being set on files, and the +read *and* execute bits being set on directories, in POSIX. + +Bit: 0 + +- `write`: `bool` +For files, permission to mutate the file. +For directories, permission to create, remove, and rename items +within the directory. + +Bit: 1 + +- `execute`: `bool` +For files, permission to "execute" the file, using whatever +concept of "executing" the host filesystem has. +This flag is not valid for directories. + +Bit: 2 + +- `private`: `bool` +For filesystems which have a concept of multiple "users", this flag +indicates that the file is only accessible by the effective "user" +that the WASI store uses to access the filesystem, and inaccessible +to other "users". + +Bit: 3 + +## `filestat`: `Record` +File attributes. + +Size: 64 + +Alignment: 8 + +### Record members +- `dev`: [`device`](#device) +Device ID of device containing the file. + +Offset: 0 + +- `ino`: [`inode`](#inode) +File serial number. + +Offset: 8 + +- `filetype`: [`filetype`](#filetype) +File type. + +Offset: 16 + +- `permissions`: [`permissions`](#permissions) +File permissions. + +Offset: 17 + +- `nlink`: [`linkcount`](#linkcount) +Number of hard links to the file. + +Offset: 24 + +- `size`: [`filesize`](#filesize) +For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. + +Offset: 32 + +- `atim`: [`timestamp`](#timestamp) +Last data access timestamp. + +Offset: 40 + +- `mtim`: [`timestamp`](#timestamp) +Last data modification timestamp. + +Offset: 48 + +- `ctim`: [`timestamp`](#timestamp) +Last file status change timestamp. + +Offset: 56 + +## `userdata`: `u64` +User-provided value that may be attached to objects that is retained when +extracted from the implementation. + +Size: 8 + +Alignment: 8 + +## `eventtype`: `Variant` +Type of a subscription to an event or its occurrence. + +Size: 1 + +Alignment: 1 + +### Variant cases +- `clock` +The time value of clock [`subscription_clock::id`](#subscription_clock.id) has +reached timestamp [`subscription_clock::timeout`](#subscription_clock.timeout). + +- `fd_read` +File descriptor [`subscription_fd_readwrite::fd`](#subscription_fd_readwrite.fd) has data +available for reading. This event always triggers for regular files. + +- `fd_write` +File descriptor [`subscription_fd_readwrite::fd`](#subscription_fd_readwrite.fd) has capacity +available for writing. This event always triggers for regular files. + +## `eventrwflags`: `Record` +The state of the file descriptor subscribed to with +[`eventtype::fd_read`](#eventtype.fd_read) or [`eventtype::fd_write`](#eventtype.fd_write). + +Size: 2 + +Alignment: 2 + +### Record members +- `fd_readwrite_hangup`: `bool` +The peer of this socket has closed or disconnected. + +Bit: 0 + +## `event_fd_readwrite`: `Record` +The contents of an [`event`](#event) when type is [`eventtype::fd_read`](#eventtype.fd_read) or +[`eventtype::fd_write`](#eventtype.fd_write). + +Size: 16 + +Alignment: 8 + +### Record members +- `nbytes`: [`filesize`](#filesize) +The number of bytes available for reading or writing. + +Offset: 0 + +- `flags`: [`eventrwflags`](#eventrwflags) +The state of the file descriptor. + +Offset: 8 + +## `event_u`: `Variant` +The contents of an [`event`](#event). + +Size: 24 + +Alignment: 8 + +### Variant Layout +- size: 24 +- align: 8 +- tag_size: 1 +### Variant cases +- `clock` + +- `fd_read`: [`event_fd_readwrite`](#event_fd_readwrite) + +- `fd_write`: [`event_fd_readwrite`](#event_fd_readwrite) + +## `event`: `Record` +An event that occurred. + +Size: 40 + +Alignment: 8 + +### Record members +- `userdata`: [`userdata`](#userdata) +User-provided value that got attached to [`subscription::userdata`](#subscription.userdata). + +Offset: 0 + +- `error`: [`errno`](#errno) +If non-zero, an error that occurred while processing the subscription request. + +Offset: 8 + +- `u`: [`event_u`](#event_u) +The type of the event that occurred, and the contents of the event + +Offset: 16 + +## `subclockflags`: `Record` +Flags determining how to interpret the timestamp provided in +[`subscription_clock::timeout`](#subscription_clock.timeout). + +Size: 2 + +Alignment: 2 + +### Record members +- `subscription_clock_abstime`: `bool` +If set, treat the timestamp provided in +[`subscription_clock::timeout`](#subscription_clock.timeout) as an absolute timestamp of clock +[`subscription_clock::id`](#subscription_clock.id). If clear, treat the timestamp +provided in [`subscription_clock::timeout`](#subscription_clock.timeout) relative to the +current time value of clock [`subscription_clock::id`](#subscription_clock.id). + +Bit: 0 + +## `subscription_clock`: `Record` +The contents of a [`subscription`](#subscription) when type is [`eventtype::clock`](#eventtype.clock). + +Size: 32 + +Alignment: 8 + +### Record members +- `id`: [`clockid`](#clockid) +The clock against which to compare the timestamp. + +Offset: 0 + +- `timeout`: [`timestamp`](#timestamp) +The absolute or relative timestamp. + +Offset: 8 + +- `precision`: [`timestamp`](#timestamp) +The amount of time that the implementation may wait additionally +to coalesce with other events. + +Offset: 16 + +- `flags`: [`subclockflags`](#subclockflags) +Flags specifying whether the timeout is absolute or relative + +Offset: 24 + +## `subscription_fd_readwrite`: `Record` +The contents of a [`subscription`](#subscription) when type is type is +[`eventtype::fd_read`](#eventtype.fd_read) or [`eventtype::fd_write`](#eventtype.fd_write). + +Size: 4 + +Alignment: 4 + +### Record members +- `fd`: [`fd`](#fd) +The file descriptor on which to wait for it to become ready for reading or writing. + +Offset: 0 + +## `subscription_u`: `Variant` +The contents of a [`subscription`](#subscription). + +Size: 40 + +Alignment: 8 + +### Variant Layout +- size: 40 +- align: 8 +- tag_size: 1 +### Variant cases +- `clock`: [`subscription_clock`](#subscription_clock) + +- `fd_read`: [`subscription_fd_readwrite`](#subscription_fd_readwrite) + +- `fd_write`: [`subscription_fd_readwrite`](#subscription_fd_readwrite) + +## `subscription`: `Record` +Subscription to an event. + +Size: 48 + +Alignment: 8 + +### Record members +- `userdata`: [`userdata`](#userdata) +User-provided value that is attached to the subscription in the +implementation and returned through [`event::userdata`](#event.userdata). + +Offset: 0 + +- `u`: [`subscription_u`](#subscription_u) +The type of the event to which to subscribe, and the contents of the subscription. + +Offset: 8 + +## `exitcode`: `u8` +Exit code generated by a program when exiting. + +Size: 1 + +Alignment: 1 + +### Constants +- `success` + +- `failure` + +## `riflags`: `Record` +Flags provided to `sock_recv`. + +Size: 2 + +Alignment: 2 + +### Record members +- `recv_peek`: `bool` +Returns the message without removing it from the socket's receive queue. + +Bit: 0 + +- `recv_waitall`: `bool` +On byte-stream sockets, block until the full amount of data can be returned. + +Bit: 1 + +## `roflags`: `Record` +Flags returned by `sock_recv`. + +Size: 2 + +Alignment: 2 + +### Record members +- `recv_data_truncated`: `bool` +Returned by `sock_recv`: Message data has been truncated. + +Bit: 0 + +## `siflags`: `u16` +Flags provided to `sock_send`. As there are currently no flags +defined, it must be set to zero. + +Size: 2 + +Alignment: 2 + +## `sdflags`: `Record` +Which channels on a socket to shut down. + +Size: 1 + +Alignment: 1 + +### Record members +- `rd`: `bool` +Disables further receive operations. + +Bit: 0 + +- `wr`: `bool` +Disables further send operations. + +Bit: 1 + +## `preopentype`: `Variant` +Identifiers for preopened capabilities. + +Size: 1 + +Alignment: 1 + +### Variant cases +- `dir` +A pre-opened directory. + +## `prestat_dir`: `Record` +The contents of a [`prestat`](#prestat) when its type is [`preopentype::dir`](#preopentype.dir). + +Size: 4 + +Alignment: 4 + +### Record members +- `pr_name_len`: [`size`](#size) +The length of the directory name for use with `fd_prestat_dir_name`. + +Offset: 0 + +## `prestat`: `Variant` +Information about a pre-opened capability. + +Size: 8 + +Alignment: 4 + +### Variant Layout +- size: 8 +- align: 4 +- tag_size: 1 +### Variant cases +- `dir`: [`prestat_dir`](#prestat_dir) +When type is [`preopentype::dir`](#preopentype.dir): + +# Modules +## wasi_ephemeral_io_arrays +### Imports +#### Memory +### Functions + +--- + +#### `advise(fd: fd, offset: filesize, len: filesize, advice: advice) -> Result<(), errno>` +Provide file advisory information on a file descriptor. +Note: This is similar to `posix_fadvise` in POSIX. + +##### Params +- `fd`: [`fd`](#fd) + +- `offset`: [`filesize`](#filesize) +The offset within the file to which the advisory applies. + +- `len`: [`filesize`](#filesize) +The length of the region to which the advisory applies. + +- `advice`: [`advice`](#advice) +The advice. + +##### Results +- `error`: `Result<(), errno>` + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok` + +- `err`: [`errno`](#errno) + + +--- + +#### `pread(fd: fd, iovs: iovec_array, offset: filesize) -> Result` +Read from a file descriptor, without using and updating the file descriptor's offset. +Note: This is similar to `preadv` in Linux (and other Unix-es). + +##### Params +- `fd`: [`fd`](#fd) + +- `iovs`: [`iovec_array`](#iovec_array) +List of scatter/gather vectors in which to store data. + +- `offset`: [`filesize`](#filesize) +The offset within the file at which to read. + +##### Results +- `error`: `Result` +The number of bytes read. + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`size`](#size) + +- `err`: [`errno`](#errno) + + +--- + +#### `pwrite(fd: fd, iovs: ciovec_array, offset: filesize) -> Result` +Write to a file descriptor, without using and updating the file descriptor's offset. +Note: This is similar to `pwritev` in Linux (and other Unix-es). + +Like Linux (and other Unix-es), any calls of [`pwrite`](#pwrite) (and other +functions to read or write) for a regular file by other threads in the +WASI process should not be interleaved while [`pwrite`](#pwrite) is executed. + +##### Params +- `fd`: [`fd`](#fd) + +- `iovs`: [`ciovec_array`](#ciovec_array) +List of scatter/gather vectors from which to retrieve data. + +- `offset`: [`filesize`](#filesize) +The offset within the file at which to write. + +##### Results +- `error`: `Result` +The number of bytes written. + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`size`](#size) + +- `err`: [`errno`](#errno) + +## wasi_ephemeral_io_streams +### Imports +#### Memory +### Functions + +--- + +#### `read(fd: fd, iovs: iovec_array) -> Result` +Read from a file descriptor. +Note: This is similar to `readv` in POSIX. + +##### Params +- `fd`: [`fd`](#fd) + +- `iovs`: [`iovec_array`](#iovec_array) +List of scatter/gather vectors to which to store data. + +##### Results +- `error`: `Result` +The number of bytes read. + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`size`](#size) + +- `err`: [`errno`](#errno) + + +--- + +#### `write(fd: fd, iovs: ciovec_array) -> Result` +Write to a file descriptor. +Note: This is similar to `writev` in POSIX. + +Like POSIX, any calls of [`write`](#write) (and other functions to read or write) +for a regular file by other threads in the WASI process should not be +interleaved while [`write`](#write) is executed. + +##### Params +- `fd`: [`fd`](#fd) + +- `iovs`: [`ciovec_array`](#ciovec_array) +List of scatter/gather vectors from which to retrieve data. + +##### Results +- `error`: `Result` +The number of bytes written. + +###### Variant Layout +- size: 8 +- align: 4 +- tag_size: 4 +###### Variant cases +- `ok`: [`size`](#size) + +- `err`: [`errno`](#errno) + diff --git a/standard/io/witx/io_arrays.witx b/standard/io/witx/io_arrays.witx new file mode 100644 index 0000000..f6439c8 --- /dev/null +++ b/standard/io/witx/io_arrays.witx @@ -0,0 +1,49 @@ +;; WASI I/O Arrays. + +(use "typenames.witx") + +(module $wasi_ephemeral_io_arrays + ;;; Linear memory to be accessed by WASI functions that need it. + (import "memory" (memory)) + + ;;; Provide file advisory information on a file descriptor. + ;;; Note: This is similar to `posix_fadvise` in POSIX. + (@interface func (export "advise") + (param $fd $fd) + ;;; The offset within the file to which the advisory applies. + (param $offset $filesize) + ;;; The length of the region to which the advisory applies. + (param $len $filesize) + ;;; The advice. + (param $advice $advice) + (result $error (expected (error $errno))) + ) + + ;;; Read from a file descriptor, without using and updating the file descriptor's offset. + ;;; Note: This is similar to `preadv` in Linux (and other Unix-es). + (@interface func (export "pread") + (param $fd $fd) + ;;; List of scatter/gather vectors in which to store data. + (param $iovs $iovec_array) + ;;; The offset within the file at which to read. + (param $offset $filesize) + ;;; The number of bytes read. + (result $error (expected $size (error $errno))) + ) + + ;;; Write to a file descriptor, without using and updating the file descriptor's offset. + ;;; Note: This is similar to `pwritev` in Linux (and other Unix-es). + ;;; + ;;; Like Linux (and other Unix-es), any calls of `pwrite` (and other + ;;; functions to read or write) for a regular file by other threads in the + ;;; WASI process should not be interleaved while `pwrite` is executed. + (@interface func (export "pwrite") + (param $fd $fd) + ;;; List of scatter/gather vectors from which to retrieve data. + (param $iovs $ciovec_array) + ;;; The offset within the file at which to write. + (param $offset $filesize) + ;;; The number of bytes written. + (result $error (expected $size (error $errno))) + ) +) diff --git a/standard/io/witx/io_streams.witx b/standard/io/witx/io_streams.witx new file mode 100644 index 0000000..b762917 --- /dev/null +++ b/standard/io/witx/io_streams.witx @@ -0,0 +1,32 @@ +;; WASI I/O Streams. + +(use "typenames.witx") + +(module $wasi_ephemeral_io_streams + ;;; Linear memory to be accessed by WASI functions that need it. + (import "memory" (memory)) + + ;;; Read from a file descriptor. + ;;; Note: This is similar to `readv` in POSIX. + (@interface func (export "read") + (param $fd $fd) + ;;; List of scatter/gather vectors to which to store data. + (param $iovs $iovec_array) + ;;; The number of bytes read. + (result $error (expected $size (error $errno))) + ) + + ;;; Write to a file descriptor. + ;;; Note: This is similar to `writev` in POSIX. + ;;; + ;;; Like POSIX, any calls of `write` (and other functions to read or write) + ;;; for a regular file by other threads in the WASI process should not be + ;;; interleaved while `write` is executed. + (@interface func (export "write") + (param $fd $fd) + ;;; List of scatter/gather vectors from which to retrieve data. + (param $iovs $ciovec_array) + ;;; The number of bytes written. + (result $error (expected $size (error $errno))) + ) +) diff --git a/standard/io/witx/typenames.witx b/standard/io/witx/typenames.witx new file mode 100644 index 0000000..bbd6489 --- /dev/null +++ b/standard/io/witx/typenames.witx @@ -0,0 +1,708 @@ +;; Type names used by low-level WASI interfaces. +;; +;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). +;; +;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md) +;; for an explanation of what that means. + +;;; An array size. +;;; +;;; Note: This is similar to `size_t` in POSIX. +(typename $size (@witx usize)) + +;;; Non-negative file size or length of a region within a file. +(typename $filesize u64) + +;;; Timestamp in nanoseconds. +(typename $timestamp u64) + +;;; Identifiers for clocks. +(typename $clockid + (enum (@witx tag u32) + ;;; The clock measuring real time. Time value zero corresponds with + ;;; 1970-01-01T00:00:00Z. + $realtime + ;;; The store-wide monotonic clock, which is defined as a clock measuring + ;;; real time, whose value cannot be adjusted and which cannot have negative + ;;; clock jumps. The epoch of this clock is undefined. The absolute time + ;;; value of this clock therefore has no meaning. + $monotonic + ) +) + +;;; Error codes returned by functions. +;;; Not all of these error codes are returned by the functions provided by this +;;; API; some are used in higher-level library layers, and others are provided +;;; merely for alignment with POSIX. +(typename $errno + (enum (@witx tag u16) + ;;; No error occurred. System call completed successfully. + $success + ;;; Argument list too long. + $2big + ;;; Permission denied. + $access + ;;; Address in use. + $addrinuse + ;;; Address not available. + $addrnotavail + ;;; Address family not supported. + $afnosupport + ;;; Resource unavailable, or operation would block. + $again + ;;; Connection already in progress. + $already + ;;; Bad file descriptor. + $badf + ;;; Bad message. + $badmsg + ;;; Device or resource busy. + $busy + ;;; Operation canceled. + $canceled + ;;; No child processes. + $child + ;;; Connection aborted. + $connaborted + ;;; Connection refused. + $connrefused + ;;; Connection reset. + $connreset + ;;; Resource deadlock would occur. + $deadlk + ;;; Destination address required. + $destaddrreq + ;;; Mathematics argument out of domain of function. + $dom + ;;; Reserved. + $dquot + ;;; File exists. + $exist + ;;; Bad address. + $fault + ;;; File too large. + $fbig + ;;; Host is unreachable. + $hostunreach + ;;; Identifier removed. + $idrm + ;;; Illegal byte sequence. + $ilseq + ;;; Operation in progress. + $inprogress + ;;; Interrupted function. + $intr + ;;; Invalid argument. + $inval + ;;; I/O error. + $io + ;;; Socket is connected. + $isconn + ;;; Is a directory. + $isdir + ;;; Too many levels of symbolic links. + $loop + ;;; File descriptor value too large. + $mfile + ;;; Too many links. + $mlink + ;;; Message too large. + $msgsize + ;;; Reserved. + $multihop + ;;; Filename too long. + $nametoolong + ;;; Network is down. + $netdown + ;;; Connection aborted by network. + $netreset + ;;; Network unreachable. + $netunreach + ;;; Too many files open in system. + $nfile + ;;; No buffer space available. + $nobufs + ;;; No such device. + $nodev + ;;; No such file or directory. + $noent + ;;; Executable file format error. + $noexec + ;;; No locks available. + $nolck + ;;; Reserved. + $nolink + ;;; Not enough space. + $nomem + ;;; No message of the desired type. + $nomsg + ;;; Protocol not available. + $noprotoopt + ;;; No space left on device. + $nospc + ;;; Function not supported. + $nosys + ;;; The socket is not connected. + $notconn + ;;; Not a directory or a symbolic link to a directory. + $notdir + ;;; Directory not empty. + $notempty + ;;; State not recoverable. + $notrecoverable + ;;; Not a socket. + $notsock + ;;; Not supported, or operation not supported on socket. + $notsup + ;;; Inappropriate I/O control operation. + $notty + ;;; No such device or address. + $nxio + ;;; Value too large to be stored in data type. + $overflow + ;;; Previous owner died. + $ownerdead + ;;; Operation not permitted. + $perm + ;;; Broken pipe. + $pipe + ;;; Protocol error. + $proto + ;;; Protocol not supported. + $protonosupport + ;;; Protocol wrong type for socket. + $prototype + ;;; Result too large. + $range + ;;; Read-only file system. + $rofs + ;;; Invalid seek. + $spipe + ;;; No such process. + $srch + ;;; Reserved. + $stale + ;;; Connection timed out. + $timedout + ;;; Text file busy. + $txtbsy + ;;; Cross-device link. + $xdev + ;;; Extension: Capabilities insufficient. + $notcapable + ) +) + +;;; File descriptor rights, determining which actions may be performed. +(typename $rights + (flags (@witx repr u64) + ;;; The right to invoke `fd_datasync`. + ;; + ;;; If `path_open` is set, includes the right to invoke + ;;; `path_open` with `fdflags::dsync`. + $fd_datasync + ;;; The right to invoke `fd_read` and `sock_recv`. + ;; + ;;; If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. + $fd_read + ;;; The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. + $fd_seek + ;;; The right to invoke `fd_fdstat_set_flags`. + $fd_fdstat_set_flags + ;;; The right to invoke `fd_sync`. + ;; + ;;; If `path_open` is set, includes the right to invoke + ;;; `path_open` with `fdflags::rsync` and `fdflags::dsync`. + $fd_sync + ;;; The right to invoke `fd_seek` in such a way that the file offset + ;;; remains unaltered (i.e., `whence::cur` with offset zero), or to + ;;; invoke `fd_tell`. + $fd_tell + ;;; The right to invoke `fd_write` and `sock_send`. + ;;; If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. + $fd_write + ;;; The right to invoke `fd_advise`. + $fd_advise + ;;; The right to invoke `fd_allocate`. + $fd_allocate + ;;; The right to invoke `path_create_directory`. + $path_create_directory + ;;; If `path_open` is set, the right to invoke `path_open` with `oflags::create`. + $path_create_file + ;;; The right to invoke `path_link` with the file descriptor as the + ;;; source directory. + $path_link_source + ;;; The right to invoke `path_link` with the file descriptor as the + ;;; target directory. + $path_link_target + ;;; The right to invoke `path_open`. + $path_open + ;;; The right to invoke `fd_readdir`. + $fd_readdir + ;;; The right to invoke `path_readlink`. + $path_readlink + ;;; The right to invoke `path_rename` with the file descriptor as the source directory. + $path_rename_source + ;;; The right to invoke `path_rename` with the file descriptor as the target directory. + $path_rename_target + ;;; The right to invoke `path_filestat_get`. + $path_filestat_get + ;;; The right to change a file's size. + ;;; If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. + ;;; Note: there is no function named `path_filestat_set_size`. This follows POSIX design, + ;;; which only has `ftruncate` and does not provide `ftruncateat`. + ;;; While such function would be desirable from the API design perspective, there are virtually + ;;; no use cases for it since no code written for POSIX systems would use it. + ;;; Moreover, implementing it would require multiple syscalls, leading to inferior performance. + $path_filestat_set_size + ;;; The right to invoke `path_filestat_set_times`. + $path_filestat_set_times + ;;; The right to invoke `path_permissions_set`. + $path_permissions_set + ;;; The right to invoke `fd_filestat_get`. + $fd_filestat_get + ;;; The right to invoke `fd_filestat_set_size`. + $fd_filestat_set_size + ;;; The right to invoke `fd_filestat_set_times`. + $fd_filestat_set_times + ;;; The right to invoke `fd_permissions_set`. + $fd_permissions_set + ;;; The right to invoke `path_symlink`. + $path_symlink + ;;; The right to invoke `path_remove_directory`. + $path_remove_directory + ;;; The right to invoke `path_unlink_file`. + $path_unlink_file + ;;; If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. + ;;; If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. + $poll_fd_readwrite + ;;; The right to invoke `sock_shutdown`. + $sock_shutdown + ) +) + +;;; A file descriptor handle. +(typename $fd (handle)) + +;;; A region of memory for scatter/gather reads. +(typename $iovec + (record + ;;; The address of the buffer to be filled. + (field $buf (@witx pointer u8)) + ;;; The length of the buffer to be filled. + (field $buf_len $size) + ) +) + +;;; A region of memory for scatter/gather writes. +(typename $ciovec + (record + ;;; The address of the buffer to be written. + (field $buf (@witx const_pointer u8)) + ;;; The length of the buffer to be written. + (field $buf_len $size) + ) +) + +(typename $iovec_array (list $iovec)) +(typename $ciovec_array (list $ciovec)) + +;;; Relative offset within a file. +(typename $filedelta s64) + +;;; The position relative to which to set the offset of the file descriptor. +(typename $whence + (enum (@witx tag u8) + ;;; Seek relative to start-of-file. + $set + ;;; Seek relative to current position. + $cur + ;;; Seek relative to end-of-file. + $end + ) +) + +;;; A reference to the offset of a directory entry. +(typename $dircookie u64) + +;;; In an `fd_readdir` call, this value signifies the start of the directory. +(@witx const $dircookie $start 0) + +;;; The type for the `dirent::d_namlen` field of `dirent`. +(typename $dirnamlen u32) + +;;; File serial number that is unique within its file system. +(typename $inode u64) + +;;; The type of a file descriptor or file. +(typename $filetype + (enum (@witx tag u8) + ;;; The type of the file descriptor or file is unknown or is different from any of the other types specified. + $unknown + ;;; The file descriptor or file refers to a block device inode. + $block_device + ;;; The file descriptor or file refers to a character device inode. + $character_device + ;;; The file descriptor or file refers to a directory inode. + $directory + ;;; The file descriptor or file refers to a regular file inode. + $regular_file + ;;; The file descriptor or file refers to a datagram socket. + $socket_dgram + ;;; The file descriptor or file refers to a byte-stream socket. + $socket_stream + ;;; The file refers to a symbolic link inode. + $symbolic_link + ;;; The file descriptor or file refers to a FIFO. + $fifo + ) +) + +;;; A directory entry. +(typename $dirent + (record + ;;; The offset of the next directory entry stored in this directory. + (field $d_next $dircookie) + ;;; The serial number of the file referred to by this directory entry. + (field $d_ino $inode) + ;;; The type of the file referred to by this directory entry. + (field $d_type $filetype) + ;;; The length of the name of the directory entry. + (field $d_namlen $dirnamlen) + ) +) + +;;; File or memory access pattern advisory information. +(typename $advice + (enum (@witx tag u8) + ;;; The application has no advice to give on its behavior with respect to the specified data. + $normal + ;;; The application expects to access the specified data sequentially from lower offsets to higher offsets. + $sequential + ;;; The application expects to access the specified data in a random order. + $random + ;;; The application expects to access the specified data in the near future. + $willneed + ;;; The application expects that it will not access the specified data in the near future. + $dontneed + ;;; The application expects to access the specified data once and then not reuse it thereafter. + $noreuse + ) +) + +;;; File descriptor flags. +(typename $fdflags + (flags (@witx repr u16) + ;;; Append mode: Data written to the file is always appended to the file's end. + $append + ;;; Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + $dsync + ;;; Non-blocking mode. + $nonblock + ;;; Synchronized read I/O operations. + $rsync + ;;; Write according to synchronized I/O file integrity completion. In + ;;; addition to synchronizing the data stored in the file, the implementation + ;;; may also synchronously update the file's metadata. + $sync + ) +) + +;;; File descriptor attributes. +(typename $fdstat + (record + ;;; File type. + (field $fs_filetype $filetype) + ;;; File descriptor flags. + (field $fs_flags $fdflags) + ;;; Rights that apply to this file descriptor. + (field $fs_rights_base $rights) + ;;; Maximum set of rights that may be installed on new file descriptors that + ;;; are created through this file descriptor, e.g., through `path_open`. + (field $fs_rights_inheriting $rights) + ) +) + +;;; Identifier for a device containing a file system. Can be used in combination +;;; with `inode` to uniquely identify a file or directory in the filesystem. +(typename $device u64) + +;;; Which file time attributes to adjust. +(typename $fstflags + (flags (@witx repr u16) + ;;; Adjust the last data access timestamp to the value stored in `filestat::atim`. + $atim + ;;; Adjust the last data access timestamp to the time of clock `clockid::realtime`. + $atim_now + ;;; Adjust the last data modification timestamp to the value stored in `filestat::mtim`. + $mtim + ;;; Adjust the last data modification timestamp to the time of clock `clockid::realtime`. + $mtim_now + ) +) + +;;; Flags determining the method of how paths are resolved. +(typename $lookupflags + (flags (@witx repr u32) + ;;; As long as the resolved path corresponds to a symbolic link, it is expanded. + $symlink_follow + ) +) + +;;; Open flags used by `path_open`. +(typename $oflags + (flags (@witx repr u16) + ;;; Create file if it does not exist. + $create + ;;; Fail if not a directory. + $directory + ;;; Fail if file already exists. + $excl + ;;; Truncate file to size 0. + $trunc + ) +) + +;;; Number of hard links to an inode. +(typename $linkcount u64) + +;;; File permissions. This represents the permissions associated with a +;;; file in a filesystem, and don't fully reflect all the conditions +;;; which determine whether a given WASI program can access the file. +(typename $permissions + (flags (@witx repr u8) + ;;; For files, permission to read the file. + ;;; For directories, permission to do `readdir` and access files + ;;; within the directory. + ;;; + ;;; Note: This is similar to the read bit being set on files, and the + ;;; read *and* execute bits being set on directories, in POSIX. + $read + + ;;; For files, permission to mutate the file. + ;;; For directories, permission to create, remove, and rename items + ;;; within the directory. + $write + + ;;; For files, permission to "execute" the file, using whatever + ;;; concept of "executing" the host filesystem has. + ;;; This flag is not valid for directories. + $execute + + ;;; For filesystems which have a concept of multiple "users", this flag + ;;; indicates that the file is only accessible by the effective "user" + ;;; that the WASI store uses to access the filesystem, and inaccessible + ;;; to other "users". + $private + ) +) + +;;; File attributes. +(typename $filestat + (record + ;;; Device ID of device containing the file. + (field $dev $device) + ;;; File serial number. + (field $ino $inode) + ;;; File type. + (field $filetype $filetype) + ;;; File permissions. + (field $permissions $permissions) + ;;; Number of hard links to the file. + (field $nlink $linkcount) + ;;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. + (field $size $filesize) + ;;; Last data access timestamp. + (field $atim $timestamp) + ;;; Last data modification timestamp. + (field $mtim $timestamp) + ;;; Last file status change timestamp. + (field $ctim $timestamp) + ) +) + +;;; User-provided value that may be attached to objects that is retained when +;;; extracted from the implementation. +(typename $userdata u64) + +;;; Type of a subscription to an event or its occurrence. +(typename $eventtype + (enum (@witx tag u8) + ;;; The time value of clock `subscription_clock::id` has + ;;; reached timestamp `subscription_clock::timeout`. + $clock + ;;; File descriptor `subscription_fd_readwrite::fd` has data + ;;; available for reading. This event always triggers for regular files. + $fd_read + ;;; File descriptor `subscription_fd_readwrite::fd` has capacity + ;;; available for writing. This event always triggers for regular files. + $fd_write + ) +) + +;;; The state of the file descriptor subscribed to with +;;; `eventtype::fd_read` or `eventtype::fd_write`. +(typename $eventrwflags + (flags (@witx repr u16) + ;;; The peer of this socket has closed or disconnected. + $fd_readwrite_hangup + ) +) + +;;; The contents of an `event` when type is `eventtype::fd_read` or +;;; `eventtype::fd_write`. +(typename $event_fd_readwrite + (record + ;;; The number of bytes available for reading or writing. + (field $nbytes $filesize) + ;;; The state of the file descriptor. + (field $flags $eventrwflags) + ) +) + +;;; The contents of an `event`. +(typename $event_u + (variant (@witx tag $eventtype) + (case $fd_read $event_fd_readwrite) + (case $fd_write $event_fd_readwrite) + (case $clock) + ) +) + +;;; An event that occurred. +(typename $event + (record + ;;; User-provided value that got attached to `subscription::userdata`. + (field $userdata $userdata) + ;;; If non-zero, an error that occurred while processing the subscription request. + (field $error $errno) + ;;; The type of the event that occurred, and the contents of the event + (field $u $event_u) + ) +) + +;;; Flags determining how to interpret the timestamp provided in +;;; `subscription_clock::timeout`. +(typename $subclockflags + (flags (@witx repr u16) + ;;; If set, treat the timestamp provided in + ;;; `subscription_clock::timeout` as an absolute timestamp of clock + ;;; `subscription_clock::id`. If clear, treat the timestamp + ;;; provided in `subscription_clock::timeout` relative to the + ;;; current time value of clock `subscription_clock::id`. + $subscription_clock_abstime + ) +) + +;;; The contents of a `subscription` when type is `eventtype::clock`. +(typename $subscription_clock + (record + ;;; The clock against which to compare the timestamp. + (field $id $clockid) + ;;; The absolute or relative timestamp. + (field $timeout $timestamp) + ;;; The amount of time that the implementation may wait additionally + ;;; to coalesce with other events. + (field $precision $timestamp) + ;;; Flags specifying whether the timeout is absolute or relative + (field $flags $subclockflags) + ) +) + +;;; The contents of a `subscription` when type is type is +;;; `eventtype::fd_read` or `eventtype::fd_write`. +(typename $subscription_fd_readwrite + (record + ;;; The file descriptor on which to wait for it to become ready for reading or writing. + (field $fd $fd) + ) +) + +;;; The contents of a `subscription`. +(typename $subscription_u + (union (@witx tag $eventtype) + $subscription_clock + $subscription_fd_readwrite + $subscription_fd_readwrite + ) +) + +;;; Subscription to an event. +(typename $subscription + (record + ;;; User-provided value that is attached to the subscription in the + ;;; implementation and returned through `event::userdata`. + (field $userdata $userdata) + ;;; The type of the event to which to subscribe, and the contents of the subscription. + (field $u $subscription_u) + ) +) + +;;; Exit code generated by a program when exiting. +(typename $exitcode u8) + +;;; Indicate the program exited successfully. +;;; +;;; Note: This is similar to `EXIT_SUCCESS` in POSIX. +(@witx const $exitcode $success 0) + +;;; Indicate the program exited unsuccessfully. +;;; +;;; Note: This is similar to `EXIT_FAILURE` in POSIX. +(@witx const $exitcode $failure 1) + +;;; Flags provided to `sock_recv`. +(typename $riflags + (flags (@witx repr u16) + ;;; Returns the message without removing it from the socket's receive queue. + $recv_peek + ;;; On byte-stream sockets, block until the full amount of data can be returned. + $recv_waitall + ) +) + +;;; Flags returned by `sock_recv`. +(typename $roflags + (flags (@witx repr u16) + ;;; Returned by `sock_recv`: Message data has been truncated. + $recv_data_truncated + ) +) + +;;; Flags provided to `sock_send`. As there are currently no flags +;;; defined, it must be set to zero. +(typename $siflags u16) + +;;; Which channels on a socket to shut down. +(typename $sdflags + (flags (@witx repr u8) + ;;; Disables further receive operations. + $rd + ;;; Disables further send operations. + $wr + ) +) + +;;; Identifiers for preopened capabilities. +(typename $preopentype + (enum (@witx tag u8) + ;;; A pre-opened directory. + $dir + ) +) + +;;; The contents of a `prestat` when its type is `preopentype::dir`. +(typename $prestat_dir + (record + ;;; The length of the directory name for use with `fd_prestat_dir_name`. + (field $pr_name_len $size) + ) +) + +;;; Information about a pre-opened capability. +(typename $prestat + (union (@witx tag $preopentype) + ;;; When type is `preopentype::dir`: + $prestat_dir + ) +) diff --git a/tools/repo_docs.sh b/tools/repo_docs.sh index e0187bc..76d1462 100755 --- a/tools/repo_docs.sh +++ b/tools/repo_docs.sh @@ -15,3 +15,8 @@ cargo run -p witx-cli -- docs $1 \ ../../phases/ephemeral/witx/wasi_ephemeral_sched.witx \ ../../phases/ephemeral/witx/wasi_ephemeral_sock.witx \ --output ../../phases/ephemeral/docs.md + +for dir in ../../standard/*/witx; do + cargo run -p witx-cli -- docs $1 "$dir"/*.witx \ + --output "$dir"/../docs.md +done