2 * THIS FILE IS AUTO-GENERATED from the following files:
3 * wasi_snapshot_preview1.witx
5 * To regenerate this file execute:
7 * cargo run --manifest-path tools/wasi-headers/Cargo.toml generate-libc
9 * Modifications to this file will cause CI to fail, the code generator tool
10 * must be modified to change this file.
13 * This file describes the [WASI] interface, consisting of functions, types,
14 * and defined values (macros).
16 * The interface described here is greatly inspired by [CloudABI]'s clean,
17 * thoughtfully-designed, capability-oriented, POSIX-style API.
19 * [CloudABI]: https://github.com/NuxiNL/cloudlibc
20 * [WASI]: https://github.com/WebAssembly/WASI/
27 #error <wasi/api.h> is only supported on WASI platforms.
31 #error <wasi/api.h> only supports wasm32; doesn't yet support wasm64
37 _Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
38 _Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
39 _Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
40 _Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
41 _Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
42 _Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
43 _Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
44 _Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
45 _Static_assert(_Alignof(void*) == 4, "non-wasi data layout");
51 // TODO: Encoding this in witx.
52 #define __WASI_DIRCOOKIE_START (UINT64_C(0))
53 typedef __SIZE_TYPE__ __wasi_size_t;
55 _Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size");
56 _Static_assert(_Alignof(__wasi_size_t) == 4, "witx calculated align");
59 * Non-negative file size or length of a region within a file.
61 typedef uint64_t __wasi_filesize_t;
63 _Static_assert(sizeof(__wasi_filesize_t) == 8, "witx calculated size");
64 _Static_assert(_Alignof(__wasi_filesize_t) == 8, "witx calculated align");
67 * Timestamp in nanoseconds.
69 typedef uint64_t __wasi_timestamp_t;
71 _Static_assert(sizeof(__wasi_timestamp_t) == 8, "witx calculated size");
72 _Static_assert(_Alignof(__wasi_timestamp_t) == 8, "witx calculated align");
75 * Identifiers for clocks.
77 typedef uint32_t __wasi_clockid_t;
80 * The clock measuring real time. Time value zero corresponds with
81 * 1970-01-01T00:00:00Z.
83 #define __WASI_CLOCKID_REALTIME (UINT32_C(0))
86 * The store-wide monotonic clock, which is defined as a clock measuring
87 * real time, whose value cannot be adjusted and which cannot have negative
88 * clock jumps. The epoch of this clock is undefined. The absolute time
89 * value of this clock therefore has no meaning.
91 #define __WASI_CLOCKID_MONOTONIC (UINT32_C(1))
94 * The CPU-time clock associated with the current process.
96 #define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2))
99 * The CPU-time clock associated with the current thread.
101 #define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3))
103 _Static_assert(sizeof(__wasi_clockid_t) == 4, "witx calculated size");
104 _Static_assert(_Alignof(__wasi_clockid_t) == 4, "witx calculated align");
107 * Error codes returned by functions.
108 * Not all of these error codes are returned by the functions provided by this
109 * API; some are used in higher-level library layers, and others are provided
110 * merely for alignment with POSIX.
112 typedef uint16_t __wasi_errno_t;
115 * No error occurred. System call completed successfully.
117 #define __WASI_ERRNO_SUCCESS (UINT16_C(0))
120 * Argument list too long.
122 #define __WASI_ERRNO_2BIG (UINT16_C(1))
127 #define __WASI_ERRNO_ACCES (UINT16_C(2))
132 #define __WASI_ERRNO_ADDRINUSE (UINT16_C(3))
135 * Address not available.
137 #define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4))
140 * Address family not supported.
142 #define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5))
145 * Resource unavailable, or operation would block.
147 #define __WASI_ERRNO_AGAIN (UINT16_C(6))
150 * Connection already in progress.
152 #define __WASI_ERRNO_ALREADY (UINT16_C(7))
155 * Bad file descriptor.
157 #define __WASI_ERRNO_BADF (UINT16_C(8))
162 #define __WASI_ERRNO_BADMSG (UINT16_C(9))
165 * Device or resource busy.
167 #define __WASI_ERRNO_BUSY (UINT16_C(10))
170 * Operation canceled.
172 #define __WASI_ERRNO_CANCELED (UINT16_C(11))
175 * No child processes.
177 #define __WASI_ERRNO_CHILD (UINT16_C(12))
180 * Connection aborted.
182 #define __WASI_ERRNO_CONNABORTED (UINT16_C(13))
185 * Connection refused.
187 #define __WASI_ERRNO_CONNREFUSED (UINT16_C(14))
192 #define __WASI_ERRNO_CONNRESET (UINT16_C(15))
195 * Resource deadlock would occur.
197 #define __WASI_ERRNO_DEADLK (UINT16_C(16))
200 * Destination address required.
202 #define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17))
205 * Mathematics argument out of domain of function.
207 #define __WASI_ERRNO_DOM (UINT16_C(18))
212 #define __WASI_ERRNO_DQUOT (UINT16_C(19))
217 #define __WASI_ERRNO_EXIST (UINT16_C(20))
222 #define __WASI_ERRNO_FAULT (UINT16_C(21))
227 #define __WASI_ERRNO_FBIG (UINT16_C(22))
230 * Host is unreachable.
232 #define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23))
235 * Identifier removed.
237 #define __WASI_ERRNO_IDRM (UINT16_C(24))
240 * Illegal byte sequence.
242 #define __WASI_ERRNO_ILSEQ (UINT16_C(25))
245 * Operation in progress.
247 #define __WASI_ERRNO_INPROGRESS (UINT16_C(26))
250 * Interrupted function.
252 #define __WASI_ERRNO_INTR (UINT16_C(27))
257 #define __WASI_ERRNO_INVAL (UINT16_C(28))
262 #define __WASI_ERRNO_IO (UINT16_C(29))
265 * Socket is connected.
267 #define __WASI_ERRNO_ISCONN (UINT16_C(30))
272 #define __WASI_ERRNO_ISDIR (UINT16_C(31))
275 * Too many levels of symbolic links.
277 #define __WASI_ERRNO_LOOP (UINT16_C(32))
280 * File descriptor value too large.
282 #define __WASI_ERRNO_MFILE (UINT16_C(33))
287 #define __WASI_ERRNO_MLINK (UINT16_C(34))
292 #define __WASI_ERRNO_MSGSIZE (UINT16_C(35))
297 #define __WASI_ERRNO_MULTIHOP (UINT16_C(36))
302 #define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37))
307 #define __WASI_ERRNO_NETDOWN (UINT16_C(38))
310 * Connection aborted by network.
312 #define __WASI_ERRNO_NETRESET (UINT16_C(39))
315 * Network unreachable.
317 #define __WASI_ERRNO_NETUNREACH (UINT16_C(40))
320 * Too many files open in system.
322 #define __WASI_ERRNO_NFILE (UINT16_C(41))
325 * No buffer space available.
327 #define __WASI_ERRNO_NOBUFS (UINT16_C(42))
332 #define __WASI_ERRNO_NODEV (UINT16_C(43))
335 * No such file or directory.
337 #define __WASI_ERRNO_NOENT (UINT16_C(44))
340 * Executable file format error.
342 #define __WASI_ERRNO_NOEXEC (UINT16_C(45))
345 * No locks available.
347 #define __WASI_ERRNO_NOLCK (UINT16_C(46))
352 #define __WASI_ERRNO_NOLINK (UINT16_C(47))
357 #define __WASI_ERRNO_NOMEM (UINT16_C(48))
360 * No message of the desired type.
362 #define __WASI_ERRNO_NOMSG (UINT16_C(49))
365 * Protocol not available.
367 #define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50))
370 * No space left on device.
372 #define __WASI_ERRNO_NOSPC (UINT16_C(51))
375 * Function not supported.
377 #define __WASI_ERRNO_NOSYS (UINT16_C(52))
380 * The socket is not connected.
382 #define __WASI_ERRNO_NOTCONN (UINT16_C(53))
385 * Not a directory or a symbolic link to a directory.
387 #define __WASI_ERRNO_NOTDIR (UINT16_C(54))
390 * Directory not empty.
392 #define __WASI_ERRNO_NOTEMPTY (UINT16_C(55))
395 * State not recoverable.
397 #define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56))
402 #define __WASI_ERRNO_NOTSOCK (UINT16_C(57))
405 * Not supported, or operation not supported on socket.
407 #define __WASI_ERRNO_NOTSUP (UINT16_C(58))
410 * Inappropriate I/O control operation.
412 #define __WASI_ERRNO_NOTTY (UINT16_C(59))
415 * No such device or address.
417 #define __WASI_ERRNO_NXIO (UINT16_C(60))
420 * Value too large to be stored in data type.
422 #define __WASI_ERRNO_OVERFLOW (UINT16_C(61))
425 * Previous owner died.
427 #define __WASI_ERRNO_OWNERDEAD (UINT16_C(62))
430 * Operation not permitted.
432 #define __WASI_ERRNO_PERM (UINT16_C(63))
437 #define __WASI_ERRNO_PIPE (UINT16_C(64))
442 #define __WASI_ERRNO_PROTO (UINT16_C(65))
445 * Protocol not supported.
447 #define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66))
450 * Protocol wrong type for socket.
452 #define __WASI_ERRNO_PROTOTYPE (UINT16_C(67))
457 #define __WASI_ERRNO_RANGE (UINT16_C(68))
460 * Read-only file system.
462 #define __WASI_ERRNO_ROFS (UINT16_C(69))
467 #define __WASI_ERRNO_SPIPE (UINT16_C(70))
472 #define __WASI_ERRNO_SRCH (UINT16_C(71))
477 #define __WASI_ERRNO_STALE (UINT16_C(72))
480 * Connection timed out.
482 #define __WASI_ERRNO_TIMEDOUT (UINT16_C(73))
487 #define __WASI_ERRNO_TXTBSY (UINT16_C(74))
492 #define __WASI_ERRNO_XDEV (UINT16_C(75))
495 * Extension: Capabilities insufficient.
497 #define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76))
499 _Static_assert(sizeof(__wasi_errno_t) == 2, "witx calculated size");
500 _Static_assert(_Alignof(__wasi_errno_t) == 2, "witx calculated align");
503 * File descriptor rights, determining which actions may be performed.
505 typedef uint64_t __wasi_rights_t;
508 * The right to invoke `fd_datasync`.
509 * If `path_open` is set, includes the right to invoke
510 * `path_open` with `fdflags::dsync`.
512 #define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0))
515 * The right to invoke `fd_read` and `sock_recv`.
516 * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
518 #define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1))
521 * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
523 #define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2))
526 * The right to invoke `fd_fdstat_set_flags`.
528 #define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3))
531 * The right to invoke `fd_sync`.
532 * If `path_open` is set, includes the right to invoke
533 * `path_open` with `fdflags::rsync` and `fdflags::dsync`.
535 #define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4))
538 * The right to invoke `fd_seek` in such a way that the file offset
539 * remains unaltered (i.e., `whence::cur` with offset zero), or to
542 #define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5))
545 * The right to invoke `fd_write` and `sock_send`.
546 * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
548 #define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6))
551 * The right to invoke `fd_advise`.
553 #define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7))
556 * The right to invoke `fd_allocate`.
558 #define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8))
561 * The right to invoke `path_create_directory`.
563 #define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9))
566 * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
568 #define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10))
571 * The right to invoke `path_link` with the file descriptor as the
574 #define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11))
577 * The right to invoke `path_link` with the file descriptor as the
580 #define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12))
583 * The right to invoke `path_open`.
585 #define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13))
588 * The right to invoke `fd_readdir`.
590 #define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14))
593 * The right to invoke `path_readlink`.
595 #define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15))
598 * The right to invoke `path_rename` with the file descriptor as the source directory.
600 #define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16))
603 * The right to invoke `path_rename` with the file descriptor as the target directory.
605 #define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17))
608 * The right to invoke `path_filestat_get`.
610 #define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18))
613 * The right to change a file's size (there is no `path_filestat_set_size`).
614 * If `path_open` is set
, includes the right to invoke `path_open` with `
oflags::trunc`
.
616 #define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19))
619 * The right to invoke `path_filestat_set_times`.
621 #define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20))
624 * The right to invoke `fd_filestat_get`.
626 #define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21))
629 * The right to invoke `fd_filestat_set_size`.
631 #define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22))
634 * The right to invoke `fd_filestat_set_times`.
636 #define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23))
639 * The right to invoke `path_symlink`.
641 #define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24))
644 * The right to invoke `path_remove_directory`.
646 #define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25))
649 * The right to invoke `path_unlink_file`.
651 #define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26))
654 * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
655 * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
657 #define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27))
660 * The right to invoke `sock_shutdown`.
662 #define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28))
665 * A file descriptor handle.
667 typedef int __wasi_fd_t
;
669 _Static_assert(sizeof(__wasi_fd_t
) == 4, "witx calculated size");
670 _Static_assert(_Alignof(__wasi_fd_t
) == 4, "witx calculated align");
673 * A region of memory for scatter/gather reads.
675 typedef struct __wasi_iovec_t
{
677 * The address of the buffer to be filled.
682 * The length of the buffer to be filled.
684 __wasi_size_t buf_len
;
688 _Static_assert(sizeof(__wasi_iovec_t
) == 8, "witx calculated size");
689 _Static_assert(_Alignof(__wasi_iovec_t
) == 4, "witx calculated align");
690 _Static_assert(offsetof(__wasi_iovec_t
, buf
) == 0, "witx calculated offset");
691 _Static_assert(offsetof(__wasi_iovec_t
, buf_len
) == 4, "witx calculated offset");
694 * A region of memory for scatter/gather writes.
696 typedef struct __wasi_ciovec_t
{
698 * The address of the buffer to be written.
703 * The length of the buffer to be written.
705 __wasi_size_t buf_len
;
709 _Static_assert(sizeof(__wasi_ciovec_t
) == 8, "witx calculated size");
710 _Static_assert(_Alignof(__wasi_ciovec_t
) == 4, "witx calculated align");
711 _Static_assert(offsetof(__wasi_ciovec_t
, buf
) == 0, "witx calculated offset");
712 _Static_assert(offsetof(__wasi_ciovec_t
, buf_len
) == 4, "witx calculated offset");
715 * Relative offset within a file.
717 typedef int64_t __wasi_filedelta_t
;
719 _Static_assert(sizeof(__wasi_filedelta_t
) == 8, "witx calculated size");
720 _Static_assert(_Alignof(__wasi_filedelta_t
) == 8, "witx calculated align");
723 * The position relative to which to set the offset of the file descriptor.
725 typedef uint8_t __wasi_whence_t
;
728 * Seek relative to start-of-file.
730 #define __WASI_WHENCE_SET (UINT8_C(0))
733 * Seek relative to current position.
735 #define __WASI_WHENCE_CUR (UINT8_C(1))
738 * Seek relative to end-of-file.
740 #define __WASI_WHENCE_END (UINT8_C(2))
742 _Static_assert(sizeof(__wasi_whence_t
) == 1, "witx calculated size");
743 _Static_assert(_Alignof(__wasi_whence_t
) == 1, "witx calculated align");
746 * A reference to the offset of a directory entry.
748 * The value 0 signifies the start of the directory.
750 typedef uint64_t __wasi_dircookie_t
;
752 _Static_assert(sizeof(__wasi_dircookie_t
) == 8, "witx calculated size");
753 _Static_assert(_Alignof(__wasi_dircookie_t
) == 8, "witx calculated align");
756 * The type for the `dirent::d_namlen` field of `dirent` struct.
758 typedef uint32_t __wasi_dirnamlen_t
;
760 _Static_assert(sizeof(__wasi_dirnamlen_t
) == 4, "witx calculated size");
761 _Static_assert(_Alignof(__wasi_dirnamlen_t
) == 4, "witx calculated align");
764 * File serial number that is unique within its file system.
766 typedef uint64_t __wasi_inode_t
;
768 _Static_assert(sizeof(__wasi_inode_t
) == 8, "witx calculated size");
769 _Static_assert(_Alignof(__wasi_inode_t
) == 8, "witx calculated align");
772 * The type of a file descriptor or file.
774 typedef uint8_t __wasi_filetype_t
;
777 * The type of the file descriptor or file is unknown or is different from any of the other types specified.
779 #define __WASI_FILETYPE_UNKNOWN (UINT8_C(0))
782 * The file descriptor or file refers to a block device inode.
784 #define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1))
787 * The file descriptor or file refers to a character device inode.
789 #define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2))
792 * The file descriptor or file refers to a directory inode.
794 #define __WASI_FILETYPE_DIRECTORY (UINT8_C(3))
797 * The file descriptor or file refers to a regular file inode.
799 #define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4))
802 * The file descriptor or file refers to a datagram socket.
804 #define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5))
807 * The file descriptor or file refers to a byte-stream socket.
809 #define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6))
812 * The file refers to a symbolic link inode.
814 #define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7))
816 _Static_assert(sizeof(__wasi_filetype_t
) == 1, "witx calculated size");
817 _Static_assert(_Alignof(__wasi_filetype_t
) == 1, "witx calculated align");
822 typedef struct __wasi_dirent_t
{
824 * The offset of the next directory entry stored in this directory.
826 __wasi_dircookie_t d_next
;
829 * The serial number of the file referred to by this directory entry.
831 __wasi_inode_t d_ino
;
834 * The length of the name of the directory entry.
836 __wasi_dirnamlen_t d_namlen
;
839 * The type of the file referred to by this directory entry.
841 __wasi_filetype_t d_type
;
845 _Static_assert(sizeof(__wasi_dirent_t
) == 24, "witx calculated size");
846 _Static_assert(_Alignof(__wasi_dirent_t
) == 8, "witx calculated align");
847 _Static_assert(offsetof(__wasi_dirent_t
, d_next
) == 0, "witx calculated offset");
848 _Static_assert(offsetof(__wasi_dirent_t
, d_ino
) == 8, "witx calculated offset");
849 _Static_assert(offsetof(__wasi_dirent_t
, d_namlen
) == 16, "witx calculated offset");
850 _Static_assert(offsetof(__wasi_dirent_t
, d_type
) == 20, "witx calculated offset");
853 * File or memory access pattern advisory information.
855 typedef uint8_t __wasi_advice_t
;
858 * The application has no advice to give on its behavior with respect to the specified data.
860 #define __WASI_ADVICE_NORMAL (UINT8_C(0))
863 * The application expects to access the specified data sequentially from lower offsets to higher offsets.
865 #define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1))
868 * The application expects to access the specified data in a random order.
870 #define __WASI_ADVICE_RANDOM (UINT8_C(2))
873 * The application expects to access the specified data in the near future.
875 #define __WASI_ADVICE_WILLNEED (UINT8_C(3))
878 * The application expects that it will not access the specified data in the near future.
880 #define __WASI_ADVICE_DONTNEED (UINT8_C(4))
883 * The application expects to access the specified data once and then not reuse it thereafter.
885 #define __WASI_ADVICE_NOREUSE (UINT8_C(5))
887 _Static_assert(sizeof(__wasi_advice_t
) == 1, "witx calculated size");
888 _Static_assert(_Alignof(__wasi_advice_t
) == 1, "witx calculated align");
891 * File descriptor flags.
893 typedef uint16_t __wasi_fdflags_t
;
896 * Append mode: Data written to the file is always appended to the file's end.
898 #define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)(1 << 0))
901 * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
903 #define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1))
908 #define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2))
911 * Synchronized read I/O operations.
913 #define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3))
916 * Write according to synchronized I/O file integrity completion. In
917 * addition to synchronizing the data stored in the file, the implementation
918 * may also synchronously update the file's metadata.
920 #define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4))
923 * File descriptor attributes.
925 typedef struct __wasi_fdstat_t
{
929 __wasi_filetype_t fs_filetype
;
932 * File descriptor flags.
934 __wasi_fdflags_t fs_flags
;
937 * Rights that apply to this file descriptor.
939 __wasi_rights_t fs_rights_base
;
942 * Maximum set of rights that may be installed on new file descriptors that
943 * are created through this file descriptor, e.g., through `path_open`.
945 __wasi_rights_t fs_rights_inheriting
;
949 _Static_assert(sizeof(__wasi_fdstat_t
) == 24, "witx calculated size");
950 _Static_assert(_Alignof(__wasi_fdstat_t
) == 8, "witx calculated align");
951 _Static_assert(offsetof(__wasi_fdstat_t
, fs_filetype
) == 0, "witx calculated offset");
952 _Static_assert(offsetof(__wasi_fdstat_t
, fs_flags
) == 2, "witx calculated offset");
953 _Static_assert(offsetof(__wasi_fdstat_t
, fs_rights_base
) == 8, "witx calculated offset");
954 _Static_assert(offsetof(__wasi_fdstat_t
, fs_rights_inheriting
) == 16, "witx calculated offset");
957 * Identifier for a device containing a file system. Can be used in combination
958 * with `inode` to uniquely identify a file or directory in the filesystem.
960 typedef uint64_t __wasi_device_t
;
962 _Static_assert(sizeof(__wasi_device_t
) == 8, "witx calculated size");
963 _Static_assert(_Alignof(__wasi_device_t
) == 8, "witx calculated align");
966 * Which file time attributes to adjust.
968 typedef uint16_t __wasi_fstflags_t
;
971 * Adjust the last data access timestamp to the value stored in `filestat::atim`.
973 #define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0))
976 * Adjust the last data access timestamp to the time of clock `clockid::realtime`.
978 #define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1))
981 * Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
983 #define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2))
986 * Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
988 #define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3))
991 * Flags determining the method of how paths are resolved.
993 typedef uint32_t __wasi_lookupflags_t
;
996 * As long as the resolved path corresponds to a symbolic link, it is expanded.
998 #define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0))
1001 * Open flags used by `path_open`.
1003 typedef uint16_t __wasi_oflags_t
;
1006 * Create file if it does not exist.
1008 #define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0))
1011 * Fail if not a directory.
1013 #define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1))
1016 * Fail if file already exists.
1018 #define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2))
1021 * Truncate file to size 0.
1023 #define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3))
1026 * Number of hard links to an inode.
1028 typedef uint64_t __wasi_linkcount_t
;
1030 _Static_assert(sizeof(__wasi_linkcount_t
) == 8, "witx calculated size");
1031 _Static_assert(_Alignof(__wasi_linkcount_t
) == 8, "witx calculated align");
1036 typedef struct __wasi_filestat_t
{
1038 * Device ID of device containing the file.
1040 __wasi_device_t dev
;
1043 * File serial number.
1050 __wasi_filetype_t filetype
;
1053 * Number of hard links to the file.
1055 __wasi_linkcount_t nlink
;
1058 * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
1060 __wasi_filesize_t size
;
1063 * Last data access timestamp.
1065 __wasi_timestamp_t atim
;
1068 * Last data modification timestamp.
1070 __wasi_timestamp_t mtim
;
1073 * Last file status change timestamp.
1075 __wasi_timestamp_t ctim
;
1077 } __wasi_filestat_t
;
1079 _Static_assert(sizeof(__wasi_filestat_t
) == 64, "witx calculated size");
1080 _Static_assert(_Alignof(__wasi_filestat_t
) == 8, "witx calculated align");
1081 _Static_assert(offsetof(__wasi_filestat_t
, dev
) == 0, "witx calculated offset");
1082 _Static_assert(offsetof(__wasi_filestat_t
, ino
) == 8, "witx calculated offset");
1083 _Static_assert(offsetof(__wasi_filestat_t
, filetype
) == 16, "witx calculated offset");
1084 _Static_assert(offsetof(__wasi_filestat_t
, nlink
) == 24, "witx calculated offset");
1085 _Static_assert(offsetof(__wasi_filestat_t
, size
) == 32, "witx calculated offset");
1086 _Static_assert(offsetof(__wasi_filestat_t
, atim
) == 40, "witx calculated offset");
1087 _Static_assert(offsetof(__wasi_filestat_t
, mtim
) == 48, "witx calculated offset");
1088 _Static_assert(offsetof(__wasi_filestat_t
, ctim
) == 56, "witx calculated offset");
1091 * User-provided value that may be attached to objects that is retained when
1092 * extracted from the implementation.
1094 typedef uint64_t __wasi_userdata_t
;
1096 _Static_assert(sizeof(__wasi_userdata_t
) == 8, "witx calculated size");
1097 _Static_assert(_Alignof(__wasi_userdata_t
) == 8, "witx calculated align");
1100 * Type of a subscription to an event or its occurrence.
1102 typedef uint8_t __wasi_eventtype_t
;
1105 * The time value of clock `subscription_clock::id` has
1106 * reached timestamp `subscription_clock::timeout`.
1108 #define __WASI_EVENTTYPE_CLOCK (UINT8_C(0))
1111 * File descriptor `subscription_fd_readwrite::file_descriptor` has data
1112 * available for reading. This event always triggers for regular files.
1114 #define __WASI_EVENTTYPE_FD_READ (UINT8_C(1))
1117 * File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
1118 * available for writing. This event always triggers for regular files.
1120 #define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2))
1122 _Static_assert(sizeof(__wasi_eventtype_t
) == 1, "witx calculated size");
1123 _Static_assert(_Alignof(__wasi_eventtype_t
) == 1, "witx calculated align");
1126 * The state of the file descriptor subscribed to with
1127 * `eventtype::fd_read` or `eventtype::fd_write`.
1129 typedef uint16_t __wasi_eventrwflags_t
;
1132 * The peer of this socket has closed or disconnected.
1134 #define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)(1 << 0))
1137 * The contents of an `event` when type is `eventtype::fd_read` or
1138 * `eventtype::fd_write`.
1140 typedef struct __wasi_event_fd_readwrite_t
{
1142 * The number of bytes available for reading or writing.
1144 __wasi_filesize_t nbytes
;
1147 * The state of the file descriptor.
1149 __wasi_eventrwflags_t flags
;
1151 } __wasi_event_fd_readwrite_t
;
1153 _Static_assert(sizeof(__wasi_event_fd_readwrite_t
) == 16, "witx calculated size");
1154 _Static_assert(_Alignof(__wasi_event_fd_readwrite_t
) == 8, "witx calculated align");
1155 _Static_assert(offsetof(__wasi_event_fd_readwrite_t
, nbytes
) == 0, "witx calculated offset");
1156 _Static_assert(offsetof(__wasi_event_fd_readwrite_t
, flags
) == 8, "witx calculated offset");
1159 * An event that occurred.
1161 typedef struct __wasi_event_t
{
1163 * User-provided value that got attached to `subscription::userdata`.
1165 __wasi_userdata_t userdata
;
1168 * If non-zero, an error that occurred while processing the subscription request.
1170 __wasi_errno_t error
;
1173 * The type of event that occured
1175 __wasi_eventtype_t type
;
1178 * The contents of the event, if it is an `eventtype::fd_read` or
1179 * `eventtype::fd_write`. `eventtype::clock` events ignore this field.
1181 __wasi_event_fd_readwrite_t fd_readwrite
;
1185 _Static_assert(sizeof(__wasi_event_t
) == 32, "witx calculated size");
1186 _Static_assert(_Alignof(__wasi_event_t
) == 8, "witx calculated align");
1187 _Static_assert(offsetof(__wasi_event_t
, userdata
) == 0, "witx calculated offset");
1188 _Static_assert(offsetof(__wasi_event_t
, error
) == 8, "witx calculated offset");
1189 _Static_assert(offsetof(__wasi_event_t
, type
) == 10, "witx calculated offset");
1190 _Static_assert(offsetof(__wasi_event_t
, fd_readwrite
) == 16, "witx calculated offset");
1193 * Flags determining how to interpret the timestamp provided in
1194 * `subscription_clock::timeout`.
1196 typedef uint16_t __wasi_subclockflags_t
;
1199 * If set, treat the timestamp provided in
1200 * `subscription_clock::timeout` as an absolute timestamp of clock
1201 * `subscription_clock::id`. If clear, treat the timestamp
1202 * provided in `subscription_clock::timeout` relative to the
1203 * current time value of clock `subscription_clock::id`.
1205 #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0))
1208 * The contents of a `subscription` when type is `eventtype::clock`.
1210 typedef struct __wasi_subscription_clock_t
{
1212 * The clock against which to compare the timestamp.
1214 __wasi_clockid_t id
;
1217 * The absolute or relative timestamp.
1219 __wasi_timestamp_t timeout
;
1222 * The amount of time that the implementation may wait additionally
1223 * to coalesce with other events.
1225 __wasi_timestamp_t precision
;
1228 * Flags specifying whether the timeout is absolute or relative
1230 __wasi_subclockflags_t flags
;
1232 } __wasi_subscription_clock_t
;
1234 _Static_assert(sizeof(__wasi_subscription_clock_t
) == 32, "witx calculated size");
1235 _Static_assert(_Alignof(__wasi_subscription_clock_t
) == 8, "witx calculated align");
1236 _Static_assert(offsetof(__wasi_subscription_clock_t
, id
) == 0, "witx calculated offset");
1237 _Static_assert(offsetof(__wasi_subscription_clock_t
, timeout
) == 8, "witx calculated offset");
1238 _Static_assert(offsetof(__wasi_subscription_clock_t
, precision
) == 16, "witx calculated offset");
1239 _Static_assert(offsetof(__wasi_subscription_clock_t
, flags
) == 24, "witx calculated offset");
1242 * The contents of a `subscription` when type is type is
1243 * `eventtype::fd_read` or `eventtype::fd_write`.
1245 typedef struct __wasi_subscription_fd_readwrite_t
{
1247 * The file descriptor on which to wait for it to become ready for reading or writing.
1249 __wasi_fd_t file_descriptor
;
1251 } __wasi_subscription_fd_readwrite_t
;
1253 _Static_assert(sizeof(__wasi_subscription_fd_readwrite_t
) == 4, "witx calculated size");
1254 _Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t
) == 4, "witx calculated align");
1255 _Static_assert(offsetof(__wasi_subscription_fd_readwrite_t
, file_descriptor
) == 0, "witx calculated offset");
1258 * The contents of a `subscription`.
1260 typedef union __wasi_subscription_u_u_t
{
1261 __wasi_subscription_clock_t clock
;
1262 __wasi_subscription_fd_readwrite_t fd_read
;
1263 __wasi_subscription_fd_readwrite_t fd_write
;
1264 } __wasi_subscription_u_u_t
;
1265 typedef struct __wasi_subscription_u_t
{
1267 __wasi_subscription_u_u_t u
;
1268 } __wasi_subscription_u_t
;
1270 _Static_assert(sizeof(__wasi_subscription_u_t
) == 40, "witx calculated size");
1271 _Static_assert(_Alignof(__wasi_subscription_u_t
) == 8, "witx calculated align");
1274 * Subscription to an event.
1276 typedef struct __wasi_subscription_t
{
1278 * User-provided value that is attached to the subscription in the
1279 * implementation and returned through `event::userdata`.
1281 __wasi_userdata_t userdata
;
1284 * The type of the event to which to subscribe, and its contents
1286 __wasi_subscription_u_t u
;
1288 } __wasi_subscription_t
;
1290 _Static_assert(sizeof(__wasi_subscription_t
) == 48, "witx calculated size");
1291 _Static_assert(_Alignof(__wasi_subscription_t
) == 8, "witx calculated align");
1292 _Static_assert(offsetof(__wasi_subscription_t
, userdata
) == 0, "witx calculated offset");
1293 _Static_assert(offsetof(__wasi_subscription_t
, u
) == 8, "witx calculated offset");
1296 * Exit code generated by a process when exiting.
1298 typedef uint32_t __wasi_exitcode_t
;
1300 _Static_assert(sizeof(__wasi_exitcode_t
) == 4, "witx calculated size");
1301 _Static_assert(_Alignof(__wasi_exitcode_t
) == 4, "witx calculated align");
1306 typedef uint8_t __wasi_signal_t
;
1309 * No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
1310 * so this value is reserved.
1312 #define __WASI_SIGNAL_NONE (UINT8_C(0))
1316 * Action: Terminates the process.
1318 #define __WASI_SIGNAL_HUP (UINT8_C(1))
1321 * Terminate interrupt signal.
1322 * Action: Terminates the process.
1324 #define __WASI_SIGNAL_INT (UINT8_C(2))
1327 * Terminal quit signal.
1328 * Action: Terminates the process.
1330 #define __WASI_SIGNAL_QUIT (UINT8_C(3))
1333 * Illegal instruction.
1334 * Action: Terminates the process.
1336 #define __WASI_SIGNAL_ILL (UINT8_C(4))
1339 * Trace/breakpoint trap.
1340 * Action: Terminates the process.
1342 #define __WASI_SIGNAL_TRAP (UINT8_C(5))
1345 * Process abort signal.
1346 * Action: Terminates the process.
1348 #define __WASI_SIGNAL_ABRT (UINT8_C(6))
1351 * Access to an undefined portion of a memory object.
1352 * Action: Terminates the process.
1354 #define __WASI_SIGNAL_BUS (UINT8_C(7))
1357 * Erroneous arithmetic operation.
1358 * Action: Terminates the process.
1360 #define __WASI_SIGNAL_FPE (UINT8_C(8))
1364 * Action: Terminates the process.
1366 #define __WASI_SIGNAL_KILL (UINT8_C(9))
1369 * User-defined signal 1.
1370 * Action: Terminates the process.
1372 #define __WASI_SIGNAL_USR1 (UINT8_C(10))
1375 * Invalid memory reference.
1376 * Action: Terminates the process.
1378 #define __WASI_SIGNAL_SEGV (UINT8_C(11))
1381 * User-defined signal 2.
1382 * Action: Terminates the process.
1384 #define __WASI_SIGNAL_USR2 (UINT8_C(12))
1387 * Write on a pipe with no one to read it.
1390 #define __WASI_SIGNAL_PIPE (UINT8_C(13))
1394 * Action: Terminates the process.
1396 #define __WASI_SIGNAL_ALRM (UINT8_C(14))
1399 * Termination signal.
1400 * Action: Terminates the process.
1402 #define __WASI_SIGNAL_TERM (UINT8_C(15))
1405 * Child process terminated, stopped, or continued.
1408 #define __WASI_SIGNAL_CHLD (UINT8_C(16))
1411 * Continue executing, if stopped.
1412 * Action: Continues executing, if stopped.
1414 #define __WASI_SIGNAL_CONT (UINT8_C(17))
1418 * Action: Stops executing.
1420 #define __WASI_SIGNAL_STOP (UINT8_C(18))
1423 * Terminal stop signal.
1424 * Action: Stops executing.
1426 #define __WASI_SIGNAL_TSTP (UINT8_C(19))
1429 * Background process attempting read.
1430 * Action: Stops executing.
1432 #define __WASI_SIGNAL_TTIN (UINT8_C(20))
1435 * Background process attempting write.
1436 * Action: Stops executing.
1438 #define __WASI_SIGNAL_TTOU (UINT8_C(21))
1441 * High bandwidth data is available at a socket.
1444 #define __WASI_SIGNAL_URG (UINT8_C(22))
1447 * CPU time limit exceeded.
1448 * Action: Terminates the process.
1450 #define __WASI_SIGNAL_XCPU (UINT8_C(23))
1453 * File size limit exceeded.
1454 * Action: Terminates the process.
1456 #define __WASI_SIGNAL_XFSZ (UINT8_C(24))
1459 * Virtual timer expired.
1460 * Action: Terminates the process.
1462 #define __WASI_SIGNAL_VTALRM (UINT8_C(25))
1465 * Profiling timer expired.
1466 * Action: Terminates the process.
1468 #define __WASI_SIGNAL_PROF (UINT8_C(26))
1474 #define __WASI_SIGNAL_WINCH (UINT8_C(27))
1478 * Action: Terminates the process.
1480 #define __WASI_SIGNAL_POLL (UINT8_C(28))
1484 * Action: Terminates the process.
1486 #define __WASI_SIGNAL_PWR (UINT8_C(29))
1490 * Action: Terminates the process.
1492 #define __WASI_SIGNAL_SYS (UINT8_C(30))
1494 _Static_assert(sizeof(__wasi_signal_t
) == 1, "witx calculated size");
1495 _Static_assert(_Alignof(__wasi_signal_t
) == 1, "witx calculated align");
1498 * Flags provided to `sock_recv`.
1500 typedef uint16_t __wasi_riflags_t
;
1503 * Returns the message without removing it from the socket's receive queue.
1505 #define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)(1 << 0))
1508 * On byte-stream sockets, block until the full amount of data can be returned.
1510 #define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1))
1513 * Flags returned by `sock_recv`.
1515 typedef uint16_t __wasi_roflags_t
;
1518 * Returned by `sock_recv`: Message data has been truncated.
1520 #define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)(1 << 0))
1523 * Flags provided to `sock_send`. As there are currently no flags
1524 * defined, it must be set to zero.
1526 typedef uint16_t __wasi_siflags_t
;
1528 _Static_assert(sizeof(__wasi_siflags_t
) == 2, "witx calculated size");
1529 _Static_assert(_Alignof(__wasi_siflags_t
) == 2, "witx calculated align");
1532 * Which channels on a socket to shut down.
1534 typedef uint8_t __wasi_sdflags_t
;
1537 * Disables further receive operations.
1539 #define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0))
1542 * Disables further send operations.
1544 #define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1))
1547 * Identifiers for preopened capabilities.
1549 typedef uint8_t __wasi_preopentype_t
;
1552 * A pre-opened directory.
1554 #define __WASI_PREOPENTYPE_DIR (UINT8_C(0))
1556 _Static_assert(sizeof(__wasi_preopentype_t
) == 1, "witx calculated size");
1557 _Static_assert(_Alignof(__wasi_preopentype_t
) == 1, "witx calculated align");
1560 * The contents of a $prestat when type is `preopentype::dir`.
1562 typedef struct __wasi_prestat_dir_t
{
1564 * The length of the directory name for use with `fd_prestat_dir_name`.
1566 __wasi_size_t pr_name_len
;
1568 } __wasi_prestat_dir_t
;
1570 _Static_assert(sizeof(__wasi_prestat_dir_t
) == 4, "witx calculated size");
1571 _Static_assert(_Alignof(__wasi_prestat_dir_t
) == 4, "witx calculated align");
1572 _Static_assert(offsetof(__wasi_prestat_dir_t
, pr_name_len
) == 0, "witx calculated offset");
1575 * Information about a pre-opened capability.
1577 typedef union __wasi_prestat_u_t
{
1578 __wasi_prestat_dir_t dir
;
1579 } __wasi_prestat_u_t
;
1580 typedef struct __wasi_prestat_t
{
1582 __wasi_prestat_u_t u
;
1585 _Static_assert(sizeof(__wasi_prestat_t
) == 8, "witx calculated size");
1586 _Static_assert(_Alignof(__wasi_prestat_t
) == 4, "witx calculated align");
1589 * @defgroup wasi_snapshot_preview1
1594 * Read command-line argument data.
1595 * The size of the array should match that returned by `args_sizes_get`
1597 __wasi_errno_t
__wasi_args_get(
1600 ) __attribute__((__warn_unused_result__
));
1602 * Return command-line argument data sizes.
1604 * Returns the number of arguments and the size of the argument string
1605 * data, or an error.
1607 __wasi_errno_t
__wasi_args_sizes_get(
1608 __wasi_size_t
*retptr0
,
1609 __wasi_size_t
*retptr1
1610 ) __attribute__((__warn_unused_result__
));
1612 * Read environment variable data.
1613 * The sizes of the buffers should match that returned by `environ_sizes_get`.
1615 __wasi_errno_t
__wasi_environ_get(
1616 uint8_t * * environ
,
1617 uint8_t * environ_buf
1618 ) __attribute__((__warn_unused_result__
));
1620 * Return environment variable data sizes.
1622 * Returns the number of environment variable arguments and the size of the
1623 * environment variable data.
1625 __wasi_errno_t
__wasi_environ_sizes_get(
1626 __wasi_size_t
*retptr0
,
1627 __wasi_size_t
*retptr1
1628 ) __attribute__((__warn_unused_result__
));
1630 * Return the resolution of a clock.
1631 * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
1632 * return `errno::inval`.
1633 * Note: This is similar to `clock_getres` in POSIX.
1635 * The resolution of the clock, or an error if one happened.
1637 __wasi_errno_t
__wasi_clock_res_get(
1639 * The clock for which to return the resolution.
1641 __wasi_clockid_t id
,
1642 __wasi_timestamp_t
*retptr0
1643 ) __attribute__((__warn_unused_result__
));
1645 * Return the time value of a clock.
1646 * Note: This is similar to `clock_gettime` in POSIX.
1648 * The time value of the clock.
1650 __wasi_errno_t
__wasi_clock_time_get(
1652 * The clock for which to return the time.
1654 __wasi_clockid_t id
,
1656 * The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
1658 __wasi_timestamp_t precision
,
1659 __wasi_timestamp_t
*retptr0
1660 ) __attribute__((__warn_unused_result__
));
1662 * Provide file advisory information on a file descriptor.
1663 * Note: This is similar to `posix_fadvise` in POSIX.
1665 __wasi_errno_t
__wasi_fd_advise(
1668 * The offset within the file to which the advisory applies.
1670 __wasi_filesize_t offset
,
1672 * The length of the region to which the advisory applies.
1674 __wasi_filesize_t len
,
1678 __wasi_advice_t advice
1679 ) __attribute__((__warn_unused_result__
));
1681 * Force the allocation of space in a file.
1682 * Note: This is similar to `posix_fallocate` in POSIX.
1684 __wasi_errno_t
__wasi_fd_allocate(
1687 * The offset at which to start the allocation.
1689 __wasi_filesize_t offset
,
1691 * The length of the area that is allocated.
1693 __wasi_filesize_t len
1694 ) __attribute__((__warn_unused_result__
));
1696 * Close a file descriptor.
1697 * Note: This is similar to `close` in POSIX.
1699 __wasi_errno_t
__wasi_fd_close(
1701 ) __attribute__((__warn_unused_result__
));
1703 * Synchronize the data of a file to disk.
1704 * Note: This is similar to `fdatasync` in POSIX.
1706 __wasi_errno_t
__wasi_fd_datasync(
1708 ) __attribute__((__warn_unused_result__
));
1710 * Get the attributes of a file descriptor.
1711 * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
1713 * The buffer where the file descriptor's attributes are stored.
1715 __wasi_errno_t
__wasi_fd_fdstat_get(
1717 __wasi_fdstat_t
*retptr0
1718 ) __attribute__((__warn_unused_result__
));
1720 * Adjust the flags associated with a file descriptor.
1721 * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
1723 __wasi_errno_t
__wasi_fd_fdstat_set_flags(
1726 * The desired values of the file descriptor flags.
1728 __wasi_fdflags_t flags
1729 ) __attribute__((__warn_unused_result__
));
1731 * Adjust the rights associated with a file descriptor.
1732 * This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
1734 __wasi_errno_t
__wasi_fd_fdstat_set_rights(
1737 * The desired rights of the file descriptor.
1739 __wasi_rights_t fs_rights_base
,
1740 __wasi_rights_t fs_rights_inheriting
1741 ) __attribute__((__warn_unused_result__
));
1743 * Return the attributes of an open file.
1745 * The buffer where the file's attributes are stored.
1747 __wasi_errno_t
__wasi_fd_filestat_get(
1749 __wasi_filestat_t
*retptr0
1750 ) __attribute__((__warn_unused_result__
));
1752 * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
1753 * Note: This is similar to `ftruncate` in POSIX.
1755 __wasi_errno_t
__wasi_fd_filestat_set_size(
1758 * The desired file size.
1760 __wasi_filesize_t size
1761 ) __attribute__((__warn_unused_result__
));
1763 * Adjust the timestamps of an open file or directory.
1764 * Note: This is similar to `futimens` in POSIX.
1766 __wasi_errno_t
__wasi_fd_filestat_set_times(
1769 * The desired values of the data access timestamp.
1771 __wasi_timestamp_t atim
,
1773 * The desired values of the data modification timestamp.
1775 __wasi_timestamp_t mtim
,
1777 * A bitmask indicating which timestamps to adjust.
1779 __wasi_fstflags_t fst_flags
1780 ) __attribute__((__warn_unused_result__
));
1782 * Read from a file descriptor, without using and updating the file descriptor's offset.
1783 * Note: This is similar to `preadv` in POSIX.
1785 * The number of bytes read.
1787 __wasi_errno_t
__wasi_fd_pread(
1790 * List of scatter/gather vectors in which to store data.
1792 const __wasi_iovec_t
*iovs
,
1794 * The length of the array pointed to by `iovs`.
1798 * The offset within the file at which to read.
1800 __wasi_filesize_t offset
,
1801 __wasi_size_t
*retptr0
1802 ) __attribute__((__warn_unused_result__
));
1804 * Return a description of the given preopened file descriptor.
1806 * The buffer where the description is stored.
1808 __wasi_errno_t
__wasi_fd_prestat_get(
1810 __wasi_prestat_t
*retptr0
1811 ) __attribute__((__warn_unused_result__
));
1813 * Return a description of the given preopened file descriptor.
1815 __wasi_errno_t
__wasi_fd_prestat_dir_name(
1818 * A buffer into which to write the preopened directory name.
1821 __wasi_size_t path_len
1822 ) __attribute__((__warn_unused_result__
));
1824 * Write to a file descriptor, without using and updating the file descriptor's offset.
1825 * Note: This is similar to `pwritev` in POSIX.
1827 * The number of bytes written.
1829 __wasi_errno_t
__wasi_fd_pwrite(
1832 * List of scatter/gather vectors from which to retrieve data.
1834 const __wasi_ciovec_t
*iovs
,
1836 * The length of the array pointed to by `iovs`.
1840 * The offset within the file at which to write.
1842 __wasi_filesize_t offset
,
1843 __wasi_size_t
*retptr0
1844 ) __attribute__((__warn_unused_result__
));
1846 * Read from a file descriptor.
1847 * Note: This is similar to `readv` in POSIX.
1849 * The number of bytes read.
1851 __wasi_errno_t
__wasi_fd_read(
1854 * List of scatter/gather vectors to which to store data.
1856 const __wasi_iovec_t
*iovs
,
1858 * The length of the array pointed to by `iovs`.
1861 __wasi_size_t
*retptr0
1862 ) __attribute__((__warn_unused_result__
));
1864 * Read directory entries from a directory.
1865 * When successful, the contents of the output buffer consist of a sequence of
1866 * directory entries. Each directory entry consists of a `dirent` object,
1867 * followed by `dirent::d_namlen` bytes holding the name of the directory
1869 * This function fills the output buffer as much as possible, potentially
1870 * truncating the last directory entry. This allows the caller to grow its
1871 * read buffer size in case it's too small to fit a single large directory
1872 * entry, or skip the oversized directory entry.
1874 * 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.
1876 __wasi_errno_t
__wasi_fd_readdir(
1879 * The buffer where directory entries are stored
1882 __wasi_size_t buf_len
,
1884 * The location within the directory to start reading
1886 __wasi_dircookie_t cookie
,
1887 __wasi_size_t
*retptr0
1888 ) __attribute__((__warn_unused_result__
));
1890 * Atomically replace a file descriptor by renumbering another file descriptor.
1891 * Due to the strong focus on thread safety, this environment does not provide
1892 * a mechanism to duplicate or renumber a file descriptor to an arbitrary
1893 * number, like `dup2()`. This would be prone to race conditions, as an actual
1894 * file descriptor with the same number could be allocated by a different
1895 * thread at the same time.
1896 * This function provides a way to atomically renumber file descriptors, which
1897 * would disappear if `dup2()` were to be removed entirely.
1899 __wasi_errno_t
__wasi_fd_renumber(
1902 * The file descriptor to overwrite.
1905 ) __attribute__((__warn_unused_result__
));
1907 * Move the offset of a file descriptor.
1908 * Note: This is similar to `lseek` in POSIX.
1910 * The new offset of the file descriptor, relative to the start of the file.
1912 __wasi_errno_t
__wasi_fd_seek(
1915 * The number of bytes to move.
1917 __wasi_filedelta_t offset
,
1919 * The base from which the offset is relative.
1921 __wasi_whence_t whence
,
1922 __wasi_filesize_t
*retptr0
1923 ) __attribute__((__warn_unused_result__
));
1925 * Synchronize the data and metadata of a file to disk.
1926 * Note: This is similar to `fsync` in POSIX.
1928 __wasi_errno_t
__wasi_fd_sync(
1930 ) __attribute__((__warn_unused_result__
));
1932 * Return the current offset of a file descriptor.
1933 * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
1935 * The current offset of the file descriptor, relative to the start of the file.
1937 __wasi_errno_t
__wasi_fd_tell(
1939 __wasi_filesize_t
*retptr0
1940 ) __attribute__((__warn_unused_result__
));
1942 * Write to a file descriptor.
1943 * Note: This is similar to `writev` in POSIX.
1945 __wasi_errno_t
__wasi_fd_write(
1948 * List of scatter/gather vectors from which to retrieve data.
1950 const __wasi_ciovec_t
*iovs
,
1952 * The length of the array pointed to by `iovs`.
1955 __wasi_size_t
*retptr0
1956 ) __attribute__((__warn_unused_result__
));
1958 * Create a directory.
1959 * Note: This is similar to `mkdirat` in POSIX.
1961 __wasi_errno_t
__wasi_path_create_directory(
1964 * The path at which to create the directory.
1967 ) __attribute__((__warn_unused_result__
));
1969 * Return the attributes of a file or directory.
1970 * Note: This is similar to `stat` in POSIX.
1972 * The buffer where the file's attributes are stored.
1974 __wasi_errno_t
__wasi_path_filestat_get(
1977 * Flags determining the method of how the path is resolved.
1979 __wasi_lookupflags_t flags
,
1981 * The path of the file or directory to inspect.
1984 __wasi_filestat_t
*retptr0
1985 ) __attribute__((__warn_unused_result__
));
1987 * Adjust the timestamps of a file or directory.
1988 * Note: This is similar to `utimensat` in POSIX.
1990 __wasi_errno_t
__wasi_path_filestat_set_times(
1993 * Flags determining the method of how the path is resolved.
1995 __wasi_lookupflags_t flags
,
1997 * The path of the file or directory to operate on.
2001 * The desired values of the data access timestamp.
2003 __wasi_timestamp_t atim
,
2005 * The desired values of the data modification timestamp.
2007 __wasi_timestamp_t mtim
,
2009 * A bitmask indicating which timestamps to adjust.
2011 __wasi_fstflags_t fst_flags
2012 ) __attribute__((__warn_unused_result__
));
2014 * Create a hard link.
2015 * Note: This is similar to `linkat` in POSIX.
2017 __wasi_errno_t
__wasi_path_link(
2020 * Flags determining the method of how the path is resolved.
2022 __wasi_lookupflags_t old_flags
,
2024 * The source path from which to link.
2026 const char *old_path
,
2028 * The working directory at which the resolution of the new path starts.
2032 * The destination path at which to create the hard link.
2034 const char *new_path
2035 ) __attribute__((__warn_unused_result__
));
2037 * Open a file or directory.
2038 * The returned file descriptor is not guaranteed to be the lowest-numbered
2039 * file descriptor not currently open; it is randomized to prevent
2040 * applications from depending on making assumptions about indexes, since this
2041 * is error-prone in multi-threaded contexts. The returned file descriptor is
2042 * guaranteed to be less than 2**31.
2043 * Note: This is similar to `openat` in POSIX.
2045 * The file descriptor of the file that has been opened.
2047 __wasi_errno_t
__wasi_path_open(
2050 * Flags determining the method of how the path is resolved.
2052 __wasi_lookupflags_t dirflags
,
2054 * The relative path of the file or directory to open, relative to the
2055 * `path_open::fd` directory.
2059 * The method by which to open the file.
2061 __wasi_oflags_t oflags
,
2063 * The initial rights of the newly created file descriptor. The
2064 * implementation is allowed to return a file descriptor with fewer rights
2065 * than specified, if and only if those rights do not apply to the type of
2066 * file being opened.
2067 * The *base* rights are rights that will apply to operations using the file
2068 * descriptor itself, while the *inheriting* rights are rights that apply to
2069 * file descriptors derived from it.
2071 __wasi_rights_t fs_rights_base
,
2072 __wasi_rights_t fs_rights_inheriting
,
2073 __wasi_fdflags_t fdflags
,
2074 __wasi_fd_t
*retptr0
2075 ) __attribute__((__warn_unused_result__
));
2077 * Read the contents of a symbolic link.
2078 * Note: This is similar to `readlinkat` in POSIX.
2080 * The number of bytes placed in the buffer.
2082 __wasi_errno_t
__wasi_path_readlink(
2085 * The path of the symbolic link from which to read.
2089 * The buffer to which to write the contents of the symbolic link.
2092 __wasi_size_t buf_len
,
2093 __wasi_size_t
*retptr0
2094 ) __attribute__((__warn_unused_result__
));
2096 * Remove a directory.
2097 * Return `errno::notempty` if the directory is not empty.
2098 * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
2100 __wasi_errno_t
__wasi_path_remove_directory(
2103 * The path to a directory to remove.
2106 ) __attribute__((__warn_unused_result__
));
2108 * Rename a file or directory.
2109 * Note: This is similar to `renameat` in POSIX.
2111 __wasi_errno_t
__wasi_path_rename(
2114 * The source path of the file or directory to rename.
2116 const char *old_path
,
2118 * The working directory at which the resolution of the new path starts.
2122 * The destination path to which to rename the file or directory.
2124 const char *new_path
2125 ) __attribute__((__warn_unused_result__
));
2127 * Create a symbolic link.
2128 * Note: This is similar to `symlinkat` in POSIX.
2130 __wasi_errno_t
__wasi_path_symlink(
2132 * The contents of the symbolic link.
2134 const char *old_path
,
2137 * The destination path at which to create the symbolic link.
2139 const char *new_path
2140 ) __attribute__((__warn_unused_result__
));
2143 * Return `errno::isdir` if the path refers to a directory.
2144 * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
2146 __wasi_errno_t
__wasi_path_unlink_file(
2149 * The path to a file to unlink.
2152 ) __attribute__((__warn_unused_result__
));
2154 * Concurrently poll for the occurrence of a set of events.
2156 * The number of events stored.
2158 __wasi_errno_t
__wasi_poll_oneoff(
2160 * The events to which to subscribe.
2162 const __wasi_subscription_t
* in
,
2164 * The events that have occurred.
2166 __wasi_event_t
* out
,
2168 * Both the number of subscriptions and events.
2170 __wasi_size_t nsubscriptions
,
2171 __wasi_size_t
*retptr0
2172 ) __attribute__((__warn_unused_result__
));
2174 * Terminate the process normally. An exit code of 0 indicates successful
2175 * termination of the program. The meanings of other values is dependent on
2178 _Noreturn
void __wasi_proc_exit(
2180 * The exit code returned by the process.
2182 __wasi_exitcode_t rval
2185 * Send a signal to the process of the calling thread.
2186 * Note: This is similar to `raise` in POSIX.
2188 __wasi_errno_t
__wasi_proc_raise(
2190 * The signal condition to trigger.
2193 ) __attribute__((__warn_unused_result__
));
2195 * Temporarily yield execution of the calling thread.
2196 * Note: This is similar to `sched_yield` in POSIX.
2198 __wasi_errno_t
__wasi_sched_yield(
2200 ) __attribute__((__warn_unused_result__
));
2202 * Write high-quality random data into a buffer.
2203 * This function blocks when the implementation is unable to immediately
2204 * provide sufficient high-quality random data.
2205 * This function may execute slowly, so when large mounts of random data are
2206 * required, it's advisable to use this function to seed a pseudo-random
2207 * number generator, rather than to provide the random data directly.
2209 __wasi_errno_t
__wasi_random_get(
2211 * The buffer to fill with random data.
2214 __wasi_size_t buf_len
2215 ) __attribute__((__warn_unused_result__
));
2217 * Receive a message from a socket.
2218 * Note: This is similar to `recv` in POSIX, though it also supports reading
2219 * the data into multiple buffers in the manner of `readv`.
2221 * Number of bytes stored in ri_data and message flags.
2223 __wasi_errno_t
__wasi_sock_recv(
2226 * List of scatter/gather vectors to which to store data.
2228 const __wasi_iovec_t
*ri_data
,
2230 * The length of the array pointed to by `ri_data`.
2236 __wasi_riflags_t ri_flags
,
2237 __wasi_size_t
*retptr0
,
2238 __wasi_roflags_t
*retptr1
2239 ) __attribute__((__warn_unused_result__
));
2241 * Send a message on a socket.
2242 * Note: This is similar to `send` in POSIX, though it also supports writing
2243 * the data from multiple buffers in the manner of `writev`.
2245 * Number of bytes transmitted.
2247 __wasi_errno_t
__wasi_sock_send(
2250 * List of scatter/gather vectors to which to retrieve data
2252 const __wasi_ciovec_t
*si_data
,
2254 * The length of the array pointed to by `si_data`.
2260 __wasi_siflags_t si_flags
,
2261 __wasi_size_t
*retptr0
2262 ) __attribute__((__warn_unused_result__
));
2264 * Shut down socket send and receive channels.
2265 * Note: This is similar to `shutdown` in POSIX.
2267 __wasi_errno_t
__wasi_sock_shutdown(
2270 * Which channels on the socket to shut down.
2272 __wasi_sdflags_t how
2273 ) __attribute__((__warn_unused_result__
));