83 KiB
WASI Core API
This is the API-level documentation for WASI Core. The function names are prefixed with "__wasi_" to reflect how they are spelled in flat-namespace contexts, however at the wasm module level, they are unprefixed, because they're inside a module namespace (currently "wasi_unstable").
Functions that start with __wasi_fd_ operate on file descriptors,
while functions that start with __wasi_path_ operate on filesystem
paths, which are relative to directory file descriptors.
Much inspiration and content here is derived from CloudABI and POSIX, though there are also several differences from CloudABI and POSIX. For example, WASI Core has no concept of processes in the traditional Unix sense. While wasm linear memories have some of the aspects of processes, and it's possible to emulate the full semantics of processes on top of them, this can sometimes be unnatural and inefficient. The goal for WASI Core is to be a WebAssembly-native API that exposes APIs that fit well into the underlying WebAssembly platform, rather than to directly emulate other platforms.
This is also a work in progress, and the API here is still evolving.
System calls
__wasi_args_get()__wasi_args_sizes_get()__wasi_clock_res_get()__wasi_clock_time_get()__wasi_environ_get()__wasi_environ_sizes_get()__wasi_fd_advise()__wasi_fd_allocate()__wasi_fd_close()__wasi_fd_datasync()__wasi_fd_fdstat_get()__wasi_fd_fdstat_set_flags()__wasi_fd_fdstat_set_rights()__wasi_fd_filestat_get()__wasi_fd_filestat_set_size()__wasi_fd_filestat_set_times()__wasi_fd_pread()__wasi_fd_prestat_dir_name()__wasi_fd_prestat_get()__wasi_fd_pwrite()__wasi_fd_read()__wasi_fd_readdir()__wasi_fd_renumber()__wasi_fd_seek()__wasi_fd_sync()__wasi_fd_tell()__wasi_fd_write()__wasi_path_create_directory()__wasi_path_filestat_get()__wasi_path_filestat_set_times()__wasi_path_link()__wasi_path_open()__wasi_path_readlink()__wasi_path_remove_directory()__wasi_path_rename()__wasi_path_symlink()__wasi_path_unlink_file()__wasi_poll_oneoff()__wasi_proc_exit()__wasi_proc_raise()__wasi_random_get()__wasi_sched_yield()__wasi_sock_recv()__wasi_sock_send()__wasi_sock_shutdown()
__wasi_args_get()
Read command-line argument data.
The sizes of the buffers should match that returned by __wasi_args_sizes_get().
Inputs:
-
A pointer to a buffer to write the argument pointers.
-
A pointer to a buffer to write the argument string data.
__wasi_args_sizes_get()
Return command-line argument data sizes.
Outputs:
__wasi_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 __WASI_EINVAL.
Note: This is similar to clock_getres in POSIX.
Inputs:
-
__wasi_clockid_t clock_idThe clock for which to return the resolution.
Outputs:
-
__wasi_timestamp_t resolutionThe resolution of the clock.
__wasi_clock_time_get()
Return the time value of a clock.
Note: This is similar to clock_gettime in POSIX.
Inputs:
-
__wasi_clockid_t clock_idThe clock for which to return the time.
-
__wasi_timestamp_t precisionThe maximum lag (exclusive) that the returned time value may have, compared to its actual value.
Outputs:
-
__wasi_timestamp_t timeThe time value of the clock.
__wasi_environ_get()
Read environment variable data.
The sizes of the buffers should match that returned by __wasi_environ_sizes_get().
Inputs:
-
A pointer to a buffer to write the environment variable pointers.
-
A pointer to a buffer to write the environment variable string data.
__wasi_environ_sizes_get()
Return environment variable data sizes.
Outputs:
-
The number of environment variables.
-
The size of the environment variable string data.
__wasi_fd_advise()
Provide file advisory information on a file descriptor.
Note: This is similar to posix_fadvise in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor for the file for which to provide file advisory information.
-
__wasi_filesize_t offsetThe offset within the file to which the advisory applies.
-
The length of the region to which the advisory applies.
-
__wasi_advice_t adviceThe advice.
__wasi_fd_allocate()
Force the allocation of space in a file.
Note: This is similar to posix_fallocate in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor for the file in which to allocate space.
-
__wasi_filesize_t offsetThe offset at which to start the allocation.
-
The length of the area that is allocated.
__wasi_fd_close()
Close a file descriptor.
Note: This is similar to close in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor to close.
__wasi_fd_datasync()
Synchronize the data of a file to disk.
Note: This is similar to fdatasync in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor of the file to synchronize to disk.
__wasi_fd_fdstat_get()
Get the attributes of a file descriptor.
Note: This returns similar flags to fcntl(fd, F_GETFL) in POSIX, as well
as additional fields.
Inputs:
-
__wasi_fd_t fdThe file descriptor to inspect.
-
__wasi_fdstat_t *bufThe buffer where the file descriptor's attributes are stored.
__wasi_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 fdThe file descriptor to operate on.
-
__wasi_fdflags_t flagsThe desired values of the file descriptor flags.
__wasi_fd_fdstat_set_rights()
Adjust the rights associated with a file descriptor.
This can only be used to remove rights, and returns
__WASI_ENOTCAPABLE if called in a way that would attempt
to add rights.
Inputs:
-
__wasi_fd_t fdThe file descriptor to operate on.
-
__wasi_rights_t fs_rights_baseThe desired base rights of the file descriptor.
-
__wasi_rights_t fs_rights_inheritingThe desired inheriting rights of the file descriptor.
__wasi_fd_filestat_get()
Return the attributes of an open file.
Inputs:
-
__wasi_fd_t fdThe file descriptor to inspect.
-
__wasi_filestat_t *bufThe buffer where the file's attributes are stored.
__wasi_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 fdA file descriptor for the file to adjust.
-
__wasi_filesize_t st_sizeThe desired file size.
__wasi_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 fdThe file descriptor to operate on.
-
__wasi_timestamp_t st_atimThe desired values of the data access timestamp.
-
__wasi_timestamp_t st_mtimThe desired values of the data modification timestamp.
-
__wasi_fstflags_t fst_flagsA bitmask indicating which timestamps to adjust.
__wasi_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 fdThe file descriptor from which to read data.
-
const __wasi_iovec_t *iovsandsize_t iovs_lenList of scatter/gather vectors in which to store data.
-
__wasi_filesize_t offsetThe offset within the file at which to read.
Outputs:
__wasi_fd_prestat_dir_name()
Return a description of the given preopened file descriptor.
Inputs:
-
__wasi_fd_t fdThe file descriptor about which to retrieve information.
-
const char *pathandsize_t path_lenA buffer into which to write the preopened directory name.
__wasi_fd_prestat_get()
Return a description of the given preopened file descriptor.
Inputs:
-
__wasi_fd_t fdThe file descriptor about which to retrieve information.
-
__wasi_prestat_t *bufThe buffer where the description is stored.
__wasi_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 fdThe file descriptor to which to write data.
-
const __wasi_ciovec_t *iovsandsize_t iovs_lenList of scatter/gather vectors from which to retrieve data.
-
__wasi_filesize_t offsetThe offset within the file at which to write.
Outputs:
__wasi_fd_read()
Read from a file descriptor.
Note: This is similar to readv in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor from which to read data.
-
const __wasi_iovec_t *iovsandsize_t iovs_lenList of scatter/gather vectors to which to store data.
Outputs:
__wasi_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 __wasi_dirent_t object, followed by __wasi_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.
Inputs:
-
__wasi_fd_t fdThe directory from which to read the directory entries.
-
The buffer where directory entries are stored.
-
__wasi_dircookie_t cookieThe location within the directory to start reading.
Outputs:
-
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.
__wasi_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 fromThe file descriptor to renumber.
-
__wasi_fd_t toThe file descriptor to overwrite.
__wasi_fd_seek()
Move the offset of a file descriptor.
Note: This is similar to lseek in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor to operate on.
-
__wasi_filedelta_t offsetThe number of bytes to move.
-
__wasi_whence_t whenceThe base from which the offset is relative.
Outputs:
-
__wasi_filesize_t newoffsetThe new offset of the file descriptor, relative to the start of the file.
__wasi_fd_sync()
Synchronize the data and metadata of a file to disk.
Note: This is similar to fsync in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor of the file containing the data and metadata to synchronize to disk.
__wasi_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 fdThe file descriptor to inspect.
Outputs:
-
__wasi_filesize_t offsetThe current offset of the file descriptor, relative to the start of the file.
__wasi_fd_write()
Write to a file descriptor.
Note: This is similar to writev in POSIX.
Inputs:
-
__wasi_fd_t fdThe file descriptor to which to write data.
-
const __wasi_ciovec_t *iovsandsize_t iovs_lenList of scatter/gather vectors from which to retrieve data.
Outputs:
__wasi_path_create_directory()
Create a directory.
Note: This is similar to mkdirat in POSIX.
Inputs:
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
const char *pathandsize_t path_lenThe path at which to create the directory.
__wasi_path_filestat_get()
Return the attributes of a file or directory.
Note: This is similar to stat in POSIX.
Inputs:
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
__wasi_lookupflags_t flagsFlags determining the method of how the path is resolved.
-
const char *pathandsize_t path_lenThe path of the file or directory to inspect.
-
__wasi_filestat_t *bufThe buffer where the file's attributes are stored.
__wasi_path_filestat_set_times()
Adjust the timestamps of a file or directory.
Note: This is similar to utimensat in POSIX.
Inputs:
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
__wasi_lookupflags_t flagsFlags determining the method of how the path is resolved.
-
const char *pathandsize_t path_lenThe path of the file or directory to operate on.
-
__wasi_timestamp_t st_atimThe desired values of the data access timestamp.
-
__wasi_timestamp_t st_mtimThe desired values of the data modification timestamp.
-
__wasi_fstflags_t fst_flagsA bitmask indicating which timestamps to adjust.
__wasi_path_link()
Create a hard link.
Note: This is similar to linkat in POSIX.
Inputs:
-
__wasi_fd_t old_fdThe working directory at which the resolution of the old path starts.
-
__wasi_lookupflags_t old_flagsFlags determining the method of how the path is resolved.
-
const char *old_pathandsize_t old_path_lenThe source path from which to link.
-
__wasi_fd_t new_fdThe working directory at which the resolution of the new path starts.
-
const char *new_pathandsize_t new_path_lenThe destination path at which to create the hard link.
__wasi_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 dirfdThe working directory at which the resolution of the path starts.
-
__wasi_lookupflags_t dirflagsFlags determining the method of how the path is resolved.
-
const char *pathandsize_t path_lenThe relative path of the file or directory to open, relative to the
dirfddirectory. -
__wasi_oflags_t o_flagsThe method by which to open the file.
-
__wasi_rights_t fs_rights_baseThe initial base 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.
-
__wasi_rights_t fs_rights_inheritingThe initial inheriting 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 inheriting rights are rights that will apply to file descriptors derived from the file descriptor itself.
-
__wasi_fdflags_t fs_flagsThe initial flags of the file descriptor.
Outputs:
-
__wasi_fd_t fdThe file descriptor of the file that has been opened.
__wasi_path_readlink()
Read the contents of a symbolic link.
Note: This is similar to readlinkat in POSIX.
Inputs:
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
const char *pathandsize_t path_lenThe path of the symbolic link from which to read.
-
The buffer to which to write the contents of the symbolic link.
Outputs:
__wasi_path_remove_directory()
Remove a directory.
Return __WASI_ENOTEMPTY if the directory is not empty.
Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR) in POSIX.
Inputs:
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
const char *pathandsize_t path_lenThe path to a directory to remove.
__wasi_path_rename()
Rename a file or directory.
Note: This is similar to renameat in POSIX.
Inputs:
-
__wasi_fd_t old_fdThe working directory at which the resolution of the old path starts.
-
const char *old_pathandsize_t old_path_lenThe source path of the file or directory to rename.
-
__wasi_fd_t new_fdThe working directory at which the resolution of the new path starts.
-
const char *new_pathandsize_t new_path_lenThe destination path to which to rename the file or directory.
__wasi_path_symlink()
Create a symbolic link.
Note: This is similar to symlinkat in POSIX.
Inputs:
-
const char *old_pathandsize_t old_path_lenThe contents of the symbolic link.
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
const char *new_pathandsize_t new_path_lenThe destination path at which to create the symbolic link.
__wasi_path_unlink_file()
Unlink a file.
Return __WASI_EISDIR if the path refers to a directory.
Note: This is similar to unlinkat(fd, path, 0) in POSIX.
Inputs:
-
__wasi_fd_t fdThe working directory at which the resolution of the path starts.
-
const char *pathandsize_t path_lenThe path to a file to unlink.
__wasi_poll_oneoff()
Concurrently poll for the occurrence of a set of events.
Inputs:
-
const __wasi_subscription_t *inThe events to which to subscribe.
-
__wasi_event_t *outThe events that have occurred.
-
Both the number of subscriptions and events.
Outputs:
__wasi_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 rvalThe exit code returned by the process.
Does not return.
__wasi_proc_raise()
Send a signal to the process of the calling thread.
Note: This is similar to raise in POSIX.
Inputs:
-
__wasi_signal_t sigThe signal condition to trigger.
__wasi_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:
__wasi_sched_yield()
Temporarily yield execution of the calling thread.
Note: This is similar to sched_yield in POSIX.
__wasi_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 sockThe socket on which to receive data.
-
const __wasi_iovec_t *ri_dataandsize_t ri_data_lenList of scatter/gather vectors to which to store data.
-
__wasi_riflags_t ri_flagsMessage flags.
Outputs:
-
Number of bytes stored in
ri_data. -
__wasi_roflags_t ro_flagsMessage flags.
__wasi_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 sockThe socket on which to send data.
-
const __wasi_ciovec_t *si_dataandsize_t si_data_lenList of scatter/gather vectors to which to retrieve data.
-
__wasi_siflags_t si_flagsMessage flags.
Outputs:
__wasi_sock_shutdown()
Shut down socket send and receive channels.
Note: This is similar to shutdown in POSIX.
Inputs:
-
__wasi_fd_t sockThe socket on which to shutdown channels.
-
__wasi_sdflags_t howWhich channels on the socket to shut down.
Types
__wasi_advice_t (uint8_t)
File or memory access pattern advisory information.
Used by __wasi_fd_advise().
Possible values:
-
The application expects that it will not access the specified data in the near future.
-
The application expects to access the specified data once and then not reuse it thereafter.
-
The application has no advice to give on its behavior with respect to the specified data.
-
The application expects to access the specified data in a random order.
-
The application expects to access the specified data sequentially from lower offsets to higher offsets.
-
The application expects to access the specified data in the near future.
__wasi_ciovec_t (struct)
A region of memory for scatter/gather writes.
Used by __wasi_fd_pwrite(), __wasi_fd_write(), and __wasi_sock_send().
Members:
__wasi_clockid_t (uint32_t)
Identifiers for clocks.
Used by __wasi_subscription_t, __wasi_clock_res_get(), and __wasi_clock_time_get().
Possible values:
-
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.
-
__WASI_CLOCK_PROCESS_CPUTIME_IDThe CPU-time clock associated with the current process.
-
The clock measuring real time. Time value zero corresponds with 1970-01-01T00:00:00Z.
-
__WASI_CLOCK_THREAD_CPUTIME_IDThe CPU-time clock associated with the current thread.
__wasi_device_t (uint64_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.
Used by __wasi_filestat_t.
__wasi_dircookie_t (uint64_t)
A reference to the offset of a directory entry.
Used by __wasi_dirent_t and __wasi_fd_readdir().
Special values:
__wasi_dirent_t (struct)
A directory entry.
Members:
-
__wasi_dircookie_t d_nextThe offset of the next directory entry stored in this directory.
-
__wasi_inode_t d_inoThe serial number of the file referred to by this directory entry.
-
The length of the name of the directory entry.
-
__wasi_filetype_t d_typeThe type of the file referred to by this directory entry.
__wasi_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 __wasi_event_t.
Possible values:
-
No error occurred. System call completed successfully.
-
Argument list too long.
-
Permission denied.
-
Address in use.
-
Address not available.
-
Address family not supported.
-
Resource unavailable, or operation would block.
-
Connection already in progress.
-
Bad file descriptor.
-
Bad message.
-
Device or resource busy.
-
Operation canceled.
-
No child processes.
-
Connection aborted.
-
Connection refused.
-
Connection reset.
-
Resource deadlock would occur.
-
Destination address required.
-
Mathematics argument out of domain of function.
-
Reserved.
-
File exists.
-
Bad address.
-
File too large.
-
Host is unreachable.
-
Identifier removed.
-
Illegal byte sequence.
-
Operation in progress.
-
Interrupted function.
-
Invalid argument.
-
I/O error.
-
Socket is connected.
-
Is a directory.
-
Too many levels of symbolic links.
-
File descriptor value too large.
-
Too many links.
-
Message too large.
-
Reserved.
-
Filename too long.
-
Network is down.
-
Connection aborted by network.
-
Network unreachable.
-
Too many files open in system.
-
No buffer space available.
-
No such device.
-
No such file or directory.
-
Executable file format error.
-
No locks available.
-
Reserved.
-
Not enough space.
-
No message of the desired type.
-
Protocol not available.
-
No space left on device.
-
Function not supported.
-
The socket is not connected.
-
Not a directory or a symbolic link to a directory.
-
Directory not empty.
-
State not recoverable.
-
Not a socket.
-
Not supported, or operation not supported on socket.
-
Inappropriate I/O control operation.
-
No such device or address.
-
Value too large to be stored in data type.
-
Previous owner died.
-
Operation not permitted.
-
Broken pipe.
-
Protocol error.
-
Protocol not supported.
-
Protocol wrong type for socket.
-
Result too large.
-
Read-only file system.
-
Invalid seek.
-
No such process.
-
Reserved.
-
Connection timed out.
-
Text file busy.
-
Cross-device link.
-
Extension: Capabilities insufficient.
__wasi_event_t (struct)
An event that occurred.
Used by __wasi_poll_oneoff().
Members:
-
__wasi_userdata_t userdataUser-provided value that got attached to
__wasi_subscription_t::userdata. -
__wasi_errno_t errorIf non-zero, an error that occurred while processing the subscription request.
-
__wasi_eventtype_t typeThe type of the event that occurred.
-
When
typeis__WASI_EVENTTYPE_FD_READor__WASI_EVENTTYPE_FD_WRITE:-
-
__wasi_filesize_t nbytesThe number of bytes available for reading or writing.
-
__wasi_eventrwflags_t flagsThe state of the file descriptor.
-
-
__wasi_eventrwflags_t (uint16_t bitfield)
The state of the file descriptor subscribed to with
__WASI_EVENTTYPE_FD_READ or __WASI_EVENTTYPE_FD_WRITE.
Used by __wasi_event_t.
Possible values:
__wasi_eventtype_t (uint8_t)
Type of a subscription to an event or its occurrence.
Used by __wasi_event_t and __wasi_subscription_t.
Possible values:
-
The time value of clock
__wasi_subscription_t::u.clock.clock_idhas reached timestamp__wasi_subscription_t::u.clock.timeout. -
File descriptor
__wasi_subscription_t::u.fd_readwrite.fdhas data available for reading. This event always triggers for regular files. -
File descriptor
__wasi_subscription_t::u.fd_readwrite.fdhas capacity available for writing. This event always triggers for regular files.
__wasi_exitcode_t (uint32_t)
Exit code generated by a process when exiting.
Used by __wasi_proc_exit().
__wasi_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). Starting at 3 follow a possibly-entry sequence
of preopened file descriptors provided by the host environment;
information about these may be obtained through
__wasi_fd_prestat_get().
Other than these, WASI implementations are not required to allocate new file descriptors in ascending order.
__wasi_fdflags_t (uint16_t bitfield)
File descriptor flags.
Used by __wasi_fdstat_t, __wasi_fd_fdstat_set_flags(), and __wasi_path_open().
Possible values:
-
Append mode: Data written to the file is always appended to the file's end.
-
Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
-
Non-blocking mode.
-
Synchronized read I/O operations.
-
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.
__wasi_fdstat_t (struct)
File descriptor attributes.
Used by __wasi_fd_fdstat_get().
Members:
-
__wasi_filetype_t fs_filetypeFile type.
-
__wasi_fdflags_t fs_flagsFile descriptor flags.
-
__wasi_rights_t fs_rights_baseRights that apply to this file descriptor.
-
__wasi_rights_t fs_rights_inheritingMaximum 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_filedelta_t (int64_t)
Relative offset within a file.
Used by __wasi_fd_seek().
__wasi_filesize_t (uint64_t)
Non-negative file size or length of a region within a file.
Used by __wasi_event_t, __wasi_filestat_t, __wasi_fd_advise(), __wasi_fd_allocate(), __wasi_fd_filestat_set_size(), __wasi_fd_pread(), __wasi_fd_pwrite(), __wasi_fd_seek(), and __wasi_fd_tell().
__wasi_filestat_t (struct)
File attributes.
Used by __wasi_fd_filestat_get() and __wasi_path_filestat_get().
Members:
-
__wasi_device_t st_devDevice ID of device containing the file.
-
__wasi_inode_t st_inoFile serial number.
-
__wasi_filetype_t st_filetypeFile type.
-
__wasi_linkcount_t st_nlinkNumber of hard links to the file.
-
__wasi_filesize_t st_sizeFor 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 st_atimLast data access timestamp.
-
__wasi_timestamp_t st_mtimLast data modification timestamp.
-
__wasi_timestamp_t st_ctimLast file status change timestamp.
__wasi_filetype_t (uint8_t)
The type of a file descriptor or file.
Used by __wasi_dirent_t, __wasi_fdstat_t, and __wasi_filestat_t.
Possible values:
-
The type of the file descriptor or file is unknown or is different from any of the other types specified.
-
The file descriptor or file refers to a block device inode.
-
__WASI_FILETYPE_CHARACTER_DEVICEThe file descriptor or file refers to a character device inode.
-
The file descriptor or file refers to a directory inode.
-
The file descriptor or file refers to a regular file inode.
-
The file descriptor or file refers to a datagram socket.
-
The file descriptor or file refers to a byte-stream socket.
-
The file refers to a symbolic link inode.
__wasi_fstflags_t (uint16_t bitfield)
Which file time attributes to adjust.
Used by __wasi_fd_filestat_set_times() and __wasi_path_filestat_set_times().
Possible values:
-
Adjust the last data access timestamp to the value stored in
__wasi_filestat_t::st_atim. -
Adjust the last data access timestamp to the time of clock
__WASI_CLOCK_REALTIME. -
Adjust the last data modification timestamp to the value stored in
__wasi_filestat_t::st_mtim. -
Adjust the last data modification timestamp to the time of clock
__WASI_CLOCK_REALTIME.
__wasi_inode_t (uint64_t)
File serial number that is unique within its file system.
Used by __wasi_dirent_t and __wasi_filestat_t.
__wasi_iovec_t (struct)
A region of memory for scatter/gather reads.
Used by __wasi_fd_pread(), __wasi_fd_read(), and __wasi_sock_recv().
Members:
__wasi_linkcount_t (uint32_t)
Number of hard links to an inode.
Used by __wasi_filestat_t.
__wasi_lookupflags_t (uint32_t bitfield)
Flags determining the method of how paths are resolved.
Used by __wasi_path_filestat_get(), __wasi_path_filestat_set_times(), __wasi_path_link(), and __wasi_path_open().
Possible values:
-
As long as the resolved path corresponds to a symbolic link, it is expanded.
__wasi_oflags_t (uint16_t bitfield)
Open flags used by __wasi_path_open().
Used by __wasi_path_open().
Possible values:
-
Create file if it does not exist.
-
Fail if not a directory.
-
Fail if file already exists.
-
Truncate file to size 0.
__wasi_preopentype_t (uint8_t)
Preopened resource type.
Used by __wasi_prestat_t.
Possible values:
__wasi_prestat_t (struct)
Information about a preopened resource.
Used by __wasi_fd_prestat_get().
Members:
-
__wasi_preopentype_t pr_typeThe type of the preopened resource.
-
When
pr_typeis__WASI_PREOPENTYPE_DIR:
__wasi_riflags_t (uint16_t bitfield)
Flags provided to __wasi_sock_recv().
Used by __wasi_sock_recv().
Possible values:
-
Returns the message without removing it from the socket's receive queue.
-
On byte-stream sockets, block until the full amount of data can be returned.
__wasi_rights_t (uint64_t bitfield)
File descriptor rights, determining which actions may be performed.
Used by __wasi_fdstat_t, __wasi_fd_fdstat_set_rights(), and __wasi_path_open().
Possible values:
-
The right to invoke
__wasi_fd_datasync().If
__WASI_RIGHT_PATH_OPENis set, includes the right to invoke__wasi_path_open()with__WASI_FDFLAG_DSYNC. -
The right to invoke
__wasi_fd_read()and__wasi_sock_recv().If
__WASI_RIGHT_FD_SEEKis set, includes the right to invoke__wasi_fd_pread(). -
The right to invoke
__wasi_fd_seek(). This flag implies__WASI_RIGHT_FD_TELL. -
__WASI_RIGHT_FD_FDSTAT_SET_FLAGSThe right to invoke
__wasi_fd_fdstat_set_flags(). -
The right to invoke
__wasi_fd_sync().If
__WASI_RIGHT_PATH_OPENis set, includes the right to invoke__wasi_path_open()with__WASI_FDFLAG_RSYNCand__WASI_FDFLAG_DSYNC. -
The right to invoke
__wasi_fd_seek()in such a way that the file offset remains unaltered (i.e.,__WASI_WHENCE_CURwith offset zero), or to invoke__wasi_fd_tell(). -
The right to invoke
__wasi_fd_write()and__wasi_sock_send().If
__WASI_RIGHT_FD_SEEKis set, includes the right to invoke__wasi_fd_pwrite(). -
The right to invoke
__wasi_fd_advise(). -
The right to invoke
__wasi_fd_allocate(). -
__WASI_RIGHT_PATH_CREATE_DIRECTORYThe right to invoke
__wasi_path_create_directory(). -
If
__WASI_RIGHT_PATH_OPENis set, the right to invoke__wasi_path_open()with__WASI_O_CREAT. -
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 target directory. -
The right to invoke
__wasi_path_open(). -
The right to invoke
__wasi_fd_readdir(). -
The right to invoke
__wasi_path_readlink(). -
__WASI_RIGHT_PATH_RENAME_SOURCEThe right to invoke
__wasi_path_rename()with the file descriptor as the source directory. -
__WASI_RIGHT_PATH_RENAME_TARGETThe right to invoke
__wasi_path_rename()with the file descriptor as the target directory. -
__WASI_RIGHT_PATH_FILESTAT_GETThe right to invoke
__wasi_path_filestat_get(). -
__WASI_RIGHT_PATH_FILESTAT_SET_SIZEThe right to change a file's size (there is no
__wasi_path_filestat_set_size()).If
__WASI_RIGHT_PATH_OPENis set, includes the right to invoke__wasi_path_open()with__WASI_O_TRUNC. -
__WASI_RIGHT_PATH_FILESTAT_SET_TIMESThe right to invoke
__wasi_path_filestat_set_times(). -
The right to invoke
__wasi_fd_filestat_get(). -
__WASI_RIGHT_FD_FILESTAT_SET_SIZEThe right to invoke
__wasi_fd_filestat_set_size(). -
__WASI_RIGHT_FD_FILESTAT_SET_TIMESThe right to invoke
__wasi_fd_filestat_set_times(). -
The right to invoke
__wasi_path_symlink(). -
The right to invoke
__wasi_path_unlink_file(). -
__WASI_RIGHT_PATH_REMOVE_DIRECTORYThe right to invoke
__wasi_path_remove_directory(). -
__WASI_RIGHT_POLL_FD_READWRITEIf
__WASI_RIGHT_FD_READis set, includes the right to invoke__wasi_poll_oneoff()to subscribe to__WASI_EVENTTYPE_FD_READ.If
__WASI_RIGHT_FD_WRITEis set, includes the right to invoke__wasi_poll_oneoff()to subscribe to__WASI_EVENTTYPE_FD_WRITE. -
The right to invoke
__wasi_sock_shutdown().
__wasi_roflags_t (uint16_t bitfield)
Flags returned by __wasi_sock_recv().
Used by __wasi_sock_recv().
Possible values:
-
__WASI_SOCK_RECV_DATA_TRUNCATEDReturned by
__wasi_sock_recv(): Message data has been truncated.
__wasi_sdflags_t (uint8_t bitfield)
Which channels on a socket to shut down.
Used by __wasi_sock_shutdown().
Possible values:
-
Disables further receive operations.
-
Disables further send operations.
__wasi_siflags_t (uint16_t bitfield)
Flags provided to __wasi_sock_send(). As there are currently no flags
defined, it must be set to zero.
Used by __wasi_sock_send().
__wasi_signal_t (uint8_t)
Signal condition.
Used by __wasi_proc_raise().
Possible values:
-
Process abort signal.
Action: Terminates the process.
-
Alarm clock.
Action: Terminates the process.
-
Access to an undefined portion of a memory object.
Action: Terminates the process.
-
Child process terminated, stopped, or continued.
Action: Ignored.
-
Continue executing, if stopped.
Action: Continues executing, if stopped.
-
Erroneous arithmetic operation.
Action: Terminates the process.
-
Hangup.
Action: Terminates the process.
-
Illegal instruction.
Action: Terminates the process.
-
Terminate interrupt signal.
Action: Terminates the process.
-
Kill.
Action: Terminates the process.
-
Write on a pipe with no one to read it.
Action: Ignored.
-
Terminal quit signal.
Action: Terminates the process.
-
Invalid memory reference.
Action: Terminates the process.
-
Stop executing.
Action: Stops executing.
-
Bad system call.
Action: Terminates the process.
-
Termination signal.
Action: Terminates the process.
-
Trace/breakpoint trap.
Action: Terminates the process.
-
Terminal stop signal.
Action: Stops executing.
-
Background process attempting read.
Action: Stops executing.
-
Background process attempting write.
Action: Stops executing.
-
High bandwidth data is available at a socket.
Action: Ignored.
-
User-defined signal 1.
Action: Terminates the process.
-
User-defined signal 2.
Action: Terminates the process.
-
Virtual timer expired.
Action: Terminates the process.
-
CPU time limit exceeded.
Action: Terminates the process.
-
File size limit exceeded.
Action: Terminates the process.
__wasi_subclockflags_t (uint16_t bitfield)
Flags determining how to interpret the timestamp provided in
__wasi_subscription_t::u.clock.timeout.
Used by __wasi_subscription_t.
Possible values:
-
__WASI_SUBSCRIPTION_CLOCK_ABSTIMEIf set, treat the timestamp provided in
__wasi_subscription_t::u.clock.timeoutas an absolute timestamp of clock__wasi_subscription_t::u.clock.clock_id.If clear, treat the timestamp provided in
__wasi_subscription_t::u.clock.timeoutrelative to the current time value of clock__wasi_subscription_t::u.clock.clock_id.
__wasi_subscription_t (struct)
Subscription to an event.
Used by __wasi_poll_oneoff().
Members:
-
__wasi_userdata_t userdataUser-provided value that is attached to the subscription in the implementation and returned through
__wasi_event_t::userdata. -
__wasi_eventtype_t typeThe type of the event to which to subscribe.
-
When
typeis__WASI_EVENTTYPE_CLOCK:-
-
__wasi_userdata_t identifierThe user-defined unique identifier of the clock.
-
__wasi_clockid_t clock_idThe clock against which to compare the timestamp.
-
__wasi_timestamp_t timeoutThe absolute or relative timestamp.
-
__wasi_timestamp_t precisionThe amount of time that the implementation may wait additionally to coalesce with other events.
-
__wasi_subclockflags_t flagsFlags specifying whether the timeout is absolute or relative.
-
-
-
When
typeis__WASI_EVENTTYPE_FD_READor__WASI_EVENTTYPE_FD_WRITE:-
-
__wasi_fd_t fdThe file descriptor on which to wait for it to become ready for reading or writing.
-
-
__wasi_timestamp_t (uint64_t)
Timestamp in nanoseconds.
Used by __wasi_filestat_t, __wasi_subscription_t, __wasi_clock_res_get(), __wasi_clock_time_get(), __wasi_fd_filestat_set_times(), and __wasi_path_filestat_set_times().
__wasi_userdata_t (uint64_t)
User-provided value that may be attached to objects that is retained when extracted from the implementation.
Used by __wasi_event_t and __wasi_subscription_t.
__wasi_whence_t (uint8_t)
The position relative to which to set the offset of the file descriptor.
Used by __wasi_fd_seek().
Possible values: