]> git.proxmox.com Git - wasi-libc.git/blobdiff - libc-bottom-half/headers/public/wasi/api.h
__wasi_thread_spawn: stop truncating the return value (#353)
[wasi-libc.git] / libc-bottom-half / headers / public / wasi / api.h
index 0745241eea62d1b1938e355e5fa4f525ea51a5d4..45a6506e2ffa022e081bea9aa8e14cf8b7c4da5a 100644 (file)
@@ -1,14 +1,19 @@
 /**
- * THIS FILE IS AUTO-GENERATED!
+ * <wasi/api.h>. This file contains declarations describing the WASI ABI
+ * as of "snapshot preview1". It was originally auto-generated from
+ * wasi_snapshot_preview1.witx, however WASI is in the process of
+ * transitioning to a new IDL and header file generator, and this file
+ * is temporarily being manually maintained.
  *
  * @file
- * This file describes the WASI interface, consisting of functions, types,
+ * This file describes the [WASI] interface, consisting of functions, types,
  * and defined values (macros).
  *
  * The interface described here is greatly inspired by [CloudABI]'s clean,
- * thoughtfully-designed, cabability-oriented, POSIX-style API.
+ * thoughtfully-designed, capability-oriented, POSIX-style API.
  *
  * [CloudABI]: https://github.com/NuxiNL/cloudlibc
+ * [WASI]: https://github.com/WebAssembly/WASI/
  */
 
 #ifndef __wasi_api_h
 #error <wasi/api.h> is only supported on WASI platforms.
 #endif
 
+#ifndef __wasm32__
+#error <wasi/api.h> only supports wasm32; doesn't yet support wasm64
+#endif
+
 #include <stddef.h>
 #include <stdint.h>
 
@@ -29,6 +38,7 @@ _Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout");
 _Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout");
 _Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout");
 _Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout");
+_Static_assert(_Alignof(void*) == 4, "non-wasi data layout");
 
 #ifdef __cplusplus
 extern "C" {
@@ -38,16 +48,25 @@ extern "C" {
 #define __WASI_DIRCOOKIE_START (UINT64_C(0))
 typedef __SIZE_TYPE__ __wasi_size_t;
 
+_Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_size_t) == 4, "witx calculated align");
+
 /**
  * Non-negative file size or length of a region within a file.
  */
 typedef uint64_t __wasi_filesize_t;
 
+_Static_assert(sizeof(__wasi_filesize_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_filesize_t) == 8, "witx calculated align");
+
 /**
  * Timestamp in nanoseconds.
  */
 typedef uint64_t __wasi_timestamp_t;
 
+_Static_assert(sizeof(__wasi_timestamp_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_timestamp_t) == 8, "witx calculated align");
+
 /**
  * Identifiers for clocks.
  */
@@ -57,7 +76,7 @@ typedef uint32_t __wasi_clockid_t;
  * The clock measuring real time. Time value zero corresponds with
  * 1970-01-01T00:00:00Z.
  */
-#define __WASI_CLOCKID_REALTIME ((__wasi_clockid_t)0)
+#define __WASI_CLOCKID_REALTIME (UINT32_C(0))
 
 /**
  * The store-wide monotonic clock, which is defined as a clock measuring
@@ -65,17 +84,20 @@ typedef uint32_t __wasi_clockid_t;
  * clock jumps. The epoch of this clock is undefined. The absolute time
  * value of this clock therefore has no meaning.
  */
-#define __WASI_CLOCKID_MONOTONIC ((__wasi_clockid_t)1)
+#define __WASI_CLOCKID_MONOTONIC (UINT32_C(1))
 
 /**
  * The CPU-time clock associated with the current process.
  */
-#define __WASI_CLOCKID_PROCESS_CPUTIME_ID ((__wasi_clockid_t)2)
+#define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2))
 
 /**
  * The CPU-time clock associated with the current thread.
  */
-#define __WASI_CLOCKID_THREAD_CPUTIME_ID ((__wasi_clockid_t)3)
+#define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3))
+
+_Static_assert(sizeof(__wasi_clockid_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_clockid_t) == 4, "witx calculated align");
 
 /**
  * Error codes returned by functions.
@@ -88,387 +110,390 @@ typedef uint16_t __wasi_errno_t;
 /**
  * No error occurred. System call completed successfully.
  */
-#define __WASI_ERRNO_SUCCESS ((__wasi_errno_t)0)
+#define __WASI_ERRNO_SUCCESS (UINT16_C(0))
 
 /**
  * Argument list too long.
  */
-#define __WASI_ERRNO_2BIG ((__wasi_errno_t)1)
+#define __WASI_ERRNO_2BIG (UINT16_C(1))
 
 /**
  * Permission denied.
  */
-#define __WASI_ERRNO_ACCES ((__wasi_errno_t)2)
+#define __WASI_ERRNO_ACCES (UINT16_C(2))
 
 /**
  * Address in use.
  */
-#define __WASI_ERRNO_ADDRINUSE ((__wasi_errno_t)3)
+#define __WASI_ERRNO_ADDRINUSE (UINT16_C(3))
 
 /**
  * Address not available.
  */
-#define __WASI_ERRNO_ADDRNOTAVAIL ((__wasi_errno_t)4)
+#define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4))
 
 /**
  * Address family not supported.
  */
-#define __WASI_ERRNO_AFNOSUPPORT ((__wasi_errno_t)5)
+#define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5))
 
 /**
  * Resource unavailable, or operation would block.
  */
-#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
+#define __WASI_ERRNO_AGAIN (UINT16_C(6))
 
 /**
  * Connection already in progress.
  */
-#define __WASI_ERRNO_ALREADY ((__wasi_errno_t)7)
+#define __WASI_ERRNO_ALREADY (UINT16_C(7))
 
 /**
  * Bad file descriptor.
  */
-#define __WASI_ERRNO_BADF ((__wasi_errno_t)8)
+#define __WASI_ERRNO_BADF (UINT16_C(8))
 
 /**
  * Bad message.
  */
-#define __WASI_ERRNO_BADMSG ((__wasi_errno_t)9)
+#define __WASI_ERRNO_BADMSG (UINT16_C(9))
 
 /**
  * Device or resource busy.
  */
-#define __WASI_ERRNO_BUSY ((__wasi_errno_t)10)
+#define __WASI_ERRNO_BUSY (UINT16_C(10))
 
 /**
  * Operation canceled.
  */
-#define __WASI_ERRNO_CANCELED ((__wasi_errno_t)11)
+#define __WASI_ERRNO_CANCELED (UINT16_C(11))
 
 /**
  * No child processes.
  */
-#define __WASI_ERRNO_CHILD ((__wasi_errno_t)12)
+#define __WASI_ERRNO_CHILD (UINT16_C(12))
 
 /**
  * Connection aborted.
  */
-#define __WASI_ERRNO_CONNABORTED ((__wasi_errno_t)13)
+#define __WASI_ERRNO_CONNABORTED (UINT16_C(13))
 
 /**
  * Connection refused.
  */
-#define __WASI_ERRNO_CONNREFUSED ((__wasi_errno_t)14)
+#define __WASI_ERRNO_CONNREFUSED (UINT16_C(14))
 
 /**
  * Connection reset.
  */
-#define __WASI_ERRNO_CONNRESET ((__wasi_errno_t)15)
+#define __WASI_ERRNO_CONNRESET (UINT16_C(15))
 
 /**
  * Resource deadlock would occur.
  */
-#define __WASI_ERRNO_DEADLK ((__wasi_errno_t)16)
+#define __WASI_ERRNO_DEADLK (UINT16_C(16))
 
 /**
  * Destination address required.
  */
-#define __WASI_ERRNO_DESTADDRREQ ((__wasi_errno_t)17)
+#define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17))
 
 /**
  * Mathematics argument out of domain of function.
  */
-#define __WASI_ERRNO_DOM ((__wasi_errno_t)18)
+#define __WASI_ERRNO_DOM (UINT16_C(18))
 
 /**
  * Reserved.
  */
-#define __WASI_ERRNO_DQUOT ((__wasi_errno_t)19)
+#define __WASI_ERRNO_DQUOT (UINT16_C(19))
 
 /**
  * File exists.
  */
-#define __WASI_ERRNO_EXIST ((__wasi_errno_t)20)
+#define __WASI_ERRNO_EXIST (UINT16_C(20))
 
 /**
  * Bad address.
  */
-#define __WASI_ERRNO_FAULT ((__wasi_errno_t)21)
+#define __WASI_ERRNO_FAULT (UINT16_C(21))
 
 /**
  * File too large.
  */
-#define __WASI_ERRNO_FBIG ((__wasi_errno_t)22)
+#define __WASI_ERRNO_FBIG (UINT16_C(22))
 
 /**
  * Host is unreachable.
  */
-#define __WASI_ERRNO_HOSTUNREACH ((__wasi_errno_t)23)
+#define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23))
 
 /**
  * Identifier removed.
  */
-#define __WASI_ERRNO_IDRM ((__wasi_errno_t)24)
+#define __WASI_ERRNO_IDRM (UINT16_C(24))
 
 /**
  * Illegal byte sequence.
  */
-#define __WASI_ERRNO_ILSEQ ((__wasi_errno_t)25)
+#define __WASI_ERRNO_ILSEQ (UINT16_C(25))
 
 /**
  * Operation in progress.
  */
-#define __WASI_ERRNO_INPROGRESS ((__wasi_errno_t)26)
+#define __WASI_ERRNO_INPROGRESS (UINT16_C(26))
 
 /**
  * Interrupted function.
  */
-#define __WASI_ERRNO_INTR ((__wasi_errno_t)27)
+#define __WASI_ERRNO_INTR (UINT16_C(27))
 
 /**
  * Invalid argument.
  */
-#define __WASI_ERRNO_INVAL ((__wasi_errno_t)28)
+#define __WASI_ERRNO_INVAL (UINT16_C(28))
 
 /**
  * I/O error.
  */
-#define __WASI_ERRNO_IO ((__wasi_errno_t)29)
+#define __WASI_ERRNO_IO (UINT16_C(29))
 
 /**
  * Socket is connected.
  */
-#define __WASI_ERRNO_ISCONN ((__wasi_errno_t)30)
+#define __WASI_ERRNO_ISCONN (UINT16_C(30))
 
 /**
  * Is a directory.
  */
-#define __WASI_ERRNO_ISDIR ((__wasi_errno_t)31)
+#define __WASI_ERRNO_ISDIR (UINT16_C(31))
 
 /**
  * Too many levels of symbolic links.
  */
-#define __WASI_ERRNO_LOOP ((__wasi_errno_t)32)
+#define __WASI_ERRNO_LOOP (UINT16_C(32))
 
 /**
  * File descriptor value too large.
  */
-#define __WASI_ERRNO_MFILE ((__wasi_errno_t)33)
+#define __WASI_ERRNO_MFILE (UINT16_C(33))
 
 /**
  * Too many links.
  */
-#define __WASI_ERRNO_MLINK ((__wasi_errno_t)34)
+#define __WASI_ERRNO_MLINK (UINT16_C(34))
 
 /**
  * Message too large.
  */
-#define __WASI_ERRNO_MSGSIZE ((__wasi_errno_t)35)
+#define __WASI_ERRNO_MSGSIZE (UINT16_C(35))
 
 /**
  * Reserved.
  */
-#define __WASI_ERRNO_MULTIHOP ((__wasi_errno_t)36)
+#define __WASI_ERRNO_MULTIHOP (UINT16_C(36))
 
 /**
  * Filename too long.
  */
-#define __WASI_ERRNO_NAMETOOLONG ((__wasi_errno_t)37)
+#define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37))
 
 /**
  * Network is down.
  */
-#define __WASI_ERRNO_NETDOWN ((__wasi_errno_t)38)
+#define __WASI_ERRNO_NETDOWN (UINT16_C(38))
 
 /**
  * Connection aborted by network.
  */
-#define __WASI_ERRNO_NETRESET ((__wasi_errno_t)39)
+#define __WASI_ERRNO_NETRESET (UINT16_C(39))
 
 /**
  * Network unreachable.
  */
-#define __WASI_ERRNO_NETUNREACH ((__wasi_errno_t)40)
+#define __WASI_ERRNO_NETUNREACH (UINT16_C(40))
 
 /**
  * Too many files open in system.
  */
-#define __WASI_ERRNO_NFILE ((__wasi_errno_t)41)
+#define __WASI_ERRNO_NFILE (UINT16_C(41))
 
 /**
  * No buffer space available.
  */
-#define __WASI_ERRNO_NOBUFS ((__wasi_errno_t)42)
+#define __WASI_ERRNO_NOBUFS (UINT16_C(42))
 
 /**
  * No such device.
  */
-#define __WASI_ERRNO_NODEV ((__wasi_errno_t)43)
+#define __WASI_ERRNO_NODEV (UINT16_C(43))
 
 /**
  * No such file or directory.
  */
-#define __WASI_ERRNO_NOENT ((__wasi_errno_t)44)
+#define __WASI_ERRNO_NOENT (UINT16_C(44))
 
 /**
  * Executable file format error.
  */
-#define __WASI_ERRNO_NOEXEC ((__wasi_errno_t)45)
+#define __WASI_ERRNO_NOEXEC (UINT16_C(45))
 
 /**
  * No locks available.
  */
-#define __WASI_ERRNO_NOLCK ((__wasi_errno_t)46)
+#define __WASI_ERRNO_NOLCK (UINT16_C(46))
 
 /**
  * Reserved.
  */
-#define __WASI_ERRNO_NOLINK ((__wasi_errno_t)47)
+#define __WASI_ERRNO_NOLINK (UINT16_C(47))
 
 /**
  * Not enough space.
  */
-#define __WASI_ERRNO_NOMEM ((__wasi_errno_t)48)
+#define __WASI_ERRNO_NOMEM (UINT16_C(48))
 
 /**
  * No message of the desired type.
  */
-#define __WASI_ERRNO_NOMSG ((__wasi_errno_t)49)
+#define __WASI_ERRNO_NOMSG (UINT16_C(49))
 
 /**
  * Protocol not available.
  */
-#define __WASI_ERRNO_NOPROTOOPT ((__wasi_errno_t)50)
+#define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50))
 
 /**
  * No space left on device.
  */
-#define __WASI_ERRNO_NOSPC ((__wasi_errno_t)51)
+#define __WASI_ERRNO_NOSPC (UINT16_C(51))
 
 /**
  * Function not supported.
  */
-#define __WASI_ERRNO_NOSYS ((__wasi_errno_t)52)
+#define __WASI_ERRNO_NOSYS (UINT16_C(52))
 
 /**
  * The socket is not connected.
  */
-#define __WASI_ERRNO_NOTCONN ((__wasi_errno_t)53)
+#define __WASI_ERRNO_NOTCONN (UINT16_C(53))
 
 /**
  * Not a directory or a symbolic link to a directory.
  */
-#define __WASI_ERRNO_NOTDIR ((__wasi_errno_t)54)
+#define __WASI_ERRNO_NOTDIR (UINT16_C(54))
 
 /**
  * Directory not empty.
  */
-#define __WASI_ERRNO_NOTEMPTY ((__wasi_errno_t)55)
+#define __WASI_ERRNO_NOTEMPTY (UINT16_C(55))
 
 /**
  * State not recoverable.
  */
-#define __WASI_ERRNO_NOTRECOVERABLE ((__wasi_errno_t)56)
+#define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56))
 
 /**
  * Not a socket.
  */
-#define __WASI_ERRNO_NOTSOCK ((__wasi_errno_t)57)
+#define __WASI_ERRNO_NOTSOCK (UINT16_C(57))
 
 /**
  * Not supported, or operation not supported on socket.
  */
-#define __WASI_ERRNO_NOTSUP ((__wasi_errno_t)58)
+#define __WASI_ERRNO_NOTSUP (UINT16_C(58))
 
 /**
  * Inappropriate I/O control operation.
  */
-#define __WASI_ERRNO_NOTTY ((__wasi_errno_t)59)
+#define __WASI_ERRNO_NOTTY (UINT16_C(59))
 
 /**
  * No such device or address.
  */
-#define __WASI_ERRNO_NXIO ((__wasi_errno_t)60)
+#define __WASI_ERRNO_NXIO (UINT16_C(60))
 
 /**
  * Value too large to be stored in data type.
  */
-#define __WASI_ERRNO_OVERFLOW ((__wasi_errno_t)61)
+#define __WASI_ERRNO_OVERFLOW (UINT16_C(61))
 
 /**
  * Previous owner died.
  */
-#define __WASI_ERRNO_OWNERDEAD ((__wasi_errno_t)62)
+#define __WASI_ERRNO_OWNERDEAD (UINT16_C(62))
 
 /**
  * Operation not permitted.
  */
-#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)
+#define __WASI_ERRNO_PERM (UINT16_C(63))
 
 /**
  * Broken pipe.
  */
-#define __WASI_ERRNO_PIPE ((__wasi_errno_t)64)
+#define __WASI_ERRNO_PIPE (UINT16_C(64))
 
 /**
  * Protocol error.
  */
-#define __WASI_ERRNO_PROTO ((__wasi_errno_t)65)
+#define __WASI_ERRNO_PROTO (UINT16_C(65))
 
 /**
  * Protocol not supported.
  */
-#define __WASI_ERRNO_PROTONOSUPPORT ((__wasi_errno_t)66)
+#define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66))
 
 /**
  * Protocol wrong type for socket.
  */
-#define __WASI_ERRNO_PROTOTYPE ((__wasi_errno_t)67)
+#define __WASI_ERRNO_PROTOTYPE (UINT16_C(67))
 
 /**
  * Result too large.
  */
-#define __WASI_ERRNO_RANGE ((__wasi_errno_t)68)
+#define __WASI_ERRNO_RANGE (UINT16_C(68))
 
 /**
  * Read-only file system.
  */
-#define __WASI_ERRNO_ROFS ((__wasi_errno_t)69)
+#define __WASI_ERRNO_ROFS (UINT16_C(69))
 
 /**
  * Invalid seek.
  */
-#define __WASI_ERRNO_SPIPE ((__wasi_errno_t)70)
+#define __WASI_ERRNO_SPIPE (UINT16_C(70))
 
 /**
  * No such process.
  */
-#define __WASI_ERRNO_SRCH ((__wasi_errno_t)71)
+#define __WASI_ERRNO_SRCH (UINT16_C(71))
 
 /**
  * Reserved.
  */
-#define __WASI_ERRNO_STALE ((__wasi_errno_t)72)
+#define __WASI_ERRNO_STALE (UINT16_C(72))
 
 /**
  * Connection timed out.
  */
-#define __WASI_ERRNO_TIMEDOUT ((__wasi_errno_t)73)
+#define __WASI_ERRNO_TIMEDOUT (UINT16_C(73))
 
 /**
  * Text file busy.
  */
-#define __WASI_ERRNO_TXTBSY ((__wasi_errno_t)74)
+#define __WASI_ERRNO_TXTBSY (UINT16_C(74))
 
 /**
  * Cross-device link.
  */
-#define __WASI_ERRNO_XDEV ((__wasi_errno_t)75)
+#define __WASI_ERRNO_XDEV (UINT16_C(75))
 
 /**
  * Extension: Capabilities insufficient.
  */
-#define __WASI_ERRNO_NOTCAPABLE ((__wasi_errno_t)76)
+#define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76))
+
+_Static_assert(sizeof(__wasi_errno_t) == 2, "witx calculated size");
+_Static_assert(_Alignof(__wasi_errno_t) == 2, "witx calculated align");
 
 /**
  * File descriptor rights, determining which actions may be performed.
@@ -478,164 +503,172 @@ typedef uint64_t __wasi_rights_t;
 /**
  * The right to invoke `fd_datasync`.
  * If `path_open` is set, includes the right to invoke
- * `path_open` with `fdflag::dsync`.
+ * `path_open` with `fdflags::dsync`.
  */
-#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)1)
+#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0))
 
 /**
  * The right to invoke `fd_read` and `sock_recv`.
  * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`.
  */
-#define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)2)
+#define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1))
 
 /**
  * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
  */
-#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)4)
+#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2))
 
 /**
  * The right to invoke `fd_fdstat_set_flags`.
  */
-#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)8)
+#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3))
 
 /**
  * The right to invoke `fd_sync`.
  * If `path_open` is set, includes the right to invoke
- * `path_open` with `fdflag::rsync` and `fdflag::dsync`.
+ * `path_open` with `fdflags::rsync` and `fdflags::dsync`.
  */
-#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)16)
+#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4))
 
 /**
  * The right to invoke `fd_seek` in such a way that the file offset
- * remains unaltered (i.e., `WHENCE_CUR` with offset zero), or to
+ * remains unaltered (i.e., `whence::cur` with offset zero), or to
  * invoke `fd_tell`.
  */
-#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)32)
+#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5))
 
 /**
  * The right to invoke `fd_write` and `sock_send`.
  * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`.
  */
-#define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)64)
+#define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6))
 
 /**
  * The right to invoke `fd_advise`.
  */
-#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)128)
+#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7))
 
 /**
  * The right to invoke `fd_allocate`.
  */
-#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)256)
+#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8))
 
 /**
  * The right to invoke `path_create_directory`.
  */
-#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)512)
+#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9))
 
 /**
  * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
  */
-#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)1024)
+#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10))
 
 /**
  * The right to invoke `path_link` with the file descriptor as the
  * source directory.
  */
-#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)2048)
+#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11))
 
 /**
  * The right to invoke `path_link` with the file descriptor as the
  * target directory.
  */
-#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)4096)
+#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12))
 
 /**
  * The right to invoke `path_open`.
  */
-#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)8192)
+#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13))
 
 /**
  * The right to invoke `fd_readdir`.
  */
-#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)16384)
+#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14))
 
 /**
  * The right to invoke `path_readlink`.
  */
-#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)32768)
+#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15))
 
 /**
  * The right to invoke `path_rename` with the file descriptor as the source directory.
  */
-#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)65536)
+#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16))
 
 /**
  * The right to invoke `path_rename` with the file descriptor as the target directory.
  */
-#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)131072)
+#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17))
 
 /**
  * The right to invoke `path_filestat_get`.
  */
-#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)262144)
+#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18))
 
 /**
  * The right to change a file's size (there is no `path_filestat_set_size`).
  * If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`.
  */
-#define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)524288)
+#define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19))
 
 /**
  * The right to invoke `path_filestat_set_times`.
  */
-#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)1048576)
+#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20))
 
 /**
  * The right to invoke `fd_filestat_get`.
  */
-#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)2097152)
+#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21))
 
 /**
  * The right to invoke `fd_filestat_set_size`.
  */
-#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)4194304)
+#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22))
 
 /**
  * The right to invoke `fd_filestat_set_times`.
  */
-#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)8388608)
+#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23))
 
 /**
  * The right to invoke `path_symlink`.
  */
-#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)16777216)
+#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24))
 
 /**
  * The right to invoke `path_remove_directory`.
  */
-#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)33554432)
+#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25))
 
 /**
  * The right to invoke `path_unlink_file`.
  */
-#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)67108864)
+#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26))
 
 /**
  * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`.
  * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`.
  */
-#define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)134217728)
+#define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27))
 
 /**
  * The right to invoke `sock_shutdown`.
  */
-#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)268435456)
+#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28))
 
 /**
- * A file descriptor index.
+ * The right to invoke `sock_accept`.
  */
-typedef uint32_t __wasi_fd_t;
+#define __WASI_RIGHTS_SOCK_ACCEPT ((__wasi_rights_t)(1 << 29))
+
+/**
+ * A file descriptor handle.
+ */
+typedef int __wasi_fd_t;
+
+_Static_assert(sizeof(__wasi_fd_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_fd_t) == 4, "witx calculated align");
 
 /**
  * A region of memory for scatter/gather reads.
@@ -653,6 +686,11 @@ typedef struct __wasi_iovec_t {
 
 } __wasi_iovec_t;
 
+_Static_assert(sizeof(__wasi_iovec_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_iovec_t) == 4, "witx calculated align");
+_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_iovec_t, buf_len) == 4, "witx calculated offset");
+
 /**
  * A region of memory for scatter/gather writes.
  */
@@ -669,11 +707,19 @@ typedef struct __wasi_ciovec_t {
 
 } __wasi_ciovec_t;
 
+_Static_assert(sizeof(__wasi_ciovec_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_ciovec_t) == 4, "witx calculated align");
+_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_ciovec_t, buf_len) == 4, "witx calculated offset");
+
 /**
  * Relative offset within a file.
  */
 typedef int64_t __wasi_filedelta_t;
 
