Transformed from: https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/docs.md
Skip to Types.
Linear memory to be accessed by WASI functions that need it.
args_get
(argv: Pointer<Pointer<u8>>, argv_buf: Pointer<u8>) → Result<(), errno>
Read command-line argument data.
The size of the array should match that returned by args_sizes_get
.
Each argument is expected to be \0
terminated.
The first argument should be a string containing the "name" of the
program. This need not be a usable filesystem path or even file name,
and may even be a fixed string. Subsequent arguments are the arguments
passed to the program by the user.
err
: errno
args_sizes_get
() → Result<(size, size), errno>
Return command-line argument data sizes.
None
error
: Result<(size, size), errno>
environ_get
(environ: Pointer<Pointer<u8>>, environ_buf: Pointer<u8>) → Result<(), errno>
Read environment variable data.
The sizes of the buffers should match that returned by environ_sizes_get
.
Key/value pairs are expected to be joined with =
s, and terminated with \0
s.
err
: errno
environ_sizes_get
() → Result<(size, size), errno>
Return environment variable data sizes.
None
error
: Result<(size, size), errno>
clock_res_get
(id: clockid) → Result<timestamp, errno>
Return the resolution of a clock.
Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
return errno::inval
.
Note: This is similar to clock_getres
in POSIX.
id
: clockid
clock_time_get
(id: clockid, precision: timestamp) → Result<timestamp, errno>
Return the time value of a clock.
Note: This is similar to clock_gettime
in POSIX.
id
: clockid
The clock for which to return the time.
precision
: timestamp
The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
fd_advise
(fd: fd, offset: filesize, len: filesize, advice: advice) → Result<(), errno>
Provide file advisory information on a file descriptor.
Note: This is similar to posix_fadvise
in POSIX.
fd
: fd
offset
: filesize
The offset within the file to which the advisory applies.
len
: filesize
The length of the region to which the advisory applies.
advice
: advice
The advice.
err
: errno
fd_allocate
(fd: fd, offset: filesize, len: filesize) → Result<(), errno>
Force the allocation of space in a file.
Note: This is similar to posix_fallocate
in POSIX.
fd
: fd
offset
: filesize
The offset at which to start the allocation.
len
: filesize
The length of the area that is allocated.
err
: errno
fd_close
(fd: fd) → Result<(), errno>
Close a file descriptor.
Note: This is similar to close
in POSIX.
fd
: fd
err
: errno
fd_datasync
(fd: fd) → Result<(), errno>
Synchronize the data of a file to disk.
Note: This is similar to fdatasync
in POSIX.
fd
: fd
err
: errno
fd_fdstat_get
(fd: fd) → Result<fdstat, errno>
Get the attributes of a file descriptor.
Note: This returns similar flags to fcntl(fd, F_GETFL)
in POSIX, as well as additional fields.
fd
: fd
fd_fdstat_set_flags
(fd: fd, flags: fdflags) → Result<(), errno>
Adjust the flags associated with a file descriptor.
Note: This is similar to fcntl(fd, F_SETFL, flags)
in POSIX.
err
: errno
fd_fdstat_set_rights
(fd: fd, fs_rights_base: rights, fs_rights_inheriting: rights) → Result<(), errno>
Adjust the rights associated with a file descriptor.
This can only be used to remove rights, and returns errno::notcapable
if called in a way that would attempt to add rights
fd
: fd
fs_rights_base
: rights
The desired rights of the file descriptor.
fs_rights_inheriting
: rights
err
: errno
fd_filestat_get
(fd: fd) → Result<filestat, errno>
Return the attributes of an open file.
fd
: fd
fd_filestat_set_size
(fd: fd, size: filesize) → Result<(), errno>
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.
err
: errno
fd_filestat_set_times
(fd: fd, atim: timestamp, mtim: timestamp, fst_flags: fstflags) → Result<(), errno>
Adjust the timestamps of an open file or directory.
Note: This is similar to futimens
in POSIX.
fd
: fd
atim
: timestamp
The desired values of the data access timestamp.
mtim
: timestamp
The desired values of the data modification timestamp.
fst_flags
: fstflags
A bitmask indicating which timestamps to adjust.
err
: errno
fd_pread
(fd: fd, iovs: iovec_array, offset: filesize) → Result<size, errno>
Read from a file descriptor, without using and updating the file descriptor's offset.
Note: This is similar to preadv
in Linux (and other Unix-es).
fd
: fd
iovs
: iovec_array
List of scatter/gather vectors in which to store data.
offset
: filesize
The offset within the file at which to read.
fd_prestat_get
(fd: fd) → Result<prestat, errno>
Return a description of the given preopened file descriptor.
fd
: fd
fd_prestat_dir_name
(fd: fd, path: Pointer<u8>, path_len: size) → Result<(), errno>
Return a description of the given preopened file descriptor.
err
: errno
fd_pwrite
(fd: fd, iovs: ciovec_array, offset: filesize) → Result<size, errno>
Write to a file descriptor, without using and updating the file descriptor's offset.
Note: This is similar to pwritev
in Linux (and other Unix-es).
Like Linux (and other Unix-es), any calls of pwrite
(and other
functions to read or write) for a regular file by other threads in the
WASI process should not be interleaved while pwrite
is executed.
fd
: fd
iovs
: ciovec_array
List of scatter/gather vectors from which to retrieve data.
offset
: filesize
The offset within the file at which to write.
fd_read
(fd: fd, iovs: iovec_array) → Result<size, errno>
Read from a file descriptor.
Note: This is similar to readv
in POSIX.
fd
: fd
iovs
: iovec_array
List of scatter/gather vectors to which to store data.
fd_readdir
(fd: fd, buf: Pointer<u8>, buf_len: size, cookie: dircookie) → Result<size, errno>
Read directory entries from a directory.
When successful, the contents of the output buffer consist of a sequence of
directory entries. Each directory entry consists of a dirent
object,
followed by 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.
Entries for the special .
and ..
directory entries are included in the
sequence.
fd
: fd
buf
: Pointer<u8>
The buffer where directory entries are stored
buf_len
: size
cookie
: dircookie
The location within the directory to start reading
error
: Result<size, errno>
fd_renumber
(fd: fd, to: fd) → Result<(), errno>
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.
err
: errno
fd_seek
(fd: fd, offset: filedelta, whence: whence) → Result<filesize, errno>
Move the offset of a file descriptor.
Note: This is similar to lseek
in POSIX.
fd
: fd
offset
: filedelta
The number of bytes to move.
whence
: whence
The base from which the offset is relative.
error
: Result<filesize, errno>
fd_sync
(fd: fd) → Result<(), errno>
Synchronize the data and metadata of a file to disk.
Note: This is similar to fsync
in POSIX.
fd
: fd
err
: errno
fd_tell
(fd: fd) → Result<filesize, errno>
Return the current offset of a file descriptor.
Note: This is similar to lseek(fd, 0, SEEK_CUR)
in POSIX.
fd
: fd
error
: Result<filesize, errno>
fd_write
(fd: fd, iovs: ciovec_array) → Result<size, errno>
Write to a file descriptor.
Note: This is similar to writev
in POSIX.
Like POSIX, any calls of write
(and other functions to read or write)
for a regular file by other threads in the WASI process should not be
interleaved while write
is executed.
fd
: fd
iovs
: ciovec_array
List of scatter/gather vectors from which to retrieve data.
path_create_directory
(fd: fd, path: string) → Result<(), errno>
Create a directory.
Note: This is similar to mkdirat
in POSIX.
fd
: fd
err
: errno
path_filestat_get
(fd: fd, flags: lookupflags, path: string) → Result<filestat, errno>
Return the attributes of a file or directory.
Note: This is similar to stat
in POSIX.
fd
: fd
flags
: lookupflags
Flags determining the method of how the path is resolved.
path_filestat_set_times
(fd: fd, flags: lookupflags, path: string, atim: timestamp, mtim: timestamp, fst_flags: fstflags) → Result<(), errno>
Adjust the timestamps of a file or directory.
Note: This is similar to utimensat
in POSIX.
fd
: fd
flags
: lookupflags
Flags determining the method of how the path is resolved.
path
: string
The path of the file or directory to operate on.
atim
: timestamp
The desired values of the data access timestamp.
mtim
: timestamp
The desired values of the data modification timestamp.
fst_flags
: fstflags
A bitmask indicating which timestamps to adjust.
err
: errno
path_link
(old_fd: fd, old_flags: lookupflags, old_path: string, new_fd: fd, new_path: string) → Result<(), errno>
Create a hard link.
Note: This is similar to linkat
in POSIX.
old_fd
: fd
old_flags
: lookupflags
Flags determining the method of how the path is resolved.
new_fd
: fd
The working directory at which the resolution of the new path starts.
new_path
: string
The destination path at which to create the hard link.
err
: errno
path_open
(fd: fd, dirflags: lookupflags, path: string, oflags: oflags, fs_rights_base: rights, fs_rights_inheriting: rights, fdflags: fdflags) → Result<fd, errno>
Open a file or directory.
The returned file descriptor is not guaranteed to be the lowest-numbered
file descriptor not currently open; it is randomized to prevent
applications from depending on making assumptions about indexes, since this
is error-prone in multi-threaded contexts. The returned file descriptor is
guaranteed to be less than 2**31.
Note: This is similar to openat
in POSIX.
fd
: fd
dirflags
: lookupflags
Flags determining the method of how the path is resolved.
path
: string
The relative path of the file or directory to open, relative to the
path_open::fd
directory.
oflags
: oflags
The method by which to open the file.
fs_rights_base
: rights
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.
fs_rights_inheriting
: rights
fdflags
: fdflags
path_readlink
(fd: fd, path: string, buf: Pointer<u8>, buf_len: size) → Result<size, errno>
Read the contents of a symbolic link.
Note: This is similar to readlinkat
in POSIX. If buf
is not large
enough to contain the contents of the link, the first buf_len
bytes will be
be written to buf
.
fd
: fd
path
: string
The path of the symbolic link from which to read.
buf
: Pointer<u8>
The buffer to which to write the contents of the symbolic link.
buf_len
: size
path_remove_directory
(fd: fd, path: string) → Result<(), errno>
Remove a directory.
Return errno::notempty
if the directory is not empty.
Note: This is similar to unlinkat(fd, path, AT_REMOVEDIR)
in POSIX.
fd
: fd
err
: errno
path_rename
(fd: fd, old_path: string, new_fd: fd, new_path: string) → Result<(), errno>
Rename a file or directory.
Note: This is similar to renameat
in POSIX.
fd
: fd
old_path
: string
The source path of the file or directory to rename.
new_fd
: fd
The working directory at which the resolution of the new path starts.
new_path
: string
The destination path to which to rename the file or directory.
err
: errno
path_symlink
(old_path: string, fd: fd, new_path: string) → Result<(), errno>
Create a symbolic link.
Note: This is similar to symlinkat
in POSIX.
fd
: fd
new_path
: string
The destination path at which to create the symbolic link.
err
: errno
path_unlink_file
(fd: fd, path: string) → Result<(), errno>
Unlink a file.
Return errno::isdir
if the path refers to a directory.
Note: This is similar to unlinkat(fd, path, 0)
in POSIX.
fd
: fd
err
: errno
poll_oneoff
(in: ConstPointer<subscription>, out: Pointer<event>, nsubscriptions: size) → Result<size, errno>
Concurrently poll for the occurrence of a set of events.
If nsubscriptions
is 0, returns errno::inval
.
in
: ConstPointer<subscription>
The events to which to subscribe.
nsubscriptions
: size
Both the number of subscriptions and events.
proc_exit
(rval: exitcode)
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.
rval
: exitcode
proc_raise
(sig: signal) → Result<(), errno>
Send a signal to the process of the calling thread.
Note: This is similar to raise
in POSIX.
sig
: signal
err
: errno
sched_yield
() → Result<(), errno>
Temporarily yield execution of the calling thread.
Note: This is similar to sched_yield
in POSIX.
None
err
: errno
random_get
(buf: Pointer<u8>, buf_len: size) → Result<(), errno>
Write high-quality random data into a buffer.
This function blocks when the implementation is unable to immediately
provide sufficient high-quality random data.
This function may execute slowly, so when large mounts of random data are
required, it's advisable to use this function to seed a pseudo-random
number generator, rather than to provide the random data directly.
buf_len
: size
err
: errno
sock_accept
(fd: fd, flags: fdflags) → Result<fd, errno>
Accept a new incoming connection.
Note: This is similar to accept
in POSIX.
sock_recv
(fd: fd, ri_data: iovec_array, ri_flags: riflags) → Result<(size, roflags), errno>
Receive a message from a socket.
Note: This is similar to recv
in POSIX, though it also supports reading
the data into multiple buffers in the manner of readv
.
fd
: fd
ri_data
: iovec_array
List of scatter/gather vectors to which to store data.
ri_flags
: riflags
Message flags.
sock_send
(fd: fd, si_data: ciovec_array, si_flags: siflags) → Result<size, errno>
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
.
fd
: fd
si_data
: ciovec_array
List of scatter/gather vectors to which to retrieve data
si_flags
: siflags
Message flags.
sock_shutdown
(fd: fd, how: sdflags) → Result<(), errno>
Shut down socket send and receive channels.
Note: This is similar to shutdown
in POSIX.
err
: errno
See the complete reference here.
size
: u32
filesize
: u64
Non-negative file size or length of a region within a file.
timestamp
: u64
Timestamp in nanoseconds.
clockid
: Variant
Identifiers for clocks.
errno
: Variant
Error codes returned by functions.
Not all of these error codes are returned by the functions provided by this
API; some are used in higher-level library layers, and others are provided
merely for alignment with POSIX.
rights
: Record
File descriptor rights, determining which actions may be performed.
fd
: Handle
A file descriptor handle.
iovec
: Record
A region of memory for scatter/gather reads.
ciovec
: Record
A region of memory for scatter/gather writes.
iovec_array
: List<iovec>
ciovec_array
: List<ciovec>
filedelta
: s64
Relative offset within a file.
whence
: Variant
The position relative to which to set the offset of the file descriptor.
dircookie
: u64
A reference to the offset of a directory entry.
The value 0 signifies the start of the directory.
dirnamlen
: u32
The type for the dirent::d_namlen
field of dirent
struct.
inode
: u64
File serial number that is unique within its file system.
filetype
: Variant
The type of a file descriptor or file.
dirent
: Record
A directory entry.
advice
: Variant
File or memory access pattern advisory information.
fdflags
: Record
File descriptor flags.
fdstat
: Record
File descriptor attributes.
device
: u64
Identifier for a device containing a file system. Can be used in combination
with inode
to uniquely identify a file or directory in the filesystem.
fstflags
: Record
Which file time attributes to adjust.
lookupflags
: Record
Flags determining the method of how paths are resolved.
oflags
: Record
Open flags used by path_open
.
linkcount
: u64
Number of hard links to an inode.
filestat
: Record
File attributes.
userdata
: u64
User-provided value that may be attached to objects that is retained when
extracted from the implementation.
eventtype
: Variant
Type of a subscription to an event or its occurrence.
eventrwflags
: Record
The state of the file descriptor subscribed to with
eventtype::fd_read
or eventtype::fd_write
.
event_fd_readwrite
: Record
The contents of an event
when type is eventtype::fd_read
or
eventtype::fd_write
.
event
: Record
An event that occurred.
subclockflags
: Record
Flags determining how to interpret the timestamp provided in
subscription_clock::timeout
.
subscription_clock
: Record
The contents of a subscription
when type is eventtype::clock
.
subscription_fd_readwrite
: Record
The contents of a subscription
when type is type is
eventtype::fd_read
or eventtype::fd_write
.
subscription_u
: Variant
The contents of a subscription
.
subscription
: Record
Subscription to an event.
exitcode
: u32
Exit code generated by a process when exiting.
signal
: Variant
Signal condition.
riflags
: Record
Flags provided to sock_recv
.
roflags
: Record
Flags returned by sock_recv
.
siflags
: u16
Flags provided to sock_send
. As there are currently no flags
defined, it must be set to zero.
sdflags
: Record
Which channels on a socket to shut down.
preopentype
: Variant
Identifiers for preopened capabilities.
prestat_dir
: Record
The contents of a prestat
when type is preopentype::dir
.
prestat
: Variant
Information about a pre-opened capability.