]> git.proxmox.com Git - wasi-libc.git/commitdiff
Wasi snapshot preview1 (#140)
authorDan Gohman <sunfish@mozilla.com>
Fri, 22 Nov 2019 04:06:00 +0000 (20:06 -0800)
committerGitHub <noreply@github.com>
Fri, 22 Nov 2019 04:06:00 +0000 (20:06 -0800)
* Make __wasi_linkcount_t a uint64_t (#134)

Refs: https://github.com/WebAssembly/WASI/pull/127

* Generate the WASI interface from witx.

This replaces the hand-maintained <wasi/core.h> header with a
<wasi/api.h> generated from witx.

Most of the churn here is caused by upstream WASI renamings; hopefully
in the future ABI updates will be less noisy.

87 files changed:
expected/wasm32-wasi/include-all.c
expected/wasm32-wasi/predefined-macros.txt
libc-bottom-half/cloudlibc/src/common/clock.h
libc-bottom-half/cloudlibc/src/common/errno.h
libc-bottom-half/cloudlibc/src/common/time.h
libc-bottom-half/cloudlibc/src/common/tls.h
libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h
libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c
libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c
libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c
libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c
libc-bottom-half/cloudlibc/src/libc/errno/errno.c
libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c
libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c
libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c
libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c
libc-bottom-half/cloudlibc/src/libc/poll/poll.c
libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c
libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c
libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c
libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c
libc-bottom-half/cloudlibc/src/libc/sys/resource/getrusage.c
libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c
libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c
libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c
libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c
libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c
libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c
libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c
libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c
libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c
libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h
libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c
libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c
libc-bottom-half/cloudlibc/src/libc/sys/times/times.c
libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c
libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c
libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c
libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c
libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c
libc-bottom-half/cloudlibc/src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c
libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c
libc-bottom-half/cloudlibc/src/libc/time/CLOCK_THREAD_CPUTIME_ID.c
libc-bottom-half/cloudlibc/src/libc/time/clock.c
libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c
libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c
libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c
libc-bottom-half/cloudlibc/src/libc/time/time.c
libc-bottom-half/cloudlibc/src/libc/unistd/close.c
libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c
libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c
libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c
libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c
libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c
libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c
libc-bottom-half/cloudlibc/src/libc/unistd/pread.c
libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c
libc-bottom-half/cloudlibc/src/libc/unistd/read.c
libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c
libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c
libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c
libc-bottom-half/cloudlibc/src/libc/unistd/write.c
libc-bottom-half/crt/crt1.c
libc-bottom-half/headers/private/wasi/libc-internal.h
libc-bottom-half/headers/public/__errno_values.h
libc-bottom-half/headers/public/__header_bits_signal.h
libc-bottom-half/headers/public/__header_dirent.h
libc-bottom-half/headers/public/__header_fcntl.h
libc-bottom-half/headers/public/__header_sys_socket.h
libc-bottom-half/headers/public/__header_time.h
libc-bottom-half/headers/public/__seek.h
libc-bottom-half/headers/public/wasi/api.h [new file with mode: 0644]
libc-bottom-half/headers/public/wasi/core.h [deleted file]
libc-bottom-half/libpreopen/libpreopen.c
libc-bottom-half/sources/__environ.c
libc-bottom-half/sources/__original_main.c
libc-bottom-half/sources/__wasilibc_fd_renumber.c
libc-bottom-half/sources/__wasilibc_rmdirat.c
libc-bottom-half/sources/__wasilibc_tell.c
libc-bottom-half/sources/__wasilibc_unlinkat.c
libc-bottom-half/sources/getentropy.c
libc-bottom-half/sources/isatty.c
libc-bottom-half/sources/pause.c
tools/wasi-headers/Cargo.toml [new file with mode: 0644]
tools/wasi-headers/LICENSE [new file with mode: 0644]
tools/wasi-headers/src/c_header.rs [new file with mode: 0644]
tools/wasi-headers/src/main.rs [new file with mode: 0644]

index c9b6fa084f9d13793d369797e2eaf5631be63a7b..e1d62316e82fd9ec877e8a3bb74de887108d5c4e 100644 (file)
 #include <uchar.h>
 #include <unistd.h>
 #include <values.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc-find-relpath.h>
 #include <wasi/libc.h>
 #include <wchar.h>
index ef860937c00068e33606f1ed8c4a6d1958278b63..24298107ed3fa2d9e1f84ced1a088bbe4f4dcb0e 100644 (file)
 #define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN
 #define D_FMT 0x20029
 #define D_T_FMT 0x20028
-#define E2BIG __WASI_E2BIG
-#define EACCES __WASI_EACCES
+#define E2BIG __WASI_ERRNO_2BIG
+#define EACCES __WASI_ERRNO_ACCES
 #define EACCESS 2
-#define EADDRINUSE __WASI_EADDRINUSE
-#define EADDRNOTAVAIL __WASI_EADDRNOTAVAIL
-#define EAFNOSUPPORT __WASI_EAFNOSUPPORT
-#define EAGAIN __WASI_EAGAIN
-#define EALREADY __WASI_EALREADY
-#define EBADF __WASI_EBADF
+#define EADDRINUSE __WASI_ERRNO_ADDRINUSE
+#define EADDRNOTAVAIL __WASI_ERRNO_ADDRNOTAVAIL
+#define EAFNOSUPPORT __WASI_ERRNO_AFNOSUPPORT
+#define EAGAIN __WASI_ERRNO_AGAIN
+#define EALREADY __WASI_ERRNO_ALREADY
+#define EBADF __WASI_ERRNO_BADF
 #define EBADID 5
-#define EBADMSG __WASI_EBADMSG
+#define EBADMSG __WASI_ERRNO_BADMSG
 #define EBADOP 4
-#define EBUSY __WASI_EBUSY
+#define EBUSY __WASI_ERRNO_BUSY
 #define EC 247
-#define ECANCELED __WASI_ECANCELED
-#define ECHILD __WASI_ECHILD
-#define ECONNABORTED __WASI_ECONNABORTED
-#define ECONNREFUSED __WASI_ECONNREFUSED
-#define ECONNRESET __WASI_ECONNRESET
-#define EDEADLK __WASI_EDEADLK
-#define EDESTADDRREQ __WASI_EDESTADDRREQ
-#define EDOM __WASI_EDOM
-#define EDQUOT __WASI_EDQUOT
-#define EEXIST __WASI_EEXIST
+#define ECANCELED __WASI_ERRNO_CANCELED
+#define ECHILD __WASI_ERRNO_CHILD
+#define ECONNABORTED __WASI_ERRNO_CONNABORTED
+#define ECONNREFUSED __WASI_ERRNO_CONNREFUSED
+#define ECONNRESET __WASI_ERRNO_CONNRESET
+#define EDEADLK __WASI_ERRNO_DEADLK
+#define EDESTADDRREQ __WASI_ERRNO_DESTADDRREQ
+#define EDOM __WASI_ERRNO_DOM
+#define EDQUOT __WASI_ERRNO_DQUOT
+#define EEXIST __WASI_ERRNO_EXIST
 #define EEXISTS 6
-#define EFAULT __WASI_EFAULT
-#define EFBIG __WASI_EFBIG
+#define EFAULT __WASI_ERRNO_FAULT
+#define EFBIG __WASI_ERRNO_FBIG
 #define EFD_CLOEXEC O_CLOEXEC
 #define EFD_NONBLOCK O_NONBLOCK
 #define EFD_SEMAPHORE 1
-#define EHOSTUNREACH __WASI_EHOSTUNREACH
-#define EIDRM __WASI_EIDRM
-#define EILSEQ __WASI_EILSEQ
-#define EINPROGRESS __WASI_EINPROGRESS
-#define EINTR __WASI_EINTR
-#define EINVAL __WASI_EINVAL
-#define EIO __WASI_EIO
-#define EISCONN __WASI_EISCONN
-#define EISDIR __WASI_EISDIR
+#define EHOSTUNREACH __WASI_ERRNO_HOSTUNREACH
+#define EIDRM __WASI_ERRNO_IDRM
+#define EILSEQ __WASI_ERRNO_ILSEQ
+#define EINPROGRESS __WASI_ERRNO_INPROGRESS
+#define EINTR __WASI_ERRNO_INTR
+#define EINVAL __WASI_ERRNO_INVAL
+#define EIO __WASI_ERRNO_IO
+#define EISCONN __WASI_ERRNO_ISCONN
+#define EISDIR __WASI_ERRNO_ISDIR
 #define EL 248
-#define ELOOP __WASI_ELOOP
-#define EMFILE __WASI_EMFILE
-#define EMLINK __WASI_EMLINK
-#define EMSGSIZE __WASI_EMSGSIZE
-#define EMULTIHOP __WASI_EMULTIHOP
-#define ENAMETOOLONG __WASI_ENAMETOOLONG
+#define ELOOP __WASI_ERRNO_LOOP
+#define EMFILE __WASI_ERRNO_MFILE
+#define EMLINK __WASI_ERRNO_MLINK
+#define EMSGSIZE __WASI_ERRNO_MSGSIZE
+#define EMULTIHOP __WASI_ERRNO_MULTIHOP
+#define ENAMETOOLONG __WASI_ERRNO_NAMETOOLONG
 #define ENCRYPT_CNT 9
 #define ENCRYPT_DEC_KEYID 8
 #define ENCRYPT_ENC_KEYID 7
 #define ENCTYPE_DES_OFB64 2
 #define ENCTYPE_NAME(x) enctype_names[x]
 #define ENCTYPE_NAME_OK(x) ((unsigned int)(x) < ENCTYPE_CNT)
-#define ENETDOWN __WASI_ENETDOWN
-#define ENETRESET __WASI_ENETRESET
-#define ENETUNREACH __WASI_ENETUNREACH
-#define ENFILE __WASI_ENFILE
-#define ENOBUFS __WASI_ENOBUFS
-#define ENODEV __WASI_ENODEV
-#define ENOENT __WASI_ENOENT
-#define ENOEXEC __WASI_ENOEXEC
-#define ENOLCK __WASI_ENOLCK
-#define ENOLINK __WASI_ENOLINK
-#define ENOMEM __WASI_ENOMEM
-#define ENOMSG __WASI_ENOMSG
-#define ENOPROTOOPT __WASI_ENOPROTOOPT
+#define ENETDOWN __WASI_ERRNO_NETDOWN
+#define ENETRESET __WASI_ERRNO_NETRESET
+#define ENETUNREACH __WASI_ERRNO_NETUNREACH
+#define ENFILE __WASI_ERRNO_NFILE
+#define ENOBUFS __WASI_ERRNO_NOBUFS
+#define ENODEV __WASI_ERRNO_NODEV
+#define ENOENT __WASI_ERRNO_NOENT
+#define ENOEXEC __WASI_ERRNO_NOEXEC
+#define ENOLCK __WASI_ERRNO_NOLCK
+#define ENOLINK __WASI_ERRNO_NOLINK
+#define ENOMEM __WASI_ERRNO_NOMEM
+#define ENOMSG __WASI_ERRNO_NOMSG
+#define ENOPROTOOPT __WASI_ERRNO_NOPROTOOPT
 #define ENOSPACE 3
-#define ENOSPC __WASI_ENOSPC
-#define ENOSYS __WASI_ENOSYS
-#define ENOTCAPABLE __WASI_ENOTCAPABLE
-#define ENOTCONN __WASI_ENOTCONN
-#define ENOTDIR __WASI_ENOTDIR
-#define ENOTEMPTY __WASI_ENOTEMPTY
+#define ENOSPC __WASI_ERRNO_NOSPC
+#define ENOSYS __WASI_ERRNO_NOSYS
+#define ENOTCAPABLE __WASI_ERRNO_NOTCAPABLE
+#define ENOTCONN __WASI_ERRNO_NOTCONN
+#define ENOTDIR __WASI_ERRNO_NOTDIR
+#define ENOTEMPTY __WASI_ERRNO_NOTEMPTY
 #define ENOTFOUND 1
-#define ENOTRECOVERABLE __WASI_ENOTRECOVERABLE
-#define ENOTSOCK __WASI_ENOTSOCK
-#define ENOTSUP __WASI_ENOTSUP
-#define ENOTTY __WASI_ENOTTY
+#define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE
+#define ENOTSOCK __WASI_ERRNO_NOTSOCK
+#define ENOTSUP __WASI_ERRNO_NOTSUP
+#define ENOTTY __WASI_ERRNO_NOTTY
 #define ENOUSER 7
 #define ENV_ESC 2
 #define ENV_USERVAR 3
-#define ENXIO __WASI_ENXIO
+#define ENXIO __WASI_ERRNO_NXIO
 #define EOF (-1)
 #define EOPNOTSUPP ENOTSUP
 #define EOR 239
-#define EOVERFLOW __WASI_EOVERFLOW
-#define EOWNERDEAD __WASI_EOWNERDEAD
-#define EPERM __WASI_EPERM
-#define EPIPE __WASI_EPIPE
-#define EPROTO __WASI_EPROTO
-#define EPROTONOSUPPORT __WASI_EPROTONOSUPPORT
-#define EPROTOTYPE __WASI_EPROTOTYPE
+#define EOVERFLOW __WASI_ERRNO_OVERFLOW
+#define EOWNERDEAD __WASI_ERRNO_OWNERDEAD
+#define EPERM __WASI_ERRNO_PERM
+#define EPIPE __WASI_ERRNO_PIPE
+#define EPROTO __WASI_ERRNO_PROTO
+#define EPROTONOSUPPORT __WASI_ERRNO_PROTONOSUPPORT
+#define EPROTOTYPE __WASI_ERRNO_PROTOTYPE
 #define ERA 0x2002C
-#define ERANGE __WASI_ERANGE
+#define ERANGE __WASI_ERRNO_RANGE
 #define ERA_D_FMT 0x2002E
 #define ERA_D_T_FMT 0x20030
 #define ERA_T_FMT 0x20031
-#define EROFS __WASI_EROFS
+#define EROFS __WASI_ERRNO_ROFS
 #define ERROR 05
-#define ESPIPE __WASI_ESPIPE
-#define ESRCH __WASI_ESRCH
-#define ESTALE __WASI_ESTALE
-#define ETIMEDOUT __WASI_ETIMEDOUT
-#define ETXTBSY __WASI_ETXTBSY
+#define ESPIPE __WASI_ERRNO_SPIPE
+#define ESRCH __WASI_ERRNO_SRCH
+#define ESTALE __WASI_ERRNO_STALE
+#define ETIMEDOUT __WASI_ERRNO_TIMEDOUT
+#define ETXTBSY __WASI_ERRNO_TXTBSY
 #define EUNDEF 0
 #define EWOULDBLOCK EAGAIN
-#define EXDEV __WASI_EXDEV
+#define EXDEV __WASI_ERRNO_XDEV
 #define EXIT_FAILURE 1
 #define EXIT_SUCCESS 0
 #define EX_CANTCREAT 73
 #define MSG_ANY 0x02
 #define MSG_BAND 0x04
 #define MSG_HIPRI 0x01
-#define MSG_PEEK __WASI_SOCK_RECV_PEEK
-#define MSG_TRUNC __WASI_SOCK_RECV_DATA_TRUNCATED
-#define MSG_WAITALL __WASI_SOCK_RECV_WAITALL
+#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK
+#define MSG_TRUNC __WASI_RIFLAGS_RECV_DATA_TRUNCATED
+#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL
 #define MUXID_ALL (-1)
 #define M_1_PI 0.31830988618379067154
 #define M_2_PI 0.63661977236758134308
 #define OLD_ENV_VAR 1
 #define ONCE_FLAG_INIT 0
 #define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH)
-#define O_APPEND __WASI_FDFLAG_APPEND
+#define O_APPEND __WASI_FDFLAGS_APPEND
 #define O_CLOEXEC (0)
-#define O_CREAT (__WASI_O_CREAT << 12)
-#define O_DIRECTORY (__WASI_O_DIRECTORY << 12)
-#define O_DSYNC __WASI_FDFLAG_DSYNC
-#define O_EXCL (__WASI_O_EXCL << 12)
+#define O_CREAT (__WASI_OFLAGS_CREAT << 12)
+#define O_DIRECTORY (__WASI_OFLAGS_DIRECTORY << 12)
+#define O_DSYNC __WASI_FDFLAGS_DSYNC
+#define O_EXCL (__WASI_OFLAGS_EXCL << 12)
 #define O_EXEC (0x02000000)
 #define O_NOCTTY (0)
 #define O_NOFOLLOW (0x01000000)
-#define O_NONBLOCK __WASI_FDFLAG_NONBLOCK
+#define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK
 #define O_RDONLY (0x04000000)
 #define O_RDWR (O_RDONLY | O_WRONLY)
-#define O_RSYNC __WASI_FDFLAG_RSYNC
+#define O_RSYNC __WASI_FDFLAGS_RSYNC
 #define O_SEARCH (0x08000000)
-#define O_SYNC __WASI_FDFLAG_SYNC
-#define O_TRUNC (__WASI_O_TRUNC << 12)
+#define O_SYNC __WASI_FDFLAGS_SYNC
+#define O_TRUNC (__WASI_OFLAGS_TRUNC << 12)
 #define O_TTY_INIT (0)
 #define O_WRONLY (0x10000000)
 #define PACKETSZ NS_PACKETSZ
 #define SHORTBITS (sizeof(short) * 8)
 #define SHRT_MAX 0x7fff
 #define SHRT_MIN (-1-0x7fff)
-#define SHUT_RD __WASI_SHUT_RD
+#define SHUT_RD __WASI_SDFLAGS_RD
 #define SHUT_RDWR (SHUT_RD | SHUT_WR)
-#define SHUT_WR __WASI_SHUT_WR
+#define SHUT_WR __WASI_SDFLAGS_WR
 #define SIGABRT __WASI_SIGABRT
 #define SIGALRM __WASI_SIGALRM
 #define SIGBUS __WASI_SIGBUS
 #define TH_RST 0x04
 #define TH_SYN 0x02
 #define TH_URG 0x20
-#define TIMER_ABSTIME __WASI_SUBSCRIPTION_CLOCK_ABSTIME
+#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME
 #define TIMESPEC_TO_TIMEVAL(tv,ts) ( (tv)->tv_sec = (ts)->tv_sec, (tv)->tv_usec = (ts)->tv_nsec / 1000, (void)0 )
 #define TIMEVAL_TO_TIMESPEC(tv,ts) ( (ts)->tv_sec = (tv)->tv_sec, (ts)->tv_nsec = (tv)->tv_usec * 1000, (void)0 )
 #define TIME_BAD TIME_ERROR
 #define __UINT_LEAST8_MAX__ 255
 #define __UINT_LEAST8_TYPE__ unsigned char
 #define __USER_LABEL_PREFIX__ 
-#define __WASI_ADVICE_DONTNEED (UINT8_C(4))
-#define __WASI_ADVICE_NOREUSE (UINT8_C(5))
-#define __WASI_ADVICE_NORMAL (UINT8_C(0))
-#define __WASI_ADVICE_RANDOM (UINT8_C(2))
-#define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1))
-#define __WASI_ADVICE_WILLNEED (UINT8_C(3))
-#define __WASI_CLOCK_MONOTONIC (UINT32_C(1))
-#define __WASI_CLOCK_PROCESS_CPUTIME_ID (UINT32_C(2))
-#define __WASI_CLOCK_REALTIME (UINT32_C(0))
-#define __WASI_CLOCK_THREAD_CPUTIME_ID (UINT32_C(3))
+#define __WASI_ADVICE_DONTNEED ((__wasi_advice_t)4)
+#define __WASI_ADVICE_NOREUSE ((__wasi_advice_t)5)
+#define __WASI_ADVICE_NORMAL ((__wasi_advice_t)0)
+#define __WASI_ADVICE_RANDOM ((__wasi_advice_t)2)
+#define __WASI_ADVICE_SEQUENTIAL ((__wasi_advice_t)1)
+#define __WASI_ADVICE_WILLNEED ((__wasi_advice_t)3)
+#define __WASI_CLOCKID_MONOTONIC ((__wasi_clockid_t)1)
+#define __WASI_CLOCKID_PROCESS_CPUTIME_ID ((__wasi_clockid_t)2)
+#define __WASI_CLOCKID_REALTIME ((__wasi_clockid_t)0)
+#define __WASI_CLOCKID_THREAD_CPUTIME_ID ((__wasi_clockid_t)3)
 #define __WASI_DIRCOOKIE_START (UINT64_C(0))
-#define __WASI_E2BIG (UINT16_C(1))
-#define __WASI_EACCES (UINT16_C(2))
-#define __WASI_EADDRINUSE (UINT16_C(3))
-#define __WASI_EADDRNOTAVAIL (UINT16_C(4))
-#define __WASI_EAFNOSUPPORT (UINT16_C(5))
-#define __WASI_EAGAIN (UINT16_C(6))
-#define __WASI_EALREADY (UINT16_C(7))
-#define __WASI_EBADF (UINT16_C(8))
-#define __WASI_EBADMSG (UINT16_C(9))
-#define __WASI_EBUSY (UINT16_C(10))
-#define __WASI_ECANCELED (UINT16_C(11))
-#define __WASI_ECHILD (UINT16_C(12))
-#define __WASI_ECONNABORTED (UINT16_C(13))
-#define __WASI_ECONNREFUSED (UINT16_C(14))
-#define __WASI_ECONNRESET (UINT16_C(15))
-#define __WASI_EDEADLK (UINT16_C(16))
-#define __WASI_EDESTADDRREQ (UINT16_C(17))
-#define __WASI_EDOM (UINT16_C(18))
-#define __WASI_EDQUOT (UINT16_C(19))
-#define __WASI_EEXIST (UINT16_C(20))
-#define __WASI_EFAULT (UINT16_C(21))
-#define __WASI_EFBIG (UINT16_C(22))
-#define __WASI_EHOSTUNREACH (UINT16_C(23))
-#define __WASI_EIDRM (UINT16_C(24))
-#define __WASI_EILSEQ (UINT16_C(25))
-#define __WASI_EINPROGRESS (UINT16_C(26))
-#define __WASI_EINTR (UINT16_C(27))
-#define __WASI_EINVAL (UINT16_C(28))
-#define __WASI_EIO (UINT16_C(29))
-#define __WASI_EISCONN (UINT16_C(30))
-#define __WASI_EISDIR (UINT16_C(31))
-#define __WASI_ELOOP (UINT16_C(32))
-#define __WASI_EMFILE (UINT16_C(33))
-#define __WASI_EMLINK (UINT16_C(34))
-#define __WASI_EMSGSIZE (UINT16_C(35))
-#define __WASI_EMULTIHOP (UINT16_C(36))
-#define __WASI_ENAMETOOLONG (UINT16_C(37))
-#define __WASI_ENETDOWN (UINT16_C(38))
-#define __WASI_ENETRESET (UINT16_C(39))
-#define __WASI_ENETUNREACH (UINT16_C(40))
-#define __WASI_ENFILE (UINT16_C(41))
-#define __WASI_ENOBUFS (UINT16_C(42))
-#define __WASI_ENODEV (UINT16_C(43))
-#define __WASI_ENOENT (UINT16_C(44))
-#define __WASI_ENOEXEC (UINT16_C(45))
-#define __WASI_ENOLCK (UINT16_C(46))
-#define __WASI_ENOLINK (UINT16_C(47))
-#define __WASI_ENOMEM (UINT16_C(48))
-#define __WASI_ENOMSG (UINT16_C(49))
-#define __WASI_ENOPROTOOPT (UINT16_C(50))
-#define __WASI_ENOSPC (UINT16_C(51))
-#define __WASI_ENOSYS (UINT16_C(52))
-#define __WASI_ENOTCAPABLE (UINT16_C(76))
-#define __WASI_ENOTCONN (UINT16_C(53))
-#define __WASI_ENOTDIR (UINT16_C(54))
-#define __WASI_ENOTEMPTY (UINT16_C(55))
-#define __WASI_ENOTRECOVERABLE (UINT16_C(56))
-#define __WASI_ENOTSOCK (UINT16_C(57))
-#define __WASI_ENOTSUP (UINT16_C(58))
-#define __WASI_ENOTTY (UINT16_C(59))
-#define __WASI_ENXIO (UINT16_C(60))
-#define __WASI_EOVERFLOW (UINT16_C(61))
-#define __WASI_EOWNERDEAD (UINT16_C(62))
-#define __WASI_EPERM (UINT16_C(63))
-#define __WASI_EPIPE (UINT16_C(64))
-#define __WASI_EPROTO (UINT16_C(65))
-#define __WASI_EPROTONOSUPPORT (UINT16_C(66))
-#define __WASI_EPROTOTYPE (UINT16_C(67))
-#define __WASI_ERANGE (UINT16_C(68))
-#define __WASI_EROFS (UINT16_C(69))
-#define __WASI_ESPIPE (UINT16_C(70))
-#define __WASI_ESRCH (UINT16_C(71))
-#define __WASI_ESTALE (UINT16_C(72))
-#define __WASI_ESUCCESS (UINT16_C(0))
-#define __WASI_ETIMEDOUT (UINT16_C(73))
-#define __WASI_ETXTBSY (UINT16_C(74))
-#define __WASI_EVENTTYPE_CLOCK (UINT8_C(0))
-#define __WASI_EVENTTYPE_FD_READ (UINT8_C(1))
-#define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2))
-#define __WASI_EVENT_FD_READWRITE_HANGUP (UINT16_C(0x0001))
-#define __WASI_EXDEV (UINT16_C(75))
-#define __WASI_FDFLAG_APPEND (UINT16_C(0x0001))
-#define __WASI_FDFLAG_DSYNC (UINT16_C(0x0002))
-#define __WASI_FDFLAG_NONBLOCK (UINT16_C(0x0004))
-#define __WASI_FDFLAG_RSYNC (UINT16_C(0x0008))
-#define __WASI_FDFLAG_SYNC (UINT16_C(0x0010))
-#define __WASI_FILESTAT_SET_ATIM (UINT16_C(0x0001))
-#define __WASI_FILESTAT_SET_ATIM_NOW (UINT16_C(0x0002))
-#define __WASI_FILESTAT_SET_MTIM (UINT16_C(0x0004))
-#define __WASI_FILESTAT_SET_MTIM_NOW (UINT16_C(0x0008))
-#define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1))
-#define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2))
-#define __WASI_FILETYPE_DIRECTORY (UINT8_C(3))
-#define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4))
-#define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5))
-#define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6))
-#define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7))
-#define __WASI_FILETYPE_UNKNOWN (UINT8_C(0))
-#define __WASI_LOOKUP_SYMLINK_FOLLOW (UINT32_C(0x00000001))
-#define __WASI_O_CREAT (UINT16_C(0x0001))
-#define __WASI_O_DIRECTORY (UINT16_C(0x0002))
-#define __WASI_O_EXCL (UINT16_C(0x0004))
-#define __WASI_O_TRUNC (UINT16_C(0x0008))
-#define __WASI_PREOPENTYPE_DIR (UINT8_C(0))
-#define __WASI_RIGHT_FD_ADVISE (UINT64_C(0x0000000000000080))
-#define __WASI_RIGHT_FD_ALLOCATE (UINT64_C(0x0000000000000100))
-#define __WASI_RIGHT_FD_DATASYNC (UINT64_C(0x0000000000000001))
-#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS (UINT64_C(0x0000000000000008))
-#define __WASI_RIGHT_FD_FILESTAT_GET (UINT64_C(0x0000000000200000))
-#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE (UINT64_C(0x0000000000400000))
-#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES (UINT64_C(0x0000000000800000))
-#define __WASI_RIGHT_FD_READ (UINT64_C(0x0000000000000002))
-#define __WASI_RIGHT_FD_READDIR (UINT64_C(0x0000000000004000))
-#define __WASI_RIGHT_FD_SEEK (UINT64_C(0x0000000000000004))
-#define __WASI_RIGHT_FD_SYNC (UINT64_C(0x0000000000000010))
-#define __WASI_RIGHT_FD_TELL (UINT64_C(0x0000000000000020))
-#define __WASI_RIGHT_FD_WRITE (UINT64_C(0x0000000000000040))
-#define __WASI_RIGHT_PATH_CREATE_DIRECTORY (UINT64_C(0x0000000000000200))
-#define __WASI_RIGHT_PATH_CREATE_FILE (UINT64_C(0x0000000000000400))
-#define __WASI_RIGHT_PATH_FILESTAT_GET (UINT64_C(0x0000000000040000))
-#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE (UINT64_C(0x0000000000080000))
-#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES (UINT64_C(0x0000000000100000))
-#define __WASI_RIGHT_PATH_LINK_SOURCE (UINT64_C(0x0000000000000800))
-#define __WASI_RIGHT_PATH_LINK_TARGET (UINT64_C(0x0000000000001000))
-#define __WASI_RIGHT_PATH_OPEN (UINT64_C(0x0000000000002000))
-#define __WASI_RIGHT_PATH_READLINK (UINT64_C(0x0000000000008000))
-#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY (UINT64_C(0x0000000002000000))
-#define __WASI_RIGHT_PATH_RENAME_SOURCE (UINT64_C(0x0000000000010000))
-#define __WASI_RIGHT_PATH_RENAME_TARGET (UINT64_C(0x0000000000020000))
-#define __WASI_RIGHT_PATH_SYMLINK (UINT64_C(0x0000000001000000))
-#define __WASI_RIGHT_PATH_UNLINK_FILE (UINT64_C(0x0000000004000000))
-#define __WASI_RIGHT_POLL_FD_READWRITE (UINT64_C(0x0000000008000000))
-#define __WASI_RIGHT_SOCK_SHUTDOWN (UINT64_C(0x0000000010000000))
-#define __WASI_SHUT_RD (UINT8_C(0x01))
-#define __WASI_SHUT_WR (UINT8_C(0x02))
-#define __WASI_SIGABRT (UINT8_C(6))
-#define __WASI_SIGALRM (UINT8_C(14))
-#define __WASI_SIGBUS (UINT8_C(7))
-#define __WASI_SIGCHLD (UINT8_C(16))
-#define __WASI_SIGCONT (UINT8_C(17))
-#define __WASI_SIGFPE (UINT8_C(8))
-#define __WASI_SIGHUP (UINT8_C(1))
-#define __WASI_SIGILL (UINT8_C(4))
-#define __WASI_SIGINT (UINT8_C(2))
-#define __WASI_SIGKILL (UINT8_C(9))
-#define __WASI_SIGPIPE (UINT8_C(13))
-#define __WASI_SIGPOLL (UINT8_C(28))
-#define __WASI_SIGPROF (UINT8_C(26))
-#define __WASI_SIGPWR (UINT8_C(29))
-#define __WASI_SIGQUIT (UINT8_C(3))
-#define __WASI_SIGSEGV (UINT8_C(11))
-#define __WASI_SIGSTOP (UINT8_C(18))
-#define __WASI_SIGSYS (UINT8_C(30))
-#define __WASI_SIGTERM (UINT8_C(15))
-#define __WASI_SIGTRAP (UINT8_C(5))
-#define __WASI_SIGTSTP (UINT8_C(19))
-#define __WASI_SIGTTIN (UINT8_C(20))
-#define __WASI_SIGTTOU (UINT8_C(21))
-#define __WASI_SIGURG (UINT8_C(22))
-#define __WASI_SIGUSR1 (UINT8_C(10))
-#define __WASI_SIGUSR2 (UINT8_C(12))
-#define __WASI_SIGVTALRM (UINT8_C(25))
-#define __WASI_SIGWINCH (UINT8_C(27))
-#define __WASI_SIGXCPU (UINT8_C(23))
-#define __WASI_SIGXFSZ (UINT8_C(24))
-#define __WASI_SOCK_RECV_DATA_TRUNCATED (UINT16_C(0x0001))
-#define __WASI_SOCK_RECV_PEEK (UINT16_C(0x0001))
-#define __WASI_SOCK_RECV_WAITALL (UINT16_C(0x0002))
-#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (UINT16_C(0x0001))
-#define __WASI_WHENCE_CUR (UINT8_C(0))
-#define __WASI_WHENCE_END (UINT8_C(1))
-#define __WASI_WHENCE_SET (UINT8_C(2))
+#define __WASI_ERRNO_2BIG ((__wasi_errno_t)1)
+#define __WASI_ERRNO_ACCES ((__wasi_errno_t)2)
+#define __WASI_ERRNO_ADDRINUSE ((__wasi_errno_t)3)
+#define __WASI_ERRNO_ADDRNOTAVAIL ((__wasi_errno_t)4)
+#define __WASI_ERRNO_AFNOSUPPORT ((__wasi_errno_t)5)
+#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
+#define __WASI_ERRNO_ALREADY ((__wasi_errno_t)7)
+#define __WASI_ERRNO_BADF ((__wasi_errno_t)8)
+#define __WASI_ERRNO_BADMSG ((__wasi_errno_t)9)
+#define __WASI_ERRNO_BUSY ((__wasi_errno_t)10)
+#define __WASI_ERRNO_CANCELED ((__wasi_errno_t)11)
+#define __WASI_ERRNO_CHILD ((__wasi_errno_t)12)
+#define __WASI_ERRNO_CONNABORTED ((__wasi_errno_t)13)
+#define __WASI_ERRNO_CONNREFUSED ((__wasi_errno_t)14)
+#define __WASI_ERRNO_CONNRESET ((__wasi_errno_t)15)
+#define __WASI_ERRNO_DEADLK ((__wasi_errno_t)16)
+#define __WASI_ERRNO_DESTADDRREQ ((__wasi_errno_t)17)
+#define __WASI_ERRNO_DOM ((__wasi_errno_t)18)
+#define __WASI_ERRNO_DQUOT ((__wasi_errno_t)19)
+#define __WASI_ERRNO_EXIST ((__wasi_errno_t)20)
+#define __WASI_ERRNO_FAULT ((__wasi_errno_t)21)
+#define __WASI_ERRNO_FBIG ((__wasi_errno_t)22)
+#define __WASI_ERRNO_HOSTUNREACH ((__wasi_errno_t)23)
+#define __WASI_ERRNO_IDRM ((__wasi_errno_t)24)
+#define __WASI_ERRNO_ILSEQ ((__wasi_errno_t)25)
+#define __WASI_ERRNO_INPROGRESS ((__wasi_errno_t)26)
+#define __WASI_ERRNO_INTR ((__wasi_errno_t)27)
+#define __WASI_ERRNO_INVAL ((__wasi_errno_t)28)
+#define __WASI_ERRNO_IO ((__wasi_errno_t)29)
+#define __WASI_ERRNO_ISCONN ((__wasi_errno_t)30)
+#define __WASI_ERRNO_ISDIR ((__wasi_errno_t)31)
+#define __WASI_ERRNO_LOOP ((__wasi_errno_t)32)
+#define __WASI_ERRNO_MFILE ((__wasi_errno_t)33)
+#define __WASI_ERRNO_MLINK ((__wasi_errno_t)34)
+#define __WASI_ERRNO_MSGSIZE ((__wasi_errno_t)35)
+#define __WASI_ERRNO_MULTIHOP ((__wasi_errno_t)36)
+#define __WASI_ERRNO_NAMETOOLONG ((__wasi_errno_t)37)
+#define __WASI_ERRNO_NETDOWN ((__wasi_errno_t)38)
+#define __WASI_ERRNO_NETRESET ((__wasi_errno_t)39)
+#define __WASI_ERRNO_NETUNREACH ((__wasi_errno_t)40)
+#define __WASI_ERRNO_NFILE ((__wasi_errno_t)41)
+#define __WASI_ERRNO_NOBUFS ((__wasi_errno_t)42)
+#define __WASI_ERRNO_NODEV ((__wasi_errno_t)43)
+#define __WASI_ERRNO_NOENT ((__wasi_errno_t)44)
+#define __WASI_ERRNO_NOEXEC ((__wasi_errno_t)45)
+#define __WASI_ERRNO_NOLCK ((__wasi_errno_t)46)
+#define __WASI_ERRNO_NOLINK ((__wasi_errno_t)47)
+#define __WASI_ERRNO_NOMEM ((__wasi_errno_t)48)
+#define __WASI_ERRNO_NOMSG ((__wasi_errno_t)49)
+#define __WASI_ERRNO_NOPROTOOPT ((__wasi_errno_t)50)
+#define __WASI_ERRNO_NOSPC ((__wasi_errno_t)51)
+#define __WASI_ERRNO_NOSYS ((__wasi_errno_t)52)
+#define __WASI_ERRNO_NOTCAPABLE ((__wasi_errno_t)76)
+#define __WASI_ERRNO_NOTCONN ((__wasi_errno_t)53)
+#define __WASI_ERRNO_NOTDIR ((__wasi_errno_t)54)
+#define __WASI_ERRNO_NOTEMPTY ((__wasi_errno_t)55)
+#define __WASI_ERRNO_NOTRECOVERABLE ((__wasi_errno_t)56)
+#define __WASI_ERRNO_NOTSOCK ((__wasi_errno_t)57)
+#define __WASI_ERRNO_NOTSUP ((__wasi_errno_t)58)
+#define __WASI_ERRNO_NOTTY ((__wasi_errno_t)59)
+#define __WASI_ERRNO_NXIO ((__wasi_errno_t)60)
+#define __WASI_ERRNO_OVERFLOW ((__wasi_errno_t)61)
+#define __WASI_ERRNO_OWNERDEAD ((__wasi_errno_t)62)
+#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)
+#define __WASI_ERRNO_PIPE ((__wasi_errno_t)64)
+#define __WASI_ERRNO_PROTO ((__wasi_errno_t)65)
+#define __WASI_ERRNO_PROTONOSUPPORT ((__wasi_errno_t)66)
+#define __WASI_ERRNO_PROTOTYPE ((__wasi_errno_t)67)
+#define __WASI_ERRNO_RANGE ((__wasi_errno_t)68)
+#define __WASI_ERRNO_ROFS ((__wasi_errno_t)69)
+#define __WASI_ERRNO_SPIPE ((__wasi_errno_t)70)
+#define __WASI_ERRNO_SRCH ((__wasi_errno_t)71)
+#define __WASI_ERRNO_STALE ((__wasi_errno_t)72)
+#define __WASI_ERRNO_SUCCESS ((__wasi_errno_t)0)
+#define __WASI_ERRNO_TIMEDOUT ((__wasi_errno_t)73)
+#define __WASI_ERRNO_TXTBSY ((__wasi_errno_t)74)
+#define __WASI_ERRNO_XDEV ((__wasi_errno_t)75)
+#define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)1)
+#define __WASI_EVENTTYPE_CLOCK ((__wasi_eventtype_t)0)
+#define __WASI_EVENTTYPE_FD_READ ((__wasi_eventtype_t)1)
+#define __WASI_EVENTTYPE_FD_WRITE ((__wasi_eventtype_t)2)
+#define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)1)
+#define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)2)
+#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)4)
+#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)8)
+#define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)16)
+#define __WASI_FILETYPE_BLOCK_DEVICE ((__wasi_filetype_t)1)
+#define __WASI_FILETYPE_CHARACTER_DEVICE ((__wasi_filetype_t)2)
+#define __WASI_FILETYPE_DIRECTORY ((__wasi_filetype_t)3)
+#define __WASI_FILETYPE_REGULAR_FILE ((__wasi_filetype_t)4)
+#define __WASI_FILETYPE_SOCKET_DGRAM ((__wasi_filetype_t)5)
+#define __WASI_FILETYPE_SOCKET_STREAM ((__wasi_filetype_t)6)
+#define __WASI_FILETYPE_SYMBOLIC_LINK ((__wasi_filetype_t)7)
+#define __WASI_FILETYPE_UNKNOWN ((__wasi_filetype_t)0)
+#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)1)
+#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)2)
+#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)4)
+#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)8)
+#define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)1)
+#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)1)
+#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)2)
+#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)4)
+#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)8)
+#define __WASI_PREOPENTYPE_DIR ((__wasi_preopentype_t)0)
+#define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)1)
+#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)2)
+#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)128)
+#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)256)
+#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)1)
+#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)8)
+#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)2097152)
+#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)4194304)
+#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)8388608)
+#define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)2)
+#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)16384)
+#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)4)
+#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)16)
+#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)32)
+#define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)64)
+#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)512)
+#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)1024)
+#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)262144)
+#define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)524288)
+#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)1048576)
+#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)2048)
+#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)4096)
+#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)8192)
+#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)32768)
+#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)33554432)
+#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)65536)
+#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)131072)
+#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)16777216)
+#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)67108864)
+#define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)134217728)
+#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)268435456)
+#define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)1)
+#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)1)
+#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)2)
+#define __WASI_SIGNAL_ABRT ((__wasi_signal_t)6)
+#define __WASI_SIGNAL_ALRM ((__wasi_signal_t)14)
+#define __WASI_SIGNAL_BUS ((__wasi_signal_t)7)
+#define __WASI_SIGNAL_CHLD ((__wasi_signal_t)16)
+#define __WASI_SIGNAL_CONT ((__wasi_signal_t)17)
+#define __WASI_SIGNAL_FPE ((__wasi_signal_t)8)
+#define __WASI_SIGNAL_HUP ((__wasi_signal_t)1)
+#define __WASI_SIGNAL_ILL ((__wasi_signal_t)4)
+#define __WASI_SIGNAL_INT ((__wasi_signal_t)2)
+#define __WASI_SIGNAL_KILL ((__wasi_signal_t)9)
+#define __WASI_SIGNAL_NONE ((__wasi_signal_t)0)
+#define __WASI_SIGNAL_PIPE ((__wasi_signal_t)13)
+#define __WASI_SIGNAL_POLL ((__wasi_signal_t)28)
+#define __WASI_SIGNAL_PROF ((__wasi_signal_t)26)
+#define __WASI_SIGNAL_PWR ((__wasi_signal_t)29)
+#define __WASI_SIGNAL_QUIT ((__wasi_signal_t)3)
+#define __WASI_SIGNAL_SEGV ((__wasi_signal_t)11)
+#define __WASI_SIGNAL_STOP ((__wasi_signal_t)18)
+#define __WASI_SIGNAL_SYS ((__wasi_signal_t)30)
+#define __WASI_SIGNAL_TERM ((__wasi_signal_t)15)
+#define __WASI_SIGNAL_TRAP ((__wasi_signal_t)5)
+#define __WASI_SIGNAL_TSTP ((__wasi_signal_t)19)
+#define __WASI_SIGNAL_TTIN ((__wasi_signal_t)20)
+#define __WASI_SIGNAL_TTOU ((__wasi_signal_t)21)
+#define __WASI_SIGNAL_URG ((__wasi_signal_t)22)
+#define __WASI_SIGNAL_USR1 ((__wasi_signal_t)10)
+#define __WASI_SIGNAL_USR2 ((__wasi_signal_t)12)
+#define __WASI_SIGNAL_VTALRM ((__wasi_signal_t)25)
+#define __WASI_SIGNAL_WINCH ((__wasi_signal_t)27)
+#define __WASI_SIGNAL_XCPU ((__wasi_signal_t)23)
+#define __WASI_SIGNAL_XFSZ ((__wasi_signal_t)24)
+#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)1)
+#define __WASI_WHENCE_CUR ((__wasi_whence_t)1)
+#define __WASI_WHENCE_END ((__wasi_whence_t)2)
+#define __WASI_WHENCE_SET ((__wasi_whence_t)0)
 #define __WCHAR_MAX__ 2147483647
 #define __WCHAR_TYPE__ int
 #define __WCHAR_WIDTH__ 32
 #define __tm_zone tm_zone
 #define __va_copy(d,s) __builtin_va_copy(d,s)
 #define __wasi__ 1
-#define __wasi_core_h 
+#define __wasi_api_h 
 #define __wasi_libc_find_relpath_h 
 #define __wasi_libc_h 
 #define __wasilibc___errno_values_h 
index b20b72807045f7c36cdad64549544b23c565d054..58d40a18379ff6f7e0d7c2f952a2513bed8fed8b 100644 (file)
@@ -5,7 +5,7 @@
 #ifndef COMMON_CLOCK_H
 #define COMMON_CLOCK_H
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 // In this implementation we define clockid_t as a pointer type, so that
 // we can implement them as full objects. Right now we only use those
index 9135c69fac000ccdebc7a77d7d4bf43503934f66..ebc1734a52cc2a7180ad98090c04dad2008678d4 100644 (file)
@@ -5,7 +5,7 @@
 #ifndef COMMON_ERRNO_H
 #define COMMON_ERRNO_H
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 #ifdef __wasilibc_unmodified_upstream
 // Translates ENOTCAPABLE to ENOTDIR if not a directory.
index 480125b280e832b50beabcf81f68323ec0cdcab6..293678d823c237eda5164f8f73399e2b1d157748 100644 (file)
@@ -10,7 +10,7 @@
 
 #include <sys/time.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <stdbool.h>
 #include <time.h>
 
index cdb6b677668c84a2520a734c0c54b66f40dd7776..c7af4a5bf0ddf7a4f9236cbfcee94c7e0a8ce4ee 100644 (file)
@@ -6,7 +6,7 @@
 #define COMMON_TLS_H
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <stdalign.h>
 #include <stddef.h>
 
index d944bc014cabda76a966ad932f78e691050b12b7..642400a0513580ffb00d244f8c4847e701a3859a 100644 (file)
@@ -5,7 +5,7 @@
 #ifndef DIRENT_DIRENT_IMPL_H
 #define DIRENT_DIRENT_IMPL_H
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <stddef.h>
 
 struct dirent;
index ead18c5e423040b371f0d4c6d9a3a71883c53d86..325093fc29c4aa09a40e514bb7645d8bd0df9e4f 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <dirent.h>
 #include <errno.h>
 #include <stdlib.h>
@@ -28,7 +28,8 @@ DIR *fdopendir(int fd) {
 #ifdef __wasilibc_unmodified_upstream
       __wasi_file_readdir(fd, dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE,
 #else
-      __wasi_fd_readdir(fd, dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE,
+      // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support.
+      __wasi_fd_readdir(fd, (uint8_t *)dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE,
 #endif
                                 __WASI_DIRCOOKIE_START, &dirp->buffer_used);
   if (error != 0) {
index 2b843457c03789de1c7d10ecf6f1fd53db7d3ce0..c4a2013037ad4bf72c052076b45daf800d51fb73 100644 (file)
@@ -5,7 +5,7 @@
 #include <sys/stat.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <dirent.h>
 #include <errno.h>
 #include <stddef.h>
@@ -94,7 +94,8 @@ struct dirent *readdir(DIR *dirp) {
 #ifdef __wasilibc_unmodified_upstream
         __wasi_file_readdir(dirp->fd, dirp->buffer, dirp->buffer_size,
 #else
-        __wasi_fd_readdir(dirp->fd, dirp->buffer, dirp->buffer_size,
+        // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support.
+        __wasi_fd_readdir(dirp->fd, (uint8_t *)dirp->buffer, dirp->buffer_size,
 #endif
                                   dirp->cookie, &dirp->buffer_used);
     if (error != 0) {
index 850c04a98ef32f7d2b7814d63a5c19cc5debdb0c..8dd58827accfc1b566876f35ef0b4db56a28868c 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <dirent.h>
 
 #include "dirent_impl.h"
index 345234f1b0c8ae81e160b791de0f87a238b39f65..83cdeb91e76013e006f0182730d5cad4a1b9bb89 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <dirent.h>
 #include <errno.h>
@@ -122,7 +122,8 @@ int scandirat(int dirfd, const char *dir, struct dirent ***namelist,
 #ifdef __wasilibc_unmodified_upstream
     __wasi_errno_t error = __wasi_file_readdir(fd, buffer, buffer_size,
 #else
-    __wasi_errno_t error = __wasi_fd_readdir(fd, buffer, buffer_size,
+    // TODO: Remove the cast on `buffer` once the witx is updated with char8 support.
+    __wasi_errno_t error = __wasi_fd_readdir(fd, (uint8_t *)buffer, buffer_size,
 #endif
                                                        cookie, &buffer_used);
     if (error != 0) {
index a9816ecde9febb6a98624e105717e1be8c710c50..d7a27f3fcc0010e07f1b099effb21664c2d2102c 100644 (file)
@@ -3,85 +3,85 @@
 // SPDX-License-Identifier: BSD-2-Clause
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <threads.h>
 
-static_assert(E2BIG == __WASI_E2BIG, "Value mismatch");
-static_assert(EACCES == __WASI_EACCES, "Value mismatch");
-static_assert(EADDRINUSE == __WASI_EADDRINUSE, "Value mismatch");
-static_assert(EADDRNOTAVAIL == __WASI_EADDRNOTAVAIL, "Value mismatch");
-static_assert(EAFNOSUPPORT == __WASI_EAFNOSUPPORT, "Value mismatch");
-static_assert(EAGAIN == __WASI_EAGAIN, "Value mismatch");
-static_assert(EALREADY == __WASI_EALREADY, "Value mismatch");
-static_assert(EBADF == __WASI_EBADF, "Value mismatch");
-static_assert(EBADMSG == __WASI_EBADMSG, "Value mismatch");
-static_assert(EBUSY == __WASI_EBUSY, "Value mismatch");
-static_assert(ECANCELED == __WASI_ECANCELED, "Value mismatch");
-static_assert(ECHILD == __WASI_ECHILD, "Value mismatch");
-static_assert(ECONNABORTED == __WASI_ECONNABORTED, "Value mismatch");
-static_assert(ECONNREFUSED == __WASI_ECONNREFUSED, "Value mismatch");
-static_assert(ECONNRESET == __WASI_ECONNRESET, "Value mismatch");
-static_assert(EDEADLK == __WASI_EDEADLK, "Value mismatch");
-static_assert(EDESTADDRREQ == __WASI_EDESTADDRREQ, "Value mismatch");
-static_assert(EDOM == __WASI_EDOM, "Value mismatch");
-static_assert(EDQUOT == __WASI_EDQUOT, "Value mismatch");
-static_assert(EEXIST == __WASI_EEXIST, "Value mismatch");
-static_assert(EFAULT == __WASI_EFAULT, "Value mismatch");
-static_assert(EFBIG == __WASI_EFBIG, "Value mismatch");
-static_assert(EHOSTUNREACH == __WASI_EHOSTUNREACH, "Value mismatch");
-static_assert(EIDRM == __WASI_EIDRM, "Value mismatch");
-static_assert(EILSEQ == __WASI_EILSEQ, "Value mismatch");
-static_assert(EINPROGRESS == __WASI_EINPROGRESS, "Value mismatch");
-static_assert(EINTR == __WASI_EINTR, "Value mismatch");
-static_assert(EINVAL == __WASI_EINVAL, "Value mismatch");
-static_assert(EIO == __WASI_EIO, "Value mismatch");
-static_assert(EISCONN == __WASI_EISCONN, "Value mismatch");
-static_assert(EISDIR == __WASI_EISDIR, "Value mismatch");
-static_assert(ELOOP == __WASI_ELOOP, "Value mismatch");
-static_assert(EMFILE == __WASI_EMFILE, "Value mismatch");
-static_assert(EMLINK == __WASI_EMLINK, "Value mismatch");
-static_assert(EMSGSIZE == __WASI_EMSGSIZE, "Value mismatch");
-static_assert(EMULTIHOP == __WASI_EMULTIHOP, "Value mismatch");
-static_assert(ENAMETOOLONG == __WASI_ENAMETOOLONG, "Value mismatch");
-static_assert(ENETDOWN == __WASI_ENETDOWN, "Value mismatch");
-static_assert(ENETRESET == __WASI_ENETRESET, "Value mismatch");
-static_assert(ENETUNREACH == __WASI_ENETUNREACH, "Value mismatch");
-static_assert(ENFILE == __WASI_ENFILE, "Value mismatch");
-static_assert(ENOBUFS == __WASI_ENOBUFS, "Value mismatch");
-static_assert(ENODEV == __WASI_ENODEV, "Value mismatch");
-static_assert(ENOENT == __WASI_ENOENT, "Value mismatch");
-static_assert(ENOEXEC == __WASI_ENOEXEC, "Value mismatch");
-static_assert(ENOLCK == __WASI_ENOLCK, "Value mismatch");
-static_assert(ENOLINK == __WASI_ENOLINK, "Value mismatch");
-static_assert(ENOMEM == __WASI_ENOMEM, "Value mismatch");
-static_assert(ENOMSG == __WASI_ENOMSG, "Value mismatch");
-static_assert(ENOPROTOOPT == __WASI_ENOPROTOOPT, "Value mismatch");
-static_assert(ENOSPC == __WASI_ENOSPC, "Value mismatch");
-static_assert(ENOSYS == __WASI_ENOSYS, "Value mismatch");
-static_assert(ENOTCAPABLE == __WASI_ENOTCAPABLE, "Value mismatch");
-static_assert(ENOTCONN == __WASI_ENOTCONN, "Value mismatch");
-static_assert(ENOTDIR == __WASI_ENOTDIR, "Value mismatch");
-static_assert(ENOTEMPTY == __WASI_ENOTEMPTY, "Value mismatch");
-static_assert(ENOTRECOVERABLE == __WASI_ENOTRECOVERABLE, "Value mismatch");
-static_assert(ENOTSOCK == __WASI_ENOTSOCK, "Value mismatch");
-static_assert(ENOTSUP == __WASI_ENOTSUP, "Value mismatch");
-static_assert(ENOTTY == __WASI_ENOTTY, "Value mismatch");
-static_assert(ENXIO == __WASI_ENXIO, "Value mismatch");
-static_assert(EOVERFLOW == __WASI_EOVERFLOW, "Value mismatch");
-static_assert(EOWNERDEAD == __WASI_EOWNERDEAD, "Value mismatch");
-static_assert(EPERM == __WASI_EPERM, "Value mismatch");
-static_assert(EPIPE == __WASI_EPIPE, "Value mismatch");
-static_assert(EPROTO == __WASI_EPROTO, "Value mismatch");
-static_assert(EPROTONOSUPPORT == __WASI_EPROTONOSUPPORT, "Value mismatch");
-static_assert(EPROTOTYPE == __WASI_EPROTOTYPE, "Value mismatch");
-static_assert(ERANGE == __WASI_ERANGE, "Value mismatch");
-static_assert(EROFS == __WASI_EROFS, "Value mismatch");
-static_assert(ESPIPE == __WASI_ESPIPE, "Value mismatch");
-static_assert(ESRCH == __WASI_ESRCH, "Value mismatch");
-static_assert(ESTALE == __WASI_ESTALE, "Value mismatch");
-static_assert(ETIMEDOUT == __WASI_ETIMEDOUT, "Value mismatch");
-static_assert(ETXTBSY == __WASI_ETXTBSY, "Value mismatch");
-static_assert(EXDEV == __WASI_EXDEV, "Value mismatch");
+static_assert(E2BIG == __WASI_ERRNO_2BIG, "Value mismatch");
+static_assert(EACCES == __WASI_ERRNO_ACCES, "Value mismatch");
+static_assert(EADDRINUSE == __WASI_ERRNO_ADDRINUSE, "Value mismatch");
+static_assert(EADDRNOTAVAIL == __WASI_ERRNO_ADDRNOTAVAIL, "Value mismatch");
+static_assert(EAFNOSUPPORT == __WASI_ERRNO_AFNOSUPPORT, "Value mismatch");
+static_assert(EAGAIN == __WASI_ERRNO_AGAIN, "Value mismatch");
+static_assert(EALREADY == __WASI_ERRNO_ALREADY, "Value mismatch");
+static_assert(EBADF == __WASI_ERRNO_BADF, "Value mismatch");
+static_assert(EBADMSG == __WASI_ERRNO_BADMSG, "Value mismatch");
+static_assert(EBUSY == __WASI_ERRNO_BUSY, "Value mismatch");
+static_assert(ECANCELED == __WASI_ERRNO_CANCELED, "Value mismatch");
+static_assert(ECHILD == __WASI_ERRNO_CHILD, "Value mismatch");
+static_assert(ECONNABORTED == __WASI_ERRNO_CONNABORTED, "Value mismatch");
+static_assert(ECONNREFUSED == __WASI_ERRNO_CONNREFUSED, "Value mismatch");
+static_assert(ECONNRESET == __WASI_ERRNO_CONNRESET, "Value mismatch");
+static_assert(EDEADLK == __WASI_ERRNO_DEADLK, "Value mismatch");
+static_assert(EDESTADDRREQ == __WASI_ERRNO_DESTADDRREQ, "Value mismatch");
+static_assert(EDOM == __WASI_ERRNO_DOM, "Value mismatch");
+static_assert(EDQUOT == __WASI_ERRNO_DQUOT, "Value mismatch");
+static_assert(EEXIST == __WASI_ERRNO_EXIST, "Value mismatch");
+static_assert(EFAULT == __WASI_ERRNO_FAULT, "Value mismatch");
+static_assert(EFBIG == __WASI_ERRNO_FBIG, "Value mismatch");
+static_assert(EHOSTUNREACH == __WASI_ERRNO_HOSTUNREACH, "Value mismatch");
+static_assert(EIDRM == __WASI_ERRNO_IDRM, "Value mismatch");
+static_assert(EILSEQ == __WASI_ERRNO_ILSEQ, "Value mismatch");
+static_assert(EINPROGRESS == __WASI_ERRNO_INPROGRESS, "Value mismatch");
+static_assert(EINTR == __WASI_ERRNO_INTR, "Value mismatch");
+static_assert(EINVAL == __WASI_ERRNO_INVAL, "Value mismatch");
+static_assert(EIO == __WASI_ERRNO_IO, "Value mismatch");
+static_assert(EISCONN == __WASI_ERRNO_ISCONN, "Value mismatch");
+static_assert(EISDIR == __WASI_ERRNO_ISDIR, "Value mismatch");
+static_assert(ELOOP == __WASI_ERRNO_LOOP, "Value mismatch");
+static_assert(EMFILE == __WASI_ERRNO_MFILE, "Value mismatch");
+static_assert(EMLINK == __WASI_ERRNO_MLINK, "Value mismatch");
+static_assert(EMSGSIZE == __WASI_ERRNO_MSGSIZE, "Value mismatch");
+static_assert(EMULTIHOP == __WASI_ERRNO_MULTIHOP, "Value mismatch");
+static_assert(ENAMETOOLONG == __WASI_ERRNO_NAMETOOLONG, "Value mismatch");
+static_assert(ENETDOWN == __WASI_ERRNO_NETDOWN, "Value mismatch");
+static_assert(ENETRESET == __WASI_ERRNO_NETRESET, "Value mismatch");
+static_assert(ENETUNREACH == __WASI_ERRNO_NETUNREACH, "Value mismatch");
+static_assert(ENFILE == __WASI_ERRNO_NFILE, "Value mismatch");
+static_assert(ENOBUFS == __WASI_ERRNO_NOBUFS, "Value mismatch");
+static_assert(ENODEV == __WASI_ERRNO_NODEV, "Value mismatch");
+static_assert(ENOENT == __WASI_ERRNO_NOENT, "Value mismatch");
+static_assert(ENOEXEC == __WASI_ERRNO_NOEXEC, "Value mismatch");
+static_assert(ENOLCK == __WASI_ERRNO_NOLCK, "Value mismatch");
+static_assert(ENOLINK == __WASI_ERRNO_NOLINK, "Value mismatch");
+static_assert(ENOMEM == __WASI_ERRNO_NOMEM, "Value mismatch");
+static_assert(ENOMSG == __WASI_ERRNO_NOMSG, "Value mismatch");
+static_assert(ENOPROTOOPT == __WASI_ERRNO_NOPROTOOPT, "Value mismatch");
+static_assert(ENOSPC == __WASI_ERRNO_NOSPC, "Value mismatch");
+static_assert(ENOSYS == __WASI_ERRNO_NOSYS, "Value mismatch");
+static_assert(ENOTCAPABLE == __WASI_ERRNO_NOTCAPABLE, "Value mismatch");
+static_assert(ENOTCONN == __WASI_ERRNO_NOTCONN, "Value mismatch");
+static_assert(ENOTDIR == __WASI_ERRNO_NOTDIR, "Value mismatch");
+static_assert(ENOTEMPTY == __WASI_ERRNO_NOTEMPTY, "Value mismatch");
+static_assert(ENOTRECOVERABLE == __WASI_ERRNO_NOTRECOVERABLE, "Value mismatch");
+static_assert(ENOTSOCK == __WASI_ERRNO_NOTSOCK, "Value mismatch");
+static_assert(ENOTSUP == __WASI_ERRNO_NOTSUP, "Value mismatch");
+static_assert(ENOTTY == __WASI_ERRNO_NOTTY, "Value mismatch");
+static_assert(ENXIO == __WASI_ERRNO_NXIO, "Value mismatch");
+static_assert(EOVERFLOW == __WASI_ERRNO_OVERFLOW, "Value mismatch");
+static_assert(EOWNERDEAD == __WASI_ERRNO_OWNERDEAD, "Value mismatch");
+static_assert(EPERM == __WASI_ERRNO_PERM, "Value mismatch");
+static_assert(EPIPE == __WASI_ERRNO_PIPE, "Value mismatch");
+static_assert(EPROTO == __WASI_ERRNO_PROTO, "Value mismatch");
+static_assert(EPROTONOSUPPORT == __WASI_ERRNO_PROTONOSUPPORT, "Value mismatch");
+static_assert(EPROTOTYPE == __WASI_ERRNO_PROTOTYPE, "Value mismatch");
+static_assert(ERANGE == __WASI_ERRNO_RANGE, "Value mismatch");
+static_assert(EROFS == __WASI_ERRNO_ROFS, "Value mismatch");
+static_assert(ESPIPE == __WASI_ERRNO_SPIPE, "Value mismatch");
+static_assert(ESRCH == __WASI_ERRNO_SRCH, "Value mismatch");
+static_assert(ESTALE == __WASI_ERRNO_STALE, "Value mismatch");
+static_assert(ETIMEDOUT == __WASI_ERRNO_TIMEDOUT, "Value mismatch");
+static_assert(ETXTBSY == __WASI_ERRNO_TXTBSY, "Value mismatch");
+static_assert(EXDEV == __WASI_ERRNO_XDEV, "Value mismatch");
 
 thread_local int errno = 0;
index 3015e62b1b8f5a578327aa45a9aa26f12f7aab46..d4e5597463626d0ae02fae0f2bcf3b02dc6633db 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <stdarg.h>
@@ -33,14 +33,19 @@ int fcntl(int fildes, int cmd, ...) {
       if ((fds.fs_rights_base &
 #ifdef __wasilibc_unmodified_upstream
            (__WASI_RIGHT_FD_READ | __WASI_RIGHT_FILE_READDIR)) != 0) {
+        if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) != 0)
 #else
-           (__WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_READDIR)) != 0) {
+           (__WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR)) != 0) {
+        if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0)
 #endif
-        if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) != 0)
           oflags |= O_RDWR;
         else
           oflags |= O_RDONLY;
+#ifdef __wasilibc_unmodified_upstream
       } else if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) != 0) {
+#else
+      } else if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) {
+#endif
         oflags |= O_WRONLY;
 #ifdef __wasilibc_unmodified_upstream
       } else if ((fds.fs_rights_base & __WASI_RIGHT_PROC_EXEC) != 0) {
index cb11be9686400cea1349a9180d2bffca41a5ecda..12d62b724cc7855668f62784a431d52312c37551 100644 (file)
@@ -5,22 +5,37 @@
 #include <common/errno.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
 
+#ifdef __wasilibc_unmodified_upstream // fstat
 static_assert(O_APPEND == __WASI_FDFLAG_APPEND, "Value mismatch");
 static_assert(O_DSYNC == __WASI_FDFLAG_DSYNC, "Value mismatch");
 static_assert(O_NONBLOCK == __WASI_FDFLAG_NONBLOCK, "Value mismatch");
 static_assert(O_RSYNC == __WASI_FDFLAG_RSYNC, "Value mismatch");
 static_assert(O_SYNC == __WASI_FDFLAG_SYNC, "Value mismatch");
+#else
+static_assert(O_APPEND == __WASI_FDFLAGS_APPEND, "Value mismatch");
+static_assert(O_DSYNC == __WASI_FDFLAGS_DSYNC, "Value mismatch");
+static_assert(O_NONBLOCK == __WASI_FDFLAGS_NONBLOCK, "Value mismatch");
+static_assert(O_RSYNC == __WASI_FDFLAGS_RSYNC, "Value mismatch");
+static_assert(O_SYNC == __WASI_FDFLAGS_SYNC, "Value mismatch");
+#endif
 
+#ifdef __wasilibc_unmodified_upstream // fstat
 static_assert(O_CREAT >> 12 == __WASI_O_CREAT, "Value mismatch");
 static_assert(O_DIRECTORY >> 12 == __WASI_O_DIRECTORY, "Value mismatch");
 static_assert(O_EXCL >> 12 == __WASI_O_EXCL, "Value mismatch");
 static_assert(O_TRUNC >> 12 == __WASI_O_TRUNC, "Value mismatch");
+#else
+static_assert(O_CREAT >> 12 == __WASI_OFLAGS_CREAT, "Value mismatch");
+static_assert(O_DIRECTORY >> 12 == __WASI_OFLAGS_DIRECTORY, "Value mismatch");
+static_assert(O_EXCL >> 12 == __WASI_OFLAGS_EXCL, "Value mismatch");
+static_assert(O_TRUNC >> 12 == __WASI_OFLAGS_TRUNC, "Value mismatch");
+#endif
 
 int openat(int fd, const char *path, int oflag, ...) {
 #ifdef __wasilibc_unmodified_upstream // fstat
@@ -37,13 +52,14 @@ int __wasilibc_openat_nomode(int fd, const char *path, int oflag) {
   __wasi_rights_t min = 0;
 #endif
   __wasi_rights_t max =
-      ~(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ |
 #ifdef __wasilibc_unmodified_upstream // fstat
+      ~(__WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_READ |
         __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FILE_ALLOCATE |
         __WASI_RIGHT_FILE_READDIR | __WASI_RIGHT_FILE_STAT_FPUT_SIZE |
 #else
-        __WASI_RIGHT_FD_WRITE | __WASI_RIGHT_FD_ALLOCATE |
-        __WASI_RIGHT_FD_READDIR | __WASI_RIGHT_FD_FILESTAT_SET_SIZE |
+      ~(__WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_READ |
+        __WASI_RIGHTS_FD_WRITE | __WASI_RIGHTS_FD_ALLOCATE |
+        __WASI_RIGHTS_FD_READDIR | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE |
 #endif
 #ifdef __wasilibc_unmodified_upstream // RIGHT_MEM_MAP_EXEC
         __WASI_RIGHT_MEM_MAP_EXEC);
@@ -63,7 +79,7 @@ int __wasilibc_openat_nomode(int fd, const char *path, int oflag) {
         max |= __WASI_RIGHT_FD_READ | __WASI_RIGHT_FILE_READDIR |
                __WASI_RIGHT_MEM_MAP_EXEC;
 #else
-        max |= __WASI_RIGHT_FD_READ | __WASI_RIGHT_FD_READDIR;
+        max |= __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR;
 #endif
       }
       if ((oflag & O_WRONLY) != 0) {
@@ -72,13 +88,14 @@ int __wasilibc_openat_nomode(int fd, const char *path, int oflag) {
         if ((oflag & O_APPEND) == 0)
           min |= __WASI_RIGHT_FD_SEEK;
 #endif
-        max |= __WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE |
 #ifdef __wasilibc_unmodified_upstream // fstat
+        max |= __WASI_RIGHT_FD_DATASYNC | __WASI_RIGHT_FD_WRITE |
                __WASI_RIGHT_FILE_ALLOCATE |
                __WASI_RIGHT_FILE_STAT_FPUT_SIZE;
 #else
-               __WASI_RIGHT_FD_ALLOCATE |
-               __WASI_RIGHT_FD_FILESTAT_SET_SIZE;
+        max |= __WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_WRITE |
+               __WASI_RIGHTS_FD_ALLOCATE |
+               __WASI_RIGHTS_FD_FILESTAT_SET_SIZE;
 #endif
       }
       break;
@@ -130,7 +147,7 @@ int __wasilibc_openat_nomode(int fd, const char *path, int oflag) {
 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
     lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
 #else
-    lookup_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
+    lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
 #endif
 
   // Open file with appropriate rights.
index 3b06c579331dcce087c3063c359033a5b9886909..af8d7e1a6e46080fa253ec2861b1c7dddd079722 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: BSD-2-Clause
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 
index ea7ae9f555b96fdd9f1b0fe392587540e9af0cb8..44e1842480f353ec256ac61c849b11ae064b3182 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 
index fe28542989d4f1508a072bbeb821b38d1d5ede66..b55651aab1a66f28b1baae7b8cde595d7502ce01 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <poll.h>
 #include <stdbool.h>
@@ -26,7 +26,7 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) {
           .fd_readwrite.fd = pollfd->fd,
           .fd_readwrite.flags = __WASI_SUBSCRIPTION_FD_READWRITE_POLL,
 #else
-          .u.fd_readwrite.fd = pollfd->fd,
+          .u.fd_readwrite.file_descriptor = pollfd->fd,
 #endif
       };
       created_events = true;
@@ -40,7 +40,7 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) {
           .fd_readwrite.fd = pollfd->fd,
           .fd_readwrite.flags = __WASI_SUBSCRIPTION_FD_READWRITE_POLL,
 #else
-          .u.fd_readwrite.fd = pollfd->fd,
+          .u.fd_readwrite.file_descriptor = pollfd->fd,
 #endif
       };
       created_events = true;
@@ -64,7 +64,7 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) {
         .clock.clock_id = __WASI_CLOCK_REALTIME,
         .clock.timeout = (__wasi_timestamp_t)timeout * 1000000,
 #else
-        .u.clock.clock_id = __WASI_CLOCK_REALTIME,
+        .u.clock.id = __WASI_CLOCKID_REALTIME,
         .u.clock.timeout = (__wasi_timestamp_t)timeout * 1000000,
 #endif
     };
@@ -95,10 +95,18 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) {
     if (event->type == __WASI_EVENTTYPE_FD_READ ||
         event->type == __WASI_EVENTTYPE_FD_WRITE) {
       struct pollfd *pollfd = (struct pollfd *)(uintptr_t)event->userdata;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
       if (event->error == __WASI_EBADF) {
+#else
+      if (event->error == __WASI_ERRNO_BADF) {
+#endif
         // Invalid file descriptor.
         pollfd->revents |= POLLNVAL;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
       } else if (event->error == __WASI_EPIPE) {
+#else
+      } else if (event->error == __WASI_ERRNO_PIPE) {
+#endif
         // Hangup on write side of pipe.
         pollfd->revents |= POLLHUP;
       } else if (event->error != 0) {
@@ -111,7 +119,7 @@ int poll(struct pollfd *fds, size_t nfds, int timeout) {
 #ifdef __wasilibc_unmodified_upstream // non-anonymous unions
         if (event->fd_readwrite.flags & __WASI_EVENT_FD_READWRITE_HANGUP)
 #else
-        if (event->u.fd_readwrite.flags & __WASI_EVENT_FD_READWRITE_HANGUP)
+        if (event->u.fd_readwrite.flags & __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP)
 #endif
           pollfd->revents |= POLLHUP;
       }
index 987aec03973f0d388916b0d3e4e78e1041b7c967..e48e3c7463857d1880d22d4d41757edff7e4001e 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <sched.h>
 
index fd5bcb9343392939b74910678f89542210907ceb..f5e4d96c8d013b1c421081aee92ec7a3ed477051 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <stdio.h>
 #include <string.h>
index cba2fc376245542fb0b1df852530e63271b8a07d..10dab2b61e44c3b041af6c8d763ec72ce323153e 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <stdlib.h>
 #include <stdnoreturn.h>
 #include <unistd.h>
index 5aec924e8c6518b45170fca54747e3fece9b5660..e047fc7547a733888bdf3bb155b0804c7de69ee4 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <sys/ioctl.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <stdarg.h>
 
@@ -19,7 +19,7 @@ int ioctl(int fildes, int request, ...) {
               .fd_readwrite.fd = fildes,
               .fd_readwrite.flags = __WASI_SUBSCRIPTION_FD_READWRITE_POLL,
 #else
-              .u.fd_readwrite.fd = fildes,
+              .u.fd_readwrite.file_descriptor = fildes,
 #endif
           },
           {
@@ -27,7 +27,7 @@ int ioctl(int fildes, int request, ...) {
 #ifdef __wasilibc_unmodified_upstream // non-anonymous unions
               .clock.clock_id = __WASI_CLOCK_MONOTONIC,
 #else
-              .u.clock.clock_id = __WASI_CLOCK_MONOTONIC,
+              .u.clock.id = __WASI_CLOCKID_MONOTONIC,
 #endif
           },
       };
@@ -88,9 +88,17 @@ int ioctl(int fildes, int request, ...) {
       va_list ap;
       va_start(ap, request);
       if (*va_arg(ap, const int *) != 0)
+#ifdef __wasilibc_unmodified_upstream // generated constant names
         fds.fs_flags |= __WASI_FDFLAG_NONBLOCK;
+#else
+        fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK;
+#endif
       else
+#ifdef __wasilibc_unmodified_upstream // generated constant names
         fds.fs_flags &= ~__WASI_FDFLAG_NONBLOCK;
+#else
+        fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK;
+#endif
       va_end(ap);
 
       // Update the file descriptor flags.
index 279f13da46cf8dd0bc898bee9d2a2b429e8cbcb7..be1a0788e094b59421946269a9ab269378e5332d 100644 (file)
@@ -6,14 +6,18 @@
 
 #include <sys/resource.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 int getrusage(int who, struct rusage *r_usage) {
   switch (who) {
     case RUSAGE_SELF: {
       __wasi_timestamp_t usertime = 0;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
       (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 1000,
+#else
+      (void)__wasi_clock_time_get(__WASI_CLOCKID_PROCESS_CPUTIME_ID, 1000,
+#endif
                                   &usertime);
       *r_usage = (struct rusage){
           .ru_utime = timestamp_to_timeval(usertime),
index c33ec13fedb98d4731f16771fd2dd4377b4f480c..b31741e301c68808ccc80403571e8155d4275922 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <sys/select.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
@@ -54,7 +54,7 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
           .fd_readwrite.fd = fd,
           .fd_readwrite.flags = __WASI_SUBSCRIPTION_FD_READWRITE_POLL,
 #else
-          .u.fd_readwrite.fd = fd,
+          .u.fd_readwrite.file_descriptor = fd,
 #endif
       };
     }
@@ -72,7 +72,7 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
           .fd_readwrite.fd = fd,
           .fd_readwrite.flags = __WASI_SUBSCRIPTION_FD_READWRITE_POLL,
 #else
-          .u.fd_readwrite.fd = fd,
+          .u.fd_readwrite.file_descriptor = fd,
 #endif
       };
     }
@@ -86,7 +86,7 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
 #ifdef __wasilibc_unmodified_upstream // non-anonymous unions
         .clock.clock_id = __WASI_CLOCK_REALTIME,
 #else
-        .u.clock.clock_id = __WASI_CLOCK_REALTIME,
+        .u.clock.id = __WASI_CLOCKID_REALTIME,
 #endif
     };
 #ifdef __wasilibc_unmodified_upstream // non-anonymous unions
@@ -117,7 +117,11 @@ int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds,
     const __wasi_event_t *event = &events[i];
     if ((event->type == __WASI_EVENTTYPE_FD_READ ||
          event->type == __WASI_EVENTTYPE_FD_WRITE) &&
+#ifdef __wasilibc_unmodified_upstream // generated constant names
         event->error == __WASI_EBADF) {
+#else
+        event->error == __WASI_ERRNO_BADF) {
+#endif
       errno = EBADF;
       return -1;
     }
index d933c4215d4f5123570cfe11721409dd0b7198a5..61af183f4afff266deb942f4a85653a2b9c2e2c4 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <sys/socket.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <string.h>
 
index 799aaf9a8f3b47aebe02e0995d9e05e4b542859d..57e0370a41104e6e02ac09758b3b022e68e1ac0d 100644 (file)
@@ -7,12 +7,17 @@
 #include <sys/socket.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <stdint.h>
 
+#ifdef __wasilibc_unmodified_upstream
 static_assert(MSG_PEEK == __WASI_SOCK_RECV_PEEK, "Value mismatch");
 static_assert(MSG_WAITALL == __WASI_SOCK_RECV_WAITALL, "Value mismatch");
+#else
+static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch");
+static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch");
+#endif
 
 ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) {
   // Validate flags.
index 03e19c4b96e5d802db4916f056c0d4db97bad98e..626110cc5456a113f73c8bb16df9a06ebb402184 100644 (file)
@@ -7,7 +7,7 @@
 #include <sys/socket.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 ssize_t send(int socket, const void *buffer, size_t length, int flags) {
index 475d0b78eebe185b992ae48e00c1c0e8ae4a3514..560f53c30a33b3d84bd37d8029de3601d3aed8bc 100644 (file)
@@ -7,11 +7,16 @@
 #include <sys/socket.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
+#ifdef __wasilibc_unmodified_upstream // generated constant names
 static_assert(SHUT_RD == __WASI_SHUT_RD, "Value mismatch");
 static_assert(SHUT_WR == __WASI_SHUT_WR, "Value mismatch");
+#else
+static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch");
+static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch");
+#endif
 
 int shutdown(int socket, int how) {
   // Validate shutdown flags.
index f4f88fc9fe6e9bbf4dcab2c5717c4eb34bd48b50..ff590d13cb07f9beeecb97de8a8427c578910bf2 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <sys/stat.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 #include "stat_impl.h"
index b70751f1978a2bc780de23a664e87d5e04a8ebf1..375d59de47be22a4b629b7073d26381b1c73c101 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <sys/stat.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
@@ -25,7 +25,7 @@ int fstatat(int fd, const char *restrict path, struct stat *restrict buf,
 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
     lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
 #else
-    lookup_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
+    lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
 #endif
 
   // Perform system call.
index e39f53fadce63e87b35ea156ffd0f0efa81386a1..1ae43ddeb9393e9aee8d0ccc430688ee4c1e2269 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <sys/stat.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 #include "stat_impl.h"
index 41c5ba8302b2a992ce96e685e9d86d432ec8f2c9..75f47a4a68299393510759a151e013a2eb74a917 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <sys/stat.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <string.h>
 
index 9475b7f7f88300b30a40f55437dd84a06bb4c8c5..d1a26fdadd82f8023b4a0e88c6e823cd86f005bf 100644 (file)
@@ -10,7 +10,7 @@
 #include <sys/stat.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <stdbool.h>
 
 static_assert(S_ISBLK(S_IFBLK), "Value mismatch");
@@ -24,12 +24,14 @@ static_assert(S_ISSOCK(S_IFSOCK), "Value mismatch");
 static inline void to_public_stat(const __wasi_filestat_t *in,
                                   struct stat *out) {
   // Ensure that we don't truncate any values.
+#ifdef __wasilibc_unmodified_upstream
   static_assert(sizeof(in->st_dev) == sizeof(out->st_dev), "Size mismatch");
   static_assert(sizeof(in->st_ino) == sizeof(out->st_ino), "Size mismatch");
-#ifdef __wasilibc_unmodified_upstream
   static_assert(sizeof(in->st_filetype) == sizeof(out->__st_filetype),
                 "Size mismatch");
 #else
+  static_assert(sizeof(in->dev) == sizeof(out->st_dev), "Size mismatch");
+  static_assert(sizeof(in->ino) == sizeof(out->st_ino), "Size mismatch");
   /*
    * The non-standard __st_filetype field appears to only be used for shared
    * memory, which we don't currently support.
@@ -37,19 +39,19 @@ static inline void to_public_stat(const __wasi_filestat_t *in,
 #endif
 #ifdef __wasilibc_unmodified_upstream
   static_assert(sizeof(in->st_nlink) == sizeof(out->st_nlink), "Size mismatch");
+  static_assert(sizeof(in->st_size) == sizeof(out->st_size), "Size mismatch");
 #else
   /* nlink_t is 64-bit on wasm32, following the x32 ABI. */
-  static_assert(sizeof(in->st_nlink) <= sizeof(out->st_nlink), "Size shortfall");
+  static_assert(sizeof(in->nlink) <= sizeof(out->st_nlink), "Size shortfall");
+  static_assert(sizeof(in->size) == sizeof(out->st_size), "Size mismatch");
 #endif
-  static_assert(sizeof(in->st_size) == sizeof(out->st_size), "Size mismatch");
 
   *out = (struct stat){
+#ifdef __wasilibc_unmodified_upstream
 #define COPY_FIELD(field) .field = in->field
       COPY_FIELD(st_dev),
       COPY_FIELD(st_ino),
-#ifdef __wasilibc_unmodified_upstream
       .__st_filetype = in->st_filetype,
-#endif
       COPY_FIELD(st_nlink),
       COPY_FIELD(st_size),
 #undef COPY_FIELD
@@ -58,10 +60,23 @@ static inline void to_public_stat(const __wasi_filestat_t *in,
       COPY_TIMESPEC(st_mtim),
       COPY_TIMESPEC(st_ctim),
 #undef COPY_TIMESPEC
+#else
+      .st_dev = in->dev,
+      .st_ino = in->ino,
+      .st_nlink = in->nlink,
+      .st_size = in->size,
+      .st_atim = timestamp_to_timespec(in->atim),
+      .st_mtim = timestamp_to_timespec(in->mtim),
+      .st_ctim = timestamp_to_timespec(in->ctim),
+#endif
   };
 
   // Convert file type to legacy types encoded in st_mode.
+#ifdef __wasilibc_unmodified_upstream
   switch (in->st_filetype) {
+#else
+  switch (in->filetype) {
+#endif
     case __WASI_FILETYPE_BLOCK_DEVICE:
       out->st_mode |= S_IFBLK;
       break;
@@ -98,7 +113,7 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
 #ifdef __wasilibc_unmodified_upstream // fstat
     *flags = __WASI_FILESTAT_ATIM_NOW | __WASI_FILESTAT_MTIM_NOW;
 #else
-    *flags = __WASI_FILESTAT_SET_ATIM_NOW | __WASI_FILESTAT_SET_MTIM_NOW;
+    *flags = __WASI_FSTFLAGS_ATIM_NOW | __WASI_FSTFLAGS_MTIM_NOW;
 #endif
   } else {
     // Set individual timestamps.
@@ -108,7 +123,7 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
 #ifdef __wasilibc_unmodified_upstream // fstat
         *flags |= __WASI_FILESTAT_ATIM_NOW;
 #else
-        *flags |= __WASI_FILESTAT_SET_ATIM_NOW;
+        *flags |= __WASI_FSTFLAGS_ATIM_NOW;
 #endif
         break;
       case UTIME_OMIT:
@@ -118,7 +133,7 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
         *flags |= __WASI_FILESTAT_ATIM;
         if (!timespec_to_timestamp_exact(&times[0], &fs->st_atim))
 #else
-        *flags |= __WASI_FILESTAT_SET_ATIM;
+        *flags |= __WASI_FSTFLAGS_ATIM;
         if (!timespec_to_timestamp_exact(&times[0], st_atim))
 #endif
           return false;
@@ -130,7 +145,7 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
 #ifdef __wasilibc_unmodified_upstream // fstat
         *flags |= __WASI_FILESTAT_MTIM_NOW;
 #else
-        *flags |= __WASI_FILESTAT_SET_MTIM_NOW;
+        *flags |= __WASI_FSTFLAGS_MTIM_NOW;
 #endif
         break;
       case UTIME_OMIT:
@@ -140,7 +155,7 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
         *flags |= __WASI_FILESTAT_MTIM;
         if (!timespec_to_timestamp_exact(&times[1], &fs->st_mtim))
 #else
-        *flags |= __WASI_FILESTAT_SET_MTIM;
+        *flags |= __WASI_FSTFLAGS_MTIM;
         if (!timespec_to_timestamp_exact(&times[1], st_mtim))
 #endif
           return false;
index 28c875cacbd63059ee7c1cbbab83b0b36ae59550..f27b67d6ef36fa1f2325fd33c8bc421de1bc8605 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <sys/stat.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
@@ -40,7 +40,7 @@ int utimensat(int fd, const char *path, const struct timespec times[2],
 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
     lookup.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
 #else
-    lookup_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
+    lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
 #endif
 
   // Perform system call.
index 15a0d56415ef01a88cbe01723952f12bfe22689b..9d33386fb68499c5590d6e4f69d7057f5fe1e8ff 100644 (file)
@@ -6,7 +6,7 @@
 
 #include <sys/time.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 #ifdef __wasilibc_unmodified_upstream
 int gettimeofday(struct timeval *restrict tp, ...) {
@@ -14,7 +14,11 @@ int gettimeofday(struct timeval *restrict tp, ...) {
 int gettimeofday(struct timeval *restrict tp, void *tz) {
 #endif
   __wasi_timestamp_t ts = 0;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
   (void)__wasi_clock_time_get(__WASI_CLOCK_REALTIME, 1000, &ts);
+#else
+  (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
+#endif
   *tp = timestamp_to_timeval(ts);
   return 0;
 }
index c2564e1dd31a4c1085777893275ccaf3d31ba0c3..19dc42a9bace4824630e7986872a44410253b78f 100644 (file)
@@ -7,7 +7,7 @@
 #include <sys/times.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC,
               "Timestamp should need no conversion");
@@ -15,11 +15,19 @@ static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC,
 clock_t times(struct tms *buffer) {
   // Obtain user time.
   __wasi_timestamp_t usertime = 0;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
   (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 0, &usertime);
+#else
+  (void)__wasi_clock_time_get(__WASI_CLOCKID_PROCESS_CPUTIME_ID, 0, &usertime);
+#endif
   *buffer = (struct tms){.tms_utime = usertime};
 
   // Obtain real time.
   __wasi_timestamp_t realtime = 0;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
   (void)__wasi_clock_time_get(__WASI_CLOCK_MONOTONIC, 0, &realtime);
+#else
+  (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &realtime);
+#endif
   return realtime;
 }
index a8213e3332cab30dbda9fddf68e855b4f9d70ddc..36f882dd930dc197f67822d09bab78cbe3ce4cfb 100644 (file)
@@ -5,7 +5,7 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 ssize_t preadv(int fildes, const struct iovec *iov, int iovcnt, off_t offset) {
index 7ebcde84b48eadfc591931add95fdabd4b819c74..d6f885187025c56c27ee9e861cdadcaaa1802607 100644 (file)
@@ -5,7 +5,7 @@
 #include <sys/types.h>
 #include <sys/uio.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 ssize_t pwritev(int fildes, const struct iovec *iov, int iovcnt, off_t offset) {
index da1ca9c9935f880c318c48dec440f9133dbf5481..e3eaebe467827dae5979c2883855f1fcaec231bd 100644 (file)
@@ -5,7 +5,7 @@
 #include <sys/uio.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <stddef.h>
 
index 3dd658ac78adab240da20f9ab3423047fa4f5555..459b1526434a9e1594c2d5537a0c08371b0a9f8b 100644 (file)
@@ -5,7 +5,7 @@
 #include <sys/uio.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <stddef.h>
 
index 3085b6a37a2a8c339673ee9015a609b6a25dd657..bf87ea9f2eece2d2503c4c783503cac4dd73da7d 100644 (file)
@@ -4,9 +4,13 @@
 
 #include <common/clock.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <time.h>
 
 const struct __clockid _CLOCK_MONOTONIC = {
+#ifdef __wasilibc_unmodified_upstream // generated constant names
     .id = __WASI_CLOCK_MONOTONIC,
+#else
+    .id = __WASI_CLOCKID_MONOTONIC,
+#endif
 };
index 895af1fd78c55a7765935b181354fa3fadb462fc..ce872140365d816202aeeeab2f81e558586afa39 100644 (file)
@@ -4,9 +4,13 @@
 
 #include <common/clock.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <time.h>
 
 const struct __clockid _CLOCK_PROCESS_CPUTIME_ID = {
+#ifdef __wasilibc_unmodified_upstream
     .id = __WASI_CLOCK_PROCESS_CPUTIME_ID,
+#else
+    .id = __WASI_CLOCKID_PROCESS_CPUTIME_ID,
+#endif
 };
index 446b706b98314a3899d6f457e12768d272a32b0c..9bbcc6e8aa7678476acda5fdc8d5685b7f0122f1 100644 (file)
@@ -4,9 +4,13 @@
 
 #include <common/clock.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <time.h>
 
 const struct __clockid _CLOCK_REALTIME = {
+#ifdef __wasilibc_unmodified_upstream // generated constant names
     .id = __WASI_CLOCK_REALTIME,
+#else
+    .id = __WASI_CLOCKID_REALTIME,
+#endif
 };
index a47230dc3b13b3ffa845a9d351697017340b3e00..4cfd3ee54dc3fc255f6868bfe963c9499edb4200 100644 (file)
@@ -4,9 +4,13 @@
 
 #include <common/clock.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <time.h>
 
 const struct __clockid _CLOCK_THREAD_CPUTIME_ID = {
+#ifdef __wasilibc_unmodified_upstream // generated constant names
     .id = __WASI_CLOCK_THREAD_CPUTIME_ID,
+#else
+    .id = __WASI_CLOCKID_THREAD_CPUTIME_ID,
+#endif
 };
index 47f15e50c975be3422add361aaadd9c7a7e80fc2..d0748f33c4f91546bbc4073f9cb3746702a07106 100644 (file)
@@ -5,7 +5,7 @@
 #include <common/time.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <time.h>
 
 static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC,
@@ -13,6 +13,10 @@ static_assert(CLOCKS_PER_SEC == NSEC_PER_SEC,
 
 clock_t clock(void) {
   __wasi_timestamp_t ts = 0;
+#ifdef __wasilibc_unmodified_upstream // generated constant names
   (void)__wasi_clock_time_get(__WASI_CLOCK_PROCESS_CPUTIME_ID, 0, &ts);
+#else
+  (void)__wasi_clock_time_get(__WASI_CLOCKID_PROCESS_CPUTIME_ID, 0, &ts);
+#endif
   return ts;
 }
index f34626e789e6c0e8755d594144eab5164c39d7b3..8030d4bb3f24e58b8b370846e65902014d00cdcb 100644 (file)
@@ -5,7 +5,7 @@
 #include <common/clock.h>
 #include <common/time.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <time.h>
 
index 7b98ef3b492507e9b17a8f03067c398db710a4f4..412b61352cbe1111ea8f30d8f162a10150e54f20 100644 (file)
@@ -5,7 +5,7 @@
 #include <common/clock.h>
 #include <common/time.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <time.h>
 
index 23fb80bc930c7d97d44923404ad8cdcaa5d7516c..9b8505f5be8cd26ee94f96a31573b1a8ec048a90 100644 (file)
@@ -6,11 +6,15 @@
 #include <common/time.h>
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <time.h>
 
+#ifdef __wasilibc_unmodified_upstream // generated constant names
 static_assert(TIMER_ABSTIME == __WASI_SUBSCRIPTION_CLOCK_ABSTIME,
+#else
+static_assert(TIMER_ABSTIME == __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME,
+#endif
               "Value mismatch");
 
 #ifdef __wasilibc_unmodified_upstream
@@ -30,7 +34,7 @@ int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp,
       .clock.clock_id = clock_id->id,
       .clock.flags = flags,
 #else
-      .u.clock.clock_id = clock_id->id,
+      .u.clock.id = clock_id->id,
       .u.clock.flags = flags,
 #endif
   };
index f9ef839b0fb57f2dd08ef742275e450673909a06..2c0ba9aeb94d7ea34172e7144d4b541c41605e48 100644 (file)
@@ -4,12 +4,16 @@
 
 #include <common/time.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <time.h>
 
 time_t time(time_t *tloc) {
   __wasi_timestamp_t ts = 0;
+#ifdef __wasilibc_unmodified_upstream
   (void)__wasi_clock_time_get(__WASI_CLOCK_REALTIME, NSEC_PER_SEC, &ts);
+#else
+  (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts);
+#endif
   if (tloc != NULL)
     *tloc = ts / NSEC_PER_SEC;
   return ts / NSEC_PER_SEC;
index a3e0aac4bd893d65ad682e405900164ae417ea1c..2f5814bb655e6547a3c7de019672f816fb1eb487 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index ba253e040c51aa36f5296dcd67bb56c8bf6f4f49..2c8ee84f7f3103ab1de9b1b4cec3d7f632fc477f 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
@@ -25,7 +25,7 @@ int faccessat(int fd, const char *path, int amode, int flag) {
       .flags = __WASI_LOOKUP_SYMLINK_FOLLOW,
   };
 #else
-  __wasi_lookupflags_t lookup_flags = __WASI_LOOKUP_SYMLINK_FOLLOW;
+  __wasi_lookupflags_t lookup_flags = __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
 #endif
   __wasi_filestat_t file;
   __wasi_errno_t error =
@@ -55,20 +55,24 @@ int faccessat(int fd, const char *path, int amode, int flag) {
 
     __wasi_rights_t min = 0;
     if ((amode & R_OK) != 0)
-      min |= file.st_filetype == __WASI_FILETYPE_DIRECTORY
 #ifdef __wasilibc_unmodified_upstream
+      min |= file.st_filetype == __WASI_FILETYPE_DIRECTORY
                  ? __WASI_RIGHT_FILE_READDIR
+                 : __WASI_RIGHT_FD_READ;
 #else
-                 ? __WASI_RIGHT_FD_READDIR
+      min |= file.filetype == __WASI_FILETYPE_DIRECTORY
+                 ? __WASI_RIGHTS_FD_READDIR
+                 : __WASI_RIGHTS_FD_READ;
 #endif
-                 : __WASI_RIGHT_FD_READ;
     if ((amode & W_OK) != 0)
+#ifdef __wasilibc_unmodified_upstream // generated constant names
       min |= __WASI_RIGHT_FD_WRITE;
-    if ((amode & X_OK) != 0 && file.st_filetype != __WASI_FILETYPE_DIRECTORY)
+#else
+      min |= __WASI_RIGHTS_FD_WRITE;
+#endif
 #ifdef __wasilibc_unmodified_upstream // RIGHT_PROC_EXEC
+    if ((amode & X_OK) != 0 && file.st_filetype != __WASI_FILETYPE_DIRECTORY)
       min |= __WASI_RIGHT_PROC_EXEC;
-#else
-      (void)0;
 #endif
 
     if ((min & directory.fs_rights_inheriting) != min) {
index e3ae22ed4d81862f2cbd367e27af5bc446adde23..b821b0668b0151e0c085dc96feceee5d9df9678a 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index fab1db1f833044f7ab61c91a3119f94905bacb2f..733e29479431006a88b75eeb894ae36cd7e8f9f4 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index 1146167f488ad97fb43b3bfde53fd44442710574..c00ccdd4fe418cbcee91b6dfcd6ab9eeb007087b 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index 21e889d93b56134e73074a3e600c2dd901645a5d..f0ec72bd6a5c83bc2248752ee8d55641a7950e32 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <fcntl.h>
 #include <string.h>
@@ -21,7 +21,7 @@ int linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) {
 #ifdef __wasilibc_unmodified_upstream // split out __wasi_lookup_t
     lookup1.flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
 #else
-    lookup1_flags |= __WASI_LOOKUP_SYMLINK_FOLLOW;
+    lookup1_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW;
 #endif
 
   // Perform system call.
index a0e41b70867a9e8d653f3197858518bcff65aae2..f21e328884d75804bc18730dd4bff7ee50fb95fc 100644 (file)
@@ -3,7 +3,7 @@
 // SPDX-License-Identifier: BSD-2-Clause
 
 #include <assert.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index bb970d4bc21ef446ed49c5c5c5e32e50b361758a..9520867a6d8e35e812e8d13790da0f155a55dd4b 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
@@ -23,7 +23,11 @@ ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset) {
     if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) {
 #endif
       // Determine why we got ENOTCAPABLE.
+#ifdef __wasilibc_unmodified_upstream // generated constant names
       if ((fds.fs_rights_base & __WASI_RIGHT_FD_READ) == 0)
+#else
+      if ((fds.fs_rights_base & __WASI_RIGHTS_FD_READ) == 0)
+#endif
         error = EBADF;
       else
         error = ESPIPE;
index 0239cac90b222a9066474ad92739f22732b9283a..56672e5b572d1d3823cbf52100d6ac9b9904c2a6 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
@@ -23,7 +23,11 @@ ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) {
     if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) {
 #endif
       // Determine why we got ENOTCAPABLE.
+#ifdef __wasilibc_unmodified_upstream // generated constant names
       if ((fds.fs_rights_base & __WASI_RIGHT_FD_WRITE) == 0)
+#else
+      if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) == 0)
+#endif
         error = EBADF;
       else
         error = ESPIPE;
index 94375e11e697befa71c2caa969d94ca1abf91783..1582126e1b58cd0f84ae91e94b0748d96a828156 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index 4341e60673026dd2a52305c44fbb63bb37e1e779..1ebffc6001ae2b1408cf51d34bd423eedb551b00 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
@@ -14,10 +14,12 @@ ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf,
   size_t bufused;
 #ifdef __wasilibc_unmodified_upstream
   __wasi_errno_t error = __wasi_file_readlink(fd, path, strlen(path),
+                                                      buf, bufsize, &bufused);
 #else
+  // TODO: Remove the cast on `buf` once the witx is updated with char8 support.
   __wasi_errno_t error = __wasi_path_readlink(fd, path, strlen(path),
+                                                      (uint8_t*)buf, bufsize, &bufused);
 #endif
-                                                      buf, bufsize, &bufused);
   if (error != 0) {
     errno = errno_fixup_directory(fd, error);
     return -1;
index 343f09fe3b9bb8ee6c6e8041af6284900f6cdb2e..9ad06b7aa6b8ee88c16fde34cfcd6a52e81cc1be 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <string.h>
 #include <unistd.h>
index d070bb0d48e19dd738475046383ce6560fbf6151..d970ad1b4bddafa1a2e3702efd89d48ae3af1601 100644 (file)
@@ -4,7 +4,7 @@
 
 #include <common/errno.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #ifdef __wasilibc_unmodified_upstream // unlink
 #else
 #include <wasi/libc.h>
index 5245da8a9bcdc0c02f81f6dec568d80adf40f2d6..a6567e80952a9bafcc87c6a45874e105bc8925e8 100644 (file)
@@ -2,7 +2,7 @@
 //
 // SPDX-License-Identifier: BSD-2-Clause
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index 59ca2bf5250c3ff0bcbf9f5d07da4a2f7fbba585..c9f6644a83df49520bfe03482a2a75e35bbbc676 100644 (file)
@@ -1,6 +1,6 @@
 #include <stdlib.h>
 #include <sysexits.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <wasi/libc-internal.h>
 
@@ -14,14 +14,14 @@ __wasi_errno_t __wasilibc_populate_libpreopen(void) __attribute__((weak));
 void _start(void) {
     // Record the preopened resources, if needed.
     if (&__wasilibc_populate_libpreopen != NULL &&
-        __wasilibc_populate_libpreopen() != __WASI_ESUCCESS)
+        __wasilibc_populate_libpreopen() != __WASI_ERRNO_SUCCESS)
     {
         _Exit(EX_OSERR);
     }
 
     // Fill in the environment from WASI syscalls, if needed.
     if (&__wasilibc_populate_environ != NULL &&
-        __wasilibc_populate_environ() != __WASI_ESUCCESS)
+        __wasilibc_populate_environ() != __WASI_ERRNO_SUCCESS)
     {
         _Exit(EX_OSERR);
     }
index 89fcace9e34478ee643454cd94f1707c6e427a94..e0dfd9b438d8d177a281365111ea20086110d34e 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __wasi_libc_internal_h
 #define __wasi_libc_internal_h
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 #ifdef __cplusplus
 extern "C" {
index 19e2579410cec67e72e76003c5136c747b4afcf1..6d6d412046d778a36456ef63dc0000c53f36bcdc 100644 (file)
@@ -1,84 +1,84 @@
 #ifndef __wasilibc___errno_values_h
 #define __wasilibc___errno_values_h
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
-#define E2BIG __WASI_E2BIG
-#define EACCES __WASI_EACCES
-#define EADDRINUSE __WASI_EADDRINUSE
-#define EADDRNOTAVAIL __WASI_EADDRNOTAVAIL
-#define EAFNOSUPPORT __WASI_EAFNOSUPPORT
-#define EAGAIN __WASI_EAGAIN
-#define EALREADY __WASI_EALREADY
-#define EBADF __WASI_EBADF
-#define EBADMSG __WASI_EBADMSG
-#define EBUSY __WASI_EBUSY
-#define ECANCELED __WASI_ECANCELED
-#define ECHILD __WASI_ECHILD
-#define ECONNABORTED __WASI_ECONNABORTED
-#define ECONNREFUSED __WASI_ECONNREFUSED
-#define ECONNRESET __WASI_ECONNRESET
-#define EDEADLK __WASI_EDEADLK
-#define EDESTADDRREQ __WASI_EDESTADDRREQ
-#define EDOM __WASI_EDOM
-#define EDQUOT __WASI_EDQUOT
-#define EEXIST __WASI_EEXIST
-#define EFAULT __WASI_EFAULT
-#define EFBIG __WASI_EFBIG
-#define EHOSTUNREACH __WASI_EHOSTUNREACH
-#define EIDRM __WASI_EIDRM
-#define EILSEQ __WASI_EILSEQ
-#define EINPROGRESS __WASI_EINPROGRESS
-#define EINTR __WASI_EINTR
-#define EINVAL __WASI_EINVAL
-#define EIO __WASI_EIO
-#define EISCONN __WASI_EISCONN
-#define EISDIR __WASI_EISDIR
-#define ELOOP __WASI_ELOOP
-#define EMFILE __WASI_EMFILE
-#define EMLINK __WASI_EMLINK
-#define EMSGSIZE __WASI_EMSGSIZE
-#define EMULTIHOP __WASI_EMULTIHOP
-#define ENAMETOOLONG __WASI_ENAMETOOLONG
-#define ENETDOWN __WASI_ENETDOWN
-#define ENETRESET __WASI_ENETRESET
-#define ENETUNREACH __WASI_ENETUNREACH
-#define ENFILE __WASI_ENFILE
-#define ENOBUFS __WASI_ENOBUFS
-#define ENODEV __WASI_ENODEV
-#define ENOENT __WASI_ENOENT
-#define ENOEXEC __WASI_ENOEXEC
-#define ENOLCK __WASI_ENOLCK
-#define ENOLINK __WASI_ENOLINK
-#define ENOMEM __WASI_ENOMEM
-#define ENOMSG __WASI_ENOMSG
-#define ENOPROTOOPT __WASI_ENOPROTOOPT
-#define ENOSPC __WASI_ENOSPC
-#define ENOSYS __WASI_ENOSYS
-#define ENOTCONN __WASI_ENOTCONN
-#define ENOTDIR __WASI_ENOTDIR
-#define ENOTEMPTY __WASI_ENOTEMPTY
-#define ENOTRECOVERABLE __WASI_ENOTRECOVERABLE
-#define ENOTSOCK __WASI_ENOTSOCK
-#define ENOTSUP __WASI_ENOTSUP
-#define ENOTTY __WASI_ENOTTY
-#define ENXIO __WASI_ENXIO
-#define EOVERFLOW __WASI_EOVERFLOW
-#define EOWNERDEAD __WASI_EOWNERDEAD
-#define EPERM __WASI_EPERM
-#define EPIPE __WASI_EPIPE
-#define EPROTO __WASI_EPROTO
-#define EPROTONOSUPPORT __WASI_EPROTONOSUPPORT
-#define EPROTOTYPE __WASI_EPROTOTYPE
-#define ERANGE __WASI_ERANGE
-#define EROFS __WASI_EROFS
-#define ESPIPE __WASI_ESPIPE
-#define ESRCH __WASI_ESRCH
-#define ESTALE __WASI_ESTALE
-#define ETIMEDOUT __WASI_ETIMEDOUT
-#define ETXTBSY __WASI_ETXTBSY
-#define EXDEV __WASI_EXDEV
-#define ENOTCAPABLE __WASI_ENOTCAPABLE
+#define E2BIG __WASI_ERRNO_2BIG
+#define EACCES __WASI_ERRNO_ACCES
+#define EADDRINUSE __WASI_ERRNO_ADDRINUSE
+#define EADDRNOTAVAIL __WASI_ERRNO_ADDRNOTAVAIL
+#define EAFNOSUPPORT __WASI_ERRNO_AFNOSUPPORT
+#define EAGAIN __WASI_ERRNO_AGAIN
+#define EALREADY __WASI_ERRNO_ALREADY
+#define EBADF __WASI_ERRNO_BADF
+#define EBADMSG __WASI_ERRNO_BADMSG
+#define EBUSY __WASI_ERRNO_BUSY
+#define ECANCELED __WASI_ERRNO_CANCELED
+#define ECHILD __WASI_ERRNO_CHILD
+#define ECONNABORTED __WASI_ERRNO_CONNABORTED
+#define ECONNREFUSED __WASI_ERRNO_CONNREFUSED
+#define ECONNRESET __WASI_ERRNO_CONNRESET
+#define EDEADLK __WASI_ERRNO_DEADLK
+#define EDESTADDRREQ __WASI_ERRNO_DESTADDRREQ
+#define EDOM __WASI_ERRNO_DOM
+#define EDQUOT __WASI_ERRNO_DQUOT
+#define EEXIST __WASI_ERRNO_EXIST
+#define EFAULT __WASI_ERRNO_FAULT
+#define EFBIG __WASI_ERRNO_FBIG
+#define EHOSTUNREACH __WASI_ERRNO_HOSTUNREACH
+#define EIDRM __WASI_ERRNO_IDRM
+#define EILSEQ __WASI_ERRNO_ILSEQ
+#define EINPROGRESS __WASI_ERRNO_INPROGRESS
+#define EINTR __WASI_ERRNO_INTR
+#define EINVAL __WASI_ERRNO_INVAL
+#define EIO __WASI_ERRNO_IO
+#define EISCONN __WASI_ERRNO_ISCONN
+#define EISDIR __WASI_ERRNO_ISDIR
+#define ELOOP __WASI_ERRNO_LOOP
+#define EMFILE __WASI_ERRNO_MFILE
+#define EMLINK __WASI_ERRNO_MLINK
+#define EMSGSIZE __WASI_ERRNO_MSGSIZE
+#define EMULTIHOP __WASI_ERRNO_MULTIHOP
+#define ENAMETOOLONG __WASI_ERRNO_NAMETOOLONG
+#define ENETDOWN __WASI_ERRNO_NETDOWN
+#define ENETRESET __WASI_ERRNO_NETRESET
+#define ENETUNREACH __WASI_ERRNO_NETUNREACH
+#define ENFILE __WASI_ERRNO_NFILE
+#define ENOBUFS __WASI_ERRNO_NOBUFS
+#define ENODEV __WASI_ERRNO_NODEV
+#define ENOENT __WASI_ERRNO_NOENT
+#define ENOEXEC __WASI_ERRNO_NOEXEC
+#define ENOLCK __WASI_ERRNO_NOLCK
+#define ENOLINK __WASI_ERRNO_NOLINK
+#define ENOMEM __WASI_ERRNO_NOMEM
+#define ENOMSG __WASI_ERRNO_NOMSG
+#define ENOPROTOOPT __WASI_ERRNO_NOPROTOOPT
+#define ENOSPC __WASI_ERRNO_NOSPC
+#define ENOSYS __WASI_ERRNO_NOSYS
+#define ENOTCONN __WASI_ERRNO_NOTCONN
+#define ENOTDIR __WASI_ERRNO_NOTDIR
+#define ENOTEMPTY __WASI_ERRNO_NOTEMPTY
+#define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE
+#define ENOTSOCK __WASI_ERRNO_NOTSOCK
+#define ENOTSUP __WASI_ERRNO_NOTSUP
+#define ENOTTY __WASI_ERRNO_NOTTY
+#define ENXIO __WASI_ERRNO_NXIO
+#define EOVERFLOW __WASI_ERRNO_OVERFLOW
+#define EOWNERDEAD __WASI_ERRNO_OWNERDEAD
+#define EPERM __WASI_ERRNO_PERM
+#define EPIPE __WASI_ERRNO_PIPE
+#define EPROTO __WASI_ERRNO_PROTO
+#define EPROTONOSUPPORT __WASI_ERRNO_PROTONOSUPPORT
+#define EPROTOTYPE __WASI_ERRNO_PROTOTYPE
+#define ERANGE __WASI_ERRNO_RANGE
+#define EROFS __WASI_ERRNO_ROFS
+#define ESPIPE __WASI_ERRNO_SPIPE
+#define ESRCH __WASI_ERRNO_SRCH
+#define ESTALE __WASI_ERRNO_STALE
+#define ETIMEDOUT __WASI_ERRNO_TIMEDOUT
+#define ETXTBSY __WASI_ERRNO_TXTBSY
+#define EXDEV __WASI_ERRNO_XDEV
+#define ENOTCAPABLE __WASI_ERRNO_NOTCAPABLE
 
 #define EOPNOTSUPP ENOTSUP
 #define EWOULDBLOCK EAGAIN
index 32d17a7b61288e068c0a3419312a530f292c5e88..4689d43b2157550111bb6222f6ad5d716a0aef3b 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __wasilibc___header_bits_signal_h
 #define __wasilibc___header_bits_signal_h
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 #define SIGHUP    __WASI_SIGHUP
 #define SIGINT    __WASI_SIGINT
index 1b4914c608ebecda4ad80bec609c78eff26152c5..9779065ca7f6573e3fb3126dedf9f5026c165d27 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __wasilibc___header_dirent_h
 #define __wasilibc___header_dirent_h
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 #define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE
 #define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE
index 24f72eaf971959a15a94139f5c3934b1bb0a29ea..98264395c962402b29a54fbc2b0be13d3f173d30 100644 (file)
@@ -1,19 +1,19 @@
 #ifndef __wasilibc___header_fcntl_h
 #define __wasilibc___header_fcntl_h
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <__seek.h>
 #include <__mode_t.h>
 
-#define O_APPEND __WASI_FDFLAG_APPEND
-#define O_DSYNC __WASI_FDFLAG_DSYNC
-#define O_NONBLOCK __WASI_FDFLAG_NONBLOCK
-#define O_RSYNC __WASI_FDFLAG_RSYNC
-#define O_SYNC __WASI_FDFLAG_SYNC
-#define O_CREAT (__WASI_O_CREAT << 12)
-#define O_DIRECTORY (__WASI_O_DIRECTORY << 12)
-#define O_EXCL (__WASI_O_EXCL << 12)
-#define O_TRUNC (__WASI_O_TRUNC << 12)
+#define O_APPEND __WASI_FDFLAGS_APPEND
+#define O_DSYNC __WASI_FDFLAGS_DSYNC
+#define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK
+#define O_RSYNC __WASI_FDFLAGS_RSYNC
+#define O_SYNC __WASI_FDFLAGS_SYNC
+#define O_CREAT (__WASI_OFLAGS_CREAT << 12)
+#define O_DIRECTORY (__WASI_OFLAGS_DIRECTORY << 12)
+#define O_EXCL (__WASI_OFLAGS_EXCL << 12)
+#define O_TRUNC (__WASI_OFLAGS_TRUNC << 12)
 
 #define O_NOFOLLOW (0x01000000)
 #define O_EXEC     (0x02000000)
index 798b80be1b47f1220071e1821de74ab3e71905a0..9fa8684f830eb683737dbb972c09da16352a36d2 100644 (file)
@@ -5,15 +5,15 @@
 #include <__struct_sockaddr.h>
 #include <__struct_sockaddr_storage.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
-#define SHUT_RD __WASI_SHUT_RD
-#define SHUT_WR __WASI_SHUT_WR
+#define SHUT_RD __WASI_SDFLAGS_RD
+#define SHUT_WR __WASI_SDFLAGS_WR
 #define SHUT_RDWR (SHUT_RD | SHUT_WR)
 
-#define MSG_PEEK __WASI_SOCK_RECV_PEEK
-#define MSG_WAITALL __WASI_SOCK_RECV_WAITALL
-#define MSG_TRUNC __WASI_SOCK_RECV_DATA_TRUNCATED
+#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK
+#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL
+#define MSG_TRUNC __WASI_RIFLAGS_RECV_DATA_TRUNCATED
 
 #define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM
 #define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM
index c625159515c07a483a781d4860d25f8b345e7e17..2d56b1e76fd32452d27219a502dbdeb32a7b273f 100644 (file)
@@ -10,9 +10,9 @@
 #include <__struct_tm.h>
 #include <__typedef_clockid_t.h>
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
-#define TIMER_ABSTIME __WASI_SUBSCRIPTION_CLOCK_ABSTIME
+#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME
 
 extern const struct __clockid _CLOCK_MONOTONIC;
 #define CLOCK_MONOTONIC (&_CLOCK_MONOTONIC)
index 868d04065ed8bdc72539ef573bb8c2035c2e63b9..8824adb1415b05f43a8365bf321d68ad3a2743b2 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef __wasilibc___seek_h
 #define __wasilibc___seek_h
 
-#include <wasi/core.h>
+#include <wasi/api.h>
 
 #define SEEK_CUR __WASI_WHENCE_CUR
 #define SEEK_END __WASI_WHENCE_END
diff --git a/libc-bottom-half/headers/public/wasi/api.h b/libc-bottom-half/headers/public/wasi/api.h
new file mode 100644 (file)
index 0000000..0745241
--- /dev/null
@@ -0,0 +1,2569 @@
+/**
+ * THIS FILE IS AUTO-GENERATED!
+ *
+ * @file
+ * 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.
+ *
+ * [CloudABI]: https://github.com/NuxiNL/cloudlibc
+ */
+
+#ifndef __wasi_api_h
+#define __wasi_api_h
+
+#ifndef __wasi__
+#error <wasi/api.h> is only supported on WASI platforms.
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
+_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
+_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
+_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
+_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");
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// TODO: Encoding this in witx.
+#define __WASI_DIRCOOKIE_START (UINT64_C(0))
+typedef __SIZE_TYPE__ __wasi_size_t;
+
+/**
+ * Non-negative file size or length of a region within a file.
+ */
+typedef uint64_t __wasi_filesize_t;
+
+/**
+ * Timestamp in nanoseconds.
+ */
+typedef uint64_t __wasi_timestamp_t;
+
+/**
+ * Identifiers for clocks.
+ */
+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)
+
+/**
+ * The store-wide monotonic clock, which is defined as a clock measuring
+ * real time, whose value cannot be adjusted and which cannot have negative
+ * clock jumps. The epoch of this clock is undefined. The absolute time
+ * value of this clock therefore has no meaning.
+ */
+#define __WASI_CLOCKID_MONOTONIC ((__wasi_clockid_t)1)
+
+/**
+ * The CPU-time clock associated with the current process.
+ */
+#define __WASI_CLOCKID_PROCESS_CPUTIME_ID ((__wasi_clockid_t)2)
+
+/**
+ * The CPU-time clock associated with the current thread.
+ */
+#define __WASI_CLOCKID_THREAD_CPUTIME_ID ((__wasi_clockid_t)3)
+
+/**
+ * Error codes returned by functions.
+ * Not all of these error codes are returned by the functions provided by this
+ * API; some are used in higher-level library layers, and others are provided
+ * merely for alignment with POSIX.
+ */
+typedef uint16_t __wasi_errno_t;
+
+/**
+ * No error occurred. System call completed successfully.
+ */
+#define __WASI_ERRNO_SUCCESS ((__wasi_errno_t)0)
+
+/**
+ * Argument list too long.
+ */
+#define __WASI_ERRNO_2BIG ((__wasi_errno_t)1)
+
+/**
+ * Permission denied.
+ */
+#define __WASI_ERRNO_ACCES ((__wasi_errno_t)2)
+
+/**
+ * Address in use.
+ */
+#define __WASI_ERRNO_ADDRINUSE ((__wasi_errno_t)3)
+
+/**
+ * Address not available.
+ */
+#define __WASI_ERRNO_ADDRNOTAVAIL ((__wasi_errno_t)4)
+
+/**
+ * Address family not supported.
+ */
+#define __WASI_ERRNO_AFNOSUPPORT ((__wasi_errno_t)5)
+
+/**
+ * Resource unavailable, or operation would block.
+ */
+#define __WASI_ERRNO_AGAIN ((__wasi_errno_t)6)
+
+/**
+ * Connection already in progress.
+ */
+#define __WASI_ERRNO_ALREADY ((__wasi_errno_t)7)
+
+/**
+ * Bad file descriptor.
+ */
+#define __WASI_ERRNO_BADF ((__wasi_errno_t)8)
+
+/**
+ * Bad message.
+ */
+#define __WASI_ERRNO_BADMSG ((__wasi_errno_t)9)
+
+/**
+ * Device or resource busy.
+ */
+#define __WASI_ERRNO_BUSY ((__wasi_errno_t)10)
+
+/**
+ * Operation canceled.
+ */
+#define __WASI_ERRNO_CANCELED ((__wasi_errno_t)11)
+
+/**
+ * No child processes.
+ */
+#define __WASI_ERRNO_CHILD ((__wasi_errno_t)12)
+
+/**
+ * Connection aborted.
+ */
+#define __WASI_ERRNO_CONNABORTED ((__wasi_errno_t)13)
+
+/**
+ * Connection refused.
+ */
+#define __WASI_ERRNO_CONNREFUSED ((__wasi_errno_t)14)
+
+/**
+ * Connection reset.
+ */
+#define __WASI_ERRNO_CONNRESET ((__wasi_errno_t)15)
+
+/**
+ * Resource deadlock would occur.
+ */
+#define __WASI_ERRNO_DEADLK ((__wasi_errno_t)16)
+
+/**
+ * Destination address required.
+ */
+#define __WASI_ERRNO_DESTADDRREQ ((__wasi_errno_t)17)
+
+/**
+ * Mathematics argument out of domain of function.
+ */
+#define __WASI_ERRNO_DOM ((__wasi_errno_t)18)
+
+/**
+ * Reserved.
+ */
+#define __WASI_ERRNO_DQUOT ((__wasi_errno_t)19)
+
+/**
+ * File exists.
+ */
+#define __WASI_ERRNO_EXIST ((__wasi_errno_t)20)
+
+/**
+ * Bad address.
+ */
+#define __WASI_ERRNO_FAULT ((__wasi_errno_t)21)
+
+/**
+ * File too large.
+ */
+#define __WASI_ERRNO_FBIG ((__wasi_errno_t)22)
+
+/**
+ * Host is unreachable.
+ */
+#define __WASI_ERRNO_HOSTUNREACH ((__wasi_errno_t)23)
+
+/**
+ * Identifier removed.
+ */
+#define __WASI_ERRNO_IDRM ((__wasi_errno_t)24)
+
+/**
+ * Illegal byte sequence.
+ */
+#define __WASI_ERRNO_ILSEQ ((__wasi_errno_t)25)
+
+/**
+ * Operation in progress.
+ */
+#define __WASI_ERRNO_INPROGRESS ((__wasi_errno_t)26)
+
+/**
+ * Interrupted function.
+ */
+#define __WASI_ERRNO_INTR ((__wasi_errno_t)27)
+
+/**
+ * Invalid argument.
+ */
+#define __WASI_ERRNO_INVAL ((__wasi_errno_t)28)
+
+/**
+ * I/O error.
+ */
+#define __WASI_ERRNO_IO ((__wasi_errno_t)29)
+
+/**
+ * Socket is connected.
+ */
+#define __WASI_ERRNO_ISCONN ((__wasi_errno_t)30)
+
+/**
+ * Is a directory.
+ */
+#define __WASI_ERRNO_ISDIR ((__wasi_errno_t)31)
+
+/**
+ * Too many levels of symbolic links.
+ */
+#define __WASI_ERRNO_LOOP ((__wasi_errno_t)32)
+
+/**
+ * File descriptor value too large.
+ */
+#define __WASI_ERRNO_MFILE ((__wasi_errno_t)33)
+
+/**
+ * Too many links.
+ */
+#define __WASI_ERRNO_MLINK ((__wasi_errno_t)34)
+
+/**
+ * Message too large.
+ */
+#define __WASI_ERRNO_MSGSIZE ((__wasi_errno_t)35)
+
+/**
+ * Reserved.
+ */
+#define __WASI_ERRNO_MULTIHOP ((__wasi_errno_t)36)
+
+/**
+ * Filename too long.
+ */
+#define __WASI_ERRNO_NAMETOOLONG ((__wasi_errno_t)37)
+
+/**
+ * Network is down.
+ */
+#define __WASI_ERRNO_NETDOWN ((__wasi_errno_t)38)
+
+/**
+ * Connection aborted by network.
+ */
+#define __WASI_ERRNO_NETRESET ((__wasi_errno_t)39)
+
+/**
+ * Network unreachable.
+ */
+#define __WASI_ERRNO_NETUNREACH ((__wasi_errno_t)40)
+
+/**
+ * Too many files open in system.
+ */
+#define __WASI_ERRNO_NFILE ((__wasi_errno_t)41)
+
+/**
+ * No buffer space available.
+ */
+#define __WASI_ERRNO_NOBUFS ((__wasi_errno_t)42)
+
+/**
+ * No such device.
+ */
+#define __WASI_ERRNO_NODEV ((__wasi_errno_t)43)
+
+/**
+ * No such file or directory.
+ */
+#define __WASI_ERRNO_NOENT ((__wasi_errno_t)44)
+
+/**
+ * Executable file format error.
+ */
+#define __WASI_ERRNO_NOEXEC ((__wasi_errno_t)45)
+
+/**
+ * No locks available.
+ */
+#define __WASI_ERRNO_NOLCK ((__wasi_errno_t)46)
+
+/**
+ * Reserved.
+ */
+#define __WASI_ERRNO_NOLINK ((__wasi_errno_t)47)
+
+/**
+ * Not enough space.
+ */
+#define __WASI_ERRNO_NOMEM ((__wasi_errno_t)48)
+
+/**
+ * No message of the desired type.
+ */
+#define __WASI_ERRNO_NOMSG ((__wasi_errno_t)49)
+
+/**
+ * Protocol not available.
+ */
+#define __WASI_ERRNO_NOPROTOOPT ((__wasi_errno_t)50)
+
+/**
+ * No space left on device.
+ */
+#define __WASI_ERRNO_NOSPC ((__wasi_errno_t)51)
+
+/**
+ * Function not supported.
+ */
+#define __WASI_ERRNO_NOSYS ((__wasi_errno_t)52)
+
+/**
+ * The socket is not connected.
+ */
+#define __WASI_ERRNO_NOTCONN ((__wasi_errno_t)53)
+
+/**
+ * Not a directory or a symbolic link to a directory.
+ */
+#define __WASI_ERRNO_NOTDIR ((__wasi_errno_t)54)
+
+/**
+ * Directory not empty.
+ */
+#define __WASI_ERRNO_NOTEMPTY ((__wasi_errno_t)55)
+
+/**
+ * State not recoverable.
+ */
+#define __WASI_ERRNO_NOTRECOVERABLE ((__wasi_errno_t)56)
+
+/**
+ * Not a socket.
+ */
+#define __WASI_ERRNO_NOTSOCK ((__wasi_errno_t)57)
+
+/**
+ * Not supported, or operation not supported on socket.
+ */
+#define __WASI_ERRNO_NOTSUP ((__wasi_errno_t)58)
+
+/**
+ * Inappropriate I/O control operation.
+ */
+#define __WASI_ERRNO_NOTTY ((__wasi_errno_t)59)
+
+/**
+ * No such device or address.
+ */
+#define __WASI_ERRNO_NXIO ((__wasi_errno_t)60)
+
+/**
+ * Value too large to be stored in data type.
+ */
+#define __WASI_ERRNO_OVERFLOW ((__wasi_errno_t)61)
+
+/**
+ * Previous owner died.
+ */
+#define __WASI_ERRNO_OWNERDEAD ((__wasi_errno_t)62)
+
+/**
+ * Operation not permitted.
+ */
+#define __WASI_ERRNO_PERM ((__wasi_errno_t)63)
+
+/**
+ * Broken pipe.
+ */
+#define __WASI_ERRNO_PIPE ((__wasi_errno_t)64)
+
+/**
+ * Protocol error.
+ */
+#define __WASI_ERRNO_PROTO ((__wasi_errno_t)65)
+
+/**
+ * Protocol not supported.
+ */
+#define __WASI_ERRNO_PROTONOSUPPORT ((__wasi_errno_t)66)
+
+/**
+ * Protocol wrong type for socket.
+ */
+#define __WASI_ERRNO_PROTOTYPE ((__wasi_errno_t)67)
+
+/**
+ * Result too large.
+ */
+#define __WASI_ERRNO_RANGE ((__wasi_errno_t)68)
+
+/**
+ * Read-only file system.
+ */
+#define __WASI_ERRNO_ROFS ((__wasi_errno_t)69)
+
+/**
+ * Invalid seek.
+ */
+#define __WASI_ERRNO_SPIPE ((__wasi_errno_t)70)
+
+/**
+ * No such process.
+ */
+#define __WASI_ERRNO_SRCH ((__wasi_errno_t)71)
+
+/**
+ * Reserved.
+ */
+#define __WASI_ERRNO_STALE ((__wasi_errno_t)72)
+
+/**
+ * Connection timed out.
+ */
+#define __WASI_ERRNO_TIMEDOUT ((__wasi_errno_t)73)
+
+/**
+ * Text file busy.
+ */
+#define __WASI_ERRNO_TXTBSY ((__wasi_errno_t)74)
+
+/**
+ * Cross-device link.
+ */
+#define __WASI_ERRNO_XDEV ((__wasi_errno_t)75)
+
+/**
+ * Extension: Capabilities insufficient.
+ */
+#define __WASI_ERRNO_NOTCAPABLE ((__wasi_errno_t)76)
+
+/**
+ * File descriptor rights, determining which actions may be performed.
+ */
+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`.
+ */
+#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)1)
+
+/**
+ * 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)
+
+/**
+ * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`.
+ */
+#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)4)
+
+/**
+ * The right to invoke `fd_fdstat_set_flags`.
+ */
+#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)8)
+
+/**
+ * The right to invoke `fd_sync`.
+ * If `path_open` is set, includes the right to invoke
+ * `path_open` with `fdflag::rsync` and `fdflag::dsync`.
+ */
+#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)16)
+
+/**
+ * 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
+ * invoke `fd_tell`.
+ */
+#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)32)
+
+/**
+ * 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)
+
+/**
+ * The right to invoke `fd_advise`.
+ */
+#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)128)
+
+/**
+ * The right to invoke `fd_allocate`.
+ */
+#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)256)
+
+/**
+ * The right to invoke `path_create_directory`.
+ */
+#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)512)
+
+/**
+ * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`.
+ */
+#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)1024)
+
+/**
+ * The right to invoke `path_link` with the file descriptor as the
+ * source directory.
+ */
+#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)2048)
+
+/**
+ * The right to invoke `path_link` with the file descriptor as the
+ * target directory.
+ */
+#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)4096)
+
+/**
+ * The right to invoke `path_open`.
+ */
+#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)8192)
+
+/**
+ * The right to invoke `fd_readdir`.
+ */
+#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)16384)
+
+/**
+ * The right to invoke `path_readlink`.
+ */
+#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)32768)
+
+/**
+ * The right to invoke `path_rename` with the file descriptor as the source directory.
+ */
+#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)65536)
+
+/**
+ * The right to invoke `path_rename` with the file descriptor as the target directory.
+ */
+#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)131072)
+
+/**
+ * The right to invoke `path_filestat_get`.
+ */
+#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)262144)
+
+/**
+ * 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)
+
+/**
+ * The right to invoke `path_filestat_set_times`.
+ */
+#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)1048576)
+
+/**
+ * The right to invoke `fd_filestat_get`.
+ */
+#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)2097152)
+
+/**
+ * The right to invoke `fd_filestat_set_size`.
+ */
+#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)4194304)
+
+/**
+ * The right to invoke `fd_filestat_set_times`.
+ */
+#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)8388608)
+
+/**
+ * The right to invoke `path_symlink`.
+ */
+#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)16777216)
+
+/**
+ * The right to invoke `path_remove_directory`.
+ */
+#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)33554432)
+
+/**
+ * The right to invoke `path_unlink_file`.
+ */
+#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)67108864)
+
+/**
+ * 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)
+
+/**
+ * The right to invoke `sock_shutdown`.
+ */
+#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)268435456)
+
+/**
+ * A file descriptor index.
+ */
+typedef uint32_t __wasi_fd_t;
+
+/**
+ * A region of memory for scatter/gather reads.
+ */
+typedef struct __wasi_iovec_t {
+    /**
+     * The address of the buffer to be filled.
+     */
+    uint8_t * buf;
+
+    /**
+     * The length of the buffer to be filled.
+     */
+    __wasi_size_t buf_len;
+
+} __wasi_iovec_t;
+
+/**
+ * A region of memory for scatter/gather writes.
+ */
+typedef struct __wasi_ciovec_t {
+    /**
+     * The address of the buffer to be written.
+     */
+    const uint8_t * buf;
+
+    /**
+     * The length of the buffer to be written.
+     */
+    __wasi_size_t buf_len;
+
+} __wasi_ciovec_t;
+
+/**
+ * Relative offset within a file.
+ */
+typedef int64_t __wasi_filedelta_t;
+
+/**
+ * The position relative to which to set the offset of the file descriptor.
+ */
+typedef uint8_t __wasi_whence_t;
+
+/**
+ * Seek relative to start-of-file.
+ */
+#define __WASI_WHENCE_SET ((__wasi_whence_t)0)
+
+/**
+ * Seek relative to current position.
+ */
+#define __WASI_WHENCE_CUR ((__wasi_whence_t)1)
+
+/**
+ * Seek relative to end-of-file.
+ */
+#define __WASI_WHENCE_END ((__wasi_whence_t)2)
+
+/**
+ * A reference to the offset of a directory entry.
+ * 
+ * The value 0 signifies the start of the directory.
+ */
+typedef uint64_t __wasi_dircookie_t;
+
+/**
+ * The type for the $d_namlen field of $dirent.
+ */
+typedef uint32_t __wasi_dirnamlen_t;
+
+/**
+ * File serial number that is unique within its file system.
+ */
+typedef uint64_t __wasi_inode_t;
+
+/**
+ * The type of a file descriptor or file.
+ */
+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)
+
+/**
+ * The file descriptor or file refers to a block device inode.
+ */
+#define __WASI_FILETYPE_BLOCK_DEVICE ((__wasi_filetype_t)1)
+
+/**
+ * The file descriptor or file refers to a character device inode.
+ */
+#define __WASI_FILETYPE_CHARACTER_DEVICE ((__wasi_filetype_t)2)
+
+/**
+ * The file descriptor or file refers to a directory inode.
+ */
+#define __WASI_FILETYPE_DIRECTORY ((__wasi_filetype_t)3)
+
+/**
+ * The file descriptor or file refers to a regular file inode.
+ */
+#define __WASI_FILETYPE_REGULAR_FILE ((__wasi_filetype_t)4)
+
+/**
+ * The file descriptor or file refers to a datagram socket.
+ */
+#define __WASI_FILETYPE_SOCKET_DGRAM ((__wasi_filetype_t)5)
+
+/**
+ * The file descriptor or file refers to a byte-stream socket.
+ */
+#define __WASI_FILETYPE_SOCKET_STREAM ((__wasi_filetype_t)6)
+
+/**
+ * The file refers to a symbolic link inode.
+ */
+#define __WASI_FILETYPE_SYMBOLIC_LINK ((__wasi_filetype_t)7)
+
+/**
+ * A directory entry.
+ */
+typedef struct __wasi_dirent_t {
+    /**
+     * The offset of the next directory entry stored in this directory.
+     */
+    __wasi_dircookie_t d_next;
+
+    /**
+     * The serial number of the file referred to by this directory entry.
+     */
+    __wasi_inode_t d_ino;
+
+    /**
+     * The length of the name of the directory entry.
+     */
+    __wasi_dirnamlen_t d_namlen;
+
+    /**
+     * The type of the file referred to by this directory entry.
+     */
+    __wasi_filetype_t d_type;
+
+} __wasi_dirent_t;
+
+/**
+ * File or memory access pattern advisory information.
+ */
+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)
+
+/**
+ * The application expects to access the specified data sequentially from lower offsets to higher offsets.
+ */
+#define __WASI_ADVICE_SEQUENTIAL ((__wasi_advice_t)1)
+
+/**
+ * The application expects to access the specified data in a random order.
+ */
+#define __WASI_ADVICE_RANDOM ((__wasi_advice_t)2)
+
+/**
+ * The application expects to access the specified data in the near future.
+ */
+#define __WASI_ADVICE_WILLNEED ((__wasi_advice_t)3)
+
+/**
+ * The application expects that it will not access the specified data in the near future.
+ */
+#define __WASI_ADVICE_DONTNEED ((__wasi_advice_t)4)
+
+/**
+ * The application expects to access the specified data once and then not reuse it thereafter.
+ */
+#define __WASI_ADVICE_NOREUSE ((__wasi_advice_t)5)
+
+/**
+ * File descriptor flags.
+ */
+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)
+
+/**
+ * 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)
+
+/**
+ * Non-blocking mode.
+ */
+#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)4)
+
+/**
+ * Synchronized read I/O operations.
+ */
+#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)8)
+
+/**
+ * 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)
+
+/**
+ * File descriptor attributes.
+ */
+typedef struct __wasi_fdstat_t {
+    /**
+     * File type.
+     */
+    __wasi_filetype_t fs_filetype;
+
+    /**
+     * File descriptor flags.
+     */
+    __wasi_fdflags_t fs_flags;
+
+    /**
+     * Rights that apply to this file descriptor.
+     */
+    __wasi_rights_t fs_rights_base;
+
+    /**
+     * Maximum set of rights that may be installed on new file descriptors that
+     * are created through this file descriptor, e.g., through `path_open`.
+     */
+    __wasi_rights_t fs_rights_inheriting;
+
+} __wasi_fdstat_t;
+
+/**
+ * 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;
+
+/**
+ * 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`.
+ */
+#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)1)
+
+/**
+ * Adjust the last data access timestamp to the time of clock `clock::realtime`.
+ */
+#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)2)
+
+/**
+ * Adjust the last data modification timestamp to the value stored in `filestat::st_mtim`.
+ */
+#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)4)
+
+/**
+ * Adjust the last data modification timestamp to the time of clock `clock::realtime`.
+ */
+#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)8)
+
+/**
+ * Flags determining the method of how paths are resolved.
+ */
+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)
+
+/**
+ * Open flags used by `path_open`.
+ */
+typedef uint16_t __wasi_oflags_t;
+
+/**
+ * Create file if it does not exist.
+ */
+#define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)1)
+
+/**
+ * Fail if not a directory.
+ */
+#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)2)
+
+/**
+ * Fail if file already exists.
+ */
+#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)4)
+
+/**
+ * Truncate file to size 0.
+ */
+#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)8)
+
+/**
+ * Number of hard links to an inode.
+ */
+typedef uint64_t __wasi_linkcount_t;
+
+/**
+ * File attributes.
+ */
+typedef struct __wasi_filestat_t {
+    /**
+     * Device ID of device containing the file.
+     */
+    __wasi_device_t dev;
+
+    /**
+     * File serial number.
+     */
+    __wasi_inode_t ino;
+
+    /**
+     * File type.
+     */
+    __wasi_filetype_t filetype;
+
+    /**
+     * Number of hard links to the file.
+     */
+    __wasi_linkcount_t nlink;
+
+    /**
+     * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link.
+     */
+    __wasi_filesize_t size;
+
+    /**
+     * Last data access timestamp.
+     */
+    __wasi_timestamp_t atim;
+
+    /**
+     * Last data modification timestamp.
+     */
+    __wasi_timestamp_t mtim;
+
+    /**
+     * Last file status change timestamp.
+     */
+    __wasi_timestamp_t ctim;
+
+} __wasi_filestat_t;
+
+/**
+ * User-provided value that may be attached to objects that is retained when
+ * extracted from the implementation.
+ */
+typedef uint64_t __wasi_userdata_t;
+
+/**
+ * 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`.
+ */
+#define __WASI_EVENTTYPE_CLOCK ((__wasi_eventtype_t)0)
+
+/**
+ * File descriptor `subscription::u.fd_readwrite.fd` has data
+ * available for reading. This event always triggers for regular files.
+ */
+#define __WASI_EVENTTYPE_FD_READ ((__wasi_eventtype_t)1)
+
+/**
+ * File descriptor `subscription::u.fd_readwrite.fd` has capacity
+ * available for writing. This event always triggers for regular files.
+ */
+#define __WASI_EVENTTYPE_FD_WRITE ((__wasi_eventtype_t)2)
+
+/**
+ * The state of the file descriptor subscribed to with
+ * `eventtype::fd_read` or `eventtype::fd_write`.
+ */
+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)
+
+/**
+ * The contents of an $event when type is `eventtype::fd_read` or
+ * `eventtype::fd_write`.
+ */
+typedef struct __wasi_event_fd_readwrite_t {
+    /**
+     * The number of bytes available for reading or writing.
+     */
+    __wasi_filesize_t nbytes;
+
+    /**
+     * The state of the file descriptor.
+     */
+    __wasi_eventrwflags_t flags;
+
+} __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;
+
+/**
+ * An event that occurred.
+ */
+typedef struct __wasi_event_t {
+    /**
+     * User-provided value that got attached to `subscription::userdata`.
+     */
+    __wasi_userdata_t userdata;
+
+    /**
+     * If non-zero, an error that occurred while processing the subscription request.
+     */
+    __wasi_errno_t error;
+
+    /**
+     * The type of the event that occurred.
+     */
+    __wasi_eventtype_t type;
+
+    /**
+     * The contents of the event.
+     */
+    __wasi_event_u_t u;
+
+} __wasi_event_t;
+
+/**
+ * Flags determining how to interpret the timestamp provided in
+ * `subscription::u.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.`
+ */
+#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)1)
+
+/**
+ * The contents of a $subscription when type is `eventtype::clock`.
+ */
+typedef struct __wasi_subscription_clock_t {
+    /**
+     * The clock against which to compare the timestamp.
+     */
+    __wasi_clockid_t id;
+
+    /**
+     * The absolute or relative timestamp.
+     */
+    __wasi_timestamp_t timeout;
+
+    /**
+     * The amount of time that the implementation may wait additionally
+     * to coalesce with other events.
+     */
+    __wasi_timestamp_t precision;
+
+    /**
+     * Flags specifying whether the timeout is absolute or relative
+     */
+    __wasi_subclockflags_t flags;
+
+} __wasi_subscription_clock_t;
+
+/**
+ * The contents of a $subscription when type is type is
+ * `eventtype::fd_read` or `eventtype::fd_write`.
+ */
+typedef struct __wasi_subscription_fd_readwrite_t {
+    /**
+     * The file descriptor on which to wait for it to become ready for reading or writing.
+     */
+    __wasi_fd_t file_descriptor;
+
+} __wasi_subscription_fd_readwrite_t;
+
+/**
+ * The contents of a $subscription.
+ */
+typedef union __wasi_subscription_u_t {
+    /**
+     * When type is `eventtype::clock`:
+     */
+    __wasi_subscription_clock_t clock;
+
+    /**
+     * When type is `eventtype::fd_read` or `eventtype::fd_write`:
+     */
+    __wasi_subscription_fd_readwrite_t fd_readwrite;
+
+} __wasi_subscription_u_t;
+
+/**
+ * Subscription to an event.
+ */
+typedef struct __wasi_subscription_t {
+    /**
+     * User-provided value that is attached to the subscription in the
+     * implementation and returned through `event::userdata`.
+     */
+    __wasi_userdata_t userdata;
+
+    /**
+     * The type of the event to which to subscribe.
+     */
+    __wasi_eventtype_t type;
+
+    /**
+     * The contents of the subscription.
+     */
+    __wasi_subscription_u_t u;
+
+} __wasi_subscription_t;
+
+/**
+ * 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)
+
+/**
+ * Flags provided to `sock_recv`.
+ */
+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)
+
+/**
+ * On byte-stream sockets, block until the full amount of data can be returned.
+ */
+#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)2)
+
+/**
+ * Flags returned by `sock_recv`.
+ */
+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)
+
+/**
+ * Flags provided to `sock_send`. As there are currently no flags
+ * defined, it must be set to zero.
+ */
+typedef uint16_t __wasi_siflags_t;
+
+/**
+ * Which channels on a socket to shut down.
+ */
+typedef uint8_t __wasi_sdflags_t;
+
+/**
+ * Disables further receive operations.
+ */
+#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)1)
+
+/**
+ * Disables further send operations.
+ */
+#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)2)
+
+/**
+ * Identifiers for preopened capabilities.
+ */
+typedef uint8_t __wasi_preopentype_t;
+
+/**
+ * A pre-opened directory.
+ */
+#define __WASI_PREOPENTYPE_DIR ((__wasi_preopentype_t)0)
+
+/**
+ * The contents of a $prestat when type is `preopentype::dir`.
+ */
+typedef struct __wasi_prestat_dir_t {
+    /**
+     * The length of the directory name for use with `fd_prestat_dir_name`.
+     */
+    __wasi_size_t pr_name_len;
+
+} __wasi_prestat_dir_t;
+
+/**
+ * The contents of an $prestat.
+ */
+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.
+     */
+    __wasi_prestat_u_t u;
+
+} __wasi_prestat_t;
+
+/**
+ * @defgroup wasi_snapshot_preview1
+ * @{
+ */
+
+/**
+ * Read command-line argument data.
+ * The size of the array should match that returned by `wasi_args_sizes_get()`
+ */
+__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__
+));
+
+/**
+ * Return command-line argument data sizes.
+ */
+__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__
+));
+
+/**
+ * Read environment variable data.
+ * The sizes of the buffers should match that returned by `environ.sizes_get()`.
+ */
+__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__
+));
+
+/**
+ * Return command-line argument data sizes.
+ */
+__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__
+));
+
+/**
+ * Return the resolution of a clock.
+ * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, return `WASI_EINVAL`
+ * Note: This is similar to `clock_getres` in POSIX.
+ */
+__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__
+));
+
+/**
+ * Return the time value of a clock.
+ * Note: This is similar to `clock_gettime` in POSIX.
+ */
+__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__
+));
+
+/**
+ * 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,
+
+    /**
+     * The offset within the file to which the advisory applies.
+     */
+    uint64_t offset,
+
+    /**
+     * The length of the region to which the advisory applies.
+     */
+    uint64_t len,
+
+    /**
+     * The advice.
+     */
+    __wasi_advice_t advice
+) __attribute__((
+    __import_module__("wasi_snapshot_preview1"),
+    __import_name__("fd_advise"),
+    __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,
+
+    /**
+     * The offset at which to start the allocation.
+     */
+    uint64_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__
+));
+
+/**
+ * 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__
+));
+
+/**
+ * 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__
+));
+
+/**
+ * Get the attributes of a file descriptor.
+ * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields.
+ */
+__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__
+));
+
+/**
+ * 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,
+
+    /**
+     * 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__
+));
+
+/**
+ * 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
+ */
+__wasi_errno_t __wasi_fd_fdstat_set_rights(
+    uint32_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__
+));
+
+/**
+ * Return the attributes of an open file.
+ */
+__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__
+));
+
+/**
+ * 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,
+
+    /**
+     * The desired file size.
+     */
+    uint64_t size
+) __attribute__((
+    __import_module__("wasi_snapshot_preview1"),
+    __import_name__("fd_filestat_set_size"),
+    __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,
+
+    /**
+     * The desired values of the data access timestamp.
+     */
+    uint64_t atim,
+
+    /**
+     * The desired values of the data modification timestamp.
+     */
+    uint64_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__
+));
+
+/**
+ * Read from a file descriptor, without using and updating the file descriptor's offset.
+ * Note: This is similar to `preadv` in POSIX.
+ */
+__wasi_errno_t __wasi_fd_pread(
+    uint32_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__
+));
+
+/**
+ * Return a description of the given preopened file descriptor.
+ */
+__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__
+));
+
+/**
+ * Return a description of the given preopened file descriptor.
+ */
+__wasi_errno_t __wasi_fd_prestat_dir_name(
+    uint32_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__
+));
+
+/**
+ * Write to a file descriptor, without using and updating the file descriptor's offset.
+ * Note: This is similar to `pwritev` in POSIX.
+ */
+__wasi_errno_t __wasi_fd_pwrite(
+    uint32_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__
+));
+
+/**
+ * Read from a file descriptor.
+ * Note: This is similar to `readv` in POSIX.
+ */
+__wasi_errno_t __wasi_fd_read(
+    uint32_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__
+));
+
+/**
+ * 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
+ * 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.
+ */
+__wasi_errno_t __wasi_fd_readdir(
+    uint32_t fd,
+
+    /**
+     * The buffer where directory entries are stored
+     */
+    uint8_t * buf,
+
+    uint32_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__
+));
+
+/**
+ * Atomically replace a file descriptor by renumbering another file descriptor.
+ * Due to the strong focus on thread safety, this environment does not provide
+ * a mechanism to duplicate or renumber a file descriptor to an arbitrary
+ * number, like `dup2()`. This would be prone to race conditions, as an actual
+ * file descriptor with the same number could be allocated by a different
+ * thread at the same time.
+ * This function provides a way to atomically renumber file descriptors, which
+ * would disappear if `dup2()` were to be removed entirely.
+ */
+__wasi_errno_t __wasi_fd_renumber(
+    uint32_t fd,
+
+    /**
+     * The file descriptor to overwrite.
+     */
+    uint32_t to
+) __attribute__((
+    __import_module__("wasi_snapshot_preview1"),
+    __import_name__("fd_renumber"),
+    __warn_unused_result__
+));
+
+/**
+ * Move the offset of a file descriptor.
+ * Note: This is similar to `lseek` in POSIX.
+ */
+__wasi_errno_t __wasi_fd_seek(
+    uint32_t fd,
+
+    /**
+     * The number of bytes to move.
+     */
+    int64_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__
+));
+
+/**
+ * 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__
+));
+
+/**
+ * Return the current offset of a file descriptor.
+ * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX.
+ */
+__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__
+));
+
+/**
+ * Write to a file descriptor.
+ * Note: This is similar to `writev` in POSIX.
+ */
+__wasi_errno_t __wasi_fd_write(
+    uint32_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__
+));
+
+/**
+ * Create a directory.
+ * Note: This is similar to `mkdirat` in POSIX.
+ */
+__wasi_errno_t __wasi_path_create_directory(
+    uint32_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__
+));
+
+/**
+ * Return the attributes of a file or directory.
+ * Note: This is similar to `stat` in POSIX.
+ */
+__wasi_errno_t __wasi_path_filestat_get(
+    uint32_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__
+));
+
+/**
+ * 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,
+
+    /**
+     * 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,
+
+    /**
+     * The desired values of the data modification timestamp.
+     */
+    uint64_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__
+));
+
+/**
+ * Create a hard link.
+ * Note: This is similar to `linkat` in POSIX.
+ */
+__wasi_errno_t __wasi_path_link(
+    uint32_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,
+
+    /**
+     * 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__
+));
+
+/**
+ * Open a file or directory.
+ * The returned file descriptor is not guaranteed to be the lowest-numbered
+ * file descriptor not currently open; it is randomized to prevent
+ * applications from depending on making assumptions about indexes, since this
+ * is error-prone in multi-threaded contexts. The returned file descriptor is
+ * guaranteed to be less than 2**31.
+ * Note: This is similar to `openat` in POSIX.
+ */
+__wasi_errno_t __wasi_path_open(
+    uint32_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.
+     */
+    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
+     * than specified, if and only if those rights do not apply to the type of
+     * file being opened.
+     * The *base* rights are rights that will apply to operations using the file
+     * descriptor itself, while the *inheriting* rights are rights that apply to
+     * file descriptors derived from it.
+     */
+    __wasi_rights_t fs_rights_base,
+
+    __wasi_rights_t fs_rights_inherting,
+
+    __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__
+));
+
+/**
+ * Read the contents of a symbolic link.
+ * Note: This is similar to `readlinkat` in POSIX.
+ */
+__wasi_errno_t __wasi_path_readlink(
+    uint32_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__
+));
+
+/**
+ * Remove a directory.
+ * Return `ENOTEMPTY` 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,
+
+    /**
+     * 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__
+));
+
+/**
+ * Rename a file or directory.
+ * Note: This is similar to `renameat` in POSIX.
+ */
+__wasi_errno_t __wasi_path_rename(
+    uint32_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,
+
+    /**
+     * 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__
+));
+
+/**
+ * Create a symbolic link.
+ * Note: This is similar to `symlinkat` in POSIX.
+ */
+__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,
+
+    /**
+     * 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__
+));
+
+/**
+ * Unlink a file.
+ * Return `EISDIR` 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,
+
+    /**
+     * 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__
+));
+
+/**
+ * Concurrently poll for the occurrence of a set of events.
+ */
+__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__
+));
+
+/**
+ * Terminate the process normally. An exit code of 0 indicates successful
+ * termination of the program. The meanings of other values is dependent on
+ * the environment.
+ */
+_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__
+));
+
+/**
+ * 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__
+));
+
+/**
+ * Write high-quality random data into a buffer.
+ * This function blocks when the implementation is unable to immediately
+ * provide sufficient high-quality random data.
+ * This function may execute slowly, so when large mounts of random data are
+ * required, it's advisable to use this function to seed a pseudo-random
+ * number generator, rather than to provide the random data directly.
+ */
+__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__
+));
+
+/**
+ * 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`.
+ */
+__wasi_errno_t __wasi_sock_recv(
+    uint32_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__
+));
+
+/**
+ * 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`.
+ */
+__wasi_errno_t __wasi_sock_send(
+    uint32_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__
+));
+
+/**
+ * Shut down socket send and receive channels.
+ * Note: This is similar to `shutdown` in POSIX.
+ */
+__wasi_errno_t __wasi_sock_shutdown(
+    uint32_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__
+));
+
+/** @} */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
diff --git a/libc-bottom-half/headers/public/wasi/core.h b/libc-bottom-half/headers/public/wasi/core.h
deleted file mode 100644 (file)
index ead023e..0000000
+++ /dev/null
@@ -1,744 +0,0 @@
-/*
- * 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.
- *
- * [CloudABI]: https://github.com/NuxiNL/cloudlibc
- */
-
-#ifndef __wasi_core_h
-#define __wasi_core_h
-
-#ifndef __wasi__
-#error <wasi/core.h> is only supported on WASI platforms.
-#endif
-
-#include <stddef.h>
-#include <stdint.h>
-
-_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
-_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
-_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
-_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
-_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");
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef uint8_t __wasi_advice_t;
-#define __WASI_ADVICE_NORMAL     (UINT8_C(0))
-#define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1))
-#define __WASI_ADVICE_RANDOM     (UINT8_C(2))
-#define __WASI_ADVICE_WILLNEED   (UINT8_C(3))
-#define __WASI_ADVICE_DONTNEED   (UINT8_C(4))
-#define __WASI_ADVICE_NOREUSE    (UINT8_C(5))
-
-typedef uint32_t __wasi_clockid_t;
-#define __WASI_CLOCK_REALTIME           (UINT32_C(0))
-#define __WASI_CLOCK_MONOTONIC          (UINT32_C(1))
-#define __WASI_CLOCK_PROCESS_CPUTIME_ID (UINT32_C(2))
-#define __WASI_CLOCK_THREAD_CPUTIME_ID  (UINT32_C(3))
-
-typedef uint64_t __wasi_device_t;
-
-typedef uint64_t __wasi_dircookie_t;
-#define __WASI_DIRCOOKIE_START (UINT64_C(0))
-
-typedef uint16_t __wasi_errno_t;
-#define __WASI_ESUCCESS        (UINT16_C(0))
-#define __WASI_E2BIG           (UINT16_C(1))
-#define __WASI_EACCES          (UINT16_C(2))
-#define __WASI_EADDRINUSE      (UINT16_C(3))
-#define __WASI_EADDRNOTAVAIL   (UINT16_C(4))
-#define __WASI_EAFNOSUPPORT    (UINT16_C(5))
-#define __WASI_EAGAIN          (UINT16_C(6))
-#define __WASI_EALREADY        (UINT16_C(7))
-#define __WASI_EBADF           (UINT16_C(8))
-#define __WASI_EBADMSG         (UINT16_C(9))
-#define __WASI_EBUSY           (UINT16_C(10))
-#define __WASI_ECANCELED       (UINT16_C(11))
-#define __WASI_ECHILD          (UINT16_C(12))
-#define __WASI_ECONNABORTED    (UINT16_C(13))
-#define __WASI_ECONNREFUSED    (UINT16_C(14))
-#define __WASI_ECONNRESET      (UINT16_C(15))
-#define __WASI_EDEADLK         (UINT16_C(16))
-#define __WASI_EDESTADDRREQ    (UINT16_C(17))
-#define __WASI_EDOM            (UINT16_C(18))
-#define __WASI_EDQUOT          (UINT16_C(19))
-#define __WASI_EEXIST          (UINT16_C(20))
-#define __WASI_EFAULT          (UINT16_C(21))
-#define __WASI_EFBIG           (UINT16_C(22))
-#define __WASI_EHOSTUNREACH    (UINT16_C(23))
-#define __WASI_EIDRM           (UINT16_C(24))
-#define __WASI_EILSEQ          (UINT16_C(25))
-#define __WASI_EINPROGRESS     (UINT16_C(26))
-#define __WASI_EINTR           (UINT16_C(27))
-#define __WASI_EINVAL          (UINT16_C(28))
-#define __WASI_EIO             (UINT16_C(29))
-#define __WASI_EISCONN         (UINT16_C(30))
-#define __WASI_EISDIR          (UINT16_C(31))
-#define __WASI_ELOOP           (UINT16_C(32))
-#define __WASI_EMFILE          (UINT16_C(33))
-#define __WASI_EMLINK          (UINT16_C(34))
-#define __WASI_EMSGSIZE        (UINT16_C(35))
-#define __WASI_EMULTIHOP       (UINT16_C(36))
-#define __WASI_ENAMETOOLONG    (UINT16_C(37))
-#define __WASI_ENETDOWN        (UINT16_C(38))
-#define __WASI_ENETRESET       (UINT16_C(39))
-#define __WASI_ENETUNREACH     (UINT16_C(40))
-#define __WASI_ENFILE          (UINT16_C(41))
-#define __WASI_ENOBUFS         (UINT16_C(42))
-#define __WASI_ENODEV          (UINT16_C(43))
-#define __WASI_ENOENT          (UINT16_C(44))
-#define __WASI_ENOEXEC         (UINT16_C(45))
-#define __WASI_ENOLCK          (UINT16_C(46))
-#define __WASI_ENOLINK         (UINT16_C(47))
-#define __WASI_ENOMEM          (UINT16_C(48))
-#define __WASI_ENOMSG          (UINT16_C(49))
-#define __WASI_ENOPROTOOPT     (UINT16_C(50))
-#define __WASI_ENOSPC          (UINT16_C(51))
-#define __WASI_ENOSYS          (UINT16_C(52))
-#define __WASI_ENOTCONN        (UINT16_C(53))
-#define __WASI_ENOTDIR         (UINT16_C(54))
-#define __WASI_ENOTEMPTY       (UINT16_C(55))
-#define __WASI_ENOTRECOVERABLE (UINT16_C(56))
-#define __WASI_ENOTSOCK        (UINT16_C(57))
-#define __WASI_ENOTSUP         (UINT16_C(58))
-#define __WASI_ENOTTY          (UINT16_C(59))
-#define __WASI_ENXIO           (UINT16_C(60))
-#define __WASI_EOVERFLOW       (UINT16_C(61))
-#define __WASI_EOWNERDEAD      (UINT16_C(62))
-#define __WASI_EPERM           (UINT16_C(63))
-#define __WASI_EPIPE           (UINT16_C(64))
-#define __WASI_EPROTO          (UINT16_C(65))
-#define __WASI_EPROTONOSUPPORT (UINT16_C(66))
-#define __WASI_EPROTOTYPE      (UINT16_C(67))
-#define __WASI_ERANGE          (UINT16_C(68))
-#define __WASI_EROFS           (UINT16_C(69))
-#define __WASI_ESPIPE          (UINT16_C(70))
-#define __WASI_ESRCH           (UINT16_C(71))
-#define __WASI_ESTALE          (UINT16_C(72))
-#define __WASI_ETIMEDOUT       (UINT16_C(73))
-#define __WASI_ETXTBSY         (UINT16_C(74))
-#define __WASI_EXDEV           (UINT16_C(75))
-#define __WASI_ENOTCAPABLE     (UINT16_C(76))
-
-typedef uint16_t __wasi_eventrwflags_t;
-#define __WASI_EVENT_FD_READWRITE_HANGUP (UINT16_C(0x0001))
-
-typedef uint8_t __wasi_eventtype_t;
-#define __WASI_EVENTTYPE_CLOCK          (UINT8_C(0))
-#define __WASI_EVENTTYPE_FD_READ        (UINT8_C(1))
-#define __WASI_EVENTTYPE_FD_WRITE       (UINT8_C(2))
-
-typedef uint32_t __wasi_exitcode_t;
-
-typedef uint32_t __wasi_fd_t;
-
-typedef uint16_t __wasi_fdflags_t;
-#define __WASI_FDFLAG_APPEND   (UINT16_C(0x0001))
-#define __WASI_FDFLAG_DSYNC    (UINT16_C(0x0002))
-#define __WASI_FDFLAG_NONBLOCK (UINT16_C(0x0004))
-#define __WASI_FDFLAG_RSYNC    (UINT16_C(0x0008))
-#define __WASI_FDFLAG_SYNC     (UINT16_C(0x0010))
-
-typedef int64_t __wasi_filedelta_t;
-
-typedef uint64_t __wasi_filesize_t;
-
-typedef uint8_t __wasi_filetype_t;
-#define __WASI_FILETYPE_UNKNOWN          (UINT8_C(0))
-#define __WASI_FILETYPE_BLOCK_DEVICE     (UINT8_C(1))
-#define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2))
-#define __WASI_FILETYPE_DIRECTORY        (UINT8_C(3))
-#define __WASI_FILETYPE_REGULAR_FILE     (UINT8_C(4))
-#define __WASI_FILETYPE_SOCKET_DGRAM     (UINT8_C(5))
-#define __WASI_FILETYPE_SOCKET_STREAM    (UINT8_C(6))
-#define __WASI_FILETYPE_SYMBOLIC_LINK    (UINT8_C(7))
-
-typedef uint16_t __wasi_fstflags_t;
-#define __WASI_FILESTAT_SET_ATIM     (UINT16_C(0x0001))
-#define __WASI_FILESTAT_SET_ATIM_NOW (UINT16_C(0x0002))
-#define __WASI_FILESTAT_SET_MTIM     (UINT16_C(0x0004))
-#define __WASI_FILESTAT_SET_MTIM_NOW (UINT16_C(0x0008))
-
-typedef uint64_t __wasi_inode_t;
-
-typedef uint32_t __wasi_linkcount_t;
-
-typedef uint32_t __wasi_lookupflags_t;
-#define __WASI_LOOKUP_SYMLINK_FOLLOW (UINT32_C(0x00000001))
-
-typedef uint16_t __wasi_oflags_t;
-#define __WASI_O_CREAT     (UINT16_C(0x0001))
-#define __WASI_O_DIRECTORY (UINT16_C(0x0002))
-#define __WASI_O_EXCL      (UINT16_C(0x0004))
-#define __WASI_O_TRUNC     (UINT16_C(0x0008))
-
-typedef uint16_t __wasi_riflags_t;
-#define __WASI_SOCK_RECV_PEEK    (UINT16_C(0x0001))
-#define __WASI_SOCK_RECV_WAITALL (UINT16_C(0x0002))
-
-typedef uint64_t __wasi_rights_t;
-#define __WASI_RIGHT_FD_DATASYNC           (UINT64_C(0x0000000000000001))
-#define __WASI_RIGHT_FD_READ               (UINT64_C(0x0000000000000002))
-#define __WASI_RIGHT_FD_SEEK               (UINT64_C(0x0000000000000004))
-#define __WASI_RIGHT_FD_FDSTAT_SET_FLAGS   (UINT64_C(0x0000000000000008))
-#define __WASI_RIGHT_FD_SYNC               (UINT64_C(0x0000000000000010))
-#define __WASI_RIGHT_FD_TELL               (UINT64_C(0x0000000000000020))
-#define __WASI_RIGHT_FD_WRITE              (UINT64_C(0x0000000000000040))
-#define __WASI_RIGHT_FD_ADVISE             (UINT64_C(0x0000000000000080))
-#define __WASI_RIGHT_FD_ALLOCATE           (UINT64_C(0x0000000000000100))
-#define __WASI_RIGHT_PATH_CREATE_DIRECTORY (UINT64_C(0x0000000000000200))
-#define __WASI_RIGHT_PATH_CREATE_FILE      (UINT64_C(0x0000000000000400))
-#define __WASI_RIGHT_PATH_LINK_SOURCE      (UINT64_C(0x0000000000000800))
-#define __WASI_RIGHT_PATH_LINK_TARGET      (UINT64_C(0x0000000000001000))
-#define __WASI_RIGHT_PATH_OPEN             (UINT64_C(0x0000000000002000))
-#define __WASI_RIGHT_FD_READDIR            (UINT64_C(0x0000000000004000))
-#define __WASI_RIGHT_PATH_READLINK         (UINT64_C(0x0000000000008000))
-#define __WASI_RIGHT_PATH_RENAME_SOURCE    (UINT64_C(0x0000000000010000))
-#define __WASI_RIGHT_PATH_RENAME_TARGET    (UINT64_C(0x0000000000020000))
-#define __WASI_RIGHT_PATH_FILESTAT_GET       (UINT64_C(0x0000000000040000))
-#define __WASI_RIGHT_PATH_FILESTAT_SET_SIZE  (UINT64_C(0x0000000000080000))
-#define __WASI_RIGHT_PATH_FILESTAT_SET_TIMES (UINT64_C(0x0000000000100000))
-#define __WASI_RIGHT_FD_FILESTAT_GET        (UINT64_C(0x0000000000200000))
-#define __WASI_RIGHT_FD_FILESTAT_SET_SIZE   (UINT64_C(0x0000000000400000))
-#define __WASI_RIGHT_FD_FILESTAT_SET_TIMES  (UINT64_C(0x0000000000800000))
-#define __WASI_RIGHT_PATH_SYMLINK          (UINT64_C(0x0000000001000000))
-#define __WASI_RIGHT_PATH_REMOVE_DIRECTORY (UINT64_C(0x0000000002000000))
-#define __WASI_RIGHT_PATH_UNLINK_FILE      (UINT64_C(0x0000000004000000))
-#define __WASI_RIGHT_POLL_FD_READWRITE     (UINT64_C(0x0000000008000000))
-#define __WASI_RIGHT_SOCK_SHUTDOWN         (UINT64_C(0x0000000010000000))
-
-typedef uint16_t __wasi_roflags_t;
-#define __WASI_SOCK_RECV_DATA_TRUNCATED (UINT16_C(0x0001))
-
-typedef uint8_t __wasi_sdflags_t;
-#define __WASI_SHUT_RD (UINT8_C(0x01))
-#define __WASI_SHUT_WR (UINT8_C(0x02))
-
-typedef uint16_t __wasi_siflags_t;
-
-typedef uint8_t __wasi_signal_t;
-/* UINT8_C(0) is reserved; POSIX has special semantics for kill(pid, 0). */
-#define __WASI_SIGHUP    (UINT8_C(1))
-#define __WASI_SIGINT    (UINT8_C(2))
-#define __WASI_SIGQUIT   (UINT8_C(3))
-#define __WASI_SIGILL    (UINT8_C(4))
-#define __WASI_SIGTRAP   (UINT8_C(5))
-#define __WASI_SIGABRT   (UINT8_C(6))
-#define __WASI_SIGBUS    (UINT8_C(7))
-#define __WASI_SIGFPE    (UINT8_C(8))
-#define __WASI_SIGKILL   (UINT8_C(9))
-#define __WASI_SIGUSR1   (UINT8_C(10))
-#define __WASI_SIGSEGV   (UINT8_C(11))
-#define __WASI_SIGUSR2   (UINT8_C(12))
-#define __WASI_SIGPIPE   (UINT8_C(13))
-#define __WASI_SIGALRM   (UINT8_C(14))
-#define __WASI_SIGTERM   (UINT8_C(15))
-#define __WASI_SIGCHLD   (UINT8_C(16))
-#define __WASI_SIGCONT   (UINT8_C(17))
-#define __WASI_SIGSTOP   (UINT8_C(18))
-#define __WASI_SIGTSTP   (UINT8_C(19))
-#define __WASI_SIGTTIN   (UINT8_C(20))
-#define __WASI_SIGTTOU   (UINT8_C(21))
-#define __WASI_SIGURG    (UINT8_C(22))
-#define __WASI_SIGXCPU   (UINT8_C(23))
-#define __WASI_SIGXFSZ   (UINT8_C(24))
-#define __WASI_SIGVTALRM (UINT8_C(25))
-#define __WASI_SIGPROF   (UINT8_C(26))
-#define __WASI_SIGWINCH  (UINT8_C(27))
-#define __WASI_SIGPOLL   (UINT8_C(28))
-#define __WASI_SIGPWR    (UINT8_C(29))
-#define __WASI_SIGSYS    (UINT8_C(30))
-
-typedef uint16_t __wasi_subclockflags_t;
-#define __WASI_SUBSCRIPTION_CLOCK_ABSTIME (UINT16_C(0x0001))
-
-typedef uint64_t __wasi_timestamp_t;
-
-typedef uint64_t __wasi_userdata_t;
-
-typedef uint8_t __wasi_whence_t;
-#define __WASI_WHENCE_CUR (UINT8_C(0))
-#define __WASI_WHENCE_END (UINT8_C(1))
-#define __WASI_WHENCE_SET (UINT8_C(2))
-
-typedef uint8_t __wasi_preopentype_t;
-#define __WASI_PREOPENTYPE_DIR              (UINT8_C(0))
-
-typedef struct __wasi_dirent_t {
-    __wasi_dircookie_t d_next;
-    __wasi_inode_t d_ino;
-    uint32_t d_namlen;
-    __wasi_filetype_t d_type;
-} __wasi_dirent_t;
-_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "non-wasi data layout");
-_Static_assert(sizeof(__wasi_dirent_t) == 24, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_dirent_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_event_t {
-    __wasi_userdata_t userdata;
-    __wasi_errno_t error;
-    __wasi_eventtype_t type;
-    union __wasi_event_u {
-        struct __wasi_event_u_fd_readwrite_t {
-            __wasi_filesize_t nbytes;
-            __wasi_eventrwflags_t flags;
-        } fd_readwrite;
-    } u;
-} __wasi_event_t;
-_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_event_t, error) == 8, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_event_t, type) == 10, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_event_t, u.fd_readwrite.nbytes) == 16, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_event_t, u.fd_readwrite.flags) == 24, "non-wasi data layout");
-_Static_assert(sizeof(__wasi_event_t) == 32, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_event_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_prestat_t {
-    __wasi_preopentype_t pr_type;
-    union __wasi_prestat_u {
-        struct __wasi_prestat_u_dir_t {
-            size_t pr_name_len;
-        } dir;
-    } u;
-} __wasi_prestat_t;
-_Static_assert(offsetof(__wasi_prestat_t, pr_type) == 0, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    offsetof(__wasi_prestat_t, u.dir.pr_name_len) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    sizeof(__wasi_prestat_t) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    sizeof(__wasi_prestat_t) == 16, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    _Alignof(__wasi_prestat_t) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    _Alignof(__wasi_prestat_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_fdstat_t {
-    __wasi_filetype_t fs_filetype;
-    __wasi_fdflags_t fs_flags;
-    __wasi_rights_t fs_rights_base;
-    __wasi_rights_t fs_rights_inheriting;
-} __wasi_fdstat_t;
-_Static_assert(
-    offsetof(__wasi_fdstat_t, fs_filetype) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16,
-    "non-wasi data layout");
-_Static_assert(sizeof(__wasi_fdstat_t) == 24, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_filestat_t {
-    __wasi_device_t st_dev;
-    __wasi_inode_t st_ino;
-    __wasi_filetype_t st_filetype;
-    __wasi_linkcount_t st_nlink;
-    __wasi_filesize_t st_size;
-    __wasi_timestamp_t st_atim;
-    __wasi_timestamp_t st_mtim;
-    __wasi_timestamp_t st_ctim;
-} __wasi_filestat_t;
-_Static_assert(offsetof(__wasi_filestat_t, st_dev) == 0, "non-wasi data layout");
-_Static_assert(offsetof(__wasi_filestat_t, st_ino) == 8, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_filestat_t, st_filetype) == 16, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_filestat_t, st_nlink) == 20, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_filestat_t, st_size) == 24, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_filestat_t, st_atim) == 32, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_filestat_t, st_mtim) == 40, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_filestat_t, st_ctim) == 48, "non-wasi data layout");
-_Static_assert(sizeof(__wasi_filestat_t) == 56, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_filestat_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_ciovec_t {
-    const void *buf;
-    size_t buf_len;
-} __wasi_ciovec_t;
-_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    offsetof(__wasi_ciovec_t, buf_len) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    offsetof(__wasi_ciovec_t, buf_len) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    sizeof(__wasi_ciovec_t) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    sizeof(__wasi_ciovec_t) == 16, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    _Alignof(__wasi_ciovec_t) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    _Alignof(__wasi_ciovec_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_iovec_t {
-    void *buf;
-    size_t buf_len;
-} __wasi_iovec_t;
-_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    offsetof(__wasi_iovec_t, buf_len) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    offsetof(__wasi_iovec_t, buf_len) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    sizeof(__wasi_iovec_t) == 8, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    sizeof(__wasi_iovec_t) == 16, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 4 ||
-    _Alignof(__wasi_iovec_t) == 4, "non-wasi data layout");
-_Static_assert(sizeof(void *) != 8 ||
-    _Alignof(__wasi_iovec_t) == 8, "non-wasi data layout");
-
-typedef struct __wasi_subscription_t {
-    __wasi_userdata_t userdata;
-    __wasi_eventtype_t type;
-    union __wasi_subscription_u {
-        struct __wasi_subscription_u_clock_t {
-            __wasi_userdata_t identifier;
-            __wasi_clockid_t clock_id;
-            __wasi_timestamp_t timeout;
-            __wasi_timestamp_t precision;
-            __wasi_subclockflags_t flags;
-        } clock;
-        struct __wasi_subscription_u_fd_readwrite_t {
-            __wasi_fd_t fd;
-        } fd_readwrite;
-    } u;
-} __wasi_subscription_t;
-_Static_assert(
-    offsetof(__wasi_subscription_t, userdata) == 0, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, type) == 8, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, u.clock.identifier) == 16,
-    "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, u.clock.clock_id) == 24,
-    "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, u.clock.timeout) == 32, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, u.clock.precision) == 40,
-    "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, u.clock.flags) == 48, "non-wasi data layout");
-_Static_assert(
-    offsetof(__wasi_subscription_t, u.fd_readwrite.fd) == 16,
-    "non-wasi data layout");
-_Static_assert(sizeof(__wasi_subscription_t) == 56, "non-wasi data layout");
-_Static_assert(_Alignof(__wasi_subscription_t) == 8, "non-wasi data layout");
-
-#define __WASI_SYSCALL_NAME(name) \
-    __attribute__((__import_module__("wasi_unstable"), __import_name__(#name)))
-
-__wasi_errno_t __wasi_args_get(
-    char **argv,
-    char *argv_buf
-) __WASI_SYSCALL_NAME(args_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_args_sizes_get(
-    size_t *argc,
-    size_t *argv_buf_size
-) __WASI_SYSCALL_NAME(args_sizes_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_clock_res_get(
-    __wasi_clockid_t clock_id,
-    __wasi_timestamp_t *resolution
-) __WASI_SYSCALL_NAME(clock_res_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_clock_time_get(
-    __wasi_clockid_t clock_id,
-    __wasi_timestamp_t precision,
-    __wasi_timestamp_t *time
-) __WASI_SYSCALL_NAME(clock_time_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_environ_get(
-    char **environ,
-    char *environ_buf
-) __WASI_SYSCALL_NAME(environ_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_environ_sizes_get(
-    size_t *environ_count,
-    size_t *environ_buf_size
-) __WASI_SYSCALL_NAME(environ_sizes_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_prestat_get(
-    __wasi_fd_t fd,
-    __wasi_prestat_t *buf
-) __WASI_SYSCALL_NAME(fd_prestat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_prestat_dir_name(
-    __wasi_fd_t fd,
-    char *path,
-    size_t path_len
-) __WASI_SYSCALL_NAME(fd_prestat_dir_name) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_close(
-    __wasi_fd_t fd
-) __WASI_SYSCALL_NAME(fd_close) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_datasync(
-    __wasi_fd_t fd
-) __WASI_SYSCALL_NAME(fd_datasync) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_pread(
-    __wasi_fd_t fd,
-    const __wasi_iovec_t *iovs,
-    size_t iovs_len,
-    __wasi_filesize_t offset,
-    size_t *nread
-) __WASI_SYSCALL_NAME(fd_pread) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_pwrite(
-    __wasi_fd_t fd,
-    const __wasi_ciovec_t *iovs,
-    size_t iovs_len,
-    __wasi_filesize_t offset,
-    size_t *nwritten
-) __WASI_SYSCALL_NAME(fd_pwrite) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_read(
-    __wasi_fd_t fd,
-    const __wasi_iovec_t *iovs,
-    size_t iovs_len,
-    size_t *nread
-) __WASI_SYSCALL_NAME(fd_read) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_renumber(
-    __wasi_fd_t from,
-    __wasi_fd_t to
-) __WASI_SYSCALL_NAME(fd_renumber) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_seek(
-    __wasi_fd_t fd,
-    __wasi_filedelta_t offset,
-    __wasi_whence_t whence,
-    __wasi_filesize_t *newoffset
-) __WASI_SYSCALL_NAME(fd_seek) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_tell(
-    __wasi_fd_t fd,
-    __wasi_filesize_t *newoffset
-) __WASI_SYSCALL_NAME(fd_tell) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_fdstat_get(
-    __wasi_fd_t fd,
-    __wasi_fdstat_t *buf
-) __WASI_SYSCALL_NAME(fd_fdstat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_fdstat_set_flags(
-    __wasi_fd_t fd,
-    __wasi_fdflags_t flags
-) __WASI_SYSCALL_NAME(fd_fdstat_set_flags) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_fdstat_set_rights(
-    __wasi_fd_t fd,
-    __wasi_rights_t fs_rights_base,
-    __wasi_rights_t fs_rights_inheriting
-) __WASI_SYSCALL_NAME(fd_fdstat_set_rights) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_sync(
-    __wasi_fd_t fd
-) __WASI_SYSCALL_NAME(fd_sync) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_write(
-    __wasi_fd_t fd,
-    const __wasi_ciovec_t *iovs,
-    size_t iovs_len,
-    size_t *nwritten
-) __WASI_SYSCALL_NAME(fd_write) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_advise(
-    __wasi_fd_t fd,
-    __wasi_filesize_t offset,
-    __wasi_filesize_t len,
-    __wasi_advice_t advice
-) __WASI_SYSCALL_NAME(fd_advise) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_allocate(
-    __wasi_fd_t fd,
-    __wasi_filesize_t offset,
-    __wasi_filesize_t len
-) __WASI_SYSCALL_NAME(fd_allocate) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_create_directory(
-    __wasi_fd_t fd,
-    const char *path,
-    size_t path_len
-) __WASI_SYSCALL_NAME(path_create_directory) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_link(
-    __wasi_fd_t old_fd,
-    __wasi_lookupflags_t old_flags,
-    const char *old_path,
-    size_t old_path_len,
-    __wasi_fd_t new_fd,
-    const char *new_path,
-    size_t new_path_len
-) __WASI_SYSCALL_NAME(path_link) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_open(
-    __wasi_fd_t dirfd,
-    __wasi_lookupflags_t dirflags,
-    const char *path,
-    size_t path_len,
-    __wasi_oflags_t oflags,
-    __wasi_rights_t fs_rights_base,
-    __wasi_rights_t fs_rights_inheriting,
-    __wasi_fdflags_t fs_flags,
-    __wasi_fd_t *fd
-) __WASI_SYSCALL_NAME(path_open) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_readdir(
-    __wasi_fd_t fd,
-    void *buf,
-    size_t buf_len,
-    __wasi_dircookie_t cookie,
-    size_t *bufused
-) __WASI_SYSCALL_NAME(fd_readdir) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_readlink(
-    __wasi_fd_t fd,
-    const char *path,
-    size_t path_len,
-    char *buf,
-    size_t buf_len,
-    size_t *bufused
-) __WASI_SYSCALL_NAME(path_readlink) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_rename(
-    __wasi_fd_t old_fd,
-    const char *old_path,
-    size_t old_path_len,
-    __wasi_fd_t new_fd,
-    const char *new_path,
-    size_t new_path_len
-) __WASI_SYSCALL_NAME(path_rename) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_filestat_get(
-    __wasi_fd_t fd,
-    __wasi_filestat_t *buf
-) __WASI_SYSCALL_NAME(fd_filestat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_filestat_set_times(
-    __wasi_fd_t fd,
-    __wasi_timestamp_t st_atim,
-    __wasi_timestamp_t st_mtim,
-    __wasi_fstflags_t fstflags
-) __WASI_SYSCALL_NAME(fd_filestat_set_times) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_fd_filestat_set_size(
-    __wasi_fd_t fd,
-    __wasi_filesize_t st_size
-) __WASI_SYSCALL_NAME(fd_filestat_set_size) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_filestat_get(
-    __wasi_fd_t fd,
-    __wasi_lookupflags_t flags,
-    const char *path,
-    size_t path_len,
-    __wasi_filestat_t *buf
-) __WASI_SYSCALL_NAME(path_filestat_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_filestat_set_times(
-    __wasi_fd_t fd,
-    __wasi_lookupflags_t flags,
-    const char *path,
-    size_t path_len,
-    __wasi_timestamp_t st_atim,
-    __wasi_timestamp_t st_mtim,
-    __wasi_fstflags_t fstflags
-) __WASI_SYSCALL_NAME(path_filestat_set_times) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_symlink(
-    const char *old_path,
-    size_t old_path_len,
-    __wasi_fd_t fd,
-    const char *new_path,
-    size_t new_path_len
-) __WASI_SYSCALL_NAME(path_symlink) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_unlink_file(
-    __wasi_fd_t fd,
-    const char *path,
-    size_t path_len
-) __WASI_SYSCALL_NAME(path_unlink_file) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_path_remove_directory(
-    __wasi_fd_t fd,
-    const char *path,
-    size_t path_len
-) __WASI_SYSCALL_NAME(path_remove_directory) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_poll_oneoff(
-    const __wasi_subscription_t *in,
-    __wasi_event_t *out,
-    size_t nsubscriptions,
-    size_t *nevents
-) __WASI_SYSCALL_NAME(poll_oneoff) __attribute__((__warn_unused_result__));
-
-_Noreturn void __wasi_proc_exit(
-    __wasi_exitcode_t rval
-) __WASI_SYSCALL_NAME(proc_exit);
-
-__wasi_errno_t __wasi_proc_raise(
-    __wasi_signal_t sig
-) __WASI_SYSCALL_NAME(proc_raise) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_random_get(
-    void *buf,
-    size_t buf_len
-) __WASI_SYSCALL_NAME(random_get) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_sock_recv(
-    __wasi_fd_t sock,
-    const __wasi_iovec_t *ri_data,
-    size_t ri_data_len,
-    __wasi_riflags_t ri_flags,
-    size_t *ro_datalen,
-    __wasi_roflags_t *ro_flags
-) __WASI_SYSCALL_NAME(sock_recv) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_sock_send(
-    __wasi_fd_t sock,
-    const __wasi_ciovec_t *si_data,
-    size_t si_data_len,
-    __wasi_siflags_t si_flags,
-    size_t *so_datalen
-) __WASI_SYSCALL_NAME(sock_send) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_sock_shutdown(
-    __wasi_fd_t sock,
-    __wasi_sdflags_t how
-) __WASI_SYSCALL_NAME(sock_shutdown) __attribute__((__warn_unused_result__));
-
-__wasi_errno_t __wasi_sched_yield(void)
-    __WASI_SYSCALL_NAME(sched_yield) __attribute__((__warn_unused_result__));
-
-#ifdef __cplusplus
-}
-#endif
-
-#undef __WASI_SYSCALL_NAME
-
-#endif
index ca12929dd96104b11d74ac68c1228822247b463a..8800b89e5d4db58ebd4bbf7ea8a9143a80955914 100644 (file)
@@ -530,18 +530,19 @@ __wasilibc_populate_libpreopen(void)
     for (__wasi_fd_t fd = 3; fd != 0; ++fd) {
         __wasi_prestat_t prestat;
         __wasi_errno_t ret = __wasi_fd_prestat_get(fd, &prestat);
-        if (ret == __WASI_EBADF)
+        if (ret == __WASI_ERRNO_BADF)
             break;
-        if (ret != __WASI_ESUCCESS)
+        if (ret != __WASI_ERRNO_SUCCESS)
             return ret;
         switch (prestat.pr_type) {
         case __WASI_PREOPENTYPE_DIR: {
             char *path = malloc(prestat.u.dir.pr_name_len + 1);
             if (path == NULL)
-                return __WASI_ENOMEM;
+                return __WASI_ERRNO_NOMEM;
 
-            ret = __wasi_fd_prestat_dir_name(fd, path, prestat.u.dir.pr_name_len);
-            if (ret != __WASI_ESUCCESS) {
+            // TODO: Remove the cast on `path` once the witx is updated with char8 support.
+            ret = __wasi_fd_prestat_dir_name(fd, (uint8_t *)path, prestat.u.dir.pr_name_len);
+            if (ret != __WASI_ERRNO_SUCCESS) {
                 free(path);
                 return ret;
             }
@@ -549,7 +550,7 @@ __wasilibc_populate_libpreopen(void)
 
             if (internal_register_preopened_fd(fd, path) != 0) {
                 free(path);
-                return __WASI_ENOMEM;
+                return __WASI_ERRNO_NOMEM;
             }
 
             break;
@@ -559,5 +560,5 @@ __wasilibc_populate_libpreopen(void)
         }
     }
 
-    return __WASI_ESUCCESS;
+    return __WASI_ERRNO_SUCCESS;
 }
index 3e14ace003d54b23121b89bc0a51c8dae0a0e9bb..38c82d44bcb6d9a5edb3815b6830a1524c13d0f6 100644 (file)
@@ -1,6 +1,6 @@
 #include <unistd.h>
 #include <stdlib.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <wasi/libc-internal.h>
 
@@ -19,23 +19,23 @@ __wasi_errno_t __wasilibc_populate_environ(void) {
     size_t environ_count;
     size_t environ_buf_size;
     err = __wasi_environ_sizes_get(&environ_count, &environ_buf_size);
-    if (err != __WASI_ESUCCESS) {
+    if (err != __WASI_ERRNO_SUCCESS) {
         return err;
     }
     if (environ_count == 0) {
-        return __WASI_ESUCCESS;
+        return __WASI_ERRNO_SUCCESS;
     }
 
     // Add 1 for the NULL pointer to mark the end, and check for overflow.
     size_t num_ptrs = environ_count + 1;
     if (num_ptrs == 0) {
-        return __WASI_ENOMEM;
+        return __WASI_ERRNO_NOMEM;
     }
 
     // Allocate memory for storing the environment chars.
     char *environ_buf = malloc(environ_buf_size);
     if (environ_buf == NULL) {
-        return __WASI_ENOMEM;
+        return __WASI_ERRNO_NOMEM;
     }
 
     // Allocate memory for the array of pointers. This uses `calloc` both to
@@ -43,12 +43,13 @@ __wasi_errno_t __wasilibc_populate_environ(void) {
     char **environ_ptrs = calloc(num_ptrs, sizeof(char *));
     if (environ_ptrs == NULL) {
         free(environ_buf);
-        return __WASI_ENOMEM;
+        return __WASI_ERRNO_NOMEM;
     }
 
     // Fill the environment chars, and the __environ array with pointers into those chars.
-    err = __wasi_environ_get(environ_ptrs, environ_buf);
-    if (err == __WASI_ESUCCESS) {
+    // TODO: Remove the casts on `environ_ptrs` and `environ_buf` once the witx is updated with char8 support.
+    err = __wasi_environ_get((uint8_t **)environ_ptrs, (uint8_t *)environ_buf);
+    if (err == __WASI_ERRNO_SUCCESS) {
         __environ = environ_ptrs;
     } else {
         free(environ_buf);
index 31ce665e9da8f350e2ff2d7a2218141db2a151ef..b0982d50bef9dbe524e0eae7e70df91df09293a3 100644 (file)
@@ -1,4 +1,4 @@
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <stdlib.h>
 #include <sysexits.h>
@@ -17,7 +17,7 @@ int __original_main(void) {
     size_t argv_buf_size;
     size_t argc;
     err = __wasi_args_sizes_get(&argc, &argv_buf_size);
-    if (err != __WASI_ESUCCESS) {
+    if (err != __WASI_ERRNO_SUCCESS) {
         _Exit(EX_OSERR);
     }
 
@@ -42,8 +42,9 @@ int __original_main(void) {
     }
 
     // Fill the argument chars, and the argv array with pointers into those chars.
-    err = __wasi_args_get(argv, argv_buf);
-    if (err != __WASI_ESUCCESS) {
+    // TODO: Remove the casts on `argv_ptrs` and `argv_buf` once the witx is updated with char8 support.
+    err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf);
+    if (err != __WASI_ERRNO_SUCCESS) {
         free(argv_buf);
         free(argv);
         _Exit(EX_OSERR);
index a7d33c53c76599a544cefe7f922dc8ae1708a350..aa9d8dcb1c07fdf5a014594f23c6fc5a131be270 100644 (file)
@@ -1,4 +1,4 @@
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <errno.h>
 #include <unistd.h>
index 713b6289af84ff1cecd77d9aed867db4a427a603..acb9528eb891ceb6c4d66bba1c61740d7728487a 100644 (file)
@@ -1,5 +1,5 @@
 #include <common/errno.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <errno.h>
 #include <string.h>
index 01dcd356983d3c9990d51797a948d427911b4dd1..358d0ca375af7cebde3083baaf62201f239cf274 100644 (file)
@@ -1,4 +1,4 @@
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 
 off_t __wasilibc_tell(int fildes) {
index e5c84a2a4393005e524cfbe0b94b7fe88aa877c2..a26634821b5bd8910f4b3777c28dfb6808d0f700 100644 (file)
@@ -1,5 +1,5 @@
 #include <common/errno.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <wasi/libc.h>
 #include <errno.h>
 #include <string.h>
index cb5eb5f7bf0981bfc4d9f8836e9fa4b15b8a0703..7f96b85e1f67dced02bf7fa90fd22f1fd97c6a19 100644 (file)
@@ -1,4 +1,4 @@
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <errno.h>
 #include <unistd.h>
 
index ff0fa925036c3c1dcd62325dea7a39d72f99fb09..c6f8662816a009d0f7e8a8b6a88627fb435b1aaa 100644 (file)
@@ -1,4 +1,4 @@
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <__errno.h>
 #include <__function___isatty.h>
 
@@ -12,8 +12,8 @@ int __isatty(int fd) {
 
     // A tty is a character device that we can't seek or tell on.
     if (statbuf.fs_filetype != __WASI_FILETYPE_CHARACTER_DEVICE ||
-        (statbuf.fs_rights_base & (__WASI_RIGHT_FD_SEEK | __WASI_RIGHT_FD_TELL)) != 0) {
-        errno = __WASI_ENOTTY;
+        (statbuf.fs_rights_base & (__WASI_RIGHTS_FD_SEEK | __WASI_RIGHTS_FD_TELL)) != 0) {
+        errno = __WASI_ERRNO_NOTTY;
         return 0;
     }
 
index aa64428f631c76a005a5be1acc8dbd827328fc35..0e3e71250253f43a9418f22110032cef1854d3a2 100644 (file)
@@ -1,6 +1,6 @@
 #include <stddef.h>
 #include <errno.h>
-#include <wasi/core.h>
+#include <wasi/api.h>
 #include <unistd.h>
 
 int pause(void) {
diff --git a/tools/wasi-headers/Cargo.toml b/tools/wasi-headers/Cargo.toml
new file mode 100644 (file)
index 0000000..c0b04e7
--- /dev/null
@@ -0,0 +1,12 @@
+[package]
+name = "wasi-headers"
+version = "0.0.0"
+authors = ["Dan Gohman <sunfish@mozilla.com>"]
+license = "Apache-2.0"
+edition = "2018"
+publish = false
+
+[dependencies]
+clap = "2"
+heck = "0.3.1"
+witx = "0.5.0"
diff --git a/tools/wasi-headers/LICENSE b/tools/wasi-headers/LICENSE
new file mode 100644 (file)
index 0000000..8f71f43
--- /dev/null
@@ -0,0 +1,202 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "{}"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright {yyyy} {name of copyright owner}
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+
diff --git a/tools/wasi-headers/src/c_header.rs b/tools/wasi-headers/src/c_header.rs
new file mode 100644 (file)
index 0000000..43c66f7
--- /dev/null
@@ -0,0 +1,414 @@
+use heck::ShoutySnakeCase;
+use witx::*;
+
+const PROLOGUE: &str = r#"/**
+ * THIS FILE IS AUTO-GENERATED!
+ *
+ * @file
+ * 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.
+ *
+ * [CloudABI]: https://github.com/NuxiNL/cloudlibc
+ */
+
+#ifndef __wasi_api_h
+#define __wasi_api_h
+
+#ifndef __wasi__
+#error <wasi/api.h> is only supported on WASI platforms.
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+_Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout");
+_Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout");
+_Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout");
+_Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout");
+_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");
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+// TODO: Encoding this in witx.
+#define __WASI_DIRCOOKIE_START (UINT64_C(0))
+"#;
+
+const EPILOGUE: &str = r#"#ifdef __cplusplus
+}
+#endif
+
+#endif"#;
+
+pub fn to_c_header(doc: &Document) -> String {
+    let mut ret = String::new();
+
+    ret.push_str(PROLOGUE);
+
+    for d in doc.datatypes() {
+        print_datatype(&mut ret, &*d);
+    }
+
+    for m in doc.modules() {
+        print_module(&mut ret, doc, &m);
+    }
+
+    ret.push_str(EPILOGUE);
+
+    ret
+}
+
+fn print_datatype(ret: &mut String, d: &Datatype) {
+    if !d.docs.is_empty() {
+        ret.push_str("/**\n");
+        for line in d.docs.lines() {
+            ret.push_str(&format!(" * {}\n", line));
+        }
+        ret.push_str(" */\n");
+    }
+
+    match &d.variant {
+        DatatypeVariant::Alias(a) => print_alias(ret, a),
+        DatatypeVariant::Enum(e) => print_enum(ret, e),
+        DatatypeVariant::Flags(f) => print_flags(ret, f),
+        DatatypeVariant::Struct(s) => print_struct(ret, s),
+        DatatypeVariant::Union(u) => print_union(ret, u),
+        DatatypeVariant::Handle(h) => print_handle(ret, h),
+    }
+}
+
+fn print_alias(ret: &mut String, a: &AliasDatatype) {
+    match a.to {
+        DatatypeIdent::Array(_) => {
+            // Don't emit arrays as top-level types; instead we special-case
+            // them in places like parameter lists so that we can pass them
+            // as pointer and length pairs.
+        }
+        _ => {
+            if a.name.as_str() == "size" {
+                // Special-case "size" as "__SIZE_TYPE__" -- TODO: Encode this in witx.
+                ret.push_str(&format!(
+                    "typedef __SIZE_TYPE__ __wasi_{}_t;\n",
+                    ident_name(&a.name)
+                ));
+            } else {
+                ret.push_str(&format!(
+                    "typedef {} __wasi_{}_t;\n",
+                    datatype_ident_name(&a.to),
+                    ident_name(&a.name)
+                ));
+            }
+            ret.push_str("\n");
+        }
+    }
+}
+
+fn print_enum(ret: &mut String, e: &EnumDatatype) {
+    ret.push_str(&format!(
+        "typedef {} __wasi_{}_t;\n",
+        intrepr_name(e.repr),
+        ident_name(&e.name)
+    ));
+    ret.push_str("\n");
+
+    for (index, variant) in e.variants.iter().enumerate() {
+        if !variant.docs.is_empty() {
+            ret.push_str("/**\n");
+            for line in variant.docs.lines() {
+                ret.push_str(&format!(" * {}\n", line));
+            }
+            ret.push_str(" */\n");
+        }
+        ret.push_str(&format!(
+            "#define __WASI_{}_{} ((__wasi_{}_t){})\n",
+            ident_name(&e.name).to_shouty_snake_case(),
+            ident_name(&variant.name).to_shouty_snake_case(),
+            ident_name(&e.name),
+            index
+        ));
+        ret.push_str("\n");
+    }
+}
+
+fn print_flags(ret: &mut String, f: &FlagsDatatype) {
+    ret.push_str(&format!(
+        "typedef {} __wasi_{}_t;\n",
+        intrepr_name(f.repr),
+        ident_name(&f.name)
+    ));
+    ret.push_str("\n");
+
+    for (index, flag) in f.flags.iter().enumerate() {
+        if !flag.docs.is_empty() {
+            ret.push_str("/**\n");
+            for line in flag.docs.lines() {
+                ret.push_str(&format!(" * {}\n", line));
+            }
+            ret.push_str(" */\n");
+        }
+        ret.push_str(&format!(
+            "#define __WASI_{}_{} ((__wasi_{}_t){})\n",
+            ident_name(&f.name).to_shouty_snake_case(),
+            ident_name(&flag.name).to_shouty_snake_case(),
+            ident_name(&f.name),
+            1u128 << index
+        ));
+        ret.push_str("\n");
+    }
+}
+
+fn print_struct(ret: &mut String, s: &StructDatatype) {
+    ret.push_str(&format!(
+        "typedef struct __wasi_{}_t {{\n",
+        ident_name(&s.name)
+    ));
+
+    for member in &s.members {
+        if !member.docs.is_empty() {
+            ret.push_str("    /**\n");
+            for line in member.docs.lines() {
+                ret.push_str(&format!("     * {}\n", line));
+            }
+            ret.push_str("     */\n");
+        }
+        ret.push_str(&format!(
+            "    {} {};\n",
+            datatype_ident_name(&member.type_),
+            ident_name(&member.name)
+        ));
+        ret.push_str("\n");
+    }
+
+    ret.push_str(&format!("}} __wasi_{}_t;\n", ident_name(&s.name)));
+    ret.push_str("\n");
+}
+
+fn print_union(ret: &mut String, u: &UnionDatatype) {
+    ret.push_str(&format!(
+        "typedef union __wasi_{}_t {{\n",
+        ident_name(&u.name)
+    ));
+
+    for variant in &u.variants {
+        if !variant.docs.is_empty() {
+            ret.push_str("    /**\n");
+            for line in variant.docs.lines() {
+                ret.push_str(&format!("     * {}\n", line));
+            }
+            ret.push_str("     */\n");
+        }
+        ret.push_str(&format!(
+            "    {} {};\n",
+            datatype_ident_name(&variant.type_),
+            ident_name(&variant.name)
+        ));
+        ret.push_str("\n");
+    }
+
+    ret.push_str(&format!("}} __wasi_{}_t;\n", ident_name(&u.name)));
+    ret.push_str("\n");
+}
+
+fn print_handle(ret: &mut String, h: &HandleDatatype) {
+    ret.push_str(&format!("typedef int __wasi_{}_t;", ident_name(&h.name)));
+}
+
+fn print_module(ret: &mut String, doc: &Document, m: &Module) {
+    ret.push_str("/**\n");
+    ret.push_str(&format!(" * @defgroup {}\n", ident_name(&m.name),));
+    for line in m.docs.lines() {
+        ret.push_str(&format!(" * {}\n", line));
+    }
+    ret.push_str(" * @{\n");
+    ret.push_str(" */\n");
+    ret.push_str("\n");
+
+    for func in m.funcs() {
+        print_func(ret, doc, &func, &m.name);
+    }
+
+    ret.push_str("/** @} */\n");
+    ret.push_str("\n");
+}
+
+fn print_func(ret: &mut String, doc: &Document, func: &InterfaceFunc, module_name: &Id) {
+    if !func.docs.is_empty() {
+        ret.push_str("/**\n");
+        for line in func.docs.lines() {
+            ret.push_str(&format!(" * {}\n", line));
+        }
+        if !func.results.is_empty() {
+            let first_result = &func.results[0];
+            if !first_result.docs.is_empty() {
+                ret.push_str(" * @return\n");
+                for line in first_result.docs.lines() {
+                    ret.push_str(&format!(" * {}", line));
+                }
+            }
+        }
+        ret.push_str(" */\n");
+    }
+    if func.results.is_empty() {
+        // Special-case "proc_exit" as _Noreturn -- TODO: Encode this in witx.
+        if func.name.as_str() == "proc_exit" {
+            ret.push_str("_Noreturn ");
+        }
+        ret.push_str("void ");
+    } else {
+        let first_result = &func.results[0];
+        ret.push_str(&format!("{} ", datatype_ident_name(&first_result.type_)));
+    }
+
+    ret.push_str(&format!("__wasi_{}(\n", ident_name(&func.name)));
+
+    if func.params.is_empty() && func.results.len() <= 1 {
+        ret.push_str("    void\n");
+    }
+    for (index, param) in func.params.iter().enumerate() {
+        if !param.docs.is_empty() {
+            ret.push_str("    /**\n");
+            for line in param.docs.lines() {
+                ret.push_str(&format!("     * {}\n", line));
+            }
+            ret.push_str("     */\n");
+        }
+        add_params(ret, doc, &ident_name(&param.name), &param.type_);
+        ret.push_str(&format!(
+            "{}\n",
+            if index + 1 < func.params.len() || func.results.len() > 1 {
+                ",\n"
+            } else {
+                ""
+            }
+        ));
+    }
+
+    for (index, result) in func.results.iter().enumerate() {
+        if index == 0 {
+            // The first result is returned by value above.
+            continue;
+        }
+        if !result.docs.is_empty() {
+            ret.push_str("    /**\n");
+            for line in result.docs.lines() {
+                ret.push_str(&format!("     * {}\n", line));
+            }
+            ret.push_str("     */\n");
+        }
+        ret.push_str(&format!(
+            "    {} *{}{}\n",
+            datatype_ident_name(&result.type_),
+            ident_name(&result.name),
+            if index + 1 < func.results.len() {
+                ","
+            } else {
+                ""
+            }
+        ));
+    }
+
+    ret.push_str(") __attribute__((\n");
+    ret.push_str(&format!(
+        "    __import_module__(\"{}\"),\n",
+        ident_name(module_name)
+    ));
+    ret.push_str(&format!(
+        "    __import_name__(\"{}\")",
+        ident_name(&func.name)
+    ));
+    if !func.results.is_empty() {
+        ret.push_str(",\n    __warn_unused_result__\n");
+    }
+    ret.push_str("));\n");
+    ret.push_str("\n");
+}
+
+fn add_params(ret: &mut String, doc: &Document, name: &str, type_: &DatatypeIdent) {
+    match type_ {
+        DatatypeIdent::Ident(i) => match &doc.datatype(&i.name).unwrap().as_ref().variant {
+            DatatypeVariant::Alias(a) => add_resolved_params(ret, name, &a.to),
+            _ => add_resolved_params(ret, name, type_),
+        },
+        _ => add_resolved_params(ret, name, type_),
+    }
+}
+
+fn add_resolved_params(ret: &mut String, name: &str, type_: &DatatypeIdent) {
+    match type_ {
+        DatatypeIdent::Builtin(BuiltinType::String) => {
+            ret.push_str(&format!("    const char *{},\n", name));
+            ret.push_str("\n");
+            ret.push_str("    /**\n");
+            ret.push_str(&format!(
+                "     * The length of the buffer pointed to by `{}`.\n",
+                name,
+            ));
+            ret.push_str("     */\n");
+            ret.push_str(&format!("    size_t {}_len", name));
+        }
+        DatatypeIdent::Array(element) => {
+            ret.push_str(&format!(
+                "    const {} *{},\n",
+                datatype_ident_name(&element),
+                name
+            ));
+            ret.push_str("\n");
+            ret.push_str("    /**\n");
+            ret.push_str(&format!(
+                "     * The length of the array pointed to by `{}`.\n",
+                name,
+            ));
+            ret.push_str("     */\n");
+            ret.push_str(&format!("    size_t {}_len", name));
+        }
+        _ => {
+            ret.push_str(&format!("    {} {}", datatype_ident_name(&type_), name));
+        }
+    }
+}
+
+fn ident_name(i: &Id) -> String {
+    i.as_str().to_string()
+}
+
+fn builtin_type_name(b: BuiltinType) -> &'static str {
+    match b {
+        BuiltinType::String => "string",
+        BuiltinType::U8 => "uint8_t",
+        BuiltinType::U16 => "uint16_t",
+        BuiltinType::U32 => "uint32_t",
+        BuiltinType::U64 => "uint64_t",
+        BuiltinType::S8 => "int8_t",
+        BuiltinType::S16 => "int16_t",
+        BuiltinType::S32 => "int32_t",
+        BuiltinType::S64 => "int64_t",
+        BuiltinType::F32 => "float",
+        BuiltinType::F64 => "double",
+    }
+}
+
+fn datatype_ident_name(data_ty: &DatatypeIdent) -> String {
+    match data_ty {
+        DatatypeIdent::Builtin(b) => builtin_type_name(*b).to_string(),
+        DatatypeIdent::Array(_) => unreachable!("arrays should be special-cased"),
+        DatatypeIdent::Pointer(p) => format!("{} *", datatype_ident_name(&*p)),
+        DatatypeIdent::ConstPointer(p) => format!("const {} *", datatype_ident_name(&*p)),
+        DatatypeIdent::Ident(i) => format!("__wasi_{}_t", i.name.as_str()),
+    }
+}
+
+fn intrepr_name(i: IntRepr) -> &'static str {
+    match i {
+        IntRepr::U8 => "uint8_t",
+        IntRepr::U16 => "uint16_t",
+        IntRepr::U32 => "uint32_t",
+        IntRepr::U64 => "uint64_t",
+    }
+}
diff --git a/tools/wasi-headers/src/main.rs b/tools/wasi-headers/src/main.rs
new file mode 100644 (file)
index 0000000..d88bd2d
--- /dev/null
@@ -0,0 +1,59 @@
+mod c_header;
+
+use crate::c_header::to_c_header;
+use clap::{App, Arg};
+use std::fs::File;
+use std::io::Write;
+use std::path::PathBuf;
+use std::process;
+use witx::load;
+
+pub fn main() {
+    let app = App::new("wasi-headers")
+        .version(env!("CARGO_PKG_VERSION"))
+        .about("Generate C headers for WASI interfaces")
+        .arg(
+            Arg::with_name("input")
+                .required(true)
+                .multiple(true)
+                .help("path to root of witx document"),
+        )
+        .arg(
+            Arg::with_name("verbose")
+                .short("v")
+                .long("verbose")
+                .takes_value(false)
+                .required(false),
+        )
+        .get_matches();
+
+    let inputs = app
+        .values_of("input")
+        .expect("at least one input required")
+        .map(PathBuf::from)
+        .collect::<Vec<PathBuf>>();
+
+    match load(&inputs) {
+        Ok(doc) => {
+            if app.is_present("verbose") {
+                println!("{:?}", doc)
+            }
+
+            let c_header = to_c_header(&doc);
+            if let Some(output) = app.value_of("output") {
+                let mut file = File::create(output).expect("create output file");
+                file.write_all(c_header.as_bytes())
+                    .expect("write output file");
+            } else {
+                println!("{}", c_header)
+            }
+        }
+        Err(e) => {
+            println!("{}", e.report());
+            if app.is_present("verbose") {
+                println!("{:?}", e);
+            }
+            process::exit(1)
+        }
+    }
+}