+_Static_assert(sizeof(__wasi_filedelta_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_filedelta_t) == 8, "witx calculated align");
+
 /**
  * The position relative to which to set the offset of the file descriptor.
  */
@@ -682,17 +728,20 @@ typedef uint8_t __wasi_whence_t;
 /**
  * Seek relative to start-of-file.
  */
-#define __WASI_WHENCE_SET ((__wasi_whence_t)0)
+#define __WASI_WHENCE_SET (UINT8_C(0))
 
 /**
  * Seek relative to current position.
  */
-#define __WASI_WHENCE_CUR ((__wasi_whence_t)1)
+#define __WASI_WHENCE_CUR (UINT8_C(1))
 
 /**
  * Seek relative to end-of-file.
  */
-#define __WASI_WHENCE_END ((__wasi_whence_t)2)
+#define __WASI_WHENCE_END (UINT8_C(2))
+
+_Static_assert(sizeof(__wasi_whence_t) == 1, "witx calculated size");
+_Static_assert(_Alignof(__wasi_whence_t) == 1, "witx calculated align");
 
 /**
  * A reference to the offset of a directory entry.
@@ -701,16 +750,25 @@ typedef uint8_t __wasi_whence_t;
  */
 typedef uint64_t __wasi_dircookie_t;
 
