2 * <wasi/api.h>. This file contains declarations describing the WASI ABI
3 * as of "snapshot preview1". It was originally auto-generated from
4 * wasi_snapshot_preview1.witx, however WASI is in the process of
5 * transitioning to a new IDL and header file generator, and this file
6 * is temporarily being manually maintained.
9 * This file describes the [WASI] interface, consisting of functions, types,
10 * and defined values (macros).
12 * The interface described here is greatly inspired by [CloudABI]'s clean,
13 * thoughtfully-designed, capability-oriented, POSIX-style API.
15 * [CloudABI]: https://github.com/NuxiNL/cloudlibc
16 * [WASI]: https://github.com/WebAssembly/WASI/
23 #error <wasi/api.h> is only supported on WASI platforms.
27 #error <wasi/api.h> only supports wasm32; doesn't yet support wasm64
33 _Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
34 _Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
35 _Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
36 _Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
37 _Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
38 _Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
39 _Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
40 _Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
41 _Static_assert(_Alignof(void*) == 4, "non-wasi data layout");
47 // TODO: Encoding this in witx.
48 #define __WASI_DIRCOOKIE_START (UINT64_C(0))
49 typedef __SIZE_TYPE__ __wasi_size_t;
51 _Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size");
52 _Static_assert(_Alignof(__wasi_size_t) == 4, "witx calculated align");
55 * Non-negative file size or length of a region within a file.
57 typedef uint64_t __wasi_filesize_t;
59 _Static_assert(sizeof(__wasi_filesize_t) == 8, "witx calculated size");
60 _Static_assert(_Alignof(__wasi_filesize_t) == 8, "witx calculated align");
63 * Timestamp in nanoseconds.
65 typedef uint64_t __wasi_timestamp_t;
67 _Static_assert(sizeof(__wasi_timestamp_t) == 8, "witx calculated size");
68 _Static_assert(_Alignof(__wasi_timestamp_t) == 8, "witx calculated align");
71 * Identifiers for clocks.
73 typedef uint32_t __wasi_clockid_t;
76 * The clock measuring real time. Time value zero corresponds with
77 * 1970-01-01T00:00:00Z.
79 #define __WASI_CLOCKID_REALTIME (UINT32_C(0))
82 * The store-wide monotonic clock, which is defined as a clock measuring
83 * real time, whose value cannot be adjusted and which cannot have negative
84 * clock jumps. The epoch of this clock is undefined. The absolute time
85 * value of this clock therefore has no meaning.
87 #define __WASI_CLOCKID_MONOTONIC (UINT32_C(1))
90 * The CPU-time clock associated with the current process.
92 #define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2))
95 * The CPU-time clock associated with the current thread.
97 #define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3))
99 _Static_assert(sizeof(__wasi_clockid_t) == 4, "witx calculated size");
100 _Static_assert(_Alignof(__wasi_clockid_t) == 4, "witx calculated align");
103 * Error codes returned by functions.
104 * Not all of these error codes are returned by the functions provided by this
105 * API; some are used in higher-level library layers, and others are provided
106 * merely for alignment with POSIX.
108 typedef uint16_t __wasi_errno_t;
111 * No error occurred. System call completed successfully.
113 #define __WASI_ERRNO_SUCCESS (UINT16_C(0))
116 * Argument list too long.
118 #define __WASI_ERRNO_2BIG (UINT16_C(1))
123 #define __WASI_ERRNO_ACCES (UINT16_C(2))
128 #define __WASI_ERRNO_ADDRINUSE (UINT16_C(3))
131 * Address not available.
133 #define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4))
136 * Address family not supported.
138 #define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5))
141 * Resource unavailable, or operation would block.
143 #define __WASI_ERRNO_AGAIN (UINT16_C(6))
146 * Connection already in progress.
148 #define __WASI_ERRNO_ALREADY (UINT16_C(7))
151 * Bad file descriptor.
153 #define __WASI_ERRNO_BADF (UINT16_C(8))
158 #define __WASI_ERRNO_BADMSG (UINT16_C(9))
161 * Device or resource busy.
163 #define __WASI_ERRNO_BUSY (UINT16_C(10))
166 * Operation canceled.
168 #define __WASI_ERRNO_CANCELED (UINT16_C(11))
171 * No child processes.
173 #define __WASI_ERRNO_CHILD (UINT16_C(12))
176 * Connection aborted.
178 #define __WASI_ERRNO_CONNABORTED (UINT16_C(13))
181 * Connection refused.
183 #define __WASI_ERRNO_CONNREFUSED (UINT16_C(14))
188 #define __WASI_ERRNO_CONNRESET (UINT16_C(15))
191 * Resource deadlock would occur.
193 #define __WASI_ERRNO_DEADLK (UINT16_C(16))
196 * Destination address required.
198 #define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17))
201 * Mathematics argument out of domain of function.
203 #define __WASI_ERRNO_DOM (UINT16_C(18))
208 #define __WASI_ERRNO_DQUOT (UINT16_C(19))
213 #define __WASI_ERRNO_EXIST (UINT16_C(20))
218 #define __WASI_ERRNO_FAULT (UINT16_C(21))
223 #define __WASI_ERRNO_FBIG (UINT16_C(22))
226 * Host is unreachable.
228 #define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23))
231 * Identifier removed.
233 #define __WASI_ERRNO_IDRM (UINT16_C(24))
236 * Illegal byte sequence.
238 #define __WASI_ERRNO_ILSEQ (UINT16_C(25))
241 * Operation in progress.
243 #define __WASI_ERRNO_INPROGRESS (UINT16_C(26))
246 * Interrupted function.
248 #define __WASI_ERRNO_INTR (UINT16_C(27))
253 #define __WASI_ERRNO_INVAL (UINT16_C(28))
258 #define __WASI_ERRNO_IO (UINT16_C(29))
261 * Socket is connected.
263 #define __WASI_ERRNO_ISCONN (UINT16_C(30))
268 #define __WASI_ERRNO_ISDIR (UINT16_C(31))
271 * Too many levels of symbolic links.
273 #define __WASI_ERRNO_LOOP (UINT16_C(32))
276 * File descriptor value too large.
278 #define __WASI_ERRNO_MFILE (UINT16_C(33))
283 #define __WASI_ERRNO_MLINK (UINT16_C(34))
288 #define __WASI_ERRNO_MSGSIZE (UINT16_C(35))
293 #define __WASI_ERRNO_MULTIHOP (UINT16_C(36))
298 #define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37))
303 #define __WASI_ERRNO_NETDOWN (UINT16_C(38))
306 * Connection aborted by network.
308 #define __WASI_ERRNO_NETRESET (UINT16_C(39))
311 * Network unreachable.
313 #define __WASI_ERRNO_NETUNREACH (UINT16_C(40))
316 * Too many files open in system.
318 #define __WASI_ERRNO_NFILE (UINT16_C(41))
321 * No buffer space available.
323 #define __WASI_ERRNO_NOBUFS (UINT16_C(42))
328 #define __WASI_ERRNO_NODEV (UINT16_C(43))
331 * No such file or directory.
333 #define __WASI_ERRNO_NOENT (UINT16_C(44))
336 * Executable file format error.
338 #define __WASI_ERRNO_NOEXEC (UINT16_C(45))
341 * No locks available.
343 #define __WASI_ERRNO_NOLCK (UINT16_C(46))
348 #define __WASI_ERRNO_NOLINK (UINT16_C(47))
353 #define __WASI_ERRNO_NOMEM (UINT16_C(48))
356 * No message of the desired type.
358 #define __WASI_ERRNO_NOMSG (UINT16_C(49))
361 * Protocol not available.
363 #define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50))
366 * No space left on device.
368 #define __WASI_ERRNO_NOSPC (UINT16_C(51))
371 * Function not supported.
373 #define __WASI_ERRNO_NOSYS (UINT16_C(52))
376 * The socket is not connected.
378 #define __WASI_ERRNO_NOTCONN (UINT16_C(53))
381 * Not a directory or a symbolic link to a directory.
383 #define __WASI_ERRNO_NOTDIR (UINT16_C(54))
386 * Directory not empty.
388 #define __WASI_ERRNO_NOTEMPTY (UINT16_C(55))
391 * State not recoverable.
393 #define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56))
398 #define __WASI_ERRNO_NOTSOCK (UINT16_C(57))
401 * Not supported, or operation not supported on socket.
403 #define __WASI_ERRNO_NOTSUP (UINT16_C(58))
406 * Inappropriate I/O control operation.
408 #define __WASI_ERRNO_NOTTY (UINT16_C(59))
411 * No such device or address.
413 #define __WASI_ERRNO_NXIO (UINT16_C(60))
416 * Value too large to be stored in data type.
418 #define __WASI_ERRNO_OVERFLOW (UINT16_C(61))
421 * Previous owner died.
423 #define __WASI_ERRNO_OWNERDEAD (UINT16_C(62))
426 * Operation not permitted.
428 #define __WASI_ERRNO_PERM (UINT16_C(63))
433 #define __WASI_ERRNO_PIPE (UINT16_C(64))
438 #define __WASI_ERRNO_PROTO (UINT16_C(65))
441 * Protocol not supported.
443 #define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66))
446 * Protocol wrong type for socket.
448 #define __WASI_ERRNO_PROTOTYPE (UINT16_C(67))
453 #define __WASI_ERRNO_RANGE (UINT16_C(68))
456 * Read-only file system.
458 #define __WASI_ERRNO_ROFS (UINT16_C(69))
463 #define __WASI_ERRNO_SPIPE (UINT16_C(70))
468 #define __WASI_ERRNO_SRCH (UINT16_C(71))
473 #define __WASI_ERRNO_STALE (UINT16_C(72))
476 * Connection timed out.
478 #define __WASI_ERRNO_TIMEDOUT (UINT16_C(73))
483 #define __WASI_ERRNO_TXTBSY (UINT16_C(74))
488 #define __WASI_ERRNO_XDEV (UINT16_C(75))
491 * Extension: Capabilities insufficient.
493 #define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76))
495 _Static_assert(sizeof(__wasi_errno_t) == 2, "witx calculated size");
496 _Static_assert(_Alignof(__wasi_errno_t) == 2, "witx calculated align");
499 * File descriptor rights, determining which actions may be performed.
501 typedef uint64_t __wasi_rights_t;
504 * The right to invoke `fd_datasync`.
505 * If `path_open` is set, includes the right to invoke
506 * `path_open` with `fdflags::dsync`.
508 #define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0))
511 * The right to invoke `fd_read` and `sock_recv`.
512 * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
514 #define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1))
517 * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
519 #define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2))
522 * The right to invoke `fd_fdstat_set_flags`.
524 #define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3))
527 * The right to invoke `fd_sync`.
528 * If `path_open` is set, includes the right to invoke
529 * `path_open` with `fdflags::rsync` and `fdflags::dsync`.
531 #define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4))
534 * The right to invoke `fd_seek` in such a way that the file offset
535 * remains unaltered (i.e., `whence::cur` with offset zero), or to
538 #define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5))
541 * The right to invoke `fd_write` and `sock_send`.
542 * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
544 #define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6))
547 * The right to invoke `fd_advise`.
549 #define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7))
552 * The right to invoke `fd_allocate`.
554 #define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8))
557 * The right to invoke `path_create_directory`.
559 #define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9))
562 * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
564 #define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10))
567 * The right to invoke `path_link` with the file descriptor as the
570 #define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11))
573 * The right to invoke `path_link` with the file descriptor as the
576 #define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12))
579 * The right to invoke `path_open`.
581 #define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13))
584 * The right to invoke `fd_readdir`.
586 #define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14))
589 * The right to invoke `path_readlink`.
591 #define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15))
594 * The right to invoke `path_rename` with the file descriptor as the source directory.
596 #define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16))
599 * The right to invoke `path_rename` with the file descriptor as the target directory.
601 #define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17))
604 * The right to invoke `path_filestat_get`.
606 #define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18))
609 * The right to change a file's size (there is no `path_filestat_set_size`).
610 * If `path_open` is set
, includes the right to invoke `path_open` with `
oflags::trunc`
.
612 #define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19))
615 * The right to invoke `path_filestat_set_times`.
617 #define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20))
620 * The right to invoke `fd_filestat_get`.
622 #define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21))
625 * The right to invoke `fd_filestat_set_size`.
627 #define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22))
630 * The right to invoke `fd_filestat_set_times`.
632 #define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23))
635 * The right to invoke `path_symlink`.
637 #define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24))
640 * The right to invoke `path_remove_directory`.
642 #define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25))
645 * The right to invoke `path_unlink_file`.
647 #define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26))
650 * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
651 * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
653 #define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27))
656 * The right to invoke `sock_shutdown`.
658 #define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28))
661 * The right to invoke `sock_accept`.
663 #define __WASI_RIGHTS_SOCK_ACCEPT ((__wasi_rights_t)(1 << 29))
666 * A file descriptor handle.
668 typedef int __wasi_fd_t
;
670 _Static_assert(sizeof(__wasi_fd_t
) == 4, "witx calculated size");
671 _Static_assert(_Alignof(__wasi_fd_t
) == 4, "witx calculated align");
674 * A region of memory for scatter/gather reads.
676 typedef struct __wasi_iovec_t
{
678 * The address of the buffer to be filled.
683 * The length of the buffer to be filled.
685 __wasi_size_t buf_len
;
689 _Static_assert(sizeof(__wasi_iovec_t
) == 8, "witx calculated size");
690 _Static_assert(_Alignof(__wasi_iovec_t
) == 4, "witx calculated align");
691 _Static_assert(offsetof(__wasi_iovec_t
, buf
) == 0, "witx calculated offset");
692 _Static_assert(offsetof(__wasi_iovec_t
, buf_len
) == 4, "witx calculated offset");
695 * A region of memory for scatter/gather writes.
697 typedef struct __wasi_ciovec_t
{
699 * The address of the buffer to be written.
704 * The length of the buffer to be written.
706 __wasi_size_t buf_len
;
710 _Static_assert(sizeof(__wasi_ciovec_t
) == 8, "witx calculated size");
711 _Static_assert(_Alignof(__wasi_ciovec_t
) == 4, "witx calculated align");
712 _Static_assert(offsetof(__wasi_ciovec_t
, buf
) == 0, "witx calculated offset");
713 _Static_assert(offsetof(__wasi_ciovec_t
, buf_len
) == 4, "witx calculated offset");
716 * Relative offset within a file.
718 typedef int64_t __wasi_filedelta_t
;
720 _Static_assert(sizeof(__wasi_filedelta_t
) == 8, "witx calculated size");
721 _Static_assert(_Alignof(__wasi_filedelta_t
) == 8, "witx calculated align");
724 * The position relative to which to set the offset of the file descriptor.
726 typedef uint8_t __wasi_whence_t
;
729 * Seek relative to start-of-file.
731 #define __WASI_WHENCE_SET (UINT8_C(0))
734 * Seek relative to current position.
736 #define __WASI_WHENCE_CUR (UINT8_C(1))
739 * Seek relative to end-of-file.
741 #define __WASI_WHENCE_END (UINT8_C(2))
743 _Static_assert(sizeof(__wasi_whence_t
) == 1, "witx calculated size");
744 _Static_assert(_Alignof(__wasi_whence_t
) == 1, "witx calculated align");
747 * A reference to the offset of a directory entry.
749 * The value 0 signifies the start of the directory.
751 typedef uint64_t __wasi_dircookie_t
;
753 _Static_assert(sizeof(__wasi_dircookie_t
) == 8, "witx calculated size");
754 _Static_assert(_Alignof(__wasi_dircookie_t
) == 8, "witx calculated align");
757 * The type for the `dirent::d_namlen` field of `dirent` struct.
759 typedef uint32_t __wasi_dirnamlen_t
;
761 _Static_assert(sizeof(__wasi_dirnamlen_t
) == 4, "witx calculated size");
762 _Static_assert(_Alignof(__wasi_dirnamlen_t
) == 4, "witx calculated align");
765 * File serial number that is unique within its file system.
767 typedef uint64_t __wasi_inode_t
;
769 _Static_assert(sizeof(__wasi_inode_t
) == 8, "witx calculated size");
770 _Static_assert(_Alignof(__wasi_inode_t
) == 8, "witx calculated align");
773 * The type of a file descriptor or file.
775 typedef uint8_t __wasi_filetype_t
;
778 * The type of the file descriptor or file is unknown or is different from any of the other types specified.
780 #define __WASI_FILETYPE_UNKNOWN (UINT8_C(0))
783 * The file descriptor or file refers to a block device inode.
785 #define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1))
788 * The file descriptor or file refers to a character device inode.
790 #define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2))
793 * The file descriptor or file refers to a directory inode.
795 #define __WASI_FILETYPE_DIRECTORY (UINT8_C(3))
798 * The file descriptor or file refers to a regular file inode.
800 #define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4))
803 * The file descriptor or file refers to a datagram socket.
805 #define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5))
808 * The file descriptor or file refers to a byte-stream socket.
810 #define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6))
813 * The file refers to a symbolic link inode.
815 #define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7))
817 _Static_assert(sizeof(__wasi_filetype_t
) == 1, "witx calculated size");
818 _Static_assert(_Alignof(__wasi_filetype_t
) == 1, "witx calculated align");
823 typedef struct __wasi_dirent_t
{
825 * The offset of the next directory entry stored in this directory.
827 __wasi_dircookie_t d_next
;
830 * The serial number of the file referred to by this directory entry.
832 __wasi_inode_t d_ino
;
835 * The length of the name of the directory entry.
837 __wasi_dirnamlen_t d_namlen
;
840 * The type of the file referred to by this directory entry.
842 __wasi_filetype_t d_type
;
846 _Static_assert(sizeof(__wasi_dirent_t
) == 24, "witx calculated size");
847 _Static_assert(_Alignof(__wasi_dirent_t
) == 8, "witx calculated align");
848 _Static_assert(offsetof(__wasi_dirent_t
, d_next
) == 0, "witx calculated offset");
849 _Static_assert(offsetof(__wasi_dirent_t
, d_ino
) == 8, "witx calculated offset");
850 _Static_assert(offsetof(__wasi_dirent_t
, d_namlen
) == 16, "witx calculated offset");
851 _Static_assert(offsetof(__wasi_dirent_t
, d_type
) == 20, "witx calculated offset");
854 * File or memory access pattern advisory information.
856 typedef uint8_t __wasi_advice_t
;
859 * The application has no advice to give on its behavior with respect to the specified data.
861 #define __WASI_ADVICE_NORMAL (UINT8_C(0))
864 * The application expects to access the specified data sequentially from lower offsets to higher offsets.
866 #define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1))
869 * The application expects to access the specified data in a random order.
871 #define __WASI_ADVICE_RANDOM (UINT8_C(2))
874 * The application expects to access the specified data in the near future.
876 #define __WASI_ADVICE_WILLNEED (UINT8_C(3))
879 * The application expects that it will not access the specified data in the near future.
881 #define __WASI_ADVICE_DONTNEED (UINT8_C(4))
884 * The application expects to access the specified data once and then not reuse it thereafter.
886 #define __WASI_ADVICE_NOREUSE (UINT8_C(5))
888 _Static_assert(sizeof(__wasi_advice_t
) == 1, "witx calculated size");
889 _Static_assert(_Alignof(__wasi_advice_t
) == 1, "witx calculated align");
892 * File descriptor flags.
894 typedef uint16_t __wasi_fdflags_t
;
897 * Append mode: Data written to the file is always appended to the file's end.
899 #define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)(1 << 0))
902 * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
904 #define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1))
909 #define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2))
912 * Synchronized read I/O operations.
914 #define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3))
917 * Write according to synchronized I/O file integrity completion. In
918 * addition to synchronizing the data stored in the file, the implementation
919 * may also synchronously update the file's metadata.
921 #define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4))
924 * File descriptor attributes.
926 typedef struct __wasi_fdstat_t
{
930 __wasi_filetype_t fs_filetype
;
933 * File descriptor flags.
935 __wasi_fdflags_t fs_flags
;
938 * Rights that apply to this file descriptor.
940 __wasi_rights_t fs_rights_base
;
943 * Maximum set of rights that may be installed on new file descriptors that
944 * are created through this file descriptor, e.g., through `path_open`.
946 __wasi_rights_t fs_rights_inheriting
;
950 _Static_assert(sizeof(__wasi_fdstat_t
) == 24, "witx calculated size");
951 _Static_assert(_Alignof(__wasi_fdstat_t
) == 8, "witx calculated align");
952 _Static_assert(offsetof(__wasi_fdstat_t
, fs_filetype
) == 0, "witx calculated offset");
953 _Static_assert(offsetof(__wasi_fdstat_t
, fs_flags
) == 2, "witx calculated offset");
954 _Static_assert(offsetof(__wasi_fdstat_t
, fs_rights_base
) == 8, "witx calculated offset");
955 _Static_assert(offsetof(__wasi_fdstat_t
, fs_rights_inheriting
) == 16, "witx calculated offset");
958 * Identifier for a device containing a file system. Can be used in combination
959 * with `inode` to uniquely identify a file or directory in the filesystem.
961 typedef uint64_t __wasi_device_t
;
963 _Static_assert(sizeof(__wasi_device_t
) == 8, "witx calculated size");
964 _Static_assert(_Alignof(__wasi_device_t
) == 8, "witx calculated align");
967 * Which file time attributes to adjust.
969 typedef uint16_t __wasi_fstflags_t
;
972 * Adjust the last data access timestamp to the value stored in `filestat::atim`.
974 #define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0))
977 * Adjust the last data access timestamp to the time of clock `clockid::realtime`.
979 #define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1))
982 * Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
984 #define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2))
987 * Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
989 #define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3))
992 * Flags determining the method of how paths are resolved.
994 typedef uint32_t __wasi_lookupflags_t
;
997 * As long as the resolved path corresponds to a symbolic link, it is expanded.
999 #define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0))
1002 * Open flags used by `path_open`.
1004 typedef uint16_t __wasi_oflags_t
;
1007 * Create file if it does not exist.
1009 #define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0))
1012 * Fail if not a directory.
1014 #define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1))
1017 * Fail if file already exists.
1019 #define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2))
1022 * Truncate file to size 0.
1024 #define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3))
1027 * Number of hard links to an inode.
1029 typedef uint64_t __wasi_linkcount_t
;
1031 _Static_assert(sizeof(__wasi_linkcount_t
) == 8, "witx calculated size");
1032 _Static_assert(_Alignof(__wasi_linkcount_t
) == 8, "witx calculated align");
1037 typedef struct __wasi_filestat_t
{
1039 * Device ID of device containing the file.
1041 __wasi_device_t dev
;
1044 * File serial number.
1051 __wasi_filetype_t filetype
;
1054 * Number of hard links to the file.
1056 __wasi_linkcount_t nlink
;
1059 * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
1061 __wasi_filesize_t size
;
1064 * Last data access timestamp.
1066 __wasi_timestamp_t atim
;
1069 * Last data modification timestamp.
1071 __wasi_timestamp_t mtim
;
1074 * Last file status change timestamp.
1076 __wasi_timestamp_t ctim
;
1078 } __wasi_filestat_t
;
1080 _Static_assert(sizeof(__wasi_filestat_t
) == 64, "witx calculated size");
1081 _Static_assert(_Alignof(__wasi_filestat_t
) == 8, "witx calculated align");
1082 _Static_assert(offsetof(__wasi_filestat_t
, dev
) == 0, "witx calculated offset");
1083 _Static_assert(offsetof(__wasi_filestat_t
, ino
) == 8, "witx calculated offset");
1084 _Static_assert(offsetof(__wasi_filestat_t
, filetype
) == 16, "witx calculated offset");
1085 _Static_assert(offsetof(__wasi_filestat_t
, nlink
) == 24, "witx calculated offset");
1086 _Static_assert(offsetof(__wasi_filestat_t
, size
) == 32, "witx calculated offset");
1087 _Static_assert(offsetof(__wasi_filestat_t
, atim
) == 40, "witx calculated offset");
1088 _Static_assert(offsetof(__wasi_filestat_t
, mtim
) == 48, "witx calculated offset");
1089 _Static_assert(offsetof(__wasi_filestat_t
, ctim
) == 56, "witx calculated offset");
1092 * User-provided value that may be attached to objects that is retained when
1093 * extracted from the implementation.
1095 typedef uint64_t __wasi_userdata_t
;
1097 _Static_assert(sizeof(__wasi_userdata_t
) == 8, "witx calculated size");
1098 _Static_assert(_Alignof(__wasi_userdata_t
) == 8, "witx calculated align");
1101 * Type of a subscription to an event or its occurrence.
1103 typedef uint8_t __wasi_eventtype_t
;
1106 * The time value of clock `subscription_clock::id` has
1107 * reached timestamp `subscription_clock::timeout`.
1109 #define __WASI_EVENTTYPE_CLOCK (UINT8_C(0))
1112 * File descriptor `subscription_fd_readwrite::file_descriptor` has data
1113 * available for reading. This event always triggers for regular files.
1115 #define __WASI_EVENTTYPE_FD_READ (UINT8_C(1))
1118 * File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
1119 * available for writing. This event always triggers for regular files.
1121 #define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2))
1123 _Static_assert(sizeof(__wasi_eventtype_t
) == 1, "witx calculated size");
1124 _Static_assert(_Alignof(__wasi_eventtype_t
) == 1, "witx calculated align");
1127 * The state of the file descriptor subscribed to with
1128 * `eventtype::fd_read` or `eventtype::fd_write`.
1130 typedef uint16_t __wasi_eventrwflags_t
;
1133 * The peer of this socket has closed or disconnected.
1135 #define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)(1 << 0))
1138 * The contents of an `event` when type is `eventtype::fd_read` or
1139 * `eventtype::fd_write`.
1141 typedef struct __wasi_event_fd_readwrite_t
{
1143 * The number of bytes available for reading or writing.
1145 __wasi_filesize_t nbytes
;
1148 * The state of the file descriptor.
1150 __wasi_eventrwflags_t flags
;
1152 } __wasi_event_fd_readwrite_t
;
1154 _Static_assert(sizeof(__wasi_event_fd_readwrite_t
) == 16, "witx calculated size");
1155 _Static_assert(_Alignof(__wasi_event_fd_readwrite_t
) == 8, "witx calculated align");
1156 _Static_assert(offsetof(__wasi_event_fd_readwrite_t
, nbytes
) == 0, "witx calculated offset");
1157 _Static_assert(offsetof(__wasi_event_fd_readwrite_t
, flags
) == 8, "witx calculated offset");
1160 * An event that occurred.
1162 typedef struct __wasi_event_t
{
1164 * User-provided value that got attached to `subscription::userdata`.
1166 __wasi_userdata_t userdata
;
1169 * If non-zero, an error that occurred while processing the subscription request.
1171 __wasi_errno_t error
;
1174 * The type of event that occured
1176 __wasi_eventtype_t type
;
1179 * The contents of the event, if it is an `eventtype::fd_read` or
1180 * `eventtype::fd_write`. `eventtype::clock` events ignore this field.
1182 __wasi_event_fd_readwrite_t fd_readwrite
;
1186 _Static_assert(sizeof(__wasi_event_t
) == 32, "witx calculated size");
1187 _Static_assert(_Alignof(__wasi_event_t
) == 8, "witx calculated align");
1188 _Static_assert(offsetof(__wasi_event_t
, userdata
) == 0, "witx calculated offset");
1189 _Static_assert(offsetof(__wasi_event_t
, error
) == 8, "witx calculated offset");
1190 _Static_assert(offsetof(__wasi_event_t
, type
) == 10, "witx calculated offset");
1191 _Static_assert(offsetof(__wasi_event_t
, fd_readwrite
) == 16, "witx calculated offset");
1194 * Flags determining how to interpret the timestamp provided in
1195 * `subscription_clock::timeout`.
1197 typedef uint16_t __wasi_subclockflags_t
;
1200 * If set, treat the timestamp provided in
1201 * `subscription_clock::timeout` as an absolute timestamp of clock
1202 * `subscription_clock::id`. If clear, treat the timestamp
1203 * provided in `subscription_clock::timeout` relative to the
1204 * current time value of clock `subscription_clock::id`.
1206 #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0))
1209 * The contents of a `subscription` when type is `eventtype::clock`.
1211 typedef struct __wasi_subscription_clock_t
{
1213 * The clock against which to compare the timestamp.
1215 __wasi_clockid_t id
;
1218 * The absolute or relative timestamp.
1220 __wasi_timestamp_t timeout
;
1223 * The amount of time that the implementation may wait additionally
1224 * to coalesce with other events.
1226 __wasi_timestamp_t precision
;
1229 * Flags specifying whether the timeout is absolute or relative
1231 __wasi_subclockflags_t flags
;
1233 } __wasi_subscription_clock_t
;
1235 _Static_assert(sizeof(__wasi_subscription_clock_t
) == 32, "witx calculated size");
1236 _Static_assert(_Alignof(__wasi_subscription_clock_t
) == 8, "witx calculated align");
1237 _Static_assert(offsetof(__wasi_subscription_clock_t
, id
) == 0, "witx calculated offset");
1238 _Static_assert(offsetof(__wasi_subscription_clock_t
, timeout
) == 8, "witx calculated offset");
1239 _Static_assert(offsetof(__wasi_subscription_clock_t
, precision
) == 16, "witx calculated offset");
1240 _Static_assert(offsetof(__wasi_subscription_clock_t
, flags
) == 24, "witx calculated offset");
1243 * The contents of a `subscription` when type is type is
1244 * `eventtype::fd_read` or `eventtype::fd_write`.
1246 typedef struct __wasi_subscription_fd_readwrite_t
{
1248 * The file descriptor on which to wait for it to become ready for reading or writing.
1250 __wasi_fd_t file_descriptor
;
1252 } __wasi_subscription_fd_readwrite_t
;
1254 _Static_assert(sizeof(__wasi_subscription_fd_readwrite_t
) == 4, "witx calculated size");
1255 _Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t
) == 4, "witx calculated align");
1256 _Static_assert(offsetof(__wasi_subscription_fd_readwrite_t
, file_descriptor
) == 0, "witx calculated offset");
1259 * The contents of a `subscription`.
1261 typedef union __wasi_subscription_u_u_t
{
1262 __wasi_subscription_clock_t clock
;
1263 __wasi_subscription_fd_readwrite_t fd_read
;
1264 __wasi_subscription_fd_readwrite_t fd_write
;
1265 } __wasi_subscription_u_u_t
;
1266 typedef struct __wasi_subscription_u_t
{
1268 __wasi_subscription_u_u_t u
;
1269 } __wasi_subscription_u_t
;
1271 _Static_assert(sizeof(__wasi_subscription_u_t
) == 40, "witx calculated size");
1272 _Static_assert(_Alignof(__wasi_subscription_u_t
) == 8, "witx calculated align");
1275 * Subscription to an event.
1277 typedef struct __wasi_subscription_t
{
1279 * User-provided value that is attached to the subscription in the
1280 * implementation and returned through `event::userdata`.
1282 __wasi_userdata_t userdata
;
1285 * The type of the event to which to subscribe, and its contents
1287 __wasi_subscription_u_t u
;
1289 } __wasi_subscription_t
;
1291 _Static_assert(sizeof(__wasi_subscription_t
) == 48, "witx calculated size");
1292 _Static_assert(_Alignof(__wasi_subscription_t
) == 8, "witx calculated align");
1293 _Static_assert(offsetof(__wasi_subscription_t
, userdata
) == 0, "witx calculated offset");
1294 _Static_assert(offsetof(__wasi_subscription_t
, u
) == 8, "witx calculated offset");
1297 * Exit code generated by a process when exiting.
1299 typedef uint32_t __wasi_exitcode_t
;
1301 _Static_assert(sizeof(__wasi_exitcode_t
) == 4, "witx calculated size");
1302 _Static_assert(_Alignof(__wasi_exitcode_t
) == 4, "witx calculated align");
1305 * Flags provided to `sock_recv`.
1307 typedef uint16_t __wasi_riflags_t
;
1310 * Returns the message without removing it from the socket's receive queue.
1312 #define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)(1 << 0))
1315 * On byte-stream sockets, block until the full amount of data can be returned.
1317 #define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1))
1320 * Flags returned by `sock_recv`.
1322 typedef uint16_t __wasi_roflags_t
;
1325 * Returned by `sock_recv`: Message data has been truncated.
1327 #define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)(1 << 0))
1330 * Flags provided to `sock_send`. As there are currently no flags
1331 * defined, it must be set to zero.
1333 typedef uint16_t __wasi_siflags_t
;
1335 _Static_assert(sizeof(__wasi_siflags_t
) == 2, "witx calculated size");
1336 _Static_assert(_Alignof(__wasi_siflags_t
) == 2, "witx calculated align");
1339 * Which channels on a socket to shut down.
1341 typedef uint8_t __wasi_sdflags_t
;
1344 * Disables further receive operations.
1346 #define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0))
1349 * Disables further send operations.
1351 #define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1))
1354 * Identifiers for preopened capabilities.
1356 typedef uint8_t __wasi_preopentype_t
;
1359 * A pre-opened directory.
1361 #define __WASI_PREOPENTYPE_DIR (UINT8_C(0))
1363 _Static_assert(sizeof(__wasi_preopentype_t
) == 1, "witx calculated size");
1364 _Static_assert(_Alignof(__wasi_preopentype_t
) == 1, "witx calculated align");
1367 * The contents of a $prestat when type is `preopentype::dir`.
1369 typedef struct __wasi_prestat_dir_t
{
1371 * The length of the directory name for use with `fd_prestat_dir_name`.
1373 __wasi_size_t pr_name_len
;
1375 } __wasi_prestat_dir_t
;
1377 _Static_assert(sizeof(__wasi_prestat_dir_t
) == 4, "witx calculated size");
1378 _Static_assert(_Alignof(__wasi_prestat_dir_t
) == 4, "witx calculated align");
1379 _Static_assert(offsetof(__wasi_prestat_dir_t
, pr_name_len
) == 0, "witx calculated offset");
1382 * Information about a pre-opened capability.
1384 typedef union __wasi_prestat_u_t
{
1385 __wasi_prestat_dir_t dir
;
1386 } __wasi_prestat_u_t
;
1387 typedef struct __wasi_prestat_t
{
1389 __wasi_prestat_u_t u
;
1392 _Static_assert(sizeof(__wasi_prestat_t
) == 8, "witx calculated size");
1393 _Static_assert(_Alignof(__wasi_prestat_t
) == 4, "witx calculated align");
1396 * @defgroup wasi_snapshot_preview1
1401 * Read command-line argument data.
1402 * The size of the array should match that returned by `args_sizes_get`.
1403 * Each argument is expected to be `\0` terminated.
1405 __wasi_errno_t
__wasi_args_get(
1408 ) __attribute__((__warn_unused_result__
));
1410 * Return command-line argument data sizes.
1412 * Returns the number of arguments and the size of the argument string
1413 * data, or an error.
1415 __wasi_errno_t
__wasi_args_sizes_get(
1416 __wasi_size_t
*retptr0
,
1417 __wasi_size_t
*retptr1
1418 ) __attribute__((__warn_unused_result__
));
1420 * Read environment variable data.
1421 * The sizes of the buffers should match that returned by `environ_sizes_get`.
1422 * Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s.
1424 __wasi_errno_t
__wasi_environ_get(
1425 uint8_t * * environ
,
1426 uint8_t * environ_buf
1427 ) __attribute__((__warn_unused_result__
));
1429 * Return environment variable data sizes.
1431 * Returns the number of environment variable arguments and the size of the
1432 * environment variable data.
1434 __wasi_errno_t
__wasi_environ_sizes_get(
1435 __wasi_size_t
*retptr0
,
1436 __wasi_size_t
*retptr1
1437 ) __attribute__((__warn_unused_result__
));
1439 * Return the resolution of a clock.
1440 * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
1441 * return `errno::inval`.
1442 * Note: This is similar to `clock_getres` in POSIX.
1444 * The resolution of the clock, or an error if one happened.
1446 __wasi_errno_t
__wasi_clock_res_get(
1448 * The clock for which to return the resolution.
1450 __wasi_clockid_t id
,
1451 __wasi_timestamp_t
*retptr0
1452 ) __attribute__((__warn_unused_result__
));
1454 * Return the time value of a clock.
1455 * Note: This is similar to `clock_gettime` in POSIX.
1457 * The time value of the clock.
1459 __wasi_errno_t
__wasi_clock_time_get(
1461 * The clock for which to return the time.
1463 __wasi_clockid_t id
,
1465 * The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
1467 __wasi_timestamp_t precision
,
1468 __wasi_timestamp_t
*retptr0
1469 ) __attribute__((__warn_unused_result__
));
1471 * Provide file advisory information on a file descriptor.
1472 * Note: This is similar to `posix_fadvise` in POSIX.
1474 __wasi_errno_t
__wasi_fd_advise(
1477 * The offset within the file to which the advisory applies.
1479 __wasi_filesize_t offset
,
1481 * The length of the region to which the advisory applies.
1483 __wasi_filesize_t len
,
1487 __wasi_advice_t advice
1488 ) __attribute__((__warn_unused_result__
));
1490 * Force the allocation of space in a file.
1491 * Note: This is similar to `posix_fallocate` in POSIX.
1493 __wasi_errno_t
__wasi_fd_allocate(
1496 * The offset at which to start the allocation.
1498 __wasi_filesize_t offset
,
1500 * The length of the area that is allocated.
1502 __wasi_filesize_t len
1503 ) __attribute__((__warn_unused_result__
));
1505 * Close a file descriptor.
1506 * Note: This is similar to `close` in POSIX.
1508 __wasi_errno_t
__wasi_fd_close(
1510 ) __attribute__((__warn_unused_result__
));
1512 * Synchronize the data of a file to disk.
1513 * Note: This is similar to `fdatasync` in POSIX.
1515 __wasi_errno_t
__wasi_fd_datasync(
1517 ) __attribute__((__warn_unused_result__
));
1519 * Get the attributes of a file descriptor.
1520 * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
1522 * The buffer where the file descriptor's attributes are stored.
1524 __wasi_errno_t
__wasi_fd_fdstat_get(
1526 __wasi_fdstat_t
*retptr0
1527 ) __attribute__((__warn_unused_result__
));
1529 * Adjust the flags associated with a file descriptor.
1530 * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
1532 __wasi_errno_t
__wasi_fd_fdstat_set_flags(
1535 * The desired values of the file descriptor flags.
1537 __wasi_fdflags_t flags
1538 ) __attribute__((__warn_unused_result__
));
1540 * Adjust the rights associated with a file descriptor.
1541 * This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
1543 __wasi_errno_t
__wasi_fd_fdstat_set_rights(
1546 * The desired rights of the file descriptor.
1548 __wasi_rights_t fs_rights_base
,
1549 __wasi_rights_t fs_rights_inheriting
1550 ) __attribute__((__warn_unused_result__
));
1552 * Return the attributes of an open file.
1554 * The buffer where the file's attributes are stored.
1556 __wasi_errno_t
__wasi_fd_filestat_get(
1558 __wasi_filestat_t
*retptr0
1559 ) __attribute__((__warn_unused_result__
));
1561 * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
1562 * Note: This is similar to `ftruncate` in POSIX.
1564 __wasi_errno_t
__wasi_fd_filestat_set_size(
1567 * The desired file size.
1569 __wasi_filesize_t size
1570 ) __attribute__((__warn_unused_result__
));
1572 * Adjust the timestamps of an open file or directory.
1573 * Note: This is similar to `futimens` in POSIX.
1575 __wasi_errno_t
__wasi_fd_filestat_set_times(
1578 * The desired values of the data access timestamp.
1580 __wasi_timestamp_t atim
,
1582 * The desired values of the data modification timestamp.
1584 __wasi_timestamp_t mtim
,
1586 * A bitmask indicating which timestamps to adjust.
1588 __wasi_fstflags_t fst_flags
1589 ) __attribute__((__warn_unused_result__
));
1591 * Read from a file descriptor, without using and updating the file descriptor's offset.
1592 * Note: This is similar to `preadv` in POSIX.
1594 * The number of bytes read.
1596 __wasi_errno_t
__wasi_fd_pread(
1599 * List of scatter/gather vectors in which to store data.
1601 const __wasi_iovec_t
*iovs
,
1603 * The length of the array pointed to by `iovs`.
1607 * The offset within the file at which to read.
1609 __wasi_filesize_t offset
,
1610 __wasi_size_t
*retptr0
1611 ) __attribute__((__warn_unused_result__
));
1613 * Return a description of the given preopened file descriptor.
1615 * The buffer where the description is stored.
1617 __wasi_errno_t
__wasi_fd_prestat_get(
1619 __wasi_prestat_t
*retptr0
1620 ) __attribute__((__warn_unused_result__
));
1622 * Return a description of the given preopened file descriptor.
1624 __wasi_errno_t
__wasi_fd_prestat_dir_name(
1627 * A buffer into which to write the preopened directory name.
1630 __wasi_size_t path_len
1631 ) __attribute__((__warn_unused_result__
));
1633 * Write to a file descriptor, without using and updating the file descriptor's offset.
1634 * Note: This is similar to `pwritev` in POSIX.
1636 * The number of bytes written.
1638 __wasi_errno_t
__wasi_fd_pwrite(
1641 * List of scatter/gather vectors from which to retrieve data.
1643 const __wasi_ciovec_t
*iovs
,
1645 * The length of the array pointed to by `iovs`.
1649 * The offset within the file at which to write.
1651 __wasi_filesize_t offset
,
1652 __wasi_size_t
*retptr0
1653 ) __attribute__((__warn_unused_result__
));
1655 * Read from a file descriptor.
1656 * Note: This is similar to `readv` in POSIX.
1658 * The number of bytes read.
1660 __wasi_errno_t
__wasi_fd_read(
1663 * List of scatter/gather vectors to which to store data.
1665 const __wasi_iovec_t
*iovs
,
1667 * The length of the array pointed to by `iovs`.
1670 __wasi_size_t
*retptr0
1671 ) __attribute__((__warn_unused_result__
));
1673 * Read directory entries from a directory.
1674 * When successful, the contents of the output buffer consist of a sequence of
1675 * directory entries. Each directory entry consists of a `dirent` object,
1676 * followed by `dirent::d_namlen` bytes holding the name of the directory
1678 * This function fills the output buffer as much as possible, potentially
1679 * truncating the last directory entry. This allows the caller to grow its
1680 * read buffer size in case it's too small to fit a single large directory
1681 * entry, or skip the oversized directory entry.
1683 * 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.
1685 __wasi_errno_t
__wasi_fd_readdir(
1688 * The buffer where directory entries are stored
1691 __wasi_size_t buf_len
,
1693 * The location within the directory to start reading
1695 __wasi_dircookie_t cookie
,
1696 __wasi_size_t
*retptr0
1697 ) __attribute__((__warn_unused_result__
));
1699 * Atomically replace a file descriptor by renumbering another file descriptor.
1700 * Due to the strong focus on thread safety, this environment does not provide
1701 * a mechanism to duplicate or renumber a file descriptor to an arbitrary
1702 * number, like `dup2()`. This would be prone to race conditions, as an actual
1703 * file descriptor with the same number could be allocated by a different
1704 * thread at the same time.
1705 * This function provides a way to atomically renumber file descriptors, which
1706 * would disappear if `dup2()` were to be removed entirely.
1708 __wasi_errno_t
__wasi_fd_renumber(
1711 * The file descriptor to overwrite.
1714 ) __attribute__((__warn_unused_result__
));
1716 * Move the offset of a file descriptor.
1717 * Note: This is similar to `lseek` in POSIX.
1719 * The new offset of the file descriptor, relative to the start of the file.
1721 __wasi_errno_t
__wasi_fd_seek(
1724 * The number of bytes to move.
1726 __wasi_filedelta_t offset
,
1728 * The base from which the offset is relative.
1730 __wasi_whence_t whence
,
1731 __wasi_filesize_t
*retptr0
1732 ) __attribute__((__warn_unused_result__
));
1734 * Synchronize the data and metadata of a file to disk.
1735 * Note: This is similar to `fsync` in POSIX.
1737 __wasi_errno_t
__wasi_fd_sync(
1739 ) __attribute__((__warn_unused_result__
));
1741 * Return the current offset of a file descriptor.
1742 * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
1744 * The current offset of the file descriptor, relative to the start of the file.
1746 __wasi_errno_t
__wasi_fd_tell(
1748 __wasi_filesize_t
*retptr0
1749 ) __attribute__((__warn_unused_result__
));
1751 * Write to a file descriptor.
1752 * Note: This is similar to `writev` in POSIX.
1754 __wasi_errno_t
__wasi_fd_write(
1757 * List of scatter/gather vectors from which to retrieve data.
1759 const __wasi_ciovec_t
*iovs
,
1761 * The length of the array pointed to by `iovs`.
1764 __wasi_size_t
*retptr0
1765 ) __attribute__((__warn_unused_result__
));
1767 * Create a directory.
1768 * Note: This is similar to `mkdirat` in POSIX.
1770 __wasi_errno_t
__wasi_path_create_directory(
1773 * The path at which to create the directory.
1776 ) __attribute__((__warn_unused_result__
));
1778 * Return the attributes of a file or directory.
1779 * Note: This is similar to `stat` in POSIX.
1781 * The buffer where the file's attributes are stored.
1783 __wasi_errno_t
__wasi_path_filestat_get(
1786 * Flags determining the method of how the path is resolved.
1788 __wasi_lookupflags_t flags
,
1790 * The path of the file or directory to inspect.
1793 __wasi_filestat_t
*retptr0
1794 ) __attribute__((__warn_unused_result__
));
1796 * Adjust the timestamps of a file or directory.
1797 * Note: This is similar to `utimensat` in POSIX.
1799 __wasi_errno_t
__wasi_path_filestat_set_times(
1802 * Flags determining the method of how the path is resolved.
1804 __wasi_lookupflags_t flags
,
1806 * The path of the file or directory to operate on.
1810 * The desired values of the data access timestamp.
1812 __wasi_timestamp_t atim
,
1814 * The desired values of the data modification timestamp.
1816 __wasi_timestamp_t mtim
,
1818 * A bitmask indicating which timestamps to adjust.
1820 __wasi_fstflags_t fst_flags
1821 ) __attribute__((__warn_unused_result__
));
1823 * Create a hard link.
1824 * Note: This is similar to `linkat` in POSIX.
1826 __wasi_errno_t
__wasi_path_link(
1829 * Flags determining the method of how the path is resolved.
1831 __wasi_lookupflags_t old_flags
,
1833 * The source path from which to link.
1835 const char *old_path
,
1837 * The working directory at which the resolution of the new path starts.
1841 * The destination path at which to create the hard link.
1843 const char *new_path
1844 ) __attribute__((__warn_unused_result__
));
1846 * Open a file or directory.
1847 * The returned file descriptor is not guaranteed to be the lowest-numbered
1848 * file descriptor not currently open; it is randomized to prevent
1849 * applications from depending on making assumptions about indexes, since this
1850 * is error-prone in multi-threaded contexts. The returned file descriptor is
1851 * guaranteed to be less than 2**31.
1852 * Note: This is similar to `openat` in POSIX.
1854 * The file descriptor of the file that has been opened.
1856 __wasi_errno_t
__wasi_path_open(
1859 * Flags determining the method of how the path is resolved.
1861 __wasi_lookupflags_t dirflags
,
1863 * The relative path of the file or directory to open, relative to the
1864 * `path_open::fd` directory.
1868 * The method by which to open the file.
1870 __wasi_oflags_t oflags
,
1872 * The initial rights of the newly created file descriptor. The
1873 * implementation is allowed to return a file descriptor with fewer rights
1874 * than specified, if and only if those rights do not apply to the type of
1875 * file being opened.
1876 * The *base* rights are rights that will apply to operations using the file
1877 * descriptor itself, while the *inheriting* rights are rights that apply to
1878 * file descriptors derived from it.
1880 __wasi_rights_t fs_rights_base
,
1881 __wasi_rights_t fs_rights_inheriting
,
1882 __wasi_fdflags_t fdflags
,
1883 __wasi_fd_t
*retptr0
1884 ) __attribute__((__warn_unused_result__
));
1886 * Read the contents of a symbolic link.
1887 * Note: This is similar to `readlinkat` in POSIX.
1889 * The number of bytes placed in the buffer.
1891 __wasi_errno_t
__wasi_path_readlink(
1894 * The path of the symbolic link from which to read.
1898 * The buffer to which to write the contents of the symbolic link.
1901 __wasi_size_t buf_len
,
1902 __wasi_size_t
*retptr0
1903 ) __attribute__((__warn_unused_result__
));
1905 * Remove a directory.
1906 * Return `errno::notempty` if the directory is not empty.
1907 * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
1909 __wasi_errno_t
__wasi_path_remove_directory(
1912 * The path to a directory to remove.
1915 ) __attribute__((__warn_unused_result__
));
1917 * Rename a file or directory.
1918 * Note: This is similar to `renameat` in POSIX.
1920 __wasi_errno_t
__wasi_path_rename(
1923 * The source path of the file or directory to rename.
1925 const char *old_path
,
1927 * The working directory at which the resolution of the new path starts.
1931 * The destination path to which to rename the file or directory.
1933 const char *new_path
1934 ) __attribute__((__warn_unused_result__
));
1936 * Create a symbolic link.
1937 * Note: This is similar to `symlinkat` in POSIX.
1939 __wasi_errno_t
__wasi_path_symlink(
1941 * The contents of the symbolic link.
1943 const char *old_path
,
1946 * The destination path at which to create the symbolic link.
1948 const char *new_path
1949 ) __attribute__((__warn_unused_result__
));
1952 * Return `errno::isdir` if the path refers to a directory.
1953 * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
1955 __wasi_errno_t
__wasi_path_unlink_file(
1958 * The path to a file to unlink.
1961 ) __attribute__((__warn_unused_result__
));
1963 * Concurrently poll for the occurrence of a set of events.
1965 * The number of events stored.
1967 __wasi_errno_t
__wasi_poll_oneoff(
1969 * The events to which to subscribe.
1971 const __wasi_subscription_t
* in
,
1973 * The events that have occurred.
1975 __wasi_event_t
* out
,
1977 * Both the number of subscriptions and events.
1979 __wasi_size_t nsubscriptions
,
1980 __wasi_size_t
*retptr0
1981 ) __attribute__((__warn_unused_result__
));
1983 * Terminate the process normally. An exit code of 0 indicates successful
1984 * termination of the program. The meanings of other values is dependent on
1987 _Noreturn
void __wasi_proc_exit(
1989 * The exit code returned by the process.
1991 __wasi_exitcode_t rval
1994 * Temporarily yield execution of the calling thread.
1995 * Note: This is similar to `sched_yield` in POSIX.
1997 __wasi_errno_t
__wasi_sched_yield(
1999 ) __attribute__((__warn_unused_result__
));
2001 * Write high-quality random data into a buffer.
2002 * This function blocks when the implementation is unable to immediately
2003 * provide sufficient high-quality random data.
2004 * This function may execute slowly, so when large mounts of random data are
2005 * required, it's advisable to use this function to seed a pseudo-random
2006 * number generator, rather than to provide the random data directly.
2008 __wasi_errno_t
__wasi_random_get(
2010 * The buffer to fill with random data.
2013 __wasi_size_t buf_len
2014 ) __attribute__((__warn_unused_result__
));
2016 * Accept a new incoming connection.
2017 * Note: This is similar to `accept` in POSIX.
2019 * New socket connection
2021 __wasi_errno_t
__wasi_sock_accept(
2023 * The listening socket.
2027 * The desired values of the file descriptor flags.
2029 __wasi_fdflags_t flags
,
2030 __wasi_fd_t
*retptr0
2031 ) __attribute__((__warn_unused_result__
));
2033 * Receive a message from a socket.
2034 * Note: This is similar to `recv` in POSIX, though it also supports reading
2035 * the data into multiple buffers in the manner of `readv`.
2037 * Number of bytes stored in ri_data and message flags.
2039 __wasi_errno_t
__wasi_sock_recv(
2042 * List of scatter/gather vectors to which to store data.
2044 const __wasi_iovec_t
*ri_data
,
2046 * The length of the array pointed to by `ri_data`.
2052 __wasi_riflags_t ri_flags
,
2053 __wasi_size_t
*retptr0
,
2054 __wasi_roflags_t
*retptr1
2055 ) __attribute__((__warn_unused_result__
));
2057 * Send a message on a socket.
2058 * Note: This is similar to `send` in POSIX, though it also supports writing
2059 * the data from multiple buffers in the manner of `writev`.
2061 * Number of bytes transmitted.
2063 __wasi_errno_t
__wasi_sock_send(
2066 * List of scatter/gather vectors to which to retrieve data
2068 const __wasi_ciovec_t
*si_data
,
2070 * The length of the array pointed to by `si_data`.
2076 __wasi_siflags_t si_flags
,
2077 __wasi_size_t
*retptr0
2078 ) __attribute__((__warn_unused_result__
));
2080 * Shut down socket send and receive channels.
2081 * Note: This is similar to `shutdown` in POSIX.
2083 __wasi_errno_t
__wasi_sock_shutdown(
2086 * Which channels on the socket to shut down.
2088 __wasi_sdflags_t how
2089 ) __attribute__((__warn_unused_result__
));
2094 * Request a new thread to be created by the host.
2096 * The host will create a new instance of the current module sharing its
2097 * memory, find an exported entry function--`wasi_thread_start`--, and call the
2098 * entry function with `start_arg` in the new thread.
2100 * @see https://github.com/WebAssembly/wasi-threads/#readme
2102 int32_t __wasi_thread_spawn(
2104 * A pointer to an opaque struct to be passed to the module's entry
2108 ) __attribute__((__warn_unused_result__
));