diff --git a/CMakeLists.txt b/CMakeLists.txt index 8c2a340c2c765ed7e836fea0d82dda78b34e043e..9e74b6f17b313a6c4bef52610f2d49b33ecda978 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -457,7 +457,6 @@ set(ZIG_STAGE2_SOURCES src/register_manager.zig src/target.zig src/tracy.zig - src/libs/wasi_libc.zig ) if(MSVC) diff --git a/build.zig b/build.zig index 8a216c1808022a621d44954009603ed6f3921af8..53a08e287cfce7eaf6f8d76a83c37e745e563f19 100644 --- a/build.zig +++ b/build.zig @@ -775,7 +775,6 @@ pub fn build(b: *std.Build) !void { .optimize_modes = optimize_modes, .test_filters = test_filters, .test_target_filters = test_target_filters, - .skip_wasm = skip_wasm, .max_rss = 4_300_000_000, })) |test_libc_nsz_step| test_step.dependOn(test_libc_nsz_step); diff --git a/lib/c/ctype.zig b/lib/c/ctype.zig index 9316ee102f9ec971acbb70662cbaf2c7db24a626..25671d66405034074fa7985bf094158942bfecdb 100644 --- a/lib/c/ctype.zig +++ b/lib/c/ctype.zig @@ -3,8 +3,8 @@ const std = @import("std"); const symbol = @import("../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - // Functions specific to musl and wasi-libc. + if (builtin.target.isMuslLibC()) { + // Functions specific to musl. symbol(&isalnum, "isalnum"); symbol(&isalpha, "isalpha"); symbol(&isblank, "isblank"); diff --git a/lib/c/inttypes.zig b/lib/c/inttypes.zig index d8807154d3409359af1b8ab2e6e32d4eabee3a18..d0a4efd1eb1581fb8c541802e26a74200ab0ae59 100644 --- a/lib/c/inttypes.zig +++ b/lib/c/inttypes.zig @@ -7,8 +7,8 @@ const imaxdiv_t = std.c.imaxdiv_t; const symbol = @import("../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - // Functions specific to musl and wasi-libc. + if (builtin.target.isMuslLibC()) { + // Functions specific to musl. symbol(&imaxabs, "imaxabs"); symbol(&imaxdiv, "imaxdiv"); } diff --git a/lib/c/math.zig b/lib/c/math.zig index b1ff37c04e0f454024a0e5e45590cecb34bb0df1..f9073add14799636be748725d54cf786e84c45aa 100644 --- a/lib/c/math.zig +++ b/lib/c/math.zig @@ -31,7 +31,7 @@ comptime { symbol(&math.snan(c_longdouble), "__SNANL"); } - if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMinGW() or builtin.target.isMuslLibC()) { symbol(&frexpf, "frexpf"); symbol(&frexpl, "frexpl"); symbol(&hypotf, "hypotf"); @@ -42,14 +42,14 @@ comptime { symbol(&rintl, "rintl"); } - if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC()) { symbol(&atanl, "atanl"); symbol(©signl, "copysignl"); symbol(&fdiml, "fdiml"); symbol(&nanl, "nanl"); } - if ((builtin.target.isMinGW() and builtin.cpu.arch == .x86) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if ((builtin.target.isMinGW() and builtin.cpu.arch == .x86) or builtin.target.isMuslLibC()) { symbol(&acosf, "acosf"); symbol(&atanf, "atanf"); symbol(&coshf, "coshf"); @@ -57,7 +57,7 @@ comptime { symbol(&tanhf, "tanhf"); } - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { symbol(&acos, "acos"); symbol(&acoshf, "acoshf"); symbol(&asin, "asin"); diff --git a/lib/c/pthread.zig b/lib/c/pthread.zig index b7131bd1eb38c33330eeab361da9e20eb2a3abea..70fa3329649480617277033a96783d89592c3f52 100644 --- a/lib/c/pthread.zig +++ b/lib/c/pthread.zig @@ -6,7 +6,7 @@ const c = std.c; const symbol = @import("../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC() or builtin.target.isMinGW()) { + if (builtin.target.isMuslLibC() or builtin.target.isMinGW()) { symbol(&pthread_spin_init, "pthread_spin_init"); symbol(&pthread_spin_destroy, "pthread_spin_destroy"); symbol(&pthread_spin_trylock, "pthread_spin_trylock"); diff --git a/lib/c/search.zig b/lib/c/search.zig index 12a9018d63b5849a04014682d561e0bec93ee783..9b42a67156fb7839b41b042db502a908c4592885 100644 --- a/lib/c/search.zig +++ b/lib/c/search.zig @@ -3,7 +3,7 @@ const builtin = @import("builtin"); const symbol = @import("../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { symbol(&insque, "insque"); symbol(&remque, "remque"); } diff --git a/lib/c/stdlib.zig b/lib/c/stdlib.zig index 4f3d6cf5869ee46ae7a54def9f597b33eb082d7e..c5cbbfff3316e7c5c9bae17d7f61e14d7c7d7aef 100644 --- a/lib/c/stdlib.zig +++ b/lib/c/stdlib.zig @@ -12,8 +12,8 @@ comptime { _ = @import("stdlib/rand.zig"); _ = @import("stdlib/drand48.zig"); - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { - // Functions specific to musl and wasi-libc. + if (builtin.target.isMuslLibC()) { + // Functions specific to musl. symbol(&abs, "abs"); symbol(&labs, "labs"); symbol(&llabs, "llabs"); diff --git a/lib/c/stdlib/drand48.zig b/lib/c/stdlib/drand48.zig index 692230d12196cfa75be727a3fa61c117aea2e967..46e72de0b901d45fab48ad0f8d3eafc5e56281d5 100644 --- a/lib/c/stdlib/drand48.zig +++ b/lib/c/stdlib/drand48.zig @@ -8,7 +8,7 @@ const Lcg = std.Random.lcg.Wrapping(u48); const symbol = @import("../../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { symbol(&erand48, "erand48"); symbol(&jrand48, "jrand48"); symbol(&nrand48, "nrand48"); diff --git a/lib/c/stdlib/rand.zig b/lib/c/stdlib/rand.zig index a160a9d376c440584247c0aa72140e3d7a92eb95..2a9acaa42382a475b3dff7383a4d0cb6280bbf5c 100644 --- a/lib/c/stdlib/rand.zig +++ b/lib/c/stdlib/rand.zig @@ -3,7 +3,7 @@ const std = @import("std"); const symbol = @import("../../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { symbol(&rand, "rand"); symbol(&srand, "srand"); symbol(&rand_r, "rand_r"); diff --git a/lib/c/string.zig b/lib/c/string.zig index 31a11b1ce95fd62ffa367c11e24d11c7025622c3..81d80050a290d21df7825e5875f2e16f30ba76d2 100644 --- a/lib/c/string.zig +++ b/lib/c/string.zig @@ -6,7 +6,7 @@ const c = std.c; comptime { symbol(&strndup, "strndup"); - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { // memcpy implemented in compiler_rt // memmove implemented in compiler_rt // memset implemented in compiler_rt @@ -53,7 +53,7 @@ comptime { symbol(&__strcoll_l, "strcoll_l"); symbol(&__strxfrm_l, "strxfrm_l"); - // These symbols are not in the public ABI of musl/wasi. However they depend on these exports internally. + // These symbols are not in the public ABI of musl. However it depends on these exports internally. symbol(&stpcpy, "__stpcpy"); symbol(&stpncpy, "__stpncpy"); symbol(&strchrnul, "__strchrnul"); diff --git a/lib/c/strings.zig b/lib/c/strings.zig index 111da9ad0f04eff48c890c6b33b5481c733a8aae..ecb52275abd924ea7b365c35ad4bd923c7f5921c 100644 --- a/lib/c/strings.zig +++ b/lib/c/strings.zig @@ -3,7 +3,7 @@ const std = @import("std"); const symbol = @import("../c.zig").symbol; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { // bcmp is implemented in compiler_rt symbol(&bcopy, "bcopy"); symbol(&bzero, "bzero"); diff --git a/lib/c/sys/utsname.zig b/lib/c/sys/utsname.zig index 5ae02adbc40b00329be390a7e15eb872fac30be7..df54c237ef7b4f08931cd3d402e0548af8f196f8 100644 --- a/lib/c/sys/utsname.zig +++ b/lib/c/sys/utsname.zig @@ -9,27 +9,8 @@ comptime { if (builtin.target.isMuslLibC()) { symbol(&unameLinux, "uname"); } - - if (builtin.target.isWasiLibC()) { - symbol(&unameWasi, "uname"); - } } fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int { return errno(std.os.linux.uname(uts)); } - -fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int { - // note the @bitCast's for NUL termination! - uts.sysname[0..5].* = @bitCast("wasi".*); - uts.nodename[0..7].* = @bitCast("(none)".*); - uts.release[0..6].* = @bitCast("0.0.0".*); - uts.version[0..6].* = @bitCast("0.0.0".*); - uts.machine[0..7].* = @bitCast(switch (builtin.target.cpu.arch) { - .wasm32 => "wasm32", - .wasm64 => "wasm64", - else => comptime unreachable, - }.*); - uts.domainname[0..7].* = @bitCast("(none)".*); - return 0; -} diff --git a/lib/c/unistd.zig b/lib/c/unistd.zig index 44a80a95ab16a497e1d83149cd61bfb3a333e666..f958c2f3e31bef7034dc2b633ed4976309a5e7b1 100644 --- a/lib/c/unistd.zig +++ b/lib/c/unistd.zig @@ -51,12 +51,9 @@ comptime { symbol(&execveLinux, "execve"); } - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { symbol(&swab, "swab"); } - if (builtin.target.isWasiLibC()) { - symbol(&closeWasi, "close"); - } } fn _exit(exit_code: c_int) callconv(.c) noreturn { @@ -248,13 +245,3 @@ fn close(fd: std.c.fd_t) callconv(.c) c_int { fn posix_close(fd: std.c.fd_t, _: c_int) callconv(.c) c_int { return close(fd); } - -fn closeWasi(fd: std.c.fd_t) callconv(.c) c_int { - switch (std.os.wasi.fd_close(fd)) { - .SUCCESS => return 0, - else => |e| { - std.c._errno().* = @backingInt(e); - return -1; - }, - } -} diff --git a/lib/c/wchar.zig b/lib/c/wchar.zig index e8837247a0d6799e63796a46c918b55c647aa9f7..81858e2136527c52b4345d2e228ef8e3f6325633 100644 --- a/lib/c/wchar.zig +++ b/lib/c/wchar.zig @@ -8,7 +8,7 @@ const symbol = @import("../c.zig").symbol; const c = std.c; comptime { - if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { + if (builtin.target.isMuslLibC()) { symbol(&wmemchr, "wmemchr"); symbol(&wmemcmp, "wmemcmp"); symbol(&wmemcpy, "wmemcpy"); diff --git a/lib/compiler_rt.zig b/lib/compiler_rt.zig index 885af93f59009fe62c6344475b7333435e60ac93..5660847ce84fbbedc64d4e980202e3865f8df592 100644 --- a/lib/compiler_rt.zig +++ b/lib/compiler_rt.zig @@ -267,7 +267,6 @@ pub const want_float_exceptions = !builtin.cpu.arch.isWasm(); /// arm-linux-musleabihf => true /// arm-linux-gnueabihf => true /// arm-linux-eabihf => false -/// wasm32-wasi-musl => false /// wasm32-freestanding-none => false /// x86_64-windows-gnu => true /// x86_64-windows-msvc => true diff --git a/lib/libc/include/wasm-wasi-musl/__errno.h b/lib/libc/include/wasm-wasi-musl/__errno.h deleted file mode 100644 index 008245d9788e61faa4af1247ba389b84d7bb56df..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__errno.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __wasilibc___errno_h -#define __wasilibc___errno_h - -#ifdef __cplusplus -extern "C" { -#endif - -extern _Thread_local int errno; - -#define errno errno - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__errno_values.h b/lib/libc/include/wasm-wasi-musl/__errno_values.h deleted file mode 100644 index 6d6d412046d778a36456ef63dc0000c53f36bcdc..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__errno_values.h +++ /dev/null @@ -1,86 +0,0 @@ -#ifndef __wasilibc___errno_values_h -#define __wasilibc___errno_values_h - -#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 EOPNOTSUPP ENOTSUP -#define EWOULDBLOCK EAGAIN - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__fd_set.h b/lib/libc/include/wasm-wasi-musl/__fd_set.h deleted file mode 100644 index 7be0b9fcea0411d5cc6a838ba4860b058aa4fb87..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__fd_set.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef __wasilibc___fd_set_h -#define __wasilibc___fd_set_h - -#include <__typedef_fd_set.h> - -#ifdef __cplusplus -extern "C" { -#endif - -static __inline void FD_CLR(int __fd, fd_set *__set) { - size_t __n = __set->__nfds; - for (int *__p = __set->__fds, *__e = __p + __n; - __p < __e; ++__p) - { - if (*__p == __fd) { - *__p = __e[-1]; - __set->__nfds = __n - 1; - return; - } - } -} - -static __inline -#ifdef __cplusplus -bool -#else -_Bool -#endif -FD_ISSET(int __fd, const fd_set *__set) -{ - size_t __n = __set->__nfds; - for (const int *__p = __set->__fds, *__e = __p + __n; - __p < __e; ++__p) - { - if (*__p == __fd) { - return 1; - } - } - return 0; -} - -static __inline void FD_SET(int __fd, fd_set *__set) { - size_t __n = __set->__nfds; - for (const int *__p = __set->__fds, *__e = __p + __n; - __p < __e; ++__p) - { - if (*__p == __fd) { - return; - } - } - __set->__nfds = __n + 1; - __set->__fds[__n] = __fd; -} - -static __inline void FD_ZERO(fd_set *__set) { - __set->__nfds = 0; -} - -static __inline void FD_COPY(const fd_set *__restrict __from, - fd_set *__restrict __to) { - size_t __n = __from->__nfds; - __to->__nfds = __n; - __builtin_memcpy(__to->__fds, __from->__fds, __n * sizeof(int)); -} - -#define FD_CLR(fd, set) (FD_CLR((fd), (set))) -#define FD_ISSET(fd, set) (FD_ISSET((fd), (set))) -#define FD_SET(fd, set) (FD_SET((fd), (set))) -#define FD_ZERO(set) (FD_ZERO((set))) -#define FD_COPY(from, to) (FD_COPY((from), (to))) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__function___isatty.h b/lib/libc/include/wasm-wasi-musl/__function___isatty.h deleted file mode 100644 index 7c0464519a4282b772144941813ef7f1cb5b6bc1..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__function___isatty.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __wasilibc___function___isatty_h -#define __wasilibc___function___isatty_h - -#ifdef __cplusplus -extern "C" { -#endif - -int __isatty(int fd); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__functions_malloc.h b/lib/libc/include/wasm-wasi-musl/__functions_malloc.h deleted file mode 100644 index d516bc3484d613f935514ccc9f2d11338ee11761..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__functions_malloc.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef __wasilibc___functions_malloc_h -#define __wasilibc___functions_malloc_h - -#define __need_size_t -#define __need_wchar_t -#define __need_NULL -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void *malloc(size_t __size) __attribute__((__malloc__, __warn_unused_result__)); -void free(void *__ptr); -void *calloc(size_t __nmemb, size_t __size) __attribute__((__malloc__, __warn_unused_result__)); -void *realloc(void *__ptr, size_t __size) __attribute__((__warn_unused_result__)); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -void *reallocarray(void *__ptr, size_t __nmemb, size_t __size) __attribute__((__warn_unused_result__)); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__functions_memcpy.h b/lib/libc/include/wasm-wasi-musl/__functions_memcpy.h deleted file mode 100644 index 253b06586dfb4798852e4dec10a2a6bc5910e235..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__functions_memcpy.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __wasilibc___functions_memcpy_h -#define __wasilibc___functions_memcpy_h - -#define __need_size_t -#define __need_NULL -#include - -#ifdef __cplusplus -extern "C" { -#endif - -void *memcpy(void *__restrict__ __dst, const void *__restrict__ __src, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2))); -void *memmove(void *__dst, const void *__src, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2))); -void *memset(void *__dst, int __c, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1))); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_dirent.h b/lib/libc/include/wasm-wasi-musl/__header_dirent.h deleted file mode 100644 index 027fc07a99452bef16f5293170f575143058b82c..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_dirent.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef __wasilibc___header_dirent_h -#define __wasilibc___header_dirent_h - -#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_SOCK 20 - -#define IFTODT(x) (__wasilibc_iftodt(x)) -#define DTTOIF(x) (__wasilibc_dttoif(x)) - -#include <__struct_dirent.h> -#include <__typedef_DIR.h> - -#ifdef __cplusplus -extern "C" { -#endif - -int __wasilibc_iftodt(int x); -int __wasilibc_dttoif(int x); - -int closedir(DIR *); -DIR *opendir(const char *); -DIR *fdopendir(int); -int fdclosedir(DIR *); -struct dirent *readdir(DIR *); -void rewinddir(DIR *); -void seekdir(DIR *, long); -long telldir(DIR *); -DIR *opendirat(int, const char *); -void rewinddir(DIR *); -int scandirat(int, const char *, struct dirent ***, - int (*)(const struct dirent *), - int (*)(const struct dirent **, const struct dirent **)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_fcntl.h b/lib/libc/include/wasm-wasi-musl/__header_fcntl.h deleted file mode 100644 index 04252acc4adcf422edcfb2fff1fc8c2c20c1d25f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_fcntl.h +++ /dev/null @@ -1,61 +0,0 @@ -#ifndef __wasilibc___header_fcntl_h -#define __wasilibc___header_fcntl_h - -#include -#include <__seek.h> -#include <__mode_t.h> - -#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) -#define O_RDONLY (0x04000000) -#define O_SEARCH (0x08000000) -#define O_WRONLY (0x10000000) - -/* - * O_CLOEXEC is defined to be zero, as WASI has no exec-style functions. - */ -#define O_CLOEXEC (0) - -/* - * O_TTY_INIT is defined to be zero, meaning that WASI implementations are - * expected to always initialize a terminal the first time it's opened. - */ -#define O_TTY_INIT (0) - -#define O_NOCTTY (0) - -#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 F_GETFD (1) -#define F_SETFD (2) -#define F_GETFL (3) -#define F_SETFL (4) - -#define FD_CLOEXEC (1) - -#define AT_EACCESS (0x0) -#define AT_SYMLINK_NOFOLLOW (0x1) -#define AT_SYMLINK_FOLLOW (0x2) -#define AT_REMOVEDIR (0x4) - -#define AT_FDCWD (-2) - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_inttypes.h b/lib/libc/include/wasm-wasi-musl/__header_inttypes.h deleted file mode 100644 index 47c5c9b6380cc634fc4f3512ca65408b5f9a2cfb..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_inttypes.h +++ /dev/null @@ -1,182 +0,0 @@ -#ifndef __wasilibc___include_inttypes_h -#define __wasilibc___include_inttypes_h - -#include - -#define __need_wchar_t -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { intmax_t quot, rem; } imaxdiv_t; - -intmax_t imaxabs(intmax_t); -imaxdiv_t imaxdiv(intmax_t, intmax_t); -intmax_t strtoimax(const char *__restrict, char **__restrict, int); -uintmax_t strtoumax(const char *__restrict, char **__restrict, int); -intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); -uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); - -#define PRId16 __INT16_FMTd__ -#define PRIi16 __INT16_FMTi__ -#define PRId32 __INT32_FMTd__ -#define PRIi32 __INT32_FMTi__ -#define PRId64 __INT64_FMTd__ -#define PRIi64 __INT64_FMTi__ -#define PRId8 __INT8_FMTd__ -#define PRIi8 __INT8_FMTi__ -#define PRIdMAX __INTMAX_FMTd__ -#define PRIiMAX __INTMAX_FMTi__ -#define PRIdPTR __INTPTR_FMTd__ -#define PRIiPTR __INTPTR_FMTi__ -#define PRIdFAST16 __INT_FAST16_FMTd__ -#define PRIiFAST16 __INT_FAST16_FMTi__ -#define PRIdFAST32 __INT_FAST32_FMTd__ -#define PRIiFAST32 __INT_FAST32_FMTi__ -#define PRIdFAST64 __INT_FAST64_FMTd__ -#define PRIiFAST64 __INT_FAST64_FMTi__ -#define PRIdFAST8 __INT_FAST8_FMTd__ -#define PRIiFAST8 __INT_FAST8_FMTi__ -#define PRIdLEAST16 __INT_LEAST16_FMTd__ -#define PRIiLEAST16 __INT_LEAST16_FMTi__ -#define PRIdLEAST32 __INT_LEAST32_FMTd__ -#define PRIiLEAST32 __INT_LEAST32_FMTi__ -#define PRIdLEAST64 __INT_LEAST64_FMTd__ -#define PRIiLEAST64 __INT_LEAST64_FMTi__ -#define PRIdLEAST8 __INT_LEAST8_FMTd__ -#define PRIiLEAST8 __INT_LEAST8_FMTi__ -#define PRIX16 __UINT16_FMTX__ -#define PRIo16 __UINT16_FMTo__ -#define PRIu16 __UINT16_FMTu__ -#define PRIx16 __UINT16_FMTx__ -#define PRIX32 __UINT32_FMTX__ -#define PRIo32 __UINT32_FMTo__ -#define PRIu32 __UINT32_FMTu__ -#define PRIx32 __UINT32_FMTx__ -#define PRIX64 __UINT64_FMTX__ -#define PRIo64 __UINT64_FMTo__ -#define PRIu64 __UINT64_FMTu__ -#define PRIx64 __UINT64_FMTx__ -#define PRIX8 __UINT8_FMTX__ -#define PRIo8 __UINT8_FMTo__ -#define PRIu8 __UINT8_FMTu__ -#define PRIx8 __UINT8_FMTx__ -#define PRIXMAX __UINTMAX_FMTX__ -#define PRIoMAX __UINTMAX_FMTo__ -#define PRIuMAX __UINTMAX_FMTu__ -#define PRIxMAX __UINTMAX_FMTx__ -#define PRIXPTR __UINTPTR_FMTX__ -#define PRIoPTR __UINTPTR_FMTo__ -#define PRIuPTR __UINTPTR_FMTu__ -#define PRIxPTR __UINTPTR_FMTx__ -#define PRIXFAST16 __UINT_FAST16_FMTX__ -#define PRIoFAST16 __UINT_FAST16_FMTo__ -#define PRIuFAST16 __UINT_FAST16_FMTu__ -#define PRIxFAST16 __UINT_FAST16_FMTx__ -#define PRIXFAST32 __UINT_FAST32_FMTX__ -#define PRIoFAST32 __UINT_FAST32_FMTo__ -#define PRIuFAST32 __UINT_FAST32_FMTu__ -#define PRIxFAST32 __UINT_FAST32_FMTx__ -#define PRIXFAST64 __UINT_FAST64_FMTX__ -#define PRIoFAST64 __UINT_FAST64_FMTo__ -#define PRIuFAST64 __UINT_FAST64_FMTu__ -#define PRIxFAST64 __UINT_FAST64_FMTx__ -#define PRIXFAST8 __UINT_FAST8_FMTX__ -#define PRIoFAST8 __UINT_FAST8_FMTo__ -#define PRIuFAST8 __UINT_FAST8_FMTu__ -#define PRIxFAST8 __UINT_FAST8_FMTx__ -#define PRIXLEAST16 __UINT_LEAST16_FMTX__ -#define PRIoLEAST16 __UINT_LEAST16_FMTo__ -#define PRIuLEAST16 __UINT_LEAST16_FMTu__ -#define PRIxLEAST16 __UINT_LEAST16_FMTx__ -#define PRIXLEAST32 __UINT_LEAST32_FMTX__ -#define PRIoLEAST32 __UINT_LEAST32_FMTo__ -#define PRIuLEAST32 __UINT_LEAST32_FMTu__ -#define PRIxLEAST32 __UINT_LEAST32_FMTx__ -#define PRIXLEAST64 __UINT_LEAST64_FMTX__ -#define PRIoLEAST64 __UINT_LEAST64_FMTo__ -#define PRIuLEAST64 __UINT_LEAST64_FMTu__ -#define PRIxLEAST64 __UINT_LEAST64_FMTx__ -#define PRIXLEAST8 __UINT_LEAST8_FMTX__ -#define PRIoLEAST8 __UINT_LEAST8_FMTo__ -#define PRIuLEAST8 __UINT_LEAST8_FMTu__ -#define PRIxLEAST8 __UINT_LEAST8_FMTx__ - -#define SCNd16 __INT16_FMTd__ -#define SCNi16 __INT16_FMTi__ -#define SCNd32 __INT32_FMTd__ -#define SCNi32 __INT32_FMTi__ -#define SCNd64 __INT64_FMTd__ -#define SCNi64 __INT64_FMTi__ -#define SCNd8 __INT8_FMTd__ -#define SCNi8 __INT8_FMTi__ -#define SCNdMAX __INTMAX_FMTd__ -#define SCNiMAX __INTMAX_FMTi__ -#define SCNdPTR __INTPTR_FMTd__ -#define SCNiPTR __INTPTR_FMTi__ -#define SCNdFAST16 __INT_FAST16_FMTd__ -#define SCNiFAST16 __INT_FAST16_FMTi__ -#define SCNdFAST32 __INT_FAST32_FMTd__ -#define SCNiFAST32 __INT_FAST32_FMTi__ -#define SCNdFAST64 __INT_FAST64_FMTd__ -#define SCNiFAST64 __INT_FAST64_FMTi__ -#define SCNdFAST8 __INT_FAST8_FMTd__ -#define SCNiFAST8 __INT_FAST8_FMTi__ -#define SCNdLEAST16 __INT_LEAST16_FMTd__ -#define SCNiLEAST16 __INT_LEAST16_FMTi__ -#define SCNdLEAST32 __INT_LEAST32_FMTd__ -#define SCNiLEAST32 __INT_LEAST32_FMTi__ -#define SCNdLEAST64 __INT_LEAST64_FMTd__ -#define SCNiLEAST64 __INT_LEAST64_FMTi__ -#define SCNdLEAST8 __INT_LEAST8_FMTd__ -#define SCNiLEAST8 __INT_LEAST8_FMTi__ -#define SCNo16 __UINT16_FMTo__ -#define SCNu16 __UINT16_FMTu__ -#define SCNx16 __UINT16_FMTx__ -#define SCNo32 __UINT32_FMTo__ -#define SCNu32 __UINT32_FMTu__ -#define SCNx32 __UINT32_FMTx__ -#define SCNo64 __UINT64_FMTo__ -#define SCNu64 __UINT64_FMTu__ -#define SCNx64 __UINT64_FMTx__ -#define SCNo8 __UINT8_FMTo__ -#define SCNu8 __UINT8_FMTu__ -#define SCNx8 __UINT8_FMTx__ -#define SCNoMAX __UINTMAX_FMTo__ -#define SCNuMAX __UINTMAX_FMTu__ -#define SCNxMAX __UINTMAX_FMTx__ -#define SCNoPTR __UINTPTR_FMTo__ -#define SCNuPTR __UINTPTR_FMTu__ -#define SCNxPTR __UINTPTR_FMTx__ -#define SCNoFAST16 __UINT_FAST16_FMTo__ -#define SCNuFAST16 __UINT_FAST16_FMTu__ -#define SCNxFAST16 __UINT_FAST16_FMTx__ -#define SCNoFAST32 __UINT_FAST32_FMTo__ -#define SCNuFAST32 __UINT_FAST32_FMTu__ -#define SCNxFAST32 __UINT_FAST32_FMTx__ -#define SCNoFAST64 __UINT_FAST64_FMTo__ -#define SCNuFAST64 __UINT_FAST64_FMTu__ -#define SCNxFAST64 __UINT_FAST64_FMTx__ -#define SCNoFAST8 __UINT_FAST8_FMTo__ -#define SCNuFAST8 __UINT_FAST8_FMTu__ -#define SCNxFAST8 __UINT_FAST8_FMTx__ -#define SCNoLEAST16 __UINT_LEAST16_FMTo__ -#define SCNuLEAST16 __UINT_LEAST16_FMTu__ -#define SCNxLEAST16 __UINT_LEAST16_FMTx__ -#define SCNoLEAST32 __UINT_LEAST32_FMTo__ -#define SCNuLEAST32 __UINT_LEAST32_FMTu__ -#define SCNxLEAST32 __UINT_LEAST32_FMTx__ -#define SCNoLEAST64 __UINT_LEAST64_FMTo__ -#define SCNuLEAST64 __UINT_LEAST64_FMTu__ -#define SCNxLEAST64 __UINT_LEAST64_FMTx__ -#define SCNoLEAST8 __UINT_LEAST8_FMTo__ -#define SCNuLEAST8 __UINT_LEAST8_FMTu__ -#define SCNxLEAST8 __UINT_LEAST8_FMTx__ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_netinet_in.h b/lib/libc/include/wasm-wasi-musl/__header_netinet_in.h deleted file mode 100644 index 30359c88ff1c243c742ad6b4d5ab9d0b3ed6d34e..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_netinet_in.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef __wasilibc___header_netinet_in_h -#define __wasilibc___header_netinet_in_h - -#include <__struct_in_addr.h> -#include <__struct_in6_addr.h> -#include <__struct_sockaddr_in.h> -#include <__struct_sockaddr_in6.h> - -#define IPPROTO_IP 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_TCP 6 -#define IPPROTO_UDP 17 -#define IPPROTO_IPV6 41 -#define IPPROTO_RAW 255 - -#define IN6ADDR_ANY_INIT { { \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00 \ -} } - -#define IN6ADDR_LOOPBACK_INIT { { \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x00, \ - 0x00, 0x00, 0x00, 0x01 \ -} } - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_poll.h b/lib/libc/include/wasm-wasi-musl/__header_poll.h deleted file mode 100644 index 23b36f2f20b5f0e038d4d57502aa173968401014..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_poll.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef __wasilibc___header_poll_h -#define __wasilibc___header_poll_h - -#include <__struct_pollfd.h> -#include <__typedef_nfds_t.h> - -#define POLLRDNORM 0x1 -#define POLLWRNORM 0x2 - -#define POLLIN POLLRDNORM -#define POLLOUT POLLWRNORM - -#define POLLERR 0x1000 -#define POLLHUP 0x2000 -#define POLLNVAL 0x4000 - -#ifdef __cplusplus -extern "C" { -#endif - -int poll(struct pollfd[], nfds_t, int); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_stdlib.h b/lib/libc/include/wasm-wasi-musl/__header_stdlib.h deleted file mode 100644 index a6c49a53170d92fbadabe94fc3cd2870345ddb32..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_stdlib.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __wasilibc___header_stdlib_h -#define __wasilibc___header_stdlib_h - -#define __need_size_t -#include - -#include <__functions_malloc.h> - -#ifdef __cplusplus -extern "C" { -#endif - -void abort(void) __attribute__((__noreturn__)); -void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); -void _Exit(int) __attribute__((__noreturn__)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_string.h b/lib/libc/include/wasm-wasi-musl/__header_string.h deleted file mode 100644 index eb98a8a2b7b999790c374dde922ab0c7fd78b3ab..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_string.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef __wasilibc___header_string_h -#define __wasilibc___header_string_h - -#define __need_size_t -#define __need_NULL -#include - -#include <__functions_memcpy.h> - -#ifdef __cplusplus -extern "C" { -#endif - -size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); -char *strdup(const char *) __attribute__((__nothrow__, __nonnull__(1))); -int strcmp(const char *, const char *) __attribute__((__nothrow__, __pure__, __nonnull__(1, 2))); -void *memchr(const void *, int, size_t) __attribute__((__nothrow__, __pure__, __nonnull__(1))); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_sys_ioctl.h b/lib/libc/include/wasm-wasi-musl/__header_sys_ioctl.h deleted file mode 100644 index f2cf4ee73da0ec186ead8fd2ffb5721c8c972eea..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_sys_ioctl.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef __wasilibc___header_sys_ioctl_h -#define __wasilibc___header_sys_ioctl_h - -#define FIONREAD 1 -#define FIONBIO 2 - -#ifdef __cplusplus -extern "C" { -#endif - -int ioctl(int, int, ...); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_sys_resource.h b/lib/libc/include/wasm-wasi-musl/__header_sys_resource.h deleted file mode 100644 index bae9d5aaca09cd67619f1f16452e3fa61127748c..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_sys_resource.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __wasilibc___header_sys_resource_h -#define __wasilibc___header_sys_resource_h - -#include <__struct_rusage.h> - -#define RUSAGE_SELF 1 -#define RUSAGE_CHILDREN 2 - -#ifdef __cplusplus -extern "C" { -#endif - -int getrusage(int who, struct rusage *usage); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_sys_socket.h b/lib/libc/include/wasm-wasi-musl/__header_sys_socket.h deleted file mode 100644 index fa98ccac2943ac55ff6a1560552da38f674b4c45..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_sys_socket.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __wasilibc___header_sys_socket_h -#define __wasilibc___header_sys_socket_h - -#include <__wasi_snapshot.h> -#include <__struct_msghdr.h> -#include <__struct_sockaddr.h> -#include <__struct_sockaddr_storage.h> - -#include - -#define SHUT_RD __WASI_SDFLAGS_RD -#define SHUT_WR __WASI_SDFLAGS_WR -#define SHUT_RDWR (SHUT_RD | SHUT_WR) - -#ifdef __wasilibc_use_wasip2 -#define MSG_DONTWAIT 0x0040 -#define MSG_NOSIGNAL 0x4000 -#define MSG_PEEK 0x0002 -#define MSG_WAITALL 0x0100 -#define MSG_TRUNC 0x0020 - -#define SOL_IP 0 -#define SOL_TCP 6 -#define SOL_UDP 17 -#define SOL_IPV6 41 - -#define SOMAXCONN 128 - -#define SO_REUSEADDR 2 -#define SO_ERROR 4 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_ACCEPTCONN 30 -#define SO_PROTOCOL 38 -#define SO_DOMAIN 39 - -#if __LONG_MAX == 0x7fffffff -#define SO_RCVTIMEO 66 -#define SO_SNDTIMEO 67 -#else -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -#endif - -#else // __wasilibc_use_wasip2 -#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK -#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL -#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_NONBLOCK (0x00004000) -#define SOCK_CLOEXEC (0x00002000) - -#define SOL_SOCKET 0x7fffffff - -#define SO_TYPE 3 - -#define PF_UNSPEC 0 -#define PF_INET 1 -#define PF_INET6 2 - -#define AF_UNSPEC PF_UNSPEC -#define AF_INET PF_INET -#define AF_INET6 PF_INET6 -#define AF_UNIX 3 - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_sys_stat.h b/lib/libc/include/wasm-wasi-musl/__header_sys_stat.h deleted file mode 100644 index f965cf3d33a2ab09d96e186cc6279473035de7c3..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_sys_stat.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __wasilibc___header_sys_stat_h -#define __wasilibc___header_sys_stat_h - -#include <__struct_stat.h> - -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - -#include <__mode_t.h> - -#define UTIME_NOW (-1) -#define UTIME_OMIT (-2) - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_time.h b/lib/libc/include/wasm-wasi-musl/__header_time.h deleted file mode 100644 index 2a2ff91d8a94ee1ff1f96d1c8ebf16455dfd1828..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_time.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef __wasilibc___header_time_h -#define __wasilibc___header_time_h - -#define __need_size_t -#define __need_NULL -#include - -#include <__typedef_time_t.h> -#include <__struct_timespec.h> -#include <__struct_tm.h> -#include <__typedef_clockid_t.h> - -#include - -#define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME - -extern const struct __clockid _CLOCK_MONOTONIC; -#define CLOCK_MONOTONIC (&_CLOCK_MONOTONIC) -extern const struct __clockid _CLOCK_REALTIME; -#define CLOCK_REALTIME (&_CLOCK_REALTIME) - -/* - * TIME_UTC is the only standardized time base value. - */ -#define TIME_UTC 1 - -/* - * Note that XSI specifies CLOCKS_PER_SEC to be 1000000, rather than - * 1000000000; the clock API is providing more precision than XSI specifies. - */ -#define CLOCKS_PER_SEC ((clock_t)1000000000) - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__header_unistd.h b/lib/libc/include/wasm-wasi-musl/__header_unistd.h deleted file mode 100644 index 6b80d63788317fb9d73573cf4b17fe909f937e00..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__header_unistd.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef __wasilibc___header_unistd_h -#define __wasilibc___header_unistd_h - -struct stat; - -#include <__seek.h> - -#define F_OK (0) -#define X_OK (1) -#define W_OK (2) -#define R_OK (4) - -#ifdef __cplusplus -extern "C" { -#endif - -int close(int fd); -int faccessat(int, const char *, int, int); -int fstatat(int, const char *__restrict, struct stat *__restrict, int); -int renameat(int, const char *, int, const char *); -int openat(int, const char *, int, ...); -void *sbrk(intptr_t increment); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__macro_FD_SETSIZE.h b/lib/libc/include/wasm-wasi-musl/__macro_FD_SETSIZE.h deleted file mode 100644 index bb88e45c426cdc85dd591cd725e9428461cf3711..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__macro_FD_SETSIZE.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___macro_FD_SETSIZE_h -#define __wasilibc___macro_FD_SETSIZE_h - -#define FD_SETSIZE 1024 - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__macro_PAGESIZE.h b/lib/libc/include/wasm-wasi-musl/__macro_PAGESIZE.h deleted file mode 100644 index fbeff8d0020a187bb540e4e0eb6ed5e07e66072f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__macro_PAGESIZE.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef __wasilibc___macro_PAGESIZE_h -#define __wasilibc___macro_PAGESIZE_h - -/* - * Without custom-page-sizes proposal, the page size in WebAssembly - * is fixed at 64 KiB. - * - * The LLVM versions with a support of custom-page-sizes proposal - * provides __wasm_first_page_end global to allow page-size-agnostic - * objects. - * - * If this ever needs to be a value outside the range of an `int`, the - * `getpagesize` function which returns this value will need special - * consideration. POSIX has deprecated `getpagesize` in favor of - * `sysconf(_SC_PAGESIZE)` which does not have this problem. - */ -#if __clang_major__ >= 22 -extern char __wasm_first_page_end; -#define PAGESIZE ((unsigned long)&__wasm_first_page_end) -#else -#define PAGESIZE (0x10000) -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__mode_t.h b/lib/libc/include/wasm-wasi-musl/__mode_t.h deleted file mode 100644 index d2dbe04715337cbb586ff3818fc03444326245c4..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__mode_t.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef __wasilibc___mode_t_h -#define __wasilibc___mode_t_h - -#define S_IFMT \ - (S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK) -#define S_IFBLK (0x6000) -#define S_IFCHR (0x2000) -#define S_IFDIR (0x4000) -#define S_IFLNK (0xa000) -#define S_IFREG (0x8000) -#define S_IFSOCK (0xc000) -#define S_IFIFO (0x1000) - -#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) -#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) -#define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) -#define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) -#define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) -#define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) -#define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) - -#define S_IXOTH (0x1) -#define S_IWOTH (0x2) -#define S_IROTH (0x4) -#define S_IRWXO (S_IXOTH | S_IWOTH | S_IROTH) -#define S_IXGRP (0x8) -#define S_IWGRP (0x10) -#define S_IRGRP (0x20) -#define S_IRWXG (S_IXGRP | S_IWGRP | S_IRGRP) -#define S_IXUSR (0x40) -#define S_IWUSR (0x80) -#define S_IRUSR (0x100) -#define S_IRWXU (S_IXUSR | S_IWUSR | S_IRUSR) -#define S_ISVTX (0x200) -#define S_ISGID (0x400) -#define S_ISUID (0x800) - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__seek.h b/lib/libc/include/wasm-wasi-musl/__seek.h deleted file mode 100644 index 8824adb1415b05f43a8365bf321d68ad3a2743b2..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__seek.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasilibc___seek_h -#define __wasilibc___seek_h - -#include - -#define SEEK_CUR __WASI_WHENCE_CUR -#define SEEK_END __WASI_WHENCE_END -#define SEEK_SET __WASI_WHENCE_SET - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_dirent.h b/lib/libc/include/wasm-wasi-musl/__struct_dirent.h deleted file mode 100644 index 9d2ece81dd1e62c7cd0932a650c2fdf154925348..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_dirent.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __wasilibc___struct_dirent_h -#define __wasilibc___struct_dirent_h - -#include <__typedef_ino_t.h> - -#define _DIRENT_HAVE_D_TYPE - -struct dirent { - ino_t d_ino; - unsigned char d_type; - char d_name[]; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_in6_addr.h b/lib/libc/include/wasm-wasi-musl/__struct_in6_addr.h deleted file mode 100644 index cf2fafeb40bf0928dfdaecd5c71c2b24797d52c9..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_in6_addr.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __wasilibc___struct_in6_addr_h -#define __wasilibc___struct_in6_addr_h - -struct in6_addr { - _Alignas(int32_t) unsigned char s6_addr[16]; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_in_addr.h b/lib/libc/include/wasm-wasi-musl/__struct_in_addr.h deleted file mode 100644 index 881ffa6d81542b1855eebf1eedd317bbf38effb8..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_in_addr.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasilibc___struct_in_addr_h -#define __wasilibc___struct_in_addr_h - -#include <__typedef_in_addr_t.h> - -struct in_addr { - in_addr_t s_addr; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_iovec.h b/lib/libc/include/wasm-wasi-musl/__struct_iovec.h deleted file mode 100644 index da3e1c7d94ac419f944d76748fd4209d5e84095b..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_iovec.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __wasilibc___struct_iovec_h -#define __wasilibc___struct_iovec_h - -#define __need_size_t -#include - -struct iovec { - void *iov_base; - size_t iov_len; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_msghdr.h b/lib/libc/include/wasm-wasi-musl/__struct_msghdr.h deleted file mode 100644 index 0c0877dc132f75bf341afa4ddf20ba7d069a087a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_msghdr.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __wasilibc___struct_msghdr_h -#define __wasilibc___struct_msghdr_h - -#include <__typedef_socklen_t.h> - -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; - int msg_iovlen; - void *msg_control; - socklen_t msg_controllen; - int msg_flags; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_pollfd.h b/lib/libc/include/wasm-wasi-musl/__struct_pollfd.h deleted file mode 100644 index 45874c59106bab74b8a4bdd8f739e59225c5831d..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_pollfd.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasilibc___struct_pollfd_h -#define __wasilibc___struct_pollfd_h - -struct pollfd { - int fd; - short events; - short revents; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_rusage.h b/lib/libc/include/wasm-wasi-musl/__struct_rusage.h deleted file mode 100644 index 69fe2fef3481a6a11154bdc7dd1ae9dba476295a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_rusage.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __wasilibc___struct_rusage_h -#define __wasilibc___struct_rusage_h - -#include <__struct_timeval.h> - -/* TODO: Add more features here. */ -struct rusage { - struct timeval ru_utime; - struct timeval ru_stime; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr.h b/lib/libc/include/wasm-wasi-musl/__struct_sockaddr.h deleted file mode 100644 index 2e14d95258f52dc281cdffe667910eda9a7f2fbc..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __wasilibc___struct_sockaddr_h -#define __wasilibc___struct_sockaddr_h - -#include <__typedef_sa_family_t.h> - -struct sockaddr { - __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sa_family; - char sa_data[0]; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h b/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h deleted file mode 100644 index 5d4ce51becc4557a65db04ab15dcad95f5233053..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __wasilibc___struct_sockaddr_in_h -#define __wasilibc___struct_sockaddr_in_h - -#include <__typedef_sa_family_t.h> -#include <__typedef_in_port_t.h> -#include <__struct_in_addr.h> - -struct sockaddr_in { - __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h b/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h deleted file mode 100644 index 98703dcbeb65467429c2f77c1bdffbe888d6a22a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef __wasilibc___struct_sockaddr_in6_h -#define __wasilibc___struct_sockaddr_in6_h - -#include <__typedef_sa_family_t.h> -#include <__typedef_in_port_t.h> -#include <__struct_in6_addr.h> - -struct sockaddr_in6 { - __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin6_family; - in_port_t sin6_port; - unsigned sin6_flowinfo; - struct in6_addr sin6_addr; - unsigned sin6_scope_id; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h b/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h deleted file mode 100644 index b4ebad2fed1e4a543b2733d87ecd6cdc9c991ca8..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __wasilibc___struct_sockaddr_storage_h -#define __wasilibc___struct_sockaddr_storage_h - -#include <__typedef_sa_family_t.h> - -struct sockaddr_storage { - __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t ss_family; - char __ss_data[32]; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_un.h b/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_un.h deleted file mode 100644 index 637119495a23b7fb132b000c487fb9435bbb97fd..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_sockaddr_un.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef __wasilibc___struct_sockaddr_un_h -#define __wasilibc___struct_sockaddr_un_h - -#include <__typedef_sa_family_t.h> - -struct sockaddr_un { - __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sun_family; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_stat.h b/lib/libc/include/wasm-wasi-musl/__struct_stat.h deleted file mode 100644 index 5e345da127227ec25e547afd18a7b74d3287d75f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_stat.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef __wasilibc___struct_stat_h -#define __wasilibc___struct_stat_h - -#include <__typedef_dev_t.h> -#include <__typedef_ino_t.h> -#include <__typedef_nlink_t.h> -#include <__typedef_mode_t.h> -#include <__typedef_uid_t.h> -#include <__typedef_gid_t.h> -#include <__typedef_off_t.h> -#include <__typedef_blksize_t.h> -#include <__typedef_blkcnt_t.h> -#include <__struct_timespec.h> - -struct stat { - dev_t st_dev; - ino_t st_ino; - nlink_t st_nlink; - - mode_t st_mode; - uid_t st_uid; - gid_t st_gid; - unsigned int __pad0; - dev_t st_rdev; - off_t st_size; - blksize_t st_blksize; - blkcnt_t st_blocks; - - struct timespec st_atim; - struct timespec st_mtim; - struct timespec st_ctim; - long long __reserved[3]; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_timespec.h b/lib/libc/include/wasm-wasi-musl/__struct_timespec.h deleted file mode 100644 index 10d83f990f9348c5477788864bc597cc87c0ca99..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_timespec.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef __wasilibc___struct_timespec_h -#define __wasilibc___struct_timespec_h - -#include <__typedef_time_t.h> - -/* As specified in POSIX. */ -struct timespec { - time_t tv_sec; - long tv_nsec; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_timeval.h b/lib/libc/include/wasm-wasi-musl/__struct_timeval.h deleted file mode 100644 index b09f1a9da78cd679747da0fac239f0d4aa50358b..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_timeval.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __wasilibc___struct_timeval_h -#define __wasilibc___struct_timeval_h - -#include <__typedef_time_t.h> -#include <__typedef_suseconds_t.h> - -/* As specified in POSIX. */ -struct timeval { - time_t tv_sec; - suseconds_t tv_usec; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_tm.h b/lib/libc/include/wasm-wasi-musl/__struct_tm.h deleted file mode 100644 index 3c83dc5b28762aa1b3837228e18e1df151dee896..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_tm.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef __wasilibc___struct_tm_h -#define __wasilibc___struct_tm_h - -struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - int __tm_gmtoff; - const char *__tm_zone; - int __tm_nsec; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__struct_tms.h b/lib/libc/include/wasm-wasi-musl/__struct_tms.h deleted file mode 100644 index 9914097b2a6b3d02b96f2e798535dd6e91150e77..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__struct_tms.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef __wasilibc___struct_tms_h -#define __wasilibc___struct_tms_h - -#include <__typedef_clock_t.h> - -struct tms { - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_DIR.h b/lib/libc/include/wasm-wasi-musl/__typedef_DIR.h deleted file mode 100644 index f07cfc18f7ff7e37aff788a3fa0e7c7c03e07242..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_DIR.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_DIR_h -#define __wasilibc___typedef_DIR_h - -typedef struct _DIR DIR; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_blkcnt_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_blkcnt_t.h deleted file mode 100644 index e8d7b3dced6278f6bc582e589c07bf757133ecd2..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_blkcnt_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_blkcnt_t_h -#define __wasilibc___typedef_blkcnt_t_h - -/* Define these as 64-bit signed integers to support files larger than 2 GiB. */ -typedef long long blkcnt_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_blksize_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_blksize_t.h deleted file mode 100644 index 8816e0a2e7fc1c127df76862fcb6e9537d3530c0..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_blksize_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_blksize_t_h -#define __wasilibc___typedef_blksize_t_h - -typedef long blksize_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_clock_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_clock_t.h deleted file mode 100644 index 68cb58849e06b2a6a3628ff159d0686dde34c941..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_clock_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_clock_t_h -#define __wasilibc___typedef_clock_t_h - -/* Define this as a 64-bit signed integer to avoid wraparounds. */ -typedef long long clock_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_clockid_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_clockid_t.h deleted file mode 100644 index 6de424446271f0e74a5c6f32493f26e5b090e99e..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_clockid_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_clockid_t_h -#define __wasilibc___typedef_clockid_t_h - -typedef const struct __clockid *clockid_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_dev_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_dev_t.h deleted file mode 100644 index 353e94f553539b49f8e018127a91587123cbbc57..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_dev_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_dev_t_h -#define __wasilibc___typedef_dev_t_h - -/* Define these as 64-bit integers to support billions of devices. */ -typedef unsigned long long dev_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_fd_set.h b/lib/libc/include/wasm-wasi-musl/__typedef_fd_set.h deleted file mode 100644 index 35ea958fc9d2f2a0744ce0f68e28a0470b95b8ff..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_fd_set.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __wasilibc___typedef_fd_set_h -#define __wasilibc___typedef_fd_set_h - -#define __need_size_t -#include - -#include <__macro_FD_SETSIZE.h> - -typedef struct { - size_t __nfds; - int __fds[FD_SETSIZE]; -} fd_set; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_gid_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_gid_t.h deleted file mode 100644 index 6eb82f274b7f6c6ef16728ac015d395e56ff2609..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_gid_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_gid_t_h -#define __wasilibc___typedef_gid_t_h - -typedef unsigned gid_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_in_addr_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_in_addr_t.h deleted file mode 100644 index 68ab51220363092a3c832e2e18bb4e5a7e085eac..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_in_addr_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_in_addr_t_h -#define __wasilibc___typedef_in_addr_t_h - -typedef unsigned in_addr_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_in_port_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_in_port_t.h deleted file mode 100644 index 890a2c878ea5666d92a7bf0ef788025e533d528c..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_in_port_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_in_port_t_h -#define __wasilibc___typedef_in_port_t_h - -typedef unsigned short in_port_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_ino_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_ino_t.h deleted file mode 100644 index f3e11e43e189debee999fcbf9660c606fd614152..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_ino_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_ino_t_h -#define __wasilibc___typedef_ino_t_h - -/* Define these as 64-bit integers to support billions of inodes. */ -typedef unsigned long long ino_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_mode_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_mode_t.h deleted file mode 100644 index 51b927d9dafc80f3c1ce8b1f549599dfcaaf4d0b..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_mode_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_mode_t_h -#define __wasilibc___typedef_mode_t_h - -typedef unsigned mode_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_nfds_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_nfds_t.h deleted file mode 100644 index ea0a93e76c6e5a4841f2fbba3e66a9cd3d8a539d..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_nfds_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_nfds_t_h -#define __wasilibc___typedef_nfds_t_h - -typedef unsigned long nfds_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_nlink_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_nlink_t.h deleted file mode 100644 index ae34c79f1bbbb9aefea42f513a2a26227c1b349d..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_nlink_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_nlink_t_h -#define __wasilibc___typedef_nlink_t_h - -/* Define these as 64-bit unsigned integers to support billions of links. */ -typedef unsigned long long nlink_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_off_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_off_t.h deleted file mode 100644 index 115ffdd955e1cabb51079db8b6b3e028fdddf590..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_off_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_off_t_h -#define __wasilibc___typedef_off_t_h - -/* Define these as 64-bit signed integers to support files larger than 2 GiB. */ -typedef long long off_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_sa_family_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_sa_family_t.h deleted file mode 100644 index 0ad18c94199cc000cd1a7c839fada44d88cca997..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_sa_family_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_sa_family_t_h -#define __wasilibc___typedef_sa_family_t_h - -typedef unsigned short sa_family_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_sigset_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_sigset_t.h deleted file mode 100644 index f7e486751295299125c5fe520bf0e0789806cc94..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_sigset_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_sigset_t_h -#define __wasilibc___typedef_sigset_t_h - -/* TODO: This is just a placeholder for now. Keep this in sync with musl. */ -typedef unsigned char sigset_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_socklen_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_socklen_t.h deleted file mode 100644 index bd68e55529c3ab4432f8b528ccc140f4e2ed1f80..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_socklen_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_socklen_t_h -#define __wasilibc___typedef_socklen_t_h - -typedef unsigned socklen_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_ssize_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_ssize_t.h deleted file mode 100644 index 25dc15a838fc52ecba17c5f6c7f7b31140bdb02a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_ssize_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_ssize_t_h -#define __wasilibc___typedef_ssize_t_h - -/* This is defined to be the same size as size_t. */ -typedef long ssize_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_suseconds_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_suseconds_t.h deleted file mode 100644 index 92667e2aa6cf6265b10373c0abecf9bbf268833f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_suseconds_t.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef __wasilibc___typedef_suseconds_t_h -#define __wasilibc___typedef_suseconds_t_h - -/* Define this to be 64-bit as its main use is in struct timeval where the - extra space would otherwise be padding. */ -typedef long long suseconds_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_time_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_time_t.h deleted file mode 100644 index 6ee0f86bf89e7ac6fd6798bc8736c3d57f6bc226..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_time_t.h +++ /dev/null @@ -1,7 +0,0 @@ -#ifndef __wasilibc___typedef_time_t_h -#define __wasilibc___typedef_time_t_h - -/* Define this as a 64-bit signed integer to avoid the 2038 bug. */ -typedef long long time_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__typedef_uid_t.h b/lib/libc/include/wasm-wasi-musl/__typedef_uid_t.h deleted file mode 100644 index c9da30036c94a3852bbeaf7ed17504924e41abae..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__typedef_uid_t.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef __wasilibc___typedef_uid_t_h -#define __wasilibc___typedef_uid_t_h - -typedef unsigned uid_t; - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/__wasi_snapshot.h b/lib/libc/include/wasm-wasi-musl/__wasi_snapshot.h deleted file mode 100644 index 9a100780597708f3dfdff766e0a05681938d2124..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/__wasi_snapshot.h +++ /dev/null @@ -1,5 +0,0 @@ -/* This file is (practically) empty by default. The Makefile will replace it - with a non-empty version that defines `__wasilibc_use_wasip2` if targeting - `wasm32-wasip2`. - */ - diff --git a/lib/libc/include/wasm-wasi-musl/arpa/inet.h b/lib/libc/include/wasm-wasi-musl/arpa/inet.h deleted file mode 100644 index f657c30ec80361d1c98e1ff29dc2d2e69b92e779..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/arpa/inet.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _ARPA_INET_H -#define _ARPA_INET_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_addr */ -in_addr_t inet_addr (const char *); -in_addr_t inet_network (const char *); -char *inet_ntoa (struct in_addr); -#endif -int inet_pton (int, const char *__restrict, void *__restrict); -const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); - -int inet_aton (const char *, struct in_addr *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_makeaddr */ -struct in_addr inet_makeaddr(in_addr_t, in_addr_t); -in_addr_t inet_lnaof(struct in_addr); -in_addr_t inet_netof(struct in_addr); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/arpa/nameser_compat.h b/lib/libc/include/wasm-wasi-musl/arpa/nameser_compat.h deleted file mode 100644 index 3aac25c98b50ab58abab357b91d43e916483daf7..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/arpa/nameser_compat.h +++ /dev/null @@ -1,2 +0,0 @@ -#include - diff --git a/lib/libc/include/wasm-wasi-musl/arpa/tftp.h b/lib/libc/include/wasm-wasi-musl/arpa/tftp.h deleted file mode 100644 index 799c54f2217e0671ea1c676fbfe50ed6304d7dbb..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/arpa/tftp.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef _ARPA_TFTP_H -#define _ARPA_TFTP_H -#define SEGSIZE 512 -#define RRQ 01 -#define WRQ 02 -#define DATA 03 -#define ACK 04 -#define ERROR 05 -struct tftphdr { - short th_opcode; - union { - unsigned short tu_block; - short tu_code; - char tu_stuff[1]; - } th_u; - char th_data[1]; -}; -#define th_block th_u.tu_block -#define th_code th_u.tu_code -#define th_stuff th_u.tu_stuff -#define th_msg th_data -#define EUNDEF 0 -#define ENOTFOUND 1 -#define EACCESS 2 -#define ENOSPACE 3 -#define EBADOP 4 -#define EBADID 5 -#define EEXISTS 6 -#define ENOUSER 7 -#endif - diff --git a/lib/libc/include/wasm-wasi-musl/bits/alltypes.h b/lib/libc/include/wasm-wasi-musl/bits/alltypes.h deleted file mode 100644 index 4e3a97effe592fad2e4ff7e34603752cd820e5c8..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/alltypes.h +++ /dev/null @@ -1,460 +0,0 @@ -#define _Addr long -#define _Int64 long long -#define _Reg long long - -#define __BYTE_ORDER __BYTE_ORDER__ - -#define __LONG_MAX __LONG_MAX__ - -/* - * Rather than define everything ourselves here in the musl layer, for - * WASI, reference the definitions in the lower layers. - */ - -#if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) -#define __need_wchar_t -#include -#define __DEFINED_wchar_t -#endif - -#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) -#define __need_wint_t -#include -#define __DEFINED_wint_t -#endif - -#if defined(__NEED_float_t) && !defined(__DEFINED_float_t) -typedef float float_t; -#define __DEFINED_float_t -#endif - -#if defined(__NEED_double_t) && !defined(__DEFINED_double_t) -typedef double double_t; -#define __DEFINED_double_t -#endif - - -#if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) -#define __need_max_align_t -#include -#define __DEFINED_max_align_t -#endif - -#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) -#include <__typedef_time_t.h> -#define __DEFINED_time_t -#endif - -#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) -#include <__typedef_suseconds_t.h> -#define __DEFINED_suseconds_t -#endif - -#if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) -#include <__typedef_clockid_t.h> -#define __DEFINED_clockid_t -#endif - -#if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) -#include <__typedef_sigset_t.h> -#define __DEFINED_sigset_t -#endif - -#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) -#include <__typedef_clock_t.h> -#define __DEFINED_clock_t -#endif -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __USE_TIME_BITS64 1 - -#if defined(__NEED_size_t) && !defined(__DEFINED_size_t) -typedef unsigned _Addr size_t; -#define __DEFINED_size_t -#endif - -#if defined(__NEED_uintptr_t) && !defined(__DEFINED_uintptr_t) -typedef unsigned _Addr uintptr_t; -#define __DEFINED_uintptr_t -#endif - -#if defined(__NEED_ptrdiff_t) && !defined(__DEFINED_ptrdiff_t) -typedef _Addr ptrdiff_t; -#define __DEFINED_ptrdiff_t -#endif - -#if defined(__NEED_ssize_t) && !defined(__DEFINED_ssize_t) -typedef _Addr ssize_t; -#define __DEFINED_ssize_t -#endif - -#if defined(__NEED_intptr_t) && !defined(__DEFINED_intptr_t) -typedef _Addr intptr_t; -#define __DEFINED_intptr_t -#endif - -#if defined(__NEED_regoff_t) && !defined(__DEFINED_regoff_t) -typedef _Addr regoff_t; -#define __DEFINED_regoff_t -#endif - -#if defined(__NEED_register_t) && !defined(__DEFINED_register_t) -typedef _Reg register_t; -#define __DEFINED_register_t -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) -typedef _Int64 time_t; -#define __DEFINED_time_t -#endif - -#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) -typedef _Int64 suseconds_t; -#define __DEFINED_suseconds_t -#endif - -#else -#if defined(__NEED_time_t) && !defined(__DEFINED_time_t) -#include <__typedef_time_t.h> -#define __DEFINED_time_t -#endif - -#if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) -#include <__typedef_suseconds_t.h> -#define __DEFINED_suseconds_t -#endif -#endif - -#if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) -typedef signed char int8_t; -#define __DEFINED_int8_t -#endif - -#if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) -typedef signed short int16_t; -#define __DEFINED_int16_t -#endif - -#if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) -typedef signed int int32_t; -#define __DEFINED_int32_t -#endif - -#if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) -typedef signed _Int64 int64_t; -#define __DEFINED_int64_t -#endif - -#if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) -typedef signed _Int64 intmax_t; -#define __DEFINED_intmax_t -#endif - -#if defined(__NEED_uint8_t) && !defined(__DEFINED_uint8_t) -typedef unsigned char uint8_t; -#define __DEFINED_uint8_t -#endif - -#if defined(__NEED_uint16_t) && !defined(__DEFINED_uint16_t) -typedef unsigned short uint16_t; -#define __DEFINED_uint16_t -#endif - -#if defined(__NEED_uint32_t) && !defined(__DEFINED_uint32_t) -typedef unsigned int uint32_t; -#define __DEFINED_uint32_t -#endif - -#if defined(__NEED_uint64_t) && !defined(__DEFINED_uint64_t) -typedef unsigned _Int64 uint64_t; -#define __DEFINED_uint64_t -#endif - -#if defined(__NEED_u_int64_t) && !defined(__DEFINED_u_int64_t) -typedef unsigned _Int64 u_int64_t; -#define __DEFINED_u_int64_t -#endif - -#if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t) -typedef unsigned _Int64 uintmax_t; -#define __DEFINED_uintmax_t -#endif - - -#if defined(__NEED_mode_t) && !defined(__DEFINED_mode_t) -typedef unsigned mode_t; -#define __DEFINED_mode_t -#endif - -#if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) -typedef unsigned _Reg nlink_t; -#define __DEFINED_nlink_t -#endif - -#if defined(__NEED_off_t) && !defined(__DEFINED_off_t) -typedef _Int64 off_t; -#define __DEFINED_off_t -#endif - -#if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t) -typedef unsigned _Int64 ino_t; -#define __DEFINED_ino_t -#endif - -#if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) -typedef unsigned _Int64 dev_t; -#define __DEFINED_dev_t -#endif - -#if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) -typedef long blksize_t; -#define __DEFINED_blksize_t -#endif - -#if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) -typedef _Int64 blkcnt_t; -#define __DEFINED_blkcnt_t -#endif - -#if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) -typedef unsigned _Int64 fsblkcnt_t; -#define __DEFINED_fsblkcnt_t -#endif - -#if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) -typedef unsigned _Int64 fsfilcnt_t; -#define __DEFINED_fsfilcnt_t -#endif - - -#if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) -typedef unsigned wint_t; -#define __DEFINED_wint_t -#endif - -#if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) -typedef unsigned long wctype_t; -#define __DEFINED_wctype_t -#endif - - -#if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t) -typedef void * timer_t; -#define __DEFINED_timer_t -#endif - -#if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) -typedef int clockid_t; -#define __DEFINED_clockid_t -#endif - -#if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) -typedef long clock_t; -#define __DEFINED_clock_t -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) -struct timeval { time_t tv_sec; suseconds_t tv_usec; }; -#define __DEFINED_struct_timeval -#endif - -#if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) -struct timespec { time_t tv_sec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER==4321); long tv_nsec; int :8*(sizeof(time_t)-sizeof(long))*(__BYTE_ORDER!=4321); }; -#define __DEFINED_struct_timespec -#endif - -#else -#include <__struct_timeval.h> -#include <__struct_timespec.h> -#endif - -#if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t) -typedef int pid_t; -#define __DEFINED_pid_t -#endif - -#if defined(__NEED_id_t) && !defined(__DEFINED_id_t) -typedef unsigned id_t; -#define __DEFINED_id_t -#endif - -#if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t) -typedef unsigned uid_t; -#define __DEFINED_uid_t -#endif - -#if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t) -typedef unsigned gid_t; -#define __DEFINED_gid_t -#endif - -#if defined(__NEED_key_t) && !defined(__DEFINED_key_t) -typedef int key_t; -#define __DEFINED_key_t -#endif - -#if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t) -typedef unsigned useconds_t; -#define __DEFINED_useconds_t -#endif - - -#ifdef __cplusplus -#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) -typedef unsigned long pthread_t; -#define __DEFINED_pthread_t -#endif - -#else -#if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) -typedef struct __pthread * pthread_t; -#define __DEFINED_pthread_t -#endif - -#endif -#if defined(__NEED_pthread_once_t) && !defined(__DEFINED_pthread_once_t) -typedef int pthread_once_t; -#define __DEFINED_pthread_once_t -#endif - -#if defined(__NEED_pthread_key_t) && !defined(__DEFINED_pthread_key_t) -typedef unsigned pthread_key_t; -#define __DEFINED_pthread_key_t -#endif - -#if defined(__NEED_pthread_spinlock_t) && !defined(__DEFINED_pthread_spinlock_t) -typedef int pthread_spinlock_t; -#define __DEFINED_pthread_spinlock_t -#endif - -#if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t) -typedef struct { unsigned __attr; } pthread_mutexattr_t; -#define __DEFINED_pthread_mutexattr_t -#endif - -#if defined(__NEED_pthread_condattr_t) && !defined(__DEFINED_pthread_condattr_t) -typedef struct { unsigned __attr; } pthread_condattr_t; -#define __DEFINED_pthread_condattr_t -#endif - -#if defined(__NEED_pthread_barrierattr_t) && !defined(__DEFINED_pthread_barrierattr_t) -typedef struct { unsigned __attr; } pthread_barrierattr_t; -#define __DEFINED_pthread_barrierattr_t -#endif - -#if defined(__NEED_pthread_rwlockattr_t) && !defined(__DEFINED_pthread_rwlockattr_t) -typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; -#define __DEFINED_pthread_rwlockattr_t -#endif - - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#if defined(__NEED_struct__IO_FILE) && !defined(__DEFINED_struct__IO_FILE) -struct _IO_FILE { char __x; }; -#define __DEFINED_struct__IO_FILE -#endif - -#endif -#if defined(__NEED_FILE) && !defined(__DEFINED_FILE) -typedef struct _IO_FILE FILE; -#define __DEFINED_FILE -#endif - - -#if defined(__NEED_va_list) && !defined(__DEFINED_va_list) -typedef __builtin_va_list va_list; -#define __DEFINED_va_list -#endif - -#if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) -typedef __builtin_va_list __isoc_va_list; -#define __DEFINED___isoc_va_list -#endif - - -#if defined(__NEED_mbstate_t) && !defined(__DEFINED_mbstate_t) -typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; -#define __DEFINED_mbstate_t -#endif - - -#if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t) -typedef struct __locale_struct * locale_t; -#define __DEFINED_locale_t -#endif - - -#if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) -typedef struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t; -#define __DEFINED_sigset_t -#endif - - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec) -struct iovec { void *iov_base; size_t iov_len; }; -#define __DEFINED_struct_iovec -#endif - -#else -#include <__struct_iovec.h> -#endif - -#if defined(__NEED_struct_winsize) && !defined(__DEFINED_struct_winsize) -struct winsize { unsigned short ws_row, ws_col, ws_xpixel, ws_ypixel; }; -#define __DEFINED_struct_winsize -#endif - - -#if defined(__NEED_socklen_t) && !defined(__DEFINED_socklen_t) -typedef unsigned socklen_t; -#define __DEFINED_socklen_t -#endif - -#if defined(__NEED_sa_family_t) && !defined(__DEFINED_sa_family_t) -typedef unsigned short sa_family_t; -#define __DEFINED_sa_family_t -#endif - - -#if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) -typedef struct { union { int __i[sizeof(long)==8?14:9]; volatile int __vi[sizeof(long)==8?14:9]; unsigned long __s[sizeof(long)==8?7:9]; } __u; } pthread_attr_t; -#define __DEFINED_pthread_attr_t -#endif - -#if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) -typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } pthread_mutex_t; -#define __DEFINED_pthread_mutex_t -#endif - -#if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) -typedef struct { union { int __i[sizeof(long)==8?10:6]; volatile int __vi[sizeof(long)==8?10:6]; volatile void *volatile __p[sizeof(long)==8?5:6]; } __u; } mtx_t; -#define __DEFINED_mtx_t -#endif - -#if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) -typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } pthread_cond_t; -#define __DEFINED_pthread_cond_t -#endif - -#if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) -typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } cnd_t; -#define __DEFINED_cnd_t -#endif - -#if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) -typedef struct { union { int __i[sizeof(long)==8?14:8]; volatile int __vi[sizeof(long)==8?14:8]; void *__p[sizeof(long)==8?7:8]; } __u; } pthread_rwlock_t; -#define __DEFINED_pthread_rwlock_t -#endif - -#if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) -typedef struct { union { int __i[sizeof(long)==8?8:5]; volatile int __vi[sizeof(long)==8?8:5]; void *__p[sizeof(long)==8?4:5]; } __u; } pthread_barrier_t; -#define __DEFINED_pthread_barrier_t -#endif - - -#undef _Addr -#undef _Int64 -#undef _Reg diff --git a/lib/libc/include/wasm-wasi-musl/bits/dirent.h b/lib/libc/include/wasm-wasi-musl/bits/dirent.h deleted file mode 100644 index 55f2bc9d4ebea51424f9b89176dcad0ce8e4e97f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/dirent.h +++ /dev/null @@ -1 +0,0 @@ -#include <__struct_dirent.h> diff --git a/lib/libc/include/wasm-wasi-musl/bits/fcntl.h b/lib/libc/include/wasm-wasi-musl/bits/fcntl.h deleted file mode 100644 index a2f334161308bc5da472b7ff29ee63b3c4503c88..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/fcntl.h +++ /dev/null @@ -1 +0,0 @@ -/* Use the WASI libc fcntl implementation bits. */ diff --git a/lib/libc/include/wasm-wasi-musl/bits/fenv.h b/lib/libc/include/wasm-wasi-musl/bits/fenv.h deleted file mode 100644 index edbdea2a5efcda22054568550ef555acdf14cd35..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/fenv.h +++ /dev/null @@ -1,10 +0,0 @@ -#define FE_ALL_EXCEPT 0 -#define FE_TONEAREST 0 - -typedef unsigned long fexcept_t; - -typedef struct { - unsigned long __cw; -} fenv_t; - -#define FE_DFL_ENV ((const fenv_t *) -1) diff --git a/lib/libc/include/wasm-wasi-musl/bits/ioctl.h b/lib/libc/include/wasm-wasi-musl/bits/ioctl.h deleted file mode 100644 index b4bf7c71bdf2a82daba6382a279f07ac82e6101c..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/ioctl.h +++ /dev/null @@ -1 +0,0 @@ -/* Use the WASI libc ioctl implementation bits. */ diff --git a/lib/libc/include/wasm-wasi-musl/bits/limits.h b/lib/libc/include/wasm-wasi-musl/bits/limits.h deleted file mode 100644 index 801bc48fd16f2c8c7b1d6b3d43c2fa0200c93a9e..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/limits.h +++ /dev/null @@ -1 +0,0 @@ -#include <__macro_PAGESIZE.h> diff --git a/lib/libc/include/wasm-wasi-musl/bits/posix.h b/lib/libc/include/wasm-wasi-musl/bits/posix.h deleted file mode 100644 index 387a3e4791553e568821216b3d49e3b7c9d016fd..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_ILP32_OFFBIG (1) -#define _POSIX_V7_ILP32_OFFBIG (1) diff --git a/lib/libc/include/wasm-wasi-musl/bits/setjmp.h b/lib/libc/include/wasm-wasi-musl/bits/setjmp.h deleted file mode 100644 index 63973a8001168472c1acc8ba1df81f59e8f7b583..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long __jmp_buf[8]; diff --git a/lib/libc/include/wasm-wasi-musl/bits/signal.h b/lib/libc/include/wasm-wasi-musl/bits/signal.h deleted file mode 100644 index 77e8d8c61e8c31a1104f12625ccf8b0ea17c4bf0..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/signal.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifdef _WASI_EMULATED_SIGNAL - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT SIGABRT -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS - -#define _NSIG 65 - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/bits/stat.h b/lib/libc/include/wasm-wasi-musl/bits/stat.h deleted file mode 100644 index 67a0e726ab0a799d0656402199b5d399d600c59e..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/stat.h +++ /dev/null @@ -1 +0,0 @@ -#include <__struct_stat.h> diff --git a/lib/libc/include/wasm-wasi-musl/bits/stdint.h b/lib/libc/include/wasm-wasi-musl/bits/stdint.h deleted file mode 100644 index 6e7c7705bf48a7d55e8841eab5adb4f458a54d30..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/bits/stdint.h +++ /dev/null @@ -1,20 +0,0 @@ -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; - -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST32_MIN INT32_MIN - -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MAX INT32_MAX - -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX - -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#define SIZE_MAX UINT32_MAX diff --git a/lib/libc/include/wasm-wasi-musl/complex.h b/lib/libc/include/wasm-wasi-musl/complex.h deleted file mode 100644 index a645eb13af8b84bda2ce3b3f027840ea867cef6b..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/complex.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define complex _Complex -#ifdef __GNUC__ -#define _Complex_I (__extension__ (0.0f+1.0fi)) -#else -#define _Complex_I (0.0f+1.0fi) -#endif -#define I _Complex_I - -double complex cacos(double complex); -float complex cacosf(float complex); -long double complex cacosl(long double complex); - -double complex casin(double complex); -float complex casinf(float complex); -long double complex casinl(long double complex); - -double complex catan(double complex); -float complex catanf(float complex); -long double complex catanl(long double complex); - -double complex ccos(double complex); -float complex ccosf(float complex); -long double complex ccosl(long double complex); - -double complex csin(double complex); -float complex csinf(float complex); -long double complex csinl(long double complex); - -double complex ctan(double complex); -float complex ctanf(float complex); -long double complex ctanl(long double complex); - -double complex cacosh(double complex); -float complex cacoshf(float complex); -long double complex cacoshl(long double complex); - -double complex casinh(double complex); -float complex casinhf(float complex); -long double complex casinhl(long double complex); - -double complex catanh(double complex); -float complex catanhf(float complex); -long double complex catanhl(long double complex); - -double complex ccosh(double complex); -float complex ccoshf(float complex); -long double complex ccoshl(long double complex); - -double complex csinh(double complex); -float complex csinhf(float complex); -long double complex csinhl(long double complex); - -double complex ctanh(double complex); -float complex ctanhf(float complex); -long double complex ctanhl(long double complex); - -double complex cexp(double complex); -float complex cexpf(float complex); -long double complex cexpl(long double complex); - -double complex clog(double complex); -float complex clogf(float complex); -long double complex clogl(long double complex); - -double cabs(double complex); -float cabsf(float complex); -long double cabsl(long double complex); - -double complex cpow(double complex, double complex); -float complex cpowf(float complex, float complex); -long double complex cpowl(long double complex, long double complex); - -double complex csqrt(double complex); -float complex csqrtf(float complex); -long double complex csqrtl(long double complex); - -double carg(double complex); -float cargf(float complex); -long double cargl(long double complex); - -double cimag(double complex); -float cimagf(float complex); -long double cimagl(long double complex); - -double complex conj(double complex); -float complex conjf(float complex); -long double complex conjl(long double complex); - -double complex cproj(double complex); -float complex cprojf(float complex); -long double complex cprojl(long double complex); - -double creal(double complex); -float crealf(float complex); -long double creall(long double complex); - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's real/imag operators rather than union type punning */ -#ifndef __cplusplus -#define __CIMAG(x, t) \ - (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) - -#define creal(x) ((double)(x)) -#define crealf(x) ((float)(x)) -#define creall(x) ((long double)(x)) - -#define cimag(x) __CIMAG(x, double) -#define cimagf(x) __CIMAG(x, float) -#define cimagl(x) __CIMAG(x, long double) -#endif -#else -#define creal(x) (__builtin_creal(x)) -#define crealf(x) (__builtin_crealf(x)) -#define creall(x) (__builtin_creall(x)) - -#define cimag(x) (__builtin_cimag(x)) -#define cimagf(x) (__builtin_cimagf(x)) -#define cimagl(x) (__builtin_cimagl(x)) -#endif - -#if __STDC_VERSION__ >= 201112L -#if defined(_Imaginary_I) -#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)) -#elif defined(__clang__) -#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) -#else -#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) -#endif -#define CMPLX(x, y) __CMPLX(x, y, double) -#define CMPLXF(x, y) __CMPLX(x, y, float) -#define CMPLXL(x, y) __CMPLX(x, y, long double) -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/dirent.h b/lib/libc/include/wasm-wasi-musl/dirent.h deleted file mode 100644 index 52a3b16a440566efa68ff2fd824359a27792c551..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/dirent.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef _DIRENT_H -#define _DIRENT_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_dirent.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_ino_t -#define __NEED_off_t -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define __NEED_size_t -#endif - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef struct __dirstream DIR; -#else -#include <__typedef_DIR.h> -#endif - -#define d_fileno d_ino - -int closedir(DIR *); -DIR *fdopendir(int); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -#ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ -int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); -#endif -void rewinddir(DIR *); -int dirfd(DIR *); - -int alphasort(const struct dirent **, const struct dirent **); -int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -void seekdir(DIR *, long); -long telldir(DIR *); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 -#define IFTODT(x) ((x)>>12 & 017) -#define DTTOIF(x) ((x)<<12) -#endif -int getdents(int, struct dirent *, size_t); -#endif - -#ifdef _GNU_SOURCE -int versionsort(const struct dirent **, const struct dirent **); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define dirent64 dirent -#define readdir64 readdir -#ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ -#define readdir64_r readdir_r -#endif -#define scandir64 scandir -#define alphasort64 alphasort -#define versionsort64 versionsort -#define off64_t off_t -#define ino64_t ino_t -#define getdents64 getdents -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/dlfcn.h b/lib/libc/include/wasm-wasi-musl/dlfcn.h deleted file mode 100644 index e802de88f67122a9f908355ca7fac6850c6de6b6..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/dlfcn.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _DLFCN_H -#define _DLFCN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define RTLD_LAZY 1 -#define RTLD_NOW 2 -#define RTLD_NOLOAD 4 -#define RTLD_NODELETE 4096 -#define RTLD_GLOBAL 256 -#ifdef __wasilibc_unmodified_upstream -#define RTLD_LOCAL 0 -#else -/* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and - * allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` - * should be the default when neither is specified. - */ -#define RTLD_LOCAL 8 -#endif - -#define RTLD_NEXT ((void *)-1) -#define RTLD_DEFAULT ((void *)0) - -#ifdef __wasilibc_unmodified_upstream -#define RTLD_DI_LINKMAP 2 -#endif - -int dlclose(void *); -char *dlerror(void); -void *dlopen(const char *, int); -void *dlsym(void *__restrict, const char *__restrict); - -#if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) -typedef struct { - const char *dli_fname; - void *dli_fbase; - const char *dli_sname; - void *dli_saddr; -} Dl_info; -int dladdr(const void *, Dl_info *); -int dlinfo(void *, int, void *); -#endif - -#if _REDIR_TIME64 -__REDIR(dlsym, __dlsym_time64); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/errno.h b/lib/libc/include/wasm-wasi-musl/errno.h deleted file mode 100644 index 0252e1b09560cbeca8df05745203454cc6a66a16..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/errno.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _ERRNO_H -#define _ERRNO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#include - -#ifdef __GNUC__ -__attribute__((const)) -#endif -int *__errno_location(void); -#define errno (*__errno_location()) -#else -#include <__errno.h> -#include <__errno_values.h> -#endif - -#ifdef _GNU_SOURCE -extern char *program_invocation_short_name, *program_invocation_name; -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/libc/include/wasm-wasi-musl/fcntl.h b/lib/libc/include/wasm-wasi-musl/fcntl.h deleted file mode 100644 index eef21db1dcbe90f9be3b15edcf8326d8d8e77cd7..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/fcntl.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef _FCNTL_H -#define _FCNTL_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_fcntl.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_mode_t - -#ifdef _GNU_SOURCE -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec -#endif - -#include - -#include - -struct flock { - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - pid_t l_pid; -}; - -int creat(const char *, mode_t); -int fcntl(int, int, ...); -int open(const char *, int, ...); -int openat(int, const char *, int, ...); -int posix_fadvise(int, off_t, off_t, int); -int posix_fallocate(int, off_t, off_t); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define O_SEARCH O_PATH -#define O_EXEC O_PATH -#define O_TTY_INIT 0 - -#define O_ACCMODE (03|O_SEARCH) -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define F_OFD_GETLK 36 -#define F_OFD_SETLK 37 -#define F_OFD_SETLKW 38 - -#define F_DUPFD_CLOEXEC 1030 - -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 - -#define FD_CLOEXEC 1 - -#define AT_FDCWD (-100) -#define AT_SYMLINK_NOFOLLOW 0x100 -#define AT_REMOVEDIR 0x200 -#define AT_SYMLINK_FOLLOW 0x400 -#define AT_EACCESS 0x200 - -#define POSIX_FADV_NORMAL 0 -#define POSIX_FADV_RANDOM 1 -#define POSIX_FADV_SEQUENTIAL 2 -#define POSIX_FADV_WILLNEED 3 -#ifndef POSIX_FADV_DONTNEED -#define POSIX_FADV_DONTNEED 4 -#define POSIX_FADV_NOREUSE 5 -#endif - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#ifndef S_IRUSR -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define AT_NO_AUTOMOUNT 0x800 -#define AT_EMPTY_PATH 0x1000 -#define AT_STATX_SYNC_TYPE 0x6000 -#define AT_STATX_SYNC_AS_STAT 0x0000 -#define AT_STATX_FORCE_SYNC 0x2000 -#define AT_STATX_DONT_SYNC 0x4000 -#define AT_RECURSIVE 0x8000 - -#define FAPPEND O_APPEND -#define FFSYNC O_SYNC -#define FASYNC O_ASYNC -#define FNONBLOCK O_NONBLOCK -#define FNDELAY O_NDELAY - -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 - -#define F_SETLEASE 1024 -#define F_GETLEASE 1025 -#define F_NOTIFY 1026 -#define F_CANCELLK 1029 -#define F_SETPIPE_SZ 1031 -#define F_GETPIPE_SZ 1032 -#define F_ADD_SEALS 1033 -#define F_GET_SEALS 1034 - -#define F_SEAL_SEAL 0x0001 -#define F_SEAL_SHRINK 0x0002 -#define F_SEAL_GROW 0x0004 -#define F_SEAL_WRITE 0x0008 -#define F_SEAL_FUTURE_WRITE 0x0010 - -#define F_GET_RW_HINT 1035 -#define F_SET_RW_HINT 1036 -#define F_GET_FILE_RW_HINT 1037 -#define F_SET_FILE_RW_HINT 1038 - -#define RWF_WRITE_LIFE_NOT_SET 0 -#define RWH_WRITE_LIFE_NONE 1 -#define RWH_WRITE_LIFE_SHORT 2 -#define RWH_WRITE_LIFE_MEDIUM 3 -#define RWH_WRITE_LIFE_LONG 4 -#define RWH_WRITE_LIFE_EXTREME 5 - -#define DN_ACCESS 0x00000001 -#define DN_MODIFY 0x00000002 -#define DN_CREATE 0x00000004 -#define DN_DELETE 0x00000008 -#define DN_RENAME 0x00000010 -#define DN_ATTRIB 0x00000020 -#define DN_MULTISHOT 0x80000000 - -int lockf(int, int, off_t); -#endif -#endif - -#if defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ -#define F_OWNER_TID 0 -#define F_OWNER_PID 1 -#define F_OWNER_PGRP 2 -#define F_OWNER_GID 2 -struct file_handle { - unsigned handle_bytes; - int handle_type; - unsigned char f_handle[]; -}; -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no F_GETOWN_EX */ -struct f_owner_ex { - int type; - pid_t pid; -}; -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ -#define FALLOC_FL_KEEP_SIZE 1 -#define FALLOC_FL_PUNCH_HOLE 2 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ -#define MAX_HANDLE_SZ 128 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no syc_file_range */ -#define SYNC_FILE_RANGE_WAIT_BEFORE 1 -#define SYNC_FILE_RANGE_WRITE 2 -#define SYNC_FILE_RANGE_WAIT_AFTER 4 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no splice */ -#define SPLICE_F_MOVE 1 -#define SPLICE_F_NONBLOCK 2 -#define SPLICE_F_MORE 4 -#define SPLICE_F_GIFT 8 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ -int fallocate(int, int, off_t, off_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ -int name_to_handle_at(int, const char *, struct file_handle *, int *, int); -int open_by_handle_at(int, struct file_handle *, int); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */ -ssize_t readahead(int, off_t, size_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */ -int sync_file_range(int, off_t, off_t, unsigned); -ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); -ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); -ssize_t tee(int, int, size_t, unsigned); -#endif -#define loff_t off_t -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -#define F_GETLK64 F_GETLK -#define F_SETLK64 F_SETLK -#define F_SETLKW64 F_SETLKW -#define flock64 flock -#endif -#define open64 open -#define openat64 openat -#define creat64 creat -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -#define lockf64 lockf -#endif -#define posix_fadvise64 posix_fadvise -#define posix_fallocate64 posix_fallocate -#define off64_t off_t -#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ -#if defined(_GNU_SOURCE) -#define fallocate64 fallocate -#endif -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/fenv.h b/lib/libc/include/wasm-wasi-musl/fenv.h deleted file mode 100644 index 05de990c0bad27ae63af84199caf3ef549249886..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/fenv.h +++ /dev/null @@ -1,28 +0,0 @@ -#ifndef _FENV_H -#define _FENV_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -int feclearexcept(int); -int fegetexceptflag(fexcept_t *, int); -int feraiseexcept(int); -int fesetexceptflag(const fexcept_t *, int); -int fetestexcept(int); - -int fegetround(void); -int fesetround(int); - -int fegetenv(fenv_t *); -int feholdexcept(fenv_t *); -int fesetenv(const fenv_t *); -int feupdateenv(const fenv_t *); - -#ifdef __cplusplus -} -#endif -#endif - diff --git a/lib/libc/include/wasm-wasi-musl/float.h b/lib/libc/include/wasm-wasi-musl/float.h deleted file mode 100644 index 85ce20c4c824c1fab900d0aff7e99d6e330f3b3b..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/float.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _FLOAT_H -#define _FLOAT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of FLT_ROUNDS */ -int __flt_rounds(void); -#define FLT_ROUNDS (__flt_rounds()) -#else -#define FLT_ROUNDS (__builtin_flt_rounds()) -#endif - -#define FLT_RADIX 2 - -#define FLT_TRUE_MIN 1.40129846432481707092e-45F -#define FLT_MIN 1.17549435082228750797e-38F -#define FLT_MAX 3.40282346638528859812e+38F -#define FLT_EPSILON 1.1920928955078125e-07F - -#define FLT_MANT_DIG 24 -#define FLT_MIN_EXP (-125) -#define FLT_MAX_EXP 128 -#define FLT_HAS_SUBNORM 1 - -#define FLT_DIG 6 -#define FLT_DECIMAL_DIG 9 -#define FLT_MIN_10_EXP (-37) -#define FLT_MAX_10_EXP 38 - -#define DBL_TRUE_MIN 4.94065645841246544177e-324 -#define DBL_MIN 2.22507385850720138309e-308 -#define DBL_MAX 1.79769313486231570815e+308 -#define DBL_EPSILON 2.22044604925031308085e-16 - -#define DBL_MANT_DIG 53 -#define DBL_MIN_EXP (-1021) -#define DBL_MAX_EXP 1024 -#define DBL_HAS_SUBNORM 1 - -#define DBL_DIG 15 -#define DBL_DECIMAL_DIG 17 -#define DBL_MIN_10_EXP (-307) -#define DBL_MAX_10_EXP 308 - -#define LDBL_HAS_SUBNORM 1 -#define LDBL_DECIMAL_DIG DECIMAL_DIG - -#include - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/fts.h b/lib/libc/include/wasm-wasi-musl/fts.h deleted file mode 100644 index aef9e0038b9c565c71d64940575550978c714ca6..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/fts.h +++ /dev/null @@ -1,155 +0,0 @@ -/* $NetBSD: fts.h,v 1.19 2009/08/16 19:33:38 christos Exp $ */ - -/* - * Copyright (c) 1989, 1993 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)fts.h 8.3 (Berkeley) 8/14/94 - */ - -#ifndef _FTS_H_ -#define _FTS_H_ - -#include -#include - -#ifndef __fts_stat_t -#define __fts_stat_t struct stat -#endif -#ifndef __fts_nlink_t -#define __fts_nlink_t nlink_t -#endif -#ifndef __fts_ino_t -#define __fts_ino_t ino_t -#endif -#ifndef __fts_length_t -#define __fts_length_t unsigned int -#endif -#ifndef __fts_number_t -#define __fts_number_t int64_t -#endif -#ifndef __fts_dev_t -#define __fts_dev_t dev_t -#endif -#ifndef __fts_level_t -#define __fts_level_t int -#endif - -typedef struct { - struct _ftsent *fts_cur; /* current node */ - struct _ftsent *fts_child; /* linked list of children */ - struct _ftsent **fts_array; /* sort array */ - dev_t fts_dev; /* starting device # */ - char *fts_path; /* path for this descent */ - int fts_rfd; /* fd for root */ - unsigned int fts_pathlen; /* sizeof(path) */ - unsigned int fts_nitems; /* elements in the sort array */ - int (*fts_compar) /* compare function */ - (const struct _ftsent **, const struct _ftsent **); - -#define FTS_COMFOLLOW 0x001 /* follow command line symlinks */ -#define FTS_LOGICAL 0x002 /* logical walk */ -#define FTS_NOCHDIR 0x004 /* don't change directories */ -#define FTS_NOSTAT 0x008 /* don't get stat info */ -#define FTS_PHYSICAL 0x010 /* physical walk */ -#define FTS_SEEDOT 0x020 /* return dot and dot-dot */ -#define FTS_XDEV 0x040 /* don't cross devices */ -#define FTS_WHITEOUT 0x080 /* return whiteout information */ -#define FTS_OPTIONMASK 0x0ff /* valid user option mask */ - -#define FTS_NAMEONLY 0x100 /* (private) child names only */ -#define FTS_STOP 0x200 /* (private) unrecoverable error */ - int fts_options; /* fts_open options, global flags */ -} FTS; - -typedef struct _ftsent { - struct _ftsent *fts_cycle; /* cycle node */ - struct _ftsent *fts_parent; /* parent directory */ - struct _ftsent *fts_link; /* next file in directory */ - __fts_number_t fts_number; /* local numeric value */ - void *fts_pointer; /* local address value */ - char *fts_accpath; /* access path */ - char *fts_path; /* root path */ - int fts_errno; /* errno for this node */ - int fts_symfd; /* fd for symlink */ - __fts_length_t fts_pathlen; /* strlen(fts_path) */ - __fts_length_t fts_namelen; /* strlen(fts_name) */ - - __fts_ino_t fts_ino; /* inode */ - __fts_dev_t fts_dev; /* device */ - __fts_nlink_t fts_nlink; /* link count */ - -#define FTS_ROOTPARENTLEVEL -1 -#define FTS_ROOTLEVEL 0 - __fts_level_t fts_level; /* depth (-1 to N) */ - -#define FTS_D 1 /* preorder directory */ -#define FTS_DC 2 /* directory that causes cycles */ -#define FTS_DEFAULT 3 /* none of the above */ -#define FTS_DNR 4 /* unreadable directory */ -#define FTS_DOT 5 /* dot or dot-dot */ -#define FTS_DP 6 /* postorder directory */ -#define FTS_ERR 7 /* error; errno is set */ -#define FTS_F 8 /* regular file */ -#define FTS_INIT 9 /* initialized only */ -#define FTS_NS 10 /* stat(2) failed */ -#define FTS_NSOK 11 /* no stat(2) requested */ -#define FTS_SL 12 /* symbolic link */ -#define FTS_SLNONE 13 /* symbolic link without target */ -#define FTS_W 14 /* whiteout object */ - unsigned short fts_info; /* user flags for FTSENT structure */ - -#define FTS_DONTCHDIR 0x01 /* don't chdir .. to the parent */ -#define FTS_SYMFOLLOW 0x02 /* followed a symlink to get here */ -#define FTS_ISW 0x04 /* this is a whiteout object */ - unsigned short fts_flags; /* private flags for FTSENT structure */ - -#define FTS_AGAIN 1 /* read node again */ -#define FTS_FOLLOW 2 /* follow symbolic link */ -#define FTS_NOINSTR 3 /* no instructions */ -#define FTS_SKIP 4 /* discard node */ - unsigned short fts_instr; /* fts_set() instructions */ - - __fts_stat_t *fts_statp; /* stat(2) information */ - char fts_name[1]; /* file name */ -} FTSENT; - -#ifdef __cplusplus -extern "C" { -#endif -FTSENT *fts_children(FTS *, int); -int fts_close(FTS *); -FTS *fts_open(char * const *, int, - int (*)(const FTSENT **, const FTSENT **)); -FTSENT *fts_read(FTS *); -int fts_set(FTS *, FTSENT *, int); -#ifdef __cplusplus -} -#endif - - -#endif /* !_FTS_H_ */ diff --git a/lib/libc/include/wasm-wasi-musl/ftw.h b/lib/libc/include/wasm-wasi-musl/ftw.h deleted file mode 100644 index 2b1b270c777d39a1f94fcce0f985847ee67f8a81..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/ftw.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _FTW_H -#define _FTW_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define FTW_F 1 -#define FTW_D 2 -#define FTW_DNR 3 -#define FTW_NS 4 -#define FTW_SL 5 -#define FTW_DP 6 -#define FTW_SLN 7 - -#define FTW_PHYS 1 -#define FTW_MOUNT 2 -#define FTW_CHDIR 4 -#define FTW_DEPTH 8 - -struct FTW { - int base; - int level; -}; - -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -int ftw(const char *, int (*)(const char *, const struct stat *, int), int); -#endif -int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -#define ftw64 ftw -#endif -#define nftw64 nftw -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/glob.h b/lib/libc/include/wasm-wasi-musl/glob.h deleted file mode 100644 index 8c4bf15891d78c8fec9ff164be9c58762ecc2c71..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/glob.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _GLOB_H -#define _GLOB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t - -#include - -typedef struct { - size_t gl_pathc; - char **gl_pathv; - size_t gl_offs; - int __dummy1; - void *__dummy2[5]; -} glob_t; - -int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); -void globfree(glob_t *); - -#define GLOB_ERR 0x01 -#define GLOB_MARK 0x02 -#define GLOB_NOSORT 0x04 -#define GLOB_DOOFFS 0x08 -#define GLOB_NOCHECK 0x10 -#define GLOB_APPEND 0x20 -#define GLOB_NOESCAPE 0x40 -#define GLOB_PERIOD 0x80 - -#ifdef __wasilibc_unmodified_upstream // WASI has no usernames -#define GLOB_TILDE 0x1000 -#define GLOB_TILDE_CHECK 0x4000 -#endif - -#define GLOB_NOSPACE 1 -#define GLOB_ABORTED 2 -#define GLOB_NOMATCH 3 -#define GLOB_NOSYS 4 - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define glob64 glob -#define globfree64 globfree -#define glob64_t glob_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/ifaddrs.h b/lib/libc/include/wasm-wasi-musl/ifaddrs.h deleted file mode 100644 index c0328a8ea510385a56fb15a8a8eba6ba90d1508c..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/ifaddrs.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _IFADDRS_H -#define _IFADDRS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -struct ifaddrs { - struct ifaddrs *ifa_next; - char *ifa_name; - unsigned ifa_flags; - struct sockaddr *ifa_addr; - struct sockaddr *ifa_netmask; - union { - struct sockaddr *ifu_broadaddr; - struct sockaddr *ifu_dstaddr; - } ifa_ifu; - void *ifa_data; -}; -#define ifa_broadaddr ifa_ifu.ifu_broadaddr -#define ifa_dstaddr ifa_ifu.ifu_dstaddr - -void freeifaddrs(struct ifaddrs *); -int getifaddrs(struct ifaddrs **); - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/libc/include/wasm-wasi-musl/inttypes.h b/lib/libc/include/wasm-wasi-musl/inttypes.h deleted file mode 100644 index 71b3904317750c43864e26b097202c680a10323e..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/inttypes.h +++ /dev/null @@ -1,233 +0,0 @@ -#ifndef _INTTYPES_H -#define _INTTYPES_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_wchar_t -#include - -typedef struct { intmax_t quot, rem; } imaxdiv_t; - -intmax_t imaxabs(intmax_t); -imaxdiv_t imaxdiv(intmax_t, intmax_t); - -intmax_t strtoimax(const char *__restrict, char **__restrict, int); -uintmax_t strtoumax(const char *__restrict, char **__restrict, int); - -intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); -uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); - -#if UINTPTR_MAX == UINT64_MAX -#define __PRI64 "l" -#define __PRIPTR "l" -#else -#define __PRI64 "ll" -#define __PRIPTR "" -#endif - -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 __PRI64 "d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 __PRI64 "d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 "d" -#define PRIdFAST32 "d" -#define PRIdFAST64 __PRI64 "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 __PRI64 "i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 __PRI64 "i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" -#define PRIiFAST32 "i" -#define PRIiFAST64 __PRI64 "i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 __PRI64 "o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 __PRI64 "o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" -#define PRIoFAST32 "o" -#define PRIoFAST64 __PRI64 "o" - -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 __PRI64 "u" - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 __PRI64 "u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" -#define PRIuFAST32 "u" -#define PRIuFAST64 __PRI64 "u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 __PRI64 "x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 __PRI64 "x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" -#define PRIxFAST32 "x" -#define PRIxFAST64 __PRI64 "x" - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 __PRI64 "X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 __PRI64 "X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" -#define PRIXFAST32 "X" -#define PRIXFAST64 __PRI64 "X" - -#define PRIdMAX __PRI64 "d" -#define PRIiMAX __PRI64 "i" -#define PRIoMAX __PRI64 "o" -#define PRIuMAX __PRI64 "u" -#define PRIxMAX __PRI64 "x" -#define PRIXMAX __PRI64 "X" - -#define PRIdPTR __PRIPTR "d" -#define PRIiPTR __PRIPTR "i" -#define PRIoPTR __PRIPTR "o" -#define PRIuPTR __PRIPTR "u" -#define PRIxPTR __PRIPTR "x" -#define PRIXPTR __PRIPTR "X" - -#define SCNd8 "hhd" -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 __PRI64 "d" - -#define SCNdLEAST8 "hhd" -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 __PRI64 "d" - -#define SCNdFAST8 "hhd" -#define SCNdFAST16 "d" -#define SCNdFAST32 "d" -#define SCNdFAST64 __PRI64 "d" - -#define SCNi8 "hhi" -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 __PRI64 "i" - -#define SCNiLEAST8 "hhi" -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 __PRI64 "i" - -#define SCNiFAST8 "hhi" -#define SCNiFAST16 "i" -#define SCNiFAST32 "i" -#define SCNiFAST64 __PRI64 "i" - -#define SCNu8 "hhu" -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 __PRI64 "u" - -#define SCNuLEAST8 "hhu" -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 __PRI64 "u" - -#define SCNuFAST8 "hhu" -#define SCNuFAST16 "u" -#define SCNuFAST32 "u" -#define SCNuFAST64 __PRI64 "u" - -#define SCNo8 "hho" -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 __PRI64 "o" - -#define SCNoLEAST8 "hho" -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 __PRI64 "o" - -#define SCNoFAST8 "hho" -#define SCNoFAST16 "o" -#define SCNoFAST32 "o" -#define SCNoFAST64 __PRI64 "o" - -#define SCNx8 "hhx" -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 __PRI64 "x" - -#define SCNxLEAST8 "hhx" -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 __PRI64 "x" - -#define SCNxFAST8 "hhx" -#define SCNxFAST16 "x" -#define SCNxFAST32 "x" -#define SCNxFAST64 __PRI64 "x" - -#define SCNdMAX __PRI64 "d" -#define SCNiMAX __PRI64 "i" -#define SCNoMAX __PRI64 "o" -#define SCNuMAX __PRI64 "u" -#define SCNxMAX __PRI64 "x" - -#define SCNdPTR __PRIPTR "d" -#define SCNiPTR __PRIPTR "i" -#define SCNoPTR __PRIPTR "o" -#define SCNuPTR __PRIPTR "u" -#define SCNxPTR __PRIPTR "x" - -#ifdef __cplusplus -} -#endif -#else -#include <__header_inttypes.h> -#endif - -#endif - diff --git a/lib/libc/include/wasm-wasi-musl/limits.h b/lib/libc/include/wasm-wasi-musl/limits.h deleted file mode 100644 index c160568cdecedf4a5fba9692237baf624d3d705c..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/limits.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef _LIMITS_H -#define _LIMITS_H - -#include - -#include /* __LONG_MAX */ - -/* Support signed or unsigned plain-char */ - -#if '\xff' > 0 -#define CHAR_MIN 0 -#define CHAR_MAX 255 -#else -#define CHAR_MIN (-128) -#define CHAR_MAX 127 -#endif - -#define CHAR_BIT 8 -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 255 -#define SHRT_MIN (-1-0x7fff) -#define SHRT_MAX 0x7fff -#define USHRT_MAX 0xffff -#define INT_MIN (-1-0x7fffffff) -#define INT_MAX 0x7fffffff -#define UINT_MAX 0xffffffffU -#define LONG_MIN (-LONG_MAX-1) -#define LONG_MAX __LONG_MAX -#define ULONG_MAX (2UL*LONG_MAX+1) -#define LLONG_MIN (-LLONG_MAX-1) -#define LLONG_MAX 0x7fffffffffffffffLL -#define ULLONG_MAX (2ULL*LLONG_MAX+1) - -#define MB_LEN_MAX 4 - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#include - -#ifdef __wasilibc_unmodified_upstream /* WASI has no pipes */ -#define PIPE_BUF 4096 -#endif -#define FILESIZEBITS 64 -#ifndef NAME_MAX -#define NAME_MAX 255 -#endif -#define PATH_MAX 4096 -#define NGROUPS_MAX 32 -#define ARG_MAX 131072 -#define IOV_MAX 1024 -#define SYMLOOP_MAX 40 -#define WORD_BIT 32 -#define SSIZE_MAX LONG_MAX -#define TZNAME_MAX 6 -#define TTY_NAME_MAX 32 -#define HOST_NAME_MAX 255 - -#if LONG_MAX == 0x7fffffffL -#define LONG_BIT 32 -#else -#define LONG_BIT 64 -#endif - -/* Implementation choices... */ - -#define PTHREAD_KEYS_MAX 128 -#define PTHREAD_STACK_MIN 2048 -#define PTHREAD_DESTRUCTOR_ITERATIONS 4 -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#define SEM_VALUE_MAX 0x7fffffff -#define SEM_NSEMS_MAX 256 -#endif -#define DELAYTIMER_MAX 0x7fffffff -#ifdef __wasilibc_unmodified_upstream /* WASI has no mq */ -#define MQ_PRIO_MAX 32768 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no usernames */ -#define LOGIN_NAME_MAX 256 -#endif - -/* Arbitrary numbers... */ - -#ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ -#define BC_BASE_MAX 99 -#define BC_DIM_MAX 2048 -#define BC_SCALE_MAX 99 -#define BC_STRING_MAX 1000 -#endif -#define CHARCLASS_NAME_MAX 14 -#define COLL_WEIGHTS_MAX 2 -#ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ -#define EXPR_NEST_MAX 32 -#define LINE_MAX 4096 -#endif -#define RE_DUP_MAX 255 - -#define NL_ARGMAX 9 -#define NL_MSGMAX 32767 -#define NL_SETMAX 255 -#define NL_TEXTMAX 2048 - -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) - -#ifdef PAGESIZE -#define PAGE_SIZE PAGESIZE -#endif -#define NZERO 20 -#define NL_LANGMAX 32 - -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) - -#define NL_NMAX 16 - -#endif - -/* POSIX/SUS requirements follow. These numbers come directly - * from SUS and have nothing to do with the host system. */ - -#define _POSIX_AIO_LISTIO_MAX 2 -#define _POSIX_AIO_MAX 1 -#define _POSIX_ARG_MAX 4096 -#define _POSIX_CHILD_MAX 25 -#define _POSIX_CLOCKRES_MIN 20000000 -#define _POSIX_DELAYTIMER_MAX 32 -#define _POSIX_HOST_NAME_MAX 255 -#define _POSIX_LINK_MAX 8 -#define _POSIX_LOGIN_NAME_MAX 9 -#define _POSIX_MAX_CANON 255 -#define _POSIX_MAX_INPUT 255 -#define _POSIX_MQ_OPEN_MAX 8 -#define _POSIX_MQ_PRIO_MAX 32 -#define _POSIX_NAME_MAX 14 -#define _POSIX_NGROUPS_MAX 8 -#define _POSIX_OPEN_MAX 20 -#define _POSIX_PATH_MAX 256 -#define _POSIX_PIPE_BUF 512 -#define _POSIX_RE_DUP_MAX 255 -#define _POSIX_RTSIG_MAX 8 -#define _POSIX_SEM_NSEMS_MAX 256 -#define _POSIX_SEM_VALUE_MAX 32767 -#define _POSIX_SIGQUEUE_MAX 32 -#define _POSIX_SSIZE_MAX 32767 -#define _POSIX_STREAM_MAX 8 -#define _POSIX_SS_REPL_MAX 4 -#define _POSIX_SYMLINK_MAX 255 -#define _POSIX_SYMLOOP_MAX 8 -#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 -#define _POSIX_THREAD_KEYS_MAX 128 -#define _POSIX_THREAD_THREADS_MAX 64 -#define _POSIX_TIMER_MAX 32 -#define _POSIX_TRACE_EVENT_NAME_MAX 30 -#define _POSIX_TRACE_NAME_MAX 8 -#define _POSIX_TRACE_SYS_MAX 8 -#define _POSIX_TRACE_USER_EVENT_MAX 32 -#define _POSIX_TTY_NAME_MAX 9 -#define _POSIX_TZNAME_MAX 6 -#define _POSIX2_BC_BASE_MAX 99 -#define _POSIX2_BC_DIM_MAX 2048 -#define _POSIX2_BC_SCALE_MAX 99 -#define _POSIX2_BC_STRING_MAX 1000 -#define _POSIX2_CHARCLASS_NAME_MAX 14 -#define _POSIX2_COLL_WEIGHTS_MAX 2 -#define _POSIX2_EXPR_NEST_MAX 32 -#define _POSIX2_LINE_MAX 2048 -#define _POSIX2_RE_DUP_MAX 255 - -#define _XOPEN_IOV_MAX 16 -#define _XOPEN_NAME_MAX 255 -#define _XOPEN_PATH_MAX 1024 - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/locale.h b/lib/libc/include/wasm-wasi-musl/locale.h deleted file mode 100644 index 6a62d1f5a7ff1843d59200a0380ea2868117c0b0..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/locale.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef _LOCALE_H -#define _LOCALE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define LC_CTYPE 0 -#define LC_NUMERIC 1 -#define LC_TIME 2 -#define LC_COLLATE 3 -#define LC_MONETARY 4 -#define LC_MESSAGES 5 -#define LC_ALL 6 - -struct lconv { - char *decimal_point; - char *thousands_sep; - char *grouping; - - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; -}; - - -char *setlocale (int, const char *); -struct lconv *localeconv(void); - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define __NEED_locale_t - -#include - -#define LC_GLOBAL_LOCALE ((locale_t)-1) - -#define LC_CTYPE_MASK (1< -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *malloc (size_t); -void *calloc (size_t, size_t); -void *realloc (void *, size_t); -void free (void *); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -void *valloc (size_t); -void *memalign(size_t, size_t); -#endif - -size_t malloc_usable_size(void *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/math.h b/lib/libc/include/wasm-wasi-musl/math.h deleted file mode 100644 index 515cc66be0b3ba3297ff84f78bd759406b1486d3..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/math.h +++ /dev/null @@ -1,459 +0,0 @@ -#ifndef _MATH_H -#define _MATH_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_float_t -#define __NEED_double_t -#include - -#if 100*__GNUC__+__GNUC_MINOR__ >= 303 -#define NAN __builtin_nanf("") -#define INFINITY __builtin_inff() -#else -#define NAN (0.0f/0.0f) -#define INFINITY 1e5000f -#endif - -#define HUGE_VALF INFINITY -#define HUGE_VAL ((double)INFINITY) -#define HUGE_VALL ((long double)INFINITY) - -#define MATH_ERRNO 1 -#define MATH_ERREXCEPT 2 -#define math_errhandling 2 - -#define FP_ILOGBNAN (-1-0x7fffffff) -#define FP_ILOGB0 FP_ILOGBNAN - -#define FP_NAN 0 -#define FP_INFINITE 1 -#define FP_ZERO 2 -#define FP_SUBNORMAL 3 -#define FP_NORMAL 4 - -#ifdef __FP_FAST_FMA -#define FP_FAST_FMA 1 -#endif - -#ifdef __FP_FAST_FMAF -#define FP_FAST_FMAF 1 -#endif - -#ifdef __FP_FAST_FMAL -#define FP_FAST_FMAL 1 -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of the fpclassify-like operations */ -int __fpclassify(double); -int __fpclassifyf(float); -int __fpclassifyl(long double); - -static __inline unsigned __FLOAT_BITS(float __f) -{ - union {float __f; unsigned __i;} __u; - __u.__f = __f; - return __u.__i; -} -static __inline unsigned long long __DOUBLE_BITS(double __f) -{ - union {double __f; unsigned long long __i;} __u; - __u.__f = __f; - return __u.__i; -} - -#define fpclassify(x) ( \ - sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ - sizeof(x) == sizeof(double) ? __fpclassify(x) : \ - __fpclassifyl(x) ) - -#define isinf(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ - __fpclassifyl(x) == FP_INFINITE) - -#define isnan(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ - __fpclassifyl(x) == FP_NAN) - -#define isnormal(x) ( \ - sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ - sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ - __fpclassifyl(x) == FP_NORMAL) - -#define isfinite(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ - __fpclassifyl(x) > FP_INFINITE) - -int __signbit(double); -int __signbitf(float); -int __signbitl(long double); - -#define signbit(x) ( \ - sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ - sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ - __signbitl(x) ) - -#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) - -#define __ISREL_DEF(rel, op, type) \ -static __inline int __is##rel(type __x, type __y) \ -{ return !isunordered(__x,__y) && __x op __y; } - -__ISREL_DEF(lessf, <, float_t) -__ISREL_DEF(less, <, double_t) -__ISREL_DEF(lessl, <, long double) -__ISREL_DEF(lessequalf, <=, float_t) -__ISREL_DEF(lessequal, <=, double_t) -__ISREL_DEF(lessequall, <=, long double) -__ISREL_DEF(lessgreaterf, !=, float_t) -__ISREL_DEF(lessgreater, !=, double_t) -__ISREL_DEF(lessgreaterl, !=, long double) -__ISREL_DEF(greaterf, >, float_t) -__ISREL_DEF(greater, >, double_t) -__ISREL_DEF(greaterl, >, long double) -__ISREL_DEF(greaterequalf, >=, float_t) -__ISREL_DEF(greaterequal, >=, double_t) -__ISREL_DEF(greaterequall, >=, long double) - -#define __tg_pred_2(x, y, p) ( \ - sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ - sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ - p##l(x, y) ) - -#define isless(x, y) __tg_pred_2(x, y, __isless) -#define islessequal(x, y) __tg_pred_2(x, y, __islessequal) -#define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) -#define isgreater(x, y) __tg_pred_2(x, y, __isgreater) -#define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) -#else -#define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, \ - FP_NORMAL, FP_SUBNORMAL, \ - FP_ZERO, x)) -#define isinf(x) (__builtin_isinf(x)) -#define isnan(x) (__builtin_isnan(x)) -#define isnormal(x) (__builtin_isnormal(x)) -#define isfinite(x) (__builtin_isfinite(x)) -#define signbit(x) (__builtin_signbit(x)) -#define isunordered(x, y) (__builtin_isunordered(x, y)) -#define isless(x, y) (__builtin_isless(x, y)) -#define islessequal(x, y) (__builtin_islessequal(x, y)) -#define islessgreater(x, y) (__builtin_islessgreater(x, y)) -#define isgreater(x, y) (__builtin_isgreater(x, y)) -#define isgreaterequal(x, y) (__builtin_isgreaterequal(x, y)) -#endif - -double acos(double); -float acosf(float); -long double acosl(long double); - -double acosh(double); -float acoshf(float); -long double acoshl(long double); - -double asin(double); -float asinf(float); -long double asinl(long double); - -double asinh(double); -float asinhf(float); -long double asinhl(long double); - -double atan(double); -float atanf(float); -long double atanl(long double); - -double atan2(double, double); -float atan2f(float, float); -long double atan2l(long double, long double); - -double atanh(double); -float atanhf(float); -long double atanhl(long double); - -double cbrt(double); -float cbrtf(float); -long double cbrtl(long double); - -double ceil(double); -float ceilf(float); -long double ceill(long double); - -double copysign(double, double); -float copysignf(float, float); -long double copysignl(long double, long double); - -double cos(double); -float cosf(float); -long double cosl(long double); - -double cosh(double); -float coshf(float); -long double coshl(long double); - -double erf(double); -float erff(float); -long double erfl(long double); - -double erfc(double); -float erfcf(float); -long double erfcl(long double); - -double exp(double); -float expf(float); -long double expl(long double); - -double exp2(double); -float exp2f(float); -long double exp2l(long double); - -double expm1(double); -float expm1f(float); -long double expm1l(long double); - -double fabs(double); -float fabsf(float); -long double fabsl(long double); - -double fdim(double, double); -float fdimf(float, float); -long double fdiml(long double, long double); - -double floor(double); -float floorf(float); -long double floorl(long double); - -double fma(double, double, double); -float fmaf(float, float, float); -long double fmal(long double, long double, long double); - -double fmax(double, double); -float fmaxf(float, float); -long double fmaxl(long double, long double); - -double fmin(double, double); -float fminf(float, float); -long double fminl(long double, long double); - -double fmod(double, double); -float fmodf(float, float); -long double fmodl(long double, long double); - -double frexp(double, int *); -float frexpf(float, int *); -long double frexpl(long double, int *); - -double hypot(double, double); -float hypotf(float, float); -long double hypotl(long double, long double); - -int ilogb(double); -int ilogbf(float); -int ilogbl(long double); - -double ldexp(double, int); -float ldexpf(float, int); -long double ldexpl(long double, int); - -double lgamma(double); -float lgammaf(float); -long double lgammal(long double); - -long long llrint(double); -long long llrintf(float); -long long llrintl(long double); - -long long llround(double); -long long llroundf(float); -long long llroundl(long double); - -double log(double); -float logf(float); -long double logl(long double); - -double log10(double); -float log10f(float); -long double log10l(long double); - -double log1p(double); -float log1pf(float); -long double log1pl(long double); - -double log2(double); -float log2f(float); -long double log2l(long double); - -double logb(double); -float logbf(float); -long double logbl(long double); - -long lrint(double); -long lrintf(float); -long lrintl(long double); - -long lround(double); -long lroundf(float); -long lroundl(long double); - -double modf(double, double *); -float modff(float, float *); -long double modfl(long double, long double *); - -double nan(const char *); -float nanf(const char *); -long double nanl(const char *); - -double nearbyint(double); -float nearbyintf(float); -long double nearbyintl(long double); - -double nextafter(double, double); -float nextafterf(float, float); -long double nextafterl(long double, long double); - -double nexttoward(double, long double); -float nexttowardf(float, long double); -long double nexttowardl(long double, long double); - -double pow(double, double); -float powf(float, float); -long double powl(long double, long double); - -double remainder(double, double); -float remainderf(float, float); -long double remainderl(long double, long double); - -double remquo(double, double, int *); -float remquof(float, float, int *); -long double remquol(long double, long double, int *); - -double rint(double); -float rintf(float); -long double rintl(long double); - -double round(double); -float roundf(float); -long double roundl(long double); - -double scalbln(double, long); -float scalblnf(float, long); -long double scalblnl(long double, long); - -double scalbn(double, int); -float scalbnf(float, int); -long double scalbnl(long double, int); - -double sin(double); -float sinf(float); -long double sinl(long double); - -double sinh(double); -float sinhf(float); -long double sinhl(long double); - -double sqrt(double); -float sqrtf(float); -long double sqrtl(long double); - -double tan(double); -float tanf(float); -long double tanl(long double); - -double tanh(double); -float tanhf(float); -long double tanhl(long double); - -double tgamma(double); -float tgammaf(float); -long double tgammal(long double); - -double trunc(double); -float truncf(float); -long double truncl(long double); - - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) -#undef MAXFLOAT -#define MAXFLOAT 3.40282346638528859812e+38F -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define M_E 2.7182818284590452354 /* e */ -#define M_LOG2E 1.4426950408889634074 /* log_2 e */ -#define M_LOG10E 0.43429448190325182765 /* log_10 e */ -#define M_LN2 0.69314718055994530942 /* log_e 2 */ -#define M_LN10 2.30258509299404568402 /* log_e 10 */ -#define M_PI 3.14159265358979323846 /* pi */ -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ - -extern int signgam; - -double j0(double); -double j1(double); -double jn(int, double); - -double y0(double); -double y1(double); -double yn(int, double); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define HUGE 3.40282346638528859812e+38F - -double drem(double, double); -float dremf(float, float); - -int finite(double); -int finitef(float); - -double scalb(double, double); -float scalbf(float, float); - -double significand(double); -float significandf(float); - -double lgamma_r(double, int*); -float lgammaf_r(float, int*); - -float j0f(float); -float j1f(float); -float jnf(int, float); - -float y0f(float); -float y1f(float); -float ynf(int, float); -#endif - -#ifdef _GNU_SOURCE -long double lgammal_r(long double, int*); - -void sincos(double, double*, double*); -void sincosf(float, float*, float*); -void sincosl(long double, long double*, long double*); - -double exp10(double); -float exp10f(float); -long double exp10l(long double); - -double pow10(double); -float pow10f(float); -long double pow10l(long double); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/netinet/in.h b/lib/libc/include/wasm-wasi-musl/netinet/in.h deleted file mode 100644 index d9422af2ea09c8da87b558c5d7629dc60681c268..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/netinet/in.h +++ /dev/null @@ -1,433 +0,0 @@ -#ifndef _NETINET_IN_H -#define _NETINET_IN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_netinet_in.h> -#endif - -typedef uint16_t in_port_t; -typedef uint32_t in_addr_t; -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct in_addr { in_addr_t s_addr; }; -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr_in { - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - uint8_t sin_zero[8]; -}; -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct in6_addr { - union { - uint8_t __s6_addr[16]; - uint16_t __s6_addr16[8]; - uint32_t __s6_addr32[4]; - } __in6_union; -}; -#define s6_addr __in6_union.__s6_addr -#define s6_addr16 __in6_union.__s6_addr16 -#define s6_addr32 __in6_union.__s6_addr32 -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr_in6 { - sa_family_t sin6_family; - in_port_t sin6_port; - uint32_t sin6_flowinfo; - struct in6_addr sin6_addr; - uint32_t sin6_scope_id; -}; -#endif - -struct ipv6_mreq { - struct in6_addr ipv6mr_multiaddr; - unsigned ipv6mr_interface; -}; - -#define INADDR_ANY ((in_addr_t) 0x00000000) -#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) -#define INADDR_NONE ((in_addr_t) 0xffffffff) -#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) -#define INADDR_DUMMY ((in_addr_t) 0xc0000008) - -#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) -#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) -#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) -#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) -#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } -#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } -#endif - -extern const struct in6_addr in6addr_any, in6addr_loopback; - -#define INET_ADDRSTRLEN 16 -#define INET6_ADDRSTRLEN 46 - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -#define IPPORT_RESERVED 1024 - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IGMP 2 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_EGP 8 -#define IPPROTO_PUP 12 -#define IPPROTO_UDP 17 -#define IPPROTO_IDP 22 -#define IPPROTO_TP 29 -#define IPPROTO_DCCP 33 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_RSVP 46 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_MTP 92 -#define IPPROTO_BEETPH 94 -#define IPPROTO_ENCAP 98 -#define IPPROTO_PIM 103 -#define IPPROTO_COMP 108 -#define IPPROTO_SCTP 132 -#define IPPROTO_MH 135 -#define IPPROTO_UDPLITE 136 -#define IPPROTO_MPLS 137 -#define IPPROTO_ETHERNET 143 -#define IPPROTO_RAW 255 -#define IPPROTO_MPTCP 262 -#define IPPROTO_MAX 263 -#endif - -#define IN6_IS_ADDR_UNSPECIFIED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) - -#define IN6_IS_ADDR_LOOPBACK(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && \ - ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ - ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) - -#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) - -#define IN6_IS_ADDR_LINKLOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) - -#define IN6_IS_ADDR_SITELOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) - -#define IN6_IS_ADDR_V4MAPPED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ - ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) - -#define IN6_IS_ADDR_V4COMPAT(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) - -#define IN6_IS_ADDR_MC_NODELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) - -#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) - -#define IN6_IS_ADDR_MC_SITELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) - -#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) - -#define IN6_IS_ADDR_MC_GLOBAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) - -#define __ARE_4_EQUAL(a,b) \ - (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) -#define IN6_ARE_ADDR_EQUAL(a,b) \ - __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) - -#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) -#define IN_CLASSA_NET 0xff000000 -#define IN_CLASSA_NSHIFT 24 -#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) -#define IN_CLASSA_MAX 128 -#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) -#define IN_CLASSB_NET 0xffff0000 -#define IN_CLASSB_NSHIFT 16 -#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) -#define IN_CLASSB_MAX 65536 -#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) -#define IN_CLASSC_NET 0xffffff00 -#define IN_CLASSC_NSHIFT 8 -#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) -#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) -#define IN_MULTICAST(a) IN_CLASSD(a) -#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) -#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) - -#define IN_LOOPBACKNET 127 - - -#define IP_TOS 1 -#define IP_TTL 2 -#define IP_HDRINCL 3 -#define IP_OPTIONS 4 -#define IP_ROUTER_ALERT 5 -#define IP_RECVOPTS 6 -#define IP_RETOPTS 7 -#define IP_PKTINFO 8 -#define IP_PKTOPTIONS 9 -#define IP_PMTUDISC 10 -#define IP_MTU_DISCOVER 10 -#define IP_RECVERR 11 -#define IP_RECVTTL 12 -#define IP_RECVTOS 13 -#define IP_MTU 14 -#define IP_FREEBIND 15 -#define IP_IPSEC_POLICY 16 -#define IP_XFRM_POLICY 17 -#define IP_PASSSEC 18 -#define IP_TRANSPARENT 19 -#define IP_ORIGDSTADDR 20 -#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR -#define IP_MINTTL 21 -#define IP_NODEFRAG 22 -#define IP_CHECKSUM 23 -#define IP_BIND_ADDRESS_NO_PORT 24 -#define IP_RECVFRAGSIZE 25 -#define IP_RECVERR_RFC4884 26 -#define IP_MULTICAST_IF 32 -#define IP_MULTICAST_TTL 33 -#define IP_MULTICAST_LOOP 34 -#define IP_ADD_MEMBERSHIP 35 -#define IP_DROP_MEMBERSHIP 36 -#define IP_UNBLOCK_SOURCE 37 -#define IP_BLOCK_SOURCE 38 -#define IP_ADD_SOURCE_MEMBERSHIP 39 -#define IP_DROP_SOURCE_MEMBERSHIP 40 -#define IP_MSFILTER 41 -#define IP_MULTICAST_ALL 49 -#define IP_UNICAST_IF 50 - -#define IP_RECVRETOPTS IP_RETOPTS - -#define IP_PMTUDISC_DONT 0 -#define IP_PMTUDISC_WANT 1 -#define IP_PMTUDISC_DO 2 -#define IP_PMTUDISC_PROBE 3 -#define IP_PMTUDISC_INTERFACE 4 -#define IP_PMTUDISC_OMIT 5 - -#define IP_DEFAULT_MULTICAST_TTL 1 -#define IP_DEFAULT_MULTICAST_LOOP 1 -#define IP_MAX_MEMBERSHIPS 20 - -struct ip_opts { - struct in_addr ip_dst; - char ip_opts[40]; -}; - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define MCAST_JOIN_GROUP 42 -#define MCAST_BLOCK_SOURCE 43 -#define MCAST_UNBLOCK_SOURCE 44 -#define MCAST_LEAVE_GROUP 45 -#define MCAST_JOIN_SOURCE_GROUP 46 -#define MCAST_LEAVE_SOURCE_GROUP 47 -#define MCAST_MSFILTER 48 - -#define MCAST_EXCLUDE 0 -#define MCAST_INCLUDE 1 - -struct ip_mreq { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -struct ip_mreqn { - struct in_addr imr_multiaddr; - struct in_addr imr_address; - int imr_ifindex; -}; - -struct ip_mreq_source { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; - struct in_addr imr_sourceaddr; -}; - -struct ip_msfilter { - struct in_addr imsf_multiaddr; - struct in_addr imsf_interface; - uint32_t imsf_fmode; - uint32_t imsf_numsrc; - struct in_addr imsf_slist[1]; -}; -#define IP_MSFILTER_SIZE(numsrc) \ - (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ - + (numsrc) * sizeof(struct in_addr)) - -struct group_req { - uint32_t gr_interface; - struct sockaddr_storage gr_group; -}; - -struct group_source_req { - uint32_t gsr_interface; - struct sockaddr_storage gsr_group; - struct sockaddr_storage gsr_source; -}; - -struct group_filter { - uint32_t gf_interface; - struct sockaddr_storage gf_group; - uint32_t gf_fmode; - uint32_t gf_numsrc; - struct sockaddr_storage gf_slist[1]; -}; -#define GROUP_FILTER_SIZE(numsrc) \ - (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ - + (numsrc) * sizeof(struct sockaddr_storage)) - -struct in_pktinfo { - int ipi_ifindex; - struct in_addr ipi_spec_dst; - struct in_addr ipi_addr; -}; - -struct in6_pktinfo { - struct in6_addr ipi6_addr; - unsigned ipi6_ifindex; -}; - -struct ip6_mtuinfo { - struct sockaddr_in6 ip6m_addr; - uint32_t ip6m_mtu; -}; -#endif - -#define IPV6_ADDRFORM 1 -#define IPV6_2292PKTINFO 2 -#define IPV6_2292HOPOPTS 3 -#define IPV6_2292DSTOPTS 4 -#define IPV6_2292RTHDR 5 -#define IPV6_2292PKTOPTIONS 6 -#define IPV6_CHECKSUM 7 -#define IPV6_2292HOPLIMIT 8 -#define IPV6_NEXTHOP 9 -#define IPV6_AUTHHDR 10 -#define IPV6_UNICAST_HOPS 16 -#define IPV6_MULTICAST_IF 17 -#define IPV6_MULTICAST_HOPS 18 -#define IPV6_MULTICAST_LOOP 19 -#define IPV6_JOIN_GROUP 20 -#define IPV6_LEAVE_GROUP 21 -#define IPV6_ROUTER_ALERT 22 -#define IPV6_MTU_DISCOVER 23 -#define IPV6_MTU 24 -#define IPV6_RECVERR 25 -#define IPV6_V6ONLY 26 -#define IPV6_JOIN_ANYCAST 27 -#define IPV6_LEAVE_ANYCAST 28 -#define IPV6_MULTICAST_ALL 29 -#define IPV6_ROUTER_ALERT_ISOLATE 30 -#define IPV6_IPSEC_POLICY 34 -#define IPV6_XFRM_POLICY 35 -#define IPV6_HDRINCL 36 - -#define IPV6_RECVPKTINFO 49 -#define IPV6_PKTINFO 50 -#define IPV6_RECVHOPLIMIT 51 -#define IPV6_HOPLIMIT 52 -#define IPV6_RECVHOPOPTS 53 -#define IPV6_HOPOPTS 54 -#define IPV6_RTHDRDSTOPTS 55 -#define IPV6_RECVRTHDR 56 -#define IPV6_RTHDR 57 -#define IPV6_RECVDSTOPTS 58 -#define IPV6_DSTOPTS 59 -#define IPV6_RECVPATHMTU 60 -#define IPV6_PATHMTU 61 -#define IPV6_DONTFRAG 62 -#define IPV6_RECVTCLASS 66 -#define IPV6_TCLASS 67 -#define IPV6_AUTOFLOWLABEL 70 -#define IPV6_ADDR_PREFERENCES 72 -#define IPV6_MINHOPCOUNT 73 -#define IPV6_ORIGDSTADDR 74 -#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR -#define IPV6_TRANSPARENT 75 -#define IPV6_UNICAST_IF 76 -#define IPV6_RECVFRAGSIZE 77 -#define IPV6_FREEBIND 78 - -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#define IPV6_RXHOPOPTS IPV6_HOPOPTS -#define IPV6_RXDSTOPTS IPV6_DSTOPTS - -#define IPV6_PMTUDISC_DONT 0 -#define IPV6_PMTUDISC_WANT 1 -#define IPV6_PMTUDISC_DO 2 -#define IPV6_PMTUDISC_PROBE 3 -#define IPV6_PMTUDISC_INTERFACE 4 -#define IPV6_PMTUDISC_OMIT 5 - -#define IPV6_PREFER_SRC_TMP 0x0001 -#define IPV6_PREFER_SRC_PUBLIC 0x0002 -#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 -#define IPV6_PREFER_SRC_COA 0x0004 -#define IPV6_PREFER_SRC_HOME 0x0400 -#define IPV6_PREFER_SRC_CGA 0x0008 -#define IPV6_PREFER_SRC_NONCGA 0x0800 - -#define IPV6_RTHDR_LOOSE 0 -#define IPV6_RTHDR_STRICT 1 - -#define IPV6_RTHDR_TYPE_0 0 - -#define __UAPI_DEF_IN_ADDR 0 -#define __UAPI_DEF_IN_IPPROTO 0 -#define __UAPI_DEF_IN_PKTINFO 0 -#define __UAPI_DEF_IP_MREQ 0 -#define __UAPI_DEF_SOCKADDR_IN 0 -#define __UAPI_DEF_IN_CLASS 0 -#define __UAPI_DEF_IN6_ADDR 0 -#define __UAPI_DEF_IN6_ADDR_ALT 0 -#define __UAPI_DEF_SOCKADDR_IN6 0 -#define __UAPI_DEF_IPV6_MREQ 0 -#define __UAPI_DEF_IPPROTO_V6 0 -#define __UAPI_DEF_IPV6_OPTIONS 0 -#define __UAPI_DEF_IN6_PKTINFO 0 -#define __UAPI_DEF_IP6_MTUINFO 0 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/poll.h b/lib/libc/include/wasm-wasi-musl/poll.h deleted file mode 100644 index 00e2537ae0826f14b2e53c9b93389fb8430bbfd0..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/poll.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _POLL_H -#define _POLL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define POLLIN 0x001 -#define POLLPRI 0x002 -#define POLLOUT 0x004 -#define POLLERR 0x008 -#define POLLHUP 0x010 -#define POLLNVAL 0x020 -#define POLLRDNORM 0x040 -#define POLLRDBAND 0x080 -#ifndef POLLWRNORM -#define POLLWRNORM 0x100 -#define POLLWRBAND 0x200 -#endif -#ifndef POLLMSG -#define POLLMSG 0x400 -#define POLLRDHUP 0x2000 -#endif -#else -#include <__header_poll.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef unsigned long nfds_t; -#else -#include <__typedef_nfds_t.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct pollfd { - int fd; - short events; - short revents; -}; -#else -#include <__struct_pollfd.h> -#endif - -int poll (struct pollfd *, nfds_t, int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_time_t -#define __NEED_struct_timespec -#define __NEED_sigset_t -#include -int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); -#endif - -#if _REDIR_TIME64 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__REDIR(ppoll, __ppoll_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/pthread.h b/lib/libc/include/wasm-wasi-musl/pthread.h deleted file mode 100644 index 111c1fbf8c1c0c4ec57dddf6409d6f30e92dc2d9..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/pthread.h +++ /dev/null @@ -1,267 +0,0 @@ -#ifndef _PTHREAD_H -#define _PTHREAD_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_time_t -#define __NEED_clockid_t -#define __NEED_struct_timespec -#define __NEED_sigset_t -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t -#define __NEED_size_t - -#include - -#include -#include - -#define PTHREAD_CREATE_JOINABLE 0 -#define PTHREAD_CREATE_DETACHED 1 - -#define PTHREAD_MUTEX_NORMAL 0 -#define PTHREAD_MUTEX_DEFAULT 0 -#define PTHREAD_MUTEX_RECURSIVE 1 -#define PTHREAD_MUTEX_ERRORCHECK 2 - -#define PTHREAD_MUTEX_STALLED 0 -#define PTHREAD_MUTEX_ROBUST 1 - -#define PTHREAD_PRIO_NONE 0 -#define PTHREAD_PRIO_INHERIT 1 -#define PTHREAD_PRIO_PROTECT 2 - -#define PTHREAD_INHERIT_SCHED 0 -#define PTHREAD_EXPLICIT_SCHED 1 - -#define PTHREAD_SCOPE_SYSTEM 0 -#define PTHREAD_SCOPE_PROCESS 1 - -#define PTHREAD_PROCESS_PRIVATE 0 -#define PTHREAD_PROCESS_SHARED 1 - - -#define PTHREAD_MUTEX_INITIALIZER {{{0}}} -#define PTHREAD_RWLOCK_INITIALIZER {{{0}}} -#define PTHREAD_COND_INITIALIZER {{{0}}} -#define PTHREAD_ONCE_INIT 0 - - -#define PTHREAD_CANCEL_ENABLE 0 -#define PTHREAD_CANCEL_DISABLE 1 -#define PTHREAD_CANCEL_MASKED 2 - -#define PTHREAD_CANCEL_DEFERRED 0 -#define PTHREAD_CANCEL_ASYNCHRONOUS 1 - -#define PTHREAD_CANCELED ((void *)-1) - - -#define PTHREAD_BARRIER_SERIAL_THREAD (-1) - - -#define PTHREAD_NULL ((pthread_t)0) - - -#ifdef __wasilibc_unmodified_upstream -int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); -int pthread_detach(pthread_t); -_Noreturn void pthread_exit(void *); -int pthread_join(pthread_t, void **); -#else -#if defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); -int pthread_detach(pthread_t); -int pthread_join(pthread_t, void **); -#else -#define pthread_create(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#define pthread_detach(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#define pthread_join(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#endif -#endif - -#ifdef __GNUC__ -__attribute__((const)) -#endif -pthread_t pthread_self(void); - -int pthread_equal(pthread_t, pthread_t); -#ifndef __cplusplus -#define pthread_equal(x,y) ((x)==(y)) -#endif - -int pthread_setcancelstate(int, int *); -int pthread_setcanceltype(int, int *); -void pthread_testcancel(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no cancellation support. */ -int pthread_cancel(pthread_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict); -int pthread_setschedparam(pthread_t, int, const struct sched_param *); -#endif -int pthread_setschedprio(pthread_t, int); - -int pthread_once(pthread_once_t *, void (*)(void)); - -int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict); -int pthread_mutex_lock(pthread_mutex_t *); -int pthread_mutex_unlock(pthread_mutex_t *); -int pthread_mutex_trylock(pthread_mutex_t *); -int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict); -int pthread_mutex_destroy(pthread_mutex_t *); -int pthread_mutex_consistent(pthread_mutex_t *); - -int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict); -int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict); - -int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict); -int pthread_cond_destroy(pthread_cond_t *); -int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict); -int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict); -int pthread_cond_broadcast(pthread_cond_t *); -int pthread_cond_signal(pthread_cond_t *); - -int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict); -int pthread_rwlock_destroy(pthread_rwlock_t *); -int pthread_rwlock_rdlock(pthread_rwlock_t *); -int pthread_rwlock_tryrdlock(pthread_rwlock_t *); -int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); -int pthread_rwlock_wrlock(pthread_rwlock_t *); -int pthread_rwlock_trywrlock(pthread_rwlock_t *); -int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); -int pthread_rwlock_unlock(pthread_rwlock_t *); - -int pthread_spin_init(pthread_spinlock_t *, int); -int pthread_spin_destroy(pthread_spinlock_t *); -int pthread_spin_lock(pthread_spinlock_t *); -int pthread_spin_trylock(pthread_spinlock_t *); -int pthread_spin_unlock(pthread_spinlock_t *); - -int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned); -int pthread_barrier_destroy(pthread_barrier_t *); -int pthread_barrier_wait(pthread_barrier_t *); - -int pthread_key_create(pthread_key_t *, void (*)(void *)); -int pthread_key_delete(pthread_key_t); -void *pthread_getspecific(pthread_key_t); -int pthread_setspecific(pthread_key_t, const void *); - -int pthread_attr_init(pthread_attr_t *); -int pthread_attr_destroy(pthread_attr_t *); - -int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict); -int pthread_attr_setguardsize(pthread_attr_t *, size_t); -int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict); -int pthread_attr_setstacksize(pthread_attr_t *, size_t); -int pthread_attr_getdetachstate(const pthread_attr_t *, int *); -int pthread_attr_setdetachstate(pthread_attr_t *, int); -int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict); -int pthread_attr_setstack(pthread_attr_t *, void *, size_t); -int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict); -int pthread_attr_setscope(pthread_attr_t *, int); -int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict); -int pthread_attr_setschedpolicy(pthread_attr_t *, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict); -int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict); -#endif -int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict); -int pthread_attr_setinheritsched(pthread_attr_t *, int); - -int pthread_mutexattr_destroy(pthread_mutexattr_t *); -int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_init(pthread_mutexattr_t *); -int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); -int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); -int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); -int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); -int pthread_mutexattr_settype(pthread_mutexattr_t *, int); - -int pthread_condattr_init(pthread_condattr_t *); -int pthread_condattr_destroy(pthread_condattr_t *); -int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); -int pthread_condattr_setpshared(pthread_condattr_t *, int); -int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict); -int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict); - -int pthread_rwlockattr_init(pthread_rwlockattr_t *); -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); -int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); -int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict); - -int pthread_barrierattr_destroy(pthread_barrierattr_t *); -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict); -int pthread_barrierattr_init(pthread_barrierattr_t *); -int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); - -int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); - -int pthread_getconcurrency(void); -int pthread_setconcurrency(int); - -int pthread_getcpuclockid(pthread_t, clockid_t *); - -struct __ptcb { - void (*__f)(void *); - void *__x; - struct __ptcb *__next; -}; - -void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *); -void _pthread_cleanup_pop(struct __ptcb *, int); - -#define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); -#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) - -#ifdef _GNU_SOURCE -struct cpu_set_t; -int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); -int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); -int pthread_getattr_np(pthread_t, pthread_attr_t *); -int pthread_setname_np(pthread_t, const char *); -int pthread_getname_np(pthread_t, char *, size_t); -int pthread_getattr_default_np(pthread_attr_t *); -int pthread_setattr_default_np(const pthread_attr_t *); -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -int pthread_tryjoin_np(pthread_t, void **); -int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); -#else -#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#endif -#endif - -#if _REDIR_TIME64 -__REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64); -__REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64); -__REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64); -__REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64); -#ifdef _GNU_SOURCE -__REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sched.h b/lib/libc/include/wasm-wasi-musl/sched.h deleted file mode 100644 index 407d604af3bed4b2a67a658239606b2d9414ce16..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sched.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef _SCHED_H -#define _SCHED_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_struct_timespec -#define __NEED_pid_t -#define __NEED_time_t - -#ifdef _GNU_SOURCE -#define __NEED_size_t -#endif - -#include - -struct sched_param { - int sched_priority; - int __reserved1; -#if _REDIR_TIME64 - long __reserved2[4]; -#else - struct { - time_t __reserved1; - long __reserved2; - } __reserved2[2]; -#endif - int __reserved3; -}; - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int sched_get_priority_max(int); -int sched_get_priority_min(int); -int sched_getparam(pid_t, struct sched_param *); -int sched_getscheduler(pid_t); -int sched_rr_get_interval(pid_t, struct timespec *); -int sched_setparam(pid_t, const struct sched_param *); -int sched_setscheduler(pid_t, int, const struct sched_param *); -#endif -int sched_yield(void); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 -#define SCHED_BATCH 3 -#define SCHED_IDLE 5 -#define SCHED_DEADLINE 6 -#define SCHED_RESET_ON_FORK 0x40000000 - -#ifdef _GNU_SOURCE -#define CSIGNAL 0x000000ff -#define CLONE_NEWTIME 0x00000080 -#define CLONE_VM 0x00000100 -#define CLONE_FS 0x00000200 -#define CLONE_FILES 0x00000400 -#define CLONE_SIGHAND 0x00000800 -#define CLONE_PIDFD 0x00001000 -#define CLONE_PTRACE 0x00002000 -#define CLONE_VFORK 0x00004000 -#define CLONE_PARENT 0x00008000 -#define CLONE_THREAD 0x00010000 -#define CLONE_NEWNS 0x00020000 -#define CLONE_SYSVSEM 0x00040000 -#define CLONE_SETTLS 0x00080000 -#define CLONE_PARENT_SETTID 0x00100000 -#define CLONE_CHILD_CLEARTID 0x00200000 -#define CLONE_DETACHED 0x00400000 -#define CLONE_UNTRACED 0x00800000 -#define CLONE_CHILD_SETTID 0x01000000 -#define CLONE_NEWCGROUP 0x02000000 -#define CLONE_NEWUTS 0x04000000 -#define CLONE_NEWIPC 0x08000000 -#define CLONE_NEWUSER 0x10000000 -#define CLONE_NEWPID 0x20000000 -#define CLONE_NEWNET 0x40000000 -#define CLONE_IO 0x80000000 -int clone (int (*)(void *), void *, int, void *, ...); -int unshare(int); -int setns(int, int); - -void *memcpy(void *__restrict, const void *__restrict, size_t); -int memcmp(const void *, const void *, size_t); -void *memset (void *, int, size_t); -void *calloc(size_t, size_t); -void free(void *); - -typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; -int __sched_cpucount(size_t, const cpu_set_t *); -int sched_getcpu(void); -int sched_getaffinity(pid_t, size_t, cpu_set_t *); -int sched_setaffinity(pid_t, size_t, const cpu_set_t *); - -#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ - (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) - -#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) -#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) -#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) - -#define __CPU_op_func_S(func, op) \ -static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ - const cpu_set_t *__src1, const cpu_set_t *__src2) \ -{ \ - size_t __i; \ - for (__i=0; __i<__size/sizeof(long); __i++) \ - ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ - op ((unsigned long *)__src2)[__i] ; \ -} - -__CPU_op_func_S(AND, &) -__CPU_op_func_S(OR, |) -__CPU_op_func_S(XOR, ^) - -#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) -#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) -#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) - -#define CPU_COUNT_S(size,set) __sched_cpucount(size,set) -#define CPU_ZERO_S(size,set) memset(set,0,size) -#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) - -#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ - + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) -#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) -#define CPU_FREE(set) free(set) - -#define CPU_SETSIZE 1024 - -#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) -#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) -#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) -#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) -#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) -#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) -#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) -#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) -#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) - -#endif -#endif - -#if _REDIR_TIME64 -__REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/setjmp.h b/lib/libc/include/wasm-wasi-musl/setjmp.h deleted file mode 100644 index b57999ed61e8752f340e0896bdeb19627eb4aabc..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/setjmp.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _SETJMP_H -#define _SETJMP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifndef __wasilibc_unmodified_upstream -/* WASI has no setjmp */ -#if !defined(__wasm_exception_handling__) -#error Setjmp/longjmp support requires Exception handling support, which is [not yet standardized](https://github.com/WebAssembly/proposals?tab=readme-ov-file#phase-3---implementation-phase-cg--wg). To enable it, compile with `-mllvm -wasm-enable-sjlj` and use an engine that implements the Exception handling proposal. -#endif -#endif -#include - -typedef struct __jmp_buf_tag { - __jmp_buf __jb; - unsigned long __fl; - unsigned long __ss[128/sizeof(long)]; -} jmp_buf[1]; - -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) -#define __setjmp_attr __attribute__((__returns_twice__)) -#else -#define __setjmp_attr -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -typedef jmp_buf sigjmp_buf; -int sigsetjmp (sigjmp_buf, int) __setjmp_attr; -_Noreturn void siglongjmp (sigjmp_buf, int); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -int _setjmp (jmp_buf) __setjmp_attr; -_Noreturn void _longjmp (jmp_buf, int); -#endif - -int setjmp (jmp_buf) __setjmp_attr; -_Noreturn void longjmp (jmp_buf, int); - -#define setjmp setjmp - -#undef __setjmp_attr - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/signal.h b/lib/libc/include/wasm-wasi-musl/signal.h deleted file mode 100644 index 75b5e55284f56a4b1ee4d2a32faee77830858265..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/signal.h +++ /dev/null @@ -1,339 +0,0 @@ -#ifndef _WASI_EMULATED_SIGNAL -#error "wasm lacks signal support; to enable minimal signal emulation, \ -compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal" -#else -#ifndef _SIGNAL_H -#define _SIGNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef __wasilibc_unmodified_upstream /* WASI has no ucontext support */ -#ifdef _GNU_SOURCE -#define __ucontext ucontext -#endif - -#define __NEED_size_t -#define __NEED_pid_t -#define __NEED_uid_t -#define __NEED_struct_timespec -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_sigset_t - -#include - -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 - -#define SI_ASYNCNL (-60) -#define SI_TKILL (-6) -#define SI_SIGIO (-5) -#define SI_ASYNCIO (-4) -#define SI_MESGQ (-3) -#define SI_TIMER (-2) -#define SI_QUEUE (-1) -#define SI_USER 0 -#define SI_KERNEL 128 - -typedef struct sigaltstack stack_t; -#endif - -#endif - -#include - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ -#define SIG_HOLD ((void (*)(int)) 2) - -#define FPE_INTDIV 1 -#define FPE_INTOVF 2 -#define FPE_FLTDIV 3 -#define FPE_FLTOVF 4 -#define FPE_FLTUND 5 -#define FPE_FLTRES 6 -#define FPE_FLTINV 7 -#define FPE_FLTSUB 8 - -#define ILL_ILLOPC 1 -#define ILL_ILLOPN 2 -#define ILL_ILLADR 3 -#define ILL_ILLTRP 4 -#define ILL_PRVOPC 5 -#define ILL_PRVREG 6 -#define ILL_COPROC 7 -#define ILL_BADSTK 8 - -#define SEGV_MAPERR 1 -#define SEGV_ACCERR 2 -#define SEGV_BNDERR 3 -#define SEGV_PKUERR 4 -#define SEGV_MTEAERR 8 -#define SEGV_MTESERR 9 - -#define BUS_ADRALN 1 -#define BUS_ADRERR 2 -#define BUS_OBJERR 3 -#define BUS_MCEERR_AR 4 -#define BUS_MCEERR_AO 5 - -#define CLD_EXITED 1 -#define CLD_KILLED 2 -#define CLD_DUMPED 3 -#define CLD_TRAPPED 4 -#define CLD_STOPPED 5 -#define CLD_CONTINUED 6 - -union sigval { - int sival_int; - void *sival_ptr; -}; - -typedef struct { -#ifdef __SI_SWAP_ERRNO_CODE - int si_signo, si_code, si_errno; -#else - int si_signo, si_errno, si_code; -#endif - union { - char __pad[128 - 2*sizeof(int) - sizeof(long)]; - struct { - union { - struct { - pid_t si_pid; - uid_t si_uid; - } __piduid; - struct { - int si_timerid; - int si_overrun; - } __timer; - } __first; - union { - union sigval si_value; - struct { - int si_status; - clock_t si_utime, si_stime; - } __sigchld; - } __second; - } __si_common; - struct { - void *si_addr; - short si_addr_lsb; - union { - struct { - void *si_lower; - void *si_upper; - } __addr_bnd; - unsigned si_pkey; - } __first; - } __sigfault; - struct { - long si_band; - int si_fd; - } __sigpoll; - struct { - void *si_call_addr; - int si_syscall; - unsigned si_arch; - } __sigsys; - } __si_fields; -} siginfo_t; -#define si_pid __si_fields.__si_common.__first.__piduid.si_pid -#define si_uid __si_fields.__si_common.__first.__piduid.si_uid -#define si_status __si_fields.__si_common.__second.__sigchld.si_status -#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime -#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime -#define si_value __si_fields.__si_common.__second.si_value -#define si_addr __si_fields.__sigfault.si_addr -#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb -#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower -#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper -#define si_pkey __si_fields.__sigfault.__first.si_pkey -#define si_band __si_fields.__sigpoll.si_band -#define si_fd __si_fields.__sigpoll.si_fd -#define si_timerid __si_fields.__si_common.__first.__timer.si_timerid -#define si_overrun __si_fields.__si_common.__first.__timer.si_overrun -#define si_ptr si_value.sival_ptr -#define si_int si_value.sival_int -#define si_call_addr __si_fields.__sigsys.si_call_addr -#define si_syscall __si_fields.__sigsys.si_syscall -#define si_arch __si_fields.__sigsys.si_arch - -struct sigaction { - union { - void (*sa_handler)(int); - void (*sa_sigaction)(int, siginfo_t *, void *); - } __sa_handler; - sigset_t sa_mask; - int sa_flags; - void (*sa_restorer)(void); -}; -#define sa_handler __sa_handler.sa_handler -#define sa_sigaction __sa_handler.sa_sigaction - -#define SA_UNSUPPORTED 0x00000400 -#define SA_EXPOSE_TAGBITS 0x00000800 - -struct sigevent { - union sigval sigev_value; - int sigev_signo; - int sigev_notify; - union { - char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; - pid_t sigev_notify_thread_id; - struct { - void (*sigev_notify_function)(union sigval); - pthread_attr_t *sigev_notify_attributes; - } __sev_thread; - } __sev_fields; -}; - -#define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id -#define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function -#define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes - -#define SIGEV_SIGNAL 0 -#define SIGEV_NONE 1 -#define SIGEV_THREAD 2 -#define SIGEV_THREAD_ID 4 -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ -int __libc_current_sigrtmin(void); -int __libc_current_sigrtmax(void); - -#define SIGRTMIN (__libc_current_sigrtmin()) -#define SIGRTMAX (__libc_current_sigrtmax()) -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ -int kill(pid_t, int); - -int sigemptyset(sigset_t *); -int sigfillset(sigset_t *); -int sigaddset(sigset_t *, int); -int sigdelset(sigset_t *, int); -int sigismember(const sigset_t *, int); - -int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); -int sigsuspend(const sigset_t *); -int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); -int sigpending(sigset_t *); -int sigwait(const sigset_t *__restrict, int *__restrict); -int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); -int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); -int sigqueue(pid_t, int, union sigval); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ -int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); -int pthread_kill(pthread_t, int); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ -void psiginfo(const siginfo_t *, const char *); -#endif -void psignal(int, const char *); - -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -int killpg(pid_t, int); -int sigaltstack(const stack_t *__restrict, stack_t *__restrict); -int sighold(int); -int sigignore(int); -int siginterrupt(int, int); -int sigpause(int); -int sigrelse(int); -void (*sigset(int, void (*)(int)))(int); -#define TRAP_BRKPT 1 -#define TRAP_TRACE 2 -#define TRAP_BRANCH 3 -#define TRAP_HWBKPT 4 -#define TRAP_UNK 5 -#define POLL_IN 1 -#define POLL_OUT 2 -#define POLL_MSG 3 -#define POLL_ERR 4 -#define POLL_PRI 5 -#define POLL_HUP 6 -#define SS_ONSTACK 1 -#define SS_DISABLE 2 -#define SS_AUTODISARM (1U << 31) -#define SS_FLAG_BITS SS_AUTODISARM -#endif -#endif - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define NSIG _NSIG -typedef void (*sig_t)(int); - -#define SYS_SECCOMP 1 -#define SYS_USER_DISPATCH 2 -#endif - -#ifdef _GNU_SOURCE -typedef void (*sighandler_t)(int); -void (*bsd_signal(int, void (*)(int)))(int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ -int sigisemptyset(const sigset_t *); -int sigorset (sigset_t *, const sigset_t *, const sigset_t *); -int sigandset(sigset_t *, const sigset_t *, const sigset_t *); - -#define SA_NOMASK SA_NODEFER -#define SA_ONESHOT SA_RESETHAND -#endif -#endif - -#ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ -#define SIG_ERR ((void (*)(int))-1) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN ((void (*)(int)) 1) -#else -void __SIG_ERR(int); -void __SIG_IGN(int); -#define SIG_ERR (__SIG_ERR) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN (__SIG_IGN) -#endif - -#ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ -typedef int sig_atomic_t; -#else -typedef long sig_atomic_t; -#endif - -void (*signal(int, void (*)(int)))(int); -int raise(int); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ -#if _REDIR_TIME64 -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -__REDIR(sigtimedwait, __sigtimedwait_time64); -#endif -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/stdio.h b/lib/libc/include/wasm-wasi-musl/stdio.h deleted file mode 100644 index d63d739f0ff0ae3333bf3aac972bf80faad9a104..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/stdio.h +++ /dev/null @@ -1,254 +0,0 @@ -#ifndef _STDIO_H -#define _STDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_FILE -#define __NEED___isoc_va_list -#define __NEED_size_t - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#if __STDC_VERSION__ < 201112L -#define __NEED_struct__IO_FILE -#endif -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_ssize_t -#define __NEED_off_t -#define __NEED_va_list -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#undef EOF -#define EOF (-1) - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#else -#include <__seek.h> -#endif - -#define _IOFBF 0 -#define _IOLBF 1 -#define _IONBF 2 - -#define BUFSIZ 1024 -#define FILENAME_MAX 4096 -#define FOPEN_MAX 1000 -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#define TMP_MAX 10000 -#define L_tmpnam 20 -#endif - -typedef union _G_fpos64_t { - char __opaque[16]; - long long __lldata; - double __align; -} fpos_t; - -extern FILE *const stdin; -extern FILE *const stdout; -extern FILE *const stderr; - -#define stdin (stdin) -#define stdout (stdout) -#define stderr (stderr) - -FILE *fopen(const char *__restrict, const char *__restrict); -FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); -int fclose(FILE *); - -int remove(const char *); -int rename(const char *, const char *); - -int feof(FILE *); -int ferror(FILE *); -int fflush(FILE *); -void clearerr(FILE *); - -int fseek(FILE *, long, int); -long ftell(FILE *); -void rewind(FILE *); - -int fgetpos(FILE *__restrict, fpos_t *__restrict); -int fsetpos(FILE *, const fpos_t *); - -size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); -size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); - -int fgetc(FILE *); -int getc(FILE *); -int getchar(void); -int ungetc(int, FILE *); - -int fputc(int, FILE *); -int putc(int, FILE *); -int putchar(int); - -char *fgets(char *__restrict, int, FILE *__restrict); -#if __STDC_VERSION__ < 201112L -#ifdef __wasilibc_unmodified_upstream /* gets is obsolete */ -char *gets(char *); -#else -char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI"))); -#endif -#endif - -int fputs(const char *__restrict, FILE *__restrict); -int puts(const char *); - -int printf(const char *__restrict, ...); -int fprintf(FILE *__restrict, const char *__restrict, ...); -int sprintf(char *__restrict, const char *__restrict, ...); -int snprintf(char *__restrict, size_t, const char *__restrict, ...); - -int vprintf(const char *__restrict, __isoc_va_list); -int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); -int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); -int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); - -int scanf(const char *__restrict, ...); -int fscanf(FILE *__restrict, const char *__restrict, ...); -int sscanf(const char *__restrict, const char *__restrict, ...); -int vscanf(const char *__restrict, __isoc_va_list); -int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); -int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); - -void perror(const char *); - -int setvbuf(FILE *__restrict, char *__restrict, int, size_t); -void setbuf(FILE *__restrict, char *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -char *tmpnam(char *); -FILE *tmpfile(void); -#else -char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI"))); -FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI"))); -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -FILE *fmemopen(void *__restrict, size_t, const char *__restrict); -FILE *open_memstream(char **, size_t *); -FILE *fdopen(int, const char *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no popen */ -FILE *popen(const char *, const char *); -int pclose(FILE *); -#endif -int fileno(FILE *); -int fseeko(FILE *, off_t, int); -off_t ftello(FILE *); -int dprintf(int, const char *__restrict, ...); -int vdprintf(int, const char *__restrict, __isoc_va_list); -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -void flockfile(FILE *); -int ftrylockfile(FILE *); -void funlockfile(FILE *); -#endif -int getc_unlocked(FILE *); -int getchar_unlocked(void); -int putc_unlocked(int, FILE *); -int putchar_unlocked(int); -ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); -ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); -int renameat(int, const char *, int, const char *); -char *ctermid(char *); -#define L_ctermid 20 -#endif - - -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define P_tmpdir "/tmp" -char *tempnam(const char *, const char *); -#endif -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define L_cuserid 20 -char *cuserid(char *); -void setlinebuf(FILE *); -void setbuffer(FILE *, char *, size_t); -int fgetc_unlocked(FILE *); -int fputc_unlocked(int, FILE *); -int fflush_unlocked(FILE *); -size_t fread_unlocked(void *, size_t, size_t, FILE *); -size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); -void clearerr_unlocked(FILE *); -int feof_unlocked(FILE *); -int ferror_unlocked(FILE *); -int fileno_unlocked(FILE *); -int getw(FILE *); -int putw(int, FILE *); -char *fgetln(FILE *, size_t *); -int asprintf(char **, const char *, ...); -int vasprintf(char **, const char *, __isoc_va_list); -#endif - -#ifdef _GNU_SOURCE -char *fgets_unlocked(char *, int, FILE *); -int fputs_unlocked(const char *, FILE *); - -typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); -typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); -typedef int (cookie_seek_function_t)(void *, off_t *, int); -typedef int (cookie_close_function_t)(void *); - -typedef struct _IO_cookie_io_functions_t { - cookie_read_function_t *read; - cookie_write_function_t *write; - cookie_seek_function_t *seek; - cookie_close_function_t *close; -} cookie_io_functions_t; - -FILE *fopencookie(void *, const char *, cookie_io_functions_t); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#define tmpfile64 tmpfile -#endif -#define fopen64 fopen -#define freopen64 freopen -#define fseeko64 fseeko -#define ftello64 ftello -#define fgetpos64 fgetpos -#define fsetpos64 fsetpos -#define fpos64_t fpos_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/stdlib.h b/lib/libc/include/wasm-wasi-musl/stdlib.h deleted file mode 100644 index c5b6cd2d980a058b613cd90f9fecc9ff7c0fd8c7..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/stdlib.h +++ /dev/null @@ -1,217 +0,0 @@ -#ifndef _STDLIB_H -#define _STDLIB_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__functions_malloc.h> -#include <__header_stdlib.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define __NEED_size_t -#define __NEED_wchar_t - -#include - -int atoi (const char *); -long atol (const char *); -long long atoll (const char *); -double atof (const char *); - -float strtof (const char *__restrict, char **__restrict); -double strtod (const char *__restrict, char **__restrict); -long double strtold (const char *__restrict, char **__restrict); - -long strtol (const char *__restrict, char **__restrict, int); -unsigned long strtoul (const char *__restrict, char **__restrict, int); -long long strtoll (const char *__restrict, char **__restrict, int); -unsigned long long strtoull (const char *__restrict, char **__restrict, int); - -int rand (void); -void srand (unsigned); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *malloc (size_t); -void *calloc (size_t, size_t); -void *realloc (void *, size_t); -void free (void *); -#endif -void *aligned_alloc(size_t, size_t); - -_Noreturn void abort (void); -int atexit (void (*) (void)); -_Noreturn void exit (int); -_Noreturn void _Exit (int); -int at_quick_exit (void (*) (void)); -_Noreturn void quick_exit (int); - -char *getenv (const char *); - -int system (const char *); - -void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); -void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); - -int abs (int); -long labs (long); -long long llabs (long long); - -typedef struct { int quot, rem; } div_t; -typedef struct { long quot, rem; } ldiv_t; -typedef struct { long long quot, rem; } lldiv_t; - -div_t div (int, int); -ldiv_t ldiv (long, long); -lldiv_t lldiv (long long, long long); - -int mblen (const char *, size_t); -int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); -int wctomb (char *, wchar_t); -size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); -size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -size_t __ctype_get_mb_cur_max(void); -#define MB_CUR_MAX (__ctype_get_mb_cur_max()) - -#define RAND_MAX (0x7fffffff) - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ -#define WNOHANG 1 -#define WUNTRACED 2 - -#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) -#define WTERMSIG(s) ((s) & 0x7f) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00) -#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) -#endif - -int posix_memalign (void **, size_t, size_t); -int setenv (const char *, const char *, int); -int unsetenv (const char *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -int mkstemp (char *); -int mkostemp (char *, int); -char *mkdtemp (char *); -#endif -int getsubopt (char **, char *const *, char **); -int rand_r (unsigned *); - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *realpath (const char *__restrict, char *__restrict); -long int random (void); -void srandom (unsigned int); -char *initstate (unsigned int, char *, size_t); -char *setstate (char *); -int putenv (char *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ -int posix_openpt (int); -int grantpt (int); -int unlockpt (int); -char *ptsname (int); -#endif -char *l64a (long); -long a64l (const char *); -void setkey (const char *); -double drand48 (void); -double erand48 (unsigned short [3]); -long int lrand48 (void); -long int nrand48 (unsigned short [3]); -long mrand48 (void); -long jrand48 (unsigned short [3]); -void srand48 (long); -unsigned short *seed48 (unsigned short [3]); -void lcong48 (unsigned short [7]); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#include -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -char *mktemp (char *); -int mkstemps (char *, int); -int mkostemps (char *, int, int); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -void *valloc (size_t); -void *memalign(size_t, size_t); -int getloadavg(double *, int); -#endif -int clearenv(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ -#define WCOREDUMP(s) ((s) & 0x80) -#define WIFCONTINUED(s) ((s) == 0xffff) -void *reallocarray (void *, size_t, size_t); -void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); -#endif -#endif - -#ifdef _GNU_SOURCE -#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ -int ptsname_r(int, char *, size_t); -#endif -char *ecvt(double, int, int *, int *); -char *fcvt(double, int, int *, int *); -char *gcvt(double, int, char *); -char *secure_getenv(const char *); -struct __locale_struct; -float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); -double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); -long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#if defined(_LARGEFILE64_SOURCE) -#define mkstemp64 mkstemp -#define mkostemp64 mkostemp -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define mkstemps64 mkstemps -#define mkostemps64 mkostemps -#endif -#endif -#endif - -#ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */ -#else -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#include -uint32_t arc4random(void); -void arc4random_buf(void *, size_t); -uint32_t arc4random_uniform(uint32_t); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/string.h b/lib/libc/include/wasm-wasi-musl/string.h deleted file mode 100644 index 7b3c3b9415f23a733fbe5d9632a915e7e6d9e17b..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/string.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_string.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define __NEED_size_t -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_locale_t -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *memcpy (void *__restrict, const void *__restrict, size_t); -void *memmove (void *, const void *, size_t); -void *memset (void *, int, size_t); -#endif -int memcmp (const void *, const void *, size_t); -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *memchr (const void *, int, size_t); -#endif - -char *strcpy (char *__restrict, const char *__restrict); -char *strncpy (char *__restrict, const char *__restrict, size_t); - -char *strcat (char *__restrict, const char *__restrict); -char *strncat (char *__restrict, const char *__restrict, size_t); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -int strcmp (const char *, const char *); -#endif -int strncmp (const char *, const char *, size_t); - -int strcoll (const char *, const char *); -size_t strxfrm (char *__restrict, const char *__restrict, size_t); - -char *strchr (const char *, int); -char *strrchr (const char *, int); - -size_t strcspn (const char *, const char *); -size_t strspn (const char *, const char *); -char *strpbrk (const char *, const char *); -char *strstr (const char *, const char *); -char *strtok (char *__restrict, const char *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -size_t strlen (const char *); -#endif - -char *strerror (int); - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#include -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); -int strerror_r (int, char *, size_t); -char *stpcpy(char *__restrict, const char *__restrict); -char *stpncpy(char *__restrict, const char *__restrict, size_t); -size_t strnlen (const char *, size_t); -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -char *strdup (const char *); -#endif -char *strndup (const char *, size_t); -char *strsignal(int); -char *strerror_l (int, locale_t); -int strcoll_l (const char *, const char *, locale_t); -size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); -void *memmem(const void *, size_t, const void *, size_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -void *memccpy (void *__restrict, const void *__restrict, int, size_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -char *strsep(char **, const char *); -size_t strlcat (char *, const char *, size_t); -size_t strlcpy (char *, const char *, size_t); -void explicit_bzero (void *, size_t); -#endif - -#ifdef _GNU_SOURCE -#define strdupa(x) strcpy(alloca(strlen(x)+1),x) -int strverscmp (const char *, const char *); -char *strchrnul(const char *, int); -char *strcasestr(const char *, const char *); -void *memrchr(const void *, int, size_t); -void *mempcpy(void *, const void *, size_t); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/ioctl.h b/lib/libc/include/wasm-wasi-musl/sys/ioctl.h deleted file mode 100644 index cf3acb3ad842af6b30b01ebb74b1c8a6b2ac8596..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/ioctl.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_struct_winsize - -#include -#include - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 -#define N_GIGASET_M101 16 -#define N_SLCAN 17 -#define N_PPS 18 -#define N_V253 19 -#define N_CAIF 20 -#define N_GSM0710 21 -#define N_TI_WL 22 -#define N_TRACESINK 23 -#define N_TRACEROUTER 24 -#define N_NCI 25 -#define N_SPEAKUP 26 -#define N_NULL 27 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 1 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 - -int ioctl (int, int, ...); - -#ifdef __cplusplus -} -#endif -#else -#include <__header_sys_ioctl.h> -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/mman.h b/lib/libc/include/wasm-wasi-musl/sys/mman.h deleted file mode 100644 index 335ba2d714be677a29df7bb53bddd5acd4c37131..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/mman.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef _WASI_EMULATED_MMAN -#error "WASI lacks a true mmap; to enable minimal mmap emulation, \ -compile with -D_WASI_EMULATED_MMAN and link with -lwasi-emulated-mman" -#else -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_mode_t -#define __NEED_size_t -#define __NEED_off_t - -#if defined(_GNU_SOURCE) -#define __NEED_ssize_t -#endif - -#include - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_SHARED_VALIDATE 0x03 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_SYNC 0x80000 -#define MAP_FIXED_NOREPLACE 0x100000 -#define MAP_FILE 0 - -#define MAP_HUGE_SHIFT 26 -#define MAP_HUGE_MASK 0x3f -#define MAP_HUGE_16KB (14 << 26) -#define MAP_HUGE_64KB (16 << 26) -#define MAP_HUGE_512KB (19 << 26) -#define MAP_HUGE_1MB (20 << 26) -#define MAP_HUGE_2MB (21 << 26) -#define MAP_HUGE_8MB (23 << 26) -#define MAP_HUGE_16MB (24 << 26) -#define MAP_HUGE_32MB (25 << 26) -#define MAP_HUGE_256MB (28 << 26) -#define MAP_HUGE_512MB (29 << 26) -#define MAP_HUGE_1GB (30 << 26) -#define MAP_HUGE_2GB (31 << 26) -#define MAP_HUGE_16GB (34U << 26) - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -#define POSIX_MADV_NORMAL 0 -#define POSIX_MADV_RANDOM 1 -#define POSIX_MADV_SEQUENTIAL 2 -#define POSIX_MADV_WILLNEED 3 -#define POSIX_MADV_DONTNEED 4 - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MADV_NORMAL 0 -#define MADV_RANDOM 1 -#define MADV_SEQUENTIAL 2 -#define MADV_WILLNEED 3 -#define MADV_DONTNEED 4 -#define MADV_FREE 8 -#define MADV_REMOVE 9 -#define MADV_DONTFORK 10 -#define MADV_DOFORK 11 -#define MADV_MERGEABLE 12 -#define MADV_UNMERGEABLE 13 -#define MADV_HUGEPAGE 14 -#define MADV_NOHUGEPAGE 15 -#define MADV_DONTDUMP 16 -#define MADV_DODUMP 17 -#define MADV_WIPEONFORK 18 -#define MADV_KEEPONFORK 19 -#define MADV_COLD 20 -#define MADV_PAGEOUT 21 -#define MADV_HWPOISON 100 -#define MADV_SOFT_OFFLINE 101 -#endif - -#ifdef _GNU_SOURCE -#define MREMAP_MAYMOVE 1 -#define MREMAP_FIXED 2 -#define MREMAP_DONTUNMAP 4 - -#define MLOCK_ONFAULT 0x01 - -#define MFD_CLOEXEC 0x0001U -#define MFD_ALLOW_SEALING 0x0002U -#define MFD_HUGETLB 0x0004U -#endif - -#include - -void *mmap (void *, size_t, int, int, int, off_t); -int munmap (void *, size_t); - -int mprotect (void *, size_t, int); -int msync (void *, size_t, int); - -int posix_madvise (void *, size_t, int); - -int mlock (const void *, size_t); -int munlock (const void *, size_t); -int mlockall (int); -int munlockall (void); - -#ifdef _GNU_SOURCE -void *mremap (void *, size_t, size_t, int, ...); -int remap_file_pages (void *, size_t, int, size_t, int); -int memfd_create (const char *, unsigned); -int mlock2 (const void *, size_t, unsigned); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int madvise (void *, size_t, int); -int mincore (void *, size_t, unsigned char *); -#endif - -int shm_open (const char *, int, mode_t); -int shm_unlink (const char *); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define mmap64 mmap -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/param.h b/lib/libc/include/wasm-wasi-musl/sys/param.h deleted file mode 100644 index 01411725e42e1c5e981b36b4d91a1053c538572a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/param.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _SYS_PARAM_H -#define _SYS_PARAM_H - -#define MAXSYMLINKS 20 -#define MAXHOSTNAMELEN 64 -#define MAXNAMLEN 255 -#define MAXPATHLEN 4096 -#define NBBY 8 -#define NGROUPS 32 -#define CANBSIZ 255 -#define NOFILE 256 -#define NCARGS 131072 -#define DEV_BSIZE 512 -#define NOGROUP (-1) - -#undef MIN -#undef MAX -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) - -#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) -#define setbit(x,i) __bitop(x,i,|=) -#define clrbit(x,i) __bitop(x,i,&=~) -#define isset(x,i) __bitop(x,i,&) -#define isclr(x,i) !isset(x,i) - -#define howmany(n,d) (((n)+((d)-1))/(d)) -#define roundup(n,d) (howmany(n,d)*(d)) -#define powerof2(n) !(((n)-1) & (n)) - -#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) -#include -#endif -#include -#include - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/random.h b/lib/libc/include/wasm-wasi-musl/sys/random.h deleted file mode 100644 index 51cf9d7ffb4bd9f33cb41f16f6113fb94e762595..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/random.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _SYS_RANDOM_H -#define _SYS_RANDOM_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no getrandom, but it does have getentropy */ -#define __NEED_size_t -#define __NEED_ssize_t -#include - -#define GRND_NONBLOCK 0x0001 -#define GRND_RANDOM 0x0002 -#define GRND_INSECURE 0x0004 - -ssize_t getrandom(void *, size_t, unsigned); -#else -#define __NEED_size_t -#include - -int getentropy(void *, size_t); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/resource.h b/lib/libc/include/wasm-wasi-musl/sys/resource.h deleted file mode 100644 index 6c3a7ff2aa2f0306fb63996d84365278c5aabac4..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/resource.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef _WASI_EMULATED_PROCESS_CLOCKS -#error WASI lacks process-associated clocks; to enable emulation of the `getrusage` function using \ -the wall clock, which isn't sensitive to whether the program is running or suspended, \ -compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks -#else -#ifndef _SYS_RESOURCE_H -#define _SYS_RESOURCE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_id_t - -#ifdef _GNU_SOURCE -#define __NEED_pid_t -#endif - -#include -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef unsigned long long rlim_t; - -struct rlimit { - rlim_t rlim_cur; - rlim_t rlim_max; -}; - -struct rusage { - struct timeval ru_utime; - struct timeval ru_stime; - /* linux extentions, but useful */ - long ru_maxrss; - long ru_ixrss; - long ru_idrss; - long ru_isrss; - long ru_minflt; - long ru_majflt; - long ru_nswap; - long ru_inblock; - long ru_oublock; - long ru_msgsnd; - long ru_msgrcv; - long ru_nsignals; - long ru_nvcsw; - long ru_nivcsw; - /* room for more... */ - long __reserved[16]; -}; - -int getrlimit (int, struct rlimit *); -int setrlimit (int, const struct rlimit *); -int getrusage (int, struct rusage *); - -int getpriority (int, id_t); -int setpriority (int, id_t, int); - -#ifdef _GNU_SOURCE -int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); -#define prlimit64 prlimit -#endif - -#define PRIO_MIN (-20) -#define PRIO_MAX 20 - -#define PRIO_PROCESS 0 -#define PRIO_PGRP 1 -#define PRIO_USER 2 - -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN (-1) -#define RUSAGE_THREAD 1 - -#define RLIM_INFINITY (~0ULL) -#define RLIM_SAVED_CUR RLIM_INFINITY -#define RLIM_SAVED_MAX RLIM_INFINITY - -#define RLIMIT_CPU 0 -#define RLIMIT_FSIZE 1 -#define RLIMIT_DATA 2 -#define RLIMIT_STACK 3 -#define RLIMIT_CORE 4 -#ifndef RLIMIT_RSS -#define RLIMIT_RSS 5 -#define RLIMIT_NPROC 6 -#define RLIMIT_NOFILE 7 -#define RLIMIT_MEMLOCK 8 -#define RLIMIT_AS 9 -#endif -#define RLIMIT_LOCKS 10 -#define RLIMIT_SIGPENDING 11 -#define RLIMIT_MSGQUEUE 12 -#define RLIMIT_NICE 13 -#define RLIMIT_RTPRIO 14 -#define RLIMIT_RTTIME 15 -#define RLIMIT_NLIMITS 16 - -#define RLIM_NLIMITS RLIMIT_NLIMITS - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define RLIM64_INFINITY RLIM_INFINITY -#define RLIM64_SAVED_CUR RLIM_SAVED_CUR -#define RLIM64_SAVED_MAX RLIM_SAVED_MAX -#define getrlimit64 getrlimit -#define setrlimit64 setrlimit -#define rlimit64 rlimit -#define rlim64_t rlim_t -#endif -#else -#include <__header_sys_resource.h> -#endif - -#if _REDIR_TIME64 -__REDIR(getrusage, __getrusage_time64); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/select.h b/lib/libc/include/wasm-wasi-musl/sys/select.h deleted file mode 100644 index 1c1adfff59a146745231ebbb3d66db402451769e..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/select.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _SYS_SELECT_H -#define _SYS_SELECT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_suseconds_t -#define __NEED_struct_timeval -#define __NEED_struct_timespec -#define __NEED_sigset_t - -#include - -#define FD_SETSIZE 1024 - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef unsigned long fd_mask; -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef struct { - unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; -} fd_set; - -#define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) -#else -#include <__fd_set.h> -#endif - -int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); -int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define NFDBITS (8*(int)sizeof(long)) -#endif -#endif - -#if _REDIR_TIME64 -__REDIR(select, __select_time64); -__REDIR(pselect, __pselect_time64); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/socket.h b/lib/libc/include/wasm-wasi-musl/sys/socket.h deleted file mode 100644 index 29189e39eb841c1c5baab30e30986db990ea67de..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/socket.h +++ /dev/null @@ -1,454 +0,0 @@ -#ifndef _SYS_SOCKET_H -#define _SYS_SOCKET_H - -#include <__wasi_snapshot.h> - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_sys_socket.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_socklen_t -#define __NEED_sa_family_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_pid_t -#define __NEED_gid_t -#define __NEED_struct_iovec - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad1; -#endif - int msg_iovlen; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad1; -#endif - void *msg_control; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad2; -#endif - socklen_t msg_controllen; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad2; -#endif - int msg_flags; -}; - -struct cmsghdr { -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad1; -#endif - socklen_t cmsg_len; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad1; -#endif - int cmsg_level; - int cmsg_type; -}; -#else -#include <__struct_msghdr.h> -#endif - -#ifdef _GNU_SOURCE -struct ucred { - pid_t pid; - uid_t uid; - gid_t gid; -}; - -struct mmsghdr { - struct msghdr msg_hdr; - unsigned int msg_len; -}; - -struct timespec; - -int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); -int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); -#endif - -struct linger { - int l_onoff; - int l_linger; -}; - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#ifndef SOCK_STREAM -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#endif - -#define SOCK_RAW 3 -#define SOCK_RDM 4 -#define SOCK_SEQPACKET 5 -#define SOCK_DCCP 6 -#define SOCK_PACKET 10 - -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 02000000 -#define SOCK_NONBLOCK 04000 -#endif - -#define PF_UNSPEC 0 -#define PF_LOCAL 1 -#define PF_UNIX PF_LOCAL -#define PF_FILE PF_LOCAL -#define PF_INET 2 -#define PF_AX25 3 -#define PF_IPX 4 -#define PF_APPLETALK 5 -#define PF_NETROM 6 -#define PF_BRIDGE 7 -#define PF_ATMPVC 8 -#define PF_X25 9 -#define PF_INET6 10 -#define PF_ROSE 11 -#define PF_DECnet 12 -#define PF_NETBEUI 13 -#define PF_SECURITY 14 -#define PF_KEY 15 -#define PF_NETLINK 16 -#define PF_ROUTE PF_NETLINK -#define PF_PACKET 17 -#define PF_ASH 18 -#define PF_ECONET 19 -#define PF_ATMSVC 20 -#define PF_RDS 21 -#define PF_SNA 22 -#define PF_IRDA 23 -#define PF_PPPOX 24 -#define PF_WANPIPE 25 -#define PF_LLC 26 -#define PF_IB 27 -#define PF_MPLS 28 -#define PF_CAN 29 -#define PF_TIPC 30 -#define PF_BLUETOOTH 31 -#define PF_IUCV 32 -#define PF_RXRPC 33 -#define PF_ISDN 34 -#define PF_PHONET 35 -#define PF_IEEE802154 36 -#define PF_CAIF 37 -#define PF_ALG 38 -#define PF_NFC 39 -#define PF_VSOCK 40 -#define PF_KCM 41 -#define PF_QIPCRTR 42 -#define PF_SMC 43 -#define PF_XDP 44 -#define PF_MAX 45 - -#define AF_UNSPEC PF_UNSPEC -#define AF_LOCAL PF_LOCAL -#define AF_UNIX AF_LOCAL -#define AF_FILE AF_LOCAL -#define AF_INET PF_INET -#define AF_AX25 PF_AX25 -#define AF_IPX PF_IPX -#define AF_APPLETALK PF_APPLETALK -#define AF_NETROM PF_NETROM -#define AF_BRIDGE PF_BRIDGE -#define AF_ATMPVC PF_ATMPVC -#define AF_X25 PF_X25 -#define AF_INET6 PF_INET6 -#define AF_ROSE PF_ROSE -#define AF_DECnet PF_DECnet -#define AF_NETBEUI PF_NETBEUI -#define AF_SECURITY PF_SECURITY -#define AF_KEY PF_KEY -#define AF_NETLINK PF_NETLINK -#define AF_ROUTE PF_ROUTE -#define AF_PACKET PF_PACKET -#define AF_ASH PF_ASH -#define AF_ECONET PF_ECONET -#define AF_ATMSVC PF_ATMSVC -#define AF_RDS PF_RDS -#define AF_SNA PF_SNA -#define AF_IRDA PF_IRDA -#define AF_PPPOX PF_PPPOX -#define AF_WANPIPE PF_WANPIPE -#define AF_LLC PF_LLC -#define AF_IB PF_IB -#define AF_MPLS PF_MPLS -#define AF_CAN PF_CAN -#define AF_TIPC PF_TIPC -#define AF_BLUETOOTH PF_BLUETOOTH -#define AF_IUCV PF_IUCV -#define AF_RXRPC PF_RXRPC -#define AF_ISDN PF_ISDN -#define AF_PHONET PF_PHONET -#define AF_IEEE802154 PF_IEEE802154 -#define AF_CAIF PF_CAIF -#define AF_ALG PF_ALG -#define AF_NFC PF_NFC -#define AF_VSOCK PF_VSOCK -#define AF_KCM PF_KCM -#define AF_QIPCRTR PF_QIPCRTR -#define AF_SMC PF_SMC -#define AF_XDP PF_XDP -#define AF_MAX PF_MAX - -#ifndef SO_DEBUG -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -#define SO_REUSEPORT 15 -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_ACCEPTCONN 30 -#define SO_PEERSEC 31 -#define SO_SNDBUFFORCE 32 -#define SO_RCVBUFFORCE 33 -#define SO_PROTOCOL 38 -#define SO_DOMAIN 39 -#endif - -#ifndef SO_RCVTIMEO -#if __LONG_MAX == 0x7fffffff -#define SO_RCVTIMEO 66 -#define SO_SNDTIMEO 67 -#else -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -#endif -#endif - -#ifndef SO_TIMESTAMP -#if __LONG_MAX == 0x7fffffff -#define SO_TIMESTAMP 63 -#define SO_TIMESTAMPNS 64 -#define SO_TIMESTAMPING 65 -#else -#define SO_TIMESTAMP 29 -#define SO_TIMESTAMPNS 35 -#define SO_TIMESTAMPING 37 -#endif -#endif - -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 - -#define SO_BINDTODEVICE 25 - -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 -#define SO_GET_FILTER SO_ATTACH_FILTER - -#define SO_PEERNAME 28 -#define SCM_TIMESTAMP SO_TIMESTAMP -#define SO_PASSSEC 34 -#define SCM_TIMESTAMPNS SO_TIMESTAMPNS -#define SO_MARK 36 -#define SCM_TIMESTAMPING SO_TIMESTAMPING -#define SO_RXQ_OVFL 40 -#define SO_WIFI_STATUS 41 -#define SCM_WIFI_STATUS SO_WIFI_STATUS -#define SO_PEEK_OFF 42 -#define SO_NOFCS 43 -#define SO_LOCK_FILTER 44 -#define SO_SELECT_ERR_QUEUE 45 -#define SO_BUSY_POLL 46 -#define SO_MAX_PACING_RATE 47 -#define SO_BPF_EXTENSIONS 48 -#define SO_INCOMING_CPU 49 -#define SO_ATTACH_BPF 50 -#define SO_DETACH_BPF SO_DETACH_FILTER -#define SO_ATTACH_REUSEPORT_CBPF 51 -#define SO_ATTACH_REUSEPORT_EBPF 52 -#define SO_CNX_ADVICE 53 -#define SCM_TIMESTAMPING_OPT_STATS 54 -#define SO_MEMINFO 55 -#define SO_INCOMING_NAPI_ID 56 -#define SO_COOKIE 57 -#define SCM_TIMESTAMPING_PKTINFO 58 -#define SO_PEERGROUPS 59 -#define SO_ZEROCOPY 60 -#define SO_TXTIME 61 -#define SCM_TXTIME SO_TXTIME -#define SO_BINDTOIFINDEX 62 -#define SO_DETACH_REUSEPORT_BPF 68 -#define SO_PREFER_BUSY_POLL 69 -#define SO_BUSY_POLL_BUDGET 70 - -#ifndef SOL_SOCKET -#define SOL_SOCKET 1 -#endif - -#define SOL_IP 0 -#define SOL_IPV6 41 -#define SOL_ICMPV6 58 - -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 -#define SOL_AAL 265 -#define SOL_IRDA 266 -#define SOL_NETBEUI 267 -#define SOL_LLC 268 -#define SOL_DCCP 269 -#define SOL_NETLINK 270 -#define SOL_TIPC 271 -#define SOL_RXRPC 272 -#define SOL_PPPOL2TP 273 -#define SOL_BLUETOOTH 274 -#define SOL_PNPIPE 275 -#define SOL_RDS 276 -#define SOL_IUCV 277 -#define SOL_CAIF 278 -#define SOL_ALG 279 -#define SOL_NFC 280 -#define SOL_KCM 281 -#define SOL_TLS 282 -#define SOL_XDP 283 - -#define SOMAXCONN 128 - -#define MSG_OOB 0x0001 -#define MSG_PEEK 0x0002 -#define MSG_DONTROUTE 0x0004 -#define MSG_CTRUNC 0x0008 -#define MSG_PROXY 0x0010 -#define MSG_TRUNC 0x0020 -#define MSG_DONTWAIT 0x0040 -#define MSG_EOR 0x0080 -#define MSG_WAITALL 0x0100 -#define MSG_FIN 0x0200 -#define MSG_SYN 0x0400 -#define MSG_CONFIRM 0x0800 -#define MSG_RST 0x1000 -#define MSG_ERRQUEUE 0x2000 -#define MSG_NOSIGNAL 0x4000 -#define MSG_MORE 0x8000 -#define MSG_WAITFORONE 0x10000 -#define MSG_BATCH 0x40000 -#define MSG_ZEROCOPY 0x4000000 -#define MSG_FASTOPEN 0x20000000 -#define MSG_CMSG_CLOEXEC 0x40000000 - -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) -#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ - __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ - ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) - -#define SCM_RIGHTS 0x01 -#define SCM_CREDENTIALS 0x02 -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr { - sa_family_t sa_family; - char sa_data[14]; -}; -#else -#include <__struct_sockaddr.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr_storage { - sa_family_t ss_family; - char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; - unsigned long __ss_align; -}; -#else -#include <__struct_sockaddr_storage.h> -#endif - -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int socket (int, int, int); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */ -int socketpair (int, int, int, int [2]); -#endif - -int shutdown (int, int); - -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int connect (int, const struct sockaddr *, socklen_t); -int bind (int, const struct sockaddr *, socklen_t); -int listen (int, int); -#endif - -int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); -int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); - -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); -int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); -#endif - -ssize_t send (int, const void *, size_t, int); -ssize_t recv (int, void *, size_t, int); -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); -ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ -ssize_t sendmsg (int, const struct msghdr *, int); -ssize_t recvmsg (int, struct msghdr *, int); -#endif - -int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int setsockopt (int, int, int, const void *, socklen_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ -int sockatmark (int); -#endif - -#if _REDIR_TIME64 -#ifdef _GNU_SOURCE -__REDIR(recvmmsg, __recvmmsg_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/stat.h b/lib/libc/include/wasm-wasi-musl/sys/stat.h deleted file mode 100644 index 01d30ddaf3d2ebddaab55fefeb3b82bd781e8a4a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/stat.h +++ /dev/null @@ -1,198 +0,0 @@ -#ifndef _SYS_STAT_H -#define _SYS_STAT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_dev_t -#define __NEED_ino_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_time_t -#define __NEED_blksize_t -#define __NEED_blkcnt_t -#define __NEED_struct_timespec - -#ifdef _GNU_SOURCE -#define __NEED_int64_t -#define __NEED_uint64_t -#define __NEED_uint32_t -#define __NEED_uint16_t -#endif - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - -#define S_IFMT 0170000 - -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFBLK 0060000 -#define S_IFREG 0100000 -#define S_IFIFO 0010000 -#define S_IFLNK 0120000 -#define S_IFSOCK 0140000 - -#define S_TYPEISMQ(buf) 0 -#define S_TYPEISSEM(buf) 0 -#define S_TYPEISSHM(buf) 0 -#define S_TYPEISTMO(buf) 0 - -#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) -#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) -#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) - -#ifndef S_IRUSR -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 -#endif - -#define UTIME_NOW 0x3fffffff -#define UTIME_OMIT 0x3ffffffe -#else -#include <__header_sys_stat.h> -#endif - -int stat(const char *__restrict, struct stat *__restrict); -int fstat(int, struct stat *); -int lstat(const char *__restrict, struct stat *__restrict); -int fstatat(int, const char *__restrict, struct stat *__restrict, int); -int chmod(const char *, mode_t); -int fchmod(int, mode_t); -int fchmodat(int, const char *, mode_t, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no umask */ -mode_t umask(mode_t); -#endif -int mkdir(const char *, mode_t); -#ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ -int mkfifo(const char *, mode_t); -#endif -int mkdirat(int, const char *, mode_t); -#ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ -int mkfifoat(int, const char *, mode_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no mknod */ -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int mknod(const char *, mode_t, dev_t); -int mknodat(int, const char *, mode_t, dev_t); -#endif -#endif - -int futimens(int, const struct timespec [2]); -int utimensat(int, const char *, const struct timespec [2], int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ -int lchmod(const char *, mode_t); -#endif -#define S_IREAD S_IRUSR -#define S_IWRITE S_IWUSR -#define S_IEXEC S_IXUSR -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no statx */ -#if defined(_GNU_SOURCE) -#define STATX_TYPE 1U -#define STATX_MODE 2U -#define STATX_NLINK 4U -#define STATX_UID 8U -#define STATX_GID 0x10U -#define STATX_ATIME 0x20U -#define STATX_MTIME 0x40U -#define STATX_CTIME 0x80U -#define STATX_INO 0x100U -#define STATX_SIZE 0x200U -#define STATX_BLOCKS 0x400U -#define STATX_BASIC_STATS 0x7ffU -#define STATX_BTIME 0x800U -#define STATX_ALL 0xfffU - -struct statx_timestamp { - int64_t tv_sec; - uint32_t tv_nsec, __pad; -}; - -struct statx { - uint32_t stx_mask; - uint32_t stx_blksize; - uint64_t stx_attributes; - uint32_t stx_nlink; - uint32_t stx_uid; - uint32_t stx_gid; - uint16_t stx_mode; - uint16_t __pad0[1]; - uint64_t stx_ino; - uint64_t stx_size; - uint64_t stx_blocks; - uint64_t stx_attributes_mask; - struct statx_timestamp stx_atime; - struct statx_timestamp stx_btime; - struct statx_timestamp stx_ctime; - struct statx_timestamp stx_mtime; - uint32_t stx_rdev_major; - uint32_t stx_rdev_minor; - uint32_t stx_dev_major; - uint32_t stx_dev_minor; - uint64_t __pad1[14]; -}; - -int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict); -#endif -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define stat64 stat -#define fstat64 fstat -#define lstat64 lstat -#define fstatat64 fstatat -#define blkcnt64_t blkcnt_t -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#define ino64_t ino_t -#define off64_t off_t -#endif - -#if _REDIR_TIME64 -__REDIR(stat, __stat_time64); -__REDIR(fstat, __fstat_time64); -__REDIR(lstat, __lstat_time64); -__REDIR(fstatat, __fstatat_time64); -__REDIR(futimens, __futimens_time64); -__REDIR(utimensat, __utimensat_time64); -#endif - -#ifdef __cplusplus -} -#endif -#endif - - diff --git a/lib/libc/include/wasm-wasi-musl/sys/statvfs.h b/lib/libc/include/wasm-wasi-musl/sys/statvfs.h deleted file mode 100644 index 6cf35c5941b706c9272265e54a1a06775164232f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/statvfs.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _SYS_STATVFS_H -#define _SYS_STATVFS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t -#include - -struct statvfs { - unsigned long f_bsize, f_frsize; - fsblkcnt_t f_blocks, f_bfree, f_bavail; - fsfilcnt_t f_files, f_ffree, f_favail; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned long f_fsid; - unsigned :8*(2*sizeof(int)-sizeof(long)); -#else - unsigned :8*(2*sizeof(int)-sizeof(long)); - unsigned long f_fsid; -#endif - unsigned long f_flag, f_namemax; - unsigned int f_type; - int __reserved[5]; -}; - -int statvfs (const char *__restrict, struct statvfs *__restrict); -int fstatvfs (int, struct statvfs *); - -#define ST_RDONLY 1 -#define ST_NOSUID 2 -#define ST_NODEV 4 -#define ST_NOEXEC 8 -#define ST_SYNCHRONOUS 16 -#define ST_MANDLOCK 64 -#define ST_WRITE 128 -#define ST_APPEND 256 -#define ST_IMMUTABLE 512 -#define ST_NOATIME 1024 -#define ST_NODIRATIME 2048 -#define ST_RELATIME 4096 - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define statvfs64 statvfs -#define fstatvfs64 fstatvfs -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/syscall.h b/lib/libc/include/wasm-wasi-musl/sys/syscall.h deleted file mode 100644 index ceed6b59cb3ee550651c23c9758e06ff0106d6bb..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/syscall.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _SYS_SYSCALL_H -#define _SYS_SYSCALL_H - -#ifdef __wasilibc_unmodified_upstream /* WASI has no syscall */ -#include -#else -/* The generic syscall funtion is not yet implemented. */ -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/time.h b/lib/libc/include/wasm-wasi-musl/sys/time.h deleted file mode 100644 index 0f736551f60f57d560a5bfb485892abe611908e2..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/time.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _SYS_TIME_H -#define _SYS_TIME_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -int gettimeofday (struct timeval *__restrict, void *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no getitimer */ -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerval { - struct timeval it_interval; - struct timeval it_value; -}; - -int getitimer (int, struct itimerval *); -int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); -#endif -int utimes (const char *, const struct timeval [2]); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -int futimes(int, const struct timeval [2]); -#endif -int futimesat(int, const char *, const struct timeval [2]); -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -int lutimes(const char *, const struct timeval [2]); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no way to set the time */ -int settimeofday(const struct timeval *, const struct timezone *); -int adjtime (const struct timeval *, struct timeval *); -#endif -#define timerisset(t) ((t)->tv_sec || (t)->tv_usec) -#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) -#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ - (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) -#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ - ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ - ((a)->tv_usec -= 1000000, (a)->tv_sec++) ) -#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ - ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ - ((a)->tv_usec += 1000000, (a)->tv_sec--) ) -#endif - -#if defined(_GNU_SOURCE) -#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ - (ts)->tv_sec = (tv)->tv_sec, \ - (ts)->tv_nsec = (tv)->tv_usec * 1000, \ - (void)0 ) -#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ - (tv)->tv_sec = (ts)->tv_sec, \ - (tv)->tv_usec = (ts)->tv_nsec / 1000, \ - (void)0 ) -#endif - -#if _REDIR_TIME64 -__REDIR(gettimeofday, __gettimeofday_time64); -__REDIR(getitimer, __getitimer_time64); -__REDIR(setitimer, __setitimer_time64); -__REDIR(utimes, __utimes_time64); -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__REDIR(futimes, __futimes_time64); -__REDIR(futimesat, __futimesat_time64); -__REDIR(lutimes, __lutimes_time64); -__REDIR(settimeofday, __settimeofday_time64); -__REDIR(adjtime, __adjtime64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/times.h b/lib/libc/include/wasm-wasi-musl/sys/times.h deleted file mode 100644 index cdaeeee91a9e08cfd3a8d21b0be52a1695afe15a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/times.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _WASI_EMULATED_PROCESS_CLOCKS -#error WASI lacks process-associated clocks; to enable emulation of the `times` function using \ -the wall clock, which isn't sensitive to whether the program is running or suspended, \ -compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks -#else -#ifndef _SYS_TIMES_H -#define _SYS_TIMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_clock_t -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct tms { - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; -#else -#include <__struct_tms.h> -#endif - -clock_t times (struct tms *); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/types.h b/lib/libc/include/wasm-wasi-musl/sys/types.h deleted file mode 100644 index 0c35541da0754954b9aa13d90322458c92277a53..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/types.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_ino_t -#define __NEED_dev_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_time_t -#define __NEED_timer_t -#define __NEED_clockid_t - -#define __NEED_blkcnt_t -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t - -#define __NEED_id_t -#define __NEED_key_t -#define __NEED_clock_t -#define __NEED_suseconds_t -#define __NEED_blksize_t - -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t -#define __NEED_useconds_t - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_int8_t -#define __NEED_int16_t -#define __NEED_int32_t -#define __NEED_int64_t -#define __NEED_u_int64_t -#define __NEED_register_t -#endif - -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef unsigned char u_int8_t; -typedef unsigned short u_int16_t; -typedef unsigned u_int32_t; -typedef char *caddr_t; -typedef unsigned char u_char; -typedef unsigned short u_short, ushort; -typedef unsigned u_int, uint; -typedef unsigned long u_long, ulong; -typedef long long quad_t; -typedef unsigned long long u_quad_t; -#include -#include -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define blkcnt64_t blkcnt_t -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#define ino64_t ino_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/uio.h b/lib/libc/include/wasm-wasi-musl/sys/uio.h deleted file mode 100644 index f102d5a56e423b7de5ea14f09a8b4e364877e386..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/uio.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _SYS_UIO_H -#define _SYS_UIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_off_t -#endif - -#ifdef _GNU_SOURCE -#define __NEED_pid_t -#endif - -#include - -#define UIO_MAXIOV 1024 - -ssize_t readv (int, const struct iovec *, int); -ssize_t writev (int, const struct iovec *, int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -ssize_t preadv (int, const struct iovec *, int, off_t); -ssize_t pwritev (int, const struct iovec *, int, off_t); -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define preadv64 preadv -#define pwritev64 pwritev -#define off64_t off_t -#endif -#endif - -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have these Linux-specific functions -#ifdef _GNU_SOURCE -ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); -ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); -ssize_t preadv2 (int, const struct iovec *, int, off_t, int); -ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); -#define RWF_HIPRI 0x00000001 -#define RWF_DSYNC 0x00000002 -#define RWF_SYNC 0x00000004 -#define RWF_NOWAIT 0x00000008 -#define RWF_APPEND 0x00000010 -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/sys/un.h b/lib/libc/include/wasm-wasi-musl/sys/un.h deleted file mode 100644 index 71169567172c40860b513b93deeee40ab4d7bde7..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/sys/un.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _SYS_UN_H -#define _SYS_UN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_sa_family_t -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_size_t -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* WASI has no UNIX-domain sockets */ -struct sockaddr_un { - sa_family_t sun_family; - char sun_path[108]; -}; -#else -#include <__struct_sockaddr_un.h> -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* Declare strlen with the same attributes as uses */ -size_t strlen(const char *); -#else -size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); -#endif -#define SUN_LEN(s) (2+strlen((s)->sun_path)) -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/time.h b/lib/libc/include/wasm-wasi-musl/time.h deleted file mode 100644 index f53414878aa0daff7d6f9e9f042443a9b2e2f9e6..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/time.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef _TIME_H -#define _TIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_struct_timespec - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_clockid_t -#define __NEED_timer_t -#define __NEED_pid_t -#define __NEED_locale_t -#endif - -#include - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define __tm_gmtoff tm_gmtoff -#define __tm_zone tm_zone -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - long __tm_gmtoff; - const char *__tm_zone; -}; -#else -#include <__header_time.h> -#endif - -#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) -clock_t clock (void); -#else -__attribute__((__deprecated__( -"WASI lacks process-associated clocks; to enable emulation of the `clock` function using " -"the wall clock, which isn't sensitive to whether the program is running or suspended, " -"compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks" -))) -clock_t clock (void); -#endif -time_t time (time_t *); -double difftime (time_t, time_t); -time_t mktime (struct tm *); -size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); -struct tm *gmtime (const time_t *); -struct tm *localtime (const time_t *); -char *asctime (const struct tm *); -char *ctime (const time_t *); -int timespec_get(struct timespec *, int); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define CLOCKS_PER_SEC 1000000L - -#define TIME_UTC 1 -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); - -struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); -struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); -char *asctime_r (const struct tm *__restrict, char *__restrict); -char *ctime_r (const time_t *, char *); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ -void tzset (void); -#endif - -struct itimerspec { - struct timespec it_interval; - struct timespec it_value; -}; - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define CLOCK_REALTIME 0 -#define CLOCK_MONOTONIC 1 -#define CLOCK_PROCESS_CPUTIME_ID 2 -#define CLOCK_THREAD_CPUTIME_ID 3 -#define CLOCK_MONOTONIC_RAW 4 -#define CLOCK_REALTIME_COARSE 5 -#define CLOCK_MONOTONIC_COARSE 6 -#define CLOCK_BOOTTIME 7 -#define CLOCK_REALTIME_ALARM 8 -#define CLOCK_BOOTTIME_ALARM 9 -#define CLOCK_SGI_CYCLE 10 -#define CLOCK_TAI 11 - -#define TIMER_ABSTIME 1 -#endif - -int nanosleep (const struct timespec *, struct timespec *); -int clock_getres (clockid_t, struct timespec *); -int clock_gettime (clockid_t, struct timespec *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */ -int clock_settime (clockid_t, const struct timespec *); -#endif -int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */ -int clock_getcpuclockid (pid_t, clockid_t *); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no timers */ -struct sigevent; -int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); -int timer_delete (timer_t); -int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); -int timer_gettime (timer_t, struct itimerspec *); -int timer_getoverrun (timer_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ -extern char *tzname[2]; -#endif - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); -#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ -extern int daylight; -extern long timezone; -#endif -extern int getdate_err; -struct tm *getdate (const char *); -#endif - - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no stime */ -int stime(const time_t *); -#endif -time_t timegm(struct tm *); -#endif - -#if _REDIR_TIME64 -__REDIR(time, __time64); -__REDIR(difftime, __difftime64); -__REDIR(mktime, __mktime64); -__REDIR(gmtime, __gmtime64); -__REDIR(localtime, __localtime64); -__REDIR(ctime, __ctime64); -__REDIR(timespec_get, __timespec_get_time64); -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -__REDIR(gmtime_r, __gmtime64_r); -__REDIR(localtime_r, __localtime64_r); -__REDIR(ctime_r, __ctime64_r); -__REDIR(nanosleep, __nanosleep_time64); -__REDIR(clock_getres, __clock_getres_time64); -__REDIR(clock_gettime, __clock_gettime64); -__REDIR(clock_settime, __clock_settime64); -__REDIR(clock_nanosleep, __clock_nanosleep_time64); -__REDIR(timer_settime, __timer_settime64); -__REDIR(timer_gettime, __timer_gettime64); -#endif -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__REDIR(stime, __stime64); -__REDIR(timegm, __timegm_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/unistd.h b/lib/libc/include/wasm-wasi-musl/unistd.h deleted file mode 100644 index c3158e6e649220fd5520dbf804bd91ff6b11c6b4..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/unistd.h +++ /dev/null @@ -1,589 +0,0 @@ -#ifndef _UNISTD_H -#define _UNISTD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#define SEEK_DATA 3 -#define SEEK_HOLE 4 -#else -#include <__header_unistd.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_intptr_t -#define __NEED_useconds_t - -#include - -#ifdef __wasilibc_unmodified_upstream /* WASI has no pipe */ -int pipe(int [2]); -int pipe2(int [2], int); -#endif -int close(int); -int posix_close(int, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no dup */ -int dup(int); -int dup2(int, int); -int dup3(int, int, int); -#endif -off_t lseek(int, off_t, int); -#ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */ -#else -off_t __wasilibc_tell(int); - -#ifndef __cplusplus -/* - * Optimize lseek in the case where it's just returning the current offset. - * This avoids importing `__wasi_fd_seek` altogether in many common cases. - * - * But don't do this for C++ because a simple macro wouldn't handle namespaces - * correctly: - * - User code could qualify the `lseek` call with `::`. - * - There may be another `lseek` in scope from a `using` declaration. - */ -#define lseek(fd, offset, whence) \ - ({ \ - off_t __f = (fd); \ - off_t __o = (offset); \ - off_t __w = (whence); \ - __builtin_constant_p((offset)) && \ - __builtin_constant_p((whence)) && \ - __o == 0 && \ - __w == SEEK_CUR \ - ? __wasilibc_tell(__f) \ - : lseek(__f, __o, __w); \ - }) -#endif -#endif -int fsync(int); -int fdatasync(int); - -ssize_t read(int, void *, size_t); -ssize_t write(int, const void *, size_t); -ssize_t pread(int, void *, size_t, off_t); -ssize_t pwrite(int, const void *, size_t, off_t); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no chown */ -int chown(const char *, uid_t, gid_t); -int fchown(int, uid_t, gid_t); -int lchown(const char *, uid_t, gid_t); -int fchownat(int, const char *, uid_t, gid_t, int); -#endif - -int link(const char *, const char *); -int linkat(int, const char *, int, const char *, int); -int symlink(const char *, const char *); -int symlinkat(const char *, int, const char *); -ssize_t readlink(const char *__restrict, char *__restrict, size_t); -ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); -int unlink(const char *); -int unlinkat(int, const char *, int); -int rmdir(const char *); -int truncate(const char *, off_t); -int ftruncate(int, off_t); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -#endif - -int access(const char *, int); -int faccessat(int, const char *, int, int); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no fchdir */ -int fchdir(int); -#endif -int chdir(const char *); -char *getcwd(char *, size_t); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ -unsigned alarm(unsigned); -#endif -unsigned sleep(unsigned); -#ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ -int pause(void); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ -pid_t fork(void); -pid_t _Fork(void); -int execve(const char *, char *const [], char *const []); -int execv(const char *, char *const []); -int execle(const char *, const char *, ...); -int execl(const char *, const char *, ...); -int execvp(const char *, char *const []); -int execlp(const char *, const char *, ...); -int fexecve(int, char *const [], char *const []); -#endif -_Noreturn void _exit(int); - -#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_GETPID) -pid_t getpid(void); -#else -__attribute__((__deprecated__( -"WASI lacks process identifiers; to enable emulation of the `getpid` function using " -"a placeholder value, which doesn't reflect the host PID of the program, " -"compile with -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid" -))) -pid_t getpid(void); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no getpid etc. */ -pid_t getppid(void); -pid_t getpgrp(void); -pid_t getpgid(pid_t); -int setpgid(pid_t, pid_t); -pid_t setsid(void); -pid_t getsid(pid_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no ttyname */ -char *ttyname(int); -int ttyname_r(int, char *, size_t); -#endif -int isatty(int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no process groups */ -pid_t tcgetpgrp(int); -int tcsetpgrp(int, pid_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no getuid etc. */ -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); -int getgroups(int, gid_t []); -int setuid(uid_t); -int seteuid(uid_t); -int setgid(gid_t); -int setegid(gid_t); -#endif - -char *getlogin(void); -int getlogin_r(char *, size_t); -int gethostname(char *, size_t); -char *ctermid(char *); - -int getopt(int, char * const [], const char *); -extern char *optarg; -extern int optind, opterr, optopt; - -long pathconf(const char *, int); -long fpathconf(int, int); -long sysconf(int); -size_t confstr(int, char *, size_t); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 -#ifdef __wasilibc_unmodified_upstream /* WASI has no setreuid */ -int setreuid(uid_t, uid_t); -int setregid(gid_t, gid_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -int lockf(int, int, off_t); -#endif -long gethostid(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no nice, sync, or setpgrp */ -int nice(int); -void sync(void); -pid_t setpgrp(void); -#endif -char *crypt(const char *, const char *); -void encrypt(char *, int); -void swab(const void *__restrict, void *__restrict, ssize_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -int usleep(unsigned); -unsigned ualarm(unsigned, unsigned); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define L_SET 0 -#define L_INCR 1 -#define L_XTND 2 -#ifdef __wasilibc_unmodified_upstream /* WASI has no brk */ -int brk(void *); -#endif -void *sbrk(intptr_t); -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ -pid_t vfork(void); -int vhangup(void); -int chroot(const char *); -#endif -int getpagesize(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ -int getdtablesize(void); -int sethostname(const char *, size_t); -int getdomainname(char *, size_t); -int setdomainname(const char *, size_t); -int setgroups(size_t, const gid_t *); -char *getpass(const char *); -int daemon(int, int); -void setusershell(void); -void endusershell(void); -char *getusershell(void); -int acct(const char *); -long syscall(long, ...); -int execvpe(const char *, char *const [], char *const []); -int issetugid(void); -#endif -int getentropy(void *, size_t); -extern int optreset; -#endif - -#ifdef _GNU_SOURCE -extern char **environ; -#ifdef __wasilibc_unmodified_upstream /* WASI has no get/setresuid */ -int setresuid(uid_t, uid_t, uid_t); -int setresgid(gid_t, gid_t, gid_t); -int getresuid(uid_t *, uid_t *, uid_t *); -int getresgid(gid_t *, gid_t *, gid_t *); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no cwd */ -char *get_current_dir_name(void); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no syncfs */ -int syncfs(int); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no eaccess */ -int euidaccess(const char *, int); -int eaccess(const char *, int); -ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); -pid_t gettid(void); -#endif -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define lseek64 lseek -#define pread64 pread -#define pwrite64 pwrite -#ifdef __wasilibc_unmodified_upstream /* WASI has no truncate */ -#define truncate64 truncate -#endif -#define ftruncate64 ftruncate -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -#define lockf64 lockf -#endif -#define off64_t off_t -#endif - -#define POSIX_CLOSE_RESTART 0 - -#define _XOPEN_VERSION 700 -#define _XOPEN_UNIX 1 -#define _XOPEN_ENH_I18N 1 - -#define _POSIX_VERSION 200809L -#define _POSIX2_VERSION _POSIX_VERSION - -#define _POSIX_ADVISORY_INFO _POSIX_VERSION -#define _POSIX_CHOWN_RESTRICTED 1 -#define _POSIX_IPV6 _POSIX_VERSION -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes, mmap, or mq */ -#define _POSIX_JOB_CONTROL 1 -#define _POSIX_MAPPED_FILES _POSIX_VERSION -#define _POSIX_MEMLOCK _POSIX_VERSION -#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION -#define _POSIX_MEMORY_PROTECTION _POSIX_VERSION -#define _POSIX_MESSAGE_PASSING _POSIX_VERSION -#endif -#define _POSIX_FSYNC _POSIX_VERSION -#define _POSIX_NO_TRUNC 1 -#ifdef __wasilibc_unmodified_upstream /* WASI has no raw sockets */ -#define _POSIX_RAW_SOCKETS _POSIX_VERSION -#endif -#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION -#define _POSIX_REGEXP 1 -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ -#define _POSIX_SAVED_IDS 1 -#define _POSIX_SHELL 1 -#define _POSIX_SPAWN _POSIX_VERSION -#endif -#define _POSIX_VDISABLE 0 - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -#define _POSIX_THREADS _POSIX_VERSION -#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION -#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION -#endif -#if defined(__wasilibc_unmodified_upstream) /* wasi-libc doesn't provide pthread_attr_{get,set}stackaddr */ -#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION -#endif -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION -#endif -#if defined(__wasilibc_unmodified_upstream) /* WASI has no scheduling control, and wasi-libc doesn't provide pthread_getcpuclockid */ -#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION -#define _POSIX_THREAD_CPUTIME _POSIX_VERSION -#endif -#define _POSIX_TIMERS _POSIX_VERSION -#define _POSIX_TIMEOUTS _POSIX_VERSION -#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION -#define _POSIX_CPUTIME _POSIX_VERSION -#define _POSIX_CLOCK_SELECTION _POSIX_VERSION -#define _POSIX_BARRIERS _POSIX_VERSION -#define _POSIX_SPIN_LOCKS _POSIX_VERSION -#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX async I/O, semaphores, or shared memory */ -#define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION -#define _POSIX_SEMAPHORES _POSIX_VERSION -#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION -#endif - -#define _POSIX2_C_BIND _POSIX_VERSION - -#include - - - -#define _PC_LINK_MAX 0 -#define _PC_MAX_CANON 1 -#define _PC_MAX_INPUT 2 -#define _PC_NAME_MAX 3 -#define _PC_PATH_MAX 4 -#define _PC_PIPE_BUF 5 -#define _PC_CHOWN_RESTRICTED 6 -#define _PC_NO_TRUNC 7 -#define _PC_VDISABLE 8 -#define _PC_SYNC_IO 9 -#define _PC_ASYNC_IO 10 -#define _PC_PRIO_IO 11 -#define _PC_SOCK_MAXBUF 12 -#define _PC_FILESIZEBITS 13 -#define _PC_REC_INCR_XFER_SIZE 14 -#define _PC_REC_MAX_XFER_SIZE 15 -#define _PC_REC_MIN_XFER_SIZE 16 -#define _PC_REC_XFER_ALIGN 17 -#define _PC_ALLOC_SIZE_MIN 18 -#define _PC_SYMLINK_MAX 19 -#define _PC_2_SYMLINKS 20 - -#define _SC_ARG_MAX 0 -#define _SC_CHILD_MAX 1 -#define _SC_CLK_TCK 2 -#define _SC_NGROUPS_MAX 3 -#define _SC_OPEN_MAX 4 -#define _SC_STREAM_MAX 5 -#define _SC_TZNAME_MAX 6 -#define _SC_JOB_CONTROL 7 -#define _SC_SAVED_IDS 8 -#define _SC_REALTIME_SIGNALS 9 -#define _SC_PRIORITY_SCHEDULING 10 -#define _SC_TIMERS 11 -#define _SC_ASYNCHRONOUS_IO 12 -#define _SC_PRIORITIZED_IO 13 -#define _SC_SYNCHRONIZED_IO 14 -#define _SC_FSYNC 15 -#define _SC_MAPPED_FILES 16 -#define _SC_MEMLOCK 17 -#define _SC_MEMLOCK_RANGE 18 -#define _SC_MEMORY_PROTECTION 19 -#define _SC_MESSAGE_PASSING 20 -#define _SC_SEMAPHORES 21 -#define _SC_SHARED_MEMORY_OBJECTS 22 -#define _SC_AIO_LISTIO_MAX 23 -#define _SC_AIO_MAX 24 -#define _SC_AIO_PRIO_DELTA_MAX 25 -#define _SC_DELAYTIMER_MAX 26 -#define _SC_MQ_OPEN_MAX 27 -#define _SC_MQ_PRIO_MAX 28 -#define _SC_VERSION 29 -#define _SC_PAGE_SIZE 30 -#define _SC_PAGESIZE 30 /* !! */ -#define _SC_RTSIG_MAX 31 -#define _SC_SEM_NSEMS_MAX 32 -#define _SC_SEM_VALUE_MAX 33 -#define _SC_SIGQUEUE_MAX 34 -#define _SC_TIMER_MAX 35 -#define _SC_BC_BASE_MAX 36 -#define _SC_BC_DIM_MAX 37 -#define _SC_BC_SCALE_MAX 38 -#define _SC_BC_STRING_MAX 39 -#define _SC_COLL_WEIGHTS_MAX 40 -#define _SC_EXPR_NEST_MAX 42 -#define _SC_LINE_MAX 43 -#define _SC_RE_DUP_MAX 44 -#define _SC_2_VERSION 46 -#define _SC_2_C_BIND 47 -#define _SC_2_C_DEV 48 -#define _SC_2_FORT_DEV 49 -#define _SC_2_FORT_RUN 50 -#define _SC_2_SW_DEV 51 -#define _SC_2_LOCALEDEF 52 -#define _SC_UIO_MAXIOV 60 /* !! */ -#define _SC_IOV_MAX 60 -#define _SC_THREADS 67 -#define _SC_THREAD_SAFE_FUNCTIONS 68 -#define _SC_GETGR_R_SIZE_MAX 69 -#define _SC_GETPW_R_SIZE_MAX 70 -#define _SC_LOGIN_NAME_MAX 71 -#define _SC_TTY_NAME_MAX 72 -#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 -#define _SC_THREAD_KEYS_MAX 74 -#define _SC_THREAD_STACK_MIN 75 -#define _SC_THREAD_THREADS_MAX 76 -#define _SC_THREAD_ATTR_STACKADDR 77 -#define _SC_THREAD_ATTR_STACKSIZE 78 -#define _SC_THREAD_PRIORITY_SCHEDULING 79 -#define _SC_THREAD_PRIO_INHERIT 80 -#define _SC_THREAD_PRIO_PROTECT 81 -#define _SC_THREAD_PROCESS_SHARED 82 -#define _SC_NPROCESSORS_CONF 83 -#define _SC_NPROCESSORS_ONLN 84 -#define _SC_PHYS_PAGES 85 -#define _SC_AVPHYS_PAGES 86 -#define _SC_ATEXIT_MAX 87 -#define _SC_PASS_MAX 88 -#define _SC_XOPEN_VERSION 89 -#define _SC_XOPEN_XCU_VERSION 90 -#define _SC_XOPEN_UNIX 91 -#define _SC_XOPEN_CRYPT 92 -#define _SC_XOPEN_ENH_I18N 93 -#define _SC_XOPEN_SHM 94 -#define _SC_2_CHAR_TERM 95 -#define _SC_2_UPE 97 -#define _SC_XOPEN_XPG2 98 -#define _SC_XOPEN_XPG3 99 -#define _SC_XOPEN_XPG4 100 -#define _SC_NZERO 109 -#define _SC_XBS5_ILP32_OFF32 125 -#define _SC_XBS5_ILP32_OFFBIG 126 -#define _SC_XBS5_LP64_OFF64 127 -#define _SC_XBS5_LPBIG_OFFBIG 128 -#define _SC_XOPEN_LEGACY 129 -#define _SC_XOPEN_REALTIME 130 -#define _SC_XOPEN_REALTIME_THREADS 131 -#define _SC_ADVISORY_INFO 132 -#define _SC_BARRIERS 133 -#define _SC_CLOCK_SELECTION 137 -#define _SC_CPUTIME 138 -#define _SC_THREAD_CPUTIME 139 -#define _SC_MONOTONIC_CLOCK 149 -#define _SC_READER_WRITER_LOCKS 153 -#define _SC_SPIN_LOCKS 154 -#define _SC_REGEXP 155 -#define _SC_SHELL 157 -#define _SC_SPAWN 159 -#define _SC_SPORADIC_SERVER 160 -#define _SC_THREAD_SPORADIC_SERVER 161 -#define _SC_TIMEOUTS 164 -#define _SC_TYPED_MEMORY_OBJECTS 165 -#define _SC_2_PBS 168 -#define _SC_2_PBS_ACCOUNTING 169 -#define _SC_2_PBS_LOCATE 170 -#define _SC_2_PBS_MESSAGE 171 -#define _SC_2_PBS_TRACK 172 -#define _SC_SYMLOOP_MAX 173 -#define _SC_STREAMS 174 -#define _SC_2_PBS_CHECKPOINT 175 -#define _SC_V6_ILP32_OFF32 176 -#define _SC_V6_ILP32_OFFBIG 177 -#define _SC_V6_LP64_OFF64 178 -#define _SC_V6_LPBIG_OFFBIG 179 -#define _SC_HOST_NAME_MAX 180 -#define _SC_TRACE 181 -#define _SC_TRACE_EVENT_FILTER 182 -#define _SC_TRACE_INHERIT 183 -#define _SC_TRACE_LOG 184 - -#define _SC_IPV6 235 -#define _SC_RAW_SOCKETS 236 -#define _SC_V7_ILP32_OFF32 237 -#define _SC_V7_ILP32_OFFBIG 238 -#define _SC_V7_LP64_OFF64 239 -#define _SC_V7_LPBIG_OFFBIG 240 -#define _SC_SS_REPL_MAX 241 -#define _SC_TRACE_EVENT_NAME_MAX 242 -#define _SC_TRACE_NAME_MAX 243 -#define _SC_TRACE_SYS_MAX 244 -#define _SC_TRACE_USER_EVENT_MAX 245 -#define _SC_XOPEN_STREAMS 246 -#define _SC_THREAD_ROBUST_PRIO_INHERIT 247 -#define _SC_THREAD_ROBUST_PRIO_PROTECT 248 -#define _SC_MINSIGSTKSZ 249 -#define _SC_SIGSTKSZ 250 - -#define _CS_PATH 0 -#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 -#define _CS_GNU_LIBC_VERSION 2 -#define _CS_GNU_LIBPTHREAD_VERSION 3 -#define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 -#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 - -#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 -#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 -#define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 -#define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 -#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 -#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 -#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 -#define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 -#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 -#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 -#define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 -#define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 -#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 -#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 -#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 -#define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 -#define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 -#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 -#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 -#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 -#define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 -#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 -#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 -#define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 -#define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 -#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 -#define _CS_V6_ENV 1148 -#define _CS_V7_ENV 1149 -#define _CS_POSIX_V7_THREADS_CFLAGS 1150 -#define _CS_POSIX_V7_THREADS_LDFLAGS 1151 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wasi/api.h b/lib/libc/include/wasm-wasi-musl/wasi/api.h deleted file mode 100644 index 45a6506e2ffa022e081bea9aa8e14cf8b7c4da5a..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wasi/api.h +++ /dev/null @@ -1,2115 +0,0 @@ -/** - * . This file contains declarations describing the WASI ABI - * as of "snapshot preview1". It was originally auto-generated from - * wasi_snapshot_preview1.witx, however WASI is in the process of - * transitioning to a new IDL and header file generator, and this file - * is temporarily being manually maintained. - * - * @file - * This file describes the [WASI] interface, consisting of functions, types, - * and defined values (macros). - * - * The interface described here is greatly inspired by [CloudABI]'s clean, - * thoughtfully-designed, capability-oriented, POSIX-style API. - * - * [CloudABI]: https://github.com/NuxiNL/cloudlibc - * [WASI]: https://github.com/WebAssembly/WASI/ - */ - -#ifndef __wasi_api_h -#define __wasi_api_h - -#ifndef __wasi__ -#error is only supported on WASI platforms. -#endif - -#ifndef __wasm32__ -#error only supports wasm32; doesn't yet support wasm64 -#endif - -#include -#include - -_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"); -_Static_assert(_Alignof(void*) == 4, "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; - -_Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_size_t) == 4, "witx calculated align"); - -/** - * Non-negative file size or length of a region within a file. - */ -typedef uint64_t __wasi_filesize_t; - -_Static_assert(sizeof(__wasi_filesize_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_filesize_t) == 8, "witx calculated align"); - -/** - * Timestamp in nanoseconds. - */ -typedef uint64_t __wasi_timestamp_t; - -_Static_assert(sizeof(__wasi_timestamp_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_timestamp_t) == 8, "witx calculated align"); - -/** - * Identifiers for clocks. - */ -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 (UINT32_C(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 (UINT32_C(1)) - -/** - * The CPU-time clock associated with the current process. - */ -#define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2)) - -/** - * The CPU-time clock associated with the current thread. - */ -#define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3)) - -_Static_assert(sizeof(__wasi_clockid_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_clockid_t) == 4, "witx calculated align"); - -/** - * Error codes returned by functions. - * 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 (UINT16_C(0)) - -/** - * Argument list too long. - */ -#define __WASI_ERRNO_2BIG (UINT16_C(1)) - -/** - * Permission denied. - */ -#define __WASI_ERRNO_ACCES (UINT16_C(2)) - -/** - * Address in use. - */ -#define __WASI_ERRNO_ADDRINUSE (UINT16_C(3)) - -/** - * Address not available. - */ -#define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4)) - -/** - * Address family not supported. - */ -#define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5)) - -/** - * Resource unavailable, or operation would block. - */ -#define __WASI_ERRNO_AGAIN (UINT16_C(6)) - -/** - * Connection already in progress. - */ -#define __WASI_ERRNO_ALREADY (UINT16_C(7)) - -/** - * Bad file descriptor. - */ -#define __WASI_ERRNO_BADF (UINT16_C(8)) - -/** - * Bad message. - */ -#define __WASI_ERRNO_BADMSG (UINT16_C(9)) - -/** - * Device or resource busy. - */ -#define __WASI_ERRNO_BUSY (UINT16_C(10)) - -/** - * Operation canceled. - */ -#define __WASI_ERRNO_CANCELED (UINT16_C(11)) - -/** - * No child processes. - */ -#define __WASI_ERRNO_CHILD (UINT16_C(12)) - -/** - * Connection aborted. - */ -#define __WASI_ERRNO_CONNABORTED (UINT16_C(13)) - -/** - * Connection refused. - */ -#define __WASI_ERRNO_CONNREFUSED (UINT16_C(14)) - -/** - * Connection reset. - */ -#define __WASI_ERRNO_CONNRESET (UINT16_C(15)) - -/** - * Resource deadlock would occur. - */ -#define __WASI_ERRNO_DEADLK (UINT16_C(16)) - -/** - * Destination address required. - */ -#define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17)) - -/** - * Mathematics argument out of domain of function. - */ -#define __WASI_ERRNO_DOM (UINT16_C(18)) - -/** - * Reserved. - */ -#define __WASI_ERRNO_DQUOT (UINT16_C(19)) - -/** - * File exists. - */ -#define __WASI_ERRNO_EXIST (UINT16_C(20)) - -/** - * Bad address. - */ -#define __WASI_ERRNO_FAULT (UINT16_C(21)) - -/** - * File too large. - */ -#define __WASI_ERRNO_FBIG (UINT16_C(22)) - -/** - * Host is unreachable. - */ -#define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23)) - -/** - * Identifier removed. - */ -#define __WASI_ERRNO_IDRM (UINT16_C(24)) - -/** - * Illegal byte sequence. - */ -#define __WASI_ERRNO_ILSEQ (UINT16_C(25)) - -/** - * Operation in progress. - */ -#define __WASI_ERRNO_INPROGRESS (UINT16_C(26)) - -/** - * Interrupted function. - */ -#define __WASI_ERRNO_INTR (UINT16_C(27)) - -/** - * Invalid argument. - */ -#define __WASI_ERRNO_INVAL (UINT16_C(28)) - -/** - * I/O error. - */ -#define __WASI_ERRNO_IO (UINT16_C(29)) - -/** - * Socket is connected. - */ -#define __WASI_ERRNO_ISCONN (UINT16_C(30)) - -/** - * Is a directory. - */ -#define __WASI_ERRNO_ISDIR (UINT16_C(31)) - -/** - * Too many levels of symbolic links. - */ -#define __WASI_ERRNO_LOOP (UINT16_C(32)) - -/** - * File descriptor value too large. - */ -#define __WASI_ERRNO_MFILE (UINT16_C(33)) - -/** - * Too many links. - */ -#define __WASI_ERRNO_MLINK (UINT16_C(34)) - -/** - * Message too large. - */ -#define __WASI_ERRNO_MSGSIZE (UINT16_C(35)) - -/** - * Reserved. - */ -#define __WASI_ERRNO_MULTIHOP (UINT16_C(36)) - -/** - * Filename too long. - */ -#define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37)) - -/** - * Network is down. - */ -#define __WASI_ERRNO_NETDOWN (UINT16_C(38)) - -/** - * Connection aborted by network. - */ -#define __WASI_ERRNO_NETRESET (UINT16_C(39)) - -/** - * Network unreachable. - */ -#define __WASI_ERRNO_NETUNREACH (UINT16_C(40)) - -/** - * Too many files open in system. - */ -#define __WASI_ERRNO_NFILE (UINT16_C(41)) - -/** - * No buffer space available. - */ -#define __WASI_ERRNO_NOBUFS (UINT16_C(42)) - -/** - * No such device. - */ -#define __WASI_ERRNO_NODEV (UINT16_C(43)) - -/** - * No such file or directory. - */ -#define __WASI_ERRNO_NOENT (UINT16_C(44)) - -/** - * Executable file format error. - */ -#define __WASI_ERRNO_NOEXEC (UINT16_C(45)) - -/** - * No locks available. - */ -#define __WASI_ERRNO_NOLCK (UINT16_C(46)) - -/** - * Reserved. - */ -#define __WASI_ERRNO_NOLINK (UINT16_C(47)) - -/** - * Not enough space. - */ -#define __WASI_ERRNO_NOMEM (UINT16_C(48)) - -/** - * No message of the desired type. - */ -#define __WASI_ERRNO_NOMSG (UINT16_C(49)) - -/** - * Protocol not available. - */ -#define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50)) - -/** - * No space left on device. - */ -#define __WASI_ERRNO_NOSPC (UINT16_C(51)) - -/** - * Function not supported. - */ -#define __WASI_ERRNO_NOSYS (UINT16_C(52)) - -/** - * The socket is not connected. - */ -#define __WASI_ERRNO_NOTCONN (UINT16_C(53)) - -/** - * Not a directory or a symbolic link to a directory. - */ -#define __WASI_ERRNO_NOTDIR (UINT16_C(54)) - -/** - * Directory not empty. - */ -#define __WASI_ERRNO_NOTEMPTY (UINT16_C(55)) - -/** - * State not recoverable. - */ -#define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56)) - -/** - * Not a socket. - */ -#define __WASI_ERRNO_NOTSOCK (UINT16_C(57)) - -/** - * Not supported, or operation not supported on socket. - */ -#define __WASI_ERRNO_NOTSUP (UINT16_C(58)) - -/** - * Inappropriate I/O control operation. - */ -#define __WASI_ERRNO_NOTTY (UINT16_C(59)) - -/** - * No such device or address. - */ -#define __WASI_ERRNO_NXIO (UINT16_C(60)) - -/** - * Value too large to be stored in data type. - */ -#define __WASI_ERRNO_OVERFLOW (UINT16_C(61)) - -/** - * Previous owner died. - */ -#define __WASI_ERRNO_OWNERDEAD (UINT16_C(62)) - -/** - * Operation not permitted. - */ -#define __WASI_ERRNO_PERM (UINT16_C(63)) - -/** - * Broken pipe. - */ -#define __WASI_ERRNO_PIPE (UINT16_C(64)) - -/** - * Protocol error. - */ -#define __WASI_ERRNO_PROTO (UINT16_C(65)) - -/** - * Protocol not supported. - */ -#define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66)) - -/** - * Protocol wrong type for socket. - */ -#define __WASI_ERRNO_PROTOTYPE (UINT16_C(67)) - -/** - * Result too large. - */ -#define __WASI_ERRNO_RANGE (UINT16_C(68)) - -/** - * Read-only file system. - */ -#define __WASI_ERRNO_ROFS (UINT16_C(69)) - -/** - * Invalid seek. - */ -#define __WASI_ERRNO_SPIPE (UINT16_C(70)) - -/** - * No such process. - */ -#define __WASI_ERRNO_SRCH (UINT16_C(71)) - -/** - * Reserved. - */ -#define __WASI_ERRNO_STALE (UINT16_C(72)) - -/** - * Connection timed out. - */ -#define __WASI_ERRNO_TIMEDOUT (UINT16_C(73)) - -/** - * Text file busy. - */ -#define __WASI_ERRNO_TXTBSY (UINT16_C(74)) - -/** - * Cross-device link. - */ -#define __WASI_ERRNO_XDEV (UINT16_C(75)) - -/** - * Extension: Capabilities insufficient. - */ -#define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76)) - -_Static_assert(sizeof(__wasi_errno_t) == 2, "witx calculated size"); -_Static_assert(_Alignof(__wasi_errno_t) == 2, "witx calculated align"); - -/** - * File descriptor rights, determining which actions may be performed. - */ -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 `fdflags::dsync`. - */ -#define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0)) - -/** - * The right to invoke `fd_read` and `sock_recv`. - * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. - */ -#define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1)) - -/** - * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. - */ -#define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2)) - -/** - * The right to invoke `fd_fdstat_set_flags`. - */ -#define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3)) - -/** - * The right to invoke `fd_sync`. - * If `path_open` is set, includes the right to invoke - * `path_open` with `fdflags::rsync` and `fdflags::dsync`. - */ -#define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4)) - -/** - * The right to invoke `fd_seek` in such a way that the file offset - * remains unaltered (i.e., `whence::cur` with offset zero), or to - * invoke `fd_tell`. - */ -#define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5)) - -/** - * The right to invoke `fd_write` and `sock_send`. - * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. - */ -#define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6)) - -/** - * The right to invoke `fd_advise`. - */ -#define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7)) - -/** - * The right to invoke `fd_allocate`. - */ -#define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8)) - -/** - * The right to invoke `path_create_directory`. - */ -#define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9)) - -/** - * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`. - */ -#define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10)) - -/** - * The right to invoke `path_link` with the file descriptor as the - * source directory. - */ -#define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11)) - -/** - * The right to invoke `path_link` with the file descriptor as the - * target directory. - */ -#define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12)) - -/** - * The right to invoke `path_open`. - */ -#define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13)) - -/** - * The right to invoke `fd_readdir`. - */ -#define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14)) - -/** - * The right to invoke `path_readlink`. - */ -#define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15)) - -/** - * The right to invoke `path_rename` with the file descriptor as the source directory. - */ -#define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16)) - -/** - * The right to invoke `path_rename` with the file descriptor as the target directory. - */ -#define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17)) - -/** - * The right to invoke `path_filestat_get`. - */ -#define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18)) - -/** - * The right to change a file's size (there is no `path_filestat_set_size`). - * If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. - */ -#define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19)) - -/** - * The right to invoke `path_filestat_set_times`. - */ -#define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20)) - -/** - * The right to invoke `fd_filestat_get`. - */ -#define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21)) - -/** - * The right to invoke `fd_filestat_set_size`. - */ -#define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22)) - -/** - * The right to invoke `fd_filestat_set_times`. - */ -#define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23)) - -/** - * The right to invoke `path_symlink`. - */ -#define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24)) - -/** - * The right to invoke `path_remove_directory`. - */ -#define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25)) - -/** - * The right to invoke `path_unlink_file`. - */ -#define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26)) - -/** - * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. - * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. - */ -#define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27)) - -/** - * The right to invoke `sock_shutdown`. - */ -#define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28)) - -/** - * The right to invoke `sock_accept`. - */ -#define __WASI_RIGHTS_SOCK_ACCEPT ((__wasi_rights_t)(1 << 29)) - -/** - * A file descriptor handle. - */ -typedef int __wasi_fd_t; - -_Static_assert(sizeof(__wasi_fd_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_fd_t) == 4, "witx calculated align"); - -/** - * A region of memory for scatter/gather reads. - */ -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; - -_Static_assert(sizeof(__wasi_iovec_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_iovec_t) == 4, "witx calculated align"); -_Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_iovec_t, buf_len) == 4, "witx calculated offset"); - -/** - * A region of memory for scatter/gather writes. - */ -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; - -_Static_assert(sizeof(__wasi_ciovec_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_ciovec_t) == 4, "witx calculated align"); -_Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_ciovec_t, buf_len) == 4, "witx calculated offset"); - -/** - * Relative offset within a file. - */ -typedef int64_t __wasi_filedelta_t; - -_Static_assert(sizeof(__wasi_filedelta_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_filedelta_t) == 8, "witx calculated align"); - -/** - * The position relative to which to set the offset of the file descriptor. - */ -typedef uint8_t __wasi_whence_t; - -/** - * Seek relative to start-of-file. - */ -#define __WASI_WHENCE_SET (UINT8_C(0)) - -/** - * Seek relative to current position. - */ -#define __WASI_WHENCE_CUR (UINT8_C(1)) - -/** - * Seek relative to end-of-file. - */ -#define __WASI_WHENCE_END (UINT8_C(2)) - -_Static_assert(sizeof(__wasi_whence_t) == 1, "witx calculated size"); -_Static_assert(_Alignof(__wasi_whence_t) == 1, "witx calculated align"); - -/** - * A reference to the offset of a directory entry. - * - * The value 0 signifies the start of the directory. - */ -typedef uint64_t __wasi_dircookie_t; - -_Static_assert(sizeof(__wasi_dircookie_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_dircookie_t) == 8, "witx calculated align"); - -/** - * The type for the `dirent::d_namlen` field of `dirent` struct. - */ -typedef uint32_t __wasi_dirnamlen_t; - -_Static_assert(sizeof(__wasi_dirnamlen_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_dirnamlen_t) == 4, "witx calculated align"); - -/** - * File serial number that is unique within its file system. - */ -typedef uint64_t __wasi_inode_t; - -_Static_assert(sizeof(__wasi_inode_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_inode_t) == 8, "witx calculated align"); - -/** - * The type of a file descriptor or file. - */ -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 (UINT8_C(0)) - -/** - * The file descriptor or file refers to a block device inode. - */ -#define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1)) - -/** - * The file descriptor or file refers to a character device inode. - */ -#define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2)) - -/** - * The file descriptor or file refers to a directory inode. - */ -#define __WASI_FILETYPE_DIRECTORY (UINT8_C(3)) - -/** - * The file descriptor or file refers to a regular file inode. - */ -#define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4)) - -/** - * The file descriptor or file refers to a datagram socket. - */ -#define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5)) - -/** - * The file descriptor or file refers to a byte-stream socket. - */ -#define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6)) - -/** - * The file refers to a symbolic link inode. - */ -#define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7)) - -_Static_assert(sizeof(__wasi_filetype_t) == 1, "witx calculated size"); -_Static_assert(_Alignof(__wasi_filetype_t) == 1, "witx calculated align"); - -/** - * A directory entry. - */ -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; - -_Static_assert(sizeof(__wasi_dirent_t) == 24, "witx calculated size"); -_Static_assert(_Alignof(__wasi_dirent_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "witx calculated offset"); -_Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "witx calculated offset"); -_Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "witx calculated offset"); - -/** - * File or memory access pattern advisory information. - */ -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 (UINT8_C(0)) - -/** - * The application expects to access the specified data sequentially from lower offsets to higher offsets. - */ -#define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1)) - -/** - * The application expects to access the specified data in a random order. - */ -#define __WASI_ADVICE_RANDOM (UINT8_C(2)) - -/** - * The application expects to access the specified data in the near future. - */ -#define __WASI_ADVICE_WILLNEED (UINT8_C(3)) - -/** - * The application expects that it will not access the specified data in the near future. - */ -#define __WASI_ADVICE_DONTNEED (UINT8_C(4)) - -/** - * The application expects to access the specified data once and then not reuse it thereafter. - */ -#define __WASI_ADVICE_NOREUSE (UINT8_C(5)) - -_Static_assert(sizeof(__wasi_advice_t) == 1, "witx calculated size"); -_Static_assert(_Alignof(__wasi_advice_t) == 1, "witx calculated align"); - -/** - * File descriptor flags. - */ -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 << 0)) - -/** - * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. - */ -#define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1)) - -/** - * Non-blocking mode. - */ -#define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2)) - -/** - * Synchronized read I/O operations. - */ -#define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3)) - -/** - * Write according to synchronized I/O file integrity completion. In - * addition to synchronizing the data stored in the file, the implementation - * may also synchronously update the file's metadata. - */ -#define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4)) - -/** - * 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; - -_Static_assert(sizeof(__wasi_fdstat_t) == 24, "witx calculated size"); -_Static_assert(_Alignof(__wasi_fdstat_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_fdstat_t, fs_filetype) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "witx calculated offset"); -_Static_assert(offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "witx calculated offset"); -_Static_assert(offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16, "witx calculated offset"); - -/** - * Identifier for a device containing a file system. Can be used in combination - * with `inode` to uniquely identify a file or directory in the filesystem. - */ -typedef uint64_t __wasi_device_t; - -_Static_assert(sizeof(__wasi_device_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_device_t) == 8, "witx calculated align"); - -/** - * Which file time attributes to adjust. - */ -typedef uint16_t __wasi_fstflags_t; - -/** - * Adjust the last data access timestamp to the value stored in `filestat::atim`. - */ -#define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0)) - -/** - * Adjust the last data access timestamp to the time of clock `clockid::realtime`. - */ -#define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1)) - -/** - * Adjust the last data modification timestamp to the value stored in `filestat::mtim`. - */ -#define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2)) - -/** - * Adjust the last data modification timestamp to the time of clock `clockid::realtime`. - */ -#define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3)) - -/** - * 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 << 0)) - -/** - * 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 << 0)) - -/** - * Fail if not a directory. - */ -#define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1)) - -/** - * Fail if file already exists. - */ -#define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2)) - -/** - * Truncate file to size 0. - */ -#define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3)) - -/** - * Number of hard links to an inode. - */ -typedef uint64_t __wasi_linkcount_t; - -_Static_assert(sizeof(__wasi_linkcount_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_linkcount_t) == 8, "witx calculated align"); - -/** - * File attributes. - */ -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; - -_Static_assert(sizeof(__wasi_filestat_t) == 64, "witx calculated size"); -_Static_assert(_Alignof(__wasi_filestat_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_filestat_t, dev) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, ino) == 8, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, filetype) == 16, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, nlink) == 24, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, size) == 32, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, atim) == 40, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, mtim) == 48, "witx calculated offset"); -_Static_assert(offsetof(__wasi_filestat_t, ctim) == 56, "witx calculated offset"); - -/** - * User-provided value that may be attached to objects that is retained when - * extracted from the implementation. - */ -typedef uint64_t __wasi_userdata_t; - -_Static_assert(sizeof(__wasi_userdata_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_userdata_t) == 8, "witx calculated align"); - -/** - * Type of a subscription to an event or its occurrence. - */ -typedef uint8_t __wasi_eventtype_t; - -/** - * The time value of clock `subscription_clock::id` has - * reached timestamp `subscription_clock::timeout`. - */ -#define __WASI_EVENTTYPE_CLOCK (UINT8_C(0)) - -/** - * File descriptor `subscription_fd_readwrite::file_descriptor` has data - * available for reading. This event always triggers for regular files. - */ -#define __WASI_EVENTTYPE_FD_READ (UINT8_C(1)) - -/** - * File descriptor `subscription_fd_readwrite::file_descriptor` has capacity - * available for writing. This event always triggers for regular files. - */ -#define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2)) - -_Static_assert(sizeof(__wasi_eventtype_t) == 1, "witx calculated size"); -_Static_assert(_Alignof(__wasi_eventtype_t) == 1, "witx calculated align"); - -/** - * The state of the file descriptor subscribed to with - * `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 << 0)) - -/** - * 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; - -_Static_assert(sizeof(__wasi_event_fd_readwrite_t) == 16, "witx calculated size"); -_Static_assert(_Alignof(__wasi_event_fd_readwrite_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_event_fd_readwrite_t, nbytes) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_event_fd_readwrite_t, flags) == 8, "witx calculated offset"); - -/** - * An event that occurred. - */ -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 event that occured - */ - __wasi_eventtype_t type; - - /** - * The contents of the event, if it is an `eventtype::fd_read` or - * `eventtype::fd_write`. `eventtype::clock` events ignore this field. - */ - __wasi_event_fd_readwrite_t fd_readwrite; - -} __wasi_event_t; - -_Static_assert(sizeof(__wasi_event_t) == 32, "witx calculated size"); -_Static_assert(_Alignof(__wasi_event_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_event_t, userdata) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_event_t, error) == 8, "witx calculated offset"); -_Static_assert(offsetof(__wasi_event_t, type) == 10, "witx calculated offset"); -_Static_assert(offsetof(__wasi_event_t, fd_readwrite) == 16, "witx calculated offset"); - -/** - * Flags determining how to interpret the timestamp provided in - * `subscription_clock::timeout`. - */ -typedef uint16_t __wasi_subclockflags_t; - -/** - * If set, treat the timestamp provided in - * `subscription_clock::timeout` as an absolute timestamp of clock - * `subscription_clock::id`. If clear, treat the timestamp - * provided in `subscription_clock::timeout` relative to the - * current time value of clock `subscription_clock::id`. - */ -#define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0)) - -/** - * 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; - -_Static_assert(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_clock_t, id) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset"); - -/** - * The contents of a `subscription` when type is type is - * `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; - -_Static_assert(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_fd_readwrite_t, file_descriptor) == 0, "witx calculated offset"); - -/** - * The contents of a `subscription`. - */ -typedef union __wasi_subscription_u_u_t { - __wasi_subscription_clock_t clock; - __wasi_subscription_fd_readwrite_t fd_read; - __wasi_subscription_fd_readwrite_t fd_write; -} __wasi_subscription_u_u_t; -typedef struct __wasi_subscription_u_t { - uint8_t tag; - __wasi_subscription_u_u_t u; -} __wasi_subscription_u_t; - -_Static_assert(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align"); - -/** - * Subscription to an event. - */ -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, and its contents - */ - __wasi_subscription_u_t u; - -} __wasi_subscription_t; - -_Static_assert(sizeof(__wasi_subscription_t) == 48, "witx calculated size"); -_Static_assert(_Alignof(__wasi_subscription_t) == 8, "witx calculated align"); -_Static_assert(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset"); -_Static_assert(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset"); - -/** - * Exit code generated by a process when exiting. - */ -typedef uint32_t __wasi_exitcode_t; - -_Static_assert(sizeof(__wasi_exitcode_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_exitcode_t) == 4, "witx calculated align"); - -/** - * Flags provided to `sock_recv`. - */ -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 << 0)) - -/** - * On byte-stream sockets, block until the full amount of data can be returned. - */ -#define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1)) - -/** - * 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 << 0)) - -/** - * Flags provided to `sock_send`. As there are currently no flags - * defined, it must be set to zero. - */ -typedef uint16_t __wasi_siflags_t; - -_Static_assert(sizeof(__wasi_siflags_t) == 2, "witx calculated size"); -_Static_assert(_Alignof(__wasi_siflags_t) == 2, "witx calculated align"); - -/** - * Which channels on a socket to shut down. - */ -typedef uint8_t __wasi_sdflags_t; - -/** - * Disables further receive operations. - */ -#define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0)) - -/** - * Disables further send operations. - */ -#define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1)) - -/** - * Identifiers for preopened capabilities. - */ -typedef uint8_t __wasi_preopentype_t; - -/** - * A pre-opened directory. - */ -#define __WASI_PREOPENTYPE_DIR (UINT8_C(0)) - -_Static_assert(sizeof(__wasi_preopentype_t) == 1, "witx calculated size"); -_Static_assert(_Alignof(__wasi_preopentype_t) == 1, "witx calculated align"); - -/** - * The contents of a $prestat when type is `preopentype::dir`. - */ -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; - -_Static_assert(sizeof(__wasi_prestat_dir_t) == 4, "witx calculated size"); -_Static_assert(_Alignof(__wasi_prestat_dir_t) == 4, "witx calculated align"); -_Static_assert(offsetof(__wasi_prestat_dir_t, pr_name_len) == 0, "witx calculated offset"); - -/** - * Information about a pre-opened capability. - */ -typedef union __wasi_prestat_u_t { - __wasi_prestat_dir_t dir; -} __wasi_prestat_u_t; -typedef struct __wasi_prestat_t { - uint8_t tag; - __wasi_prestat_u_t u; -} __wasi_prestat_t; - -_Static_assert(sizeof(__wasi_prestat_t) == 8, "witx calculated size"); -_Static_assert(_Alignof(__wasi_prestat_t) == 4, "witx calculated align"); - -/** - * @defgroup wasi_snapshot_preview1 - * @{ - */ - -/** - * Read command-line argument data. - * The size of the array should match that returned by `args_sizes_get`. - * Each argument is expected to be `\0` terminated. - */ -__wasi_errno_t __wasi_args_get( - uint8_t * * argv, - uint8_t * argv_buf -) __attribute__((__warn_unused_result__)); -/** - * Return command-line argument data sizes. - * @return - * Returns the number of arguments and the size of the argument string - * data, or an error. - */ -__wasi_errno_t __wasi_args_sizes_get( - __wasi_size_t *retptr0, - __wasi_size_t *retptr1 -) __attribute__((__warn_unused_result__)); -/** - * Read environment variable data. - * The sizes of the buffers should match that returned by `environ_sizes_get`. - * Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s. - */ -__wasi_errno_t __wasi_environ_get( - uint8_t * * environ, - uint8_t * environ_buf -) __attribute__((__warn_unused_result__)); -/** - * Return environment variable data sizes. - * @return - * Returns the number of environment variable arguments and the size of the - * environment variable data. - */ -__wasi_errno_t __wasi_environ_sizes_get( - __wasi_size_t *retptr0, - __wasi_size_t *retptr1 -) __attribute__((__warn_unused_result__)); -/** - * Return the resolution of a clock. - * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, - * return `errno::inval`. - * Note: This is similar to `clock_getres` in POSIX. - * @return - * The resolution of the clock, or an error if one happened. - */ -__wasi_errno_t __wasi_clock_res_get( - /** - * The clock for which to return the resolution. - */ - __wasi_clockid_t id, - __wasi_timestamp_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Return the time value of a clock. - * Note: This is similar to `clock_gettime` in POSIX. - * @return - * The time value of the clock. - */ -__wasi_errno_t __wasi_clock_time_get( - /** - * The clock for which to return the time. - */ - __wasi_clockid_t id, - /** - * The maximum lag (exclusive) that the returned time value may have, compared to its actual value. - */ - __wasi_timestamp_t precision, - __wasi_timestamp_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Provide file advisory information on a file descriptor. - * Note: This is similar to `posix_fadvise` in POSIX. - */ -__wasi_errno_t __wasi_fd_advise( - __wasi_fd_t fd, - /** - * The offset within the file to which the advisory applies. - */ - __wasi_filesize_t offset, - /** - * The length of the region to which the advisory applies. - */ - __wasi_filesize_t len, - /** - * The advice. - */ - __wasi_advice_t advice -) __attribute__((__warn_unused_result__)); -/** - * Force the allocation of space in a file. - * Note: This is similar to `posix_fallocate` in POSIX. - */ -__wasi_errno_t __wasi_fd_allocate( - __wasi_fd_t fd, - /** - * The offset at which to start the allocation. - */ - __wasi_filesize_t offset, - /** - * The length of the area that is allocated. - */ - __wasi_filesize_t len -) __attribute__((__warn_unused_result__)); -/** - * Close a file descriptor. - * Note: This is similar to `close` in POSIX. - */ -__wasi_errno_t __wasi_fd_close( - __wasi_fd_t fd -) __attribute__((__warn_unused_result__)); -/** - * Synchronize the data of a file to disk. - * Note: This is similar to `fdatasync` in POSIX. - */ -__wasi_errno_t __wasi_fd_datasync( - __wasi_fd_t fd -) __attribute__((__warn_unused_result__)); -/** - * Get the attributes of a file descriptor. - * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. - * @return - * The buffer where the file descriptor's attributes are stored. - */ -__wasi_errno_t __wasi_fd_fdstat_get( - __wasi_fd_t fd, - __wasi_fdstat_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Adjust the flags associated with a file descriptor. - * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. - */ -__wasi_errno_t __wasi_fd_fdstat_set_flags( - __wasi_fd_t fd, - /** - * The desired values of the file descriptor flags. - */ - __wasi_fdflags_t flags -) __attribute__((__warn_unused_result__)); -/** - * Adjust the rights associated with a file descriptor. - * This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights - */ -__wasi_errno_t __wasi_fd_fdstat_set_rights( - __wasi_fd_t fd, - /** - * The desired rights of the file descriptor. - */ - __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting -) __attribute__((__warn_unused_result__)); -/** - * Return the attributes of an open file. - * @return - * The buffer where the file's attributes are stored. - */ -__wasi_errno_t __wasi_fd_filestat_get( - __wasi_fd_t fd, - __wasi_filestat_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. - * Note: This is similar to `ftruncate` in POSIX. - */ -__wasi_errno_t __wasi_fd_filestat_set_size( - __wasi_fd_t fd, - /** - * The desired file size. - */ - __wasi_filesize_t size -) __attribute__((__warn_unused_result__)); -/** - * Adjust the timestamps of an open file or directory. - * Note: This is similar to `futimens` in POSIX. - */ -__wasi_errno_t __wasi_fd_filestat_set_times( - __wasi_fd_t fd, - /** - * The desired values of the data access timestamp. - */ - __wasi_timestamp_t atim, - /** - * The desired values of the data modification timestamp. - */ - __wasi_timestamp_t mtim, - /** - * A bitmask indicating which timestamps to adjust. - */ - __wasi_fstflags_t fst_flags -) __attribute__((__warn_unused_result__)); -/** - * Read from a file descriptor, without using and updating the file descriptor's offset. - * Note: This is similar to `preadv` in POSIX. - * @return - * The number of bytes read. - */ -__wasi_errno_t __wasi_fd_pread( - __wasi_fd_t fd, - /** - * List of scatter/gather vectors in which to store data. - */ - const __wasi_iovec_t *iovs, - /** - * The length of the array pointed to by `iovs`. - */ - size_t iovs_len, - /** - * The offset within the file at which to read. - */ - __wasi_filesize_t offset, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Return a description of the given preopened file descriptor. - * @return - * The buffer where the description is stored. - */ -__wasi_errno_t __wasi_fd_prestat_get( - __wasi_fd_t fd, - __wasi_prestat_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Return a description of the given preopened file descriptor. - */ -__wasi_errno_t __wasi_fd_prestat_dir_name( - __wasi_fd_t fd, - /** - * A buffer into which to write the preopened directory name. - */ - uint8_t * path, - __wasi_size_t path_len -) __attribute__((__warn_unused_result__)); -/** - * Write to a file descriptor, without using and updating the file descriptor's offset. - * Note: This is similar to `pwritev` in POSIX. - * @return - * The number of bytes written. - */ -__wasi_errno_t __wasi_fd_pwrite( - __wasi_fd_t fd, - /** - * List of scatter/gather vectors from which to retrieve data. - */ - const __wasi_ciovec_t *iovs, - /** - * The length of the array pointed to by `iovs`. - */ - size_t iovs_len, - /** - * The offset within the file at which to write. - */ - __wasi_filesize_t offset, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Read from a file descriptor. - * Note: This is similar to `readv` in POSIX. - * @return - * The number of bytes read. - */ -__wasi_errno_t __wasi_fd_read( - __wasi_fd_t fd, - /** - * List of scatter/gather vectors to which to store data. - */ - const __wasi_iovec_t *iovs, - /** - * The length of the array pointed to by `iovs`. - */ - size_t iovs_len, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Read directory entries from a directory. - * When successful, the contents of the output buffer consist of a sequence of - * directory entries. Each directory entry consists of a `dirent` object, - * followed by `dirent::d_namlen` bytes holding the name of the directory - * entry. - * This function fills the output buffer as much as possible, potentially - * truncating the last directory entry. This allows the caller to grow its - * read buffer size in case it's too small to fit a single large directory - * entry, or skip the oversized directory entry. - * @return - * The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. - */ -__wasi_errno_t __wasi_fd_readdir( - __wasi_fd_t fd, - /** - * The buffer where directory entries are stored - */ - uint8_t * buf, - __wasi_size_t buf_len, - /** - * The location within the directory to start reading - */ - __wasi_dircookie_t cookie, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Atomically replace a file descriptor by renumbering another file descriptor. - * Due to the strong focus on thread safety, this environment does not provide - * 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( - __wasi_fd_t fd, - /** - * The file descriptor to overwrite. - */ - __wasi_fd_t to -) __attribute__((__warn_unused_result__)); -/** - * Move the offset of a file descriptor. - * Note: This is similar to `lseek` in POSIX. - * @return - * The new offset of the file descriptor, relative to the start of the file. - */ -__wasi_errno_t __wasi_fd_seek( - __wasi_fd_t fd, - /** - * The number of bytes to move. - */ - __wasi_filedelta_t offset, - /** - * The base from which the offset is relative. - */ - __wasi_whence_t whence, - __wasi_filesize_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Synchronize the data and metadata of a file to disk. - * Note: This is similar to `fsync` in POSIX. - */ -__wasi_errno_t __wasi_fd_sync( - __wasi_fd_t fd -) __attribute__((__warn_unused_result__)); -/** - * Return the current offset of a file descriptor. - * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. - * @return - * The current offset of the file descriptor, relative to the start of the file. - */ -__wasi_errno_t __wasi_fd_tell( - __wasi_fd_t fd, - __wasi_filesize_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Write to a file descriptor. - * Note: This is similar to `writev` in POSIX. - */ -__wasi_errno_t __wasi_fd_write( - __wasi_fd_t fd, - /** - * List of scatter/gather vectors from which to retrieve data. - */ - const __wasi_ciovec_t *iovs, - /** - * The length of the array pointed to by `iovs`. - */ - size_t iovs_len, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Create a directory. - * Note: This is similar to `mkdirat` in POSIX. - */ -__wasi_errno_t __wasi_path_create_directory( - __wasi_fd_t fd, - /** - * The path at which to create the directory. - */ - const char *path -) __attribute__((__warn_unused_result__)); -/** - * Return the attributes of a file or directory. - * Note: This is similar to `stat` in POSIX. - * @return - * The buffer where the file's attributes are stored. - */ -__wasi_errno_t __wasi_path_filestat_get( - __wasi_fd_t fd, - /** - * Flags determining the method of how the path is resolved. - */ - __wasi_lookupflags_t flags, - /** - * The path of the file or directory to inspect. - */ - const char *path, - __wasi_filestat_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Adjust the timestamps of a file or directory. - * Note: This is similar to `utimensat` in POSIX. - */ -__wasi_errno_t __wasi_path_filestat_set_times( - __wasi_fd_t fd, - /** - * Flags determining the method of how the path is resolved. - */ - __wasi_lookupflags_t flags, - /** - * The path of the file or directory to operate on. - */ - const char *path, - /** - * The desired values of the data access timestamp. - */ - __wasi_timestamp_t atim, - /** - * The desired values of the data modification timestamp. - */ - __wasi_timestamp_t mtim, - /** - * A bitmask indicating which timestamps to adjust. - */ - __wasi_fstflags_t fst_flags -) __attribute__((__warn_unused_result__)); -/** - * Create a hard link. - * Note: This is similar to `linkat` in POSIX. - */ -__wasi_errno_t __wasi_path_link( - __wasi_fd_t old_fd, - /** - * Flags determining the method of how the path is resolved. - */ - __wasi_lookupflags_t old_flags, - /** - * The source path from which to link. - */ - const char *old_path, - /** - * The working directory at which the resolution of the new path starts. - */ - __wasi_fd_t new_fd, - /** - * The destination path at which to create the hard link. - */ - const char *new_path -) __attribute__((__warn_unused_result__)); -/** - * Open a file or directory. - * The returned file descriptor is not guaranteed to be the lowest-numbered - * 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. - * @return - * The file descriptor of the file that has been opened. - */ -__wasi_errno_t __wasi_path_open( - __wasi_fd_t fd, - /** - * Flags determining the method of how the path is resolved. - */ - __wasi_lookupflags_t dirflags, - /** - * The relative path of the file or directory to open, relative to the - * `path_open::fd` directory. - */ - const char *path, - /** - * 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_inheriting, - __wasi_fdflags_t fdflags, - __wasi_fd_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Read the contents of a symbolic link. - * Note: This is similar to `readlinkat` in POSIX. - * @return - * The number of bytes placed in the buffer. - */ -__wasi_errno_t __wasi_path_readlink( - __wasi_fd_t fd, - /** - * The path of the symbolic link from which to read. - */ - const char *path, - /** - * The buffer to which to write the contents of the symbolic link. - */ - uint8_t * buf, - __wasi_size_t buf_len, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Remove a directory. - * Return `errno::notempty` if the directory is not empty. - * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. - */ -__wasi_errno_t __wasi_path_remove_directory( - __wasi_fd_t fd, - /** - * The path to a directory to remove. - */ - const char *path -) __attribute__((__warn_unused_result__)); -/** - * Rename a file or directory. - * Note: This is similar to `renameat` in POSIX. - */ -__wasi_errno_t __wasi_path_rename( - __wasi_fd_t fd, - /** - * The source path of the file or directory to rename. - */ - const char *old_path, - /** - * The working directory at which the resolution of the new path starts. - */ - __wasi_fd_t new_fd, - /** - * The destination path to which to rename the file or directory. - */ - const char *new_path -) __attribute__((__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, - __wasi_fd_t fd, - /** - * The destination path at which to create the symbolic link. - */ - const char *new_path -) __attribute__((__warn_unused_result__)); -/** - * Unlink a file. - * Return `errno::isdir` if the path refers to a directory. - * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. - */ -__wasi_errno_t __wasi_path_unlink_file( - __wasi_fd_t fd, - /** - * The path to a file to unlink. - */ - const char *path -) __attribute__((__warn_unused_result__)); -/** - * Concurrently poll for the occurrence of a set of events. - * @return - * The number of events stored. - */ -__wasi_errno_t __wasi_poll_oneoff( - /** - * The events to which to subscribe. - */ - const __wasi_subscription_t * in, - /** - * The events that have occurred. - */ - __wasi_event_t * out, - /** - * Both the number of subscriptions and events. - */ - __wasi_size_t nsubscriptions, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Terminate the process normally. An exit code of 0 indicates successful - * termination of the program. The meanings of other values is dependent on - * the environment. - */ -_Noreturn void __wasi_proc_exit( - /** - * The exit code returned by the process. - */ - __wasi_exitcode_t rval -); -/** - * Temporarily yield execution of the calling thread. - * Note: This is similar to `sched_yield` in POSIX. - */ -__wasi_errno_t __wasi_sched_yield( - void -) __attribute__((__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, - __wasi_size_t buf_len -) __attribute__((__warn_unused_result__)); -/** - * Accept a new incoming connection. - * Note: This is similar to `accept` in POSIX. - * @return - * New socket connection - */ -__wasi_errno_t __wasi_sock_accept( - /** - * The listening socket. - */ - __wasi_fd_t fd, - /** - * The desired values of the file descriptor flags. - */ - __wasi_fdflags_t flags, - __wasi_fd_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Receive a message from a socket. - * Note: This is similar to `recv` in POSIX, though it also supports reading - * the data into multiple buffers in the manner of `readv`. - * @return - * Number of bytes stored in ri_data and message flags. - */ -__wasi_errno_t __wasi_sock_recv( - __wasi_fd_t fd, - /** - * List of scatter/gather vectors to which to store data. - */ - const __wasi_iovec_t *ri_data, - /** - * The length of the array pointed to by `ri_data`. - */ - size_t ri_data_len, - /** - * Message flags. - */ - __wasi_riflags_t ri_flags, - __wasi_size_t *retptr0, - __wasi_roflags_t *retptr1 -) __attribute__((__warn_unused_result__)); -/** - * Send a message on a socket. - * Note: This is similar to `send` in POSIX, though it also supports writing - * the data from multiple buffers in the manner of `writev`. - * @return - * Number of bytes transmitted. - */ -__wasi_errno_t __wasi_sock_send( - __wasi_fd_t fd, - /** - * List of scatter/gather vectors to which to retrieve data - */ - const __wasi_ciovec_t *si_data, - /** - * The length of the array pointed to by `si_data`. - */ - size_t si_data_len, - /** - * Message flags. - */ - __wasi_siflags_t si_flags, - __wasi_size_t *retptr0 -) __attribute__((__warn_unused_result__)); -/** - * Shut down socket send and receive channels. - * Note: This is similar to `shutdown` in POSIX. - */ -__wasi_errno_t __wasi_sock_shutdown( - __wasi_fd_t fd, - /** - * Which channels on the socket to shut down. - */ - __wasi_sdflags_t how -) __attribute__((__warn_unused_result__)); -/** @} */ - -#ifdef _REENTRANT -/** - * Request a new thread to be created by the host. - * - * The host will create a new instance of the current module sharing its - * memory, find an exported entry function--`wasi_thread_start`--, and call the - * entry function with `start_arg` in the new thread. - * - * @see https://github.com/WebAssembly/wasi-threads/#readme - */ -int32_t __wasi_thread_spawn( - /** - * A pointer to an opaque struct to be passed to the module's entry - * function. - */ - void *start_arg -) __attribute__((__warn_unused_result__)); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wasi/libc-busywait.h b/lib/libc/include/wasm-wasi-musl/wasi/libc-busywait.h deleted file mode 100644 index c90017b8e03f7f3aae4a77dcb71dc7ba28c4b1f0..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wasi/libc-busywait.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __wasi_libc_busywait_h -#define __wasi_libc_busywait_h - -#ifdef __cplusplus -extern "C" { -#endif - -/// Enable busywait in futex on current thread. -void __wasilibc_enable_futex_busywait_on_current_thread(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wasi/libc-environ.h b/lib/libc/include/wasm-wasi-musl/wasi/libc-environ.h deleted file mode 100644 index f84ba8e606492fc679d8bb8d51b917007889aa3f..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wasi/libc-environ.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef __wasi_libc_environ_h -#define __wasi_libc_environ_h - -/// This header file is a WASI-libc-specific interface, and is not needed by -/// most programs. Most programs should just use the standard `getenv` and -/// related APIs, which take care of all of the details automatically. - -#ifdef __cplusplus -extern "C" { -#endif - -/// Initialize the global environment variable state. Only needs to be -/// called once; most users should call `__wasilibc_ensure_environ` instead. -void __wasilibc_initialize_environ(void); - -/// If `__wasilibc_initialize_environ` has not yet been called, call it. -void __wasilibc_ensure_environ(void); - -/// De-initialize the global environment variable state, so that subsequent -/// calls to `__wasilibc_ensure_environ` call `__wasilibc_initialize_environ`. -void __wasilibc_deinitialize_environ(void); - -/// Call `__wasilibc_initialize_environ` only if `environ` and `_environ` are -/// referenced in the program. -void __wasilibc_maybe_reinitialize_environ_eagerly(void); - -/// Return the value of the `environ` variable. Using `environ` directly -/// requires eager initialization of the environment variables. Using this -/// function instead of `environ` allows initialization to happen lazily. -char **__wasilibc_get_environ(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wasi/libc-find-relpath.h b/lib/libc/include/wasm-wasi-musl/wasi/libc-find-relpath.h deleted file mode 100644 index 32dbb03510761b9b2c1de2123039ca3450c2ef14..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wasi/libc-find-relpath.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __wasi_libc_find_relpath_h -#define __wasi_libc_find_relpath_h - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * Look up the given `path`, relative to the cwd, in the preopened directory - * map. If a suitable entry is found, then the file descriptor for that entry - * is returned. Additionally the absolute path of the directory's file - * descriptor is returned in `abs_prefix` and the relative portion that needs - * to be opened is stored in `*relative_path`. - * - * The `relative_path` argument must be a pointer to a buffer valid for - * `relative_path_len` bytes, and this may be used as storage for the relative - * portion of the path being returned through `*relative_path`. - * - * See documentation on `__wasilibc_find_abspath` for more info about what the - * paths look like. - * - * Returns -1 on failure. Errno is set to either: - * - * * ENOMEM - failed to allocate memory for internal routines. - * * ENOENT - the `path` could not be found relative to any preopened dir. - * * ERANGE - the `relative_path` buffer is too small to hold the relative path. - */ -int __wasilibc_find_relpath(const char *path, - const char **__restrict__ abs_prefix, - char **relative_path, - size_t relative_path_len); - -/** - * Look up the given `path`, which is interpreted as absolute, in the preopened - * directory map. If a suitable entry is found, then the file descriptor for - * that entry is returned. Additionally the relative portion of the path to - * where the fd is opened is returned through `relative_path`, the absolute - * prefix which was matched is stored to `abs_prefix`, and `relative_path` may - * be an interior pointer to the `abspath` string. - * - * The `abs_prefix` returned string will not contain a leading `/`. Note that - * this may be the empty string. Additionally the returned `relative_path` will - * not contain a leading `/`. The `relative_path` return will not return an - * empty string, it will return `"."` instead if it would otherwise do so. - * - * Returns -1 on failure. Errno is set to either: - * - * * ENOMEM - failed to allocate memory for internal routines. - * * ENOENT - the `path` could not be found relative to any preopened dir. - */ -int __wasilibc_find_abspath(const char *abspath, - const char **__restrict__ abs_prefix, - const char **__restrict__ relative_path); - -/** - * Same as `__wasilibc_find_relpath`, except that this function will interpret - * `relative` as a malloc'd buffer that will be `realloc`'d to the appropriate - * size to contain the relative path. - * - * Note that this is a weak symbol and if it's not defined you can use - * `__wasilibc_find_relpath`. The weak-nature of this symbols means that if it's - * not otherwise included in the compilation then `chdir` wasn't used an there's - * no need for this symbol. - * - * See documentation on `__wasilibc_find_relpath` for more information. - */ -int __wasilibc_find_relpath_alloc( - const char *path, - const char **abs, - char **relative, - size_t *relative_len, - int can_realloc -) __attribute__((__weak__)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wasi/libc-nocwd.h b/lib/libc/include/wasm-wasi-musl/wasi/libc-nocwd.h deleted file mode 100644 index a9885030d0c95d36bb41246b9b64b74cc181d1e7..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wasi/libc-nocwd.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef __wasi_libc_nocwd_h -#define __wasi_libc_nocwd_h - -/* - * In order to support AT_FDCWD, we need to wrap the *at functions to handle - * it by calling back into the non-at versions which perform libpreopen - * queries. These __wasilibc_nocwd_* forms are the underlying calls which - * assume AT_FDCWD has already been resolved. - */ - -#define __need_size_t -#include -#include <__typedef_ssize_t.h> -#include <__typedef_mode_t.h> -#include <__typedef_DIR.h> - -#ifdef __cplusplus -extern "C" { -#endif - -struct timespec; -struct stat; -struct dirent; - -int __wasilibc_nocwd___wasilibc_unlinkat(int, const char *) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd___wasilibc_rmdirat(int, const char *) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_linkat(int, const char *, int, const char *, int) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_symlinkat(const char *, int, const char *) - __attribute__((__warn_unused_result__)); -ssize_t __wasilibc_nocwd_readlinkat(int, const char *__restrict, char *__restrict, size_t) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_faccessat(int, const char *, int, int) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_renameat(int, const char *, int, const char *) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_openat_nomode(int, const char *, int) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_fstatat(int, const char *__restrict, struct stat *__restrict, int) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_mkdirat_nomode(int, const char *) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_utimensat(int, const char *, const struct timespec [2], int) - __attribute__((__warn_unused_result__)); -DIR *__wasilibc_nocwd_opendirat(int, const char *) - __attribute__((__warn_unused_result__)); -int __wasilibc_nocwd_scandirat(int, const char *, struct dirent ***, - int (*)(const struct dirent *), - int (*)(const struct dirent **, const struct dirent **)) - __attribute__((__warn_unused_result__)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wasi/libc.h b/lib/libc/include/wasm-wasi-musl/wasi/libc.h deleted file mode 100644 index e280f0e42169f769d6a91914ff5e7d01d58e8029..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wasi/libc.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef __wasi_libc_h -#define __wasi_libc_h - -#include <__typedef_off_t.h> -#include <__struct_timespec.h> -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct stat; -struct timespec; - -/// Populate libc's preopen tables. This is normally done automatically -/// just before it's needed, however if you call `__wasi_fd_renumber` or -/// `__wasi_fd_close` directly, and you need the preopens to be accurate -/// afterward, you should call this before doing so. -void __wasilibc_populate_preopens(void); - -/// Register the given pre-opened file descriptor under the given path. -/// -/// This function does not take ownership of `prefix` (it makes its own copy). -int __wasilibc_register_preopened_fd(int fd, const char *prefix); - -/// Renumber `fd` to `newfd`; similar to `dup2` but does a move rather than a -/// copy. -int __wasilibc_fd_renumber(int fd, int newfd) - __attribute__((__warn_unused_result__)); - -/// Like `unlinkat`, but without depending on `__wasi_path_remove_directory`. -int __wasilibc_unlinkat(int fd, const char *path) - __attribute__((__warn_unused_result__)); - -/// An `*at` version of rmdir. -int __wasilibc_rmdirat(int fd, const char *path) - __attribute__((__warn_unused_result__)); - -/// Like `open`, but without the varargs in the signature. -int __wasilibc_open_nomode(const char *path, int oflag); - -/// Like `openat`, but without the varargs in the signature. -int __wasilibc_openat_nomode(int fd, const char *path, int oflag); - -/// Return the current file offset. Like `lseek(fd, 0, SEEK_CUR)`, but without -/// depending on `lseek`. -off_t __wasilibc_tell(int fd) - __attribute__((__warn_unused_result__)); - -/* Non-`at` forms of various `*at` functions. */ -int __wasilibc_access(const char *pathname, int mode, int flags) - __attribute__((__warn_unused_result__)); -int __wasilibc_stat(const char *__restrict pathname, struct stat *__restrict statbuf, int flags) - __attribute__((__warn_unused_result__)); -int __wasilibc_utimens(const char *pathname, const struct timespec times[2], int flags) - __attribute__((__warn_unused_result__)); -int __wasilibc_link(const char *oldpath, const char *newpath, int flags) - __attribute__((__warn_unused_result__)); -int __wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags) - __attribute__((__warn_unused_result__)); -int __wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags) - __attribute__((__warn_unused_result__)); -int __wasilibc_rename_oldat(int olddirfd, const char *oldpath, const char *newpath) - __attribute__((__warn_unused_result__)); -int __wasilibc_rename_newat(const char *oldpath, int newdirfd, const char *newpath) - __attribute__((__warn_unused_result__)); - -/// Enable busywait in futex on current thread. -void __wasilibc_enable_futex_busywait_on_current_thread(void); - -/// Fill a buffer with random bytes -int __wasilibc_random(void* buffer, size_t len) - __attribute__((__warn_unused_result__)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/include/wasm-wasi-musl/wchar.h b/lib/libc/include/wasm-wasi-musl/wchar.h deleted file mode 100644 index 06b088aa9bde488d10892eae44f4f4635b5155ce..0000000000000000000000000000000000000000 --- a/lib/libc/include/wasm-wasi-musl/wchar.h +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef _WCHAR_H -#define _WCHAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_FILE -#define __NEED___isoc_va_list -#define __NEED_size_t -#define __NEED_wchar_t -#define __NEED_wint_t -#define __NEED_mbstate_t - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#if __STDC_VERSION__ < 201112L -#define __NEED_struct__IO_FILE -#endif -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_locale_t -#define __NEED_va_list -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_wctype_t -#endif - -#include - -#if L'\0'-1 > 0 -#define WCHAR_MAX (0xffffffffu+L'\0') -#define WCHAR_MIN (0+L'\0') -#else -#define WCHAR_MAX (0x7fffffff+L'\0') -#define WCHAR_MIN (-1-0x7fffffff+L'\0') -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#undef WEOF -#define WEOF 0xffffffffU - -wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -int wcscmp (const wchar_t *, const wchar_t *); -int wcsncmp (const wchar_t *, const wchar_t *, size_t); - -int wcscoll(const wchar_t *, const wchar_t *); -size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -wchar_t *wcschr (const wchar_t *, wchar_t); -wchar_t *wcsrchr (const wchar_t *, wchar_t); - -size_t wcscspn (const wchar_t *, const wchar_t *); -size_t wcsspn (const wchar_t *, const wchar_t *); -wchar_t *wcspbrk (const wchar_t *, const wchar_t *); - -wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); - -size_t wcslen (const wchar_t *); - -wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcswcs (const wchar_t *, const wchar_t *); - -wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); -int wmemcmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); -wchar_t *wmemset (wchar_t *, wchar_t, size_t); - -wint_t btowc (int); -int wctob (wint_t); - -int mbsinit (const mbstate_t *); -size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); -size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); - -size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); - -size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); -size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); - -float wcstof (const wchar_t *__restrict, wchar_t **__restrict); -double wcstod (const wchar_t *__restrict, wchar_t **__restrict); -long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); - -long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); -unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); - -long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); -unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); - - - -int fwide (FILE *, int); - - -int wprintf (const wchar_t *__restrict, ...); -int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); -int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); - -int vwprintf (const wchar_t *__restrict, __isoc_va_list); -int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); -int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); - -int wscanf (const wchar_t *__restrict, ...); -int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); -int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); - -int vwscanf (const wchar_t *__restrict, __isoc_va_list); -int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); -int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); - -wint_t fgetwc (FILE *); -wint_t getwc (FILE *); -wint_t getwchar (void); - -wint_t fputwc (wchar_t, FILE *); -wint_t putwc (wchar_t, FILE *); -wint_t putwchar (wchar_t); - -wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); -int fputws (const wchar_t *__restrict, FILE *__restrict); - -wint_t ungetwc (wint_t, FILE *); - -struct tm; -size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); - -#undef iswdigit - -#if defined(_GNU_SOURCE) -wint_t fgetwc_unlocked (FILE *); -wint_t getwc_unlocked (FILE *); -wint_t getwchar_unlocked (void); -wint_t fputwc_unlocked (wchar_t, FILE *); -wint_t putwc_unlocked (wchar_t, FILE *); -wint_t putwchar_unlocked (wchar_t); -wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); -int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -FILE *open_wmemstream(wchar_t **, size_t *); -size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); -size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); -wchar_t *wcsdup(const wchar_t *); -size_t wcsnlen (const wchar_t *, size_t); -wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -int wcscasecmp(const wchar_t *, const wchar_t *); -int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); -int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); -int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); -int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); -size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int wcwidth (wchar_t); -int wcswidth (const wchar_t *, size_t); -int iswalnum(wint_t); -int iswalpha(wint_t); -int iswblank(wint_t); -int iswcntrl(wint_t); -int iswdigit(wint_t); -int iswgraph(wint_t); -int iswlower(wint_t); -int iswprint(wint_t); -int iswpunct(wint_t); -int iswspace(wint_t); -int iswupper(wint_t); -int iswxdigit(wint_t); -int iswctype(wint_t, wctype_t); -wint_t towlower(wint_t); -wint_t towupper(wint_t); -wctype_t wctype(const char *); - -#ifndef __cplusplus -#undef iswdigit -#define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/LICENSE b/lib/libc/wasi/LICENSE deleted file mode 100644 index b0bfe6c10f06916057c200398da5f7d737de06a9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/LICENSE +++ /dev/null @@ -1,16 +0,0 @@ -wasi-libc as a whole is multi-licensed under the -Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, and -the MIT License. See the LICENSE-APACHE-LLVM, LICENSE-APACHE and LICENSE-MIT -files, respectively, for details. - -Portions of this software are derived from third-party works covered by -their own licenses: - -dlmalloc/ - CC0; see the notice in malloc.c for details -emmalloc/ - MIT; see the notice in emmalloc.c for details -libc-bottom-half/cloudlibc/ - BSD-2-Clause; see the LICENSE file for details -libc-top-half/musl/ - MIT; see the COPYRIGHT file for details - -wasi-libc's changes to these files are multi-licensed under the -Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, -the MIT License, and the original licenses of the third-party works. diff --git a/lib/libc/wasi/LICENSE-APACHE b/lib/libc/wasi/LICENSE-APACHE deleted file mode 100644 index 16fe87b06e802f094b3fbb0894b137bca2b16ef1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/LICENSE-APACHE +++ /dev/null @@ -1,201 +0,0 @@ - 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/lib/libc/wasi/LICENSE-APACHE-LLVM b/lib/libc/wasi/LICENSE-APACHE-LLVM deleted file mode 100644 index f9d81955f4bcb8f96a025e2ecc46f39ec536d465..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/LICENSE-APACHE-LLVM +++ /dev/null @@ -1,220 +0,0 @@ - - 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. - - ---- LLVM Exceptions to the Apache 2.0 License ---- - -As an exception, if, as a result of your compiling your source code, portions -of this Software are embedded into an Object form of such source code, you -may redistribute such embedded portions in such Object form without complying -with the conditions of Sections 4(a), 4(b) and 4(d) of the License. - -In addition, if you combine or link compiled forms of this Software with -software that is licensed under the GPLv2 ("Combined Software") and if a -court of competent jurisdiction determines that the patent provision (Section -3), the indemnity provision (Section 9) or other Section of the License -conflicts with the conditions of the GPLv2, you may retroactively and -prospectively choose to deem waived or otherwise exclude such Section(s) of -the License, but only in their entirety and only with respect to the Combined -Software. - diff --git a/lib/libc/wasi/LICENSE-MIT b/lib/libc/wasi/LICENSE-MIT deleted file mode 100644 index 31aa79387f27e730e33d871925e152e35e428031..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/LICENSE-MIT +++ /dev/null @@ -1,23 +0,0 @@ -Permission is hereby granted, free of charge, to any -person obtaining a copy of this software and associated -documentation files (the "Software"), to deal in the -Software without restriction, including without -limitation the rights to use, copy, modify, merge, -publish, distribute, sublicense, and/or sell copies of -the Software, and to permit persons to whom the Software -is furnished to do so, subject to the following -conditions: - -The above copyright notice and this permission notice -shall be included in all copies or substantial portions -of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF -ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED -TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A -PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT -SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR -IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. diff --git a/lib/libc/wasi/fts/config.h b/lib/libc/wasi/fts/config.h deleted file mode 100644 index abdd30401202eebbd81205a4e62ebf8c5c472d26..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/fts/config.h +++ /dev/null @@ -1,7 +0,0 @@ -#define HAVE_DECL_MAX 1 - -#define HAVE_DECL_UINTMAX_MAX 0 - -#define HAVE_DIRFD 1 - -#define HAVE_FCHDIR 0 diff --git a/lib/libc/wasi/fts/musl-fts/COPYING b/lib/libc/wasi/fts/musl-fts/COPYING deleted file mode 100644 index f06eb044ea895d23f0c02b9f0b2dc271c2ee34c1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/fts/musl-fts/COPYING +++ /dev/null @@ -1,26 +0,0 @@ -Copyright (c) 1989, 1993 - The Regents of the University of California. All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. -3. Neither the name of the University nor the names of its contributors - may be used to endorse or promote products derived from this software - without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. diff --git a/lib/libc/wasi/fts/musl-fts/fts.c b/lib/libc/wasi/fts/musl-fts/fts.c deleted file mode 100644 index da4bc0875641ac8292a6ebdbce91f69da80d4117..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/fts/musl-fts/fts.c +++ /dev/null @@ -1,1279 +0,0 @@ -/* $NetBSD: fts.c,v 1.48 2015/01/29 15:55:21 manu Exp $ */ - -/*- - * Copyright (c) 1990, 1993, 1994 - * The Regents of the University of California. All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if defined(LIBC_SCCS) && !defined(lint) -#if 0 -static char sccsid[] = "@(#)fts.c 8.6 (Berkeley) 8/14/94"; -#else -__RCSID("$NetBSD: fts.c,v 1.48 2015/01/29 15:55:21 manu Exp $"); -#endif -#endif /* LIBC_SCCS and not lint */ - -#include "config.h" - -#include -#include - -#include -#define _DIAGASSERT(e) -#include -#include -#include -#include -#include -#include -#include - -#if !defined(HAVE_DECL_MAX) || (HAVE_DECL_MAX==0) -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -#if !defined(UINT_MAX) && (HAVE_DECL_UINTMAX_MAX==1) -#define UINT_MAX UINTMAX_MAX -#endif - -#if !defined(HAVE_DIRFD) -#if defined(HAVE_DIR_DD_FD) -#define dirfd(dirp) ((dirp)->dd_fd) -#endif -#if defined(HAVE_DIR_D_FD) -#define dirfd(dirp) ((dirp)->d_fd) -#endif -#endif - -static FTSENT *fts_alloc(FTS *, const char *, size_t); -static FTSENT *fts_build(FTS *, int); -static void fts_free(FTSENT *); -static void fts_lfree(FTSENT *); -static void fts_load(FTS *, FTSENT *); -static size_t fts_maxarglen(char * const *); -static size_t fts_pow2(size_t); -static int fts_palloc(FTS *, size_t); -static void fts_padjust(FTS *, FTSENT *); -static FTSENT *fts_sort(FTS *, FTSENT *, size_t); -static unsigned short fts_stat(FTS *, FTSENT *, int); -static int fts_safe_changedir(const FTS *, const FTSENT *, int, - const char *); - -#if defined(ALIGNBYTES) && defined(ALIGN) -#define FTS_ALLOC_ALIGNED 1 -#else -#undef FTS_ALLOC_ALIGNED -#endif - -#ifndef ftsent_namelen_truncate -#define ftsent_namelen_truncate(a) \ - ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) -#endif -#ifndef ftsent_pathlen_truncate -#define ftsent_pathlen_truncate(a) \ - ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) -#endif -#ifndef fts_pathlen_truncate -#define fts_pathlen_truncate(a) \ - ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) -#endif -#ifndef fts_nitems_truncate -#define fts_nitems_truncate(a) \ - ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) -#endif - -#define ISDOT(a) (a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) - -#define CLR(opt) (sp->fts_options &= ~(opt)) -#define ISSET(opt) (sp->fts_options & (opt)) -#define SET(opt) (sp->fts_options |= (opt)) - -#if HAVE_FCHDIR -#define CHDIR(sp, path) (!ISSET(FTS_NOCHDIR) && chdir(path)) -#define FCHDIR(sp, fd) (!ISSET(FTS_NOCHDIR) && fchdir(fd)) -#else -/* If we don't have fchdir, pretend that !ISSET(FTS_NOCHDIR) is always false in - * the above macros, and do not reference chdir or fchdir. */ -#define CHDIR(sp, path) 0 -#define FCHDIR(sp, fd) 0 -#endif - -/* fts_build flags */ -#define BCHILD 1 /* fts_children */ -#define BNAMES 2 /* fts_children, names only */ -#define BREAD 3 /* fts_read */ - -#ifndef DTF_HIDEW -#undef FTS_WHITEOUT -#endif - -FTS * -fts_open(char * const *argv, int options, - int (*compar)(const FTSENT **, const FTSENT **)) -{ - FTS *sp; - FTSENT *p, *root; - size_t nitems; - FTSENT *parent, *tmp = NULL; /* pacify gcc */ - size_t len; - - _DIAGASSERT(argv != NULL); - -#if !HAVE_FCHDIR - /* If we don't have fchdir, pretend that FTS_NOCHDIR is always set. */ - options |= FTS_NOCHDIR; -#endif - - /* Options check. */ - if (options & ~FTS_OPTIONMASK) { - errno = EINVAL; - return (NULL); - } - - /* Allocate/initialize the stream */ - if ((sp = malloc(sizeof(FTS))) == NULL) - return (NULL); - memset(sp, 0, sizeof(FTS)); - sp->fts_compar = compar; - sp->fts_options = options; - - /* Logical walks turn on NOCHDIR; symbolic links are too hard. */ - if (ISSET(FTS_LOGICAL)) - SET(FTS_NOCHDIR); - - /* - * Start out with 1K of path space, and enough, in any case, - * to hold the user's paths. - */ - if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) - goto mem1; - - /* Allocate/initialize root's parent. */ - if ((parent = fts_alloc(sp, "", 0)) == NULL) - goto mem2; - parent->fts_level = FTS_ROOTPARENTLEVEL; - - /* Allocate/initialize root(s). */ - for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { - /* Don't allow zero-length paths. */ - if ((len = strlen(*argv)) == 0) { - errno = ENOENT; - goto mem3; - } - - if ((p = fts_alloc(sp, *argv, len)) == NULL) - goto mem3; - p->fts_level = FTS_ROOTLEVEL; - p->fts_parent = parent; - p->fts_accpath = p->fts_name; - p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); - - /* Command-line "." and ".." are real directories. */ - if (p->fts_info == FTS_DOT) - p->fts_info = FTS_D; - - /* - * If comparison routine supplied, traverse in sorted - * order; otherwise traverse in the order specified. - */ - if (compar) { - p->fts_link = root; - root = p; - } else { - p->fts_link = NULL; - if (root == NULL) - tmp = root = p; - else { - tmp->fts_link = p; - tmp = p; - } - } - } - if (compar && nitems > 1) - root = fts_sort(sp, root, nitems); - - /* - * Allocate a dummy pointer and make fts_read think that we've just - * finished the node before the root(s); set p->fts_info to FTS_INIT - * so that everything about the "current" node is ignored. - */ - if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) - goto mem3; - sp->fts_cur->fts_link = root; - sp->fts_cur->fts_info = FTS_INIT; - - /* - * If using chdir(2), grab a file descriptor pointing to dot to ensure - * that we can get back here; this could be avoided for some paths, - * but almost certainly not worth the effort. Slashes, symbolic links, - * and ".." are all fairly nasty problems. Note, if we can't get the - * descriptor we run anyway, just more slowly. - */ -#ifndef O_CLOEXEC -#define O_CLOEXEC 0 -#endif - if (!ISSET(FTS_NOCHDIR)) { - if ((sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) - SET(FTS_NOCHDIR); - } - - if (nitems == 0) - fts_free(parent); - - return (sp); - -mem3: fts_lfree(root); - fts_free(parent); -mem2: free(sp->fts_path); -mem1: free(sp); - return (NULL); -} - -static void -fts_load(FTS *sp, FTSENT *p) -{ - size_t len; - char *cp; - - _DIAGASSERT(sp != NULL); - _DIAGASSERT(p != NULL); - - /* - * Load the stream structure for the next traversal. Since we don't - * actually enter the directory until after the preorder visit, set - * the fts_accpath field specially so the chdir gets done to the right - * place and the user can access the first node. From fts_open it's - * known that the path will fit. - */ - len = p->fts_pathlen = p->fts_namelen; - memmove(sp->fts_path, p->fts_name, len + 1); - if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { - len = strlen(++cp); - memmove(p->fts_name, cp, len + 1); - p->fts_namelen = ftsent_namelen_truncate(len); - } - p->fts_accpath = p->fts_path = sp->fts_path; - sp->fts_dev = p->fts_dev; -} - -int -fts_close(FTS *sp) -{ - FTSENT *freep, *p; - int saved_errno = 0; - - _DIAGASSERT(sp != NULL); - - /* - * This still works if we haven't read anything -- the dummy structure - * points to the root list, so we step through to the end of the root - * list which has a valid parent pointer. - */ - if (sp->fts_cur) { - if (sp->fts_cur->fts_flags & FTS_SYMFOLLOW) - (void)close(sp->fts_cur->fts_symfd); - for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { - freep = p; - p = p->fts_link ? p->fts_link : p->fts_parent; - fts_free(freep); - } - fts_free(p); - } - - /* Free up child linked list, sort array, path buffer. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - if (sp->fts_array) - free(sp->fts_array); - free(sp->fts_path); - - #if HAVE_FCHDIR - /* Return to original directory, save errno if necessary. */ - if (!ISSET(FTS_NOCHDIR)) { - if (fchdir(sp->fts_rfd) == -1) - saved_errno = errno; - (void)close(sp->fts_rfd); - } - #endif - - /* Free up the stream pointer. */ - free(sp); - if (saved_errno) { - errno = saved_errno; - return -1; - } - - return 0; -} - -#if !defined(__FTS_COMPAT_TAILINGSLASH) - -/* - * Special case of "/" at the end of the path so that slashes aren't - * appended which would cause paths to be written as "....//foo". - */ -#define NAPPEND(p) \ - (p->fts_path[p->fts_pathlen - 1] == '/' \ - ? p->fts_pathlen - 1 : p->fts_pathlen) - -#else /* !defined(__FTS_COMPAT_TAILINGSLASH) */ - -/* - * compatibility with the old behaviour. - * - * Special case a root of "/" so that slashes aren't appended which would - * cause paths to be written as "//foo". - */ - -#define NAPPEND(p) \ - (p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 && \ - p->fts_path[0] == '/' ? 0 : p->fts_pathlen) - -#endif /* !defined(__FTS_COMPAT_TAILINGSLASH) */ - -FTSENT * -fts_read(FTS *sp) -{ - FTSENT *p, *tmp; - int instr; - char *t; - int saved_errno; - - _DIAGASSERT(sp != NULL); - - /* If finished or unrecoverable error, return NULL. */ - if (sp->fts_cur == NULL || ISSET(FTS_STOP)) - return (NULL); - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* Save and zero out user instructions. */ - instr = p->fts_instr; - p->fts_instr = FTS_NOINSTR; - - /* Any type of file may be re-visited; re-stat and re-turn. */ - if (instr == FTS_AGAIN) { - p->fts_info = fts_stat(sp, p, 0); - return (p); - } - - /* - * Following a symlink -- SLNONE test allows application to see - * SLNONE and recover. If indirecting through a symlink, have - * keep a pointer to current location. If unable to get that - * pointer, follow fails. - */ - if (instr == FTS_FOLLOW && - (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = open(".", O_RDONLY | O_CLOEXEC, 0)) - == -1) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - return (p); - } - - /* Directory in pre-order. */ - if (p->fts_info == FTS_D) { - /* If skipped or crossed mount point, do post-order visit. */ - if (instr == FTS_SKIP || - (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { - if (p->fts_flags & FTS_SYMFOLLOW) - (void)close(p->fts_symfd); - if (sp->fts_child) { - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - p->fts_info = FTS_DP; - return (p); - } - - /* Rebuild if only read the names and now traversing. */ - if (sp->fts_child && ISSET(FTS_NAMEONLY)) { - CLR(FTS_NAMEONLY); - fts_lfree(sp->fts_child); - sp->fts_child = NULL; - } - - /* - * Cd to the subdirectory. - * - * If have already read and now fail to chdir, whack the list - * to make the names come out right, and set the parent errno - * so the application will eventually get an error condition. - * Set the FTS_DONTCHDIR flag so that when we logically change - * directories back to the parent we don't do a chdir. - * - * If haven't read do so. If the read fails, fts_build sets - * FTS_STOP or the fts_info field of the node. - */ - if (sp->fts_child) { - if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { - p->fts_errno = errno; - p->fts_flags |= FTS_DONTCHDIR; - for (p = sp->fts_child; p; p = p->fts_link) - p->fts_accpath = - p->fts_parent->fts_accpath; - } - } else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { - if (ISSET(FTS_STOP)) - return (NULL); - return (p); - } - p = sp->fts_child; - sp->fts_child = NULL; - goto name; - } - -next: - /* Move to the next node on this level. */ - tmp = p; - - /* - * We are going to free sp->fts_cur, set it to NULL so - * that fts_close() does not attempt to free it again - * if we exit without setting it to a new value because - * FCHDIR() failed below. - */ - assert(tmp == sp->fts_cur); - sp->fts_cur = NULL; - - if ((p = p->fts_link) != NULL) { - fts_free(tmp); - - /* - * If reached the top, return to the original directory, and - * load the paths for the next root. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - fts_load(sp, p); - return (sp->fts_cur = p); - } - - /* - * User may have called fts_set on the node. If skipped, - * ignore. If followed, get a file descriptor so we can - * get back if necessary. - */ - if (p->fts_instr == FTS_SKIP) - goto next; - if (p->fts_instr == FTS_FOLLOW) { - p->fts_info = fts_stat(sp, p, 1); - if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { - if ((p->fts_symfd = - open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) { - p->fts_errno = errno; - p->fts_info = FTS_ERR; - } else - p->fts_flags |= FTS_SYMFOLLOW; - } - p->fts_instr = FTS_NOINSTR; - } - -name: t = sp->fts_path + NAPPEND(p->fts_parent); - *t++ = '/'; - memmove(t, p->fts_name, (size_t)(p->fts_namelen + 1)); - return (sp->fts_cur = p); - } - - /* Move up to the parent node. */ - p = tmp->fts_parent; - fts_free(tmp); - - if (p->fts_level == FTS_ROOTPARENTLEVEL) { - /* - * Done; free everything up and set errno to 0 so the user - * can distinguish between error and EOF. - */ - fts_free(p); - errno = 0; - return (sp->fts_cur = NULL); - } - - /* NUL terminate the pathname. */ - sp->fts_path[p->fts_pathlen] = '\0'; - - /* - * Return to the parent directory. If at a root node or came through - * a symlink, go back through the file descriptor. Otherwise, cd up - * one directory. - */ - if (p->fts_level == FTS_ROOTLEVEL) { - if (FCHDIR(sp, sp->fts_rfd)) { - SET(FTS_STOP); - return (NULL); - } - } else if (p->fts_flags & FTS_SYMFOLLOW) { - if (FCHDIR(sp, p->fts_symfd)) { - saved_errno = errno; - (void)close(p->fts_symfd); - errno = saved_errno; - SET(FTS_STOP); - return (NULL); - } - (void)close(p->fts_symfd); - } else if (!(p->fts_flags & FTS_DONTCHDIR) && - fts_safe_changedir(sp, p->fts_parent, -1, "..")) { - SET(FTS_STOP); - return (NULL); - } - p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; - return (sp->fts_cur = p); -} - -/* - * Fts_set takes the stream as an argument although it's not used in this - * implementation; it would be necessary if anyone wanted to add global - * semantics to fts using fts_set. An error return is allowed for similar - * reasons. - */ -/* ARGSUSED */ -int -fts_set(FTS *sp, FTSENT *p, int instr) -{ - - _DIAGASSERT(sp != NULL); - _DIAGASSERT(p != NULL); - - if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && - instr != FTS_NOINSTR && instr != FTS_SKIP) { - errno = EINVAL; - return (1); - } - p->fts_instr = instr; - return (0); -} - -FTSENT * -fts_children(FTS *sp, int instr) -{ - FTSENT *p; - int fd; - - _DIAGASSERT(sp != NULL); - - if (instr && instr != FTS_NAMEONLY) { - errno = EINVAL; - return (NULL); - } - - /* Set current node pointer. */ - p = sp->fts_cur; - - /* - * Errno set to 0 so user can distinguish empty directory from - * an error. - */ - errno = 0; - - /* Fatal errors stop here. */ - if (ISSET(FTS_STOP)) - return (NULL); - - /* Return logical hierarchy of user's arguments. */ - if (p->fts_info == FTS_INIT) - return (p->fts_link); - - /* - * If not a directory being visited in pre-order, stop here. Could - * allow FTS_DNR, assuming the user has fixed the problem, but the - * same effect is available with FTS_AGAIN. - */ - if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) - return (NULL); - - /* Free up any previous child list. */ - if (sp->fts_child) - fts_lfree(sp->fts_child); - - if (instr == FTS_NAMEONLY) { - SET(FTS_NAMEONLY); - instr = BNAMES; - } else - instr = BCHILD; - - #if HAVE_FCHDIR - /* - * If using chdir on a relative path and called BEFORE fts_read does - * its chdir to the root of a traversal, we can lose -- we need to - * chdir into the subdirectory, and we don't know where the current - * directory is, so we can't get back so that the upcoming chdir by - * fts_read will work. - */ - if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || - ISSET(FTS_NOCHDIR)) - return (sp->fts_child = fts_build(sp, instr)); - - if ((fd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) - return (sp->fts_child = NULL); - sp->fts_child = fts_build(sp, instr); - if (fchdir(fd)) { - (void)close(fd); - return (NULL); - } - (void)close(fd); - return (sp->fts_child); - #else - /* If not using chdir, just build the list. */ - return (sp->fts_child = fts_build(sp, instr)); - #endif -} - -/* - * This is the tricky part -- do not casually change *anything* in here. The - * idea is to build the linked list of entries that are used by fts_children - * and fts_read. There are lots of special cases. - * - * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is - * set and it's a physical walk (so that symbolic links can't be directories), - * we can do things quickly. First, if it's a 4.4BSD file system, the type - * of the file is in the directory entry. Otherwise, we assume that the number - * of subdirectories in a node is equal to the number of links to the parent. - * The former skips all stat calls. The latter skips stat calls in any leaf - * directories and for any files after the subdirectories in the directory have - * been found, cutting the stat calls by about 2/3. - */ -static FTSENT * -fts_build(FTS *sp, int type) -{ - struct dirent *dp; - FTSENT *p, *head; - size_t nitems; - FTSENT *cur, *tail; - DIR *dirp; - void *oldaddr; - size_t dnamlen; - int cderrno, descend, level, nlinks, saved_errno, nostat, doadjust; - size_t len, maxlen; -#ifdef FTS_WHITEOUT - int oflag; -#endif - char *cp = NULL; /* pacify gcc */ - - _DIAGASSERT(sp != NULL); - - /* Set current node pointer. */ - cur = sp->fts_cur; - - /* - * Open the directory for reading. If this fails, we're done. - * If being called from fts_read, set the fts_info field. - */ -#ifdef FTS_WHITEOUT - if (ISSET(FTS_WHITEOUT)) - oflag = DTF_NODUP|DTF_REWIND; - else - oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; -#else -#define __opendir2(path, flag) opendir(path) -#endif - if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { - if (type == BREAD) { - cur->fts_info = FTS_DNR; - cur->fts_errno = errno; - } - return (NULL); - } - - /* - * Nlinks is the number of possible entries of type directory in the - * directory if we're cheating on stat calls, 0 if we're not doing - * any stat calls at all, -1 if we're doing stats on everything. - */ - if (type == BNAMES) { - nlinks = 0; - nostat = 1; - } else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { - nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); - nostat = 1; - } else { - nlinks = -1; - nostat = 0; - } - -#ifdef notdef - (void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); - (void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", - ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); -#endif - /* - * If we're going to need to stat anything or we want to descend - * and stay in the directory, chdir. If this fails we keep going, - * but set a flag so we don't chdir after the post-order visit. - * We won't be able to stat anything, but we can still return the - * names themselves. Note, that since fts_read won't be able to - * chdir into the directory, it will have to return different path - * names than before, i.e. "a/b" instead of "b". Since the node - * has already been visited in pre-order, have to wait until the - * post-order visit to return the error. There is a special case - * here, if there was nothing to stat then it's not an error to - * not be able to stat. This is all fairly nasty. If a program - * needed sorted entries or stat information, they had better be - * checking FTS_NS on the returned nodes. - */ - cderrno = 0; - if (nlinks || type == BREAD) { - if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { - if (nlinks && type == BREAD) - cur->fts_errno = errno; - cur->fts_flags |= FTS_DONTCHDIR; - descend = 0; - cderrno = errno; - } else - descend = 1; - } else - descend = 0; - - /* - * Figure out the max file name length that can be stored in the - * current path -- the inner loop allocates more path as necessary. - * We really wouldn't have to do the maxlen calculations here, we - * could do them in fts_read before returning the path, but it's a - * lot easier here since the length is part of the dirent structure. - * - * If not changing directories set a pointer so that can just append - * each new name into the path. - */ - len = NAPPEND(cur); - if (ISSET(FTS_NOCHDIR)) { - cp = sp->fts_path + len; - *cp++ = '/'; - } - len++; - maxlen = sp->fts_pathlen - len; - -#if defined(__FTS_COMPAT_LEVEL) - if (cur->fts_level == SHRT_MAX) { - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = ENAMETOOLONG; - return (NULL); - } -#endif - - level = cur->fts_level + 1; - - /* Read the directory, attaching each entry to the `link' pointer. */ - doadjust = 0; - for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) { - - if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) - continue; - -#if defined(HAVE_STRUCT_DIRENT_D_NAMLEN) - dnamlen = dp->d_namlen; -#else - dnamlen = strlen(dp->d_name); -#endif - if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL) - goto mem1; - if (dnamlen >= maxlen) { /* include space for NUL */ - oldaddr = sp->fts_path; - if (fts_palloc(sp, dnamlen + len + 1)) { - /* - * No more memory for path or structures. Save - * errno, free up the current structure and the - * structures already allocated. - */ -mem1: saved_errno = errno; - if (p) - fts_free(p); - fts_lfree(head); - (void)closedir(dirp); - errno = saved_errno; - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - return (NULL); - } - /* Did realloc() change the pointer? */ - if (oldaddr != sp->fts_path) { - doadjust = 1; - if (ISSET(FTS_NOCHDIR)) - cp = sp->fts_path + len; - } - maxlen = sp->fts_pathlen - len; - } - -#if defined(__FTS_COMPAT_LENGTH) - if (len + dnamlen >= USHRT_MAX) { - /* - * In an FTSENT, fts_pathlen is an unsigned short - * so it is possible to wraparound here. - * If we do, free up the current structure and the - * structures already allocated, then error out - * with ENAMETOOLONG. - */ - fts_free(p); - fts_lfree(head); - (void)closedir(dirp); - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - errno = ENAMETOOLONG; - return (NULL); - } -#endif - p->fts_level = level; - p->fts_pathlen = ftsent_pathlen_truncate(len + dnamlen); - p->fts_parent = sp->fts_cur; - -#ifdef FTS_WHITEOUT - if (dp->d_type == DT_WHT) - p->fts_flags |= FTS_ISW; -#endif - - if (cderrno) { - if (nlinks) { - p->fts_info = FTS_NS; - p->fts_errno = cderrno; - } else - p->fts_info = FTS_NSOK; - p->fts_accpath = cur->fts_accpath; - } else if (nlinks == 0 -#ifdef DT_DIR - || (nostat && - dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) -#endif - ) { - p->fts_accpath = - ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; - p->fts_info = FTS_NSOK; - } else { - /* Build a file name for fts_stat to stat. */ - if (ISSET(FTS_NOCHDIR)) { - p->fts_accpath = p->fts_path; - memmove(cp, p->fts_name, - (size_t)(p->fts_namelen + 1)); - } else - p->fts_accpath = p->fts_name; - /* Stat it. */ - p->fts_info = fts_stat(sp, p, 0); - - /* Decrement link count if applicable. */ - if (nlinks > 0 && (p->fts_info == FTS_D || - p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) - --nlinks; - } - - /* We walk in directory order so "ls -f" doesn't get upset. */ - p->fts_link = NULL; - if (head == NULL) - head = tail = p; - else { - tail->fts_link = p; - tail = p; - } - ++nitems; - } - (void)closedir(dirp); - - /* - * If had to realloc the path, adjust the addresses for the rest - * of the tree. - */ - if (doadjust) - fts_padjust(sp, head); - - /* - * If not changing directories, reset the path back to original - * state. - */ - if (ISSET(FTS_NOCHDIR)) { - if (len == sp->fts_pathlen || nitems == 0) - --cp; - *cp = '\0'; - } - - /* - * If descended after called from fts_children or after called from - * fts_read and nothing found, get back. At the root level we use - * the saved fd; if one of fts_open()'s arguments is a relative path - * to an empty directory, we wind up here with no other way back. If - * can't get back, we're done. - */ - if (descend && (type == BCHILD || !nitems) && - (cur->fts_level == FTS_ROOTLEVEL ? - FCHDIR(sp, sp->fts_rfd) : - fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { - cur->fts_info = FTS_ERR; - SET(FTS_STOP); - return (NULL); - } - - /* If didn't find anything, return NULL. */ - if (!nitems) { - if (type == BREAD) - cur->fts_info = FTS_DP; - return (NULL); - } - - /* Sort the entries. */ - if (sp->fts_compar && nitems > 1) - head = fts_sort(sp, head, nitems); - return (head); -} - -static unsigned short -fts_stat(FTS *sp, FTSENT *p, int follow) -{ - FTSENT *t; - dev_t dev; - __fts_ino_t ino; - __fts_stat_t *sbp, sb; - int saved_errno; - - _DIAGASSERT(sp != NULL); - _DIAGASSERT(p != NULL); - - /* If user needs stat info, stat buffer already allocated. */ - sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; - -#ifdef FTS_WHITEOUT - /* check for whiteout */ - if (p->fts_flags & FTS_ISW) { - if (sbp != &sb) { - memset(sbp, '\0', sizeof (*sbp)); - sbp->st_mode = S_IFWHT; - } - return (FTS_W); - } -#endif - - /* - * If doing a logical walk, or application requested FTS_FOLLOW, do - * a stat(2). If that fails, check for a non-existent symlink. If - * fail, set the errno from the stat call. - */ - if (ISSET(FTS_LOGICAL) || follow) { - if (stat(p->fts_accpath, sbp)) { - saved_errno = errno; - if (!lstat(p->fts_accpath, sbp)) { - errno = 0; - return (FTS_SLNONE); - } - p->fts_errno = saved_errno; - goto err; - } - } else if (lstat(p->fts_accpath, sbp)) { - p->fts_errno = errno; -err: memset(sbp, 0, sizeof(*sbp)); - return (FTS_NS); - } - - if (S_ISDIR(sbp->st_mode)) { - /* - * Set the device/inode. Used to find cycles and check for - * crossing mount points. Also remember the link count, used - * in fts_build to limit the number of stat calls. It is - * understood that these fields are only referenced if fts_info - * is set to FTS_D. - */ - dev = p->fts_dev = sbp->st_dev; - ino = p->fts_ino = sbp->st_ino; - p->fts_nlink = sbp->st_nlink; - - if (ISDOT(p->fts_name)) - return (FTS_DOT); - - /* - * Cycle detection is done by brute force when the directory - * is first encountered. If the tree gets deep enough or the - * number of symbolic links to directories is high enough, - * something faster might be worthwhile. - */ - for (t = p->fts_parent; - t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) - if (ino == t->fts_ino && dev == t->fts_dev) { - p->fts_cycle = t; - return (FTS_DC); - } - return (FTS_D); - } - if (S_ISLNK(sbp->st_mode)) - return (FTS_SL); - if (S_ISREG(sbp->st_mode)) - return (FTS_F); - return (FTS_DEFAULT); -} - -static FTSENT * -fts_sort(FTS *sp, FTSENT *head, size_t nitems) -{ - FTSENT **ap, *p; - - _DIAGASSERT(sp != NULL); - _DIAGASSERT(head != NULL); - - /* - * Construct an array of pointers to the structures and call qsort(3). - * Reassemble the array in the order returned by qsort. If unable to - * sort for memory reasons, return the directory entries in their - * current order. Allocate enough space for the current needs plus - * 40 so don't realloc one entry at a time. - */ - if (nitems > sp->fts_nitems) { - FTSENT **new; - - new = realloc(sp->fts_array, sizeof(FTSENT *) * (nitems + 40)); - if (new == 0) - return (head); - sp->fts_array = new; - sp->fts_nitems = fts_nitems_truncate(nitems + 40); - } - for (ap = sp->fts_array, p = head; p; p = p->fts_link) - *ap++ = p; - qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), - (int (*)(const void *, const void *))sp->fts_compar); - for (head = *(ap = sp->fts_array); --nitems; ++ap) - ap[0]->fts_link = ap[1]; - ap[0]->fts_link = NULL; - return (head); -} - -static FTSENT * -fts_alloc(FTS *sp, const char *name, size_t namelen) -{ - FTSENT *p; -#if defined(FTS_ALLOC_ALIGNED) - size_t len; -#endif - - _DIAGASSERT(sp != NULL); - _DIAGASSERT(name != NULL); - -#if defined(FTS_ALLOC_ALIGNED) - /* - * The file name is a variable length array and no stat structure is - * necessary if the user has set the nostat bit. Allocate the FTSENT - * structure, the file name and the stat structure in one chunk, but - * be careful that the stat structure is reasonably aligned. Since the - * fts_name field is declared to be of size 1, the fts_name pointer is - * namelen + 2 before the first possible address of the stat structure. - */ - len = sizeof(FTSENT) + namelen; - if (!ISSET(FTS_NOSTAT)) - len += sizeof(*(p->fts_statp)) + ALIGNBYTES; - if ((p = malloc(len)) == NULL) - return (NULL); - - if (!ISSET(FTS_NOSTAT)) - p->fts_statp = (__fts_stat_t *)ALIGN( - (unsigned long)(p->fts_name + namelen + 2)); -#else - if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL) - return (NULL); - - if (!ISSET(FTS_NOSTAT)) - if ((p->fts_statp = malloc(sizeof(*(p->fts_statp)))) == NULL) { - free(p); - return (NULL); - } -#endif - - if (ISSET(FTS_NOSTAT)) - p->fts_statp = NULL; - - /* Copy the name plus the trailing NULL. */ - memmove(p->fts_name, name, namelen + 1); - - p->fts_namelen = ftsent_namelen_truncate(namelen); - p->fts_path = sp->fts_path; - p->fts_errno = 0; - p->fts_flags = 0; - p->fts_instr = FTS_NOINSTR; - p->fts_number = 0; - p->fts_pointer = NULL; - return (p); -} - -static void -fts_free(FTSENT *p) -{ -#if !defined(FTS_ALLOC_ALIGNED) - if (p->fts_statp) - free(p->fts_statp); -#endif - free(p); -} - -static void -fts_lfree(FTSENT *head) -{ - FTSENT *p; - - /* XXX: head may be NULL ? */ - - /* Free a linked list of structures. */ - while ((p = head) != NULL) { - head = head->fts_link; - fts_free(p); - } -} - -static size_t -fts_pow2(size_t x) -{ - - x--; - x |= x>>1; - x |= x>>2; - x |= x>>4; - x |= x>>8; - x |= x>>16; -#if LONG_BIT > 32 - x |= x>>32; -#endif -#if LONG_BIT > 64 - x |= x>>64; -#endif - x++; - return (x); -} - -/* - * Allow essentially unlimited paths; find, rm, ls should all work on any tree. - * Most systems will allow creation of paths much longer than MAXPATHLEN, even - * though the kernel won't resolve them. Round up the new size to a power of 2, - * so we don't realloc the path 2 bytes at a time. - */ -static int -fts_palloc(FTS *sp, size_t size) -{ - char *new; - - _DIAGASSERT(sp != NULL); - -#ifdef __FTS_COMPAT_LENGTH - /* Protect against fts_pathlen overflow. */ - if (size > USHRT_MAX + 1) { - errno = ENAMETOOLONG; - return (1); - } -#endif - size = fts_pow2(size); - new = realloc(sp->fts_path, size); - if (new == 0) - return (1); - sp->fts_path = new; - sp->fts_pathlen = fts_pathlen_truncate(size); - return (0); -} - -/* - * When the path is realloc'd, have to fix all of the pointers in structures - * already returned. - */ -static void -fts_padjust(FTS *sp, FTSENT *head) -{ - FTSENT *p; - char *addr; - - _DIAGASSERT(sp != NULL); - -#define ADJUST(p) do { \ - if ((p)->fts_accpath != (p)->fts_name) \ - (p)->fts_accpath = \ - addr + ((p)->fts_accpath - (p)->fts_path); \ - (p)->fts_path = addr; \ -} while (/*CONSTCOND*/0) - - addr = sp->fts_path; - - /* Adjust the current set of children. */ - for (p = sp->fts_child; p; p = p->fts_link) - ADJUST(p); - - /* Adjust the rest of the tree, including the current level. */ - for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { - ADJUST(p); - p = p->fts_link ? p->fts_link : p->fts_parent; - } -} - -static size_t -fts_maxarglen(char * const *argv) -{ - size_t len, max; - - _DIAGASSERT(argv != NULL); - - for (max = 0; *argv; ++argv) - if ((len = strlen(*argv)) > max) - max = len; - return (max + 1); -} - -/* - * Change to dir specified by fd or p->fts_accpath without getting - * tricked by someone changing the world out from underneath us. - * Assumes p->fts_dev and p->fts_ino are filled in. - */ -static int -fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path) -{ -#if HAVE_FCHDIR - int oldfd = fd, ret = -1; - __fts_stat_t sb; - - if (ISSET(FTS_NOCHDIR)) - return 0; - - if (oldfd < 0 && (fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) - return -1; - - if (fstat(fd, &sb) == -1) - goto bail; - - if (sb.st_ino != p->fts_ino || sb.st_dev != p->fts_dev) { - errno = ENOENT; - goto bail; - } - - ret = fchdir(fd); - -bail: - if (oldfd < 0) { - int save_errno = errno; - (void)close(fd); - errno = save_errno; - } - return ret; -#else - /* If we can't do fchdir, pretend as if ISSET(FTS_NOCHDIR) is set. */ - return 0; -#endif -} diff --git a/lib/libc/wasi/libc-bottom-half/clocks/clock.c b/lib/libc/wasi/libc-bottom-half/clocks/clock.c deleted file mode 100644 index 6767d7393216acf96d06a4283f3da9dda057e68b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/clocks/clock.c +++ /dev/null @@ -1,35 +0,0 @@ -#define _WASI_EMULATED_PROCESS_CLOCKS -#include -#include -#include - -_Static_assert( - CLOCKS_PER_SEC == NSEC_PER_SEC, - "This implementation assumes that `clock` is in nanoseconds" -); - -// Snapshot of the monotonic clock at the start of the program. -static __wasi_timestamp_t start; - -// Use a priority of 10 to run fairly early in the implementation-reserved -// constructor priority range. -__attribute__((constructor(10))) -static void init(void) { - (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &start); -} - -// Define the libc symbol as `__clock` so that we can reliably call it -// from elsewhere in libc. -clock_t __clock(void) { - // Use `MONOTONIC` instead of `PROCESS_CPUTIME_ID` since WASI doesn't have - // an inherent concept of a process. Note that this means we'll incorrectly - // include time from other processes, so this function is only declared by - // the headers if `_WASI_EMULATED_PROCESS_CLOCKS` is defined. - __wasi_timestamp_t now = 0; - (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &now); - return now - start; -} - -// Define a user-visible alias as a weak symbol. -__attribute__((__weak__, __alias__("__clock"))) -clock_t clock(void); diff --git a/lib/libc/wasi/libc-bottom-half/clocks/getrusage.c b/lib/libc/wasi/libc-bottom-half/clocks/getrusage.c deleted file mode 100644 index d0113c5135094833c8138097caf3fb42bc635c95..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/clocks/getrusage.c +++ /dev/null @@ -1,28 +0,0 @@ -#define _WASI_EMULATED_PROCESS_CLOCKS -#include -#include -#include -#include -#include - -// `clock` is a weak symbol so that application code can override it. -// We want to use the function in libc, so use the libc-internal name. -clock_t __clock(void); - -int getrusage(int who, struct rusage *r_usage) { - switch (who) { - case RUSAGE_SELF: { - __wasi_timestamp_t usertime = __clock(); - *r_usage = (struct rusage) { - .ru_utime = timestamp_to_timeval(usertime) - }; - return 0; - } - case RUSAGE_CHILDREN: - *r_usage = (struct rusage) {}; - return 0; - default: - errno = EINVAL; - return -1; - } -} diff --git a/lib/libc/wasi/libc-bottom-half/clocks/times.c b/lib/libc/wasi/libc-bottom-half/clocks/times.c deleted file mode 100644 index 48fa07baa7f07154bfb7db677a8618df580ef8f9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/clocks/times.c +++ /dev/null @@ -1,27 +0,0 @@ -#define _WASI_EMULATED_PROCESS_CLOCKS -#include -#include -#include -#include - -_Static_assert( - CLOCKS_PER_SEC == NSEC_PER_SEC, - "This implementation assumes that `clock` is in nanoseconds" -); - -// `clock` is a weak symbol so that application code can override it. -// We want to use the function in libc, so use the libc-internal name. -clock_t __clock(void); - -clock_t times(struct tms *buffer) { - __wasi_timestamp_t user = __clock(); - *buffer = (struct tms){ - .tms_utime = user, - // WASI doesn't provide a way to spawn a new process, so always 0. - .tms_cutime = 0 - }; - - __wasi_timestamp_t realtime = 0; - (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &realtime); - return realtime; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/LICENSE b/lib/libc/wasi/libc-bottom-half/cloudlibc/LICENSE deleted file mode 100644 index dd33b05122987dfa57c8170e5e2d9459420eef9e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/LICENSE +++ /dev/null @@ -1,22 +0,0 @@ -Copyright (c) 2015-2017 Nuxi (https://nuxi.nl/) and contributors. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: -1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. -2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -SUCH DAMAGE. diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/clock.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/clock.h deleted file mode 100644 index 58d40a18379ff6f7e0d7c2f952a2513bed8fed8b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/clock.h +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifndef COMMON_CLOCK_H -#define COMMON_CLOCK_H - -#include - -// 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 -// objects to store the raw ABI-level clock identifier, but in the -// future we can use this to provide support for pthread_getcpuclockid() -// and clock file descriptors. -struct __clockid { - __wasi_clockid_t id; -}; - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/limits.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/limits.h deleted file mode 100644 index 67e2f0743836ee9041b99f79714a518ee0cac704..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/limits.h +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifndef COMMON_LIMITS_H -#define COMMON_LIMITS_H - -#include - -#define NUMERIC_MIN(t) \ - _Generic((t)0, char \ - : CHAR_MIN, signed char \ - : SCHAR_MIN, unsigned char : 0, short \ - : SHRT_MIN, unsigned short : 0, int \ - : INT_MIN, unsigned int : 0, long \ - : LONG_MIN, unsigned long : 0, long long \ - : LLONG_MIN, unsigned long long : 0, default \ - : (void)0) - -#define NUMERIC_MAX(t) \ - _Generic((t)0, char \ - : CHAR_MAX, signed char \ - : SCHAR_MAX, unsigned char \ - : UCHAR_MAX, short \ - : SHRT_MAX, unsigned short \ - : USHRT_MAX, int \ - : INT_MAX, unsigned int \ - : UINT_MAX, long \ - : LONG_MAX, unsigned long \ - : ULONG_MAX, long long \ - : LLONG_MAX, unsigned long long \ - : ULLONG_MAX, default \ - : (void)0) - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/time.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/time.h deleted file mode 100644 index 08e28526904f83276fe8c0090d70d260d7803b64..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/time.h +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifndef COMMON_TIME_H -#define COMMON_TIME_H - -#include - -#include - -#include -#include -#include - -#define NSEC_PER_SEC 1000000000 - -static inline bool timespec_to_timestamp_exact( - const struct timespec *timespec, __wasi_timestamp_t *timestamp) { - // Invalid nanoseconds field. - if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) - return false; - - // Timestamps before the Epoch are not supported. - if (timespec->tv_sec < 0) - return false; - - // Make sure our timestamp does not overflow. - return !__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) && - !__builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp); -} - -static inline bool timespec_to_timestamp_clamp( - const struct timespec *timespec, __wasi_timestamp_t *timestamp) { - // Invalid nanoseconds field. - if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) - return false; - - if (timespec->tv_sec < 0) { - // Timestamps before the Epoch are not supported. - *timestamp = 0; - } else if (__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) || - __builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp)) { - // Make sure our timestamp does not overflow. - *timestamp = NUMERIC_MAX(__wasi_timestamp_t); - } - return true; -} - -static inline struct timespec timestamp_to_timespec( - __wasi_timestamp_t timestamp) { - // Decompose timestamp into seconds and nanoseconds. - return (struct timespec){.tv_sec = timestamp / NSEC_PER_SEC, - .tv_nsec = timestamp % NSEC_PER_SEC}; -} - -static inline struct timeval timestamp_to_timeval( - __wasi_timestamp_t timestamp) { - struct timespec ts = timestamp_to_timespec(timestamp); - return (struct timeval){.tv_sec = ts.tv_sec, ts.tv_nsec / 1000}; -} - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/include/_/cdefs.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/include/_/cdefs.h deleted file mode 100644 index d9a6f547b06ca555cb7b93627001a6f479f3f927..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/include/_/cdefs.h +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ -// -// Redistribution and use in source and binary forms, with or without -// modification, are permitted provided that the following conditions -// are met: -// 1. Redistributions of source code must retain the above copyright -// notice, this list of conditions and the following disclaimer. -// 2. Redistributions in binary form must reproduce the above copyright -// notice, this list of conditions and the following disclaimer in the -// documentation and/or other materials provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND -// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -// ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE -// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -// OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -// OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -// SUCH DAMAGE. - -#ifndef ___CDEFS_H_ -#define ___CDEFS_H_ - -// Compiler-independent annotations. - -#define __strong_reference(oldsym, newsym) \ - extern __typeof__(oldsym) newsym __attribute__((__alias__(#oldsym))) - -// Convenience macros. - -#define __arraycount(x) (sizeof(x) / sizeof((x)[0])) - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c deleted file mode 100644 index 358573750f009a561eba7469677a3fa84b957842..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -int closedir(DIR *dirp) { - return close(fdclosedir(dirp)); -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h deleted file mode 100644 index 642400a0513580ffb00d244f8c4847e701a3859a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifndef DIRENT_DIRENT_IMPL_H -#define DIRENT_DIRENT_IMPL_H - -#include -#include - -struct dirent; - -#define DIRENT_DEFAULT_BUFFER_SIZE 4096 - -struct _DIR { - // Directory file descriptor and cookie. - int fd; - __wasi_dircookie_t cookie; - - // Read buffer. - char *buffer; - size_t buffer_processed; - size_t buffer_size; - size_t buffer_used; - - // Object returned by readdir(). - struct dirent *dirent; - size_t dirent_size; -}; - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c deleted file mode 100644 index 033157a4e2a63d93a54c256b18a541f7b7fa15c9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include "dirent_impl.h" - -int dirfd(DIR *dirp) { - return dirp->fd; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c deleted file mode 100644 index cabe702325021d6472df2ef8ded1681a96ee9811..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include "dirent_impl.h" - -int fdclosedir(DIR *dirp) { - int fd = dirp->fd; - free(dirp->buffer); - free(dirp->dirent); - free(dirp); - return fd; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c deleted file mode 100644 index 4a2136af520e545b31c43002dfdffc3f5d444c13..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -#include "dirent_impl.h" - -DIR *fdopendir(int fd) { - // Allocate new directory object and read buffer. - DIR *dirp = malloc(sizeof(*dirp)); - if (dirp == NULL) - return NULL; - dirp->buffer = malloc(DIRENT_DEFAULT_BUFFER_SIZE); - if (dirp->buffer == NULL) { - free(dirp); - return NULL; - } - - // Ensure that this is really a directory by already loading the first - // chunk of data. - __wasi_errno_t error = - // 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, - __WASI_DIRCOOKIE_START, &dirp->buffer_used); - if (error != 0) { - free(dirp->buffer); - free(dirp); - errno = error; - return NULL; - } - - // Initialize other members. - dirp->fd = fd; - dirp->cookie = __WASI_DIRCOOKIE_START; - dirp->buffer_processed = 0; - dirp->buffer_size = DIRENT_DEFAULT_BUFFER_SIZE; - dirp->dirent = NULL; - dirp->dirent_size = 1; - return dirp; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c deleted file mode 100644 index e6d1c2a3f3a693d1637f3c4c5ca9bd714b4fc3ba..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include -#include -#include - -DIR *__wasilibc_nocwd_opendirat(int dir, const char *dirname) { - // Open directory. - int fd = __wasilibc_nocwd_openat_nomode(dir, dirname, O_RDONLY | O_NONBLOCK | O_DIRECTORY); - if (fd == -1) - return NULL; - - // Create directory handle. - DIR *result = fdopendir(fd); - if (result == NULL) - close(fd); - return result; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c deleted file mode 100644 index bfd19213c6abae67dad9211f5d040f38063b72bb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include "dirent_impl.h" - -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"); -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"); - -// Grows a buffer to be large enough to hold a certain amount of data. -#define GROW(buffer, buffer_size, target_size) \ - do { \ - if ((buffer_size) < (target_size)) { \ - size_t new_size = (buffer_size); \ - while (new_size < (target_size)) \ - new_size *= 2; \ - void *new_buffer = realloc(buffer, new_size); \ - if (new_buffer == NULL) \ - return NULL; \ - (buffer) = new_buffer; \ - (buffer_size) = new_size; \ - } \ - } while (0) - -struct dirent *readdir(DIR *dirp) { - for (;;) { - // Extract the next dirent header. - size_t buffer_left = dirp->buffer_used - dirp->buffer_processed; - if (buffer_left < sizeof(__wasi_dirent_t)) { - // End-of-file. - if (dirp->buffer_used < dirp->buffer_size) - return NULL; - goto read_entries; - } - __wasi_dirent_t entry; - memcpy(&entry, dirp->buffer + dirp->buffer_processed, sizeof(entry)); - - size_t entry_size = sizeof(__wasi_dirent_t) + entry.d_namlen; - if (entry.d_namlen == 0) { - // Invalid pathname length. Skip the entry. - dirp->buffer_processed += entry_size; - continue; - } - - // The entire entry must be present in buffer space. If not, read - // the entry another time. Ensure that the read buffer is large - // enough to fit at least this single entry. - if (buffer_left < entry_size) { - GROW(dirp->buffer, dirp->buffer_size, entry_size); - goto read_entries; - } - - // Skip entries having null bytes in the filename. - const char *name = dirp->buffer + dirp->buffer_processed + sizeof(entry); - if (memchr(name, '\0', entry.d_namlen) != NULL) { - dirp->buffer_processed += entry_size; - continue; - } - - // Return the next directory entry. Ensure that the dirent is large - // enough to fit the filename. - GROW(dirp->dirent, dirp->dirent_size, - offsetof(struct dirent, d_name) + entry.d_namlen + 1); - struct dirent *dirent = dirp->dirent; - dirent->d_type = entry.d_type; - memcpy(dirent->d_name, name, entry.d_namlen); - dirent->d_name[entry.d_namlen] = '\0'; - - // `fd_readdir` implementations may set the inode field to zero if the - // the inode number is unknown. In that case, do an `fstatat` to get the - // inode number. - off_t d_ino = entry.d_ino; - unsigned char d_type = entry.d_type; - if (d_ino == 0 && strcmp(dirent->d_name, "..") != 0) { - struct stat statbuf; - if (fstatat(dirp->fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) { - if (errno == ENOENT) { - // The file disappeared before we could read it, so skip it. - dirp->buffer_processed += entry_size; - continue; - } - return NULL; - } - - // Fill in the inode. - d_ino = statbuf.st_ino; - - // In case someone raced with us and replaced the object with this name - // with another of a different type, update the type too. - d_type = __wasilibc_iftodt(statbuf.st_mode & S_IFMT); - } - dirent->d_ino = d_ino; - dirent->d_type = d_type; - - dirp->cookie = entry.d_next; - dirp->buffer_processed += entry_size; - return dirent; - - read_entries: - // Discard data currently stored in the input buffer. - dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; - - // Load more directory entries and continue. - __wasi_errno_t error = - // 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, - dirp->cookie, &dirp->buffer_used); - if (error != 0) { - errno = error; - return NULL; - } - dirp->buffer_processed = 0; - } -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c deleted file mode 100644 index 8dd58827accfc1b566876f35ef0b4db56a28868c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include "dirent_impl.h" - -void rewinddir(DIR *dirp) { - // Update cookie. - dirp->cookie = __WASI_DIRCOOKIE_START; - // Mark entire buffer as processed to force a read of new data. - dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c deleted file mode 100644 index 079b3b3b29efd8fe1b597dff16d63c488b9a1403..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c +++ /dev/null @@ -1,168 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "dirent_impl.h" - -static int sel_true(const struct dirent *de) { - return 1; -} - -int __wasilibc_nocwd_scandirat(int dirfd, const char *dir, struct dirent ***namelist, - int (*sel)(const struct dirent *), - int (*compar)(const struct dirent **, const struct dirent **)) { - struct stat statbuf; - - // Match all files if no select function is provided. - if (sel == NULL) - sel = sel_true; - - // Open the directory. - int fd = __wasilibc_nocwd_openat_nomode(dirfd, dir, O_RDONLY | O_NONBLOCK | O_DIRECTORY); - if (fd == -1) - return -1; - - // Allocate a read buffer for the directory entries. - size_t buffer_size = DIRENT_DEFAULT_BUFFER_SIZE; - char *buffer = malloc(buffer_size); - if (buffer == NULL) { - close(fd); - return -1; - } - size_t buffer_processed = buffer_size; - size_t buffer_used = buffer_size; - - // Space for the array to return to the caller. - struct dirent **dirents = NULL; - size_t dirents_size = 0; - size_t dirents_used = 0; - - __wasi_dircookie_t cookie = __WASI_DIRCOOKIE_START; - for (;;) { - // Extract the next dirent header. - size_t buffer_left = buffer_used - buffer_processed; - if (buffer_left < sizeof(__wasi_dirent_t)) { - // End-of-file. - if (buffer_used < buffer_size) - break; - goto read_entries; - } - __wasi_dirent_t entry; - memcpy(&entry, buffer + buffer_processed, sizeof(entry)); - - size_t entry_size = sizeof(__wasi_dirent_t) + entry.d_namlen; - if (entry.d_namlen == 0) { - // Invalid pathname length. Skip the entry. - buffer_processed += entry_size; - continue; - } - - // The entire entry must be present in buffer space. If not, read - // the entry another time. Ensure that the read buffer is large - // enough to fit at least this single entry. - if (buffer_left < entry_size) { - while (buffer_size < entry_size) - buffer_size *= 2; - char *new_buffer = realloc(buffer, buffer_size); - if (new_buffer == NULL) - goto bad; - buffer = new_buffer; - goto read_entries; - } - - // Skip entries having null bytes in the filename. - const char *name = buffer + buffer_processed + sizeof(entry); - buffer_processed += entry_size; - if (memchr(name, '\0', entry.d_namlen) != NULL) - continue; - - // Create the new directory entry. - struct dirent *dirent = - malloc(offsetof(struct dirent, d_name) + entry.d_namlen + 1); - if (dirent == NULL) - goto bad; - dirent->d_type = entry.d_type; - memcpy(dirent->d_name, name, entry.d_namlen); - dirent->d_name[entry.d_namlen] = '\0'; - - // `fd_readdir` implementations may set the inode field to zero if the - // the inode number is unknown. In that case, do an `fstatat` to get the - // inode number. - off_t d_ino = entry.d_ino; - unsigned char d_type = entry.d_type; - if (d_ino == 0) { - if (fstatat(fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) { - return -1; - } - - // Fill in the inode. - d_ino = statbuf.st_ino; - - // In case someone raced with us and replaced the object with this name - // with another of a different type, update the type too. - d_type = __wasilibc_iftodt(statbuf.st_mode & S_IFMT); - } - dirent->d_ino = d_ino; - dirent->d_type = d_type; - - cookie = entry.d_next; - - if (sel(dirent)) { - // Add the entry to the results. - if (dirents_used == dirents_size) { - dirents_size = dirents_size < 8 ? 8 : dirents_size * 2; - struct dirent **new_dirents = - realloc(dirents, dirents_size * sizeof(*dirents)); - if (new_dirents == NULL) { - free(dirent); - goto bad; - } - dirents = new_dirents; - } - dirents[dirents_used++] = dirent; - } else { - // Discard the entry. - free(dirent); - } - continue; - - read_entries:; - // Load more directory entries and continue. - // 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, - cookie, &buffer_used); - if (error != 0) { - errno = error; - goto bad; - } - buffer_processed = 0; - } - - // Sort results and return them. - free(buffer); - close(fd); - (qsort)(dirents, dirents_used, sizeof(*dirents), - (int (*)(const void *, const void *))compar); - *namelist = dirents; - return dirents_used; - -bad: - // Deallocate partially created results. - for (size_t i = 0; i < dirents_used; ++i) - free(dirents[i]); - free(dirents); - free(buffer); - close(fd); - return -1; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c deleted file mode 100644 index a865d92c7c1a770518f6a88f17ca98ae1e37262a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include "dirent_impl.h" - -void seekdir(DIR *dirp, long loc) { - // Update cookie. - dirp->cookie = (unsigned long)loc; - // Mark entire buffer as processed to force a read of new data. - // TODO(ed): We could prevent a read if the offset is in the buffer. - dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c deleted file mode 100644 index 05687eef87e4a9712a4c41acfbd201401b298199..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include "dirent_impl.h" - -long telldir(DIR *dirp) { - return dirp->cookie; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c deleted file mode 100644 index d7a27f3fcc0010e07f1b099effb21664c2d2102c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -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; diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c deleted file mode 100644 index 5d4055dd5fa46294fdadf4fb28169d8a783da704..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c +++ /dev/null @@ -1,62 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -int fcntl(int fildes, int cmd, ...) { - switch (cmd) { - case F_GETFD: - // Act as if the close-on-exec flag is always set. - return FD_CLOEXEC; - case F_SETFD: - // The close-on-exec flag is ignored. - return 0; - case F_GETFL: { - // Obtain the flags and the rights of the descriptor. - __wasi_fdstat_t fds; - __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); - if (error != 0) { - errno = error; - return -1; - } - - // Roughly approximate the access mode by converting the rights. - int oflags = fds.fs_flags; - if ((fds.fs_rights_base & - (__WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR)) != 0) { - if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) - oflags |= O_RDWR; - else - oflags |= O_RDONLY; - } else if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) { - oflags |= O_WRONLY; - } else { - oflags |= O_SEARCH; - } - return oflags; - } - case F_SETFL: { - // Set new file descriptor flags. - va_list ap; - va_start(ap, cmd); - int flags = va_arg(ap, int); - va_end(ap); - - __wasi_fdflags_t fs_flags = flags & 0xfff; - __wasi_errno_t error = - __wasi_fd_fdstat_set_flags(fildes, fs_flags); - if (error != 0) { - errno = error; - return -1; - } - return 0; - } - default: - errno = EINVAL; - return -1; - } -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c deleted file mode 100644 index 09cbbf8008f1da05c59cbd964b8b58bcac91d789..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include -#include -#include - -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"); - -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"); - -int __wasilibc_nocwd_openat_nomode(int fd, const char *path, int oflag) { - // Compute rights corresponding with the access modes provided. - // Attempt to obtain all rights, except the ones that contradict the - // access mode provided to openat(). - __wasi_rights_t max = - ~(__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); - switch (oflag & O_ACCMODE) { - case O_RDONLY: - case O_RDWR: - case O_WRONLY: - if ((oflag & O_RDONLY) != 0) { - max |= __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR; - } - if ((oflag & O_WRONLY) != 0) { - max |= __WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_WRITE | - __WASI_RIGHTS_FD_ALLOCATE | - __WASI_RIGHTS_FD_FILESTAT_SET_SIZE; - } - break; - case O_EXEC: - break; - case O_SEARCH: - break; - default: - errno = EINVAL; - return -1; - } - - // Ensure that we can actually obtain the minimal rights needed. - __wasi_fdstat_t fsb_cur; - __wasi_errno_t error = __wasi_fd_fdstat_get(fd, &fsb_cur); - if (error != 0) { - errno = error; - return -1; - } - - // Path lookup properties. - __wasi_lookupflags_t lookup_flags = 0; - if ((oflag & O_NOFOLLOW) == 0) - lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; - - // Open file with appropriate rights. - __wasi_fdflags_t fs_flags = oflag & 0xfff; - __wasi_rights_t fs_rights_base = max & fsb_cur.fs_rights_inheriting; - __wasi_rights_t fs_rights_inheriting = fsb_cur.fs_rights_inheriting; - __wasi_fd_t newfd; - error = __wasi_path_open(fd, lookup_flags, path, - (oflag >> 12) & 0xfff, - fs_rights_base, fs_rights_inheriting, fs_flags, - &newfd); - if (error != 0) { - errno = error; - return -1; - } - return newfd; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c deleted file mode 100644 index d683d399f247297e7eb78ed10185d9987562b759..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -static_assert(POSIX_FADV_DONTNEED == __WASI_ADVICE_DONTNEED, - "Value mismatch"); -static_assert(POSIX_FADV_NOREUSE == __WASI_ADVICE_NOREUSE, "Value mismatch"); -static_assert(POSIX_FADV_NORMAL == __WASI_ADVICE_NORMAL, "Value mismatch"); -static_assert(POSIX_FADV_RANDOM == __WASI_ADVICE_RANDOM, "Value mismatch"); -static_assert(POSIX_FADV_SEQUENTIAL == __WASI_ADVICE_SEQUENTIAL, - "Value mismatch"); -static_assert(POSIX_FADV_WILLNEED == __WASI_ADVICE_WILLNEED, - "Value mismatch"); - -int posix_fadvise(int fd, off_t offset, off_t len, int advice) { - if (offset < 0 || len < 0) - return EINVAL; - return __wasi_fd_advise(fd, offset, len, advice); -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c deleted file mode 100644 index 4b41c4b65c9a721555e09bb6435a77bbe95cba99..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -int posix_fallocate(int fd, off_t offset, off_t len) { - if (offset < 0 || len < 0) - return EINVAL; - return __wasi_fd_allocate(fd, offset, len); -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c deleted file mode 100644 index 0ee14791d99e7b5c0991d0f224e512521b9b131a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c +++ /dev/null @@ -1,174 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -static int poll_wasip1(struct pollfd *fds, size_t nfds, int timeout) { - // Construct events for poll(). - size_t maxevents = 2 * nfds + 1; - __wasi_subscription_t subscriptions[maxevents]; - size_t nsubscriptions = 0; - for (size_t i = 0; i < nfds; ++i) { - struct pollfd *pollfd = &fds[i]; - if (pollfd->fd < 0) - continue; - bool created_events = false; - if ((pollfd->events & POLLRDNORM) != 0) { - __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; - *subscription = (__wasi_subscription_t){ - .userdata = (uintptr_t)pollfd, - .u.tag = __WASI_EVENTTYPE_FD_READ, - .u.u.fd_read.file_descriptor = pollfd->fd, - }; - created_events = true; - } - if ((pollfd->events & POLLWRNORM) != 0) { - __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; - *subscription = (__wasi_subscription_t){ - .userdata = (uintptr_t)pollfd, - .u.tag = __WASI_EVENTTYPE_FD_WRITE, - .u.u.fd_write.file_descriptor = pollfd->fd, - }; - created_events = true; - } - - // As entries are decomposed into separate read/write subscriptions, - // we cannot detect POLLERR, POLLHUP and POLLNVAL if POLLRDNORM and - // POLLWRNORM are not specified. Disallow this for now. - if (!created_events) { - errno = ENOSYS; - return -1; - } - } - - // Create extra event for the timeout. - if (timeout >= 0) { - __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; - *subscription = (__wasi_subscription_t){ - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = __WASI_CLOCKID_REALTIME, - .u.u.clock.timeout = (__wasi_timestamp_t)timeout * 1000000, - }; - } - - // Execute poll(). - size_t nevents; - __wasi_event_t events[nsubscriptions]; - __wasi_errno_t error = - __wasi_poll_oneoff(subscriptions, events, nsubscriptions, &nevents); - if (error != 0) { - // WASI's poll requires at least one subscription, or else it returns - // `EINVAL`. Since a `poll` with nothing to wait for is valid in POSIX, - // return `ENOTSUP` to indicate that we don't support that case. - // - // Wasm has no signal handling, so if none of the user-provided `pollfd` - // elements, nor the timeout, led us to producing even one subscription - // to wait for, there would be no way for the poll to wake up. WASI - // returns `EINVAL` in this case, but for users of `poll`, `ENOTSUP` is - // more likely to be understood. - if (nsubscriptions == 0) - errno = ENOTSUP; - else - errno = error; - return -1; - } - - // Clear revents fields. - for (size_t i = 0; i < nfds; ++i) { - struct pollfd *pollfd = &fds[i]; - pollfd->revents = 0; - } - - // Set revents fields. - for (size_t i = 0; i < nevents; ++i) { - const __wasi_event_t *event = &events[i]; - if (event->type == __WASI_EVENTTYPE_FD_READ || - event->type == __WASI_EVENTTYPE_FD_WRITE) { - struct pollfd *pollfd = (struct pollfd *)(uintptr_t)event->userdata; - if (event->error == __WASI_ERRNO_BADF) { - // Invalid file descriptor. - pollfd->revents |= POLLNVAL; - } else if (event->error == __WASI_ERRNO_PIPE) { - // Hangup on write side of pipe. - pollfd->revents |= POLLHUP; - } else if (event->error != 0) { - // Another error occurred. - pollfd->revents |= POLLERR; - } else { - // Data can be read or written. - if (event->type == __WASI_EVENTTYPE_FD_READ) { - pollfd->revents |= POLLRDNORM; - if (event->fd_readwrite.flags & __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP) { - pollfd->revents |= POLLHUP; - } - } else if (event->type == __WASI_EVENTTYPE_FD_WRITE) { - pollfd->revents |= POLLWRNORM; - if (event->fd_readwrite.flags & __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP) { - pollfd->revents |= POLLHUP; - } - } - } - } - } - - // Return the number of events with a non-zero revents value. - int retval = 0; - for (size_t i = 0; i < nfds; ++i) { - struct pollfd *pollfd = &fds[i]; - // POLLHUP contradicts with POLLWRNORM. - if ((pollfd->revents & POLLHUP) != 0) - pollfd->revents &= ~POLLWRNORM; - if (pollfd->revents != 0) - ++retval; - } - return retval; -} - -#ifdef __wasilibc_use_wasip2 -#include - -int poll_wasip2(struct pollfd *fds, size_t nfds, int timeout); - -int poll(struct pollfd* fds, nfds_t nfds, int timeout) -{ - bool found_socket = false; - bool found_non_socket = false; - for (size_t i = 0; i < nfds; ++i) { - descriptor_table_entry_t* entry; - if (descriptor_table_get_ref(fds[i].fd, &entry)) { - found_socket = true; - } else { - found_non_socket = true; - } - } - - if (found_socket) { - if (found_non_socket) { - // We currently don't support polling a mix of non-sockets and - // sockets here (though you can do it by using the host APIs - // directly), and we probably won't until we've migrated entirely to - // WASI 0.2. - errno = ENOTSUP; - return -1; - } - - return poll_wasip2(fds, nfds, timeout); - } else if (found_non_socket) { - return poll_wasip1(fds, nfds, timeout); - } else if (timeout >= 0) { - return poll_wasip2(fds, nfds, timeout); - } else { - errno = ENOTSUP; - return -1; - } -} -#else // not __wasilibc_use_wasip2 -int poll(struct pollfd* fds, nfds_t nfds, int timeout) -{ - return poll_wasip1(fds, nfds, timeout); -} -#endif // not __wasilibc_use_wasip2 diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c deleted file mode 100644 index 6100ea561dc15260d18c89dbb781c920f48b78f1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -int sched_yield(void) { - __wasi_errno_t error = __wasi_sched_yield(); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c deleted file mode 100644 index c1706db48f75731971289a0cf9efd6ed4c8205ab..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char *new) { - __wasi_errno_t error = __wasi_path_rename(oldfd, old, newfd, new); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c deleted file mode 100644 index a2c4e0bd2716d542940ed4850b6f3622fdeea1e9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifdef __wasilibc_use_wasip2 -#include -#else -#include -#endif -#include <_/cdefs.h> -#include -#include - -noreturn void _Exit(int status) { -#ifdef __wasilibc_use_wasip2 - exit_result_void_void_t exit_status = { .is_err = status != 0 }; - exit_exit(&exit_status); -#else - __wasi_proc_exit(status); -#endif -} - -__strong_reference(_Exit, _exit); diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c deleted file mode 100644 index 2c968b2a05f129a3b0d0e0b591051c7f1e63fa15..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -#include -#ifdef __wasilibc_use_wasip2 -#include -#endif - -int ioctl(int fildes, int request, ...) { -#ifdef __wasilibc_use_wasip2 - descriptor_table_entry_t *entry; - if (descriptor_table_get_ref(fildes, &entry)) { - switch (entry->tag) { - case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { - tcp_socket_t *socket = &entry->tcp_socket; - switch (request) { - case FIONBIO: { - va_list ap; - va_start(ap, request); - socket->blocking = *va_arg(ap, const int *) == - 0; - va_end(ap); - - return 0; - } - - default: - // TODO wasi-sockets: anything else we should support? - errno = EINVAL; - return -1; - } - } - - case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: { - udp_socket_t *socket = &entry->udp_socket; - switch (request) { - case FIONBIO: { - va_list ap; - va_start(ap, request); - socket->blocking = *va_arg(ap, const int *) == - 0; - va_end(ap); - - return 0; - } - - default: - // TODO wasi-sockets: anything else we should support? - errno = EINVAL; - return -1; - } - } - - default: - errno = ENOPROTOOPT; - return -1; - } - } -#endif // __wasilibc_use_wasip2 - - switch (request) { - case FIONREAD: { - // Poll the file descriptor to determine how many bytes can be read. - __wasi_subscription_t subscriptions[2] = { - { - .u.tag = __WASI_EVENTTYPE_FD_READ, - .u.u.fd_read.file_descriptor = fildes, - }, - { - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, - }, - }; - __wasi_event_t events[__arraycount(subscriptions)]; - size_t nevents; - __wasi_errno_t error = __wasi_poll_oneoff( - subscriptions, events, __arraycount(subscriptions), &nevents); - if (error != 0) { - errno = error; - return -1; - } - - // Location where result should be written. - va_list ap; - va_start(ap, request); - int *result = va_arg(ap, int *); - va_end(ap); - - // Extract number of bytes for reading from poll results. - for (size_t i = 0; i < nevents; ++i) { - __wasi_event_t *event = &events[i]; - if (event->error != 0) { - errno = event->error; - return -1; - } - if (event->type == __WASI_EVENTTYPE_FD_READ) { - *result = event->fd_readwrite.nbytes; - return 0; - } - } - - // No data available for reading. - *result = 0; - return 0; - } - case FIONBIO: { - // Obtain the current file descriptor flags. - __wasi_fdstat_t fds; - __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); - if (error != 0) { - errno = error; - return -1; - } - - // Toggle the non-blocking flag based on the argument. - va_list ap; - va_start(ap, request); - if (*va_arg(ap, const int *) != 0) - fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; - else - fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; - va_end(ap); - - // Update the file descriptor flags. - error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); - if (error != 0) { - errno = error; - return -1; - } - return 0; - } - default: - // Invalid request. - errno = EINVAL; - return -1; - } -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c deleted file mode 100644 index 3b479edfbbefa98e587170ede1713caa6e1755ff..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include - -#include -#include -#include - -int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, - fd_set *restrict errorfds, const struct timespec *restrict timeout, - const sigset_t *sigmask) { - // Negative file descriptor upperbound. - if (nfds < 0) { - errno = EINVAL; - return -1; - } - - // This implementation does not support polling for exceptional - // conditions, such as out-of-band data on TCP sockets. - if (errorfds != NULL && errorfds->__nfds > 0) { - errno = ENOSYS; - return -1; - } - - // Replace NULL pointers by the empty set. - fd_set empty; - FD_ZERO(&empty); - if (readfds == NULL) - readfds = ∅ - if (writefds == NULL) - writefds = ∅ - - struct pollfd poll_fds[readfds->__nfds + writefds->__nfds]; - size_t poll_nfds = 0; - - for (size_t i = 0; i < readfds->__nfds; ++i) { - int fd = readfds->__fds[i]; - if (fd < nfds) { - poll_fds[poll_nfds++] = (struct pollfd){ - .fd = fd, - .events = POLLRDNORM, - .revents = 0 - }; - } - } - - for (size_t i = 0; i < writefds->__nfds; ++i) { - int fd = writefds->__fds[i]; - if (fd < nfds) { - poll_fds[poll_nfds++] = (struct pollfd){ - .fd = fd, - .events = POLLWRNORM, - .revents = 0 - }; - } - } - - int poll_timeout; - if (timeout) { - uint64_t timeout_u64; - if (!timespec_to_timestamp_clamp(timeout, &timeout_u64) ) { - errno = EINVAL; - return -1; - } - - // Convert nanoseconds to milliseconds: - timeout_u64 /= 1000000; - - if (timeout_u64 > INT_MAX) { - timeout_u64 = INT_MAX; - } - - poll_timeout = (int) timeout_u64; - } else { - poll_timeout = -1; - }; - - if (poll(poll_fds, poll_nfds, poll_timeout) < 0) { - return -1; - } - - FD_ZERO(readfds); - FD_ZERO(writefds); - for (size_t i = 0; i < poll_nfds; ++i) { - struct pollfd* pollfd = poll_fds + i; - if ((pollfd->revents & POLLRDNORM) != 0) { - readfds->__fds[readfds->__nfds++] = pollfd->fd; - } - if ((pollfd->revents & POLLWRNORM) != 0) { - writefds->__fds[writefds->__nfds++] = pollfd->fd; - } - } - - return readfds->__nfds + writefds->__nfds; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c deleted file mode 100644 index ebe5e8c656eb61e8d86c17d4315768646b3636a9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, - fd_set *restrict errorfds, struct timeval *restrict timeout) { - if (timeout != NULL) { - // Timeout specified. - if (timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) { - errno = EINVAL; - return -1; - } - struct timespec ts = {.tv_sec = timeout->tv_sec, - .tv_nsec = (long)timeout->tv_usec * 1000}; - return pselect(nfds, readfds, writefds, errorfds, &ts, NULL); - } else { - // No timeout specified. - return pselect(nfds, readfds, writefds, errorfds, NULL, NULL); - } -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c deleted file mode 100644 index 1fe41c4e30d2c117360c8ee35961fc201d22da46..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include - -int getsockopt(int socket, int level, int option_name, - void *restrict option_value, socklen_t *restrict option_len) { - // Only support SOL_SOCKET options for now. - if (level != SOL_SOCKET) { - errno = ENOPROTOOPT; - return -1; - } - - int value; - switch (option_name) { - case SO_TYPE: { - // Return the type of the socket. This information can simply be - // obtained by looking at the file descriptor type. - __wasi_fdstat_t fsb; - if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { - errno = EBADF; - return -1; - } - if (fsb.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM && - fsb.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM) { - errno = ENOTSOCK; - return -1; - } - value = fsb.fs_filetype; - break; - } - default: { - errno = ENOPROTOOPT; - return -1; - } - } - - // Copy out integer value. - memcpy(option_value, &value, - *option_len < sizeof(int) ? *option_len : sizeof(int)); - *option_len = sizeof(int); - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c deleted file mode 100644 index d35f8894fa4597f73accd9a718f04f9d65443eaf..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); -static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); - -ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { - // Validate flags. - if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { - errno = EOPNOTSUPP; - return -1; - } - - // Prepare input parameters. - __wasi_iovec_t iov = {.buf = buffer, .buf_len = length}; - __wasi_iovec_t *ri_data = &iov; - size_t ri_data_len = 1; - __wasi_riflags_t ri_flags = flags; - - // Perform system call. - size_t ro_datalen; - __wasi_roflags_t ro_flags; - __wasi_errno_t error = __wasi_sock_recv(socket, - ri_data, ri_data_len, ri_flags, - &ro_datalen, - &ro_flags); - if (error != 0) { - errno = error; - return -1; - } - return ro_datalen; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c deleted file mode 100644 index 85a298a73155af42b19e975734452d876a702eca..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include - -ssize_t send(int socket, const void *buffer, size_t length, int flags) { - // This implementation does not support any flags. - if (flags != 0) { - errno = EOPNOTSUPP; - return -1; - } - - // Prepare input parameters. - __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; - __wasi_ciovec_t *si_data = &iov; - size_t si_data_len = 1; - __wasi_siflags_t si_flags = 0; - - // Perform system call. - size_t so_datalen; - __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); - if (error != 0) { - errno = error; - return -1; - } - return so_datalen; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c deleted file mode 100644 index 261fcb81ea9cb8a19ed87509f9d3b4ec49b8695c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include - -static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); -static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); - -int shutdown(int socket, int how) { - // Validate shutdown flags. - if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) { - errno = EINVAL; - return -1; - } - - __wasi_errno_t error = __wasi_sock_shutdown(socket, how); - if (error != 0) { - errno = error; - return -1; - } - return error; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket_impl.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket_impl.h deleted file mode 100644 index 7b1a366d90a69f1aa3aba16f80c49d4762dee318..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket_impl.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifndef SYS_SOCKET_SOCKET_IMPL_H -#define SYS_SOCKET_SOCKET_IMPL_H - -#include -#include - -#include - -#include -#include -#include -#include - -static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr), - "struct sockaddr_storage too small"); -static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr), - "struct sockaddr alignment incorrect"); -static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr_in), - "struct sockaddr_storage too small"); -static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr_in), - "struct sockaddr_in alignment incorrect"); -static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr_in6), - "struct sockaddr_storage too small"); -static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr_in6), - "struct sockaddr_in6 alignment incorrect"); -static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr_un), - "struct sockaddr_storage too small"); -static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr_un), - "struct sockaddr_un alignment incorrect"); - -// Returns the control message header stored at a provided memory -// address, ensuring that it is stored within the ancillary data buffer -// of a message header. -static inline struct cmsghdr *CMSG_GET(const struct msghdr *mhdr, void *cmsg) { - // Safety belt: require that the returned object is properly aligned. - assert((uintptr_t)cmsg % alignof(struct cmsghdr) == 0 && - "Attempted to access unaligned control message header"); - - // Safety belt: the computed starting address of the control message - // header may only lie inside the ancillary data buffer, or right - // after it in case we've reached the end of the buffer. - const unsigned char *begin = mhdr->msg_control; - const unsigned char *end = begin + mhdr->msg_controllen; - assert((unsigned char *)cmsg >= begin && - (unsigned char *)cmsg < end + alignof(struct cmsghdr) && - "Computed object outside of buffer boundaries"); - - // Only return the control message header in case all of its fields - // lie within the ancillary data buffer. - return CMSG_DATA((struct cmsghdr *)cmsg) <= end ? cmsg : NULL; -} - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c deleted file mode 100644 index b8ffdb59c7083baa8609dc0803a551e97e082e91..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -#include "stat_impl.h" - -int fstat(int fildes, struct stat *buf) { - __wasi_filestat_t internal_stat; - __wasi_errno_t error = __wasi_fd_filestat_get(fildes, &internal_stat); - if (error != 0) { - errno = error; - return -1; - } - to_public_stat(&internal_stat, buf); - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c deleted file mode 100644 index 25b29ac9821abc490883238a425243b75e5af314..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -#include "stat_impl.h" - -int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *restrict buf, - int flag) { - // Create lookup properties. - __wasi_lookupflags_t lookup_flags = 0; - if ((flag & AT_SYMLINK_NOFOLLOW) == 0) - lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; - - // Perform system call. - __wasi_filestat_t internal_stat; - __wasi_errno_t error = - __wasi_path_filestat_get(fd, lookup_flags, path, &internal_stat); - if (error != 0) { - errno = error; - return -1; - } - to_public_stat(&internal_stat, buf); - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c deleted file mode 100644 index 13357fcf0a7183f115b9823d3ee312c79cc86e9b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -#include "stat_impl.h" - -int futimens(int fd, const struct timespec *times) { - // Convert timestamps and extract NOW/OMIT flags. - __wasi_timestamp_t st_atim; - __wasi_timestamp_t st_mtim; - __wasi_fstflags_t flags; - if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { - errno = EINVAL; - return -1; - } - - // Perform system call. - __wasi_errno_t error = __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, flags); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c deleted file mode 100644 index fd27d5e1732146a874d4d190ca10868c1c3afd3c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include - -int __wasilibc_nocwd_mkdirat_nomode(int fd, const char *path) { - __wasi_errno_t error = __wasi_path_create_directory(fd, path); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h deleted file mode 100644 index 9726b5165685b7342c8e972c9e1f3dbc30682992..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h +++ /dev/null @@ -1,116 +0,0 @@ -// Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#ifndef SYS_STAT_STAT_IMPL_H -#define SYS_STAT_STAT_IMPL_H - -#include - -#include - -#include -#include -#include - -static_assert(S_ISBLK(S_IFBLK), "Value mismatch"); -static_assert(S_ISCHR(S_IFCHR), "Value mismatch"); -static_assert(S_ISDIR(S_IFDIR), "Value mismatch"); -static_assert(S_ISFIFO(S_IFIFO), "Value mismatch"); -static_assert(S_ISLNK(S_IFLNK), "Value mismatch"); -static_assert(S_ISREG(S_IFREG), "Value mismatch"); -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. - 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. - */ - /* nlink_t is 64-bit on wasm32, following the x32 ABI. */ - static_assert(sizeof(in->nlink) <= sizeof(out->st_nlink), "Size shortfall"); - static_assert(sizeof(in->size) == sizeof(out->st_size), "Size mismatch"); - - *out = (struct stat){ - .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), - }; - - // Convert file type to legacy types encoded in st_mode. - switch (in->filetype) { - case __WASI_FILETYPE_BLOCK_DEVICE: - out->st_mode |= S_IFBLK; - break; - case __WASI_FILETYPE_CHARACTER_DEVICE: - out->st_mode |= S_IFCHR; - break; - case __WASI_FILETYPE_DIRECTORY: - out->st_mode |= S_IFDIR; - break; - case __WASI_FILETYPE_REGULAR_FILE: - out->st_mode |= S_IFREG; - break; - case __WASI_FILETYPE_SOCKET_DGRAM: - case __WASI_FILETYPE_SOCKET_STREAM: - out->st_mode |= S_IFSOCK; - break; - case __WASI_FILETYPE_SYMBOLIC_LINK: - out->st_mode |= S_IFLNK; - break; - } -} - -static inline bool utimens_get_timestamps(const struct timespec *times, - __wasi_timestamp_t *st_atim, - __wasi_timestamp_t *st_mtim, - __wasi_fstflags_t *flags) { - if (times == NULL) { - // Update both timestamps. - *flags = __WASI_FSTFLAGS_ATIM_NOW | __WASI_FSTFLAGS_MTIM_NOW; - *st_atim = (__wasi_timestamp_t) { 0 }; - *st_mtim = (__wasi_timestamp_t) { 0 }; - } else { - // Set individual timestamps. - *flags = 0; - switch (times[0].tv_nsec) { - case UTIME_NOW: - *flags |= __WASI_FSTFLAGS_ATIM_NOW; - *st_atim = (__wasi_timestamp_t) { 0 }; - break; - case UTIME_OMIT: - *st_atim = (__wasi_timestamp_t) { 0 }; - break; - default: - *flags |= __WASI_FSTFLAGS_ATIM; - if (!timespec_to_timestamp_exact(×[0], st_atim)) - return false; - break; - } - - switch (times[1].tv_nsec) { - case UTIME_NOW: - *flags |= __WASI_FSTFLAGS_MTIM_NOW; - *st_mtim = (__wasi_timestamp_t) { 0 }; - break; - case UTIME_OMIT: - *st_mtim = (__wasi_timestamp_t) { 0 }; - break; - default: - *flags |= __WASI_FSTFLAGS_MTIM; - if (!timespec_to_timestamp_exact(×[1], st_mtim)) - return false; - break; - } - } - return true; -} - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c deleted file mode 100644 index 19508a1365109e021d341d7bbdb100b74a2969c8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -#include "stat_impl.h" - -int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec times[2], - int flag) { - // Convert timestamps and extract NOW/OMIT flags. - __wasi_timestamp_t st_atim; - __wasi_timestamp_t st_mtim; - __wasi_fstflags_t flags; - if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { - errno = EINVAL; - return -1; - } - - // Create lookup properties. - __wasi_lookupflags_t lookup_flags = 0; - if ((flag & AT_SYMLINK_NOFOLLOW) == 0) - lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; - - // Perform system call. - __wasi_errno_t error = - __wasi_path_filestat_set_times(fd, lookup_flags, path, st_atim, st_mtim, flags); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c deleted file mode 100644 index 596bdfff28e2c769b64c3ac4a89a3e9a72992e4e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include - -#include - -int gettimeofday(struct timeval *restrict tp, void *tz) { - if (tp != NULL) { - __wasi_timestamp_t ts = 0; - (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); - *tp = timestamp_to_timeval(ts); - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c deleted file mode 100644 index 36f882dd930dc197f67822d09bab78cbe3ce4cfb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include -#include - -ssize_t preadv(int fildes, const struct iovec *iov, int iovcnt, off_t offset) { - if (iovcnt < 0 || offset < 0) { - errno = EINVAL; - return -1; - } - size_t bytes_read; - __wasi_errno_t error = __wasi_fd_pread( - fildes, (const __wasi_iovec_t *)iov, iovcnt, offset, &bytes_read); - if (error != 0) { - errno = error; - return -1; - } - return bytes_read; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c deleted file mode 100644 index d6f885187025c56c27ee9e861cdadcaaa1802607..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include -#include - -ssize_t pwritev(int fildes, const struct iovec *iov, int iovcnt, off_t offset) { - if (iovcnt < 0 || offset < 0) { - errno = EINVAL; - return -1; - } - size_t bytes_written; - __wasi_errno_t error = __wasi_fd_pwrite( - fildes, (const __wasi_ciovec_t *)iov, iovcnt, offset, &bytes_written); - if (error != 0) { - errno = error; - return -1; - } - return bytes_written; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c deleted file mode 100644 index e3eaebe467827dae5979c2883855f1fcaec231bd..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -static_assert(offsetof(struct iovec, iov_base) == - offsetof(__wasi_iovec_t, buf), - "Offset mismatch"); -static_assert(sizeof(((struct iovec *)0)->iov_base) == - sizeof(((__wasi_iovec_t *)0)->buf), - "Size mismatch"); -static_assert(offsetof(struct iovec, iov_len) == - offsetof(__wasi_iovec_t, buf_len), - "Offset mismatch"); -static_assert(sizeof(((struct iovec *)0)->iov_len) == - sizeof(((__wasi_iovec_t *)0)->buf_len), - "Size mismatch"); -static_assert(sizeof(struct iovec) == sizeof(__wasi_iovec_t), - "Size mismatch"); - -ssize_t readv(int fildes, const struct iovec *iov, int iovcnt) { - if (iovcnt < 0) { - errno = EINVAL; - return -1; - } - size_t bytes_read; - __wasi_errno_t error = __wasi_fd_read( - fildes, (const __wasi_iovec_t *)iov, iovcnt, &bytes_read); - if (error != 0) { - errno = error; - return -1; - } - return bytes_read; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c deleted file mode 100644 index 459b1526434a9e1594c2d5537a0c08371b0a9f8b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -static_assert(offsetof(struct iovec, iov_base) == - offsetof(__wasi_ciovec_t, buf), - "Offset mismatch"); -static_assert(sizeof(((struct iovec *)0)->iov_base) == - sizeof(((__wasi_ciovec_t *)0)->buf), - "Size mismatch"); -static_assert(offsetof(struct iovec, iov_len) == - offsetof(__wasi_ciovec_t, buf_len), - "Offset mismatch"); -static_assert(sizeof(((struct iovec *)0)->iov_len) == - sizeof(((__wasi_ciovec_t *)0)->buf_len), - "Size mismatch"); -static_assert(sizeof(struct iovec) == sizeof(__wasi_ciovec_t), - "Size mismatch"); - -ssize_t writev(int fildes, const struct iovec *iov, int iovcnt) { - if (iovcnt < 0) { - errno = EINVAL; - return -1; - } - size_t bytes_written; - __wasi_errno_t error = __wasi_fd_write( - fildes, (const __wasi_ciovec_t *)iov, iovcnt, &bytes_written); - if (error != 0) { - errno = error; - return -1; - } - return bytes_written; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c deleted file mode 100644 index a4c4a62c685f7997282bab67337846f6324e4ce0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -const struct __clockid _CLOCK_MONOTONIC = { - .id = __WASI_CLOCKID_MONOTONIC, -}; diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c deleted file mode 100644 index 952375444b9da8e59c37e4fc9c1c62cb13460cde..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -const struct __clockid _CLOCK_REALTIME = { - .id = __WASI_CLOCKID_REALTIME, -}; diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c deleted file mode 100644 index 8030d4bb3f24e58b8b370846e65902014d00cdcb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include -#include -#include - -int clock_getres(clockid_t clock_id, struct timespec *res) { - __wasi_timestamp_t ts; - __wasi_errno_t error = __wasi_clock_res_get(clock_id->id, &ts); - if (error != 0) { - errno = error; - return -1; - } - *res = timestamp_to_timespec(ts); - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c deleted file mode 100644 index c7e1a609e7b21c6fbd8b0544e6fcc660261f1898..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include -#include -#include - -int __clock_gettime(clockid_t clock_id, struct timespec *tp) { - __wasi_timestamp_t ts; - __wasi_errno_t error = __wasi_clock_time_get(clock_id->id, 1, &ts); - if (error != 0) { - errno = error; - return -1; - } - *tp = timestamp_to_timespec(ts); - return 0; -} -weak_alias(__clock_gettime, clock_gettime); diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c deleted file mode 100644 index d375056ff4da1262b511308b845cb2ae5ae0c942..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -#include -#include -#include -#include - -static_assert(TIMER_ABSTIME == __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME, - "Value mismatch"); - -int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, - struct timespec *rmtp) { - if ((flags & ~TIMER_ABSTIME) != 0) - return EINVAL; - - // Prepare polling subscription. - __wasi_subscription_t sub = { - .u.tag = __WASI_EVENTTYPE_CLOCK, - .u.u.clock.id = clock_id->id, - .u.u.clock.flags = flags, - }; - if (!timespec_to_timestamp_clamp(rqtp, &sub.u.u.clock.timeout)) - return EINVAL; - - // Block until polling event is triggered. - size_t nevents; - __wasi_event_t ev; - __wasi_errno_t error = __wasi_poll_oneoff(&sub, &ev, 1, &nevents); - return error == 0 && ev.error == 0 ? 0 : ENOTSUP; -} - -weak_alias(clock_nanosleep, __clock_nanosleep); diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c deleted file mode 100644 index 5f26c5cc6d8ee3e4ab05d55c4a92203010cccbe5..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -int nanosleep(const struct timespec *rqtp, struct timespec *rem) { - int error = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rem); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c deleted file mode 100644 index 52bc0e4842695f88f2d56042e5ae471fb26d9ce9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include - -time_t time(time_t *tloc) { - __wasi_timestamp_t ts = 0; - (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts); - if (tloc != NULL) - *tloc = ts / NSEC_PER_SEC; - return ts / NSEC_PER_SEC; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c deleted file mode 100644 index ffaef6ed6238dd14cb4e5a58450185731731fa8f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c +++ /dev/null @@ -1,53 +0,0 @@ -// Copyright (c) 2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include -#include - -int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) { - // Validate function parameters. - if ((amode & ~(F_OK | R_OK | W_OK | X_OK)) != 0 || - (flag & ~AT_EACCESS) != 0) { - errno = EINVAL; - return -1; - } - - // Check for target file existence and obtain the file type. - __wasi_lookupflags_t lookup_flags = __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; - __wasi_filestat_t file; - __wasi_errno_t error = - __wasi_path_filestat_get(fd, lookup_flags, path, &file); - if (error != 0) { - errno = error; - return -1; - } - - // Test whether the requested access rights are present on the - // directory file descriptor. - if (amode != 0) { - __wasi_fdstat_t directory; - error = __wasi_fd_fdstat_get(fd, &directory); - if (error != 0) { - errno = error; - return -1; - } - - __wasi_rights_t min = 0; - if ((amode & R_OK) != 0) - min |= file.filetype == __WASI_FILETYPE_DIRECTORY - ? __WASI_RIGHTS_FD_READDIR - : __WASI_RIGHTS_FD_READ; - if ((amode & W_OK) != 0) - min |= __WASI_RIGHTS_FD_WRITE; - - if ((min & directory.fs_rights_inheriting) != min) { - errno = EACCES; - return -1; - } - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c deleted file mode 100644 index b821b0668b0151e0c085dc96feceee5d9df9678a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -int fdatasync(int fildes) { - __wasi_errno_t error = __wasi_fd_datasync(fildes); - if (error != 0) { - errno = error == ENOTCAPABLE ? EBADF : error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c deleted file mode 100644 index 733e29479431006a88b75eeb894ae36cd7e8f9f4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -int fsync(int fildes) { - __wasi_errno_t error = __wasi_fd_sync(fildes); - if (error != 0) { - errno = error == ENOTCAPABLE ? EINVAL : error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c deleted file mode 100644 index 7792597e2f51621d67f4e15b60b6963622f89198..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -int ftruncate(int fildes, off_t length) { - if (length < 0) { - errno = EINVAL; - return -1; - } - __wasi_filesize_t st_size = length; - __wasi_errno_t error = - __wasi_fd_filestat_set_size(fildes, st_size); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c deleted file mode 100644 index d57f5621d62ca829a493b768dde6c94bb9f7b71a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include -#include - -int __wasilibc_nocwd_linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) { - // Create lookup properties. - __wasi_lookupflags_t lookup1_flags = 0; - if ((flag & AT_SYMLINK_FOLLOW) != 0) - lookup1_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; - - // Perform system call. - __wasi_errno_t error = __wasi_path_link(fd1, lookup1_flags, path1, fd2, path2); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c deleted file mode 100644 index 3e0429f10f7cad6cc9dd1e43dee40386b0576374..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -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"); - -off_t __lseek(int fildes, off_t offset, int whence) { - __wasi_filesize_t new_offset; - __wasi_errno_t error = - __wasi_fd_seek(fildes, offset, whence, &new_offset); - if (error != 0) { - errno = error == ENOTCAPABLE ? ESPIPE : error; - return -1; - } - return new_offset; -} - -weak_alias(__lseek, lseek); diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c deleted file mode 100644 index c9944bc4e8ab797fb8f007f5e074fa0be10d5c93..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset) { - if (offset < 0) { - errno = EINVAL; - return -1; - } - __wasi_iovec_t iov = {.buf = buf, .buf_len = nbyte}; - size_t bytes_read; - __wasi_errno_t error = - __wasi_fd_pread(fildes, &iov, 1, offset, &bytes_read); - if (error != 0) { - __wasi_fdstat_t fds; - if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) { - // Determine why we got ENOTCAPABLE. - if ((fds.fs_rights_base & __WASI_RIGHTS_FD_READ) == 0) - error = EBADF; - else - error = ESPIPE; - } - errno = error; - return -1; - } - return bytes_read; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c deleted file mode 100644 index f80bc406b9a0ec311107a76c300a54b279b988c7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) { - if (offset < 0) { - errno = EINVAL; - return -1; - } - __wasi_ciovec_t iov = {.buf = buf, .buf_len = nbyte}; - size_t bytes_written; - __wasi_errno_t error = - __wasi_fd_pwrite(fildes, &iov, 1, offset, &bytes_written); - if (error != 0) { - __wasi_fdstat_t fds; - if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) { - // Determine why we got ENOTCAPABLE. - if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) == 0) - error = EBADF; - else - error = ESPIPE; - } - errno = error; - return -1; - } - return bytes_written; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c deleted file mode 100644 index 1582126e1b58cd0f84ae91e94b0748d96a828156..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -ssize_t read(int fildes, void *buf, size_t nbyte) { - __wasi_iovec_t iov = {.buf = buf, .buf_len = nbyte}; - size_t bytes_read; - __wasi_errno_t error = __wasi_fd_read(fildes, &iov, 1, &bytes_read); - if (error != 0) { - errno = error == ENOTCAPABLE ? EBADF : error; - return -1; - } - return bytes_read; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c deleted file mode 100644 index 7a3bce27b7a38a58dbbac2af58c8f3dbd952e4fe..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -ssize_t __wasilibc_nocwd_readlinkat(int fd, const char *restrict path, char *restrict buf, - size_t bufsize) { - size_t bufused; - // TODO: Remove the cast on `buf` once the witx is updated with char8 support. - __wasi_errno_t error = __wasi_path_readlink(fd, path, - (uint8_t*)buf, bufsize, &bufused); - if (error != 0) { - errno = error; - return -1; - } - return bufused; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c deleted file mode 100644 index 970287b62fb1babece575f166e0a7644ecb8b616..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (c) 2015 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include - -unsigned int sleep(unsigned int seconds) { - struct timespec ts = {.tv_sec = seconds, .tv_nsec = 0}; - if (clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL) != 0) - return seconds; - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c deleted file mode 100644 index 0aa38be2cd49fe0f8f2b6c0c3ed60fffdcd5e384..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include - -int __wasilibc_nocwd_symlinkat(const char *path1, int fd, const char *path2) { - __wasi_errno_t error = __wasi_path_symlink(path1, fd, path2); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c deleted file mode 100644 index 351bf9264570c0051b8b6a144d16b741f1eae92c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include -#include -#include -#include - -int unlinkat(int fd, const char *path, int flag) { - if ((flag & AT_REMOVEDIR) != 0) { - return __wasilibc_rmdirat(fd, path); - } - return __wasilibc_unlinkat(fd, path); -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c deleted file mode 100644 index 8005f172594ceafdfa1fa49ec82228f5797f2b5a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -int usleep(useconds_t useconds) { - struct timespec ts = {.tv_sec = useconds / 1000000, - .tv_nsec = useconds % 1000000 * 1000}; - int error = clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c b/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c deleted file mode 100644 index a6567e80952a9bafcc87c6a45874e105bc8925e8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ -// -// SPDX-License-Identifier: BSD-2-Clause - -#include -#include -#include - -ssize_t write(int fildes, const void *buf, size_t nbyte) { - __wasi_ciovec_t iov = {.buf = buf, .buf_len = nbyte}; - size_t bytes_written; - __wasi_errno_t error = - __wasi_fd_write(fildes, &iov, 1, &bytes_written); - if (error != 0) { - errno = error == ENOTCAPABLE ? EBADF : error; - return -1; - } - return bytes_written; -} diff --git a/lib/libc/wasi/libc-bottom-half/crt/crt1-command.c b/lib/libc/wasi/libc-bottom-half/crt/crt1-command.c deleted file mode 100644 index 1639dec13642c332cd3a7b8b08ef26c3490f6d8a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/crt/crt1-command.c +++ /dev/null @@ -1,64 +0,0 @@ -#ifdef _REENTRANT -#include -extern void __wasi_init_tp(void); -#endif -#ifdef __wasilibc_use_wasip2 -#include -#else -#include -#endif -extern void __wasm_call_ctors(void); -extern int __main_void(void); -extern void __wasm_call_dtors(void); - -__attribute__((export_name("_start"))) -void _start(void) { - // Commands should only be called once per instance. This simple check - // ensures that the `_start` function isn't started more than once. - // - // We use `volatile` here to prevent the store to `started` from being - // sunk past any subsequent code, and to prevent any compiler from - // optimizing based on the knowledge that `_start` is the program - // entrypoint. -#ifdef _REENTRANT - static volatile _Atomic int started = 0; - int expected = 0; - if (!atomic_compare_exchange_strong(&started, &expected, 1)) { - __builtin_trap(); - } -#else - static volatile int started = 0; - if (started != 0) { - __builtin_trap(); - } - started = 1; -#endif - -#ifdef _REENTRANT - __wasi_init_tp(); -#endif - - // The linker synthesizes this to call constructors. - __wasm_call_ctors(); - - // Call `__main_void` which will either be the application's zero-argument - // `__main_void` function or a libc routine which obtains the command-line - // arguments and calls `__main_argv_argc`. - int r = __main_void(); - - // Call atexit functions, destructors, stdio cleanup, etc. - __wasm_call_dtors(); - - // If main exited successfully, just return, otherwise call - // `__wasi_proc_exit`. -#ifdef __wasilibc_use_wasip2 - if (r != 0) { - exit_result_void_void_t status = { .is_err = true }; - exit_exit(&status); - } -#else - if (r != 0) { - __wasi_proc_exit(r); - } -#endif -} diff --git a/lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c b/lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c deleted file mode 100644 index ea4a84f8de6e475de2fd58d16eb4f88db3d8764b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c +++ /dev/null @@ -1,27 +0,0 @@ -#if defined(_REENTRANT) -#include -extern void __wasi_init_tp(void); -#endif -extern void __wasm_call_ctors(void); - -__attribute__((export_name("_initialize"))) -void _initialize(void) { -#if defined(_REENTRANT) - static volatile atomic_int initialized = 0; - int expected = 0; - if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) { - __builtin_trap(); - } - - __wasi_init_tp(); -#else - static volatile int initialized = 0; - if (initialized != 0) { - __builtin_trap(); - } - initialized = 1; -#endif - - // The linker synthesizes this to call constructors. - __wasm_call_ctors(); -} diff --git a/lib/libc/wasi/libc-bottom-half/getpid/getpid.c b/lib/libc/wasi/libc-bottom-half/getpid/getpid.c deleted file mode 100644 index d2920ac521b3af67425a27ca87f3da00cc528b6c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/getpid/getpid.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -pid_t getpid(void) { - // Return an arbitrary value, greater than 1 which is special. - return 42; -} diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/_/limits.h b/lib/libc/wasi/libc-bottom-half/headers/private/_/limits.h deleted file mode 100644 index 1e189a16ecec5fe05942b5111b09c257a6325fef..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/_/limits.h +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timespec.h b/lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timespec.h deleted file mode 100644 index fbe602a1e0a8df2632699ab515d0b7c8c759b7ed..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timespec.h +++ /dev/null @@ -1 +0,0 @@ -#include <__struct_timespec.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timeval.h b/lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timeval.h deleted file mode 100644 index 9cabfd73e5999c96d8f51971ea07e6dcdc7f410d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timeval.h +++ /dev/null @@ -1 +0,0 @@ -#include <__struct_timeval.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/_/types.h b/lib/libc/wasi/libc-bottom-half/headers/private/_/types.h deleted file mode 100644 index 42b17e5d1f2e0ce097217198c76f35f261c16a2a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/_/types.h +++ /dev/null @@ -1,9 +0,0 @@ -#include <_/cdefs.h> -#include -#include -#include -#include -#include - -typedef uint64_t __uint64_t; -#define _UINT64_C UINT64_C diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/assert.h b/lib/libc/wasi/libc-bottom-half/headers/private/assert.h deleted file mode 100644 index 8e19ff46c53174463e2dc3641156149b74d4f7d6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/assert.h +++ /dev/null @@ -1,7 +0,0 @@ -#include - -#ifndef __cplusplus -#define static_assert _Static_assert -#endif - -#define assert(x) ((void)((x) || (abort(), 0))) diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/common/crt.h b/lib/libc/wasi/libc-bottom-half/headers/private/common/crt.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/errno.h b/lib/libc/wasi/libc-bottom-half/headers/private/errno.h deleted file mode 100644 index 3b37313d943f2695bdfea696aecdc44d6e47a399..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/errno.h +++ /dev/null @@ -1,2 +0,0 @@ -#include_next -#define EOPNOTSUPP ENOTSUP diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/fcntl.h b/lib/libc/wasi/libc-bottom-half/headers/private/fcntl.h deleted file mode 100644 index 3210418b2d5561b627caa1753a05f1f41bbad06b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/fcntl.h +++ /dev/null @@ -1,2 +0,0 @@ -#include_next -#include <_/types.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/sched.h b/lib/libc/wasi/libc-bottom-half/headers/private/sched.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/stdarg.h b/lib/libc/wasi/libc-bottom-half/headers/private/stdarg.h deleted file mode 100644 index e01960829d10854eed7df8ea889d72f22b59ba5b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/stdarg.h +++ /dev/null @@ -1,2 +0,0 @@ -#include_next -#include <_/cdefs.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/stdint.h b/lib/libc/wasi/libc-bottom-half/headers/private/stdint.h deleted file mode 100644 index 1fed338419aac237975215dbac6ebe45dd67d286..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/stdint.h +++ /dev/null @@ -1,12 +0,0 @@ -#include_next - -#define __need_size_t -#include - -#include <__typedef_clock_t.h> -#include <__typedef_time_t.h> -#include <__typedef_blksize_t.h> -#include <__typedef_off_t.h> -#include <__typedef_ssize_t.h> -#include <__typedef_suseconds_t.h> -#include <__typedef_nlink_t.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/stdio.h b/lib/libc/wasi/libc-bottom-half/headers/private/stdio.h deleted file mode 100644 index b135b6aba622660b00d3e2ec43ac74766442e9b2..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/stdio.h +++ /dev/null @@ -1,3 +0,0 @@ -#include <_/cdefs.h> -int snprintf(char *str, size_t size, const char *format, ...); -int rename(const char *oldpath, const char *newpath); diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/stdlib.h b/lib/libc/wasi/libc-bottom-half/headers/private/stdlib.h deleted file mode 100644 index 8c2b395a6b2c3181e0e07a41bdef0ba736843afe..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/stdlib.h +++ /dev/null @@ -1,8 +0,0 @@ -#define __need_size_t -#define __need_wchar_t -#define __need_NULL -#include - -#include_next - -int clearenv(void); diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/string.h b/lib/libc/wasi/libc-bottom-half/headers/private/string.h deleted file mode 100644 index 1c4ce192cfe9cf5b8fa1a54c082ab2b28a9604e3..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/string.h +++ /dev/null @@ -1,2 +0,0 @@ -#include_next -#include <_/cdefs.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/sys/mman.h b/lib/libc/wasi/libc-bottom-half/headers/private/sys/mman.h deleted file mode 100644 index bdd5401da35ad26f4c4a7d91c0c8e54e92c3c099..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/sys/mman.h +++ /dev/null @@ -1,2 +0,0 @@ -#include_next -#include <_/types.h> diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/threads.h b/lib/libc/wasi/libc-bottom-half/headers/private/threads.h deleted file mode 100644 index b51ef0d80d3f4f238d90985e22ec908e26cebf9a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/threads.h +++ /dev/null @@ -1,3 +0,0 @@ -#ifndef __cplusplus -#define thread_local _Thread_local -#endif diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/wasi/descriptor_table.h b/lib/libc/wasi/libc-bottom-half/headers/private/wasi/descriptor_table.h deleted file mode 100644 index 8e9a90d9d16036caf36a4038984b2abdcf74a884..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/wasi/descriptor_table.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef DESCRIPTOR_TABLE_H -#define DESCRIPTOR_TABLE_H - -#include - -typedef struct { - int dummy; -} tcp_socket_state_unbound_t; -typedef struct { - int dummy; -} tcp_socket_state_bound_t; -typedef struct { - int dummy; -} tcp_socket_state_connecting_t; -typedef struct { - int dummy; -} tcp_socket_state_listening_t; - -typedef struct { - streams_own_input_stream_t input; - poll_own_pollable_t input_pollable; - streams_own_output_stream_t output; - poll_own_pollable_t output_pollable; -} tcp_socket_state_connected_t; - -typedef struct { - network_error_code_t error_code; -} tcp_socket_state_connect_failed_t; - -// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. -typedef struct { - enum { - TCP_SOCKET_STATE_UNBOUND, - TCP_SOCKET_STATE_BOUND, - TCP_SOCKET_STATE_CONNECTING, - TCP_SOCKET_STATE_CONNECTED, - TCP_SOCKET_STATE_CONNECT_FAILED, - TCP_SOCKET_STATE_LISTENING, - } tag; - union { - tcp_socket_state_unbound_t unbound; - tcp_socket_state_bound_t bound; - tcp_socket_state_connecting_t connecting; - tcp_socket_state_connected_t connected; - tcp_socket_state_connect_failed_t connect_failed; - tcp_socket_state_listening_t listening; - }; -} tcp_socket_state_t; - -typedef struct { - tcp_own_tcp_socket_t socket; - poll_own_pollable_t socket_pollable; - bool blocking; - bool fake_nodelay; - bool fake_reuseaddr; - network_ip_address_family_t family; - tcp_socket_state_t state; -} tcp_socket_t; - -typedef struct { - udp_own_incoming_datagram_stream_t incoming; - poll_own_pollable_t incoming_pollable; - udp_own_outgoing_datagram_stream_t outgoing; - poll_own_pollable_t outgoing_pollable; -} udp_socket_streams_t; - -typedef struct { - int dummy; -} udp_socket_state_unbound_t; -typedef struct { - int dummy; -} udp_socket_state_bound_nostreams_t; - -typedef struct { - udp_socket_streams_t streams; // Streams have no remote_address -} udp_socket_state_bound_streaming_t; - -typedef struct { - udp_socket_streams_t streams; // Streams have a remote_address -} udp_socket_state_connected_t; - -// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. -// The "bound" state is split up into two distinct tags: -// - "bound_nostreams": Bound, but no datagram streams set up (yet). That will be done the first time send or recv is called. -// - "bound_streaming": Bound with active streams. -typedef struct { - enum { - UDP_SOCKET_STATE_UNBOUND, - UDP_SOCKET_STATE_BOUND_NOSTREAMS, - UDP_SOCKET_STATE_BOUND_STREAMING, - UDP_SOCKET_STATE_CONNECTED, - } tag; - union { - udp_socket_state_unbound_t unbound; - udp_socket_state_bound_nostreams_t bound_nostreams; - udp_socket_state_bound_streaming_t bound_streaming; - udp_socket_state_connected_t connected; - }; -} udp_socket_state_t; - -typedef struct { - udp_own_udp_socket_t socket; - poll_own_pollable_t socket_pollable; - bool blocking; - network_ip_address_family_t family; - udp_socket_state_t state; -} udp_socket_t; - -// This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. -typedef struct { - enum { - DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, - DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, - } tag; - union { - tcp_socket_t tcp_socket; - udp_socket_t udp_socket; - }; -} descriptor_table_entry_t; - -bool descriptor_table_insert(descriptor_table_entry_t entry, int *fd); - -bool descriptor_table_get_ref(int fd, descriptor_table_entry_t **entry); - -bool descriptor_table_remove(int fd, descriptor_table_entry_t *entry); - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/headers/private/wasi/sockets_utils.h b/lib/libc/wasi/libc-bottom-half/headers/private/wasi/sockets_utils.h deleted file mode 100644 index 354664d9caa461094ebcc1b2cf1126beb7e51b95..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/headers/private/wasi/sockets_utils.h +++ /dev/null @@ -1,67 +0,0 @@ -#ifndef __wasi_sockets_utils_h -#define __wasi_sockets_utils_h - -#include - -#include - -typedef struct { - enum { - OUTPUT_SOCKADDR_NULL, - OUTPUT_SOCKADDR_V4, - OUTPUT_SOCKADDR_V6, - } tag; - union { - struct { - int dummy; - } null; - struct { - struct sockaddr_in *addr; - socklen_t *addrlen; - } v4; - struct { - struct sockaddr_in6 *addr; - socklen_t *addrlen; - } v6; - }; -} output_sockaddr_t; - -typedef struct { - char *s_name; - uint16_t port; - uint16_t protocol; -} service_entry_t; - -typedef enum { - SERVICE_PROTOCOL_TCP = 1, - SERVICE_PROTOCOL_UDP = 2 -} service_protocol_e; - -network_borrow_network_t __wasi_sockets_utils__borrow_network(); -int __wasi_sockets_utils__map_error(network_error_code_t wasi_error); -bool __wasi_sockets_utils__parse_address( - network_ip_address_family_t expected_family, - const struct sockaddr *address, socklen_t len, - network_ip_socket_address_t *result, int *error); -bool __wasi_sockets_utils__output_addr_validate( - network_ip_address_family_t expected_family, struct sockaddr *addr, - socklen_t *addrlen, output_sockaddr_t *result); -void __wasi_sockets_utils__output_addr_write( - const network_ip_socket_address_t input, output_sockaddr_t *output); -int __wasi_sockets_utils__posix_family(network_ip_address_family_t wasi_family); -network_ip_socket_address_t -__wasi_sockets_utils__any_addr(network_ip_address_family_t family); -int __wasi_sockets_utils__tcp_bind(tcp_socket_t *socket, - network_ip_socket_address_t *address); -int __wasi_sockets_utils__udp_bind(udp_socket_t *socket, - network_ip_socket_address_t *address); -bool __wasi_sockets_utils__stream(udp_socket_t *socket, - network_ip_socket_address_t *remote_address, - udp_socket_streams_t *result, - network_error_code_t *error); -void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams); -int __wasi_sockets_utils__parse_port(const char *port); -const service_entry_t *__wasi_sockets_utils__get_service_entry_by_name(const char *name); -const service_entry_t *__wasi_sockets_utils__get_service_entry_by_port(const uint16_t port); - -#endif diff --git a/lib/libc/wasi/libc-bottom-half/mman/mman.c b/lib/libc/wasi/libc-bottom-half/mman/mman.c deleted file mode 100644 index 6f672e2896b713777c28d9c091956c0562823981..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/mman/mman.c +++ /dev/null @@ -1,157 +0,0 @@ -// Userspace emulation of mmap and munmap. Restrictions apply. -// -// This is meant to be complete enough to be compatible with code that uses -// mmap for simple file I/O. It just allocates memory with malloc and reads -// and writes data with pread and pwrite. - -#define _WASI_EMULATED_MMAN -#include -#include -#include -#include -#include -#include -#include - -struct map { - int prot; - int flags; - off_t offset; - size_t length; -}; - -void *mmap(void *addr, size_t length, int prot, int flags, - int fd, off_t offset) { - // Check for unsupported flags. - if ((flags & (MAP_PRIVATE | MAP_SHARED)) == 0 || - (flags & MAP_FIXED) != 0 || -#ifdef MAP_SHARED_VALIDATE - (flags & MAP_SHARED_VALIDATE) == MAP_SHARED_VALIDATE || -#endif -#ifdef MAP_NORESERVE - (flags & MAP_NORESERVE) != 0 || -#endif -#ifdef MAP_GROWSDOWN - (flags & MAP_GROWSDOWN) != 0 || -#endif -#ifdef MAP_HUGETLB - (flags & MAP_HUGETLB) != 0 || -#endif -#ifdef MAP_FIXED_NOREPLACE - (flags & MAP_FIXED_NOREPLACE) != 0 || -#endif - 0) - { - errno = EINVAL; - return MAP_FAILED; - } - - // Check for unsupported protection requests. - if (prot == PROT_NONE || -#ifdef PROT_EXEC - (prot & PROT_EXEC) != 0 || -#endif - 0) - { - errno = EINVAL; - return MAP_FAILED; - } - - // To be consistent with POSIX. - if (length == 0) { - errno = EINVAL; - return MAP_FAILED; - } - - // Check for integer overflow. - size_t buf_len = 0; - if (__builtin_add_overflow(length, sizeof(struct map), &buf_len)) { - errno = ENOMEM; - return MAP_FAILED; - } - - // Allocate the memory. - struct map *map = malloc(buf_len); - if (!map) { - errno = ENOMEM; - return MAP_FAILED; - } - - // Initialize the header. - map->prot = prot; - map->flags = flags; - map->offset = offset; - map->length = length; - - // Initialize the main memory buffer, either with the contents of a file, - // or with zeros. - addr = map + 1; - if ((flags & MAP_ANON) == 0) { - char *body = (char *)addr; - while (length > 0) { - const ssize_t nread = pread(fd, body, length, offset); - if (nread < 0) { - if (errno == EINTR) - continue; - return MAP_FAILED; - } - if (nread == 0) - break; - length -= (size_t)nread; - offset += (size_t)nread; - body += (size_t)nread; - } - } else { - memset(addr, 0, length); - } - - return addr; -} - -int munmap(void *addr, size_t length) { - struct map *map = (struct map *)addr - 1; - - // We don't support partial munmapping. - if (map->length != length) { - errno = EINVAL; - return -1; - } - - // Release the memory. - free(map); - - // Success! - return 0; -} - -int mprotect(void *addr, size_t length, int prot) { - // Address must be page-aligned. - size_t begin = (size_t)addr; - if ((begin & (PAGESIZE - 1)) != 0) { - errno = EINVAL; - return -1; - } - - // Length must not be big enough to wrap around. - size_t end; - if (__builtin_add_overflow(begin, length, &end)) { - errno = ENOMEM; - return -1; - } - - // Range must be in bounds of linear memory. - size_t memory_size = __builtin_wasm_memory_size(0) * PAGESIZE; - if (end > memory_size) { - errno = ENOMEM; - return -1; - } - - // Can only protect memory as read/write (which is a no-op). - if (prot != (PROT_READ | PROT_WRITE)) { - errno = ENOTSUP; - return -1; - } - - // Success! - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/signal/signal.c b/lib/libc/wasi/libc-bottom-half/signal/signal.c deleted file mode 100644 index c9a435b394657476c3130b8c7e87597979ddfa51..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/signal/signal.c +++ /dev/null @@ -1,142 +0,0 @@ -// Userspace emulation of `raise` and `signal`. -// -// WebAssembly doesn't support asynchronous signal delivery, so we can't -// support it in WASI libc. But we can make things like `raise` work. - -#define _WASI_EMULATED_SIGNAL -#define _ALL_SOURCE -#define _GNU_SOURCE -#include -#include -#include -#include -#include -#include - -void __SIG_IGN(int sig) { - // do nothing -} - -_Noreturn -void __SIG_ERR(int sig) { - __builtin_trap(); -} - -_Noreturn -static void core_handler(int sig) { - fprintf(stderr, "Program received fatal signal: %s\n", strsignal(sig)); - abort(); -} - -_Noreturn -static void terminate_handler(int sig) { - fprintf(stderr, "Program received termination signal: %s\n", strsignal(sig)); - abort(); -} - -_Noreturn -static void stop_handler(int sig) { - fprintf(stderr, "Program received stop signal: %s\n", strsignal(sig)); - abort(); -} - -static void continue_handler(int sig) { - // do nothing -} - -static const sighandler_t default_handlers[_NSIG] = { - // Default behavior: "core". - [SIGABRT] = core_handler, - [SIGBUS] = core_handler, - [SIGFPE] = core_handler, - [SIGILL] = core_handler, -#if SIGIOT != SIGABRT - [SIGIOT] = core_handler, -#endif - [SIGQUIT] = core_handler, - [SIGSEGV] = core_handler, - [SIGSYS] = core_handler, - [SIGTRAP] = core_handler, - [SIGXCPU] = core_handler, - [SIGXFSZ] = core_handler, -#if defined(SIGUNUSED) && SIGUNUSED != SIGSYS - [SIGUNUSED] = core_handler, -#endif - - // Default behavior: ignore. - [SIGCHLD] = SIG_IGN, -#if defined(SIGCLD) && SIGCLD != SIGCHLD - [SIGCLD] = SIG_IGN, -#endif - [SIGURG] = SIG_IGN, - [SIGWINCH] = SIG_IGN, - - // Default behavior: "continue". - [SIGCONT] = continue_handler, - - // Default behavior: "stop". - [SIGSTOP] = stop_handler, - [SIGTSTP] = stop_handler, - [SIGTTIN] = stop_handler, - [SIGTTOU] = stop_handler, - - // Default behavior: "terminate". - [SIGHUP] = terminate_handler, - [SIGINT] = terminate_handler, - [SIGKILL] = terminate_handler, - [SIGUSR1] = terminate_handler, - [SIGUSR2] = terminate_handler, - [SIGPIPE] = terminate_handler, - [SIGALRM] = terminate_handler, - [SIGTERM] = terminate_handler, - [SIGSTKFLT] = terminate_handler, - [SIGVTALRM] = terminate_handler, - [SIGPROF] = terminate_handler, - [SIGIO] = terminate_handler, -#if SIGPOLL != SIGIO - [SIGPOLL] = terminate_handler, -#endif - [SIGPWR] = terminate_handler, -}; - -static sighandler_t handlers[_NSIG]; - -int raise(int sig) { - if (sig < 0 || sig >= _NSIG) { - errno = EINVAL; - return -1; - } - - sighandler_t func = handlers[sig]; - - if (func == NULL) { - default_handlers[sig](sig); - } else { - func(sig); - } - - return 0; -} - -void (*signal(int sig, void (*func)(int)))(int) { - assert(SIG_DFL == NULL); - - if (sig < 0 || sig >= _NSIG) { - errno = EINVAL; - return SIG_ERR; - } - - if (sig == SIGKILL || sig == SIGSTOP) { - errno = EINVAL; - return SIG_ERR; - } - - sighandler_t old = handlers[sig]; - - handlers[sig] = func; - - return old; -} - -extern __typeof(signal) bsd_signal __attribute__((weak, alias("signal"))); -extern __typeof(signal) __sysv_signal __attribute__((weak, alias("signal"))); diff --git a/lib/libc/wasi/libc-bottom-half/sources/__errno_location.c b/lib/libc/wasi/libc-bottom-half/sources/__errno_location.c deleted file mode 100644 index 5e6ef5e6bfabf7bbd5b3fec887f5524e03e21c8a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__errno_location.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int *__errno_location(void) { - return &errno; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__main_void.c b/lib/libc/wasi/libc-bottom-half/sources/__main_void.c deleted file mode 100644 index c40241fa3e5a6a46912c4bad6ab03189819cf4f4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__main_void.c +++ /dev/null @@ -1,110 +0,0 @@ -#ifdef __wasilibc_use_wasip2 -#include -#else -#include -#endif -#include -#include - -// The user's `main` function, expecting arguments. -// -// Note that we make this a weak symbol so that it will have a -// `WASM_SYM_BINDING_WEAK` flag in libc.so, which tells the dynamic linker that -// it need not be defined (e.g. in reactor-style apps with no main function). -// See also the TODO comment on `__main_void` below. -__attribute__((__weak__)) -int __main_argc_argv(int argc, char *argv[]); - -// If the user's `main` function expects arguments, the compiler will rename -// it to `__main_argc_argv`, and this version will get linked in, which -// initializes the argument data and calls `__main_argc_argv`. -// -// TODO: Ideally this function would be defined in a crt*.o file and linked in -// as necessary by the Clang driver. However, moving it to crt1-command.c -// breaks `--no-gc-sections`, so we'll probably need to create a new file -// (e.g. crt0.o or crtend.o) and teach Clang to use it when needed. -__attribute__((__weak__, nodebug)) -int __main_void(void) { -#ifdef __wasilibc_use_wasip2 - wasip2_list_string_t argument_list; - - environment_get_arguments(&argument_list); - - // Add 1 for the NULL pointer to mark the end, and check for overflow. - size_t argc = argument_list.len; - size_t num_ptrs = argc + 1; - if (num_ptrs == 0) { - wasip2_list_string_free(&argument_list); - _Exit(EX_SOFTWARE); - } - - // Allocate memory for the array of pointers. This uses `calloc` both to - // handle overflow and to initialize the NULL pointer at the end. - char **argv = calloc(num_ptrs, sizeof(char *)); - if (argv == NULL) { - wasip2_list_string_free(&argument_list); - _Exit(EX_SOFTWARE); - } - - // Copy the arguments - for (size_t i = 0; i < argc; i++) { - wasip2_string_t wasi_string = argument_list.ptr[i]; - size_t len = wasi_string.len; - argv[i] = malloc(len + 1); - if (!argv[i]) { - wasip2_list_string_free(&argument_list); - _Exit(EX_SOFTWARE); - } - memcpy(argv[i], wasi_string.ptr, len); - argv[i][len] = '\0'; - } - - // Free the WASI argument list - wasip2_list_string_free(&argument_list); - - // Call `__main_argc_argv` with the arguments! - return __main_argc_argv(argc, argv); -#else - __wasi_errno_t err; - - // Get the sizes of the arrays we'll have to create to copy in the args. - size_t argv_buf_size; - size_t argc; - err = __wasi_args_sizes_get(&argc, &argv_buf_size); - if (err != __WASI_ERRNO_SUCCESS) { - _Exit(EX_OSERR); - } - - // Add 1 for the NULL pointer to mark the end, and check for overflow. - size_t num_ptrs = argc + 1; - if (num_ptrs == 0) { - _Exit(EX_SOFTWARE); - } - - // Allocate memory for storing the argument chars. - char *argv_buf = malloc(argv_buf_size); - if (argv_buf == NULL) { - _Exit(EX_SOFTWARE); - } - - // Allocate memory for the array of pointers. This uses `calloc` both to - // handle overflow and to initialize the NULL pointer at the end. - char **argv = calloc(num_ptrs, sizeof(char *)); - if (argv == NULL) { - free(argv_buf); - _Exit(EX_SOFTWARE); - } - - // Fill the argument chars, and the argv array with pointers into those chars. - // 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); - } - - // Call `__main_argc_argv` with the arguments! - return __main_argc_argv(argc, argv); -#endif -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_dt.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_dt.c deleted file mode 100644 index b06460fcc91bfb16facc53ec0ae3a2276fa6da8f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_dt.c +++ /dev/null @@ -1,34 +0,0 @@ -#include <__header_dirent.h> -#include <__mode_t.h> - -int __wasilibc_iftodt(int x) { - switch (x) { - case S_IFDIR: return DT_DIR; - case S_IFCHR: return DT_CHR; - case S_IFBLK: return DT_BLK; - case S_IFREG: return DT_REG; - case S_IFIFO: return DT_FIFO; - case S_IFLNK: return DT_LNK; -#ifdef DT_SOCK - case S_IFSOCK: return DT_SOCK; -#endif - default: return DT_UNKNOWN; - } -} - -int __wasilibc_dttoif(int x) { - switch (x) { - case DT_DIR: return S_IFDIR; - case DT_CHR: return S_IFCHR; - case DT_BLK: return S_IFBLK; - case DT_REG: return S_IFREG; - case DT_FIFO: return S_IFIFO; - case DT_LNK: return S_IFLNK; -#ifdef DT_SOCK - case DT_SOCK: return S_IFSOCK; -#endif - case DT_UNKNOWN: - default: - return S_IFSOCK; - } -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_environ.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_environ.c deleted file mode 100644 index 53d0a553c8de545299492556096457c950e7c277..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_environ.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -extern char **__wasilibc_environ; - -// See the comments in libc-environ.h. -char **__wasilibc_get_environ(void) { - // Perform lazy initialization if needed. - __wasilibc_ensure_environ(); - - // Return `environ`. Use the `__wasilibc_`-prefixed name so that we don't - // pull in the `environ` symbol directly, which would lead to eager - // initialization being done instead. - return __wasilibc_environ; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c deleted file mode 100644 index bf2b3a2e935120c263dba0d3cf6ab21b2e19a654..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c +++ /dev/null @@ -1,72 +0,0 @@ -#include -#include -#include -#include - -int __wasilibc_fd_renumber(int fd, int newfd) { - // Scan the preopen fds before making any changes. - __wasilibc_populate_preopens(); - - __wasi_errno_t error = __wasi_fd_renumber(fd, newfd); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} - -#ifdef __wasilibc_use_wasip2 -#include - -void drop_tcp_socket(tcp_socket_t socket) { - switch (socket.state.tag) { - case TCP_SOCKET_STATE_UNBOUND: - case TCP_SOCKET_STATE_BOUND: - case TCP_SOCKET_STATE_CONNECTING: - case TCP_SOCKET_STATE_LISTENING: - case TCP_SOCKET_STATE_CONNECT_FAILED: - // No additional resources to drop. - break; - case TCP_SOCKET_STATE_CONNECTED: { - tcp_socket_state_connected_t connection = socket.state.connected; - - poll_pollable_drop_own(connection.input_pollable); - poll_pollable_drop_own(connection.output_pollable); - streams_input_stream_drop_own(connection.input); - streams_output_stream_drop_own(connection.output); - break; - } - default: /* unreachable */ abort(); - } - - poll_pollable_drop_own(socket.socket_pollable); - tcp_tcp_socket_drop_own(socket.socket); -} - -void drop_udp_socket_streams(udp_socket_streams_t streams) { - poll_pollable_drop_own(streams.incoming_pollable); - poll_pollable_drop_own(streams.outgoing_pollable); - udp_incoming_datagram_stream_drop_own(streams.incoming); - udp_outgoing_datagram_stream_drop_own(streams.outgoing); -} - -void drop_udp_socket(udp_socket_t socket) { - switch (socket.state.tag) { - case UDP_SOCKET_STATE_UNBOUND: - case UDP_SOCKET_STATE_BOUND_NOSTREAMS: - // No additional resources to drop. - break; - case UDP_SOCKET_STATE_BOUND_STREAMING: - drop_udp_socket_streams(socket.state.bound_streaming.streams); - break; - case UDP_SOCKET_STATE_CONNECTED: { - drop_udp_socket_streams(socket.state.connected.streams); - break; - } - default: /* unreachable */ abort(); - } - - poll_pollable_drop_own(socket.socket_pollable); - udp_udp_socket_drop_own(socket.socket); -} -#endif // __wasilibc_use_wasip2 diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c deleted file mode 100644 index 9eddb4b5ff6cc484355500359725d74c1f07017f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c +++ /dev/null @@ -1,147 +0,0 @@ -#include -#include -#include -#ifdef __wasilibc_use_wasip2 -#include -#else -#include -#endif -#include -#include - -/// If the program doesn't use `environ`, it'll get this version of -/// `__wasilibc_environ`, which isn't initialized with a constructor function. -/// `getenv` etc. call `__wasilibc_ensure_environ()` before accessing it. -/// Statically-initialize it to an invalid pointer value so that we can -/// detect if it's been explicitly initialized (we can't use `NULL` because -/// `clearenv` sets it to NULL. -weak char **__wasilibc_environ = (char **)-1; - -// See the comments in libc-environ.h. -void __wasilibc_ensure_environ(void) { - if (__wasilibc_environ == (char **)-1) { - __wasilibc_initialize_environ(); - } -} - -/// Avoid dynamic allocation for the case where there are no environment -/// variables, but we still need a non-NULL pointer to an (empty) array. -static char *empty_environ[1] = { NULL }; - -// See the comments in libc-environ.h. -void __wasilibc_initialize_environ(void) { -#ifdef __wasilibc_use_wasip2 - // Get the environment - wasip2_list_tuple2_string_string_t wasi_environment; - environment_get_environment(&wasi_environment); - - size_t environ_count = wasi_environment.len; - if (environ_count == 0) { - __wasilibc_environ = empty_environ; - return; - } - - // 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) { - goto software; - } - - // Allocate memory for the array of pointers. This uses `calloc` both to - // handle overflow and to initialize the NULL pointer at the end. - char **environ_ptrs = calloc(num_ptrs, sizeof(char *)); - - // Copy the environment variables - for (size_t i = 0; i < environ_count; i++) { - wasip2_tuple2_string_string_t pair = wasi_environment.ptr[i]; - // 1 extra character for the null terminator, 1 for the '=' character - environ_ptrs[i] = malloc(pair.f0.len + pair.f1.len + 2); - if (!environ_ptrs[i]) { - for (size_t j = 0; j < i; j++) - free(environ_ptrs[j]); - free(environ_ptrs); - goto software; - } - memcpy(environ_ptrs[i], pair.f0.ptr, pair.f0.len); - environ_ptrs[i][pair.f0.len] = '='; - memcpy(environ_ptrs[i] + pair.f0.len + 1, pair.f1.ptr, pair.f1.len); - environ_ptrs[i][pair.f0.len + pair.f1.len + 1] = '\0'; - } - - // Free the WASI environment list - wasip2_list_tuple2_string_string_free(&wasi_environment); - - // Initialize the environment from the created array - __wasilibc_environ = environ_ptrs; - return; -software: - wasip2_list_tuple2_string_string_free(&wasi_environment); - _Exit(EX_SOFTWARE); - -#else - // Get the sizes of the arrays we'll have to create to copy in the environment. - size_t environ_count; - size_t environ_buf_size; - __wasi_errno_t err = __wasi_environ_sizes_get(&environ_count, &environ_buf_size); - if (err != __WASI_ERRNO_SUCCESS) { - goto oserr; - } - if (environ_count == 0) { - __wasilibc_environ = empty_environ; - return; - } - - // 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) { - goto software; - } - - // Allocate memory for storing the environment chars. - char *environ_buf = malloc(environ_buf_size); - if (environ_buf == NULL) { - goto software; - } - - // Allocate memory for the array of pointers. This uses `calloc` both to - // handle overflow and to initialize the NULL pointer at the end. - char **environ_ptrs = calloc(num_ptrs, sizeof(char *)); - if (environ_ptrs == NULL) { - free(environ_buf); - goto software; - } - - // Fill the environment chars, and the `__wasilibc_environ` array with - // pointers into those chars. - // 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) { - free(environ_buf); - free(environ_ptrs); - goto oserr; - } - - __wasilibc_environ = environ_ptrs; - return; -oserr: - _Exit(EX_OSERR); -software: - _Exit(EX_SOFTWARE); -#endif -} - -// See the comments in libc-environ.h. -void __wasilibc_deinitialize_environ(void) { - if (__wasilibc_environ != (char **)-1) { - // Let libc-top-half clear the old environment-variable strings. - clearenv(); - // Set the pointer to the special init value. - __wasilibc_environ = (char **)-1; - } -} - -// See the comments in libc-environ.h. -weak void __wasilibc_maybe_reinitialize_environ_eagerly(void) { - // This version does nothing. It may be overridden by a version which does - // something if `environ` is used. -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_random.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_random.c deleted file mode 100644 index 8232c44e3825187f8b36bbe029eb3b65e186eed6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_random.c +++ /dev/null @@ -1,29 +0,0 @@ -#include -#include -#ifdef __wasilibc_use_wasip2 -#include -#include - -int __wasilibc_random(void *buffer, size_t len) { - - // Set up a WASI byte list to receive the results - wasip2_list_u8_t wasi_list; - - // Get random bytes - random_get_random_bytes(len, &wasi_list); - - // The spec for get-random-bytes specifies that wasi_list.len - // will be equal to len. - if (wasi_list.len != len) - _Exit(EX_OSERR); - else { - // Copy the result - memcpy(buffer, wasi_list.ptr, len); - } - - // Free the WASI byte list - wasip2_list_u8_free(&wasi_list); - - return 0; -} -#endif diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c deleted file mode 100644 index 186de01831a5f849ffff0fc7ccdfaaaa75fc0c29..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c +++ /dev/null @@ -1,671 +0,0 @@ -/** - * THIS FILE IS AUTO-GENERATED from the following files: - * wasi_snapshot_preview1.witx - * - * To regenerate this file execute: - * - * cargo run --manifest-path tools/wasi-headers/Cargo.toml generate-libc - * - * Modifications to this file will cause CI to fail, the code generator tool - * must be modified to change this file. - */ - -#include -#include - -int32_t __imported_wasi_snapshot_preview1_args_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("args_get") -)); - -__wasi_errno_t __wasi_args_get( - uint8_t * * argv, - uint8_t * argv_buf -){ - int32_t ret = __imported_wasi_snapshot_preview1_args_get((int32_t) argv, (int32_t) argv_buf); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_args_sizes_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("args_sizes_get") -)); - -__wasi_errno_t __wasi_args_sizes_get( - __wasi_size_t *retptr0, - __wasi_size_t *retptr1 -){ - int32_t ret = __imported_wasi_snapshot_preview1_args_sizes_get((int32_t) retptr0, (int32_t) retptr1); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_environ_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("environ_get") -)); - -__wasi_errno_t __wasi_environ_get( - uint8_t * * environ, - uint8_t * environ_buf -){ - int32_t ret = __imported_wasi_snapshot_preview1_environ_get((int32_t) environ, (int32_t) environ_buf); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_environ_sizes_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("environ_sizes_get") -)); - -__wasi_errno_t __wasi_environ_sizes_get( - __wasi_size_t *retptr0, - __wasi_size_t *retptr1 -){ - int32_t ret = __imported_wasi_snapshot_preview1_environ_sizes_get((int32_t) retptr0, (int32_t) retptr1); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_clock_res_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("clock_res_get") -)); - -__wasi_errno_t __wasi_clock_res_get( - __wasi_clockid_t id, - __wasi_timestamp_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_clock_res_get((int32_t) id, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_clock_time_get(int32_t arg0, int64_t arg1, int32_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("clock_time_get") -)); - -__wasi_errno_t __wasi_clock_time_get( - __wasi_clockid_t id, - __wasi_timestamp_t precision, - __wasi_timestamp_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_clock_time_get((int32_t) id, (int64_t) precision, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_advise(int32_t arg0, int64_t arg1, int64_t arg2, int32_t arg3) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_advise") -)); - -__wasi_errno_t __wasi_fd_advise( - __wasi_fd_t fd, - __wasi_filesize_t offset, - __wasi_filesize_t len, - __wasi_advice_t advice -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_advise((int32_t) fd, (int64_t) offset, (int64_t) len, (int32_t) advice); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_allocate(int32_t arg0, int64_t arg1, int64_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_allocate") -)); - -__wasi_errno_t __wasi_fd_allocate( - __wasi_fd_t fd, - __wasi_filesize_t offset, - __wasi_filesize_t len -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_allocate((int32_t) fd, (int64_t) offset, (int64_t) len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_close(int32_t arg0) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_close") -)); - -__wasi_errno_t __wasi_fd_close( - __wasi_fd_t fd -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_close((int32_t) fd); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_datasync(int32_t arg0) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_datasync") -)); - -__wasi_errno_t __wasi_fd_datasync( - __wasi_fd_t fd -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_datasync((int32_t) fd); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_fdstat_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_fdstat_get") -)); - -__wasi_errno_t __wasi_fd_fdstat_get( - __wasi_fd_t fd, - __wasi_fdstat_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_fdstat_get((int32_t) fd, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_fdstat_set_flags(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_fdstat_set_flags") -)); - -__wasi_errno_t __wasi_fd_fdstat_set_flags( - __wasi_fd_t fd, - __wasi_fdflags_t flags -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_fdstat_set_flags((int32_t) fd, flags); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_fdstat_set_rights(int32_t arg0, int64_t arg1, int64_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_fdstat_set_rights") -)); - -__wasi_errno_t __wasi_fd_fdstat_set_rights( - __wasi_fd_t fd, - __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_fdstat_set_rights((int32_t) fd, fs_rights_base, fs_rights_inheriting); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_filestat_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_filestat_get") -)); - -__wasi_errno_t __wasi_fd_filestat_get( - __wasi_fd_t fd, - __wasi_filestat_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_filestat_get((int32_t) fd, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_filestat_set_size(int32_t arg0, int64_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_filestat_set_size") -)); - -__wasi_errno_t __wasi_fd_filestat_set_size( - __wasi_fd_t fd, - __wasi_filesize_t size -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_filestat_set_size((int32_t) fd, (int64_t) size); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_filestat_set_times(int32_t arg0, int64_t arg1, int64_t arg2, int32_t arg3) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_filestat_set_times") -)); - -__wasi_errno_t __wasi_fd_filestat_set_times( - __wasi_fd_t fd, - __wasi_timestamp_t atim, - __wasi_timestamp_t mtim, - __wasi_fstflags_t fst_flags -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_filestat_set_times((int32_t) fd, (int64_t) atim, (int64_t) mtim, fst_flags); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_pread(int32_t arg0, int32_t arg1, int32_t arg2, int64_t arg3, int32_t arg4) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_pread") -)); - -__wasi_errno_t __wasi_fd_pread( - __wasi_fd_t fd, - const __wasi_iovec_t *iovs, - size_t iovs_len, - __wasi_filesize_t offset, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_pread((int32_t) fd, (int32_t) iovs, (int32_t) iovs_len, (int64_t) offset, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_prestat_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_prestat_get") -)); - -__wasi_errno_t __wasi_fd_prestat_get( - __wasi_fd_t fd, - __wasi_prestat_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_prestat_get((int32_t) fd, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_prestat_dir_name(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_prestat_dir_name") -)); - -__wasi_errno_t __wasi_fd_prestat_dir_name( - __wasi_fd_t fd, - uint8_t * path, - __wasi_size_t path_len -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_prestat_dir_name((int32_t) fd, (int32_t) path, (int32_t) path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_pwrite(int32_t arg0, int32_t arg1, int32_t arg2, int64_t arg3, int32_t arg4) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_pwrite") -)); - -__wasi_errno_t __wasi_fd_pwrite( - __wasi_fd_t fd, - const __wasi_ciovec_t *iovs, - size_t iovs_len, - __wasi_filesize_t offset, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_pwrite((int32_t) fd, (int32_t) iovs, (int32_t) iovs_len, (int64_t) offset, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_read(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_read") -)); - -__wasi_errno_t __wasi_fd_read( - __wasi_fd_t fd, - const __wasi_iovec_t *iovs, - size_t iovs_len, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_read((int32_t) fd, (int32_t) iovs, (int32_t) iovs_len, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_readdir(int32_t arg0, int32_t arg1, int32_t arg2, int64_t arg3, int32_t arg4) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_readdir") -)); - -__wasi_errno_t __wasi_fd_readdir( - __wasi_fd_t fd, - uint8_t * buf, - __wasi_size_t buf_len, - __wasi_dircookie_t cookie, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_readdir((int32_t) fd, (int32_t) buf, (int32_t) buf_len, (int64_t) cookie, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_renumber(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_renumber") -)); - -__wasi_errno_t __wasi_fd_renumber( - __wasi_fd_t fd, - __wasi_fd_t to -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_renumber((int32_t) fd, (int32_t) to); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_seek(int32_t arg0, int64_t arg1, int32_t arg2, int32_t arg3) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_seek") -)); - -__wasi_errno_t __wasi_fd_seek( - __wasi_fd_t fd, - __wasi_filedelta_t offset, - __wasi_whence_t whence, - __wasi_filesize_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_seek((int32_t) fd, offset, (int32_t) whence, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_sync(int32_t arg0) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_sync") -)); - -__wasi_errno_t __wasi_fd_sync( - __wasi_fd_t fd -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_sync((int32_t) fd); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_tell(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_tell") -)); - -__wasi_errno_t __wasi_fd_tell( - __wasi_fd_t fd, - __wasi_filesize_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_tell((int32_t) fd, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_fd_write(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("fd_write") -)); - -__wasi_errno_t __wasi_fd_write( - __wasi_fd_t fd, - const __wasi_ciovec_t *iovs, - size_t iovs_len, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_fd_write((int32_t) fd, (int32_t) iovs, (int32_t) iovs_len, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_create_directory(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_create_directory") -)); - -__wasi_errno_t __wasi_path_create_directory( - __wasi_fd_t fd, - const char *path -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_create_directory((int32_t) fd, (int32_t) path, (int32_t) path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_filestat_get(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_filestat_get") -)); - -__wasi_errno_t __wasi_path_filestat_get( - __wasi_fd_t fd, - __wasi_lookupflags_t flags, - const char *path, - __wasi_filestat_t *retptr0 -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_filestat_get((int32_t) fd, flags, (int32_t) path, (int32_t) path_len, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_filestat_set_times(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int64_t arg4, int64_t arg5, int32_t arg6) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_filestat_set_times") -)); - -__wasi_errno_t __wasi_path_filestat_set_times( - __wasi_fd_t fd, - __wasi_lookupflags_t flags, - const char *path, - __wasi_timestamp_t atim, - __wasi_timestamp_t mtim, - __wasi_fstflags_t fst_flags -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_filestat_set_times((int32_t) fd, flags, (int32_t) path, (int32_t) path_len, (int64_t) atim, (int64_t) mtim, fst_flags); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_link(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int32_t arg5, int32_t arg6) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_link") -)); - -__wasi_errno_t __wasi_path_link( - __wasi_fd_t old_fd, - __wasi_lookupflags_t old_flags, - const char *old_path, - __wasi_fd_t new_fd, - const char *new_path -){ - size_t old_path_len = strlen(old_path); - size_t new_path_len = strlen(new_path); - int32_t ret = __imported_wasi_snapshot_preview1_path_link((int32_t) old_fd, old_flags, (int32_t) old_path, (int32_t) old_path_len, (int32_t) new_fd, (int32_t) new_path, (int32_t) new_path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_open(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int64_t arg5, int64_t arg6, int32_t arg7, int32_t arg8) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_open") -)); - -__wasi_errno_t __wasi_path_open( - __wasi_fd_t fd, - __wasi_lookupflags_t dirflags, - const char *path, - __wasi_oflags_t oflags, - __wasi_rights_t fs_rights_base, - __wasi_rights_t fs_rights_inheriting, - __wasi_fdflags_t fdflags, - __wasi_fd_t *retptr0 -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_open((int32_t) fd, dirflags, (int32_t) path, (int32_t) path_len, oflags, fs_rights_base, fs_rights_inheriting, fdflags, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_readlink(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int32_t arg5) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_readlink") -)); - -__wasi_errno_t __wasi_path_readlink( - __wasi_fd_t fd, - const char *path, - uint8_t * buf, - __wasi_size_t buf_len, - __wasi_size_t *retptr0 -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_readlink((int32_t) fd, (int32_t) path, (int32_t) path_len, (int32_t) buf, (int32_t) buf_len, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_remove_directory(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_remove_directory") -)); - -__wasi_errno_t __wasi_path_remove_directory( - __wasi_fd_t fd, - const char *path -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_remove_directory((int32_t) fd, (int32_t) path, (int32_t) path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_rename(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int32_t arg5) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_rename") -)); - -__wasi_errno_t __wasi_path_rename( - __wasi_fd_t fd, - const char *old_path, - __wasi_fd_t new_fd, - const char *new_path -){ - size_t old_path_len = strlen(old_path); - size_t new_path_len = strlen(new_path); - int32_t ret = __imported_wasi_snapshot_preview1_path_rename((int32_t) fd, (int32_t) old_path, (int32_t) old_path_len, (int32_t) new_fd, (int32_t) new_path, (int32_t) new_path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_symlink(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_symlink") -)); - -__wasi_errno_t __wasi_path_symlink( - const char *old_path, - __wasi_fd_t fd, - const char *new_path -){ - size_t old_path_len = strlen(old_path); - size_t new_path_len = strlen(new_path); - int32_t ret = __imported_wasi_snapshot_preview1_path_symlink((int32_t) old_path, (int32_t) old_path_len, (int32_t) fd, (int32_t) new_path, (int32_t) new_path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_path_unlink_file(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("path_unlink_file") -)); - -__wasi_errno_t __wasi_path_unlink_file( - __wasi_fd_t fd, - const char *path -){ - size_t path_len = strlen(path); - int32_t ret = __imported_wasi_snapshot_preview1_path_unlink_file((int32_t) fd, (int32_t) path, (int32_t) path_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_poll_oneoff(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("poll_oneoff") -)); - -__wasi_errno_t __wasi_poll_oneoff( - const __wasi_subscription_t * in, - __wasi_event_t * out, - __wasi_size_t nsubscriptions, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_poll_oneoff((int32_t) in, (int32_t) out, (int32_t) nsubscriptions, (int32_t) retptr0); - return (uint16_t) ret; -} - -_Noreturn void __imported_wasi_snapshot_preview1_proc_exit(int32_t arg0) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("proc_exit") -)); - -_Noreturn void __wasi_proc_exit( - __wasi_exitcode_t rval -){ - __imported_wasi_snapshot_preview1_proc_exit((int32_t) rval); -} - -int32_t __imported_wasi_snapshot_preview1_sched_yield() __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("sched_yield") -)); - -__wasi_errno_t __wasi_sched_yield( - void -){ - int32_t ret = __imported_wasi_snapshot_preview1_sched_yield(); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_random_get(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("random_get") -)); - -__wasi_errno_t __wasi_random_get( - uint8_t * buf, - __wasi_size_t buf_len -){ - int32_t ret = __imported_wasi_snapshot_preview1_random_get((int32_t) buf, (int32_t) buf_len); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_sock_accept(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("sock_accept") -)); - -__wasi_errno_t __wasi_sock_accept( - __wasi_fd_t fd, - __wasi_fdflags_t flags, - __wasi_fd_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_sock_accept((int32_t) fd, flags, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_sock_recv(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4, int32_t arg5) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("sock_recv") -)); - -__wasi_errno_t __wasi_sock_recv( - __wasi_fd_t fd, - const __wasi_iovec_t *ri_data, - size_t ri_data_len, - __wasi_riflags_t ri_flags, - __wasi_size_t *retptr0, - __wasi_roflags_t *retptr1 -){ - int32_t ret = __imported_wasi_snapshot_preview1_sock_recv((int32_t) fd, (int32_t) ri_data, (int32_t) ri_data_len, ri_flags, (int32_t) retptr0, (int32_t) retptr1); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_sock_send(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("sock_send") -)); - -__wasi_errno_t __wasi_sock_send( - __wasi_fd_t fd, - const __wasi_ciovec_t *si_data, - size_t si_data_len, - __wasi_siflags_t si_flags, - __wasi_size_t *retptr0 -){ - int32_t ret = __imported_wasi_snapshot_preview1_sock_send((int32_t) fd, (int32_t) si_data, (int32_t) si_data_len, (int32_t) si_flags, (int32_t) retptr0); - return (uint16_t) ret; -} - -int32_t __imported_wasi_snapshot_preview1_sock_shutdown(int32_t arg0, int32_t arg1) __attribute__(( - __import_module__("wasi_snapshot_preview1"), - __import_name__("sock_shutdown") -)); - -__wasi_errno_t __wasi_sock_shutdown( - __wasi_fd_t fd, - __wasi_sdflags_t how -){ - int32_t ret = __imported_wasi_snapshot_preview1_sock_shutdown((int32_t) fd, how); - return (uint16_t) ret; -} - -#ifdef _REENTRANT -int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__(( - __import_module__("wasi"), - __import_name__("thread-spawn") -)); - -int32_t __wasi_thread_spawn(void* start_arg) { - return __imported_wasi_thread_spawn((int32_t) start_arg); -} -#endif diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c deleted file mode 100644 index b2b906aa68c802f6769e6bf27e0608371c95dd37..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -int __wasilibc_nocwd___wasilibc_rmdirat(int fd, const char *path) { - __wasi_errno_t error = __wasi_path_remove_directory(fd, path); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_tell.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_tell.c deleted file mode 100644 index 358d0ca375af7cebde3083baaf62201f239cf274..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_tell.c +++ /dev/null @@ -1,14 +0,0 @@ -#include -#include - -off_t __wasilibc_tell(int fildes) { - __wasi_filesize_t offset; - __wasi_errno_t error = __wasi_fd_tell(fildes, &offset); - if (error != 0) { - // lseek returns ESPIPE on when called on a pipe, socket, or fifo, - // which on WASI would translate into ENOTCAPABLE. - errno = error == ENOTCAPABLE ? ESPIPE : error; - return -1; - } - return offset; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c b/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c deleted file mode 100644 index 8b4f6b5ceaf0c92c44fdf3a31193d0ceb12f42c6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include -#include - -int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) { - __wasi_errno_t error = __wasi_path_unlink_file(fd, path); - if (error != 0) { - errno = error; - return -1; - } - return 0; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/abort.c b/lib/libc/wasi/libc-bottom-half/sources/abort.c deleted file mode 100644 index 95fe2be045bc6d6de9d44d311cc34fd74f48bb27..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/abort.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -void abort(void) { - // wasm doesn't support signals, so just trap to halt the program. - __builtin_trap(); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/accept-wasip1.c b/lib/libc/wasi/libc-bottom-half/sources/accept-wasip1.c deleted file mode 100644 index 902e7316f5812220266957583e403aa97843fcf7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/accept-wasip1.c +++ /dev/null @@ -1,51 +0,0 @@ -// SPDX-License-Identifier: BSD-2-Clause - -#include - -#include -#include -#include -#include - -int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) { - int ret = -1; - - __wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret); - - if (error != 0) { - errno = error; - return -1; - } - - // Clear sockaddr to indicate undefined address - memset(addr, 0, *addrlen); - // might be AF_UNIX or AF_INET - addr->sa_family = AF_UNSPEC; - *addrlen = sizeof(struct sockaddr); - - return ret; -} - -int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) { - int ret = -1; - - if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) { - errno = EINVAL; - return -1; - } - - __wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret); - - if (error != 0) { - errno = error; - return -1; - } - - // Clear sockaddr to indicate undefined address - memset(addr, 0, *addrlen); - // might be AF_UNIX or AF_INET - addr->sa_family = AF_UNSPEC; - *addrlen = sizeof(struct sockaddr); - - return ret; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/at_fdcwd.c b/lib/libc/wasi/libc-bottom-half/sources/at_fdcwd.c deleted file mode 100644 index c83797ddc9135c724ef8bf3ab8130e414a8df5f4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/at_fdcwd.c +++ /dev/null @@ -1,141 +0,0 @@ -// Handle AT_FDCWD and absolute paths for the *at functions. -// -// In the case of an AT_FDCWD file descriptor or an absolute path, call the -// corresponding non-`at` function. This will send it through the libpreopen -// wrappers to convert the path into a directory file descriptor and relative -// path before translating it into the corresponding `__wasilibc_nocwd_*at` -// function, which then calls the appropriate WASI function. - -#include -#include -#include -#include -#include -#include -#include -#include - -// If the platform doesn't define O_TMPFILE, we don't need to worry about it. -#ifndef O_TMPFILE -#define O_TMPFILE 0 -#endif - -int openat(int dirfd, const char *pathname, int flags, ...) { - if (dirfd == AT_FDCWD || pathname[0] == '/') { - return open(pathname, flags); - } - - return __wasilibc_nocwd_openat_nomode(dirfd, pathname, flags); -} - -int symlinkat(const char *target, int dirfd, const char *linkpath) { - if (dirfd == AT_FDCWD || linkpath[0] == '/') { - return symlink(target, linkpath); - } - - return __wasilibc_nocwd_symlinkat(target, dirfd, linkpath); -} - -ssize_t readlinkat(int dirfd, const char *__restrict pathname, char *__restrict buf, size_t bufsiz) { - if (dirfd == AT_FDCWD || pathname[0] == '/') { - return readlink(pathname, buf, bufsiz); - } - - return __wasilibc_nocwd_readlinkat(dirfd, pathname, buf, bufsiz); -} - -int mkdirat(int dirfd, const char *pathname, mode_t mode) { - if (dirfd == AT_FDCWD || pathname[0] == '/') { - return mkdir(pathname, mode); - } - - return __wasilibc_nocwd_mkdirat_nomode(dirfd, pathname); -} - -DIR *opendirat(int dirfd, const char *path) { - if (dirfd == AT_FDCWD || path[0] == '/') { - return opendir(path); - } - - return __wasilibc_nocwd_opendirat(dirfd, path); -} - -int scandirat(int dirfd, const char *dirp, struct dirent ***namelist, - int (*filter)(const struct dirent *), - int (*compar)(const struct dirent **, const struct dirent **)) { - if (dirfd == AT_FDCWD || dirp[0] == '/') { - return scandir(dirp, namelist, filter, compar); - } - - return __wasilibc_nocwd_scandirat(dirfd, dirp, namelist, filter, compar); -} - -int faccessat(int dirfd, const char *pathname, int mode, int flags) { - if (dirfd == AT_FDCWD || pathname[0] == '/') { - return __wasilibc_access(pathname, mode, flags); - } - - return __wasilibc_nocwd_faccessat(dirfd, pathname, mode, flags); -} - -int fstatat(int dirfd, const char *__restrict pathname, struct stat *__restrict statbuf, int flags) { - if (dirfd == AT_FDCWD || pathname[0] == '/') { - return __wasilibc_stat(pathname, statbuf, flags); - } - - return __wasilibc_nocwd_fstatat(dirfd, pathname, statbuf, flags); -} - -int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) { - if (dirfd == AT_FDCWD || pathname[0] == '/') { - return __wasilibc_utimens(pathname, times, flags); - } - - return __wasilibc_nocwd_utimensat(dirfd, pathname, times, flags); -} - -int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags) { - if ((olddirfd == AT_FDCWD || oldpath[0] == '/') && - (newdirfd == AT_FDCWD || newpath[0] == '/')) { - return __wasilibc_link(oldpath, newpath, flags); - } - if (olddirfd == AT_FDCWD || oldpath[0] == '/') { - return __wasilibc_link_newat(oldpath, newdirfd, newpath, flags); - } - if (newdirfd == AT_FDCWD || newpath[0] == '/') { - return __wasilibc_link_oldat(olddirfd, oldpath, newpath, flags); - } - - return __wasilibc_nocwd_linkat(olddirfd, oldpath, newdirfd, newpath, flags); -} - -int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { - if ((olddirfd == AT_FDCWD || oldpath[0] == '/') && - (newdirfd == AT_FDCWD || newpath[0] == '/')) { - return rename(oldpath, newpath); - } - if (olddirfd == AT_FDCWD || oldpath[0] == '/') { - return __wasilibc_rename_newat(oldpath, newdirfd, newpath); - } - if (newdirfd == AT_FDCWD || newpath[0] == '/') { - return __wasilibc_rename_oldat(olddirfd, oldpath, newpath); - } - - return __wasilibc_nocwd_renameat(olddirfd, oldpath, newdirfd, newpath); -} - -int __wasilibc_unlinkat(int dirfd, const char *path) { - if (dirfd == AT_FDCWD || path[0] == '/') { - return unlink(path); - } - - return __wasilibc_nocwd___wasilibc_unlinkat(dirfd, path); -} - -int __wasilibc_rmdirat(int dirfd, const char *path) { - if (dirfd == AT_FDCWD || path[0] == '/') { - return rmdir(path); - } - - return __wasilibc_nocwd___wasilibc_rmdirat(dirfd, path); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/chdir.c b/lib/libc/wasi/libc-bottom-half/sources/chdir.c deleted file mode 100644 index 37c95a4e56e1c8da7fa511f090a9d6e94dca0113..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/chdir.c +++ /dev/null @@ -1,171 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _REENTRANT -void __wasilibc_cwd_lock(void); -void __wasilibc_cwd_unlock(void); -#else -#define __wasilibc_cwd_lock() (void)0 -#define __wasilibc_cwd_unlock() (void)0 -#endif -extern char *__wasilibc_cwd; -static int __wasilibc_cwd_mallocd = 0; - -int chdir(const char *path) -{ - static char *relative_buf = NULL; - static size_t relative_buf_len = 0; - - // Find a preopen'd directory as well as a relative path we're anchored - // from which we're changing directories to. - const char *abs; - int parent_fd = __wasilibc_find_relpath_alloc(path, &abs, &relative_buf, &relative_buf_len, 1); - if (parent_fd == -1) - return -1; - - // Make sure that this directory we're accessing is indeed a directory. - struct stat dirinfo; - int ret = fstatat(parent_fd, relative_buf, &dirinfo, 0); - if (ret == -1) - return -1; - if (!S_ISDIR(dirinfo.st_mode)) { - errno = ENOTDIR; - return -1; - } - - // Create a string that looks like: - // - // __wasilibc_cwd = "/" + abs + "/" + relative_buf - // - // If `relative_buf` is equal to "." or `abs` is equal to the empty string, - // however, we skip that part and the middle slash. - size_t abs_len = strlen(abs); - int copy_relative = strcmp(relative_buf, ".") != 0; - int mid = copy_relative && abs[0] != 0; - char *new_cwd = malloc(1 + abs_len + mid + (copy_relative ? strlen(relative_buf) : 0) + 1); - if (new_cwd == NULL) { - errno = ENOMEM; - return -1; - } - new_cwd[0] = '/'; - strcpy(new_cwd + 1, abs); - if (mid) - new_cwd[1 + abs_len] = '/'; - if (copy_relative) - strcpy(new_cwd + 1 + abs_len + mid, relative_buf); - - // And set our new malloc'd buffer into the global cwd, freeing the - // previous one if necessary. - __wasilibc_cwd_lock(); - char *prev_cwd = __wasilibc_cwd; - __wasilibc_cwd = new_cwd; - __wasilibc_cwd_unlock(); - if (__wasilibc_cwd_mallocd) - free(prev_cwd); - __wasilibc_cwd_mallocd = 1; - return 0; -} - -static const char *make_absolute(const char *path) { - static char *make_absolute_buf = NULL; - static size_t make_absolute_len = 0; - - // If this path is absolute, then we return it as-is. - if (path[0] == '/') { - return path; - } - -#ifndef _REENTRANT - // If the path is empty, or points to the current directory, then return - // the current directory. - if (path[0] == 0 || !strcmp(path, ".") || !strcmp(path, "./")) { - return __wasilibc_cwd; - } -#endif - - // If the path starts with `./` then we won't be appending that to the cwd. - if (path[0] == '.' && path[1] == '/') - path += 2; - - // Otherwise we'll take the current directory, add a `/`, and then add the - // input `path`. Note that this doesn't do any normalization (like removing - // `/./`). - __wasilibc_cwd_lock(); - size_t cwd_len = strlen(__wasilibc_cwd); - size_t path_len = path ? strlen(path) : 0; - __wasilibc_cwd_unlock(); - int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1; - size_t alloc_len = cwd_len + path_len + 1 + need_slash; - if (alloc_len > make_absolute_len) { - char *tmp = realloc(make_absolute_buf, alloc_len); - if (tmp == NULL) { - __wasilibc_cwd_unlock(); - return NULL; - } - make_absolute_buf = tmp; - make_absolute_len = alloc_len; - } - strcpy(make_absolute_buf, __wasilibc_cwd); - __wasilibc_cwd_unlock(); - -#ifdef _REENTRANT - if (path[0] == 0 || !strcmp(path, ".") || !strcmp(path, "./")) { - return make_absolute_buf; - } -#endif - - if (need_slash) - strcpy(make_absolute_buf + cwd_len, "/"); - strcpy(make_absolute_buf + cwd_len + need_slash, path); - return make_absolute_buf; -} - -// Helper function defined only in this object file and weakly referenced from -// `preopens.c` and `posix.c` This function isn't necessary unless `chdir` is -// pulled in because all paths are otherwise absolute or relative to the root. -int __wasilibc_find_relpath_alloc( - const char *path, - const char **abs_prefix, - char **relative_buf, - size_t *relative_buf_len, - int can_realloc -) { - // First, make our path absolute taking the cwd into account. - const char *abspath = make_absolute(path); - if (abspath == NULL) { - errno = ENOMEM; - return -1; - } - - // Next use our absolute path and split it. Find the preopened `fd` parent - // directory and set `abs_prefix`. Next up we'll be trying to fit `rel` - // into `relative_buf`. - const char *rel; - int fd = __wasilibc_find_abspath(abspath, abs_prefix, &rel); - if (fd == -1) - return -1; - - size_t rel_len = strlen(rel); - if (*relative_buf_len < rel_len + 1) { - if (!can_realloc) { - errno = ERANGE; - return -1; - } - char *tmp = realloc(*relative_buf, rel_len + 1); - if (tmp == NULL) { - errno = ENOMEM; - return -1; - } - *relative_buf = tmp; - *relative_buf_len = rel_len + 1; - } - strcpy(*relative_buf, rel); - return fd; -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/complex-builtins.c b/lib/libc/wasi/libc-bottom-half/sources/complex-builtins.c deleted file mode 100644 index 971d57e19b91ca87ee379ebb0091d51848be3f49..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/complex-builtins.c +++ /dev/null @@ -1,29 +0,0 @@ -// Each of the following complex functions can be implemented with a single -// wasm instruction, so use that implementation rather than the portable -// one in libm. - -#include - -float (crealf)(float _Complex x) { - return __builtin_crealf(x); -} - -double (creal)(double _Complex x) { - return __builtin_creal(x); -} - -long double (creall)(long double _Complex x) { - return __builtin_creall(x); -} - -float (cimagf)(float _Complex x) { - return __builtin_cimagf(x); -} - -double (cimag)(double _Complex x) { - return __builtin_cimag(x); -} - -long double (cimagl)(long double _Complex x) { - return __builtin_cimagl(x); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/environ.c b/lib/libc/wasi/libc-bottom-half/sources/environ.c deleted file mode 100644 index 50d60deff407fcf929303933ac95daef3783bb00..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/environ.c +++ /dev/null @@ -1,31 +0,0 @@ -#include -#include -#include -#include -#include -#include - -// If the program does use `environ`, it'll get this version of -// `__wasilibc_environ`, which is initialized with a constructor function, so -// that it's initialized whenever user code might want to access it. -char **__wasilibc_environ; -weak_alias(__wasilibc_environ, _environ); -weak_alias(__wasilibc_environ, environ); - -// We define this function here in the same source file as -// `__wasilibc_environ`, so that this function is called in iff environment -// variable support is used. -// Concerning the 50 -- levels up to 100 are reserved for the implementation, -// so we an arbitrary number in the middle of the range to allow other -// reserved things to go before or after. -__attribute__((constructor(50))) -static void __wasilibc_initialize_environ_eagerly(void) { - __wasilibc_initialize_environ(); -} - -// See the comments in libc-environ.h. -void __wasilibc_maybe_reinitialize_environ_eagerly(void) { - // This translation unit is linked in if `environ` is used, meaning we need - // to eagerly reinitialize the environment variables. - __wasilibc_initialize_environ(); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/errno.c b/lib/libc/wasi/libc-bottom-half/sources/errno.c deleted file mode 100644 index 4e98a5b84db8ad74507c4c0a74f820bba6acf755..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/errno.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -// These values are used by reference-sysroot's dlmalloc. -const int __EINVAL = EINVAL; -const int __ENOMEM = ENOMEM; diff --git a/lib/libc/wasi/libc-bottom-half/sources/getcwd.c b/lib/libc/wasi/libc-bottom-half/sources/getcwd.c deleted file mode 100644 index 3b1ce706940470717f16be45465b4b2838999f39..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/getcwd.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include -#include "lock.h" - -char *__wasilibc_cwd = "/"; - -#ifdef _REENTRANT -static volatile int lock[1]; -void __wasilibc_cwd_lock(void) { LOCK(lock); } -void __wasilibc_cwd_unlock(void) { UNLOCK(lock); } -#else -#define __wasilibc_cwd_lock() (void)0 -#define __wasilibc_cwd_unlock() (void)0 -#endif - -char *getcwd(char *buf, size_t size) -{ - __wasilibc_cwd_lock(); - if (!buf) { - buf = strdup(__wasilibc_cwd); - if (!buf) { - errno = ENOMEM; - __wasilibc_cwd_unlock(); - return NULL; - } - } else { - size_t len = strlen(__wasilibc_cwd); - if (size < len + 1) { - errno = ERANGE; - __wasilibc_cwd_unlock(); - return NULL; - } - strcpy(buf, __wasilibc_cwd); - } - __wasilibc_cwd_unlock(); - return buf; -} - diff --git a/lib/libc/wasi/libc-bottom-half/sources/getentropy.c b/lib/libc/wasi/libc-bottom-half/sources/getentropy.c deleted file mode 100644 index 3d6ff05c79d76ec2202d0cecb84e194e524b9448..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/getentropy.c +++ /dev/null @@ -1,26 +0,0 @@ -#include -#include -#ifdef __wasilibc_use_wasip2 -#include -#else -#include -#endif - -int __getentropy(void *buffer, size_t len) { - if (len > 256) { - errno = EIO; - return -1; - } - -#ifdef __wasilibc_use_wasip2 - int r = __wasilibc_random(buffer, len); -#else - int r = __wasi_random_get(buffer, len); -#endif - if (r != 0) { - errno = r; - return -1; - } - return 0; -} -weak_alias(__getentropy, getentropy); diff --git a/lib/libc/wasi/libc-bottom-half/sources/isatty.c b/lib/libc/wasi/libc-bottom-half/sources/isatty.c deleted file mode 100644 index c6f8662816a009d0f7e8a8b6a88627fb435b1aaa..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/isatty.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include <__errno.h> -#include <__function___isatty.h> - -int __isatty(int fd) { - __wasi_fdstat_t statbuf; - int r = __wasi_fd_fdstat_get(fd, &statbuf); - if (r != 0) { - errno = r; - return 0; - } - - // 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_RIGHTS_FD_SEEK | __WASI_RIGHTS_FD_TELL)) != 0) { - errno = __WASI_ERRNO_NOTTY; - return 0; - } - - return 1; -} -extern __typeof(__isatty) isatty __attribute__((weak, alias("__isatty"))); diff --git a/lib/libc/wasi/libc-bottom-half/sources/math/math-builtins.c b/lib/libc/wasi/libc-bottom-half/sources/math/math-builtins.c deleted file mode 100644 index a5eb7cd494d0fffc4eeb2eabb3e44246caea88b3..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/math/math-builtins.c +++ /dev/null @@ -1,69 +0,0 @@ -// Each of the following math functions can be implemented with a single -// wasm instruction, so use that implementation rather than the portable -// one in libm. - -#include - -float fabsf(float x) { - return __builtin_fabsf(x); -} - -double fabs(double x) { - return __builtin_fabs(x); -} - -float sqrtf(float x) { - return __builtin_sqrtf(x); -} - -double sqrt(double x) { - return __builtin_sqrt(x); -} - -float copysignf(float x, float y) { - return __builtin_copysignf(x, y); -} - -double copysign(double x, double y) { - return __builtin_copysign(x, y); -} - -float ceilf(float x) { - return __builtin_ceilf(x); -} - -double ceil(double x) { - return __builtin_ceil(x); -} - -float floorf(float x) { - return __builtin_floorf(x); -} - -double floor(double x) { - return __builtin_floor(x); -} - -float truncf(float x) { - return __builtin_truncf(x); -} - -double trunc(double x) { - return __builtin_trunc(x); -} - -float nearbyintf(float x) { - return __builtin_nearbyintf(x); -} - -double nearbyint(double x) { - return __builtin_nearbyint(x); -} - -float rintf(float x) { - return __builtin_rintf(x); -} - -double rint(double x) { - return __builtin_rint(x); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/posix.c b/lib/libc/wasi/libc-bottom-half/sources/posix.c deleted file mode 100644 index 7da6a3df681392e0376455a15ab1b9d64aaf6310..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/posix.c +++ /dev/null @@ -1,490 +0,0 @@ -//! POSIX-like functions supporting absolute path arguments, implemented in -//! terms of `__wasilibc_find_relpath` and `*at`-style functions. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -static int find_relpath2( - const char *path, - char **relative, - size_t *relative_len -) { - // See comments in `preopens.c` for what this trick is doing. - const char *abs; - if (__wasilibc_find_relpath_alloc) - return __wasilibc_find_relpath_alloc(path, &abs, relative, relative_len, 1); - return __wasilibc_find_relpath(path, &abs, relative, *relative_len); -} - -// Helper to call `__wasilibc_find_relpath` and return an already-managed -// pointer for the `relative` path. This function is not reentrant since the -// `relative` pointer will point to static data that cannot be reused until -// `relative` is no longer used. -static int find_relpath(const char *path, char **relative) { - static __thread char *relative_buf = NULL; - static __thread size_t relative_buf_len = 0; - int fd = find_relpath2(path, &relative_buf, &relative_buf_len); - // find_relpath2 can update relative_buf, so assign it after the call - *relative = relative_buf; - return fd; -} - -// same as `find_relpath`, but uses another set of static variables to cache -static int find_relpath_alt(const char *path, char **relative) { - static __thread char *relative_buf = NULL; - static __thread size_t relative_buf_len = 0; - int fd = find_relpath2(path, &relative_buf, &relative_buf_len); - // find_relpath2 can update relative_buf, so assign it after the call - *relative = relative_buf; - return fd; -} - -int open(const char *path, int oflag, ...) { - // WASI libc's `openat` ignores the mode argument, so call a special - // entrypoint which avoids the varargs calling convention. - return __wasilibc_open_nomode(path, oflag); -} - -// See the documentation in libc.h -int __wasilibc_open_nomode(const char *path, int oflag) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_openat_nomode(dirfd, relative_path, oflag); -} - -int access(const char *path, int amode) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_faccessat(dirfd, relative_path, amode, 0); -} - -ssize_t readlink( - const char *restrict path, - char *restrict buf, - size_t bufsize) -{ - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_readlinkat(dirfd, relative_path, buf, bufsize); -} - -int stat(const char *restrict path, struct stat *restrict buf) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_fstatat(dirfd, relative_path, buf, 0); -} - -int lstat(const char *restrict path, struct stat *restrict buf) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_fstatat(dirfd, relative_path, buf, AT_SYMLINK_NOFOLLOW); -} - -int utime(const char *path, const struct utimbuf *times) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_utimensat( - dirfd, relative_path, - times ? ((struct timespec [2]) { - { .tv_sec = times->actime }, - { .tv_sec = times->modtime } - }) - : NULL, - 0); -} - -int utimes(const char *path, const struct timeval times[2]) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_utimensat( - dirfd, relative_path, - times ? ((struct timespec [2]) { - { .tv_sec = times[0].tv_sec, - .tv_nsec = times[0].tv_usec * 1000 }, - { .tv_sec = times[1].tv_sec, - .tv_nsec = times[1].tv_usec * 1000 }, - }) - : NULL, - 0); -} - -int unlink(const char *path) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - // `unlinkat` imports `__wasi_path_remove_directory` even when - // `AT_REMOVEDIR` isn't passed. Instead, use a specialized function which - // just imports `__wasi_path_unlink_file`. - return __wasilibc_nocwd___wasilibc_unlinkat(dirfd, relative_path); -} - -int rmdir(const char *path) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd___wasilibc_rmdirat(dirfd, relative_path); -} - -int remove(const char *path) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - // First try to remove it as a file. - int r = __wasilibc_nocwd___wasilibc_unlinkat(dirfd, relative_path); - if (r != 0 && (errno == EISDIR || errno == ENOENT)) { - // That failed, but it might be a directory. - r = __wasilibc_nocwd___wasilibc_rmdirat(dirfd, relative_path); - - // If it isn't a directory, we lack capabilities to remove it as a file. - if (errno == ENOTDIR) - errno = ENOENT; - } - return r; -} - -int mkdir(const char *path, mode_t mode) { - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_mkdirat_nomode(dirfd, relative_path); -} - -DIR *opendir(const char *dirname) { - char *relative_path; - int dirfd = find_relpath(dirname, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return NULL; - } - - return __wasilibc_nocwd_opendirat(dirfd, relative_path); -} - -int scandir( - const char *restrict dir, - struct dirent ***restrict namelist, - int (*filter)(const struct dirent *), - int (*compar)(const struct dirent **, const struct dirent **) -) { - char *relative_path; - int dirfd = find_relpath(dir, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_scandirat(dirfd, relative_path, namelist, filter, compar); -} - -int symlink(const char *target, const char *linkpath) { - char *relative_path; - int dirfd = find_relpath(linkpath, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_symlinkat(target, dirfd, relative_path); -} - -int link(const char *old, const char *new) { - char *old_relative_path; - int old_dirfd = find_relpath_alt(old, &old_relative_path); - - if (old_dirfd != -1) { - char *new_relative_path; - int new_dirfd = find_relpath(new, &new_relative_path); - - if (new_dirfd != -1) - return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, - new_dirfd, new_relative_path, 0); - } - - // We couldn't find a preopen for it; fail as if we can't find the path. - errno = ENOENT; - return -1; -} - -int rename(const char *old, const char *new) { - char *old_relative_path; - int old_dirfd = find_relpath_alt(old, &old_relative_path); - - if (old_dirfd != -1) { - char *new_relative_path; - int new_dirfd = find_relpath(new, &new_relative_path); - - if (new_dirfd != -1) - return __wasilibc_nocwd_renameat(old_dirfd, old_relative_path, - new_dirfd, new_relative_path); - } - - // We couldn't find a preopen for it; fail as if we can't find the path. - errno = ENOENT; - return -1; -} - -int chmod(const char *path, mode_t mode) { - // TODO: We plan to support this eventually in WASI, but not yet. - // Meanwhile, we provide a stub so that libc++'s `` - // implementation will build unmodified. - errno = ENOSYS; - return -1; -} - -int fchmod(int fd, mode_t mode) { - // TODO: We plan to support this eventually in WASI, but not yet. - // Meanwhile, we provide a stub so that libc++'s `` - // implementation will build unmodified. - errno = ENOSYS; - return -1; -} - -int fchmodat(int fd, const char *path, mode_t mode, int flag) { - // TODO: We plan to support this eventually in WASI, but not yet. - // Meanwhile, we provide a stub so that libc++'s `` - // implementation will build unmodified. - errno = ENOSYS; - return -1; -} - -int statvfs(const char *__restrict path, struct statvfs *__restrict buf) { - // TODO: We plan to support this eventually in WASI, but not yet. - // Meanwhile, we provide a stub so that libc++'s `` - // implementation will build unmodified. - errno = ENOSYS; - return -1; -} - -int fstatvfs(int fd, struct statvfs *buf) { - // TODO: We plan to support this eventually in WASI, but not yet. - // Meanwhile, we provide a stub so that libc++'s `` - // implementation will build unmodified. - errno = ENOSYS; - return -1; -} - -// Like `access`, but with `faccessat`'s flags argument. -int -__wasilibc_access(const char *path, int mode, int flags) -{ - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_faccessat(dirfd, relative_path, - mode, flags); -} - -// Like `utimensat`, but without the `at` part. -int -__wasilibc_utimens(const char *path, const struct timespec times[2], int flags) -{ - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_utimensat(dirfd, relative_path, - times, flags); -} - -// Like `stat`, but with `fstatat`'s flags argument. -int -__wasilibc_stat(const char *__restrict path, struct stat *__restrict st, int flags) -{ - char *relative_path; - int dirfd = find_relpath(path, &relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_fstatat(dirfd, relative_path, st, flags); -} - -// Like `link`, but with `linkat`'s flags argument. -int -__wasilibc_link(const char *oldpath, const char *newpath, int flags) -{ - char *old_relative_path; - char *new_relative_path; - int old_dirfd = find_relpath(oldpath, &old_relative_path); - int new_dirfd = find_relpath(newpath, &new_relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (old_dirfd == -1 || new_dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, - new_dirfd, new_relative_path, - flags); -} - -// Like `__wasilibc_link`, but oldpath is relative to olddirfd. -int -__wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags) -{ - char *new_relative_path; - int new_dirfd = find_relpath(newpath, &new_relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (new_dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_linkat(olddirfd, oldpath, - new_dirfd, new_relative_path, - flags); -} - -// Like `__wasilibc_link`, but newpath is relative to newdirfd. -int -__wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags) -{ - char *old_relative_path; - int old_dirfd = find_relpath(oldpath, &old_relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (old_dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, - newdirfd, newpath, - flags); -} - -// Like `rename`, but from is relative to fromdirfd. -int -__wasilibc_rename_oldat(int fromdirfd, const char *from, const char *to) -{ - char *to_relative_path; - int to_dirfd = find_relpath(to, &to_relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (to_dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_renameat(fromdirfd, from, to_dirfd, to_relative_path); -} - -// Like `rename`, but to is relative to todirfd. -int -__wasilibc_rename_newat(const char *from, int todirfd, const char *to) -{ - char *from_relative_path; - int from_dirfd = find_relpath(from, &from_relative_path); - - // If we can't find a preopen for it, fail as if we can't find the path. - if (from_dirfd == -1) { - errno = ENOENT; - return -1; - } - - return __wasilibc_nocwd_renameat(from_dirfd, from_relative_path, todirfd, to); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/preopens.c b/lib/libc/wasi/libc-bottom-half/sources/preopens.c deleted file mode 100644 index ccd65e892f73eeaebf2fd5d2e7c7e2bceeed0c4a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/preopens.c +++ /dev/null @@ -1,310 +0,0 @@ -//! Support for "preopens", file descriptors passed into the program from the -//! environment, with associated path prefixes, which can be used to map -//! absolute paths to capabilities with relative paths. - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/// A name and file descriptor pair. -typedef struct preopen { - /// The path prefix associated with the file descriptor. - const char *prefix; - - /// The file descriptor. - __wasi_fd_t fd; -} preopen; - -/// A simple growable array of `preopen`. -static _Atomic _Bool preopens_populated = false; -static preopen *preopens; -static size_t num_preopens; -static size_t preopen_capacity; - -/// Access to the the above preopen must be protected in the presence of -/// threads. -#ifdef _REENTRANT -static volatile int lock[1]; -#endif - -#ifdef NDEBUG -#define assert_invariants() // assertions disabled -#else -static void assert_invariants(void) { - assert(num_preopens <= preopen_capacity); - assert(preopen_capacity == 0 || preopens != NULL); - assert(preopen_capacity == 0 || - preopen_capacity * sizeof(preopen) > preopen_capacity); - - for (size_t i = 0; i < num_preopens; ++i) { - const preopen *pre = &preopens[i]; - assert(pre->prefix != NULL); - assert(pre->fd != (__wasi_fd_t)-1); -#ifdef __wasm__ - assert((uintptr_t)pre->prefix < - (__uint128_t)__builtin_wasm_memory_size(0) * PAGESIZE); -#endif - } -} -#endif - -/// Allocate space for more preopens. Returns 0 on success and -1 on failure. -static int resize(void) { - size_t start_capacity = 4; - size_t old_capacity = preopen_capacity; - size_t new_capacity = old_capacity == 0 ? start_capacity : old_capacity * 2; - - preopen *old_preopens = preopens; - preopen *new_preopens = calloc(sizeof(preopen), new_capacity); - if (new_preopens == NULL) { - return -1; - } - - memcpy(new_preopens, old_preopens, num_preopens * sizeof(preopen)); - preopens = new_preopens; - preopen_capacity = new_capacity; - free(old_preopens); - - assert_invariants(); - return 0; -} - -// Normalize an absolute path. Removes leading `/` and leading `./`, so the -// first character is the start of a directory name. This works because our -// process always starts with a working directory of `/`. Additionally translate -// `.` to the empty string. -static const char *strip_prefixes(const char *path) { - while (1) { - if (path[0] == '/') { - path++; - } else if (path[0] == '.' && path[1] == '/') { - path += 2; - } else if (path[0] == '.' && path[1] == 0) { - path++; - } else { - break; - } - } - - return path; -} - -/// Similar to `internal_register_preopened_fd` but does not take a lock. -static int internal_register_preopened_fd_unlocked(__wasi_fd_t fd, const char *relprefix) { - // Check preconditions. - assert_invariants(); - assert(fd != AT_FDCWD); - assert(fd != -1); - assert(relprefix != NULL); - - if (num_preopens == preopen_capacity && resize() != 0) { - return -1; - } - - char *prefix = strdup(strip_prefixes(relprefix)); - if (prefix == NULL) { - return -1; - } - preopens[num_preopens++] = (preopen) { prefix, fd, }; - - assert_invariants(); - return 0; -} - -/// Register the given preopened file descriptor under the given path. -/// -/// This function takes ownership of `prefix`. -static int internal_register_preopened_fd(__wasi_fd_t fd, const char *relprefix) { - LOCK(lock); - - int r = internal_register_preopened_fd_unlocked(fd, relprefix); - - UNLOCK(lock); - - return r; -} - -/// Are the `prefix_len` bytes pointed to by `prefix` a prefix of `path`? -static bool prefix_matches(const char *prefix, size_t prefix_len, const char *path) { - // Allow an empty string as a prefix of any relative path. - if (path[0] != '/' && prefix_len == 0) - return true; - - // Check whether any bytes of the prefix differ. - if (memcmp(path, prefix, prefix_len) != 0) - return false; - - // Ignore trailing slashes in directory names. - size_t i = prefix_len; - while (i > 0 && prefix[i - 1] == '/') { - --i; - } - - // Match only complete path components. - char last = path[i]; - return last == '/' || last == '\0'; -} - -// See the documentation in libc.h -int __wasilibc_register_preopened_fd(int fd, const char *prefix) { - __wasilibc_populate_preopens(); - - return internal_register_preopened_fd((__wasi_fd_t)fd, prefix); -} - -// See the documentation in libc-find-relpath.h. -int __wasilibc_find_relpath(const char *path, - const char **abs_prefix, - char **relative_path, - size_t relative_path_len) { - // If `chdir` is linked, whose object file defines this symbol, then we - // call that. Otherwise if the program can't `chdir` then `path` is - // absolute (or relative to the root dir), so we delegate to `find_abspath` - if (__wasilibc_find_relpath_alloc) - return __wasilibc_find_relpath_alloc(path, abs_prefix, relative_path, &relative_path_len, 0); - return __wasilibc_find_abspath(path, abs_prefix, (const char**) relative_path); -} - -// See the documentation in libc-find-relpath.h. -int __wasilibc_find_abspath(const char *path, - const char **abs_prefix, - const char **relative_path) { - __wasilibc_populate_preopens(); - - // Strip leading `/` characters, the prefixes we're matching won't have - // them. - while (*path == '/') - path++; - // Search through the preopens table. Iterate in reverse so that more - // recently added preopens take precedence over less recently addded ones. - size_t match_len = 0; - int fd = -1; - LOCK(lock); - for (size_t i = num_preopens; i > 0; --i) { - const preopen *pre = &preopens[i - 1]; - const char *prefix = pre->prefix; - size_t len = strlen(prefix); - - // If we haven't had a match yet, or the candidate path is longer than - // our current best match's path, and the candidate path is a prefix of - // the requested path, take that as the new best path. - if ((fd == -1 || len > match_len) && - prefix_matches(prefix, len, path)) - { - fd = pre->fd; - match_len = len; - *abs_prefix = prefix; - } - } - UNLOCK(lock); - - if (fd == -1) { - errno = ENOENT; - return -1; - } - - // The relative path is the substring after the portion that was matched. - const char *computed = path + match_len; - - // Omit leading slashes in the relative path. - while (*computed == '/') - ++computed; - - // *at syscalls don't accept empty relative paths, so use "." instead. - if (*computed == '\0') - computed = "."; - - *relative_path = computed; - return fd; -} - -/* zig patch: initialize preopens early so zig code doesn't have to call __wasilibc_populate_preopens */ -__attribute__((constructor(51))) -void __wasilibc_populate_preopens(void) { - // Fast path: If the preopens are already initialized, do nothing. - if (preopens_populated) { - return; - } - - LOCK(lock); - - // Check whether another thread initialized the preopens already. - if (preopens_populated) { - UNLOCK(lock); - return; - } - - // Skip stdin, stdout, and stderr, and count up until we reach an invalid - // file descriptor. - 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_ERRNO_BADF) - break; - if (ret != __WASI_ERRNO_SUCCESS) - goto oserr; - switch (prestat.tag) { - case __WASI_PREOPENTYPE_DIR: { - char *prefix = malloc(prestat.u.dir.pr_name_len + 1); - if (prefix == NULL) - goto software; - - // TODO: Remove the cast on `prefix` once the witx is updated with - // char8 support. - ret = __wasi_fd_prestat_dir_name(fd, (uint8_t *)prefix, - prestat.u.dir.pr_name_len); - if (ret != __WASI_ERRNO_SUCCESS) - goto oserr; - prefix[prestat.u.dir.pr_name_len] = '\0'; - - if (internal_register_preopened_fd_unlocked(fd, prefix) != 0) - goto software; - free(prefix); - - break; - } - default: - break; - } - } - - // Preopens are now initialized. - preopens_populated = true; - - UNLOCK(lock); - - return; -oserr: - _Exit(EX_OSERR); -software: - _Exit(EX_SOFTWARE); -} - -void __wasilibc_reset_preopens(void) { - LOCK(lock); - - if (num_preopens) { - for (int i = 0; i < num_preopens; ++i) { - free((void*) preopens[i].prefix); - } - free(preopens); - } - - preopens_populated = false; - preopens = NULL; - num_preopens = 0; - preopen_capacity = 0; - - assert_invariants(); - - UNLOCK(lock); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/sbrk.c b/lib/libc/wasi/libc-bottom-half/sources/sbrk.c deleted file mode 100644 index a26b75e9e3e52d0a96629d548cd23974eed518a0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/sbrk.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include -#include -#include <__macro_PAGESIZE.h> - -// Bare-bones implementation of sbrk. -void *sbrk(intptr_t increment) { - // sbrk(0) returns the current memory size. - if (increment == 0) { - // The wasm spec doesn't guarantee that memory.grow of 0 always succeeds. - return (void *)(__builtin_wasm_memory_size(0) * PAGESIZE); - } - - // We only support page-size increments. - if (increment % PAGESIZE != 0) { - abort(); - } - - // WebAssembly doesn't support shrinking linear memory. - if (increment < 0) { - abort(); - } - - uintptr_t old = __builtin_wasm_memory_grow(0, (uintptr_t)increment / PAGESIZE); - - if (old == SIZE_MAX) { - errno = ENOMEM; - return (void *)-1; - } - - return (void *)(old * PAGESIZE); -} diff --git a/lib/libc/wasi/libc-bottom-half/sources/truncate.c b/lib/libc/wasi/libc-bottom-half/sources/truncate.c deleted file mode 100644 index 24ae28f15eb87077ac3d20b3f6e807f54a32d039..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-bottom-half/sources/truncate.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include -#include -#include - -int truncate(const char *path, off_t length) -{ - int fd = __wasilibc_open_nomode(path, O_WRONLY | O_CLOEXEC | O_NOCTTY); - if (fd < 0) - return -1; - - int result = ftruncate(fd, length); - if (result != 0) { - int save_errno = errno; - (void)close(fd); - errno = save_errno; - return -1; - } - - return close(fd); -} diff --git a/lib/libc/wasi/libc-top-half/headers/private/printscan.h b/lib/libc/wasi/libc-top-half/headers/private/printscan.h deleted file mode 100644 index 7c21f99d8378cc270cd4173a97f380d306781c9e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/headers/private/printscan.h +++ /dev/null @@ -1,59 +0,0 @@ -#if defined(__wasilibc_printscan_no_floating_point) - -#include - -__attribute__((__cold__, __noreturn__)) -static void floating_point_not_supported(void) { - void abort(void) __attribute__((__noreturn__)); - fputs("Support for floating-point formatting is currently disabled.\n" - "To enable it, " __wasilibc_printscan_floating_point_support_option ".\n", stderr); - abort(); -} - -#elif defined(__wasilibc_printscan_no_long_double) - -#include - -typedef double long_double; -#undef LDBL_TRUE_MIN -#define LDBL_TRUE_MIN DBL_DENORM_MIN -#undef LDBL_MIN -#define LDBL_MIN DBL_MIN -#undef LDBL_MAX -#define LDBL_MAX DBL_MAX -#undef LDBL_EPSILON -#define LDBL_EPSILON DBL_EPSILON -#undef LDBL_MANT_DIG -#define LDBL_MANT_DIG DBL_MANT_DIG -#undef LDBL_MIN_EXP -#define LDBL_MIN_EXP DBL_MIN_EXP -#undef LDBL_MAX_EXP -#define LDBL_MAX_EXP DBL_MAX_EXP -#undef LDBL_DIG -#define LDBL_DIG DBL_DIG -#undef LDBL_MIN_10_EXP -#define LDBL_MIN_10_EXP DBL_MIN_10_EXP -#undef LDBL_MAX_10_EXP -#define LDBL_MAX_10_EXP DBL_MAX_10_EXP -#undef frexpl -#define frexpl(x, exp) frexp(x, exp) -#undef copysignl -#define copysignl(x, y) copysign(x, y) -#undef fmodl -#define fmodl(x, y) fmod(x, y) -#undef scalbnl -#define scalbnl(arg, exp) scalbn(arg, exp) -__attribute__((__cold__, __noreturn__)) -static void long_double_not_supported(void) { - void abort(void) __attribute__((__noreturn__)); - fputs("Support for formatting long double values is currently disabled.\n" - "To enable it, " __wasilibc_printscan_full_support_option ".\n", &__stderr_FILE); - abort(); -} - -#else - -// Full long double support. -typedef long double long_double; - -#endif diff --git a/lib/libc/wasi/libc-top-half/headers/private/wasi/libc-environ-compat.h b/lib/libc/wasi/libc-top-half/headers/private/wasi/libc-environ-compat.h deleted file mode 100644 index fa2747dec87965ac66ebef5230d9e6af3755a59a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/headers/private/wasi/libc-environ-compat.h +++ /dev/null @@ -1,12 +0,0 @@ -// This header file is meant to be included withinin the body of a function -// which uses `__environ`. Code using `__environ` expects it will be initialized -// eagerly. `__wasilibc_environ` is initialized lazily. Provide `__environ` as -// an alias and arrange for the lazy initialization to be performed. - -extern char **__wasilibc_environ; - -__wasilibc_ensure_environ(); - -#ifndef __wasilibc_environ -#define __environ __wasilibc_environ -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/COPYRIGHT b/lib/libc/wasi/libc-top-half/musl/COPYRIGHT deleted file mode 100644 index c1628e9ac84f927fe791124ec172fb61c760bb9b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/COPYRIGHT +++ /dev/null @@ -1,193 +0,0 @@ -musl as a whole is licensed under the following standard MIT license: - ----------------------------------------------------------------------- -Copyright © 2005-2020 Rich Felker, et al. - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY -CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, -TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE -SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ----------------------------------------------------------------------- - -Authors/contributors include: - -A. Wilcox -Ada Worcester -Alex Dowad -Alex Suykov -Alexander Monakov -Andre McCurdy -Andrew Kelley -Anthony G. Basile -Aric Belsito -Arvid Picciani -Bartosz Brachaczek -Benjamin Peterson -Bobby Bingham -Boris Brezillon -Brent Cook -Chris Spiegel -Clément Vasseur -Daniel Micay -Daniel Sabogal -Daurnimator -David Carlier -David Edelsohn -Denys Vlasenko -Dmitry Ivanov -Dmitry V. Levin -Drew DeVault -Emil Renner Berthing -Fangrui Song -Felix Fietkau -Felix Janda -Gianluca Anzolin -Hauke Mehrtens -He X -Hiltjo Posthuma -Isaac Dunham -Jaydeep Patil -Jens Gustedt -Jeremy Huntwork -Jo-Philipp Wich -Joakim Sindholt -John Spencer -Julien Ramseier -Justin Cormack -Kaarle Ritvanen -Khem Raj -Kylie McClain -Leah Neukirchen -Luca Barbato -Luka Perkov -M Farkas-Dyck (Strake) -Mahesh Bodapati -Markus Wichmann -Masanori Ogino -Michael Clark -Michael Forney -Mikhail Kremnyov -Natanael Copa -Nicholas J. Kain -orc -Pascal Cuoq -Patrick Oppenlander -Petr Hosek -Petr Skocik -Pierre Carrier -Reini Urban -Rich Felker -Richard Pennington -Ryan Fairfax -Samuel Holland -Segev Finer -Shiz -sin -Solar Designer -Stefan Kristiansson -Stefan O'Rear -Szabolcs Nagy -Timo Teräs -Trutz Behn -Valentin Ochs -Will Dietz -William Haddon -William Pitcock - -Portions of this software are derived from third-party works licensed -under terms compatible with the above MIT license: - -The TRE regular expression implementation (src/regex/reg* and -src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed -under a 2-clause BSD license (license text in the source files). The -included version has been heavily modified by Rich Felker in 2012, in -the interests of size, simplicity, and namespace cleanliness. - -Much of the math library code (src/math/* and src/complex/*) is -Copyright © 1993,2004 Sun Microsystems or -Copyright © 2003-2011 David Schultz or -Copyright © 2003-2009 Steven G. Kargl or -Copyright © 2003-2009 Bruce D. Evans or -Copyright © 2008 Stephen L. Moshier or -Copyright © 2017-2018 Arm Limited -and labelled as such in comments in the individual source files. All -have been licensed under extremely permissive terms. - -The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008 -The Android Open Source Project and is licensed under a two-clause BSD -license. It was taken from Bionic libc, used on Android. - -The AArch64 memcpy and memset code (src/string/aarch64/*) are -Copyright © 1999-2019, Arm Limited. - -The implementation of DES for crypt (src/crypt/crypt_des.c) is -Copyright © 1994 David Burren. It is licensed under a BSD license. - -The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was -originally written by Solar Designer and placed into the public -domain. The code also comes with a fallback permissive license for use -in jurisdictions that may not recognize the public domain. - -The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011 -Valentin Ochs and is licensed under an MIT-style license. - -The x86_64 port was written by Nicholas J. Kain and is licensed under -the standard MIT terms. - -The mips and microblaze ports were originally written by Richard -Pennington for use in the ellcc project. The original code was adapted -by Rich Felker for build system and code conventions during upstream -integration. It is licensed under the standard MIT terms. - -The mips64 port was contributed by Imagination Technologies and is -licensed under the standard MIT terms. - -The powerpc port was also originally written by Richard Pennington, -and later supplemented and integrated by John Spencer. It is licensed -under the standard MIT terms. - -All other files which have no copyright comments are original works -produced specifically for use as part of this library, written either -by Rich Felker, the main author of the library, or by one or more -contibutors listed above. Details on authorship of individual files -can be found in the git version control history of the project. The -omission of copyright and license comments in each file is in the -interest of source tree size. - -In addition, permission is hereby granted for all public header files -(include/* and arch/*/bits/*) and crt files intended to be linked into -applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit -the copyright notice and permission notice otherwise required by the -license, and to use these files without any requirement of -attribution. These files include substantial contributions from: - -Bobby Bingham -John Spencer -Nicholas J. Kain -Rich Felker -Richard Pennington -Stefan Kristiansson -Szabolcs Nagy - -all of whom have explicitly granted such permission. - -This file previously contained text expressing a belief that most of -the files covered by the above exception were sufficiently trivial not -to be subject to copyright, resulting in confusion over whether it -negated the permissions granted in the license. In the spirit of -permissive licensing, and of not having licensing issues being an -obstacle to adoption, that text has been removed. diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h deleted file mode 100644 index c24ce2d7b1d2cdbaadeca3efa9cbb1ddc5a4baea..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h +++ /dev/null @@ -1,6 +0,0 @@ -#define a_cas(p, t, s) (__sync_val_compare_and_swap((p), (t), (s))) -#define a_crash() (__builtin_trap()) -#define a_clz_32 __builtin_clz -#define a_clz_64 __builtin_clzll -#define a_ctz_32 __builtin_ctz -#define a_ctz_64 __builtin_ctzll diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/dirent.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/dirent.h deleted file mode 100644 index 55f2bc9d4ebea51424f9b89176dcad0ce8e4e97f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/dirent.h +++ /dev/null @@ -1 +0,0 @@ -#include <__struct_dirent.h> diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/fcntl.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/fcntl.h deleted file mode 100644 index a2f334161308bc5da472b7ff29ee63b3c4503c88..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/fcntl.h +++ /dev/null @@ -1 +0,0 @@ -/* Use the WASI libc fcntl implementation bits. */ diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/float.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/float.h deleted file mode 100644 index 719c79085af84ad0148edcfbacce963d15178837..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/float.h +++ /dev/null @@ -1,16 +0,0 @@ -#define FLT_EVAL_METHOD 0 - -#define LDBL_TRUE_MIN 6.47517511943802511092443895822764655e-4966L -#define LDBL_MIN 3.36210314311209350626267781732175260e-4932L -#define LDBL_MAX 1.18973149535723176508575932662800702e+4932L -#define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L - -#define LDBL_MANT_DIG 113 -#define LDBL_MIN_EXP (-16381) -#define LDBL_MAX_EXP 16384 - -#define LDBL_DIG 33 -#define LDBL_MIN_10_EXP (-4931) -#define LDBL_MAX_10_EXP 4932 - -#define DECIMAL_DIG 36 diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/ioctl.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/ioctl.h deleted file mode 100644 index b4bf7c71bdf2a82daba6382a279f07ac82e6101c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/ioctl.h +++ /dev/null @@ -1 +0,0 @@ -/* Use the WASI libc ioctl implementation bits. */ diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/limits.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/limits.h deleted file mode 100644 index 801bc48fd16f2c8c7b1d6b3d43c2fa0200c93a9e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/limits.h +++ /dev/null @@ -1 +0,0 @@ -#include <__macro_PAGESIZE.h> diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/posix.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/posix.h deleted file mode 100644 index 387a3e4791553e568821216b3d49e3b7c9d016fd..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/posix.h +++ /dev/null @@ -1,2 +0,0 @@ -#define _POSIX_V6_ILP32_OFFBIG (1) -#define _POSIX_V7_ILP32_OFFBIG (1) diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/reg.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/reg.h deleted file mode 100644 index 2633f39d77739ffd4a9100508c3bbfd6286ffa43..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/reg.h +++ /dev/null @@ -1,2 +0,0 @@ -#undef __WORDSIZE -#define __WORDSIZE 64 diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/setjmp.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/setjmp.h deleted file mode 100644 index 63973a8001168472c1acc8ba1df81f59e8f7b583..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/setjmp.h +++ /dev/null @@ -1 +0,0 @@ -typedef unsigned long __jmp_buf[8]; diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/signal.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/signal.h deleted file mode 100644 index 77e8d8c61e8c31a1104f12625ccf8b0ea17c4bf0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/signal.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifdef _WASI_EMULATED_SIGNAL - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT SIGABRT -#define SIGBUS 7 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGUSR1 10 -#define SIGSEGV 11 -#define SIGUSR2 12 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPOLL 29 -#define SIGPWR 30 -#define SIGSYS 31 -#define SIGUNUSED SIGSYS - -#define _NSIG 65 - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stat.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stat.h deleted file mode 100644 index 67a0e726ab0a799d0656402199b5d399d600c59e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stat.h +++ /dev/null @@ -1 +0,0 @@ -#include <__struct_stat.h> diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stdint.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stdint.h deleted file mode 100644 index 6e7c7705bf48a7d55e8841eab5adb4f458a54d30..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stdint.h +++ /dev/null @@ -1,20 +0,0 @@ -typedef int16_t int_fast16_t; -typedef int32_t int_fast32_t; -typedef uint16_t uint_fast16_t; -typedef uint32_t uint_fast32_t; - -#define INT_FAST16_MIN INT16_MIN -#define INT_FAST32_MIN INT32_MIN - -#define INT_FAST16_MAX INT16_MAX -#define INT_FAST32_MAX INT32_MAX - -#define UINT_FAST16_MAX UINT16_MAX -#define UINT_FAST32_MAX UINT32_MAX - -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#define PTRDIFF_MIN INT32_MIN -#define PTRDIFF_MAX INT32_MAX -#define SIZE_MAX UINT32_MAX diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/fp_arch.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/fp_arch.h deleted file mode 100644 index 707d512726ea7bbb960324490f7bda683057b28e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/fp_arch.h +++ /dev/null @@ -1,25 +0,0 @@ -// WebAssembly has no floating-point exceptions or alternate rounding modes, -// so there's no need to prevent expressions from moving or force their -// evaluation. - -#define fp_barrierf fp_barrierf -static inline float fp_barrierf(float x) -{ - return x; -} - -#define fp_barrier fp_barrier -static inline double fp_barrier(double x) -{ - return x; -} - -#define fp_force_evalf fp_force_evalf -static inline void fp_force_evalf(float x) -{ -} - -#define fp_force_eval fp_force_eval -static inline void fp_force_eval(double x) -{ -} diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/pthread_arch.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/pthread_arch.h deleted file mode 100644 index 58e76ab0a5ff2383e6cb05f50a70179b1e67918d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/pthread_arch.h +++ /dev/null @@ -1,5 +0,0 @@ -extern _Thread_local struct __pthread __wasilibc_pthread_self; - -static inline uintptr_t __get_tp() { - return (uintptr_t)&__wasilibc_pthread_self; -} diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/reloc.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/reloc.h deleted file mode 100644 index 91b484030cd23dc4e45b91b9edf9d66e62c9223c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/reloc.h +++ /dev/null @@ -1 +0,0 @@ -#define LDSO_ARCH "wasm32" diff --git a/lib/libc/wasi/libc-top-half/musl/arch/wasm32/syscall_arch.h b/lib/libc/wasi/libc-top-half/musl/arch/wasm32/syscall_arch.h deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/lib/libc/wasi/libc-top-half/musl/include/aio.h b/lib/libc/wasi/libc-top-half/musl/include/aio.h deleted file mode 100644 index 453c41b7489f3d2f27a545db8a9ab072e9ea75d0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/aio.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _AIO_H -#define _AIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include - -#define __NEED_ssize_t -#define __NEED_off_t - -#include - -struct aiocb { - int aio_fildes, aio_lio_opcode, aio_reqprio; - volatile void *aio_buf; - size_t aio_nbytes; - struct sigevent aio_sigevent; - void *__td; - int __lock[2]; - volatile int __err; - ssize_t __ret; - off_t aio_offset; - void *__next, *__prev; - char __dummy4[32-2*sizeof(void *)]; -}; - -#define AIO_CANCELED 0 -#define AIO_NOTCANCELED 1 -#define AIO_ALLDONE 2 - -#define LIO_READ 0 -#define LIO_WRITE 1 -#define LIO_NOP 2 - -#define LIO_WAIT 0 -#define LIO_NOWAIT 1 - -int aio_read(struct aiocb *); -int aio_write(struct aiocb *); -int aio_error(const struct aiocb *); -ssize_t aio_return(struct aiocb *); -int aio_cancel(int, struct aiocb *); -int aio_suspend(const struct aiocb *const [], int, const struct timespec *); -int aio_fsync(int, struct aiocb *); - -int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define aiocb64 aiocb -#define aio_read64 aio_read -#define aio_write64 aio_write -#define aio_error64 aio_error -#define aio_return64 aio_return -#define aio_cancel64 aio_cancel -#define aio_suspend64 aio_suspend -#define aio_fsync64 aio_fsync -#define lio_listio64 lio_listio -#define off64_t off_t -#endif - -#if _REDIR_TIME64 -__REDIR(aio_suspend, __aio_suspend_time64); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/arpa/inet.h b/lib/libc/wasi/libc-top-half/musl/include/arpa/inet.h deleted file mode 100644 index f657c30ec80361d1c98e1ff29dc2d2e69b92e779..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/arpa/inet.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef _ARPA_INET_H -#define _ARPA_INET_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_addr */ -in_addr_t inet_addr (const char *); -in_addr_t inet_network (const char *); -char *inet_ntoa (struct in_addr); -#endif -int inet_pton (int, const char *__restrict, void *__restrict); -const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); - -int inet_aton (const char *, struct in_addr *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no inet_makeaddr */ -struct in_addr inet_makeaddr(in_addr_t, in_addr_t); -in_addr_t inet_lnaof(struct in_addr); -in_addr_t inet_netof(struct in_addr); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/complex.h b/lib/libc/wasi/libc-top-half/musl/include/complex.h deleted file mode 100644 index a645eb13af8b84bda2ce3b3f027840ea867cef6b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/complex.h +++ /dev/null @@ -1,143 +0,0 @@ -#ifndef _COMPLEX_H -#define _COMPLEX_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define complex _Complex -#ifdef __GNUC__ -#define _Complex_I (__extension__ (0.0f+1.0fi)) -#else -#define _Complex_I (0.0f+1.0fi) -#endif -#define I _Complex_I - -double complex cacos(double complex); -float complex cacosf(float complex); -long double complex cacosl(long double complex); - -double complex casin(double complex); -float complex casinf(float complex); -long double complex casinl(long double complex); - -double complex catan(double complex); -float complex catanf(float complex); -long double complex catanl(long double complex); - -double complex ccos(double complex); -float complex ccosf(float complex); -long double complex ccosl(long double complex); - -double complex csin(double complex); -float complex csinf(float complex); -long double complex csinl(long double complex); - -double complex ctan(double complex); -float complex ctanf(float complex); -long double complex ctanl(long double complex); - -double complex cacosh(double complex); -float complex cacoshf(float complex); -long double complex cacoshl(long double complex); - -double complex casinh(double complex); -float complex casinhf(float complex); -long double complex casinhl(long double complex); - -double complex catanh(double complex); -float complex catanhf(float complex); -long double complex catanhl(long double complex); - -double complex ccosh(double complex); -float complex ccoshf(float complex); -long double complex ccoshl(long double complex); - -double complex csinh(double complex); -float complex csinhf(float complex); -long double complex csinhl(long double complex); - -double complex ctanh(double complex); -float complex ctanhf(float complex); -long double complex ctanhl(long double complex); - -double complex cexp(double complex); -float complex cexpf(float complex); -long double complex cexpl(long double complex); - -double complex clog(double complex); -float complex clogf(float complex); -long double complex clogl(long double complex); - -double cabs(double complex); -float cabsf(float complex); -long double cabsl(long double complex); - -double complex cpow(double complex, double complex); -float complex cpowf(float complex, float complex); -long double complex cpowl(long double complex, long double complex); - -double complex csqrt(double complex); -float complex csqrtf(float complex); -long double complex csqrtl(long double complex); - -double carg(double complex); -float cargf(float complex); -long double cargl(long double complex); - -double cimag(double complex); -float cimagf(float complex); -long double cimagl(long double complex); - -double complex conj(double complex); -float complex conjf(float complex); -long double complex conjl(long double complex); - -double complex cproj(double complex); -float complex cprojf(float complex); -long double complex cprojl(long double complex); - -double creal(double complex); -float crealf(float complex); -long double creall(long double complex); - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's real/imag operators rather than union type punning */ -#ifndef __cplusplus -#define __CIMAG(x, t) \ - (+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) - -#define creal(x) ((double)(x)) -#define crealf(x) ((float)(x)) -#define creall(x) ((long double)(x)) - -#define cimag(x) __CIMAG(x, double) -#define cimagf(x) __CIMAG(x, float) -#define cimagl(x) __CIMAG(x, long double) -#endif -#else -#define creal(x) (__builtin_creal(x)) -#define crealf(x) (__builtin_crealf(x)) -#define creall(x) (__builtin_creall(x)) - -#define cimag(x) (__builtin_cimag(x)) -#define cimagf(x) (__builtin_cimagf(x)) -#define cimagl(x) (__builtin_cimagl(x)) -#endif - -#if __STDC_VERSION__ >= 201112L -#if defined(_Imaginary_I) -#define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)) -#elif defined(__clang__) -#define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) -#else -#define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) -#endif -#define CMPLX(x, y) __CMPLX(x, y, double) -#define CMPLXF(x, y) __CMPLX(x, y, float) -#define CMPLXL(x, y) __CMPLX(x, y, long double) -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/dirent.h b/lib/libc/wasi/libc-top-half/musl/include/dirent.h deleted file mode 100644 index 52a3b16a440566efa68ff2fd824359a27792c551..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/dirent.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef _DIRENT_H -#define _DIRENT_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_dirent.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_ino_t -#define __NEED_off_t -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define __NEED_size_t -#endif - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef struct __dirstream DIR; -#else -#include <__typedef_DIR.h> -#endif - -#define d_fileno d_ino - -int closedir(DIR *); -DIR *fdopendir(int); -DIR *opendir(const char *); -struct dirent *readdir(DIR *); -#ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ -int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); -#endif -void rewinddir(DIR *); -int dirfd(DIR *); - -int alphasort(const struct dirent **, const struct dirent **); -int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -void seekdir(DIR *, long); -long telldir(DIR *); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define DT_UNKNOWN 0 -#define DT_FIFO 1 -#define DT_CHR 2 -#define DT_DIR 4 -#define DT_BLK 6 -#define DT_REG 8 -#define DT_LNK 10 -#define DT_SOCK 12 -#define DT_WHT 14 -#define IFTODT(x) ((x)>>12 & 017) -#define DTTOIF(x) ((x)<<12) -#endif -int getdents(int, struct dirent *, size_t); -#endif - -#ifdef _GNU_SOURCE -int versionsort(const struct dirent **, const struct dirent **); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define dirent64 dirent -#define readdir64 readdir -#ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ -#define readdir64_r readdir_r -#endif -#define scandir64 scandir -#define alphasort64 alphasort -#define versionsort64 versionsort -#define off64_t off_t -#define ino64_t ino_t -#define getdents64 getdents -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/dlfcn.h b/lib/libc/wasi/libc-top-half/musl/include/dlfcn.h deleted file mode 100644 index e802de88f67122a9f908355ca7fac6850c6de6b6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/dlfcn.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _DLFCN_H -#define _DLFCN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define RTLD_LAZY 1 -#define RTLD_NOW 2 -#define RTLD_NOLOAD 4 -#define RTLD_NODELETE 4096 -#define RTLD_GLOBAL 256 -#ifdef __wasilibc_unmodified_upstream -#define RTLD_LOCAL 0 -#else -/* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and - * allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` - * should be the default when neither is specified. - */ -#define RTLD_LOCAL 8 -#endif - -#define RTLD_NEXT ((void *)-1) -#define RTLD_DEFAULT ((void *)0) - -#ifdef __wasilibc_unmodified_upstream -#define RTLD_DI_LINKMAP 2 -#endif - -int dlclose(void *); -char *dlerror(void); -void *dlopen(const char *, int); -void *dlsym(void *__restrict, const char *__restrict); - -#if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) -typedef struct { - const char *dli_fname; - void *dli_fbase; - const char *dli_sname; - void *dli_saddr; -} Dl_info; -int dladdr(const void *, Dl_info *); -int dlinfo(void *, int, void *); -#endif - -#if _REDIR_TIME64 -__REDIR(dlsym, __dlsym_time64); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/errno.h b/lib/libc/wasi/libc-top-half/musl/include/errno.h deleted file mode 100644 index 0252e1b09560cbeca8df05745203454cc6a66a16..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/errno.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _ERRNO_H -#define _ERRNO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#include - -#ifdef __GNUC__ -__attribute__((const)) -#endif -int *__errno_location(void); -#define errno (*__errno_location()) -#else -#include <__errno.h> -#include <__errno_values.h> -#endif - -#ifdef _GNU_SOURCE -extern char *program_invocation_short_name, *program_invocation_name; -#endif - -#ifdef __cplusplus -} -#endif - -#endif - diff --git a/lib/libc/wasi/libc-top-half/musl/include/fcntl.h b/lib/libc/wasi/libc-top-half/musl/include/fcntl.h deleted file mode 100644 index eef21db1dcbe90f9be3b15edcf8326d8d8e77cd7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/fcntl.h +++ /dev/null @@ -1,250 +0,0 @@ -#ifndef _FCNTL_H -#define _FCNTL_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_fcntl.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_mode_t - -#ifdef _GNU_SOURCE -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec -#endif - -#include - -#include - -struct flock { - short l_type; - short l_whence; - off_t l_start; - off_t l_len; - pid_t l_pid; -}; - -int creat(const char *, mode_t); -int fcntl(int, int, ...); -int open(const char *, int, ...); -int openat(int, const char *, int, ...); -int posix_fadvise(int, off_t, off_t, int); -int posix_fallocate(int, off_t, off_t); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define O_SEARCH O_PATH -#define O_EXEC O_PATH -#define O_TTY_INIT 0 - -#define O_ACCMODE (03|O_SEARCH) -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 - -#define F_OFD_GETLK 36 -#define F_OFD_SETLK 37 -#define F_OFD_SETLKW 38 - -#define F_DUPFD_CLOEXEC 1030 - -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 - -#define FD_CLOEXEC 1 - -#define AT_FDCWD (-100) -#define AT_SYMLINK_NOFOLLOW 0x100 -#define AT_REMOVEDIR 0x200 -#define AT_SYMLINK_FOLLOW 0x400 -#define AT_EACCESS 0x200 - -#define POSIX_FADV_NORMAL 0 -#define POSIX_FADV_RANDOM 1 -#define POSIX_FADV_SEQUENTIAL 2 -#define POSIX_FADV_WILLNEED 3 -#ifndef POSIX_FADV_DONTNEED -#define POSIX_FADV_DONTNEED 4 -#define POSIX_FADV_NOREUSE 5 -#endif - -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 - -#ifndef S_IRUSR -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define AT_NO_AUTOMOUNT 0x800 -#define AT_EMPTY_PATH 0x1000 -#define AT_STATX_SYNC_TYPE 0x6000 -#define AT_STATX_SYNC_AS_STAT 0x0000 -#define AT_STATX_FORCE_SYNC 0x2000 -#define AT_STATX_DONT_SYNC 0x4000 -#define AT_RECURSIVE 0x8000 - -#define FAPPEND O_APPEND -#define FFSYNC O_SYNC -#define FASYNC O_ASYNC -#define FNONBLOCK O_NONBLOCK -#define FNDELAY O_NDELAY - -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 - -#define F_SETLEASE 1024 -#define F_GETLEASE 1025 -#define F_NOTIFY 1026 -#define F_CANCELLK 1029 -#define F_SETPIPE_SZ 1031 -#define F_GETPIPE_SZ 1032 -#define F_ADD_SEALS 1033 -#define F_GET_SEALS 1034 - -#define F_SEAL_SEAL 0x0001 -#define F_SEAL_SHRINK 0x0002 -#define F_SEAL_GROW 0x0004 -#define F_SEAL_WRITE 0x0008 -#define F_SEAL_FUTURE_WRITE 0x0010 - -#define F_GET_RW_HINT 1035 -#define F_SET_RW_HINT 1036 -#define F_GET_FILE_RW_HINT 1037 -#define F_SET_FILE_RW_HINT 1038 - -#define RWF_WRITE_LIFE_NOT_SET 0 -#define RWH_WRITE_LIFE_NONE 1 -#define RWH_WRITE_LIFE_SHORT 2 -#define RWH_WRITE_LIFE_MEDIUM 3 -#define RWH_WRITE_LIFE_LONG 4 -#define RWH_WRITE_LIFE_EXTREME 5 - -#define DN_ACCESS 0x00000001 -#define DN_MODIFY 0x00000002 -#define DN_CREATE 0x00000004 -#define DN_DELETE 0x00000008 -#define DN_RENAME 0x00000010 -#define DN_ATTRIB 0x00000020 -#define DN_MULTISHOT 0x80000000 - -int lockf(int, int, off_t); -#endif -#endif - -#if defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ -#define F_OWNER_TID 0 -#define F_OWNER_PID 1 -#define F_OWNER_PGRP 2 -#define F_OWNER_GID 2 -struct file_handle { - unsigned handle_bytes; - int handle_type; - unsigned char f_handle[]; -}; -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no F_GETOWN_EX */ -struct f_owner_ex { - int type; - pid_t pid; -}; -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ -#define FALLOC_FL_KEEP_SIZE 1 -#define FALLOC_FL_PUNCH_HOLE 2 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ -#define MAX_HANDLE_SZ 128 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no syc_file_range */ -#define SYNC_FILE_RANGE_WAIT_BEFORE 1 -#define SYNC_FILE_RANGE_WRITE 2 -#define SYNC_FILE_RANGE_WAIT_AFTER 4 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no splice */ -#define SPLICE_F_MOVE 1 -#define SPLICE_F_NONBLOCK 2 -#define SPLICE_F_MORE 4 -#define SPLICE_F_GIFT 8 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ -int fallocate(int, int, off_t, off_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ -int name_to_handle_at(int, const char *, struct file_handle *, int *, int); -int open_by_handle_at(int, struct file_handle *, int); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */ -ssize_t readahead(int, off_t, size_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */ -int sync_file_range(int, off_t, off_t, unsigned); -ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); -ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); -ssize_t tee(int, int, size_t, unsigned); -#endif -#define loff_t off_t -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -#define F_GETLK64 F_GETLK -#define F_SETLK64 F_SETLK -#define F_SETLKW64 F_SETLKW -#define flock64 flock -#endif -#define open64 open -#define openat64 openat -#define creat64 creat -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -#define lockf64 lockf -#endif -#define posix_fadvise64 posix_fadvise -#define posix_fallocate64 posix_fallocate -#define off64_t off_t -#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ -#if defined(_GNU_SOURCE) -#define fallocate64 fallocate -#endif -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/float.h b/lib/libc/wasi/libc-top-half/musl/include/float.h deleted file mode 100644 index 85ce20c4c824c1fab900d0aff7e99d6e330f3b3b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/float.h +++ /dev/null @@ -1,56 +0,0 @@ -#ifndef _FLOAT_H -#define _FLOAT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of FLT_ROUNDS */ -int __flt_rounds(void); -#define FLT_ROUNDS (__flt_rounds()) -#else -#define FLT_ROUNDS (__builtin_flt_rounds()) -#endif - -#define FLT_RADIX 2 - -#define FLT_TRUE_MIN 1.40129846432481707092e-45F -#define FLT_MIN 1.17549435082228750797e-38F -#define FLT_MAX 3.40282346638528859812e+38F -#define FLT_EPSILON 1.1920928955078125e-07F - -#define FLT_MANT_DIG 24 -#define FLT_MIN_EXP (-125) -#define FLT_MAX_EXP 128 -#define FLT_HAS_SUBNORM 1 - -#define FLT_DIG 6 -#define FLT_DECIMAL_DIG 9 -#define FLT_MIN_10_EXP (-37) -#define FLT_MAX_10_EXP 38 - -#define DBL_TRUE_MIN 4.94065645841246544177e-324 -#define DBL_MIN 2.22507385850720138309e-308 -#define DBL_MAX 1.79769313486231570815e+308 -#define DBL_EPSILON 2.22044604925031308085e-16 - -#define DBL_MANT_DIG 53 -#define DBL_MIN_EXP (-1021) -#define DBL_MAX_EXP 1024 -#define DBL_HAS_SUBNORM 1 - -#define DBL_DIG 15 -#define DBL_DECIMAL_DIG 17 -#define DBL_MIN_10_EXP (-307) -#define DBL_MAX_10_EXP 308 - -#define LDBL_HAS_SUBNORM 1 -#define LDBL_DECIMAL_DIG DECIMAL_DIG - -#include - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/ftw.h b/lib/libc/wasi/libc-top-half/musl/include/ftw.h deleted file mode 100644 index 2b1b270c777d39a1f94fcce0f985847ee67f8a81..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/ftw.h +++ /dev/null @@ -1,45 +0,0 @@ -#ifndef _FTW_H -#define _FTW_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define FTW_F 1 -#define FTW_D 2 -#define FTW_DNR 3 -#define FTW_NS 4 -#define FTW_SL 5 -#define FTW_DP 6 -#define FTW_SLN 7 - -#define FTW_PHYS 1 -#define FTW_MOUNT 2 -#define FTW_CHDIR 4 -#define FTW_DEPTH 8 - -struct FTW { - int base; - int level; -}; - -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -int ftw(const char *, int (*)(const char *, const struct stat *, int), int); -#endif -int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -#define ftw64 ftw -#endif -#define nftw64 nftw -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/glob.h b/lib/libc/wasi/libc-top-half/musl/include/glob.h deleted file mode 100644 index 8c4bf15891d78c8fec9ff164be9c58762ecc2c71..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/glob.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _GLOB_H -#define _GLOB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t - -#include - -typedef struct { - size_t gl_pathc; - char **gl_pathv; - size_t gl_offs; - int __dummy1; - void *__dummy2[5]; -} glob_t; - -int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); -void globfree(glob_t *); - -#define GLOB_ERR 0x01 -#define GLOB_MARK 0x02 -#define GLOB_NOSORT 0x04 -#define GLOB_DOOFFS 0x08 -#define GLOB_NOCHECK 0x10 -#define GLOB_APPEND 0x20 -#define GLOB_NOESCAPE 0x40 -#define GLOB_PERIOD 0x80 - -#ifdef __wasilibc_unmodified_upstream // WASI has no usernames -#define GLOB_TILDE 0x1000 -#define GLOB_TILDE_CHECK 0x4000 -#endif - -#define GLOB_NOSPACE 1 -#define GLOB_ABORTED 2 -#define GLOB_NOMATCH 3 -#define GLOB_NOSYS 4 - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define glob64 glob -#define globfree64 globfree -#define glob64_t glob_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/inttypes.h b/lib/libc/wasi/libc-top-half/musl/include/inttypes.h deleted file mode 100644 index 71b3904317750c43864e26b097202c680a10323e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/inttypes.h +++ /dev/null @@ -1,233 +0,0 @@ -#ifndef _INTTYPES_H -#define _INTTYPES_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_wchar_t -#include - -typedef struct { intmax_t quot, rem; } imaxdiv_t; - -intmax_t imaxabs(intmax_t); -imaxdiv_t imaxdiv(intmax_t, intmax_t); - -intmax_t strtoimax(const char *__restrict, char **__restrict, int); -uintmax_t strtoumax(const char *__restrict, char **__restrict, int); - -intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); -uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); - -#if UINTPTR_MAX == UINT64_MAX -#define __PRI64 "l" -#define __PRIPTR "l" -#else -#define __PRI64 "ll" -#define __PRIPTR "" -#endif - -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 __PRI64 "d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 __PRI64 "d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 "d" -#define PRIdFAST32 "d" -#define PRIdFAST64 __PRI64 "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 __PRI64 "i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 __PRI64 "i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" -#define PRIiFAST32 "i" -#define PRIiFAST64 __PRI64 "i" - -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 __PRI64 "o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 __PRI64 "o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" -#define PRIoFAST32 "o" -#define PRIoFAST64 __PRI64 "o" - -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 __PRI64 "u" - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 __PRI64 "u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" -#define PRIuFAST32 "u" -#define PRIuFAST64 __PRI64 "u" - -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 __PRI64 "x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 __PRI64 "x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" -#define PRIxFAST32 "x" -#define PRIxFAST64 __PRI64 "x" - -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 __PRI64 "X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 __PRI64 "X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" -#define PRIXFAST32 "X" -#define PRIXFAST64 __PRI64 "X" - -#define PRIdMAX __PRI64 "d" -#define PRIiMAX __PRI64 "i" -#define PRIoMAX __PRI64 "o" -#define PRIuMAX __PRI64 "u" -#define PRIxMAX __PRI64 "x" -#define PRIXMAX __PRI64 "X" - -#define PRIdPTR __PRIPTR "d" -#define PRIiPTR __PRIPTR "i" -#define PRIoPTR __PRIPTR "o" -#define PRIuPTR __PRIPTR "u" -#define PRIxPTR __PRIPTR "x" -#define PRIXPTR __PRIPTR "X" - -#define SCNd8 "hhd" -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 __PRI64 "d" - -#define SCNdLEAST8 "hhd" -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 __PRI64 "d" - -#define SCNdFAST8 "hhd" -#define SCNdFAST16 "d" -#define SCNdFAST32 "d" -#define SCNdFAST64 __PRI64 "d" - -#define SCNi8 "hhi" -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 __PRI64 "i" - -#define SCNiLEAST8 "hhi" -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 __PRI64 "i" - -#define SCNiFAST8 "hhi" -#define SCNiFAST16 "i" -#define SCNiFAST32 "i" -#define SCNiFAST64 __PRI64 "i" - -#define SCNu8 "hhu" -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 __PRI64 "u" - -#define SCNuLEAST8 "hhu" -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 __PRI64 "u" - -#define SCNuFAST8 "hhu" -#define SCNuFAST16 "u" -#define SCNuFAST32 "u" -#define SCNuFAST64 __PRI64 "u" - -#define SCNo8 "hho" -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 __PRI64 "o" - -#define SCNoLEAST8 "hho" -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 __PRI64 "o" - -#define SCNoFAST8 "hho" -#define SCNoFAST16 "o" -#define SCNoFAST32 "o" -#define SCNoFAST64 __PRI64 "o" - -#define SCNx8 "hhx" -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 __PRI64 "x" - -#define SCNxLEAST8 "hhx" -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 __PRI64 "x" - -#define SCNxFAST8 "hhx" -#define SCNxFAST16 "x" -#define SCNxFAST32 "x" -#define SCNxFAST64 __PRI64 "x" - -#define SCNdMAX __PRI64 "d" -#define SCNiMAX __PRI64 "i" -#define SCNoMAX __PRI64 "o" -#define SCNuMAX __PRI64 "u" -#define SCNxMAX __PRI64 "x" - -#define SCNdPTR __PRIPTR "d" -#define SCNiPTR __PRIPTR "i" -#define SCNoPTR __PRIPTR "o" -#define SCNuPTR __PRIPTR "u" -#define SCNxPTR __PRIPTR "x" - -#ifdef __cplusplus -} -#endif -#else -#include <__header_inttypes.h> -#endif - -#endif - diff --git a/lib/libc/wasi/libc-top-half/musl/include/limits.h b/lib/libc/wasi/libc-top-half/musl/include/limits.h deleted file mode 100644 index c160568cdecedf4a5fba9692237baf624d3d705c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/limits.h +++ /dev/null @@ -1,178 +0,0 @@ -#ifndef _LIMITS_H -#define _LIMITS_H - -#include - -#include /* __LONG_MAX */ - -/* Support signed or unsigned plain-char */ - -#if '\xff' > 0 -#define CHAR_MIN 0 -#define CHAR_MAX 255 -#else -#define CHAR_MIN (-128) -#define CHAR_MAX 127 -#endif - -#define CHAR_BIT 8 -#define SCHAR_MIN (-128) -#define SCHAR_MAX 127 -#define UCHAR_MAX 255 -#define SHRT_MIN (-1-0x7fff) -#define SHRT_MAX 0x7fff -#define USHRT_MAX 0xffff -#define INT_MIN (-1-0x7fffffff) -#define INT_MAX 0x7fffffff -#define UINT_MAX 0xffffffffU -#define LONG_MIN (-LONG_MAX-1) -#define LONG_MAX __LONG_MAX -#define ULONG_MAX (2UL*LONG_MAX+1) -#define LLONG_MIN (-LLONG_MAX-1) -#define LLONG_MAX 0x7fffffffffffffffLL -#define ULLONG_MAX (2ULL*LLONG_MAX+1) - -#define MB_LEN_MAX 4 - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#include - -#ifdef __wasilibc_unmodified_upstream /* WASI has no pipes */ -#define PIPE_BUF 4096 -#endif -#define FILESIZEBITS 64 -#ifndef NAME_MAX -#define NAME_MAX 255 -#endif -#define PATH_MAX 4096 -#define NGROUPS_MAX 32 -#define ARG_MAX 131072 -#define IOV_MAX 1024 -#define SYMLOOP_MAX 40 -#define WORD_BIT 32 -#define SSIZE_MAX LONG_MAX -#define TZNAME_MAX 6 -#define TTY_NAME_MAX 32 -#define HOST_NAME_MAX 255 - -#if LONG_MAX == 0x7fffffffL -#define LONG_BIT 32 -#else -#define LONG_BIT 64 -#endif - -/* Implementation choices... */ - -#define PTHREAD_KEYS_MAX 128 -#define PTHREAD_STACK_MIN 2048 -#define PTHREAD_DESTRUCTOR_ITERATIONS 4 -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#define SEM_VALUE_MAX 0x7fffffff -#define SEM_NSEMS_MAX 256 -#endif -#define DELAYTIMER_MAX 0x7fffffff -#ifdef __wasilibc_unmodified_upstream /* WASI has no mq */ -#define MQ_PRIO_MAX 32768 -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no usernames */ -#define LOGIN_NAME_MAX 256 -#endif - -/* Arbitrary numbers... */ - -#ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ -#define BC_BASE_MAX 99 -#define BC_DIM_MAX 2048 -#define BC_SCALE_MAX 99 -#define BC_STRING_MAX 1000 -#endif -#define CHARCLASS_NAME_MAX 14 -#define COLL_WEIGHTS_MAX 2 -#ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ -#define EXPR_NEST_MAX 32 -#define LINE_MAX 4096 -#endif -#define RE_DUP_MAX 255 - -#define NL_ARGMAX 9 -#define NL_MSGMAX 32767 -#define NL_SETMAX 255 -#define NL_TEXTMAX 2048 - -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) - -#ifdef PAGESIZE -#define PAGE_SIZE PAGESIZE -#endif -#define NZERO 20 -#define NL_LANGMAX 32 - -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) - -#define NL_NMAX 16 - -#endif - -/* POSIX/SUS requirements follow. These numbers come directly - * from SUS and have nothing to do with the host system. */ - -#define _POSIX_AIO_LISTIO_MAX 2 -#define _POSIX_AIO_MAX 1 -#define _POSIX_ARG_MAX 4096 -#define _POSIX_CHILD_MAX 25 -#define _POSIX_CLOCKRES_MIN 20000000 -#define _POSIX_DELAYTIMER_MAX 32 -#define _POSIX_HOST_NAME_MAX 255 -#define _POSIX_LINK_MAX 8 -#define _POSIX_LOGIN_NAME_MAX 9 -#define _POSIX_MAX_CANON 255 -#define _POSIX_MAX_INPUT 255 -#define _POSIX_MQ_OPEN_MAX 8 -#define _POSIX_MQ_PRIO_MAX 32 -#define _POSIX_NAME_MAX 14 -#define _POSIX_NGROUPS_MAX 8 -#define _POSIX_OPEN_MAX 20 -#define _POSIX_PATH_MAX 256 -#define _POSIX_PIPE_BUF 512 -#define _POSIX_RE_DUP_MAX 255 -#define _POSIX_RTSIG_MAX 8 -#define _POSIX_SEM_NSEMS_MAX 256 -#define _POSIX_SEM_VALUE_MAX 32767 -#define _POSIX_SIGQUEUE_MAX 32 -#define _POSIX_SSIZE_MAX 32767 -#define _POSIX_STREAM_MAX 8 -#define _POSIX_SS_REPL_MAX 4 -#define _POSIX_SYMLINK_MAX 255 -#define _POSIX_SYMLOOP_MAX 8 -#define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 -#define _POSIX_THREAD_KEYS_MAX 128 -#define _POSIX_THREAD_THREADS_MAX 64 -#define _POSIX_TIMER_MAX 32 -#define _POSIX_TRACE_EVENT_NAME_MAX 30 -#define _POSIX_TRACE_NAME_MAX 8 -#define _POSIX_TRACE_SYS_MAX 8 -#define _POSIX_TRACE_USER_EVENT_MAX 32 -#define _POSIX_TTY_NAME_MAX 9 -#define _POSIX_TZNAME_MAX 6 -#define _POSIX2_BC_BASE_MAX 99 -#define _POSIX2_BC_DIM_MAX 2048 -#define _POSIX2_BC_SCALE_MAX 99 -#define _POSIX2_BC_STRING_MAX 1000 -#define _POSIX2_CHARCLASS_NAME_MAX 14 -#define _POSIX2_COLL_WEIGHTS_MAX 2 -#define _POSIX2_EXPR_NEST_MAX 32 -#define _POSIX2_LINE_MAX 2048 -#define _POSIX2_RE_DUP_MAX 255 - -#define _XOPEN_IOV_MAX 16 -#define _XOPEN_NAME_MAX 255 -#define _XOPEN_PATH_MAX 1024 - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/locale.h b/lib/libc/wasi/libc-top-half/musl/include/locale.h deleted file mode 100644 index 6a62d1f5a7ff1843d59200a0380ea2868117c0b0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/locale.h +++ /dev/null @@ -1,93 +0,0 @@ -#ifndef _LOCALE_H -#define _LOCALE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define LC_CTYPE 0 -#define LC_NUMERIC 1 -#define LC_TIME 2 -#define LC_COLLATE 3 -#define LC_MONETARY 4 -#define LC_MESSAGES 5 -#define LC_ALL 6 - -struct lconv { - char *decimal_point; - char *thousands_sep; - char *grouping; - - char *int_curr_symbol; - char *currency_symbol; - char *mon_decimal_point; - char *mon_thousands_sep; - char *mon_grouping; - char *positive_sign; - char *negative_sign; - char int_frac_digits; - char frac_digits; - char p_cs_precedes; - char p_sep_by_space; - char n_cs_precedes; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_p_cs_precedes; - char int_p_sep_by_space; - char int_n_cs_precedes; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; -}; - - -char *setlocale (int, const char *); -struct lconv *localeconv(void); - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define __NEED_locale_t - -#include - -#define LC_GLOBAL_LOCALE ((locale_t)-1) - -#define LC_CTYPE_MASK (1< -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_size_t - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *malloc (size_t); -void *calloc (size_t, size_t); -void *realloc (void *, size_t); -void free (void *); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -void *valloc (size_t); -void *memalign(size_t, size_t); -#endif - -size_t malloc_usable_size(void *); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/math.h b/lib/libc/wasi/libc-top-half/musl/include/math.h deleted file mode 100644 index 515cc66be0b3ba3297ff84f78bd759406b1486d3..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/math.h +++ /dev/null @@ -1,459 +0,0 @@ -#ifndef _MATH_H -#define _MATH_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_float_t -#define __NEED_double_t -#include - -#if 100*__GNUC__+__GNUC_MINOR__ >= 303 -#define NAN __builtin_nanf("") -#define INFINITY __builtin_inff() -#else -#define NAN (0.0f/0.0f) -#define INFINITY 1e5000f -#endif - -#define HUGE_VALF INFINITY -#define HUGE_VAL ((double)INFINITY) -#define HUGE_VALL ((long double)INFINITY) - -#define MATH_ERRNO 1 -#define MATH_ERREXCEPT 2 -#define math_errhandling 2 - -#define FP_ILOGBNAN (-1-0x7fffffff) -#define FP_ILOGB0 FP_ILOGBNAN - -#define FP_NAN 0 -#define FP_INFINITE 1 -#define FP_ZERO 2 -#define FP_SUBNORMAL 3 -#define FP_NORMAL 4 - -#ifdef __FP_FAST_FMA -#define FP_FAST_FMA 1 -#endif - -#ifdef __FP_FAST_FMAF -#define FP_FAST_FMAF 1 -#endif - -#ifdef __FP_FAST_FMAL -#define FP_FAST_FMAL 1 -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of the fpclassify-like operations */ -int __fpclassify(double); -int __fpclassifyf(float); -int __fpclassifyl(long double); - -static __inline unsigned __FLOAT_BITS(float __f) -{ - union {float __f; unsigned __i;} __u; - __u.__f = __f; - return __u.__i; -} -static __inline unsigned long long __DOUBLE_BITS(double __f) -{ - union {double __f; unsigned long long __i;} __u; - __u.__f = __f; - return __u.__i; -} - -#define fpclassify(x) ( \ - sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ - sizeof(x) == sizeof(double) ? __fpclassify(x) : \ - __fpclassifyl(x) ) - -#define isinf(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ - __fpclassifyl(x) == FP_INFINITE) - -#define isnan(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ - __fpclassifyl(x) == FP_NAN) - -#define isnormal(x) ( \ - sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ - sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ - __fpclassifyl(x) == FP_NORMAL) - -#define isfinite(x) ( \ - sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ - sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ - __fpclassifyl(x) > FP_INFINITE) - -int __signbit(double); -int __signbitf(float); -int __signbitl(long double); - -#define signbit(x) ( \ - sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ - sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ - __signbitl(x) ) - -#define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) - -#define __ISREL_DEF(rel, op, type) \ -static __inline int __is##rel(type __x, type __y) \ -{ return !isunordered(__x,__y) && __x op __y; } - -__ISREL_DEF(lessf, <, float_t) -__ISREL_DEF(less, <, double_t) -__ISREL_DEF(lessl, <, long double) -__ISREL_DEF(lessequalf, <=, float_t) -__ISREL_DEF(lessequal, <=, double_t) -__ISREL_DEF(lessequall, <=, long double) -__ISREL_DEF(lessgreaterf, !=, float_t) -__ISREL_DEF(lessgreater, !=, double_t) -__ISREL_DEF(lessgreaterl, !=, long double) -__ISREL_DEF(greaterf, >, float_t) -__ISREL_DEF(greater, >, double_t) -__ISREL_DEF(greaterl, >, long double) -__ISREL_DEF(greaterequalf, >=, float_t) -__ISREL_DEF(greaterequal, >=, double_t) -__ISREL_DEF(greaterequall, >=, long double) - -#define __tg_pred_2(x, y, p) ( \ - sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ - sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ - p##l(x, y) ) - -#define isless(x, y) __tg_pred_2(x, y, __isless) -#define islessequal(x, y) __tg_pred_2(x, y, __islessequal) -#define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) -#define isgreater(x, y) __tg_pred_2(x, y, __isgreater) -#define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) -#else -#define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, \ - FP_NORMAL, FP_SUBNORMAL, \ - FP_ZERO, x)) -#define isinf(x) (__builtin_isinf(x)) -#define isnan(x) (__builtin_isnan(x)) -#define isnormal(x) (__builtin_isnormal(x)) -#define isfinite(x) (__builtin_isfinite(x)) -#define signbit(x) (__builtin_signbit(x)) -#define isunordered(x, y) (__builtin_isunordered(x, y)) -#define isless(x, y) (__builtin_isless(x, y)) -#define islessequal(x, y) (__builtin_islessequal(x, y)) -#define islessgreater(x, y) (__builtin_islessgreater(x, y)) -#define isgreater(x, y) (__builtin_isgreater(x, y)) -#define isgreaterequal(x, y) (__builtin_isgreaterequal(x, y)) -#endif - -double acos(double); -float acosf(float); -long double acosl(long double); - -double acosh(double); -float acoshf(float); -long double acoshl(long double); - -double asin(double); -float asinf(float); -long double asinl(long double); - -double asinh(double); -float asinhf(float); -long double asinhl(long double); - -double atan(double); -float atanf(float); -long double atanl(long double); - -double atan2(double, double); -float atan2f(float, float); -long double atan2l(long double, long double); - -double atanh(double); -float atanhf(float); -long double atanhl(long double); - -double cbrt(double); -float cbrtf(float); -long double cbrtl(long double); - -double ceil(double); -float ceilf(float); -long double ceill(long double); - -double copysign(double, double); -float copysignf(float, float); -long double copysignl(long double, long double); - -double cos(double); -float cosf(float); -long double cosl(long double); - -double cosh(double); -float coshf(float); -long double coshl(long double); - -double erf(double); -float erff(float); -long double erfl(long double); - -double erfc(double); -float erfcf(float); -long double erfcl(long double); - -double exp(double); -float expf(float); -long double expl(long double); - -double exp2(double); -float exp2f(float); -long double exp2l(long double); - -double expm1(double); -float expm1f(float); -long double expm1l(long double); - -double fabs(double); -float fabsf(float); -long double fabsl(long double); - -double fdim(double, double); -float fdimf(float, float); -long double fdiml(long double, long double); - -double floor(double); -float floorf(float); -long double floorl(long double); - -double fma(double, double, double); -float fmaf(float, float, float); -long double fmal(long double, long double, long double); - -double fmax(double, double); -float fmaxf(float, float); -long double fmaxl(long double, long double); - -double fmin(double, double); -float fminf(float, float); -long double fminl(long double, long double); - -double fmod(double, double); -float fmodf(float, float); -long double fmodl(long double, long double); - -double frexp(double, int *); -float frexpf(float, int *); -long double frexpl(long double, int *); - -double hypot(double, double); -float hypotf(float, float); -long double hypotl(long double, long double); - -int ilogb(double); -int ilogbf(float); -int ilogbl(long double); - -double ldexp(double, int); -float ldexpf(float, int); -long double ldexpl(long double, int); - -double lgamma(double); -float lgammaf(float); -long double lgammal(long double); - -long long llrint(double); -long long llrintf(float); -long long llrintl(long double); - -long long llround(double); -long long llroundf(float); -long long llroundl(long double); - -double log(double); -float logf(float); -long double logl(long double); - -double log10(double); -float log10f(float); -long double log10l(long double); - -double log1p(double); -float log1pf(float); -long double log1pl(long double); - -double log2(double); -float log2f(float); -long double log2l(long double); - -double logb(double); -float logbf(float); -long double logbl(long double); - -long lrint(double); -long lrintf(float); -long lrintl(long double); - -long lround(double); -long lroundf(float); -long lroundl(long double); - -double modf(double, double *); -float modff(float, float *); -long double modfl(long double, long double *); - -double nan(const char *); -float nanf(const char *); -long double nanl(const char *); - -double nearbyint(double); -float nearbyintf(float); -long double nearbyintl(long double); - -double nextafter(double, double); -float nextafterf(float, float); -long double nextafterl(long double, long double); - -double nexttoward(double, long double); -float nexttowardf(float, long double); -long double nexttowardl(long double, long double); - -double pow(double, double); -float powf(float, float); -long double powl(long double, long double); - -double remainder(double, double); -float remainderf(float, float); -long double remainderl(long double, long double); - -double remquo(double, double, int *); -float remquof(float, float, int *); -long double remquol(long double, long double, int *); - -double rint(double); -float rintf(float); -long double rintl(long double); - -double round(double); -float roundf(float); -long double roundl(long double); - -double scalbln(double, long); -float scalblnf(float, long); -long double scalblnl(long double, long); - -double scalbn(double, int); -float scalbnf(float, int); -long double scalbnl(long double, int); - -double sin(double); -float sinf(float); -long double sinl(long double); - -double sinh(double); -float sinhf(float); -long double sinhl(long double); - -double sqrt(double); -float sqrtf(float); -long double sqrtl(long double); - -double tan(double); -float tanf(float); -long double tanl(long double); - -double tanh(double); -float tanhf(float); -long double tanhl(long double); - -double tgamma(double); -float tgammaf(float); -long double tgammal(long double); - -double trunc(double); -float truncf(float); -long double truncl(long double); - - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) -#undef MAXFLOAT -#define MAXFLOAT 3.40282346638528859812e+38F -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define M_E 2.7182818284590452354 /* e */ -#define M_LOG2E 1.4426950408889634074 /* log_2 e */ -#define M_LOG10E 0.43429448190325182765 /* log_10 e */ -#define M_LN2 0.69314718055994530942 /* log_e 2 */ -#define M_LN10 2.30258509299404568402 /* log_e 10 */ -#define M_PI 3.14159265358979323846 /* pi */ -#define M_PI_2 1.57079632679489661923 /* pi/2 */ -#define M_PI_4 0.78539816339744830962 /* pi/4 */ -#define M_1_PI 0.31830988618379067154 /* 1/pi */ -#define M_2_PI 0.63661977236758134308 /* 2/pi */ -#define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ -#define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ -#define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ - -extern int signgam; - -double j0(double); -double j1(double); -double jn(int, double); - -double y0(double); -double y1(double); -double yn(int, double); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define HUGE 3.40282346638528859812e+38F - -double drem(double, double); -float dremf(float, float); - -int finite(double); -int finitef(float); - -double scalb(double, double); -float scalbf(float, float); - -double significand(double); -float significandf(float); - -double lgamma_r(double, int*); -float lgammaf_r(float, int*); - -float j0f(float); -float j1f(float); -float jnf(int, float); - -float y0f(float); -float y1f(float); -float ynf(int, float); -#endif - -#ifdef _GNU_SOURCE -long double lgammal_r(long double, int*); - -void sincos(double, double*, double*); -void sincosf(float, float*, float*); -void sincosl(long double, long double*, long double*); - -double exp10(double); -float exp10f(float); -long double exp10l(long double); - -double pow10(double); -float pow10f(float); -long double pow10l(long double); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/netdb.h b/lib/libc/wasi/libc-top-half/musl/include/netdb.h deleted file mode 100644 index 35a9e0d15e9834b406a7cab5b8fc3c8b887cbde9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/netdb.h +++ /dev/null @@ -1,162 +0,0 @@ -#ifndef _NETDB_H -#define _NETDB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_size_t -#include -#endif - -struct addrinfo { - int ai_flags; - int ai_family; - int ai_socktype; - int ai_protocol; - socklen_t ai_addrlen; - struct sockaddr *ai_addr; - char *ai_canonname; - struct addrinfo *ai_next; -}; - -#define AI_PASSIVE 0x01 -#define AI_CANONNAME 0x02 -#define AI_NUMERICHOST 0x04 -#define AI_V4MAPPED 0x08 -#define AI_ALL 0x10 -#define AI_ADDRCONFIG 0x20 -#define AI_NUMERICSERV 0x400 - - -#define NI_NUMERICHOST 0x01 -#define NI_NUMERICSERV 0x02 -#define NI_NOFQDN 0x04 -#define NI_NAMEREQD 0x08 -#define NI_DGRAM 0x10 -#define NI_NUMERICSCOPE 0x100 - -#define EAI_BADFLAGS -1 -#define EAI_NONAME -2 -#define EAI_AGAIN -3 -#define EAI_FAIL -4 -#define EAI_NODATA -5 -#define EAI_FAMILY -6 -#define EAI_SOCKTYPE -7 -#define EAI_SERVICE -8 -#define EAI_MEMORY -10 -#define EAI_SYSTEM -11 -#define EAI_OVERFLOW -12 - -int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); -void freeaddrinfo (struct addrinfo *); -int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); -const char *gai_strerror(int); - - -/* Legacy functions follow (marked OBsolete in SUS) */ - -struct netent { - char *n_name; - char **n_aliases; - int n_addrtype; - uint32_t n_net; -}; - -struct hostent { - char *h_name; - char **h_aliases; - int h_addrtype; - int h_length; - char **h_addr_list; -}; -#define h_addr h_addr_list[0] - -struct servent { - char *s_name; - char **s_aliases; - int s_port; - char *s_proto; -}; - -struct protoent { - char *p_name; - char **p_aliases; - int p_proto; -}; - -void sethostent (int); -void endhostent (void); -struct hostent *gethostent (void); - -void setnetent (int); -void endnetent (void); -struct netent *getnetent (void); -struct netent *getnetbyaddr (uint32_t, int); -struct netent *getnetbyname (const char *); - -void setservent (int); -void endservent (void); -struct servent *getservent (void); -struct servent *getservbyname (const char *, const char *); -struct servent *getservbyport (int, const char *); - -void setprotoent (int); -void endprotoent (void); -struct protoent *getprotoent (void); -struct protoent *getprotobyname (const char *); -struct protoent *getprotobynumber (int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ - || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -struct hostent *gethostbyname (const char *); -struct hostent *gethostbyaddr (const void *, socklen_t, int); -#ifdef __GNUC__ -__attribute__((const)) -#endif -#ifdef __wasilibc_unmodified_upstream -int *__h_errno_location(void); -#define h_errno (*__h_errno_location()) -#elif (defined __wasilibc_use_wasip2) -extern _Thread_local int h_errno; -#define h_errno h_errno -#endif -#define HOST_NOT_FOUND 1 -#define TRY_AGAIN 2 -#define NO_RECOVERY 3 -#define NO_DATA 4 -#define NO_ADDRESS NO_DATA -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -void herror(const char *); -const char *hstrerror(int); -int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); -int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); -struct hostent *gethostbyname2(const char *, int); -int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); -int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); -int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); -#define EAI_NODATA -5 -#define EAI_ADDRFAMILY -9 -#define EAI_INPROGRESS -100 -#define EAI_CANCELED -101 -#define EAI_NOTCANCELED -102 -#define EAI_ALLDONE -103 -#define EAI_INTR -104 -#define EAI_IDN_ENCODE -105 -#define NI_MAXHOST 255 -#define NI_MAXSERV 32 -#endif - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/netinet/in.h b/lib/libc/wasi/libc-top-half/musl/include/netinet/in.h deleted file mode 100644 index d9422af2ea09c8da87b558c5d7629dc60681c268..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/netinet/in.h +++ /dev/null @@ -1,433 +0,0 @@ -#ifndef _NETINET_IN_H -#define _NETINET_IN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_netinet_in.h> -#endif - -typedef uint16_t in_port_t; -typedef uint32_t in_addr_t; -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct in_addr { in_addr_t s_addr; }; -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr_in { - sa_family_t sin_family; - in_port_t sin_port; - struct in_addr sin_addr; - uint8_t sin_zero[8]; -}; -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct in6_addr { - union { - uint8_t __s6_addr[16]; - uint16_t __s6_addr16[8]; - uint32_t __s6_addr32[4]; - } __in6_union; -}; -#define s6_addr __in6_union.__s6_addr -#define s6_addr16 __in6_union.__s6_addr16 -#define s6_addr32 __in6_union.__s6_addr32 -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr_in6 { - sa_family_t sin6_family; - in_port_t sin6_port; - uint32_t sin6_flowinfo; - struct in6_addr sin6_addr; - uint32_t sin6_scope_id; -}; -#endif - -struct ipv6_mreq { - struct in6_addr ipv6mr_multiaddr; - unsigned ipv6mr_interface; -}; - -#define INADDR_ANY ((in_addr_t) 0x00000000) -#define INADDR_BROADCAST ((in_addr_t) 0xffffffff) -#define INADDR_NONE ((in_addr_t) 0xffffffff) -#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) -#define INADDR_DUMMY ((in_addr_t) 0xc0000008) - -#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) -#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) -#define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) -#define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) -#define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } -#define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } -#endif - -extern const struct in6_addr in6addr_any, in6addr_loopback; - -#define INET_ADDRSTRLEN 16 -#define INET6_ADDRSTRLEN 46 - -uint32_t htonl(uint32_t); -uint16_t htons(uint16_t); -uint32_t ntohl(uint32_t); -uint16_t ntohs(uint16_t); - -#define IPPORT_RESERVED 1024 - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define IPPROTO_IP 0 -#define IPPROTO_HOPOPTS 0 -#define IPPROTO_ICMP 1 -#define IPPROTO_IGMP 2 -#define IPPROTO_IPIP 4 -#define IPPROTO_TCP 6 -#define IPPROTO_EGP 8 -#define IPPROTO_PUP 12 -#define IPPROTO_UDP 17 -#define IPPROTO_IDP 22 -#define IPPROTO_TP 29 -#define IPPROTO_DCCP 33 -#define IPPROTO_IPV6 41 -#define IPPROTO_ROUTING 43 -#define IPPROTO_FRAGMENT 44 -#define IPPROTO_RSVP 46 -#define IPPROTO_GRE 47 -#define IPPROTO_ESP 50 -#define IPPROTO_AH 51 -#define IPPROTO_ICMPV6 58 -#define IPPROTO_NONE 59 -#define IPPROTO_DSTOPTS 60 -#define IPPROTO_MTP 92 -#define IPPROTO_BEETPH 94 -#define IPPROTO_ENCAP 98 -#define IPPROTO_PIM 103 -#define IPPROTO_COMP 108 -#define IPPROTO_SCTP 132 -#define IPPROTO_MH 135 -#define IPPROTO_UDPLITE 136 -#define IPPROTO_MPLS 137 -#define IPPROTO_ETHERNET 143 -#define IPPROTO_RAW 255 -#define IPPROTO_MPTCP 262 -#define IPPROTO_MAX 263 -#endif - -#define IN6_IS_ADDR_UNSPECIFIED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) - -#define IN6_IS_ADDR_LOOPBACK(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && \ - ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ - ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) - -#define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) - -#define IN6_IS_ADDR_LINKLOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) - -#define IN6_IS_ADDR_SITELOCAL(a) \ - ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) - -#define IN6_IS_ADDR_V4MAPPED(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ - ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) - -#define IN6_IS_ADDR_V4COMPAT(a) \ - (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ - ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) - -#define IN6_IS_ADDR_MC_NODELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) - -#define IN6_IS_ADDR_MC_LINKLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) - -#define IN6_IS_ADDR_MC_SITELOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) - -#define IN6_IS_ADDR_MC_ORGLOCAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) - -#define IN6_IS_ADDR_MC_GLOBAL(a) \ - (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) - -#define __ARE_4_EQUAL(a,b) \ - (!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) -#define IN6_ARE_ADDR_EQUAL(a,b) \ - __ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) - -#define IN_CLASSA(a) ((((in_addr_t)(a)) & 0x80000000) == 0) -#define IN_CLASSA_NET 0xff000000 -#define IN_CLASSA_NSHIFT 24 -#define IN_CLASSA_HOST (0xffffffff & ~IN_CLASSA_NET) -#define IN_CLASSA_MAX 128 -#define IN_CLASSB(a) ((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) -#define IN_CLASSB_NET 0xffff0000 -#define IN_CLASSB_NSHIFT 16 -#define IN_CLASSB_HOST (0xffffffff & ~IN_CLASSB_NET) -#define IN_CLASSB_MAX 65536 -#define IN_CLASSC(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) -#define IN_CLASSC_NET 0xffffff00 -#define IN_CLASSC_NSHIFT 8 -#define IN_CLASSC_HOST (0xffffffff & ~IN_CLASSC_NET) -#define IN_CLASSD(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) -#define IN_MULTICAST(a) IN_CLASSD(a) -#define IN_EXPERIMENTAL(a) ((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) -#define IN_BADCLASS(a) ((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) - -#define IN_LOOPBACKNET 127 - - -#define IP_TOS 1 -#define IP_TTL 2 -#define IP_HDRINCL 3 -#define IP_OPTIONS 4 -#define IP_ROUTER_ALERT 5 -#define IP_RECVOPTS 6 -#define IP_RETOPTS 7 -#define IP_PKTINFO 8 -#define IP_PKTOPTIONS 9 -#define IP_PMTUDISC 10 -#define IP_MTU_DISCOVER 10 -#define IP_RECVERR 11 -#define IP_RECVTTL 12 -#define IP_RECVTOS 13 -#define IP_MTU 14 -#define IP_FREEBIND 15 -#define IP_IPSEC_POLICY 16 -#define IP_XFRM_POLICY 17 -#define IP_PASSSEC 18 -#define IP_TRANSPARENT 19 -#define IP_ORIGDSTADDR 20 -#define IP_RECVORIGDSTADDR IP_ORIGDSTADDR -#define IP_MINTTL 21 -#define IP_NODEFRAG 22 -#define IP_CHECKSUM 23 -#define IP_BIND_ADDRESS_NO_PORT 24 -#define IP_RECVFRAGSIZE 25 -#define IP_RECVERR_RFC4884 26 -#define IP_MULTICAST_IF 32 -#define IP_MULTICAST_TTL 33 -#define IP_MULTICAST_LOOP 34 -#define IP_ADD_MEMBERSHIP 35 -#define IP_DROP_MEMBERSHIP 36 -#define IP_UNBLOCK_SOURCE 37 -#define IP_BLOCK_SOURCE 38 -#define IP_ADD_SOURCE_MEMBERSHIP 39 -#define IP_DROP_SOURCE_MEMBERSHIP 40 -#define IP_MSFILTER 41 -#define IP_MULTICAST_ALL 49 -#define IP_UNICAST_IF 50 - -#define IP_RECVRETOPTS IP_RETOPTS - -#define IP_PMTUDISC_DONT 0 -#define IP_PMTUDISC_WANT 1 -#define IP_PMTUDISC_DO 2 -#define IP_PMTUDISC_PROBE 3 -#define IP_PMTUDISC_INTERFACE 4 -#define IP_PMTUDISC_OMIT 5 - -#define IP_DEFAULT_MULTICAST_TTL 1 -#define IP_DEFAULT_MULTICAST_LOOP 1 -#define IP_MAX_MEMBERSHIPS 20 - -struct ip_opts { - struct in_addr ip_dst; - char ip_opts[40]; -}; - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) - -#define MCAST_JOIN_GROUP 42 -#define MCAST_BLOCK_SOURCE 43 -#define MCAST_UNBLOCK_SOURCE 44 -#define MCAST_LEAVE_GROUP 45 -#define MCAST_JOIN_SOURCE_GROUP 46 -#define MCAST_LEAVE_SOURCE_GROUP 47 -#define MCAST_MSFILTER 48 - -#define MCAST_EXCLUDE 0 -#define MCAST_INCLUDE 1 - -struct ip_mreq { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; -}; - -struct ip_mreqn { - struct in_addr imr_multiaddr; - struct in_addr imr_address; - int imr_ifindex; -}; - -struct ip_mreq_source { - struct in_addr imr_multiaddr; - struct in_addr imr_interface; - struct in_addr imr_sourceaddr; -}; - -struct ip_msfilter { - struct in_addr imsf_multiaddr; - struct in_addr imsf_interface; - uint32_t imsf_fmode; - uint32_t imsf_numsrc; - struct in_addr imsf_slist[1]; -}; -#define IP_MSFILTER_SIZE(numsrc) \ - (sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ - + (numsrc) * sizeof(struct in_addr)) - -struct group_req { - uint32_t gr_interface; - struct sockaddr_storage gr_group; -}; - -struct group_source_req { - uint32_t gsr_interface; - struct sockaddr_storage gsr_group; - struct sockaddr_storage gsr_source; -}; - -struct group_filter { - uint32_t gf_interface; - struct sockaddr_storage gf_group; - uint32_t gf_fmode; - uint32_t gf_numsrc; - struct sockaddr_storage gf_slist[1]; -}; -#define GROUP_FILTER_SIZE(numsrc) \ - (sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ - + (numsrc) * sizeof(struct sockaddr_storage)) - -struct in_pktinfo { - int ipi_ifindex; - struct in_addr ipi_spec_dst; - struct in_addr ipi_addr; -}; - -struct in6_pktinfo { - struct in6_addr ipi6_addr; - unsigned ipi6_ifindex; -}; - -struct ip6_mtuinfo { - struct sockaddr_in6 ip6m_addr; - uint32_t ip6m_mtu; -}; -#endif - -#define IPV6_ADDRFORM 1 -#define IPV6_2292PKTINFO 2 -#define IPV6_2292HOPOPTS 3 -#define IPV6_2292DSTOPTS 4 -#define IPV6_2292RTHDR 5 -#define IPV6_2292PKTOPTIONS 6 -#define IPV6_CHECKSUM 7 -#define IPV6_2292HOPLIMIT 8 -#define IPV6_NEXTHOP 9 -#define IPV6_AUTHHDR 10 -#define IPV6_UNICAST_HOPS 16 -#define IPV6_MULTICAST_IF 17 -#define IPV6_MULTICAST_HOPS 18 -#define IPV6_MULTICAST_LOOP 19 -#define IPV6_JOIN_GROUP 20 -#define IPV6_LEAVE_GROUP 21 -#define IPV6_ROUTER_ALERT 22 -#define IPV6_MTU_DISCOVER 23 -#define IPV6_MTU 24 -#define IPV6_RECVERR 25 -#define IPV6_V6ONLY 26 -#define IPV6_JOIN_ANYCAST 27 -#define IPV6_LEAVE_ANYCAST 28 -#define IPV6_MULTICAST_ALL 29 -#define IPV6_ROUTER_ALERT_ISOLATE 30 -#define IPV6_IPSEC_POLICY 34 -#define IPV6_XFRM_POLICY 35 -#define IPV6_HDRINCL 36 - -#define IPV6_RECVPKTINFO 49 -#define IPV6_PKTINFO 50 -#define IPV6_RECVHOPLIMIT 51 -#define IPV6_HOPLIMIT 52 -#define IPV6_RECVHOPOPTS 53 -#define IPV6_HOPOPTS 54 -#define IPV6_RTHDRDSTOPTS 55 -#define IPV6_RECVRTHDR 56 -#define IPV6_RTHDR 57 -#define IPV6_RECVDSTOPTS 58 -#define IPV6_DSTOPTS 59 -#define IPV6_RECVPATHMTU 60 -#define IPV6_PATHMTU 61 -#define IPV6_DONTFRAG 62 -#define IPV6_RECVTCLASS 66 -#define IPV6_TCLASS 67 -#define IPV6_AUTOFLOWLABEL 70 -#define IPV6_ADDR_PREFERENCES 72 -#define IPV6_MINHOPCOUNT 73 -#define IPV6_ORIGDSTADDR 74 -#define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR -#define IPV6_TRANSPARENT 75 -#define IPV6_UNICAST_IF 76 -#define IPV6_RECVFRAGSIZE 77 -#define IPV6_FREEBIND 78 - -#define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP -#define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP -#define IPV6_RXHOPOPTS IPV6_HOPOPTS -#define IPV6_RXDSTOPTS IPV6_DSTOPTS - -#define IPV6_PMTUDISC_DONT 0 -#define IPV6_PMTUDISC_WANT 1 -#define IPV6_PMTUDISC_DO 2 -#define IPV6_PMTUDISC_PROBE 3 -#define IPV6_PMTUDISC_INTERFACE 4 -#define IPV6_PMTUDISC_OMIT 5 - -#define IPV6_PREFER_SRC_TMP 0x0001 -#define IPV6_PREFER_SRC_PUBLIC 0x0002 -#define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 -#define IPV6_PREFER_SRC_COA 0x0004 -#define IPV6_PREFER_SRC_HOME 0x0400 -#define IPV6_PREFER_SRC_CGA 0x0008 -#define IPV6_PREFER_SRC_NONCGA 0x0800 - -#define IPV6_RTHDR_LOOSE 0 -#define IPV6_RTHDR_STRICT 1 - -#define IPV6_RTHDR_TYPE_0 0 - -#define __UAPI_DEF_IN_ADDR 0 -#define __UAPI_DEF_IN_IPPROTO 0 -#define __UAPI_DEF_IN_PKTINFO 0 -#define __UAPI_DEF_IP_MREQ 0 -#define __UAPI_DEF_SOCKADDR_IN 0 -#define __UAPI_DEF_IN_CLASS 0 -#define __UAPI_DEF_IN6_ADDR 0 -#define __UAPI_DEF_IN6_ADDR_ALT 0 -#define __UAPI_DEF_SOCKADDR_IN6 0 -#define __UAPI_DEF_IPV6_MREQ 0 -#define __UAPI_DEF_IPPROTO_V6 0 -#define __UAPI_DEF_IPV6_OPTIONS 0 -#define __UAPI_DEF_IN6_PKTINFO 0 -#define __UAPI_DEF_IP6_MTUINFO 0 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/poll.h b/lib/libc/wasi/libc-top-half/musl/include/poll.h deleted file mode 100644 index 00e2537ae0826f14b2e53c9b93389fb8430bbfd0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/poll.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef _POLL_H -#define _POLL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define POLLIN 0x001 -#define POLLPRI 0x002 -#define POLLOUT 0x004 -#define POLLERR 0x008 -#define POLLHUP 0x010 -#define POLLNVAL 0x020 -#define POLLRDNORM 0x040 -#define POLLRDBAND 0x080 -#ifndef POLLWRNORM -#define POLLWRNORM 0x100 -#define POLLWRBAND 0x200 -#endif -#ifndef POLLMSG -#define POLLMSG 0x400 -#define POLLRDHUP 0x2000 -#endif -#else -#include <__header_poll.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef unsigned long nfds_t; -#else -#include <__typedef_nfds_t.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct pollfd { - int fd; - short events; - short revents; -}; -#else -#include <__struct_pollfd.h> -#endif - -int poll (struct pollfd *, nfds_t, int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_time_t -#define __NEED_struct_timespec -#define __NEED_sigset_t -#include -int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); -#endif - -#if _REDIR_TIME64 -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__REDIR(ppoll, __ppoll_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/pthread.h b/lib/libc/wasi/libc-top-half/musl/include/pthread.h deleted file mode 100644 index 111c1fbf8c1c0c4ec57dddf6409d6f30e92dc2d9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/pthread.h +++ /dev/null @@ -1,267 +0,0 @@ -#ifndef _PTHREAD_H -#define _PTHREAD_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_time_t -#define __NEED_clockid_t -#define __NEED_struct_timespec -#define __NEED_sigset_t -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t -#define __NEED_size_t - -#include - -#include -#include - -#define PTHREAD_CREATE_JOINABLE 0 -#define PTHREAD_CREATE_DETACHED 1 - -#define PTHREAD_MUTEX_NORMAL 0 -#define PTHREAD_MUTEX_DEFAULT 0 -#define PTHREAD_MUTEX_RECURSIVE 1 -#define PTHREAD_MUTEX_ERRORCHECK 2 - -#define PTHREAD_MUTEX_STALLED 0 -#define PTHREAD_MUTEX_ROBUST 1 - -#define PTHREAD_PRIO_NONE 0 -#define PTHREAD_PRIO_INHERIT 1 -#define PTHREAD_PRIO_PROTECT 2 - -#define PTHREAD_INHERIT_SCHED 0 -#define PTHREAD_EXPLICIT_SCHED 1 - -#define PTHREAD_SCOPE_SYSTEM 0 -#define PTHREAD_SCOPE_PROCESS 1 - -#define PTHREAD_PROCESS_PRIVATE 0 -#define PTHREAD_PROCESS_SHARED 1 - - -#define PTHREAD_MUTEX_INITIALIZER {{{0}}} -#define PTHREAD_RWLOCK_INITIALIZER {{{0}}} -#define PTHREAD_COND_INITIALIZER {{{0}}} -#define PTHREAD_ONCE_INIT 0 - - -#define PTHREAD_CANCEL_ENABLE 0 -#define PTHREAD_CANCEL_DISABLE 1 -#define PTHREAD_CANCEL_MASKED 2 - -#define PTHREAD_CANCEL_DEFERRED 0 -#define PTHREAD_CANCEL_ASYNCHRONOUS 1 - -#define PTHREAD_CANCELED ((void *)-1) - - -#define PTHREAD_BARRIER_SERIAL_THREAD (-1) - - -#define PTHREAD_NULL ((pthread_t)0) - - -#ifdef __wasilibc_unmodified_upstream -int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); -int pthread_detach(pthread_t); -_Noreturn void pthread_exit(void *); -int pthread_join(pthread_t, void **); -#else -#if defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); -int pthread_detach(pthread_t); -int pthread_join(pthread_t, void **); -#else -#define pthread_create(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#define pthread_detach(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#define pthread_join(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#endif -#endif - -#ifdef __GNUC__ -__attribute__((const)) -#endif -pthread_t pthread_self(void); - -int pthread_equal(pthread_t, pthread_t); -#ifndef __cplusplus -#define pthread_equal(x,y) ((x)==(y)) -#endif - -int pthread_setcancelstate(int, int *); -int pthread_setcanceltype(int, int *); -void pthread_testcancel(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no cancellation support. */ -int pthread_cancel(pthread_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict); -int pthread_setschedparam(pthread_t, int, const struct sched_param *); -#endif -int pthread_setschedprio(pthread_t, int); - -int pthread_once(pthread_once_t *, void (*)(void)); - -int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict); -int pthread_mutex_lock(pthread_mutex_t *); -int pthread_mutex_unlock(pthread_mutex_t *); -int pthread_mutex_trylock(pthread_mutex_t *); -int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict); -int pthread_mutex_destroy(pthread_mutex_t *); -int pthread_mutex_consistent(pthread_mutex_t *); - -int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict); -int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict); - -int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict); -int pthread_cond_destroy(pthread_cond_t *); -int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict); -int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict); -int pthread_cond_broadcast(pthread_cond_t *); -int pthread_cond_signal(pthread_cond_t *); - -int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict); -int pthread_rwlock_destroy(pthread_rwlock_t *); -int pthread_rwlock_rdlock(pthread_rwlock_t *); -int pthread_rwlock_tryrdlock(pthread_rwlock_t *); -int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); -int pthread_rwlock_wrlock(pthread_rwlock_t *); -int pthread_rwlock_trywrlock(pthread_rwlock_t *); -int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); -int pthread_rwlock_unlock(pthread_rwlock_t *); - -int pthread_spin_init(pthread_spinlock_t *, int); -int pthread_spin_destroy(pthread_spinlock_t *); -int pthread_spin_lock(pthread_spinlock_t *); -int pthread_spin_trylock(pthread_spinlock_t *); -int pthread_spin_unlock(pthread_spinlock_t *); - -int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned); -int pthread_barrier_destroy(pthread_barrier_t *); -int pthread_barrier_wait(pthread_barrier_t *); - -int pthread_key_create(pthread_key_t *, void (*)(void *)); -int pthread_key_delete(pthread_key_t); -void *pthread_getspecific(pthread_key_t); -int pthread_setspecific(pthread_key_t, const void *); - -int pthread_attr_init(pthread_attr_t *); -int pthread_attr_destroy(pthread_attr_t *); - -int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict); -int pthread_attr_setguardsize(pthread_attr_t *, size_t); -int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict); -int pthread_attr_setstacksize(pthread_attr_t *, size_t); -int pthread_attr_getdetachstate(const pthread_attr_t *, int *); -int pthread_attr_setdetachstate(pthread_attr_t *, int); -int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict); -int pthread_attr_setstack(pthread_attr_t *, void *, size_t); -int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict); -int pthread_attr_setscope(pthread_attr_t *, int); -int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict); -int pthread_attr_setschedpolicy(pthread_attr_t *, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict); -int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict); -#endif -int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict); -int pthread_attr_setinheritsched(pthread_attr_t *, int); - -int pthread_mutexattr_destroy(pthread_mutexattr_t *); -int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict); -int pthread_mutexattr_init(pthread_mutexattr_t *); -int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); -int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); -int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); -int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); -int pthread_mutexattr_settype(pthread_mutexattr_t *, int); - -int pthread_condattr_init(pthread_condattr_t *); -int pthread_condattr_destroy(pthread_condattr_t *); -int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); -int pthread_condattr_setpshared(pthread_condattr_t *, int); -int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict); -int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict); - -int pthread_rwlockattr_init(pthread_rwlockattr_t *); -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); -int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); -int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict); - -int pthread_barrierattr_destroy(pthread_barrierattr_t *); -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict); -int pthread_barrierattr_init(pthread_barrierattr_t *); -int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); - -int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); - -int pthread_getconcurrency(void); -int pthread_setconcurrency(int); - -int pthread_getcpuclockid(pthread_t, clockid_t *); - -struct __ptcb { - void (*__f)(void *); - void *__x; - struct __ptcb *__next; -}; - -void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *); -void _pthread_cleanup_pop(struct __ptcb *, int); - -#define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); -#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) - -#ifdef _GNU_SOURCE -struct cpu_set_t; -int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); -int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); -int pthread_getattr_np(pthread_t, pthread_attr_t *); -int pthread_setname_np(pthread_t, const char *); -int pthread_getname_np(pthread_t, char *, size_t); -int pthread_getattr_default_np(pthread_attr_t *); -int pthread_setattr_default_np(const pthread_attr_t *); -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -int pthread_tryjoin_np(pthread_t, void **); -int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); -#else -#define pthread_tryjoin_np(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#define pthread_timedjoin_np(...) ({ _Static_assert(0, "This function is not available on a single-threaded target; switch to a multi-threaded target with -pthread or enable a stub implementation by undefining _WASI_STRICT_PTHREAD"); 0;}) -#endif -#endif - -#if _REDIR_TIME64 -__REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64); -__REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64); -__REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64); -__REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64); -#ifdef _GNU_SOURCE -__REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sched.h b/lib/libc/wasi/libc-top-half/musl/include/sched.h deleted file mode 100644 index 407d604af3bed4b2a67a658239606b2d9414ce16..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sched.h +++ /dev/null @@ -1,152 +0,0 @@ -#ifndef _SCHED_H -#define _SCHED_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_struct_timespec -#define __NEED_pid_t -#define __NEED_time_t - -#ifdef _GNU_SOURCE -#define __NEED_size_t -#endif - -#include - -struct sched_param { - int sched_priority; - int __reserved1; -#if _REDIR_TIME64 - long __reserved2[4]; -#else - struct { - time_t __reserved1; - long __reserved2; - } __reserved2[2]; -#endif - int __reserved3; -}; - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int sched_get_priority_max(int); -int sched_get_priority_min(int); -int sched_getparam(pid_t, struct sched_param *); -int sched_getscheduler(pid_t); -int sched_rr_get_interval(pid_t, struct timespec *); -int sched_setparam(pid_t, const struct sched_param *); -int sched_setscheduler(pid_t, int, const struct sched_param *); -#endif -int sched_yield(void); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 -#define SCHED_BATCH 3 -#define SCHED_IDLE 5 -#define SCHED_DEADLINE 6 -#define SCHED_RESET_ON_FORK 0x40000000 - -#ifdef _GNU_SOURCE -#define CSIGNAL 0x000000ff -#define CLONE_NEWTIME 0x00000080 -#define CLONE_VM 0x00000100 -#define CLONE_FS 0x00000200 -#define CLONE_FILES 0x00000400 -#define CLONE_SIGHAND 0x00000800 -#define CLONE_PIDFD 0x00001000 -#define CLONE_PTRACE 0x00002000 -#define CLONE_VFORK 0x00004000 -#define CLONE_PARENT 0x00008000 -#define CLONE_THREAD 0x00010000 -#define CLONE_NEWNS 0x00020000 -#define CLONE_SYSVSEM 0x00040000 -#define CLONE_SETTLS 0x00080000 -#define CLONE_PARENT_SETTID 0x00100000 -#define CLONE_CHILD_CLEARTID 0x00200000 -#define CLONE_DETACHED 0x00400000 -#define CLONE_UNTRACED 0x00800000 -#define CLONE_CHILD_SETTID 0x01000000 -#define CLONE_NEWCGROUP 0x02000000 -#define CLONE_NEWUTS 0x04000000 -#define CLONE_NEWIPC 0x08000000 -#define CLONE_NEWUSER 0x10000000 -#define CLONE_NEWPID 0x20000000 -#define CLONE_NEWNET 0x40000000 -#define CLONE_IO 0x80000000 -int clone (int (*)(void *), void *, int, void *, ...); -int unshare(int); -int setns(int, int); - -void *memcpy(void *__restrict, const void *__restrict, size_t); -int memcmp(const void *, const void *, size_t); -void *memset (void *, int, size_t); -void *calloc(size_t, size_t); -void free(void *); - -typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; -int __sched_cpucount(size_t, const cpu_set_t *); -int sched_getcpu(void); -int sched_getaffinity(pid_t, size_t, cpu_set_t *); -int sched_setaffinity(pid_t, size_t, const cpu_set_t *); - -#define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ - (((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) - -#define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) -#define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) -#define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) - -#define __CPU_op_func_S(func, op) \ -static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ - const cpu_set_t *__src1, const cpu_set_t *__src2) \ -{ \ - size_t __i; \ - for (__i=0; __i<__size/sizeof(long); __i++) \ - ((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ - op ((unsigned long *)__src2)[__i] ; \ -} - -__CPU_op_func_S(AND, &) -__CPU_op_func_S(OR, |) -__CPU_op_func_S(XOR, ^) - -#define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) -#define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) -#define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) - -#define CPU_COUNT_S(size,set) __sched_cpucount(size,set) -#define CPU_ZERO_S(size,set) memset(set,0,size) -#define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) - -#define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ - + ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) -#define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) -#define CPU_FREE(set) free(set) - -#define CPU_SETSIZE 1024 - -#define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) -#define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) -#define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) -#define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) -#define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) -#define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) -#define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) -#define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) -#define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) - -#endif -#endif - -#if _REDIR_TIME64 -__REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/setjmp.h b/lib/libc/wasi/libc-top-half/musl/include/setjmp.h deleted file mode 100644 index b57999ed61e8752f340e0896bdeb19627eb4aabc..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/setjmp.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef _SETJMP_H -#define _SETJMP_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifndef __wasilibc_unmodified_upstream -/* WASI has no setjmp */ -#if !defined(__wasm_exception_handling__) -#error Setjmp/longjmp support requires Exception handling support, which is [not yet standardized](https://github.com/WebAssembly/proposals?tab=readme-ov-file#phase-3---implementation-phase-cg--wg). To enable it, compile with `-mllvm -wasm-enable-sjlj` and use an engine that implements the Exception handling proposal. -#endif -#endif -#include - -typedef struct __jmp_buf_tag { - __jmp_buf __jb; - unsigned long __fl; - unsigned long __ss[128/sizeof(long)]; -} jmp_buf[1]; - -#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) -#define __setjmp_attr __attribute__((__returns_twice__)) -#else -#define __setjmp_attr -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -typedef jmp_buf sigjmp_buf; -int sigsetjmp (sigjmp_buf, int) __setjmp_attr; -_Noreturn void siglongjmp (sigjmp_buf, int); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -int _setjmp (jmp_buf) __setjmp_attr; -_Noreturn void _longjmp (jmp_buf, int); -#endif - -int setjmp (jmp_buf) __setjmp_attr; -_Noreturn void longjmp (jmp_buf, int); - -#define setjmp setjmp - -#undef __setjmp_attr - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/signal.h b/lib/libc/wasi/libc-top-half/musl/include/signal.h deleted file mode 100644 index 75b5e55284f56a4b1ee4d2a32faee77830858265..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/signal.h +++ /dev/null @@ -1,339 +0,0 @@ -#ifndef _WASI_EMULATED_SIGNAL -#error "wasm lacks signal support; to enable minimal signal emulation, \ -compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal" -#else -#ifndef _SIGNAL_H -#define _SIGNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef __wasilibc_unmodified_upstream /* WASI has no ucontext support */ -#ifdef _GNU_SOURCE -#define __ucontext ucontext -#endif - -#define __NEED_size_t -#define __NEED_pid_t -#define __NEED_uid_t -#define __NEED_struct_timespec -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_sigset_t - -#include - -#define SIG_BLOCK 0 -#define SIG_UNBLOCK 1 -#define SIG_SETMASK 2 - -#define SI_ASYNCNL (-60) -#define SI_TKILL (-6) -#define SI_SIGIO (-5) -#define SI_ASYNCIO (-4) -#define SI_MESGQ (-3) -#define SI_TIMER (-2) -#define SI_QUEUE (-1) -#define SI_USER 0 -#define SI_KERNEL 128 - -typedef struct sigaltstack stack_t; -#endif - -#endif - -#include - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ -#define SIG_HOLD ((void (*)(int)) 2) - -#define FPE_INTDIV 1 -#define FPE_INTOVF 2 -#define FPE_FLTDIV 3 -#define FPE_FLTOVF 4 -#define FPE_FLTUND 5 -#define FPE_FLTRES 6 -#define FPE_FLTINV 7 -#define FPE_FLTSUB 8 - -#define ILL_ILLOPC 1 -#define ILL_ILLOPN 2 -#define ILL_ILLADR 3 -#define ILL_ILLTRP 4 -#define ILL_PRVOPC 5 -#define ILL_PRVREG 6 -#define ILL_COPROC 7 -#define ILL_BADSTK 8 - -#define SEGV_MAPERR 1 -#define SEGV_ACCERR 2 -#define SEGV_BNDERR 3 -#define SEGV_PKUERR 4 -#define SEGV_MTEAERR 8 -#define SEGV_MTESERR 9 - -#define BUS_ADRALN 1 -#define BUS_ADRERR 2 -#define BUS_OBJERR 3 -#define BUS_MCEERR_AR 4 -#define BUS_MCEERR_AO 5 - -#define CLD_EXITED 1 -#define CLD_KILLED 2 -#define CLD_DUMPED 3 -#define CLD_TRAPPED 4 -#define CLD_STOPPED 5 -#define CLD_CONTINUED 6 - -union sigval { - int sival_int; - void *sival_ptr; -}; - -typedef struct { -#ifdef __SI_SWAP_ERRNO_CODE - int si_signo, si_code, si_errno; -#else - int si_signo, si_errno, si_code; -#endif - union { - char __pad[128 - 2*sizeof(int) - sizeof(long)]; - struct { - union { - struct { - pid_t si_pid; - uid_t si_uid; - } __piduid; - struct { - int si_timerid; - int si_overrun; - } __timer; - } __first; - union { - union sigval si_value; - struct { - int si_status; - clock_t si_utime, si_stime; - } __sigchld; - } __second; - } __si_common; - struct { - void *si_addr; - short si_addr_lsb; - union { - struct { - void *si_lower; - void *si_upper; - } __addr_bnd; - unsigned si_pkey; - } __first; - } __sigfault; - struct { - long si_band; - int si_fd; - } __sigpoll; - struct { - void *si_call_addr; - int si_syscall; - unsigned si_arch; - } __sigsys; - } __si_fields; -} siginfo_t; -#define si_pid __si_fields.__si_common.__first.__piduid.si_pid -#define si_uid __si_fields.__si_common.__first.__piduid.si_uid -#define si_status __si_fields.__si_common.__second.__sigchld.si_status -#define si_utime __si_fields.__si_common.__second.__sigchld.si_utime -#define si_stime __si_fields.__si_common.__second.__sigchld.si_stime -#define si_value __si_fields.__si_common.__second.si_value -#define si_addr __si_fields.__sigfault.si_addr -#define si_addr_lsb __si_fields.__sigfault.si_addr_lsb -#define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower -#define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper -#define si_pkey __si_fields.__sigfault.__first.si_pkey -#define si_band __si_fields.__sigpoll.si_band -#define si_fd __si_fields.__sigpoll.si_fd -#define si_timerid __si_fields.__si_common.__first.__timer.si_timerid -#define si_overrun __si_fields.__si_common.__first.__timer.si_overrun -#define si_ptr si_value.sival_ptr -#define si_int si_value.sival_int -#define si_call_addr __si_fields.__sigsys.si_call_addr -#define si_syscall __si_fields.__sigsys.si_syscall -#define si_arch __si_fields.__sigsys.si_arch - -struct sigaction { - union { - void (*sa_handler)(int); - void (*sa_sigaction)(int, siginfo_t *, void *); - } __sa_handler; - sigset_t sa_mask; - int sa_flags; - void (*sa_restorer)(void); -}; -#define sa_handler __sa_handler.sa_handler -#define sa_sigaction __sa_handler.sa_sigaction - -#define SA_UNSUPPORTED 0x00000400 -#define SA_EXPOSE_TAGBITS 0x00000800 - -struct sigevent { - union sigval sigev_value; - int sigev_signo; - int sigev_notify; - union { - char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; - pid_t sigev_notify_thread_id; - struct { - void (*sigev_notify_function)(union sigval); - pthread_attr_t *sigev_notify_attributes; - } __sev_thread; - } __sev_fields; -}; - -#define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id -#define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function -#define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes - -#define SIGEV_SIGNAL 0 -#define SIGEV_NONE 1 -#define SIGEV_THREAD 2 -#define SIGEV_THREAD_ID 4 -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ -int __libc_current_sigrtmin(void); -int __libc_current_sigrtmax(void); - -#define SIGRTMIN (__libc_current_sigrtmin()) -#define SIGRTMAX (__libc_current_sigrtmax()) -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ -int kill(pid_t, int); - -int sigemptyset(sigset_t *); -int sigfillset(sigset_t *); -int sigaddset(sigset_t *, int); -int sigdelset(sigset_t *, int); -int sigismember(const sigset_t *, int); - -int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); -int sigsuspend(const sigset_t *); -int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); -int sigpending(sigset_t *); -int sigwait(const sigset_t *__restrict, int *__restrict); -int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); -int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); -int sigqueue(pid_t, int, union sigval); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ -int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); -int pthread_kill(pthread_t, int); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ -void psiginfo(const siginfo_t *, const char *); -#endif -void psignal(int, const char *); - -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -int killpg(pid_t, int); -int sigaltstack(const stack_t *__restrict, stack_t *__restrict); -int sighold(int); -int sigignore(int); -int siginterrupt(int, int); -int sigpause(int); -int sigrelse(int); -void (*sigset(int, void (*)(int)))(int); -#define TRAP_BRKPT 1 -#define TRAP_TRACE 2 -#define TRAP_BRANCH 3 -#define TRAP_HWBKPT 4 -#define TRAP_UNK 5 -#define POLL_IN 1 -#define POLL_OUT 2 -#define POLL_MSG 3 -#define POLL_ERR 4 -#define POLL_PRI 5 -#define POLL_HUP 6 -#define SS_ONSTACK 1 -#define SS_DISABLE 2 -#define SS_AUTODISARM (1U << 31) -#define SS_FLAG_BITS SS_AUTODISARM -#endif -#endif - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define NSIG _NSIG -typedef void (*sig_t)(int); - -#define SYS_SECCOMP 1 -#define SYS_USER_DISPATCH 2 -#endif - -#ifdef _GNU_SOURCE -typedef void (*sighandler_t)(int); -void (*bsd_signal(int, void (*)(int)))(int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ -int sigisemptyset(const sigset_t *); -int sigorset (sigset_t *, const sigset_t *, const sigset_t *); -int sigandset(sigset_t *, const sigset_t *, const sigset_t *); - -#define SA_NOMASK SA_NODEFER -#define SA_ONESHOT SA_RESETHAND -#endif -#endif - -#ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ -#define SIG_ERR ((void (*)(int))-1) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN ((void (*)(int)) 1) -#else -void __SIG_ERR(int); -void __SIG_IGN(int); -#define SIG_ERR (__SIG_ERR) -#define SIG_DFL ((void (*)(int)) 0) -#define SIG_IGN (__SIG_IGN) -#endif - -#ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ -typedef int sig_atomic_t; -#else -typedef long sig_atomic_t; -#endif - -void (*signal(int, void (*)(int)))(int); -int raise(int); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ -#if _REDIR_TIME64 -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -__REDIR(sigtimedwait, __sigtimedwait_time64); -#endif -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/stdio.h b/lib/libc/wasi/libc-top-half/musl/include/stdio.h deleted file mode 100644 index d63d739f0ff0ae3333bf3aac972bf80faad9a104..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/stdio.h +++ /dev/null @@ -1,254 +0,0 @@ -#ifndef _STDIO_H -#define _STDIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_FILE -#define __NEED___isoc_va_list -#define __NEED_size_t - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#if __STDC_VERSION__ < 201112L -#define __NEED_struct__IO_FILE -#endif -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_ssize_t -#define __NEED_off_t -#define __NEED_va_list -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#undef EOF -#define EOF (-1) - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#undef SEEK_SET -#undef SEEK_CUR -#undef SEEK_END -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#else -#include <__seek.h> -#endif - -#define _IOFBF 0 -#define _IOLBF 1 -#define _IONBF 2 - -#define BUFSIZ 1024 -#define FILENAME_MAX 4096 -#define FOPEN_MAX 1000 -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#define TMP_MAX 10000 -#define L_tmpnam 20 -#endif - -typedef union _G_fpos64_t { - char __opaque[16]; - long long __lldata; - double __align; -} fpos_t; - -extern FILE *const stdin; -extern FILE *const stdout; -extern FILE *const stderr; - -#define stdin (stdin) -#define stdout (stdout) -#define stderr (stderr) - -FILE *fopen(const char *__restrict, const char *__restrict); -FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); -int fclose(FILE *); - -int remove(const char *); -int rename(const char *, const char *); - -int feof(FILE *); -int ferror(FILE *); -int fflush(FILE *); -void clearerr(FILE *); - -int fseek(FILE *, long, int); -long ftell(FILE *); -void rewind(FILE *); - -int fgetpos(FILE *__restrict, fpos_t *__restrict); -int fsetpos(FILE *, const fpos_t *); - -size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); -size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); - -int fgetc(FILE *); -int getc(FILE *); -int getchar(void); -int ungetc(int, FILE *); - -int fputc(int, FILE *); -int putc(int, FILE *); -int putchar(int); - -char *fgets(char *__restrict, int, FILE *__restrict); -#if __STDC_VERSION__ < 201112L -#ifdef __wasilibc_unmodified_upstream /* gets is obsolete */ -char *gets(char *); -#else -char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI"))); -#endif -#endif - -int fputs(const char *__restrict, FILE *__restrict); -int puts(const char *); - -int printf(const char *__restrict, ...); -int fprintf(FILE *__restrict, const char *__restrict, ...); -int sprintf(char *__restrict, const char *__restrict, ...); -int snprintf(char *__restrict, size_t, const char *__restrict, ...); - -int vprintf(const char *__restrict, __isoc_va_list); -int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); -int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); -int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); - -int scanf(const char *__restrict, ...); -int fscanf(FILE *__restrict, const char *__restrict, ...); -int sscanf(const char *__restrict, const char *__restrict, ...); -int vscanf(const char *__restrict, __isoc_va_list); -int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); -int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); - -void perror(const char *); - -int setvbuf(FILE *__restrict, char *__restrict, int, size_t); -void setbuf(FILE *__restrict, char *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -char *tmpnam(char *); -FILE *tmpfile(void); -#else -char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI"))); -FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI"))); -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -FILE *fmemopen(void *__restrict, size_t, const char *__restrict); -FILE *open_memstream(char **, size_t *); -FILE *fdopen(int, const char *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no popen */ -FILE *popen(const char *, const char *); -int pclose(FILE *); -#endif -int fileno(FILE *); -int fseeko(FILE *, off_t, int); -off_t ftello(FILE *); -int dprintf(int, const char *__restrict, ...); -int vdprintf(int, const char *__restrict, __isoc_va_list); -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -void flockfile(FILE *); -int ftrylockfile(FILE *); -void funlockfile(FILE *); -#endif -int getc_unlocked(FILE *); -int getchar_unlocked(void); -int putc_unlocked(int, FILE *); -int putchar_unlocked(int); -ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); -ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); -int renameat(int, const char *, int, const char *); -char *ctermid(char *); -#define L_ctermid 20 -#endif - - -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define P_tmpdir "/tmp" -char *tempnam(const char *, const char *); -#endif -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define L_cuserid 20 -char *cuserid(char *); -void setlinebuf(FILE *); -void setbuffer(FILE *, char *, size_t); -int fgetc_unlocked(FILE *); -int fputc_unlocked(int, FILE *); -int fflush_unlocked(FILE *); -size_t fread_unlocked(void *, size_t, size_t, FILE *); -size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); -void clearerr_unlocked(FILE *); -int feof_unlocked(FILE *); -int ferror_unlocked(FILE *); -int fileno_unlocked(FILE *); -int getw(FILE *); -int putw(int, FILE *); -char *fgetln(FILE *, size_t *); -int asprintf(char **, const char *, ...); -int vasprintf(char **, const char *, __isoc_va_list); -#endif - -#ifdef _GNU_SOURCE -char *fgets_unlocked(char *, int, FILE *); -int fputs_unlocked(const char *, FILE *); - -typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); -typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); -typedef int (cookie_seek_function_t)(void *, off_t *, int); -typedef int (cookie_close_function_t)(void *); - -typedef struct _IO_cookie_io_functions_t { - cookie_read_function_t *read; - cookie_write_function_t *write; - cookie_seek_function_t *seek; - cookie_close_function_t *close; -} cookie_io_functions_t; - -FILE *fopencookie(void *, const char *, cookie_io_functions_t); -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#define tmpfile64 tmpfile -#endif -#define fopen64 fopen -#define freopen64 freopen -#define fseeko64 fseeko -#define ftello64 ftello -#define fgetpos64 fgetpos -#define fsetpos64 fsetpos -#define fpos64_t fpos_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/stdlib.h b/lib/libc/wasi/libc-top-half/musl/include/stdlib.h deleted file mode 100644 index c5b6cd2d980a058b613cd90f9fecc9ff7c0fd8c7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/stdlib.h +++ /dev/null @@ -1,217 +0,0 @@ -#ifndef _STDLIB_H -#define _STDLIB_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__functions_malloc.h> -#include <__header_stdlib.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define __NEED_size_t -#define __NEED_wchar_t - -#include - -int atoi (const char *); -long atol (const char *); -long long atoll (const char *); -double atof (const char *); - -float strtof (const char *__restrict, char **__restrict); -double strtod (const char *__restrict, char **__restrict); -long double strtold (const char *__restrict, char **__restrict); - -long strtol (const char *__restrict, char **__restrict, int); -unsigned long strtoul (const char *__restrict, char **__restrict, int); -long long strtoll (const char *__restrict, char **__restrict, int); -unsigned long long strtoull (const char *__restrict, char **__restrict, int); - -int rand (void); -void srand (unsigned); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *malloc (size_t); -void *calloc (size_t, size_t); -void *realloc (void *, size_t); -void free (void *); -#endif -void *aligned_alloc(size_t, size_t); - -_Noreturn void abort (void); -int atexit (void (*) (void)); -_Noreturn void exit (int); -_Noreturn void _Exit (int); -int at_quick_exit (void (*) (void)); -_Noreturn void quick_exit (int); - -char *getenv (const char *); - -int system (const char *); - -void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); -void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); - -int abs (int); -long labs (long); -long long llabs (long long); - -typedef struct { int quot, rem; } div_t; -typedef struct { long quot, rem; } ldiv_t; -typedef struct { long long quot, rem; } lldiv_t; - -div_t div (int, int); -ldiv_t ldiv (long, long); -lldiv_t lldiv (long long, long long); - -int mblen (const char *, size_t); -int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); -int wctomb (char *, wchar_t); -size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); -size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); - -#define EXIT_FAILURE 1 -#define EXIT_SUCCESS 0 - -size_t __ctype_get_mb_cur_max(void); -#define MB_CUR_MAX (__ctype_get_mb_cur_max()) - -#define RAND_MAX (0x7fffffff) - - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ -#define WNOHANG 1 -#define WUNTRACED 2 - -#define WEXITSTATUS(s) (((s) & 0xff00) >> 8) -#define WTERMSIG(s) ((s) & 0x7f) -#define WSTOPSIG(s) WEXITSTATUS(s) -#define WIFEXITED(s) (!WTERMSIG(s)) -#define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00) -#define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) -#endif - -int posix_memalign (void **, size_t, size_t); -int setenv (const char *, const char *, int); -int unsetenv (const char *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -int mkstemp (char *); -int mkostemp (char *, int); -char *mkdtemp (char *); -#endif -int getsubopt (char **, char *const *, char **); -int rand_r (unsigned *); - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *realpath (const char *__restrict, char *__restrict); -long int random (void); -void srandom (unsigned int); -char *initstate (unsigned int, char *, size_t); -char *setstate (char *); -int putenv (char *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ -int posix_openpt (int); -int grantpt (int); -int unlockpt (int); -char *ptsname (int); -#endif -char *l64a (long); -long a64l (const char *); -void setkey (const char *); -double drand48 (void); -double erand48 (unsigned short [3]); -long int lrand48 (void); -long int nrand48 (unsigned short [3]); -long mrand48 (void); -long jrand48 (unsigned short [3]); -void srand48 (long); -unsigned short *seed48 (unsigned short [3]); -void lcong48 (unsigned short [7]); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#include -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -char *mktemp (char *); -int mkstemps (char *, int); -int mkostemps (char *, int, int); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -void *valloc (size_t); -void *memalign(size_t, size_t); -int getloadavg(double *, int); -#endif -int clearenv(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ -#define WCOREDUMP(s) ((s) & 0x80) -#define WIFCONTINUED(s) ((s) == 0xffff) -void *reallocarray (void *, size_t, size_t); -void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); -#endif -#endif - -#ifdef _GNU_SOURCE -#ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ -int ptsname_r(int, char *, size_t); -#endif -char *ecvt(double, int, int *, int *); -char *fcvt(double, int, int *, int *); -char *gcvt(double, int, char *); -char *secure_getenv(const char *); -struct __locale_struct; -float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); -double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); -long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ -#if defined(_LARGEFILE64_SOURCE) -#define mkstemp64 mkstemp -#define mkostemp64 mkostemp -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define mkstemps64 mkstemps -#define mkostemps64 mkostemps -#endif -#endif -#endif - -#ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */ -#else -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#include -uint32_t arc4random(void); -void arc4random_buf(void *, size_t); -uint32_t arc4random_uniform(uint32_t); -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/string.h b/lib/libc/wasi/libc-top-half/musl/include/string.h deleted file mode 100644 index 7b3c3b9415f23a733fbe5d9632a915e7e6d9e17b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/string.h +++ /dev/null @@ -1,123 +0,0 @@ -#ifndef _STRING_H -#define _STRING_H - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_string.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define __NEED_size_t -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_locale_t -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *memcpy (void *__restrict, const void *__restrict, size_t); -void *memmove (void *, const void *, size_t); -void *memset (void *, int, size_t); -#endif -int memcmp (const void *, const void *, size_t); -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -void *memchr (const void *, int, size_t); -#endif - -char *strcpy (char *__restrict, const char *__restrict); -char *strncpy (char *__restrict, const char *__restrict, size_t); - -char *strcat (char *__restrict, const char *__restrict); -char *strncat (char *__restrict, const char *__restrict, size_t); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -int strcmp (const char *, const char *); -#endif -int strncmp (const char *, const char *, size_t); - -int strcoll (const char *, const char *); -size_t strxfrm (char *__restrict, const char *__restrict, size_t); - -char *strchr (const char *, int); -char *strrchr (const char *, int); - -size_t strcspn (const char *, const char *); -size_t strspn (const char *, const char *); -char *strpbrk (const char *, const char *); -char *strstr (const char *, const char *); -char *strtok (char *__restrict, const char *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -size_t strlen (const char *); -#endif - -char *strerror (int); - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#include -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); -int strerror_r (int, char *, size_t); -char *stpcpy(char *__restrict, const char *__restrict); -char *stpncpy(char *__restrict, const char *__restrict, size_t); -size_t strnlen (const char *, size_t); -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -char *strdup (const char *); -#endif -char *strndup (const char *, size_t); -char *strsignal(int); -char *strerror_l (int, locale_t); -int strcoll_l (const char *, const char *, locale_t); -size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); -void *memmem(const void *, size_t, const void *, size_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -void *memccpy (void *__restrict, const void *__restrict, int, size_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -char *strsep(char **, const char *); -size_t strlcat (char *, const char *, size_t); -size_t strlcpy (char *, const char *, size_t); -void explicit_bzero (void *, size_t); -#endif - -#ifdef _GNU_SOURCE -#define strdupa(x) strcpy(alloca(strlen(x)+1),x) -int strverscmp (const char *, const char *); -char *strchrnul(const char *, int); -char *strcasestr(const char *, const char *); -void *memrchr(const void *, int, size_t); -void *mempcpy(void *, const void *, size_t); -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/ioctl.h b/lib/libc/wasi/libc-top-half/musl/include/sys/ioctl.h deleted file mode 100644 index cf3acb3ad842af6b30b01ebb74b1c8a6b2ac8596..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/ioctl.h +++ /dev/null @@ -1,124 +0,0 @@ -#ifndef _SYS_IOCTL_H -#define _SYS_IOCTL_H -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_struct_winsize - -#include -#include - -#define N_TTY 0 -#define N_SLIP 1 -#define N_MOUSE 2 -#define N_PPP 3 -#define N_STRIP 4 -#define N_AX25 5 -#define N_X25 6 -#define N_6PACK 7 -#define N_MASC 8 -#define N_R3964 9 -#define N_PROFIBUS_FDL 10 -#define N_IRDA 11 -#define N_SMSBLOCK 12 -#define N_HDLC 13 -#define N_SYNC_PPP 14 -#define N_HCI 15 -#define N_GIGASET_M101 16 -#define N_SLCAN 17 -#define N_PPS 18 -#define N_V253 19 -#define N_CAIF 20 -#define N_GSM0710 21 -#define N_TI_WL 22 -#define N_TRACESINK 23 -#define N_TRACEROUTER 24 -#define N_NCI 25 -#define N_SPEAKUP 26 -#define N_NULL 27 - -#define TIOCPKT_DATA 0 -#define TIOCPKT_FLUSHREAD 1 -#define TIOCPKT_FLUSHWRITE 2 -#define TIOCPKT_STOP 4 -#define TIOCPKT_START 8 -#define TIOCPKT_NOSTOP 16 -#define TIOCPKT_DOSTOP 32 -#define TIOCPKT_IOCTL 64 - -#define TIOCSER_TEMT 1 - -#define SIOCADDRT 0x890B -#define SIOCDELRT 0x890C -#define SIOCRTMSG 0x890D - -#define SIOCGIFNAME 0x8910 -#define SIOCSIFLINK 0x8911 -#define SIOCGIFCONF 0x8912 -#define SIOCGIFFLAGS 0x8913 -#define SIOCSIFFLAGS 0x8914 -#define SIOCGIFADDR 0x8915 -#define SIOCSIFADDR 0x8916 -#define SIOCGIFDSTADDR 0x8917 -#define SIOCSIFDSTADDR 0x8918 -#define SIOCGIFBRDADDR 0x8919 -#define SIOCSIFBRDADDR 0x891a -#define SIOCGIFNETMASK 0x891b -#define SIOCSIFNETMASK 0x891c -#define SIOCGIFMETRIC 0x891d -#define SIOCSIFMETRIC 0x891e -#define SIOCGIFMEM 0x891f -#define SIOCSIFMEM 0x8920 -#define SIOCGIFMTU 0x8921 -#define SIOCSIFMTU 0x8922 -#define SIOCSIFNAME 0x8923 -#define SIOCSIFHWADDR 0x8924 -#define SIOCGIFENCAP 0x8925 -#define SIOCSIFENCAP 0x8926 -#define SIOCGIFHWADDR 0x8927 -#define SIOCGIFSLAVE 0x8929 -#define SIOCSIFSLAVE 0x8930 -#define SIOCADDMULTI 0x8931 -#define SIOCDELMULTI 0x8932 -#define SIOCGIFINDEX 0x8933 -#define SIOGIFINDEX SIOCGIFINDEX -#define SIOCSIFPFLAGS 0x8934 -#define SIOCGIFPFLAGS 0x8935 -#define SIOCDIFADDR 0x8936 -#define SIOCSIFHWBROADCAST 0x8937 -#define SIOCGIFCOUNT 0x8938 - -#define SIOCGIFBR 0x8940 -#define SIOCSIFBR 0x8941 - -#define SIOCGIFTXQLEN 0x8942 -#define SIOCSIFTXQLEN 0x8943 - -#define SIOCDARP 0x8953 -#define SIOCGARP 0x8954 -#define SIOCSARP 0x8955 - -#define SIOCDRARP 0x8960 -#define SIOCGRARP 0x8961 -#define SIOCSRARP 0x8962 - -#define SIOCGIFMAP 0x8970 -#define SIOCSIFMAP 0x8971 - -#define SIOCADDDLCI 0x8980 -#define SIOCDELDLCI 0x8981 - -#define SIOCDEVPRIVATE 0x89F0 -#define SIOCPROTOPRIVATE 0x89E0 - -int ioctl (int, int, ...); - -#ifdef __cplusplus -} -#endif -#else -#include <__header_sys_ioctl.h> -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/mman.h b/lib/libc/wasi/libc-top-half/musl/include/sys/mman.h deleted file mode 100644 index 335ba2d714be677a29df7bb53bddd5acd4c37131..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/mman.h +++ /dev/null @@ -1,157 +0,0 @@ -#ifndef _WASI_EMULATED_MMAN -#error "WASI lacks a true mmap; to enable minimal mmap emulation, \ -compile with -D_WASI_EMULATED_MMAN and link with -lwasi-emulated-mman" -#else -#ifndef _SYS_MMAN_H -#define _SYS_MMAN_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_mode_t -#define __NEED_size_t -#define __NEED_off_t - -#if defined(_GNU_SOURCE) -#define __NEED_ssize_t -#endif - -#include - -#define MAP_FAILED ((void *) -1) - -#define MAP_SHARED 0x01 -#define MAP_PRIVATE 0x02 -#define MAP_SHARED_VALIDATE 0x03 -#define MAP_TYPE 0x0f -#define MAP_FIXED 0x10 -#define MAP_ANON 0x20 -#define MAP_ANONYMOUS MAP_ANON -#define MAP_NORESERVE 0x4000 -#define MAP_GROWSDOWN 0x0100 -#define MAP_DENYWRITE 0x0800 -#define MAP_EXECUTABLE 0x1000 -#define MAP_LOCKED 0x2000 -#define MAP_POPULATE 0x8000 -#define MAP_NONBLOCK 0x10000 -#define MAP_STACK 0x20000 -#define MAP_HUGETLB 0x40000 -#define MAP_SYNC 0x80000 -#define MAP_FIXED_NOREPLACE 0x100000 -#define MAP_FILE 0 - -#define MAP_HUGE_SHIFT 26 -#define MAP_HUGE_MASK 0x3f -#define MAP_HUGE_16KB (14 << 26) -#define MAP_HUGE_64KB (16 << 26) -#define MAP_HUGE_512KB (19 << 26) -#define MAP_HUGE_1MB (20 << 26) -#define MAP_HUGE_2MB (21 << 26) -#define MAP_HUGE_8MB (23 << 26) -#define MAP_HUGE_16MB (24 << 26) -#define MAP_HUGE_32MB (25 << 26) -#define MAP_HUGE_256MB (28 << 26) -#define MAP_HUGE_512MB (29 << 26) -#define MAP_HUGE_1GB (30 << 26) -#define MAP_HUGE_2GB (31 << 26) -#define MAP_HUGE_16GB (34U << 26) - -#define PROT_NONE 0 -#define PROT_READ 1 -#define PROT_WRITE 2 -#define PROT_EXEC 4 -#define PROT_GROWSDOWN 0x01000000 -#define PROT_GROWSUP 0x02000000 - -#define MS_ASYNC 1 -#define MS_INVALIDATE 2 -#define MS_SYNC 4 - -#define MCL_CURRENT 1 -#define MCL_FUTURE 2 -#define MCL_ONFAULT 4 - -#define POSIX_MADV_NORMAL 0 -#define POSIX_MADV_RANDOM 1 -#define POSIX_MADV_SEQUENTIAL 2 -#define POSIX_MADV_WILLNEED 3 -#define POSIX_MADV_DONTNEED 4 - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define MADV_NORMAL 0 -#define MADV_RANDOM 1 -#define MADV_SEQUENTIAL 2 -#define MADV_WILLNEED 3 -#define MADV_DONTNEED 4 -#define MADV_FREE 8 -#define MADV_REMOVE 9 -#define MADV_DONTFORK 10 -#define MADV_DOFORK 11 -#define MADV_MERGEABLE 12 -#define MADV_UNMERGEABLE 13 -#define MADV_HUGEPAGE 14 -#define MADV_NOHUGEPAGE 15 -#define MADV_DONTDUMP 16 -#define MADV_DODUMP 17 -#define MADV_WIPEONFORK 18 -#define MADV_KEEPONFORK 19 -#define MADV_COLD 20 -#define MADV_PAGEOUT 21 -#define MADV_HWPOISON 100 -#define MADV_SOFT_OFFLINE 101 -#endif - -#ifdef _GNU_SOURCE -#define MREMAP_MAYMOVE 1 -#define MREMAP_FIXED 2 -#define MREMAP_DONTUNMAP 4 - -#define MLOCK_ONFAULT 0x01 - -#define MFD_CLOEXEC 0x0001U -#define MFD_ALLOW_SEALING 0x0002U -#define MFD_HUGETLB 0x0004U -#endif - -#include - -void *mmap (void *, size_t, int, int, int, off_t); -int munmap (void *, size_t); - -int mprotect (void *, size_t, int); -int msync (void *, size_t, int); - -int posix_madvise (void *, size_t, int); - -int mlock (const void *, size_t); -int munlock (const void *, size_t); -int mlockall (int); -int munlockall (void); - -#ifdef _GNU_SOURCE -void *mremap (void *, size_t, size_t, int, ...); -int remap_file_pages (void *, size_t, int, size_t, int); -int memfd_create (const char *, unsigned); -int mlock2 (const void *, size_t, unsigned); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int madvise (void *, size_t, int); -int mincore (void *, size_t, unsigned char *); -#endif - -int shm_open (const char *, int, mode_t); -int shm_unlink (const char *); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define mmap64 mmap -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/param.h b/lib/libc/wasi/libc-top-half/musl/include/sys/param.h deleted file mode 100644 index 01411725e42e1c5e981b36b4d91a1053c538572a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/param.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _SYS_PARAM_H -#define _SYS_PARAM_H - -#define MAXSYMLINKS 20 -#define MAXHOSTNAMELEN 64 -#define MAXNAMLEN 255 -#define MAXPATHLEN 4096 -#define NBBY 8 -#define NGROUPS 32 -#define CANBSIZ 255 -#define NOFILE 256 -#define NCARGS 131072 -#define DEV_BSIZE 512 -#define NOGROUP (-1) - -#undef MIN -#undef MAX -#define MIN(a,b) (((a)<(b))?(a):(b)) -#define MAX(a,b) (((a)>(b))?(a):(b)) - -#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) -#define setbit(x,i) __bitop(x,i,|=) -#define clrbit(x,i) __bitop(x,i,&=~) -#define isset(x,i) __bitop(x,i,&) -#define isclr(x,i) !isset(x,i) - -#define howmany(n,d) (((n)+((d)-1))/(d)) -#define roundup(n,d) (howmany(n,d)*(d)) -#define powerof2(n) !(((n)-1) & (n)) - -#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) -#include -#endif -#include -#include - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/random.h b/lib/libc/wasi/libc-top-half/musl/include/sys/random.h deleted file mode 100644 index 51cf9d7ffb4bd9f33cb41f16f6113fb94e762595..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/random.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef _SYS_RANDOM_H -#define _SYS_RANDOM_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no getrandom, but it does have getentropy */ -#define __NEED_size_t -#define __NEED_ssize_t -#include - -#define GRND_NONBLOCK 0x0001 -#define GRND_RANDOM 0x0002 -#define GRND_INSECURE 0x0004 - -ssize_t getrandom(void *, size_t, unsigned); -#else -#define __NEED_size_t -#include - -int getentropy(void *, size_t); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/resource.h b/lib/libc/wasi/libc-top-half/musl/include/sys/resource.h deleted file mode 100644 index 6c3a7ff2aa2f0306fb63996d84365278c5aabac4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/resource.h +++ /dev/null @@ -1,126 +0,0 @@ -#ifndef _WASI_EMULATED_PROCESS_CLOCKS -#error WASI lacks process-associated clocks; to enable emulation of the `getrusage` function using \ -the wall clock, which isn't sensitive to whether the program is running or suspended, \ -compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks -#else -#ifndef _SYS_RESOURCE_H -#define _SYS_RESOURCE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#define __NEED_id_t - -#ifdef _GNU_SOURCE -#define __NEED_pid_t -#endif - -#include -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef unsigned long long rlim_t; - -struct rlimit { - rlim_t rlim_cur; - rlim_t rlim_max; -}; - -struct rusage { - struct timeval ru_utime; - struct timeval ru_stime; - /* linux extentions, but useful */ - long ru_maxrss; - long ru_ixrss; - long ru_idrss; - long ru_isrss; - long ru_minflt; - long ru_majflt; - long ru_nswap; - long ru_inblock; - long ru_oublock; - long ru_msgsnd; - long ru_msgrcv; - long ru_nsignals; - long ru_nvcsw; - long ru_nivcsw; - /* room for more... */ - long __reserved[16]; -}; - -int getrlimit (int, struct rlimit *); -int setrlimit (int, const struct rlimit *); -int getrusage (int, struct rusage *); - -int getpriority (int, id_t); -int setpriority (int, id_t, int); - -#ifdef _GNU_SOURCE -int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); -#define prlimit64 prlimit -#endif - -#define PRIO_MIN (-20) -#define PRIO_MAX 20 - -#define PRIO_PROCESS 0 -#define PRIO_PGRP 1 -#define PRIO_USER 2 - -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN (-1) -#define RUSAGE_THREAD 1 - -#define RLIM_INFINITY (~0ULL) -#define RLIM_SAVED_CUR RLIM_INFINITY -#define RLIM_SAVED_MAX RLIM_INFINITY - -#define RLIMIT_CPU 0 -#define RLIMIT_FSIZE 1 -#define RLIMIT_DATA 2 -#define RLIMIT_STACK 3 -#define RLIMIT_CORE 4 -#ifndef RLIMIT_RSS -#define RLIMIT_RSS 5 -#define RLIMIT_NPROC 6 -#define RLIMIT_NOFILE 7 -#define RLIMIT_MEMLOCK 8 -#define RLIMIT_AS 9 -#endif -#define RLIMIT_LOCKS 10 -#define RLIMIT_SIGPENDING 11 -#define RLIMIT_MSGQUEUE 12 -#define RLIMIT_NICE 13 -#define RLIMIT_RTPRIO 14 -#define RLIMIT_RTTIME 15 -#define RLIMIT_NLIMITS 16 - -#define RLIM_NLIMITS RLIMIT_NLIMITS - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define RLIM64_INFINITY RLIM_INFINITY -#define RLIM64_SAVED_CUR RLIM_SAVED_CUR -#define RLIM64_SAVED_MAX RLIM_SAVED_MAX -#define getrlimit64 getrlimit -#define setrlimit64 setrlimit -#define rlimit64 rlimit -#define rlim64_t rlim_t -#endif -#else -#include <__header_sys_resource.h> -#endif - -#if _REDIR_TIME64 -__REDIR(getrusage, __getrusage_time64); -#endif - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/select.h b/lib/libc/wasi/libc-top-half/musl/include/sys/select.h deleted file mode 100644 index 1c1adfff59a146745231ebbb3d66db402451769e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/select.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef _SYS_SELECT_H -#define _SYS_SELECT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_suseconds_t -#define __NEED_struct_timeval -#define __NEED_struct_timespec -#define __NEED_sigset_t - -#include - -#define FD_SETSIZE 1024 - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef unsigned long fd_mask; -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -typedef struct { - unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; -} fd_set; - -#define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0) -#define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) -#define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) -#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) -#else -#include <__fd_set.h> -#endif - -int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); -int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define NFDBITS (8*(int)sizeof(long)) -#endif -#endif - -#if _REDIR_TIME64 -__REDIR(select, __select_time64); -__REDIR(pselect, __pselect_time64); -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/sendfile.h b/lib/libc/wasi/libc-top-half/musl/include/sys/sendfile.h deleted file mode 100644 index e7570d8e5c4f0226c88321b8d7cafb5071ec8391..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/sendfile.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _SYS_SENDFILE_H -#define _SYS_SENDFILE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -ssize_t sendfile(int, int, off_t *, size_t); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define sendfile64 sendfile -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/socket.h b/lib/libc/wasi/libc-top-half/musl/include/sys/socket.h deleted file mode 100644 index 29189e39eb841c1c5baab30e30986db990ea67de..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/socket.h +++ /dev/null @@ -1,454 +0,0 @@ -#ifndef _SYS_SOCKET_H -#define _SYS_SOCKET_H - -#include <__wasi_snapshot.h> - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#else -#include <__header_sys_socket.h> -#endif -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_socklen_t -#define __NEED_sa_family_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_pid_t -#define __NEED_gid_t -#define __NEED_struct_iovec - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct msghdr { - void *msg_name; - socklen_t msg_namelen; - struct iovec *msg_iov; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad1; -#endif - int msg_iovlen; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad1; -#endif - void *msg_control; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad2; -#endif - socklen_t msg_controllen; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad2; -#endif - int msg_flags; -}; - -struct cmsghdr { -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN - int __pad1; -#endif - socklen_t cmsg_len; -#if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN - int __pad1; -#endif - int cmsg_level; - int cmsg_type; -}; -#else -#include <__struct_msghdr.h> -#endif - -#ifdef _GNU_SOURCE -struct ucred { - pid_t pid; - uid_t uid; - gid_t gid; -}; - -struct mmsghdr { - struct msghdr msg_hdr; - unsigned int msg_len; -}; - -struct timespec; - -int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); -int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); -#endif - -struct linger { - int l_onoff; - int l_linger; -}; - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define SHUT_RD 0 -#define SHUT_WR 1 -#define SHUT_RDWR 2 - -#ifndef SOCK_STREAM -#define SOCK_STREAM 1 -#define SOCK_DGRAM 2 -#endif - -#define SOCK_RAW 3 -#define SOCK_RDM 4 -#define SOCK_SEQPACKET 5 -#define SOCK_DCCP 6 -#define SOCK_PACKET 10 - -#ifndef SOCK_CLOEXEC -#define SOCK_CLOEXEC 02000000 -#define SOCK_NONBLOCK 04000 -#endif - -#define PF_UNSPEC 0 -#define PF_LOCAL 1 -#define PF_UNIX PF_LOCAL -#define PF_FILE PF_LOCAL -#define PF_INET 2 -#define PF_AX25 3 -#define PF_IPX 4 -#define PF_APPLETALK 5 -#define PF_NETROM 6 -#define PF_BRIDGE 7 -#define PF_ATMPVC 8 -#define PF_X25 9 -#define PF_INET6 10 -#define PF_ROSE 11 -#define PF_DECnet 12 -#define PF_NETBEUI 13 -#define PF_SECURITY 14 -#define PF_KEY 15 -#define PF_NETLINK 16 -#define PF_ROUTE PF_NETLINK -#define PF_PACKET 17 -#define PF_ASH 18 -#define PF_ECONET 19 -#define PF_ATMSVC 20 -#define PF_RDS 21 -#define PF_SNA 22 -#define PF_IRDA 23 -#define PF_PPPOX 24 -#define PF_WANPIPE 25 -#define PF_LLC 26 -#define PF_IB 27 -#define PF_MPLS 28 -#define PF_CAN 29 -#define PF_TIPC 30 -#define PF_BLUETOOTH 31 -#define PF_IUCV 32 -#define PF_RXRPC 33 -#define PF_ISDN 34 -#define PF_PHONET 35 -#define PF_IEEE802154 36 -#define PF_CAIF 37 -#define PF_ALG 38 -#define PF_NFC 39 -#define PF_VSOCK 40 -#define PF_KCM 41 -#define PF_QIPCRTR 42 -#define PF_SMC 43 -#define PF_XDP 44 -#define PF_MAX 45 - -#define AF_UNSPEC PF_UNSPEC -#define AF_LOCAL PF_LOCAL -#define AF_UNIX AF_LOCAL -#define AF_FILE AF_LOCAL -#define AF_INET PF_INET -#define AF_AX25 PF_AX25 -#define AF_IPX PF_IPX -#define AF_APPLETALK PF_APPLETALK -#define AF_NETROM PF_NETROM -#define AF_BRIDGE PF_BRIDGE -#define AF_ATMPVC PF_ATMPVC -#define AF_X25 PF_X25 -#define AF_INET6 PF_INET6 -#define AF_ROSE PF_ROSE -#define AF_DECnet PF_DECnet -#define AF_NETBEUI PF_NETBEUI -#define AF_SECURITY PF_SECURITY -#define AF_KEY PF_KEY -#define AF_NETLINK PF_NETLINK -#define AF_ROUTE PF_ROUTE -#define AF_PACKET PF_PACKET -#define AF_ASH PF_ASH -#define AF_ECONET PF_ECONET -#define AF_ATMSVC PF_ATMSVC -#define AF_RDS PF_RDS -#define AF_SNA PF_SNA -#define AF_IRDA PF_IRDA -#define AF_PPPOX PF_PPPOX -#define AF_WANPIPE PF_WANPIPE -#define AF_LLC PF_LLC -#define AF_IB PF_IB -#define AF_MPLS PF_MPLS -#define AF_CAN PF_CAN -#define AF_TIPC PF_TIPC -#define AF_BLUETOOTH PF_BLUETOOTH -#define AF_IUCV PF_IUCV -#define AF_RXRPC PF_RXRPC -#define AF_ISDN PF_ISDN -#define AF_PHONET PF_PHONET -#define AF_IEEE802154 PF_IEEE802154 -#define AF_CAIF PF_CAIF -#define AF_ALG PF_ALG -#define AF_NFC PF_NFC -#define AF_VSOCK PF_VSOCK -#define AF_KCM PF_KCM -#define AF_QIPCRTR PF_QIPCRTR -#define AF_SMC PF_SMC -#define AF_XDP PF_XDP -#define AF_MAX PF_MAX - -#ifndef SO_DEBUG -#define SO_DEBUG 1 -#define SO_REUSEADDR 2 -#define SO_TYPE 3 -#define SO_ERROR 4 -#define SO_DONTROUTE 5 -#define SO_BROADCAST 6 -#define SO_SNDBUF 7 -#define SO_RCVBUF 8 -#define SO_KEEPALIVE 9 -#define SO_OOBINLINE 10 -#define SO_NO_CHECK 11 -#define SO_PRIORITY 12 -#define SO_LINGER 13 -#define SO_BSDCOMPAT 14 -#define SO_REUSEPORT 15 -#define SO_PASSCRED 16 -#define SO_PEERCRED 17 -#define SO_RCVLOWAT 18 -#define SO_SNDLOWAT 19 -#define SO_ACCEPTCONN 30 -#define SO_PEERSEC 31 -#define SO_SNDBUFFORCE 32 -#define SO_RCVBUFFORCE 33 -#define SO_PROTOCOL 38 -#define SO_DOMAIN 39 -#endif - -#ifndef SO_RCVTIMEO -#if __LONG_MAX == 0x7fffffff -#define SO_RCVTIMEO 66 -#define SO_SNDTIMEO 67 -#else -#define SO_RCVTIMEO 20 -#define SO_SNDTIMEO 21 -#endif -#endif - -#ifndef SO_TIMESTAMP -#if __LONG_MAX == 0x7fffffff -#define SO_TIMESTAMP 63 -#define SO_TIMESTAMPNS 64 -#define SO_TIMESTAMPING 65 -#else -#define SO_TIMESTAMP 29 -#define SO_TIMESTAMPNS 35 -#define SO_TIMESTAMPING 37 -#endif -#endif - -#define SO_SECURITY_AUTHENTICATION 22 -#define SO_SECURITY_ENCRYPTION_TRANSPORT 23 -#define SO_SECURITY_ENCRYPTION_NETWORK 24 - -#define SO_BINDTODEVICE 25 - -#define SO_ATTACH_FILTER 26 -#define SO_DETACH_FILTER 27 -#define SO_GET_FILTER SO_ATTACH_FILTER - -#define SO_PEERNAME 28 -#define SCM_TIMESTAMP SO_TIMESTAMP -#define SO_PASSSEC 34 -#define SCM_TIMESTAMPNS SO_TIMESTAMPNS -#define SO_MARK 36 -#define SCM_TIMESTAMPING SO_TIMESTAMPING -#define SO_RXQ_OVFL 40 -#define SO_WIFI_STATUS 41 -#define SCM_WIFI_STATUS SO_WIFI_STATUS -#define SO_PEEK_OFF 42 -#define SO_NOFCS 43 -#define SO_LOCK_FILTER 44 -#define SO_SELECT_ERR_QUEUE 45 -#define SO_BUSY_POLL 46 -#define SO_MAX_PACING_RATE 47 -#define SO_BPF_EXTENSIONS 48 -#define SO_INCOMING_CPU 49 -#define SO_ATTACH_BPF 50 -#define SO_DETACH_BPF SO_DETACH_FILTER -#define SO_ATTACH_REUSEPORT_CBPF 51 -#define SO_ATTACH_REUSEPORT_EBPF 52 -#define SO_CNX_ADVICE 53 -#define SCM_TIMESTAMPING_OPT_STATS 54 -#define SO_MEMINFO 55 -#define SO_INCOMING_NAPI_ID 56 -#define SO_COOKIE 57 -#define SCM_TIMESTAMPING_PKTINFO 58 -#define SO_PEERGROUPS 59 -#define SO_ZEROCOPY 60 -#define SO_TXTIME 61 -#define SCM_TXTIME SO_TXTIME -#define SO_BINDTOIFINDEX 62 -#define SO_DETACH_REUSEPORT_BPF 68 -#define SO_PREFER_BUSY_POLL 69 -#define SO_BUSY_POLL_BUDGET 70 - -#ifndef SOL_SOCKET -#define SOL_SOCKET 1 -#endif - -#define SOL_IP 0 -#define SOL_IPV6 41 -#define SOL_ICMPV6 58 - -#define SOL_RAW 255 -#define SOL_DECNET 261 -#define SOL_X25 262 -#define SOL_PACKET 263 -#define SOL_ATM 264 -#define SOL_AAL 265 -#define SOL_IRDA 266 -#define SOL_NETBEUI 267 -#define SOL_LLC 268 -#define SOL_DCCP 269 -#define SOL_NETLINK 270 -#define SOL_TIPC 271 -#define SOL_RXRPC 272 -#define SOL_PPPOL2TP 273 -#define SOL_BLUETOOTH 274 -#define SOL_PNPIPE 275 -#define SOL_RDS 276 -#define SOL_IUCV 277 -#define SOL_CAIF 278 -#define SOL_ALG 279 -#define SOL_NFC 280 -#define SOL_KCM 281 -#define SOL_TLS 282 -#define SOL_XDP 283 - -#define SOMAXCONN 128 - -#define MSG_OOB 0x0001 -#define MSG_PEEK 0x0002 -#define MSG_DONTROUTE 0x0004 -#define MSG_CTRUNC 0x0008 -#define MSG_PROXY 0x0010 -#define MSG_TRUNC 0x0020 -#define MSG_DONTWAIT 0x0040 -#define MSG_EOR 0x0080 -#define MSG_WAITALL 0x0100 -#define MSG_FIN 0x0200 -#define MSG_SYN 0x0400 -#define MSG_CONFIRM 0x0800 -#define MSG_RST 0x1000 -#define MSG_ERRQUEUE 0x2000 -#define MSG_NOSIGNAL 0x4000 -#define MSG_MORE 0x8000 -#define MSG_WAITFORONE 0x10000 -#define MSG_BATCH 0x40000 -#define MSG_ZEROCOPY 0x4000000 -#define MSG_FASTOPEN 0x20000000 -#define MSG_CMSG_CLOEXEC 0x40000000 - -#define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) -#define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) -#define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) - -#define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) -#define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ - __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ - ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) -#define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) - -#define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) -#define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) -#define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) - -#define SCM_RIGHTS 0x01 -#define SCM_CREDENTIALS 0x02 -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr { - sa_family_t sa_family; - char sa_data[14]; -}; -#else -#include <__struct_sockaddr.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct sockaddr_storage { - sa_family_t ss_family; - char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; - unsigned long __ss_align; -}; -#else -#include <__struct_sockaddr_storage.h> -#endif - -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int socket (int, int, int); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */ -int socketpair (int, int, int, int [2]); -#endif - -int shutdown (int, int); - -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int connect (int, const struct sockaddr *, socklen_t); -int bind (int, const struct sockaddr *, socklen_t); -int listen (int, int); -#endif - -int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); -int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); - -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); -int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); -#endif - -ssize_t send (int, const void *, size_t, int); -ssize_t recv (int, void *, size_t, int); -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); -ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ -ssize_t sendmsg (int, const struct msghdr *, int); -ssize_t recvmsg (int, struct msghdr *, int); -#endif - -int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); -#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) -int setsockopt (int, int, int, const void *, socklen_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ -int sockatmark (int); -#endif - -#if _REDIR_TIME64 -#ifdef _GNU_SOURCE -__REDIR(recvmmsg, __recvmmsg_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/stat.h b/lib/libc/wasi/libc-top-half/musl/include/sys/stat.h deleted file mode 100644 index 01d30ddaf3d2ebddaab55fefeb3b82bd781e8a4a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/stat.h +++ /dev/null @@ -1,198 +0,0 @@ -#ifndef _SYS_STAT_H -#define _SYS_STAT_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_dev_t -#define __NEED_ino_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_time_t -#define __NEED_blksize_t -#define __NEED_blkcnt_t -#define __NEED_struct_timespec - -#ifdef _GNU_SOURCE -#define __NEED_int64_t -#define __NEED_uint64_t -#define __NEED_uint32_t -#define __NEED_uint16_t -#endif - -#include - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define st_atime st_atim.tv_sec -#define st_mtime st_mtim.tv_sec -#define st_ctime st_ctim.tv_sec - -#define S_IFMT 0170000 - -#define S_IFDIR 0040000 -#define S_IFCHR 0020000 -#define S_IFBLK 0060000 -#define S_IFREG 0100000 -#define S_IFIFO 0010000 -#define S_IFLNK 0120000 -#define S_IFSOCK 0140000 - -#define S_TYPEISMQ(buf) 0 -#define S_TYPEISSEM(buf) 0 -#define S_TYPEISSHM(buf) 0 -#define S_TYPEISTMO(buf) 0 - -#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) -#define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) -#define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) -#define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) -#define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) -#define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) -#define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) - -#ifndef S_IRUSR -#define S_ISUID 04000 -#define S_ISGID 02000 -#define S_ISVTX 01000 -#define S_IRUSR 0400 -#define S_IWUSR 0200 -#define S_IXUSR 0100 -#define S_IRWXU 0700 -#define S_IRGRP 0040 -#define S_IWGRP 0020 -#define S_IXGRP 0010 -#define S_IRWXG 0070 -#define S_IROTH 0004 -#define S_IWOTH 0002 -#define S_IXOTH 0001 -#define S_IRWXO 0007 -#endif - -#define UTIME_NOW 0x3fffffff -#define UTIME_OMIT 0x3ffffffe -#else -#include <__header_sys_stat.h> -#endif - -int stat(const char *__restrict, struct stat *__restrict); -int fstat(int, struct stat *); -int lstat(const char *__restrict, struct stat *__restrict); -int fstatat(int, const char *__restrict, struct stat *__restrict, int); -int chmod(const char *, mode_t); -int fchmod(int, mode_t); -int fchmodat(int, const char *, mode_t, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no umask */ -mode_t umask(mode_t); -#endif -int mkdir(const char *, mode_t); -#ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ -int mkfifo(const char *, mode_t); -#endif -int mkdirat(int, const char *, mode_t); -#ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ -int mkfifoat(int, const char *, mode_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no mknod */ -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int mknod(const char *, mode_t, dev_t); -int mknodat(int, const char *, mode_t, dev_t); -#endif -#endif - -int futimens(int, const struct timespec [2]); -int utimensat(int, const char *, const struct timespec [2], int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ -int lchmod(const char *, mode_t); -#endif -#define S_IREAD S_IRUSR -#define S_IWRITE S_IWUSR -#define S_IEXEC S_IXUSR -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no statx */ -#if defined(_GNU_SOURCE) -#define STATX_TYPE 1U -#define STATX_MODE 2U -#define STATX_NLINK 4U -#define STATX_UID 8U -#define STATX_GID 0x10U -#define STATX_ATIME 0x20U -#define STATX_MTIME 0x40U -#define STATX_CTIME 0x80U -#define STATX_INO 0x100U -#define STATX_SIZE 0x200U -#define STATX_BLOCKS 0x400U -#define STATX_BASIC_STATS 0x7ffU -#define STATX_BTIME 0x800U -#define STATX_ALL 0xfffU - -struct statx_timestamp { - int64_t tv_sec; - uint32_t tv_nsec, __pad; -}; - -struct statx { - uint32_t stx_mask; - uint32_t stx_blksize; - uint64_t stx_attributes; - uint32_t stx_nlink; - uint32_t stx_uid; - uint32_t stx_gid; - uint16_t stx_mode; - uint16_t __pad0[1]; - uint64_t stx_ino; - uint64_t stx_size; - uint64_t stx_blocks; - uint64_t stx_attributes_mask; - struct statx_timestamp stx_atime; - struct statx_timestamp stx_btime; - struct statx_timestamp stx_ctime; - struct statx_timestamp stx_mtime; - uint32_t stx_rdev_major; - uint32_t stx_rdev_minor; - uint32_t stx_dev_major; - uint32_t stx_dev_minor; - uint64_t __pad1[14]; -}; - -int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict); -#endif -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define stat64 stat -#define fstat64 fstat -#define lstat64 lstat -#define fstatat64 fstatat -#define blkcnt64_t blkcnt_t -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#define ino64_t ino_t -#define off64_t off_t -#endif - -#if _REDIR_TIME64 -__REDIR(stat, __stat_time64); -__REDIR(fstat, __fstat_time64); -__REDIR(lstat, __lstat_time64); -__REDIR(fstatat, __fstatat_time64); -__REDIR(futimens, __futimens_time64); -__REDIR(utimensat, __utimensat_time64); -#endif - -#ifdef __cplusplus -} -#endif -#endif - - diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/statfs.h b/lib/libc/wasi/libc-top-half/musl/include/sys/statfs.h deleted file mode 100644 index 6f4c6230f7a0a0b81acadbe5cf0d8851a8fd7519..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/statfs.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef _SYS_STATFS_H -#define _SYS_STATFS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -typedef struct __fsid_t { - int __val[2]; -} fsid_t; - -#include - -int statfs (const char *, struct statfs *); -int fstatfs (int, struct statfs *); - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define statfs64 statfs -#define fstatfs64 fstatfs -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/statvfs.h b/lib/libc/wasi/libc-top-half/musl/include/sys/statvfs.h deleted file mode 100644 index 6cf35c5941b706c9272265e54a1a06775164232f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/statvfs.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _SYS_STATVFS_H -#define _SYS_STATVFS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t -#include - -struct statvfs { - unsigned long f_bsize, f_frsize; - fsblkcnt_t f_blocks, f_bfree, f_bavail; - fsfilcnt_t f_files, f_ffree, f_favail; -#if __BYTE_ORDER == __LITTLE_ENDIAN - unsigned long f_fsid; - unsigned :8*(2*sizeof(int)-sizeof(long)); -#else - unsigned :8*(2*sizeof(int)-sizeof(long)); - unsigned long f_fsid; -#endif - unsigned long f_flag, f_namemax; - unsigned int f_type; - int __reserved[5]; -}; - -int statvfs (const char *__restrict, struct statvfs *__restrict); -int fstatvfs (int, struct statvfs *); - -#define ST_RDONLY 1 -#define ST_NOSUID 2 -#define ST_NODEV 4 -#define ST_NOEXEC 8 -#define ST_SYNCHRONOUS 16 -#define ST_MANDLOCK 64 -#define ST_WRITE 128 -#define ST_APPEND 256 -#define ST_IMMUTABLE 512 -#define ST_NOATIME 1024 -#define ST_NODIRATIME 2048 -#define ST_RELATIME 4096 - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define statvfs64 statvfs -#define fstatvfs64 fstatvfs -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/syscall.h b/lib/libc/wasi/libc-top-half/musl/include/sys/syscall.h deleted file mode 100644 index ceed6b59cb3ee550651c23c9758e06ff0106d6bb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/syscall.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef _SYS_SYSCALL_H -#define _SYS_SYSCALL_H - -#ifdef __wasilibc_unmodified_upstream /* WASI has no syscall */ -#include -#else -/* The generic syscall funtion is not yet implemented. */ -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/time.h b/lib/libc/wasi/libc-top-half/musl/include/sys/time.h deleted file mode 100644 index 0f736551f60f57d560a5bfb485892abe611908e2..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/time.h +++ /dev/null @@ -1,84 +0,0 @@ -#ifndef _SYS_TIME_H -#define _SYS_TIME_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include - -int gettimeofday (struct timeval *__restrict, void *__restrict); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no getitimer */ -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerval { - struct timeval it_interval; - struct timeval it_value; -}; - -int getitimer (int, struct itimerval *); -int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); -#endif -int utimes (const char *, const struct timeval [2]); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -struct timezone { - int tz_minuteswest; - int tz_dsttime; -}; -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -int futimes(int, const struct timeval [2]); -#endif -int futimesat(int, const char *, const struct timeval [2]); -#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ -int lutimes(const char *, const struct timeval [2]); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no way to set the time */ -int settimeofday(const struct timeval *, const struct timezone *); -int adjtime (const struct timeval *, struct timeval *); -#endif -#define timerisset(t) ((t)->tv_sec || (t)->tv_usec) -#define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) -#define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ - (s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) -#define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ - ((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ - ((a)->tv_usec -= 1000000, (a)->tv_sec++) ) -#define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ - ((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ - ((a)->tv_usec += 1000000, (a)->tv_sec--) ) -#endif - -#if defined(_GNU_SOURCE) -#define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ - (ts)->tv_sec = (tv)->tv_sec, \ - (ts)->tv_nsec = (tv)->tv_usec * 1000, \ - (void)0 ) -#define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ - (tv)->tv_sec = (ts)->tv_sec, \ - (tv)->tv_usec = (ts)->tv_nsec / 1000, \ - (void)0 ) -#endif - -#if _REDIR_TIME64 -__REDIR(gettimeofday, __gettimeofday_time64); -__REDIR(getitimer, __getitimer_time64); -__REDIR(setitimer, __setitimer_time64); -__REDIR(utimes, __utimes_time64); -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__REDIR(futimes, __futimes_time64); -__REDIR(futimesat, __futimesat_time64); -__REDIR(lutimes, __lutimes_time64); -__REDIR(settimeofday, __settimeofday_time64); -__REDIR(adjtime, __adjtime64); -#endif -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/times.h b/lib/libc/wasi/libc-top-half/musl/include/sys/times.h deleted file mode 100644 index cdaeeee91a9e08cfd3a8d21b0be52a1695afe15a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/times.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef _WASI_EMULATED_PROCESS_CLOCKS -#error WASI lacks process-associated clocks; to enable emulation of the `times` function using \ -the wall clock, which isn't sensitive to whether the program is running or suspended, \ -compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks -#else -#ifndef _SYS_TIMES_H -#define _SYS_TIMES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#define __NEED_clock_t -#include - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct tms { - clock_t tms_utime; - clock_t tms_stime; - clock_t tms_cutime; - clock_t tms_cstime; -}; -#else -#include <__struct_tms.h> -#endif - -clock_t times (struct tms *); - -#ifdef __cplusplus -} -#endif - -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/types.h b/lib/libc/wasi/libc-top-half/musl/include/sys/types.h deleted file mode 100644 index 0c35541da0754954b9aa13d90322458c92277a53..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/types.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_ino_t -#define __NEED_dev_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_mode_t -#define __NEED_nlink_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_time_t -#define __NEED_timer_t -#define __NEED_clockid_t - -#define __NEED_blkcnt_t -#define __NEED_fsblkcnt_t -#define __NEED_fsfilcnt_t - -#define __NEED_id_t -#define __NEED_key_t -#define __NEED_clock_t -#define __NEED_suseconds_t -#define __NEED_blksize_t - -#define __NEED_pthread_t -#define __NEED_pthread_attr_t -#define __NEED_pthread_mutexattr_t -#define __NEED_pthread_condattr_t -#define __NEED_pthread_rwlockattr_t -#define __NEED_pthread_barrierattr_t -#define __NEED_pthread_mutex_t -#define __NEED_pthread_cond_t -#define __NEED_pthread_rwlock_t -#define __NEED_pthread_barrier_t -#define __NEED_pthread_spinlock_t -#define __NEED_pthread_key_t -#define __NEED_pthread_once_t -#define __NEED_useconds_t - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_int8_t -#define __NEED_int16_t -#define __NEED_int32_t -#define __NEED_int64_t -#define __NEED_u_int64_t -#define __NEED_register_t -#endif - -#include - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -typedef unsigned char u_int8_t; -typedef unsigned short u_int16_t; -typedef unsigned u_int32_t; -typedef char *caddr_t; -typedef unsigned char u_char; -typedef unsigned short u_short, ushort; -typedef unsigned u_int, uint; -typedef unsigned long u_long, ulong; -typedef long long quad_t; -typedef unsigned long long u_quad_t; -#include -#include -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define blkcnt64_t blkcnt_t -#define fsblkcnt64_t fsblkcnt_t -#define fsfilcnt64_t fsfilcnt_t -#define ino64_t ino_t -#define off64_t off_t -#endif - -#ifdef __cplusplus -} -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/uio.h b/lib/libc/wasi/libc-top-half/musl/include/sys/uio.h deleted file mode 100644 index f102d5a56e423b7de5ea14f09a8b4e364877e386..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/uio.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef _SYS_UIO_H -#define _SYS_UIO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_struct_iovec - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_off_t -#endif - -#ifdef _GNU_SOURCE -#define __NEED_pid_t -#endif - -#include - -#define UIO_MAXIOV 1024 - -ssize_t readv (int, const struct iovec *, int); -ssize_t writev (int, const struct iovec *, int); - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -ssize_t preadv (int, const struct iovec *, int, off_t); -ssize_t pwritev (int, const struct iovec *, int, off_t); -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define preadv64 preadv -#define pwritev64 pwritev -#define off64_t off_t -#endif -#endif - -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have these Linux-specific functions -#ifdef _GNU_SOURCE -ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); -ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); -ssize_t preadv2 (int, const struct iovec *, int, off_t, int); -ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); -#define RWF_HIPRI 0x00000001 -#define RWF_DSYNC 0x00000002 -#define RWF_SYNC 0x00000004 -#define RWF_NOWAIT 0x00000008 -#define RWF_APPEND 0x00000010 -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/sys/un.h b/lib/libc/wasi/libc-top-half/musl/include/sys/un.h deleted file mode 100644 index 71169567172c40860b513b93deeee40ab4d7bde7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/sys/un.h +++ /dev/null @@ -1,39 +0,0 @@ -#ifndef _SYS_UN_H -#define _SYS_UN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_sa_family_t -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_size_t -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* WASI has no UNIX-domain sockets */ -struct sockaddr_un { - sa_family_t sun_family; - char sun_path[108]; -}; -#else -#include <__struct_sockaddr_un.h> -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* Declare strlen with the same attributes as uses */ -size_t strlen(const char *); -#else -size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); -#endif -#define SUN_LEN(s) (2+strlen((s)->sun_path)) -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/time.h b/lib/libc/wasi/libc-top-half/musl/include/time.h deleted file mode 100644 index f53414878aa0daff7d6f9e9f042443a9b2e2f9e6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/time.h +++ /dev/null @@ -1,204 +0,0 @@ -#ifndef _TIME_H -#define _TIME_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - - -#define __NEED_size_t -#define __NEED_time_t -#define __NEED_clock_t -#define __NEED_struct_timespec - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -#define __NEED_clockid_t -#define __NEED_timer_t -#define __NEED_pid_t -#define __NEED_locale_t -#endif - -#include - -#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -#define __tm_gmtoff tm_gmtoff -#define __tm_zone tm_zone -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -struct tm { - int tm_sec; - int tm_min; - int tm_hour; - int tm_mday; - int tm_mon; - int tm_year; - int tm_wday; - int tm_yday; - int tm_isdst; - long __tm_gmtoff; - const char *__tm_zone; -}; -#else -#include <__header_time.h> -#endif - -#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) -clock_t clock (void); -#else -__attribute__((__deprecated__( -"WASI lacks process-associated clocks; to enable emulation of the `clock` function using " -"the wall clock, which isn't sensitive to whether the program is running or suspended, " -"compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks" -))) -clock_t clock (void); -#endif -time_t time (time_t *); -double difftime (time_t, time_t); -time_t mktime (struct tm *); -size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); -struct tm *gmtime (const time_t *); -struct tm *localtime (const time_t *); -char *asctime (const struct tm *); -char *ctime (const time_t *); -int timespec_get(struct timespec *, int); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define CLOCKS_PER_SEC 1000000L - -#define TIME_UTC 1 -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) - -size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); - -struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); -struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); -char *asctime_r (const struct tm *__restrict, char *__restrict); -char *ctime_r (const time_t *, char *); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ -void tzset (void); -#endif - -struct itimerspec { - struct timespec it_interval; - struct timespec it_value; -}; - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define CLOCK_REALTIME 0 -#define CLOCK_MONOTONIC 1 -#define CLOCK_PROCESS_CPUTIME_ID 2 -#define CLOCK_THREAD_CPUTIME_ID 3 -#define CLOCK_MONOTONIC_RAW 4 -#define CLOCK_REALTIME_COARSE 5 -#define CLOCK_MONOTONIC_COARSE 6 -#define CLOCK_BOOTTIME 7 -#define CLOCK_REALTIME_ALARM 8 -#define CLOCK_BOOTTIME_ALARM 9 -#define CLOCK_SGI_CYCLE 10 -#define CLOCK_TAI 11 - -#define TIMER_ABSTIME 1 -#endif - -int nanosleep (const struct timespec *, struct timespec *); -int clock_getres (clockid_t, struct timespec *); -int clock_gettime (clockid_t, struct timespec *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */ -int clock_settime (clockid_t, const struct timespec *); -#endif -int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */ -int clock_getcpuclockid (pid_t, clockid_t *); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no timers */ -struct sigevent; -int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); -int timer_delete (timer_t); -int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); -int timer_gettime (timer_t, struct itimerspec *); -int timer_getoverrun (timer_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ -extern char *tzname[2]; -#endif - -#endif - - -#if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) -char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); -#ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ -extern int daylight; -extern long timezone; -#endif -extern int getdate_err; -struct tm *getdate (const char *); -#endif - - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#ifdef __wasilibc_unmodified_upstream /* WASI has no stime */ -int stime(const time_t *); -#endif -time_t timegm(struct tm *); -#endif - -#if _REDIR_TIME64 -__REDIR(time, __time64); -__REDIR(difftime, __difftime64); -__REDIR(mktime, __mktime64); -__REDIR(gmtime, __gmtime64); -__REDIR(localtime, __localtime64); -__REDIR(ctime, __ctime64); -__REDIR(timespec_get, __timespec_get_time64); -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ - || defined(_BSD_SOURCE) -__REDIR(gmtime_r, __gmtime64_r); -__REDIR(localtime_r, __localtime64_r); -__REDIR(ctime_r, __ctime64_r); -__REDIR(nanosleep, __nanosleep_time64); -__REDIR(clock_getres, __clock_getres_time64); -__REDIR(clock_gettime, __clock_gettime64); -__REDIR(clock_settime, __clock_settime64); -__REDIR(clock_nanosleep, __clock_nanosleep_time64); -__REDIR(timer_settime, __timer_settime64); -__REDIR(timer_gettime, __timer_gettime64); -#endif -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -__REDIR(stime, __stime64); -__REDIR(timegm, __timegm_time64); -#endif -#endif - -#ifdef __cplusplus -} -#endif - - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/unistd.h b/lib/libc/wasi/libc-top-half/musl/include/unistd.h deleted file mode 100644 index c3158e6e649220fd5520dbf804bd91ff6b11c6b4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/unistd.h +++ /dev/null @@ -1,589 +0,0 @@ -#ifndef _UNISTD_H -#define _UNISTD_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define STDIN_FILENO 0 -#define STDOUT_FILENO 1 -#define STDERR_FILENO 2 - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define SEEK_SET 0 -#define SEEK_CUR 1 -#define SEEK_END 2 -#define SEEK_DATA 3 -#define SEEK_HOLE 4 -#else -#include <__header_unistd.h> -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#define __NEED_size_t -#define __NEED_ssize_t -#define __NEED_uid_t -#define __NEED_gid_t -#define __NEED_off_t -#define __NEED_pid_t -#define __NEED_intptr_t -#define __NEED_useconds_t - -#include - -#ifdef __wasilibc_unmodified_upstream /* WASI has no pipe */ -int pipe(int [2]); -int pipe2(int [2], int); -#endif -int close(int); -int posix_close(int, int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no dup */ -int dup(int); -int dup2(int, int); -int dup3(int, int, int); -#endif -off_t lseek(int, off_t, int); -#ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */ -#else -off_t __wasilibc_tell(int); - -#ifndef __cplusplus -/* - * Optimize lseek in the case where it's just returning the current offset. - * This avoids importing `__wasi_fd_seek` altogether in many common cases. - * - * But don't do this for C++ because a simple macro wouldn't handle namespaces - * correctly: - * - User code could qualify the `lseek` call with `::`. - * - There may be another `lseek` in scope from a `using` declaration. - */ -#define lseek(fd, offset, whence) \ - ({ \ - off_t __f = (fd); \ - off_t __o = (offset); \ - off_t __w = (whence); \ - __builtin_constant_p((offset)) && \ - __builtin_constant_p((whence)) && \ - __o == 0 && \ - __w == SEEK_CUR \ - ? __wasilibc_tell(__f) \ - : lseek(__f, __o, __w); \ - }) -#endif -#endif -int fsync(int); -int fdatasync(int); - -ssize_t read(int, void *, size_t); -ssize_t write(int, const void *, size_t); -ssize_t pread(int, void *, size_t, off_t); -ssize_t pwrite(int, const void *, size_t, off_t); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no chown */ -int chown(const char *, uid_t, gid_t); -int fchown(int, uid_t, gid_t); -int lchown(const char *, uid_t, gid_t); -int fchownat(int, const char *, uid_t, gid_t, int); -#endif - -int link(const char *, const char *); -int linkat(int, const char *, int, const char *, int); -int symlink(const char *, const char *); -int symlinkat(const char *, int, const char *); -ssize_t readlink(const char *__restrict, char *__restrict, size_t); -ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); -int unlink(const char *); -int unlinkat(int, const char *, int); -int rmdir(const char *); -int truncate(const char *, off_t); -int ftruncate(int, off_t); - -#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ -#define F_OK 0 -#define R_OK 4 -#define W_OK 2 -#define X_OK 1 -#endif - -int access(const char *, int); -int faccessat(int, const char *, int, int); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no fchdir */ -int fchdir(int); -#endif -int chdir(const char *); -char *getcwd(char *, size_t); - -#ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ -unsigned alarm(unsigned); -#endif -unsigned sleep(unsigned); -#ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ -int pause(void); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ -pid_t fork(void); -pid_t _Fork(void); -int execve(const char *, char *const [], char *const []); -int execv(const char *, char *const []); -int execle(const char *, const char *, ...); -int execl(const char *, const char *, ...); -int execvp(const char *, char *const []); -int execlp(const char *, const char *, ...); -int fexecve(int, char *const [], char *const []); -#endif -_Noreturn void _exit(int); - -#if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_GETPID) -pid_t getpid(void); -#else -__attribute__((__deprecated__( -"WASI lacks process identifiers; to enable emulation of the `getpid` function using " -"a placeholder value, which doesn't reflect the host PID of the program, " -"compile with -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid" -))) -pid_t getpid(void); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no getpid etc. */ -pid_t getppid(void); -pid_t getpgrp(void); -pid_t getpgid(pid_t); -int setpgid(pid_t, pid_t); -pid_t setsid(void); -pid_t getsid(pid_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no ttyname */ -char *ttyname(int); -int ttyname_r(int, char *, size_t); -#endif -int isatty(int); -#ifdef __wasilibc_unmodified_upstream /* WASI has no process groups */ -pid_t tcgetpgrp(int); -int tcsetpgrp(int, pid_t); -#endif - -#ifdef __wasilibc_unmodified_upstream /* WASI has no getuid etc. */ -uid_t getuid(void); -uid_t geteuid(void); -gid_t getgid(void); -gid_t getegid(void); -int getgroups(int, gid_t []); -int setuid(uid_t); -int seteuid(uid_t); -int setgid(gid_t); -int setegid(gid_t); -#endif - -char *getlogin(void); -int getlogin_r(char *, size_t); -int gethostname(char *, size_t); -char *ctermid(char *); - -int getopt(int, char * const [], const char *); -extern char *optarg; -extern int optind, opterr, optopt; - -long pathconf(const char *, int); -long fpathconf(int, int); -long sysconf(int); -size_t confstr(int, char *, size_t); - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define F_ULOCK 0 -#define F_LOCK 1 -#define F_TLOCK 2 -#define F_TEST 3 -#ifdef __wasilibc_unmodified_upstream /* WASI has no setreuid */ -int setreuid(uid_t, uid_t); -int setregid(gid_t, gid_t); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -int lockf(int, int, off_t); -#endif -long gethostid(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no nice, sync, or setpgrp */ -int nice(int); -void sync(void); -pid_t setpgrp(void); -#endif -char *crypt(const char *, const char *); -void encrypt(char *, int); -void swab(const void *__restrict, void *__restrict, ssize_t); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ - || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) -int usleep(unsigned); -unsigned ualarm(unsigned, unsigned); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define L_SET 0 -#define L_INCR 1 -#define L_XTND 2 -#ifdef __wasilibc_unmodified_upstream /* WASI has no brk */ -int brk(void *); -#endif -void *sbrk(intptr_t); -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ -pid_t vfork(void); -int vhangup(void); -int chroot(const char *); -#endif -int getpagesize(void); -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ -int getdtablesize(void); -int sethostname(const char *, size_t); -int getdomainname(char *, size_t); -int setdomainname(const char *, size_t); -int setgroups(size_t, const gid_t *); -char *getpass(const char *); -int daemon(int, int); -void setusershell(void); -void endusershell(void); -char *getusershell(void); -int acct(const char *); -long syscall(long, ...); -int execvpe(const char *, char *const [], char *const []); -int issetugid(void); -#endif -int getentropy(void *, size_t); -extern int optreset; -#endif - -#ifdef _GNU_SOURCE -extern char **environ; -#ifdef __wasilibc_unmodified_upstream /* WASI has no get/setresuid */ -int setresuid(uid_t, uid_t, uid_t); -int setresgid(gid_t, gid_t, gid_t); -int getresuid(uid_t *, uid_t *, uid_t *); -int getresgid(gid_t *, gid_t *, gid_t *); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no cwd */ -char *get_current_dir_name(void); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no syncfs */ -int syncfs(int); -#endif -#ifdef __wasilibc_unmodified_upstream /* WASI has no eaccess */ -int euidaccess(const char *, int); -int eaccess(const char *, int); -ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); -pid_t gettid(void); -#endif -#endif - -#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) -#define lseek64 lseek -#define pread64 pread -#define pwrite64 pwrite -#ifdef __wasilibc_unmodified_upstream /* WASI has no truncate */ -#define truncate64 truncate -#endif -#define ftruncate64 ftruncate -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ -#define lockf64 lockf -#endif -#define off64_t off_t -#endif - -#define POSIX_CLOSE_RESTART 0 - -#define _XOPEN_VERSION 700 -#define _XOPEN_UNIX 1 -#define _XOPEN_ENH_I18N 1 - -#define _POSIX_VERSION 200809L -#define _POSIX2_VERSION _POSIX_VERSION - -#define _POSIX_ADVISORY_INFO _POSIX_VERSION -#define _POSIX_CHOWN_RESTRICTED 1 -#define _POSIX_IPV6 _POSIX_VERSION -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes, mmap, or mq */ -#define _POSIX_JOB_CONTROL 1 -#define _POSIX_MAPPED_FILES _POSIX_VERSION -#define _POSIX_MEMLOCK _POSIX_VERSION -#define _POSIX_MEMLOCK_RANGE _POSIX_VERSION -#define _POSIX_MEMORY_PROTECTION _POSIX_VERSION -#define _POSIX_MESSAGE_PASSING _POSIX_VERSION -#endif -#define _POSIX_FSYNC _POSIX_VERSION -#define _POSIX_NO_TRUNC 1 -#ifdef __wasilibc_unmodified_upstream /* WASI has no raw sockets */ -#define _POSIX_RAW_SOCKETS _POSIX_VERSION -#endif -#define _POSIX_REALTIME_SIGNALS _POSIX_VERSION -#define _POSIX_REGEXP 1 -#ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ -#define _POSIX_SAVED_IDS 1 -#define _POSIX_SHELL 1 -#define _POSIX_SPAWN _POSIX_VERSION -#endif -#define _POSIX_VDISABLE 0 - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -#define _POSIX_THREADS _POSIX_VERSION -#define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION -#define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION -#endif -#if defined(__wasilibc_unmodified_upstream) /* wasi-libc doesn't provide pthread_attr_{get,set}stackaddr */ -#define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION -#endif -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) -#define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION -#endif -#if defined(__wasilibc_unmodified_upstream) /* WASI has no scheduling control, and wasi-libc doesn't provide pthread_getcpuclockid */ -#define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION -#define _POSIX_THREAD_CPUTIME _POSIX_VERSION -#endif -#define _POSIX_TIMERS _POSIX_VERSION -#define _POSIX_TIMEOUTS _POSIX_VERSION -#define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION -#define _POSIX_CPUTIME _POSIX_VERSION -#define _POSIX_CLOCK_SELECTION _POSIX_VERSION -#define _POSIX_BARRIERS _POSIX_VERSION -#define _POSIX_SPIN_LOCKS _POSIX_VERSION -#define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION -#ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX async I/O, semaphores, or shared memory */ -#define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION -#define _POSIX_SEMAPHORES _POSIX_VERSION -#define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION -#endif - -#define _POSIX2_C_BIND _POSIX_VERSION - -#include - - - -#define _PC_LINK_MAX 0 -#define _PC_MAX_CANON 1 -#define _PC_MAX_INPUT 2 -#define _PC_NAME_MAX 3 -#define _PC_PATH_MAX 4 -#define _PC_PIPE_BUF 5 -#define _PC_CHOWN_RESTRICTED 6 -#define _PC_NO_TRUNC 7 -#define _PC_VDISABLE 8 -#define _PC_SYNC_IO 9 -#define _PC_ASYNC_IO 10 -#define _PC_PRIO_IO 11 -#define _PC_SOCK_MAXBUF 12 -#define _PC_FILESIZEBITS 13 -#define _PC_REC_INCR_XFER_SIZE 14 -#define _PC_REC_MAX_XFER_SIZE 15 -#define _PC_REC_MIN_XFER_SIZE 16 -#define _PC_REC_XFER_ALIGN 17 -#define _PC_ALLOC_SIZE_MIN 18 -#define _PC_SYMLINK_MAX 19 -#define _PC_2_SYMLINKS 20 - -#define _SC_ARG_MAX 0 -#define _SC_CHILD_MAX 1 -#define _SC_CLK_TCK 2 -#define _SC_NGROUPS_MAX 3 -#define _SC_OPEN_MAX 4 -#define _SC_STREAM_MAX 5 -#define _SC_TZNAME_MAX 6 -#define _SC_JOB_CONTROL 7 -#define _SC_SAVED_IDS 8 -#define _SC_REALTIME_SIGNALS 9 -#define _SC_PRIORITY_SCHEDULING 10 -#define _SC_TIMERS 11 -#define _SC_ASYNCHRONOUS_IO 12 -#define _SC_PRIORITIZED_IO 13 -#define _SC_SYNCHRONIZED_IO 14 -#define _SC_FSYNC 15 -#define _SC_MAPPED_FILES 16 -#define _SC_MEMLOCK 17 -#define _SC_MEMLOCK_RANGE 18 -#define _SC_MEMORY_PROTECTION 19 -#define _SC_MESSAGE_PASSING 20 -#define _SC_SEMAPHORES 21 -#define _SC_SHARED_MEMORY_OBJECTS 22 -#define _SC_AIO_LISTIO_MAX 23 -#define _SC_AIO_MAX 24 -#define _SC_AIO_PRIO_DELTA_MAX 25 -#define _SC_DELAYTIMER_MAX 26 -#define _SC_MQ_OPEN_MAX 27 -#define _SC_MQ_PRIO_MAX 28 -#define _SC_VERSION 29 -#define _SC_PAGE_SIZE 30 -#define _SC_PAGESIZE 30 /* !! */ -#define _SC_RTSIG_MAX 31 -#define _SC_SEM_NSEMS_MAX 32 -#define _SC_SEM_VALUE_MAX 33 -#define _SC_SIGQUEUE_MAX 34 -#define _SC_TIMER_MAX 35 -#define _SC_BC_BASE_MAX 36 -#define _SC_BC_DIM_MAX 37 -#define _SC_BC_SCALE_MAX 38 -#define _SC_BC_STRING_MAX 39 -#define _SC_COLL_WEIGHTS_MAX 40 -#define _SC_EXPR_NEST_MAX 42 -#define _SC_LINE_MAX 43 -#define _SC_RE_DUP_MAX 44 -#define _SC_2_VERSION 46 -#define _SC_2_C_BIND 47 -#define _SC_2_C_DEV 48 -#define _SC_2_FORT_DEV 49 -#define _SC_2_FORT_RUN 50 -#define _SC_2_SW_DEV 51 -#define _SC_2_LOCALEDEF 52 -#define _SC_UIO_MAXIOV 60 /* !! */ -#define _SC_IOV_MAX 60 -#define _SC_THREADS 67 -#define _SC_THREAD_SAFE_FUNCTIONS 68 -#define _SC_GETGR_R_SIZE_MAX 69 -#define _SC_GETPW_R_SIZE_MAX 70 -#define _SC_LOGIN_NAME_MAX 71 -#define _SC_TTY_NAME_MAX 72 -#define _SC_THREAD_DESTRUCTOR_ITERATIONS 73 -#define _SC_THREAD_KEYS_MAX 74 -#define _SC_THREAD_STACK_MIN 75 -#define _SC_THREAD_THREADS_MAX 76 -#define _SC_THREAD_ATTR_STACKADDR 77 -#define _SC_THREAD_ATTR_STACKSIZE 78 -#define _SC_THREAD_PRIORITY_SCHEDULING 79 -#define _SC_THREAD_PRIO_INHERIT 80 -#define _SC_THREAD_PRIO_PROTECT 81 -#define _SC_THREAD_PROCESS_SHARED 82 -#define _SC_NPROCESSORS_CONF 83 -#define _SC_NPROCESSORS_ONLN 84 -#define _SC_PHYS_PAGES 85 -#define _SC_AVPHYS_PAGES 86 -#define _SC_ATEXIT_MAX 87 -#define _SC_PASS_MAX 88 -#define _SC_XOPEN_VERSION 89 -#define _SC_XOPEN_XCU_VERSION 90 -#define _SC_XOPEN_UNIX 91 -#define _SC_XOPEN_CRYPT 92 -#define _SC_XOPEN_ENH_I18N 93 -#define _SC_XOPEN_SHM 94 -#define _SC_2_CHAR_TERM 95 -#define _SC_2_UPE 97 -#define _SC_XOPEN_XPG2 98 -#define _SC_XOPEN_XPG3 99 -#define _SC_XOPEN_XPG4 100 -#define _SC_NZERO 109 -#define _SC_XBS5_ILP32_OFF32 125 -#define _SC_XBS5_ILP32_OFFBIG 126 -#define _SC_XBS5_LP64_OFF64 127 -#define _SC_XBS5_LPBIG_OFFBIG 128 -#define _SC_XOPEN_LEGACY 129 -#define _SC_XOPEN_REALTIME 130 -#define _SC_XOPEN_REALTIME_THREADS 131 -#define _SC_ADVISORY_INFO 132 -#define _SC_BARRIERS 133 -#define _SC_CLOCK_SELECTION 137 -#define _SC_CPUTIME 138 -#define _SC_THREAD_CPUTIME 139 -#define _SC_MONOTONIC_CLOCK 149 -#define _SC_READER_WRITER_LOCKS 153 -#define _SC_SPIN_LOCKS 154 -#define _SC_REGEXP 155 -#define _SC_SHELL 157 -#define _SC_SPAWN 159 -#define _SC_SPORADIC_SERVER 160 -#define _SC_THREAD_SPORADIC_SERVER 161 -#define _SC_TIMEOUTS 164 -#define _SC_TYPED_MEMORY_OBJECTS 165 -#define _SC_2_PBS 168 -#define _SC_2_PBS_ACCOUNTING 169 -#define _SC_2_PBS_LOCATE 170 -#define _SC_2_PBS_MESSAGE 171 -#define _SC_2_PBS_TRACK 172 -#define _SC_SYMLOOP_MAX 173 -#define _SC_STREAMS 174 -#define _SC_2_PBS_CHECKPOINT 175 -#define _SC_V6_ILP32_OFF32 176 -#define _SC_V6_ILP32_OFFBIG 177 -#define _SC_V6_LP64_OFF64 178 -#define _SC_V6_LPBIG_OFFBIG 179 -#define _SC_HOST_NAME_MAX 180 -#define _SC_TRACE 181 -#define _SC_TRACE_EVENT_FILTER 182 -#define _SC_TRACE_INHERIT 183 -#define _SC_TRACE_LOG 184 - -#define _SC_IPV6 235 -#define _SC_RAW_SOCKETS 236 -#define _SC_V7_ILP32_OFF32 237 -#define _SC_V7_ILP32_OFFBIG 238 -#define _SC_V7_LP64_OFF64 239 -#define _SC_V7_LPBIG_OFFBIG 240 -#define _SC_SS_REPL_MAX 241 -#define _SC_TRACE_EVENT_NAME_MAX 242 -#define _SC_TRACE_NAME_MAX 243 -#define _SC_TRACE_SYS_MAX 244 -#define _SC_TRACE_USER_EVENT_MAX 245 -#define _SC_XOPEN_STREAMS 246 -#define _SC_THREAD_ROBUST_PRIO_INHERIT 247 -#define _SC_THREAD_ROBUST_PRIO_PROTECT 248 -#define _SC_MINSIGSTKSZ 249 -#define _SC_SIGSTKSZ 250 - -#define _CS_PATH 0 -#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 1 -#define _CS_GNU_LIBC_VERSION 2 -#define _CS_GNU_LIBPTHREAD_VERSION 3 -#define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS 4 -#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 5 - -#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 1116 -#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 1117 -#define _CS_POSIX_V6_ILP32_OFF32_LIBS 1118 -#define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS 1119 -#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 1120 -#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 1121 -#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 1122 -#define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS 1123 -#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 1124 -#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 1125 -#define _CS_POSIX_V6_LP64_OFF64_LIBS 1126 -#define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS 1127 -#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 1128 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 1129 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 1130 -#define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS 1131 -#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1132 -#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 1133 -#define _CS_POSIX_V7_ILP32_OFF32_LIBS 1134 -#define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS 1135 -#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 1136 -#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 1137 -#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 1138 -#define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS 1139 -#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 1140 -#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 1141 -#define _CS_POSIX_V7_LP64_OFF64_LIBS 1142 -#define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS 1143 -#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 1144 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 1145 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 1146 -#define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS 1147 -#define _CS_V6_ENV 1148 -#define _CS_V7_ENV 1149 -#define _CS_POSIX_V7_THREADS_CFLAGS 1150 -#define _CS_POSIX_V7_THREADS_LDFLAGS 1151 - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/wasi/libc-busywait.h b/lib/libc/wasi/libc-top-half/musl/include/wasi/libc-busywait.h deleted file mode 100644 index c90017b8e03f7f3aae4a77dcb71dc7ba28c4b1f0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/wasi/libc-busywait.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef __wasi_libc_busywait_h -#define __wasi_libc_busywait_h - -#ifdef __cplusplus -extern "C" { -#endif - -/// Enable busywait in futex on current thread. -void __wasilibc_enable_futex_busywait_on_current_thread(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/include/wchar.h b/lib/libc/wasi/libc-top-half/musl/include/wchar.h deleted file mode 100644 index 06b088aa9bde488d10892eae44f4f4635b5155ce..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/include/wchar.h +++ /dev/null @@ -1,214 +0,0 @@ -#ifndef _WCHAR_H -#define _WCHAR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#define __NEED_FILE -#define __NEED___isoc_va_list -#define __NEED_size_t -#define __NEED_wchar_t -#define __NEED_wint_t -#define __NEED_mbstate_t - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#if __STDC_VERSION__ < 201112L -#define __NEED_struct__IO_FILE -#endif -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_locale_t -#define __NEED_va_list -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -#define __NEED_wctype_t -#endif - -#include - -#if L'\0'-1 > 0 -#define WCHAR_MAX (0xffffffffu+L'\0') -#define WCHAR_MIN (0+L'\0') -#else -#define WCHAR_MAX (0x7fffffff+L'\0') -#define WCHAR_MIN (-1-0x7fffffff+L'\0') -#endif - -#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ -#if __cplusplus >= 201103L -#define NULL nullptr -#elif defined(__cplusplus) -#define NULL 0L -#else -#define NULL ((void*)0) -#endif -#else -#define __need_NULL -#include -#endif - -#undef WEOF -#define WEOF 0xffffffffU - -wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -int wcscmp (const wchar_t *, const wchar_t *); -int wcsncmp (const wchar_t *, const wchar_t *, size_t); - -int wcscoll(const wchar_t *, const wchar_t *); -size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); - -wchar_t *wcschr (const wchar_t *, wchar_t); -wchar_t *wcsrchr (const wchar_t *, wchar_t); - -size_t wcscspn (const wchar_t *, const wchar_t *); -size_t wcsspn (const wchar_t *, const wchar_t *); -wchar_t *wcspbrk (const wchar_t *, const wchar_t *); - -wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); - -size_t wcslen (const wchar_t *); - -wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcswcs (const wchar_t *, const wchar_t *); - -wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); -int wmemcmp (const wchar_t *, const wchar_t *, size_t); -wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); -wchar_t *wmemset (wchar_t *, wchar_t, size_t); - -wint_t btowc (int); -int wctob (wint_t); - -int mbsinit (const mbstate_t *); -size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); -size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); - -size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); - -size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); -size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); - -float wcstof (const wchar_t *__restrict, wchar_t **__restrict); -double wcstod (const wchar_t *__restrict, wchar_t **__restrict); -long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); - -long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); -unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); - -long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); -unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); - - - -int fwide (FILE *, int); - - -int wprintf (const wchar_t *__restrict, ...); -int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); -int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); - -int vwprintf (const wchar_t *__restrict, __isoc_va_list); -int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); -int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); - -int wscanf (const wchar_t *__restrict, ...); -int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); -int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); - -int vwscanf (const wchar_t *__restrict, __isoc_va_list); -int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); -int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); - -wint_t fgetwc (FILE *); -wint_t getwc (FILE *); -wint_t getwchar (void); - -wint_t fputwc (wchar_t, FILE *); -wint_t putwc (wchar_t, FILE *); -wint_t putwchar (wchar_t); - -wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); -int fputws (const wchar_t *__restrict, FILE *__restrict); - -wint_t ungetwc (wint_t, FILE *); - -struct tm; -size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); - -#undef iswdigit - -#if defined(_GNU_SOURCE) -wint_t fgetwc_unlocked (FILE *); -wint_t getwc_unlocked (FILE *); -wint_t getwchar_unlocked (void); -wint_t fputwc_unlocked (wchar_t, FILE *); -wint_t putwc_unlocked (wchar_t, FILE *); -wint_t putwchar_unlocked (wchar_t); -wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); -int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); -#endif - -#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); -#endif - -#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ - || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -FILE *open_wmemstream(wchar_t **, size_t *); -size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); -size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); -wchar_t *wcsdup(const wchar_t *); -size_t wcsnlen (const wchar_t *, size_t); -wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); -wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); -int wcscasecmp(const wchar_t *, const wchar_t *); -int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); -int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); -int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); -int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); -size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); -#endif - -#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) -int wcwidth (wchar_t); -int wcswidth (const wchar_t *, size_t); -int iswalnum(wint_t); -int iswalpha(wint_t); -int iswblank(wint_t); -int iswcntrl(wint_t); -int iswdigit(wint_t); -int iswgraph(wint_t); -int iswlower(wint_t); -int iswprint(wint_t); -int iswpunct(wint_t); -int iswspace(wint_t); -int iswupper(wint_t); -int iswxdigit(wint_t); -int iswctype(wint_t, wctype_t); -wint_t towlower(wint_t); -wint_t towupper(wint_t); -wctype_t wctype(const char *); - -#ifndef __cplusplus -#undef iswdigit -#define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) -#endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/conf/fpathconf.c b/lib/libc/wasi/libc-top-half/musl/src/conf/fpathconf.c deleted file mode 100644 index 058b62aee953418116c863df60b41181817146f7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/conf/fpathconf.c +++ /dev/null @@ -1,39 +0,0 @@ -#include -#include -#include - -long fpathconf(int fd, int name) -{ - static const short values[] = { - [_PC_LINK_MAX] = _POSIX_LINK_MAX, - [_PC_MAX_CANON] = _POSIX_MAX_CANON, - [_PC_MAX_INPUT] = _POSIX_MAX_INPUT, - [_PC_NAME_MAX] = NAME_MAX, - [_PC_PATH_MAX] = PATH_MAX, -#ifdef __wasilibc_unmodified_upstream // WASI has no pipes - [_PC_PIPE_BUF] = PIPE_BUF, -#else - [_PC_PIPE_BUF] = -1, -#endif - [_PC_CHOWN_RESTRICTED] = 1, - [_PC_NO_TRUNC] = 1, - [_PC_VDISABLE] = 0, - [_PC_SYNC_IO] = 1, - [_PC_ASYNC_IO] = -1, - [_PC_PRIO_IO] = -1, - [_PC_SOCK_MAXBUF] = -1, - [_PC_FILESIZEBITS] = FILESIZEBITS, - [_PC_REC_INCR_XFER_SIZE] = 4096, - [_PC_REC_MAX_XFER_SIZE] = 4096, - [_PC_REC_MIN_XFER_SIZE] = 4096, - [_PC_REC_XFER_ALIGN] = 4096, - [_PC_ALLOC_SIZE_MIN] = 4096, - [_PC_SYMLINK_MAX] = -1, - [_PC_2_SYMLINKS] = 1 - }; - if (name >= sizeof(values)/sizeof(values[0])) { - errno = EINVAL; - return -1; - } - return values[name]; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/conf/sysconf.c b/lib/libc/wasi/libc-top-half/musl/src/conf/sysconf.c deleted file mode 100644 index a935853cbd8bfcb6bcdf90227679db3cf47bffc1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/conf/sysconf.c +++ /dev/null @@ -1,297 +0,0 @@ -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // WASI has no process-level accounting -#include -#endif -#ifdef __wasilibc_unmodified_upstream // WASI has no realtime signals -#include -#endif -#include -#ifdef __wasilibc_unmodified_upstream -#include -#include "syscall.h" -#endif -#include "libc.h" - -#define JT(x) (-256|(x)) -#define VER JT(1) -#define JT_ARG_MAX JT(2) -#ifdef __wasilibc_unmodified_upstream // WASI has no mq -#define JT_MQ_PRIO_MAX JT(3) -#endif -#define JT_PAGE_SIZE JT(4) -#ifdef __wasilibc_unmodified_upstream // WASI has no semaphores -#define JT_SEM_VALUE_MAX JT(5) -#endif -#define JT_NPROCESSORS_CONF JT(6) -#define JT_NPROCESSORS_ONLN JT(7) -#define JT_PHYS_PAGES JT(8) -#define JT_AVPHYS_PAGES JT(9) -#define JT_ZERO JT(10) -#define JT_DELAYTIMER_MAX JT(11) -#define JT_MINSIGSTKSZ JT(12) -#define JT_SIGSTKSZ JT(13) - -#define RLIM(x) (-32768|(RLIMIT_ ## x)) - -long sysconf(int name) -{ - static const short values[] = { - [_SC_ARG_MAX] = JT_ARG_MAX, -#ifdef __wasilibc_unmodified_upstream // WASI has no processes - [_SC_CHILD_MAX] = RLIM(NPROC), -#else - // Not supported on wasi. - [_SC_CHILD_MAX] = -1, -#endif - [_SC_CLK_TCK] = 100, - [_SC_NGROUPS_MAX] = 32, -#ifdef __wasilibc_unmodified_upstream // WASI has no rlimit - [_SC_OPEN_MAX] = RLIM(NOFILE), -#else - // Rlimit is not supported on wasi. - [_SC_OPEN_MAX] = -1, -#endif - - [_SC_STREAM_MAX] = -1, - [_SC_TZNAME_MAX] = TZNAME_MAX, - [_SC_JOB_CONTROL] = 1, - [_SC_SAVED_IDS] = 1, - [_SC_REALTIME_SIGNALS] = VER, - [_SC_PRIORITY_SCHEDULING] = -1, - [_SC_TIMERS] = VER, - [_SC_ASYNCHRONOUS_IO] = VER, - [_SC_PRIORITIZED_IO] = -1, - [_SC_SYNCHRONIZED_IO] = -1, - [_SC_FSYNC] = VER, - [_SC_MAPPED_FILES] = VER, - [_SC_MEMLOCK] = VER, - [_SC_MEMLOCK_RANGE] = VER, - [_SC_MEMORY_PROTECTION] = VER, - [_SC_MESSAGE_PASSING] = VER, - [_SC_SEMAPHORES] = VER, - [_SC_SHARED_MEMORY_OBJECTS] = VER, - [_SC_AIO_LISTIO_MAX] = -1, - [_SC_AIO_MAX] = -1, - [_SC_AIO_PRIO_DELTA_MAX] = JT_ZERO, /* ?? */ - [_SC_DELAYTIMER_MAX] = JT_DELAYTIMER_MAX, -#ifdef __wasilibc_unmodified_upstream // WASI has no mq - [_SC_MQ_OPEN_MAX] = -1, - [_SC_MQ_PRIO_MAX] = JT_MQ_PRIO_MAX, -#endif - [_SC_VERSION] = VER, - [_SC_PAGE_SIZE] = JT_PAGE_SIZE, -#ifdef __wasilibc_unmodified_upstream // WASI has no realtime signals - [_SC_RTSIG_MAX] = _NSIG - 1 - 31 - 3, -#else - // Not supported on wasi. - [_SC_RTSIG_MAX] = -1, -#endif -#ifdef __wasilibc_unmodified_upstream // WASI has no semaphores - [_SC_SEM_NSEMS_MAX] = SEM_NSEMS_MAX, - [_SC_SEM_VALUE_MAX] = JT_SEM_VALUE_MAX, -#else - [_SC_SEM_NSEMS_MAX] = -1, - [_SC_SEM_VALUE_MAX] = -1, -#endif - [_SC_SIGQUEUE_MAX] = -1, - [_SC_TIMER_MAX] = -1, -#ifdef __wasilibc_unmodified_upstream // WASI has no shell commands - [_SC_BC_BASE_MAX] = _POSIX2_BC_BASE_MAX, - [_SC_BC_DIM_MAX] = _POSIX2_BC_DIM_MAX, - [_SC_BC_SCALE_MAX] = _POSIX2_BC_SCALE_MAX, - [_SC_BC_STRING_MAX] = _POSIX2_BC_STRING_MAX, -#else - [_SC_BC_BASE_MAX] = -1, - [_SC_BC_DIM_MAX] = -1, - [_SC_BC_SCALE_MAX] = -1, - [_SC_BC_STRING_MAX] = -1, -#endif - [_SC_COLL_WEIGHTS_MAX] = COLL_WEIGHTS_MAX, - [_SC_EXPR_NEST_MAX] = -1, - [_SC_LINE_MAX] = -1, - [_SC_RE_DUP_MAX] = RE_DUP_MAX, - [_SC_2_VERSION] = VER, - [_SC_2_C_BIND] = VER, - [_SC_2_C_DEV] = -1, - [_SC_2_FORT_DEV] = -1, - [_SC_2_FORT_RUN] = -1, - [_SC_2_SW_DEV] = -1, - [_SC_2_LOCALEDEF] = -1, - [_SC_IOV_MAX] = IOV_MAX, - [_SC_THREADS] = VER, - [_SC_THREAD_SAFE_FUNCTIONS] = VER, - [_SC_GETGR_R_SIZE_MAX] = -1, - [_SC_GETPW_R_SIZE_MAX] = -1, - [_SC_LOGIN_NAME_MAX] = 256, - [_SC_TTY_NAME_MAX] = TTY_NAME_MAX, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - [_SC_THREAD_DESTRUCTOR_ITERATIONS] = PTHREAD_DESTRUCTOR_ITERATIONS, - [_SC_THREAD_KEYS_MAX] = PTHREAD_KEYS_MAX, - [_SC_THREAD_STACK_MIN] = PTHREAD_STACK_MIN, -#else - [_SC_THREAD_DESTRUCTOR_ITERATIONS] = -1, - [_SC_THREAD_KEYS_MAX] = -1, - [_SC_THREAD_STACK_MIN] = -1, -#endif - [_SC_THREAD_THREADS_MAX] = -1, - [_SC_THREAD_ATTR_STACKADDR] = VER, - [_SC_THREAD_ATTR_STACKSIZE] = VER, - [_SC_THREAD_PRIORITY_SCHEDULING] = VER, - [_SC_THREAD_PRIO_INHERIT] = -1, - [_SC_THREAD_PRIO_PROTECT] = -1, - [_SC_THREAD_PROCESS_SHARED] = VER, - [_SC_NPROCESSORS_CONF] = JT_NPROCESSORS_CONF, - [_SC_NPROCESSORS_ONLN] = JT_NPROCESSORS_ONLN, - [_SC_PHYS_PAGES] = JT_PHYS_PAGES, - [_SC_AVPHYS_PAGES] = JT_AVPHYS_PAGES, - [_SC_ATEXIT_MAX] = -1, - [_SC_PASS_MAX] = -1, - [_SC_XOPEN_VERSION] = _XOPEN_VERSION, - [_SC_XOPEN_XCU_VERSION] = _XOPEN_VERSION, - [_SC_XOPEN_UNIX] = 1, - [_SC_XOPEN_CRYPT] = -1, - [_SC_XOPEN_ENH_I18N] = 1, - [_SC_XOPEN_SHM] = 1, - [_SC_2_CHAR_TERM] = -1, - [_SC_2_UPE] = -1, - [_SC_XOPEN_XPG2] = -1, - [_SC_XOPEN_XPG3] = -1, - [_SC_XOPEN_XPG4] = -1, - [_SC_NZERO] = NZERO, - [_SC_XBS5_ILP32_OFF32] = -1, - [_SC_XBS5_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, - [_SC_XBS5_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, - [_SC_XBS5_LPBIG_OFFBIG] = -1, - [_SC_XOPEN_LEGACY] = -1, - [_SC_XOPEN_REALTIME] = -1, - [_SC_XOPEN_REALTIME_THREADS] = -1, - [_SC_ADVISORY_INFO] = VER, - [_SC_BARRIERS] = VER, - [_SC_CLOCK_SELECTION] = VER, - [_SC_CPUTIME] = VER, - [_SC_THREAD_CPUTIME] = VER, - [_SC_MONOTONIC_CLOCK] = VER, - [_SC_READER_WRITER_LOCKS] = VER, - [_SC_SPIN_LOCKS] = VER, - [_SC_REGEXP] = 1, - [_SC_SHELL] = 1, - [_SC_SPAWN] = VER, - [_SC_SPORADIC_SERVER] = -1, - [_SC_THREAD_SPORADIC_SERVER] = -1, - [_SC_TIMEOUTS] = VER, - [_SC_TYPED_MEMORY_OBJECTS] = -1, - [_SC_2_PBS] = -1, - [_SC_2_PBS_ACCOUNTING] = -1, - [_SC_2_PBS_LOCATE] = -1, - [_SC_2_PBS_MESSAGE] = -1, - [_SC_2_PBS_TRACK] = -1, - [_SC_SYMLOOP_MAX] = SYMLOOP_MAX, - [_SC_STREAMS] = JT_ZERO, - [_SC_2_PBS_CHECKPOINT] = -1, - [_SC_V6_ILP32_OFF32] = -1, - [_SC_V6_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, - [_SC_V6_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, - [_SC_V6_LPBIG_OFFBIG] = -1, - [_SC_HOST_NAME_MAX] = HOST_NAME_MAX, - [_SC_TRACE] = -1, - [_SC_TRACE_EVENT_FILTER] = -1, - [_SC_TRACE_INHERIT] = -1, - [_SC_TRACE_LOG] = -1, - - [_SC_IPV6] = VER, - [_SC_RAW_SOCKETS] = VER, - [_SC_V7_ILP32_OFF32] = -1, - [_SC_V7_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, - [_SC_V7_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, - [_SC_V7_LPBIG_OFFBIG] = -1, - [_SC_SS_REPL_MAX] = -1, - [_SC_TRACE_EVENT_NAME_MAX] = -1, - [_SC_TRACE_NAME_MAX] = -1, - [_SC_TRACE_SYS_MAX] = -1, - [_SC_TRACE_USER_EVENT_MAX] = -1, - [_SC_XOPEN_STREAMS] = JT_ZERO, - [_SC_THREAD_ROBUST_PRIO_INHERIT] = -1, - [_SC_THREAD_ROBUST_PRIO_PROTECT] = -1, - - [_SC_MINSIGSTKSZ] = JT_MINSIGSTKSZ, - [_SC_SIGSTKSZ] = JT_SIGSTKSZ, - }; - - if (name >= sizeof(values)/sizeof(values[0]) || !values[name]) { - errno = EINVAL; - return -1; - } else if (values[name] >= -1) { - return values[name]; - } else if (values[name] < -256) { -#ifdef __wasilibc_unmodified_upstream // WASI has no getrlimit - struct rlimit lim; - getrlimit(values[name]&16383, &lim); - if (lim.rlim_cur == RLIM_INFINITY) - return -1; - return lim.rlim_cur > LONG_MAX ? LONG_MAX : lim.rlim_cur; -#else - // Not supported on wasi. - errno = EINVAL; - return -1; -#endif - } - - switch ((unsigned char)values[name]) { - case VER & 255: - return _POSIX_VERSION; - case JT_ARG_MAX & 255: - return ARG_MAX; -#ifdef __wasilibc_unmodified_upstream // WASI has no mq - case JT_MQ_PRIO_MAX & 255: - return MQ_PRIO_MAX; -#endif - case JT_PAGE_SIZE & 255: - return PAGE_SIZE; -#ifdef __wasilibc_unmodified_upstream // WASI has no semaphores - case JT_SEM_VALUE_MAX & 255: - return SEM_VALUE_MAX; -#endif - case JT_DELAYTIMER_MAX & 255: - return DELAYTIMER_MAX; - case JT_NPROCESSORS_CONF & 255: - case JT_NPROCESSORS_ONLN & 255: ; -#ifdef __wasilibc_unmodified_upstream - unsigned char set[128] = {1}; - int i, cnt; - __syscall(SYS_sched_getaffinity, 0, sizeof set, set); - for (i=cnt=0; i LONG_MAX) ? LONG_MAX : mem; -#endif - case JT_ZERO & 255: - return 0; - } -#ifdef __wasilibc_unmodified_upstream // WASI has no auxv - case JT_MINSIGSTKSZ & 255: - case JT_SIGSTKSZ & 255: ; - long val = __getauxval(AT_MINSIGSTKSZ); - if (val < MINSIGSTKSZ) val = MINSIGSTKSZ; - if (values[name] == JT_SIGSTKSZ) - val += SIGSTKSZ - MINSIGSTKSZ; - return val; -#endif - return values[name]; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/dirent/alphasort.c b/lib/libc/wasi/libc-top-half/musl/src/dirent/alphasort.c deleted file mode 100644 index bee672ebda0c510b2ea57335c69b06baf421f401..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/dirent/alphasort.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -int alphasort(const struct dirent **a, const struct dirent **b) -{ - return strcoll((*a)->d_name, (*b)->d_name); -} - -weak_alias(alphasort, alphasort64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/dirent/versionsort.c b/lib/libc/wasi/libc-top-half/musl/src/dirent/versionsort.c deleted file mode 100644 index d4c489230abb864c167d910078a4cda9c6ef2655..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/dirent/versionsort.c +++ /dev/null @@ -1,11 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -int versionsort(const struct dirent **a, const struct dirent **b) -{ - return strverscmp((*a)->d_name, (*b)->d_name); -} - -#undef versionsort64 -weak_alias(versionsort, versionsort64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c b/lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c deleted file mode 100644 index 7c39c22e680ea4d07ec6ef4c19a15b5a088d2f71..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c +++ /dev/null @@ -1,59 +0,0 @@ -#include -#include -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include "pthread_impl.h" -#else -// In non-_REENTRANT, include it for `a_crash` -# include "atomic.h" -#endif - -uintptr_t __stack_chk_guard; - -void __init_ssp(void *entropy) -{ - if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t)); - else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245; - -#if UINTPTR_MAX >= 0xffffffffffffffff - /* Sacrifice 8 bits of entropy on 64bit to prevent leaking/ - * overwriting the canary via string-manipulation functions. - * The NULL byte is on the second byte so that off-by-ones can - * still be detected. Endianness is taken care of - * automatically. */ - ((char *)&__stack_chk_guard)[1] = 0; -#endif - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - __pthread_self()->canary = __stack_chk_guard; -#endif -} - -void __stack_chk_fail(void) -{ - a_crash(); -} - -hidden void __stack_chk_fail_local(void); - -weak_alias(__stack_chk_fail, __stack_chk_fail_local); - -#ifndef __wasilibc_unmodified_upstream -#ifdef __wasilibc_use_wasip2 -# include -#else -# include -#endif - -__attribute__((constructor(60))) -static void __wasilibc_init_ssp(void) { - uintptr_t entropy; -#ifdef __wasilibc_use_wasip2 - int len = sizeof(uintptr_t); - - int r = __wasilibc_random(&entropy, len); -#else - int r = __wasi_random_get((uint8_t *)&entropy, sizeof(uintptr_t)); -#endif - __init_ssp(r ? NULL : &entropy); -} -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/env/clearenv.c b/lib/libc/wasi/libc-top-half/musl/src/env/clearenv.c deleted file mode 100644 index 0abbec30207a63e38006b62947dd10a57bf37892..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/env/clearenv.c +++ /dev/null @@ -1,21 +0,0 @@ -#define _GNU_SOURCE -#include -#include - -static void dummy(char *old, char *new) {} -weak_alias(dummy, __env_rm_add); - -int clearenv() -{ -#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. -#else -// This specialized header is included within the function body to arranges for -// the environment variables to be lazily initialized. It redefined `__environ`, -// so don't remove or reorder it with respect to other code. -#include "wasi/libc-environ-compat.h" -#endif - char **e = __environ; - __environ = 0; - if (e) while (*e) __env_rm_add(*e++, 0); - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/env/getenv.c b/lib/libc/wasi/libc-top-half/musl/src/env/getenv.c deleted file mode 100644 index 346c333f8d0ab68c71a9cc47d7652ee20da28fd6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/env/getenv.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include -#include - -char *getenv(const char *name) -{ -#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. -#else -// This specialized header is included within the function body to arranges for -// the environment variables to be lazily initialized. It redefined `__environ`, -// so don't remove or reorder it with respect to other code. -#include "wasi/libc-environ-compat.h" -#endif - size_t l = __strchrnul(name, '=') - name; - if (l && !name[l] && __environ) - for (char **e = __environ; *e; e++) - if (!strncmp(name, *e, l) && l[*e] == '=') - return *e + l+1; - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/env/putenv.c b/lib/libc/wasi/libc-top-half/musl/src/env/putenv.c deleted file mode 100644 index 0d5989541af8341e21d3ed6a15288868dd7308bb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/env/putenv.c +++ /dev/null @@ -1,53 +0,0 @@ -#include -#include -#include - -static void dummy(char *old, char *new) {} -weak_alias(dummy, __env_rm_add); - -int __putenv(char *s, size_t l, char *r) -{ -#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. -#else -// This specialized header is included within the function body to arranges for -// the environment variables to be lazily initialized. It redefined `__environ`, -// so don't remove or reorder it with respect to other code. -#include "wasi/libc-environ-compat.h" -#endif - size_t i=0; - if (__environ) { - for (char **e = __environ; *e; e++, i++) - if (!strncmp(s, *e, l+1)) { - char *tmp = *e; - *e = s; - __env_rm_add(tmp, r); - return 0; - } - } - static char **oldenv; - char **newenv; - if (__environ == oldenv) { - newenv = realloc(oldenv, sizeof *newenv * (i+2)); - if (!newenv) goto oom; - } else { - newenv = malloc(sizeof *newenv * (i+2)); - if (!newenv) goto oom; - if (i) memcpy(newenv, __environ, sizeof *newenv * i); - free(oldenv); - } - newenv[i] = s; - newenv[i+1] = 0; - __environ = oldenv = newenv; - if (r) __env_rm_add(0, r); - return 0; -oom: - free(r); - return -1; -} - -int putenv(char *s) -{ - size_t l = __strchrnul(s, '=') - s; - if (!l || !s[l]) return unsetenv(s); - return __putenv(s, l, 0); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/env/unsetenv.c b/lib/libc/wasi/libc-top-half/musl/src/env/unsetenv.c deleted file mode 100644 index 40f0eea6d8a75fd5881a9eedaee61dc01376687f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/env/unsetenv.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include -#include -#include - -static void dummy(char *old, char *new) {} -weak_alias(dummy, __env_rm_add); - -int unsetenv(const char *name) -{ - size_t l = __strchrnul(name, '=') - name; - if (!l || name[l]) { - errno = EINVAL; - return -1; - } -#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. -#else -// This specialized header is included within the function body to arranges for -// the environment variables to be lazily initialized. It redefined `__environ`, -// so don't remove or reorder it with respect to other code. -#include "wasi/libc-environ-compat.h" -#endif - if (__environ) { - char **e = __environ, **eo = e; - for (; *e; e++) - if (!strncmp(name, *e, l) && l[*e] == '=') - __env_rm_add(*e, 0); - else if (eo != e) - *eo++ = *e; - else - eo++; - if (eo != e) *eo = 0; - } - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/errno/__strerror.h b/lib/libc/wasi/libc-top-half/musl/src/errno/__strerror.h deleted file mode 100644 index bd6dccbe2d3fdf63134ddb5d291ae423978cd8e6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/errno/__strerror.h +++ /dev/null @@ -1,137 +0,0 @@ -/* The first entry is a catch-all for codes not enumerated here. - * This file is included multiple times to declare and define a structure - * with these messages, and then to define a lookup table translating - * error codes to offsets of corresponding fields in the structure. */ - -#ifdef __wasilibc_unmodified_upstream // Print "Success" for ESUCCESS. -E(0, "No error information") -#else -E(0, "Success") -#endif - -E(EILSEQ, "Illegal byte sequence") -E(EDOM, "Domain error") -E(ERANGE, "Result not representable") - -E(ENOTTY, "Not a tty") -E(EACCES, "Permission denied") -E(EPERM, "Operation not permitted") -E(ENOENT, "No such file or directory") -E(ESRCH, "No such process") -E(EEXIST, "File exists") - -E(EOVERFLOW, "Value too large for data type") -E(ENOSPC, "No space left on device") -E(ENOMEM, "Out of memory") - -E(EBUSY, "Resource busy") -E(EINTR, "Interrupted system call") -E(EAGAIN, "Resource temporarily unavailable") -E(ESPIPE, "Invalid seek") - -E(EXDEV, "Cross-device link") -E(EROFS, "Read-only file system") -E(ENOTEMPTY, "Directory not empty") - -E(ECONNRESET, "Connection reset by peer") -E(ETIMEDOUT, "Operation timed out") -E(ECONNREFUSED, "Connection refused") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(EHOSTDOWN, "Host is down") -#endif -E(EHOSTUNREACH, "Host is unreachable") -E(EADDRINUSE, "Address in use") - -E(EPIPE, "Broken pipe") -E(EIO, "I/O error") -E(ENXIO, "No such device or address") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(ENOTBLK, "Block device required") -#endif -E(ENODEV, "No such device") -E(ENOTDIR, "Not a directory") -E(EISDIR, "Is a directory") -E(ETXTBSY, "Text file busy") -E(ENOEXEC, "Exec format error") - -E(EINVAL, "Invalid argument") - -E(E2BIG, "Argument list too long") -E(ELOOP, "Symbolic link loop") -E(ENAMETOOLONG, "Filename too long") -E(ENFILE, "Too many open files in system") -E(EMFILE, "No file descriptors available") -E(EBADF, "Bad file descriptor") -E(ECHILD, "No child process") -E(EFAULT, "Bad address") -E(EFBIG, "File too large") -E(EMLINK, "Too many links") -E(ENOLCK, "No locks available") - -E(EDEADLK, "Resource deadlock would occur") -E(ENOTRECOVERABLE, "State not recoverable") -E(EOWNERDEAD, "Previous owner died") -E(ECANCELED, "Operation canceled") -E(ENOSYS, "Function not implemented") -E(ENOMSG, "No message of desired type") -E(EIDRM, "Identifier removed") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(ENOSTR, "Device not a stream") -E(ENODATA, "No data available") -E(ETIME, "Device timeout") -E(ENOSR, "Out of streams resources") -#endif -E(ENOLINK, "Link has been severed") -E(EPROTO, "Protocol error") -E(EBADMSG, "Bad message") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(EBADFD, "File descriptor in bad state") -#endif -E(ENOTSOCK, "Not a socket") -E(EDESTADDRREQ, "Destination address required") -E(EMSGSIZE, "Message too large") -E(EPROTOTYPE, "Protocol wrong type for socket") -E(ENOPROTOOPT, "Protocol not available") -E(EPROTONOSUPPORT,"Protocol not supported") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(ESOCKTNOSUPPORT,"Socket type not supported") -#endif -E(ENOTSUP, "Not supported") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(EPFNOSUPPORT, "Protocol family not supported") -#endif -E(EAFNOSUPPORT, "Address family not supported by protocol") -E(EADDRNOTAVAIL,"Address not available") -E(ENETDOWN, "Network is down") -E(ENETUNREACH, "Network unreachable") -E(ENETRESET, "Connection reset by network") -E(ECONNABORTED, "Connection aborted") -E(ENOBUFS, "No buffer space available") -E(EISCONN, "Socket is connected") -E(ENOTCONN, "Socket not connected") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(ESHUTDOWN, "Cannot send after socket shutdown") -#endif -E(EALREADY, "Operation already in progress") -E(EINPROGRESS, "Operation in progress") -E(ESTALE, "Stale file handle") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(EREMOTEIO, "Remote I/O error") -#endif -E(EDQUOT, "Quota exceeded") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(ENOMEDIUM, "No medium found") -E(EMEDIUMTYPE, "Wrong medium type") -#endif -E(EMULTIHOP, "Multihop attempted") -#ifdef __wasilibc_unmodified_upstream // errno value not in WASI -E(ENOKEY, "Required key not available") -E(EKEYEXPIRED, "Key has expired") -E(EKEYREVOKED, "Key has been revoked") -E(EKEYREJECTED, "Key was rejected by service") -#endif -#ifdef __wasilibc_unmodified_upstream // errno value in WASI and not musl -#else -// WASI adds this errno code. -E(ENOTCAPABLE, "Capabilities insufficient") -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/errno/strerror.c b/lib/libc/wasi/libc-top-half/musl/src/errno/strerror.c deleted file mode 100644 index 7f926432b3090190f0288ecd2caa27c75daf80a9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/errno/strerror.c +++ /dev/null @@ -1,47 +0,0 @@ -#include -#include -#include -#include "locale_impl.h" - -/* mips has one error code outside of the 8-bit range due to a - * historical typo, so we just remap it. */ -#if EDQUOT==1133 -#define EDQUOT_ORIG 1133 -#undef EDQUOT -#define EDQUOT 109 -#endif - -static const struct errmsgstr_t { -#define E(n, s) char str##n[sizeof(s)]; -#include "__strerror.h" -#undef E -} errmsgstr = { -#define E(n, s) s, -#include "__strerror.h" -#undef E -}; - -static const unsigned short errmsgidx[] = { -#define E(n, s) [n] = offsetof(struct errmsgstr_t, str##n), -#include "__strerror.h" -#undef E -}; - -char *__strerror_l(int e, locale_t loc) -{ - const char *s; -#ifdef EDQUOT_ORIG - if (e==EDQUOT) e=0; - else if (e==EDQUOT_ORIG) e=EDQUOT; -#endif - if (e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0; - s = (char *)&errmsgstr + errmsgidx[e]; - return (char *)LCTRANS(s, LC_MESSAGES, loc); -} - -char *strerror(int e) -{ - return __strerror_l(e, CURRENT_LOCALE); -} - -weak_alias(__strerror_l, strerror_l); diff --git a/lib/libc/wasi/libc-top-half/musl/src/exit/at_quick_exit.c b/lib/libc/wasi/libc-top-half/musl/src/exit/at_quick_exit.c deleted file mode 100644 index 429d0b033004b257f0259ecc49a5f3965b325584..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/exit/at_quick_exit.c +++ /dev/null @@ -1,35 +0,0 @@ -#include -#include "libc.h" -#include "lock.h" -#include "fork_impl.h" - -#define COUNT 32 - -static void (*funcs[COUNT])(void); -static int count; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -static volatile int lock[1]; -volatile int *const __at_quick_exit_lockptr = lock; -#endif - -void __funcs_on_quick_exit() -{ - void (*func)(void); - LOCK(lock); - while (count > 0) { - func = funcs[--count]; - UNLOCK(lock); - func(); - LOCK(lock); - } -} - -int at_quick_exit(void (*func)(void)) -{ - int r = 0; - LOCK(lock); - if (count == 32) r = -1; - else funcs[count++] = func; - UNLOCK(lock); - return r; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/exit/atexit.c b/lib/libc/wasi/libc-top-half/musl/src/exit/atexit.c deleted file mode 100644 index 30f897b7eae8478a67cebc7c0b804ffcc78ced73..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/exit/atexit.c +++ /dev/null @@ -1,77 +0,0 @@ -#include -#include -#include "libc.h" -#include "lock.h" -#include "fork_impl.h" - -/* Ensure that at least 32 atexit handlers can be registered without malloc */ -#define COUNT 32 - -static struct fl -{ - struct fl *next; - void (*f[COUNT])(void *); - void *a[COUNT]; -} builtin, *head; - -static int slot; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -static volatile int lock[1]; -volatile int *const __atexit_lockptr = lock; -#endif - -void __funcs_on_exit() -{ - void (*func)(void *), *arg; - LOCK(lock); - for (; head; head=head->next, slot=COUNT) while(slot-->0) { - func = head->f[slot]; - arg = head->a[slot]; - UNLOCK(lock); - func(arg); - LOCK(lock); - } -} - -void __cxa_finalize(void *dso) -{ -} - -int __cxa_atexit(void (*func)(void *), void *arg, void *dso) -{ - LOCK(lock); - - /* Defer initialization of head so it can be in BSS */ - if (!head) head = &builtin; - - /* If the current function list is full, add a new one */ - if (slot==COUNT) { - struct fl *new_fl = calloc(sizeof(struct fl), 1); - if (!new_fl) { - UNLOCK(lock); - return -1; - } - new_fl->next = head; - head = new_fl; - slot = 0; - } - - /* Append function to the list. */ - head->f[slot] = func; - head->a[slot] = arg; - slot++; - - UNLOCK(lock); - return 0; -} - -static void call(void *p) -{ - ((void (*)(void))(uintptr_t)p)(); -} - -int atexit(void (*func)(void)) -{ - return __cxa_atexit(call, (void *)(uintptr_t)func, 0); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/exit/exit.c b/lib/libc/wasi/libc-top-half/musl/src/exit/exit.c deleted file mode 100644 index 1536d7dc0d90e047e4545026262bfe9f17f0e92b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/exit/exit.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#include -#include "libc.h" - -static void dummy() -{ -} - -/* atexit.c and __stdio_exit.c override these. the latter is linked - * as a consequence of linking either __toread.c or __towrite.c. */ -weak_alias(dummy, __funcs_on_exit); -weak_alias(dummy, __stdio_exit); -#ifdef __wasilibc_unmodified_upstream // fini -weak_alias(dummy, _fini); - -extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void); - -static void libc_exit_fini(void) -{ - uintptr_t a = (uintptr_t)&__fini_array_end; - for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)())) - (*(void (**)())(a-sizeof(void(*)())))(); - _fini(); -} - -weak_alias(libc_exit_fini, __libc_exit_fini); -#endif - -#ifdef __wasilibc_unmodified_upstream // WASI libc uses a custom exit -_Noreturn void exit(int code) -{ - __funcs_on_exit(); - __libc_exit_fini(); - __stdio_exit(); - _Exit(code); -} -#else -// Split out the cleanup functions so that we can call them without calling -// _Exit if we don't need to. This allows _start to just return if main -// returns 0. -void __wasm_call_dtors(void) -{ - __funcs_on_exit(); - __stdio_exit(); -} - -_Noreturn void exit(int code) -{ - __wasm_call_dtors(); - _Exit(code); -} -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/fcntl/creat.c b/lib/libc/wasi/libc-top-half/musl/src/fcntl/creat.c deleted file mode 100644 index 8f8aab64631cf4c74f1768cf06a4035c7541e97f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/fcntl/creat.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -int creat(const char *filename, mode_t mode) -{ - return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode); -} - -weak_alias(creat, creat64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/arpa/inet.h b/lib/libc/wasi/libc-top-half/musl/src/include/arpa/inet.h deleted file mode 100644 index 1e6debf49669aa9cbf48802f76fa351728b2e43d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/arpa/inet.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef ARPA_INET_H -#define ARPA_INET_H - -#include "../../../include/arpa/inet.h" - -hidden int __inet_aton(const char *, struct in_addr *); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/errno.h b/lib/libc/wasi/libc-top-half/musl/src/include/errno.h deleted file mode 100644 index 70941d855a191b1d6e08f752a585bf71150ffa64..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/errno.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef ERRNO_H -#define ERRNO_H - -#include "../../include/errno.h" - -#ifdef __wasilibc_unmodified_upstream // Use alternate WASI libc headers -#ifdef __GNUC__ -__attribute__((const)) -#endif -hidden int *___errno_location(void); - -#undef errno -#define errno (*___errno_location()) -#else -// Use the WASI libc errno. -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/pthread.h b/lib/libc/wasi/libc-top-half/musl/src/include/pthread.h deleted file mode 100644 index 0aba813e9a47911b96cfbefb35f1660702e70818..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/pthread.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef PTHREAD_H -#define PTHREAD_H - -#include "../../include/pthread.h" - -hidden int __pthread_once(pthread_once_t *, void (*)(void)); -hidden void __pthread_testcancel(void); -hidden int __pthread_setcancelstate(int, int *); -hidden int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict); -#ifdef __wasilibc_unmodified_upstream -hidden _Noreturn void __pthread_exit(void *); -#endif -hidden int __pthread_join(pthread_t, void **); -hidden int __pthread_mutex_lock(pthread_mutex_t *); -hidden int __pthread_mutex_trylock(pthread_mutex_t *); -hidden int __pthread_mutex_trylock_owner(pthread_mutex_t *); -hidden int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict); -hidden int __pthread_mutex_unlock(pthread_mutex_t *); -hidden int __private_cond_signal(pthread_cond_t *, int); -hidden int __pthread_cond_timedwait(pthread_cond_t *restrict, pthread_mutex_t *restrict, const struct timespec *restrict); -hidden int __pthread_key_create(pthread_key_t *, void (*)(void *)); -hidden int __pthread_key_delete(pthread_key_t); -hidden int __pthread_rwlock_rdlock(pthread_rwlock_t *); -hidden int __pthread_rwlock_tryrdlock(pthread_rwlock_t *); -hidden int __pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); -hidden int __pthread_rwlock_wrlock(pthread_rwlock_t *); -hidden int __pthread_rwlock_trywrlock(pthread_rwlock_t *); -hidden int __pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); -hidden int __pthread_rwlock_unlock(pthread_rwlock_t *); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/signal.h b/lib/libc/wasi/libc-top-half/musl/src/include/signal.h deleted file mode 100644 index 46de698d999b9962bb38fe48e8167af347bba66f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/signal.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef SIGNAL_H -#define SIGNAL_H - -#include "../../include/signal.h" - -#ifdef __wasilibc_unmodified_upstream // WASI has no sigaction -hidden int __sigaction(int, const struct sigaction *, struct sigaction *); - -hidden void __block_all_sigs(void *); -hidden void __block_app_sigs(void *); -hidden void __restore_sigs(void *); - -hidden void __get_handler_set(sigset_t *); -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/stdio.h b/lib/libc/wasi/libc-top-half/musl/src/include/stdio.h deleted file mode 100644 index 176a73c2ae9ae3ab6a7d948edb8f0656d753dc1d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/stdio.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#define __DEFINED_struct__IO_FILE -#endif - -#include "../../include/stdio.h" - -#undef stdin -#undef stdout -#undef stderr - -extern hidden FILE __stdin_FILE; -extern hidden FILE __stdout_FILE; -extern hidden FILE __stderr_FILE; - -#define stdin (&__stdin_FILE) -#define stdout (&__stdout_FILE) -#define stderr (&__stderr_FILE) - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/stdlib.h b/lib/libc/wasi/libc-top-half/musl/src/include/stdlib.h deleted file mode 100644 index 1599691fbeec4d037674c309a03dccec1e12db36..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/stdlib.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef STDLIB_H -#define STDLIB_H - -#include "../../include/stdlib.h" - -hidden int __putenv(char *, size_t, char *); -hidden void __env_rm_add(char *, char *); -hidden int __mkostemps(char *, int, int); -hidden int __ptsname_r(int, char *, size_t); -hidden char *__randname(char *); -hidden void __qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/string.h b/lib/libc/wasi/libc-top-half/musl/src/include/string.h deleted file mode 100644 index 2133b5c1eead4f94b5cb7f9a70c21788678cd3be..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/string.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef STRING_H -#define STRING_H - -#include "../../include/string.h" - -hidden void *__memrchr(const void *, int, size_t); -hidden char *__stpcpy(char *, const char *); -hidden char *__stpncpy(char *, const char *, size_t); -hidden char *__strchrnul(const char *, int); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/sys/mman.h b/lib/libc/wasi/libc-top-half/musl/src/include/sys/mman.h deleted file mode 100644 index 57c5bd3d9621daf1c9d40fde24c0d05f464489b6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/sys/mman.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef SYS_MMAN_H -#define SYS_MMAN_H - -#include "../../../include/sys/mman.h" - -hidden void __vm_wait(void); -hidden void __vm_lock(void); -hidden void __vm_unlock(void); - -hidden void *__mmap(void *, size_t, int, int, int, off_t); -hidden int __munmap(void *, size_t); -hidden void *__mremap(void *, size_t, size_t, int, ...); -hidden int __madvise(void *, size_t, int); -hidden int __mprotect(void *, size_t, int); - -hidden const unsigned char *__map_file(const char *, size_t *); - -hidden char *__shm_mapname(const char *, char *); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/sys/stat.h b/lib/libc/wasi/libc-top-half/musl/src/include/sys/stat.h deleted file mode 100644 index 59339beecb17e2dc4bf7793ce8ed984c138b2f33..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/sys/stat.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef SYS_STAT_H -#define SYS_STAT_H - -#include "../../../include/sys/stat.h" - -hidden int __fstat(int, struct stat *); -hidden int __fstatat(int, const char *restrict, struct stat *restrict, int); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/sys/time.h b/lib/libc/wasi/libc-top-half/musl/src/include/sys/time.h deleted file mode 100644 index fb9622e51fcf9608bcf604794a4a18e0790a2f7a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/sys/time.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef SYS_TIME_H -#define SYS_TIME_H - -#include "../../../include/sys/time.h" - -hidden int __futimesat(int, const char *, const struct timeval [2]); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/time.h b/lib/libc/wasi/libc-top-half/musl/src/include/time.h deleted file mode 100644 index cbabde476790e755cb85210b0194c320256ed027..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/time.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef TIME_H -#define TIME_H - -#include "../../include/time.h" - -hidden int __clock_gettime(clockid_t, struct timespec *); -hidden int __clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); - -hidden char *__asctime_r(const struct tm *, char *); -hidden struct tm *__gmtime_r(const time_t *restrict, struct tm *restrict); -hidden struct tm *__localtime_r(const time_t *restrict, struct tm *restrict); - -hidden size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/unistd.h b/lib/libc/wasi/libc-top-half/musl/src/include/unistd.h deleted file mode 100644 index d02206ec1cbb3de3ce0a527f3464542f7520f428..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/unistd.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef UNISTD_H -#define UNISTD_H - -#include "../../include/unistd.h" - -#ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. -extern char **__environ; -#else -// To support lazy initialization of environment variables, `__environ` is -// omitted, and a lazy `__wasilibc_environ` is used instead. Use -// "wasi/libc-environ-compat.h" in functions that use `__environ`. -#include "wasi/libc-environ.h" -#endif - -hidden int __dup3(int, int, int); -hidden int __mkostemps(char *, int, int); -hidden int __execvpe(const char *, char *const *, char *const *); -hidden off_t __lseek(int, off_t, int); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/include/wchar.h b/lib/libc/wasi/libc-top-half/musl/src/include/wchar.h deleted file mode 100644 index 1814bade087174a785cbce3d371c9afd6724f867..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/include/wchar.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef WCHAR_H -#define WCHAR_H - -#ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ -#define __DEFINED_struct__IO_FILE -#endif - -#include "../../include/wchar.h" - -#endif - diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/complex_impl.h b/lib/libc/wasi/libc-top-half/musl/src/internal/complex_impl.h deleted file mode 100644 index 51fb298acd4d4ef6acabe07b2e54b2c54585575c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/complex_impl.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef _COMPLEX_IMPL_H -#define _COMPLEX_IMPL_H - -#include -#include "libm.h" - -#undef __CMPLX -#undef CMPLX -#undef CMPLXF -#undef CMPLXL - -#define __CMPLX(x, y, t) \ - ((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z) - -#define CMPLX(x, y) __CMPLX(x, y, double) -#define CMPLXF(x, y) __CMPLX(x, y, float) -#define CMPLXL(x, y) __CMPLX(x, y, long double) - -hidden double complex __ldexp_cexp(double complex,int); -hidden float complex __ldexp_cexpf(float complex,int); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/defsysinfo.c b/lib/libc/wasi/libc-top-half/musl/src/internal/defsysinfo.c deleted file mode 100644 index 6d4117dbfa8d3e29e893b27a2db8e96b032d8722..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/defsysinfo.c +++ /dev/null @@ -1,3 +0,0 @@ -#include "libc.h" - -size_t __sysinfo; diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.c b/lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.c deleted file mode 100644 index 4cc6059f438e4368da315a13f12988f0ea1ec3f2..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.c +++ /dev/null @@ -1,556 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -#include "printscan.h" -#endif - -#include "shgetc.h" -#include "floatscan.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 - -#define LD_B1B_DIG 2 -#define LD_B1B_MAX 9007199, 254740991 -#define KMAX 128 - -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - -#define LD_B1B_DIG 3 -#define LD_B1B_MAX 18, 446744073, 709551615 -#define KMAX 2048 - -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 - -#define LD_B1B_DIG 4 -#define LD_B1B_MAX 10384593, 717069655, 257060992, 658440191 -#define KMAX 2048 - -#else -#error Unsupported long double representation -#endif - -#define MASK (KMAX-1) - -static long long scanexp(FILE *f, int pok) -{ - int c; - int x; - long long y; - int neg = 0; - - c = shgetc(f); - if (c=='+' || c=='-') { - neg = (c=='-'); - c = shgetc(f); - if (c-'0'>=10U && pok) shunget(f); - } - if (c-'0'>=10U) { - shunget(f); - return LLONG_MIN; - } - for (x=0; c-'0'<10U && x=0) { - shunget(f); - } - if (!gotdig) { - errno = EINVAL; - shlim(f, 0); - return 0; - } - - /* Handle zero specially to avoid nasty special cases later */ - if (!x[0]) return sign * 0.0; - - /* Optimize small integers (w/no exponent) and over/under-flow */ - if (lrp==dc && dc<10 && (bits>30 || x[0]>>bits==0)) -#if defined(__wasilibc_printscan_no_long_double) - return sign * (long_double)x[0]; -#else - return sign * (long double)x[0]; -#endif - if (lrp > -emin/2) { - errno = ERANGE; - return sign * LDBL_MAX * LDBL_MAX; - } - if (lrp < emin-2*LDBL_MANT_DIG) { - errno = ERANGE; - return sign * LDBL_MIN * LDBL_MIN; - } - - /* Align incomplete final B1B digit */ - if (j) { - for (; j<9; j++) x[k]*=10; - k++; - j=0; - } - - a = 0; - z = k; - e2 = 0; - rp = lrp; - - /* Optimize small to mid-size integers (even in exp. notation) */ - if (lnz<9 && lnz<=rp && rp < 18) { -#if defined(__wasilibc_printscan_no_long_double) - if (rp == 9) return sign * (long_double)x[0]; - if (rp < 9) return sign * (long_double)x[0] / p10s[8-rp]; -#else - if (rp == 9) return sign * (long double)x[0]; - if (rp < 9) return sign * (long double)x[0] / p10s[8-rp]; -#endif - int bitlim = bits-3*(int)(rp-9); - if (bitlim>30 || x[0]>>bitlim==0) -#if defined(__wasilibc_printscan_no_long_double) - return sign * (long_double)x[0] * p10s[rp-10]; -#else - return sign * (long double)x[0] * p10s[rp-10]; -#endif - } - - /* Drop trailing zeros */ - for (; !x[z-1]; z--); - - /* Align radix point to B1B digit boundary */ - if (rp % 9) { - int rpm9 = rp>=0 ? rp%9 : rp%9+9; - int p10 = p10s[8-rpm9]; - uint32_t carry = 0; - for (k=a; k!=z; k++) { - uint32_t tmp = x[k] % p10; - x[k] = x[k]/p10 + carry; - carry = 1000000000/p10 * tmp; - if (k==a && !x[k]) { - a = (a+1 & MASK); - rp -= 9; - } - } - if (carry) x[z++] = carry; - rp += 9-rpm9; - } - - /* Upscale until desired number of bits are left of radix point */ - while (rp < 9*LD_B1B_DIG || (rp == 9*LD_B1B_DIG && x[a] 1000000000) { - carry = tmp / 1000000000; - x[k] = tmp % 1000000000; - } else { - carry = 0; - x[k] = tmp; - } - if (k==(z-1 & MASK) && k!=a && !x[k]) z = k; - if (k==a) break; - } - if (carry) { - rp += 9; - a = (a-1 & MASK); - if (a == z) { - z = (z-1 & MASK); - x[z-1 & MASK] |= x[z]; - } - x[a] = carry; - } - } - - /* Downscale until exactly number of bits are left of radix point */ - for (;;) { - uint32_t carry = 0; - int sh = 1; - for (i=0; i th[i]) break; - } - if (i==LD_B1B_DIG && rp==9*LD_B1B_DIG) break; - /* FIXME: find a way to compute optimal sh */ - if (rp > 9+9*LD_B1B_DIG) sh = 9; - e2 += sh; - for (k=a; k!=z; k=(k+1 & MASK)) { - uint32_t tmp = x[k] & (1<>sh) + carry; - carry = (1000000000>>sh) * tmp; - if (k==a && !x[k]) { - a = (a+1 & MASK); - i--; - rp -= 9; - } - } - if (carry) { - if ((z+1 & MASK) != a) { - x[z] = carry; - z = (z+1 & MASK); - } else x[z-1 & MASK] |= 1; - } - } - - /* Assemble desired bits into floating point variable */ - for (y=i=0; i LDBL_MANT_DIG+e2-emin) { - bits = LDBL_MANT_DIG+e2-emin; - if (bits<0) bits=0; - denormal = 1; - } - - /* Calculate bias term to force rounding, move out lower bits */ - if (bits < LDBL_MANT_DIG) { - bias = copysignl(scalbn(1, 2*LDBL_MANT_DIG-bits-1), y); - frac = fmodl(y, scalbn(1, LDBL_MANT_DIG-bits)); - y -= frac; - y += bias; - } - - /* Process tail of decimal input so it can affect rounding */ - if ((a+i & MASK) != z) { - uint32_t t = x[a+i & MASK]; - if (t < 500000000 && (t || (a+i+1 & MASK) != z)) - frac += 0.25*sign; - else if (t > 500000000) - frac += 0.75*sign; - else if (t == 500000000) { - if ((a+i+1 & MASK) == z) - frac += 0.5*sign; - else - frac += 0.75*sign; - } - if (LDBL_MANT_DIG-bits >= 2 && !fmodl(frac, 1)) - frac++; - } - - y += frac; - y -= bias; - - if ((e2+LDBL_MANT_DIG & INT_MAX) > emax-5) { - if (fabsl(y) >= 2/LDBL_EPSILON) { - if (denormal && bits==LDBL_MANT_DIG+e2-emin) - denormal = 0; - y *= 0.5; - e2++; - } - if (e2+LDBL_MANT_DIG>emax || (denormal && frac)) - errno = ERANGE; - } - - return scalbnl(y, e2); -} - -#if defined(__wasilibc_printscan_no_long_double) -static long_double hexfloat(FILE *f, int bits, int emin, int sign, int pok) -#else -static long double hexfloat(FILE *f, int bits, int emin, int sign, int pok) -#endif -{ - uint32_t x = 0; -#if defined(__wasilibc_printscan_no_long_double) - long_double y = 0; - long_double scale = 1; - long_double bias = 0; -#else - long double y = 0; - long double scale = 1; - long double bias = 0; -#endif - int gottail = 0, gotrad = 0, gotdig = 0; - long long rp = 0; - long long dc = 0; - long long e2 = 0; - int d; - int c; - - c = shgetc(f); - - /* Skip leading zeros */ - for (; c=='0'; c = shgetc(f)) gotdig = 1; - - if (c=='.') { - gotrad = 1; - c = shgetc(f); - /* Count zeros after the radix point before significand */ - for (rp=0; c=='0'; c = shgetc(f), rp--) gotdig = 1; - } - - for (; c-'0'<10U || (c|32)-'a'<6U || c=='.'; c = shgetc(f)) { - if (c=='.') { - if (gotrad) break; - rp = dc; - gotrad = 1; - } else { - gotdig = 1; - if (c > '9') d = (c|32)+10-'a'; - else d = c-'0'; - if (dc<8) { - x = x*16 + d; - } else if (dc < (LDBL_MANT_DIG+3)/4+1) { - y += d*(scale/=16); - } else if (d && !gottail) { - y += 0.5*scale; - gottail = 1; - } - dc++; - } - } - if (!gotdig) { - shunget(f); - if (pok) { - shunget(f); - if (gotrad) shunget(f); - } else { - shlim(f, 0); - } - return sign * 0.0; - } - if (!gotrad) rp = dc; - while (dc<8) x *= 16, dc++; - if ((c|32)=='p') { - e2 = scanexp(f, pok); - if (e2 == LLONG_MIN) { - if (pok) { - shunget(f); - } else { - shlim(f, 0); - return 0; - } - e2 = 0; - } - } else { - shunget(f); - } - e2 += 4*rp - 32; - - if (!x) return sign * 0.0; - if (e2 > -emin) { - errno = ERANGE; - return sign * LDBL_MAX * LDBL_MAX; - } - if (e2 < emin-2*LDBL_MANT_DIG) { - errno = ERANGE; - return sign * LDBL_MIN * LDBL_MIN; - } - - while (x < 0x80000000) { - if (y>=0.5) { - x += x + 1; - y += y - 1; - } else { - x += x; - y += y; - } - e2--; - } - - if (bits > 32+e2-emin) { - bits = 32+e2-emin; - if (bits<0) bits=0; - } - - if (bits < LDBL_MANT_DIG) - bias = copysignl(scalbn(1, 32+LDBL_MANT_DIG-bits-1), sign); - - if (bits<32 && y && !(x&1)) x++, y=0; - -#if defined(__wasilibc_printscan_no_long_double) - y = bias + sign*(long_double)x + sign*y; -#else - y = bias + sign*(long double)x + sign*y; -#endif - y -= bias; - - if (!y) errno = ERANGE; - - return scalbnl(y, e2); -} - -#if defined(__wasilibc_printscan_no_long_double) -long_double __floatscan(FILE *f, int prec, int pok) -#else -long double __floatscan(FILE *f, int prec, int pok) -#endif -{ - int sign = 1; - size_t i; - int bits; - int emin; - int c; - - switch (prec) { - case 0: - bits = FLT_MANT_DIG; - emin = FLT_MIN_EXP-bits; - break; - case 1: - bits = DBL_MANT_DIG; - emin = DBL_MIN_EXP-bits; - break; - case 2: - bits = LDBL_MANT_DIG; - emin = LDBL_MIN_EXP-bits; - break; - default: - return 0; - } - - while (isspace((c=shgetc(f)))); - - if (c=='+' || c=='-') { - sign -= 2*(c=='-'); - c = shgetc(f); - } - - for (i=0; i<8 && (c|32)=="infinity"[i]; i++) - if (i<7) c = shgetc(f); - if (i==3 || i==8 || (i>3 && pok)) { - if (i!=8) { - shunget(f); - if (pok) for (; i>3; i--) shunget(f); - } - return sign * INFINITY; - } - if (!i) for (i=0; i<3 && (c|32)=="nan"[i]; i++) - if (i<2) c = shgetc(f); - if (i==3) { - if (shgetc(f) != '(') { - shunget(f); - return NAN; - } - for (i=1; ; i++) { - c = shgetc(f); - if (c-'0'<10U || c-'A'<26U || c-'a'<26U || c=='_') - continue; - if (c==')') return NAN; - shunget(f); - if (!pok) { - errno = EINVAL; - shlim(f, 0); - return 0; - } - while (i--) shunget(f); - return NAN; - } - return NAN; - } - - if (i) { - shunget(f); - errno = EINVAL; - shlim(f, 0); - return 0; - } - - if (c=='0') { - c = shgetc(f); - if ((c|32) == 'x') - return hexfloat(f, bits, emin, sign, pok); - shunget(f); - c = '0'; - } - - return decfloat(f, c, bits, emin, sign, pok); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.h b/lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.h deleted file mode 100644 index 8febd4673326c442a501bb9174b0375e9ba7f921..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef FLOATSCAN_H -#define FLOATSCAN_H - -#include - -#if defined(__wasilibc_printscan_no_long_double) -hidden long_double __floatscan(FILE *, int, int); -#else -hidden long double __floatscan(FILE *, int, int); -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/fork_impl.h b/lib/libc/wasi/libc-top-half/musl/src/internal/fork_impl.h deleted file mode 100644 index 16154e381ae89a0e77c9c6d94e2ca2fa2bc53e29..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/fork_impl.h +++ /dev/null @@ -1,23 +0,0 @@ -#include - -#ifdef __wasilibc_unmodified_upstream -extern hidden volatile int *const __at_quick_exit_lockptr; -extern hidden volatile int *const __atexit_lockptr; -extern hidden volatile int *const __gettext_lockptr; -extern hidden volatile int *const __locale_lockptr; -extern hidden volatile int *const __random_lockptr; -extern hidden volatile int *const __sem_open_lockptr; -extern hidden volatile int *const __stdio_ofl_lockptr; -extern hidden volatile int *const __syslog_lockptr; -extern hidden volatile int *const __timezone_lockptr; - -extern hidden volatile int *const __bump_lockptr; - -extern hidden volatile int *const __vmlock_lockptr; - -hidden void __malloc_atfork(int); -hidden void __ldso_atfork(int); -hidden void __pthread_key_atfork(int); - -hidden void __post_Fork(int); -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/intscan.c b/lib/libc/wasi/libc-top-half/musl/src/internal/intscan.c deleted file mode 100644 index a4a5ae861282863035a492ce8db0e18d4acfe3ac..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/intscan.c +++ /dev/null @@ -1,100 +0,0 @@ -#include -#include -#include -#include "shgetc.h" - -/* Lookup table for digit values. -1==255>=36 -> invalid */ -static const unsigned char table[] = { -1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, -25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, --1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -}; - -unsigned long long __intscan(FILE *f, unsigned base, int pok, unsigned long long lim) -{ - const unsigned char *val = table+1; - int c, neg=0; - unsigned x; - unsigned long long y; - if (base > 36 || base == 1) { - errno = EINVAL; - return 0; - } - while (isspace((c=shgetc(f)))); - if (c=='+' || c=='-') { - neg = -(c=='-'); - c = shgetc(f); - } - if ((base == 0 || base == 16) && c=='0') { - c = shgetc(f); - if ((c|32)=='x') { - c = shgetc(f); - if (val[c]>=16) { - shunget(f); - if (pok) shunget(f); - else shlim(f, 0); - return 0; - } - base = 16; - } else if (base == 0) { - base = 8; - } - } else { - if (base == 0) base = 10; - if (val[c] >= base) { - shunget(f); - shlim(f, 0); - errno = EINVAL; - return 0; - } - } - if (base == 10) { - for (x=0; c-'0'<10U && x<=UINT_MAX/10-1; c=shgetc(f)) - x = x*10 + (c-'0'); - for (y=x; c-'0'<10U && y<=ULLONG_MAX/10 && 10*y<=ULLONG_MAX-(c-'0'); c=shgetc(f)) - y = y*10 + (c-'0'); - if (c-'0'>=10U) goto done; - } else if (!(base & base-1)) { - int bs = "\0\1\2\4\7\3\6\5"[(0x17*base)>>5&7]; - for (x=0; val[c]>bs; c=shgetc(f)) - y = y<=lim) { - if (!(lim&1) && !neg) { - errno = ERANGE; - return lim-1; - } else if (y>lim) { - errno = ERANGE; - return lim; - } - } - return (y^neg)-neg; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/libc.c b/lib/libc/wasi/libc-top-half/musl/src/internal/libc.c deleted file mode 100644 index cb05181084a57ab5cc8772b31edb75ffd0279d1c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/libc.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "libc.h" - -struct __libc __libc; - -size_t __hwcap; -char *__progname=0, *__progname_full=0; - -weak_alias(__progname, program_invocation_short_name); -weak_alias(__progname_full, program_invocation_name); diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/libc.h b/lib/libc/wasi/libc-top-half/musl/src/internal/libc.h deleted file mode 100644 index 355c3a4e2398d9b6c8ea2805d9a010ffc489ebc9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/libc.h +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef LIBC_H -#define LIBC_H - -#include -#include -#include - -struct __locale_map; - -struct __locale_struct { - const struct __locale_map *cat[6]; -}; - -struct tls_module { - struct tls_module *next; - void *image; - size_t len, size, align, offset; -}; - -struct __libc { -#ifdef __wasilibc_unmodified_upstream - char can_do_threads; -#endif -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - char threaded; -#endif -#ifdef __wasilibc_unmodified_upstream // WASI doesn't currently use any code that needs "secure" mode - char secure; -#endif -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - volatile signed char need_locks; - int threads_minus_1; -#endif -#ifdef __wasilibc_unmodified_upstream // WASI has no auxv - size_t *auxv; -#endif -#ifdef __wasilibc_unmodified_upstream // WASI use different TLS implement - struct tls_module *tls_head; - size_t tls_size, tls_align, tls_cnt; -#endif -#ifdef __wasilibc_unmodified_upstream // WASI doesn't get the page size from auxv - size_t page_size; -#endif - struct __locale_struct global_locale; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#else - struct __locale_struct *current_locale; -#endif -}; - -#ifndef PAGE_SIZE -#define PAGE_SIZE libc.page_size -#endif - -extern hidden struct __libc __libc; -#define libc __libc - -hidden void __init_libc(char **, char *); -hidden void __init_tls(size_t *); -hidden void __init_ssp(void *); -hidden void __libc_start_init(void); -hidden void __funcs_on_exit(void); -hidden void __funcs_on_quick_exit(void); -hidden void __libc_exit_fini(void); -hidden void __fork_handler(int); - -extern hidden size_t __hwcap; -extern hidden size_t __sysinfo; -extern char *__progname, *__progname_full; - -extern hidden const char __libc_version[]; - -hidden void __synccall(void (*)(void *), void *); -hidden int __setxid(int, int, int, int); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/libm.h b/lib/libc/wasi/libc-top-half/musl/src/internal/libm.h deleted file mode 100644 index 2b06ac45aa99ab19d15212dae887b0d4225186da..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/libm.h +++ /dev/null @@ -1,292 +0,0 @@ -#ifndef _LIBM_H -#define _LIBM_H - -#include -#include -#include -#include -#include "fp_arch.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN -union ldshape { - long double f; - struct { - uint64_t m; - uint16_t se; - } i; -}; -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN -/* This is the m68k variant of 80-bit long double, and this definition only works - * on archs where the alignment requirement of uint64_t is <= 4. */ -union ldshape { - long double f; - struct { - uint16_t se; - uint16_t pad; - uint64_t m; - } i; -}; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN -union ldshape { - long double f; - struct { - uint64_t lo; - uint32_t mid; - uint16_t top; - uint16_t se; - } i; - struct { - uint64_t lo; - uint64_t hi; - } i2; -}; -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN -union ldshape { - long double f; - struct { - uint16_t se; - uint16_t top; - uint32_t mid; - uint64_t lo; - } i; - struct { - uint64_t hi; - uint64_t lo; - } i2; -}; -#else -#error Unsupported long double representation -#endif - -/* Support non-nearest rounding mode. */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -#define WANT_ROUNDING 1 -#else -#define WANT_ROUNDING 0 -#endif -/* Support signaling NaNs. */ -#define WANT_SNAN 0 - -#if WANT_SNAN -#error SNaN is unsupported -#else -#define issignalingf_inline(x) 0 -#define issignaling_inline(x) 0 -#endif - -#ifndef TOINT_INTRINSICS -#define TOINT_INTRINSICS 0 -#endif - -#if TOINT_INTRINSICS -/* Round x to nearest int in all rounding modes, ties have to be rounded - consistently with converttoint so the results match. If the result - would be outside of [-2^31, 2^31-1] then the semantics is unspecified. */ -static double_t roundtoint(double_t); - -/* Convert x to nearest int in all rounding modes, ties have to be rounded - consistently with roundtoint. If the result is not representible in an - int32_t then the semantics is unspecified. */ -static int32_t converttoint(double_t); -#endif - -/* Helps static branch prediction so hot path can be better optimized. */ -#ifdef __GNUC__ -#define predict_true(x) __builtin_expect(!!(x), 1) -#define predict_false(x) __builtin_expect(x, 0) -#else -#define predict_true(x) (x) -#define predict_false(x) (x) -#endif - -/* Evaluate an expression as the specified type. With standard excess - precision handling a type cast or assignment is enough (with - -ffloat-store an assignment is required, in old compilers argument - passing and return statement may not drop excess precision). */ - -static inline float eval_as_float(float x) -{ - float y = x; - return y; -} - -static inline double eval_as_double(double x) -{ - double y = x; - return y; -} - -/* fp_barrier returns its input, but limits code transformations - as if it had a side-effect (e.g. observable io) and returned - an arbitrary value. */ - -#ifndef fp_barrierf -#define fp_barrierf fp_barrierf -static inline float fp_barrierf(float x) -{ - volatile float y = x; - return y; -} -#endif - -#ifndef fp_barrier -#define fp_barrier fp_barrier -static inline double fp_barrier(double x) -{ - volatile double y = x; - return y; -} -#endif - -#ifndef fp_barrierl -#define fp_barrierl fp_barrierl -static inline long double fp_barrierl(long double x) -{ - volatile long double y = x; - return y; -} -#endif - -/* fp_force_eval ensures that the input value is computed when that's - otherwise unused. To prevent the constant folding of the input - expression, an additional fp_barrier may be needed or a compilation - mode that does so (e.g. -frounding-math in gcc). Then it can be - used to evaluate an expression for its fenv side-effects only. */ - -#ifndef fp_force_evalf -#define fp_force_evalf fp_force_evalf -static inline void fp_force_evalf(float x) -{ - volatile float y; - y = x; -} -#endif - -#ifndef fp_force_eval -#define fp_force_eval fp_force_eval -static inline void fp_force_eval(double x) -{ - volatile double y; - y = x; -} -#endif - -#ifndef fp_force_evall -#define fp_force_evall fp_force_evall -static inline void fp_force_evall(long double x) -{ - volatile long double y; - y = x; -} -#endif - -#ifdef __wasilibc_unmodified_upstream // WASI has no floating-point status flags -#define FORCE_EVAL(x) do { \ - if (sizeof(x) == sizeof(float)) { \ - fp_force_evalf(x); \ - } else if (sizeof(x) == sizeof(double)) { \ - fp_force_eval(x); \ - } else { \ - fp_force_evall(x); \ - } \ -} while(0) -#else -/* WebAssembly doesn't have floating-point status flags, so there's no reason - * to force evaluations. */ -#define FORCE_EVAL(x) ((void)(x)) -#endif - -#define asuint(f) ((union{float _f; uint32_t _i;}){f})._i -#define asfloat(i) ((union{uint32_t _i; float _f;}){i})._f -#define asuint64(f) ((union{double _f; uint64_t _i;}){f})._i -#define asdouble(i) ((union{uint64_t _i; double _f;}){i})._f - -#define EXTRACT_WORDS(hi,lo,d) \ -do { \ - uint64_t __u = asuint64(d); \ - (hi) = __u >> 32; \ - (lo) = (uint32_t)__u; \ -} while (0) - -#define GET_HIGH_WORD(hi,d) \ -do { \ - (hi) = asuint64(d) >> 32; \ -} while (0) - -#define GET_LOW_WORD(lo,d) \ -do { \ - (lo) = (uint32_t)asuint64(d); \ -} while (0) - -#define INSERT_WORDS(d,hi,lo) \ -do { \ - (d) = asdouble(((uint64_t)(hi)<<32) | (uint32_t)(lo)); \ -} while (0) - -#define SET_HIGH_WORD(d,hi) \ - INSERT_WORDS(d, hi, (uint32_t)asuint64(d)) - -#define SET_LOW_WORD(d,lo) \ - INSERT_WORDS(d, asuint64(d)>>32, lo) - -#define GET_FLOAT_WORD(w,d) \ -do { \ - (w) = asuint(d); \ -} while (0) - -#define SET_FLOAT_WORD(d,w) \ -do { \ - (d) = asfloat(w); \ -} while (0) - -hidden int __rem_pio2_large(double*,double*,int,int,int); - -hidden int __rem_pio2(double,double*); -hidden double __sin(double,double,int); -hidden double __cos(double,double); -hidden double __tan(double,double,int); -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -hidden double __expo2(double,double); -#else -hidden double __expo2(double); -#endif - -hidden int __rem_pio2f(float,double*); -hidden float __sindf(double); -hidden float __cosdf(double); -hidden float __tandf(double,int); -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -hidden float __expo2f(float,float); -#else -hidden float __expo2f(float); -#endif - -hidden int __rem_pio2l(long double, long double *); -hidden long double __sinl(long double, long double, int); -hidden long double __cosl(long double, long double); -hidden long double __tanl(long double, long double, int); - -hidden long double __polevll(long double, const long double *, int); -hidden long double __p1evll(long double, const long double *, int); - -extern int __signgam; -hidden double __lgamma_r(double, int *); -hidden float __lgammaf_r(float, int *); - -/* error handling functions */ -hidden float __math_xflowf(uint32_t, float); -hidden float __math_uflowf(uint32_t); -hidden float __math_oflowf(uint32_t); -hidden float __math_divzerof(uint32_t); -hidden float __math_invalidf(float); -hidden double __math_xflow(uint32_t, double); -hidden double __math_uflow(uint32_t); -hidden double __math_oflow(uint32_t); -hidden double __math_divzero(uint32_t); -hidden double __math_invalid(double); -#if LDBL_MANT_DIG != DBL_MANT_DIG -hidden long double __math_invalidl(long double); -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/locale_impl.h b/lib/libc/wasi/libc-top-half/musl/src/internal/locale_impl.h deleted file mode 100644 index 88f5dcf8f07c7530d175428bb6d6388b8f6e86b1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/locale_impl.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef _LOCALE_IMPL_H -#define _LOCALE_IMPL_H - -#include -#include -#include "libc.h" -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include "pthread_impl.h" -#endif - -#define LOCALE_NAME_MAX 23 - -struct __locale_map { - const void *map; - size_t map_size; - char name[LOCALE_NAME_MAX+1]; - const struct __locale_map *next; -}; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -extern hidden volatile int __locale_lock[1]; -#endif - -extern hidden const struct __locale_map __c_dot_utf8; -extern hidden const struct __locale_struct __c_locale; -extern hidden const struct __locale_struct __c_dot_utf8_locale; - -hidden const struct __locale_map *__get_locale(int, const char *); -hidden const char *__mo_lookup(const void *, size_t, const char *); -hidden const char *__lctrans(const char *, const struct __locale_map *); -#ifdef __wasilibc_unmodified_upstream -hidden const char *__lctrans_cur(const char *); -#else -// We make this visible in the wasi-libc build because -// libwasi-emulated-signal.so needs to import it from libc.so. If we ever -// decide to merge libwasi-emulated-signal.so into libc.so, this will no longer -// be necessary. -const char *__lctrans_cur(const char *); -#endif -hidden const char *__lctrans_impl(const char *, const struct __locale_map *); -hidden int __loc_is_allocated(locale_t); -hidden char *__gettextdomain(void); - -#define LOC_MAP_FAILED ((const struct __locale_map *)-1) - -#define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) -#define LCTRANS_CUR(msg) __lctrans_cur(msg) - -#define C_LOCALE ((locale_t)&__c_locale) -#define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#define CURRENT_LOCALE (__pthread_self()->locale) - -#define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) -#else -// If we haven't set up the current_local field yet, do so. Then return an -// lvalue for the current_locale field. -#define CURRENT_LOCALE \ - (*({ \ - if (!libc.current_locale) { \ - libc.current_locale = &libc.global_locale; \ - } \ - &libc.current_locale; \ - })) - -#define CURRENT_UTF8 (!!CURRENT_LOCALE->cat[LC_CTYPE]) -#endif - -#undef MB_CUR_MAX -#define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/lock.h b/lib/libc/wasi/libc-top-half/musl/src/internal/lock.h deleted file mode 100644 index 29787fb1f428127af3f4070061d9c7dd2f55550b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/lock.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef LOCK_H -#define LOCK_H - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -hidden void __lock(volatile int *); -hidden void __unlock(volatile int *); -#define LOCK(x) __lock(x) -#define UNLOCK(x) __unlock(x) -#else -// No locking needed. -#define LOCK(x) ((void)0) -#define UNLOCK(x) ((void)0) -#endif - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/pthread_impl.h b/lib/libc/wasi/libc-top-half/musl/src/internal/pthread_impl.h deleted file mode 100644 index 0106ac3855a29db29feb0d8763c2409622c5c9a9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/pthread_impl.h +++ /dev/null @@ -1,233 +0,0 @@ -#ifndef _PTHREAD_IMPL_H -#define _PTHREAD_IMPL_H - -#include -#ifdef __wasilibc_unmodified_upstream -#include -#endif -#include -#include -#ifdef __wasilibc_unmodified_upstream -#include -#endif -#include "libc.h" -#ifdef __wasilibc_unmodified_upstream -#include "syscall.h" -#endif -#include "atomic.h" -#include "futex.h" - -#include "pthread_arch.h" - -#define pthread __pthread - -struct pthread { - /* Part 1 -- these fields may be external or - * internal (accessed via asm) ABI. Do not change. */ - struct pthread *self; -#ifdef __wasilibc_unmodified_upstream -#ifndef TLS_ABOVE_TP - uintptr_t *dtv; -#endif -#endif - struct pthread *prev, *next; /* non-ABI */ - uintptr_t sysinfo; -#ifndef TLS_ABOVE_TP -#ifdef CANARY_PAD - uintptr_t canary_pad; -#endif - uintptr_t canary; -#endif - - /* Part 2 -- implementation details, non-ABI. */ - int tid; - int errno_val; - volatile int detach_state; - volatile int cancel; - volatile unsigned char canceldisable, cancelasync; - unsigned char tsd_used:1; - unsigned char dlerror_flag:1; - unsigned char *map_base; - size_t map_size; - void *stack; - size_t stack_size; - size_t guard_size; - void *result; - struct __ptcb *cancelbuf; - void **tsd; - struct { - volatile void *volatile head; - long off; - volatile void *volatile pending; - } robust_list; - int h_errno_val; - volatile int timer_id; - locale_t locale; - volatile int killlock[1]; - char *dlerror_buf; - void *stdio_locks; - - /* Part 3 -- the positions of these fields relative to - * the end of the structure is external and internal ABI. */ -#ifdef TLS_ABOVE_TP - uintptr_t canary; - uintptr_t *dtv; -#endif -}; - -enum { - DT_EXITED = 0, - DT_EXITING, - DT_JOINABLE, - DT_DETACHED, -}; - -#define __SU (sizeof(size_t)/sizeof(int)) - -#define _a_stacksize __u.__s[0] -#define _a_guardsize __u.__s[1] -#define _a_stackaddr __u.__s[2] -#define _a_detach __u.__i[3*__SU+0] -#define _a_sched __u.__i[3*__SU+1] -#define _a_policy __u.__i[3*__SU+2] -#define _a_prio __u.__i[3*__SU+3] -#define _m_type __u.__i[0] -#define _m_lock __u.__vi[1] -#define _m_waiters __u.__vi[2] -#define _m_prev __u.__p[3] -#define _m_next __u.__p[4] -#define _m_count __u.__i[5] -#define _c_shared __u.__p[0] -#define _c_seq __u.__vi[2] -#define _c_waiters __u.__vi[3] -#define _c_clock __u.__i[4] -#define _c_lock __u.__vi[8] -#define _c_head __u.__p[1] -#define _c_tail __u.__p[5] -#define _rw_lock __u.__vi[0] -#define _rw_waiters __u.__vi[1] -#define _rw_shared __u.__i[2] -#define _b_lock __u.__vi[0] -#define _b_waiters __u.__vi[1] -#define _b_limit __u.__i[2] -#define _b_count __u.__vi[3] -#define _b_waiters2 __u.__vi[4] -#define _b_inst __u.__p[3] - -#ifndef TP_OFFSET -#define TP_OFFSET 0 -#endif - -#ifndef DTP_OFFSET -#define DTP_OFFSET 0 -#endif - -#ifdef TLS_ABOVE_TP -#define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + TP_OFFSET) -#define __pthread_self() ((pthread_t)(__get_tp() - sizeof(struct __pthread) - TP_OFFSET)) -#else -#define TP_ADJ(p) (p) -#define __pthread_self() ((pthread_t)__get_tp()) -#endif - -#ifndef tls_mod_off_t -#define tls_mod_off_t size_t -#endif - -#define SIGTIMER 32 -#define SIGCANCEL 33 -#define SIGSYNCCALL 34 - -#define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) -#define SIGPT_SET \ - ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ - [sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) -#define SIGTIMER_SET \ - ((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ - 0x80000000 }) - -void *__tls_get_addr(tls_mod_off_t *); -hidden int __init_tp(void *); -hidden void *__copy_tls(unsigned char *); -hidden void __reset_tls(); - -hidden void __membarrier_init(void); -hidden void __dl_thread_cleanup(void); -hidden void __testcancel(); -hidden void __do_cleanup_push(struct __ptcb *); -hidden void __do_cleanup_pop(struct __ptcb *); -hidden void __pthread_tsd_run_dtors(); - -hidden void __pthread_key_delete_synccall(void (*)(void *), void *); -hidden int __pthread_key_delete_impl(pthread_key_t); - -extern hidden volatile size_t __pthread_tsd_size; -extern hidden void *__pthread_tsd_main[]; -extern hidden volatile int __eintr_valid_flag; - -hidden int __clone(int (*)(void *), void *, int, void *, ...); -hidden int __set_thread_area(void *); -#ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ -hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); -#endif -hidden void __unmapself(void *, size_t); - -#ifndef __wasilibc_unmodified_upstream -hidden int __wasilibc_futex_wait(volatile void *, int, int, int64_t); -#endif -hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); -hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); -hidden void __wait(volatile int *, volatile int *, int, int); -static inline void __wake(volatile void *addr, int cnt, int priv) -{ - if (priv) priv = FUTEX_PRIVATE; - if (cnt<0) cnt = INT_MAX; -#ifdef __wasilibc_unmodified_upstream - __syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || - __syscall(SYS_futex, addr, FUTEX_WAKE, cnt); -#else -#ifdef _REENTRANT - __builtin_wasm_memory_atomic_notify((int*)addr, cnt); -#endif -#endif -} -static inline void __futexwait(volatile void *addr, int val, int priv) -{ -#ifdef __wasilibc_unmodified_upstream - if (priv) priv = FUTEX_PRIVATE; - __syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS || - __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); -#else - __wait(addr, NULL, val, priv); -#endif -} - -hidden void __acquire_ptc(void); -hidden void __release_ptc(void); -hidden void __inhibit_ptc(void); - -hidden void __tl_lock(void); -hidden void __tl_unlock(void); -hidden void __tl_sync(pthread_t); - -extern hidden volatile int __thread_list_lock; - -extern hidden volatile int __abort_lock[1]; - -extern hidden unsigned __default_stacksize; -extern hidden unsigned __default_guardsize; - -#define DEFAULT_STACK_SIZE 131072 -#ifdef __wasilibc_unmodified_upstream -#define DEFAULT_GUARD_SIZE 8192 -#else -/* guard doesn't make much sense without mprotect. */ -#define DEFAULT_GUARD_SIZE 0 -#endif - -#define DEFAULT_STACK_MAX (8<<20) -#define DEFAULT_GUARD_MAX (1<<20) - -#define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.c b/lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.c deleted file mode 100644 index 7455d2f00a04e477db9f4129fb4d5ba0809af1cb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.c +++ /dev/null @@ -1,37 +0,0 @@ -#include "shgetc.h" - -/* The shcnt field stores the number of bytes read so far, offset by - * the value of buf-rpos at the last function call (__shlim or __shgetc), - * so that between calls the inline shcnt macro can add rpos-buf to get - * the actual count. */ - -void __shlim(FILE *f, off_t lim) -{ - f->shlim = lim; - f->shcnt = f->buf - f->rpos; - /* If lim is nonzero, rend must be a valid pointer. */ - if (lim && f->rend - f->rpos > lim) - f->shend = f->rpos + lim; - else - f->shend = f->rend; -} - -int __shgetc(FILE *f) -{ - int c; - off_t cnt = shcnt(f); - if (f->shlim && cnt >= f->shlim || (c=__uflow(f)) < 0) { - f->shcnt = f->buf - f->rpos + cnt; - f->shend = f->rpos; - f->shlim = -1; - return EOF; - } - cnt++; - if (f->shlim && f->rend - f->rpos > f->shlim - cnt) - f->shend = f->rpos + (f->shlim - cnt); - else - f->shend = f->rend; - f->shcnt = f->buf - f->rpos + cnt; - if (f->rpos <= f->buf) f->rpos[-1] = c; - return c; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.h b/lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.h deleted file mode 100644 index 9435381a61d1ee45c373c87bf7bcb5b43b370676..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.h +++ /dev/null @@ -1,32 +0,0 @@ -#include "stdio_impl.h" - -/* Scan helper "stdio" functions for use by scanf-family and strto*-family - * functions. These accept either a valid stdio FILE, or a minimal pseudo - * FILE whose buffer pointers point into a null-terminated string. In the - * latter case, the sh_fromstring macro should be used to setup the FILE; - * the rest of the structure can be left uninitialized. - * - * To begin using these functions, shlim must first be called on the FILE - * to set a field width limit, or 0 for no limit. For string pseudo-FILEs, - * a nonzero limit is not valid and produces undefined behavior. After that, - * shgetc, shunget, and shcnt are valid as long as no other stdio functions - * are called on the stream. - * - * When used with a real FILE object, shunget has only one byte of pushback - * available. Further shunget (up to a limit of the stdio UNGET buffer size) - * will adjust the position but will not restore the data to be read again. - * This functionality is needed for the wcsto*-family functions, where it's - * okay because the FILE will be discarded immediately anyway. When used - * with string pseudo-FILEs, shunget has unlimited pushback, back to the - * beginning of the string. */ - -hidden void __shlim(FILE *, off_t); -hidden int __shgetc(FILE *); - -#define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf)) -#define shlim(f, lim) __shlim((f), (lim)) -#define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f)) -#define shunget(f) ((f)->shlim>=0 ? (void)(f)->rpos-- : (void)0) - -#define sh_fromstring(f, s) \ - ((f)->buf = (f)->rpos = (void *)(s), (f)->rend = (void*)-1) diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/stdio_impl.h b/lib/libc/wasi/libc-top-half/musl/src/internal/stdio_impl.h deleted file mode 100644 index 7f19dd95160e2fe03c7ae44f0a5f03e15aa6e8a5..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/stdio_impl.h +++ /dev/null @@ -1,137 +0,0 @@ -#ifndef _STDIO_IMPL_H -#define _STDIO_IMPL_H - -#include -#if defined(__wasilibc_unmodified_upstream) -#include "syscall.h" -#endif - -#define UNGET 8 - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0) -#define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0) -#define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0) -#else -// No locking needed. -#define FFINALLOCK(f) ((void)(f)) -#define FLOCK(f) ((void)(f)) -#define FUNLOCK(f) ((void)(f)) -#endif - -#define F_PERM 1 -#define F_NORD 4 -#define F_NOWR 8 -#define F_EOF 16 -#define F_ERR 32 -#define F_SVB 64 -#define F_APP 128 - -struct _IO_FILE { - unsigned flags; - unsigned char *rpos, *rend; - int (*close)(FILE *); - unsigned char *wend, *wpos; -#ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields. - unsigned char *mustbezero_1; -#endif - unsigned char *wbase; - size_t (*read)(FILE *, unsigned char *, size_t); - size_t (*write)(FILE *, const unsigned char *, size_t); - off_t (*seek)(FILE *, off_t, int); - unsigned char *buf; - size_t buf_size; - FILE *prev, *next; - int fd; -#ifdef __wasilibc_unmodified_upstream // WASI has no popen - int pipe_pid; -#endif -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - long lockcount; -#endif - int mode; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - volatile int lock; -#endif - int lbf; - void *cookie; - off_t off; - char *getln_buf; -#ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields. - void *mustbezero_2; -#endif - unsigned char *shend; - off_t shlim, shcnt; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - FILE *prev_locked, *next_locked; -#endif - struct __locale_struct *locale; -}; - -extern hidden FILE *volatile __stdin_used; -extern hidden FILE *volatile __stdout_used; -extern hidden FILE *volatile __stderr_used; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -hidden int __lockfile(FILE *); -hidden void __unlockfile(FILE *); -#endif - -hidden size_t __stdio_read(FILE *, unsigned char *, size_t); -hidden size_t __stdio_write(FILE *, const unsigned char *, size_t); -hidden size_t __stdout_write(FILE *, const unsigned char *, size_t); -hidden off_t __stdio_seek(FILE *, off_t, int); -hidden int __stdio_close(FILE *); - -hidden int __toread(FILE *); -hidden int __towrite(FILE *); - -hidden void __stdio_exit(void); -hidden void __stdio_exit_needed(void); - -#ifdef __wasilibc_unmodified_upstream // wasm has no "protected" visibility -#if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303) -__attribute__((visibility("protected"))) -#endif -#endif -int __overflow(FILE *, int), __uflow(FILE *); - -hidden int __fseeko(FILE *, off_t, int); -hidden int __fseeko_unlocked(FILE *, off_t, int); -hidden off_t __ftello(FILE *); -hidden off_t __ftello_unlocked(FILE *); -hidden size_t __fwritex(const unsigned char *, size_t, FILE *); -hidden int __putc_unlocked(int, FILE *); - -hidden FILE *__fdopen(int, const char *); -hidden int __fmodeflags(const char *); - -hidden FILE *__ofl_add(FILE *f); -hidden FILE **__ofl_lock(void); -hidden void __ofl_unlock(void); - -struct __pthread; -hidden void __register_locked_file(FILE *, struct __pthread *); -hidden void __unlist_locked_file(FILE *); -hidden void __do_orphaned_stdio_locks(void); - -#define MAYBE_WAITERS 0x40000000 - -hidden void __getopt_msg(const char *, const char *, const char *, size_t); - -#define feof(f) ((f)->flags & F_EOF) -#define ferror(f) ((f)->flags & F_ERR) - -#define getc_unlocked(f) \ - ( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) ) - -#define putc_unlocked(c, f) \ - ( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \ - ? *(f)->wpos++ = (unsigned char)(c) \ - : __overflow((f),(unsigned char)(c)) ) - -/* Caller-allocated FILE * operations */ -hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t); -hidden int __fclose_ca(FILE *); - -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/internal/syscall.h b/lib/libc/wasi/libc-top-half/musl/src/internal/syscall.h deleted file mode 100644 index 2665715aa9c91d0f0a2adaa3d7f890c64ae9575e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/internal/syscall.h +++ /dev/null @@ -1,412 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream -#ifndef _INTERNAL_SYSCALL_H -#define _INTERNAL_SYSCALL_H - -#include -#include -#include -#include "syscall_arch.h" - -#ifndef SYSCALL_RLIM_INFINITY -#define SYSCALL_RLIM_INFINITY (~0ULL) -#endif - -#ifndef SYSCALL_MMAP2_UNIT -#define SYSCALL_MMAP2_UNIT 4096ULL -#endif - -#ifndef __SYSCALL_LL_PRW -#define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x) -#endif - -#ifndef __scc -#define __scc(X) ((long) (X)) -typedef long syscall_arg_t; -#endif - -hidden long __syscall_ret(unsigned long), - __syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, - syscall_arg_t, syscall_arg_t, syscall_arg_t); - -#define __syscall1(n,a) __syscall1(n,__scc(a)) -#define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b)) -#define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c)) -#define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d)) -#define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e)) -#define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) -#define __syscall7(n,a,b,c,d,e,f,g) __syscall7(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f),__scc(g)) - -#define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n -#define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,) -#define __SYSCALL_CONCAT_X(a,b) a##b -#define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) -#define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) - -#define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) -#define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) - -#define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f)) -#define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f)) - -#define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0) -#define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0) -#define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0) -#define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0) -#define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0) -#define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0) -#define __syscall_cp6(n,a,b,c,d,e,f) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) - -#define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__) -#define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__)) - -static inline long __alt_socketcall(int sys, int sock, int cp, syscall_arg_t a, syscall_arg_t b, syscall_arg_t c, syscall_arg_t d, syscall_arg_t e, syscall_arg_t f) -{ - long r; - if (cp) r = __syscall_cp(sys, a, b, c, d, e, f); - else r = __syscall(sys, a, b, c, d, e, f); - if (r != -ENOSYS) return r; -#ifdef SYS_socketcall - if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f})); - else r = __syscall(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f})); -#endif - return r; -} -#define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \ - __scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f)) -#define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \ - __scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f)) - -/* fixup legacy 16-bit junk */ - -#ifdef SYS_getuid32 -#undef SYS_lchown -#undef SYS_getuid -#undef SYS_getgid -#undef SYS_geteuid -#undef SYS_getegid -#undef SYS_setreuid -#undef SYS_setregid -#undef SYS_getgroups -#undef SYS_setgroups -#undef SYS_fchown -#undef SYS_setresuid -#undef SYS_getresuid -#undef SYS_setresgid -#undef SYS_getresgid -#undef SYS_chown -#undef SYS_setuid -#undef SYS_setgid -#undef SYS_setfsuid -#undef SYS_setfsgid -#define SYS_lchown SYS_lchown32 -#define SYS_getuid SYS_getuid32 -#define SYS_getgid SYS_getgid32 -#define SYS_geteuid SYS_geteuid32 -#define SYS_getegid SYS_getegid32 -#define SYS_setreuid SYS_setreuid32 -#define SYS_setregid SYS_setregid32 -#define SYS_getgroups SYS_getgroups32 -#define SYS_setgroups SYS_setgroups32 -#define SYS_fchown SYS_fchown32 -#define SYS_setresuid SYS_setresuid32 -#define SYS_getresuid SYS_getresuid32 -#define SYS_setresgid SYS_setresgid32 -#define SYS_getresgid SYS_getresgid32 -#define SYS_chown SYS_chown32 -#define SYS_setuid SYS_setuid32 -#define SYS_setgid SYS_setgid32 -#define SYS_setfsuid SYS_setfsuid32 -#define SYS_setfsgid SYS_setfsgid32 -#endif - - -/* fixup legacy 32-bit-vs-lfs64 junk */ - -#ifdef SYS_fcntl64 -#undef SYS_fcntl -#define SYS_fcntl SYS_fcntl64 -#endif - -#ifdef SYS_getdents64 -#undef SYS_getdents -#define SYS_getdents SYS_getdents64 -#endif - -#ifdef SYS_ftruncate64 -#undef SYS_ftruncate -#undef SYS_truncate -#define SYS_ftruncate SYS_ftruncate64 -#define SYS_truncate SYS_truncate64 -#endif - -#ifdef SYS_stat64 -#undef SYS_stat -#define SYS_stat SYS_stat64 -#endif - -#ifdef SYS_fstat64 -#undef SYS_fstat -#define SYS_fstat SYS_fstat64 -#endif - -#ifdef SYS_lstat64 -#undef SYS_lstat -#define SYS_lstat SYS_lstat64 -#endif - -#ifdef SYS_statfs64 -#undef SYS_statfs -#define SYS_statfs SYS_statfs64 -#endif - -#ifdef SYS_fstatfs64 -#undef SYS_fstatfs -#define SYS_fstatfs SYS_fstatfs64 -#endif - -#if defined(SYS_newfstatat) -#undef SYS_fstatat -#define SYS_fstatat SYS_newfstatat -#elif defined(SYS_fstatat64) -#undef SYS_fstatat -#define SYS_fstatat SYS_fstatat64 -#endif - -#ifdef SYS_ugetrlimit -#undef SYS_getrlimit -#define SYS_getrlimit SYS_ugetrlimit -#endif - -#ifdef SYS__newselect -#undef SYS_select -#define SYS_select SYS__newselect -#endif - -#ifdef SYS_pread64 -#undef SYS_pread -#undef SYS_pwrite -#define SYS_pread SYS_pread64 -#define SYS_pwrite SYS_pwrite64 -#endif - -#ifdef SYS_fadvise64_64 -#undef SYS_fadvise -#define SYS_fadvise SYS_fadvise64_64 -#elif defined(SYS_fadvise64) -#undef SYS_fadvise -#define SYS_fadvise SYS_fadvise64 -#endif - -#ifdef SYS_sendfile64 -#undef SYS_sendfile -#define SYS_sendfile SYS_sendfile64 -#endif - -#ifdef SYS_timer_settime32 -#define SYS_timer_settime SYS_timer_settime32 -#endif - -#ifdef SYS_timer_gettime32 -#define SYS_timer_gettime SYS_timer_gettime32 -#endif - -#ifdef SYS_timerfd_settime32 -#define SYS_timerfd_settime SYS_timerfd_settime32 -#endif - -#ifdef SYS_timerfd_gettime32 -#define SYS_timerfd_gettime SYS_timerfd_gettime32 -#endif - -#ifdef SYS_clock_settime32 -#define SYS_clock_settime SYS_clock_settime32 -#endif - -#ifdef SYS_clock_gettime32 -#define SYS_clock_gettime SYS_clock_gettime32 -#endif - -#ifdef SYS_clock_getres_time32 -#define SYS_clock_getres SYS_clock_getres_time32 -#endif - -#ifdef SYS_clock_nanosleep_time32 -#define SYS_clock_nanosleep SYS_clock_nanosleep_time32 -#endif - -#ifdef SYS_gettimeofday_time32 -#define SYS_gettimeofday SYS_gettimeofday_time32 -#endif - -#ifdef SYS_settimeofday_time32 -#define SYS_settimeofday SYS_settimeofday_time32 -#endif - -/* Ensure that the plain syscall names are defined even for "time64-only" - * archs. These facilitate callers passing null time arguments, and make - * tests for establishing which to use/fallback-to more consistent when - * they do need to be called with time arguments. */ - -#ifndef SYS_clock_gettime -#define SYS_clock_gettime SYS_clock_gettime64 -#endif - -#ifndef SYS_clock_settime -#define SYS_clock_settime SYS_clock_settime64 -#endif - -#ifndef SYS_clock_adjtime -#define SYS_clock_adjtime SYS_clock_adjtime64 -#endif - -#ifndef SYS_clock_getres -#define SYS_clock_getres SYS_clock_getres_time64 -#endif - -#ifndef SYS_clock_nanosleep -#define SYS_clock_nanosleep SYS_clock_nanosleep_time64 -#endif - -#ifndef SYS_timer_gettime -#define SYS_timer_gettime SYS_timer_gettime64 -#endif - -#ifndef SYS_timer_settime -#define SYS_timer_settime SYS_timer_settime64 -#endif - -#ifndef SYS_timerfd_gettime -#define SYS_timerfd_gettime SYS_timerfd_gettime64 -#endif - -#ifndef SYS_timerfd_settime -#define SYS_timerfd_settime SYS_timerfd_settime64 -#endif - -#ifndef SYS_utimensat -#define SYS_utimensat SYS_utimensat_time64 -#endif - -#ifndef SYS_pselect6 -#define SYS_pselect6 SYS_pselect6_time64 -#endif - -#ifndef SYS_ppoll -#define SYS_ppoll SYS_ppoll_time64 -#endif - -#ifndef SYS_recvmmsg -#define SYS_recvmmsg SYS_recvmmsg_time64 -#endif - -#ifndef SYS_mq_timedsend -#define SYS_mq_timedsend SYS_mq_timedsend_time64 -#endif - -#ifndef SYS_mq_timedreceive -#define SYS_mq_timedreceive SYS_mq_timedreceive_time64 -#endif - -/* SYS_semtimedop omitted because SYS_ipc may provide it */ - -#ifndef SYS_rt_sigtimedwait -#define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64 -#endif - -#ifndef SYS_futex -#define SYS_futex SYS_futex_time64 -#endif - -#ifndef SYS_sched_rr_get_interval -#define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64 -#endif - - - - -/* socketcall calls */ - -#define __SC_socket 1 -#define __SC_bind 2 -#define __SC_connect 3 -#define __SC_listen 4 -#define __SC_accept 5 -#define __SC_getsockname 6 -#define __SC_getpeername 7 -#define __SC_socketpair 8 -#define __SC_send 9 -#define __SC_recv 10 -#define __SC_sendto 11 -#define __SC_recvfrom 12 -#define __SC_shutdown 13 -#define __SC_setsockopt 14 -#define __SC_getsockopt 15 -#define __SC_sendmsg 16 -#define __SC_recvmsg 17 -#define __SC_accept4 18 -#define __SC_recvmmsg 19 -#define __SC_sendmmsg 20 - -/* This is valid only because all socket syscalls are made via - * socketcall, which always fills unused argument slots with zeros. */ -#ifndef SYS_accept -#define SYS_accept SYS_accept4 -#endif - -#ifndef SO_RCVTIMEO_OLD -#define SO_RCVTIMEO_OLD 20 -#endif -#ifndef SO_SNDTIMEO_OLD -#define SO_SNDTIMEO_OLD 21 -#endif - -#define SO_TIMESTAMP_OLD 29 -#define SO_TIMESTAMPNS_OLD 35 -#define SO_TIMESTAMPING_OLD 37 -#define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD -#define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD -#define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD - -#ifndef SIOCGSTAMP_OLD -#define SIOCGSTAMP_OLD 0x8906 -#endif -#ifndef SIOCGSTAMPNS_OLD -#define SIOCGSTAMPNS_OLD 0x8907 -#endif - -#ifdef SYS_open -#define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE) -#define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo) -#define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE) -#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo) -#else -#define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) -#define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) -#define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) -#define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) -#endif - -#define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__) -#define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__)) - -#define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__) -#define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) - -#ifdef SYS_wait4 -#define __sys_wait4(a,b,c,d) __syscall(SYS_wait4,a,b,c,d) -#define __sys_wait4_cp(a,b,c,d) __syscall_cp(SYS_wait4,a,b,c,d) -#else -hidden long __emulate_wait4(int, int *, int, void *, int); -#define __sys_wait4(a,b,c,d) __emulate_wait4(a,b,c,d,0) -#define __sys_wait4_cp(a,b,c,d) __emulate_wait4(a,b,c,d,1) -#endif - -#define sys_wait4(a,b,c,d) __syscall_ret(__sys_wait4(a,b,c,d)) -#define sys_wait4_cp(a,b,c,d) __syscall_ret(__sys_wait4_cp(a,b,c,d)) - -hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); - -hidden void *__vdsosym(const char *, const char *); - -#endif -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/locale/catclose.c b/lib/libc/wasi/libc-top-half/musl/src/locale/catclose.c deleted file mode 100644 index a110246cb78db2a3437673986396da149dc3b556..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/locale/catclose.c +++ /dev/null @@ -1,18 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet -#include -#endif - -#define V(p) be32toh(*(uint32_t *)(p)) - -int catclose (nl_catd catd) -{ -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet - char *map = (char *)catd; - munmap(map, V(map+8)+20); -#endif - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/locale/catgets.c b/lib/libc/wasi/libc-top-half/musl/src/locale/catgets.c deleted file mode 100644 index ad0457fdf3e69101fd73ae372959ecdf9558a1ae..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/locale/catgets.c +++ /dev/null @@ -1,44 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include -#include -#include - -#define V(p) be32toh(*(uint32_t *)(p)) - -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet -static int cmp(const void *a, const void *b) -{ - uint32_t x = V(a), y = V(b); - return xy ? 1 : 0; -} -#endif - -char *catgets (nl_catd catd, int set_id, int msg_id, const char *s) -{ -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet - const char *map = (const char *)catd; - uint32_t nsets = V(map+4); - const char *sets = map+20; - const char *msgs = map+20+V(map+12); - const char *strings = map+20+V(map+16); - uint32_t set_id_be = htobe32(set_id); - uint32_t msg_id_be = htobe32(msg_id); - const char *set = bsearch(&set_id_be, sets, nsets, 12, cmp); - if (!set) { - errno = ENOMSG; - return (char *)s; - } - uint32_t nmsgs = V(set+4); - msgs += 12*V(set+8); - const char *msg = bsearch(&msg_id_be, msgs, nmsgs, 12, cmp); - if (!msg) { - errno = ENOMSG; - return (char *)s; - } - return (char *)(strings + V(msg+8)); -#else - return (char *)s; -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/locale/catopen.c b/lib/libc/wasi/libc-top-half/musl/src/locale/catopen.c deleted file mode 100644 index c6116b1606c30701b911dec28bc8efd5d262b629..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/locale/catopen.c +++ /dev/null @@ -1,87 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet -#include -#endif -#include "libc.h" - -#define V(p) be32toh(*(uint32_t *)(p)) - -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet -static nl_catd do_catopen(const char *name) -{ - size_t size; - const unsigned char *map = __map_file(name, &size); - /* Size recorded in the file must match file size; otherwise - * the information needed to unmap the file will be lost. */ - if (!map || V(map) != 0xff88ff89 || 20+V(map+8) != size) { - if(map) munmap((void *)map, size); - errno = ENOENT; - return (nl_catd)-1; - } - return (nl_catd)map; -} -#endif - -nl_catd catopen(const char *name, int oflag) -{ -#ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet - nl_catd catd; - - if (strchr(name, '/')) return do_catopen(name); - - char buf[PATH_MAX]; - size_t i; - const char *path, *lang, *p, *z; - if (libc.secure || !(path = getenv("NLSPATH"))) { - errno = ENOENT; - return (nl_catd)-1; - } - lang = oflag ? nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)) : getenv("LANG"); - if (!lang) lang = ""; - for (p=path; *p; p=z) { - i = 0; - z = __strchrnul(p, ':'); - for (; p= sizeof buf - i) { - break; - } - memcpy(buf+i, v, l); - i += l; - } - if (!*z && (p -#include -#ifdef __wasilibc_unmodified_upstream // WASI has no mmap -#include -#endif -#include -#include "locale_impl.h" -#include "libc.h" -#include "lock.h" -#include "fork_impl.h" - -const char *__lctrans_impl(const char *msg, const struct __locale_map *lm) -{ - const char *trans = 0; - if (lm) trans = __mo_lookup(lm->map, lm->map_size, msg); - return trans ? trans : msg; -} - -static const char envvars[][12] = { - "LC_CTYPE", - "LC_NUMERIC", - "LC_TIME", - "LC_COLLATE", - "LC_MONETARY", - "LC_MESSAGES", -}; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -volatile int __locale_lock[1]; -volatile int *const __locale_lockptr = __locale_lock; -#endif - -const struct __locale_map *__get_locale(int cat, const char *val) -{ - static void *volatile loc_head; - const struct __locale_map *p; - struct __locale_map *new = 0; - const char *path = 0, *z; - char buf[256]; - size_t l, n; - - if (!*val) { - (val = getenv("LC_ALL")) && *val || - (val = getenv(envvars[cat])) && *val || - (val = getenv("LANG")) && *val || - (val = "C.UTF-8"); - } - - /* Limit name length and forbid leading dot or any slashes. */ - for (n=0; nnext) - if (!strcmp(val, p->name)) return p; - -#ifdef __wasilibc_unmodified_upstream // WASI has no mmap, though this code could be made to use something else - if (!libc.secure) path = getenv("MUSL_LOCPATH"); - /* FIXME: add a default path? */ - - if (path) for (; *path; path=z+!!*z) { - z = __strchrnul(path, ':'); - l = z - path; - if (l >= sizeof buf - n - 2) continue; - memcpy(buf, path, l); - buf[l] = '/'; - memcpy(buf+l+1, val, n); - buf[l+1+n] = 0; - size_t map_size; - const void *map = __map_file(buf, &map_size); - if (map) { - new = malloc(sizeof *new); - if (!new) { - __munmap((void *)map, map_size); - break; - } - new->map = map; - new->map_size = map_size; - memcpy(new->name, val, n); - new->name[n] = 0; - new->next = loc_head; - loc_head = new; - break; - } - } -#endif - - /* If no locale definition was found, make a locale map - * object anyway to store the name, which is kept for the - * sake of being able to do message translations at the - * application level. */ - if (!new && (new = malloc(sizeof *new))) { - new->map = __c_dot_utf8.map; - new->map_size = __c_dot_utf8.map_size; - memcpy(new->name, val, n); - new->name[n] = 0; - new->next = loc_head; - loc_head = new; - } - - /* For LC_CTYPE, never return a null pointer unless the - * requested name was "C" or "POSIX". */ - if (!new && cat == LC_CTYPE) new = (void *)&__c_dot_utf8; - - return new; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/locale/newlocale.c b/lib/libc/wasi/libc-top-half/musl/src/locale/newlocale.c deleted file mode 100644 index 154682de971f6b65acd420b6639b692f1b7a33eb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/locale/newlocale.c +++ /dev/null @@ -1,67 +0,0 @@ -#include -#include -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include -#endif -#include "locale_impl.h" -#include "lock.h" - -static int default_locale_init_done; -static struct __locale_struct default_locale, default_ctype_locale; - -int __loc_is_allocated(locale_t loc) -{ - return loc && loc != C_LOCALE && loc != UTF8_LOCALE - && loc != &default_locale && loc != &default_ctype_locale; -} - -static locale_t do_newlocale(int mask, const char *name, locale_t loc) -{ - struct __locale_struct tmp; - - for (int i=0; icat[i] : - __get_locale(i, (mask & (1<locale; -#else - locale_t old = libc.current_locale; - if (!old) old = LC_GLOBAL_LOCALE; -#endif - locale_t global = &libc.global_locale; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - if (new) self->locale = new == LC_GLOBAL_LOCALE ? global : new; -#else - if (new) libc.current_locale = new == LC_GLOBAL_LOCALE ? global : new; -#endif - - return old == global ? LC_GLOBAL_LOCALE : old; -} - -weak_alias(__uselocale, uselocale); diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/__expo2.c b/lib/libc/wasi/libc-top-half/musl/src/math/__expo2.c deleted file mode 100644 index 4ff17df405ac532ce8eb70225443f884a39c740e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/__expo2.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "libm.h" - -/* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */ -static const int k = 2043; -static const double kln2 = 0x1.62066151add8bp+10; - -/* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -double __expo2(double x, double sign) -#else -double __expo2(double x) -#endif -{ - double scale; - - /* note that k is odd and scale*scale overflows */ - INSERT_WORDS(scale, (uint32_t)(0x3ff + k/2) << 20, 0); - /* exp(x - k ln2) * 2**(k-1) */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - /* in directed rounding correct sign before rounding or overflow is important */ - return exp(x - kln2) * (sign * scale) * scale; -#else - return exp(x - kln2) * scale * scale; -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/__expo2f.c b/lib/libc/wasi/libc-top-half/musl/src/math/__expo2f.c deleted file mode 100644 index acbaeb4ce36040ff4b1f9f98181da51abd880546..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/__expo2f.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "libm.h" - -/* k is such that k*ln2 has minimal relative error and x - kln2 > log(FLT_MIN) */ -static const int k = 235; -static const float kln2 = 0x1.45c778p+7f; - -/* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -float __expo2f(float x, float sign) -#else -float __expo2f(float x) -#endif -{ - float scale; - - /* note that k is odd and scale*scale overflows */ - SET_FLOAT_WORD(scale, (uint32_t)(0x7f + k/2) << 23); - /* exp(x - k ln2) * 2**(k-1) */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - /* in directed rounding correct sign before rounding or overflow is important */ - return expf(x - kln2) * (sign * scale) * scale; -#else - return expf(x - kln2) * scale * scale; -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2.c b/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2.c deleted file mode 100644 index 326cda75815a2425bcaada613d488befd9692a2b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2.c +++ /dev/null @@ -1,194 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * Optimized by Bruce D. Evans. - */ -/* __rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __rem_pio2_large() for large x - */ - -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 33 bit of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 33 bit of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 33 bit of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ -static const double -toint = 1.5/EPS, -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -pio4 = 0x1.921fb54442d18p-1, -#endif -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ -pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ -pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ -pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ -pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ -pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ - -/* caller must handle the case when reduction is not needed: |x| ~<= pi/4 */ -int __rem_pio2(double x, double *y) -{ - union {double f; uint64_t i;} u = {x}; - double_t z,w,t,r,fn; - double tx[3],ty[2]; - uint32_t ix; - int sign, n, ex, ey, i; - - sign = u.i>>63; - ix = u.i>>32 & 0x7fffffff; - if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ - if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ - goto medium; /* cancellation -- use medium case */ - if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ - if (!sign) { - z = x - pio2_1; /* one round good to 85 bits */ - y[0] = z - pio2_1t; - y[1] = (z-y[0]) - pio2_1t; - return 1; - } else { - z = x + pio2_1; - y[0] = z + pio2_1t; - y[1] = (z-y[0]) + pio2_1t; - return -1; - } - } else { - if (!sign) { - z = x - 2*pio2_1; - y[0] = z - 2*pio2_1t; - y[1] = (z-y[0]) - 2*pio2_1t; - return 2; - } else { - z = x + 2*pio2_1; - y[0] = z + 2*pio2_1t; - y[1] = (z-y[0]) + 2*pio2_1t; - return -2; - } - } - } - if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ - if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ - if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ - goto medium; - if (!sign) { - z = x - 3*pio2_1; - y[0] = z - 3*pio2_1t; - y[1] = (z-y[0]) - 3*pio2_1t; - return 3; - } else { - z = x + 3*pio2_1; - y[0] = z + 3*pio2_1t; - y[1] = (z-y[0]) + 3*pio2_1t; - return -3; - } - } else { - if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ - goto medium; - if (!sign) { - z = x - 4*pio2_1; - y[0] = z - 4*pio2_1t; - y[1] = (z-y[0]) - 4*pio2_1t; - return 4; - } else { - z = x + 4*pio2_1; - y[0] = z + 4*pio2_1t; - y[1] = (z-y[0]) + 4*pio2_1t; - return -4; - } - } - } - if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ -medium: - /* rint(x/(pi/2)) */ - fn = (double_t)x*invpio2 + toint - toint; - n = (int32_t)fn; - r = x - fn*pio2_1; - w = fn*pio2_1t; /* 1st round, good to 85 bits */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - /* Matters with directed rounding. */ - if (predict_false(r - w < -pio4)) { - n--; - fn--; - r = x - fn*pio2_1; - w = fn*pio2_1t; - } else if (predict_false(r - w > pio4)) { - n++; - fn++; - r = x - fn*pio2_1; - w = fn*pio2_1t; - } -#endif - y[0] = r - w; - u.f = y[0]; - ey = u.i>>52 & 0x7ff; - ex = ix>>20; - if (ex - ey > 16) { /* 2nd round, good to 118 bits */ - t = r; - w = fn*pio2_2; - r = t - w; - w = fn*pio2_2t - ((t-r)-w); - y[0] = r - w; - u.f = y[0]; - ey = u.i>>52 & 0x7ff; - if (ex - ey > 49) { /* 3rd round, good to 151 bits, covers all cases */ - t = r; - w = fn*pio2_3; - r = t - w; - w = fn*pio2_3t - ((t-r)-w); - y[0] = r - w; - } - } - y[1] = (r - y[0]) - w; - return n; - } - /* - * all other (large) arguments - */ - if (ix >= 0x7ff00000) { /* x is inf or NaN */ - y[0] = y[1] = x - x; - return 0; - } - /* set z = scalbn(|x|,-ilogb(x)+23) */ - u.f = x; - u.i &= (uint64_t)-1>>12; - u.i |= (uint64_t)(0x3ff + 23)<<52; - z = u.f; - for (i=0; i < 2; i++) { - tx[i] = (double)(int32_t)z; - z = (z-tx[i])*0x1p24; - } - tx[i] = z; - /* skip zero terms, first term is non-zero */ - while (tx[i] == 0.0) - i--; - n = __rem_pio2_large(tx,ty,(int)(ix>>20)-(0x3ff+23),i+1,1); - if (sign) { - y[0] = -ty[0]; - y[1] = -ty[1]; - return -n; - } - y[0] = ty[0]; - y[1] = ty[1]; - return n; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2f.c b/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2f.c deleted file mode 100644 index 034ed810016acc240caa92bee0e023654e7cee9c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2f.c +++ /dev/null @@ -1,90 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2f.c */ -/* - * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. - * Debugged and optimized by Bruce D. Evans. - */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * - * Developed at SunPro, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - */ -/* __rem_pio2f(x,y) - * - * return the remainder of x rem pi/2 in *y - * use double precision for everything except passing x - * use __rem_pio2_large() for large x - */ - -#include "libm.h" - -#if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 -#define EPS DBL_EPSILON -#elif FLT_EVAL_METHOD==2 -#define EPS LDBL_EPSILON -#endif - -/* - * invpio2: 53 bits of 2/pi - * pio2_1: first 25 bits of pi/2 - * pio2_1t: pi/2 - pio2_1 - */ -static const double -toint = 1.5/EPS, -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -pio4 = 0x1.921fb6p-1, -#endif -invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ -pio2_1 = 1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */ -pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */ - -int __rem_pio2f(float x, double *y) -{ - union {float f; uint32_t i;} u = {x}; - double tx[1],ty[1]; - double_t fn; - uint32_t ix; - int n, sign, e0; - - ix = u.i & 0x7fffffff; - /* 25+53 bit pi is good enough for medium size */ - if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */ - /* Use a specialized rint() to get fn. */ - fn = (double_t)x*invpio2 + toint - toint; - n = (int32_t)fn; - *y = x - fn*pio2_1 - fn*pio2_1t; -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - /* Matters with directed rounding. */ - if (predict_false(*y < -pio4)) { - n--; - fn--; - *y = x - fn*pio2_1 - fn*pio2_1t; - } else if (predict_false(*y > pio4)) { - n++; - fn++; - *y = x - fn*pio2_1 - fn*pio2_1t; - } -#endif - return n; - } - if(ix>=0x7f800000) { /* x is inf or NaN */ - *y = x-x; - return 0; - } - /* scale x into [2^23, 2^24-1] */ - sign = u.i>>31; - e0 = (ix>>23) - (0x7f+23); /* e0 = ilogb(|x|)-23, positive */ - u.i = ix - (e0<<23); - tx[0] = u.f; - n = __rem_pio2_large(tx,ty,e0,1,0); - if (sign) { - *y = -ty[0]; - return -n; - } - *y = ty[0]; - return n; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2l.c b/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2l.c deleted file mode 100644 index e73a86bf3728f9f72e05c65183754c6115be0c65..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2l.c +++ /dev/null @@ -1,159 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/ld80/e_rem_pio2.c */ -/* - * ==================================================== - * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. - * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. - * - * Developed at SunSoft, a Sun Microsystems, Inc. business. - * Permission to use, copy, modify, and distribute this - * software is freely granted, provided that this notice - * is preserved. - * ==================================================== - * - * Optimized by Bruce D. Evans. - */ -#include "libm.h" -#if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -/* ld80 and ld128 version of __rem_pio2(x,y) - * - * return the remainder of x rem pi/2 in y[0]+y[1] - * use __rem_pio2_large() for large x - */ - -static const long double toint = 1.5/LDBL_EPSILON; - -#if LDBL_MANT_DIG == 64 -/* u ~< 0x1p25*pi/2 */ -#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000)) -#define QUOBITS(x) ((uint32_t)(int32_t)x & 0x7fffffff) -#define ROUND1 22 -#define ROUND2 61 -#define NX 3 -#define NY 2 -/* - * invpio2: 64 bits of 2/pi - * pio2_1: first 39 bits of pi/2 - * pio2_1t: pi/2 - pio2_1 - * pio2_2: second 39 bits of pi/2 - * pio2_2t: pi/2 - (pio2_1+pio2_2) - * pio2_3: third 39 bits of pi/2 - * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) - */ -static const double -pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */ -pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */ -pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */ -static const long double -pio4 = 0x1.921fb54442d1846ap-1L, -invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 */ -pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */ -pio2_2t = 6.36831716351095013979e-25L, /* 0xc51701b839a25205.0p-144 */ -pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */ -#elif LDBL_MANT_DIG == 113 -/* u ~< 0x1p45*pi/2 */ -#define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f)) -#define QUOBITS(x) ((uint32_t)(int64_t)x & 0x7fffffff) -#define ROUND1 51 -#define ROUND2 119 -#define NX 5 -#define NY 3 -static const long double -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes -pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, -#endif -invpio2 = 6.3661977236758134307553505349005747e-01L, /* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 */ -pio2_1 = 1.5707963267948966192292994253909555e+00L, /* 0x1921fb54442d18469800000000000.0p-112 */ -pio2_1t = 2.0222662487959507323996846200947577e-21L, /* 0x13198a2e03707344a4093822299f3.0p-181 */ -pio2_2 = 2.0222662487959507323994779168837751e-21L, /* 0x13198a2e03707344a400000000000.0p-181 */ -pio2_2t = 2.0670321098263988236496903051604844e-43L, /* 0x127044533e63a0105df531d89cd91.0p-254 */ -pio2_3 = 2.0670321098263988236499468110329591e-43L, /* 0x127044533e63a0105e00000000000.0p-254 */ -pio2_3t = -2.5650587247459238361625433492959285e-65L; /* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */ -#endif - -int __rem_pio2l(long double x, long double *y) -{ - union ldshape u,uz; - long double z,w,t,r,fn; - double tx[NX],ty[NY]; - int ex,ey,n,i; - - u.f = x; - ex = u.i.se & 0x7fff; - if (SMALL(u)) { - /* rint(x/(pi/2)) */ - fn = x*invpio2 + toint - toint; - n = QUOBITS(fn); - r = x-fn*pio2_1; - w = fn*pio2_1t; /* 1st round good to 102/180 bits (ld80/ld128) */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - /* Matters with directed rounding. */ - if (predict_false(r - w < -pio4)) { - n--; - fn--; - r = x - fn*pio2_1; - w = fn*pio2_1t; - } else if (predict_false(r - w > pio4)) { - n++; - fn++; - r = x - fn*pio2_1; - w = fn*pio2_1t; - } -#endif - y[0] = r-w; - u.f = y[0]; - ey = u.i.se & 0x7fff; - if (ex - ey > ROUND1) { /* 2nd iteration needed, good to 141/248 (ld80/ld128) */ - t = r; - w = fn*pio2_2; - r = t-w; - w = fn*pio2_2t-((t-r)-w); - y[0] = r-w; - u.f = y[0]; - ey = u.i.se & 0x7fff; - if (ex - ey > ROUND2) { /* 3rd iteration, good to 180/316 bits */ - t = r; /* will cover all possible cases (not verified for ld128) */ - w = fn*pio2_3; - r = t-w; - w = fn*pio2_3t-((t-r)-w); - y[0] = r-w; - } - } - y[1] = (r - y[0]) - w; - return n; - } - /* - * all other (large) arguments - */ - if (ex == 0x7fff) { /* x is inf or NaN */ - y[0] = y[1] = x - x; - return 0; - } - /* set z = scalbn(|x|,-ilogb(x)+23) */ - uz.f = x; - uz.i.se = 0x3fff + 23; - z = uz.f; - for (i=0; i < NX - 1; i++) { - tx[i] = (double)(int32_t)z; - z = (z-tx[i])*0x1p24; - } - tx[i] = z; - while (tx[i] == 0) - i--; - n = __rem_pio2_large(tx, ty, ex-0x3fff-23, i+1, NY); - w = ty[1]; - if (NY == 3) - w += ty[2]; - r = ty[0] + w; - /* TODO: for ld128 this does not follow the recommendation of the - comments of __rem_pio2_large which seem wrong if |ty[0]| > |ty[1]+ty[2]| */ - w -= r - ty[0]; - if (u.i.se >> 15) { - y[0] = -r; - y[1] = -w; - return -n; - } - y[0] = r; - y[1] = w; - return n; -} -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/fmal.c b/lib/libc/wasi/libc-top-half/musl/src/math/fmal.c deleted file mode 100644 index dd0e26332243f72737d7ba0f5c5dab176ffee9fa..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/fmal.c +++ /dev/null @@ -1,297 +0,0 @@ -/* origin: FreeBSD /usr/src/lib/msun/src/s_fmal.c */ -/*- - * Copyright (c) 2005-2011 David Schultz - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - - -#include "libm.h" -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double fmal(long double x, long double y, long double z) -{ - return fma(x, y, z); -} -#elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 -#include -#if LDBL_MANT_DIG == 64 -#define LASTBIT(u) (u.i.m & 1) -#define SPLIT (0x1p32L + 1) -#elif LDBL_MANT_DIG == 113 -#define LASTBIT(u) (u.i.lo & 1) -#define SPLIT (0x1p57L + 1) -#endif - -/* - * A struct dd represents a floating-point number with twice the precision - * of a long double. We maintain the invariant that "hi" stores the high-order - * bits of the result. - */ -struct dd { - long double hi; - long double lo; -}; - -/* - * Compute a+b exactly, returning the exact result in a struct dd. We assume - * that both a and b are finite, but make no assumptions about their relative - * magnitudes. - */ -static inline struct dd dd_add(long double a, long double b) -{ - struct dd ret; - long double s; - - ret.hi = a + b; - s = ret.hi - a; - ret.lo = (a - (ret.hi - s)) + (b - s); - return (ret); -} - -/* - * Compute a+b, with a small tweak: The least significant bit of the - * result is adjusted into a sticky bit summarizing all the bits that - * were lost to rounding. This adjustment negates the effects of double - * rounding when the result is added to another number with a higher - * exponent. For an explanation of round and sticky bits, see any reference - * on FPU design, e.g., - * - * J. Coonen. An Implementation Guide to a Proposed Standard for - * Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980. - */ -static inline long double add_adjusted(long double a, long double b) -{ - struct dd sum; - union ldshape u; - - sum = dd_add(a, b); - if (sum.lo != 0) { - u.f = sum.hi; - if (!LASTBIT(u)) - sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); - } - return (sum.hi); -} - -/* - * Compute ldexp(a+b, scale) with a single rounding error. It is assumed - * that the result will be subnormal, and care is taken to ensure that - * double rounding does not occur. - */ -static inline long double add_and_denormalize(long double a, long double b, int scale) -{ - struct dd sum; - int bits_lost; - union ldshape u; - - sum = dd_add(a, b); - - /* - * If we are losing at least two bits of accuracy to denormalization, - * then the first lost bit becomes a round bit, and we adjust the - * lowest bit of sum.hi to make it a sticky bit summarizing all the - * bits in sum.lo. With the sticky bit adjusted, the hardware will - * break any ties in the correct direction. - * - * If we are losing only one bit to denormalization, however, we must - * break the ties manually. - */ - if (sum.lo != 0) { - u.f = sum.hi; - bits_lost = -u.i.se - scale + 1; - if ((bits_lost != 1) ^ LASTBIT(u)) - sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); - } - return scalbnl(sum.hi, scale); -} - -/* - * Compute a*b exactly, returning the exact result in a struct dd. We assume - * that both a and b are normalized, so no underflow or overflow will occur. - * The current rounding mode must be round-to-nearest. - */ -static inline struct dd dd_mul(long double a, long double b) -{ - struct dd ret; - long double ha, hb, la, lb, p, q; - - p = a * SPLIT; - ha = a - p; - ha += p; - la = a - ha; - - p = b * SPLIT; - hb = b - p; - hb += p; - lb = b - hb; - - p = ha * hb; - q = ha * lb + la * hb; - - ret.hi = p + q; - ret.lo = p - ret.hi + q + la * lb; - return (ret); -} - -/* - * Fused multiply-add: Compute x * y + z with a single rounding error. - * - * We use scaling to avoid overflow/underflow, along with the - * canonical precision-doubling technique adapted from: - * - * Dekker, T. A Floating-Point Technique for Extending the - * Available Precision. Numer. Math. 18, 224-242 (1971). - */ -long double fmal(long double x, long double y, long double z) -{ - #pragma STDC FENV_ACCESS ON - long double xs, ys, zs, adj; - struct dd xy, r; - int oround; - int ex, ey, ez; - int spread; - - /* - * Handle special cases. The order of operations and the particular - * return values here are crucial in handling special cases involving - * infinities, NaNs, overflows, and signed zeroes correctly. - */ - if (!isfinite(x) || !isfinite(y)) - return (x * y + z); - if (!isfinite(z)) - return (z); - if (x == 0.0 || y == 0.0) - return (x * y + z); - if (z == 0.0) - return (x * y); - - xs = frexpl(x, &ex); - ys = frexpl(y, &ey); - zs = frexpl(z, &ez); - oround = fegetround(); - spread = ex + ey - ez; - - /* - * If x * y and z are many orders of magnitude apart, the scaling - * will overflow, so we handle these cases specially. Rounding - * modes other than FE_TONEAREST are painful. - */ - if (spread < -LDBL_MANT_DIG) { -#ifdef FE_INEXACT - feraiseexcept(FE_INEXACT); -#endif -#ifdef FE_UNDERFLOW - if (!isnormal(z)) - feraiseexcept(FE_UNDERFLOW); -#endif - switch (oround) { - default: /* FE_TONEAREST */ - return (z); -#ifdef FE_TOWARDZERO - case FE_TOWARDZERO: - if (x > 0.0 ^ y < 0.0 ^ z < 0.0) - return (z); - else - return (nextafterl(z, 0)); -#endif -#ifdef FE_DOWNWARD - case FE_DOWNWARD: - if (x > 0.0 ^ y < 0.0) - return (z); - else - return (nextafterl(z, -INFINITY)); -#endif -#ifdef FE_UPWARD - case FE_UPWARD: - if (x > 0.0 ^ y < 0.0) - return (nextafterl(z, INFINITY)); - else - return (z); -#endif - } - } - if (spread <= LDBL_MANT_DIG * 2) - zs = scalbnl(zs, -spread); - else - zs = copysignl(LDBL_MIN, zs); - - fesetround(FE_TONEAREST); - - /* - * Basic approach for round-to-nearest: - * - * (xy.hi, xy.lo) = x * y (exact) - * (r.hi, r.lo) = xy.hi + z (exact) - * adj = xy.lo + r.lo (inexact; low bit is sticky) - * result = r.hi + adj (correctly rounded) - */ - xy = dd_mul(xs, ys); - r = dd_add(xy.hi, zs); - - spread = ex + ey; - - if (r.hi == 0.0) { - /* - * When the addends cancel to 0, ensure that the result has - * the correct sign. - */ - fesetround(oround); -#ifdef __wasilibc_unmodified_upstream // WASI doesn't need old GCC workarounds - volatile long double vzs = zs; /* XXX gcc CSE bug workaround */ -#else - long double vzs = zs; -#endif - return xy.hi + vzs + scalbnl(xy.lo, spread); - } - - if (oround != FE_TONEAREST) { - /* - * There is no need to worry about double rounding in directed - * rounding modes. - * But underflow may not be raised correctly, example in downward rounding: - * fmal(0x1.0000000001p-16000L, 0x1.0000000001p-400L, -0x1p-16440L) - */ - long double ret; -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - int e = fetestexcept(FE_INEXACT); - feclearexcept(FE_INEXACT); -#endif - fesetround(oround); - adj = r.lo + xy.lo; - ret = scalbnl(r.hi + adj, spread); -#if defined(FE_INEXACT) && defined(FE_UNDERFLOW) - if (ilogbl(ret) < -16382 && fetestexcept(FE_INEXACT)) - feraiseexcept(FE_UNDERFLOW); - else if (e) - feraiseexcept(FE_INEXACT); -#endif - return ret; - } - - adj = add_adjusted(r.lo, xy.lo); - if (spread + ilogbl(r.hi) > -16383) - return scalbnl(r.hi + adj, spread); - else - return add_and_denormalize(r.hi, adj, spread); -} -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/powl.c b/lib/libc/wasi/libc-top-half/musl/src/math/powl.c deleted file mode 100644 index 25364d700c1498432193dc003ebe64871176d095..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/powl.c +++ /dev/null @@ -1,534 +0,0 @@ -/* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_powl.c */ -/* - * Copyright (c) 2008 Stephen L. Moshier - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. - */ -/* powl.c - * - * Power function, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, z, powl(); - * - * z = powl( x, y ); - * - * - * DESCRIPTION: - * - * Computes x raised to the yth power. Analytically, - * - * x**y = exp( y log(x) ). - * - * Following Cody and Waite, this program uses a lookup table - * of 2**-i/32 and pseudo extended precision arithmetic to - * obtain several extra bits of accuracy in both the logarithm - * and the exponential. - * - * - * ACCURACY: - * - * The relative error of pow(x,y) can be estimated - * by y dl ln(2), where dl is the absolute error of - * the internally computed base 2 logarithm. At the ends - * of the approximation interval the logarithm equal 1/32 - * and its relative error is about 1 lsb = 1.1e-19. Hence - * the predicted relative error in the result is 2.3e-21 y . - * - * Relative error: - * arithmetic domain # trials peak rms - * - * IEEE +-1000 40000 2.8e-18 3.7e-19 - * .001 < x < 1000, with log(x) uniformly distributed. - * -1000 < y < 1000, y uniformly distributed. - * - * IEEE 0,8700 60000 6.5e-18 1.0e-18 - * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed. - * - * - * ERROR MESSAGES: - * - * message condition value returned - * pow overflow x**y > MAXNUM INFINITY - * pow underflow x**y < 1/MAXNUM 0.0 - * pow domain x<0 and y noninteger 0.0 - * - */ - -#include "libm.h" - -#if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 -long double powl(long double x, long double y) -{ - return pow(x, y); -} -#elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 - -/* Table size */ -#define NXT 32 - -/* log(1+x) = x - .5x^2 + x^3 * P(z)/Q(z) - * on the domain 2^(-1/32) - 1 <= x <= 2^(1/32) - 1 - */ -static const long double P[] = { - 8.3319510773868690346226E-4L, - 4.9000050881978028599627E-1L, - 1.7500123722550302671919E0L, - 1.4000100839971580279335E0L, -}; -static const long double Q[] = { -/* 1.0000000000000000000000E0L,*/ - 5.2500282295834889175431E0L, - 8.4000598057587009834666E0L, - 4.2000302519914740834728E0L, -}; -/* A[i] = 2^(-i/32), rounded to IEEE long double precision. - * If i is even, A[i] + B[i/2] gives additional accuracy. - */ -static const long double A[33] = { - 1.0000000000000000000000E0L, - 9.7857206208770013448287E-1L, - 9.5760328069857364691013E-1L, - 9.3708381705514995065011E-1L, - 9.1700404320467123175367E-1L, - 8.9735453750155359320742E-1L, - 8.7812608018664974155474E-1L, - 8.5930964906123895780165E-1L, - 8.4089641525371454301892E-1L, - 8.2287773907698242225554E-1L, - 8.0524516597462715409607E-1L, - 7.8799042255394324325455E-1L, - 7.7110541270397041179298E-1L, - 7.5458221379671136985669E-1L, - 7.3841307296974965571198E-1L, - 7.2259040348852331001267E-1L, - 7.0710678118654752438189E-1L, - 6.9195494098191597746178E-1L, - 6.7712777346844636413344E-1L, - 6.6261832157987064729696E-1L, - 6.4841977732550483296079E-1L, - 6.3452547859586661129850E-1L, - 6.2092890603674202431705E-1L, - 6.0762367999023443907803E-1L, - 5.9460355750136053334378E-1L, - 5.8186242938878875689693E-1L, - 5.6939431737834582684856E-1L, - 5.5719337129794626814472E-1L, - 5.4525386633262882960438E-1L, - 5.3357020033841180906486E-1L, - 5.2213689121370692017331E-1L, - 5.1094857432705833910408E-1L, - 5.0000000000000000000000E-1L, -}; -static const long double B[17] = { - 0.0000000000000000000000E0L, - 2.6176170809902549338711E-20L, --1.0126791927256478897086E-20L, - 1.3438228172316276937655E-21L, - 1.2207982955417546912101E-20L, --6.3084814358060867200133E-21L, - 1.3164426894366316434230E-20L, --1.8527916071632873716786E-20L, - 1.8950325588932570796551E-20L, - 1.5564775779538780478155E-20L, - 6.0859793637556860974380E-21L, --2.0208749253662532228949E-20L, - 1.4966292219224761844552E-20L, - 3.3540909728056476875639E-21L, --8.6987564101742849540743E-22L, --1.2327176863327626135542E-20L, - 0.0000000000000000000000E0L, -}; - -/* 2^x = 1 + x P(x), - * on the interval -1/32 <= x <= 0 - */ -static const long double R[] = { - 1.5089970579127659901157E-5L, - 1.5402715328927013076125E-4L, - 1.3333556028915671091390E-3L, - 9.6181291046036762031786E-3L, - 5.5504108664798463044015E-2L, - 2.4022650695910062854352E-1L, - 6.9314718055994530931447E-1L, -}; - -#define MEXP (NXT*16384.0L) -/* The following if denormal numbers are supported, else -MEXP: */ -#define MNEXP (-NXT*(16384.0L+64.0L)) -/* log2(e) - 1 */ -#define LOG2EA 0.44269504088896340735992L - -#define F W -#define Fa Wa -#define Fb Wb -#define G W -#define Ga Wa -#define Gb u -#define H W -#define Ha Wb -#define Hb Wb - -static const long double MAXLOGL = 1.1356523406294143949492E4L; -static const long double MINLOGL = -1.13994985314888605586758E4L; -static const long double LOGE2L = 6.9314718055994530941723E-1L; -static const long double huge = 0x1p10000L; -/* XXX Prevent gcc from erroneously constant folding this. */ -#ifdef __wasilibc_unmodified_upstream // WASI doesn't need old GCC workarounds -static const volatile long double twom10000 = 0x1p-10000L; -#else -static const long double twom10000 = 0x1p-10000L; -#endif - -static long double reducl(long double); -static long double powil(long double, int); - -long double powl(long double x, long double y) -{ - /* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */ - int i, nflg, iyflg, yoddint; - long e; - volatile long double z=0; - long double w=0, W=0, Wa=0, Wb=0, ya=0, yb=0, u=0; - - /* make sure no invalid exception is raised by nan comparision */ - if (isnan(x)) { - if (!isnan(y) && y == 0.0) - return 1.0; - return x; - } - if (isnan(y)) { - if (x == 1.0) - return 1.0; - return y; - } - if (x == 1.0) - return 1.0; /* 1**y = 1, even if y is nan */ - if (y == 0.0) - return 1.0; /* x**0 = 1, even if x is nan */ - if (y == 1.0) - return x; - /* if y*log2(x) < log2(LDBL_TRUE_MIN)-1 then x^y uflows to 0 - if y*log2(x) > -log2(LDBL_TRUE_MIN)+1 > LDBL_MAX_EXP then x^y oflows - if |x|!=1 then |log2(x)| > |log(x)| > LDBL_EPSILON/2 so - x^y oflows/uflows if |y|*LDBL_EPSILON/2 > -log2(LDBL_TRUE_MIN)+1 */ - if (fabsl(y) > 2*(-LDBL_MIN_EXP+LDBL_MANT_DIG+1)/LDBL_EPSILON) { - /* y is not an odd int */ - if (x == -1.0) - return 1.0; - if (y == INFINITY) { - if (x > 1.0 || x < -1.0) - return INFINITY; - return 0.0; - } - if (y == -INFINITY) { - if (x > 1.0 || x < -1.0) - return 0.0; - return INFINITY; - } - if ((x > 1.0 || x < -1.0) == (y > 0)) - return huge * huge; - return twom10000 * twom10000; - } - if (x == INFINITY) { - if (y > 0.0) - return INFINITY; - return 0.0; - } - - w = floorl(y); - - /* Set iyflg to 1 if y is an integer. */ - iyflg = 0; - if (w == y) - iyflg = 1; - - /* Test for odd integer y. */ - yoddint = 0; - if (iyflg) { - ya = fabsl(y); - ya = floorl(0.5 * ya); - yb = 0.5 * fabsl(w); - if( ya != yb ) - yoddint = 1; - } - - if (x == -INFINITY) { - if (y > 0.0) { - if (yoddint) - return -INFINITY; - return INFINITY; - } - if (y < 0.0) { - if (yoddint) - return -0.0; - return 0.0; - } - } - nflg = 0; /* (x<0)**(odd int) */ - if (x <= 0.0) { - if (x == 0.0) { - if (y < 0.0) { - if (signbit(x) && yoddint) - /* (-0.0)**(-odd int) = -inf, divbyzero */ - return -1.0/0.0; - /* (+-0.0)**(negative) = inf, divbyzero */ - return 1.0/0.0; - } - if (signbit(x) && yoddint) - return -0.0; - return 0.0; - } - if (iyflg == 0) - return (x - x) / (x - x); /* (x<0)**(non-int) is NaN */ - /* (x<0)**(integer) */ - if (yoddint) - nflg = 1; /* negate result */ - x = -x; - } - /* (+integer)**(integer) */ - if (iyflg && floorl(x) == x && fabsl(y) < 32768.0) { - w = powil(x, (int)y); - return nflg ? -w : w; - } - - /* separate significand from exponent */ - x = frexpl(x, &i); - e = i; - - /* find significand in antilog table A[] */ - i = 1; - if (x <= A[17]) - i = 17; - if (x <= A[i+8]) - i += 8; - if (x <= A[i+4]) - i += 4; - if (x <= A[i+2]) - i += 2; - if (x >= A[1]) - i = -1; - i += 1; - - /* Find (x - A[i])/A[i] - * in order to compute log(x/A[i]): - * - * log(x) = log( a x/a ) = log(a) + log(x/a) - * - * log(x/a) = log(1+v), v = x/a - 1 = (x-a)/a - */ - x -= A[i]; - x -= B[i/2]; - x /= A[i]; - - /* rational approximation for log(1+v): - * - * log(1+v) = v - v**2/2 + v**3 P(v) / Q(v) - */ - z = x*x; - w = x * (z * __polevll(x, P, 3) / __p1evll(x, Q, 3)); - w = w - 0.5*z; - - /* Convert to base 2 logarithm: - * multiply by log2(e) = 1 + LOG2EA - */ - z = LOG2EA * w; - z += w; - z += LOG2EA * x; - z += x; - - /* Compute exponent term of the base 2 logarithm. */ - w = -i; - w /= NXT; - w += e; - /* Now base 2 log of x is w + z. */ - - /* Multiply base 2 log by y, in extended precision. */ - - /* separate y into large part ya - * and small part yb less than 1/NXT - */ - ya = reducl(y); - yb = y - ya; - - /* (w+z)(ya+yb) - * = w*ya + w*yb + z*y - */ - F = z * y + w * yb; - Fa = reducl(F); - Fb = F - Fa; - - G = Fa + w * ya; - Ga = reducl(G); - Gb = G - Ga; - - H = Fb + Gb; - Ha = reducl(H); - w = (Ga + Ha) * NXT; - - /* Test the power of 2 for overflow */ - if (w > MEXP) - return huge * huge; /* overflow */ - if (w < MNEXP) - return twom10000 * twom10000; /* underflow */ - - e = w; - Hb = H - Ha; - - if (Hb > 0.0) { - e += 1; - Hb -= 1.0/NXT; /*0.0625L;*/ - } - - /* Now the product y * log2(x) = Hb + e/NXT. - * - * Compute base 2 exponential of Hb, - * where -0.0625 <= Hb <= 0. - */ - z = Hb * __polevll(Hb, R, 6); /* z = 2**Hb - 1 */ - - /* Express e/NXT as an integer plus a negative number of (1/NXT)ths. - * Find lookup table entry for the fractional power of 2. - */ - if (e < 0) - i = 0; - else - i = 1; - i = e/NXT + i; - e = NXT*i - e; - w = A[e]; - z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */ - z = z + w; - z = scalbnl(z, i); /* multiply by integer power of 2 */ - - if (nflg) - z = -z; - return z; -} - - -/* Find a multiple of 1/NXT that is within 1/NXT of x. */ -static long double reducl(long double x) -{ - long double t; - - t = x * NXT; - t = floorl(t); - t = t / NXT; - return t; -} - -/* - * Positive real raised to integer power, long double precision - * - * - * SYNOPSIS: - * - * long double x, y, powil(); - * int n; - * - * y = powil( x, n ); - * - * - * DESCRIPTION: - * - * Returns argument x>0 raised to the nth power. - * The routine efficiently decomposes n as a sum of powers of - * two. The desired power is a product of two-to-the-kth - * powers of x. Thus to compute the 32767 power of x requires - * 28 multiplications instead of 32767 multiplications. - * - * - * ACCURACY: - * - * Relative error: - * arithmetic x domain n domain # trials peak rms - * IEEE .001,1000 -1022,1023 50000 4.3e-17 7.8e-18 - * IEEE 1,2 -1022,1023 20000 3.9e-17 7.6e-18 - * IEEE .99,1.01 0,8700 10000 3.6e-16 7.2e-17 - * - * Returns MAXNUM on overflow, zero on underflow. - */ - -static long double powil(long double x, int nn) -{ - long double ww, y; - long double s; - int n, e, sign, lx; - - if (nn == 0) - return 1.0; - - if (nn < 0) { - sign = -1; - n = -nn; - } else { - sign = 1; - n = nn; - } - - /* Overflow detection */ - - /* Calculate approximate logarithm of answer */ - s = x; - s = frexpl( s, &lx); - e = (lx - 1)*n; - if ((e == 0) || (e > 64) || (e < -64)) { - s = (s - 7.0710678118654752e-1L) / (s + 7.0710678118654752e-1L); - s = (2.9142135623730950L * s - 0.5 + lx) * nn * LOGE2L; - } else { - s = LOGE2L * e; - } - - if (s > MAXLOGL) - return huge * huge; /* overflow */ - - if (s < MINLOGL) - return twom10000 * twom10000; /* underflow */ - /* Handle tiny denormal answer, but with less accuracy - * since roundoff error in 1.0/x will be amplified. - * The precise demarcation should be the gradual underflow threshold. - */ - if (s < -MAXLOGL+2.0) { - x = 1.0/x; - sign = -sign; - } - - /* First bit of the power */ - if (n & 1) - y = x; - else - y = 1.0; - - ww = x; - n >>= 1; - while (n) { - ww = ww * ww; /* arg to the 2-to-the-kth power */ - if (n & 1) /* if that bit is set, then include in product */ - y *= ww; - n >>= 1; - } - - if (sign < 0) - y = 1.0/y; - return y; -} -#elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 -// TODO: broken implementation to make things compile -long double powl(long double x, long double y) -{ - return pow(x, y); -} -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/sinh.c b/lib/libc/wasi/libc-top-half/musl/src/math/sinh.c deleted file mode 100644 index c8dda8d6849e49fc4e489ba5e71cae05f86ebce4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/sinh.c +++ /dev/null @@ -1,43 +0,0 @@ -#include "libm.h" - -/* sinh(x) = (exp(x) - 1/exp(x))/2 - * = (exp(x)-1 + (exp(x)-1)/exp(x))/2 - * = x + x^3/6 + o(x^5) - */ -double sinh(double x) -{ - union {double f; uint64_t i;} u = {.f = x}; - uint32_t w; - double t, h, absx; - - h = 0.5; - if (u.i >> 63) - h = -h; - /* |x| */ - u.i &= (uint64_t)-1/2; - absx = u.f; - w = u.i >> 32; - - /* |x| < log(DBL_MAX) */ - if (w < 0x40862e42) { - t = expm1(absx); - if (w < 0x3ff00000) { - if (w < 0x3ff00000 - (26<<20)) - /* note: inexact and underflow are raised by expm1 */ - /* note: this branch avoids spurious underflow */ - return x; - return h*(2*t - t*t/(t+1)); - } - /* note: |x|>log(0x1p26)+eps could be just h*exp(x) */ - return h*(t + t/(t+1)); - } - - /* |x| > log(DBL_MAX) or nan */ - /* note: the result is stored to handle overflow */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - t = __expo2(absx, 2*h); -#else - t = 2*h*__expo2(absx); -#endif - return t; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/math/sinhf.c b/lib/libc/wasi/libc-top-half/musl/src/math/sinhf.c deleted file mode 100644 index 3ac49e218678cd69dab0e7be853bc1286bcc656d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/math/sinhf.c +++ /dev/null @@ -1,35 +0,0 @@ -#include "libm.h" - -float sinhf(float x) -{ - union {float f; uint32_t i;} u = {.f = x}; - uint32_t w; - float t, h, absx; - - h = 0.5; - if (u.i >> 31) - h = -h; - /* |x| */ - u.i &= 0x7fffffff; - absx = u.f; - w = u.i; - - /* |x| < log(FLT_MAX) */ - if (w < 0x42b17217) { - t = expm1f(absx); - if (w < 0x3f800000) { - if (w < 0x3f800000 - (12<<23)) - return x; - return h*(2*t - t*t/(t+1)); - } - return h*(t + t/(t+1)); - } - - /* |x| > logf(FLT_MAX) or nan */ -#ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes - t = __expo2f(absx, 2*h); -#else - t = 2*h*__expo2f(absx); -#endif - return t; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/misc/dl.c b/lib/libc/wasi/libc-top-half/musl/src/misc/dl.c deleted file mode 100644 index 266594fd1fd65628a7069ca53338e7aacdf4c0a9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/misc/dl.c +++ /dev/null @@ -1,45 +0,0 @@ -/* This file is used to build libdl.so with stub versions of `dlopen`, `dlsym`, - * etc. The intention is that this stubbed libdl.so can be used to build - * libraries and applications which use `dlopen` without committing to a - * specific runtime implementation. Later, it can be replaced with a real, - * working libdl.so (e.g. at runtime or component composition time). - * - * For example, the `wasm-tools component link` subcommand can be used to create - * a component that bundles any `dlopen`-able libraries in such a way that their - * function exports can be resolved symbolically at runtime using an - * implementation of libdl.so designed for that purpose. In other cases, a - * runtime might provide Emscripten-style dynamic linking via URLs or else a - * more traditional, filesystem-based implementation. Finally, even this - * stubbed version of libdl.so can be used at runtime in cases where dynamic - * library resolution cannot or should not be supported (and the application can - * handle this situation gracefully). */ - -#include -#include - -static const char *error = NULL; - -weak int dlclose(void *library) -{ - error = "dlclose not implemented"; - return -1; -} - -weak char *dlerror(void) -{ - const char *var = error; - error = NULL; - return (char*) var; -} - -weak void *dlopen(const char *name, int flags) -{ - error = "dlopen not implemented"; - return NULL; -} - -weak void *dlsym(void *library, const char *name) -{ - error = "dlsym not implemented"; - return NULL; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/misc/fmtmsg.c b/lib/libc/wasi/libc-top-half/musl/src/misc/fmtmsg.c deleted file mode 100644 index 0c66076ef1f532fc744b5170b72b53c0ef02d7ef..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/misc/fmtmsg.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Public domain fmtmsg() - * Written by Isaac Dunham, 2014 - */ -#include -#include -#include -#include -#include -#include -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include -#endif - -/* - * If lstr is the first part of bstr, check that the next char in bstr - * is either \0 or : - */ -static int _strcolcmp(const char *lstr, const char *bstr) -{ - size_t i = 0; - while (lstr[i] && bstr[i] && (bstr[i] == lstr[i])) i++; - if ( lstr[i] || (bstr[i] && bstr[i] != ':')) return 1; - return 0; -} - -int fmtmsg(long classification, const char *label, int severity, - const char *text, const char *action, const char *tag) -{ - int ret = 0, i, consolefd, verb = 0; - char *errstring = MM_NULLSEV, *cmsg = getenv("MSGVERB"); - char *const msgs[] = { - "label", "severity", "text", "action", "tag", NULL - }; - int cs; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); -#endif - - if (severity == MM_HALT) errstring = "HALT: "; - else if (severity == MM_ERROR) errstring = "ERROR: "; - else if (severity == MM_WARNING) errstring = "WARNING: "; - else if (severity == MM_INFO) errstring = "INFO: "; - - if (classification & MM_CONSOLE) { - consolefd = open("/dev/console", O_WRONLY); - if (consolefd < 0) { - ret = MM_NOCON; - } else { - if (dprintf(consolefd, "%s%s%s%s%s%s%s%s\n", - label?label:"", label?": ":"", - severity?errstring:"", text?text:"", - action?"\nTO FIX: ":"", - action?action:"", action?" ":"", - tag?tag:"" )<1) - ret = MM_NOCON; - close(consolefd); - } - } - - if (classification & MM_PRINT) { - while (cmsg && cmsg[0]) { - for(i=0; msgs[i]; i++) { - if (!_strcolcmp(msgs[i], cmsg)) break; - } - if (msgs[i] == NULL) { - //ignore MSGVERB-unrecognized component - verb = 0xFF; - break; - } else { - verb |= (1 << i); - cmsg = strchr(cmsg, ':'); - if (cmsg) cmsg++; - } - } - if (!verb) verb = 0xFF; - if (dprintf(2, "%s%s%s%s%s%s%s%s\n", - (verb&1 && label) ? label : "", - (verb&1 && label) ? ": " : "", - (verb&2 && severity) ? errstring : "", - (verb&4 && text) ? text : "", - (verb&8 && action) ? "\nTO FIX: " : "", - (verb&8 && action) ? action : "", - (verb&8 && action) ? " " : "", - (verb&16 && tag) ? tag : "" ) < 1) - ret |= MM_NOMSG; - } - if ((ret & (MM_NOCON|MM_NOMSG)) == (MM_NOCON|MM_NOMSG)) - ret = MM_NOTOK; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - pthread_setcancelstate(cs, 0); -#endif - - return ret; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/misc/nftw.c b/lib/libc/wasi/libc-top-half/musl/src/misc/nftw.c deleted file mode 100644 index e32743b5ac632752ec61d4e476872c6581cc2905..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/misc/nftw.c +++ /dev/null @@ -1,150 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include -#endif - -struct history -{ - struct history *chain; - dev_t dev; - ino_t ino; - int level; - int base; -}; - -#undef dirfd -#define dirfd(d) (*(int *)d) - -static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags, struct history *h) -{ - size_t l = strlen(path), j = l && path[l-1]=='/' ? l-1 : l; - struct stat st; - struct history new; - int type; - int r; - int dfd; - int err; - struct FTW lev; - - st.st_dev = st.st_ino = 0; - - if ((flags & FTW_PHYS) ? lstat(path, &st) : stat(path, &st) < 0) { - if (!(flags & FTW_PHYS) && errno==ENOENT && !lstat(path, &st)) - type = FTW_SLN; - else if (errno != EACCES) return -1; - else type = FTW_NS; - } else if (S_ISDIR(st.st_mode)) { - if (flags & FTW_DEPTH) type = FTW_DP; - else type = FTW_D; - } else if (S_ISLNK(st.st_mode)) { - if (flags & FTW_PHYS) type = FTW_SL; - else type = FTW_SLN; - } else { - type = FTW_F; - } - - if ((flags & FTW_MOUNT) && h && type != FTW_NS && st.st_dev != h->dev) - return 0; - - new.chain = h; - new.dev = st.st_dev; - new.ino = st.st_ino; - new.level = h ? h->level+1 : 0; - new.base = j+1; - - lev.level = new.level; - if (h) { - lev.base = h->base; - } else { - size_t k; - for (k=j; k && path[k]=='/'; k--); - for (; k && path[k-1]!='/'; k--); - lev.base = k; - } - - if (type == FTW_D || type == FTW_DP) { - dfd = open(path, O_RDONLY); - err = errno; - if (dfd < 0 && err == EACCES) type = FTW_DNR; - if (!fd_limit) close(dfd); - } - - if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) - return r; - - for (; h; h = h->chain) - if (h->dev == st.st_dev && h->ino == st.st_ino) - return 0; - - if ((type == FTW_D || type == FTW_DP) && fd_limit) { - if (dfd < 0) { - errno = err; - return -1; - } - DIR *d = fdopendir(dfd); - if (d) { - struct dirent *de; - while ((de = readdir(d))) { - if (de->d_name[0] == '.' - && (!de->d_name[1] - || (de->d_name[1]=='.' - && !de->d_name[2]))) continue; - if (strlen(de->d_name) >= PATH_MAX-l) { - errno = ENAMETOOLONG; - closedir(d); - return -1; - } - path[j]='/'; - strcpy(path+j+1, de->d_name); - if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { - closedir(d); - return r; - } - } - closedir(d); - } else { - close(dfd); - return -1; - } - } - - path[l] = 0; - if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) - return r; - - return 0; -} - -int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) -{ - int r, cs; - size_t l; - char pathbuf[PATH_MAX+1]; - - if (fd_limit <= 0) return 0; - - l = strlen(path); - if (l > PATH_MAX) { - errno = ENAMETOOLONG; - return -1; - } - memcpy(pathbuf, path, l+1); - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); -#endif - r = do_nftw(pathbuf, fn, fd_limit, flags, NULL); -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - pthread_setcancelstate(cs, 0); -#endif - return r; -} - -weak_alias(nftw, nftw64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/prng/random.c b/lib/libc/wasi/libc-top-half/musl/src/prng/random.c deleted file mode 100644 index daac028d867c1a1e8ad2ccad37a134260818016a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/prng/random.c +++ /dev/null @@ -1,126 +0,0 @@ -#include -#include -#include "lock.h" -#include "fork_impl.h" - -/* -this code uses the same lagged fibonacci generator as the -original bsd random implementation except for the seeding -which was broken in the original -*/ - -static uint32_t init[] = { -0x00000000,0x5851f42d,0xc0b18ccf,0xcbb5f646, -0xc7033129,0x30705b04,0x20fd5db4,0x9a8b7f78, -0x502959d8,0xab894868,0x6c0356a7,0x88cdb7ff, -0xb477d43f,0x70a3a52b,0xa8e4baf1,0xfd8341fc, -0x8ae16fd9,0x742d2f7a,0x0d1f0796,0x76035e09, -0x40f7702c,0x6fa72ca5,0xaaa84157,0x58a0df74, -0xc74a0364,0xae533cc4,0x04185faf,0x6de3b115, -0x0cab8628,0xf043bfa4,0x398150e9,0x37521657}; - -static int n = 31; -static int i = 3; -static int j = 0; -static uint32_t *x = init+1; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -static volatile int lock[1]; -volatile int *const __random_lockptr = lock; -#endif - -static uint32_t lcg31(uint32_t x) { - return (1103515245*x + 12345) & 0x7fffffff; -} - -static uint64_t lcg64(uint64_t x) { - return 6364136223846793005ull*x + 1; -} - -static void *savestate() { - x[-1] = (n<<16)|(i<<8)|j; - return x-1; -} - -static void loadstate(uint32_t *state) { - x = state+1; - n = x[-1]>>16; - i = (x[-1]>>8)&0xff; - j = x[-1]&0xff; -} - -static void __srandom(unsigned seed) { - int k; - uint64_t s = seed; - - if (n == 0) { - x[0] = s; - return; - } - i = n == 31 || n == 7 ? 3 : 1; - j = 0; - for (k = 0; k < n; k++) { - s = lcg64(s); - x[k] = s>>32; - } - /* make sure x contains at least one odd number */ - x[0] |= 1; -} - -void srandom(unsigned seed) { - LOCK(lock); - __srandom(seed); - UNLOCK(lock); -} - -char *initstate(unsigned seed, char *state, size_t size) { - void *old; - - if (size < 8) - return 0; - LOCK(lock); - old = savestate(); - if (size < 32) - n = 0; - else if (size < 64) - n = 7; - else if (size < 128) - n = 15; - else if (size < 256) - n = 31; - else - n = 63; - x = (uint32_t*)state + 1; - __srandom(seed); - savestate(); - UNLOCK(lock); - return old; -} - -char *setstate(char *state) { - void *old; - - LOCK(lock); - old = savestate(); - loadstate((uint32_t*)state); - UNLOCK(lock); - return old; -} - -long random(void) { - long k; - - LOCK(lock); - if (n == 0) { - k = x[0] = lcg31(x[0]); - goto end; - } - x[i] += x[j]; - k = x[i]>>1; - if (++i == n) - i = 0; - if (++j == n) - j = 0; -end: - UNLOCK(lock); - return k; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/regex/glob.c b/lib/libc/wasi/libc-top-half/musl/src/regex/glob.c deleted file mode 100644 index 435d12e43f684335397a02d7e2299961dc88b627..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/regex/glob.c +++ /dev/null @@ -1,317 +0,0 @@ -#define _BSD_SOURCE -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // WASI has no usernames -#include -#endif - -struct match -{ - struct match *next; - char name[]; -}; - -static int append(struct match **tail, const char *name, size_t len, int mark) -{ - struct match *new = malloc(sizeof(struct match) + len + 2); - if (!new) return -1; - (*tail)->next = new; - new->next = NULL; - memcpy(new->name, name, len+1); - if (mark && len && name[len-1]!='/') { - new->name[len] = '/'; - new->name[len+1] = 0; - } - *tail = new; - return 0; -} - -static int do_glob(char *buf, size_t pos, int type, char *pat, int flags, int (*errfunc)(const char *path, int err), struct match **tail) -{ - /* If GLOB_MARK is unused, we don't care about type. */ - if (!type && !(flags & GLOB_MARK)) type = DT_REG; - - /* Special-case the remaining pattern being all slashes, in - * which case we can use caller-passed type if it's a dir. */ - if (*pat && type!=DT_DIR) type = 0; - while (pos+1 < PATH_MAX && *pat=='/') buf[pos++] = *pat++; - - /* Consume maximal [escaped-]literal prefix of pattern, copying - * and un-escaping it to the running buffer as we go. */ - ptrdiff_t i=0, j=0; - int in_bracket = 0, overflow = 0; - for (; pat[i]!='*' && pat[i]!='?' && (!in_bracket || pat[i]!=']'); i++) { - if (!pat[i]) { - if (overflow) return 0; - pat += i; - pos += j; - i = j = 0; - break; - } else if (pat[i] == '[') { - in_bracket = 1; - } else if (pat[i] == '\\' && !(flags & GLOB_NOESCAPE)) { - /* Backslashes inside a bracket are (at least by - * our interpretation) non-special, so if next - * char is ']' we have a complete expression. */ - if (in_bracket && pat[i+1]==']') break; - /* Unpaired final backslash never matches. */ - if (!pat[i+1]) return 0; - i++; - } - if (pat[i] == '/') { - if (overflow) return 0; - in_bracket = 0; - pat += i+1; - i = -1; - pos += j+1; - j = -1; - } - /* Only store a character if it fits in the buffer, but if - * a potential bracket expression is open, the overflow - * must be remembered and handled later only if the bracket - * is unterminated (and thereby a literal), so as not to - * disallow long bracket expressions with short matches. */ - if (pos+(j+1) < PATH_MAX) { - buf[pos+j++] = pat[i]; - } else if (in_bracket) { - overflow = 1; - } else { - return 0; - } - /* If we consume any new components, the caller-passed type - * or dummy type from above is no longer valid. */ - type = 0; - } - buf[pos] = 0; - if (!*pat) { - /* If we consumed any components above, or if GLOB_MARK is - * requested and we don't yet know if the match is a dir, - * we must confirm the file exists and/or determine its type. - * - * If marking dirs, symlink type is inconclusive; we need the - * type for the symlink target, and therefore must try stat - * first unless type is known not to be a symlink. Otherwise, - * or if that fails, use lstat for determining existence to - * avoid false negatives in the case of broken symlinks. */ - struct stat st; - if ((flags & GLOB_MARK) && (!type||type==DT_LNK) && !stat(buf, &st)) { - if (S_ISDIR(st.st_mode)) type = DT_DIR; - else type = DT_REG; - } - if (!type && lstat(buf, &st)) { - if (errno!=ENOENT && (errfunc(buf, errno) || (flags & GLOB_ERR))) - return GLOB_ABORTED; - return 0; - } - if (append(tail, buf, pos, (flags & GLOB_MARK) && type==DT_DIR)) - return GLOB_NOSPACE; - return 0; - } - char *p2 = strchr(pat, '/'), saved_sep = '/'; - /* Check if the '/' was escaped and, if so, remove the escape char - * so that it will not be unpaired when passed to fnmatch. */ - if (p2 && !(flags & GLOB_NOESCAPE)) { - char *p; - for (p=p2; p>pat && p[-1]=='\\'; p--); - if ((p2-p)%2) { - p2--; - saved_sep = '\\'; - } - } - DIR *dir = opendir(pos ? buf : "."); - if (!dir) { - if (errfunc(buf, errno) || (flags & GLOB_ERR)) - return GLOB_ABORTED; - return 0; - } - int old_errno = errno; - struct dirent *de; - while (errno=0, de=readdir(dir)) { - /* Quickly skip non-directories when there's pattern left. */ - if (p2 && de->d_type && de->d_type!=DT_DIR && de->d_type!=DT_LNK) - continue; - - size_t l = strlen(de->d_name); - if (l >= PATH_MAX-pos) continue; - - if (p2) *p2 = 0; - - int fnm_flags= ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) - | ((!(flags & GLOB_PERIOD)) ? FNM_PERIOD : 0); - - if (fnmatch(pat, de->d_name, fnm_flags)) - continue; - - /* With GLOB_PERIOD, don't allow matching . or .. unless - * fnmatch would match them with FNM_PERIOD rules in effect. */ - if (p2 && (flags & GLOB_PERIOD) && de->d_name[0]=='.' - && (!de->d_name[1] || de->d_name[1]=='.' && !de->d_name[2]) - && fnmatch(pat, de->d_name, fnm_flags | FNM_PERIOD)) - continue; - - memcpy(buf+pos, de->d_name, l+1); - if (p2) *p2 = saved_sep; - int r = do_glob(buf, pos+l, de->d_type, p2 ? p2 : "", flags, errfunc, tail); - if (r) { - closedir(dir); - return r; - } - } - int readerr = errno; - if (p2) *p2 = saved_sep; - closedir(dir); - if (readerr && (errfunc(buf, errno) || (flags & GLOB_ERR))) - return GLOB_ABORTED; - errno = old_errno; - return 0; -} - -static int ignore_err(const char *path, int err) -{ - return 0; -} - -static void freelist(struct match *head) -{ - struct match *match, *next; - for (match=head->next; match; match=next) { - next = match->next; - free(match); - } -} - -static int sort(const void *a, const void *b) -{ - return strcmp(*(const char **)a, *(const char **)b); -} - -#ifdef __wasilibc_unmodified_upstream // WASI has no usernames -static int expand_tilde(char **pat, char *buf, size_t *pos) -{ - char *p = *pat + 1; - size_t i = 0; - - char delim, *name_end = __strchrnul(p, '/'); - if ((delim = *name_end)) *name_end++ = 0; - *pat = name_end; - - char *home = *p ? NULL : getenv("HOME"); - if (!home) { - struct passwd pw, *res; - switch (*p ? getpwnam_r(p, &pw, buf, PATH_MAX, &res) - : getpwuid_r(getuid(), &pw, buf, PATH_MAX, &res)) { - case ENOMEM: - return GLOB_NOSPACE; - case 0: - if (!res) - default: - return GLOB_NOMATCH; - } - home = pw.pw_dir; - } - while (i < PATH_MAX - 2 && *home) - buf[i++] = *home++; - if (*home) - return GLOB_NOMATCH; - if ((buf[i] = delim)) - buf[++i] = 0; - *pos = i; - return 0; -} -#endif - -int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *restrict g) -{ - struct match head = { .next = NULL }, *tail = &head; - size_t cnt, i; - size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; - int error = 0; - char buf[PATH_MAX]; - - if (!errfunc) errfunc = ignore_err; - - if (!(flags & GLOB_APPEND)) { - g->gl_offs = offs; - g->gl_pathc = 0; - g->gl_pathv = NULL; - } - - if (*pat) { - char *p = strdup(pat); - if (!p) return GLOB_NOSPACE; - buf[0] = 0; - size_t pos = 0; - char *s = p; -#ifdef __wasilibc_unmodified_upstream // WASI has no usernames - if ((flags & (GLOB_TILDE | GLOB_TILDE_CHECK)) && *p == '~') - error = expand_tilde(&s, buf, &pos); -#endif - if (!error) - error = do_glob(buf, pos, 0, s, flags, errfunc, &tail); - free(p); - } - - if (error == GLOB_NOSPACE) { - freelist(&head); - return error; - } - - for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++); - if (!cnt) { - if (flags & GLOB_NOCHECK) { - tail = &head; - if (append(&tail, pat, strlen(pat), 0)) - return GLOB_NOSPACE; - cnt++; - } else if (!error) - return GLOB_NOMATCH; - } - - if (flags & GLOB_APPEND) { - char **pathv = realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(char *)); - if (!pathv) { - freelist(&head); - return GLOB_NOSPACE; - } - g->gl_pathv = pathv; - offs += g->gl_pathc; - } else { - g->gl_pathv = malloc((offs + cnt + 1) * sizeof(char *)); - if (!g->gl_pathv) { - freelist(&head); - return GLOB_NOSPACE; - } - for (i=0; igl_pathv[i] = NULL; - } - for (i=0, tail=head.next; inext, i++) - g->gl_pathv[offs + i] = tail->name; - g->gl_pathv[offs + i] = NULL; - g->gl_pathc += cnt; - - if (!(flags & GLOB_NOSORT)) - qsort(g->gl_pathv+offs, cnt, sizeof(char *), sort); - - return error; -} - -void globfree(glob_t *g) -{ - size_t i; - for (i=0; igl_pathc; i++) - free(g->gl_pathv[g->gl_offs + i] - offsetof(struct match, name)); - free(g->gl_pathv); - g->gl_pathc = 0; - g->gl_pathv = NULL; -} - -weak_alias(glob, glob64); -weak_alias(globfree, globfree64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/regex/regcomp.c b/lib/libc/wasi/libc-top-half/musl/src/regex/regcomp.c deleted file mode 100644 index fb24556ebe12e33cd07d86a7953e2ce30f45c3b7..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/regex/regcomp.c +++ /dev/null @@ -1,2953 +0,0 @@ -/* - regcomp.c - TRE POSIX compatible regex compilation functions. - - Copyright (c) 2001-2009 Ville Laurikari - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include -#include -#include -#include -#include -#include - -#include "tre.h" - -#include - -/*********************************************************************** - from tre-compile.h -***********************************************************************/ - -typedef struct { - int position; - int code_min; - int code_max; - int *tags; - int assertions; - tre_ctype_t class; - tre_ctype_t *neg_classes; - int backref; -} tre_pos_and_tags_t; - - -/*********************************************************************** - from tre-ast.c and tre-ast.h -***********************************************************************/ - -/* The different AST node types. */ -typedef enum { - LITERAL, - CATENATION, - ITERATION, - UNION -} tre_ast_type_t; - -/* Special subtypes of TRE_LITERAL. */ -#define EMPTY -1 /* Empty leaf (denotes empty string). */ -#define ASSERTION -2 /* Assertion leaf. */ -#define TAG -3 /* Tag leaf. */ -#define BACKREF -4 /* Back reference leaf. */ - -#define IS_SPECIAL(x) ((x)->code_min < 0) -#define IS_EMPTY(x) ((x)->code_min == EMPTY) -#define IS_ASSERTION(x) ((x)->code_min == ASSERTION) -#define IS_TAG(x) ((x)->code_min == TAG) -#define IS_BACKREF(x) ((x)->code_min == BACKREF) - - -/* A generic AST node. All AST nodes consist of this node on the top - level with `obj' pointing to the actual content. */ -typedef struct { - tre_ast_type_t type; /* Type of the node. */ - void *obj; /* Pointer to actual node. */ - int nullable; - int submatch_id; - int num_submatches; - int num_tags; - tre_pos_and_tags_t *firstpos; - tre_pos_and_tags_t *lastpos; -} tre_ast_node_t; - - -/* A "literal" node. These are created for assertions, back references, - tags, matching parameter settings, and all expressions that match one - character. */ -typedef struct { - long code_min; - long code_max; - int position; - tre_ctype_t class; - tre_ctype_t *neg_classes; -} tre_literal_t; - -/* A "catenation" node. These are created when two regexps are concatenated. - If there are more than one subexpressions in sequence, the `left' part - holds all but the last, and `right' part holds the last subexpression - (catenation is left associative). */ -typedef struct { - tre_ast_node_t *left; - tre_ast_node_t *right; -} tre_catenation_t; - -/* An "iteration" node. These are created for the "*", "+", "?", and "{m,n}" - operators. */ -typedef struct { - /* Subexpression to match. */ - tre_ast_node_t *arg; - /* Minimum number of consecutive matches. */ - int min; - /* Maximum number of consecutive matches. */ - int max; - /* If 0, match as many characters as possible, if 1 match as few as - possible. Note that this does not always mean the same thing as - matching as many/few repetitions as possible. */ - unsigned int minimal:1; -} tre_iteration_t; - -/* An "union" node. These are created for the "|" operator. */ -typedef struct { - tre_ast_node_t *left; - tre_ast_node_t *right; -} tre_union_t; - - -static tre_ast_node_t * -tre_ast_new_node(tre_mem_t mem, int type, void *obj) -{ - tre_ast_node_t *node = tre_mem_calloc(mem, sizeof *node); - if (!node || !obj) - return 0; - node->obj = obj; - node->type = type; - node->nullable = -1; - node->submatch_id = -1; - return node; -} - -static tre_ast_node_t * -tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position) -{ - tre_ast_node_t *node; - tre_literal_t *lit; - - lit = tre_mem_calloc(mem, sizeof *lit); - node = tre_ast_new_node(mem, LITERAL, lit); - if (!node) - return 0; - lit->code_min = code_min; - lit->code_max = code_max; - lit->position = position; - return node; -} - -static tre_ast_node_t * -tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max, int minimal) -{ - tre_ast_node_t *node; - tre_iteration_t *iter; - - iter = tre_mem_calloc(mem, sizeof *iter); - node = tre_ast_new_node(mem, ITERATION, iter); - if (!node) - return 0; - iter->arg = arg; - iter->min = min; - iter->max = max; - iter->minimal = minimal; - node->num_submatches = arg->num_submatches; - return node; -} - -static tre_ast_node_t * -tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right) -{ - tre_ast_node_t *node; - tre_union_t *un; - - if (!left) - return right; - un = tre_mem_calloc(mem, sizeof *un); - node = tre_ast_new_node(mem, UNION, un); - if (!node || !right) - return 0; - un->left = left; - un->right = right; - node->num_submatches = left->num_submatches + right->num_submatches; - return node; -} - -static tre_ast_node_t * -tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right) -{ - tre_ast_node_t *node; - tre_catenation_t *cat; - - if (!left) - return right; - cat = tre_mem_calloc(mem, sizeof *cat); - node = tre_ast_new_node(mem, CATENATION, cat); - if (!node) - return 0; - cat->left = left; - cat->right = right; - node->num_submatches = left->num_submatches + right->num_submatches; - return node; -} - - -/*********************************************************************** - from tre-stack.c and tre-stack.h -***********************************************************************/ - -typedef struct tre_stack_rec tre_stack_t; - -/* Creates a new stack object. `size' is initial size in bytes, `max_size' - is maximum size, and `increment' specifies how much more space will be - allocated with realloc() if all space gets used up. Returns the stack - object or NULL if out of memory. */ -static tre_stack_t * -tre_stack_new(int size, int max_size, int increment); - -/* Frees the stack object. */ -static void -tre_stack_destroy(tre_stack_t *s); - -/* Returns the current number of objects in the stack. */ -static int -tre_stack_num_objects(tre_stack_t *s); - -/* Each tre_stack_push_*(tre_stack_t *s, value) function pushes - `value' on top of stack `s'. Returns REG_ESPACE if out of memory. - This tries to realloc() more space before failing if maximum size - has not yet been reached. Returns REG_OK if successful. */ -#define declare_pushf(typetag, type) \ - static reg_errcode_t tre_stack_push_ ## typetag(tre_stack_t *s, type value) - -declare_pushf(voidptr, void *); -declare_pushf(int, int); - -/* Each tre_stack_pop_*(tre_stack_t *s) function pops the topmost - element off of stack `s' and returns it. The stack must not be - empty. */ -#define declare_popf(typetag, type) \ - static type tre_stack_pop_ ## typetag(tre_stack_t *s) - -declare_popf(voidptr, void *); -declare_popf(int, int); - -/* Just to save some typing. */ -#define STACK_PUSH(s, typetag, value) \ - do \ - { \ - status = tre_stack_push_ ## typetag(s, value); \ - } \ - while (/*CONSTCOND*/0) - -#define STACK_PUSHX(s, typetag, value) \ - { \ - status = tre_stack_push_ ## typetag(s, value); \ - if (status != REG_OK) \ - break; \ - } - -#define STACK_PUSHR(s, typetag, value) \ - { \ - reg_errcode_t _status; \ - _status = tre_stack_push_ ## typetag(s, value); \ - if (_status != REG_OK) \ - return _status; \ - } - -union tre_stack_item { - void *voidptr_value; - int int_value; -}; - -struct tre_stack_rec { - int size; - int max_size; - int increment; - int ptr; - union tre_stack_item *stack; -}; - - -static tre_stack_t * -tre_stack_new(int size, int max_size, int increment) -{ - tre_stack_t *s; - - s = xmalloc(sizeof(*s)); - if (s != NULL) - { - s->stack = xmalloc(sizeof(*s->stack) * size); - if (s->stack == NULL) - { - xfree(s); - return NULL; - } - s->size = size; - s->max_size = max_size; - s->increment = increment; - s->ptr = 0; - } - return s; -} - -static void -tre_stack_destroy(tre_stack_t *s) -{ - xfree(s->stack); - xfree(s); -} - -static int -tre_stack_num_objects(tre_stack_t *s) -{ - return s->ptr; -} - -static reg_errcode_t -tre_stack_push(tre_stack_t *s, union tre_stack_item value) -{ - if (s->ptr < s->size) - { - s->stack[s->ptr] = value; - s->ptr++; - } - else - { - if (s->size >= s->max_size) - { - return REG_ESPACE; - } - else - { - union tre_stack_item *new_buffer; - int new_size; - new_size = s->size + s->increment; - if (new_size > s->max_size) - new_size = s->max_size; - new_buffer = xrealloc(s->stack, sizeof(*new_buffer) * new_size); - if (new_buffer == NULL) - { - return REG_ESPACE; - } - assert(new_size > s->size); - s->size = new_size; - s->stack = new_buffer; - tre_stack_push(s, value); - } - } - return REG_OK; -} - -#define define_pushf(typetag, type) \ - declare_pushf(typetag, type) { \ - union tre_stack_item item; \ - item.typetag ## _value = value; \ - return tre_stack_push(s, item); \ -} - -define_pushf(int, int) -define_pushf(voidptr, void *) - -#define define_popf(typetag, type) \ - declare_popf(typetag, type) { \ - return s->stack[--s->ptr].typetag ## _value; \ - } - -define_popf(int, int) -define_popf(voidptr, void *) - - -/*********************************************************************** - from tre-parse.c and tre-parse.h -***********************************************************************/ - -/* Parse context. */ -typedef struct { - /* Memory allocator. The AST is allocated using this. */ - tre_mem_t mem; - /* Stack used for keeping track of regexp syntax. */ - tre_stack_t *stack; - /* The parsed node after a parse function returns. */ - tre_ast_node_t *n; - /* Position in the regexp pattern after a parse function returns. */ - const char *s; - /* The first character of the last subexpression parsed. */ - const char *start; - /* Current submatch ID. */ - int submatch_id; - /* Current position (number of literal). */ - int position; - /* The highest back reference or -1 if none seen so far. */ - int max_backref; - /* Compilation flags. */ - int cflags; -} tre_parse_ctx_t; - -/* Some macros for expanding \w, \s, etc. */ -static const struct { - char c; - const char *expansion; -} tre_macros[] = { - {'t', "\t"}, {'n', "\n"}, {'r', "\r"}, - {'f', "\f"}, {'a', "\a"}, {'e', "\033"}, - {'w', "[[:alnum:]_]"}, {'W', "[^[:alnum:]_]"}, {'s', "[[:space:]]"}, - {'S', "[^[:space:]]"}, {'d', "[[:digit:]]"}, {'D', "[^[:digit:]]"}, - { 0, 0 } -}; - -/* Expands a macro delimited by `regex' and `regex_end' to `buf', which - must have at least `len' items. Sets buf[0] to zero if the there - is no match in `tre_macros'. */ -static const char *tre_expand_macro(const char *s) -{ - int i; - for (i = 0; tre_macros[i].c && tre_macros[i].c != *s; i++); - return tre_macros[i].expansion; -} - -static int -tre_compare_lit(const void *a, const void *b) -{ - const tre_literal_t *const *la = a; - const tre_literal_t *const *lb = b; - /* assumes the range of valid code_min is < INT_MAX */ - return la[0]->code_min - lb[0]->code_min; -} - -struct literals { - tre_mem_t mem; - tre_literal_t **a; - int len; - int cap; -}; - -static tre_literal_t *tre_new_lit(struct literals *p) -{ - tre_literal_t **a; - if (p->len >= p->cap) { - if (p->cap >= 1<<15) - return 0; - p->cap *= 2; - a = xrealloc(p->a, p->cap * sizeof *p->a); - if (!a) - return 0; - p->a = a; - } - a = p->a + p->len++; - *a = tre_mem_calloc(p->mem, sizeof **a); - return *a; -} - -static int add_icase_literals(struct literals *ls, int min, int max) -{ - tre_literal_t *lit; - int b, e, c; - for (c=min; c<=max; ) { - /* assumes islower(c) and isupper(c) are exclusive - and toupper(c)!=c if islower(c). - multiple opposite case characters are not supported */ - if (tre_islower(c)) { - b = e = tre_toupper(c); - for (c++, e++; c<=max; c++, e++) - if (tre_toupper(c) != e) break; - } else if (tre_isupper(c)) { - b = e = tre_tolower(c); - for (c++, e++; c<=max; c++, e++) - if (tre_tolower(c) != e) break; - } else { - c++; - continue; - } - lit = tre_new_lit(ls); - if (!lit) - return -1; - lit->code_min = b; - lit->code_max = e-1; - lit->position = -1; - } - return 0; -} - - -/* Maximum number of character classes in a negated bracket expression. */ -#define MAX_NEG_CLASSES 64 - -struct neg { - int negate; - int len; - tre_ctype_t a[MAX_NEG_CLASSES]; -}; - -// TODO: parse bracket into a set of non-overlapping [lo,hi] ranges - -/* -bracket grammar: -Bracket = '[' List ']' | '[^' List ']' -List = Term | List Term -Term = Char | Range | Chclass | Eqclass -Range = Char '-' Char | Char '-' '-' -Char = Coll | coll_single -Meta = ']' | '-' -Coll = '[.' coll_single '.]' | '[.' coll_multi '.]' | '[.' Meta '.]' -Eqclass = '[=' coll_single '=]' | '[=' coll_multi '=]' -Chclass = '[:' class ':]' - -coll_single is a single char collating element but it can be - '-' only at the beginning or end of a List and - ']' only at the beginning of a List and - '^' anywhere except after the openning '[' -*/ - -static reg_errcode_t parse_bracket_terms(tre_parse_ctx_t *ctx, const char *s, struct literals *ls, struct neg *neg) -{ - const char *start = s; - tre_ctype_t class; - int min, max; - wchar_t wc; - int len; - - for (;;) { - class = 0; - len = mbtowc(&wc, s, -1); - if (len <= 0) - return *s ? REG_BADPAT : REG_EBRACK; - if (*s == ']' && s != start) { - ctx->s = s+1; - return REG_OK; - } - if (*s == '-' && s != start && s[1] != ']' && - /* extension: [a-z--@] is accepted as [a-z]|[--@] */ - (s[1] != '-' || s[2] == ']')) - return REG_ERANGE; - if (*s == '[' && (s[1] == '.' || s[1] == '=')) - /* collating symbols and equivalence classes are not supported */ - return REG_ECOLLATE; - if (*s == '[' && s[1] == ':') { - char tmp[CHARCLASS_NAME_MAX+1]; - s += 2; - for (len=0; len < CHARCLASS_NAME_MAX && s[len]; len++) { - if (s[len] == ':') { - memcpy(tmp, s, len); - tmp[len] = 0; - class = tre_ctype(tmp); - break; - } - } - if (!class || s[len+1] != ']') - return REG_ECTYPE; - min = 0; - max = TRE_CHAR_MAX; - s += len+2; - } else { - min = max = wc; - s += len; - if (*s == '-' && s[1] != ']') { - s++; - len = mbtowc(&wc, s, -1); - max = wc; - /* XXX - Should use collation order instead of - encoding values in character ranges. */ - if (len <= 0 || min > max) - return REG_ERANGE; - s += len; - } - } - - if (class && neg->negate) { - if (neg->len >= MAX_NEG_CLASSES) - return REG_ESPACE; - neg->a[neg->len++] = class; - } else { - tre_literal_t *lit = tre_new_lit(ls); - if (!lit) - return REG_ESPACE; - lit->code_min = min; - lit->code_max = max; - lit->class = class; - lit->position = -1; - - /* Add opposite-case codepoints if REG_ICASE is present. - It seems that POSIX requires that bracket negation - should happen before case-folding, but most practical - implementations do it the other way around. Changing - the order would need efficient representation of - case-fold ranges and bracket range sets even with - simple patterns so this is ok for now. */ - if (ctx->cflags & REG_ICASE && !class) - if (add_icase_literals(ls, min, max)) - return REG_ESPACE; - } - } -} - -static reg_errcode_t parse_bracket(tre_parse_ctx_t *ctx, const char *s) -{ - int i, max, min, negmax, negmin; - tre_ast_node_t *node = 0, *n; - tre_ctype_t *nc = 0; - tre_literal_t *lit; - struct literals ls; - struct neg neg; - reg_errcode_t err; - - ls.mem = ctx->mem; - ls.len = 0; - ls.cap = 32; - ls.a = xmalloc(ls.cap * sizeof *ls.a); - if (!ls.a) - return REG_ESPACE; - neg.len = 0; - neg.negate = *s == '^'; - if (neg.negate) - s++; - - err = parse_bracket_terms(ctx, s, &ls, &neg); - if (err != REG_OK) - goto parse_bracket_done; - - if (neg.negate) { - /* - * With REG_NEWLINE, POSIX requires that newlines are not matched by - * any form of a non-matching list. - */ - if (ctx->cflags & REG_NEWLINE) { - lit = tre_new_lit(&ls); - if (!lit) { - err = REG_ESPACE; - goto parse_bracket_done; - } - lit->code_min = '\n'; - lit->code_max = '\n'; - lit->position = -1; - } - /* Sort the array if we need to negate it. */ - qsort(ls.a, ls.len, sizeof *ls.a, tre_compare_lit); - /* extra lit for the last negated range */ - lit = tre_new_lit(&ls); - if (!lit) { - err = REG_ESPACE; - goto parse_bracket_done; - } - lit->code_min = TRE_CHAR_MAX+1; - lit->code_max = TRE_CHAR_MAX+1; - lit->position = -1; - /* negated classes */ - if (neg.len) { - nc = tre_mem_alloc(ctx->mem, (neg.len+1)*sizeof *neg.a); - if (!nc) { - err = REG_ESPACE; - goto parse_bracket_done; - } - memcpy(nc, neg.a, neg.len*sizeof *neg.a); - nc[neg.len] = 0; - } - } - - /* Build a union of the items in the array, negated if necessary. */ - negmax = negmin = 0; - for (i = 0; i < ls.len; i++) { - lit = ls.a[i]; - min = lit->code_min; - max = lit->code_max; - if (neg.negate) { - if (min <= negmin) { - /* Overlap. */ - negmin = MAX(max + 1, negmin); - continue; - } - negmax = min - 1; - lit->code_min = negmin; - lit->code_max = negmax; - negmin = max + 1; - } - lit->position = ctx->position; - lit->neg_classes = nc; - n = tre_ast_new_node(ctx->mem, LITERAL, lit); - node = tre_ast_new_union(ctx->mem, node, n); - if (!node) { - err = REG_ESPACE; - break; - } - } - -parse_bracket_done: - xfree(ls.a); - ctx->position++; - ctx->n = node; - return err; -} - -static const char *parse_dup_count(const char *s, int *n) -{ - *n = -1; - if (!isdigit(*s)) - return s; - *n = 0; - for (;;) { - *n = 10 * *n + (*s - '0'); - s++; - if (!isdigit(*s) || *n > RE_DUP_MAX) - break; - } - return s; -} - -static const char *parse_dup(const char *s, int ere, int *pmin, int *pmax) -{ - int min, max; - - s = parse_dup_count(s, &min); - if (*s == ',') - s = parse_dup_count(s+1, &max); - else - max = min; - - if ( - (max < min && max >= 0) || - max > RE_DUP_MAX || - min > RE_DUP_MAX || - min < 0 || - (!ere && *s++ != '\\') || - *s++ != '}' - ) - return 0; - *pmin = min; - *pmax = max; - return s; -} - -static int hexval(unsigned c) -{ - if (c-'0'<10) return c-'0'; - c |= 32; - if (c-'a'<6) return c-'a'+10; - return -1; -} - -static reg_errcode_t marksub(tre_parse_ctx_t *ctx, tre_ast_node_t *node, int subid) -{ - if (node->submatch_id >= 0) { - tre_ast_node_t *n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - if (!n) - return REG_ESPACE; - n = tre_ast_new_catenation(ctx->mem, n, node); - if (!n) - return REG_ESPACE; - n->num_submatches = node->num_submatches; - node = n; - } - node->submatch_id = subid; - node->num_submatches++; - ctx->n = node; - return REG_OK; -} - -/* -BRE grammar: -Regex = Branch | '^' | '$' | '^$' | '^' Branch | Branch '$' | '^' Branch '$' -Branch = Atom | Branch Atom -Atom = char | quoted_char | '.' | Bracket | Atom Dup | '\(' Branch '\)' | back_ref -Dup = '*' | '\{' Count '\}' | '\{' Count ',\}' | '\{' Count ',' Count '\}' - -(leading ^ and trailing $ in a sub expr may be an anchor or literal as well) - -ERE grammar: -Regex = Branch | Regex '|' Branch -Branch = Atom | Branch Atom -Atom = char | quoted_char | '.' | Bracket | Atom Dup | '(' Regex ')' | '^' | '$' -Dup = '*' | '+' | '?' | '{' Count '}' | '{' Count ',}' | '{' Count ',' Count '}' - -(a*+?, ^*, $+, \X, {, (|a) are unspecified) -*/ - -static reg_errcode_t parse_atom(tre_parse_ctx_t *ctx, const char *s) -{ - int len, ere = ctx->cflags & REG_EXTENDED; - const char *p; - tre_ast_node_t *node; - wchar_t wc; - switch (*s) { - case '[': - return parse_bracket(ctx, s+1); - case '\\': - p = tre_expand_macro(s+1); - if (p) { - /* assume \X expansion is a single atom */ - reg_errcode_t err = parse_atom(ctx, p); - ctx->s = s+2; - return err; - } - /* extensions: \b, \B, \<, \>, \xHH \x{HHHH} */ - switch (*++s) { - case 0: - return REG_EESCAPE; - case 'b': - node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_WB, -1); - break; - case 'B': - node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_WB_NEG, -1); - break; - case '<': - node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_BOW, -1); - break; - case '>': - node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_EOW, -1); - break; - case 'x': - s++; - int i, v = 0, c; - len = 2; - if (*s == '{') { - len = 8; - s++; - } - for (i=0; imem, v, v, ctx->position++); - s--; - break; - case '{': - case '+': - case '?': - /* extension: treat \+, \? as repetitions in BRE */ - /* reject repetitions after empty expression in BRE */ - if (!ere) - return REG_BADRPT; - case '|': - /* extension: treat \| as alternation in BRE */ - if (!ere) { - node = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - s--; - goto end; - } - /* fallthrough */ - default: - if (!ere && (unsigned)*s-'1' < 9) { - /* back reference */ - int val = *s - '0'; - node = tre_ast_new_literal(ctx->mem, BACKREF, val, ctx->position++); - ctx->max_backref = MAX(val, ctx->max_backref); - } else { - /* extension: accept unknown escaped char - as a literal */ - goto parse_literal; - } - } - s++; - break; - case '.': - if (ctx->cflags & REG_NEWLINE) { - tre_ast_node_t *tmp1, *tmp2; - tmp1 = tre_ast_new_literal(ctx->mem, 0, '\n'-1, ctx->position++); - tmp2 = tre_ast_new_literal(ctx->mem, '\n'+1, TRE_CHAR_MAX, ctx->position++); - if (tmp1 && tmp2) - node = tre_ast_new_union(ctx->mem, tmp1, tmp2); - else - node = 0; - } else { - node = tre_ast_new_literal(ctx->mem, 0, TRE_CHAR_MAX, ctx->position++); - } - s++; - break; - case '^': - /* '^' has a special meaning everywhere in EREs, and at beginning of BRE. */ - if (!ere && s != ctx->start) - goto parse_literal; - node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_BOL, -1); - s++; - break; - case '$': - /* '$' is special everywhere in EREs, and at the end of a BRE subexpression. */ - if (!ere && s[1] && (s[1]!='\\'|| (s[2]!=')' && s[2]!='|'))) - goto parse_literal; - node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_EOL, -1); - s++; - break; - case '*': - case '{': - case '+': - case '?': - /* reject repetitions after empty expression in ERE */ - if (ere) - return REG_BADRPT; - case '|': - if (!ere) - goto parse_literal; - case 0: - node = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - break; - default: -parse_literal: - len = mbtowc(&wc, s, -1); - if (len < 0) - return REG_BADPAT; - if (ctx->cflags & REG_ICASE && (tre_isupper(wc) || tre_islower(wc))) { - tre_ast_node_t *tmp1, *tmp2; - /* multiple opposite case characters are not supported */ - tmp1 = tre_ast_new_literal(ctx->mem, tre_toupper(wc), tre_toupper(wc), ctx->position); - tmp2 = tre_ast_new_literal(ctx->mem, tre_tolower(wc), tre_tolower(wc), ctx->position); - if (tmp1 && tmp2) - node = tre_ast_new_union(ctx->mem, tmp1, tmp2); - else - node = 0; - } else { - node = tre_ast_new_literal(ctx->mem, wc, wc, ctx->position); - } - ctx->position++; - s += len; - break; - } -end: - if (!node) - return REG_ESPACE; - ctx->n = node; - ctx->s = s; - return REG_OK; -} - -#define PUSHPTR(err, s, v) do { \ - if ((err = tre_stack_push_voidptr(s, v)) != REG_OK) \ - return err; \ -} while(0) - -#define PUSHINT(err, s, v) do { \ - if ((err = tre_stack_push_int(s, v)) != REG_OK) \ - return err; \ -} while(0) - -static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) -{ - tre_ast_node_t *nbranch=0, *nunion=0; - int ere = ctx->cflags & REG_EXTENDED; - const char *s = ctx->start; - int subid = 0; - int depth = 0; - reg_errcode_t err; - tre_stack_t *stack = ctx->stack; - - PUSHINT(err, stack, subid++); - for (;;) { - if ((!ere && *s == '\\' && s[1] == '(') || - (ere && *s == '(')) { - PUSHPTR(err, stack, nunion); - PUSHPTR(err, stack, nbranch); - PUSHINT(err, stack, subid++); - s++; - if (!ere) - s++; - depth++; - nbranch = nunion = 0; - ctx->start = s; - continue; - } - if ((!ere && *s == '\\' && s[1] == ')') || - (ere && *s == ')' && depth)) { - ctx->n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - if (!ctx->n) - return REG_ESPACE; - } else { - err = parse_atom(ctx, s); - if (err != REG_OK) - return err; - s = ctx->s; - } - - parse_iter: - for (;;) { - int min, max; - - if (*s!='\\' && *s!='*') { - if (!ere) - break; - if (*s!='+' && *s!='?' && *s!='{') - break; - } - if (*s=='\\' && ere) - break; - /* extension: treat \+, \? as repetitions in BRE */ - if (*s=='\\' && s[1]!='+' && s[1]!='?' && s[1]!='{') - break; - if (*s=='\\') - s++; - - /* handle ^* at the start of a BRE. */ - if (!ere && s==ctx->start+1 && s[-1]=='^') - break; - - /* extension: multiple consecutive *+?{,} is unspecified, - but (a+)+ has to be supported so accepting a++ makes - sense, note however that the RE_DUP_MAX limit can be - circumvented: (a{255}){255} uses a lot of memory.. */ - if (*s=='{') { - s = parse_dup(s+1, ere, &min, &max); - if (!s) - return REG_BADBR; - } else { - min=0; - max=-1; - if (*s == '+') - min = 1; - if (*s == '?') - max = 1; - s++; - } - if (max == 0) - ctx->n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); - else - ctx->n = tre_ast_new_iter(ctx->mem, ctx->n, min, max, 0); - if (!ctx->n) - return REG_ESPACE; - } - - nbranch = tre_ast_new_catenation(ctx->mem, nbranch, ctx->n); - if ((ere && *s == '|') || - (ere && *s == ')' && depth) || - (!ere && *s == '\\' && s[1] == ')') || - /* extension: treat \| as alternation in BRE */ - (!ere && *s == '\\' && s[1] == '|') || - !*s) { - /* extension: empty branch is unspecified (), (|a), (a|) - here they are not rejected but match on empty string */ - int c = *s; - nunion = tre_ast_new_union(ctx->mem, nunion, nbranch); - nbranch = 0; - - if (c == '\\' && s[1] == '|') { - s+=2; - ctx->start = s; - } else if (c == '|') { - s++; - ctx->start = s; - } else { - if (c == '\\') { - if (!depth) return REG_EPAREN; - s+=2; - } else if (c == ')') - s++; - depth--; - err = marksub(ctx, nunion, tre_stack_pop_int(stack)); - if (err != REG_OK) - return err; - if (!c && depth<0) { - ctx->submatch_id = subid; - return REG_OK; - } - if (!c || depth<0) - return REG_EPAREN; - nbranch = tre_stack_pop_voidptr(stack); - nunion = tre_stack_pop_voidptr(stack); - goto parse_iter; - } - } - } -} - - -/*********************************************************************** - from tre-compile.c -***********************************************************************/ - - -/* - TODO: - - Fix tre_ast_to_tnfa() to recurse using a stack instead of recursive - function calls. -*/ - -/* - Algorithms to setup tags so that submatch addressing can be done. -*/ - - -/* Inserts a catenation node to the root of the tree given in `node'. - As the left child a new tag with number `tag_id' to `node' is added, - and the right child is the old root. */ -static reg_errcode_t -tre_add_tag_left(tre_mem_t mem, tre_ast_node_t *node, int tag_id) -{ - tre_catenation_t *c; - - c = tre_mem_alloc(mem, sizeof(*c)); - if (c == NULL) - return REG_ESPACE; - c->left = tre_ast_new_literal(mem, TAG, tag_id, -1); - if (c->left == NULL) - return REG_ESPACE; - c->right = tre_mem_alloc(mem, sizeof(tre_ast_node_t)); - if (c->right == NULL) - return REG_ESPACE; - - c->right->obj = node->obj; - c->right->type = node->type; - c->right->nullable = -1; - c->right->submatch_id = -1; - c->right->firstpos = NULL; - c->right->lastpos = NULL; - c->right->num_tags = 0; - c->right->num_submatches = 0; - node->obj = c; - node->type = CATENATION; - return REG_OK; -} - -/* Inserts a catenation node to the root of the tree given in `node'. - As the right child a new tag with number `tag_id' to `node' is added, - and the left child is the old root. */ -static reg_errcode_t -tre_add_tag_right(tre_mem_t mem, tre_ast_node_t *node, int tag_id) -{ - tre_catenation_t *c; - - c = tre_mem_alloc(mem, sizeof(*c)); - if (c == NULL) - return REG_ESPACE; - c->right = tre_ast_new_literal(mem, TAG, tag_id, -1); - if (c->right == NULL) - return REG_ESPACE; - c->left = tre_mem_alloc(mem, sizeof(tre_ast_node_t)); - if (c->left == NULL) - return REG_ESPACE; - - c->left->obj = node->obj; - c->left->type = node->type; - c->left->nullable = -1; - c->left->submatch_id = -1; - c->left->firstpos = NULL; - c->left->lastpos = NULL; - c->left->num_tags = 0; - c->left->num_submatches = 0; - node->obj = c; - node->type = CATENATION; - return REG_OK; -} - -typedef enum { - ADDTAGS_RECURSE, - ADDTAGS_AFTER_ITERATION, - ADDTAGS_AFTER_UNION_LEFT, - ADDTAGS_AFTER_UNION_RIGHT, - ADDTAGS_AFTER_CAT_LEFT, - ADDTAGS_AFTER_CAT_RIGHT, - ADDTAGS_SET_SUBMATCH_END -} tre_addtags_symbol_t; - - -typedef struct { - int tag; - int next_tag; -} tre_tag_states_t; - - -/* Go through `regset' and set submatch data for submatches that are - using this tag. */ -static void -tre_purge_regset(int *regset, tre_tnfa_t *tnfa, int tag) -{ - int i; - - for (i = 0; regset[i] >= 0; i++) - { - int id = regset[i] / 2; - int start = !(regset[i] % 2); - if (start) - tnfa->submatch_data[id].so_tag = tag; - else - tnfa->submatch_data[id].eo_tag = tag; - } - regset[0] = -1; -} - - -/* Adds tags to appropriate locations in the parse tree in `tree', so that - subexpressions marked for submatch addressing can be traced. */ -static reg_errcode_t -tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, - tre_tnfa_t *tnfa) -{ - reg_errcode_t status = REG_OK; - tre_addtags_symbol_t symbol; - tre_ast_node_t *node = tree; /* Tree node we are currently looking at. */ - int bottom = tre_stack_num_objects(stack); - /* True for first pass (counting number of needed tags) */ - int first_pass = (mem == NULL || tnfa == NULL); - int *regset, *orig_regset; - int num_tags = 0; /* Total number of tags. */ - int num_minimals = 0; /* Number of special minimal tags. */ - int tag = 0; /* The tag that is to be added next. */ - int next_tag = 1; /* Next tag to use after this one. */ - int *parents; /* Stack of submatches the current submatch is - contained in. */ - int minimal_tag = -1; /* Tag that marks the beginning of a minimal match. */ - tre_tag_states_t *saved_states; - - tre_tag_direction_t direction = TRE_TAG_MINIMIZE; - if (!first_pass) - { - tnfa->end_tag = 0; - tnfa->minimal_tags[0] = -1; - } - - regset = xmalloc(sizeof(*regset) * ((tnfa->num_submatches + 1) * 2)); - if (regset == NULL) - return REG_ESPACE; - regset[0] = -1; - orig_regset = regset; - - parents = xmalloc(sizeof(*parents) * (tnfa->num_submatches + 1)); - if (parents == NULL) - { - xfree(regset); - return REG_ESPACE; - } - parents[0] = -1; - - saved_states = xmalloc(sizeof(*saved_states) * (tnfa->num_submatches + 1)); - if (saved_states == NULL) - { - xfree(regset); - xfree(parents); - return REG_ESPACE; - } - else - { - unsigned int i; - for (i = 0; i <= tnfa->num_submatches; i++) - saved_states[i].tag = -1; - } - - STACK_PUSH(stack, voidptr, node); - STACK_PUSH(stack, int, ADDTAGS_RECURSE); - - while (tre_stack_num_objects(stack) > bottom) - { - if (status != REG_OK) - break; - - symbol = (tre_addtags_symbol_t)tre_stack_pop_int(stack); - switch (symbol) - { - - case ADDTAGS_SET_SUBMATCH_END: - { - int id = tre_stack_pop_int(stack); - int i; - - /* Add end of this submatch to regset. */ - for (i = 0; regset[i] >= 0; i++); - regset[i] = id * 2 + 1; - regset[i + 1] = -1; - - /* Pop this submatch from the parents stack. */ - for (i = 0; parents[i] >= 0; i++); - parents[i - 1] = -1; - break; - } - - case ADDTAGS_RECURSE: - node = tre_stack_pop_voidptr(stack); - - if (node->submatch_id >= 0) - { - int id = node->submatch_id; - int i; - - - /* Add start of this submatch to regset. */ - for (i = 0; regset[i] >= 0; i++); - regset[i] = id * 2; - regset[i + 1] = -1; - - if (!first_pass) - { - for (i = 0; parents[i] >= 0; i++); - tnfa->submatch_data[id].parents = NULL; - if (i > 0) - { - int *p = xmalloc(sizeof(*p) * (i + 1)); - if (p == NULL) - { - status = REG_ESPACE; - break; - } - assert(tnfa->submatch_data[id].parents == NULL); - tnfa->submatch_data[id].parents = p; - for (i = 0; parents[i] >= 0; i++) - p[i] = parents[i]; - p[i] = -1; - } - } - - /* Add end of this submatch to regset after processing this - node. */ - STACK_PUSHX(stack, int, node->submatch_id); - STACK_PUSHX(stack, int, ADDTAGS_SET_SUBMATCH_END); - } - - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit = node->obj; - - if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) - { - int i; - if (regset[0] >= 0) - { - /* Regset is not empty, so add a tag before the - literal or backref. */ - if (!first_pass) - { - status = tre_add_tag_left(mem, node, tag); - tnfa->tag_directions[tag] = direction; - if (minimal_tag >= 0) - { - for (i = 0; tnfa->minimal_tags[i] >= 0; i++); - tnfa->minimal_tags[i] = tag; - tnfa->minimal_tags[i + 1] = minimal_tag; - tnfa->minimal_tags[i + 2] = -1; - minimal_tag = -1; - num_minimals++; - } - tre_purge_regset(regset, tnfa, tag); - } - else - { - node->num_tags = 1; - } - - regset[0] = -1; - tag = next_tag; - num_tags++; - next_tag++; - } - } - else - { - assert(!IS_TAG(lit)); - } - break; - } - case CATENATION: - { - tre_catenation_t *cat = node->obj; - tre_ast_node_t *left = cat->left; - tre_ast_node_t *right = cat->right; - int reserved_tag = -1; - - - /* After processing right child. */ - STACK_PUSHX(stack, voidptr, node); - STACK_PUSHX(stack, int, ADDTAGS_AFTER_CAT_RIGHT); - - /* Process right child. */ - STACK_PUSHX(stack, voidptr, right); - STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - - /* After processing left child. */ - STACK_PUSHX(stack, int, next_tag + left->num_tags); - if (left->num_tags > 0 && right->num_tags > 0) - { - /* Reserve the next tag to the right child. */ - reserved_tag = next_tag; - next_tag++; - } - STACK_PUSHX(stack, int, reserved_tag); - STACK_PUSHX(stack, int, ADDTAGS_AFTER_CAT_LEFT); - - /* Process left child. */ - STACK_PUSHX(stack, voidptr, left); - STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - - } - break; - case ITERATION: - { - tre_iteration_t *iter = node->obj; - - if (first_pass) - { - STACK_PUSHX(stack, int, regset[0] >= 0 || iter->minimal); - } - else - { - STACK_PUSHX(stack, int, tag); - STACK_PUSHX(stack, int, iter->minimal); - } - STACK_PUSHX(stack, voidptr, node); - STACK_PUSHX(stack, int, ADDTAGS_AFTER_ITERATION); - - STACK_PUSHX(stack, voidptr, iter->arg); - STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - - /* Regset is not empty, so add a tag here. */ - if (regset[0] >= 0 || iter->minimal) - { - if (!first_pass) - { - int i; - status = tre_add_tag_left(mem, node, tag); - if (iter->minimal) - tnfa->tag_directions[tag] = TRE_TAG_MAXIMIZE; - else - tnfa->tag_directions[tag] = direction; - if (minimal_tag >= 0) - { - for (i = 0; tnfa->minimal_tags[i] >= 0; i++); - tnfa->minimal_tags[i] = tag; - tnfa->minimal_tags[i + 1] = minimal_tag; - tnfa->minimal_tags[i + 2] = -1; - minimal_tag = -1; - num_minimals++; - } - tre_purge_regset(regset, tnfa, tag); - } - - regset[0] = -1; - tag = next_tag; - num_tags++; - next_tag++; - } - direction = TRE_TAG_MINIMIZE; - } - break; - case UNION: - { - tre_union_t *uni = node->obj; - tre_ast_node_t *left = uni->left; - tre_ast_node_t *right = uni->right; - int left_tag; - int right_tag; - - if (regset[0] >= 0) - { - left_tag = next_tag; - right_tag = next_tag + 1; - } - else - { - left_tag = tag; - right_tag = next_tag; - } - - /* After processing right child. */ - STACK_PUSHX(stack, int, right_tag); - STACK_PUSHX(stack, int, left_tag); - STACK_PUSHX(stack, voidptr, regset); - STACK_PUSHX(stack, int, regset[0] >= 0); - STACK_PUSHX(stack, voidptr, node); - STACK_PUSHX(stack, voidptr, right); - STACK_PUSHX(stack, voidptr, left); - STACK_PUSHX(stack, int, ADDTAGS_AFTER_UNION_RIGHT); - - /* Process right child. */ - STACK_PUSHX(stack, voidptr, right); - STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - - /* After processing left child. */ - STACK_PUSHX(stack, int, ADDTAGS_AFTER_UNION_LEFT); - - /* Process left child. */ - STACK_PUSHX(stack, voidptr, left); - STACK_PUSHX(stack, int, ADDTAGS_RECURSE); - - /* Regset is not empty, so add a tag here. */ - if (regset[0] >= 0) - { - if (!first_pass) - { - int i; - status = tre_add_tag_left(mem, node, tag); - tnfa->tag_directions[tag] = direction; - if (minimal_tag >= 0) - { - for (i = 0; tnfa->minimal_tags[i] >= 0; i++); - tnfa->minimal_tags[i] = tag; - tnfa->minimal_tags[i + 1] = minimal_tag; - tnfa->minimal_tags[i + 2] = -1; - minimal_tag = -1; - num_minimals++; - } - tre_purge_regset(regset, tnfa, tag); - } - - regset[0] = -1; - tag = next_tag; - num_tags++; - next_tag++; - } - - if (node->num_submatches > 0) - { - /* The next two tags are reserved for markers. */ - next_tag++; - tag = next_tag; - next_tag++; - } - - break; - } - } - - if (node->submatch_id >= 0) - { - int i; - /* Push this submatch on the parents stack. */ - for (i = 0; parents[i] >= 0; i++); - parents[i] = node->submatch_id; - parents[i + 1] = -1; - } - - break; /* end case: ADDTAGS_RECURSE */ - - case ADDTAGS_AFTER_ITERATION: - { - int minimal = 0; - int enter_tag; - node = tre_stack_pop_voidptr(stack); - if (first_pass) - { - node->num_tags = ((tre_iteration_t *)node->obj)->arg->num_tags - + tre_stack_pop_int(stack); - minimal_tag = -1; - } - else - { - minimal = tre_stack_pop_int(stack); - enter_tag = tre_stack_pop_int(stack); - if (minimal) - minimal_tag = enter_tag; - } - - if (!first_pass) - { - if (minimal) - direction = TRE_TAG_MINIMIZE; - else - direction = TRE_TAG_MAXIMIZE; - } - break; - } - - case ADDTAGS_AFTER_CAT_LEFT: - { - int new_tag = tre_stack_pop_int(stack); - next_tag = tre_stack_pop_int(stack); - if (new_tag >= 0) - { - tag = new_tag; - } - break; - } - - case ADDTAGS_AFTER_CAT_RIGHT: - node = tre_stack_pop_voidptr(stack); - if (first_pass) - node->num_tags = ((tre_catenation_t *)node->obj)->left->num_tags - + ((tre_catenation_t *)node->obj)->right->num_tags; - break; - - case ADDTAGS_AFTER_UNION_LEFT: - /* Lift the bottom of the `regset' array so that when processing - the right operand the items currently in the array are - invisible. The original bottom was saved at ADDTAGS_UNION and - will be restored at ADDTAGS_AFTER_UNION_RIGHT below. */ - while (*regset >= 0) - regset++; - break; - - case ADDTAGS_AFTER_UNION_RIGHT: - { - int added_tags, tag_left, tag_right; - tre_ast_node_t *left = tre_stack_pop_voidptr(stack); - tre_ast_node_t *right = tre_stack_pop_voidptr(stack); - node = tre_stack_pop_voidptr(stack); - added_tags = tre_stack_pop_int(stack); - if (first_pass) - { - node->num_tags = ((tre_union_t *)node->obj)->left->num_tags - + ((tre_union_t *)node->obj)->right->num_tags + added_tags - + ((node->num_submatches > 0) ? 2 : 0); - } - regset = tre_stack_pop_voidptr(stack); - tag_left = tre_stack_pop_int(stack); - tag_right = tre_stack_pop_int(stack); - - /* Add tags after both children, the left child gets a smaller - tag than the right child. This guarantees that we prefer - the left child over the right child. */ - /* XXX - This is not always necessary (if the children have - tags which must be seen for every match of that child). */ - /* XXX - Check if this is the only place where tre_add_tag_right - is used. If so, use tre_add_tag_left (putting the tag before - the child as opposed after the child) and throw away - tre_add_tag_right. */ - if (node->num_submatches > 0) - { - if (!first_pass) - { - status = tre_add_tag_right(mem, left, tag_left); - tnfa->tag_directions[tag_left] = TRE_TAG_MAXIMIZE; - if (status == REG_OK) - status = tre_add_tag_right(mem, right, tag_right); - tnfa->tag_directions[tag_right] = TRE_TAG_MAXIMIZE; - } - num_tags += 2; - } - direction = TRE_TAG_MAXIMIZE; - break; - } - - default: - assert(0); - break; - - } /* end switch(symbol) */ - } /* end while(tre_stack_num_objects(stack) > bottom) */ - - if (!first_pass) - tre_purge_regset(regset, tnfa, tag); - - if (!first_pass && minimal_tag >= 0) - { - int i; - for (i = 0; tnfa->minimal_tags[i] >= 0; i++); - tnfa->minimal_tags[i] = tag; - tnfa->minimal_tags[i + 1] = minimal_tag; - tnfa->minimal_tags[i + 2] = -1; - minimal_tag = -1; - num_minimals++; - } - - assert(tree->num_tags == num_tags); - tnfa->end_tag = num_tags; - tnfa->num_tags = num_tags; - tnfa->num_minimals = num_minimals; - xfree(orig_regset); - xfree(parents); - xfree(saved_states); - return status; -} - - - -/* - AST to TNFA compilation routines. -*/ - -typedef enum { - COPY_RECURSE, - COPY_SET_RESULT_PTR -} tre_copyast_symbol_t; - -/* Flags for tre_copy_ast(). */ -#define COPY_REMOVE_TAGS 1 -#define COPY_MAXIMIZE_FIRST_TAG 2 - -static reg_errcode_t -tre_copy_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, - int flags, int *pos_add, tre_tag_direction_t *tag_directions, - tre_ast_node_t **copy, int *max_pos) -{ - reg_errcode_t status = REG_OK; - int bottom = tre_stack_num_objects(stack); - int num_copied = 0; - int first_tag = 1; - tre_ast_node_t **result = copy; - tre_copyast_symbol_t symbol; - - STACK_PUSH(stack, voidptr, ast); - STACK_PUSH(stack, int, COPY_RECURSE); - - while (status == REG_OK && tre_stack_num_objects(stack) > bottom) - { - tre_ast_node_t *node; - if (status != REG_OK) - break; - - symbol = (tre_copyast_symbol_t)tre_stack_pop_int(stack); - switch (symbol) - { - case COPY_SET_RESULT_PTR: - result = tre_stack_pop_voidptr(stack); - break; - case COPY_RECURSE: - node = tre_stack_pop_voidptr(stack); - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit = node->obj; - int pos = lit->position; - int min = lit->code_min; - int max = lit->code_max; - if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) - { - /* XXX - e.g. [ab] has only one position but two - nodes, so we are creating holes in the state space - here. Not fatal, just wastes memory. */ - pos += *pos_add; - num_copied++; - } - else if (IS_TAG(lit) && (flags & COPY_REMOVE_TAGS)) - { - /* Change this tag to empty. */ - min = EMPTY; - max = pos = -1; - } - else if (IS_TAG(lit) && (flags & COPY_MAXIMIZE_FIRST_TAG) - && first_tag) - { - /* Maximize the first tag. */ - tag_directions[max] = TRE_TAG_MAXIMIZE; - first_tag = 0; - } - *result = tre_ast_new_literal(mem, min, max, pos); - if (*result == NULL) - status = REG_ESPACE; - else { - tre_literal_t *p = (*result)->obj; - p->class = lit->class; - p->neg_classes = lit->neg_classes; - } - - if (pos > *max_pos) - *max_pos = pos; - break; - } - case UNION: - { - tre_union_t *uni = node->obj; - tre_union_t *tmp; - *result = tre_ast_new_union(mem, uni->left, uni->right); - if (*result == NULL) - { - status = REG_ESPACE; - break; - } - tmp = (*result)->obj; - result = &tmp->left; - STACK_PUSHX(stack, voidptr, uni->right); - STACK_PUSHX(stack, int, COPY_RECURSE); - STACK_PUSHX(stack, voidptr, &tmp->right); - STACK_PUSHX(stack, int, COPY_SET_RESULT_PTR); - STACK_PUSHX(stack, voidptr, uni->left); - STACK_PUSHX(stack, int, COPY_RECURSE); - break; - } - case CATENATION: - { - tre_catenation_t *cat = node->obj; - tre_catenation_t *tmp; - *result = tre_ast_new_catenation(mem, cat->left, cat->right); - if (*result == NULL) - { - status = REG_ESPACE; - break; - } - tmp = (*result)->obj; - tmp->left = NULL; - tmp->right = NULL; - result = &tmp->left; - - STACK_PUSHX(stack, voidptr, cat->right); - STACK_PUSHX(stack, int, COPY_RECURSE); - STACK_PUSHX(stack, voidptr, &tmp->right); - STACK_PUSHX(stack, int, COPY_SET_RESULT_PTR); - STACK_PUSHX(stack, voidptr, cat->left); - STACK_PUSHX(stack, int, COPY_RECURSE); - break; - } - case ITERATION: - { - tre_iteration_t *iter = node->obj; - STACK_PUSHX(stack, voidptr, iter->arg); - STACK_PUSHX(stack, int, COPY_RECURSE); - *result = tre_ast_new_iter(mem, iter->arg, iter->min, - iter->max, iter->minimal); - if (*result == NULL) - { - status = REG_ESPACE; - break; - } - iter = (*result)->obj; - result = &iter->arg; - break; - } - default: - assert(0); - break; - } - break; - } - } - *pos_add += num_copied; - return status; -} - -typedef enum { - EXPAND_RECURSE, - EXPAND_AFTER_ITER -} tre_expand_ast_symbol_t; - -/* Expands each iteration node that has a finite nonzero minimum or maximum - iteration count to a catenated sequence of copies of the node. */ -static reg_errcode_t -tre_expand_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, - int *position, tre_tag_direction_t *tag_directions) -{ - reg_errcode_t status = REG_OK; - int bottom = tre_stack_num_objects(stack); - int pos_add = 0; - int pos_add_total = 0; - int max_pos = 0; - int iter_depth = 0; - - STACK_PUSHR(stack, voidptr, ast); - STACK_PUSHR(stack, int, EXPAND_RECURSE); - while (status == REG_OK && tre_stack_num_objects(stack) > bottom) - { - tre_ast_node_t *node; - tre_expand_ast_symbol_t symbol; - - if (status != REG_OK) - break; - - symbol = (tre_expand_ast_symbol_t)tre_stack_pop_int(stack); - node = tre_stack_pop_voidptr(stack); - switch (symbol) - { - case EXPAND_RECURSE: - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit= node->obj; - if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) - { - lit->position += pos_add; - if (lit->position > max_pos) - max_pos = lit->position; - } - break; - } - case UNION: - { - tre_union_t *uni = node->obj; - STACK_PUSHX(stack, voidptr, uni->right); - STACK_PUSHX(stack, int, EXPAND_RECURSE); - STACK_PUSHX(stack, voidptr, uni->left); - STACK_PUSHX(stack, int, EXPAND_RECURSE); - break; - } - case CATENATION: - { - tre_catenation_t *cat = node->obj; - STACK_PUSHX(stack, voidptr, cat->right); - STACK_PUSHX(stack, int, EXPAND_RECURSE); - STACK_PUSHX(stack, voidptr, cat->left); - STACK_PUSHX(stack, int, EXPAND_RECURSE); - break; - } - case ITERATION: - { - tre_iteration_t *iter = node->obj; - STACK_PUSHX(stack, int, pos_add); - STACK_PUSHX(stack, voidptr, node); - STACK_PUSHX(stack, int, EXPAND_AFTER_ITER); - STACK_PUSHX(stack, voidptr, iter->arg); - STACK_PUSHX(stack, int, EXPAND_RECURSE); - /* If we are going to expand this node at EXPAND_AFTER_ITER - then don't increase the `pos' fields of the nodes now, it - will get done when expanding. */ - if (iter->min > 1 || iter->max > 1) - pos_add = 0; - iter_depth++; - break; - } - default: - assert(0); - break; - } - break; - case EXPAND_AFTER_ITER: - { - tre_iteration_t *iter = node->obj; - int pos_add_last; - pos_add = tre_stack_pop_int(stack); - pos_add_last = pos_add; - if (iter->min > 1 || iter->max > 1) - { - tre_ast_node_t *seq1 = NULL, *seq2 = NULL; - int j; - int pos_add_save = pos_add; - - /* Create a catenated sequence of copies of the node. */ - for (j = 0; j < iter->min; j++) - { - tre_ast_node_t *copy; - /* Remove tags from all but the last copy. */ - int flags = ((j + 1 < iter->min) - ? COPY_REMOVE_TAGS - : COPY_MAXIMIZE_FIRST_TAG); - pos_add_save = pos_add; - status = tre_copy_ast(mem, stack, iter->arg, flags, - &pos_add, tag_directions, ©, - &max_pos); - if (status != REG_OK) - return status; - if (seq1 != NULL) - seq1 = tre_ast_new_catenation(mem, seq1, copy); - else - seq1 = copy; - if (seq1 == NULL) - return REG_ESPACE; - } - - if (iter->max == -1) - { - /* No upper limit. */ - pos_add_save = pos_add; - status = tre_copy_ast(mem, stack, iter->arg, 0, - &pos_add, NULL, &seq2, &max_pos); - if (status != REG_OK) - return status; - seq2 = tre_ast_new_iter(mem, seq2, 0, -1, 0); - if (seq2 == NULL) - return REG_ESPACE; - } - else - { - for (j = iter->min; j < iter->max; j++) - { - tre_ast_node_t *tmp, *copy; - pos_add_save = pos_add; - status = tre_copy_ast(mem, stack, iter->arg, 0, - &pos_add, NULL, ©, &max_pos); - if (status != REG_OK) - return status; - if (seq2 != NULL) - seq2 = tre_ast_new_catenation(mem, copy, seq2); - else - seq2 = copy; - if (seq2 == NULL) - return REG_ESPACE; - tmp = tre_ast_new_literal(mem, EMPTY, -1, -1); - if (tmp == NULL) - return REG_ESPACE; - seq2 = tre_ast_new_union(mem, tmp, seq2); - if (seq2 == NULL) - return REG_ESPACE; - } - } - - pos_add = pos_add_save; - if (seq1 == NULL) - seq1 = seq2; - else if (seq2 != NULL) - seq1 = tre_ast_new_catenation(mem, seq1, seq2); - if (seq1 == NULL) - return REG_ESPACE; - node->obj = seq1->obj; - node->type = seq1->type; - } - - iter_depth--; - pos_add_total += pos_add - pos_add_last; - if (iter_depth == 0) - pos_add = pos_add_total; - - break; - } - default: - assert(0); - break; - } - } - - *position += pos_add_total; - - /* `max_pos' should never be larger than `*position' if the above - code works, but just an extra safeguard let's make sure - `*position' is set large enough so enough memory will be - allocated for the transition table. */ - if (max_pos > *position) - *position = max_pos; - - return status; -} - -static tre_pos_and_tags_t * -tre_set_empty(tre_mem_t mem) -{ - tre_pos_and_tags_t *new_set; - - new_set = tre_mem_calloc(mem, sizeof(*new_set)); - if (new_set == NULL) - return NULL; - - new_set[0].position = -1; - new_set[0].code_min = -1; - new_set[0].code_max = -1; - - return new_set; -} - -static tre_pos_and_tags_t * -tre_set_one(tre_mem_t mem, int position, int code_min, int code_max, - tre_ctype_t class, tre_ctype_t *neg_classes, int backref) -{ - tre_pos_and_tags_t *new_set; - - new_set = tre_mem_calloc(mem, sizeof(*new_set) * 2); - if (new_set == NULL) - return NULL; - - new_set[0].position = position; - new_set[0].code_min = code_min; - new_set[0].code_max = code_max; - new_set[0].class = class; - new_set[0].neg_classes = neg_classes; - new_set[0].backref = backref; - new_set[1].position = -1; - new_set[1].code_min = -1; - new_set[1].code_max = -1; - - return new_set; -} - -static tre_pos_and_tags_t * -tre_set_union(tre_mem_t mem, tre_pos_and_tags_t *set1, tre_pos_and_tags_t *set2, - int *tags, int assertions) -{ - int s1, s2, i, j; - tre_pos_and_tags_t *new_set; - int *new_tags; - int num_tags; - - for (num_tags = 0; tags != NULL && tags[num_tags] >= 0; num_tags++); - for (s1 = 0; set1[s1].position >= 0; s1++); - for (s2 = 0; set2[s2].position >= 0; s2++); - new_set = tre_mem_calloc(mem, sizeof(*new_set) * (s1 + s2 + 1)); - if (!new_set ) - return NULL; - - for (s1 = 0; set1[s1].position >= 0; s1++) - { - new_set[s1].position = set1[s1].position; - new_set[s1].code_min = set1[s1].code_min; - new_set[s1].code_max = set1[s1].code_max; - new_set[s1].assertions = set1[s1].assertions | assertions; - new_set[s1].class = set1[s1].class; - new_set[s1].neg_classes = set1[s1].neg_classes; - new_set[s1].backref = set1[s1].backref; - if (set1[s1].tags == NULL && tags == NULL) - new_set[s1].tags = NULL; - else - { - for (i = 0; set1[s1].tags != NULL && set1[s1].tags[i] >= 0; i++); - new_tags = tre_mem_alloc(mem, (sizeof(*new_tags) - * (i + num_tags + 1))); - if (new_tags == NULL) - return NULL; - for (j = 0; j < i; j++) - new_tags[j] = set1[s1].tags[j]; - for (i = 0; i < num_tags; i++) - new_tags[j + i] = tags[i]; - new_tags[j + i] = -1; - new_set[s1].tags = new_tags; - } - } - - for (s2 = 0; set2[s2].position >= 0; s2++) - { - new_set[s1 + s2].position = set2[s2].position; - new_set[s1 + s2].code_min = set2[s2].code_min; - new_set[s1 + s2].code_max = set2[s2].code_max; - /* XXX - why not | assertions here as well? */ - new_set[s1 + s2].assertions = set2[s2].assertions; - new_set[s1 + s2].class = set2[s2].class; - new_set[s1 + s2].neg_classes = set2[s2].neg_classes; - new_set[s1 + s2].backref = set2[s2].backref; - if (set2[s2].tags == NULL) - new_set[s1 + s2].tags = NULL; - else - { - for (i = 0; set2[s2].tags[i] >= 0; i++); - new_tags = tre_mem_alloc(mem, sizeof(*new_tags) * (i + 1)); - if (new_tags == NULL) - return NULL; - for (j = 0; j < i; j++) - new_tags[j] = set2[s2].tags[j]; - new_tags[j] = -1; - new_set[s1 + s2].tags = new_tags; - } - } - new_set[s1 + s2].position = -1; - return new_set; -} - -/* Finds the empty path through `node' which is the one that should be - taken according to POSIX.2 rules, and adds the tags on that path to - `tags'. `tags' may be NULL. If `num_tags_seen' is not NULL, it is - set to the number of tags seen on the path. */ -static reg_errcode_t -tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node, int *tags, - int *assertions, int *num_tags_seen) -{ - tre_literal_t *lit; - tre_union_t *uni; - tre_catenation_t *cat; - tre_iteration_t *iter; - int i; - int bottom = tre_stack_num_objects(stack); - reg_errcode_t status = REG_OK; - if (num_tags_seen) - *num_tags_seen = 0; - - status = tre_stack_push_voidptr(stack, node); - - /* Walk through the tree recursively. */ - while (status == REG_OK && tre_stack_num_objects(stack) > bottom) - { - node = tre_stack_pop_voidptr(stack); - - switch (node->type) - { - case LITERAL: - lit = (tre_literal_t *)node->obj; - switch (lit->code_min) - { - case TAG: - if (lit->code_max >= 0) - { - if (tags != NULL) - { - /* Add the tag to `tags'. */ - for (i = 0; tags[i] >= 0; i++) - if (tags[i] == lit->code_max) - break; - if (tags[i] < 0) - { - tags[i] = lit->code_max; - tags[i + 1] = -1; - } - } - if (num_tags_seen) - (*num_tags_seen)++; - } - break; - case ASSERTION: - assert(lit->code_max >= 1 - || lit->code_max <= ASSERT_LAST); - if (assertions != NULL) - *assertions |= lit->code_max; - break; - case EMPTY: - break; - default: - assert(0); - break; - } - break; - - case UNION: - /* Subexpressions starting earlier take priority over ones - starting later, so we prefer the left subexpression over the - right subexpression. */ - uni = (tre_union_t *)node->obj; - if (uni->left->nullable) - STACK_PUSHX(stack, voidptr, uni->left) - else if (uni->right->nullable) - STACK_PUSHX(stack, voidptr, uni->right) - else - assert(0); - break; - - case CATENATION: - /* The path must go through both children. */ - cat = (tre_catenation_t *)node->obj; - assert(cat->left->nullable); - assert(cat->right->nullable); - STACK_PUSHX(stack, voidptr, cat->left); - STACK_PUSHX(stack, voidptr, cat->right); - break; - - case ITERATION: - /* A match with an empty string is preferred over no match at - all, so we go through the argument if possible. */ - iter = (tre_iteration_t *)node->obj; - if (iter->arg->nullable) - STACK_PUSHX(stack, voidptr, iter->arg); - break; - - default: - assert(0); - break; - } - } - - return status; -} - - -typedef enum { - NFL_RECURSE, - NFL_POST_UNION, - NFL_POST_CATENATION, - NFL_POST_ITERATION -} tre_nfl_stack_symbol_t; - - -/* Computes and fills in the fields `nullable', `firstpos', and `lastpos' for - the nodes of the AST `tree'. */ -static reg_errcode_t -tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree) -{ - int bottom = tre_stack_num_objects(stack); - - STACK_PUSHR(stack, voidptr, tree); - STACK_PUSHR(stack, int, NFL_RECURSE); - - while (tre_stack_num_objects(stack) > bottom) - { - tre_nfl_stack_symbol_t symbol; - tre_ast_node_t *node; - - symbol = (tre_nfl_stack_symbol_t)tre_stack_pop_int(stack); - node = tre_stack_pop_voidptr(stack); - switch (symbol) - { - case NFL_RECURSE: - switch (node->type) - { - case LITERAL: - { - tre_literal_t *lit = (tre_literal_t *)node->obj; - if (IS_BACKREF(lit)) - { - /* Back references: nullable = false, firstpos = {i}, - lastpos = {i}. */ - node->nullable = 0; - node->firstpos = tre_set_one(mem, lit->position, 0, - TRE_CHAR_MAX, 0, NULL, -1); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_one(mem, lit->position, 0, - TRE_CHAR_MAX, 0, NULL, - (int)lit->code_max); - if (!node->lastpos) - return REG_ESPACE; - } - else if (lit->code_min < 0) - { - /* Tags, empty strings, params, and zero width assertions: - nullable = true, firstpos = {}, and lastpos = {}. */ - node->nullable = 1; - node->firstpos = tre_set_empty(mem); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_empty(mem); - if (!node->lastpos) - return REG_ESPACE; - } - else - { - /* Literal at position i: nullable = false, firstpos = {i}, - lastpos = {i}. */ - node->nullable = 0; - node->firstpos = - tre_set_one(mem, lit->position, (int)lit->code_min, - (int)lit->code_max, 0, NULL, -1); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_one(mem, lit->position, - (int)lit->code_min, - (int)lit->code_max, - lit->class, lit->neg_classes, - -1); - if (!node->lastpos) - return REG_ESPACE; - } - break; - } - - case UNION: - /* Compute the attributes for the two subtrees, and after that - for this node. */ - STACK_PUSHR(stack, voidptr, node); - STACK_PUSHR(stack, int, NFL_POST_UNION); - STACK_PUSHR(stack, voidptr, ((tre_union_t *)node->obj)->right); - STACK_PUSHR(stack, int, NFL_RECURSE); - STACK_PUSHR(stack, voidptr, ((tre_union_t *)node->obj)->left); - STACK_PUSHR(stack, int, NFL_RECURSE); - break; - - case CATENATION: - /* Compute the attributes for the two subtrees, and after that - for this node. */ - STACK_PUSHR(stack, voidptr, node); - STACK_PUSHR(stack, int, NFL_POST_CATENATION); - STACK_PUSHR(stack, voidptr, ((tre_catenation_t *)node->obj)->right); - STACK_PUSHR(stack, int, NFL_RECURSE); - STACK_PUSHR(stack, voidptr, ((tre_catenation_t *)node->obj)->left); - STACK_PUSHR(stack, int, NFL_RECURSE); - break; - - case ITERATION: - /* Compute the attributes for the subtree, and after that for - this node. */ - STACK_PUSHR(stack, voidptr, node); - STACK_PUSHR(stack, int, NFL_POST_ITERATION); - STACK_PUSHR(stack, voidptr, ((tre_iteration_t *)node->obj)->arg); - STACK_PUSHR(stack, int, NFL_RECURSE); - break; - } - break; /* end case: NFL_RECURSE */ - - case NFL_POST_UNION: - { - tre_union_t *uni = (tre_union_t *)node->obj; - node->nullable = uni->left->nullable || uni->right->nullable; - node->firstpos = tre_set_union(mem, uni->left->firstpos, - uni->right->firstpos, NULL, 0); - if (!node->firstpos) - return REG_ESPACE; - node->lastpos = tre_set_union(mem, uni->left->lastpos, - uni->right->lastpos, NULL, 0); - if (!node->lastpos) - return REG_ESPACE; - break; - } - - case NFL_POST_ITERATION: - { - tre_iteration_t *iter = (tre_iteration_t *)node->obj; - - if (iter->min == 0 || iter->arg->nullable) - node->nullable = 1; - else - node->nullable = 0; - node->firstpos = iter->arg->firstpos; - node->lastpos = iter->arg->lastpos; - break; - } - - case NFL_POST_CATENATION: - { - int num_tags, *tags, assertions; - reg_errcode_t status; - tre_catenation_t *cat = node->obj; - node->nullable = cat->left->nullable && cat->right->nullable; - - /* Compute firstpos. */ - if (cat->left->nullable) - { - /* The left side matches the empty string. Make a first pass - with tre_match_empty() to get the number of tags and - parameters. */ - status = tre_match_empty(stack, cat->left, - NULL, NULL, &num_tags); - if (status != REG_OK) - return status; - /* Allocate arrays for the tags and parameters. */ - tags = xmalloc(sizeof(*tags) * (num_tags + 1)); - if (!tags) - return REG_ESPACE; - tags[0] = -1; - assertions = 0; - /* Second pass with tre_mach_empty() to get the list of - tags and parameters. */ - status = tre_match_empty(stack, cat->left, tags, - &assertions, NULL); - if (status != REG_OK) - { - xfree(tags); - return status; - } - node->firstpos = - tre_set_union(mem, cat->right->firstpos, cat->left->firstpos, - tags, assertions); - xfree(tags); - if (!node->firstpos) - return REG_ESPACE; - } - else - { - node->firstpos = cat->left->firstpos; - } - - /* Compute lastpos. */ - if (cat->right->nullable) - { - /* The right side matches the empty string. Make a first pass - with tre_match_empty() to get the number of tags and - parameters. */ - status = tre_match_empty(stack, cat->right, - NULL, NULL, &num_tags); - if (status != REG_OK) - return status; - /* Allocate arrays for the tags and parameters. */ - tags = xmalloc(sizeof(int) * (num_tags + 1)); - if (!tags) - return REG_ESPACE; - tags[0] = -1; - assertions = 0; - /* Second pass with tre_mach_empty() to get the list of - tags and parameters. */ - status = tre_match_empty(stack, cat->right, tags, - &assertions, NULL); - if (status != REG_OK) - { - xfree(tags); - return status; - } - node->lastpos = - tre_set_union(mem, cat->left->lastpos, cat->right->lastpos, - tags, assertions); - xfree(tags); - if (!node->lastpos) - return REG_ESPACE; - } - else - { - node->lastpos = cat->right->lastpos; - } - break; - } - - default: - assert(0); - break; - } - } - - return REG_OK; -} - - -/* Adds a transition from each position in `p1' to each position in `p2'. */ -static reg_errcode_t -tre_make_trans(tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2, - tre_tnfa_transition_t *transitions, - int *counts, int *offs) -{ - tre_pos_and_tags_t *orig_p2 = p2; - tre_tnfa_transition_t *trans; - int i, j, k, l, dup, prev_p2_pos; - - if (transitions != NULL) - while (p1->position >= 0) - { - p2 = orig_p2; - prev_p2_pos = -1; - while (p2->position >= 0) - { - /* Optimization: if this position was already handled, skip it. */ - if (p2->position == prev_p2_pos) - { - p2++; - continue; - } - prev_p2_pos = p2->position; - /* Set `trans' to point to the next unused transition from - position `p1->position'. */ - trans = transitions + offs[p1->position]; - while (trans->state != NULL) - { -#if 0 - /* If we find a previous transition from `p1->position' to - `p2->position', it is overwritten. This can happen only - if there are nested loops in the regexp, like in "((a)*)*". - In POSIX.2 repetition using the outer loop is always - preferred over using the inner loop. Therefore the - transition for the inner loop is useless and can be thrown - away. */ - /* XXX - The same position is used for all nodes in a bracket - expression, so this optimization cannot be used (it will - break bracket expressions) unless I figure out a way to - detect it here. */ - if (trans->state_id == p2->position) - { - break; - } -#endif - trans++; - } - - if (trans->state == NULL) - (trans + 1)->state = NULL; - /* Use the character ranges, assertions, etc. from `p1' for - the transition from `p1' to `p2'. */ - trans->code_min = p1->code_min; - trans->code_max = p1->code_max; - trans->state = transitions + offs[p2->position]; - trans->state_id = p2->position; - trans->assertions = p1->assertions | p2->assertions - | (p1->class ? ASSERT_CHAR_CLASS : 0) - | (p1->neg_classes != NULL ? ASSERT_CHAR_CLASS_NEG : 0); - if (p1->backref >= 0) - { - assert((trans->assertions & ASSERT_CHAR_CLASS) == 0); - assert(p2->backref < 0); - trans->u.backref = p1->backref; - trans->assertions |= ASSERT_BACKREF; - } - else - trans->u.class = p1->class; - if (p1->neg_classes != NULL) - { - for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++); - trans->neg_classes = - xmalloc(sizeof(*trans->neg_classes) * (i + 1)); - if (trans->neg_classes == NULL) - return REG_ESPACE; - for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++) - trans->neg_classes[i] = p1->neg_classes[i]; - trans->neg_classes[i] = (tre_ctype_t)0; - } - else - trans->neg_classes = NULL; - - /* Find out how many tags this transition has. */ - i = 0; - if (p1->tags != NULL) - while(p1->tags[i] >= 0) - i++; - j = 0; - if (p2->tags != NULL) - while(p2->tags[j] >= 0) - j++; - - /* If we are overwriting a transition, free the old tag array. */ - if (trans->tags != NULL) - xfree(trans->tags); - trans->tags = NULL; - - /* If there were any tags, allocate an array and fill it. */ - if (i + j > 0) - { - trans->tags = xmalloc(sizeof(*trans->tags) * (i + j + 1)); - if (!trans->tags) - return REG_ESPACE; - i = 0; - if (p1->tags != NULL) - while(p1->tags[i] >= 0) - { - trans->tags[i] = p1->tags[i]; - i++; - } - l = i; - j = 0; - if (p2->tags != NULL) - while (p2->tags[j] >= 0) - { - /* Don't add duplicates. */ - dup = 0; - for (k = 0; k < i; k++) - if (trans->tags[k] == p2->tags[j]) - { - dup = 1; - break; - } - if (!dup) - trans->tags[l++] = p2->tags[j]; - j++; - } - trans->tags[l] = -1; - } - - p2++; - } - p1++; - } - else - /* Compute a maximum limit for the number of transitions leaving - from each state. */ - while (p1->position >= 0) - { - p2 = orig_p2; - while (p2->position >= 0) - { - counts[p1->position]++; - p2++; - } - p1++; - } - return REG_OK; -} - -/* Converts the syntax tree to a TNFA. All the transitions in the TNFA are - labelled with one character range (there are no transitions on empty - strings). The TNFA takes O(n^2) space in the worst case, `n' is size of - the regexp. */ -static reg_errcode_t -tre_ast_to_tnfa(tre_ast_node_t *node, tre_tnfa_transition_t *transitions, - int *counts, int *offs) -{ - tre_union_t *uni; - tre_catenation_t *cat; - tre_iteration_t *iter; - reg_errcode_t errcode = REG_OK; - - /* XXX - recurse using a stack!. */ - switch (node->type) - { - case LITERAL: - break; - case UNION: - uni = (tre_union_t *)node->obj; - errcode = tre_ast_to_tnfa(uni->left, transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - errcode = tre_ast_to_tnfa(uni->right, transitions, counts, offs); - break; - - case CATENATION: - cat = (tre_catenation_t *)node->obj; - /* Add a transition from each position in cat->left->lastpos - to each position in cat->right->firstpos. */ - errcode = tre_make_trans(cat->left->lastpos, cat->right->firstpos, - transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - errcode = tre_ast_to_tnfa(cat->left, transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - errcode = tre_ast_to_tnfa(cat->right, transitions, counts, offs); - break; - - case ITERATION: - iter = (tre_iteration_t *)node->obj; - assert(iter->max == -1 || iter->max == 1); - - if (iter->max == -1) - { - assert(iter->min == 0 || iter->min == 1); - /* Add a transition from each last position in the iterated - expression to each first position. */ - errcode = tre_make_trans(iter->arg->lastpos, iter->arg->firstpos, - transitions, counts, offs); - if (errcode != REG_OK) - return errcode; - } - errcode = tre_ast_to_tnfa(iter->arg, transitions, counts, offs); - break; - } - return errcode; -} - - -#define ERROR_EXIT(err) \ - do \ - { \ - errcode = err; \ - if (/*CONSTCOND*/1) \ - goto error_exit; \ - } \ - while (/*CONSTCOND*/0) - - -int -regcomp(regex_t *restrict preg, const char *restrict regex, int cflags) -{ - tre_stack_t *stack; - tre_ast_node_t *tree, *tmp_ast_l, *tmp_ast_r; - tre_pos_and_tags_t *p; - int *counts = NULL, *offs = NULL; - int i, add = 0; - tre_tnfa_transition_t *transitions, *initial; - tre_tnfa_t *tnfa = NULL; - tre_submatch_data_t *submatch_data; - tre_tag_direction_t *tag_directions = NULL; - reg_errcode_t errcode; - tre_mem_t mem; - - /* Parse context. */ - tre_parse_ctx_t parse_ctx; - - /* Allocate a stack used throughout the compilation process for various - purposes. */ - stack = tre_stack_new(512, 1024000, 128); - if (!stack) - return REG_ESPACE; - /* Allocate a fast memory allocator. */ - mem = tre_mem_new(); - if (!mem) - { - tre_stack_destroy(stack); - return REG_ESPACE; - } - - /* Parse the regexp. */ - memset(&parse_ctx, 0, sizeof(parse_ctx)); - parse_ctx.mem = mem; - parse_ctx.stack = stack; - parse_ctx.start = regex; - parse_ctx.cflags = cflags; - parse_ctx.max_backref = -1; - errcode = tre_parse(&parse_ctx); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - preg->re_nsub = parse_ctx.submatch_id - 1; - tree = parse_ctx.n; - -#ifdef TRE_DEBUG - tre_ast_print(tree); -#endif /* TRE_DEBUG */ - - /* Referring to nonexistent subexpressions is illegal. */ - if (parse_ctx.max_backref > (int)preg->re_nsub) - ERROR_EXIT(REG_ESUBREG); - - /* Allocate the TNFA struct. */ - tnfa = xcalloc(1, sizeof(tre_tnfa_t)); - if (tnfa == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->have_backrefs = parse_ctx.max_backref >= 0; - tnfa->have_approx = 0; - tnfa->num_submatches = parse_ctx.submatch_id; - - /* Set up tags for submatch addressing. If REG_NOSUB is set and the - regexp does not have back references, this can be skipped. */ - if (tnfa->have_backrefs || !(cflags & REG_NOSUB)) - { - - /* Figure out how many tags we will need. */ - errcode = tre_add_tags(NULL, stack, tree, tnfa); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - if (tnfa->num_tags > 0) - { - tag_directions = xmalloc(sizeof(*tag_directions) - * (tnfa->num_tags + 1)); - if (tag_directions == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->tag_directions = tag_directions; - memset(tag_directions, -1, - sizeof(*tag_directions) * (tnfa->num_tags + 1)); - } - tnfa->minimal_tags = xcalloc((unsigned)tnfa->num_tags * 2 + 1, - sizeof(*tnfa->minimal_tags)); - if (tnfa->minimal_tags == NULL) - ERROR_EXIT(REG_ESPACE); - - submatch_data = xcalloc((unsigned)parse_ctx.submatch_id, - sizeof(*submatch_data)); - if (submatch_data == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->submatch_data = submatch_data; - - errcode = tre_add_tags(mem, stack, tree, tnfa); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - } - - /* Expand iteration nodes. */ - errcode = tre_expand_ast(mem, stack, tree, &parse_ctx.position, - tag_directions); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - /* Add a dummy node for the final state. - XXX - For certain patterns this dummy node can be optimized away, - for example "a*" or "ab*". Figure out a simple way to detect - this possibility. */ - tmp_ast_l = tree; - tmp_ast_r = tre_ast_new_literal(mem, 0, 0, parse_ctx.position++); - if (tmp_ast_r == NULL) - ERROR_EXIT(REG_ESPACE); - - tree = tre_ast_new_catenation(mem, tmp_ast_l, tmp_ast_r); - if (tree == NULL) - ERROR_EXIT(REG_ESPACE); - - errcode = tre_compute_nfl(mem, stack, tree); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - counts = xmalloc(sizeof(int) * parse_ctx.position); - if (counts == NULL) - ERROR_EXIT(REG_ESPACE); - - offs = xmalloc(sizeof(int) * parse_ctx.position); - if (offs == NULL) - ERROR_EXIT(REG_ESPACE); - - for (i = 0; i < parse_ctx.position; i++) - counts[i] = 0; - tre_ast_to_tnfa(tree, NULL, counts, NULL); - - add = 0; - for (i = 0; i < parse_ctx.position; i++) - { - offs[i] = add; - add += counts[i] + 1; - counts[i] = 0; - } - transitions = xcalloc((unsigned)add + 1, sizeof(*transitions)); - if (transitions == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->transitions = transitions; - tnfa->num_transitions = add; - - errcode = tre_ast_to_tnfa(tree, transitions, counts, offs); - if (errcode != REG_OK) - ERROR_EXIT(errcode); - - tnfa->firstpos_chars = NULL; - - p = tree->firstpos; - i = 0; - while (p->position >= 0) - { - i++; - p++; - } - - initial = xcalloc((unsigned)i + 1, sizeof(tre_tnfa_transition_t)); - if (initial == NULL) - ERROR_EXIT(REG_ESPACE); - tnfa->initial = initial; - - i = 0; - for (p = tree->firstpos; p->position >= 0; p++) - { - initial[i].state = transitions + offs[p->position]; - initial[i].state_id = p->position; - initial[i].tags = NULL; - /* Copy the arrays p->tags, and p->params, they are allocated - from a tre_mem object. */ - if (p->tags) - { - int j; - for (j = 0; p->tags[j] >= 0; j++); - initial[i].tags = xmalloc(sizeof(*p->tags) * (j + 1)); - if (!initial[i].tags) - ERROR_EXIT(REG_ESPACE); - memcpy(initial[i].tags, p->tags, sizeof(*p->tags) * (j + 1)); - } - initial[i].assertions = p->assertions; - i++; - } - initial[i].state = NULL; - - tnfa->num_transitions = add; - tnfa->final = transitions + offs[tree->lastpos[0].position]; - tnfa->num_states = parse_ctx.position; - tnfa->cflags = cflags; - - tre_mem_destroy(mem); - tre_stack_destroy(stack); - xfree(counts); - xfree(offs); - - preg->TRE_REGEX_T_FIELD = (void *)tnfa; - return REG_OK; - - error_exit: - /* Free everything that was allocated and return the error code. */ - tre_mem_destroy(mem); - if (stack != NULL) - tre_stack_destroy(stack); - if (counts != NULL) - xfree(counts); - if (offs != NULL) - xfree(offs); - preg->TRE_REGEX_T_FIELD = (void *)tnfa; - regfree(preg); - return errcode; -} - - - - -void -regfree(regex_t *preg) -{ - tre_tnfa_t *tnfa; - unsigned int i; - tre_tnfa_transition_t *trans; - - tnfa = (void *)preg->TRE_REGEX_T_FIELD; - if (!tnfa) - return; - - for (i = 0; i < tnfa->num_transitions; i++) - if (tnfa->transitions[i].state) - { - if (tnfa->transitions[i].tags) - xfree(tnfa->transitions[i].tags); - if (tnfa->transitions[i].neg_classes) - xfree(tnfa->transitions[i].neg_classes); - } - if (tnfa->transitions) - xfree(tnfa->transitions); - - if (tnfa->initial) - { - for (trans = tnfa->initial; trans->state; trans++) - { - if (trans->tags) - xfree(trans->tags); - } - xfree(tnfa->initial); - } - - if (tnfa->submatch_data) - { - for (i = 0; i < tnfa->num_submatches; i++) - if (tnfa->submatch_data[i].parents) - xfree(tnfa->submatch_data[i].parents); - xfree(tnfa->submatch_data); - } - - if (tnfa->tag_directions) - xfree(tnfa->tag_directions); - if (tnfa->firstpos_chars) - xfree(tnfa->firstpos_chars); - if (tnfa->minimal_tags) - xfree(tnfa->minimal_tags); - xfree(tnfa); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/regex/regexec.c b/lib/libc/wasi/libc-top-half/musl/src/regex/regexec.c deleted file mode 100644 index 253b0e1495601567cca31ea27dceca744fcdbfcb..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/regex/regexec.c +++ /dev/null @@ -1,1028 +0,0 @@ -/* - regexec.c - TRE POSIX compatible matching functions (and more). - - Copyright (c) 2001-2009 Ville Laurikari - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include -#include -#include -#include -#include -#include - -#include - -#include "tre.h" - -#include - -static void -tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, - const tre_tnfa_t *tnfa, regoff_t *tags, regoff_t match_eo); - -/*********************************************************************** - from tre-match-utils.h -***********************************************************************/ - -#define GET_NEXT_WCHAR() do { \ - prev_c = next_c; pos += pos_add_next; \ - if ((pos_add_next = mbtowc(&next_c, str_byte, MB_LEN_MAX)) <= 0) { \ - if (pos_add_next < 0) { ret = REG_NOMATCH; goto error_exit; } \ - else pos_add_next++; \ - } \ - str_byte += pos_add_next; \ - } while (0) - -#define IS_WORD_CHAR(c) ((c) == L'_' || tre_isalnum(c)) - -#define CHECK_ASSERTIONS(assertions) \ - (((assertions & ASSERT_AT_BOL) \ - && (pos > 0 || reg_notbol) \ - && (prev_c != L'\n' || !reg_newline)) \ - || ((assertions & ASSERT_AT_EOL) \ - && (next_c != L'\0' || reg_noteol) \ - && (next_c != L'\n' || !reg_newline)) \ - || ((assertions & ASSERT_AT_BOW) \ - && (IS_WORD_CHAR(prev_c) || !IS_WORD_CHAR(next_c))) \ - || ((assertions & ASSERT_AT_EOW) \ - && (!IS_WORD_CHAR(prev_c) || IS_WORD_CHAR(next_c))) \ - || ((assertions & ASSERT_AT_WB) \ - && (pos != 0 && next_c != L'\0' \ - && IS_WORD_CHAR(prev_c) == IS_WORD_CHAR(next_c))) \ - || ((assertions & ASSERT_AT_WB_NEG) \ - && (pos == 0 || next_c == L'\0' \ - || IS_WORD_CHAR(prev_c) != IS_WORD_CHAR(next_c)))) - -#define CHECK_CHAR_CLASSES(trans_i, tnfa, eflags) \ - (((trans_i->assertions & ASSERT_CHAR_CLASS) \ - && !(tnfa->cflags & REG_ICASE) \ - && !tre_isctype((tre_cint_t)prev_c, trans_i->u.class)) \ - || ((trans_i->assertions & ASSERT_CHAR_CLASS) \ - && (tnfa->cflags & REG_ICASE) \ - && !tre_isctype(tre_tolower((tre_cint_t)prev_c),trans_i->u.class) \ - && !tre_isctype(tre_toupper((tre_cint_t)prev_c),trans_i->u.class)) \ - || ((trans_i->assertions & ASSERT_CHAR_CLASS_NEG) \ - && tre_neg_char_classes_match(trans_i->neg_classes,(tre_cint_t)prev_c,\ - tnfa->cflags & REG_ICASE))) - - - - -/* Returns 1 if `t1' wins `t2', 0 otherwise. */ -static int -tre_tag_order(int num_tags, tre_tag_direction_t *tag_directions, - regoff_t *t1, regoff_t *t2) -{ - int i; - for (i = 0; i < num_tags; i++) - { - if (tag_directions[i] == TRE_TAG_MINIMIZE) - { - if (t1[i] < t2[i]) - return 1; - if (t1[i] > t2[i]) - return 0; - } - else - { - if (t1[i] > t2[i]) - return 1; - if (t1[i] < t2[i]) - return 0; - } - } - /* assert(0);*/ - return 0; -} - -static int -tre_neg_char_classes_match(tre_ctype_t *classes, tre_cint_t wc, int icase) -{ - while (*classes != (tre_ctype_t)0) - if ((!icase && tre_isctype(wc, *classes)) - || (icase && (tre_isctype(tre_toupper(wc), *classes) - || tre_isctype(tre_tolower(wc), *classes)))) - return 1; /* Match. */ - else - classes++; - return 0; /* No match. */ -} - - -/*********************************************************************** - from tre-match-parallel.c -***********************************************************************/ - -/* - This algorithm searches for matches basically by reading characters - in the searched string one by one, starting at the beginning. All - matching paths in the TNFA are traversed in parallel. When two or - more paths reach the same state, exactly one is chosen according to - tag ordering rules; if returning submatches is not required it does - not matter which path is chosen. - - The worst case time required for finding the leftmost and longest - match, or determining that there is no match, is always linearly - dependent on the length of the text being searched. - - This algorithm cannot handle TNFAs with back referencing nodes. - See `tre-match-backtrack.c'. -*/ - -typedef struct { - tre_tnfa_transition_t *state; - regoff_t *tags; -} tre_tnfa_reach_t; - -typedef struct { - regoff_t pos; - regoff_t **tags; -} tre_reach_pos_t; - - -static reg_errcode_t -tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, - regoff_t *match_tags, int eflags, - regoff_t *match_end_ofs) -{ - /* State variables required by GET_NEXT_WCHAR. */ - tre_char_t prev_c = 0, next_c = 0; - const char *str_byte = string; - regoff_t pos = -1; - regoff_t pos_add_next = 1; -#ifdef TRE_MBSTATE - mbstate_t mbstate; -#endif /* TRE_MBSTATE */ - int reg_notbol = eflags & REG_NOTBOL; - int reg_noteol = eflags & REG_NOTEOL; - int reg_newline = tnfa->cflags & REG_NEWLINE; - reg_errcode_t ret; - - char *buf; - tre_tnfa_transition_t *trans_i; - tre_tnfa_reach_t *reach, *reach_next, *reach_i, *reach_next_i; - tre_reach_pos_t *reach_pos; - int *tag_i; - int num_tags, i; - - regoff_t match_eo = -1; /* end offset of match (-1 if no match found yet) */ - int new_match = 0; - regoff_t *tmp_tags = NULL; - regoff_t *tmp_iptr; - -#ifdef TRE_MBSTATE - memset(&mbstate, '\0', sizeof(mbstate)); -#endif /* TRE_MBSTATE */ - - if (!match_tags) - num_tags = 0; - else - num_tags = tnfa->num_tags; - - /* Allocate memory for temporary data required for matching. This needs to - be done for every matching operation to be thread safe. This allocates - everything in a single large block with calloc(). */ - { - size_t tbytes, rbytes, pbytes, xbytes, total_bytes; - char *tmp_buf; - - /* Ensure that tbytes and xbytes*num_states cannot overflow, and that - * they don't contribute more than 1/8 of SIZE_MAX to total_bytes. */ - if (num_tags > SIZE_MAX/(8 * sizeof(regoff_t) * tnfa->num_states)) - return REG_ESPACE; - - /* Likewise check rbytes. */ - if (tnfa->num_states+1 > SIZE_MAX/(8 * sizeof(*reach_next))) - return REG_ESPACE; - - /* Likewise check pbytes. */ - if (tnfa->num_states > SIZE_MAX/(8 * sizeof(*reach_pos))) - return REG_ESPACE; - - /* Compute the length of the block we need. */ - tbytes = sizeof(*tmp_tags) * num_tags; - rbytes = sizeof(*reach_next) * (tnfa->num_states + 1); - pbytes = sizeof(*reach_pos) * tnfa->num_states; - xbytes = sizeof(regoff_t) * num_tags; - total_bytes = - (sizeof(long) - 1) * 4 /* for alignment paddings */ - + (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes; - - /* Allocate the memory. */ - buf = calloc(total_bytes, 1); - if (buf == NULL) - return REG_ESPACE; - - /* Get the various pointers within tmp_buf (properly aligned). */ - tmp_tags = (void *)buf; - tmp_buf = buf + tbytes; - tmp_buf += ALIGN(tmp_buf, long); - reach_next = (void *)tmp_buf; - tmp_buf += rbytes; - tmp_buf += ALIGN(tmp_buf, long); - reach = (void *)tmp_buf; - tmp_buf += rbytes; - tmp_buf += ALIGN(tmp_buf, long); - reach_pos = (void *)tmp_buf; - tmp_buf += pbytes; - tmp_buf += ALIGN(tmp_buf, long); - for (i = 0; i < tnfa->num_states; i++) - { - reach[i].tags = (void *)tmp_buf; - tmp_buf += xbytes; - reach_next[i].tags = (void *)tmp_buf; - tmp_buf += xbytes; - } - } - - for (i = 0; i < tnfa->num_states; i++) - reach_pos[i].pos = -1; - - GET_NEXT_WCHAR(); - pos = 0; - - reach_next_i = reach_next; - while (1) - { - /* If no match found yet, add the initial states to `reach_next'. */ - if (match_eo < 0) - { - trans_i = tnfa->initial; - while (trans_i->state != NULL) - { - if (reach_pos[trans_i->state_id].pos < pos) - { - if (trans_i->assertions - && CHECK_ASSERTIONS(trans_i->assertions)) - { - trans_i++; - continue; - } - - reach_next_i->state = trans_i->state; - for (i = 0; i < num_tags; i++) - reach_next_i->tags[i] = -1; - tag_i = trans_i->tags; - if (tag_i) - while (*tag_i >= 0) - { - if (*tag_i < num_tags) - reach_next_i->tags[*tag_i] = pos; - tag_i++; - } - if (reach_next_i->state == tnfa->final) - { - match_eo = pos; - new_match = 1; - for (i = 0; i < num_tags; i++) - match_tags[i] = reach_next_i->tags[i]; - } - reach_pos[trans_i->state_id].pos = pos; - reach_pos[trans_i->state_id].tags = &reach_next_i->tags; - reach_next_i++; - } - trans_i++; - } - reach_next_i->state = NULL; - } - else - { - if (num_tags == 0 || reach_next_i == reach_next) - /* We have found a match. */ - break; - } - - /* Check for end of string. */ - if (!next_c) break; - - GET_NEXT_WCHAR(); - - /* Swap `reach' and `reach_next'. */ - reach_i = reach; - reach = reach_next; - reach_next = reach_i; - - /* For each state in `reach', weed out states that don't fulfill the - minimal matching conditions. */ - if (tnfa->num_minimals && new_match) - { - new_match = 0; - reach_next_i = reach_next; - for (reach_i = reach; reach_i->state; reach_i++) - { - int skip = 0; - for (i = 0; tnfa->minimal_tags[i] >= 0; i += 2) - { - int end = tnfa->minimal_tags[i]; - int start = tnfa->minimal_tags[i + 1]; - if (end >= num_tags) - { - skip = 1; - break; - } - else if (reach_i->tags[start] == match_tags[start] - && reach_i->tags[end] < match_tags[end]) - { - skip = 1; - break; - } - } - if (!skip) - { - reach_next_i->state = reach_i->state; - tmp_iptr = reach_next_i->tags; - reach_next_i->tags = reach_i->tags; - reach_i->tags = tmp_iptr; - reach_next_i++; - } - } - reach_next_i->state = NULL; - - /* Swap `reach' and `reach_next'. */ - reach_i = reach; - reach = reach_next; - reach_next = reach_i; - } - - /* For each state in `reach' see if there is a transition leaving with - the current input symbol to a state not yet in `reach_next', and - add the destination states to `reach_next'. */ - reach_next_i = reach_next; - for (reach_i = reach; reach_i->state; reach_i++) - { - for (trans_i = reach_i->state; trans_i->state; trans_i++) - { - /* Does this transition match the input symbol? */ - if (trans_i->code_min <= (tre_cint_t)prev_c && - trans_i->code_max >= (tre_cint_t)prev_c) - { - if (trans_i->assertions - && (CHECK_ASSERTIONS(trans_i->assertions) - || CHECK_CHAR_CLASSES(trans_i, tnfa, eflags))) - { - continue; - } - - /* Compute the tags after this transition. */ - for (i = 0; i < num_tags; i++) - tmp_tags[i] = reach_i->tags[i]; - tag_i = trans_i->tags; - if (tag_i != NULL) - while (*tag_i >= 0) - { - if (*tag_i < num_tags) - tmp_tags[*tag_i] = pos; - tag_i++; - } - - if (reach_pos[trans_i->state_id].pos < pos) - { - /* Found an unvisited node. */ - reach_next_i->state = trans_i->state; - tmp_iptr = reach_next_i->tags; - reach_next_i->tags = tmp_tags; - tmp_tags = tmp_iptr; - reach_pos[trans_i->state_id].pos = pos; - reach_pos[trans_i->state_id].tags = &reach_next_i->tags; - - if (reach_next_i->state == tnfa->final - && (match_eo == -1 - || (num_tags > 0 - && reach_next_i->tags[0] <= match_tags[0]))) - { - match_eo = pos; - new_match = 1; - for (i = 0; i < num_tags; i++) - match_tags[i] = reach_next_i->tags[i]; - } - reach_next_i++; - - } - else - { - assert(reach_pos[trans_i->state_id].pos == pos); - /* Another path has also reached this state. We choose - the winner by examining the tag values for both - paths. */ - if (tre_tag_order(num_tags, tnfa->tag_directions, - tmp_tags, - *reach_pos[trans_i->state_id].tags)) - { - /* The new path wins. */ - tmp_iptr = *reach_pos[trans_i->state_id].tags; - *reach_pos[trans_i->state_id].tags = tmp_tags; - if (trans_i->state == tnfa->final) - { - match_eo = pos; - new_match = 1; - for (i = 0; i < num_tags; i++) - match_tags[i] = tmp_tags[i]; - } - tmp_tags = tmp_iptr; - } - } - } - } - } - reach_next_i->state = NULL; - } - - *match_end_ofs = match_eo; - ret = match_eo >= 0 ? REG_OK : REG_NOMATCH; -error_exit: - xfree(buf); - return ret; -} - - - -/*********************************************************************** - from tre-match-backtrack.c -***********************************************************************/ - -/* - This matcher is for regexps that use back referencing. Regexp matching - with back referencing is an NP-complete problem on the number of back - references. The easiest way to match them is to use a backtracking - routine which basically goes through all possible paths in the TNFA - and chooses the one which results in the best (leftmost and longest) - match. This can be spectacularly expensive and may run out of stack - space, but there really is no better known generic algorithm. Quoting - Henry Spencer from comp.compilers: - - - POSIX.2 REs require longest match, which is really exciting to - implement since the obsolete ("basic") variant also includes - \. I haven't found a better way of tackling this than doing - a preliminary match using a DFA (or simulation) on a modified RE - that just replicates subREs for \, and then doing a - backtracking match to determine whether the subRE matches were - right. This can be rather slow, but I console myself with the - thought that people who use \ deserve very slow execution. - (Pun unintentional but very appropriate.) - -*/ - -typedef struct { - regoff_t pos; - const char *str_byte; - tre_tnfa_transition_t *state; - int state_id; - int next_c; - regoff_t *tags; -#ifdef TRE_MBSTATE - mbstate_t mbstate; -#endif /* TRE_MBSTATE */ -} tre_backtrack_item_t; - -typedef struct tre_backtrack_struct { - tre_backtrack_item_t item; - struct tre_backtrack_struct *prev; - struct tre_backtrack_struct *next; -} *tre_backtrack_t; - -#ifdef TRE_MBSTATE -#define BT_STACK_MBSTATE_IN stack->item.mbstate = (mbstate) -#define BT_STACK_MBSTATE_OUT (mbstate) = stack->item.mbstate -#else /* !TRE_MBSTATE */ -#define BT_STACK_MBSTATE_IN -#define BT_STACK_MBSTATE_OUT -#endif /* !TRE_MBSTATE */ - -#define tre_bt_mem_new tre_mem_new -#define tre_bt_mem_alloc tre_mem_alloc -#define tre_bt_mem_destroy tre_mem_destroy - - -#define BT_STACK_PUSH(_pos, _str_byte, _str_wide, _state, _state_id, _next_c, _tags, _mbstate) \ - do \ - { \ - int i; \ - if (!stack->next) \ - { \ - tre_backtrack_t s; \ - s = tre_bt_mem_alloc(mem, sizeof(*s)); \ - if (!s) \ - { \ - tre_bt_mem_destroy(mem); \ - if (tags) \ - xfree(tags); \ - if (pmatch) \ - xfree(pmatch); \ - if (states_seen) \ - xfree(states_seen); \ - return REG_ESPACE; \ - } \ - s->prev = stack; \ - s->next = NULL; \ - s->item.tags = tre_bt_mem_alloc(mem, \ - sizeof(*tags) * tnfa->num_tags); \ - if (!s->item.tags) \ - { \ - tre_bt_mem_destroy(mem); \ - if (tags) \ - xfree(tags); \ - if (pmatch) \ - xfree(pmatch); \ - if (states_seen) \ - xfree(states_seen); \ - return REG_ESPACE; \ - } \ - stack->next = s; \ - stack = s; \ - } \ - else \ - stack = stack->next; \ - stack->item.pos = (_pos); \ - stack->item.str_byte = (_str_byte); \ - stack->item.state = (_state); \ - stack->item.state_id = (_state_id); \ - stack->item.next_c = (_next_c); \ - for (i = 0; i < tnfa->num_tags; i++) \ - stack->item.tags[i] = (_tags)[i]; \ - BT_STACK_MBSTATE_IN; \ - } \ - while (0) - -#define BT_STACK_POP() \ - do \ - { \ - int i; \ - assert(stack->prev); \ - pos = stack->item.pos; \ - str_byte = stack->item.str_byte; \ - state = stack->item.state; \ - next_c = stack->item.next_c; \ - for (i = 0; i < tnfa->num_tags; i++) \ - tags[i] = stack->item.tags[i]; \ - BT_STACK_MBSTATE_OUT; \ - stack = stack->prev; \ - } \ - while (0) - -#undef MIN -#define MIN(a, b) ((a) <= (b) ? (a) : (b)) - -static reg_errcode_t -tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string, - regoff_t *match_tags, int eflags, regoff_t *match_end_ofs) -{ - /* State variables required by GET_NEXT_WCHAR. */ - tre_char_t prev_c = 0, next_c = 0; - const char *str_byte = string; - regoff_t pos = 0; - regoff_t pos_add_next = 1; -#ifdef TRE_MBSTATE - mbstate_t mbstate; -#endif /* TRE_MBSTATE */ - int reg_notbol = eflags & REG_NOTBOL; - int reg_noteol = eflags & REG_NOTEOL; - int reg_newline = tnfa->cflags & REG_NEWLINE; - - /* These are used to remember the necessary values of the above - variables to return to the position where the current search - started from. */ - int next_c_start; - const char *str_byte_start; - regoff_t pos_start = -1; -#ifdef TRE_MBSTATE - mbstate_t mbstate_start; -#endif /* TRE_MBSTATE */ - - /* End offset of best match so far, or -1 if no match found yet. */ - regoff_t match_eo = -1; - /* Tag arrays. */ - int *next_tags; - regoff_t *tags = NULL; - /* Current TNFA state. */ - tre_tnfa_transition_t *state; - int *states_seen = NULL; - - /* Memory allocator to for allocating the backtracking stack. */ - tre_mem_t mem = tre_bt_mem_new(); - - /* The backtracking stack. */ - tre_backtrack_t stack; - - tre_tnfa_transition_t *trans_i; - regmatch_t *pmatch = NULL; - int ret; - -#ifdef TRE_MBSTATE - memset(&mbstate, '\0', sizeof(mbstate)); -#endif /* TRE_MBSTATE */ - - if (!mem) - return REG_ESPACE; - stack = tre_bt_mem_alloc(mem, sizeof(*stack)); - if (!stack) - { - ret = REG_ESPACE; - goto error_exit; - } - stack->prev = NULL; - stack->next = NULL; - - if (tnfa->num_tags) - { - tags = xmalloc(sizeof(*tags) * tnfa->num_tags); - if (!tags) - { - ret = REG_ESPACE; - goto error_exit; - } - } - if (tnfa->num_submatches) - { - pmatch = xmalloc(sizeof(*pmatch) * tnfa->num_submatches); - if (!pmatch) - { - ret = REG_ESPACE; - goto error_exit; - } - } - if (tnfa->num_states) - { - states_seen = xmalloc(sizeof(*states_seen) * tnfa->num_states); - if (!states_seen) - { - ret = REG_ESPACE; - goto error_exit; - } - } - - retry: - { - int i; - for (i = 0; i < tnfa->num_tags; i++) - { - tags[i] = -1; - if (match_tags) - match_tags[i] = -1; - } - for (i = 0; i < tnfa->num_states; i++) - states_seen[i] = 0; - } - - state = NULL; - pos = pos_start; - GET_NEXT_WCHAR(); - pos_start = pos; - next_c_start = next_c; - str_byte_start = str_byte; -#ifdef TRE_MBSTATE - mbstate_start = mbstate; -#endif /* TRE_MBSTATE */ - - /* Handle initial states. */ - next_tags = NULL; - for (trans_i = tnfa->initial; trans_i->state; trans_i++) - { - if (trans_i->assertions && CHECK_ASSERTIONS(trans_i->assertions)) - { - continue; - } - if (state == NULL) - { - /* Start from this state. */ - state = trans_i->state; - next_tags = trans_i->tags; - } - else - { - /* Backtrack to this state. */ - BT_STACK_PUSH(pos, str_byte, 0, trans_i->state, - trans_i->state_id, next_c, tags, mbstate); - { - int *tmp = trans_i->tags; - if (tmp) - while (*tmp >= 0) - stack->item.tags[*tmp++] = pos; - } - } - } - - if (next_tags) - for (; *next_tags >= 0; next_tags++) - tags[*next_tags] = pos; - - - if (state == NULL) - goto backtrack; - - while (1) - { - tre_tnfa_transition_t *next_state; - int empty_br_match; - - if (state == tnfa->final) - { - if (match_eo < pos - || (match_eo == pos - && match_tags - && tre_tag_order(tnfa->num_tags, tnfa->tag_directions, - tags, match_tags))) - { - int i; - /* This match wins the previous match. */ - match_eo = pos; - if (match_tags) - for (i = 0; i < tnfa->num_tags; i++) - match_tags[i] = tags[i]; - } - /* Our TNFAs never have transitions leaving from the final state, - so we jump right to backtracking. */ - goto backtrack; - } - - /* Go to the next character in the input string. */ - empty_br_match = 0; - trans_i = state; - if (trans_i->state && trans_i->assertions & ASSERT_BACKREF) - { - /* This is a back reference state. All transitions leaving from - this state have the same back reference "assertion". Instead - of reading the next character, we match the back reference. */ - regoff_t so, eo; - int bt = trans_i->u.backref; - regoff_t bt_len; - int result; - - /* Get the substring we need to match against. Remember to - turn off REG_NOSUB temporarily. */ - tre_fill_pmatch(bt + 1, pmatch, tnfa->cflags & ~REG_NOSUB, - tnfa, tags, pos); - so = pmatch[bt].rm_so; - eo = pmatch[bt].rm_eo; - bt_len = eo - so; - - result = strncmp((const char*)string + so, str_byte - 1, - (size_t)bt_len); - - if (result == 0) - { - /* Back reference matched. Check for infinite loop. */ - if (bt_len == 0) - empty_br_match = 1; - if (empty_br_match && states_seen[trans_i->state_id]) - { - goto backtrack; - } - - states_seen[trans_i->state_id] = empty_br_match; - - /* Advance in input string and resync `prev_c', `next_c' - and pos. */ - str_byte += bt_len - 1; - pos += bt_len - 1; - GET_NEXT_WCHAR(); - } - else - { - goto backtrack; - } - } - else - { - /* Check for end of string. */ - if (next_c == L'\0') - goto backtrack; - - /* Read the next character. */ - GET_NEXT_WCHAR(); - } - - next_state = NULL; - for (trans_i = state; trans_i->state; trans_i++) - { - if (trans_i->code_min <= (tre_cint_t)prev_c - && trans_i->code_max >= (tre_cint_t)prev_c) - { - if (trans_i->assertions - && (CHECK_ASSERTIONS(trans_i->assertions) - || CHECK_CHAR_CLASSES(trans_i, tnfa, eflags))) - { - continue; - } - - if (next_state == NULL) - { - /* First matching transition. */ - next_state = trans_i->state; - next_tags = trans_i->tags; - } - else - { - /* Second matching transition. We may need to backtrack here - to take this transition instead of the first one, so we - push this transition in the backtracking stack so we can - jump back here if needed. */ - BT_STACK_PUSH(pos, str_byte, 0, trans_i->state, - trans_i->state_id, next_c, tags, mbstate); - { - int *tmp; - for (tmp = trans_i->tags; tmp && *tmp >= 0; tmp++) - stack->item.tags[*tmp] = pos; - } -#if 0 /* XXX - it's important not to look at all transitions here to keep - the stack small! */ - break; -#endif - } - } - } - - if (next_state != NULL) - { - /* Matching transitions were found. Take the first one. */ - state = next_state; - - /* Update the tag values. */ - if (next_tags) - while (*next_tags >= 0) - tags[*next_tags++] = pos; - } - else - { - backtrack: - /* A matching transition was not found. Try to backtrack. */ - if (stack->prev) - { - if (stack->item.state->assertions & ASSERT_BACKREF) - { - states_seen[stack->item.state_id] = 0; - } - - BT_STACK_POP(); - } - else if (match_eo < 0) - { - /* Try starting from a later position in the input string. */ - /* Check for end of string. */ - if (next_c == L'\0') - { - break; - } - next_c = next_c_start; -#ifdef TRE_MBSTATE - mbstate = mbstate_start; -#endif /* TRE_MBSTATE */ - str_byte = str_byte_start; - goto retry; - } - else - { - break; - } - } - } - - ret = match_eo >= 0 ? REG_OK : REG_NOMATCH; - *match_end_ofs = match_eo; - - error_exit: - tre_bt_mem_destroy(mem); -#ifndef TRE_USE_ALLOCA - if (tags) - xfree(tags); - if (pmatch) - xfree(pmatch); - if (states_seen) - xfree(states_seen); -#endif /* !TRE_USE_ALLOCA */ - - return ret; -} - -/*********************************************************************** - from regexec.c -***********************************************************************/ - -/* Fills the POSIX.2 regmatch_t array according to the TNFA tag and match - endpoint values. */ -static void -tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, - const tre_tnfa_t *tnfa, regoff_t *tags, regoff_t match_eo) -{ - tre_submatch_data_t *submatch_data; - unsigned int i, j; - int *parents; - - i = 0; - if (match_eo >= 0 && !(cflags & REG_NOSUB)) - { - /* Construct submatch offsets from the tags. */ - submatch_data = tnfa->submatch_data; - while (i < tnfa->num_submatches && i < nmatch) - { - if (submatch_data[i].so_tag == tnfa->end_tag) - pmatch[i].rm_so = match_eo; - else - pmatch[i].rm_so = tags[submatch_data[i].so_tag]; - - if (submatch_data[i].eo_tag == tnfa->end_tag) - pmatch[i].rm_eo = match_eo; - else - pmatch[i].rm_eo = tags[submatch_data[i].eo_tag]; - - /* If either of the endpoints were not used, this submatch - was not part of the match. */ - if (pmatch[i].rm_so == -1 || pmatch[i].rm_eo == -1) - pmatch[i].rm_so = pmatch[i].rm_eo = -1; - - i++; - } - /* Reset all submatches that are not within all of their parent - submatches. */ - i = 0; - while (i < tnfa->num_submatches && i < nmatch) - { - if (pmatch[i].rm_eo == -1) - assert(pmatch[i].rm_so == -1); - assert(pmatch[i].rm_so <= pmatch[i].rm_eo); - - parents = submatch_data[i].parents; - if (parents != NULL) - for (j = 0; parents[j] >= 0; j++) - { - if (pmatch[i].rm_so < pmatch[parents[j]].rm_so - || pmatch[i].rm_eo > pmatch[parents[j]].rm_eo) - pmatch[i].rm_so = pmatch[i].rm_eo = -1; - } - i++; - } - } - - while (i < nmatch) - { - pmatch[i].rm_so = -1; - pmatch[i].rm_eo = -1; - i++; - } -} - - -/* - Wrapper functions for POSIX compatible regexp matching. -*/ - -int -regexec(const regex_t *restrict preg, const char *restrict string, - size_t nmatch, regmatch_t pmatch[restrict], int eflags) -{ - tre_tnfa_t *tnfa = (void *)preg->TRE_REGEX_T_FIELD; - reg_errcode_t status; - regoff_t *tags = NULL, eo; - if (tnfa->cflags & REG_NOSUB) nmatch = 0; - if (tnfa->num_tags > 0 && nmatch > 0) - { - tags = xmalloc(sizeof(*tags) * tnfa->num_tags); - if (tags == NULL) - return REG_ESPACE; - } - - /* Dispatch to the appropriate matcher. */ - if (tnfa->have_backrefs) - { - /* The regex has back references, use the backtracking matcher. */ - status = tre_tnfa_run_backtrack(tnfa, string, tags, eflags, &eo); - } - else - { - /* Exact matching, no back references, use the parallel matcher. */ - status = tre_tnfa_run_parallel(tnfa, string, tags, eflags, &eo); - } - - if (status == REG_OK) - /* A match was found, so fill the submatch registers. */ - tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo); - if (tags) - xfree(tags); - return status; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/regex/tre-mem.c b/lib/libc/wasi/libc-top-half/musl/src/regex/tre-mem.c deleted file mode 100644 index 86f809d45564ee3190be8d65aac328f97f2882b4..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/regex/tre-mem.c +++ /dev/null @@ -1,158 +0,0 @@ -/* - tre-mem.c - TRE memory allocator - - Copyright (c) 2001-2009 Ville Laurikari - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -/* - This memory allocator is for allocating small memory blocks efficiently - in terms of memory overhead and execution speed. The allocated blocks - cannot be freed individually, only all at once. There can be multiple - allocators, though. -*/ - -#include -#include - -#include "tre.h" - -/* - This memory allocator is for allocating small memory blocks efficiently - in terms of memory overhead and execution speed. The allocated blocks - cannot be freed individually, only all at once. There can be multiple - allocators, though. -*/ - -/* Returns a new memory allocator or NULL if out of memory. */ -tre_mem_t -tre_mem_new_impl(int provided, void *provided_block) -{ - tre_mem_t mem; - if (provided) - { - mem = provided_block; - memset(mem, 0, sizeof(*mem)); - } - else - mem = xcalloc(1, sizeof(*mem)); - if (mem == NULL) - return NULL; - return mem; -} - - -/* Frees the memory allocator and all memory allocated with it. */ -void -tre_mem_destroy(tre_mem_t mem) -{ - tre_list_t *tmp, *l = mem->blocks; - - while (l != NULL) - { - xfree(l->data); - tmp = l->next; - xfree(l); - l = tmp; - } - xfree(mem); -} - - -/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the - allocated block or NULL if an underlying malloc() failed. */ -void * -tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, - int zero, size_t size) -{ - void *ptr; - - if (mem->failed) - { - return NULL; - } - - if (mem->n < size) - { - /* We need more memory than is available in the current block. - Allocate a new block. */ - tre_list_t *l; - if (provided) - { - if (provided_block == NULL) - { - mem->failed = 1; - return NULL; - } - mem->ptr = provided_block; - mem->n = TRE_MEM_BLOCK_SIZE; - } - else - { - int block_size; - if (size * 8 > TRE_MEM_BLOCK_SIZE) - block_size = size * 8; - else - block_size = TRE_MEM_BLOCK_SIZE; - l = xmalloc(sizeof(*l)); - if (l == NULL) - { - mem->failed = 1; - return NULL; - } - l->data = xmalloc(block_size); - if (l->data == NULL) - { - xfree(l); - mem->failed = 1; - return NULL; - } - l->next = NULL; - if (mem->current != NULL) - mem->current->next = l; - if (mem->blocks == NULL) - mem->blocks = l; - mem->current = l; - mem->ptr = l->data; - mem->n = block_size; - } - } - - /* Make sure the next pointer will be aligned. */ - size += ALIGN(mem->ptr + size, long); - - /* Allocate from current block. */ - ptr = mem->ptr; - mem->ptr += size; - mem->n -= size; - - /* Set to zero if needed. */ - if (zero) - memset(ptr, 0, size); - - return ptr; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/regex/tre.h b/lib/libc/wasi/libc-top-half/musl/src/regex/tre.h deleted file mode 100644 index aed64f3e7e0f7dc5c6bf820daf57b29cc5c15c89..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/regex/tre.h +++ /dev/null @@ -1,233 +0,0 @@ -/* - tre-internal.h - TRE internal definitions - - Copyright (c) 2001-2009 Ville Laurikari - All rights reserved. - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - - 1. Redistributions of source code must retain the above copyright - notice, this list of conditions and the following disclaimer. - - 2. Redistributions in binary form must reproduce the above copyright - notice, this list of conditions and the following disclaimer in the - documentation and/or other materials provided with the distribution. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -*/ - -#include -#include -#include - -#undef TRE_MBSTATE - -#ifdef __wasilibc_unmodified_upstream // Allow NDEBUG to be predefined. -#define NDEBUG -#endif - -#define TRE_REGEX_T_FIELD __opaque -typedef int reg_errcode_t; - -typedef wchar_t tre_char_t; - -#define DPRINT(msg) do { } while(0) - -#define elementsof(x) ( sizeof(x) / sizeof(x[0]) ) - -#define tre_mbrtowc(pwc, s, n, ps) (mbtowc((pwc), (s), (n))) - -/* Wide characters. */ -typedef wint_t tre_cint_t; -#define TRE_CHAR_MAX 0x10ffff - -#define tre_isalnum iswalnum -#define tre_isalpha iswalpha -#define tre_isblank iswblank -#define tre_iscntrl iswcntrl -#define tre_isdigit iswdigit -#define tre_isgraph iswgraph -#define tre_islower iswlower -#define tre_isprint iswprint -#define tre_ispunct iswpunct -#define tre_isspace iswspace -#define tre_isupper iswupper -#define tre_isxdigit iswxdigit - -#define tre_tolower towlower -#define tre_toupper towupper -#define tre_strlen wcslen - -/* Use system provided iswctype() and wctype(). */ -typedef wctype_t tre_ctype_t; -#define tre_isctype iswctype -#define tre_ctype wctype - -/* Returns number of bytes to add to (char *)ptr to make it - properly aligned for the type. */ -#define ALIGN(ptr, type) \ - ((((long)ptr) % sizeof(type)) \ - ? (sizeof(type) - (((long)ptr) % sizeof(type))) \ - : 0) - -#undef MAX -#undef MIN -#define MAX(a, b) (((a) >= (b)) ? (a) : (b)) -#define MIN(a, b) (((a) <= (b)) ? (a) : (b)) - -/* TNFA transition type. A TNFA state is an array of transitions, - the terminator is a transition with NULL `state'. */ -typedef struct tnfa_transition tre_tnfa_transition_t; - -struct tnfa_transition { - /* Range of accepted characters. */ - tre_cint_t code_min; - tre_cint_t code_max; - /* Pointer to the destination state. */ - tre_tnfa_transition_t *state; - /* ID number of the destination state. */ - int state_id; - /* -1 terminated array of tags (or NULL). */ - int *tags; - /* Assertion bitmap. */ - int assertions; - /* Assertion parameters. */ - union { - /* Character class assertion. */ - tre_ctype_t class; - /* Back reference assertion. */ - int backref; - } u; - /* Negative character class assertions. */ - tre_ctype_t *neg_classes; -}; - - -/* Assertions. */ -#define ASSERT_AT_BOL 1 /* Beginning of line. */ -#define ASSERT_AT_EOL 2 /* End of line. */ -#define ASSERT_CHAR_CLASS 4 /* Character class in `class'. */ -#define ASSERT_CHAR_CLASS_NEG 8 /* Character classes in `neg_classes'. */ -#define ASSERT_AT_BOW 16 /* Beginning of word. */ -#define ASSERT_AT_EOW 32 /* End of word. */ -#define ASSERT_AT_WB 64 /* Word boundary. */ -#define ASSERT_AT_WB_NEG 128 /* Not a word boundary. */ -#define ASSERT_BACKREF 256 /* A back reference in `backref'. */ -#define ASSERT_LAST 256 - -/* Tag directions. */ -typedef enum { - TRE_TAG_MINIMIZE = 0, - TRE_TAG_MAXIMIZE = 1 -} tre_tag_direction_t; - -/* Instructions to compute submatch register values from tag values - after a successful match. */ -struct tre_submatch_data { - /* Tag that gives the value for rm_so (submatch start offset). */ - int so_tag; - /* Tag that gives the value for rm_eo (submatch end offset). */ - int eo_tag; - /* List of submatches this submatch is contained in. */ - int *parents; -}; - -typedef struct tre_submatch_data tre_submatch_data_t; - - -/* TNFA definition. */ -typedef struct tnfa tre_tnfa_t; - -struct tnfa { - tre_tnfa_transition_t *transitions; - unsigned int num_transitions; - tre_tnfa_transition_t *initial; - tre_tnfa_transition_t *final; - tre_submatch_data_t *submatch_data; - char *firstpos_chars; - int first_char; - unsigned int num_submatches; - tre_tag_direction_t *tag_directions; - int *minimal_tags; - int num_tags; - int num_minimals; - int end_tag; - int num_states; - int cflags; - int have_backrefs; - int have_approx; -}; - -/* from tre-mem.h: */ - -#define TRE_MEM_BLOCK_SIZE 1024 - -typedef struct tre_list { - void *data; - struct tre_list *next; -} tre_list_t; - -typedef struct tre_mem_struct { - tre_list_t *blocks; - tre_list_t *current; - char *ptr; - size_t n; - int failed; - void **provided; -} *tre_mem_t; - -#define tre_mem_new_impl __tre_mem_new_impl -#define tre_mem_alloc_impl __tre_mem_alloc_impl -#define tre_mem_destroy __tre_mem_destroy - -hidden tre_mem_t tre_mem_new_impl(int provided, void *provided_block); -hidden void *tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, - int zero, size_t size); - -/* Returns a new memory allocator or NULL if out of memory. */ -#define tre_mem_new() tre_mem_new_impl(0, NULL) - -/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the - allocated block or NULL if an underlying malloc() failed. */ -#define tre_mem_alloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 0, size) - -/* Allocates a block of `size' bytes from `mem'. Returns a pointer to the - allocated block or NULL if an underlying malloc() failed. The memory - is set to zero. */ -#define tre_mem_calloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 1, size) - -#ifdef TRE_USE_ALLOCA -/* alloca() versions. Like above, but memory is allocated with alloca() - instead of malloc(). */ - -#define tre_mem_newa() \ - tre_mem_new_impl(1, alloca(sizeof(struct tre_mem_struct))) - -#define tre_mem_alloca(mem, size) \ - ((mem)->n >= (size) \ - ? tre_mem_alloc_impl((mem), 1, NULL, 0, (size)) \ - : tre_mem_alloc_impl((mem), 1, alloca(TRE_MEM_BLOCK_SIZE), 0, (size))) -#endif /* TRE_USE_ALLOCA */ - - -/* Frees the memory allocator and all memory allocated with it. */ -hidden void tre_mem_destroy(tre_mem_t mem); - -#define xmalloc malloc -#define xcalloc calloc -#define xfree free -#define xrealloc realloc - diff --git a/lib/libc/wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c b/lib/libc/wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c deleted file mode 100644 index 24e4e336184444dbcd97ac58c9c5d5cb131f6656..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c +++ /dev/null @@ -1,83 +0,0 @@ -/* - * a runtime implementation for - * https://github.com/llvm/llvm-project/pull/84137 - * https://docs.google.com/document/d/1ZvTPT36K5jjiedF8MCXbEmYjULJjI723aOAks1IdLLg/edit - */ - -#include -#include - -/* - * function prototypes - */ -void __wasm_setjmp(void *env, uint32_t label, void *func_invocation_id); -uint32_t __wasm_setjmp_test(void *env, void *func_invocation_id); -void __wasm_longjmp(void *env, int val); - -/* - * jmp_buf should have large enough size and alignment to contain - * this structure. - */ -struct jmp_buf_impl { - void *func_invocation_id; - uint32_t label; - - /* - * this is a temorary storage used by the communication between - * __wasm_sjlj_longjmp and WebAssemblyLowerEmscriptenEHSjL-generated - * logic. - * ideally, this can be replaced with multivalue. - */ - struct arg { - void *env; - int val; - } arg; -}; - -void -__wasm_setjmp(void *env, uint32_t label, void *func_invocation_id) -{ - struct jmp_buf_impl *jb = env; - if (label == 0) { /* ABI contract */ - __builtin_trap(); - } - if (func_invocation_id == NULL) { /* sanity check */ - __builtin_trap(); - } - jb->func_invocation_id = func_invocation_id; - jb->label = label; -} - -uint32_t -__wasm_setjmp_test(void *env, void *func_invocation_id) -{ - struct jmp_buf_impl *jb = env; - if (jb->label == 0) { /* ABI contract */ - __builtin_trap(); - } - if (func_invocation_id == NULL) { /* sanity check */ - __builtin_trap(); - } - if (jb->func_invocation_id == func_invocation_id) { - return jb->label; - } - return 0; -} - -void -__wasm_longjmp(void *env, int val) -{ - struct jmp_buf_impl *jb = env; - struct arg *arg = &jb->arg; - /* - * C standard says: - * The longjmp function cannot cause the setjmp macro to return - * the value 0; if val is 0, the setjmp macro returns the value 1. - */ - if (val == 0) { - val = 1; - } - arg->env = env; - arg->val = val; - __builtin_wasm_throw(1, arg); /* 1 == C_LONGJMP */ -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stat/futimesat.c b/lib/libc/wasi/libc-top-half/musl/src/stat/futimesat.c deleted file mode 100644 index c29b2b790ffc14b12fea225e243bc375e9135008..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stat/futimesat.c +++ /dev/null @@ -1,31 +0,0 @@ -#define _GNU_SOURCE -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall -#include "syscall.h" -#endif - -int __futimesat(int dirfd, const char *pathname, const struct timeval times[2]) -{ - struct timespec ts[2]; - if (times) { - int i; - for (i=0; i<2; i++) { -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - if (times[i].tv_usec >= 1000000ULL) - return __syscall_ret(-EINVAL); -#else - if (times[i].tv_usec >= 1000000ULL) { - errno = EINVAL; - return -1; - } -#endif - ts[i].tv_sec = times[i].tv_sec; - ts[i].tv_nsec = times[i].tv_usec * 1000; - } - } - return utimensat(dirfd, pathname, times ? ts : 0, 0); -} - -weak_alias(__futimesat, futimesat); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__fdopen.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__fdopen.c deleted file mode 100644 index 5c8df495e3db5be3f2d14fa27eb22be823aea8e6..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__fdopen.c +++ /dev/null @@ -1,85 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include "libc.h" -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall -#else -#include <__function___isatty.h> -#endif - -FILE *__fdopen(int fd, const char *mode) -{ - FILE *f; -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - struct winsize wsz; -#endif - - /* Check for valid initial mode character */ - if (!strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - /* Allocate FILE+buffer or fail */ - if (!(f=malloc(sizeof *f + UNGET + BUFSIZ))) return 0; - - /* Zero-fill only the struct, not the buffer */ - memset(f, 0, sizeof *f); - - /* Impose mode restrictions */ - if (!strchr(mode, '+')) f->flags = (*mode == 'r') ? F_NOWR : F_NORD; - - /* Apply close-on-exec flag */ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - if (strchr(mode, 'e')) __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); -#else - if (strchr(mode, 'e')) fcntl(fd, F_SETFD, FD_CLOEXEC); -#endif - - /* Set append mode on fd if opened for append */ - if (*mode == 'a') { -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - int flags = __syscall(SYS_fcntl, fd, F_GETFL); -#else - int flags = fcntl(fd, F_GETFL); -#endif - if (!(flags & O_APPEND)) -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - __syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND); -#else - fcntl(fd, F_SETFL, flags | O_APPEND); -#endif - f->flags |= F_APP; - } - - f->fd = fd; - f->buf = (unsigned char *)f + sizeof *f + UNGET; - f->buf_size = BUFSIZ; - - /* Activate line buffered mode for terminals */ - f->lbf = EOF; -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - if (!(f->flags & F_NOWR) && !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz)) -#else - if (!(f->flags & F_NOWR) && __isatty(fd)) -#endif - f->lbf = '\n'; - - /* Initialize op ptrs. No problem if some are unneeded. */ - f->read = __stdio_read; - f->write = __stdio_write; - f->seek = __stdio_seek; - f->close = __stdio_close; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - if (!libc.threaded) f->lock = -1; -#endif - - /* Add new FILE to open file list */ - return __ofl_add(f); -} - -weak_alias(__fdopen, fdopen); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c deleted file mode 100644 index 192050b00606031afa188c76f99918ae09237625..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len) -{ - memset(f, 0, sizeof *f); - -#ifdef __wasilibc_unmodified_upstream // WASI has no sys_open - f->fd = sys_open(filename, O_RDONLY|O_CLOEXEC); -#else - f->fd = open(filename, O_RDONLY|O_CLOEXEC); -#endif - if (f->fd < 0) return 0; -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - __syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC); -#else - fcntl(f->fd, F_SETFD, FD_CLOEXEC); -#endif - - f->flags = F_NOWR | F_PERM; - f->buf = buf + UNGET; - f->buf_size = len - UNGET; - f->read = __stdio_read; - f->seek = __stdio_seek; - f->close = __stdio_close; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - f->lock = -1; -#endif - - return f; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_close.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_close.c deleted file mode 100644 index 0d7c91e6083ec11e578fd04ebcfba2dd84d93a00..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_close.c +++ /dev/null @@ -1,26 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall -#else -#include -#endif -#include "stdio_impl.h" -#include "aio_impl.h" - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -static int dummy(int fd) -{ - return fd; -} - -weak_alias(dummy, __aio_close); -#else -#define __aio_close(fd) (fd) -#endif - -int __stdio_close(FILE *f) -{ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - return syscall(SYS_close, __aio_close(f->fd)); -#else - return close(__aio_close(f->fd)); -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_read.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_read.c deleted file mode 100644 index d7011881424650e7dda9b75fa149eb3a4b96a4a3..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_read.c +++ /dev/null @@ -1,33 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall -#else -#include -#endif -#include "stdio_impl.h" -#include - -size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) -{ - struct iovec iov[2] = { - { .iov_base = buf, .iov_len = len - !!f->buf_size }, - { .iov_base = f->buf, .iov_len = f->buf_size } - }; - ssize_t cnt; - -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - cnt = iov[0].iov_len ? syscall(SYS_readv, f->fd, iov, 2) - : syscall(SYS_read, f->fd, iov[1].iov_base, iov[1].iov_len); -#else - cnt = iov[0].iov_len ? readv(f->fd, iov, 2) - : read(f->fd, iov[1].iov_base, iov[1].iov_len); -#endif - if (cnt <= 0) { - f->flags |= cnt ? F_ERR : F_EOF; - return 0; - } - if (cnt <= iov[0].iov_len) return cnt; - cnt -= iov[0].iov_len; - f->rpos = f->buf; - f->rend = f->buf + cnt; - if (f->buf_size) buf[len-1] = *f->rpos++; - return len; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_seek.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_seek.c deleted file mode 100644 index 782c6784224b336fb7f2a75c632596ca92643636..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_seek.c +++ /dev/null @@ -1,11 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall -#else -#include -#endif -#include "stdio_impl.h" -#include "stdio_impl.h" - -off_t __stdio_seek(FILE *f, off_t off, int whence) -{ - return __lseek(f->fd, off, whence); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_write.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_write.c deleted file mode 100644 index 753730493f4859678df106d9b775ab306bab2106..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_write.c +++ /dev/null @@ -1,38 +0,0 @@ -#include "stdio_impl.h" -#include - -size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) -{ - struct iovec iovs[2] = { - { .iov_base = f->wbase, .iov_len = f->wpos-f->wbase }, - { .iov_base = (void *)buf, .iov_len = len } - }; - struct iovec *iov = iovs; - size_t rem = iov[0].iov_len + iov[1].iov_len; - int iovcnt = 2; - ssize_t cnt; - for (;;) { -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - cnt = syscall(SYS_writev, f->fd, iov, iovcnt); -#else - cnt = writev(f->fd, iov, iovcnt); -#endif - if (cnt == rem) { - f->wend = f->buf + f->buf_size; - f->wpos = f->wbase = f->buf; - return len; - } - if (cnt < 0) { - f->wpos = f->wbase = f->wend = 0; - f->flags |= F_ERR; - return iovcnt == 2 ? 0 : len-iov[0].iov_len; - } - rem -= cnt; - if (cnt > iov[0].iov_len) { - cnt -= iov[0].iov_len; - iov++; iovcnt--; - } - iov[0].iov_base = (char *)iov[0].iov_base + cnt; - iov[0].iov_len -= cnt; - } -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdout_write.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdout_write.c deleted file mode 100644 index 8190ec5b4c1fcb5c963ef06a96a2dfa37d89f3c3..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/__stdout_write.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "stdio_impl.h" -#include -#ifdef __wasilibc_unmodified_upstream // use isatty rather than manual ioctl -#else -#include <__function___isatty.h> -#endif - -size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len) -{ -#ifdef __wasilibc_unmodified_upstream // use isatty rather than manual ioctl - struct winsize wsz; -#endif - f->write = __stdio_write; -#ifdef __wasilibc_unmodified_upstream // use isatty rather than manual ioctl - if (!(f->flags & F_SVB) && __syscall(SYS_ioctl, f->fd, TIOCGWINSZ, &wsz)) -#else - if (!(f->flags & F_SVB) && !__isatty(f->fd)) -#endif - f->lbf = -1; - return __stdio_write(f, buf, len); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fgetc.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fgetc.c deleted file mode 100644 index 2578afccd28ac8f75e8bb470e99ca74015cb75f2..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fgetc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "getc.h" - -int fgetc(FILE *f) -{ - return do_getc(f); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fgetpos.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fgetpos.c deleted file mode 100644 index 50813d2c50eeabac931539e3b72aa97a412fb31e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fgetpos.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "stdio_impl.h" - -int fgetpos(FILE *restrict f, fpos_t *restrict pos) -{ - off_t off = __ftello(f); - if (off < 0) return -1; - *(long long *)pos = off; - return 0; -} - -weak_alias(fgetpos, fgetpos64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fmemopen.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fmemopen.c deleted file mode 100644 index 3ee57b9ea5b4937449f9968df89164f84f26a205..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fmemopen.c +++ /dev/null @@ -1,137 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include "libc.h" - -struct cookie { - size_t pos, len, size; - unsigned char *buf; - int mode; -}; - -struct mem_FILE { - FILE f; - struct cookie c; - unsigned char buf[UNGET+BUFSIZ], buf2[]; -}; - -static off_t mseek(FILE *f, off_t off, int whence) -{ - ssize_t base; - struct cookie *c = f->cookie; - if (whence>2U) { -fail: - errno = EINVAL; - return -1; - } -#ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values. - base = (size_t [3]){0, c->pos, c->len}[whence]; -#else - base = (size_t [3]) { - [SEEK_SET] = 0, - [SEEK_CUR] = c->pos, - [SEEK_END] = c->len - }[whence]; -#endif - if (off < -base || off > (ssize_t)c->size-base) goto fail; - return c->pos = base+off; -} - -static size_t mread(FILE *f, unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t rem = c->len - c->pos; - if (c->pos > c->len) rem = 0; - if (len > rem) { - len = rem; - f->flags |= F_EOF; - } - memcpy(buf, c->buf+c->pos, len); - c->pos += len; - rem -= len; - if (rem > f->buf_size) rem = f->buf_size; - f->rpos = f->buf; - f->rend = f->buf + rem; - memcpy(f->rpos, c->buf+c->pos, rem); - c->pos += rem; - return len; -} - -static size_t mwrite(FILE *f, const unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t rem; - size_t len2 = f->wpos - f->wbase; - if (len2) { - f->wpos = f->wbase; - if (mwrite(f, f->wpos, len2) < len2) return 0; - } - if (c->mode == 'a') c->pos = c->len; - rem = c->size - c->pos; - if (len > rem) len = rem; - memcpy(c->buf+c->pos, buf, len); - c->pos += len; - if (c->pos > c->len) { - c->len = c->pos; - if (c->len < c->size) c->buf[c->len] = 0; - else if ((f->flags&F_NORD) && c->size) c->buf[c->size-1] = 0; - } - return len; -} - -static int mclose(FILE *m) -{ - return 0; -} - -FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) -{ - struct mem_FILE *f; - int plus = !!strchr(mode, '+'); - - if (!strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - if (!buf && size > PTRDIFF_MAX) { - errno = ENOMEM; - return 0; - } - - f = malloc(sizeof *f + (buf?0:size)); - if (!f) return 0; - memset(f, 0, offsetof(struct mem_FILE, buf)); - f->f.cookie = &f->c; - f->f.fd = -1; - f->f.lbf = EOF; - f->f.buf = f->buf + UNGET; - f->f.buf_size = sizeof f->buf - UNGET; - if (!buf) { - buf = f->buf2; - memset(buf, 0, size); - } - - f->c.buf = buf; - f->c.size = size; - f->c.mode = *mode; - - if (!plus) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD; - if (*mode == 'r') f->c.len = size; - else if (*mode == 'a') f->c.len = f->c.pos = strnlen(buf, size); - else if (plus) *f->c.buf = 0; - - f->f.read = mread; - f->f.write = mwrite; - f->f.seek = mseek; - f->f.close = mclose; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - if (!libc.threaded) f->f.lock = -1; -#endif - - return __ofl_add(&f->f); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fopen.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fopen.c deleted file mode 100644 index 670f43892b42a445123c4b34b4fcb1a572e4e32d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fopen.c +++ /dev/null @@ -1,51 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall -#else -#include -#include -#endif -#include "stdio_impl.h" -#include -#include -#include - -FILE *fopen(const char *restrict filename, const char *restrict mode) -{ - FILE *f; - int fd; - int flags; - - /* Check for valid initial mode character */ - if (!strchr("rwa", *mode)) { - errno = EINVAL; - return 0; - } - - /* Compute the flags to pass to open() */ - flags = __fmodeflags(mode); - -#ifdef __wasilibc_unmodified_upstream // WASI has no sys_open - fd = sys_open(filename, flags, 0666); -#else - // WASI libc ignores the mode parameter anyway, so skip the varargs. - fd = __wasilibc_open_nomode(filename, flags); -#endif - if (fd < 0) return 0; -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - if (flags & O_CLOEXEC) - __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); -#else - /* Avoid __syscall, but also, FD_CLOEXEC is not supported in WASI. */ -#endif - - f = __fdopen(fd, mode); - if (f) return f; - -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - __syscall(SYS_close, fd); -#else - close(fd); -#endif - return 0; -} - -weak_alias(fopen, fopen64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fputc.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fputc.c deleted file mode 100644 index f364ed38ba7471d3ca80f2d21560737eca642042..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fputc.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "putc.h" - -int fputc(int c, FILE *f) -{ - return do_putc(c, f); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/freopen.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/freopen.c deleted file mode 100644 index 7c0ef085d9e0ac23d2bae19727eda1989d9cc649..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/freopen.c +++ /dev/null @@ -1,82 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall, dup -#include "stdio_impl.h" -#else -#include -#endif -#include -#include -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall, dup -#else -// Move this below fcntl.h and unistd.h so that the __syscall macro doesn't -// cause trouble. -#include "stdio_impl.h" -#endif - -/* The basic idea of this implementation is to open a new FILE, - * hack the necessary parts of the new FILE into the old one, then - * close the new FILE. */ - -/* Locking IS necessary because another thread may provably hold the - * lock, via flockfile or otherwise, when freopen is called, and in that - * case, freopen cannot act until the lock is released. */ - -FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *restrict f) -{ - int fl = __fmodeflags(mode); - FILE *f2; - - FLOCK(f); - - fflush(f); - - if (!filename) { - if (fl&O_CLOEXEC) -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - __syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC); -#else - fcntl(f->fd, F_SETFD, FD_CLOEXEC); -#endif - fl &= ~(O_CREAT|O_EXCL|O_CLOEXEC); -#ifdef __wasilibc_unmodified_upstream // WASI has no syscall - if (syscall(SYS_fcntl, f->fd, F_SETFL, fl) < 0) -#else - if (fcntl(f->fd, F_SETFL, fl) < 0) -#endif - goto fail; - } else { - f2 = fopen(filename, mode); - if (!f2) goto fail; - if (f2->fd == f->fd) f2->fd = -1; /* avoid closing in fclose */ -#ifdef __wasilibc_unmodified_upstream // WASI has no dup - else if (__dup3(f2->fd, f->fd, fl&O_CLOEXEC)<0) goto fail2; -#else - // WASI doesn't have dup3, but does have a way to renumber - // an existing file descriptor. - else { - if (__wasilibc_fd_renumber(f2->fd, f->fd)<0) goto fail2; - f2->fd = -1; /* avoid closing in fclose */ - } -#endif - - f->flags = (f->flags & F_PERM) | f2->flags; - f->read = f2->read; - f->write = f2->write; - f->seek = f2->seek; - f->close = f2->close; - - fclose(f2); - } - - f->mode = 0; - f->locale = 0; - FUNLOCK(f); - return f; - -fail2: - fclose(f2); -fail: - fclose(f); - return NULL; -} - -weak_alias(freopen, freopen64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fseek.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fseek.c deleted file mode 100644 index c07f7e952642ba3bef35f4eb8a7865e6a8d1b5dc..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fseek.c +++ /dev/null @@ -1,50 +0,0 @@ -#include "stdio_impl.h" -#include - -int __fseeko_unlocked(FILE *f, off_t off, int whence) -{ - /* Fail immediately for invalid whence argument. */ - if (whence != SEEK_CUR && whence != SEEK_SET && whence != SEEK_END) { - errno = EINVAL; - return -1; - } - - /* Adjust relative offset for unread data in buffer, if any. */ - if (whence == SEEK_CUR && f->rend) off -= f->rend - f->rpos; - - /* Flush write buffer, and report error on failure. */ - if (f->wpos != f->wbase) { - f->write(f, 0, 0); - if (!f->wpos) return -1; - } - - /* Leave writing mode */ - f->wpos = f->wbase = f->wend = 0; - - /* Perform the underlying seek. */ - if (f->seek(f, off, whence) < 0) return -1; - - /* If seek succeeded, file is seekable and we discard read buffer. */ - f->rpos = f->rend = 0; - f->flags &= ~F_EOF; - - return 0; -} - -int __fseeko(FILE *f, off_t off, int whence) -{ - int result; - FLOCK(f); - result = __fseeko_unlocked(f, off, whence); - FUNLOCK(f); - return result; -} - -int fseek(FILE *f, long off, int whence) -{ - return __fseeko(f, off, whence); -} - -weak_alias(__fseeko, fseeko); - -weak_alias(fseeko, fseeko64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/fsetpos.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/fsetpos.c deleted file mode 100644 index 77ab8d820603401a71804a85cc4d005eaa22ad60..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/fsetpos.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "stdio_impl.h" - -int fsetpos(FILE *f, const fpos_t *pos) -{ - return __fseeko(f, *(const long long *)pos, SEEK_SET); -} - -weak_alias(fsetpos, fsetpos64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/ftell.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/ftell.c deleted file mode 100644 index 1a2afbbce3a62ef87f90c7093d11bd8f5369da84..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/ftell.c +++ /dev/null @@ -1,41 +0,0 @@ -#include "stdio_impl.h" -#include -#include - -off_t __ftello_unlocked(FILE *f) -{ - off_t pos = f->seek(f, 0, - (f->flags & F_APP) && f->wpos != f->wbase - ? SEEK_END : SEEK_CUR); - if (pos < 0) return pos; - - /* Adjust for data in buffer. */ - if (f->rend) - pos += f->rpos - f->rend; - else if (f->wbase) - pos += f->wpos - f->wbase; - return pos; -} - -off_t __ftello(FILE *f) -{ - off_t pos; - FLOCK(f); - pos = __ftello_unlocked(f); - FUNLOCK(f); - return pos; -} - -long ftell(FILE *f) -{ - off_t pos = __ftello(f); - if (pos > LONG_MAX) { - errno = EOVERFLOW; - return -1; - } - return pos; -} - -weak_alias(__ftello, ftello); - -weak_alias(ftello, ftello64); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/getc.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/getc.c deleted file mode 100644 index 8409fc2343fc9060da320ccefe93b394b7801a2b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/getc.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "getc.h" - -int getc(FILE *f) -{ - return do_getc(f); -} - -weak_alias(getc, _IO_getc); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/getc.h b/lib/libc/wasi/libc-top-half/musl/src/stdio/getc.h deleted file mode 100644 index e62e3f0dab3b55d1524ec3d8dce101b381c34226..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/getc.h +++ /dev/null @@ -1,29 +0,0 @@ -#include "stdio_impl.h" -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include "pthread_impl.h" - -#ifdef __GNUC__ -__attribute__((__noinline__)) -#endif -static int locking_getc(FILE *f) -{ - if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f); - int c = getc_unlocked(f); - if (a_swap(&f->lock, 0) & MAYBE_WAITERS) - __wake(&f->lock, 1, 1); - return c; -} -#endif - -static inline int do_getc(FILE *f) -{ -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - int l = f->lock; - if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid) - return getc_unlocked(f); - return locking_getc(f); -#else - // With no threads, locking is unnecessary. - return getc_unlocked(f); -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/getchar.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/getchar.c deleted file mode 100644 index df395ca9548dc3591469e0676c334c3e362aba2d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/getchar.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "getc.h" - -int getchar(void) -{ - return do_getc(stdin); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/ofl.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/ofl.c deleted file mode 100644 index 33a8aa50bcec1a6f9632b0d12cff37f33e208e7b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/ofl.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "stdio_impl.h" -#include "lock.h" -#include "fork_impl.h" - -static FILE *ofl_head; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -static volatile int ofl_lock[1]; -volatile int *const __stdio_ofl_lockptr = ofl_lock; -#endif - -FILE **__ofl_lock() -{ - LOCK(ofl_lock); - return &ofl_head; -} - -void __ofl_unlock() -{ - UNLOCK(ofl_lock); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/open_memstream.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/open_memstream.c deleted file mode 100644 index aa502206515986ef85eb99bb4dac715965517ace..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/open_memstream.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include "libc.h" - -struct cookie { - char **bufp; - size_t *sizep; - size_t pos; - char *buf; - size_t len; - size_t space; -}; - -struct ms_FILE { - FILE f; - struct cookie c; - unsigned char buf[BUFSIZ]; -}; - -static off_t ms_seek(FILE *f, off_t off, int whence) -{ - ssize_t base; - struct cookie *c = f->cookie; - if (whence>2U) { -fail: - errno = EINVAL; - return -1; - } -#ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values. - base = (size_t [3]){0, c->pos, c->len}[whence]; -#else - base = (size_t [3]) { - [SEEK_SET] = 0, - [SEEK_CUR] = c->pos, - [SEEK_END] = c->len - }[whence]; -#endif - if (off < -base || off > SSIZE_MAX-base) goto fail; - return c->pos = base+off; -} - -static size_t ms_write(FILE *f, const unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t len2 = f->wpos - f->wbase; - char *newbuf; - if (len2) { - f->wpos = f->wbase; - if (ms_write(f, f->wbase, len2) < len2) return 0; - } - if (len + c->pos >= c->space) { - len2 = 2*c->space+1 | c->pos+len+1; - newbuf = realloc(c->buf, len2); - if (!newbuf) return 0; - *c->bufp = c->buf = newbuf; - memset(c->buf + c->space, 0, len2 - c->space); - c->space = len2; - } - memcpy(c->buf+c->pos, buf, len); - c->pos += len; - if (c->pos >= c->len) c->len = c->pos; - *c->sizep = c->pos; - return len; -} - -static int ms_close(FILE *f) -{ - return 0; -} - -FILE *open_memstream(char **bufp, size_t *sizep) -{ - struct ms_FILE *f; - char *buf; - - if (!(f=malloc(sizeof *f))) return 0; - if (!(buf=malloc(sizeof *buf))) { - free(f); - return 0; - } - memset(&f->f, 0, sizeof f->f); - memset(&f->c, 0, sizeof f->c); - f->f.cookie = &f->c; - - f->c.bufp = bufp; - f->c.sizep = sizep; - f->c.pos = f->c.len = f->c.space = *sizep = 0; - f->c.buf = *bufp = buf; - *buf = 0; - - f->f.flags = F_NORD; - f->f.fd = -1; - f->f.buf = f->buf; - f->f.buf_size = sizeof f->buf; - f->f.lbf = EOF; - f->f.write = ms_write; - f->f.seek = ms_seek; - f->f.close = ms_close; - f->f.mode = -1; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - if (!libc.threaded) f->f.lock = -1; -#endif - - return __ofl_add(&f->f); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/open_wmemstream.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/open_wmemstream.c deleted file mode 100644 index 198d5d4390ad32e3551cb682806b30a65fce5d53..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/open_wmemstream.c +++ /dev/null @@ -1,116 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include "libc.h" - -struct cookie { - wchar_t **bufp; - size_t *sizep; - size_t pos; - wchar_t *buf; - size_t len; - size_t space; - mbstate_t mbs; -}; - -struct wms_FILE { - FILE f; - struct cookie c; - unsigned char buf[1]; -}; - -static off_t wms_seek(FILE *f, off_t off, int whence) -{ - ssize_t base; - struct cookie *c = f->cookie; - if (whence>2U) { -fail: - errno = EINVAL; - return -1; - } -#ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values. - base = (size_t [3]){0, c->pos, c->len}[whence]; -#else - base = (size_t [3]) { - [SEEK_SET] = 0, - [SEEK_CUR] = c->pos, - [SEEK_END] = c->len - }[whence]; -#endif - if (off < -base || off > SSIZE_MAX/4-base) goto fail; - memset(&c->mbs, 0, sizeof c->mbs); - return c->pos = base+off; -} - -static size_t wms_write(FILE *f, const unsigned char *buf, size_t len) -{ - struct cookie *c = f->cookie; - size_t len2 = f->wpos - f->wbase; - wchar_t *newbuf; - if (len2) { - f->wpos = f->wbase; - if (wms_write(f, f->wbase, len2) < len2) return 0; - } - if (len + c->pos >= c->space) { - len2 = 2*c->space+1 | c->pos+len+1; - if (len2 > SSIZE_MAX/4) return 0; - newbuf = realloc(c->buf, len2*4); - if (!newbuf) return 0; - *c->bufp = c->buf = newbuf; - memset(c->buf + c->space, 0, 4*(len2 - c->space)); - c->space = len2; - } - - len2 = mbsnrtowcs(c->buf+c->pos, (void *)&buf, len, c->space-c->pos, &c->mbs); - if (len2 == -1) return 0; - c->pos += len2; - if (c->pos >= c->len) c->len = c->pos; - *c->sizep = c->pos; - return len; -} - -static int wms_close(FILE *f) -{ - return 0; -} - -FILE *open_wmemstream(wchar_t **bufp, size_t *sizep) -{ - struct wms_FILE *f; - wchar_t *buf; - - if (!(f=malloc(sizeof *f))) return 0; - if (!(buf=malloc(sizeof *buf))) { - free(f); - return 0; - } - memset(&f->f, 0, sizeof f->f); - memset(&f->c, 0, sizeof f->c); - f->f.cookie = &f->c; - - f->c.bufp = bufp; - f->c.sizep = sizep; - f->c.pos = f->c.len = f->c.space = *sizep = 0; - f->c.buf = *bufp = buf; - *buf = 0; - - f->f.flags = F_NORD; - f->f.fd = -1; - f->f.buf = f->buf; - f->f.buf_size = 0; - f->f.lbf = EOF; - f->f.write = wms_write; - f->f.seek = wms_seek; - f->f.close = wms_close; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - if (!libc.threaded) f->f.lock = -1; -#endif - - fwide(&f->f, 1); - - return __ofl_add(&f->f); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/printf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/printf.c deleted file mode 100644 index 46cc6d8e605153077988f37ad9821366bc5fac55..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/printf.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -int printf(const char *restrict fmt, ...) -{ - int ret; - va_list ap; - va_start(ap, fmt); - ret = vfprintf(stdout, fmt, ap); - va_end(ap); - return ret; -} -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -weak_alias(printf, iprintf); -weak_alias(printf, __small_printf); -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/putc.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/putc.c deleted file mode 100644 index 4744d978725deb765850b7922b7b7d2aa02772f1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/putc.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include "putc.h" - -int putc(int c, FILE *f) -{ - return do_putc(c, f); -} - -weak_alias(putc, _IO_putc); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/putc.h b/lib/libc/wasi/libc-top-half/musl/src/stdio/putc.h deleted file mode 100644 index 2cc63d2dbe3d3e0e80530097b1913d2605a512f0..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/putc.h +++ /dev/null @@ -1,29 +0,0 @@ -#include "stdio_impl.h" -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include "pthread_impl.h" - -#ifdef __GNUC__ -__attribute__((__noinline__)) -#endif -static int locking_putc(int c, FILE *f) -{ - if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f); - c = putc_unlocked(c, f); - if (a_swap(&f->lock, 0) & MAYBE_WAITERS) - __wake(&f->lock, 1, 1); - return c; -} -#endif - -static inline int do_putc(int c, FILE *f) -{ -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - int l = f->lock; - if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid) - return putc_unlocked(c, f); - return locking_putc(c, f); -#else - // With no threads, locking is unnecessary. - return putc_unlocked(c, f); -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/putchar.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/putchar.c deleted file mode 100644 index f044f16973b5748077b1536704cf322c94711ad8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/putchar.c +++ /dev/null @@ -1,7 +0,0 @@ -#include -#include "putc.h" - -int putchar(int c) -{ - return do_putc(c, stdout); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/stderr.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/stderr.c deleted file mode 100644 index 5f24549f83b4379a3695feaf508d881fa0953541..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/stderr.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "stdio_impl.h" - -#undef stderr - -static unsigned char buf[UNGET]; -hidden FILE __stderr_FILE = { - .buf = buf+UNGET, - .buf_size = 0, - .fd = 2, - .flags = F_PERM | F_NORD, - .lbf = -1, - .write = __stdio_write, - .seek = __stdio_seek, - .close = __stdio_close, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .lock = -1, -#endif -}; -FILE *const stderr = &__stderr_FILE; -FILE *volatile __stderr_used = &__stderr_FILE; diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/stdin.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/stdin.c deleted file mode 100644 index 68e1c3f643437b43cc3c6ac91bbfd1744c798509..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/stdin.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "stdio_impl.h" - -#undef stdin - -static unsigned char buf[BUFSIZ+UNGET]; -hidden FILE __stdin_FILE = { - .buf = buf+UNGET, - .buf_size = sizeof buf-UNGET, - .fd = 0, - .flags = F_PERM | F_NOWR, - .read = __stdio_read, - .seek = __stdio_seek, - .close = __stdio_close, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .lock = -1, -#endif -}; -FILE *const stdin = &__stdin_FILE; -FILE *volatile __stdin_used = &__stdin_FILE; diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/stdout.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/stdout.c deleted file mode 100644 index e0e2bced94103b24ed225b70feba3dde29c07b55..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/stdout.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "stdio_impl.h" - -#undef stdout - -static unsigned char buf[BUFSIZ+UNGET]; -hidden FILE __stdout_FILE = { - .buf = buf+UNGET, - .buf_size = sizeof buf-UNGET, - .fd = 1, - .flags = F_PERM | F_NORD, - .lbf = '\n', - .write = __stdout_write, - .seek = __stdio_seek, - .close = __stdio_close, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .lock = -1, -#endif -}; -FILE *const stdout = &__stdout_FILE; -FILE *volatile __stdout_used = &__stdout_FILE; diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vdprintf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vdprintf.c deleted file mode 100644 index cef0a1af29e9cd867d579fe32c657ae4d6193ed8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vdprintf.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "stdio_impl.h" - -int vdprintf(int fd, const char *restrict fmt, va_list ap) -{ - FILE f = { - .fd = fd, .lbf = EOF, .write = __stdio_write, - .buf = (void *)fmt, .buf_size = 0, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .lock = -1 -#endif - }; - return vfprintf(&f, fmt, ap); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vfprintf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vfprintf.c deleted file mode 100644 index 46a8a8c56ccb6cc222f9bc55af03cfa5b6a87b03..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vfprintf.c +++ /dev/null @@ -1,744 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -#include "printscan.h" -#endif - -/* Some useful macros */ - -#define MAX(a,b) ((a)>(b) ? (a) : (b)) -#define MIN(a,b) ((a)<(b) ? (a) : (b)) - -/* Convenient bit representation for modifier flags, which all fall - * within 31 codepoints of the space character. */ - -#define ALT_FORM (1U<<'#'-' ') -#define ZERO_PAD (1U<<'0'-' ') -#define LEFT_ADJ (1U<<'-'-' ') -#define PAD_POS (1U<<' '-' ') -#define MARK_POS (1U<<'+'-' ') -#define GROUPED (1U<<'\''-' ') - -#define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) - -/* State machine to accept length modifiers + conversion specifiers. - * Result is 0 on failure, or an argument type to pop on success. */ - -enum { - BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, - ZTPRE, JPRE, - STOP, - PTR, INT, UINT, ULLONG, - LONG, ULONG, - SHORT, USHORT, CHAR, UCHAR, - LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, - DBL, LDBL, - NOARG, - MAXSTATE -}; - -#define S(x) [(x)-'A'] - -static const unsigned char states[]['z'-'A'+1] = { - { /* 0: bare types */ - S('d') = INT, S('i') = INT, - S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = INT, S('C') = UINT, - S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, - S('m') = NOARG, - S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, - S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, - }, { /* 1: l-prefixed */ - S('d') = LONG, S('i') = LONG, - S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = UINT, S('s') = PTR, S('n') = PTR, - S('l') = LLPRE, - }, { /* 2: ll-prefixed */ - S('d') = LLONG, S('i') = LLONG, - S('o') = ULLONG, S('u') = ULLONG, - S('x') = ULLONG, S('X') = ULLONG, - S('n') = PTR, - }, { /* 3: h-prefixed */ - S('d') = SHORT, S('i') = SHORT, - S('o') = USHORT, S('u') = USHORT, - S('x') = USHORT, S('X') = USHORT, - S('n') = PTR, - S('h') = HHPRE, - }, { /* 4: hh-prefixed */ - S('d') = CHAR, S('i') = CHAR, - S('o') = UCHAR, S('u') = UCHAR, - S('x') = UCHAR, S('X') = UCHAR, - S('n') = PTR, - }, { /* 5: L-prefixed */ - S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, - S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, - S('n') = PTR, - }, { /* 6: z- or t-prefixed (assumed to be same size) */ - S('d') = PDIFF, S('i') = PDIFF, - S('o') = SIZET, S('u') = SIZET, - S('x') = SIZET, S('X') = SIZET, - S('n') = PTR, - }, { /* 7: j-prefixed */ - S('d') = IMAX, S('i') = IMAX, - S('o') = UMAX, S('u') = UMAX, - S('x') = UMAX, S('X') = UMAX, - S('n') = PTR, - } -}; - -#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') - -union arg -{ - uintmax_t i; -#if !defined(__wasilibc_printscan_no_floating_point) -#if defined(__wasilibc_printscan_no_long_double) - long_double f; -#else - long double f; -#endif -#endif - void *p; -}; - -static void pop_arg(union arg *arg, int type, va_list *ap) -{ - switch (type) { - case PTR: arg->p = va_arg(*ap, void *); - break; case INT: arg->i = va_arg(*ap, int); - break; case UINT: arg->i = va_arg(*ap, unsigned int); - break; case LONG: arg->i = va_arg(*ap, long); - break; case ULONG: arg->i = va_arg(*ap, unsigned long); - break; case ULLONG: arg->i = va_arg(*ap, unsigned long long); - break; case SHORT: arg->i = (short)va_arg(*ap, int); - break; case USHORT: arg->i = (unsigned short)va_arg(*ap, int); - break; case CHAR: arg->i = (signed char)va_arg(*ap, int); - break; case UCHAR: arg->i = (unsigned char)va_arg(*ap, int); - break; case LLONG: arg->i = va_arg(*ap, long long); - break; case SIZET: arg->i = va_arg(*ap, size_t); - break; case IMAX: arg->i = va_arg(*ap, intmax_t); - break; case UMAX: arg->i = va_arg(*ap, uintmax_t); - break; case PDIFF: arg->i = va_arg(*ap, ptrdiff_t); - break; case UIPTR: arg->i = (uintptr_t)va_arg(*ap, void *); -#if defined(__wasilibc_printscan_no_floating_point) - break; case DBL: - case LDBL: - floating_point_not_supported(); -#else - break; case DBL: arg->f = va_arg(*ap, double); -#if defined(__wasilibc_printscan_no_long_double) - break; case LDBL: long_double_not_supported(); -#else - break; case LDBL: arg->f = va_arg(*ap, long double); -#endif -#endif - } -} - -static void out(FILE *f, const char *s, size_t l) -{ - if (!ferror(f)) __fwritex((void *)s, l, f); -} - -static void pad(FILE *f, char c, int w, int l, int fl) -{ - char pad[256]; - if (fl & (LEFT_ADJ | ZERO_PAD) || l >= w) return; - l = w - l; - memset(pad, c, l>sizeof pad ? sizeof pad : l); - for (; l >= sizeof pad; l -= sizeof pad) - out(f, pad, sizeof pad); - out(f, pad, l); -} - -static const char xdigits[16] = { - "0123456789ABCDEF" -}; - -static char *fmt_x(uintmax_t x, char *s, int lower) -{ - for (; x; x>>=4) *--s = xdigits[(x&15)]|lower; - return s; -} - -static char *fmt_o(uintmax_t x, char *s) -{ - for (; x; x>>=3) *--s = '0' + (x&7); - return s; -} - -static char *fmt_u(uintmax_t x, char *s) -{ - unsigned long y; - for ( ; x>ULONG_MAX; x/=10) *--s = '0' + x%10; - for (y=x; y; y/=10) *--s = '0' + y%10; - return s; -} - -#if !defined(__wasilibc_printscan_no_floating_point) -/* Do not override this check. The floating point printing code below - * depends on the float.h constants being right. If they are wrong, it - * may overflow the stack. */ -#if LDBL_MANT_DIG == 53 -#if defined(__wasilibc_printscan_no_long_double) -typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long_double)]; -#else -typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)]; -#endif -#endif - -#if defined(__wasilibc_printscan_no_long_double) -static int fmt_fp(FILE *f, long_double y, int w, int p, int fl, int t) -#else -static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) -#endif -{ - uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion - + (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion - uint32_t *a, *d, *r, *z; - int e2=0, e, i, j, l; - char buf[9+LDBL_MANT_DIG/4], *s; - const char *prefix="-0X+0X 0X-0x+0x 0x"; - int pl; - char ebuf0[3*sizeof(int)], *ebuf=&ebuf0[3*sizeof(int)], *estr; - - pl=1; - if (signbit(y)) { - y=-y; - } else if (fl & MARK_POS) { - prefix+=3; - } else if (fl & PAD_POS) { - prefix+=6; - } else prefix++, pl=0; - - if (!isfinite(y)) { - char *s = (t&32)?"inf":"INF"; - if (y!=y) s=(t&32)?"nan":"NAN"; - pad(f, ' ', w, 3+pl, fl&~ZERO_PAD); - out(f, prefix, pl); - out(f, s, 3); - pad(f, ' ', w, 3+pl, fl^LEFT_ADJ); - return MAX(w, 3+pl); - } - - y = frexpl(y, &e2) * 2; - if (y) e2--; - - if ((t|32)=='a') { -#if defined(__wasilibc_printscan_no_long_double) - long_double round = 8.0; -#else - long double round = 8.0; -#endif - int re; - - if (t&32) prefix += 9; - pl += 2; - - if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0; - else re=LDBL_MANT_DIG/4-1-p; - - if (re) { - round *= 1<<(LDBL_MANT_DIG%4); - while (re--) round*=16; - if (*prefix=='-') { - y=-y; - y-=round; - y+=round; - y=-y; - } else { - y+=round; - y-=round; - } - } - - estr=fmt_u(e2<0 ? -e2 : e2, ebuf); - if (estr==ebuf) *--estr='0'; - *--estr = (e2<0 ? '-' : '+'); - *--estr = t+('p'-'a'); - - s=buf; - do { - int x=y; - *s++=xdigits[x]|(t&32); - y=16*(y-x); - if (s-buf==1 && (y||p>0||(fl&ALT_FORM))) *s++='.'; - } while (y); - - if (p > INT_MAX-2-(ebuf-estr)-pl) - return -1; - if (p && s-buf-2 < p) - l = (p+2) + (ebuf-estr); - else - l = (s-buf) + (ebuf-estr); - - pad(f, ' ', w, pl+l, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+l, fl^ZERO_PAD); - out(f, buf, s-buf); - pad(f, '0', l-(ebuf-estr)-(s-buf), 0, 0); - out(f, estr, ebuf-estr); - pad(f, ' ', w, pl+l, fl^LEFT_ADJ); - return MAX(w, pl+l); - } - if (p<0) p=6; - - if (y) y *= 0x1p28, e2-=28; - - if (e2<0) a=r=z=big; - else a=r=z=big+sizeof(big)/sizeof(*big) - LDBL_MANT_DIG - 1; - - do { - *z = y; - y = 1000000000*(y-*z++); - } while (y); - - while (e2>0) { - uint32_t carry=0; - int sh=MIN(29,e2); - for (d=z-1; d>=a; d--) { - uint64_t x = ((uint64_t)*d<a && !z[-1]) z--; - e2-=sh; - } - while (e2<0) { - uint32_t carry=0, *b; - int sh=MIN(9,-e2), need=1+(p+LDBL_MANT_DIG/3U+8)/9; - for (d=a; d>sh) + carry; - carry = (1000000000>>sh) * rm; - } - if (!*a) a++; - if (carry) *z++ = carry; - /* Avoid (slow!) computation past requested precision */ - b = (t|32)=='f' ? r : a; - if (z-b > need) z = b+need; - e2+=sh; - } - - if (a=i; i*=10, e++); - else e=0; - - /* Perform rounding: j is precision after the radix (possibly neg) */ - j = p - ((t|32)!='f')*e - ((t|32)=='g' && p); - if (j < 9*(z-r-1)) { - uint32_t x; - /* We avoid C's broken division of negative numbers */ - d = r + 1 + ((j+9*LDBL_MAX_EXP)/9 - LDBL_MAX_EXP); - j += 9*LDBL_MAX_EXP; - j %= 9; - for (i=10, j++; j<9; i*=10, j++); - x = *d % i; - /* Are there any significant digits past j? */ - if (x || d+1!=z) { -#if defined(__wasilibc_printscan_no_long_double) - long_double round = 2/LDBL_EPSILON; - long_double small; -#else - long double round = 2/LDBL_EPSILON; - long double small; -#endif - if ((*d/i & 1) || (i==1000000000 && d>a && (d[-1]&1))) - round += 2; - if (x 999999999) { - *d--=0; - if (d=i; i*=10, e++); - } - } - if (z>d+1) z=d+1; - } - for (; z>a && !z[-1]; z--); - - if ((t|32)=='g') { - if (!p) p++; - if (p>e && e>=-4) { - t--; - p-=e+1; - } else { - t-=2; - p--; - } - if (!(fl&ALT_FORM)) { - /* Count trailing zeros in last place */ - if (z>a && z[-1]) for (i=10, j=0; z[-1]%i==0; i*=10, j++); - else j=9; - if ((t|32)=='f') - p = MIN(p,MAX(0,9*(z-r-1)-j)); - else - p = MIN(p,MAX(0,9*(z-r-1)+e-j)); - } - } - if (p > INT_MAX-1-(p || (fl&ALT_FORM))) - return -1; - l = 1 + p + (p || (fl&ALT_FORM)); - if ((t|32)=='f') { - if (e > INT_MAX-l) return -1; - if (e>0) l+=e; - } else { - estr=fmt_u(e<0 ? -e : e, ebuf); - while(ebuf-estr<2) *--estr='0'; - *--estr = (e<0 ? '-' : '+'); - *--estr = t; - if (ebuf-estr > INT_MAX-l) return -1; - l += ebuf-estr; - } - - if (l > INT_MAX-pl) return -1; - pad(f, ' ', w, pl+l, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+l, fl^ZERO_PAD); - - if ((t|32)=='f') { - if (a>r) a=r; - for (d=a; d<=r; d++) { - char *s = fmt_u(*d, buf+9); - if (d!=a) while (s>buf) *--s='0'; - else if (s==buf+9) *--s='0'; - out(f, s, buf+9-s); - } - if (p || (fl&ALT_FORM)) out(f, ".", 1); - for (; d0; d++, p-=9) { - char *s = fmt_u(*d, buf+9); - while (s>buf) *--s='0'; - out(f, s, MIN(9,p)); - } - pad(f, '0', p+9, 9, 0); - } else { - if (z<=a) z=a+1; - for (d=a; d=0; d++) { - char *s = fmt_u(*d, buf+9); - if (s==buf+9) *--s='0'; - if (d!=a) while (s>buf) *--s='0'; - else { - out(f, s++, 1); - if (p>0||(fl&ALT_FORM)) out(f, ".", 1); - } - out(f, s, MIN(buf+9-s, p)); - p -= buf+9-s; - } - pad(f, '0', p+18, 18, 0); - out(f, estr, ebuf-estr); - } - - pad(f, ' ', w, pl+l, fl^LEFT_ADJ); - - return MAX(w, pl+l); -} -#endif - -static int getint(char **s) { - int i; - for (i=0; isdigit(**s); (*s)++) { - if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; - else i = 10*i + (**s-'0'); - } - return i; -} - -static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, int *nl_type) -{ - char *a, *z, *s=(char *)fmt; - unsigned l10n=0, fl; - int w, p, xp; - union arg arg; - int argpos; - unsigned st, ps; - int cnt=0, l=0; - size_t i; - char buf[sizeof(uintmax_t)*3]; - const char *prefix; - int t, pl; - wchar_t wc[2], *ws; - char mb[4]; - - for (;;) { - /* This error is only specified for snprintf, but since it's - * unspecified for other forms, do the same. Stop immediately - * on overflow; otherwise %n could produce wrong results. */ - if (l > INT_MAX - cnt) goto overflow; - - /* Update output count, end loop when fmt is exhausted */ - cnt += l; - if (!*s) break; - - /* Handle literal text and %% format specifiers */ - for (a=s; *s && *s!='%'; s++); - for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); - if (z-a > INT_MAX-cnt) goto overflow; - l = z-a; - if (f) out(f, a, l); - if (l) continue; - - if (isdigit(s[1]) && s[2]=='$') { - l10n=1; - argpos = s[1]-'0'; - s+=3; - } else { - argpos = -1; - s++; - } - - /* Read modifier flags */ - for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) - fl |= 1U<<*s-' '; - - /* Read field width */ - if (*s=='*') { - if (isdigit(s[1]) && s[2]=='$') { - l10n=1; - if (!f) nl_type[s[1]-'0'] = INT, w = 0; - else w = nl_arg[s[1]-'0'].i; - s+=3; - } else if (!l10n) { - w = f ? va_arg(*ap, int) : 0; - s++; - } else goto inval; - if (w<0) fl|=LEFT_ADJ, w=-w; - } else if ((w=getint(&s))<0) goto overflow; - - /* Read precision */ - if (*s=='.' && s[1]=='*') { - if (isdigit(s[2]) && s[3]=='$') { - if (!f) nl_type[s[2]-'0'] = INT, p = 0; - else p = nl_arg[s[2]-'0'].i; - s+=4; - } else if (!l10n) { - p = f ? va_arg(*ap, int) : 0; - s+=2; - } else goto inval; - xp = (p>=0); - } else if (*s=='.') { - s++; - p = getint(&s); - xp = 1; - } else { - p = -1; - xp = 0; - } - - /* Format specifier state machine */ - st=0; - do { - if (OOB(*s)) goto inval; - ps=st; - st=states[st]S(*s++); - } while (st-1=0) goto inval; - } else { - if (argpos>=0) { - if (!f) nl_type[argpos]=st; - else arg=nl_arg[argpos]; - } else if (f) pop_arg(&arg, st, ap); - else return 0; - } - - if (!f) continue; - - /* Do not process any new directives once in error state. */ - if (ferror(f)) return -1; - - z = buf + sizeof(buf); - prefix = "-+ 0X0x"; - pl = 0; - t = s[-1]; - - /* Transform ls,lc -> S,C */ - if (ps && (t&15)==3) t&=~32; - - /* - and 0 flags are mutually exclusive */ - if (fl & LEFT_ADJ) fl &= ~ZERO_PAD; - - switch(t) { - case 'n': - switch(ps) { - case BARE: *(int *)arg.p = cnt; break; - case LPRE: *(long *)arg.p = cnt; break; - case LLPRE: *(long long *)arg.p = cnt; break; - case HPRE: *(unsigned short *)arg.p = cnt; break; - case HHPRE: *(unsigned char *)arg.p = cnt; break; - case ZTPRE: *(size_t *)arg.p = cnt; break; - case JPRE: *(uintmax_t *)arg.p = cnt; break; - } - continue; - case 'p': - p = MAX(p, 2*sizeof(void*)); - t = 'x'; - fl |= ALT_FORM; - case 'x': case 'X': - a = fmt_x(arg.i, z, t&32); - if (arg.i && (fl & ALT_FORM)) prefix+=(t>>4), pl=2; - if (0) { - case 'o': - a = fmt_o(arg.i, z); - if ((fl&ALT_FORM) && pINTMAX_MAX) { - arg.i=-arg.i; - } else if (fl & MARK_POS) { - prefix++; - } else if (fl & PAD_POS) { - prefix+=2; - } else pl=0; - case 'u': - a = fmt_u(arg.i, z); - } - if (xp && p<0) goto overflow; - if (xp) fl &= ~ZERO_PAD; - if (!arg.i && !p) { - a=z; - break; - } - p = MAX(p, z-a + !arg.i); - break; - narrow_c: - case 'c': - *(a=z-(p=1))=arg.i; - fl &= ~ZERO_PAD; - break; - case 'm': - if (1) a = strerror(errno); else - case 's': - a = arg.p ? arg.p : "(null)"; - z = a + strnlen(a, p<0 ? INT_MAX : p); - if (p<0 && *z) goto overflow; - p = z-a; - fl &= ~ZERO_PAD; - break; - case 'C': - if (!arg.i) goto narrow_c; - wc[0] = arg.i; - wc[1] = 0; - arg.p = wc; - p = -1; - case 'S': - ws = arg.p; - for (i=l=0; i

=0 && l<=p-i; i+=l); - if (l<0) return -1; - if (i > INT_MAX) goto overflow; - p = i; - pad(f, ' ', w, p, fl); - ws = arg.p; - for (i=0; i<0U+p && *ws && i+(l=wctomb(mb, *ws++))<=p; i+=l) - out(f, mb, l); - pad(f, ' ', w, p, fl^LEFT_ADJ); - l = w>p ? w : p; - continue; -#if !defined(__wasilibc_printscan_no_floating_point) - case 'e': case 'f': case 'g': case 'a': - case 'E': case 'F': case 'G': case 'A': - if (xp && p<0) goto overflow; - l = fmt_fp(f, arg.f, w, p, fl, t); - if (l<0) goto overflow; - continue; -#endif - } - - if (p < z-a) p = z-a; - if (p > INT_MAX-pl) goto overflow; - if (w < pl+p) w = pl+p; - if (w > INT_MAX-cnt) goto overflow; - - pad(f, ' ', w, pl+p, fl); - out(f, prefix, pl); - pad(f, '0', w, pl+p, fl^ZERO_PAD); - pad(f, '0', p, z-a, 0); - out(f, a, z-a); - pad(f, ' ', w, pl+p, fl^LEFT_ADJ); - - l = w; - } - - if (f) return cnt; - if (!l10n) return 0; - - for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) - pop_arg(nl_arg+i, nl_type[i], ap); - for (; i<=NL_ARGMAX && !nl_type[i]; i++); - if (i<=NL_ARGMAX) goto inval; - return 1; - -inval: - errno = EINVAL; - return -1; -overflow: - errno = EOVERFLOW; - return -1; -} - -int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) -{ - va_list ap2; - int nl_type[NL_ARGMAX+1] = {0}; - union arg nl_arg[NL_ARGMAX+1]; - unsigned char internal_buf[80], *saved_buf = 0; - int olderr; - int ret; - - /* the copy allows passing va_list* even if va_list is an array */ - va_copy(ap2, ap); - if (printf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { - va_end(ap2); - return -1; - } - - FLOCK(f); - olderr = f->flags & F_ERR; - f->flags &= ~F_ERR; - if (!f->buf_size) { - saved_buf = f->buf; - f->buf = internal_buf; - f->buf_size = sizeof internal_buf; - f->wpos = f->wbase = f->wend = 0; - } - if (!f->wend && __towrite(f)) ret = -1; - else ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); - if (saved_buf) { - f->write(f, 0, 0); - if (!f->wpos) ret = -1; - f->buf = saved_buf; - f->buf_size = 0; - f->wpos = f->wbase = f->wend = 0; - } - if (ferror(f)) ret = -1; - f->flags |= olderr; - FUNLOCK(f); - va_end(ap2); - return ret; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vfscanf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vfscanf.c deleted file mode 100644 index b612bbdd4fdf29df6f092cfb37194852eb37e162..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vfscanf.c +++ /dev/null @@ -1,351 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -#include "printscan.h" -#endif - -#include "stdio_impl.h" -#include "shgetc.h" -#include "intscan.h" -#include "floatscan.h" - -#define SIZE_hh -2 -#define SIZE_h -1 -#define SIZE_def 0 -#define SIZE_l 1 -#define SIZE_L 2 -#define SIZE_ll 3 - -static void store_int(void *dest, int size, unsigned long long i) -{ - if (!dest) return; - switch (size) { - case SIZE_hh: - *(char *)dest = i; - break; - case SIZE_h: - *(short *)dest = i; - break; - case SIZE_def: - *(int *)dest = i; - break; - case SIZE_l: - *(long *)dest = i; - break; - case SIZE_ll: - *(long long *)dest = i; - break; - } -} - -static void *arg_n(va_list ap, unsigned int n) -{ - void *p; - unsigned int i; - va_list ap2; - va_copy(ap2, ap); - for (i=n; i>1; i--) va_arg(ap2, void *); - p = va_arg(ap2, void *); - va_end(ap2); - return p; -} - -int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) -{ - int width; - int size; - int alloc = 0; - int base; - const unsigned char *p; - int c, t; - char *s; - wchar_t *wcs; - mbstate_t st; - void *dest=NULL; - int invert; - int matches=0; - unsigned long long x; -#if defined(__wasilibc_printscan_no_long_double) - long_double y; -#else - long double y; -#endif - off_t pos = 0; - unsigned char scanset[257]; - size_t i, k; - wchar_t wc; - - FLOCK(f); - - if (!f->rpos) __toread(f); - if (!f->rpos) goto input_fail; - - for (p=(const unsigned char *)fmt; *p; p++) { - - alloc = 0; - - if (isspace(*p)) { - while (isspace(p[1])) p++; - shlim(f, 0); - while (isspace(shgetc(f))); - shunget(f); - pos += shcnt(f); - continue; - } - if (*p != '%' || p[1] == '%') { - shlim(f, 0); - if (*p == '%') { - p++; - while (isspace((c=shgetc(f)))); - } else { - c = shgetc(f); - } - if (c!=*p) { - shunget(f); - if (c<0) goto input_fail; - goto match_fail; - } - pos += shcnt(f); - continue; - } - - p++; - if (*p=='*') { - dest = 0; p++; - } else if (isdigit(*p) && p[1]=='$') { - dest = arg_n(ap, *p-'0'); p+=2; - } else { - dest = va_arg(ap, void *); - } - - for (width=0; isdigit(*p); p++) { - width = 10*width + *p - '0'; - } - - if (*p=='m') { - wcs = 0; - s = 0; - alloc = !!dest; - p++; - } else { - alloc = 0; - } - - size = SIZE_def; - switch (*p++) { - case 'h': - if (*p == 'h') p++, size = SIZE_hh; - else size = SIZE_h; - break; - case 'l': - if (*p == 'l') p++, size = SIZE_ll; - else size = SIZE_l; - break; - case 'j': - size = SIZE_ll; - break; - case 'z': - case 't': - size = SIZE_l; - break; - case 'L': - size = SIZE_L; - break; - case 'd': case 'i': case 'o': case 'u': case 'x': - case 'a': case 'e': case 'f': case 'g': - case 'A': case 'E': case 'F': case 'G': case 'X': - case 's': case 'c': case '[': - case 'S': case 'C': - case 'p': case 'n': - p--; - break; - default: - goto fmt_fail; - } - - t = *p; - - /* C or S */ - if ((t&0x2f) == 3) { - t |= 32; - size = SIZE_l; - } - - switch (t) { - case 'c': - if (width < 1) width = 1; - case '[': - break; - case 'n': - store_int(dest, size, pos); - /* do not increment match count, etc! */ - continue; - default: - shlim(f, 0); - while (isspace(shgetc(f))); - shunget(f); - pos += shcnt(f); - } - - shlim(f, width); - if (shgetc(f) < 0) goto input_fail; - shunget(f); - - switch (t) { - case 's': - case 'c': - case '[': - if (t == 'c' || t == 's') { - memset(scanset, -1, sizeof scanset); - scanset[0] = 0; - if (t == 's') { - scanset[1+'\t'] = 0; - scanset[1+'\n'] = 0; - scanset[1+'\v'] = 0; - scanset[1+'\f'] = 0; - scanset[1+'\r'] = 0; - scanset[1+' '] = 0; - } - } else { - if (*++p == '^') p++, invert = 1; - else invert = 0; - memset(scanset, invert, sizeof scanset); - scanset[0] = 0; - if (*p == '-') p++, scanset[1+'-'] = 1-invert; - else if (*p == ']') p++, scanset[1+']'] = 1-invert; - for (; *p != ']'; p++) { - if (!*p) goto fmt_fail; - if (*p=='-' && p[1] && p[1] != ']') - for (c=p++[-1]; c<*p; c++) - scanset[1+c] = 1-invert; - scanset[1+*p] = 1-invert; - } - } - wcs = 0; - s = 0; - i = 0; - k = t=='c' ? width+1U : 31; - if (size == SIZE_l) { - if (alloc) { - wcs = malloc(k*sizeof(wchar_t)); - if (!wcs) goto alloc_fail; - } else { - wcs = dest; - } - st = (mbstate_t){0}; - while (scanset[(c=shgetc(f))+1]) { - switch (mbrtowc(&wc, &(char){c}, 1, &st)) { - case -1: - goto input_fail; - case -2: - continue; - } - if (wcs) wcs[i++] = wc; - if (alloc && i==k) { - k+=k+1; - wchar_t *tmp = realloc(wcs, k*sizeof(wchar_t)); - if (!tmp) goto alloc_fail; - wcs = tmp; - } - } - if (!mbsinit(&st)) goto input_fail; - } else if (alloc) { - s = malloc(k); - if (!s) goto alloc_fail; - while (scanset[(c=shgetc(f))+1]) { - s[i++] = c; - if (i==k) { - k+=k+1; - char *tmp = realloc(s, k); - if (!tmp) goto alloc_fail; - s = tmp; - } - } - } else if ((s = dest)) { - while (scanset[(c=shgetc(f))+1]) - s[i++] = c; - } else { - while (scanset[(c=shgetc(f))+1]); - } - shunget(f); - if (!shcnt(f)) goto match_fail; - if (t == 'c' && shcnt(f) != width) goto match_fail; - if (alloc) { - if (size == SIZE_l) *(wchar_t **)dest = wcs; - else *(char **)dest = s; - } - if (t != 'c') { - if (wcs) wcs[i] = 0; - if (s) s[i] = 0; - } - break; - case 'p': - case 'X': - case 'x': - base = 16; - goto int_common; - case 'o': - base = 8; - goto int_common; - case 'd': - case 'u': - base = 10; - goto int_common; - case 'i': - base = 0; - int_common: - x = __intscan(f, base, 0, ULLONG_MAX); - if (!shcnt(f)) goto match_fail; - if (t=='p' && dest) *(void **)dest = (void *)(uintptr_t)x; - else store_int(dest, size, x); - break; - case 'a': case 'A': - case 'e': case 'E': - case 'f': case 'F': - case 'g': case 'G': - y = __floatscan(f, size, 0); - if (!shcnt(f)) goto match_fail; - if (dest) switch (size) { - case SIZE_def: - *(float *)dest = y; - break; - case SIZE_l: - *(double *)dest = y; - break; - case SIZE_L: -#if defined(__wasilibc_printscan_no_long_double) - long_double_not_supported(); -#else - *(long double *)dest = y; -#endif - break; - } - break; - } - - pos += shcnt(f); - if (dest) matches++; - } - if (0) { -fmt_fail: -alloc_fail: -input_fail: - if (!matches) matches--; -match_fail: - if (alloc) { - free(s); - free(wcs); - } - } - FUNLOCK(f); - return matches; -} - -weak_alias(vfscanf,__isoc99_vfscanf); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vfwprintf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vfwprintf.c deleted file mode 100644 index ba64eeb053f219dcdcbfce6dfaa2f4c14a83834f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vfwprintf.c +++ /dev/null @@ -1,421 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -#include "printscan.h" -#endif - -/* Convenient bit representation for modifier flags, which all fall - * within 31 codepoints of the space character. */ - -#define ALT_FORM (1U<<'#'-' ') -#define ZERO_PAD (1U<<'0'-' ') -#define LEFT_ADJ (1U<<'-'-' ') -#define PAD_POS (1U<<' '-' ') -#define MARK_POS (1U<<'+'-' ') -#define GROUPED (1U<<'\''-' ') - -#define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) - -/* State machine to accept length modifiers + conversion specifiers. - * Result is 0 on failure, or an argument type to pop on success. */ - -enum { - BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, - ZTPRE, JPRE, - STOP, - PTR, INT, UINT, ULLONG, - LONG, ULONG, - SHORT, USHORT, CHAR, UCHAR, - LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, - DBL, LDBL, - NOARG, - MAXSTATE -}; - -#define S(x) [(x)-'A'] - -static const unsigned char states[]['z'-'A'+1] = { - { /* 0: bare types */ - S('d') = INT, S('i') = INT, - S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = INT, S('C') = UINT, - S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, - S('m') = NOARG, - S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, - S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, - }, { /* 1: l-prefixed */ - S('d') = LONG, S('i') = LONG, - S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, - S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, - S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, - S('c') = UINT, S('s') = PTR, S('n') = PTR, - S('l') = LLPRE, - }, { /* 2: ll-prefixed */ - S('d') = LLONG, S('i') = LLONG, - S('o') = ULLONG, S('u') = ULLONG, - S('x') = ULLONG, S('X') = ULLONG, - S('n') = PTR, - }, { /* 3: h-prefixed */ - S('d') = SHORT, S('i') = SHORT, - S('o') = USHORT, S('u') = USHORT, - S('x') = USHORT, S('X') = USHORT, - S('n') = PTR, - S('h') = HHPRE, - }, { /* 4: hh-prefixed */ - S('d') = CHAR, S('i') = CHAR, - S('o') = UCHAR, S('u') = UCHAR, - S('x') = UCHAR, S('X') = UCHAR, - S('n') = PTR, - }, { /* 5: L-prefixed */ - S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, - S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, - S('n') = PTR, - }, { /* 6: z- or t-prefixed (assumed to be same size) */ - S('d') = PDIFF, S('i') = PDIFF, - S('o') = SIZET, S('u') = SIZET, - S('x') = SIZET, S('X') = SIZET, - S('n') = PTR, - }, { /* 7: j-prefixed */ - S('d') = IMAX, S('i') = IMAX, - S('o') = UMAX, S('u') = UMAX, - S('x') = UMAX, S('X') = UMAX, - S('n') = PTR, - } -}; - -#define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') - -union arg -{ - uintmax_t i; -#if !defined(__wasilibc_printscan_no_floating_point) -#if defined(__wasilibc_printscan_no_long_double) - long_double f; -#else - long double f; -#endif -#endif - void *p; -}; - -static void pop_arg(union arg *arg, int type, va_list *ap) -{ - switch (type) { - case PTR: arg->p = va_arg(*ap, void *); - break; case INT: arg->i = va_arg(*ap, int); - break; case UINT: arg->i = va_arg(*ap, unsigned int); - break; case LONG: arg->i = va_arg(*ap, long); - break; case ULONG: arg->i = va_arg(*ap, unsigned long); - break; case ULLONG: arg->i = va_arg(*ap, unsigned long long); - break; case SHORT: arg->i = (short)va_arg(*ap, int); - break; case USHORT: arg->i = (unsigned short)va_arg(*ap, int); - break; case CHAR: arg->i = (signed char)va_arg(*ap, int); - break; case UCHAR: arg->i = (unsigned char)va_arg(*ap, int); - break; case LLONG: arg->i = va_arg(*ap, long long); - break; case SIZET: arg->i = va_arg(*ap, size_t); - break; case IMAX: arg->i = va_arg(*ap, intmax_t); - break; case UMAX: arg->i = va_arg(*ap, uintmax_t); - break; case PDIFF: arg->i = va_arg(*ap, ptrdiff_t); - break; case UIPTR: arg->i = (uintptr_t)va_arg(*ap, void *); -#if defined(__wasilibc_printscan_no_floating_point) - break; case DBL: - break; case LDBL: floating_point_not_supported(); -#else - break; case DBL: arg->f = va_arg(*ap, double); -#if defined(__wasilibc_printscan_no_long_double) - break; case LDBL: long_double_not_supported(); -#else - break; case LDBL: arg->f = va_arg(*ap, long double); -#endif -#endif - } -} - -static void out(FILE *f, const wchar_t *s, size_t l) -{ - while (l-- && !ferror(f)) fputwc(*s++, f); -} - -static void pad(FILE *f, int n, int fl) -{ - if ((fl & LEFT_ADJ) || !n || ferror(f)) return; - fprintf(f, "%*s", n, ""); -} - -static int getint(wchar_t **s) { - int i; - for (i=0; iswdigit(**s); (*s)++) { - if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; - else i = 10*i + (**s-'0'); - } - return i; -} - -static const char sizeprefix['y'-'a'] = { -['a'-'a']='L', ['e'-'a']='L', ['f'-'a']='L', ['g'-'a']='L', -['d'-'a']='j', ['i'-'a']='j', ['o'-'a']='j', ['u'-'a']='j', ['x'-'a']='j', -['p'-'a']='j' -}; - -static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_arg, int *nl_type) -{ - wchar_t *a, *z, *s=(wchar_t *)fmt; - unsigned l10n=0, fl; - int w, p, xp; - union arg arg; - int argpos; - unsigned st, ps; - int cnt=0, l=0; - int i; - int t; - char *bs; - char charfmt[16]; - wchar_t wc; - - for (;;) { - /* This error is only specified for snprintf, but since it's - * unspecified for other forms, do the same. Stop immediately - * on overflow; otherwise %n could produce wrong results. */ - if (l > INT_MAX - cnt) goto overflow; - - /* Update output count, end loop when fmt is exhausted */ - cnt += l; - if (!*s) break; - - /* Handle literal text and %% format specifiers */ - for (a=s; *s && *s!='%'; s++); - for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); - if (z-a > INT_MAX-cnt) goto overflow; - l = z-a; - if (f) out(f, a, l); - if (l) continue; - - if (iswdigit(s[1]) && s[2]=='$') { - l10n=1; - argpos = s[1]-'0'; - s+=3; - } else { - argpos = -1; - s++; - } - - /* Read modifier flags */ - for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) - fl |= 1U<<*s-' '; - - /* Read field width */ - if (*s=='*') { - if (iswdigit(s[1]) && s[2]=='$') { - l10n=1; - nl_type[s[1]-'0'] = INT; - w = nl_arg[s[1]-'0'].i; - s+=3; - } else if (!l10n) { - w = f ? va_arg(*ap, int) : 0; - s++; - } else goto inval; - if (w<0) fl|=LEFT_ADJ, w=-w; - } else if ((w=getint(&s))<0) goto overflow; - - /* Read precision */ - if (*s=='.' && s[1]=='*') { - if (isdigit(s[2]) && s[3]=='$') { - nl_type[s[2]-'0'] = INT; - p = nl_arg[s[2]-'0'].i; - s+=4; - } else if (!l10n) { - p = f ? va_arg(*ap, int) : 0; - s+=2; - } else goto inval; - xp = (p>=0); - } else if (*s=='.') { - s++; - p = getint(&s); - xp = 1; - } else { - p = -1; - xp = 0; - } - - /* Format specifier state machine */ - st=0; - do { - if (OOB(*s)) goto inval; - ps=st; - st=states[st]S(*s++); - } while (st-1=0) goto inval; - } else { - if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos]; - else if (f) pop_arg(&arg, st, ap); - else return 0; - } - - if (!f) continue; - - /* Do not process any new directives once in error state. */ - if (ferror(f)) return -1; - - t = s[-1]; - if (ps && (t&15)==3) t&=~32; - - switch (t) { - case 'n': - switch(ps) { - case BARE: *(int *)arg.p = cnt; break; - case LPRE: *(long *)arg.p = cnt; break; - case LLPRE: *(long long *)arg.p = cnt; break; - case HPRE: *(unsigned short *)arg.p = cnt; break; - case HHPRE: *(unsigned char *)arg.p = cnt; break; - case ZTPRE: *(size_t *)arg.p = cnt; break; - case JPRE: *(uintmax_t *)arg.p = cnt; break; - } - continue; - case 'c': - case 'C': - if (w<1) w=1; - pad(f, w-1, fl); - out(f, &(wchar_t){t=='C' ? arg.i : btowc(arg.i)}, 1); - pad(f, w-1, fl^LEFT_ADJ); - l = w; - continue; - case 'S': - a = arg.p; - z = a + wcsnlen(a, p<0 ? INT_MAX : p); - if (p<0 && *z) goto overflow; - p = z-a; - if (w0; bs+=i, l++); - if (i<0) return -1; - if (p<0 && *bs) goto overflow; - p=l; - if (wflags & F_ERR; - f->flags &= ~F_ERR; - ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type); - if (ferror(f)) ret = -1; - f->flags |= olderr; - FUNLOCK(f); - va_end(ap2); - return ret; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vsnprintf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vsnprintf.c deleted file mode 100644 index 48c3aef7e7063c28e3ddb44b101bb61e7ed8be28..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vsnprintf.c +++ /dev/null @@ -1,52 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include - -struct cookie { - char *s; - size_t n; -}; - -#define MIN(a, b) ((a) < (b) ? (a) : (b)) - -static size_t sn_write(FILE *f, const unsigned char *s, size_t l) -{ - struct cookie *c = f->cookie; - size_t k = MIN(c->n, f->wpos - f->wbase); - if (k) { - memcpy(c->s, f->wbase, k); - c->s += k; - c->n -= k; - } - k = MIN(c->n, l); - if (k) { - memcpy(c->s, s, k); - c->s += k; - c->n -= k; - } - *c->s = 0; - f->wpos = f->wbase = f->buf; - /* pretend to succeed, even if we discarded extra data */ - return l; -} - -int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap) -{ - unsigned char buf[1]; - char dummy[1]; - struct cookie c = { .s = n ? s : dummy, .n = n ? n-1 : 0 }; - FILE f = { - .lbf = EOF, - .write = sn_write, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .lock = -1, -#endif - .buf = buf, - .cookie = &c, - }; - - *c.s = 0; - return vfprintf(&f, fmt, ap); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vsscanf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vsscanf.c deleted file mode 100644 index 0e5b482656194a672b13d8f41225a6d404e7f790..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vsscanf.c +++ /dev/null @@ -1,31 +0,0 @@ -#include "stdio_impl.h" -#include - -static size_t string_read(FILE *f, unsigned char *buf, size_t len) -{ - char *src = f->cookie; - size_t k = len+256; - char *end = memchr(src, 0, k); - if (end) k = end-src; - if (k < len) len = k; - memcpy(buf, src, len); - f->rpos = (void *)(src+len); - f->rend = (void *)(src+k); - f->cookie = src+k; - return len; -} - -int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) -{ - FILE f = { - .buf = (void *)s, .cookie = (void *)s, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .read = string_read, .lock = -1 -#else - .read = string_read -#endif - }; - return vfscanf(&f, fmt, ap); -} - -weak_alias(vsscanf,__isoc99_vsscanf); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vswprintf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vswprintf.c deleted file mode 100644 index cab94cba77031a73ae16f7984432bd015876eeb2..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vswprintf.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "stdio_impl.h" -#include -#include -#include -#include -#include - -struct cookie { - wchar_t *ws; - size_t l; -}; - -static size_t sw_write(FILE *f, const unsigned char *s, size_t l) -{ - size_t l0 = l; - int i = 0; - struct cookie *c = f->cookie; - if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1) - return -1; - while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) { - if (!i) i=1; - s+=i; - l-=i; - c->l--; - c->ws++; - } - *c->ws = 0; - if (i < 0) { - f->wpos = f->wbase = f->wend = 0; - f->flags |= F_ERR; - return i; - } - f->wend = f->buf + f->buf_size; - f->wpos = f->wbase = f->buf; - return l0; -} - -int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) -{ - int r; - unsigned char buf[256]; - struct cookie c = { s, n-1 }; - FILE f = { - .lbf = EOF, - .write = sw_write, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .lock = -1, -#endif - .buf = buf, - .buf_size = sizeof buf, - .cookie = &c, - }; - - if (!n) { - return -1; - } - r = vfwprintf(&f, fmt, ap); - sw_write(&f, 0, 0); - return r>=n ? -1 : r; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdio/vswscanf.c b/lib/libc/wasi/libc-top-half/musl/src/stdio/vswscanf.c deleted file mode 100644 index ea827102d56c690e5eee2f193a0d79acc89d853b..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdio/vswscanf.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "stdio_impl.h" -#include - -static size_t wstring_read(FILE *f, unsigned char *buf, size_t len) -{ - const wchar_t *src = f->cookie; - size_t k; - - if (!src) return 0; - - k = wcsrtombs((void *)f->buf, &src, f->buf_size, 0); - if (k==(size_t)-1) { - f->rpos = f->rend = 0; - return 0; - } - - f->rpos = f->buf; - f->rend = f->buf + k; - f->cookie = (void *)src; - - if (!len || !k) return 0; - - *buf = *f->rpos++; - return 1; -} - -int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap) -{ - unsigned char buf[256]; - FILE f = { - .buf = buf, .buf_size = sizeof buf, - .cookie = (void *)s, -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - .read = wstring_read, .lock = -1 -#else - .read = wstring_read -#endif - }; - return vfwscanf(&f, fmt, ap); -} - -weak_alias(vswscanf,__isoc99_vswscanf); diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdlib/strtod.c b/lib/libc/wasi/libc-top-half/musl/src/stdlib/strtod.c deleted file mode 100644 index 184bca4629e7f9df4d477858d22e7d21c1ef3383..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdlib/strtod.c +++ /dev/null @@ -1,48 +0,0 @@ -#include -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -#include "printscan.h" -#define __NEED_locale_t -#include -#endif -#include "shgetc.h" -#include "floatscan.h" -#include "stdio_impl.h" - -#if defined(__wasilibc_printscan_no_long_double) -static long_double strtox(const char *s, char **p, int prec) -#else -static long double strtox(const char *s, char **p, int prec) -#endif -{ - FILE f; - sh_fromstring(&f, s); - shlim(&f, 0); -#if defined(__wasilibc_printscan_no_long_double) - long_double y = __floatscan(&f, prec, 1); -#else - long double y = __floatscan(&f, prec, 1); -#endif - off_t cnt = shcnt(&f); - if (p) *p = cnt ? (char *)s + cnt : (char *)s; - return y; -} - -float strtof(const char *restrict s, char **restrict p) -{ - return strtox(s, p, 0); -} - -double strtod(const char *restrict s, char **restrict p) -{ - return strtox(s, p, 1); -} - -long double strtold(const char *restrict s, char **restrict p) -{ -#if defined(__wasilibc_printscan_no_long_double) - long_double_not_supported(); -#else - return strtox(s, p, 2); -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstod.c b/lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstod.c deleted file mode 100644 index 97b894eb27ee40c4aae4913a8d1c1f6f66ea1811..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstod.c +++ /dev/null @@ -1,82 +0,0 @@ -#ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed -#else -#include "printscan.h" -#endif -#include "shgetc.h" -#include "floatscan.h" -#include "stdio_impl.h" -#include -#include - -/* This read function heavily cheats. It knows: - * (1) len will always be 1 - * (2) non-ascii characters don't matter */ - -static size_t do_read(FILE *f, unsigned char *buf, size_t len) -{ - size_t i; - const wchar_t *wcs = f->cookie; - - if (!wcs[0]) wcs=L"@"; - for (i=0; ibuf_size && wcs[i]; i++) - f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; - f->rpos = f->buf; - f->rend = f->buf + i; - f->cookie = (void *)(wcs+i); - - if (i && len) { - *buf = *f->rpos++; - return 1; - } - return 0; -} - -#if defined(__wasilibc_printscan_no_long_double) -static long_double wcstox(const wchar_t *s, wchar_t **p, int prec) -#else -static long double wcstox(const wchar_t *s, wchar_t **p, int prec) -#endif -{ - wchar_t *t = (wchar_t *)s; - unsigned char buf[64]; - FILE f = {0}; - f.flags = 0; - f.rpos = f.rend = f.buf = buf + 4; - f.buf_size = sizeof buf - 4; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - f.lock = -1; -#endif - f.read = do_read; - while (iswspace(*t)) t++; - f.cookie = (void *)t; - shlim(&f, 0); -#if defined(__wasilibc_printscan_no_long_double) - long_double y = __floatscan(&f, prec, 1); -#else - long double y = __floatscan(&f, prec, 1); -#endif - if (p) { - size_t cnt = shcnt(&f); - *p = cnt ? t + cnt : (wchar_t *)s; - } - return y; -} - -float wcstof(const wchar_t *restrict s, wchar_t **restrict p) -{ - return wcstox(s, p, 0); -} - -double wcstod(const wchar_t *restrict s, wchar_t **restrict p) -{ - return wcstox(s, p, 1); -} - -long double wcstold(const wchar_t *restrict s, wchar_t **restrict p) -{ -#if defined(__wasilibc_printscan_no_long_double) - long_double_not_supported(); -#else - return wcstox(s, p, 2); -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstol.c b/lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstol.c deleted file mode 100644 index 3aefd06f448380422f132df03d5408553cf5908a..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstol.c +++ /dev/null @@ -1,83 +0,0 @@ -#include "stdio_impl.h" -#include "intscan.h" -#include "shgetc.h" -#include -#include -#include -#include - -/* This read function heavily cheats. It knows: - * (1) len will always be 1 - * (2) non-ascii characters don't matter */ - -static size_t do_read(FILE *f, unsigned char *buf, size_t len) -{ - size_t i; - const wchar_t *wcs = f->cookie; - - if (!wcs[0]) wcs=L"@"; - for (i=0; ibuf_size && wcs[i]; i++) - f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; - f->rpos = f->buf; - f->rend = f->buf + i; - f->cookie = (void *)(wcs+i); - - if (i && len) { - *buf = *f->rpos++; - return 1; - } - return 0; -} - -static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsigned long long lim) -{ - wchar_t *t = (wchar_t *)s; - unsigned char buf[64]; - FILE f = {0}; - f.flags = 0; - f.rpos = f.rend = f.buf = buf + 4; - f.buf_size = sizeof buf - 4; -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - f.lock = -1; -#endif - f.read = do_read; - while (iswspace(*t)) t++; - f.cookie = (void *)t; - shlim(&f, 0); - unsigned long long y = __intscan(&f, base, 1, lim); - if (p) { - size_t cnt = shcnt(&f); - *p = cnt ? t + cnt : (wchar_t *)s; - } - return y; -} - -unsigned long long wcstoull(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, ULLONG_MAX); -} - -long long wcstoll(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, LLONG_MIN); -} - -unsigned long wcstoul(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, ULONG_MAX); -} - -long wcstol(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstox(s, p, base, 0UL+LONG_MIN); -} - -intmax_t wcstoimax(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstoll(s, p, base); -} - -uintmax_t wcstoumax(const wchar_t *restrict s, wchar_t **restrict p, int base) -{ - return wcstoull(s, p, base); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c deleted file mode 100644 index ab8d938c69f4d25e73bca3a138178dcbafab9122..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c +++ /dev/null @@ -1,121 +0,0 @@ -#include "pthread_impl.h" - -#ifndef __wasilibc_unmodified_upstream -#include -#endif - -int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state) -{ - *state = a->_a_detach; - return 0; -} -int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) -{ - *size = a->_a_guardsize; - return 0; -} - -#ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ -int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit) -{ - *inherit = a->_a_sched; - return 0; -} - -int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) -{ - param->sched_priority = a->_a_prio; - return 0; -} - -int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy) -{ - *policy = a->_a_policy; - return 0; -} - -int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope) -{ - *scope = PTHREAD_SCOPE_SYSTEM; - return 0; -} -#else -int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) -{ - param->sched_priority = 0; - return 0; -} -#endif - -int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size) -{ - if (!a->_a_stackaddr) - return EINVAL; - *size = a->_a_stacksize; - *addr = (void *)(a->_a_stackaddr - *size); - return 0; -} - -int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) -{ - *size = a->_a_stacksize; - return 0; -} - -int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared) -{ - *pshared = !!a->__attr; - return 0; -} - -#ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */ -int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) -{ - *clk = a->__attr & 0x7fffffff; - return 0; -} -#else -int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) -{ - if (a->__attr & 0x7fffffff == __WASI_CLOCKID_REALTIME) - *clk = CLOCK_REALTIME; - if (a->__attr & 0x7fffffff == __WASI_CLOCKID_MONOTONIC) - *clk = CLOCK_MONOTONIC; - return 0; -} -#endif - -int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared) -{ - *pshared = a->__attr>>31; - return 0; -} - -int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol) -{ - *protocol = a->__attr / 8U % 2; - return 0; -} -int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared) -{ - *pshared = a->__attr / 128U % 2; - return 0; -} - -int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) -{ - *robust = a->__attr / 4U % 2; - return 0; -} - -int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type) -{ - *type = a->__attr & 3; - return 0; -} - -int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared) -{ - *pshared = a->__attr[0]; - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c deleted file mode 100644 index 589ff676e87da59e06df362ff5e431a3616ece3e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) -{ -#ifdef __wasilibc_unmodified_upstream - if (size > SIZE_MAX/8) return EINVAL; -#else - /* WASI doesn't have memory protection required for stack guards. */ - if (size > 0) return EINVAL; -#endif - a->_a_guardsize = size; - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c deleted file mode 100644 index 0a41f0d1a11497de16cef9f25c17938033745237..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param) -{ -#ifdef __wasilibc_unmodified_upstream - a->_a_prio = param->sched_priority; -#else - if (param->sched_priority != 0) return ENOTSUP; -#endif - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c deleted file mode 100644 index 681827f8cc9fabc53b01cda91eae3ade51880b81..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c +++ /dev/null @@ -1,113 +0,0 @@ -#define _GNU_SOURCE -#include -#include "pthread_impl.h" -#include "syscall.h" - -#ifdef __wasilibc_unmodified_upstream -hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c(); - -long __cancel() -{ - pthread_t self = __pthread_self(); - if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync) - pthread_exit(PTHREAD_CANCELED); - self->canceldisable = PTHREAD_CANCEL_DISABLE; - return -ECANCELED; -} - -long __syscall_cp_asm(volatile void *, syscall_arg_t, - syscall_arg_t, syscall_arg_t, syscall_arg_t, - syscall_arg_t, syscall_arg_t, syscall_arg_t); - -long __syscall_cp_c(syscall_arg_t nr, - syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, - syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) -{ - pthread_t self; - long r; - int st; - - if ((st=(self=__pthread_self())->canceldisable) - && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close)) - return __syscall(nr, u, v, w, x, y, z); - - r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z); - if (r==-EINTR && nr!=SYS_close && self->cancel && - self->canceldisable != PTHREAD_CANCEL_DISABLE) - r = __cancel(); - return r; -} - -static void _sigaddset(sigset_t *set, int sig) -{ - unsigned s = sig-1; - set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); -} - -extern hidden const char __cp_begin[1], __cp_end[1], __cp_cancel[1]; - -static void cancel_handler(int sig, siginfo_t *si, void *ctx) -{ - pthread_t self = __pthread_self(); - ucontext_t *uc = ctx; - uintptr_t pc = uc->uc_mcontext.MC_PC; - - a_barrier(); - if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return; - - _sigaddset(&uc->uc_sigmask, SIGCANCEL); - - if (self->cancelasync) { - pthread_sigmask(SIG_SETMASK, &uc->uc_sigmask, 0); - __cancel(); - } - - if (pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) { - uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel; -#ifdef CANCEL_GOT - uc->uc_mcontext.MC_GOT = CANCEL_GOT; -#endif - return; - } - - __syscall(SYS_tkill, self->tid, SIGCANCEL); -} - -void __testcancel() -{ - pthread_t self = __pthread_self(); - if (self->cancel && !self->canceldisable) - __cancel(); -} - -static void init_cancellation() -{ - struct sigaction sa = { - .sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK, - .sa_sigaction = cancel_handler - }; - memset(&sa.sa_mask, -1, _NSIG/8); - __libc_sigaction(SIGCANCEL, &sa, 0); -} - -int pthread_cancel(pthread_t t) -{ - static int init; - if (!init) { - init_cancellation(); - init = 1; - } - a_store(&t->cancel, 1); - if (t == pthread_self()) { - if (t->canceldisable == PTHREAD_CANCEL_ENABLE && t->cancelasync) - pthread_exit(PTHREAD_CANCELED); - return 0; - } - return pthread_kill(t, SIGCANCEL); -} -#else -int pthread_cancel(pthread_t t) -{ - return ENOTSUP; -} -#endif diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c deleted file mode 100644 index 21ca070c3ecde0e9c3e44cea86fab3096ce6b651..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "pthread_impl.h" - -#ifndef __wasilibc_unmodified_upstream -#include -#endif - -int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk) -{ -#ifdef __wasilibc_unmodified_upstream - if (clk < 0 || clk-2U < 2) return EINVAL; -#else - if (clk->id < 0 || clk->id-2U < 2) return EINVAL; -#endif - a->__attr &= 0x80000000; -#ifdef __wasilibc_unmodified_upstream - a->__attr |= clk; -#else - a->__attr |= clk->id; -#endif - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c deleted file mode 100644 index 6325f9ba6d6d7ca2bb1d47b1fb407ad5a080f7ae..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c +++ /dev/null @@ -1,105 +0,0 @@ -#include "pthread_impl.h" -#include "fork_impl.h" - -volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; -void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; - -static void (*keys[PTHREAD_KEYS_MAX])(void *); - -static pthread_rwlock_t key_lock = PTHREAD_RWLOCK_INITIALIZER; - -static pthread_key_t next_key; - -static void nodtor(void *dummy) -{ -} - -static void dummy_0(void) -{ -} - -weak_alias(dummy_0, __tl_lock); -weak_alias(dummy_0, __tl_unlock); - -#ifdef __wasilibc_unmodified_upstream // WASI lacks fork -void __pthread_key_atfork(int who) -{ - if (who<0) __pthread_rwlock_rdlock(&key_lock); - else if (!who) __pthread_rwlock_unlock(&key_lock); - else key_lock = (pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER; -} -#endif - -int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) -{ - pthread_t self = __pthread_self(); - - /* This can only happen in the main thread before - * pthread_create has been called. */ - if (!self->tsd) self->tsd = __pthread_tsd_main; - - /* Purely a sentinel value since null means slot is free. */ - if (!dtor) dtor = nodtor; - - __pthread_rwlock_wrlock(&key_lock); - pthread_key_t j = next_key; - do { - if (!keys[j]) { - keys[next_key = *k = j] = dtor; - __pthread_rwlock_unlock(&key_lock); - return 0; - } - } while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key); - - __pthread_rwlock_unlock(&key_lock); - return EAGAIN; -} - -int __pthread_key_delete(pthread_key_t k) -{ - sigset_t set; - pthread_t self = __pthread_self(), td=self; - -#ifdef __wasilibc_unmodified_upstream - __block_app_sigs(&set); -#endif - __pthread_rwlock_wrlock(&key_lock); - - __tl_lock(); - do td->tsd[k] = 0; - while ((td=td->next)!=self); - __tl_unlock(); - - keys[k] = 0; - - __pthread_rwlock_unlock(&key_lock); -#ifdef __wasilibc_unmodified_upstream - __restore_sigs(&set); -#endif - - return 0; -} - -void __pthread_tsd_run_dtors() -{ - pthread_t self = __pthread_self(); - int i, j; - for (j=0; self->tsd_used && jtsd_used = 0; - for (i=0; itsd[i]; - void (*dtor)(void *) = keys[i]; - self->tsd[i] = 0; - if (val && dtor && dtor != nodtor) { - __pthread_rwlock_unlock(&key_lock); - dtor(val); - __pthread_rwlock_rdlock(&key_lock); - } - } - __pthread_rwlock_unlock(&key_lock); - } -} - -weak_alias(__pthread_key_create, pthread_key_create); -weak_alias(__pthread_key_delete, pthread_key_delete); diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c deleted file mode 100644 index e53c39c684e797c916f55c638ff577f9278ed9ac..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c +++ /dev/null @@ -1,18 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_destroy(pthread_mutex_t *mutex) -{ -#ifdef __wasilibc_unmodified_upstream - /* If the mutex being destroyed is process-shared and has nontrivial - * type (tracking ownership), it might be in the pending slot of a - * robust_list; wait for quiescence. */ - if (mutex->_m_type > 128) __vm_wait(); -#else - /* For now, wasi-libc chooses to avoid implementing robust mutex support - * though this could be added later. The error code indicates that the - * mutex was an invalid type, but it would be more accurate as - * "unimplemented". */ - if (mutex->_m_type > 128) return EINVAL; -#endif - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c deleted file mode 100644 index 84b02ba130ef0d07de7737549a9daa7dcffc36e9..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "pthread_impl.h" -#include "syscall.h" - -static volatile int check_pi_result = -1; - -int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol) -{ - int r; - switch (protocol) { - case PTHREAD_PRIO_NONE: - a->__attr &= ~8; - return 0; - case PTHREAD_PRIO_INHERIT: -#ifdef __wasilibc_unmodified_upstream - r = check_pi_result; - if (r < 0) { - volatile int lk = 0; - r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0); - a_store(&check_pi_result, r); - } - if (r) return r; - a->__attr |= 8; - return 0; -#else - return ENOTSUP; -#endif - case PTHREAD_PRIO_PROTECT: - return ENOTSUP; - default: - return EINVAL; - } -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c deleted file mode 100644 index 68c7d65d8176b680f32186c788d0c768b0d90687..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "pthread_impl.h" -#include "syscall.h" - -static volatile int check_robust_result = -1; - -int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust) -{ -#ifdef __wasilibc_unmodified_upstream - if (robust > 1U) return EINVAL; - if (robust) { - int r = check_robust_result; - if (r < 0) { - void *p; - size_t l; - r = -__syscall(SYS_get_robust_list, 0, &p, &l); - a_store(&check_robust_result, r); - } - if (r) return r; - a->__attr |= 4; - return 0; - } - a->__attr &= ~4; - return 0; -#else - if (robust) return EINVAL; - return 0; -#endif -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c b/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c deleted file mode 100644 index 1ea2856d67cc440fd6d2fdf0eb41731c3e6faf2c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c +++ /dev/null @@ -1,14 +0,0 @@ -#include "pthread_impl.h" -#include - -#if !defined(__wasilibc_unmodified_upstream) && defined(__wasm__) -_Thread_local struct pthread __wasilibc_pthread_self; -#endif - -static pthread_t __pthread_self_internal() -{ - return __pthread_self(); -} - -weak_alias(__pthread_self_internal, pthread_self); -weak_alias(__pthread_self_internal, thrd_current); diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/__secs_to_tm.c b/lib/libc/wasi/libc-top-half/musl/src/time/__secs_to_tm.c deleted file mode 100644 index 093d9021ae010f0a13b1cfaf470afb551dcc7d66..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/__secs_to_tm.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "time_impl.h" -#include - -/* 2000-03-01 (mod 400 year, immediately after feb29 */ -#define LEAPOCH (946684800LL + 86400*(31+29)) - -#define DAYS_PER_400Y (365*400 + 97) -#define DAYS_PER_100Y (365*100 + 24) -#define DAYS_PER_4Y (365*4 + 1) - -int __secs_to_tm(long long t, struct tm *tm) -{ - long long days, secs, years; - int remdays, remsecs, remyears; - int qc_cycles, c_cycles, q_cycles; - int months; - int wday, yday, leap; - static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29}; - - /* Reject time_t values whose year would overflow int */ - if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL) - return -1; - - secs = t - LEAPOCH; - days = secs / 86400; - remsecs = secs % 86400; - if (remsecs < 0) { - remsecs += 86400; - days--; - } - - wday = (3+days)%7; - if (wday < 0) wday += 7; - - qc_cycles = days / DAYS_PER_400Y; - remdays = days % DAYS_PER_400Y; - if (remdays < 0) { - remdays += DAYS_PER_400Y; - qc_cycles--; - } - - c_cycles = remdays / DAYS_PER_100Y; - if (c_cycles == 4) c_cycles--; - remdays -= c_cycles * DAYS_PER_100Y; - - q_cycles = remdays / DAYS_PER_4Y; - if (q_cycles == 25) q_cycles--; - remdays -= q_cycles * DAYS_PER_4Y; - - remyears = remdays / 365; - if (remyears == 4) remyears--; - remdays -= remyears * 365; - - leap = !remyears && (q_cycles || !c_cycles); - yday = remdays + 31 + 28 + leap; - if (yday >= 365+leap) yday -= 365+leap; - - years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles; - - for (months=0; days_in_month[months] <= remdays; months++) - remdays -= days_in_month[months]; - - if (months >= 10) { - months -= 12; - years++; - } - - if (years+100 > INT_MAX || years+100 < INT_MIN) - return -1; - - tm->tm_year = years + 100; - tm->tm_mon = months + 2; - tm->tm_mday = remdays + 1; - tm->tm_wday = wday; - tm->tm_yday = yday; - - tm->tm_hour = remsecs / 3600; - tm->tm_min = remsecs / 60 % 60; - tm->tm_sec = remsecs % 60; - - return 0; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/__tm_to_secs.c b/lib/libc/wasi/libc-top-half/musl/src/time/__tm_to_secs.c deleted file mode 100644 index c29fa985a6dd58fdffa9190e995d993b9e4c4427..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/__tm_to_secs.c +++ /dev/null @@ -1,24 +0,0 @@ -#include "time_impl.h" - -long long __tm_to_secs(const struct tm *tm) -{ - int is_leap; - long long year = tm->tm_year; - int month = tm->tm_mon; - if (month >= 12 || month < 0) { - int adj = month / 12; - month %= 12; - if (month < 0) { - adj--; - month += 12; - } - year += adj; - } - long long t = __year_to_secs(year, &is_leap); - t += __month_to_secs(month, is_leap); - t += 86400LL * (tm->tm_mday-1); - t += 3600LL * tm->tm_hour; - t += 60LL * tm->tm_min; - t += tm->tm_sec; - return t; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/__tz.c b/lib/libc/wasi/libc-top-half/musl/src/time/__tz.c deleted file mode 100644 index ee05eb58f8444241bdaad5b7ae47fb3a83c9fa3f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/__tz.c +++ /dev/null @@ -1,455 +0,0 @@ -#include "time_impl.h" -#include -#include -#include -#include -#ifdef __wasilibc_unmodified_upstream // timezone data -#include -#include -#endif -#include "libc.h" -#include "lock.h" -#include "fork_impl.h" - -#ifdef __wasilibc_unmodified_upstream // timezone data -long __timezone = 0; -int __daylight = 0; -char *__tzname[2] = { 0, 0 }; - -weak_alias(__timezone, timezone); -weak_alias(__daylight, daylight); -weak_alias(__tzname, tzname); - -static char std_name[TZNAME_MAX+1]; -static char dst_name[TZNAME_MAX+1]; -#endif -const char __utc[] = "UTC"; - -#ifdef __wasilibc_unmodified_upstream // timezone data -static int dst_off; -static int r0[5], r1[5]; - -static const unsigned char *zi, *trans, *index, *types, *abbrevs, *abbrevs_end; -static size_t map_size; - -static char old_tz_buf[32]; -static char *old_tz = old_tz_buf; -static size_t old_tz_size = sizeof old_tz_buf; - -static volatile int lock[1]; -volatile int *const __timezone_lockptr = lock; - -static int getint(const char **p) -{ - unsigned x; - for (x=0; **p-'0'<10U; (*p)++) x = **p-'0' + 10*x; - return x; -} - -static int getoff(const char **p) -{ - int neg = 0; - if (**p == '-') { - ++*p; - neg = 1; - } else if (**p == '+') { - ++*p; - } - int off = 3600*getint(p); - if (**p == ':') { - ++*p; - off += 60*getint(p); - if (**p == ':') { - ++*p; - off += getint(p); - } - } - return neg ? -off : off; -} - -static void getrule(const char **p, int rule[5]) -{ - int r = rule[0] = **p; - - if (r!='M') { - if (r=='J') ++*p; - else rule[0] = 0; - rule[1] = getint(p); - } else { - ++*p; rule[1] = getint(p); - ++*p; rule[2] = getint(p); - ++*p; rule[3] = getint(p); - } - - if (**p=='/') { - ++*p; - rule[4] = getoff(p); - } else { - rule[4] = 7200; - } -} - -static void getname(char *d, const char **p) -{ - int i; - if (**p == '<') { - ++*p; - for (i=0; (*p)[i] && (*p)[i]!='>'; i++) - if (i PATH_MAX+1) s = __utc, i = 3; - if (i >= old_tz_size) { - old_tz_size *= 2; - if (i >= old_tz_size) old_tz_size = i+1; - if (old_tz_size > PATH_MAX+2) old_tz_size = PATH_MAX+2; - old_tz = malloc(old_tz_size); - } - if (old_tz) memcpy(old_tz, s, i+1); - - int posix_form = 0; - if (*s != ':') { - p = s; - char dummy_name[TZNAME_MAX+1]; - getname(dummy_name, &p); - if (p!=s && (*p == '+' || *p == '-' || isdigit(*p) - || !strcmp(dummy_name, "UTC") - || !strcmp(dummy_name, "GMT"))) - posix_form = 1; - } - - /* Non-suid can use an absolute tzfile pathname or a relative - * pathame beginning with "."; in secure mode, only the - * standard path will be searched. */ - if (!posix_form) { - if (*s == ':') s++; - if (*s == '/' || *s == '.') { - if (!libc.secure || !strcmp(s, "/etc/localtime")) - map = __map_file(s, &map_size); - } else { - size_t l = strlen(s); - if (l <= NAME_MAX && !strchr(s, '.')) { - memcpy(pathname, s, l+1); - pathname[l] = 0; - for (try=search; !map && *try; try+=l+1) { - l = strlen(try); - memcpy(pathname-l, try, l); - map = __map_file(pathname-l, &map_size); - } - } - } - if (!map) s = __utc; - } - if (map && (map_size < 44 || memcmp(map, "TZif", 4))) { - __munmap((void *)map, map_size); - map = 0; - s = __utc; - } - - zi = map; - if (map) { - int scale = 2; - if (map[4]!='1') { - size_t skip = zi_dotprod(zi+20, VEC(1,1,8,5,6,1), 6); - trans = zi+skip+44+44; - scale++; - } else { - trans = zi+44; - } - index = trans + (zi_read32(trans-12) << scale); - types = index + zi_read32(trans-12); - abbrevs = types + 6*zi_read32(trans-8); - abbrevs_end = abbrevs + zi_read32(trans-4); - if (zi[map_size-1] == '\n') { - for (s = (const char *)zi+map_size-2; *s!='\n'; s--); - s++; - } else { - const unsigned char *p; - __tzname[0] = __tzname[1] = 0; - __daylight = __timezone = dst_off = 0; - for (p=types; p>scale, m; - - if (!n) { - if (alt) *alt = 0; - return 0; - } - - /* Binary search for 'most-recent rule before t'. */ - while (n > 1) { - m = a + n/2; - x = zi_read32(trans + (m<>scale; - if (a == n-1) return -1; - if (a == 0) { - x = zi_read32(trans); - if (scale == 3) x = x<<32 | zi_read32(trans + 4); - else x = (int32_t)x; - /* Find the lowest non-DST type, or 0 if none. */ - size_t j = 0; - for (size_t i=abbrevs-types; i; i-=6) { - if (!types[i-6+4]) j = i-6; - } - if (local) off = (int32_t)zi_read32(types + j); - /* If t is before first transition, use the above-found type - * and the index-zero (after transition) type as the alt. */ - if (t - off < (int64_t)x) { - if (alt) *alt = index[0]; - return j/6; - } - } - - /* Try to find a neighboring opposite-DST-status rule. */ - if (alt) { - if (a && types[6*index[a-1]+4] != types[6*index[a]+4]) - *alt = index[a-1]; - else if (a+1>(m-1))&1); -} - -/* Convert a POSIX DST rule plus year to seconds since epoch. */ - -static long long rule_to_secs(const int *rule, int year) -{ - int is_leap; - long long t = __year_to_secs(year, &is_leap); - int x, m, n, d; - if (rule[0]!='M') { - x = rule[1]; - if (rule[0]=='J' && (x < 60 || !is_leap)) x--; - t += 86400 * x; - } else { - m = rule[1]; - n = rule[2]; - d = rule[3]; - t += __month_to_secs(m-1, is_leap); - int wday = (int)((t + 4*86400) % (7*86400)) / 86400; - int days = d - wday; - if (days < 0) days += 7; - if (n == 5 && days+28 >= days_in_month(m, is_leap)) n = 4; - t += 86400 * (days + 7*(n-1)); - } - t += rule[4]; - return t; -} - -/* Determine the time zone in effect for a given time in seconds since the - * epoch. It can be given in local or universal time. The results will - * indicate whether DST is in effect at the queried time, and will give both - * the GMT offset for the active zone/DST rule and the opposite DST. This - * enables a caller to efficiently adjust for the case where an explicit - * DST specification mismatches what would be in effect at the time. */ - -void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppoff, const char **zonename) -{ - LOCK(lock); - - do_tzset(); - - if (zi) { - size_t alt, i = scan_trans(t, local, &alt); - if (i != -1) { - *isdst = types[6*i+4]; - *offset = (int32_t)zi_read32(types+6*i); - *zonename = (const char *)abbrevs + types[6*i+5]; - if (oppoff) *oppoff = (int32_t)zi_read32(types+6*alt); - UNLOCK(lock); - return; - } - } - - if (!__daylight) goto std; - - /* FIXME: may be broken if DST changes right at year boundary? - * Also, this could be more efficient.*/ - long long y = t / 31556952 + 70; - while (__year_to_secs(y, 0) > t) y--; - while (__year_to_secs(y+1, 0) < t) y++; - - long long t0 = rule_to_secs(r0, y); - long long t1 = rule_to_secs(r1, y); - - if (!local) { - t0 += __timezone; - t1 += dst_off; - } - if (t0 < t1) { - if (t >= t0 && t < t1) goto dst; - goto std; - } else { - if (t >= t1 && t < t0) goto std; - goto dst; - } -std: - *isdst = 0; - *offset = -__timezone; - if (oppoff) *oppoff = -dst_off; - *zonename = __tzname[0]; - UNLOCK(lock); - return; -dst: - *isdst = 1; - *offset = -dst_off; - if (oppoff) *oppoff = -__timezone; - *zonename = __tzname[1]; - UNLOCK(lock); -} - -static void __tzset() -{ - LOCK(lock); - do_tzset(); - UNLOCK(lock); -} - -weak_alias(__tzset, tzset); -#else -void __secs_to_zone(long long t, int local, int *isdst, int *offset, long *oppoff, const char **zonename) -{ - // Minimalist implementation for now. - if (isdst) - *isdst = 0; - if (offset) - *offset = 0; - if (oppoff) - *oppoff = 0; - if (zonename) - *zonename = __utc; -} -#endif - -const char *__tm_to_tzname(const struct tm *tm) -{ - const void *p = tm->__tm_zone; -#ifdef __wasilibc_unmodified_upstream // timezone data - LOCK(lock); - do_tzset(); - if (p != __utc && p != __tzname[0] && p != __tzname[1] && - (!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs)) - p = ""; - UNLOCK(lock); -#endif - return p; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/getdate.c b/lib/libc/wasi/libc-top-half/musl/src/time/getdate.c deleted file mode 100644 index 058c48b9d6de652a5615081467cb7564d184e4ba..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/getdate.c +++ /dev/null @@ -1,52 +0,0 @@ -#include -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) -#include -#endif -#include -#include -#include - -int getdate_err; - -struct tm *getdate(const char *s) -{ - static struct tm tmbuf; - struct tm *ret = 0; - char *datemsk = getenv("DATEMSK"); - FILE *f = 0; - char fmt[100], *p; - int cs; - -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs); -#endif - - if (!datemsk) { - getdate_err = 1; - goto out; - } - - f = fopen(datemsk, "rbe"); - if (!f) { - if (errno == ENOMEM) getdate_err = 6; - else getdate_err = 2; - goto out; - } - - while (fgets(fmt, sizeof fmt, f)) { - p = strptime(s, fmt, &tmbuf); - if (p && !*p) { - ret = &tmbuf; - goto out; - } - } - - if (ferror(f)) getdate_err = 5; - else getdate_err = 7; -out: - if (f) fclose(f); -#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) - pthread_setcancelstate(cs, 0); -#endif - return ret; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/gmtime.c b/lib/libc/wasi/libc-top-half/musl/src/time/gmtime.c deleted file mode 100644 index 6320b6377e62310dfde727d165085e162480d7d2..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/gmtime.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "time_impl.h" -#include - -struct tm *gmtime(const time_t *t) -{ - static struct tm tm; - return __gmtime_r(t, &tm); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/gmtime_r.c b/lib/libc/wasi/libc-top-half/musl/src/time/gmtime_r.c deleted file mode 100644 index 22aec2c2e2ef21b8a1beb5bcd84da5988b3b41de..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/gmtime_r.c +++ /dev/null @@ -1,16 +0,0 @@ -#include "time_impl.h" -#include - -struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) -{ - if (__secs_to_tm(*t, tm) < 0) { - errno = EOVERFLOW; - return 0; - } - tm->tm_isdst = 0; - tm->__tm_gmtoff = 0; - tm->__tm_zone = __utc; - return tm; -} - -weak_alias(__gmtime_r, gmtime_r); diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/localtime.c b/lib/libc/wasi/libc-top-half/musl/src/time/localtime.c deleted file mode 100644 index 5210423230ca237de6cbaecbf666bcf73ac12af1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/localtime.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "time_impl.h" - -struct tm *localtime(const time_t *t) -{ - static struct tm tm; - return __localtime_r(t, &tm); -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/localtime_r.c b/lib/libc/wasi/libc-top-half/musl/src/time/localtime_r.c deleted file mode 100644 index 1a15b314d0f1209db127a9f1b50229249a11515c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/localtime_r.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "time_impl.h" -#include -#include - -struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm) -{ - /* Reject time_t values whose year would overflow int because - * __secs_to_zone cannot safely handle them. */ - if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) { - errno = EOVERFLOW; - return 0; - } - __secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone); - if (__secs_to_tm((long long)*t + tm->__tm_gmtoff, tm) < 0) { - errno = EOVERFLOW; - return 0; - } - return tm; -} - -weak_alias(__localtime_r, localtime_r); diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/mktime.c b/lib/libc/wasi/libc-top-half/musl/src/time/mktime.c deleted file mode 100644 index bad3f0765a089fd9f97e6f0d651b15fd19d949ed..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/mktime.c +++ /dev/null @@ -1,28 +0,0 @@ -#include "time_impl.h" -#include - -time_t mktime(struct tm *tm) -{ - struct tm new; - long opp; - long long t = __tm_to_secs(tm); - - __secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); - - if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst) - t -= opp - new.__tm_gmtoff; - - t -= new.__tm_gmtoff; - if ((time_t)t != t) goto error; - - __secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); - - if (__secs_to_tm(t + new.__tm_gmtoff, &new) < 0) goto error; - - *tm = new; - return t; - -error: - errno = EOVERFLOW; - return -1; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/strftime.c b/lib/libc/wasi/libc-top-half/musl/src/time/strftime.c deleted file mode 100644 index 6efde91b05c46755d8c8358fd4265ca59a27e008..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/strftime.c +++ /dev/null @@ -1,291 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include "locale_impl.h" -#include "time_impl.h" - -static int is_leap(int y) -{ - /* Avoid overflow */ - if (y>INT_MAX-1900) y -= 2000; - y += 1900; - return !(y%4) && ((y%100) || !(y%400)); -} - -static int week_num(const struct tm *tm) -{ - int val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; - /* If 1 Jan is just 1-3 days past Monday, - * the previous week is also in this year. */ - if ((tm->tm_wday + 371U - tm->tm_yday - 2) % 7 <= 2) - val++; - if (!val) { - val = 52; - /* If 31 December of prev year a Thursday, - * or Friday of a leap year, then the - * prev year has 53 weeks. */ - int dec31 = (tm->tm_wday + 7U - tm->tm_yday - 1) % 7; - if (dec31 == 4 || (dec31 == 5 && is_leap(tm->tm_year%400-1))) - val++; - } else if (val == 53) { - /* If 1 January is not a Thursday, and not - * a Wednesday of a leap year, then this - * year has only 52 weeks. */ - int jan1 = (tm->tm_wday + 371U - tm->tm_yday) % 7; - if (jan1 != 4 && (jan1 != 3 || !is_leap(tm->tm_year))) - val = 1; - } - return val; -} - -const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad) -{ - nl_item item; - long long val; - const char *fmt = "-"; - int width = 2, def_pad = '0'; - - switch (f) { - case 'a': - if (tm->tm_wday > 6U) goto string; - item = ABDAY_1 + tm->tm_wday; - goto nl_strcat; - case 'A': - if (tm->tm_wday > 6U) goto string; - item = DAY_1 + tm->tm_wday; - goto nl_strcat; - case 'h': - case 'b': - if (tm->tm_mon > 11U) goto string; - item = ABMON_1 + tm->tm_mon; - goto nl_strcat; - case 'B': - if (tm->tm_mon > 11U) goto string; - item = MON_1 + tm->tm_mon; - goto nl_strcat; - case 'c': - item = D_T_FMT; - goto nl_strftime; - case 'C': - val = (1900LL+tm->tm_year) / 100; - goto number; - case 'e': - def_pad = '_'; - case 'd': - val = tm->tm_mday; - goto number; - case 'D': - fmt = "%m/%d/%y"; - goto recu_strftime; - case 'F': - fmt = "%Y-%m-%d"; - goto recu_strftime; - case 'g': - case 'G': - val = tm->tm_year + 1900LL; - if (tm->tm_yday < 3 && week_num(tm) != 1) val--; - else if (tm->tm_yday > 360 && week_num(tm) == 1) val++; - if (f=='g') val %= 100; - else width = 4; - goto number; - case 'H': - val = tm->tm_hour; - goto number; - case 'I': - val = tm->tm_hour; - if (!val) val = 12; - else if (val > 12) val -= 12; - goto number; - case 'j': - val = tm->tm_yday+1; - width = 3; - goto number; - case 'm': - val = tm->tm_mon+1; - goto number; - case 'M': - val = tm->tm_min; - goto number; - case 'n': - *l = 1; - return "\n"; - case 'p': - item = tm->tm_hour >= 12 ? PM_STR : AM_STR; - goto nl_strcat; - case 'r': - item = T_FMT_AMPM; - goto nl_strftime; - case 'R': - fmt = "%H:%M"; - goto recu_strftime; - case 's': - val = __tm_to_secs(tm) - tm->__tm_gmtoff; - width = 1; - goto number; - case 'S': - val = tm->tm_sec; - goto number; - case 't': - *l = 1; - return "\t"; - case 'T': - fmt = "%H:%M:%S"; - goto recu_strftime; - case 'u': - val = tm->tm_wday ? tm->tm_wday : 7; - width = 1; - goto number; - case 'U': - val = (tm->tm_yday + 7U - tm->tm_wday) / 7; - goto number; - case 'W': - val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; - goto number; - case 'V': - val = week_num(tm); - goto number; - case 'w': - val = tm->tm_wday; - width = 1; - goto number; - case 'x': - item = D_FMT; - goto nl_strftime; - case 'X': - item = T_FMT; - goto nl_strftime; - case 'y': - val = (tm->tm_year + 1900LL) % 100; - if (val < 0) val = -val; - goto number; - case 'Y': - val = tm->tm_year + 1900LL; - if (val >= 10000) { - *l = snprintf(*s, sizeof *s, "+%lld", val); - return *s; - } - width = 4; - goto number; - case 'z': - if (tm->tm_isdst < 0) { - *l = 0; - return ""; - } -#ifdef __wasilibc_unmodified_upstream // wasi-libc's __tm_gmtoff is an int - *l = snprintf(*s, sizeof *s, "%+.4ld", -#else - *l = snprintf(*s, sizeof *s, "%+.4d", -#endif - tm->__tm_gmtoff/3600*100 + tm->__tm_gmtoff%3600/60); - return *s; - case 'Z': - if (tm->tm_isdst < 0) { - *l = 0; - return ""; - } - fmt = __tm_to_tzname(tm); - goto string; - case '%': - *l = 1; - return "%"; - default: - return 0; - } -number: - switch (pad ? pad : def_pad) { - case '-': *l = snprintf(*s, sizeof *s, "%lld", val); break; - case '_': *l = snprintf(*s, sizeof *s, "%*lld", width, val); break; - case '0': - default: *l = snprintf(*s, sizeof *s, "%0*lld", width, val); break; - } - return *s; -nl_strcat: - fmt = __nl_langinfo_l(item, loc); -string: - *l = strlen(fmt); - return fmt; -nl_strftime: - fmt = __nl_langinfo_l(item, loc); -recu_strftime: - *l = __strftime_l(*s, sizeof *s, fmt, tm, loc); - if (!*l) return 0; - return *s; -} - -size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc) -{ - size_t l, k; - char buf[100]; - char *p; - const char *t; - int pad, plus; - unsigned long width; - for (l=0; ltm_year < -1900) { - s[l++] = '-'; - width--; - } else if (plus && d+(width-k) >= (*p=='C'?3:5)) { - s[l++] = '+'; - width--; - } - for (; width > k && l < n; width--) - s[l++] = '0'; - } - if (k > n-l) k = n-l; - memcpy(s+l, t, k); - l += k; - } - if (n) { - if (l==n) l=n-1; - s[l] = 0; - } - return 0; -} - -size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) -{ - return __strftime_l(s, n, f, tm, CURRENT_LOCALE); -} - -weak_alias(__strftime_l, strftime_l); diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/time_impl.h b/lib/libc/wasi/libc-top-half/musl/src/time/time_impl.h deleted file mode 100644 index 1a378c2506fa8dda9f8fbe09c0d24a759b3f2729..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/time_impl.h +++ /dev/null @@ -1,15 +0,0 @@ -#include - -hidden int __days_in_month(int, int); -hidden int __month_to_secs(int, int); -hidden long long __year_to_secs(long long, int *); -hidden long long __tm_to_secs(const struct tm *); -hidden const char *__tm_to_tzname(const struct tm *); -hidden int __secs_to_tm(long long, struct tm *); -#ifdef __wasilibc_unmodified_upstream // type of __tm_gmtoff -hidden void __secs_to_zone(long long, int, int *, long *, long *, const char **); -#else -hidden void __secs_to_zone(long long, int, int *, int *, long *, const char **); -#endif -hidden const char *__strftime_fmt_1(char (*)[100], size_t *, int, const struct tm *, locale_t, int); -extern hidden const char __utc[]; diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/timegm.c b/lib/libc/wasi/libc-top-half/musl/src/time/timegm.c deleted file mode 100644 index 4e5907d7f56027f960c088014d935fb9c3682ca1..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/timegm.c +++ /dev/null @@ -1,18 +0,0 @@ -#define _GNU_SOURCE -#include "time_impl.h" -#include - -time_t timegm(struct tm *tm) -{ - struct tm new; - long long t = __tm_to_secs(tm); - if (__secs_to_tm(t, &new) < 0) { - errno = EOVERFLOW; - return -1; - } - *tm = new; - tm->tm_isdst = 0; - tm->__tm_gmtoff = 0; - tm->__tm_zone = __utc; - return t; -} diff --git a/lib/libc/wasi/libc-top-half/musl/src/time/wcsftime.c b/lib/libc/wasi/libc-top-half/musl/src/time/wcsftime.c deleted file mode 100644 index 8e1437b33f9ce808597adcdf8db033514cb7fea8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/musl/src/time/wcsftime.c +++ /dev/null @@ -1,71 +0,0 @@ -#include -#include -#include -#include "locale_impl.h" -#include "time_impl.h" - -size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, const struct tm *restrict tm, locale_t loc) -{ - size_t l, k; - char buf[100]; - wchar_t wbuf[100]; - wchar_t *p; - const char *t_mb; - const wchar_t *t; - int pad, plus; - unsigned long width; - for (l=0; ltm_year >= 10000-1900) - s[l++] = '+'; - else if (tm->tm_year < -1900) - s[l++] = '-'; - else - width++; - for (; width > k && l < n; width--) - s[l++] = '0'; - } - if (k >= n-l) k = n-l; - wmemcpy(s+l, t, k); - l += k; - } - if (n) { - if (l==n) l=n-1; - s[l] = 0; - } - return 0; -} - -size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, const struct tm *restrict tm) -{ - return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE); -} - -weak_alias(__wcsftime_l, wcsftime_l); diff --git a/lib/libc/wasi/libc-top-half/sources/arc4random.c b/lib/libc/wasi/libc-top-half/sources/arc4random.c deleted file mode 100644 index 9898206bb78ee87c829603e3edfca202a69c8057..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/libc-top-half/sources/arc4random.c +++ /dev/null @@ -1,160 +0,0 @@ -#include -#include -#include -#include -#include - -#define RNG_RESERVE_LEN 512 - -#define CHACHA20_KEYBYTES 32 -#define CHACHA20_BLOCKBYTES 64 - -#define ROTL32(x, b) (uint32_t)(((x) << (b)) | ((x) >> (32 - (b)))) - -#define CHACHA20_QUARTERROUND(A, B, C, D) \ - A += B; \ - D = ROTL32(D ^ A, 16); \ - C += D; \ - B = ROTL32(B ^ C, 12); \ - A += B; \ - D = ROTL32(D ^ A, 8); \ - C += D; \ - B = ROTL32(B ^ C, 7) - -static void CHACHA20_ROUNDS(uint32_t st[16]) -{ - int i; - - for (i = 0; i < 20; i += 2) { - CHACHA20_QUARTERROUND(st[0], st[4], st[8], st[12]); - CHACHA20_QUARTERROUND(st[1], st[5], st[9], st[13]); - CHACHA20_QUARTERROUND(st[2], st[6], st[10], st[14]); - CHACHA20_QUARTERROUND(st[3], st[7], st[11], st[15]); - CHACHA20_QUARTERROUND(st[0], st[5], st[10], st[15]); - CHACHA20_QUARTERROUND(st[1], st[6], st[11], st[12]); - CHACHA20_QUARTERROUND(st[2], st[7], st[8], st[13]); - CHACHA20_QUARTERROUND(st[3], st[4], st[9], st[14]); - } -} - -static void chacha20_update(uint8_t out[CHACHA20_BLOCKBYTES], uint32_t st[16]) -{ - uint32_t ks[16]; - int i; - - memcpy(ks, st, 4 * 16); - CHACHA20_ROUNDS(st); - for (i = 0; i < 16; i++) { - ks[i] += st[i]; - } - memcpy(out, ks, CHACHA20_BLOCKBYTES); - st[12]++; -} - -static void chacha20_init(uint32_t st[16], const uint8_t key[CHACHA20_KEYBYTES]) -{ - static const uint32_t constants[4] = { 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 }; - memcpy(&st[0], constants, 4 * 4); - memcpy(&st[4], key, CHACHA20_KEYBYTES); - memset(&st[12], 0, 4 * 4); -} - -static int chacha20_rng(uint8_t* out, size_t len, uint8_t key[CHACHA20_KEYBYTES]) -{ - uint32_t st[16]; - size_t off; - - chacha20_init(st, key); - chacha20_update(&out[0], st); - memcpy(key, out, CHACHA20_KEYBYTES); - off = 0; - while (len >= CHACHA20_BLOCKBYTES) { - chacha20_update(&out[off], st); - len -= CHACHA20_BLOCKBYTES; - off += CHACHA20_BLOCKBYTES; - } - if (len > 0) { - uint8_t tmp[CHACHA20_BLOCKBYTES]; - chacha20_update(tmp, st); - memcpy(&out[off], tmp, len); - } - return 0; -} - -struct rng_state { - int initialized; - size_t off; - uint8_t key[CHACHA20_KEYBYTES]; - uint8_t reserve[RNG_RESERVE_LEN]; -}; - -void arc4random_buf(void* buffer, size_t len) -{ - static _Thread_local struct rng_state rng_state; - - unsigned char* buffer_ = (unsigned char*)buffer; - size_t off; - size_t remaining; - size_t partial; - - if (!rng_state.initialized) { - if (getentropy(rng_state.key, sizeof rng_state.key) != 0) { - assert(0); - } - rng_state.off = RNG_RESERVE_LEN; - rng_state.initialized = 1; - } - off = 0; - remaining = len; - while (remaining > 0) { - if (rng_state.off == RNG_RESERVE_LEN) { - while (remaining >= RNG_RESERVE_LEN) { - chacha20_rng(&buffer_[off], RNG_RESERVE_LEN, rng_state.key); - off += RNG_RESERVE_LEN; - remaining -= RNG_RESERVE_LEN; - } - if (remaining == 0) { - break; - } - chacha20_rng(&rng_state.reserve[0], RNG_RESERVE_LEN, rng_state.key); - rng_state.off = 0; - } - partial = RNG_RESERVE_LEN - rng_state.off; - if (remaining < partial) { - partial = remaining; - } - memcpy(&buffer_[off], &rng_state.reserve[rng_state.off], partial); - memset(&rng_state.reserve[rng_state.off], 0, partial); - rng_state.off += partial; - remaining -= partial; - off += partial; - } -} - -uint32_t arc4random(void) -{ - uint32_t v; - - arc4random_buf(&v, sizeof v); - - return v; -} - -uint32_t arc4random_uniform(const uint32_t upper_bound) -{ - uint32_t min; - uint32_t r; - - if (upper_bound < 2U) { - return 0; - } - min = (1U + ~upper_bound) % upper_bound; // = 2**32 mod upper_bound - do { - r = arc4random(); - } while (r < min); - - // r is now clamped to a set whose size mod upper_bound == 0. - // The worst case (2**31+1) requires 2 attempts on average. - - return r % upper_bound; -} diff --git a/lib/libc/wasi/thread-stub/pthread_barrier_destroy.c b/lib/libc/wasi/thread-stub/pthread_barrier_destroy.c deleted file mode 100644 index 2898c41a00f9fff5377826556e19a554242735ba..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_barrier_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_destroy(pthread_barrier_t *b) -{ - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_barrier_init.c b/lib/libc/wasi/thread-stub/pthread_barrier_init.c deleted file mode 100644 index 42eb6451b70cd0edb0db81ac4e5090b2599deade..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_barrier_init.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count) -{ - if (count-1 > INT_MAX-1) return EINVAL; - *b = (pthread_barrier_t){ ._b_limit = count-1 }; - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_barrier_wait.c b/lib/libc/wasi/thread-stub/pthread_barrier_wait.c deleted file mode 100644 index c5a4afb73e81378a425154ed1e8ffad344b653ab..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_barrier_wait.c +++ /dev/null @@ -1,7 +0,0 @@ -#include "pthread_impl.h" - -int pthread_barrier_wait(pthread_barrier_t *b) -{ - if (!b->_b_limit) return PTHREAD_BARRIER_SERIAL_THREAD; - __builtin_trap(); -} diff --git a/lib/libc/wasi/thread-stub/pthread_cond_broadcast.c b/lib/libc/wasi/thread-stub/pthread_cond_broadcast.c deleted file mode 100644 index ce318099659439f09af3e09b84e34d2c370ebb85..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_cond_broadcast.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_broadcast(pthread_cond_t *c) -{ - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_cond_destroy.c b/lib/libc/wasi/thread-stub/pthread_cond_destroy.c deleted file mode 100644 index 1d21a5a8bfc717d4dff16a229f563f4384493eb8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_cond_destroy.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_destroy(pthread_cond_t *c) -{ - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_cond_init.c b/lib/libc/wasi/thread-stub/pthread_cond_init.c deleted file mode 100644 index c32903b6c7154c712a74a1e8054b16c19d2dea59..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_cond_init.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a) -{ - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_cond_signal.c b/lib/libc/wasi/thread-stub/pthread_cond_signal.c deleted file mode 100644 index 4eb2774ae25ba78c105473ab1e722a0305e1aa19..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_cond_signal.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_signal(pthread_cond_t *c) -{ - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_cond_timedwait.c b/lib/libc/wasi/thread-stub/pthread_cond_timedwait.c deleted file mode 100644 index 0e7f9f835acf9c4956a6c122f29a1c23a31d302f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_cond_timedwait.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts) -{ - /* Error check mutexes must detect if they're not locked (UB for others) */ - if (!m->_m_count) return EPERM; - int ret = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, ts, 0); - if (ret == 0) return ETIMEDOUT; - if (ret != EINTR) return ret; - return 0; -} - -weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait); diff --git a/lib/libc/wasi/thread-stub/pthread_cond_wait.c b/lib/libc/wasi/thread-stub/pthread_cond_wait.c deleted file mode 100644 index 84a44b7bc0644f6b73253532cd328534fca8d28e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_cond_wait.c +++ /dev/null @@ -1,9 +0,0 @@ -#include "pthread_impl.h" - -int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m) -{ - /* Because there is no other thread that can signal us, this is a deadlock immediately. - The other possible choice is to return immediately (spurious wakeup), but that is likely to - just result in the program spinning forever on a condition that cannot become true. */ - __builtin_trap(); -} diff --git a/lib/libc/wasi/thread-stub/pthread_create.c b/lib/libc/wasi/thread-stub/pthread_create.c deleted file mode 100644 index 717564cd1bec9ad0650bc0c55280f68a6135616f..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_create.c +++ /dev/null @@ -1,19 +0,0 @@ -#include "pthread_impl.h" - -static void dummy_0() -{ -} -weak_alias(dummy_0, __acquire_ptc); -weak_alias(dummy_0, __release_ptc); - -int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg) -{ - /* - "The system lacked the necessary resources to create another thread, - or the system-imposed limit on the total number of threads in a process - {PTHREAD_THREADS_MAX} would be exceeded." - */ - return EAGAIN; -} - -weak_alias(__pthread_create, pthread_create); diff --git a/lib/libc/wasi/thread-stub/pthread_detach.c b/lib/libc/wasi/thread-stub/pthread_detach.c deleted file mode 100644 index 55953e1598b960f83fff8534de762c0c86a0df95..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_detach.c +++ /dev/null @@ -1,13 +0,0 @@ -#include "pthread_impl.h" - -static int __pthread_detach(pthread_t t) -{ - /* - If we are the only thread, when we exit the whole process exits. - So the storage will be reclaimed no matter what. - */ - return 0; -} - -weak_alias(__pthread_detach, pthread_detach); -weak_alias(__pthread_detach, thrd_detach); diff --git a/lib/libc/wasi/thread-stub/pthread_getattr_np.c b/lib/libc/wasi/thread-stub/pthread_getattr_np.c deleted file mode 100644 index d463de14349ac567bd1fd28b4771e480fc575015..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_getattr_np.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int pthread_getattr_np(pthread_t t, pthread_attr_t *a) -{ - *a = (pthread_attr_t){0}; - /* Can't join main thread. */ - a->_a_detach = PTHREAD_CREATE_DETACHED; - /* WASI doesn't have memory protection required for stack guards. */ - a->_a_guardsize = 0; - return 0; -} diff --git a/lib/libc/wasi/thread-stub/pthread_join.c b/lib/libc/wasi/thread-stub/pthread_join.c deleted file mode 100644 index cbdcedd73325da872f56839cb34a02c0ce434a70..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_join.c +++ /dev/null @@ -1,32 +0,0 @@ -#include "pthread_impl.h" - -static int __pthread_tryjoin_np(pthread_t t, void **res) -{ - /* - "The behavior is undefined if the value specified by the thread argument - to pthread_join() refers to the calling thread." - */ - return 0; -} - -static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) -{ - /* - "The behavior is undefined if the value specified by the thread argument - to pthread_join() refers to the calling thread." - */ - return 0; -} - -int __pthread_join(pthread_t t, void **res) -{ - /* - "The behavior is undefined if the value specified by the thread argument - to pthread_join() refers to the calling thread." - */ - return 0; -} - -weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); -weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np); -weak_alias(__pthread_join, pthread_join); diff --git a/lib/libc/wasi/thread-stub/pthread_mutex_consistent.c b/lib/libc/wasi/thread-stub/pthread_mutex_consistent.c deleted file mode 100644 index 639635361fb58ebb2cd9a8e1055d11b543b070ea..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_mutex_consistent.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_consistent(pthread_mutex_t *m) -{ - /* cannot be a robust mutex, as they're entirely unsupported in WASI */ - return EINVAL; - -} diff --git a/lib/libc/wasi/thread-stub/pthread_mutex_getprioceiling.c b/lib/libc/wasi/thread-stub/pthread_mutex_getprioceiling.c deleted file mode 100644 index 8c75a6612c89821d83aa9cde5038f3de8260ffec..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_mutex_getprioceiling.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "pthread_impl.h" - -int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict m, int *restrict ceiling) -{ - return EINVAL; -} diff --git a/lib/libc/wasi/thread-stub/pthread_mutex_lock.c b/lib/libc/wasi/thread-stub/pthread_mutex_lock.c deleted file mode 100644 index 9b380c50ec1fc6712a48c9a060187dfbcd2ea430..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_mutex_lock.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_lock(pthread_mutex_t *m) -{ - /* - _m_type[1:0] - type - 0 - normal - 1 - recursive - 2 - errorcheck - */ - if (m->_m_type&3 != PTHREAD_MUTEX_RECURSIVE) { - if (m->_m_count) return EDEADLK; - m->_m_count = 1; - } else { - if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN; - m->_m_count++; - } - return 0; -} - -weak_alias(__pthread_mutex_lock, pthread_mutex_lock); diff --git a/lib/libc/wasi/thread-stub/pthread_mutex_timedlock.c b/lib/libc/wasi/thread-stub/pthread_mutex_timedlock.c deleted file mode 100644 index 51f2606407e52ac841bfd630586fca9f77318fad..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_mutex_timedlock.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at) -{ - /* "The pthread_mutex_timedlock() function may fail if: A deadlock condition was detected." */ - /* This means that we don't have to wait and then return timeout, we can just detect deadlock. */ - return pthread_mutex_lock(m); -} - -weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); diff --git a/lib/libc/wasi/thread-stub/pthread_mutex_trylock.c b/lib/libc/wasi/thread-stub/pthread_mutex_trylock.c deleted file mode 100644 index 9f00f893fc916ac554ecace2affe24327b67cf1e..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_mutex_trylock.c +++ /dev/null @@ -1,21 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_trylock(pthread_mutex_t *m) -{ - /* - _m_type[1:0] - type - 0 - normal - 1 - recursive - 2 - errorcheck - */ - if (m->_m_type&3 != PTHREAD_MUTEX_RECURSIVE) { - if (m->_m_count) return EBUSY; - m->_m_count = 1; - } else { - if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN; - m->_m_count++; - } - return 0; -} - -weak_alias(__pthread_mutex_trylock, pthread_mutex_trylock); diff --git a/lib/libc/wasi/thread-stub/pthread_mutex_unlock.c b/lib/libc/wasi/thread-stub/pthread_mutex_unlock.c deleted file mode 100644 index 33757864aab265df9d592b11b92ef8edd39c41b3..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_mutex_unlock.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_mutex_unlock(pthread_mutex_t *m) -{ - if (!m->_m_count) return EPERM; - m->_m_count--; - return 0; -} - -weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock); diff --git a/lib/libc/wasi/thread-stub/pthread_once.c b/lib/libc/wasi/thread-stub/pthread_once.c deleted file mode 100644 index 350342a1ef2aee200f8781408981528debb371de..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_once.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_once(pthread_once_t *control, void (*init)(void)) -{ - if (!*control) { - init(); - *control = 1; - } - return 0; -} - -weak_alias(__pthread_once, pthread_once); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_rdlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_rdlock.c deleted file mode 100644 index 1b935da4ea7379341dd0127dc9dd980f97e48993..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_rdlock.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_rdlock(pthread_rwlock_t *rw) -{ - if (rw->_rw_lock == 0x7fffffff) return EDEADLK; - if (rw->_rw_lock == 0x7ffffffe) return EAGAIN; - rw->_rw_lock++; - return 0; -} - -weak_alias(__pthread_rwlock_rdlock, pthread_rwlock_rdlock); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_timedrdlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_timedrdlock.c deleted file mode 100644 index 44825643417f23bbb85acd5a01f501db4266d231..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_timedrdlock.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) -{ - return pthread_rwlock_rdlock(rw); -} - -weak_alias(__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_timedwrlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_timedwrlock.c deleted file mode 100644 index 1ee24500b3a9155863e0a000855c10982cf63c8c..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_timedwrlock.c +++ /dev/null @@ -1,8 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) -{ - return pthread_rwlock_wrlock(rw); -} - -weak_alias(__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_tryrdlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_tryrdlock.c deleted file mode 100644 index 4753a60e069babc2e9ed8ac2a055bdf32f28aeef..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_tryrdlock.c +++ /dev/null @@ -1,11 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_tryrdlock(pthread_rwlock_t *rw) -{ - if (rw->_rw_lock == 0x7fffffff) return EBUSY; - if (rw->_rw_lock == 0x7ffffffe) return EAGAIN; - rw->_rw_lock++; - return 0; -} - -weak_alias(__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_trywrlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_trywrlock.c deleted file mode 100644 index 3077fdc31de0f27977ec5f32cca3e5593fd61625..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_trywrlock.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_trywrlock(pthread_rwlock_t *rw) -{ - if (rw->_rw_lock) return EBUSY; - rw->_rw_lock = 0x7fffffff; - return 0; -} - -weak_alias(__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_unlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_unlock.c deleted file mode 100644 index 40f047ea962a718311e5497a8f6b45784a887ea8..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_unlock.c +++ /dev/null @@ -1,12 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_unlock(pthread_rwlock_t *rw) -{ - if (rw->_rw_lock == 0x7fffffff) - rw->_rw_lock = 0; - else - rw->_rw_lock--; - return 0; -} - -weak_alias(__pthread_rwlock_unlock, pthread_rwlock_unlock); diff --git a/lib/libc/wasi/thread-stub/pthread_rwlock_wrlock.c b/lib/libc/wasi/thread-stub/pthread_rwlock_wrlock.c deleted file mode 100644 index ce9d2099bea4ab77a4f72328b66558d9dfcdf49d..0000000000000000000000000000000000000000 --- a/lib/libc/wasi/thread-stub/pthread_rwlock_wrlock.c +++ /dev/null @@ -1,10 +0,0 @@ -#include "pthread_impl.h" - -int __pthread_rwlock_wrlock(pthread_rwlock_t *rw) -{ - if (rw->_rw_lock) return EDEADLK; - rw->_rw_lock = 0x7fffffff; - return 0; -} - -weak_alias(__pthread_rwlock_wrlock, pthread_rwlock_wrlock); diff --git a/lib/std/Io/Threaded/test.zig b/lib/std/Io/Threaded/test.zig index 392323de9b15c8674b4af0ea7aea21a5f49d6faf..2f2da58252b540df458c26262218a2e4fbf11329 100644 --- a/lib/std/Io/Threaded/test.zig +++ b/lib/std/Io/Threaded/test.zig @@ -201,11 +201,6 @@ test "cancel blocked read from pipe" { } test "memory mapping fallback" { - if (builtin.os.tag == .wasi and builtin.link_libc) { - // https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission) - return error.SkipZigTest; - } - var threaded: std.Io.Threaded = .init(std.testing.allocator, .{ .argv0 = .empty, .environ = .empty, diff --git a/lib/std/Io/test.zig b/lib/std/Io/test.zig index 54d79fceec8e6adebbc4e35867bcea93aa318bf2..758a18f645726f575d95b80a663d802675d0cde1 100644 --- a/lib/std/Io/test.zig +++ b/lib/std/Io/test.zig @@ -135,9 +135,6 @@ test "File.setLength" { } test "legacy setLength" { - // https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission) - if (builtin.os.tag == .wasi and builtin.link_libc) return error.SkipZigTest; - const io = testing.io; var tmp = tmpDir(.{}); @@ -629,10 +626,6 @@ test "randomSecure" { test "memory mapping" { if (builtin.cpu.arch == .hexagon) return error.SkipZigTest; // mmap returned EINVAL if (builtin.cpu.arch.isSPARC()) return error.SkipZigTest; // mmap returned EINVAL - if (builtin.os.tag == .wasi and builtin.link_libc) { - // https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission) - return error.SkipZigTest; - } const io = testing.io; diff --git a/lib/std/Target.zig b/lib/std/Target.zig index fc2f550586ca6c4c7cb5cffcd72fb29672a87cb9..4375a9d9b3dd21db25e66565592fd3d1d06683a7 100644 --- a/lib/std/Target.zig +++ b/lib/std/Target.zig @@ -950,7 +950,7 @@ pub const Abi = enum { .psx => .eabi, .psp => .eabihf, .vita => .eabihf, - .wasi, .emscripten => .musl, + .emscripten => .musl, .ashetos => .eabi, @@ -981,6 +981,7 @@ pub const Abi = enum { .opengl, .vulkan, .tios, + .wasi, => .none, }; } @@ -2290,10 +2291,6 @@ pub inline fn isOpenBSDLibC(target: *const Target) bool { }; } -pub inline fn isWasiLibC(target: *const Target) bool { - return target.os.tag == .wasi and target.abi.isMusl(); -} - /// Does this target require linking libc? This may be the case if the target has an unstable /// syscall interface, for example. pub fn requiresLibC(target: *const Target) bool { diff --git a/lib/std/c.zig b/lib/std/c.zig index c03e83fd65ac14590516f3a16572f2d3cc6a41df..7c8dcd4f075086eda8f3e620481e20e7cc5063f4 100644 --- a/lib/std/c.zig +++ b/lib/std/c.zig @@ -11,7 +11,6 @@ const assert = std.debug.assert; const page_size = std.heap.page_size_min; const linux = std.os.linux; const emscripten = std.os.emscripten; -const wasi = std.os.wasi; const windows = std.os.windows; const ws2_32 = std.os.windows.ws2_32; const darwin = @import("c/darwin.zig"); @@ -80,7 +79,6 @@ pub fn errno(rc: anytype) E { pub const ino_t = switch (native_os) { .linux => linux.ino_t, .emscripten => emscripten.ino_t, - .wasi => wasi.inode_t, .windows => windows.LARGE_INTEGER, .haiku => i64, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L38 @@ -96,7 +94,7 @@ pub const off_t = switch (native_os) { /// For use with `utimensat` and `futimens`. pub const UTIME = switch (native_os) { - .dragonfly, .freebsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => struct { + .dragonfly, .freebsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { pub const NOW: timespec = .{ .sec = 0, .nsec = -1 }; pub const OMIT: timespec = .{ .sec = 0, .nsec = -2 }; }, @@ -120,25 +118,6 @@ pub const UTIME = switch (native_os) { pub const timespec = switch (native_os) { .linux => linux.timespec, .emscripten => emscripten.timespec, - // lib/libc/include/wasm-wasi-musl/__struct_timespec.h - .wasi => extern struct { - sec: time_t, - nsec: c_long, - - pub fn fromTimestamp(tm: wasi.timestamp_t) timespec { - const sec: wasi.timestamp_t = tm / 1_000_000_000; - const nsec = tm - sec * 1_000_000_000; - return .{ - .sec = @as(time_t, @intCast(sec)), - .nsec = @as(isize, @intCast(nsec)), - }; - } - - pub fn toTimestamp(ts: timespec) wasi.timestamp_t { - return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) + - @as(wasi.timestamp_t, @intCast(ts.nsec)); - } - }, // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20 .dragonfly, .freebsd, .netbsd, .openbsd, .illumos, .haiku, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct { sec: time_t, @@ -149,7 +128,6 @@ pub const timespec = switch (native_os) { pub const dev_t = switch (native_os) { .emscripten => emscripten.dev_t, - .wasi => wasi.device_t, .openbsd, .haiku, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => i32, // glibc and musl define dev_t as u64, while in Linux kernel it is u32. // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L43 @@ -163,14 +141,12 @@ pub const mode_t = switch (native_os) { .openbsd, .haiku, .netbsd, .illumos, .windows => u32, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44 .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16, - .wasi => if (builtin.link_libc) u32 else u0, // WASI libc emulates mode. else => u0, }; pub const nlink_t = switch (native_os) { .linux => linux.nlink_t, .emscripten => emscripten.nlink_t, - .wasi => c_ulonglong, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L45 .freebsd, .serenity => u64, .openbsd, .netbsd, .dragonfly, .illumos, .windows => u32, @@ -196,7 +172,6 @@ pub const gid_t = switch (native_os) { pub const blksize_t = switch (native_os) { .linux => linux.blksize_t, .emscripten => emscripten.blksize_t, - .wasi => c_long, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L42 .serenity => u64, else => i32, @@ -254,7 +229,6 @@ pub const group = switch (native_os) { pub const blkcnt_t = switch (native_os) { .linux => linux.blkcnt_t, .emscripten => emscripten.blkcnt_t, - .wasi => c_longlong, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L41 .serenity => u64, else => i64, @@ -262,7 +236,6 @@ pub const blkcnt_t = switch (native_os) { pub const fd_t = switch (native_os) { .linux => linux.fd_t, - .wasi => wasi.fd_t, .windows => windows.HANDLE, .serenity => c_int, else => i32, @@ -293,7 +266,6 @@ pub const timerfd_clockid_t = switch (native_os) { pub const CLOCK = clockid_t; pub const clockid_t = switch (native_os) { .linux, .emscripten => linux.clockid_t, - .wasi => wasi.clockid_t, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(u32) { REALTIME = 0, MONOTONIC = 6, @@ -386,7 +358,6 @@ pub const CPU_COUNT = switch (native_os) { pub const E = switch (native_os) { .linux => linux.E, .emscripten => emscripten.E, - .wasi => wasi.errno_t, .windows => enum(u16) { /// No error occurred. SUCCESS = 0, @@ -845,13 +816,6 @@ pub const Elf_Symndx = switch (native_os) { pub const F = switch (native_os) { .linux => linux.F, .emscripten => emscripten.F, - .wasi => struct { - // Match `F_*` constants from lib/libc/include/wasm-wasi-musl/__header_fcntl.h - pub const GETFD = 1; - pub const SETFD = 2; - pub const GETFL = 3; - pub const SETFL = 4; - }, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { /// duplicate file descriptor pub const DUPFD = 0; @@ -1323,7 +1287,7 @@ pub const IOV_MAX = switch (native_os) { .linux => linux.IOV_MAX, .emscripten => emscripten.IOV_MAX, // https://github.com/SerenityOS/serenity/blob/098af0f846a87b651731780ff48420205fd33754/Kernel/API/POSIX/sys/uio.h#L16 - .openbsd, .haiku, .illumos, .wasi, .serenity => 1024, + .openbsd, .haiku, .illumos, .serenity => 1024, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 16, .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX, else => {}, @@ -1854,7 +1818,6 @@ pub const NAME_MAX = switch (native_os) { pub const PATH_MAX = switch (native_os) { .linux => linux.PATH_MAX, .emscripten => emscripten.PATH_MAX, - .wasi => 4096, .windows => 260, .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 1024, else => {}, @@ -1863,15 +1826,6 @@ pub const PATH_MAX = switch (native_os) { pub const POLL = switch (native_os) { .linux => linux.POLL, .emscripten => emscripten.POLL, - .wasi => struct { - pub const RDNORM = 0x1; - pub const WRNORM = 0x2; - pub const IN = RDNORM; - pub const OUT = WRNORM; - pub const ERR = 0x1000; - pub const HUP = 0x2000; - pub const NVAL = 0x4000; - }, .windows => ws2_32.POLL, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { pub const IN = 0x001; @@ -2042,45 +1996,6 @@ pub const RLIM = switch (native_os) { pub const S = switch (native_os) { .linux => linux.S, .emscripten => emscripten.S, - .wasi => struct { - // Match `S_*` constants from lib/libc/include/wasm-wasi-musl/__mode_t.h - pub const IFBLK = 0x6000; - pub const IFCHR = 0x2000; - pub const IFDIR = 0x4000; - pub const IFIFO = 0x1000; - pub const IFLNK = 0xa000; - pub const IFMT = IFBLK | IFCHR | IFDIR | IFIFO | IFLNK | IFREG | IFSOCK; - pub const IFREG = 0x8000; - pub const IFSOCK = 0xc000; - - pub fn ISBLK(m: u32) bool { - return m & IFMT == IFBLK; - } - - pub fn ISCHR(m: u32) bool { - return m & IFMT == IFCHR; - } - - pub fn ISDIR(m: u32) bool { - return m & IFMT == IFDIR; - } - - pub fn ISFIFO(m: u32) bool { - return m & IFMT == IFIFO; - } - - pub fn ISLNK(m: u32) bool { - return m & IFMT == IFLNK; - } - - pub fn ISREG(m: u32) bool { - return m & IFMT == IFREG; - } - - pub fn ISSOCK(m: u32) bool { - return m & IFMT == IFSOCK; - } - }, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { pub const IFMT = 0o170000; @@ -2736,11 +2651,6 @@ pub const _SC = if (builtin.abi.isAndroid()) enum(c_int) { pub const SEEK = switch (native_os) { .linux => linux.SEEK, .emscripten => emscripten.SEEK, - .wasi => struct { - pub const SET: wasi.whence_t = .SET; - pub const CUR: wasi.whence_t = .CUR; - pub const END: wasi.whence_t = .END; - }, // https://github.com/SerenityOS/serenity/blob/808ce594db1f2190e5212a250e900bde2ffe710b/Kernel/API/POSIX/stdio.h#L15-L17 .openbsd, .haiku, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .serenity => struct { pub const SET = 0; @@ -4263,7 +4173,7 @@ pub const in6_pktinfo = switch (native_os) { }; pub const itimerspec = switch (native_os) { .linux => linux.itimerspec, - .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .windows, .wasi => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .windows => extern struct { interval: timespec, value: timespec, }, @@ -4510,7 +4420,7 @@ comptime { pub const nfds_t = switch (native_os) { .linux => linux.nfds_t, .emscripten => emscripten.nfds_t, - .haiku, .illumos, .wasi => usize, + .haiku, .illumos => usize, .windows => c_ulong, .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u32, // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L32 @@ -7247,15 +7157,14 @@ pub const time_t = switch (native_os) { .emscripten => emscripten.time_t, .freebsd, .haiku => if (native_arch == .x86) c_int else c_longlong, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47 - // lib/libc/include/wasm-wasi-musl/__typedef_time_t.h - .netbsd, .openbsd, .serenity, .wasi => c_longlong, + .netbsd, .openbsd, .serenity => c_longlong, else => void, }; pub const suseconds_t = switch (native_os) { .dragonfly, .freebsd, .openbsd, .illumos => c_long, .netbsd, .haiku, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_int, // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L49 - .serenity, .wasi => c_longlong, + .serenity => c_longlong, else => void, }; @@ -7267,7 +7176,7 @@ pub const timeval = switch (native_os) { usec: c_long, }, // https://github.com/SerenityOS/serenity/blob/6b6eca0631c893c5f8cfb8274cdfe18e2d0637c0/Kernel/API/POSIX/sys/time.h#L15-L18 - .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { /// seconds sec: time_t, /// microseconds @@ -7279,7 +7188,7 @@ pub const timezone = switch (native_os) { .linux => linux.timezone, .emscripten => emscripten.timezone, // https://github.com/SerenityOS/serenity/blob/ba776390b5878ec0be1a9e595a3471a6cfe0a0cf/Userland/Libraries/LibC/sys/time.h#L19-L22 - .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .wasi => extern struct { + .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct { minuteswest: c_int, dsttime: c_int, }, @@ -7293,14 +7202,6 @@ pub const user_desc = switch (native_os) { pub const utsname = switch (native_os) { .linux => linux.utsname, .emscripten => emscripten.utsname, - .wasi => extern struct { - sysname: [64:0]u8, - nodename: [64:0]u8, - release: [64:0]u8, - version: [64:0]u8, - machine: [64:0]u8, - domainname: [64:0]u8, - }, .illumos => extern struct { sysname: [256:0]u8, nodename: [256:0]u8, @@ -7338,7 +7239,7 @@ pub const _errno = switch (native_os) { else => private.__errno_location, }, .emscripten => private.__errno_location, - .wasi, .dragonfly => private.errnoFromThreadLocal, + .dragonfly => private.errnoFromThreadLocal, .windows => private._errno, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd => private.__error, .illumos => private.___errno, @@ -7857,65 +7758,6 @@ pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize pub const Stat = switch (native_os) { .emscripten => emscripten.Stat, - .wasi => extern struct { - // Match wasi-libc's `struct stat` in lib/libc/include/wasm-wasi-musl/__struct_stat.h - dev: dev_t, - ino: ino_t, - nlink: nlink_t, - mode: mode_t, - uid: uid_t, - gid: gid_t, - __pad0: c_uint = 0, - rdev: dev_t, - size: off_t, - blksize: blksize_t, - blocks: blkcnt_t, - atim: timespec, - mtim: timespec, - ctim: timespec, - __reserved: [3]c_longlong = [3]c_longlong{ 0, 0, 0 }, - - pub fn atime(self: @This()) timespec { - return self.atim; - } - - pub fn mtime(self: @This()) timespec { - return self.mtim; - } - - pub fn ctime(self: @This()) timespec { - return self.ctim; - } - - pub fn fromFilestat(st: wasi.filestat_t) Stat { - return .{ - .dev = st.dev, - .ino = st.ino, - .mode = switch (st.filetype) { - .UNKNOWN => 0, - .BLOCK_DEVICE => S.IFBLK, - .CHARACTER_DEVICE => S.IFCHR, - .DIRECTORY => S.IFDIR, - .REGULAR_FILE => S.IFREG, - .SOCKET_DGRAM => S.IFSOCK, - .SOCKET_STREAM => S.IFIFO, - .SYMBOLIC_LINK => S.IFLNK, - _ => 0, - }, - .nlink = st.nlink, - .size = @intCast(st.size), - .atim = timespec.fromTimestamp(st.atim), - .mtim = timespec.fromTimestamp(st.mtim), - .ctim = timespec.fromTimestamp(st.ctim), - - .uid = 0, - .gid = 0, - .rdev = 0, - .blksize = 0, - .blocks = 0, - }; - } - }, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { dev: i32, mode: u16, @@ -8623,19 +8465,6 @@ pub const AT = switch (native_os) { pub const STATX_DONT_SYNC = 0x4000; pub const RECURSIVE = 0x8000; }, - .wasi => struct { - // Match `AT_*` constants in lib/libc/include/wasm-wasi-musl/__header_fcntl.h - pub const EACCESS = 0x0; - pub const SYMLINK_NOFOLLOW = 0x1; - pub const SYMLINK_FOLLOW = 0x2; - pub const REMOVEDIR = 0x4; - /// When linking libc, we follow their convention and use -2 for current working directory. - /// However, without libc, Zig does a different convention: it assumes the - /// current working directory is the first preopen. This behavior can be - /// overridden with a public function called `wasi_cwd` in the root source - /// file. - pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3; - }, // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L49-L52 .serenity => struct { pub const FDCWD = -100; @@ -8671,28 +8500,6 @@ pub const O = switch (native_os) { TMPFILE: bool = false, _: u9 = 0, }, - .wasi => packed struct(u32) { - // Match `O_*` bits from lib/libc/include/wasm-wasi-musl/__header_fcntl.h - APPEND: bool = false, - DSYNC: bool = false, - NONBLOCK: bool = false, - RSYNC: bool = false, - SYNC: bool = false, - _5: u7 = 0, - CREAT: bool = false, - DIRECTORY: bool = false, - EXCL: bool = false, - TRUNC: bool = false, - _16: u8 = 0, - NOFOLLOW: bool = false, - EXEC: bool = false, - read: bool = false, - SEARCH: bool = false, - write: bool = false, - // O_CLOEXEC, O_TTY_ININT, O_NOCTTY are 0 in wasi-musl, so they're silently - // ignored in C code. Thus no mapping in Zig. - _: u3 = 0, - }, .illumos => packed struct(u32) { ACCMODE: std.posix.ACCMODE = .RDONLY, NDELAY: bool = false, @@ -9131,7 +8938,7 @@ pub const V = switch (native_os) { STATUS, ERASE2, }, - .emscripten, .wasi => enum { + .emscripten => enum { INTR, QUIT, ERASE, @@ -9180,7 +8987,7 @@ pub const NCCS = switch (native_os) { .haiku => 11, .illumos => 19, // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L15 - .emscripten, .wasi, .serenity => 32, + .emscripten, .serenity => 32, else => void, }; @@ -9222,7 +9029,7 @@ pub const termios = switch (native_os) { lflag: tc_lflag_t, cc: [NCCS]cc_t, }, - .emscripten, .wasi => extern struct { + .emscripten => extern struct { iflag: tc_iflag_t, oflag: tc_oflag_t, cflag: tc_cflag_t, @@ -9325,7 +9132,7 @@ pub const tc_iflag_t = switch (native_os) { _: u16 = 0, }, // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L52-L66 - .emscripten, .wasi, .serenity => packed struct(u32) { + .emscripten, .serenity => packed struct(u32) { IGNBRK: bool = false, BRKINT: bool = false, IGNPAR: bool = false, @@ -9418,7 +9225,7 @@ pub const tc_oflag_t = switch (native_os) { _: u14 = 0, }, // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L69-L97 - .haiku, .wasi, .emscripten, .serenity => packed struct(u32) { + .haiku, .emscripten, .serenity => packed struct(u32) { OPOST: bool = false, OLCUC: bool = false, ONLCR: bool = false, @@ -9566,7 +9373,7 @@ pub const tc_cflag_t = switch (native_os) { CRTSXOFF: bool = false, CRTSCTS: bool = false, }, - .wasi, .emscripten => packed struct(u32) { + .emscripten => packed struct(u32) { _0: u4 = 0, CSIZE: CSIZE = .CS5, CSTOPB: bool = false, @@ -9702,7 +9509,7 @@ pub const tc_lflag_t = switch (native_os) { IEXTEN: bool = false, _: u16 = 0, }, - .wasi, .emscripten => packed struct(u32) { + .emscripten => packed struct(u32) { ISIG: bool = false, ICANON: bool = false, _2: u1 = 0, @@ -9886,7 +9693,7 @@ pub const speed_t = switch (native_os) { B4000000 = 31, }, // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L111-L159 - .emscripten, .wasi, .serenity => enum(u32) { + .emscripten, .serenity => enum(u32) { B0 = 0o0000000, B50 = 0o0000001, B75 = 0o0000002, @@ -9923,7 +9730,7 @@ pub const speed_t = switch (native_os) { else => void, }; -pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int; +pub const whence_t = c_int; pub const sig_atomic_t = switch (native_os) { // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L20 @@ -10881,7 +10688,7 @@ pub const gettimeofday = switch (native_os) { }; pub const mlock = switch (native_os) { - .windows, .wasi => {}, + .windows => {}, else => private.mlock, }; @@ -10891,7 +10698,7 @@ pub const mlock2 = switch (native_os) { }; pub const munlock = switch (native_os) { - .windows, .wasi => {}, + .windows => {}, else => private.munlock, }; @@ -11042,7 +10849,7 @@ pub const sf_hdtr = switch (native_os) { }; pub const flock = switch (native_os) { - .windows, .wasi => {}, + .windows => {}, else => private.flock, }; @@ -11521,7 +11328,7 @@ pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usi pub const TIMER = switch (native_os) { .linux, .emscripten => std.os.linux.TIMER, - .openbsd, .netbsd, .wasi, .windows, .freebsd, .serenity => packed struct(u32) { + .openbsd, .netbsd, .windows, .freebsd, .serenity => packed struct(u32) { ABSTIME: bool, _: u31 = 0, }, @@ -11529,12 +11336,12 @@ pub const TIMER = switch (native_os) { }; pub const clock_nanosleep = switch (native_os) { - .linux, .emscripten, .netbsd, .wasi, .windows, .freebsd, .serenity => private.clock_nanosleep, + .linux, .emscripten, .netbsd, .windows, .freebsd, .serenity => private.clock_nanosleep, else => {}, }; pub const ioctl = switch (native_os) { - .windows, .wasi => {}, + .windows => {}, else => private.ioctl, }; diff --git a/lib/std/fs/test.zig b/lib/std/fs/test.zig index b30da786b770ef75458387803be1e9aaaf1eb5ba..75a1dfe70305f73fdc0c1e8245ad2d3fb43db5b0 100644 --- a/lib/std/fs/test.zig +++ b/lib/std/fs/test.zig @@ -890,14 +890,8 @@ test "file operations on directories" { }, } - if (native_os == .wasi and builtin.link_libc) { - // wasmtime unexpectedly succeeds here, see https://github.com/ziglang/zig/issues/20747 - const handle = try ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write }); - handle.close(io); - } else { - // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms. - try expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write })); - } + // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms. + try expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write })); { const handle = try ctx.dir.openFile(io, test_dir_name, .{ .allow_directory = true, .mode = .read_only }); @@ -2765,7 +2759,7 @@ test "hard link with different directories" { } test "stat smoke test" { - if (native_os == .wasi and !builtin.link_libc) return error.SkipZigTest; + if (native_os == .wasi) return error.SkipZigTest; const io = testing.io; diff --git a/lib/std/os/wasi.zig b/lib/std/os/wasi.zig index 87e1bc59c2e7a1c3af4c3e3410d80313da8644dc..29487351fabdefbb1b79c30c92e882344f9c8209 100644 --- a/lib/std/os/wasi.zig +++ b/lib/std/os/wasi.zig @@ -1,7 +1,7 @@ //! wasi_snapshot_preview1 spec available (in witx format) here: //! * typenames -- https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/typenames.witx //! * module -- https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx -//! Note that libc API does *not* go in this file. wasi libc API goes into std/c.zig instead. +//! Note that libc API does *not* go in this file. const builtin = @import("builtin"); const std = @import("std"); const assert = std.debug.assert; diff --git a/lib/std/posix.zig b/lib/std/posix.zig index d845a8607dbb89550018673c8b20ec2db7aebdce..d6a28d877b4c5d515cc4f5b51361b43122ea8203 100644 --- a/lib/std/posix.zig +++ b/lib/std/posix.zig @@ -24,7 +24,7 @@ test { /// Whether to use libc for the POSIX API layer. const use_libc = builtin.link_libc or switch (native_os) { - .windows, .wasi => true, + .windows => true, else => false, }; @@ -54,6 +54,7 @@ else switch (native_os) { // https://github.com/pspdev/newlib/blob/9e0a073634ad73e8e088f2e071c55a9fe5d39709/newlib/libc/sys/psp/sys/dirent.h#L19 pub const NAME_MAX = 255; }, + .wasi => @import("posix/wasi.zig"), else => struct { pub const pid_t = void; pub const pollfd = void; @@ -443,7 +444,7 @@ pub const OpenError = std.Io.File.OpenError || error{WouldBlock}; pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenError!fd_t { if (native_os == .windows) { @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); - } else if (native_os == .wasi and !builtin.link_libc) { + } else if (native_os == .wasi) { @compileError("use std.Io instead"); } const file_path_c = try toPosixPath(file_path); @@ -459,7 +460,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: O, mode: mode_t) OpenError!fd_t { if (native_os == .windows) { @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); - } else if (native_os == .wasi and !builtin.link_libc) { + } else if (native_os == .wasi) { return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode); } diff --git a/lib/std/posix/wasi.zig b/lib/std/posix/wasi.zig new file mode 100644 index 0000000000000000000000000000000000000000..51c9482ed9e732177cc9329c9528a608ac0db07d --- /dev/null +++ b/lib/std/posix/wasi.zig @@ -0,0 +1,81 @@ +//! This exists to satisfy the `std.posix` interface for WASI w/o libc. Most of the stuff here is +//! taken from wasi-libc, i.e. it is essentially made up from the perspective of pure WASI. This +//! should be removed alongside `std.posix` eventually. + +const builtin = @import("builtin"); +const std = @import("../std.zig"); + +const wasi = std.os.wasi; + +pub const pid_t = i32; +pub const fd_t = wasi.fd_t; +pub const uid_t = u32; +pub const gid_t = u32; +pub const mode_t = u0; +pub const nlink_t = u64; +pub const ino_t = wasi.inode_t; + +pub const time_t = i64; +pub const timespec = extern struct { + sec: time_t, + nsec: c_long, + + pub fn fromTimestamp(tm: wasi.timestamp_t) @This() { + const sec: wasi.timestamp_t = tm / 1_000_000_000; + const nsec = tm - sec * 1_000_000_000; + return .{ + .sec = @as(time_t, @intCast(sec)), + .nsec = @as(isize, @intCast(nsec)), + }; + } + + pub fn toTimestamp(ts: @This()) wasi.timestamp_t { + return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) + + @as(wasi.timestamp_t, @intCast(ts.nsec)); + } +}; + +pub const pollfd = extern struct { + fd: fd_t, + events: i16, + revents: i16 = undefined, +}; + +pub const rlimit_resource = void; + +pub const E = wasi.errno_t; + +pub const SIG = void; +pub const Sigaction = void; + +pub const PROT = void; + +pub const MCL = void; + +pub const AT = struct { + pub const EACCESS = 0x0; + pub const SYMLINK_NOFOLLOW = 0x1; + pub const SYMLINK_FOLLOW = 0x2; + pub const REMOVEDIR = 0x4; + + pub const FDCWD: fd_t = 3; +}; + +pub const IFNAMESIZE = {}; + +pub const STDIN_FILENO = 0; +pub const STDOUT_FILENO = 1; +pub const STDERR_FILENO = 2; + +pub const PATH_MAX = 4096; +pub const IOV_MAX = 1024; + +pub const getrandom = {}; + +pub const mlock = {}; +pub const mlock2 = {}; +pub const munlock = {}; +pub const mlockall = {}; +pub const munlockall = {}; + +pub const cmsg_align = {}; diff --git a/lib/std/process/Args.zig b/lib/std/process/Args.zig index 353fcfe4247b6709b2505c34c5b0ecc09ec7cb3e..3b21156e8307834802a5a7e6266f75651fa9d4c8 100644 --- a/lib/std/process/Args.zig +++ b/lib/std/process/Args.zig @@ -14,11 +14,7 @@ vector: Vector, /// queried and heap-allocated at runtime. pub const Vector = switch (native_os) { .windows => []const u16, // WTF-16 encoded - .wasi => switch (builtin.link_libc) { - false => void, - true => []const [*:0]const u8, - }, - .freestanding, .other => void, + .wasi, .freestanding, .other => void, else => []const [*:0]const u8, }; @@ -26,7 +22,7 @@ pub const Vector = switch (native_os) { pub const Iterator = struct { const Inner = switch (native_os) { .windows => Windows, - .wasi => if (builtin.link_libc) Posix else Wasi, + .wasi => Wasi, else => Posix, }; @@ -44,7 +40,7 @@ pub const Iterator = struct { /// You must deinitialize iterator's internal buffers by calling `deinit` when done. pub fn initAllocator(a: Args, gpa: Allocator) InitError!Iterator { - if (native_os == .wasi and !builtin.link_libc) { + if (native_os == .wasi) { return .{ .inner = try .init(gpa) }; } if (native_os == .windows) { @@ -73,7 +69,7 @@ pub const Iterator = struct { /// `initAllocator` function. pub fn deinit(it: *Iterator) void { // Unless we're targeting WASI or Windows, this is a no-op. - if (native_os == .wasi and !builtin.link_libc) it.inner.deinit(); + if (native_os == .wasi) it.inner.deinit(); if (native_os == .windows) it.inner.deinit(); } @@ -504,7 +500,7 @@ pub fn toSlice(a: Args, arena: Allocator) ToSliceError![]const [:0]const u8 { } return result_slice_list; - } else if (native_os == .wasi and !builtin.link_libc) { + } else if (native_os == .wasi) { var count: usize = undefined; var buf_size: usize = undefined; diff --git a/lib/std/process/Environ.zig b/lib/std/process/Environ.zig index 157ee40a23ec15d4cf929023b879e64e6ddaae96..2c809733b8587621313a938c570b7cc8bcab2b4a 100644 --- a/lib/std/process/Environ.zig +++ b/lib/std/process/Environ.zig @@ -24,11 +24,8 @@ pub const empty: Environ = .{ .block = .empty }; /// operating system `void` is also used. pub const Block = switch (native_os) { .windows => GlobalBlock, - .wasi, .emscripten => switch (builtin.link_libc) { - false => GlobalBlock, - true => PosixBlock, - }, - .freestanding, .other => GlobalBlock, + .emscripten => if (builtin.link_libc) PosixBlock else GlobalBlock, + .wasi, .freestanding, .other => GlobalBlock, else => PosixBlock, }; @@ -513,7 +510,7 @@ pub fn createMap(env: Environ, allocator: Allocator) CreateMapError!Map { assert(std.os.windows.ntdll.RtlEnterCriticalSection(peb.FastPebLock) == .SUCCESS); defer assert(std.os.windows.ntdll.RtlLeaveCriticalSection(peb.FastPebLock) == .SUCCESS); try map.putWindowsBlock(.{ .ptr = peb.ProcessParameters.Environment }); - } else if (native_os == .wasi and !builtin.link_libc) empty: { + } else if (native_os == .wasi) empty: { if (!env.block.use_global) break :empty; var environ_count: usize = undefined; @@ -951,7 +948,7 @@ test Map { test "convert from Environ to Map and back again" { if (native_os == .windows) return; - if (native_os == .wasi and !builtin.link_libc) return; + if (native_os == .wasi) return; const gpa = testing.allocator; diff --git a/lib/std/start.zig b/lib/std/start.zig index 0a83ece4f107c1bda7a770b23f7cc56a04296705..96190d835614718793d94832f9a0b72e415d964d 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -757,7 +757,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)]; const environ: [:null]?[*:0]u8 = switch (builtin.os.tag) { - .wasi, .emscripten => environ: { + .emscripten => environ: { const c_environ = std.c.environ; var env_count: usize = 0; while (c_environ[env_count] != null) : (env_count += 1) {} diff --git a/lib/std/zig/LibCDirs.zig b/lib/std/zig/LibCDirs.zig index 0c8873479420e6aca1db1e27e02f79600ee10950..f0f27b5d65ffc7424e99813bfa91afa22ab8e4ff 100644 --- a/lib/std/zig/LibCDirs.zig +++ b/lib/std/zig/LibCDirs.zig @@ -165,7 +165,7 @@ pub fn detectFromBuilding(arena: Allocator, zig_lib_dir: Path, target: *const st const generic_name = libCGenericName(target); // Some architecture families are handled by the same set of headers. - const arch_name = if (target.isMuslLibC() or target.isWasiLibC()) + const arch_name = if (target.isMuslLibC()) std.zig.target.muslArchNameHeaders(target.cpu.arch) else if (target.isGnuLibC()) std.zig.target.glibcArchNameHeaders(target.cpu.arch) diff --git a/lib/std/zig/target.zig b/lib/std/zig/target.zig index e70832bd47f5f2180bda7c41d828ddea8b1d477c..3f4f135470fa6a578e01e7f8a324083fb10e7423 100644 --- a/lib/std/zig/target.zig +++ b/lib/std/zig/target.zig @@ -103,7 +103,6 @@ pub const available_libcs = [_]ArchOsAbi{ .{ .arch = .sparc64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 1, .patch = 19 } }, .{ .arch = .sparc64, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 1, .minor = 4, .patch = 0 } }, .{ .arch = .sparc64, .os = .openbsd, .abi = .none, .os_ver = .{ .major = 3, .minor = 0, .patch = 0 } }, - .{ .arch = .wasm32, .os = .wasi, .abi = .musl }, .{ .arch = .x86, .os = .freebsd, .abi = .none }, .{ .arch = .x86, .os = .linux, .abi = .gnu, .glibc_triple = "i686-linux-gnu" }, .{ .arch = .x86, .os = .linux, .abi = .musl }, @@ -241,7 +240,6 @@ pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 .riscv32 => "riscv32", .riscv64 => "riscv64", .s390x => "s390x", - .wasm32, .wasm64 => "wasm", .x86 => "i386", .x86_64 => "x86_64", else => unreachable, @@ -396,19 +394,6 @@ pub fn isLibCLibName(target: *const std.Target, name: []const u8) bool { return true; if (eqlIgnoreCase(ignore_case, name, "xnet")) return true; - - if (target.os.tag == .wasi) { - if (eqlIgnoreCase(ignore_case, name, "setjmp")) - return true; - if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-getpid")) - return true; - if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-mman")) - return true; - if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-process-clocks")) - return true; - if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-signal")) - return true; - } } if (target.os.tag.isDarwin()) { diff --git a/src/Compilation.zig b/src/Compilation.zig index cf7d046aebbc0eec0843ac186fd929128297d386..90df796fe59cb098350a203b1e4021e345d185e5 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -29,7 +29,6 @@ const openbsd = @import("libs/openbsd.zig"); const mingw = @import("libs/mingw.zig"); const libunwind = @import("libs/libunwind.zig"); const libcxx = @import("libs/libcxx.zig"); -const wasi_libc = @import("libs/wasi_libc.zig"); const clangMain = @import("main.zig").clangMain; const Zcu = @import("Zcu.zig"); const Sema = @import("Sema.zig"); @@ -294,8 +293,6 @@ const QueuedJobs = struct { freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".field_names.len]bool = @splat(false), netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), - /// one of WASI libc static objects - wasi_libc_crt_file: [@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len]bool = @splat(false), /// one of the mingw-w64 static objects mingw_crt_file: [@typeInfo(mingw.CrtFile).@"enum".field_names.len]bool = @splat(false), /// all of the glibc shared objects @@ -1217,7 +1214,6 @@ pub const MiscTask = enum { libtsan, libubsan, libfuzzer, - wasi_libc_crt_file, compiler_rt, libzigc, link_depfile, @@ -1230,10 +1226,6 @@ pub const MiscTask = enum { @"musl libc.a", @"musl libc.so", - @"wasi crt1-reactor.o", - @"wasi crt1-command.o", - @"wasi libc.a", - @"glibc Scrt1.o", @"glibc libc_nonshared.a", @"glibc shared object", @@ -2502,11 +2494,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, } comp.queued_jobs.openbsd_shared_objects = true; - } else if (target.isWasiLibC()) { - if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); - - comp.queued_jobs.wasi_libc_crt_file[@backingInt(wasi_libc.execModelCrtFile(comp.config.wasi_exec_model))] = true; - comp.queued_jobs.wasi_libc_crt_file[@backingInt(wasi_libc.CrtFile.libc_a)] = true; } else if (target.isMinGW()) { if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); @@ -4602,13 +4589,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node } } - for (0..@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len) |i| { - if (comp.queued_jobs.wasi_libc_crt_file[i]) { - const tag: wasi_libc.CrtFile = @fromBackingInt(@intCast(i)); - prelink_group.async(io, buildWasiLibcCrtFile, .{ comp, tag, main_progress_node }); - } - } - for (0..@typeInfo(mingw.CrtFile).@"enum".field_names.len) |i| { if (comp.queued_jobs.mingw_crt_file[i]) { const tag: mingw.CrtFile = @fromBackingInt(@intCast(i)); @@ -5365,17 +5345,6 @@ fn buildMingwImportLib(comp: *Compilation, lib_name: []const u8, is_prelink: boo ); } -fn buildWasiLibcCrtFile(comp: *Compilation, crt_file: wasi_libc.CrtFile, prog_node: std.Progress.Node) void { - if (wasi_libc.buildCrtFile(comp, crt_file, prog_node)) |_| { - comp.queued_jobs.wasi_libc_crt_file[@backingInt(crt_file)] = false; - } else |err| switch (err) { - error.AlreadyReported => return, - else => comp.lockAndSetMiscFailure(.wasi_libc_crt_file, "unable to build WASI libc {s}: {s}", .{ - @tagName(crt_file), @errorName(err), - }), - } -} - fn buildLibUnwind(comp: *Compilation, prog_node: std.Progress.Node) void { if (libunwind.buildStaticLib(comp, prog_node)) |_| { comp.queued_jobs.libunwind = false; diff --git a/src/libs/libcxx.zig b/src/libs/libcxx.zig index 88a92274188ff5294bf7c868027f49d3c9e5d40c..4718b38d89635e57610d54ba87ba21dcb43466ec 100644 --- a/src/libs/libcxx.zig +++ b/src/libs/libcxx.zig @@ -195,9 +195,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! var c_source_files = try std.array_list.Managed(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len); for (libcxx_files) |cxx_src| { - // These don't compile on WASI due to e.g. `fchmod` usage. - if (std.mem.startsWith(u8, cxx_src, "src/filesystem/") and target.os.tag == .wasi) - continue; if (std.mem.startsWith(u8, cxx_src, "src/support/win32/") and target.os.tag != .windows) continue; @@ -211,11 +208,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! try cflags.append("-D_LIBCPP_BUILDING_LIBRARY"); try cflags.append("-DLIBCXX_BUILDING_LIBCXXABI"); try cflags.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER"); - - if (target.os.tag == .wasi) { - try cflags.append("-fno-exceptions"); - } - try cflags.append("-fvisibility=hidden"); try cflags.append("-fvisibility-inlines-hidden"); @@ -386,10 +378,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr for (libcxxabi_files) |cxxabi_src| { if (!comp.config.any_non_single_threaded and std.mem.eql(u8, cxxabi_src, "src/cxa_thread_atexit.cpp")) continue; - if (target.os.tag == .wasi and - (std.mem.eql(u8, cxxabi_src, "src/cxa_exception.cpp") or std.mem.eql(u8, cxxabi_src, "src/cxa_personality.cpp"))) - continue; - if (target.os.tag != .wasi and std.mem.eql(u8, cxxabi_src, "src/cxa_noexception.cpp")) + if (std.mem.eql(u8, cxxabi_src, "src/cxa_noexception.cpp")) continue; var cflags = std.array_list.Managed([]const u8).init(arena); @@ -408,10 +397,6 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL"); } - if (target.os.tag == .wasi) { - try cflags.append("-fno-exceptions"); - } - try cflags.append("-fvisibility=hidden"); try cflags.append("-fvisibility-inlines-hidden"); @@ -519,9 +504,7 @@ pub fn addCxxArgs( try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS"); try cflags.append("-D_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS=0"); - try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_HAS_FILESYSTEM={d}", .{ - @as(u1, if (target.os.tag == .wasi) 0 else 1), - })); + try cflags.append("-D_LIBCPP_HAS_FILESYSTEM"); try cflags.append("-D_LIBCPP_HAS_RANDOM_DEVICE"); try cflags.append("-D_LIBCPP_HAS_LOCALIZATION"); try cflags.append("-D_LIBCPP_HAS_UNICODE"); diff --git a/src/libs/wasi_libc.zig b/src/libs/wasi_libc.zig deleted file mode 100644 index 561966b01707194d277afc0d5afecb241a68f732..0000000000000000000000000000000000000000 --- a/src/libs/wasi_libc.zig +++ /dev/null @@ -1,1115 +0,0 @@ -const std = @import("std"); -const mem = std.mem; -const path = std.fs.path; - -const Allocator = std.mem.Allocator; -const Compilation = @import("../Compilation.zig"); -const build_options = @import("build_options"); - -pub const CrtFile = enum { - crt1_reactor_o, - crt1_command_o, - libc_a, -}; - -pub fn execModelCrtFile(wasi_exec_model: std.lang.WasiExecModel) CrtFile { - return switch (wasi_exec_model) { - .reactor => CrtFile.crt1_reactor_o, - .command => CrtFile.crt1_command_o, - }; -} - -pub fn execModelCrtFileFullName(wasi_exec_model: std.lang.WasiExecModel) []const u8 { - return switch (execModelCrtFile(wasi_exec_model)) { - .crt1_reactor_o => "crt1-reactor.o", - .crt1_command_o => "crt1-command.o", - else => unreachable, - }; -} - -/// TODO replace anyerror with explicit error set, recording user-friendly errors with -/// lockAndSetMiscFailure and returning error.AlreadyReported. see libcxx.zig for example. -pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progress.Node) anyerror!void { - if (!build_options.have_llvm) { - return error.ZigCompilerNotBuiltWithLLVMExtensions; - } - - const gpa = comp.gpa; - var arena_allocator = std.heap.ArenaAllocator.init(gpa); - defer arena_allocator.deinit(); - const arena = arena_allocator.allocator(); - - switch (crt_file) { - .crt1_reactor_o => { - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{}); - try addLibcBottomHalfIncludes(comp, arena, &args); - - var files = [_]Compilation.CSourceFile{ - .{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, crt1_reactor_src_file), - }), - .extra_flags = args.items, - .owner = undefined, - }, - }; - - return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files, .{}); - }, - .crt1_command_o => { - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{}); - try addLibcBottomHalfIncludes(comp, arena, &args); - - var files = [_]Compilation.CSourceFile{ - .{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, crt1_command_src_file), - }), - .extra_flags = args.items, - .owner = undefined, - }, - }; - - return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files, .{}); - }, - .libc_a => { - var libc_sources = std.array_list.Managed(Compilation.CSourceFile).init(arena); - - { - // Compile libc-bottom-half. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - try addLibcBottomHalfIncludes(comp, arena, &args); - - for (libc_bottom_half_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile libc-top-half. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - try addLibcTopHalfIncludes(comp, arena, &args); - - for (libc_top_half_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile musl-fts. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - try args.appendSlice(&[_][]const u8{ - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "fts", - }), - }); - - for (fts_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - if (comp.getTarget().cpu.has(.wasm, .exception_handling)) { - // Compile libsetjmp. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - try addLibcTopHalfIncludes(comp, arena, &args); - - for (setjmp_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile libdl. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - try addLibcTopHalfIncludes(comp, arena, &args); - - for (emulated_dl_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile libwasi-emulated-process-clocks. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - - for (emulated_process_clocks_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile libwasi-emulated-getpid. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - - for (emulated_getpid_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile libwasi-emulated-mman. - var args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); - - for (emulated_mman_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = args.items, - .owner = undefined, - }); - } - } - - { - // Compile libwasi-emulated-signal. - var bottom_args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &bottom_args, .{ .want_O3 = true }); - - for (emulated_signal_bottom_half_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = bottom_args.items, - .owner = undefined, - }); - } - - var top_args = std.array_list.Managed([]const u8).init(arena); - try addCCArgs(comp, arena, &top_args, .{ .want_O3 = true }); - try addLibcTopHalfIncludes(comp, arena, &top_args); - try top_args.append("-D_WASI_EMULATED_SIGNAL"); - - for (emulated_signal_top_half_src_files) |file_path| { - try libc_sources.append(.{ - .src_path = try comp.dirs.zig_lib.join(arena, &.{ - "libc", try sanitize(arena, file_path), - }), - .extra_flags = top_args.items, - .owner = undefined, - }); - } - } - - try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); - }, - } -} - -fn sanitize(arena: Allocator, file_path: []const u8) ![]const u8 { - // TODO do this at comptime on the comptime data rather than at runtime - // probably best to wait until self-hosted is done and our comptime execution - // is faster and uses less memory. - const out_path = if (path.sep != '/') blk: { - const mutable_file_path = try arena.dupe(u8, file_path); - for (mutable_file_path) |*c| { - if (c.* == '/') { - c.* = path.sep; - } - } - break :blk mutable_file_path; - } else file_path; - return out_path; -} - -const CCOptions = struct { - want_O3: bool = false, - no_strict_aliasing: bool = false, -}; - -fn addCCArgs( - comp: *Compilation, - arena: Allocator, - args: *std.array_list.Managed([]const u8), - options: CCOptions, -) error{OutOfMemory}!void { - const target = comp.getTarget(); - const arch_name = std.zig.target.muslArchNameHeaders(target.cpu.arch); - const os_name = @tagName(target.os.tag); - const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name }); - const o_arg = if (options.want_O3) "-O3" else "-Os"; - - try args.appendSlice(&[_][]const u8{ - "-std=gnu17", - "-fno-trapping-math", - "-w", // ignore all warnings - - o_arg, - - "-mthread-model", - "single", - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-bottom-half", - "cloudlibc", - "src", - }), - - "-isystem", - try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }), - "-isystem", - try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", "generic-musl" }), - - "-DBULK_MEMORY_THRESHOLD=32", - }); - - if (options.no_strict_aliasing) { - try args.appendSlice(&[_][]const u8{"-fno-strict-aliasing"}); - } -} - -fn addLibcBottomHalfIncludes( - comp: *Compilation, - arena: Allocator, - args: *std.array_list.Managed([]const u8), -) error{OutOfMemory}!void { - try args.appendSlice(&[_][]const u8{ - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-bottom-half", - "headers", - "private", - }), - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-bottom-half", - "cloudlibc", - "src", - "include", - }), - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-bottom-half", - "cloudlibc", - "src", - }), - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-top-half", - "musl", - "src", - "include", - }), - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "musl", - "src", - "include", - }), - "-I", - - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-top-half", - "musl", - "src", - "internal", - }), - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "musl", - "src", - "internal", - }), - }); -} - -fn addLibcTopHalfIncludes( - comp: *Compilation, - arena: Allocator, - args: *std.array_list.Managed([]const u8), -) error{OutOfMemory}!void { - try args.appendSlice(&[_][]const u8{ - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-top-half", - "musl", - "src", - "include", - }), - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "musl", - "src", - "include", - }), - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-top-half", - "musl", - "src", - "internal", - }), - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "musl", - "src", - "internal", - }), - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-top-half", - "musl", - "arch", - "wasm32", - }), - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "musl", - "arch", - "generic", - }), - - "-I", - try comp.dirs.zig_lib.join(arena, &.{ - "libc", - "wasi", - "libc-top-half", - "headers", - "private", - }), - }); -} - -const libc_bottom_half_src_files = [_][]const u8{ - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c", - "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c", - "wasi/libc-bottom-half/sources/abort.c", - "wasi/libc-bottom-half/sources/accept-wasip1.c", - "wasi/libc-bottom-half/sources/at_fdcwd.c", - "wasi/libc-bottom-half/sources/chdir.c", - "wasi/libc-bottom-half/sources/complex-builtins.c", - "wasi/libc-bottom-half/sources/environ.c", - "wasi/libc-bottom-half/sources/errno.c", - "wasi/libc-bottom-half/sources/__errno_location.c", - "wasi/libc-bottom-half/sources/getcwd.c", - "wasi/libc-bottom-half/sources/getentropy.c", - "wasi/libc-bottom-half/sources/isatty.c", - "wasi/libc-bottom-half/sources/__main_void.c", - "wasi/libc-bottom-half/sources/math/math-builtins.c", - "wasi/libc-bottom-half/sources/posix.c", - "wasi/libc-bottom-half/sources/preopens.c", - "wasi/libc-bottom-half/sources/sbrk.c", - "wasi/libc-bottom-half/sources/truncate.c", - "wasi/libc-bottom-half/sources/__wasilibc_dt.c", - "wasi/libc-bottom-half/sources/__wasilibc_environ.c", - "wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c", - "wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c", - "wasi/libc-bottom-half/sources/__wasilibc_random.c", - "wasi/libc-bottom-half/sources/__wasilibc_real.c", - "wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c", - "wasi/libc-bottom-half/sources/__wasilibc_tell.c", - "wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c", -}; - -const libc_top_half_src_files = [_][]const u8{ - "musl/src/complex/cabs.c", - "musl/src/complex/cabsf.c", - "musl/src/complex/cabsl.c", - "musl/src/complex/cacos.c", - "musl/src/complex/cacosf.c", - "musl/src/complex/cacosh.c", - "musl/src/complex/cacoshf.c", - "musl/src/complex/cacoshl.c", - "musl/src/complex/cacosl.c", - "musl/src/complex/carg.c", - "musl/src/complex/cargf.c", - "musl/src/complex/cargl.c", - "musl/src/complex/casin.c", - "musl/src/complex/casinf.c", - "musl/src/complex/casinh.c", - "musl/src/complex/casinhf.c", - "musl/src/complex/casinhl.c", - "musl/src/complex/casinl.c", - "musl/src/complex/catan.c", - "musl/src/complex/catanf.c", - "musl/src/complex/catanh.c", - "musl/src/complex/catanhf.c", - "musl/src/complex/catanhl.c", - "musl/src/complex/catanl.c", - "musl/src/complex/ccos.c", - "musl/src/complex/ccosf.c", - "musl/src/complex/ccosh.c", - "musl/src/complex/ccoshf.c", - "musl/src/complex/ccoshl.c", - "musl/src/complex/ccosl.c", - "musl/src/complex/__cexp.c", - "musl/src/complex/cexp.c", - "musl/src/complex/__cexpf.c", - "musl/src/complex/cexpf.c", - "musl/src/complex/cexpl.c", - "musl/src/complex/clog.c", - "musl/src/complex/clogf.c", - "musl/src/complex/clogl.c", - "musl/src/complex/conj.c", - "musl/src/complex/conjf.c", - "musl/src/complex/conjl.c", - "musl/src/complex/cpow.c", - "musl/src/complex/cpowf.c", - "musl/src/complex/cpowl.c", - "musl/src/complex/cproj.c", - "musl/src/complex/cprojf.c", - "musl/src/complex/cprojl.c", - "musl/src/complex/csin.c", - "musl/src/complex/csinf.c", - "musl/src/complex/csinh.c", - "musl/src/complex/csinhf.c", - "musl/src/complex/csinhl.c", - "musl/src/complex/csinl.c", - "musl/src/complex/csqrt.c", - "musl/src/complex/csqrtf.c", - "musl/src/complex/csqrtl.c", - "musl/src/complex/ctan.c", - "musl/src/complex/ctanf.c", - "musl/src/complex/ctanh.c", - "musl/src/complex/ctanhf.c", - "musl/src/complex/ctanhl.c", - "musl/src/complex/ctanl.c", - "musl/src/conf/confstr.c", - "musl/src/conf/legacy.c", - "musl/src/conf/pathconf.c", - "musl/src/crypt/crypt_blowfish.c", - "musl/src/crypt/crypt.c", - "musl/src/crypt/crypt_des.c", - "musl/src/crypt/crypt_md5.c", - "musl/src/crypt/crypt_r.c", - "musl/src/crypt/crypt_sha256.c", - "musl/src/crypt/crypt_sha512.c", - "musl/src/crypt/encrypt.c", - "musl/src/ctype/__ctype_b_loc.c", - "musl/src/ctype/__ctype_get_mb_cur_max.c", - "musl/src/ctype/__ctype_tolower_loc.c", - "musl/src/ctype/__ctype_toupper_loc.c", - "musl/src/ctype/iswalnum.c", - "musl/src/ctype/iswalpha.c", - "musl/src/ctype/iswblank.c", - "musl/src/ctype/iswcntrl.c", - "musl/src/ctype/iswctype.c", - "musl/src/ctype/iswdigit.c", - "musl/src/ctype/iswgraph.c", - "musl/src/ctype/iswlower.c", - "musl/src/ctype/iswprint.c", - "musl/src/ctype/iswpunct.c", - "musl/src/ctype/iswspace.c", - "musl/src/ctype/iswupper.c", - "musl/src/ctype/iswxdigit.c", - "musl/src/ctype/towctrans.c", - "musl/src/ctype/wcswidth.c", - "musl/src/ctype/wctrans.c", - "musl/src/ctype/wcwidth.c", - "musl/src/env/setenv.c", - "musl/src/exit/assert.c", - "musl/src/exit/quick_exit.c", - "musl/src/fenv/fegetexceptflag.c", - "musl/src/fenv/feholdexcept.c", - "musl/src/fenv/fenv.c", - "musl/src/fenv/fesetexceptflag.c", - "musl/src/fenv/fesetround.c", - "musl/src/fenv/feupdateenv.c", - "musl/src/legacy/getpagesize.c", - "musl/src/locale/c_locale.c", - "musl/src/locale/duplocale.c", - "musl/src/locale/freelocale.c", - "musl/src/locale/iconv.c", - "musl/src/locale/iconv_close.c", - "musl/src/locale/langinfo.c", - "musl/src/locale/__lctrans.c", - "musl/src/locale/localeconv.c", - "musl/src/locale/__mo_lookup.c", - "musl/src/locale/pleval.c", - "musl/src/locale/setlocale.c", - "musl/src/locale/strfmon.c", - "musl/src/locale/strtod_l.c", - "musl/src/locale/wcscoll.c", - "musl/src/locale/wcsxfrm.c", - "musl/src/math/acosh.c", - "musl/src/math/acoshl.c", - "musl/src/math/acosl.c", - "musl/src/math/asinf.c", - "musl/src/math/asinh.c", - "musl/src/math/asinhf.c", - "musl/src/math/asinhl.c", - "musl/src/math/asinl.c", - "musl/src/math/atan2.c", - "musl/src/math/atan2f.c", - "musl/src/math/atan2l.c", - "musl/src/math/atanh.c", - "musl/src/math/atanhf.c", - "musl/src/math/atanhl.c", - "musl/src/math/cbrtl.c", - "musl/src/math/__cos.c", - "musl/src/math/__cosdf.c", - "musl/src/math/coshl.c", - "musl/src/math/erf.c", - "musl/src/math/erff.c", - "musl/src/math/erfl.c", - "musl/src/math/exp10l.c", - "musl/src/math/exp2f_data.c", - "musl/src/math/exp2l.c", - "musl/src/math/exp_data.c", - "musl/src/math/expl.c", - "musl/src/math/expm1.c", - "musl/src/math/expm1f.c", - "musl/src/math/expm1l.c", - "musl/src/math/fma.c", - "musl/src/math/fmaf.c", - "musl/src/math/ilogb.c", - "musl/src/math/ilogbf.c", - "musl/src/math/ilogbl.c", - "musl/src/math/__invtrigl.c", - "musl/src/math/j0.c", - "musl/src/math/j0f.c", - "musl/src/math/j1.c", - "musl/src/math/j1f.c", - "musl/src/math/jn.c", - "musl/src/math/jnf.c", - "musl/src/math/ldexp.c", - "musl/src/math/ldexpf.c", - "musl/src/math/ldexpl.c", - "musl/src/math/lgamma.c", - "musl/src/math/lgammaf.c", - "musl/src/math/lgammaf_r.c", - "musl/src/math/lgammal.c", - "musl/src/math/lgamma_r.c", - "musl/src/math/llrint.c", - "musl/src/math/llrintf.c", - "musl/src/math/llrintl.c", - "musl/src/math/llround.c", - "musl/src/math/llroundf.c", - "musl/src/math/llroundl.c", - "musl/src/math/log10l.c", - "musl/src/math/log1pl.c", - "musl/src/math/log2l.c", - "musl/src/math/logb.c", - "musl/src/math/logbf.c", - "musl/src/math/logbl.c", - "musl/src/math/logl.c", - "musl/src/math/__math_divzero.c", - "musl/src/math/__math_divzerof.c", - "musl/src/math/__math_invalid.c", - "musl/src/math/__math_invalidf.c", - "musl/src/math/__math_invalidl.c", - "musl/src/math/__math_oflow.c", - "musl/src/math/__math_oflowf.c", - "musl/src/math/__math_uflow.c", - "musl/src/math/__math_uflowf.c", - "musl/src/math/__math_xflow.c", - "musl/src/math/__math_xflowf.c", - "musl/src/math/nearbyintl.c", - "musl/src/math/nextafter.c", - "musl/src/math/nextafterf.c", - "musl/src/math/nextafterl.c", - "musl/src/math/nexttoward.c", - "musl/src/math/nexttowardf.c", - "musl/src/math/nexttowardl.c", - "musl/src/math/__polevll.c", - "musl/src/math/pow.c", - "musl/src/math/pow_data.c", - "musl/src/math/powf.c", - "musl/src/math/powf_data.c", - "musl/src/math/remainder.c", - "musl/src/math/remainderf.c", - "musl/src/math/remainderl.c", - "musl/src/math/__rem_pio2_large.c", - "musl/src/math/remquo.c", - "musl/src/math/remquof.c", - "musl/src/math/remquol.c", - "musl/src/math/scalb.c", - "musl/src/math/scalbf.c", - "musl/src/math/scalbln.c", - "musl/src/math/scalblnf.c", - "musl/src/math/scalblnl.c", - "musl/src/math/scalbn.c", - "musl/src/math/scalbnf.c", - "musl/src/math/scalbnl.c", - "musl/src/math/signgam.c", - "musl/src/math/significand.c", - "musl/src/math/significandf.c", - "musl/src/math/__sin.c", - "musl/src/math/__sindf.c", - "musl/src/math/sinhl.c", - "musl/src/math/__tan.c", - "musl/src/math/__tandf.c", - "musl/src/math/tanhl.c", - "musl/src/math/tgamma.c", - "musl/src/math/tgammaf.c", - "musl/src/math/tgammal.c", - "musl/src/misc/a64l.c", - "musl/src/misc/basename.c", - "musl/src/misc/dirname.c", - "musl/src/misc/getdomainname.c", - "musl/src/misc/gethostid.c", - "musl/src/misc/getopt.c", - "musl/src/misc/getopt_long.c", - "musl/src/misc/getsubopt.c", - "musl/src/misc/realpath.c", - "musl/src/multibyte/btowc.c", - "musl/src/multibyte/c16rtomb.c", - "musl/src/multibyte/c32rtomb.c", - "musl/src/multibyte/internal.c", - "musl/src/multibyte/mblen.c", - "musl/src/multibyte/mbrlen.c", - "musl/src/multibyte/mbrtoc16.c", - "musl/src/multibyte/mbrtoc32.c", - "musl/src/multibyte/mbrtowc.c", - "musl/src/multibyte/mbsinit.c", - "musl/src/multibyte/mbsnrtowcs.c", - "musl/src/multibyte/mbsrtowcs.c", - "musl/src/multibyte/mbstowcs.c", - "musl/src/multibyte/mbtowc.c", - "musl/src/multibyte/wcrtomb.c", - "musl/src/multibyte/wcsnrtombs.c", - "musl/src/multibyte/wcsrtombs.c", - "musl/src/multibyte/wcstombs.c", - "musl/src/multibyte/wctob.c", - "musl/src/multibyte/wctomb.c", - "musl/src/network/htonl.c", - "musl/src/network/htons.c", - "musl/src/network/in6addr_any.c", - "musl/src/network/in6addr_loopback.c", - "musl/src/network/inet_aton.c", - "musl/src/network/inet_ntop.c", - "musl/src/network/inet_pton.c", - "musl/src/network/ntohl.c", - "musl/src/network/ntohs.c", - "musl/src/regex/fnmatch.c", - "musl/src/regex/regerror.c", - "musl/src/search/hsearch.c", - "musl/src/search/lsearch.c", - "musl/src/search/tdelete.c", - "musl/src/search/tdestroy.c", - "musl/src/search/tfind.c", - "musl/src/search/tsearch.c", - "musl/src/search/twalk.c", - "musl/src/stdio/asprintf.c", - "musl/src/stdio/clearerr.c", - "musl/src/stdio/dprintf.c", - "musl/src/stdio/ext2.c", - "musl/src/stdio/ext.c", - "musl/src/stdio/fclose.c", - "musl/src/stdio/__fclose_ca.c", - "musl/src/stdio/feof.c", - "musl/src/stdio/ferror.c", - "musl/src/stdio/fflush.c", - "musl/src/stdio/fgetln.c", - "musl/src/stdio/fgets.c", - "musl/src/stdio/fgetwc.c", - "musl/src/stdio/fgetws.c", - "musl/src/stdio/fileno.c", - "musl/src/stdio/__fmodeflags.c", - "musl/src/stdio/fopencookie.c", - "musl/src/stdio/fprintf.c", - "musl/src/stdio/fputs.c", - "musl/src/stdio/fputwc.c", - "musl/src/stdio/fputws.c", - "musl/src/stdio/fread.c", - "musl/src/stdio/fscanf.c", - "musl/src/stdio/fwide.c", - "musl/src/stdio/fwprintf.c", - "musl/src/stdio/fwrite.c", - "musl/src/stdio/fwscanf.c", - "musl/src/stdio/getchar_unlocked.c", - "musl/src/stdio/getc_unlocked.c", - "musl/src/stdio/getdelim.c", - "musl/src/stdio/getline.c", - "musl/src/stdio/getw.c", - "musl/src/stdio/getwc.c", - "musl/src/stdio/getwchar.c", - "musl/src/stdio/ofl_add.c", - "musl/src/stdio/__overflow.c", - "musl/src/stdio/perror.c", - "musl/src/stdio/putchar_unlocked.c", - "musl/src/stdio/putc_unlocked.c", - "musl/src/stdio/puts.c", - "musl/src/stdio/putw.c", - "musl/src/stdio/putwc.c", - "musl/src/stdio/putwchar.c", - "musl/src/stdio/rewind.c", - "musl/src/stdio/scanf.c", - "musl/src/stdio/setbuf.c", - "musl/src/stdio/setbuffer.c", - "musl/src/stdio/setlinebuf.c", - "musl/src/stdio/setvbuf.c", - "musl/src/stdio/snprintf.c", - "musl/src/stdio/sprintf.c", - "musl/src/stdio/sscanf.c", - "musl/src/stdio/__stdio_exit.c", - "musl/src/stdio/swprintf.c", - "musl/src/stdio/swscanf.c", - "musl/src/stdio/__toread.c", - "musl/src/stdio/__towrite.c", - "musl/src/stdio/__uflow.c", - "musl/src/stdio/ungetc.c", - "musl/src/stdio/ungetwc.c", - "musl/src/stdio/vasprintf.c", - "musl/src/stdio/vfwscanf.c", - "musl/src/stdio/vprintf.c", - "musl/src/stdio/vscanf.c", - "musl/src/stdio/vsprintf.c", - "musl/src/stdio/vwprintf.c", - "musl/src/stdio/vwscanf.c", - "musl/src/stdio/wprintf.c", - "musl/src/stdio/wscanf.c", - "musl/src/stdlib/atof.c", - "musl/src/stdlib/ecvt.c", - "musl/src/stdlib/fcvt.c", - "musl/src/stdlib/gcvt.c", - "musl/src/string/strerror_r.c", - "musl/src/string/strverscmp.c", - "musl/src/string/wcscasecmp.c", - "musl/src/string/wcscasecmp_l.c", - "musl/src/string/wcsncasecmp.c", - "musl/src/string/wcsncasecmp_l.c", - "musl/src/thread/default_attr.c", - "musl/src/thread/pthread_attr_destroy.c", - "musl/src/thread/pthread_attr_init.c", - "musl/src/thread/pthread_attr_setdetachstate.c", - "musl/src/thread/pthread_attr_setstack.c", - "musl/src/thread/pthread_attr_setstacksize.c", - "musl/src/thread/pthread_barrierattr_destroy.c", - "musl/src/thread/pthread_barrierattr_init.c", - "musl/src/thread/pthread_barrierattr_setpshared.c", - "musl/src/thread/pthread_cleanup_push.c", - "musl/src/thread/pthread_condattr_destroy.c", - "musl/src/thread/pthread_condattr_init.c", - "musl/src/thread/pthread_condattr_setpshared.c", - "musl/src/thread/pthread_equal.c", - "musl/src/thread/pthread_getspecific.c", - "musl/src/thread/pthread_mutexattr_destroy.c", - "musl/src/thread/pthread_mutexattr_init.c", - "musl/src/thread/pthread_mutexattr_setpshared.c", - "musl/src/thread/pthread_mutexattr_settype.c", - "musl/src/thread/pthread_mutex_init.c", - "musl/src/thread/pthread_rwlockattr_destroy.c", - "musl/src/thread/pthread_rwlockattr_init.c", - "musl/src/thread/pthread_rwlockattr_setpshared.c", - "musl/src/thread/pthread_rwlock_destroy.c", - "musl/src/thread/pthread_rwlock_init.c", - "musl/src/thread/pthread_setcancelstate.c", - "musl/src/thread/pthread_setcanceltype.c", - "musl/src/thread/pthread_setspecific.c", - "musl/src/thread/pthread_testcancel.c", - "musl/src/thread/thrd_sleep.c", - "musl/src/time/asctime.c", - "musl/src/time/asctime_r.c", - "musl/src/time/ctime.c", - "musl/src/time/ctime_r.c", - "musl/src/time/difftime.c", - "musl/src/time/ftime.c", - "musl/src/time/__month_to_secs.c", - "musl/src/time/strptime.c", - "musl/src/time/timespec_get.c", - "musl/src/time/__year_to_secs.c", - - "wasi/libc-top-half/musl/src/conf/fpathconf.c", - "wasi/libc-top-half/musl/src/conf/sysconf.c", - "wasi/libc-top-half/musl/src/dirent/alphasort.c", - "wasi/libc-top-half/musl/src/dirent/versionsort.c", - "wasi/libc-top-half/musl/src/env/clearenv.c", - "wasi/libc-top-half/musl/src/env/getenv.c", - "wasi/libc-top-half/musl/src/env/putenv.c", - "wasi/libc-top-half/musl/src/env/__stack_chk_fail.c", - "wasi/libc-top-half/musl/src/env/unsetenv.c", - "wasi/libc-top-half/musl/src/errno/strerror.c", - "wasi/libc-top-half/musl/src/exit/atexit.c", - "wasi/libc-top-half/musl/src/exit/at_quick_exit.c", - "wasi/libc-top-half/musl/src/exit/exit.c", - "wasi/libc-top-half/musl/src/fcntl/creat.c", - "wasi/libc-top-half/musl/src/internal/defsysinfo.c", - "wasi/libc-top-half/musl/src/internal/floatscan.c", - "wasi/libc-top-half/musl/src/internal/intscan.c", - "wasi/libc-top-half/musl/src/internal/libc.c", - "wasi/libc-top-half/musl/src/internal/shgetc.c", - "wasi/libc-top-half/musl/src/locale/catclose.c", - "wasi/libc-top-half/musl/src/locale/catgets.c", - "wasi/libc-top-half/musl/src/locale/catopen.c", - "wasi/libc-top-half/musl/src/locale/locale_map.c", - "wasi/libc-top-half/musl/src/locale/newlocale.c", - "wasi/libc-top-half/musl/src/locale/uselocale.c", - "wasi/libc-top-half/musl/src/math/__expo2.c", - "wasi/libc-top-half/musl/src/math/__expo2f.c", - "wasi/libc-top-half/musl/src/math/fmal.c", - "wasi/libc-top-half/musl/src/math/powl.c", - "wasi/libc-top-half/musl/src/math/__rem_pio2.c", - "wasi/libc-top-half/musl/src/math/__rem_pio2f.c", - "wasi/libc-top-half/musl/src/math/__rem_pio2l.c", - "wasi/libc-top-half/musl/src/math/sinh.c", - "wasi/libc-top-half/musl/src/math/sinhf.c", - "wasi/libc-top-half/musl/src/misc/fmtmsg.c", - "wasi/libc-top-half/musl/src/misc/nftw.c", - "wasi/libc-top-half/musl/src/prng/random.c", - "wasi/libc-top-half/musl/src/regex/glob.c", - "wasi/libc-top-half/musl/src/regex/regcomp.c", - "wasi/libc-top-half/musl/src/regex/regexec.c", - "wasi/libc-top-half/musl/src/regex/tre-mem.c", - "wasi/libc-top-half/musl/src/stat/futimesat.c", - "wasi/libc-top-half/musl/src/stdio/__fdopen.c", - "wasi/libc-top-half/musl/src/stdio/fgetc.c", - "wasi/libc-top-half/musl/src/stdio/fgetpos.c", - "wasi/libc-top-half/musl/src/stdio/fmemopen.c", - "wasi/libc-top-half/musl/src/stdio/fopen.c", - "wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c", - "wasi/libc-top-half/musl/src/stdio/fputc.c", - "wasi/libc-top-half/musl/src/stdio/freopen.c", - "wasi/libc-top-half/musl/src/stdio/fseek.c", - "wasi/libc-top-half/musl/src/stdio/fsetpos.c", - "wasi/libc-top-half/musl/src/stdio/ftell.c", - "wasi/libc-top-half/musl/src/stdio/getc.c", - "wasi/libc-top-half/musl/src/stdio/getchar.c", - "wasi/libc-top-half/musl/src/stdio/ofl.c", - "wasi/libc-top-half/musl/src/stdio/open_memstream.c", - "wasi/libc-top-half/musl/src/stdio/open_wmemstream.c", - "wasi/libc-top-half/musl/src/stdio/printf.c", - "wasi/libc-top-half/musl/src/stdio/putc.c", - "wasi/libc-top-half/musl/src/stdio/putchar.c", - "wasi/libc-top-half/musl/src/stdio/stderr.c", - "wasi/libc-top-half/musl/src/stdio/stdin.c", - "wasi/libc-top-half/musl/src/stdio/__stdio_close.c", - "wasi/libc-top-half/musl/src/stdio/__stdio_read.c", - "wasi/libc-top-half/musl/src/stdio/__stdio_seek.c", - "wasi/libc-top-half/musl/src/stdio/__stdio_write.c", - "wasi/libc-top-half/musl/src/stdio/stdout.c", - "wasi/libc-top-half/musl/src/stdio/__stdout_write.c", - "wasi/libc-top-half/musl/src/stdio/vdprintf.c", - "wasi/libc-top-half/musl/src/stdio/vfprintf.c", - "wasi/libc-top-half/musl/src/stdio/vfscanf.c", - "wasi/libc-top-half/musl/src/stdio/vfwprintf.c", - "wasi/libc-top-half/musl/src/stdio/vsnprintf.c", - "wasi/libc-top-half/musl/src/stdio/vsscanf.c", - "wasi/libc-top-half/musl/src/stdio/vswprintf.c", - "wasi/libc-top-half/musl/src/stdio/vswscanf.c", - "wasi/libc-top-half/musl/src/stdlib/strtod.c", - "wasi/libc-top-half/musl/src/stdlib/wcstod.c", - "wasi/libc-top-half/musl/src/stdlib/wcstol.c", - "wasi/libc-top-half/musl/src/thread/pthread_attr_get.c", - "wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c", - "wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c", - "wasi/libc-top-half/musl/src/thread/pthread_cancel.c", - "wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c", - "wasi/libc-top-half/musl/src/thread/pthread_key_create.c", - "wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c", - "wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c", - "wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c", - "wasi/libc-top-half/musl/src/thread/pthread_self.c", - "wasi/libc-top-half/musl/src/time/getdate.c", - "wasi/libc-top-half/musl/src/time/gmtime.c", - "wasi/libc-top-half/musl/src/time/gmtime_r.c", - "wasi/libc-top-half/musl/src/time/localtime.c", - "wasi/libc-top-half/musl/src/time/localtime_r.c", - "wasi/libc-top-half/musl/src/time/mktime.c", - "wasi/libc-top-half/musl/src/time/__secs_to_tm.c", - "wasi/libc-top-half/musl/src/time/strftime.c", - "wasi/libc-top-half/musl/src/time/timegm.c", - "wasi/libc-top-half/musl/src/time/__tm_to_secs.c", - "wasi/libc-top-half/musl/src/time/__tz.c", - "wasi/libc-top-half/musl/src/time/wcsftime.c", - - "wasi/libc-top-half/sources/arc4random.c", - - "wasi/thread-stub/pthread_barrier_destroy.c", - "wasi/thread-stub/pthread_barrier_init.c", - "wasi/thread-stub/pthread_barrier_wait.c", - "wasi/thread-stub/pthread_cond_broadcast.c", - "wasi/thread-stub/pthread_cond_destroy.c", - "wasi/thread-stub/pthread_cond_init.c", - "wasi/thread-stub/pthread_cond_signal.c", - "wasi/thread-stub/pthread_cond_timedwait.c", - "wasi/thread-stub/pthread_cond_wait.c", - "wasi/thread-stub/pthread_create.c", - "wasi/thread-stub/pthread_detach.c", - "wasi/thread-stub/pthread_getattr_np.c", - "wasi/thread-stub/pthread_join.c", - "wasi/thread-stub/pthread_mutex_consistent.c", - "wasi/thread-stub/pthread_mutex_getprioceiling.c", - "wasi/thread-stub/pthread_mutex_lock.c", - "wasi/thread-stub/pthread_mutex_timedlock.c", - "wasi/thread-stub/pthread_mutex_trylock.c", - "wasi/thread-stub/pthread_mutex_unlock.c", - "wasi/thread-stub/pthread_once.c", - "wasi/thread-stub/pthread_rwlock_rdlock.c", - "wasi/thread-stub/pthread_rwlock_timedrdlock.c", - "wasi/thread-stub/pthread_rwlock_timedwrlock.c", - "wasi/thread-stub/pthread_rwlock_tryrdlock.c", - "wasi/thread-stub/pthread_rwlock_trywrlock.c", - "wasi/thread-stub/pthread_rwlock_unlock.c", - "wasi/thread-stub/pthread_rwlock_wrlock.c", -}; - -const crt1_command_src_file = "wasi/libc-bottom-half/crt/crt1-command.c"; -const crt1_reactor_src_file = "wasi/libc-bottom-half/crt/crt1-reactor.c"; - -const fts_src_files = &[_][]const u8{ - "wasi/fts/musl-fts/fts.c", -}; - -const setjmp_src_files = &[_][]const u8{ - "wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c", -}; - -const emulated_dl_src_files = &[_][]const u8{ - "wasi/libc-top-half/musl/src/misc/dl.c", -}; - -const emulated_process_clocks_src_files = &[_][]const u8{ - "wasi/libc-bottom-half/clocks/clock.c", - "wasi/libc-bottom-half/clocks/getrusage.c", - "wasi/libc-bottom-half/clocks/times.c", -}; - -const emulated_getpid_src_files = &[_][]const u8{ - "wasi/libc-bottom-half/getpid/getpid.c", -}; - -const emulated_mman_src_files = &[_][]const u8{ - "wasi/libc-bottom-half/mman/mman.c", -}; - -const emulated_signal_bottom_half_src_files = &[_][]const u8{ - "wasi/libc-bottom-half/signal/signal.c", -}; - -const emulated_signal_top_half_src_files = &[_][]const u8{ - "musl/src/signal/psignal.c", - "musl/src/string/strsignal.c", -}; diff --git a/src/link.zig b/src/link.zig index be4505c462076a5b4ee900db75e16ede3e05e6c3..5b1b0bbeb601c90013a603f4014b1c32254a8634 100644 --- a/src/link.zig +++ b/src/link.zig @@ -15,7 +15,6 @@ const Compilation = @import("Compilation.zig"); const LibCInstallation = std.zig.LibCInstallation; const trace = @import("tracy.zig").trace; -const wasi_libc = @import("libs/wasi_libc.zig"); const Zcu = @import("Zcu.zig"); const InternPool = @import("InternPool.zig"); diff --git a/src/link/Lld.zig b/src/link/Lld.zig index ccdaadab5a4900375fc7396ee76842cffdff0df0..c7d428e209e169a8a580b2dfea6648019c6417eb 100644 --- a/src/link/Lld.zig +++ b/src/link/Lld.zig @@ -1565,18 +1565,6 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void { (comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic); if (comp.config.link_libc and is_exe_or_dyn_lib) { - if (target.os.tag == .wasi) { - try argv.append(try comp.crtFileAsString( - arena, - wasi_libc.execModelCrtFileFullName(comp.config.wasi_exec_model), - )); - try argv.append(try comp.crtFileAsString(arena, "libc.a")); - } - - if (comp.zigc_static_lib) |zigc| { - try argv.append(try zigc.full_object_path.toString(arena)); - } - if (comp.config.link_libcpp) { try argv.append(try comp.libcxx_static_lib.?.full_object_path.toString(arena)); try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena)); @@ -1706,7 +1694,6 @@ const freebsd = @import("../libs/freebsd.zig"); const glibc = @import("../libs/glibc.zig"); const netbsd = @import("../libs/netbsd.zig"); const openbsd = @import("../libs/openbsd.zig"); -const wasi_libc = @import("../libs/wasi_libc.zig"); const link = @import("../link.zig"); const lldMain = @import("../main.zig").lldMain; const target_util = @import("../target.zig"); diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index ea00a2f31b74610c151499948658af9e85002903..953f3b6140ed13060bc10de49cf8c945a9eb402a 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -40,7 +40,6 @@ const Zcu = @import("../Zcu.zig"); const codegen = @import("../codegen.zig"); const link = @import("../link.zig"); const trace = @import("../tracy.zig").trace; -const wasi_libc = @import("../libs/wasi_libc.zig"); const Value = @import("../Value.zig"); base: link.File, diff --git a/src/main.zig b/src/main.zig index 7d9d7e8ef506177405d5b2e1c859ad9afbc0d66d..68b38d043071c3ca48e2bd3aab68648165c13530 100644 --- a/src/main.zig +++ b/src/main.zig @@ -26,7 +26,6 @@ pub const tracy = @import("tracy.zig"); const Compilation = @import("Compilation.zig"); const link = @import("link.zig"); const build_options = @import("build_options"); -const wasi_libc = @import("libs/wasi_libc.zig"); const target_util = @import("target.zig"); const crash_report = @import("crash_report.zig"); const Zcu = @import("Zcu.zig"); diff --git a/src/target.zig b/src/target.zig index 6234c11a146b18c45b6b36ecf12138edebb99a5c..f8065f9a61523e57df99d28bdfd09b06a079c995 100644 --- a/src/target.zig +++ b/src/target.zig @@ -365,10 +365,6 @@ pub fn clangSupportsStackProtector(target: *const std.Target) bool { }; } -pub fn libcProvidesStackProtector(target: *const std.Target) bool { - return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV(); -} - /// Returns true if `@returnAddress()` is supported by the target and has a /// reasonably performant implementation for the requested optimization mode. pub fn supportsReturnAddress(target: *const std.Target, optimize: std.lang.Optimize) bool { @@ -478,7 +474,7 @@ pub fn canBuildLibUbsanRt(target: *const std.Target) enum { no, yes, llvm_only, /// Whether libzigc can fill-in the gaps of an existing libc /// or *is* the libc of the target. pub fn wantsZigC(target: *const std.Target, link_mode: std.lang.LinkMode) bool { - return (target.isMuslLibC() and link_mode == .static) or target.isWasiLibC() or target.isMinGW(); + return (target.isMuslLibC() and link_mode == .static) or target.isMinGW(); } pub fn hasRedZone(target: *const std.Target) bool { diff --git a/test/cases/export_override_libc.zig b/test/cases/export_override_libc.zig index bc16cb8dd2cdfcb0f09da2da83715b2ec9715321..625eff7b3d6c8ff365b31ebf66ae6c291461b7b2 100644 --- a/test/cases/export_override_libc.zig +++ b/test/cases/export_override_libc.zig @@ -13,4 +13,5 @@ pub fn main() void { } // run +// target=native // link_libc=true diff --git a/test/libc.zig b/test/libc.zig index 6f5590a543fe9966cd82cc3ed5241ae03f6566b6..b23ac2e30938e74f25d44bafb85baaea733139ca 100644 --- a/test/libc.zig +++ b/test/libc.zig @@ -1,342 +1,342 @@ pub fn addCases(cases: *tests.LibcContext) void { - cases.addLibcTestCase("api/main.c", true, .{}); + cases.addLibcTestCase("api/main.c", .{}); - cases.addLibcTestCase("functional/argv.c", true, .{}); - cases.addLibcTestCase("functional/basename.c", true, .{}); - cases.addLibcTestCase("functional/clocale_mbfuncs.c", true, .{}); - cases.addLibcTestCase("functional/clock_gettime.c", true, .{}); - cases.addLibcTestCase("functional/crypt.c", true, .{}); - cases.addLibcTestCase("functional/dirname.c", true, .{}); - cases.addLibcTestCase("functional/env.c", true, .{}); - cases.addLibcTestCase("functional/fcntl.c", false, .{}); - cases.addLibcTestCase("functional/fdopen.c", false, .{}); - cases.addLibcTestCase("functional/fnmatch.c", true, .{}); - cases.addLibcTestCase("functional/fscanf.c", false, .{}); - cases.addLibcTestCase("functional/fwscanf.c", false, .{}); - cases.addLibcTestCase("functional/iconv_open.c", true, .{}); - cases.addLibcTestCase("functional/inet_pton.c", false, .{}); + cases.addLibcTestCase("functional/argv.c", .{}); + cases.addLibcTestCase("functional/basename.c", .{}); + cases.addLibcTestCase("functional/clocale_mbfuncs.c", .{}); + cases.addLibcTestCase("functional/clock_gettime.c", .{}); + cases.addLibcTestCase("functional/crypt.c", .{}); + cases.addLibcTestCase("functional/dirname.c", .{}); + cases.addLibcTestCase("functional/env.c", .{}); + cases.addLibcTestCase("functional/fcntl.c", .{}); + cases.addLibcTestCase("functional/fdopen.c", .{}); + cases.addLibcTestCase("functional/fnmatch.c", .{}); + cases.addLibcTestCase("functional/fscanf.c", .{}); + cases.addLibcTestCase("functional/fwscanf.c", .{}); + cases.addLibcTestCase("functional/iconv_open.c", .{}); + cases.addLibcTestCase("functional/inet_pton.c", .{}); // "functional/ipc_msg.c": Probably a bug in qemu // "functional/ipc_sem.c": Probably a bug in qemu // "functional/ipc_shm.c": Probably a bug in qemu - cases.addLibcTestCase("functional/mbc.c", true, .{}); - cases.addLibcTestCase("functional/memstream.c", true, .{}); + cases.addLibcTestCase("functional/mbc.c", .{}); + cases.addLibcTestCase("functional/memstream.c", .{}); // "functional/mntent.c": https://www.openwall.com/lists/musl/2024/10/22/1 - cases.addLibcTestCase("functional/popen.c", false, .{}); - // cases.addLibcTestCase("functional/pthread_cancel-points.c", false, .{}); - racey if multiple instances of the test run concurrently. - cases.addLibcTestCase("functional/pthread_cancel.c", false, .{}); - cases.addLibcTestCase("functional/pthread_cond.c", false, .{}); - cases.addLibcTestCase("functional/pthread_mutex.c", false, .{}); + cases.addLibcTestCase("functional/popen.c", .{}); + // cases.addLibcTestCase("functional/pthread_cancel-points.c", .{}); - racey if multiple instances of the test run concurrently. + cases.addLibcTestCase("functional/pthread_cancel.c", .{}); + cases.addLibcTestCase("functional/pthread_cond.c", .{}); + cases.addLibcTestCase("functional/pthread_mutex.c", .{}); // "functional/pthread_mutex_pi.c": Probably a bug in qemu (big/little endian FUTEX_LOCK_PI) // "functional/pthread_robust.c": https://gitlab.com/qemu-project/qemu/-/issues/2424 - cases.addLibcTestCase("functional/pthread_tsd.c", false, .{}); - cases.addLibcTestCase("functional/qsort.c", true, .{}); - cases.addLibcTestCase("functional/random.c", true, .{}); - cases.addLibcTestCase("functional/search_hsearch.c", true, .{}); - cases.addLibcTestCase("functional/search_insque.c", true, .{}); - cases.addLibcTestCase("functional/search_lsearch.c", true, .{}); - cases.addLibcTestCase("functional/search_tsearch.c", true, .{}); - cases.addLibcTestCase("functional/sem_init.c", false, .{}); - cases.addLibcTestCase("functional/sem_open.c", false, .{}); - cases.addLibcTestCase("functional/setjmp.c", false, .{}); - cases.addLibcTestCase("functional/snprintf.c", true, .{}); - cases.addLibcTestCase("functional/socket.c", false, .{}); - cases.addLibcTestCase("functional/spawn.c", false, .{}); - cases.addLibcTestCase("functional/sscanf.c", true, .{}); - cases.addLibcTestCase("functional/sscanf_long.c", false, .{}); - cases.addLibcTestCase("functional/stat.c", false, .{}); - cases.addLibcTestCase("functional/strftime.c", true, .{}); - cases.addLibcTestCase("functional/string.c", true, .{}); - cases.addLibcTestCase("functional/string_memcpy.c", true, .{}); - cases.addLibcTestCase("functional/string_memmem.c", true, .{}); - cases.addLibcTestCase("functional/string_memset.c", true, .{}); - cases.addLibcTestCase("functional/string_strchr.c", true, .{}); - cases.addLibcTestCase("functional/string_strcspn.c", true, .{}); - cases.addLibcTestCase("functional/string_strstr.c", true, .{}); - cases.addLibcTestCase("functional/strtod.c", true, .{}); - cases.addLibcTestCase("functional/strtod_long.c", true, .{}); - cases.addLibcTestCase("functional/strtod_simple.c", true, .{}); - cases.addLibcTestCase("functional/strtof.c", true, .{}); - cases.addLibcTestCase("functional/strtol.c", true, .{}); - cases.addLibcTestCase("functional/strtold.c", true, .{}); - cases.addLibcTestCase("functional/swprintf.c", true, .{}); - cases.addLibcTestCase("functional/tgmath.c", true, .{}); - cases.addLibcTestCase("functional/time.c", false, .{}); - cases.addLibcTestCase("functional/tls_align.c", true, .{ .additional_src_file = "functional/tls_align_dso.c" }); - cases.addLibcTestCase("functional/tls_init.c", false, .{}); - cases.addLibcTestCase("functional/tls_local_exec.c", false, .{}); - cases.addLibcTestCase("functional/udiv.c", true, .{}); - cases.addLibcTestCase("functional/ungetc.c", false, .{}); - // cases.addLibcTestCase("functional/utime.c", false, .{}); - fails under heavy load; futimens not reflected in subsequent fstat - cases.addLibcTestCase("functional/vfork.c", false, .{}); - cases.addLibcTestCase("functional/wcsstr.c", true, .{}); - cases.addLibcTestCase("functional/wcstol.c", true, .{}); + cases.addLibcTestCase("functional/pthread_tsd.c", .{}); + cases.addLibcTestCase("functional/qsort.c", .{}); + cases.addLibcTestCase("functional/random.c", .{}); + cases.addLibcTestCase("functional/search_hsearch.c", .{}); + cases.addLibcTestCase("functional/search_insque.c", .{}); + cases.addLibcTestCase("functional/search_lsearch.c", .{}); + cases.addLibcTestCase("functional/search_tsearch.c", .{}); + cases.addLibcTestCase("functional/sem_init.c", .{}); + cases.addLibcTestCase("functional/sem_open.c", .{}); + cases.addLibcTestCase("functional/setjmp.c", .{}); + cases.addLibcTestCase("functional/snprintf.c", .{}); + cases.addLibcTestCase("functional/socket.c", .{}); + cases.addLibcTestCase("functional/spawn.c", .{}); + cases.addLibcTestCase("functional/sscanf.c", .{}); + cases.addLibcTestCase("functional/sscanf_long.c", .{}); + cases.addLibcTestCase("functional/stat.c", .{}); + cases.addLibcTestCase("functional/strftime.c", .{}); + cases.addLibcTestCase("functional/string.c", .{}); + cases.addLibcTestCase("functional/string_memcpy.c", .{}); + cases.addLibcTestCase("functional/string_memmem.c", .{}); + cases.addLibcTestCase("functional/string_memset.c", .{}); + cases.addLibcTestCase("functional/string_strchr.c", .{}); + cases.addLibcTestCase("functional/string_strcspn.c", .{}); + cases.addLibcTestCase("functional/string_strstr.c", .{}); + cases.addLibcTestCase("functional/strtod.c", .{}); + cases.addLibcTestCase("functional/strtod_long.c", .{}); + cases.addLibcTestCase("functional/strtod_simple.c", .{}); + cases.addLibcTestCase("functional/strtof.c", .{}); + cases.addLibcTestCase("functional/strtol.c", .{}); + cases.addLibcTestCase("functional/strtold.c", .{}); + cases.addLibcTestCase("functional/swprintf.c", .{}); + cases.addLibcTestCase("functional/tgmath.c", .{}); + cases.addLibcTestCase("functional/time.c", .{}); + cases.addLibcTestCase("functional/tls_align.c", .{ .additional_src_file = "functional/tls_align_dso.c" }); + cases.addLibcTestCase("functional/tls_init.c", .{}); + cases.addLibcTestCase("functional/tls_local_exec.c", .{}); + cases.addLibcTestCase("functional/udiv.c", .{}); + cases.addLibcTestCase("functional/ungetc.c", .{}); + // cases.addLibcTestCase("functional/utime.c", .{}); - fails under heavy load; futimens not reflected in subsequent fstat + cases.addLibcTestCase("functional/vfork.c", .{}); + cases.addLibcTestCase("functional/wcsstr.c", .{}); + cases.addLibcTestCase("functional/wcstol.c", .{}); - // cases.addLibcTestCase("regression/daemon-failure.c", false, .{}); - unexpected ENOMEM with high FD limit - cases.addLibcTestCase("regression/dn_expand-empty.c", false, .{}); - cases.addLibcTestCase("regression/dn_expand-ptr-0.c", false, .{}); - cases.addLibcTestCase("regression/execle-env.c", false, .{}); - cases.addLibcTestCase("regression/fflush-exit.c", false, .{}); - cases.addLibcTestCase("regression/fgets-eof.c", true, .{}); - cases.addLibcTestCase("regression/fgetwc-buffering.c", false, .{}); - cases.addLibcTestCase("regression/flockfile-list.c", false, .{}); - cases.addLibcTestCase("regression/fpclassify-invalid-ld80.c", true, .{}); - cases.addLibcTestCase("regression/ftello-unflushed-append.c", false, .{}); - cases.addLibcTestCase("regression/getpwnam_r-crash.c", false, .{}); - cases.addLibcTestCase("regression/getpwnam_r-errno.c", false, .{}); - cases.addLibcTestCase("regression/iconv-roundtrips.c", true, .{}); - cases.addLibcTestCase("regression/inet_ntop-v4mapped.c", true, .{}); - cases.addLibcTestCase("regression/inet_pton-empty-last-field.c", true, .{}); - cases.addLibcTestCase("regression/iswspace-null.c", true, .{}); - cases.addLibcTestCase("regression/lrand48-signextend.c", true, .{}); - cases.addLibcTestCase("regression/lseek-large.c", false, .{}); - cases.addLibcTestCase("regression/malloc-0.c", true, .{}); + // cases.addLibcTestCase("regression/daemon-failure.c", .{}); - unexpected ENOMEM with high FD limit + cases.addLibcTestCase("regression/dn_expand-empty.c", .{}); + cases.addLibcTestCase("regression/dn_expand-ptr-0.c", .{}); + cases.addLibcTestCase("regression/execle-env.c", .{}); + cases.addLibcTestCase("regression/fflush-exit.c", .{}); + cases.addLibcTestCase("regression/fgets-eof.c", .{}); + cases.addLibcTestCase("regression/fgetwc-buffering.c", .{}); + cases.addLibcTestCase("regression/flockfile-list.c", .{}); + cases.addLibcTestCase("regression/fpclassify-invalid-ld80.c", .{}); + cases.addLibcTestCase("regression/ftello-unflushed-append.c", .{}); + cases.addLibcTestCase("regression/getpwnam_r-crash.c", .{}); + cases.addLibcTestCase("regression/getpwnam_r-errno.c", .{}); + cases.addLibcTestCase("regression/iconv-roundtrips.c", .{}); + cases.addLibcTestCase("regression/inet_ntop-v4mapped.c", .{}); + cases.addLibcTestCase("regression/inet_pton-empty-last-field.c", .{}); + cases.addLibcTestCase("regression/iswspace-null.c", .{}); + cases.addLibcTestCase("regression/lrand48-signextend.c", .{}); + cases.addLibcTestCase("regression/lseek-large.c", .{}); + cases.addLibcTestCase("regression/malloc-0.c", .{}); // "regression/malloc-brk-fail.c": QEMU OOM - // cases.addLibcTestCase("regression/malloc-oom.c", false, .{}); // wasi-libc: requires t_memfill; QEMU OOM - cases.addLibcTestCase("regression/mbsrtowcs-overflow.c", true, .{}); - cases.addLibcTestCase("regression/memmem-oob-read.c", true, .{}); - cases.addLibcTestCase("regression/memmem-oob.c", true, .{}); - cases.addLibcTestCase("regression/mkdtemp-failure.c", false, .{}); - cases.addLibcTestCase("regression/mkstemp-failure.c", false, .{}); - cases.addLibcTestCase("regression/printf-1e9-oob.c", true, .{}); - cases.addLibcTestCase("regression/printf-fmt-g-round.c", true, .{}); - cases.addLibcTestCase("regression/printf-fmt-g-zeros.c", true, .{}); - cases.addLibcTestCase("regression/printf-fmt-n.c", true, .{}); + // cases.addLibcTestCase("regression/malloc-oom.c", .{}); // QEMU OOM + cases.addLibcTestCase("regression/mbsrtowcs-overflow.c", .{}); + cases.addLibcTestCase("regression/memmem-oob-read.c", .{}); + cases.addLibcTestCase("regression/memmem-oob.c", .{}); + cases.addLibcTestCase("regression/mkdtemp-failure.c", .{}); + cases.addLibcTestCase("regression/mkstemp-failure.c", .{}); + cases.addLibcTestCase("regression/printf-1e9-oob.c", .{}); + cases.addLibcTestCase("regression/printf-fmt-g-round.c", .{}); + cases.addLibcTestCase("regression/printf-fmt-g-zeros.c", .{}); + cases.addLibcTestCase("regression/printf-fmt-n.c", .{}); // "regression/pthread-robust-detach.c": https://gitlab.com/qemu-project/qemu/-/issues/2424 - cases.addLibcTestCase("regression/pthread_atfork-errno-clobber.c", false, .{}); - cases.addLibcTestCase("regression/pthread_cancel-sem_wait.c", false, .{}); - // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond-smasher.c", false, .{}); - // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond_wait-cancel_ignored.c", false, .{}); - cases.addLibcTestCase("regression/pthread_condattr_setclock.c", false, .{}); + cases.addLibcTestCase("regression/pthread_atfork-errno-clobber.c", .{}); + cases.addLibcTestCase("regression/pthread_cancel-sem_wait.c", .{}); + // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond-smasher.c", .{}); + // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond_wait-cancel_ignored.c", .{}); + cases.addLibcTestCase("regression/pthread_condattr_setclock.c", .{}); // "regression/pthread_create-oom.c": QEMU OOM - cases.addLibcTestCase("regression/pthread_exit-cancel.c", false, .{}); - cases.addLibcTestCase("regression/pthread_exit-dtor.c", false, .{}); - cases.addLibcTestCase("regression/pthread_once-deadlock.c", false, .{}); - cases.addLibcTestCase("regression/pthread_rwlock-ebusy.c", false, .{}); - cases.addLibcTestCase("regression/putenv-doublefree.c", true, .{}); - // cases.addLibcTestCase("regression/raise-race.c", false, .{}); - Sometimes hangs when run natively on x86_64-linux. - cases.addLibcTestCase("regression/regex-backref-0.c", true, .{}); - cases.addLibcTestCase("regression/regex-bracket-icase.c", true, .{}); - cases.addLibcTestCase("regression/regex-ere-backref.c", true, .{}); - cases.addLibcTestCase("regression/regex-escaped-high-byte.c", true, .{}); - cases.addLibcTestCase("regression/regex-negated-range.c", true, .{}); - cases.addLibcTestCase("regression/regexec-nosub.c", true, .{}); - cases.addLibcTestCase("regression/rewind-clear-error.c", false, .{}); - // cases.addLibcTestCase("regression/rlimit-open-files.c", false, .{}); - fails when machine is under heavy load - cases.addLibcTestCase("regression/scanf-bytes-consumed.c", true, .{}); - cases.addLibcTestCase("regression/scanf-match-literal-eof.c", true, .{}); - cases.addLibcTestCase("regression/scanf-nullbyte-char.c", true, .{}); - cases.addLibcTestCase("regression/sem_close-unmap.c", false, .{}); + cases.addLibcTestCase("regression/pthread_exit-cancel.c", .{}); + cases.addLibcTestCase("regression/pthread_exit-dtor.c", .{}); + cases.addLibcTestCase("regression/pthread_once-deadlock.c", .{}); + cases.addLibcTestCase("regression/pthread_rwlock-ebusy.c", .{}); + cases.addLibcTestCase("regression/putenv-doublefree.c", .{}); + // cases.addLibcTestCase("regression/raise-race.c", .{}); - Sometimes hangs when run natively on x86_64-linux. + cases.addLibcTestCase("regression/regex-backref-0.c", .{}); + cases.addLibcTestCase("regression/regex-bracket-icase.c", .{}); + cases.addLibcTestCase("regression/regex-ere-backref.c", .{}); + cases.addLibcTestCase("regression/regex-escaped-high-byte.c", .{}); + cases.addLibcTestCase("regression/regex-negated-range.c", .{}); + cases.addLibcTestCase("regression/regexec-nosub.c", .{}); + cases.addLibcTestCase("regression/rewind-clear-error.c", .{}); + // cases.addLibcTestCase("regression/rlimit-open-files.c", .{}); - fails when machine is under heavy load + cases.addLibcTestCase("regression/scanf-bytes-consumed.c", .{}); + cases.addLibcTestCase("regression/scanf-match-literal-eof.c", .{}); + cases.addLibcTestCase("regression/scanf-nullbyte-char.c", .{}); + cases.addLibcTestCase("regression/sem_close-unmap.c", .{}); // "regression/setenv-oom.c": QEMU OOM - cases.addLibcTestCase("regression/setvbuf-unget.c", true, .{}); - cases.addLibcTestCase("regression/sigaltstack.c", false, .{}); - cases.addLibcTestCase("regression/sigprocmask-internal.c", false, .{}); - cases.addLibcTestCase("regression/sigreturn.c", true, .{}); - cases.addLibcTestCase("regression/sscanf-eof.c", true, .{}); - cases.addLibcTestCase("regression/strverscmp.c", true, .{}); - cases.addLibcTestCase("regression/syscall-sign-extend.c", false, .{}); - cases.addLibcTestCase("regression/uselocale-0.c", true, .{}); - cases.addLibcTestCase("regression/wcsncpy-read-overflow.c", true, .{}); - cases.addLibcTestCase("regression/wcsstr-false-negative.c", true, .{}); + cases.addLibcTestCase("regression/setvbuf-unget.c", .{}); + cases.addLibcTestCase("regression/sigaltstack.c", .{}); + cases.addLibcTestCase("regression/sigprocmask-internal.c", .{}); + cases.addLibcTestCase("regression/sigreturn.c", .{}); + cases.addLibcTestCase("regression/sscanf-eof.c", .{}); + cases.addLibcTestCase("regression/strverscmp.c", .{}); + cases.addLibcTestCase("regression/syscall-sign-extend.c", .{}); + cases.addLibcTestCase("regression/uselocale-0.c", .{}); + cases.addLibcTestCase("regression/wcsncpy-read-overflow.c", .{}); + cases.addLibcTestCase("regression/wcsstr-false-negative.c", .{}); - cases.addLibcTestCase("math/acos.c", true, .{}); - cases.addLibcTestCase("math/acosf.c", true, .{}); - // cases.addLibcTestCase("math/acosh.c", true, .{}); - cases.addLibcTestCase("math/acoshf.c", true, .{}); - // cases.addLibcTestCase("math/acoshl.c", true, .{}); - // cases.addLibcTestCase("math/acosl.c", true, .{}); - cases.addLibcTestCase("math/asin.c", true, .{}); - cases.addLibcTestCase("math/asinf.c", true, .{}); - // cases.addLibcTestCase("math/asinh.c", true, .{}); - cases.addLibcTestCase("math/asinhf.c", true, .{}); - // cases.addLibcTestCase("math/asinhl.c", true, .{}); - cases.addLibcTestCase("math/asinl.c", true, .{}); - cases.addLibcTestCase("math/atan.c", true, .{}); - cases.addLibcTestCase("math/atan2.c", true, .{}); - cases.addLibcTestCase("math/atan2f.c", true, .{}); - cases.addLibcTestCase("math/atan2l.c", true, .{}); - cases.addLibcTestCase("math/atanf.c", true, .{}); - cases.addLibcTestCase("math/atanh.c", true, .{}); - cases.addLibcTestCase("math/atanhf.c", true, .{}); - cases.addLibcTestCase("math/atanhl.c", true, .{}); - cases.addLibcTestCase("math/atanl.c", true, .{}); - cases.addLibcTestCase("math/cbrt.c", true, .{}); - cases.addLibcTestCase("math/cbrtf.c", true, .{}); - cases.addLibcTestCase("math/cbrtl.c", true, .{}); - cases.addLibcTestCase("math/ceil.c", true, .{}); - cases.addLibcTestCase("math/ceilf.c", true, .{}); - cases.addLibcTestCase("math/ceill.c", true, .{}); - cases.addLibcTestCase("math/copysign.c", true, .{}); - cases.addLibcTestCase("math/copysignf.c", true, .{}); - cases.addLibcTestCase("math/copysignl.c", true, .{}); - cases.addLibcTestCase("math/cos.c", true, .{}); - cases.addLibcTestCase("math/cosf.c", true, .{}); - cases.addLibcTestCase("math/cosh.c", true, .{}); - cases.addLibcTestCase("math/coshf.c", true, .{}); - cases.addLibcTestCase("math/coshl.c", true, .{}); - cases.addLibcTestCase("math/cosl.c", true, .{}); - cases.addLibcTestCase("math/drem.c", true, .{}); - cases.addLibcTestCase("math/dremf.c", true, .{}); - cases.addLibcTestCase("math/erf.c", true, .{}); - cases.addLibcTestCase("math/erfc.c", true, .{}); - // cases.addLibcTestCase("math/erfcf.c", true, .{}); - cases.addLibcTestCase("math/erfcl.c", true, .{}); - cases.addLibcTestCase("math/erff.c", true, .{}); - cases.addLibcTestCase("math/erfl.c", true, .{}); - cases.addLibcTestCase("math/exp.c", true, .{}); - cases.addLibcTestCase("math/exp10.c", true, .{}); - cases.addLibcTestCase("math/exp10f.c", true, .{}); - cases.addLibcTestCase("math/exp10l.c", true, .{}); - cases.addLibcTestCase("math/exp2.c", true, .{}); - cases.addLibcTestCase("math/exp2f.c", true, .{}); - cases.addLibcTestCase("math/exp2l.c", true, .{}); - cases.addLibcTestCase("math/expf.c", true, .{}); - cases.addLibcTestCase("math/expl.c", true, .{}); - // cases.addLibcTestCase("math/expm1.c", true, .{}); - // cases.addLibcTestCase("math/expm1f.c", true, .{}); - // cases.addLibcTestCase("math/expm1l.c", true, .{}); - cases.addLibcTestCase("math/fabs.c", true, .{}); - cases.addLibcTestCase("math/fabsf.c", true, .{}); - cases.addLibcTestCase("math/fabsl.c", true, .{}); - cases.addLibcTestCase("math/fdim.c", true, .{}); - cases.addLibcTestCase("math/fdimf.c", true, .{}); - cases.addLibcTestCase("math/fdiml.c", true, .{}); - cases.addLibcTestCase("math/fenv.c", true, .{}); - cases.addLibcTestCase("math/floor.c", true, .{}); - cases.addLibcTestCase("math/floorf.c", true, .{}); - cases.addLibcTestCase("math/floorl.c", true, .{}); - // cases.addLibcTestCase("math/fma.c", true, .{}); - // cases.addLibcTestCase("math/fmaf.c", true, .{}); - // cases.addLibcTestCase("math/fmal.c", true, .{}); - cases.addLibcTestCase("math/fmax.c", true, .{}); - cases.addLibcTestCase("math/fmaxf.c", true, .{}); - cases.addLibcTestCase("math/fmaxl.c", true, .{}); - cases.addLibcTestCase("math/fmin.c", true, .{}); - cases.addLibcTestCase("math/fminf.c", true, .{}); - cases.addLibcTestCase("math/fminl.c", true, .{}); - cases.addLibcTestCase("math/fmod.c", true, .{}); - cases.addLibcTestCase("math/fmodf.c", true, .{}); - cases.addLibcTestCase("math/fmodl.c", true, .{}); - cases.addLibcTestCase("math/fpclassify.c", true, .{}); - cases.addLibcTestCase("math/frexp.c", true, .{}); - cases.addLibcTestCase("math/frexpf.c", true, .{}); - cases.addLibcTestCase("math/frexpl.c", true, .{}); - cases.addLibcTestCase("math/hypot.c", true, .{}); - cases.addLibcTestCase("math/hypotf.c", true, .{}); - cases.addLibcTestCase("math/hypotl.c", true, .{}); - // cases.addLibcTestCase("math/ilogb.c", true, .{}); - // cases.addLibcTestCase("math/ilogbf.c", true, .{}); - // cases.addLibcTestCase("math/ilogbl.c", true, .{}); - cases.addLibcTestCase("math/isless.c", true, .{}); - // cases.addLibcTestCase("math/j0.c", true, .{}); - cases.addLibcTestCase("math/j0f.c", true, .{}); - cases.addLibcTestCase("math/j1.c", true, .{}); - cases.addLibcTestCase("math/j1f.c", true, .{}); - // cases.addLibcTestCase("math/jn.c", true, .{}); - // cases.addLibcTestCase("math/jnf.c", true, .{}); - cases.addLibcTestCase("math/ldexp.c", true, .{}); - cases.addLibcTestCase("math/ldexpf.c", true, .{}); - cases.addLibcTestCase("math/ldexpl.c", true, .{}); - // cases.addLibcTestCase("math/lgamma.c", true, .{}); - cases.addLibcTestCase("math/lgamma_r.c", true, .{}); - // cases.addLibcTestCase("math/lgammaf.c", true, .{}); - // cases.addLibcTestCase("math/lgammaf_r.c", true, .{}); - // cases.addLibcTestCase("math/lgammal.c", true, .{}); - cases.addLibcTestCase("math/lgammal_r.c", true, .{}); - // cases.addLibcTestCase("math/llrint.c", true, .{}); - // cases.addLibcTestCase("math/llrintf.c", true, .{}); - // cases.addLibcTestCase("math/llrintl.c", true, .{}); - // cases.addLibcTestCase("math/llround.c", true, .{}); - // cases.addLibcTestCase("math/llroundf.c", true, .{}); - // cases.addLibcTestCase("math/llroundl.c", true, .{}); - cases.addLibcTestCase("math/log.c", true, .{}); - cases.addLibcTestCase("math/log10.c", true, .{}); - cases.addLibcTestCase("math/log10f.c", true, .{}); - cases.addLibcTestCase("math/log10l.c", true, .{}); - cases.addLibcTestCase("math/log1p.c", true, .{}); - cases.addLibcTestCase("math/log1pf.c", true, .{}); - // cases.addLibcTestCase("math/log1pl.c", true, .{}); - cases.addLibcTestCase("math/log2.c", true, .{}); - cases.addLibcTestCase("math/log2f.c", true, .{}); - cases.addLibcTestCase("math/log2l.c", true, .{}); - cases.addLibcTestCase("math/logb.c", true, .{}); - cases.addLibcTestCase("math/logbf.c", true, .{}); - cases.addLibcTestCase("math/logbl.c", true, .{}); - cases.addLibcTestCase("math/logf.c", true, .{}); - cases.addLibcTestCase("math/logl.c", true, .{}); - cases.addLibcTestCase("math/lrint.c", true, .{}); - cases.addLibcTestCase("math/lrintf.c", true, .{}); - cases.addLibcTestCase("math/lrintl.c", true, .{}); - cases.addLibcTestCase("math/lround.c", true, .{}); - cases.addLibcTestCase("math/lroundf.c", true, .{}); - cases.addLibcTestCase("math/lroundl.c", true, .{}); - cases.addLibcTestCase("math/modf.c", true, .{}); - cases.addLibcTestCase("math/modff.c", true, .{}); - cases.addLibcTestCase("math/modfl.c", true, .{}); - // cases.addLibcTestCase("math/nearbyint.c", true, .{}); - cases.addLibcTestCase("math/nearbyintf.c", true, .{}); - // cases.addLibcTestCase("math/nearbyintl.c", true, .{}); - cases.addLibcTestCase("math/nextafter.c", true, .{}); - cases.addLibcTestCase("math/nextafterf.c", true, .{}); - cases.addLibcTestCase("math/nextafterl.c", true, .{}); - cases.addLibcTestCase("math/nexttoward.c", true, .{}); - cases.addLibcTestCase("math/nexttowardf.c", true, .{}); - cases.addLibcTestCase("math/nexttowardl.c", true, .{}); - // cases.addLibcTestCase("math/pow.c", true, .{}); - cases.addLibcTestCase("math/pow10.c", true, .{}); - cases.addLibcTestCase("math/pow10f.c", true, .{}); - cases.addLibcTestCase("math/pow10l.c", true, .{}); - // cases.addLibcTestCase("math/powf.c", true, .{}); - // cases.addLibcTestCase("math/powl.c", true, .{}); - cases.addLibcTestCase("math/remainder.c", true, .{}); - cases.addLibcTestCase("math/remainderf.c", true, .{}); - cases.addLibcTestCase("math/remainderl.c", true, .{}); - cases.addLibcTestCase("math/remquo.c", true, .{}); - cases.addLibcTestCase("math/remquof.c", true, .{}); - cases.addLibcTestCase("math/remquol.c", true, .{}); - cases.addLibcTestCase("math/rint.c", true, .{}); - cases.addLibcTestCase("math/rintf.c", true, .{}); - cases.addLibcTestCase("math/rintl.c", true, .{}); - cases.addLibcTestCase("math/round.c", true, .{}); - cases.addLibcTestCase("math/roundf.c", true, .{}); - cases.addLibcTestCase("math/roundl.c", true, .{}); - cases.addLibcTestCase("math/scalb.c", true, .{}); - cases.addLibcTestCase("math/scalbf.c", true, .{}); - cases.addLibcTestCase("math/scalbln.c", true, .{}); - cases.addLibcTestCase("math/scalblnf.c", true, .{}); - cases.addLibcTestCase("math/scalblnl.c", true, .{}); - cases.addLibcTestCase("math/scalbn.c", true, .{}); - cases.addLibcTestCase("math/scalbnf.c", true, .{}); - cases.addLibcTestCase("math/scalbnl.c", true, .{}); - cases.addLibcTestCase("math/sin.c", true, .{}); - cases.addLibcTestCase("math/sincos.c", true, .{}); - cases.addLibcTestCase("math/sincosf.c", true, .{}); - cases.addLibcTestCase("math/sincosl.c", true, .{}); - cases.addLibcTestCase("math/sinf.c", true, .{}); - // cases.addLibcTestCase("math/sinh.c", true, .{}); - cases.addLibcTestCase("math/sinhf.c", true, .{}); - // cases.addLibcTestCase("math/sinhl.c", true, .{}); - cases.addLibcTestCase("math/sinl.c", true, .{}); - cases.addLibcTestCase("math/sqrt.c", true, .{}); - cases.addLibcTestCase("math/sqrtf.c", true, .{}); - cases.addLibcTestCase("math/sqrtl.c", true, .{}); - cases.addLibcTestCase("math/tan.c", true, .{}); - cases.addLibcTestCase("math/tanf.c", true, .{}); - cases.addLibcTestCase("math/tanh.c", true, .{}); - cases.addLibcTestCase("math/tanhf.c", true, .{}); - cases.addLibcTestCase("math/tanhl.c", true, .{}); - cases.addLibcTestCase("math/tanl.c", true, .{}); - // cases.addLibcTestCase("math/tgamma.c", true, .{}); - // cases.addLibcTestCase("math/tgammaf.c", true, .{}); - // cases.addLibcTestCase("math/tgammal.c", true, .{}); - cases.addLibcTestCase("math/trunc.c", true, .{}); - cases.addLibcTestCase("math/truncf.c", true, .{}); - cases.addLibcTestCase("math/truncl.c", true, .{}); - // cases.addLibcTestCase("math/y0.c", true, .{}); - // cases.addLibcTestCase("math/y0f.c", true, .{}); - // cases.addLibcTestCase("math/y1.c", true, .{}); - // cases.addLibcTestCase("math/y1f.c", true, .{}); - // cases.addLibcTestCase("math/yn.c", true, .{}); - // cases.addLibcTestCase("math/ynf.c", true, .{}); + cases.addLibcTestCase("math/acos.c", .{}); + cases.addLibcTestCase("math/acosf.c", .{}); + // cases.addLibcTestCase("math/acosh.c", .{}); + cases.addLibcTestCase("math/acoshf.c", .{}); + // cases.addLibcTestCase("math/acoshl.c", .{}); + // cases.addLibcTestCase("math/acosl.c", .{}); + cases.addLibcTestCase("math/asin.c", .{}); + cases.addLibcTestCase("math/asinf.c", .{}); + // cases.addLibcTestCase("math/asinh.c", .{}); + cases.addLibcTestCase("math/asinhf.c", .{}); + // cases.addLibcTestCase("math/asinhl.c", .{}); + cases.addLibcTestCase("math/asinl.c", .{}); + cases.addLibcTestCase("math/atan.c", .{}); + cases.addLibcTestCase("math/atan2.c", .{}); + cases.addLibcTestCase("math/atan2f.c", .{}); + cases.addLibcTestCase("math/atan2l.c", .{}); + cases.addLibcTestCase("math/atanf.c", .{}); + cases.addLibcTestCase("math/atanh.c", .{}); + cases.addLibcTestCase("math/atanhf.c", .{}); + cases.addLibcTestCase("math/atanhl.c", .{}); + cases.addLibcTestCase("math/atanl.c", .{}); + cases.addLibcTestCase("math/cbrt.c", .{}); + cases.addLibcTestCase("math/cbrtf.c", .{}); + cases.addLibcTestCase("math/cbrtl.c", .{}); + cases.addLibcTestCase("math/ceil.c", .{}); + cases.addLibcTestCase("math/ceilf.c", .{}); + cases.addLibcTestCase("math/ceill.c", .{}); + cases.addLibcTestCase("math/copysign.c", .{}); + cases.addLibcTestCase("math/copysignf.c", .{}); + cases.addLibcTestCase("math/copysignl.c", .{}); + cases.addLibcTestCase("math/cos.c", .{}); + cases.addLibcTestCase("math/cosf.c", .{}); + cases.addLibcTestCase("math/cosh.c", .{}); + cases.addLibcTestCase("math/coshf.c", .{}); + cases.addLibcTestCase("math/coshl.c", .{}); + cases.addLibcTestCase("math/cosl.c", .{}); + cases.addLibcTestCase("math/drem.c", .{}); + cases.addLibcTestCase("math/dremf.c", .{}); + cases.addLibcTestCase("math/erf.c", .{}); + cases.addLibcTestCase("math/erfc.c", .{}); + // cases.addLibcTestCase("math/erfcf.c", .{}); + cases.addLibcTestCase("math/erfcl.c", .{}); + cases.addLibcTestCase("math/erff.c", .{}); + cases.addLibcTestCase("math/erfl.c", .{}); + cases.addLibcTestCase("math/exp.c", .{}); + cases.addLibcTestCase("math/exp10.c", .{}); + cases.addLibcTestCase("math/exp10f.c", .{}); + cases.addLibcTestCase("math/exp10l.c", .{}); + cases.addLibcTestCase("math/exp2.c", .{}); + cases.addLibcTestCase("math/exp2f.c", .{}); + cases.addLibcTestCase("math/exp2l.c", .{}); + cases.addLibcTestCase("math/expf.c", .{}); + cases.addLibcTestCase("math/expl.c", .{}); + // cases.addLibcTestCase("math/expm1.c", .{}); + // cases.addLibcTestCase("math/expm1f.c", .{}); + // cases.addLibcTestCase("math/expm1l.c", .{}); + cases.addLibcTestCase("math/fabs.c", .{}); + cases.addLibcTestCase("math/fabsf.c", .{}); + cases.addLibcTestCase("math/fabsl.c", .{}); + cases.addLibcTestCase("math/fdim.c", .{}); + cases.addLibcTestCase("math/fdimf.c", .{}); + cases.addLibcTestCase("math/fdiml.c", .{}); + cases.addLibcTestCase("math/fenv.c", .{}); + cases.addLibcTestCase("math/floor.c", .{}); + cases.addLibcTestCase("math/floorf.c", .{}); + cases.addLibcTestCase("math/floorl.c", .{}); + // cases.addLibcTestCase("math/fma.c", .{}); + // cases.addLibcTestCase("math/fmaf.c", .{}); + // cases.addLibcTestCase("math/fmal.c", .{}); + cases.addLibcTestCase("math/fmax.c", .{}); + cases.addLibcTestCase("math/fmaxf.c", .{}); + cases.addLibcTestCase("math/fmaxl.c", .{}); + cases.addLibcTestCase("math/fmin.c", .{}); + cases.addLibcTestCase("math/fminf.c", .{}); + cases.addLibcTestCase("math/fminl.c", .{}); + cases.addLibcTestCase("math/fmod.c", .{}); + cases.addLibcTestCase("math/fmodf.c", .{}); + cases.addLibcTestCase("math/fmodl.c", .{}); + cases.addLibcTestCase("math/fpclassify.c", .{}); + cases.addLibcTestCase("math/frexp.c", .{}); + cases.addLibcTestCase("math/frexpf.c", .{}); + cases.addLibcTestCase("math/frexpl.c", .{}); + cases.addLibcTestCase("math/hypot.c", .{}); + cases.addLibcTestCase("math/hypotf.c", .{}); + cases.addLibcTestCase("math/hypotl.c", .{}); + // cases.addLibcTestCase("math/ilogb.c", .{}); + // cases.addLibcTestCase("math/ilogbf.c", .{}); + // cases.addLibcTestCase("math/ilogbl.c", .{}); + cases.addLibcTestCase("math/isless.c", .{}); + // cases.addLibcTestCase("math/j0.c", .{}); + cases.addLibcTestCase("math/j0f.c", .{}); + cases.addLibcTestCase("math/j1.c", .{}); + cases.addLibcTestCase("math/j1f.c", .{}); + // cases.addLibcTestCase("math/jn.c", .{}); + // cases.addLibcTestCase("math/jnf.c", .{}); + cases.addLibcTestCase("math/ldexp.c", .{}); + cases.addLibcTestCase("math/ldexpf.c", .{}); + cases.addLibcTestCase("math/ldexpl.c", .{}); + // cases.addLibcTestCase("math/lgamma.c", .{}); + cases.addLibcTestCase("math/lgamma_r.c", .{}); + // cases.addLibcTestCase("math/lgammaf.c", .{}); + // cases.addLibcTestCase("math/lgammaf_r.c", .{}); + // cases.addLibcTestCase("math/lgammal.c", .{}); + cases.addLibcTestCase("math/lgammal_r.c", .{}); + // cases.addLibcTestCase("math/llrint.c", .{}); + // cases.addLibcTestCase("math/llrintf.c", .{}); + // cases.addLibcTestCase("math/llrintl.c", .{}); + // cases.addLibcTestCase("math/llround.c", .{}); + // cases.addLibcTestCase("math/llroundf.c", .{}); + // cases.addLibcTestCase("math/llroundl.c", .{}); + cases.addLibcTestCase("math/log.c", .{}); + cases.addLibcTestCase("math/log10.c", .{}); + cases.addLibcTestCase("math/log10f.c", .{}); + cases.addLibcTestCase("math/log10l.c", .{}); + cases.addLibcTestCase("math/log1p.c", .{}); + cases.addLibcTestCase("math/log1pf.c", .{}); + // cases.addLibcTestCase("math/log1pl.c", .{}); + cases.addLibcTestCase("math/log2.c", .{}); + cases.addLibcTestCase("math/log2f.c", .{}); + cases.addLibcTestCase("math/log2l.c", .{}); + cases.addLibcTestCase("math/logb.c", .{}); + cases.addLibcTestCase("math/logbf.c", .{}); + cases.addLibcTestCase("math/logbl.c", .{}); + cases.addLibcTestCase("math/logf.c", .{}); + cases.addLibcTestCase("math/logl.c", .{}); + cases.addLibcTestCase("math/lrint.c", .{}); + cases.addLibcTestCase("math/lrintf.c", .{}); + cases.addLibcTestCase("math/lrintl.c", .{}); + cases.addLibcTestCase("math/lround.c", .{}); + cases.addLibcTestCase("math/lroundf.c", .{}); + cases.addLibcTestCase("math/lroundl.c", .{}); + cases.addLibcTestCase("math/modf.c", .{}); + cases.addLibcTestCase("math/modff.c", .{}); + cases.addLibcTestCase("math/modfl.c", .{}); + // cases.addLibcTestCase("math/nearbyint.c", .{}); + cases.addLibcTestCase("math/nearbyintf.c", .{}); + // cases.addLibcTestCase("math/nearbyintl.c", .{}); + cases.addLibcTestCase("math/nextafter.c", .{}); + cases.addLibcTestCase("math/nextafterf.c", .{}); + cases.addLibcTestCase("math/nextafterl.c", .{}); + cases.addLibcTestCase("math/nexttoward.c", .{}); + cases.addLibcTestCase("math/nexttowardf.c", .{}); + cases.addLibcTestCase("math/nexttowardl.c", .{}); + // cases.addLibcTestCase("math/pow.c", .{}); + cases.addLibcTestCase("math/pow10.c", .{}); + cases.addLibcTestCase("math/pow10f.c", .{}); + cases.addLibcTestCase("math/pow10l.c", .{}); + // cases.addLibcTestCase("math/powf.c", .{}); + // cases.addLibcTestCase("math/powl.c", .{}); + cases.addLibcTestCase("math/remainder.c", .{}); + cases.addLibcTestCase("math/remainderf.c", .{}); + cases.addLibcTestCase("math/remainderl.c", .{}); + cases.addLibcTestCase("math/remquo.c", .{}); + cases.addLibcTestCase("math/remquof.c", .{}); + cases.addLibcTestCase("math/remquol.c", .{}); + cases.addLibcTestCase("math/rint.c", .{}); + cases.addLibcTestCase("math/rintf.c", .{}); + cases.addLibcTestCase("math/rintl.c", .{}); + cases.addLibcTestCase("math/round.c", .{}); + cases.addLibcTestCase("math/roundf.c", .{}); + cases.addLibcTestCase("math/roundl.c", .{}); + cases.addLibcTestCase("math/scalb.c", .{}); + cases.addLibcTestCase("math/scalbf.c", .{}); + cases.addLibcTestCase("math/scalbln.c", .{}); + cases.addLibcTestCase("math/scalblnf.c", .{}); + cases.addLibcTestCase("math/scalblnl.c", .{}); + cases.addLibcTestCase("math/scalbn.c", .{}); + cases.addLibcTestCase("math/scalbnf.c", .{}); + cases.addLibcTestCase("math/scalbnl.c", .{}); + cases.addLibcTestCase("math/sin.c", .{}); + cases.addLibcTestCase("math/sincos.c", .{}); + cases.addLibcTestCase("math/sincosf.c", .{}); + cases.addLibcTestCase("math/sincosl.c", .{}); + cases.addLibcTestCase("math/sinf.c", .{}); + // cases.addLibcTestCase("math/sinh.c", .{}); + cases.addLibcTestCase("math/sinhf.c", .{}); + // cases.addLibcTestCase("math/sinhl.c", .{}); + cases.addLibcTestCase("math/sinl.c", .{}); + cases.addLibcTestCase("math/sqrt.c", .{}); + cases.addLibcTestCase("math/sqrtf.c", .{}); + cases.addLibcTestCase("math/sqrtl.c", .{}); + cases.addLibcTestCase("math/tan.c", .{}); + cases.addLibcTestCase("math/tanf.c", .{}); + cases.addLibcTestCase("math/tanh.c", .{}); + cases.addLibcTestCase("math/tanhf.c", .{}); + cases.addLibcTestCase("math/tanhl.c", .{}); + cases.addLibcTestCase("math/tanl.c", .{}); + // cases.addLibcTestCase("math/tgamma.c", .{}); + // cases.addLibcTestCase("math/tgammaf.c", .{}); + // cases.addLibcTestCase("math/tgammal.c", .{}); + cases.addLibcTestCase("math/trunc.c", .{}); + cases.addLibcTestCase("math/truncf.c", .{}); + cases.addLibcTestCase("math/truncl.c", .{}); + // cases.addLibcTestCase("math/y0.c", .{}); + // cases.addLibcTestCase("math/y0f.c", .{}); + // cases.addLibcTestCase("math/y1.c", .{}); + // cases.addLibcTestCase("math/y1f.c", .{}); + // cases.addLibcTestCase("math/yn.c", .{}); + // cases.addLibcTestCase("math/ynf.c", .{}); } const std = @import("std"); diff --git a/test/llvm_targets.zig b/test/llvm_targets.zig index 38c5040e1d06ea158046c1db75711de4cf27e2b9..29badbc31122d8fb58ddd87630d6b58d4760ee49 100644 --- a/test/llvm_targets.zig +++ b/test/llvm_targets.zig @@ -290,12 +290,10 @@ const targets = [_]std.Target.Query{ .{ .cpu_arch = .wasm32, .os_tag = .emscripten, .abi = .none }, .{ .cpu_arch = .wasm32, .os_tag = .freestanding, .abi = .none }, - .{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .musl }, .{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .none }, .{ .cpu_arch = .wasm64, .os_tag = .emscripten, .abi = .none }, .{ .cpu_arch = .wasm64, .os_tag = .freestanding, .abi = .none }, - .{ .cpu_arch = .wasm64, .os_tag = .wasi, .abi = .musl }, .{ .cpu_arch = .wasm64, .os_tag = .wasi, .abi = .none }, .{ .cpu_arch = .x86, .os_tag = .freestanding, .abi = .none }, diff --git a/test/src/Libc.zig b/test/src/Libc.zig index 9a87d922acb2675131f70243a20edc6ca34ce1f7..da25b6a54b04607e40293bc9aba922013e9df510 100644 --- a/test/src/Libc.zig +++ b/test/src/Libc.zig @@ -10,7 +10,6 @@ pub const Options = struct { optimize_modes: []const std.builtin.Optimize, test_filters: []const []const u8, test_target_filters: []const []const u8, - skip_wasm: bool, max_rss: u64, }; @@ -18,7 +17,6 @@ const TestCase = struct { name: []const u8, src_file: std.Build.LazyPath, additional_src_file: ?std.Build.LazyPath, - supports_wasi_libc: bool, }; pub const LibcTestCaseOption = struct { @@ -28,7 +26,6 @@ pub const LibcTestCaseOption = struct { pub fn addLibcTestCase( libc: *Libc, path: []const u8, - supports_wasi_libc: bool, options: LibcTestCaseOption, ) void { const graph = libc.b.graph; @@ -39,7 +36,6 @@ pub fn addLibcTestCase( .name = name, .src_file = libc.libc_test_src_path.path(libc.b, path), .additional_src_file = if (options.additional_src_file) |additional_src_file| libc.libc_test_src_path.path(libc.b, additional_src_file) else null, - .supports_wasi_libc = supports_wasi_libc, }) catch @panic("OOM"); } @@ -49,8 +45,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { } else false; if (!want_debug) return; - if (libc.options.skip_wasm and target.query.cpu_arch != null and target.query.cpu_arch.?.isWasm()) return; - if (libc.options.test_target_filters.len > 0) { const triple_txt = target.query.zigTriple(libc.b.allocator) catch @panic("OOM"); for (libc.options.test_target_filters) |filter| { @@ -81,9 +75,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { }); for (libc.test_cases.items) |*test_case| { - if (target.result.isWasiLibC() and !test_case.supports_wasi_libc) - continue; - const annotated_case_name = libc.b.fmt("run libc-test {s}", .{test_case.name}); for (libc.options.test_filters) |test_filter| { if (std.mem.find(u8, annotated_case_name, test_filter)) |_| break; @@ -95,8 +86,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { .link_libc = true, }); mod.addIncludePath(common); - if (target.result.isWasiLibC()) - mod.addCMacro("_WASI_EMULATED_SIGNAL", ""); mod.addCSourceFile(.{ .file = test_case.src_file, .flags = &.{"-fno-builtin"}, diff --git a/test/standalone/posix/getenv.zig b/test/standalone/posix/getenv.zig index 62c348e085b93dfee378b84953096879cbc575cc..aff77f0d937492c6c90a10892b651d374e2e71cc 100644 --- a/test/standalone/posix/getenv.zig +++ b/test/standalone/posix/getenv.zig @@ -5,7 +5,7 @@ const builtin = @import("builtin"); pub fn main(init: std.process.Init.Minimal) !void { if (builtin.target.os.tag == .windows) return; - if (builtin.target.os.tag == .wasi and !builtin.link_libc) return; + if (builtin.target.os.tag == .wasi) return; const environ = init.environ; diff --git a/test/tests.zig b/test/tests.zig index 89a95c9f32aa2b15bdc11f0f581d3395daebc8e6..7801ff25afb1823f2be8f20d37fdcad22ba75f16 100644 --- a/test/tests.zig +++ b/test/tests.zig @@ -1616,14 +1616,6 @@ const module_test_targets = blk: { .abi = .none, }, }, - .{ - .target = .{ - .cpu_arch = .wasm32, - .os_tag = .wasi, - .abi = .musl, - }, - .link_libc = true, - }, // Windows Targets @@ -2050,25 +2042,6 @@ const c_abi_targets = blk: { }, }, - // WASI Targets - - .{ - .target = .{ - .cpu_arch = .wasm32, - .os_tag = .wasi, - .abi = .musl, - }, - }, - .{ - .target = .{ - .cpu_arch = .wasm32, - .os_tag = .wasi, - .abi = .musl, - }, - .use_llvm = false, - .use_lld = false, - }, - // Windows Targets .{ @@ -3633,11 +3606,6 @@ const libc_test_nsz_targets: []const std.Target.Query = &.{ .os_tag = .linux, .abi = .musl, }, - .{ - .cpu_arch = .wasm32, - .os_tag = .wasi, - .abi = .musl, - }, .{ .cpu_arch = .x86, .os_tag = .linux,