+_Static_assert(sizeof(__wasi_dircookie_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_dircookie_t) == 8, "witx calculated align");
+
 /**
- * The type for the $d_namlen field of $dirent.
+ * The type for the `dirent::d_namlen` field of `dirent` struct.
  */
 typedef uint32_t __wasi_dirnamlen_t;
 
+_Static_assert(sizeof(__wasi_dirnamlen_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_dirnamlen_t) == 4, "witx calculated align");
+
 /**
  * File serial number that is unique within its file system.
  */
 typedef uint64_t __wasi_inode_t;
 
+_Static_assert(sizeof(__wasi_inode_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_inode_t) == 8, "witx calculated align");
+
 /**
  * The type of a file descriptor or file.
  */
@@ -719,42 +777,45 @@ typedef uint8_t __wasi_filetype_t;
 /**
  * The type of the file descriptor or file is unknown or is different from any of the other types specified.
  */
-#define __WASI_FILETYPE_UNKNOWN ((__wasi_filetype_t)0)
+#define __WASI_FILETYPE_UNKNOWN (UINT8_C(0))
 
 /**
  * The file descriptor or file refers to a block device inode.
  */
-#define __WASI_FILETYPE_BLOCK_DEVICE ((__wasi_filetype_t)1)
+#define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1))
 
 /**
  * The file descriptor or file refers to a character device inode.
  */
-#define __WASI_FILETYPE_CHARACTER_DEVICE ((__wasi_filetype_t)2)
+#define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2))
 
 /**
  * The file descriptor or file refers to a directory inode.
  */
-#define __WASI_FILETYPE_DIRECTORY ((__wasi_filetype_t)3)
+#define __WASI_FILETYPE_DIRECTORY (UINT8_C(3))
 
 /**
  * The file descriptor or file refers to a regular file inode.
  */
-#define __WASI_FILETYPE_REGULAR_FILE ((__wasi_filetype_t)4)
+#define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4))
 
 /**
  * The file descriptor or file refers to a datagram socket.
  */
-#define __WASI_FILETYPE_SOCKET_DGRAM ((__wasi_filetype_t)5)
+#define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5))
 
 /**
  * The file descriptor or file refers to a byte-stream socket.
  */
