From 8210df5399b2c7aefb56eb064b84d3264fb831c5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Dec 2025 13:33:14 -0800 Subject: [PATCH 1/5] Sever wasip2's dependence on wasip1 headers This commit updates `wasi/api.h` to be fully undefined on WASIp2 targets. This prevents leaking WASIp1 definitions on unapplicable targets, such as `wasm32-wasip2` and the upcoming `wasm32-wasip3`. This involved changing a number of `#define`s from something symbolic to a number literal. Static assertions throughout the codebase, already present, assert that these numbers match WASIp1 ABI values and for WASIp2+ these numbers are just a libc abstraction, not part of the ABI. --- libc-bottom-half/cloudlibc/src/common/clock.h | 5 +- .../cloudlibc/src/common/errors.h | 74 ++++----- .../cloudlibc/src/libc/dirent/readdir.c | 2 + .../cloudlibc/src/libc/errno/errno.c | 2 + .../cloudlibc/src/libc/fcntl/openat.c | 2 + .../cloudlibc/src/libc/fcntl/posix_fadvise.c | 2 + .../cloudlibc/src/libc/sys/stat/fstatat.c | 4 +- .../cloudlibc/src/libc/sys/stat/futimens.c | 1 - .../cloudlibc/src/libc/sys/stat/utimensat.c | 4 +- .../cloudlibc/src/libc/sys/uio/readv.c | 2 + .../cloudlibc/src/libc/sys/uio/writev.c | 2 + .../cloudlibc/src/libc/time/CLOCK_MONOTONIC.c | 7 +- .../cloudlibc/src/libc/time/CLOCK_REALTIME.c | 7 +- .../cloudlibc/src/libc/time/clock_nanosleep.c | 2 + .../cloudlibc/src/libc/unistd/lseek.c | 2 + .../headers/public/__errno_values.h | 152 +++++++++--------- .../headers/public/__header_dirent.h | 20 +-- .../headers/public/__header_fcntl.h | 30 ++-- .../headers/public/__header_sys_socket.h | 8 +- .../headers/public/__header_time.h | 2 +- .../headers/public/__header_unistd.h | 1 + libc-bottom-half/headers/public/__seek.h | 6 +- libc-bottom-half/headers/public/wasi/api.h | 4 +- libc-bottom-half/sources/netdb.c | 5 + .../musl/src/thread/pthread_attr_get.c | 4 +- libc-top-half/sources/arc4random.c | 2 +- test/src/memchr.c | 1 + test/src/strrchr.c | 1 + 28 files changed, 191 insertions(+), 163 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/common/clock.h b/libc-bottom-half/cloudlibc/src/common/clock.h index 58d40a183..d6d6a5ad6 100644 --- a/libc-bottom-half/cloudlibc/src/common/clock.h +++ b/libc-bottom-half/cloudlibc/src/common/clock.h @@ -5,7 +5,8 @@ #ifndef COMMON_CLOCK_H #define COMMON_CLOCK_H -#include +#define CLOCKID_MONOTONIC 0 +#define CLOCKID_REALTIME 1 // 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 @@ -13,7 +14,7 @@ // future we can use this to provide support for pthread_getcpuclockid() // and clock file descriptors. struct __clockid { - __wasi_clockid_t id; + int id; }; #endif diff --git a/libc-bottom-half/cloudlibc/src/common/errors.h b/libc-bottom-half/cloudlibc/src/common/errors.h index a8c1a00a2..92f91c206 100644 --- a/libc-bottom-half/cloudlibc/src/common/errors.h +++ b/libc-bottom-half/cloudlibc/src/common/errors.h @@ -6,115 +6,115 @@ static void translate_error(filesystem_error_code_t error) { switch (error) { case FILESYSTEM_ERROR_CODE_ACCESS: - errno = __WASI_ERRNO_ACCES; + errno = EACCES; break; case FILESYSTEM_ERROR_CODE_WOULD_BLOCK: - errno = __WASI_ERRNO_AGAIN; + errno = EAGAIN; break; case FILESYSTEM_ERROR_CODE_ALREADY: - errno = __WASI_ERRNO_ALREADY; + errno = EALREADY; break; case FILESYSTEM_ERROR_CODE_BAD_DESCRIPTOR: - errno = __WASI_ERRNO_BADF; + errno = EBADF; break; case FILESYSTEM_ERROR_CODE_BUSY: - errno = __WASI_ERRNO_BUSY; + errno = EBUSY; break; case FILESYSTEM_ERROR_CODE_DEADLOCK: - errno = __WASI_ERRNO_DEADLK; + errno = EDEADLK; break; case FILESYSTEM_ERROR_CODE_QUOTA: - errno = __WASI_ERRNO_DQUOT; + errno = EDQUOT; break; case FILESYSTEM_ERROR_CODE_EXIST: - errno = __WASI_ERRNO_EXIST; + errno = EEXIST; break; case FILESYSTEM_ERROR_CODE_FILE_TOO_LARGE: - errno = __WASI_ERRNO_FBIG; + errno = EFBIG; break; case FILESYSTEM_ERROR_CODE_ILLEGAL_BYTE_SEQUENCE: - errno = __WASI_ERRNO_ILSEQ; + errno = EILSEQ; break; case FILESYSTEM_ERROR_CODE_IN_PROGRESS: - errno = __WASI_ERRNO_INPROGRESS; + errno = EINPROGRESS; break; case FILESYSTEM_ERROR_CODE_INTERRUPTED: - errno = __WASI_ERRNO_INTR; + errno = EINTR; break; case FILESYSTEM_ERROR_CODE_INVALID: - errno = __WASI_ERRNO_INVAL; + errno = EINVAL; break; case FILESYSTEM_ERROR_CODE_IO: - errno = __WASI_ERRNO_IO; + errno = EIO; break; case FILESYSTEM_ERROR_CODE_IS_DIRECTORY: - errno = __WASI_ERRNO_ISDIR; + errno = EISDIR; break; case FILESYSTEM_ERROR_CODE_LOOP: - errno = __WASI_ERRNO_LOOP; + errno = ELOOP; break; case FILESYSTEM_ERROR_CODE_TOO_MANY_LINKS: - errno = __WASI_ERRNO_MLINK; + errno = EMLINK; break; case FILESYSTEM_ERROR_CODE_MESSAGE_SIZE: - errno = __WASI_ERRNO_MSGSIZE; + errno = EMSGSIZE; break; case FILESYSTEM_ERROR_CODE_NAME_TOO_LONG: - errno = __WASI_ERRNO_NAMETOOLONG; + errno = ENAMETOOLONG; break; case FILESYSTEM_ERROR_CODE_NO_DEVICE: - errno = __WASI_ERRNO_NODEV; + errno = ENODEV; break; case FILESYSTEM_ERROR_CODE_NO_ENTRY: - errno = __WASI_ERRNO_NOENT; + errno = ENOENT; break; case FILESYSTEM_ERROR_CODE_NO_LOCK: - errno = __WASI_ERRNO_NOLCK; + errno = ENOLCK; break; case FILESYSTEM_ERROR_CODE_INSUFFICIENT_MEMORY: - errno = __WASI_ERRNO_NOMEM; + errno = ENOMEM; break; case FILESYSTEM_ERROR_CODE_INSUFFICIENT_SPACE: - errno = __WASI_ERRNO_NOSPC; + errno = ENOSPC; break; case FILESYSTEM_ERROR_CODE_NOT_DIRECTORY: - errno = __WASI_ERRNO_NOTDIR; + errno = ENOTDIR; break; case FILESYSTEM_ERROR_CODE_NOT_EMPTY: - errno = __WASI_ERRNO_NOTEMPTY; + errno = ENOTEMPTY; break; case FILESYSTEM_ERROR_CODE_NOT_RECOVERABLE: - errno = __WASI_ERRNO_NOTRECOVERABLE; + errno = ENOTRECOVERABLE; break; case FILESYSTEM_ERROR_CODE_UNSUPPORTED: - errno = __WASI_ERRNO_NOTSUP; + errno = ENOTSUP; break; case FILESYSTEM_ERROR_CODE_NO_TTY: - errno = __WASI_ERRNO_NOTTY; + errno = ENOTTY; break; case FILESYSTEM_ERROR_CODE_NO_SUCH_DEVICE: - errno = __WASI_ERRNO_NXIO; + errno = ENXIO; break; case FILESYSTEM_ERROR_CODE_OVERFLOW: - errno = __WASI_ERRNO_OVERFLOW; + errno = EOVERFLOW; break; case FILESYSTEM_ERROR_CODE_NOT_PERMITTED: - errno = __WASI_ERRNO_PERM; + errno = EPERM; break; case FILESYSTEM_ERROR_CODE_PIPE: - errno = __WASI_ERRNO_PIPE; + errno = EPIPE; break; case FILESYSTEM_ERROR_CODE_READ_ONLY: - errno = __WASI_ERRNO_ROFS; + errno = EROFS; break; case FILESYSTEM_ERROR_CODE_INVALID_SEEK: - errno = __WASI_ERRNO_SPIPE; + errno = ESPIPE; break; case FILESYSTEM_ERROR_CODE_TEXT_FILE_BUSY: - errno = __WASI_ERRNO_TXTBSY; + errno = ETXTBSY; break; case FILESYSTEM_ERROR_CODE_CROSS_DEVICE: - errno = __WASI_ERRNO_XDEV; + errno = EXDEV; break; default: abort(); // Unreachable diff --git a/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c b/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c index 68e012a18..10b12d73d 100644 --- a/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c +++ b/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c @@ -23,6 +23,7 @@ #include "dirent_impl.h" +#ifndef __wasilibc_use_wasip2 static_assert(DT_BLK == __WASI_FILETYPE_BLOCK_DEVICE, "Value mismatch"); static_assert(DT_CHR == __WASI_FILETYPE_CHARACTER_DEVICE, "Value mismatch"); static_assert(DT_DIR == __WASI_FILETYPE_DIRECTORY, "Value mismatch"); @@ -30,6 +31,7 @@ static_assert(DT_FIFO == __WASI_FILETYPE_SOCKET_STREAM, "Value mismatch"); static_assert(DT_LNK == __WASI_FILETYPE_SYMBOLIC_LINK, "Value mismatch"); static_assert(DT_REG == __WASI_FILETYPE_REGULAR_FILE, "Value mismatch"); static_assert(DT_UNKNOWN == __WASI_FILETYPE_UNKNOWN, "Value mismatch"); +#endif // Grows a buffer to be large enough to hold a certain amount of data. #define GROW(buffer, buffer_size, target_size) \ diff --git a/libc-bottom-half/cloudlibc/src/libc/errno/errno.c b/libc-bottom-half/cloudlibc/src/libc/errno/errno.c index d7a27f3fc..8ea01f7e0 100644 --- a/libc-bottom-half/cloudlibc/src/libc/errno/errno.c +++ b/libc-bottom-half/cloudlibc/src/libc/errno/errno.c @@ -7,6 +7,7 @@ #include #include +#ifndef __wasilibc_use_wasip2 static_assert(E2BIG == __WASI_ERRNO_2BIG, "Value mismatch"); static_assert(EACCES == __WASI_ERRNO_ACCES, "Value mismatch"); static_assert(EADDRINUSE == __WASI_ERRNO_ADDRINUSE, "Value mismatch"); @@ -83,5 +84,6 @@ 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"); +#endif thread_local int errno = 0; diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c index 986a22056..50cec6c12 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c @@ -17,6 +17,7 @@ #include #include +#ifndef __wasilibc_use_wasip2 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"); @@ -27,6 +28,7 @@ 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 __wasilibc_nocwd_openat_nomode(int fd, const char *path, int oflag) { diff --git a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c index 8e00461e4..a4ef02cb1 100644 --- a/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c +++ b/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c @@ -13,6 +13,7 @@ #include #include +#ifndef __wasilibc_use_wasip2 static_assert(POSIX_FADV_DONTNEED == __WASI_ADVICE_DONTNEED, "Value mismatch"); static_assert(POSIX_FADV_NOREUSE == __WASI_ADVICE_NOREUSE, "Value mismatch"); @@ -22,6 +23,7 @@ static_assert(POSIX_FADV_SEQUENTIAL == __WASI_ADVICE_SEQUENTIAL, "Value mismatch"); static_assert(POSIX_FADV_WILLNEED == __WASI_ADVICE_WILLNEED, "Value mismatch"); +#endif int posix_fadvise(int fd, off_t offset, off_t len, int advice) { if (offset < 0 || len < 0) diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c index 2b1bafded..cf96ae19a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c @@ -46,9 +46,9 @@ int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *res } // Create lookup properties. - __wasi_lookupflags_t lookup_flags = 0; + filesystem_path_flags_t lookup_flags = 0; if ((flag & AT_SYMLINK_NOFOLLOW) == 0) - lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; + lookup_flags |= FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW; // Perform system call. filesystem_descriptor_stat_t internal_stat; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c index 6bbf9f94d..dcb057ce7 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c @@ -25,7 +25,6 @@ int futimens(int fd, const struct timespec *times) { // Convert timestamps and extract NOW/OMIT flags. filesystem_new_timestamp_t new_timestamp_atim; filesystem_new_timestamp_t new_timestamp_mtim; - __wasi_fstflags_t flags; if (!utimens_get_timestamps(times, &new_timestamp_atim, &new_timestamp_mtim)) { errno = EINVAL; return -1; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c b/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c index 29dcd00d6..2ef221598 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c @@ -34,9 +34,9 @@ int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec t } // Create lookup properties. - __wasi_lookupflags_t lookup_flags = 0; + filesystem_path_flags_t lookup_flags = 0; if ((flag & AT_SYMLINK_NOFOLLOW) == 0) - lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; + lookup_flags |= FILESYSTEM_PATH_FLAGS_SYMLINK_FOLLOW; // Convert the string into a Wasm string wasip2_string_t path_wasm_string; diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c b/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c index a016deb52..6edfe5713 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c @@ -10,6 +10,7 @@ #include #include +#ifndef __wasilibc_use_wasip2 static_assert(offsetof(struct iovec, iov_base) == offsetof(__wasi_iovec_t, buf), "Offset mismatch"); @@ -24,6 +25,7 @@ static_assert(sizeof(((struct iovec *)0)->iov_len) == "Size mismatch"); static_assert(sizeof(struct iovec) == sizeof(__wasi_iovec_t), "Size mismatch"); +#endif ssize_t readv(int fildes, const struct iovec *iov, int iovcnt) { if (iovcnt < 0) { diff --git a/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c b/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c index fb2150831..d6ebcc366 100644 --- a/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c +++ b/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c @@ -16,6 +16,7 @@ #include #include +#ifndef __wasilibc_use_wasip2 static_assert(offsetof(struct iovec, iov_base) == offsetof(__wasi_ciovec_t, buf), "Offset mismatch"); @@ -30,6 +31,7 @@ static_assert(sizeof(((struct iovec *)0)->iov_len) == "Size mismatch"); static_assert(sizeof(struct iovec) == sizeof(__wasi_ciovec_t), "Size mismatch"); +#endif ssize_t writev(int fildes, const struct iovec *iov, int iovcnt) { if (iovcnt < 0) { diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c index a4c4a62c6..98293f41a 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c @@ -7,6 +7,11 @@ #include #include +#ifndef __wasilibc_use_wasip2 +static_assert(__WASI_CLOCKID_MONOTONIC == CLOCKID_MONOTONIC, + "__WASI_CLOCKID_MONOTONIC has changed value"); +#endif + const struct __clockid _CLOCK_MONOTONIC = { - .id = __WASI_CLOCKID_MONOTONIC, + .id = CLOCKID_MONOTONIC, }; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c index 952375444..e343104e7 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c @@ -7,6 +7,11 @@ #include #include +#ifndef __wasilibc_use_wasip2 +static_assert(__WASI_CLOCKID_REALTIME == CLOCKID_REALTIME, + "__WASI_CLOCKID_REALTIME has changed value"); +#endif + const struct __clockid _CLOCK_REALTIME = { - .id = __WASI_CLOCKID_REALTIME, + .id = CLOCKID_REALTIME, }; diff --git a/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c b/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c index 05a0962a7..8bb7b35bc 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c @@ -14,8 +14,10 @@ #include #include +#ifndef __wasilibc_use_wasip2 static_assert(TIMER_ABSTIME == __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME, "Value mismatch"); +#endif #ifdef __wasilibc_use_wasip2 int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, diff --git a/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c b/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c index 5211221e9..2cd993f27 100644 --- a/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c +++ b/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c @@ -14,9 +14,11 @@ #include #include +#ifndef __wasilibc_use_wasip2 static_assert(SEEK_CUR == __WASI_WHENCE_CUR, "Value mismatch"); static_assert(SEEK_END == __WASI_WHENCE_END, "Value mismatch"); static_assert(SEEK_SET == __WASI_WHENCE_SET, "Value mismatch"); +#endif off_t __lseek(int fildes, off_t offset, int whence) { #ifdef __wasilibc_use_wasip2 diff --git a/libc-bottom-half/headers/public/__errno_values.h b/libc-bottom-half/headers/public/__errno_values.h index 6d6d41204..97f3882ab 100644 --- a/libc-bottom-half/headers/public/__errno_values.h +++ b/libc-bottom-half/headers/public/__errno_values.h @@ -3,82 +3,82 @@ #include -#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 E2BIG 1 +#define EACCES 2 +#define EADDRINUSE 3 +#define EADDRNOTAVAIL 4 +#define EAFNOSUPPORT 5 +#define EAGAIN 6 +#define EALREADY 7 +#define EBADF 8 +#define EBADMSG 9 +#define EBUSY 10 +#define ECANCELED 11 +#define ECHILD 12 +#define ECONNABORTED 13 +#define ECONNREFUSED 14 +#define ECONNRESET 15 +#define EDEADLK 16 +#define EDESTADDRREQ 17 +#define EDOM 18 +#define EDQUOT 19 +#define EEXIST 20 +#define EFAULT 21 +#define EFBIG 22 +#define EHOSTUNREACH 23 +#define EIDRM 24 +#define EILSEQ 25 +#define EINPROGRESS 26 +#define EINTR 27 +#define EINVAL 28 +#define EIO 29 +#define EISCONN 30 +#define EISDIR 31 +#define ELOOP 32 +#define EMFILE 33 +#define EMLINK 34 +#define EMSGSIZE 35 +#define EMULTIHOP 36 +#define ENAMETOOLONG 37 +#define ENETDOWN 38 +#define ENETRESET 39 +#define ENETUNREACH 40 +#define ENFILE 41 +#define ENOBUFS 42 +#define ENODEV 43 +#define ENOENT 44 +#define ENOEXEC 45 +#define ENOLCK 46 +#define ENOLINK 47 +#define ENOMEM 48 +#define ENOMSG 49 +#define ENOPROTOOPT 50 +#define ENOSPC 51 +#define ENOSYS 52 +#define ENOTCONN 53 +#define ENOTDIR 54 +#define ENOTEMPTY 55 +#define ENOTRECOVERABLE 56 +#define ENOTSOCK 57 +#define ENOTSUP 58 +#define ENOTTY 59 +#define ENXIO 60 +#define EOVERFLOW 61 +#define EOWNERDEAD 62 +#define EPERM 63 +#define EPIPE 64 +#define EPROTO 65 +#define EPROTONOSUPPORT 66 +#define EPROTOTYPE 67 +#define ERANGE 68 +#define EROFS 69 +#define ESPIPE 70 +#define ESRCH 71 +#define ESTALE 72 +#define ETIMEDOUT 73 +#define ETXTBSY 74 +#define EXDEV 75 +#define ENOTCAPABLE 76 #define EOPNOTSUPP ENOTSUP #define EWOULDBLOCK EAGAIN diff --git a/libc-bottom-half/headers/public/__header_dirent.h b/libc-bottom-half/headers/public/__header_dirent.h index 027fc07a9..ff87959c5 100644 --- a/libc-bottom-half/headers/public/__header_dirent.h +++ b/libc-bottom-half/headers/public/__header_dirent.h @@ -3,19 +3,13 @@ #include -#define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE -#define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE -#define DT_DIR __WASI_FILETYPE_DIRECTORY -#define DT_FIFO __WASI_FILETYPE_SOCKET_STREAM -#define DT_LNK __WASI_FILETYPE_SYMBOLIC_LINK -#define DT_REG __WASI_FILETYPE_REGULAR_FILE -#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN - -// DT_SOCK is not supported in WASI Preview 1 (but will be in Preview 2). We -// define it regardless so that libc++'s `` implementation builds. -// The exact value is mostly arbitrary, but chosen so it doesn't conflict with -// any of the existing `__WASI_FILETYPE_*` flags. We do not expect any new -// flags to be added to WASI Preview 1, so that should be sufficient. +#define DT_UNKNOWN 0 +#define DT_BLK 1 +#define DT_CHR 2 +#define DT_DIR 3 +#define DT_REG 4 +#define DT_FIFO 6 +#define DT_LNK 7 #define DT_SOCK 20 #define IFTODT(x) (__wasilibc_iftodt(x)) diff --git a/libc-bottom-half/headers/public/__header_fcntl.h b/libc-bottom-half/headers/public/__header_fcntl.h index 2ac9baf64..33165d873 100644 --- a/libc-bottom-half/headers/public/__header_fcntl.h +++ b/libc-bottom-half/headers/public/__header_fcntl.h @@ -5,15 +5,15 @@ #include <__seek.h> #include -#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_APPEND 0x0001 +#define O_DSYNC 0x0002 +#define O_NONBLOCK 0x0004 +#define O_RSYNC 0x0008 +#define O_SYNC 0x0010 +#define O_CREAT (0x0001 << 12) +#define O_DIRECTORY (0x0002 << 12) +#define O_EXCL (0x0004 << 12) +#define O_TRUNC (0x0008 << 12) #define O_NOFOLLOW (0x01000000) #define O_EXEC (0x02000000) @@ -37,12 +37,12 @@ #define O_RDWR (O_RDONLY | O_WRONLY) #define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH) -#define POSIX_FADV_DONTNEED __WASI_ADVICE_DONTNEED -#define POSIX_FADV_NOREUSE __WASI_ADVICE_NOREUSE -#define POSIX_FADV_NORMAL __WASI_ADVICE_NORMAL -#define POSIX_FADV_RANDOM __WASI_ADVICE_RANDOM -#define POSIX_FADV_SEQUENTIAL __WASI_ADVICE_SEQUENTIAL -#define POSIX_FADV_WILLNEED __WASI_ADVICE_WILLNEED +#define POSIX_FADV_NORMAL 0 +#define POSIX_FADV_SEQUENTIAL 1 +#define POSIX_FADV_RANDOM 2 +#define POSIX_FADV_WILLNEED 3 +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_NOREUSE 5 #define F_GETFD (1) #define F_SETFD (2) diff --git a/libc-bottom-half/headers/public/__header_sys_socket.h b/libc-bottom-half/headers/public/__header_sys_socket.h index c67c2e4dc..3bb9715bd 100644 --- a/libc-bottom-half/headers/public/__header_sys_socket.h +++ b/libc-bottom-half/headers/public/__header_sys_socket.h @@ -8,8 +8,8 @@ #include -#define SHUT_RD __WASI_SDFLAGS_RD -#define SHUT_WR __WASI_SDFLAGS_WR +#define SHUT_RD 1 +#define SHUT_WR 2 #define SHUT_RDWR (SHUT_RD | SHUT_WR) #ifdef __wasilibc_use_wasip2 @@ -49,8 +49,8 @@ #define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED #endif // __wasilibc_use_wasip2 -#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM -#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM +#define SOCK_DGRAM 5 +#define SOCK_STREAM 6 #define SOCK_NONBLOCK (0x00004000) #define SOCK_CLOEXEC (0x00002000) diff --git a/libc-bottom-half/headers/public/__header_time.h b/libc-bottom-half/headers/public/__header_time.h index 5c148fb0b..004351e48 100644 --- a/libc-bottom-half/headers/public/__header_time.h +++ b/libc-bottom-half/headers/public/__header_time.h @@ -14,7 +14,7 @@ #include #endif -#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME +#define TIMER_ABSTIME 1 extern const struct __clockid _CLOCK_MONOTONIC; #define CLOCK_MONOTONIC (&_CLOCK_MONOTONIC) diff --git a/libc-bottom-half/headers/public/__header_unistd.h b/libc-bottom-half/headers/public/__header_unistd.h index 6b80d6378..3df64636a 100644 --- a/libc-bottom-half/headers/public/__header_unistd.h +++ b/libc-bottom-half/headers/public/__header_unistd.h @@ -3,6 +3,7 @@ struct stat; +#include #include <__seek.h> #define F_OK (0) diff --git a/libc-bottom-half/headers/public/__seek.h b/libc-bottom-half/headers/public/__seek.h index 8824adb14..8ecdfd922 100644 --- a/libc-bottom-half/headers/public/__seek.h +++ b/libc-bottom-half/headers/public/__seek.h @@ -3,8 +3,8 @@ #include -#define SEEK_CUR __WASI_WHENCE_CUR -#define SEEK_END __WASI_WHENCE_END -#define SEEK_SET __WASI_WHENCE_SET +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 #endif diff --git a/libc-bottom-half/headers/public/wasi/api.h b/libc-bottom-half/headers/public/wasi/api.h index 84225dbae..c3e55b094 100644 --- a/libc-bottom-half/headers/public/wasi/api.h +++ b/libc-bottom-half/headers/public/wasi/api.h @@ -19,6 +19,8 @@ #ifndef __wasi_api_h #define __wasi_api_h +#ifndef __wasilibc_use_wasip2 + #ifndef __wasi__ #error is only supported on WASI platforms. #endif @@ -1445,8 +1447,6 @@ typedef struct __wasi_prestat_t { _Static_assert(sizeof(__wasi_prestat_t) == 8, "witx calculated size"); _Static_assert(_Alignof(__wasi_prestat_t) == 4, "witx calculated align"); -#ifndef __wasilibc_use_wasip2 - /** * @defgroup wasi_snapshot_preview1 * @{ diff --git a/libc-bottom-half/sources/netdb.c b/libc-bottom-half/sources/netdb.c index d4f3f5b3c..145b8740d 100644 --- a/libc-bottom-half/sources/netdb.c +++ b/libc-bottom-half/sources/netdb.c @@ -5,6 +5,11 @@ #include #include +#ifndef __wasilibc_use_wasip2 +static_assert(SOCK_DGRAM == __WASI_FILETYPE_SOCKET_DGRAM, "value mismatch"); +static_assert(SOCK_STREAM == __WASI_FILETYPE_SOCKET_STREAM, "value mismatch"); +#endif + _Thread_local int h_errno = 0; static struct servent global_serv = { 0 }; diff --git a/libc-top-half/musl/src/thread/pthread_attr_get.c b/libc-top-half/musl/src/thread/pthread_attr_get.c index ab8d938c6..503c5b85a 100644 --- a/libc-top-half/musl/src/thread/pthread_attr_get.c +++ b/libc-top-half/musl/src/thread/pthread_attr_get.c @@ -77,9 +77,9 @@ int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *r #else int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) { - if (a->__attr & 0x7fffffff == __WASI_CLOCKID_REALTIME) + if (a->__attr & 0x7fffffff == CLOCKID_REALTIME) *clk = CLOCK_REALTIME; - if (a->__attr & 0x7fffffff == __WASI_CLOCKID_MONOTONIC) + if (a->__attr & 0x7fffffff == CLOCKID_MONOTONIC) *clk = CLOCK_MONOTONIC; return 0; } diff --git a/libc-top-half/sources/arc4random.c b/libc-top-half/sources/arc4random.c index 47681703d..782bd3bb1 100644 --- a/libc-top-half/sources/arc4random.c +++ b/libc-top-half/sources/arc4random.c @@ -23,7 +23,7 @@ void arc4random_buf(void* buffer, size_t len) #endif // `__wasi_random_get` should always succeed. - if (r != __WASI_ERRNO_SUCCESS) { + if (r != 0) { __builtin_trap(); } } diff --git a/test/src/memchr.c b/test/src/memchr.c index 3a6b10336..74234ec1a 100644 --- a/test/src/memchr.c +++ b/test/src/memchr.c @@ -2,6 +2,7 @@ #include #include #include +#include void test(char *ptr, size_t length, void *want) { void *got = memchr(ptr, 7, length); diff --git a/test/src/strrchr.c b/test/src/strrchr.c index 12d006afd..54f506231 100644 --- a/test/src/strrchr.c +++ b/test/src/strrchr.c @@ -1,6 +1,7 @@ #include <__macro_PAGESIZE.h> #include #include +#include void test(char *ptr, char *want) { char *got = strrchr(ptr, 7); From f4f25945c1c37a6b1ae00454e19c9c555f454bbb Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Dec 2025 14:27:13 -0800 Subject: [PATCH 2/5] Try to fix build --- libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c | 1 + libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c | 1 + 2 files changed, 2 insertions(+) diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c index 98293f41a..c7aad4775 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: BSD-2-Clause +#include #include #include diff --git a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c index e343104e7..4d389acd7 100644 --- a/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c +++ b/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c @@ -2,6 +2,7 @@ // // SPDX-License-Identifier: BSD-2-Clause +#include #include #include From af77a0704fe789e27e88d9c05e7e69efefc5d0d9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Dec 2025 14:30:21 -0800 Subject: [PATCH 3/5] Fix definitions --- libc-bottom-half/cloudlibc/src/common/clock.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc-bottom-half/cloudlibc/src/common/clock.h b/libc-bottom-half/cloudlibc/src/common/clock.h index d6d6a5ad6..7ad532315 100644 --- a/libc-bottom-half/cloudlibc/src/common/clock.h +++ b/libc-bottom-half/cloudlibc/src/common/clock.h @@ -5,8 +5,8 @@ #ifndef COMMON_CLOCK_H #define COMMON_CLOCK_H -#define CLOCKID_MONOTONIC 0 -#define CLOCKID_REALTIME 1 +#define CLOCKID_REALTIME 0 +#define CLOCKID_MONOTONIC 1 // 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 From ab37a366eb4c0b0f43b4d6d439907ddeb79a1410 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Dec 2025 17:20:30 -0800 Subject: [PATCH 4/5] Update symbols --- .../wasm32-wasip1-threads/defined-symbols.txt | 2 +- .../predefined-macros.txt | 212 +++++++++--------- expected/wasm32-wasip1/defined-symbols.txt | 2 +- expected/wasm32-wasip1/predefined-macros.txt | 212 +++++++++--------- expected/wasm32-wasip2/defined-symbols.txt | 2 +- expected/wasm32-wasip2/predefined-macros.txt | 212 +++++++++--------- 6 files changed, 321 insertions(+), 321 deletions(-) diff --git a/expected/wasm32-wasip1-threads/defined-symbols.txt b/expected/wasm32-wasip1-threads/defined-symbols.txt index fb4d38261..4fb5d53fc 100644 --- a/expected/wasm32-wasip1-threads/defined-symbols.txt +++ b/expected/wasm32-wasip1-threads/defined-symbols.txt @@ -1390,4 +1390,4 @@ y0f y1 y1f yn -ynf +ynf \ No newline at end of file diff --git a/expected/wasm32-wasip1-threads/predefined-macros.txt b/expected/wasm32-wasip1-threads/predefined-macros.txt index 823ef8c93..5a819ec1f 100644 --- a/expected/wasm32-wasip1-threads/predefined-macros.txt +++ b/expected/wasm32-wasip1-threads/predefined-macros.txt @@ -175,62 +175,62 @@ #define DONT 254 #define DOUBLEBITS (sizeof(double) * 8) #define DTTOIF(x) (__wasilibc_dttoif(x)) -#define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE -#define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE -#define DT_DIR __WASI_FILETYPE_DIRECTORY -#define DT_FIFO __WASI_FILETYPE_SOCKET_STREAM -#define DT_LNK __WASI_FILETYPE_SYMBOLIC_LINK -#define DT_REG __WASI_FILETYPE_REGULAR_FILE +#define DT_BLK 1 +#define DT_CHR 2 +#define DT_DIR 3 +#define DT_FIFO 6 +#define DT_LNK 7 +#define DT_REG 4 #define DT_SOCK 20 -#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN +#define DT_UNKNOWN 0 #define D_FMT 0x20029 #define D_T_FMT 0x20028 -#define E2BIG __WASI_ERRNO_2BIG -#define EACCES __WASI_ERRNO_ACCES +#define E2BIG 1 +#define EACCES 2 #define EACCESS 2 -#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 EADDRINUSE 3 +#define EADDRNOTAVAIL 4 +#define EAFNOSUPPORT 5 +#define EAGAIN 6 +#define EALREADY 7 +#define EBADF 8 #define EBADID 5 -#define EBADMSG __WASI_ERRNO_BADMSG +#define EBADMSG 9 #define EBADOP 4 -#define EBUSY __WASI_ERRNO_BUSY +#define EBUSY 10 #define EC 247 -#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 ECANCELED 11 +#define ECHILD 12 +#define ECONNABORTED 13 +#define ECONNREFUSED 14 +#define ECONNRESET 15 +#define EDEADLK 16 +#define EDESTADDRREQ 17 +#define EDOM 18 +#define EDQUOT 19 +#define EEXIST 20 #define EEXISTS 6 -#define EFAULT __WASI_ERRNO_FAULT -#define EFBIG __WASI_ERRNO_FBIG +#define EFAULT 21 +#define EFBIG 22 #define EFD_CLOEXEC O_CLOEXEC #define EFD_NONBLOCK O_NONBLOCK #define EFD_SEMAPHORE 1 -#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 EHOSTUNREACH 23 +#define EIDRM 24 +#define EILSEQ 25 +#define EINPROGRESS 26 +#define EINTR 27 +#define EINVAL 28 +#define EIO 29 +#define EISCONN 30 +#define EISDIR 31 #define EL 248 -#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 ELOOP 32 +#define EMFILE 33 +#define EMLINK 34 +#define EMSGSIZE 35 +#define EMULTIHOP 36 +#define ENAMETOOLONG 37 #define ENCRYPT_CNT 9 #define ENCRYPT_DEC_KEYID 8 #define ENCRYPT_ENC_KEYID 7 @@ -249,60 +249,60 @@ #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_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 ENETDOWN 38 +#define ENETRESET 39 +#define ENETUNREACH 40 +#define ENFILE 41 +#define ENOBUFS 42 +#define ENODEV 43 +#define ENOENT 44 +#define ENOEXEC 45 +#define ENOLCK 46 +#define ENOLINK 47 +#define ENOMEM 48 +#define ENOMSG 49 +#define ENOPROTOOPT 50 #define ENOSPACE 3 -#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 ENOSPC 51 +#define ENOSYS 52 +#define ENOTCAPABLE 76 +#define ENOTCONN 53 +#define ENOTDIR 54 +#define ENOTEMPTY 55 #define ENOTFOUND 1 -#define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE -#define ENOTSOCK __WASI_ERRNO_NOTSOCK -#define ENOTSUP __WASI_ERRNO_NOTSUP -#define ENOTTY __WASI_ERRNO_NOTTY +#define ENOTRECOVERABLE 56 +#define ENOTSOCK 57 +#define ENOTSUP 58 +#define ENOTTY 59 #define ENOUSER 7 #define ENV_ESC 2 #define ENV_USERVAR 3 -#define ENXIO __WASI_ERRNO_NXIO +#define ENXIO 60 #define EOF (-1) #define EOPNOTSUPP ENOTSUP #define EOR 239 -#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 EOVERFLOW 61 +#define EOWNERDEAD 62 +#define EPERM 63 +#define EPIPE 64 +#define EPROTO 65 +#define EPROTONOSUPPORT 66 +#define EPROTOTYPE 67 #define ERA 0x2002C -#define ERANGE __WASI_ERRNO_RANGE +#define ERANGE 68 #define ERA_D_FMT 0x2002E #define ERA_D_T_FMT 0x20030 #define ERA_T_FMT 0x20031 -#define EROFS __WASI_ERRNO_ROFS +#define EROFS 69 #define ERROR 05 -#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 ESPIPE 70 +#define ESRCH 71 +#define ESTALE 72 +#define ETIMEDOUT 73 +#define ETXTBSY 74 #define EUNDEF 0 #define EWOULDBLOCK EAGAIN -#define EXDEV __WASI_ERRNO_XDEV +#define EXDEV 75 #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define EX_CANTCREAT 73 @@ -1294,22 +1294,22 @@ #define OLD_ENV_VAR 1 #define ONCE_FLAG_INIT 0 #define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH) -#define O_APPEND __WASI_FDFLAGS_APPEND +#define O_APPEND 0x0001 #define O_CLOEXEC (0) -#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_CREAT (0x0001 << 12) +#define O_DIRECTORY (0x0002 << 12) +#define O_DSYNC 0x0002 +#define O_EXCL (0x0004 << 12) #define O_EXEC (0x02000000) #define O_NOCTTY (0) #define O_NOFOLLOW (0x01000000) -#define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK +#define O_NONBLOCK 0x0004 #define O_RDONLY (0x04000000) #define O_RDWR (O_RDONLY | O_WRONLY) -#define O_RSYNC __WASI_FDFLAGS_RSYNC +#define O_RSYNC 0x0008 #define O_SEARCH (0x08000000) -#define O_SYNC __WASI_FDFLAGS_SYNC -#define O_TRUNC (__WASI_OFLAGS_TRUNC << 12) +#define O_SYNC 0x0010 +#define O_TRUNC (0x0008 << 12) #define O_TTY_INIT (0) #define O_WRONLY (0x10000000) #define PACKETSZ NS_PACKETSZ @@ -1362,12 +1362,12 @@ #define POLLRDNORM 0x1 #define POLLWRNORM 0x2 #define POSIX_CLOSE_RESTART 0 -#define POSIX_FADV_DONTNEED __WASI_ADVICE_DONTNEED -#define POSIX_FADV_NOREUSE __WASI_ADVICE_NOREUSE -#define POSIX_FADV_NORMAL __WASI_ADVICE_NORMAL -#define POSIX_FADV_RANDOM __WASI_ADVICE_RANDOM -#define POSIX_FADV_SEQUENTIAL __WASI_ADVICE_SEQUENTIAL -#define POSIX_FADV_WILLNEED __WASI_ADVICE_WILLNEED +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_NOREUSE 5 +#define POSIX_FADV_NORMAL 0 +#define POSIX_FADV_RANDOM 2 +#define POSIX_FADV_SEQUENTIAL 1 +#define POSIX_FADV_WILLNEED 3 #define PRELIM 1 #define PRIX16 __UINT16_FMTX__ #define PRIX32 __UINT32_FMTX__ @@ -1620,9 +1620,9 @@ #define SCNxMAX __UINTMAX_FMTx__ #define SCNxPTR __UINTPTR_FMTx__ #define SE 240 -#define SEEK_CUR __WASI_WHENCE_CUR -#define SEEK_END __WASI_WHENCE_END -#define SEEK_SET __WASI_WHENCE_SET +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_SET 0 #define SEGSIZE 512 #define SEM_FAILED ((sem_t *)0) #define SEM_NSEMS_MAX 256 @@ -1631,9 +1631,9 @@ #define SHORTBITS (sizeof(short) * 8) #define SHRT_MAX 0x7fff #define SHRT_MIN (-1-0x7fff) -#define SHUT_RD __WASI_SDFLAGS_RD +#define SHUT_RD 1 #define SHUT_RDWR (SHUT_RD | SHUT_WR) -#define SHUT_WR __WASI_SDFLAGS_WR +#define SHUT_WR 2 #define SIG_ATOMIC_MAX INT32_MAX #define SIG_ATOMIC_MIN INT32_MIN #define SIZE_MAX UINT32_MAX @@ -1674,9 +1674,9 @@ #define SNDPIPE 0x002 #define SNDZERO 0x001 #define SOCK_CLOEXEC (0x00002000) -#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM +#define SOCK_DGRAM 5 #define SOCK_NONBLOCK (0x00004000) -#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM +#define SOCK_STREAM 6 #define SOL_SOCKET 0x7fffffff #define SOL_TCP 6 #define SOL_UDP 17 @@ -1907,7 +1907,7 @@ #define TH_RST 0x04 #define TH_SYN 0x02 #define TH_URG 0x20 -#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME +#define TIMER_ABSTIME 1 #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 diff --git a/expected/wasm32-wasip1/defined-symbols.txt b/expected/wasm32-wasip1/defined-symbols.txt index 411178130..562d70527 100644 --- a/expected/wasm32-wasip1/defined-symbols.txt +++ b/expected/wasm32-wasip1/defined-symbols.txt @@ -1347,4 +1347,4 @@ y0f y1 y1f yn -ynf +ynf \ No newline at end of file diff --git a/expected/wasm32-wasip1/predefined-macros.txt b/expected/wasm32-wasip1/predefined-macros.txt index 493b767eb..d87cc696f 100644 --- a/expected/wasm32-wasip1/predefined-macros.txt +++ b/expected/wasm32-wasip1/predefined-macros.txt @@ -175,62 +175,62 @@ #define DONT 254 #define DOUBLEBITS (sizeof(double) * 8) #define DTTOIF(x) (__wasilibc_dttoif(x)) -#define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE -#define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE -#define DT_DIR __WASI_FILETYPE_DIRECTORY -#define DT_FIFO __WASI_FILETYPE_SOCKET_STREAM -#define DT_LNK __WASI_FILETYPE_SYMBOLIC_LINK -#define DT_REG __WASI_FILETYPE_REGULAR_FILE +#define DT_BLK 1 +#define DT_CHR 2 +#define DT_DIR 3 +#define DT_FIFO 6 +#define DT_LNK 7 +#define DT_REG 4 #define DT_SOCK 20 -#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN +#define DT_UNKNOWN 0 #define D_FMT 0x20029 #define D_T_FMT 0x20028 -#define E2BIG __WASI_ERRNO_2BIG -#define EACCES __WASI_ERRNO_ACCES +#define E2BIG 1 +#define EACCES 2 #define EACCESS 2 -#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 EADDRINUSE 3 +#define EADDRNOTAVAIL 4 +#define EAFNOSUPPORT 5 +#define EAGAIN 6 +#define EALREADY 7 +#define EBADF 8 #define EBADID 5 -#define EBADMSG __WASI_ERRNO_BADMSG +#define EBADMSG 9 #define EBADOP 4 -#define EBUSY __WASI_ERRNO_BUSY +#define EBUSY 10 #define EC 247 -#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 ECANCELED 11 +#define ECHILD 12 +#define ECONNABORTED 13 +#define ECONNREFUSED 14 +#define ECONNRESET 15 +#define EDEADLK 16 +#define EDESTADDRREQ 17 +#define EDOM 18 +#define EDQUOT 19 +#define EEXIST 20 #define EEXISTS 6 -#define EFAULT __WASI_ERRNO_FAULT -#define EFBIG __WASI_ERRNO_FBIG +#define EFAULT 21 +#define EFBIG 22 #define EFD_CLOEXEC O_CLOEXEC #define EFD_NONBLOCK O_NONBLOCK #define EFD_SEMAPHORE 1 -#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 EHOSTUNREACH 23 +#define EIDRM 24 +#define EILSEQ 25 +#define EINPROGRESS 26 +#define EINTR 27 +#define EINVAL 28 +#define EIO 29 +#define EISCONN 30 +#define EISDIR 31 #define EL 248 -#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 ELOOP 32 +#define EMFILE 33 +#define EMLINK 34 +#define EMSGSIZE 35 +#define EMULTIHOP 36 +#define ENAMETOOLONG 37 #define ENCRYPT_CNT 9 #define ENCRYPT_DEC_KEYID 8 #define ENCRYPT_ENC_KEYID 7 @@ -249,60 +249,60 @@ #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_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 ENETDOWN 38 +#define ENETRESET 39 +#define ENETUNREACH 40 +#define ENFILE 41 +#define ENOBUFS 42 +#define ENODEV 43 +#define ENOENT 44 +#define ENOEXEC 45 +#define ENOLCK 46 +#define ENOLINK 47 +#define ENOMEM 48 +#define ENOMSG 49 +#define ENOPROTOOPT 50 #define ENOSPACE 3 -#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 ENOSPC 51 +#define ENOSYS 52 +#define ENOTCAPABLE 76 +#define ENOTCONN 53 +#define ENOTDIR 54 +#define ENOTEMPTY 55 #define ENOTFOUND 1 -#define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE -#define ENOTSOCK __WASI_ERRNO_NOTSOCK -#define ENOTSUP __WASI_ERRNO_NOTSUP -#define ENOTTY __WASI_ERRNO_NOTTY +#define ENOTRECOVERABLE 56 +#define ENOTSOCK 57 +#define ENOTSUP 58 +#define ENOTTY 59 #define ENOUSER 7 #define ENV_ESC 2 #define ENV_USERVAR 3 -#define ENXIO __WASI_ERRNO_NXIO +#define ENXIO 60 #define EOF (-1) #define EOPNOTSUPP ENOTSUP #define EOR 239 -#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 EOVERFLOW 61 +#define EOWNERDEAD 62 +#define EPERM 63 +#define EPIPE 64 +#define EPROTO 65 +#define EPROTONOSUPPORT 66 +#define EPROTOTYPE 67 #define ERA 0x2002C -#define ERANGE __WASI_ERRNO_RANGE +#define ERANGE 68 #define ERA_D_FMT 0x2002E #define ERA_D_T_FMT 0x20030 #define ERA_T_FMT 0x20031 -#define EROFS __WASI_ERRNO_ROFS +#define EROFS 69 #define ERROR 05 -#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 ESPIPE 70 +#define ESRCH 71 +#define ESTALE 72 +#define ETIMEDOUT 73 +#define ETXTBSY 74 #define EUNDEF 0 #define EWOULDBLOCK EAGAIN -#define EXDEV __WASI_ERRNO_XDEV +#define EXDEV 75 #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define EX_CANTCREAT 73 @@ -1294,22 +1294,22 @@ #define OLD_ENV_VAR 1 #define ONCE_FLAG_INIT 0 #define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH) -#define O_APPEND __WASI_FDFLAGS_APPEND +#define O_APPEND 0x0001 #define O_CLOEXEC (0) -#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_CREAT (0x0001 << 12) +#define O_DIRECTORY (0x0002 << 12) +#define O_DSYNC 0x0002 +#define O_EXCL (0x0004 << 12) #define O_EXEC (0x02000000) #define O_NOCTTY (0) #define O_NOFOLLOW (0x01000000) -#define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK +#define O_NONBLOCK 0x0004 #define O_RDONLY (0x04000000) #define O_RDWR (O_RDONLY | O_WRONLY) -#define O_RSYNC __WASI_FDFLAGS_RSYNC +#define O_RSYNC 0x0008 #define O_SEARCH (0x08000000) -#define O_SYNC __WASI_FDFLAGS_SYNC -#define O_TRUNC (__WASI_OFLAGS_TRUNC << 12) +#define O_SYNC 0x0010 +#define O_TRUNC (0x0008 << 12) #define O_TTY_INIT (0) #define O_WRONLY (0x10000000) #define PACKETSZ NS_PACKETSZ @@ -1362,12 +1362,12 @@ #define POLLRDNORM 0x1 #define POLLWRNORM 0x2 #define POSIX_CLOSE_RESTART 0 -#define POSIX_FADV_DONTNEED __WASI_ADVICE_DONTNEED -#define POSIX_FADV_NOREUSE __WASI_ADVICE_NOREUSE -#define POSIX_FADV_NORMAL __WASI_ADVICE_NORMAL -#define POSIX_FADV_RANDOM __WASI_ADVICE_RANDOM -#define POSIX_FADV_SEQUENTIAL __WASI_ADVICE_SEQUENTIAL -#define POSIX_FADV_WILLNEED __WASI_ADVICE_WILLNEED +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_NOREUSE 5 +#define POSIX_FADV_NORMAL 0 +#define POSIX_FADV_RANDOM 2 +#define POSIX_FADV_SEQUENTIAL 1 +#define POSIX_FADV_WILLNEED 3 #define PRELIM 1 #define PRIX16 __UINT16_FMTX__ #define PRIX32 __UINT32_FMTX__ @@ -1620,18 +1620,18 @@ #define SCNxMAX __UINTMAX_FMTx__ #define SCNxPTR __UINTPTR_FMTx__ #define SE 240 -#define SEEK_CUR __WASI_WHENCE_CUR -#define SEEK_END __WASI_WHENCE_END -#define SEEK_SET __WASI_WHENCE_SET +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_SET 0 #define SEGSIZE 512 #define SEM_FAILED ((sem_t *)0) #define SERVFAIL ns_r_servfail #define SHORTBITS (sizeof(short) * 8) #define SHRT_MAX 0x7fff #define SHRT_MIN (-1-0x7fff) -#define SHUT_RD __WASI_SDFLAGS_RD +#define SHUT_RD 1 #define SHUT_RDWR (SHUT_RD | SHUT_WR) -#define SHUT_WR __WASI_SDFLAGS_WR +#define SHUT_WR 2 #define SIG_ATOMIC_MAX INT32_MAX #define SIG_ATOMIC_MIN INT32_MIN #define SIZE_MAX UINT32_MAX @@ -1672,9 +1672,9 @@ #define SNDPIPE 0x002 #define SNDZERO 0x001 #define SOCK_CLOEXEC (0x00002000) -#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM +#define SOCK_DGRAM 5 #define SOCK_NONBLOCK (0x00004000) -#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM +#define SOCK_STREAM 6 #define SOL_SOCKET 0x7fffffff #define SOL_TCP 6 #define SOL_UDP 17 @@ -1905,7 +1905,7 @@ #define TH_RST 0x04 #define TH_SYN 0x02 #define TH_URG 0x20 -#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME +#define TIMER_ABSTIME 1 #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 diff --git a/expected/wasm32-wasip2/defined-symbols.txt b/expected/wasm32-wasip2/defined-symbols.txt index 5ca31fb7c..c23a9f83e 100644 --- a/expected/wasm32-wasip2/defined-symbols.txt +++ b/expected/wasm32-wasip2/defined-symbols.txt @@ -1573,4 +1573,4 @@ y0f y1 y1f yn -ynf +ynf \ No newline at end of file diff --git a/expected/wasm32-wasip2/predefined-macros.txt b/expected/wasm32-wasip2/predefined-macros.txt index 912b5e0f5..5995dacf7 100644 --- a/expected/wasm32-wasip2/predefined-macros.txt +++ b/expected/wasm32-wasip2/predefined-macros.txt @@ -182,23 +182,23 @@ #define DONT 254 #define DOUBLEBITS (sizeof(double) * 8) #define DTTOIF(x) (__wasilibc_dttoif(x)) -#define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE -#define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE -#define DT_DIR __WASI_FILETYPE_DIRECTORY -#define DT_FIFO __WASI_FILETYPE_SOCKET_STREAM -#define DT_LNK __WASI_FILETYPE_SYMBOLIC_LINK -#define DT_REG __WASI_FILETYPE_REGULAR_FILE +#define DT_BLK 1 +#define DT_CHR 2 +#define DT_DIR 3 +#define DT_FIFO 6 +#define DT_LNK 7 +#define DT_REG 4 #define DT_SOCK 20 -#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN +#define DT_UNKNOWN 0 #define D_FMT 0x20029 #define D_T_FMT 0x20028 -#define E2BIG __WASI_ERRNO_2BIG -#define EACCES __WASI_ERRNO_ACCES +#define E2BIG 1 +#define EACCES 2 #define EACCESS 2 -#define EADDRINUSE __WASI_ERRNO_ADDRINUSE -#define EADDRNOTAVAIL __WASI_ERRNO_ADDRNOTAVAIL -#define EAFNOSUPPORT __WASI_ERRNO_AFNOSUPPORT -#define EAGAIN __WASI_ERRNO_AGAIN +#define EADDRINUSE 3 +#define EADDRNOTAVAIL 4 +#define EAFNOSUPPORT 5 +#define EAGAIN 6 #define EAI_ADDRFAMILY -9 #define EAI_AGAIN -3 #define EAI_ALLDONE -103 @@ -217,45 +217,45 @@ #define EAI_SERVICE -8 #define EAI_SOCKTYPE -7 #define EAI_SYSTEM -11 -#define EALREADY __WASI_ERRNO_ALREADY -#define EBADF __WASI_ERRNO_BADF +#define EALREADY 7 +#define EBADF 8 #define EBADID 5 -#define EBADMSG __WASI_ERRNO_BADMSG +#define EBADMSG 9 #define EBADOP 4 -#define EBUSY __WASI_ERRNO_BUSY +#define EBUSY 10 #define EC 247 -#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 ECANCELED 11 +#define ECHILD 12 +#define ECONNABORTED 13 +#define ECONNREFUSED 14 +#define ECONNRESET 15 +#define EDEADLK 16 +#define EDESTADDRREQ 17 +#define EDOM 18 +#define EDQUOT 19 +#define EEXIST 20 #define EEXISTS 6 -#define EFAULT __WASI_ERRNO_FAULT -#define EFBIG __WASI_ERRNO_FBIG +#define EFAULT 21 +#define EFBIG 22 #define EFD_CLOEXEC O_CLOEXEC #define EFD_NONBLOCK O_NONBLOCK #define EFD_SEMAPHORE 1 -#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 EHOSTUNREACH 23 +#define EIDRM 24 +#define EILSEQ 25 +#define EINPROGRESS 26 +#define EINTR 27 +#define EINVAL 28 +#define EIO 29 +#define EISCONN 30 +#define EISDIR 31 #define EL 248 -#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 ELOOP 32 +#define EMFILE 33 +#define EMLINK 34 +#define EMSGSIZE 35 +#define EMULTIHOP 36 +#define ENAMETOOLONG 37 #define ENCRYPT_CNT 9 #define ENCRYPT_DEC_KEYID 8 #define ENCRYPT_ENC_KEYID 7 @@ -274,60 +274,60 @@ #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_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 ENETDOWN 38 +#define ENETRESET 39 +#define ENETUNREACH 40 +#define ENFILE 41 +#define ENOBUFS 42 +#define ENODEV 43 +#define ENOENT 44 +#define ENOEXEC 45 +#define ENOLCK 46 +#define ENOLINK 47 +#define ENOMEM 48 +#define ENOMSG 49 +#define ENOPROTOOPT 50 #define ENOSPACE 3 -#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 ENOSPC 51 +#define ENOSYS 52 +#define ENOTCAPABLE 76 +#define ENOTCONN 53 +#define ENOTDIR 54 +#define ENOTEMPTY 55 #define ENOTFOUND 1 -#define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE -#define ENOTSOCK __WASI_ERRNO_NOTSOCK -#define ENOTSUP __WASI_ERRNO_NOTSUP -#define ENOTTY __WASI_ERRNO_NOTTY +#define ENOTRECOVERABLE 56 +#define ENOTSOCK 57 +#define ENOTSUP 58 +#define ENOTTY 59 #define ENOUSER 7 #define ENV_ESC 2 #define ENV_USERVAR 3 -#define ENXIO __WASI_ERRNO_NXIO +#define ENXIO 60 #define EOF (-1) #define EOPNOTSUPP ENOTSUP #define EOR 239 -#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 EOVERFLOW 61 +#define EOWNERDEAD 62 +#define EPERM 63 +#define EPIPE 64 +#define EPROTO 65 +#define EPROTONOSUPPORT 66 +#define EPROTOTYPE 67 #define ERA 0x2002C -#define ERANGE __WASI_ERRNO_RANGE +#define ERANGE 68 #define ERA_D_FMT 0x2002E #define ERA_D_T_FMT 0x20030 #define ERA_T_FMT 0x20031 -#define EROFS __WASI_ERRNO_ROFS +#define EROFS 69 #define ERROR 05 -#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 ESPIPE 70 +#define ESRCH 71 +#define ESTALE 72 +#define ETIMEDOUT 73 +#define ETXTBSY 74 #define EUNDEF 0 #define EWOULDBLOCK EAGAIN -#define EXDEV __WASI_ERRNO_XDEV +#define EXDEV 75 #define EXIT_FAILURE 1 #define EXIT_SUCCESS 0 #define EX_CANTCREAT 73 @@ -1425,22 +1425,22 @@ #define OLD_ENV_VAR 1 #define ONCE_FLAG_INIT 0 #define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH) -#define O_APPEND __WASI_FDFLAGS_APPEND +#define O_APPEND 0x0001 #define O_CLOEXEC (0) -#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_CREAT (0x0001 << 12) +#define O_DIRECTORY (0x0002 << 12) +#define O_DSYNC 0x0002 +#define O_EXCL (0x0004 << 12) #define O_EXEC (0x02000000) #define O_NOCTTY (0) #define O_NOFOLLOW (0x01000000) -#define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK +#define O_NONBLOCK 0x0004 #define O_RDONLY (0x04000000) #define O_RDWR (O_RDONLY | O_WRONLY) -#define O_RSYNC __WASI_FDFLAGS_RSYNC +#define O_RSYNC 0x0008 #define O_SEARCH (0x08000000) -#define O_SYNC __WASI_FDFLAGS_SYNC -#define O_TRUNC (__WASI_OFLAGS_TRUNC << 12) +#define O_SYNC 0x0010 +#define O_TRUNC (0x0008 << 12) #define O_TTY_INIT (0) #define O_WRONLY (0x10000000) #define PACKETSZ NS_PACKETSZ @@ -1493,12 +1493,12 @@ #define POLLRDNORM 0x1 #define POLLWRNORM 0x2 #define POSIX_CLOSE_RESTART 0 -#define POSIX_FADV_DONTNEED __WASI_ADVICE_DONTNEED -#define POSIX_FADV_NOREUSE __WASI_ADVICE_NOREUSE -#define POSIX_FADV_NORMAL __WASI_ADVICE_NORMAL -#define POSIX_FADV_RANDOM __WASI_ADVICE_RANDOM -#define POSIX_FADV_SEQUENTIAL __WASI_ADVICE_SEQUENTIAL -#define POSIX_FADV_WILLNEED __WASI_ADVICE_WILLNEED +#define POSIX_FADV_DONTNEED 4 +#define POSIX_FADV_NOREUSE 5 +#define POSIX_FADV_NORMAL 0 +#define POSIX_FADV_RANDOM 2 +#define POSIX_FADV_SEQUENTIAL 1 +#define POSIX_FADV_WILLNEED 3 #define PRELIM 1 #define PRIX16 __UINT16_FMTX__ #define PRIX32 __UINT32_FMTX__ @@ -1751,18 +1751,18 @@ #define SCNxMAX __UINTMAX_FMTx__ #define SCNxPTR __UINTPTR_FMTx__ #define SE 240 -#define SEEK_CUR __WASI_WHENCE_CUR -#define SEEK_END __WASI_WHENCE_END -#define SEEK_SET __WASI_WHENCE_SET +#define SEEK_CUR 1 +#define SEEK_END 2 +#define SEEK_SET 0 #define SEGSIZE 512 #define SEM_FAILED ((sem_t *)0) #define SERVFAIL ns_r_servfail #define SHORTBITS (sizeof(short) * 8) #define SHRT_MAX 0x7fff #define SHRT_MIN (-1-0x7fff) -#define SHUT_RD __WASI_SDFLAGS_RD +#define SHUT_RD 1 #define SHUT_RDWR (SHUT_RD | SHUT_WR) -#define SHUT_WR __WASI_SDFLAGS_WR +#define SHUT_WR 2 #define SIG_ATOMIC_MAX INT32_MAX #define SIG_ATOMIC_MIN INT32_MIN #define SIZE_MAX UINT32_MAX @@ -1803,9 +1803,9 @@ #define SNDPIPE 0x002 #define SNDZERO 0x001 #define SOCK_CLOEXEC (0x00002000) -#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM +#define SOCK_DGRAM 5 #define SOCK_NONBLOCK (0x00004000) -#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM +#define SOCK_STREAM 6 #define SOL_IP 0 #define SOL_IPV6 41 #define SOL_SOCKET 0x7fffffff @@ -2054,7 +2054,7 @@ #define TH_RST 0x04 #define TH_SYN 0x02 #define TH_URG 0x20 -#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME +#define TIMER_ABSTIME 1 #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 From c4fa8acdfd33818928705e29745c4ff11a6ffa39 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Dec 2025 18:18:18 -0800 Subject: [PATCH 5/5] Reformat --- libc-bottom-half/headers/public/__header_unistd.h | 2 +- test/src/memchr.c | 2 +- test/src/strrchr.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libc-bottom-half/headers/public/__header_unistd.h b/libc-bottom-half/headers/public/__header_unistd.h index 3df64636a..71be8a36d 100644 --- a/libc-bottom-half/headers/public/__header_unistd.h +++ b/libc-bottom-half/headers/public/__header_unistd.h @@ -3,8 +3,8 @@ struct stat; -#include #include <__seek.h> +#include #define F_OK (0) #define X_OK (1) diff --git a/test/src/memchr.c b/test/src/memchr.c index 74234ec1a..e03db5332 100644 --- a/test/src/memchr.c +++ b/test/src/memchr.c @@ -1,8 +1,8 @@ #include <__macro_PAGESIZE.h> #include +#include #include #include -#include void test(char *ptr, size_t length, void *want) { void *got = memchr(ptr, 7, length); diff --git a/test/src/strrchr.c b/test/src/strrchr.c index 54f506231..12ad9f1a8 100644 --- a/test/src/strrchr.c +++ b/test/src/strrchr.c @@ -1,7 +1,7 @@ #include <__macro_PAGESIZE.h> +#include #include #include -#include void test(char *ptr, char *want) { char *got = strrchr(ptr, 7);