From 383385700a13acc2bc4ad2ac7e78a445d9053d21 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 14 Aug 2019 22:42:24 -0700 Subject: [PATCH 01/26] A wasi_unstable description based on module types. This sketches out a description of the current wasi_unstable API, using a syntax which anticipates the "module types" syntax [recently proposed to the CG](https://github.com/WebAssembly/meetings/blob/master/2019/CG-08-06.md#discuss-new-proposal-that-introduces-types-for-modules-and-instances-and-text-format-thereof-as-initially-discussed-in-design1289), though it does use a few extensions which can be easily lowered, and which mostly anticipate the [Interface Types](https://github.com/WebAssembly/webidl-bindings/issues/47#issuecomment-519717553) proposal. This is derived from [the WatIDL proposal](https://github.com/WebAssembly/WASI/pull/64), though it differs in a few ways: - It doesn't yet do anything special for capabilities, for now. File descriptors are just integers, for now. But the idea is that we could add OCAP concepts later. - It uses a new `(flags ...)` construct in place of structs of Bool fields, to describe flags values. This allows us to explicitly declare the underlying wasm type for flags values. - Types used by the API are declared outside of the moduletype, because we're using wat syntax as much as possible, and there, `(type ...)` inside a module declares an entry in the type section, which isn't what's intended here. The extensions to module types are: - It uses `string`, `array`, and `{s,u}{8,16,32,64}` types, which are expected to be provided in some form by the Interface Types proposal. For now though, they can all be lowered in straightforward ways, by assuming that `string` is always just UTF-8. - It adds `typename` declarations, which can name any wasm type, and of the extra types mentioned in the previous item, or `struct`, `enum`, or `flags`. - It declares functions with multiple return values, which for now will need to be lowered to output (pointer) parameters. --- design/wasi_unstable/wasi_unstable.wati | 1206 +++++++++++++++++++++++ 1 file changed, 1206 insertions(+) create mode 100644 design/wasi_unstable/wasi_unstable.wati diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati new file mode 100644 index 00000000..1dd06791 --- /dev/null +++ b/design/wasi_unstable/wasi_unstable.wati @@ -0,0 +1,1206 @@ +;; The wasi_unstable module type. +;; +;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). + +(typename $size_t u32) +(typename $string_array (array string)) + +;; Non-negative file size or length of a region within a file. +(typename $filesize_t u64) + +;; Timestamp in nanoseconds. +(typename $timestamp_t u64) + +;; Identifiers for clocks. +(typename $clockid_t + (enum u32 + ;; 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. + $CLOCK_MONOTONIC + ;; The CPU-time clock associated with the current process. + $CLOCK_PROCESS_CPUTIME_ID + ;; The clock measuring real time. Time value zero corresponds with + ;; 1970-01-01T00:00:00Z. + $CLOCK_REALTIME + ;; The CPU-time clock associated with the current thread. + $CLOCK_THREAD_CPUTIME_ID + ) +) + +;; 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_t + (enum u16 + ;; No error occurred. System call completed successfully. + $ESUCCESS + ;; Argument list too long. + $E2BIG + ;; Permission denied. + $EACCES + ;; Address in use. + $EADDRINUSE + ;; Address not available. + $EADDRNOTAVAIL + ;; Address family not supported. + $EAFNOSUPPORT + ;; Resource unavailable, or operation would block. + $EAGAIN + ;; Connection already in progress. + $EALREADY + ;; Bad file descriptor. + $EBADF + ;; Bad message. + $EBADMSG + ;; Device or resource busy. + $EBUSY + ;; Operation canceled. + $ECANCELED + ;; No child processes. + $ECHILD + ;; Connection aborted. + $ECONNABORTED + ;; Connection refused. + $ECONNREFUSED + ;; Connection reset. + $ECONNRESET + ;; Resource deadlock would occur. + $EDEADLK + ;; Destination address required. + $EDESTADDRREQ + ;; Mathematics argument out of domain of function. + $EDOM + ;; Reserved. + $EDQUOT + ;; File exists. + $EEXIST + ;; Bad address. + $EFAULT + ;; File too large. + $EFBIG + ;; Host is unreachable. + $EHOSTUNREACH + ;; Identifier removed. + $EIDRM + ;; Illegal byte sequence. + $EILSEQ + ;; Operation in progress. + $EINPROGRESS + ;; Interrupted function. + $EINTR + ;; Invalid argument. + $EINVAL + ;; I/O error. + $EIO + ;; Socket is connected. + $EISCONN + ;; Is a directory. + $EISDIR + ;; Too many levels of symbolic links. + $ELOOP + ;; File descriptor value too large. + $EMFILE + ;; Too many links. + $EMLINK + ;; Message too large. + $EMSGSIZE + ;; Reserved. + $EMULTIHOP + ;; Filename too long. + $ENAMETOOLONG + ;; Network is down. + $ENETDOWN + ;; Connection aborted by network. + $ENETRESET + ;; Network unreachable. + $ENETUNREACH + ;; Too many files open in system. + $ENFILE + ;; No buffer space available. + $ENOBUFS + ;; No such device. + $ENODEV + ;; No such file or directory. + $ENOENT + ;; Executable file format error. + $ENOEXEC + ;; No locks available. + $ENOLCK + ;; Reserved. + $ENOLINK + ;; Not enough space. + $ENOMEM + ;; No message of the desired type. + $ENOMSG + ;; Protocol not available. + $ENOPROTOOPT + ;; No space left on device. + $ENOSPC + ;; Function not supported. + $ENOSYS + ;; The socket is not connected. + $ENOTCONN + ;; Not a directory or a symbolic link to a directory. + $ENOTDIR + ;; Directory not empty. + $ENOTEMPTY + ;; State not recoverable. + $ENOTRECOVERABLE + ;; Not a socket. + $ENOTSOCK + ;; Not supported, or operation not supported on socket. + $ENOTSUP + ;; Inappropriate I/O control operation. + $ENOTTY + ;; No such device or address. + $ENXIO + ;; Value too large to be stored in data type. + $EOVERFLOW + ;; Previous owner died. + $EOWNERDEAD + ;; Operation not permitted. + $EPERM + ;; Broken pipe. + $EPIPE + ;; Protocol error. + $EPROTO + ;; Protocol not supported. + $EPROTONOSUPPORT + ;; Protocol wrong type for socket. + $EPROTOTYPE + ;; Result too large. + $ERANGE + ;; Read-only file system. + $EROFS + ;; Invalid seek. + $ESPIPE + ;; No such process. + $ESRCH + ;; Reserved. + $ESTALE + ;; Connection timed out. + $ETIMEDOUT + ;; Text file busy. + $ETXTBSY + ;; Cross-device link. + $EXDEV + ;; Extension: Capabilities insufficient. + $ENOTCAPABLE + ) +) + +;; File descriptor rights, determining which actions may be performed. +(typename $rights_t + (flags u64 + ;; The right to invoke __wasi_fd_datasync(). + ;; + ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke + ;` __wasi_path_open() with __WASI_FDFLAG_DSYNC. + (flag $RIGHT_FD_DATASYNC) + ;; The right to invoke __wasi_fd_read() and __wasi_sock_recv(). + ;; + ;; If __WASI_RIGHT_FD_SEEK is set, includes the right to invoke + ;; __wasi_fd_pread(). + (flag $RIGHT_FD_READ) + ;; The right to invoke __wasi_fd_seek(). This flag implies __WASI_RIGHT_FD_TELL. + (flag $RIGHT_FD_SEEK) + ;; The right to invoke __wasi_fd_fdstat_set_flags(). + (flag $RIGHT_FD_FDSTAT_SET_FLAGS) + ;; The right to invoke __wasi_fd_sync(). + ;; + ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke + ;; __wasi_path_open() with __WASI_FDFLAG_RSYNC and __WASI_FDFLAG_DSYNC. + (flag $RIGHT_FD_SYNC) + ;; The right to invoke __wasi_fd_seek() in such a way that the file offset + ;; remains unaltered (i.e., __WASI_WHENCE_CUR with offset zero), or to + ;; invoke __wasi_fd_tell(). + (flag $RIGHT_FD_TELL) + ;; The right to invoke __wasi_fd_write() and __wasi_sock_send(). + ;; If __WASI_RIGHT_FD_SEEK is set, includes the right to invoke __wasi_fd_pwrite(). + (flag $RIGHT_FD_WRITE) + ;; The right to invoke __wasi_fd_advise(). + (flag $RIGHT_FD_ADVISE) + ;; The right to invoke __wasi_fd_allocate(). + (flag $RIGHT_FD_ALLOCATE) + ;; The right to invoke __wasi_path_create_directory(). + (flag $RIGHT_PATH_CREATE_DIRECTORY) + ;; If __WASI_RIGHT_PATH_OPEN is set, the right to invoke __wasi_path_open() with __WASI_O_CREAT. + (flag $RIGHT_PATH_CREATE_FILE) + ;; The right to invoke __wasi_path_link() with the file descriptor as the source directory. + (flag $RIGHT_PATH_LINK_SOURCE) + ;; The right to invoke __wasi_path_link() with the file descriptor as the target directory. + (flag $RIGHT_PATH_LINK_TARGET) + ;; The right to invoke __wasi_path_open(). + (flag $RIGHT_PATH_OPEN) + ;; The right to invoke __wasi_fd_readdir(). + (flag $RIGHT_FD_READDIR) + ;; The right to invoke __wasi_path_readlink(). + (flag $RIGHT_PATH_READLINK) + ;; The right to invoke __wasi_path_rename() with the file descriptor as the source directory. + (flag $RIGHT_PATH_RENAME_SOURCE) + ;; The right to invoke __wasi_path_rename() with the file descriptor as the target directory. + (flag $RIGHT_PATH_RENAME_TARGET) + ;; The right to invoke __wasi_path_filestat_get(). + (flag $RIGHT_PATH_FILESTAT_GET) + ;; The right to change a file's size (there is no __wasi_path_filestat_set_size()). + ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke __wasi_path_open() with __WASI_O_TRUNC. + (flag $RIGHT_PATH_FILESTAT_SET_SIZE) + ;; The right to invoke __wasi_path_filestat_set_times(). + (flag $RIGHT_PATH_FILESTAT_SET_TIMES) + ;; The right to invoke __wasi_fd_filestat_get(). + (flag $RIGHT_FD_FILESTAT_GET) + ;; The right to invoke __wasi_fd_filestat_set_size(). + (flag $RIGHT_FD_FILESTAT_SET_SIZE) + ;; The right to invoke __wasi_fd_filestat_set_times(). + (flag $RIGHT_FD_FILESTAT_SET_TIMES) + ;; The right to invoke __wasi_path_symlink(). + (flag $RIGHT_PATH_SYMLINK) + ;; The right to invoke __wasi_path_unlink_file(). + (flag $RIGHT_PATH_UNLINK_FILE) + ;; The right to invoke __wasi_path_remove_directory(). + (flag $RIGHT_PATH_REMOVE_DIRECTORY) + ;; If __WASI_RIGHT_FD_READ is set, includes the right to invoke __wasi_poll_oneoff() to subscribe to __WASI_EVENTTYPE_FD_READ. + ;; If __WASI_RIGHT_FD_WRITE is set, includes the right to invoke __wasi_poll_oneoff() to subscribe to __WASI_EVENTTYPE_FD_WRITE. + (flag $RIGHT_POLL_FD_READWRITE) + ;; The right to invoke __wasi_sock_shutdown(). + (flag $RIGHT_SOCK_SHUTDOWN) + ) +) + +;; a file descriptor index +(typename $fd_t u32) + +(typename $iovec_t_array (array $iovec_t)) +(typename $ciovec_t_array (array $ciovec_t)) + +;; A region of memory for scatter/gather reads. +(typename $iovec_t + (struct + ;; The address and length of the buffer to be filled. + (field $buf data) + (field $buf_len data) + ) +) + +;; A region of memory for scatter/gather writes. +(typename $ciovec_t + (struct + ;; The address and length of the buffer to be written. + (field $buf data) + (field $buf_len data) + ) +) + +;; Relative offset within a file. +(typename $filedelta_t s64) + +;; The position relative to which to set the offset of the file descriptor. +(typename $whence_t + (enum u8 + ;; Seek relative to current position. + $WHENCE_CUR + ;; Seek relative to end-of-file. + $WHENCE_END + ;; Seek relative to start-of-file. + $WHENCE_SET + ) +) + +;; A reference to the offset of a directory entry. +(typename $dircookie_t u64) + +;; The type for the $d_namelen field of $dirent_t. +(typename $dirnamlen_t u32) + +;; A directory entry. +(typename $dirent_t + (struct + ;; The offset of the next directory entry stored in this directory. + (field $d_next $dircookie_t) + ;; The serial number of the file referred to by this directory entry. + (field $d_ino $inode_t) + ;; The length of the name of the directory entry. + (field $d_namlen $dirnamelen_t) + ;; The type of the file referred to by this directory entry. + (field $d_type $filetype_t) + ) +) + +;; File or memory access pattern advisory information. +(typename $advice_t + (enum u8 + ;; The application expects that it will not access the specified data in the near future. + $ADVICE_DONTNEED + ;; The application expects to access the specified data once and then not reuse it thereafter. + $ADVICE_NOREUSE + ;; The application has no advice to give on its behavior with respect to the specified data. + $ADVICE_NORMAL + ;; The application expects to access the specified data in a random order. + $ADVICE_RANDOM + ;; The application expects to access the specified data sequentially from lower offsets to higher offsets. + $ADVICE_SEQUENTIAL + ;; The application expects to access the specified data in the near future. + $ADVICE_WILLNEED + ) +) + +;; File descriptor flags. +(typename $fdflags_t + (flags u16 + ;; Append mode: Data written to the file is always appended to the file's end. + (flag $FDFLAG_APPEND) + ;; Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. + (flag $FDFLAG_DSYNC) + ;; Non-blocking mode. + (flag $FDFLAG_NONBLOCK) + ;; Synchronized read I/O operations. + (flag $FDFLAG_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. + (flag $FDFLAG_SYNC) + ) +) + +;; File descriptor attributes. +(typename $fdstat_t + (struct + ;; File type. + (field $fs_filetype $filetype_t) + ;; File descriptor flags. + (field $fs_flags $fdflags_t) + ;; Rights that apply to this file descriptor. + (field $fs_rights_base $rights_t) + ;; Maximum set of rights that may be installed on new file descriptors that + ;; are created through this file descriptor, e.g., through + ;; __wasi_path_open(). + (field $fs_rights_inheriting $rights_t) + ) +) + +;; Identifier for a device containing a file system. Can be used in combination +;; with __wasi_inode_t to uniquely identify a file or directory in the +;; filesystem. +(typename $device_t u64) + +;; The type of a file descriptor or file. +(typename $filetype_t + (enum u8 + ;; The type of the file descriptor or file is unknown or is different from any of the other types specified. + $FILETYPE_UNKNOWN + ;; The file descriptor or file refers to a block device inode. + $FILETYPE_BLOCK_DEVICE + ;; The file descriptor or file refers to a character device inode. + $FILETYPE_CHARACTER_DEVICE + ;; The file descriptor or file refers to a directory inode. + $FILETYPE_DIRECTORY + ;; The file descriptor or file refers to a regular file inode. + $FILETYPE_REGULAR_FILE + ;; The file descriptor or file refers to a datagram socket. + $FILETYPE_SOCKET_DGRAM + ;; The file descriptor or file refers to a byte-stream socket. + $FILETYPE_SOCKET_STREAM + ;; The file refers to a symbolic link inode. + $FILETYPE_SYMBOLIC_LINK + ) +) + +;; Which file time attributes to adjust. +(typename $fstflags_t + (flags u16 + ;; Adjust the last data access timestamp to the value stored in __wasi_filestat_t::st_atim. + (flag $FILESTAT_SET_ATIM) + ;; Adjust the last data access timestamp to the time of clock __WASI_CLOCK_REALTIME. + (flag $FILESTAT_SET_ATIM_NOW) + ;; Adjust the last data modification timestamp to the value stored in __wasi_filestat_t::st_mtim. + (flag $FILESTAT_SET_MTIM) + ;; Adjust the last data modification timestamp to the time of clock __WASI_CLOCK_REALTIME. + (flag $FILESTAT_SET_MTIM_NOW) + ) +) + +;; File serial number that is unique within its file system. +(typename $inode_t u64) + +;; Flags determining the method of how paths are resolved. +(typename $lookupflags_t + (flags u32 + ;; As long as the resolved path corresponds to a symbolic link, it is expanded. + (flag $LOOKUP_SYMLINK_FOLLOW) + ) +) + +;; Open flags used by __wasi_path_open(). +(typename $oflags_t + (flags u16 + ;; Create file if it does not exist. + (flag $O_CREAT) + ;; Fail if not a directory. + (flag $O_DIRECTORY) + ;; Fail if file already exists. + (flag $O_EXCL) + ;; Truncate file to size 0. + (flag $O_TRUNC) + ) +) + +;; Number of hard links to an inode. +(typename $linkcount_t u32) + +;; File attributes. +(typename $filestat_t + (struct + ;; Device ID of device containing the file. + (field $st_dev $device_t) + ;; File serial number. + (field $st_ino $inode_t) + ;; File type. + (field $st_filetype $filetype_t) + ;; Number of hard links to the file. + (field $st_nlink $linkcount_t) + ;; For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. + (field $st_size $filesize_t) + ;; Last data access timestamp. + (field $st_atim $timestamp_t) + ;; Last data modification timestamp. + (field $st_mtim $timestamp_t) + ;; Last file status change timestamp. + (field $st_ctim $timestamp_t) + ) +) + +;; User-provided value that may be attached to objects that is retained when extracted from the implementation. +(typename $userdata_t u64) + +;; An event that occurred. +(typename $event_t + (struct + ;; User-provided value that got attached to __wasi_subscription_t::userdata. + (field $userdata $userdata_t) + ;; If non-zero, an error that occurred while processing the subscription request. + (field $error $errno_t) + ;; The type of the event that occurred. + (field $type $eventtype_t) + (field $u + (typename union + ;; When type is __WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE: + (field $fd_readwrite + (typename stuct + ;; The number of bytes available for reading or writing. + (field $nbytes $filesize_t) + ;; The state of the file descriptor. + (field $flags $eventrwflags_t) + ) + ) + (field $else Null) + ) + ) + ) +) + +;; The state of the file descriptor subscribed to with __WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE. +(typename $eventrwflags_t + (flags u16 + ;; The peer of this socket has closed or disconnected. + (flag $EVENT_FD_READWRITE_HANGUP) + ) +) + +;; Type of a subscription to an event or its occurrence. +(typename $eventtype_t + (flags u8 + ;; The time value of clock __wasi_subscription_t::u.clock.clock_id has reached timestamp __wasi_subscription_t::u.clock.timeout. + (flag $EVENTTYPE_CLOCK) + ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has data available for reading. This event always triggers for regular files. + (flag $EVENTTYPE_FD_READ) + ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has capacity available for writing. This event always triggers for regular files. + (flag $EVENTTYPE_FD_WRITE) + ) +) + +;; Flags determining how to interpret the timestamp provided in __wasi_subscription_t::u.clock.timeout. +(typename $subclockflags_t + (flags u16 + ;; If set, treat the timestamp provided in + ;; __wasi_subscription_t::u.clock.timeout as an absolute timestamp of clock + ;; __wasi_subscription_t::u.clock.clock_id. If clear, treat the timestamp + ;; provided in __wasi_subscription_t::u.clock.timeout relative to the + ;; current time value of clock __wasi_subscription_t::u.clock.clock_id. + (flag $SUBSCRIPTION_CLOCK_ABSTIME) + ) +) + +;; Subscription to an event. +(typename $subscription_t + (struct + ;; User-provided value that is attached to the subscription in the implementation and returned through __wasi_event_t::userdata. + (field $userdata $userdata_t) + ;; The type of the event to which to subscribe. + (field $type $eventtype_t) + (field + (type + (union + ;; When type is __WASI_EVENTTYPE_CLOCK + (field $clock + (typename + (struct + ;; The user-defined unique identifier of the clock. + (field $identifier $userdata_t) + ;; The clock against which to compare the timestamp. + (field $clock_id $clockid_t) + ;; The absolute or relative timestamp. + (field $timeout $timestamp_t) + ;; The amount of time that the implementation may wait additionally to coalesce with other events. + ;; Flags specifying whether the timeout is absolute or relative + (field $precision $timestamp_t) + ) + ) + ) + ;; When type is __WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE: + (field $fd_readwrite + (type + (struct + ;; The file descriptor on which to wait for it to become ready for reading or writing. + (field $file_descriptor $fd_t) + ) + ) + ) + ) + ) + ) + ) +) + +;; Exit code generated by a process when exiting. +(typename $exitcode_t u32) + +;; Signal condition. +(typename $signal_t + (enum u8 + ;; Process abort signal. + ;; Action: Terminates the process. + $SIGABRT + ;; Alarm clock. + ;; Action: Terminates the process. + $SIGALRM + ;; Access to an undefined portion of a memory object. + ;; Action: Terminates the process. + $SIGBUS + ;; Child process terminated, stopped, or continued. + ;; Action: Ignored. + $SIGCHLD + ;; Continue executing, if stopped. + ;; Action: Continues executing, if stopped. + $SIGCONT + ;; Erroneous arithmetic operation. + ;; Action: Terminates the process. + $SIGFPE + ;; Hangup. + ;; Action: Terminates the process. + $SIGHUP + ;; Illegal instruction. + ;; Action: Terminates the process. + $SIGILL + ;; Terminate interrupt signal. + ;; Action: Terminates the process. + $SIGINT + ;; Kill. + ;; Action: Terminates the process. + $SIGKILL + ;; Write on a pipe with no one to read it. + ;; Action: Ignored. + $SIGPIPE + ;; Terminal quit signal. + ;; Action: Terminates the process. + $SIGQUIT + ;; Invalid memory reference. + ;; Action: Terminates the process. + $SIGSEGV + ;; Stop executing. + ;; Action: Stops executing. + $SIGSTOP + ;; Bad system call. + ;; Action: Terminates the process. + $SIGSYS + ;; Termination signal. + ;; Action: Terminates the process. + $SIGTERM + ;; Trace/breakpoint trap. + ;; Action: Terminates the process. + $SIGTRAP + ;; Terminal stop signal. + ;; Action: Stops executing. + $SIGTSTP + ;; Background process attempting read. + ;; Action: Stops executing. + $SIGTTIN + ;; Background process attempting write. + ;; Action: Stops executing. + $SIGTTOU + ;; High bandwidth data is available at a socket. + ;; Action: Ignored. + $SIGURG + ;; User-defined signal 1. + ;; Action: Terminates the process. + $SIGUSR1 + ;; User-defined signal 2. + ;; Action: Terminates the process. + $SIGUSR2 + ;; Virtual timer expired. + ;; Action: Terminates the process. + $SIGVTALRM + ;; CPU time limit exceeded. + ;; Action: Terminates the process. + $SIGXCPU + ;; File size limit exceeded. + ;; Action: Terminates the process. + $SIGXFSZ + ) +) + +;; Flags provided to __wasi_sock_recv(). +(typename $riflags_t + (flags u16 + ;; Returns the message without removing it from the socket's receive queue. + (flag $SOCK_RECV_PEEK) + ;; On byte-stream sockets, block until the full amount of data can be returned. + (flag $SOCK_RECV_WAITALL) + ) +) + +;; Flags returned by __wasi_sock_recv(). +(typename $roflags_t + (flags u16 + ;; Returned by __wasi_sock_recv(): Message data has been truncated. + (flag $SOCK_RECV_DATA_TRUNCATED) + ) +) + +;; Flags provided to __wasi_sock_send(). As there are currently no flags defined, it must be set to zero. +(typename $siflags_t u16) + +;; Which channels on a socket to shut down. +(typename $sdflags_t + (flags u8 + ;; Disables further receive operations. + (flag $SHUT_RD) + ;; Disables further send operations. + (flag $SHUT_WR) + ) +) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; +;; The wasi_unstable moduletype. +;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +(moduletype $wasi_unstable + ;; Linear memory used by the program. + (import "memory" (memory)) + + ;; The program entry point. + (import "_start" (func)) + + ;; Read command-line argument data. + ;; The size of the array should match that returned by `wasi_args_sizes_get()` + (func (export "args_get") + (result $error $errno_t) + (result $argv $string_array) + ) + ;; Return command-line argument data sizes. + (func (export "args_sizes_get") + (result $error $errno_t) + ;; The number of arguments. + (result $argc $size_t) + ;; The size of the argument string data. + (result $argv_buf_size $size_t) + ) + + ;; Read environment variable data. + ;; The sizes of the buffers should match that returned by `environ.sizes_get()`. + (func (export "environ_get") + (result $error $errno_t) + (result $argv $string_array) + ) + ;; Return command-line argument data sizes. + (func (export "environ_sizes_get") + ;; The number of arguments. + (result $argc $size_t) + ;; The size of the argument string data. + (result $argv_buf_size $size_t) + ) + + ;; Return the resolution of a clock. + ;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL` + ;; Note: This is similar to `clock_getres` in POSIX. + (func (export "clock_res_get") + (result $error $errno_t) + ;; The clock for which to return the resolution. + (param $clock_id $clockid_t) + ;; The resolution of the clock. + (result $resolution $timestamp_t) + ) + ;; Return the time value of a clock. + ;; Note: This is similar to `clock_gettime` in POSIX. + (func (export "clock_time_get") + ;; The clock for which to return the time. + (param $clock_id $clockid_t) + ;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value. + (param $precision $timestamp_t) + (result $error $errno_t) + ;; The time value of the clock. + (result $time $timestamp_t) + ) + + ;; Provide file advisory information on a file descriptor. + ;; Note: This is similar to `posix_fadvise` in POSIX. + (func (export "fd_advise") + (param $self $fd_t) + (param $offset $filesize_t) ;; The offset within the file to which the advisory applies. + (param $len $filesize_t) ;; The length of the region to which the advisory applies. + (param $advice $advice_t) ;; The advice. + (result $error $errno_t) + ) + + ;; Force the allocation of space in a file. + ;; Note: This is similar to `posix_fallocate` in POSIX. + (func (export "fd_allocate") + (param $self $fd_t) + ;; The offset at which to start the allocation. + (param $offset $filesize_t) + ;; The length of the area that is allocated. + (param $len $filesize_t) + (result $error $errno_t) + ) + + ;; Close a file descriptor. + ;; Note: This is similar to `close` in POSIX. + (func (export "fd_close") + (param $self $fd_t) + (result $error $errno_t) + ) + + ;; Synchronize the data of a file to disk. + ;; Note: This is similar to `fdatasync` in POSIX. + (func (export "fd_datasync") + (param $self $fd_t) + (result $error $errno_t) + ) + + ;; Get the attributes of a file descriptor. + ;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. + (func (export "fd_fdstat_get") + (param $self $fd_t) + (result $error $errno_t) + ;; The buffer where the file descriptor's attributes are stored. + (result $fdstat_t) + ) + + ;; Adjust the flags associated with a file descriptor. + ;; Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. + (func (export "fd_fdstat_set_flags") + (param $self $fd_t) + ;; The desired values of the file descriptor flags. + (param $flags $fdflags) + (result $error $errno_t) + ) + + ;; Adjust the rights associated with a file descriptor. + ;; This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights + (func (export "fd_fdstat_set_rights") + (param $self $fd_t) + ;; The desired rights of the file descriptor. + (param $fs_rights_base $rights_t) + (param $fs_rights_inheriting $rights_t) + (result $error $errno_t) + ) + + ;; Return the attributes of an open file. + (func (export "fd_filestat_get") + (param $self $fd_t) + (result $error $errno_t) + ;; The buffer where the file's attributes are stored. + (result $fs_rights_base $rights_t) + ) + + ;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. + ;; Note: This is similar to `ftruncate` in POSIX. + (func (export "fd_filestat_set_size") + (param $self $fd_t) + ;; The desired file size. + (param $st_size $filesize_t) + (result $error $errno_t) + ) + + ;; Adjust the timestamps of an open file or directory. + ;; Note: This is similar to `futimens` in POSIX. + (func (export "fd_filestat_set_times") + (param $self $fd_t) + ;; The desired values of the data access timestamp. + (param $st_atim $timestamp_t) + ;; The desired values of the data modification timestamp. + (param $st_mtim $timestamp_t) + ;; A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags_t) + (result $error $errno_t) + ) + + ;; Read from a file descriptor, without using and updating the file descriptor's offset. + ;; Note: This is similar to `preadv` in POSIX. + (func (export "fd_pread") + (param $self $fd_t) + ;; List of scatter/gather vectors in which to store data. + (param $iovs $iovec_t_array) + ;; The offset within the file at which to read. + (param $offset $filesize_t) + (result $error $errno_t) + ;; The number of bytes read. + (result $nread $size_t) + ) + + ;; Return a description of the given preopened file descriptor. + (func (export "fd_prestat_get") + (param $self $fd_t) + (result $error $errno_t) + ;; The buffer where the description is stored. + (result $buf $prestat_t) + ) + + ;; Return a description of the given preopened file descriptor. + (func (export "fd_prestat_dir_name") + (param $self $fd_t) + ;; A buffer into which to write the preopened directory name. + (param $path string) + (result $error $errno_t) + ) + + ;; Write to a file descriptor, without using and updating the file descriptor's offset. + ;; Note: This is similar to `pwritev` in POSIX. + (func (export "fd_pwrite") + (param $self $fd_t) + ;; List of scatter/gather vectors from which to retrieve data. + (param $iovs $iovec_t_array) + ;; The offset within the file at which to write. + (param $offset $filesize_t) + (result $error $errno_t) + ;; The number of bytes written. + (result $nwritten $size_t) + ) + + ;; Read from a file descriptor. + ;; Note: This is similar to `readv` in POSIX. + (func (export "fd_read") + (param $self $fd_t) + ;; List of scatter/gather vectors to which to store data. + (param $iovs $iovec_t_array) + (result $error $errno_t) + ;; The number of bytes read. + (result $nread $size_t) + ) + + ;; Read directory entries from a directory. + ;; When successful, the contents of the output buffer consist of a sequence of + ;; directory entries. Each directory entry consists of a dirent_t object, + ;; followed by dirent_t::d_namlen bytes holding the name of the directory + ;; entry. + ;; + ;; This function fills the output buffer as much as possible, potentially + ;; truncating the last directory entry. This allows the caller to grow its + ;; read buffer size in case it's too small to fit a single large directory + ;; entry, or skip the oversized directory entry. + (func (export "fd_readdir") + (param $self $fd_t) + ;; The buffer where directory entries are stored + (param $buf data) + ;; The location within the directory to start reading + (param $cookie $dircookie_t) + (result $error $errno_t) + ;; The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. + (result $bufused $size_t) + ) + + ;; Atomically replace a file descriptor by renumbering another file descriptor. + ;; Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like dup2(). This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time. + ;; This function provides a way to atomically renumber file descriptors, which would disappear if dup2() were to be removed entirely. + (func (export "fd_renumber") + (param $self $fd_t) + ;; The file descriptor to overwrite. + (param $to $fd_t) + (result $error $errno_t) + ) + + ;; Move the offset of a file descriptor. + ;; Note: This is similar to `lseek` in POSIX. + (func (export "fd_seek") + (param $self $fd_t) + ;; The number of bytes to move. + (param $offset $filedelta_t) + ;; The base from which the offset is relative. + (param $whence $whence_t) + (result $error $errno_t) + ;; The new offset of the file descriptor, relative to the start of the file. + (result $newoffset $filesize_t) + ) + + ;; Synchronize the data and metadata of a file to disk. + ;; Note: This is similar to `fsync` in POSIX. + (func (export "fd_sync") + (param $self $fd_t) + (result $error $errno_t) + ) + + ;; Return the current offset of a file descriptor. + ;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. + (func (export "fd_tell") + (param $self $fd_t) + (result $error $errno_t) + ;; The current offset of the file descriptor, relative to the start of the file. + (result $offset $filesize_t) + ) + + ;; Write to a file descriptor. + ;; Note: This is similar to `writev` in POSIX. + (func (export "fd_write") + (param $self $fd_t) + ;; List of scatter/gather vectors from which to retrieve data. + (param $iovs $iovec_t_array) + (result $error $errno_t) + ;; The number of bytes written. + (result $nwritten $size_t) + ) + + ;; Create a directory. + ;; Note: This is similar to `mkdirat` in POSIX. + (func (export "path_create_directory") + (param $self $fd_t) + ;; The path at which to create the directory. + (param $path string) + (result $error $errno_t) + ) + + ;; Return the attributes of a file or directory. + ;; Note: This is similar to `stat` in POSIX. + (func (export "path_filestat_get") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $flags $lookupflags_t) + ;; The path of the file or directory to inspect. + (param $path string) + (result $error $errno_t) + ;; The buffer where the file's attributes are stored. + (result $buf $filestat_t) + ) + + ;; Adjust the timestamps of a file or directory. + ;; Note: This is similar to `utimensat` in POSIX. + (func (export "path_filestat_set_times") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $flags $lookupflags_t) + ;; The path of the file or directory to operate on. + (param $path string) + ;; The desired values of the data access timestamp. + (param $st_atim $timestamp_t) + ;; The desired values of the data modification timestamp. + (param $st_mtim $timestamp_t) + ;; A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags_t) + (result $error $errno_t) + ) + + ;; Create a hard link. + ;; Note: This is similar to `linkat` in POSIX. + (func (export "path_link") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $old_flags $lookupflags_t) + ;; The source path from which to link. + (param $old_path string) + ;; The working directory at which the resolution of the new path starts. + (param $new_fd $path) + ;; The destination path at which to create the hard link. + (param $new_path string) + (result $error $errno_t) + ) + + ;; Open a file or directory. + ;; + ;; The returned file descriptor is not guaranteed to be the lowest-numbered + ;; file descriptor not currently open; it is randomized to prevent + ;; applications from depending on making assumptions about indexes, since this + ;; is error-prone in multi-threaded contexts. The returned file descriptor is + ;; guaranteed to be less than 231. + ;; + ;; Note: This is similar to `openat` in POSIX. + (func (export "path_open") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $dirflags $lookupflags_t) + ;; The relative path of the file or directory to open, relative to the + ;; `dirfd` directory. + (param $path string) + ;; The method by which to open the file. + (param $o_flags $oflags_t) + ;; The initial rights of the newly created file descriptor. The + ;; implementation is allowed to return a file descriptor with fewer rights + ;; than specified, if and only if those rights do not apply to the type of + ;; file being opened. + ;; + ;; The base rights are rights that will apply to operations using the file + ;; descriptor itself, while the inheriting rights are rights that apply to + ;; file descriptors derived from it. + (param $fs_rights_base $rights_t) + (param $fs_rights_inherting $rights_t) + (result $error $errno_t) + ;; The file descriptor of the file that has been opened. + (result $opened_fd $fd_t) + ) + + ;; Read the contents of a symbolic link. + ;; Note: This is similar to `readlinkat` in POSIX. + (func (export "path_readlink") + (param $self $fd_t) + ;; The path of the symbolic link from which to read. + (param $path) + ;; The buffer to which to write the contents of the symbolic link. + (param $buf string) + (result $error $errno_t) + ;; The number of bytes placed in the buffer. + (result $bufused $size_t) + ) + + ;; Remove a directory. + ;; Return `__WASI_ENOTEMPTY` if the directory is not empty. + ;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + (func (export "path_remove_directory") + (param $self $fd_t) + ;; The path to a directory to remove. + (param $path string) + (result $error $errno_t) + ) + + ;; Rename a file or directory. + ;; Note: This is similar to `renameat` in POSIX. + (func (export "path_rename") + (param $self $fd_t) + ;; The source path of the file or directory to rename. + (param $old_path string) + ;; The working directory at which the resolution of the new path starts. + (param $new_fd $fd) + ;; The destination path to which to rename the file or directory. + (param $new_path string) + (result $error $errno_t) + ) + + ;; Create a symbolic link. + ;; Note: This is similar to `symlinkat` in POSIX. + (func (export "path_symlink") + (param $self $fd_t) + ;; The contents of the symbolic link. + (param $old_path string) + ;; The destination path at which to create the symbolic link. + (param $new_path string) + (result $error $errno_t) + ) + + + ;; Unlink a file. + ;; Return __WASI_EISDIR if the path refers to a directory. + ;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. + (func (export "path_unlink_file") + (param $self $fd_t) + ;; The path to a file to unlink. + (param $path string) + (result $error $errno_t) + ) + + ;; Concurrently poll for the occurrence of a set of events. + (func (export "poll_oneoff") + ;; The events to which to subscribe. + (param $in $subscription_t) + ;; The events that have occurred. + (param $out $event_t) + ;; Both the number of subscriptions and events. + (param $nsubscriptions $size_t) + (result $error $errno_t) + ;; The number of events stored. + (result $nevents $size_t) + ) + + ;; Terminate the process normally. An exit code of 0 indicates successful + ;; termination of the program. The meanings of other values is dependent on + ;; the environment. + (func (export "proc_exit") + ;; The exit code returned by the process. + (param $rval $exitcode_t) + ) + + ;; Send a signal to the process of the calling thread. + ;; Note: This is similar to `raise` in POSIX. + (func (export "proc_raise") + ;; The signal condition to trigger. + (param $sig $signal_t) + (result $error $errno_t) + ) + + ;; Temporarily yield execution of the calling thread. + ;; Note: This is similar to `sched_yield` in POSIX. + (func (export "proc_sched_yield") + (result $error $errno_t) + ) + + ;; Write high-quality random data into a buffer. + ;; This function blocks when the implementation is unable to immediately + ;; provide sufficient high-quality random data. + ;; This function may execute slowly, so when large mounts of random data are + ;; required, it's advisable to use this function to seed a pseudo-random + ;; number generator, rather than to provide the random data directly. + (func (export "random_get") + ;; The buffer to fill with random data. + (param $buf data) + (result $error $errno_t) + ) + + ;; Receive a message from a socket. + ;; Note: This is similar to `recv` in POSIX, though it also supports reading + ;; the data into multiple buffers in the manner of `readv`. + (func (export "sock_recv") + (param $self $fd_t) + ;; List of scatter/gather vectors to which to store data. + (param $ri_data $iovec_t_array) + ;; Message flags. + (param $ri_flags $riflags_t) + (result $error $errno_t) + ;; Number of bytes stored in ri_data. + (result $ro_datalen $size_t) + ;; Message flags. + (result $ro_flags $roflags_t) + ) + + ;; Send a message on a socket. + ;; Note: This is similar to `send` in POSIX, though it also supports writing + ;; the data from multiple buffers in the manner of `writev`. + (func (export "sock_send") + (param $self $fd_t) + ;; List of scatter/gather vectors to which to retrieve data + (param $si_data $ciovec_t_array) + ;; Message flags. + (param $si_flags $siflags_t) + (result $error $errno_t) + ;; Number of bytes transmitted. + (result $so_datalen $size_t) + ) + + ;; Shut down socket send and receive channels. + ;; Note: This is similar to `shutdown` in POSIX. + (func (export "sock_shutdown") + (param $self $fd_t) + ;; Which channels on the socket to shut down. + (param $how $sdflags_t) + (result $error $errno_t) + ) +) From 33cd953adfed49d4c40d43ac78644bae90045eb3 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 15:13:53 -0700 Subject: [PATCH 02/26] Update design/wasi_unstable/wasi_unstable.wati Co-Authored-By: Stefan Junker --- design/wasi_unstable/wasi_unstable.wati | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index 1dd06791..42c6ba88 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -198,7 +198,7 @@ ;; The right to invoke __wasi_fd_datasync(). ;; ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke - ;` __wasi_path_open() with __WASI_FDFLAG_DSYNC. + ;; __wasi_path_open() with __WASI_FDFLAG_DSYNC. (flag $RIGHT_FD_DATASYNC) ;; The right to invoke __wasi_fd_read() and __wasi_sock_recv(). ;; From 402979b26c1c1693028f2bc24043cba525f9285d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 10:40:46 -0700 Subject: [PATCH 03/26] Give types to iovec_t/ciovec_t's fields. This replaces the "data" type. It'll be desirable to use higher-level types to describe what iovec/ciovec do, however to avoid getting into IDL design questions, for now just use explicit pointer and length values to keep things simple. --- design/wasi_unstable/wasi_unstable.wati | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index 42c6ba88..448c1505 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -3,6 +3,7 @@ ;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). (typename $size_t u32) +(typename $uintptr_t u32) (typename $string_array (array string)) ;; Non-negative file size or length of a region within a file. @@ -280,8 +281,8 @@ (typename $iovec_t (struct ;; The address and length of the buffer to be filled. - (field $buf data) - (field $buf_len data) + (field $buf $uintptr_t) + (field $buf_len $size_t) ) ) @@ -289,8 +290,8 @@ (typename $ciovec_t (struct ;; The address and length of the buffer to be written. - (field $buf data) - (field $buf_len data) + (field $buf $uintptr_t) + (field $buf_len $size_t) ) ) From e427e18290fd5380a3e4f9e25c81b738ddcf6ff7 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 10:55:24 -0700 Subject: [PATCH 04/26] Code-quote more things. --- design/wasi_unstable/wasi_unstable.wati | 112 ++++++++++++------------ 1 file changed, 56 insertions(+), 56 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index 448c1505..d0ee446f 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -196,82 +196,82 @@ ;; File descriptor rights, determining which actions may be performed. (typename $rights_t (flags u64 - ;; The right to invoke __wasi_fd_datasync(). + ;; The right to invoke `__wasi_fd_datasync()`. ;; - ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke - ;; __wasi_path_open() with __WASI_FDFLAG_DSYNC. + ;; If `__WASI_RIGHT_PATH_OPEN` is set, includes the right to invoke + ;; `__wasi_path_open()` with `__WASI_FDFLAG_DSYNC`. (flag $RIGHT_FD_DATASYNC) - ;; The right to invoke __wasi_fd_read() and __wasi_sock_recv(). + ;; The right to invoke `__wasi_fd_read()` and `__wasi_sock_recv()`. ;; - ;; If __WASI_RIGHT_FD_SEEK is set, includes the right to invoke - ;; __wasi_fd_pread(). + ;; If `__WASI_RIGHT_FD_SEEK` is set, includes the right to invoke + ;; `__wasi_fd_pread()`. (flag $RIGHT_FD_READ) - ;; The right to invoke __wasi_fd_seek(). This flag implies __WASI_RIGHT_FD_TELL. + ;; The right to invoke `__wasi_fd_seek()`. This flag implies `__WASI_RIGHT_FD_TELL`. (flag $RIGHT_FD_SEEK) - ;; The right to invoke __wasi_fd_fdstat_set_flags(). + ;; The right to invoke `__wasi_fd_fdstat_set_flags()`. (flag $RIGHT_FD_FDSTAT_SET_FLAGS) - ;; The right to invoke __wasi_fd_sync(). + ;; The right to invoke `__wasi_fd_sync()`. ;; - ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke - ;; __wasi_path_open() with __WASI_FDFLAG_RSYNC and __WASI_FDFLAG_DSYNC. + ;; If `__WASI_RIGHT_PATH_OPEN` is set, includes the right to invoke + ;; `__wasi_path_open()` with `__WASI_FDFLAG_RSYNC` and `__WASI_FDFLAG_DSYNC`. (flag $RIGHT_FD_SYNC) - ;; The right to invoke __wasi_fd_seek() in such a way that the file offset - ;; remains unaltered (i.e., __WASI_WHENCE_CUR with offset zero), or to - ;; invoke __wasi_fd_tell(). + ;; The right to invoke `__wasi_fd_seek()` in such a way that the file offset + ;; remains unaltered (i.e., `__WASI_WHENCE_CUR` with offset zero), or to + ;; invoke `__wasi_fd_tell()`. (flag $RIGHT_FD_TELL) - ;; The right to invoke __wasi_fd_write() and __wasi_sock_send(). - ;; If __WASI_RIGHT_FD_SEEK is set, includes the right to invoke __wasi_fd_pwrite(). + ;; The right to invoke `__wasi_fd_write()` and `__wasi_sock_send()`. + ;; If `__WASI_RIGHT_FD_SEEK` is set, includes the right to invoke `__wasi_fd_pwrite()`. (flag $RIGHT_FD_WRITE) - ;; The right to invoke __wasi_fd_advise(). + ;; The right to invoke `__wasi_fd_advise()`. (flag $RIGHT_FD_ADVISE) - ;; The right to invoke __wasi_fd_allocate(). + ;; The right to invoke `__wasi_fd_allocate()`. (flag $RIGHT_FD_ALLOCATE) - ;; The right to invoke __wasi_path_create_directory(). + ;; The right to invoke `__wasi_path_create_directory()`. (flag $RIGHT_PATH_CREATE_DIRECTORY) - ;; If __WASI_RIGHT_PATH_OPEN is set, the right to invoke __wasi_path_open() with __WASI_O_CREAT. + ;; If `__WASI_RIGHT_PATH_OPEN` is set, the right to invoke `__wasi_path_open()` with `__WASI_O_CREAT`. (flag $RIGHT_PATH_CREATE_FILE) - ;; The right to invoke __wasi_path_link() with the file descriptor as the source directory. + ;; The right to invoke `__wasi_path_link()` with the file descriptor as the source directory. (flag $RIGHT_PATH_LINK_SOURCE) - ;; The right to invoke __wasi_path_link() with the file descriptor as the target directory. + ;; The right to invoke `__wasi_path_link()` with the file descriptor as the target directory. (flag $RIGHT_PATH_LINK_TARGET) - ;; The right to invoke __wasi_path_open(). + ;; The right to invoke `__wasi_path_open()`. (flag $RIGHT_PATH_OPEN) - ;; The right to invoke __wasi_fd_readdir(). + ;; The right to invoke `__wasi_fd_readdir()`. (flag $RIGHT_FD_READDIR) - ;; The right to invoke __wasi_path_readlink(). + ;; The right to invoke `__wasi_path_readlink()`. (flag $RIGHT_PATH_READLINK) - ;; The right to invoke __wasi_path_rename() with the file descriptor as the source directory. + ;; The right to invoke `__wasi_path_rename()` with the file descriptor as the source directory. (flag $RIGHT_PATH_RENAME_SOURCE) - ;; The right to invoke __wasi_path_rename() with the file descriptor as the target directory. + ;; The right to invoke `__wasi_path_rename()` with the file descriptor as the target directory. (flag $RIGHT_PATH_RENAME_TARGET) - ;; The right to invoke __wasi_path_filestat_get(). + ;; The right to invoke `__wasi_path_filestat_get()`. (flag $RIGHT_PATH_FILESTAT_GET) - ;; The right to change a file's size (there is no __wasi_path_filestat_set_size()). - ;; If __WASI_RIGHT_PATH_OPEN is set, includes the right to invoke __wasi_path_open() with __WASI_O_TRUNC. + ;; The right to change a file's size (there is no `__wasi_path_filestat_set_size()`). + ;; If `__WASI_RIGHT_PATH_OPEN` is set, includes the right to invoke `__wasi_path_open()` with `__WASI_O_TRUNC`. (flag $RIGHT_PATH_FILESTAT_SET_SIZE) - ;; The right to invoke __wasi_path_filestat_set_times(). + ;; The right to invoke `__wasi_path_filestat_set_times()`. (flag $RIGHT_PATH_FILESTAT_SET_TIMES) - ;; The right to invoke __wasi_fd_filestat_get(). + ;; The right to invoke `__wasi_fd_filestat_get()`. (flag $RIGHT_FD_FILESTAT_GET) - ;; The right to invoke __wasi_fd_filestat_set_size(). + ;; The right to invoke `__wasi_fd_filestat_set_size()`. (flag $RIGHT_FD_FILESTAT_SET_SIZE) - ;; The right to invoke __wasi_fd_filestat_set_times(). + ;; The right to invoke `__wasi_fd_filestat_set_times()`. (flag $RIGHT_FD_FILESTAT_SET_TIMES) - ;; The right to invoke __wasi_path_symlink(). + ;; The right to invoke `__wasi_path_symlink()`. (flag $RIGHT_PATH_SYMLINK) - ;; The right to invoke __wasi_path_unlink_file(). + ;; The right to invoke `__wasi_path_unlink_file()`. (flag $RIGHT_PATH_UNLINK_FILE) - ;; The right to invoke __wasi_path_remove_directory(). + ;; The right to invoke `__wasi_path_remove_directory()`. (flag $RIGHT_PATH_REMOVE_DIRECTORY) - ;; If __WASI_RIGHT_FD_READ is set, includes the right to invoke __wasi_poll_oneoff() to subscribe to __WASI_EVENTTYPE_FD_READ. - ;; If __WASI_RIGHT_FD_WRITE is set, includes the right to invoke __wasi_poll_oneoff() to subscribe to __WASI_EVENTTYPE_FD_WRITE. + ;; If `__WASI_RIGHT_FD_READ` is set, includes the right to invoke `__wasi_poll_oneoff()` to subscribe to `__WASI_EVENTTYPE_FD_READ`. + ;; If `__WASI_RIGHT_FD_WRITE` is set, includes the right to invoke `__wasi_poll_oneoff()` to subscribe to `__WASI_EVENTTYPE_FD_WRITE`. (flag $RIGHT_POLL_FD_READWRITE) - ;; The right to invoke __wasi_sock_shutdown(). + ;; The right to invoke `__wasi_sock_shutdown()`. (flag $RIGHT_SOCK_SHUTDOWN) ) ) -;; a file descriptor index +;; A file descriptor index. (typename $fd_t u32) (typename $iovec_t_array (array $iovec_t)) @@ -377,7 +377,7 @@ (field $fs_rights_base $rights_t) ;; Maximum set of rights that may be installed on new file descriptors that ;; are created through this file descriptor, e.g., through - ;; __wasi_path_open(). + ;; `__wasi_path_open()`. (field $fs_rights_inheriting $rights_t) ) ) @@ -414,11 +414,11 @@ (flags u16 ;; Adjust the last data access timestamp to the value stored in __wasi_filestat_t::st_atim. (flag $FILESTAT_SET_ATIM) - ;; Adjust the last data access timestamp to the time of clock __WASI_CLOCK_REALTIME. + ;; Adjust the last data access timestamp to the time of clock `__WASI_CLOCK_REALTIME`. (flag $FILESTAT_SET_ATIM_NOW) ;; Adjust the last data modification timestamp to the value stored in __wasi_filestat_t::st_mtim. (flag $FILESTAT_SET_MTIM) - ;; Adjust the last data modification timestamp to the time of clock __WASI_CLOCK_REALTIME. + ;; Adjust the last data modification timestamp to the time of clock `__WASI_CLOCK_REALTIME`. (flag $FILESTAT_SET_MTIM_NOW) ) ) @@ -434,7 +434,7 @@ ) ) -;; Open flags used by __wasi_path_open(). +;; Open flags used by `__wasi_path_open()`. (typename $oflags_t (flags u16 ;; Create file if it does not exist. @@ -487,7 +487,7 @@ (field $type $eventtype_t) (field $u (typename union - ;; When type is __WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE: + ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: (field $fd_readwrite (typename stuct ;; The number of bytes available for reading or writing. @@ -502,7 +502,7 @@ ) ) -;; The state of the file descriptor subscribed to with __WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE. +;; The state of the file descriptor subscribed to with `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`. (typename $eventrwflags_t (flags u16 ;; The peer of this socket has closed or disconnected. @@ -544,7 +544,7 @@ (field (type (union - ;; When type is __WASI_EVENTTYPE_CLOCK + ;; When type is `__WASI_EVENTTYPE_CLOCK`: (field $clock (typename (struct @@ -560,7 +560,7 @@ ) ) ) - ;; When type is __WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE: + ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: (field $fd_readwrite (type (struct @@ -662,7 +662,7 @@ ) ) -;; Flags provided to __wasi_sock_recv(). +;; Flags provided to `__wasi_sock_recv()`. (typename $riflags_t (flags u16 ;; Returns the message without removing it from the socket's receive queue. @@ -672,15 +672,15 @@ ) ) -;; Flags returned by __wasi_sock_recv(). +;; Flags returned by `__wasi_sock_recv()`. (typename $roflags_t (flags u16 - ;; Returned by __wasi_sock_recv(): Message data has been truncated. + ;; Returned by `__wasi_sock_recv()`: Message data has been truncated. (flag $SOCK_RECV_DATA_TRUNCATED) ) ) -;; Flags provided to __wasi_sock_send(). As there are currently no flags defined, it must be set to zero. +;; Flags provided to `__wasi_sock_send()`. As there are currently no flags defined, it must be set to zero. (typename $siflags_t u16) ;; Which channels on a socket to shut down. @@ -925,8 +925,8 @@ ) ;; Atomically replace a file descriptor by renumbering another file descriptor. - ;; Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like dup2(). This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time. - ;; This function provides a way to atomically renumber file descriptors, which would disappear if dup2() were to be removed entirely. + ;; Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like `dup2()`. This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time. + ;; This function provides a way to atomically renumber file descriptors, which would disappear if `dup2()` were to be removed entirely. (func (export "fd_renumber") (param $self $fd_t) ;; The file descriptor to overwrite. @@ -1110,7 +1110,7 @@ ;; Unlink a file. - ;; Return __WASI_EISDIR if the path refers to a directory. + ;; Return `__WASI_EISDIR` if the path refers to a directory. ;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. (func (export "path_unlink_file") (param $self $fd_t) From cb498da2de26a4ca5d39d8fac29eb1ad1fbf3b0c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 10:57:25 -0700 Subject: [PATCH 05/26] Remove the $else field of a union. --- design/wasi_unstable/wasi_unstable.wati | 1 - 1 file changed, 1 deletion(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index d0ee446f..0570345c 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -496,7 +496,6 @@ (field $flags $eventrwflags_t) ) ) - (field $else Null) ) ) ) From 80a41155ae9ef3c629ce6a567696cea1176fb1ef Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 10:59:09 -0700 Subject: [PATCH 06/26] Clean up a few more `(type ...)` and `(typename ...)` constructs. Only use `(typename ...)` to declare named types; don't use it for inline types. --- design/wasi_unstable/wasi_unstable.wati | 48 +++++++++++-------------- 1 file changed, 21 insertions(+), 27 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index 0570345c..43805482 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -486,10 +486,10 @@ ;; The type of the event that occurred. (field $type $eventtype_t) (field $u - (typename union + (union ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: (field $fd_readwrite - (typename stuct + (struct ;; The number of bytes available for reading or writing. (field $nbytes $filesize_t) ;; The state of the file descriptor. @@ -541,32 +541,26 @@ ;; The type of the event to which to subscribe. (field $type $eventtype_t) (field - (type - (union - ;; When type is `__WASI_EVENTTYPE_CLOCK`: - (field $clock - (typename - (struct - ;; The user-defined unique identifier of the clock. - (field $identifier $userdata_t) - ;; The clock against which to compare the timestamp. - (field $clock_id $clockid_t) - ;; The absolute or relative timestamp. - (field $timeout $timestamp_t) - ;; The amount of time that the implementation may wait additionally to coalesce with other events. - ;; Flags specifying whether the timeout is absolute or relative - (field $precision $timestamp_t) - ) - ) + (union + ;; When type is `__WASI_EVENTTYPE_CLOCK`: + (field $clock + (struct + ;; The user-defined unique identifier of the clock. + (field $identifier $userdata_t) + ;; The clock against which to compare the timestamp. + (field $clock_id $clockid_t) + ;; The absolute or relative timestamp. + (field $timeout $timestamp_t) + ;; The amount of time that the implementation may wait additionally to coalesce with other events. + ;; Flags specifying whether the timeout is absolute or relative + (field $precision $timestamp_t) ) - ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: - (field $fd_readwrite - (type - (struct - ;; The file descriptor on which to wait for it to become ready for reading or writing. - (field $file_descriptor $fd_t) - ) - ) + ) + ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: + (field $fd_readwrite + (struct + ;; The file descriptor on which to wait for it to become ready for reading or writing. + (field $file_descriptor $fd_t) ) ) ) From 2ddd38a86389bf995c4370f7397ac723e749073f Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 11:01:21 -0700 Subject: [PATCH 07/26] Wrap some long lines. --- design/wasi_unstable/wasi_unstable.wati | 45 ++++++++++++++++++------- 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index 43805482..a2ba1e3e 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -230,9 +230,11 @@ (flag $RIGHT_PATH_CREATE_DIRECTORY) ;; If `__WASI_RIGHT_PATH_OPEN` is set, the right to invoke `__wasi_path_open()` with `__WASI_O_CREAT`. (flag $RIGHT_PATH_CREATE_FILE) - ;; The right to invoke `__wasi_path_link()` with the file descriptor as the source directory. + ;; The right to invoke `__wasi_path_link()` with the file descriptor as the + ;; source directory. (flag $RIGHT_PATH_LINK_SOURCE) - ;; The right to invoke `__wasi_path_link()` with the file descriptor as the target directory. + ;; The right to invoke `__wasi_path_link()` with the file descriptor as the + ;; target directory. (flag $RIGHT_PATH_LINK_TARGET) ;; The right to invoke `__wasi_path_open()`. (flag $RIGHT_PATH_OPEN) @@ -473,7 +475,8 @@ ) ) -;; User-provided value that may be attached to objects that is retained when extracted from the implementation. +;; User-provided value that may be attached to objects that is retained when +;; extracted from the implementation. (typename $userdata_t u64) ;; An event that occurred. @@ -501,7 +504,8 @@ ) ) -;; The state of the file descriptor subscribed to with `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`. +;; The state of the file descriptor subscribed to with +;; `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`. (typename $eventrwflags_t (flags u16 ;; The peer of this socket has closed or disconnected. @@ -512,16 +516,20 @@ ;; Type of a subscription to an event or its occurrence. (typename $eventtype_t (flags u8 - ;; The time value of clock __wasi_subscription_t::u.clock.clock_id has reached timestamp __wasi_subscription_t::u.clock.timeout. + ;; The time value of clock __wasi_subscription_t::u.clock.clock_id has + ;; reached timestamp __wasi_subscription_t::u.clock.timeout. (flag $EVENTTYPE_CLOCK) - ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has data available for reading. This event always triggers for regular files. + ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has data + ;; available for reading. This event always triggers for regular files. (flag $EVENTTYPE_FD_READ) - ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has capacity available for writing. This event always triggers for regular files. + ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has capacity + ;; available for writing. This event always triggers for regular files. (flag $EVENTTYPE_FD_WRITE) ) ) -;; Flags determining how to interpret the timestamp provided in __wasi_subscription_t::u.clock.timeout. +;; Flags determining how to interpret the timestamp provided in +;; __wasi_subscription_t::u.clock.timeout. (typename $subclockflags_t (flags u16 ;; If set, treat the timestamp provided in @@ -536,7 +544,8 @@ ;; Subscription to an event. (typename $subscription_t (struct - ;; User-provided value that is attached to the subscription in the implementation and returned through __wasi_event_t::userdata. + ;; User-provided value that is attached to the subscription in the + ;; implementation and returned through __wasi_event_t::userdata. (field $userdata $userdata_t) ;; The type of the event to which to subscribe. (field $type $eventtype_t) @@ -551,7 +560,9 @@ (field $clock_id $clockid_t) ;; The absolute or relative timestamp. (field $timeout $timestamp_t) - ;; The amount of time that the implementation may wait additionally to coalesce with other events. + ;; The amount of time that the implementation may wait additionally + ;; to coalesce with other events. + ;; ;; Flags specifying whether the timeout is absolute or relative (field $precision $timestamp_t) ) @@ -673,7 +684,8 @@ ) ) -;; Flags provided to `__wasi_sock_send()`. As there are currently no flags defined, it must be set to zero. +;; Flags provided to `__wasi_sock_send()`. As there are currently no flags +;; defined, it must be set to zero. (typename $siflags_t u16) ;; Which channels on a socket to shut down. @@ -918,8 +930,15 @@ ) ;; Atomically replace a file descriptor by renumbering another file descriptor. - ;; Due to the strong focus on thread safety, this environment does not provide a mechanism to duplicate or renumber a file descriptor to an arbitrary number, like `dup2()`. This would be prone to race conditions, as an actual file descriptor with the same number could be allocated by a different thread at the same time. - ;; This function provides a way to atomically renumber file descriptors, which would disappear if `dup2()` were to be removed entirely. + ;; + ;; Due to the strong focus on thread safety, this environment does not provide + ;; a mechanism to duplicate or renumber a file descriptor to an arbitrary + ;; number, like `dup2()`. This would be prone to race conditions, as an actual + ;; file descriptor with the same number could be allocated by a different + ;; thread at the same time. + ;; + ;; This function provides a way to atomically renumber file descriptors, which + ;; would disappear if `dup2()` were to be removed entirely. (func (export "fd_renumber") (param $self $fd_t) ;; The file descriptor to overwrite. From c5d74fd01f868735e4ea522060b575d892873786 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 11:05:15 -0700 Subject: [PATCH 08/26] Fix field syntax. --- design/wasi_unstable/wasi_unstable.wati | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index a2ba1e3e..63897449 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -549,7 +549,7 @@ (field $userdata $userdata_t) ;; The type of the event to which to subscribe. (field $type $eventtype_t) - (field + (field $u (union ;; When type is `__WASI_EVENTTYPE_CLOCK`: (field $clock From 234233d6a6ea491bb7af7d1a7cddc3c38603d896 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 15 Aug 2019 11:05:23 -0700 Subject: [PATCH 09/26] Fix exponentiation syntax in a comment. --- design/wasi_unstable/wasi_unstable.wati | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/wasi_unstable.wati index 63897449..5a816ada 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/wasi_unstable.wati @@ -1046,7 +1046,7 @@ ;; file descriptor not currently open; it is randomized to prevent ;; applications from depending on making assumptions about indexes, since this ;; is error-prone in multi-threaded contexts. The returned file descriptor is - ;; guaranteed to be less than 231. + ;; guaranteed to be less than 2**31. ;; ;; Note: This is similar to `openat` in POSIX. (func (export "path_open") From e0d5f4005b22eeb3eddc3759781e40f65696af0a Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 22 Aug 2019 10:48:08 -0700 Subject: [PATCH 10/26] Rename .wati to .widl, use more interface-types syntax, and move types to a separate file. --- .../{wasi_unstable.wati => typenames.widl} | 522 +----------------- design/wasi_unstable/wasi_unstable.widl | 519 +++++++++++++++++ 2 files changed, 520 insertions(+), 521 deletions(-) rename design/wasi_unstable/{wasi_unstable.wati => typenames.widl} (54%) create mode 100644 design/wasi_unstable/wasi_unstable.widl diff --git a/design/wasi_unstable/wasi_unstable.wati b/design/wasi_unstable/typenames.widl similarity index 54% rename from design/wasi_unstable/wasi_unstable.wati rename to design/wasi_unstable/typenames.widl index 5a816ada..df97290e 100644 --- a/design/wasi_unstable/wasi_unstable.wati +++ b/design/wasi_unstable/typenames.widl @@ -1,4 +1,4 @@ -;; The wasi_unstable module type. +;; Type names used by the wasi_unstable module type. ;; ;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). @@ -697,523 +697,3 @@ (flag $SHUT_WR) ) ) - -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; -;; The wasi_unstable moduletype. -;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -(moduletype $wasi_unstable - ;; Linear memory used by the program. - (import "memory" (memory)) - - ;; The program entry point. - (import "_start" (func)) - - ;; Read command-line argument data. - ;; The size of the array should match that returned by `wasi_args_sizes_get()` - (func (export "args_get") - (result $error $errno_t) - (result $argv $string_array) - ) - ;; Return command-line argument data sizes. - (func (export "args_sizes_get") - (result $error $errno_t) - ;; The number of arguments. - (result $argc $size_t) - ;; The size of the argument string data. - (result $argv_buf_size $size_t) - ) - - ;; Read environment variable data. - ;; The sizes of the buffers should match that returned by `environ.sizes_get()`. - (func (export "environ_get") - (result $error $errno_t) - (result $argv $string_array) - ) - ;; Return command-line argument data sizes. - (func (export "environ_sizes_get") - ;; The number of arguments. - (result $argc $size_t) - ;; The size of the argument string data. - (result $argv_buf_size $size_t) - ) - - ;; Return the resolution of a clock. - ;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL` - ;; Note: This is similar to `clock_getres` in POSIX. - (func (export "clock_res_get") - (result $error $errno_t) - ;; The clock for which to return the resolution. - (param $clock_id $clockid_t) - ;; The resolution of the clock. - (result $resolution $timestamp_t) - ) - ;; Return the time value of a clock. - ;; Note: This is similar to `clock_gettime` in POSIX. - (func (export "clock_time_get") - ;; The clock for which to return the time. - (param $clock_id $clockid_t) - ;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value. - (param $precision $timestamp_t) - (result $error $errno_t) - ;; The time value of the clock. - (result $time $timestamp_t) - ) - - ;; Provide file advisory information on a file descriptor. - ;; Note: This is similar to `posix_fadvise` in POSIX. - (func (export "fd_advise") - (param $self $fd_t) - (param $offset $filesize_t) ;; The offset within the file to which the advisory applies. - (param $len $filesize_t) ;; The length of the region to which the advisory applies. - (param $advice $advice_t) ;; The advice. - (result $error $errno_t) - ) - - ;; Force the allocation of space in a file. - ;; Note: This is similar to `posix_fallocate` in POSIX. - (func (export "fd_allocate") - (param $self $fd_t) - ;; The offset at which to start the allocation. - (param $offset $filesize_t) - ;; The length of the area that is allocated. - (param $len $filesize_t) - (result $error $errno_t) - ) - - ;; Close a file descriptor. - ;; Note: This is similar to `close` in POSIX. - (func (export "fd_close") - (param $self $fd_t) - (result $error $errno_t) - ) - - ;; Synchronize the data of a file to disk. - ;; Note: This is similar to `fdatasync` in POSIX. - (func (export "fd_datasync") - (param $self $fd_t) - (result $error $errno_t) - ) - - ;; Get the attributes of a file descriptor. - ;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. - (func (export "fd_fdstat_get") - (param $self $fd_t) - (result $error $errno_t) - ;; The buffer where the file descriptor's attributes are stored. - (result $fdstat_t) - ) - - ;; Adjust the flags associated with a file descriptor. - ;; Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. - (func (export "fd_fdstat_set_flags") - (param $self $fd_t) - ;; The desired values of the file descriptor flags. - (param $flags $fdflags) - (result $error $errno_t) - ) - - ;; Adjust the rights associated with a file descriptor. - ;; This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights - (func (export "fd_fdstat_set_rights") - (param $self $fd_t) - ;; The desired rights of the file descriptor. - (param $fs_rights_base $rights_t) - (param $fs_rights_inheriting $rights_t) - (result $error $errno_t) - ) - - ;; Return the attributes of an open file. - (func (export "fd_filestat_get") - (param $self $fd_t) - (result $error $errno_t) - ;; The buffer where the file's attributes are stored. - (result $fs_rights_base $rights_t) - ) - - ;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. - ;; Note: This is similar to `ftruncate` in POSIX. - (func (export "fd_filestat_set_size") - (param $self $fd_t) - ;; The desired file size. - (param $st_size $filesize_t) - (result $error $errno_t) - ) - - ;; Adjust the timestamps of an open file or directory. - ;; Note: This is similar to `futimens` in POSIX. - (func (export "fd_filestat_set_times") - (param $self $fd_t) - ;; The desired values of the data access timestamp. - (param $st_atim $timestamp_t) - ;; The desired values of the data modification timestamp. - (param $st_mtim $timestamp_t) - ;; A bitmask indicating which timestamps to adjust. - (param $fst_flags $fstflags_t) - (result $error $errno_t) - ) - - ;; Read from a file descriptor, without using and updating the file descriptor's offset. - ;; Note: This is similar to `preadv` in POSIX. - (func (export "fd_pread") - (param $self $fd_t) - ;; List of scatter/gather vectors in which to store data. - (param $iovs $iovec_t_array) - ;; The offset within the file at which to read. - (param $offset $filesize_t) - (result $error $errno_t) - ;; The number of bytes read. - (result $nread $size_t) - ) - - ;; Return a description of the given preopened file descriptor. - (func (export "fd_prestat_get") - (param $self $fd_t) - (result $error $errno_t) - ;; The buffer where the description is stored. - (result $buf $prestat_t) - ) - - ;; Return a description of the given preopened file descriptor. - (func (export "fd_prestat_dir_name") - (param $self $fd_t) - ;; A buffer into which to write the preopened directory name. - (param $path string) - (result $error $errno_t) - ) - - ;; Write to a file descriptor, without using and updating the file descriptor's offset. - ;; Note: This is similar to `pwritev` in POSIX. - (func (export "fd_pwrite") - (param $self $fd_t) - ;; List of scatter/gather vectors from which to retrieve data. - (param $iovs $iovec_t_array) - ;; The offset within the file at which to write. - (param $offset $filesize_t) - (result $error $errno_t) - ;; The number of bytes written. - (result $nwritten $size_t) - ) - - ;; Read from a file descriptor. - ;; Note: This is similar to `readv` in POSIX. - (func (export "fd_read") - (param $self $fd_t) - ;; List of scatter/gather vectors to which to store data. - (param $iovs $iovec_t_array) - (result $error $errno_t) - ;; The number of bytes read. - (result $nread $size_t) - ) - - ;; Read directory entries from a directory. - ;; When successful, the contents of the output buffer consist of a sequence of - ;; directory entries. Each directory entry consists of a dirent_t object, - ;; followed by dirent_t::d_namlen bytes holding the name of the directory - ;; entry. - ;; - ;; This function fills the output buffer as much as possible, potentially - ;; truncating the last directory entry. This allows the caller to grow its - ;; read buffer size in case it's too small to fit a single large directory - ;; entry, or skip the oversized directory entry. - (func (export "fd_readdir") - (param $self $fd_t) - ;; The buffer where directory entries are stored - (param $buf data) - ;; The location within the directory to start reading - (param $cookie $dircookie_t) - (result $error $errno_t) - ;; The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. - (result $bufused $size_t) - ) - - ;; Atomically replace a file descriptor by renumbering another file descriptor. - ;; - ;; Due to the strong focus on thread safety, this environment does not provide - ;; a mechanism to duplicate or renumber a file descriptor to an arbitrary - ;; number, like `dup2()`. This would be prone to race conditions, as an actual - ;; file descriptor with the same number could be allocated by a different - ;; thread at the same time. - ;; - ;; This function provides a way to atomically renumber file descriptors, which - ;; would disappear if `dup2()` were to be removed entirely. - (func (export "fd_renumber") - (param $self $fd_t) - ;; The file descriptor to overwrite. - (param $to $fd_t) - (result $error $errno_t) - ) - - ;; Move the offset of a file descriptor. - ;; Note: This is similar to `lseek` in POSIX. - (func (export "fd_seek") - (param $self $fd_t) - ;; The number of bytes to move. - (param $offset $filedelta_t) - ;; The base from which the offset is relative. - (param $whence $whence_t) - (result $error $errno_t) - ;; The new offset of the file descriptor, relative to the start of the file. - (result $newoffset $filesize_t) - ) - - ;; Synchronize the data and metadata of a file to disk. - ;; Note: This is similar to `fsync` in POSIX. - (func (export "fd_sync") - (param $self $fd_t) - (result $error $errno_t) - ) - - ;; Return the current offset of a file descriptor. - ;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. - (func (export "fd_tell") - (param $self $fd_t) - (result $error $errno_t) - ;; The current offset of the file descriptor, relative to the start of the file. - (result $offset $filesize_t) - ) - - ;; Write to a file descriptor. - ;; Note: This is similar to `writev` in POSIX. - (func (export "fd_write") - (param $self $fd_t) - ;; List of scatter/gather vectors from which to retrieve data. - (param $iovs $iovec_t_array) - (result $error $errno_t) - ;; The number of bytes written. - (result $nwritten $size_t) - ) - - ;; Create a directory. - ;; Note: This is similar to `mkdirat` in POSIX. - (func (export "path_create_directory") - (param $self $fd_t) - ;; The path at which to create the directory. - (param $path string) - (result $error $errno_t) - ) - - ;; Return the attributes of a file or directory. - ;; Note: This is similar to `stat` in POSIX. - (func (export "path_filestat_get") - (param $self $fd_t) - ;; Flags determining the method of how the path is resolved. - (param $flags $lookupflags_t) - ;; The path of the file or directory to inspect. - (param $path string) - (result $error $errno_t) - ;; The buffer where the file's attributes are stored. - (result $buf $filestat_t) - ) - - ;; Adjust the timestamps of a file or directory. - ;; Note: This is similar to `utimensat` in POSIX. - (func (export "path_filestat_set_times") - (param $self $fd_t) - ;; Flags determining the method of how the path is resolved. - (param $flags $lookupflags_t) - ;; The path of the file or directory to operate on. - (param $path string) - ;; The desired values of the data access timestamp. - (param $st_atim $timestamp_t) - ;; The desired values of the data modification timestamp. - (param $st_mtim $timestamp_t) - ;; A bitmask indicating which timestamps to adjust. - (param $fst_flags $fstflags_t) - (result $error $errno_t) - ) - - ;; Create a hard link. - ;; Note: This is similar to `linkat` in POSIX. - (func (export "path_link") - (param $self $fd_t) - ;; Flags determining the method of how the path is resolved. - (param $old_flags $lookupflags_t) - ;; The source path from which to link. - (param $old_path string) - ;; The working directory at which the resolution of the new path starts. - (param $new_fd $path) - ;; The destination path at which to create the hard link. - (param $new_path string) - (result $error $errno_t) - ) - - ;; Open a file or directory. - ;; - ;; The returned file descriptor is not guaranteed to be the lowest-numbered - ;; file descriptor not currently open; it is randomized to prevent - ;; applications from depending on making assumptions about indexes, since this - ;; is error-prone in multi-threaded contexts. The returned file descriptor is - ;; guaranteed to be less than 2**31. - ;; - ;; Note: This is similar to `openat` in POSIX. - (func (export "path_open") - (param $self $fd_t) - ;; Flags determining the method of how the path is resolved. - (param $dirflags $lookupflags_t) - ;; The relative path of the file or directory to open, relative to the - ;; `dirfd` directory. - (param $path string) - ;; The method by which to open the file. - (param $o_flags $oflags_t) - ;; The initial rights of the newly created file descriptor. The - ;; implementation is allowed to return a file descriptor with fewer rights - ;; than specified, if and only if those rights do not apply to the type of - ;; file being opened. - ;; - ;; The base rights are rights that will apply to operations using the file - ;; descriptor itself, while the inheriting rights are rights that apply to - ;; file descriptors derived from it. - (param $fs_rights_base $rights_t) - (param $fs_rights_inherting $rights_t) - (result $error $errno_t) - ;; The file descriptor of the file that has been opened. - (result $opened_fd $fd_t) - ) - - ;; Read the contents of a symbolic link. - ;; Note: This is similar to `readlinkat` in POSIX. - (func (export "path_readlink") - (param $self $fd_t) - ;; The path of the symbolic link from which to read. - (param $path) - ;; The buffer to which to write the contents of the symbolic link. - (param $buf string) - (result $error $errno_t) - ;; The number of bytes placed in the buffer. - (result $bufused $size_t) - ) - - ;; Remove a directory. - ;; Return `__WASI_ENOTEMPTY` if the directory is not empty. - ;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. - (func (export "path_remove_directory") - (param $self $fd_t) - ;; The path to a directory to remove. - (param $path string) - (result $error $errno_t) - ) - - ;; Rename a file or directory. - ;; Note: This is similar to `renameat` in POSIX. - (func (export "path_rename") - (param $self $fd_t) - ;; The source path of the file or directory to rename. - (param $old_path string) - ;; The working directory at which the resolution of the new path starts. - (param $new_fd $fd) - ;; The destination path to which to rename the file or directory. - (param $new_path string) - (result $error $errno_t) - ) - - ;; Create a symbolic link. - ;; Note: This is similar to `symlinkat` in POSIX. - (func (export "path_symlink") - (param $self $fd_t) - ;; The contents of the symbolic link. - (param $old_path string) - ;; The destination path at which to create the symbolic link. - (param $new_path string) - (result $error $errno_t) - ) - - - ;; Unlink a file. - ;; Return `__WASI_EISDIR` if the path refers to a directory. - ;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. - (func (export "path_unlink_file") - (param $self $fd_t) - ;; The path to a file to unlink. - (param $path string) - (result $error $errno_t) - ) - - ;; Concurrently poll for the occurrence of a set of events. - (func (export "poll_oneoff") - ;; The events to which to subscribe. - (param $in $subscription_t) - ;; The events that have occurred. - (param $out $event_t) - ;; Both the number of subscriptions and events. - (param $nsubscriptions $size_t) - (result $error $errno_t) - ;; The number of events stored. - (result $nevents $size_t) - ) - - ;; Terminate the process normally. An exit code of 0 indicates successful - ;; termination of the program. The meanings of other values is dependent on - ;; the environment. - (func (export "proc_exit") - ;; The exit code returned by the process. - (param $rval $exitcode_t) - ) - - ;; Send a signal to the process of the calling thread. - ;; Note: This is similar to `raise` in POSIX. - (func (export "proc_raise") - ;; The signal condition to trigger. - (param $sig $signal_t) - (result $error $errno_t) - ) - - ;; Temporarily yield execution of the calling thread. - ;; Note: This is similar to `sched_yield` in POSIX. - (func (export "proc_sched_yield") - (result $error $errno_t) - ) - - ;; Write high-quality random data into a buffer. - ;; This function blocks when the implementation is unable to immediately - ;; provide sufficient high-quality random data. - ;; This function may execute slowly, so when large mounts of random data are - ;; required, it's advisable to use this function to seed a pseudo-random - ;; number generator, rather than to provide the random data directly. - (func (export "random_get") - ;; The buffer to fill with random data. - (param $buf data) - (result $error $errno_t) - ) - - ;; Receive a message from a socket. - ;; Note: This is similar to `recv` in POSIX, though it also supports reading - ;; the data into multiple buffers in the manner of `readv`. - (func (export "sock_recv") - (param $self $fd_t) - ;; List of scatter/gather vectors to which to store data. - (param $ri_data $iovec_t_array) - ;; Message flags. - (param $ri_flags $riflags_t) - (result $error $errno_t) - ;; Number of bytes stored in ri_data. - (result $ro_datalen $size_t) - ;; Message flags. - (result $ro_flags $roflags_t) - ) - - ;; Send a message on a socket. - ;; Note: This is similar to `send` in POSIX, though it also supports writing - ;; the data from multiple buffers in the manner of `writev`. - (func (export "sock_send") - (param $self $fd_t) - ;; List of scatter/gather vectors to which to retrieve data - (param $si_data $ciovec_t_array) - ;; Message flags. - (param $si_flags $siflags_t) - (result $error $errno_t) - ;; Number of bytes transmitted. - (result $so_datalen $size_t) - ) - - ;; Shut down socket send and receive channels. - ;; Note: This is similar to `shutdown` in POSIX. - (func (export "sock_shutdown") - (param $self $fd_t) - ;; Which channels on the socket to shut down. - (param $how $sdflags_t) - (result $error $errno_t) - ) -) diff --git a/design/wasi_unstable/wasi_unstable.widl b/design/wasi_unstable/wasi_unstable.widl new file mode 100644 index 00000000..30633d71 --- /dev/null +++ b/design/wasi_unstable/wasi_unstable.widl @@ -0,0 +1,519 @@ +;; The wasi_unstable module type. +;; +;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). + +(import "typenames.wid") + +(module $wasi_unstable + ;; Linear memory used by the program. + (import "memory" (memory)) + + ;; The program entry point. + (import "_start" (func)) + + ;; Read command-line argument data. + ;; The size of the array should match that returned by `wasi_args_sizes_get()` + (@interface func (export "args_get") + (result $error $errno_t) + (result $argv $string_array) + ) + ;; Return command-line argument data sizes. + (@interface func (export "args_sizes_get") + (result $error $errno_t) + ;; The number of arguments. + (result $argc $size_t) + ;; The size of the argument string data. + (result $argv_buf_size $size_t) + ) + + ;; Read environment variable data. + ;; The sizes of the buffers should match that returned by `environ.sizes_get()`. + (@interface func (export "environ_get") + (result $error $errno_t) + (result $argv $string_array) + ) + ;; Return command-line argument data sizes. + (@interface func (export "environ_sizes_get") + ;; The number of arguments. + (result $argc $size_t) + ;; The size of the argument string data. + (result $argv_buf_size $size_t) + ) + + ;; Return the resolution of a clock. + ;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL` + ;; Note: This is similar to `clock_getres` in POSIX. + (@interface func (export "clock_res_get") + (result $error $errno_t) + ;; The clock for which to return the resolution. + (param $clock_id $clockid_t) + ;; The resolution of the clock. + (result $resolution $timestamp_t) + ) + ;; Return the time value of a clock. + ;; Note: This is similar to `clock_gettime` in POSIX. + (@interface func (export "clock_time_get") + ;; The clock for which to return the time. + (param $clock_id $clockid_t) + ;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value. + (param $precision $timestamp_t) + (result $error $errno_t) + ;; The time value of the clock. + (result $time $timestamp_t) + ) + + ;; Provide file advisory information on a file descriptor. + ;; Note: This is similar to `posix_fadvise` in POSIX. + (@interface func (export "fd_advise") + (param $self $fd_t) + (param $offset $filesize_t) ;; The offset within the file to which the advisory applies. + (param $len $filesize_t) ;; The length of the region to which the advisory applies. + (param $advice $advice_t) ;; The advice. + (result $error $errno_t) + ) + + ;; Force the allocation of space in a file. + ;; Note: This is similar to `posix_fallocate` in POSIX. + (@interface func (export "fd_allocate") + (param $self $fd_t) + ;; The offset at which to start the allocation. + (param $offset $filesize_t) + ;; The length of the area that is allocated. + (param $len $filesize_t) + (result $error $errno_t) + ) + + ;; Close a file descriptor. + ;; Note: This is similar to `close` in POSIX. + (@interface func (export "fd_close") + (param $self $fd_t) + (result $error $errno_t) + ) + + ;; Synchronize the data of a file to disk. + ;; Note: This is similar to `fdatasync` in POSIX. + (@interface func (export "fd_datasync") + (param $self $fd_t) + (result $error $errno_t) + ) + + ;; Get the attributes of a file descriptor. + ;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. + (@interface func (export "fd_fdstat_get") + (param $self $fd_t) + (result $error $errno_t) + ;; The buffer where the file descriptor's attributes are stored. + (result $fdstat_t) + ) + + ;; Adjust the flags associated with a file descriptor. + ;; Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. + (@interface func (export "fd_fdstat_set_flags") + (param $self $fd_t) + ;; The desired values of the file descriptor flags. + (param $flags $fdflags) + (result $error $errno_t) + ) + + ;; Adjust the rights associated with a file descriptor. + ;; This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights + (@interface func (export "fd_fdstat_set_rights") + (param $self $fd_t) + ;; The desired rights of the file descriptor. + (param $fs_rights_base $rights_t) + (param $fs_rights_inheriting $rights_t) + (result $error $errno_t) + ) + + ;; Return the attributes of an open file. + (@interface func (export "fd_filestat_get") + (param $self $fd_t) + (result $error $errno_t) + ;; The buffer where the file's attributes are stored. + (result $fs_rights_base $rights_t) + ) + + ;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. + ;; Note: This is similar to `ftruncate` in POSIX. + (@interface func (export "fd_filestat_set_size") + (param $self $fd_t) + ;; The desired file size. + (param $st_size $filesize_t) + (result $error $errno_t) + ) + + ;; Adjust the timestamps of an open file or directory. + ;; Note: This is similar to `futimens` in POSIX. + (@interface func (export "fd_filestat_set_times") + (param $self $fd_t) + ;; The desired values of the data access timestamp. + (param $st_atim $timestamp_t) + ;; The desired values of the data modification timestamp. + (param $st_mtim $timestamp_t) + ;; A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags_t) + (result $error $errno_t) + ) + + ;; Read from a file descriptor, without using and updating the file descriptor's offset. + ;; Note: This is similar to `preadv` in POSIX. + (@interface func (export "fd_pread") + (param $self $fd_t) + ;; List of scatter/gather vectors in which to store data. + (param $iovs $iovec_t_array) + ;; The offset within the file at which to read. + (param $offset $filesize_t) + (result $error $errno_t) + ;; The number of bytes read. + (result $nread $size_t) + ) + + ;; Return a description of the given preopened file descriptor. + (@interface func (export "fd_prestat_get") + (param $self $fd_t) + (result $error $errno_t) + ;; The buffer where the description is stored. + (result $buf $prestat_t) + ) + + ;; Return a description of the given preopened file descriptor. + (@interface func (export "fd_prestat_dir_name") + (param $self $fd_t) + ;; A buffer into which to write the preopened directory name. + (param $path string) + (result $error $errno_t) + ) + + ;; Write to a file descriptor, without using and updating the file descriptor's offset. + ;; Note: This is similar to `pwritev` in POSIX. + (@interface func (export "fd_pwrite") + (param $self $fd_t) + ;; List of scatter/gather vectors from which to retrieve data. + (param $iovs $iovec_t_array) + ;; The offset within the file at which to write. + (param $offset $filesize_t) + (result $error $errno_t) + ;; The number of bytes written. + (result $nwritten $size_t) + ) + + ;; Read from a file descriptor. + ;; Note: This is similar to `readv` in POSIX. + (@interface func (export "fd_read") + (param $self $fd_t) + ;; List of scatter/gather vectors to which to store data. + (param $iovs $iovec_t_array) + (result $error $errno_t) + ;; The number of bytes read. + (result $nread $size_t) + ) + + ;; Read directory entries from a directory. + ;; When successful, the contents of the output buffer consist of a sequence of + ;; directory entries. Each directory entry consists of a dirent_t object, + ;; followed by dirent_t::d_namlen bytes holding the name of the directory + ;; entry. + ;; + ;; This function fills the output buffer as much as possible, potentially + ;; truncating the last directory entry. This allows the caller to grow its + ;; read buffer size in case it's too small to fit a single large directory + ;; entry, or skip the oversized directory entry. + (@interface func (export "fd_readdir") + (param $self $fd_t) + ;; The buffer where directory entries are stored + (param $buf data) + ;; The location within the directory to start reading + (param $cookie $dircookie_t) + (result $error $errno_t) + ;; The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. + (result $bufused $size_t) + ) + + ;; Atomically replace a file descriptor by renumbering another file descriptor. + ;; + ;; Due to the strong focus on thread safety, this environment does not provide + ;; a mechanism to duplicate or renumber a file descriptor to an arbitrary + ;; number, like `dup2()`. This would be prone to race conditions, as an actual + ;; file descriptor with the same number could be allocated by a different + ;; thread at the same time. + ;; + ;; This function provides a way to atomically renumber file descriptors, which + ;; would disappear if `dup2()` were to be removed entirely. + (@interface func (export "fd_renumber") + (param $self $fd_t) + ;; The file descriptor to overwrite. + (param $to $fd_t) + (result $error $errno_t) + ) + + ;; Move the offset of a file descriptor. + ;; Note: This is similar to `lseek` in POSIX. + (@interface func (export "fd_seek") + (param $self $fd_t) + ;; The number of bytes to move. + (param $offset $filedelta_t) + ;; The base from which the offset is relative. + (param $whence $whence_t) + (result $error $errno_t) + ;; The new offset of the file descriptor, relative to the start of the file. + (result $newoffset $filesize_t) + ) + + ;; Synchronize the data and metadata of a file to disk. + ;; Note: This is similar to `fsync` in POSIX. + (@interface func (export "fd_sync") + (param $self $fd_t) + (result $error $errno_t) + ) + + ;; Return the current offset of a file descriptor. + ;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. + (@interface func (export "fd_tell") + (param $self $fd_t) + (result $error $errno_t) + ;; The current offset of the file descriptor, relative to the start of the file. + (result $offset $filesize_t) + ) + + ;; Write to a file descriptor. + ;; Note: This is similar to `writev` in POSIX. + (@interface func (export "fd_write") + (param $self $fd_t) + ;; List of scatter/gather vectors from which to retrieve data. + (param $iovs $iovec_t_array) + (result $error $errno_t) + ;; The number of bytes written. + (result $nwritten $size_t) + ) + + ;; Create a directory. + ;; Note: This is similar to `mkdirat` in POSIX. + (@interface func (export "path_create_directory") + (param $self $fd_t) + ;; The path at which to create the directory. + (param $path string) + (result $error $errno_t) + ) + + ;; Return the attributes of a file or directory. + ;; Note: This is similar to `stat` in POSIX. + (@interface func (export "path_filestat_get") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $flags $lookupflags_t) + ;; The path of the file or directory to inspect. + (param $path string) + (result $error $errno_t) + ;; The buffer where the file's attributes are stored. + (result $buf $filestat_t) + ) + + ;; Adjust the timestamps of a file or directory. + ;; Note: This is similar to `utimensat` in POSIX. + (@interface func (export "path_filestat_set_times") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $flags $lookupflags_t) + ;; The path of the file or directory to operate on. + (param $path string) + ;; The desired values of the data access timestamp. + (param $st_atim $timestamp_t) + ;; The desired values of the data modification timestamp. + (param $st_mtim $timestamp_t) + ;; A bitmask indicating which timestamps to adjust. + (param $fst_flags $fstflags_t) + (result $error $errno_t) + ) + + ;; Create a hard link. + ;; Note: This is similar to `linkat` in POSIX. + (@interface func (export "path_link") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $old_flags $lookupflags_t) + ;; The source path from which to link. + (param $old_path string) + ;; The working directory at which the resolution of the new path starts. + (param $new_fd $path) + ;; The destination path at which to create the hard link. + (param $new_path string) + (result $error $errno_t) + ) + + ;; Open a file or directory. + ;; + ;; The returned file descriptor is not guaranteed to be the lowest-numbered + ;; file descriptor not currently open; it is randomized to prevent + ;; applications from depending on making assumptions about indexes, since this + ;; is error-prone in multi-threaded contexts. The returned file descriptor is + ;; guaranteed to be less than 2**31. + ;; + ;; Note: This is similar to `openat` in POSIX. + (@interface func (export "path_open") + (param $self $fd_t) + ;; Flags determining the method of how the path is resolved. + (param $dirflags $lookupflags_t) + ;; The relative path of the file or directory to open, relative to the + ;; `dirfd` directory. + (param $path string) + ;; The method by which to open the file. + (param $o_flags $oflags_t) + ;; The initial rights of the newly created file descriptor. The + ;; implementation is allowed to return a file descriptor with fewer rights + ;; than specified, if and only if those rights do not apply to the type of + ;; file being opened. + ;; + ;; The base rights are rights that will apply to operations using the file + ;; descriptor itself, while the inheriting rights are rights that apply to + ;; file descriptors derived from it. + (param $fs_rights_base $rights_t) + (param $fs_rights_inherting $rights_t) + (result $error $errno_t) + ;; The file descriptor of the file that has been opened. + (result $opened_fd $fd_t) + ) + + ;; Read the contents of a symbolic link. + ;; Note: This is similar to `readlinkat` in POSIX. + (@interface func (export "path_readlink") + (param $self $fd_t) + ;; The path of the symbolic link from which to read. + (param $path) + ;; The buffer to which to write the contents of the symbolic link. + (param $buf string) + (result $error $errno_t) + ;; The number of bytes placed in the buffer. + (result $bufused $size_t) + ) + + ;; Remove a directory. + ;; Return `__WASI_ENOTEMPTY` if the directory is not empty. + ;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. + (@interface func (export "path_remove_directory") + (param $self $fd_t) + ;; The path to a directory to remove. + (param $path string) + (result $error $errno_t) + ) + + ;; Rename a file or directory. + ;; Note: This is similar to `renameat` in POSIX. + (@interface func (export "path_rename") + (param $self $fd_t) + ;; The source path of the file or directory to rename. + (param $old_path string) + ;; The working directory at which the resolution of the new path starts. + (param $new_fd $fd) + ;; The destination path to which to rename the file or directory. + (param $new_path string) + (result $error $errno_t) + ) + + ;; Create a symbolic link. + ;; Note: This is similar to `symlinkat` in POSIX. + (@interface func (export "path_symlink") + (param $self $fd_t) + ;; The contents of the symbolic link. + (param $old_path string) + ;; The destination path at which to create the symbolic link. + (param $new_path string) + (result $error $errno_t) + ) + + + ;; Unlink a file. + ;; Return `__WASI_EISDIR` if the path refers to a directory. + ;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. + (@interface func (export "path_unlink_file") + (param $self $fd_t) + ;; The path to a file to unlink. + (param $path string) + (result $error $errno_t) + ) + + ;; Concurrently poll for the occurrence of a set of events. + (@interface func (export "poll_oneoff") + ;; The events to which to subscribe. + (param $in $subscription_t) + ;; The events that have occurred. + (param $out $event_t) + ;; Both the number of subscriptions and events. + (param $nsubscriptions $size_t) + (result $error $errno_t) + ;; The number of events stored. + (result $nevents $size_t) + ) + + ;; Terminate the process normally. An exit code of 0 indicates successful + ;; termination of the program. The meanings of other values is dependent on + ;; the environment. + (@interface func (export "proc_exit") + ;; The exit code returned by the process. + (param $rval $exitcode_t) + ) + + ;; Send a signal to the process of the calling thread. + ;; Note: This is similar to `raise` in POSIX. + (@interface func (export "proc_raise") + ;; The signal condition to trigger. + (param $sig $signal_t) + (result $error $errno_t) + ) + + ;; Temporarily yield execution of the calling thread. + ;; Note: This is similar to `sched_yield` in POSIX. + (@interface func (export "proc_sched_yield") + (result $error $errno_t) + ) + + ;; Write high-quality random data into a buffer. + ;; This function blocks when the implementation is unable to immediately + ;; provide sufficient high-quality random data. + ;; This function may execute slowly, so when large mounts of random data are + ;; required, it's advisable to use this function to seed a pseudo-random + ;; number generator, rather than to provide the random data directly. + (@interface func (export "random_get") + ;; The buffer to fill with random data. + (param $buf data) + (result $error $errno_t) + ) + + ;; Receive a message from a socket. + ;; Note: This is similar to `recv` in POSIX, though it also supports reading + ;; the data into multiple buffers in the manner of `readv`. + (@interface func (export "sock_recv") + (param $self $fd_t) + ;; List of scatter/gather vectors to which to store data. + (param $ri_data $iovec_t_array) + ;; Message flags. + (param $ri_flags $riflags_t) + (result $error $errno_t) + ;; Number of bytes stored in ri_data. + (result $ro_datalen $size_t) + ;; Message flags. + (result $ro_flags $roflags_t) + ) + + ;; Send a message on a socket. + ;; Note: This is similar to `send` in POSIX, though it also supports writing + ;; the data from multiple buffers in the manner of `writev`. + (@interface func (export "sock_send") + (param $self $fd_t) + ;; List of scatter/gather vectors to which to retrieve data + (param $si_data $ciovec_t_array) + ;; Message flags. + (param $si_flags $siflags_t) + (result $error $errno_t) + ;; Number of bytes transmitted. + (result $so_datalen $size_t) + ) + + ;; Shut down socket send and receive channels. + ;; Note: This is similar to `shutdown` in POSIX. + (@interface func (export "sock_shutdown") + (param $self $fd_t) + ;; Which channels on the socket to shut down. + (param $how $sdflags_t) + (result $error $errno_t) + ) +) From 1565100e92636ea86157ade786648716766d456e Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 29 Aug 2019 21:55:06 -0700 Subject: [PATCH 11/26] Rename `import` to `use`, since "import" already means something in wasm. --- design/wasi_unstable/wasi_unstable.widl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/wasi_unstable/wasi_unstable.widl b/design/wasi_unstable/wasi_unstable.widl index 30633d71..730f1c84 100644 --- a/design/wasi_unstable/wasi_unstable.widl +++ b/design/wasi_unstable/wasi_unstable.widl @@ -2,7 +2,7 @@ ;; ;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). -(import "typenames.wid") +(use "typenames.wid") (module $wasi_unstable ;; Linear memory used by the program. From 7013711860d0fcb9eeef0c0e1bdc7214cc982509 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 11:12:04 -0700 Subject: [PATCH 12/26] Remove the `_start` import. It isn't logically part of the `wasi_unstable` module. It's part of the platform-level ABI. --- design/wasi_unstable/wasi_unstable.widl | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.widl b/design/wasi_unstable/wasi_unstable.widl index 730f1c84..6ec0e7d6 100644 --- a/design/wasi_unstable/wasi_unstable.widl +++ b/design/wasi_unstable/wasi_unstable.widl @@ -5,12 +5,9 @@ (use "typenames.wid") (module $wasi_unstable - ;; Linear memory used by the program. + ;; Linear memory to be accessed by WASI functions that need it. (import "memory" (memory)) - ;; The program entry point. - (import "_start" (func)) - ;; Read command-line argument data. ;; The size of the array should match that returned by `wasi_args_sizes_get()` (@interface func (export "args_get") From 2e6ec0e2a1eeede32645943deb670f02fbfca7ec Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 11:13:56 -0700 Subject: [PATCH 13/26] Rename "$self" paramaters to "$fd" to be more descriptive. We're not currently using a method-oriented API, so instead of saying "self", say "fd", which is what these parameters are. --- design/wasi_unstable/wasi_unstable.widl | 68 ++++++++++++------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.widl b/design/wasi_unstable/wasi_unstable.widl index 6ec0e7d6..2cb9cfff 100644 --- a/design/wasi_unstable/wasi_unstable.widl +++ b/design/wasi_unstable/wasi_unstable.widl @@ -62,7 +62,7 @@ ;; Provide file advisory information on a file descriptor. ;; Note: This is similar to `posix_fadvise` in POSIX. (@interface func (export "fd_advise") - (param $self $fd_t) + (param $fd $fd_t) (param $offset $filesize_t) ;; The offset within the file to which the advisory applies. (param $len $filesize_t) ;; The length of the region to which the advisory applies. (param $advice $advice_t) ;; The advice. @@ -72,7 +72,7 @@ ;; Force the allocation of space in a file. ;; Note: This is similar to `posix_fallocate` in POSIX. (@interface func (export "fd_allocate") - (param $self $fd_t) + (param $fd $fd_t) ;; The offset at which to start the allocation. (param $offset $filesize_t) ;; The length of the area that is allocated. @@ -83,21 +83,21 @@ ;; Close a file descriptor. ;; Note: This is similar to `close` in POSIX. (@interface func (export "fd_close") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ) ;; Synchronize the data of a file to disk. ;; Note: This is similar to `fdatasync` in POSIX. (@interface func (export "fd_datasync") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ) ;; Get the attributes of a file descriptor. ;; Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. (@interface func (export "fd_fdstat_get") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ;; The buffer where the file descriptor's attributes are stored. (result $fdstat_t) @@ -106,7 +106,7 @@ ;; Adjust the flags associated with a file descriptor. ;; Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. (@interface func (export "fd_fdstat_set_flags") - (param $self $fd_t) + (param $fd $fd_t) ;; The desired values of the file descriptor flags. (param $flags $fdflags) (result $error $errno_t) @@ -115,7 +115,7 @@ ;; Adjust the rights associated with a file descriptor. ;; This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights (@interface func (export "fd_fdstat_set_rights") - (param $self $fd_t) + (param $fd $fd_t) ;; The desired rights of the file descriptor. (param $fs_rights_base $rights_t) (param $fs_rights_inheriting $rights_t) @@ -124,7 +124,7 @@ ;; Return the attributes of an open file. (@interface func (export "fd_filestat_get") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ;; The buffer where the file's attributes are stored. (result $fs_rights_base $rights_t) @@ -133,7 +133,7 @@ ;; Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. ;; Note: This is similar to `ftruncate` in POSIX. (@interface func (export "fd_filestat_set_size") - (param $self $fd_t) + (param $fd $fd_t) ;; The desired file size. (param $st_size $filesize_t) (result $error $errno_t) @@ -142,7 +142,7 @@ ;; Adjust the timestamps of an open file or directory. ;; Note: This is similar to `futimens` in POSIX. (@interface func (export "fd_filestat_set_times") - (param $self $fd_t) + (param $fd $fd_t) ;; The desired values of the data access timestamp. (param $st_atim $timestamp_t) ;; The desired values of the data modification timestamp. @@ -155,7 +155,7 @@ ;; Read from a file descriptor, without using and updating the file descriptor's offset. ;; Note: This is similar to `preadv` in POSIX. (@interface func (export "fd_pread") - (param $self $fd_t) + (param $fd $fd_t) ;; List of scatter/gather vectors in which to store data. (param $iovs $iovec_t_array) ;; The offset within the file at which to read. @@ -167,7 +167,7 @@ ;; Return a description of the given preopened file descriptor. (@interface func (export "fd_prestat_get") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ;; The buffer where the description is stored. (result $buf $prestat_t) @@ -175,7 +175,7 @@ ;; Return a description of the given preopened file descriptor. (@interface func (export "fd_prestat_dir_name") - (param $self $fd_t) + (param $fd $fd_t) ;; A buffer into which to write the preopened directory name. (param $path string) (result $error $errno_t) @@ -184,7 +184,7 @@ ;; Write to a file descriptor, without using and updating the file descriptor's offset. ;; Note: This is similar to `pwritev` in POSIX. (@interface func (export "fd_pwrite") - (param $self $fd_t) + (param $fd $fd_t) ;; List of scatter/gather vectors from which to retrieve data. (param $iovs $iovec_t_array) ;; The offset within the file at which to write. @@ -197,7 +197,7 @@ ;; Read from a file descriptor. ;; Note: This is similar to `readv` in POSIX. (@interface func (export "fd_read") - (param $self $fd_t) + (param $fd $fd_t) ;; List of scatter/gather vectors to which to store data. (param $iovs $iovec_t_array) (result $error $errno_t) @@ -216,7 +216,7 @@ ;; read buffer size in case it's too small to fit a single large directory ;; entry, or skip the oversized directory entry. (@interface func (export "fd_readdir") - (param $self $fd_t) + (param $fd $fd_t) ;; The buffer where directory entries are stored (param $buf data) ;; The location within the directory to start reading @@ -237,7 +237,7 @@ ;; This function provides a way to atomically renumber file descriptors, which ;; would disappear if `dup2()` were to be removed entirely. (@interface func (export "fd_renumber") - (param $self $fd_t) + (param $fd $fd_t) ;; The file descriptor to overwrite. (param $to $fd_t) (result $error $errno_t) @@ -246,7 +246,7 @@ ;; Move the offset of a file descriptor. ;; Note: This is similar to `lseek` in POSIX. (@interface func (export "fd_seek") - (param $self $fd_t) + (param $fd $fd_t) ;; The number of bytes to move. (param $offset $filedelta_t) ;; The base from which the offset is relative. @@ -259,14 +259,14 @@ ;; Synchronize the data and metadata of a file to disk. ;; Note: This is similar to `fsync` in POSIX. (@interface func (export "fd_sync") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ) ;; Return the current offset of a file descriptor. ;; Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. (@interface func (export "fd_tell") - (param $self $fd_t) + (param $fd $fd_t) (result $error $errno_t) ;; The current offset of the file descriptor, relative to the start of the file. (result $offset $filesize_t) @@ -275,7 +275,7 @@ ;; Write to a file descriptor. ;; Note: This is similar to `writev` in POSIX. (@interface func (export "fd_write") - (param $self $fd_t) + (param $fd $fd_t) ;; List of scatter/gather vectors from which to retrieve data. (param $iovs $iovec_t_array) (result $error $errno_t) @@ -286,7 +286,7 @@ ;; Create a directory. ;; Note: This is similar to `mkdirat` in POSIX. (@interface func (export "path_create_directory") - (param $self $fd_t) + (param $fd $fd_t) ;; The path at which to create the directory. (param $path string) (result $error $errno_t) @@ -295,7 +295,7 @@ ;; Return the attributes of a file or directory. ;; Note: This is similar to `stat` in POSIX. (@interface func (export "path_filestat_get") - (param $self $fd_t) + (param $fd $fd_t) ;; Flags determining the method of how the path is resolved. (param $flags $lookupflags_t) ;; The path of the file or directory to inspect. @@ -308,7 +308,7 @@ ;; Adjust the timestamps of a file or directory. ;; Note: This is similar to `utimensat` in POSIX. (@interface func (export "path_filestat_set_times") - (param $self $fd_t) + (param $fd $fd_t) ;; Flags determining the method of how the path is resolved. (param $flags $lookupflags_t) ;; The path of the file or directory to operate on. @@ -325,7 +325,7 @@ ;; Create a hard link. ;; Note: This is similar to `linkat` in POSIX. (@interface func (export "path_link") - (param $self $fd_t) + (param $fd $fd_t) ;; Flags determining the method of how the path is resolved. (param $old_flags $lookupflags_t) ;; The source path from which to link. @@ -347,7 +347,7 @@ ;; ;; Note: This is similar to `openat` in POSIX. (@interface func (export "path_open") - (param $self $fd_t) + (param $fd $fd_t) ;; Flags determining the method of how the path is resolved. (param $dirflags $lookupflags_t) ;; The relative path of the file or directory to open, relative to the @@ -373,7 +373,7 @@ ;; Read the contents of a symbolic link. ;; Note: This is similar to `readlinkat` in POSIX. (@interface func (export "path_readlink") - (param $self $fd_t) + (param $fd $fd_t) ;; The path of the symbolic link from which to read. (param $path) ;; The buffer to which to write the contents of the symbolic link. @@ -387,7 +387,7 @@ ;; Return `__WASI_ENOTEMPTY` if the directory is not empty. ;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. (@interface func (export "path_remove_directory") - (param $self $fd_t) + (param $fd $fd_t) ;; The path to a directory to remove. (param $path string) (result $error $errno_t) @@ -396,7 +396,7 @@ ;; Rename a file or directory. ;; Note: This is similar to `renameat` in POSIX. (@interface func (export "path_rename") - (param $self $fd_t) + (param $fd $fd_t) ;; The source path of the file or directory to rename. (param $old_path string) ;; The working directory at which the resolution of the new path starts. @@ -409,7 +409,7 @@ ;; Create a symbolic link. ;; Note: This is similar to `symlinkat` in POSIX. (@interface func (export "path_symlink") - (param $self $fd_t) + (param $fd $fd_t) ;; The contents of the symbolic link. (param $old_path string) ;; The destination path at which to create the symbolic link. @@ -422,7 +422,7 @@ ;; Return `__WASI_EISDIR` if the path refers to a directory. ;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. (@interface func (export "path_unlink_file") - (param $self $fd_t) + (param $fd $fd_t) ;; The path to a file to unlink. (param $path string) (result $error $errno_t) @@ -479,7 +479,7 @@ ;; Note: This is similar to `recv` in POSIX, though it also supports reading ;; the data into multiple buffers in the manner of `readv`. (@interface func (export "sock_recv") - (param $self $fd_t) + (param $fd $fd_t) ;; List of scatter/gather vectors to which to store data. (param $ri_data $iovec_t_array) ;; Message flags. @@ -495,7 +495,7 @@ ;; Note: This is similar to `send` in POSIX, though it also supports writing ;; the data from multiple buffers in the manner of `writev`. (@interface func (export "sock_send") - (param $self $fd_t) + (param $fd $fd_t) ;; List of scatter/gather vectors to which to retrieve data (param $si_data $ciovec_t_array) ;; Message flags. @@ -508,7 +508,7 @@ ;; Shut down socket send and receive channels. ;; Note: This is similar to `shutdown` in POSIX. (@interface func (export "sock_shutdown") - (param $self $fd_t) + (param $fd $fd_t) ;; Which channels on the socket to shut down. (param $how $sdflags_t) (result $error $errno_t) From a75b0517e36de249dd2933baaba2f671cdce2b9d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 15:23:56 -0700 Subject: [PATCH 14/26] Give names to union types. --- design/wasi_unstable/typenames.widl | 80 ++++++++++++++++------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/design/wasi_unstable/typenames.widl b/design/wasi_unstable/typenames.widl index df97290e..53b01bde 100644 --- a/design/wasi_unstable/typenames.widl +++ b/design/wasi_unstable/typenames.widl @@ -488,17 +488,21 @@ (field $error $errno_t) ;; The type of the event that occurred. (field $type $eventtype_t) - (field $u - (union - ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: - (field $fd_readwrite - (struct - ;; The number of bytes available for reading or writing. - (field $nbytes $filesize_t) - ;; The state of the file descriptor. - (field $flags $eventrwflags_t) - ) - ) + ;; The contents of the event. + (field $u $event_u)) + ) +) + +;; The contents of an $event_t. +(typename $event_u + (union + ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: + (field $fd_readwrite + (struct + ;; The number of bytes available for reading or writing. + (field $nbytes $filesize_t) + ;; The state of the file descriptor. + (field $flags $eventrwflags_t) ) ) ) @@ -549,31 +553,35 @@ (field $userdata $userdata_t) ;; The type of the event to which to subscribe. (field $type $eventtype_t) - (field $u - (union - ;; When type is `__WASI_EVENTTYPE_CLOCK`: - (field $clock - (struct - ;; The user-defined unique identifier of the clock. - (field $identifier $userdata_t) - ;; The clock against which to compare the timestamp. - (field $clock_id $clockid_t) - ;; The absolute or relative timestamp. - (field $timeout $timestamp_t) - ;; The amount of time that the implementation may wait additionally - ;; to coalesce with other events. - ;; - ;; Flags specifying whether the timeout is absolute or relative - (field $precision $timestamp_t) - ) - ) - ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: - (field $fd_readwrite - (struct - ;; The file descriptor on which to wait for it to become ready for reading or writing. - (field $file_descriptor $fd_t) - ) - ) + ;; The contents of the subscription. + (field $u $subscription_u) + ) +) + +;; The contents of a $subscription_t. +(typename $subscription_u + (union + ;; When type is `__WASI_EVENTTYPE_CLOCK`: + (field $clock + (struct + ;; The user-defined unique identifier of the clock. + (field $identifier $userdata_t) + ;; The clock against which to compare the timestamp. + (field $clock_id $clockid_t) + ;; The absolute or relative timestamp. + (field $timeout $timestamp_t) + ;; The amount of time that the implementation may wait additionally + ;; to coalesce with other events. + ;; + ;; Flags specifying whether the timeout is absolute or relative + (field $precision $timestamp_t) + ) + ) + ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: + (field $fd_readwrite + (struct + ;; The file descriptor on which to wait for it to become ready for reading or writing. + (field $file_descriptor $fd_t) ) ) ) From 7b07f0f1307a44958eb2c8057405f736ee7ec19c Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 15:33:18 -0700 Subject: [PATCH 15/26] Give names to struct types. --- design/wasi_unstable/typenames.widl | 69 +++++++++++++++++------------ 1 file changed, 40 insertions(+), 29 deletions(-) diff --git a/design/wasi_unstable/typenames.widl b/design/wasi_unstable/typenames.widl index 53b01bde..90aac966 100644 --- a/design/wasi_unstable/typenames.widl +++ b/design/wasi_unstable/typenames.widl @@ -497,14 +497,18 @@ (typename $event_u (union ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: - (field $fd_readwrite - (struct - ;; The number of bytes available for reading or writing. - (field $nbytes $filesize_t) - ;; The state of the file descriptor. - (field $flags $eventrwflags_t) - ) - ) + (field $fd_readwrite $event_fd_readwrite_t) + ) +) + +;; The contents of an $event_t when type is `__WASI_EVENTTYPE_FD_READ` or +;; `__WASI_EVENTTYPE_FD_WRITE`. +(typename $event_fd_readwrite_t + (struct + ;; The number of bytes available for reading or writing. + (field $nbytes $filesize_t) + ;; The state of the file descriptor. + (field $flags $eventrwflags_t) ) ) @@ -562,28 +566,35 @@ (typename $subscription_u (union ;; When type is `__WASI_EVENTTYPE_CLOCK`: - (field $clock - (struct - ;; The user-defined unique identifier of the clock. - (field $identifier $userdata_t) - ;; The clock against which to compare the timestamp. - (field $clock_id $clockid_t) - ;; The absolute or relative timestamp. - (field $timeout $timestamp_t) - ;; The amount of time that the implementation may wait additionally - ;; to coalesce with other events. - ;; - ;; Flags specifying whether the timeout is absolute or relative - (field $precision $timestamp_t) - ) - ) + (field $clock $subscription_clock_t) ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: - (field $fd_readwrite - (struct - ;; The file descriptor on which to wait for it to become ready for reading or writing. - (field $file_descriptor $fd_t) - ) - ) + (field $fd_readwrite $subscription_fd_readwrite_t) + ) +) + +;; The contents of a $subscription_t when type is `__WASI_EVENTTYPE_CLOCK`. +(typename $subscription_clock_t + (struct + ;; The user-defined unique identifier of the clock. + (field $identifier $userdata_t) + ;; The clock against which to compare the timestamp. + (field $clock_id $clockid_t) + ;; The absolute or relative timestamp. + (field $timeout $timestamp_t) + ;; The amount of time that the implementation may wait additionally + ;; to coalesce with other events. + ;; + ;; Flags specifying whether the timeout is absolute or relative + (field $precision $timestamp_t) + ) +) + +;; The contents of a $subscription_t when type is type is +;; `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`. +(typename $subscription_fd_readwrite_t + (struct + ;; The file descriptor on which to wait for it to become ready for reading or writing. + (field $file_descriptor $fd_t) ) ) From a9702286b4895199a23edb5efc4cd6b09daaf3a5 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 16:55:50 -0700 Subject: [PATCH 16/26] Rename .widl to .witx. --- design/wasi_unstable/{typenames.widl => typenames.witx} | 0 design/wasi_unstable/{wasi_unstable.widl => wasi_unstable.witx} | 0 2 files changed, 0 insertions(+), 0 deletions(-) rename design/wasi_unstable/{typenames.widl => typenames.witx} (100%) rename design/wasi_unstable/{wasi_unstable.widl => wasi_unstable.witx} (100%) diff --git a/design/wasi_unstable/typenames.widl b/design/wasi_unstable/typenames.witx similarity index 100% rename from design/wasi_unstable/typenames.widl rename to design/wasi_unstable/typenames.witx diff --git a/design/wasi_unstable/wasi_unstable.widl b/design/wasi_unstable/wasi_unstable.witx similarity index 100% rename from design/wasi_unstable/wasi_unstable.widl rename to design/wasi_unstable/wasi_unstable.witx From dfd5883ec63581dd5fd2e232a131fc86cef45b43 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Wed, 4 Sep 2019 17:10:34 -0700 Subject: [PATCH 17/26] Fix extra close paren. --- design/wasi_unstable/typenames.witx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 90aac966..06df2177 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -489,7 +489,7 @@ ;; The type of the event that occurred. (field $type $eventtype_t) ;; The contents of the event. - (field $u $event_u)) + (field $u $event_u) ) ) From a2931a0cb3c78940ab561406b375033fa708d342 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Sep 2019 08:57:45 -0700 Subject: [PATCH 18/26] Use ciovec_t for fd_write and fd_pwrite. --- design/wasi_unstable/wasi_unstable.witx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.witx b/design/wasi_unstable/wasi_unstable.witx index 2cb9cfff..54ea0765 100644 --- a/design/wasi_unstable/wasi_unstable.witx +++ b/design/wasi_unstable/wasi_unstable.witx @@ -186,7 +186,7 @@ (@interface func (export "fd_pwrite") (param $fd $fd_t) ;; List of scatter/gather vectors from which to retrieve data. - (param $iovs $iovec_t_array) + (param $iovs $ciovec_t_array) ;; The offset within the file at which to write. (param $offset $filesize_t) (result $error $errno_t) @@ -277,7 +277,7 @@ (@interface func (export "fd_write") (param $fd $fd_t) ;; List of scatter/gather vectors from which to retrieve data. - (param $iovs $iovec_t_array) + (param $iovs $ciovec_t_array) (result $error $errno_t) ;; The number of bytes written. (result $nwritten $size_t) From bb6d142990a52d94decadf4a4d9a8a5056baa3b4 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Sep 2019 09:00:32 -0700 Subject: [PATCH 19/26] Don't use interface types to pass mutable buffers. This adds new constructs, (@witx pointer T), and (@witx const_pointer T), and uses them to describe raw pointers to linear memory buffers. For now, these can be treated essentially the same as $uintptr_t, though in the future we may do something more sophisticated. --- design/wasi_unstable/typenames.witx | 6 ++---- design/wasi_unstable/wasi_unstable.witx | 22 ++++++++++++++-------- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 06df2177..87ee29d6 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -3,8 +3,6 @@ ;; Some content here is derived from [CloudABI](https://github.com/NuxiNL/cloudabi). (typename $size_t u32) -(typename $uintptr_t u32) -(typename $string_array (array string)) ;; Non-negative file size or length of a region within a file. (typename $filesize_t u64) @@ -283,7 +281,7 @@ (typename $iovec_t (struct ;; The address and length of the buffer to be filled. - (field $buf $uintptr_t) + (field $buf (@witx pointer u8)) (field $buf_len $size_t) ) ) @@ -292,7 +290,7 @@ (typename $ciovec_t (struct ;; The address and length of the buffer to be written. - (field $buf $uintptr_t) + (field $buf (@witx const_pointer u8)) (field $buf_len $size_t) ) ) diff --git a/design/wasi_unstable/wasi_unstable.witx b/design/wasi_unstable/wasi_unstable.witx index 54ea0765..23f8931e 100644 --- a/design/wasi_unstable/wasi_unstable.witx +++ b/design/wasi_unstable/wasi_unstable.witx @@ -11,8 +11,9 @@ ;; Read command-line argument data. ;; The size of the array should match that returned by `wasi_args_sizes_get()` (@interface func (export "args_get") + (param $argv (@witx pointer (@witx pointer u8))) + (param $argv_buf (@witx pointer u8)) (result $error $errno_t) - (result $argv $string_array) ) ;; Return command-line argument data sizes. (@interface func (export "args_sizes_get") @@ -26,8 +27,9 @@ ;; Read environment variable data. ;; The sizes of the buffers should match that returned by `environ.sizes_get()`. (@interface func (export "environ_get") + (param $environ (@witx pointer (@witx pointer u8))) + (param $environ_buf (@witx pointer u8)) (result $error $errno_t) - (result $argv $string_array) ) ;; Return command-line argument data sizes. (@interface func (export "environ_sizes_get") @@ -177,7 +179,8 @@ (@interface func (export "fd_prestat_dir_name") (param $fd $fd_t) ;; A buffer into which to write the preopened directory name. - (param $path string) + (param $path (@witx pointer u8)) + (param $path_len $size_t) (result $error $errno_t) ) @@ -218,7 +221,8 @@ (@interface func (export "fd_readdir") (param $fd $fd_t) ;; The buffer where directory entries are stored - (param $buf data) + (param $buf (@witx pointer u8)) + (param $buf_len $size_t) ;; The location within the directory to start reading (param $cookie $dircookie_t) (result $error $errno_t) @@ -377,7 +381,8 @@ ;; The path of the symbolic link from which to read. (param $path) ;; The buffer to which to write the contents of the symbolic link. - (param $buf string) + (param $buf (@witx pointer u8)) + (param $buf_len $size_t) (result $error $errno_t) ;; The number of bytes placed in the buffer. (result $bufused $size_t) @@ -431,9 +436,9 @@ ;; Concurrently poll for the occurrence of a set of events. (@interface func (export "poll_oneoff") ;; The events to which to subscribe. - (param $in $subscription_t) + (param $in (const_pointer $subscription_t)) ;; The events that have occurred. - (param $out $event_t) + (param $out (@witx pointer $event_t)) ;; Both the number of subscriptions and events. (param $nsubscriptions $size_t) (result $error $errno_t) @@ -471,7 +476,8 @@ ;; number generator, rather than to provide the random data directly. (@interface func (export "random_get") ;; The buffer to fill with random data. - (param $buf data) + (param $buf (@witx pointer u8)) + (param $buf_len $size_t) (result $error $errno_t) ) From fc69216acfc8a6dfae202d8e10c34befd448c788 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Sep 2019 09:21:13 -0700 Subject: [PATCH 20/26] Fix a missing @witx. --- design/wasi_unstable/wasi_unstable.witx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/design/wasi_unstable/wasi_unstable.witx b/design/wasi_unstable/wasi_unstable.witx index 23f8931e..82b75ef2 100644 --- a/design/wasi_unstable/wasi_unstable.witx +++ b/design/wasi_unstable/wasi_unstable.witx @@ -436,7 +436,7 @@ ;; Concurrently poll for the occurrence of a set of events. (@interface func (export "poll_oneoff") ;; The events to which to subscribe. - (param $in (const_pointer $subscription_t)) + (param $in (@witx const_pointer $subscription_t)) ;; The events that have occurred. (param $out (@witx pointer $event_t)) ;; Both the number of subscriptions and events. From 2ec3a17030edb7b7418c74586aa96556f81391ae Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Sep 2019 09:46:18 -0700 Subject: [PATCH 21/26] Give each field its own comment, instead of commenting them as a group. --- design/wasi_unstable/typenames.witx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 87ee29d6..021c750a 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -280,8 +280,9 @@ ;; A region of memory for scatter/gather reads. (typename $iovec_t (struct - ;; The address and length of the buffer to be filled. + ;; 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_t) ) ) @@ -289,8 +290,9 @@ ;; A region of memory for scatter/gather writes. (typename $ciovec_t (struct - ;; The address and length of the buffer to be written. + ;; 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_t) ) ) From fe65a69ade7e2cb581257b930891eb306b2861e2 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Thu, 5 Sep 2019 12:25:59 -0700 Subject: [PATCH 22/26] Add a document on `witx`. --- design/wasi_unstable/typenames.witx | 3 +++ design/wasi_unstable/wasi_unstable.witx | 3 +++ docs/witx.md | 30 +++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 docs/witx.md diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 021c750a..14fd81e4 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -1,6 +1,9 @@ ;; Type names used by the wasi_unstable module type. ;; ;; 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. (typename $size_t u32) diff --git a/design/wasi_unstable/wasi_unstable.witx b/design/wasi_unstable/wasi_unstable.witx index 82b75ef2..c47541b9 100644 --- a/design/wasi_unstable/wasi_unstable.witx +++ b/design/wasi_unstable/wasi_unstable.witx @@ -1,6 +1,9 @@ ;; The wasi_unstable module type. ;; ;; 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. (use "typenames.wid") diff --git a/docs/witx.md b/docs/witx.md new file mode 100644 index 00000000..db267992 --- /dev/null +++ b/docs/witx.md @@ -0,0 +1,30 @@ +# Know your `witx` + +The `witx` file format is an experimental format which is based on the +[module types] text format (`wit`), (which is in turn based on the +[wat format], which is based on [S-expressions]). It adds some features +using the same syntax as [interface types], some features with syntax +similar to [gc types], as well as a few special features of its own. + +`witx` is actively evolving. Expect backwards-incompatible changes, +particularly in the areas where `witx` differs from `wit`. + +The initial goal for `witx` is just to have a language suitable for +expressing [WASI] APIs in, to serve as the vocabulary for proposing changes +to existing APIs and proposing new APIs. Initially, while it uses some of +the syntax and concepts from interface types, it doesn't currently imply the +full interface types specification, or the use of the interface types custom +sections. + +We expect that eventually we will transition to using the full interface +types specification. Until then, the goals here are to remain aligned with +interface types and other relevant WebAssembly standards and proposals +wherever practical, and to be an input into the design process of interface +types. + +[module types]: https://github.com/WebAssembly/module-types/blob/master/proposals/module-types/Overview.md +[interface types]: https://github.com/WebAssembly/interface-types/blob/master/proposals/interface-types/Explainer.md +[gc types]: https://github.com/WebAssembly/gc +[wat format]: https://webassembly.github.io/spec/core/bikeshed/index.html#text-format%E2%91%A0 +[S-expressions]: https://en.wikipedia.org/wiki/S-expression +[WASI]: https://github.com/WebAssembly/WASI From df8e670290e6aa84565ad581f11485f90d64498b Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 9 Sep 2019 10:22:56 -0700 Subject: [PATCH 23/26] Add $prestat_t and friends. --- design/wasi_unstable/typenames.witx | 34 +++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 14fd81e4..226ec4e7 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -719,3 +719,37 @@ (flag $SHUT_WR) ) ) + +;; Information about a pre-opened capability. +(typename $prestat_t + (struct + ;; The type of the pre-opened capability. + (field $pr_type $preopentype_t) + ;; The contents of the information. + (field $u $prestat_u) + ) +) + +;; Identifiers for preopened capabilities. +(typename preopentype_t + (enum u8 + ;; A pre-opened directory. + $PREOPENTYPE_DIR + ) +) + +;; The contents of an $prestat_t. +(typename $prestat_u + (union + ;; When type is `PREOPENTYPE_DIR`: + (field $dir $prestat_dir) + ) +) + +;; The contents of a $prestat_t when type is `PREOPENTYPE_DIR`. +(typename $prestat_dir + (struct + ;; The length of the directory name for use with `fd_prestat_dir_name`. + (field $pr_name_len $size_t) + ) +) From 6497e90b45c8967944b72dbffd6ae07034d22b59 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Mon, 9 Sep 2019 10:28:25 -0700 Subject: [PATCH 24/26] Remove `__wasi_` and `__WASI_` prefixes from names in comments. --- design/wasi_unstable/typenames.witx | 141 ++++++++++++------------ design/wasi_unstable/wasi_unstable.witx | 4 +- 2 files changed, 71 insertions(+), 74 deletions(-) diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 226ec4e7..4bab3073 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -197,79 +197,78 @@ ;; File descriptor rights, determining which actions may be performed. (typename $rights_t (flags u64 - ;; The right to invoke `__wasi_fd_datasync()`. + ;; The right to invoke `fd_datasync`. ;; - ;; If `__WASI_RIGHT_PATH_OPEN` is set, includes the right to invoke - ;; `__wasi_path_open()` with `__WASI_FDFLAG_DSYNC`. + ;; If `RIGHT_PATH_OPEN` is set, includes the right to invoke + ;; `path_open` with `FDFLAG_DSYNC`. (flag $RIGHT_FD_DATASYNC) - ;; The right to invoke `__wasi_fd_read()` and `__wasi_sock_recv()`. + ;; The right to invoke `fd_read` and `sock_recv`. ;; - ;; If `__WASI_RIGHT_FD_SEEK` is set, includes the right to invoke - ;; `__wasi_fd_pread()`. + ;; If `RIGHT_FD_SEEK` is set, includes the right to invoke `fd_pread`. (flag $RIGHT_FD_READ) - ;; The right to invoke `__wasi_fd_seek()`. This flag implies `__WASI_RIGHT_FD_TELL`. + ;; The right to invoke `fd_seek`. This flag implies `RIGHT_FD_TELL`. (flag $RIGHT_FD_SEEK) - ;; The right to invoke `__wasi_fd_fdstat_set_flags()`. + ;; The right to invoke `fd_fdstat_set_flags`. (flag $RIGHT_FD_FDSTAT_SET_FLAGS) - ;; The right to invoke `__wasi_fd_sync()`. + ;; The right to invoke `fd_sync`. ;; - ;; If `__WASI_RIGHT_PATH_OPEN` is set, includes the right to invoke - ;; `__wasi_path_open()` with `__WASI_FDFLAG_RSYNC` and `__WASI_FDFLAG_DSYNC`. + ;; If `RIGHT_PATH_OPEN` is set, includes the right to invoke + ;; `path_open` with `FDFLAG_RSYNC` and `FDFLAG_DSYNC`. (flag $RIGHT_FD_SYNC) - ;; The right to invoke `__wasi_fd_seek()` in such a way that the file offset - ;; remains unaltered (i.e., `__WASI_WHENCE_CUR` with offset zero), or to - ;; invoke `__wasi_fd_tell()`. + ;; 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`. (flag $RIGHT_FD_TELL) - ;; The right to invoke `__wasi_fd_write()` and `__wasi_sock_send()`. - ;; If `__WASI_RIGHT_FD_SEEK` is set, includes the right to invoke `__wasi_fd_pwrite()`. + ;; The right to invoke `fd_write` and `sock_send`. + ;; If `RIGHT_FD_SEEK` is set, includes the right to invoke `fd_pwrite`. (flag $RIGHT_FD_WRITE) - ;; The right to invoke `__wasi_fd_advise()`. + ;; The right to invoke `fd_advise`. (flag $RIGHT_FD_ADVISE) - ;; The right to invoke `__wasi_fd_allocate()`. + ;; The right to invoke `fd_allocate`. (flag $RIGHT_FD_ALLOCATE) - ;; The right to invoke `__wasi_path_create_directory()`. + ;; The right to invoke `path_create_directory`. (flag $RIGHT_PATH_CREATE_DIRECTORY) - ;; If `__WASI_RIGHT_PATH_OPEN` is set, the right to invoke `__wasi_path_open()` with `__WASI_O_CREAT`. + ;; If `RIGHT_PATH_OPEN` is set, the right to invoke `path_open` with `O_CREAT`. (flag $RIGHT_PATH_CREATE_FILE) - ;; The right to invoke `__wasi_path_link()` with the file descriptor as the + ;; The right to invoke `path_link` with the file descriptor as the ;; source directory. (flag $RIGHT_PATH_LINK_SOURCE) - ;; The right to invoke `__wasi_path_link()` with the file descriptor as the + ;; The right to invoke `path_link` with the file descriptor as the ;; target directory. (flag $RIGHT_PATH_LINK_TARGET) - ;; The right to invoke `__wasi_path_open()`. + ;; The right to invoke `path_open`. (flag $RIGHT_PATH_OPEN) - ;; The right to invoke `__wasi_fd_readdir()`. + ;; The right to invoke `fd_readdir`. (flag $RIGHT_FD_READDIR) - ;; The right to invoke `__wasi_path_readlink()`. + ;; The right to invoke `path_readlink`. (flag $RIGHT_PATH_READLINK) - ;; The right to invoke `__wasi_path_rename()` with the file descriptor as the source directory. + ;; The right to invoke `path_rename` with the file descriptor as the source directory. (flag $RIGHT_PATH_RENAME_SOURCE) - ;; The right to invoke `__wasi_path_rename()` with the file descriptor as the target directory. + ;; The right to invoke `path_rename` with the file descriptor as the target directory. (flag $RIGHT_PATH_RENAME_TARGET) - ;; The right to invoke `__wasi_path_filestat_get()`. + ;; The right to invoke `path_filestat_get`. (flag $RIGHT_PATH_FILESTAT_GET) - ;; The right to change a file's size (there is no `__wasi_path_filestat_set_size()`). - ;; If `__WASI_RIGHT_PATH_OPEN` is set, includes the right to invoke `__wasi_path_open()` with `__WASI_O_TRUNC`. + ;; The right to change a file's size (there is no `path_filestat_set_size`). + ;; If `RIGHT_PATH_OPEN` is set, includes the right to invoke `path_open` with `O_TRUNC`. (flag $RIGHT_PATH_FILESTAT_SET_SIZE) - ;; The right to invoke `__wasi_path_filestat_set_times()`. + ;; The right to invoke `path_filestat_set_times`. (flag $RIGHT_PATH_FILESTAT_SET_TIMES) - ;; The right to invoke `__wasi_fd_filestat_get()`. + ;; The right to invoke `fd_filestat_get`. (flag $RIGHT_FD_FILESTAT_GET) - ;; The right to invoke `__wasi_fd_filestat_set_size()`. + ;; The right to invoke `fd_filestat_set_size`. (flag $RIGHT_FD_FILESTAT_SET_SIZE) - ;; The right to invoke `__wasi_fd_filestat_set_times()`. + ;; The right to invoke `fd_filestat_set_times`. (flag $RIGHT_FD_FILESTAT_SET_TIMES) - ;; The right to invoke `__wasi_path_symlink()`. + ;; The right to invoke `path_symlink`. (flag $RIGHT_PATH_SYMLINK) - ;; The right to invoke `__wasi_path_unlink_file()`. + ;; The right to invoke `path_unlink_file`. (flag $RIGHT_PATH_UNLINK_FILE) - ;; The right to invoke `__wasi_path_remove_directory()`. + ;; The right to invoke `path_remove_directory`. (flag $RIGHT_PATH_REMOVE_DIRECTORY) - ;; If `__WASI_RIGHT_FD_READ` is set, includes the right to invoke `__wasi_poll_oneoff()` to subscribe to `__WASI_EVENTTYPE_FD_READ`. - ;; If `__WASI_RIGHT_FD_WRITE` is set, includes the right to invoke `__wasi_poll_oneoff()` to subscribe to `__WASI_EVENTTYPE_FD_WRITE`. + ;; If `RIGHT_FD_READ` is set, includes the right to invoke `poll_oneoff` to subscribe to `EVENTTYPE_FD_READ`. + ;; If `RIGHT_FD_WRITE` is set, includes the right to invoke `poll_oneoff` to subscribe to `EVENTTYPE_FD_WRITE`. (flag $RIGHT_POLL_FD_READWRITE) - ;; The right to invoke `__wasi_sock_shutdown()`. + ;; The right to invoke `sock_shutdown`. (flag $RIGHT_SOCK_SHUTDOWN) ) ) @@ -381,15 +380,13 @@ ;; Rights that apply to this file descriptor. (field $fs_rights_base $rights_t) ;; Maximum set of rights that may be installed on new file descriptors that - ;; are created through this file descriptor, e.g., through - ;; `__wasi_path_open()`. + ;; are created through this file descriptor, e.g., through `path_open`. (field $fs_rights_inheriting $rights_t) ) ) ;; Identifier for a device containing a file system. Can be used in combination -;; with __wasi_inode_t to uniquely identify a file or directory in the -;; filesystem. +;; with `inode_t` to uniquely identify a file or directory in the filesystem. (typename $device_t u64) ;; The type of a file descriptor or file. @@ -417,13 +414,13 @@ ;; Which file time attributes to adjust. (typename $fstflags_t (flags u16 - ;; Adjust the last data access timestamp to the value stored in __wasi_filestat_t::st_atim. + ;; Adjust the last data access timestamp to the value stored in `filestat_t::st_atim`. (flag $FILESTAT_SET_ATIM) - ;; Adjust the last data access timestamp to the time of clock `__WASI_CLOCK_REALTIME`. + ;; Adjust the last data access timestamp to the time of clock `CLOCK_REALTIME`. (flag $FILESTAT_SET_ATIM_NOW) - ;; Adjust the last data modification timestamp to the value stored in __wasi_filestat_t::st_mtim. + ;; Adjust the last data modification timestamp to the value stored in `filestat_t::st_mtim`. (flag $FILESTAT_SET_MTIM) - ;; Adjust the last data modification timestamp to the time of clock `__WASI_CLOCK_REALTIME`. + ;; Adjust the last data modification timestamp to the time of clock `CLOCK_REALTIME`. (flag $FILESTAT_SET_MTIM_NOW) ) ) @@ -439,7 +436,7 @@ ) ) -;; Open flags used by `__wasi_path_open()`. +;; Open flags used by `path_open`. (typename $oflags_t (flags u16 ;; Create file if it does not exist. @@ -485,7 +482,7 @@ ;; An event that occurred. (typename $event_t (struct - ;; User-provided value that got attached to __wasi_subscription_t::userdata. + ;; User-provided value that got attached to `subscription_t::userdata`. (field $userdata $userdata_t) ;; If non-zero, an error that occurred while processing the subscription request. (field $error $errno_t) @@ -499,13 +496,13 @@ ;; The contents of an $event_t. (typename $event_u (union - ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: + ;; When type is `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`: (field $fd_readwrite $event_fd_readwrite_t) ) ) -;; The contents of an $event_t when type is `__WASI_EVENTTYPE_FD_READ` or -;; `__WASI_EVENTTYPE_FD_WRITE`. +;; The contents of an $event_t when type is `EVENTTYPE_FD_READ` or +;; `EVENTTYPE_FD_WRITE`. (typename $event_fd_readwrite_t (struct ;; The number of bytes available for reading or writing. @@ -516,7 +513,7 @@ ) ;; The state of the file descriptor subscribed to with -;; `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`. +;; `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`. (typename $eventrwflags_t (flags u16 ;; The peer of this socket has closed or disconnected. @@ -527,27 +524,27 @@ ;; Type of a subscription to an event or its occurrence. (typename $eventtype_t (flags u8 - ;; The time value of clock __wasi_subscription_t::u.clock.clock_id has - ;; reached timestamp __wasi_subscription_t::u.clock.timeout. + ;; The time value of clock `subscription_t::u.clock.clock_id` has + ;; reached timestamp `subscription_t::u.clock.timeout`. (flag $EVENTTYPE_CLOCK) - ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has data + ;; File descriptor `subscription_t::u.fd_readwrite.fd` has data ;; available for reading. This event always triggers for regular files. (flag $EVENTTYPE_FD_READ) - ;; File descriptor __wasi_subscription_t::u.fd_readwrite.fd has capacity + ;; File descriptor `subscription_t::u.fd_readwrite.fd` has capacity ;; available for writing. This event always triggers for regular files. (flag $EVENTTYPE_FD_WRITE) ) ) ;; Flags determining how to interpret the timestamp provided in -;; __wasi_subscription_t::u.clock.timeout. +;; `subscription_t::u.clock.timeout.` (typename $subclockflags_t (flags u16 ;; If set, treat the timestamp provided in - ;; __wasi_subscription_t::u.clock.timeout as an absolute timestamp of clock - ;; __wasi_subscription_t::u.clock.clock_id. If clear, treat the timestamp - ;; provided in __wasi_subscription_t::u.clock.timeout relative to the - ;; current time value of clock __wasi_subscription_t::u.clock.clock_id. + ;; `subscription_t::u.clock.timeout` as an absolute timestamp of clock + ;; `subscription_t::u.clock.clock_id.` If clear, treat the timestamp + ;; provided in `subscription_t::u.clock.timeout` relative to the + ;; current time value of clock `subscription_t::u.clock.clock_id.` (flag $SUBSCRIPTION_CLOCK_ABSTIME) ) ) @@ -556,7 +553,7 @@ (typename $subscription_t (struct ;; User-provided value that is attached to the subscription in the - ;; implementation and returned through __wasi_event_t::userdata. + ;; implementation and returned through `event_t::userdata`. (field $userdata $userdata_t) ;; The type of the event to which to subscribe. (field $type $eventtype_t) @@ -568,14 +565,14 @@ ;; The contents of a $subscription_t. (typename $subscription_u (union - ;; When type is `__WASI_EVENTTYPE_CLOCK`: + ;; When type is `EVENTTYPE_CLOCK`: (field $clock $subscription_clock_t) - ;; When type is `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`: + ;; When type is `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`: (field $fd_readwrite $subscription_fd_readwrite_t) ) ) -;; The contents of a $subscription_t when type is `__WASI_EVENTTYPE_CLOCK`. +;; The contents of a $subscription_t when type is `EVENTTYPE_CLOCK`. (typename $subscription_clock_t (struct ;; The user-defined unique identifier of the clock. @@ -593,7 +590,7 @@ ) ;; The contents of a $subscription_t when type is type is -;; `__WASI_EVENTTYPE_FD_READ` or `__WASI_EVENTTYPE_FD_WRITE`. +;; `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`. (typename $subscription_fd_readwrite_t (struct ;; The file descriptor on which to wait for it to become ready for reading or writing. @@ -688,7 +685,7 @@ ) ) -;; Flags provided to `__wasi_sock_recv()`. +;; Flags provided to `sock_recv`. (typename $riflags_t (flags u16 ;; Returns the message without removing it from the socket's receive queue. @@ -698,15 +695,15 @@ ) ) -;; Flags returned by `__wasi_sock_recv()`. +;; Flags returned by `sock_recv`. (typename $roflags_t (flags u16 - ;; Returned by `__wasi_sock_recv()`: Message data has been truncated. + ;; Returned by `sock_recv`: Message data has been truncated. (flag $SOCK_RECV_DATA_TRUNCATED) ) ) -;; Flags provided to `__wasi_sock_send()`. As there are currently no flags +;; Flags provided to `sock_send`. As there are currently no flags ;; defined, it must be set to zero. (typename $siflags_t u16) diff --git a/design/wasi_unstable/wasi_unstable.witx b/design/wasi_unstable/wasi_unstable.witx index c47541b9..4a48cc38 100644 --- a/design/wasi_unstable/wasi_unstable.witx +++ b/design/wasi_unstable/wasi_unstable.witx @@ -392,7 +392,7 @@ ) ;; Remove a directory. - ;; Return `__WASI_ENOTEMPTY` if the directory is not empty. + ;; Return `ENOTEMPTY` if the directory is not empty. ;; Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. (@interface func (export "path_remove_directory") (param $fd $fd_t) @@ -427,7 +427,7 @@ ;; Unlink a file. - ;; Return `__WASI_EISDIR` if the path refers to a directory. + ;; Return `EISDIR` if the path refers to a directory. ;; Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. (@interface func (export "path_unlink_file") (param $fd $fd_t) From 1ce9ef4ef24d5bfb6b7ff308c97733e9c0d1ac0d Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 10 Sep 2019 15:12:48 -0700 Subject: [PATCH 25/26] Pick up some validation fixes from lucet-idl. See https://github.com/fastly/lucet/pull/275/files#diff-1ac8557cf1c286d69d13ccaa4b21d291 --- design/wasi_unstable/wasi_unstable.witx | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/design/wasi_unstable/wasi_unstable.witx b/design/wasi_unstable/wasi_unstable.witx index 4a48cc38..6d4bea54 100644 --- a/design/wasi_unstable/wasi_unstable.witx +++ b/design/wasi_unstable/wasi_unstable.witx @@ -5,7 +5,7 @@ ;; This is a `witx` file. See [here](https://github.com/WebAssembly/WASI/tree/master/docs/witx.md) ;; for an explanation of what that means. -(use "typenames.wid") +(use "typenames.witx") (module $wasi_unstable ;; Linear memory to be accessed by WASI functions that need it. @@ -105,7 +105,7 @@ (param $fd $fd_t) (result $error $errno_t) ;; The buffer where the file descriptor's attributes are stored. - (result $fdstat_t) + (result $stat $fdstat_t) ) ;; Adjust the flags associated with a file descriptor. @@ -113,7 +113,7 @@ (@interface func (export "fd_fdstat_set_flags") (param $fd $fd_t) ;; The desired values of the file descriptor flags. - (param $flags $fdflags) + (param $flags $fdflags_t) (result $error $errno_t) ) @@ -332,13 +332,13 @@ ;; Create a hard link. ;; Note: This is similar to `linkat` in POSIX. (@interface func (export "path_link") - (param $fd $fd_t) + (param $old_fd $fd_t) ;; Flags determining the method of how the path is resolved. (param $old_flags $lookupflags_t) ;; The source path from which to link. (param $old_path string) ;; The working directory at which the resolution of the new path starts. - (param $new_fd $path) + (param $new_fd $fd_t) ;; The destination path at which to create the hard link. (param $new_path string) (result $error $errno_t) @@ -382,7 +382,7 @@ (@interface func (export "path_readlink") (param $fd $fd_t) ;; The path of the symbolic link from which to read. - (param $path) + (param $path string) ;; The buffer to which to write the contents of the symbolic link. (param $buf (@witx pointer u8)) (param $buf_len $size_t) @@ -408,7 +408,7 @@ ;; The source path of the file or directory to rename. (param $old_path string) ;; The working directory at which the resolution of the new path starts. - (param $new_fd $fd) + (param $new_fd $fd_t) ;; The destination path to which to rename the file or directory. (param $new_path string) (result $error $errno_t) From 2cf06aa10130b1fd54804730f29c9c59c378d372 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 10 Sep 2019 15:24:32 -0700 Subject: [PATCH 26/26] Reorder typenames so that definitions precede uses. The wat format allows forward references to '$' identifiers, so we'll probably have to support this eventually too, but for now, reorder things to make it easy to process. --- design/wasi_unstable/typenames.witx | 202 ++++++++++++++-------------- 1 file changed, 101 insertions(+), 101 deletions(-) diff --git a/design/wasi_unstable/typenames.witx b/design/wasi_unstable/typenames.witx index 4bab3073..1d33a35f 100644 --- a/design/wasi_unstable/typenames.witx +++ b/design/wasi_unstable/typenames.witx @@ -276,9 +276,6 @@ ;; A file descriptor index. (typename $fd_t u32) -(typename $iovec_t_array (array $iovec_t)) -(typename $ciovec_t_array (array $ciovec_t)) - ;; A region of memory for scatter/gather reads. (typename $iovec_t (struct @@ -299,6 +296,9 @@ ) ) +(typename $iovec_t_array (array $iovec_t)) +(typename $ciovec_t_array (array $ciovec_t)) + ;; Relative offset within a file. (typename $filedelta_t s64) @@ -317,9 +317,34 @@ ;; A reference to the offset of a directory entry. (typename $dircookie_t u64) -;; The type for the $d_namelen field of $dirent_t. +;; The type for the $d_namlen field of $dirent_t. (typename $dirnamlen_t u32) +;; File serial number that is unique within its file system. +(typename $inode_t u64) + +;; The type of a file descriptor or file. +(typename $filetype_t + (enum u8 + ;; The type of the file descriptor or file is unknown or is different from any of the other types specified. + $FILETYPE_UNKNOWN + ;; The file descriptor or file refers to a block device inode. + $FILETYPE_BLOCK_DEVICE + ;; The file descriptor or file refers to a character device inode. + $FILETYPE_CHARACTER_DEVICE + ;; The file descriptor or file refers to a directory inode. + $FILETYPE_DIRECTORY + ;; The file descriptor or file refers to a regular file inode. + $FILETYPE_REGULAR_FILE + ;; The file descriptor or file refers to a datagram socket. + $FILETYPE_SOCKET_DGRAM + ;; The file descriptor or file refers to a byte-stream socket. + $FILETYPE_SOCKET_STREAM + ;; The file refers to a symbolic link inode. + $FILETYPE_SYMBOLIC_LINK + ) +) + ;; A directory entry. (typename $dirent_t (struct @@ -328,7 +353,7 @@ ;; The serial number of the file referred to by this directory entry. (field $d_ino $inode_t) ;; The length of the name of the directory entry. - (field $d_namlen $dirnamelen_t) + (field $d_namlen $dirnamlen_t) ;; The type of the file referred to by this directory entry. (field $d_type $filetype_t) ) @@ -389,28 +414,6 @@ ;; with `inode_t` to uniquely identify a file or directory in the filesystem. (typename $device_t u64) -;; The type of a file descriptor or file. -(typename $filetype_t - (enum u8 - ;; The type of the file descriptor or file is unknown or is different from any of the other types specified. - $FILETYPE_UNKNOWN - ;; The file descriptor or file refers to a block device inode. - $FILETYPE_BLOCK_DEVICE - ;; The file descriptor or file refers to a character device inode. - $FILETYPE_CHARACTER_DEVICE - ;; The file descriptor or file refers to a directory inode. - $FILETYPE_DIRECTORY - ;; The file descriptor or file refers to a regular file inode. - $FILETYPE_REGULAR_FILE - ;; The file descriptor or file refers to a datagram socket. - $FILETYPE_SOCKET_DGRAM - ;; The file descriptor or file refers to a byte-stream socket. - $FILETYPE_SOCKET_STREAM - ;; The file refers to a symbolic link inode. - $FILETYPE_SYMBOLIC_LINK - ) -) - ;; Which file time attributes to adjust. (typename $fstflags_t (flags u16 @@ -425,9 +428,6 @@ ) ) -;; File serial number that is unique within its file system. -(typename $inode_t u64) - ;; Flags determining the method of how paths are resolved. (typename $lookupflags_t (flags u32 @@ -479,25 +479,27 @@ ;; extracted from the implementation. (typename $userdata_t u64) -;; An event that occurred. -(typename $event_t - (struct - ;; User-provided value that got attached to `subscription_t::userdata`. - (field $userdata $userdata_t) - ;; If non-zero, an error that occurred while processing the subscription request. - (field $error $errno_t) - ;; The type of the event that occurred. - (field $type $eventtype_t) - ;; The contents of the event. - (field $u $event_u) +;; Type of a subscription to an event or its occurrence. +(typename $eventtype_t + (flags u8 + ;; The time value of clock `subscription_t::u.clock.clock_id` has + ;; reached timestamp `subscription_t::u.clock.timeout`. + (flag $EVENTTYPE_CLOCK) + ;; File descriptor `subscription_t::u.fd_readwrite.fd` has data + ;; available for reading. This event always triggers for regular files. + (flag $EVENTTYPE_FD_READ) + ;; File descriptor `subscription_t::u.fd_readwrite.fd` has capacity + ;; available for writing. This event always triggers for regular files. + (flag $EVENTTYPE_FD_WRITE) ) ) -;; The contents of an $event_t. -(typename $event_u - (union - ;; When type is `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`: - (field $fd_readwrite $event_fd_readwrite_t) +;; The state of the file descriptor subscribed to with +;; `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`. +(typename $eventrwflags_t + (flags u16 + ;; The peer of this socket has closed or disconnected. + (flag $EVENT_FD_READWRITE_HANGUP) ) ) @@ -512,27 +514,25 @@ ) ) -;; The state of the file descriptor subscribed to with -;; `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`. -(typename $eventrwflags_t - (flags u16 - ;; The peer of this socket has closed or disconnected. - (flag $EVENT_FD_READWRITE_HANGUP) +;; The contents of an $event_t. +(typename $event_u + (union + ;; When type is `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`: + (field $fd_readwrite $event_fd_readwrite_t) ) ) -;; Type of a subscription to an event or its occurrence. -(typename $eventtype_t - (flags u8 - ;; The time value of clock `subscription_t::u.clock.clock_id` has - ;; reached timestamp `subscription_t::u.clock.timeout`. - (flag $EVENTTYPE_CLOCK) - ;; File descriptor `subscription_t::u.fd_readwrite.fd` has data - ;; available for reading. This event always triggers for regular files. - (flag $EVENTTYPE_FD_READ) - ;; File descriptor `subscription_t::u.fd_readwrite.fd` has capacity - ;; available for writing. This event always triggers for regular files. - (flag $EVENTTYPE_FD_WRITE) +;; An event that occurred. +(typename $event_t + (struct + ;; User-provided value that got attached to `subscription_t::userdata`. + (field $userdata $userdata_t) + ;; If non-zero, an error that occurred while processing the subscription request. + (field $error $errno_t) + ;; The type of the event that occurred. + (field $type $eventtype_t) + ;; The contents of the event. + (field $u $event_u) ) ) @@ -549,29 +549,6 @@ ) ) -;; Subscription to an event. -(typename $subscription_t - (struct - ;; User-provided value that is attached to the subscription in the - ;; implementation and returned through `event_t::userdata`. - (field $userdata $userdata_t) - ;; The type of the event to which to subscribe. - (field $type $eventtype_t) - ;; The contents of the subscription. - (field $u $subscription_u) - ) -) - -;; The contents of a $subscription_t. -(typename $subscription_u - (union - ;; When type is `EVENTTYPE_CLOCK`: - (field $clock $subscription_clock_t) - ;; When type is `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`: - (field $fd_readwrite $subscription_fd_readwrite_t) - ) -) - ;; The contents of a $subscription_t when type is `EVENTTYPE_CLOCK`. (typename $subscription_clock_t (struct @@ -598,6 +575,29 @@ ) ) +;; The contents of a $subscription_t. +(typename $subscription_u + (union + ;; When type is `EVENTTYPE_CLOCK`: + (field $clock $subscription_clock_t) + ;; When type is `EVENTTYPE_FD_READ` or `EVENTTYPE_FD_WRITE`: + (field $fd_readwrite $subscription_fd_readwrite_t) + ) +) + +;; Subscription to an event. +(typename $subscription_t + (struct + ;; User-provided value that is attached to the subscription in the + ;; implementation and returned through `event_t::userdata`. + (field $userdata $userdata_t) + ;; The type of the event to which to subscribe. + (field $type $eventtype_t) + ;; The contents of the subscription. + (field $u $subscription_u) + ) +) + ;; Exit code generated by a process when exiting. (typename $exitcode_t u32) @@ -717,16 +717,6 @@ ) ) -;; Information about a pre-opened capability. -(typename $prestat_t - (struct - ;; The type of the pre-opened capability. - (field $pr_type $preopentype_t) - ;; The contents of the information. - (field $u $prestat_u) - ) -) - ;; Identifiers for preopened capabilities. (typename preopentype_t (enum u8 @@ -735,6 +725,14 @@ ) ) +;; The contents of a $prestat_t when type is `PREOPENTYPE_DIR`. +(typename $prestat_dir + (struct + ;; The length of the directory name for use with `fd_prestat_dir_name`. + (field $pr_name_len $size_t) + ) +) + ;; The contents of an $prestat_t. (typename $prestat_u (union @@ -743,10 +741,12 @@ ) ) -;; The contents of a $prestat_t when type is `PREOPENTYPE_DIR`. -(typename $prestat_dir +;; Information about a pre-opened capability. +(typename $prestat_t (struct - ;; The length of the directory name for use with `fd_prestat_dir_name`. - (field $pr_name_len $size_t) + ;; The type of the pre-opened capability. + (field $pr_type $preopentype_t) + ;; The contents of the information. + (field $u $prestat_u) ) )