You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
532 lines
19 KiB
532 lines
19 KiB
;; WASI Preview. This is an evolution of the API that WASI initially
|
|
;; launched with.
|
|
;;
|
|
;; 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.witx")
|
|
|
|
(module $wasi_snapshot_preview1
|
|
;;; Linear memory to be accessed by WASI functions that need it.
|
|
(import "memory" (memory))
|
|
|
|
;;; Read command-line argument data.
|
|
;;; The size of the array should match that returned by `args_sizes_get`
|
|
(@interface func (export "args_get")
|
|
(param $argv (@witx pointer (@witx pointer u8)))
|
|
(param $argv_buf (@witx pointer u8))
|
|
(result $error $errno)
|
|
)
|
|
;;; Return command-line argument data sizes.
|
|
(@interface func (export "args_sizes_get")
|
|
(result $error $errno)
|
|
;;; The number of arguments.
|
|
(result $argc $size)
|
|
;;; The size of the argument string data.
|
|
(result $argv_buf_size $size)
|
|
)
|
|
|
|
;;; 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)
|
|
)
|
|
;;; Return environment variable data sizes.
|
|
(@interface func (export "environ_sizes_get")
|
|
(result $error $errno)
|
|
;;; The number of environment variable arguments.
|
|
(result $environc $size)
|
|
;;; The size of the environment variable data.
|
|
(result $environ_buf_size $size)
|
|
)
|
|
|
|
;;; Return the resolution of a clock.
|
|
;;; Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
|
|
;;; return `errno::inval`.
|
|
;;; Note: This is similar to `clock_getres` in POSIX.
|
|
(@interface func (export "clock_res_get")
|
|
;;; The clock for which to return the resolution.
|
|
(param $id $clockid)
|
|
(result $error $errno)
|
|
;;; The resolution of the clock.
|
|
(result $resolution $timestamp)
|
|
)
|
|
;;; 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 $id $clockid)
|
|
;;; The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
|
|
(param $precision $timestamp)
|
|
(result $error $errno)
|
|
;;; The time value of the clock.
|
|
(result $time $timestamp)
|
|
)
|
|
|
|
;;; Provide file advisory information on a file descriptor.
|
|
;;; Note: This is similar to `posix_fadvise` in POSIX.
|
|
(@interface func (export "fd_advise")
|
|
(param $fd $fd)
|
|
;;; The offset within the file to which the advisory applies.
|
|
(param $offset $filesize)
|
|
;;; The length of the region to which the advisory applies.
|
|
(param $len $filesize)
|
|
;;; The advice.
|
|
(param $advice $advice)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Force the allocation of space in a file.
|
|
;;; Note: This is similar to `posix_fallocate` in POSIX.
|
|
(@interface func (export "fd_allocate")
|
|
(param $fd $fd)
|
|
;;; The offset at which to start the allocation.
|
|
(param $offset $filesize)
|
|
;;; The length of the area that is allocated.
|
|
(param $len $filesize)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Close a file descriptor.
|
|
;;; Note: This is similar to `close` in POSIX.
|
|
(@interface func (export "fd_close")
|
|
(param $fd $fd)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Synchronize the data of a file to disk.
|
|
;;; Note: This is similar to `fdatasync` in POSIX.
|
|
(@interface func (export "fd_datasync")
|
|
(param $fd $fd)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
(result $error $errno)
|
|
;;; The buffer where the file descriptor's attributes are stored.
|
|
(result $stat $fdstat)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; The desired values of the file descriptor flags.
|
|
(param $flags $fdflags)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Adjust the rights associated with a file descriptor.
|
|
;;; This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
|
|
(@interface func (export "fd_fdstat_set_rights")
|
|
(param $fd $fd)
|
|
;;; The desired rights of the file descriptor.
|
|
(param $fs_rights_base $rights)
|
|
(param $fs_rights_inheriting $rights)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Return the attributes of an open file.
|
|
(@interface func (export "fd_filestat_get")
|
|
(param $fd $fd)
|
|
(result $error $errno)
|
|
;;; The buffer where the file's attributes are stored.
|
|
(result $buf $filestat)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; The desired file size.
|
|
(param $size $filesize)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; The desired values of the data access timestamp.
|
|
(param $atim $timestamp)
|
|
;;; The desired values of the data modification timestamp.
|
|
(param $mtim $timestamp)
|
|
;;; A bitmask indicating which timestamps to adjust.
|
|
(param $fst_flags $fstflags)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; List of scatter/gather vectors in which to store data.
|
|
(param $iovs $iovec_array)
|
|
;;; The offset within the file at which to read.
|
|
(param $offset $filesize)
|
|
(result $error $errno)
|
|
;;; The number of bytes read.
|
|
(result $nread $size)
|
|
)
|
|
|
|
;;; Return a description of the given preopened file descriptor.
|
|
(@interface func (export "fd_prestat_get")
|
|
(param $fd $fd)
|
|
(result $error $errno)
|
|
;;; The buffer where the description is stored.
|
|
(result $buf $prestat)
|
|
)
|
|
|
|
;;; Return a description of the given preopened file descriptor.
|
|
(@interface func (export "fd_prestat_dir_name")
|
|
(param $fd $fd)
|
|
;;; A buffer into which to write the preopened directory name.
|
|
(param $path (@witx pointer u8))
|
|
(param $path_len $size)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; List of scatter/gather vectors from which to retrieve data.
|
|
(param $iovs $ciovec_array)
|
|
;;; The offset within the file at which to write.
|
|
(param $offset $filesize)
|
|
(result $error $errno)
|
|
;;; The number of bytes written.
|
|
(result $nwritten $size)
|
|
)
|
|
|
|
;;; Read from a file descriptor.
|
|
;;; Note: This is similar to `readv` in POSIX.
|
|
(@interface func (export "fd_read")
|
|
(param $fd $fd)
|
|
;;; List of scatter/gather vectors to which to store data.
|
|
(param $iovs $iovec_array)
|
|
(result $error $errno)
|
|
;;; The number of bytes read.
|
|
(result $nread $size)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; The buffer where directory entries are stored
|
|
(param $buf (@witx pointer u8))
|
|
(param $buf_len $size)
|
|
;;; The location within the directory to start reading
|
|
(param $cookie $dircookie)
|
|
(result $error $errno)
|
|
;;; 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)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; The file descriptor to overwrite.
|
|
(param $to $fd)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Move the offset of a file descriptor.
|
|
;;; Note: This is similar to `lseek` in POSIX.
|
|
(@interface func (export "fd_seek")
|
|
(param $fd $fd)
|
|
;;; The number of bytes to move.
|
|
(param $offset $filedelta)
|
|
;;; The base from which the offset is relative.
|
|
(param $whence $whence)
|
|
(result $error $errno)
|
|
;;; The new offset of the file descriptor, relative to the start of the file.
|
|
(result $newoffset $filesize)
|
|
)
|
|
|
|
;;; Synchronize the data and metadata of a file to disk.
|
|
;;; Note: This is similar to `fsync` in POSIX.
|
|
(@interface func (export "fd_sync")
|
|
(param $fd $fd)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
(result $error $errno)
|
|
;;; The current offset of the file descriptor, relative to the start of the file.
|
|
(result $offset $filesize)
|
|
)
|
|
|
|
;;; Write to a file descriptor.
|
|
;;; Note: This is similar to `writev` in POSIX.
|
|
(@interface func (export "fd_write")
|
|
(param $fd $fd)
|
|
;;; List of scatter/gather vectors from which to retrieve data.
|
|
(param $iovs $ciovec_array)
|
|
(result $error $errno)
|
|
;;; The number of bytes written.
|
|
(result $nwritten $size)
|
|
)
|
|
|
|
;;; Create a directory.
|
|
;;; Note: This is similar to `mkdirat` in POSIX.
|
|
(@interface func (export "path_create_directory")
|
|
(param $fd $fd)
|
|
;;; The path at which to create the directory.
|
|
(param $path string)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Return the attributes of a file or directory.
|
|
;;; Note: This is similar to `stat` in POSIX.
|
|
(@interface func (export "path_filestat_get")
|
|
(param $fd $fd)
|
|
;;; Flags determining the method of how the path is resolved.
|
|
(param $flags $lookupflags)
|
|
;;; The path of the file or directory to inspect.
|
|
(param $path string)
|
|
(result $error $errno)
|
|
;;; The buffer where the file's attributes are stored.
|
|
(result $buf $filestat)
|
|
)
|
|
|
|
;;; Adjust the timestamps of a file or directory.
|
|
;;; Note: This is similar to `utimensat` in POSIX.
|
|
(@interface func (export "path_filestat_set_times")
|
|
(param $fd $fd)
|
|
;;; Flags determining the method of how the path is resolved.
|
|
(param $flags $lookupflags)
|
|
;;; The path of the file or directory to operate on.
|
|
(param $path string)
|
|
;;; The desired values of the data access timestamp.
|
|
(param $atim $timestamp)
|
|
;;; The desired values of the data modification timestamp.
|
|
(param $mtim $timestamp)
|
|
;;; A bitmask indicating which timestamps to adjust.
|
|
(param $fst_flags $fstflags)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Create a hard link.
|
|
;;; Note: This is similar to `linkat` in POSIX.
|
|
(@interface func (export "path_link")
|
|
(param $old_fd $fd)
|
|
;;; Flags determining the method of how the path is resolved.
|
|
(param $old_flags $lookupflags)
|
|
;;; 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 $fd)
|
|
;;; The destination path at which to create the hard link.
|
|
(param $new_path string)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; Flags determining the method of how the path is resolved.
|
|
(param $dirflags $lookupflags)
|
|
;;; The relative path of the file or directory to open, relative to the
|
|
;;; `path_open::fd` directory.
|
|
(param $path string)
|
|
;;; The method by which to open the file.
|
|
(param $oflags $oflags)
|
|
;;; 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)
|
|
(param $fs_rights_inherting $rights)
|
|
(param $fdflags $fdflags)
|
|
(result $error $errno)
|
|
;;; The file descriptor of the file that has been opened.
|
|
(result $opened_fd $fd)
|
|
)
|
|
|
|
;;; Read the contents of a symbolic link.
|
|
;;; Note: This is similar to `readlinkat` in POSIX.
|
|
(@interface func (export "path_readlink")
|
|
(param $fd $fd)
|
|
;;; The path of the symbolic link from which to read.
|
|
(param $path string)
|
|
;;; The buffer to which to write the contents of the symbolic link.
|
|
(param $buf (@witx pointer u8))
|
|
(param $buf_len $size)
|
|
(result $error $errno)
|
|
;;; The number of bytes placed in the buffer.
|
|
(result $bufused $size)
|
|
)
|
|
|
|
;;; Remove a directory.
|
|
;;; Return `errno::notempty` 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)
|
|
;;; The path to a directory to remove.
|
|
(param $path string)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Rename a file or directory.
|
|
;;; Note: This is similar to `renameat` in POSIX.
|
|
(@interface func (export "path_rename")
|
|
(param $fd $fd)
|
|
;;; 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)
|
|
)
|
|
|
|
;;; Create a symbolic link.
|
|
;;; Note: This is similar to `symlinkat` in POSIX.
|
|
(@interface func (export "path_symlink")
|
|
;;; The contents of the symbolic link.
|
|
(param $old_path string)
|
|
(param $fd $fd)
|
|
;;; The destination path at which to create the symbolic link.
|
|
(param $new_path string)
|
|
(result $error $errno)
|
|
)
|
|
|
|
|
|
;;; Unlink a file.
|
|
;;; Return `errno::isdir` 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)
|
|
;;; The path to a file to unlink.
|
|
(param $path string)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Concurrently poll for the occurrence of a set of events.
|
|
(@interface func (export "poll_oneoff")
|
|
;;; The events to which to subscribe.
|
|
(param $in (@witx const_pointer $subscription))
|
|
;;; The events that have occurred.
|
|
(param $out (@witx pointer $event))
|
|
;;; Both the number of subscriptions and events.
|
|
(param $nsubscriptions $size)
|
|
(result $error $errno)
|
|
;;; The number of events stored.
|
|
(result $nevents $size)
|
|
)
|
|
|
|
;;; 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)
|
|
)
|
|
|
|
;;; 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)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; Temporarily yield execution of the calling thread.
|
|
;;; Note: This is similar to `sched_yield` in POSIX.
|
|
(@interface func (export "sched_yield")
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 (@witx pointer u8))
|
|
(param $buf_len $size)
|
|
(result $error $errno)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; List of scatter/gather vectors to which to store data.
|
|
(param $ri_data $iovec_array)
|
|
;;; Message flags.
|
|
(param $ri_flags $riflags)
|
|
(result $error $errno)
|
|
;;; Number of bytes stored in ri_data.
|
|
(result $ro_datalen $size)
|
|
;;; Message flags.
|
|
(result $ro_flags $roflags)
|
|
)
|
|
|
|
;;; 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 $fd $fd)
|
|
;;; List of scatter/gather vectors to which to retrieve data
|
|
(param $si_data $ciovec_array)
|
|
;;; Message flags.
|
|
(param $si_flags $siflags)
|
|
(result $error $errno)
|
|
;;; Number of bytes transmitted.
|
|
(result $so_datalen $size)
|
|
)
|
|
|
|
;;; Shut down socket send and receive channels.
|
|
;;; Note: This is similar to `shutdown` in POSIX.
|
|
(@interface func (export "sock_shutdown")
|
|
(param $fd $fd)
|
|
;;; Which channels on the socket to shut down.
|
|
(param $how $sdflags)
|
|
(result $error $errno)
|
|
)
|
|
)
|
|
|