-#define __WASI_FILETYPE_SOCKET_STREAM ((__wasi_filetype_t)6)
+#define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6))
 
 /**
  * The file refers to a symbolic link inode.
  */
-#define __WASI_FILETYPE_SYMBOLIC_LINK ((__wasi_filetype_t)7)
+#define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7))
+
+_Static_assert(sizeof(__wasi_filetype_t) == 1, "witx calculated size");
+_Static_assert(_Alignof(__wasi_filetype_t) == 1, "witx calculated align");
 
 /**
  * A directory entry.
@@ -782,6 +843,13 @@ typedef struct __wasi_dirent_t {
 
 } __wasi_dirent_t;
 
+_Static_assert(sizeof(__wasi_dirent_t) == 24, "witx calculated size");
+_Static_assert(_Alignof(__wasi_dirent_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "witx calculated offset");
+_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "witx calculated offset");
+_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "witx calculated offset");
+
 /**
  * File or memory access pattern advisory information.
  */
@@ -790,32 +858,35 @@ typedef uint8_t __wasi_advice_t;
 /**
  * The application has no advice to give on its behavior with respect to the specified data.
  */
-#define __WASI_ADVICE_NORMAL ((__wasi_advice_t)0)
+#define __WASI_ADVICE_NORMAL (UINT8_C(0))
 
 /**
  * The application expects to access the specified data sequentially from lower offsets to higher offsets.
  */
-#define __WASI_ADVICE_SEQUENTIAL ((__wasi_advice_t)1)
+#define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1))
 
 /**
  * The application expects to access the specified data in a random order.
  */
-#define __WASI_ADVICE_RANDOM ((__wasi_advice_t)2)
+#define __WASI_ADVICE_RANDOM (UINT8_C(2))
 
 /**
  * The application expects to access the specified data in the near future.
  */
-#define __WASI_ADVICE_WILLNEED ((__wasi_advice_t)3)
+#define __WASI_ADVICE_WILLNEED (UINT8_C(3))
 
 /**
  * The application expects that it will not access the specified data in the near future.
  */
-#define __WASI_ADVICE_DONTNEED ((__wasi_advice_t)4)
+#define __WASI_ADVICE_DONTNEED (UINT8_C(4))
 
 /**
  * The application expects to access the specified data once and then not reuse it thereafter.
  */
-#define __WASI_ADVICE_NOREUSE ((__wasi_advice_t)5)
+#define __WASI_ADVICE_NOREUSE (UINT8_C(5))
+
+_Static_assert(sizeof(__wasi_advice_t) == 1, "witx calculated size");
+_Static_assert(_Alignof(__wasi_advice_t) == 1, "witx calculated align");
 
 /**
  * File descriptor flags.
@@ -825,29 +896,29 @@ typedef uint16_t __wasi_fdflags_t;
 /**
  * Append mode: Data written to the file is always appended to the file's end.
  */
-#define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)1)
+#define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)(1 << 0))
 
 /**
  * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized.
  */
-#define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)2)
+#define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1))
 
 /**
  * Non-blocking mode.
  */
-#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)4)
+#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2))
 
 /**
  * Synchronized read I/O operations.
  */
-#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)8)
+#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3))
 
 /**
  * Write according to synchronized I/O file integrity completion. In
  * addition to synchronizing the data stored in the file, the implementation
  * may also synchronously update the file's metadata.
  */
-#define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)16)
+#define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4))
 
 /**
  * File descriptor attributes.
@@ -876,36 +947,46 @@ typedef struct __wasi_fdstat_t {
 
 } __wasi_fdstat_t;
 
+_Static_assert(sizeof(__wasi_fdstat_t) == 24, "witx calculated size");
+_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_fdstat_t, fs_filetype) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "witx calculated offset");
+_Static_assert(offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "witx calculated offset");
+_Static_assert(offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16, "witx calculated offset");
+
 /**
  * Identifier for a device containing a file system. Can be used in combination
  * with `inode` to uniquely identify a file or directory in the filesystem.
  */
 typedef uint64_t __wasi_device_t;
 
+_Static_assert(sizeof(__wasi_device_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_device_t) == 8, "witx calculated align");
+
 /**
  * Which file time attributes to adjust.
  */
 typedef uint16_t __wasi_fstflags_t;
 
 /**
- * Adjust the last data access timestamp to the value stored in `filestat::st_atim`.
+ * Adjust the last data access timestamp to the value stored in `filestat::atim`.
  */
-#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)1)
+#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0))
 
 /**
- * Adjust the last data access timestamp to the time of clock `clock::realtime`.
+ * Adjust the last data access timestamp to the time of clock `clockid::realtime`.
  */
-#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)2)
+#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1))
 
 /**
- * Adjust the last data modification timestamp to the value stored in `filestat::st_mtim`.
+ * Adjust the last data modification timestamp to the value stored in `filestat::mtim`.
  */
-#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)4)
+#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2))
 
 /**
- * Adjust the last data modification timestamp to the time of clock `clock::realtime`.
+ * Adjust the last data modification timestamp to the time of clock `clockid::realtime`.
  */
-#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)8)
+#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3))
 
 /**
  * Flags determining the method of how paths are resolved.
@@ -915,7 +996,7 @@ typedef uint32_t __wasi_lookupflags_t;
 /**
  * As long as the resolved path corresponds to a symbolic link, it is expanded.
  */
-#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)1)
+#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0))
 
 /**
  * Open flags used by `path_open`.
@@ -925,28 +1006,31 @@ typedef uint16_t __wasi_oflags_t;
 /**
  * Create file if it does not exist.
  */
-#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)1)
+#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0))
 
 /**
  * Fail if not a directory.
  */
-#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)2)
+#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1))
 
 /**
  * Fail if file already exists.
  */
-#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)4)
+#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2))
 
 /**
  * Truncate file to size 0.
  */
-#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)8)
+#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3))
 
 /**
  * Number of hard links to an inode.
  */
 typedef uint64_t __wasi_linkcount_t;
 
+_Static_assert(sizeof(__wasi_linkcount_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_linkcount_t) == 8, "witx calculated align");
+
 /**
  * File attributes.
  */
@@ -993,34 +1077,51 @@ typedef struct __wasi_filestat_t {
 
 } __wasi_filestat_t;
 
+_Static_assert(sizeof(__wasi_filestat_t) == 64, "witx calculated size");
+_Static_assert(_Alignof(__wasi_filestat_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_filestat_t, dev) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, ino) == 8, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, filetype) == 16, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, nlink) == 24, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, size) == 32, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, atim) == 40, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, mtim) == 48, "witx calculated offset");
+_Static_assert(offsetof(__wasi_filestat_t, ctim) == 56, "witx calculated offset");
+
 /**
  * User-provided value that may be attached to objects that is retained when
  * extracted from the implementation.
  */
 typedef uint64_t __wasi_userdata_t;
 
+_Static_assert(sizeof(__wasi_userdata_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_userdata_t) == 8, "witx calculated align");
+
 /**
  * Type of a subscription to an event or its occurrence.
  */
 typedef uint8_t __wasi_eventtype_t;
 
 /**
- * The time value of clock `subscription::u.clock.clock_id` has
- * reached timestamp `subscription::u.clock.timeout`.
+ * The time value of clock `subscription_clock::id` has
+ * reached timestamp `subscription_clock::timeout`.
  */
-#define __WASI_EVENTTYPE_CLOCK ((__wasi_eventtype_t)0)
+#define __WASI_EVENTTYPE_CLOCK (UINT8_C(0))
 
 /**
- * File descriptor `subscription::u.fd_readwrite.fd` has data
+ * File descriptor `subscription_fd_readwrite::file_descriptor` has data
  * available for reading. This event always triggers for regular files.
  */
-#define __WASI_EVENTTYPE_FD_READ ((__wasi_eventtype_t)1)
+#define __WASI_EVENTTYPE_FD_READ (UINT8_C(1))
 
 /**
- * File descriptor `subscription::u.fd_readwrite.fd` has capacity
+ * File descriptor `subscription_fd_readwrite::file_descriptor` has capacity
  * available for writing. This event always triggers for regular files.
  */
-#define __WASI_EVENTTYPE_FD_WRITE ((__wasi_eventtype_t)2)
+#define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2))
+
+_Static_assert(sizeof(__wasi_eventtype_t) == 1, "witx calculated size");
+_Static_assert(_Alignof(__wasi_eventtype_t) == 1, "witx calculated align");
 
 /**
  * The state of the file descriptor subscribed to with
@@ -1031,10 +1132,10 @@ typedef uint16_t __wasi_eventrwflags_t;
 /**
  * The peer of this socket has closed or disconnected.
  */
