Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/nodejs/uvwasi

WASI syscall API built atop libuv
https://github.com/nodejs/uvwasi

vewasiraptors

Last synced: about 2 months ago
JSON representation

WASI syscall API built atop libuv

Awesome Lists containing this project

README

        

# uvwasi

**This project does not currently provide the comprehensive file system security
properties provided by some WASI runtimes. Full support for secure file system sandboxing
may or may not be implemented in future. In the mean time, do not rely on it to run untrusted code.**

`uvwasi` implements the [WASI][] system call API, so that WebAssembly
runtimes can easily implement WASI calls. Under the hood, `uvwasi`
leverages [libuv][] where possible for maximum portability.

|
WebAssembly code | WebAssembly application code
| |
| v
| WASI syscalls (inserted by compiler toolchain)
| |
------------------------------+ |
| v
WebAssembly runtime (Node.js) | uvwasi (implementation of WASI)
| |
| v
| libuv
| |
| v
| platform-specific calls
|

*(Hence uvwasi isn't for making C-programs-that-use-libuv-APIs execute on
WASI runtimes. That would either be a new platform added by libuv, or done
through POSIX emulation by the Emscripten or wasi-sdk toolchains.)*

## Building Locally

To build with [CMake](https://cmake.org/):

```sh
$ mkdir -p out/cmake ; cd out/cmake # create build directory
$ cmake ../.. -DBUILD_TESTING=ON # generate project with test
$ cmake --build . # build
$ ctest -C Debug --output-on-failure # run tests
```

## Example Usage

```c
#include
#include
#include "uv.h"
#include "uvwasi.h"

int main(void) {
uvwasi_t uvwasi;
uvwasi_options_t init_options;
uvwasi_errno_t err;

/* Setup the initialization options. */
init_options.in = 0;
init_options.out = 1;
init_options.err = 2;
init_options.fd_table_size = 3;
init_options.argc = 3;
init_options.argv = calloc(3, sizeof(char*));
init_options.argv[0] = "--foo=bar";
init_options.argv[1] = "-baz";
init_options.argv[2] = "100";
init_options.envp = NULL;
init_options.preopenc = 1;
init_options.preopens = calloc(1, sizeof(uvwasi_preopen_t));
init_options.preopens[0].mapped_path = "/var";
init_options.preopens[0].real_path = ".";
init_options.allocator = NULL;

/* Initialize the sandbox. */
err = uvwasi_init(&uvwasi, &init_options);
assert(err == UVWASI_ESUCCESS);

/* TODO(cjihrig): Show an example system call or two. */

/* Clean up resources. */
uvwasi_destroy(&uvwasi);
return 0;
}
```

## API

The WASI API is versioned. This documentation is based on the WASI [preview 1][]
snapshot. `uvwasi` implements the WASI system call API with the following
additions/modifications:

- Each system call takes an additional `uvwasi_t*` as its first argument. The
`uvwasi_t` is the sandbox under which system calls are issued. Each `uvwasi_t`
can have different command line arguments, environment variables, preopened
directories, file descriptor mappings, etc. This allows one controlling
process to host multiple WASI applications simultaneously.
- Each system call returns a `uvwasi_errno_t`. This appears to be expected of
WASI system calls, but it is not explicitly part of the official API docs.
This detail is explicitly documented here.
- Additional functions and data types are provided for interacting with WASI
sandboxes and the `uvwasi` library. These APIs are documented in the
Unofficial APIs section below.

### Unofficial APIs

This section contains data types and functions for working with `uvwasi`. They
are not part of the official WASI API, but are used to embed `uvwasi`.

### `UVWASI_VERSION_MAJOR`

The major release version of the `uvwasi` library. `uvwasi` follows semantic
versioning. Changes to this value represent breaking changes in the public API.

### `UVWASI_VERSION_MINOR`

The minor release version of the `uvwasi` library. `uvwasi` follows semantic
versioning. Changes to this value represent feature additions in the public API.

### `UVWASI_VERSION_PATCH`

The patch release version of the `uvwasi` library. `uvwasi` follows semantic
versioning. Changes to this value represent bug fixes in the public API.

### `UVWASI_VERSION_HEX`

The major, minor, and patch versions of the `uvwasi` library encoded as a single
integer value.

### `UVWASI_VERSION_STRING`

The major, minor, and patch versions of the `uvwasi` library encoded as a
version string.

### `UVWASI_VERSION_WASI`

The version of the WASI API targeted by `uvwasi`.

### `uvwasi_t`

An individual WASI sandbox instance.

```c
typedef struct uvwasi_s {
struct uvwasi_fd_table_t fds;
uvwasi_size_t argc;
char** argv;
char* argv_buf;
uvwasi_size_t argv_buf_size;
uvwasi_size_t envc;
char** env;
char* env_buf;
uvwasi_size_t env_buf_size;
} uvwasi_t;
```

### `uvwasi_preopen_t`

A data structure used to map a directory path within a WASI sandbox to a
directory path on the WASI host platform.

```c
typedef struct uvwasi_preopen_s {
char* mapped_path;
char* real_path;
} uvwasi_preopen_t;
```

### `uvwasi_options_t`

A data structure used to pass configuration options to `uvwasi_init()`.

```c
typedef struct uvwasi_options_s {
uvwasi_size_t fd_table_size;
uvwasi_size_t preopenc;
uvwasi_preopen_t* preopens;
uvwasi_size_t argc;
char** argv;
char** envp;
uvwasi_fd_t in;
uvwasi_fd_t out;
uvwasi_fd_t err;
const uvwasi_mem_t* allocator;
} uvwasi_options_t;
```

### `uvwasi_init()`

Initializes a sandbox represented by a `uvwasi_t` using the options represented
by a `uvwasi_options_t`.

Inputs:

- [\_\_wasi\_t](#uvwasi_t) uvwasi

The sandbox to initialize.

- [\_\_wasi\_options\_t](#uvwasi_options_t) options

Configuration options used when initializing the sandbox.

Outputs:

- None

Returns:

- [\_\_wasi\_errno\_t](#errno) errno

A WASI errno.

### `uvwasi_destroy()`

Cleans up resources related to a WASI sandbox. This function notably does not
return an error code.

Inputs:

- [\_\_wasi\_t](#uvwasi_t) uvwasi

The sandbox to clean up.

Outputs:

- None

Returns:

- None

### System Calls

This section has been adapted from the official WASI API documentation.

- [`uvwasi_args_get()`](#args_get)
- [`uvwasi_args_sizes_get()`](#args_sizes_get)
- [`uvwasi_clock_res_get()`](#clock_res_get)
- [`uvwasi_clock_time_get()`](#clock_time_get)
- [`uvwasi_environ_get()`](#environ_get)
- [`uvwasi_environ_sizes_get()`](#environ_sizes_get)
- [`uvwasi_fd_advise()`](#fd_advise)
- [`uvwasi_fd_allocate()`](#fd_allocate)
- [`uvwasi_fd_close()`](#fd_close)
- [`uvwasi_fd_datasync()`](#fd_datasync)
- [`uvwasi_fd_fdstat_get()`](#fd_fdstat_get)
- [`uvwasi_fd_fdstat_set_flags()`](#fd_fdstat_set_flags)
- [`uvwasi_fd_fdstat_set_rights()`](#fd_fdstat_set_rights)
- [`uvwasi_fd_filestat_get()`](#fd_filestat_get)
- [`uvwasi_fd_filestat_set_size()`](#fd_filestat_set_size)
- [`uvwasi_fd_filestat_set_times()`](#fd_filestat_set_times)
- [`uvwasi_fd_pread()`](#fd_pread)
- [`uvwasi_fd_prestat_get()`](#fd_prestat_get)
- [`uvwasi_fd_prestat_dir_name()`](#fd_prestat_dir_name)
- [`uvwasi_fd_pwrite()`](#fd_pwrite)
- [`uvwasi_fd_read()`](#fd_read)
- [`uvwasi_fd_readdir()`](#fd_readdir)
- [`uvwasi_fd_renumber()`](#fd_renumber)
- [`uvwasi_fd_seek()`](#fd_seek)
- [`uvwasi_fd_sync()`](#fd_sync)
- [`uvwasi_fd_tell()`](#fd_tell)
- [`uvwasi_fd_write()`](#fd_write)
- [`uvwasi_path_create_directory()`](#path_create_directory)
- [`uvwasi_path_filestat_get()`](#path_filestat_get)
- [`uvwasi_path_filestat_set_times()`](#path_filestat_set_times)
- [`uvwasi_path_link()`](#path_link)
- [`uvwasi_path_open()`](#path_open)
- [`uvwasi_path_readlink()`](#path_readlink)
- [`uvwasi_path_remove_directory()`](#path_remove_directory)
- [`uvwasi_path_rename()`](#path_rename)
- [`uvwasi_path_symlink()`](#path_symlink)
- [`uvwasi_path_unlink_file()`](#path_unlink_file)
- [`uvwasi_poll_oneoff()`](#poll_oneoff)
- [`uvwasi_proc_exit()`](#proc_exit)
- [`uvwasi_proc_raise()`](#proc_raise)
- [`uvwasi_random_get()`](#random_get)
- [`uvwasi_sched_yield()`](#sched_yield)
- [`uvwasi_sock_recv()`](#sock_recv)
- [`uvwasi_sock_send()`](#sock_send)
- [`uvwasi_sock_shutdown()`](#sock_shutdown)

### `uvwasi_args_get()`

Read command-line argument data.

The sizes of the buffers should match that returned by [`uvwasi_args_sizes_get()`](#args_sizes_get).

Inputs:

- char \*\*argv

A pointer to a buffer to write the argument pointers.

- char \*argv\_buf

A pointer to a buffer to write the argument string data.

### `uvwasi_args_sizes_get()`

Return command-line argument data sizes.

Outputs:

- \_\_wasi\_size\_t \*argc

The number of arguments.

- \_\_wasi\_size\_t \*argv\_buf\_size

The size of the argument string data.

### `uvwasi_clock_res_get()`

Return the resolution of a clock.

Implementations are required to provide a non-zero value for supported clocks.
For unsupported clocks, return [`UVWASI_EINVAL`](#errno.inval).

Note: This is similar to `clock_getres` in POSIX.

Inputs:

- [\_\_wasi\_clockid\_t](#clockid) clock\_id

The clock for which to return the resolution.

Outputs:

- [\_\_wasi\_timestamp\_t](#timestamp) resolution

The resolution of the clock.

### `uvwasi_clock_time_get()`

Return the time value of a clock.

Note: This is similar to `clock_gettime` in POSIX.

Inputs:

- [\_\_wasi\_clockid\_t](#clockid) clock\_id

The clock for which to return the time.

- [\_\_wasi\_timestamp\_t](#timestamp) precision

The maximum lag (exclusive) that the returned
time value may have, compared to its actual
value.

Outputs:

- [\_\_wasi\_timestamp\_t](#timestamp) time

The time value of the clock.

### `uvwasi_environ_get()`

Read environment variable data.

The sizes of the buffers should match that returned by [`uvwasi_environ_sizes_get()`](#environ_sizes_get).

Inputs:

- char \*\*environ

A pointer to a buffer to write the environment variable pointers.

- char \*environ\_buf

A pointer to a buffer to write the environment variable string data.

### `uvwasi_environ_sizes_get()`

Return command-line argument data sizes.

Outputs:

- \_\_wasi\_size\_t \*environ\_count

The number of environment variables.

- \_\_wasi\_size\_t \*environ\_buf\_size

The size of the environment variable string data.

### `uvwasi_fd_advise()`

Provide file advisory information on a file descriptor.

Note: This is similar to `posix_fadvise` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor for the file for which to provide file advisory information.

- [\_\_wasi\_filesize\_t](#filesize) offset

The offset within the file to which the advisory applies.

- [\_\_wasi\_filesize\_t](#filesize) len

The length of the region to which the advisory applies.

- [\_\_wasi\_advice\_t](#advice) advice

The advice.

### `uvwasi_fd_allocate()`

Force the allocation of space in a file.

Note: This is similar to `posix_fallocate` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor for the file in which to allocate space.

- [\_\_wasi\_filesize\_t](#filesize) offset

The offset at which to start the allocation.

- [\_\_wasi\_filesize\_t](#filesize) len

The length of the area that is allocated.

### `uvwasi_fd_close()`

Close a file descriptor.

Note: This is similar to `close` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to close.

### `uvwasi_fd_datasync()`

Synchronize the data of a file to disk.

Note: This is similar to `fdatasync` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor of the file to synchronize to disk.

### `uvwasi_fd_fdstat_get()`

Get the attributes of a file descriptor.

Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well
as additional fields.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to inspect.

- [\_\_wasi\_fdstat\_t](#fdstat) \*buf

The buffer where the file descriptor's attributes are stored.

### `uvwasi_fd_fdstat_set_flags()`

Adjust the flags associated with a file descriptor.

Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to operate on.

- [\_\_wasi\_fdflags\_t](#fdflags) flags

The desired values of the file descriptor
flags.

### `uvwasi_fd_fdstat_set_rights()`

Adjust the rights associated with a file descriptor.

This can only be used to remove rights, and returns
[`UVWASI_ENOTCAPABLE`](#errno.notcapable) if called in a way that would attempt
to add rights.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to operate on.

- [\_\_wasi\_rights\_t](#rights) fs\_rights\_base and [\_\_wasi\_rights\_t](#rights) fs\_rights\_inheriting

The desired rights of the file descriptor.

### `uvwasi_fd_filestat_get()`

Return the attributes of an open file.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to inspect.

- [\_\_wasi\_filestat\_t](#filestat) \*buf

The buffer where the file's attributes are
stored.

### `uvwasi_fd_filestat_set_size()`

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.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

A file descriptor for the file to adjust.

- [\_\_wasi\_filesize\_t](#filesize) st\_size

The desired file size.

### `uvwasi_fd_filestat_set_times()`

Adjust the timestamps of an open file or directory.

Note: This is similar to `futimens` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to operate on.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_atim

The desired values of the data access timestamp.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_mtim

The desired values of the data modification timestamp.

- [\_\_wasi\_fstflags\_t](#fstflags) fst\_flags

A bitmask indicating which timestamps to adjust.

### `uvwasi_fd_pread()`

Read from a file descriptor, without using and updating the
file descriptor's offset.

Note: This is similar to `preadv` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor from which to read data.

- const [\_\_wasi\_iovec\_t](#iovec) \*iovs and \_\_wasi\_size\_t iovs\_len

List of scatter/gather vectors in which to store data.

- [\_\_wasi\_filesize\_t](#filesize) offset

The offset within the file at which to read.

Outputs:

- \_\_wasi\_size\_t nread

The number of bytes read.

### `uvwasi_fd_prestat_get()`

Return a description of the given preopened file descriptor.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor about which to retrieve information.

- [\_\_wasi\_prestat\_t](#prestat) \*buf

The buffer where the description is stored.

### `uvwasi_fd_prestat_dir_name()`

Return a description of the given preopened file descriptor.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor about which to retrieve information.

- const char \*path and \_\_wasi\_size\_t path\_len

A buffer into which to write the preopened directory name.

### `uvwasi_fd_pwrite()`

Write to a file descriptor, without using and updating the
file descriptor's offset.

Note: This is similar to `pwritev` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to which to write data.

- const [\_\_wasi\_ciovec\_t](#ciovec) \*iovs and \_\_wasi\_size\_t iovs\_len

List of scatter/gather vectors from which to retrieve data.

- [\_\_wasi\_filesize\_t](#filesize) offset

The offset within the file at which to write.

Outputs:

- \_\_wasi\_size\_t nwritten

The number of bytes written.

### `uvwasi_fd_read()`

Read from a file descriptor.

Note: This is similar to `readv` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor from which to read data.

- const [\_\_wasi\_iovec\_t](#iovec) \*iovs and \_\_wasi\_size\_t iovs\_len

List of scatter/gather vectors to which to store data.

Outputs:

- \_\_wasi\_size\_t nread

The number of bytes read.

### `uvwasi_fd_readdir()`

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 [`uvwasi_dirent_t`](#dirent) object, followed by [`uvwasi_dirent_t::d_namlen`](#dirent.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.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The directory from which to read the directory
entries.

- void \*buf and \_\_wasi\_size\_t buf\_len

The buffer where directory entries are stored.

- [\_\_wasi\_dircookie\_t](#dircookie) cookie

The location within the directory to start
reading.

Outputs:

- \_\_wasi\_size\_t bufused

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.

### `uvwasi_fd_renumber()`

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.

Inputs:

- [\_\_wasi\_fd\_t](#fd) from

The file descriptor to renumber.

- [\_\_wasi\_fd\_t](#fd) to

The file descriptor to overwrite.

### `uvwasi_fd_seek()`

Move the offset of a file descriptor.

Note: This is similar to `lseek` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to operate on.

- [\_\_wasi\_filedelta\_t](#filedelta) offset

The number of bytes to move.

- [\_\_wasi\_whence\_t](#whence) whence

The base from which the offset is relative.

Outputs:

- [\_\_wasi\_filesize\_t](#filesize) newoffset

The new offset of the file descriptor,
relative to the start of the file.

### `uvwasi_fd_sync()`

Synchronize the data and metadata of a file to disk.

Note: This is similar to `fsync` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor of the file containing the data
and metadata to synchronize to disk.

### `uvwasi_fd_tell()`

Return the current offset of a file descriptor.

Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to inspect.

Outputs:

- [\_\_wasi\_filesize\_t](#filesize) offset

The current offset of the file descriptor, relative to the start of the file.

### `uvwasi_fd_write()`

Write to a file descriptor.

Note: This is similar to `writev` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor to which to write data.

- const [\_\_wasi\_ciovec\_t](#ciovec) \*iovs and \_\_wasi\_size\_t iovs\_len

List of scatter/gather vectors from which to retrieve data.

Outputs:

- \_\_wasi\_size\_t nwritten

The number of bytes written.

### `uvwasi_path_create_directory()`

Create a directory.

Note: This is similar to `mkdirat` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- const char \*path and \_\_wasi\_size\_t path\_len

The path at which to create the directory.

### `uvwasi_path_filestat_get()`

Return the attributes of a file or directory.

Note: This is similar to `stat` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- [\_\_wasi\_lookupflags\_t](#lookupflags) flags

Flags determining the method of how the path is resolved.

- const char \*path and \_\_wasi\_size\_t path\_len

The path of the file or directory to inspect.

- [\_\_wasi\_filestat\_t](#filestat) \*buf

The buffer where the file's attributes are
stored.

### `uvwasi_path_filestat_set_times()`

Adjust the timestamps of a file or directory.

Note: This is similar to `utimensat` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- [\_\_wasi\_lookupflags\_t](#lookupflags) flags

Flags determining the method of how the path is resolved.

- const char \*path and \_\_wasi\_size\_t path\_len

The path of the file or directory to operate on.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_atim

The desired values of the data access timestamp.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_mtim

The desired values of the data modification timestamp.

- [\_\_wasi\_fstflags\_t](#fstflags) fst\_flags

A bitmask indicating which timestamps to adjust.

### `uvwasi_path_link()`

Create a hard link.

Note: This is similar to `linkat` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) old\_fd

The working directory at which the resolution of the old path starts.

- [\_\_wasi\_lookupflags\_t](#lookupflags) old\_flags

Flags determining the method of how the path is resolved.

- const char \*old\_path and \_\_wasi\_size\_t old\_path\_len

The source path from which to link.

- [\_\_wasi\_fd\_t](#fd) new\_fd

The working directory at which the resolution of the new path starts.

- const char \*new\_path and \_\_wasi\_size\_t new\_path\_len

The destination path at which to create the hard link.

### `uvwasi_path_open()`

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.

Inputs:

- [\_\_wasi\_fd\_t](#fd) dirfd

The working directory at which the resolution of the path starts.

- [\_\_wasi\_lookupflags\_t](#lookupflags) dirflags

Flags determining the method of how the path is resolved.

- const char \*path and \_\_wasi\_size\_t path\_len

The relative path of the file or directory to open, relative to
the [`dirfd`](#path_open.dirfd) directory.

- [\_\_wasi\_oflags\_t](#oflags) o_flags

The method by which to open the file.

- [\_\_wasi\_rights\_t](#rights) fs\_rights\_base and [\_\_wasi\_rights\_t](#rights) fs\_rights\_inheriting

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.

- [\_\_wasi\_fdflags\_t](#fdflags) fs\_flags

The initial flags of the file descriptor.

Outputs:

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor of the file that has been
opened.

### `uvwasi_path_readlink()`

Read the contents of a symbolic link.

Note: This is similar to `readlinkat` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- const char \*path and \_\_wasi\_size\_t path\_len

The path of the symbolic link from which to read.

- char \*buf and \_\_wasi\_size\_t buf\_len

The buffer to which to write the contents of the symbolic link.

Outputs:

- \_\_wasi\_size\_t bufused

The number of bytes placed in the buffer.

### `uvwasi_path_remove_directory()`

Remove a directory.

Return [`UVWASI_ENOTEMPTY`](#errno.notempty) if the directory is not empty.

Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- const char \*path and \_\_wasi\_size\_t path\_len

The path to a directory to remove.

### `uvwasi_path_rename()`

Rename a file or directory.

Note: This is similar to `renameat` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) old\_fd

The working directory at which the resolution of the old path starts.

- const char \*old\_path and \_\_wasi\_size\_t old\_path\_len

The source path of the file or directory to rename.

- [\_\_wasi\_fd\_t](#fd) new\_fd

The working directory at which the resolution of the new path starts.

- const char \*new\_path and \_\_wasi\_size\_t new\_path\_len

The destination path to which to rename the file or directory.

### `uvwasi_path_symlink()`

Create a symbolic link.

Note: This is similar to `symlinkat` in POSIX.

Inputs:

- const char \*old\_path and \_\_wasi\_size\_t old_path\_len

The contents of the symbolic link.

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- const char \*new\_path and \_\_wasi\_size\_t new\_path\_len

The destination path at which to create the symbolic link.

### `uvwasi_path_unlink_file()`

Unlink a file.

Return [`UVWASI_EISDIR`](#errno.isdir) if the path refers to a directory.

Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) fd

The working directory at which the resolution of the path starts.

- const char \*path and \_\_wasi\_size\_t path\_len

The path to a file to unlink.

### `uvwasi_poll_oneoff()`

Concurrently poll for the occurrence of a set of events.

Inputs:

- const [\_\_wasi\_subscription\_t](#subscription) \*in

The events to which to subscribe.

- [\_\_wasi\_event\_t](#event) \*out

The events that have occurred.

- \_\_wasi\_size\_t nsubscriptions

Both the number of subscriptions and events.

Outputs:

- \_\_wasi\_size\_t nevents

The number of events stored.

### `uvwasi_proc_exit()`

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.

Note: This is similar to `_Exit` in POSIX.

Inputs:

- [\_\_wasi\_exitcode\_t](#exitcode) rval

The exit code returned by the process.

Does not return.

### `uvwasi_proc_raise()`

Send a signal to the process of the calling thread.

Note: This is similar to `raise` in POSIX.

Inputs:

- [\_\_wasi\_signal\_t](#signal) sig

The signal condition to trigger.

### `uvwasi_random_get()`

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.

Inputs:

- void \*buf and \_\_wasi\_size\_t buf\_len

The buffer to fill with random data.

### `uvwasi_sched_yield()`

Temporarily yield execution of the calling thread.

Note: This is similar to `sched_yield` in POSIX.

### `uvwasi_sock_recv()`

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`.

Inputs:

- [\_\_wasi\_fd\_t](#fd) sock

The socket on which to receive data.

- const [\_\_wasi\_iovec\_t](#iovec) \*ri\_data and \_\_wasi\_size\_t ri\_data\_len

List of scatter/gather vectors to which to store data.

- [\_\_wasi\_riflags\_t](#riflags) ri\_flags

Message flags.

Outputs:

- \_\_wasi\_size\_t ro\_datalen

Number of bytes stored in [`ri_data`](#sock_recv.ri_data).

- [\_\_wasi\_roflags\_t](#roflags) ro\_flags

Message flags.

### `uvwasi_sock_send()`

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`.

Inputs:

- [\_\_wasi\_fd\_t](#fd) sock

The socket on which to send data.

- const [\_\_wasi\_ciovec\_t](#ciovec) \*si\_data and \_\_wasi\_size\_t si\_data\_len

List of scatter/gather vectors to which to retrieve data

- [\_\_wasi\_siflags\_t](#siflags) si\_flags

Message flags.

Outputs:

- \_\_wasi\_size\_t so\_datalen

Number of bytes transmitted.

### `uvwasi_sock_shutdown()`

Shut down socket send and receive channels.

Note: This is similar to `shutdown` in POSIX.

Inputs:

- [\_\_wasi\_fd\_t](#fd) sock

The socket on which to shutdown channels.

- [\_\_wasi\_sdflags\_t](#sdflags) how

Which channels on the socket to shut down.

## Types

### `uvwasi_advice_t` (`uint8_t`)

File or memory access pattern advisory information.

Used by [`uvwasi_fd_advise()`](#fd_advise).

Possible values:

- **`UVWASI_ADVICE_DONTNEED`**

The application expects that it will not access the
specified data in the near future.

- **`UVWASI_ADVICE_NOREUSE`**

The application expects to access the specified data
once and then not reuse it thereafter.

- **`UVWASI_ADVICE_NORMAL`**

The application has no advice to give on its behavior
with respect to the specified data.

- **`UVWASI_ADVICE_RANDOM`**

The application expects to access the specified data
in a random order.

- **`UVWASI_ADVICE_SEQUENTIAL`**

The application expects to access the specified data
sequentially from lower offsets to higher offsets.

- **`UVWASI_ADVICE_WILLNEED`**

The application expects to access the specified data
in the near future.

### `uvwasi_ciovec_t` (`struct`)

A region of memory for scatter/gather writes.

Used by [`uvwasi_fd_pwrite()`](#fd_pwrite), [`uvwasi_fd_write()`](#fd_write), and [`uvwasi_sock_send()`](#sock_send).

Members:

- const void \*buf and \_\_wasi\_size\_t buf\_len

The address and length of the buffer to be written.

### `uvwasi_clockid_t` (`uint32_t`)

Identifiers for clocks.

Used by [`uvwasi_subscription_t`](#subscription), [`uvwasi_clock_res_get()`](#clock_res_get), and [`uvwasi_clock_time_get()`](#clock_time_get).

Possible values:

- **`UVWASI_CLOCK_MONOTONIC`**

The store-wide monotonic clock, which is defined as a
clock measuring real time, whose value cannot be
adjusted and which cannot have negative clock jumps.

The epoch of this clock is undefined. The absolute
time value of this clock therefore has no meaning.

- **`UVWASI_CLOCK_PROCESS_CPUTIME_ID`**

The CPU-time clock associated with the current
process.

- **`UVWASI_CLOCK_REALTIME`**

The clock measuring real time. Time value
zero corresponds with 1970-01-01T00:00:00Z.

- **`UVWASI_CLOCK_THREAD_CPUTIME_ID`**

The CPU-time clock associated with the current thread.

### `uvwasi_device_t` (`uint64_t`)

Identifier for a device containing a file system. Can be used
in combination with [`uvwasi_inode_t`](#inode) to uniquely identify a file or
directory in the filesystem.

Used by [`uvwasi_filestat_t`](#filestat).

### `uvwasi_dircookie_t` (`uint64_t`)

A reference to the offset of a directory entry.

Used by [`uvwasi_dirent_t`](#dirent) and [`uvwasi_fd_readdir()`](#fd_readdir).

Special values:

- **`UVWASI_DIRCOOKIE_START`**

Permanent reference to the first directory entry
within a directory.

### `uvwasi_dirent_t` (`struct`)

A directory entry.

Members:

- [\_\_wasi\_dircookie\_t](#dircookie) d\_next

The offset of the next directory entry stored in this
directory.

- [\_\_wasi\_inode\_t](#inode) d\_ino

The serial number of the file referred to by this
directory entry.

- uint32\_t d\_namlen

The length of the name of the directory entry.

- [\_\_wasi\_filetype\_t](#filetype) d\_type

The type of the file referred to by this directory
entry.

### `uvwasi_errno_t` (`uint16_t`)

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.

Used by [`uvwasi_event_t`](#event).

Possible values:

- **`UVWASI_ESUCCESS`**

No error occurred. System call completed successfully.

- **`UVWASI_E2BIG`**

Argument list too long.

- **`UVWASI_EACCES`**

Permission denied.

- **`UVWASI_EADDRINUSE`**

Address in use.

- **`UVWASI_EADDRNOTAVAIL`**

Address not available.

- **`UVWASI_EAFNOSUPPORT`**

Address family not supported.

- **`UVWASI_EAGAIN`**

Resource unavailable, or operation would block.

- **`UVWASI_EALREADY`**

Connection already in progress.

- **`UVWASI_EBADF`**

Bad file descriptor.

- **`UVWASI_EBADMSG`**

Bad message.

- **`UVWASI_EBUSY`**

Device or resource busy.

- **`UVWASI_ECANCELED`**

Operation canceled.

- **`UVWASI_ECHILD`**

No child processes.

- **`UVWASI_ECONNABORTED`**

Connection aborted.

- **`UVWASI_ECONNREFUSED`**

Connection refused.

- **`UVWASI_ECONNRESET`**

Connection reset.

- **`UVWASI_EDEADLK`**

Resource deadlock would occur.

- **`UVWASI_EDESTADDRREQ`**

Destination address required.

- **`UVWASI_EDOM`**

Mathematics argument out of domain of function.

- **`UVWASI_EDQUOT`**

Reserved.

- **`UVWASI_EEXIST`**

File exists.

- **`UVWASI_EFAULT`**

Bad address.

- **`UVWASI_EFBIG`**

File too large.

- **`UVWASI_EHOSTUNREACH`**

Host is unreachable.

- **`UVWASI_EIDRM`**

Identifier removed.

- **`UVWASI_EILSEQ`**

Illegal byte sequence.

- **`UVWASI_EINPROGRESS`**

Operation in progress.

- **`UVWASI_EINTR`**

Interrupted function.

- **`UVWASI_EINVAL`**

Invalid argument.

- **`UVWASI_EIO`**

I/O error.

- **`UVWASI_EISCONN`**

Socket is connected.

- **`UVWASI_EISDIR`**

Is a directory.

- **`UVWASI_ELOOP`**

Too many levels of symbolic links.

- **`UVWASI_EMFILE`**

File descriptor value too large.

- **`UVWASI_EMLINK`**

Too many links.

- **`UVWASI_EMSGSIZE`**

Message too large.

- **`UVWASI_EMULTIHOP`**

Reserved.

- **`UVWASI_ENAMETOOLONG`**

Filename too long.

- **`UVWASI_ENETDOWN`**

Network is down.

- **`UVWASI_ENETRESET`**

Connection aborted by network.

- **`UVWASI_ENETUNREACH`**

Network unreachable.

- **`UVWASI_ENFILE`**

Too many files open in system.

- **`UVWASI_ENOBUFS`**

No buffer space available.

- **`UVWASI_ENODEV`**

No such device.

- **`UVWASI_ENOENT`**

No such file or directory.

- **`UVWASI_ENOEXEC`**

Executable file format error.

- **`UVWASI_ENOLCK`**

No locks available.

- **`UVWASI_ENOLINK`**

Reserved.

- **`UVWASI_ENOMEM`**

Not enough space.

- **`UVWASI_ENOMSG`**

No message of the desired type.

- **`UVWASI_ENOPROTOOPT`**

Protocol not available.

- **`UVWASI_ENOSPC`**

No space left on device.

- **`UVWASI_ENOSYS`**

Function not supported.

- **`UVWASI_ENOTCONN`**

The socket is not connected.

- **`UVWASI_ENOTDIR`**

Not a directory or a symbolic link to a directory.

- **`UVWASI_ENOTEMPTY`**

Directory not empty.

- **`UVWASI_ENOTRECOVERABLE`**

State not recoverable.

- **`UVWASI_ENOTSOCK`**

Not a socket.

- **`UVWASI_ENOTSUP`**

Not supported, or operation not supported on socket.

- **`UVWASI_ENOTTY`**

Inappropriate I/O control operation.

- **`UVWASI_ENXIO`**

No such device or address.

- **`UVWASI_EOVERFLOW`**

Value too large to be stored in data type.

- **`UVWASI_EOWNERDEAD`**

Previous owner died.

- **`UVWASI_EPERM`**

Operation not permitted.

- **`UVWASI_EPIPE`**

Broken pipe.

- **`UVWASI_EPROTO`**

Protocol error.

- **`UVWASI_EPROTONOSUPPORT`**

Protocol not supported.

- **`UVWASI_EPROTOTYPE`**

Protocol wrong type for socket.

- **`UVWASI_ERANGE`**

Result too large.

- **`UVWASI_EROFS`**

Read-only file system.

- **`UVWASI_ESPIPE`**

Invalid seek.

- **`UVWASI_ESRCH`**

No such process.

- **`UVWASI_ESTALE`**

Reserved.

- **`UVWASI_ETIMEDOUT`**

Connection timed out.

- **`UVWASI_ETXTBSY`**

Text file busy.

- **`UVWASI_EXDEV`**

Cross-device link.

- **`UVWASI_ENOTCAPABLE`**

Extension: Capabilities insufficient.

### `uvwasi_event_t` (`struct`)

An event that occurred.

Used by [`uvwasi_poll_oneoff()`](#poll_oneoff).

Members:

- [\_\_wasi\_userdata\_t](#userdata) userdata

User-provided value that got attached to
[`uvwasi_subscription_t::userdata`](#subscription.userdata).

- [\_\_wasi\_errno\_t](#errno) error

If non-zero, an error that occurred while processing
the subscription request.

- [\_\_wasi\_eventtype\_t](#eventtype) type

The type of the event that occurred.

- When `type` is [`UVWASI_EVENTTYPE_FD_READ`](#eventtype.fd_read) or [`UVWASI_EVENTTYPE_FD_WRITE`](#eventtype.fd_write):

- **`u.fd_readwrite`**

- [\_\_wasi\_filesize\_t](#filesize) nbytes

The number of bytes available for reading or writing.

- [\_\_wasi\_eventrwflags\_t](#eventrwflags) flags

The state of the file descriptor.

### `uvwasi_eventrwflags_t` (`uint16_t` bitfield)

The state of the file descriptor subscribed to with
[`UVWASI_EVENTTYPE_FD_READ`](#eventtype.fd_read) or [`UVWASI_EVENTTYPE_FD_WRITE`](#eventtype.fd_write).

Used by [`uvwasi_event_t`](#event).

Possible values:

- **`UVWASI_EVENT_FD_READWRITE_HANGUP`**

The peer of this socket has closed or disconnected.

### `uvwasi_eventtype_t` (`uint8_t`)

Type of a subscription to an event or its occurrence.

Used by [`uvwasi_event_t`](#event) and [`uvwasi_subscription_t`](#subscription).

Possible values:

- **`UVWASI_EVENTTYPE_CLOCK`**

The time value of clock [`uvwasi_subscription_t::u.clock.clock_id`](#subscription.u.clock.clock_id)
has reached timestamp [`uvwasi_subscription_t::u.clock.timeout`](#subscription.u.clock.timeout).

- **`UVWASI_EVENTTYPE_FD_READ`**

File descriptor [`uvwasi_subscription_t::u.fd_readwrite.fd`](#subscription.u.fd_readwrite.fd) has
data available for reading. This event always triggers
for regular files.

- **`UVWASI_EVENTTYPE_FD_WRITE`**

File descriptor [`uvwasi_subscription_t::u.fd_readwrite.fd`](#subscription.u.fd_readwrite.fd) has
capacity available for writing. This event always
triggers for regular files.

### `uvwasi_exitcode_t` (`uint32_t`)

Exit code generated by a process when exiting.

Used by [`uvwasi_proc_exit()`](#proc_exit).

### `uvwasi_fd_t` (`uint32_t`)

A file descriptor number.

Used by many functions in this API.

As in POSIX, three file descriptor numbers are provided to instances
on startup -- 0, 1, and 2, (a.k.a. `STDIN_FILENO`, `STDOUT_FILENO`,
and `STDERR_FILENO`).

Other than these, WASI implementations are not required to allocate
new file descriptors in ascending order.

### `uvwasi_fdflags_t` (`uint16_t` bitfield)

File descriptor flags.

Used by [`uvwasi_fdstat_t`](#fdstat), [`uvwasi_fd_fdstat_set_flags()`](#fd_fdstat_set_flags), and [`uvwasi_path_open()`](#path_open).

Possible values:

- **`UVWASI_FDFLAG_APPEND`**

Append mode: Data written to the file is always
appended to the file's end.

- **`UVWASI_FDFLAG_DSYNC`**

Write according to synchronized I/O data integrity
completion. Only the data stored in the file is
synchronized.

- **`UVWASI_FDFLAG_NONBLOCK`**

Non-blocking mode.

- **`UVWASI_FDFLAG_RSYNC`**

Synchronized read I/O operations.

- **`UVWASI_FDFLAG_SYNC`**

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.

### `uvwasi_fdstat_t` (`struct`)

File descriptor attributes.

Used by [`uvwasi_fd_fdstat_get()`](#fd_fdstat_get).

Members:

- [\_\_wasi\_filetype\_t](#filetype) fs\_filetype

File type.

- [\_\_wasi\_fdflags\_t](#fdflags) fs\_flags

File descriptor flags.

- [\_\_wasi\_rights\_t](#rights) fs\_rights\_base

Rights that apply to this file descriptor.

- [\_\_wasi\_rights\_t](#rights) fs\_rights\_inheriting

Maximum set of rights that may be installed on new
file descriptors that are created through this file
descriptor, e.g., through [`uvwasi_path_open()`](#path_open).

### `uvwasi_filedelta_t` (`int64_t`)

Relative offset within a file.

Used by [`uvwasi_fd_seek()`](#fd_seek).

### `uvwasi_filesize_t` (`uint64_t`)

Non-negative file size or length of a region within a file.

Used by [`uvwasi_event_t`](#event), [`uvwasi_filestat_t`](#filestat), [`uvwasi_fd_pread()`](#fd_pread), [`uvwasi_fd_pwrite()`](#fd_pwrite), [`uvwasi_fd_seek()`](#fd_seek), [`uvwasi_path_tell()`](#path_tell), [`uvwasi_fd_advise()`](#fd_advise), [`uvwasi_fd_allocate()`](#fd_allocate), and [`uvwasi_fd_filestat_set_size()`](#fd_filestat_set_size).

### `uvwasi_filestat_t` (`struct`)

File attributes.

Used by [`uvwasi_fd_filestat_get()`](#fd_filestat_get) and [`uvwasi_path_filestat_get()`](#path_filestat_get).

Members:

- [\_\_wasi\_device\_t](#device) st\_dev

Device ID of device containing the file.

- [\_\_wasi\_inode\_t](#inode) st\_ino

File serial number.

- [\_\_wasi\_filetype\_t](#filetype) st\_filetype

File type.

- [\_\_wasi\_linkcount\_t](#linkcount) st\_nlink

Number of hard links to the file.

- [\_\_wasi\_filesize\_t](#filesize) st\_size

For regular files, the file size in bytes. For
symbolic links, the length in bytes of the pathname
contained in the symbolic link.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_atim

Last data access timestamp.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_mtim

Last data modification timestamp.

- [\_\_wasi\_timestamp\_t](#timestamp) st\_ctim

Last file status change timestamp.

### `uvwasi_filetype_t` (`uint8_t`)

The type of a file descriptor or file.

Used by [`uvwasi_dirent_t`](#dirent), [`uvwasi_fdstat_t`](#fdstat), and [`uvwasi_filestat_t`](#filestat).

Possible values:

- **`UVWASI_FILETYPE_UNKNOWN`**

The type of the file descriptor or file is unknown or
is different from any of the other types specified.

- **`UVWASI_FILETYPE_BLOCK_DEVICE`**

The file descriptor or file refers to a block device
inode.

- **`UVWASI_FILETYPE_CHARACTER_DEVICE`**

The file descriptor or file refers to a character
device inode.

- **`UVWASI_FILETYPE_DIRECTORY`**

The file descriptor or file refers to a directory
inode.

- **`UVWASI_FILETYPE_REGULAR_FILE`**

The file descriptor or file refers to a regular file
inode.

- **`UVWASI_FILETYPE_SOCKET_DGRAM`**

The file descriptor or file refers to a datagram
socket.

- **`UVWASI_FILETYPE_SOCKET_STREAM`**

The file descriptor or file refers to a byte-stream
socket.

- **`UVWASI_FILETYPE_SYMBOLIC_LINK`**

The file refers to a symbolic link inode.

### `uvwasi_fstflags_t` (`uint16_t` bitfield)

Which file time attributes to adjust.

Used by [`uvwasi_fd_filestat_set_times()`](#fd_filestat_set_times) and [`uvwasi_path_filestat_set_times()`](#path_filestat_set_times).

Possible values:

- **`UVWASI_FILESTAT_SET_ATIM`**

Adjust the last data access timestamp to the value
stored in [`uvwasi_filestat_t::st_atim`](#filestat.st_atim).

- **`UVWASI_FILESTAT_SET_ATIM_NOW`**

Adjust the last data access timestamp to the time
of clock [`UVWASI_CLOCK_REALTIME`](#clockid.realtime).

- **`UVWASI_FILESTAT_SET_MTIM`**

Adjust the last data modification timestamp to the
value stored in [`uvwasi_filestat_t::st_mtim`](#filestat.st_mtim).

- **`UVWASI_FILESTAT_SET_MTIM_NOW`**

Adjust the last data modification timestamp to the
time of clock [`UVWASI_CLOCK_REALTIME`](#clockid.realtime).

### `uvwasi_inode_t` (`uint64_t`)

File serial number that is unique within its file system.

Used by [`uvwasi_dirent_t`](#dirent) and [`uvwasi_filestat_t`](#filestat).

### `uvwasi_iovec_t` (`struct`)

A region of memory for scatter/gather reads.

Used by [`uvwasi_fd_pread()`](#fd_pread), [`uvwasi_fd_read()`](#fd_read), and [`uvwasi_sock_recv()`](#sock_recv).

Members:

- void \*buf and \_\_wasi\_size\_t buf\_len

The address and length of the buffer to be filled.

### `uvwasi_linkcount_t` (`uint64_t`)

Number of hard links to an inode.

Used by [`uvwasi_filestat_t`](#filestat).

### `uvwasi_lookupflags_t` (`uint32_t` bitfield)

Flags determining the method of how paths are resolved.

Used by [`uvwasi_path_filestat_get()`](#path_filestat_get), [`uvwasi_path_filestat_set_times()`](#path_filestat_set_times), [`uvwasi_path_link()`](#path_link), and [`uvwasi_path_open()`](#path_open).

Possible values:

- **`UVWASI_LOOKUP_SYMLINK_FOLLOW`**

As long as the resolved path corresponds to a symbolic
link, it is expanded.

### `uvwasi_oflags_t` (`uint16_t` bitfield)

Open flags used by [`uvwasi_path_open()`](#path_open).

Used by [`uvwasi_path_open()`](#path_open).

Possible values:

- **`UVWASI_O_CREAT`**

Create file if it does not exist.

- **`UVWASI_O_DIRECTORY`**

Fail if not a directory.

- **`UVWASI_O_EXCL`**

Fail if file already exists.

- **`UVWASI_O_TRUNC`**

Truncate file to size 0.

### `uvwasi_riflags_t` (`uint16_t` bitfield)

Flags provided to [`uvwasi_sock_recv()`](#sock_recv).

Used by [`uvwasi_sock_recv()`](#sock_recv).

Possible values:

- **`UVWASI_SOCK_RECV_PEEK`**

Returns the message without removing it from the
socket's receive queue.

- **`UVWASI_SOCK_RECV_WAITALL`**

On byte-stream sockets, block until the full amount
of data can be returned.

### `uvwasi_rights_t` (`uint64_t` bitfield)

File descriptor rights, determining which actions may be
performed.

Used by [`uvwasi_fdstat_t`](#fdstat), [`uvwasi_fd_fdstat_set_rights()`](#fd_fdstat_set_rights), and [`uvwasi_path_open()`](#path_open).

Possible values:

- **`UVWASI_RIGHT_FD_DATASYNC`**

The right to invoke [`uvwasi_fd_datasync()`](#fd_datasync).

If [`UVWASI_RIGHT_PATH_OPEN`](#rights.path_open) is set, includes the right to
invoke [`uvwasi_path_open()`](#path_open) with [`UVWASI_FDFLAG_DSYNC`](#fdflags.dsync).

- **`UVWASI_RIGHT_FD_READ`**

The right to invoke [`uvwasi_fd_read()`](#fd_read) and [`uvwasi_sock_recv()`](#sock_recv).

If [`UVWASI_RIGHT_FD_SEEK`](#rights.fd_seek) is set, includes the right to invoke
[`uvwasi_fd_pread()`](#fd_pread).

- **`UVWASI_RIGHT_FD_SEEK`**

The right to invoke [`uvwasi_fd_seek()`](#fd_seek). This flag implies
[`UVWASI_RIGHT_FD_TELL`](#rights.fd_tell).

- **`UVWASI_RIGHT_FD_FDSTAT_SET_FLAGS`**

The right to invoke [`uvwasi_fd_fdstat_set_flags()`](#fd_fdstat_set_flags).

- **`UVWASI_RIGHT_FD_SYNC`**

The right to invoke [`uvwasi_fd_sync()`](#fd_sync).

If [`UVWASI_RIGHT_PATH_OPEN`](#rights.path_open) is set, includes the right to
invoke [`uvwasi_path_open()`](#path_open) with [`UVWASI_FDFLAG_RSYNC`](#fdflags.rsync) and
[`UVWASI_FDFLAG_DSYNC`](#fdflags.dsync).

- **`UVWASI_RIGHT_FD_TELL`**

The right to invoke [`uvwasi_fd_seek()`](#fd_seek) in such a way that the
file offset remains unaltered (i.e., [`UVWASI_WHENCE_CUR`](#whence.cur) with
offset zero), or to invoke [`uvwasi_fd_tell()`](#fd_tell).

- **`UVWASI_RIGHT_FD_WRITE`**

The right to invoke [`uvwasi_fd_write()`](#fd_write) and [`uvwasi_sock_send()`](#sock_send).

If [`UVWASI_RIGHT_FD_SEEK`](#rights.fd_seek) is set, includes the right to
invoke [`uvwasi_fd_pwrite()`](#fd_pwrite).

- **`UVWASI_RIGHT_FD_ADVISE`**

The right to invoke [`uvwasi_fd_advise()`](#fd_advise).

- **`UVWASI_RIGHT_FD_ALLOCATE`**

The right to invoke [`uvwasi_fd_allocate()`](#fd_allocate).

- **`UVWASI_RIGHT_PATH_CREATE_DIRECTORY`**

The right to invoke [`uvwasi_path_create_directory()`](#path_create_directory).

- **`UVWASI_RIGHT_PATH_CREATE_FILE`**

If [`UVWASI_RIGHT_PATH_OPEN`](#rights.path_open) is set, the right to invoke
[`uvwasi_path_open()`](#path_open) with [`UVWASI_O_CREAT`](#oflags.creat).

- **`UVWASI_RIGHT_PATH_LINK_SOURCE`**

The right to invoke [`uvwasi_path_link()`](#path_link) with the file
descriptor as the source directory.

- **`UVWASI_RIGHT_PATH_LINK_TARGET`**

The right to invoke [`uvwasi_path_link()`](#path_link) with the file
descriptor as the target directory.

- **`UVWASI_RIGHT_PATH_OPEN`**

The right to invoke [`uvwasi_path_open()`](#path_open).

- **`UVWASI_RIGHT_FD_READDIR`**

The right to invoke [`uvwasi_fd_readdir()`](#fd_readdir).

- **`UVWASI_RIGHT_PATH_READLINK`**

The right to invoke [`uvwasi_path_readlink()`](#path_readlink).

- **`UVWASI_RIGHT_PATH_RENAME_SOURCE`**

The right to invoke [`uvwasi_path_rename()`](#path_rename) with the file
descriptor as the source directory.

- **`UVWASI_RIGHT_PATH_RENAME_TARGET`**

The right to invoke [`uvwasi_path_rename()`](#path_rename) with the file
descriptor as the target directory.

- **`UVWASI_RIGHT_PATH_FILESTAT_GET`**

The right to invoke [`uvwasi_path_filestat_get()`](#path_filestat_get).

- **`UVWASI_RIGHT_PATH_FILESTAT_SET_SIZE`**

The right to change a file's size (there is no `uvwasi_path_filestat_set_size()`).

If [`UVWASI_RIGHT_PATH_OPEN`](#rights.path_open) is set, includes the right to
invoke [`uvwasi_path_open()`](#path_open) with [`UVWASI_O_TRUNC`](#oflags.trunc).

- **`UVWASI_RIGHT_PATH_FILESTAT_SET_TIMES`**

The right to invoke [`uvwasi_path_filestat_set_times()`](#path_filestat_set_times).

- **`UVWASI_RIGHT_FD_FILESTAT_GET`**

The right to invoke [`uvwasi_fd_filestat_get()`](#fd_filestat_get).

- **`UVWASI_RIGHT_FD_FILESTAT_SET_SIZE`**

The right to invoke [`uvwasi_fd_filestat_set_size()`](#fd_filestat_set_size).

- **`UVWASI_RIGHT_FD_FILESTAT_SET_TIMES`**

The right to invoke [`uvwasi_fd_filestat_set_times()`](#fd_filestat_set_times).

- **`UVWASI_RIGHT_PATH_SYMLINK`**

The right to invoke [`uvwasi_path_symlink()`](#path_symlink).

- **`UVWASI_RIGHT_PATH_UNLINK_FILE`**

The right to invoke [`uvwasi_path_unlink_file()`](#path_unlink_file).

- **`UVWASI_RIGHT_PATH_REMOVE_DIRECTORY`**

The right to invoke [`uvwasi_path_remove_directory()`](#path_remove_directory).

- **`UVWASI_RIGHT_POLL_FD_READWRITE`**

If [`UVWASI_RIGHT_FD_READ`](#rights.fd_read) is set, includes the right to
invoke [`uvwasi_poll_oneoff()`](#poll_oneoff) to subscribe to [`UVWASI_EVENTTYPE_FD_READ`](#eventtype.fd_read).

If [`UVWASI_RIGHT_FD_WRITE`](#rights.fd_write) is set, includes the right to
invoke [`uvwasi_poll_oneoff()`](#poll_oneoff) to subscribe to [`UVWASI_EVENTTYPE_FD_WRITE`](#eventtype.fd_write).

- **`UVWASI_RIGHT_SOCK_SHUTDOWN`**

The right to invoke [`uvwasi_sock_shutdown()`](#sock_shutdown).

### `uvwasi_roflags_t` (`uint16_t` bitfield)

Flags returned by [`uvwasi_sock_recv()`](#sock_recv).

Used by [`uvwasi_sock_recv()`](#sock_recv).

Possible values:

- **`UVWASI_SOCK_RECV_DATA_TRUNCATED`**

Returned by [`uvwasi_sock_recv()`](#sock_recv): Message data has been
truncated.

### `uvwasi_sdflags_t` (`uint8_t` bitfield)

Which channels on a socket to shut down.

Used by [`uvwasi_sock_shutdown()`](#sock_shutdown).

Possible values:

- **`UVWASI_SHUT_RD`**

Disables further receive operations.

- **`UVWASI_SHUT_WR`**

Disables further send operations.

### `uvwasi_siflags_t` (`uint16_t` bitfield)

Flags provided to [`uvwasi_sock_send()`](#sock_send). As there are currently no flags
defined, it must be set to zero.

Used by [`uvwasi_sock_send()`](#sock_send).

### `uvwasi_signal_t` (`uint8_t`)

Signal condition.

Used by [`uvwasi_proc_raise()`](#proc_raise).

Possible values:

- **`UVWASI_SIGABRT`**

Process abort signal.

Action: Terminates the process.

- **`UVWASI_SIGALRM`**

Alarm clock.

Action: Terminates the process.

- **`UVWASI_SIGBUS`**

Access to an undefined portion of a memory object.

Action: Terminates the process.

- **`UVWASI_SIGCHLD`**

Child process terminated, stopped, or continued.

Action: Ignored.

- **`UVWASI_SIGCONT`**

Continue executing, if stopped.

Action: Continues executing, if stopped.

- **`UVWASI_SIGFPE`**

Erroneous arithmetic operation.

Action: Terminates the process.

- **`UVWASI_SIGHUP`**

Hangup.

Action: Terminates the process.

- **`UVWASI_SIGILL`**

Illegal instruction.

Action: Terminates the process.

- **`UVWASI_SIGINT`**

Terminate interrupt signal.

Action: Terminates the process.

- **`UVWASI_SIGKILL`**

Kill.

Action: Terminates the process.

- **`UVWASI_SIGPIPE`**

Write on a pipe with no one to read it.

Action: Ignored.

- **`UVWASI_SIGQUIT`**

Terminal quit signal.

Action: Terminates the process.

- **`UVWASI_SIGSEGV`**

Invalid memory reference.

Action: Terminates the process.

- **`UVWASI_SIGSTOP`**

Stop executing.

Action: Stops executing.

- **`UVWASI_SIGSYS`**

Bad system call.

Action: Terminates the process.

- **`UVWASI_SIGTERM`**

Termination signal.

Action: Terminates the process.

- **`UVWASI_SIGTRAP`**

Trace/breakpoint trap.

Action: Terminates the process.

- **`UVWASI_SIGTSTP`**

Terminal stop signal.

Action: Stops executing.

- **`UVWASI_SIGTTIN`**

Background process attempting read.

Action: Stops executing.

- **`UVWASI_SIGTTOU`**

Background process attempting write.

Action: Stops executing.

- **`UVWASI_SIGURG`**

High bandwidth data is available at a socket.

Action: Ignored.

- **`UVWASI_SIGUSR1`**

User-defined signal 1.

Action: Terminates the process.

- **`UVWASI_SIGUSR2`**

User-defined signal 2.

Action: Terminates the process.

- **`UVWASI_SIGVTALRM`**

Virtual timer expired.

Action: Terminates the process.

- **`UVWASI_SIGXCPU`**

CPU time limit exceeded.

Action: Terminates the process.

- **`UVWASI_SIGXFSZ`**

File size limit exceeded.

Action: Terminates the process.

### `uvwasi_subclockflags_t` (`uint16_t` bitfield)

Flags determining how to interpret the timestamp provided in
[`uvwasi_subscription_t::u.clock.timeout`](#subscription.u.clock.timeout).

Used by [`uvwasi_subscription_t`](#subscription).

Possible values:

- **`UVWASI_SUBSCRIPTION_CLOCK_ABSTIME`**

If set, treat the timestamp provided in
[`uvwasi_subscription_t::u.clock.timeout`](#subscription.u.clock.timeout) as an absolute timestamp
of clock [`uvwasi_subscription_t::u.clock.clock_id`](#subscription.u.clock.clock_id).

If clear, treat the timestamp provided in
[`uvwasi_subscription_t::u.clock.timeout`](#subscription.u.clock.timeout) relative to the current
time value of clock [`uvwasi_subscription_t::u.clock.clock_id`](#subscription.u.clock.clock_id).

### `uvwasi_subscription_t` (`struct`)

Subscription to an event.

Used by [`uvwasi_poll_oneoff()`](#poll_oneoff).

Members:

- [\_\_wasi\_userdata\_t](#userdata) userdata

User-provided value that is attached to the subscription in the
implementation and returned through
[`uvwasi_event_t::userdata`](#event.userdata).

- [\_\_wasi\_eventtype\_t](#eventtype) type

The type of the event to which to subscribe.

- When `type` is [`UVWASI_EVENTTYPE_CLOCK`](#eventtype.u.clock):

- **`u.clock`**

- [\_\_wasi\_clockid\_t](#clockid) clock\_id

The clock against which to compare the timestamp.

- [\_\_wasi\_timestamp\_t](#timestamp) timeout

The absolute or relative timestamp.

- [\_\_wasi\_timestamp\_t](#timestamp) precision

The amount of time that the implementation may wait additionally
to coalesce with other events.

- [\_\_wasi\_subclockflags\_t](#subclockflags) flags

Flags specifying whether the timeout is absolute or relative.

- When `type` is [`UVWASI_EVENTTYPE_FD_READ`](#eventtype.fd_read) or [`UVWASI_EVENTTYPE_FD_WRITE`](#eventtype.fd_write):

- **`u.fd_readwrite`**

- [\_\_wasi\_fd\_t](#fd) fd

The file descriptor on which to wait for it to become ready
for reading or writing.

### `uvwasi_timestamp_t` (`uint64_t`)

Timestamp in nanoseconds.

Used by [`uvwasi_filestat_t`](#filestat), [`uvwasi_subscription_t`](#subscription), [`uvwasi_clock_res_get()`](#clock_res_get), [`uvwasi_clock_time_get()`](#clock_time_get), [`uvwasi_fd_filestat_set_times()`](#fd_filestat_set_times), and [`uvwasi_path_filestat_set_times()`](#path_filestat_set_times).

### `uvwasi_userdata_t` (`uint64_t`)

User-provided value that may be attached to objects that is
retained when extracted from the implementation.

Used by [`uvwasi_event_t`](#event) and [`uvwasi_subscription_t`](#subscription).

### `uvwasi_whence_t` (`uint8_t`)

The position relative to which to set the offset of the file descriptor.

Used by [`uvwasi_fd_seek()`](#fd_seek).

Possible values:

- **`UVWASI_WHENCE_CUR`**

Seek relative to current position.

- **`UVWASI_WHENCE_END`**

Seek relative to end-of-file.

- **`UVWASI_WHENCE_SET`**

Seek relative to start-of-file.

## Doing a release

To do a release complete the following steps:

* Look at the list of changes - https://github.com/nodejs/uvwasi/commits/main.
* Put together a list of notable changes.
See https://github.com/nodejs/uvwasi/releases/tag/v0.0.14
or any of the other releases for example. Use that list in the release commit,
the GitHub release, and the PR to update uvwasi in Node.js (or any other
projects where you update it)
* Update the version in the CMake file. Specifically: https://github.com/nodejs/uvwasi/blob/main/CMakeLists.txt#L5
* Create a release commit. This should just involve changing one line and
adding the notable changes. See
https://github.com/nodejs/uvwasi/commit/6ad5fc996420d0e4e75983ce3deb65f327321f33
as an example.
* PR the release commit. Once it lands, create a GitHub release with
the same notable changes. When doing the GitHub release you will need to select
`Choose a tag` and type in the new tag. That should result in
` Create new tag: vX.Y.Z on publish` where vX.Y.Z matches the tag you specified.
* Update uvwasi in Node.js or any projects you want to update - there are several
other projects that use uvwasi.

[WASI]: https://github.com/WebAssembly/WASI
[libuv]: https://github.com/libuv/libuv
[preview 1]: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md