-#define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)1)
+#define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)(1 << 0))
 
 /**
- * The contents of an $event when type is `eventtype::fd_read` or
+ * The contents of an `event` when type is `eventtype::fd_read` or
  * `eventtype::fd_write`.
  */
 typedef struct __wasi_event_fd_readwrite_t {
@@ -1050,16 +1151,10 @@ typedef struct __wasi_event_fd_readwrite_t {
 
 } __wasi_event_fd_readwrite_t;
 
-/**
- * The contents of an $event.
- */
-typedef union __wasi_event_u_t {
-    /**
-     * When type is `eventtype::fd_read` or `eventtype::fd_write`:
-     */
-    __wasi_event_fd_readwrite_t fd_readwrite;
-
-} __wasi_event_u_t;
+_Static_assert(sizeof(__wasi_event_fd_readwrite_t) == 16, "witx calculated size");
+_Static_assert(_Alignof(__wasi_event_fd_readwrite_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_event_fd_readwrite_t, nbytes) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_event_fd_readwrite_t, flags) == 8, "witx calculated offset");
 
 /**
  * An event that occurred.
@@ -1076,34 +1171,42 @@ typedef struct __wasi_event_t {
     __wasi_errno_t error;
 
     /**
-     * The type of the event that occurred.
+     * The type of event that occured
      */
     __wasi_eventtype_t type;
 
     /**
-     * The contents of the event.
+     * The contents of the event, if it is an `eventtype::fd_read` or
+     * `eventtype::fd_write`. `eventtype::clock` events ignore this field.
      */
-    __wasi_event_u_t u;
+    __wasi_event_fd_readwrite_t fd_readwrite;
 
 } __wasi_event_t;
 
+_Static_assert(sizeof(__wasi_event_t) == 32, "witx calculated size");
+_Static_assert(_Alignof(__wasi_event_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_event_t, error) == 8, "witx calculated offset");
+_Static_assert(offsetof(__wasi_event_t, type) == 10, "witx calculated offset");
+_Static_assert(offsetof(__wasi_event_t, fd_readwrite) == 16, "witx calculated offset");
+
 /**
  * Flags determining how to interpret the timestamp provided in
- * `subscription::u.clock.timeout.`
+ * `subscription_clock::timeout`.
  */
 typedef uint16_t __wasi_subclockflags_t;
 
 /**
  * If set, treat the timestamp provided in
- * `subscription::u.clock.timeout` as an absolute timestamp of clock
- * `subscription::u.clock.clock_id.` If clear, treat the timestamp
- * provided in `subscription::u.clock.timeout` relative to the
- * current time value of clock `subscription::u.clock.clock_id.`
+ * `subscription_clock::timeout` as an absolute timestamp of clock
+ * `subscription_clock::id`. If clear, treat the timestamp
+ * provided in `subscription_clock::timeout` relative to the
+ * current time value of clock `subscription_clock::id`.
  */
-#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)1)
+#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0))
 
 /**
- * The contents of a $subscription when type is `eventtype::clock`.
+ * The contents of a `subscription` when type is `eventtype::clock`.
  */
 typedef struct __wasi_subscription_clock_t {
     /**
@@ -1129,8 +1232,15 @@ typedef struct __wasi_subscription_clock_t {
 
 } __wasi_subscription_clock_t;
 
+_Static_assert(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size");
+_Static_assert(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_subscription_clock_t, id) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset");
+_Static_assert(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset");
+_Static_assert(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset");
+
 /**
- * The contents of a $subscription when type is type is
+ * The contents of a `subscription` when type is type is
  * `eventtype::fd_read` or `eventtype::fd_write`.
  */
 typedef struct __wasi_subscription_fd_readwrite_t {
@@ -1141,22 +1251,26 @@ typedef struct __wasi_subscription_fd_readwrite_t {
 
 } __wasi_subscription_fd_readwrite_t;
 
+_Static_assert(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align");
+_Static_assert(offsetof(__wasi_subscription_fd_readwrite_t, file_descriptor) == 0, "witx calculated offset");
+
 /**
- * The contents of a $subscription.
+ * The contents of a `subscription`.
  */
-typedef union __wasi_subscription_u_t {
-    /**
-     * When type is `eventtype::clock`:
-     */
+typedef union __wasi_subscription_u_u_t {
     __wasi_subscription_clock_t clock;
-
-    /**
-     * When type is `eventtype::fd_read` or `eventtype::fd_write`:
-     */
-    __wasi_subscription_fd_readwrite_t fd_readwrite;
-
+    __wasi_subscription_fd_readwrite_t fd_read;
+    __wasi_subscription_fd_readwrite_t fd_write;
+} __wasi_subscription_u_u_t;
+typedef struct __wasi_subscription_u_t {
+    uint8_t tag;
+    __wasi_subscription_u_u_t u;
 } __wasi_subscription_u_t;
 
+_Static_assert(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size");
+_Static_assert(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align");
+
 /**
  * Subscription to an event.
  */
@@ -1168,212 +1282,24 @@ typedef struct __wasi_subscription_t {
     __wasi_userdata_t userdata;
 
     /**
-     * The type of the event to which to subscribe.
-     */
-    __wasi_eventtype_t type;
-
-    /**
-     * The contents of the subscription.
+     * The type of the event to which to subscribe, and its contents
      */
     __wasi_subscription_u_t u;
 
 } __wasi_subscription_t;
 
+_Static_assert(sizeof(__wasi_subscription_t) == 48, "witx calculated size");
+_Static_assert(_Alignof(__wasi_subscription_t) == 8, "witx calculated align");
+_Static_assert(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset");
+_Static_assert(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset");
+
 /**
  * Exit code generated by a process when exiting.
  */
 typedef uint32_t __wasi_exitcode_t;
 
-/**
- * Signal condition.
- */
-typedef uint8_t __wasi_signal_t;
-
-/**
- * No signal. Note that POSIX has special semantics for `kill(pid, 0)`,
- * so this value is reserved.
- */
-#define __WASI_SIGNAL_NONE ((__wasi_signal_t)0)
-
-/**
- * Hangup.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_HUP ((__wasi_signal_t)1)
-
-/**
- * Terminate interrupt signal.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_INT ((__wasi_signal_t)2)
-
-/**
- * Terminal quit signal.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_QUIT ((__wasi_signal_t)3)
-
-/**
- * Illegal instruction.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_ILL ((__wasi_signal_t)4)
-
-/**
- * Trace/breakpoint trap.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_TRAP ((__wasi_signal_t)5)
-
-/**
- * Process abort signal.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_ABRT ((__wasi_signal_t)6)
-
-/**
- * Access to an undefined portion of a memory object.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_BUS ((__wasi_signal_t)7)
-
-/**
- * Erroneous arithmetic operation.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_FPE ((__wasi_signal_t)8)
-
-/**
- * Kill.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_KILL ((__wasi_signal_t)9)
-
-/**
- * User-defined signal 1.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_USR1 ((__wasi_signal_t)10)
-
-/**
- * Invalid memory reference.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_SEGV ((__wasi_signal_t)11)
-
-/**
- * User-defined signal 2.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_USR2 ((__wasi_signal_t)12)
-
-/**
- * Write on a pipe with no one to read it.
- * Action: Ignored.
- */
-#define __WASI_SIGNAL_PIPE ((__wasi_signal_t)13)
-
-/**
- * Alarm clock.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_ALRM ((__wasi_signal_t)14)
-
-/**
- * Termination signal.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_TERM ((__wasi_signal_t)15)
-
-/**
- * Child process terminated, stopped, or continued.
- * Action: Ignored.
- */
-#define __WASI_SIGNAL_CHLD ((__wasi_signal_t)16)
-
-/**
- * Continue executing, if stopped.
- * Action: Continues executing, if stopped.
- */
-#define __WASI_SIGNAL_CONT ((__wasi_signal_t)17)
-
-/**
- * Stop executing.
- * Action: Stops executing.
- */
-#define __WASI_SIGNAL_STOP ((__wasi_signal_t)18)
-
-/**
- * Terminal stop signal.
- * Action: Stops executing.
- */
-#define __WASI_SIGNAL_TSTP ((__wasi_signal_t)19)
-
-/**
- * Background process attempting read.
- * Action: Stops executing.
- */
-#define __WASI_SIGNAL_TTIN ((__wasi_signal_t)20)
-
-/**
- * Background process attempting write.
- * Action: Stops executing.
- */
-#define __WASI_SIGNAL_TTOU ((__wasi_signal_t)21)
-
-/**
- * High bandwidth data is available at a socket.
- * Action: Ignored.
- */
-#define __WASI_SIGNAL_URG ((__wasi_signal_t)22)
-
-/**
- * CPU time limit exceeded.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_XCPU ((__wasi_signal_t)23)
-
-/**
- * File size limit exceeded.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_XFSZ ((__wasi_signal_t)24)
-
-/**
- * Virtual timer expired.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_VTALRM ((__wasi_signal_t)25)
-
-/**
- * Profiling timer expired.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_PROF ((__wasi_signal_t)26)
-
-/**
- * Window changed.
- * Action: Ignored.
- */
-#define __WASI_SIGNAL_WINCH ((__wasi_signal_t)27)
-
-/**
- * I/O possible.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_POLL ((__wasi_signal_t)28)
-
-/**
- * Power failure.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_PWR ((__wasi_signal_t)29)
-
-/**
- * Bad system call.
- * Action: Terminates the process.
- */
-#define __WASI_SIGNAL_SYS ((__wasi_signal_t)30)
+_Static_assert(sizeof(__wasi_exitcode_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_exitcode_t) == 4, "witx calculated align");
 
 /**
  * Flags provided to `sock_recv`.
@@ -1383,12 +1309,12 @@ typedef uint16_t __wasi_riflags_t;
 /**
  * Returns the message without removing it from the socket's receive queue.
  */
-#define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)1)
+#define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)(1 << 0))
 
 /**
  * On byte-stream sockets, block until the full amount of data can be returned.
  */
-#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)2)
+#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1))
 
 /**
  * Flags returned by `sock_recv`.
@@ -1398,7 +1324,7 @@ typedef uint16_t __wasi_roflags_t;
 /**
  * Returned by `sock_recv`: Message data has been truncated.
  */
-#define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)1)
+#define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)(1 << 0))
 
 /**
  * Flags provided to `sock_send`. As there are currently no flags
@@ -1406,6 +1332,9 @@ typedef uint16_t __wasi_roflags_t;
  */
 typedef uint16_t __wasi_siflags_t;
 
+_Static_assert(sizeof(__wasi_siflags_t) == 2, "witx calculated size");
+_Static_assert(_Alignof(__wasi_siflags_t) == 2, "witx calculated align");
+
 /**
  * Which channels on a socket to shut down.
  */
@@ -1414,12 +1343,12 @@ typedef uint8_t __wasi_sdflags_t;
 /**
  * Disables further receive operations.
  */
-#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)1)
+#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0))
 
 /**
  * Disables further send operations.
  */
-#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)2)
+#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1))
 
 /**
  * Identifiers for preopened capabilities.
@@ -1429,7 +1358,10 @@ typedef uint8_t __wasi_preopentype_t;
 /**
  * A pre-opened directory.
  */
-#define __WASI_PREOPENTYPE_DIR ((__wasi_preopentype_t)0)
+#define __WASI_PREOPENTYPE_DIR (UINT8_C(0))
+
+_Static_assert(sizeof(__wasi_preopentype_t) == 1, "witx calculated size");
+_Static_assert(_Alignof(__wasi_preopentype_t) == 1, "witx calculated align");
 
 /**
  * The contents of a $prestat when type is `preopentype::dir`.
@@ -1442,33 +1374,24 @@ typedef struct __wasi_prestat_dir_t {
 
 } __wasi_prestat_dir_t;
 
+_Static_assert(sizeof(__wasi_prestat_dir_t) == 4, "witx calculated size");
+_Static_assert(_Alignof(__wasi_prestat_dir_t) == 4, "witx calculated align");
+_Static_assert(offsetof(__wasi_prestat_dir_t, pr_name_len) == 0, "witx calculated offset");
+
 /**
- * The contents of an $prestat.
+ * Information about a pre-opened capability.
  */
 typedef union __wasi_prestat_u_t {
-    /**
-     * When type is `preopentype::dir`:
-     */
     __wasi_prestat_dir_t dir;
-
 } __wasi_prestat_u_t;
-
-/**
- * Information about a pre-opened capability.
- */
 typedef struct __wasi_prestat_t {
-    /**
-     * The type of the pre-opened capability.
-     */
-    __wasi_preopentype_t pr_type;
-
-    /**
-     * The contents of the information.
-     */
+    uint8_t tag;
     __wasi_prestat_u_t u;
-
 } __wasi_prestat_t;
 
+_Static_assert(sizeof(__wasi_prestat_t) == 8, "witx calculated size");
+_Static_assert(_Alignof(__wasi_prestat_t) == 4, "witx calculated align");
+
 /**
  * @defgroup wasi_snapshot_preview1
  * @{
@@ -1476,461 +1399,302 @@ typedef struct __wasi_prestat_t {
 
 /**
  * Read command-line argument data.
- * The size of the array should match that returned by `wasi_args_sizes_get()`
+ * The size of the array should match that returned by `args_sizes_get`.
+ * Each argument is expected to be `\0` terminated.
  */
 __wasi_errno_t __wasi_args_get(
     uint8_t * * argv,
-
     uint8_t * argv_buf
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("args_get"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Return command-line argument data sizes.
+ * @return
+ * Returns the number of arguments and the size of the argument string
+ * data, or an error.
  */
 __wasi_errno_t __wasi_args_sizes_get(
-    /**
-     * The number of arguments.
-     */
-    __wasi_size_t *argc,
-    /**
-     * The size of the argument string data.
-     */
-    __wasi_size_t *argv_buf_size
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("args_sizes_get"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t *retptr0,
+    __wasi_size_t *retptr1
+) __attribute__((__warn_unused_result__));
 /**
  * Read environment variable data.
- * The sizes of the buffers should match that returned by `environ.sizes_get()`.
+ * The sizes of the buffers should match that returned by `environ_sizes_get`.
+ * Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s.
  */
 __wasi_errno_t __wasi_environ_get(
     uint8_t * * environ,
-
     uint8_t * environ_buf
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("environ_get"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
- * Return command-line argument data sizes.
+ * Return environment variable data sizes.
+ * @return
+ * Returns the number of environment variable arguments and the size of the
+ * environment variable data.
  */
 __wasi_errno_t __wasi_environ_sizes_get(
-    /**
-     * The number of arguments.
-     */
-    __wasi_size_t *argc,
-    /**
-     * The size of the argument string data.
-     */
-    __wasi_size_t *argv_buf_size
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("environ_sizes_get"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t *retptr0,
+    __wasi_size_t *retptr1
+) __attribute__((__warn_unused_result__));
 /**
  * Return the resolution of a clock.
- * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL`
+ * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks,
+ * return `errno::inval`.
  * Note: This is similar to `clock_getres` in POSIX.
+ * @return
+ * The resolution of the clock, or an error if one happened.
  */
 __wasi_errno_t __wasi_clock_res_get(
     /**
      * The clock for which to return the resolution.
      */
     __wasi_clockid_t id,
-
-    /**
-     * The resolution of the clock.
-     */
-    __wasi_timestamp_t *resolution
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("clock_res_get"),
-    __warn_unused_result__
-));
-
+    __wasi_timestamp_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Return the time value of a clock.
  * Note: This is similar to `clock_gettime` in POSIX.
+ * @return
+ * The time value of the clock.
  */
 __wasi_errno_t __wasi_clock_time_get(
     /**
      * The clock for which to return the time.
      */
     __wasi_clockid_t id,
-
     /**
      * The maximum lag (exclusive) that the returned time value may have, compared to its actual value.
      */
-    uint64_t precision,
-
-    /**
-     * The time value of the clock.
-     */
-    __wasi_timestamp_t *time
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("clock_time_get"),
-    __warn_unused_result__
-));
-
+    __wasi_timestamp_t precision,
+    __wasi_timestamp_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Provide file advisory information on a file descriptor.
  * Note: This is similar to `posix_fadvise` in POSIX.
  */
 __wasi_errno_t __wasi_fd_advise(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The offset within the file to which the advisory applies.
      */
-    uint64_t offset,
-
+    __wasi_filesize_t offset,
     /**
      * The length of the region to which the advisory applies.
      */
-    uint64_t len,
-
+    __wasi_filesize_t len,
     /**
      * The advice.
      */
     __wasi_advice_t advice
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_advise"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Force the allocation of space in a file.
  * Note: This is similar to `posix_fallocate` in POSIX.
  */
 __wasi_errno_t __wasi_fd_allocate(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The offset at which to start the allocation.
      */
-    uint64_t offset,
-
+    __wasi_filesize_t offset,
     /**
      * The length of the area that is allocated.
      */
-    uint64_t len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_allocate"),
-    __warn_unused_result__
-));
-
+    __wasi_filesize_t len
+) __attribute__((__warn_unused_result__));
 /**
  * Close a file descriptor.
  * Note: This is similar to `close` in POSIX.
  */
 __wasi_errno_t __wasi_fd_close(
-    uint32_t fd
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_close"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd
+) __attribute__((__warn_unused_result__));
 /**
  * Synchronize the data of a file to disk.
  * Note: This is similar to `fdatasync` in POSIX.
  */
 __wasi_errno_t __wasi_fd_datasync(
-    uint32_t fd
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_datasync"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd
+) __attribute__((__warn_unused_result__));
 /**
  * Get the attributes of a file descriptor.
  * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
+ * @return
+ * The buffer where the file descriptor's attributes are stored.
  */
 __wasi_errno_t __wasi_fd_fdstat_get(
-    uint32_t fd,
-
-    /**
-     * The buffer where the file descriptor's attributes are stored.
-     */
-    __wasi_fdstat_t *stat
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_fdstat_get"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd,
+    __wasi_fdstat_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Adjust the flags associated with a file descriptor.
  * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX.
  */
 __wasi_errno_t __wasi_fd_fdstat_set_flags(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The desired values of the file descriptor flags.
      */
     __wasi_fdflags_t flags
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_fdstat_set_flags"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Adjust the rights associated with a file descriptor.
- * This can only be used to remove rights, and returns `ENOTCAPABLE` if called in a way that would attempt to add rights
+ * This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights
  */
 __wasi_errno_t __wasi_fd_fdstat_set_rights(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The desired rights of the file descriptor.
      */
     __wasi_rights_t fs_rights_base,
-
     __wasi_rights_t fs_rights_inheriting
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_fdstat_set_rights"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Return the attributes of an open file.
+ * @return
+ * The buffer where the file's attributes are stored.
  */
 __wasi_errno_t __wasi_fd_filestat_get(
-    uint32_t fd,
-
-    /**
-     * The buffer where the file's attributes are stored.
-     */
-    __wasi_filestat_t *buf
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_filestat_get"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd,
+    __wasi_filestat_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros.
  * Note: This is similar to `ftruncate` in POSIX.
  */
 __wasi_errno_t __wasi_fd_filestat_set_size(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The desired file size.
      */
-    uint64_t size
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_filestat_set_size"),
-    __warn_unused_result__
-));
-
+    __wasi_filesize_t size
+) __attribute__((__warn_unused_result__));
 /**
  * Adjust the timestamps of an open file or directory.
  * Note: This is similar to `futimens` in POSIX.
  */
 __wasi_errno_t __wasi_fd_filestat_set_times(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The desired values of the data access timestamp.
      */
-    uint64_t atim,
-
+    __wasi_timestamp_t atim,
     /**
      * The desired values of the data modification timestamp.
      */
-    uint64_t mtim,
-
+    __wasi_timestamp_t mtim,
     /**
      * A bitmask indicating which timestamps to adjust.
      */
     __wasi_fstflags_t fst_flags
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_filestat_set_times"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Read from a file descriptor, without using and updating the file descriptor's offset.
  * Note: This is similar to `preadv` in POSIX.
+ * @return
+ * The number of bytes read.
  */
 __wasi_errno_t __wasi_fd_pread(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * List of scatter/gather vectors in which to store data.
      */
     const __wasi_iovec_t *iovs,
-
     /**
      * The length of the array pointed to by `iovs`.
      */
     size_t iovs_len,
-
     /**
      * The offset within the file at which to read.
      */
-    uint64_t offset,
-
-    /**
-     * The number of bytes read.
-     */
-    __wasi_size_t *nread
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_pread"),
-    __warn_unused_result__
-));
-
+    __wasi_filesize_t offset,
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Return a description of the given preopened file descriptor.
+ * @return
+ * The buffer where the description is stored.
  */
 __wasi_errno_t __wasi_fd_prestat_get(
-    uint32_t fd,
-
-    /**
-     * The buffer where the description is stored.
-     */
-    __wasi_prestat_t *buf
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_prestat_get"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd,
+    __wasi_prestat_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Return a description of the given preopened file descriptor.
  */
 __wasi_errno_t __wasi_fd_prestat_dir_name(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * A buffer into which to write the preopened directory name.
      */
     uint8_t * path,
-
-    uint32_t path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_prestat_dir_name"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t path_len
+) __attribute__((__warn_unused_result__));
 /**
  * Write to a file descriptor, without using and updating the file descriptor's offset.
  * Note: This is similar to `pwritev` in POSIX.
+ * @return
+ * The number of bytes written.
  */
 __wasi_errno_t __wasi_fd_pwrite(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * List of scatter/gather vectors from which to retrieve data.
      */
     const __wasi_ciovec_t *iovs,
-
     /**
      * The length of the array pointed to by `iovs`.
      */
     size_t iovs_len,
-
     /**
      * The offset within the file at which to write.
      */
-    uint64_t offset,
-
-    /**
-     * The number of bytes written.
-     */
-    __wasi_size_t *nwritten
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_pwrite"),
-    __warn_unused_result__
-));
-
+    __wasi_filesize_t offset,
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Read from a file descriptor.
  * Note: This is similar to `readv` in POSIX.
+ * @return
+ * The number of bytes read.
  */
 __wasi_errno_t __wasi_fd_read(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * List of scatter/gather vectors to which to store data.
      */
     const __wasi_iovec_t *iovs,
-
     /**
      * The length of the array pointed to by `iovs`.
      */
     size_t iovs_len,
-
-    /**
-     * The number of bytes read.
-     */
-    __wasi_size_t *nread
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_read"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Read directory entries from a directory.
  * When successful, the contents of the output buffer consist of a sequence of
- * directory entries. Each directory entry consists of a dirent_t object,
- * followed by dirent_t::d_namlen bytes holding the name of the directory
+ * directory entries. Each directory entry consists of a `dirent` object,
+ * followed by `dirent::d_namlen` bytes holding the name of the directory
  * entry.
  * This function fills the output buffer as much as possible, potentially
  * truncating the last directory entry. This allows the caller to grow its
  * read buffer size in case it's too small to fit a single large directory
  * entry, or skip the oversized directory entry.
+ * @return
+ * The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
  */
 __wasi_errno_t __wasi_fd_readdir(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The buffer where directory entries are stored
      */
     uint8_t * buf,
-
-    uint32_t buf_len,
-
+    __wasi_size_t buf_len,
     /**
      * The location within the directory to start reading
      */
-    uint64_t cookie,
-
-    /**
-     * The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached.
-     */
-    __wasi_size_t *bufused
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_readdir"),
-    __warn_unused_result__
-));
-
+    __wasi_dircookie_t cookie,
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Atomically replace a file descriptor by renumbering another file descriptor.
  * Due to the strong focus on thread safety, this environment does not provide
@@ -1942,239 +1706,142 @@ __wasi_errno_t __wasi_fd_readdir(
  * would disappear if `dup2()` were to be removed entirely.
  */
 __wasi_errno_t __wasi_fd_renumber(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The file descriptor to overwrite.
      */
-    uint32_t to
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_renumber"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t to
+) __attribute__((__warn_unused_result__));
 /**
  * Move the offset of a file descriptor.
  * Note: This is similar to `lseek` in POSIX.
+ * @return
+ * The new offset of the file descriptor, relative to the start of the file.
  */
 __wasi_errno_t __wasi_fd_seek(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The number of bytes to move.
      */
-    int64_t offset,
-
+    __wasi_filedelta_t offset,
     /**
      * The base from which the offset is relative.
      */
     __wasi_whence_t whence,
-
-    /**
-     * The new offset of the file descriptor, relative to the start of the file.
-     */
-    __wasi_filesize_t *newoffset
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_seek"),
-    __warn_unused_result__
-));
-
+    __wasi_filesize_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Synchronize the data and metadata of a file to disk.
  * Note: This is similar to `fsync` in POSIX.
  */
 __wasi_errno_t __wasi_fd_sync(
-    uint32_t fd
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_sync"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd
+) __attribute__((__warn_unused_result__));
 /**
  * Return the current offset of a file descriptor.
  * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
+ * @return
+ * The current offset of the file descriptor, relative to the start of the file.
  */
 __wasi_errno_t __wasi_fd_tell(
-    uint32_t fd,
-
-    /**
-     * The current offset of the file descriptor, relative to the start of the file.
-     */
-    __wasi_filesize_t *offset
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_tell"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t fd,
+    __wasi_filesize_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Write to a file descriptor.
  * Note: This is similar to `writev` in POSIX.
  */
 __wasi_errno_t __wasi_fd_write(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * List of scatter/gather vectors from which to retrieve data.
      */
     const __wasi_ciovec_t *iovs,
-
     /**
      * The length of the array pointed to by `iovs`.
      */
     size_t iovs_len,
-
-    /**
-     * The number of bytes written.
-     */
-    __wasi_size_t *nwritten
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("fd_write"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Create a directory.
  * Note: This is similar to `mkdirat` in POSIX.
  */
 __wasi_errno_t __wasi_path_create_directory(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The path at which to create the directory.
      */
-    const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_create_directory"),
-    __warn_unused_result__
-));
-
+    const char *path
+) __attribute__((__warn_unused_result__));
 /**
  * Return the attributes of a file or directory.
  * Note: This is similar to `stat` in POSIX.
+ * @return
+ * The buffer where the file's attributes are stored.
  */
 __wasi_errno_t __wasi_path_filestat_get(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * Flags determining the method of how the path is resolved.
      */
     __wasi_lookupflags_t flags,
-
     /**
      * The path of the file or directory to inspect.
      */
     const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len,
-
-    /**
-     * The buffer where the file's attributes are stored.
-     */
-    __wasi_filestat_t *buf
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_filestat_get"),
-    __warn_unused_result__
-));
-
+    __wasi_filestat_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Adjust the timestamps of a file or directory.
  * Note: This is similar to `utimensat` in POSIX.
  */
 __wasi_errno_t __wasi_path_filestat_set_times(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * Flags determining the method of how the path is resolved.
      */
     __wasi_lookupflags_t flags,
-
     /**
      * The path of the file or directory to operate on.
      */
     const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len,
-
     /**
      * The desired values of the data access timestamp.
      */
-    uint64_t atim,
-
+    __wasi_timestamp_t atim,
     /**
      * The desired values of the data modification timestamp.
      */
-    uint64_t mtim,
-
+    __wasi_timestamp_t mtim,
     /**
      * A bitmask indicating which timestamps to adjust.
      */
     __wasi_fstflags_t fst_flags
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_filestat_set_times"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Create a hard link.
  * Note: This is similar to `linkat` in POSIX.
  */
 __wasi_errno_t __wasi_path_link(
-    uint32_t old_fd,
-
+    __wasi_fd_t old_fd,
     /**
      * Flags determining the method of how the path is resolved.
      */
     __wasi_lookupflags_t old_flags,
-
     /**
      * The source path from which to link.
      */
     const char *old_path,
-
-    /**
-     * The length of the buffer pointed to by `old_path`.
-     */
-    size_t old_path_len,
-
     /**
      * The working directory at which the resolution of the new path starts.
      */
-    uint32_t new_fd,
-
+    __wasi_fd_t new_fd,
     /**
      * The destination path at which to create the hard link.
      */
-    const char *new_path,
-
-    /**
-     * The length of the buffer pointed to by `new_path`.
-     */
-    size_t new_path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_link"),
-    __warn_unused_result__
-));
-
+    const char *new_path
+) __attribute__((__warn_unused_result__));
 /**
  * Open a file or directory.
  * The returned file descriptor is not guaranteed to be the lowest-numbered
@@ -2183,31 +1850,24 @@ __wasi_errno_t __wasi_path_link(
  * is error-prone in multi-threaded contexts. The returned file descriptor is
  * guaranteed to be less than 2**31.
  * Note: This is similar to `openat` in POSIX.
+ * @return
+ * The file descriptor of the file that has been opened.
  */
 __wasi_errno_t __wasi_path_open(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * Flags determining the method of how the path is resolved.
      */
     __wasi_lookupflags_t dirflags,
-
     /**
      * The relative path of the file or directory to open, relative to the
-     * `dirfd` directory.
+     * `path_open::fd` directory.
      */
     const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len,
-
     /**
      * The method by which to open the file.
      */
     __wasi_oflags_t oflags,
-
     /**
      * The initial rights of the newly created file descriptor. The
      * implementation is allowed to return a file descriptor with fewer rights
@@ -2218,115 +1878,60 @@ __wasi_errno_t __wasi_path_open(
      * file descriptors derived from it.
      */
     __wasi_rights_t fs_rights_base,
-
-    __wasi_rights_t fs_rights_inherting,
-
+    __wasi_rights_t fs_rights_inheriting,
     __wasi_fdflags_t fdflags,
-
-    /**
-     * The file descriptor of the file that has been opened.
-     */
-    __wasi_fd_t *opened_fd
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_open"),
-    __warn_unused_result__
-));
-
+    __wasi_fd_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Read the contents of a symbolic link.
  * Note: This is similar to `readlinkat` in POSIX.
+ * @return
+ * The number of bytes placed in the buffer.
  */
 __wasi_errno_t __wasi_path_readlink(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The path of the symbolic link from which to read.
      */
     const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len,
-
     /**
      * The buffer to which to write the contents of the symbolic link.
      */
     uint8_t * buf,
-
-    uint32_t buf_len,
-
-    /**
-     * The number of bytes placed in the buffer.
-     */
-    __wasi_size_t *bufused
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_readlink"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t buf_len,
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Remove a directory.
- * Return `ENOTEMPTY` if the directory is not empty.
+ * Return `errno::notempty` if the directory is not empty.
  * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX.
  */
 __wasi_errno_t __wasi_path_remove_directory(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The path to a directory to remove.
      */
-    const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_remove_directory"),
-    __warn_unused_result__
-));
-
+    const char *path
+) __attribute__((__warn_unused_result__));
 /**
  * Rename a file or directory.
  * Note: This is similar to `renameat` in POSIX.
  */
 __wasi_errno_t __wasi_path_rename(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The source path of the file or directory to rename.
      */
     const char *old_path,
-
-    /**
-     * The length of the buffer pointed to by `old_path`.
-     */
-    size_t old_path_len,
-
     /**
      * The working directory at which the resolution of the new path starts.
      */
-    uint32_t new_fd,
-
+    __wasi_fd_t new_fd,
     /**
      * The destination path to which to rename the file or directory.
      */
-    const char *new_path,
-
-    /**
-     * The length of the buffer pointed to by `new_path`.
-     */
-    size_t new_path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_rename"),
-    __warn_unused_result__
-));
-
+    const char *new_path
+) __attribute__((__warn_unused_result__));
 /**
  * Create a symbolic link.
  * Note: This is similar to `symlinkat` in POSIX.
@@ -2336,81 +1941,44 @@ __wasi_errno_t __wasi_path_symlink(
      * The contents of the symbolic link.
      */
     const char *old_path,
-
-    /**
-     * The length of the buffer pointed to by `old_path`.
-     */
-    size_t old_path_len,
-
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The destination path at which to create the symbolic link.
      */
-    const char *new_path,
-
-    /**
-     * The length of the buffer pointed to by `new_path`.
-     */
-    size_t new_path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_symlink"),
-    __warn_unused_result__
-));
-
+    const char *new_path
+) __attribute__((__warn_unused_result__));
 /**
  * Unlink a file.
- * Return `EISDIR` if the path refers to a directory.
+ * Return `errno::isdir` if the path refers to a directory.
  * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX.
  */
 __wasi_errno_t __wasi_path_unlink_file(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * The path to a file to unlink.
      */
-    const char *path,
-
-    /**
-     * The length of the buffer pointed to by `path`.
-     */
-    size_t path_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("path_unlink_file"),
-    __warn_unused_result__
-));
-
+    const char *path
+) __attribute__((__warn_unused_result__));
 /**
  * Concurrently poll for the occurrence of a set of events.
+ * @return
+ * The number of events stored.
  */
 __wasi_errno_t __wasi_poll_oneoff(
     /**
      * The events to which to subscribe.
      */
     const __wasi_subscription_t * in,
-
     /**
      * The events that have occurred.
      */
     __wasi_event_t * out,
-
     /**
      * Both the number of subscriptions and events.
      */
-    uint32_t nsubscriptions,
-
-    /**
-     * The number of events stored.
-     */
-    __wasi_size_t *nevents
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("poll_oneoff"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t nsubscriptions,
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Terminate the process normally. An exit code of 0 indicates successful
  * termination of the program. The meanings of other values is dependent on
@@ -2420,38 +1988,15 @@ _Noreturn void __wasi_proc_exit(
     /**
      * The exit code returned by the process.
      */
-    uint32_t rval
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("proc_exit")));
-
-/**
- * Send a signal to the process of the calling thread.
- * Note: This is similar to `raise` in POSIX.
- */
-__wasi_errno_t __wasi_proc_raise(
-    /**
-     * The signal condition to trigger.
-     */
-    __wasi_signal_t sig
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("proc_raise"),
-    __warn_unused_result__
-));
-
+    __wasi_exitcode_t rval
+);
 /**
  * Temporarily yield execution of the calling thread.
  * Note: This is similar to `sched_yield` in POSIX.
  */
 __wasi_errno_t __wasi_sched_yield(
     void
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("sched_yield"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /**
  * Write high-quality random data into a buffer.
  * This function blocks when the implementation is unable to immediately
@@ -2465,103 +2010,104 @@ __wasi_errno_t __wasi_random_get(
      * The buffer to fill with random data.
      */
     uint8_t * buf,
-
-    uint32_t buf_len
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("random_get"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t buf_len
+) __attribute__((__warn_unused_result__));
+/**
+ * Accept a new incoming connection.
+ * Note: This is similar to `accept` in POSIX.
+ * @return
+ * New socket connection
+ */
+__wasi_errno_t __wasi_sock_accept(
+    /**
+     * The listening socket.
+     */
+    __wasi_fd_t fd,
+    /**
+     * The desired values of the file descriptor flags.
+     */
+    __wasi_fdflags_t flags,
+    __wasi_fd_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Receive a message from a socket.
  * Note: This is similar to `recv` in POSIX, though it also supports reading
  * the data into multiple buffers in the manner of `readv`.
+ * @return
+ * Number of bytes stored in ri_data and message flags.
  */
 __wasi_errno_t __wasi_sock_recv(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * List of scatter/gather vectors to which to store data.
      */
     const __wasi_iovec_t *ri_data,
-
     /**
      * The length of the array pointed to by `ri_data`.
      */
     size_t ri_data_len,
-
     /**
      * Message flags.
      */
     __wasi_riflags_t ri_flags,
-
-    /**
-     * Number of bytes stored in ri_data.
-     */
-    __wasi_size_t *ro_datalen,
-    /**
-     * Message flags.
-     */
-    __wasi_roflags_t *ro_flags
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("sock_recv"),
-    __warn_unused_result__
-));
-
+    __wasi_size_t *retptr0,
+    __wasi_roflags_t *retptr1
+) __attribute__((__warn_unused_result__));
 /**
  * Send a message on a socket.
  * Note: This is similar to `send` in POSIX, though it also supports writing
  * the data from multiple buffers in the manner of `writev`.
+ * @return
+ * Number of bytes transmitted.
  */
 __wasi_errno_t __wasi_sock_send(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * List of scatter/gather vectors to which to retrieve data
      */
     const __wasi_ciovec_t *si_data,
-
     /**
      * The length of the array pointed to by `si_data`.
      */
     size_t si_data_len,
-
     /**
      * Message flags.
      */
-    uint16_t si_flags,
-
-    /**
-     * Number of bytes transmitted.
-     */
-    __wasi_size_t *so_datalen
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("sock_send"),
-    __warn_unused_result__
-));
-
+    __wasi_siflags_t si_flags,
+    __wasi_size_t *retptr0
+) __attribute__((__warn_unused_result__));
 /**
  * Shut down socket send and receive channels.
  * Note: This is similar to `shutdown` in POSIX.
  */
 __wasi_errno_t __wasi_sock_shutdown(
-    uint32_t fd,
-
+    __wasi_fd_t fd,
     /**
      * Which channels on the socket to shut down.
      */
     __wasi_sdflags_t how
-) __attribute__((
-    __import_module__("wasi_snapshot_preview1"),
-    __import_name__("sock_shutdown"),
-    __warn_unused_result__
-));
-
+) __attribute__((__warn_unused_result__));
 /** @} */
 
+#ifdef _REENTRANT
+/**
+ * Request a new thread to be created by the host.
+ *
+ * The host will create a new instance of the current module sharing its
+ * memory, find an exported entry function--`wasi_thread_start`--, and call the
+ * entry function with `start_arg` in the new thread.
+ *
+ * @see https://github.com/WebAssembly/wasi-threads/#readme
+ */
+int32_t __wasi_thread_spawn(
+    /**
+     * A pointer to an opaque struct to be passed to the module's entry
+     * function.
+     */
+    void *start_arg
+)  __attribute__((__warn_unused_result__));
+#endif
+
 #ifdef __cplusplus
 }
 #endif