| author | |
| committer | |
| log | 5e754304de220c24dc63975970b672c928bab998 |
| tree | 4cc9ebe37ea6bf2c6f9f0451d4dba5f4f1bac6a2 |
| parent | 56023ff8fe2c110bb408daae809a882095d9bad9 |
closes https://github.com/ziglang/zig/issues/9342
closes https://github.com/ziglang/zig/issues/15005
closes https://github.com/ziglang/zig/issues/20747
closes https://github.com/ziglang/zig/issues/22570
closes https://codeberg.org/ziglang/zig/issues/30977520 files changed, 475 insertions(+), 42155 deletions(-)
CMakeLists.txt-1| ... | @@ -457,7 +457,6 @@ set(ZIG_STAGE2_SOURCES | ... | @@ -457,7 +457,6 @@ set(ZIG_STAGE2_SOURCES |
| 457 | src/register_manager.zig | 457 | src/register_manager.zig |
| 458 | src/target.zig | 458 | src/target.zig |
| 459 | src/tracy.zig | 459 | src/tracy.zig |
| 460 | src/libs/wasi_libc.zig | ||
| 461 | ) | 460 | ) |
| 462 | 461 | ||
| 463 | if(MSVC) | 462 | if(MSVC) |
build.zig-1| ... | @@ -775,7 +775,6 @@ pub fn build(b: *std.Build) !void { | ... | @@ -775,7 +775,6 @@ pub fn build(b: *std.Build) !void { |
| 775 | .optimize_modes = optimize_modes, | 775 | .optimize_modes = optimize_modes, |
| 776 | .test_filters = test_filters, | 776 | .test_filters = test_filters, |
| 777 | .test_target_filters = test_target_filters, | 777 | .test_target_filters = test_target_filters, |
| 778 | .skip_wasm = skip_wasm, | ||
| 779 | .max_rss = 4_300_000_000, | 778 | .max_rss = 4_300_000_000, |
| 780 | })) |test_libc_nsz_step| test_step.dependOn(test_libc_nsz_step); | 779 | })) |test_libc_nsz_step| test_step.dependOn(test_libc_nsz_step); |
| 781 | 780 |
lib/c/ctype.zig+2-2| ... | @@ -3,8 +3,8 @@ const std = @import("std"); | ... | @@ -3,8 +3,8 @@ const std = @import("std"); |
| 3 | const symbol = @import("../c.zig").symbol; | 3 | const symbol = @import("../c.zig").symbol; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 6 | if (builtin.target.isMuslLibC()) { |
| 7 | // Functions specific to musl and wasi-libc. | 7 | // Functions specific to musl. |
| 8 | symbol(&isalnum, "isalnum"); | 8 | symbol(&isalnum, "isalnum"); |
| 9 | symbol(&isalpha, "isalpha"); | 9 | symbol(&isalpha, "isalpha"); |
| 10 | symbol(&isblank, "isblank"); | 10 | symbol(&isblank, "isblank"); |
lib/c/inttypes.zig+2-2| ... | @@ -7,8 +7,8 @@ const imaxdiv_t = std.c.imaxdiv_t; | ... | @@ -7,8 +7,8 @@ const imaxdiv_t = std.c.imaxdiv_t; |
| 7 | const symbol = @import("../c.zig").symbol; | 7 | const symbol = @import("../c.zig").symbol; |
| 8 | 8 | ||
| 9 | comptime { | 9 | comptime { |
| 10 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 10 | if (builtin.target.isMuslLibC()) { |
| 11 | // Functions specific to musl and wasi-libc. | 11 | // Functions specific to musl. |
| 12 | symbol(&imaxabs, "imaxabs"); | 12 | symbol(&imaxabs, "imaxabs"); |
| 13 | symbol(&imaxdiv, "imaxdiv"); | 13 | symbol(&imaxdiv, "imaxdiv"); |
| 14 | } | 14 | } |
lib/c/math.zig+4-4| ... | @@ -31,7 +31,7 @@ comptime { | ... | @@ -31,7 +31,7 @@ comptime { |
| 31 | symbol(&math.snan(c_longdouble), "__SNANL"); | 31 | symbol(&math.snan(c_longdouble), "__SNANL"); |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | if (builtin.target.isMinGW() or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 34 | if (builtin.target.isMinGW() or builtin.target.isMuslLibC()) { |
| 35 | symbol(&frexpf, "frexpf"); | 35 | symbol(&frexpf, "frexpf"); |
| 36 | symbol(&frexpl, "frexpl"); | 36 | symbol(&frexpl, "frexpl"); |
| 37 | symbol(&hypotf, "hypotf"); | 37 | symbol(&hypotf, "hypotf"); |
| ... | @@ -42,14 +42,14 @@ comptime { | ... | @@ -42,14 +42,14 @@ comptime { |
| 42 | symbol(&rintl, "rintl"); | 42 | symbol(&rintl, "rintl"); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 45 | if ((builtin.target.isMinGW() and @sizeOf(f64) != @sizeOf(c_longdouble)) or builtin.target.isMuslLibC()) { |
| 46 | symbol(&atanl, "atanl"); | 46 | symbol(&atanl, "atanl"); |
| 47 | symbol(&copysignl, "copysignl"); | 47 | symbol(&copysignl, "copysignl"); |
| 48 | symbol(&fdiml, "fdiml"); | 48 | symbol(&fdiml, "fdiml"); |
| 49 | symbol(&nanl, "nanl"); | 49 | symbol(&nanl, "nanl"); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | if ((builtin.target.isMinGW() and builtin.cpu.arch == .x86) or builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 52 | if ((builtin.target.isMinGW() and builtin.cpu.arch == .x86) or builtin.target.isMuslLibC()) { |
| 53 | symbol(&acosf, "acosf"); | 53 | symbol(&acosf, "acosf"); |
| 54 | symbol(&atanf, "atanf"); | 54 | symbol(&atanf, "atanf"); |
| 55 | symbol(&coshf, "coshf"); | 55 | symbol(&coshf, "coshf"); |
| ... | @@ -57,7 +57,7 @@ comptime { | ... | @@ -57,7 +57,7 @@ comptime { |
| 57 | symbol(&tanhf, "tanhf"); | 57 | symbol(&tanhf, "tanhf"); |
| 58 | } | 58 | } |
| 59 | 59 | ||
| 60 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 60 | if (builtin.target.isMuslLibC()) { |
| 61 | symbol(&acos, "acos"); | 61 | symbol(&acos, "acos"); |
| 62 | symbol(&acoshf, "acoshf"); | 62 | symbol(&acoshf, "acoshf"); |
| 63 | symbol(&asin, "asin"); | 63 | symbol(&asin, "asin"); |
lib/c/pthread.zig+1-1| ... | @@ -6,7 +6,7 @@ const c = std.c; | ... | @@ -6,7 +6,7 @@ const c = std.c; |
| 6 | const symbol = @import("../c.zig").symbol; | 6 | const symbol = @import("../c.zig").symbol; |
| 7 | 7 | ||
| 8 | comptime { | 8 | comptime { |
| 9 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC() or builtin.target.isMinGW()) { | 9 | if (builtin.target.isMuslLibC() or builtin.target.isMinGW()) { |
| 10 | symbol(&pthread_spin_init, "pthread_spin_init"); | 10 | symbol(&pthread_spin_init, "pthread_spin_init"); |
| 11 | symbol(&pthread_spin_destroy, "pthread_spin_destroy"); | 11 | symbol(&pthread_spin_destroy, "pthread_spin_destroy"); |
| 12 | symbol(&pthread_spin_trylock, "pthread_spin_trylock"); | 12 | symbol(&pthread_spin_trylock, "pthread_spin_trylock"); |
lib/c/search.zig+1-1| ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); | ... | @@ -3,7 +3,7 @@ const builtin = @import("builtin"); |
| 3 | const symbol = @import("../c.zig").symbol; | 3 | const symbol = @import("../c.zig").symbol; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 6 | if (builtin.target.isMuslLibC()) { |
| 7 | symbol(&insque, "insque"); | 7 | symbol(&insque, "insque"); |
| 8 | symbol(&remque, "remque"); | 8 | symbol(&remque, "remque"); |
| 9 | } | 9 | } |
lib/c/stdlib.zig+2-2| ... | @@ -12,8 +12,8 @@ comptime { | ... | @@ -12,8 +12,8 @@ comptime { |
| 12 | _ = @import("stdlib/rand.zig"); | 12 | _ = @import("stdlib/rand.zig"); |
| 13 | _ = @import("stdlib/drand48.zig"); | 13 | _ = @import("stdlib/drand48.zig"); |
| 14 | 14 | ||
| 15 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 15 | if (builtin.target.isMuslLibC()) { |
| 16 | // Functions specific to musl and wasi-libc. | 16 | // Functions specific to musl. |
| 17 | symbol(&abs, "abs"); | 17 | symbol(&abs, "abs"); |
| 18 | symbol(&labs, "labs"); | 18 | symbol(&labs, "labs"); |
| 19 | symbol(&llabs, "llabs"); | 19 | symbol(&llabs, "llabs"); |
lib/c/stdlib/drand48.zig+1-1| ... | @@ -8,7 +8,7 @@ const Lcg = std.Random.lcg.Wrapping(u48); | ... | @@ -8,7 +8,7 @@ const Lcg = std.Random.lcg.Wrapping(u48); |
| 8 | const symbol = @import("../../c.zig").symbol; | 8 | const symbol = @import("../../c.zig").symbol; |
| 9 | 9 | ||
| 10 | comptime { | 10 | comptime { |
| 11 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 11 | if (builtin.target.isMuslLibC()) { |
| 12 | symbol(&erand48, "erand48"); | 12 | symbol(&erand48, "erand48"); |
| 13 | symbol(&jrand48, "jrand48"); | 13 | symbol(&jrand48, "jrand48"); |
| 14 | symbol(&nrand48, "nrand48"); | 14 | symbol(&nrand48, "nrand48"); |
lib/c/stdlib/rand.zig+1-1| ... | @@ -3,7 +3,7 @@ const std = @import("std"); | ... | @@ -3,7 +3,7 @@ const std = @import("std"); |
| 3 | const symbol = @import("../../c.zig").symbol; | 3 | const symbol = @import("../../c.zig").symbol; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 6 | if (builtin.target.isMuslLibC()) { |
| 7 | symbol(&rand, "rand"); | 7 | symbol(&rand, "rand"); |
| 8 | symbol(&srand, "srand"); | 8 | symbol(&srand, "srand"); |
| 9 | symbol(&rand_r, "rand_r"); | 9 | symbol(&rand_r, "rand_r"); |
lib/c/string.zig+2-2| ... | @@ -6,7 +6,7 @@ const c = std.c; | ... | @@ -6,7 +6,7 @@ const c = std.c; |
| 6 | comptime { | 6 | comptime { |
| 7 | symbol(&strndup, "strndup"); | 7 | symbol(&strndup, "strndup"); |
| 8 | 8 | ||
| 9 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 9 | if (builtin.target.isMuslLibC()) { |
| 10 | // memcpy implemented in compiler_rt | 10 | // memcpy implemented in compiler_rt |
| 11 | // memmove implemented in compiler_rt | 11 | // memmove implemented in compiler_rt |
| 12 | // memset implemented in compiler_rt | 12 | // memset implemented in compiler_rt |
| ... | @@ -53,7 +53,7 @@ comptime { | ... | @@ -53,7 +53,7 @@ comptime { |
| 53 | symbol(&__strcoll_l, "strcoll_l"); | 53 | symbol(&__strcoll_l, "strcoll_l"); |
| 54 | symbol(&__strxfrm_l, "strxfrm_l"); | 54 | symbol(&__strxfrm_l, "strxfrm_l"); |
| 55 | 55 | ||
| 56 | // These symbols are not in the public ABI of musl/wasi. However they depend on these exports internally. | 56 | // These symbols are not in the public ABI of musl. However it depends on these exports internally. |
| 57 | symbol(&stpcpy, "__stpcpy"); | 57 | symbol(&stpcpy, "__stpcpy"); |
| 58 | symbol(&stpncpy, "__stpncpy"); | 58 | symbol(&stpncpy, "__stpncpy"); |
| 59 | symbol(&strchrnul, "__strchrnul"); | 59 | symbol(&strchrnul, "__strchrnul"); |
lib/c/strings.zig+1-1| ... | @@ -3,7 +3,7 @@ const std = @import("std"); | ... | @@ -3,7 +3,7 @@ const std = @import("std"); |
| 3 | const symbol = @import("../c.zig").symbol; | 3 | const symbol = @import("../c.zig").symbol; |
| 4 | 4 | ||
| 5 | comptime { | 5 | comptime { |
| 6 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 6 | if (builtin.target.isMuslLibC()) { |
| 7 | // bcmp is implemented in compiler_rt | 7 | // bcmp is implemented in compiler_rt |
| 8 | symbol(&bcopy, "bcopy"); | 8 | symbol(&bcopy, "bcopy"); |
| 9 | symbol(&bzero, "bzero"); | 9 | symbol(&bzero, "bzero"); |
lib/c/sys/utsname.zig-19| ... | @@ -9,27 +9,8 @@ comptime { | ... | @@ -9,27 +9,8 @@ comptime { |
| 9 | if (builtin.target.isMuslLibC()) { | 9 | if (builtin.target.isMuslLibC()) { |
| 10 | symbol(&unameLinux, "uname"); | 10 | symbol(&unameLinux, "uname"); |
| 11 | } | 11 | } |
| 12 | |||
| 13 | if (builtin.target.isWasiLibC()) { | ||
| 14 | symbol(&unameWasi, "uname"); | ||
| 15 | } | ||
| 16 | } | 12 | } |
| 17 | 13 | ||
| 18 | fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int { | 14 | fn unameLinux(uts: *std.os.linux.utsname) callconv(.c) c_int { |
| 19 | return errno(std.os.linux.uname(uts)); | 15 | return errno(std.os.linux.uname(uts)); |
| 20 | } | 16 | } |
| 21 | |||
| 22 | fn unameWasi(uts: *std.c.utsname) callconv(.c) c_int { | ||
| 23 | // note the @bitCast's for NUL termination! | ||
| 24 | uts.sysname[0..5].* = @bitCast("wasi".*); | ||
| 25 | uts.nodename[0..7].* = @bitCast("(none)".*); | ||
| 26 | uts.release[0..6].* = @bitCast("0.0.0".*); | ||
| 27 | uts.version[0..6].* = @bitCast("0.0.0".*); | ||
| 28 | uts.machine[0..7].* = @bitCast(switch (builtin.target.cpu.arch) { | ||
| 29 | .wasm32 => "wasm32", | ||
| 30 | .wasm64 => "wasm64", | ||
| 31 | else => comptime unreachable, | ||
| 32 | }.*); | ||
| 33 | uts.domainname[0..7].* = @bitCast("(none)".*); | ||
| 34 | return 0; | ||
| 35 | } |
lib/c/unistd.zig+1-14| ... | @@ -51,12 +51,9 @@ comptime { | ... | @@ -51,12 +51,9 @@ comptime { |
| 51 | 51 | ||
| 52 | symbol(&execveLinux, "execve"); | 52 | symbol(&execveLinux, "execve"); |
| 53 | } | 53 | } |
| 54 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 54 | if (builtin.target.isMuslLibC()) { |
| 55 | symbol(&swab, "swab"); | 55 | symbol(&swab, "swab"); |
| 56 | } | 56 | } |
| 57 | if (builtin.target.isWasiLibC()) { | ||
| 58 | symbol(&closeWasi, "close"); | ||
| 59 | } | ||
| 60 | } | 57 | } |
| 61 | 58 | ||
| 62 | fn _exit(exit_code: c_int) callconv(.c) noreturn { | 59 | fn _exit(exit_code: c_int) callconv(.c) noreturn { |
| ... | @@ -248,13 +245,3 @@ fn close(fd: std.c.fd_t) callconv(.c) c_int { | ... | @@ -248,13 +245,3 @@ fn close(fd: std.c.fd_t) callconv(.c) c_int { |
| 248 | fn posix_close(fd: std.c.fd_t, _: c_int) callconv(.c) c_int { | 245 | fn posix_close(fd: std.c.fd_t, _: c_int) callconv(.c) c_int { |
| 249 | return close(fd); | 246 | return close(fd); |
| 250 | } | 247 | } |
| 251 | |||
| 252 | fn closeWasi(fd: std.c.fd_t) callconv(.c) c_int { | ||
| 253 | switch (std.os.wasi.fd_close(fd)) { | ||
| 254 | .SUCCESS => return 0, | ||
| 255 | else => |e| { | ||
| 256 | std.c._errno().* = @backingInt(e); | ||
| 257 | return -1; | ||
| 258 | }, | ||
| 259 | } | ||
| 260 | } |
lib/c/wchar.zig+1-1| ... | @@ -8,7 +8,7 @@ const symbol = @import("../c.zig").symbol; | ... | @@ -8,7 +8,7 @@ const symbol = @import("../c.zig").symbol; |
| 8 | const c = std.c; | 8 | const c = std.c; |
| 9 | 9 | ||
| 10 | comptime { | 10 | comptime { |
| 11 | if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) { | 11 | if (builtin.target.isMuslLibC()) { |
| 12 | symbol(&wmemchr, "wmemchr"); | 12 | symbol(&wmemchr, "wmemchr"); |
| 13 | symbol(&wmemcmp, "wmemcmp"); | 13 | symbol(&wmemcmp, "wmemcmp"); |
| 14 | symbol(&wmemcpy, "wmemcpy"); | 14 | symbol(&wmemcpy, "wmemcpy"); |
lib/compiler_rt.zig-1| ... | @@ -267,7 +267,6 @@ pub const want_float_exceptions = !builtin.cpu.arch.isWasm(); | ... | @@ -267,7 +267,6 @@ pub const want_float_exceptions = !builtin.cpu.arch.isWasm(); |
| 267 | /// arm-linux-musleabihf => true | 267 | /// arm-linux-musleabihf => true |
| 268 | /// arm-linux-gnueabihf => true | 268 | /// arm-linux-gnueabihf => true |
| 269 | /// arm-linux-eabihf => false | 269 | /// arm-linux-eabihf => false |
| 270 | /// wasm32-wasi-musl => false | ||
| 271 | /// wasm32-freestanding-none => false | 270 | /// wasm32-freestanding-none => false |
| 272 | /// x86_64-windows-gnu => true | 271 | /// x86_64-windows-gnu => true |
| 273 | /// x86_64-windows-msvc => true | 272 | /// x86_64-windows-msvc => true |
lib/libc/include/wasm-wasi-musl/__errno.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___errno_h | ||
| 2 | #define __wasilibc___errno_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | extern _Thread_local int errno; | ||
| 9 | |||
| 10 | #define errno errno | ||
| 11 | |||
| 12 | #ifdef __cplusplus | ||
| 13 | } | ||
| 14 | #endif | ||
| 15 | #endif | ||
lib/libc/include/wasm-wasi-musl/__errno_values.h deleted-86| ... | @@ -1,86 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___errno_values_h | ||
| 2 | #define __wasilibc___errno_values_h | ||
| 3 | |||
| 4 | #include <wasi/api.h> | ||
| 5 | |||
| 6 | #define E2BIG __WASI_ERRNO_2BIG | ||
| 7 | #define EACCES __WASI_ERRNO_ACCES | ||
| 8 | #define EADDRINUSE __WASI_ERRNO_ADDRINUSE | ||
| 9 | #define EADDRNOTAVAIL __WASI_ERRNO_ADDRNOTAVAIL | ||
| 10 | #define EAFNOSUPPORT __WASI_ERRNO_AFNOSUPPORT | ||
| 11 | #define EAGAIN __WASI_ERRNO_AGAIN | ||
| 12 | #define EALREADY __WASI_ERRNO_ALREADY | ||
| 13 | #define EBADF __WASI_ERRNO_BADF | ||
| 14 | #define EBADMSG __WASI_ERRNO_BADMSG | ||
| 15 | #define EBUSY __WASI_ERRNO_BUSY | ||
| 16 | #define ECANCELED __WASI_ERRNO_CANCELED | ||
| 17 | #define ECHILD __WASI_ERRNO_CHILD | ||
| 18 | #define ECONNABORTED __WASI_ERRNO_CONNABORTED | ||
| 19 | #define ECONNREFUSED __WASI_ERRNO_CONNREFUSED | ||
| 20 | #define ECONNRESET __WASI_ERRNO_CONNRESET | ||
| 21 | #define EDEADLK __WASI_ERRNO_DEADLK | ||
| 22 | #define EDESTADDRREQ __WASI_ERRNO_DESTADDRREQ | ||
| 23 | #define EDOM __WASI_ERRNO_DOM | ||
| 24 | #define EDQUOT __WASI_ERRNO_DQUOT | ||
| 25 | #define EEXIST __WASI_ERRNO_EXIST | ||
| 26 | #define EFAULT __WASI_ERRNO_FAULT | ||
| 27 | #define EFBIG __WASI_ERRNO_FBIG | ||
| 28 | #define EHOSTUNREACH __WASI_ERRNO_HOSTUNREACH | ||
| 29 | #define EIDRM __WASI_ERRNO_IDRM | ||
| 30 | #define EILSEQ __WASI_ERRNO_ILSEQ | ||
| 31 | #define EINPROGRESS __WASI_ERRNO_INPROGRESS | ||
| 32 | #define EINTR __WASI_ERRNO_INTR | ||
| 33 | #define EINVAL __WASI_ERRNO_INVAL | ||
| 34 | #define EIO __WASI_ERRNO_IO | ||
| 35 | #define EISCONN __WASI_ERRNO_ISCONN | ||
| 36 | #define EISDIR __WASI_ERRNO_ISDIR | ||
| 37 | #define ELOOP __WASI_ERRNO_LOOP | ||
| 38 | #define EMFILE __WASI_ERRNO_MFILE | ||
| 39 | #define EMLINK __WASI_ERRNO_MLINK | ||
| 40 | #define EMSGSIZE __WASI_ERRNO_MSGSIZE | ||
| 41 | #define EMULTIHOP __WASI_ERRNO_MULTIHOP | ||
| 42 | #define ENAMETOOLONG __WASI_ERRNO_NAMETOOLONG | ||
| 43 | #define ENETDOWN __WASI_ERRNO_NETDOWN | ||
| 44 | #define ENETRESET __WASI_ERRNO_NETRESET | ||
| 45 | #define ENETUNREACH __WASI_ERRNO_NETUNREACH | ||
| 46 | #define ENFILE __WASI_ERRNO_NFILE | ||
| 47 | #define ENOBUFS __WASI_ERRNO_NOBUFS | ||
| 48 | #define ENODEV __WASI_ERRNO_NODEV | ||
| 49 | #define ENOENT __WASI_ERRNO_NOENT | ||
| 50 | #define ENOEXEC __WASI_ERRNO_NOEXEC | ||
| 51 | #define ENOLCK __WASI_ERRNO_NOLCK | ||
| 52 | #define ENOLINK __WASI_ERRNO_NOLINK | ||
| 53 | #define ENOMEM __WASI_ERRNO_NOMEM | ||
| 54 | #define ENOMSG __WASI_ERRNO_NOMSG | ||
| 55 | #define ENOPROTOOPT __WASI_ERRNO_NOPROTOOPT | ||
| 56 | #define ENOSPC __WASI_ERRNO_NOSPC | ||
| 57 | #define ENOSYS __WASI_ERRNO_NOSYS | ||
| 58 | #define ENOTCONN __WASI_ERRNO_NOTCONN | ||
| 59 | #define ENOTDIR __WASI_ERRNO_NOTDIR | ||
| 60 | #define ENOTEMPTY __WASI_ERRNO_NOTEMPTY | ||
| 61 | #define ENOTRECOVERABLE __WASI_ERRNO_NOTRECOVERABLE | ||
| 62 | #define ENOTSOCK __WASI_ERRNO_NOTSOCK | ||
| 63 | #define ENOTSUP __WASI_ERRNO_NOTSUP | ||
| 64 | #define ENOTTY __WASI_ERRNO_NOTTY | ||
| 65 | #define ENXIO __WASI_ERRNO_NXIO | ||
| 66 | #define EOVERFLOW __WASI_ERRNO_OVERFLOW | ||
| 67 | #define EOWNERDEAD __WASI_ERRNO_OWNERDEAD | ||
| 68 | #define EPERM __WASI_ERRNO_PERM | ||
| 69 | #define EPIPE __WASI_ERRNO_PIPE | ||
| 70 | #define EPROTO __WASI_ERRNO_PROTO | ||
| 71 | #define EPROTONOSUPPORT __WASI_ERRNO_PROTONOSUPPORT | ||
| 72 | #define EPROTOTYPE __WASI_ERRNO_PROTOTYPE | ||
| 73 | #define ERANGE __WASI_ERRNO_RANGE | ||
| 74 | #define EROFS __WASI_ERRNO_ROFS | ||
| 75 | #define ESPIPE __WASI_ERRNO_SPIPE | ||
| 76 | #define ESRCH __WASI_ERRNO_SRCH | ||
| 77 | #define ESTALE __WASI_ERRNO_STALE | ||
| 78 | #define ETIMEDOUT __WASI_ERRNO_TIMEDOUT | ||
| 79 | #define ETXTBSY __WASI_ERRNO_TXTBSY | ||
| 80 | #define EXDEV __WASI_ERRNO_XDEV | ||
| 81 | #define ENOTCAPABLE __WASI_ERRNO_NOTCAPABLE | ||
| 82 | |||
| 83 | #define EOPNOTSUPP ENOTSUP | ||
| 84 | #define EWOULDBLOCK EAGAIN | ||
| 85 | |||
| 86 | #endif | ||
lib/libc/include/wasm-wasi-musl/__fd_set.h deleted-76| ... | @@ -1,76 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___fd_set_h | ||
| 2 | #define __wasilibc___fd_set_h | ||
| 3 | |||
| 4 | #include <__typedef_fd_set.h> | ||
| 5 | |||
| 6 | #ifdef __cplusplus | ||
| 7 | extern "C" { | ||
| 8 | #endif | ||
| 9 | |||
| 10 | static __inline void FD_CLR(int __fd, fd_set *__set) { | ||
| 11 | size_t __n = __set->__nfds; | ||
| 12 | for (int *__p = __set->__fds, *__e = __p + __n; | ||
| 13 | __p < __e; ++__p) | ||
| 14 | { | ||
| 15 | if (*__p == __fd) { | ||
| 16 | *__p = __e[-1]; | ||
| 17 | __set->__nfds = __n - 1; | ||
| 18 | return; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | static __inline | ||
| 24 | #ifdef __cplusplus | ||
| 25 | bool | ||
| 26 | #else | ||
| 27 | _Bool | ||
| 28 | #endif | ||
| 29 | FD_ISSET(int __fd, const fd_set *__set) | ||
| 30 | { | ||
| 31 | size_t __n = __set->__nfds; | ||
| 32 | for (const int *__p = __set->__fds, *__e = __p + __n; | ||
| 33 | __p < __e; ++__p) | ||
| 34 | { | ||
| 35 | if (*__p == __fd) { | ||
| 36 | return 1; | ||
| 37 | } | ||
| 38 | } | ||
| 39 | return 0; | ||
| 40 | } | ||
| 41 | |||
| 42 | static __inline void FD_SET(int __fd, fd_set *__set) { | ||
| 43 | size_t __n = __set->__nfds; | ||
| 44 | for (const int *__p = __set->__fds, *__e = __p + __n; | ||
| 45 | __p < __e; ++__p) | ||
| 46 | { | ||
| 47 | if (*__p == __fd) { | ||
| 48 | return; | ||
| 49 | } | ||
| 50 | } | ||
| 51 | __set->__nfds = __n + 1; | ||
| 52 | __set->__fds[__n] = __fd; | ||
| 53 | } | ||
| 54 | |||
| 55 | static __inline void FD_ZERO(fd_set *__set) { | ||
| 56 | __set->__nfds = 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | static __inline void FD_COPY(const fd_set *__restrict __from, | ||
| 60 | fd_set *__restrict __to) { | ||
| 61 | size_t __n = __from->__nfds; | ||
| 62 | __to->__nfds = __n; | ||
| 63 | __builtin_memcpy(__to->__fds, __from->__fds, __n * sizeof(int)); | ||
| 64 | } | ||
| 65 | |||
| 66 | #define FD_CLR(fd, set) (FD_CLR((fd), (set))) | ||
| 67 | #define FD_ISSET(fd, set) (FD_ISSET((fd), (set))) | ||
| 68 | #define FD_SET(fd, set) (FD_SET((fd), (set))) | ||
| 69 | #define FD_ZERO(set) (FD_ZERO((set))) | ||
| 70 | #define FD_COPY(from, to) (FD_COPY((from), (to))) | ||
| 71 | |||
| 72 | #ifdef __cplusplus | ||
| 73 | } | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #endif | ||
lib/libc/include/wasm-wasi-musl/__function___isatty.h deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___function___isatty_h | ||
| 2 | #define __wasilibc___function___isatty_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | int __isatty(int fd); | ||
| 9 | |||
| 10 | #ifdef __cplusplus | ||
| 11 | } | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/__functions_malloc.h deleted-26| ... | @@ -1,26 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___functions_malloc_h | ||
| 2 | #define __wasilibc___functions_malloc_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #define __need_wchar_t | ||
| 6 | #define __need_NULL | ||
| 7 | #include <stddef.h> | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | void *malloc(size_t __size) __attribute__((__malloc__, __warn_unused_result__)); | ||
| 14 | void free(void *__ptr); | ||
| 15 | void *calloc(size_t __nmemb, size_t __size) __attribute__((__malloc__, __warn_unused_result__)); | ||
| 16 | void *realloc(void *__ptr, size_t __size) __attribute__((__warn_unused_result__)); | ||
| 17 | |||
| 18 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 19 | void *reallocarray(void *__ptr, size_t __nmemb, size_t __size) __attribute__((__warn_unused_result__)); | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef __cplusplus | ||
| 23 | } | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #endif | ||
lib/libc/include/wasm-wasi-musl/__functions_memcpy.h deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___functions_memcpy_h | ||
| 2 | #define __wasilibc___functions_memcpy_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #define __need_NULL | ||
| 6 | #include <stddef.h> | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | void *memcpy(void *__restrict__ __dst, const void *__restrict__ __src, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2))); | ||
| 13 | void *memmove(void *__dst, const void *__src, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1, 2))); | ||
| 14 | void *memset(void *__dst, int __c, size_t __n) __attribute__((__nothrow__, __leaf__, __nonnull__(1))); | ||
| 15 | |||
| 16 | #ifdef __cplusplus | ||
| 17 | } | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_dirent.h deleted-52| ... | @@ -1,52 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_dirent_h | ||
| 2 | #define __wasilibc___header_dirent_h | ||
| 3 | |||
| 4 | #include <wasi/api.h> | ||
| 5 | |||
| 6 | #define DT_BLK __WASI_FILETYPE_BLOCK_DEVICE | ||
| 7 | #define DT_CHR __WASI_FILETYPE_CHARACTER_DEVICE | ||
| 8 | #define DT_DIR __WASI_FILETYPE_DIRECTORY | ||
| 9 | #define DT_FIFO __WASI_FILETYPE_SOCKET_STREAM | ||
| 10 | #define DT_LNK __WASI_FILETYPE_SYMBOLIC_LINK | ||
| 11 | #define DT_REG __WASI_FILETYPE_REGULAR_FILE | ||
| 12 | #define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN | ||
| 13 | |||
| 14 | // DT_SOCK is not supported in WASI Preview 1 (but will be in Preview 2). We | ||
| 15 | // define it regardless so that libc++'s `<filesystem>` implementation builds. | ||
| 16 | // The exact value is mostly arbitrary, but chosen so it doesn't conflict with | ||
| 17 | // any of the existing `__WASI_FILETYPE_*` flags. We do not expect any new | ||
| 18 | // flags to be added to WASI Preview 1, so that should be sufficient. | ||
| 19 | #define DT_SOCK 20 | ||
| 20 | |||
| 21 | #define IFTODT(x) (__wasilibc_iftodt(x)) | ||
| 22 | #define DTTOIF(x) (__wasilibc_dttoif(x)) | ||
| 23 | |||
| 24 | #include <__struct_dirent.h> | ||
| 25 | #include <__typedef_DIR.h> | ||
| 26 | |||
| 27 | #ifdef __cplusplus | ||
| 28 | extern "C" { | ||
| 29 | #endif | ||
| 30 | |||
| 31 | int __wasilibc_iftodt(int x); | ||
| 32 | int __wasilibc_dttoif(int x); | ||
| 33 | |||
| 34 | int closedir(DIR *); | ||
| 35 | DIR *opendir(const char *); | ||
| 36 | DIR *fdopendir(int); | ||
| 37 | int fdclosedir(DIR *); | ||
| 38 | struct dirent *readdir(DIR *); | ||
| 39 | void rewinddir(DIR *); | ||
| 40 | void seekdir(DIR *, long); | ||
| 41 | long telldir(DIR *); | ||
| 42 | DIR *opendirat(int, const char *); | ||
| 43 | void rewinddir(DIR *); | ||
| 44 | int scandirat(int, const char *, struct dirent ***, | ||
| 45 | int (*)(const struct dirent *), | ||
| 46 | int (*)(const struct dirent **, const struct dirent **)); | ||
| 47 | |||
| 48 | #ifdef __cplusplus | ||
| 49 | } | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_fcntl.h deleted-61| ... | @@ -1,61 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_fcntl_h | ||
| 2 | #define __wasilibc___header_fcntl_h | ||
| 3 | |||
| 4 | #include <wasi/api.h> | ||
| 5 | #include <__seek.h> | ||
| 6 | #include <__mode_t.h> | ||
| 7 | |||
| 8 | #define O_APPEND __WASI_FDFLAGS_APPEND | ||
| 9 | #define O_DSYNC __WASI_FDFLAGS_DSYNC | ||
| 10 | #define O_NONBLOCK __WASI_FDFLAGS_NONBLOCK | ||
| 11 | #define O_RSYNC __WASI_FDFLAGS_RSYNC | ||
| 12 | #define O_SYNC __WASI_FDFLAGS_SYNC | ||
| 13 | #define O_CREAT (__WASI_OFLAGS_CREAT << 12) | ||
| 14 | #define O_DIRECTORY (__WASI_OFLAGS_DIRECTORY << 12) | ||
| 15 | #define O_EXCL (__WASI_OFLAGS_EXCL << 12) | ||
| 16 | #define O_TRUNC (__WASI_OFLAGS_TRUNC << 12) | ||
| 17 | |||
| 18 | #define O_NOFOLLOW (0x01000000) | ||
| 19 | #define O_EXEC (0x02000000) | ||
| 20 | #define O_RDONLY (0x04000000) | ||
| 21 | #define O_SEARCH (0x08000000) | ||
| 22 | #define O_WRONLY (0x10000000) | ||
| 23 | |||
| 24 | /* | ||
| 25 | * O_CLOEXEC is defined to be zero, as WASI has no exec-style functions. | ||
| 26 | */ | ||
| 27 | #define O_CLOEXEC (0) | ||
| 28 | |||
| 29 | /* | ||
| 30 | * O_TTY_INIT is defined to be zero, meaning that WASI implementations are | ||
| 31 | * expected to always initialize a terminal the first time it's opened. | ||
| 32 | */ | ||
| 33 | #define O_TTY_INIT (0) | ||
| 34 | |||
| 35 | #define O_NOCTTY (0) | ||
| 36 | |||
| 37 | #define O_RDWR (O_RDONLY | O_WRONLY) | ||
| 38 | #define O_ACCMODE (O_EXEC | O_RDWR | O_SEARCH) | ||
| 39 | |||
| 40 | #define POSIX_FADV_DONTNEED __WASI_ADVICE_DONTNEED | ||
| 41 | #define POSIX_FADV_NOREUSE __WASI_ADVICE_NOREUSE | ||
| 42 | #define POSIX_FADV_NORMAL __WASI_ADVICE_NORMAL | ||
| 43 | #define POSIX_FADV_RANDOM __WASI_ADVICE_RANDOM | ||
| 44 | #define POSIX_FADV_SEQUENTIAL __WASI_ADVICE_SEQUENTIAL | ||
| 45 | #define POSIX_FADV_WILLNEED __WASI_ADVICE_WILLNEED | ||
| 46 | |||
| 47 | #define F_GETFD (1) | ||
| 48 | #define F_SETFD (2) | ||
| 49 | #define F_GETFL (3) | ||
| 50 | #define F_SETFL (4) | ||
| 51 | |||
| 52 | #define FD_CLOEXEC (1) | ||
| 53 | |||
| 54 | #define AT_EACCESS (0x0) | ||
| 55 | #define AT_SYMLINK_NOFOLLOW (0x1) | ||
| 56 | #define AT_SYMLINK_FOLLOW (0x2) | ||
| 57 | #define AT_REMOVEDIR (0x4) | ||
| 58 | |||
| 59 | #define AT_FDCWD (-2) | ||
| 60 | |||
| 61 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_inttypes.h deleted-182| ... | @@ -1,182 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___include_inttypes_h | ||
| 2 | #define __wasilibc___include_inttypes_h | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #define __need_wchar_t | ||
| 7 | #include <stddef.h> | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | typedef struct { intmax_t quot, rem; } imaxdiv_t; | ||
| 14 | |||
| 15 | intmax_t imaxabs(intmax_t); | ||
| 16 | imaxdiv_t imaxdiv(intmax_t, intmax_t); | ||
| 17 | intmax_t strtoimax(const char *__restrict, char **__restrict, int); | ||
| 18 | uintmax_t strtoumax(const char *__restrict, char **__restrict, int); | ||
| 19 | intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 20 | uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 21 | |||
| 22 | #define PRId16 __INT16_FMTd__ | ||
| 23 | #define PRIi16 __INT16_FMTi__ | ||
| 24 | #define PRId32 __INT32_FMTd__ | ||
| 25 | #define PRIi32 __INT32_FMTi__ | ||
| 26 | #define PRId64 __INT64_FMTd__ | ||
| 27 | #define PRIi64 __INT64_FMTi__ | ||
| 28 | #define PRId8 __INT8_FMTd__ | ||
| 29 | #define PRIi8 __INT8_FMTi__ | ||
| 30 | #define PRIdMAX __INTMAX_FMTd__ | ||
| 31 | #define PRIiMAX __INTMAX_FMTi__ | ||
| 32 | #define PRIdPTR __INTPTR_FMTd__ | ||
| 33 | #define PRIiPTR __INTPTR_FMTi__ | ||
| 34 | #define PRIdFAST16 __INT_FAST16_FMTd__ | ||
| 35 | #define PRIiFAST16 __INT_FAST16_FMTi__ | ||
| 36 | #define PRIdFAST32 __INT_FAST32_FMTd__ | ||
| 37 | #define PRIiFAST32 __INT_FAST32_FMTi__ | ||
| 38 | #define PRIdFAST64 __INT_FAST64_FMTd__ | ||
| 39 | #define PRIiFAST64 __INT_FAST64_FMTi__ | ||
| 40 | #define PRIdFAST8 __INT_FAST8_FMTd__ | ||
| 41 | #define PRIiFAST8 __INT_FAST8_FMTi__ | ||
| 42 | #define PRIdLEAST16 __INT_LEAST16_FMTd__ | ||
| 43 | #define PRIiLEAST16 __INT_LEAST16_FMTi__ | ||
| 44 | #define PRIdLEAST32 __INT_LEAST32_FMTd__ | ||
| 45 | #define PRIiLEAST32 __INT_LEAST32_FMTi__ | ||
| 46 | #define PRIdLEAST64 __INT_LEAST64_FMTd__ | ||
| 47 | #define PRIiLEAST64 __INT_LEAST64_FMTi__ | ||
| 48 | #define PRIdLEAST8 __INT_LEAST8_FMTd__ | ||
| 49 | #define PRIiLEAST8 __INT_LEAST8_FMTi__ | ||
| 50 | #define PRIX16 __UINT16_FMTX__ | ||
| 51 | #define PRIo16 __UINT16_FMTo__ | ||
| 52 | #define PRIu16 __UINT16_FMTu__ | ||
| 53 | #define PRIx16 __UINT16_FMTx__ | ||
| 54 | #define PRIX32 __UINT32_FMTX__ | ||
| 55 | #define PRIo32 __UINT32_FMTo__ | ||
| 56 | #define PRIu32 __UINT32_FMTu__ | ||
| 57 | #define PRIx32 __UINT32_FMTx__ | ||
| 58 | #define PRIX64 __UINT64_FMTX__ | ||
| 59 | #define PRIo64 __UINT64_FMTo__ | ||
| 60 | #define PRIu64 __UINT64_FMTu__ | ||
| 61 | #define PRIx64 __UINT64_FMTx__ | ||
| 62 | #define PRIX8 __UINT8_FMTX__ | ||
| 63 | #define PRIo8 __UINT8_FMTo__ | ||
| 64 | #define PRIu8 __UINT8_FMTu__ | ||
| 65 | #define PRIx8 __UINT8_FMTx__ | ||
| 66 | #define PRIXMAX __UINTMAX_FMTX__ | ||
| 67 | #define PRIoMAX __UINTMAX_FMTo__ | ||
| 68 | #define PRIuMAX __UINTMAX_FMTu__ | ||
| 69 | #define PRIxMAX __UINTMAX_FMTx__ | ||
| 70 | #define PRIXPTR __UINTPTR_FMTX__ | ||
| 71 | #define PRIoPTR __UINTPTR_FMTo__ | ||
| 72 | #define PRIuPTR __UINTPTR_FMTu__ | ||
| 73 | #define PRIxPTR __UINTPTR_FMTx__ | ||
| 74 | #define PRIXFAST16 __UINT_FAST16_FMTX__ | ||
| 75 | #define PRIoFAST16 __UINT_FAST16_FMTo__ | ||
| 76 | #define PRIuFAST16 __UINT_FAST16_FMTu__ | ||
| 77 | #define PRIxFAST16 __UINT_FAST16_FMTx__ | ||
| 78 | #define PRIXFAST32 __UINT_FAST32_FMTX__ | ||
| 79 | #define PRIoFAST32 __UINT_FAST32_FMTo__ | ||
| 80 | #define PRIuFAST32 __UINT_FAST32_FMTu__ | ||
| 81 | #define PRIxFAST32 __UINT_FAST32_FMTx__ | ||
| 82 | #define PRIXFAST64 __UINT_FAST64_FMTX__ | ||
| 83 | #define PRIoFAST64 __UINT_FAST64_FMTo__ | ||
| 84 | #define PRIuFAST64 __UINT_FAST64_FMTu__ | ||
| 85 | #define PRIxFAST64 __UINT_FAST64_FMTx__ | ||
| 86 | #define PRIXFAST8 __UINT_FAST8_FMTX__ | ||
| 87 | #define PRIoFAST8 __UINT_FAST8_FMTo__ | ||
| 88 | #define PRIuFAST8 __UINT_FAST8_FMTu__ | ||
| 89 | #define PRIxFAST8 __UINT_FAST8_FMTx__ | ||
| 90 | #define PRIXLEAST16 __UINT_LEAST16_FMTX__ | ||
| 91 | #define PRIoLEAST16 __UINT_LEAST16_FMTo__ | ||
| 92 | #define PRIuLEAST16 __UINT_LEAST16_FMTu__ | ||
| 93 | #define PRIxLEAST16 __UINT_LEAST16_FMTx__ | ||
| 94 | #define PRIXLEAST32 __UINT_LEAST32_FMTX__ | ||
| 95 | #define PRIoLEAST32 __UINT_LEAST32_FMTo__ | ||
| 96 | #define PRIuLEAST32 __UINT_LEAST32_FMTu__ | ||
| 97 | #define PRIxLEAST32 __UINT_LEAST32_FMTx__ | ||
| 98 | #define PRIXLEAST64 __UINT_LEAST64_FMTX__ | ||
| 99 | #define PRIoLEAST64 __UINT_LEAST64_FMTo__ | ||
| 100 | #define PRIuLEAST64 __UINT_LEAST64_FMTu__ | ||
| 101 | #define PRIxLEAST64 __UINT_LEAST64_FMTx__ | ||
| 102 | #define PRIXLEAST8 __UINT_LEAST8_FMTX__ | ||
| 103 | #define PRIoLEAST8 __UINT_LEAST8_FMTo__ | ||
| 104 | #define PRIuLEAST8 __UINT_LEAST8_FMTu__ | ||
| 105 | #define PRIxLEAST8 __UINT_LEAST8_FMTx__ | ||
| 106 | |||
| 107 | #define SCNd16 __INT16_FMTd__ | ||
| 108 | #define SCNi16 __INT16_FMTi__ | ||
| 109 | #define SCNd32 __INT32_FMTd__ | ||
| 110 | #define SCNi32 __INT32_FMTi__ | ||
| 111 | #define SCNd64 __INT64_FMTd__ | ||
| 112 | #define SCNi64 __INT64_FMTi__ | ||
| 113 | #define SCNd8 __INT8_FMTd__ | ||
| 114 | #define SCNi8 __INT8_FMTi__ | ||
| 115 | #define SCNdMAX __INTMAX_FMTd__ | ||
| 116 | #define SCNiMAX __INTMAX_FMTi__ | ||
| 117 | #define SCNdPTR __INTPTR_FMTd__ | ||
| 118 | #define SCNiPTR __INTPTR_FMTi__ | ||
| 119 | #define SCNdFAST16 __INT_FAST16_FMTd__ | ||
| 120 | #define SCNiFAST16 __INT_FAST16_FMTi__ | ||
| 121 | #define SCNdFAST32 __INT_FAST32_FMTd__ | ||
| 122 | #define SCNiFAST32 __INT_FAST32_FMTi__ | ||
| 123 | #define SCNdFAST64 __INT_FAST64_FMTd__ | ||
| 124 | #define SCNiFAST64 __INT_FAST64_FMTi__ | ||
| 125 | #define SCNdFAST8 __INT_FAST8_FMTd__ | ||
| 126 | #define SCNiFAST8 __INT_FAST8_FMTi__ | ||
| 127 | #define SCNdLEAST16 __INT_LEAST16_FMTd__ | ||
| 128 | #define SCNiLEAST16 __INT_LEAST16_FMTi__ | ||
| 129 | #define SCNdLEAST32 __INT_LEAST32_FMTd__ | ||
| 130 | #define SCNiLEAST32 __INT_LEAST32_FMTi__ | ||
| 131 | #define SCNdLEAST64 __INT_LEAST64_FMTd__ | ||
| 132 | #define SCNiLEAST64 __INT_LEAST64_FMTi__ | ||
| 133 | #define SCNdLEAST8 __INT_LEAST8_FMTd__ | ||
| 134 | #define SCNiLEAST8 __INT_LEAST8_FMTi__ | ||
| 135 | #define SCNo16 __UINT16_FMTo__ | ||
| 136 | #define SCNu16 __UINT16_FMTu__ | ||
| 137 | #define SCNx16 __UINT16_FMTx__ | ||
| 138 | #define SCNo32 __UINT32_FMTo__ | ||
| 139 | #define SCNu32 __UINT32_FMTu__ | ||
| 140 | #define SCNx32 __UINT32_FMTx__ | ||
| 141 | #define SCNo64 __UINT64_FMTo__ | ||
| 142 | #define SCNu64 __UINT64_FMTu__ | ||
| 143 | #define SCNx64 __UINT64_FMTx__ | ||
| 144 | #define SCNo8 __UINT8_FMTo__ | ||
| 145 | #define SCNu8 __UINT8_FMTu__ | ||
| 146 | #define SCNx8 __UINT8_FMTx__ | ||
| 147 | #define SCNoMAX __UINTMAX_FMTo__ | ||
| 148 | #define SCNuMAX __UINTMAX_FMTu__ | ||
| 149 | #define SCNxMAX __UINTMAX_FMTx__ | ||
| 150 | #define SCNoPTR __UINTPTR_FMTo__ | ||
| 151 | #define SCNuPTR __UINTPTR_FMTu__ | ||
| 152 | #define SCNxPTR __UINTPTR_FMTx__ | ||
| 153 | #define SCNoFAST16 __UINT_FAST16_FMTo__ | ||
| 154 | #define SCNuFAST16 __UINT_FAST16_FMTu__ | ||
| 155 | #define SCNxFAST16 __UINT_FAST16_FMTx__ | ||
| 156 | #define SCNoFAST32 __UINT_FAST32_FMTo__ | ||
| 157 | #define SCNuFAST32 __UINT_FAST32_FMTu__ | ||
| 158 | #define SCNxFAST32 __UINT_FAST32_FMTx__ | ||
| 159 | #define SCNoFAST64 __UINT_FAST64_FMTo__ | ||
| 160 | #define SCNuFAST64 __UINT_FAST64_FMTu__ | ||
| 161 | #define SCNxFAST64 __UINT_FAST64_FMTx__ | ||
| 162 | #define SCNoFAST8 __UINT_FAST8_FMTo__ | ||
| 163 | #define SCNuFAST8 __UINT_FAST8_FMTu__ | ||
| 164 | #define SCNxFAST8 __UINT_FAST8_FMTx__ | ||
| 165 | #define SCNoLEAST16 __UINT_LEAST16_FMTo__ | ||
| 166 | #define SCNuLEAST16 __UINT_LEAST16_FMTu__ | ||
| 167 | #define SCNxLEAST16 __UINT_LEAST16_FMTx__ | ||
| 168 | #define SCNoLEAST32 __UINT_LEAST32_FMTo__ | ||
| 169 | #define SCNuLEAST32 __UINT_LEAST32_FMTu__ | ||
| 170 | #define SCNxLEAST32 __UINT_LEAST32_FMTx__ | ||
| 171 | #define SCNoLEAST64 __UINT_LEAST64_FMTo__ | ||
| 172 | #define SCNuLEAST64 __UINT_LEAST64_FMTu__ | ||
| 173 | #define SCNxLEAST64 __UINT_LEAST64_FMTx__ | ||
| 174 | #define SCNoLEAST8 __UINT_LEAST8_FMTo__ | ||
| 175 | #define SCNuLEAST8 __UINT_LEAST8_FMTu__ | ||
| 176 | #define SCNxLEAST8 __UINT_LEAST8_FMTx__ | ||
| 177 | |||
| 178 | #ifdef __cplusplus | ||
| 179 | } | ||
| 180 | #endif | ||
| 181 | |||
| 182 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_netinet_in.h deleted-30| ... | @@ -1,30 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_netinet_in_h | ||
| 2 | #define __wasilibc___header_netinet_in_h | ||
| 3 | |||
| 4 | #include <__struct_in_addr.h> | ||
| 5 | #include <__struct_in6_addr.h> | ||
| 6 | #include <__struct_sockaddr_in.h> | ||
| 7 | #include <__struct_sockaddr_in6.h> | ||
| 8 | |||
| 9 | #define IPPROTO_IP 0 | ||
| 10 | #define IPPROTO_ICMP 1 | ||
| 11 | #define IPPROTO_TCP 6 | ||
| 12 | #define IPPROTO_UDP 17 | ||
| 13 | #define IPPROTO_IPV6 41 | ||
| 14 | #define IPPROTO_RAW 255 | ||
| 15 | |||
| 16 | #define IN6ADDR_ANY_INIT { { \ | ||
| 17 | 0x00, 0x00, 0x00, 0x00, \ | ||
| 18 | 0x00, 0x00, 0x00, 0x00, \ | ||
| 19 | 0x00, 0x00, 0x00, 0x00, \ | ||
| 20 | 0x00, 0x00, 0x00, 0x00 \ | ||
| 21 | } } | ||
| 22 | |||
| 23 | #define IN6ADDR_LOOPBACK_INIT { { \ | ||
| 24 | 0x00, 0x00, 0x00, 0x00, \ | ||
| 25 | 0x00, 0x00, 0x00, 0x00, \ | ||
| 26 | 0x00, 0x00, 0x00, 0x00, \ | ||
| 27 | 0x00, 0x00, 0x00, 0x01 \ | ||
| 28 | } } | ||
| 29 | |||
| 30 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_poll.h deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_poll_h | ||
| 2 | #define __wasilibc___header_poll_h | ||
| 3 | |||
| 4 | #include <__struct_pollfd.h> | ||
| 5 | #include <__typedef_nfds_t.h> | ||
| 6 | |||
| 7 | #define POLLRDNORM 0x1 | ||
| 8 | #define POLLWRNORM 0x2 | ||
| 9 | |||
| 10 | #define POLLIN POLLRDNORM | ||
| 11 | #define POLLOUT POLLWRNORM | ||
| 12 | |||
| 13 | #define POLLERR 0x1000 | ||
| 14 | #define POLLHUP 0x2000 | ||
| 15 | #define POLLNVAL 0x4000 | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | extern "C" { | ||
| 19 | #endif | ||
| 20 | |||
| 21 | int poll(struct pollfd[], nfds_t, int); | ||
| 22 | |||
| 23 | #ifdef __cplusplus | ||
| 24 | } | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_stdlib.h deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_stdlib_h | ||
| 2 | #define __wasilibc___header_stdlib_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__functions_malloc.h> | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | void abort(void) __attribute__((__noreturn__)); | ||
| 14 | void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 15 | void _Exit(int) __attribute__((__noreturn__)); | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | } | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_string.h deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_string_h | ||
| 2 | #define __wasilibc___header_string_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #define __need_NULL | ||
| 6 | #include <stddef.h> | ||
| 7 | |||
| 8 | #include <__functions_memcpy.h> | ||
| 9 | |||
| 10 | #ifdef __cplusplus | ||
| 11 | extern "C" { | ||
| 12 | #endif | ||
| 13 | |||
| 14 | size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); | ||
| 15 | char *strdup(const char *) __attribute__((__nothrow__, __nonnull__(1))); | ||
| 16 | int strcmp(const char *, const char *) __attribute__((__nothrow__, __pure__, __nonnull__(1, 2))); | ||
| 17 | void *memchr(const void *, int, size_t) __attribute__((__nothrow__, __pure__, __nonnull__(1))); | ||
| 18 | |||
| 19 | #ifdef __cplusplus | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_sys_ioctl.h deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_sys_ioctl_h | ||
| 2 | #define __wasilibc___header_sys_ioctl_h | ||
| 3 | |||
| 4 | #define FIONREAD 1 | ||
| 5 | #define FIONBIO 2 | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | int ioctl(int, int, ...); | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | } | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_sys_resource.h deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_sys_resource_h | ||
| 2 | #define __wasilibc___header_sys_resource_h | ||
| 3 | |||
| 4 | #include <__struct_rusage.h> | ||
| 5 | |||
| 6 | #define RUSAGE_SELF 1 | ||
| 7 | #define RUSAGE_CHILDREN 2 | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | int getrusage(int who, struct rusage *usage); | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | } | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_sys_socket.h deleted-79| ... | @@ -1,79 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_sys_socket_h | ||
| 2 | #define __wasilibc___header_sys_socket_h | ||
| 3 | |||
| 4 | #include <__wasi_snapshot.h> | ||
| 5 | #include <__struct_msghdr.h> | ||
| 6 | #include <__struct_sockaddr.h> | ||
| 7 | #include <__struct_sockaddr_storage.h> | ||
| 8 | |||
| 9 | #include <wasi/api.h> | ||
| 10 | |||
| 11 | #define SHUT_RD __WASI_SDFLAGS_RD | ||
| 12 | #define SHUT_WR __WASI_SDFLAGS_WR | ||
| 13 | #define SHUT_RDWR (SHUT_RD | SHUT_WR) | ||
| 14 | |||
| 15 | #ifdef __wasilibc_use_wasip2 | ||
| 16 | #define MSG_DONTWAIT 0x0040 | ||
| 17 | #define MSG_NOSIGNAL 0x4000 | ||
| 18 | #define MSG_PEEK 0x0002 | ||
| 19 | #define MSG_WAITALL 0x0100 | ||
| 20 | #define MSG_TRUNC 0x0020 | ||
| 21 | |||
| 22 | #define SOL_IP 0 | ||
| 23 | #define SOL_TCP 6 | ||
| 24 | #define SOL_UDP 17 | ||
| 25 | #define SOL_IPV6 41 | ||
| 26 | |||
| 27 | #define SOMAXCONN 128 | ||
| 28 | |||
| 29 | #define SO_REUSEADDR 2 | ||
| 30 | #define SO_ERROR 4 | ||
| 31 | #define SO_SNDBUF 7 | ||
| 32 | #define SO_RCVBUF 8 | ||
| 33 | #define SO_KEEPALIVE 9 | ||
| 34 | #define SO_ACCEPTCONN 30 | ||
| 35 | #define SO_PROTOCOL 38 | ||
| 36 | #define SO_DOMAIN 39 | ||
| 37 | |||
| 38 | #if __LONG_MAX == 0x7fffffff | ||
| 39 | #define SO_RCVTIMEO 66 | ||
| 40 | #define SO_SNDTIMEO 67 | ||
| 41 | #else | ||
| 42 | #define SO_RCVTIMEO 20 | ||
| 43 | #define SO_SNDTIMEO 21 | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #else // __wasilibc_use_wasip2 | ||
| 47 | #define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK | ||
| 48 | #define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL | ||
| 49 | #define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED | ||
| 50 | #endif // __wasilibc_use_wasip2 | ||
| 51 | |||
| 52 | #define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM | ||
| 53 | #define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM | ||
| 54 | |||
| 55 | #define SOCK_NONBLOCK (0x00004000) | ||
| 56 | #define SOCK_CLOEXEC (0x00002000) | ||
| 57 | |||
| 58 | #define SOL_SOCKET 0x7fffffff | ||
| 59 | |||
| 60 | #define SO_TYPE 3 | ||
| 61 | |||
| 62 | #define PF_UNSPEC 0 | ||
| 63 | #define PF_INET 1 | ||
| 64 | #define PF_INET6 2 | ||
| 65 | |||
| 66 | #define AF_UNSPEC PF_UNSPEC | ||
| 67 | #define AF_INET PF_INET | ||
| 68 | #define AF_INET6 PF_INET6 | ||
| 69 | #define AF_UNIX 3 | ||
| 70 | |||
| 71 | #ifdef __cplusplus | ||
| 72 | extern "C" { | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef __cplusplus | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_sys_stat.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_sys_stat_h | ||
| 2 | #define __wasilibc___header_sys_stat_h | ||
| 3 | |||
| 4 | #include <__struct_stat.h> | ||
| 5 | |||
| 6 | #define st_atime st_atim.tv_sec | ||
| 7 | #define st_mtime st_mtim.tv_sec | ||
| 8 | #define st_ctime st_ctim.tv_sec | ||
| 9 | |||
| 10 | #include <__mode_t.h> | ||
| 11 | |||
| 12 | #define UTIME_NOW (-1) | ||
| 13 | #define UTIME_OMIT (-2) | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_time.h deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_time_h | ||
| 2 | #define __wasilibc___header_time_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #define __need_NULL | ||
| 6 | #include <stddef.h> | ||
| 7 | |||
| 8 | #include <__typedef_time_t.h> | ||
| 9 | #include <__struct_timespec.h> | ||
| 10 | #include <__struct_tm.h> | ||
| 11 | #include <__typedef_clockid_t.h> | ||
| 12 | |||
| 13 | #include <wasi/api.h> | ||
| 14 | |||
| 15 | #define TIMER_ABSTIME __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME | ||
| 16 | |||
| 17 | extern const struct __clockid _CLOCK_MONOTONIC; | ||
| 18 | #define CLOCK_MONOTONIC (&_CLOCK_MONOTONIC) | ||
| 19 | extern const struct __clockid _CLOCK_REALTIME; | ||
| 20 | #define CLOCK_REALTIME (&_CLOCK_REALTIME) | ||
| 21 | |||
| 22 | /* | ||
| 23 | * TIME_UTC is the only standardized time base value. | ||
| 24 | */ | ||
| 25 | #define TIME_UTC 1 | ||
| 26 | |||
| 27 | /* | ||
| 28 | * Note that XSI specifies CLOCKS_PER_SEC to be 1000000, rather than | ||
| 29 | * 1000000000; the clock API is providing more precision than XSI specifies. | ||
| 30 | */ | ||
| 31 | #define CLOCKS_PER_SEC ((clock_t)1000000000) | ||
| 32 | |||
| 33 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_unistd.h deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___header_unistd_h | ||
| 2 | #define __wasilibc___header_unistd_h | ||
| 3 | |||
| 4 | struct stat; | ||
| 5 | |||
| 6 | #include <__seek.h> | ||
| 7 | |||
| 8 | #define F_OK (0) | ||
| 9 | #define X_OK (1) | ||
| 10 | #define W_OK (2) | ||
| 11 | #define R_OK (4) | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | extern "C" { | ||
| 15 | #endif | ||
| 16 | |||
| 17 | int close(int fd); | ||
| 18 | int faccessat(int, const char *, int, int); | ||
| 19 | int fstatat(int, const char *__restrict, struct stat *__restrict, int); | ||
| 20 | int renameat(int, const char *, int, const char *); | ||
| 21 | int openat(int, const char *, int, ...); | ||
| 22 | void *sbrk(intptr_t increment); | ||
| 23 | |||
| 24 | #ifdef __cplusplus | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #endif | ||
lib/libc/include/wasm-wasi-musl/__macro_FD_SETSIZE.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___macro_FD_SETSIZE_h | ||
| 2 | #define __wasilibc___macro_FD_SETSIZE_h | ||
| 3 | |||
| 4 | #define FD_SETSIZE 1024 | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__macro_PAGESIZE.h deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___macro_PAGESIZE_h | ||
| 2 | #define __wasilibc___macro_PAGESIZE_h | ||
| 3 | |||
| 4 | /* | ||
| 5 | * Without custom-page-sizes proposal, the page size in WebAssembly | ||
| 6 | * is fixed at 64 KiB. | ||
| 7 | * | ||
| 8 | * The LLVM versions with a support of custom-page-sizes proposal | ||
| 9 | * provides __wasm_first_page_end global to allow page-size-agnostic | ||
| 10 | * objects. | ||
| 11 | * | ||
| 12 | * If this ever needs to be a value outside the range of an `int`, the | ||
| 13 | * `getpagesize` function which returns this value will need special | ||
| 14 | * consideration. POSIX has deprecated `getpagesize` in favor of | ||
| 15 | * `sysconf(_SC_PAGESIZE)` which does not have this problem. | ||
| 16 | */ | ||
| 17 | #if __clang_major__ >= 22 | ||
| 18 | extern char __wasm_first_page_end; | ||
| 19 | #define PAGESIZE ((unsigned long)&__wasm_first_page_end) | ||
| 20 | #else | ||
| 21 | #define PAGESIZE (0x10000) | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif | ||
lib/libc/include/wasm-wasi-musl/__mode_t.h deleted-38| ... | @@ -1,38 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___mode_t_h | ||
| 2 | #define __wasilibc___mode_t_h | ||
| 3 | |||
| 4 | #define S_IFMT \ | ||
| 5 | (S_IFBLK | S_IFCHR | S_IFDIR | S_IFIFO | S_IFLNK | S_IFREG | S_IFSOCK) | ||
| 6 | #define S_IFBLK (0x6000) | ||
| 7 | #define S_IFCHR (0x2000) | ||
| 8 | #define S_IFDIR (0x4000) | ||
| 9 | #define S_IFLNK (0xa000) | ||
| 10 | #define S_IFREG (0x8000) | ||
| 11 | #define S_IFSOCK (0xc000) | ||
| 12 | #define S_IFIFO (0x1000) | ||
| 13 | |||
| 14 | #define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK) | ||
| 15 | #define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR) | ||
| 16 | #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) | ||
| 17 | #define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO) | ||
| 18 | #define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK) | ||
| 19 | #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) | ||
| 20 | #define S_ISSOCK(m) (((m)&S_IFMT) == S_IFSOCK) | ||
| 21 | |||
| 22 | #define S_IXOTH (0x1) | ||
| 23 | #define S_IWOTH (0x2) | ||
| 24 | #define S_IROTH (0x4) | ||
| 25 | #define S_IRWXO (S_IXOTH | S_IWOTH | S_IROTH) | ||
| 26 | #define S_IXGRP (0x8) | ||
| 27 | #define S_IWGRP (0x10) | ||
| 28 | #define S_IRGRP (0x20) | ||
| 29 | #define S_IRWXG (S_IXGRP | S_IWGRP | S_IRGRP) | ||
| 30 | #define S_IXUSR (0x40) | ||
| 31 | #define S_IWUSR (0x80) | ||
| 32 | #define S_IRUSR (0x100) | ||
| 33 | #define S_IRWXU (S_IXUSR | S_IWUSR | S_IRUSR) | ||
| 34 | #define S_ISVTX (0x200) | ||
| 35 | #define S_ISGID (0x400) | ||
| 36 | #define S_ISUID (0x800) | ||
| 37 | |||
| 38 | #endif | ||
lib/libc/include/wasm-wasi-musl/__seek.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___seek_h | ||
| 2 | #define __wasilibc___seek_h | ||
| 3 | |||
| 4 | #include <wasi/api.h> | ||
| 5 | |||
| 6 | #define SEEK_CUR __WASI_WHENCE_CUR | ||
| 7 | #define SEEK_END __WASI_WHENCE_END | ||
| 8 | #define SEEK_SET __WASI_WHENCE_SET | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_dirent.h deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_dirent_h | ||
| 2 | #define __wasilibc___struct_dirent_h | ||
| 3 | |||
| 4 | #include <__typedef_ino_t.h> | ||
| 5 | |||
| 6 | #define _DIRENT_HAVE_D_TYPE | ||
| 7 | |||
| 8 | struct dirent { | ||
| 9 | ino_t d_ino; | ||
| 10 | unsigned char d_type; | ||
| 11 | char d_name[]; | ||
| 12 | }; | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_in6_addr.h deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_in6_addr_h | ||
| 2 | #define __wasilibc___struct_in6_addr_h | ||
| 3 | |||
| 4 | struct in6_addr { | ||
| 5 | _Alignas(int32_t) unsigned char s6_addr[16]; | ||
| 6 | }; | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_in_addr.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_in_addr_h | ||
| 2 | #define __wasilibc___struct_in_addr_h | ||
| 3 | |||
| 4 | #include <__typedef_in_addr_t.h> | ||
| 5 | |||
| 6 | struct in_addr { | ||
| 7 | in_addr_t s_addr; | ||
| 8 | }; | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_iovec.h deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_iovec_h | ||
| 2 | #define __wasilibc___struct_iovec_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | struct iovec { | ||
| 8 | void *iov_base; | ||
| 9 | size_t iov_len; | ||
| 10 | }; | ||
| 11 | |||
| 12 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_msghdr.h deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_msghdr_h | ||
| 2 | #define __wasilibc___struct_msghdr_h | ||
| 3 | |||
| 4 | #include <__typedef_socklen_t.h> | ||
| 5 | |||
| 6 | struct msghdr { | ||
| 7 | void *msg_name; | ||
| 8 | socklen_t msg_namelen; | ||
| 9 | struct iovec *msg_iov; | ||
| 10 | int msg_iovlen; | ||
| 11 | void *msg_control; | ||
| 12 | socklen_t msg_controllen; | ||
| 13 | int msg_flags; | ||
| 14 | }; | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_pollfd.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_pollfd_h | ||
| 2 | #define __wasilibc___struct_pollfd_h | ||
| 3 | |||
| 4 | struct pollfd { | ||
| 5 | int fd; | ||
| 6 | short events; | ||
| 7 | short revents; | ||
| 8 | }; | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_rusage.h deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_rusage_h | ||
| 2 | #define __wasilibc___struct_rusage_h | ||
| 3 | |||
| 4 | #include <__struct_timeval.h> | ||
| 5 | |||
| 6 | /* TODO: Add more features here. */ | ||
| 7 | struct rusage { | ||
| 8 | struct timeval ru_utime; | ||
| 9 | struct timeval ru_stime; | ||
| 10 | }; | ||
| 11 | |||
| 12 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr.h deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_h | ||
| 2 | #define __wasilibc___struct_sockaddr_h | ||
| 3 | |||
| 4 | #include <__typedef_sa_family_t.h> | ||
| 5 | |||
| 6 | struct sockaddr { | ||
| 7 | __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sa_family; | ||
| 8 | char sa_data[0]; | ||
| 9 | }; | ||
| 10 | |||
| 11 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_in_h | ||
| 2 | #define __wasilibc___struct_sockaddr_in_h | ||
| 3 | |||
| 4 | #include <__typedef_sa_family_t.h> | ||
| 5 | #include <__typedef_in_port_t.h> | ||
| 6 | #include <__struct_in_addr.h> | ||
| 7 | |||
| 8 | struct sockaddr_in { | ||
| 9 | __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin_family; | ||
| 10 | in_port_t sin_port; | ||
| 11 | struct in_addr sin_addr; | ||
| 12 | }; | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_in6_h | ||
| 2 | #define __wasilibc___struct_sockaddr_in6_h | ||
| 3 | |||
| 4 | #include <__typedef_sa_family_t.h> | ||
| 5 | #include <__typedef_in_port_t.h> | ||
| 6 | #include <__struct_in6_addr.h> | ||
| 7 | |||
| 8 | struct sockaddr_in6 { | ||
| 9 | __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin6_family; | ||
| 10 | in_port_t sin6_port; | ||
| 11 | unsigned sin6_flowinfo; | ||
| 12 | struct in6_addr sin6_addr; | ||
| 13 | unsigned sin6_scope_id; | ||
| 14 | }; | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_storage_h | ||
| 2 | #define __wasilibc___struct_sockaddr_storage_h | ||
| 3 | |||
| 4 | #include <__typedef_sa_family_t.h> | ||
| 5 | |||
| 6 | struct sockaddr_storage { | ||
| 7 | __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t ss_family; | ||
| 8 | char __ss_data[32]; | ||
| 9 | }; | ||
| 10 | |||
| 11 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_un.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_un_h | ||
| 2 | #define __wasilibc___struct_sockaddr_un_h | ||
| 3 | |||
| 4 | #include <__typedef_sa_family_t.h> | ||
| 5 | |||
| 6 | struct sockaddr_un { | ||
| 7 | __attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sun_family; | ||
| 8 | }; | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_stat.h deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_stat_h | ||
| 2 | #define __wasilibc___struct_stat_h | ||
| 3 | |||
| 4 | #include <__typedef_dev_t.h> | ||
| 5 | #include <__typedef_ino_t.h> | ||
| 6 | #include <__typedef_nlink_t.h> | ||
| 7 | #include <__typedef_mode_t.h> | ||
| 8 | #include <__typedef_uid_t.h> | ||
| 9 | #include <__typedef_gid_t.h> | ||
| 10 | #include <__typedef_off_t.h> | ||
| 11 | #include <__typedef_blksize_t.h> | ||
| 12 | #include <__typedef_blkcnt_t.h> | ||
| 13 | #include <__struct_timespec.h> | ||
| 14 | |||
| 15 | struct stat { | ||
| 16 | dev_t st_dev; | ||
| 17 | ino_t st_ino; | ||
| 18 | nlink_t st_nlink; | ||
| 19 | |||
| 20 | mode_t st_mode; | ||
| 21 | uid_t st_uid; | ||
| 22 | gid_t st_gid; | ||
| 23 | unsigned int __pad0; | ||
| 24 | dev_t st_rdev; | ||
| 25 | off_t st_size; | ||
| 26 | blksize_t st_blksize; | ||
| 27 | blkcnt_t st_blocks; | ||
| 28 | |||
| 29 | struct timespec st_atim; | ||
| 30 | struct timespec st_mtim; | ||
| 31 | struct timespec st_ctim; | ||
| 32 | long long __reserved[3]; | ||
| 33 | }; | ||
| 34 | |||
| 35 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_timespec.h deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_timespec_h | ||
| 2 | #define __wasilibc___struct_timespec_h | ||
| 3 | |||
| 4 | #include <__typedef_time_t.h> | ||
| 5 | |||
| 6 | /* As specified in POSIX. */ | ||
| 7 | struct timespec { | ||
| 8 | time_t tv_sec; | ||
| 9 | long tv_nsec; | ||
| 10 | }; | ||
| 11 | |||
| 12 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_timeval.h deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_timeval_h | ||
| 2 | #define __wasilibc___struct_timeval_h | ||
| 3 | |||
| 4 | #include <__typedef_time_t.h> | ||
| 5 | #include <__typedef_suseconds_t.h> | ||
| 6 | |||
| 7 | /* As specified in POSIX. */ | ||
| 8 | struct timeval { | ||
| 9 | time_t tv_sec; | ||
| 10 | suseconds_t tv_usec; | ||
| 11 | }; | ||
| 12 | |||
| 13 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_tm.h deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_tm_h | ||
| 2 | #define __wasilibc___struct_tm_h | ||
| 3 | |||
| 4 | struct tm { | ||
| 5 | int tm_sec; | ||
| 6 | int tm_min; | ||
| 7 | int tm_hour; | ||
| 8 | int tm_mday; | ||
| 9 | int tm_mon; | ||
| 10 | int tm_year; | ||
| 11 | int tm_wday; | ||
| 12 | int tm_yday; | ||
| 13 | int tm_isdst; | ||
| 14 | int __tm_gmtoff; | ||
| 15 | const char *__tm_zone; | ||
| 16 | int __tm_nsec; | ||
| 17 | }; | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_tms.h deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___struct_tms_h | ||
| 2 | #define __wasilibc___struct_tms_h | ||
| 3 | |||
| 4 | #include <__typedef_clock_t.h> | ||
| 5 | |||
| 6 | struct tms { | ||
| 7 | clock_t tms_utime; | ||
| 8 | clock_t tms_stime; | ||
| 9 | clock_t tms_cutime; | ||
| 10 | clock_t tms_cstime; | ||
| 11 | }; | ||
| 12 | |||
| 13 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_DIR.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_DIR_h | ||
| 2 | #define __wasilibc___typedef_DIR_h | ||
| 3 | |||
| 4 | typedef struct _DIR DIR; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_blkcnt_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_blkcnt_t_h | ||
| 2 | #define __wasilibc___typedef_blkcnt_t_h | ||
| 3 | |||
| 4 | /* Define these as 64-bit signed integers to support files larger than 2 GiB. */ | ||
| 5 | typedef long long blkcnt_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_blksize_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_blksize_t_h | ||
| 2 | #define __wasilibc___typedef_blksize_t_h | ||
| 3 | |||
| 4 | typedef long blksize_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_clock_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_clock_t_h | ||
| 2 | #define __wasilibc___typedef_clock_t_h | ||
| 3 | |||
| 4 | /* Define this as a 64-bit signed integer to avoid wraparounds. */ | ||
| 5 | typedef long long clock_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_clockid_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_clockid_t_h | ||
| 2 | #define __wasilibc___typedef_clockid_t_h | ||
| 3 | |||
| 4 | typedef const struct __clockid *clockid_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_dev_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_dev_t_h | ||
| 2 | #define __wasilibc___typedef_dev_t_h | ||
| 3 | |||
| 4 | /* Define these as 64-bit integers to support billions of devices. */ | ||
| 5 | typedef unsigned long long dev_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_fd_set.h deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_fd_set_h | ||
| 2 | #define __wasilibc___typedef_fd_set_h | ||
| 3 | |||
| 4 | #define __need_size_t | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__macro_FD_SETSIZE.h> | ||
| 8 | |||
| 9 | typedef struct { | ||
| 10 | size_t __nfds; | ||
| 11 | int __fds[FD_SETSIZE]; | ||
| 12 | } fd_set; | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_gid_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_gid_t_h | ||
| 2 | #define __wasilibc___typedef_gid_t_h | ||
| 3 | |||
| 4 | typedef unsigned gid_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_in_addr_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_in_addr_t_h | ||
| 2 | #define __wasilibc___typedef_in_addr_t_h | ||
| 3 | |||
| 4 | typedef unsigned in_addr_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_in_port_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_in_port_t_h | ||
| 2 | #define __wasilibc___typedef_in_port_t_h | ||
| 3 | |||
| 4 | typedef unsigned short in_port_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_ino_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_ino_t_h | ||
| 2 | #define __wasilibc___typedef_ino_t_h | ||
| 3 | |||
| 4 | /* Define these as 64-bit integers to support billions of inodes. */ | ||
| 5 | typedef unsigned long long ino_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_mode_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_mode_t_h | ||
| 2 | #define __wasilibc___typedef_mode_t_h | ||
| 3 | |||
| 4 | typedef unsigned mode_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_nfds_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_nfds_t_h | ||
| 2 | #define __wasilibc___typedef_nfds_t_h | ||
| 3 | |||
| 4 | typedef unsigned long nfds_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_nlink_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_nlink_t_h | ||
| 2 | #define __wasilibc___typedef_nlink_t_h | ||
| 3 | |||
| 4 | /* Define these as 64-bit unsigned integers to support billions of links. */ | ||
| 5 | typedef unsigned long long nlink_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_off_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_off_t_h | ||
| 2 | #define __wasilibc___typedef_off_t_h | ||
| 3 | |||
| 4 | /* Define these as 64-bit signed integers to support files larger than 2 GiB. */ | ||
| 5 | typedef long long off_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_sa_family_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_sa_family_t_h | ||
| 2 | #define __wasilibc___typedef_sa_family_t_h | ||
| 3 | |||
| 4 | typedef unsigned short sa_family_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_sigset_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_sigset_t_h | ||
| 2 | #define __wasilibc___typedef_sigset_t_h | ||
| 3 | |||
| 4 | /* TODO: This is just a placeholder for now. Keep this in sync with musl. */ | ||
| 5 | typedef unsigned char sigset_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_socklen_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_socklen_t_h | ||
| 2 | #define __wasilibc___typedef_socklen_t_h | ||
| 3 | |||
| 4 | typedef unsigned socklen_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_ssize_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_ssize_t_h | ||
| 2 | #define __wasilibc___typedef_ssize_t_h | ||
| 3 | |||
| 4 | /* This is defined to be the same size as size_t. */ | ||
| 5 | typedef long ssize_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_suseconds_t.h deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_suseconds_t_h | ||
| 2 | #define __wasilibc___typedef_suseconds_t_h | ||
| 3 | |||
| 4 | /* Define this to be 64-bit as its main use is in struct timeval where the | ||
| 5 | extra space would otherwise be padding. */ | ||
| 6 | typedef long long suseconds_t; | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_time_t.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_time_t_h | ||
| 2 | #define __wasilibc___typedef_time_t_h | ||
| 3 | |||
| 4 | /* Define this as a 64-bit signed integer to avoid the 2038 bug. */ | ||
| 5 | typedef long long time_t; | ||
| 6 | |||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/__typedef_uid_t.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #ifndef __wasilibc___typedef_uid_t_h | ||
| 2 | #define __wasilibc___typedef_uid_t_h | ||
| 3 | |||
| 4 | typedef unsigned uid_t; | ||
| 5 | |||
| 6 | #endif | ||
lib/libc/include/wasm-wasi-musl/__wasi_snapshot.h deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | /* This file is (practically) empty by default. The Makefile will replace it | ||
| 2 | with a non-empty version that defines `__wasilibc_use_wasip2` if targeting | ||
| 3 | `wasm32-wasip2`. | ||
| 4 | */ | ||
| 5 | |||
lib/libc/include/wasm-wasi-musl/arpa/inet.h deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #ifndef _ARPA_INET_H | ||
| 2 | #define	_ARPA_INET_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | uint32_t htonl(uint32_t); | ||
| 12 | uint16_t htons(uint16_t); | ||
| 13 | uint32_t ntohl(uint32_t); | ||
| 14 | uint16_t ntohs(uint16_t); | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream /* WASI has no inet_addr */ | ||
| 17 | in_addr_t inet_addr (const char *); | ||
| 18 | in_addr_t inet_network (const char *); | ||
| 19 | char *inet_ntoa (struct in_addr); | ||
| 20 | #endif | ||
| 21 | int inet_pton (int, const char *__restrict, void *__restrict); | ||
| 22 | const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); | ||
| 23 | |||
| 24 | int inet_aton (const char *, struct in_addr *); | ||
| 25 | #ifdef __wasilibc_unmodified_upstream /* WASI has no inet_makeaddr */ | ||
| 26 | struct in_addr inet_makeaddr(in_addr_t, in_addr_t); | ||
| 27 | in_addr_t inet_lnaof(struct in_addr); | ||
| 28 | in_addr_t inet_netof(struct in_addr); | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifdef __cplusplus | ||
| 32 | } | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #endif | ||
lib/libc/include/wasm-wasi-musl/arpa/nameser_compat.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include <arpa/nameser.h> | ||
| 2 | |||
lib/libc/include/wasm-wasi-musl/arpa/tftp.h deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | #ifndef _ARPA_TFTP_H | ||
| 2 | #define _ARPA_TFTP_H | ||
| 3 | #define SEGSIZE 512 | ||
| 4 | #define RRQ 01 | ||
| 5 | #define WRQ 02 | ||
| 6 | #define DATA 03 | ||
| 7 | #define ACK 04 | ||
| 8 | #define ERROR 05 | ||
| 9 | struct tftphdr { | ||
| 10 | 	short th_opcode; | ||
| 11 | 	union { | ||
| 12 | 		unsigned short tu_block; | ||
| 13 | 		short tu_code; | ||
| 14 | 		char tu_stuff[1]; | ||
| 15 | 	} th_u; | ||
| 16 | 	char th_data[1]; | ||
| 17 | }; | ||
| 18 | #define th_block th_u.tu_block | ||
| 19 | #define th_code th_u.tu_code | ||
| 20 | #define th_stuff th_u.tu_stuff | ||
| 21 | #define th_msg th_data | ||
| 22 | #define EUNDEF 0 | ||
| 23 | #define ENOTFOUND 1 | ||
| 24 | #define EACCESS 2 | ||
| 25 | #define ENOSPACE 3 | ||
| 26 | #define EBADOP 4 | ||
| 27 | #define EBADID 5 | ||
| 28 | #define EEXISTS 6 | ||
| 29 | #define ENOUSER 7 | ||
| 30 | #endif | ||
| 31 | |||
lib/libc/include/wasm-wasi-musl/bits/alltypes.h deleted-460| ... | @@ -1,460 +0,0 @@ | ||
| 1 | #define _Addr long | ||
| 2 | #define _Int64 long long | ||
| 3 | #define _Reg long long | ||
| 4 | |||
| 5 | #define __BYTE_ORDER __BYTE_ORDER__ | ||
| 6 | |||
| 7 | #define __LONG_MAX __LONG_MAX__ | ||
| 8 | |||
| 9 | /* | ||
| 10 | * Rather than define everything ourselves here in the musl layer, for | ||
| 11 | * WASI, reference the definitions in the lower layers. | ||
| 12 | */ | ||
| 13 | |||
| 14 | #if defined(__NEED_wchar_t) && !defined(__DEFINED_wchar_t) | ||
| 15 | #define __need_wchar_t | ||
| 16 | #include <stddef.h> | ||
| 17 | #define __DEFINED_wchar_t | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) | ||
| 21 | #define __need_wint_t | ||
| 22 | #include <stddef.h> | ||
| 23 | #define __DEFINED_wint_t | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if defined(__NEED_float_t) && !defined(__DEFINED_float_t) | ||
| 27 | typedef float float_t; | ||
| 28 | #define __DEFINED_float_t | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #if defined(__NEED_double_t) && !defined(__DEFINED_double_t) | ||
| 32 | typedef double double_t; | ||
| 33 | #define __DEFINED_double_t | ||
| 34 | #endif | ||
| 35 | |||
| 36 | |||
| 37 | #if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) | ||
| 38 | #define __need_max_align_t | ||
| 39 | #include <stddef.h> | ||
| 40 | #define __DEFINED_max_align_t | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #if defined(__NEED_time_t) && !defined(__DEFINED_time_t) | ||
| 44 | #include <__typedef_time_t.h> | ||
| 45 | #define __DEFINED_time_t | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) | ||
| 49 | #include <__typedef_suseconds_t.h> | ||
| 50 | #define __DEFINED_suseconds_t | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) | ||
| 54 | #include <__typedef_clockid_t.h> | ||
| 55 | #define __DEFINED_clockid_t | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) | ||
| 59 | #include <__typedef_sigset_t.h> | ||
| 60 | #define __DEFINED_sigset_t | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) | ||
| 64 | #include <__typedef_clock_t.h> | ||
| 65 | #define __DEFINED_clock_t | ||
| 66 | #endif | ||
| 67 | #define __LITTLE_ENDIAN 1234 | ||
| 68 | #define __BIG_ENDIAN 4321 | ||
| 69 | #define __USE_TIME_BITS64 1 | ||
| 70 | |||
| 71 | #if defined(__NEED_size_t) && !defined(__DEFINED_size_t) | ||
| 72 | typedef unsigned _Addr size_t; | ||
| 73 | #define __DEFINED_size_t | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #if defined(__NEED_uintptr_t) && !defined(__DEFINED_uintptr_t) | ||
| 77 | typedef unsigned _Addr uintptr_t; | ||
| 78 | #define __DEFINED_uintptr_t | ||
| 79 | #endif | ||
| 80 | |||
| 81 | #if defined(__NEED_ptrdiff_t) && !defined(__DEFINED_ptrdiff_t) | ||
| 82 | typedef _Addr ptrdiff_t; | ||
| 83 | #define __DEFINED_ptrdiff_t | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #if defined(__NEED_ssize_t) && !defined(__DEFINED_ssize_t) | ||
| 87 | typedef _Addr ssize_t; | ||
| 88 | #define __DEFINED_ssize_t | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #if defined(__NEED_intptr_t) && !defined(__DEFINED_intptr_t) | ||
| 92 | typedef _Addr intptr_t; | ||
| 93 | #define __DEFINED_intptr_t | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #if defined(__NEED_regoff_t) && !defined(__DEFINED_regoff_t) | ||
| 97 | typedef _Addr regoff_t; | ||
| 98 | #define __DEFINED_regoff_t | ||
| 99 | #endif | ||
| 100 | |||
| 101 | #if defined(__NEED_register_t) && !defined(__DEFINED_register_t) | ||
| 102 | typedef _Reg register_t; | ||
| 103 | #define __DEFINED_register_t | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 107 | #if defined(__NEED_time_t) && !defined(__DEFINED_time_t) | ||
| 108 | typedef _Int64 time_t; | ||
| 109 | #define __DEFINED_time_t | ||
| 110 | #endif | ||
| 111 | |||
| 112 | #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) | ||
| 113 | typedef _Int64 suseconds_t; | ||
| 114 | #define __DEFINED_suseconds_t | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #else | ||
| 118 | #if defined(__NEED_time_t) && !defined(__DEFINED_time_t) | ||
| 119 | #include <__typedef_time_t.h> | ||
| 120 | #define __DEFINED_time_t | ||
| 121 | #endif | ||
| 122 | |||
| 123 | #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) | ||
| 124 | #include <__typedef_suseconds_t.h> | ||
| 125 | #define __DEFINED_suseconds_t | ||
| 126 | #endif | ||
| 127 | #endif | ||
| 128 | |||
| 129 | #if defined(__NEED_int8_t) && !defined(__DEFINED_int8_t) | ||
| 130 | typedef signed char int8_t; | ||
| 131 | #define __DEFINED_int8_t | ||
| 132 | #endif | ||
| 133 | |||
| 134 | #if defined(__NEED_int16_t) && !defined(__DEFINED_int16_t) | ||
| 135 | typedef signed short int16_t; | ||
| 136 | #define __DEFINED_int16_t | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #if defined(__NEED_int32_t) && !defined(__DEFINED_int32_t) | ||
| 140 | typedef signed int int32_t; | ||
| 141 | #define __DEFINED_int32_t | ||
| 142 | #endif | ||
| 143 | |||
| 144 | #if defined(__NEED_int64_t) && !defined(__DEFINED_int64_t) | ||
| 145 | typedef signed _Int64 int64_t; | ||
| 146 | #define __DEFINED_int64_t | ||
| 147 | #endif | ||
| 148 | |||
| 149 | #if defined(__NEED_intmax_t) && !defined(__DEFINED_intmax_t) | ||
| 150 | typedef signed _Int64 intmax_t; | ||
| 151 | #define __DEFINED_intmax_t | ||
| 152 | #endif | ||
| 153 | |||
| 154 | #if defined(__NEED_uint8_t) && !defined(__DEFINED_uint8_t) | ||
| 155 | typedef unsigned char uint8_t; | ||
| 156 | #define __DEFINED_uint8_t | ||
| 157 | #endif | ||
| 158 | |||
| 159 | #if defined(__NEED_uint16_t) && !defined(__DEFINED_uint16_t) | ||
| 160 | typedef unsigned short uint16_t; | ||
| 161 | #define __DEFINED_uint16_t | ||
| 162 | #endif | ||
| 163 | |||
| 164 | #if defined(__NEED_uint32_t) && !defined(__DEFINED_uint32_t) | ||
| 165 | typedef unsigned int uint32_t; | ||
| 166 | #define __DEFINED_uint32_t | ||
| 167 | #endif | ||
| 168 | |||
| 169 | #if defined(__NEED_uint64_t) && !defined(__DEFINED_uint64_t) | ||
| 170 | typedef unsigned _Int64 uint64_t; | ||
| 171 | #define __DEFINED_uint64_t | ||
| 172 | #endif | ||
| 173 | |||
| 174 | #if defined(__NEED_u_int64_t) && !defined(__DEFINED_u_int64_t) | ||
| 175 | typedef unsigned _Int64 u_int64_t; | ||
| 176 | #define __DEFINED_u_int64_t | ||
| 177 | #endif | ||
| 178 | |||
| 179 | #if defined(__NEED_uintmax_t) && !defined(__DEFINED_uintmax_t) | ||
| 180 | typedef unsigned _Int64 uintmax_t; | ||
| 181 | #define __DEFINED_uintmax_t | ||
| 182 | #endif | ||
| 183 | |||
| 184 | |||
| 185 | #if defined(__NEED_mode_t) && !defined(__DEFINED_mode_t) | ||
| 186 | typedef unsigned mode_t; | ||
| 187 | #define __DEFINED_mode_t | ||
| 188 | #endif | ||
| 189 | |||
| 190 | #if defined(__NEED_nlink_t) && !defined(__DEFINED_nlink_t) | ||
| 191 | typedef unsigned _Reg nlink_t; | ||
| 192 | #define __DEFINED_nlink_t | ||
| 193 | #endif | ||
| 194 | |||
| 195 | #if defined(__NEED_off_t) && !defined(__DEFINED_off_t) | ||
| 196 | typedef _Int64 off_t; | ||
| 197 | #define __DEFINED_off_t | ||
| 198 | #endif | ||
| 199 | |||
| 200 | #if defined(__NEED_ino_t) && !defined(__DEFINED_ino_t) | ||
| 201 | typedef unsigned _Int64 ino_t; | ||
| 202 | #define __DEFINED_ino_t | ||
| 203 | #endif | ||
| 204 | |||
| 205 | #if defined(__NEED_dev_t) && !defined(__DEFINED_dev_t) | ||
| 206 | typedef unsigned _Int64 dev_t; | ||
| 207 | #define __DEFINED_dev_t | ||
| 208 | #endif | ||
| 209 | |||
| 210 | #if defined(__NEED_blksize_t) && !defined(__DEFINED_blksize_t) | ||
| 211 | typedef long blksize_t; | ||
| 212 | #define __DEFINED_blksize_t | ||
| 213 | #endif | ||
| 214 | |||
| 215 | #if defined(__NEED_blkcnt_t) && !defined(__DEFINED_blkcnt_t) | ||
| 216 | typedef _Int64 blkcnt_t; | ||
| 217 | #define __DEFINED_blkcnt_t | ||
| 218 | #endif | ||
| 219 | |||
| 220 | #if defined(__NEED_fsblkcnt_t) && !defined(__DEFINED_fsblkcnt_t) | ||
| 221 | typedef unsigned _Int64 fsblkcnt_t; | ||
| 222 | #define __DEFINED_fsblkcnt_t | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #if defined(__NEED_fsfilcnt_t) && !defined(__DEFINED_fsfilcnt_t) | ||
| 226 | typedef unsigned _Int64 fsfilcnt_t; | ||
| 227 | #define __DEFINED_fsfilcnt_t | ||
| 228 | #endif | ||
| 229 | |||
| 230 | |||
| 231 | #if defined(__NEED_wint_t) && !defined(__DEFINED_wint_t) | ||
| 232 | typedef unsigned wint_t; | ||
| 233 | #define __DEFINED_wint_t | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #if defined(__NEED_wctype_t) && !defined(__DEFINED_wctype_t) | ||
| 237 | typedef unsigned long wctype_t; | ||
| 238 | #define __DEFINED_wctype_t | ||
| 239 | #endif | ||
| 240 | |||
| 241 | |||
| 242 | #if defined(__NEED_timer_t) && !defined(__DEFINED_timer_t) | ||
| 243 | typedef void * timer_t; | ||
| 244 | #define __DEFINED_timer_t | ||
| 245 | #endif | ||
| 246 | |||
| 247 | #if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) | ||
| 248 | typedef int clockid_t; | ||
| 249 | #define __DEFINED_clockid_t | ||
| 250 | #endif | ||
| 251 | |||
| 252 | #if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) | ||
| 253 | typedef long clock_t; | ||
| 254 | #define __DEFINED_clock_t | ||
| 255 | #endif | ||
| 256 | |||
| 257 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 258 | #if defined(__NEED_struct_timeval) && !defined(__DEFINED_struct_timeval) | ||
| 259 | struct timeval { time_t tv_sec; suseconds_t tv_usec; }; | ||
| 260 | #define __DEFINED_struct_timeval | ||
| 261 | #endif | ||
| 262 | |||
| 263 | #if defined(__NEED_struct_timespec) && !defined(__DEFINED_struct_timespec) | ||
| 264 | 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); }; | ||
| 265 | #define __DEFINED_struct_timespec | ||
| 266 | #endif | ||
| 267 | |||
| 268 | #else | ||
| 269 | #include <__struct_timeval.h> | ||
| 270 | #include <__struct_timespec.h> | ||
| 271 | #endif | ||
| 272 | |||
| 273 | #if defined(__NEED_pid_t) && !defined(__DEFINED_pid_t) | ||
| 274 | typedef int pid_t; | ||
| 275 | #define __DEFINED_pid_t | ||
| 276 | #endif | ||
| 277 | |||
| 278 | #if defined(__NEED_id_t) && !defined(__DEFINED_id_t) | ||
| 279 | typedef unsigned id_t; | ||
| 280 | #define __DEFINED_id_t | ||
| 281 | #endif | ||
| 282 | |||
| 283 | #if defined(__NEED_uid_t) && !defined(__DEFINED_uid_t) | ||
| 284 | typedef unsigned uid_t; | ||
| 285 | #define __DEFINED_uid_t | ||
| 286 | #endif | ||
| 287 | |||
| 288 | #if defined(__NEED_gid_t) && !defined(__DEFINED_gid_t) | ||
| 289 | typedef unsigned gid_t; | ||
| 290 | #define __DEFINED_gid_t | ||
| 291 | #endif | ||
| 292 | |||
| 293 | #if defined(__NEED_key_t) && !defined(__DEFINED_key_t) | ||
| 294 | typedef int key_t; | ||
| 295 | #define __DEFINED_key_t | ||
| 296 | #endif | ||
| 297 | |||
| 298 | #if defined(__NEED_useconds_t) && !defined(__DEFINED_useconds_t) | ||
| 299 | typedef unsigned useconds_t; | ||
| 300 | #define __DEFINED_useconds_t | ||
| 301 | #endif | ||
| 302 | |||
| 303 | |||
| 304 | #ifdef __cplusplus | ||
| 305 | #if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) | ||
| 306 | typedef unsigned long pthread_t; | ||
| 307 | #define __DEFINED_pthread_t | ||
| 308 | #endif | ||
| 309 | |||
| 310 | #else | ||
| 311 | #if defined(__NEED_pthread_t) && !defined(__DEFINED_pthread_t) | ||
| 312 | typedef struct __pthread * pthread_t; | ||
| 313 | #define __DEFINED_pthread_t | ||
| 314 | #endif | ||
| 315 | |||
| 316 | #endif | ||
| 317 | #if defined(__NEED_pthread_once_t) && !defined(__DEFINED_pthread_once_t) | ||
| 318 | typedef int pthread_once_t; | ||
| 319 | #define __DEFINED_pthread_once_t | ||
| 320 | #endif | ||
| 321 | |||
| 322 | #if defined(__NEED_pthread_key_t) && !defined(__DEFINED_pthread_key_t) | ||
| 323 | typedef unsigned pthread_key_t; | ||
| 324 | #define __DEFINED_pthread_key_t | ||
| 325 | #endif | ||
| 326 | |||
| 327 | #if defined(__NEED_pthread_spinlock_t) && !defined(__DEFINED_pthread_spinlock_t) | ||
| 328 | typedef int pthread_spinlock_t; | ||
| 329 | #define __DEFINED_pthread_spinlock_t | ||
| 330 | #endif | ||
| 331 | |||
| 332 | #if defined(__NEED_pthread_mutexattr_t) && !defined(__DEFINED_pthread_mutexattr_t) | ||
| 333 | typedef struct { unsigned __attr; } pthread_mutexattr_t; | ||
| 334 | #define __DEFINED_pthread_mutexattr_t | ||
| 335 | #endif | ||
| 336 | |||
| 337 | #if defined(__NEED_pthread_condattr_t) && !defined(__DEFINED_pthread_condattr_t) | ||
| 338 | typedef struct { unsigned __attr; } pthread_condattr_t; | ||
| 339 | #define __DEFINED_pthread_condattr_t | ||
| 340 | #endif | ||
| 341 | |||
| 342 | #if defined(__NEED_pthread_barrierattr_t) && !defined(__DEFINED_pthread_barrierattr_t) | ||
| 343 | typedef struct { unsigned __attr; } pthread_barrierattr_t; | ||
| 344 | #define __DEFINED_pthread_barrierattr_t | ||
| 345 | #endif | ||
| 346 | |||
| 347 | #if defined(__NEED_pthread_rwlockattr_t) && !defined(__DEFINED_pthread_rwlockattr_t) | ||
| 348 | typedef struct { unsigned __attr[2]; } pthread_rwlockattr_t; | ||
| 349 | #define __DEFINED_pthread_rwlockattr_t | ||
| 350 | #endif | ||
| 351 | |||
| 352 | |||
| 353 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 354 | #if defined(__NEED_struct__IO_FILE) && !defined(__DEFINED_struct__IO_FILE) | ||
| 355 | struct _IO_FILE { char __x; }; | ||
| 356 | #define __DEFINED_struct__IO_FILE | ||
| 357 | #endif | ||
| 358 | |||
| 359 | #endif | ||
| 360 | #if defined(__NEED_FILE) && !defined(__DEFINED_FILE) | ||
| 361 | typedef struct _IO_FILE FILE; | ||
| 362 | #define __DEFINED_FILE | ||
| 363 | #endif | ||
| 364 | |||
| 365 | |||
| 366 | #if defined(__NEED_va_list) && !defined(__DEFINED_va_list) | ||
| 367 | typedef __builtin_va_list va_list; | ||
| 368 | #define __DEFINED_va_list | ||
| 369 | #endif | ||
| 370 | |||
| 371 | #if defined(__NEED___isoc_va_list) && !defined(__DEFINED___isoc_va_list) | ||
| 372 | typedef __builtin_va_list __isoc_va_list; | ||
| 373 | #define __DEFINED___isoc_va_list | ||
| 374 | #endif | ||
| 375 | |||
| 376 | |||
| 377 | #if defined(__NEED_mbstate_t) && !defined(__DEFINED_mbstate_t) | ||
| 378 | typedef struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; | ||
| 379 | #define __DEFINED_mbstate_t | ||
| 380 | #endif | ||
| 381 | |||
| 382 | |||
| 383 | #if defined(__NEED_locale_t) && !defined(__DEFINED_locale_t) | ||
| 384 | typedef struct __locale_struct * locale_t; | ||
| 385 | #define __DEFINED_locale_t | ||
| 386 | #endif | ||
| 387 | |||
| 388 | |||
| 389 | #if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) | ||
| 390 | typedef struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t; | ||
| 391 | #define __DEFINED_sigset_t | ||
| 392 | #endif | ||
| 393 | |||
| 394 | |||
| 395 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 396 | #if defined(__NEED_struct_iovec) && !defined(__DEFINED_struct_iovec) | ||
| 397 | struct iovec { void *iov_base; size_t iov_len; }; | ||
| 398 | #define __DEFINED_struct_iovec | ||
| 399 | #endif | ||
| 400 | |||
| 401 | #else | ||
| 402 | #include <__struct_iovec.h> | ||
| 403 | #endif | ||
| 404 | |||
| 405 | #if defined(__NEED_struct_winsize) && !defined(__DEFINED_struct_winsize) | ||
| 406 | struct winsize { unsigned short ws_row, ws_col, ws_xpixel, ws_ypixel; }; | ||
| 407 | #define __DEFINED_struct_winsize | ||
| 408 | #endif | ||
| 409 | |||
| 410 | |||
| 411 | #if defined(__NEED_socklen_t) && !defined(__DEFINED_socklen_t) | ||
| 412 | typedef unsigned socklen_t; | ||
| 413 | #define __DEFINED_socklen_t | ||
| 414 | #endif | ||
| 415 | |||
| 416 | #if defined(__NEED_sa_family_t) && !defined(__DEFINED_sa_family_t) | ||
| 417 | typedef unsigned short sa_family_t; | ||
| 418 | #define __DEFINED_sa_family_t | ||
| 419 | #endif | ||
| 420 | |||
| 421 | |||
| 422 | #if defined(__NEED_pthread_attr_t) && !defined(__DEFINED_pthread_attr_t) | ||
| 423 | 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; | ||
| 424 | #define __DEFINED_pthread_attr_t | ||
| 425 | #endif | ||
| 426 | |||
| 427 | #if defined(__NEED_pthread_mutex_t) && !defined(__DEFINED_pthread_mutex_t) | ||
| 428 | 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; | ||
| 429 | #define __DEFINED_pthread_mutex_t | ||
| 430 | #endif | ||
| 431 | |||
| 432 | #if defined(__NEED_mtx_t) && !defined(__DEFINED_mtx_t) | ||
| 433 | 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; | ||
| 434 | #define __DEFINED_mtx_t | ||
| 435 | #endif | ||
| 436 | |||
| 437 | #if defined(__NEED_pthread_cond_t) && !defined(__DEFINED_pthread_cond_t) | ||
| 438 | typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } pthread_cond_t; | ||
| 439 | #define __DEFINED_pthread_cond_t | ||
| 440 | #endif | ||
| 441 | |||
| 442 | #if defined(__NEED_cnd_t) && !defined(__DEFINED_cnd_t) | ||
| 443 | typedef struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } cnd_t; | ||
| 444 | #define __DEFINED_cnd_t | ||
| 445 | #endif | ||
| 446 | |||
| 447 | #if defined(__NEED_pthread_rwlock_t) && !defined(__DEFINED_pthread_rwlock_t) | ||
| 448 | 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; | ||
| 449 | #define __DEFINED_pthread_rwlock_t | ||
| 450 | #endif | ||
| 451 | |||
| 452 | #if defined(__NEED_pthread_barrier_t) && !defined(__DEFINED_pthread_barrier_t) | ||
| 453 | 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; | ||
| 454 | #define __DEFINED_pthread_barrier_t | ||
| 455 | #endif | ||
| 456 | |||
| 457 | |||
| 458 | #undef _Addr | ||
| 459 | #undef _Int64 | ||
| 460 | #undef _Reg | ||
lib/libc/include/wasm-wasi-musl/bits/dirent.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__struct_dirent.h> | ||
lib/libc/include/wasm-wasi-musl/bits/fcntl.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | /* Use the WASI libc fcntl implementation bits. */ | ||
lib/libc/include/wasm-wasi-musl/bits/fenv.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #define FE_ALL_EXCEPT 0 | ||
| 2 | #define FE_TONEAREST 0 | ||
| 3 | |||
| 4 | typedef unsigned long fexcept_t; | ||
| 5 | |||
| 6 | typedef struct { | ||
| 7 | 	unsigned long __cw; | ||
| 8 | } fenv_t; | ||
| 9 | |||
| 10 | #define FE_DFL_ENV ((const fenv_t *) -1) | ||
lib/libc/include/wasm-wasi-musl/bits/ioctl.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | /* Use the WASI libc ioctl implementation bits. */ | ||
lib/libc/include/wasm-wasi-musl/bits/limits.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__macro_PAGESIZE.h> | ||
lib/libc/include/wasm-wasi-musl/bits/posix.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #define _POSIX_V6_ILP32_OFFBIG (1) | ||
| 2 | #define _POSIX_V7_ILP32_OFFBIG (1) | ||
lib/libc/include/wasm-wasi-musl/bits/setjmp.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | typedef unsigned long __jmp_buf[8]; | ||
lib/libc/include/wasm-wasi-musl/bits/signal.h deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | #ifdef _WASI_EMULATED_SIGNAL | ||
| 2 | |||
| 3 | #define SIGHUP 1 | ||
| 4 | #define SIGINT 2 | ||
| 5 | #define SIGQUIT 3 | ||
| 6 | #define SIGILL 4 | ||
| 7 | #define SIGTRAP 5 | ||
| 8 | #define SIGABRT 6 | ||
| 9 | #define SIGIOT SIGABRT | ||
| 10 | #define SIGBUS 7 | ||
| 11 | #define SIGFPE 8 | ||
| 12 | #define SIGKILL 9 | ||
| 13 | #define SIGUSR1 10 | ||
| 14 | #define SIGSEGV 11 | ||
| 15 | #define SIGUSR2 12 | ||
| 16 | #define SIGPIPE 13 | ||
| 17 | #define SIGALRM 14 | ||
| 18 | #define SIGTERM 15 | ||
| 19 | #define SIGSTKFLT 16 | ||
| 20 | #define SIGCHLD 17 | ||
| 21 | #define SIGCONT 18 | ||
| 22 | #define SIGSTOP 19 | ||
| 23 | #define SIGTSTP 20 | ||
| 24 | #define SIGTTIN 21 | ||
| 25 | #define SIGTTOU 22 | ||
| 26 | #define SIGURG 23 | ||
| 27 | #define SIGXCPU 24 | ||
| 28 | #define SIGXFSZ 25 | ||
| 29 | #define SIGVTALRM 26 | ||
| 30 | #define SIGPROF 27 | ||
| 31 | #define SIGWINCH 28 | ||
| 32 | #define SIGIO 29 | ||
| 33 | #define SIGPOLL 29 | ||
| 34 | #define SIGPWR 30 | ||
| 35 | #define SIGSYS 31 | ||
| 36 | #define SIGUNUSED SIGSYS | ||
| 37 | |||
| 38 | #define _NSIG 65 | ||
| 39 | |||
| 40 | #endif | ||
lib/libc/include/wasm-wasi-musl/bits/stat.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__struct_stat.h> | ||
lib/libc/include/wasm-wasi-musl/bits/stdint.h deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | typedef int16_t int_fast16_t; | ||
| 2 | typedef int32_t int_fast32_t; | ||
| 3 | typedef uint16_t uint_fast16_t; | ||
| 4 | typedef uint32_t uint_fast32_t; | ||
| 5 | |||
| 6 | #define INT_FAST16_MIN INT16_MIN | ||
| 7 | #define INT_FAST32_MIN INT32_MIN | ||
| 8 | |||
| 9 | #define INT_FAST16_MAX INT16_MAX | ||
| 10 | #define INT_FAST32_MAX INT32_MAX | ||
| 11 | |||
| 12 | #define UINT_FAST16_MAX UINT16_MAX | ||
| 13 | #define UINT_FAST32_MAX UINT32_MAX | ||
| 14 | |||
| 15 | #define INTPTR_MIN INT32_MIN | ||
| 16 | #define INTPTR_MAX INT32_MAX | ||
| 17 | #define UINTPTR_MAX UINT32_MAX | ||
| 18 | #define PTRDIFF_MIN INT32_MIN | ||
| 19 | #define PTRDIFF_MAX INT32_MAX | ||
| 20 | #define SIZE_MAX UINT32_MAX | ||
lib/libc/include/wasm-wasi-musl/complex.h deleted-143| ... | @@ -1,143 +0,0 @@ | ||
| 1 | #ifndef _COMPLEX_H | ||
| 2 | #define _COMPLEX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define complex _Complex | ||
| 9 | #ifdef __GNUC__ | ||
| 10 | #define _Complex_I (__extension__ (0.0f+1.0fi)) | ||
| 11 | #else | ||
| 12 | #define _Complex_I (0.0f+1.0fi) | ||
| 13 | #endif | ||
| 14 | #define I _Complex_I | ||
| 15 | |||
| 16 | double complex cacos(double complex); | ||
| 17 | float complex cacosf(float complex); | ||
| 18 | long double complex cacosl(long double complex); | ||
| 19 | |||
| 20 | double complex casin(double complex); | ||
| 21 | float complex casinf(float complex); | ||
| 22 | long double complex casinl(long double complex); | ||
| 23 | |||
| 24 | double complex catan(double complex); | ||
| 25 | float complex catanf(float complex); | ||
| 26 | long double complex catanl(long double complex); | ||
| 27 | |||
| 28 | double complex ccos(double complex); | ||
| 29 | float complex ccosf(float complex); | ||
| 30 | long double complex ccosl(long double complex); | ||
| 31 | |||
| 32 | double complex csin(double complex); | ||
| 33 | float complex csinf(float complex); | ||
| 34 | long double complex csinl(long double complex); | ||
| 35 | |||
| 36 | double complex ctan(double complex); | ||
| 37 | float complex ctanf(float complex); | ||
| 38 | long double complex ctanl(long double complex); | ||
| 39 | |||
| 40 | double complex cacosh(double complex); | ||
| 41 | float complex cacoshf(float complex); | ||
| 42 | long double complex cacoshl(long double complex); | ||
| 43 | |||
| 44 | double complex casinh(double complex); | ||
| 45 | float complex casinhf(float complex); | ||
| 46 | long double complex casinhl(long double complex); | ||
| 47 | |||
| 48 | double complex catanh(double complex); | ||
| 49 | float complex catanhf(float complex); | ||
| 50 | long double complex catanhl(long double complex); | ||
| 51 | |||
| 52 | double complex ccosh(double complex); | ||
| 53 | float complex ccoshf(float complex); | ||
| 54 | long double complex ccoshl(long double complex); | ||
| 55 | |||
| 56 | double complex csinh(double complex); | ||
| 57 | float complex csinhf(float complex); | ||
| 58 | long double complex csinhl(long double complex); | ||
| 59 | |||
| 60 | double complex ctanh(double complex); | ||
| 61 | float complex ctanhf(float complex); | ||
| 62 | long double complex ctanhl(long double complex); | ||
| 63 | |||
| 64 | double complex cexp(double complex); | ||
| 65 | float complex cexpf(float complex); | ||
| 66 | long double complex cexpl(long double complex); | ||
| 67 | |||
| 68 | double complex clog(double complex); | ||
| 69 | float complex clogf(float complex); | ||
| 70 | long double complex clogl(long double complex); | ||
| 71 | |||
| 72 | double cabs(double complex); | ||
| 73 | float cabsf(float complex); | ||
| 74 | long double cabsl(long double complex); | ||
| 75 | |||
| 76 | double complex cpow(double complex, double complex); | ||
| 77 | float complex cpowf(float complex, float complex); | ||
| 78 | long double complex cpowl(long double complex, long double complex); | ||
| 79 | |||
| 80 | double complex csqrt(double complex); | ||
| 81 | float complex csqrtf(float complex); | ||
| 82 | long double complex csqrtl(long double complex); | ||
| 83 | |||
| 84 | double carg(double complex); | ||
| 85 | float cargf(float complex); | ||
| 86 | long double cargl(long double complex); | ||
| 87 | |||
| 88 | double cimag(double complex); | ||
| 89 | float cimagf(float complex); | ||
| 90 | long double cimagl(long double complex); | ||
| 91 | |||
| 92 | double complex conj(double complex); | ||
| 93 | float complex conjf(float complex); | ||
| 94 | long double complex conjl(long double complex); | ||
| 95 | |||
| 96 | double complex cproj(double complex); | ||
| 97 | float complex cprojf(float complex); | ||
| 98 | long double complex cprojl(long double complex); | ||
| 99 | |||
| 100 | double creal(double complex); | ||
| 101 | float crealf(float complex); | ||
| 102 | long double creall(long double complex); | ||
| 103 | |||
| 104 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's real/imag operators rather than union type punning */ | ||
| 105 | #ifndef __cplusplus | ||
| 106 | #define __CIMAG(x, t) \ | ||
| 107 | 	(+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) | ||
| 108 | |||
| 109 | #define creal(x) ((double)(x)) | ||
| 110 | #define crealf(x) ((float)(x)) | ||
| 111 | #define creall(x) ((long double)(x)) | ||
| 112 | |||
| 113 | #define cimag(x) __CIMAG(x, double) | ||
| 114 | #define cimagf(x) __CIMAG(x, float) | ||
| 115 | #define cimagl(x) __CIMAG(x, long double) | ||
| 116 | #endif | ||
| 117 | #else | ||
| 118 | #define creal(x) (__builtin_creal(x)) | ||
| 119 | #define crealf(x) (__builtin_crealf(x)) | ||
| 120 | #define creall(x) (__builtin_creall(x)) | ||
| 121 | |||
| 122 | #define cimag(x) (__builtin_cimag(x)) | ||
| 123 | #define cimagf(x) (__builtin_cimagf(x)) | ||
| 124 | #define cimagl(x) (__builtin_cimagl(x)) | ||
| 125 | #endif | ||
| 126 | |||
| 127 | #if __STDC_VERSION__ >= 201112L | ||
| 128 | #if defined(_Imaginary_I) | ||
| 129 | #define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)) | ||
| 130 | #elif defined(__clang__) | ||
| 131 | #define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) | ||
| 132 | #else | ||
| 133 | #define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) | ||
| 134 | #endif | ||
| 135 | #define CMPLX(x, y) __CMPLX(x, y, double) | ||
| 136 | #define CMPLXF(x, y) __CMPLX(x, y, float) | ||
| 137 | #define CMPLXL(x, y) __CMPLX(x, y, long double) | ||
| 138 | #endif | ||
| 139 | |||
| 140 | #ifdef __cplusplus | ||
| 141 | } | ||
| 142 | #endif | ||
| 143 | #endif | ||
lib/libc/include/wasm-wasi-musl/dirent.h deleted-89| ... | @@ -1,89 +0,0 @@ | ||
| 1 | #ifndef	_DIRENT_H | ||
| 2 | #define	_DIRENT_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__header_dirent.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #define __NEED_ino_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 17 | #define __NEED_size_t | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #include <bits/alltypes.h> | ||
| 21 | |||
| 22 | #include <bits/dirent.h> | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 25 | typedef struct __dirstream DIR; | ||
| 26 | #else | ||
| 27 | #include <__typedef_DIR.h> | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #define d_fileno d_ino | ||
| 31 | |||
| 32 | int closedir(DIR *); | ||
| 33 | DIR *fdopendir(int); | ||
| 34 | DIR *opendir(const char *); | ||
| 35 | struct dirent *readdir(DIR *); | ||
| 36 | #ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ | ||
| 37 | int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); | ||
| 38 | #endif | ||
| 39 | void rewinddir(DIR *); | ||
| 40 | int dirfd(DIR *); | ||
| 41 | |||
| 42 | int alphasort(const struct dirent **, const struct dirent **); | ||
| 43 | int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); | ||
| 44 | |||
| 45 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 46 | void seekdir(DIR *, long); | ||
| 47 | long telldir(DIR *); | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 51 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 52 | #define DT_UNKNOWN 0 | ||
| 53 | #define DT_FIFO 1 | ||
| 54 | #define DT_CHR 2 | ||
| 55 | #define DT_DIR 4 | ||
| 56 | #define DT_BLK 6 | ||
| 57 | #define DT_REG 8 | ||
| 58 | #define DT_LNK 10 | ||
| 59 | #define DT_SOCK 12 | ||
| 60 | #define DT_WHT 14 | ||
| 61 | #define IFTODT(x) ((x)>>12 & 017) | ||
| 62 | #define DTTOIF(x) ((x)<<12) | ||
| 63 | #endif | ||
| 64 | int getdents(int, struct dirent *, size_t); | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #ifdef _GNU_SOURCE | ||
| 68 | int versionsort(const struct dirent **, const struct dirent **); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 72 | #define dirent64 dirent | ||
| 73 | #define readdir64 readdir | ||
| 74 | #ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ | ||
| 75 | #define readdir64_r readdir_r | ||
| 76 | #endif | ||
| 77 | #define scandir64 scandir | ||
| 78 | #define alphasort64 alphasort | ||
| 79 | #define versionsort64 versionsort | ||
| 80 | #define off64_t off_t | ||
| 81 | #define ino64_t ino_t | ||
| 82 | #define getdents64 getdents | ||
| 83 | #endif | ||
| 84 | |||
| 85 | #ifdef __cplusplus | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #endif | ||
lib/libc/include/wasm-wasi-musl/dlfcn.h deleted-56| ... | @@ -1,56 +0,0 @@ | ||
| 1 | #ifndef	_DLFCN_H | ||
| 2 | #define	_DLFCN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define RTLD_LAZY 1 | ||
| 11 | #define RTLD_NOW 2 | ||
| 12 | #define RTLD_NOLOAD 4 | ||
| 13 | #define RTLD_NODELETE 4096 | ||
| 14 | #define RTLD_GLOBAL 256 | ||
| 15 | #ifdef __wasilibc_unmodified_upstream | ||
| 16 | #define RTLD_LOCAL 0 | ||
| 17 | #else | ||
| 18 | /* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and | ||
| 19 | * allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` | ||
| 20 | * should be the default when neither is specified. | ||
| 21 | */ | ||
| 22 | #define RTLD_LOCAL 8 | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #define RTLD_NEXT ((void *)-1) | ||
| 26 | #define RTLD_DEFAULT ((void *)0) | ||
| 27 | |||
| 28 | #ifdef __wasilibc_unmodified_upstream | ||
| 29 | #define RTLD_DI_LINKMAP 2 | ||
| 30 | #endif | ||
| 31 | |||
| 32 | int dlclose(void *); | ||
| 33 | char *dlerror(void); | ||
| 34 | void *dlopen(const char *, int); | ||
| 35 | void *dlsym(void *__restrict, const char *__restrict); | ||
| 36 | |||
| 37 | #if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) | ||
| 38 | typedef struct { | ||
| 39 | 	const char *dli_fname; | ||
| 40 | 	void *dli_fbase; | ||
| 41 | 	const char *dli_sname; | ||
| 42 | 	void *dli_saddr; | ||
| 43 | } Dl_info; | ||
| 44 | int dladdr(const void *, Dl_info *); | ||
| 45 | int dlinfo(void *, int, void *); | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #if _REDIR_TIME64 | ||
| 49 | __REDIR(dlsym, __dlsym_time64); | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #ifdef __cplusplus | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #endif | ||
lib/libc/include/wasm-wasi-musl/errno.h deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #ifndef	_ERRNO_H | ||
| 2 | #define _ERRNO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 11 | #include <bits/errno.h> | ||
| 12 | |||
| 13 | #ifdef __GNUC__ | ||
| 14 | __attribute__((const)) | ||
| 15 | #endif | ||
| 16 | int *__errno_location(void); | ||
| 17 | #define errno (*__errno_location()) | ||
| 18 | #else | ||
| 19 | #include <__errno.h> | ||
| 20 | #include <__errno_values.h> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #ifdef _GNU_SOURCE | ||
| 24 | extern char *program_invocation_short_name, *program_invocation_name; | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifdef __cplusplus | ||
| 28 | } | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #endif | ||
| 32 | |||
lib/libc/include/wasm-wasi-musl/fcntl.h deleted-250| ... | @@ -1,250 +0,0 @@ | ||
| 1 | #ifndef	_FCNTL_H | ||
| 2 | #define	_FCNTL_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__header_fcntl.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #define __NEED_off_t | ||
| 15 | #define __NEED_pid_t | ||
| 16 | #define __NEED_mode_t | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __NEED_size_t | ||
| 20 | #define __NEED_ssize_t | ||
| 21 | #define __NEED_struct_iovec | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include <bits/alltypes.h> | ||
| 25 | |||
| 26 | #include <bits/fcntl.h> | ||
| 27 | |||
| 28 | struct flock { | ||
| 29 | 	short l_type; | ||
| 30 | 	short l_whence; | ||
| 31 | 	off_t l_start; | ||
| 32 | 	off_t l_len; | ||
| 33 | 	pid_t l_pid; | ||
| 34 | }; | ||
| 35 | |||
| 36 | int creat(const char *, mode_t); | ||
| 37 | int fcntl(int, int, ...); | ||
| 38 | int open(const char *, int, ...); | ||
| 39 | int openat(int, const char *, int, ...); | ||
| 40 | int posix_fadvise(int, off_t, off_t, int); | ||
| 41 | int posix_fallocate(int, off_t, off_t); | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 44 | #define O_SEARCH O_PATH | ||
| 45 | #define O_EXEC O_PATH | ||
| 46 | #define O_TTY_INIT 0 | ||
| 47 | |||
| 48 | #define O_ACCMODE (03|O_SEARCH) | ||
| 49 | #define O_RDONLY 00 | ||
| 50 | #define O_WRONLY 01 | ||
| 51 | #define O_RDWR 02 | ||
| 52 | |||
| 53 | #define F_OFD_GETLK 36 | ||
| 54 | #define F_OFD_SETLK 37 | ||
| 55 | #define F_OFD_SETLKW 38 | ||
| 56 | |||
| 57 | #define F_DUPFD_CLOEXEC 1030 | ||
| 58 | |||
| 59 | #define F_RDLCK 0 | ||
| 60 | #define F_WRLCK 1 | ||
| 61 | #define F_UNLCK 2 | ||
| 62 | |||
| 63 | #define FD_CLOEXEC 1 | ||
| 64 | |||
| 65 | #define AT_FDCWD (-100) | ||
| 66 | #define AT_SYMLINK_NOFOLLOW 0x100 | ||
| 67 | #define AT_REMOVEDIR 0x200 | ||
| 68 | #define AT_SYMLINK_FOLLOW 0x400 | ||
| 69 | #define AT_EACCESS 0x200 | ||
| 70 | |||
| 71 | #define POSIX_FADV_NORMAL 0 | ||
| 72 | #define POSIX_FADV_RANDOM 1 | ||
| 73 | #define POSIX_FADV_SEQUENTIAL 2 | ||
| 74 | #define POSIX_FADV_WILLNEED 3 | ||
| 75 | #ifndef POSIX_FADV_DONTNEED | ||
| 76 | #define POSIX_FADV_DONTNEED 4 | ||
| 77 | #define POSIX_FADV_NOREUSE 5 | ||
| 78 | #endif | ||
| 79 | |||
| 80 | #undef SEEK_SET | ||
| 81 | #undef SEEK_CUR | ||
| 82 | #undef SEEK_END | ||
| 83 | #define SEEK_SET 0 | ||
| 84 | #define SEEK_CUR 1 | ||
| 85 | #define SEEK_END 2 | ||
| 86 | |||
| 87 | #ifndef S_IRUSR | ||
| 88 | #define S_ISUID 04000 | ||
| 89 | #define S_ISGID 02000 | ||
| 90 | #define S_ISVTX 01000 | ||
| 91 | #define S_IRUSR 0400 | ||
| 92 | #define S_IWUSR 0200 | ||
| 93 | #define S_IXUSR 0100 | ||
| 94 | #define S_IRWXU 0700 | ||
| 95 | #define S_IRGRP 0040 | ||
| 96 | #define S_IWGRP 0020 | ||
| 97 | #define S_IXGRP 0010 | ||
| 98 | #define S_IRWXG 0070 | ||
| 99 | #define S_IROTH 0004 | ||
| 100 | #define S_IWOTH 0002 | ||
| 101 | #define S_IXOTH 0001 | ||
| 102 | #define S_IRWXO 0007 | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 106 | #define AT_NO_AUTOMOUNT 0x800 | ||
| 107 | #define AT_EMPTY_PATH 0x1000 | ||
| 108 | #define AT_STATX_SYNC_TYPE 0x6000 | ||
| 109 | #define AT_STATX_SYNC_AS_STAT 0x0000 | ||
| 110 | #define AT_STATX_FORCE_SYNC 0x2000 | ||
| 111 | #define AT_STATX_DONT_SYNC 0x4000 | ||
| 112 | #define AT_RECURSIVE 0x8000 | ||
| 113 | |||
| 114 | #define FAPPEND O_APPEND | ||
| 115 | #define FFSYNC O_SYNC | ||
| 116 | #define FASYNC O_ASYNC | ||
| 117 | #define FNONBLOCK O_NONBLOCK | ||
| 118 | #define FNDELAY O_NDELAY | ||
| 119 | |||
| 120 | #define F_OK 0 | ||
| 121 | #define R_OK 4 | ||
| 122 | #define W_OK 2 | ||
| 123 | #define X_OK 1 | ||
| 124 | #define F_ULOCK 0 | ||
| 125 | #define F_LOCK 1 | ||
| 126 | #define F_TLOCK 2 | ||
| 127 | #define F_TEST 3 | ||
| 128 | |||
| 129 | #define F_SETLEASE	1024 | ||
| 130 | #define F_GETLEASE	1025 | ||
| 131 | #define F_NOTIFY	1026 | ||
| 132 | #define F_CANCELLK	1029 | ||
| 133 | #define F_SETPIPE_SZ	1031 | ||
| 134 | #define F_GETPIPE_SZ	1032 | ||
| 135 | #define F_ADD_SEALS	1033 | ||
| 136 | #define F_GET_SEALS	1034 | ||
| 137 | |||
| 138 | #define F_SEAL_SEAL	0x0001 | ||
| 139 | #define F_SEAL_SHRINK	0x0002 | ||
| 140 | #define F_SEAL_GROW	0x0004 | ||
| 141 | #define F_SEAL_WRITE	0x0008 | ||
| 142 | #define F_SEAL_FUTURE_WRITE	0x0010 | ||
| 143 | |||
| 144 | #define F_GET_RW_HINT		1035 | ||
| 145 | #define F_SET_RW_HINT		1036 | ||
| 146 | #define F_GET_FILE_RW_HINT	1037 | ||
| 147 | #define F_SET_FILE_RW_HINT	1038 | ||
| 148 | |||
| 149 | #define RWF_WRITE_LIFE_NOT_SET	0 | ||
| 150 | #define RWH_WRITE_LIFE_NONE	1 | ||
| 151 | #define RWH_WRITE_LIFE_SHORT	2 | ||
| 152 | #define RWH_WRITE_LIFE_MEDIUM	3 | ||
| 153 | #define RWH_WRITE_LIFE_LONG	4 | ||
| 154 | #define RWH_WRITE_LIFE_EXTREME	5 | ||
| 155 | |||
| 156 | #define DN_ACCESS	0x00000001 | ||
| 157 | #define DN_MODIFY	0x00000002 | ||
| 158 | #define DN_CREATE	0x00000004 | ||
| 159 | #define DN_DELETE	0x00000008 | ||
| 160 | #define DN_RENAME	0x00000010 | ||
| 161 | #define DN_ATTRIB	0x00000020 | ||
| 162 | #define DN_MULTISHOT	0x80000000 | ||
| 163 | |||
| 164 | int lockf(int, int, off_t); | ||
| 165 | #endif | ||
| 166 | #endif | ||
| 167 | |||
| 168 | #if defined(_GNU_SOURCE) | ||
| 169 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 170 | #define F_OWNER_TID 0 | ||
| 171 | #define F_OWNER_PID 1 | ||
| 172 | #define F_OWNER_PGRP 2 | ||
| 173 | #define F_OWNER_GID 2 | ||
| 174 | struct file_handle { | ||
| 175 | 	unsigned handle_bytes; | ||
| 176 | 	int handle_type; | ||
| 177 | 	unsigned char f_handle[]; | ||
| 178 | }; | ||
| 179 | #endif | ||
| 180 | #ifdef __wasilibc_unmodified_upstream /* WASI has no F_GETOWN_EX */ | ||
| 181 | struct f_owner_ex { | ||
| 182 | 	int type; | ||
| 183 | 	pid_t pid; | ||
| 184 | }; | ||
| 185 | #endif | ||
| 186 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ | ||
| 187 | #define FALLOC_FL_KEEP_SIZE 1 | ||
| 188 | #define FALLOC_FL_PUNCH_HOLE 2 | ||
| 189 | #endif | ||
| 190 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 191 | #define MAX_HANDLE_SZ 128 | ||
| 192 | #endif | ||
| 193 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syc_file_range */ | ||
| 194 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 | ||
| 195 | #define SYNC_FILE_RANGE_WRITE 2 | ||
| 196 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 | ||
| 197 | #endif | ||
| 198 | #ifdef __wasilibc_unmodified_upstream /* WASI has no splice */ | ||
| 199 | #define SPLICE_F_MOVE 1 | ||
| 200 | #define SPLICE_F_NONBLOCK 2 | ||
| 201 | #define SPLICE_F_MORE 4 | ||
| 202 | #define SPLICE_F_GIFT 8 | ||
| 203 | #endif | ||
| 204 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ | ||
| 205 | int fallocate(int, int, off_t, off_t); | ||
| 206 | #endif | ||
| 207 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 208 | int name_to_handle_at(int, const char *, struct file_handle *, int *, int); | ||
| 209 | int open_by_handle_at(int, struct file_handle *, int); | ||
| 210 | #endif | ||
| 211 | #ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */ | ||
| 212 | ssize_t readahead(int, off_t, size_t); | ||
| 213 | #endif | ||
| 214 | #ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */ | ||
| 215 | int sync_file_range(int, off_t, off_t, unsigned); | ||
| 216 | ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); | ||
| 217 | ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 218 | ssize_t tee(int, int, size_t, unsigned); | ||
| 219 | #endif | ||
| 220 | #define loff_t off_t | ||
| 221 | #endif | ||
| 222 | |||
| 223 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 224 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 225 | #define F_GETLK64 F_GETLK | ||
| 226 | #define F_SETLK64 F_SETLK | ||
| 227 | #define F_SETLKW64 F_SETLKW | ||
| 228 | #define flock64 flock | ||
| 229 | #endif | ||
| 230 | #define open64 open | ||
| 231 | #define openat64 openat | ||
| 232 | #define creat64 creat | ||
| 233 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 234 | #define lockf64 lockf | ||
| 235 | #endif | ||
| 236 | #define posix_fadvise64 posix_fadvise | ||
| 237 | #define posix_fallocate64 posix_fallocate | ||
| 238 | #define off64_t off_t | ||
| 239 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ | ||
| 240 | #if defined(_GNU_SOURCE) | ||
| 241 | #define fallocate64 fallocate | ||
| 242 | #endif | ||
| 243 | #endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifdef __cplusplus | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | |||
| 250 | #endif | ||
lib/libc/include/wasm-wasi-musl/fenv.h deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | #ifndef _FENV_H | ||
| 2 | #define _FENV_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <bits/fenv.h> | ||
| 9 | |||
| 10 | int feclearexcept(int); | ||
| 11 | int fegetexceptflag(fexcept_t *, int); | ||
| 12 | int feraiseexcept(int); | ||
| 13 | int fesetexceptflag(const fexcept_t *, int); | ||
| 14 | int fetestexcept(int); | ||
| 15 | |||
| 16 | int fegetround(void); | ||
| 17 | int fesetround(int); | ||
| 18 | |||
| 19 | int fegetenv(fenv_t *); | ||
| 20 | int feholdexcept(fenv_t *); | ||
| 21 | int fesetenv(const fenv_t *); | ||
| 22 | int feupdateenv(const fenv_t *); | ||
| 23 | |||
| 24 | #ifdef __cplusplus | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | #endif | ||
| 28 | |||
lib/libc/include/wasm-wasi-musl/float.h deleted-56| ... | @@ -1,56 +0,0 @@ | ||
| 1 | #ifndef _FLOAT_H | ||
| 2 | #define _FLOAT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of FLT_ROUNDS */ | ||
| 9 | int __flt_rounds(void); | ||
| 10 | #define FLT_ROUNDS (__flt_rounds()) | ||
| 11 | #else | ||
| 12 | #define FLT_ROUNDS (__builtin_flt_rounds()) | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #define FLT_RADIX 2 | ||
| 16 | |||
| 17 | #define FLT_TRUE_MIN 1.40129846432481707092e-45F | ||
| 18 | #define FLT_MIN 1.17549435082228750797e-38F | ||
| 19 | #define FLT_MAX 3.40282346638528859812e+38F | ||
| 20 | #define FLT_EPSILON 1.1920928955078125e-07F | ||
| 21 | |||
| 22 | #define FLT_MANT_DIG 24 | ||
| 23 | #define FLT_MIN_EXP (-125) | ||
| 24 | #define FLT_MAX_EXP 128 | ||
| 25 | #define FLT_HAS_SUBNORM 1 | ||
| 26 | |||
| 27 | #define FLT_DIG 6 | ||
| 28 | #define FLT_DECIMAL_DIG 9 | ||
| 29 | #define FLT_MIN_10_EXP (-37) | ||
| 30 | #define FLT_MAX_10_EXP 38 | ||
| 31 | |||
| 32 | #define DBL_TRUE_MIN 4.94065645841246544177e-324 | ||
| 33 | #define DBL_MIN 2.22507385850720138309e-308 | ||
| 34 | #define DBL_MAX 1.79769313486231570815e+308 | ||
| 35 | #define DBL_EPSILON 2.22044604925031308085e-16 | ||
| 36 | |||
| 37 | #define DBL_MANT_DIG 53 | ||
| 38 | #define DBL_MIN_EXP (-1021) | ||
| 39 | #define DBL_MAX_EXP 1024 | ||
| 40 | #define DBL_HAS_SUBNORM 1 | ||
| 41 | |||
| 42 | #define DBL_DIG 15 | ||
| 43 | #define DBL_DECIMAL_DIG 17 | ||
| 44 | #define DBL_MIN_10_EXP (-307) | ||
| 45 | #define DBL_MAX_10_EXP 308 | ||
| 46 | |||
| 47 | #define LDBL_HAS_SUBNORM 1 | ||
| 48 | #define LDBL_DECIMAL_DIG DECIMAL_DIG | ||
| 49 | |||
| 50 | #include <bits/float.h> | ||
| 51 | |||
| 52 | #ifdef __cplusplus | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #endif | ||
lib/libc/include/wasm-wasi-musl/fts.h deleted-155| ... | @@ -1,155 +0,0 @@ | ||
| 1 | /*	$NetBSD: fts.h,v 1.19 2009/08/16 19:33:38 christos Exp $	*/ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Copyright (c) 1989, 1993 | ||
| 5 | *	The Regents of the University of California. All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * 3. Neither the name of the University nor the names of its contributors | ||
| 16 | * may be used to endorse or promote products derived from this software | ||
| 17 | * without specific prior written permission. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | * SUCH DAMAGE. | ||
| 30 | * | ||
| 31 | *	@(#)fts.h	8.3 (Berkeley) 8/14/94 | ||
| 32 | */ | ||
| 33 | |||
| 34 | #ifndef	_FTS_H_ | ||
| 35 | #define	_FTS_H_ | ||
| 36 | |||
| 37 | #include <stdint.h> | ||
| 38 | #include <sys/types.h> | ||
| 39 | |||
| 40 | #ifndef	__fts_stat_t | ||
| 41 | #define	__fts_stat_t	struct stat | ||
| 42 | #endif | ||
| 43 | #ifndef	__fts_nlink_t | ||
| 44 | #define	__fts_nlink_t	nlink_t | ||
| 45 | #endif | ||
| 46 | #ifndef	__fts_ino_t | ||
| 47 | #define	__fts_ino_t	ino_t | ||
| 48 | #endif | ||
| 49 | #ifndef	__fts_length_t | ||
| 50 | #define	__fts_length_t	unsigned int | ||
| 51 | #endif | ||
| 52 | #ifndef	__fts_number_t | ||
| 53 | #define	__fts_number_t	int64_t | ||
| 54 | #endif | ||
| 55 | #ifndef	__fts_dev_t | ||
| 56 | #define	__fts_dev_t	dev_t | ||
| 57 | #endif | ||
| 58 | #ifndef	__fts_level_t | ||
| 59 | #define	__fts_level_t	int | ||
| 60 | #endif | ||
| 61 | |||
| 62 | typedef struct { | ||
| 63 | 	struct _ftsent *fts_cur;	/* current node */ | ||
| 64 | 	struct _ftsent *fts_child;	/* linked list of children */ | ||
| 65 | 	struct _ftsent **fts_array;	/* sort array */ | ||
| 66 | 	dev_t fts_dev;			/* starting device # */ | ||
| 67 | 	char *fts_path;			/* path for this descent */ | ||
| 68 | 	int fts_rfd;			/* fd for root */ | ||
| 69 | 	unsigned int fts_pathlen;	/* sizeof(path) */ | ||
| 70 | 	unsigned int fts_nitems;	/* elements in the sort array */ | ||
| 71 | 	int (*fts_compar)		/* compare function */ | ||
| 72 | 		(const struct _ftsent **, const struct _ftsent **); | ||
| 73 | |||
| 74 | #define	FTS_COMFOLLOW	0x001		/* follow command line symlinks */ | ||
| 75 | #define	FTS_LOGICAL	0x002		/* logical walk */ | ||
| 76 | #define	FTS_NOCHDIR	0x004		/* don't change directories */ | ||
| 77 | #define	FTS_NOSTAT	0x008		/* don't get stat info */ | ||
| 78 | #define	FTS_PHYSICAL	0x010		/* physical walk */ | ||
| 79 | #define	FTS_SEEDOT	0x020		/* return dot and dot-dot */ | ||
| 80 | #define	FTS_XDEV	0x040		/* don't cross devices */ | ||
| 81 | #define	FTS_WHITEOUT	0x080		/* return whiteout information */ | ||
| 82 | #define	FTS_OPTIONMASK	0x0ff		/* valid user option mask */ | ||
| 83 | |||
| 84 | #define	FTS_NAMEONLY	0x100		/* (private) child names only */ | ||
| 85 | #define	FTS_STOP	0x200		/* (private) unrecoverable error */ | ||
| 86 | 	int fts_options;		/* fts_open options, global flags */ | ||
| 87 | } FTS; | ||
| 88 | |||
| 89 | typedef struct _ftsent { | ||
| 90 | 	struct _ftsent *fts_cycle;	/* cycle node */ | ||
| 91 | 	struct _ftsent *fts_parent;	/* parent directory */ | ||
| 92 | 	struct _ftsent *fts_link;	/* next file in directory */ | ||
| 93 | 	__fts_number_t fts_number; /* local numeric value */ | ||
| 94 | 	void *fts_pointer;	 /* local address value */ | ||
| 95 | 	char *fts_accpath;		/* access path */ | ||
| 96 | 	char *fts_path;			/* root path */ | ||
| 97 | 	int fts_errno;			/* errno for this node */ | ||
| 98 | 	int fts_symfd;			/* fd for symlink */ | ||
| 99 | 	__fts_length_t fts_pathlen;	/* strlen(fts_path) */ | ||
| 100 | 	__fts_length_t fts_namelen;	/* strlen(fts_name) */ | ||
| 101 | |||
| 102 | 	__fts_ino_t fts_ino;		/* inode */ | ||
| 103 | 	__fts_dev_t fts_dev;		/* device */ | ||
| 104 | 	__fts_nlink_t fts_nlink;	/* link count */ | ||
| 105 | |||
| 106 | #define	FTS_ROOTPARENTLEVEL	-1 | ||
| 107 | #define	FTS_ROOTLEVEL		 0 | ||
| 108 | 	__fts_level_t fts_level;		/* depth (-1 to N) */ | ||
| 109 | |||
| 110 | #define	FTS_D		 1		/* preorder directory */ | ||
| 111 | #define	FTS_DC		 2		/* directory that causes cycles */ | ||
| 112 | #define	FTS_DEFAULT	 3		/* none of the above */ | ||
| 113 | #define	FTS_DNR		 4		/* unreadable directory */ | ||
| 114 | #define	FTS_DOT		 5		/* dot or dot-dot */ | ||
| 115 | #define	FTS_DP		 6		/* postorder directory */ | ||
| 116 | #define	FTS_ERR		 7		/* error; errno is set */ | ||
| 117 | #define	FTS_F		 8		/* regular file */ | ||
| 118 | #define	FTS_INIT	 9		/* initialized only */ | ||
| 119 | #define	FTS_NS		10		/* stat(2) failed */ | ||
| 120 | #define	FTS_NSOK	11		/* no stat(2) requested */ | ||
| 121 | #define	FTS_SL		12		/* symbolic link */ | ||
| 122 | #define	FTS_SLNONE	13		/* symbolic link without target */ | ||
| 123 | #define	FTS_W		14		/* whiteout object */ | ||
| 124 | 	unsigned short fts_info;	/* user flags for FTSENT structure */ | ||
| 125 | |||
| 126 | #define	FTS_DONTCHDIR	 0x01		/* don't chdir .. to the parent */ | ||
| 127 | #define	FTS_SYMFOLLOW	 0x02		/* followed a symlink to get here */ | ||
| 128 | #define	FTS_ISW		 0x04		/* this is a whiteout object */ | ||
| 129 | 	unsigned short fts_flags;	/* private flags for FTSENT structure */ | ||
| 130 | |||
| 131 | #define	FTS_AGAIN	 1		/* read node again */ | ||
| 132 | #define	FTS_FOLLOW	 2		/* follow symbolic link */ | ||
| 133 | #define	FTS_NOINSTR	 3		/* no instructions */ | ||
| 134 | #define	FTS_SKIP	 4		/* discard node */ | ||
| 135 | 	unsigned short fts_instr;	/* fts_set() instructions */ | ||
| 136 | |||
| 137 | 	__fts_stat_t *fts_statp;	/* stat(2) information */ | ||
| 138 | 	char fts_name[1];		/* file name */ | ||
| 139 | } FTSENT; | ||
| 140 | |||
| 141 | #ifdef __cplusplus | ||
| 142 | extern "C" { | ||
| 143 | #endif | ||
| 144 | FTSENT	*fts_children(FTS *, int); | ||
| 145 | int	 fts_close(FTS *); | ||
| 146 | FTS	*fts_open(char * const *, int, | ||
| 147 | int (*)(const FTSENT **, const FTSENT **)); | ||
| 148 | FTSENT	*fts_read(FTS *); | ||
| 149 | int	 fts_set(FTS *, FTSENT *, int); | ||
| 150 | #ifdef __cplusplus | ||
| 151 | } | ||
| 152 | #endif | ||
| 153 | |||
| 154 | |||
| 155 | #endif /* !_FTS_H_ */ | ||
lib/libc/include/wasm-wasi-musl/ftw.h deleted-45| ... | @@ -1,45 +0,0 @@ | ||
| 1 | #ifndef _FTW_H | ||
| 2 | #define	_FTW_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <sys/stat.h> | ||
| 10 | |||
| 11 | #define FTW_F 1 | ||
| 12 | #define FTW_D 2 | ||
| 13 | #define FTW_DNR 3 | ||
| 14 | #define FTW_NS 4 | ||
| 15 | #define FTW_SL 5 | ||
| 16 | #define FTW_DP 6 | ||
| 17 | #define FTW_SLN 7 | ||
| 18 | |||
| 19 | #define FTW_PHYS 1 | ||
| 20 | #define FTW_MOUNT 2 | ||
| 21 | #define FTW_CHDIR 4 | ||
| 22 | #define FTW_DEPTH 8 | ||
| 23 | |||
| 24 | struct FTW { | ||
| 25 | 	int base; | ||
| 26 | 	int level; | ||
| 27 | }; | ||
| 28 | |||
| 29 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 30 | int ftw(const char *, int (*)(const char *, const struct stat *, int), int); | ||
| 31 | #endif | ||
| 32 | int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); | ||
| 33 | |||
| 34 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 35 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 36 | #define ftw64 ftw | ||
| 37 | #endif | ||
| 38 | #define nftw64 nftw | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifdef __cplusplus | ||
| 42 | } | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #endif | ||
lib/libc/include/wasm-wasi-musl/glob.h deleted-54| ... | @@ -1,54 +0,0 @@ | ||
| 1 | #ifndef	_GLOB_H | ||
| 2 | #define	_GLOB_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | |||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | typedef struct { | ||
| 15 | 	size_t gl_pathc; | ||
| 16 | 	char **gl_pathv; | ||
| 17 | 	size_t gl_offs; | ||
| 18 | 	int __dummy1; | ||
| 19 | 	void *__dummy2[5]; | ||
| 20 | } glob_t; | ||
| 21 | |||
| 22 | int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); | ||
| 23 | void globfree(glob_t *); | ||
| 24 | |||
| 25 | #define GLOB_ERR 0x01 | ||
| 26 | #define GLOB_MARK 0x02 | ||
| 27 | #define GLOB_NOSORT 0x04 | ||
| 28 | #define GLOB_DOOFFS 0x08 | ||
| 29 | #define GLOB_NOCHECK 0x10 | ||
| 30 | #define GLOB_APPEND 0x20 | ||
| 31 | #define GLOB_NOESCAPE 0x40 | ||
| 32 | #define	GLOB_PERIOD 0x80 | ||
| 33 | |||
| 34 | #ifdef __wasilibc_unmodified_upstream // WASI has no usernames | ||
| 35 | #define GLOB_TILDE 0x1000 | ||
| 36 | #define GLOB_TILDE_CHECK 0x4000 | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #define GLOB_NOSPACE 1 | ||
| 40 | #define GLOB_ABORTED 2 | ||
| 41 | #define GLOB_NOMATCH 3 | ||
| 42 | #define GLOB_NOSYS 4 | ||
| 43 | |||
| 44 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 45 | #define glob64 glob | ||
| 46 | #define globfree64 globfree | ||
| 47 | #define glob64_t glob_t | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #ifdef __cplusplus | ||
| 51 | } | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #endif | ||
lib/libc/include/wasm-wasi-musl/ifaddrs.h deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #ifndef _IFADDRS_H | ||
| 2 | #define _IFADDRS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | #include <sys/socket.h> | ||
| 11 | |||
| 12 | struct ifaddrs { | ||
| 13 | 	struct ifaddrs *ifa_next; | ||
| 14 | 	char *ifa_name; | ||
| 15 | 	unsigned ifa_flags; | ||
| 16 | 	struct sockaddr *ifa_addr; | ||
| 17 | 	struct sockaddr *ifa_netmask; | ||
| 18 | 	union { | ||
| 19 | 		struct sockaddr *ifu_broadaddr; | ||
| 20 | 		struct sockaddr *ifu_dstaddr; | ||
| 21 | 	} ifa_ifu; | ||
| 22 | 	void *ifa_data; | ||
| 23 | }; | ||
| 24 | #define ifa_broadaddr ifa_ifu.ifu_broadaddr | ||
| 25 | #define ifa_dstaddr ifa_ifu.ifu_dstaddr | ||
| 26 | |||
| 27 | void freeifaddrs(struct ifaddrs *); | ||
| 28 | int getifaddrs(struct ifaddrs **); | ||
| 29 | |||
| 30 | #ifdef __cplusplus | ||
| 31 | } | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #endif | ||
| 35 | |||
lib/libc/include/wasm-wasi-musl/inttypes.h deleted-233| ... | @@ -1,233 +0,0 @@ | ||
| 1 | #ifndef _INTTYPES_H | ||
| 2 | #define _INTTYPES_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #ifdef __cplusplus | ||
| 6 | extern "C" { | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include <features.h> | ||
| 10 | #include <stdint.h> | ||
| 11 | |||
| 12 | #define __NEED_wchar_t | ||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | typedef struct { intmax_t quot, rem; } imaxdiv_t; | ||
| 16 | |||
| 17 | intmax_t imaxabs(intmax_t); | ||
| 18 | imaxdiv_t imaxdiv(intmax_t, intmax_t); | ||
| 19 | |||
| 20 | intmax_t strtoimax(const char *__restrict, char **__restrict, int); | ||
| 21 | uintmax_t strtoumax(const char *__restrict, char **__restrict, int); | ||
| 22 | |||
| 23 | intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 24 | uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 25 | |||
| 26 | #if UINTPTR_MAX == UINT64_MAX | ||
| 27 | #define __PRI64 "l" | ||
| 28 | #define __PRIPTR "l" | ||
| 29 | #else | ||
| 30 | #define __PRI64 "ll" | ||
| 31 | #define __PRIPTR "" | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #define PRId8 "d" | ||
| 35 | #define PRId16 "d" | ||
| 36 | #define PRId32 "d" | ||
| 37 | #define PRId64 __PRI64 "d" | ||
| 38 | |||
| 39 | #define PRIdLEAST8 "d" | ||
| 40 | #define PRIdLEAST16 "d" | ||
| 41 | #define PRIdLEAST32 "d" | ||
| 42 | #define PRIdLEAST64 __PRI64 "d" | ||
| 43 | |||
| 44 | #define PRIdFAST8 "d" | ||
| 45 | #define PRIdFAST16 "d" | ||
| 46 | #define PRIdFAST32 "d" | ||
| 47 | #define PRIdFAST64 __PRI64 "d" | ||
| 48 | |||
| 49 | #define PRIi8 "i" | ||
| 50 | #define PRIi16 "i" | ||
| 51 | #define PRIi32 "i" | ||
| 52 | #define PRIi64 __PRI64 "i" | ||
| 53 | |||
| 54 | #define PRIiLEAST8 "i" | ||
| 55 | #define PRIiLEAST16 "i" | ||
| 56 | #define PRIiLEAST32 "i" | ||
| 57 | #define PRIiLEAST64 __PRI64 "i" | ||
| 58 | |||
| 59 | #define PRIiFAST8 "i" | ||
| 60 | #define PRIiFAST16 "i" | ||
| 61 | #define PRIiFAST32 "i" | ||
| 62 | #define PRIiFAST64 __PRI64 "i" | ||
| 63 | |||
| 64 | #define PRIo8 "o" | ||
| 65 | #define PRIo16 "o" | ||
| 66 | #define PRIo32 "o" | ||
| 67 | #define PRIo64 __PRI64 "o" | ||
| 68 | |||
| 69 | #define PRIoLEAST8 "o" | ||
| 70 | #define PRIoLEAST16 "o" | ||
| 71 | #define PRIoLEAST32 "o" | ||
| 72 | #define PRIoLEAST64 __PRI64 "o" | ||
| 73 | |||
| 74 | #define PRIoFAST8 "o" | ||
| 75 | #define PRIoFAST16 "o" | ||
| 76 | #define PRIoFAST32 "o" | ||
| 77 | #define PRIoFAST64 __PRI64 "o" | ||
| 78 | |||
| 79 | #define PRIu8 "u" | ||
| 80 | #define PRIu16 "u" | ||
| 81 | #define PRIu32 "u" | ||
| 82 | #define PRIu64 __PRI64 "u" | ||
| 83 | |||
| 84 | #define PRIuLEAST8 "u" | ||
| 85 | #define PRIuLEAST16 "u" | ||
| 86 | #define PRIuLEAST32 "u" | ||
| 87 | #define PRIuLEAST64 __PRI64 "u" | ||
| 88 | |||
| 89 | #define PRIuFAST8 "u" | ||
| 90 | #define PRIuFAST16 "u" | ||
| 91 | #define PRIuFAST32 "u" | ||
| 92 | #define PRIuFAST64 __PRI64 "u" | ||
| 93 | |||
| 94 | #define PRIx8 "x" | ||
| 95 | #define PRIx16 "x" | ||
| 96 | #define PRIx32 "x" | ||
| 97 | #define PRIx64 __PRI64 "x" | ||
| 98 | |||
| 99 | #define PRIxLEAST8 "x" | ||
| 100 | #define PRIxLEAST16 "x" | ||
| 101 | #define PRIxLEAST32 "x" | ||
| 102 | #define PRIxLEAST64 __PRI64 "x" | ||
| 103 | |||
| 104 | #define PRIxFAST8 "x" | ||
| 105 | #define PRIxFAST16 "x" | ||
| 106 | #define PRIxFAST32 "x" | ||
| 107 | #define PRIxFAST64 __PRI64 "x" | ||
| 108 | |||
| 109 | #define PRIX8 "X" | ||
| 110 | #define PRIX16 "X" | ||
| 111 | #define PRIX32 "X" | ||
| 112 | #define PRIX64 __PRI64 "X" | ||
| 113 | |||
| 114 | #define PRIXLEAST8 "X" | ||
| 115 | #define PRIXLEAST16 "X" | ||
| 116 | #define PRIXLEAST32 "X" | ||
| 117 | #define PRIXLEAST64 __PRI64 "X" | ||
| 118 | |||
| 119 | #define PRIXFAST8 "X" | ||
| 120 | #define PRIXFAST16 "X" | ||
| 121 | #define PRIXFAST32 "X" | ||
| 122 | #define PRIXFAST64 __PRI64 "X" | ||
| 123 | |||
| 124 | #define PRIdMAX __PRI64 "d" | ||
| 125 | #define PRIiMAX __PRI64 "i" | ||
| 126 | #define PRIoMAX __PRI64 "o" | ||
| 127 | #define PRIuMAX __PRI64 "u" | ||
| 128 | #define PRIxMAX __PRI64 "x" | ||
| 129 | #define PRIXMAX __PRI64 "X" | ||
| 130 | |||
| 131 | #define PRIdPTR __PRIPTR "d" | ||
| 132 | #define PRIiPTR __PRIPTR "i" | ||
| 133 | #define PRIoPTR __PRIPTR "o" | ||
| 134 | #define PRIuPTR __PRIPTR "u" | ||
| 135 | #define PRIxPTR __PRIPTR "x" | ||
| 136 | #define PRIXPTR __PRIPTR "X" | ||
| 137 | |||
| 138 | #define SCNd8 "hhd" | ||
| 139 | #define SCNd16 "hd" | ||
| 140 | #define SCNd32 "d" | ||
| 141 | #define SCNd64 __PRI64 "d" | ||
| 142 | |||
| 143 | #define SCNdLEAST8 "hhd" | ||
| 144 | #define SCNdLEAST16 "hd" | ||
| 145 | #define SCNdLEAST32 "d" | ||
| 146 | #define SCNdLEAST64 __PRI64 "d" | ||
| 147 | |||
| 148 | #define SCNdFAST8 "hhd" | ||
| 149 | #define SCNdFAST16 "d" | ||
| 150 | #define SCNdFAST32 "d" | ||
| 151 | #define SCNdFAST64 __PRI64 "d" | ||
| 152 | |||
| 153 | #define SCNi8 "hhi" | ||
| 154 | #define SCNi16 "hi" | ||
| 155 | #define SCNi32 "i" | ||
| 156 | #define SCNi64 __PRI64 "i" | ||
| 157 | |||
| 158 | #define SCNiLEAST8 "hhi" | ||
| 159 | #define SCNiLEAST16 "hi" | ||
| 160 | #define SCNiLEAST32 "i" | ||
| 161 | #define SCNiLEAST64 __PRI64 "i" | ||
| 162 | |||
| 163 | #define SCNiFAST8 "hhi" | ||
| 164 | #define SCNiFAST16 "i" | ||
| 165 | #define SCNiFAST32 "i" | ||
| 166 | #define SCNiFAST64 __PRI64 "i" | ||
| 167 | |||
| 168 | #define SCNu8 "hhu" | ||
| 169 | #define SCNu16 "hu" | ||
| 170 | #define SCNu32 "u" | ||
| 171 | #define SCNu64 __PRI64 "u" | ||
| 172 | |||
| 173 | #define SCNuLEAST8 "hhu" | ||
| 174 | #define SCNuLEAST16 "hu" | ||
| 175 | #define SCNuLEAST32 "u" | ||
| 176 | #define SCNuLEAST64 __PRI64 "u" | ||
| 177 | |||
| 178 | #define SCNuFAST8 "hhu" | ||
| 179 | #define SCNuFAST16 "u" | ||
| 180 | #define SCNuFAST32 "u" | ||
| 181 | #define SCNuFAST64 __PRI64 "u" | ||
| 182 | |||
| 183 | #define SCNo8 "hho" | ||
| 184 | #define SCNo16 "ho" | ||
| 185 | #define SCNo32 "o" | ||
| 186 | #define SCNo64 __PRI64 "o" | ||
| 187 | |||
| 188 | #define SCNoLEAST8 "hho" | ||
| 189 | #define SCNoLEAST16 "ho" | ||
| 190 | #define SCNoLEAST32 "o" | ||
| 191 | #define SCNoLEAST64 __PRI64 "o" | ||
| 192 | |||
| 193 | #define SCNoFAST8 "hho" | ||
| 194 | #define SCNoFAST16 "o" | ||
| 195 | #define SCNoFAST32 "o" | ||
| 196 | #define SCNoFAST64 __PRI64 "o" | ||
| 197 | |||
| 198 | #define SCNx8 "hhx" | ||
| 199 | #define SCNx16 "hx" | ||
| 200 | #define SCNx32 "x" | ||
| 201 | #define SCNx64 __PRI64 "x" | ||
| 202 | |||
| 203 | #define SCNxLEAST8 "hhx" | ||
| 204 | #define SCNxLEAST16 "hx" | ||
| 205 | #define SCNxLEAST32 "x" | ||
| 206 | #define SCNxLEAST64 __PRI64 "x" | ||
| 207 | |||
| 208 | #define SCNxFAST8 "hhx" | ||
| 209 | #define SCNxFAST16 "x" | ||
| 210 | #define SCNxFAST32 "x" | ||
| 211 | #define SCNxFAST64 __PRI64 "x" | ||
| 212 | |||
| 213 | #define SCNdMAX __PRI64 "d" | ||
| 214 | #define SCNiMAX __PRI64 "i" | ||
| 215 | #define SCNoMAX __PRI64 "o" | ||
| 216 | #define SCNuMAX __PRI64 "u" | ||
| 217 | #define SCNxMAX __PRI64 "x" | ||
| 218 | |||
| 219 | #define SCNdPTR __PRIPTR "d" | ||
| 220 | #define SCNiPTR __PRIPTR "i" | ||
| 221 | #define SCNoPTR __PRIPTR "o" | ||
| 222 | #define SCNuPTR __PRIPTR "u" | ||
| 223 | #define SCNxPTR __PRIPTR "x" | ||
| 224 | |||
| 225 | #ifdef __cplusplus | ||
| 226 | } | ||
| 227 | #endif | ||
| 228 | #else | ||
| 229 | #include <__header_inttypes.h> | ||
| 230 | #endif | ||
| 231 | |||
| 232 | #endif | ||
| 233 | |||
lib/libc/include/wasm-wasi-musl/limits.h deleted-178| ... | @@ -1,178 +0,0 @@ | ||
| 1 | #ifndef _LIMITS_H | ||
| 2 | #define _LIMITS_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | #include <bits/alltypes.h> /* __LONG_MAX */ | ||
| 7 | |||
| 8 | /* Support signed or unsigned plain-char */ | ||
| 9 | |||
| 10 | #if '\xff' > 0 | ||
| 11 | #define CHAR_MIN 0 | ||
| 12 | #define CHAR_MAX 255 | ||
| 13 | #else | ||
| 14 | #define CHAR_MIN (-128) | ||
| 15 | #define CHAR_MAX 127 | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #define CHAR_BIT 8 | ||
| 19 | #define SCHAR_MIN (-128) | ||
| 20 | #define SCHAR_MAX 127 | ||
| 21 | #define UCHAR_MAX 255 | ||
| 22 | #define SHRT_MIN (-1-0x7fff) | ||
| 23 | #define SHRT_MAX 0x7fff | ||
| 24 | #define USHRT_MAX 0xffff | ||
| 25 | #define INT_MIN (-1-0x7fffffff) | ||
| 26 | #define INT_MAX 0x7fffffff | ||
| 27 | #define UINT_MAX 0xffffffffU | ||
| 28 | #define LONG_MIN (-LONG_MAX-1) | ||
| 29 | #define LONG_MAX __LONG_MAX | ||
| 30 | #define ULONG_MAX (2UL*LONG_MAX+1) | ||
| 31 | #define LLONG_MIN (-LLONG_MAX-1) | ||
| 32 | #define LLONG_MAX 0x7fffffffffffffffLL | ||
| 33 | #define ULLONG_MAX (2ULL*LLONG_MAX+1) | ||
| 34 | |||
| 35 | #define MB_LEN_MAX 4 | ||
| 36 | |||
| 37 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 38 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 39 | |||
| 40 | #include <bits/limits.h> | ||
| 41 | |||
| 42 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pipes */ | ||
| 43 | #define PIPE_BUF 4096 | ||
| 44 | #endif | ||
| 45 | #define FILESIZEBITS 64 | ||
| 46 | #ifndef NAME_MAX | ||
| 47 | #define NAME_MAX 255 | ||
| 48 | #endif | ||
| 49 | #define PATH_MAX 4096 | ||
| 50 | #define NGROUPS_MAX 32 | ||
| 51 | #define ARG_MAX 131072 | ||
| 52 | #define IOV_MAX 1024 | ||
| 53 | #define SYMLOOP_MAX 40 | ||
| 54 | #define WORD_BIT 32 | ||
| 55 | #define SSIZE_MAX LONG_MAX | ||
| 56 | #define TZNAME_MAX 6 | ||
| 57 | #define TTY_NAME_MAX 32 | ||
| 58 | #define HOST_NAME_MAX 255 | ||
| 59 | |||
| 60 | #if LONG_MAX == 0x7fffffffL | ||
| 61 | #define LONG_BIT 32 | ||
| 62 | #else | ||
| 63 | #define LONG_BIT 64 | ||
| 64 | #endif | ||
| 65 | |||
| 66 | /* Implementation choices... */ | ||
| 67 | |||
| 68 | #define PTHREAD_KEYS_MAX 128 | ||
| 69 | #define PTHREAD_STACK_MIN 2048 | ||
| 70 | #define PTHREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 71 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 72 | #define SEM_VALUE_MAX 0x7fffffff | ||
| 73 | #define SEM_NSEMS_MAX 256 | ||
| 74 | #endif | ||
| 75 | #define DELAYTIMER_MAX 0x7fffffff | ||
| 76 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mq */ | ||
| 77 | #define MQ_PRIO_MAX 32768 | ||
| 78 | #endif | ||
| 79 | #ifdef __wasilibc_unmodified_upstream /* WASI has no usernames */ | ||
| 80 | #define LOGIN_NAME_MAX 256 | ||
| 81 | #endif | ||
| 82 | |||
| 83 | /* Arbitrary numbers... */ | ||
| 84 | |||
| 85 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 86 | #define BC_BASE_MAX 99 | ||
| 87 | #define BC_DIM_MAX 2048 | ||
| 88 | #define BC_SCALE_MAX 99 | ||
| 89 | #define BC_STRING_MAX 1000 | ||
| 90 | #endif | ||
| 91 | #define CHARCLASS_NAME_MAX 14 | ||
| 92 | #define COLL_WEIGHTS_MAX 2 | ||
| 93 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 94 | #define EXPR_NEST_MAX 32 | ||
| 95 | #define LINE_MAX 4096 | ||
| 96 | #endif | ||
| 97 | #define RE_DUP_MAX 255 | ||
| 98 | |||
| 99 | #define NL_ARGMAX 9 | ||
| 100 | #define NL_MSGMAX 32767 | ||
| 101 | #define NL_SETMAX 255 | ||
| 102 | #define NL_TEXTMAX 2048 | ||
| 103 | |||
| 104 | #endif | ||
| 105 | |||
| 106 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) | ||
| 107 | |||
| 108 | #ifdef PAGESIZE | ||
| 109 | #define PAGE_SIZE PAGESIZE | ||
| 110 | #endif | ||
| 111 | #define NZERO 20 | ||
| 112 | #define NL_LANGMAX 32 | ||
| 113 | |||
| 114 | #endif | ||
| 115 | |||
| 116 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 117 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 118 | |||
| 119 | #define NL_NMAX 16 | ||
| 120 | |||
| 121 | #endif | ||
| 122 | |||
| 123 | /* POSIX/SUS requirements follow. These numbers come directly | ||
| 124 | * from SUS and have nothing to do with the host system. */ | ||
| 125 | |||
| 126 | #define _POSIX_AIO_LISTIO_MAX 2 | ||
| 127 | #define _POSIX_AIO_MAX 1 | ||
| 128 | #define _POSIX_ARG_MAX 4096 | ||
| 129 | #define _POSIX_CHILD_MAX 25 | ||
| 130 | #define _POSIX_CLOCKRES_MIN 20000000 | ||
| 131 | #define _POSIX_DELAYTIMER_MAX 32 | ||
| 132 | #define _POSIX_HOST_NAME_MAX 255 | ||
| 133 | #define _POSIX_LINK_MAX 8 | ||
| 134 | #define _POSIX_LOGIN_NAME_MAX 9 | ||
| 135 | #define _POSIX_MAX_CANON 255 | ||
| 136 | #define _POSIX_MAX_INPUT 255 | ||
| 137 | #define _POSIX_MQ_OPEN_MAX 8 | ||
| 138 | #define _POSIX_MQ_PRIO_MAX 32 | ||
| 139 | #define _POSIX_NAME_MAX 14 | ||
| 140 | #define _POSIX_NGROUPS_MAX 8 | ||
| 141 | #define _POSIX_OPEN_MAX 20 | ||
| 142 | #define _POSIX_PATH_MAX 256 | ||
| 143 | #define _POSIX_PIPE_BUF 512 | ||
| 144 | #define _POSIX_RE_DUP_MAX 255 | ||
| 145 | #define _POSIX_RTSIG_MAX 8 | ||
| 146 | #define _POSIX_SEM_NSEMS_MAX 256 | ||
| 147 | #define _POSIX_SEM_VALUE_MAX 32767 | ||
| 148 | #define _POSIX_SIGQUEUE_MAX 32 | ||
| 149 | #define _POSIX_SSIZE_MAX 32767 | ||
| 150 | #define _POSIX_STREAM_MAX 8 | ||
| 151 | #define _POSIX_SS_REPL_MAX 4 | ||
| 152 | #define _POSIX_SYMLINK_MAX 255 | ||
| 153 | #define _POSIX_SYMLOOP_MAX 8 | ||
| 154 | #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 155 | #define _POSIX_THREAD_KEYS_MAX 128 | ||
| 156 | #define _POSIX_THREAD_THREADS_MAX 64 | ||
| 157 | #define _POSIX_TIMER_MAX 32 | ||
| 158 | #define _POSIX_TRACE_EVENT_NAME_MAX 30 | ||
| 159 | #define _POSIX_TRACE_NAME_MAX 8 | ||
| 160 | #define _POSIX_TRACE_SYS_MAX 8 | ||
| 161 | #define _POSIX_TRACE_USER_EVENT_MAX 32 | ||
| 162 | #define _POSIX_TTY_NAME_MAX 9 | ||
| 163 | #define _POSIX_TZNAME_MAX 6 | ||
| 164 | #define _POSIX2_BC_BASE_MAX 99 | ||
| 165 | #define _POSIX2_BC_DIM_MAX 2048 | ||
| 166 | #define _POSIX2_BC_SCALE_MAX 99 | ||
| 167 | #define _POSIX2_BC_STRING_MAX 1000 | ||
| 168 | #define _POSIX2_CHARCLASS_NAME_MAX 14 | ||
| 169 | #define _POSIX2_COLL_WEIGHTS_MAX 2 | ||
| 170 | #define _POSIX2_EXPR_NEST_MAX 32 | ||
| 171 | #define _POSIX2_LINE_MAX 2048 | ||
| 172 | #define _POSIX2_RE_DUP_MAX 255 | ||
| 173 | |||
| 174 | #define _XOPEN_IOV_MAX 16 | ||
| 175 | #define _XOPEN_NAME_MAX 255 | ||
| 176 | #define _XOPEN_PATH_MAX 1024 | ||
| 177 | |||
| 178 | #endif | ||
lib/libc/include/wasm-wasi-musl/locale.h deleted-93| ... | @@ -1,93 +0,0 @@ | ||
| 1 | #ifndef	_LOCALE_H | ||
| 2 | #define	_LOCALE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 11 | #if __cplusplus >= 201103L | ||
| 12 | #define NULL nullptr | ||
| 13 | #elif defined(__cplusplus) | ||
| 14 | #define NULL 0L | ||
| 15 | #else | ||
| 16 | #define NULL ((void*)0) | ||
| 17 | #endif | ||
| 18 | #else | ||
| 19 | #define __need_NULL | ||
| 20 | #include <stddef.h> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #define LC_CTYPE 0 | ||
| 24 | #define LC_NUMERIC 1 | ||
| 25 | #define LC_TIME 2 | ||
| 26 | #define LC_COLLATE 3 | ||
| 27 | #define LC_MONETARY 4 | ||
| 28 | #define LC_MESSAGES 5 | ||
| 29 | #define LC_ALL 6 | ||
| 30 | |||
| 31 | struct lconv { | ||
| 32 | 	char *decimal_point; | ||
| 33 | 	char *thousands_sep; | ||
| 34 | 	char *grouping; | ||
| 35 | |||
| 36 | 	char *int_curr_symbol; | ||
| 37 | 	char *currency_symbol; | ||
| 38 | 	char *mon_decimal_point; | ||
| 39 | 	char *mon_thousands_sep; | ||
| 40 | 	char *mon_grouping; | ||
| 41 | 	char *positive_sign; | ||
| 42 | 	char *negative_sign; | ||
| 43 | 	char int_frac_digits; | ||
| 44 | 	char frac_digits; | ||
| 45 | 	char p_cs_precedes; | ||
| 46 | 	char p_sep_by_space; | ||
| 47 | 	char n_cs_precedes; | ||
| 48 | 	char n_sep_by_space; | ||
| 49 | 	char p_sign_posn; | ||
| 50 | 	char n_sign_posn; | ||
| 51 | 	char int_p_cs_precedes; | ||
| 52 | 	char int_p_sep_by_space; | ||
| 53 | 	char int_n_cs_precedes; | ||
| 54 | 	char int_n_sep_by_space; | ||
| 55 | 	char int_p_sign_posn; | ||
| 56 | 	char int_n_sign_posn; | ||
| 57 | }; | ||
| 58 | |||
| 59 | |||
| 60 | char *setlocale (int, const char *); | ||
| 61 | struct lconv *localeconv(void); | ||
| 62 | |||
| 63 | |||
| 64 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 65 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 66 | |||
| 67 | #define __NEED_locale_t | ||
| 68 | |||
| 69 | #include <bits/alltypes.h> | ||
| 70 | |||
| 71 | #define LC_GLOBAL_LOCALE ((locale_t)-1) | ||
| 72 | |||
| 73 | #define LC_CTYPE_MASK (1<<LC_CTYPE) | ||
| 74 | #define LC_NUMERIC_MASK (1<<LC_NUMERIC) | ||
| 75 | #define LC_TIME_MASK (1<<LC_TIME) | ||
| 76 | #define LC_COLLATE_MASK (1<<LC_COLLATE) | ||
| 77 | #define LC_MONETARY_MASK (1<<LC_MONETARY) | ||
| 78 | #define LC_MESSAGES_MASK (1<<LC_MESSAGES) | ||
| 79 | #define LC_ALL_MASK 0x7fffffff | ||
| 80 | |||
| 81 | locale_t duplocale(locale_t); | ||
| 82 | void freelocale(locale_t); | ||
| 83 | locale_t newlocale(int, const char *, locale_t); | ||
| 84 | locale_t uselocale(locale_t); | ||
| 85 | |||
| 86 | #endif | ||
| 87 | |||
| 88 | |||
| 89 | #ifdef __cplusplus | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #endif | ||
lib/libc/include/wasm-wasi-musl/malloc.h deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 1 | #ifndef _MALLOC_H | ||
| 2 | #define _MALLOC_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__functions_malloc.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #define __NEED_size_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 17 | void *malloc (size_t); | ||
| 18 | void *calloc (size_t, size_t); | ||
| 19 | void *realloc (void *, size_t); | ||
| 20 | void free (void *); | ||
| 21 | #endif | ||
| 22 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 23 | void *valloc (size_t); | ||
| 24 | void *memalign(size_t, size_t); | ||
| 25 | #endif | ||
| 26 | |||
| 27 | size_t malloc_usable_size(void *); | ||
| 28 | |||
| 29 | #ifdef __cplusplus | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #endif | ||
lib/libc/include/wasm-wasi-musl/math.h deleted-459| ... | @@ -1,459 +0,0 @@ | ||
| 1 | #ifndef _MATH_H | ||
| 2 | #define _MATH_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_float_t | ||
| 11 | #define __NEED_double_t | ||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | #if 100*__GNUC__+__GNUC_MINOR__ >= 303 | ||
| 15 | #define NAN __builtin_nanf("") | ||
| 16 | #define INFINITY __builtin_inff() | ||
| 17 | #else | ||
| 18 | #define NAN (0.0f/0.0f) | ||
| 19 | #define INFINITY 1e5000f | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #define HUGE_VALF INFINITY | ||
| 23 | #define HUGE_VAL ((double)INFINITY) | ||
| 24 | #define HUGE_VALL ((long double)INFINITY) | ||
| 25 | |||
| 26 | #define MATH_ERRNO 1 | ||
| 27 | #define MATH_ERREXCEPT 2 | ||
| 28 | #define math_errhandling 2 | ||
| 29 | |||
| 30 | #define FP_ILOGBNAN (-1-0x7fffffff) | ||
| 31 | #define FP_ILOGB0 FP_ILOGBNAN | ||
| 32 | |||
| 33 | #define FP_NAN 0 | ||
| 34 | #define FP_INFINITE 1 | ||
| 35 | #define FP_ZERO 2 | ||
| 36 | #define FP_SUBNORMAL 3 | ||
| 37 | #define FP_NORMAL 4 | ||
| 38 | |||
| 39 | #ifdef __FP_FAST_FMA | ||
| 40 | #define FP_FAST_FMA 1 | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef __FP_FAST_FMAF | ||
| 44 | #define FP_FAST_FMAF 1 | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #ifdef __FP_FAST_FMAL | ||
| 48 | #define FP_FAST_FMAL 1 | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of the fpclassify-like operations */ | ||
| 52 | int __fpclassify(double); | ||
| 53 | int __fpclassifyf(float); | ||
| 54 | int __fpclassifyl(long double); | ||
| 55 | |||
| 56 | static __inline unsigned __FLOAT_BITS(float __f) | ||
| 57 | { | ||
| 58 | 	union {float __f; unsigned __i;} __u; | ||
| 59 | 	__u.__f = __f; | ||
| 60 | 	return __u.__i; | ||
| 61 | } | ||
| 62 | static __inline unsigned long long __DOUBLE_BITS(double __f) | ||
| 63 | { | ||
| 64 | 	union {double __f; unsigned long long __i;} __u; | ||
| 65 | 	__u.__f = __f; | ||
| 66 | 	return __u.__i; | ||
| 67 | } | ||
| 68 | |||
| 69 | #define fpclassify(x) ( \ | ||
| 70 | 	sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ | ||
| 71 | 	sizeof(x) == sizeof(double) ? __fpclassify(x) : \ | ||
| 72 | 	__fpclassifyl(x) ) | ||
| 73 | |||
| 74 | #define isinf(x) ( \ | ||
| 75 | 	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ | ||
| 76 | 	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ | ||
| 77 | 	__fpclassifyl(x) == FP_INFINITE) | ||
| 78 | |||
| 79 | #define isnan(x) ( \ | ||
| 80 | 	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ | ||
| 81 | 	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ | ||
| 82 | 	__fpclassifyl(x) == FP_NAN) | ||
| 83 | |||
| 84 | #define isnormal(x) ( \ | ||
| 85 | 	sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ | ||
| 86 | 	sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ | ||
| 87 | 	__fpclassifyl(x) == FP_NORMAL) | ||
| 88 | |||
| 89 | #define isfinite(x) ( \ | ||
| 90 | 	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ | ||
| 91 | 	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ | ||
| 92 | 	__fpclassifyl(x) > FP_INFINITE) | ||
| 93 | |||
| 94 | int __signbit(double); | ||
| 95 | int __signbitf(float); | ||
| 96 | int __signbitl(long double); | ||
| 97 | |||
| 98 | #define signbit(x) ( \ | ||
| 99 | 	sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ | ||
| 100 | 	sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ | ||
| 101 | 	__signbitl(x) ) | ||
| 102 | |||
| 103 | #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) | ||
| 104 | |||
| 105 | #define __ISREL_DEF(rel, op, type) \ | ||
| 106 | static __inline int __is##rel(type __x, type __y) \ | ||
| 107 | { return !isunordered(__x,__y) && __x op __y; } | ||
| 108 | |||
| 109 | __ISREL_DEF(lessf, <, float_t) | ||
| 110 | __ISREL_DEF(less, <, double_t) | ||
| 111 | __ISREL_DEF(lessl, <, long double) | ||
| 112 | __ISREL_DEF(lessequalf, <=, float_t) | ||
| 113 | __ISREL_DEF(lessequal, <=, double_t) | ||
| 114 | __ISREL_DEF(lessequall, <=, long double) | ||
| 115 | __ISREL_DEF(lessgreaterf, !=, float_t) | ||
| 116 | __ISREL_DEF(lessgreater, !=, double_t) | ||
| 117 | __ISREL_DEF(lessgreaterl, !=, long double) | ||
| 118 | __ISREL_DEF(greaterf, >, float_t) | ||
| 119 | __ISREL_DEF(greater, >, double_t) | ||
| 120 | __ISREL_DEF(greaterl, >, long double) | ||
| 121 | __ISREL_DEF(greaterequalf, >=, float_t) | ||
| 122 | __ISREL_DEF(greaterequal, >=, double_t) | ||
| 123 | __ISREL_DEF(greaterequall, >=, long double) | ||
| 124 | |||
| 125 | #define __tg_pred_2(x, y, p) ( \ | ||
| 126 | 	sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ | ||
| 127 | 	sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ | ||
| 128 | 	p##l(x, y) ) | ||
| 129 | |||
| 130 | #define isless(x, y) __tg_pred_2(x, y, __isless) | ||
| 131 | #define islessequal(x, y) __tg_pred_2(x, y, __islessequal) | ||
| 132 | #define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) | ||
| 133 | #define isgreater(x, y) __tg_pred_2(x, y, __isgreater) | ||
| 134 | #define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) | ||
| 135 | #else | ||
| 136 | #define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, \ | ||
| 137 | FP_NORMAL, FP_SUBNORMAL, \ | ||
| 138 | FP_ZERO, x)) | ||
| 139 | #define isinf(x) (__builtin_isinf(x)) | ||
| 140 | #define isnan(x) (__builtin_isnan(x)) | ||
| 141 | #define isnormal(x) (__builtin_isnormal(x)) | ||
| 142 | #define isfinite(x) (__builtin_isfinite(x)) | ||
| 143 | #define signbit(x) (__builtin_signbit(x)) | ||
| 144 | #define isunordered(x, y) (__builtin_isunordered(x, y)) | ||
| 145 | #define isless(x, y) (__builtin_isless(x, y)) | ||
| 146 | #define islessequal(x, y) (__builtin_islessequal(x, y)) | ||
| 147 | #define islessgreater(x, y) (__builtin_islessgreater(x, y)) | ||
| 148 | #define isgreater(x, y) (__builtin_isgreater(x, y)) | ||
| 149 | #define isgreaterequal(x, y) (__builtin_isgreaterequal(x, y)) | ||
| 150 | #endif | ||
| 151 | |||
| 152 | double acos(double); | ||
| 153 | float acosf(float); | ||
| 154 | long double acosl(long double); | ||
| 155 | |||
| 156 | double acosh(double); | ||
| 157 | float acoshf(float); | ||
| 158 | long double acoshl(long double); | ||
| 159 | |||
| 160 | double asin(double); | ||
| 161 | float asinf(float); | ||
| 162 | long double asinl(long double); | ||
| 163 | |||
| 164 | double asinh(double); | ||
| 165 | float asinhf(float); | ||
| 166 | long double asinhl(long double); | ||
| 167 | |||
| 168 | double atan(double); | ||
| 169 | float atanf(float); | ||
| 170 | long double atanl(long double); | ||
| 171 | |||
| 172 | double atan2(double, double); | ||
| 173 | float atan2f(float, float); | ||
| 174 | long double atan2l(long double, long double); | ||
| 175 | |||
| 176 | double atanh(double); | ||
| 177 | float atanhf(float); | ||
| 178 | long double atanhl(long double); | ||
| 179 | |||
| 180 | double cbrt(double); | ||
| 181 | float cbrtf(float); | ||
| 182 | long double cbrtl(long double); | ||
| 183 | |||
| 184 | double ceil(double); | ||
| 185 | float ceilf(float); | ||
| 186 | long double ceill(long double); | ||
| 187 | |||
| 188 | double copysign(double, double); | ||
| 189 | float copysignf(float, float); | ||
| 190 | long double copysignl(long double, long double); | ||
| 191 | |||
| 192 | double cos(double); | ||
| 193 | float cosf(float); | ||
| 194 | long double cosl(long double); | ||
| 195 | |||
| 196 | double cosh(double); | ||
| 197 | float coshf(float); | ||
| 198 | long double coshl(long double); | ||
| 199 | |||
| 200 | double erf(double); | ||
| 201 | float erff(float); | ||
| 202 | long double erfl(long double); | ||
| 203 | |||
| 204 | double erfc(double); | ||
| 205 | float erfcf(float); | ||
| 206 | long double erfcl(long double); | ||
| 207 | |||
| 208 | double exp(double); | ||
| 209 | float expf(float); | ||
| 210 | long double expl(long double); | ||
| 211 | |||
| 212 | double exp2(double); | ||
| 213 | float exp2f(float); | ||
| 214 | long double exp2l(long double); | ||
| 215 | |||
| 216 | double expm1(double); | ||
| 217 | float expm1f(float); | ||
| 218 | long double expm1l(long double); | ||
| 219 | |||
| 220 | double fabs(double); | ||
| 221 | float fabsf(float); | ||
| 222 | long double fabsl(long double); | ||
| 223 | |||
| 224 | double fdim(double, double); | ||
| 225 | float fdimf(float, float); | ||
| 226 | long double fdiml(long double, long double); | ||
| 227 | |||
| 228 | double floor(double); | ||
| 229 | float floorf(float); | ||
| 230 | long double floorl(long double); | ||
| 231 | |||
| 232 | double fma(double, double, double); | ||
| 233 | float fmaf(float, float, float); | ||
| 234 | long double fmal(long double, long double, long double); | ||
| 235 | |||
| 236 | double fmax(double, double); | ||
| 237 | float fmaxf(float, float); | ||
| 238 | long double fmaxl(long double, long double); | ||
| 239 | |||
| 240 | double fmin(double, double); | ||
| 241 | float fminf(float, float); | ||
| 242 | long double fminl(long double, long double); | ||
| 243 | |||
| 244 | double fmod(double, double); | ||
| 245 | float fmodf(float, float); | ||
| 246 | long double fmodl(long double, long double); | ||
| 247 | |||
| 248 | double frexp(double, int *); | ||
| 249 | float frexpf(float, int *); | ||
| 250 | long double frexpl(long double, int *); | ||
| 251 | |||
| 252 | double hypot(double, double); | ||
| 253 | float hypotf(float, float); | ||
| 254 | long double hypotl(long double, long double); | ||
| 255 | |||
| 256 | int ilogb(double); | ||
| 257 | int ilogbf(float); | ||
| 258 | int ilogbl(long double); | ||
| 259 | |||
| 260 | double ldexp(double, int); | ||
| 261 | float ldexpf(float, int); | ||
| 262 | long double ldexpl(long double, int); | ||
| 263 | |||
| 264 | double lgamma(double); | ||
| 265 | float lgammaf(float); | ||
| 266 | long double lgammal(long double); | ||
| 267 | |||
| 268 | long long llrint(double); | ||
| 269 | long long llrintf(float); | ||
| 270 | long long llrintl(long double); | ||
| 271 | |||
| 272 | long long llround(double); | ||
| 273 | long long llroundf(float); | ||
| 274 | long long llroundl(long double); | ||
| 275 | |||
| 276 | double log(double); | ||
| 277 | float logf(float); | ||
| 278 | long double logl(long double); | ||
| 279 | |||
| 280 | double log10(double); | ||
| 281 | float log10f(float); | ||
| 282 | long double log10l(long double); | ||
| 283 | |||
| 284 | double log1p(double); | ||
| 285 | float log1pf(float); | ||
| 286 | long double log1pl(long double); | ||
| 287 | |||
| 288 | double log2(double); | ||
| 289 | float log2f(float); | ||
| 290 | long double log2l(long double); | ||
| 291 | |||
| 292 | double logb(double); | ||
| 293 | float logbf(float); | ||
| 294 | long double logbl(long double); | ||
| 295 | |||
| 296 | long lrint(double); | ||
| 297 | long lrintf(float); | ||
| 298 | long lrintl(long double); | ||
| 299 | |||
| 300 | long lround(double); | ||
| 301 | long lroundf(float); | ||
| 302 | long lroundl(long double); | ||
| 303 | |||
| 304 | double modf(double, double *); | ||
| 305 | float modff(float, float *); | ||
| 306 | long double modfl(long double, long double *); | ||
| 307 | |||
| 308 | double nan(const char *); | ||
| 309 | float nanf(const char *); | ||
| 310 | long double nanl(const char *); | ||
| 311 | |||
| 312 | double nearbyint(double); | ||
| 313 | float nearbyintf(float); | ||
| 314 | long double nearbyintl(long double); | ||
| 315 | |||
| 316 | double nextafter(double, double); | ||
| 317 | float nextafterf(float, float); | ||
| 318 | long double nextafterl(long double, long double); | ||
| 319 | |||
| 320 | double nexttoward(double, long double); | ||
| 321 | float nexttowardf(float, long double); | ||
| 322 | long double nexttowardl(long double, long double); | ||
| 323 | |||
| 324 | double pow(double, double); | ||
| 325 | float powf(float, float); | ||
| 326 | long double powl(long double, long double); | ||
| 327 | |||
| 328 | double remainder(double, double); | ||
| 329 | float remainderf(float, float); | ||
| 330 | long double remainderl(long double, long double); | ||
| 331 | |||
| 332 | double remquo(double, double, int *); | ||
| 333 | float remquof(float, float, int *); | ||
| 334 | long double remquol(long double, long double, int *); | ||
| 335 | |||
| 336 | double rint(double); | ||
| 337 | float rintf(float); | ||
| 338 | long double rintl(long double); | ||
| 339 | |||
| 340 | double round(double); | ||
| 341 | float roundf(float); | ||
| 342 | long double roundl(long double); | ||
| 343 | |||
| 344 | double scalbln(double, long); | ||
| 345 | float scalblnf(float, long); | ||
| 346 | long double scalblnl(long double, long); | ||
| 347 | |||
| 348 | double scalbn(double, int); | ||
| 349 | float scalbnf(float, int); | ||
| 350 | long double scalbnl(long double, int); | ||
| 351 | |||
| 352 | double sin(double); | ||
| 353 | float sinf(float); | ||
| 354 | long double sinl(long double); | ||
| 355 | |||
| 356 | double sinh(double); | ||
| 357 | float sinhf(float); | ||
| 358 | long double sinhl(long double); | ||
| 359 | |||
| 360 | double sqrt(double); | ||
| 361 | float sqrtf(float); | ||
| 362 | long double sqrtl(long double); | ||
| 363 | |||
| 364 | double tan(double); | ||
| 365 | float tanf(float); | ||
| 366 | long double tanl(long double); | ||
| 367 | |||
| 368 | double tanh(double); | ||
| 369 | float tanhf(float); | ||
| 370 | long double tanhl(long double); | ||
| 371 | |||
| 372 | double tgamma(double); | ||
| 373 | float tgammaf(float); | ||
| 374 | long double tgammal(long double); | ||
| 375 | |||
| 376 | double trunc(double); | ||
| 377 | float truncf(float); | ||
| 378 | long double truncl(long double); | ||
| 379 | |||
| 380 | |||
| 381 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) | ||
| 382 | #undef MAXFLOAT | ||
| 383 | #define MAXFLOAT 3.40282346638528859812e+38F | ||
| 384 | #endif | ||
| 385 | |||
| 386 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 387 | #define M_E 2.7182818284590452354 /* e */ | ||
| 388 | #define M_LOG2E 1.4426950408889634074 /* log_2 e */ | ||
| 389 | #define M_LOG10E 0.43429448190325182765 /* log_10 e */ | ||
| 390 | #define M_LN2 0.69314718055994530942 /* log_e 2 */ | ||
| 391 | #define M_LN10 2.30258509299404568402 /* log_e 10 */ | ||
| 392 | #define M_PI 3.14159265358979323846 /* pi */ | ||
| 393 | #define M_PI_2 1.57079632679489661923 /* pi/2 */ | ||
| 394 | #define M_PI_4 0.78539816339744830962 /* pi/4 */ | ||
| 395 | #define M_1_PI 0.31830988618379067154 /* 1/pi */ | ||
| 396 | #define M_2_PI 0.63661977236758134308 /* 2/pi */ | ||
| 397 | #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ | ||
| 398 | #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | ||
| 399 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ | ||
| 400 | |||
| 401 | extern int signgam; | ||
| 402 | |||
| 403 | double j0(double); | ||
| 404 | double j1(double); | ||
| 405 | double jn(int, double); | ||
| 406 | |||
| 407 | double y0(double); | ||
| 408 | double y1(double); | ||
| 409 | double yn(int, double); | ||
| 410 | #endif | ||
| 411 | |||
| 412 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 413 | #define HUGE 3.40282346638528859812e+38F | ||
| 414 | |||
| 415 | double drem(double, double); | ||
| 416 | float dremf(float, float); | ||
| 417 | |||
| 418 | int finite(double); | ||
| 419 | int finitef(float); | ||
| 420 | |||
| 421 | double scalb(double, double); | ||
| 422 | float scalbf(float, float); | ||
| 423 | |||
| 424 | double significand(double); | ||
| 425 | float significandf(float); | ||
| 426 | |||
| 427 | double lgamma_r(double, int*); | ||
| 428 | float lgammaf_r(float, int*); | ||
| 429 | |||
| 430 | float j0f(float); | ||
| 431 | float j1f(float); | ||
| 432 | float jnf(int, float); | ||
| 433 | |||
| 434 | float y0f(float); | ||
| 435 | float y1f(float); | ||
| 436 | float ynf(int, float); | ||
| 437 | #endif | ||
| 438 | |||
| 439 | #ifdef _GNU_SOURCE | ||
| 440 | long double lgammal_r(long double, int*); | ||
| 441 | |||
| 442 | void sincos(double, double*, double*); | ||
| 443 | void sincosf(float, float*, float*); | ||
| 444 | void sincosl(long double, long double*, long double*); | ||
| 445 | |||
| 446 | double exp10(double); | ||
| 447 | float exp10f(float); | ||
| 448 | long double exp10l(long double); | ||
| 449 | |||
| 450 | double pow10(double); | ||
| 451 | float pow10f(float); | ||
| 452 | long double pow10l(long double); | ||
| 453 | #endif | ||
| 454 | |||
| 455 | #ifdef __cplusplus | ||
| 456 | } | ||
| 457 | #endif | ||
| 458 | |||
| 459 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/in.h deleted-433| ... | @@ -1,433 +0,0 @@ | ||
| 1 | #ifndef	_NETINET_IN_H | ||
| 2 | #define	_NETINET_IN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <inttypes.h> | ||
| 10 | #include <sys/socket.h> | ||
| 11 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 12 | #else | ||
| 13 | #include <__header_netinet_in.h> | ||
| 14 | #endif | ||
| 15 | |||
| 16 | typedef uint16_t in_port_t; | ||
| 17 | typedef uint32_t in_addr_t; | ||
| 18 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 19 | struct in_addr { in_addr_t s_addr; }; | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 23 | struct sockaddr_in { | ||
| 24 | 	sa_family_t sin_family; | ||
| 25 | 	in_port_t sin_port; | ||
| 26 | 	struct in_addr sin_addr; | ||
| 27 | 	uint8_t sin_zero[8]; | ||
| 28 | }; | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 32 | struct in6_addr { | ||
| 33 | 	union { | ||
| 34 | 		uint8_t __s6_addr[16]; | ||
| 35 | 		uint16_t __s6_addr16[8]; | ||
| 36 | 		uint32_t __s6_addr32[4]; | ||
| 37 | 	} __in6_union; | ||
| 38 | }; | ||
| 39 | #define s6_addr __in6_union.__s6_addr | ||
| 40 | #define s6_addr16 __in6_union.__s6_addr16 | ||
| 41 | #define s6_addr32 __in6_union.__s6_addr32 | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 45 | struct sockaddr_in6 { | ||
| 46 | 	sa_family_t sin6_family; | ||
| 47 | 	in_port_t sin6_port; | ||
| 48 | 	uint32_t sin6_flowinfo; | ||
| 49 | 	struct in6_addr sin6_addr; | ||
| 50 | 	uint32_t sin6_scope_id; | ||
| 51 | }; | ||
| 52 | #endif | ||
| 53 | |||
| 54 | struct ipv6_mreq { | ||
| 55 | 	struct in6_addr ipv6mr_multiaddr; | ||
| 56 | 	unsigned ipv6mr_interface; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #define INADDR_ANY ((in_addr_t) 0x00000000) | ||
| 60 | #define INADDR_BROADCAST ((in_addr_t) 0xffffffff) | ||
| 61 | #define INADDR_NONE ((in_addr_t) 0xffffffff) | ||
| 62 | #define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) | ||
| 63 | #define INADDR_DUMMY ((in_addr_t) 0xc0000008) | ||
| 64 | |||
| 65 | #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) | ||
| 66 | #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) | ||
| 67 | #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) | ||
| 68 | #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) | ||
| 69 | #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) | ||
| 70 | |||
| 71 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 72 | #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } | ||
| 73 | #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } | ||
| 74 | #endif | ||
| 75 | |||
| 76 | extern const struct in6_addr in6addr_any, in6addr_loopback; | ||
| 77 | |||
| 78 | #define INET_ADDRSTRLEN 16 | ||
| 79 | #define INET6_ADDRSTRLEN 46 | ||
| 80 | |||
| 81 | uint32_t htonl(uint32_t); | ||
| 82 | uint16_t htons(uint16_t); | ||
| 83 | uint32_t ntohl(uint32_t); | ||
| 84 | uint16_t ntohs(uint16_t); | ||
| 85 | |||
| 86 | #define IPPORT_RESERVED 1024 | ||
| 87 | |||
| 88 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 89 | #define IPPROTO_IP 0 | ||
| 90 | #define IPPROTO_HOPOPTS 0 | ||
| 91 | #define IPPROTO_ICMP 1 | ||
| 92 | #define IPPROTO_IGMP 2 | ||
| 93 | #define IPPROTO_IPIP 4 | ||
| 94 | #define IPPROTO_TCP 6 | ||
| 95 | #define IPPROTO_EGP 8 | ||
| 96 | #define IPPROTO_PUP 12 | ||
| 97 | #define IPPROTO_UDP 17 | ||
| 98 | #define IPPROTO_IDP 22 | ||
| 99 | #define IPPROTO_TP 29 | ||
| 100 | #define IPPROTO_DCCP 33 | ||
| 101 | #define IPPROTO_IPV6 41 | ||
| 102 | #define IPPROTO_ROUTING 43 | ||
| 103 | #define IPPROTO_FRAGMENT 44 | ||
| 104 | #define IPPROTO_RSVP 46 | ||
| 105 | #define IPPROTO_GRE 47 | ||
| 106 | #define IPPROTO_ESP 50 | ||
| 107 | #define IPPROTO_AH 51 | ||
| 108 | #define IPPROTO_ICMPV6 58 | ||
| 109 | #define IPPROTO_NONE 59 | ||
| 110 | #define IPPROTO_DSTOPTS 60 | ||
| 111 | #define IPPROTO_MTP 92 | ||
| 112 | #define IPPROTO_BEETPH 94 | ||
| 113 | #define IPPROTO_ENCAP 98 | ||
| 114 | #define IPPROTO_PIM 103 | ||
| 115 | #define IPPROTO_COMP 108 | ||
| 116 | #define IPPROTO_SCTP 132 | ||
| 117 | #define IPPROTO_MH 135 | ||
| 118 | #define IPPROTO_UDPLITE 136 | ||
| 119 | #define IPPROTO_MPLS 137 | ||
| 120 | #define IPPROTO_ETHERNET 143 | ||
| 121 | #define IPPROTO_RAW 255 | ||
| 122 | #define IPPROTO_MPTCP 262 | ||
| 123 | #define IPPROTO_MAX 263 | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #define IN6_IS_ADDR_UNSPECIFIED(a) \ | ||
| 127 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 128 | ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) | ||
| 129 | |||
| 130 | #define IN6_IS_ADDR_LOOPBACK(a) \ | ||
| 131 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 132 | ((uint32_t *) (a))[2] == 0 && \ | ||
| 133 | ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ | ||
| 134 | ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) | ||
| 135 | |||
| 136 | #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) | ||
| 137 | |||
| 138 | #define IN6_IS_ADDR_LINKLOCAL(a) \ | ||
| 139 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) | ||
| 140 | |||
| 141 | #define IN6_IS_ADDR_SITELOCAL(a) \ | ||
| 142 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) | ||
| 143 | |||
| 144 | #define IN6_IS_ADDR_V4MAPPED(a) \ | ||
| 145 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 146 | ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ | ||
| 147 | ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) | ||
| 148 | |||
| 149 | #define IN6_IS_ADDR_V4COMPAT(a) \ | ||
| 150 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 151 | ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) | ||
| 152 | |||
| 153 | #define IN6_IS_ADDR_MC_NODELOCAL(a) \ | ||
| 154 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) | ||
| 155 | |||
| 156 | #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ | ||
| 157 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) | ||
| 158 | |||
| 159 | #define IN6_IS_ADDR_MC_SITELOCAL(a) \ | ||
| 160 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) | ||
| 161 | |||
| 162 | #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ | ||
| 163 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) | ||
| 164 | |||
| 165 | #define IN6_IS_ADDR_MC_GLOBAL(a) \ | ||
| 166 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) | ||
| 167 | |||
| 168 | #define __ARE_4_EQUAL(a,b) \ | ||
| 169 | 	(!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) | ||
| 170 | #define IN6_ARE_ADDR_EQUAL(a,b) \ | ||
| 171 | 	__ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) | ||
| 172 | |||
| 173 | #define	IN_CLASSA(a)		((((in_addr_t)(a)) & 0x80000000) == 0) | ||
| 174 | #define	IN_CLASSA_NET		0xff000000 | ||
| 175 | #define	IN_CLASSA_NSHIFT	24 | ||
| 176 | #define	IN_CLASSA_HOST		(0xffffffff & ~IN_CLASSA_NET) | ||
| 177 | #define	IN_CLASSA_MAX		128 | ||
| 178 | #define	IN_CLASSB(a)		((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) | ||
| 179 | #define	IN_CLASSB_NET		0xffff0000 | ||
| 180 | #define	IN_CLASSB_NSHIFT	16 | ||
| 181 | #define	IN_CLASSB_HOST		(0xffffffff & ~IN_CLASSB_NET) | ||
| 182 | #define	IN_CLASSB_MAX		65536 | ||
| 183 | #define	IN_CLASSC(a)		((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) | ||
| 184 | #define	IN_CLASSC_NET		0xffffff00 | ||
| 185 | #define	IN_CLASSC_NSHIFT	8 | ||
| 186 | #define	IN_CLASSC_HOST		(0xffffffff & ~IN_CLASSC_NET) | ||
| 187 | #define	IN_CLASSD(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) | ||
| 188 | #define	IN_MULTICAST(a)		IN_CLASSD(a) | ||
| 189 | #define	IN_EXPERIMENTAL(a)	((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) | ||
| 190 | #define	IN_BADCLASS(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) | ||
| 191 | |||
| 192 | #define IN_LOOPBACKNET 127 | ||
| 193 | |||
| 194 | |||
| 195 | #define IP_TOS 1 | ||
| 196 | #define IP_TTL 2 | ||
| 197 | #define IP_HDRINCL 3 | ||
| 198 | #define IP_OPTIONS 4 | ||
| 199 | #define IP_ROUTER_ALERT 5 | ||
| 200 | #define IP_RECVOPTS 6 | ||
| 201 | #define IP_RETOPTS 7 | ||
| 202 | #define IP_PKTINFO 8 | ||
| 203 | #define IP_PKTOPTIONS 9 | ||
| 204 | #define IP_PMTUDISC 10 | ||
| 205 | #define IP_MTU_DISCOVER 10 | ||
| 206 | #define IP_RECVERR 11 | ||
| 207 | #define IP_RECVTTL 12 | ||
| 208 | #define IP_RECVTOS 13 | ||
| 209 | #define IP_MTU 14 | ||
| 210 | #define IP_FREEBIND 15 | ||
| 211 | #define IP_IPSEC_POLICY 16 | ||
| 212 | #define IP_XFRM_POLICY 17 | ||
| 213 | #define IP_PASSSEC 18 | ||
| 214 | #define IP_TRANSPARENT 19 | ||
| 215 | #define IP_ORIGDSTADDR 20 | ||
| 216 | #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR | ||
| 217 | #define IP_MINTTL 21 | ||
| 218 | #define IP_NODEFRAG 22 | ||
| 219 | #define IP_CHECKSUM 23 | ||
| 220 | #define IP_BIND_ADDRESS_NO_PORT 24 | ||
| 221 | #define IP_RECVFRAGSIZE 25 | ||
| 222 | #define IP_RECVERR_RFC4884 26 | ||
| 223 | #define IP_MULTICAST_IF 32 | ||
| 224 | #define IP_MULTICAST_TTL 33 | ||
| 225 | #define IP_MULTICAST_LOOP 34 | ||
| 226 | #define IP_ADD_MEMBERSHIP 35 | ||
| 227 | #define IP_DROP_MEMBERSHIP 36 | ||
| 228 | #define IP_UNBLOCK_SOURCE 37 | ||
| 229 | #define IP_BLOCK_SOURCE 38 | ||
| 230 | #define IP_ADD_SOURCE_MEMBERSHIP 39 | ||
| 231 | #define IP_DROP_SOURCE_MEMBERSHIP 40 | ||
| 232 | #define IP_MSFILTER 41 | ||
| 233 | #define IP_MULTICAST_ALL 49 | ||
| 234 | #define IP_UNICAST_IF 50 | ||
| 235 | |||
| 236 | #define IP_RECVRETOPTS IP_RETOPTS | ||
| 237 | |||
| 238 | #define IP_PMTUDISC_DONT 0 | ||
| 239 | #define IP_PMTUDISC_WANT 1 | ||
| 240 | #define IP_PMTUDISC_DO 2 | ||
| 241 | #define IP_PMTUDISC_PROBE 3 | ||
| 242 | #define IP_PMTUDISC_INTERFACE 4 | ||
| 243 | #define IP_PMTUDISC_OMIT 5 | ||
| 244 | |||
| 245 | #define IP_DEFAULT_MULTICAST_TTL 1 | ||
| 246 | #define IP_DEFAULT_MULTICAST_LOOP 1 | ||
| 247 | #define IP_MAX_MEMBERSHIPS 20 | ||
| 248 | |||
| 249 | struct ip_opts { | ||
| 250 | 	struct in_addr ip_dst; | ||
| 251 | 	char ip_opts[40]; | ||
| 252 | }; | ||
| 253 | |||
| 254 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 255 | |||
| 256 | #define MCAST_JOIN_GROUP 42 | ||
| 257 | #define MCAST_BLOCK_SOURCE 43 | ||
| 258 | #define MCAST_UNBLOCK_SOURCE 44 | ||
| 259 | #define MCAST_LEAVE_GROUP 45 | ||
| 260 | #define MCAST_JOIN_SOURCE_GROUP 46 | ||
| 261 | #define MCAST_LEAVE_SOURCE_GROUP 47 | ||
| 262 | #define MCAST_MSFILTER 48 | ||
| 263 | |||
| 264 | #define MCAST_EXCLUDE 0 | ||
| 265 | #define MCAST_INCLUDE 1 | ||
| 266 | |||
| 267 | struct ip_mreq { | ||
| 268 | 	struct in_addr imr_multiaddr; | ||
| 269 | 	struct in_addr imr_interface; | ||
| 270 | }; | ||
| 271 | |||
| 272 | struct ip_mreqn { | ||
| 273 | 	struct in_addr imr_multiaddr; | ||
| 274 | 	struct in_addr imr_address; | ||
| 275 | 	int imr_ifindex; | ||
| 276 | }; | ||
| 277 | |||
| 278 | struct ip_mreq_source { | ||
| 279 | 	struct in_addr imr_multiaddr; | ||
| 280 | 	struct in_addr imr_interface; | ||
| 281 | 	struct in_addr imr_sourceaddr; | ||
| 282 | }; | ||
| 283 | |||
| 284 | struct ip_msfilter { | ||
| 285 | 	struct in_addr imsf_multiaddr; | ||
| 286 | 	struct in_addr imsf_interface; | ||
| 287 | 	uint32_t imsf_fmode; | ||
| 288 | 	uint32_t imsf_numsrc; | ||
| 289 | 	struct in_addr imsf_slist[1]; | ||
| 290 | }; | ||
| 291 | #define IP_MSFILTER_SIZE(numsrc) \ | ||
| 292 | 	(sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ | ||
| 293 | 	+ (numsrc) * sizeof(struct in_addr)) | ||
| 294 | |||
| 295 | struct group_req { | ||
| 296 | 	uint32_t gr_interface; | ||
| 297 | 	struct sockaddr_storage gr_group; | ||
| 298 | }; | ||
| 299 | |||
| 300 | struct group_source_req { | ||
| 301 | 	uint32_t gsr_interface; | ||
| 302 | 	struct sockaddr_storage gsr_group; | ||
| 303 | 	struct sockaddr_storage gsr_source; | ||
| 304 | }; | ||
| 305 | |||
| 306 | struct group_filter { | ||
| 307 | 	uint32_t gf_interface; | ||
| 308 | 	struct sockaddr_storage gf_group; | ||
| 309 | 	uint32_t gf_fmode; | ||
| 310 | 	uint32_t gf_numsrc; | ||
| 311 | 	struct sockaddr_storage gf_slist[1]; | ||
| 312 | }; | ||
| 313 | #define GROUP_FILTER_SIZE(numsrc) \ | ||
| 314 | 	(sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ | ||
| 315 | 	+ (numsrc) * sizeof(struct sockaddr_storage)) | ||
| 316 | |||
| 317 | struct in_pktinfo { | ||
| 318 | 	int ipi_ifindex; | ||
| 319 | 	struct in_addr ipi_spec_dst; | ||
| 320 | 	struct in_addr ipi_addr; | ||
| 321 | }; | ||
| 322 | |||
| 323 | struct in6_pktinfo { | ||
| 324 | 	struct in6_addr ipi6_addr; | ||
| 325 | 	unsigned ipi6_ifindex; | ||
| 326 | }; | ||
| 327 | |||
| 328 | struct ip6_mtuinfo { | ||
| 329 | 	struct sockaddr_in6 ip6m_addr; | ||
| 330 | 	uint32_t ip6m_mtu; | ||
| 331 | }; | ||
| 332 | #endif | ||
| 333 | |||
| 334 | #define IPV6_ADDRFORM 1 | ||
| 335 | #define IPV6_2292PKTINFO 2 | ||
| 336 | #define IPV6_2292HOPOPTS 3 | ||
| 337 | #define IPV6_2292DSTOPTS 4 | ||
| 338 | #define IPV6_2292RTHDR 5 | ||
| 339 | #define IPV6_2292PKTOPTIONS 6 | ||
| 340 | #define IPV6_CHECKSUM 7 | ||
| 341 | #define IPV6_2292HOPLIMIT 8 | ||
| 342 | #define IPV6_NEXTHOP 9 | ||
| 343 | #define IPV6_AUTHHDR 10 | ||
| 344 | #define IPV6_UNICAST_HOPS 16 | ||
| 345 | #define IPV6_MULTICAST_IF 17 | ||
| 346 | #define IPV6_MULTICAST_HOPS 18 | ||
| 347 | #define IPV6_MULTICAST_LOOP 19 | ||
| 348 | #define IPV6_JOIN_GROUP 20 | ||
| 349 | #define IPV6_LEAVE_GROUP 21 | ||
| 350 | #define IPV6_ROUTER_ALERT 22 | ||
| 351 | #define IPV6_MTU_DISCOVER 23 | ||
| 352 | #define IPV6_MTU 24 | ||
| 353 | #define IPV6_RECVERR 25 | ||
| 354 | #define IPV6_V6ONLY 26 | ||
| 355 | #define IPV6_JOIN_ANYCAST 27 | ||
| 356 | #define IPV6_LEAVE_ANYCAST 28 | ||
| 357 | #define IPV6_MULTICAST_ALL 29 | ||
| 358 | #define IPV6_ROUTER_ALERT_ISOLATE 30 | ||
| 359 | #define IPV6_IPSEC_POLICY 34 | ||
| 360 | #define IPV6_XFRM_POLICY 35 | ||
| 361 | #define IPV6_HDRINCL 36 | ||
| 362 | |||
| 363 | #define IPV6_RECVPKTINFO 49 | ||
| 364 | #define IPV6_PKTINFO 50 | ||
| 365 | #define IPV6_RECVHOPLIMIT 51 | ||
| 366 | #define IPV6_HOPLIMIT 52 | ||
| 367 | #define IPV6_RECVHOPOPTS 53 | ||
| 368 | #define IPV6_HOPOPTS 54 | ||
| 369 | #define IPV6_RTHDRDSTOPTS 55 | ||
| 370 | #define IPV6_RECVRTHDR 56 | ||
| 371 | #define IPV6_RTHDR 57 | ||
| 372 | #define IPV6_RECVDSTOPTS 58 | ||
| 373 | #define IPV6_DSTOPTS 59 | ||
| 374 | #define IPV6_RECVPATHMTU 60 | ||
| 375 | #define IPV6_PATHMTU 61 | ||
| 376 | #define IPV6_DONTFRAG 62 | ||
| 377 | #define IPV6_RECVTCLASS 66 | ||
| 378 | #define IPV6_TCLASS 67 | ||
| 379 | #define IPV6_AUTOFLOWLABEL 70 | ||
| 380 | #define IPV6_ADDR_PREFERENCES 72 | ||
| 381 | #define IPV6_MINHOPCOUNT 73 | ||
| 382 | #define IPV6_ORIGDSTADDR 74 | ||
| 383 | #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR | ||
| 384 | #define IPV6_TRANSPARENT 75 | ||
| 385 | #define IPV6_UNICAST_IF 76 | ||
| 386 | #define IPV6_RECVFRAGSIZE 77 | ||
| 387 | #define IPV6_FREEBIND 78 | ||
| 388 | |||
| 389 | #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP | ||
| 390 | #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP | ||
| 391 | #define IPV6_RXHOPOPTS IPV6_HOPOPTS | ||
| 392 | #define IPV6_RXDSTOPTS IPV6_DSTOPTS | ||
| 393 | |||
| 394 | #define IPV6_PMTUDISC_DONT 0 | ||
| 395 | #define IPV6_PMTUDISC_WANT 1 | ||
| 396 | #define IPV6_PMTUDISC_DO 2 | ||
| 397 | #define IPV6_PMTUDISC_PROBE 3 | ||
| 398 | #define IPV6_PMTUDISC_INTERFACE 4 | ||
| 399 | #define IPV6_PMTUDISC_OMIT 5 | ||
| 400 | |||
| 401 | #define IPV6_PREFER_SRC_TMP 0x0001 | ||
| 402 | #define IPV6_PREFER_SRC_PUBLIC 0x0002 | ||
| 403 | #define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 | ||
| 404 | #define IPV6_PREFER_SRC_COA 0x0004 | ||
| 405 | #define IPV6_PREFER_SRC_HOME 0x0400 | ||
| 406 | #define IPV6_PREFER_SRC_CGA 0x0008 | ||
| 407 | #define IPV6_PREFER_SRC_NONCGA 0x0800 | ||
| 408 | |||
| 409 | #define IPV6_RTHDR_LOOSE 0 | ||
| 410 | #define IPV6_RTHDR_STRICT 1 | ||
| 411 | |||
| 412 | #define IPV6_RTHDR_TYPE_0 0 | ||
| 413 | |||
| 414 | #define __UAPI_DEF_IN_ADDR 0 | ||
| 415 | #define __UAPI_DEF_IN_IPPROTO 0 | ||
| 416 | #define __UAPI_DEF_IN_PKTINFO 0 | ||
| 417 | #define __UAPI_DEF_IP_MREQ 0 | ||
| 418 | #define __UAPI_DEF_SOCKADDR_IN 0 | ||
| 419 | #define __UAPI_DEF_IN_CLASS 0 | ||
| 420 | #define __UAPI_DEF_IN6_ADDR 0 | ||
| 421 | #define __UAPI_DEF_IN6_ADDR_ALT 0 | ||
| 422 | #define __UAPI_DEF_SOCKADDR_IN6 0 | ||
| 423 | #define __UAPI_DEF_IPV6_MREQ 0 | ||
| 424 | #define __UAPI_DEF_IPPROTO_V6 0 | ||
| 425 | #define __UAPI_DEF_IPV6_OPTIONS 0 | ||
| 426 | #define __UAPI_DEF_IN6_PKTINFO 0 | ||
| 427 | #define __UAPI_DEF_IP6_MTUINFO 0 | ||
| 428 | |||
| 429 | #ifdef __cplusplus | ||
| 430 | } | ||
| 431 | #endif | ||
| 432 | |||
| 433 | #endif | ||
lib/libc/include/wasm-wasi-musl/poll.h deleted-69| ... | @@ -1,69 +0,0 @@ | ||
| 1 | #ifndef	_POLL_H | ||
| 2 | #define	_POLL_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #include <bits/poll.h> | ||
| 11 | |||
| 12 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 13 | #define POLLIN 0x001 | ||
| 14 | #define POLLPRI 0x002 | ||
| 15 | #define POLLOUT 0x004 | ||
| 16 | #define POLLERR 0x008 | ||
| 17 | #define POLLHUP 0x010 | ||
| 18 | #define POLLNVAL 0x020 | ||
| 19 | #define POLLRDNORM 0x040 | ||
| 20 | #define POLLRDBAND 0x080 | ||
| 21 | #ifndef POLLWRNORM | ||
| 22 | #define POLLWRNORM 0x100 | ||
| 23 | #define POLLWRBAND 0x200 | ||
| 24 | #endif | ||
| 25 | #ifndef POLLMSG | ||
| 26 | #define POLLMSG 0x400 | ||
| 27 | #define POLLRDHUP 0x2000 | ||
| 28 | #endif | ||
| 29 | #else | ||
| 30 | #include <__header_poll.h> | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 34 | typedef unsigned long nfds_t; | ||
| 35 | #else | ||
| 36 | #include <__typedef_nfds_t.h> | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 40 | struct pollfd { | ||
| 41 | 	int fd; | ||
| 42 | 	short events; | ||
| 43 | 	short revents; | ||
| 44 | }; | ||
| 45 | #else | ||
| 46 | #include <__struct_pollfd.h> | ||
| 47 | #endif | ||
| 48 | |||
| 49 | int poll (struct pollfd *, nfds_t, int); | ||
| 50 | |||
| 51 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 52 | #define __NEED_time_t | ||
| 53 | #define __NEED_struct_timespec | ||
| 54 | #define __NEED_sigset_t | ||
| 55 | #include <bits/alltypes.h> | ||
| 56 | int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #if _REDIR_TIME64 | ||
| 60 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 61 | __REDIR(ppoll, __ppoll_time64); | ||
| 62 | #endif | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | } | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #endif | ||
lib/libc/include/wasm-wasi-musl/pthread.h deleted-267| ... | @@ -1,267 +0,0 @@ | ||
| 1 | #ifndef _PTHREAD_H | ||
| 2 | #define _PTHREAD_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_time_t | ||
| 10 | #define __NEED_clockid_t | ||
| 11 | #define __NEED_struct_timespec | ||
| 12 | #define __NEED_sigset_t | ||
| 13 | #define __NEED_pthread_t | ||
| 14 | #define __NEED_pthread_attr_t | ||
| 15 | #define __NEED_pthread_mutexattr_t | ||
| 16 | #define __NEED_pthread_condattr_t | ||
| 17 | #define __NEED_pthread_rwlockattr_t | ||
| 18 | #define __NEED_pthread_barrierattr_t | ||
| 19 | #define __NEED_pthread_mutex_t | ||
| 20 | #define __NEED_pthread_cond_t | ||
| 21 | #define __NEED_pthread_rwlock_t | ||
| 22 | #define __NEED_pthread_barrier_t | ||
| 23 | #define __NEED_pthread_spinlock_t | ||
| 24 | #define __NEED_pthread_key_t | ||
| 25 | #define __NEED_pthread_once_t | ||
| 26 | #define __NEED_size_t | ||
| 27 | |||
| 28 | #include <bits/alltypes.h> | ||
| 29 | |||
| 30 | #include <sched.h> | ||
| 31 | #include <time.h> | ||
| 32 | |||
| 33 | #define PTHREAD_CREATE_JOINABLE 0 | ||
| 34 | #define PTHREAD_CREATE_DETACHED 1 | ||
| 35 | |||
| 36 | #define PTHREAD_MUTEX_NORMAL 0 | ||
| 37 | #define PTHREAD_MUTEX_DEFAULT 0 | ||
| 38 | #define PTHREAD_MUTEX_RECURSIVE 1 | ||
| 39 | #define PTHREAD_MUTEX_ERRORCHECK 2 | ||
| 40 | |||
| 41 | #define PTHREAD_MUTEX_STALLED 0 | ||
| 42 | #define PTHREAD_MUTEX_ROBUST 1 | ||
| 43 | |||
| 44 | #define PTHREAD_PRIO_NONE 0 | ||
| 45 | #define PTHREAD_PRIO_INHERIT 1 | ||
| 46 | #define PTHREAD_PRIO_PROTECT 2 | ||
| 47 | |||
| 48 | #define PTHREAD_INHERIT_SCHED 0 | ||
| 49 | #define PTHREAD_EXPLICIT_SCHED 1 | ||
| 50 | |||
| 51 | #define PTHREAD_SCOPE_SYSTEM 0 | ||
| 52 | #define PTHREAD_SCOPE_PROCESS 1 | ||
| 53 | |||
| 54 | #define PTHREAD_PROCESS_PRIVATE 0 | ||
| 55 | #define PTHREAD_PROCESS_SHARED 1 | ||
| 56 | |||
| 57 | |||
| 58 | #define PTHREAD_MUTEX_INITIALIZER {{{0}}} | ||
| 59 | #define PTHREAD_RWLOCK_INITIALIZER {{{0}}} | ||
| 60 | #define PTHREAD_COND_INITIALIZER {{{0}}} | ||
| 61 | #define PTHREAD_ONCE_INIT 0 | ||
| 62 | |||
| 63 | |||
| 64 | #define PTHREAD_CANCEL_ENABLE 0 | ||
| 65 | #define PTHREAD_CANCEL_DISABLE 1 | ||
| 66 | #define PTHREAD_CANCEL_MASKED 2 | ||
| 67 | |||
| 68 | #define PTHREAD_CANCEL_DEFERRED 0 | ||
| 69 | #define PTHREAD_CANCEL_ASYNCHRONOUS 1 | ||
| 70 | |||
| 71 | #define PTHREAD_CANCELED ((void *)-1) | ||
| 72 | |||
| 73 | |||
| 74 | #define PTHREAD_BARRIER_SERIAL_THREAD (-1) | ||
| 75 | |||
| 76 | |||
| 77 | #define PTHREAD_NULL ((pthread_t)0) | ||
| 78 | |||
| 79 | |||
| 80 | #ifdef __wasilibc_unmodified_upstream | ||
| 81 | int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); | ||
| 82 | int pthread_detach(pthread_t); | ||
| 83 | _Noreturn void pthread_exit(void *); | ||
| 84 | int pthread_join(pthread_t, void **); | ||
| 85 | #else | ||
| 86 | #if defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 87 | int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); | ||
| 88 | int pthread_detach(pthread_t); | ||
| 89 | int pthread_join(pthread_t, void **); | ||
| 90 | #else | ||
| 91 | #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;}) | ||
| 92 | #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;}) | ||
| 93 | #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;}) | ||
| 94 | #endif | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #ifdef __GNUC__ | ||
| 98 | __attribute__((const)) | ||
| 99 | #endif | ||
| 100 | pthread_t pthread_self(void); | ||
| 101 | |||
| 102 | int pthread_equal(pthread_t, pthread_t); | ||
| 103 | #ifndef __cplusplus | ||
| 104 | #define pthread_equal(x,y) ((x)==(y)) | ||
| 105 | #endif | ||
| 106 | |||
| 107 | int pthread_setcancelstate(int, int *); | ||
| 108 | int pthread_setcanceltype(int, int *); | ||
| 109 | void pthread_testcancel(void); | ||
| 110 | #ifdef __wasilibc_unmodified_upstream /* WASI has no cancellation support. */ | ||
| 111 | int pthread_cancel(pthread_t); | ||
| 112 | #endif | ||
| 113 | |||
| 114 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 115 | int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict); | ||
| 116 | int pthread_setschedparam(pthread_t, int, const struct sched_param *); | ||
| 117 | #endif | ||
| 118 | int pthread_setschedprio(pthread_t, int); | ||
| 119 | |||
| 120 | int pthread_once(pthread_once_t *, void (*)(void)); | ||
| 121 | |||
| 122 | int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict); | ||
| 123 | int pthread_mutex_lock(pthread_mutex_t *); | ||
| 124 | int pthread_mutex_unlock(pthread_mutex_t *); | ||
| 125 | int pthread_mutex_trylock(pthread_mutex_t *); | ||
| 126 | int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict); | ||
| 127 | int pthread_mutex_destroy(pthread_mutex_t *); | ||
| 128 | int pthread_mutex_consistent(pthread_mutex_t *); | ||
| 129 | |||
| 130 | int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict); | ||
| 131 | int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict); | ||
| 132 | |||
| 133 | int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict); | ||
| 134 | int pthread_cond_destroy(pthread_cond_t *); | ||
| 135 | int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict); | ||
| 136 | int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict); | ||
| 137 | int pthread_cond_broadcast(pthread_cond_t *); | ||
| 138 | int pthread_cond_signal(pthread_cond_t *); | ||
| 139 | |||
| 140 | int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict); | ||
| 141 | int pthread_rwlock_destroy(pthread_rwlock_t *); | ||
| 142 | int pthread_rwlock_rdlock(pthread_rwlock_t *); | ||
| 143 | int pthread_rwlock_tryrdlock(pthread_rwlock_t *); | ||
| 144 | int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 145 | int pthread_rwlock_wrlock(pthread_rwlock_t *); | ||
| 146 | int pthread_rwlock_trywrlock(pthread_rwlock_t *); | ||
| 147 | int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 148 | int pthread_rwlock_unlock(pthread_rwlock_t *); | ||
| 149 | |||
| 150 | int pthread_spin_init(pthread_spinlock_t *, int); | ||
| 151 | int pthread_spin_destroy(pthread_spinlock_t *); | ||
| 152 | int pthread_spin_lock(pthread_spinlock_t *); | ||
| 153 | int pthread_spin_trylock(pthread_spinlock_t *); | ||
| 154 | int pthread_spin_unlock(pthread_spinlock_t *); | ||
| 155 | |||
| 156 | int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned); | ||
| 157 | int pthread_barrier_destroy(pthread_barrier_t *); | ||
| 158 | int pthread_barrier_wait(pthread_barrier_t *); | ||
| 159 | |||
| 160 | int pthread_key_create(pthread_key_t *, void (*)(void *)); | ||
| 161 | int pthread_key_delete(pthread_key_t); | ||
| 162 | void *pthread_getspecific(pthread_key_t); | ||
| 163 | int pthread_setspecific(pthread_key_t, const void *); | ||
| 164 | |||
| 165 | int pthread_attr_init(pthread_attr_t *); | ||
| 166 | int pthread_attr_destroy(pthread_attr_t *); | ||
| 167 | |||
| 168 | int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict); | ||
| 169 | int pthread_attr_setguardsize(pthread_attr_t *, size_t); | ||
| 170 | int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict); | ||
| 171 | int pthread_attr_setstacksize(pthread_attr_t *, size_t); | ||
| 172 | int pthread_attr_getdetachstate(const pthread_attr_t *, int *); | ||
| 173 | int pthread_attr_setdetachstate(pthread_attr_t *, int); | ||
| 174 | int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict); | ||
| 175 | int pthread_attr_setstack(pthread_attr_t *, void *, size_t); | ||
| 176 | int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict); | ||
| 177 | int pthread_attr_setscope(pthread_attr_t *, int); | ||
| 178 | int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict); | ||
| 179 | int pthread_attr_setschedpolicy(pthread_attr_t *, int); | ||
| 180 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 181 | int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict); | ||
| 182 | int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict); | ||
| 183 | #endif | ||
| 184 | int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict); | ||
| 185 | int pthread_attr_setinheritsched(pthread_attr_t *, int); | ||
| 186 | |||
| 187 | int pthread_mutexattr_destroy(pthread_mutexattr_t *); | ||
| 188 | int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 189 | int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 190 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 191 | int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 192 | int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 193 | int pthread_mutexattr_init(pthread_mutexattr_t *); | ||
| 194 | int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); | ||
| 195 | int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); | ||
| 196 | int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); | ||
| 197 | int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); | ||
| 198 | int pthread_mutexattr_settype(pthread_mutexattr_t *, int); | ||
| 199 | |||
| 200 | int pthread_condattr_init(pthread_condattr_t *); | ||
| 201 | int pthread_condattr_destroy(pthread_condattr_t *); | ||
| 202 | int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); | ||
| 203 | int pthread_condattr_setpshared(pthread_condattr_t *, int); | ||
| 204 | int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict); | ||
| 205 | int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict); | ||
| 206 | |||
| 207 | int pthread_rwlockattr_init(pthread_rwlockattr_t *); | ||
| 208 | int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); | ||
| 209 | int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); | ||
| 210 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict); | ||
| 211 | |||
| 212 | int pthread_barrierattr_destroy(pthread_barrierattr_t *); | ||
| 213 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict); | ||
| 214 | int pthread_barrierattr_init(pthread_barrierattr_t *); | ||
| 215 | int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); | ||
| 216 | |||
| 217 | int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); | ||
| 218 | |||
| 219 | int pthread_getconcurrency(void); | ||
| 220 | int pthread_setconcurrency(int); | ||
| 221 | |||
| 222 | int pthread_getcpuclockid(pthread_t, clockid_t *); | ||
| 223 | |||
| 224 | struct __ptcb { | ||
| 225 | 	void (*__f)(void *); | ||
| 226 | 	void *__x; | ||
| 227 | 	struct __ptcb *__next; | ||
| 228 | }; | ||
| 229 | |||
| 230 | void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *); | ||
| 231 | void _pthread_cleanup_pop(struct __ptcb *, int); | ||
| 232 | |||
| 233 | #define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); | ||
| 234 | #define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) | ||
| 235 | |||
| 236 | #ifdef _GNU_SOURCE | ||
| 237 | struct cpu_set_t; | ||
| 238 | int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); | ||
| 239 | int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); | ||
| 240 | int pthread_getattr_np(pthread_t, pthread_attr_t *); | ||
| 241 | int pthread_setname_np(pthread_t, const char *); | ||
| 242 | int pthread_getname_np(pthread_t, char *, size_t); | ||
| 243 | int pthread_getattr_default_np(pthread_attr_t *); | ||
| 244 | int pthread_setattr_default_np(const pthread_attr_t *); | ||
| 245 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 246 | int pthread_tryjoin_np(pthread_t, void **); | ||
| 247 | int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); | ||
| 248 | #else | ||
| 249 | #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;}) | ||
| 250 | #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;}) | ||
| 251 | #endif | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #if _REDIR_TIME64 | ||
| 255 | __REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64); | ||
| 256 | __REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64); | ||
| 257 | __REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64); | ||
| 258 | __REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64); | ||
| 259 | #ifdef _GNU_SOURCE | ||
| 260 | __REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64); | ||
| 261 | #endif | ||
| 262 | #endif | ||
| 263 | |||
| 264 | #ifdef __cplusplus | ||
| 265 | } | ||
| 266 | #endif | ||
| 267 | #endif | ||
lib/libc/include/wasm-wasi-musl/sched.h deleted-152| ... | @@ -1,152 +0,0 @@ | ||
| 1 | #ifndef _SCHED_H | ||
| 2 | #define _SCHED_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_struct_timespec | ||
| 10 | #define __NEED_pid_t | ||
| 11 | #define __NEED_time_t | ||
| 12 | |||
| 13 | #ifdef _GNU_SOURCE | ||
| 14 | #define __NEED_size_t | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #include <bits/alltypes.h> | ||
| 18 | |||
| 19 | struct sched_param { | ||
| 20 | 	int sched_priority; | ||
| 21 | 	int __reserved1; | ||
| 22 | #if _REDIR_TIME64 | ||
| 23 | 	long __reserved2[4]; | ||
| 24 | #else | ||
| 25 | 	struct { | ||
| 26 | 		time_t __reserved1; | ||
| 27 | 		long __reserved2; | ||
| 28 | 	} __reserved2[2]; | ||
| 29 | #endif | ||
| 30 | 	int __reserved3; | ||
| 31 | }; | ||
| 32 | |||
| 33 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 34 | int sched_get_priority_max(int); | ||
| 35 | int sched_get_priority_min(int); | ||
| 36 | int sched_getparam(pid_t, struct sched_param *); | ||
| 37 | int sched_getscheduler(pid_t); | ||
| 38 | int sched_rr_get_interval(pid_t, struct timespec *); | ||
| 39 | int sched_setparam(pid_t, const struct sched_param *); | ||
| 40 | int sched_setscheduler(pid_t, int, const struct sched_param *); | ||
| 41 | #endif | ||
| 42 | int sched_yield(void); | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 45 | #define SCHED_OTHER 0 | ||
| 46 | #define SCHED_FIFO 1 | ||
| 47 | #define SCHED_RR 2 | ||
| 48 | #define SCHED_BATCH 3 | ||
| 49 | #define SCHED_IDLE 5 | ||
| 50 | #define SCHED_DEADLINE 6 | ||
| 51 | #define SCHED_RESET_ON_FORK 0x40000000 | ||
| 52 | |||
| 53 | #ifdef _GNU_SOURCE | ||
| 54 | #define CSIGNAL		0x000000ff | ||
| 55 | #define CLONE_NEWTIME	0x00000080 | ||
| 56 | #define CLONE_VM	0x00000100 | ||
| 57 | #define CLONE_FS	0x00000200 | ||
| 58 | #define CLONE_FILES	0x00000400 | ||
| 59 | #define CLONE_SIGHAND	0x00000800 | ||
| 60 | #define CLONE_PIDFD	0x00001000 | ||
| 61 | #define CLONE_PTRACE	0x00002000 | ||
| 62 | #define CLONE_VFORK	0x00004000 | ||
| 63 | #define CLONE_PARENT	0x00008000 | ||
| 64 | #define CLONE_THREAD	0x00010000 | ||
| 65 | #define CLONE_NEWNS	0x00020000 | ||
| 66 | #define CLONE_SYSVSEM	0x00040000 | ||
| 67 | #define CLONE_SETTLS	0x00080000 | ||
| 68 | #define CLONE_PARENT_SETTID	0x00100000 | ||
| 69 | #define CLONE_CHILD_CLEARTID	0x00200000 | ||
| 70 | #define CLONE_DETACHED	0x00400000 | ||
| 71 | #define CLONE_UNTRACED	0x00800000 | ||
| 72 | #define CLONE_CHILD_SETTID	0x01000000 | ||
| 73 | #define CLONE_NEWCGROUP	0x02000000 | ||
| 74 | #define CLONE_NEWUTS	0x04000000 | ||
| 75 | #define CLONE_NEWIPC	0x08000000 | ||
| 76 | #define CLONE_NEWUSER	0x10000000 | ||
| 77 | #define CLONE_NEWPID	0x20000000 | ||
| 78 | #define CLONE_NEWNET	0x40000000 | ||
| 79 | #define CLONE_IO	0x80000000 | ||
| 80 | int clone (int (*)(void *), void *, int, void *, ...); | ||
| 81 | int unshare(int); | ||
| 82 | int setns(int, int); | ||
| 83 | |||
| 84 | void *memcpy(void *__restrict, const void *__restrict, size_t); | ||
| 85 | int memcmp(const void *, const void *, size_t); | ||
| 86 | void *memset (void *, int, size_t); | ||
| 87 | void *calloc(size_t, size_t); | ||
| 88 | void free(void *); | ||
| 89 | |||
| 90 | typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; | ||
| 91 | int __sched_cpucount(size_t, const cpu_set_t *); | ||
| 92 | int sched_getcpu(void); | ||
| 93 | int sched_getaffinity(pid_t, size_t, cpu_set_t *); | ||
| 94 | int sched_setaffinity(pid_t, size_t, const cpu_set_t *); | ||
| 95 | |||
| 96 | #define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ | ||
| 97 | 	(((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) | ||
| 98 | |||
| 99 | #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) | ||
| 100 | #define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) | ||
| 101 | #define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) | ||
| 102 | |||
| 103 | #define __CPU_op_func_S(func, op) \ | ||
| 104 | static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ | ||
| 105 | 	const cpu_set_t *__src1, const cpu_set_t *__src2) \ | ||
| 106 | { \ | ||
| 107 | 	size_t __i; \ | ||
| 108 | 	for (__i=0; __i<__size/sizeof(long); __i++) \ | ||
| 109 | 		((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ | ||
| 110 | 			op ((unsigned long *)__src2)[__i] ; \ | ||
| 111 | } | ||
| 112 | |||
| 113 | __CPU_op_func_S(AND, &) | ||
| 114 | __CPU_op_func_S(OR, |) | ||
| 115 | __CPU_op_func_S(XOR, ^) | ||
| 116 | |||
| 117 | #define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) | ||
| 118 | #define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) | ||
| 119 | #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) | ||
| 120 | |||
| 121 | #define CPU_COUNT_S(size,set) __sched_cpucount(size,set) | ||
| 122 | #define CPU_ZERO_S(size,set) memset(set,0,size) | ||
| 123 | #define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) | ||
| 124 | |||
| 125 | #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ | ||
| 126 | 	+ ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) | ||
| 127 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) | ||
| 128 | #define CPU_FREE(set) free(set) | ||
| 129 | |||
| 130 | #define CPU_SETSIZE 1024 | ||
| 131 | |||
| 132 | #define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) | ||
| 133 | #define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) | ||
| 134 | #define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) | ||
| 135 | #define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) | ||
| 136 | #define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) | ||
| 137 | #define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) | ||
| 138 | #define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) | ||
| 139 | #define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) | ||
| 140 | #define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) | ||
| 141 | |||
| 142 | #endif | ||
| 143 | #endif | ||
| 144 | |||
| 145 | #if _REDIR_TIME64 | ||
| 146 | __REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); | ||
| 147 | #endif | ||
| 148 | |||
| 149 | #ifdef __cplusplus | ||
| 150 | } | ||
| 151 | #endif | ||
| 152 | #endif | ||
lib/libc/include/wasm-wasi-musl/setjmp.h deleted-55| ... | @@ -1,55 +0,0 @@ | ||
| 1 | #ifndef	_SETJMP_H | ||
| 2 | #define	_SETJMP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifndef __wasilibc_unmodified_upstream | ||
| 11 | /* WASI has no setjmp */ | ||
| 12 | #if !defined(__wasm_exception_handling__) | ||
| 13 | #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. | ||
| 14 | #endif | ||
| 15 | #endif | ||
| 16 | #include <bits/setjmp.h> | ||
| 17 | |||
| 18 | typedef struct __jmp_buf_tag { | ||
| 19 | 	__jmp_buf __jb; | ||
| 20 | 	unsigned long __fl; | ||
| 21 | 	unsigned long __ss[128/sizeof(long)]; | ||
| 22 | } jmp_buf[1]; | ||
| 23 | |||
| 24 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) | ||
| 25 | #define __setjmp_attr __attribute__((__returns_twice__)) | ||
| 26 | #else | ||
| 27 | #define __setjmp_attr | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 31 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 32 | || defined(_BSD_SOURCE) | ||
| 33 | typedef jmp_buf sigjmp_buf; | ||
| 34 | int sigsetjmp (sigjmp_buf, int) __setjmp_attr; | ||
| 35 | _Noreturn void siglongjmp (sigjmp_buf, int); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 39 | || defined(_BSD_SOURCE) | ||
| 40 | int _setjmp (jmp_buf) __setjmp_attr; | ||
| 41 | _Noreturn void _longjmp (jmp_buf, int); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | int setjmp (jmp_buf) __setjmp_attr; | ||
| 45 | _Noreturn void longjmp (jmp_buf, int); | ||
| 46 | |||
| 47 | #define setjmp setjmp | ||
| 48 | |||
| 49 | #undef __setjmp_attr | ||
| 50 | |||
| 51 | #ifdef __cplusplus | ||
| 52 | } | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #endif | ||
lib/libc/include/wasm-wasi-musl/signal.h deleted-339| ... | @@ -1,339 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_SIGNAL | ||
| 2 | #error "wasm lacks signal support; to enable minimal signal emulation, \ | ||
| 3 | compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal" | ||
| 4 | #else | ||
| 5 | #ifndef _SIGNAL_H | ||
| 6 | #define _SIGNAL_H | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 15 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 16 | || defined(_BSD_SOURCE) | ||
| 17 | |||
| 18 | #ifdef __wasilibc_unmodified_upstream /* WASI has no ucontext support */ | ||
| 19 | #ifdef _GNU_SOURCE | ||
| 20 | #define __ucontext ucontext | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #define __NEED_size_t | ||
| 24 | #define __NEED_pid_t | ||
| 25 | #define __NEED_uid_t | ||
| 26 | #define __NEED_struct_timespec | ||
| 27 | #define __NEED_pthread_t | ||
| 28 | #define __NEED_pthread_attr_t | ||
| 29 | #define __NEED_time_t | ||
| 30 | #define __NEED_clock_t | ||
| 31 | #define __NEED_sigset_t | ||
| 32 | |||
| 33 | #include <bits/alltypes.h> | ||
| 34 | |||
| 35 | #define SIG_BLOCK 0 | ||
| 36 | #define SIG_UNBLOCK 1 | ||
| 37 | #define SIG_SETMASK 2 | ||
| 38 | |||
| 39 | #define SI_ASYNCNL (-60) | ||
| 40 | #define SI_TKILL (-6) | ||
| 41 | #define SI_SIGIO (-5) | ||
| 42 | #define SI_ASYNCIO (-4) | ||
| 43 | #define SI_MESGQ (-3) | ||
| 44 | #define SI_TIMER (-2) | ||
| 45 | #define SI_QUEUE (-1) | ||
| 46 | #define SI_USER 0 | ||
| 47 | #define SI_KERNEL 128 | ||
| 48 | |||
| 49 | typedef struct sigaltstack stack_t; | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #endif | ||
| 53 | |||
| 54 | #include <bits/signal.h> | ||
| 55 | |||
| 56 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 57 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 58 | || defined(_BSD_SOURCE) | ||
| 59 | |||
| 60 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ | ||
| 61 | #define SIG_HOLD ((void (*)(int)) 2) | ||
| 62 | |||
| 63 | #define FPE_INTDIV 1 | ||
| 64 | #define FPE_INTOVF 2 | ||
| 65 | #define FPE_FLTDIV 3 | ||
| 66 | #define FPE_FLTOVF 4 | ||
| 67 | #define FPE_FLTUND 5 | ||
| 68 | #define FPE_FLTRES 6 | ||
| 69 | #define FPE_FLTINV 7 | ||
| 70 | #define FPE_FLTSUB 8 | ||
| 71 | |||
| 72 | #define ILL_ILLOPC 1 | ||
| 73 | #define ILL_ILLOPN 2 | ||
| 74 | #define ILL_ILLADR 3 | ||
| 75 | #define ILL_ILLTRP 4 | ||
| 76 | #define ILL_PRVOPC 5 | ||
| 77 | #define ILL_PRVREG 6 | ||
| 78 | #define ILL_COPROC 7 | ||
| 79 | #define ILL_BADSTK 8 | ||
| 80 | |||
| 81 | #define SEGV_MAPERR 1 | ||
| 82 | #define SEGV_ACCERR 2 | ||
| 83 | #define SEGV_BNDERR 3 | ||
| 84 | #define SEGV_PKUERR 4 | ||
| 85 | #define SEGV_MTEAERR 8 | ||
| 86 | #define SEGV_MTESERR 9 | ||
| 87 | |||
| 88 | #define BUS_ADRALN 1 | ||
| 89 | #define BUS_ADRERR 2 | ||
| 90 | #define BUS_OBJERR 3 | ||
| 91 | #define BUS_MCEERR_AR 4 | ||
| 92 | #define BUS_MCEERR_AO 5 | ||
| 93 | |||
| 94 | #define CLD_EXITED 1 | ||
| 95 | #define CLD_KILLED 2 | ||
| 96 | #define CLD_DUMPED 3 | ||
| 97 | #define CLD_TRAPPED 4 | ||
| 98 | #define CLD_STOPPED 5 | ||
| 99 | #define CLD_CONTINUED 6 | ||
| 100 | |||
| 101 | union sigval { | ||
| 102 | 	int sival_int; | ||
| 103 | 	void *sival_ptr; | ||
| 104 | }; | ||
| 105 | |||
| 106 | typedef struct { | ||
| 107 | #ifdef __SI_SWAP_ERRNO_CODE | ||
| 108 | 	int si_signo, si_code, si_errno; | ||
| 109 | #else | ||
| 110 | 	int si_signo, si_errno, si_code; | ||
| 111 | #endif | ||
| 112 | 	union { | ||
| 113 | 		char __pad[128 - 2*sizeof(int) - sizeof(long)]; | ||
| 114 | 		struct { | ||
| 115 | 			union { | ||
| 116 | 				struct { | ||
| 117 | 					pid_t si_pid; | ||
| 118 | 					uid_t si_uid; | ||
| 119 | 				} __piduid; | ||
| 120 | 				struct { | ||
| 121 | 					int si_timerid; | ||
| 122 | 					int si_overrun; | ||
| 123 | 				} __timer; | ||
| 124 | 			} __first; | ||
| 125 | 			union { | ||
| 126 | 				union sigval si_value; | ||
| 127 | 				struct { | ||
| 128 | 					int si_status; | ||
| 129 | 					clock_t si_utime, si_stime; | ||
| 130 | 				} __sigchld; | ||
| 131 | 			} __second; | ||
| 132 | 		} __si_common; | ||
| 133 | 		struct { | ||
| 134 | 			void *si_addr; | ||
| 135 | 			short si_addr_lsb; | ||
| 136 | 			union { | ||
| 137 | 				struct { | ||
| 138 | 					void *si_lower; | ||
| 139 | 					void *si_upper; | ||
| 140 | 				} __addr_bnd; | ||
| 141 | 				unsigned si_pkey; | ||
| 142 | 			} __first; | ||
| 143 | 		} __sigfault; | ||
| 144 | 		struct { | ||
| 145 | 			long si_band; | ||
| 146 | 			int si_fd; | ||
| 147 | 		} __sigpoll; | ||
| 148 | 		struct { | ||
| 149 | 			void *si_call_addr; | ||
| 150 | 			int si_syscall; | ||
| 151 | 			unsigned si_arch; | ||
| 152 | 		} __sigsys; | ||
| 153 | 	} __si_fields; | ||
| 154 | } siginfo_t; | ||
| 155 | #define si_pid __si_fields.__si_common.__first.__piduid.si_pid | ||
| 156 | #define si_uid __si_fields.__si_common.__first.__piduid.si_uid | ||
| 157 | #define si_status __si_fields.__si_common.__second.__sigchld.si_status | ||
| 158 | #define si_utime __si_fields.__si_common.__second.__sigchld.si_utime | ||
| 159 | #define si_stime __si_fields.__si_common.__second.__sigchld.si_stime | ||
| 160 | #define si_value __si_fields.__si_common.__second.si_value | ||
| 161 | #define si_addr __si_fields.__sigfault.si_addr | ||
| 162 | #define si_addr_lsb __si_fields.__sigfault.si_addr_lsb | ||
| 163 | #define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower | ||
| 164 | #define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper | ||
| 165 | #define si_pkey __si_fields.__sigfault.__first.si_pkey | ||
| 166 | #define si_band __si_fields.__sigpoll.si_band | ||
| 167 | #define si_fd __si_fields.__sigpoll.si_fd | ||
| 168 | #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid | ||
| 169 | #define si_overrun __si_fields.__si_common.__first.__timer.si_overrun | ||
| 170 | #define si_ptr si_value.sival_ptr | ||
| 171 | #define si_int si_value.sival_int | ||
| 172 | #define si_call_addr __si_fields.__sigsys.si_call_addr | ||
| 173 | #define si_syscall __si_fields.__sigsys.si_syscall | ||
| 174 | #define si_arch __si_fields.__sigsys.si_arch | ||
| 175 | |||
| 176 | struct sigaction { | ||
| 177 | 	union { | ||
| 178 | 		void (*sa_handler)(int); | ||
| 179 | 		void (*sa_sigaction)(int, siginfo_t *, void *); | ||
| 180 | 	} __sa_handler; | ||
| 181 | 	sigset_t sa_mask; | ||
| 182 | 	int sa_flags; | ||
| 183 | 	void (*sa_restorer)(void); | ||
| 184 | }; | ||
| 185 | #define sa_handler __sa_handler.sa_handler | ||
| 186 | #define sa_sigaction __sa_handler.sa_sigaction | ||
| 187 | |||
| 188 | #define SA_UNSUPPORTED 0x00000400 | ||
| 189 | #define SA_EXPOSE_TAGBITS 0x00000800 | ||
| 190 | |||
| 191 | struct sigevent { | ||
| 192 | 	union sigval sigev_value; | ||
| 193 | 	int sigev_signo; | ||
| 194 | 	int sigev_notify; | ||
| 195 | 	union { | ||
| 196 | 		char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; | ||
| 197 | 		pid_t sigev_notify_thread_id; | ||
| 198 | 		struct { | ||
| 199 | 			void (*sigev_notify_function)(union sigval); | ||
| 200 | 			pthread_attr_t *sigev_notify_attributes; | ||
| 201 | 		} __sev_thread; | ||
| 202 | 	} __sev_fields; | ||
| 203 | }; | ||
| 204 | |||
| 205 | #define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id | ||
| 206 | #define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function | ||
| 207 | #define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes | ||
| 208 | |||
| 209 | #define SIGEV_SIGNAL 0 | ||
| 210 | #define SIGEV_NONE 1 | ||
| 211 | #define SIGEV_THREAD 2 | ||
| 212 | #define SIGEV_THREAD_ID 4 | ||
| 213 | #endif | ||
| 214 | |||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ | ||
| 216 | int __libc_current_sigrtmin(void); | ||
| 217 | int __libc_current_sigrtmax(void); | ||
| 218 | |||
| 219 | #define SIGRTMIN (__libc_current_sigrtmin()) | ||
| 220 | #define SIGRTMAX (__libc_current_sigrtmax()) | ||
| 221 | #endif | ||
| 222 | |||
| 223 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 224 | int kill(pid_t, int); | ||
| 225 | |||
| 226 | int sigemptyset(sigset_t *); | ||
| 227 | int sigfillset(sigset_t *); | ||
| 228 | int sigaddset(sigset_t *, int); | ||
| 229 | int sigdelset(sigset_t *, int); | ||
| 230 | int sigismember(const sigset_t *, int); | ||
| 231 | |||
| 232 | int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 233 | int sigsuspend(const sigset_t *); | ||
| 234 | int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); | ||
| 235 | int sigpending(sigset_t *); | ||
| 236 | int sigwait(const sigset_t *__restrict, int *__restrict); | ||
| 237 | int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); | ||
| 238 | int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); | ||
| 239 | int sigqueue(pid_t, int, union sigval); | ||
| 240 | #endif | ||
| 241 | |||
| 242 | #ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ | ||
| 243 | int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 244 | int pthread_kill(pthread_t, int); | ||
| 245 | #endif | ||
| 246 | |||
| 247 | #ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ | ||
| 248 | void psiginfo(const siginfo_t *, const char *); | ||
| 249 | #endif | ||
| 250 | void psignal(int, const char *); | ||
| 251 | |||
| 252 | #endif | ||
| 253 | |||
| 254 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 255 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 256 | int killpg(pid_t, int); | ||
| 257 | int sigaltstack(const stack_t *__restrict, stack_t *__restrict); | ||
| 258 | int sighold(int); | ||
| 259 | int sigignore(int); | ||
| 260 | int siginterrupt(int, int); | ||
| 261 | int sigpause(int); | ||
| 262 | int sigrelse(int); | ||
| 263 | void (*sigset(int, void (*)(int)))(int); | ||
| 264 | #define TRAP_BRKPT 1 | ||
| 265 | #define TRAP_TRACE 2 | ||
| 266 | #define TRAP_BRANCH 3 | ||
| 267 | #define TRAP_HWBKPT 4 | ||
| 268 | #define TRAP_UNK 5 | ||
| 269 | #define POLL_IN 1 | ||
| 270 | #define POLL_OUT 2 | ||
| 271 | #define POLL_MSG 3 | ||
| 272 | #define POLL_ERR 4 | ||
| 273 | #define POLL_PRI 5 | ||
| 274 | #define POLL_HUP 6 | ||
| 275 | #define SS_ONSTACK 1 | ||
| 276 | #define SS_DISABLE 2 | ||
| 277 | #define SS_AUTODISARM (1U << 31) | ||
| 278 | #define SS_FLAG_BITS SS_AUTODISARM | ||
| 279 | #endif | ||
| 280 | #endif | ||
| 281 | |||
| 282 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 283 | #define NSIG _NSIG | ||
| 284 | typedef void (*sig_t)(int); | ||
| 285 | |||
| 286 | #define SYS_SECCOMP 1 | ||
| 287 | #define SYS_USER_DISPATCH 2 | ||
| 288 | #endif | ||
| 289 | |||
| 290 | #ifdef _GNU_SOURCE | ||
| 291 | typedef void (*sighandler_t)(int); | ||
| 292 | void (*bsd_signal(int, void (*)(int)))(int); | ||
| 293 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ | ||
| 294 | int sigisemptyset(const sigset_t *); | ||
| 295 | int sigorset (sigset_t *, const sigset_t *, const sigset_t *); | ||
| 296 | int sigandset(sigset_t *, const sigset_t *, const sigset_t *); | ||
| 297 | |||
| 298 | #define SA_NOMASK SA_NODEFER | ||
| 299 | #define SA_ONESHOT SA_RESETHAND | ||
| 300 | #endif | ||
| 301 | #endif | ||
| 302 | |||
| 303 | #ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ | ||
| 304 | #define SIG_ERR ((void (*)(int))-1) | ||
| 305 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 306 | #define SIG_IGN ((void (*)(int)) 1) | ||
| 307 | #else | ||
| 308 | void __SIG_ERR(int); | ||
| 309 | void __SIG_IGN(int); | ||
| 310 | #define SIG_ERR (__SIG_ERR) | ||
| 311 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 312 | #define SIG_IGN (__SIG_IGN) | ||
| 313 | #endif | ||
| 314 | |||
| 315 | #ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ | ||
| 316 | typedef int sig_atomic_t; | ||
| 317 | #else | ||
| 318 | typedef long sig_atomic_t; | ||
| 319 | #endif | ||
| 320 | |||
| 321 | void (*signal(int, void (*)(int)))(int); | ||
| 322 | int raise(int); | ||
| 323 | |||
| 324 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ | ||
| 325 | #if _REDIR_TIME64 | ||
| 326 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 327 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 328 | || defined(_BSD_SOURCE) | ||
| 329 | __REDIR(sigtimedwait, __sigtimedwait_time64); | ||
| 330 | #endif | ||
| 331 | #endif | ||
| 332 | #endif | ||
| 333 | |||
| 334 | #ifdef __cplusplus | ||
| 335 | } | ||
| 336 | #endif | ||
| 337 | |||
| 338 | #endif | ||
| 339 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdio.h deleted-254| ... | @@ -1,254 +0,0 @@ | ||
| 1 | #ifndef _STDIO_H | ||
| 2 | #define _STDIO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_FILE | ||
| 11 | #define __NEED___isoc_va_list | ||
| 12 | #define __NEED_size_t | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 15 | #if __STDC_VERSION__ < 201112L | ||
| 16 | #define __NEED_struct__IO_FILE | ||
| 17 | #endif | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 21 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 22 | || defined(_BSD_SOURCE) | ||
| 23 | #define __NEED_ssize_t | ||
| 24 | #define __NEED_off_t | ||
| 25 | #define __NEED_va_list | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #include <bits/alltypes.h> | ||
| 29 | |||
| 30 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 31 | #if __cplusplus >= 201103L | ||
| 32 | #define NULL nullptr | ||
| 33 | #elif defined(__cplusplus) | ||
| 34 | #define NULL 0L | ||
| 35 | #else | ||
| 36 | #define NULL ((void*)0) | ||
| 37 | #endif | ||
| 38 | #else | ||
| 39 | #define __need_NULL | ||
| 40 | #include <stddef.h> | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #undef EOF | ||
| 44 | #define EOF (-1) | ||
| 45 | |||
| 46 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 47 | #undef SEEK_SET | ||
| 48 | #undef SEEK_CUR | ||
| 49 | #undef SEEK_END | ||
| 50 | #define SEEK_SET 0 | ||
| 51 | #define SEEK_CUR 1 | ||
| 52 | #define SEEK_END 2 | ||
| 53 | #else | ||
| 54 | #include <__seek.h> | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #define _IOFBF 0 | ||
| 58 | #define _IOLBF 1 | ||
| 59 | #define _IONBF 2 | ||
| 60 | |||
| 61 | #define BUFSIZ 1024 | ||
| 62 | #define FILENAME_MAX 4096 | ||
| 63 | #define FOPEN_MAX 1000 | ||
| 64 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 65 | #define TMP_MAX 10000 | ||
| 66 | #define L_tmpnam 20 | ||
| 67 | #endif | ||
| 68 | |||
| 69 | typedef union _G_fpos64_t { | ||
| 70 | 	char __opaque[16]; | ||
| 71 | 	long long __lldata; | ||
| 72 | 	double __align; | ||
| 73 | } fpos_t; | ||
| 74 | |||
| 75 | extern FILE *const stdin; | ||
| 76 | extern FILE *const stdout; | ||
| 77 | extern FILE *const stderr; | ||
| 78 | |||
| 79 | #define stdin (stdin) | ||
| 80 | #define stdout (stdout) | ||
| 81 | #define stderr (stderr) | ||
| 82 | |||
| 83 | FILE *fopen(const char *__restrict, const char *__restrict); | ||
| 84 | FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); | ||
| 85 | int fclose(FILE *); | ||
| 86 | |||
| 87 | int remove(const char *); | ||
| 88 | int rename(const char *, const char *); | ||
| 89 | |||
| 90 | int feof(FILE *); | ||
| 91 | int ferror(FILE *); | ||
| 92 | int fflush(FILE *); | ||
| 93 | void clearerr(FILE *); | ||
| 94 | |||
| 95 | int fseek(FILE *, long, int); | ||
| 96 | long ftell(FILE *); | ||
| 97 | void rewind(FILE *); | ||
| 98 | |||
| 99 | int fgetpos(FILE *__restrict, fpos_t *__restrict); | ||
| 100 | int fsetpos(FILE *, const fpos_t *); | ||
| 101 | |||
| 102 | size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 103 | size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 104 | |||
| 105 | int fgetc(FILE *); | ||
| 106 | int getc(FILE *); | ||
| 107 | int getchar(void); | ||
| 108 | int ungetc(int, FILE *); | ||
| 109 | |||
| 110 | int fputc(int, FILE *); | ||
| 111 | int putc(int, FILE *); | ||
| 112 | int putchar(int); | ||
| 113 | |||
| 114 | char *fgets(char *__restrict, int, FILE *__restrict); | ||
| 115 | #if __STDC_VERSION__ < 201112L | ||
| 116 | #ifdef __wasilibc_unmodified_upstream /* gets is obsolete */ | ||
| 117 | char *gets(char *); | ||
| 118 | #else | ||
| 119 | char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI"))); | ||
| 120 | #endif | ||
| 121 | #endif | ||
| 122 | |||
| 123 | int fputs(const char *__restrict, FILE *__restrict); | ||
| 124 | int puts(const char *); | ||
| 125 | |||
| 126 | int printf(const char *__restrict, ...); | ||
| 127 | int fprintf(FILE *__restrict, const char *__restrict, ...); | ||
| 128 | int sprintf(char *__restrict, const char *__restrict, ...); | ||
| 129 | int snprintf(char *__restrict, size_t, const char *__restrict, ...); | ||
| 130 | |||
| 131 | int vprintf(const char *__restrict, __isoc_va_list); | ||
| 132 | int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 133 | int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 134 | int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); | ||
| 135 | |||
| 136 | int scanf(const char *__restrict, ...); | ||
| 137 | int fscanf(FILE *__restrict, const char *__restrict, ...); | ||
| 138 | int sscanf(const char *__restrict, const char *__restrict, ...); | ||
| 139 | int vscanf(const char *__restrict, __isoc_va_list); | ||
| 140 | int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 141 | int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 142 | |||
| 143 | void perror(const char *); | ||
| 144 | |||
| 145 | int setvbuf(FILE *__restrict, char *__restrict, int, size_t); | ||
| 146 | void setbuf(FILE *__restrict, char *__restrict); | ||
| 147 | |||
| 148 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 149 | char *tmpnam(char *); | ||
| 150 | FILE *tmpfile(void); | ||
| 151 | #else | ||
| 152 | char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI"))); | ||
| 153 | FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI"))); | ||
| 154 | #endif | ||
| 155 | |||
| 156 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 157 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 158 | || defined(_BSD_SOURCE) | ||
| 159 | FILE *fmemopen(void *__restrict, size_t, const char *__restrict); | ||
| 160 | FILE *open_memstream(char **, size_t *); | ||
| 161 | FILE *fdopen(int, const char *); | ||
| 162 | #ifdef __wasilibc_unmodified_upstream /* WASI has no popen */ | ||
| 163 | FILE *popen(const char *, const char *); | ||
| 164 | int pclose(FILE *); | ||
| 165 | #endif | ||
| 166 | int fileno(FILE *); | ||
| 167 | int fseeko(FILE *, off_t, int); | ||
| 168 | off_t ftello(FILE *); | ||
| 169 | int dprintf(int, const char *__restrict, ...); | ||
| 170 | int vdprintf(int, const char *__restrict, __isoc_va_list); | ||
| 171 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 172 | void flockfile(FILE *); | ||
| 173 | int ftrylockfile(FILE *); | ||
| 174 | void funlockfile(FILE *); | ||
| 175 | #endif | ||
| 176 | int getc_unlocked(FILE *); | ||
| 177 | int getchar_unlocked(void); | ||
| 178 | int putc_unlocked(int, FILE *); | ||
| 179 | int putchar_unlocked(int); | ||
| 180 | ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); | ||
| 181 | ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); | ||
| 182 | int renameat(int, const char *, int, const char *); | ||
| 183 | char *ctermid(char *); | ||
| 184 | #define L_ctermid 20 | ||
| 185 | #endif | ||
| 186 | |||
| 187 | |||
| 188 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 189 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 190 | || defined(_BSD_SOURCE) | ||
| 191 | #define P_tmpdir "/tmp" | ||
| 192 | char *tempnam(const char *, const char *); | ||
| 193 | #endif | ||
| 194 | #endif | ||
| 195 | |||
| 196 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 197 | #define L_cuserid 20 | ||
| 198 | char *cuserid(char *); | ||
| 199 | void setlinebuf(FILE *); | ||
| 200 | void setbuffer(FILE *, char *, size_t); | ||
| 201 | int fgetc_unlocked(FILE *); | ||
| 202 | int fputc_unlocked(int, FILE *); | ||
| 203 | int fflush_unlocked(FILE *); | ||
| 204 | size_t fread_unlocked(void *, size_t, size_t, FILE *); | ||
| 205 | size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); | ||
| 206 | void clearerr_unlocked(FILE *); | ||
| 207 | int feof_unlocked(FILE *); | ||
| 208 | int ferror_unlocked(FILE *); | ||
| 209 | int fileno_unlocked(FILE *); | ||
| 210 | int getw(FILE *); | ||
| 211 | int putw(int, FILE *); | ||
| 212 | char *fgetln(FILE *, size_t *); | ||
| 213 | int asprintf(char **, const char *, ...); | ||
| 214 | int vasprintf(char **, const char *, __isoc_va_list); | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #ifdef _GNU_SOURCE | ||
| 218 | char *fgets_unlocked(char *, int, FILE *); | ||
| 219 | int fputs_unlocked(const char *, FILE *); | ||
| 220 | |||
| 221 | typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); | ||
| 222 | typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); | ||
| 223 | typedef int (cookie_seek_function_t)(void *, off_t *, int); | ||
| 224 | typedef int (cookie_close_function_t)(void *); | ||
| 225 | |||
| 226 | typedef struct _IO_cookie_io_functions_t { | ||
| 227 | 	cookie_read_function_t *read; | ||
| 228 | 	cookie_write_function_t *write; | ||
| 229 | 	cookie_seek_function_t *seek; | ||
| 230 | 	cookie_close_function_t *close; | ||
| 231 | } cookie_io_functions_t; | ||
| 232 | |||
| 233 | FILE *fopencookie(void *, const char *, cookie_io_functions_t); | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 237 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 238 | #define tmpfile64 tmpfile | ||
| 239 | #endif | ||
| 240 | #define fopen64 fopen | ||
| 241 | #define freopen64 freopen | ||
| 242 | #define fseeko64 fseeko | ||
| 243 | #define ftello64 ftello | ||
| 244 | #define fgetpos64 fgetpos | ||
| 245 | #define fsetpos64 fsetpos | ||
| 246 | #define fpos64_t fpos_t | ||
| 247 | #define off64_t off_t | ||
| 248 | #endif | ||
| 249 | |||
| 250 | #ifdef __cplusplus | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdlib.h deleted-217| ... | @@ -1,217 +0,0 @@ | ||
| 1 | #ifndef _STDLIB_H | ||
| 2 | #define _STDLIB_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__functions_malloc.h> | ||
| 7 | #include <__header_stdlib.h> | ||
| 8 | #endif | ||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #include <features.h> | ||
| 14 | |||
| 15 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 16 | #if __cplusplus >= 201103L | ||
| 17 | #define NULL nullptr | ||
| 18 | #elif defined(__cplusplus) | ||
| 19 | #define NULL 0L | ||
| 20 | #else | ||
| 21 | #define NULL ((void*)0) | ||
| 22 | #endif | ||
| 23 | #else | ||
| 24 | #define __need_NULL | ||
| 25 | #include <stddef.h> | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #define __NEED_size_t | ||
| 29 | #define __NEED_wchar_t | ||
| 30 | |||
| 31 | #include <bits/alltypes.h> | ||
| 32 | |||
| 33 | int atoi (const char *); | ||
| 34 | long atol (const char *); | ||
| 35 | long long atoll (const char *); | ||
| 36 | double atof (const char *); | ||
| 37 | |||
| 38 | float strtof (const char *__restrict, char **__restrict); | ||
| 39 | double strtod (const char *__restrict, char **__restrict); | ||
| 40 | long double strtold (const char *__restrict, char **__restrict); | ||
| 41 | |||
| 42 | long strtol (const char *__restrict, char **__restrict, int); | ||
| 43 | unsigned long strtoul (const char *__restrict, char **__restrict, int); | ||
| 44 | long long strtoll (const char *__restrict, char **__restrict, int); | ||
| 45 | unsigned long long strtoull (const char *__restrict, char **__restrict, int); | ||
| 46 | |||
| 47 | int rand (void); | ||
| 48 | void srand (unsigned); | ||
| 49 | |||
| 50 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 51 | void *malloc (size_t); | ||
| 52 | void *calloc (size_t, size_t); | ||
| 53 | void *realloc (void *, size_t); | ||
| 54 | void free (void *); | ||
| 55 | #endif | ||
| 56 | void *aligned_alloc(size_t, size_t); | ||
| 57 | |||
| 58 | _Noreturn void abort (void); | ||
| 59 | int atexit (void (*) (void)); | ||
| 60 | _Noreturn void exit (int); | ||
| 61 | _Noreturn void _Exit (int); | ||
| 62 | int at_quick_exit (void (*) (void)); | ||
| 63 | _Noreturn void quick_exit (int); | ||
| 64 | |||
| 65 | char *getenv (const char *); | ||
| 66 | |||
| 67 | int system (const char *); | ||
| 68 | |||
| 69 | void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 70 | void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 71 | |||
| 72 | int abs (int); | ||
| 73 | long labs (long); | ||
| 74 | long long llabs (long long); | ||
| 75 | |||
| 76 | typedef struct { int quot, rem; } div_t; | ||
| 77 | typedef struct { long quot, rem; } ldiv_t; | ||
| 78 | typedef struct { long long quot, rem; } lldiv_t; | ||
| 79 | |||
| 80 | div_t div (int, int); | ||
| 81 | ldiv_t ldiv (long, long); | ||
| 82 | lldiv_t lldiv (long long, long long); | ||
| 83 | |||
| 84 | int mblen (const char *, size_t); | ||
| 85 | int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 86 | int wctomb (char *, wchar_t); | ||
| 87 | size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 88 | size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); | ||
| 89 | |||
| 90 | #define EXIT_FAILURE 1 | ||
| 91 | #define EXIT_SUCCESS 0 | ||
| 92 | |||
| 93 | size_t __ctype_get_mb_cur_max(void); | ||
| 94 | #define MB_CUR_MAX (__ctype_get_mb_cur_max()) | ||
| 95 | |||
| 96 | #define RAND_MAX (0x7fffffff) | ||
| 97 | |||
| 98 | |||
| 99 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 100 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 101 | || defined(_BSD_SOURCE) | ||
| 102 | |||
| 103 | #ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ | ||
| 104 | #define WNOHANG 1 | ||
| 105 | #define WUNTRACED 2 | ||
| 106 | |||
| 107 | #define WEXITSTATUS(s) (((s) & 0xff00) >> 8) | ||
| 108 | #define WTERMSIG(s) ((s) & 0x7f) | ||
| 109 | #define WSTOPSIG(s) WEXITSTATUS(s) | ||
| 110 | #define WIFEXITED(s) (!WTERMSIG(s)) | ||
| 111 | #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00) | ||
| 112 | #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) | ||
| 113 | #endif | ||
| 114 | |||
| 115 | int posix_memalign (void **, size_t, size_t); | ||
| 116 | int setenv (const char *, const char *, int); | ||
| 117 | int unsetenv (const char *); | ||
| 118 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 119 | int mkstemp (char *); | ||
| 120 | int mkostemp (char *, int); | ||
| 121 | char *mkdtemp (char *); | ||
| 122 | #endif | ||
| 123 | int getsubopt (char **, char *const *, char **); | ||
| 124 | int rand_r (unsigned *); | ||
| 125 | |||
| 126 | #endif | ||
| 127 | |||
| 128 | |||
| 129 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 130 | || defined(_BSD_SOURCE) | ||
| 131 | char *realpath (const char *__restrict, char *__restrict); | ||
| 132 | long int random (void); | ||
| 133 | void srandom (unsigned int); | ||
| 134 | char *initstate (unsigned int, char *, size_t); | ||
| 135 | char *setstate (char *); | ||
| 136 | int putenv (char *); | ||
| 137 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ | ||
| 138 | int posix_openpt (int); | ||
| 139 | int grantpt (int); | ||
| 140 | int unlockpt (int); | ||
| 141 | char *ptsname (int); | ||
| 142 | #endif | ||
| 143 | char *l64a (long); | ||
| 144 | long a64l (const char *); | ||
| 145 | void setkey (const char *); | ||
| 146 | double drand48 (void); | ||
| 147 | double erand48 (unsigned short [3]); | ||
| 148 | long int lrand48 (void); | ||
| 149 | long int nrand48 (unsigned short [3]); | ||
| 150 | long mrand48 (void); | ||
| 151 | long jrand48 (unsigned short [3]); | ||
| 152 | void srand48 (long); | ||
| 153 | unsigned short *seed48 (unsigned short [3]); | ||
| 154 | void lcong48 (unsigned short [7]); | ||
| 155 | #endif | ||
| 156 | |||
| 157 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 158 | #include <alloca.h> | ||
| 159 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 160 | char *mktemp (char *); | ||
| 161 | int mkstemps (char *, int); | ||
| 162 | int mkostemps (char *, int, int); | ||
| 163 | #endif | ||
| 164 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 165 | void *valloc (size_t); | ||
| 166 | void *memalign(size_t, size_t); | ||
| 167 | int getloadavg(double *, int); | ||
| 168 | #endif | ||
| 169 | int clearenv(void); | ||
| 170 | #ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ | ||
| 171 | #define WCOREDUMP(s) ((s) & 0x80) | ||
| 172 | #define WIFCONTINUED(s) ((s) == 0xffff) | ||
| 173 | void *reallocarray (void *, size_t, size_t); | ||
| 174 | void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); | ||
| 175 | #endif | ||
| 176 | #endif | ||
| 177 | |||
| 178 | #ifdef _GNU_SOURCE | ||
| 179 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ | ||
| 180 | int ptsname_r(int, char *, size_t); | ||
| 181 | #endif | ||
| 182 | char *ecvt(double, int, int *, int *); | ||
| 183 | char *fcvt(double, int, int *, int *); | ||
| 184 | char *gcvt(double, int, char *); | ||
| 185 | char *secure_getenv(const char *); | ||
| 186 | struct __locale_struct; | ||
| 187 | float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 188 | double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 189 | long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 190 | #endif | ||
| 191 | |||
| 192 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 193 | #if defined(_LARGEFILE64_SOURCE) | ||
| 194 | #define mkstemp64 mkstemp | ||
| 195 | #define mkostemp64 mkostemp | ||
| 196 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 197 | #define mkstemps64 mkstemps | ||
| 198 | #define mkostemps64 mkostemps | ||
| 199 | #endif | ||
| 200 | #endif | ||
| 201 | #endif | ||
| 202 | |||
| 203 | #ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */ | ||
| 204 | #else | ||
| 205 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 206 | #include <stdint.h> | ||
| 207 | uint32_t arc4random(void); | ||
| 208 | void arc4random_buf(void *, size_t); | ||
| 209 | uint32_t arc4random_uniform(uint32_t); | ||
| 210 | #endif | ||
| 211 | #endif | ||
| 212 | |||
| 213 | #ifdef __cplusplus | ||
| 214 | } | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #endif | ||
lib/libc/include/wasm-wasi-musl/string.h deleted-123| ... | @@ -1,123 +0,0 @@ | ||
| 1 | #ifndef	_STRING_H | ||
| 2 | #define	_STRING_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__header_string.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 15 | #if __cplusplus >= 201103L | ||
| 16 | #define NULL nullptr | ||
| 17 | #elif defined(__cplusplus) | ||
| 18 | #define NULL 0L | ||
| 19 | #else | ||
| 20 | #define NULL ((void*)0) | ||
| 21 | #endif | ||
| 22 | #else | ||
| 23 | #define __need_NULL | ||
| 24 | #include <stddef.h> | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #define __NEED_size_t | ||
| 28 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 29 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 30 | || defined(_BSD_SOURCE) | ||
| 31 | #define __NEED_locale_t | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include <bits/alltypes.h> | ||
| 35 | |||
| 36 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 37 | void *memcpy (void *__restrict, const void *__restrict, size_t); | ||
| 38 | void *memmove (void *, const void *, size_t); | ||
| 39 | void *memset (void *, int, size_t); | ||
| 40 | #endif | ||
| 41 | int memcmp (const void *, const void *, size_t); | ||
| 42 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 43 | void *memchr (const void *, int, size_t); | ||
| 44 | #endif | ||
| 45 | |||
| 46 | char *strcpy (char *__restrict, const char *__restrict); | ||
| 47 | char *strncpy (char *__restrict, const char *__restrict, size_t); | ||
| 48 | |||
| 49 | char *strcat (char *__restrict, const char *__restrict); | ||
| 50 | char *strncat (char *__restrict, const char *__restrict, size_t); | ||
| 51 | |||
| 52 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 53 | int strcmp (const char *, const char *); | ||
| 54 | #endif | ||
| 55 | int strncmp (const char *, const char *, size_t); | ||
| 56 | |||
| 57 | int strcoll (const char *, const char *); | ||
| 58 | size_t strxfrm (char *__restrict, const char *__restrict, size_t); | ||
| 59 | |||
| 60 | char *strchr (const char *, int); | ||
| 61 | char *strrchr (const char *, int); | ||
| 62 | |||
| 63 | size_t strcspn (const char *, const char *); | ||
| 64 | size_t strspn (const char *, const char *); | ||
| 65 | char *strpbrk (const char *, const char *); | ||
| 66 | char *strstr (const char *, const char *); | ||
| 67 | char *strtok (char *__restrict, const char *__restrict); | ||
| 68 | |||
| 69 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 70 | size_t strlen (const char *); | ||
| 71 | #endif | ||
| 72 | |||
| 73 | char *strerror (int); | ||
| 74 | |||
| 75 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 76 | #include <strings.h> | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 80 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 81 | || defined(_BSD_SOURCE) | ||
| 82 | char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); | ||
| 83 | int strerror_r (int, char *, size_t); | ||
| 84 | char *stpcpy(char *__restrict, const char *__restrict); | ||
| 85 | char *stpncpy(char *__restrict, const char *__restrict, size_t); | ||
| 86 | size_t strnlen (const char *, size_t); | ||
| 87 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 88 | char *strdup (const char *); | ||
| 89 | #endif | ||
| 90 | char *strndup (const char *, size_t); | ||
| 91 | char *strsignal(int); | ||
| 92 | char *strerror_l (int, locale_t); | ||
| 93 | int strcoll_l (const char *, const char *, locale_t); | ||
| 94 | size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); | ||
| 95 | void *memmem(const void *, size_t, const void *, size_t); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 99 | || defined(_BSD_SOURCE) | ||
| 100 | void *memccpy (void *__restrict, const void *__restrict, int, size_t); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 104 | char *strsep(char **, const char *); | ||
| 105 | size_t strlcat (char *, const char *, size_t); | ||
| 106 | size_t strlcpy (char *, const char *, size_t); | ||
| 107 | void explicit_bzero (void *, size_t); | ||
| 108 | #endif | ||
| 109 | |||
| 110 | #ifdef _GNU_SOURCE | ||
| 111 | #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x) | ||
| 112 | int strverscmp (const char *, const char *); | ||
| 113 | char *strchrnul(const char *, int); | ||
| 114 | char *strcasestr(const char *, const char *); | ||
| 115 | void *memrchr(const void *, int, size_t); | ||
| 116 | void *mempcpy(void *, const void *, size_t); | ||
| 117 | #endif | ||
| 118 | |||
| 119 | #ifdef __cplusplus | ||
| 120 | } | ||
| 121 | #endif | ||
| 122 | |||
| 123 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/ioctl.h deleted-124| ... | @@ -1,124 +0,0 @@ | ||
| 1 | #ifndef	_SYS_IOCTL_H | ||
| 2 | #define	_SYS_IOCTL_H | ||
| 3 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_struct_winsize | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | #include <bits/ioctl.h> | ||
| 12 | |||
| 13 | #define N_TTY 0 | ||
| 14 | #define N_SLIP 1 | ||
| 15 | #define N_MOUSE 2 | ||
| 16 | #define N_PPP 3 | ||
| 17 | #define N_STRIP 4 | ||
| 18 | #define N_AX25 5 | ||
| 19 | #define N_X25 6 | ||
| 20 | #define N_6PACK 7 | ||
| 21 | #define N_MASC 8 | ||
| 22 | #define N_R3964 9 | ||
| 23 | #define N_PROFIBUS_FDL 10 | ||
| 24 | #define N_IRDA 11 | ||
| 25 | #define N_SMSBLOCK 12 | ||
| 26 | #define N_HDLC 13 | ||
| 27 | #define N_SYNC_PPP 14 | ||
| 28 | #define N_HCI 15 | ||
| 29 | #define N_GIGASET_M101 16 | ||
| 30 | #define N_SLCAN 17 | ||
| 31 | #define N_PPS 18 | ||
| 32 | #define N_V253 19 | ||
| 33 | #define N_CAIF 20 | ||
| 34 | #define N_GSM0710 21 | ||
| 35 | #define N_TI_WL 22 | ||
| 36 | #define N_TRACESINK 23 | ||
| 37 | #define N_TRACEROUTER 24 | ||
| 38 | #define N_NCI 25 | ||
| 39 | #define N_SPEAKUP 26 | ||
| 40 | #define N_NULL 27 | ||
| 41 | |||
| 42 | #define TIOCPKT_DATA 0 | ||
| 43 | #define TIOCPKT_FLUSHREAD 1 | ||
| 44 | #define TIOCPKT_FLUSHWRITE 2 | ||
| 45 | #define TIOCPKT_STOP 4 | ||
| 46 | #define TIOCPKT_START 8 | ||
| 47 | #define TIOCPKT_NOSTOP 16 | ||
| 48 | #define TIOCPKT_DOSTOP 32 | ||
| 49 | #define TIOCPKT_IOCTL 64 | ||
| 50 | |||
| 51 | #define TIOCSER_TEMT 1 | ||
| 52 | |||
| 53 | #define SIOCADDRT 0x890B | ||
| 54 | #define SIOCDELRT 0x890C | ||
| 55 | #define SIOCRTMSG 0x890D | ||
| 56 | |||
| 57 | #define SIOCGIFNAME 0x8910 | ||
| 58 | #define SIOCSIFLINK 0x8911 | ||
| 59 | #define SIOCGIFCONF 0x8912 | ||
| 60 | #define SIOCGIFFLAGS 0x8913 | ||
| 61 | #define SIOCSIFFLAGS 0x8914 | ||
| 62 | #define SIOCGIFADDR 0x8915 | ||
| 63 | #define SIOCSIFADDR 0x8916 | ||
| 64 | #define SIOCGIFDSTADDR 0x8917 | ||
| 65 | #define SIOCSIFDSTADDR 0x8918 | ||
| 66 | #define SIOCGIFBRDADDR 0x8919 | ||
| 67 | #define SIOCSIFBRDADDR 0x891a | ||
| 68 | #define SIOCGIFNETMASK 0x891b | ||
| 69 | #define SIOCSIFNETMASK 0x891c | ||
| 70 | #define SIOCGIFMETRIC 0x891d | ||
| 71 | #define SIOCSIFMETRIC 0x891e | ||
| 72 | #define SIOCGIFMEM 0x891f | ||
| 73 | #define SIOCSIFMEM 0x8920 | ||
| 74 | #define SIOCGIFMTU 0x8921 | ||
| 75 | #define SIOCSIFMTU 0x8922 | ||
| 76 | #define SIOCSIFNAME 0x8923 | ||
| 77 | #define SIOCSIFHWADDR 0x8924 | ||
| 78 | #define SIOCGIFENCAP 0x8925 | ||
| 79 | #define SIOCSIFENCAP 0x8926 | ||
| 80 | #define SIOCGIFHWADDR 0x8927 | ||
| 81 | #define SIOCGIFSLAVE 0x8929 | ||
| 82 | #define SIOCSIFSLAVE 0x8930 | ||
| 83 | #define SIOCADDMULTI 0x8931 | ||
| 84 | #define SIOCDELMULTI 0x8932 | ||
| 85 | #define SIOCGIFINDEX 0x8933 | ||
| 86 | #define SIOGIFINDEX SIOCGIFINDEX | ||
| 87 | #define SIOCSIFPFLAGS 0x8934 | ||
| 88 | #define SIOCGIFPFLAGS 0x8935 | ||
| 89 | #define SIOCDIFADDR 0x8936 | ||
| 90 | #define SIOCSIFHWBROADCAST 0x8937 | ||
| 91 | #define SIOCGIFCOUNT 0x8938 | ||
| 92 | |||
| 93 | #define SIOCGIFBR 0x8940 | ||
| 94 | #define SIOCSIFBR 0x8941 | ||
| 95 | |||
| 96 | #define SIOCGIFTXQLEN 0x8942 | ||
| 97 | #define SIOCSIFTXQLEN 0x8943 | ||
| 98 | |||
| 99 | #define SIOCDARP 0x8953 | ||
| 100 | #define SIOCGARP 0x8954 | ||
| 101 | #define SIOCSARP 0x8955 | ||
| 102 | |||
| 103 | #define SIOCDRARP 0x8960 | ||
| 104 | #define SIOCGRARP 0x8961 | ||
| 105 | #define SIOCSRARP 0x8962 | ||
| 106 | |||
| 107 | #define SIOCGIFMAP 0x8970 | ||
| 108 | #define SIOCSIFMAP 0x8971 | ||
| 109 | |||
| 110 | #define SIOCADDDLCI 0x8980 | ||
| 111 | #define SIOCDELDLCI 0x8981 | ||
| 112 | |||
| 113 | #define SIOCDEVPRIVATE 0x89F0 | ||
| 114 | #define SIOCPROTOPRIVATE 0x89E0 | ||
| 115 | |||
| 116 | int ioctl (int, int, ...); | ||
| 117 | |||
| 118 | #ifdef __cplusplus | ||
| 119 | } | ||
| 120 | #endif | ||
| 121 | #else | ||
| 122 | #include <__header_sys_ioctl.h> | ||
| 123 | #endif | ||
| 124 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/mman.h deleted-157| ... | @@ -1,157 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_MMAN | ||
| 2 | #error "WASI lacks a true mmap; to enable minimal mmap emulation, \ | ||
| 3 | compile with -D_WASI_EMULATED_MMAN and link with -lwasi-emulated-mman" | ||
| 4 | #else | ||
| 5 | #ifndef	_SYS_MMAN_H | ||
| 6 | #define	_SYS_MMAN_H | ||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #include <features.h> | ||
| 12 | |||
| 13 | #define __NEED_mode_t | ||
| 14 | #define __NEED_size_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | |||
| 17 | #if defined(_GNU_SOURCE) | ||
| 18 | #define __NEED_ssize_t | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #include <bits/alltypes.h> | ||
| 22 | |||
| 23 | #define MAP_FAILED ((void *) -1) | ||
| 24 | |||
| 25 | #define MAP_SHARED 0x01 | ||
| 26 | #define MAP_PRIVATE 0x02 | ||
| 27 | #define MAP_SHARED_VALIDATE 0x03 | ||
| 28 | #define MAP_TYPE 0x0f | ||
| 29 | #define MAP_FIXED 0x10 | ||
| 30 | #define MAP_ANON 0x20 | ||
| 31 | #define MAP_ANONYMOUS MAP_ANON | ||
| 32 | #define MAP_NORESERVE 0x4000 | ||
| 33 | #define MAP_GROWSDOWN 0x0100 | ||
| 34 | #define MAP_DENYWRITE 0x0800 | ||
| 35 | #define MAP_EXECUTABLE 0x1000 | ||
| 36 | #define MAP_LOCKED 0x2000 | ||
| 37 | #define MAP_POPULATE 0x8000 | ||
| 38 | #define MAP_NONBLOCK 0x10000 | ||
| 39 | #define MAP_STACK 0x20000 | ||
| 40 | #define MAP_HUGETLB 0x40000 | ||
| 41 | #define MAP_SYNC 0x80000 | ||
| 42 | #define MAP_FIXED_NOREPLACE 0x100000 | ||
| 43 | #define MAP_FILE 0 | ||
| 44 | |||
| 45 | #define MAP_HUGE_SHIFT 26 | ||
| 46 | #define MAP_HUGE_MASK 0x3f | ||
| 47 | #define MAP_HUGE_16KB (14 << 26) | ||
| 48 | #define MAP_HUGE_64KB (16 << 26) | ||
| 49 | #define MAP_HUGE_512KB (19 << 26) | ||
| 50 | #define MAP_HUGE_1MB (20 << 26) | ||
| 51 | #define MAP_HUGE_2MB (21 << 26) | ||
| 52 | #define MAP_HUGE_8MB (23 << 26) | ||
| 53 | #define MAP_HUGE_16MB (24 << 26) | ||
| 54 | #define MAP_HUGE_32MB (25 << 26) | ||
| 55 | #define MAP_HUGE_256MB (28 << 26) | ||
| 56 | #define MAP_HUGE_512MB (29 << 26) | ||
| 57 | #define MAP_HUGE_1GB (30 << 26) | ||
| 58 | #define MAP_HUGE_2GB (31 << 26) | ||
| 59 | #define MAP_HUGE_16GB (34U << 26) | ||
| 60 | |||
| 61 | #define PROT_NONE 0 | ||
| 62 | #define PROT_READ 1 | ||
| 63 | #define PROT_WRITE 2 | ||
| 64 | #define PROT_EXEC 4 | ||
| 65 | #define PROT_GROWSDOWN 0x01000000 | ||
| 66 | #define PROT_GROWSUP 0x02000000 | ||
| 67 | |||
| 68 | #define MS_ASYNC 1 | ||
| 69 | #define MS_INVALIDATE 2 | ||
| 70 | #define MS_SYNC 4 | ||
| 71 | |||
| 72 | #define MCL_CURRENT 1 | ||
| 73 | #define MCL_FUTURE 2 | ||
| 74 | #define MCL_ONFAULT 4 | ||
| 75 | |||
| 76 | #define POSIX_MADV_NORMAL 0 | ||
| 77 | #define POSIX_MADV_RANDOM 1 | ||
| 78 | #define POSIX_MADV_SEQUENTIAL 2 | ||
| 79 | #define POSIX_MADV_WILLNEED 3 | ||
| 80 | #define POSIX_MADV_DONTNEED 4 | ||
| 81 | |||
| 82 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 83 | #define MADV_NORMAL 0 | ||
| 84 | #define MADV_RANDOM 1 | ||
| 85 | #define MADV_SEQUENTIAL 2 | ||
| 86 | #define MADV_WILLNEED 3 | ||
| 87 | #define MADV_DONTNEED 4 | ||
| 88 | #define MADV_FREE 8 | ||
| 89 | #define MADV_REMOVE 9 | ||
| 90 | #define MADV_DONTFORK 10 | ||
| 91 | #define MADV_DOFORK 11 | ||
| 92 | #define MADV_MERGEABLE 12 | ||
| 93 | #define MADV_UNMERGEABLE 13 | ||
| 94 | #define MADV_HUGEPAGE 14 | ||
| 95 | #define MADV_NOHUGEPAGE 15 | ||
| 96 | #define MADV_DONTDUMP 16 | ||
| 97 | #define MADV_DODUMP 17 | ||
| 98 | #define MADV_WIPEONFORK 18 | ||
| 99 | #define MADV_KEEPONFORK 19 | ||
| 100 | #define MADV_COLD 20 | ||
| 101 | #define MADV_PAGEOUT 21 | ||
| 102 | #define MADV_HWPOISON 100 | ||
| 103 | #define MADV_SOFT_OFFLINE 101 | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifdef _GNU_SOURCE | ||
| 107 | #define MREMAP_MAYMOVE 1 | ||
| 108 | #define MREMAP_FIXED 2 | ||
| 109 | #define MREMAP_DONTUNMAP 4 | ||
| 110 | |||
| 111 | #define MLOCK_ONFAULT 0x01 | ||
| 112 | |||
| 113 | #define MFD_CLOEXEC 0x0001U | ||
| 114 | #define MFD_ALLOW_SEALING 0x0002U | ||
| 115 | #define MFD_HUGETLB 0x0004U | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #include <bits/mman.h> | ||
| 119 | |||
| 120 | void *mmap (void *, size_t, int, int, int, off_t); | ||
| 121 | int munmap (void *, size_t); | ||
| 122 | |||
| 123 | int mprotect (void *, size_t, int); | ||
| 124 | int msync (void *, size_t, int); | ||
| 125 | |||
| 126 | int posix_madvise (void *, size_t, int); | ||
| 127 | |||
| 128 | int mlock (const void *, size_t); | ||
| 129 | int munlock (const void *, size_t); | ||
| 130 | int mlockall (int); | ||
| 131 | int munlockall (void); | ||
| 132 | |||
| 133 | #ifdef _GNU_SOURCE | ||
| 134 | void *mremap (void *, size_t, size_t, int, ...); | ||
| 135 | int remap_file_pages (void *, size_t, int, size_t, int); | ||
| 136 | int memfd_create (const char *, unsigned); | ||
| 137 | int mlock2 (const void *, size_t, unsigned); | ||
| 138 | #endif | ||
| 139 | |||
| 140 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 141 | int madvise (void *, size_t, int); | ||
| 142 | int mincore (void *, size_t, unsigned char *); | ||
| 143 | #endif | ||
| 144 | |||
| 145 | int shm_open (const char *, int, mode_t); | ||
| 146 | int shm_unlink (const char *); | ||
| 147 | |||
| 148 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 149 | #define mmap64 mmap | ||
| 150 | #define off64_t off_t | ||
| 151 | #endif | ||
| 152 | |||
| 153 | #ifdef __cplusplus | ||
| 154 | } | ||
| 155 | #endif | ||
| 156 | #endif | ||
| 157 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/param.h deleted-37| ... | @@ -1,37 +0,0 @@ | ||
| 1 | #ifndef _SYS_PARAM_H | ||
| 2 | #define _SYS_PARAM_H | ||
| 3 | |||
| 4 | #define MAXSYMLINKS 20 | ||
| 5 | #define MAXHOSTNAMELEN 64 | ||
| 6 | #define MAXNAMLEN 255 | ||
| 7 | #define MAXPATHLEN 4096 | ||
| 8 | #define NBBY 8 | ||
| 9 | #define NGROUPS 32 | ||
| 10 | #define CANBSIZ 255 | ||
| 11 | #define NOFILE 256 | ||
| 12 | #define NCARGS 131072 | ||
| 13 | #define DEV_BSIZE 512 | ||
| 14 | #define NOGROUP (-1) | ||
| 15 | |||
| 16 | #undef MIN | ||
| 17 | #undef MAX | ||
| 18 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 19 | #define MAX(a,b) (((a)>(b))?(a):(b)) | ||
| 20 | |||
| 21 | #define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) | ||
| 22 | #define setbit(x,i) __bitop(x,i,|=) | ||
| 23 | #define clrbit(x,i) __bitop(x,i,&=~) | ||
| 24 | #define isset(x,i) __bitop(x,i,&) | ||
| 25 | #define isclr(x,i) !isset(x,i) | ||
| 26 | |||
| 27 | #define howmany(n,d) (((n)+((d)-1))/(d)) | ||
| 28 | #define roundup(n,d) (howmany(n,d)*(d)) | ||
| 29 | #define powerof2(n) !(((n)-1) & (n)) | ||
| 30 | |||
| 31 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) | ||
| 32 | #include <sys/resource.h> | ||
| 33 | #endif | ||
| 34 | #include <endian.h> | ||
| 35 | #include <limits.h> | ||
| 36 | |||
| 37 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/random.h deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | #ifndef _SYS_RANDOM_H | ||
| 2 | #define _SYS_RANDOM_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getrandom, but it does have getentropy */ | ||
| 8 | #define __NEED_size_t | ||
| 9 | #define __NEED_ssize_t | ||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #define GRND_NONBLOCK	0x0001 | ||
| 13 | #define GRND_RANDOM	0x0002 | ||
| 14 | #define GRND_INSECURE	0x0004 | ||
| 15 | |||
| 16 | ssize_t getrandom(void *, size_t, unsigned); | ||
| 17 | #else | ||
| 18 | #define __NEED_size_t | ||
| 19 | #include <bits/alltypes.h> | ||
| 20 | |||
| 21 | int getentropy(void *, size_t); | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #ifdef __cplusplus | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/resource.h deleted-126| ... | @@ -1,126 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #error WASI lacks process-associated clocks; to enable emulation of the `getrusage` function using \ | ||
| 3 | the wall clock, which isn't sensitive to whether the program is running or suspended, \ | ||
| 4 | compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks | ||
| 5 | #else | ||
| 6 | #ifndef	_SYS_RESOURCE_H | ||
| 7 | #define	_SYS_RESOURCE_H | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #include <features.h> | ||
| 14 | #include <sys/time.h> | ||
| 15 | |||
| 16 | #define __NEED_id_t | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __NEED_pid_t | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #include <bits/alltypes.h> | ||
| 23 | #include <bits/resource.h> | ||
| 24 | |||
| 25 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 26 | typedef unsigned long long rlim_t; | ||
| 27 | |||
| 28 | struct rlimit { | ||
| 29 | 	rlim_t rlim_cur; | ||
| 30 | 	rlim_t rlim_max; | ||
| 31 | }; | ||
| 32 | |||
| 33 | struct rusage { | ||
| 34 | 	struct timeval ru_utime; | ||
| 35 | 	struct timeval ru_stime; | ||
| 36 | 	/* linux extentions, but useful */ | ||
| 37 | 	long	ru_maxrss; | ||
| 38 | 	long	ru_ixrss; | ||
| 39 | 	long	ru_idrss; | ||
| 40 | 	long	ru_isrss; | ||
| 41 | 	long	ru_minflt; | ||
| 42 | 	long	ru_majflt; | ||
| 43 | 	long	ru_nswap; | ||
| 44 | 	long	ru_inblock; | ||
| 45 | 	long	ru_oublock; | ||
| 46 | 	long	ru_msgsnd; | ||
| 47 | 	long	ru_msgrcv; | ||
| 48 | 	long	ru_nsignals; | ||
| 49 | 	long	ru_nvcsw; | ||
| 50 | 	long	ru_nivcsw; | ||
| 51 | 	/* room for more... */ | ||
| 52 | 	long __reserved[16]; | ||
| 53 | }; | ||
| 54 | |||
| 55 | int getrlimit (int, struct rlimit *); | ||
| 56 | int setrlimit (int, const struct rlimit *); | ||
| 57 | int getrusage (int, struct rusage *); | ||
| 58 | |||
| 59 | int getpriority (int, id_t); | ||
| 60 | int setpriority (int, id_t, int); | ||
| 61 | |||
| 62 | #ifdef _GNU_SOURCE | ||
| 63 | int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); | ||
| 64 | #define prlimit64 prlimit | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #define PRIO_MIN (-20) | ||
| 68 | #define PRIO_MAX 20 | ||
| 69 | |||
| 70 | #define PRIO_PROCESS 0 | ||
| 71 | #define PRIO_PGRP 1 | ||
| 72 | #define PRIO_USER 2 | ||
| 73 | |||
| 74 | #define RUSAGE_SELF 0 | ||
| 75 | #define RUSAGE_CHILDREN (-1) | ||
| 76 | #define RUSAGE_THREAD 1 | ||
| 77 | |||
| 78 | #define RLIM_INFINITY (~0ULL) | ||
| 79 | #define RLIM_SAVED_CUR RLIM_INFINITY | ||
| 80 | #define RLIM_SAVED_MAX RLIM_INFINITY | ||
| 81 | |||
| 82 | #define RLIMIT_CPU 0 | ||
| 83 | #define RLIMIT_FSIZE 1 | ||
| 84 | #define RLIMIT_DATA 2 | ||
| 85 | #define RLIMIT_STACK 3 | ||
| 86 | #define RLIMIT_CORE 4 | ||
| 87 | #ifndef RLIMIT_RSS | ||
| 88 | #define RLIMIT_RSS 5 | ||
| 89 | #define RLIMIT_NPROC 6 | ||
| 90 | #define RLIMIT_NOFILE 7 | ||
| 91 | #define RLIMIT_MEMLOCK 8 | ||
| 92 | #define RLIMIT_AS 9 | ||
| 93 | #endif | ||
| 94 | #define RLIMIT_LOCKS 10 | ||
| 95 | #define RLIMIT_SIGPENDING 11 | ||
| 96 | #define RLIMIT_MSGQUEUE 12 | ||
| 97 | #define RLIMIT_NICE 13 | ||
| 98 | #define RLIMIT_RTPRIO 14 | ||
| 99 | #define RLIMIT_RTTIME 15 | ||
| 100 | #define RLIMIT_NLIMITS 16 | ||
| 101 | |||
| 102 | #define RLIM_NLIMITS RLIMIT_NLIMITS | ||
| 103 | |||
| 104 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 105 | #define RLIM64_INFINITY RLIM_INFINITY | ||
| 106 | #define RLIM64_SAVED_CUR RLIM_SAVED_CUR | ||
| 107 | #define RLIM64_SAVED_MAX RLIM_SAVED_MAX | ||
| 108 | #define getrlimit64 getrlimit | ||
| 109 | #define setrlimit64 setrlimit | ||
| 110 | #define rlimit64 rlimit | ||
| 111 | #define rlim64_t rlim_t | ||
| 112 | #endif | ||
| 113 | #else | ||
| 114 | #include <__header_sys_resource.h> | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #if _REDIR_TIME64 | ||
| 118 | __REDIR(getrusage, __getrusage_time64); | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #ifdef __cplusplus | ||
| 122 | } | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #endif | ||
| 126 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/select.h deleted-54| ... | @@ -1,54 +0,0 @@ | ||
| 1 | #ifndef _SYS_SELECT_H | ||
| 2 | #define _SYS_SELECT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_time_t | ||
| 11 | #define __NEED_suseconds_t | ||
| 12 | #define __NEED_struct_timeval | ||
| 13 | #define __NEED_struct_timespec | ||
| 14 | #define __NEED_sigset_t | ||
| 15 | |||
| 16 | #include <bits/alltypes.h> | ||
| 17 | |||
| 18 | #define FD_SETSIZE 1024 | ||
| 19 | |||
| 20 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 21 | typedef unsigned long fd_mask; | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 25 | typedef struct { | ||
| 26 | 	unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; | ||
| 27 | } fd_set; | ||
| 28 | |||
| 29 | #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) | ||
| 30 | #define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) | ||
| 31 | #define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) | ||
| 32 | #define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) | ||
| 33 | #else | ||
| 34 | #include <__fd_set.h> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); | ||
| 38 | int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); | ||
| 39 | |||
| 40 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 41 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 42 | #define NFDBITS (8*(int)sizeof(long)) | ||
| 43 | #endif | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #if _REDIR_TIME64 | ||
| 47 | __REDIR(select, __select_time64); | ||
| 48 | __REDIR(pselect, __pselect_time64); | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #ifdef __cplusplus | ||
| 52 | } | ||
| 53 | #endif | ||
| 54 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/socket.h deleted-454| ... | @@ -1,454 +0,0 @@ | ||
| 1 | #ifndef	_SYS_SOCKET_H | ||
| 2 | #define	_SYS_SOCKET_H | ||
| 3 | |||
| 4 | #include <__wasi_snapshot.h> | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 7 | #else | ||
| 8 | #include <__header_sys_socket.h> | ||
| 9 | #endif | ||
| 10 | #ifdef __cplusplus | ||
| 11 | extern "C" { | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include <features.h> | ||
| 15 | |||
| 16 | #define __NEED_socklen_t | ||
| 17 | #define __NEED_sa_family_t | ||
| 18 | #define __NEED_size_t | ||
| 19 | #define __NEED_ssize_t | ||
| 20 | #define __NEED_uid_t | ||
| 21 | #define __NEED_pid_t | ||
| 22 | #define __NEED_gid_t | ||
| 23 | #define __NEED_struct_iovec | ||
| 24 | |||
| 25 | #include <bits/alltypes.h> | ||
| 26 | |||
| 27 | #include <bits/socket.h> | ||
| 28 | |||
| 29 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 30 | struct msghdr { | ||
| 31 | 	void *msg_name; | ||
| 32 | 	socklen_t msg_namelen; | ||
| 33 | 	struct iovec *msg_iov; | ||
| 34 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 35 | 	int __pad1; | ||
| 36 | #endif | ||
| 37 | 	int msg_iovlen; | ||
| 38 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 39 | 	int __pad1; | ||
| 40 | #endif | ||
| 41 | 	void *msg_control; | ||
| 42 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 43 | 	int __pad2; | ||
| 44 | #endif | ||
| 45 | 	socklen_t msg_controllen; | ||
| 46 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 47 | 	int __pad2; | ||
| 48 | #endif | ||
| 49 | 	int msg_flags; | ||
| 50 | }; | ||
| 51 | |||
| 52 | struct cmsghdr { | ||
| 53 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 54 | 	int __pad1; | ||
| 55 | #endif | ||
| 56 | 	socklen_t cmsg_len; | ||
| 57 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 58 | 	int __pad1; | ||
| 59 | #endif | ||
| 60 | 	int cmsg_level; | ||
| 61 | 	int cmsg_type; | ||
| 62 | }; | ||
| 63 | #else | ||
| 64 | #include <__struct_msghdr.h> | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #ifdef _GNU_SOURCE | ||
| 68 | struct ucred { | ||
| 69 | 	pid_t pid; | ||
| 70 | 	uid_t uid; | ||
| 71 | 	gid_t gid; | ||
| 72 | }; | ||
| 73 | |||
| 74 | struct mmsghdr { | ||
| 75 | 	struct msghdr msg_hdr; | ||
| 76 | 	unsigned int msg_len; | ||
| 77 | }; | ||
| 78 | |||
| 79 | struct timespec; | ||
| 80 | |||
| 81 | int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); | ||
| 82 | int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); | ||
| 83 | #endif | ||
| 84 | |||
| 85 | struct linger { | ||
| 86 | 	int l_onoff; | ||
| 87 | 	int l_linger; | ||
| 88 | }; | ||
| 89 | |||
| 90 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 91 | #define SHUT_RD 0 | ||
| 92 | #define SHUT_WR 1 | ||
| 93 | #define SHUT_RDWR 2 | ||
| 94 | |||
| 95 | #ifndef SOCK_STREAM | ||
| 96 | #define SOCK_STREAM 1 | ||
| 97 | #define SOCK_DGRAM 2 | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #define SOCK_RAW 3 | ||
| 101 | #define SOCK_RDM 4 | ||
| 102 | #define SOCK_SEQPACKET 5 | ||
| 103 | #define SOCK_DCCP 6 | ||
| 104 | #define SOCK_PACKET 10 | ||
| 105 | |||
| 106 | #ifndef SOCK_CLOEXEC | ||
| 107 | #define SOCK_CLOEXEC 02000000 | ||
| 108 | #define SOCK_NONBLOCK 04000 | ||
| 109 | #endif | ||
| 110 | |||
| 111 | #define PF_UNSPEC 0 | ||
| 112 | #define PF_LOCAL 1 | ||
| 113 | #define PF_UNIX PF_LOCAL | ||
| 114 | #define PF_FILE PF_LOCAL | ||
| 115 | #define PF_INET 2 | ||
| 116 | #define PF_AX25 3 | ||
| 117 | #define PF_IPX 4 | ||
| 118 | #define PF_APPLETALK 5 | ||
| 119 | #define PF_NETROM 6 | ||
| 120 | #define PF_BRIDGE 7 | ||
| 121 | #define PF_ATMPVC 8 | ||
| 122 | #define PF_X25 9 | ||
| 123 | #define PF_INET6 10 | ||
| 124 | #define PF_ROSE 11 | ||
| 125 | #define PF_DECnet 12 | ||
| 126 | #define PF_NETBEUI 13 | ||
| 127 | #define PF_SECURITY 14 | ||
| 128 | #define PF_KEY 15 | ||
| 129 | #define PF_NETLINK 16 | ||
| 130 | #define PF_ROUTE PF_NETLINK | ||
| 131 | #define PF_PACKET 17 | ||
| 132 | #define PF_ASH 18 | ||
| 133 | #define PF_ECONET 19 | ||
| 134 | #define PF_ATMSVC 20 | ||
| 135 | #define PF_RDS 21 | ||
| 136 | #define PF_SNA 22 | ||
| 137 | #define PF_IRDA 23 | ||
| 138 | #define PF_PPPOX 24 | ||
| 139 | #define PF_WANPIPE 25 | ||
| 140 | #define PF_LLC 26 | ||
| 141 | #define PF_IB 27 | ||
| 142 | #define PF_MPLS 28 | ||
| 143 | #define PF_CAN 29 | ||
| 144 | #define PF_TIPC 30 | ||
| 145 | #define PF_BLUETOOTH 31 | ||
| 146 | #define PF_IUCV 32 | ||
| 147 | #define PF_RXRPC 33 | ||
| 148 | #define PF_ISDN 34 | ||
| 149 | #define PF_PHONET 35 | ||
| 150 | #define PF_IEEE802154 36 | ||
| 151 | #define PF_CAIF 37 | ||
| 152 | #define PF_ALG 38 | ||
| 153 | #define PF_NFC 39 | ||
| 154 | #define PF_VSOCK 40 | ||
| 155 | #define PF_KCM 41 | ||
| 156 | #define PF_QIPCRTR 42 | ||
| 157 | #define PF_SMC 43 | ||
| 158 | #define PF_XDP 44 | ||
| 159 | #define PF_MAX 45 | ||
| 160 | |||
| 161 | #define AF_UNSPEC PF_UNSPEC | ||
| 162 | #define AF_LOCAL PF_LOCAL | ||
| 163 | #define AF_UNIX AF_LOCAL | ||
| 164 | #define AF_FILE AF_LOCAL | ||
| 165 | #define AF_INET PF_INET | ||
| 166 | #define AF_AX25 PF_AX25 | ||
| 167 | #define AF_IPX PF_IPX | ||
| 168 | #define AF_APPLETALK PF_APPLETALK | ||
| 169 | #define AF_NETROM PF_NETROM | ||
| 170 | #define AF_BRIDGE PF_BRIDGE | ||
| 171 | #define AF_ATMPVC PF_ATMPVC | ||
| 172 | #define AF_X25 PF_X25 | ||
| 173 | #define AF_INET6 PF_INET6 | ||
| 174 | #define AF_ROSE PF_ROSE | ||
| 175 | #define AF_DECnet PF_DECnet | ||
| 176 | #define AF_NETBEUI PF_NETBEUI | ||
| 177 | #define AF_SECURITY PF_SECURITY | ||
| 178 | #define AF_KEY PF_KEY | ||
| 179 | #define AF_NETLINK PF_NETLINK | ||
| 180 | #define AF_ROUTE PF_ROUTE | ||
| 181 | #define AF_PACKET PF_PACKET | ||
| 182 | #define AF_ASH PF_ASH | ||
| 183 | #define AF_ECONET PF_ECONET | ||
| 184 | #define AF_ATMSVC PF_ATMSVC | ||
| 185 | #define AF_RDS PF_RDS | ||
| 186 | #define AF_SNA PF_SNA | ||
| 187 | #define AF_IRDA PF_IRDA | ||
| 188 | #define AF_PPPOX PF_PPPOX | ||
| 189 | #define AF_WANPIPE PF_WANPIPE | ||
| 190 | #define AF_LLC PF_LLC | ||
| 191 | #define AF_IB PF_IB | ||
| 192 | #define AF_MPLS PF_MPLS | ||
| 193 | #define AF_CAN PF_CAN | ||
| 194 | #define AF_TIPC PF_TIPC | ||
| 195 | #define AF_BLUETOOTH PF_BLUETOOTH | ||
| 196 | #define AF_IUCV PF_IUCV | ||
| 197 | #define AF_RXRPC PF_RXRPC | ||
| 198 | #define AF_ISDN PF_ISDN | ||
| 199 | #define AF_PHONET PF_PHONET | ||
| 200 | #define AF_IEEE802154 PF_IEEE802154 | ||
| 201 | #define AF_CAIF PF_CAIF | ||
| 202 | #define AF_ALG PF_ALG | ||
| 203 | #define AF_NFC PF_NFC | ||
| 204 | #define AF_VSOCK PF_VSOCK | ||
| 205 | #define AF_KCM PF_KCM | ||
| 206 | #define AF_QIPCRTR PF_QIPCRTR | ||
| 207 | #define AF_SMC PF_SMC | ||
| 208 | #define AF_XDP PF_XDP | ||
| 209 | #define AF_MAX PF_MAX | ||
| 210 | |||
| 211 | #ifndef SO_DEBUG | ||
| 212 | #define SO_DEBUG 1 | ||
| 213 | #define SO_REUSEADDR 2 | ||
| 214 | #define SO_TYPE 3 | ||
| 215 | #define SO_ERROR 4 | ||
| 216 | #define SO_DONTROUTE 5 | ||
| 217 | #define SO_BROADCAST 6 | ||
| 218 | #define SO_SNDBUF 7 | ||
| 219 | #define SO_RCVBUF 8 | ||
| 220 | #define SO_KEEPALIVE 9 | ||
| 221 | #define SO_OOBINLINE 10 | ||
| 222 | #define SO_NO_CHECK 11 | ||
| 223 | #define SO_PRIORITY 12 | ||
| 224 | #define SO_LINGER 13 | ||
| 225 | #define SO_BSDCOMPAT 14 | ||
| 226 | #define SO_REUSEPORT 15 | ||
| 227 | #define SO_PASSCRED 16 | ||
| 228 | #define SO_PEERCRED 17 | ||
| 229 | #define SO_RCVLOWAT 18 | ||
| 230 | #define SO_SNDLOWAT 19 | ||
| 231 | #define SO_ACCEPTCONN 30 | ||
| 232 | #define SO_PEERSEC 31 | ||
| 233 | #define SO_SNDBUFFORCE 32 | ||
| 234 | #define SO_RCVBUFFORCE 33 | ||
| 235 | #define SO_PROTOCOL 38 | ||
| 236 | #define SO_DOMAIN 39 | ||
| 237 | #endif | ||
| 238 | |||
| 239 | #ifndef SO_RCVTIMEO | ||
| 240 | #if __LONG_MAX == 0x7fffffff | ||
| 241 | #define SO_RCVTIMEO 66 | ||
| 242 | #define SO_SNDTIMEO 67 | ||
| 243 | #else | ||
| 244 | #define SO_RCVTIMEO 20 | ||
| 245 | #define SO_SNDTIMEO 21 | ||
| 246 | #endif | ||
| 247 | #endif | ||
| 248 | |||
| 249 | #ifndef SO_TIMESTAMP | ||
| 250 | #if __LONG_MAX == 0x7fffffff | ||
| 251 | #define SO_TIMESTAMP 63 | ||
| 252 | #define SO_TIMESTAMPNS 64 | ||
| 253 | #define SO_TIMESTAMPING 65 | ||
| 254 | #else | ||
| 255 | #define SO_TIMESTAMP 29 | ||
| 256 | #define SO_TIMESTAMPNS 35 | ||
| 257 | #define SO_TIMESTAMPING 37 | ||
| 258 | #endif | ||
| 259 | #endif | ||
| 260 | |||
| 261 | #define SO_SECURITY_AUTHENTICATION 22 | ||
| 262 | #define SO_SECURITY_ENCRYPTION_TRANSPORT 23 | ||
| 263 | #define SO_SECURITY_ENCRYPTION_NETWORK 24 | ||
| 264 | |||
| 265 | #define SO_BINDTODEVICE 25 | ||
| 266 | |||
| 267 | #define SO_ATTACH_FILTER 26 | ||
| 268 | #define SO_DETACH_FILTER 27 | ||
| 269 | #define SO_GET_FILTER SO_ATTACH_FILTER | ||
| 270 | |||
| 271 | #define SO_PEERNAME 28 | ||
| 272 | #define SCM_TIMESTAMP SO_TIMESTAMP | ||
| 273 | #define SO_PASSSEC 34 | ||
| 274 | #define SCM_TIMESTAMPNS SO_TIMESTAMPNS | ||
| 275 | #define SO_MARK 36 | ||
| 276 | #define SCM_TIMESTAMPING SO_TIMESTAMPING | ||
| 277 | #define SO_RXQ_OVFL 40 | ||
| 278 | #define SO_WIFI_STATUS 41 | ||
| 279 | #define SCM_WIFI_STATUS SO_WIFI_STATUS | ||
| 280 | #define SO_PEEK_OFF 42 | ||
| 281 | #define SO_NOFCS 43 | ||
| 282 | #define SO_LOCK_FILTER 44 | ||
| 283 | #define SO_SELECT_ERR_QUEUE 45 | ||
| 284 | #define SO_BUSY_POLL 46 | ||
| 285 | #define SO_MAX_PACING_RATE 47 | ||
| 286 | #define SO_BPF_EXTENSIONS 48 | ||
| 287 | #define SO_INCOMING_CPU 49 | ||
| 288 | #define SO_ATTACH_BPF 50 | ||
| 289 | #define SO_DETACH_BPF SO_DETACH_FILTER | ||
| 290 | #define SO_ATTACH_REUSEPORT_CBPF 51 | ||
| 291 | #define SO_ATTACH_REUSEPORT_EBPF 52 | ||
| 292 | #define SO_CNX_ADVICE 53 | ||
| 293 | #define SCM_TIMESTAMPING_OPT_STATS 54 | ||
| 294 | #define SO_MEMINFO 55 | ||
| 295 | #define SO_INCOMING_NAPI_ID 56 | ||
| 296 | #define SO_COOKIE 57 | ||
| 297 | #define SCM_TIMESTAMPING_PKTINFO 58 | ||
| 298 | #define SO_PEERGROUPS 59 | ||
| 299 | #define SO_ZEROCOPY 60 | ||
| 300 | #define SO_TXTIME 61 | ||
| 301 | #define SCM_TXTIME SO_TXTIME | ||
| 302 | #define SO_BINDTOIFINDEX 62 | ||
| 303 | #define SO_DETACH_REUSEPORT_BPF 68 | ||
| 304 | #define SO_PREFER_BUSY_POLL 69 | ||
| 305 | #define SO_BUSY_POLL_BUDGET 70 | ||
| 306 | |||
| 307 | #ifndef SOL_SOCKET | ||
| 308 | #define SOL_SOCKET 1 | ||
| 309 | #endif | ||
| 310 | |||
| 311 | #define SOL_IP 0 | ||
| 312 | #define SOL_IPV6 41 | ||
| 313 | #define SOL_ICMPV6 58 | ||
| 314 | |||
| 315 | #define SOL_RAW 255 | ||
| 316 | #define SOL_DECNET 261 | ||
| 317 | #define SOL_X25 262 | ||
| 318 | #define SOL_PACKET 263 | ||
| 319 | #define SOL_ATM 264 | ||
| 320 | #define SOL_AAL 265 | ||
| 321 | #define SOL_IRDA 266 | ||
| 322 | #define SOL_NETBEUI 267 | ||
| 323 | #define SOL_LLC 268 | ||
| 324 | #define SOL_DCCP 269 | ||
| 325 | #define SOL_NETLINK 270 | ||
| 326 | #define SOL_TIPC 271 | ||
| 327 | #define SOL_RXRPC 272 | ||
| 328 | #define SOL_PPPOL2TP 273 | ||
| 329 | #define SOL_BLUETOOTH 274 | ||
| 330 | #define SOL_PNPIPE 275 | ||
| 331 | #define SOL_RDS 276 | ||
| 332 | #define SOL_IUCV 277 | ||
| 333 | #define SOL_CAIF 278 | ||
| 334 | #define SOL_ALG 279 | ||
| 335 | #define SOL_NFC 280 | ||
| 336 | #define SOL_KCM 281 | ||
| 337 | #define SOL_TLS 282 | ||
| 338 | #define SOL_XDP 283 | ||
| 339 | |||
| 340 | #define SOMAXCONN 128 | ||
| 341 | |||
| 342 | #define MSG_OOB 0x0001 | ||
| 343 | #define MSG_PEEK 0x0002 | ||
| 344 | #define MSG_DONTROUTE 0x0004 | ||
| 345 | #define MSG_CTRUNC 0x0008 | ||
| 346 | #define MSG_PROXY 0x0010 | ||
| 347 | #define MSG_TRUNC 0x0020 | ||
| 348 | #define MSG_DONTWAIT 0x0040 | ||
| 349 | #define MSG_EOR 0x0080 | ||
| 350 | #define MSG_WAITALL 0x0100 | ||
| 351 | #define MSG_FIN 0x0200 | ||
| 352 | #define MSG_SYN 0x0400 | ||
| 353 | #define MSG_CONFIRM 0x0800 | ||
| 354 | #define MSG_RST 0x1000 | ||
| 355 | #define MSG_ERRQUEUE 0x2000 | ||
| 356 | #define MSG_NOSIGNAL 0x4000 | ||
| 357 | #define MSG_MORE 0x8000 | ||
| 358 | #define MSG_WAITFORONE 0x10000 | ||
| 359 | #define MSG_BATCH 0x40000 | ||
| 360 | #define MSG_ZEROCOPY 0x4000000 | ||
| 361 | #define MSG_FASTOPEN 0x20000000 | ||
| 362 | #define MSG_CMSG_CLOEXEC 0x40000000 | ||
| 363 | |||
| 364 | #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) | ||
| 365 | #define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) | ||
| 366 | #define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) | ||
| 367 | |||
| 368 | #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) | ||
| 369 | #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ | ||
| 370 | 	__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ | ||
| 371 | 	? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) | ||
| 372 | #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) | ||
| 373 | |||
| 374 | #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) | ||
| 375 | #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) | ||
| 376 | #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) | ||
| 377 | |||
| 378 | #define SCM_RIGHTS 0x01 | ||
| 379 | #define SCM_CREDENTIALS 0x02 | ||
| 380 | #endif | ||
| 381 | |||
| 382 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 383 | struct sockaddr { | ||
| 384 | 	sa_family_t sa_family; | ||
| 385 | 	char sa_data[14]; | ||
| 386 | }; | ||
| 387 | #else | ||
| 388 | #include <__struct_sockaddr.h> | ||
| 389 | #endif | ||
| 390 | |||
| 391 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 392 | struct sockaddr_storage { | ||
| 393 | 	sa_family_t ss_family; | ||
| 394 | 	char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; | ||
| 395 | 	unsigned long __ss_align; | ||
| 396 | }; | ||
| 397 | #else | ||
| 398 | #include <__struct_sockaddr_storage.h> | ||
| 399 | #endif | ||
| 400 | |||
| 401 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 402 | int socket (int, int, int); | ||
| 403 | #endif | ||
| 404 | |||
| 405 | #ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */ | ||
| 406 | int socketpair (int, int, int, int [2]); | ||
| 407 | #endif | ||
| 408 | |||
| 409 | int shutdown (int, int); | ||
| 410 | |||
| 411 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 412 | int connect (int, const struct sockaddr *, socklen_t); | ||
| 413 | int bind (int, const struct sockaddr *, socklen_t); | ||
| 414 | int listen (int, int); | ||
| 415 | #endif | ||
| 416 | |||
| 417 | int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 418 | int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); | ||
| 419 | |||
| 420 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 421 | int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 422 | int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 423 | #endif | ||
| 424 | |||
| 425 | ssize_t send (int, const void *, size_t, int); | ||
| 426 | ssize_t recv (int, void *, size_t, int); | ||
| 427 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 428 | ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); | ||
| 429 | ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 430 | #endif | ||
| 431 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ | ||
| 432 | ssize_t sendmsg (int, const struct msghdr *, int); | ||
| 433 | ssize_t recvmsg (int, struct msghdr *, int); | ||
| 434 | #endif | ||
| 435 | |||
| 436 | int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); | ||
| 437 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 438 | int setsockopt (int, int, int, const void *, socklen_t); | ||
| 439 | #endif | ||
| 440 | |||
| 441 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ | ||
| 442 | int sockatmark (int); | ||
| 443 | #endif | ||
| 444 | |||
| 445 | #if _REDIR_TIME64 | ||
| 446 | #ifdef _GNU_SOURCE | ||
| 447 | __REDIR(recvmmsg, __recvmmsg_time64); | ||
| 448 | #endif | ||
| 449 | #endif | ||
| 450 | |||
| 451 | #ifdef __cplusplus | ||
| 452 | } | ||
| 453 | #endif | ||
| 454 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/stat.h deleted-198| ... | @@ -1,198 +0,0 @@ | ||
| 1 | #ifndef	_SYS_STAT_H | ||
| 2 | #define	_SYS_STAT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_dev_t | ||
| 10 | #define __NEED_ino_t | ||
| 11 | #define __NEED_mode_t | ||
| 12 | #define __NEED_nlink_t | ||
| 13 | #define __NEED_uid_t | ||
| 14 | #define __NEED_gid_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | #define __NEED_time_t | ||
| 17 | #define __NEED_blksize_t | ||
| 18 | #define __NEED_blkcnt_t | ||
| 19 | #define __NEED_struct_timespec | ||
| 20 | |||
| 21 | #ifdef _GNU_SOURCE | ||
| 22 | #define __NEED_int64_t | ||
| 23 | #define __NEED_uint64_t | ||
| 24 | #define __NEED_uint32_t | ||
| 25 | #define __NEED_uint16_t | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #include <bits/alltypes.h> | ||
| 29 | |||
| 30 | #include <bits/stat.h> | ||
| 31 | |||
| 32 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 33 | #define st_atime st_atim.tv_sec | ||
| 34 | #define st_mtime st_mtim.tv_sec | ||
| 35 | #define st_ctime st_ctim.tv_sec | ||
| 36 | |||
| 37 | #define S_IFMT 0170000 | ||
| 38 | |||
| 39 | #define S_IFDIR 0040000 | ||
| 40 | #define S_IFCHR 0020000 | ||
| 41 | #define S_IFBLK 0060000 | ||
| 42 | #define S_IFREG 0100000 | ||
| 43 | #define S_IFIFO 0010000 | ||
| 44 | #define S_IFLNK 0120000 | ||
| 45 | #define S_IFSOCK 0140000 | ||
| 46 | |||
| 47 | #define S_TYPEISMQ(buf) 0 | ||
| 48 | #define S_TYPEISSEM(buf) 0 | ||
| 49 | #define S_TYPEISSHM(buf) 0 | ||
| 50 | #define S_TYPEISTMO(buf) 0 | ||
| 51 | |||
| 52 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | ||
| 53 | #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) | ||
| 54 | #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) | ||
| 55 | #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) | ||
| 56 | #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) | ||
| 57 | #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) | ||
| 58 | #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) | ||
| 59 | |||
| 60 | #ifndef S_IRUSR | ||
| 61 | #define S_ISUID 04000 | ||
| 62 | #define S_ISGID 02000 | ||
| 63 | #define S_ISVTX 01000 | ||
| 64 | #define S_IRUSR 0400 | ||
| 65 | #define S_IWUSR 0200 | ||
| 66 | #define S_IXUSR 0100 | ||
| 67 | #define S_IRWXU 0700 | ||
| 68 | #define S_IRGRP 0040 | ||
| 69 | #define S_IWGRP 0020 | ||
| 70 | #define S_IXGRP 0010 | ||
| 71 | #define S_IRWXG 0070 | ||
| 72 | #define S_IROTH 0004 | ||
| 73 | #define S_IWOTH 0002 | ||
| 74 | #define S_IXOTH 0001 | ||
| 75 | #define S_IRWXO 0007 | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #define UTIME_NOW 0x3fffffff | ||
| 79 | #define UTIME_OMIT 0x3ffffffe | ||
| 80 | #else | ||
| 81 | #include <__header_sys_stat.h> | ||
| 82 | #endif | ||
| 83 | |||
| 84 | int stat(const char *__restrict, struct stat *__restrict); | ||
| 85 | int fstat(int, struct stat *); | ||
| 86 | int lstat(const char *__restrict, struct stat *__restrict); | ||
| 87 | int fstatat(int, const char *__restrict, struct stat *__restrict, int); | ||
| 88 | int chmod(const char *, mode_t); | ||
| 89 | int fchmod(int, mode_t); | ||
| 90 | int fchmodat(int, const char *, mode_t, int); | ||
| 91 | #ifdef __wasilibc_unmodified_upstream /* WASI has no umask */ | ||
| 92 | mode_t umask(mode_t); | ||
| 93 | #endif | ||
| 94 | int mkdir(const char *, mode_t); | ||
| 95 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 96 | int mkfifo(const char *, mode_t); | ||
| 97 | #endif | ||
| 98 | int mkdirat(int, const char *, mode_t); | ||
| 99 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 100 | int mkfifoat(int, const char *, mode_t); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mknod */ | ||
| 104 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 105 | int mknod(const char *, mode_t, dev_t); | ||
| 106 | int mknodat(int, const char *, mode_t, dev_t); | ||
| 107 | #endif | ||
| 108 | #endif | ||
| 109 | |||
| 110 | int futimens(int, const struct timespec [2]); | ||
| 111 | int utimensat(int, const char *, const struct timespec [2], int); | ||
| 112 | |||
| 113 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 114 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ | ||
| 115 | int lchmod(const char *, mode_t); | ||
| 116 | #endif | ||
| 117 | #define S_IREAD S_IRUSR | ||
| 118 | #define S_IWRITE S_IWUSR | ||
| 119 | #define S_IEXEC S_IXUSR | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifdef __wasilibc_unmodified_upstream /* WASI has no statx */ | ||
| 123 | #if defined(_GNU_SOURCE) | ||
| 124 | #define STATX_TYPE 1U | ||
| 125 | #define STATX_MODE 2U | ||
| 126 | #define STATX_NLINK 4U | ||
| 127 | #define STATX_UID 8U | ||
| 128 | #define STATX_GID 0x10U | ||
| 129 | #define STATX_ATIME 0x20U | ||
| 130 | #define STATX_MTIME 0x40U | ||
| 131 | #define STATX_CTIME 0x80U | ||
| 132 | #define STATX_INO 0x100U | ||
| 133 | #define STATX_SIZE 0x200U | ||
| 134 | #define STATX_BLOCKS 0x400U | ||
| 135 | #define STATX_BASIC_STATS 0x7ffU | ||
| 136 | #define STATX_BTIME 0x800U | ||
| 137 | #define STATX_ALL 0xfffU | ||
| 138 | |||
| 139 | struct statx_timestamp { | ||
| 140 | 	int64_t tv_sec; | ||
| 141 | 	uint32_t tv_nsec, __pad; | ||
| 142 | }; | ||
| 143 | |||
| 144 | struct statx { | ||
| 145 | 	uint32_t stx_mask; | ||
| 146 | 	uint32_t stx_blksize; | ||
| 147 | 	uint64_t stx_attributes; | ||
| 148 | 	uint32_t stx_nlink; | ||
| 149 | 	uint32_t stx_uid; | ||
| 150 | 	uint32_t stx_gid; | ||
| 151 | 	uint16_t stx_mode; | ||
| 152 | 	uint16_t __pad0[1]; | ||
| 153 | 	uint64_t stx_ino; | ||
| 154 | 	uint64_t stx_size; | ||
| 155 | 	uint64_t stx_blocks; | ||
| 156 | 	uint64_t stx_attributes_mask; | ||
| 157 | 	struct statx_timestamp stx_atime; | ||
| 158 | 	struct statx_timestamp stx_btime; | ||
| 159 | 	struct statx_timestamp stx_ctime; | ||
| 160 | 	struct statx_timestamp stx_mtime; | ||
| 161 | 	uint32_t stx_rdev_major; | ||
| 162 | 	uint32_t stx_rdev_minor; | ||
| 163 | 	uint32_t stx_dev_major; | ||
| 164 | 	uint32_t stx_dev_minor; | ||
| 165 | 	uint64_t __pad1[14]; | ||
| 166 | }; | ||
| 167 | |||
| 168 | int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict); | ||
| 169 | #endif | ||
| 170 | #endif | ||
| 171 | |||
| 172 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 173 | #define stat64 stat | ||
| 174 | #define fstat64 fstat | ||
| 175 | #define lstat64 lstat | ||
| 176 | #define fstatat64 fstatat | ||
| 177 | #define blkcnt64_t blkcnt_t | ||
| 178 | #define fsblkcnt64_t fsblkcnt_t | ||
| 179 | #define fsfilcnt64_t fsfilcnt_t | ||
| 180 | #define ino64_t ino_t | ||
| 181 | #define off64_t off_t | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #if _REDIR_TIME64 | ||
| 185 | __REDIR(stat, __stat_time64); | ||
| 186 | __REDIR(fstat, __fstat_time64); | ||
| 187 | __REDIR(lstat, __lstat_time64); | ||
| 188 | __REDIR(fstatat, __fstatat_time64); | ||
| 189 | __REDIR(futimens, __futimens_time64); | ||
| 190 | __REDIR(utimensat, __utimensat_time64); | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #ifdef __cplusplus | ||
| 194 | } | ||
| 195 | #endif | ||
| 196 | #endif | ||
| 197 | |||
| 198 | |||
lib/libc/include/wasm-wasi-musl/sys/statvfs.h deleted-57| ... | @@ -1,57 +0,0 @@ | ||
| 1 | #ifndef	_SYS_STATVFS_H | ||
| 2 | #define	_SYS_STATVFS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_fsblkcnt_t | ||
| 11 | #define __NEED_fsfilcnt_t | ||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | struct statvfs { | ||
| 15 | 	unsigned long f_bsize, f_frsize; | ||
| 16 | 	fsblkcnt_t f_blocks, f_bfree, f_bavail; | ||
| 17 | 	fsfilcnt_t f_files, f_ffree, f_favail; | ||
| 18 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 19 | 	unsigned long f_fsid; | ||
| 20 | 	unsigned :8*(2*sizeof(int)-sizeof(long)); | ||
| 21 | #else | ||
| 22 | 	unsigned :8*(2*sizeof(int)-sizeof(long)); | ||
| 23 | 	unsigned long f_fsid; | ||
| 24 | #endif | ||
| 25 | 	unsigned long f_flag, f_namemax; | ||
| 26 | 	unsigned int f_type; | ||
| 27 | 	int __reserved[5]; | ||
| 28 | }; | ||
| 29 | |||
| 30 | int statvfs (const char *__restrict, struct statvfs *__restrict); | ||
| 31 | int fstatvfs (int, struct statvfs *); | ||
| 32 | |||
| 33 | #define ST_RDONLY 1 | ||
| 34 | #define ST_NOSUID 2 | ||
| 35 | #define ST_NODEV 4 | ||
| 36 | #define ST_NOEXEC 8 | ||
| 37 | #define ST_SYNCHRONOUS 16 | ||
| 38 | #define ST_MANDLOCK 64 | ||
| 39 | #define ST_WRITE 128 | ||
| 40 | #define ST_APPEND 256 | ||
| 41 | #define ST_IMMUTABLE 512 | ||
| 42 | #define ST_NOATIME 1024 | ||
| 43 | #define ST_NODIRATIME 2048 | ||
| 44 | #define ST_RELATIME 4096 | ||
| 45 | |||
| 46 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 47 | #define statvfs64 statvfs | ||
| 48 | #define fstatvfs64 fstatvfs | ||
| 49 | #define fsblkcnt64_t fsblkcnt_t | ||
| 50 | #define fsfilcnt64_t fsfilcnt_t | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #ifdef __cplusplus | ||
| 54 | } | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/syscall.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #ifndef _SYS_SYSCALL_H | ||
| 2 | #define _SYS_SYSCALL_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syscall */ | ||
| 5 | #include <bits/syscall.h> | ||
| 6 | #else | ||
| 7 | /* The generic syscall funtion is not yet implemented. */ | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/time.h deleted-84| ... | @@ -1,84 +0,0 @@ | ||
| 1 | #ifndef _SYS_TIME_H | ||
| 2 | #define _SYS_TIME_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #include <sys/select.h> | ||
| 10 | |||
| 11 | int gettimeofday (struct timeval *__restrict, void *__restrict); | ||
| 12 | |||
| 13 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getitimer */ | ||
| 14 | #define ITIMER_REAL 0 | ||
| 15 | #define ITIMER_VIRTUAL 1 | ||
| 16 | #define ITIMER_PROF 2 | ||
| 17 | |||
| 18 | struct itimerval { | ||
| 19 | 	struct timeval it_interval; | ||
| 20 | 	struct timeval it_value; | ||
| 21 | }; | ||
| 22 | |||
| 23 | int getitimer (int, struct itimerval *); | ||
| 24 | int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); | ||
| 25 | #endif | ||
| 26 | int utimes (const char *, const struct timeval [2]); | ||
| 27 | |||
| 28 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 29 | struct timezone { | ||
| 30 | 	int tz_minuteswest; | ||
| 31 | 	int tz_dsttime; | ||
| 32 | }; | ||
| 33 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 34 | int futimes(int, const struct timeval [2]); | ||
| 35 | #endif | ||
| 36 | int futimesat(int, const char *, const struct timeval [2]); | ||
| 37 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 38 | int lutimes(const char *, const struct timeval [2]); | ||
| 39 | #endif | ||
| 40 | #ifdef __wasilibc_unmodified_upstream /* WASI has no way to set the time */ | ||
| 41 | int settimeofday(const struct timeval *, const struct timezone *); | ||
| 42 | int adjtime (const struct timeval *, struct timeval *); | ||
| 43 | #endif | ||
| 44 | #define timerisset(t) ((t)->tv_sec || (t)->tv_usec) | ||
| 45 | #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) | ||
| 46 | #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ | ||
| 47 | 	(s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) | ||
| 48 | #define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ | ||
| 49 | 	((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ | ||
| 50 | 	((a)->tv_usec -= 1000000, (a)->tv_sec++) ) | ||
| 51 | #define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ | ||
| 52 | 	((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ | ||
| 53 | 	((a)->tv_usec += 1000000, (a)->tv_sec--) ) | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #if defined(_GNU_SOURCE) | ||
| 57 | #define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ | ||
| 58 | 	(ts)->tv_sec = (tv)->tv_sec, \ | ||
| 59 | 	(ts)->tv_nsec = (tv)->tv_usec * 1000, \ | ||
| 60 | 	(void)0 ) | ||
| 61 | #define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ | ||
| 62 | 	(tv)->tv_sec = (ts)->tv_sec, \ | ||
| 63 | 	(tv)->tv_usec = (ts)->tv_nsec / 1000, \ | ||
| 64 | 	(void)0 ) | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #if _REDIR_TIME64 | ||
| 68 | __REDIR(gettimeofday, __gettimeofday_time64); | ||
| 69 | __REDIR(getitimer, __getitimer_time64); | ||
| 70 | __REDIR(setitimer, __setitimer_time64); | ||
| 71 | __REDIR(utimes, __utimes_time64); | ||
| 72 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 73 | __REDIR(futimes, __futimes_time64); | ||
| 74 | __REDIR(futimesat, __futimesat_time64); | ||
| 75 | __REDIR(lutimes, __lutimes_time64); | ||
| 76 | __REDIR(settimeofday, __settimeofday_time64); | ||
| 77 | __REDIR(adjtime, __adjtime64); | ||
| 78 | #endif | ||
| 79 | #endif | ||
| 80 | |||
| 81 | #ifdef __cplusplus | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/times.h deleted-34| ... | @@ -1,34 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #error WASI lacks process-associated clocks; to enable emulation of the `times` function using \ | ||
| 3 | the wall clock, which isn't sensitive to whether the program is running or suspended, \ | ||
| 4 | compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks | ||
| 5 | #else | ||
| 6 | #ifndef	_SYS_TIMES_H | ||
| 7 | #define	_SYS_TIMES_H | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #define __NEED_clock_t | ||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 17 | struct tms { | ||
| 18 | 	clock_t tms_utime; | ||
| 19 | 	clock_t tms_stime; | ||
| 20 | 	clock_t tms_cutime; | ||
| 21 | 	clock_t tms_cstime; | ||
| 22 | }; | ||
| 23 | #else | ||
| 24 | #include <__struct_tms.h> | ||
| 25 | #endif | ||
| 26 | |||
| 27 | clock_t times (struct tms *); | ||
| 28 | |||
| 29 | #ifdef __cplusplus | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #endif | ||
| 34 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/types.h deleted-85| ... | @@ -1,85 +0,0 @@ | ||
| 1 | #ifndef	_SYS_TYPES_H | ||
| 2 | #define	_SYS_TYPES_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_ino_t | ||
| 10 | #define __NEED_dev_t | ||
| 11 | #define __NEED_uid_t | ||
| 12 | #define __NEED_gid_t | ||
| 13 | #define __NEED_mode_t | ||
| 14 | #define __NEED_nlink_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | #define __NEED_pid_t | ||
| 17 | #define __NEED_size_t | ||
| 18 | #define __NEED_ssize_t | ||
| 19 | #define __NEED_time_t | ||
| 20 | #define __NEED_timer_t | ||
| 21 | #define __NEED_clockid_t | ||
| 22 | |||
| 23 | #define __NEED_blkcnt_t | ||
| 24 | #define __NEED_fsblkcnt_t | ||
| 25 | #define __NEED_fsfilcnt_t | ||
| 26 | |||
| 27 | #define __NEED_id_t | ||
| 28 | #define __NEED_key_t | ||
| 29 | #define __NEED_clock_t | ||
| 30 | #define __NEED_suseconds_t | ||
| 31 | #define __NEED_blksize_t | ||
| 32 | |||
| 33 | #define __NEED_pthread_t | ||
| 34 | #define __NEED_pthread_attr_t | ||
| 35 | #define __NEED_pthread_mutexattr_t | ||
| 36 | #define __NEED_pthread_condattr_t | ||
| 37 | #define __NEED_pthread_rwlockattr_t | ||
| 38 | #define __NEED_pthread_barrierattr_t | ||
| 39 | #define __NEED_pthread_mutex_t | ||
| 40 | #define __NEED_pthread_cond_t | ||
| 41 | #define __NEED_pthread_rwlock_t | ||
| 42 | #define __NEED_pthread_barrier_t | ||
| 43 | #define __NEED_pthread_spinlock_t | ||
| 44 | #define __NEED_pthread_key_t | ||
| 45 | #define __NEED_pthread_once_t | ||
| 46 | #define __NEED_useconds_t | ||
| 47 | |||
| 48 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 49 | #define __NEED_int8_t | ||
| 50 | #define __NEED_int16_t | ||
| 51 | #define __NEED_int32_t | ||
| 52 | #define __NEED_int64_t | ||
| 53 | #define __NEED_u_int64_t | ||
| 54 | #define __NEED_register_t | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #include <bits/alltypes.h> | ||
| 58 | |||
| 59 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 60 | typedef unsigned char u_int8_t; | ||
| 61 | typedef unsigned short u_int16_t; | ||
| 62 | typedef unsigned u_int32_t; | ||
| 63 | typedef char *caddr_t; | ||
| 64 | typedef unsigned char u_char; | ||
| 65 | typedef unsigned short u_short, ushort; | ||
| 66 | typedef unsigned u_int, uint; | ||
| 67 | typedef unsigned long u_long, ulong; | ||
| 68 | typedef long long quad_t; | ||
| 69 | typedef unsigned long long u_quad_t; | ||
| 70 | #include <endian.h> | ||
| 71 | #include <sys/select.h> | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 75 | #define blkcnt64_t blkcnt_t | ||
| 76 | #define fsblkcnt64_t fsblkcnt_t | ||
| 77 | #define fsfilcnt64_t fsfilcnt_t | ||
| 78 | #define ino64_t ino_t | ||
| 79 | #define off64_t off_t | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifdef __cplusplus | ||
| 83 | } | ||
| 84 | #endif | ||
| 85 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/uio.h deleted-57| ... | @@ -1,57 +0,0 @@ | ||
| 1 | #ifndef _SYS_UIO_H | ||
| 2 | #define _SYS_UIO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | #define __NEED_ssize_t | ||
| 12 | #define __NEED_struct_iovec | ||
| 13 | |||
| 14 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 15 | #define __NEED_off_t | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __NEED_pid_t | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #include <bits/alltypes.h> | ||
| 23 | |||
| 24 | #define UIO_MAXIOV 1024 | ||
| 25 | |||
| 26 | ssize_t readv (int, const struct iovec *, int); | ||
| 27 | ssize_t writev (int, const struct iovec *, int); | ||
| 28 | |||
| 29 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 30 | ssize_t preadv (int, const struct iovec *, int, off_t); | ||
| 31 | ssize_t pwritev (int, const struct iovec *, int, off_t); | ||
| 32 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 33 | #define preadv64 preadv | ||
| 34 | #define pwritev64 pwritev | ||
| 35 | #define off64_t off_t | ||
| 36 | #endif | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have these Linux-specific functions | ||
| 40 | #ifdef _GNU_SOURCE | ||
| 41 | ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 42 | ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 43 | ssize_t preadv2 (int, const struct iovec *, int, off_t, int); | ||
| 44 | ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); | ||
| 45 | #define RWF_HIPRI 0x00000001 | ||
| 46 | #define RWF_DSYNC 0x00000002 | ||
| 47 | #define RWF_SYNC 0x00000004 | ||
| 48 | #define RWF_NOWAIT 0x00000008 | ||
| 49 | #define RWF_APPEND 0x00000010 | ||
| 50 | #endif | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #ifdef __cplusplus | ||
| 54 | } | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/un.h deleted-39| ... | @@ -1,39 +0,0 @@ | ||
| 1 | #ifndef	_SYS_UN_H | ||
| 2 | #define	_SYS_UN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_sa_family_t | ||
| 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 12 | #define __NEED_size_t | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #include <bits/alltypes.h> | ||
| 16 | |||
| 17 | #ifdef __wasilibc_unmodified_upstream /* WASI has no UNIX-domain sockets */ | ||
| 18 | struct sockaddr_un { | ||
| 19 | 	sa_family_t sun_family; | ||
| 20 | 	char sun_path[108]; | ||
| 21 | }; | ||
| 22 | #else | ||
| 23 | #include <__struct_sockaddr_un.h> | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 27 | #ifdef __wasilibc_unmodified_upstream /* Declare strlen with the same attributes as <string.h> uses */ | ||
| 28 | size_t strlen(const char *); | ||
| 29 | #else | ||
| 30 | size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); | ||
| 31 | #endif | ||
| 32 | #define SUN_LEN(s) (2+strlen((s)->sun_path)) | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #ifdef __cplusplus | ||
| 36 | } | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/include/wasm-wasi-musl/time.h deleted-204| ... | @@ -1,204 +0,0 @@ | ||
| 1 | #ifndef	_TIME_H | ||
| 2 | #define _TIME_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 11 | #if __cplusplus >= 201103L | ||
| 12 | #define NULL nullptr | ||
| 13 | #elif defined(__cplusplus) | ||
| 14 | #define NULL 0L | ||
| 15 | #else | ||
| 16 | #define NULL ((void*)0) | ||
| 17 | #endif | ||
| 18 | #else | ||
| 19 | #define __need_NULL | ||
| 20 | #include <stddef.h> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | |||
| 24 | #define __NEED_size_t | ||
| 25 | #define __NEED_time_t | ||
| 26 | #define __NEED_clock_t | ||
| 27 | #define __NEED_struct_timespec | ||
| 28 | |||
| 29 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 30 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 31 | || defined(_BSD_SOURCE) | ||
| 32 | #define __NEED_clockid_t | ||
| 33 | #define __NEED_timer_t | ||
| 34 | #define __NEED_pid_t | ||
| 35 | #define __NEED_locale_t | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #include <bits/alltypes.h> | ||
| 39 | |||
| 40 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 41 | #define __tm_gmtoff tm_gmtoff | ||
| 42 | #define __tm_zone tm_zone | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 46 | struct tm { | ||
| 47 | 	int tm_sec; | ||
| 48 | 	int tm_min; | ||
| 49 | 	int tm_hour; | ||
| 50 | 	int tm_mday; | ||
| 51 | 	int tm_mon; | ||
| 52 | 	int tm_year; | ||
| 53 | 	int tm_wday; | ||
| 54 | 	int tm_yday; | ||
| 55 | 	int tm_isdst; | ||
| 56 | 	long __tm_gmtoff; | ||
| 57 | 	const char *__tm_zone; | ||
| 58 | }; | ||
| 59 | #else | ||
| 60 | #include <__header_time.h> | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) | ||
| 64 | clock_t clock (void); | ||
| 65 | #else | ||
| 66 | __attribute__((__deprecated__( | ||
| 67 | "WASI lacks process-associated clocks; to enable emulation of the `clock` function using " | ||
| 68 | "the wall clock, which isn't sensitive to whether the program is running or suspended, " | ||
| 69 | "compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks" | ||
| 70 | ))) | ||
| 71 | clock_t clock (void); | ||
| 72 | #endif | ||
| 73 | time_t time (time_t *); | ||
| 74 | double difftime (time_t, time_t); | ||
| 75 | time_t mktime (struct tm *); | ||
| 76 | size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); | ||
| 77 | struct tm *gmtime (const time_t *); | ||
| 78 | struct tm *localtime (const time_t *); | ||
| 79 | char *asctime (const struct tm *); | ||
| 80 | char *ctime (const time_t *); | ||
| 81 | int timespec_get(struct timespec *, int); | ||
| 82 | |||
| 83 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 84 | #define CLOCKS_PER_SEC 1000000L | ||
| 85 | |||
| 86 | #define TIME_UTC 1 | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 90 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 91 | || defined(_BSD_SOURCE) | ||
| 92 | |||
| 93 | size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); | ||
| 94 | |||
| 95 | struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 96 | struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 97 | char *asctime_r (const struct tm *__restrict, char *__restrict); | ||
| 98 | char *ctime_r (const time_t *, char *); | ||
| 99 | |||
| 100 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 101 | void tzset (void); | ||
| 102 | #endif | ||
| 103 | |||
| 104 | struct itimerspec { | ||
| 105 | 	struct timespec it_interval; | ||
| 106 | 	struct timespec it_value; | ||
| 107 | }; | ||
| 108 | |||
| 109 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 110 | #define CLOCK_REALTIME 0 | ||
| 111 | #define CLOCK_MONOTONIC 1 | ||
| 112 | #define CLOCK_PROCESS_CPUTIME_ID 2 | ||
| 113 | #define CLOCK_THREAD_CPUTIME_ID 3 | ||
| 114 | #define CLOCK_MONOTONIC_RAW 4 | ||
| 115 | #define CLOCK_REALTIME_COARSE 5 | ||
| 116 | #define CLOCK_MONOTONIC_COARSE 6 | ||
| 117 | #define CLOCK_BOOTTIME 7 | ||
| 118 | #define CLOCK_REALTIME_ALARM 8 | ||
| 119 | #define CLOCK_BOOTTIME_ALARM 9 | ||
| 120 | #define CLOCK_SGI_CYCLE 10 | ||
| 121 | #define CLOCK_TAI 11 | ||
| 122 | |||
| 123 | #define TIMER_ABSTIME 1 | ||
| 124 | #endif | ||
| 125 | |||
| 126 | int nanosleep (const struct timespec *, struct timespec *); | ||
| 127 | int clock_getres (clockid_t, struct timespec *); | ||
| 128 | int clock_gettime (clockid_t, struct timespec *); | ||
| 129 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */ | ||
| 130 | int clock_settime (clockid_t, const struct timespec *); | ||
| 131 | #endif | ||
| 132 | int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); | ||
| 133 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */ | ||
| 134 | int clock_getcpuclockid (pid_t, clockid_t *); | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timers */ | ||
| 138 | struct sigevent; | ||
| 139 | int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); | ||
| 140 | int timer_delete (timer_t); | ||
| 141 | int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); | ||
| 142 | int timer_gettime (timer_t, struct itimerspec *); | ||
| 143 | int timer_getoverrun (timer_t); | ||
| 144 | #endif | ||
| 145 | |||
| 146 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 147 | extern char *tzname[2]; | ||
| 148 | #endif | ||
| 149 | |||
| 150 | #endif | ||
| 151 | |||
| 152 | |||
| 153 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 154 | char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); | ||
| 155 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 156 | extern int daylight; | ||
| 157 | extern long timezone; | ||
| 158 | #endif | ||
| 159 | extern int getdate_err; | ||
| 160 | struct tm *getdate (const char *); | ||
| 161 | #endif | ||
| 162 | |||
| 163 | |||
| 164 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 165 | #ifdef __wasilibc_unmodified_upstream /* WASI has no stime */ | ||
| 166 | int stime(const time_t *); | ||
| 167 | #endif | ||
| 168 | time_t timegm(struct tm *); | ||
| 169 | #endif | ||
| 170 | |||
| 171 | #if _REDIR_TIME64 | ||
| 172 | __REDIR(time, __time64); | ||
| 173 | __REDIR(difftime, __difftime64); | ||
| 174 | __REDIR(mktime, __mktime64); | ||
| 175 | __REDIR(gmtime, __gmtime64); | ||
| 176 | __REDIR(localtime, __localtime64); | ||
| 177 | __REDIR(ctime, __ctime64); | ||
| 178 | __REDIR(timespec_get, __timespec_get_time64); | ||
| 179 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 180 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 181 | || defined(_BSD_SOURCE) | ||
| 182 | __REDIR(gmtime_r, __gmtime64_r); | ||
| 183 | __REDIR(localtime_r, __localtime64_r); | ||
| 184 | __REDIR(ctime_r, __ctime64_r); | ||
| 185 | __REDIR(nanosleep, __nanosleep_time64); | ||
| 186 | __REDIR(clock_getres, __clock_getres_time64); | ||
| 187 | __REDIR(clock_gettime, __clock_gettime64); | ||
| 188 | __REDIR(clock_settime, __clock_settime64); | ||
| 189 | __REDIR(clock_nanosleep, __clock_nanosleep_time64); | ||
| 190 | __REDIR(timer_settime, __timer_settime64); | ||
| 191 | __REDIR(timer_gettime, __timer_gettime64); | ||
| 192 | #endif | ||
| 193 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 194 | __REDIR(stime, __stime64); | ||
| 195 | __REDIR(timegm, __timegm_time64); | ||
| 196 | #endif | ||
| 197 | #endif | ||
| 198 | |||
| 199 | #ifdef __cplusplus | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | |||
| 203 | |||
| 204 | #endif | ||
lib/libc/include/wasm-wasi-musl/unistd.h deleted-589| ... | @@ -1,589 +0,0 @@ | ||
| 1 | #ifndef	_UNISTD_H | ||
| 2 | #define	_UNISTD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define STDIN_FILENO 0 | ||
| 11 | #define STDOUT_FILENO 1 | ||
| 12 | #define STDERR_FILENO 2 | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 15 | #define SEEK_SET 0 | ||
| 16 | #define SEEK_CUR 1 | ||
| 17 | #define SEEK_END 2 | ||
| 18 | #define SEEK_DATA 3 | ||
| 19 | #define SEEK_HOLE 4 | ||
| 20 | #else | ||
| 21 | #include <__header_unistd.h> | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 25 | #if __cplusplus >= 201103L | ||
| 26 | #define NULL nullptr | ||
| 27 | #elif defined(__cplusplus) | ||
| 28 | #define NULL 0L | ||
| 29 | #else | ||
| 30 | #define NULL ((void*)0) | ||
| 31 | #endif | ||
| 32 | #else | ||
| 33 | #define __need_NULL | ||
| 34 | #include <stddef.h> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #define __NEED_size_t | ||
| 38 | #define __NEED_ssize_t | ||
| 39 | #define __NEED_uid_t | ||
| 40 | #define __NEED_gid_t | ||
| 41 | #define __NEED_off_t | ||
| 42 | #define __NEED_pid_t | ||
| 43 | #define __NEED_intptr_t | ||
| 44 | #define __NEED_useconds_t | ||
| 45 | |||
| 46 | #include <bits/alltypes.h> | ||
| 47 | |||
| 48 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pipe */ | ||
| 49 | int pipe(int [2]); | ||
| 50 | int pipe2(int [2], int); | ||
| 51 | #endif | ||
| 52 | int close(int); | ||
| 53 | int posix_close(int, int); | ||
| 54 | #ifdef __wasilibc_unmodified_upstream /* WASI has no dup */ | ||
| 55 | int dup(int); | ||
| 56 | int dup2(int, int); | ||
| 57 | int dup3(int, int, int); | ||
| 58 | #endif | ||
| 59 | off_t lseek(int, off_t, int); | ||
| 60 | #ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */ | ||
| 61 | #else | ||
| 62 | off_t __wasilibc_tell(int); | ||
| 63 | |||
| 64 | #ifndef __cplusplus | ||
| 65 | /* | ||
| 66 | * Optimize lseek in the case where it's just returning the current offset. | ||
| 67 | * This avoids importing `__wasi_fd_seek` altogether in many common cases. | ||
| 68 | * | ||
| 69 | * But don't do this for C++ because a simple macro wouldn't handle namespaces | ||
| 70 | * correctly: | ||
| 71 | * - User code could qualify the `lseek` call with `::`. | ||
| 72 | * - There may be another `lseek` in scope from a `using` declaration. | ||
| 73 | */ | ||
| 74 | #define lseek(fd, offset, whence) \ | ||
| 75 | ({ \ | ||
| 76 | off_t __f = (fd); \ | ||
| 77 | off_t __o = (offset); \ | ||
| 78 | off_t __w = (whence); \ | ||
| 79 | __builtin_constant_p((offset)) && \ | ||
| 80 | __builtin_constant_p((whence)) && \ | ||
| 81 | __o == 0 && \ | ||
| 82 | __w == SEEK_CUR \ | ||
| 83 | ? __wasilibc_tell(__f) \ | ||
| 84 | : lseek(__f, __o, __w); \ | ||
| 85 | }) | ||
| 86 | #endif | ||
| 87 | #endif | ||
| 88 | int fsync(int); | ||
| 89 | int fdatasync(int); | ||
| 90 | |||
| 91 | ssize_t read(int, void *, size_t); | ||
| 92 | ssize_t write(int, const void *, size_t); | ||
| 93 | ssize_t pread(int, void *, size_t, off_t); | ||
| 94 | ssize_t pwrite(int, const void *, size_t, off_t); | ||
| 95 | |||
| 96 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chown */ | ||
| 97 | int chown(const char *, uid_t, gid_t); | ||
| 98 | int fchown(int, uid_t, gid_t); | ||
| 99 | int lchown(const char *, uid_t, gid_t); | ||
| 100 | int fchownat(int, const char *, uid_t, gid_t, int); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | int link(const char *, const char *); | ||
| 104 | int linkat(int, const char *, int, const char *, int); | ||
| 105 | int symlink(const char *, const char *); | ||
| 106 | int symlinkat(const char *, int, const char *); | ||
| 107 | ssize_t readlink(const char *__restrict, char *__restrict, size_t); | ||
| 108 | ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); | ||
| 109 | int unlink(const char *); | ||
| 110 | int unlinkat(int, const char *, int); | ||
| 111 | int rmdir(const char *); | ||
| 112 | int truncate(const char *, off_t); | ||
| 113 | int ftruncate(int, off_t); | ||
| 114 | |||
| 115 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 116 | #define F_OK 0 | ||
| 117 | #define R_OK 4 | ||
| 118 | #define W_OK 2 | ||
| 119 | #define X_OK 1 | ||
| 120 | #endif | ||
| 121 | |||
| 122 | int access(const char *, int); | ||
| 123 | int faccessat(int, const char *, int, int); | ||
| 124 | |||
| 125 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fchdir */ | ||
| 126 | int fchdir(int); | ||
| 127 | #endif | ||
| 128 | int chdir(const char *); | ||
| 129 | char *getcwd(char *, size_t); | ||
| 130 | |||
| 131 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 132 | unsigned alarm(unsigned); | ||
| 133 | #endif | ||
| 134 | unsigned sleep(unsigned); | ||
| 135 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ | ||
| 136 | int pause(void); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ | ||
| 140 | pid_t fork(void); | ||
| 141 | pid_t _Fork(void); | ||
| 142 | int execve(const char *, char *const [], char *const []); | ||
| 143 | int execv(const char *, char *const []); | ||
| 144 | int execle(const char *, const char *, ...); | ||
| 145 | int execl(const char *, const char *, ...); | ||
| 146 | int execvp(const char *, char *const []); | ||
| 147 | int execlp(const char *, const char *, ...); | ||
| 148 | int fexecve(int, char *const [], char *const []); | ||
| 149 | #endif | ||
| 150 | _Noreturn void _exit(int); | ||
| 151 | |||
| 152 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_GETPID) | ||
| 153 | pid_t getpid(void); | ||
| 154 | #else | ||
| 155 | __attribute__((__deprecated__( | ||
| 156 | "WASI lacks process identifiers; to enable emulation of the `getpid` function using " | ||
| 157 | "a placeholder value, which doesn't reflect the host PID of the program, " | ||
| 158 | "compile with -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid" | ||
| 159 | ))) | ||
| 160 | pid_t getpid(void); | ||
| 161 | #endif | ||
| 162 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getpid etc. */ | ||
| 163 | pid_t getppid(void); | ||
| 164 | pid_t getpgrp(void); | ||
| 165 | pid_t getpgid(pid_t); | ||
| 166 | int setpgid(pid_t, pid_t); | ||
| 167 | pid_t setsid(void); | ||
| 168 | pid_t getsid(pid_t); | ||
| 169 | #endif | ||
| 170 | #ifdef __wasilibc_unmodified_upstream /* WASI has no ttyname */ | ||
| 171 | char *ttyname(int); | ||
| 172 | int ttyname_r(int, char *, size_t); | ||
| 173 | #endif | ||
| 174 | int isatty(int); | ||
| 175 | #ifdef __wasilibc_unmodified_upstream /* WASI has no process groups */ | ||
| 176 | pid_t tcgetpgrp(int); | ||
| 177 | int tcsetpgrp(int, pid_t); | ||
| 178 | #endif | ||
| 179 | |||
| 180 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getuid etc. */ | ||
| 181 | uid_t getuid(void); | ||
| 182 | uid_t geteuid(void); | ||
| 183 | gid_t getgid(void); | ||
| 184 | gid_t getegid(void); | ||
| 185 | int getgroups(int, gid_t []); | ||
| 186 | int setuid(uid_t); | ||
| 187 | int seteuid(uid_t); | ||
| 188 | int setgid(gid_t); | ||
| 189 | int setegid(gid_t); | ||
| 190 | #endif | ||
| 191 | |||
| 192 | char *getlogin(void); | ||
| 193 | int getlogin_r(char *, size_t); | ||
| 194 | int gethostname(char *, size_t); | ||
| 195 | char *ctermid(char *); | ||
| 196 | |||
| 197 | int getopt(int, char * const [], const char *); | ||
| 198 | extern char *optarg; | ||
| 199 | extern int optind, opterr, optopt; | ||
| 200 | |||
| 201 | long pathconf(const char *, int); | ||
| 202 | long fpathconf(int, int); | ||
| 203 | long sysconf(int); | ||
| 204 | size_t confstr(int, char *, size_t); | ||
| 205 | |||
| 206 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 207 | #define F_ULOCK 0 | ||
| 208 | #define F_LOCK 1 | ||
| 209 | #define F_TLOCK 2 | ||
| 210 | #define F_TEST 3 | ||
| 211 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setreuid */ | ||
| 212 | int setreuid(uid_t, uid_t); | ||
| 213 | int setregid(gid_t, gid_t); | ||
| 214 | #endif | ||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 216 | int lockf(int, int, off_t); | ||
| 217 | #endif | ||
| 218 | long gethostid(void); | ||
| 219 | #ifdef __wasilibc_unmodified_upstream /* WASI has no nice, sync, or setpgrp */ | ||
| 220 | int nice(int); | ||
| 221 | void sync(void); | ||
| 222 | pid_t setpgrp(void); | ||
| 223 | #endif | ||
| 224 | char *crypt(const char *, const char *); | ||
| 225 | void encrypt(char *, int); | ||
| 226 | void swab(const void *__restrict, void *__restrict, ssize_t); | ||
| 227 | #endif | ||
| 228 | |||
| 229 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 230 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 231 | int usleep(unsigned); | ||
| 232 | unsigned ualarm(unsigned, unsigned); | ||
| 233 | #endif | ||
| 234 | |||
| 235 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 236 | #define L_SET 0 | ||
| 237 | #define L_INCR 1 | ||
| 238 | #define L_XTND 2 | ||
| 239 | #ifdef __wasilibc_unmodified_upstream /* WASI has no brk */ | ||
| 240 | int brk(void *); | ||
| 241 | #endif | ||
| 242 | void *sbrk(intptr_t); | ||
| 243 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 244 | pid_t vfork(void); | ||
| 245 | int vhangup(void); | ||
| 246 | int chroot(const char *); | ||
| 247 | #endif | ||
| 248 | int getpagesize(void); | ||
| 249 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 250 | int getdtablesize(void); | ||
| 251 | int sethostname(const char *, size_t); | ||
| 252 | int getdomainname(char *, size_t); | ||
| 253 | int setdomainname(const char *, size_t); | ||
| 254 | int setgroups(size_t, const gid_t *); | ||
| 255 | char *getpass(const char *); | ||
| 256 | int daemon(int, int); | ||
| 257 | void setusershell(void); | ||
| 258 | void endusershell(void); | ||
| 259 | char *getusershell(void); | ||
| 260 | int acct(const char *); | ||
| 261 | long syscall(long, ...); | ||
| 262 | int execvpe(const char *, char *const [], char *const []); | ||
| 263 | int issetugid(void); | ||
| 264 | #endif | ||
| 265 | int getentropy(void *, size_t); | ||
| 266 | extern int optreset; | ||
| 267 | #endif | ||
| 268 | |||
| 269 | #ifdef _GNU_SOURCE | ||
| 270 | extern char **environ; | ||
| 271 | #ifdef __wasilibc_unmodified_upstream /* WASI has no get/setresuid */ | ||
| 272 | int setresuid(uid_t, uid_t, uid_t); | ||
| 273 | int setresgid(gid_t, gid_t, gid_t); | ||
| 274 | int getresuid(uid_t *, uid_t *, uid_t *); | ||
| 275 | int getresgid(gid_t *, gid_t *, gid_t *); | ||
| 276 | #endif | ||
| 277 | #ifdef __wasilibc_unmodified_upstream /* WASI has no cwd */ | ||
| 278 | char *get_current_dir_name(void); | ||
| 279 | #endif | ||
| 280 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syncfs */ | ||
| 281 | int syncfs(int); | ||
| 282 | #endif | ||
| 283 | #ifdef __wasilibc_unmodified_upstream /* WASI has no eaccess */ | ||
| 284 | int euidaccess(const char *, int); | ||
| 285 | int eaccess(const char *, int); | ||
| 286 | ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 287 | pid_t gettid(void); | ||
| 288 | #endif | ||
| 289 | #endif | ||
| 290 | |||
| 291 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 292 | #define lseek64 lseek | ||
| 293 | #define pread64 pread | ||
| 294 | #define pwrite64 pwrite | ||
| 295 | #ifdef __wasilibc_unmodified_upstream /* WASI has no truncate */ | ||
| 296 | #define truncate64 truncate | ||
| 297 | #endif | ||
| 298 | #define ftruncate64 ftruncate | ||
| 299 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 300 | #define lockf64 lockf | ||
| 301 | #endif | ||
| 302 | #define off64_t off_t | ||
| 303 | #endif | ||
| 304 | |||
| 305 | #define POSIX_CLOSE_RESTART 0 | ||
| 306 | |||
| 307 | #define _XOPEN_VERSION 700 | ||
| 308 | #define _XOPEN_UNIX 1 | ||
| 309 | #define _XOPEN_ENH_I18N 1 | ||
| 310 | |||
| 311 | #define _POSIX_VERSION 200809L | ||
| 312 | #define _POSIX2_VERSION _POSIX_VERSION | ||
| 313 | |||
| 314 | #define _POSIX_ADVISORY_INFO _POSIX_VERSION | ||
| 315 | #define _POSIX_CHOWN_RESTRICTED 1 | ||
| 316 | #define _POSIX_IPV6 _POSIX_VERSION | ||
| 317 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes, mmap, or mq */ | ||
| 318 | #define _POSIX_JOB_CONTROL 1 | ||
| 319 | #define _POSIX_MAPPED_FILES _POSIX_VERSION | ||
| 320 | #define _POSIX_MEMLOCK _POSIX_VERSION | ||
| 321 | #define _POSIX_MEMLOCK_RANGE _POSIX_VERSION | ||
| 322 | #define _POSIX_MEMORY_PROTECTION _POSIX_VERSION | ||
| 323 | #define _POSIX_MESSAGE_PASSING _POSIX_VERSION | ||
| 324 | #endif | ||
| 325 | #define _POSIX_FSYNC _POSIX_VERSION | ||
| 326 | #define _POSIX_NO_TRUNC 1 | ||
| 327 | #ifdef __wasilibc_unmodified_upstream /* WASI has no raw sockets */ | ||
| 328 | #define _POSIX_RAW_SOCKETS _POSIX_VERSION | ||
| 329 | #endif | ||
| 330 | #define _POSIX_REALTIME_SIGNALS _POSIX_VERSION | ||
| 331 | #define _POSIX_REGEXP 1 | ||
| 332 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 333 | #define _POSIX_SAVED_IDS 1 | ||
| 334 | #define _POSIX_SHELL 1 | ||
| 335 | #define _POSIX_SPAWN _POSIX_VERSION | ||
| 336 | #endif | ||
| 337 | #define _POSIX_VDISABLE 0 | ||
| 338 | |||
| 339 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 340 | #define _POSIX_THREADS _POSIX_VERSION | ||
| 341 | #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION | ||
| 342 | #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION | ||
| 343 | #endif | ||
| 344 | #if defined(__wasilibc_unmodified_upstream) /* wasi-libc doesn't provide pthread_attr_{get,set}stackaddr */ | ||
| 345 | #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION | ||
| 346 | #endif | ||
| 347 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 348 | #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION | ||
| 349 | #endif | ||
| 350 | #if defined(__wasilibc_unmodified_upstream) /* WASI has no scheduling control, and wasi-libc doesn't provide pthread_getcpuclockid */ | ||
| 351 | #define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION | ||
| 352 | #define _POSIX_THREAD_CPUTIME _POSIX_VERSION | ||
| 353 | #endif | ||
| 354 | #define _POSIX_TIMERS _POSIX_VERSION | ||
| 355 | #define _POSIX_TIMEOUTS _POSIX_VERSION | ||
| 356 | #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION | ||
| 357 | #define _POSIX_CPUTIME _POSIX_VERSION | ||
| 358 | #define _POSIX_CLOCK_SELECTION _POSIX_VERSION | ||
| 359 | #define _POSIX_BARRIERS _POSIX_VERSION | ||
| 360 | #define _POSIX_SPIN_LOCKS _POSIX_VERSION | ||
| 361 | #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION | ||
| 362 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX async I/O, semaphores, or shared memory */ | ||
| 363 | #define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION | ||
| 364 | #define _POSIX_SEMAPHORES _POSIX_VERSION | ||
| 365 | #define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION | ||
| 366 | #endif | ||
| 367 | |||
| 368 | #define _POSIX2_C_BIND _POSIX_VERSION | ||
| 369 | |||
| 370 | #include <bits/posix.h> | ||
| 371 | |||
| 372 | |||
| 373 | |||
| 374 | #define _PC_LINK_MAX	0 | ||
| 375 | #define _PC_MAX_CANON	1 | ||
| 376 | #define _PC_MAX_INPUT	2 | ||
| 377 | #define _PC_NAME_MAX	3 | ||
| 378 | #define _PC_PATH_MAX	4 | ||
| 379 | #define _PC_PIPE_BUF	5 | ||
| 380 | #define _PC_CHOWN_RESTRICTED	6 | ||
| 381 | #define _PC_NO_TRUNC	7 | ||
| 382 | #define _PC_VDISABLE	8 | ||
| 383 | #define _PC_SYNC_IO	9 | ||
| 384 | #define _PC_ASYNC_IO	10 | ||
| 385 | #define _PC_PRIO_IO	11 | ||
| 386 | #define _PC_SOCK_MAXBUF	12 | ||
| 387 | #define _PC_FILESIZEBITS	13 | ||
| 388 | #define _PC_REC_INCR_XFER_SIZE	14 | ||
| 389 | #define _PC_REC_MAX_XFER_SIZE	15 | ||
| 390 | #define _PC_REC_MIN_XFER_SIZE	16 | ||
| 391 | #define _PC_REC_XFER_ALIGN	17 | ||
| 392 | #define _PC_ALLOC_SIZE_MIN	18 | ||
| 393 | #define _PC_SYMLINK_MAX	19 | ||
| 394 | #define _PC_2_SYMLINKS	20 | ||
| 395 | |||
| 396 | #define _SC_ARG_MAX	0 | ||
| 397 | #define _SC_CHILD_MAX	1 | ||
| 398 | #define _SC_CLK_TCK	2 | ||
| 399 | #define _SC_NGROUPS_MAX	3 | ||
| 400 | #define _SC_OPEN_MAX	4 | ||
| 401 | #define _SC_STREAM_MAX	5 | ||
| 402 | #define _SC_TZNAME_MAX	6 | ||
| 403 | #define _SC_JOB_CONTROL	7 | ||
| 404 | #define _SC_SAVED_IDS	8 | ||
| 405 | #define _SC_REALTIME_SIGNALS	9 | ||
| 406 | #define _SC_PRIORITY_SCHEDULING	10 | ||
| 407 | #define _SC_TIMERS	11 | ||
| 408 | #define _SC_ASYNCHRONOUS_IO	12 | ||
| 409 | #define _SC_PRIORITIZED_IO	13 | ||
| 410 | #define _SC_SYNCHRONIZED_IO	14 | ||
| 411 | #define _SC_FSYNC	15 | ||
| 412 | #define _SC_MAPPED_FILES	16 | ||
| 413 | #define _SC_MEMLOCK	17 | ||
| 414 | #define _SC_MEMLOCK_RANGE	18 | ||
| 415 | #define _SC_MEMORY_PROTECTION	19 | ||
| 416 | #define _SC_MESSAGE_PASSING	20 | ||
| 417 | #define _SC_SEMAPHORES	21 | ||
| 418 | #define _SC_SHARED_MEMORY_OBJECTS	22 | ||
| 419 | #define _SC_AIO_LISTIO_MAX	23 | ||
| 420 | #define _SC_AIO_MAX	24 | ||
| 421 | #define _SC_AIO_PRIO_DELTA_MAX	25 | ||
| 422 | #define _SC_DELAYTIMER_MAX	26 | ||
| 423 | #define _SC_MQ_OPEN_MAX	27 | ||
| 424 | #define _SC_MQ_PRIO_MAX	28 | ||
| 425 | #define _SC_VERSION	29 | ||
| 426 | #define _SC_PAGE_SIZE	30 | ||
| 427 | #define _SC_PAGESIZE	30 /* !! */ | ||
| 428 | #define _SC_RTSIG_MAX	31 | ||
| 429 | #define _SC_SEM_NSEMS_MAX	32 | ||
| 430 | #define _SC_SEM_VALUE_MAX	33 | ||
| 431 | #define _SC_SIGQUEUE_MAX	34 | ||
| 432 | #define _SC_TIMER_MAX	35 | ||
| 433 | #define _SC_BC_BASE_MAX	36 | ||
| 434 | #define _SC_BC_DIM_MAX	37 | ||
| 435 | #define _SC_BC_SCALE_MAX	38 | ||
| 436 | #define _SC_BC_STRING_MAX	39 | ||
| 437 | #define _SC_COLL_WEIGHTS_MAX	40 | ||
| 438 | #define _SC_EXPR_NEST_MAX	42 | ||
| 439 | #define _SC_LINE_MAX	43 | ||
| 440 | #define _SC_RE_DUP_MAX	44 | ||
| 441 | #define _SC_2_VERSION	46 | ||
| 442 | #define _SC_2_C_BIND	47 | ||
| 443 | #define _SC_2_C_DEV	48 | ||
| 444 | #define _SC_2_FORT_DEV	49 | ||
| 445 | #define _SC_2_FORT_RUN	50 | ||
| 446 | #define _SC_2_SW_DEV	51 | ||
| 447 | #define _SC_2_LOCALEDEF	52 | ||
| 448 | #define _SC_UIO_MAXIOV	60 /* !! */ | ||
| 449 | #define _SC_IOV_MAX	60 | ||
| 450 | #define _SC_THREADS	67 | ||
| 451 | #define _SC_THREAD_SAFE_FUNCTIONS	68 | ||
| 452 | #define _SC_GETGR_R_SIZE_MAX	69 | ||
| 453 | #define _SC_GETPW_R_SIZE_MAX	70 | ||
| 454 | #define _SC_LOGIN_NAME_MAX	71 | ||
| 455 | #define _SC_TTY_NAME_MAX	72 | ||
| 456 | #define _SC_THREAD_DESTRUCTOR_ITERATIONS	73 | ||
| 457 | #define _SC_THREAD_KEYS_MAX	74 | ||
| 458 | #define _SC_THREAD_STACK_MIN	75 | ||
| 459 | #define _SC_THREAD_THREADS_MAX	76 | ||
| 460 | #define _SC_THREAD_ATTR_STACKADDR	77 | ||
| 461 | #define _SC_THREAD_ATTR_STACKSIZE	78 | ||
| 462 | #define _SC_THREAD_PRIORITY_SCHEDULING	79 | ||
| 463 | #define _SC_THREAD_PRIO_INHERIT	80 | ||
| 464 | #define _SC_THREAD_PRIO_PROTECT	81 | ||
| 465 | #define _SC_THREAD_PROCESS_SHARED	82 | ||
| 466 | #define _SC_NPROCESSORS_CONF	83 | ||
| 467 | #define _SC_NPROCESSORS_ONLN	84 | ||
| 468 | #define _SC_PHYS_PAGES	85 | ||
| 469 | #define _SC_AVPHYS_PAGES	86 | ||
| 470 | #define _SC_ATEXIT_MAX	87 | ||
| 471 | #define _SC_PASS_MAX	88 | ||
| 472 | #define _SC_XOPEN_VERSION	89 | ||
| 473 | #define _SC_XOPEN_XCU_VERSION	90 | ||
| 474 | #define _SC_XOPEN_UNIX	91 | ||
| 475 | #define _SC_XOPEN_CRYPT	92 | ||
| 476 | #define _SC_XOPEN_ENH_I18N	93 | ||
| 477 | #define _SC_XOPEN_SHM	94 | ||
| 478 | #define _SC_2_CHAR_TERM	95 | ||
| 479 | #define _SC_2_UPE	97 | ||
| 480 | #define _SC_XOPEN_XPG2	98 | ||
| 481 | #define _SC_XOPEN_XPG3	99 | ||
| 482 | #define _SC_XOPEN_XPG4	100 | ||
| 483 | #define _SC_NZERO	109 | ||
| 484 | #define _SC_XBS5_ILP32_OFF32	125 | ||
| 485 | #define _SC_XBS5_ILP32_OFFBIG	126 | ||
| 486 | #define _SC_XBS5_LP64_OFF64	127 | ||
| 487 | #define _SC_XBS5_LPBIG_OFFBIG	128 | ||
| 488 | #define _SC_XOPEN_LEGACY	129 | ||
| 489 | #define _SC_XOPEN_REALTIME	130 | ||
| 490 | #define _SC_XOPEN_REALTIME_THREADS	131 | ||
| 491 | #define _SC_ADVISORY_INFO	132 | ||
| 492 | #define _SC_BARRIERS	133 | ||
| 493 | #define _SC_CLOCK_SELECTION	137 | ||
| 494 | #define _SC_CPUTIME	138 | ||
| 495 | #define _SC_THREAD_CPUTIME	139 | ||
| 496 | #define _SC_MONOTONIC_CLOCK	149 | ||
| 497 | #define _SC_READER_WRITER_LOCKS	153 | ||
| 498 | #define _SC_SPIN_LOCKS	154 | ||
| 499 | #define _SC_REGEXP	155 | ||
| 500 | #define _SC_SHELL	157 | ||
| 501 | #define _SC_SPAWN	159 | ||
| 502 | #define _SC_SPORADIC_SERVER	160 | ||
| 503 | #define _SC_THREAD_SPORADIC_SERVER	161 | ||
| 504 | #define _SC_TIMEOUTS	164 | ||
| 505 | #define _SC_TYPED_MEMORY_OBJECTS	165 | ||
| 506 | #define _SC_2_PBS	168 | ||
| 507 | #define _SC_2_PBS_ACCOUNTING	169 | ||
| 508 | #define _SC_2_PBS_LOCATE	170 | ||
| 509 | #define _SC_2_PBS_MESSAGE	171 | ||
| 510 | #define _SC_2_PBS_TRACK	172 | ||
| 511 | #define _SC_SYMLOOP_MAX	173 | ||
| 512 | #define _SC_STREAMS	174 | ||
| 513 | #define _SC_2_PBS_CHECKPOINT	175 | ||
| 514 | #define _SC_V6_ILP32_OFF32	176 | ||
| 515 | #define _SC_V6_ILP32_OFFBIG	177 | ||
| 516 | #define _SC_V6_LP64_OFF64	178 | ||
| 517 | #define _SC_V6_LPBIG_OFFBIG	179 | ||
| 518 | #define _SC_HOST_NAME_MAX	180 | ||
| 519 | #define _SC_TRACE	181 | ||
| 520 | #define _SC_TRACE_EVENT_FILTER	182 | ||
| 521 | #define _SC_TRACE_INHERIT	183 | ||
| 522 | #define _SC_TRACE_LOG	184 | ||
| 523 | |||
| 524 | #define _SC_IPV6	235 | ||
| 525 | #define _SC_RAW_SOCKETS	236 | ||
| 526 | #define _SC_V7_ILP32_OFF32	237 | ||
| 527 | #define _SC_V7_ILP32_OFFBIG	238 | ||
| 528 | #define _SC_V7_LP64_OFF64	239 | ||
| 529 | #define _SC_V7_LPBIG_OFFBIG	240 | ||
| 530 | #define _SC_SS_REPL_MAX	241 | ||
| 531 | #define _SC_TRACE_EVENT_NAME_MAX	242 | ||
| 532 | #define _SC_TRACE_NAME_MAX	243 | ||
| 533 | #define _SC_TRACE_SYS_MAX	244 | ||
| 534 | #define _SC_TRACE_USER_EVENT_MAX	245 | ||
| 535 | #define _SC_XOPEN_STREAMS	246 | ||
| 536 | #define _SC_THREAD_ROBUST_PRIO_INHERIT	247 | ||
| 537 | #define _SC_THREAD_ROBUST_PRIO_PROTECT	248 | ||
| 538 | #define _SC_MINSIGSTKSZ	249 | ||
| 539 | #define _SC_SIGSTKSZ	250 | ||
| 540 | |||
| 541 | #define _CS_PATH	0 | ||
| 542 | #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS	1 | ||
| 543 | #define _CS_GNU_LIBC_VERSION	2 | ||
| 544 | #define _CS_GNU_LIBPTHREAD_VERSION	3 | ||
| 545 | #define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS	4 | ||
| 546 | #define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS	5 | ||
| 547 | |||
| 548 | #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS	1116 | ||
| 549 | #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS	1117 | ||
| 550 | #define _CS_POSIX_V6_ILP32_OFF32_LIBS	1118 | ||
| 551 | #define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS	1119 | ||
| 552 | #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS	1120 | ||
| 553 | #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS	1121 | ||
| 554 | #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS	1122 | ||
| 555 | #define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS	1123 | ||
| 556 | #define _CS_POSIX_V6_LP64_OFF64_CFLAGS	1124 | ||
| 557 | #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS	1125 | ||
| 558 | #define _CS_POSIX_V6_LP64_OFF64_LIBS	1126 | ||
| 559 | #define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS	1127 | ||
| 560 | #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS	1128 | ||
| 561 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS	1129 | ||
| 562 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS	1130 | ||
| 563 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS	1131 | ||
| 564 | #define _CS_POSIX_V7_ILP32_OFF32_CFLAGS	1132 | ||
| 565 | #define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS	1133 | ||
| 566 | #define _CS_POSIX_V7_ILP32_OFF32_LIBS	1134 | ||
| 567 | #define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS	1135 | ||
| 568 | #define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS	1136 | ||
| 569 | #define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS	1137 | ||
| 570 | #define _CS_POSIX_V7_ILP32_OFFBIG_LIBS	1138 | ||
| 571 | #define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS	1139 | ||
| 572 | #define _CS_POSIX_V7_LP64_OFF64_CFLAGS	1140 | ||
| 573 | #define _CS_POSIX_V7_LP64_OFF64_LDFLAGS	1141 | ||
| 574 | #define _CS_POSIX_V7_LP64_OFF64_LIBS	1142 | ||
| 575 | #define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS	1143 | ||
| 576 | #define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS	1144 | ||
| 577 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS	1145 | ||
| 578 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS	1146 | ||
| 579 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS	1147 | ||
| 580 | #define _CS_V6_ENV	1148 | ||
| 581 | #define _CS_V7_ENV	1149 | ||
| 582 | #define _CS_POSIX_V7_THREADS_CFLAGS	1150 | ||
| 583 | #define _CS_POSIX_V7_THREADS_LDFLAGS	1151 | ||
| 584 | |||
| 585 | #ifdef __cplusplus | ||
| 586 | } | ||
| 587 | #endif | ||
| 588 | |||
| 589 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/api.h deleted-2115| ... | @@ -1,2115 +0,0 @@ | ||
| 1 | /** | ||
| 2 | * <wasi/api.h>. This file contains declarations describing the WASI ABI | ||
| 3 | * as of "snapshot preview1". It was originally auto-generated from | ||
| 4 | * wasi_snapshot_preview1.witx, however WASI is in the process of | ||
| 5 | * transitioning to a new IDL and header file generator, and this file | ||
| 6 | * is temporarily being manually maintained. | ||
| 7 | * | ||
| 8 | * @file | ||
| 9 | * This file describes the [WASI] interface, consisting of functions, types, | ||
| 10 | * and defined values (macros). | ||
| 11 | * | ||
| 12 | * The interface described here is greatly inspired by [CloudABI]'s clean, | ||
| 13 | * thoughtfully-designed, capability-oriented, POSIX-style API. | ||
| 14 | * | ||
| 15 | * [CloudABI]: https://github.com/NuxiNL/cloudlibc | ||
| 16 | * [WASI]: https://github.com/WebAssembly/WASI/ | ||
| 17 | */ | ||
| 18 | |||
| 19 | #ifndef __wasi_api_h | ||
| 20 | #define __wasi_api_h | ||
| 21 | |||
| 22 | #ifndef __wasi__ | ||
| 23 | #error <wasi/api.h> is only supported on WASI platforms. | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #ifndef __wasm32__ | ||
| 27 | #error <wasi/api.h> only supports wasm32; doesn't yet support wasm64 | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #include <stddef.h> | ||
| 31 | #include <stdint.h> | ||
| 32 | |||
| 33 | _Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout"); | ||
| 34 | _Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout"); | ||
| 35 | _Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout"); | ||
| 36 | _Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout"); | ||
| 37 | _Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout"); | ||
| 38 | _Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout"); | ||
| 39 | _Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout"); | ||
| 40 | _Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout"); | ||
| 41 | _Static_assert(_Alignof(void*) == 4, "non-wasi data layout"); | ||
| 42 | |||
| 43 | #ifdef __cplusplus | ||
| 44 | extern "C" { | ||
| 45 | #endif | ||
| 46 | |||
| 47 | // TODO: Encoding this in witx. | ||
| 48 | #define __WASI_DIRCOOKIE_START (UINT64_C(0)) | ||
| 49 | typedef __SIZE_TYPE__ __wasi_size_t; | ||
| 50 | |||
| 51 | _Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size"); | ||
| 52 | _Static_assert(_Alignof(__wasi_size_t) == 4, "witx calculated align"); | ||
| 53 | |||
| 54 | /** | ||
| 55 | * Non-negative file size or length of a region within a file. | ||
| 56 | */ | ||
| 57 | typedef uint64_t __wasi_filesize_t; | ||
| 58 | |||
| 59 | _Static_assert(sizeof(__wasi_filesize_t) == 8, "witx calculated size"); | ||
| 60 | _Static_assert(_Alignof(__wasi_filesize_t) == 8, "witx calculated align"); | ||
| 61 | |||
| 62 | /** | ||
| 63 | * Timestamp in nanoseconds. | ||
| 64 | */ | ||
| 65 | typedef uint64_t __wasi_timestamp_t; | ||
| 66 | |||
| 67 | _Static_assert(sizeof(__wasi_timestamp_t) == 8, "witx calculated size"); | ||
| 68 | _Static_assert(_Alignof(__wasi_timestamp_t) == 8, "witx calculated align"); | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Identifiers for clocks. | ||
| 72 | */ | ||
| 73 | typedef uint32_t __wasi_clockid_t; | ||
| 74 | |||
| 75 | /** | ||
| 76 | * The clock measuring real time. Time value zero corresponds with | ||
| 77 | * 1970-01-01T00:00:00Z. | ||
| 78 | */ | ||
| 79 | #define __WASI_CLOCKID_REALTIME (UINT32_C(0)) | ||
| 80 | |||
| 81 | /** | ||
| 82 | * The store-wide monotonic clock, which is defined as a clock measuring | ||
| 83 | * real time, whose value cannot be adjusted and which cannot have negative | ||
| 84 | * clock jumps. The epoch of this clock is undefined. The absolute time | ||
| 85 | * value of this clock therefore has no meaning. | ||
| 86 | */ | ||
| 87 | #define __WASI_CLOCKID_MONOTONIC (UINT32_C(1)) | ||
| 88 | |||
| 89 | /** | ||
| 90 | * The CPU-time clock associated with the current process. | ||
| 91 | */ | ||
| 92 | #define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2)) | ||
| 93 | |||
| 94 | /** | ||
| 95 | * The CPU-time clock associated with the current thread. | ||
| 96 | */ | ||
| 97 | #define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3)) | ||
| 98 | |||
| 99 | _Static_assert(sizeof(__wasi_clockid_t) == 4, "witx calculated size"); | ||
| 100 | _Static_assert(_Alignof(__wasi_clockid_t) == 4, "witx calculated align"); | ||
| 101 | |||
| 102 | /** | ||
| 103 | * Error codes returned by functions. | ||
| 104 | * Not all of these error codes are returned by the functions provided by this | ||
| 105 | * API; some are used in higher-level library layers, and others are provided | ||
| 106 | * merely for alignment with POSIX. | ||
| 107 | */ | ||
| 108 | typedef uint16_t __wasi_errno_t; | ||
| 109 | |||
| 110 | /** | ||
| 111 | * No error occurred. System call completed successfully. | ||
| 112 | */ | ||
| 113 | #define __WASI_ERRNO_SUCCESS (UINT16_C(0)) | ||
| 114 | |||
| 115 | /** | ||
| 116 | * Argument list too long. | ||
| 117 | */ | ||
| 118 | #define __WASI_ERRNO_2BIG (UINT16_C(1)) | ||
| 119 | |||
| 120 | /** | ||
| 121 | * Permission denied. | ||
| 122 | */ | ||
| 123 | #define __WASI_ERRNO_ACCES (UINT16_C(2)) | ||
| 124 | |||
| 125 | /** | ||
| 126 | * Address in use. | ||
| 127 | */ | ||
| 128 | #define __WASI_ERRNO_ADDRINUSE (UINT16_C(3)) | ||
| 129 | |||
| 130 | /** | ||
| 131 | * Address not available. | ||
| 132 | */ | ||
| 133 | #define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4)) | ||
| 134 | |||
| 135 | /** | ||
| 136 | * Address family not supported. | ||
| 137 | */ | ||
| 138 | #define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5)) | ||
| 139 | |||
| 140 | /** | ||
| 141 | * Resource unavailable, or operation would block. | ||
| 142 | */ | ||
| 143 | #define __WASI_ERRNO_AGAIN (UINT16_C(6)) | ||
| 144 | |||
| 145 | /** | ||
| 146 | * Connection already in progress. | ||
| 147 | */ | ||
| 148 | #define __WASI_ERRNO_ALREADY (UINT16_C(7)) | ||
| 149 | |||
| 150 | /** | ||
| 151 | * Bad file descriptor. | ||
| 152 | */ | ||
| 153 | #define __WASI_ERRNO_BADF (UINT16_C(8)) | ||
| 154 | |||
| 155 | /** | ||
| 156 | * Bad message. | ||
| 157 | */ | ||
| 158 | #define __WASI_ERRNO_BADMSG (UINT16_C(9)) | ||
| 159 | |||
| 160 | /** | ||
| 161 | * Device or resource busy. | ||
| 162 | */ | ||
| 163 | #define __WASI_ERRNO_BUSY (UINT16_C(10)) | ||
| 164 | |||
| 165 | /** | ||
| 166 | * Operation canceled. | ||
| 167 | */ | ||
| 168 | #define __WASI_ERRNO_CANCELED (UINT16_C(11)) | ||
| 169 | |||
| 170 | /** | ||
| 171 | * No child processes. | ||
| 172 | */ | ||
| 173 | #define __WASI_ERRNO_CHILD (UINT16_C(12)) | ||
| 174 | |||
| 175 | /** | ||
| 176 | * Connection aborted. | ||
| 177 | */ | ||
| 178 | #define __WASI_ERRNO_CONNABORTED (UINT16_C(13)) | ||
| 179 | |||
| 180 | /** | ||
| 181 | * Connection refused. | ||
| 182 | */ | ||
| 183 | #define __WASI_ERRNO_CONNREFUSED (UINT16_C(14)) | ||
| 184 | |||
| 185 | /** | ||
| 186 | * Connection reset. | ||
| 187 | */ | ||
| 188 | #define __WASI_ERRNO_CONNRESET (UINT16_C(15)) | ||
| 189 | |||
| 190 | /** | ||
| 191 | * Resource deadlock would occur. | ||
| 192 | */ | ||
| 193 | #define __WASI_ERRNO_DEADLK (UINT16_C(16)) | ||
| 194 | |||
| 195 | /** | ||
| 196 | * Destination address required. | ||
| 197 | */ | ||
| 198 | #define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17)) | ||
| 199 | |||
| 200 | /** | ||
| 201 | * Mathematics argument out of domain of function. | ||
| 202 | */ | ||
| 203 | #define __WASI_ERRNO_DOM (UINT16_C(18)) | ||
| 204 | |||
| 205 | /** | ||
| 206 | * Reserved. | ||
| 207 | */ | ||
| 208 | #define __WASI_ERRNO_DQUOT (UINT16_C(19)) | ||
| 209 | |||
| 210 | /** | ||
| 211 | * File exists. | ||
| 212 | */ | ||
| 213 | #define __WASI_ERRNO_EXIST (UINT16_C(20)) | ||
| 214 | |||
| 215 | /** | ||
| 216 | * Bad address. | ||
| 217 | */ | ||
| 218 | #define __WASI_ERRNO_FAULT (UINT16_C(21)) | ||
| 219 | |||
| 220 | /** | ||
| 221 | * File too large. | ||
| 222 | */ | ||
| 223 | #define __WASI_ERRNO_FBIG (UINT16_C(22)) | ||
| 224 | |||
| 225 | /** | ||
| 226 | * Host is unreachable. | ||
| 227 | */ | ||
| 228 | #define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23)) | ||
| 229 | |||
| 230 | /** | ||
| 231 | * Identifier removed. | ||
| 232 | */ | ||
| 233 | #define __WASI_ERRNO_IDRM (UINT16_C(24)) | ||
| 234 | |||
| 235 | /** | ||
| 236 | * Illegal byte sequence. | ||
| 237 | */ | ||
| 238 | #define __WASI_ERRNO_ILSEQ (UINT16_C(25)) | ||
| 239 | |||
| 240 | /** | ||
| 241 | * Operation in progress. | ||
| 242 | */ | ||
| 243 | #define __WASI_ERRNO_INPROGRESS (UINT16_C(26)) | ||
| 244 | |||
| 245 | /** | ||
| 246 | * Interrupted function. | ||
| 247 | */ | ||
| 248 | #define __WASI_ERRNO_INTR (UINT16_C(27)) | ||
| 249 | |||
| 250 | /** | ||
| 251 | * Invalid argument. | ||
| 252 | */ | ||
| 253 | #define __WASI_ERRNO_INVAL (UINT16_C(28)) | ||
| 254 | |||
| 255 | /** | ||
| 256 | * I/O error. | ||
| 257 | */ | ||
| 258 | #define __WASI_ERRNO_IO (UINT16_C(29)) | ||
| 259 | |||
| 260 | /** | ||
| 261 | * Socket is connected. | ||
| 262 | */ | ||
| 263 | #define __WASI_ERRNO_ISCONN (UINT16_C(30)) | ||
| 264 | |||
| 265 | /** | ||
| 266 | * Is a directory. | ||
| 267 | */ | ||
| 268 | #define __WASI_ERRNO_ISDIR (UINT16_C(31)) | ||
| 269 | |||
| 270 | /** | ||
| 271 | * Too many levels of symbolic links. | ||
| 272 | */ | ||
| 273 | #define __WASI_ERRNO_LOOP (UINT16_C(32)) | ||
| 274 | |||
| 275 | /** | ||
| 276 | * File descriptor value too large. | ||
| 277 | */ | ||
| 278 | #define __WASI_ERRNO_MFILE (UINT16_C(33)) | ||
| 279 | |||
| 280 | /** | ||
| 281 | * Too many links. | ||
| 282 | */ | ||
| 283 | #define __WASI_ERRNO_MLINK (UINT16_C(34)) | ||
| 284 | |||
| 285 | /** | ||
| 286 | * Message too large. | ||
| 287 | */ | ||
| 288 | #define __WASI_ERRNO_MSGSIZE (UINT16_C(35)) | ||
| 289 | |||
| 290 | /** | ||
| 291 | * Reserved. | ||
| 292 | */ | ||
| 293 | #define __WASI_ERRNO_MULTIHOP (UINT16_C(36)) | ||
| 294 | |||
| 295 | /** | ||
| 296 | * Filename too long. | ||
| 297 | */ | ||
| 298 | #define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37)) | ||
| 299 | |||
| 300 | /** | ||
| 301 | * Network is down. | ||
| 302 | */ | ||
| 303 | #define __WASI_ERRNO_NETDOWN (UINT16_C(38)) | ||
| 304 | |||
| 305 | /** | ||
| 306 | * Connection aborted by network. | ||
| 307 | */ | ||
| 308 | #define __WASI_ERRNO_NETRESET (UINT16_C(39)) | ||
| 309 | |||
| 310 | /** | ||
| 311 | * Network unreachable. | ||
| 312 | */ | ||
| 313 | #define __WASI_ERRNO_NETUNREACH (UINT16_C(40)) | ||
| 314 | |||
| 315 | /** | ||
| 316 | * Too many files open in system. | ||
| 317 | */ | ||
| 318 | #define __WASI_ERRNO_NFILE (UINT16_C(41)) | ||
| 319 | |||
| 320 | /** | ||
| 321 | * No buffer space available. | ||
| 322 | */ | ||
| 323 | #define __WASI_ERRNO_NOBUFS (UINT16_C(42)) | ||
| 324 | |||
| 325 | /** | ||
| 326 | * No such device. | ||
| 327 | */ | ||
| 328 | #define __WASI_ERRNO_NODEV (UINT16_C(43)) | ||
| 329 | |||
| 330 | /** | ||
| 331 | * No such file or directory. | ||
| 332 | */ | ||
| 333 | #define __WASI_ERRNO_NOENT (UINT16_C(44)) | ||
| 334 | |||
| 335 | /** | ||
| 336 | * Executable file format error. | ||
| 337 | */ | ||
| 338 | #define __WASI_ERRNO_NOEXEC (UINT16_C(45)) | ||
| 339 | |||
| 340 | /** | ||
| 341 | * No locks available. | ||
| 342 | */ | ||
| 343 | #define __WASI_ERRNO_NOLCK (UINT16_C(46)) | ||
| 344 | |||
| 345 | /** | ||
| 346 | * Reserved. | ||
| 347 | */ | ||
| 348 | #define __WASI_ERRNO_NOLINK (UINT16_C(47)) | ||
| 349 | |||
| 350 | /** | ||
| 351 | * Not enough space. | ||
| 352 | */ | ||
| 353 | #define __WASI_ERRNO_NOMEM (UINT16_C(48)) | ||
| 354 | |||
| 355 | /** | ||
| 356 | * No message of the desired type. | ||
| 357 | */ | ||
| 358 | #define __WASI_ERRNO_NOMSG (UINT16_C(49)) | ||
| 359 | |||
| 360 | /** | ||
| 361 | * Protocol not available. | ||
| 362 | */ | ||
| 363 | #define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50)) | ||
| 364 | |||
| 365 | /** | ||
| 366 | * No space left on device. | ||
| 367 | */ | ||
| 368 | #define __WASI_ERRNO_NOSPC (UINT16_C(51)) | ||
| 369 | |||
| 370 | /** | ||
| 371 | * Function not supported. | ||
| 372 | */ | ||
| 373 | #define __WASI_ERRNO_NOSYS (UINT16_C(52)) | ||
| 374 | |||
| 375 | /** | ||
| 376 | * The socket is not connected. | ||
| 377 | */ | ||
| 378 | #define __WASI_ERRNO_NOTCONN (UINT16_C(53)) | ||
| 379 | |||
| 380 | /** | ||
| 381 | * Not a directory or a symbolic link to a directory. | ||
| 382 | */ | ||
| 383 | #define __WASI_ERRNO_NOTDIR (UINT16_C(54)) | ||
| 384 | |||
| 385 | /** | ||
| 386 | * Directory not empty. | ||
| 387 | */ | ||
| 388 | #define __WASI_ERRNO_NOTEMPTY (UINT16_C(55)) | ||
| 389 | |||
| 390 | /** | ||
| 391 | * State not recoverable. | ||
| 392 | */ | ||
| 393 | #define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56)) | ||
| 394 | |||
| 395 | /** | ||
| 396 | * Not a socket. | ||
| 397 | */ | ||
| 398 | #define __WASI_ERRNO_NOTSOCK (UINT16_C(57)) | ||
| 399 | |||
| 400 | /** | ||
| 401 | * Not supported, or operation not supported on socket. | ||
| 402 | */ | ||
| 403 | #define __WASI_ERRNO_NOTSUP (UINT16_C(58)) | ||
| 404 | |||
| 405 | /** | ||
| 406 | * Inappropriate I/O control operation. | ||
| 407 | */ | ||
| 408 | #define __WASI_ERRNO_NOTTY (UINT16_C(59)) | ||
| 409 | |||
| 410 | /** | ||
| 411 | * No such device or address. | ||
| 412 | */ | ||
| 413 | #define __WASI_ERRNO_NXIO (UINT16_C(60)) | ||
| 414 | |||
| 415 | /** | ||
| 416 | * Value too large to be stored in data type. | ||
| 417 | */ | ||
| 418 | #define __WASI_ERRNO_OVERFLOW (UINT16_C(61)) | ||
| 419 | |||
| 420 | /** | ||
| 421 | * Previous owner died. | ||
| 422 | */ | ||
| 423 | #define __WASI_ERRNO_OWNERDEAD (UINT16_C(62)) | ||
| 424 | |||
| 425 | /** | ||
| 426 | * Operation not permitted. | ||
| 427 | */ | ||
| 428 | #define __WASI_ERRNO_PERM (UINT16_C(63)) | ||
| 429 | |||
| 430 | /** | ||
| 431 | * Broken pipe. | ||
| 432 | */ | ||
| 433 | #define __WASI_ERRNO_PIPE (UINT16_C(64)) | ||
| 434 | |||
| 435 | /** | ||
| 436 | * Protocol error. | ||
| 437 | */ | ||
| 438 | #define __WASI_ERRNO_PROTO (UINT16_C(65)) | ||
| 439 | |||
| 440 | /** | ||
| 441 | * Protocol not supported. | ||
| 442 | */ | ||
| 443 | #define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66)) | ||
| 444 | |||
| 445 | /** | ||
| 446 | * Protocol wrong type for socket. | ||
| 447 | */ | ||
| 448 | #define __WASI_ERRNO_PROTOTYPE (UINT16_C(67)) | ||
| 449 | |||
| 450 | /** | ||
| 451 | * Result too large. | ||
| 452 | */ | ||
| 453 | #define __WASI_ERRNO_RANGE (UINT16_C(68)) | ||
| 454 | |||
| 455 | /** | ||
| 456 | * Read-only file system. | ||
| 457 | */ | ||
| 458 | #define __WASI_ERRNO_ROFS (UINT16_C(69)) | ||
| 459 | |||
| 460 | /** | ||
| 461 | * Invalid seek. | ||
| 462 | */ | ||
| 463 | #define __WASI_ERRNO_SPIPE (UINT16_C(70)) | ||
| 464 | |||
| 465 | /** | ||
| 466 | * No such process. | ||
| 467 | */ | ||
| 468 | #define __WASI_ERRNO_SRCH (UINT16_C(71)) | ||
| 469 | |||
| 470 | /** | ||
| 471 | * Reserved. | ||
| 472 | */ | ||
| 473 | #define __WASI_ERRNO_STALE (UINT16_C(72)) | ||
| 474 | |||
| 475 | /** | ||
| 476 | * Connection timed out. | ||
| 477 | */ | ||
| 478 | #define __WASI_ERRNO_TIMEDOUT (UINT16_C(73)) | ||
| 479 | |||
| 480 | /** | ||
| 481 | * Text file busy. | ||
| 482 | */ | ||
| 483 | #define __WASI_ERRNO_TXTBSY (UINT16_C(74)) | ||
| 484 | |||
| 485 | /** | ||
| 486 | * Cross-device link. | ||
| 487 | */ | ||
| 488 | #define __WASI_ERRNO_XDEV (UINT16_C(75)) | ||
| 489 | |||
| 490 | /** | ||
| 491 | * Extension: Capabilities insufficient. | ||
| 492 | */ | ||
| 493 | #define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76)) | ||
| 494 | |||
| 495 | _Static_assert(sizeof(__wasi_errno_t) == 2, "witx calculated size"); | ||
| 496 | _Static_assert(_Alignof(__wasi_errno_t) == 2, "witx calculated align"); | ||
| 497 | |||
| 498 | /** | ||
| 499 | * File descriptor rights, determining which actions may be performed. | ||
| 500 | */ | ||
| 501 | typedef uint64_t __wasi_rights_t; | ||
| 502 | |||
| 503 | /** | ||
| 504 | * The right to invoke `fd_datasync`. | ||
| 505 | * If `path_open` is set, includes the right to invoke | ||
| 506 | * `path_open` with `fdflags::dsync`. | ||
| 507 | */ | ||
| 508 | #define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0)) | ||
| 509 | |||
| 510 | /** | ||
| 511 | * The right to invoke `fd_read` and `sock_recv`. | ||
| 512 | * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. | ||
| 513 | */ | ||
| 514 | #define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1)) | ||
| 515 | |||
| 516 | /** | ||
| 517 | * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. | ||
| 518 | */ | ||
| 519 | #define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2)) | ||
| 520 | |||
| 521 | /** | ||
| 522 | * The right to invoke `fd_fdstat_set_flags`. | ||
| 523 | */ | ||
| 524 | #define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3)) | ||
| 525 | |||
| 526 | /** | ||
| 527 | * The right to invoke `fd_sync`. | ||
| 528 | * If `path_open` is set, includes the right to invoke | ||
| 529 | * `path_open` with `fdflags::rsync` and `fdflags::dsync`. | ||
| 530 | */ | ||
| 531 | #define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4)) | ||
| 532 | |||
| 533 | /** | ||
| 534 | * The right to invoke `fd_seek` in such a way that the file offset | ||
| 535 | * remains unaltered (i.e., `whence::cur` with offset zero), or to | ||
| 536 | * invoke `fd_tell`. | ||
| 537 | */ | ||
| 538 | #define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5)) | ||
| 539 | |||
| 540 | /** | ||
| 541 | * The right to invoke `fd_write` and `sock_send`. | ||
| 542 | * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. | ||
| 543 | */ | ||
| 544 | #define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6)) | ||
| 545 | |||
| 546 | /** | ||
| 547 | * The right to invoke `fd_advise`. | ||
| 548 | */ | ||
| 549 | #define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7)) | ||
| 550 | |||
| 551 | /** | ||
| 552 | * The right to invoke `fd_allocate`. | ||
| 553 | */ | ||
| 554 | #define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8)) | ||
| 555 | |||
| 556 | /** | ||
| 557 | * The right to invoke `path_create_directory`. | ||
| 558 | */ | ||
| 559 | #define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9)) | ||
| 560 | |||
| 561 | /** | ||
| 562 | * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`. | ||
| 563 | */ | ||
| 564 | #define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10)) | ||
| 565 | |||
| 566 | /** | ||
| 567 | * The right to invoke `path_link` with the file descriptor as the | ||
| 568 | * source directory. | ||
| 569 | */ | ||
| 570 | #define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11)) | ||
| 571 | |||
| 572 | /** | ||
| 573 | * The right to invoke `path_link` with the file descriptor as the | ||
| 574 | * target directory. | ||
| 575 | */ | ||
| 576 | #define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12)) | ||
| 577 | |||
| 578 | /** | ||
| 579 | * The right to invoke `path_open`. | ||
| 580 | */ | ||
| 581 | #define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13)) | ||
| 582 | |||
| 583 | /** | ||
| 584 | * The right to invoke `fd_readdir`. | ||
| 585 | */ | ||
| 586 | #define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14)) | ||
| 587 | |||
| 588 | /** | ||
| 589 | * The right to invoke `path_readlink`. | ||
| 590 | */ | ||
| 591 | #define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15)) | ||
| 592 | |||
| 593 | /** | ||
| 594 | * The right to invoke `path_rename` with the file descriptor as the source directory. | ||
| 595 | */ | ||
| 596 | #define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16)) | ||
| 597 | |||
| 598 | /** | ||
| 599 | * The right to invoke `path_rename` with the file descriptor as the target directory. | ||
| 600 | */ | ||
| 601 | #define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17)) | ||
| 602 | |||
| 603 | /** | ||
| 604 | * The right to invoke `path_filestat_get`. | ||
| 605 | */ | ||
| 606 | #define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18)) | ||
| 607 | |||
| 608 | /** | ||
| 609 | * The right to change a file's size (there is no `path_filestat_set_size`). | ||
| 610 | * If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. | ||
| 611 | */ | ||
| 612 | #define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19)) | ||
| 613 | |||
| 614 | /** | ||
| 615 | * The right to invoke `path_filestat_set_times`. | ||
| 616 | */ | ||
| 617 | #define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20)) | ||
| 618 | |||
| 619 | /** | ||
| 620 | * The right to invoke `fd_filestat_get`. | ||
| 621 | */ | ||
| 622 | #define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21)) | ||
| 623 | |||
| 624 | /** | ||
| 625 | * The right to invoke `fd_filestat_set_size`. | ||
| 626 | */ | ||
| 627 | #define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22)) | ||
| 628 | |||
| 629 | /** | ||
| 630 | * The right to invoke `fd_filestat_set_times`. | ||
| 631 | */ | ||
| 632 | #define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23)) | ||
| 633 | |||
| 634 | /** | ||
| 635 | * The right to invoke `path_symlink`. | ||
| 636 | */ | ||
| 637 | #define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24)) | ||
| 638 | |||
| 639 | /** | ||
| 640 | * The right to invoke `path_remove_directory`. | ||
| 641 | */ | ||
| 642 | #define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25)) | ||
| 643 | |||
| 644 | /** | ||
| 645 | * The right to invoke `path_unlink_file`. | ||
| 646 | */ | ||
| 647 | #define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26)) | ||
| 648 | |||
| 649 | /** | ||
| 650 | * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. | ||
| 651 | * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. | ||
| 652 | */ | ||
| 653 | #define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27)) | ||
| 654 | |||
| 655 | /** | ||
| 656 | * The right to invoke `sock_shutdown`. | ||
| 657 | */ | ||
| 658 | #define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28)) | ||
| 659 | |||
| 660 | /** | ||
| 661 | * The right to invoke `sock_accept`. | ||
| 662 | */ | ||
| 663 | #define __WASI_RIGHTS_SOCK_ACCEPT ((__wasi_rights_t)(1 << 29)) | ||
| 664 | |||
| 665 | /** | ||
| 666 | * A file descriptor handle. | ||
| 667 | */ | ||
| 668 | typedef int __wasi_fd_t; | ||
| 669 | |||
| 670 | _Static_assert(sizeof(__wasi_fd_t) == 4, "witx calculated size"); | ||
| 671 | _Static_assert(_Alignof(__wasi_fd_t) == 4, "witx calculated align"); | ||
| 672 | |||
| 673 | /** | ||
| 674 | * A region of memory for scatter/gather reads. | ||
| 675 | */ | ||
| 676 | typedef struct __wasi_iovec_t { | ||
| 677 | /** | ||
| 678 | * The address of the buffer to be filled. | ||
| 679 | */ | ||
| 680 | uint8_t * buf; | ||
| 681 | |||
| 682 | /** | ||
| 683 | * The length of the buffer to be filled. | ||
| 684 | */ | ||
| 685 | __wasi_size_t buf_len; | ||
| 686 | |||
| 687 | } __wasi_iovec_t; | ||
| 688 | |||
| 689 | _Static_assert(sizeof(__wasi_iovec_t) == 8, "witx calculated size"); | ||
| 690 | _Static_assert(_Alignof(__wasi_iovec_t) == 4, "witx calculated align"); | ||
| 691 | _Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "witx calculated offset"); | ||
| 692 | _Static_assert(offsetof(__wasi_iovec_t, buf_len) == 4, "witx calculated offset"); | ||
| 693 | |||
| 694 | /** | ||
| 695 | * A region of memory for scatter/gather writes. | ||
| 696 | */ | ||
| 697 | typedef struct __wasi_ciovec_t { | ||
| 698 | /** | ||
| 699 | * The address of the buffer to be written. | ||
| 700 | */ | ||
| 701 | const uint8_t * buf; | ||
| 702 | |||
| 703 | /** | ||
| 704 | * The length of the buffer to be written. | ||
| 705 | */ | ||
| 706 | __wasi_size_t buf_len; | ||
| 707 | |||
| 708 | } __wasi_ciovec_t; | ||
| 709 | |||
| 710 | _Static_assert(sizeof(__wasi_ciovec_t) == 8, "witx calculated size"); | ||
| 711 | _Static_assert(_Alignof(__wasi_ciovec_t) == 4, "witx calculated align"); | ||
| 712 | _Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "witx calculated offset"); | ||
| 713 | _Static_assert(offsetof(__wasi_ciovec_t, buf_len) == 4, "witx calculated offset"); | ||
| 714 | |||
| 715 | /** | ||
| 716 | * Relative offset within a file. | ||
| 717 | */ | ||
| 718 | typedef int64_t __wasi_filedelta_t; | ||
| 719 | |||
| 720 | _Static_assert(sizeof(__wasi_filedelta_t) == 8, "witx calculated size"); | ||
| 721 | _Static_assert(_Alignof(__wasi_filedelta_t) == 8, "witx calculated align"); | ||
| 722 | |||
| 723 | /** | ||
| 724 | * The position relative to which to set the offset of the file descriptor. | ||
| 725 | */ | ||
| 726 | typedef uint8_t __wasi_whence_t; | ||
| 727 | |||
| 728 | /** | ||
| 729 | * Seek relative to start-of-file. | ||
| 730 | */ | ||
| 731 | #define __WASI_WHENCE_SET (UINT8_C(0)) | ||
| 732 | |||
| 733 | /** | ||
| 734 | * Seek relative to current position. | ||
| 735 | */ | ||
| 736 | #define __WASI_WHENCE_CUR (UINT8_C(1)) | ||
| 737 | |||
| 738 | /** | ||
| 739 | * Seek relative to end-of-file. | ||
| 740 | */ | ||
| 741 | #define __WASI_WHENCE_END (UINT8_C(2)) | ||
| 742 | |||
| 743 | _Static_assert(sizeof(__wasi_whence_t) == 1, "witx calculated size"); | ||
| 744 | _Static_assert(_Alignof(__wasi_whence_t) == 1, "witx calculated align"); | ||
| 745 | |||
| 746 | /** | ||
| 747 | * A reference to the offset of a directory entry. | ||
| 748 | * | ||
| 749 | * The value 0 signifies the start of the directory. | ||
| 750 | */ | ||
| 751 | typedef uint64_t __wasi_dircookie_t; | ||
| 752 | |||
| 753 | _Static_assert(sizeof(__wasi_dircookie_t) == 8, "witx calculated size"); | ||
| 754 | _Static_assert(_Alignof(__wasi_dircookie_t) == 8, "witx calculated align"); | ||
| 755 | |||
| 756 | /** | ||
| 757 | * The type for the `dirent::d_namlen` field of `dirent` struct. | ||
| 758 | */ | ||
| 759 | typedef uint32_t __wasi_dirnamlen_t; | ||
| 760 | |||
| 761 | _Static_assert(sizeof(__wasi_dirnamlen_t) == 4, "witx calculated size"); | ||
| 762 | _Static_assert(_Alignof(__wasi_dirnamlen_t) == 4, "witx calculated align"); | ||
| 763 | |||
| 764 | /** | ||
| 765 | * File serial number that is unique within its file system. | ||
| 766 | */ | ||
| 767 | typedef uint64_t __wasi_inode_t; | ||
| 768 | |||
| 769 | _Static_assert(sizeof(__wasi_inode_t) == 8, "witx calculated size"); | ||
| 770 | _Static_assert(_Alignof(__wasi_inode_t) == 8, "witx calculated align"); | ||
| 771 | |||
| 772 | /** | ||
| 773 | * The type of a file descriptor or file. | ||
| 774 | */ | ||
| 775 | typedef uint8_t __wasi_filetype_t; | ||
| 776 | |||
| 777 | /** | ||
| 778 | * The type of the file descriptor or file is unknown or is different from any of the other types specified. | ||
| 779 | */ | ||
| 780 | #define __WASI_FILETYPE_UNKNOWN (UINT8_C(0)) | ||
| 781 | |||
| 782 | /** | ||
| 783 | * The file descriptor or file refers to a block device inode. | ||
| 784 | */ | ||
| 785 | #define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1)) | ||
| 786 | |||
| 787 | /** | ||
| 788 | * The file descriptor or file refers to a character device inode. | ||
| 789 | */ | ||
| 790 | #define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2)) | ||
| 791 | |||
| 792 | /** | ||
| 793 | * The file descriptor or file refers to a directory inode. | ||
| 794 | */ | ||
| 795 | #define __WASI_FILETYPE_DIRECTORY (UINT8_C(3)) | ||
| 796 | |||
| 797 | /** | ||
| 798 | * The file descriptor or file refers to a regular file inode. | ||
| 799 | */ | ||
| 800 | #define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4)) | ||
| 801 | |||
| 802 | /** | ||
| 803 | * The file descriptor or file refers to a datagram socket. | ||
| 804 | */ | ||
| 805 | #define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5)) | ||
| 806 | |||
| 807 | /** | ||
| 808 | * The file descriptor or file refers to a byte-stream socket. | ||
| 809 | */ | ||
| 810 | #define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6)) | ||
| 811 | |||
| 812 | /** | ||
| 813 | * The file refers to a symbolic link inode. | ||
| 814 | */ | ||
| 815 | #define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7)) | ||
| 816 | |||
| 817 | _Static_assert(sizeof(__wasi_filetype_t) == 1, "witx calculated size"); | ||
| 818 | _Static_assert(_Alignof(__wasi_filetype_t) == 1, "witx calculated align"); | ||
| 819 | |||
| 820 | /** | ||
| 821 | * A directory entry. | ||
| 822 | */ | ||
| 823 | typedef struct __wasi_dirent_t { | ||
| 824 | /** | ||
| 825 | * The offset of the next directory entry stored in this directory. | ||
| 826 | */ | ||
| 827 | __wasi_dircookie_t d_next; | ||
| 828 | |||
| 829 | /** | ||
| 830 | * The serial number of the file referred to by this directory entry. | ||
| 831 | */ | ||
| 832 | __wasi_inode_t d_ino; | ||
| 833 | |||
| 834 | /** | ||
| 835 | * The length of the name of the directory entry. | ||
| 836 | */ | ||
| 837 | __wasi_dirnamlen_t d_namlen; | ||
| 838 | |||
| 839 | /** | ||
| 840 | * The type of the file referred to by this directory entry. | ||
| 841 | */ | ||
| 842 | __wasi_filetype_t d_type; | ||
| 843 | |||
| 844 | } __wasi_dirent_t; | ||
| 845 | |||
| 846 | _Static_assert(sizeof(__wasi_dirent_t) == 24, "witx calculated size"); | ||
| 847 | _Static_assert(_Alignof(__wasi_dirent_t) == 8, "witx calculated align"); | ||
| 848 | _Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "witx calculated offset"); | ||
| 849 | _Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "witx calculated offset"); | ||
| 850 | _Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "witx calculated offset"); | ||
| 851 | _Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "witx calculated offset"); | ||
| 852 | |||
| 853 | /** | ||
| 854 | * File or memory access pattern advisory information. | ||
| 855 | */ | ||
| 856 | typedef uint8_t __wasi_advice_t; | ||
| 857 | |||
| 858 | /** | ||
| 859 | * The application has no advice to give on its behavior with respect to the specified data. | ||
| 860 | */ | ||
| 861 | #define __WASI_ADVICE_NORMAL (UINT8_C(0)) | ||
| 862 | |||
| 863 | /** | ||
| 864 | * The application expects to access the specified data sequentially from lower offsets to higher offsets. | ||
| 865 | */ | ||
| 866 | #define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1)) | ||
| 867 | |||
| 868 | /** | ||
| 869 | * The application expects to access the specified data in a random order. | ||
| 870 | */ | ||
| 871 | #define __WASI_ADVICE_RANDOM (UINT8_C(2)) | ||
| 872 | |||
| 873 | /** | ||
| 874 | * The application expects to access the specified data in the near future. | ||
| 875 | */ | ||
| 876 | #define __WASI_ADVICE_WILLNEED (UINT8_C(3)) | ||
| 877 | |||
| 878 | /** | ||
| 879 | * The application expects that it will not access the specified data in the near future. | ||
| 880 | */ | ||
| 881 | #define __WASI_ADVICE_DONTNEED (UINT8_C(4)) | ||
| 882 | |||
| 883 | /** | ||
| 884 | * The application expects to access the specified data once and then not reuse it thereafter. | ||
| 885 | */ | ||
| 886 | #define __WASI_ADVICE_NOREUSE (UINT8_C(5)) | ||
| 887 | |||
| 888 | _Static_assert(sizeof(__wasi_advice_t) == 1, "witx calculated size"); | ||
| 889 | _Static_assert(_Alignof(__wasi_advice_t) == 1, "witx calculated align"); | ||
| 890 | |||
| 891 | /** | ||
| 892 | * File descriptor flags. | ||
| 893 | */ | ||
| 894 | typedef uint16_t __wasi_fdflags_t; | ||
| 895 | |||
| 896 | /** | ||
| 897 | * Append mode: Data written to the file is always appended to the file's end. | ||
| 898 | */ | ||
| 899 | #define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)(1 << 0)) | ||
| 900 | |||
| 901 | /** | ||
| 902 | * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. | ||
| 903 | */ | ||
| 904 | #define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1)) | ||
| 905 | |||
| 906 | /** | ||
| 907 | * Non-blocking mode. | ||
| 908 | */ | ||
| 909 | #define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2)) | ||
| 910 | |||
| 911 | /** | ||
| 912 | * Synchronized read I/O operations. | ||
| 913 | */ | ||
| 914 | #define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3)) | ||
| 915 | |||
| 916 | /** | ||
| 917 | * Write according to synchronized I/O file integrity completion. In | ||
| 918 | * addition to synchronizing the data stored in the file, the implementation | ||
| 919 | * may also synchronously update the file's metadata. | ||
| 920 | */ | ||
| 921 | #define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4)) | ||
| 922 | |||
| 923 | /** | ||
| 924 | * File descriptor attributes. | ||
| 925 | */ | ||
| 926 | typedef struct __wasi_fdstat_t { | ||
| 927 | /** | ||
| 928 | * File type. | ||
| 929 | */ | ||
| 930 | __wasi_filetype_t fs_filetype; | ||
| 931 | |||
| 932 | /** | ||
| 933 | * File descriptor flags. | ||
| 934 | */ | ||
| 935 | __wasi_fdflags_t fs_flags; | ||
| 936 | |||
| 937 | /** | ||
| 938 | * Rights that apply to this file descriptor. | ||
| 939 | */ | ||
| 940 | __wasi_rights_t fs_rights_base; | ||
| 941 | |||
| 942 | /** | ||
| 943 | * Maximum set of rights that may be installed on new file descriptors that | ||
| 944 | * are created through this file descriptor, e.g., through `path_open`. | ||
| 945 | */ | ||
| 946 | __wasi_rights_t fs_rights_inheriting; | ||
| 947 | |||
| 948 | } __wasi_fdstat_t; | ||
| 949 | |||
| 950 | _Static_assert(sizeof(__wasi_fdstat_t) == 24, "witx calculated size"); | ||
| 951 | _Static_assert(_Alignof(__wasi_fdstat_t) == 8, "witx calculated align"); | ||
| 952 | _Static_assert(offsetof(__wasi_fdstat_t, fs_filetype) == 0, "witx calculated offset"); | ||
| 953 | _Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "witx calculated offset"); | ||
| 954 | _Static_assert(offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "witx calculated offset"); | ||
| 955 | _Static_assert(offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16, "witx calculated offset"); | ||
| 956 | |||
| 957 | /** | ||
| 958 | * Identifier for a device containing a file system. Can be used in combination | ||
| 959 | * with `inode` to uniquely identify a file or directory in the filesystem. | ||
| 960 | */ | ||
| 961 | typedef uint64_t __wasi_device_t; | ||
| 962 | |||
| 963 | _Static_assert(sizeof(__wasi_device_t) == 8, "witx calculated size"); | ||
| 964 | _Static_assert(_Alignof(__wasi_device_t) == 8, "witx calculated align"); | ||
| 965 | |||
| 966 | /** | ||
| 967 | * Which file time attributes to adjust. | ||
| 968 | */ | ||
| 969 | typedef uint16_t __wasi_fstflags_t; | ||
| 970 | |||
| 971 | /** | ||
| 972 | * Adjust the last data access timestamp to the value stored in `filestat::atim`. | ||
| 973 | */ | ||
| 974 | #define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0)) | ||
| 975 | |||
| 976 | /** | ||
| 977 | * Adjust the last data access timestamp to the time of clock `clockid::realtime`. | ||
| 978 | */ | ||
| 979 | #define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1)) | ||
| 980 | |||
| 981 | /** | ||
| 982 | * Adjust the last data modification timestamp to the value stored in `filestat::mtim`. | ||
| 983 | */ | ||
| 984 | #define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2)) | ||
| 985 | |||
| 986 | /** | ||
| 987 | * Adjust the last data modification timestamp to the time of clock `clockid::realtime`. | ||
| 988 | */ | ||
| 989 | #define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3)) | ||
| 990 | |||
| 991 | /** | ||
| 992 | * Flags determining the method of how paths are resolved. | ||
| 993 | */ | ||
| 994 | typedef uint32_t __wasi_lookupflags_t; | ||
| 995 | |||
| 996 | /** | ||
| 997 | * As long as the resolved path corresponds to a symbolic link, it is expanded. | ||
| 998 | */ | ||
| 999 | #define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0)) | ||
| 1000 | |||
| 1001 | /** | ||
| 1002 | * Open flags used by `path_open`. | ||
| 1003 | */ | ||
| 1004 | typedef uint16_t __wasi_oflags_t; | ||
| 1005 | |||
| 1006 | /** | ||
| 1007 | * Create file if it does not exist. | ||
| 1008 | */ | ||
| 1009 | #define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0)) | ||
| 1010 | |||
| 1011 | /** | ||
| 1012 | * Fail if not a directory. | ||
| 1013 | */ | ||
| 1014 | #define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1)) | ||
| 1015 | |||
| 1016 | /** | ||
| 1017 | * Fail if file already exists. | ||
| 1018 | */ | ||
| 1019 | #define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2)) | ||
| 1020 | |||
| 1021 | /** | ||
| 1022 | * Truncate file to size 0. | ||
| 1023 | */ | ||
| 1024 | #define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3)) | ||
| 1025 | |||
| 1026 | /** | ||
| 1027 | * Number of hard links to an inode. | ||
| 1028 | */ | ||
| 1029 | typedef uint64_t __wasi_linkcount_t; | ||
| 1030 | |||
| 1031 | _Static_assert(sizeof(__wasi_linkcount_t) == 8, "witx calculated size"); | ||
| 1032 | _Static_assert(_Alignof(__wasi_linkcount_t) == 8, "witx calculated align"); | ||
| 1033 | |||
| 1034 | /** | ||
| 1035 | * File attributes. | ||
| 1036 | */ | ||
| 1037 | typedef struct __wasi_filestat_t { | ||
| 1038 | /** | ||
| 1039 | * Device ID of device containing the file. | ||
| 1040 | */ | ||
| 1041 | __wasi_device_t dev; | ||
| 1042 | |||
| 1043 | /** | ||
| 1044 | * File serial number. | ||
| 1045 | */ | ||
| 1046 | __wasi_inode_t ino; | ||
| 1047 | |||
| 1048 | /** | ||
| 1049 | * File type. | ||
| 1050 | */ | ||
| 1051 | __wasi_filetype_t filetype; | ||
| 1052 | |||
| 1053 | /** | ||
| 1054 | * Number of hard links to the file. | ||
| 1055 | */ | ||
| 1056 | __wasi_linkcount_t nlink; | ||
| 1057 | |||
| 1058 | /** | ||
| 1059 | * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. | ||
| 1060 | */ | ||
| 1061 | __wasi_filesize_t size; | ||
| 1062 | |||
| 1063 | /** | ||
| 1064 | * Last data access timestamp. | ||
| 1065 | */ | ||
| 1066 | __wasi_timestamp_t atim; | ||
| 1067 | |||
| 1068 | /** | ||
| 1069 | * Last data modification timestamp. | ||
| 1070 | */ | ||
| 1071 | __wasi_timestamp_t mtim; | ||
| 1072 | |||
| 1073 | /** | ||
| 1074 | * Last file status change timestamp. | ||
| 1075 | */ | ||
| 1076 | __wasi_timestamp_t ctim; | ||
| 1077 | |||
| 1078 | } __wasi_filestat_t; | ||
| 1079 | |||
| 1080 | _Static_assert(sizeof(__wasi_filestat_t) == 64, "witx calculated size"); | ||
| 1081 | _Static_assert(_Alignof(__wasi_filestat_t) == 8, "witx calculated align"); | ||
| 1082 | _Static_assert(offsetof(__wasi_filestat_t, dev) == 0, "witx calculated offset"); | ||
| 1083 | _Static_assert(offsetof(__wasi_filestat_t, ino) == 8, "witx calculated offset"); | ||
| 1084 | _Static_assert(offsetof(__wasi_filestat_t, filetype) == 16, "witx calculated offset"); | ||
| 1085 | _Static_assert(offsetof(__wasi_filestat_t, nlink) == 24, "witx calculated offset"); | ||
| 1086 | _Static_assert(offsetof(__wasi_filestat_t, size) == 32, "witx calculated offset"); | ||
| 1087 | _Static_assert(offsetof(__wasi_filestat_t, atim) == 40, "witx calculated offset"); | ||
| 1088 | _Static_assert(offsetof(__wasi_filestat_t, mtim) == 48, "witx calculated offset"); | ||
| 1089 | _Static_assert(offsetof(__wasi_filestat_t, ctim) == 56, "witx calculated offset"); | ||
| 1090 | |||
| 1091 | /** | ||
| 1092 | * User-provided value that may be attached to objects that is retained when | ||
| 1093 | * extracted from the implementation. | ||
| 1094 | */ | ||
| 1095 | typedef uint64_t __wasi_userdata_t; | ||
| 1096 | |||
| 1097 | _Static_assert(sizeof(__wasi_userdata_t) == 8, "witx calculated size"); | ||
| 1098 | _Static_assert(_Alignof(__wasi_userdata_t) == 8, "witx calculated align"); | ||
| 1099 | |||
| 1100 | /** | ||
| 1101 | * Type of a subscription to an event or its occurrence. | ||
| 1102 | */ | ||
| 1103 | typedef uint8_t __wasi_eventtype_t; | ||
| 1104 | |||
| 1105 | /** | ||
| 1106 | * The time value of clock `subscription_clock::id` has | ||
| 1107 | * reached timestamp `subscription_clock::timeout`. | ||
| 1108 | */ | ||
| 1109 | #define __WASI_EVENTTYPE_CLOCK (UINT8_C(0)) | ||
| 1110 | |||
| 1111 | /** | ||
| 1112 | * File descriptor `subscription_fd_readwrite::file_descriptor` has data | ||
| 1113 | * available for reading. This event always triggers for regular files. | ||
| 1114 | */ | ||
| 1115 | #define __WASI_EVENTTYPE_FD_READ (UINT8_C(1)) | ||
| 1116 | |||
| 1117 | /** | ||
| 1118 | * File descriptor `subscription_fd_readwrite::file_descriptor` has capacity | ||
| 1119 | * available for writing. This event always triggers for regular files. | ||
| 1120 | */ | ||
| 1121 | #define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2)) | ||
| 1122 | |||
| 1123 | _Static_assert(sizeof(__wasi_eventtype_t) == 1, "witx calculated size"); | ||
| 1124 | _Static_assert(_Alignof(__wasi_eventtype_t) == 1, "witx calculated align"); | ||
| 1125 | |||
| 1126 | /** | ||
| 1127 | * The state of the file descriptor subscribed to with | ||
| 1128 | * `eventtype::fd_read` or `eventtype::fd_write`. | ||
| 1129 | */ | ||
| 1130 | typedef uint16_t __wasi_eventrwflags_t; | ||
| 1131 | |||
| 1132 | /** | ||
| 1133 | * The peer of this socket has closed or disconnected. | ||
| 1134 | */ | ||
| 1135 | #define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)(1 << 0)) | ||
| 1136 | |||
| 1137 | /** | ||
| 1138 | * The contents of an `event` when type is `eventtype::fd_read` or | ||
| 1139 | * `eventtype::fd_write`. | ||
| 1140 | */ | ||
| 1141 | typedef struct __wasi_event_fd_readwrite_t { | ||
| 1142 | /** | ||
| 1143 | * The number of bytes available for reading or writing. | ||
| 1144 | */ | ||
| 1145 | __wasi_filesize_t nbytes; | ||
| 1146 | |||
| 1147 | /** | ||
| 1148 | * The state of the file descriptor. | ||
| 1149 | */ | ||
| 1150 | __wasi_eventrwflags_t flags; | ||
| 1151 | |||
| 1152 | } __wasi_event_fd_readwrite_t; | ||
| 1153 | |||
| 1154 | _Static_assert(sizeof(__wasi_event_fd_readwrite_t) == 16, "witx calculated size"); | ||
| 1155 | _Static_assert(_Alignof(__wasi_event_fd_readwrite_t) == 8, "witx calculated align"); | ||
| 1156 | _Static_assert(offsetof(__wasi_event_fd_readwrite_t, nbytes) == 0, "witx calculated offset"); | ||
| 1157 | _Static_assert(offsetof(__wasi_event_fd_readwrite_t, flags) == 8, "witx calculated offset"); | ||
| 1158 | |||
| 1159 | /** | ||
| 1160 | * An event that occurred. | ||
| 1161 | */ | ||
| 1162 | typedef struct __wasi_event_t { | ||
| 1163 | /** | ||
| 1164 | * User-provided value that got attached to `subscription::userdata`. | ||
| 1165 | */ | ||
| 1166 | __wasi_userdata_t userdata; | ||
| 1167 | |||
| 1168 | /** | ||
| 1169 | * If non-zero, an error that occurred while processing the subscription request. | ||
| 1170 | */ | ||
| 1171 | __wasi_errno_t error; | ||
| 1172 | |||
| 1173 | /** | ||
| 1174 | * The type of event that occured | ||
| 1175 | */ | ||
| 1176 | __wasi_eventtype_t type; | ||
| 1177 | |||
| 1178 | /** | ||
| 1179 | * The contents of the event, if it is an `eventtype::fd_read` or | ||
| 1180 | * `eventtype::fd_write`. `eventtype::clock` events ignore this field. | ||
| 1181 | */ | ||
| 1182 | __wasi_event_fd_readwrite_t fd_readwrite; | ||
| 1183 | |||
| 1184 | } __wasi_event_t; | ||
| 1185 | |||
| 1186 | _Static_assert(sizeof(__wasi_event_t) == 32, "witx calculated size"); | ||
| 1187 | _Static_assert(_Alignof(__wasi_event_t) == 8, "witx calculated align"); | ||
| 1188 | _Static_assert(offsetof(__wasi_event_t, userdata) == 0, "witx calculated offset"); | ||
| 1189 | _Static_assert(offsetof(__wasi_event_t, error) == 8, "witx calculated offset"); | ||
| 1190 | _Static_assert(offsetof(__wasi_event_t, type) == 10, "witx calculated offset"); | ||
| 1191 | _Static_assert(offsetof(__wasi_event_t, fd_readwrite) == 16, "witx calculated offset"); | ||
| 1192 | |||
| 1193 | /** | ||
| 1194 | * Flags determining how to interpret the timestamp provided in | ||
| 1195 | * `subscription_clock::timeout`. | ||
| 1196 | */ | ||
| 1197 | typedef uint16_t __wasi_subclockflags_t; | ||
| 1198 | |||
| 1199 | /** | ||
| 1200 | * If set, treat the timestamp provided in | ||
| 1201 | * `subscription_clock::timeout` as an absolute timestamp of clock | ||
| 1202 | * `subscription_clock::id`. If clear, treat the timestamp | ||
| 1203 | * provided in `subscription_clock::timeout` relative to the | ||
| 1204 | * current time value of clock `subscription_clock::id`. | ||
| 1205 | */ | ||
| 1206 | #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0)) | ||
| 1207 | |||
| 1208 | /** | ||
| 1209 | * The contents of a `subscription` when type is `eventtype::clock`. | ||
| 1210 | */ | ||
| 1211 | typedef struct __wasi_subscription_clock_t { | ||
| 1212 | /** | ||
| 1213 | * The clock against which to compare the timestamp. | ||
| 1214 | */ | ||
| 1215 | __wasi_clockid_t id; | ||
| 1216 | |||
| 1217 | /** | ||
| 1218 | * The absolute or relative timestamp. | ||
| 1219 | */ | ||
| 1220 | __wasi_timestamp_t timeout; | ||
| 1221 | |||
| 1222 | /** | ||
| 1223 | * The amount of time that the implementation may wait additionally | ||
| 1224 | * to coalesce with other events. | ||
| 1225 | */ | ||
| 1226 | __wasi_timestamp_t precision; | ||
| 1227 | |||
| 1228 | /** | ||
| 1229 | * Flags specifying whether the timeout is absolute or relative | ||
| 1230 | */ | ||
| 1231 | __wasi_subclockflags_t flags; | ||
| 1232 | |||
| 1233 | } __wasi_subscription_clock_t; | ||
| 1234 | |||
| 1235 | _Static_assert(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size"); | ||
| 1236 | _Static_assert(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align"); | ||
| 1237 | _Static_assert(offsetof(__wasi_subscription_clock_t, id) == 0, "witx calculated offset"); | ||
| 1238 | _Static_assert(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset"); | ||
| 1239 | _Static_assert(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset"); | ||
| 1240 | _Static_assert(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset"); | ||
| 1241 | |||
| 1242 | /** | ||
| 1243 | * The contents of a `subscription` when type is type is | ||
| 1244 | * `eventtype::fd_read` or `eventtype::fd_write`. | ||
| 1245 | */ | ||
| 1246 | typedef struct __wasi_subscription_fd_readwrite_t { | ||
| 1247 | /** | ||
| 1248 | * The file descriptor on which to wait for it to become ready for reading or writing. | ||
| 1249 | */ | ||
| 1250 | __wasi_fd_t file_descriptor; | ||
| 1251 | |||
| 1252 | } __wasi_subscription_fd_readwrite_t; | ||
| 1253 | |||
| 1254 | _Static_assert(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size"); | ||
| 1255 | _Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align"); | ||
| 1256 | _Static_assert(offsetof(__wasi_subscription_fd_readwrite_t, file_descriptor) == 0, "witx calculated offset"); | ||
| 1257 | |||
| 1258 | /** | ||
| 1259 | * The contents of a `subscription`. | ||
| 1260 | */ | ||
| 1261 | typedef union __wasi_subscription_u_u_t { | ||
| 1262 | __wasi_subscription_clock_t clock; | ||
| 1263 | __wasi_subscription_fd_readwrite_t fd_read; | ||
| 1264 | __wasi_subscription_fd_readwrite_t fd_write; | ||
| 1265 | } __wasi_subscription_u_u_t; | ||
| 1266 | typedef struct __wasi_subscription_u_t { | ||
| 1267 | uint8_t tag; | ||
| 1268 | __wasi_subscription_u_u_t u; | ||
| 1269 | } __wasi_subscription_u_t; | ||
| 1270 | |||
| 1271 | _Static_assert(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size"); | ||
| 1272 | _Static_assert(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align"); | ||
| 1273 | |||
| 1274 | /** | ||
| 1275 | * Subscription to an event. | ||
| 1276 | */ | ||
| 1277 | typedef struct __wasi_subscription_t { | ||
| 1278 | /** | ||
| 1279 | * User-provided value that is attached to the subscription in the | ||
| 1280 | * implementation and returned through `event::userdata`. | ||
| 1281 | */ | ||
| 1282 | __wasi_userdata_t userdata; | ||
| 1283 | |||
| 1284 | /** | ||
| 1285 | * The type of the event to which to subscribe, and its contents | ||
| 1286 | */ | ||
| 1287 | __wasi_subscription_u_t u; | ||
| 1288 | |||
| 1289 | } __wasi_subscription_t; | ||
| 1290 | |||
| 1291 | _Static_assert(sizeof(__wasi_subscription_t) == 48, "witx calculated size"); | ||
| 1292 | _Static_assert(_Alignof(__wasi_subscription_t) == 8, "witx calculated align"); | ||
| 1293 | _Static_assert(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset"); | ||
| 1294 | _Static_assert(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset"); | ||
| 1295 | |||
| 1296 | /** | ||
| 1297 | * Exit code generated by a process when exiting. | ||
| 1298 | */ | ||
| 1299 | typedef uint32_t __wasi_exitcode_t; | ||
| 1300 | |||
| 1301 | _Static_assert(sizeof(__wasi_exitcode_t) == 4, "witx calculated size"); | ||
| 1302 | _Static_assert(_Alignof(__wasi_exitcode_t) == 4, "witx calculated align"); | ||
| 1303 | |||
| 1304 | /** | ||
| 1305 | * Flags provided to `sock_recv`. | ||
| 1306 | */ | ||
| 1307 | typedef uint16_t __wasi_riflags_t; | ||
| 1308 | |||
| 1309 | /** | ||
| 1310 | * Returns the message without removing it from the socket's receive queue. | ||
| 1311 | */ | ||
| 1312 | #define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)(1 << 0)) | ||
| 1313 | |||
| 1314 | /** | ||
| 1315 | * On byte-stream sockets, block until the full amount of data can be returned. | ||
| 1316 | */ | ||
| 1317 | #define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1)) | ||
| 1318 | |||
| 1319 | /** | ||
| 1320 | * Flags returned by `sock_recv`. | ||
| 1321 | */ | ||
| 1322 | typedef uint16_t __wasi_roflags_t; | ||
| 1323 | |||
| 1324 | /** | ||
| 1325 | * Returned by `sock_recv`: Message data has been truncated. | ||
| 1326 | */ | ||
| 1327 | #define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)(1 << 0)) | ||
| 1328 | |||
| 1329 | /** | ||
| 1330 | * Flags provided to `sock_send`. As there are currently no flags | ||
| 1331 | * defined, it must be set to zero. | ||
| 1332 | */ | ||
| 1333 | typedef uint16_t __wasi_siflags_t; | ||
| 1334 | |||
| 1335 | _Static_assert(sizeof(__wasi_siflags_t) == 2, "witx calculated size"); | ||
| 1336 | _Static_assert(_Alignof(__wasi_siflags_t) == 2, "witx calculated align"); | ||
| 1337 | |||
| 1338 | /** | ||
| 1339 | * Which channels on a socket to shut down. | ||
| 1340 | */ | ||
| 1341 | typedef uint8_t __wasi_sdflags_t; | ||
| 1342 | |||
| 1343 | /** | ||
| 1344 | * Disables further receive operations. | ||
| 1345 | */ | ||
| 1346 | #define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0)) | ||
| 1347 | |||
| 1348 | /** | ||
| 1349 | * Disables further send operations. | ||
| 1350 | */ | ||
| 1351 | #define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1)) | ||
| 1352 | |||
| 1353 | /** | ||
| 1354 | * Identifiers for preopened capabilities. | ||
| 1355 | */ | ||
| 1356 | typedef uint8_t __wasi_preopentype_t; | ||
| 1357 | |||
| 1358 | /** | ||
| 1359 | * A pre-opened directory. | ||
| 1360 | */ | ||
| 1361 | #define __WASI_PREOPENTYPE_DIR (UINT8_C(0)) | ||
| 1362 | |||
| 1363 | _Static_assert(sizeof(__wasi_preopentype_t) == 1, "witx calculated size"); | ||
| 1364 | _Static_assert(_Alignof(__wasi_preopentype_t) == 1, "witx calculated align"); | ||
| 1365 | |||
| 1366 | /** | ||
| 1367 | * The contents of a $prestat when type is `preopentype::dir`. | ||
| 1368 | */ | ||
| 1369 | typedef struct __wasi_prestat_dir_t { | ||
| 1370 | /** | ||
| 1371 | * The length of the directory name for use with `fd_prestat_dir_name`. | ||
| 1372 | */ | ||
| 1373 | __wasi_size_t pr_name_len; | ||
| 1374 | |||
| 1375 | } __wasi_prestat_dir_t; | ||
| 1376 | |||
| 1377 | _Static_assert(sizeof(__wasi_prestat_dir_t) == 4, "witx calculated size"); | ||
| 1378 | _Static_assert(_Alignof(__wasi_prestat_dir_t) == 4, "witx calculated align"); | ||
| 1379 | _Static_assert(offsetof(__wasi_prestat_dir_t, pr_name_len) == 0, "witx calculated offset"); | ||
| 1380 | |||
| 1381 | /** | ||
| 1382 | * Information about a pre-opened capability. | ||
| 1383 | */ | ||
| 1384 | typedef union __wasi_prestat_u_t { | ||
| 1385 | __wasi_prestat_dir_t dir; | ||
| 1386 | } __wasi_prestat_u_t; | ||
| 1387 | typedef struct __wasi_prestat_t { | ||
| 1388 | uint8_t tag; | ||
| 1389 | __wasi_prestat_u_t u; | ||
| 1390 | } __wasi_prestat_t; | ||
| 1391 | |||
| 1392 | _Static_assert(sizeof(__wasi_prestat_t) == 8, "witx calculated size"); | ||
| 1393 | _Static_assert(_Alignof(__wasi_prestat_t) == 4, "witx calculated align"); | ||
| 1394 | |||
| 1395 | /** | ||
| 1396 | * @defgroup wasi_snapshot_preview1 | ||
| 1397 | * @{ | ||
| 1398 | */ | ||
| 1399 | |||
| 1400 | /** | ||
| 1401 | * Read command-line argument data. | ||
| 1402 | * The size of the array should match that returned by `args_sizes_get`. | ||
| 1403 | * Each argument is expected to be `\0` terminated. | ||
| 1404 | */ | ||
| 1405 | __wasi_errno_t __wasi_args_get( | ||
| 1406 | uint8_t * * argv, | ||
| 1407 | uint8_t * argv_buf | ||
| 1408 | ) __attribute__((__warn_unused_result__)); | ||
| 1409 | /** | ||
| 1410 | * Return command-line argument data sizes. | ||
| 1411 | * @return | ||
| 1412 | * Returns the number of arguments and the size of the argument string | ||
| 1413 | * data, or an error. | ||
| 1414 | */ | ||
| 1415 | __wasi_errno_t __wasi_args_sizes_get( | ||
| 1416 | __wasi_size_t *retptr0, | ||
| 1417 | __wasi_size_t *retptr1 | ||
| 1418 | ) __attribute__((__warn_unused_result__)); | ||
| 1419 | /** | ||
| 1420 | * Read environment variable data. | ||
| 1421 | * The sizes of the buffers should match that returned by `environ_sizes_get`. | ||
| 1422 | * Key/value pairs are expected to be joined with `=`s, and terminated with `\0`s. | ||
| 1423 | */ | ||
| 1424 | __wasi_errno_t __wasi_environ_get( | ||
| 1425 | uint8_t * * environ, | ||
| 1426 | uint8_t * environ_buf | ||
| 1427 | ) __attribute__((__warn_unused_result__)); | ||
| 1428 | /** | ||
| 1429 | * Return environment variable data sizes. | ||
| 1430 | * @return | ||
| 1431 | * Returns the number of environment variable arguments and the size of the | ||
| 1432 | * environment variable data. | ||
| 1433 | */ | ||
| 1434 | __wasi_errno_t __wasi_environ_sizes_get( | ||
| 1435 | __wasi_size_t *retptr0, | ||
| 1436 | __wasi_size_t *retptr1 | ||
| 1437 | ) __attribute__((__warn_unused_result__)); | ||
| 1438 | /** | ||
| 1439 | * Return the resolution of a clock. | ||
| 1440 | * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, | ||
| 1441 | * return `errno::inval`. | ||
| 1442 | * Note: This is similar to `clock_getres` in POSIX. | ||
| 1443 | * @return | ||
| 1444 | * The resolution of the clock, or an error if one happened. | ||
| 1445 | */ | ||
| 1446 | __wasi_errno_t __wasi_clock_res_get( | ||
| 1447 | /** | ||
| 1448 | * The clock for which to return the resolution. | ||
| 1449 | */ | ||
| 1450 | __wasi_clockid_t id, | ||
| 1451 | __wasi_timestamp_t *retptr0 | ||
| 1452 | ) __attribute__((__warn_unused_result__)); | ||
| 1453 | /** | ||
| 1454 | * Return the time value of a clock. | ||
| 1455 | * Note: This is similar to `clock_gettime` in POSIX. | ||
| 1456 | * @return | ||
| 1457 | * The time value of the clock. | ||
| 1458 | */ | ||
| 1459 | __wasi_errno_t __wasi_clock_time_get( | ||
| 1460 | /** | ||
| 1461 | * The clock for which to return the time. | ||
| 1462 | */ | ||
| 1463 | __wasi_clockid_t id, | ||
| 1464 | /** | ||
| 1465 | * The maximum lag (exclusive) that the returned time value may have, compared to its actual value. | ||
| 1466 | */ | ||
| 1467 | __wasi_timestamp_t precision, | ||
| 1468 | __wasi_timestamp_t *retptr0 | ||
| 1469 | ) __attribute__((__warn_unused_result__)); | ||
| 1470 | /** | ||
| 1471 | * Provide file advisory information on a file descriptor. | ||
| 1472 | * Note: This is similar to `posix_fadvise` in POSIX. | ||
| 1473 | */ | ||
| 1474 | __wasi_errno_t __wasi_fd_advise( | ||
| 1475 | __wasi_fd_t fd, | ||
| 1476 | /** | ||
| 1477 | * The offset within the file to which the advisory applies. | ||
| 1478 | */ | ||
| 1479 | __wasi_filesize_t offset, | ||
| 1480 | /** | ||
| 1481 | * The length of the region to which the advisory applies. | ||
| 1482 | */ | ||
| 1483 | __wasi_filesize_t len, | ||
| 1484 | /** | ||
| 1485 | * The advice. | ||
| 1486 | */ | ||
| 1487 | __wasi_advice_t advice | ||
| 1488 | ) __attribute__((__warn_unused_result__)); | ||
| 1489 | /** | ||
| 1490 | * Force the allocation of space in a file. | ||
| 1491 | * Note: This is similar to `posix_fallocate` in POSIX. | ||
| 1492 | */ | ||
| 1493 | __wasi_errno_t __wasi_fd_allocate( | ||
| 1494 | __wasi_fd_t fd, | ||
| 1495 | /** | ||
| 1496 | * The offset at which to start the allocation. | ||
| 1497 | */ | ||
| 1498 | __wasi_filesize_t offset, | ||
| 1499 | /** | ||
| 1500 | * The length of the area that is allocated. | ||
| 1501 | */ | ||
| 1502 | __wasi_filesize_t len | ||
| 1503 | ) __attribute__((__warn_unused_result__)); | ||
| 1504 | /** | ||
| 1505 | * Close a file descriptor. | ||
| 1506 | * Note: This is similar to `close` in POSIX. | ||
| 1507 | */ | ||
| 1508 | __wasi_errno_t __wasi_fd_close( | ||
| 1509 | __wasi_fd_t fd | ||
| 1510 | ) __attribute__((__warn_unused_result__)); | ||
| 1511 | /** | ||
| 1512 | * Synchronize the data of a file to disk. | ||
| 1513 | * Note: This is similar to `fdatasync` in POSIX. | ||
| 1514 | */ | ||
| 1515 | __wasi_errno_t __wasi_fd_datasync( | ||
| 1516 | __wasi_fd_t fd | ||
| 1517 | ) __attribute__((__warn_unused_result__)); | ||
| 1518 | /** | ||
| 1519 | * Get the attributes of a file descriptor. | ||
| 1520 | * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. | ||
| 1521 | * @return | ||
| 1522 | * The buffer where the file descriptor's attributes are stored. | ||
| 1523 | */ | ||
| 1524 | __wasi_errno_t __wasi_fd_fdstat_get( | ||
| 1525 | __wasi_fd_t fd, | ||
| 1526 | __wasi_fdstat_t *retptr0 | ||
| 1527 | ) __attribute__((__warn_unused_result__)); | ||
| 1528 | /** | ||
| 1529 | * Adjust the flags associated with a file descriptor. | ||
| 1530 | * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. | ||
| 1531 | */ | ||
| 1532 | __wasi_errno_t __wasi_fd_fdstat_set_flags( | ||
| 1533 | __wasi_fd_t fd, | ||
| 1534 | /** | ||
| 1535 | * The desired values of the file descriptor flags. | ||
| 1536 | */ | ||
| 1537 | __wasi_fdflags_t flags | ||
| 1538 | ) __attribute__((__warn_unused_result__)); | ||
| 1539 | /** | ||
| 1540 | * Adjust the rights associated with a file descriptor. | ||
| 1541 | * This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights | ||
| 1542 | */ | ||
| 1543 | __wasi_errno_t __wasi_fd_fdstat_set_rights( | ||
| 1544 | __wasi_fd_t fd, | ||
| 1545 | /** | ||
| 1546 | * The desired rights of the file descriptor. | ||
| 1547 | */ | ||
| 1548 | __wasi_rights_t fs_rights_base, | ||
| 1549 | __wasi_rights_t fs_rights_inheriting | ||
| 1550 | ) __attribute__((__warn_unused_result__)); | ||
| 1551 | /** | ||
| 1552 | * Return the attributes of an open file. | ||
| 1553 | * @return | ||
| 1554 | * The buffer where the file's attributes are stored. | ||
| 1555 | */ | ||
| 1556 | __wasi_errno_t __wasi_fd_filestat_get( | ||
| 1557 | __wasi_fd_t fd, | ||
| 1558 | __wasi_filestat_t *retptr0 | ||
| 1559 | ) __attribute__((__warn_unused_result__)); | ||
| 1560 | /** | ||
| 1561 | * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. | ||
| 1562 | * Note: This is similar to `ftruncate` in POSIX. | ||
| 1563 | */ | ||
| 1564 | __wasi_errno_t __wasi_fd_filestat_set_size( | ||
| 1565 | __wasi_fd_t fd, | ||
| 1566 | /** | ||
| 1567 | * The desired file size. | ||
| 1568 | */ | ||
| 1569 | __wasi_filesize_t size | ||
| 1570 | ) __attribute__((__warn_unused_result__)); | ||
| 1571 | /** | ||
| 1572 | * Adjust the timestamps of an open file or directory. | ||
| 1573 | * Note: This is similar to `futimens` in POSIX. | ||
| 1574 | */ | ||
| 1575 | __wasi_errno_t __wasi_fd_filestat_set_times( | ||
| 1576 | __wasi_fd_t fd, | ||
| 1577 | /** | ||
| 1578 | * The desired values of the data access timestamp. | ||
| 1579 | */ | ||
| 1580 | __wasi_timestamp_t atim, | ||
| 1581 | /** | ||
| 1582 | * The desired values of the data modification timestamp. | ||
| 1583 | */ | ||
| 1584 | __wasi_timestamp_t mtim, | ||
| 1585 | /** | ||
| 1586 | * A bitmask indicating which timestamps to adjust. | ||
| 1587 | */ | ||
| 1588 | __wasi_fstflags_t fst_flags | ||
| 1589 | ) __attribute__((__warn_unused_result__)); | ||
| 1590 | /** | ||
| 1591 | * Read from a file descriptor, without using and updating the file descriptor's offset. | ||
| 1592 | * Note: This is similar to `preadv` in POSIX. | ||
| 1593 | * @return | ||
| 1594 | * The number of bytes read. | ||
| 1595 | */ | ||
| 1596 | __wasi_errno_t __wasi_fd_pread( | ||
| 1597 | __wasi_fd_t fd, | ||
| 1598 | /** | ||
| 1599 | * List of scatter/gather vectors in which to store data. | ||
| 1600 | */ | ||
| 1601 | const __wasi_iovec_t *iovs, | ||
| 1602 | /** | ||
| 1603 | * The length of the array pointed to by `iovs`. | ||
| 1604 | */ | ||
| 1605 | size_t iovs_len, | ||
| 1606 | /** | ||
| 1607 | * The offset within the file at which to read. | ||
| 1608 | */ | ||
| 1609 | __wasi_filesize_t offset, | ||
| 1610 | __wasi_size_t *retptr0 | ||
| 1611 | ) __attribute__((__warn_unused_result__)); | ||
| 1612 | /** | ||
| 1613 | * Return a description of the given preopened file descriptor. | ||
| 1614 | * @return | ||
| 1615 | * The buffer where the description is stored. | ||
| 1616 | */ | ||
| 1617 | __wasi_errno_t __wasi_fd_prestat_get( | ||
| 1618 | __wasi_fd_t fd, | ||
| 1619 | __wasi_prestat_t *retptr0 | ||
| 1620 | ) __attribute__((__warn_unused_result__)); | ||
| 1621 | /** | ||
| 1622 | * Return a description of the given preopened file descriptor. | ||
| 1623 | */ | ||
| 1624 | __wasi_errno_t __wasi_fd_prestat_dir_name( | ||
| 1625 | __wasi_fd_t fd, | ||
| 1626 | /** | ||
| 1627 | * A buffer into which to write the preopened directory name. | ||
| 1628 | */ | ||
| 1629 | uint8_t * path, | ||
| 1630 | __wasi_size_t path_len | ||
| 1631 | ) __attribute__((__warn_unused_result__)); | ||
| 1632 | /** | ||
| 1633 | * Write to a file descriptor, without using and updating the file descriptor's offset. | ||
| 1634 | * Note: This is similar to `pwritev` in POSIX. | ||
| 1635 | * @return | ||
| 1636 | * The number of bytes written. | ||
| 1637 | */ | ||
| 1638 | __wasi_errno_t __wasi_fd_pwrite( | ||
| 1639 | __wasi_fd_t fd, | ||
| 1640 | /** | ||
| 1641 | * List of scatter/gather vectors from which to retrieve data. | ||
| 1642 | */ | ||
| 1643 | const __wasi_ciovec_t *iovs, | ||
| 1644 | /** | ||
| 1645 | * The length of the array pointed to by `iovs`. | ||
| 1646 | */ | ||
| 1647 | size_t iovs_len, | ||
| 1648 | /** | ||
| 1649 | * The offset within the file at which to write. | ||
| 1650 | */ | ||
| 1651 | __wasi_filesize_t offset, | ||
| 1652 | __wasi_size_t *retptr0 | ||
| 1653 | ) __attribute__((__warn_unused_result__)); | ||
| 1654 | /** | ||
| 1655 | * Read from a file descriptor. | ||
| 1656 | * Note: This is similar to `readv` in POSIX. | ||
| 1657 | * @return | ||
| 1658 | * The number of bytes read. | ||
| 1659 | */ | ||
| 1660 | __wasi_errno_t __wasi_fd_read( | ||
| 1661 | __wasi_fd_t fd, | ||
| 1662 | /** | ||
| 1663 | * List of scatter/gather vectors to which to store data. | ||
| 1664 | */ | ||
| 1665 | const __wasi_iovec_t *iovs, | ||
| 1666 | /** | ||
| 1667 | * The length of the array pointed to by `iovs`. | ||
| 1668 | */ | ||
| 1669 | size_t iovs_len, | ||
| 1670 | __wasi_size_t *retptr0 | ||
| 1671 | ) __attribute__((__warn_unused_result__)); | ||
| 1672 | /** | ||
| 1673 | * Read directory entries from a directory. | ||
| 1674 | * When successful, the contents of the output buffer consist of a sequence of | ||
| 1675 | * directory entries. Each directory entry consists of a `dirent` object, | ||
| 1676 | * followed by `dirent::d_namlen` bytes holding the name of the directory | ||
| 1677 | * entry. | ||
| 1678 | * This function fills the output buffer as much as possible, potentially | ||
| 1679 | * truncating the last directory entry. This allows the caller to grow its | ||
| 1680 | * read buffer size in case it's too small to fit a single large directory | ||
| 1681 | * entry, or skip the oversized directory entry. | ||
| 1682 | * @return | ||
| 1683 | * The number of bytes stored in the read buffer. If less than the size of the read buffer, the end of the directory has been reached. | ||
| 1684 | */ | ||
| 1685 | __wasi_errno_t __wasi_fd_readdir( | ||
| 1686 | __wasi_fd_t fd, | ||
| 1687 | /** | ||
| 1688 | * The buffer where directory entries are stored | ||
| 1689 | */ | ||
| 1690 | uint8_t * buf, | ||
| 1691 | __wasi_size_t buf_len, | ||
| 1692 | /** | ||
| 1693 | * The location within the directory to start reading | ||
| 1694 | */ | ||
| 1695 | __wasi_dircookie_t cookie, | ||
| 1696 | __wasi_size_t *retptr0 | ||
| 1697 | ) __attribute__((__warn_unused_result__)); | ||
| 1698 | /** | ||
| 1699 | * Atomically replace a file descriptor by renumbering another file descriptor. | ||
| 1700 | * Due to the strong focus on thread safety, this environment does not provide | ||
| 1701 | * a mechanism to duplicate or renumber a file descriptor to an arbitrary | ||
| 1702 | * number, like `dup2()`. This would be prone to race conditions, as an actual | ||
| 1703 | * file descriptor with the same number could be allocated by a different | ||
| 1704 | * thread at the same time. | ||
| 1705 | * This function provides a way to atomically renumber file descriptors, which | ||
| 1706 | * would disappear if `dup2()` were to be removed entirely. | ||
| 1707 | */ | ||
| 1708 | __wasi_errno_t __wasi_fd_renumber( | ||
| 1709 | __wasi_fd_t fd, | ||
| 1710 | /** | ||
| 1711 | * The file descriptor to overwrite. | ||
| 1712 | */ | ||
| 1713 | __wasi_fd_t to | ||
| 1714 | ) __attribute__((__warn_unused_result__)); | ||
| 1715 | /** | ||
| 1716 | * Move the offset of a file descriptor. | ||
| 1717 | * Note: This is similar to `lseek` in POSIX. | ||
| 1718 | * @return | ||
| 1719 | * The new offset of the file descriptor, relative to the start of the file. | ||
| 1720 | */ | ||
| 1721 | __wasi_errno_t __wasi_fd_seek( | ||
| 1722 | __wasi_fd_t fd, | ||
| 1723 | /** | ||
| 1724 | * The number of bytes to move. | ||
| 1725 | */ | ||
| 1726 | __wasi_filedelta_t offset, | ||
| 1727 | /** | ||
| 1728 | * The base from which the offset is relative. | ||
| 1729 | */ | ||
| 1730 | __wasi_whence_t whence, | ||
| 1731 | __wasi_filesize_t *retptr0 | ||
| 1732 | ) __attribute__((__warn_unused_result__)); | ||
| 1733 | /** | ||
| 1734 | * Synchronize the data and metadata of a file to disk. | ||
| 1735 | * Note: This is similar to `fsync` in POSIX. | ||
| 1736 | */ | ||
| 1737 | __wasi_errno_t __wasi_fd_sync( | ||
| 1738 | __wasi_fd_t fd | ||
| 1739 | ) __attribute__((__warn_unused_result__)); | ||
| 1740 | /** | ||
| 1741 | * Return the current offset of a file descriptor. | ||
| 1742 | * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. | ||
| 1743 | * @return | ||
| 1744 | * The current offset of the file descriptor, relative to the start of the file. | ||
| 1745 | */ | ||
| 1746 | __wasi_errno_t __wasi_fd_tell( | ||
| 1747 | __wasi_fd_t fd, | ||
| 1748 | __wasi_filesize_t *retptr0 | ||
| 1749 | ) __attribute__((__warn_unused_result__)); | ||
| 1750 | /** | ||
| 1751 | * Write to a file descriptor. | ||
| 1752 | * Note: This is similar to `writev` in POSIX. | ||
| 1753 | */ | ||
| 1754 | __wasi_errno_t __wasi_fd_write( | ||
| 1755 | __wasi_fd_t fd, | ||
| 1756 | /** | ||
| 1757 | * List of scatter/gather vectors from which to retrieve data. | ||
| 1758 | */ | ||
| 1759 | const __wasi_ciovec_t *iovs, | ||
| 1760 | /** | ||
| 1761 | * The length of the array pointed to by `iovs`. | ||
| 1762 | */ | ||
| 1763 | size_t iovs_len, | ||
| 1764 | __wasi_size_t *retptr0 | ||
| 1765 | ) __attribute__((__warn_unused_result__)); | ||
| 1766 | /** | ||
| 1767 | * Create a directory. | ||
| 1768 | * Note: This is similar to `mkdirat` in POSIX. | ||
| 1769 | */ | ||
| 1770 | __wasi_errno_t __wasi_path_create_directory( | ||
| 1771 | __wasi_fd_t fd, | ||
| 1772 | /** | ||
| 1773 | * The path at which to create the directory. | ||
| 1774 | */ | ||
| 1775 | const char *path | ||
| 1776 | ) __attribute__((__warn_unused_result__)); | ||
| 1777 | /** | ||
| 1778 | * Return the attributes of a file or directory. | ||
| 1779 | * Note: This is similar to `stat` in POSIX. | ||
| 1780 | * @return | ||
| 1781 | * The buffer where the file's attributes are stored. | ||
| 1782 | */ | ||
| 1783 | __wasi_errno_t __wasi_path_filestat_get( | ||
| 1784 | __wasi_fd_t fd, | ||
| 1785 | /** | ||
| 1786 | * Flags determining the method of how the path is resolved. | ||
| 1787 | */ | ||
| 1788 | __wasi_lookupflags_t flags, | ||
| 1789 | /** | ||
| 1790 | * The path of the file or directory to inspect. | ||
| 1791 | */ | ||
| 1792 | const char *path, | ||
| 1793 | __wasi_filestat_t *retptr0 | ||
| 1794 | ) __attribute__((__warn_unused_result__)); | ||
| 1795 | /** | ||
| 1796 | * Adjust the timestamps of a file or directory. | ||
| 1797 | * Note: This is similar to `utimensat` in POSIX. | ||
| 1798 | */ | ||
| 1799 | __wasi_errno_t __wasi_path_filestat_set_times( | ||
| 1800 | __wasi_fd_t fd, | ||
| 1801 | /** | ||
| 1802 | * Flags determining the method of how the path is resolved. | ||
| 1803 | */ | ||
| 1804 | __wasi_lookupflags_t flags, | ||
| 1805 | /** | ||
| 1806 | * The path of the file or directory to operate on. | ||
| 1807 | */ | ||
| 1808 | const char *path, | ||
| 1809 | /** | ||
| 1810 | * The desired values of the data access timestamp. | ||
| 1811 | */ | ||
| 1812 | __wasi_timestamp_t atim, | ||
| 1813 | /** | ||
| 1814 | * The desired values of the data modification timestamp. | ||
| 1815 | */ | ||
| 1816 | __wasi_timestamp_t mtim, | ||
| 1817 | /** | ||
| 1818 | * A bitmask indicating which timestamps to adjust. | ||
| 1819 | */ | ||
| 1820 | __wasi_fstflags_t fst_flags | ||
| 1821 | ) __attribute__((__warn_unused_result__)); | ||
| 1822 | /** | ||
| 1823 | * Create a hard link. | ||
| 1824 | * Note: This is similar to `linkat` in POSIX. | ||
| 1825 | */ | ||
| 1826 | __wasi_errno_t __wasi_path_link( | ||
| 1827 | __wasi_fd_t old_fd, | ||
| 1828 | /** | ||
| 1829 | * Flags determining the method of how the path is resolved. | ||
| 1830 | */ | ||
| 1831 | __wasi_lookupflags_t old_flags, | ||
| 1832 | /** | ||
| 1833 | * The source path from which to link. | ||
| 1834 | */ | ||
| 1835 | const char *old_path, | ||
| 1836 | /** | ||
| 1837 | * The working directory at which the resolution of the new path starts. | ||
| 1838 | */ | ||
| 1839 | __wasi_fd_t new_fd, | ||
| 1840 | /** | ||
| 1841 | * The destination path at which to create the hard link. | ||
| 1842 | */ | ||
| 1843 | const char *new_path | ||
| 1844 | ) __attribute__((__warn_unused_result__)); | ||
| 1845 | /** | ||
| 1846 | * Open a file or directory. | ||
| 1847 | * The returned file descriptor is not guaranteed to be the lowest-numbered | ||
| 1848 | * file descriptor not currently open; it is randomized to prevent | ||
| 1849 | * applications from depending on making assumptions about indexes, since this | ||
| 1850 | * is error-prone in multi-threaded contexts. The returned file descriptor is | ||
| 1851 | * guaranteed to be less than 2**31. | ||
| 1852 | * Note: This is similar to `openat` in POSIX. | ||
| 1853 | * @return | ||
| 1854 | * The file descriptor of the file that has been opened. | ||
| 1855 | */ | ||
| 1856 | __wasi_errno_t __wasi_path_open( | ||
| 1857 | __wasi_fd_t fd, | ||
| 1858 | /** | ||
| 1859 | * Flags determining the method of how the path is resolved. | ||
| 1860 | */ | ||
| 1861 | __wasi_lookupflags_t dirflags, | ||
| 1862 | /** | ||
| 1863 | * The relative path of the file or directory to open, relative to the | ||
| 1864 | * `path_open::fd` directory. | ||
| 1865 | */ | ||
| 1866 | const char *path, | ||
| 1867 | /** | ||
| 1868 | * The method by which to open the file. | ||
| 1869 | */ | ||
| 1870 | __wasi_oflags_t oflags, | ||
| 1871 | /** | ||
| 1872 | * The initial rights of the newly created file descriptor. The | ||
| 1873 | * implementation is allowed to return a file descriptor with fewer rights | ||
| 1874 | * than specified, if and only if those rights do not apply to the type of | ||
| 1875 | * file being opened. | ||
| 1876 | * The *base* rights are rights that will apply to operations using the file | ||
| 1877 | * descriptor itself, while the *inheriting* rights are rights that apply to | ||
| 1878 | * file descriptors derived from it. | ||
| 1879 | */ | ||
| 1880 | __wasi_rights_t fs_rights_base, | ||
| 1881 | __wasi_rights_t fs_rights_inheriting, | ||
| 1882 | __wasi_fdflags_t fdflags, | ||
| 1883 | __wasi_fd_t *retptr0 | ||
| 1884 | ) __attribute__((__warn_unused_result__)); | ||
| 1885 | /** | ||
| 1886 | * Read the contents of a symbolic link. | ||
| 1887 | * Note: This is similar to `readlinkat` in POSIX. | ||
| 1888 | * @return | ||
| 1889 | * The number of bytes placed in the buffer. | ||
| 1890 | */ | ||
| 1891 | __wasi_errno_t __wasi_path_readlink( | ||
| 1892 | __wasi_fd_t fd, | ||
| 1893 | /** | ||
| 1894 | * The path of the symbolic link from which to read. | ||
| 1895 | */ | ||
| 1896 | const char *path, | ||
| 1897 | /** | ||
| 1898 | * The buffer to which to write the contents of the symbolic link. | ||
| 1899 | */ | ||
| 1900 | uint8_t * buf, | ||
| 1901 | __wasi_size_t buf_len, | ||
| 1902 | __wasi_size_t *retptr0 | ||
| 1903 | ) __attribute__((__warn_unused_result__)); | ||
| 1904 | /** | ||
| 1905 | * Remove a directory. | ||
| 1906 | * Return `errno::notempty` if the directory is not empty. | ||
| 1907 | * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. | ||
| 1908 | */ | ||
| 1909 | __wasi_errno_t __wasi_path_remove_directory( | ||
| 1910 | __wasi_fd_t fd, | ||
| 1911 | /** | ||
| 1912 | * The path to a directory to remove. | ||
| 1913 | */ | ||
| 1914 | const char *path | ||
| 1915 | ) __attribute__((__warn_unused_result__)); | ||
| 1916 | /** | ||
| 1917 | * Rename a file or directory. | ||
| 1918 | * Note: This is similar to `renameat` in POSIX. | ||
| 1919 | */ | ||
| 1920 | __wasi_errno_t __wasi_path_rename( | ||
| 1921 | __wasi_fd_t fd, | ||
| 1922 | /** | ||
| 1923 | * The source path of the file or directory to rename. | ||
| 1924 | */ | ||
| 1925 | const char *old_path, | ||
| 1926 | /** | ||
| 1927 | * The working directory at which the resolution of the new path starts. | ||
| 1928 | */ | ||
| 1929 | __wasi_fd_t new_fd, | ||
| 1930 | /** | ||
| 1931 | * The destination path to which to rename the file or directory. | ||
| 1932 | */ | ||
| 1933 | const char *new_path | ||
| 1934 | ) __attribute__((__warn_unused_result__)); | ||
| 1935 | /** | ||
| 1936 | * Create a symbolic link. | ||
| 1937 | * Note: This is similar to `symlinkat` in POSIX. | ||
| 1938 | */ | ||
| 1939 | __wasi_errno_t __wasi_path_symlink( | ||
| 1940 | /** | ||
| 1941 | * The contents of the symbolic link. | ||
| 1942 | */ | ||
| 1943 | const char *old_path, | ||
| 1944 | __wasi_fd_t fd, | ||
| 1945 | /** | ||
| 1946 | * The destination path at which to create the symbolic link. | ||
| 1947 | */ | ||
| 1948 | const char *new_path | ||
| 1949 | ) __attribute__((__warn_unused_result__)); | ||
| 1950 | /** | ||
| 1951 | * Unlink a file. | ||
| 1952 | * Return `errno::isdir` if the path refers to a directory. | ||
| 1953 | * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. | ||
| 1954 | */ | ||
| 1955 | __wasi_errno_t __wasi_path_unlink_file( | ||
| 1956 | __wasi_fd_t fd, | ||
| 1957 | /** | ||
| 1958 | * The path to a file to unlink. | ||
| 1959 | */ | ||
| 1960 | const char *path | ||
| 1961 | ) __attribute__((__warn_unused_result__)); | ||
| 1962 | /** | ||
| 1963 | * Concurrently poll for the occurrence of a set of events. | ||
| 1964 | * @return | ||
| 1965 | * The number of events stored. | ||
| 1966 | */ | ||
| 1967 | __wasi_errno_t __wasi_poll_oneoff( | ||
| 1968 | /** | ||
| 1969 | * The events to which to subscribe. | ||
| 1970 | */ | ||
| 1971 | const __wasi_subscription_t * in, | ||
| 1972 | /** | ||
| 1973 | * The events that have occurred. | ||
| 1974 | */ | ||
| 1975 | __wasi_event_t * out, | ||
| 1976 | /** | ||
| 1977 | * Both the number of subscriptions and events. | ||
| 1978 | */ | ||
| 1979 | __wasi_size_t nsubscriptions, | ||
| 1980 | __wasi_size_t *retptr0 | ||
| 1981 | ) __attribute__((__warn_unused_result__)); | ||
| 1982 | /** | ||
| 1983 | * Terminate the process normally. An exit code of 0 indicates successful | ||
| 1984 | * termination of the program. The meanings of other values is dependent on | ||
| 1985 | * the environment. | ||
| 1986 | */ | ||
| 1987 | _Noreturn void __wasi_proc_exit( | ||
| 1988 | /** | ||
| 1989 | * The exit code returned by the process. | ||
| 1990 | */ | ||
| 1991 | __wasi_exitcode_t rval | ||
| 1992 | ); | ||
| 1993 | /** | ||
| 1994 | * Temporarily yield execution of the calling thread. | ||
| 1995 | * Note: This is similar to `sched_yield` in POSIX. | ||
| 1996 | */ | ||
| 1997 | __wasi_errno_t __wasi_sched_yield( | ||
| 1998 | void | ||
| 1999 | ) __attribute__((__warn_unused_result__)); | ||
| 2000 | /** | ||
| 2001 | * Write high-quality random data into a buffer. | ||
| 2002 | * This function blocks when the implementation is unable to immediately | ||
| 2003 | * provide sufficient high-quality random data. | ||
| 2004 | * This function may execute slowly, so when large mounts of random data are | ||
| 2005 | * required, it's advisable to use this function to seed a pseudo-random | ||
| 2006 | * number generator, rather than to provide the random data directly. | ||
| 2007 | */ | ||
| 2008 | __wasi_errno_t __wasi_random_get( | ||
| 2009 | /** | ||
| 2010 | * The buffer to fill with random data. | ||
| 2011 | */ | ||
| 2012 | uint8_t * buf, | ||
| 2013 | __wasi_size_t buf_len | ||
| 2014 | ) __attribute__((__warn_unused_result__)); | ||
| 2015 | /** | ||
| 2016 | * Accept a new incoming connection. | ||
| 2017 | * Note: This is similar to `accept` in POSIX. | ||
| 2018 | * @return | ||
| 2019 | * New socket connection | ||
| 2020 | */ | ||
| 2021 | __wasi_errno_t __wasi_sock_accept( | ||
| 2022 | /** | ||
| 2023 | * The listening socket. | ||
| 2024 | */ | ||
| 2025 | __wasi_fd_t fd, | ||
| 2026 | /** | ||
| 2027 | * The desired values of the file descriptor flags. | ||
| 2028 | */ | ||
| 2029 | __wasi_fdflags_t flags, | ||
| 2030 | __wasi_fd_t *retptr0 | ||
| 2031 | ) __attribute__((__warn_unused_result__)); | ||
| 2032 | /** | ||
| 2033 | * Receive a message from a socket. | ||
| 2034 | * Note: This is similar to `recv` in POSIX, though it also supports reading | ||
| 2035 | * the data into multiple buffers in the manner of `readv`. | ||
| 2036 | * @return | ||
| 2037 | * Number of bytes stored in ri_data and message flags. | ||
| 2038 | */ | ||
| 2039 | __wasi_errno_t __wasi_sock_recv( | ||
| 2040 | __wasi_fd_t fd, | ||
| 2041 | /** | ||
| 2042 | * List of scatter/gather vectors to which to store data. | ||
| 2043 | */ | ||
| 2044 | const __wasi_iovec_t *ri_data, | ||
| 2045 | /** | ||
| 2046 | * The length of the array pointed to by `ri_data`. | ||
| 2047 | */ | ||
| 2048 | size_t ri_data_len, | ||
| 2049 | /** | ||
| 2050 | * Message flags. | ||
| 2051 | */ | ||
| 2052 | __wasi_riflags_t ri_flags, | ||
| 2053 | __wasi_size_t *retptr0, | ||
| 2054 | __wasi_roflags_t *retptr1 | ||
| 2055 | ) __attribute__((__warn_unused_result__)); | ||
| 2056 | /** | ||
| 2057 | * Send a message on a socket. | ||
| 2058 | * Note: This is similar to `send` in POSIX, though it also supports writing | ||
| 2059 | * the data from multiple buffers in the manner of `writev`. | ||
| 2060 | * @return | ||
| 2061 | * Number of bytes transmitted. | ||
| 2062 | */ | ||
| 2063 | __wasi_errno_t __wasi_sock_send( | ||
| 2064 | __wasi_fd_t fd, | ||
| 2065 | /** | ||
| 2066 | * List of scatter/gather vectors to which to retrieve data | ||
| 2067 | */ | ||
| 2068 | const __wasi_ciovec_t *si_data, | ||
| 2069 | /** | ||
| 2070 | * The length of the array pointed to by `si_data`. | ||
| 2071 | */ | ||
| 2072 | size_t si_data_len, | ||
| 2073 | /** | ||
| 2074 | * Message flags. | ||
| 2075 | */ | ||
| 2076 | __wasi_siflags_t si_flags, | ||
| 2077 | __wasi_size_t *retptr0 | ||
| 2078 | ) __attribute__((__warn_unused_result__)); | ||
| 2079 | /** | ||
| 2080 | * Shut down socket send and receive channels. | ||
| 2081 | * Note: This is similar to `shutdown` in POSIX. | ||
| 2082 | */ | ||
| 2083 | __wasi_errno_t __wasi_sock_shutdown( | ||
| 2084 | __wasi_fd_t fd, | ||
| 2085 | /** | ||
| 2086 | * Which channels on the socket to shut down. | ||
| 2087 | */ | ||
| 2088 | __wasi_sdflags_t how | ||
| 2089 | ) __attribute__((__warn_unused_result__)); | ||
| 2090 | /** @} */ | ||
| 2091 | |||
| 2092 | #ifdef _REENTRANT | ||
| 2093 | /** | ||
| 2094 | * Request a new thread to be created by the host. | ||
| 2095 | * | ||
| 2096 | * The host will create a new instance of the current module sharing its | ||
| 2097 | * memory, find an exported entry function--`wasi_thread_start`--, and call the | ||
| 2098 | * entry function with `start_arg` in the new thread. | ||
| 2099 | * | ||
| 2100 | * @see https://github.com/WebAssembly/wasi-threads/#readme | ||
| 2101 | */ | ||
| 2102 | int32_t __wasi_thread_spawn( | ||
| 2103 | /** | ||
| 2104 | * A pointer to an opaque struct to be passed to the module's entry | ||
| 2105 | * function. | ||
| 2106 | */ | ||
| 2107 | void *start_arg | ||
| 2108 | ) __attribute__((__warn_unused_result__)); | ||
| 2109 | #endif | ||
| 2110 | |||
| 2111 | #ifdef __cplusplus | ||
| 2112 | } | ||
| 2113 | #endif | ||
| 2114 | |||
| 2115 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc-busywait.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #ifndef __wasi_libc_busywait_h | ||
| 2 | #define __wasi_libc_busywait_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | /// Enable busywait in futex on current thread. | ||
| 9 | void __wasilibc_enable_futex_busywait_on_current_thread(void); | ||
| 10 | |||
| 11 | #ifdef __cplusplus | ||
| 12 | } | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc-environ.h deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | #ifndef __wasi_libc_environ_h | ||
| 2 | #define __wasi_libc_environ_h | ||
| 3 | |||
| 4 | /// This header file is a WASI-libc-specific interface, and is not needed by | ||
| 5 | /// most programs. Most programs should just use the standard `getenv` and | ||
| 6 | /// related APIs, which take care of all of the details automatically. | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | /// Initialize the global environment variable state. Only needs to be | ||
| 13 | /// called once; most users should call `__wasilibc_ensure_environ` instead. | ||
| 14 | void __wasilibc_initialize_environ(void); | ||
| 15 | |||
| 16 | /// If `__wasilibc_initialize_environ` has not yet been called, call it. | ||
| 17 | void __wasilibc_ensure_environ(void); | ||
| 18 | |||
| 19 | /// De-initialize the global environment variable state, so that subsequent | ||
| 20 | /// calls to `__wasilibc_ensure_environ` call `__wasilibc_initialize_environ`. | ||
| 21 | void __wasilibc_deinitialize_environ(void); | ||
| 22 | |||
| 23 | /// Call `__wasilibc_initialize_environ` only if `environ` and `_environ` are | ||
| 24 | /// referenced in the program. | ||
| 25 | void __wasilibc_maybe_reinitialize_environ_eagerly(void); | ||
| 26 | |||
| 27 | /// Return the value of the `environ` variable. Using `environ` directly | ||
| 28 | /// requires eager initialization of the environment variables. Using this | ||
| 29 | /// function instead of `environ` allows initialization to happen lazily. | ||
| 30 | char **__wasilibc_get_environ(void); | ||
| 31 | |||
| 32 | #ifdef __cplusplus | ||
| 33 | } | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc-find-relpath.h deleted-79| ... | @@ -1,79 +0,0 @@ | ||
| 1 | #ifndef __wasi_libc_find_relpath_h | ||
| 2 | #define __wasi_libc_find_relpath_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | /** | ||
| 9 | * Look up the given `path`, relative to the cwd, in the preopened directory | ||
| 10 | * map. If a suitable entry is found, then the file descriptor for that entry | ||
| 11 | * is returned. Additionally the absolute path of the directory's file | ||
| 12 | * descriptor is returned in `abs_prefix` and the relative portion that needs | ||
| 13 | * to be opened is stored in `*relative_path`. | ||
| 14 | * | ||
| 15 | * The `relative_path` argument must be a pointer to a buffer valid for | ||
| 16 | * `relative_path_len` bytes, and this may be used as storage for the relative | ||
| 17 | * portion of the path being returned through `*relative_path`. | ||
| 18 | * | ||
| 19 | * See documentation on `__wasilibc_find_abspath` for more info about what the | ||
| 20 | * paths look like. | ||
| 21 | * | ||
| 22 | * Returns -1 on failure. Errno is set to either: | ||
| 23 | * | ||
| 24 | * * ENOMEM - failed to allocate memory for internal routines. | ||
| 25 | * * ENOENT - the `path` could not be found relative to any preopened dir. | ||
| 26 | * * ERANGE - the `relative_path` buffer is too small to hold the relative path. | ||
| 27 | */ | ||
| 28 | int __wasilibc_find_relpath(const char *path, | ||
| 29 | const char **__restrict__ abs_prefix, | ||
| 30 | char **relative_path, | ||
| 31 | size_t relative_path_len); | ||
| 32 | |||
| 33 | /** | ||
| 34 | * Look up the given `path`, which is interpreted as absolute, in the preopened | ||
| 35 | * directory map. If a suitable entry is found, then the file descriptor for | ||
| 36 | * that entry is returned. Additionally the relative portion of the path to | ||
| 37 | * where the fd is opened is returned through `relative_path`, the absolute | ||
| 38 | * prefix which was matched is stored to `abs_prefix`, and `relative_path` may | ||
| 39 | * be an interior pointer to the `abspath` string. | ||
| 40 | * | ||
| 41 | * The `abs_prefix` returned string will not contain a leading `/`. Note that | ||
| 42 | * this may be the empty string. Additionally the returned `relative_path` will | ||
| 43 | * not contain a leading `/`. The `relative_path` return will not return an | ||
| 44 | * empty string, it will return `"."` instead if it would otherwise do so. | ||
| 45 | * | ||
| 46 | * Returns -1 on failure. Errno is set to either: | ||
| 47 | * | ||
| 48 | * * ENOMEM - failed to allocate memory for internal routines. | ||
| 49 | * * ENOENT - the `path` could not be found relative to any preopened dir. | ||
| 50 | */ | ||
| 51 | int __wasilibc_find_abspath(const char *abspath, | ||
| 52 | const char **__restrict__ abs_prefix, | ||
| 53 | const char **__restrict__ relative_path); | ||
| 54 | |||
| 55 | /** | ||
| 56 | * Same as `__wasilibc_find_relpath`, except that this function will interpret | ||
| 57 | * `relative` as a malloc'd buffer that will be `realloc`'d to the appropriate | ||
| 58 | * size to contain the relative path. | ||
| 59 | * | ||
| 60 | * Note that this is a weak symbol and if it's not defined you can use | ||
| 61 | * `__wasilibc_find_relpath`. The weak-nature of this symbols means that if it's | ||
| 62 | * not otherwise included in the compilation then `chdir` wasn't used an there's | ||
| 63 | * no need for this symbol. | ||
| 64 | * | ||
| 65 | * See documentation on `__wasilibc_find_relpath` for more information. | ||
| 66 | */ | ||
| 67 | int __wasilibc_find_relpath_alloc( | ||
| 68 | const char *path, | ||
| 69 | const char **abs, | ||
| 70 | char **relative, | ||
| 71 | size_t *relative_len, | ||
| 72 | int can_realloc | ||
| 73 | ) __attribute__((__weak__)); | ||
| 74 | |||
| 75 | #ifdef __cplusplus | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc-nocwd.h deleted-58| ... | @@ -1,58 +0,0 @@ | ||
| 1 | #ifndef __wasi_libc_nocwd_h | ||
| 2 | #define __wasi_libc_nocwd_h | ||
| 3 | |||
| 4 | /* | ||
| 5 | * In order to support AT_FDCWD, we need to wrap the *at functions to handle | ||
| 6 | * it by calling back into the non-at versions which perform libpreopen | ||
| 7 | * queries. These __wasilibc_nocwd_* forms are the underlying calls which | ||
| 8 | * assume AT_FDCWD has already been resolved. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #define __need_size_t | ||
| 12 | #include <stddef.h> | ||
| 13 | #include <__typedef_ssize_t.h> | ||
| 14 | #include <__typedef_mode_t.h> | ||
| 15 | #include <__typedef_DIR.h> | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | extern "C" { | ||
| 19 | #endif | ||
| 20 | |||
| 21 | struct timespec; | ||
| 22 | struct stat; | ||
| 23 | struct dirent; | ||
| 24 | |||
| 25 | int __wasilibc_nocwd___wasilibc_unlinkat(int, const char *) | ||
| 26 | __attribute__((__warn_unused_result__)); | ||
| 27 | int __wasilibc_nocwd___wasilibc_rmdirat(int, const char *) | ||
| 28 | __attribute__((__warn_unused_result__)); | ||
| 29 | int __wasilibc_nocwd_linkat(int, const char *, int, const char *, int) | ||
| 30 | __attribute__((__warn_unused_result__)); | ||
| 31 | int __wasilibc_nocwd_symlinkat(const char *, int, const char *) | ||
| 32 | __attribute__((__warn_unused_result__)); | ||
| 33 | ssize_t __wasilibc_nocwd_readlinkat(int, const char *__restrict, char *__restrict, size_t) | ||
| 34 | __attribute__((__warn_unused_result__)); | ||
| 35 | int __wasilibc_nocwd_faccessat(int, const char *, int, int) | ||
| 36 | __attribute__((__warn_unused_result__)); | ||
| 37 | int __wasilibc_nocwd_renameat(int, const char *, int, const char *) | ||
| 38 | __attribute__((__warn_unused_result__)); | ||
| 39 | int __wasilibc_nocwd_openat_nomode(int, const char *, int) | ||
| 40 | __attribute__((__warn_unused_result__)); | ||
| 41 | int __wasilibc_nocwd_fstatat(int, const char *__restrict, struct stat *__restrict, int) | ||
| 42 | __attribute__((__warn_unused_result__)); | ||
| 43 | int __wasilibc_nocwd_mkdirat_nomode(int, const char *) | ||
| 44 | __attribute__((__warn_unused_result__)); | ||
| 45 | int __wasilibc_nocwd_utimensat(int, const char *, const struct timespec [2], int) | ||
| 46 | __attribute__((__warn_unused_result__)); | ||
| 47 | DIR *__wasilibc_nocwd_opendirat(int, const char *) | ||
| 48 | __attribute__((__warn_unused_result__)); | ||
| 49 | int __wasilibc_nocwd_scandirat(int, const char *, struct dirent ***, | ||
| 50 | int (*)(const struct dirent *), | ||
| 51 | int (*)(const struct dirent **, const struct dirent **)) | ||
| 52 | __attribute__((__warn_unused_result__)); | ||
| 53 | |||
| 54 | #ifdef __cplusplus | ||
| 55 | } | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc.h deleted-79| ... | @@ -1,79 +0,0 @@ | ||
| 1 | #ifndef __wasi_libc_h | ||
| 2 | #define __wasi_libc_h | ||
| 3 | |||
| 4 | #include <__typedef_off_t.h> | ||
| 5 | #include <__struct_timespec.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | struct stat; | ||
| 13 | struct timespec; | ||
| 14 | |||
| 15 | /// Populate libc's preopen tables. This is normally done automatically | ||
| 16 | /// just before it's needed, however if you call `__wasi_fd_renumber` or | ||
| 17 | /// `__wasi_fd_close` directly, and you need the preopens to be accurate | ||
| 18 | /// afterward, you should call this before doing so. | ||
| 19 | void __wasilibc_populate_preopens(void); | ||
| 20 | |||
| 21 | /// Register the given pre-opened file descriptor under the given path. | ||
| 22 | /// | ||
| 23 | /// This function does not take ownership of `prefix` (it makes its own copy). | ||
| 24 | int __wasilibc_register_preopened_fd(int fd, const char *prefix); | ||
| 25 | |||
| 26 | /// Renumber `fd` to `newfd`; similar to `dup2` but does a move rather than a | ||
| 27 | /// copy. | ||
| 28 | int __wasilibc_fd_renumber(int fd, int newfd) | ||
| 29 | __attribute__((__warn_unused_result__)); | ||
| 30 | |||
| 31 | /// Like `unlinkat`, but without depending on `__wasi_path_remove_directory`. | ||
| 32 | int __wasilibc_unlinkat(int fd, const char *path) | ||
| 33 | __attribute__((__warn_unused_result__)); | ||
| 34 | |||
| 35 | /// An `*at` version of rmdir. | ||
| 36 | int __wasilibc_rmdirat(int fd, const char *path) | ||
| 37 | __attribute__((__warn_unused_result__)); | ||
| 38 | |||
| 39 | /// Like `open`, but without the varargs in the signature. | ||
| 40 | int __wasilibc_open_nomode(const char *path, int oflag); | ||
| 41 | |||
| 42 | /// Like `openat`, but without the varargs in the signature. | ||
| 43 | int __wasilibc_openat_nomode(int fd, const char *path, int oflag); | ||
| 44 | |||
| 45 | /// Return the current file offset. Like `lseek(fd, 0, SEEK_CUR)`, but without | ||
| 46 | /// depending on `lseek`. | ||
| 47 | off_t __wasilibc_tell(int fd) | ||
| 48 | __attribute__((__warn_unused_result__)); | ||
| 49 | |||
| 50 | /* Non-`at` forms of various `*at` functions. */ | ||
| 51 | int __wasilibc_access(const char *pathname, int mode, int flags) | ||
| 52 | __attribute__((__warn_unused_result__)); | ||
| 53 | int __wasilibc_stat(const char *__restrict pathname, struct stat *__restrict statbuf, int flags) | ||
| 54 | __attribute__((__warn_unused_result__)); | ||
| 55 | int __wasilibc_utimens(const char *pathname, const struct timespec times[2], int flags) | ||
| 56 | __attribute__((__warn_unused_result__)); | ||
| 57 | int __wasilibc_link(const char *oldpath, const char *newpath, int flags) | ||
| 58 | __attribute__((__warn_unused_result__)); | ||
| 59 | int __wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags) | ||
| 60 | __attribute__((__warn_unused_result__)); | ||
| 61 | int __wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags) | ||
| 62 | __attribute__((__warn_unused_result__)); | ||
| 63 | int __wasilibc_rename_oldat(int olddirfd, const char *oldpath, const char *newpath) | ||
| 64 | __attribute__((__warn_unused_result__)); | ||
| 65 | int __wasilibc_rename_newat(const char *oldpath, int newdirfd, const char *newpath) | ||
| 66 | __attribute__((__warn_unused_result__)); | ||
| 67 | |||
| 68 | /// Enable busywait in futex on current thread. | ||
| 69 | void __wasilibc_enable_futex_busywait_on_current_thread(void); | ||
| 70 | |||
| 71 | /// Fill a buffer with random bytes | ||
| 72 | int __wasilibc_random(void* buffer, size_t len) | ||
| 73 | __attribute__((__warn_unused_result__)); | ||
| 74 | |||
| 75 | #ifdef __cplusplus | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #endif | ||
lib/libc/include/wasm-wasi-musl/wchar.h deleted-214| ... | @@ -1,214 +0,0 @@ | ||
| 1 | #ifndef _WCHAR_H | ||
| 2 | #define _WCHAR_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_FILE | ||
| 11 | #define __NEED___isoc_va_list | ||
| 12 | #define __NEED_size_t | ||
| 13 | #define __NEED_wchar_t | ||
| 14 | #define __NEED_wint_t | ||
| 15 | #define __NEED_mbstate_t | ||
| 16 | |||
| 17 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 18 | #if __STDC_VERSION__ < 201112L | ||
| 19 | #define __NEED_struct__IO_FILE | ||
| 20 | #endif | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 24 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 25 | #define __NEED_locale_t | ||
| 26 | #define __NEED_va_list | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 30 | #define __NEED_wctype_t | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #include <bits/alltypes.h> | ||
| 34 | |||
| 35 | #if L'\0'-1 > 0 | ||
| 36 | #define WCHAR_MAX (0xffffffffu+L'\0') | ||
| 37 | #define WCHAR_MIN (0+L'\0') | ||
| 38 | #else | ||
| 39 | #define WCHAR_MAX (0x7fffffff+L'\0') | ||
| 40 | #define WCHAR_MIN (-1-0x7fffffff+L'\0') | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 44 | #if __cplusplus >= 201103L | ||
| 45 | #define NULL nullptr | ||
| 46 | #elif defined(__cplusplus) | ||
| 47 | #define NULL 0L | ||
| 48 | #else | ||
| 49 | #define NULL ((void*)0) | ||
| 50 | #endif | ||
| 51 | #else | ||
| 52 | #define __need_NULL | ||
| 53 | #include <stddef.h> | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #undef WEOF | ||
| 57 | #define WEOF 0xffffffffU | ||
| 58 | |||
| 59 | wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 60 | wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 61 | |||
| 62 | wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 63 | wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 64 | |||
| 65 | int wcscmp (const wchar_t *, const wchar_t *); | ||
| 66 | int wcsncmp (const wchar_t *, const wchar_t *, size_t); | ||
| 67 | |||
| 68 | int wcscoll(const wchar_t *, const wchar_t *); | ||
| 69 | size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 70 | |||
| 71 | wchar_t *wcschr (const wchar_t *, wchar_t); | ||
| 72 | wchar_t *wcsrchr (const wchar_t *, wchar_t); | ||
| 73 | |||
| 74 | size_t wcscspn (const wchar_t *, const wchar_t *); | ||
| 75 | size_t wcsspn (const wchar_t *, const wchar_t *); | ||
| 76 | wchar_t *wcspbrk (const wchar_t *, const wchar_t *); | ||
| 77 | |||
| 78 | wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); | ||
| 79 | |||
| 80 | size_t wcslen (const wchar_t *); | ||
| 81 | |||
| 82 | wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); | ||
| 83 | wchar_t *wcswcs (const wchar_t *, const wchar_t *); | ||
| 84 | |||
| 85 | wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); | ||
| 86 | int wmemcmp (const wchar_t *, const wchar_t *, size_t); | ||
| 87 | wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 88 | wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); | ||
| 89 | wchar_t *wmemset (wchar_t *, wchar_t, size_t); | ||
| 90 | |||
| 91 | wint_t btowc (int); | ||
| 92 | int wctob (wint_t); | ||
| 93 | |||
| 94 | int mbsinit (const mbstate_t *); | ||
| 95 | size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 96 | size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); | ||
| 97 | |||
| 98 | size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 99 | |||
| 100 | size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); | ||
| 101 | size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); | ||
| 102 | |||
| 103 | float wcstof (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 104 | double wcstod (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 105 | long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 106 | |||
| 107 | long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 108 | unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 109 | |||
| 110 | long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 111 | unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | int fwide (FILE *, int); | ||
| 116 | |||
| 117 | |||
| 118 | int wprintf (const wchar_t *__restrict, ...); | ||
| 119 | int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 120 | int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); | ||
| 121 | |||
| 122 | int vwprintf (const wchar_t *__restrict, __isoc_va_list); | ||
| 123 | int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 124 | int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); | ||
| 125 | |||
| 126 | int wscanf (const wchar_t *__restrict, ...); | ||
| 127 | int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 128 | int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); | ||
| 129 | |||
| 130 | int vwscanf (const wchar_t *__restrict, __isoc_va_list); | ||
| 131 | int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 132 | int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 133 | |||
| 134 | wint_t fgetwc (FILE *); | ||
| 135 | wint_t getwc (FILE *); | ||
| 136 | wint_t getwchar (void); | ||
| 137 | |||
| 138 | wint_t fputwc (wchar_t, FILE *); | ||
| 139 | wint_t putwc (wchar_t, FILE *); | ||
| 140 | wint_t putwchar (wchar_t); | ||
| 141 | |||
| 142 | wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); | ||
| 143 | int fputws (const wchar_t *__restrict, FILE *__restrict); | ||
| 144 | |||
| 145 | wint_t ungetwc (wint_t, FILE *); | ||
| 146 | |||
| 147 | struct tm; | ||
| 148 | size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); | ||
| 149 | |||
| 150 | #undef iswdigit | ||
| 151 | |||
| 152 | #if defined(_GNU_SOURCE) | ||
| 153 | wint_t fgetwc_unlocked (FILE *); | ||
| 154 | wint_t getwc_unlocked (FILE *); | ||
| 155 | wint_t getwchar_unlocked (void); | ||
| 156 | wint_t fputwc_unlocked (wchar_t, FILE *); | ||
| 157 | wint_t putwc_unlocked (wchar_t, FILE *); | ||
| 158 | wint_t putwchar_unlocked (wchar_t); | ||
| 159 | wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); | ||
| 160 | int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); | ||
| 161 | #endif | ||
| 162 | |||
| 163 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 164 | size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); | ||
| 165 | #endif | ||
| 166 | |||
| 167 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 168 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 169 | FILE *open_wmemstream(wchar_t **, size_t *); | ||
| 170 | size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 171 | size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 172 | wchar_t *wcsdup(const wchar_t *); | ||
| 173 | size_t wcsnlen (const wchar_t *, size_t); | ||
| 174 | wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 175 | wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 176 | int wcscasecmp(const wchar_t *, const wchar_t *); | ||
| 177 | int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 178 | int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); | ||
| 179 | int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); | ||
| 180 | int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 181 | size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 185 | int wcwidth (wchar_t); | ||
| 186 | int wcswidth (const wchar_t *, size_t); | ||
| 187 | int iswalnum(wint_t); | ||
| 188 | int iswalpha(wint_t); | ||
| 189 | int iswblank(wint_t); | ||
| 190 | int iswcntrl(wint_t); | ||
| 191 | int iswdigit(wint_t); | ||
| 192 | int iswgraph(wint_t); | ||
| 193 | int iswlower(wint_t); | ||
| 194 | int iswprint(wint_t); | ||
| 195 | int iswpunct(wint_t); | ||
| 196 | int iswspace(wint_t); | ||
| 197 | int iswupper(wint_t); | ||
| 198 | int iswxdigit(wint_t); | ||
| 199 | int iswctype(wint_t, wctype_t); | ||
| 200 | wint_t towlower(wint_t); | ||
| 201 | wint_t towupper(wint_t); | ||
| 202 | wctype_t wctype(const char *); | ||
| 203 | |||
| 204 | #ifndef __cplusplus | ||
| 205 | #undef iswdigit | ||
| 206 | #define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 207 | #endif | ||
| 208 | #endif | ||
| 209 | |||
| 210 | #ifdef __cplusplus | ||
| 211 | } | ||
| 212 | #endif | ||
| 213 | |||
| 214 | #endif | ||
lib/libc/wasi/LICENSE deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | wasi-libc as a whole is multi-licensed under the | ||
| 2 | Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, and | ||
| 3 | the MIT License. See the LICENSE-APACHE-LLVM, LICENSE-APACHE and LICENSE-MIT | ||
| 4 | files, respectively, for details. | ||
| 5 | |||
| 6 | Portions of this software are derived from third-party works covered by | ||
| 7 | their own licenses: | ||
| 8 | |||
| 9 | dlmalloc/ - CC0; see the notice in malloc.c for details | ||
| 10 | emmalloc/ - MIT; see the notice in emmalloc.c for details | ||
| 11 | libc-bottom-half/cloudlibc/ - BSD-2-Clause; see the LICENSE file for details | ||
| 12 | libc-top-half/musl/ - MIT; see the COPYRIGHT file for details | ||
| 13 | |||
| 14 | wasi-libc's changes to these files are multi-licensed under the | ||
| 15 | Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, | ||
| 16 | the MIT License, and the original licenses of the third-party works. | ||
lib/libc/wasi/LICENSE-APACHE deleted-201| ... | @@ -1,201 +0,0 @@ | ||
| 1 | Apache License | ||
| 2 | Version 2.0, January 2004 | ||
| 3 | http://www.apache.org/licenses/ | ||
| 4 | |||
| 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||
| 6 | |||
| 7 | 1. Definitions. | ||
| 8 | |||
| 9 | "License" shall mean the terms and conditions for use, reproduction, | ||
| 10 | and distribution as defined by Sections 1 through 9 of this document. | ||
| 11 | |||
| 12 | "Licensor" shall mean the copyright owner or entity authorized by | ||
| 13 | the copyright owner that is granting the License. | ||
| 14 | |||
| 15 | "Legal Entity" shall mean the union of the acting entity and all | ||
| 16 | other entities that control, are controlled by, or are under common | ||
| 17 | control with that entity. For the purposes of this definition, | ||
| 18 | "control" means (i) the power, direct or indirect, to cause the | ||
| 19 | direction or management of such entity, whether by contract or | ||
| 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||
| 21 | outstanding shares, or (iii) beneficial ownership of such entity. | ||
| 22 | |||
| 23 | "You" (or "Your") shall mean an individual or Legal Entity | ||
| 24 | exercising permissions granted by this License. | ||
| 25 | |||
| 26 | "Source" form shall mean the preferred form for making modifications, | ||
| 27 | including but not limited to software source code, documentation | ||
| 28 | source, and configuration files. | ||
| 29 | |||
| 30 | "Object" form shall mean any form resulting from mechanical | ||
| 31 | transformation or translation of a Source form, including but | ||
| 32 | not limited to compiled object code, generated documentation, | ||
| 33 | and conversions to other media types. | ||
| 34 | |||
| 35 | "Work" shall mean the work of authorship, whether in Source or | ||
| 36 | Object form, made available under the License, as indicated by a | ||
| 37 | copyright notice that is included in or attached to the work | ||
| 38 | (an example is provided in the Appendix below). | ||
| 39 | |||
| 40 | "Derivative Works" shall mean any work, whether in Source or Object | ||
| 41 | form, that is based on (or derived from) the Work and for which the | ||
| 42 | editorial revisions, annotations, elaborations, or other modifications | ||
| 43 | represent, as a whole, an original work of authorship. For the purposes | ||
| 44 | of this License, Derivative Works shall not include works that remain | ||
| 45 | separable from, or merely link (or bind by name) to the interfaces of, | ||
| 46 | the Work and Derivative Works thereof. | ||
| 47 | |||
| 48 | "Contribution" shall mean any work of authorship, including | ||
| 49 | the original version of the Work and any modifications or additions | ||
| 50 | to that Work or Derivative Works thereof, that is intentionally | ||
| 51 | submitted to Licensor for inclusion in the Work by the copyright owner | ||
| 52 | or by an individual or Legal Entity authorized to submit on behalf of | ||
| 53 | the copyright owner. For the purposes of this definition, "submitted" | ||
| 54 | means any form of electronic, verbal, or written communication sent | ||
| 55 | to the Licensor or its representatives, including but not limited to | ||
| 56 | communication on electronic mailing lists, source code control systems, | ||
| 57 | and issue tracking systems that are managed by, or on behalf of, the | ||
| 58 | Licensor for the purpose of discussing and improving the Work, but | ||
| 59 | excluding communication that is conspicuously marked or otherwise | ||
| 60 | designated in writing by the copyright owner as "Not a Contribution." | ||
| 61 | |||
| 62 | "Contributor" shall mean Licensor and any individual or Legal Entity | ||
| 63 | on behalf of whom a Contribution has been received by Licensor and | ||
| 64 | subsequently incorporated within the Work. | ||
| 65 | |||
| 66 | 2. Grant of Copyright License. Subject to the terms and conditions of | ||
| 67 | this License, each Contributor hereby grants to You a perpetual, | ||
| 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| 69 | copyright license to reproduce, prepare Derivative Works of, | ||
| 70 | publicly display, publicly perform, sublicense, and distribute the | ||
| 71 | Work and such Derivative Works in Source or Object form. | ||
| 72 | |||
| 73 | 3. Grant of Patent License. Subject to the terms and conditions of | ||
| 74 | this License, each Contributor hereby grants to You a perpetual, | ||
| 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| 76 | (except as stated in this section) patent license to make, have made, | ||
| 77 | use, offer to sell, sell, import, and otherwise transfer the Work, | ||
| 78 | where such license applies only to those patent claims licensable | ||
| 79 | by such Contributor that are necessarily infringed by their | ||
| 80 | Contribution(s) alone or by combination of their Contribution(s) | ||
| 81 | with the Work to which such Contribution(s) was submitted. If You | ||
| 82 | institute patent litigation against any entity (including a | ||
| 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work | ||
| 84 | or a Contribution incorporated within the Work constitutes direct | ||
| 85 | or contributory patent infringement, then any patent licenses | ||
| 86 | granted to You under this License for that Work shall terminate | ||
| 87 | as of the date such litigation is filed. | ||
| 88 | |||
| 89 | 4. Redistribution. You may reproduce and distribute copies of the | ||
| 90 | Work or Derivative Works thereof in any medium, with or without | ||
| 91 | modifications, and in Source or Object form, provided that You | ||
| 92 | meet the following conditions: | ||
| 93 | |||
| 94 | (a) You must give any other recipients of the Work or | ||
| 95 | Derivative Works a copy of this License; and | ||
| 96 | |||
| 97 | (b) You must cause any modified files to carry prominent notices | ||
| 98 | stating that You changed the files; and | ||
| 99 | |||
| 100 | (c) You must retain, in the Source form of any Derivative Works | ||
| 101 | that You distribute, all copyright, patent, trademark, and | ||
| 102 | attribution notices from the Source form of the Work, | ||
| 103 | excluding those notices that do not pertain to any part of | ||
| 104 | the Derivative Works; and | ||
| 105 | |||
| 106 | (d) If the Work includes a "NOTICE" text file as part of its | ||
| 107 | distribution, then any Derivative Works that You distribute must | ||
| 108 | include a readable copy of the attribution notices contained | ||
| 109 | within such NOTICE file, excluding those notices that do not | ||
| 110 | pertain to any part of the Derivative Works, in at least one | ||
| 111 | of the following places: within a NOTICE text file distributed | ||
| 112 | as part of the Derivative Works; within the Source form or | ||
| 113 | documentation, if provided along with the Derivative Works; or, | ||
| 114 | within a display generated by the Derivative Works, if and | ||
| 115 | wherever such third-party notices normally appear. The contents | ||
| 116 | of the NOTICE file are for informational purposes only and | ||
| 117 | do not modify the License. You may add Your own attribution | ||
| 118 | notices within Derivative Works that You distribute, alongside | ||
| 119 | or as an addendum to the NOTICE text from the Work, provided | ||
| 120 | that such additional attribution notices cannot be construed | ||
| 121 | as modifying the License. | ||
| 122 | |||
| 123 | You may add Your own copyright statement to Your modifications and | ||
| 124 | may provide additional or different license terms and conditions | ||
| 125 | for use, reproduction, or distribution of Your modifications, or | ||
| 126 | for any such Derivative Works as a whole, provided Your use, | ||
| 127 | reproduction, and distribution of the Work otherwise complies with | ||
| 128 | the conditions stated in this License. | ||
| 129 | |||
| 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, | ||
| 131 | any Contribution intentionally submitted for inclusion in the Work | ||
| 132 | by You to the Licensor shall be under the terms and conditions of | ||
| 133 | this License, without any additional terms or conditions. | ||
| 134 | Notwithstanding the above, nothing herein shall supersede or modify | ||
| 135 | the terms of any separate license agreement you may have executed | ||
| 136 | with Licensor regarding such Contributions. | ||
| 137 | |||
| 138 | 6. Trademarks. This License does not grant permission to use the trade | ||
| 139 | names, trademarks, service marks, or product names of the Licensor, | ||
| 140 | except as required for reasonable and customary use in describing the | ||
| 141 | origin of the Work and reproducing the content of the NOTICE file. | ||
| 142 | |||
| 143 | 7. Disclaimer of Warranty. Unless required by applicable law or | ||
| 144 | agreed to in writing, Licensor provides the Work (and each | ||
| 145 | Contributor provides its Contributions) on an "AS IS" BASIS, | ||
| 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| 147 | implied, including, without limitation, any warranties or conditions | ||
| 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||
| 149 | PARTICULAR PURPOSE. You are solely responsible for determining the | ||
| 150 | appropriateness of using or redistributing the Work and assume any | ||
| 151 | risks associated with Your exercise of permissions under this License. | ||
| 152 | |||
| 153 | 8. Limitation of Liability. In no event and under no legal theory, | ||
| 154 | whether in tort (including negligence), contract, or otherwise, | ||
| 155 | unless required by applicable law (such as deliberate and grossly | ||
| 156 | negligent acts) or agreed to in writing, shall any Contributor be | ||
| 157 | liable to You for damages, including any direct, indirect, special, | ||
| 158 | incidental, or consequential damages of any character arising as a | ||
| 159 | result of this License or out of the use or inability to use the | ||
| 160 | Work (including but not limited to damages for loss of goodwill, | ||
| 161 | work stoppage, computer failure or malfunction, or any and all | ||
| 162 | other commercial damages or losses), even if such Contributor | ||
| 163 | has been advised of the possibility of such damages. | ||
| 164 | |||
| 165 | 9. Accepting Warranty or Additional Liability. While redistributing | ||
| 166 | the Work or Derivative Works thereof, You may choose to offer, | ||
| 167 | and charge a fee for, acceptance of support, warranty, indemnity, | ||
| 168 | or other liability obligations and/or rights consistent with this | ||
| 169 | License. However, in accepting such obligations, You may act only | ||
| 170 | on Your own behalf and on Your sole responsibility, not on behalf | ||
| 171 | of any other Contributor, and only if You agree to indemnify, | ||
| 172 | defend, and hold each Contributor harmless for any liability | ||
| 173 | incurred by, or claims asserted against, such Contributor by reason | ||
| 174 | of your accepting any such warranty or additional liability. | ||
| 175 | |||
| 176 | END OF TERMS AND CONDITIONS | ||
| 177 | |||
| 178 | APPENDIX: How to apply the Apache License to your work. | ||
| 179 | |||
| 180 | To apply the Apache License to your work, attach the following | ||
| 181 | boilerplate notice, with the fields enclosed by brackets "[]" | ||
| 182 | replaced with your own identifying information. (Don't include | ||
| 183 | the brackets!) The text should be enclosed in the appropriate | ||
| 184 | comment syntax for the file format. We also recommend that a | ||
| 185 | file or class name and description of purpose be included on the | ||
| 186 | same "printed page" as the copyright notice for easier | ||
| 187 | identification within third-party archives. | ||
| 188 | |||
| 189 | Copyright [yyyy] [name of copyright owner] | ||
| 190 | |||
| 191 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 192 | you may not use this file except in compliance with the License. | ||
| 193 | You may obtain a copy of the License at | ||
| 194 | |||
| 195 | 	http://www.apache.org/licenses/LICENSE-2.0 | ||
| 196 | |||
| 197 | Unless required by applicable law or agreed to in writing, software | ||
| 198 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 200 | See the License for the specific language governing permissions and | ||
| 201 | limitations under the License. | ||
lib/libc/wasi/LICENSE-APACHE-LLVM deleted-220| ... | @@ -1,220 +0,0 @@ | ||
| 1 | |||
| 2 | Apache License | ||
| 3 | Version 2.0, January 2004 | ||
| 4 | http://www.apache.org/licenses/ | ||
| 5 | |||
| 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION | ||
| 7 | |||
| 8 | 1. Definitions. | ||
| 9 | |||
| 10 | "License" shall mean the terms and conditions for use, reproduction, | ||
| 11 | and distribution as defined by Sections 1 through 9 of this document. | ||
| 12 | |||
| 13 | "Licensor" shall mean the copyright owner or entity authorized by | ||
| 14 | the copyright owner that is granting the License. | ||
| 15 | |||
| 16 | "Legal Entity" shall mean the union of the acting entity and all | ||
| 17 | other entities that control, are controlled by, or are under common | ||
| 18 | control with that entity. For the purposes of this definition, | ||
| 19 | "control" means (i) the power, direct or indirect, to cause the | ||
| 20 | direction or management of such entity, whether by contract or | ||
| 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the | ||
| 22 | outstanding shares, or (iii) beneficial ownership of such entity. | ||
| 23 | |||
| 24 | "You" (or "Your") shall mean an individual or Legal Entity | ||
| 25 | exercising permissions granted by this License. | ||
| 26 | |||
| 27 | "Source" form shall mean the preferred form for making modifications, | ||
| 28 | including but not limited to software source code, documentation | ||
| 29 | source, and configuration files. | ||
| 30 | |||
| 31 | "Object" form shall mean any form resulting from mechanical | ||
| 32 | transformation or translation of a Source form, including but | ||
| 33 | not limited to compiled object code, generated documentation, | ||
| 34 | and conversions to other media types. | ||
| 35 | |||
| 36 | "Work" shall mean the work of authorship, whether in Source or | ||
| 37 | Object form, made available under the License, as indicated by a | ||
| 38 | copyright notice that is included in or attached to the work | ||
| 39 | (an example is provided in the Appendix below). | ||
| 40 | |||
| 41 | "Derivative Works" shall mean any work, whether in Source or Object | ||
| 42 | form, that is based on (or derived from) the Work and for which the | ||
| 43 | editorial revisions, annotations, elaborations, or other modifications | ||
| 44 | represent, as a whole, an original work of authorship. For the purposes | ||
| 45 | of this License, Derivative Works shall not include works that remain | ||
| 46 | separable from, or merely link (or bind by name) to the interfaces of, | ||
| 47 | the Work and Derivative Works thereof. | ||
| 48 | |||
| 49 | "Contribution" shall mean any work of authorship, including | ||
| 50 | the original version of the Work and any modifications or additions | ||
| 51 | to that Work or Derivative Works thereof, that is intentionally | ||
| 52 | submitted to Licensor for inclusion in the Work by the copyright owner | ||
| 53 | or by an individual or Legal Entity authorized to submit on behalf of | ||
| 54 | the copyright owner. For the purposes of this definition, "submitted" | ||
| 55 | means any form of electronic, verbal, or written communication sent | ||
| 56 | to the Licensor or its representatives, including but not limited to | ||
| 57 | communication on electronic mailing lists, source code control systems, | ||
| 58 | and issue tracking systems that are managed by, or on behalf of, the | ||
| 59 | Licensor for the purpose of discussing and improving the Work, but | ||
| 60 | excluding communication that is conspicuously marked or otherwise | ||
| 61 | designated in writing by the copyright owner as "Not a Contribution." | ||
| 62 | |||
| 63 | "Contributor" shall mean Licensor and any individual or Legal Entity | ||
| 64 | on behalf of whom a Contribution has been received by Licensor and | ||
| 65 | subsequently incorporated within the Work. | ||
| 66 | |||
| 67 | 2. Grant of Copyright License. Subject to the terms and conditions of | ||
| 68 | this License, each Contributor hereby grants to You a perpetual, | ||
| 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| 70 | copyright license to reproduce, prepare Derivative Works of, | ||
| 71 | publicly display, publicly perform, sublicense, and distribute the | ||
| 72 | Work and such Derivative Works in Source or Object form. | ||
| 73 | |||
| 74 | 3. Grant of Patent License. Subject to the terms and conditions of | ||
| 75 | this License, each Contributor hereby grants to You a perpetual, | ||
| 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable | ||
| 77 | (except as stated in this section) patent license to make, have made, | ||
| 78 | use, offer to sell, sell, import, and otherwise transfer the Work, | ||
| 79 | where such license applies only to those patent claims licensable | ||
| 80 | by such Contributor that are necessarily infringed by their | ||
| 81 | Contribution(s) alone or by combination of their Contribution(s) | ||
| 82 | with the Work to which such Contribution(s) was submitted. If You | ||
| 83 | institute patent litigation against any entity (including a | ||
| 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work | ||
| 85 | or a Contribution incorporated within the Work constitutes direct | ||
| 86 | or contributory patent infringement, then any patent licenses | ||
| 87 | granted to You under this License for that Work shall terminate | ||
| 88 | as of the date such litigation is filed. | ||
| 89 | |||
| 90 | 4. Redistribution. You may reproduce and distribute copies of the | ||
| 91 | Work or Derivative Works thereof in any medium, with or without | ||
| 92 | modifications, and in Source or Object form, provided that You | ||
| 93 | meet the following conditions: | ||
| 94 | |||
| 95 | (a) You must give any other recipients of the Work or | ||
| 96 | Derivative Works a copy of this License; and | ||
| 97 | |||
| 98 | (b) You must cause any modified files to carry prominent notices | ||
| 99 | stating that You changed the files; and | ||
| 100 | |||
| 101 | (c) You must retain, in the Source form of any Derivative Works | ||
| 102 | that You distribute, all copyright, patent, trademark, and | ||
| 103 | attribution notices from the Source form of the Work, | ||
| 104 | excluding those notices that do not pertain to any part of | ||
| 105 | the Derivative Works; and | ||
| 106 | |||
| 107 | (d) If the Work includes a "NOTICE" text file as part of its | ||
| 108 | distribution, then any Derivative Works that You distribute must | ||
| 109 | include a readable copy of the attribution notices contained | ||
| 110 | within such NOTICE file, excluding those notices that do not | ||
| 111 | pertain to any part of the Derivative Works, in at least one | ||
| 112 | of the following places: within a NOTICE text file distributed | ||
| 113 | as part of the Derivative Works; within the Source form or | ||
| 114 | documentation, if provided along with the Derivative Works; or, | ||
| 115 | within a display generated by the Derivative Works, if and | ||
| 116 | wherever such third-party notices normally appear. The contents | ||
| 117 | of the NOTICE file are for informational purposes only and | ||
| 118 | do not modify the License. You may add Your own attribution | ||
| 119 | notices within Derivative Works that You distribute, alongside | ||
| 120 | or as an addendum to the NOTICE text from the Work, provided | ||
| 121 | that such additional attribution notices cannot be construed | ||
| 122 | as modifying the License. | ||
| 123 | |||
| 124 | You may add Your own copyright statement to Your modifications and | ||
| 125 | may provide additional or different license terms and conditions | ||
| 126 | for use, reproduction, or distribution of Your modifications, or | ||
| 127 | for any such Derivative Works as a whole, provided Your use, | ||
| 128 | reproduction, and distribution of the Work otherwise complies with | ||
| 129 | the conditions stated in this License. | ||
| 130 | |||
| 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, | ||
| 132 | any Contribution intentionally submitted for inclusion in the Work | ||
| 133 | by You to the Licensor shall be under the terms and conditions of | ||
| 134 | this License, without any additional terms or conditions. | ||
| 135 | Notwithstanding the above, nothing herein shall supersede or modify | ||
| 136 | the terms of any separate license agreement you may have executed | ||
| 137 | with Licensor regarding such Contributions. | ||
| 138 | |||
| 139 | 6. Trademarks. This License does not grant permission to use the trade | ||
| 140 | names, trademarks, service marks, or product names of the Licensor, | ||
| 141 | except as required for reasonable and customary use in describing the | ||
| 142 | origin of the Work and reproducing the content of the NOTICE file. | ||
| 143 | |||
| 144 | 7. Disclaimer of Warranty. Unless required by applicable law or | ||
| 145 | agreed to in writing, Licensor provides the Work (and each | ||
| 146 | Contributor provides its Contributions) on an "AS IS" BASIS, | ||
| 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or | ||
| 148 | implied, including, without limitation, any warranties or conditions | ||
| 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A | ||
| 150 | PARTICULAR PURPOSE. You are solely responsible for determining the | ||
| 151 | appropriateness of using or redistributing the Work and assume any | ||
| 152 | risks associated with Your exercise of permissions under this License. | ||
| 153 | |||
| 154 | 8. Limitation of Liability. In no event and under no legal theory, | ||
| 155 | whether in tort (including negligence), contract, or otherwise, | ||
| 156 | unless required by applicable law (such as deliberate and grossly | ||
| 157 | negligent acts) or agreed to in writing, shall any Contributor be | ||
| 158 | liable to You for damages, including any direct, indirect, special, | ||
| 159 | incidental, or consequential damages of any character arising as a | ||
| 160 | result of this License or out of the use or inability to use the | ||
| 161 | Work (including but not limited to damages for loss of goodwill, | ||
| 162 | work stoppage, computer failure or malfunction, or any and all | ||
| 163 | other commercial damages or losses), even if such Contributor | ||
| 164 | has been advised of the possibility of such damages. | ||
| 165 | |||
| 166 | 9. Accepting Warranty or Additional Liability. While redistributing | ||
| 167 | the Work or Derivative Works thereof, You may choose to offer, | ||
| 168 | and charge a fee for, acceptance of support, warranty, indemnity, | ||
| 169 | or other liability obligations and/or rights consistent with this | ||
| 170 | License. However, in accepting such obligations, You may act only | ||
| 171 | on Your own behalf and on Your sole responsibility, not on behalf | ||
| 172 | of any other Contributor, and only if You agree to indemnify, | ||
| 173 | defend, and hold each Contributor harmless for any liability | ||
| 174 | incurred by, or claims asserted against, such Contributor by reason | ||
| 175 | of your accepting any such warranty or additional liability. | ||
| 176 | |||
| 177 | END OF TERMS AND CONDITIONS | ||
| 178 | |||
| 179 | APPENDIX: How to apply the Apache License to your work. | ||
| 180 | |||
| 181 | To apply the Apache License to your work, attach the following | ||
| 182 | boilerplate notice, with the fields enclosed by brackets "[]" | ||
| 183 | replaced with your own identifying information. (Don't include | ||
| 184 | the brackets!) The text should be enclosed in the appropriate | ||
| 185 | comment syntax for the file format. We also recommend that a | ||
| 186 | file or class name and description of purpose be included on the | ||
| 187 | same "printed page" as the copyright notice for easier | ||
| 188 | identification within third-party archives. | ||
| 189 | |||
| 190 | Copyright [yyyy] [name of copyright owner] | ||
| 191 | |||
| 192 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 193 | you may not use this file except in compliance with the License. | ||
| 194 | You may obtain a copy of the License at | ||
| 195 | |||
| 196 | http://www.apache.org/licenses/LICENSE-2.0 | ||
| 197 | |||
| 198 | Unless required by applicable law or agreed to in writing, software | ||
| 199 | distributed under the License is distributed on an "AS IS" BASIS, | ||
| 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 201 | See the License for the specific language governing permissions and | ||
| 202 | limitations under the License. | ||
| 203 | |||
| 204 | |||
| 205 | --- LLVM Exceptions to the Apache 2.0 License ---- | ||
| 206 | |||
| 207 | As an exception, if, as a result of your compiling your source code, portions | ||
| 208 | of this Software are embedded into an Object form of such source code, you | ||
| 209 | may redistribute such embedded portions in such Object form without complying | ||
| 210 | with the conditions of Sections 4(a), 4(b) and 4(d) of the License. | ||
| 211 | |||
| 212 | In addition, if you combine or link compiled forms of this Software with | ||
| 213 | software that is licensed under the GPLv2 ("Combined Software") and if a | ||
| 214 | court of competent jurisdiction determines that the patent provision (Section | ||
| 215 | 3), the indemnity provision (Section 9) or other Section of the License | ||
| 216 | conflicts with the conditions of the GPLv2, you may retroactively and | ||
| 217 | prospectively choose to deem waived or otherwise exclude such Section(s) of | ||
| 218 | the License, but only in their entirety and only with respect to the Combined | ||
| 219 | Software. | ||
| 220 | |||
lib/libc/wasi/LICENSE-MIT deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | Permission is hereby granted, free of charge, to any | ||
| 2 | person obtaining a copy of this software and associated | ||
| 3 | documentation files (the "Software"), to deal in the | ||
| 4 | Software without restriction, including without | ||
| 5 | limitation the rights to use, copy, modify, merge, | ||
| 6 | publish, distribute, sublicense, and/or sell copies of | ||
| 7 | the Software, and to permit persons to whom the Software | ||
| 8 | is furnished to do so, subject to the following | ||
| 9 | conditions: | ||
| 10 | |||
| 11 | The above copyright notice and this permission notice | ||
| 12 | shall be included in all copies or substantial portions | ||
| 13 | of the Software. | ||
| 14 | |||
| 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF | ||
| 16 | ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED | ||
| 17 | TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A | ||
| 18 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT | ||
| 19 | SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
| 21 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR | ||
| 22 | IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER | ||
| 23 | DEALINGS IN THE SOFTWARE. | ||
lib/libc/wasi/fts/config.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #define HAVE_DECL_MAX 1 | ||
| 2 | |||
| 3 | #define HAVE_DECL_UINTMAX_MAX 0 | ||
| 4 | |||
| 5 | #define HAVE_DIRFD 1 | ||
| 6 | |||
| 7 | #define HAVE_FCHDIR 0 | ||
lib/libc/wasi/fts/musl-fts/COPYING deleted-26| ... | @@ -1,26 +0,0 @@ | ||
| 1 | Copyright (c) 1989, 1993 | ||
| 2 | The Regents of the University of California. All rights reserved. | ||
| 3 | |||
| 4 | Redistribution and use in source and binary forms, with or without | ||
| 5 | modification, are permitted provided that the following conditions | ||
| 6 | are met: | ||
| 7 | 1. Redistributions of source code must retain the above copyright | ||
| 8 | notice, this list of conditions and the following disclaimer. | ||
| 9 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 10 | notice, this list of conditions and the following disclaimer in the | ||
| 11 | documentation and/or other materials provided with the distribution. | ||
| 12 | 3. Neither the name of the University nor the names of its contributors | ||
| 13 | may be used to endorse or promote products derived from this software | ||
| 14 | without specific prior written permission. | ||
| 15 | |||
| 16 | THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 18 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 19 | ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 20 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 21 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 22 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 23 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 24 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 25 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 26 | SUCH DAMAGE. | ||
lib/libc/wasi/fts/musl-fts/fts.c deleted-1279| ... | @@ -1,1279 +0,0 @@ | ||
| 1 | /*	$NetBSD: fts.c,v 1.48 2015/01/29 15:55:21 manu Exp $	*/ | ||
| 2 | |||
| 3 | /*- | ||
| 4 | * Copyright (c) 1990, 1993, 1994 | ||
| 5 | *	The Regents of the University of California. All rights reserved. | ||
| 6 | * | ||
| 7 | * Redistribution and use in source and binary forms, with or without | ||
| 8 | * modification, are permitted provided that the following conditions | ||
| 9 | * are met: | ||
| 10 | * 1. Redistributions of source code must retain the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer. | ||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 13 | * notice, this list of conditions and the following disclaimer in the | ||
| 14 | * documentation and/or other materials provided with the distribution. | ||
| 15 | * 3. Neither the name of the University nor the names of its contributors | ||
| 16 | * may be used to endorse or promote products derived from this software | ||
| 17 | * without specific prior written permission. | ||
| 18 | * | ||
| 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
| 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
| 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 29 | * SUCH DAMAGE. | ||
| 30 | */ | ||
| 31 | |||
| 32 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 33 | #if 0 | ||
| 34 | static char sccsid[] = "@(#)fts.c	8.6 (Berkeley) 8/14/94"; | ||
| 35 | #else | ||
| 36 | __RCSID("$NetBSD: fts.c,v 1.48 2015/01/29 15:55:21 manu Exp $"); | ||
| 37 | #endif | ||
| 38 | #endif /* LIBC_SCCS and not lint */ | ||
| 39 | |||
| 40 | #include "config.h" | ||
| 41 | |||
| 42 | #include <sys/param.h> | ||
| 43 | #include <sys/stat.h> | ||
| 44 | |||
| 45 | #include <assert.h> | ||
| 46 | #define _DIAGASSERT(e) | ||
| 47 | #include <dirent.h> | ||
| 48 | #include <errno.h> | ||
| 49 | #include <fcntl.h> | ||
| 50 | #include <fts.h> | ||
| 51 | #include <stdlib.h> | ||
| 52 | #include <string.h> | ||
| 53 | #include <unistd.h> | ||
| 54 | |||
| 55 | #if !defined(HAVE_DECL_MAX) || (HAVE_DECL_MAX==0) | ||
| 56 | #define MAX(a,b) ((a)>(b)?(a):(b)) | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #if !defined(UINT_MAX) && (HAVE_DECL_UINTMAX_MAX==1) | ||
| 60 | #define UINT_MAX UINTMAX_MAX | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #if !defined(HAVE_DIRFD) | ||
| 64 | #if defined(HAVE_DIR_DD_FD) | ||
| 65 | #define dirfd(dirp) ((dirp)->dd_fd) | ||
| 66 | #endif | ||
| 67 | #if defined(HAVE_DIR_D_FD) | ||
| 68 | #define dirfd(dirp) ((dirp)->d_fd) | ||
| 69 | #endif | ||
| 70 | #endif | ||
| 71 | |||
| 72 | static FTSENT	*fts_alloc(FTS *, const char *, size_t); | ||
| 73 | static FTSENT	*fts_build(FTS *, int); | ||
| 74 | static void	 fts_free(FTSENT *); | ||
| 75 | static void	 fts_lfree(FTSENT *); | ||
| 76 | static void	 fts_load(FTS *, FTSENT *); | ||
| 77 | static size_t	 fts_maxarglen(char * const *); | ||
| 78 | static size_t	 fts_pow2(size_t); | ||
| 79 | static int	 fts_palloc(FTS *, size_t); | ||
| 80 | static void	 fts_padjust(FTS *, FTSENT *); | ||
| 81 | static FTSENT	*fts_sort(FTS *, FTSENT *, size_t); | ||
| 82 | static unsigned short fts_stat(FTS *, FTSENT *, int); | ||
| 83 | static int	 fts_safe_changedir(const FTS *, const FTSENT *, int, | ||
| 84 | const char *); | ||
| 85 | |||
| 86 | #if defined(ALIGNBYTES) && defined(ALIGN) | ||
| 87 | #define	FTS_ALLOC_ALIGNED	1 | ||
| 88 | #else | ||
| 89 | #undef	FTS_ALLOC_ALIGNED | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #ifndef ftsent_namelen_truncate | ||
| 93 | #define ftsent_namelen_truncate(a)	\ | ||
| 94 | ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) | ||
| 95 | #endif | ||
| 96 | #ifndef ftsent_pathlen_truncate | ||
| 97 | #define ftsent_pathlen_truncate(a) \ | ||
| 98 | ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) | ||
| 99 | #endif | ||
| 100 | #ifndef fts_pathlen_truncate | ||
| 101 | #define fts_pathlen_truncate(a)	\ | ||
| 102 | ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) | ||
| 103 | #endif | ||
| 104 | #ifndef fts_nitems_truncate | ||
| 105 | #define fts_nitems_truncate(a) \ | ||
| 106 | ((a) > UINT_MAX ? UINT_MAX : (unsigned int)(a)) | ||
| 107 | #endif | ||
| 108 | |||
| 109 | #define	ISDOT(a)	(a[0] == '.' && (!a[1] || (a[1] == '.' && !a[2]))) | ||
| 110 | |||
| 111 | #define	CLR(opt)	(sp->fts_options &= ~(opt)) | ||
| 112 | #define	ISSET(opt)	(sp->fts_options & (opt)) | ||
| 113 | #define	SET(opt)	(sp->fts_options |= (opt)) | ||
| 114 | |||
| 115 | #if HAVE_FCHDIR | ||
| 116 | #define	CHDIR(sp, path)	(!ISSET(FTS_NOCHDIR) && chdir(path)) | ||
| 117 | #define	FCHDIR(sp, fd)	(!ISSET(FTS_NOCHDIR) && fchdir(fd)) | ||
| 118 | #else | ||
| 119 | /* If we don't have fchdir, pretend that !ISSET(FTS_NOCHDIR) is always false in | ||
| 120 | * the above macros, and do not reference chdir or fchdir. */ | ||
| 121 | #define	CHDIR(sp, path)	0 | ||
| 122 | #define	FCHDIR(sp, fd)	0 | ||
| 123 | #endif | ||
| 124 | |||
| 125 | /* fts_build flags */ | ||
| 126 | #define	BCHILD		1		/* fts_children */ | ||
| 127 | #define	BNAMES		2		/* fts_children, names only */ | ||
| 128 | #define	BREAD		3		/* fts_read */ | ||
| 129 | |||
| 130 | #ifndef DTF_HIDEW | ||
| 131 | #undef FTS_WHITEOUT | ||
| 132 | #endif | ||
| 133 | |||
| 134 | FTS * | ||
| 135 | fts_open(char * const *argv, int options, | ||
| 136 | int (*compar)(const FTSENT **, const FTSENT **)) | ||
| 137 | { | ||
| 138 | 	FTS *sp; | ||
| 139 | 	FTSENT *p, *root; | ||
| 140 | 	size_t nitems; | ||
| 141 | 	FTSENT *parent, *tmp = NULL;	/* pacify gcc */ | ||
| 142 | 	size_t len; | ||
| 143 | |||
| 144 | 	_DIAGASSERT(argv != NULL); | ||
| 145 | |||
| 146 | #if !HAVE_FCHDIR | ||
| 147 | /* If we don't have fchdir, pretend that FTS_NOCHDIR is always set. */ | ||
| 148 | options |= FTS_NOCHDIR; | ||
| 149 | #endif | ||
| 150 | |||
| 151 | 	/* Options check. */ | ||
| 152 | 	if (options & ~FTS_OPTIONMASK) { | ||
| 153 | 		errno = EINVAL; | ||
| 154 | 		return (NULL); | ||
| 155 | 	} | ||
| 156 | |||
| 157 | 	/* Allocate/initialize the stream */ | ||
| 158 | 	if ((sp = malloc(sizeof(FTS))) == NULL) | ||
| 159 | 		return (NULL); | ||
| 160 | 	memset(sp, 0, sizeof(FTS)); | ||
| 161 | 	sp->fts_compar = compar; | ||
| 162 | 	sp->fts_options = options; | ||
| 163 | |||
| 164 | 	/* Logical walks turn on NOCHDIR; symbolic links are too hard. */ | ||
| 165 | 	if (ISSET(FTS_LOGICAL)) | ||
| 166 | 		SET(FTS_NOCHDIR); | ||
| 167 | |||
| 168 | 	/* | ||
| 169 | 	 * Start out with 1K of path space, and enough, in any case, | ||
| 170 | 	 * to hold the user's paths. | ||
| 171 | 	 */ | ||
| 172 | 	if (fts_palloc(sp, MAX(fts_maxarglen(argv), MAXPATHLEN))) | ||
| 173 | 		goto mem1; | ||
| 174 | |||
| 175 | 	/* Allocate/initialize root's parent. */ | ||
| 176 | 	if ((parent = fts_alloc(sp, "", 0)) == NULL) | ||
| 177 | 		goto mem2; | ||
| 178 | 	parent->fts_level = FTS_ROOTPARENTLEVEL; | ||
| 179 | |||
| 180 | 	/* Allocate/initialize root(s). */ | ||
| 181 | 	for (root = NULL, nitems = 0; *argv; ++argv, ++nitems) { | ||
| 182 | 		/* Don't allow zero-length paths. */ | ||
| 183 | 		if ((len = strlen(*argv)) == 0) { | ||
| 184 | 			errno = ENOENT; | ||
| 185 | 			goto mem3; | ||
| 186 | 		} | ||
| 187 | |||
| 188 | 		if ((p = fts_alloc(sp, *argv, len)) == NULL) | ||
| 189 | 			goto mem3; | ||
| 190 | 		p->fts_level = FTS_ROOTLEVEL; | ||
| 191 | 		p->fts_parent = parent; | ||
| 192 | 		p->fts_accpath = p->fts_name; | ||
| 193 | 		p->fts_info = fts_stat(sp, p, ISSET(FTS_COMFOLLOW)); | ||
| 194 | |||
| 195 | 		/* Command-line "." and ".." are real directories. */ | ||
| 196 | 		if (p->fts_info == FTS_DOT) | ||
| 197 | 			p->fts_info = FTS_D; | ||
| 198 | |||
| 199 | 		/* | ||
| 200 | 		 * If comparison routine supplied, traverse in sorted | ||
| 201 | 		 * order; otherwise traverse in the order specified. | ||
| 202 | 		 */ | ||
| 203 | 		if (compar) { | ||
| 204 | 			p->fts_link = root; | ||
| 205 | 			root = p; | ||
| 206 | 		} else { | ||
| 207 | 			p->fts_link = NULL; | ||
| 208 | 			if (root == NULL) | ||
| 209 | 				tmp = root = p; | ||
| 210 | 			else { | ||
| 211 | 				tmp->fts_link = p; | ||
| 212 | 				tmp = p; | ||
| 213 | 			} | ||
| 214 | 		} | ||
| 215 | 	} | ||
| 216 | 	if (compar && nitems > 1) | ||
| 217 | 		root = fts_sort(sp, root, nitems); | ||
| 218 | |||
| 219 | 	/* | ||
| 220 | 	 * Allocate a dummy pointer and make fts_read think that we've just | ||
| 221 | 	 * finished the node before the root(s); set p->fts_info to FTS_INIT | ||
| 222 | 	 * so that everything about the "current" node is ignored. | ||
| 223 | 	 */ | ||
| 224 | 	if ((sp->fts_cur = fts_alloc(sp, "", 0)) == NULL) | ||
| 225 | 		goto mem3; | ||
| 226 | 	sp->fts_cur->fts_link = root; | ||
| 227 | 	sp->fts_cur->fts_info = FTS_INIT; | ||
| 228 | |||
| 229 | 	/* | ||
| 230 | 	 * If using chdir(2), grab a file descriptor pointing to dot to ensure | ||
| 231 | 	 * that we can get back here; this could be avoided for some paths, | ||
| 232 | 	 * but almost certainly not worth the effort. Slashes, symbolic links, | ||
| 233 | 	 * and ".." are all fairly nasty problems. Note, if we can't get the | ||
| 234 | 	 * descriptor we run anyway, just more slowly. | ||
| 235 | 	 */ | ||
| 236 | #ifndef O_CLOEXEC | ||
| 237 | #define O_CLOEXEC 0 | ||
| 238 | #endif | ||
| 239 | 	if (!ISSET(FTS_NOCHDIR)) { | ||
| 240 | 		if ((sp->fts_rfd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) | ||
| 241 | 			SET(FTS_NOCHDIR); | ||
| 242 | 	} | ||
| 243 | |||
| 244 | 	if (nitems == 0) | ||
| 245 | 		fts_free(parent); | ||
| 246 | |||
| 247 | 	return (sp); | ||
| 248 | |||
| 249 | mem3:	fts_lfree(root); | ||
| 250 | 	fts_free(parent); | ||
| 251 | mem2:	free(sp->fts_path); | ||
| 252 | mem1:	free(sp); | ||
| 253 | 	return (NULL); | ||
| 254 | } | ||
| 255 | |||
| 256 | static void | ||
| 257 | fts_load(FTS *sp, FTSENT *p) | ||
| 258 | { | ||
| 259 | 	size_t len; | ||
| 260 | 	char *cp; | ||
| 261 | |||
| 262 | 	_DIAGASSERT(sp != NULL); | ||
| 263 | 	_DIAGASSERT(p != NULL); | ||
| 264 | |||
| 265 | 	/* | ||
| 266 | 	 * Load the stream structure for the next traversal. Since we don't | ||
| 267 | 	 * actually enter the directory until after the preorder visit, set | ||
| 268 | 	 * the fts_accpath field specially so the chdir gets done to the right | ||
| 269 | 	 * place and the user can access the first node. From fts_open it's | ||
| 270 | 	 * known that the path will fit. | ||
| 271 | 	 */ | ||
| 272 | 	len = p->fts_pathlen = p->fts_namelen; | ||
| 273 | 	memmove(sp->fts_path, p->fts_name, len + 1); | ||
| 274 | 	if ((cp = strrchr(p->fts_name, '/')) && (cp != p->fts_name || cp[1])) { | ||
| 275 | 		len = strlen(++cp); | ||
| 276 | 		memmove(p->fts_name, cp, len + 1); | ||
| 277 | 		p->fts_namelen = ftsent_namelen_truncate(len); | ||
| 278 | 	} | ||
| 279 | 	p->fts_accpath = p->fts_path = sp->fts_path; | ||
| 280 | 	sp->fts_dev = p->fts_dev; | ||
| 281 | } | ||
| 282 | |||
| 283 | int | ||
| 284 | fts_close(FTS *sp) | ||
| 285 | { | ||
| 286 | 	FTSENT *freep, *p; | ||
| 287 | 	int saved_errno = 0; | ||
| 288 | |||
| 289 | 	_DIAGASSERT(sp != NULL); | ||
| 290 | |||
| 291 | 	/* | ||
| 292 | 	 * This still works if we haven't read anything -- the dummy structure | ||
| 293 | 	 * points to the root list, so we step through to the end of the root | ||
| 294 | 	 * list which has a valid parent pointer. | ||
| 295 | 	 */ | ||
| 296 | 	if (sp->fts_cur) { | ||
| 297 | 		if (sp->fts_cur->fts_flags & FTS_SYMFOLLOW) | ||
| 298 | 			(void)close(sp->fts_cur->fts_symfd); | ||
| 299 | 		for (p = sp->fts_cur; p->fts_level >= FTS_ROOTLEVEL;) { | ||
| 300 | 			freep = p; | ||
| 301 | 			p = p->fts_link ? p->fts_link : p->fts_parent; | ||
| 302 | 			fts_free(freep); | ||
| 303 | 		} | ||
| 304 | 		fts_free(p); | ||
| 305 | 	} | ||
| 306 | |||
| 307 | 	/* Free up child linked list, sort array, path buffer. */ | ||
| 308 | 	if (sp->fts_child) | ||
| 309 | 		fts_lfree(sp->fts_child); | ||
| 310 | 	if (sp->fts_array) | ||
| 311 | 		free(sp->fts_array); | ||
| 312 | 	free(sp->fts_path); | ||
| 313 | |||
| 314 | 	#if HAVE_FCHDIR | ||
| 315 | 	/* Return to original directory, save errno if necessary. */ | ||
| 316 | 	if (!ISSET(FTS_NOCHDIR)) { | ||
| 317 | 		if (fchdir(sp->fts_rfd) == -1) | ||
| 318 | 			saved_errno = errno; | ||
| 319 | 		(void)close(sp->fts_rfd); | ||
| 320 | 	} | ||
| 321 | 	#endif | ||
| 322 | |||
| 323 | 	/* Free up the stream pointer. */ | ||
| 324 | 	free(sp); | ||
| 325 | 	if (saved_errno) { | ||
| 326 | 		errno = saved_errno; | ||
| 327 | 		return -1; | ||
| 328 | 	} | ||
| 329 | |||
| 330 | 	return 0; | ||
| 331 | } | ||
| 332 | |||
| 333 | #if !defined(__FTS_COMPAT_TAILINGSLASH) | ||
| 334 | |||
| 335 | /* | ||
| 336 | * Special case of "/" at the end of the path so that slashes aren't | ||
| 337 | * appended which would cause paths to be written as "....//foo". | ||
| 338 | */ | ||
| 339 | #define	NAPPEND(p)							\ | ||
| 340 | 	(p->fts_path[p->fts_pathlen - 1] == '/'				\ | ||
| 341 | 	 ? p->fts_pathlen - 1 : p->fts_pathlen) | ||
| 342 | |||
| 343 | #else /* !defined(__FTS_COMPAT_TAILINGSLASH) */ | ||
| 344 | |||
| 345 | /* | ||
| 346 | * compatibility with the old behaviour. | ||
| 347 | * | ||
| 348 | * Special case a root of "/" so that slashes aren't appended which would | ||
| 349 | * cause paths to be written as "//foo". | ||
| 350 | */ | ||
| 351 | |||
| 352 | #define	NAPPEND(p)							\ | ||
| 353 | 	(p->fts_level == FTS_ROOTLEVEL && p->fts_pathlen == 1 &&	\ | ||
| 354 | 	 p->fts_path[0] == '/' ? 0 : p->fts_pathlen) | ||
| 355 | |||
| 356 | #endif /* !defined(__FTS_COMPAT_TAILINGSLASH) */ | ||
| 357 | |||
| 358 | FTSENT * | ||
| 359 | fts_read(FTS *sp) | ||
| 360 | { | ||
| 361 | 	FTSENT *p, *tmp; | ||
| 362 | 	int instr; | ||
| 363 | 	char *t; | ||
| 364 | 	int saved_errno; | ||
| 365 | |||
| 366 | 	_DIAGASSERT(sp != NULL); | ||
| 367 | |||
| 368 | 	/* If finished or unrecoverable error, return NULL. */ | ||
| 369 | 	if (sp->fts_cur == NULL || ISSET(FTS_STOP)) | ||
| 370 | 		return (NULL); | ||
| 371 | |||
| 372 | 	/* Set current node pointer. */ | ||
| 373 | 	p = sp->fts_cur; | ||
| 374 | |||
| 375 | 	/* Save and zero out user instructions. */ | ||
| 376 | 	instr = p->fts_instr; | ||
| 377 | 	p->fts_instr = FTS_NOINSTR; | ||
| 378 | |||
| 379 | 	/* Any type of file may be re-visited; re-stat and re-turn. */ | ||
| 380 | 	if (instr == FTS_AGAIN) { | ||
| 381 | 		p->fts_info = fts_stat(sp, p, 0); | ||
| 382 | 		return (p); | ||
| 383 | 	} | ||
| 384 | |||
| 385 | 	/* | ||
| 386 | 	 * Following a symlink -- SLNONE test allows application to see | ||
| 387 | 	 * SLNONE and recover. If indirecting through a symlink, have | ||
| 388 | 	 * keep a pointer to current location. If unable to get that | ||
| 389 | 	 * pointer, follow fails. | ||
| 390 | 	 */ | ||
| 391 | 	if (instr == FTS_FOLLOW && | ||
| 392 | 	 (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE)) { | ||
| 393 | 		p->fts_info = fts_stat(sp, p, 1); | ||
| 394 | 		if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { | ||
| 395 | 			if ((p->fts_symfd = open(".", O_RDONLY | O_CLOEXEC, 0)) | ||
| 396 | 			 == -1) { | ||
| 397 | 				p->fts_errno = errno; | ||
| 398 | 				p->fts_info = FTS_ERR; | ||
| 399 | 			} else | ||
| 400 | 				p->fts_flags |= FTS_SYMFOLLOW; | ||
| 401 | 		} | ||
| 402 | 		return (p); | ||
| 403 | 	} | ||
| 404 | |||
| 405 | 	/* Directory in pre-order. */ | ||
| 406 | 	if (p->fts_info == FTS_D) { | ||
| 407 | 		/* If skipped or crossed mount point, do post-order visit. */ | ||
| 408 | 		if (instr == FTS_SKIP || | ||
| 409 | 		 (ISSET(FTS_XDEV) && p->fts_dev != sp->fts_dev)) { | ||
| 410 | 			if (p->fts_flags & FTS_SYMFOLLOW) | ||
| 411 | 				(void)close(p->fts_symfd); | ||
| 412 | 			if (sp->fts_child) { | ||
| 413 | 				fts_lfree(sp->fts_child); | ||
| 414 | 				sp->fts_child = NULL; | ||
| 415 | 			} | ||
| 416 | 			p->fts_info = FTS_DP; | ||
| 417 | 			return (p); | ||
| 418 | 		} | ||
| 419 | |||
| 420 | 		/* Rebuild if only read the names and now traversing. */ | ||
| 421 | 		if (sp->fts_child && ISSET(FTS_NAMEONLY)) { | ||
| 422 | 			CLR(FTS_NAMEONLY); | ||
| 423 | 			fts_lfree(sp->fts_child); | ||
| 424 | 			sp->fts_child = NULL; | ||
| 425 | 		} | ||
| 426 | |||
| 427 | 		/* | ||
| 428 | 		 * Cd to the subdirectory. | ||
| 429 | 		 * | ||
| 430 | 		 * If have already read and now fail to chdir, whack the list | ||
| 431 | 		 * to make the names come out right, and set the parent errno | ||
| 432 | 		 * so the application will eventually get an error condition. | ||
| 433 | 		 * Set the FTS_DONTCHDIR flag so that when we logically change | ||
| 434 | 		 * directories back to the parent we don't do a chdir. | ||
| 435 | 		 * | ||
| 436 | 		 * If haven't read do so. If the read fails, fts_build sets | ||
| 437 | 		 * FTS_STOP or the fts_info field of the node. | ||
| 438 | 		 */ | ||
| 439 | 		if (sp->fts_child) { | ||
| 440 | 			if (fts_safe_changedir(sp, p, -1, p->fts_accpath)) { | ||
| 441 | 				p->fts_errno = errno; | ||
| 442 | 				p->fts_flags |= FTS_DONTCHDIR; | ||
| 443 | 				for (p = sp->fts_child; p; p = p->fts_link) | ||
| 444 | 					p->fts_accpath = | ||
| 445 | 					 p->fts_parent->fts_accpath; | ||
| 446 | 			} | ||
| 447 | 		} else if ((sp->fts_child = fts_build(sp, BREAD)) == NULL) { | ||
| 448 | 			if (ISSET(FTS_STOP)) | ||
| 449 | 				return (NULL); | ||
| 450 | 			return (p); | ||
| 451 | 		} | ||
| 452 | 		p = sp->fts_child; | ||
| 453 | 		sp->fts_child = NULL; | ||
| 454 | 		goto name; | ||
| 455 | 	} | ||
| 456 | |||
| 457 | next:	 | ||
| 458 | 	/* Move to the next node on this level. */ | ||
| 459 | 	tmp = p; | ||
| 460 | |||
| 461 | 	/* | ||
| 462 | 	 * We are going to free sp->fts_cur, set it to NULL so | ||
| 463 | 	 * that fts_close() does not attempt to free it again | ||
| 464 | 	 * if we exit without setting it to a new value because | ||
| 465 | 	 * FCHDIR() failed below. | ||
| 466 | 	 */ | ||
| 467 | 	assert(tmp == sp->fts_cur); | ||
| 468 | 	sp->fts_cur = NULL; | ||
| 469 | 	 | ||
| 470 | 	if ((p = p->fts_link) != NULL) { | ||
| 471 | 		fts_free(tmp); | ||
| 472 | |||
| 473 | 		/* | ||
| 474 | 		 * If reached the top, return to the original directory, and | ||
| 475 | 		 * load the paths for the next root. | ||
| 476 | 		 */ | ||
| 477 | 		if (p->fts_level == FTS_ROOTLEVEL) { | ||
| 478 | 			if (FCHDIR(sp, sp->fts_rfd)) { | ||
| 479 | 				SET(FTS_STOP); | ||
| 480 | 				return (NULL); | ||
| 481 | 			} | ||
| 482 | 			fts_load(sp, p); | ||
| 483 | 			return (sp->fts_cur = p); | ||
| 484 | 		} | ||
| 485 | |||
| 486 | 		/* | ||
| 487 | 		 * User may have called fts_set on the node. If skipped, | ||
| 488 | 		 * ignore. If followed, get a file descriptor so we can | ||
| 489 | 		 * get back if necessary. | ||
| 490 | 		 */ | ||
| 491 | 		if (p->fts_instr == FTS_SKIP) | ||
| 492 | 			goto next; | ||
| 493 | 		if (p->fts_instr == FTS_FOLLOW) { | ||
| 494 | 			p->fts_info = fts_stat(sp, p, 1); | ||
| 495 | 			if (p->fts_info == FTS_D && !ISSET(FTS_NOCHDIR)) { | ||
| 496 | 				if ((p->fts_symfd = | ||
| 497 | 				 open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) { | ||
| 498 | 					p->fts_errno = errno; | ||
| 499 | 					p->fts_info = FTS_ERR; | ||
| 500 | 				} else | ||
| 501 | 					p->fts_flags |= FTS_SYMFOLLOW; | ||
| 502 | 			} | ||
| 503 | 			p->fts_instr = FTS_NOINSTR; | ||
| 504 | 		} | ||
| 505 | |||
| 506 | name:		t = sp->fts_path + NAPPEND(p->fts_parent); | ||
| 507 | 		*t++ = '/'; | ||
| 508 | 		memmove(t, p->fts_name, (size_t)(p->fts_namelen + 1)); | ||
| 509 | 		return (sp->fts_cur = p); | ||
| 510 | 	} | ||
| 511 | |||
| 512 | 	/* Move up to the parent node. */ | ||
| 513 | 	p = tmp->fts_parent; | ||
| 514 | 	fts_free(tmp); | ||
| 515 | |||
| 516 | 	if (p->fts_level == FTS_ROOTPARENTLEVEL) { | ||
| 517 | 		/* | ||
| 518 | 		 * Done; free everything up and set errno to 0 so the user | ||
| 519 | 		 * can distinguish between error and EOF. | ||
| 520 | 		 */ | ||
| 521 | 		fts_free(p); | ||
| 522 | 		errno = 0; | ||
| 523 | 		return (sp->fts_cur = NULL); | ||
| 524 | 	} | ||
| 525 | |||
| 526 | 	/* NUL terminate the pathname. */ | ||
| 527 | 	sp->fts_path[p->fts_pathlen] = '\0'; | ||
| 528 | |||
| 529 | 	/* | ||
| 530 | 	 * Return to the parent directory. If at a root node or came through | ||
| 531 | 	 * a symlink, go back through the file descriptor. Otherwise, cd up | ||
| 532 | 	 * one directory. | ||
| 533 | 	 */ | ||
| 534 | 	if (p->fts_level == FTS_ROOTLEVEL) { | ||
| 535 | 		if (FCHDIR(sp, sp->fts_rfd)) { | ||
| 536 | 			SET(FTS_STOP); | ||
| 537 | 			return (NULL); | ||
| 538 | 		} | ||
| 539 | 	} else if (p->fts_flags & FTS_SYMFOLLOW) { | ||
| 540 | 		if (FCHDIR(sp, p->fts_symfd)) { | ||
| 541 | 			saved_errno = errno; | ||
| 542 | 			(void)close(p->fts_symfd); | ||
| 543 | 			errno = saved_errno; | ||
| 544 | 			SET(FTS_STOP); | ||
| 545 | 			return (NULL); | ||
| 546 | 		} | ||
| 547 | 		(void)close(p->fts_symfd); | ||
| 548 | 	} else if (!(p->fts_flags & FTS_DONTCHDIR) && | ||
| 549 | 	 fts_safe_changedir(sp, p->fts_parent, -1, "..")) { | ||
| 550 | 		SET(FTS_STOP); | ||
| 551 | 		return (NULL); | ||
| 552 | 	} | ||
| 553 | 	p->fts_info = p->fts_errno ? FTS_ERR : FTS_DP; | ||
| 554 | 	return (sp->fts_cur = p); | ||
| 555 | } | ||
| 556 | |||
| 557 | /* | ||
| 558 | * Fts_set takes the stream as an argument although it's not used in this | ||
| 559 | * implementation; it would be necessary if anyone wanted to add global | ||
| 560 | * semantics to fts using fts_set. An error return is allowed for similar | ||
| 561 | * reasons. | ||
| 562 | */ | ||
| 563 | /* ARGSUSED */ | ||
| 564 | int | ||
| 565 | fts_set(FTS *sp, FTSENT *p, int instr) | ||
| 566 | { | ||
| 567 | |||
| 568 | 	_DIAGASSERT(sp != NULL); | ||
| 569 | 	_DIAGASSERT(p != NULL); | ||
| 570 | |||
| 571 | 	if (instr && instr != FTS_AGAIN && instr != FTS_FOLLOW && | ||
| 572 | 	 instr != FTS_NOINSTR && instr != FTS_SKIP) { | ||
| 573 | 		errno = EINVAL; | ||
| 574 | 		return (1); | ||
| 575 | 	} | ||
| 576 | 	p->fts_instr = instr; | ||
| 577 | 	return (0); | ||
| 578 | } | ||
| 579 | |||
| 580 | FTSENT * | ||
| 581 | fts_children(FTS *sp, int instr) | ||
| 582 | { | ||
| 583 | 	FTSENT *p; | ||
| 584 | 	int fd; | ||
| 585 | |||
| 586 | 	_DIAGASSERT(sp != NULL); | ||
| 587 | |||
| 588 | 	if (instr && instr != FTS_NAMEONLY) { | ||
| 589 | 		errno = EINVAL; | ||
| 590 | 		return (NULL); | ||
| 591 | 	} | ||
| 592 | |||
| 593 | 	/* Set current node pointer. */ | ||
| 594 | 	p = sp->fts_cur; | ||
| 595 | |||
| 596 | 	/* | ||
| 597 | 	 * Errno set to 0 so user can distinguish empty directory from | ||
| 598 | 	 * an error. | ||
| 599 | 	 */ | ||
| 600 | 	errno = 0; | ||
| 601 | |||
| 602 | 	/* Fatal errors stop here. */ | ||
| 603 | 	if (ISSET(FTS_STOP)) | ||
| 604 | 		return (NULL); | ||
| 605 | |||
| 606 | 	/* Return logical hierarchy of user's arguments. */ | ||
| 607 | 	if (p->fts_info == FTS_INIT) | ||
| 608 | 		return (p->fts_link); | ||
| 609 | |||
| 610 | 	/* | ||
| 611 | 	 * If not a directory being visited in pre-order, stop here. Could | ||
| 612 | 	 * allow FTS_DNR, assuming the user has fixed the problem, but the | ||
| 613 | 	 * same effect is available with FTS_AGAIN. | ||
| 614 | 	 */ | ||
| 615 | 	if (p->fts_info != FTS_D /* && p->fts_info != FTS_DNR */) | ||
| 616 | 		return (NULL); | ||
| 617 | |||
| 618 | 	/* Free up any previous child list. */ | ||
| 619 | 	if (sp->fts_child) | ||
| 620 | 		fts_lfree(sp->fts_child); | ||
| 621 | |||
| 622 | 	if (instr == FTS_NAMEONLY) { | ||
| 623 | 		SET(FTS_NAMEONLY); | ||
| 624 | 		instr = BNAMES; | ||
| 625 | 	} else | ||
| 626 | 		instr = BCHILD; | ||
| 627 | |||
| 628 | 	#if HAVE_FCHDIR | ||
| 629 | 	/* | ||
| 630 | 	 * If using chdir on a relative path and called BEFORE fts_read does | ||
| 631 | 	 * its chdir to the root of a traversal, we can lose -- we need to | ||
| 632 | 	 * chdir into the subdirectory, and we don't know where the current | ||
| 633 | 	 * directory is, so we can't get back so that the upcoming chdir by | ||
| 634 | 	 * fts_read will work. | ||
| 635 | 	 */ | ||
| 636 | 	if (p->fts_level != FTS_ROOTLEVEL || p->fts_accpath[0] == '/' || | ||
| 637 | 	 ISSET(FTS_NOCHDIR)) | ||
| 638 | 		return (sp->fts_child = fts_build(sp, instr)); | ||
| 639 | |||
| 640 | 	if ((fd = open(".", O_RDONLY | O_CLOEXEC, 0)) == -1) | ||
| 641 | 		return (sp->fts_child = NULL); | ||
| 642 | 	sp->fts_child = fts_build(sp, instr); | ||
| 643 | 	if (fchdir(fd)) { | ||
| 644 | 		(void)close(fd); | ||
| 645 | 		return (NULL); | ||
| 646 | 	} | ||
| 647 | 	(void)close(fd); | ||
| 648 | 	return (sp->fts_child); | ||
| 649 | 	#else | ||
| 650 | 	/* If not using chdir, just build the list. */ | ||
| 651 | 	return (sp->fts_child = fts_build(sp, instr)); | ||
| 652 | 	#endif | ||
| 653 | } | ||
| 654 | |||
| 655 | /* | ||
| 656 | * This is the tricky part -- do not casually change *anything* in here. The | ||
| 657 | * idea is to build the linked list of entries that are used by fts_children | ||
| 658 | * and fts_read. There are lots of special cases. | ||
| 659 | * | ||
| 660 | * The real slowdown in walking the tree is the stat calls. If FTS_NOSTAT is | ||
| 661 | * set and it's a physical walk (so that symbolic links can't be directories), | ||
| 662 | * we can do things quickly. First, if it's a 4.4BSD file system, the type | ||
| 663 | * of the file is in the directory entry. Otherwise, we assume that the number | ||
| 664 | * of subdirectories in a node is equal to the number of links to the parent. | ||
| 665 | * The former skips all stat calls. The latter skips stat calls in any leaf | ||
| 666 | * directories and for any files after the subdirectories in the directory have | ||
| 667 | * been found, cutting the stat calls by about 2/3. | ||
| 668 | */ | ||
| 669 | static FTSENT * | ||
| 670 | fts_build(FTS *sp, int type) | ||
| 671 | { | ||
| 672 | 	struct dirent *dp; | ||
| 673 | 	FTSENT *p, *head; | ||
| 674 | 	size_t nitems; | ||
| 675 | 	FTSENT *cur, *tail; | ||
| 676 | 	DIR *dirp; | ||
| 677 | 	void *oldaddr; | ||
| 678 | 	size_t dnamlen; | ||
| 679 | 	int cderrno, descend, level, nlinks, saved_errno, nostat, doadjust; | ||
| 680 | 	size_t len, maxlen; | ||
| 681 | #ifdef FTS_WHITEOUT | ||
| 682 | 	int oflag; | ||
| 683 | #endif | ||
| 684 | 	char *cp = NULL;	/* pacify gcc */ | ||
| 685 | |||
| 686 | 	_DIAGASSERT(sp != NULL); | ||
| 687 | |||
| 688 | 	/* Set current node pointer. */ | ||
| 689 | 	cur = sp->fts_cur; | ||
| 690 | |||
| 691 | 	/* | ||
| 692 | 	 * Open the directory for reading. If this fails, we're done. | ||
| 693 | 	 * If being called from fts_read, set the fts_info field. | ||
| 694 | 	 */ | ||
| 695 | #ifdef FTS_WHITEOUT | ||
| 696 | 	if (ISSET(FTS_WHITEOUT)) | ||
| 697 | 		oflag = DTF_NODUP|DTF_REWIND; | ||
| 698 | 	else | ||
| 699 | 		oflag = DTF_HIDEW|DTF_NODUP|DTF_REWIND; | ||
| 700 | #else | ||
| 701 | #define	__opendir2(path, flag) opendir(path) | ||
| 702 | #endif | ||
| 703 | 	if ((dirp = __opendir2(cur->fts_accpath, oflag)) == NULL) { | ||
| 704 | 		if (type == BREAD) { | ||
| 705 | 			cur->fts_info = FTS_DNR; | ||
| 706 | 			cur->fts_errno = errno; | ||
| 707 | 		} | ||
| 708 | 		return (NULL); | ||
| 709 | 	} | ||
| 710 | |||
| 711 | 	/* | ||
| 712 | 	 * Nlinks is the number of possible entries of type directory in the | ||
| 713 | 	 * directory if we're cheating on stat calls, 0 if we're not doing | ||
| 714 | 	 * any stat calls at all, -1 if we're doing stats on everything. | ||
| 715 | 	 */ | ||
| 716 | 	if (type == BNAMES) { | ||
| 717 | 		nlinks = 0; | ||
| 718 | 		nostat = 1; | ||
| 719 | 	} else if (ISSET(FTS_NOSTAT) && ISSET(FTS_PHYSICAL)) { | ||
| 720 | 		nlinks = cur->fts_nlink - (ISSET(FTS_SEEDOT) ? 0 : 2); | ||
| 721 | 		nostat = 1; | ||
| 722 | 	} else { | ||
| 723 | 		nlinks = -1; | ||
| 724 | 		nostat = 0; | ||
| 725 | 	} | ||
| 726 | |||
| 727 | #ifdef notdef | ||
| 728 | 	(void)printf("nlinks == %d (cur: %d)\n", nlinks, cur->fts_nlink); | ||
| 729 | 	(void)printf("NOSTAT %d PHYSICAL %d SEEDOT %d\n", | ||
| 730 | 	 ISSET(FTS_NOSTAT), ISSET(FTS_PHYSICAL), ISSET(FTS_SEEDOT)); | ||
| 731 | #endif | ||
| 732 | 	/* | ||
| 733 | 	 * If we're going to need to stat anything or we want to descend | ||
| 734 | 	 * and stay in the directory, chdir. If this fails we keep going, | ||
| 735 | 	 * but set a flag so we don't chdir after the post-order visit. | ||
| 736 | 	 * We won't be able to stat anything, but we can still return the | ||
| 737 | 	 * names themselves. Note, that since fts_read won't be able to | ||
| 738 | 	 * chdir into the directory, it will have to return different path | ||
| 739 | 	 * names than before, i.e. "a/b" instead of "b". Since the node | ||
| 740 | 	 * has already been visited in pre-order, have to wait until the | ||
| 741 | 	 * post-order visit to return the error. There is a special case | ||
| 742 | 	 * here, if there was nothing to stat then it's not an error to | ||
| 743 | 	 * not be able to stat. This is all fairly nasty. If a program | ||
| 744 | 	 * needed sorted entries or stat information, they had better be | ||
| 745 | 	 * checking FTS_NS on the returned nodes. | ||
| 746 | 	 */ | ||
| 747 | 	cderrno = 0; | ||
| 748 | 	if (nlinks || type == BREAD) { | ||
| 749 | 		if (fts_safe_changedir(sp, cur, dirfd(dirp), NULL)) { | ||
| 750 | 			if (nlinks && type == BREAD) | ||
| 751 | 				cur->fts_errno = errno; | ||
| 752 | 			cur->fts_flags |= FTS_DONTCHDIR; | ||
| 753 | 			descend = 0; | ||
| 754 | 			cderrno = errno; | ||
| 755 | 		} else | ||
| 756 | 			descend = 1; | ||
| 757 | 	} else | ||
| 758 | 		descend = 0; | ||
| 759 | |||
| 760 | 	/* | ||
| 761 | 	 * Figure out the max file name length that can be stored in the | ||
| 762 | 	 * current path -- the inner loop allocates more path as necessary. | ||
| 763 | 	 * We really wouldn't have to do the maxlen calculations here, we | ||
| 764 | 	 * could do them in fts_read before returning the path, but it's a | ||
| 765 | 	 * lot easier here since the length is part of the dirent structure. | ||
| 766 | 	 * | ||
| 767 | 	 * If not changing directories set a pointer so that can just append | ||
| 768 | 	 * each new name into the path. | ||
| 769 | 	 */ | ||
| 770 | 	len = NAPPEND(cur); | ||
| 771 | 	if (ISSET(FTS_NOCHDIR)) { | ||
| 772 | 		cp = sp->fts_path + len; | ||
| 773 | 		*cp++ = '/'; | ||
| 774 | 	} | ||
| 775 | 	len++; | ||
| 776 | 	maxlen = sp->fts_pathlen - len; | ||
| 777 | |||
| 778 | #if defined(__FTS_COMPAT_LEVEL) | ||
| 779 | 	if (cur->fts_level == SHRT_MAX) { | ||
| 780 | 		(void)closedir(dirp); | ||
| 781 | 		cur->fts_info = FTS_ERR; | ||
| 782 | 		SET(FTS_STOP); | ||
| 783 | 		errno = ENAMETOOLONG; | ||
| 784 | 		return (NULL); | ||
| 785 | 	} | ||
| 786 | #endif | ||
| 787 | |||
| 788 | 	level = cur->fts_level + 1; | ||
| 789 | |||
| 790 | 	/* Read the directory, attaching each entry to the `link' pointer. */ | ||
| 791 | 	doadjust = 0; | ||
| 792 | 	for (head = tail = NULL, nitems = 0; (dp = readdir(dirp)) != NULL;) { | ||
| 793 | |||
| 794 | 		if (!ISSET(FTS_SEEDOT) && ISDOT(dp->d_name)) | ||
| 795 | 			continue; | ||
| 796 | |||
| 797 | #if defined(HAVE_STRUCT_DIRENT_D_NAMLEN) | ||
| 798 | 		dnamlen = dp->d_namlen; | ||
| 799 | #else | ||
| 800 | 		dnamlen = strlen(dp->d_name); | ||
| 801 | #endif | ||
| 802 | 		if ((p = fts_alloc(sp, dp->d_name, dnamlen)) == NULL) | ||
| 803 | 			goto mem1; | ||
| 804 | 		if (dnamlen >= maxlen) {	/* include space for NUL */ | ||
| 805 | 			oldaddr = sp->fts_path; | ||
| 806 | 			if (fts_palloc(sp, dnamlen + len + 1)) { | ||
| 807 | 				/* | ||
| 808 | 				 * No more memory for path or structures. Save | ||
| 809 | 				 * errno, free up the current structure and the | ||
| 810 | 				 * structures already allocated. | ||
| 811 | 				 */ | ||
| 812 | mem1:				saved_errno = errno; | ||
| 813 | 				if (p) | ||
| 814 | 					fts_free(p); | ||
| 815 | 				fts_lfree(head); | ||
| 816 | 				(void)closedir(dirp); | ||
| 817 | 				errno = saved_errno; | ||
| 818 | 				cur->fts_info = FTS_ERR; | ||
| 819 | 				SET(FTS_STOP); | ||
| 820 | 				return (NULL); | ||
| 821 | 			} | ||
| 822 | 			/* Did realloc() change the pointer? */ | ||
| 823 | 			if (oldaddr != sp->fts_path) { | ||
| 824 | 				doadjust = 1; | ||
| 825 | 				if (ISSET(FTS_NOCHDIR)) | ||
| 826 | 					cp = sp->fts_path + len; | ||
| 827 | 			} | ||
| 828 | 			maxlen = sp->fts_pathlen - len; | ||
| 829 | 		} | ||
| 830 | |||
| 831 | #if defined(__FTS_COMPAT_LENGTH) | ||
| 832 | 		if (len + dnamlen >= USHRT_MAX) { | ||
| 833 | 			/* | ||
| 834 | 			 * In an FTSENT, fts_pathlen is an unsigned short | ||
| 835 | 			 * so it is possible to wraparound here. | ||
| 836 | 			 * If we do, free up the current structure and the | ||
| 837 | 			 * structures already allocated, then error out | ||
| 838 | 			 * with ENAMETOOLONG. | ||
| 839 | 			 */ | ||
| 840 | 			fts_free(p); | ||
| 841 | 			fts_lfree(head); | ||
| 842 | 			(void)closedir(dirp); | ||
| 843 | 			cur->fts_info = FTS_ERR; | ||
| 844 | 			SET(FTS_STOP); | ||
| 845 | 			errno = ENAMETOOLONG; | ||
| 846 | 			return (NULL); | ||
| 847 | 		} | ||
| 848 | #endif | ||
| 849 | 		p->fts_level = level; | ||
| 850 | 		p->fts_pathlen = ftsent_pathlen_truncate(len + dnamlen); | ||
| 851 | 		p->fts_parent = sp->fts_cur; | ||
| 852 | |||
| 853 | #ifdef FTS_WHITEOUT | ||
| 854 | 		if (dp->d_type == DT_WHT) | ||
| 855 | 			p->fts_flags |= FTS_ISW; | ||
| 856 | #endif | ||
| 857 | |||
| 858 | 		if (cderrno) { | ||
| 859 | 			if (nlinks) { | ||
| 860 | 				p->fts_info = FTS_NS; | ||
| 861 | 				p->fts_errno = cderrno; | ||
| 862 | 			} else | ||
| 863 | 				p->fts_info = FTS_NSOK; | ||
| 864 | 			p->fts_accpath = cur->fts_accpath; | ||
| 865 | 		} else if (nlinks == 0 | ||
| 866 | #ifdef DT_DIR | ||
| 867 | 		 || (nostat && | ||
| 868 | 		 dp->d_type != DT_DIR && dp->d_type != DT_UNKNOWN) | ||
| 869 | #endif | ||
| 870 | 		 ) { | ||
| 871 | 			p->fts_accpath = | ||
| 872 | 			 ISSET(FTS_NOCHDIR) ? p->fts_path : p->fts_name; | ||
| 873 | 			p->fts_info = FTS_NSOK; | ||
| 874 | 		} else { | ||
| 875 | 			/* Build a file name for fts_stat to stat. */ | ||
| 876 | 			if (ISSET(FTS_NOCHDIR)) { | ||
| 877 | 				p->fts_accpath = p->fts_path; | ||
| 878 | 				memmove(cp, p->fts_name, | ||
| 879 | 				 (size_t)(p->fts_namelen + 1)); | ||
| 880 | 			} else | ||
| 881 | 				p->fts_accpath = p->fts_name; | ||
| 882 | 			/* Stat it. */ | ||
| 883 | 			p->fts_info = fts_stat(sp, p, 0); | ||
| 884 | |||
| 885 | 			/* Decrement link count if applicable. */ | ||
| 886 | 			if (nlinks > 0 && (p->fts_info == FTS_D || | ||
| 887 | 			 p->fts_info == FTS_DC || p->fts_info == FTS_DOT)) | ||
| 888 | 				--nlinks; | ||
| 889 | 		} | ||
| 890 | |||
| 891 | 		/* We walk in directory order so "ls -f" doesn't get upset. */ | ||
| 892 | 		p->fts_link = NULL; | ||
| 893 | 		if (head == NULL) | ||
| 894 | 			head = tail = p; | ||
| 895 | 		else { | ||
| 896 | 			tail->fts_link = p; | ||
| 897 | 			tail = p; | ||
| 898 | 		} | ||
| 899 | 		++nitems; | ||
| 900 | 	} | ||
| 901 | 	(void)closedir(dirp); | ||
| 902 | |||
| 903 | 	/* | ||
| 904 | 	 * If had to realloc the path, adjust the addresses for the rest | ||
| 905 | 	 * of the tree. | ||
| 906 | 	 */ | ||
| 907 | 	if (doadjust) | ||
| 908 | 		fts_padjust(sp, head); | ||
| 909 | |||
| 910 | 	/* | ||
| 911 | 	 * If not changing directories, reset the path back to original | ||
| 912 | 	 * state. | ||
| 913 | 	 */ | ||
| 914 | 	if (ISSET(FTS_NOCHDIR)) { | ||
| 915 | 		if (len == sp->fts_pathlen || nitems == 0) | ||
| 916 | 			--cp; | ||
| 917 | 		*cp = '\0'; | ||
| 918 | 	} | ||
| 919 | |||
| 920 | 	/* | ||
| 921 | 	 * If descended after called from fts_children or after called from | ||
| 922 | 	 * fts_read and nothing found, get back. At the root level we use | ||
| 923 | 	 * the saved fd; if one of fts_open()'s arguments is a relative path | ||
| 924 | 	 * to an empty directory, we wind up here with no other way back. If | ||
| 925 | 	 * can't get back, we're done. | ||
| 926 | 	 */ | ||
| 927 | 	if (descend && (type == BCHILD || !nitems) && | ||
| 928 | 	 (cur->fts_level == FTS_ROOTLEVEL ? | ||
| 929 | 	 FCHDIR(sp, sp->fts_rfd) : | ||
| 930 | 	 fts_safe_changedir(sp, cur->fts_parent, -1, ".."))) { | ||
| 931 | 		cur->fts_info = FTS_ERR; | ||
| 932 | 		SET(FTS_STOP); | ||
| 933 | 		return (NULL); | ||
| 934 | 	} | ||
| 935 | |||
| 936 | 	/* If didn't find anything, return NULL. */ | ||
| 937 | 	if (!nitems) { | ||
| 938 | 		if (type == BREAD) | ||
| 939 | 			cur->fts_info = FTS_DP; | ||
| 940 | 		return (NULL); | ||
| 941 | 	} | ||
| 942 | |||
| 943 | 	/* Sort the entries. */ | ||
| 944 | 	if (sp->fts_compar && nitems > 1) | ||
| 945 | 		head = fts_sort(sp, head, nitems); | ||
| 946 | 	return (head); | ||
| 947 | } | ||
| 948 | |||
| 949 | static unsigned short | ||
| 950 | fts_stat(FTS *sp, FTSENT *p, int follow) | ||
| 951 | { | ||
| 952 | 	FTSENT *t; | ||
| 953 | 	dev_t dev; | ||
| 954 | 	__fts_ino_t ino; | ||
| 955 | 	__fts_stat_t *sbp, sb; | ||
| 956 | 	int saved_errno; | ||
| 957 | |||
| 958 | 	_DIAGASSERT(sp != NULL); | ||
| 959 | 	_DIAGASSERT(p != NULL); | ||
| 960 | |||
| 961 | 	/* If user needs stat info, stat buffer already allocated. */ | ||
| 962 | 	sbp = ISSET(FTS_NOSTAT) ? &sb : p->fts_statp; | ||
| 963 | |||
| 964 | #ifdef FTS_WHITEOUT | ||
| 965 | 	/* check for whiteout */ | ||
| 966 | 	if (p->fts_flags & FTS_ISW) { | ||
| 967 | 		if (sbp != &sb) { | ||
| 968 | 			memset(sbp, '\0', sizeof (*sbp)); | ||
| 969 | 			sbp->st_mode = S_IFWHT; | ||
| 970 | 		} | ||
| 971 | 		return (FTS_W); | ||
| 972 | 	} | ||
| 973 | #endif | ||
| 974 | |||
| 975 | 	/* | ||
| 976 | 	 * If doing a logical walk, or application requested FTS_FOLLOW, do | ||
| 977 | 	 * a stat(2). If that fails, check for a non-existent symlink. If | ||
| 978 | 	 * fail, set the errno from the stat call. | ||
| 979 | 	 */ | ||
| 980 | 	if (ISSET(FTS_LOGICAL) || follow) { | ||
| 981 | 		if (stat(p->fts_accpath, sbp)) { | ||
| 982 | 			saved_errno = errno; | ||
| 983 | 			if (!lstat(p->fts_accpath, sbp)) { | ||
| 984 | 				errno = 0; | ||
| 985 | 				return (FTS_SLNONE); | ||
| 986 | 			} | ||
| 987 | 			p->fts_errno = saved_errno; | ||
| 988 | 			goto err; | ||
| 989 | 		} | ||
| 990 | 	} else if (lstat(p->fts_accpath, sbp)) { | ||
| 991 | 		p->fts_errno = errno; | ||
| 992 | err:		memset(sbp, 0, sizeof(*sbp)); | ||
| 993 | 		return (FTS_NS); | ||
| 994 | 	} | ||
| 995 | |||
| 996 | 	if (S_ISDIR(sbp->st_mode)) { | ||
| 997 | 		/* | ||
| 998 | 		 * Set the device/inode. Used to find cycles and check for | ||
| 999 | 		 * crossing mount points. Also remember the link count, used | ||
| 1000 | 		 * in fts_build to limit the number of stat calls. It is | ||
| 1001 | 		 * understood that these fields are only referenced if fts_info | ||
| 1002 | 		 * is set to FTS_D. | ||
| 1003 | 		 */ | ||
| 1004 | 		dev = p->fts_dev = sbp->st_dev; | ||
| 1005 | 		ino = p->fts_ino = sbp->st_ino; | ||
| 1006 | 		p->fts_nlink = sbp->st_nlink; | ||
| 1007 | |||
| 1008 | 		if (ISDOT(p->fts_name)) | ||
| 1009 | 			return (FTS_DOT); | ||
| 1010 | |||
| 1011 | 		/* | ||
| 1012 | 		 * Cycle detection is done by brute force when the directory | ||
| 1013 | 		 * is first encountered. If the tree gets deep enough or the | ||
| 1014 | 		 * number of symbolic links to directories is high enough, | ||
| 1015 | 		 * something faster might be worthwhile. | ||
| 1016 | 		 */ | ||
| 1017 | 		for (t = p->fts_parent; | ||
| 1018 | 		 t->fts_level >= FTS_ROOTLEVEL; t = t->fts_parent) | ||
| 1019 | 			if (ino == t->fts_ino && dev == t->fts_dev) { | ||
| 1020 | 				p->fts_cycle = t; | ||
| 1021 | 				return (FTS_DC); | ||
| 1022 | 			} | ||
| 1023 | 		return (FTS_D); | ||
| 1024 | 	} | ||
| 1025 | 	if (S_ISLNK(sbp->st_mode)) | ||
| 1026 | 		return (FTS_SL); | ||
| 1027 | 	if (S_ISREG(sbp->st_mode)) | ||
| 1028 | 		return (FTS_F); | ||
| 1029 | 	return (FTS_DEFAULT); | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | static FTSENT * | ||
| 1033 | fts_sort(FTS *sp, FTSENT *head, size_t nitems) | ||
| 1034 | { | ||
| 1035 | 	FTSENT **ap, *p; | ||
| 1036 | |||
| 1037 | 	_DIAGASSERT(sp != NULL); | ||
| 1038 | 	_DIAGASSERT(head != NULL); | ||
| 1039 | |||
| 1040 | 	/* | ||
| 1041 | 	 * Construct an array of pointers to the structures and call qsort(3). | ||
| 1042 | 	 * Reassemble the array in the order returned by qsort. If unable to | ||
| 1043 | 	 * sort for memory reasons, return the directory entries in their | ||
| 1044 | 	 * current order. Allocate enough space for the current needs plus | ||
| 1045 | 	 * 40 so don't realloc one entry at a time. | ||
| 1046 | 	 */ | ||
| 1047 | 	if (nitems > sp->fts_nitems) { | ||
| 1048 | 		FTSENT **new; | ||
| 1049 | |||
| 1050 | 		new = realloc(sp->fts_array, sizeof(FTSENT *) * (nitems + 40)); | ||
| 1051 | 		if (new == 0) | ||
| 1052 | 			return (head); | ||
| 1053 | 		sp->fts_array = new; | ||
| 1054 | 		sp->fts_nitems = fts_nitems_truncate(nitems + 40); | ||
| 1055 | 	} | ||
| 1056 | 	for (ap = sp->fts_array, p = head; p; p = p->fts_link) | ||
| 1057 | 		*ap++ = p; | ||
| 1058 | 	qsort((void *)sp->fts_array, nitems, sizeof(FTSENT *), | ||
| 1059 | 		(int (*)(const void *, const void *))sp->fts_compar); | ||
| 1060 | 	for (head = *(ap = sp->fts_array); --nitems; ++ap) | ||
| 1061 | 		ap[0]->fts_link = ap[1]; | ||
| 1062 | 	ap[0]->fts_link = NULL; | ||
| 1063 | 	return (head); | ||
| 1064 | } | ||
| 1065 | |||
| 1066 | static FTSENT * | ||
| 1067 | fts_alloc(FTS *sp, const char *name, size_t namelen) | ||
| 1068 | { | ||
| 1069 | 	FTSENT *p; | ||
| 1070 | #if defined(FTS_ALLOC_ALIGNED) | ||
| 1071 | 	size_t len; | ||
| 1072 | #endif | ||
| 1073 | |||
| 1074 | 	_DIAGASSERT(sp != NULL); | ||
| 1075 | 	_DIAGASSERT(name != NULL); | ||
| 1076 | |||
| 1077 | #if defined(FTS_ALLOC_ALIGNED) | ||
| 1078 | 	/* | ||
| 1079 | 	 * The file name is a variable length array and no stat structure is | ||
| 1080 | 	 * necessary if the user has set the nostat bit. Allocate the FTSENT | ||
| 1081 | 	 * structure, the file name and the stat structure in one chunk, but | ||
| 1082 | 	 * be careful that the stat structure is reasonably aligned. Since the | ||
| 1083 | 	 * fts_name field is declared to be of size 1, the fts_name pointer is | ||
| 1084 | 	 * namelen + 2 before the first possible address of the stat structure. | ||
| 1085 | 	 */ | ||
| 1086 | 	len = sizeof(FTSENT) + namelen; | ||
| 1087 | 	if (!ISSET(FTS_NOSTAT)) | ||
| 1088 | 		len += sizeof(*(p->fts_statp)) + ALIGNBYTES; | ||
| 1089 | 	if ((p = malloc(len)) == NULL) | ||
| 1090 | 		return (NULL); | ||
| 1091 | |||
| 1092 | 	if (!ISSET(FTS_NOSTAT)) | ||
| 1093 | 		p->fts_statp = (__fts_stat_t *)ALIGN( | ||
| 1094 | 		 (unsigned long)(p->fts_name + namelen + 2)); | ||
| 1095 | #else | ||
| 1096 | 	if ((p = malloc(sizeof(FTSENT) + namelen)) == NULL) | ||
| 1097 | 		return (NULL); | ||
| 1098 | |||
| 1099 | 	if (!ISSET(FTS_NOSTAT)) | ||
| 1100 | 		if ((p->fts_statp = malloc(sizeof(*(p->fts_statp)))) == NULL) { | ||
| 1101 | 			free(p); | ||
| 1102 | 			return (NULL); | ||
| 1103 | 		} | ||
| 1104 | #endif | ||
| 1105 | |||
| 1106 | if (ISSET(FTS_NOSTAT)) | ||
| 1107 | p->fts_statp = NULL; | ||
| 1108 | |||
| 1109 | 	/* Copy the name plus the trailing NULL. */ | ||
| 1110 | 	memmove(p->fts_name, name, namelen + 1); | ||
| 1111 | |||
| 1112 | 	p->fts_namelen = ftsent_namelen_truncate(namelen); | ||
| 1113 | 	p->fts_path = sp->fts_path; | ||
| 1114 | 	p->fts_errno = 0; | ||
| 1115 | 	p->fts_flags = 0; | ||
| 1116 | 	p->fts_instr = FTS_NOINSTR; | ||
| 1117 | 	p->fts_number = 0; | ||
| 1118 | 	p->fts_pointer = NULL; | ||
| 1119 | 	return (p); | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | static void | ||
| 1123 | fts_free(FTSENT *p) | ||
| 1124 | { | ||
| 1125 | #if !defined(FTS_ALLOC_ALIGNED) | ||
| 1126 | 	if (p->fts_statp) | ||
| 1127 | 		free(p->fts_statp); | ||
| 1128 | #endif | ||
| 1129 | 	free(p); | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | static void | ||
| 1133 | fts_lfree(FTSENT *head) | ||
| 1134 | { | ||
| 1135 | 	FTSENT *p; | ||
| 1136 | |||
| 1137 | 	/* XXX: head may be NULL ? */ | ||
| 1138 | |||
| 1139 | 	/* Free a linked list of structures. */ | ||
| 1140 | 	while ((p = head) != NULL) { | ||
| 1141 | 		head = head->fts_link; | ||
| 1142 | 		fts_free(p); | ||
| 1143 | 	} | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | static size_t | ||
| 1147 | fts_pow2(size_t x) | ||
| 1148 | { | ||
| 1149 | |||
| 1150 | 	x--; | ||
| 1151 | 	x |= x>>1; | ||
| 1152 | 	x |= x>>2; | ||
| 1153 | 	x |= x>>4; | ||
| 1154 | 	x |= x>>8; | ||
| 1155 | 	x |= x>>16; | ||
| 1156 | #if LONG_BIT > 32 | ||
| 1157 | 	x |= x>>32; | ||
| 1158 | #endif | ||
| 1159 | #if LONG_BIT > 64 | ||
| 1160 | 	x |= x>>64; | ||
| 1161 | #endif | ||
| 1162 | 	x++; | ||
| 1163 | 	return (x); | ||
| 1164 | } | ||
| 1165 | |||
| 1166 | /* | ||
| 1167 | * Allow essentially unlimited paths; find, rm, ls should all work on any tree. | ||
| 1168 | * Most systems will allow creation of paths much longer than MAXPATHLEN, even | ||
| 1169 | * though the kernel won't resolve them. Round up the new size to a power of 2, | ||
| 1170 | * so we don't realloc the path 2 bytes at a time. | ||
| 1171 | */ | ||
| 1172 | static int | ||
| 1173 | fts_palloc(FTS *sp, size_t size) | ||
| 1174 | { | ||
| 1175 | 	char *new; | ||
| 1176 | |||
| 1177 | 	_DIAGASSERT(sp != NULL); | ||
| 1178 | |||
| 1179 | #ifdef __FTS_COMPAT_LENGTH | ||
| 1180 | 	/* Protect against fts_pathlen overflow. */ | ||
| 1181 | 	if (size > USHRT_MAX + 1) { | ||
| 1182 | 		errno = ENAMETOOLONG; | ||
| 1183 | 		return (1); | ||
| 1184 | 	} | ||
| 1185 | #endif | ||
| 1186 | 	size = fts_pow2(size); | ||
| 1187 | 	new = realloc(sp->fts_path, size); | ||
| 1188 | 	if (new == 0) | ||
| 1189 | 		return (1); | ||
| 1190 | 	sp->fts_path = new; | ||
| 1191 | 	sp->fts_pathlen = fts_pathlen_truncate(size); | ||
| 1192 | 	return (0); | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | /* | ||
| 1196 | * When the path is realloc'd, have to fix all of the pointers in structures | ||
| 1197 | * already returned. | ||
| 1198 | */ | ||
| 1199 | static void | ||
| 1200 | fts_padjust(FTS *sp, FTSENT *head) | ||
| 1201 | { | ||
| 1202 | 	FTSENT *p; | ||
| 1203 | 	char *addr; | ||
| 1204 | |||
| 1205 | 	_DIAGASSERT(sp != NULL); | ||
| 1206 | |||
| 1207 | #define	ADJUST(p) do {							\ | ||
| 1208 | 	if ((p)->fts_accpath != (p)->fts_name)				\ | ||
| 1209 | 		(p)->fts_accpath =					\ | ||
| 1210 | 		 addr + ((p)->fts_accpath - (p)->fts_path);		\ | ||
| 1211 | 	(p)->fts_path = addr;						\ | ||
| 1212 | } while (/*CONSTCOND*/0) | ||
| 1213 | |||
| 1214 | 	addr = sp->fts_path; | ||
| 1215 | |||
| 1216 | 	/* Adjust the current set of children. */ | ||
| 1217 | 	for (p = sp->fts_child; p; p = p->fts_link) | ||
| 1218 | 		ADJUST(p); | ||
| 1219 | |||
| 1220 | 	/* Adjust the rest of the tree, including the current level. */ | ||
| 1221 | 	for (p = head; p->fts_level >= FTS_ROOTLEVEL;) { | ||
| 1222 | 		ADJUST(p); | ||
| 1223 | 		p = p->fts_link ? p->fts_link : p->fts_parent; | ||
| 1224 | 	} | ||
| 1225 | } | ||
| 1226 | |||
| 1227 | static size_t | ||
| 1228 | fts_maxarglen(char * const *argv) | ||
| 1229 | { | ||
| 1230 | 	size_t len, max; | ||
| 1231 | |||
| 1232 | 	_DIAGASSERT(argv != NULL); | ||
| 1233 | |||
| 1234 | 	for (max = 0; *argv; ++argv) | ||
| 1235 | 		if ((len = strlen(*argv)) > max) | ||
| 1236 | 			max = len; | ||
| 1237 | 	return (max + 1); | ||
| 1238 | } | ||
| 1239 | |||
| 1240 | /* | ||
| 1241 | * Change to dir specified by fd or p->fts_accpath without getting | ||
| 1242 | * tricked by someone changing the world out from underneath us. | ||
| 1243 | * Assumes p->fts_dev and p->fts_ino are filled in. | ||
| 1244 | */ | ||
| 1245 | static int | ||
| 1246 | fts_safe_changedir(const FTS *sp, const FTSENT *p, int fd, const char *path) | ||
| 1247 | { | ||
| 1248 | #if HAVE_FCHDIR | ||
| 1249 | 	int oldfd = fd, ret = -1; | ||
| 1250 | 	__fts_stat_t sb; | ||
| 1251 | |||
| 1252 | 	if (ISSET(FTS_NOCHDIR)) | ||
| 1253 | 		return 0; | ||
| 1254 | |||
| 1255 | 	if (oldfd < 0 && (fd = open(path, O_RDONLY | O_CLOEXEC)) == -1) | ||
| 1256 | 		return -1; | ||
| 1257 | |||
| 1258 | 	if (fstat(fd, &sb) == -1) | ||
| 1259 | 		goto bail; | ||
| 1260 | |||
| 1261 | 	if (sb.st_ino != p->fts_ino || sb.st_dev != p->fts_dev) { | ||
| 1262 | 		errno = ENOENT; | ||
| 1263 | 		goto bail; | ||
| 1264 | 	} | ||
| 1265 | |||
| 1266 | 	ret = fchdir(fd); | ||
| 1267 | |||
| 1268 | bail: | ||
| 1269 | 	if (oldfd < 0) { | ||
| 1270 | 		int save_errno = errno; | ||
| 1271 | 		(void)close(fd); | ||
| 1272 | 		errno = save_errno; | ||
| 1273 | 	} | ||
| 1274 | 	return ret; | ||
| 1275 | #else | ||
| 1276 | 	/* If we can't do fchdir, pretend as if ISSET(FTS_NOCHDIR) is set. */ | ||
| 1277 | 	return 0; | ||
| 1278 | #endif | ||
| 1279 | } | ||
lib/libc/wasi/libc-bottom-half/clocks/clock.c deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #define _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #include <time.h> | ||
| 3 | #include <wasi/api.h> | ||
| 4 | #include <common/time.h> | ||
| 5 | |||
| 6 | _Static_assert( | ||
| 7 | CLOCKS_PER_SEC == NSEC_PER_SEC, | ||
| 8 | "This implementation assumes that `clock` is in nanoseconds" | ||
| 9 | ); | ||
| 10 | |||
| 11 | // Snapshot of the monotonic clock at the start of the program. | ||
| 12 | static __wasi_timestamp_t start; | ||
| 13 | |||
| 14 | // Use a priority of 10 to run fairly early in the implementation-reserved | ||
| 15 | // constructor priority range. | ||
| 16 | __attribute__((constructor(10))) | ||
| 17 | static void init(void) { | ||
| 18 | (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &start); | ||
| 19 | } | ||
| 20 | |||
| 21 | // Define the libc symbol as `__clock` so that we can reliably call it | ||
| 22 | // from elsewhere in libc. | ||
| 23 | clock_t __clock(void) { | ||
| 24 | // Use `MONOTONIC` instead of `PROCESS_CPUTIME_ID` since WASI doesn't have | ||
| 25 | // an inherent concept of a process. Note that this means we'll incorrectly | ||
| 26 | // include time from other processes, so this function is only declared by | ||
| 27 | // the headers if `_WASI_EMULATED_PROCESS_CLOCKS` is defined. | ||
| 28 | __wasi_timestamp_t now = 0; | ||
| 29 | (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &now); | ||
| 30 | return now - start; | ||
| 31 | } | ||
| 32 | |||
| 33 | // Define a user-visible alias as a weak symbol. | ||
| 34 | __attribute__((__weak__, __alias__("__clock"))) | ||
| 35 | clock_t clock(void); | ||
lib/libc/wasi/libc-bottom-half/clocks/getrusage.c deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | #define _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #include <sys/resource.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <time.h> | ||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <common/time.h> | ||
| 7 | |||
| 8 | // `clock` is a weak symbol so that application code can override it. | ||
| 9 | // We want to use the function in libc, so use the libc-internal name. | ||
| 10 | clock_t __clock(void); | ||
| 11 | |||
| 12 | int getrusage(int who, struct rusage *r_usage) { | ||
| 13 | switch (who) { | ||
| 14 | case RUSAGE_SELF: { | ||
| 15 | __wasi_timestamp_t usertime = __clock(); | ||
| 16 | *r_usage = (struct rusage) { | ||
| 17 | .ru_utime = timestamp_to_timeval(usertime) | ||
| 18 | 	}; | ||
| 19 | return 0; | ||
| 20 | } | ||
| 21 | case RUSAGE_CHILDREN: | ||
| 22 | *r_usage = (struct rusage) {}; | ||
| 23 | return 0; | ||
| 24 | default: | ||
| 25 | errno = EINVAL; | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | } | ||
lib/libc/wasi/libc-bottom-half/clocks/times.c deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | #define _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #include <time.h> | ||
| 3 | #include <sys/times.h> | ||
| 4 | #include <wasi/api.h> | ||
| 5 | #include <common/time.h> | ||
| 6 | |||
| 7 | _Static_assert( | ||
| 8 | CLOCKS_PER_SEC == NSEC_PER_SEC, | ||
| 9 | "This implementation assumes that `clock` is in nanoseconds" | ||
| 10 | ); | ||
| 11 | |||
| 12 | // `clock` is a weak symbol so that application code can override it. | ||
| 13 | // We want to use the function in libc, so use the libc-internal name. | ||
| 14 | clock_t __clock(void); | ||
| 15 | |||
| 16 | clock_t times(struct tms *buffer) { | ||
| 17 | __wasi_timestamp_t user = __clock(); | ||
| 18 | *buffer = (struct tms){ | ||
| 19 | .tms_utime = user, | ||
| 20 | // WASI doesn't provide a way to spawn a new process, so always 0. | ||
| 21 | .tms_cutime = 0 | ||
| 22 | }; | ||
| 23 | |||
| 24 | __wasi_timestamp_t realtime = 0; | ||
| 25 | (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &realtime); | ||
| 26 | return realtime; | ||
| 27 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/LICENSE deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | Copyright (c) 2015-2017 Nuxi (https://nuxi.nl/) and contributors. | ||
| 2 | |||
| 3 | Redistribution and use in source and binary forms, with or without | ||
| 4 | modification, are permitted provided that the following conditions | ||
| 5 | are met: | ||
| 6 | 1. Redistributions of source code must retain the above copyright | ||
| 7 | notice, this list of conditions and the following disclaimer. | ||
| 8 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 9 | notice, this list of conditions and the following disclaimer in the | ||
| 10 | documentation and/or other materials provided with the distribution. | ||
| 11 | |||
| 12 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 13 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 14 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 15 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 16 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 17 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 18 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 19 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 20 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 21 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 22 | SUCH DAMAGE. | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/clock.h deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | // Copyright (c) 2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef COMMON_CLOCK_H | ||
| 6 | #define COMMON_CLOCK_H | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | |||
| 10 | // In this implementation we define clockid_t as a pointer type, so that | ||
| 11 | // we can implement them as full objects. Right now we only use those | ||
| 12 | // objects to store the raw ABI-level clock identifier, but in the | ||
| 13 | // future we can use this to provide support for pthread_getcpuclockid() | ||
| 14 | // and clock file descriptors. | ||
| 15 | struct __clockid { | ||
| 16 | __wasi_clockid_t id; | ||
| 17 | }; | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/limits.h deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef COMMON_LIMITS_H | ||
| 6 | #define COMMON_LIMITS_H | ||
| 7 | |||
| 8 | #include <limits.h> | ||
| 9 | |||
| 10 | #define NUMERIC_MIN(t) \ | ||
| 11 | _Generic((t)0, char \ | ||
| 12 | : CHAR_MIN, signed char \ | ||
| 13 | : SCHAR_MIN, unsigned char : 0, short \ | ||
| 14 | : SHRT_MIN, unsigned short : 0, int \ | ||
| 15 | : INT_MIN, unsigned int : 0, long \ | ||
| 16 | : LONG_MIN, unsigned long : 0, long long \ | ||
| 17 | : LLONG_MIN, unsigned long long : 0, default \ | ||
| 18 | : (void)0) | ||
| 19 | |||
| 20 | #define NUMERIC_MAX(t) \ | ||
| 21 | _Generic((t)0, char \ | ||
| 22 | : CHAR_MAX, signed char \ | ||
| 23 | : SCHAR_MAX, unsigned char \ | ||
| 24 | : UCHAR_MAX, short \ | ||
| 25 | : SHRT_MAX, unsigned short \ | ||
| 26 | : USHRT_MAX, int \ | ||
| 27 | : INT_MAX, unsigned int \ | ||
| 28 | : UINT_MAX, long \ | ||
| 29 | : LONG_MAX, unsigned long \ | ||
| 30 | : ULONG_MAX, long long \ | ||
| 31 | : LLONG_MAX, unsigned long long \ | ||
| 32 | : ULLONG_MAX, default \ | ||
| 33 | : (void)0) | ||
| 34 | |||
| 35 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/time.h deleted-63| ... | @@ -1,63 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef COMMON_TIME_H | ||
| 6 | #define COMMON_TIME_H | ||
| 7 | |||
| 8 | #include <common/limits.h> | ||
| 9 | |||
| 10 | #include <sys/time.h> | ||
| 11 | |||
| 12 | #include <wasi/api.h> | ||
| 13 | #include <stdbool.h> | ||
| 14 | #include <time.h> | ||
| 15 | |||
| 16 | #define NSEC_PER_SEC 1000000000 | ||
| 17 | |||
| 18 | static inline bool timespec_to_timestamp_exact( | ||
| 19 | const struct timespec *timespec, __wasi_timestamp_t *timestamp) { | ||
| 20 | // Invalid nanoseconds field. | ||
| 21 | if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) | ||
| 22 | return false; | ||
| 23 | |||
| 24 | // Timestamps before the Epoch are not supported. | ||
| 25 | if (timespec->tv_sec < 0) | ||
| 26 | return false; | ||
| 27 | |||
| 28 | // Make sure our timestamp does not overflow. | ||
| 29 | return !__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) && | ||
| 30 | !__builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp); | ||
| 31 | } | ||
| 32 | |||
| 33 | static inline bool timespec_to_timestamp_clamp( | ||
| 34 | const struct timespec *timespec, __wasi_timestamp_t *timestamp) { | ||
| 35 | // Invalid nanoseconds field. | ||
| 36 | if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) | ||
| 37 | return false; | ||
| 38 | |||
| 39 | if (timespec->tv_sec < 0) { | ||
| 40 | // Timestamps before the Epoch are not supported. | ||
| 41 | *timestamp = 0; | ||
| 42 | } else if (__builtin_mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) || | ||
| 43 | __builtin_add_overflow(*timestamp, timespec->tv_nsec, timestamp)) { | ||
| 44 | // Make sure our timestamp does not overflow. | ||
| 45 | *timestamp = NUMERIC_MAX(__wasi_timestamp_t); | ||
| 46 | } | ||
| 47 | return true; | ||
| 48 | } | ||
| 49 | |||
| 50 | static inline struct timespec timestamp_to_timespec( | ||
| 51 | __wasi_timestamp_t timestamp) { | ||
| 52 | // Decompose timestamp into seconds and nanoseconds. | ||
| 53 | return (struct timespec){.tv_sec = timestamp / NSEC_PER_SEC, | ||
| 54 | .tv_nsec = timestamp % NSEC_PER_SEC}; | ||
| 55 | } | ||
| 56 | |||
| 57 | static inline struct timeval timestamp_to_timeval( | ||
| 58 | __wasi_timestamp_t timestamp) { | ||
| 59 | struct timespec ts = timestamp_to_timespec(timestamp); | ||
| 60 | return (struct timeval){.tv_sec = ts.tv_sec, ts.tv_nsec / 1000}; | ||
| 61 | } | ||
| 62 | |||
| 63 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/include/_/cdefs.h deleted-36| ... | @@ -1,36 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // Redistribution and use in source and binary forms, with or without | ||
| 4 | // modification, are permitted provided that the following conditions | ||
| 5 | // are met: | ||
| 6 | // 1. Redistributions of source code must retain the above copyright | ||
| 7 | // notice, this list of conditions and the following disclaimer. | ||
| 8 | // 2. Redistributions in binary form must reproduce the above copyright | ||
| 9 | // notice, this list of conditions and the following disclaimer in the | ||
| 10 | // documentation and/or other materials provided with the distribution. | ||
| 11 | // | ||
| 12 | // THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 13 | // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 14 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 15 | // ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 16 | // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 17 | // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 18 | // OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 19 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 20 | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 21 | // OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 22 | // SUCH DAMAGE. | ||
| 23 | |||
| 24 | #ifndef ___CDEFS_H_ | ||
| 25 | #define ___CDEFS_H_ | ||
| 26 | |||
| 27 | // Compiler-independent annotations. | ||
| 28 | |||
| 29 | #define __strong_reference(oldsym, newsym) \ | ||
| 30 | extern __typeof__(oldsym) newsym __attribute__((__alias__(#oldsym))) | ||
| 31 | |||
| 32 | // Convenience macros. | ||
| 33 | |||
| 34 | #define __arraycount(x) (sizeof(x) / sizeof((x)[0])) | ||
| 35 | |||
| 36 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <dirent.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | |||
| 8 | int closedir(DIR *dirp) { | ||
| 9 | return close(fdclosedir(dirp)); | ||
| 10 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirent_impl.h deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef DIRENT_DIRENT_IMPL_H | ||
| 6 | #define DIRENT_DIRENT_IMPL_H | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <stddef.h> | ||
| 10 | |||
| 11 | struct dirent; | ||
| 12 | |||
| 13 | #define DIRENT_DEFAULT_BUFFER_SIZE 4096 | ||
| 14 | |||
| 15 | struct _DIR { | ||
| 16 | // Directory file descriptor and cookie. | ||
| 17 | int fd; | ||
| 18 | __wasi_dircookie_t cookie; | ||
| 19 | |||
| 20 | // Read buffer. | ||
| 21 | char *buffer; | ||
| 22 | size_t buffer_processed; | ||
| 23 | size_t buffer_size; | ||
| 24 | size_t buffer_used; | ||
| 25 | |||
| 26 | // Object returned by readdir(). | ||
| 27 | struct dirent *dirent; | ||
| 28 | size_t dirent_size; | ||
| 29 | }; | ||
| 30 | |||
| 31 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <dirent.h> | ||
| 6 | |||
| 7 | #include "dirent_impl.h" | ||
| 8 | |||
| 9 | int dirfd(DIR *dirp) { | ||
| 10 | return dirp->fd; | ||
| 11 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <dirent.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | |||
| 8 | #include "dirent_impl.h" | ||
| 9 | |||
| 10 | int fdclosedir(DIR *dirp) { | ||
| 11 | int fd = dirp->fd; | ||
| 12 | free(dirp->buffer); | ||
| 13 | free(dirp->dirent); | ||
| 14 | free(dirp); | ||
| 15 | return fd; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c deleted-44| ... | @@ -1,44 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <dirent.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | #include "dirent_impl.h" | ||
| 11 | |||
| 12 | DIR *fdopendir(int fd) { | ||
| 13 | // Allocate new directory object and read buffer. | ||
| 14 | DIR *dirp = malloc(sizeof(*dirp)); | ||
| 15 | if (dirp == NULL) | ||
| 16 | return NULL; | ||
| 17 | dirp->buffer = malloc(DIRENT_DEFAULT_BUFFER_SIZE); | ||
| 18 | if (dirp->buffer == NULL) { | ||
| 19 | free(dirp); | ||
| 20 | return NULL; | ||
| 21 | } | ||
| 22 | |||
| 23 | // Ensure that this is really a directory by already loading the first | ||
| 24 | // chunk of data. | ||
| 25 | __wasi_errno_t error = | ||
| 26 | // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support. | ||
| 27 | __wasi_fd_readdir(fd, (uint8_t *)dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE, | ||
| 28 | __WASI_DIRCOOKIE_START, &dirp->buffer_used); | ||
| 29 | if (error != 0) { | ||
| 30 | free(dirp->buffer); | ||
| 31 | free(dirp); | ||
| 32 | errno = error; | ||
| 33 | return NULL; | ||
| 34 | } | ||
| 35 | |||
| 36 | // Initialize other members. | ||
| 37 | dirp->fd = fd; | ||
| 38 | dirp->cookie = __WASI_DIRCOOKIE_START; | ||
| 39 | dirp->buffer_processed = 0; | ||
| 40 | dirp->buffer_size = DIRENT_DEFAULT_BUFFER_SIZE; | ||
| 41 | dirp->dirent = NULL; | ||
| 42 | dirp->dirent_size = 1; | ||
| 43 | return dirp; | ||
| 44 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/libc.h> | ||
| 6 | #include <wasi/libc-nocwd.h> | ||
| 7 | #include <dirent.h> | ||
| 8 | #include <fcntl.h> | ||
| 9 | #include <stddef.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | DIR *__wasilibc_nocwd_opendirat(int dir, const char *dirname) { | ||
| 13 | // Open directory. | ||
| 14 | int fd = __wasilibc_nocwd_openat_nomode(dir, dirname, O_RDONLY | O_NONBLOCK | O_DIRECTORY); | ||
| 15 | if (fd == -1) | ||
| 16 | return NULL; | ||
| 17 | |||
| 18 | // Create directory handle. | ||
| 19 | DIR *result = fdopendir(fd); | ||
| 20 | if (result == NULL) | ||
| 21 | close(fd); | ||
| 22 | return result; | ||
| 23 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c deleted-132| ... | @@ -1,132 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | #include <sys/types.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <fcntl.h> | ||
| 9 | |||
| 10 | #include <assert.h> | ||
| 11 | #include <wasi/api.h> | ||
| 12 | #include <dirent.h> | ||
| 13 | #include <errno.h> | ||
| 14 | #include <stddef.h> | ||
| 15 | #include <stdlib.h> | ||
| 16 | #include <string.h> | ||
| 17 | |||
| 18 | #include "dirent_impl.h" | ||
| 19 | |||
| 20 | static_assert(DT_BLK == __WASI_FILETYPE_BLOCK_DEVICE, "Value mismatch"); | ||
| 21 | static_assert(DT_CHR == __WASI_FILETYPE_CHARACTER_DEVICE, "Value mismatch"); | ||
| 22 | static_assert(DT_DIR == __WASI_FILETYPE_DIRECTORY, "Value mismatch"); | ||
| 23 | static_assert(DT_FIFO == __WASI_FILETYPE_SOCKET_STREAM, "Value mismatch"); | ||
| 24 | static_assert(DT_LNK == __WASI_FILETYPE_SYMBOLIC_LINK, "Value mismatch"); | ||
| 25 | static_assert(DT_REG == __WASI_FILETYPE_REGULAR_FILE, "Value mismatch"); | ||
| 26 | static_assert(DT_UNKNOWN == __WASI_FILETYPE_UNKNOWN, "Value mismatch"); | ||
| 27 | |||
| 28 | // Grows a buffer to be large enough to hold a certain amount of data. | ||
| 29 | #define GROW(buffer, buffer_size, target_size) \ | ||
| 30 | do { \ | ||
| 31 | if ((buffer_size) < (target_size)) { \ | ||
| 32 | size_t new_size = (buffer_size); \ | ||
| 33 | while (new_size < (target_size)) \ | ||
| 34 | new_size *= 2; \ | ||
| 35 | void *new_buffer = realloc(buffer, new_size); \ | ||
| 36 | if (new_buffer == NULL) \ | ||
| 37 | return NULL; \ | ||
| 38 | (buffer) = new_buffer; \ | ||
| 39 | (buffer_size) = new_size; \ | ||
| 40 | } \ | ||
| 41 | } while (0) | ||
| 42 | |||
| 43 | struct dirent *readdir(DIR *dirp) { | ||
| 44 | for (;;) { | ||
| 45 | // Extract the next dirent header. | ||
| 46 | size_t buffer_left = dirp->buffer_used - dirp->buffer_processed; | ||
| 47 | if (buffer_left < sizeof(__wasi_dirent_t)) { | ||
| 48 | // End-of-file. | ||
| 49 | if (dirp->buffer_used < dirp->buffer_size) | ||
| 50 | return NULL; | ||
| 51 | goto read_entries; | ||
| 52 | } | ||
| 53 | __wasi_dirent_t entry; | ||
| 54 | memcpy(&entry, dirp->buffer + dirp->buffer_processed, sizeof(entry)); | ||
| 55 | |||
| 56 | size_t entry_size = sizeof(__wasi_dirent_t) + entry.d_namlen; | ||
| 57 | if (entry.d_namlen == 0) { | ||
| 58 | // Invalid pathname length. Skip the entry. | ||
| 59 | dirp->buffer_processed += entry_size; | ||
| 60 | continue; | ||
| 61 | } | ||
| 62 | |||
| 63 | // The entire entry must be present in buffer space. If not, read | ||
| 64 | // the entry another time. Ensure that the read buffer is large | ||
| 65 | // enough to fit at least this single entry. | ||
| 66 | if (buffer_left < entry_size) { | ||
| 67 | GROW(dirp->buffer, dirp->buffer_size, entry_size); | ||
| 68 | goto read_entries; | ||
| 69 | } | ||
| 70 | |||
| 71 | // Skip entries having null bytes in the filename. | ||
| 72 | const char *name = dirp->buffer + dirp->buffer_processed + sizeof(entry); | ||
| 73 | if (memchr(name, '\0', entry.d_namlen) != NULL) { | ||
| 74 | dirp->buffer_processed += entry_size; | ||
| 75 | continue; | ||
| 76 | } | ||
| 77 | |||
| 78 | // Return the next directory entry. Ensure that the dirent is large | ||
| 79 | // enough to fit the filename. | ||
| 80 | GROW(dirp->dirent, dirp->dirent_size, | ||
| 81 | offsetof(struct dirent, d_name) + entry.d_namlen + 1); | ||
| 82 | struct dirent *dirent = dirp->dirent; | ||
| 83 | dirent->d_type = entry.d_type; | ||
| 84 | memcpy(dirent->d_name, name, entry.d_namlen); | ||
| 85 | dirent->d_name[entry.d_namlen] = '\0'; | ||
| 86 | |||
| 87 | // `fd_readdir` implementations may set the inode field to zero if the | ||
| 88 | // the inode number is unknown. In that case, do an `fstatat` to get the | ||
| 89 | // inode number. | ||
| 90 | off_t d_ino = entry.d_ino; | ||
| 91 | unsigned char d_type = entry.d_type; | ||
| 92 | if (d_ino == 0 && strcmp(dirent->d_name, "..") != 0) { | ||
| 93 | struct stat statbuf; | ||
| 94 | if (fstatat(dirp->fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) { | ||
| 95 | 	if (errno == ENOENT) { | ||
| 96 | 	 // The file disappeared before we could read it, so skip it. | ||
| 97 | 	 dirp->buffer_processed += entry_size; | ||
| 98 | 	 continue; | ||
| 99 | 	} | ||
| 100 | return NULL; | ||
| 101 | } | ||
| 102 | |||
| 103 | // Fill in the inode. | ||
| 104 | d_ino = statbuf.st_ino; | ||
| 105 | |||
| 106 | // In case someone raced with us and replaced the object with this name | ||
| 107 | // with another of a different type, update the type too. | ||
| 108 | d_type = __wasilibc_iftodt(statbuf.st_mode & S_IFMT); | ||
| 109 | } | ||
| 110 | dirent->d_ino = d_ino; | ||
| 111 | dirent->d_type = d_type; | ||
| 112 | |||
| 113 | dirp->cookie = entry.d_next; | ||
| 114 | dirp->buffer_processed += entry_size; | ||
| 115 | return dirent; | ||
| 116 | |||
| 117 | read_entries: | ||
| 118 | // Discard data currently stored in the input buffer. | ||
| 119 | dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; | ||
| 120 | |||
| 121 | // Load more directory entries and continue. | ||
| 122 | __wasi_errno_t error = | ||
| 123 | // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support. | ||
| 124 | __wasi_fd_readdir(dirp->fd, (uint8_t *)dirp->buffer, dirp->buffer_size, | ||
| 125 | dirp->cookie, &dirp->buffer_used); | ||
| 126 | if (error != 0) { | ||
| 127 | errno = error; | ||
| 128 | return NULL; | ||
| 129 | } | ||
| 130 | dirp->buffer_processed = 0; | ||
| 131 | } | ||
| 132 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <dirent.h> | ||
| 7 | |||
| 8 | #include "dirent_impl.h" | ||
| 9 | |||
| 10 | void rewinddir(DIR *dirp) { | ||
| 11 | // Update cookie. | ||
| 12 | dirp->cookie = __WASI_DIRCOOKIE_START; | ||
| 13 | // Mark entire buffer as processed to force a read of new data. | ||
| 14 | dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; | ||
| 15 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c deleted-168| ... | @@ -1,168 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <wasi/libc.h> | ||
| 7 | #include <wasi/libc-nocwd.h> | ||
| 8 | #include <dirent.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <fcntl.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <unistd.h> | ||
| 14 | #include <sys/stat.h> | ||
| 15 | |||
| 16 | #include "dirent_impl.h" | ||
| 17 | |||
| 18 | static int sel_true(const struct dirent *de) { | ||
| 19 | return 1; | ||
| 20 | } | ||
| 21 | |||
| 22 | int __wasilibc_nocwd_scandirat(int dirfd, const char *dir, struct dirent ***namelist, | ||
| 23 | int (*sel)(const struct dirent *), | ||
| 24 | int (*compar)(const struct dirent **, const struct dirent **)) { | ||
| 25 | struct stat statbuf; | ||
| 26 | |||
| 27 | // Match all files if no select function is provided. | ||
| 28 | if (sel == NULL) | ||
| 29 | sel = sel_true; | ||
| 30 | |||
| 31 | // Open the directory. | ||
| 32 | int fd = __wasilibc_nocwd_openat_nomode(dirfd, dir, O_RDONLY | O_NONBLOCK | O_DIRECTORY); | ||
| 33 | if (fd == -1) | ||
| 34 | return -1; | ||
| 35 | |||
| 36 | // Allocate a read buffer for the directory entries. | ||
| 37 | size_t buffer_size = DIRENT_DEFAULT_BUFFER_SIZE; | ||
| 38 | char *buffer = malloc(buffer_size); | ||
| 39 | if (buffer == NULL) { | ||
| 40 | close(fd); | ||
| 41 | return -1; | ||
| 42 | } | ||
| 43 | size_t buffer_processed = buffer_size; | ||
| 44 | size_t buffer_used = buffer_size; | ||
| 45 | |||
| 46 | // Space for the array to return to the caller. | ||
| 47 | struct dirent **dirents = NULL; | ||
| 48 | size_t dirents_size = 0; | ||
| 49 | size_t dirents_used = 0; | ||
| 50 | |||
| 51 | __wasi_dircookie_t cookie = __WASI_DIRCOOKIE_START; | ||
| 52 | for (;;) { | ||
| 53 | // Extract the next dirent header. | ||
| 54 | size_t buffer_left = buffer_used - buffer_processed; | ||
| 55 | if (buffer_left < sizeof(__wasi_dirent_t)) { | ||
| 56 | // End-of-file. | ||
| 57 | if (buffer_used < buffer_size) | ||
| 58 | break; | ||
| 59 | goto read_entries; | ||
| 60 | } | ||
| 61 | __wasi_dirent_t entry; | ||
| 62 | memcpy(&entry, buffer + buffer_processed, sizeof(entry)); | ||
| 63 | |||
| 64 | size_t entry_size = sizeof(__wasi_dirent_t) + entry.d_namlen; | ||
| 65 | if (entry.d_namlen == 0) { | ||
| 66 | // Invalid pathname length. Skip the entry. | ||
| 67 | buffer_processed += entry_size; | ||
| 68 | continue; | ||
| 69 | } | ||
| 70 | |||
| 71 | // The entire entry must be present in buffer space. If not, read | ||
| 72 | // the entry another time. Ensure that the read buffer is large | ||
| 73 | // enough to fit at least this single entry. | ||
| 74 | if (buffer_left < entry_size) { | ||
| 75 | while (buffer_size < entry_size) | ||
| 76 | buffer_size *= 2; | ||
| 77 | char *new_buffer = realloc(buffer, buffer_size); | ||
| 78 | if (new_buffer == NULL) | ||
| 79 | goto bad; | ||
| 80 | buffer = new_buffer; | ||
| 81 | goto read_entries; | ||
| 82 | } | ||
| 83 | |||
| 84 | // Skip entries having null bytes in the filename. | ||
| 85 | const char *name = buffer + buffer_processed + sizeof(entry); | ||
| 86 | buffer_processed += entry_size; | ||
| 87 | if (memchr(name, '\0', entry.d_namlen) != NULL) | ||
| 88 | continue; | ||
| 89 | |||
| 90 | // Create the new directory entry. | ||
| 91 | struct dirent *dirent = | ||
| 92 | malloc(offsetof(struct dirent, d_name) + entry.d_namlen + 1); | ||
| 93 | if (dirent == NULL) | ||
| 94 | goto bad; | ||
| 95 | dirent->d_type = entry.d_type; | ||
| 96 | memcpy(dirent->d_name, name, entry.d_namlen); | ||
| 97 | dirent->d_name[entry.d_namlen] = '\0'; | ||
| 98 | |||
| 99 | // `fd_readdir` implementations may set the inode field to zero if the | ||
| 100 | // the inode number is unknown. In that case, do an `fstatat` to get the | ||
| 101 | // inode number. | ||
| 102 | off_t d_ino = entry.d_ino; | ||
| 103 | unsigned char d_type = entry.d_type; | ||
| 104 | if (d_ino == 0) { | ||
| 105 | if (fstatat(fd, dirent->d_name, &statbuf, AT_SYMLINK_NOFOLLOW) != 0) { | ||
| 106 | return -1; | ||
| 107 | } | ||
| 108 | |||
| 109 | // Fill in the inode. | ||
| 110 | d_ino = statbuf.st_ino; | ||
| 111 | |||
| 112 | // In case someone raced with us and replaced the object with this name | ||
| 113 | // with another of a different type, update the type too. | ||
| 114 | d_type = __wasilibc_iftodt(statbuf.st_mode & S_IFMT); | ||
| 115 | } | ||
| 116 | dirent->d_ino = d_ino; | ||
| 117 | dirent->d_type = d_type; | ||
| 118 | |||
| 119 | cookie = entry.d_next; | ||
| 120 | |||
| 121 | if (sel(dirent)) { | ||
| 122 | // Add the entry to the results. | ||
| 123 | if (dirents_used == dirents_size) { | ||
| 124 | dirents_size = dirents_size < 8 ? 8 : dirents_size * 2; | ||
| 125 | struct dirent **new_dirents = | ||
| 126 | realloc(dirents, dirents_size * sizeof(*dirents)); | ||
| 127 | if (new_dirents == NULL) { | ||
| 128 | free(dirent); | ||
| 129 | goto bad; | ||
| 130 | } | ||
| 131 | dirents = new_dirents; | ||
| 132 | } | ||
| 133 | dirents[dirents_used++] = dirent; | ||
| 134 | } else { | ||
| 135 | // Discard the entry. | ||
| 136 | free(dirent); | ||
| 137 | } | ||
| 138 | continue; | ||
| 139 | |||
| 140 | read_entries:; | ||
| 141 | // Load more directory entries and continue. | ||
| 142 | // TODO: Remove the cast on `buffer` once the witx is updated with char8 support. | ||
| 143 | __wasi_errno_t error = __wasi_fd_readdir(fd, (uint8_t *)buffer, buffer_size, | ||
| 144 | cookie, &buffer_used); | ||
| 145 | if (error != 0) { | ||
| 146 | errno = error; | ||
| 147 | goto bad; | ||
| 148 | } | ||
| 149 | buffer_processed = 0; | ||
| 150 | } | ||
| 151 | |||
| 152 | // Sort results and return them. | ||
| 153 | free(buffer); | ||
| 154 | close(fd); | ||
| 155 | (qsort)(dirents, dirents_used, sizeof(*dirents), | ||
| 156 | (int (*)(const void *, const void *))compar); | ||
| 157 | *namelist = dirents; | ||
| 158 | return dirents_used; | ||
| 159 | |||
| 160 | bad: | ||
| 161 | // Deallocate partially created results. | ||
| 162 | for (size_t i = 0; i < dirents_used; ++i) | ||
| 163 | free(dirents[i]); | ||
| 164 | free(dirents); | ||
| 165 | free(buffer); | ||
| 166 | close(fd); | ||
| 167 | return -1; | ||
| 168 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <dirent.h> | ||
| 6 | |||
| 7 | #include "dirent_impl.h" | ||
| 8 | |||
| 9 | void seekdir(DIR *dirp, long loc) { | ||
| 10 | // Update cookie. | ||
| 11 | dirp->cookie = (unsigned long)loc; | ||
| 12 | // Mark entire buffer as processed to force a read of new data. | ||
| 13 | // TODO(ed): We could prevent a read if the offset is in the buffer. | ||
| 14 | dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; | ||
| 15 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <dirent.h> | ||
| 6 | |||
| 7 | #include "dirent_impl.h" | ||
| 8 | |||
| 9 | long telldir(DIR *dirp) { | ||
| 10 | return dirp->cookie; | ||
| 11 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c deleted-87| ... | @@ -1,87 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <assert.h> | ||
| 6 | #include <wasi/api.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <threads.h> | ||
| 9 | |||
| 10 | static_assert(E2BIG == __WASI_ERRNO_2BIG, "Value mismatch"); | ||
| 11 | static_assert(EACCES == __WASI_ERRNO_ACCES, "Value mismatch"); | ||
| 12 | static_assert(EADDRINUSE == __WASI_ERRNO_ADDRINUSE, "Value mismatch"); | ||
| 13 | static_assert(EADDRNOTAVAIL == __WASI_ERRNO_ADDRNOTAVAIL, "Value mismatch"); | ||
| 14 | static_assert(EAFNOSUPPORT == __WASI_ERRNO_AFNOSUPPORT, "Value mismatch"); | ||
| 15 | static_assert(EAGAIN == __WASI_ERRNO_AGAIN, "Value mismatch"); | ||
| 16 | static_assert(EALREADY == __WASI_ERRNO_ALREADY, "Value mismatch"); | ||
| 17 | static_assert(EBADF == __WASI_ERRNO_BADF, "Value mismatch"); | ||
| 18 | static_assert(EBADMSG == __WASI_ERRNO_BADMSG, "Value mismatch"); | ||
| 19 | static_assert(EBUSY == __WASI_ERRNO_BUSY, "Value mismatch"); | ||
| 20 | static_assert(ECANCELED == __WASI_ERRNO_CANCELED, "Value mismatch"); | ||
| 21 | static_assert(ECHILD == __WASI_ERRNO_CHILD, "Value mismatch"); | ||
| 22 | static_assert(ECONNABORTED == __WASI_ERRNO_CONNABORTED, "Value mismatch"); | ||
| 23 | static_assert(ECONNREFUSED == __WASI_ERRNO_CONNREFUSED, "Value mismatch"); | ||
| 24 | static_assert(ECONNRESET == __WASI_ERRNO_CONNRESET, "Value mismatch"); | ||
| 25 | static_assert(EDEADLK == __WASI_ERRNO_DEADLK, "Value mismatch"); | ||
| 26 | static_assert(EDESTADDRREQ == __WASI_ERRNO_DESTADDRREQ, "Value mismatch"); | ||
| 27 | static_assert(EDOM == __WASI_ERRNO_DOM, "Value mismatch"); | ||
| 28 | static_assert(EDQUOT == __WASI_ERRNO_DQUOT, "Value mismatch"); | ||
| 29 | static_assert(EEXIST == __WASI_ERRNO_EXIST, "Value mismatch"); | ||
| 30 | static_assert(EFAULT == __WASI_ERRNO_FAULT, "Value mismatch"); | ||
| 31 | static_assert(EFBIG == __WASI_ERRNO_FBIG, "Value mismatch"); | ||
| 32 | static_assert(EHOSTUNREACH == __WASI_ERRNO_HOSTUNREACH, "Value mismatch"); | ||
| 33 | static_assert(EIDRM == __WASI_ERRNO_IDRM, "Value mismatch"); | ||
| 34 | static_assert(EILSEQ == __WASI_ERRNO_ILSEQ, "Value mismatch"); | ||
| 35 | static_assert(EINPROGRESS == __WASI_ERRNO_INPROGRESS, "Value mismatch"); | ||
| 36 | static_assert(EINTR == __WASI_ERRNO_INTR, "Value mismatch"); | ||
| 37 | static_assert(EINVAL == __WASI_ERRNO_INVAL, "Value mismatch"); | ||
| 38 | static_assert(EIO == __WASI_ERRNO_IO, "Value mismatch"); | ||
| 39 | static_assert(EISCONN == __WASI_ERRNO_ISCONN, "Value mismatch"); | ||
| 40 | static_assert(EISDIR == __WASI_ERRNO_ISDIR, "Value mismatch"); | ||
| 41 | static_assert(ELOOP == __WASI_ERRNO_LOOP, "Value mismatch"); | ||
| 42 | static_assert(EMFILE == __WASI_ERRNO_MFILE, "Value mismatch"); | ||
| 43 | static_assert(EMLINK == __WASI_ERRNO_MLINK, "Value mismatch"); | ||
| 44 | static_assert(EMSGSIZE == __WASI_ERRNO_MSGSIZE, "Value mismatch"); | ||
| 45 | static_assert(EMULTIHOP == __WASI_ERRNO_MULTIHOP, "Value mismatch"); | ||
| 46 | static_assert(ENAMETOOLONG == __WASI_ERRNO_NAMETOOLONG, "Value mismatch"); | ||
| 47 | static_assert(ENETDOWN == __WASI_ERRNO_NETDOWN, "Value mismatch"); | ||
| 48 | static_assert(ENETRESET == __WASI_ERRNO_NETRESET, "Value mismatch"); | ||
| 49 | static_assert(ENETUNREACH == __WASI_ERRNO_NETUNREACH, "Value mismatch"); | ||
| 50 | static_assert(ENFILE == __WASI_ERRNO_NFILE, "Value mismatch"); | ||
| 51 | static_assert(ENOBUFS == __WASI_ERRNO_NOBUFS, "Value mismatch"); | ||
| 52 | static_assert(ENODEV == __WASI_ERRNO_NODEV, "Value mismatch"); | ||
| 53 | static_assert(ENOENT == __WASI_ERRNO_NOENT, "Value mismatch"); | ||
| 54 | static_assert(ENOEXEC == __WASI_ERRNO_NOEXEC, "Value mismatch"); | ||
| 55 | static_assert(ENOLCK == __WASI_ERRNO_NOLCK, "Value mismatch"); | ||
| 56 | static_assert(ENOLINK == __WASI_ERRNO_NOLINK, "Value mismatch"); | ||
| 57 | static_assert(ENOMEM == __WASI_ERRNO_NOMEM, "Value mismatch"); | ||
| 58 | static_assert(ENOMSG == __WASI_ERRNO_NOMSG, "Value mismatch"); | ||
| 59 | static_assert(ENOPROTOOPT == __WASI_ERRNO_NOPROTOOPT, "Value mismatch"); | ||
| 60 | static_assert(ENOSPC == __WASI_ERRNO_NOSPC, "Value mismatch"); | ||
| 61 | static_assert(ENOSYS == __WASI_ERRNO_NOSYS, "Value mismatch"); | ||
| 62 | static_assert(ENOTCAPABLE == __WASI_ERRNO_NOTCAPABLE, "Value mismatch"); | ||
| 63 | static_assert(ENOTCONN == __WASI_ERRNO_NOTCONN, "Value mismatch"); | ||
| 64 | static_assert(ENOTDIR == __WASI_ERRNO_NOTDIR, "Value mismatch"); | ||
| 65 | static_assert(ENOTEMPTY == __WASI_ERRNO_NOTEMPTY, "Value mismatch"); | ||
| 66 | static_assert(ENOTRECOVERABLE == __WASI_ERRNO_NOTRECOVERABLE, "Value mismatch"); | ||
| 67 | static_assert(ENOTSOCK == __WASI_ERRNO_NOTSOCK, "Value mismatch"); | ||
| 68 | static_assert(ENOTSUP == __WASI_ERRNO_NOTSUP, "Value mismatch"); | ||
| 69 | static_assert(ENOTTY == __WASI_ERRNO_NOTTY, "Value mismatch"); | ||
| 70 | static_assert(ENXIO == __WASI_ERRNO_NXIO, "Value mismatch"); | ||
| 71 | static_assert(EOVERFLOW == __WASI_ERRNO_OVERFLOW, "Value mismatch"); | ||
| 72 | static_assert(EOWNERDEAD == __WASI_ERRNO_OWNERDEAD, "Value mismatch"); | ||
| 73 | static_assert(EPERM == __WASI_ERRNO_PERM, "Value mismatch"); | ||
| 74 | static_assert(EPIPE == __WASI_ERRNO_PIPE, "Value mismatch"); | ||
| 75 | static_assert(EPROTO == __WASI_ERRNO_PROTO, "Value mismatch"); | ||
| 76 | static_assert(EPROTONOSUPPORT == __WASI_ERRNO_PROTONOSUPPORT, "Value mismatch"); | ||
| 77 | static_assert(EPROTOTYPE == __WASI_ERRNO_PROTOTYPE, "Value mismatch"); | ||
| 78 | static_assert(ERANGE == __WASI_ERRNO_RANGE, "Value mismatch"); | ||
| 79 | static_assert(EROFS == __WASI_ERRNO_ROFS, "Value mismatch"); | ||
| 80 | static_assert(ESPIPE == __WASI_ERRNO_SPIPE, "Value mismatch"); | ||
| 81 | static_assert(ESRCH == __WASI_ERRNO_SRCH, "Value mismatch"); | ||
| 82 | static_assert(ESTALE == __WASI_ERRNO_STALE, "Value mismatch"); | ||
| 83 | static_assert(ETIMEDOUT == __WASI_ERRNO_TIMEDOUT, "Value mismatch"); | ||
| 84 | static_assert(ETXTBSY == __WASI_ERRNO_TXTBSY, "Value mismatch"); | ||
| 85 | static_assert(EXDEV == __WASI_ERRNO_XDEV, "Value mismatch"); | ||
| 86 | |||
| 87 | thread_local int errno = 0; | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c deleted-62| ... | @@ -1,62 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <stdarg.h> | ||
| 9 | |||
| 10 | int fcntl(int fildes, int cmd, ...) { | ||
| 11 | switch (cmd) { | ||
| 12 | case F_GETFD: | ||
| 13 | // Act as if the close-on-exec flag is always set. | ||
| 14 | return FD_CLOEXEC; | ||
| 15 | case F_SETFD: | ||
| 16 | // The close-on-exec flag is ignored. | ||
| 17 | return 0; | ||
| 18 | case F_GETFL: { | ||
| 19 | // Obtain the flags and the rights of the descriptor. | ||
| 20 | __wasi_fdstat_t fds; | ||
| 21 | __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); | ||
| 22 | if (error != 0) { | ||
| 23 | errno = error; | ||
| 24 | return -1; | ||
| 25 | } | ||
| 26 | |||
| 27 | // Roughly approximate the access mode by converting the rights. | ||
| 28 | int oflags = fds.fs_flags; | ||
| 29 | if ((fds.fs_rights_base & | ||
| 30 | (__WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR)) != 0) { | ||
| 31 | if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) | ||
| 32 | oflags |= O_RDWR; | ||
| 33 | else | ||
| 34 | oflags |= O_RDONLY; | ||
| 35 | } else if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) != 0) { | ||
| 36 | oflags |= O_WRONLY; | ||
| 37 | } else { | ||
| 38 | oflags |= O_SEARCH; | ||
| 39 | } | ||
| 40 | return oflags; | ||
| 41 | } | ||
| 42 | case F_SETFL: { | ||
| 43 | // Set new file descriptor flags. | ||
| 44 | va_list ap; | ||
| 45 | va_start(ap, cmd); | ||
| 46 | int flags = va_arg(ap, int); | ||
| 47 | va_end(ap); | ||
| 48 | |||
| 49 | __wasi_fdflags_t fs_flags = flags & 0xfff; | ||
| 50 | __wasi_errno_t error = | ||
| 51 | __wasi_fd_fdstat_set_flags(fildes, fs_flags); | ||
| 52 | if (error != 0) { | ||
| 53 | errno = error; | ||
| 54 | return -1; | ||
| 55 | } | ||
| 56 | return 0; | ||
| 57 | } | ||
| 58 | default: | ||
| 59 | errno = EINVAL; | ||
| 60 | return -1; | ||
| 61 | } | ||
| 62 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c deleted-80| ... | @@ -1,80 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <assert.h> | ||
| 6 | #include <wasi/api.h> | ||
| 7 | #include <wasi/libc.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | static_assert(O_APPEND == __WASI_FDFLAGS_APPEND, "Value mismatch"); | ||
| 13 | static_assert(O_DSYNC == __WASI_FDFLAGS_DSYNC, "Value mismatch"); | ||
| 14 | static_assert(O_NONBLOCK == __WASI_FDFLAGS_NONBLOCK, "Value mismatch"); | ||
| 15 | static_assert(O_RSYNC == __WASI_FDFLAGS_RSYNC, "Value mismatch"); | ||
| 16 | static_assert(O_SYNC == __WASI_FDFLAGS_SYNC, "Value mismatch"); | ||
| 17 | |||
| 18 | static_assert(O_CREAT >> 12 == __WASI_OFLAGS_CREAT, "Value mismatch"); | ||
| 19 | static_assert(O_DIRECTORY >> 12 == __WASI_OFLAGS_DIRECTORY, "Value mismatch"); | ||
| 20 | static_assert(O_EXCL >> 12 == __WASI_OFLAGS_EXCL, "Value mismatch"); | ||
| 21 | static_assert(O_TRUNC >> 12 == __WASI_OFLAGS_TRUNC, "Value mismatch"); | ||
| 22 | |||
| 23 | int __wasilibc_nocwd_openat_nomode(int fd, const char *path, int oflag) { | ||
| 24 | // Compute rights corresponding with the access modes provided. | ||
| 25 | // Attempt to obtain all rights, except the ones that contradict the | ||
| 26 | // access mode provided to openat(). | ||
| 27 | __wasi_rights_t max = | ||
| 28 | ~(__WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_READ | | ||
| 29 | __WASI_RIGHTS_FD_WRITE | __WASI_RIGHTS_FD_ALLOCATE | | ||
| 30 | __WASI_RIGHTS_FD_READDIR | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE); | ||
| 31 | switch (oflag & O_ACCMODE) { | ||
| 32 | case O_RDONLY: | ||
| 33 | case O_RDWR: | ||
| 34 | case O_WRONLY: | ||
| 35 | if ((oflag & O_RDONLY) != 0) { | ||
| 36 | max |= __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR; | ||
| 37 | } | ||
| 38 | if ((oflag & O_WRONLY) != 0) { | ||
| 39 | max |= __WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_WRITE | | ||
| 40 | __WASI_RIGHTS_FD_ALLOCATE | | ||
| 41 | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE; | ||
| 42 | } | ||
| 43 | break; | ||
| 44 | case O_EXEC: | ||
| 45 | break; | ||
| 46 | case O_SEARCH: | ||
| 47 | break; | ||
| 48 | default: | ||
| 49 | errno = EINVAL; | ||
| 50 | return -1; | ||
| 51 | } | ||
| 52 | |||
| 53 | // Ensure that we can actually obtain the minimal rights needed. | ||
| 54 | __wasi_fdstat_t fsb_cur; | ||
| 55 | __wasi_errno_t error = __wasi_fd_fdstat_get(fd, &fsb_cur); | ||
| 56 | if (error != 0) { | ||
| 57 | errno = error; | ||
| 58 | return -1; | ||
| 59 | } | ||
| 60 | |||
| 61 | // Path lookup properties. | ||
| 62 | __wasi_lookupflags_t lookup_flags = 0; | ||
| 63 | if ((oflag & O_NOFOLLOW) == 0) | ||
| 64 | lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 65 | |||
| 66 | // Open file with appropriate rights. | ||
| 67 | __wasi_fdflags_t fs_flags = oflag & 0xfff; | ||
| 68 | __wasi_rights_t fs_rights_base = max & fsb_cur.fs_rights_inheriting; | ||
| 69 | __wasi_rights_t fs_rights_inheriting = fsb_cur.fs_rights_inheriting; | ||
| 70 | __wasi_fd_t newfd; | ||
| 71 | error = __wasi_path_open(fd, lookup_flags, path, | ||
| 72 | (oflag >> 12) & 0xfff, | ||
| 73 | fs_rights_base, fs_rights_inheriting, fs_flags, | ||
| 74 | &newfd); | ||
| 75 | if (error != 0) { | ||
| 76 | errno = error; | ||
| 77 | return -1; | ||
| 78 | } | ||
| 79 | return newfd; | ||
| 80 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <assert.h> | ||
| 6 | #include <wasi/api.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <fcntl.h> | ||
| 9 | |||
| 10 | static_assert(POSIX_FADV_DONTNEED == __WASI_ADVICE_DONTNEED, | ||
| 11 | "Value mismatch"); | ||
| 12 | static_assert(POSIX_FADV_NOREUSE == __WASI_ADVICE_NOREUSE, "Value mismatch"); | ||
| 13 | static_assert(POSIX_FADV_NORMAL == __WASI_ADVICE_NORMAL, "Value mismatch"); | ||
| 14 | static_assert(POSIX_FADV_RANDOM == __WASI_ADVICE_RANDOM, "Value mismatch"); | ||
| 15 | static_assert(POSIX_FADV_SEQUENTIAL == __WASI_ADVICE_SEQUENTIAL, | ||
| 16 | "Value mismatch"); | ||
| 17 | static_assert(POSIX_FADV_WILLNEED == __WASI_ADVICE_WILLNEED, | ||
| 18 | "Value mismatch"); | ||
| 19 | |||
| 20 | int posix_fadvise(int fd, off_t offset, off_t len, int advice) { | ||
| 21 | if (offset < 0 || len < 0) | ||
| 22 | return EINVAL; | ||
| 23 | return __wasi_fd_advise(fd, offset, len, advice); | ||
| 24 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | |||
| 9 | int posix_fallocate(int fd, off_t offset, off_t len) { | ||
| 10 | if (offset < 0 || len < 0) | ||
| 11 | return EINVAL; | ||
| 12 | return __wasi_fd_allocate(fd, offset, len); | ||
| 13 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c deleted-174| ... | @@ -1,174 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <poll.h> | ||
| 8 | #include <stdbool.h> | ||
| 9 | |||
| 10 | static int poll_wasip1(struct pollfd *fds, size_t nfds, int timeout) { | ||
| 11 | // Construct events for poll(). | ||
| 12 | size_t maxevents = 2 * nfds + 1; | ||
| 13 | __wasi_subscription_t subscriptions[maxevents]; | ||
| 14 | size_t nsubscriptions = 0; | ||
| 15 | for (size_t i = 0; i < nfds; ++i) { | ||
| 16 | struct pollfd *pollfd = &fds[i]; | ||
| 17 | if (pollfd->fd < 0) | ||
| 18 | continue; | ||
| 19 | bool created_events = false; | ||
| 20 | if ((pollfd->events & POLLRDNORM) != 0) { | ||
| 21 | __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; | ||
| 22 | *subscription = (__wasi_subscription_t){ | ||
| 23 | .userdata = (uintptr_t)pollfd, | ||
| 24 | .u.tag = __WASI_EVENTTYPE_FD_READ, | ||
| 25 | .u.u.fd_read.file_descriptor = pollfd->fd, | ||
| 26 | }; | ||
| 27 | created_events = true; | ||
| 28 | } | ||
| 29 | if ((pollfd->events & POLLWRNORM) != 0) { | ||
| 30 | __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; | ||
| 31 | *subscription = (__wasi_subscription_t){ | ||
| 32 | .userdata = (uintptr_t)pollfd, | ||
| 33 | .u.tag = __WASI_EVENTTYPE_FD_WRITE, | ||
| 34 | .u.u.fd_write.file_descriptor = pollfd->fd, | ||
| 35 | }; | ||
| 36 | created_events = true; | ||
| 37 | } | ||
| 38 | |||
| 39 | // As entries are decomposed into separate read/write subscriptions, | ||
| 40 | // we cannot detect POLLERR, POLLHUP and POLLNVAL if POLLRDNORM and | ||
| 41 | // POLLWRNORM are not specified. Disallow this for now. | ||
| 42 | if (!created_events) { | ||
| 43 | errno = ENOSYS; | ||
| 44 | return -1; | ||
| 45 | } | ||
| 46 | } | ||
| 47 | |||
| 48 | // Create extra event for the timeout. | ||
| 49 | if (timeout >= 0) { | ||
| 50 | __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; | ||
| 51 | *subscription = (__wasi_subscription_t){ | ||
| 52 | .u.tag = __WASI_EVENTTYPE_CLOCK, | ||
| 53 | .u.u.clock.id = __WASI_CLOCKID_REALTIME, | ||
| 54 | .u.u.clock.timeout = (__wasi_timestamp_t)timeout * 1000000, | ||
| 55 | }; | ||
| 56 | } | ||
| 57 | |||
| 58 | // Execute poll(). | ||
| 59 | size_t nevents; | ||
| 60 | __wasi_event_t events[nsubscriptions]; | ||
| 61 | __wasi_errno_t error = | ||
| 62 | __wasi_poll_oneoff(subscriptions, events, nsubscriptions, &nevents); | ||
| 63 | if (error != 0) { | ||
| 64 | // WASI's poll requires at least one subscription, or else it returns | ||
| 65 | // `EINVAL`. Since a `poll` with nothing to wait for is valid in POSIX, | ||
| 66 | // return `ENOTSUP` to indicate that we don't support that case. | ||
| 67 | // | ||
| 68 | // Wasm has no signal handling, so if none of the user-provided `pollfd` | ||
| 69 | // elements, nor the timeout, led us to producing even one subscription | ||
| 70 | // to wait for, there would be no way for the poll to wake up. WASI | ||
| 71 | // returns `EINVAL` in this case, but for users of `poll`, `ENOTSUP` is | ||
| 72 | // more likely to be understood. | ||
| 73 | if (nsubscriptions == 0) | ||
| 74 | errno = ENOTSUP; | ||
| 75 | else | ||
| 76 | errno = error; | ||
| 77 | return -1; | ||
| 78 | } | ||
| 79 | |||
| 80 | // Clear revents fields. | ||
| 81 | for (size_t i = 0; i < nfds; ++i) { | ||
| 82 | struct pollfd *pollfd = &fds[i]; | ||
| 83 | pollfd->revents = 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | // Set revents fields. | ||
| 87 | for (size_t i = 0; i < nevents; ++i) { | ||
| 88 | const __wasi_event_t *event = &events[i]; | ||
| 89 | if (event->type == __WASI_EVENTTYPE_FD_READ || | ||
| 90 | event->type == __WASI_EVENTTYPE_FD_WRITE) { | ||
| 91 | struct pollfd *pollfd = (struct pollfd *)(uintptr_t)event->userdata; | ||
| 92 | if (event->error == __WASI_ERRNO_BADF) { | ||
| 93 | // Invalid file descriptor. | ||
| 94 | pollfd->revents |= POLLNVAL; | ||
| 95 | } else if (event->error == __WASI_ERRNO_PIPE) { | ||
| 96 | // Hangup on write side of pipe. | ||
| 97 | pollfd->revents |= POLLHUP; | ||
| 98 | } else if (event->error != 0) { | ||
| 99 | // Another error occurred. | ||
| 100 | pollfd->revents |= POLLERR; | ||
| 101 | } else { | ||
| 102 | // Data can be read or written. | ||
| 103 | if (event->type == __WASI_EVENTTYPE_FD_READ) { | ||
| 104 | pollfd->revents |= POLLRDNORM; | ||
| 105 | if (event->fd_readwrite.flags & __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP) { | ||
| 106 | pollfd->revents |= POLLHUP; | ||
| 107 | } | ||
| 108 | } else if (event->type == __WASI_EVENTTYPE_FD_WRITE) { | ||
| 109 | pollfd->revents |= POLLWRNORM; | ||
| 110 | if (event->fd_readwrite.flags & __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP) { | ||
| 111 | pollfd->revents |= POLLHUP; | ||
| 112 | } | ||
| 113 | } | ||
| 114 | } | ||
| 115 | } | ||
| 116 | } | ||
| 117 | |||
| 118 | // Return the number of events with a non-zero revents value. | ||
| 119 | int retval = 0; | ||
| 120 | for (size_t i = 0; i < nfds; ++i) { | ||
| 121 | struct pollfd *pollfd = &fds[i]; | ||
| 122 | // POLLHUP contradicts with POLLWRNORM. | ||
| 123 | if ((pollfd->revents & POLLHUP) != 0) | ||
| 124 | pollfd->revents &= ~POLLWRNORM; | ||
| 125 | if (pollfd->revents != 0) | ||
| 126 | ++retval; | ||
| 127 | } | ||
| 128 | return retval; | ||
| 129 | } | ||
| 130 | |||
| 131 | #ifdef __wasilibc_use_wasip2 | ||
| 132 | #include <wasi/descriptor_table.h> | ||
| 133 | |||
| 134 | int poll_wasip2(struct pollfd *fds, size_t nfds, int timeout); | ||
| 135 | |||
| 136 | int poll(struct pollfd* fds, nfds_t nfds, int timeout) | ||
| 137 | { | ||
| 138 | bool found_socket = false; | ||
| 139 | bool found_non_socket = false; | ||
| 140 | for (size_t i = 0; i < nfds; ++i) { | ||
| 141 | descriptor_table_entry_t* entry; | ||
| 142 | if (descriptor_table_get_ref(fds[i].fd, &entry)) { | ||
| 143 | found_socket = true; | ||
| 144 | } else { | ||
| 145 | found_non_socket = true; | ||
| 146 | } | ||
| 147 | } | ||
| 148 | |||
| 149 | if (found_socket) { | ||
| 150 | if (found_non_socket) { | ||
| 151 | // We currently don't support polling a mix of non-sockets and | ||
| 152 | // sockets here (though you can do it by using the host APIs | ||
| 153 | // directly), and we probably won't until we've migrated entirely to | ||
| 154 | // WASI 0.2. | ||
| 155 | errno = ENOTSUP; | ||
| 156 | return -1; | ||
| 157 | } | ||
| 158 | |||
| 159 | return poll_wasip2(fds, nfds, timeout); | ||
| 160 | } else if (found_non_socket) { | ||
| 161 | return poll_wasip1(fds, nfds, timeout); | ||
| 162 | } else if (timeout >= 0) { | ||
| 163 | return poll_wasip2(fds, nfds, timeout); | ||
| 164 | } else { | ||
| 165 | errno = ENOTSUP; | ||
| 166 | return -1; | ||
| 167 | } | ||
| 168 | } | ||
| 169 | #else // not __wasilibc_use_wasip2 | ||
| 170 | int poll(struct pollfd* fds, nfds_t nfds, int timeout) | ||
| 171 | { | ||
| 172 | return poll_wasip1(fds, nfds, timeout); | ||
| 173 | } | ||
| 174 | #endif // not __wasilibc_use_wasip2 | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <sched.h> | ||
| 8 | |||
| 9 | int sched_yield(void) { | ||
| 10 | __wasi_errno_t error = __wasi_sched_yield(); | ||
| 11 | if (error != 0) { | ||
| 12 | errno = error; | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | return 0; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <string.h> | ||
| 9 | |||
| 10 | int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char *new) { | ||
| 11 | __wasi_errno_t error = __wasi_path_rename(oldfd, old, newfd, new); | ||
| 12 | if (error != 0) { | ||
| 13 | errno = error; | ||
| 14 | return -1; | ||
| 15 | } | ||
| 16 | return 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifdef __wasilibc_use_wasip2 | ||
| 6 | #include <wasi/wasip2.h> | ||
| 7 | #else | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #endif | ||
| 10 | #include <_/cdefs.h> | ||
| 11 | #include <stdnoreturn.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | |||
| 14 | noreturn void _Exit(int status) { | ||
| 15 | #ifdef __wasilibc_use_wasip2 | ||
| 16 | exit_result_void_void_t exit_status = { .is_err = status != 0 }; | ||
| 17 | exit_exit(&exit_status); | ||
| 18 | #else | ||
| 19 | __wasi_proc_exit(status); | ||
| 20 | #endif | ||
| 21 | } | ||
| 22 | |||
| 23 | __strong_reference(_Exit, _exit); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c deleted-143| ... | @@ -1,143 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/ioctl.h> | ||
| 6 | |||
| 7 | #include <errno.h> | ||
| 8 | #include <stdarg.h> | ||
| 9 | |||
| 10 | #include <wasi/api.h> | ||
| 11 | #ifdef __wasilibc_use_wasip2 | ||
| 12 | #include <wasi/descriptor_table.h> | ||
| 13 | #endif | ||
| 14 | |||
| 15 | int ioctl(int fildes, int request, ...) { | ||
| 16 | #ifdef __wasilibc_use_wasip2 | ||
| 17 | 	descriptor_table_entry_t *entry; | ||
| 18 | 	if (descriptor_table_get_ref(fildes, &entry)) { | ||
| 19 | 		switch (entry->tag) { | ||
| 20 | 		case DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET: { | ||
| 21 | 			tcp_socket_t *socket = &entry->tcp_socket; | ||
| 22 | 			switch (request) { | ||
| 23 | 			case FIONBIO: { | ||
| 24 | 				va_list ap; | ||
| 25 | 				va_start(ap, request); | ||
| 26 | 				socket->blocking = *va_arg(ap, const int *) == | ||
| 27 | 						 0; | ||
| 28 | 				va_end(ap); | ||
| 29 | |||
| 30 | 				return 0; | ||
| 31 | 			} | ||
| 32 | |||
| 33 | 			default: | ||
| 34 | 				// TODO wasi-sockets: anything else we should support? | ||
| 35 | 				errno = EINVAL; | ||
| 36 | 				return -1; | ||
| 37 | 			} | ||
| 38 | 		} | ||
| 39 | |||
| 40 | 		case DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET: { | ||
| 41 | 			udp_socket_t *socket = &entry->udp_socket; | ||
| 42 | 			switch (request) { | ||
| 43 | 			case FIONBIO: { | ||
| 44 | 				va_list ap; | ||
| 45 | 				va_start(ap, request); | ||
| 46 | 				socket->blocking = *va_arg(ap, const int *) == | ||
| 47 | 						 0; | ||
| 48 | 				va_end(ap); | ||
| 49 | |||
| 50 | 				return 0; | ||
| 51 | 			} | ||
| 52 | |||
| 53 | 			default: | ||
| 54 | 				// TODO wasi-sockets: anything else we should support? | ||
| 55 | 				errno = EINVAL; | ||
| 56 | 				return -1; | ||
| 57 | 			} | ||
| 58 | 		} | ||
| 59 | |||
| 60 | 		default: | ||
| 61 | 			errno = ENOPROTOOPT; | ||
| 62 | 			return -1; | ||
| 63 | 		} | ||
| 64 | 	} | ||
| 65 | #endif // __wasilibc_use_wasip2 | ||
| 66 | |||
| 67 | switch (request) { | ||
| 68 | case FIONREAD: { | ||
| 69 | // Poll the file descriptor to determine how many bytes can be read. | ||
| 70 | __wasi_subscription_t subscriptions[2] = { | ||
| 71 | { | ||
| 72 | .u.tag = __WASI_EVENTTYPE_FD_READ, | ||
| 73 | .u.u.fd_read.file_descriptor = fildes, | ||
| 74 | }, | ||
| 75 | { | ||
| 76 | .u.tag = __WASI_EVENTTYPE_CLOCK, | ||
| 77 | .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, | ||
| 78 | }, | ||
| 79 | }; | ||
| 80 | __wasi_event_t events[__arraycount(subscriptions)]; | ||
| 81 | size_t nevents; | ||
| 82 | __wasi_errno_t error = __wasi_poll_oneoff( | ||
| 83 | subscriptions, events, __arraycount(subscriptions), &nevents); | ||
| 84 | if (error != 0) { | ||
| 85 | errno = error; | ||
| 86 | return -1; | ||
| 87 | } | ||
| 88 | |||
| 89 | // Location where result should be written. | ||
| 90 | va_list ap; | ||
| 91 | va_start(ap, request); | ||
| 92 | int *result = va_arg(ap, int *); | ||
| 93 | va_end(ap); | ||
| 94 | |||
| 95 | // Extract number of bytes for reading from poll results. | ||
| 96 | for (size_t i = 0; i < nevents; ++i) { | ||
| 97 | __wasi_event_t *event = &events[i]; | ||
| 98 | if (event->error != 0) { | ||
| 99 | errno = event->error; | ||
| 100 | return -1; | ||
| 101 | } | ||
| 102 | if (event->type == __WASI_EVENTTYPE_FD_READ) { | ||
| 103 | *result = event->fd_readwrite.nbytes; | ||
| 104 | return 0; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | |||
| 108 | // No data available for reading. | ||
| 109 | *result = 0; | ||
| 110 | return 0; | ||
| 111 | } | ||
| 112 | case FIONBIO: { | ||
| 113 | // Obtain the current file descriptor flags. | ||
| 114 | __wasi_fdstat_t fds; | ||
| 115 | __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); | ||
| 116 | if (error != 0) { | ||
| 117 | errno = error; | ||
| 118 | return -1; | ||
| 119 | } | ||
| 120 | |||
| 121 | // Toggle the non-blocking flag based on the argument. | ||
| 122 | va_list ap; | ||
| 123 | va_start(ap, request); | ||
| 124 | if (*va_arg(ap, const int *) != 0) | ||
| 125 | fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; | ||
| 126 | else | ||
| 127 | fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; | ||
| 128 | va_end(ap); | ||
| 129 | |||
| 130 | // Update the file descriptor flags. | ||
| 131 | error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); | ||
| 132 | if (error != 0) { | ||
| 133 | errno = error; | ||
| 134 | return -1; | ||
| 135 | } | ||
| 136 | return 0; | ||
| 137 | } | ||
| 138 | default: | ||
| 139 | // Invalid request. | ||
| 140 | errno = EINVAL; | ||
| 141 | return -1; | ||
| 142 | } | ||
| 143 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c deleted-99| ... | @@ -1,99 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/time.h> | ||
| 6 | |||
| 7 | #include <sys/select.h> | ||
| 8 | |||
| 9 | #include <wasi/api.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <poll.h> | ||
| 12 | |||
| 13 | int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, | ||
| 14 | fd_set *restrict errorfds, const struct timespec *restrict timeout, | ||
| 15 | const sigset_t *sigmask) { | ||
| 16 | // Negative file descriptor upperbound. | ||
| 17 | if (nfds < 0) { | ||
| 18 | errno = EINVAL; | ||
| 19 | return -1; | ||
| 20 | } | ||
| 21 | |||
| 22 | // This implementation does not support polling for exceptional | ||
| 23 | // conditions, such as out-of-band data on TCP sockets. | ||
| 24 | if (errorfds != NULL && errorfds->__nfds > 0) { | ||
| 25 | errno = ENOSYS; | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | |||
| 29 | // Replace NULL pointers by the empty set. | ||
| 30 | fd_set empty; | ||
| 31 | FD_ZERO(&empty); | ||
| 32 | if (readfds == NULL) | ||
| 33 | readfds = &empty; | ||
| 34 | if (writefds == NULL) | ||
| 35 | writefds = &empty; | ||
| 36 | |||
| 37 | struct pollfd poll_fds[readfds->__nfds + writefds->__nfds]; | ||
| 38 | size_t poll_nfds = 0; | ||
| 39 | |||
| 40 | for (size_t i = 0; i < readfds->__nfds; ++i) { | ||
| 41 | int fd = readfds->__fds[i]; | ||
| 42 | if (fd < nfds) { | ||
| 43 | poll_fds[poll_nfds++] = (struct pollfd){ | ||
| 44 | .fd = fd, | ||
| 45 | .events = POLLRDNORM, | ||
| 46 | .revents = 0 | ||
| 47 | }; | ||
| 48 | } | ||
| 49 | } | ||
| 50 | |||
| 51 | for (size_t i = 0; i < writefds->__nfds; ++i) { | ||
| 52 | int fd = writefds->__fds[i]; | ||
| 53 | if (fd < nfds) { | ||
| 54 | poll_fds[poll_nfds++] = (struct pollfd){ | ||
| 55 | .fd = fd, | ||
| 56 | .events = POLLWRNORM, | ||
| 57 | .revents = 0 | ||
| 58 | }; | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | int poll_timeout; | ||
| 63 | if (timeout) { | ||
| 64 | uint64_t timeout_u64; | ||
| 65 | if (!timespec_to_timestamp_clamp(timeout, &timeout_u64) ) { | ||
| 66 | errno = EINVAL; | ||
| 67 | return -1; | ||
| 68 | } | ||
| 69 | |||
| 70 | // Convert nanoseconds to milliseconds: | ||
| 71 | timeout_u64 /= 1000000; | ||
| 72 | |||
| 73 | if (timeout_u64 > INT_MAX) { | ||
| 74 | timeout_u64 = INT_MAX; | ||
| 75 | } | ||
| 76 | |||
| 77 | poll_timeout = (int) timeout_u64; | ||
| 78 | } else { | ||
| 79 | poll_timeout = -1; | ||
| 80 | }; | ||
| 81 | |||
| 82 | if (poll(poll_fds, poll_nfds, poll_timeout) < 0) { | ||
| 83 | return -1; | ||
| 84 | } | ||
| 85 | |||
| 86 | FD_ZERO(readfds); | ||
| 87 | FD_ZERO(writefds); | ||
| 88 | for (size_t i = 0; i < poll_nfds; ++i) { | ||
| 89 | struct pollfd* pollfd = poll_fds + i; | ||
| 90 | if ((pollfd->revents & POLLRDNORM) != 0) { | ||
| 91 | readfds->__fds[readfds->__nfds++] = pollfd->fd; | ||
| 92 | } | ||
| 93 | if ((pollfd->revents & POLLWRNORM) != 0) { | ||
| 94 | writefds->__fds[writefds->__nfds++] = pollfd->fd; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | return readfds->__nfds + writefds->__nfds; | ||
| 99 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/select.h> | ||
| 6 | |||
| 7 | #include <errno.h> | ||
| 8 | #include <stddef.h> | ||
| 9 | |||
| 10 | int select(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, | ||
| 11 | fd_set *restrict errorfds, struct timeval *restrict timeout) { | ||
| 12 | if (timeout != NULL) { | ||
| 13 | // Timeout specified. | ||
| 14 | if (timeout->tv_usec < 0 || timeout->tv_usec >= 1000000) { | ||
| 15 | errno = EINVAL; | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | struct timespec ts = {.tv_sec = timeout->tv_sec, | ||
| 19 | .tv_nsec = (long)timeout->tv_usec * 1000}; | ||
| 20 | return pselect(nfds, readfds, writefds, errorfds, &ts, NULL); | ||
| 21 | } else { | ||
| 22 | // No timeout specified. | ||
| 23 | return pselect(nfds, readfds, writefds, errorfds, NULL, NULL); | ||
| 24 | } | ||
| 25 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c deleted-48| ... | @@ -1,48 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/socket.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <string.h> | ||
| 10 | |||
| 11 | int getsockopt(int socket, int level, int option_name, | ||
| 12 | void *restrict option_value, socklen_t *restrict option_len) { | ||
| 13 | // Only support SOL_SOCKET options for now. | ||
| 14 | if (level != SOL_SOCKET) { | ||
| 15 | errno = ENOPROTOOPT; | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | |||
| 19 | int value; | ||
| 20 | switch (option_name) { | ||
| 21 | case SO_TYPE: { | ||
| 22 | // Return the type of the socket. This information can simply be | ||
| 23 | // obtained by looking at the file descriptor type. | ||
| 24 | __wasi_fdstat_t fsb; | ||
| 25 | if (__wasi_fd_fdstat_get(socket, &fsb) != 0) { | ||
| 26 | errno = EBADF; | ||
| 27 | return -1; | ||
| 28 | } | ||
| 29 | if (fsb.fs_filetype != __WASI_FILETYPE_SOCKET_DGRAM && | ||
| 30 | fsb.fs_filetype != __WASI_FILETYPE_SOCKET_STREAM) { | ||
| 31 | errno = ENOTSOCK; | ||
| 32 | return -1; | ||
| 33 | } | ||
| 34 | value = fsb.fs_filetype; | ||
| 35 | break; | ||
| 36 | } | ||
| 37 | default: { | ||
| 38 | errno = ENOPROTOOPT; | ||
| 39 | return -1; | ||
| 40 | } | ||
| 41 | } | ||
| 42 | |||
| 43 | // Copy out integer value. | ||
| 44 | memcpy(option_value, &value, | ||
| 45 | *option_len < sizeof(int) ? *option_len : sizeof(int)); | ||
| 46 | *option_len = sizeof(int); | ||
| 47 | return 0; | ||
| 48 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/socket.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <stdint.h> | ||
| 11 | |||
| 12 | static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); | ||
| 13 | static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); | ||
| 14 | |||
| 15 | ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { | ||
| 16 | // Validate flags. | ||
| 17 | if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { | ||
| 18 | errno = EOPNOTSUPP; | ||
| 19 | return -1; | ||
| 20 | } | ||
| 21 | |||
| 22 | // Prepare input parameters. | ||
| 23 | __wasi_iovec_t iov = {.buf = buffer, .buf_len = length}; | ||
| 24 | __wasi_iovec_t *ri_data = &iov; | ||
| 25 | size_t ri_data_len = 1; | ||
| 26 | __wasi_riflags_t ri_flags = flags; | ||
| 27 | |||
| 28 | // Perform system call. | ||
| 29 | size_t ro_datalen; | ||
| 30 | __wasi_roflags_t ro_flags; | ||
| 31 | __wasi_errno_t error = __wasi_sock_recv(socket, | ||
| 32 | ri_data, ri_data_len, ri_flags, | ||
| 33 | &ro_datalen, | ||
| 34 | &ro_flags); | ||
| 35 | if (error != 0) { | ||
| 36 | errno = error; | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | return ro_datalen; | ||
| 40 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/socket.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | |||
| 11 | ssize_t send(int socket, const void *buffer, size_t length, int flags) { | ||
| 12 | // This implementation does not support any flags. | ||
| 13 | if (flags != 0) { | ||
| 14 | errno = EOPNOTSUPP; | ||
| 15 | return -1; | ||
| 16 | } | ||
| 17 | |||
| 18 | // Prepare input parameters. | ||
| 19 | __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; | ||
| 20 | __wasi_ciovec_t *si_data = &iov; | ||
| 21 | size_t si_data_len = 1; | ||
| 22 | __wasi_siflags_t si_flags = 0; | ||
| 23 | |||
| 24 | // Perform system call. | ||
| 25 | size_t so_datalen; | ||
| 26 | __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); | ||
| 27 | if (error != 0) { | ||
| 28 | errno = error; | ||
| 29 | return -1; | ||
| 30 | } | ||
| 31 | return so_datalen; | ||
| 32 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/socket.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | |||
| 11 | static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); | ||
| 12 | static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); | ||
| 13 | |||
| 14 | int shutdown(int socket, int how) { | ||
| 15 | // Validate shutdown flags. | ||
| 16 | if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) { | ||
| 17 | errno = EINVAL; | ||
| 18 | return -1; | ||
| 19 | } | ||
| 20 | |||
| 21 | __wasi_errno_t error = __wasi_sock_shutdown(socket, how); | ||
| 22 | if (error != 0) { | ||
| 23 | errno = error; | ||
| 24 | return -1; | ||
| 25 | } | ||
| 26 | return error; | ||
| 27 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket_impl.h deleted-57| ... | @@ -1,57 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef SYS_SOCKET_SOCKET_IMPL_H | ||
| 6 | #define SYS_SOCKET_SOCKET_IMPL_H | ||
| 7 | |||
| 8 | #include <sys/socket.h> | ||
| 9 | #include <sys/un.h> | ||
| 10 | |||
| 11 | #include <netinet/in.h> | ||
| 12 | |||
| 13 | #include <assert.h> | ||
| 14 | #include <stdalign.h> | ||
| 15 | #include <stddef.h> | ||
| 16 | #include <stdint.h> | ||
| 17 | |||
| 18 | static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr), | ||
| 19 | "struct sockaddr_storage too small"); | ||
| 20 | static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr), | ||
| 21 | "struct sockaddr alignment incorrect"); | ||
| 22 | static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr_in), | ||
| 23 | "struct sockaddr_storage too small"); | ||
| 24 | static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr_in), | ||
| 25 | "struct sockaddr_in alignment incorrect"); | ||
| 26 | static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr_in6), | ||
| 27 | "struct sockaddr_storage too small"); | ||
| 28 | static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr_in6), | ||
| 29 | "struct sockaddr_in6 alignment incorrect"); | ||
| 30 | static_assert(sizeof(struct sockaddr_storage) >= sizeof(struct sockaddr_un), | ||
| 31 | "struct sockaddr_storage too small"); | ||
| 32 | static_assert(alignof(struct sockaddr_storage) == alignof(struct sockaddr_un), | ||
| 33 | "struct sockaddr_un alignment incorrect"); | ||
| 34 | |||
| 35 | // Returns the control message header stored at a provided memory | ||
| 36 | // address, ensuring that it is stored within the ancillary data buffer | ||
| 37 | // of a message header. | ||
| 38 | static inline struct cmsghdr *CMSG_GET(const struct msghdr *mhdr, void *cmsg) { | ||
| 39 | // Safety belt: require that the returned object is properly aligned. | ||
| 40 | assert((uintptr_t)cmsg % alignof(struct cmsghdr) == 0 && | ||
| 41 | "Attempted to access unaligned control message header"); | ||
| 42 | |||
| 43 | // Safety belt: the computed starting address of the control message | ||
| 44 | // header may only lie inside the ancillary data buffer, or right | ||
| 45 | // after it in case we've reached the end of the buffer. | ||
| 46 | const unsigned char *begin = mhdr->msg_control; | ||
| 47 | const unsigned char *end = begin + mhdr->msg_controllen; | ||
| 48 | assert((unsigned char *)cmsg >= begin && | ||
| 49 | (unsigned char *)cmsg < end + alignof(struct cmsghdr) && | ||
| 50 | "Computed object outside of buffer boundaries"); | ||
| 51 | |||
| 52 | // Only return the control message header in case all of its fields | ||
| 53 | // lie within the ancillary data buffer. | ||
| 54 | return CMSG_DATA((struct cmsghdr *)cmsg) <= end ? cmsg : NULL; | ||
| 55 | } | ||
| 56 | |||
| 57 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | |||
| 10 | #include "stat_impl.h" | ||
| 11 | |||
| 12 | int fstat(int fildes, struct stat *buf) { | ||
| 13 | __wasi_filestat_t internal_stat; | ||
| 14 | __wasi_errno_t error = __wasi_fd_filestat_get(fildes, &internal_stat); | ||
| 15 | if (error != 0) { | ||
| 16 | errno = error; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | to_public_stat(&internal_stat, buf); | ||
| 20 | return 0; | ||
| 21 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | #include "stat_impl.h" | ||
| 13 | |||
| 14 | int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *restrict buf, | ||
| 15 | int flag) { | ||
| 16 | // Create lookup properties. | ||
| 17 | __wasi_lookupflags_t lookup_flags = 0; | ||
| 18 | if ((flag & AT_SYMLINK_NOFOLLOW) == 0) | ||
| 19 | lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 20 | |||
| 21 | // Perform system call. | ||
| 22 | __wasi_filestat_t internal_stat; | ||
| 23 | __wasi_errno_t error = | ||
| 24 | __wasi_path_filestat_get(fd, lookup_flags, path, &internal_stat); | ||
| 25 | if (error != 0) { | ||
| 26 | errno = error; | ||
| 27 | return -1; | ||
| 28 | } | ||
| 29 | to_public_stat(&internal_stat, buf); | ||
| 30 | return 0; | ||
| 31 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | |||
| 10 | #include "stat_impl.h" | ||
| 11 | |||
| 12 | int futimens(int fd, const struct timespec *times) { | ||
| 13 | // Convert timestamps and extract NOW/OMIT flags. | ||
| 14 | __wasi_timestamp_t st_atim; | ||
| 15 | __wasi_timestamp_t st_mtim; | ||
| 16 | __wasi_fstflags_t flags; | ||
| 17 | if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { | ||
| 18 | errno = EINVAL; | ||
| 19 | return -1; | ||
| 20 | } | ||
| 21 | |||
| 22 | // Perform system call. | ||
| 23 | __wasi_errno_t error = __wasi_fd_filestat_set_times(fd, st_atim, st_mtim, flags); | ||
| 24 | if (error != 0) { | ||
| 25 | errno = error; | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | return 0; | ||
| 29 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <string.h> | ||
| 10 | |||
| 11 | int __wasilibc_nocwd_mkdirat_nomode(int fd, const char *path) { | ||
| 12 | __wasi_errno_t error = __wasi_path_create_directory(fd, path); | ||
| 13 | if (error != 0) { | ||
| 14 | errno = error; | ||
| 15 | return -1; | ||
| 16 | } | ||
| 17 | return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h deleted-116| ... | @@ -1,116 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef SYS_STAT_STAT_IMPL_H | ||
| 6 | #define SYS_STAT_STAT_IMPL_H | ||
| 7 | |||
| 8 | #include <common/time.h> | ||
| 9 | |||
| 10 | #include <sys/stat.h> | ||
| 11 | |||
| 12 | #include <assert.h> | ||
| 13 | #include <wasi/api.h> | ||
| 14 | #include <stdbool.h> | ||
| 15 | |||
| 16 | static_assert(S_ISBLK(S_IFBLK), "Value mismatch"); | ||
| 17 | static_assert(S_ISCHR(S_IFCHR), "Value mismatch"); | ||
| 18 | static_assert(S_ISDIR(S_IFDIR), "Value mismatch"); | ||
| 19 | static_assert(S_ISFIFO(S_IFIFO), "Value mismatch"); | ||
| 20 | static_assert(S_ISLNK(S_IFLNK), "Value mismatch"); | ||
| 21 | static_assert(S_ISREG(S_IFREG), "Value mismatch"); | ||
| 22 | static_assert(S_ISSOCK(S_IFSOCK), "Value mismatch"); | ||
| 23 | |||
| 24 | static inline void to_public_stat(const __wasi_filestat_t *in, | ||
| 25 | struct stat *out) { | ||
| 26 | // Ensure that we don't truncate any values. | ||
| 27 | static_assert(sizeof(in->dev) == sizeof(out->st_dev), "Size mismatch"); | ||
| 28 | static_assert(sizeof(in->ino) == sizeof(out->st_ino), "Size mismatch"); | ||
| 29 | /* | ||
| 30 | * The non-standard __st_filetype field appears to only be used for shared | ||
| 31 | * memory, which we don't currently support. | ||
| 32 | */ | ||
| 33 | /* nlink_t is 64-bit on wasm32, following the x32 ABI. */ | ||
| 34 | static_assert(sizeof(in->nlink) <= sizeof(out->st_nlink), "Size shortfall"); | ||
| 35 | static_assert(sizeof(in->size) == sizeof(out->st_size), "Size mismatch"); | ||
| 36 | |||
| 37 | *out = (struct stat){ | ||
| 38 | .st_dev = in->dev, | ||
| 39 | .st_ino = in->ino, | ||
| 40 | .st_nlink = in->nlink, | ||
| 41 | .st_size = in->size, | ||
| 42 | .st_atim = timestamp_to_timespec(in->atim), | ||
| 43 | .st_mtim = timestamp_to_timespec(in->mtim), | ||
| 44 | .st_ctim = timestamp_to_timespec(in->ctim), | ||
| 45 | }; | ||
| 46 | |||
| 47 | // Convert file type to legacy types encoded in st_mode. | ||
| 48 | switch (in->filetype) { | ||
| 49 | case __WASI_FILETYPE_BLOCK_DEVICE: | ||
| 50 | out->st_mode |= S_IFBLK; | ||
| 51 | break; | ||
| 52 | case __WASI_FILETYPE_CHARACTER_DEVICE: | ||
| 53 | out->st_mode |= S_IFCHR; | ||
| 54 | break; | ||
| 55 | case __WASI_FILETYPE_DIRECTORY: | ||
| 56 | out->st_mode |= S_IFDIR; | ||
| 57 | break; | ||
| 58 | case __WASI_FILETYPE_REGULAR_FILE: | ||
| 59 | out->st_mode |= S_IFREG; | ||
| 60 | break; | ||
| 61 | case __WASI_FILETYPE_SOCKET_DGRAM: | ||
| 62 | case __WASI_FILETYPE_SOCKET_STREAM: | ||
| 63 | out->st_mode |= S_IFSOCK; | ||
| 64 | break; | ||
| 65 | case __WASI_FILETYPE_SYMBOLIC_LINK: | ||
| 66 | out->st_mode |= S_IFLNK; | ||
| 67 | break; | ||
| 68 | } | ||
| 69 | } | ||
| 70 | |||
| 71 | static inline bool utimens_get_timestamps(const struct timespec *times, | ||
| 72 | __wasi_timestamp_t *st_atim, | ||
| 73 | __wasi_timestamp_t *st_mtim, | ||
| 74 | __wasi_fstflags_t *flags) { | ||
| 75 | if (times == NULL) { | ||
| 76 | // Update both timestamps. | ||
| 77 | *flags = __WASI_FSTFLAGS_ATIM_NOW | __WASI_FSTFLAGS_MTIM_NOW; | ||
| 78 | *st_atim = (__wasi_timestamp_t) { 0 }; | ||
| 79 | *st_mtim = (__wasi_timestamp_t) { 0 }; | ||
| 80 | } else { | ||
| 81 | // Set individual timestamps. | ||
| 82 | *flags = 0; | ||
| 83 | switch (times[0].tv_nsec) { | ||
| 84 | case UTIME_NOW: | ||
| 85 | *flags |= __WASI_FSTFLAGS_ATIM_NOW; | ||
| 86 | *st_atim = (__wasi_timestamp_t) { 0 }; | ||
| 87 | break; | ||
| 88 | case UTIME_OMIT: | ||
| 89 | *st_atim = (__wasi_timestamp_t) { 0 }; | ||
| 90 | break; | ||
| 91 | default: | ||
| 92 | *flags |= __WASI_FSTFLAGS_ATIM; | ||
| 93 | if (!timespec_to_timestamp_exact(&times[0], st_atim)) | ||
| 94 | return false; | ||
| 95 | break; | ||
| 96 | } | ||
| 97 | |||
| 98 | switch (times[1].tv_nsec) { | ||
| 99 | case UTIME_NOW: | ||
| 100 | *flags |= __WASI_FSTFLAGS_MTIM_NOW; | ||
| 101 | *st_mtim = (__wasi_timestamp_t) { 0 }; | ||
| 102 | break; | ||
| 103 | case UTIME_OMIT: | ||
| 104 | *st_mtim = (__wasi_timestamp_t) { 0 }; | ||
| 105 | break; | ||
| 106 | default: | ||
| 107 | *flags |= __WASI_FSTFLAGS_MTIM; | ||
| 108 | if (!timespec_to_timestamp_exact(&times[1], st_mtim)) | ||
| 109 | return false; | ||
| 110 | break; | ||
| 111 | } | ||
| 112 | } | ||
| 113 | return true; | ||
| 114 | } | ||
| 115 | |||
| 116 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c deleted-38| ... | @@ -1,38 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | #include "stat_impl.h" | ||
| 13 | |||
| 14 | int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec times[2], | ||
| 15 | int flag) { | ||
| 16 | // Convert timestamps and extract NOW/OMIT flags. | ||
| 17 | __wasi_timestamp_t st_atim; | ||
| 18 | __wasi_timestamp_t st_mtim; | ||
| 19 | __wasi_fstflags_t flags; | ||
| 20 | if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { | ||
| 21 | errno = EINVAL; | ||
| 22 | return -1; | ||
| 23 | } | ||
| 24 | |||
| 25 | // Create lookup properties. | ||
| 26 | __wasi_lookupflags_t lookup_flags = 0; | ||
| 27 | if ((flag & AT_SYMLINK_NOFOLLOW) == 0) | ||
| 28 | lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 29 | |||
| 30 | // Perform system call. | ||
| 31 | __wasi_errno_t error = | ||
| 32 | __wasi_path_filestat_set_times(fd, lookup_flags, path, st_atim, st_mtim, flags); | ||
| 33 | if (error != 0) { | ||
| 34 | errno = error; | ||
| 35 | return -1; | ||
| 36 | } | ||
| 37 | return 0; | ||
| 38 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/time.h> | ||
| 6 | |||
| 7 | #include <sys/time.h> | ||
| 8 | |||
| 9 | #include <wasi/api.h> | ||
| 10 | |||
| 11 | int gettimeofday(struct timeval *restrict tp, void *tz) { | ||
| 12 | if (tp != NULL) { | ||
| 13 | __wasi_timestamp_t ts = 0; | ||
| 14 | (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); | ||
| 15 | *tp = timestamp_to_timeval(ts); | ||
| 16 | } | ||
| 17 | return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/uio.h> | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | |||
| 11 | ssize_t preadv(int fildes, const struct iovec *iov, int iovcnt, off_t offset) { | ||
| 12 | if (iovcnt < 0 || offset < 0) { | ||
| 13 | errno = EINVAL; | ||
| 14 | return -1; | ||
| 15 | } | ||
| 16 | size_t bytes_read; | ||
| 17 | __wasi_errno_t error = __wasi_fd_pread( | ||
| 18 | fildes, (const __wasi_iovec_t *)iov, iovcnt, offset, &bytes_read); | ||
| 19 | if (error != 0) { | ||
| 20 | errno = error; | ||
| 21 | return -1; | ||
| 22 | } | ||
| 23 | return bytes_read; | ||
| 24 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/types.h> | ||
| 6 | #include <sys/uio.h> | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | |||
| 11 | ssize_t pwritev(int fildes, const struct iovec *iov, int iovcnt, off_t offset) { | ||
| 12 | if (iovcnt < 0 || offset < 0) { | ||
| 13 | errno = EINVAL; | ||
| 14 | return -1; | ||
| 15 | } | ||
| 16 | size_t bytes_written; | ||
| 17 | __wasi_errno_t error = __wasi_fd_pwrite( | ||
| 18 | fildes, (const __wasi_ciovec_t *)iov, iovcnt, offset, &bytes_written); | ||
| 19 | if (error != 0) { | ||
| 20 | errno = error; | ||
| 21 | return -1; | ||
| 22 | } | ||
| 23 | return bytes_written; | ||
| 24 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/uio.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <stddef.h> | ||
| 11 | |||
| 12 | static_assert(offsetof(struct iovec, iov_base) == | ||
| 13 | offsetof(__wasi_iovec_t, buf), | ||
| 14 | "Offset mismatch"); | ||
| 15 | static_assert(sizeof(((struct iovec *)0)->iov_base) == | ||
| 16 | sizeof(((__wasi_iovec_t *)0)->buf), | ||
| 17 | "Size mismatch"); | ||
| 18 | static_assert(offsetof(struct iovec, iov_len) == | ||
| 19 | offsetof(__wasi_iovec_t, buf_len), | ||
| 20 | "Offset mismatch"); | ||
| 21 | static_assert(sizeof(((struct iovec *)0)->iov_len) == | ||
| 22 | sizeof(((__wasi_iovec_t *)0)->buf_len), | ||
| 23 | "Size mismatch"); | ||
| 24 | static_assert(sizeof(struct iovec) == sizeof(__wasi_iovec_t), | ||
| 25 | "Size mismatch"); | ||
| 26 | |||
| 27 | ssize_t readv(int fildes, const struct iovec *iov, int iovcnt) { | ||
| 28 | if (iovcnt < 0) { | ||
| 29 | errno = EINVAL; | ||
| 30 | return -1; | ||
| 31 | } | ||
| 32 | size_t bytes_read; | ||
| 33 | __wasi_errno_t error = __wasi_fd_read( | ||
| 34 | fildes, (const __wasi_iovec_t *)iov, iovcnt, &bytes_read); | ||
| 35 | if (error != 0) { | ||
| 36 | errno = error; | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | return bytes_read; | ||
| 40 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/uio.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <stddef.h> | ||
| 11 | |||
| 12 | static_assert(offsetof(struct iovec, iov_base) == | ||
| 13 | offsetof(__wasi_ciovec_t, buf), | ||
| 14 | "Offset mismatch"); | ||
| 15 | static_assert(sizeof(((struct iovec *)0)->iov_base) == | ||
| 16 | sizeof(((__wasi_ciovec_t *)0)->buf), | ||
| 17 | "Size mismatch"); | ||
| 18 | static_assert(offsetof(struct iovec, iov_len) == | ||
| 19 | offsetof(__wasi_ciovec_t, buf_len), | ||
| 20 | "Offset mismatch"); | ||
| 21 | static_assert(sizeof(((struct iovec *)0)->iov_len) == | ||
| 22 | sizeof(((__wasi_ciovec_t *)0)->buf_len), | ||
| 23 | "Size mismatch"); | ||
| 24 | static_assert(sizeof(struct iovec) == sizeof(__wasi_ciovec_t), | ||
| 25 | "Size mismatch"); | ||
| 26 | |||
| 27 | ssize_t writev(int fildes, const struct iovec *iov, int iovcnt) { | ||
| 28 | if (iovcnt < 0) { | ||
| 29 | errno = EINVAL; | ||
| 30 | return -1; | ||
| 31 | } | ||
| 32 | size_t bytes_written; | ||
| 33 | __wasi_errno_t error = __wasi_fd_write( | ||
| 34 | fildes, (const __wasi_ciovec_t *)iov, iovcnt, &bytes_written); | ||
| 35 | if (error != 0) { | ||
| 36 | errno = error; | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | return bytes_written; | ||
| 40 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | // Copyright (c) 2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/clock.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <time.h> | ||
| 9 | |||
| 10 | const struct __clockid _CLOCK_MONOTONIC = { | ||
| 11 | .id = __WASI_CLOCKID_MONOTONIC, | ||
| 12 | }; | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | // Copyright (c) 2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/clock.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <time.h> | ||
| 9 | |||
| 10 | const struct __clockid _CLOCK_REALTIME = { | ||
| 11 | .id = __WASI_CLOCKID_REALTIME, | ||
| 12 | }; | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/clock.h> | ||
| 6 | #include <common/time.h> | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <time.h> | ||
| 11 | |||
| 12 | int clock_getres(clockid_t clock_id, struct timespec *res) { | ||
| 13 | __wasi_timestamp_t ts; | ||
| 14 | __wasi_errno_t error = __wasi_clock_res_get(clock_id->id, &ts); | ||
| 15 | if (error != 0) { | ||
| 16 | errno = error; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | *res = timestamp_to_timespec(ts); | ||
| 20 | return 0; | ||
| 21 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/clock.h> | ||
| 6 | #include <common/time.h> | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <time.h> | ||
| 11 | |||
| 12 | int __clock_gettime(clockid_t clock_id, struct timespec *tp) { | ||
| 13 | __wasi_timestamp_t ts; | ||
| 14 | __wasi_errno_t error = __wasi_clock_time_get(clock_id->id, 1, &ts); | ||
| 15 | if (error != 0) { | ||
| 16 | errno = error; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | *tp = timestamp_to_timespec(ts); | ||
| 20 | return 0; | ||
| 21 | } | ||
| 22 | weak_alias(__clock_gettime, clock_gettime); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c deleted-37| ... | @@ -1,37 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/clock.h> | ||
| 6 | #include <common/time.h> | ||
| 7 | |||
| 8 | #include <assert.h> | ||
| 9 | #include <wasi/api.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <time.h> | ||
| 12 | |||
| 13 | static_assert(TIMER_ABSTIME == __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME, | ||
| 14 | "Value mismatch"); | ||
| 15 | |||
| 16 | int clock_nanosleep(clockid_t clock_id, int flags, const struct timespec *rqtp, | ||
| 17 | struct timespec *rmtp) { | ||
| 18 | if ((flags & ~TIMER_ABSTIME) != 0) | ||
| 19 | return EINVAL; | ||
| 20 | |||
| 21 | // Prepare polling subscription. | ||
| 22 | __wasi_subscription_t sub = { | ||
| 23 | .u.tag = __WASI_EVENTTYPE_CLOCK, | ||
| 24 | .u.u.clock.id = clock_id->id, | ||
| 25 | .u.u.clock.flags = flags, | ||
| 26 | }; | ||
| 27 | if (!timespec_to_timestamp_clamp(rqtp, &sub.u.u.clock.timeout)) | ||
| 28 | return EINVAL; | ||
| 29 | |||
| 30 | // Block until polling event is triggered. | ||
| 31 | size_t nevents; | ||
| 32 | __wasi_event_t ev; | ||
| 33 | __wasi_errno_t error = __wasi_poll_oneoff(&sub, &ev, 1, &nevents); | ||
| 34 | return error == 0 && ev.error == 0 ? 0 : ENOTSUP; | ||
| 35 | } | ||
| 36 | |||
| 37 | weak_alias(clock_nanosleep, __clock_nanosleep); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <errno.h> | ||
| 6 | #include <time.h> | ||
| 7 | |||
| 8 | int nanosleep(const struct timespec *rqtp, struct timespec *rem) { | ||
| 9 | int error = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rem); | ||
| 10 | if (error != 0) { | ||
| 11 | errno = error; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | return 0; | ||
| 15 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/time.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <time.h> | ||
| 9 | |||
| 10 | time_t time(time_t *tloc) { | ||
| 11 | __wasi_timestamp_t ts = 0; | ||
| 12 | (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, NSEC_PER_SEC, &ts); | ||
| 13 | if (tloc != NULL) | ||
| 14 | *tloc = ts / NSEC_PER_SEC; | ||
| 15 | return ts / NSEC_PER_SEC; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c deleted-53| ... | @@ -1,53 +0,0 @@ | ||
| 1 | // Copyright (c) 2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) { | ||
| 12 | // Validate function parameters. | ||
| 13 | if ((amode & ~(F_OK | R_OK | W_OK | X_OK)) != 0 || | ||
| 14 | (flag & ~AT_EACCESS) != 0) { | ||
| 15 | errno = EINVAL; | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | |||
| 19 | // Check for target file existence and obtain the file type. | ||
| 20 | __wasi_lookupflags_t lookup_flags = __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 21 | __wasi_filestat_t file; | ||
| 22 | __wasi_errno_t error = | ||
| 23 | __wasi_path_filestat_get(fd, lookup_flags, path, &file); | ||
| 24 | if (error != 0) { | ||
| 25 | errno = error; | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | |||
| 29 | // Test whether the requested access rights are present on the | ||
| 30 | // directory file descriptor. | ||
| 31 | if (amode != 0) { | ||
| 32 | __wasi_fdstat_t directory; | ||
| 33 | error = __wasi_fd_fdstat_get(fd, &directory); | ||
| 34 | if (error != 0) { | ||
| 35 | errno = error; | ||
| 36 | return -1; | ||
| 37 | } | ||
| 38 | |||
| 39 | __wasi_rights_t min = 0; | ||
| 40 | if ((amode & R_OK) != 0) | ||
| 41 | min |= file.filetype == __WASI_FILETYPE_DIRECTORY | ||
| 42 | ? __WASI_RIGHTS_FD_READDIR | ||
| 43 | : __WASI_RIGHTS_FD_READ; | ||
| 44 | if ((amode & W_OK) != 0) | ||
| 45 | min |= __WASI_RIGHTS_FD_WRITE; | ||
| 46 | |||
| 47 | if ((min & directory.fs_rights_inheriting) != min) { | ||
| 48 | errno = EACCES; | ||
| 49 | return -1; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | return 0; | ||
| 53 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | int fdatasync(int fildes) { | ||
| 10 | __wasi_errno_t error = __wasi_fd_datasync(fildes); | ||
| 11 | if (error != 0) { | ||
| 12 | errno = error == ENOTCAPABLE ? EBADF : error; | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | return 0; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | int fsync(int fildes) { | ||
| 10 | __wasi_errno_t error = __wasi_fd_sync(fildes); | ||
| 11 | if (error != 0) { | ||
| 12 | errno = error == ENOTCAPABLE ? EINVAL : error; | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | return 0; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | int ftruncate(int fildes, off_t length) { | ||
| 10 | if (length < 0) { | ||
| 11 | errno = EINVAL; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | __wasi_filesize_t st_size = length; | ||
| 15 | __wasi_errno_t error = | ||
| 16 | __wasi_fd_filestat_set_size(fildes, st_size); | ||
| 17 | if (error != 0) { | ||
| 18 | errno = error; | ||
| 19 | return -1; | ||
| 20 | } | ||
| 21 | return 0; | ||
| 22 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | int __wasilibc_nocwd_linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) { | ||
| 12 | // Create lookup properties. | ||
| 13 | __wasi_lookupflags_t lookup1_flags = 0; | ||
| 14 | if ((flag & AT_SYMLINK_FOLLOW) != 0) | ||
| 15 | lookup1_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 16 | |||
| 17 | // Perform system call. | ||
| 18 | __wasi_errno_t error = __wasi_path_link(fd1, lookup1_flags, path1, fd2, path2); | ||
| 19 | if (error != 0) { | ||
| 20 | errno = error; | ||
| 21 | return -1; | ||
| 22 | } | ||
| 23 | return 0; | ||
| 24 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <assert.h> | ||
| 6 | #include <wasi/api.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | |||
| 10 | static_assert(SEEK_CUR == __WASI_WHENCE_CUR, "Value mismatch"); | ||
| 11 | static_assert(SEEK_END == __WASI_WHENCE_END, "Value mismatch"); | ||
| 12 | static_assert(SEEK_SET == __WASI_WHENCE_SET, "Value mismatch"); | ||
| 13 | |||
| 14 | off_t __lseek(int fildes, off_t offset, int whence) { | ||
| 15 | __wasi_filesize_t new_offset; | ||
| 16 | __wasi_errno_t error = | ||
| 17 | __wasi_fd_seek(fildes, offset, whence, &new_offset); | ||
| 18 | if (error != 0) { | ||
| 19 | errno = error == ENOTCAPABLE ? ESPIPE : error; | ||
| 20 | return -1; | ||
| 21 | } | ||
| 22 | return new_offset; | ||
| 23 | } | ||
| 24 | |||
| 25 | weak_alias(__lseek, lseek); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | ssize_t pread(int fildes, void *buf, size_t nbyte, off_t offset) { | ||
| 10 | if (offset < 0) { | ||
| 11 | errno = EINVAL; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | __wasi_iovec_t iov = {.buf = buf, .buf_len = nbyte}; | ||
| 15 | size_t bytes_read; | ||
| 16 | __wasi_errno_t error = | ||
| 17 | __wasi_fd_pread(fildes, &iov, 1, offset, &bytes_read); | ||
| 18 | if (error != 0) { | ||
| 19 | __wasi_fdstat_t fds; | ||
| 20 | if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) { | ||
| 21 | // Determine why we got ENOTCAPABLE. | ||
| 22 | if ((fds.fs_rights_base & __WASI_RIGHTS_FD_READ) == 0) | ||
| 23 | error = EBADF; | ||
| 24 | else | ||
| 25 | error = ESPIPE; | ||
| 26 | } | ||
| 27 | errno = error; | ||
| 28 | return -1; | ||
| 29 | } | ||
| 30 | return bytes_read; | ||
| 31 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset) { | ||
| 10 | if (offset < 0) { | ||
| 11 | errno = EINVAL; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | __wasi_ciovec_t iov = {.buf = buf, .buf_len = nbyte}; | ||
| 15 | size_t bytes_written; | ||
| 16 | __wasi_errno_t error = | ||
| 17 | __wasi_fd_pwrite(fildes, &iov, 1, offset, &bytes_written); | ||
| 18 | if (error != 0) { | ||
| 19 | __wasi_fdstat_t fds; | ||
| 20 | if (error == ENOTCAPABLE && __wasi_fd_fdstat_get(fildes, &fds) == 0) { | ||
| 21 | // Determine why we got ENOTCAPABLE. | ||
| 22 | if ((fds.fs_rights_base & __WASI_RIGHTS_FD_WRITE) == 0) | ||
| 23 | error = EBADF; | ||
| 24 | else | ||
| 25 | error = ESPIPE; | ||
| 26 | } | ||
| 27 | errno = error; | ||
| 28 | return -1; | ||
| 29 | } | ||
| 30 | return bytes_written; | ||
| 31 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | ssize_t read(int fildes, void *buf, size_t nbyte) { | ||
| 10 | __wasi_iovec_t iov = {.buf = buf, .buf_len = nbyte}; | ||
| 11 | size_t bytes_read; | ||
| 12 | __wasi_errno_t error = __wasi_fd_read(fildes, &iov, 1, &bytes_read); | ||
| 13 | if (error != 0) { | ||
| 14 | errno = error == ENOTCAPABLE ? EBADF : error; | ||
| 15 | return -1; | ||
| 16 | } | ||
| 17 | return bytes_read; | ||
| 18 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | |||
| 10 | ssize_t __wasilibc_nocwd_readlinkat(int fd, const char *restrict path, char *restrict buf, | ||
| 11 | size_t bufsize) { | ||
| 12 | size_t bufused; | ||
| 13 | // TODO: Remove the cast on `buf` once the witx is updated with char8 support. | ||
| 14 | __wasi_errno_t error = __wasi_path_readlink(fd, path, | ||
| 15 | (uint8_t*)buf, bufsize, &bufused); | ||
| 16 | if (error != 0) { | ||
| 17 | errno = error; | ||
| 18 | return -1; | ||
| 19 | } | ||
| 20 | return bufused; | ||
| 21 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <time.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | |||
| 8 | unsigned int sleep(unsigned int seconds) { | ||
| 9 | struct timespec ts = {.tv_sec = seconds, .tv_nsec = 0}; | ||
| 10 | if (clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL) != 0) | ||
| 11 | return seconds; | ||
| 12 | return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | |||
| 10 | int __wasilibc_nocwd_symlinkat(const char *path1, int fd, const char *path2) { | ||
| 11 | __wasi_errno_t error = __wasi_path_symlink(path1, fd, path2); | ||
| 12 | if (error != 0) { | ||
| 13 | errno = error; | ||
| 14 | return -1; | ||
| 15 | } | ||
| 16 | return 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <wasi/libc.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <fcntl.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | int unlinkat(int fd, const char *path, int flag) { | ||
| 13 | if ((flag & AT_REMOVEDIR) != 0) { | ||
| 14 | return __wasilibc_rmdirat(fd, path); | ||
| 15 | } | ||
| 16 | return __wasilibc_unlinkat(fd, path); | ||
| 17 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | // Copyright (c) 2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <errno.h> | ||
| 6 | #include <time.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | int usleep(useconds_t useconds) { | ||
| 10 | struct timespec ts = {.tv_sec = useconds / 1000000, | ||
| 11 | .tv_nsec = useconds % 1000000 * 1000}; | ||
| 12 | int error = clock_nanosleep(CLOCK_REALTIME, 0, &ts, NULL); | ||
| 13 | if (error != 0) { | ||
| 14 | errno = error; | ||
| 15 | return -1; | ||
| 16 | } | ||
| 17 | return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <wasi/api.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | |||
| 9 | ssize_t write(int fildes, const void *buf, size_t nbyte) { | ||
| 10 | __wasi_ciovec_t iov = {.buf = buf, .buf_len = nbyte}; | ||
| 11 | size_t bytes_written; | ||
| 12 | __wasi_errno_t error = | ||
| 13 | __wasi_fd_write(fildes, &iov, 1, &bytes_written); | ||
| 14 | if (error != 0) { | ||
| 15 | errno = error == ENOTCAPABLE ? EBADF : error; | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | return bytes_written; | ||
| 19 | } | ||
lib/libc/wasi/libc-bottom-half/crt/crt1-command.c deleted-64| ... | @@ -1,64 +0,0 @@ | ||
| 1 | #ifdef _REENTRANT | ||
| 2 | #include <stdatomic.h> | ||
| 3 | extern void __wasi_init_tp(void); | ||
| 4 | #endif | ||
| 5 | #ifdef __wasilibc_use_wasip2 | ||
| 6 | #include <wasi/wasip2.h> | ||
| 7 | #else | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #endif | ||
| 10 | extern void __wasm_call_ctors(void); | ||
| 11 | extern int __main_void(void); | ||
| 12 | extern void __wasm_call_dtors(void); | ||
| 13 | |||
| 14 | __attribute__((export_name("_start"))) | ||
| 15 | void _start(void) { | ||
| 16 | // Commands should only be called once per instance. This simple check | ||
| 17 | // ensures that the `_start` function isn't started more than once. | ||
| 18 | // | ||
| 19 | // We use `volatile` here to prevent the store to `started` from being | ||
| 20 | // sunk past any subsequent code, and to prevent any compiler from | ||
| 21 | // optimizing based on the knowledge that `_start` is the program | ||
| 22 | // entrypoint. | ||
| 23 | #ifdef _REENTRANT | ||
| 24 | static volatile _Atomic int started = 0; | ||
| 25 | int expected = 0; | ||
| 26 | if (!atomic_compare_exchange_strong(&started, &expected, 1)) { | ||
| 27 | __builtin_trap(); | ||
| 28 | } | ||
| 29 | #else | ||
| 30 | static volatile int started = 0; | ||
| 31 | if (started != 0) { | ||
| 32 | __builtin_trap(); | ||
| 33 | } | ||
| 34 | started = 1; | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #ifdef _REENTRANT | ||
| 38 | __wasi_init_tp(); | ||
| 39 | #endif | ||
| 40 | |||
| 41 | // The linker synthesizes this to call constructors. | ||
| 42 | __wasm_call_ctors(); | ||
| 43 | |||
| 44 | // Call `__main_void` which will either be the application's zero-argument | ||
| 45 | // `__main_void` function or a libc routine which obtains the command-line | ||
| 46 | // arguments and calls `__main_argv_argc`. | ||
| 47 | int r = __main_void(); | ||
| 48 | |||
| 49 | // Call atexit functions, destructors, stdio cleanup, etc. | ||
| 50 | __wasm_call_dtors(); | ||
| 51 | |||
| 52 | // If main exited successfully, just return, otherwise call | ||
| 53 | // `__wasi_proc_exit`. | ||
| 54 | #ifdef __wasilibc_use_wasip2 | ||
| 55 | if (r != 0) { | ||
| 56 | exit_result_void_void_t status = { .is_err = true }; | ||
| 57 | exit_exit(&status); | ||
| 58 | } | ||
| 59 | #else | ||
| 60 | if (r != 0) { | ||
| 61 | __wasi_proc_exit(r); | ||
| 62 | } | ||
| 63 | #endif | ||
| 64 | } | ||
lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | #if defined(_REENTRANT) | ||
| 2 | #include <stdatomic.h> | ||
| 3 | extern void __wasi_init_tp(void); | ||
| 4 | #endif | ||
| 5 | extern void __wasm_call_ctors(void); | ||
| 6 | |||
| 7 | __attribute__((export_name("_initialize"))) | ||
| 8 | void _initialize(void) { | ||
| 9 | #if defined(_REENTRANT) | ||
| 10 | static volatile atomic_int initialized = 0; | ||
| 11 | int expected = 0; | ||
| 12 | if (!atomic_compare_exchange_strong(&initialized, &expected, 1)) { | ||
| 13 | __builtin_trap(); | ||
| 14 | } | ||
| 15 | |||
| 16 | __wasi_init_tp(); | ||
| 17 | #else | ||
| 18 | static volatile int initialized = 0; | ||
| 19 | if (initialized != 0) { | ||
| 20 | __builtin_trap(); | ||
| 21 | } | ||
| 22 | initialized = 1; | ||
| 23 | #endif | ||
| 24 | |||
| 25 | // The linker synthesizes this to call constructors. | ||
| 26 | __wasm_call_ctors(); | ||
| 27 | } | ||
lib/libc/wasi/libc-bottom-half/getpid/getpid.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | pid_t getpid(void) { | ||
| 4 | // Return an arbitrary value, greater than 1 which is special. | ||
| 5 | return 42; | ||
| 6 | } | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/limits.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <limits.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timespec.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__struct_timespec.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timeval.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__struct_timeval.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/types.h deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #include <_/cdefs.h> | ||
| 2 | #include <stddef.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <stdbool.h> | ||
| 5 | #include <stdarg.h> | ||
| 6 | #include <sys/types.h> | ||
| 7 | |||
| 8 | typedef uint64_t __uint64_t; | ||
| 9 | #define _UINT64_C UINT64_C | ||
lib/libc/wasi/libc-bottom-half/headers/private/assert.h deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | #ifndef __cplusplus | ||
| 4 | #define static_assert _Static_assert | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #define assert(x) ((void)((x) || (abort(), 0))) | ||
lib/libc/wasi/libc-bottom-half/headers/private/common/crt.h deletedlib/libc/wasi/libc-bottom-half/headers/private/errno.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include_next <errno.h> | ||
| 2 | #define EOPNOTSUPP ENOTSUP | ||
lib/libc/wasi/libc-bottom-half/headers/private/fcntl.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include_next <fcntl.h> | ||
| 2 | #include <_/types.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/sched.h deletedlib/libc/wasi/libc-bottom-half/headers/private/stdarg.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include_next <stdarg.h> | ||
| 2 | #include <_/cdefs.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/stdint.h deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #include_next <stdint.h> | ||
| 2 | |||
| 3 | #define __need_size_t | ||
| 4 | #include <stddef.h> | ||
| 5 | |||
| 6 | #include <__typedef_clock_t.h> | ||
| 7 | #include <__typedef_time_t.h> | ||
| 8 | #include <__typedef_blksize_t.h> | ||
| 9 | #include <__typedef_off_t.h> | ||
| 10 | #include <__typedef_ssize_t.h> | ||
| 11 | #include <__typedef_suseconds_t.h> | ||
| 12 | #include <__typedef_nlink_t.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/stdio.h deleted-3| ... | @@ -1,3 +0,0 @@ | ||
| 1 | #include <_/cdefs.h> | ||
| 2 | int snprintf(char *str, size_t size, const char *format, ...); | ||
| 3 | int rename(const char *oldpath, const char *newpath); | ||
lib/libc/wasi/libc-bottom-half/headers/private/stdlib.h deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #define __need_size_t | ||
| 2 | #define __need_wchar_t | ||
| 3 | #define __need_NULL | ||
| 4 | #include <stddef.h> | ||
| 5 | |||
| 6 | #include_next <stdlib.h> | ||
| 7 | |||
| 8 | int clearenv(void); | ||
lib/libc/wasi/libc-bottom-half/headers/private/string.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include_next <string.h> | ||
| 2 | #include <_/cdefs.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/sys/mman.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #include_next <sys/mman.h> | ||
| 2 | #include <_/types.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/threads.h deleted-3| ... | @@ -1,3 +0,0 @@ | ||
| 1 | #ifndef __cplusplus | ||
| 2 | #define thread_local _Thread_local | ||
| 3 | #endif | ||
lib/libc/wasi/libc-bottom-half/headers/private/wasi/descriptor_table.h deleted-127| ... | @@ -1,127 +0,0 @@ | ||
| 1 | #ifndef DESCRIPTOR_TABLE_H | ||
| 2 | #define DESCRIPTOR_TABLE_H | ||
| 3 | |||
| 4 | #include <wasi/wasip2.h> | ||
| 5 | |||
| 6 | typedef struct { | ||
| 7 | 	int dummy; | ||
| 8 | } tcp_socket_state_unbound_t; | ||
| 9 | typedef struct { | ||
| 10 | 	int dummy; | ||
| 11 | } tcp_socket_state_bound_t; | ||
| 12 | typedef struct { | ||
| 13 | 	int dummy; | ||
| 14 | } tcp_socket_state_connecting_t; | ||
| 15 | typedef struct { | ||
| 16 | 	int dummy; | ||
| 17 | } tcp_socket_state_listening_t; | ||
| 18 | |||
| 19 | typedef struct { | ||
| 20 | 	streams_own_input_stream_t input; | ||
| 21 | 	poll_own_pollable_t input_pollable; | ||
| 22 | 	streams_own_output_stream_t output; | ||
| 23 | 	poll_own_pollable_t output_pollable; | ||
| 24 | } tcp_socket_state_connected_t; | ||
| 25 | |||
| 26 | typedef struct { | ||
| 27 | 	network_error_code_t error_code; | ||
| 28 | } tcp_socket_state_connect_failed_t; | ||
| 29 | |||
| 30 | // This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. | ||
| 31 | typedef struct { | ||
| 32 | 	enum { | ||
| 33 | 		TCP_SOCKET_STATE_UNBOUND, | ||
| 34 | 		TCP_SOCKET_STATE_BOUND, | ||
| 35 | 		TCP_SOCKET_STATE_CONNECTING, | ||
| 36 | 		TCP_SOCKET_STATE_CONNECTED, | ||
| 37 | 		TCP_SOCKET_STATE_CONNECT_FAILED, | ||
| 38 | 		TCP_SOCKET_STATE_LISTENING, | ||
| 39 | 	} tag; | ||
| 40 | 	union { | ||
| 41 | 		tcp_socket_state_unbound_t unbound; | ||
| 42 | 		tcp_socket_state_bound_t bound; | ||
| 43 | 		tcp_socket_state_connecting_t connecting; | ||
| 44 | 		tcp_socket_state_connected_t connected; | ||
| 45 | 		tcp_socket_state_connect_failed_t connect_failed; | ||
| 46 | 		tcp_socket_state_listening_t listening; | ||
| 47 | 	}; | ||
| 48 | } tcp_socket_state_t; | ||
| 49 | |||
| 50 | typedef struct { | ||
| 51 | 	tcp_own_tcp_socket_t socket; | ||
| 52 | 	poll_own_pollable_t socket_pollable; | ||
| 53 | 	bool blocking; | ||
| 54 | 	bool fake_nodelay; | ||
| 55 | 	bool fake_reuseaddr; | ||
| 56 | 	network_ip_address_family_t family; | ||
| 57 | 	tcp_socket_state_t state; | ||
| 58 | } tcp_socket_t; | ||
| 59 | |||
| 60 | typedef struct { | ||
| 61 | 	udp_own_incoming_datagram_stream_t incoming; | ||
| 62 | 	poll_own_pollable_t incoming_pollable; | ||
| 63 | 	udp_own_outgoing_datagram_stream_t outgoing; | ||
| 64 | 	poll_own_pollable_t outgoing_pollable; | ||
| 65 | } udp_socket_streams_t; | ||
| 66 | |||
| 67 | typedef struct { | ||
| 68 | 	int dummy; | ||
| 69 | } udp_socket_state_unbound_t; | ||
| 70 | typedef struct { | ||
| 71 | 	int dummy; | ||
| 72 | } udp_socket_state_bound_nostreams_t; | ||
| 73 | |||
| 74 | typedef struct { | ||
| 75 | 	udp_socket_streams_t streams; // Streams have no remote_address | ||
| 76 | } udp_socket_state_bound_streaming_t; | ||
| 77 | |||
| 78 | typedef struct { | ||
| 79 | 	udp_socket_streams_t streams; // Streams have a remote_address | ||
| 80 | } udp_socket_state_connected_t; | ||
| 81 | |||
| 82 | // This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. | ||
| 83 | // The "bound" state is split up into two distinct tags: | ||
| 84 | // - "bound_nostreams": Bound, but no datagram streams set up (yet). That will be done the first time send or recv is called. | ||
| 85 | // - "bound_streaming": Bound with active streams. | ||
| 86 | typedef struct { | ||
| 87 | 	enum { | ||
| 88 | 		UDP_SOCKET_STATE_UNBOUND, | ||
| 89 | 		UDP_SOCKET_STATE_BOUND_NOSTREAMS, | ||
| 90 | 		UDP_SOCKET_STATE_BOUND_STREAMING, | ||
| 91 | 		UDP_SOCKET_STATE_CONNECTED, | ||
| 92 | 	} tag; | ||
| 93 | 	union { | ||
| 94 | 		udp_socket_state_unbound_t unbound; | ||
| 95 | 		udp_socket_state_bound_nostreams_t bound_nostreams; | ||
| 96 | 		udp_socket_state_bound_streaming_t bound_streaming; | ||
| 97 | 		udp_socket_state_connected_t connected; | ||
| 98 | 	}; | ||
| 99 | } udp_socket_state_t; | ||
| 100 | |||
| 101 | typedef struct { | ||
| 102 | 	udp_own_udp_socket_t socket; | ||
| 103 | 	poll_own_pollable_t socket_pollable; | ||
| 104 | 	bool blocking; | ||
| 105 | 	network_ip_address_family_t family; | ||
| 106 | 	udp_socket_state_t state; | ||
| 107 | } udp_socket_t; | ||
| 108 | |||
| 109 | // This is a tagged union. When adding/removing/renaming cases, be sure to keep the tag and union definitions in sync. | ||
| 110 | typedef struct { | ||
| 111 | 	enum { | ||
| 112 | 		DESCRIPTOR_TABLE_ENTRY_TCP_SOCKET, | ||
| 113 | 		DESCRIPTOR_TABLE_ENTRY_UDP_SOCKET, | ||
| 114 | 	} tag; | ||
| 115 | 	union { | ||
| 116 | 		tcp_socket_t tcp_socket; | ||
| 117 | 		udp_socket_t udp_socket; | ||
| 118 | 	}; | ||
| 119 | } descriptor_table_entry_t; | ||
| 120 | |||
| 121 | bool descriptor_table_insert(descriptor_table_entry_t entry, int *fd); | ||
| 122 | |||
| 123 | bool descriptor_table_get_ref(int fd, descriptor_table_entry_t **entry); | ||
| 124 | |||
| 125 | bool descriptor_table_remove(int fd, descriptor_table_entry_t *entry); | ||
| 126 | |||
| 127 | #endif | ||
lib/libc/wasi/libc-bottom-half/headers/private/wasi/sockets_utils.h deleted-67| ... | @@ -1,67 +0,0 @@ | ||
| 1 | #ifndef __wasi_sockets_utils_h | ||
| 2 | #define __wasi_sockets_utils_h | ||
| 3 | |||
| 4 | #include <netinet/in.h> | ||
| 5 | |||
| 6 | #include <wasi/descriptor_table.h> | ||
| 7 | |||
| 8 | typedef struct { | ||
| 9 | 	enum { | ||
| 10 | 		OUTPUT_SOCKADDR_NULL, | ||
| 11 | 		OUTPUT_SOCKADDR_V4, | ||
| 12 | 		OUTPUT_SOCKADDR_V6, | ||
| 13 | 	} tag; | ||
| 14 | 	union { | ||
| 15 | 		struct { | ||
| 16 | 			int dummy; | ||
| 17 | 		} null; | ||
| 18 | 		struct { | ||
| 19 | 			struct sockaddr_in *addr; | ||
| 20 | 			socklen_t *addrlen; | ||
| 21 | 		} v4; | ||
| 22 | 		struct { | ||
| 23 | 			struct sockaddr_in6 *addr; | ||
| 24 | 			socklen_t *addrlen; | ||
| 25 | 		} v6; | ||
| 26 | 	}; | ||
| 27 | } output_sockaddr_t; | ||
| 28 | |||
| 29 | typedef struct { | ||
| 30 | 	char *s_name; | ||
| 31 | 	uint16_t port; | ||
| 32 | 	uint16_t protocol; | ||
| 33 | } service_entry_t; | ||
| 34 | |||
| 35 | typedef enum { | ||
| 36 | 	SERVICE_PROTOCOL_TCP = 1, | ||
| 37 | 	SERVICE_PROTOCOL_UDP = 2 | ||
| 38 | } service_protocol_e; | ||
| 39 | |||
| 40 | network_borrow_network_t __wasi_sockets_utils__borrow_network(); | ||
| 41 | int __wasi_sockets_utils__map_error(network_error_code_t wasi_error); | ||
| 42 | bool __wasi_sockets_utils__parse_address( | ||
| 43 | 	network_ip_address_family_t expected_family, | ||
| 44 | 	const struct sockaddr *address, socklen_t len, | ||
| 45 | 	network_ip_socket_address_t *result, int *error); | ||
| 46 | bool __wasi_sockets_utils__output_addr_validate( | ||
| 47 | 	network_ip_address_family_t expected_family, struct sockaddr *addr, | ||
| 48 | 	socklen_t *addrlen, output_sockaddr_t *result); | ||
| 49 | void __wasi_sockets_utils__output_addr_write( | ||
| 50 | 	const network_ip_socket_address_t input, output_sockaddr_t *output); | ||
| 51 | int __wasi_sockets_utils__posix_family(network_ip_address_family_t wasi_family); | ||
| 52 | network_ip_socket_address_t | ||
| 53 | __wasi_sockets_utils__any_addr(network_ip_address_family_t family); | ||
| 54 | int __wasi_sockets_utils__tcp_bind(tcp_socket_t *socket, | ||
| 55 | 				 network_ip_socket_address_t *address); | ||
| 56 | int __wasi_sockets_utils__udp_bind(udp_socket_t *socket, | ||
| 57 | 				 network_ip_socket_address_t *address); | ||
| 58 | bool __wasi_sockets_utils__stream(udp_socket_t *socket, | ||
| 59 | 				 network_ip_socket_address_t *remote_address, | ||
| 60 | 				 udp_socket_streams_t *result, | ||
| 61 | 				 network_error_code_t *error); | ||
| 62 | void __wasi_sockets_utils__drop_streams(udp_socket_streams_t streams); | ||
| 63 | int __wasi_sockets_utils__parse_port(const char *port); | ||
| 64 | const service_entry_t *__wasi_sockets_utils__get_service_entry_by_name(const char *name); | ||
| 65 | const service_entry_t *__wasi_sockets_utils__get_service_entry_by_port(const uint16_t port); | ||
| 66 | |||
| 67 | #endif | ||
lib/libc/wasi/libc-bottom-half/mman/mman.c deleted-157| ... | @@ -1,157 +0,0 @@ | ||
| 1 | // Userspace emulation of mmap and munmap. Restrictions apply. | ||
| 2 | // | ||
| 3 | // This is meant to be complete enough to be compatible with code that uses | ||
| 4 | // mmap for simple file I/O. It just allocates memory with malloc and reads | ||
| 5 | // and writes data with pread and pwrite. | ||
| 6 | |||
| 7 | #define _WASI_EMULATED_MMAN | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <limits.h> | ||
| 13 | #include <sys/mman.h> | ||
| 14 | #include <sys/types.h> | ||
| 15 | |||
| 16 | struct map { | ||
| 17 | int prot; | ||
| 18 | int flags; | ||
| 19 | off_t offset; | ||
| 20 | size_t length; | ||
| 21 | }; | ||
| 22 | |||
| 23 | void *mmap(void *addr, size_t length, int prot, int flags, | ||
| 24 | int fd, off_t offset) { | ||
| 25 | // Check for unsupported flags. | ||
| 26 | if ((flags & (MAP_PRIVATE | MAP_SHARED)) == 0 || | ||
| 27 | (flags & MAP_FIXED) != 0 || | ||
| 28 | #ifdef MAP_SHARED_VALIDATE | ||
| 29 | (flags & MAP_SHARED_VALIDATE) == MAP_SHARED_VALIDATE || | ||
| 30 | #endif | ||
| 31 | #ifdef MAP_NORESERVE | ||
| 32 | (flags & MAP_NORESERVE) != 0 || | ||
| 33 | #endif | ||
| 34 | #ifdef MAP_GROWSDOWN | ||
| 35 | (flags & MAP_GROWSDOWN) != 0 || | ||
| 36 | #endif | ||
| 37 | #ifdef MAP_HUGETLB | ||
| 38 | (flags & MAP_HUGETLB) != 0 || | ||
| 39 | #endif | ||
| 40 | #ifdef MAP_FIXED_NOREPLACE | ||
| 41 | (flags & MAP_FIXED_NOREPLACE) != 0 || | ||
| 42 | #endif | ||
| 43 | 0) | ||
| 44 | { | ||
| 45 | errno = EINVAL; | ||
| 46 | return MAP_FAILED; | ||
| 47 | } | ||
| 48 | |||
| 49 | // Check for unsupported protection requests. | ||
| 50 | if (prot == PROT_NONE || | ||
| 51 | #ifdef PROT_EXEC | ||
| 52 | (prot & PROT_EXEC) != 0 || | ||
| 53 | #endif | ||
| 54 | 0) | ||
| 55 | { | ||
| 56 | errno = EINVAL; | ||
| 57 | return MAP_FAILED; | ||
| 58 | } | ||
| 59 | |||
| 60 | // To be consistent with POSIX. | ||
| 61 | if (length == 0) { | ||
| 62 | errno = EINVAL; | ||
| 63 | return MAP_FAILED; | ||
| 64 | } | ||
| 65 | |||
| 66 | // Check for integer overflow. | ||
| 67 | size_t buf_len = 0; | ||
| 68 | if (__builtin_add_overflow(length, sizeof(struct map), &buf_len)) { | ||
| 69 | errno = ENOMEM; | ||
| 70 | return MAP_FAILED; | ||
| 71 | } | ||
| 72 | |||
| 73 | // Allocate the memory. | ||
| 74 | struct map *map = malloc(buf_len); | ||
| 75 | if (!map) { | ||
| 76 | errno = ENOMEM; | ||
| 77 | return MAP_FAILED; | ||
| 78 | } | ||
| 79 | |||
| 80 | // Initialize the header. | ||
| 81 | map->prot = prot; | ||
| 82 | map->flags = flags; | ||
| 83 | map->offset = offset; | ||
| 84 | map->length = length; | ||
| 85 | |||
| 86 | // Initialize the main memory buffer, either with the contents of a file, | ||
| 87 | // or with zeros. | ||
| 88 | addr = map + 1; | ||
| 89 | if ((flags & MAP_ANON) == 0) { | ||
| 90 | char *body = (char *)addr; | ||
| 91 | while (length > 0) { | ||
| 92 | const ssize_t nread = pread(fd, body, length, offset); | ||
| 93 | if (nread < 0) { | ||
| 94 | if (errno == EINTR) | ||
| 95 | continue; | ||
| 96 | return MAP_FAILED; | ||
| 97 | } | ||
| 98 | if (nread == 0) | ||
| 99 | break; | ||
| 100 | length -= (size_t)nread; | ||
| 101 | offset += (size_t)nread; | ||
| 102 | body += (size_t)nread; | ||
| 103 | } | ||
| 104 | } else { | ||
| 105 | memset(addr, 0, length); | ||
| 106 | } | ||
| 107 | |||
| 108 | return addr; | ||
| 109 | } | ||
| 110 | |||
| 111 | int munmap(void *addr, size_t length) { | ||
| 112 | struct map *map = (struct map *)addr - 1; | ||
| 113 | |||
| 114 | // We don't support partial munmapping. | ||
| 115 | if (map->length != length) { | ||
| 116 | errno = EINVAL; | ||
| 117 | return -1; | ||
| 118 | } | ||
| 119 | |||
| 120 | // Release the memory. | ||
| 121 | free(map); | ||
| 122 | |||
| 123 | // Success! | ||
| 124 | return 0; | ||
| 125 | } | ||
| 126 | |||
| 127 | int mprotect(void *addr, size_t length, int prot) { | ||
| 128 | // Address must be page-aligned. | ||
| 129 | size_t begin = (size_t)addr; | ||
| 130 | if ((begin & (PAGESIZE - 1)) != 0) { | ||
| 131 | errno = EINVAL; | ||
| 132 | return -1; | ||
| 133 | } | ||
| 134 | |||
| 135 | // Length must not be big enough to wrap around. | ||
| 136 | size_t end; | ||
| 137 | if (__builtin_add_overflow(begin, length, &end)) { | ||
| 138 | errno = ENOMEM; | ||
| 139 | return -1; | ||
| 140 | } | ||
| 141 | |||
| 142 | // Range must be in bounds of linear memory. | ||
| 143 | size_t memory_size = __builtin_wasm_memory_size(0) * PAGESIZE; | ||
| 144 | if (end > memory_size) { | ||
| 145 | errno = ENOMEM; | ||
| 146 | return -1; | ||
| 147 | } | ||
| 148 | |||
| 149 | // Can only protect memory as read/write (which is a no-op). | ||
| 150 | if (prot != (PROT_READ | PROT_WRITE)) { | ||
| 151 | errno = ENOTSUP; | ||
| 152 | return -1; | ||
| 153 | } | ||
| 154 | |||
| 155 | // Success! | ||
| 156 | return 0; | ||
| 157 | } | ||
lib/libc/wasi/libc-bottom-half/signal/signal.c deleted-142| ... | @@ -1,142 +0,0 @@ | ||
| 1 | // Userspace emulation of `raise` and `signal`. | ||
| 2 | // | ||
| 3 | // WebAssembly doesn't support asynchronous signal delivery, so we can't | ||
| 4 | // support it in WASI libc. But we can make things like `raise` work. | ||
| 5 | |||
| 6 | #define _WASI_EMULATED_SIGNAL | ||
| 7 | #define _ALL_SOURCE | ||
| 8 | #define _GNU_SOURCE | ||
| 9 | #include <signal.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <errno.h> | ||
| 13 | #include <string.h> | ||
| 14 | #include <assert.h> | ||
| 15 | |||
| 16 | void __SIG_IGN(int sig) { | ||
| 17 | // do nothing | ||
| 18 | } | ||
| 19 | |||
| 20 | _Noreturn | ||
| 21 | void __SIG_ERR(int sig) { | ||
| 22 | __builtin_trap(); | ||
| 23 | } | ||
| 24 | |||
| 25 | _Noreturn | ||
| 26 | static void core_handler(int sig) { | ||
| 27 | fprintf(stderr, "Program received fatal signal: %s\n", strsignal(sig)); | ||
| 28 | abort(); | ||
| 29 | } | ||
| 30 | |||
| 31 | _Noreturn | ||
| 32 | static void terminate_handler(int sig) { | ||
| 33 | fprintf(stderr, "Program received termination signal: %s\n", strsignal(sig)); | ||
| 34 | abort(); | ||
| 35 | } | ||
| 36 | |||
| 37 | _Noreturn | ||
| 38 | static void stop_handler(int sig) { | ||
| 39 | fprintf(stderr, "Program received stop signal: %s\n", strsignal(sig)); | ||
| 40 | abort(); | ||
| 41 | } | ||
| 42 | |||
| 43 | static void continue_handler(int sig) { | ||
| 44 | // do nothing | ||
| 45 | } | ||
| 46 | |||
| 47 | static const sighandler_t default_handlers[_NSIG] = { | ||
| 48 | // Default behavior: "core". | ||
| 49 | [SIGABRT] = core_handler, | ||
| 50 | [SIGBUS] = core_handler, | ||
| 51 | [SIGFPE] = core_handler, | ||
| 52 | [SIGILL] = core_handler, | ||
| 53 | #if SIGIOT != SIGABRT | ||
| 54 | [SIGIOT] = core_handler, | ||
| 55 | #endif | ||
| 56 | [SIGQUIT] = core_handler, | ||
| 57 | [SIGSEGV] = core_handler, | ||
| 58 | [SIGSYS] = core_handler, | ||
| 59 | [SIGTRAP] = core_handler, | ||
| 60 | [SIGXCPU] = core_handler, | ||
| 61 | [SIGXFSZ] = core_handler, | ||
| 62 | #if defined(SIGUNUSED) && SIGUNUSED != SIGSYS | ||
| 63 | [SIGUNUSED] = core_handler, | ||
| 64 | #endif | ||
| 65 | |||
| 66 | // Default behavior: ignore. | ||
| 67 | [SIGCHLD] = SIG_IGN, | ||
| 68 | #if defined(SIGCLD) && SIGCLD != SIGCHLD | ||
| 69 | [SIGCLD] = SIG_IGN, | ||
| 70 | #endif | ||
| 71 | [SIGURG] = SIG_IGN, | ||
| 72 | [SIGWINCH] = SIG_IGN, | ||
| 73 | |||
| 74 | // Default behavior: "continue". | ||
| 75 | [SIGCONT] = continue_handler, | ||
| 76 | |||
| 77 | // Default behavior: "stop". | ||
| 78 | [SIGSTOP] = stop_handler, | ||
| 79 | [SIGTSTP] = stop_handler, | ||
| 80 | [SIGTTIN] = stop_handler, | ||
| 81 | [SIGTTOU] = stop_handler, | ||
| 82 | |||
| 83 | // Default behavior: "terminate". | ||
| 84 | [SIGHUP] = terminate_handler, | ||
| 85 | [SIGINT] = terminate_handler, | ||
| 86 | [SIGKILL] = terminate_handler, | ||
| 87 | [SIGUSR1] = terminate_handler, | ||
| 88 | [SIGUSR2] = terminate_handler, | ||
| 89 | [SIGPIPE] = terminate_handler, | ||
| 90 | [SIGALRM] = terminate_handler, | ||
| 91 | [SIGTERM] = terminate_handler, | ||
| 92 | [SIGSTKFLT] = terminate_handler, | ||
| 93 | [SIGVTALRM] = terminate_handler, | ||
| 94 | [SIGPROF] = terminate_handler, | ||
| 95 | [SIGIO] = terminate_handler, | ||
| 96 | #if SIGPOLL != SIGIO | ||
| 97 | [SIGPOLL] = terminate_handler, | ||
| 98 | #endif | ||
| 99 | [SIGPWR] = terminate_handler, | ||
| 100 | }; | ||
| 101 | |||
| 102 | static sighandler_t handlers[_NSIG]; | ||
| 103 | |||
| 104 | int raise(int sig) { | ||
| 105 | if (sig < 0 || sig >= _NSIG) { | ||
| 106 | errno = EINVAL; | ||
| 107 | return -1; | ||
| 108 | } | ||
| 109 | |||
| 110 | sighandler_t func = handlers[sig]; | ||
| 111 | |||
| 112 | if (func == NULL) { | ||
| 113 | default_handlers[sig](sig); | ||
| 114 | } else { | ||
| 115 | func(sig); | ||
| 116 | } | ||
| 117 | |||
| 118 | return 0; | ||
| 119 | } | ||
| 120 | |||
| 121 | void (*signal(int sig, void (*func)(int)))(int) { | ||
| 122 | assert(SIG_DFL == NULL); | ||
| 123 | |||
| 124 | if (sig < 0 || sig >= _NSIG) { | ||
| 125 | errno = EINVAL; | ||
| 126 | return SIG_ERR; | ||
| 127 | } | ||
| 128 | |||
| 129 | if (sig == SIGKILL || sig == SIGSTOP) { | ||
| 130 | errno = EINVAL; | ||
| 131 | return SIG_ERR; | ||
| 132 | } | ||
| 133 | |||
| 134 | sighandler_t old = handlers[sig]; | ||
| 135 | |||
| 136 | handlers[sig] = func; | ||
| 137 | |||
| 138 | return old; | ||
| 139 | } | ||
| 140 | |||
| 141 | extern __typeof(signal) bsd_signal __attribute__((weak, alias("signal"))); | ||
| 142 | extern __typeof(signal) __sysv_signal __attribute__((weak, alias("signal"))); | ||
lib/libc/wasi/libc-bottom-half/sources/__errno_location.c deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | |||
| 3 | int *__errno_location(void) { | ||
| 4 | return &errno; | ||
| 5 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__main_void.c deleted-110| ... | @@ -1,110 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_use_wasip2 | ||
| 2 | #include <wasi/wasip2.h> | ||
| 3 | #else | ||
| 4 | #include <wasi/api.h> | ||
| 5 | #endif | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <sysexits.h> | ||
| 8 | |||
| 9 | // The user's `main` function, expecting arguments. | ||
| 10 | // | ||
| 11 | // Note that we make this a weak symbol so that it will have a | ||
| 12 | // `WASM_SYM_BINDING_WEAK` flag in libc.so, which tells the dynamic linker that | ||
| 13 | // it need not be defined (e.g. in reactor-style apps with no main function). | ||
| 14 | // See also the TODO comment on `__main_void` below. | ||
| 15 | __attribute__((__weak__)) | ||
| 16 | int __main_argc_argv(int argc, char *argv[]); | ||
| 17 | |||
| 18 | // If the user's `main` function expects arguments, the compiler will rename | ||
| 19 | // it to `__main_argc_argv`, and this version will get linked in, which | ||
| 20 | // initializes the argument data and calls `__main_argc_argv`. | ||
| 21 | // | ||
| 22 | // TODO: Ideally this function would be defined in a crt*.o file and linked in | ||
| 23 | // as necessary by the Clang driver. However, moving it to crt1-command.c | ||
| 24 | // breaks `--no-gc-sections`, so we'll probably need to create a new file | ||
| 25 | // (e.g. crt0.o or crtend.o) and teach Clang to use it when needed. | ||
| 26 | __attribute__((__weak__, nodebug)) | ||
| 27 | int __main_void(void) { | ||
| 28 | #ifdef __wasilibc_use_wasip2 | ||
| 29 | wasip2_list_string_t argument_list; | ||
| 30 | |||
| 31 | environment_get_arguments(&argument_list); | ||
| 32 | |||
| 33 | // Add 1 for the NULL pointer to mark the end, and check for overflow. | ||
| 34 | size_t argc = argument_list.len; | ||
| 35 | size_t num_ptrs = argc + 1; | ||
| 36 | if (num_ptrs == 0) { | ||
| 37 | wasip2_list_string_free(&argument_list); | ||
| 38 | _Exit(EX_SOFTWARE); | ||
| 39 | } | ||
| 40 | |||
| 41 | // Allocate memory for the array of pointers. This uses `calloc` both to | ||
| 42 | // handle overflow and to initialize the NULL pointer at the end. | ||
| 43 | char **argv = calloc(num_ptrs, sizeof(char *)); | ||
| 44 | if (argv == NULL) { | ||
| 45 | wasip2_list_string_free(&argument_list); | ||
| 46 | _Exit(EX_SOFTWARE); | ||
| 47 | } | ||
| 48 | |||
| 49 | // Copy the arguments | ||
| 50 | for (size_t i = 0; i < argc; i++) { | ||
| 51 | wasip2_string_t wasi_string = argument_list.ptr[i]; | ||
| 52 | size_t len = wasi_string.len; | ||
| 53 | argv[i] = malloc(len + 1); | ||
| 54 | if (!argv[i]) { | ||
| 55 | wasip2_list_string_free(&argument_list); | ||
| 56 | _Exit(EX_SOFTWARE); | ||
| 57 | } | ||
| 58 | memcpy(argv[i], wasi_string.ptr, len); | ||
| 59 | argv[i][len] = '\0'; | ||
| 60 | } | ||
| 61 | |||
| 62 | // Free the WASI argument list | ||
| 63 | wasip2_list_string_free(&argument_list); | ||
| 64 | |||
| 65 | // Call `__main_argc_argv` with the arguments! | ||
| 66 | return __main_argc_argv(argc, argv); | ||
| 67 | #else | ||
| 68 | __wasi_errno_t err; | ||
| 69 | |||
| 70 | // Get the sizes of the arrays we'll have to create to copy in the args. | ||
| 71 | size_t argv_buf_size; | ||
| 72 | size_t argc; | ||
| 73 | err = __wasi_args_sizes_get(&argc, &argv_buf_size); | ||
| 74 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 75 | _Exit(EX_OSERR); | ||
| 76 | } | ||
| 77 | |||
| 78 | // Add 1 for the NULL pointer to mark the end, and check for overflow. | ||
| 79 | size_t num_ptrs = argc + 1; | ||
| 80 | if (num_ptrs == 0) { | ||
| 81 | _Exit(EX_SOFTWARE); | ||
| 82 | } | ||
| 83 | |||
| 84 | // Allocate memory for storing the argument chars. | ||
| 85 | char *argv_buf = malloc(argv_buf_size); | ||
| 86 | if (argv_buf == NULL) { | ||
| 87 | _Exit(EX_SOFTWARE); | ||
| 88 | } | ||
| 89 | |||
| 90 | // Allocate memory for the array of pointers. This uses `calloc` both to | ||
| 91 | // handle overflow and to initialize the NULL pointer at the end. | ||
| 92 | char **argv = calloc(num_ptrs, sizeof(char *)); | ||
| 93 | if (argv == NULL) { | ||
| 94 | free(argv_buf); | ||
| 95 | _Exit(EX_SOFTWARE); | ||
| 96 | } | ||
| 97 | |||
| 98 | // Fill the argument chars, and the argv array with pointers into those chars. | ||
| 99 | // TODO: Remove the casts on `argv_ptrs` and `argv_buf` once the witx is updated with char8 support. | ||
| 100 | err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf); | ||
| 101 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 102 | free(argv_buf); | ||
| 103 | free(argv); | ||
| 104 | _Exit(EX_OSERR); | ||
| 105 | } | ||
| 106 | |||
| 107 | // Call `__main_argc_argv` with the arguments! | ||
| 108 | return __main_argc_argv(argc, argv); | ||
| 109 | #endif | ||
| 110 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_dt.c deleted-34| ... | @@ -1,34 +0,0 @@ | ||
| 1 | #include <__header_dirent.h> | ||
| 2 | #include <__mode_t.h> | ||
| 3 | |||
| 4 | int __wasilibc_iftodt(int x) { | ||
| 5 | switch (x) { | ||
| 6 | case S_IFDIR: return DT_DIR; | ||
| 7 | case S_IFCHR: return DT_CHR; | ||
| 8 | case S_IFBLK: return DT_BLK; | ||
| 9 | case S_IFREG: return DT_REG; | ||
| 10 | case S_IFIFO: return DT_FIFO; | ||
| 11 | case S_IFLNK: return DT_LNK; | ||
| 12 | #ifdef DT_SOCK | ||
| 13 | case S_IFSOCK: return DT_SOCK; | ||
| 14 | #endif | ||
| 15 | default: return DT_UNKNOWN; | ||
| 16 | } | ||
| 17 | } | ||
| 18 | |||
| 19 | int __wasilibc_dttoif(int x) { | ||
| 20 | switch (x) { | ||
| 21 | case DT_DIR: return S_IFDIR; | ||
| 22 | case DT_CHR: return S_IFCHR; | ||
| 23 | case DT_BLK: return S_IFBLK; | ||
| 24 | case DT_REG: return S_IFREG; | ||
| 25 | case DT_FIFO: return S_IFIFO; | ||
| 26 | case DT_LNK: return S_IFLNK; | ||
| 27 | #ifdef DT_SOCK | ||
| 28 | case DT_SOCK: return S_IFSOCK; | ||
| 29 | #endif | ||
| 30 | case DT_UNKNOWN: | ||
| 31 | default: | ||
| 32 | 	 return S_IFSOCK; | ||
| 33 | } | ||
| 34 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_environ.c deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #include <wasi/libc-environ.h> | ||
| 2 | |||
| 3 | extern char **__wasilibc_environ; | ||
| 4 | |||
| 5 | // See the comments in libc-environ.h. | ||
| 6 | char **__wasilibc_get_environ(void) { | ||
| 7 | // Perform lazy initialization if needed. | ||
| 8 | __wasilibc_ensure_environ(); | ||
| 9 | |||
| 10 | // Return `environ`. Use the `__wasilibc_`-prefixed name so that we don't | ||
| 11 | // pull in the `environ` symbol directly, which would lead to eager | ||
| 12 | // initialization being done instead. | ||
| 13 | return __wasilibc_environ; | ||
| 14 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c deleted-72| ... | @@ -1,72 +0,0 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <wasi/libc.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | int __wasilibc_fd_renumber(int fd, int newfd) { | ||
| 7 | // Scan the preopen fds before making any changes. | ||
| 8 | __wasilibc_populate_preopens(); | ||
| 9 | |||
| 10 | __wasi_errno_t error = __wasi_fd_renumber(fd, newfd); | ||
| 11 | if (error != 0) { | ||
| 12 | errno = error; | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | return 0; | ||
| 16 | } | ||
| 17 | |||
| 18 | #ifdef __wasilibc_use_wasip2 | ||
| 19 | #include <wasi/descriptor_table.h> | ||
| 20 | |||
| 21 | void drop_tcp_socket(tcp_socket_t socket) { | ||
| 22 | switch (socket.state.tag) { | ||
| 23 | case TCP_SOCKET_STATE_UNBOUND: | ||
| 24 | case TCP_SOCKET_STATE_BOUND: | ||
| 25 | case TCP_SOCKET_STATE_CONNECTING: | ||
| 26 | case TCP_SOCKET_STATE_LISTENING: | ||
| 27 | case TCP_SOCKET_STATE_CONNECT_FAILED: | ||
| 28 | // No additional resources to drop. | ||
| 29 | break; | ||
| 30 | case TCP_SOCKET_STATE_CONNECTED: { | ||
| 31 | tcp_socket_state_connected_t connection = socket.state.connected; | ||
| 32 | |||
| 33 | poll_pollable_drop_own(connection.input_pollable); | ||
| 34 | poll_pollable_drop_own(connection.output_pollable); | ||
| 35 | streams_input_stream_drop_own(connection.input); | ||
| 36 | streams_output_stream_drop_own(connection.output); | ||
| 37 | break; | ||
| 38 | } | ||
| 39 | default: /* unreachable */ abort(); | ||
| 40 | } | ||
| 41 | |||
| 42 | poll_pollable_drop_own(socket.socket_pollable); | ||
| 43 | tcp_tcp_socket_drop_own(socket.socket); | ||
| 44 | } | ||
| 45 | |||
| 46 | void drop_udp_socket_streams(udp_socket_streams_t streams) { | ||
| 47 | poll_pollable_drop_own(streams.incoming_pollable); | ||
| 48 | poll_pollable_drop_own(streams.outgoing_pollable); | ||
| 49 | udp_incoming_datagram_stream_drop_own(streams.incoming); | ||
| 50 | udp_outgoing_datagram_stream_drop_own(streams.outgoing); | ||
| 51 | } | ||
| 52 | |||
| 53 | void drop_udp_socket(udp_socket_t socket) { | ||
| 54 | switch (socket.state.tag) { | ||
| 55 | case UDP_SOCKET_STATE_UNBOUND: | ||
| 56 | case UDP_SOCKET_STATE_BOUND_NOSTREAMS: | ||
| 57 | // No additional resources to drop. | ||
| 58 | break; | ||
| 59 | case UDP_SOCKET_STATE_BOUND_STREAMING: | ||
| 60 | drop_udp_socket_streams(socket.state.bound_streaming.streams); | ||
| 61 | break; | ||
| 62 | case UDP_SOCKET_STATE_CONNECTED: { | ||
| 63 | drop_udp_socket_streams(socket.state.connected.streams); | ||
| 64 | break; | ||
| 65 | } | ||
| 66 | default: /* unreachable */ abort(); | ||
| 67 | } | ||
| 68 | |||
| 69 | poll_pollable_drop_own(socket.socket_pollable); | ||
| 70 | udp_udp_socket_drop_own(socket.socket); | ||
| 71 | } | ||
| 72 | #endif // __wasilibc_use_wasip2 | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c deleted-147| ... | @@ -1,147 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sysexits.h> | ||
| 4 | #ifdef __wasilibc_use_wasip2 | ||
| 5 | #include <wasi/wasip2.h> | ||
| 6 | #else | ||
| 7 | #include <wasi/api.h> | ||
| 8 | #endif | ||
| 9 | #include <wasi/libc.h> | ||
| 10 | #include <wasi/libc-environ.h> | ||
| 11 | |||
| 12 | /// If the program doesn't use `environ`, it'll get this version of | ||
| 13 | /// `__wasilibc_environ`, which isn't initialized with a constructor function. | ||
| 14 | /// `getenv` etc. call `__wasilibc_ensure_environ()` before accessing it. | ||
| 15 | /// Statically-initialize it to an invalid pointer value so that we can | ||
| 16 | /// detect if it's been explicitly initialized (we can't use `NULL` because | ||
| 17 | /// `clearenv` sets it to NULL. | ||
| 18 | weak char **__wasilibc_environ = (char **)-1; | ||
| 19 | |||
| 20 | // See the comments in libc-environ.h. | ||
| 21 | void __wasilibc_ensure_environ(void) { | ||
| 22 | if (__wasilibc_environ == (char **)-1) { | ||
| 23 | __wasilibc_initialize_environ(); | ||
| 24 | } | ||
| 25 | } | ||
| 26 | |||
| 27 | /// Avoid dynamic allocation for the case where there are no environment | ||
| 28 | /// variables, but we still need a non-NULL pointer to an (empty) array. | ||
| 29 | static char *empty_environ[1] = { NULL }; | ||
| 30 | |||
| 31 | // See the comments in libc-environ.h. | ||
| 32 | void __wasilibc_initialize_environ(void) { | ||
| 33 | #ifdef __wasilibc_use_wasip2 | ||
| 34 | // Get the environment | ||
| 35 | wasip2_list_tuple2_string_string_t wasi_environment; | ||
| 36 | environment_get_environment(&wasi_environment); | ||
| 37 | |||
| 38 | size_t environ_count = wasi_environment.len; | ||
| 39 | if (environ_count == 0) { | ||
| 40 | __wasilibc_environ = empty_environ; | ||
| 41 | return; | ||
| 42 | } | ||
| 43 | |||
| 44 | // Add 1 for the NULL pointer to mark the end, and check for overflow. | ||
| 45 | size_t num_ptrs = environ_count + 1; | ||
| 46 | if (num_ptrs == 0) { | ||
| 47 | goto software; | ||
| 48 | } | ||
| 49 | |||
| 50 | // Allocate memory for the array of pointers. This uses `calloc` both to | ||
| 51 | // handle overflow and to initialize the NULL pointer at the end. | ||
| 52 | char **environ_ptrs = calloc(num_ptrs, sizeof(char *)); | ||
| 53 | |||
| 54 | // Copy the environment variables | ||
| 55 | for (size_t i = 0; i < environ_count; i++) { | ||
| 56 | wasip2_tuple2_string_string_t pair = wasi_environment.ptr[i]; | ||
| 57 | // 1 extra character for the null terminator, 1 for the '=' character | ||
| 58 | environ_ptrs[i] = malloc(pair.f0.len + pair.f1.len + 2); | ||
| 59 | if (!environ_ptrs[i]) { | ||
| 60 | for (size_t j = 0; j < i; j++) | ||
| 61 | free(environ_ptrs[j]); | ||
| 62 | free(environ_ptrs); | ||
| 63 | goto software; | ||
| 64 | } | ||
| 65 | memcpy(environ_ptrs[i], pair.f0.ptr, pair.f0.len); | ||
| 66 | environ_ptrs[i][pair.f0.len] = '='; | ||
| 67 | memcpy(environ_ptrs[i] + pair.f0.len + 1, pair.f1.ptr, pair.f1.len); | ||
| 68 | environ_ptrs[i][pair.f0.len + pair.f1.len + 1] = '\0'; | ||
| 69 | } | ||
| 70 | |||
| 71 | // Free the WASI environment list | ||
| 72 | wasip2_list_tuple2_string_string_free(&wasi_environment); | ||
| 73 | |||
| 74 | // Initialize the environment from the created array | ||
| 75 | __wasilibc_environ = environ_ptrs; | ||
| 76 | return; | ||
| 77 | software: | ||
| 78 | wasip2_list_tuple2_string_string_free(&wasi_environment); | ||
| 79 | _Exit(EX_SOFTWARE); | ||
| 80 | |||
| 81 | #else | ||
| 82 | // Get the sizes of the arrays we'll have to create to copy in the environment. | ||
| 83 | size_t environ_count; | ||
| 84 | size_t environ_buf_size; | ||
| 85 | __wasi_errno_t err = __wasi_environ_sizes_get(&environ_count, &environ_buf_size); | ||
| 86 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 87 | goto oserr; | ||
| 88 | } | ||
| 89 | if (environ_count == 0) { | ||
| 90 | __wasilibc_environ = empty_environ; | ||
| 91 | return; | ||
| 92 | } | ||
| 93 | |||
| 94 | // Add 1 for the NULL pointer to mark the end, and check for overflow. | ||
| 95 | size_t num_ptrs = environ_count + 1; | ||
| 96 | if (num_ptrs == 0) { | ||
| 97 | goto software; | ||
| 98 | } | ||
| 99 | |||
| 100 | // Allocate memory for storing the environment chars. | ||
| 101 | char *environ_buf = malloc(environ_buf_size); | ||
| 102 | if (environ_buf == NULL) { | ||
| 103 | goto software; | ||
| 104 | } | ||
| 105 | |||
| 106 | // Allocate memory for the array of pointers. This uses `calloc` both to | ||
| 107 | // handle overflow and to initialize the NULL pointer at the end. | ||
| 108 | char **environ_ptrs = calloc(num_ptrs, sizeof(char *)); | ||
| 109 | if (environ_ptrs == NULL) { | ||
| 110 | free(environ_buf); | ||
| 111 | goto software; | ||
| 112 | } | ||
| 113 | |||
| 114 | // Fill the environment chars, and the `__wasilibc_environ` array with | ||
| 115 | // pointers into those chars. | ||
| 116 | // TODO: Remove the casts on `environ_ptrs` and `environ_buf` once the witx is updated with char8 support. | ||
| 117 | err = __wasi_environ_get((uint8_t **)environ_ptrs, (uint8_t *)environ_buf); | ||
| 118 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 119 | free(environ_buf); | ||
| 120 | free(environ_ptrs); | ||
| 121 | goto oserr; | ||
| 122 | } | ||
| 123 | |||
| 124 | __wasilibc_environ = environ_ptrs; | ||
| 125 | return; | ||
| 126 | oserr: | ||
| 127 | _Exit(EX_OSERR); | ||
| 128 | software: | ||
| 129 | _Exit(EX_SOFTWARE); | ||
| 130 | #endif | ||
| 131 | } | ||
| 132 | |||
| 133 | // See the comments in libc-environ.h. | ||
| 134 | void __wasilibc_deinitialize_environ(void) { | ||
| 135 | if (__wasilibc_environ != (char **)-1) { | ||
| 136 | // Let libc-top-half clear the old environment-variable strings. | ||
| 137 | clearenv(); | ||
| 138 | // Set the pointer to the special init value. | ||
| 139 | __wasilibc_environ = (char **)-1; | ||
| 140 | } | ||
| 141 | } | ||
| 142 | |||
| 143 | // See the comments in libc-environ.h. | ||
| 144 | weak void __wasilibc_maybe_reinitialize_environ_eagerly(void) { | ||
| 145 | // This version does nothing. It may be overridden by a version which does | ||
| 146 | // something if `environ` is used. | ||
| 147 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_random.c deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #ifdef __wasilibc_use_wasip2 | ||
| 4 | #include <wasi/wasip2.h> | ||
| 5 | #include <sysexits.h> | ||
| 6 | |||
| 7 | int __wasilibc_random(void *buffer, size_t len) { | ||
| 8 | |||
| 9 | // Set up a WASI byte list to receive the results | ||
| 10 | wasip2_list_u8_t wasi_list; | ||
| 11 | |||
| 12 | // Get random bytes | ||
| 13 | random_get_random_bytes(len, &wasi_list); | ||
| 14 | |||
| 15 | // The spec for get-random-bytes specifies that wasi_list.len | ||
| 16 | // will be equal to len. | ||
| 17 | if (wasi_list.len != len) | ||
| 18 | _Exit(EX_OSERR); | ||
| 19 | else { | ||
| 20 | // Copy the result | ||
| 21 | memcpy(buffer, wasi_list.ptr, len); | ||
| 22 | } | ||
| 23 | |||
| 24 | // Free the WASI byte list | ||
| 25 | wasip2_list_u8_free(&wasi_list); | ||
| 26 | |||
| 27 | return 0; | ||
| 28 | } | ||
| 29 | #endif | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c deleted-671| ... | @@ -1,671 +0,0 @@ | ||
| 1 | /** | ||
| 2 | * THIS FILE IS AUTO-GENERATED from the following files: | ||
| 3 | * wasi_snapshot_preview1.witx | ||
| 4 | * | ||
| 5 | * To regenerate this file execute: | ||
| 6 | * | ||
| 7 | * cargo run --manifest-path tools/wasi-headers/Cargo.toml generate-libc | ||
| 8 | * | ||
| 9 | * Modifications to this file will cause CI to fail, the code generator tool | ||
| 10 | * must be modified to change this file. | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <wasi/api.h> | ||
| 14 | #include <string.h> | ||
| 15 | |||
| 16 | int32_t __imported_wasi_snapshot_preview1_args_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 17 | __import_module__("wasi_snapshot_preview1"), | ||
| 18 | __import_name__("args_get") | ||
| 19 | )); | ||
| 20 | |||
| 21 | __wasi_errno_t __wasi_args_get( | ||
| 22 | uint8_t * * argv, | ||
| 23 | uint8_t * argv_buf | ||
| 24 | ){ | ||
| 25 | int32_t ret = __imported_wasi_snapshot_preview1_args_get((int32_t) argv, (int32_t) argv_buf); | ||
| 26 | return (uint16_t) ret; | ||
| 27 | } | ||
| 28 | |||
| 29 | int32_t __imported_wasi_snapshot_preview1_args_sizes_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 30 | __import_module__("wasi_snapshot_preview1"), | ||
| 31 | __import_name__("args_sizes_get") | ||
| 32 | )); | ||
| 33 | |||
| 34 | __wasi_errno_t __wasi_args_sizes_get( | ||
| 35 | __wasi_size_t *retptr0, | ||
| 36 | __wasi_size_t *retptr1 | ||
| 37 | ){ | ||
| 38 | int32_t ret = __imported_wasi_snapshot_preview1_args_sizes_get((int32_t) retptr0, (int32_t) retptr1); | ||
| 39 | return (uint16_t) ret; | ||
| 40 | } | ||
| 41 | |||
| 42 | int32_t __imported_wasi_snapshot_preview1_environ_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 43 | __import_module__("wasi_snapshot_preview1"), | ||
| 44 | __import_name__("environ_get") | ||
| 45 | )); | ||
| 46 | |||
| 47 | __wasi_errno_t __wasi_environ_get( | ||
| 48 | uint8_t * * environ, | ||
| 49 | uint8_t * environ_buf | ||
| 50 | ){ | ||
| 51 | int32_t ret = __imported_wasi_snapshot_preview1_environ_get((int32_t) environ, (int32_t) environ_buf); | ||
| 52 | return (uint16_t) ret; | ||
| 53 | } | ||
| 54 | |||
| 55 | int32_t __imported_wasi_snapshot_preview1_environ_sizes_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 56 | __import_module__("wasi_snapshot_preview1"), | ||
| 57 | __import_name__("environ_sizes_get") | ||
| 58 | )); | ||
| 59 | |||
| 60 | __wasi_errno_t __wasi_environ_sizes_get( | ||
| 61 | __wasi_size_t *retptr0, | ||
| 62 | __wasi_size_t *retptr1 | ||
| 63 | ){ | ||
| 64 | int32_t ret = __imported_wasi_snapshot_preview1_environ_sizes_get((int32_t) retptr0, (int32_t) retptr1); | ||
| 65 | return (uint16_t) ret; | ||
| 66 | } | ||
| 67 | |||
| 68 | int32_t __imported_wasi_snapshot_preview1_clock_res_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 69 | __import_module__("wasi_snapshot_preview1"), | ||
| 70 | __import_name__("clock_res_get") | ||
| 71 | )); | ||
| 72 | |||
| 73 | __wasi_errno_t __wasi_clock_res_get( | ||
| 74 | __wasi_clockid_t id, | ||
| 75 | __wasi_timestamp_t *retptr0 | ||
| 76 | ){ | ||
| 77 | int32_t ret = __imported_wasi_snapshot_preview1_clock_res_get((int32_t) id, (int32_t) retptr0); | ||
| 78 | return (uint16_t) ret; | ||
| 79 | } | ||
| 80 | |||
| 81 | int32_t __imported_wasi_snapshot_preview1_clock_time_get(int32_t arg0, int64_t arg1, int32_t arg2) __attribute__(( | ||
| 82 | __import_module__("wasi_snapshot_preview1"), | ||
| 83 | __import_name__("clock_time_get") | ||
| 84 | )); | ||
| 85 | |||
| 86 | __wasi_errno_t __wasi_clock_time_get( | ||
| 87 | __wasi_clockid_t id, | ||
| 88 | __wasi_timestamp_t precision, | ||
| 89 | __wasi_timestamp_t *retptr0 | ||
| 90 | ){ | ||
| 91 | int32_t ret = __imported_wasi_snapshot_preview1_clock_time_get((int32_t) id, (int64_t) precision, (int32_t) retptr0); | ||
| 92 | return (uint16_t) ret; | ||
| 93 | } | ||
| 94 | |||
| 95 | int32_t __imported_wasi_snapshot_preview1_fd_advise(int32_t arg0, int64_t arg1, int64_t arg2, int32_t arg3) __attribute__(( | ||
| 96 | __import_module__("wasi_snapshot_preview1"), | ||
| 97 | __import_name__("fd_advise") | ||
| 98 | )); | ||
| 99 | |||
| 100 | __wasi_errno_t __wasi_fd_advise( | ||
| 101 | __wasi_fd_t fd, | ||
| 102 | __wasi_filesize_t offset, | ||
| 103 | __wasi_filesize_t len, | ||
| 104 | __wasi_advice_t advice | ||
| 105 | ){ | ||
| 106 | int32_t ret = __imported_wasi_snapshot_preview1_fd_advise((int32_t) fd, (int64_t) offset, (int64_t) len, (int32_t) advice); | ||
| 107 | return (uint16_t) ret; | ||
| 108 | } | ||
| 109 | |||
| 110 | int32_t __imported_wasi_snapshot_preview1_fd_allocate(int32_t arg0, int64_t arg1, int64_t arg2) __attribute__(( | ||
| 111 | __import_module__("wasi_snapshot_preview1"), | ||
| 112 | __import_name__("fd_allocate") | ||
| 113 | )); | ||
| 114 | |||
| 115 | __wasi_errno_t __wasi_fd_allocate( | ||
| 116 | __wasi_fd_t fd, | ||
| 117 | __wasi_filesize_t offset, | ||
| 118 | __wasi_filesize_t len | ||
| 119 | ){ | ||
| 120 | int32_t ret = __imported_wasi_snapshot_preview1_fd_allocate((int32_t) fd, (int64_t) offset, (int64_t) len); | ||
| 121 | return (uint16_t) ret; | ||
| 122 | } | ||
| 123 | |||
| 124 | int32_t __imported_wasi_snapshot_preview1_fd_close(int32_t arg0) __attribute__(( | ||
| 125 | __import_module__("wasi_snapshot_preview1"), | ||
| 126 | __import_name__("fd_close") | ||
| 127 | )); | ||
| 128 | |||
| 129 | __wasi_errno_t __wasi_fd_close( | ||
| 130 | __wasi_fd_t fd | ||
| 131 | ){ | ||
| 132 | int32_t ret = __imported_wasi_snapshot_preview1_fd_close((int32_t) fd); | ||
| 133 | return (uint16_t) ret; | ||
| 134 | } | ||
| 135 | |||
| 136 | int32_t __imported_wasi_snapshot_preview1_fd_datasync(int32_t arg0) __attribute__(( | ||
| 137 | __import_module__("wasi_snapshot_preview1"), | ||
| 138 | __import_name__("fd_datasync") | ||
| 139 | )); | ||
| 140 | |||
| 141 | __wasi_errno_t __wasi_fd_datasync( | ||
| 142 | __wasi_fd_t fd | ||
| 143 | ){ | ||
| 144 | int32_t ret = __imported_wasi_snapshot_preview1_fd_datasync((int32_t) fd); | ||
| 145 | return (uint16_t) ret; | ||
| 146 | } | ||
| 147 | |||
| 148 | int32_t __imported_wasi_snapshot_preview1_fd_fdstat_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 149 | __import_module__("wasi_snapshot_preview1"), | ||
| 150 | __import_name__("fd_fdstat_get") | ||
| 151 | )); | ||
| 152 | |||
| 153 | __wasi_errno_t __wasi_fd_fdstat_get( | ||
| 154 | __wasi_fd_t fd, | ||
| 155 | __wasi_fdstat_t *retptr0 | ||
| 156 | ){ | ||
| 157 | int32_t ret = __imported_wasi_snapshot_preview1_fd_fdstat_get((int32_t) fd, (int32_t) retptr0); | ||
| 158 | return (uint16_t) ret; | ||
| 159 | } | ||
| 160 | |||
| 161 | int32_t __imported_wasi_snapshot_preview1_fd_fdstat_set_flags(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 162 | __import_module__("wasi_snapshot_preview1"), | ||
| 163 | __import_name__("fd_fdstat_set_flags") | ||
| 164 | )); | ||
| 165 | |||
| 166 | __wasi_errno_t __wasi_fd_fdstat_set_flags( | ||
| 167 | __wasi_fd_t fd, | ||
| 168 | __wasi_fdflags_t flags | ||
| 169 | ){ | ||
| 170 | int32_t ret = __imported_wasi_snapshot_preview1_fd_fdstat_set_flags((int32_t) fd, flags); | ||
| 171 | return (uint16_t) ret; | ||
| 172 | } | ||
| 173 | |||
| 174 | int32_t __imported_wasi_snapshot_preview1_fd_fdstat_set_rights(int32_t arg0, int64_t arg1, int64_t arg2) __attribute__(( | ||
| 175 | __import_module__("wasi_snapshot_preview1"), | ||
| 176 | __import_name__("fd_fdstat_set_rights") | ||
| 177 | )); | ||
| 178 | |||
| 179 | __wasi_errno_t __wasi_fd_fdstat_set_rights( | ||
| 180 | __wasi_fd_t fd, | ||
| 181 | __wasi_rights_t fs_rights_base, | ||
| 182 | __wasi_rights_t fs_rights_inheriting | ||
| 183 | ){ | ||
| 184 | int32_t ret = __imported_wasi_snapshot_preview1_fd_fdstat_set_rights((int32_t) fd, fs_rights_base, fs_rights_inheriting); | ||
| 185 | return (uint16_t) ret; | ||
| 186 | } | ||
| 187 | |||
| 188 | int32_t __imported_wasi_snapshot_preview1_fd_filestat_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 189 | __import_module__("wasi_snapshot_preview1"), | ||
| 190 | __import_name__("fd_filestat_get") | ||
| 191 | )); | ||
| 192 | |||
| 193 | __wasi_errno_t __wasi_fd_filestat_get( | ||
| 194 | __wasi_fd_t fd, | ||
| 195 | __wasi_filestat_t *retptr0 | ||
| 196 | ){ | ||
| 197 | int32_t ret = __imported_wasi_snapshot_preview1_fd_filestat_get((int32_t) fd, (int32_t) retptr0); | ||
| 198 | return (uint16_t) ret; | ||
| 199 | } | ||
| 200 | |||
| 201 | int32_t __imported_wasi_snapshot_preview1_fd_filestat_set_size(int32_t arg0, int64_t arg1) __attribute__(( | ||
| 202 | __import_module__("wasi_snapshot_preview1"), | ||
| 203 | __import_name__("fd_filestat_set_size") | ||
| 204 | )); | ||
| 205 | |||
| 206 | __wasi_errno_t __wasi_fd_filestat_set_size( | ||
| 207 | __wasi_fd_t fd, | ||
| 208 | __wasi_filesize_t size | ||
| 209 | ){ | ||
| 210 | int32_t ret = __imported_wasi_snapshot_preview1_fd_filestat_set_size((int32_t) fd, (int64_t) size); | ||
| 211 | return (uint16_t) ret; | ||
| 212 | } | ||
| 213 | |||
| 214 | int32_t __imported_wasi_snapshot_preview1_fd_filestat_set_times(int32_t arg0, int64_t arg1, int64_t arg2, int32_t arg3) __attribute__(( | ||
| 215 | __import_module__("wasi_snapshot_preview1"), | ||
| 216 | __import_name__("fd_filestat_set_times") | ||
| 217 | )); | ||
| 218 | |||
| 219 | __wasi_errno_t __wasi_fd_filestat_set_times( | ||
| 220 | __wasi_fd_t fd, | ||
| 221 | __wasi_timestamp_t atim, | ||
| 222 | __wasi_timestamp_t mtim, | ||
| 223 | __wasi_fstflags_t fst_flags | ||
| 224 | ){ | ||
| 225 | int32_t ret = __imported_wasi_snapshot_preview1_fd_filestat_set_times((int32_t) fd, (int64_t) atim, (int64_t) mtim, fst_flags); | ||
| 226 | return (uint16_t) ret; | ||
| 227 | } | ||
| 228 | |||
| 229 | int32_t __imported_wasi_snapshot_preview1_fd_pread(int32_t arg0, int32_t arg1, int32_t arg2, int64_t arg3, int32_t arg4) __attribute__(( | ||
| 230 | __import_module__("wasi_snapshot_preview1"), | ||
| 231 | __import_name__("fd_pread") | ||
| 232 | )); | ||
| 233 | |||
| 234 | __wasi_errno_t __wasi_fd_pread( | ||
| 235 | __wasi_fd_t fd, | ||
| 236 | const __wasi_iovec_t *iovs, | ||
| 237 | size_t iovs_len, | ||
| 238 | __wasi_filesize_t offset, | ||
| 239 | __wasi_size_t *retptr0 | ||
| 240 | ){ | ||
| 241 | 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); | ||
| 242 | return (uint16_t) ret; | ||
| 243 | } | ||
| 244 | |||
| 245 | int32_t __imported_wasi_snapshot_preview1_fd_prestat_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 246 | __import_module__("wasi_snapshot_preview1"), | ||
| 247 | __import_name__("fd_prestat_get") | ||
| 248 | )); | ||
| 249 | |||
| 250 | __wasi_errno_t __wasi_fd_prestat_get( | ||
| 251 | __wasi_fd_t fd, | ||
| 252 | __wasi_prestat_t *retptr0 | ||
| 253 | ){ | ||
| 254 | int32_t ret = __imported_wasi_snapshot_preview1_fd_prestat_get((int32_t) fd, (int32_t) retptr0); | ||
| 255 | return (uint16_t) ret; | ||
| 256 | } | ||
| 257 | |||
| 258 | int32_t __imported_wasi_snapshot_preview1_fd_prestat_dir_name(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( | ||
| 259 | __import_module__("wasi_snapshot_preview1"), | ||
| 260 | __import_name__("fd_prestat_dir_name") | ||
| 261 | )); | ||
| 262 | |||
| 263 | __wasi_errno_t __wasi_fd_prestat_dir_name( | ||
| 264 | __wasi_fd_t fd, | ||
| 265 | uint8_t * path, | ||
| 266 | __wasi_size_t path_len | ||
| 267 | ){ | ||
| 268 | int32_t ret = __imported_wasi_snapshot_preview1_fd_prestat_dir_name((int32_t) fd, (int32_t) path, (int32_t) path_len); | ||
| 269 | return (uint16_t) ret; | ||
| 270 | } | ||
| 271 | |||
| 272 | int32_t __imported_wasi_snapshot_preview1_fd_pwrite(int32_t arg0, int32_t arg1, int32_t arg2, int64_t arg3, int32_t arg4) __attribute__(( | ||
| 273 | __import_module__("wasi_snapshot_preview1"), | ||
| 274 | __import_name__("fd_pwrite") | ||
| 275 | )); | ||
| 276 | |||
| 277 | __wasi_errno_t __wasi_fd_pwrite( | ||
| 278 | __wasi_fd_t fd, | ||
| 279 | const __wasi_ciovec_t *iovs, | ||
| 280 | size_t iovs_len, | ||
| 281 | __wasi_filesize_t offset, | ||
| 282 | __wasi_size_t *retptr0 | ||
| 283 | ){ | ||
| 284 | 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); | ||
| 285 | return (uint16_t) ret; | ||
| 286 | } | ||
| 287 | |||
| 288 | int32_t __imported_wasi_snapshot_preview1_fd_read(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__(( | ||
| 289 | __import_module__("wasi_snapshot_preview1"), | ||
| 290 | __import_name__("fd_read") | ||
| 291 | )); | ||
| 292 | |||
| 293 | __wasi_errno_t __wasi_fd_read( | ||
| 294 | __wasi_fd_t fd, | ||
| 295 | const __wasi_iovec_t *iovs, | ||
| 296 | size_t iovs_len, | ||
| 297 | __wasi_size_t *retptr0 | ||
| 298 | ){ | ||
| 299 | int32_t ret = __imported_wasi_snapshot_preview1_fd_read((int32_t) fd, (int32_t) iovs, (int32_t) iovs_len, (int32_t) retptr0); | ||
| 300 | return (uint16_t) ret; | ||
| 301 | } | ||
| 302 | |||
| 303 | int32_t __imported_wasi_snapshot_preview1_fd_readdir(int32_t arg0, int32_t arg1, int32_t arg2, int64_t arg3, int32_t arg4) __attribute__(( | ||
| 304 | __import_module__("wasi_snapshot_preview1"), | ||
| 305 | __import_name__("fd_readdir") | ||
| 306 | )); | ||
| 307 | |||
| 308 | __wasi_errno_t __wasi_fd_readdir( | ||
| 309 | __wasi_fd_t fd, | ||
| 310 | uint8_t * buf, | ||
| 311 | __wasi_size_t buf_len, | ||
| 312 | __wasi_dircookie_t cookie, | ||
| 313 | __wasi_size_t *retptr0 | ||
| 314 | ){ | ||
| 315 | 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); | ||
| 316 | return (uint16_t) ret; | ||
| 317 | } | ||
| 318 | |||
| 319 | int32_t __imported_wasi_snapshot_preview1_fd_renumber(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 320 | __import_module__("wasi_snapshot_preview1"), | ||
| 321 | __import_name__("fd_renumber") | ||
| 322 | )); | ||
| 323 | |||
| 324 | __wasi_errno_t __wasi_fd_renumber( | ||
| 325 | __wasi_fd_t fd, | ||
| 326 | __wasi_fd_t to | ||
| 327 | ){ | ||
| 328 | int32_t ret = __imported_wasi_snapshot_preview1_fd_renumber((int32_t) fd, (int32_t) to); | ||
| 329 | return (uint16_t) ret; | ||
| 330 | } | ||
| 331 | |||
| 332 | int32_t __imported_wasi_snapshot_preview1_fd_seek(int32_t arg0, int64_t arg1, int32_t arg2, int32_t arg3) __attribute__(( | ||
| 333 | __import_module__("wasi_snapshot_preview1"), | ||
| 334 | __import_name__("fd_seek") | ||
| 335 | )); | ||
| 336 | |||
| 337 | __wasi_errno_t __wasi_fd_seek( | ||
| 338 | __wasi_fd_t fd, | ||
| 339 | __wasi_filedelta_t offset, | ||
| 340 | __wasi_whence_t whence, | ||
| 341 | __wasi_filesize_t *retptr0 | ||
| 342 | ){ | ||
| 343 | int32_t ret = __imported_wasi_snapshot_preview1_fd_seek((int32_t) fd, offset, (int32_t) whence, (int32_t) retptr0); | ||
| 344 | return (uint16_t) ret; | ||
| 345 | } | ||
| 346 | |||
| 347 | int32_t __imported_wasi_snapshot_preview1_fd_sync(int32_t arg0) __attribute__(( | ||
| 348 | __import_module__("wasi_snapshot_preview1"), | ||
| 349 | __import_name__("fd_sync") | ||
| 350 | )); | ||
| 351 | |||
| 352 | __wasi_errno_t __wasi_fd_sync( | ||
| 353 | __wasi_fd_t fd | ||
| 354 | ){ | ||
| 355 | int32_t ret = __imported_wasi_snapshot_preview1_fd_sync((int32_t) fd); | ||
| 356 | return (uint16_t) ret; | ||
| 357 | } | ||
| 358 | |||
| 359 | int32_t __imported_wasi_snapshot_preview1_fd_tell(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 360 | __import_module__("wasi_snapshot_preview1"), | ||
| 361 | __import_name__("fd_tell") | ||
| 362 | )); | ||
| 363 | |||
| 364 | __wasi_errno_t __wasi_fd_tell( | ||
| 365 | __wasi_fd_t fd, | ||
| 366 | __wasi_filesize_t *retptr0 | ||
| 367 | ){ | ||
| 368 | int32_t ret = __imported_wasi_snapshot_preview1_fd_tell((int32_t) fd, (int32_t) retptr0); | ||
| 369 | return (uint16_t) ret; | ||
| 370 | } | ||
| 371 | |||
| 372 | int32_t __imported_wasi_snapshot_preview1_fd_write(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__(( | ||
| 373 | __import_module__("wasi_snapshot_preview1"), | ||
| 374 | __import_name__("fd_write") | ||
| 375 | )); | ||
| 376 | |||
| 377 | __wasi_errno_t __wasi_fd_write( | ||
| 378 | __wasi_fd_t fd, | ||
| 379 | const __wasi_ciovec_t *iovs, | ||
| 380 | size_t iovs_len, | ||
| 381 | __wasi_size_t *retptr0 | ||
| 382 | ){ | ||
| 383 | int32_t ret = __imported_wasi_snapshot_preview1_fd_write((int32_t) fd, (int32_t) iovs, (int32_t) iovs_len, (int32_t) retptr0); | ||
| 384 | return (uint16_t) ret; | ||
| 385 | } | ||
| 386 | |||
| 387 | int32_t __imported_wasi_snapshot_preview1_path_create_directory(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( | ||
| 388 | __import_module__("wasi_snapshot_preview1"), | ||
| 389 | __import_name__("path_create_directory") | ||
| 390 | )); | ||
| 391 | |||
| 392 | __wasi_errno_t __wasi_path_create_directory( | ||
| 393 | __wasi_fd_t fd, | ||
| 394 | const char *path | ||
| 395 | ){ | ||
| 396 | size_t path_len = strlen(path); | ||
| 397 | int32_t ret = __imported_wasi_snapshot_preview1_path_create_directory((int32_t) fd, (int32_t) path, (int32_t) path_len); | ||
| 398 | return (uint16_t) ret; | ||
| 399 | } | ||
| 400 | |||
| 401 | 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__(( | ||
| 402 | __import_module__("wasi_snapshot_preview1"), | ||
| 403 | __import_name__("path_filestat_get") | ||
| 404 | )); | ||
| 405 | |||
| 406 | __wasi_errno_t __wasi_path_filestat_get( | ||
| 407 | __wasi_fd_t fd, | ||
| 408 | __wasi_lookupflags_t flags, | ||
| 409 | const char *path, | ||
| 410 | __wasi_filestat_t *retptr0 | ||
| 411 | ){ | ||
| 412 | size_t path_len = strlen(path); | ||
| 413 | int32_t ret = __imported_wasi_snapshot_preview1_path_filestat_get((int32_t) fd, flags, (int32_t) path, (int32_t) path_len, (int32_t) retptr0); | ||
| 414 | return (uint16_t) ret; | ||
| 415 | } | ||
| 416 | |||
| 417 | 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__(( | ||
| 418 | __import_module__("wasi_snapshot_preview1"), | ||
| 419 | __import_name__("path_filestat_set_times") | ||
| 420 | )); | ||
| 421 | |||
| 422 | __wasi_errno_t __wasi_path_filestat_set_times( | ||
| 423 | __wasi_fd_t fd, | ||
| 424 | __wasi_lookupflags_t flags, | ||
| 425 | const char *path, | ||
| 426 | __wasi_timestamp_t atim, | ||
| 427 | __wasi_timestamp_t mtim, | ||
| 428 | __wasi_fstflags_t fst_flags | ||
| 429 | ){ | ||
| 430 | size_t path_len = strlen(path); | ||
| 431 | 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); | ||
| 432 | return (uint16_t) ret; | ||
| 433 | } | ||
| 434 | |||
| 435 | 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__(( | ||
| 436 | __import_module__("wasi_snapshot_preview1"), | ||
| 437 | __import_name__("path_link") | ||
| 438 | )); | ||
| 439 | |||
| 440 | __wasi_errno_t __wasi_path_link( | ||
| 441 | __wasi_fd_t old_fd, | ||
| 442 | __wasi_lookupflags_t old_flags, | ||
| 443 | const char *old_path, | ||
| 444 | __wasi_fd_t new_fd, | ||
| 445 | const char *new_path | ||
| 446 | ){ | ||
| 447 | size_t old_path_len = strlen(old_path); | ||
| 448 | size_t new_path_len = strlen(new_path); | ||
| 449 | 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); | ||
| 450 | return (uint16_t) ret; | ||
| 451 | } | ||
| 452 | |||
| 453 | 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__(( | ||
| 454 | __import_module__("wasi_snapshot_preview1"), | ||
| 455 | __import_name__("path_open") | ||
| 456 | )); | ||
| 457 | |||
| 458 | __wasi_errno_t __wasi_path_open( | ||
| 459 | __wasi_fd_t fd, | ||
| 460 | __wasi_lookupflags_t dirflags, | ||
| 461 | const char *path, | ||
| 462 | __wasi_oflags_t oflags, | ||
| 463 | __wasi_rights_t fs_rights_base, | ||
| 464 | __wasi_rights_t fs_rights_inheriting, | ||
| 465 | __wasi_fdflags_t fdflags, | ||
| 466 | __wasi_fd_t *retptr0 | ||
| 467 | ){ | ||
| 468 | size_t path_len = strlen(path); | ||
| 469 | 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); | ||
| 470 | return (uint16_t) ret; | ||
| 471 | } | ||
| 472 | |||
| 473 | 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__(( | ||
| 474 | __import_module__("wasi_snapshot_preview1"), | ||
| 475 | __import_name__("path_readlink") | ||
| 476 | )); | ||
| 477 | |||
| 478 | __wasi_errno_t __wasi_path_readlink( | ||
| 479 | __wasi_fd_t fd, | ||
| 480 | const char *path, | ||
| 481 | uint8_t * buf, | ||
| 482 | __wasi_size_t buf_len, | ||
| 483 | __wasi_size_t *retptr0 | ||
| 484 | ){ | ||
| 485 | size_t path_len = strlen(path); | ||
| 486 | 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); | ||
| 487 | return (uint16_t) ret; | ||
| 488 | } | ||
| 489 | |||
| 490 | int32_t __imported_wasi_snapshot_preview1_path_remove_directory(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( | ||
| 491 | __import_module__("wasi_snapshot_preview1"), | ||
| 492 | __import_name__("path_remove_directory") | ||
| 493 | )); | ||
| 494 | |||
| 495 | __wasi_errno_t __wasi_path_remove_directory( | ||
| 496 | __wasi_fd_t fd, | ||
| 497 | const char *path | ||
| 498 | ){ | ||
| 499 | size_t path_len = strlen(path); | ||
| 500 | int32_t ret = __imported_wasi_snapshot_preview1_path_remove_directory((int32_t) fd, (int32_t) path, (int32_t) path_len); | ||
| 501 | return (uint16_t) ret; | ||
| 502 | } | ||
| 503 | |||
| 504 | 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__(( | ||
| 505 | __import_module__("wasi_snapshot_preview1"), | ||
| 506 | __import_name__("path_rename") | ||
| 507 | )); | ||
| 508 | |||
| 509 | __wasi_errno_t __wasi_path_rename( | ||
| 510 | __wasi_fd_t fd, | ||
| 511 | const char *old_path, | ||
| 512 | __wasi_fd_t new_fd, | ||
| 513 | const char *new_path | ||
| 514 | ){ | ||
| 515 | size_t old_path_len = strlen(old_path); | ||
| 516 | size_t new_path_len = strlen(new_path); | ||
| 517 | 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); | ||
| 518 | return (uint16_t) ret; | ||
| 519 | } | ||
| 520 | |||
| 521 | int32_t __imported_wasi_snapshot_preview1_path_symlink(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) __attribute__(( | ||
| 522 | __import_module__("wasi_snapshot_preview1"), | ||
| 523 | __import_name__("path_symlink") | ||
| 524 | )); | ||
| 525 | |||
| 526 | __wasi_errno_t __wasi_path_symlink( | ||
| 527 | const char *old_path, | ||
| 528 | __wasi_fd_t fd, | ||
| 529 | const char *new_path | ||
| 530 | ){ | ||
| 531 | size_t old_path_len = strlen(old_path); | ||
| 532 | size_t new_path_len = strlen(new_path); | ||
| 533 | 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); | ||
| 534 | return (uint16_t) ret; | ||
| 535 | } | ||
| 536 | |||
| 537 | int32_t __imported_wasi_snapshot_preview1_path_unlink_file(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( | ||
| 538 | __import_module__("wasi_snapshot_preview1"), | ||
| 539 | __import_name__("path_unlink_file") | ||
| 540 | )); | ||
| 541 | |||
| 542 | __wasi_errno_t __wasi_path_unlink_file( | ||
| 543 | __wasi_fd_t fd, | ||
| 544 | const char *path | ||
| 545 | ){ | ||
| 546 | size_t path_len = strlen(path); | ||
| 547 | int32_t ret = __imported_wasi_snapshot_preview1_path_unlink_file((int32_t) fd, (int32_t) path, (int32_t) path_len); | ||
| 548 | return (uint16_t) ret; | ||
| 549 | } | ||
| 550 | |||
| 551 | int32_t __imported_wasi_snapshot_preview1_poll_oneoff(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3) __attribute__(( | ||
| 552 | __import_module__("wasi_snapshot_preview1"), | ||
| 553 | __import_name__("poll_oneoff") | ||
| 554 | )); | ||
| 555 | |||
| 556 | __wasi_errno_t __wasi_poll_oneoff( | ||
| 557 | const __wasi_subscription_t * in, | ||
| 558 | __wasi_event_t * out, | ||
| 559 | __wasi_size_t nsubscriptions, | ||
| 560 | __wasi_size_t *retptr0 | ||
| 561 | ){ | ||
| 562 | int32_t ret = __imported_wasi_snapshot_preview1_poll_oneoff((int32_t) in, (int32_t) out, (int32_t) nsubscriptions, (int32_t) retptr0); | ||
| 563 | return (uint16_t) ret; | ||
| 564 | } | ||
| 565 | |||
| 566 | _Noreturn void __imported_wasi_snapshot_preview1_proc_exit(int32_t arg0) __attribute__(( | ||
| 567 | __import_module__("wasi_snapshot_preview1"), | ||
| 568 | __import_name__("proc_exit") | ||
| 569 | )); | ||
| 570 | |||
| 571 | _Noreturn void __wasi_proc_exit( | ||
| 572 | __wasi_exitcode_t rval | ||
| 573 | ){ | ||
| 574 | __imported_wasi_snapshot_preview1_proc_exit((int32_t) rval); | ||
| 575 | } | ||
| 576 | |||
| 577 | int32_t __imported_wasi_snapshot_preview1_sched_yield() __attribute__(( | ||
| 578 | __import_module__("wasi_snapshot_preview1"), | ||
| 579 | __import_name__("sched_yield") | ||
| 580 | )); | ||
| 581 | |||
| 582 | __wasi_errno_t __wasi_sched_yield( | ||
| 583 | void | ||
| 584 | ){ | ||
| 585 | int32_t ret = __imported_wasi_snapshot_preview1_sched_yield(); | ||
| 586 | return (uint16_t) ret; | ||
| 587 | } | ||
| 588 | |||
| 589 | int32_t __imported_wasi_snapshot_preview1_random_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 590 | __import_module__("wasi_snapshot_preview1"), | ||
| 591 | __import_name__("random_get") | ||
| 592 | )); | ||
| 593 | |||
| 594 | __wasi_errno_t __wasi_random_get( | ||
| 595 | uint8_t * buf, | ||
| 596 | __wasi_size_t buf_len | ||
| 597 | ){ | ||
| 598 | int32_t ret = __imported_wasi_snapshot_preview1_random_get((int32_t) buf, (int32_t) buf_len); | ||
| 599 | return (uint16_t) ret; | ||
| 600 | } | ||
| 601 | |||
| 602 | int32_t __imported_wasi_snapshot_preview1_sock_accept(int32_t arg0, int32_t arg1, int32_t arg2) __attribute__(( | ||
| 603 | __import_module__("wasi_snapshot_preview1"), | ||
| 604 | __import_name__("sock_accept") | ||
| 605 | )); | ||
| 606 | |||
| 607 | __wasi_errno_t __wasi_sock_accept( | ||
| 608 | __wasi_fd_t fd, | ||
| 609 | __wasi_fdflags_t flags, | ||
| 610 | __wasi_fd_t *retptr0 | ||
| 611 | ){ | ||
| 612 | int32_t ret = __imported_wasi_snapshot_preview1_sock_accept((int32_t) fd, flags, (int32_t) retptr0); | ||
| 613 | return (uint16_t) ret; | ||
| 614 | } | ||
| 615 | |||
| 616 | 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__(( | ||
| 617 | __import_module__("wasi_snapshot_preview1"), | ||
| 618 | __import_name__("sock_recv") | ||
| 619 | )); | ||
| 620 | |||
| 621 | __wasi_errno_t __wasi_sock_recv( | ||
| 622 | __wasi_fd_t fd, | ||
| 623 | const __wasi_iovec_t *ri_data, | ||
| 624 | size_t ri_data_len, | ||
| 625 | __wasi_riflags_t ri_flags, | ||
| 626 | __wasi_size_t *retptr0, | ||
| 627 | __wasi_roflags_t *retptr1 | ||
| 628 | ){ | ||
| 629 | 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); | ||
| 630 | return (uint16_t) ret; | ||
| 631 | } | ||
| 632 | |||
| 633 | int32_t __imported_wasi_snapshot_preview1_sock_send(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) __attribute__(( | ||
| 634 | __import_module__("wasi_snapshot_preview1"), | ||
| 635 | __import_name__("sock_send") | ||
| 636 | )); | ||
| 637 | |||
| 638 | __wasi_errno_t __wasi_sock_send( | ||
| 639 | __wasi_fd_t fd, | ||
| 640 | const __wasi_ciovec_t *si_data, | ||
| 641 | size_t si_data_len, | ||
| 642 | __wasi_siflags_t si_flags, | ||
| 643 | __wasi_size_t *retptr0 | ||
| 644 | ){ | ||
| 645 | 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); | ||
| 646 | return (uint16_t) ret; | ||
| 647 | } | ||
| 648 | |||
| 649 | int32_t __imported_wasi_snapshot_preview1_sock_shutdown(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 650 | __import_module__("wasi_snapshot_preview1"), | ||
| 651 | __import_name__("sock_shutdown") | ||
| 652 | )); | ||
| 653 | |||
| 654 | __wasi_errno_t __wasi_sock_shutdown( | ||
| 655 | __wasi_fd_t fd, | ||
| 656 | __wasi_sdflags_t how | ||
| 657 | ){ | ||
| 658 | int32_t ret = __imported_wasi_snapshot_preview1_sock_shutdown((int32_t) fd, how); | ||
| 659 | return (uint16_t) ret; | ||
| 660 | } | ||
| 661 | |||
| 662 | #ifdef _REENTRANT | ||
| 663 | int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__(( | ||
| 664 | __import_module__("wasi"), | ||
| 665 | __import_name__("thread-spawn") | ||
| 666 | )); | ||
| 667 | |||
| 668 | int32_t __wasi_thread_spawn(void* start_arg) { | ||
| 669 | return __imported_wasi_thread_spawn((int32_t) start_arg); | ||
| 670 | } | ||
| 671 | #endif | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <wasi/libc.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int __wasilibc_nocwd___wasilibc_rmdirat(int fd, const char *path) { | ||
| 6 | __wasi_errno_t error = __wasi_path_remove_directory(fd, path); | ||
| 7 | if (error != 0) { | ||
| 8 | errno = error; | ||
| 9 | return -1; | ||
| 10 | } | ||
| 11 | return 0; | ||
| 12 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_tell.c deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | off_t __wasilibc_tell(int fildes) { | ||
| 5 | __wasi_filesize_t offset; | ||
| 6 | __wasi_errno_t error = __wasi_fd_tell(fildes, &offset); | ||
| 7 | if (error != 0) { | ||
| 8 | // lseek returns ESPIPE on when called on a pipe, socket, or fifo, | ||
| 9 | // which on WASI would translate into ENOTCAPABLE. | ||
| 10 | errno = error == ENOTCAPABLE ? ESPIPE : error; | ||
| 11 | return -1; | ||
| 12 | } | ||
| 13 | return offset; | ||
| 14 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <wasi/libc.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) { | ||
| 6 | __wasi_errno_t error = __wasi_path_unlink_file(fd, path); | ||
| 7 | if (error != 0) { | ||
| 8 | errno = error; | ||
| 9 | return -1; | ||
| 10 | } | ||
| 11 | return 0; | ||
| 12 | } | ||
lib/libc/wasi/libc-bottom-half/sources/abort.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | void abort(void) { | ||
| 4 | // wasm doesn't support signals, so just trap to halt the program. | ||
| 5 | __builtin_trap(); | ||
| 6 | } | ||
lib/libc/wasi/libc-bottom-half/sources/accept-wasip1.c deleted-51| ... | @@ -1,51 +0,0 @@ | ||
| 1 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 2 | |||
| 3 | #include <sys/socket.h> | ||
| 4 | |||
| 5 | #include <assert.h> | ||
| 6 | #include <wasi/api.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <string.h> | ||
| 9 | |||
| 10 | int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) { | ||
| 11 | int ret = -1; | ||
| 12 | |||
| 13 | __wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret); | ||
| 14 | |||
| 15 | if (error != 0) { | ||
| 16 | errno = error; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | |||
| 20 | // Clear sockaddr to indicate undefined address | ||
| 21 | memset(addr, 0, *addrlen); | ||
| 22 | // might be AF_UNIX or AF_INET | ||
| 23 | addr->sa_family = AF_UNSPEC; | ||
| 24 | *addrlen = sizeof(struct sockaddr); | ||
| 25 | |||
| 26 | return ret; | ||
| 27 | } | ||
| 28 | |||
| 29 | int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) { | ||
| 30 | int ret = -1; | ||
| 31 | |||
| 32 | if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) { | ||
| 33 | errno = EINVAL; | ||
| 34 | return -1; | ||
| 35 | } | ||
| 36 | |||
| 37 | __wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret); | ||
| 38 | |||
| 39 | if (error != 0) { | ||
| 40 | errno = error; | ||
| 41 | return -1; | ||
| 42 | } | ||
| 43 | |||
| 44 | // Clear sockaddr to indicate undefined address | ||
| 45 | memset(addr, 0, *addrlen); | ||
| 46 | // might be AF_UNIX or AF_INET | ||
| 47 | addr->sa_family = AF_UNSPEC; | ||
| 48 | *addrlen = sizeof(struct sockaddr); | ||
| 49 | |||
| 50 | return ret; | ||
| 51 | } | ||
lib/libc/wasi/libc-bottom-half/sources/at_fdcwd.c deleted-141| ... | @@ -1,141 +0,0 @@ | ||
| 1 | // Handle AT_FDCWD and absolute paths for the *at functions. | ||
| 2 | // | ||
| 3 | // In the case of an AT_FDCWD file descriptor or an absolute path, call the | ||
| 4 | // corresponding non-`at` function. This will send it through the libpreopen | ||
| 5 | // wrappers to convert the path into a directory file descriptor and relative | ||
| 6 | // path before translating it into the corresponding `__wasilibc_nocwd_*at` | ||
| 7 | // function, which then calls the appropriate WASI function. | ||
| 8 | |||
| 9 | #include <fcntl.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <unistd.h> | ||
| 12 | #include <dirent.h> | ||
| 13 | #include <sys/types.h> | ||
| 14 | #include <sys/stat.h> | ||
| 15 | #include <wasi/libc.h> | ||
| 16 | #include <wasi/libc-nocwd.h> | ||
| 17 | |||
| 18 | // If the platform doesn't define O_TMPFILE, we don't need to worry about it. | ||
| 19 | #ifndef O_TMPFILE | ||
| 20 | #define O_TMPFILE 0 | ||
| 21 | #endif | ||
| 22 | |||
| 23 | int openat(int dirfd, const char *pathname, int flags, ...) { | ||
| 24 | if (dirfd == AT_FDCWD || pathname[0] == '/') { | ||
| 25 | return open(pathname, flags); | ||
| 26 | } | ||
| 27 | |||
| 28 | return __wasilibc_nocwd_openat_nomode(dirfd, pathname, flags); | ||
| 29 | } | ||
| 30 | |||
| 31 | int symlinkat(const char *target, int dirfd, const char *linkpath) { | ||
| 32 | if (dirfd == AT_FDCWD || linkpath[0] == '/') { | ||
| 33 | return symlink(target, linkpath); | ||
| 34 | } | ||
| 35 | |||
| 36 | return __wasilibc_nocwd_symlinkat(target, dirfd, linkpath); | ||
| 37 | } | ||
| 38 | |||
| 39 | ssize_t readlinkat(int dirfd, const char *__restrict pathname, char *__restrict buf, size_t bufsiz) { | ||
| 40 | if (dirfd == AT_FDCWD || pathname[0] == '/') { | ||
| 41 | return readlink(pathname, buf, bufsiz); | ||
| 42 | } | ||
| 43 | |||
| 44 | return __wasilibc_nocwd_readlinkat(dirfd, pathname, buf, bufsiz); | ||
| 45 | } | ||
| 46 | |||
| 47 | int mkdirat(int dirfd, const char *pathname, mode_t mode) { | ||
| 48 | if (dirfd == AT_FDCWD || pathname[0] == '/') { | ||
| 49 | return mkdir(pathname, mode); | ||
| 50 | } | ||
| 51 | |||
| 52 | return __wasilibc_nocwd_mkdirat_nomode(dirfd, pathname); | ||
| 53 | } | ||
| 54 | |||
| 55 | DIR *opendirat(int dirfd, const char *path) { | ||
| 56 | if (dirfd == AT_FDCWD || path[0] == '/') { | ||
| 57 | return opendir(path); | ||
| 58 | } | ||
| 59 | |||
| 60 | return __wasilibc_nocwd_opendirat(dirfd, path); | ||
| 61 | } | ||
| 62 | |||
| 63 | int scandirat(int dirfd, const char *dirp, struct dirent ***namelist, | ||
| 64 | int (*filter)(const struct dirent *), | ||
| 65 | int (*compar)(const struct dirent **, const struct dirent **)) { | ||
| 66 | if (dirfd == AT_FDCWD || dirp[0] == '/') { | ||
| 67 | return scandir(dirp, namelist, filter, compar); | ||
| 68 | } | ||
| 69 | |||
| 70 | return __wasilibc_nocwd_scandirat(dirfd, dirp, namelist, filter, compar); | ||
| 71 | } | ||
| 72 | |||
| 73 | int faccessat(int dirfd, const char *pathname, int mode, int flags) { | ||
| 74 | if (dirfd == AT_FDCWD || pathname[0] == '/') { | ||
| 75 | return __wasilibc_access(pathname, mode, flags); | ||
| 76 | } | ||
| 77 | |||
| 78 | return __wasilibc_nocwd_faccessat(dirfd, pathname, mode, flags); | ||
| 79 | } | ||
| 80 | |||
| 81 | int fstatat(int dirfd, const char *__restrict pathname, struct stat *__restrict statbuf, int flags) { | ||
| 82 | if (dirfd == AT_FDCWD || pathname[0] == '/') { | ||
| 83 | return __wasilibc_stat(pathname, statbuf, flags); | ||
| 84 | } | ||
| 85 | |||
| 86 | return __wasilibc_nocwd_fstatat(dirfd, pathname, statbuf, flags); | ||
| 87 | } | ||
| 88 | |||
| 89 | int utimensat(int dirfd, const char *pathname, const struct timespec times[2], int flags) { | ||
| 90 | if (dirfd == AT_FDCWD || pathname[0] == '/') { | ||
| 91 | return __wasilibc_utimens(pathname, times, flags); | ||
| 92 | } | ||
| 93 | |||
| 94 | return __wasilibc_nocwd_utimensat(dirfd, pathname, times, flags); | ||
| 95 | } | ||
| 96 | |||
| 97 | int linkat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath, int flags) { | ||
| 98 | if ((olddirfd == AT_FDCWD || oldpath[0] == '/') && | ||
| 99 | (newdirfd == AT_FDCWD || newpath[0] == '/')) { | ||
| 100 | return __wasilibc_link(oldpath, newpath, flags); | ||
| 101 | } | ||
| 102 | if (olddirfd == AT_FDCWD || oldpath[0] == '/') { | ||
| 103 | return __wasilibc_link_newat(oldpath, newdirfd, newpath, flags); | ||
| 104 | } | ||
| 105 | if (newdirfd == AT_FDCWD || newpath[0] == '/') { | ||
| 106 | return __wasilibc_link_oldat(olddirfd, oldpath, newpath, flags); | ||
| 107 | } | ||
| 108 | |||
| 109 | return __wasilibc_nocwd_linkat(olddirfd, oldpath, newdirfd, newpath, flags); | ||
| 110 | } | ||
| 111 | |||
| 112 | int renameat(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) { | ||
| 113 | if ((olddirfd == AT_FDCWD || oldpath[0] == '/') && | ||
| 114 | (newdirfd == AT_FDCWD || newpath[0] == '/')) { | ||
| 115 | return rename(oldpath, newpath); | ||
| 116 | } | ||
| 117 | if (olddirfd == AT_FDCWD || oldpath[0] == '/') { | ||
| 118 | return __wasilibc_rename_newat(oldpath, newdirfd, newpath); | ||
| 119 | } | ||
| 120 | if (newdirfd == AT_FDCWD || newpath[0] == '/') { | ||
| 121 | return __wasilibc_rename_oldat(olddirfd, oldpath, newpath); | ||
| 122 | } | ||
| 123 | |||
| 124 | return __wasilibc_nocwd_renameat(olddirfd, oldpath, newdirfd, newpath); | ||
| 125 | } | ||
| 126 | |||
| 127 | int __wasilibc_unlinkat(int dirfd, const char *path) { | ||
| 128 | if (dirfd == AT_FDCWD || path[0] == '/') { | ||
| 129 | return unlink(path); | ||
| 130 | } | ||
| 131 | |||
| 132 | return __wasilibc_nocwd___wasilibc_unlinkat(dirfd, path); | ||
| 133 | } | ||
| 134 | |||
| 135 | int __wasilibc_rmdirat(int dirfd, const char *path) { | ||
| 136 | if (dirfd == AT_FDCWD || path[0] == '/') { | ||
| 137 | return rmdir(path); | ||
| 138 | } | ||
| 139 | |||
| 140 | return __wasilibc_nocwd___wasilibc_rmdirat(dirfd, path); | ||
| 141 | } | ||
lib/libc/wasi/libc-bottom-half/sources/chdir.c deleted-171| ... | @@ -1,171 +0,0 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <sys/stat.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <wasi/libc-find-relpath.h> | ||
| 9 | #include <wasi/libc.h> | ||
| 10 | |||
| 11 | #ifdef _REENTRANT | ||
| 12 | void __wasilibc_cwd_lock(void); | ||
| 13 | void __wasilibc_cwd_unlock(void); | ||
| 14 | #else | ||
| 15 | #define __wasilibc_cwd_lock() (void)0 | ||
| 16 | #define __wasilibc_cwd_unlock() (void)0 | ||
| 17 | #endif | ||
| 18 | extern char *__wasilibc_cwd; | ||
| 19 | static int __wasilibc_cwd_mallocd = 0; | ||
| 20 | |||
| 21 | int chdir(const char *path) | ||
| 22 | { | ||
| 23 | static char *relative_buf = NULL; | ||
| 24 | static size_t relative_buf_len = 0; | ||
| 25 | |||
| 26 | // Find a preopen'd directory as well as a relative path we're anchored | ||
| 27 | // from which we're changing directories to. | ||
| 28 | const char *abs; | ||
| 29 | int parent_fd = __wasilibc_find_relpath_alloc(path, &abs, &relative_buf, &relative_buf_len, 1); | ||
| 30 | if (parent_fd == -1) | ||
| 31 | return -1; | ||
| 32 | |||
| 33 | // Make sure that this directory we're accessing is indeed a directory. | ||
| 34 | struct stat dirinfo; | ||
| 35 | int ret = fstatat(parent_fd, relative_buf, &dirinfo, 0); | ||
| 36 | if (ret == -1) | ||
| 37 | return -1; | ||
| 38 | if (!S_ISDIR(dirinfo.st_mode)) { | ||
| 39 | errno = ENOTDIR; | ||
| 40 | return -1; | ||
| 41 | } | ||
| 42 | |||
| 43 | // Create a string that looks like: | ||
| 44 | // | ||
| 45 | // __wasilibc_cwd = "/" + abs + "/" + relative_buf | ||
| 46 | // | ||
| 47 | // If `relative_buf` is equal to "." or `abs` is equal to the empty string, | ||
| 48 | // however, we skip that part and the middle slash. | ||
| 49 | size_t abs_len = strlen(abs); | ||
| 50 | int copy_relative = strcmp(relative_buf, ".") != 0; | ||
| 51 | int mid = copy_relative && abs[0] != 0; | ||
| 52 | char *new_cwd = malloc(1 + abs_len + mid + (copy_relative ? strlen(relative_buf) : 0) + 1); | ||
| 53 | if (new_cwd == NULL) { | ||
| 54 | errno = ENOMEM; | ||
| 55 | return -1; | ||
| 56 | } | ||
| 57 | new_cwd[0] = '/'; | ||
| 58 | strcpy(new_cwd + 1, abs); | ||
| 59 | if (mid) | ||
| 60 | new_cwd[1 + abs_len] = '/'; | ||
| 61 | if (copy_relative) | ||
| 62 | strcpy(new_cwd + 1 + abs_len + mid, relative_buf); | ||
| 63 | |||
| 64 | // And set our new malloc'd buffer into the global cwd, freeing the | ||
| 65 | // previous one if necessary. | ||
| 66 | __wasilibc_cwd_lock(); | ||
| 67 | char *prev_cwd = __wasilibc_cwd; | ||
| 68 | __wasilibc_cwd = new_cwd; | ||
| 69 | __wasilibc_cwd_unlock(); | ||
| 70 | if (__wasilibc_cwd_mallocd) | ||
| 71 | free(prev_cwd); | ||
| 72 | __wasilibc_cwd_mallocd = 1; | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | static const char *make_absolute(const char *path) { | ||
| 77 | static char *make_absolute_buf = NULL; | ||
| 78 | static size_t make_absolute_len = 0; | ||
| 79 | |||
| 80 | // If this path is absolute, then we return it as-is. | ||
| 81 | if (path[0] == '/') { | ||
| 82 | return path; | ||
| 83 | } | ||
| 84 | |||
| 85 | #ifndef _REENTRANT | ||
| 86 | // If the path is empty, or points to the current directory, then return | ||
| 87 | // the current directory. | ||
| 88 | if (path[0] == 0 || !strcmp(path, ".") || !strcmp(path, "./")) { | ||
| 89 | return __wasilibc_cwd; | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | // If the path starts with `./` then we won't be appending that to the cwd. | ||
| 94 | if (path[0] == '.' && path[1] == '/') | ||
| 95 | path += 2; | ||
| 96 | |||
| 97 | // Otherwise we'll take the current directory, add a `/`, and then add the | ||
| 98 | // input `path`. Note that this doesn't do any normalization (like removing | ||
| 99 | // `/./`). | ||
| 100 | __wasilibc_cwd_lock(); | ||
| 101 | size_t cwd_len = strlen(__wasilibc_cwd); | ||
| 102 | size_t path_len = path ? strlen(path) : 0; | ||
| 103 | __wasilibc_cwd_unlock(); | ||
| 104 | int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1; | ||
| 105 | size_t alloc_len = cwd_len + path_len + 1 + need_slash; | ||
| 106 | if (alloc_len > make_absolute_len) { | ||
| 107 | char *tmp = realloc(make_absolute_buf, alloc_len); | ||
| 108 | if (tmp == NULL) { | ||
| 109 | __wasilibc_cwd_unlock(); | ||
| 110 | return NULL; | ||
| 111 | } | ||
| 112 | make_absolute_buf = tmp; | ||
| 113 | make_absolute_len = alloc_len; | ||
| 114 | } | ||
| 115 | strcpy(make_absolute_buf, __wasilibc_cwd); | ||
| 116 | __wasilibc_cwd_unlock(); | ||
| 117 | |||
| 118 | #ifdef _REENTRANT | ||
| 119 | if (path[0] == 0 || !strcmp(path, ".") || !strcmp(path, "./")) { | ||
| 120 | return make_absolute_buf; | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | |||
| 124 | if (need_slash) | ||
| 125 | strcpy(make_absolute_buf + cwd_len, "/"); | ||
| 126 | strcpy(make_absolute_buf + cwd_len + need_slash, path); | ||
| 127 | return make_absolute_buf; | ||
| 128 | } | ||
| 129 | |||
| 130 | // Helper function defined only in this object file and weakly referenced from | ||
| 131 | // `preopens.c` and `posix.c` This function isn't necessary unless `chdir` is | ||
| 132 | // pulled in because all paths are otherwise absolute or relative to the root. | ||
| 133 | int __wasilibc_find_relpath_alloc( | ||
| 134 | const char *path, | ||
| 135 | const char **abs_prefix, | ||
| 136 | char **relative_buf, | ||
| 137 | size_t *relative_buf_len, | ||
| 138 | int can_realloc | ||
| 139 | ) { | ||
| 140 | // First, make our path absolute taking the cwd into account. | ||
| 141 | const char *abspath = make_absolute(path); | ||
| 142 | if (abspath == NULL) { | ||
| 143 | errno = ENOMEM; | ||
| 144 | return -1; | ||
| 145 | } | ||
| 146 | |||
| 147 | // Next use our absolute path and split it. Find the preopened `fd` parent | ||
| 148 | // directory and set `abs_prefix`. Next up we'll be trying to fit `rel` | ||
| 149 | // into `relative_buf`. | ||
| 150 | const char *rel; | ||
| 151 | int fd = __wasilibc_find_abspath(abspath, abs_prefix, &rel); | ||
| 152 | if (fd == -1) | ||
| 153 | return -1; | ||
| 154 | |||
| 155 | size_t rel_len = strlen(rel); | ||
| 156 | if (*relative_buf_len < rel_len + 1) { | ||
| 157 | if (!can_realloc) { | ||
| 158 | errno = ERANGE; | ||
| 159 | return -1; | ||
| 160 | } | ||
| 161 | char *tmp = realloc(*relative_buf, rel_len + 1); | ||
| 162 | if (tmp == NULL) { | ||
| 163 | errno = ENOMEM; | ||
| 164 | return -1; | ||
| 165 | } | ||
| 166 | *relative_buf = tmp; | ||
| 167 | *relative_buf_len = rel_len + 1; | ||
| 168 | } | ||
| 169 | strcpy(*relative_buf, rel); | ||
| 170 | return fd; | ||
| 171 | } | ||
lib/libc/wasi/libc-bottom-half/sources/complex-builtins.c deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | // Each of the following complex functions can be implemented with a single | ||
| 2 | // wasm instruction, so use that implementation rather than the portable | ||
| 3 | // one in libm. | ||
| 4 | |||
| 5 | #include <complex.h> | ||
| 6 | |||
| 7 | float (crealf)(float _Complex x) { | ||
| 8 | return __builtin_crealf(x); | ||
| 9 | } | ||
| 10 | |||
| 11 | double (creal)(double _Complex x) { | ||
| 12 | return __builtin_creal(x); | ||
| 13 | } | ||
| 14 | |||
| 15 | long double (creall)(long double _Complex x) { | ||
| 16 | return __builtin_creall(x); | ||
| 17 | } | ||
| 18 | |||
| 19 | float (cimagf)(float _Complex x) { | ||
| 20 | return __builtin_cimagf(x); | ||
| 21 | } | ||
| 22 | |||
| 23 | double (cimag)(double _Complex x) { | ||
| 24 | return __builtin_cimag(x); | ||
| 25 | } | ||
| 26 | |||
| 27 | long double (cimagl)(long double _Complex x) { | ||
| 28 | return __builtin_cimagl(x); | ||
| 29 | } | ||
lib/libc/wasi/libc-bottom-half/sources/environ.c deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sysexits.h> | ||
| 4 | #include <wasi/api.h> | ||
| 5 | #include <wasi/libc.h> | ||
| 6 | #include <wasi/libc-environ.h> | ||
| 7 | |||
| 8 | // If the program does use `environ`, it'll get this version of | ||
| 9 | // `__wasilibc_environ`, which is initialized with a constructor function, so | ||
| 10 | // that it's initialized whenever user code might want to access it. | ||
| 11 | char **__wasilibc_environ; | ||
| 12 | weak_alias(__wasilibc_environ, _environ); | ||
| 13 | weak_alias(__wasilibc_environ, environ); | ||
| 14 | |||
| 15 | // We define this function here in the same source file as | ||
| 16 | // `__wasilibc_environ`, so that this function is called in iff environment | ||
| 17 | // variable support is used. | ||
| 18 | // Concerning the 50 -- levels up to 100 are reserved for the implementation, | ||
| 19 | // so we an arbitrary number in the middle of the range to allow other | ||
| 20 | // reserved things to go before or after. | ||
| 21 | __attribute__((constructor(50))) | ||
| 22 | static void __wasilibc_initialize_environ_eagerly(void) { | ||
| 23 | __wasilibc_initialize_environ(); | ||
| 24 | } | ||
| 25 | |||
| 26 | // See the comments in libc-environ.h. | ||
| 27 | void __wasilibc_maybe_reinitialize_environ_eagerly(void) { | ||
| 28 | // This translation unit is linked in if `environ` is used, meaning we need | ||
| 29 | // to eagerly reinitialize the environment variables. | ||
| 30 | __wasilibc_initialize_environ(); | ||
| 31 | } | ||
lib/libc/wasi/libc-bottom-half/sources/errno.c deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | |||
| 3 | // These values are used by reference-sysroot's dlmalloc. | ||
| 4 | const int __EINVAL = EINVAL; | ||
| 5 | const int __ENOMEM = ENOMEM; | ||
lib/libc/wasi/libc-bottom-half/sources/getcwd.c deleted-39| ... | @@ -1,39 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "lock.h" | ||
| 5 | |||
| 6 | char *__wasilibc_cwd = "/"; | ||
| 7 | |||
| 8 | #ifdef _REENTRANT | ||
| 9 | static volatile int lock[1]; | ||
| 10 | void __wasilibc_cwd_lock(void) { LOCK(lock); } | ||
| 11 | void __wasilibc_cwd_unlock(void) { UNLOCK(lock); } | ||
| 12 | #else | ||
| 13 | #define __wasilibc_cwd_lock() (void)0 | ||
| 14 | #define __wasilibc_cwd_unlock() (void)0 | ||
| 15 | #endif | ||
| 16 | |||
| 17 | char *getcwd(char *buf, size_t size) | ||
| 18 | { | ||
| 19 | __wasilibc_cwd_lock(); | ||
| 20 | if (!buf) { | ||
| 21 | buf = strdup(__wasilibc_cwd); | ||
| 22 | if (!buf) { | ||
| 23 | errno = ENOMEM; | ||
| 24 | __wasilibc_cwd_unlock(); | ||
| 25 | return NULL; | ||
| 26 | } | ||
| 27 | } else { | ||
| 28 | size_t len = strlen(__wasilibc_cwd); | ||
| 29 | if (size < len + 1) { | ||
| 30 | errno = ERANGE; | ||
| 31 | __wasilibc_cwd_unlock(); | ||
| 32 | return NULL; | ||
| 33 | } | ||
| 34 | strcpy(buf, __wasilibc_cwd); | ||
| 35 | } | ||
| 36 | __wasilibc_cwd_unlock(); | ||
| 37 | return buf; | ||
| 38 | } | ||
| 39 | |||
lib/libc/wasi/libc-bottom-half/sources/getentropy.c deleted-26| ... | @@ -1,26 +0,0 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #ifdef __wasilibc_use_wasip2 | ||
| 4 | #include <wasi/libc.h> | ||
| 5 | #else | ||
| 6 | #include <wasi/api.h> | ||
| 7 | #endif | ||
| 8 | |||
| 9 | int __getentropy(void *buffer, size_t len) { | ||
| 10 | if (len > 256) { | ||
| 11 | errno = EIO; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | |||
| 15 | #ifdef __wasilibc_use_wasip2 | ||
| 16 | int r = __wasilibc_random(buffer, len); | ||
| 17 | #else | ||
| 18 | int r = __wasi_random_get(buffer, len); | ||
| 19 | #endif | ||
| 20 | if (r != 0) { | ||
| 21 | errno = r; | ||
| 22 | return -1; | ||
| 23 | } | ||
| 24 | return 0; | ||
| 25 | } | ||
| 26 | weak_alias(__getentropy, getentropy); | ||
lib/libc/wasi/libc-bottom-half/sources/isatty.c deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <__errno.h> | ||
| 3 | #include <__function___isatty.h> | ||
| 4 | |||
| 5 | int __isatty(int fd) { | ||
| 6 | __wasi_fdstat_t statbuf; | ||
| 7 | int r = __wasi_fd_fdstat_get(fd, &statbuf); | ||
| 8 | if (r != 0) { | ||
| 9 | errno = r; | ||
| 10 | return 0; | ||
| 11 | } | ||
| 12 | |||
| 13 | // A tty is a character device that we can't seek or tell on. | ||
| 14 | if (statbuf.fs_filetype != __WASI_FILETYPE_CHARACTER_DEVICE || | ||
| 15 | (statbuf.fs_rights_base & (__WASI_RIGHTS_FD_SEEK | __WASI_RIGHTS_FD_TELL)) != 0) { | ||
| 16 | errno = __WASI_ERRNO_NOTTY; | ||
| 17 | return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | return 1; | ||
| 21 | } | ||
| 22 | extern __typeof(__isatty) isatty __attribute__((weak, alias("__isatty"))); | ||
lib/libc/wasi/libc-bottom-half/sources/math/math-builtins.c deleted-69| ... | @@ -1,69 +0,0 @@ | ||
| 1 | // Each of the following math functions can be implemented with a single | ||
| 2 | // wasm instruction, so use that implementation rather than the portable | ||
| 3 | // one in libm. | ||
| 4 | |||
| 5 | #include <math.h> | ||
| 6 | |||
| 7 | float fabsf(float x) { | ||
| 8 | return __builtin_fabsf(x); | ||
| 9 | } | ||
| 10 | |||
| 11 | double fabs(double x) { | ||
| 12 | return __builtin_fabs(x); | ||
| 13 | } | ||
| 14 | |||
| 15 | float sqrtf(float x) { | ||
| 16 | return __builtin_sqrtf(x); | ||
| 17 | } | ||
| 18 | |||
| 19 | double sqrt(double x) { | ||
| 20 | return __builtin_sqrt(x); | ||
| 21 | } | ||
| 22 | |||
| 23 | float copysignf(float x, float y) { | ||
| 24 | return __builtin_copysignf(x, y); | ||
| 25 | } | ||
| 26 | |||
| 27 | double copysign(double x, double y) { | ||
| 28 | return __builtin_copysign(x, y); | ||
| 29 | } | ||
| 30 | |||
| 31 | float ceilf(float x) { | ||
| 32 | return __builtin_ceilf(x); | ||
| 33 | } | ||
| 34 | |||
| 35 | double ceil(double x) { | ||
| 36 | return __builtin_ceil(x); | ||
| 37 | } | ||
| 38 | |||
| 39 | float floorf(float x) { | ||
| 40 | return __builtin_floorf(x); | ||
| 41 | } | ||
| 42 | |||
| 43 | double floor(double x) { | ||
| 44 | return __builtin_floor(x); | ||
| 45 | } | ||
| 46 | |||
| 47 | float truncf(float x) { | ||
| 48 | return __builtin_truncf(x); | ||
| 49 | } | ||
| 50 | |||
| 51 | double trunc(double x) { | ||
| 52 | return __builtin_trunc(x); | ||
| 53 | } | ||
| 54 | |||
| 55 | float nearbyintf(float x) { | ||
| 56 | return __builtin_nearbyintf(x); | ||
| 57 | } | ||
| 58 | |||
| 59 | double nearbyint(double x) { | ||
| 60 | return __builtin_nearbyint(x); | ||
| 61 | } | ||
| 62 | |||
| 63 | float rintf(float x) { | ||
| 64 | return __builtin_rintf(x); | ||
| 65 | } | ||
| 66 | |||
| 67 | double rint(double x) { | ||
| 68 | return __builtin_rint(x); | ||
| 69 | } | ||
lib/libc/wasi/libc-bottom-half/sources/posix.c deleted-490| ... | @@ -1,490 +0,0 @@ | ||
| 1 | //! POSIX-like functions supporting absolute path arguments, implemented in | ||
| 2 | //! terms of `__wasilibc_find_relpath` and `*at`-style functions. | ||
| 3 | |||
| 4 | #include <errno.h> | ||
| 5 | #include <dirent.h> | ||
| 6 | #include <fcntl.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <sys/stat.h> | ||
| 9 | #include <sys/statvfs.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <utime.h> | ||
| 12 | #include <wasi/libc.h> | ||
| 13 | #include <wasi/libc-find-relpath.h> | ||
| 14 | #include <wasi/libc-nocwd.h> | ||
| 15 | |||
| 16 | static int find_relpath2( | ||
| 17 | const char *path, | ||
| 18 | char **relative, | ||
| 19 | size_t *relative_len | ||
| 20 | ) { | ||
| 21 | // See comments in `preopens.c` for what this trick is doing. | ||
| 22 | const char *abs; | ||
| 23 | if (__wasilibc_find_relpath_alloc) | ||
| 24 | return __wasilibc_find_relpath_alloc(path, &abs, relative, relative_len, 1); | ||
| 25 | return __wasilibc_find_relpath(path, &abs, relative, *relative_len); | ||
| 26 | } | ||
| 27 | |||
| 28 | // Helper to call `__wasilibc_find_relpath` and return an already-managed | ||
| 29 | // pointer for the `relative` path. This function is not reentrant since the | ||
| 30 | // `relative` pointer will point to static data that cannot be reused until | ||
| 31 | // `relative` is no longer used. | ||
| 32 | static int find_relpath(const char *path, char **relative) { | ||
| 33 | static __thread char *relative_buf = NULL; | ||
| 34 | static __thread size_t relative_buf_len = 0; | ||
| 35 | int fd = find_relpath2(path, &relative_buf, &relative_buf_len); | ||
| 36 | // find_relpath2 can update relative_buf, so assign it after the call | ||
| 37 | *relative = relative_buf; | ||
| 38 | return fd; | ||
| 39 | } | ||
| 40 | |||
| 41 | // same as `find_relpath`, but uses another set of static variables to cache | ||
| 42 | static int find_relpath_alt(const char *path, char **relative) { | ||
| 43 | static __thread char *relative_buf = NULL; | ||
| 44 | static __thread size_t relative_buf_len = 0; | ||
| 45 | int fd = find_relpath2(path, &relative_buf, &relative_buf_len); | ||
| 46 | // find_relpath2 can update relative_buf, so assign it after the call | ||
| 47 | *relative = relative_buf; | ||
| 48 | return fd; | ||
| 49 | } | ||
| 50 | |||
| 51 | int open(const char *path, int oflag, ...) { | ||
| 52 | // WASI libc's `openat` ignores the mode argument, so call a special | ||
| 53 | // entrypoint which avoids the varargs calling convention. | ||
| 54 | return __wasilibc_open_nomode(path, oflag); | ||
| 55 | } | ||
| 56 | |||
| 57 | // See the documentation in libc.h | ||
| 58 | int __wasilibc_open_nomode(const char *path, int oflag) { | ||
| 59 | char *relative_path; | ||
| 60 | int dirfd = find_relpath(path, &relative_path); | ||
| 61 | |||
| 62 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 63 | if (dirfd == -1) { | ||
| 64 | errno = ENOENT; | ||
| 65 | return -1; | ||
| 66 | } | ||
| 67 | |||
| 68 | return __wasilibc_nocwd_openat_nomode(dirfd, relative_path, oflag); | ||
| 69 | } | ||
| 70 | |||
| 71 | int access(const char *path, int amode) { | ||
| 72 | char *relative_path; | ||
| 73 | int dirfd = find_relpath(path, &relative_path); | ||
| 74 | |||
| 75 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 76 | if (dirfd == -1) { | ||
| 77 | errno = ENOENT; | ||
| 78 | return -1; | ||
| 79 | } | ||
| 80 | |||
| 81 | return __wasilibc_nocwd_faccessat(dirfd, relative_path, amode, 0); | ||
| 82 | } | ||
| 83 | |||
| 84 | ssize_t readlink( | ||
| 85 | const char *restrict path, | ||
| 86 | char *restrict buf, | ||
| 87 | size_t bufsize) | ||
| 88 | { | ||
| 89 | char *relative_path; | ||
| 90 | int dirfd = find_relpath(path, &relative_path); | ||
| 91 | |||
| 92 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 93 | if (dirfd == -1) { | ||
| 94 | errno = ENOENT; | ||
| 95 | return -1; | ||
| 96 | } | ||
| 97 | |||
| 98 | return __wasilibc_nocwd_readlinkat(dirfd, relative_path, buf, bufsize); | ||
| 99 | } | ||
| 100 | |||
| 101 | int stat(const char *restrict path, struct stat *restrict buf) { | ||
| 102 | char *relative_path; | ||
| 103 | int dirfd = find_relpath(path, &relative_path); | ||
| 104 | |||
| 105 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 106 | if (dirfd == -1) { | ||
| 107 | errno = ENOENT; | ||
| 108 | return -1; | ||
| 109 | } | ||
| 110 | |||
| 111 | return __wasilibc_nocwd_fstatat(dirfd, relative_path, buf, 0); | ||
| 112 | } | ||
| 113 | |||
| 114 | int lstat(const char *restrict path, struct stat *restrict buf) { | ||
| 115 | char *relative_path; | ||
| 116 | int dirfd = find_relpath(path, &relative_path); | ||
| 117 | |||
| 118 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 119 | if (dirfd == -1) { | ||
| 120 | errno = ENOENT; | ||
| 121 | return -1; | ||
| 122 | } | ||
| 123 | |||
| 124 | return __wasilibc_nocwd_fstatat(dirfd, relative_path, buf, AT_SYMLINK_NOFOLLOW); | ||
| 125 | } | ||
| 126 | |||
| 127 | int utime(const char *path, const struct utimbuf *times) { | ||
| 128 | char *relative_path; | ||
| 129 | int dirfd = find_relpath(path, &relative_path); | ||
| 130 | |||
| 131 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 132 | if (dirfd == -1) { | ||
| 133 | errno = ENOENT; | ||
| 134 | return -1; | ||
| 135 | } | ||
| 136 | |||
| 137 | return __wasilibc_nocwd_utimensat( | ||
| 138 | dirfd, relative_path, | ||
| 139 | times ? ((struct timespec [2]) { | ||
| 140 | { .tv_sec = times->actime }, | ||
| 141 | { .tv_sec = times->modtime } | ||
| 142 | }) | ||
| 143 | : NULL, | ||
| 144 | 0); | ||
| 145 | } | ||
| 146 | |||
| 147 | int utimes(const char *path, const struct timeval times[2]) { | ||
| 148 | char *relative_path; | ||
| 149 | int dirfd = find_relpath(path, &relative_path); | ||
| 150 | |||
| 151 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 152 | if (dirfd == -1) { | ||
| 153 | errno = ENOENT; | ||
| 154 | return -1; | ||
| 155 | } | ||
| 156 | |||
| 157 | return __wasilibc_nocwd_utimensat( | ||
| 158 | dirfd, relative_path, | ||
| 159 | times ? ((struct timespec [2]) { | ||
| 160 | { .tv_sec = times[0].tv_sec, | ||
| 161 | 				 .tv_nsec = times[0].tv_usec * 1000 }, | ||
| 162 | { .tv_sec = times[1].tv_sec, | ||
| 163 | 				 .tv_nsec = times[1].tv_usec * 1000 }, | ||
| 164 | }) | ||
| 165 | : NULL, | ||
| 166 | 0); | ||
| 167 | } | ||
| 168 | |||
| 169 | int unlink(const char *path) { | ||
| 170 | char *relative_path; | ||
| 171 | int dirfd = find_relpath(path, &relative_path); | ||
| 172 | |||
| 173 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 174 | if (dirfd == -1) { | ||
| 175 | errno = ENOENT; | ||
| 176 | return -1; | ||
| 177 | } | ||
| 178 | |||
| 179 | // `unlinkat` imports `__wasi_path_remove_directory` even when | ||
| 180 | // `AT_REMOVEDIR` isn't passed. Instead, use a specialized function which | ||
| 181 | // just imports `__wasi_path_unlink_file`. | ||
| 182 | return __wasilibc_nocwd___wasilibc_unlinkat(dirfd, relative_path); | ||
| 183 | } | ||
| 184 | |||
| 185 | int rmdir(const char *path) { | ||
| 186 | char *relative_path; | ||
| 187 | int dirfd = find_relpath(path, &relative_path); | ||
| 188 | |||
| 189 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 190 | if (dirfd == -1) { | ||
| 191 | errno = ENOENT; | ||
| 192 | return -1; | ||
| 193 | } | ||
| 194 | |||
| 195 | return __wasilibc_nocwd___wasilibc_rmdirat(dirfd, relative_path); | ||
| 196 | } | ||
| 197 | |||
| 198 | int remove(const char *path) { | ||
| 199 | char *relative_path; | ||
| 200 | int dirfd = find_relpath(path, &relative_path); | ||
| 201 | |||
| 202 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 203 | if (dirfd == -1) { | ||
| 204 | errno = ENOENT; | ||
| 205 | return -1; | ||
| 206 | } | ||
| 207 | |||
| 208 | // First try to remove it as a file. | ||
| 209 | int r = __wasilibc_nocwd___wasilibc_unlinkat(dirfd, relative_path); | ||
| 210 | if (r != 0 && (errno == EISDIR || errno == ENOENT)) { | ||
| 211 | // That failed, but it might be a directory. | ||
| 212 | r = __wasilibc_nocwd___wasilibc_rmdirat(dirfd, relative_path); | ||
| 213 | |||
| 214 | // If it isn't a directory, we lack capabilities to remove it as a file. | ||
| 215 | if (errno == ENOTDIR) | ||
| 216 | errno = ENOENT; | ||
| 217 | } | ||
| 218 | return r; | ||
| 219 | } | ||
| 220 | |||
| 221 | int mkdir(const char *path, mode_t mode) { | ||
| 222 | char *relative_path; | ||
| 223 | int dirfd = find_relpath(path, &relative_path); | ||
| 224 | |||
| 225 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 226 | if (dirfd == -1) { | ||
| 227 | errno = ENOENT; | ||
| 228 | return -1; | ||
| 229 | } | ||
| 230 | |||
| 231 | return __wasilibc_nocwd_mkdirat_nomode(dirfd, relative_path); | ||
| 232 | } | ||
| 233 | |||
| 234 | DIR *opendir(const char *dirname) { | ||
| 235 | char *relative_path; | ||
| 236 | int dirfd = find_relpath(dirname, &relative_path); | ||
| 237 | |||
| 238 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 239 | if (dirfd == -1) { | ||
| 240 | errno = ENOENT; | ||
| 241 | return NULL; | ||
| 242 | } | ||
| 243 | |||
| 244 | return __wasilibc_nocwd_opendirat(dirfd, relative_path); | ||
| 245 | } | ||
| 246 | |||
| 247 | int scandir( | ||
| 248 | const char *restrict dir, | ||
| 249 | struct dirent ***restrict namelist, | ||
| 250 | int (*filter)(const struct dirent *), | ||
| 251 | int (*compar)(const struct dirent **, const struct dirent **) | ||
| 252 | ) { | ||
| 253 | char *relative_path; | ||
| 254 | int dirfd = find_relpath(dir, &relative_path); | ||
| 255 | |||
| 256 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 257 | if (dirfd == -1) { | ||
| 258 | errno = ENOENT; | ||
| 259 | return -1; | ||
| 260 | } | ||
| 261 | |||
| 262 | return __wasilibc_nocwd_scandirat(dirfd, relative_path, namelist, filter, compar); | ||
| 263 | } | ||
| 264 | |||
| 265 | int symlink(const char *target, const char *linkpath) { | ||
| 266 | char *relative_path; | ||
| 267 | int dirfd = find_relpath(linkpath, &relative_path); | ||
| 268 | |||
| 269 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 270 | if (dirfd == -1) { | ||
| 271 | errno = ENOENT; | ||
| 272 | return -1; | ||
| 273 | } | ||
| 274 | |||
| 275 | return __wasilibc_nocwd_symlinkat(target, dirfd, relative_path); | ||
| 276 | } | ||
| 277 | |||
| 278 | int link(const char *old, const char *new) { | ||
| 279 | char *old_relative_path; | ||
| 280 | int old_dirfd = find_relpath_alt(old, &old_relative_path); | ||
| 281 | |||
| 282 | if (old_dirfd != -1) { | ||
| 283 | char *new_relative_path; | ||
| 284 | int new_dirfd = find_relpath(new, &new_relative_path); | ||
| 285 | |||
| 286 | if (new_dirfd != -1) | ||
| 287 | return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, | ||
| 288 | new_dirfd, new_relative_path, 0); | ||
| 289 | } | ||
| 290 | |||
| 291 | // We couldn't find a preopen for it; fail as if we can't find the path. | ||
| 292 | errno = ENOENT; | ||
| 293 | return -1; | ||
| 294 | } | ||
| 295 | |||
| 296 | int rename(const char *old, const char *new) { | ||
| 297 | char *old_relative_path; | ||
| 298 | int old_dirfd = find_relpath_alt(old, &old_relative_path); | ||
| 299 | |||
| 300 | if (old_dirfd != -1) { | ||
| 301 | char *new_relative_path; | ||
| 302 | int new_dirfd = find_relpath(new, &new_relative_path); | ||
| 303 | |||
| 304 | if (new_dirfd != -1) | ||
| 305 | return __wasilibc_nocwd_renameat(old_dirfd, old_relative_path, | ||
| 306 | new_dirfd, new_relative_path); | ||
| 307 | } | ||
| 308 | |||
| 309 | // We couldn't find a preopen for it; fail as if we can't find the path. | ||
| 310 | errno = ENOENT; | ||
| 311 | return -1; | ||
| 312 | } | ||
| 313 | |||
| 314 | int chmod(const char *path, mode_t mode) { | ||
| 315 | // TODO: We plan to support this eventually in WASI, but not yet. | ||
| 316 | // Meanwhile, we provide a stub so that libc++'s `<filesystem>` | ||
| 317 | // implementation will build unmodified. | ||
| 318 | errno = ENOSYS; | ||
| 319 | return -1; | ||
| 320 | } | ||
| 321 | |||
| 322 | int fchmod(int fd, mode_t mode) { | ||
| 323 | // TODO: We plan to support this eventually in WASI, but not yet. | ||
| 324 | // Meanwhile, we provide a stub so that libc++'s `<filesystem>` | ||
| 325 | // implementation will build unmodified. | ||
| 326 | errno = ENOSYS; | ||
| 327 | return -1; | ||
| 328 | } | ||
| 329 | |||
| 330 | int fchmodat(int fd, const char *path, mode_t mode, int flag) { | ||
| 331 | // TODO: We plan to support this eventually in WASI, but not yet. | ||
| 332 | // Meanwhile, we provide a stub so that libc++'s `<filesystem>` | ||
| 333 | // implementation will build unmodified. | ||
| 334 | errno = ENOSYS; | ||
| 335 | return -1; | ||
| 336 | } | ||
| 337 | |||
| 338 | int statvfs(const char *__restrict path, struct statvfs *__restrict buf) { | ||
| 339 | // TODO: We plan to support this eventually in WASI, but not yet. | ||
| 340 | // Meanwhile, we provide a stub so that libc++'s `<filesystem>` | ||
| 341 | // implementation will build unmodified. | ||
| 342 | errno = ENOSYS; | ||
| 343 | return -1; | ||
| 344 | } | ||
| 345 | |||
| 346 | int fstatvfs(int fd, struct statvfs *buf) { | ||
| 347 | // TODO: We plan to support this eventually in WASI, but not yet. | ||
| 348 | // Meanwhile, we provide a stub so that libc++'s `<filesystem>` | ||
| 349 | // implementation will build unmodified. | ||
| 350 | errno = ENOSYS; | ||
| 351 | return -1; | ||
| 352 | } | ||
| 353 | |||
| 354 | // Like `access`, but with `faccessat`'s flags argument. | ||
| 355 | int | ||
| 356 | __wasilibc_access(const char *path, int mode, int flags) | ||
| 357 | { | ||
| 358 | char *relative_path; | ||
| 359 | int dirfd = find_relpath(path, &relative_path); | ||
| 360 | |||
| 361 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 362 | if (dirfd == -1) { | ||
| 363 | errno = ENOENT; | ||
| 364 | return -1; | ||
| 365 | } | ||
| 366 | |||
| 367 | return __wasilibc_nocwd_faccessat(dirfd, relative_path, | ||
| 368 | mode, flags); | ||
| 369 | } | ||
| 370 | |||
| 371 | // Like `utimensat`, but without the `at` part. | ||
| 372 | int | ||
| 373 | __wasilibc_utimens(const char *path, const struct timespec times[2], int flags) | ||
| 374 | { | ||
| 375 | char *relative_path; | ||
| 376 | int dirfd = find_relpath(path, &relative_path); | ||
| 377 | |||
| 378 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 379 | if (dirfd == -1) { | ||
| 380 | errno = ENOENT; | ||
| 381 | return -1; | ||
| 382 | } | ||
| 383 | |||
| 384 | return __wasilibc_nocwd_utimensat(dirfd, relative_path, | ||
| 385 | times, flags); | ||
| 386 | } | ||
| 387 | |||
| 388 | // Like `stat`, but with `fstatat`'s flags argument. | ||
| 389 | int | ||
| 390 | __wasilibc_stat(const char *__restrict path, struct stat *__restrict st, int flags) | ||
| 391 | { | ||
| 392 | char *relative_path; | ||
| 393 | int dirfd = find_relpath(path, &relative_path); | ||
| 394 | |||
| 395 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 396 | if (dirfd == -1) { | ||
| 397 | errno = ENOENT; | ||
| 398 | return -1; | ||
| 399 | } | ||
| 400 | |||
| 401 | return __wasilibc_nocwd_fstatat(dirfd, relative_path, st, flags); | ||
| 402 | } | ||
| 403 | |||
| 404 | // Like `link`, but with `linkat`'s flags argument. | ||
| 405 | int | ||
| 406 | __wasilibc_link(const char *oldpath, const char *newpath, int flags) | ||
| 407 | { | ||
| 408 | char *old_relative_path; | ||
| 409 | char *new_relative_path; | ||
| 410 | int old_dirfd = find_relpath(oldpath, &old_relative_path); | ||
| 411 | int new_dirfd = find_relpath(newpath, &new_relative_path); | ||
| 412 | |||
| 413 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 414 | if (old_dirfd == -1 || new_dirfd == -1) { | ||
| 415 | errno = ENOENT; | ||
| 416 | return -1; | ||
| 417 | } | ||
| 418 | |||
| 419 | return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, | ||
| 420 | new_dirfd, new_relative_path, | ||
| 421 | flags); | ||
| 422 | } | ||
| 423 | |||
| 424 | // Like `__wasilibc_link`, but oldpath is relative to olddirfd. | ||
| 425 | int | ||
| 426 | __wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags) | ||
| 427 | { | ||
| 428 | char *new_relative_path; | ||
| 429 | int new_dirfd = find_relpath(newpath, &new_relative_path); | ||
| 430 | |||
| 431 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 432 | if (new_dirfd == -1) { | ||
| 433 | errno = ENOENT; | ||
| 434 | return -1; | ||
| 435 | } | ||
| 436 | |||
| 437 | return __wasilibc_nocwd_linkat(olddirfd, oldpath, | ||
| 438 | new_dirfd, new_relative_path, | ||
| 439 | flags); | ||
| 440 | } | ||
| 441 | |||
| 442 | // Like `__wasilibc_link`, but newpath is relative to newdirfd. | ||
| 443 | int | ||
| 444 | __wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags) | ||
| 445 | { | ||
| 446 | char *old_relative_path; | ||
| 447 | int old_dirfd = find_relpath(oldpath, &old_relative_path); | ||
| 448 | |||
| 449 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 450 | if (old_dirfd == -1) { | ||
| 451 | errno = ENOENT; | ||
| 452 | return -1; | ||
| 453 | } | ||
| 454 | |||
| 455 | return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, | ||
| 456 | newdirfd, newpath, | ||
| 457 | flags); | ||
| 458 | } | ||
| 459 | |||
| 460 | // Like `rename`, but from is relative to fromdirfd. | ||
| 461 | int | ||
| 462 | __wasilibc_rename_oldat(int fromdirfd, const char *from, const char *to) | ||
| 463 | { | ||
| 464 | char *to_relative_path; | ||
| 465 | int to_dirfd = find_relpath(to, &to_relative_path); | ||
| 466 | |||
| 467 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 468 | if (to_dirfd == -1) { | ||
| 469 | errno = ENOENT; | ||
| 470 | return -1; | ||
| 471 | } | ||
| 472 | |||
| 473 | return __wasilibc_nocwd_renameat(fromdirfd, from, to_dirfd, to_relative_path); | ||
| 474 | } | ||
| 475 | |||
| 476 | // Like `rename`, but to is relative to todirfd. | ||
| 477 | int | ||
| 478 | __wasilibc_rename_newat(const char *from, int todirfd, const char *to) | ||
| 479 | { | ||
| 480 | char *from_relative_path; | ||
| 481 | int from_dirfd = find_relpath(from, &from_relative_path); | ||
| 482 | |||
| 483 | // If we can't find a preopen for it, fail as if we can't find the path. | ||
| 484 | if (from_dirfd == -1) { | ||
| 485 | errno = ENOENT; | ||
| 486 | return -1; | ||
| 487 | } | ||
| 488 | |||
| 489 | return __wasilibc_nocwd_renameat(from_dirfd, from_relative_path, todirfd, to); | ||
| 490 | } | ||
lib/libc/wasi/libc-bottom-half/sources/preopens.c deleted-310| ... | @@ -1,310 +0,0 @@ | ||
| 1 | //! Support for "preopens", file descriptors passed into the program from the | ||
| 2 | //! environment, with associated path prefixes, which can be used to map | ||
| 3 | //! absolute paths to capabilities with relative paths. | ||
| 4 | |||
| 5 | #include <assert.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <limits.h> | ||
| 9 | #include <lock.h> | ||
| 10 | #include <stdbool.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <string.h> | ||
| 13 | #include <sysexits.h> | ||
| 14 | #include <wasi/api.h> | ||
| 15 | #include <wasi/libc-find-relpath.h> | ||
| 16 | #include <wasi/libc.h> | ||
| 17 | |||
| 18 | /// A name and file descriptor pair. | ||
| 19 | typedef struct preopen { | ||
| 20 | /// The path prefix associated with the file descriptor. | ||
| 21 | const char *prefix; | ||
| 22 | |||
| 23 | /// The file descriptor. | ||
| 24 | __wasi_fd_t fd; | ||
| 25 | } preopen; | ||
| 26 | |||
| 27 | /// A simple growable array of `preopen`. | ||
| 28 | static _Atomic _Bool preopens_populated = false; | ||
| 29 | static preopen *preopens; | ||
| 30 | static size_t num_preopens; | ||
| 31 | static size_t preopen_capacity; | ||
| 32 | |||
| 33 | /// Access to the the above preopen must be protected in the presence of | ||
| 34 | /// threads. | ||
| 35 | #ifdef _REENTRANT | ||
| 36 | static volatile int lock[1]; | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifdef NDEBUG | ||
| 40 | #define assert_invariants() // assertions disabled | ||
| 41 | #else | ||
| 42 | static void assert_invariants(void) { | ||
| 43 | assert(num_preopens <= preopen_capacity); | ||
| 44 | assert(preopen_capacity == 0 || preopens != NULL); | ||
| 45 | assert(preopen_capacity == 0 || | ||
| 46 | preopen_capacity * sizeof(preopen) > preopen_capacity); | ||
| 47 | |||
| 48 | for (size_t i = 0; i < num_preopens; ++i) { | ||
| 49 | const preopen *pre = &preopens[i]; | ||
| 50 | assert(pre->prefix != NULL); | ||
| 51 | assert(pre->fd != (__wasi_fd_t)-1); | ||
| 52 | #ifdef __wasm__ | ||
| 53 | assert((uintptr_t)pre->prefix < | ||
| 54 | (__uint128_t)__builtin_wasm_memory_size(0) * PAGESIZE); | ||
| 55 | #endif | ||
| 56 | } | ||
| 57 | } | ||
| 58 | #endif | ||
| 59 | |||
| 60 | /// Allocate space for more preopens. Returns 0 on success and -1 on failure. | ||
| 61 | static int resize(void) { | ||
| 62 | size_t start_capacity = 4; | ||
| 63 | size_t old_capacity = preopen_capacity; | ||
| 64 | size_t new_capacity = old_capacity == 0 ? start_capacity : old_capacity * 2; | ||
| 65 | |||
| 66 | preopen *old_preopens = preopens; | ||
| 67 | preopen *new_preopens = calloc(sizeof(preopen), new_capacity); | ||
| 68 | if (new_preopens == NULL) { | ||
| 69 | return -1; | ||
| 70 | } | ||
| 71 | |||
| 72 | memcpy(new_preopens, old_preopens, num_preopens * sizeof(preopen)); | ||
| 73 | preopens = new_preopens; | ||
| 74 | preopen_capacity = new_capacity; | ||
| 75 | free(old_preopens); | ||
| 76 | |||
| 77 | assert_invariants(); | ||
| 78 | return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | // Normalize an absolute path. Removes leading `/` and leading `./`, so the | ||
| 82 | // first character is the start of a directory name. This works because our | ||
| 83 | // process always starts with a working directory of `/`. Additionally translate | ||
| 84 | // `.` to the empty string. | ||
| 85 | static const char *strip_prefixes(const char *path) { | ||
| 86 | while (1) { | ||
| 87 | if (path[0] == '/') { | ||
| 88 | path++; | ||
| 89 | } else if (path[0] == '.' && path[1] == '/') { | ||
| 90 | path += 2; | ||
| 91 | } else if (path[0] == '.' && path[1] == 0) { | ||
| 92 | path++; | ||
| 93 | } else { | ||
| 94 | break; | ||
| 95 | } | ||
| 96 | } | ||
| 97 | |||
| 98 | return path; | ||
| 99 | } | ||
| 100 | |||
| 101 | /// Similar to `internal_register_preopened_fd` but does not take a lock. | ||
| 102 | static int internal_register_preopened_fd_unlocked(__wasi_fd_t fd, const char *relprefix) { | ||
| 103 | // Check preconditions. | ||
| 104 | assert_invariants(); | ||
| 105 | assert(fd != AT_FDCWD); | ||
| 106 | assert(fd != -1); | ||
| 107 | assert(relprefix != NULL); | ||
| 108 | |||
| 109 | if (num_preopens == preopen_capacity && resize() != 0) { | ||
| 110 | return -1; | ||
| 111 | } | ||
| 112 | |||
| 113 | char *prefix = strdup(strip_prefixes(relprefix)); | ||
| 114 | if (prefix == NULL) { | ||
| 115 | return -1; | ||
| 116 | } | ||
| 117 | preopens[num_preopens++] = (preopen) { prefix, fd, }; | ||
| 118 | |||
| 119 | assert_invariants(); | ||
| 120 | return 0; | ||
| 121 | } | ||
| 122 | |||
| 123 | /// Register the given preopened file descriptor under the given path. | ||
| 124 | /// | ||
| 125 | /// This function takes ownership of `prefix`. | ||
| 126 | static int internal_register_preopened_fd(__wasi_fd_t fd, const char *relprefix) { | ||
| 127 | LOCK(lock); | ||
| 128 | |||
| 129 | int r = internal_register_preopened_fd_unlocked(fd, relprefix); | ||
| 130 | |||
| 131 | UNLOCK(lock); | ||
| 132 | |||
| 133 | return r; | ||
| 134 | } | ||
| 135 | |||
| 136 | /// Are the `prefix_len` bytes pointed to by `prefix` a prefix of `path`? | ||
| 137 | static bool prefix_matches(const char *prefix, size_t prefix_len, const char *path) { | ||
| 138 | // Allow an empty string as a prefix of any relative path. | ||
| 139 | if (path[0] != '/' && prefix_len == 0) | ||
| 140 | return true; | ||
| 141 | |||
| 142 | // Check whether any bytes of the prefix differ. | ||
| 143 | if (memcmp(path, prefix, prefix_len) != 0) | ||
| 144 | return false; | ||
| 145 | |||
| 146 | // Ignore trailing slashes in directory names. | ||
| 147 | size_t i = prefix_len; | ||
| 148 | while (i > 0 && prefix[i - 1] == '/') { | ||
| 149 | --i; | ||
| 150 | } | ||
| 151 | |||
| 152 | // Match only complete path components. | ||
| 153 | char last = path[i]; | ||
| 154 | return last == '/' || last == '\0'; | ||
| 155 | } | ||
| 156 | |||
| 157 | // See the documentation in libc.h | ||
| 158 | int __wasilibc_register_preopened_fd(int fd, const char *prefix) { | ||
| 159 | __wasilibc_populate_preopens(); | ||
| 160 | |||
| 161 | return internal_register_preopened_fd((__wasi_fd_t)fd, prefix); | ||
| 162 | } | ||
| 163 | |||
| 164 | // See the documentation in libc-find-relpath.h. | ||
| 165 | int __wasilibc_find_relpath(const char *path, | ||
| 166 | const char **abs_prefix, | ||
| 167 | char **relative_path, | ||
| 168 | size_t relative_path_len) { | ||
| 169 | // If `chdir` is linked, whose object file defines this symbol, then we | ||
| 170 | // call that. Otherwise if the program can't `chdir` then `path` is | ||
| 171 | // absolute (or relative to the root dir), so we delegate to `find_abspath` | ||
| 172 | if (__wasilibc_find_relpath_alloc) | ||
| 173 | return __wasilibc_find_relpath_alloc(path, abs_prefix, relative_path, &relative_path_len, 0); | ||
| 174 | return __wasilibc_find_abspath(path, abs_prefix, (const char**) relative_path); | ||
| 175 | } | ||
| 176 | |||
| 177 | // See the documentation in libc-find-relpath.h. | ||
| 178 | int __wasilibc_find_abspath(const char *path, | ||
| 179 | const char **abs_prefix, | ||
| 180 | const char **relative_path) { | ||
| 181 | __wasilibc_populate_preopens(); | ||
| 182 | |||
| 183 | // Strip leading `/` characters, the prefixes we're matching won't have | ||
| 184 | // them. | ||
| 185 | while (*path == '/') | ||
| 186 | path++; | ||
| 187 | // Search through the preopens table. Iterate in reverse so that more | ||
| 188 | // recently added preopens take precedence over less recently addded ones. | ||
| 189 | size_t match_len = 0; | ||
| 190 | int fd = -1; | ||
| 191 | LOCK(lock); | ||
| 192 | for (size_t i = num_preopens; i > 0; --i) { | ||
| 193 | const preopen *pre = &preopens[i - 1]; | ||
| 194 | const char *prefix = pre->prefix; | ||
| 195 | size_t len = strlen(prefix); | ||
| 196 | |||
| 197 | // If we haven't had a match yet, or the candidate path is longer than | ||
| 198 | // our current best match's path, and the candidate path is a prefix of | ||
| 199 | // the requested path, take that as the new best path. | ||
| 200 | if ((fd == -1 || len > match_len) && | ||
| 201 | prefix_matches(prefix, len, path)) | ||
| 202 | { | ||
| 203 | fd = pre->fd; | ||
| 204 | match_len = len; | ||
| 205 | *abs_prefix = prefix; | ||
| 206 | } | ||
| 207 | } | ||
| 208 | UNLOCK(lock); | ||
| 209 | |||
| 210 | if (fd == -1) { | ||
| 211 | errno = ENOENT; | ||
| 212 | return -1; | ||
| 213 | } | ||
| 214 | |||
| 215 | // The relative path is the substring after the portion that was matched. | ||
| 216 | const char *computed = path + match_len; | ||
| 217 | |||
| 218 | // Omit leading slashes in the relative path. | ||
| 219 | while (*computed == '/') | ||
| 220 | ++computed; | ||
| 221 | |||
| 222 | // *at syscalls don't accept empty relative paths, so use "." instead. | ||
| 223 | if (*computed == '\0') | ||
| 224 | computed = "."; | ||
| 225 | |||
| 226 | *relative_path = computed; | ||
| 227 | return fd; | ||
| 228 | } | ||
| 229 | |||
| 230 | /* zig patch: initialize preopens early so zig code doesn't have to call __wasilibc_populate_preopens */ | ||
| 231 | __attribute__((constructor(51))) | ||
| 232 | void __wasilibc_populate_preopens(void) { | ||
| 233 | // Fast path: If the preopens are already initialized, do nothing. | ||
| 234 | if (preopens_populated) { | ||
| 235 | return; | ||
| 236 | } | ||
| 237 | |||
| 238 | LOCK(lock); | ||
| 239 | |||
| 240 | // Check whether another thread initialized the preopens already. | ||
| 241 | if (preopens_populated) { | ||
| 242 | UNLOCK(lock); | ||
| 243 | return; | ||
| 244 | } | ||
| 245 | |||
| 246 | // Skip stdin, stdout, and stderr, and count up until we reach an invalid | ||
| 247 | // file descriptor. | ||
| 248 | for (__wasi_fd_t fd = 3; fd != 0; ++fd) { | ||
| 249 | __wasi_prestat_t prestat; | ||
| 250 | __wasi_errno_t ret = __wasi_fd_prestat_get(fd, &prestat); | ||
| 251 | if (ret == __WASI_ERRNO_BADF) | ||
| 252 | break; | ||
| 253 | if (ret != __WASI_ERRNO_SUCCESS) | ||
| 254 | goto oserr; | ||
| 255 | switch (prestat.tag) { | ||
| 256 | case __WASI_PREOPENTYPE_DIR: { | ||
| 257 | char *prefix = malloc(prestat.u.dir.pr_name_len + 1); | ||
| 258 | if (prefix == NULL) | ||
| 259 | goto software; | ||
| 260 | |||
| 261 | // TODO: Remove the cast on `prefix` once the witx is updated with | ||
| 262 | // char8 support. | ||
| 263 | ret = __wasi_fd_prestat_dir_name(fd, (uint8_t *)prefix, | ||
| 264 | prestat.u.dir.pr_name_len); | ||
| 265 | if (ret != __WASI_ERRNO_SUCCESS) | ||
| 266 | goto oserr; | ||
| 267 | prefix[prestat.u.dir.pr_name_len] = '\0'; | ||
| 268 | |||
| 269 | if (internal_register_preopened_fd_unlocked(fd, prefix) != 0) | ||
| 270 | goto software; | ||
| 271 | free(prefix); | ||
| 272 | |||
| 273 | break; | ||
| 274 | } | ||
| 275 | default: | ||
| 276 | break; | ||
| 277 | } | ||
| 278 | } | ||
| 279 | |||
| 280 | // Preopens are now initialized. | ||
| 281 | preopens_populated = true; | ||
| 282 | |||
| 283 | UNLOCK(lock); | ||
| 284 | |||
| 285 | return; | ||
| 286 | oserr: | ||
| 287 | _Exit(EX_OSERR); | ||
| 288 | software: | ||
| 289 | _Exit(EX_SOFTWARE); | ||
| 290 | } | ||
| 291 | |||
| 292 | void __wasilibc_reset_preopens(void) { | ||
| 293 | LOCK(lock); | ||
| 294 | |||
| 295 | if (num_preopens) { | ||
| 296 | for (int i = 0; i < num_preopens; ++i) { | ||
| 297 | free((void*) preopens[i].prefix); | ||
| 298 | } | ||
| 299 | free(preopens); | ||
| 300 | } | ||
| 301 | |||
| 302 | preopens_populated = false; | ||
| 303 | preopens = NULL; | ||
| 304 | num_preopens = 0; | ||
| 305 | preopen_capacity = 0; | ||
| 306 | |||
| 307 | assert_invariants(); | ||
| 308 | |||
| 309 | UNLOCK(lock); | ||
| 310 | } | ||
lib/libc/wasi/libc-bottom-half/sources/sbrk.c deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <__macro_PAGESIZE.h> | ||
| 5 | |||
| 6 | // Bare-bones implementation of sbrk. | ||
| 7 | void *sbrk(intptr_t increment) { | ||
| 8 | // sbrk(0) returns the current memory size. | ||
| 9 | if (increment == 0) { | ||
| 10 | // The wasm spec doesn't guarantee that memory.grow of 0 always succeeds. | ||
| 11 | return (void *)(__builtin_wasm_memory_size(0) * PAGESIZE); | ||
| 12 | } | ||
| 13 | |||
| 14 | // We only support page-size increments. | ||
| 15 | if (increment % PAGESIZE != 0) { | ||
| 16 | abort(); | ||
| 17 | } | ||
| 18 | |||
| 19 | // WebAssembly doesn't support shrinking linear memory. | ||
| 20 | if (increment < 0) { | ||
| 21 | abort(); | ||
| 22 | } | ||
| 23 | |||
| 24 | uintptr_t old = __builtin_wasm_memory_grow(0, (uintptr_t)increment / PAGESIZE); | ||
| 25 | |||
| 26 | if (old == SIZE_MAX) { | ||
| 27 | errno = ENOMEM; | ||
| 28 | return (void *)-1; | ||
| 29 | } | ||
| 30 | |||
| 31 | return (void *)(old * PAGESIZE); | ||
| 32 | } | ||
lib/libc/wasi/libc-bottom-half/sources/truncate.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <wasi/libc.h> | ||
| 5 | |||
| 6 | int truncate(const char *path, off_t length) | ||
| 7 | { | ||
| 8 | int fd = __wasilibc_open_nomode(path, O_WRONLY | O_CLOEXEC | O_NOCTTY); | ||
| 9 | if (fd < 0) | ||
| 10 | return -1; | ||
| 11 | |||
| 12 | int result = ftruncate(fd, length); | ||
| 13 | if (result != 0) { | ||
| 14 | int save_errno = errno; | ||
| 15 | (void)close(fd); | ||
| 16 | errno = save_errno; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | |||
| 20 | return close(fd); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/headers/private/printscan.h deleted-59| ... | @@ -1,59 +0,0 @@ | ||
| 1 | #if defined(__wasilibc_printscan_no_floating_point) | ||
| 2 | |||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | __attribute__((__cold__, __noreturn__)) | ||
| 6 | static void floating_point_not_supported(void) { | ||
| 7 | void abort(void) __attribute__((__noreturn__)); | ||
| 8 | fputs("Support for floating-point formatting is currently disabled.\n" | ||
| 9 | "To enable it, " __wasilibc_printscan_floating_point_support_option ".\n", stderr); | ||
| 10 | abort(); | ||
| 11 | } | ||
| 12 | |||
| 13 | #elif defined(__wasilibc_printscan_no_long_double) | ||
| 14 | |||
| 15 | #include <stdio.h> | ||
| 16 | |||
| 17 | typedef double long_double; | ||
| 18 | #undef LDBL_TRUE_MIN | ||
| 19 | #define LDBL_TRUE_MIN DBL_DENORM_MIN | ||
| 20 | #undef LDBL_MIN | ||
| 21 | #define LDBL_MIN DBL_MIN | ||
| 22 | #undef LDBL_MAX | ||
| 23 | #define LDBL_MAX DBL_MAX | ||
| 24 | #undef LDBL_EPSILON | ||
| 25 | #define LDBL_EPSILON DBL_EPSILON | ||
| 26 | #undef LDBL_MANT_DIG | ||
| 27 | #define LDBL_MANT_DIG DBL_MANT_DIG | ||
| 28 | #undef LDBL_MIN_EXP | ||
| 29 | #define LDBL_MIN_EXP DBL_MIN_EXP | ||
| 30 | #undef LDBL_MAX_EXP | ||
| 31 | #define LDBL_MAX_EXP DBL_MAX_EXP | ||
| 32 | #undef LDBL_DIG | ||
| 33 | #define LDBL_DIG DBL_DIG | ||
| 34 | #undef LDBL_MIN_10_EXP | ||
| 35 | #define LDBL_MIN_10_EXP DBL_MIN_10_EXP | ||
| 36 | #undef LDBL_MAX_10_EXP | ||
| 37 | #define LDBL_MAX_10_EXP DBL_MAX_10_EXP | ||
| 38 | #undef frexpl | ||
| 39 | #define frexpl(x, exp) frexp(x, exp) | ||
| 40 | #undef copysignl | ||
| 41 | #define copysignl(x, y) copysign(x, y) | ||
| 42 | #undef fmodl | ||
| 43 | #define fmodl(x, y) fmod(x, y) | ||
| 44 | #undef scalbnl | ||
| 45 | #define scalbnl(arg, exp) scalbn(arg, exp) | ||
| 46 | __attribute__((__cold__, __noreturn__)) | ||
| 47 | static void long_double_not_supported(void) { | ||
| 48 | void abort(void) __attribute__((__noreturn__)); | ||
| 49 | fputs("Support for formatting long double values is currently disabled.\n" | ||
| 50 | "To enable it, " __wasilibc_printscan_full_support_option ".\n", &__stderr_FILE); | ||
| 51 | abort(); | ||
| 52 | } | ||
| 53 | |||
| 54 | #else | ||
| 55 | |||
| 56 | // Full long double support. | ||
| 57 | typedef long double long_double; | ||
| 58 | |||
| 59 | #endif | ||
lib/libc/wasi/libc-top-half/headers/private/wasi/libc-environ-compat.h deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | // This header file is meant to be included withinin the body of a function | ||
| 2 | // which uses `__environ`. Code using `__environ` expects it will be initialized | ||
| 3 | // eagerly. `__wasilibc_environ` is initialized lazily. Provide `__environ` as | ||
| 4 | // an alias and arrange for the lazy initialization to be performed. | ||
| 5 | |||
| 6 | extern char **__wasilibc_environ; | ||
| 7 | |||
| 8 | __wasilibc_ensure_environ(); | ||
| 9 | |||
| 10 | #ifndef __wasilibc_environ | ||
| 11 | #define __environ __wasilibc_environ | ||
| 12 | #endif | ||
lib/libc/wasi/libc-top-half/musl/COPYRIGHT deleted-193| ... | @@ -1,193 +0,0 @@ | ||
| 1 | musl as a whole is licensed under the following standard MIT license: | ||
| 2 | |||
| 3 | ---------------------------------------------------------------------- | ||
| 4 | Copyright © 2005-2020 Rich Felker, et al. | ||
| 5 | |||
| 6 | Permission is hereby granted, free of charge, to any person obtaining | ||
| 7 | a copy of this software and associated documentation files (the | ||
| 8 | "Software"), to deal in the Software without restriction, including | ||
| 9 | without limitation the rights to use, copy, modify, merge, publish, | ||
| 10 | distribute, sublicense, and/or sell copies of the Software, and to | ||
| 11 | permit persons to whom the Software is furnished to do so, subject to | ||
| 12 | the following conditions: | ||
| 13 | |||
| 14 | The above copyright notice and this permission notice shall be | ||
| 15 | included in all copies or substantial portions of the Software. | ||
| 16 | |||
| 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
| 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. | ||
| 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY | ||
| 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, | ||
| 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE | ||
| 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
| 24 | ---------------------------------------------------------------------- | ||
| 25 | |||
| 26 | Authors/contributors include: | ||
| 27 | |||
| 28 | A. Wilcox | ||
| 29 | Ada Worcester | ||
| 30 | Alex Dowad | ||
| 31 | Alex Suykov | ||
| 32 | Alexander Monakov | ||
| 33 | Andre McCurdy | ||
| 34 | Andrew Kelley | ||
| 35 | Anthony G. Basile | ||
| 36 | Aric Belsito | ||
| 37 | Arvid Picciani | ||
| 38 | Bartosz Brachaczek | ||
| 39 | Benjamin Peterson | ||
| 40 | Bobby Bingham | ||
| 41 | Boris Brezillon | ||
| 42 | Brent Cook | ||
| 43 | Chris Spiegel | ||
| 44 | Clément Vasseur | ||
| 45 | Daniel Micay | ||
| 46 | Daniel Sabogal | ||
| 47 | Daurnimator | ||
| 48 | David Carlier | ||
| 49 | David Edelsohn | ||
| 50 | Denys Vlasenko | ||
| 51 | Dmitry Ivanov | ||
| 52 | Dmitry V. Levin | ||
| 53 | Drew DeVault | ||
| 54 | Emil Renner Berthing | ||
| 55 | Fangrui Song | ||
| 56 | Felix Fietkau | ||
| 57 | Felix Janda | ||
| 58 | Gianluca Anzolin | ||
| 59 | Hauke Mehrtens | ||
| 60 | He X | ||
| 61 | Hiltjo Posthuma | ||
| 62 | Isaac Dunham | ||
| 63 | Jaydeep Patil | ||
| 64 | Jens Gustedt | ||
| 65 | Jeremy Huntwork | ||
| 66 | Jo-Philipp Wich | ||
| 67 | Joakim Sindholt | ||
| 68 | John Spencer | ||
| 69 | Julien Ramseier | ||
| 70 | Justin Cormack | ||
| 71 | Kaarle Ritvanen | ||
| 72 | Khem Raj | ||
| 73 | Kylie McClain | ||
| 74 | Leah Neukirchen | ||
| 75 | Luca Barbato | ||
| 76 | Luka Perkov | ||
| 77 | M Farkas-Dyck (Strake) | ||
| 78 | Mahesh Bodapati | ||
| 79 | Markus Wichmann | ||
| 80 | Masanori Ogino | ||
| 81 | Michael Clark | ||
| 82 | Michael Forney | ||
| 83 | Mikhail Kremnyov | ||
| 84 | Natanael Copa | ||
| 85 | Nicholas J. Kain | ||
| 86 | orc | ||
| 87 | Pascal Cuoq | ||
| 88 | Patrick Oppenlander | ||
| 89 | Petr Hosek | ||
| 90 | Petr Skocik | ||
| 91 | Pierre Carrier | ||
| 92 | Reini Urban | ||
| 93 | Rich Felker | ||
| 94 | Richard Pennington | ||
| 95 | Ryan Fairfax | ||
| 96 | Samuel Holland | ||
| 97 | Segev Finer | ||
| 98 | Shiz | ||
| 99 | sin | ||
| 100 | Solar Designer | ||
| 101 | Stefan Kristiansson | ||
| 102 | Stefan O'Rear | ||
| 103 | Szabolcs Nagy | ||
| 104 | Timo Teräs | ||
| 105 | Trutz Behn | ||
| 106 | Valentin Ochs | ||
| 107 | Will Dietz | ||
| 108 | William Haddon | ||
| 109 | William Pitcock | ||
| 110 | |||
| 111 | Portions of this software are derived from third-party works licensed | ||
| 112 | under terms compatible with the above MIT license: | ||
| 113 | |||
| 114 | The TRE regular expression implementation (src/regex/reg* and | ||
| 115 | src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed | ||
| 116 | under a 2-clause BSD license (license text in the source files). The | ||
| 117 | included version has been heavily modified by Rich Felker in 2012, in | ||
| 118 | the interests of size, simplicity, and namespace cleanliness. | ||
| 119 | |||
| 120 | Much of the math library code (src/math/* and src/complex/*) is | ||
| 121 | Copyright © 1993,2004 Sun Microsystems or | ||
| 122 | Copyright © 2003-2011 David Schultz or | ||
| 123 | Copyright © 2003-2009 Steven G. Kargl or | ||
| 124 | Copyright © 2003-2009 Bruce D. Evans or | ||
| 125 | Copyright © 2008 Stephen L. Moshier or | ||
| 126 | Copyright © 2017-2018 Arm Limited | ||
| 127 | and labelled as such in comments in the individual source files. All | ||
| 128 | have been licensed under extremely permissive terms. | ||
| 129 | |||
| 130 | The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008 | ||
| 131 | The Android Open Source Project and is licensed under a two-clause BSD | ||
| 132 | license. It was taken from Bionic libc, used on Android. | ||
| 133 | |||
| 134 | The AArch64 memcpy and memset code (src/string/aarch64/*) are | ||
| 135 | Copyright © 1999-2019, Arm Limited. | ||
| 136 | |||
| 137 | The implementation of DES for crypt (src/crypt/crypt_des.c) is | ||
| 138 | Copyright © 1994 David Burren. It is licensed under a BSD license. | ||
| 139 | |||
| 140 | The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was | ||
| 141 | originally written by Solar Designer and placed into the public | ||
| 142 | domain. The code also comes with a fallback permissive license for use | ||
| 143 | in jurisdictions that may not recognize the public domain. | ||
| 144 | |||
| 145 | The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011 | ||
| 146 | Valentin Ochs and is licensed under an MIT-style license. | ||
| 147 | |||
| 148 | The x86_64 port was written by Nicholas J. Kain and is licensed under | ||
| 149 | the standard MIT terms. | ||
| 150 | |||
| 151 | The mips and microblaze ports were originally written by Richard | ||
| 152 | Pennington for use in the ellcc project. The original code was adapted | ||
| 153 | by Rich Felker for build system and code conventions during upstream | ||
| 154 | integration. It is licensed under the standard MIT terms. | ||
| 155 | |||
| 156 | The mips64 port was contributed by Imagination Technologies and is | ||
| 157 | licensed under the standard MIT terms. | ||
| 158 | |||
| 159 | The powerpc port was also originally written by Richard Pennington, | ||
| 160 | and later supplemented and integrated by John Spencer. It is licensed | ||
| 161 | under the standard MIT terms. | ||
| 162 | |||
| 163 | All other files which have no copyright comments are original works | ||
| 164 | produced specifically for use as part of this library, written either | ||
| 165 | by Rich Felker, the main author of the library, or by one or more | ||
| 166 | contibutors listed above. Details on authorship of individual files | ||
| 167 | can be found in the git version control history of the project. The | ||
| 168 | omission of copyright and license comments in each file is in the | ||
| 169 | interest of source tree size. | ||
| 170 | |||
| 171 | In addition, permission is hereby granted for all public header files | ||
| 172 | (include/* and arch/*/bits/*) and crt files intended to be linked into | ||
| 173 | applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit | ||
| 174 | the copyright notice and permission notice otherwise required by the | ||
| 175 | license, and to use these files without any requirement of | ||
| 176 | attribution. These files include substantial contributions from: | ||
| 177 | |||
| 178 | Bobby Bingham | ||
| 179 | John Spencer | ||
| 180 | Nicholas J. Kain | ||
| 181 | Rich Felker | ||
| 182 | Richard Pennington | ||
| 183 | Stefan Kristiansson | ||
| 184 | Szabolcs Nagy | ||
| 185 | |||
| 186 | all of whom have explicitly granted such permission. | ||
| 187 | |||
| 188 | This file previously contained text expressing a belief that most of | ||
| 189 | the files covered by the above exception were sufficiently trivial not | ||
| 190 | to be subject to copyright, resulting in confusion over whether it | ||
| 191 | negated the permissions granted in the license. In the spirit of | ||
| 192 | permissive licensing, and of not having licensing issues being an | ||
| 193 | obstacle to adoption, that text has been removed. | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #define a_cas(p, t, s) (__sync_val_compare_and_swap((p), (t), (s))) | ||
| 2 | #define a_crash() (__builtin_trap()) | ||
| 3 | #define a_clz_32 __builtin_clz | ||
| 4 | #define a_clz_64 __builtin_clzll | ||
| 5 | #define a_ctz_32 __builtin_ctz | ||
| 6 | #define a_ctz_64 __builtin_ctzll | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/dirent.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__struct_dirent.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/fcntl.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | /* Use the WASI libc fcntl implementation bits. */ | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/float.h deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | #define FLT_EVAL_METHOD 0 | ||
| 2 | |||
| 3 | #define LDBL_TRUE_MIN 6.47517511943802511092443895822764655e-4966L | ||
| 4 | #define LDBL_MIN 3.36210314311209350626267781732175260e-4932L | ||
| 5 | #define LDBL_MAX 1.18973149535723176508575932662800702e+4932L | ||
| 6 | #define LDBL_EPSILON 1.92592994438723585305597794258492732e-34L | ||
| 7 | |||
| 8 | #define LDBL_MANT_DIG 113 | ||
| 9 | #define LDBL_MIN_EXP (-16381) | ||
| 10 | #define LDBL_MAX_EXP 16384 | ||
| 11 | |||
| 12 | #define LDBL_DIG 33 | ||
| 13 | #define LDBL_MIN_10_EXP (-4931) | ||
| 14 | #define LDBL_MAX_10_EXP 4932 | ||
| 15 | |||
| 16 | #define DECIMAL_DIG 36 | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/ioctl.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | /* Use the WASI libc ioctl implementation bits. */ | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/limits.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__macro_PAGESIZE.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/posix.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #define _POSIX_V6_ILP32_OFFBIG (1) | ||
| 2 | #define _POSIX_V7_ILP32_OFFBIG (1) | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/reg.h deleted-2| ... | @@ -1,2 +0,0 @@ | ||
| 1 | #undef __WORDSIZE | ||
| 2 | #define __WORDSIZE 64 | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/setjmp.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | typedef unsigned long __jmp_buf[8]; | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/signal.h deleted-40| ... | @@ -1,40 +0,0 @@ | ||
| 1 | #ifdef _WASI_EMULATED_SIGNAL | ||
| 2 | |||
| 3 | #define SIGHUP 1 | ||
| 4 | #define SIGINT 2 | ||
| 5 | #define SIGQUIT 3 | ||
| 6 | #define SIGILL 4 | ||
| 7 | #define SIGTRAP 5 | ||
| 8 | #define SIGABRT 6 | ||
| 9 | #define SIGIOT SIGABRT | ||
| 10 | #define SIGBUS 7 | ||
| 11 | #define SIGFPE 8 | ||
| 12 | #define SIGKILL 9 | ||
| 13 | #define SIGUSR1 10 | ||
| 14 | #define SIGSEGV 11 | ||
| 15 | #define SIGUSR2 12 | ||
| 16 | #define SIGPIPE 13 | ||
| 17 | #define SIGALRM 14 | ||
| 18 | #define SIGTERM 15 | ||
| 19 | #define SIGSTKFLT 16 | ||
| 20 | #define SIGCHLD 17 | ||
| 21 | #define SIGCONT 18 | ||
| 22 | #define SIGSTOP 19 | ||
| 23 | #define SIGTSTP 20 | ||
| 24 | #define SIGTTIN 21 | ||
| 25 | #define SIGTTOU 22 | ||
| 26 | #define SIGURG 23 | ||
| 27 | #define SIGXCPU 24 | ||
| 28 | #define SIGXFSZ 25 | ||
| 29 | #define SIGVTALRM 26 | ||
| 30 | #define SIGPROF 27 | ||
| 31 | #define SIGWINCH 28 | ||
| 32 | #define SIGIO 29 | ||
| 33 | #define SIGPOLL 29 | ||
| 34 | #define SIGPWR 30 | ||
| 35 | #define SIGSYS 31 | ||
| 36 | #define SIGUNUSED SIGSYS | ||
| 37 | |||
| 38 | #define _NSIG 65 | ||
| 39 | |||
| 40 | #endif | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stat.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #include <__struct_stat.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stdint.h deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | typedef int16_t int_fast16_t; | ||
| 2 | typedef int32_t int_fast32_t; | ||
| 3 | typedef uint16_t uint_fast16_t; | ||
| 4 | typedef uint32_t uint_fast32_t; | ||
| 5 | |||
| 6 | #define INT_FAST16_MIN INT16_MIN | ||
| 7 | #define INT_FAST32_MIN INT32_MIN | ||
| 8 | |||
| 9 | #define INT_FAST16_MAX INT16_MAX | ||
| 10 | #define INT_FAST32_MAX INT32_MAX | ||
| 11 | |||
| 12 | #define UINT_FAST16_MAX UINT16_MAX | ||
| 13 | #define UINT_FAST32_MAX UINT32_MAX | ||
| 14 | |||
| 15 | #define INTPTR_MIN INT32_MIN | ||
| 16 | #define INTPTR_MAX INT32_MAX | ||
| 17 | #define UINTPTR_MAX UINT32_MAX | ||
| 18 | #define PTRDIFF_MIN INT32_MIN | ||
| 19 | #define PTRDIFF_MAX INT32_MAX | ||
| 20 | #define SIZE_MAX UINT32_MAX | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/fp_arch.h deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | // WebAssembly has no floating-point exceptions or alternate rounding modes, | ||
| 2 | // so there's no need to prevent expressions from moving or force their | ||
| 3 | // evaluation. | ||
| 4 | |||
| 5 | #define fp_barrierf fp_barrierf | ||
| 6 | static inline float fp_barrierf(float x) | ||
| 7 | { | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #define fp_barrier fp_barrier | ||
| 12 | static inline double fp_barrier(double x) | ||
| 13 | { | ||
| 14 | 	return x; | ||
| 15 | } | ||
| 16 | |||
| 17 | #define fp_force_evalf fp_force_evalf | ||
| 18 | static inline void fp_force_evalf(float x) | ||
| 19 | { | ||
| 20 | } | ||
| 21 | |||
| 22 | #define fp_force_eval fp_force_eval | ||
| 23 | static inline void fp_force_eval(double x) | ||
| 24 | { | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/pthread_arch.h deleted-5| ... | @@ -1,5 +0,0 @@ | ||
| 1 | extern _Thread_local struct __pthread __wasilibc_pthread_self; | ||
| 2 | |||
| 3 | static inline uintptr_t __get_tp() { | ||
| 4 | return (uintptr_t)&__wasilibc_pthread_self; | ||
| 5 | } | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/reloc.h deleted-1| ... | @@ -1 +0,0 @@ | ||
| 1 | #define LDSO_ARCH "wasm32" | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/syscall_arch.h deletedlib/libc/wasi/libc-top-half/musl/include/aio.h deleted-73| ... | @@ -1,73 +0,0 @@ | ||
| 1 | #ifndef _AIO_H | ||
| 2 | #define _AIO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <signal.h> | ||
| 10 | #include <time.h> | ||
| 11 | |||
| 12 | #define __NEED_ssize_t | ||
| 13 | #define __NEED_off_t | ||
| 14 | |||
| 15 | #include <bits/alltypes.h> | ||
| 16 | |||
| 17 | struct aiocb { | ||
| 18 | 	int aio_fildes, aio_lio_opcode, aio_reqprio; | ||
| 19 | 	volatile void *aio_buf; | ||
| 20 | 	size_t aio_nbytes; | ||
| 21 | 	struct sigevent aio_sigevent; | ||
| 22 | 	void *__td; | ||
| 23 | 	int __lock[2]; | ||
| 24 | 	volatile int __err; | ||
| 25 | 	ssize_t __ret; | ||
| 26 | 	off_t aio_offset; | ||
| 27 | 	void *__next, *__prev; | ||
| 28 | 	char __dummy4[32-2*sizeof(void *)]; | ||
| 29 | }; | ||
| 30 | |||
| 31 | #define AIO_CANCELED 0 | ||
| 32 | #define AIO_NOTCANCELED 1 | ||
| 33 | #define AIO_ALLDONE 2 | ||
| 34 | |||
| 35 | #define LIO_READ 0 | ||
| 36 | #define LIO_WRITE 1 | ||
| 37 | #define LIO_NOP 2 | ||
| 38 | |||
| 39 | #define LIO_WAIT 0 | ||
| 40 | #define LIO_NOWAIT 1 | ||
| 41 | |||
| 42 | int aio_read(struct aiocb *); | ||
| 43 | int aio_write(struct aiocb *); | ||
| 44 | int aio_error(const struct aiocb *); | ||
| 45 | ssize_t aio_return(struct aiocb *); | ||
| 46 | int aio_cancel(int, struct aiocb *); | ||
| 47 | int aio_suspend(const struct aiocb *const [], int, const struct timespec *); | ||
| 48 | int aio_fsync(int, struct aiocb *); | ||
| 49 | |||
| 50 | int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict); | ||
| 51 | |||
| 52 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 53 | #define aiocb64 aiocb | ||
| 54 | #define aio_read64 aio_read | ||
| 55 | #define aio_write64 aio_write | ||
| 56 | #define aio_error64 aio_error | ||
| 57 | #define aio_return64 aio_return | ||
| 58 | #define aio_cancel64 aio_cancel | ||
| 59 | #define aio_suspend64 aio_suspend | ||
| 60 | #define aio_fsync64 aio_fsync | ||
| 61 | #define lio_listio64 lio_listio | ||
| 62 | #define off64_t off_t | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #if _REDIR_TIME64 | ||
| 66 | __REDIR(aio_suspend, __aio_suspend_time64); | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #ifdef __cplusplus | ||
| 70 | } | ||
| 71 | #endif | ||
| 72 | |||
| 73 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/arpa/inet.h deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #ifndef _ARPA_INET_H | ||
| 2 | #define	_ARPA_INET_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | uint32_t htonl(uint32_t); | ||
| 12 | uint16_t htons(uint16_t); | ||
| 13 | uint32_t ntohl(uint32_t); | ||
| 14 | uint16_t ntohs(uint16_t); | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream /* WASI has no inet_addr */ | ||
| 17 | in_addr_t inet_addr (const char *); | ||
| 18 | in_addr_t inet_network (const char *); | ||
| 19 | char *inet_ntoa (struct in_addr); | ||
| 20 | #endif | ||
| 21 | int inet_pton (int, const char *__restrict, void *__restrict); | ||
| 22 | const char *inet_ntop (int, const void *__restrict, char *__restrict, socklen_t); | ||
| 23 | |||
| 24 | int inet_aton (const char *, struct in_addr *); | ||
| 25 | #ifdef __wasilibc_unmodified_upstream /* WASI has no inet_makeaddr */ | ||
| 26 | struct in_addr inet_makeaddr(in_addr_t, in_addr_t); | ||
| 27 | in_addr_t inet_lnaof(struct in_addr); | ||
| 28 | in_addr_t inet_netof(struct in_addr); | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifdef __cplusplus | ||
| 32 | } | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/complex.h deleted-143| ... | @@ -1,143 +0,0 @@ | ||
| 1 | #ifndef _COMPLEX_H | ||
| 2 | #define _COMPLEX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define complex _Complex | ||
| 9 | #ifdef __GNUC__ | ||
| 10 | #define _Complex_I (__extension__ (0.0f+1.0fi)) | ||
| 11 | #else | ||
| 12 | #define _Complex_I (0.0f+1.0fi) | ||
| 13 | #endif | ||
| 14 | #define I _Complex_I | ||
| 15 | |||
| 16 | double complex cacos(double complex); | ||
| 17 | float complex cacosf(float complex); | ||
| 18 | long double complex cacosl(long double complex); | ||
| 19 | |||
| 20 | double complex casin(double complex); | ||
| 21 | float complex casinf(float complex); | ||
| 22 | long double complex casinl(long double complex); | ||
| 23 | |||
| 24 | double complex catan(double complex); | ||
| 25 | float complex catanf(float complex); | ||
| 26 | long double complex catanl(long double complex); | ||
| 27 | |||
| 28 | double complex ccos(double complex); | ||
| 29 | float complex ccosf(float complex); | ||
| 30 | long double complex ccosl(long double complex); | ||
| 31 | |||
| 32 | double complex csin(double complex); | ||
| 33 | float complex csinf(float complex); | ||
| 34 | long double complex csinl(long double complex); | ||
| 35 | |||
| 36 | double complex ctan(double complex); | ||
| 37 | float complex ctanf(float complex); | ||
| 38 | long double complex ctanl(long double complex); | ||
| 39 | |||
| 40 | double complex cacosh(double complex); | ||
| 41 | float complex cacoshf(float complex); | ||
| 42 | long double complex cacoshl(long double complex); | ||
| 43 | |||
| 44 | double complex casinh(double complex); | ||
| 45 | float complex casinhf(float complex); | ||
| 46 | long double complex casinhl(long double complex); | ||
| 47 | |||
| 48 | double complex catanh(double complex); | ||
| 49 | float complex catanhf(float complex); | ||
| 50 | long double complex catanhl(long double complex); | ||
| 51 | |||
| 52 | double complex ccosh(double complex); | ||
| 53 | float complex ccoshf(float complex); | ||
| 54 | long double complex ccoshl(long double complex); | ||
| 55 | |||
| 56 | double complex csinh(double complex); | ||
| 57 | float complex csinhf(float complex); | ||
| 58 | long double complex csinhl(long double complex); | ||
| 59 | |||
| 60 | double complex ctanh(double complex); | ||
| 61 | float complex ctanhf(float complex); | ||
| 62 | long double complex ctanhl(long double complex); | ||
| 63 | |||
| 64 | double complex cexp(double complex); | ||
| 65 | float complex cexpf(float complex); | ||
| 66 | long double complex cexpl(long double complex); | ||
| 67 | |||
| 68 | double complex clog(double complex); | ||
| 69 | float complex clogf(float complex); | ||
| 70 | long double complex clogl(long double complex); | ||
| 71 | |||
| 72 | double cabs(double complex); | ||
| 73 | float cabsf(float complex); | ||
| 74 | long double cabsl(long double complex); | ||
| 75 | |||
| 76 | double complex cpow(double complex, double complex); | ||
| 77 | float complex cpowf(float complex, float complex); | ||
| 78 | long double complex cpowl(long double complex, long double complex); | ||
| 79 | |||
| 80 | double complex csqrt(double complex); | ||
| 81 | float complex csqrtf(float complex); | ||
| 82 | long double complex csqrtl(long double complex); | ||
| 83 | |||
| 84 | double carg(double complex); | ||
| 85 | float cargf(float complex); | ||
| 86 | long double cargl(long double complex); | ||
| 87 | |||
| 88 | double cimag(double complex); | ||
| 89 | float cimagf(float complex); | ||
| 90 | long double cimagl(long double complex); | ||
| 91 | |||
| 92 | double complex conj(double complex); | ||
| 93 | float complex conjf(float complex); | ||
| 94 | long double complex conjl(long double complex); | ||
| 95 | |||
| 96 | double complex cproj(double complex); | ||
| 97 | float complex cprojf(float complex); | ||
| 98 | long double complex cprojl(long double complex); | ||
| 99 | |||
| 100 | double creal(double complex); | ||
| 101 | float crealf(float complex); | ||
| 102 | long double creall(long double complex); | ||
| 103 | |||
| 104 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's real/imag operators rather than union type punning */ | ||
| 105 | #ifndef __cplusplus | ||
| 106 | #define __CIMAG(x, t) \ | ||
| 107 | 	(+(union { _Complex t __z; t __xy[2]; }){(_Complex t)(x)}.__xy[1]) | ||
| 108 | |||
| 109 | #define creal(x) ((double)(x)) | ||
| 110 | #define crealf(x) ((float)(x)) | ||
| 111 | #define creall(x) ((long double)(x)) | ||
| 112 | |||
| 113 | #define cimag(x) __CIMAG(x, double) | ||
| 114 | #define cimagf(x) __CIMAG(x, float) | ||
| 115 | #define cimagl(x) __CIMAG(x, long double) | ||
| 116 | #endif | ||
| 117 | #else | ||
| 118 | #define creal(x) (__builtin_creal(x)) | ||
| 119 | #define crealf(x) (__builtin_crealf(x)) | ||
| 120 | #define creall(x) (__builtin_creall(x)) | ||
| 121 | |||
| 122 | #define cimag(x) (__builtin_cimag(x)) | ||
| 123 | #define cimagf(x) (__builtin_cimagf(x)) | ||
| 124 | #define cimagl(x) (__builtin_cimagl(x)) | ||
| 125 | #endif | ||
| 126 | |||
| 127 | #if __STDC_VERSION__ >= 201112L | ||
| 128 | #if defined(_Imaginary_I) | ||
| 129 | #define __CMPLX(x, y, t) ((t)(x) + _Imaginary_I*(t)(y)) | ||
| 130 | #elif defined(__clang__) | ||
| 131 | #define __CMPLX(x, y, t) (+(_Complex t){ (t)(x), (t)(y) }) | ||
| 132 | #else | ||
| 133 | #define __CMPLX(x, y, t) (__builtin_complex((t)(x), (t)(y))) | ||
| 134 | #endif | ||
| 135 | #define CMPLX(x, y) __CMPLX(x, y, double) | ||
| 136 | #define CMPLXF(x, y) __CMPLX(x, y, float) | ||
| 137 | #define CMPLXL(x, y) __CMPLX(x, y, long double) | ||
| 138 | #endif | ||
| 139 | |||
| 140 | #ifdef __cplusplus | ||
| 141 | } | ||
| 142 | #endif | ||
| 143 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/dirent.h deleted-89| ... | @@ -1,89 +0,0 @@ | ||
| 1 | #ifndef	_DIRENT_H | ||
| 2 | #define	_DIRENT_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__header_dirent.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #define __NEED_ino_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 17 | #define __NEED_size_t | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #include <bits/alltypes.h> | ||
| 21 | |||
| 22 | #include <bits/dirent.h> | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 25 | typedef struct __dirstream DIR; | ||
| 26 | #else | ||
| 27 | #include <__typedef_DIR.h> | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #define d_fileno d_ino | ||
| 31 | |||
| 32 | int closedir(DIR *); | ||
| 33 | DIR *fdopendir(int); | ||
| 34 | DIR *opendir(const char *); | ||
| 35 | struct dirent *readdir(DIR *); | ||
| 36 | #ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ | ||
| 37 | int readdir_r(DIR *__restrict, struct dirent *__restrict, struct dirent **__restrict); | ||
| 38 | #endif | ||
| 39 | void rewinddir(DIR *); | ||
| 40 | int dirfd(DIR *); | ||
| 41 | |||
| 42 | int alphasort(const struct dirent **, const struct dirent **); | ||
| 43 | int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); | ||
| 44 | |||
| 45 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 46 | void seekdir(DIR *, long); | ||
| 47 | long telldir(DIR *); | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 51 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 52 | #define DT_UNKNOWN 0 | ||
| 53 | #define DT_FIFO 1 | ||
| 54 | #define DT_CHR 2 | ||
| 55 | #define DT_DIR 4 | ||
| 56 | #define DT_BLK 6 | ||
| 57 | #define DT_REG 8 | ||
| 58 | #define DT_LNK 10 | ||
| 59 | #define DT_SOCK 12 | ||
| 60 | #define DT_WHT 14 | ||
| 61 | #define IFTODT(x) ((x)>>12 & 017) | ||
| 62 | #define DTTOIF(x) ((x)<<12) | ||
| 63 | #endif | ||
| 64 | int getdents(int, struct dirent *, size_t); | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #ifdef _GNU_SOURCE | ||
| 68 | int versionsort(const struct dirent **, const struct dirent **); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 72 | #define dirent64 dirent | ||
| 73 | #define readdir64 readdir | ||
| 74 | #ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */ | ||
| 75 | #define readdir64_r readdir_r | ||
| 76 | #endif | ||
| 77 | #define scandir64 scandir | ||
| 78 | #define alphasort64 alphasort | ||
| 79 | #define versionsort64 versionsort | ||
| 80 | #define off64_t off_t | ||
| 81 | #define ino64_t ino_t | ||
| 82 | #define getdents64 getdents | ||
| 83 | #endif | ||
| 84 | |||
| 85 | #ifdef __cplusplus | ||
| 86 | } | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/dlfcn.h deleted-56| ... | @@ -1,56 +0,0 @@ | ||
| 1 | #ifndef	_DLFCN_H | ||
| 2 | #define	_DLFCN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define RTLD_LAZY 1 | ||
| 11 | #define RTLD_NOW 2 | ||
| 12 | #define RTLD_NOLOAD 4 | ||
| 13 | #define RTLD_NODELETE 4096 | ||
| 14 | #define RTLD_GLOBAL 256 | ||
| 15 | #ifdef __wasilibc_unmodified_upstream | ||
| 16 | #define RTLD_LOCAL 0 | ||
| 17 | #else | ||
| 18 | /* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and | ||
| 19 | * allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL` | ||
| 20 | * should be the default when neither is specified. | ||
| 21 | */ | ||
| 22 | #define RTLD_LOCAL 8 | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #define RTLD_NEXT ((void *)-1) | ||
| 26 | #define RTLD_DEFAULT ((void *)0) | ||
| 27 | |||
| 28 | #ifdef __wasilibc_unmodified_upstream | ||
| 29 | #define RTLD_DI_LINKMAP 2 | ||
| 30 | #endif | ||
| 31 | |||
| 32 | int dlclose(void *); | ||
| 33 | char *dlerror(void); | ||
| 34 | void *dlopen(const char *, int); | ||
| 35 | void *dlsym(void *__restrict, const char *__restrict); | ||
| 36 | |||
| 37 | #if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE)) | ||
| 38 | typedef struct { | ||
| 39 | 	const char *dli_fname; | ||
| 40 | 	void *dli_fbase; | ||
| 41 | 	const char *dli_sname; | ||
| 42 | 	void *dli_saddr; | ||
| 43 | } Dl_info; | ||
| 44 | int dladdr(const void *, Dl_info *); | ||
| 45 | int dlinfo(void *, int, void *); | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #if _REDIR_TIME64 | ||
| 49 | __REDIR(dlsym, __dlsym_time64); | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #ifdef __cplusplus | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/errno.h deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #ifndef	_ERRNO_H | ||
| 2 | #define _ERRNO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 11 | #include <bits/errno.h> | ||
| 12 | |||
| 13 | #ifdef __GNUC__ | ||
| 14 | __attribute__((const)) | ||
| 15 | #endif | ||
| 16 | int *__errno_location(void); | ||
| 17 | #define errno (*__errno_location()) | ||
| 18 | #else | ||
| 19 | #include <__errno.h> | ||
| 20 | #include <__errno_values.h> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #ifdef _GNU_SOURCE | ||
| 24 | extern char *program_invocation_short_name, *program_invocation_name; | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #ifdef __cplusplus | ||
| 28 | } | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #endif | ||
| 32 | |||
lib/libc/wasi/libc-top-half/musl/include/fcntl.h deleted-250| ... | @@ -1,250 +0,0 @@ | ||
| 1 | #ifndef	_FCNTL_H | ||
| 2 | #define	_FCNTL_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__header_fcntl.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #define __NEED_off_t | ||
| 15 | #define __NEED_pid_t | ||
| 16 | #define __NEED_mode_t | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __NEED_size_t | ||
| 20 | #define __NEED_ssize_t | ||
| 21 | #define __NEED_struct_iovec | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include <bits/alltypes.h> | ||
| 25 | |||
| 26 | #include <bits/fcntl.h> | ||
| 27 | |||
| 28 | struct flock { | ||
| 29 | 	short l_type; | ||
| 30 | 	short l_whence; | ||
| 31 | 	off_t l_start; | ||
| 32 | 	off_t l_len; | ||
| 33 | 	pid_t l_pid; | ||
| 34 | }; | ||
| 35 | |||
| 36 | int creat(const char *, mode_t); | ||
| 37 | int fcntl(int, int, ...); | ||
| 38 | int open(const char *, int, ...); | ||
| 39 | int openat(int, const char *, int, ...); | ||
| 40 | int posix_fadvise(int, off_t, off_t, int); | ||
| 41 | int posix_fallocate(int, off_t, off_t); | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 44 | #define O_SEARCH O_PATH | ||
| 45 | #define O_EXEC O_PATH | ||
| 46 | #define O_TTY_INIT 0 | ||
| 47 | |||
| 48 | #define O_ACCMODE (03|O_SEARCH) | ||
| 49 | #define O_RDONLY 00 | ||
| 50 | #define O_WRONLY 01 | ||
| 51 | #define O_RDWR 02 | ||
| 52 | |||
| 53 | #define F_OFD_GETLK 36 | ||
| 54 | #define F_OFD_SETLK 37 | ||
| 55 | #define F_OFD_SETLKW 38 | ||
| 56 | |||
| 57 | #define F_DUPFD_CLOEXEC 1030 | ||
| 58 | |||
| 59 | #define F_RDLCK 0 | ||
| 60 | #define F_WRLCK 1 | ||
| 61 | #define F_UNLCK 2 | ||
| 62 | |||
| 63 | #define FD_CLOEXEC 1 | ||
| 64 | |||
| 65 | #define AT_FDCWD (-100) | ||
| 66 | #define AT_SYMLINK_NOFOLLOW 0x100 | ||
| 67 | #define AT_REMOVEDIR 0x200 | ||
| 68 | #define AT_SYMLINK_FOLLOW 0x400 | ||
| 69 | #define AT_EACCESS 0x200 | ||
| 70 | |||
| 71 | #define POSIX_FADV_NORMAL 0 | ||
| 72 | #define POSIX_FADV_RANDOM 1 | ||
| 73 | #define POSIX_FADV_SEQUENTIAL 2 | ||
| 74 | #define POSIX_FADV_WILLNEED 3 | ||
| 75 | #ifndef POSIX_FADV_DONTNEED | ||
| 76 | #define POSIX_FADV_DONTNEED 4 | ||
| 77 | #define POSIX_FADV_NOREUSE 5 | ||
| 78 | #endif | ||
| 79 | |||
| 80 | #undef SEEK_SET | ||
| 81 | #undef SEEK_CUR | ||
| 82 | #undef SEEK_END | ||
| 83 | #define SEEK_SET 0 | ||
| 84 | #define SEEK_CUR 1 | ||
| 85 | #define SEEK_END 2 | ||
| 86 | |||
| 87 | #ifndef S_IRUSR | ||
| 88 | #define S_ISUID 04000 | ||
| 89 | #define S_ISGID 02000 | ||
| 90 | #define S_ISVTX 01000 | ||
| 91 | #define S_IRUSR 0400 | ||
| 92 | #define S_IWUSR 0200 | ||
| 93 | #define S_IXUSR 0100 | ||
| 94 | #define S_IRWXU 0700 | ||
| 95 | #define S_IRGRP 0040 | ||
| 96 | #define S_IWGRP 0020 | ||
| 97 | #define S_IXGRP 0010 | ||
| 98 | #define S_IRWXG 0070 | ||
| 99 | #define S_IROTH 0004 | ||
| 100 | #define S_IWOTH 0002 | ||
| 101 | #define S_IXOTH 0001 | ||
| 102 | #define S_IRWXO 0007 | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 106 | #define AT_NO_AUTOMOUNT 0x800 | ||
| 107 | #define AT_EMPTY_PATH 0x1000 | ||
| 108 | #define AT_STATX_SYNC_TYPE 0x6000 | ||
| 109 | #define AT_STATX_SYNC_AS_STAT 0x0000 | ||
| 110 | #define AT_STATX_FORCE_SYNC 0x2000 | ||
| 111 | #define AT_STATX_DONT_SYNC 0x4000 | ||
| 112 | #define AT_RECURSIVE 0x8000 | ||
| 113 | |||
| 114 | #define FAPPEND O_APPEND | ||
| 115 | #define FFSYNC O_SYNC | ||
| 116 | #define FASYNC O_ASYNC | ||
| 117 | #define FNONBLOCK O_NONBLOCK | ||
| 118 | #define FNDELAY O_NDELAY | ||
| 119 | |||
| 120 | #define F_OK 0 | ||
| 121 | #define R_OK 4 | ||
| 122 | #define W_OK 2 | ||
| 123 | #define X_OK 1 | ||
| 124 | #define F_ULOCK 0 | ||
| 125 | #define F_LOCK 1 | ||
| 126 | #define F_TLOCK 2 | ||
| 127 | #define F_TEST 3 | ||
| 128 | |||
| 129 | #define F_SETLEASE	1024 | ||
| 130 | #define F_GETLEASE	1025 | ||
| 131 | #define F_NOTIFY	1026 | ||
| 132 | #define F_CANCELLK	1029 | ||
| 133 | #define F_SETPIPE_SZ	1031 | ||
| 134 | #define F_GETPIPE_SZ	1032 | ||
| 135 | #define F_ADD_SEALS	1033 | ||
| 136 | #define F_GET_SEALS	1034 | ||
| 137 | |||
| 138 | #define F_SEAL_SEAL	0x0001 | ||
| 139 | #define F_SEAL_SHRINK	0x0002 | ||
| 140 | #define F_SEAL_GROW	0x0004 | ||
| 141 | #define F_SEAL_WRITE	0x0008 | ||
| 142 | #define F_SEAL_FUTURE_WRITE	0x0010 | ||
| 143 | |||
| 144 | #define F_GET_RW_HINT		1035 | ||
| 145 | #define F_SET_RW_HINT		1036 | ||
| 146 | #define F_GET_FILE_RW_HINT	1037 | ||
| 147 | #define F_SET_FILE_RW_HINT	1038 | ||
| 148 | |||
| 149 | #define RWF_WRITE_LIFE_NOT_SET	0 | ||
| 150 | #define RWH_WRITE_LIFE_NONE	1 | ||
| 151 | #define RWH_WRITE_LIFE_SHORT	2 | ||
| 152 | #define RWH_WRITE_LIFE_MEDIUM	3 | ||
| 153 | #define RWH_WRITE_LIFE_LONG	4 | ||
| 154 | #define RWH_WRITE_LIFE_EXTREME	5 | ||
| 155 | |||
| 156 | #define DN_ACCESS	0x00000001 | ||
| 157 | #define DN_MODIFY	0x00000002 | ||
| 158 | #define DN_CREATE	0x00000004 | ||
| 159 | #define DN_DELETE	0x00000008 | ||
| 160 | #define DN_RENAME	0x00000010 | ||
| 161 | #define DN_ATTRIB	0x00000020 | ||
| 162 | #define DN_MULTISHOT	0x80000000 | ||
| 163 | |||
| 164 | int lockf(int, int, off_t); | ||
| 165 | #endif | ||
| 166 | #endif | ||
| 167 | |||
| 168 | #if defined(_GNU_SOURCE) | ||
| 169 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 170 | #define F_OWNER_TID 0 | ||
| 171 | #define F_OWNER_PID 1 | ||
| 172 | #define F_OWNER_PGRP 2 | ||
| 173 | #define F_OWNER_GID 2 | ||
| 174 | struct file_handle { | ||
| 175 | 	unsigned handle_bytes; | ||
| 176 | 	int handle_type; | ||
| 177 | 	unsigned char f_handle[]; | ||
| 178 | }; | ||
| 179 | #endif | ||
| 180 | #ifdef __wasilibc_unmodified_upstream /* WASI has no F_GETOWN_EX */ | ||
| 181 | struct f_owner_ex { | ||
| 182 | 	int type; | ||
| 183 | 	pid_t pid; | ||
| 184 | }; | ||
| 185 | #endif | ||
| 186 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ | ||
| 187 | #define FALLOC_FL_KEEP_SIZE 1 | ||
| 188 | #define FALLOC_FL_PUNCH_HOLE 2 | ||
| 189 | #endif | ||
| 190 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 191 | #define MAX_HANDLE_SZ 128 | ||
| 192 | #endif | ||
| 193 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syc_file_range */ | ||
| 194 | #define SYNC_FILE_RANGE_WAIT_BEFORE 1 | ||
| 195 | #define SYNC_FILE_RANGE_WRITE 2 | ||
| 196 | #define SYNC_FILE_RANGE_WAIT_AFTER 4 | ||
| 197 | #endif | ||
| 198 | #ifdef __wasilibc_unmodified_upstream /* WASI has no splice */ | ||
| 199 | #define SPLICE_F_MOVE 1 | ||
| 200 | #define SPLICE_F_NONBLOCK 2 | ||
| 201 | #define SPLICE_F_MORE 4 | ||
| 202 | #define SPLICE_F_GIFT 8 | ||
| 203 | #endif | ||
| 204 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ | ||
| 205 | int fallocate(int, int, off_t, off_t); | ||
| 206 | #endif | ||
| 207 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 208 | int name_to_handle_at(int, const char *, struct file_handle *, int *, int); | ||
| 209 | int open_by_handle_at(int, struct file_handle *, int); | ||
| 210 | #endif | ||
| 211 | #ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */ | ||
| 212 | ssize_t readahead(int, off_t, size_t); | ||
| 213 | #endif | ||
| 214 | #ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */ | ||
| 215 | int sync_file_range(int, off_t, off_t, unsigned); | ||
| 216 | ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); | ||
| 217 | ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 218 | ssize_t tee(int, int, size_t, unsigned); | ||
| 219 | #endif | ||
| 220 | #define loff_t off_t | ||
| 221 | #endif | ||
| 222 | |||
| 223 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 224 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 225 | #define F_GETLK64 F_GETLK | ||
| 226 | #define F_SETLK64 F_SETLK | ||
| 227 | #define F_SETLKW64 F_SETLKW | ||
| 228 | #define flock64 flock | ||
| 229 | #endif | ||
| 230 | #define open64 open | ||
| 231 | #define openat64 openat | ||
| 232 | #define creat64 creat | ||
| 233 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 234 | #define lockf64 lockf | ||
| 235 | #endif | ||
| 236 | #define posix_fadvise64 posix_fadvise | ||
| 237 | #define posix_fallocate64 posix_fallocate | ||
| 238 | #define off64_t off_t | ||
| 239 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */ | ||
| 240 | #if defined(_GNU_SOURCE) | ||
| 241 | #define fallocate64 fallocate | ||
| 242 | #endif | ||
| 243 | #endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifdef __cplusplus | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | |||
| 250 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/float.h deleted-56| ... | @@ -1,56 +0,0 @@ | ||
| 1 | #ifndef _FLOAT_H | ||
| 2 | #define _FLOAT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of FLT_ROUNDS */ | ||
| 9 | int __flt_rounds(void); | ||
| 10 | #define FLT_ROUNDS (__flt_rounds()) | ||
| 11 | #else | ||
| 12 | #define FLT_ROUNDS (__builtin_flt_rounds()) | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #define FLT_RADIX 2 | ||
| 16 | |||
| 17 | #define FLT_TRUE_MIN 1.40129846432481707092e-45F | ||
| 18 | #define FLT_MIN 1.17549435082228750797e-38F | ||
| 19 | #define FLT_MAX 3.40282346638528859812e+38F | ||
| 20 | #define FLT_EPSILON 1.1920928955078125e-07F | ||
| 21 | |||
| 22 | #define FLT_MANT_DIG 24 | ||
| 23 | #define FLT_MIN_EXP (-125) | ||
| 24 | #define FLT_MAX_EXP 128 | ||
| 25 | #define FLT_HAS_SUBNORM 1 | ||
| 26 | |||
| 27 | #define FLT_DIG 6 | ||
| 28 | #define FLT_DECIMAL_DIG 9 | ||
| 29 | #define FLT_MIN_10_EXP (-37) | ||
| 30 | #define FLT_MAX_10_EXP 38 | ||
| 31 | |||
| 32 | #define DBL_TRUE_MIN 4.94065645841246544177e-324 | ||
| 33 | #define DBL_MIN 2.22507385850720138309e-308 | ||
| 34 | #define DBL_MAX 1.79769313486231570815e+308 | ||
| 35 | #define DBL_EPSILON 2.22044604925031308085e-16 | ||
| 36 | |||
| 37 | #define DBL_MANT_DIG 53 | ||
| 38 | #define DBL_MIN_EXP (-1021) | ||
| 39 | #define DBL_MAX_EXP 1024 | ||
| 40 | #define DBL_HAS_SUBNORM 1 | ||
| 41 | |||
| 42 | #define DBL_DIG 15 | ||
| 43 | #define DBL_DECIMAL_DIG 17 | ||
| 44 | #define DBL_MIN_10_EXP (-307) | ||
| 45 | #define DBL_MAX_10_EXP 308 | ||
| 46 | |||
| 47 | #define LDBL_HAS_SUBNORM 1 | ||
| 48 | #define LDBL_DECIMAL_DIG DECIMAL_DIG | ||
| 49 | |||
| 50 | #include <bits/float.h> | ||
| 51 | |||
| 52 | #ifdef __cplusplus | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/ftw.h deleted-45| ... | @@ -1,45 +0,0 @@ | ||
| 1 | #ifndef _FTW_H | ||
| 2 | #define	_FTW_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <sys/stat.h> | ||
| 10 | |||
| 11 | #define FTW_F 1 | ||
| 12 | #define FTW_D 2 | ||
| 13 | #define FTW_DNR 3 | ||
| 14 | #define FTW_NS 4 | ||
| 15 | #define FTW_SL 5 | ||
| 16 | #define FTW_DP 6 | ||
| 17 | #define FTW_SLN 7 | ||
| 18 | |||
| 19 | #define FTW_PHYS 1 | ||
| 20 | #define FTW_MOUNT 2 | ||
| 21 | #define FTW_CHDIR 4 | ||
| 22 | #define FTW_DEPTH 8 | ||
| 23 | |||
| 24 | struct FTW { | ||
| 25 | 	int base; | ||
| 26 | 	int level; | ||
| 27 | }; | ||
| 28 | |||
| 29 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 30 | int ftw(const char *, int (*)(const char *, const struct stat *, int), int); | ||
| 31 | #endif | ||
| 32 | int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int); | ||
| 33 | |||
| 34 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 35 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 36 | #define ftw64 ftw | ||
| 37 | #endif | ||
| 38 | #define nftw64 nftw | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifdef __cplusplus | ||
| 42 | } | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/glob.h deleted-54| ... | @@ -1,54 +0,0 @@ | ||
| 1 | #ifndef	_GLOB_H | ||
| 2 | #define	_GLOB_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | |||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | typedef struct { | ||
| 15 | 	size_t gl_pathc; | ||
| 16 | 	char **gl_pathv; | ||
| 17 | 	size_t gl_offs; | ||
| 18 | 	int __dummy1; | ||
| 19 | 	void *__dummy2[5]; | ||
| 20 | } glob_t; | ||
| 21 | |||
| 22 | int glob(const char *__restrict, int, int (*)(const char *, int), glob_t *__restrict); | ||
| 23 | void globfree(glob_t *); | ||
| 24 | |||
| 25 | #define GLOB_ERR 0x01 | ||
| 26 | #define GLOB_MARK 0x02 | ||
| 27 | #define GLOB_NOSORT 0x04 | ||
| 28 | #define GLOB_DOOFFS 0x08 | ||
| 29 | #define GLOB_NOCHECK 0x10 | ||
| 30 | #define GLOB_APPEND 0x20 | ||
| 31 | #define GLOB_NOESCAPE 0x40 | ||
| 32 | #define	GLOB_PERIOD 0x80 | ||
| 33 | |||
| 34 | #ifdef __wasilibc_unmodified_upstream // WASI has no usernames | ||
| 35 | #define GLOB_TILDE 0x1000 | ||
| 36 | #define GLOB_TILDE_CHECK 0x4000 | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #define GLOB_NOSPACE 1 | ||
| 40 | #define GLOB_ABORTED 2 | ||
| 41 | #define GLOB_NOMATCH 3 | ||
| 42 | #define GLOB_NOSYS 4 | ||
| 43 | |||
| 44 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 45 | #define glob64 glob | ||
| 46 | #define globfree64 globfree | ||
| 47 | #define glob64_t glob_t | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #ifdef __cplusplus | ||
| 51 | } | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/inttypes.h deleted-233| ... | @@ -1,233 +0,0 @@ | ||
| 1 | #ifndef _INTTYPES_H | ||
| 2 | #define _INTTYPES_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #ifdef __cplusplus | ||
| 6 | extern "C" { | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include <features.h> | ||
| 10 | #include <stdint.h> | ||
| 11 | |||
| 12 | #define __NEED_wchar_t | ||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | typedef struct { intmax_t quot, rem; } imaxdiv_t; | ||
| 16 | |||
| 17 | intmax_t imaxabs(intmax_t); | ||
| 18 | imaxdiv_t imaxdiv(intmax_t, intmax_t); | ||
| 19 | |||
| 20 | intmax_t strtoimax(const char *__restrict, char **__restrict, int); | ||
| 21 | uintmax_t strtoumax(const char *__restrict, char **__restrict, int); | ||
| 22 | |||
| 23 | intmax_t wcstoimax(const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 24 | uintmax_t wcstoumax(const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 25 | |||
| 26 | #if UINTPTR_MAX == UINT64_MAX | ||
| 27 | #define __PRI64 "l" | ||
| 28 | #define __PRIPTR "l" | ||
| 29 | #else | ||
| 30 | #define __PRI64 "ll" | ||
| 31 | #define __PRIPTR "" | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #define PRId8 "d" | ||
| 35 | #define PRId16 "d" | ||
| 36 | #define PRId32 "d" | ||
| 37 | #define PRId64 __PRI64 "d" | ||
| 38 | |||
| 39 | #define PRIdLEAST8 "d" | ||
| 40 | #define PRIdLEAST16 "d" | ||
| 41 | #define PRIdLEAST32 "d" | ||
| 42 | #define PRIdLEAST64 __PRI64 "d" | ||
| 43 | |||
| 44 | #define PRIdFAST8 "d" | ||
| 45 | #define PRIdFAST16 "d" | ||
| 46 | #define PRIdFAST32 "d" | ||
| 47 | #define PRIdFAST64 __PRI64 "d" | ||
| 48 | |||
| 49 | #define PRIi8 "i" | ||
| 50 | #define PRIi16 "i" | ||
| 51 | #define PRIi32 "i" | ||
| 52 | #define PRIi64 __PRI64 "i" | ||
| 53 | |||
| 54 | #define PRIiLEAST8 "i" | ||
| 55 | #define PRIiLEAST16 "i" | ||
| 56 | #define PRIiLEAST32 "i" | ||
| 57 | #define PRIiLEAST64 __PRI64 "i" | ||
| 58 | |||
| 59 | #define PRIiFAST8 "i" | ||
| 60 | #define PRIiFAST16 "i" | ||
| 61 | #define PRIiFAST32 "i" | ||
| 62 | #define PRIiFAST64 __PRI64 "i" | ||
| 63 | |||
| 64 | #define PRIo8 "o" | ||
| 65 | #define PRIo16 "o" | ||
| 66 | #define PRIo32 "o" | ||
| 67 | #define PRIo64 __PRI64 "o" | ||
| 68 | |||
| 69 | #define PRIoLEAST8 "o" | ||
| 70 | #define PRIoLEAST16 "o" | ||
| 71 | #define PRIoLEAST32 "o" | ||
| 72 | #define PRIoLEAST64 __PRI64 "o" | ||
| 73 | |||
| 74 | #define PRIoFAST8 "o" | ||
| 75 | #define PRIoFAST16 "o" | ||
| 76 | #define PRIoFAST32 "o" | ||
| 77 | #define PRIoFAST64 __PRI64 "o" | ||
| 78 | |||
| 79 | #define PRIu8 "u" | ||
| 80 | #define PRIu16 "u" | ||
| 81 | #define PRIu32 "u" | ||
| 82 | #define PRIu64 __PRI64 "u" | ||
| 83 | |||
| 84 | #define PRIuLEAST8 "u" | ||
| 85 | #define PRIuLEAST16 "u" | ||
| 86 | #define PRIuLEAST32 "u" | ||
| 87 | #define PRIuLEAST64 __PRI64 "u" | ||
| 88 | |||
| 89 | #define PRIuFAST8 "u" | ||
| 90 | #define PRIuFAST16 "u" | ||
| 91 | #define PRIuFAST32 "u" | ||
| 92 | #define PRIuFAST64 __PRI64 "u" | ||
| 93 | |||
| 94 | #define PRIx8 "x" | ||
| 95 | #define PRIx16 "x" | ||
| 96 | #define PRIx32 "x" | ||
| 97 | #define PRIx64 __PRI64 "x" | ||
| 98 | |||
| 99 | #define PRIxLEAST8 "x" | ||
| 100 | #define PRIxLEAST16 "x" | ||
| 101 | #define PRIxLEAST32 "x" | ||
| 102 | #define PRIxLEAST64 __PRI64 "x" | ||
| 103 | |||
| 104 | #define PRIxFAST8 "x" | ||
| 105 | #define PRIxFAST16 "x" | ||
| 106 | #define PRIxFAST32 "x" | ||
| 107 | #define PRIxFAST64 __PRI64 "x" | ||
| 108 | |||
| 109 | #define PRIX8 "X" | ||
| 110 | #define PRIX16 "X" | ||
| 111 | #define PRIX32 "X" | ||
| 112 | #define PRIX64 __PRI64 "X" | ||
| 113 | |||
| 114 | #define PRIXLEAST8 "X" | ||
| 115 | #define PRIXLEAST16 "X" | ||
| 116 | #define PRIXLEAST32 "X" | ||
| 117 | #define PRIXLEAST64 __PRI64 "X" | ||
| 118 | |||
| 119 | #define PRIXFAST8 "X" | ||
| 120 | #define PRIXFAST16 "X" | ||
| 121 | #define PRIXFAST32 "X" | ||
| 122 | #define PRIXFAST64 __PRI64 "X" | ||
| 123 | |||
| 124 | #define PRIdMAX __PRI64 "d" | ||
| 125 | #define PRIiMAX __PRI64 "i" | ||
| 126 | #define PRIoMAX __PRI64 "o" | ||
| 127 | #define PRIuMAX __PRI64 "u" | ||
| 128 | #define PRIxMAX __PRI64 "x" | ||
| 129 | #define PRIXMAX __PRI64 "X" | ||
| 130 | |||
| 131 | #define PRIdPTR __PRIPTR "d" | ||
| 132 | #define PRIiPTR __PRIPTR "i" | ||
| 133 | #define PRIoPTR __PRIPTR "o" | ||
| 134 | #define PRIuPTR __PRIPTR "u" | ||
| 135 | #define PRIxPTR __PRIPTR "x" | ||
| 136 | #define PRIXPTR __PRIPTR "X" | ||
| 137 | |||
| 138 | #define SCNd8 "hhd" | ||
| 139 | #define SCNd16 "hd" | ||
| 140 | #define SCNd32 "d" | ||
| 141 | #define SCNd64 __PRI64 "d" | ||
| 142 | |||
| 143 | #define SCNdLEAST8 "hhd" | ||
| 144 | #define SCNdLEAST16 "hd" | ||
| 145 | #define SCNdLEAST32 "d" | ||
| 146 | #define SCNdLEAST64 __PRI64 "d" | ||
| 147 | |||
| 148 | #define SCNdFAST8 "hhd" | ||
| 149 | #define SCNdFAST16 "d" | ||
| 150 | #define SCNdFAST32 "d" | ||
| 151 | #define SCNdFAST64 __PRI64 "d" | ||
| 152 | |||
| 153 | #define SCNi8 "hhi" | ||
| 154 | #define SCNi16 "hi" | ||
| 155 | #define SCNi32 "i" | ||
| 156 | #define SCNi64 __PRI64 "i" | ||
| 157 | |||
| 158 | #define SCNiLEAST8 "hhi" | ||
| 159 | #define SCNiLEAST16 "hi" | ||
| 160 | #define SCNiLEAST32 "i" | ||
| 161 | #define SCNiLEAST64 __PRI64 "i" | ||
| 162 | |||
| 163 | #define SCNiFAST8 "hhi" | ||
| 164 | #define SCNiFAST16 "i" | ||
| 165 | #define SCNiFAST32 "i" | ||
| 166 | #define SCNiFAST64 __PRI64 "i" | ||
| 167 | |||
| 168 | #define SCNu8 "hhu" | ||
| 169 | #define SCNu16 "hu" | ||
| 170 | #define SCNu32 "u" | ||
| 171 | #define SCNu64 __PRI64 "u" | ||
| 172 | |||
| 173 | #define SCNuLEAST8 "hhu" | ||
| 174 | #define SCNuLEAST16 "hu" | ||
| 175 | #define SCNuLEAST32 "u" | ||
| 176 | #define SCNuLEAST64 __PRI64 "u" | ||
| 177 | |||
| 178 | #define SCNuFAST8 "hhu" | ||
| 179 | #define SCNuFAST16 "u" | ||
| 180 | #define SCNuFAST32 "u" | ||
| 181 | #define SCNuFAST64 __PRI64 "u" | ||
| 182 | |||
| 183 | #define SCNo8 "hho" | ||
| 184 | #define SCNo16 "ho" | ||
| 185 | #define SCNo32 "o" | ||
| 186 | #define SCNo64 __PRI64 "o" | ||
| 187 | |||
| 188 | #define SCNoLEAST8 "hho" | ||
| 189 | #define SCNoLEAST16 "ho" | ||
| 190 | #define SCNoLEAST32 "o" | ||
| 191 | #define SCNoLEAST64 __PRI64 "o" | ||
| 192 | |||
| 193 | #define SCNoFAST8 "hho" | ||
| 194 | #define SCNoFAST16 "o" | ||
| 195 | #define SCNoFAST32 "o" | ||
| 196 | #define SCNoFAST64 __PRI64 "o" | ||
| 197 | |||
| 198 | #define SCNx8 "hhx" | ||
| 199 | #define SCNx16 "hx" | ||
| 200 | #define SCNx32 "x" | ||
| 201 | #define SCNx64 __PRI64 "x" | ||
| 202 | |||
| 203 | #define SCNxLEAST8 "hhx" | ||
| 204 | #define SCNxLEAST16 "hx" | ||
| 205 | #define SCNxLEAST32 "x" | ||
| 206 | #define SCNxLEAST64 __PRI64 "x" | ||
| 207 | |||
| 208 | #define SCNxFAST8 "hhx" | ||
| 209 | #define SCNxFAST16 "x" | ||
| 210 | #define SCNxFAST32 "x" | ||
| 211 | #define SCNxFAST64 __PRI64 "x" | ||
| 212 | |||
| 213 | #define SCNdMAX __PRI64 "d" | ||
| 214 | #define SCNiMAX __PRI64 "i" | ||
| 215 | #define SCNoMAX __PRI64 "o" | ||
| 216 | #define SCNuMAX __PRI64 "u" | ||
| 217 | #define SCNxMAX __PRI64 "x" | ||
| 218 | |||
| 219 | #define SCNdPTR __PRIPTR "d" | ||
| 220 | #define SCNiPTR __PRIPTR "i" | ||
| 221 | #define SCNoPTR __PRIPTR "o" | ||
| 222 | #define SCNuPTR __PRIPTR "u" | ||
| 223 | #define SCNxPTR __PRIPTR "x" | ||
| 224 | |||
| 225 | #ifdef __cplusplus | ||
| 226 | } | ||
| 227 | #endif | ||
| 228 | #else | ||
| 229 | #include <__header_inttypes.h> | ||
| 230 | #endif | ||
| 231 | |||
| 232 | #endif | ||
| 233 | |||
lib/libc/wasi/libc-top-half/musl/include/limits.h deleted-178| ... | @@ -1,178 +0,0 @@ | ||
| 1 | #ifndef _LIMITS_H | ||
| 2 | #define _LIMITS_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | #include <bits/alltypes.h> /* __LONG_MAX */ | ||
| 7 | |||
| 8 | /* Support signed or unsigned plain-char */ | ||
| 9 | |||
| 10 | #if '\xff' > 0 | ||
| 11 | #define CHAR_MIN 0 | ||
| 12 | #define CHAR_MAX 255 | ||
| 13 | #else | ||
| 14 | #define CHAR_MIN (-128) | ||
| 15 | #define CHAR_MAX 127 | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #define CHAR_BIT 8 | ||
| 19 | #define SCHAR_MIN (-128) | ||
| 20 | #define SCHAR_MAX 127 | ||
| 21 | #define UCHAR_MAX 255 | ||
| 22 | #define SHRT_MIN (-1-0x7fff) | ||
| 23 | #define SHRT_MAX 0x7fff | ||
| 24 | #define USHRT_MAX 0xffff | ||
| 25 | #define INT_MIN (-1-0x7fffffff) | ||
| 26 | #define INT_MAX 0x7fffffff | ||
| 27 | #define UINT_MAX 0xffffffffU | ||
| 28 | #define LONG_MIN (-LONG_MAX-1) | ||
| 29 | #define LONG_MAX __LONG_MAX | ||
| 30 | #define ULONG_MAX (2UL*LONG_MAX+1) | ||
| 31 | #define LLONG_MIN (-LLONG_MAX-1) | ||
| 32 | #define LLONG_MAX 0x7fffffffffffffffLL | ||
| 33 | #define ULLONG_MAX (2ULL*LLONG_MAX+1) | ||
| 34 | |||
| 35 | #define MB_LEN_MAX 4 | ||
| 36 | |||
| 37 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 38 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 39 | |||
| 40 | #include <bits/limits.h> | ||
| 41 | |||
| 42 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pipes */ | ||
| 43 | #define PIPE_BUF 4096 | ||
| 44 | #endif | ||
| 45 | #define FILESIZEBITS 64 | ||
| 46 | #ifndef NAME_MAX | ||
| 47 | #define NAME_MAX 255 | ||
| 48 | #endif | ||
| 49 | #define PATH_MAX 4096 | ||
| 50 | #define NGROUPS_MAX 32 | ||
| 51 | #define ARG_MAX 131072 | ||
| 52 | #define IOV_MAX 1024 | ||
| 53 | #define SYMLOOP_MAX 40 | ||
| 54 | #define WORD_BIT 32 | ||
| 55 | #define SSIZE_MAX LONG_MAX | ||
| 56 | #define TZNAME_MAX 6 | ||
| 57 | #define TTY_NAME_MAX 32 | ||
| 58 | #define HOST_NAME_MAX 255 | ||
| 59 | |||
| 60 | #if LONG_MAX == 0x7fffffffL | ||
| 61 | #define LONG_BIT 32 | ||
| 62 | #else | ||
| 63 | #define LONG_BIT 64 | ||
| 64 | #endif | ||
| 65 | |||
| 66 | /* Implementation choices... */ | ||
| 67 | |||
| 68 | #define PTHREAD_KEYS_MAX 128 | ||
| 69 | #define PTHREAD_STACK_MIN 2048 | ||
| 70 | #define PTHREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 71 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 72 | #define SEM_VALUE_MAX 0x7fffffff | ||
| 73 | #define SEM_NSEMS_MAX 256 | ||
| 74 | #endif | ||
| 75 | #define DELAYTIMER_MAX 0x7fffffff | ||
| 76 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mq */ | ||
| 77 | #define MQ_PRIO_MAX 32768 | ||
| 78 | #endif | ||
| 79 | #ifdef __wasilibc_unmodified_upstream /* WASI has no usernames */ | ||
| 80 | #define LOGIN_NAME_MAX 256 | ||
| 81 | #endif | ||
| 82 | |||
| 83 | /* Arbitrary numbers... */ | ||
| 84 | |||
| 85 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 86 | #define BC_BASE_MAX 99 | ||
| 87 | #define BC_DIM_MAX 2048 | ||
| 88 | #define BC_SCALE_MAX 99 | ||
| 89 | #define BC_STRING_MAX 1000 | ||
| 90 | #endif | ||
| 91 | #define CHARCLASS_NAME_MAX 14 | ||
| 92 | #define COLL_WEIGHTS_MAX 2 | ||
| 93 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 94 | #define EXPR_NEST_MAX 32 | ||
| 95 | #define LINE_MAX 4096 | ||
| 96 | #endif | ||
| 97 | #define RE_DUP_MAX 255 | ||
| 98 | |||
| 99 | #define NL_ARGMAX 9 | ||
| 100 | #define NL_MSGMAX 32767 | ||
| 101 | #define NL_SETMAX 255 | ||
| 102 | #define NL_TEXTMAX 2048 | ||
| 103 | |||
| 104 | #endif | ||
| 105 | |||
| 106 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) | ||
| 107 | |||
| 108 | #ifdef PAGESIZE | ||
| 109 | #define PAGE_SIZE PAGESIZE | ||
| 110 | #endif | ||
| 111 | #define NZERO 20 | ||
| 112 | #define NL_LANGMAX 32 | ||
| 113 | |||
| 114 | #endif | ||
| 115 | |||
| 116 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 117 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 118 | |||
| 119 | #define NL_NMAX 16 | ||
| 120 | |||
| 121 | #endif | ||
| 122 | |||
| 123 | /* POSIX/SUS requirements follow. These numbers come directly | ||
| 124 | * from SUS and have nothing to do with the host system. */ | ||
| 125 | |||
| 126 | #define _POSIX_AIO_LISTIO_MAX 2 | ||
| 127 | #define _POSIX_AIO_MAX 1 | ||
| 128 | #define _POSIX_ARG_MAX 4096 | ||
| 129 | #define _POSIX_CHILD_MAX 25 | ||
| 130 | #define _POSIX_CLOCKRES_MIN 20000000 | ||
| 131 | #define _POSIX_DELAYTIMER_MAX 32 | ||
| 132 | #define _POSIX_HOST_NAME_MAX 255 | ||
| 133 | #define _POSIX_LINK_MAX 8 | ||
| 134 | #define _POSIX_LOGIN_NAME_MAX 9 | ||
| 135 | #define _POSIX_MAX_CANON 255 | ||
| 136 | #define _POSIX_MAX_INPUT 255 | ||
| 137 | #define _POSIX_MQ_OPEN_MAX 8 | ||
| 138 | #define _POSIX_MQ_PRIO_MAX 32 | ||
| 139 | #define _POSIX_NAME_MAX 14 | ||
| 140 | #define _POSIX_NGROUPS_MAX 8 | ||
| 141 | #define _POSIX_OPEN_MAX 20 | ||
| 142 | #define _POSIX_PATH_MAX 256 | ||
| 143 | #define _POSIX_PIPE_BUF 512 | ||
| 144 | #define _POSIX_RE_DUP_MAX 255 | ||
| 145 | #define _POSIX_RTSIG_MAX 8 | ||
| 146 | #define _POSIX_SEM_NSEMS_MAX 256 | ||
| 147 | #define _POSIX_SEM_VALUE_MAX 32767 | ||
| 148 | #define _POSIX_SIGQUEUE_MAX 32 | ||
| 149 | #define _POSIX_SSIZE_MAX 32767 | ||
| 150 | #define _POSIX_STREAM_MAX 8 | ||
| 151 | #define _POSIX_SS_REPL_MAX 4 | ||
| 152 | #define _POSIX_SYMLINK_MAX 255 | ||
| 153 | #define _POSIX_SYMLOOP_MAX 8 | ||
| 154 | #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 155 | #define _POSIX_THREAD_KEYS_MAX 128 | ||
| 156 | #define _POSIX_THREAD_THREADS_MAX 64 | ||
| 157 | #define _POSIX_TIMER_MAX 32 | ||
| 158 | #define _POSIX_TRACE_EVENT_NAME_MAX 30 | ||
| 159 | #define _POSIX_TRACE_NAME_MAX 8 | ||
| 160 | #define _POSIX_TRACE_SYS_MAX 8 | ||
| 161 | #define _POSIX_TRACE_USER_EVENT_MAX 32 | ||
| 162 | #define _POSIX_TTY_NAME_MAX 9 | ||
| 163 | #define _POSIX_TZNAME_MAX 6 | ||
| 164 | #define _POSIX2_BC_BASE_MAX 99 | ||
| 165 | #define _POSIX2_BC_DIM_MAX 2048 | ||
| 166 | #define _POSIX2_BC_SCALE_MAX 99 | ||
| 167 | #define _POSIX2_BC_STRING_MAX 1000 | ||
| 168 | #define _POSIX2_CHARCLASS_NAME_MAX 14 | ||
| 169 | #define _POSIX2_COLL_WEIGHTS_MAX 2 | ||
| 170 | #define _POSIX2_EXPR_NEST_MAX 32 | ||
| 171 | #define _POSIX2_LINE_MAX 2048 | ||
| 172 | #define _POSIX2_RE_DUP_MAX 255 | ||
| 173 | |||
| 174 | #define _XOPEN_IOV_MAX 16 | ||
| 175 | #define _XOPEN_NAME_MAX 255 | ||
| 176 | #define _XOPEN_PATH_MAX 1024 | ||
| 177 | |||
| 178 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/locale.h deleted-93| ... | @@ -1,93 +0,0 @@ | ||
| 1 | #ifndef	_LOCALE_H | ||
| 2 | #define	_LOCALE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 11 | #if __cplusplus >= 201103L | ||
| 12 | #define NULL nullptr | ||
| 13 | #elif defined(__cplusplus) | ||
| 14 | #define NULL 0L | ||
| 15 | #else | ||
| 16 | #define NULL ((void*)0) | ||
| 17 | #endif | ||
| 18 | #else | ||
| 19 | #define __need_NULL | ||
| 20 | #include <stddef.h> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #define LC_CTYPE 0 | ||
| 24 | #define LC_NUMERIC 1 | ||
| 25 | #define LC_TIME 2 | ||
| 26 | #define LC_COLLATE 3 | ||
| 27 | #define LC_MONETARY 4 | ||
| 28 | #define LC_MESSAGES 5 | ||
| 29 | #define LC_ALL 6 | ||
| 30 | |||
| 31 | struct lconv { | ||
| 32 | 	char *decimal_point; | ||
| 33 | 	char *thousands_sep; | ||
| 34 | 	char *grouping; | ||
| 35 | |||
| 36 | 	char *int_curr_symbol; | ||
| 37 | 	char *currency_symbol; | ||
| 38 | 	char *mon_decimal_point; | ||
| 39 | 	char *mon_thousands_sep; | ||
| 40 | 	char *mon_grouping; | ||
| 41 | 	char *positive_sign; | ||
| 42 | 	char *negative_sign; | ||
| 43 | 	char int_frac_digits; | ||
| 44 | 	char frac_digits; | ||
| 45 | 	char p_cs_precedes; | ||
| 46 | 	char p_sep_by_space; | ||
| 47 | 	char n_cs_precedes; | ||
| 48 | 	char n_sep_by_space; | ||
| 49 | 	char p_sign_posn; | ||
| 50 | 	char n_sign_posn; | ||
| 51 | 	char int_p_cs_precedes; | ||
| 52 | 	char int_p_sep_by_space; | ||
| 53 | 	char int_n_cs_precedes; | ||
| 54 | 	char int_n_sep_by_space; | ||
| 55 | 	char int_p_sign_posn; | ||
| 56 | 	char int_n_sign_posn; | ||
| 57 | }; | ||
| 58 | |||
| 59 | |||
| 60 | char *setlocale (int, const char *); | ||
| 61 | struct lconv *localeconv(void); | ||
| 62 | |||
| 63 | |||
| 64 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 65 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 66 | |||
| 67 | #define __NEED_locale_t | ||
| 68 | |||
| 69 | #include <bits/alltypes.h> | ||
| 70 | |||
| 71 | #define LC_GLOBAL_LOCALE ((locale_t)-1) | ||
| 72 | |||
| 73 | #define LC_CTYPE_MASK (1<<LC_CTYPE) | ||
| 74 | #define LC_NUMERIC_MASK (1<<LC_NUMERIC) | ||
| 75 | #define LC_TIME_MASK (1<<LC_TIME) | ||
| 76 | #define LC_COLLATE_MASK (1<<LC_COLLATE) | ||
| 77 | #define LC_MONETARY_MASK (1<<LC_MONETARY) | ||
| 78 | #define LC_MESSAGES_MASK (1<<LC_MESSAGES) | ||
| 79 | #define LC_ALL_MASK 0x7fffffff | ||
| 80 | |||
| 81 | locale_t duplocale(locale_t); | ||
| 82 | void freelocale(locale_t); | ||
| 83 | locale_t newlocale(int, const char *, locale_t); | ||
| 84 | locale_t uselocale(locale_t); | ||
| 85 | |||
| 86 | #endif | ||
| 87 | |||
| 88 | |||
| 89 | #ifdef __cplusplus | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/malloc.h deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 1 | #ifndef _MALLOC_H | ||
| 2 | #define _MALLOC_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__functions_malloc.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #define __NEED_size_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 17 | void *malloc (size_t); | ||
| 18 | void *calloc (size_t, size_t); | ||
| 19 | void *realloc (void *, size_t); | ||
| 20 | void free (void *); | ||
| 21 | #endif | ||
| 22 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 23 | void *valloc (size_t); | ||
| 24 | void *memalign(size_t, size_t); | ||
| 25 | #endif | ||
| 26 | |||
| 27 | size_t malloc_usable_size(void *); | ||
| 28 | |||
| 29 | #ifdef __cplusplus | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/math.h deleted-459| ... | @@ -1,459 +0,0 @@ | ||
| 1 | #ifndef _MATH_H | ||
| 2 | #define _MATH_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_float_t | ||
| 11 | #define __NEED_double_t | ||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | #if 100*__GNUC__+__GNUC_MINOR__ >= 303 | ||
| 15 | #define NAN __builtin_nanf("") | ||
| 16 | #define INFINITY __builtin_inff() | ||
| 17 | #else | ||
| 18 | #define NAN (0.0f/0.0f) | ||
| 19 | #define INFINITY 1e5000f | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #define HUGE_VALF INFINITY | ||
| 23 | #define HUGE_VAL ((double)INFINITY) | ||
| 24 | #define HUGE_VALL ((long double)INFINITY) | ||
| 25 | |||
| 26 | #define MATH_ERRNO 1 | ||
| 27 | #define MATH_ERREXCEPT 2 | ||
| 28 | #define math_errhandling 2 | ||
| 29 | |||
| 30 | #define FP_ILOGBNAN (-1-0x7fffffff) | ||
| 31 | #define FP_ILOGB0 FP_ILOGBNAN | ||
| 32 | |||
| 33 | #define FP_NAN 0 | ||
| 34 | #define FP_INFINITE 1 | ||
| 35 | #define FP_ZERO 2 | ||
| 36 | #define FP_SUBNORMAL 3 | ||
| 37 | #define FP_NORMAL 4 | ||
| 38 | |||
| 39 | #ifdef __FP_FAST_FMA | ||
| 40 | #define FP_FAST_FMA 1 | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef __FP_FAST_FMAF | ||
| 44 | #define FP_FAST_FMAF 1 | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #ifdef __FP_FAST_FMAL | ||
| 48 | #define FP_FAST_FMAL 1 | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of the fpclassify-like operations */ | ||
| 52 | int __fpclassify(double); | ||
| 53 | int __fpclassifyf(float); | ||
| 54 | int __fpclassifyl(long double); | ||
| 55 | |||
| 56 | static __inline unsigned __FLOAT_BITS(float __f) | ||
| 57 | { | ||
| 58 | 	union {float __f; unsigned __i;} __u; | ||
| 59 | 	__u.__f = __f; | ||
| 60 | 	return __u.__i; | ||
| 61 | } | ||
| 62 | static __inline unsigned long long __DOUBLE_BITS(double __f) | ||
| 63 | { | ||
| 64 | 	union {double __f; unsigned long long __i;} __u; | ||
| 65 | 	__u.__f = __f; | ||
| 66 | 	return __u.__i; | ||
| 67 | } | ||
| 68 | |||
| 69 | #define fpclassify(x) ( \ | ||
| 70 | 	sizeof(x) == sizeof(float) ? __fpclassifyf(x) : \ | ||
| 71 | 	sizeof(x) == sizeof(double) ? __fpclassify(x) : \ | ||
| 72 | 	__fpclassifyl(x) ) | ||
| 73 | |||
| 74 | #define isinf(x) ( \ | ||
| 75 | 	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) == 0x7f800000 : \ | ||
| 76 | 	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) == 0x7ffULL<<52 : \ | ||
| 77 | 	__fpclassifyl(x) == FP_INFINITE) | ||
| 78 | |||
| 79 | #define isnan(x) ( \ | ||
| 80 | 	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) > 0x7f800000 : \ | ||
| 81 | 	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) > 0x7ffULL<<52 : \ | ||
| 82 | 	__fpclassifyl(x) == FP_NAN) | ||
| 83 | |||
| 84 | #define isnormal(x) ( \ | ||
| 85 | 	sizeof(x) == sizeof(float) ? ((__FLOAT_BITS(x)+0x00800000) & 0x7fffffff) >= 0x01000000 : \ | ||
| 86 | 	sizeof(x) == sizeof(double) ? ((__DOUBLE_BITS(x)+(1ULL<<52)) & -1ULL>>1) >= 1ULL<<53 : \ | ||
| 87 | 	__fpclassifyl(x) == FP_NORMAL) | ||
| 88 | |||
| 89 | #define isfinite(x) ( \ | ||
| 90 | 	sizeof(x) == sizeof(float) ? (__FLOAT_BITS(x) & 0x7fffffff) < 0x7f800000 : \ | ||
| 91 | 	sizeof(x) == sizeof(double) ? (__DOUBLE_BITS(x) & -1ULL>>1) < 0x7ffULL<<52 : \ | ||
| 92 | 	__fpclassifyl(x) > FP_INFINITE) | ||
| 93 | |||
| 94 | int __signbit(double); | ||
| 95 | int __signbitf(float); | ||
| 96 | int __signbitl(long double); | ||
| 97 | |||
| 98 | #define signbit(x) ( \ | ||
| 99 | 	sizeof(x) == sizeof(float) ? (int)(__FLOAT_BITS(x)>>31) : \ | ||
| 100 | 	sizeof(x) == sizeof(double) ? (int)(__DOUBLE_BITS(x)>>63) : \ | ||
| 101 | 	__signbitl(x) ) | ||
| 102 | |||
| 103 | #define isunordered(x,y) (isnan((x)) ? ((void)(y),1) : isnan((y))) | ||
| 104 | |||
| 105 | #define __ISREL_DEF(rel, op, type) \ | ||
| 106 | static __inline int __is##rel(type __x, type __y) \ | ||
| 107 | { return !isunordered(__x,__y) && __x op __y; } | ||
| 108 | |||
| 109 | __ISREL_DEF(lessf, <, float_t) | ||
| 110 | __ISREL_DEF(less, <, double_t) | ||
| 111 | __ISREL_DEF(lessl, <, long double) | ||
| 112 | __ISREL_DEF(lessequalf, <=, float_t) | ||
| 113 | __ISREL_DEF(lessequal, <=, double_t) | ||
| 114 | __ISREL_DEF(lessequall, <=, long double) | ||
| 115 | __ISREL_DEF(lessgreaterf, !=, float_t) | ||
| 116 | __ISREL_DEF(lessgreater, !=, double_t) | ||
| 117 | __ISREL_DEF(lessgreaterl, !=, long double) | ||
| 118 | __ISREL_DEF(greaterf, >, float_t) | ||
| 119 | __ISREL_DEF(greater, >, double_t) | ||
| 120 | __ISREL_DEF(greaterl, >, long double) | ||
| 121 | __ISREL_DEF(greaterequalf, >=, float_t) | ||
| 122 | __ISREL_DEF(greaterequal, >=, double_t) | ||
| 123 | __ISREL_DEF(greaterequall, >=, long double) | ||
| 124 | |||
| 125 | #define __tg_pred_2(x, y, p) ( \ | ||
| 126 | 	sizeof((x)+(y)) == sizeof(float) ? p##f(x, y) : \ | ||
| 127 | 	sizeof((x)+(y)) == sizeof(double) ? p(x, y) : \ | ||
| 128 | 	p##l(x, y) ) | ||
| 129 | |||
| 130 | #define isless(x, y) __tg_pred_2(x, y, __isless) | ||
| 131 | #define islessequal(x, y) __tg_pred_2(x, y, __islessequal) | ||
| 132 | #define islessgreater(x, y) __tg_pred_2(x, y, __islessgreater) | ||
| 133 | #define isgreater(x, y) __tg_pred_2(x, y, __isgreater) | ||
| 134 | #define isgreaterequal(x, y) __tg_pred_2(x, y, __isgreaterequal) | ||
| 135 | #else | ||
| 136 | #define fpclassify(x) (__builtin_fpclassify(FP_NAN, FP_INFINITE, \ | ||
| 137 | FP_NORMAL, FP_SUBNORMAL, \ | ||
| 138 | FP_ZERO, x)) | ||
| 139 | #define isinf(x) (__builtin_isinf(x)) | ||
| 140 | #define isnan(x) (__builtin_isnan(x)) | ||
| 141 | #define isnormal(x) (__builtin_isnormal(x)) | ||
| 142 | #define isfinite(x) (__builtin_isfinite(x)) | ||
| 143 | #define signbit(x) (__builtin_signbit(x)) | ||
| 144 | #define isunordered(x, y) (__builtin_isunordered(x, y)) | ||
| 145 | #define isless(x, y) (__builtin_isless(x, y)) | ||
| 146 | #define islessequal(x, y) (__builtin_islessequal(x, y)) | ||
| 147 | #define islessgreater(x, y) (__builtin_islessgreater(x, y)) | ||
| 148 | #define isgreater(x, y) (__builtin_isgreater(x, y)) | ||
| 149 | #define isgreaterequal(x, y) (__builtin_isgreaterequal(x, y)) | ||
| 150 | #endif | ||
| 151 | |||
| 152 | double acos(double); | ||
| 153 | float acosf(float); | ||
| 154 | long double acosl(long double); | ||
| 155 | |||
| 156 | double acosh(double); | ||
| 157 | float acoshf(float); | ||
| 158 | long double acoshl(long double); | ||
| 159 | |||
| 160 | double asin(double); | ||
| 161 | float asinf(float); | ||
| 162 | long double asinl(long double); | ||
| 163 | |||
| 164 | double asinh(double); | ||
| 165 | float asinhf(float); | ||
| 166 | long double asinhl(long double); | ||
| 167 | |||
| 168 | double atan(double); | ||
| 169 | float atanf(float); | ||
| 170 | long double atanl(long double); | ||
| 171 | |||
| 172 | double atan2(double, double); | ||
| 173 | float atan2f(float, float); | ||
| 174 | long double atan2l(long double, long double); | ||
| 175 | |||
| 176 | double atanh(double); | ||
| 177 | float atanhf(float); | ||
| 178 | long double atanhl(long double); | ||
| 179 | |||
| 180 | double cbrt(double); | ||
| 181 | float cbrtf(float); | ||
| 182 | long double cbrtl(long double); | ||
| 183 | |||
| 184 | double ceil(double); | ||
| 185 | float ceilf(float); | ||
| 186 | long double ceill(long double); | ||
| 187 | |||
| 188 | double copysign(double, double); | ||
| 189 | float copysignf(float, float); | ||
| 190 | long double copysignl(long double, long double); | ||
| 191 | |||
| 192 | double cos(double); | ||
| 193 | float cosf(float); | ||
| 194 | long double cosl(long double); | ||
| 195 | |||
| 196 | double cosh(double); | ||
| 197 | float coshf(float); | ||
| 198 | long double coshl(long double); | ||
| 199 | |||
| 200 | double erf(double); | ||
| 201 | float erff(float); | ||
| 202 | long double erfl(long double); | ||
| 203 | |||
| 204 | double erfc(double); | ||
| 205 | float erfcf(float); | ||
| 206 | long double erfcl(long double); | ||
| 207 | |||
| 208 | double exp(double); | ||
| 209 | float expf(float); | ||
| 210 | long double expl(long double); | ||
| 211 | |||
| 212 | double exp2(double); | ||
| 213 | float exp2f(float); | ||
| 214 | long double exp2l(long double); | ||
| 215 | |||
| 216 | double expm1(double); | ||
| 217 | float expm1f(float); | ||
| 218 | long double expm1l(long double); | ||
| 219 | |||
| 220 | double fabs(double); | ||
| 221 | float fabsf(float); | ||
| 222 | long double fabsl(long double); | ||
| 223 | |||
| 224 | double fdim(double, double); | ||
| 225 | float fdimf(float, float); | ||
| 226 | long double fdiml(long double, long double); | ||
| 227 | |||
| 228 | double floor(double); | ||
| 229 | float floorf(float); | ||
| 230 | long double floorl(long double); | ||
| 231 | |||
| 232 | double fma(double, double, double); | ||
| 233 | float fmaf(float, float, float); | ||
| 234 | long double fmal(long double, long double, long double); | ||
| 235 | |||
| 236 | double fmax(double, double); | ||
| 237 | float fmaxf(float, float); | ||
| 238 | long double fmaxl(long double, long double); | ||
| 239 | |||
| 240 | double fmin(double, double); | ||
| 241 | float fminf(float, float); | ||
| 242 | long double fminl(long double, long double); | ||
| 243 | |||
| 244 | double fmod(double, double); | ||
| 245 | float fmodf(float, float); | ||
| 246 | long double fmodl(long double, long double); | ||
| 247 | |||
| 248 | double frexp(double, int *); | ||
| 249 | float frexpf(float, int *); | ||
| 250 | long double frexpl(long double, int *); | ||
| 251 | |||
| 252 | double hypot(double, double); | ||
| 253 | float hypotf(float, float); | ||
| 254 | long double hypotl(long double, long double); | ||
| 255 | |||
| 256 | int ilogb(double); | ||
| 257 | int ilogbf(float); | ||
| 258 | int ilogbl(long double); | ||
| 259 | |||
| 260 | double ldexp(double, int); | ||
| 261 | float ldexpf(float, int); | ||
| 262 | long double ldexpl(long double, int); | ||
| 263 | |||
| 264 | double lgamma(double); | ||
| 265 | float lgammaf(float); | ||
| 266 | long double lgammal(long double); | ||
| 267 | |||
| 268 | long long llrint(double); | ||
| 269 | long long llrintf(float); | ||
| 270 | long long llrintl(long double); | ||
| 271 | |||
| 272 | long long llround(double); | ||
| 273 | long long llroundf(float); | ||
| 274 | long long llroundl(long double); | ||
| 275 | |||
| 276 | double log(double); | ||
| 277 | float logf(float); | ||
| 278 | long double logl(long double); | ||
| 279 | |||
| 280 | double log10(double); | ||
| 281 | float log10f(float); | ||
| 282 | long double log10l(long double); | ||
| 283 | |||
| 284 | double log1p(double); | ||
| 285 | float log1pf(float); | ||
| 286 | long double log1pl(long double); | ||
| 287 | |||
| 288 | double log2(double); | ||
| 289 | float log2f(float); | ||
| 290 | long double log2l(long double); | ||
| 291 | |||
| 292 | double logb(double); | ||
| 293 | float logbf(float); | ||
| 294 | long double logbl(long double); | ||
| 295 | |||
| 296 | long lrint(double); | ||
| 297 | long lrintf(float); | ||
| 298 | long lrintl(long double); | ||
| 299 | |||
| 300 | long lround(double); | ||
| 301 | long lroundf(float); | ||
| 302 | long lroundl(long double); | ||
| 303 | |||
| 304 | double modf(double, double *); | ||
| 305 | float modff(float, float *); | ||
| 306 | long double modfl(long double, long double *); | ||
| 307 | |||
| 308 | double nan(const char *); | ||
| 309 | float nanf(const char *); | ||
| 310 | long double nanl(const char *); | ||
| 311 | |||
| 312 | double nearbyint(double); | ||
| 313 | float nearbyintf(float); | ||
| 314 | long double nearbyintl(long double); | ||
| 315 | |||
| 316 | double nextafter(double, double); | ||
| 317 | float nextafterf(float, float); | ||
| 318 | long double nextafterl(long double, long double); | ||
| 319 | |||
| 320 | double nexttoward(double, long double); | ||
| 321 | float nexttowardf(float, long double); | ||
| 322 | long double nexttowardl(long double, long double); | ||
| 323 | |||
| 324 | double pow(double, double); | ||
| 325 | float powf(float, float); | ||
| 326 | long double powl(long double, long double); | ||
| 327 | |||
| 328 | double remainder(double, double); | ||
| 329 | float remainderf(float, float); | ||
| 330 | long double remainderl(long double, long double); | ||
| 331 | |||
| 332 | double remquo(double, double, int *); | ||
| 333 | float remquof(float, float, int *); | ||
| 334 | long double remquol(long double, long double, int *); | ||
| 335 | |||
| 336 | double rint(double); | ||
| 337 | float rintf(float); | ||
| 338 | long double rintl(long double); | ||
| 339 | |||
| 340 | double round(double); | ||
| 341 | float roundf(float); | ||
| 342 | long double roundl(long double); | ||
| 343 | |||
| 344 | double scalbln(double, long); | ||
| 345 | float scalblnf(float, long); | ||
| 346 | long double scalblnl(long double, long); | ||
| 347 | |||
| 348 | double scalbn(double, int); | ||
| 349 | float scalbnf(float, int); | ||
| 350 | long double scalbnl(long double, int); | ||
| 351 | |||
| 352 | double sin(double); | ||
| 353 | float sinf(float); | ||
| 354 | long double sinl(long double); | ||
| 355 | |||
| 356 | double sinh(double); | ||
| 357 | float sinhf(float); | ||
| 358 | long double sinhl(long double); | ||
| 359 | |||
| 360 | double sqrt(double); | ||
| 361 | float sqrtf(float); | ||
| 362 | long double sqrtl(long double); | ||
| 363 | |||
| 364 | double tan(double); | ||
| 365 | float tanf(float); | ||
| 366 | long double tanl(long double); | ||
| 367 | |||
| 368 | double tanh(double); | ||
| 369 | float tanhf(float); | ||
| 370 | long double tanhl(long double); | ||
| 371 | |||
| 372 | double tgamma(double); | ||
| 373 | float tgammaf(float); | ||
| 374 | long double tgammal(long double); | ||
| 375 | |||
| 376 | double trunc(double); | ||
| 377 | float truncf(float); | ||
| 378 | long double truncl(long double); | ||
| 379 | |||
| 380 | |||
| 381 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) | ||
| 382 | #undef MAXFLOAT | ||
| 383 | #define MAXFLOAT 3.40282346638528859812e+38F | ||
| 384 | #endif | ||
| 385 | |||
| 386 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 387 | #define M_E 2.7182818284590452354 /* e */ | ||
| 388 | #define M_LOG2E 1.4426950408889634074 /* log_2 e */ | ||
| 389 | #define M_LOG10E 0.43429448190325182765 /* log_10 e */ | ||
| 390 | #define M_LN2 0.69314718055994530942 /* log_e 2 */ | ||
| 391 | #define M_LN10 2.30258509299404568402 /* log_e 10 */ | ||
| 392 | #define M_PI 3.14159265358979323846 /* pi */ | ||
| 393 | #define M_PI_2 1.57079632679489661923 /* pi/2 */ | ||
| 394 | #define M_PI_4 0.78539816339744830962 /* pi/4 */ | ||
| 395 | #define M_1_PI 0.31830988618379067154 /* 1/pi */ | ||
| 396 | #define M_2_PI 0.63661977236758134308 /* 2/pi */ | ||
| 397 | #define M_2_SQRTPI 1.12837916709551257390 /* 2/sqrt(pi) */ | ||
| 398 | #define M_SQRT2 1.41421356237309504880 /* sqrt(2) */ | ||
| 399 | #define M_SQRT1_2 0.70710678118654752440 /* 1/sqrt(2) */ | ||
| 400 | |||
| 401 | extern int signgam; | ||
| 402 | |||
| 403 | double j0(double); | ||
| 404 | double j1(double); | ||
| 405 | double jn(int, double); | ||
| 406 | |||
| 407 | double y0(double); | ||
| 408 | double y1(double); | ||
| 409 | double yn(int, double); | ||
| 410 | #endif | ||
| 411 | |||
| 412 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 413 | #define HUGE 3.40282346638528859812e+38F | ||
| 414 | |||
| 415 | double drem(double, double); | ||
| 416 | float dremf(float, float); | ||
| 417 | |||
| 418 | int finite(double); | ||
| 419 | int finitef(float); | ||
| 420 | |||
| 421 | double scalb(double, double); | ||
| 422 | float scalbf(float, float); | ||
| 423 | |||
| 424 | double significand(double); | ||
| 425 | float significandf(float); | ||
| 426 | |||
| 427 | double lgamma_r(double, int*); | ||
| 428 | float lgammaf_r(float, int*); | ||
| 429 | |||
| 430 | float j0f(float); | ||
| 431 | float j1f(float); | ||
| 432 | float jnf(int, float); | ||
| 433 | |||
| 434 | float y0f(float); | ||
| 435 | float y1f(float); | ||
| 436 | float ynf(int, float); | ||
| 437 | #endif | ||
| 438 | |||
| 439 | #ifdef _GNU_SOURCE | ||
| 440 | long double lgammal_r(long double, int*); | ||
| 441 | |||
| 442 | void sincos(double, double*, double*); | ||
| 443 | void sincosf(float, float*, float*); | ||
| 444 | void sincosl(long double, long double*, long double*); | ||
| 445 | |||
| 446 | double exp10(double); | ||
| 447 | float exp10f(float); | ||
| 448 | long double exp10l(long double); | ||
| 449 | |||
| 450 | double pow10(double); | ||
| 451 | float pow10f(float); | ||
| 452 | long double pow10l(long double); | ||
| 453 | #endif | ||
| 454 | |||
| 455 | #ifdef __cplusplus | ||
| 456 | } | ||
| 457 | #endif | ||
| 458 | |||
| 459 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netdb.h deleted-162| ... | @@ -1,162 +0,0 @@ | ||
| 1 | #ifndef	_NETDB_H | ||
| 2 | #define	_NETDB_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 12 | #define __NEED_size_t | ||
| 13 | #include <bits/alltypes.h> | ||
| 14 | #endif | ||
| 15 | |||
| 16 | struct addrinfo { | ||
| 17 | 	int ai_flags; | ||
| 18 | 	int ai_family; | ||
| 19 | 	int ai_socktype; | ||
| 20 | 	int ai_protocol; | ||
| 21 | 	socklen_t ai_addrlen; | ||
| 22 | 	struct sockaddr *ai_addr; | ||
| 23 | 	char *ai_canonname; | ||
| 24 | 	struct addrinfo *ai_next; | ||
| 25 | }; | ||
| 26 | |||
| 27 | #define AI_PASSIVE 0x01 | ||
| 28 | #define AI_CANONNAME 0x02 | ||
| 29 | #define AI_NUMERICHOST 0x04 | ||
| 30 | #define AI_V4MAPPED 0x08 | ||
| 31 | #define AI_ALL 0x10 | ||
| 32 | #define AI_ADDRCONFIG 0x20 | ||
| 33 | #define AI_NUMERICSERV 0x400 | ||
| 34 | |||
| 35 | |||
| 36 | #define NI_NUMERICHOST 0x01 | ||
| 37 | #define NI_NUMERICSERV 0x02 | ||
| 38 | #define NI_NOFQDN 0x04 | ||
| 39 | #define NI_NAMEREQD 0x08 | ||
| 40 | #define NI_DGRAM 0x10 | ||
| 41 | #define NI_NUMERICSCOPE 0x100 | ||
| 42 | |||
| 43 | #define EAI_BADFLAGS -1 | ||
| 44 | #define EAI_NONAME -2 | ||
| 45 | #define EAI_AGAIN -3 | ||
| 46 | #define EAI_FAIL -4 | ||
| 47 | #define EAI_NODATA -5 | ||
| 48 | #define EAI_FAMILY -6 | ||
| 49 | #define EAI_SOCKTYPE -7 | ||
| 50 | #define EAI_SERVICE -8 | ||
| 51 | #define EAI_MEMORY -10 | ||
| 52 | #define EAI_SYSTEM -11 | ||
| 53 | #define EAI_OVERFLOW -12 | ||
| 54 | |||
| 55 | int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); | ||
| 56 | void freeaddrinfo (struct addrinfo *); | ||
| 57 | int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); | ||
| 58 | const char *gai_strerror(int); | ||
| 59 | |||
| 60 | |||
| 61 | /* Legacy functions follow (marked OBsolete in SUS) */ | ||
| 62 | |||
| 63 | struct netent { | ||
| 64 | 	char *n_name; | ||
| 65 | 	char **n_aliases; | ||
| 66 | 	int n_addrtype; | ||
| 67 | 	uint32_t n_net; | ||
| 68 | }; | ||
| 69 | |||
| 70 | struct hostent { | ||
| 71 | 	char *h_name; | ||
| 72 | 	char **h_aliases; | ||
| 73 | 	int h_addrtype; | ||
| 74 | 	int h_length; | ||
| 75 | 	char **h_addr_list; | ||
| 76 | }; | ||
| 77 | #define h_addr h_addr_list[0] | ||
| 78 | |||
| 79 | struct servent { | ||
| 80 | 	char *s_name; | ||
| 81 | 	char **s_aliases; | ||
| 82 | 	int s_port; | ||
| 83 | 	char *s_proto; | ||
| 84 | }; | ||
| 85 | |||
| 86 | struct protoent { | ||
| 87 | 	char *p_name; | ||
| 88 | 	char **p_aliases; | ||
| 89 | 	int p_proto; | ||
| 90 | }; | ||
| 91 | |||
| 92 | void sethostent (int); | ||
| 93 | void endhostent (void); | ||
| 94 | struct hostent *gethostent (void); | ||
| 95 | |||
| 96 | void setnetent (int); | ||
| 97 | void endnetent (void); | ||
| 98 | struct netent *getnetent (void); | ||
| 99 | struct netent *getnetbyaddr (uint32_t, int); | ||
| 100 | struct netent *getnetbyname (const char *); | ||
| 101 | |||
| 102 | void setservent (int); | ||
| 103 | void endservent (void); | ||
| 104 | struct servent *getservent (void); | ||
| 105 | struct servent *getservbyname (const char *, const char *); | ||
| 106 | struct servent *getservbyport (int, const char *); | ||
| 107 | |||
| 108 | void setprotoent (int); | ||
| 109 | void endprotoent (void); | ||
| 110 | struct protoent *getprotoent (void); | ||
| 111 | struct protoent *getprotobyname (const char *); | ||
| 112 | struct protoent *getprotobynumber (int); | ||
| 113 | |||
| 114 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | ||
| 115 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | ||
| 116 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 117 | struct hostent *gethostbyname (const char *); | ||
| 118 | struct hostent *gethostbyaddr (const void *, socklen_t, int); | ||
| 119 | #ifdef __GNUC__ | ||
| 120 | __attribute__((const)) | ||
| 121 | #endif | ||
| 122 | #ifdef __wasilibc_unmodified_upstream | ||
| 123 | int *__h_errno_location(void); | ||
| 124 | #define h_errno (*__h_errno_location()) | ||
| 125 | #elif (defined __wasilibc_use_wasip2) | ||
| 126 | extern _Thread_local int h_errno; | ||
| 127 | #define h_errno h_errno | ||
| 128 | #endif | ||
| 129 | #define HOST_NOT_FOUND 1 | ||
| 130 | #define TRY_AGAIN 2 | ||
| 131 | #define NO_RECOVERY 3 | ||
| 132 | #define NO_DATA 4 | ||
| 133 | #define NO_ADDRESS NO_DATA | ||
| 134 | #endif | ||
| 135 | |||
| 136 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 137 | void herror(const char *); | ||
| 138 | const char *hstrerror(int); | ||
| 139 | int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); | ||
| 140 | int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); | ||
| 141 | struct hostent *gethostbyname2(const char *, int); | ||
| 142 | int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); | ||
| 143 | int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); | ||
| 144 | int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); | ||
| 145 | #define EAI_NODATA -5 | ||
| 146 | #define EAI_ADDRFAMILY -9 | ||
| 147 | #define EAI_INPROGRESS -100 | ||
| 148 | #define EAI_CANCELED -101 | ||
| 149 | #define EAI_NOTCANCELED -102 | ||
| 150 | #define EAI_ALLDONE -103 | ||
| 151 | #define EAI_INTR -104 | ||
| 152 | #define EAI_IDN_ENCODE -105 | ||
| 153 | #define NI_MAXHOST 255 | ||
| 154 | #define NI_MAXSERV 32 | ||
| 155 | #endif | ||
| 156 | |||
| 157 | |||
| 158 | #ifdef __cplusplus | ||
| 159 | } | ||
| 160 | #endif | ||
| 161 | |||
| 162 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/in.h deleted-433| ... | @@ -1,433 +0,0 @@ | ||
| 1 | #ifndef	_NETINET_IN_H | ||
| 2 | #define	_NETINET_IN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <inttypes.h> | ||
| 10 | #include <sys/socket.h> | ||
| 11 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 12 | #else | ||
| 13 | #include <__header_netinet_in.h> | ||
| 14 | #endif | ||
| 15 | |||
| 16 | typedef uint16_t in_port_t; | ||
| 17 | typedef uint32_t in_addr_t; | ||
| 18 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 19 | struct in_addr { in_addr_t s_addr; }; | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 23 | struct sockaddr_in { | ||
| 24 | 	sa_family_t sin_family; | ||
| 25 | 	in_port_t sin_port; | ||
| 26 | 	struct in_addr sin_addr; | ||
| 27 | 	uint8_t sin_zero[8]; | ||
| 28 | }; | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 32 | struct in6_addr { | ||
| 33 | 	union { | ||
| 34 | 		uint8_t __s6_addr[16]; | ||
| 35 | 		uint16_t __s6_addr16[8]; | ||
| 36 | 		uint32_t __s6_addr32[4]; | ||
| 37 | 	} __in6_union; | ||
| 38 | }; | ||
| 39 | #define s6_addr __in6_union.__s6_addr | ||
| 40 | #define s6_addr16 __in6_union.__s6_addr16 | ||
| 41 | #define s6_addr32 __in6_union.__s6_addr32 | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 45 | struct sockaddr_in6 { | ||
| 46 | 	sa_family_t sin6_family; | ||
| 47 | 	in_port_t sin6_port; | ||
| 48 | 	uint32_t sin6_flowinfo; | ||
| 49 | 	struct in6_addr sin6_addr; | ||
| 50 | 	uint32_t sin6_scope_id; | ||
| 51 | }; | ||
| 52 | #endif | ||
| 53 | |||
| 54 | struct ipv6_mreq { | ||
| 55 | 	struct in6_addr ipv6mr_multiaddr; | ||
| 56 | 	unsigned ipv6mr_interface; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #define INADDR_ANY ((in_addr_t) 0x00000000) | ||
| 60 | #define INADDR_BROADCAST ((in_addr_t) 0xffffffff) | ||
| 61 | #define INADDR_NONE ((in_addr_t) 0xffffffff) | ||
| 62 | #define INADDR_LOOPBACK ((in_addr_t) 0x7f000001) | ||
| 63 | #define INADDR_DUMMY ((in_addr_t) 0xc0000008) | ||
| 64 | |||
| 65 | #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) | ||
| 66 | #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) | ||
| 67 | #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) | ||
| 68 | #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) | ||
| 69 | #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) | ||
| 70 | |||
| 71 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 72 | #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } | ||
| 73 | #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } | ||
| 74 | #endif | ||
| 75 | |||
| 76 | extern const struct in6_addr in6addr_any, in6addr_loopback; | ||
| 77 | |||
| 78 | #define INET_ADDRSTRLEN 16 | ||
| 79 | #define INET6_ADDRSTRLEN 46 | ||
| 80 | |||
| 81 | uint32_t htonl(uint32_t); | ||
| 82 | uint16_t htons(uint16_t); | ||
| 83 | uint32_t ntohl(uint32_t); | ||
| 84 | uint16_t ntohs(uint16_t); | ||
| 85 | |||
| 86 | #define IPPORT_RESERVED 1024 | ||
| 87 | |||
| 88 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 89 | #define IPPROTO_IP 0 | ||
| 90 | #define IPPROTO_HOPOPTS 0 | ||
| 91 | #define IPPROTO_ICMP 1 | ||
| 92 | #define IPPROTO_IGMP 2 | ||
| 93 | #define IPPROTO_IPIP 4 | ||
| 94 | #define IPPROTO_TCP 6 | ||
| 95 | #define IPPROTO_EGP 8 | ||
| 96 | #define IPPROTO_PUP 12 | ||
| 97 | #define IPPROTO_UDP 17 | ||
| 98 | #define IPPROTO_IDP 22 | ||
| 99 | #define IPPROTO_TP 29 | ||
| 100 | #define IPPROTO_DCCP 33 | ||
| 101 | #define IPPROTO_IPV6 41 | ||
| 102 | #define IPPROTO_ROUTING 43 | ||
| 103 | #define IPPROTO_FRAGMENT 44 | ||
| 104 | #define IPPROTO_RSVP 46 | ||
| 105 | #define IPPROTO_GRE 47 | ||
| 106 | #define IPPROTO_ESP 50 | ||
| 107 | #define IPPROTO_AH 51 | ||
| 108 | #define IPPROTO_ICMPV6 58 | ||
| 109 | #define IPPROTO_NONE 59 | ||
| 110 | #define IPPROTO_DSTOPTS 60 | ||
| 111 | #define IPPROTO_MTP 92 | ||
| 112 | #define IPPROTO_BEETPH 94 | ||
| 113 | #define IPPROTO_ENCAP 98 | ||
| 114 | #define IPPROTO_PIM 103 | ||
| 115 | #define IPPROTO_COMP 108 | ||
| 116 | #define IPPROTO_SCTP 132 | ||
| 117 | #define IPPROTO_MH 135 | ||
| 118 | #define IPPROTO_UDPLITE 136 | ||
| 119 | #define IPPROTO_MPLS 137 | ||
| 120 | #define IPPROTO_ETHERNET 143 | ||
| 121 | #define IPPROTO_RAW 255 | ||
| 122 | #define IPPROTO_MPTCP 262 | ||
| 123 | #define IPPROTO_MAX 263 | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #define IN6_IS_ADDR_UNSPECIFIED(a) \ | ||
| 127 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 128 | ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) | ||
| 129 | |||
| 130 | #define IN6_IS_ADDR_LOOPBACK(a) \ | ||
| 131 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 132 | ((uint32_t *) (a))[2] == 0 && \ | ||
| 133 | ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ | ||
| 134 | ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) | ||
| 135 | |||
| 136 | #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) | ||
| 137 | |||
| 138 | #define IN6_IS_ADDR_LINKLOCAL(a) \ | ||
| 139 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) | ||
| 140 | |||
| 141 | #define IN6_IS_ADDR_SITELOCAL(a) \ | ||
| 142 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) | ||
| 143 | |||
| 144 | #define IN6_IS_ADDR_V4MAPPED(a) \ | ||
| 145 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 146 | ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ | ||
| 147 | ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) | ||
| 148 | |||
| 149 | #define IN6_IS_ADDR_V4COMPAT(a) \ | ||
| 150 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 151 | ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) | ||
| 152 | |||
| 153 | #define IN6_IS_ADDR_MC_NODELOCAL(a) \ | ||
| 154 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) | ||
| 155 | |||
| 156 | #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ | ||
| 157 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) | ||
| 158 | |||
| 159 | #define IN6_IS_ADDR_MC_SITELOCAL(a) \ | ||
| 160 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) | ||
| 161 | |||
| 162 | #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ | ||
| 163 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) | ||
| 164 | |||
| 165 | #define IN6_IS_ADDR_MC_GLOBAL(a) \ | ||
| 166 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) | ||
| 167 | |||
| 168 | #define __ARE_4_EQUAL(a,b) \ | ||
| 169 | 	(!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) | ||
| 170 | #define IN6_ARE_ADDR_EQUAL(a,b) \ | ||
| 171 | 	__ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) | ||
| 172 | |||
| 173 | #define	IN_CLASSA(a)		((((in_addr_t)(a)) & 0x80000000) == 0) | ||
| 174 | #define	IN_CLASSA_NET		0xff000000 | ||
| 175 | #define	IN_CLASSA_NSHIFT	24 | ||
| 176 | #define	IN_CLASSA_HOST		(0xffffffff & ~IN_CLASSA_NET) | ||
| 177 | #define	IN_CLASSA_MAX		128 | ||
| 178 | #define	IN_CLASSB(a)		((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) | ||
| 179 | #define	IN_CLASSB_NET		0xffff0000 | ||
| 180 | #define	IN_CLASSB_NSHIFT	16 | ||
| 181 | #define	IN_CLASSB_HOST		(0xffffffff & ~IN_CLASSB_NET) | ||
| 182 | #define	IN_CLASSB_MAX		65536 | ||
| 183 | #define	IN_CLASSC(a)		((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) | ||
| 184 | #define	IN_CLASSC_NET		0xffffff00 | ||
| 185 | #define	IN_CLASSC_NSHIFT	8 | ||
| 186 | #define	IN_CLASSC_HOST		(0xffffffff & ~IN_CLASSC_NET) | ||
| 187 | #define	IN_CLASSD(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) | ||
| 188 | #define	IN_MULTICAST(a)		IN_CLASSD(a) | ||
| 189 | #define	IN_EXPERIMENTAL(a)	((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) | ||
| 190 | #define	IN_BADCLASS(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) | ||
| 191 | |||
| 192 | #define IN_LOOPBACKNET 127 | ||
| 193 | |||
| 194 | |||
| 195 | #define IP_TOS 1 | ||
| 196 | #define IP_TTL 2 | ||
| 197 | #define IP_HDRINCL 3 | ||
| 198 | #define IP_OPTIONS 4 | ||
| 199 | #define IP_ROUTER_ALERT 5 | ||
| 200 | #define IP_RECVOPTS 6 | ||
| 201 | #define IP_RETOPTS 7 | ||
| 202 | #define IP_PKTINFO 8 | ||
| 203 | #define IP_PKTOPTIONS 9 | ||
| 204 | #define IP_PMTUDISC 10 | ||
| 205 | #define IP_MTU_DISCOVER 10 | ||
| 206 | #define IP_RECVERR 11 | ||
| 207 | #define IP_RECVTTL 12 | ||
| 208 | #define IP_RECVTOS 13 | ||
| 209 | #define IP_MTU 14 | ||
| 210 | #define IP_FREEBIND 15 | ||
| 211 | #define IP_IPSEC_POLICY 16 | ||
| 212 | #define IP_XFRM_POLICY 17 | ||
| 213 | #define IP_PASSSEC 18 | ||
| 214 | #define IP_TRANSPARENT 19 | ||
| 215 | #define IP_ORIGDSTADDR 20 | ||
| 216 | #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR | ||
| 217 | #define IP_MINTTL 21 | ||
| 218 | #define IP_NODEFRAG 22 | ||
| 219 | #define IP_CHECKSUM 23 | ||
| 220 | #define IP_BIND_ADDRESS_NO_PORT 24 | ||
| 221 | #define IP_RECVFRAGSIZE 25 | ||
| 222 | #define IP_RECVERR_RFC4884 26 | ||
| 223 | #define IP_MULTICAST_IF 32 | ||
| 224 | #define IP_MULTICAST_TTL 33 | ||
| 225 | #define IP_MULTICAST_LOOP 34 | ||
| 226 | #define IP_ADD_MEMBERSHIP 35 | ||
| 227 | #define IP_DROP_MEMBERSHIP 36 | ||
| 228 | #define IP_UNBLOCK_SOURCE 37 | ||
| 229 | #define IP_BLOCK_SOURCE 38 | ||
| 230 | #define IP_ADD_SOURCE_MEMBERSHIP 39 | ||
| 231 | #define IP_DROP_SOURCE_MEMBERSHIP 40 | ||
| 232 | #define IP_MSFILTER 41 | ||
| 233 | #define IP_MULTICAST_ALL 49 | ||
| 234 | #define IP_UNICAST_IF 50 | ||
| 235 | |||
| 236 | #define IP_RECVRETOPTS IP_RETOPTS | ||
| 237 | |||
| 238 | #define IP_PMTUDISC_DONT 0 | ||
| 239 | #define IP_PMTUDISC_WANT 1 | ||
| 240 | #define IP_PMTUDISC_DO 2 | ||
| 241 | #define IP_PMTUDISC_PROBE 3 | ||
| 242 | #define IP_PMTUDISC_INTERFACE 4 | ||
| 243 | #define IP_PMTUDISC_OMIT 5 | ||
| 244 | |||
| 245 | #define IP_DEFAULT_MULTICAST_TTL 1 | ||
| 246 | #define IP_DEFAULT_MULTICAST_LOOP 1 | ||
| 247 | #define IP_MAX_MEMBERSHIPS 20 | ||
| 248 | |||
| 249 | struct ip_opts { | ||
| 250 | 	struct in_addr ip_dst; | ||
| 251 | 	char ip_opts[40]; | ||
| 252 | }; | ||
| 253 | |||
| 254 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 255 | |||
| 256 | #define MCAST_JOIN_GROUP 42 | ||
| 257 | #define MCAST_BLOCK_SOURCE 43 | ||
| 258 | #define MCAST_UNBLOCK_SOURCE 44 | ||
| 259 | #define MCAST_LEAVE_GROUP 45 | ||
| 260 | #define MCAST_JOIN_SOURCE_GROUP 46 | ||
| 261 | #define MCAST_LEAVE_SOURCE_GROUP 47 | ||
| 262 | #define MCAST_MSFILTER 48 | ||
| 263 | |||
| 264 | #define MCAST_EXCLUDE 0 | ||
| 265 | #define MCAST_INCLUDE 1 | ||
| 266 | |||
| 267 | struct ip_mreq { | ||
| 268 | 	struct in_addr imr_multiaddr; | ||
| 269 | 	struct in_addr imr_interface; | ||
| 270 | }; | ||
| 271 | |||
| 272 | struct ip_mreqn { | ||
| 273 | 	struct in_addr imr_multiaddr; | ||
| 274 | 	struct in_addr imr_address; | ||
| 275 | 	int imr_ifindex; | ||
| 276 | }; | ||
| 277 | |||
| 278 | struct ip_mreq_source { | ||
| 279 | 	struct in_addr imr_multiaddr; | ||
| 280 | 	struct in_addr imr_interface; | ||
| 281 | 	struct in_addr imr_sourceaddr; | ||
| 282 | }; | ||
| 283 | |||
| 284 | struct ip_msfilter { | ||
| 285 | 	struct in_addr imsf_multiaddr; | ||
| 286 | 	struct in_addr imsf_interface; | ||
| 287 | 	uint32_t imsf_fmode; | ||
| 288 | 	uint32_t imsf_numsrc; | ||
| 289 | 	struct in_addr imsf_slist[1]; | ||
| 290 | }; | ||
| 291 | #define IP_MSFILTER_SIZE(numsrc) \ | ||
| 292 | 	(sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ | ||
| 293 | 	+ (numsrc) * sizeof(struct in_addr)) | ||
| 294 | |||
| 295 | struct group_req { | ||
| 296 | 	uint32_t gr_interface; | ||
| 297 | 	struct sockaddr_storage gr_group; | ||
| 298 | }; | ||
| 299 | |||
| 300 | struct group_source_req { | ||
| 301 | 	uint32_t gsr_interface; | ||
| 302 | 	struct sockaddr_storage gsr_group; | ||
| 303 | 	struct sockaddr_storage gsr_source; | ||
| 304 | }; | ||
| 305 | |||
| 306 | struct group_filter { | ||
| 307 | 	uint32_t gf_interface; | ||
| 308 | 	struct sockaddr_storage gf_group; | ||
| 309 | 	uint32_t gf_fmode; | ||
| 310 | 	uint32_t gf_numsrc; | ||
| 311 | 	struct sockaddr_storage gf_slist[1]; | ||
| 312 | }; | ||
| 313 | #define GROUP_FILTER_SIZE(numsrc) \ | ||
| 314 | 	(sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ | ||
| 315 | 	+ (numsrc) * sizeof(struct sockaddr_storage)) | ||
| 316 | |||
| 317 | struct in_pktinfo { | ||
| 318 | 	int ipi_ifindex; | ||
| 319 | 	struct in_addr ipi_spec_dst; | ||
| 320 | 	struct in_addr ipi_addr; | ||
| 321 | }; | ||
| 322 | |||
| 323 | struct in6_pktinfo { | ||
| 324 | 	struct in6_addr ipi6_addr; | ||
| 325 | 	unsigned ipi6_ifindex; | ||
| 326 | }; | ||
| 327 | |||
| 328 | struct ip6_mtuinfo { | ||
| 329 | 	struct sockaddr_in6 ip6m_addr; | ||
| 330 | 	uint32_t ip6m_mtu; | ||
| 331 | }; | ||
| 332 | #endif | ||
| 333 | |||
| 334 | #define IPV6_ADDRFORM 1 | ||
| 335 | #define IPV6_2292PKTINFO 2 | ||
| 336 | #define IPV6_2292HOPOPTS 3 | ||
| 337 | #define IPV6_2292DSTOPTS 4 | ||
| 338 | #define IPV6_2292RTHDR 5 | ||
| 339 | #define IPV6_2292PKTOPTIONS 6 | ||
| 340 | #define IPV6_CHECKSUM 7 | ||
| 341 | #define IPV6_2292HOPLIMIT 8 | ||
| 342 | #define IPV6_NEXTHOP 9 | ||
| 343 | #define IPV6_AUTHHDR 10 | ||
| 344 | #define IPV6_UNICAST_HOPS 16 | ||
| 345 | #define IPV6_MULTICAST_IF 17 | ||
| 346 | #define IPV6_MULTICAST_HOPS 18 | ||
| 347 | #define IPV6_MULTICAST_LOOP 19 | ||
| 348 | #define IPV6_JOIN_GROUP 20 | ||
| 349 | #define IPV6_LEAVE_GROUP 21 | ||
| 350 | #define IPV6_ROUTER_ALERT 22 | ||
| 351 | #define IPV6_MTU_DISCOVER 23 | ||
| 352 | #define IPV6_MTU 24 | ||
| 353 | #define IPV6_RECVERR 25 | ||
| 354 | #define IPV6_V6ONLY 26 | ||
| 355 | #define IPV6_JOIN_ANYCAST 27 | ||
| 356 | #define IPV6_LEAVE_ANYCAST 28 | ||
| 357 | #define IPV6_MULTICAST_ALL 29 | ||
| 358 | #define IPV6_ROUTER_ALERT_ISOLATE 30 | ||
| 359 | #define IPV6_IPSEC_POLICY 34 | ||
| 360 | #define IPV6_XFRM_POLICY 35 | ||
| 361 | #define IPV6_HDRINCL 36 | ||
| 362 | |||
| 363 | #define IPV6_RECVPKTINFO 49 | ||
| 364 | #define IPV6_PKTINFO 50 | ||
| 365 | #define IPV6_RECVHOPLIMIT 51 | ||
| 366 | #define IPV6_HOPLIMIT 52 | ||
| 367 | #define IPV6_RECVHOPOPTS 53 | ||
| 368 | #define IPV6_HOPOPTS 54 | ||
| 369 | #define IPV6_RTHDRDSTOPTS 55 | ||
| 370 | #define IPV6_RECVRTHDR 56 | ||
| 371 | #define IPV6_RTHDR 57 | ||
| 372 | #define IPV6_RECVDSTOPTS 58 | ||
| 373 | #define IPV6_DSTOPTS 59 | ||
| 374 | #define IPV6_RECVPATHMTU 60 | ||
| 375 | #define IPV6_PATHMTU 61 | ||
| 376 | #define IPV6_DONTFRAG 62 | ||
| 377 | #define IPV6_RECVTCLASS 66 | ||
| 378 | #define IPV6_TCLASS 67 | ||
| 379 | #define IPV6_AUTOFLOWLABEL 70 | ||
| 380 | #define IPV6_ADDR_PREFERENCES 72 | ||
| 381 | #define IPV6_MINHOPCOUNT 73 | ||
| 382 | #define IPV6_ORIGDSTADDR 74 | ||
| 383 | #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR | ||
| 384 | #define IPV6_TRANSPARENT 75 | ||
| 385 | #define IPV6_UNICAST_IF 76 | ||
| 386 | #define IPV6_RECVFRAGSIZE 77 | ||
| 387 | #define IPV6_FREEBIND 78 | ||
| 388 | |||
| 389 | #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP | ||
| 390 | #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP | ||
| 391 | #define IPV6_RXHOPOPTS IPV6_HOPOPTS | ||
| 392 | #define IPV6_RXDSTOPTS IPV6_DSTOPTS | ||
| 393 | |||
| 394 | #define IPV6_PMTUDISC_DONT 0 | ||
| 395 | #define IPV6_PMTUDISC_WANT 1 | ||
| 396 | #define IPV6_PMTUDISC_DO 2 | ||
| 397 | #define IPV6_PMTUDISC_PROBE 3 | ||
| 398 | #define IPV6_PMTUDISC_INTERFACE 4 | ||
| 399 | #define IPV6_PMTUDISC_OMIT 5 | ||
| 400 | |||
| 401 | #define IPV6_PREFER_SRC_TMP 0x0001 | ||
| 402 | #define IPV6_PREFER_SRC_PUBLIC 0x0002 | ||
| 403 | #define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 | ||
| 404 | #define IPV6_PREFER_SRC_COA 0x0004 | ||
| 405 | #define IPV6_PREFER_SRC_HOME 0x0400 | ||
| 406 | #define IPV6_PREFER_SRC_CGA 0x0008 | ||
| 407 | #define IPV6_PREFER_SRC_NONCGA 0x0800 | ||
| 408 | |||
| 409 | #define IPV6_RTHDR_LOOSE 0 | ||
| 410 | #define IPV6_RTHDR_STRICT 1 | ||
| 411 | |||
| 412 | #define IPV6_RTHDR_TYPE_0 0 | ||
| 413 | |||
| 414 | #define __UAPI_DEF_IN_ADDR 0 | ||
| 415 | #define __UAPI_DEF_IN_IPPROTO 0 | ||
| 416 | #define __UAPI_DEF_IN_PKTINFO 0 | ||
| 417 | #define __UAPI_DEF_IP_MREQ 0 | ||
| 418 | #define __UAPI_DEF_SOCKADDR_IN 0 | ||
| 419 | #define __UAPI_DEF_IN_CLASS 0 | ||
| 420 | #define __UAPI_DEF_IN6_ADDR 0 | ||
| 421 | #define __UAPI_DEF_IN6_ADDR_ALT 0 | ||
| 422 | #define __UAPI_DEF_SOCKADDR_IN6 0 | ||
| 423 | #define __UAPI_DEF_IPV6_MREQ 0 | ||
| 424 | #define __UAPI_DEF_IPPROTO_V6 0 | ||
| 425 | #define __UAPI_DEF_IPV6_OPTIONS 0 | ||
| 426 | #define __UAPI_DEF_IN6_PKTINFO 0 | ||
| 427 | #define __UAPI_DEF_IP6_MTUINFO 0 | ||
| 428 | |||
| 429 | #ifdef __cplusplus | ||
| 430 | } | ||
| 431 | #endif | ||
| 432 | |||
| 433 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/poll.h deleted-69| ... | @@ -1,69 +0,0 @@ | ||
| 1 | #ifndef	_POLL_H | ||
| 2 | #define	_POLL_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #include <bits/poll.h> | ||
| 11 | |||
| 12 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 13 | #define POLLIN 0x001 | ||
| 14 | #define POLLPRI 0x002 | ||
| 15 | #define POLLOUT 0x004 | ||
| 16 | #define POLLERR 0x008 | ||
| 17 | #define POLLHUP 0x010 | ||
| 18 | #define POLLNVAL 0x020 | ||
| 19 | #define POLLRDNORM 0x040 | ||
| 20 | #define POLLRDBAND 0x080 | ||
| 21 | #ifndef POLLWRNORM | ||
| 22 | #define POLLWRNORM 0x100 | ||
| 23 | #define POLLWRBAND 0x200 | ||
| 24 | #endif | ||
| 25 | #ifndef POLLMSG | ||
| 26 | #define POLLMSG 0x400 | ||
| 27 | #define POLLRDHUP 0x2000 | ||
| 28 | #endif | ||
| 29 | #else | ||
| 30 | #include <__header_poll.h> | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 34 | typedef unsigned long nfds_t; | ||
| 35 | #else | ||
| 36 | #include <__typedef_nfds_t.h> | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 40 | struct pollfd { | ||
| 41 | 	int fd; | ||
| 42 | 	short events; | ||
| 43 | 	short revents; | ||
| 44 | }; | ||
| 45 | #else | ||
| 46 | #include <__struct_pollfd.h> | ||
| 47 | #endif | ||
| 48 | |||
| 49 | int poll (struct pollfd *, nfds_t, int); | ||
| 50 | |||
| 51 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 52 | #define __NEED_time_t | ||
| 53 | #define __NEED_struct_timespec | ||
| 54 | #define __NEED_sigset_t | ||
| 55 | #include <bits/alltypes.h> | ||
| 56 | int ppoll(struct pollfd *, nfds_t, const struct timespec *, const sigset_t *); | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #if _REDIR_TIME64 | ||
| 60 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 61 | __REDIR(ppoll, __ppoll_time64); | ||
| 62 | #endif | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | } | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/pthread.h deleted-267| ... | @@ -1,267 +0,0 @@ | ||
| 1 | #ifndef _PTHREAD_H | ||
| 2 | #define _PTHREAD_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_time_t | ||
| 10 | #define __NEED_clockid_t | ||
| 11 | #define __NEED_struct_timespec | ||
| 12 | #define __NEED_sigset_t | ||
| 13 | #define __NEED_pthread_t | ||
| 14 | #define __NEED_pthread_attr_t | ||
| 15 | #define __NEED_pthread_mutexattr_t | ||
| 16 | #define __NEED_pthread_condattr_t | ||
| 17 | #define __NEED_pthread_rwlockattr_t | ||
| 18 | #define __NEED_pthread_barrierattr_t | ||
| 19 | #define __NEED_pthread_mutex_t | ||
| 20 | #define __NEED_pthread_cond_t | ||
| 21 | #define __NEED_pthread_rwlock_t | ||
| 22 | #define __NEED_pthread_barrier_t | ||
| 23 | #define __NEED_pthread_spinlock_t | ||
| 24 | #define __NEED_pthread_key_t | ||
| 25 | #define __NEED_pthread_once_t | ||
| 26 | #define __NEED_size_t | ||
| 27 | |||
| 28 | #include <bits/alltypes.h> | ||
| 29 | |||
| 30 | #include <sched.h> | ||
| 31 | #include <time.h> | ||
| 32 | |||
| 33 | #define PTHREAD_CREATE_JOINABLE 0 | ||
| 34 | #define PTHREAD_CREATE_DETACHED 1 | ||
| 35 | |||
| 36 | #define PTHREAD_MUTEX_NORMAL 0 | ||
| 37 | #define PTHREAD_MUTEX_DEFAULT 0 | ||
| 38 | #define PTHREAD_MUTEX_RECURSIVE 1 | ||
| 39 | #define PTHREAD_MUTEX_ERRORCHECK 2 | ||
| 40 | |||
| 41 | #define PTHREAD_MUTEX_STALLED 0 | ||
| 42 | #define PTHREAD_MUTEX_ROBUST 1 | ||
| 43 | |||
| 44 | #define PTHREAD_PRIO_NONE 0 | ||
| 45 | #define PTHREAD_PRIO_INHERIT 1 | ||
| 46 | #define PTHREAD_PRIO_PROTECT 2 | ||
| 47 | |||
| 48 | #define PTHREAD_INHERIT_SCHED 0 | ||
| 49 | #define PTHREAD_EXPLICIT_SCHED 1 | ||
| 50 | |||
| 51 | #define PTHREAD_SCOPE_SYSTEM 0 | ||
| 52 | #define PTHREAD_SCOPE_PROCESS 1 | ||
| 53 | |||
| 54 | #define PTHREAD_PROCESS_PRIVATE 0 | ||
| 55 | #define PTHREAD_PROCESS_SHARED 1 | ||
| 56 | |||
| 57 | |||
| 58 | #define PTHREAD_MUTEX_INITIALIZER {{{0}}} | ||
| 59 | #define PTHREAD_RWLOCK_INITIALIZER {{{0}}} | ||
| 60 | #define PTHREAD_COND_INITIALIZER {{{0}}} | ||
| 61 | #define PTHREAD_ONCE_INIT 0 | ||
| 62 | |||
| 63 | |||
| 64 | #define PTHREAD_CANCEL_ENABLE 0 | ||
| 65 | #define PTHREAD_CANCEL_DISABLE 1 | ||
| 66 | #define PTHREAD_CANCEL_MASKED 2 | ||
| 67 | |||
| 68 | #define PTHREAD_CANCEL_DEFERRED 0 | ||
| 69 | #define PTHREAD_CANCEL_ASYNCHRONOUS 1 | ||
| 70 | |||
| 71 | #define PTHREAD_CANCELED ((void *)-1) | ||
| 72 | |||
| 73 | |||
| 74 | #define PTHREAD_BARRIER_SERIAL_THREAD (-1) | ||
| 75 | |||
| 76 | |||
| 77 | #define PTHREAD_NULL ((pthread_t)0) | ||
| 78 | |||
| 79 | |||
| 80 | #ifdef __wasilibc_unmodified_upstream | ||
| 81 | int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); | ||
| 82 | int pthread_detach(pthread_t); | ||
| 83 | _Noreturn void pthread_exit(void *); | ||
| 84 | int pthread_join(pthread_t, void **); | ||
| 85 | #else | ||
| 86 | #if defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 87 | int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); | ||
| 88 | int pthread_detach(pthread_t); | ||
| 89 | int pthread_join(pthread_t, void **); | ||
| 90 | #else | ||
| 91 | #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;}) | ||
| 92 | #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;}) | ||
| 93 | #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;}) | ||
| 94 | #endif | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #ifdef __GNUC__ | ||
| 98 | __attribute__((const)) | ||
| 99 | #endif | ||
| 100 | pthread_t pthread_self(void); | ||
| 101 | |||
| 102 | int pthread_equal(pthread_t, pthread_t); | ||
| 103 | #ifndef __cplusplus | ||
| 104 | #define pthread_equal(x,y) ((x)==(y)) | ||
| 105 | #endif | ||
| 106 | |||
| 107 | int pthread_setcancelstate(int, int *); | ||
| 108 | int pthread_setcanceltype(int, int *); | ||
| 109 | void pthread_testcancel(void); | ||
| 110 | #ifdef __wasilibc_unmodified_upstream /* WASI has no cancellation support. */ | ||
| 111 | int pthread_cancel(pthread_t); | ||
| 112 | #endif | ||
| 113 | |||
| 114 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 115 | int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict); | ||
| 116 | int pthread_setschedparam(pthread_t, int, const struct sched_param *); | ||
| 117 | #endif | ||
| 118 | int pthread_setschedprio(pthread_t, int); | ||
| 119 | |||
| 120 | int pthread_once(pthread_once_t *, void (*)(void)); | ||
| 121 | |||
| 122 | int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict); | ||
| 123 | int pthread_mutex_lock(pthread_mutex_t *); | ||
| 124 | int pthread_mutex_unlock(pthread_mutex_t *); | ||
| 125 | int pthread_mutex_trylock(pthread_mutex_t *); | ||
| 126 | int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict); | ||
| 127 | int pthread_mutex_destroy(pthread_mutex_t *); | ||
| 128 | int pthread_mutex_consistent(pthread_mutex_t *); | ||
| 129 | |||
| 130 | int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict); | ||
| 131 | int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict); | ||
| 132 | |||
| 133 | int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict); | ||
| 134 | int pthread_cond_destroy(pthread_cond_t *); | ||
| 135 | int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict); | ||
| 136 | int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict); | ||
| 137 | int pthread_cond_broadcast(pthread_cond_t *); | ||
| 138 | int pthread_cond_signal(pthread_cond_t *); | ||
| 139 | |||
| 140 | int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict); | ||
| 141 | int pthread_rwlock_destroy(pthread_rwlock_t *); | ||
| 142 | int pthread_rwlock_rdlock(pthread_rwlock_t *); | ||
| 143 | int pthread_rwlock_tryrdlock(pthread_rwlock_t *); | ||
| 144 | int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 145 | int pthread_rwlock_wrlock(pthread_rwlock_t *); | ||
| 146 | int pthread_rwlock_trywrlock(pthread_rwlock_t *); | ||
| 147 | int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 148 | int pthread_rwlock_unlock(pthread_rwlock_t *); | ||
| 149 | |||
| 150 | int pthread_spin_init(pthread_spinlock_t *, int); | ||
| 151 | int pthread_spin_destroy(pthread_spinlock_t *); | ||
| 152 | int pthread_spin_lock(pthread_spinlock_t *); | ||
| 153 | int pthread_spin_trylock(pthread_spinlock_t *); | ||
| 154 | int pthread_spin_unlock(pthread_spinlock_t *); | ||
| 155 | |||
| 156 | int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned); | ||
| 157 | int pthread_barrier_destroy(pthread_barrier_t *); | ||
| 158 | int pthread_barrier_wait(pthread_barrier_t *); | ||
| 159 | |||
| 160 | int pthread_key_create(pthread_key_t *, void (*)(void *)); | ||
| 161 | int pthread_key_delete(pthread_key_t); | ||
| 162 | void *pthread_getspecific(pthread_key_t); | ||
| 163 | int pthread_setspecific(pthread_key_t, const void *); | ||
| 164 | |||
| 165 | int pthread_attr_init(pthread_attr_t *); | ||
| 166 | int pthread_attr_destroy(pthread_attr_t *); | ||
| 167 | |||
| 168 | int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict); | ||
| 169 | int pthread_attr_setguardsize(pthread_attr_t *, size_t); | ||
| 170 | int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict); | ||
| 171 | int pthread_attr_setstacksize(pthread_attr_t *, size_t); | ||
| 172 | int pthread_attr_getdetachstate(const pthread_attr_t *, int *); | ||
| 173 | int pthread_attr_setdetachstate(pthread_attr_t *, int); | ||
| 174 | int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict); | ||
| 175 | int pthread_attr_setstack(pthread_attr_t *, void *, size_t); | ||
| 176 | int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict); | ||
| 177 | int pthread_attr_setscope(pthread_attr_t *, int); | ||
| 178 | int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict); | ||
| 179 | int pthread_attr_setschedpolicy(pthread_attr_t *, int); | ||
| 180 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 181 | int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict); | ||
| 182 | int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict); | ||
| 183 | #endif | ||
| 184 | int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict); | ||
| 185 | int pthread_attr_setinheritsched(pthread_attr_t *, int); | ||
| 186 | |||
| 187 | int pthread_mutexattr_destroy(pthread_mutexattr_t *); | ||
| 188 | int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 189 | int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 190 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 191 | int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 192 | int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 193 | int pthread_mutexattr_init(pthread_mutexattr_t *); | ||
| 194 | int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); | ||
| 195 | int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); | ||
| 196 | int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); | ||
| 197 | int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); | ||
| 198 | int pthread_mutexattr_settype(pthread_mutexattr_t *, int); | ||
| 199 | |||
| 200 | int pthread_condattr_init(pthread_condattr_t *); | ||
| 201 | int pthread_condattr_destroy(pthread_condattr_t *); | ||
| 202 | int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); | ||
| 203 | int pthread_condattr_setpshared(pthread_condattr_t *, int); | ||
| 204 | int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict); | ||
| 205 | int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict); | ||
| 206 | |||
| 207 | int pthread_rwlockattr_init(pthread_rwlockattr_t *); | ||
| 208 | int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); | ||
| 209 | int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); | ||
| 210 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict); | ||
| 211 | |||
| 212 | int pthread_barrierattr_destroy(pthread_barrierattr_t *); | ||
| 213 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict); | ||
| 214 | int pthread_barrierattr_init(pthread_barrierattr_t *); | ||
| 215 | int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); | ||
| 216 | |||
| 217 | int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); | ||
| 218 | |||
| 219 | int pthread_getconcurrency(void); | ||
| 220 | int pthread_setconcurrency(int); | ||
| 221 | |||
| 222 | int pthread_getcpuclockid(pthread_t, clockid_t *); | ||
| 223 | |||
| 224 | struct __ptcb { | ||
| 225 | 	void (*__f)(void *); | ||
| 226 | 	void *__x; | ||
| 227 | 	struct __ptcb *__next; | ||
| 228 | }; | ||
| 229 | |||
| 230 | void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *); | ||
| 231 | void _pthread_cleanup_pop(struct __ptcb *, int); | ||
| 232 | |||
| 233 | #define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); | ||
| 234 | #define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) | ||
| 235 | |||
| 236 | #ifdef _GNU_SOURCE | ||
| 237 | struct cpu_set_t; | ||
| 238 | int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); | ||
| 239 | int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); | ||
| 240 | int pthread_getattr_np(pthread_t, pthread_attr_t *); | ||
| 241 | int pthread_setname_np(pthread_t, const char *); | ||
| 242 | int pthread_getname_np(pthread_t, char *, size_t); | ||
| 243 | int pthread_getattr_default_np(pthread_attr_t *); | ||
| 244 | int pthread_setattr_default_np(const pthread_attr_t *); | ||
| 245 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 246 | int pthread_tryjoin_np(pthread_t, void **); | ||
| 247 | int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); | ||
| 248 | #else | ||
| 249 | #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;}) | ||
| 250 | #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;}) | ||
| 251 | #endif | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #if _REDIR_TIME64 | ||
| 255 | __REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64); | ||
| 256 | __REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64); | ||
| 257 | __REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64); | ||
| 258 | __REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64); | ||
| 259 | #ifdef _GNU_SOURCE | ||
| 260 | __REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64); | ||
| 261 | #endif | ||
| 262 | #endif | ||
| 263 | |||
| 264 | #ifdef __cplusplus | ||
| 265 | } | ||
| 266 | #endif | ||
| 267 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sched.h deleted-152| ... | @@ -1,152 +0,0 @@ | ||
| 1 | #ifndef _SCHED_H | ||
| 2 | #define _SCHED_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_struct_timespec | ||
| 10 | #define __NEED_pid_t | ||
| 11 | #define __NEED_time_t | ||
| 12 | |||
| 13 | #ifdef _GNU_SOURCE | ||
| 14 | #define __NEED_size_t | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #include <bits/alltypes.h> | ||
| 18 | |||
| 19 | struct sched_param { | ||
| 20 | 	int sched_priority; | ||
| 21 | 	int __reserved1; | ||
| 22 | #if _REDIR_TIME64 | ||
| 23 | 	long __reserved2[4]; | ||
| 24 | #else | ||
| 25 | 	struct { | ||
| 26 | 		time_t __reserved1; | ||
| 27 | 		long __reserved2; | ||
| 28 | 	} __reserved2[2]; | ||
| 29 | #endif | ||
| 30 | 	int __reserved3; | ||
| 31 | }; | ||
| 32 | |||
| 33 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 34 | int sched_get_priority_max(int); | ||
| 35 | int sched_get_priority_min(int); | ||
| 36 | int sched_getparam(pid_t, struct sched_param *); | ||
| 37 | int sched_getscheduler(pid_t); | ||
| 38 | int sched_rr_get_interval(pid_t, struct timespec *); | ||
| 39 | int sched_setparam(pid_t, const struct sched_param *); | ||
| 40 | int sched_setscheduler(pid_t, int, const struct sched_param *); | ||
| 41 | #endif | ||
| 42 | int sched_yield(void); | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 45 | #define SCHED_OTHER 0 | ||
| 46 | #define SCHED_FIFO 1 | ||
| 47 | #define SCHED_RR 2 | ||
| 48 | #define SCHED_BATCH 3 | ||
| 49 | #define SCHED_IDLE 5 | ||
| 50 | #define SCHED_DEADLINE 6 | ||
| 51 | #define SCHED_RESET_ON_FORK 0x40000000 | ||
| 52 | |||
| 53 | #ifdef _GNU_SOURCE | ||
| 54 | #define CSIGNAL		0x000000ff | ||
| 55 | #define CLONE_NEWTIME	0x00000080 | ||
| 56 | #define CLONE_VM	0x00000100 | ||
| 57 | #define CLONE_FS	0x00000200 | ||
| 58 | #define CLONE_FILES	0x00000400 | ||
| 59 | #define CLONE_SIGHAND	0x00000800 | ||
| 60 | #define CLONE_PIDFD	0x00001000 | ||
| 61 | #define CLONE_PTRACE	0x00002000 | ||
| 62 | #define CLONE_VFORK	0x00004000 | ||
| 63 | #define CLONE_PARENT	0x00008000 | ||
| 64 | #define CLONE_THREAD	0x00010000 | ||
| 65 | #define CLONE_NEWNS	0x00020000 | ||
| 66 | #define CLONE_SYSVSEM	0x00040000 | ||
| 67 | #define CLONE_SETTLS	0x00080000 | ||
| 68 | #define CLONE_PARENT_SETTID	0x00100000 | ||
| 69 | #define CLONE_CHILD_CLEARTID	0x00200000 | ||
| 70 | #define CLONE_DETACHED	0x00400000 | ||
| 71 | #define CLONE_UNTRACED	0x00800000 | ||
| 72 | #define CLONE_CHILD_SETTID	0x01000000 | ||
| 73 | #define CLONE_NEWCGROUP	0x02000000 | ||
| 74 | #define CLONE_NEWUTS	0x04000000 | ||
| 75 | #define CLONE_NEWIPC	0x08000000 | ||
| 76 | #define CLONE_NEWUSER	0x10000000 | ||
| 77 | #define CLONE_NEWPID	0x20000000 | ||
| 78 | #define CLONE_NEWNET	0x40000000 | ||
| 79 | #define CLONE_IO	0x80000000 | ||
| 80 | int clone (int (*)(void *), void *, int, void *, ...); | ||
| 81 | int unshare(int); | ||
| 82 | int setns(int, int); | ||
| 83 | |||
| 84 | void *memcpy(void *__restrict, const void *__restrict, size_t); | ||
| 85 | int memcmp(const void *, const void *, size_t); | ||
| 86 | void *memset (void *, int, size_t); | ||
| 87 | void *calloc(size_t, size_t); | ||
| 88 | void free(void *); | ||
| 89 | |||
| 90 | typedef struct cpu_set_t { unsigned long __bits[128/sizeof(long)]; } cpu_set_t; | ||
| 91 | int __sched_cpucount(size_t, const cpu_set_t *); | ||
| 92 | int sched_getcpu(void); | ||
| 93 | int sched_getaffinity(pid_t, size_t, cpu_set_t *); | ||
| 94 | int sched_setaffinity(pid_t, size_t, const cpu_set_t *); | ||
| 95 | |||
| 96 | #define __CPU_op_S(i, size, set, op) ( (i)/8U >= (size) ? 0 : \ | ||
| 97 | 	(((unsigned long *)(set))[(i)/8/sizeof(long)] op (1UL<<((i)%(8*sizeof(long))))) ) | ||
| 98 | |||
| 99 | #define CPU_SET_S(i, size, set) __CPU_op_S(i, size, set, |=) | ||
| 100 | #define CPU_CLR_S(i, size, set) __CPU_op_S(i, size, set, &=~) | ||
| 101 | #define CPU_ISSET_S(i, size, set) __CPU_op_S(i, size, set, &) | ||
| 102 | |||
| 103 | #define __CPU_op_func_S(func, op) \ | ||
| 104 | static __inline void __CPU_##func##_S(size_t __size, cpu_set_t *__dest, \ | ||
| 105 | 	const cpu_set_t *__src1, const cpu_set_t *__src2) \ | ||
| 106 | { \ | ||
| 107 | 	size_t __i; \ | ||
| 108 | 	for (__i=0; __i<__size/sizeof(long); __i++) \ | ||
| 109 | 		((unsigned long *)__dest)[__i] = ((unsigned long *)__src1)[__i] \ | ||
| 110 | 			op ((unsigned long *)__src2)[__i] ; \ | ||
| 111 | } | ||
| 112 | |||
| 113 | __CPU_op_func_S(AND, &) | ||
| 114 | __CPU_op_func_S(OR, |) | ||
| 115 | __CPU_op_func_S(XOR, ^) | ||
| 116 | |||
| 117 | #define CPU_AND_S(a,b,c,d) __CPU_AND_S(a,b,c,d) | ||
| 118 | #define CPU_OR_S(a,b,c,d) __CPU_OR_S(a,b,c,d) | ||
| 119 | #define CPU_XOR_S(a,b,c,d) __CPU_XOR_S(a,b,c,d) | ||
| 120 | |||
| 121 | #define CPU_COUNT_S(size,set) __sched_cpucount(size,set) | ||
| 122 | #define CPU_ZERO_S(size,set) memset(set,0,size) | ||
| 123 | #define CPU_EQUAL_S(size,set1,set2) (!memcmp(set1,set2,size)) | ||
| 124 | |||
| 125 | #define CPU_ALLOC_SIZE(n) (sizeof(long) * ( (n)/(8*sizeof(long)) \ | ||
| 126 | 	+ ((n)%(8*sizeof(long)) + 8*sizeof(long)-1)/(8*sizeof(long)) ) ) | ||
| 127 | #define CPU_ALLOC(n) ((cpu_set_t *)calloc(1,CPU_ALLOC_SIZE(n))) | ||
| 128 | #define CPU_FREE(set) free(set) | ||
| 129 | |||
| 130 | #define CPU_SETSIZE 1024 | ||
| 131 | |||
| 132 | #define CPU_SET(i, set) CPU_SET_S(i,sizeof(cpu_set_t),set) | ||
| 133 | #define CPU_CLR(i, set) CPU_CLR_S(i,sizeof(cpu_set_t),set) | ||
| 134 | #define CPU_ISSET(i, set) CPU_ISSET_S(i,sizeof(cpu_set_t),set) | ||
| 135 | #define CPU_AND(d,s1,s2) CPU_AND_S(sizeof(cpu_set_t),d,s1,s2) | ||
| 136 | #define CPU_OR(d,s1,s2) CPU_OR_S(sizeof(cpu_set_t),d,s1,s2) | ||
| 137 | #define CPU_XOR(d,s1,s2) CPU_XOR_S(sizeof(cpu_set_t),d,s1,s2) | ||
| 138 | #define CPU_COUNT(set) CPU_COUNT_S(sizeof(cpu_set_t),set) | ||
| 139 | #define CPU_ZERO(set) CPU_ZERO_S(sizeof(cpu_set_t),set) | ||
| 140 | #define CPU_EQUAL(s1,s2) CPU_EQUAL_S(sizeof(cpu_set_t),s1,s2) | ||
| 141 | |||
| 142 | #endif | ||
| 143 | #endif | ||
| 144 | |||
| 145 | #if _REDIR_TIME64 | ||
| 146 | __REDIR(sched_rr_get_interval, __sched_rr_get_interval_time64); | ||
| 147 | #endif | ||
| 148 | |||
| 149 | #ifdef __cplusplus | ||
| 150 | } | ||
| 151 | #endif | ||
| 152 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/setjmp.h deleted-55| ... | @@ -1,55 +0,0 @@ | ||
| 1 | #ifndef	_SETJMP_H | ||
| 2 | #define	_SETJMP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifndef __wasilibc_unmodified_upstream | ||
| 11 | /* WASI has no setjmp */ | ||
| 12 | #if !defined(__wasm_exception_handling__) | ||
| 13 | #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. | ||
| 14 | #endif | ||
| 15 | #endif | ||
| 16 | #include <bits/setjmp.h> | ||
| 17 | |||
| 18 | typedef struct __jmp_buf_tag { | ||
| 19 | 	__jmp_buf __jb; | ||
| 20 | 	unsigned long __fl; | ||
| 21 | 	unsigned long __ss[128/sizeof(long)]; | ||
| 22 | } jmp_buf[1]; | ||
| 23 | |||
| 24 | #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) | ||
| 25 | #define __setjmp_attr __attribute__((__returns_twice__)) | ||
| 26 | #else | ||
| 27 | #define __setjmp_attr | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 31 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 32 | || defined(_BSD_SOURCE) | ||
| 33 | typedef jmp_buf sigjmp_buf; | ||
| 34 | int sigsetjmp (sigjmp_buf, int) __setjmp_attr; | ||
| 35 | _Noreturn void siglongjmp (sigjmp_buf, int); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 39 | || defined(_BSD_SOURCE) | ||
| 40 | int _setjmp (jmp_buf) __setjmp_attr; | ||
| 41 | _Noreturn void _longjmp (jmp_buf, int); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | int setjmp (jmp_buf) __setjmp_attr; | ||
| 45 | _Noreturn void longjmp (jmp_buf, int); | ||
| 46 | |||
| 47 | #define setjmp setjmp | ||
| 48 | |||
| 49 | #undef __setjmp_attr | ||
| 50 | |||
| 51 | #ifdef __cplusplus | ||
| 52 | } | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/signal.h deleted-339| ... | @@ -1,339 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_SIGNAL | ||
| 2 | #error "wasm lacks signal support; to enable minimal signal emulation, \ | ||
| 3 | compile with -D_WASI_EMULATED_SIGNAL and link with -lwasi-emulated-signal" | ||
| 4 | #else | ||
| 5 | #ifndef _SIGNAL_H | ||
| 6 | #define _SIGNAL_H | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 15 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 16 | || defined(_BSD_SOURCE) | ||
| 17 | |||
| 18 | #ifdef __wasilibc_unmodified_upstream /* WASI has no ucontext support */ | ||
| 19 | #ifdef _GNU_SOURCE | ||
| 20 | #define __ucontext ucontext | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #define __NEED_size_t | ||
| 24 | #define __NEED_pid_t | ||
| 25 | #define __NEED_uid_t | ||
| 26 | #define __NEED_struct_timespec | ||
| 27 | #define __NEED_pthread_t | ||
| 28 | #define __NEED_pthread_attr_t | ||
| 29 | #define __NEED_time_t | ||
| 30 | #define __NEED_clock_t | ||
| 31 | #define __NEED_sigset_t | ||
| 32 | |||
| 33 | #include <bits/alltypes.h> | ||
| 34 | |||
| 35 | #define SIG_BLOCK 0 | ||
| 36 | #define SIG_UNBLOCK 1 | ||
| 37 | #define SIG_SETMASK 2 | ||
| 38 | |||
| 39 | #define SI_ASYNCNL (-60) | ||
| 40 | #define SI_TKILL (-6) | ||
| 41 | #define SI_SIGIO (-5) | ||
| 42 | #define SI_ASYNCIO (-4) | ||
| 43 | #define SI_MESGQ (-3) | ||
| 44 | #define SI_TIMER (-2) | ||
| 45 | #define SI_QUEUE (-1) | ||
| 46 | #define SI_USER 0 | ||
| 47 | #define SI_KERNEL 128 | ||
| 48 | |||
| 49 | typedef struct sigaltstack stack_t; | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #endif | ||
| 53 | |||
| 54 | #include <bits/signal.h> | ||
| 55 | |||
| 56 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 57 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 58 | || defined(_BSD_SOURCE) | ||
| 59 | |||
| 60 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ | ||
| 61 | #define SIG_HOLD ((void (*)(int)) 2) | ||
| 62 | |||
| 63 | #define FPE_INTDIV 1 | ||
| 64 | #define FPE_INTOVF 2 | ||
| 65 | #define FPE_FLTDIV 3 | ||
| 66 | #define FPE_FLTOVF 4 | ||
| 67 | #define FPE_FLTUND 5 | ||
| 68 | #define FPE_FLTRES 6 | ||
| 69 | #define FPE_FLTINV 7 | ||
| 70 | #define FPE_FLTSUB 8 | ||
| 71 | |||
| 72 | #define ILL_ILLOPC 1 | ||
| 73 | #define ILL_ILLOPN 2 | ||
| 74 | #define ILL_ILLADR 3 | ||
| 75 | #define ILL_ILLTRP 4 | ||
| 76 | #define ILL_PRVOPC 5 | ||
| 77 | #define ILL_PRVREG 6 | ||
| 78 | #define ILL_COPROC 7 | ||
| 79 | #define ILL_BADSTK 8 | ||
| 80 | |||
| 81 | #define SEGV_MAPERR 1 | ||
| 82 | #define SEGV_ACCERR 2 | ||
| 83 | #define SEGV_BNDERR 3 | ||
| 84 | #define SEGV_PKUERR 4 | ||
| 85 | #define SEGV_MTEAERR 8 | ||
| 86 | #define SEGV_MTESERR 9 | ||
| 87 | |||
| 88 | #define BUS_ADRALN 1 | ||
| 89 | #define BUS_ADRERR 2 | ||
| 90 | #define BUS_OBJERR 3 | ||
| 91 | #define BUS_MCEERR_AR 4 | ||
| 92 | #define BUS_MCEERR_AO 5 | ||
| 93 | |||
| 94 | #define CLD_EXITED 1 | ||
| 95 | #define CLD_KILLED 2 | ||
| 96 | #define CLD_DUMPED 3 | ||
| 97 | #define CLD_TRAPPED 4 | ||
| 98 | #define CLD_STOPPED 5 | ||
| 99 | #define CLD_CONTINUED 6 | ||
| 100 | |||
| 101 | union sigval { | ||
| 102 | 	int sival_int; | ||
| 103 | 	void *sival_ptr; | ||
| 104 | }; | ||
| 105 | |||
| 106 | typedef struct { | ||
| 107 | #ifdef __SI_SWAP_ERRNO_CODE | ||
| 108 | 	int si_signo, si_code, si_errno; | ||
| 109 | #else | ||
| 110 | 	int si_signo, si_errno, si_code; | ||
| 111 | #endif | ||
| 112 | 	union { | ||
| 113 | 		char __pad[128 - 2*sizeof(int) - sizeof(long)]; | ||
| 114 | 		struct { | ||
| 115 | 			union { | ||
| 116 | 				struct { | ||
| 117 | 					pid_t si_pid; | ||
| 118 | 					uid_t si_uid; | ||
| 119 | 				} __piduid; | ||
| 120 | 				struct { | ||
| 121 | 					int si_timerid; | ||
| 122 | 					int si_overrun; | ||
| 123 | 				} __timer; | ||
| 124 | 			} __first; | ||
| 125 | 			union { | ||
| 126 | 				union sigval si_value; | ||
| 127 | 				struct { | ||
| 128 | 					int si_status; | ||
| 129 | 					clock_t si_utime, si_stime; | ||
| 130 | 				} __sigchld; | ||
| 131 | 			} __second; | ||
| 132 | 		} __si_common; | ||
| 133 | 		struct { | ||
| 134 | 			void *si_addr; | ||
| 135 | 			short si_addr_lsb; | ||
| 136 | 			union { | ||
| 137 | 				struct { | ||
| 138 | 					void *si_lower; | ||
| 139 | 					void *si_upper; | ||
| 140 | 				} __addr_bnd; | ||
| 141 | 				unsigned si_pkey; | ||
| 142 | 			} __first; | ||
| 143 | 		} __sigfault; | ||
| 144 | 		struct { | ||
| 145 | 			long si_band; | ||
| 146 | 			int si_fd; | ||
| 147 | 		} __sigpoll; | ||
| 148 | 		struct { | ||
| 149 | 			void *si_call_addr; | ||
| 150 | 			int si_syscall; | ||
| 151 | 			unsigned si_arch; | ||
| 152 | 		} __sigsys; | ||
| 153 | 	} __si_fields; | ||
| 154 | } siginfo_t; | ||
| 155 | #define si_pid __si_fields.__si_common.__first.__piduid.si_pid | ||
| 156 | #define si_uid __si_fields.__si_common.__first.__piduid.si_uid | ||
| 157 | #define si_status __si_fields.__si_common.__second.__sigchld.si_status | ||
| 158 | #define si_utime __si_fields.__si_common.__second.__sigchld.si_utime | ||
| 159 | #define si_stime __si_fields.__si_common.__second.__sigchld.si_stime | ||
| 160 | #define si_value __si_fields.__si_common.__second.si_value | ||
| 161 | #define si_addr __si_fields.__sigfault.si_addr | ||
| 162 | #define si_addr_lsb __si_fields.__sigfault.si_addr_lsb | ||
| 163 | #define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower | ||
| 164 | #define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper | ||
| 165 | #define si_pkey __si_fields.__sigfault.__first.si_pkey | ||
| 166 | #define si_band __si_fields.__sigpoll.si_band | ||
| 167 | #define si_fd __si_fields.__sigpoll.si_fd | ||
| 168 | #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid | ||
| 169 | #define si_overrun __si_fields.__si_common.__first.__timer.si_overrun | ||
| 170 | #define si_ptr si_value.sival_ptr | ||
| 171 | #define si_int si_value.sival_int | ||
| 172 | #define si_call_addr __si_fields.__sigsys.si_call_addr | ||
| 173 | #define si_syscall __si_fields.__sigsys.si_syscall | ||
| 174 | #define si_arch __si_fields.__sigsys.si_arch | ||
| 175 | |||
| 176 | struct sigaction { | ||
| 177 | 	union { | ||
| 178 | 		void (*sa_handler)(int); | ||
| 179 | 		void (*sa_sigaction)(int, siginfo_t *, void *); | ||
| 180 | 	} __sa_handler; | ||
| 181 | 	sigset_t sa_mask; | ||
| 182 | 	int sa_flags; | ||
| 183 | 	void (*sa_restorer)(void); | ||
| 184 | }; | ||
| 185 | #define sa_handler __sa_handler.sa_handler | ||
| 186 | #define sa_sigaction __sa_handler.sa_sigaction | ||
| 187 | |||
| 188 | #define SA_UNSUPPORTED 0x00000400 | ||
| 189 | #define SA_EXPOSE_TAGBITS 0x00000800 | ||
| 190 | |||
| 191 | struct sigevent { | ||
| 192 | 	union sigval sigev_value; | ||
| 193 | 	int sigev_signo; | ||
| 194 | 	int sigev_notify; | ||
| 195 | 	union { | ||
| 196 | 		char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; | ||
| 197 | 		pid_t sigev_notify_thread_id; | ||
| 198 | 		struct { | ||
| 199 | 			void (*sigev_notify_function)(union sigval); | ||
| 200 | 			pthread_attr_t *sigev_notify_attributes; | ||
| 201 | 		} __sev_thread; | ||
| 202 | 	} __sev_fields; | ||
| 203 | }; | ||
| 204 | |||
| 205 | #define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id | ||
| 206 | #define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function | ||
| 207 | #define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes | ||
| 208 | |||
| 209 | #define SIGEV_SIGNAL 0 | ||
| 210 | #define SIGEV_NONE 1 | ||
| 211 | #define SIGEV_THREAD 2 | ||
| 212 | #define SIGEV_THREAD_ID 4 | ||
| 213 | #endif | ||
| 214 | |||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ | ||
| 216 | int __libc_current_sigrtmin(void); | ||
| 217 | int __libc_current_sigrtmax(void); | ||
| 218 | |||
| 219 | #define SIGRTMIN (__libc_current_sigrtmin()) | ||
| 220 | #define SIGRTMAX (__libc_current_sigrtmax()) | ||
| 221 | #endif | ||
| 222 | |||
| 223 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 224 | int kill(pid_t, int); | ||
| 225 | |||
| 226 | int sigemptyset(sigset_t *); | ||
| 227 | int sigfillset(sigset_t *); | ||
| 228 | int sigaddset(sigset_t *, int); | ||
| 229 | int sigdelset(sigset_t *, int); | ||
| 230 | int sigismember(const sigset_t *, int); | ||
| 231 | |||
| 232 | int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 233 | int sigsuspend(const sigset_t *); | ||
| 234 | int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); | ||
| 235 | int sigpending(sigset_t *); | ||
| 236 | int sigwait(const sigset_t *__restrict, int *__restrict); | ||
| 237 | int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); | ||
| 238 | int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); | ||
| 239 | int sigqueue(pid_t, int, union sigval); | ||
| 240 | #endif | ||
| 241 | |||
| 242 | #ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ | ||
| 243 | int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 244 | int pthread_kill(pthread_t, int); | ||
| 245 | #endif | ||
| 246 | |||
| 247 | #ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ | ||
| 248 | void psiginfo(const siginfo_t *, const char *); | ||
| 249 | #endif | ||
| 250 | void psignal(int, const char *); | ||
| 251 | |||
| 252 | #endif | ||
| 253 | |||
| 254 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 255 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 256 | int killpg(pid_t, int); | ||
| 257 | int sigaltstack(const stack_t *__restrict, stack_t *__restrict); | ||
| 258 | int sighold(int); | ||
| 259 | int sigignore(int); | ||
| 260 | int siginterrupt(int, int); | ||
| 261 | int sigpause(int); | ||
| 262 | int sigrelse(int); | ||
| 263 | void (*sigset(int, void (*)(int)))(int); | ||
| 264 | #define TRAP_BRKPT 1 | ||
| 265 | #define TRAP_TRACE 2 | ||
| 266 | #define TRAP_BRANCH 3 | ||
| 267 | #define TRAP_HWBKPT 4 | ||
| 268 | #define TRAP_UNK 5 | ||
| 269 | #define POLL_IN 1 | ||
| 270 | #define POLL_OUT 2 | ||
| 271 | #define POLL_MSG 3 | ||
| 272 | #define POLL_ERR 4 | ||
| 273 | #define POLL_PRI 5 | ||
| 274 | #define POLL_HUP 6 | ||
| 275 | #define SS_ONSTACK 1 | ||
| 276 | #define SS_DISABLE 2 | ||
| 277 | #define SS_AUTODISARM (1U << 31) | ||
| 278 | #define SS_FLAG_BITS SS_AUTODISARM | ||
| 279 | #endif | ||
| 280 | #endif | ||
| 281 | |||
| 282 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 283 | #define NSIG _NSIG | ||
| 284 | typedef void (*sig_t)(int); | ||
| 285 | |||
| 286 | #define SYS_SECCOMP 1 | ||
| 287 | #define SYS_USER_DISPATCH 2 | ||
| 288 | #endif | ||
| 289 | |||
| 290 | #ifdef _GNU_SOURCE | ||
| 291 | typedef void (*sighandler_t)(int); | ||
| 292 | void (*bsd_signal(int, void (*)(int)))(int); | ||
| 293 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ | ||
| 294 | int sigisemptyset(const sigset_t *); | ||
| 295 | int sigorset (sigset_t *, const sigset_t *, const sigset_t *); | ||
| 296 | int sigandset(sigset_t *, const sigset_t *, const sigset_t *); | ||
| 297 | |||
| 298 | #define SA_NOMASK SA_NODEFER | ||
| 299 | #define SA_ONESHOT SA_RESETHAND | ||
| 300 | #endif | ||
| 301 | #endif | ||
| 302 | |||
| 303 | #ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ | ||
| 304 | #define SIG_ERR ((void (*)(int))-1) | ||
| 305 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 306 | #define SIG_IGN ((void (*)(int)) 1) | ||
| 307 | #else | ||
| 308 | void __SIG_ERR(int); | ||
| 309 | void __SIG_IGN(int); | ||
| 310 | #define SIG_ERR (__SIG_ERR) | ||
| 311 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 312 | #define SIG_IGN (__SIG_IGN) | ||
| 313 | #endif | ||
| 314 | |||
| 315 | #ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ | ||
| 316 | typedef int sig_atomic_t; | ||
| 317 | #else | ||
| 318 | typedef long sig_atomic_t; | ||
| 319 | #endif | ||
| 320 | |||
| 321 | void (*signal(int, void (*)(int)))(int); | ||
| 322 | int raise(int); | ||
| 323 | |||
| 324 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ | ||
| 325 | #if _REDIR_TIME64 | ||
| 326 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 327 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 328 | || defined(_BSD_SOURCE) | ||
| 329 | __REDIR(sigtimedwait, __sigtimedwait_time64); | ||
| 330 | #endif | ||
| 331 | #endif | ||
| 332 | #endif | ||
| 333 | |||
| 334 | #ifdef __cplusplus | ||
| 335 | } | ||
| 336 | #endif | ||
| 337 | |||
| 338 | #endif | ||
| 339 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdio.h deleted-254| ... | @@ -1,254 +0,0 @@ | ||
| 1 | #ifndef _STDIO_H | ||
| 2 | #define _STDIO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_FILE | ||
| 11 | #define __NEED___isoc_va_list | ||
| 12 | #define __NEED_size_t | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 15 | #if __STDC_VERSION__ < 201112L | ||
| 16 | #define __NEED_struct__IO_FILE | ||
| 17 | #endif | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 21 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 22 | || defined(_BSD_SOURCE) | ||
| 23 | #define __NEED_ssize_t | ||
| 24 | #define __NEED_off_t | ||
| 25 | #define __NEED_va_list | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #include <bits/alltypes.h> | ||
| 29 | |||
| 30 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 31 | #if __cplusplus >= 201103L | ||
| 32 | #define NULL nullptr | ||
| 33 | #elif defined(__cplusplus) | ||
| 34 | #define NULL 0L | ||
| 35 | #else | ||
| 36 | #define NULL ((void*)0) | ||
| 37 | #endif | ||
| 38 | #else | ||
| 39 | #define __need_NULL | ||
| 40 | #include <stddef.h> | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #undef EOF | ||
| 44 | #define EOF (-1) | ||
| 45 | |||
| 46 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 47 | #undef SEEK_SET | ||
| 48 | #undef SEEK_CUR | ||
| 49 | #undef SEEK_END | ||
| 50 | #define SEEK_SET 0 | ||
| 51 | #define SEEK_CUR 1 | ||
| 52 | #define SEEK_END 2 | ||
| 53 | #else | ||
| 54 | #include <__seek.h> | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #define _IOFBF 0 | ||
| 58 | #define _IOLBF 1 | ||
| 59 | #define _IONBF 2 | ||
| 60 | |||
| 61 | #define BUFSIZ 1024 | ||
| 62 | #define FILENAME_MAX 4096 | ||
| 63 | #define FOPEN_MAX 1000 | ||
| 64 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 65 | #define TMP_MAX 10000 | ||
| 66 | #define L_tmpnam 20 | ||
| 67 | #endif | ||
| 68 | |||
| 69 | typedef union _G_fpos64_t { | ||
| 70 | 	char __opaque[16]; | ||
| 71 | 	long long __lldata; | ||
| 72 | 	double __align; | ||
| 73 | } fpos_t; | ||
| 74 | |||
| 75 | extern FILE *const stdin; | ||
| 76 | extern FILE *const stdout; | ||
| 77 | extern FILE *const stderr; | ||
| 78 | |||
| 79 | #define stdin (stdin) | ||
| 80 | #define stdout (stdout) | ||
| 81 | #define stderr (stderr) | ||
| 82 | |||
| 83 | FILE *fopen(const char *__restrict, const char *__restrict); | ||
| 84 | FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); | ||
| 85 | int fclose(FILE *); | ||
| 86 | |||
| 87 | int remove(const char *); | ||
| 88 | int rename(const char *, const char *); | ||
| 89 | |||
| 90 | int feof(FILE *); | ||
| 91 | int ferror(FILE *); | ||
| 92 | int fflush(FILE *); | ||
| 93 | void clearerr(FILE *); | ||
| 94 | |||
| 95 | int fseek(FILE *, long, int); | ||
| 96 | long ftell(FILE *); | ||
| 97 | void rewind(FILE *); | ||
| 98 | |||
| 99 | int fgetpos(FILE *__restrict, fpos_t *__restrict); | ||
| 100 | int fsetpos(FILE *, const fpos_t *); | ||
| 101 | |||
| 102 | size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 103 | size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 104 | |||
| 105 | int fgetc(FILE *); | ||
| 106 | int getc(FILE *); | ||
| 107 | int getchar(void); | ||
| 108 | int ungetc(int, FILE *); | ||
| 109 | |||
| 110 | int fputc(int, FILE *); | ||
| 111 | int putc(int, FILE *); | ||
| 112 | int putchar(int); | ||
| 113 | |||
| 114 | char *fgets(char *__restrict, int, FILE *__restrict); | ||
| 115 | #if __STDC_VERSION__ < 201112L | ||
| 116 | #ifdef __wasilibc_unmodified_upstream /* gets is obsolete */ | ||
| 117 | char *gets(char *); | ||
| 118 | #else | ||
| 119 | char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI"))); | ||
| 120 | #endif | ||
| 121 | #endif | ||
| 122 | |||
| 123 | int fputs(const char *__restrict, FILE *__restrict); | ||
| 124 | int puts(const char *); | ||
| 125 | |||
| 126 | int printf(const char *__restrict, ...); | ||
| 127 | int fprintf(FILE *__restrict, const char *__restrict, ...); | ||
| 128 | int sprintf(char *__restrict, const char *__restrict, ...); | ||
| 129 | int snprintf(char *__restrict, size_t, const char *__restrict, ...); | ||
| 130 | |||
| 131 | int vprintf(const char *__restrict, __isoc_va_list); | ||
| 132 | int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 133 | int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 134 | int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); | ||
| 135 | |||
| 136 | int scanf(const char *__restrict, ...); | ||
| 137 | int fscanf(FILE *__restrict, const char *__restrict, ...); | ||
| 138 | int sscanf(const char *__restrict, const char *__restrict, ...); | ||
| 139 | int vscanf(const char *__restrict, __isoc_va_list); | ||
| 140 | int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 141 | int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 142 | |||
| 143 | void perror(const char *); | ||
| 144 | |||
| 145 | int setvbuf(FILE *__restrict, char *__restrict, int, size_t); | ||
| 146 | void setbuf(FILE *__restrict, char *__restrict); | ||
| 147 | |||
| 148 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 149 | char *tmpnam(char *); | ||
| 150 | FILE *tmpfile(void); | ||
| 151 | #else | ||
| 152 | char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI"))); | ||
| 153 | FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI"))); | ||
| 154 | #endif | ||
| 155 | |||
| 156 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 157 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 158 | || defined(_BSD_SOURCE) | ||
| 159 | FILE *fmemopen(void *__restrict, size_t, const char *__restrict); | ||
| 160 | FILE *open_memstream(char **, size_t *); | ||
| 161 | FILE *fdopen(int, const char *); | ||
| 162 | #ifdef __wasilibc_unmodified_upstream /* WASI has no popen */ | ||
| 163 | FILE *popen(const char *, const char *); | ||
| 164 | int pclose(FILE *); | ||
| 165 | #endif | ||
| 166 | int fileno(FILE *); | ||
| 167 | int fseeko(FILE *, off_t, int); | ||
| 168 | off_t ftello(FILE *); | ||
| 169 | int dprintf(int, const char *__restrict, ...); | ||
| 170 | int vdprintf(int, const char *__restrict, __isoc_va_list); | ||
| 171 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 172 | void flockfile(FILE *); | ||
| 173 | int ftrylockfile(FILE *); | ||
| 174 | void funlockfile(FILE *); | ||
| 175 | #endif | ||
| 176 | int getc_unlocked(FILE *); | ||
| 177 | int getchar_unlocked(void); | ||
| 178 | int putc_unlocked(int, FILE *); | ||
| 179 | int putchar_unlocked(int); | ||
| 180 | ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); | ||
| 181 | ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); | ||
| 182 | int renameat(int, const char *, int, const char *); | ||
| 183 | char *ctermid(char *); | ||
| 184 | #define L_ctermid 20 | ||
| 185 | #endif | ||
| 186 | |||
| 187 | |||
| 188 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 189 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 190 | || defined(_BSD_SOURCE) | ||
| 191 | #define P_tmpdir "/tmp" | ||
| 192 | char *tempnam(const char *, const char *); | ||
| 193 | #endif | ||
| 194 | #endif | ||
| 195 | |||
| 196 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 197 | #define L_cuserid 20 | ||
| 198 | char *cuserid(char *); | ||
| 199 | void setlinebuf(FILE *); | ||
| 200 | void setbuffer(FILE *, char *, size_t); | ||
| 201 | int fgetc_unlocked(FILE *); | ||
| 202 | int fputc_unlocked(int, FILE *); | ||
| 203 | int fflush_unlocked(FILE *); | ||
| 204 | size_t fread_unlocked(void *, size_t, size_t, FILE *); | ||
| 205 | size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); | ||
| 206 | void clearerr_unlocked(FILE *); | ||
| 207 | int feof_unlocked(FILE *); | ||
| 208 | int ferror_unlocked(FILE *); | ||
| 209 | int fileno_unlocked(FILE *); | ||
| 210 | int getw(FILE *); | ||
| 211 | int putw(int, FILE *); | ||
| 212 | char *fgetln(FILE *, size_t *); | ||
| 213 | int asprintf(char **, const char *, ...); | ||
| 214 | int vasprintf(char **, const char *, __isoc_va_list); | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #ifdef _GNU_SOURCE | ||
| 218 | char *fgets_unlocked(char *, int, FILE *); | ||
| 219 | int fputs_unlocked(const char *, FILE *); | ||
| 220 | |||
| 221 | typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); | ||
| 222 | typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); | ||
| 223 | typedef int (cookie_seek_function_t)(void *, off_t *, int); | ||
| 224 | typedef int (cookie_close_function_t)(void *); | ||
| 225 | |||
| 226 | typedef struct _IO_cookie_io_functions_t { | ||
| 227 | 	cookie_read_function_t *read; | ||
| 228 | 	cookie_write_function_t *write; | ||
| 229 | 	cookie_seek_function_t *seek; | ||
| 230 | 	cookie_close_function_t *close; | ||
| 231 | } cookie_io_functions_t; | ||
| 232 | |||
| 233 | FILE *fopencookie(void *, const char *, cookie_io_functions_t); | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 237 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 238 | #define tmpfile64 tmpfile | ||
| 239 | #endif | ||
| 240 | #define fopen64 fopen | ||
| 241 | #define freopen64 freopen | ||
| 242 | #define fseeko64 fseeko | ||
| 243 | #define ftello64 ftello | ||
| 244 | #define fgetpos64 fgetpos | ||
| 245 | #define fsetpos64 fsetpos | ||
| 246 | #define fpos64_t fpos_t | ||
| 247 | #define off64_t off_t | ||
| 248 | #endif | ||
| 249 | |||
| 250 | #ifdef __cplusplus | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdlib.h deleted-217| ... | @@ -1,217 +0,0 @@ | ||
| 1 | #ifndef _STDLIB_H | ||
| 2 | #define _STDLIB_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__functions_malloc.h> | ||
| 7 | #include <__header_stdlib.h> | ||
| 8 | #endif | ||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #include <features.h> | ||
| 14 | |||
| 15 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 16 | #if __cplusplus >= 201103L | ||
| 17 | #define NULL nullptr | ||
| 18 | #elif defined(__cplusplus) | ||
| 19 | #define NULL 0L | ||
| 20 | #else | ||
| 21 | #define NULL ((void*)0) | ||
| 22 | #endif | ||
| 23 | #else | ||
| 24 | #define __need_NULL | ||
| 25 | #include <stddef.h> | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #define __NEED_size_t | ||
| 29 | #define __NEED_wchar_t | ||
| 30 | |||
| 31 | #include <bits/alltypes.h> | ||
| 32 | |||
| 33 | int atoi (const char *); | ||
| 34 | long atol (const char *); | ||
| 35 | long long atoll (const char *); | ||
| 36 | double atof (const char *); | ||
| 37 | |||
| 38 | float strtof (const char *__restrict, char **__restrict); | ||
| 39 | double strtod (const char *__restrict, char **__restrict); | ||
| 40 | long double strtold (const char *__restrict, char **__restrict); | ||
| 41 | |||
| 42 | long strtol (const char *__restrict, char **__restrict, int); | ||
| 43 | unsigned long strtoul (const char *__restrict, char **__restrict, int); | ||
| 44 | long long strtoll (const char *__restrict, char **__restrict, int); | ||
| 45 | unsigned long long strtoull (const char *__restrict, char **__restrict, int); | ||
| 46 | |||
| 47 | int rand (void); | ||
| 48 | void srand (unsigned); | ||
| 49 | |||
| 50 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 51 | void *malloc (size_t); | ||
| 52 | void *calloc (size_t, size_t); | ||
| 53 | void *realloc (void *, size_t); | ||
| 54 | void free (void *); | ||
| 55 | #endif | ||
| 56 | void *aligned_alloc(size_t, size_t); | ||
| 57 | |||
| 58 | _Noreturn void abort (void); | ||
| 59 | int atexit (void (*) (void)); | ||
| 60 | _Noreturn void exit (int); | ||
| 61 | _Noreturn void _Exit (int); | ||
| 62 | int at_quick_exit (void (*) (void)); | ||
| 63 | _Noreturn void quick_exit (int); | ||
| 64 | |||
| 65 | char *getenv (const char *); | ||
| 66 | |||
| 67 | int system (const char *); | ||
| 68 | |||
| 69 | void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 70 | void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 71 | |||
| 72 | int abs (int); | ||
| 73 | long labs (long); | ||
| 74 | long long llabs (long long); | ||
| 75 | |||
| 76 | typedef struct { int quot, rem; } div_t; | ||
| 77 | typedef struct { long quot, rem; } ldiv_t; | ||
| 78 | typedef struct { long long quot, rem; } lldiv_t; | ||
| 79 | |||
| 80 | div_t div (int, int); | ||
| 81 | ldiv_t ldiv (long, long); | ||
| 82 | lldiv_t lldiv (long long, long long); | ||
| 83 | |||
| 84 | int mblen (const char *, size_t); | ||
| 85 | int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 86 | int wctomb (char *, wchar_t); | ||
| 87 | size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 88 | size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); | ||
| 89 | |||
| 90 | #define EXIT_FAILURE 1 | ||
| 91 | #define EXIT_SUCCESS 0 | ||
| 92 | |||
| 93 | size_t __ctype_get_mb_cur_max(void); | ||
| 94 | #define MB_CUR_MAX (__ctype_get_mb_cur_max()) | ||
| 95 | |||
| 96 | #define RAND_MAX (0x7fffffff) | ||
| 97 | |||
| 98 | |||
| 99 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 100 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 101 | || defined(_BSD_SOURCE) | ||
| 102 | |||
| 103 | #ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ | ||
| 104 | #define WNOHANG 1 | ||
| 105 | #define WUNTRACED 2 | ||
| 106 | |||
| 107 | #define WEXITSTATUS(s) (((s) & 0xff00) >> 8) | ||
| 108 | #define WTERMSIG(s) ((s) & 0x7f) | ||
| 109 | #define WSTOPSIG(s) WEXITSTATUS(s) | ||
| 110 | #define WIFEXITED(s) (!WTERMSIG(s)) | ||
| 111 | #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001U)>>8) > 0x7f00) | ||
| 112 | #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) | ||
| 113 | #endif | ||
| 114 | |||
| 115 | int posix_memalign (void **, size_t, size_t); | ||
| 116 | int setenv (const char *, const char *, int); | ||
| 117 | int unsetenv (const char *); | ||
| 118 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 119 | int mkstemp (char *); | ||
| 120 | int mkostemp (char *, int); | ||
| 121 | char *mkdtemp (char *); | ||
| 122 | #endif | ||
| 123 | int getsubopt (char **, char *const *, char **); | ||
| 124 | int rand_r (unsigned *); | ||
| 125 | |||
| 126 | #endif | ||
| 127 | |||
| 128 | |||
| 129 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 130 | || defined(_BSD_SOURCE) | ||
| 131 | char *realpath (const char *__restrict, char *__restrict); | ||
| 132 | long int random (void); | ||
| 133 | void srandom (unsigned int); | ||
| 134 | char *initstate (unsigned int, char *, size_t); | ||
| 135 | char *setstate (char *); | ||
| 136 | int putenv (char *); | ||
| 137 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ | ||
| 138 | int posix_openpt (int); | ||
| 139 | int grantpt (int); | ||
| 140 | int unlockpt (int); | ||
| 141 | char *ptsname (int); | ||
| 142 | #endif | ||
| 143 | char *l64a (long); | ||
| 144 | long a64l (const char *); | ||
| 145 | void setkey (const char *); | ||
| 146 | double drand48 (void); | ||
| 147 | double erand48 (unsigned short [3]); | ||
| 148 | long int lrand48 (void); | ||
| 149 | long int nrand48 (unsigned short [3]); | ||
| 150 | long mrand48 (void); | ||
| 151 | long jrand48 (unsigned short [3]); | ||
| 152 | void srand48 (long); | ||
| 153 | unsigned short *seed48 (unsigned short [3]); | ||
| 154 | void lcong48 (unsigned short [7]); | ||
| 155 | #endif | ||
| 156 | |||
| 157 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 158 | #include <alloca.h> | ||
| 159 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 160 | char *mktemp (char *); | ||
| 161 | int mkstemps (char *, int); | ||
| 162 | int mkostemps (char *, int, int); | ||
| 163 | #endif | ||
| 164 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 165 | void *valloc (size_t); | ||
| 166 | void *memalign(size_t, size_t); | ||
| 167 | int getloadavg(double *, int); | ||
| 168 | #endif | ||
| 169 | int clearenv(void); | ||
| 170 | #ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ | ||
| 171 | #define WCOREDUMP(s) ((s) & 0x80) | ||
| 172 | #define WIFCONTINUED(s) ((s) == 0xffff) | ||
| 173 | void *reallocarray (void *, size_t, size_t); | ||
| 174 | void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); | ||
| 175 | #endif | ||
| 176 | #endif | ||
| 177 | |||
| 178 | #ifdef _GNU_SOURCE | ||
| 179 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ | ||
| 180 | int ptsname_r(int, char *, size_t); | ||
| 181 | #endif | ||
| 182 | char *ecvt(double, int, int *, int *); | ||
| 183 | char *fcvt(double, int, int *, int *); | ||
| 184 | char *gcvt(double, int, char *); | ||
| 185 | char *secure_getenv(const char *); | ||
| 186 | struct __locale_struct; | ||
| 187 | float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 188 | double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 189 | long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 190 | #endif | ||
| 191 | |||
| 192 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 193 | #if defined(_LARGEFILE64_SOURCE) | ||
| 194 | #define mkstemp64 mkstemp | ||
| 195 | #define mkostemp64 mkostemp | ||
| 196 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 197 | #define mkstemps64 mkstemps | ||
| 198 | #define mkostemps64 mkostemps | ||
| 199 | #endif | ||
| 200 | #endif | ||
| 201 | #endif | ||
| 202 | |||
| 203 | #ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */ | ||
| 204 | #else | ||
| 205 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 206 | #include <stdint.h> | ||
| 207 | uint32_t arc4random(void); | ||
| 208 | void arc4random_buf(void *, size_t); | ||
| 209 | uint32_t arc4random_uniform(uint32_t); | ||
| 210 | #endif | ||
| 211 | #endif | ||
| 212 | |||
| 213 | #ifdef __cplusplus | ||
| 214 | } | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/string.h deleted-123| ... | @@ -1,123 +0,0 @@ | ||
| 1 | #ifndef	_STRING_H | ||
| 2 | #define	_STRING_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 5 | #else | ||
| 6 | #include <__header_string.h> | ||
| 7 | #endif | ||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <features.h> | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 15 | #if __cplusplus >= 201103L | ||
| 16 | #define NULL nullptr | ||
| 17 | #elif defined(__cplusplus) | ||
| 18 | #define NULL 0L | ||
| 19 | #else | ||
| 20 | #define NULL ((void*)0) | ||
| 21 | #endif | ||
| 22 | #else | ||
| 23 | #define __need_NULL | ||
| 24 | #include <stddef.h> | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #define __NEED_size_t | ||
| 28 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 29 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 30 | || defined(_BSD_SOURCE) | ||
| 31 | #define __NEED_locale_t | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include <bits/alltypes.h> | ||
| 35 | |||
| 36 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 37 | void *memcpy (void *__restrict, const void *__restrict, size_t); | ||
| 38 | void *memmove (void *, const void *, size_t); | ||
| 39 | void *memset (void *, int, size_t); | ||
| 40 | #endif | ||
| 41 | int memcmp (const void *, const void *, size_t); | ||
| 42 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 43 | void *memchr (const void *, int, size_t); | ||
| 44 | #endif | ||
| 45 | |||
| 46 | char *strcpy (char *__restrict, const char *__restrict); | ||
| 47 | char *strncpy (char *__restrict, const char *__restrict, size_t); | ||
| 48 | |||
| 49 | char *strcat (char *__restrict, const char *__restrict); | ||
| 50 | char *strncat (char *__restrict, const char *__restrict, size_t); | ||
| 51 | |||
| 52 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 53 | int strcmp (const char *, const char *); | ||
| 54 | #endif | ||
| 55 | int strncmp (const char *, const char *, size_t); | ||
| 56 | |||
| 57 | int strcoll (const char *, const char *); | ||
| 58 | size_t strxfrm (char *__restrict, const char *__restrict, size_t); | ||
| 59 | |||
| 60 | char *strchr (const char *, int); | ||
| 61 | char *strrchr (const char *, int); | ||
| 62 | |||
| 63 | size_t strcspn (const char *, const char *); | ||
| 64 | size_t strspn (const char *, const char *); | ||
| 65 | char *strpbrk (const char *, const char *); | ||
| 66 | char *strstr (const char *, const char *); | ||
| 67 | char *strtok (char *__restrict, const char *__restrict); | ||
| 68 | |||
| 69 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 70 | size_t strlen (const char *); | ||
| 71 | #endif | ||
| 72 | |||
| 73 | char *strerror (int); | ||
| 74 | |||
| 75 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 76 | #include <strings.h> | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 80 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 81 | || defined(_BSD_SOURCE) | ||
| 82 | char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); | ||
| 83 | int strerror_r (int, char *, size_t); | ||
| 84 | char *stpcpy(char *__restrict, const char *__restrict); | ||
| 85 | char *stpncpy(char *__restrict, const char *__restrict, size_t); | ||
| 86 | size_t strnlen (const char *, size_t); | ||
| 87 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 88 | char *strdup (const char *); | ||
| 89 | #endif | ||
| 90 | char *strndup (const char *, size_t); | ||
| 91 | char *strsignal(int); | ||
| 92 | char *strerror_l (int, locale_t); | ||
| 93 | int strcoll_l (const char *, const char *, locale_t); | ||
| 94 | size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); | ||
| 95 | void *memmem(const void *, size_t, const void *, size_t); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 99 | || defined(_BSD_SOURCE) | ||
| 100 | void *memccpy (void *__restrict, const void *__restrict, int, size_t); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 104 | char *strsep(char **, const char *); | ||
| 105 | size_t strlcat (char *, const char *, size_t); | ||
| 106 | size_t strlcpy (char *, const char *, size_t); | ||
| 107 | void explicit_bzero (void *, size_t); | ||
| 108 | #endif | ||
| 109 | |||
| 110 | #ifdef _GNU_SOURCE | ||
| 111 | #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x) | ||
| 112 | int strverscmp (const char *, const char *); | ||
| 113 | char *strchrnul(const char *, int); | ||
| 114 | char *strcasestr(const char *, const char *); | ||
| 115 | void *memrchr(const void *, int, size_t); | ||
| 116 | void *mempcpy(void *, const void *, size_t); | ||
| 117 | #endif | ||
| 118 | |||
| 119 | #ifdef __cplusplus | ||
| 120 | } | ||
| 121 | #endif | ||
| 122 | |||
| 123 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/ioctl.h deleted-124| ... | @@ -1,124 +0,0 @@ | ||
| 1 | #ifndef	_SYS_IOCTL_H | ||
| 2 | #define	_SYS_IOCTL_H | ||
| 3 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_struct_winsize | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | #include <bits/ioctl.h> | ||
| 12 | |||
| 13 | #define N_TTY 0 | ||
| 14 | #define N_SLIP 1 | ||
| 15 | #define N_MOUSE 2 | ||
| 16 | #define N_PPP 3 | ||
| 17 | #define N_STRIP 4 | ||
| 18 | #define N_AX25 5 | ||
| 19 | #define N_X25 6 | ||
| 20 | #define N_6PACK 7 | ||
| 21 | #define N_MASC 8 | ||
| 22 | #define N_R3964 9 | ||
| 23 | #define N_PROFIBUS_FDL 10 | ||
| 24 | #define N_IRDA 11 | ||
| 25 | #define N_SMSBLOCK 12 | ||
| 26 | #define N_HDLC 13 | ||
| 27 | #define N_SYNC_PPP 14 | ||
| 28 | #define N_HCI 15 | ||
| 29 | #define N_GIGASET_M101 16 | ||
| 30 | #define N_SLCAN 17 | ||
| 31 | #define N_PPS 18 | ||
| 32 | #define N_V253 19 | ||
| 33 | #define N_CAIF 20 | ||
| 34 | #define N_GSM0710 21 | ||
| 35 | #define N_TI_WL 22 | ||
| 36 | #define N_TRACESINK 23 | ||
| 37 | #define N_TRACEROUTER 24 | ||
| 38 | #define N_NCI 25 | ||
| 39 | #define N_SPEAKUP 26 | ||
| 40 | #define N_NULL 27 | ||
| 41 | |||
| 42 | #define TIOCPKT_DATA 0 | ||
| 43 | #define TIOCPKT_FLUSHREAD 1 | ||
| 44 | #define TIOCPKT_FLUSHWRITE 2 | ||
| 45 | #define TIOCPKT_STOP 4 | ||
| 46 | #define TIOCPKT_START 8 | ||
| 47 | #define TIOCPKT_NOSTOP 16 | ||
| 48 | #define TIOCPKT_DOSTOP 32 | ||
| 49 | #define TIOCPKT_IOCTL 64 | ||
| 50 | |||
| 51 | #define TIOCSER_TEMT 1 | ||
| 52 | |||
| 53 | #define SIOCADDRT 0x890B | ||
| 54 | #define SIOCDELRT 0x890C | ||
| 55 | #define SIOCRTMSG 0x890D | ||
| 56 | |||
| 57 | #define SIOCGIFNAME 0x8910 | ||
| 58 | #define SIOCSIFLINK 0x8911 | ||
| 59 | #define SIOCGIFCONF 0x8912 | ||
| 60 | #define SIOCGIFFLAGS 0x8913 | ||
| 61 | #define SIOCSIFFLAGS 0x8914 | ||
| 62 | #define SIOCGIFADDR 0x8915 | ||
| 63 | #define SIOCSIFADDR 0x8916 | ||
| 64 | #define SIOCGIFDSTADDR 0x8917 | ||
| 65 | #define SIOCSIFDSTADDR 0x8918 | ||
| 66 | #define SIOCGIFBRDADDR 0x8919 | ||
| 67 | #define SIOCSIFBRDADDR 0x891a | ||
| 68 | #define SIOCGIFNETMASK 0x891b | ||
| 69 | #define SIOCSIFNETMASK 0x891c | ||
| 70 | #define SIOCGIFMETRIC 0x891d | ||
| 71 | #define SIOCSIFMETRIC 0x891e | ||
| 72 | #define SIOCGIFMEM 0x891f | ||
| 73 | #define SIOCSIFMEM 0x8920 | ||
| 74 | #define SIOCGIFMTU 0x8921 | ||
| 75 | #define SIOCSIFMTU 0x8922 | ||
| 76 | #define SIOCSIFNAME 0x8923 | ||
| 77 | #define SIOCSIFHWADDR 0x8924 | ||
| 78 | #define SIOCGIFENCAP 0x8925 | ||
| 79 | #define SIOCSIFENCAP 0x8926 | ||
| 80 | #define SIOCGIFHWADDR 0x8927 | ||
| 81 | #define SIOCGIFSLAVE 0x8929 | ||
| 82 | #define SIOCSIFSLAVE 0x8930 | ||
| 83 | #define SIOCADDMULTI 0x8931 | ||
| 84 | #define SIOCDELMULTI 0x8932 | ||
| 85 | #define SIOCGIFINDEX 0x8933 | ||
| 86 | #define SIOGIFINDEX SIOCGIFINDEX | ||
| 87 | #define SIOCSIFPFLAGS 0x8934 | ||
| 88 | #define SIOCGIFPFLAGS 0x8935 | ||
| 89 | #define SIOCDIFADDR 0x8936 | ||
| 90 | #define SIOCSIFHWBROADCAST 0x8937 | ||
| 91 | #define SIOCGIFCOUNT 0x8938 | ||
| 92 | |||
| 93 | #define SIOCGIFBR 0x8940 | ||
| 94 | #define SIOCSIFBR 0x8941 | ||
| 95 | |||
| 96 | #define SIOCGIFTXQLEN 0x8942 | ||
| 97 | #define SIOCSIFTXQLEN 0x8943 | ||
| 98 | |||
| 99 | #define SIOCDARP 0x8953 | ||
| 100 | #define SIOCGARP 0x8954 | ||
| 101 | #define SIOCSARP 0x8955 | ||
| 102 | |||
| 103 | #define SIOCDRARP 0x8960 | ||
| 104 | #define SIOCGRARP 0x8961 | ||
| 105 | #define SIOCSRARP 0x8962 | ||
| 106 | |||
| 107 | #define SIOCGIFMAP 0x8970 | ||
| 108 | #define SIOCSIFMAP 0x8971 | ||
| 109 | |||
| 110 | #define SIOCADDDLCI 0x8980 | ||
| 111 | #define SIOCDELDLCI 0x8981 | ||
| 112 | |||
| 113 | #define SIOCDEVPRIVATE 0x89F0 | ||
| 114 | #define SIOCPROTOPRIVATE 0x89E0 | ||
| 115 | |||
| 116 | int ioctl (int, int, ...); | ||
| 117 | |||
| 118 | #ifdef __cplusplus | ||
| 119 | } | ||
| 120 | #endif | ||
| 121 | #else | ||
| 122 | #include <__header_sys_ioctl.h> | ||
| 123 | #endif | ||
| 124 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/mman.h deleted-157| ... | @@ -1,157 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_MMAN | ||
| 2 | #error "WASI lacks a true mmap; to enable minimal mmap emulation, \ | ||
| 3 | compile with -D_WASI_EMULATED_MMAN and link with -lwasi-emulated-mman" | ||
| 4 | #else | ||
| 5 | #ifndef	_SYS_MMAN_H | ||
| 6 | #define	_SYS_MMAN_H | ||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #include <features.h> | ||
| 12 | |||
| 13 | #define __NEED_mode_t | ||
| 14 | #define __NEED_size_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | |||
| 17 | #if defined(_GNU_SOURCE) | ||
| 18 | #define __NEED_ssize_t | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #include <bits/alltypes.h> | ||
| 22 | |||
| 23 | #define MAP_FAILED ((void *) -1) | ||
| 24 | |||
| 25 | #define MAP_SHARED 0x01 | ||
| 26 | #define MAP_PRIVATE 0x02 | ||
| 27 | #define MAP_SHARED_VALIDATE 0x03 | ||
| 28 | #define MAP_TYPE 0x0f | ||
| 29 | #define MAP_FIXED 0x10 | ||
| 30 | #define MAP_ANON 0x20 | ||
| 31 | #define MAP_ANONYMOUS MAP_ANON | ||
| 32 | #define MAP_NORESERVE 0x4000 | ||
| 33 | #define MAP_GROWSDOWN 0x0100 | ||
| 34 | #define MAP_DENYWRITE 0x0800 | ||
| 35 | #define MAP_EXECUTABLE 0x1000 | ||
| 36 | #define MAP_LOCKED 0x2000 | ||
| 37 | #define MAP_POPULATE 0x8000 | ||
| 38 | #define MAP_NONBLOCK 0x10000 | ||
| 39 | #define MAP_STACK 0x20000 | ||
| 40 | #define MAP_HUGETLB 0x40000 | ||
| 41 | #define MAP_SYNC 0x80000 | ||
| 42 | #define MAP_FIXED_NOREPLACE 0x100000 | ||
| 43 | #define MAP_FILE 0 | ||
| 44 | |||
| 45 | #define MAP_HUGE_SHIFT 26 | ||
| 46 | #define MAP_HUGE_MASK 0x3f | ||
| 47 | #define MAP_HUGE_16KB (14 << 26) | ||
| 48 | #define MAP_HUGE_64KB (16 << 26) | ||
| 49 | #define MAP_HUGE_512KB (19 << 26) | ||
| 50 | #define MAP_HUGE_1MB (20 << 26) | ||
| 51 | #define MAP_HUGE_2MB (21 << 26) | ||
| 52 | #define MAP_HUGE_8MB (23 << 26) | ||
| 53 | #define MAP_HUGE_16MB (24 << 26) | ||
| 54 | #define MAP_HUGE_32MB (25 << 26) | ||
| 55 | #define MAP_HUGE_256MB (28 << 26) | ||
| 56 | #define MAP_HUGE_512MB (29 << 26) | ||
| 57 | #define MAP_HUGE_1GB (30 << 26) | ||
| 58 | #define MAP_HUGE_2GB (31 << 26) | ||
| 59 | #define MAP_HUGE_16GB (34U << 26) | ||
| 60 | |||
| 61 | #define PROT_NONE 0 | ||
| 62 | #define PROT_READ 1 | ||
| 63 | #define PROT_WRITE 2 | ||
| 64 | #define PROT_EXEC 4 | ||
| 65 | #define PROT_GROWSDOWN 0x01000000 | ||
| 66 | #define PROT_GROWSUP 0x02000000 | ||
| 67 | |||
| 68 | #define MS_ASYNC 1 | ||
| 69 | #define MS_INVALIDATE 2 | ||
| 70 | #define MS_SYNC 4 | ||
| 71 | |||
| 72 | #define MCL_CURRENT 1 | ||
| 73 | #define MCL_FUTURE 2 | ||
| 74 | #define MCL_ONFAULT 4 | ||
| 75 | |||
| 76 | #define POSIX_MADV_NORMAL 0 | ||
| 77 | #define POSIX_MADV_RANDOM 1 | ||
| 78 | #define POSIX_MADV_SEQUENTIAL 2 | ||
| 79 | #define POSIX_MADV_WILLNEED 3 | ||
| 80 | #define POSIX_MADV_DONTNEED 4 | ||
| 81 | |||
| 82 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 83 | #define MADV_NORMAL 0 | ||
| 84 | #define MADV_RANDOM 1 | ||
| 85 | #define MADV_SEQUENTIAL 2 | ||
| 86 | #define MADV_WILLNEED 3 | ||
| 87 | #define MADV_DONTNEED 4 | ||
| 88 | #define MADV_FREE 8 | ||
| 89 | #define MADV_REMOVE 9 | ||
| 90 | #define MADV_DONTFORK 10 | ||
| 91 | #define MADV_DOFORK 11 | ||
| 92 | #define MADV_MERGEABLE 12 | ||
| 93 | #define MADV_UNMERGEABLE 13 | ||
| 94 | #define MADV_HUGEPAGE 14 | ||
| 95 | #define MADV_NOHUGEPAGE 15 | ||
| 96 | #define MADV_DONTDUMP 16 | ||
| 97 | #define MADV_DODUMP 17 | ||
| 98 | #define MADV_WIPEONFORK 18 | ||
| 99 | #define MADV_KEEPONFORK 19 | ||
| 100 | #define MADV_COLD 20 | ||
| 101 | #define MADV_PAGEOUT 21 | ||
| 102 | #define MADV_HWPOISON 100 | ||
| 103 | #define MADV_SOFT_OFFLINE 101 | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifdef _GNU_SOURCE | ||
| 107 | #define MREMAP_MAYMOVE 1 | ||
| 108 | #define MREMAP_FIXED 2 | ||
| 109 | #define MREMAP_DONTUNMAP 4 | ||
| 110 | |||
| 111 | #define MLOCK_ONFAULT 0x01 | ||
| 112 | |||
| 113 | #define MFD_CLOEXEC 0x0001U | ||
| 114 | #define MFD_ALLOW_SEALING 0x0002U | ||
| 115 | #define MFD_HUGETLB 0x0004U | ||
| 116 | #endif | ||
| 117 | |||
| 118 | #include <bits/mman.h> | ||
| 119 | |||
| 120 | void *mmap (void *, size_t, int, int, int, off_t); | ||
| 121 | int munmap (void *, size_t); | ||
| 122 | |||
| 123 | int mprotect (void *, size_t, int); | ||
| 124 | int msync (void *, size_t, int); | ||
| 125 | |||
| 126 | int posix_madvise (void *, size_t, int); | ||
| 127 | |||
| 128 | int mlock (const void *, size_t); | ||
| 129 | int munlock (const void *, size_t); | ||
| 130 | int mlockall (int); | ||
| 131 | int munlockall (void); | ||
| 132 | |||
| 133 | #ifdef _GNU_SOURCE | ||
| 134 | void *mremap (void *, size_t, size_t, int, ...); | ||
| 135 | int remap_file_pages (void *, size_t, int, size_t, int); | ||
| 136 | int memfd_create (const char *, unsigned); | ||
| 137 | int mlock2 (const void *, size_t, unsigned); | ||
| 138 | #endif | ||
| 139 | |||
| 140 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 141 | int madvise (void *, size_t, int); | ||
| 142 | int mincore (void *, size_t, unsigned char *); | ||
| 143 | #endif | ||
| 144 | |||
| 145 | int shm_open (const char *, int, mode_t); | ||
| 146 | int shm_unlink (const char *); | ||
| 147 | |||
| 148 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 149 | #define mmap64 mmap | ||
| 150 | #define off64_t off_t | ||
| 151 | #endif | ||
| 152 | |||
| 153 | #ifdef __cplusplus | ||
| 154 | } | ||
| 155 | #endif | ||
| 156 | #endif | ||
| 157 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/param.h deleted-37| ... | @@ -1,37 +0,0 @@ | ||
| 1 | #ifndef _SYS_PARAM_H | ||
| 2 | #define _SYS_PARAM_H | ||
| 3 | |||
| 4 | #define MAXSYMLINKS 20 | ||
| 5 | #define MAXHOSTNAMELEN 64 | ||
| 6 | #define MAXNAMLEN 255 | ||
| 7 | #define MAXPATHLEN 4096 | ||
| 8 | #define NBBY 8 | ||
| 9 | #define NGROUPS 32 | ||
| 10 | #define CANBSIZ 255 | ||
| 11 | #define NOFILE 256 | ||
| 12 | #define NCARGS 131072 | ||
| 13 | #define DEV_BSIZE 512 | ||
| 14 | #define NOGROUP (-1) | ||
| 15 | |||
| 16 | #undef MIN | ||
| 17 | #undef MAX | ||
| 18 | #define MIN(a,b) (((a)<(b))?(a):(b)) | ||
| 19 | #define MAX(a,b) (((a)>(b))?(a):(b)) | ||
| 20 | |||
| 21 | #define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8)) | ||
| 22 | #define setbit(x,i) __bitop(x,i,|=) | ||
| 23 | #define clrbit(x,i) __bitop(x,i,&=~) | ||
| 24 | #define isset(x,i) __bitop(x,i,&) | ||
| 25 | #define isclr(x,i) !isset(x,i) | ||
| 26 | |||
| 27 | #define howmany(n,d) (((n)+((d)-1))/(d)) | ||
| 28 | #define roundup(n,d) (howmany(n,d)*(d)) | ||
| 29 | #define powerof2(n) !(((n)-1) & (n)) | ||
| 30 | |||
| 31 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) | ||
| 32 | #include <sys/resource.h> | ||
| 33 | #endif | ||
| 34 | #include <endian.h> | ||
| 35 | #include <limits.h> | ||
| 36 | |||
| 37 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/random.h deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | #ifndef _SYS_RANDOM_H | ||
| 2 | #define _SYS_RANDOM_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getrandom, but it does have getentropy */ | ||
| 8 | #define __NEED_size_t | ||
| 9 | #define __NEED_ssize_t | ||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #define GRND_NONBLOCK	0x0001 | ||
| 13 | #define GRND_RANDOM	0x0002 | ||
| 14 | #define GRND_INSECURE	0x0004 | ||
| 15 | |||
| 16 | ssize_t getrandom(void *, size_t, unsigned); | ||
| 17 | #else | ||
| 18 | #define __NEED_size_t | ||
| 19 | #include <bits/alltypes.h> | ||
| 20 | |||
| 21 | int getentropy(void *, size_t); | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #ifdef __cplusplus | ||
| 25 | } | ||
| 26 | #endif | ||
| 27 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/resource.h deleted-126| ... | @@ -1,126 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #error WASI lacks process-associated clocks; to enable emulation of the `getrusage` function using \ | ||
| 3 | the wall clock, which isn't sensitive to whether the program is running or suspended, \ | ||
| 4 | compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks | ||
| 5 | #else | ||
| 6 | #ifndef	_SYS_RESOURCE_H | ||
| 7 | #define	_SYS_RESOURCE_H | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #include <features.h> | ||
| 14 | #include <sys/time.h> | ||
| 15 | |||
| 16 | #define __NEED_id_t | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __NEED_pid_t | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #include <bits/alltypes.h> | ||
| 23 | #include <bits/resource.h> | ||
| 24 | |||
| 25 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 26 | typedef unsigned long long rlim_t; | ||
| 27 | |||
| 28 | struct rlimit { | ||
| 29 | 	rlim_t rlim_cur; | ||
| 30 | 	rlim_t rlim_max; | ||
| 31 | }; | ||
| 32 | |||
| 33 | struct rusage { | ||
| 34 | 	struct timeval ru_utime; | ||
| 35 | 	struct timeval ru_stime; | ||
| 36 | 	/* linux extentions, but useful */ | ||
| 37 | 	long	ru_maxrss; | ||
| 38 | 	long	ru_ixrss; | ||
| 39 | 	long	ru_idrss; | ||
| 40 | 	long	ru_isrss; | ||
| 41 | 	long	ru_minflt; | ||
| 42 | 	long	ru_majflt; | ||
| 43 | 	long	ru_nswap; | ||
| 44 | 	long	ru_inblock; | ||
| 45 | 	long	ru_oublock; | ||
| 46 | 	long	ru_msgsnd; | ||
| 47 | 	long	ru_msgrcv; | ||
| 48 | 	long	ru_nsignals; | ||
| 49 | 	long	ru_nvcsw; | ||
| 50 | 	long	ru_nivcsw; | ||
| 51 | 	/* room for more... */ | ||
| 52 | 	long __reserved[16]; | ||
| 53 | }; | ||
| 54 | |||
| 55 | int getrlimit (int, struct rlimit *); | ||
| 56 | int setrlimit (int, const struct rlimit *); | ||
| 57 | int getrusage (int, struct rusage *); | ||
| 58 | |||
| 59 | int getpriority (int, id_t); | ||
| 60 | int setpriority (int, id_t, int); | ||
| 61 | |||
| 62 | #ifdef _GNU_SOURCE | ||
| 63 | int prlimit(pid_t, int, const struct rlimit *, struct rlimit *); | ||
| 64 | #define prlimit64 prlimit | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #define PRIO_MIN (-20) | ||
| 68 | #define PRIO_MAX 20 | ||
| 69 | |||
| 70 | #define PRIO_PROCESS 0 | ||
| 71 | #define PRIO_PGRP 1 | ||
| 72 | #define PRIO_USER 2 | ||
| 73 | |||
| 74 | #define RUSAGE_SELF 0 | ||
| 75 | #define RUSAGE_CHILDREN (-1) | ||
| 76 | #define RUSAGE_THREAD 1 | ||
| 77 | |||
| 78 | #define RLIM_INFINITY (~0ULL) | ||
| 79 | #define RLIM_SAVED_CUR RLIM_INFINITY | ||
| 80 | #define RLIM_SAVED_MAX RLIM_INFINITY | ||
| 81 | |||
| 82 | #define RLIMIT_CPU 0 | ||
| 83 | #define RLIMIT_FSIZE 1 | ||
| 84 | #define RLIMIT_DATA 2 | ||
| 85 | #define RLIMIT_STACK 3 | ||
| 86 | #define RLIMIT_CORE 4 | ||
| 87 | #ifndef RLIMIT_RSS | ||
| 88 | #define RLIMIT_RSS 5 | ||
| 89 | #define RLIMIT_NPROC 6 | ||
| 90 | #define RLIMIT_NOFILE 7 | ||
| 91 | #define RLIMIT_MEMLOCK 8 | ||
| 92 | #define RLIMIT_AS 9 | ||
| 93 | #endif | ||
| 94 | #define RLIMIT_LOCKS 10 | ||
| 95 | #define RLIMIT_SIGPENDING 11 | ||
| 96 | #define RLIMIT_MSGQUEUE 12 | ||
| 97 | #define RLIMIT_NICE 13 | ||
| 98 | #define RLIMIT_RTPRIO 14 | ||
| 99 | #define RLIMIT_RTTIME 15 | ||
| 100 | #define RLIMIT_NLIMITS 16 | ||
| 101 | |||
| 102 | #define RLIM_NLIMITS RLIMIT_NLIMITS | ||
| 103 | |||
| 104 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 105 | #define RLIM64_INFINITY RLIM_INFINITY | ||
| 106 | #define RLIM64_SAVED_CUR RLIM_SAVED_CUR | ||
| 107 | #define RLIM64_SAVED_MAX RLIM_SAVED_MAX | ||
| 108 | #define getrlimit64 getrlimit | ||
| 109 | #define setrlimit64 setrlimit | ||
| 110 | #define rlimit64 rlimit | ||
| 111 | #define rlim64_t rlim_t | ||
| 112 | #endif | ||
| 113 | #else | ||
| 114 | #include <__header_sys_resource.h> | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #if _REDIR_TIME64 | ||
| 118 | __REDIR(getrusage, __getrusage_time64); | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #ifdef __cplusplus | ||
| 122 | } | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #endif | ||
| 126 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/select.h deleted-54| ... | @@ -1,54 +0,0 @@ | ||
| 1 | #ifndef _SYS_SELECT_H | ||
| 2 | #define _SYS_SELECT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_time_t | ||
| 11 | #define __NEED_suseconds_t | ||
| 12 | #define __NEED_struct_timeval | ||
| 13 | #define __NEED_struct_timespec | ||
| 14 | #define __NEED_sigset_t | ||
| 15 | |||
| 16 | #include <bits/alltypes.h> | ||
| 17 | |||
| 18 | #define FD_SETSIZE 1024 | ||
| 19 | |||
| 20 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 21 | typedef unsigned long fd_mask; | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 25 | typedef struct { | ||
| 26 | 	unsigned long fds_bits[FD_SETSIZE / 8 / sizeof(long)]; | ||
| 27 | } fd_set; | ||
| 28 | |||
| 29 | #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) | ||
| 30 | #define FD_SET(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long))))) | ||
| 31 | #define FD_CLR(d, s) ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long))))) | ||
| 32 | #define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long))))) | ||
| 33 | #else | ||
| 34 | #include <__fd_set.h> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict); | ||
| 38 | int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict); | ||
| 39 | |||
| 40 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 41 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 42 | #define NFDBITS (8*(int)sizeof(long)) | ||
| 43 | #endif | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #if _REDIR_TIME64 | ||
| 47 | __REDIR(select, __select_time64); | ||
| 48 | __REDIR(pselect, __pselect_time64); | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #ifdef __cplusplus | ||
| 52 | } | ||
| 53 | #endif | ||
| 54 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/sendfile.h deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | #ifndef _SYS_SENDFILE_H | ||
| 2 | #define _SYS_SENDFILE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | ssize_t sendfile(int, int, off_t *, size_t); | ||
| 12 | |||
| 13 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 14 | #define sendfile64 sendfile | ||
| 15 | #define off64_t off_t | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/socket.h deleted-454| ... | @@ -1,454 +0,0 @@ | ||
| 1 | #ifndef	_SYS_SOCKET_H | ||
| 2 | #define	_SYS_SOCKET_H | ||
| 3 | |||
| 4 | #include <__wasi_snapshot.h> | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 7 | #else | ||
| 8 | #include <__header_sys_socket.h> | ||
| 9 | #endif | ||
| 10 | #ifdef __cplusplus | ||
| 11 | extern "C" { | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include <features.h> | ||
| 15 | |||
| 16 | #define __NEED_socklen_t | ||
| 17 | #define __NEED_sa_family_t | ||
| 18 | #define __NEED_size_t | ||
| 19 | #define __NEED_ssize_t | ||
| 20 | #define __NEED_uid_t | ||
| 21 | #define __NEED_pid_t | ||
| 22 | #define __NEED_gid_t | ||
| 23 | #define __NEED_struct_iovec | ||
| 24 | |||
| 25 | #include <bits/alltypes.h> | ||
| 26 | |||
| 27 | #include <bits/socket.h> | ||
| 28 | |||
| 29 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 30 | struct msghdr { | ||
| 31 | 	void *msg_name; | ||
| 32 | 	socklen_t msg_namelen; | ||
| 33 | 	struct iovec *msg_iov; | ||
| 34 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 35 | 	int __pad1; | ||
| 36 | #endif | ||
| 37 | 	int msg_iovlen; | ||
| 38 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 39 | 	int __pad1; | ||
| 40 | #endif | ||
| 41 | 	void *msg_control; | ||
| 42 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 43 | 	int __pad2; | ||
| 44 | #endif | ||
| 45 | 	socklen_t msg_controllen; | ||
| 46 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 47 | 	int __pad2; | ||
| 48 | #endif | ||
| 49 | 	int msg_flags; | ||
| 50 | }; | ||
| 51 | |||
| 52 | struct cmsghdr { | ||
| 53 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 54 | 	int __pad1; | ||
| 55 | #endif | ||
| 56 | 	socklen_t cmsg_len; | ||
| 57 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 58 | 	int __pad1; | ||
| 59 | #endif | ||
| 60 | 	int cmsg_level; | ||
| 61 | 	int cmsg_type; | ||
| 62 | }; | ||
| 63 | #else | ||
| 64 | #include <__struct_msghdr.h> | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #ifdef _GNU_SOURCE | ||
| 68 | struct ucred { | ||
| 69 | 	pid_t pid; | ||
| 70 | 	uid_t uid; | ||
| 71 | 	gid_t gid; | ||
| 72 | }; | ||
| 73 | |||
| 74 | struct mmsghdr { | ||
| 75 | 	struct msghdr msg_hdr; | ||
| 76 | 	unsigned int msg_len; | ||
| 77 | }; | ||
| 78 | |||
| 79 | struct timespec; | ||
| 80 | |||
| 81 | int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); | ||
| 82 | int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); | ||
| 83 | #endif | ||
| 84 | |||
| 85 | struct linger { | ||
| 86 | 	int l_onoff; | ||
| 87 | 	int l_linger; | ||
| 88 | }; | ||
| 89 | |||
| 90 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 91 | #define SHUT_RD 0 | ||
| 92 | #define SHUT_WR 1 | ||
| 93 | #define SHUT_RDWR 2 | ||
| 94 | |||
| 95 | #ifndef SOCK_STREAM | ||
| 96 | #define SOCK_STREAM 1 | ||
| 97 | #define SOCK_DGRAM 2 | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #define SOCK_RAW 3 | ||
| 101 | #define SOCK_RDM 4 | ||
| 102 | #define SOCK_SEQPACKET 5 | ||
| 103 | #define SOCK_DCCP 6 | ||
| 104 | #define SOCK_PACKET 10 | ||
| 105 | |||
| 106 | #ifndef SOCK_CLOEXEC | ||
| 107 | #define SOCK_CLOEXEC 02000000 | ||
| 108 | #define SOCK_NONBLOCK 04000 | ||
| 109 | #endif | ||
| 110 | |||
| 111 | #define PF_UNSPEC 0 | ||
| 112 | #define PF_LOCAL 1 | ||
| 113 | #define PF_UNIX PF_LOCAL | ||
| 114 | #define PF_FILE PF_LOCAL | ||
| 115 | #define PF_INET 2 | ||
| 116 | #define PF_AX25 3 | ||
| 117 | #define PF_IPX 4 | ||
| 118 | #define PF_APPLETALK 5 | ||
| 119 | #define PF_NETROM 6 | ||
| 120 | #define PF_BRIDGE 7 | ||
| 121 | #define PF_ATMPVC 8 | ||
| 122 | #define PF_X25 9 | ||
| 123 | #define PF_INET6 10 | ||
| 124 | #define PF_ROSE 11 | ||
| 125 | #define PF_DECnet 12 | ||
| 126 | #define PF_NETBEUI 13 | ||
| 127 | #define PF_SECURITY 14 | ||
| 128 | #define PF_KEY 15 | ||
| 129 | #define PF_NETLINK 16 | ||
| 130 | #define PF_ROUTE PF_NETLINK | ||
| 131 | #define PF_PACKET 17 | ||
| 132 | #define PF_ASH 18 | ||
| 133 | #define PF_ECONET 19 | ||
| 134 | #define PF_ATMSVC 20 | ||
| 135 | #define PF_RDS 21 | ||
| 136 | #define PF_SNA 22 | ||
| 137 | #define PF_IRDA 23 | ||
| 138 | #define PF_PPPOX 24 | ||
| 139 | #define PF_WANPIPE 25 | ||
| 140 | #define PF_LLC 26 | ||
| 141 | #define PF_IB 27 | ||
| 142 | #define PF_MPLS 28 | ||
| 143 | #define PF_CAN 29 | ||
| 144 | #define PF_TIPC 30 | ||
| 145 | #define PF_BLUETOOTH 31 | ||
| 146 | #define PF_IUCV 32 | ||
| 147 | #define PF_RXRPC 33 | ||
| 148 | #define PF_ISDN 34 | ||
| 149 | #define PF_PHONET 35 | ||
| 150 | #define PF_IEEE802154 36 | ||
| 151 | #define PF_CAIF 37 | ||
| 152 | #define PF_ALG 38 | ||
| 153 | #define PF_NFC 39 | ||
| 154 | #define PF_VSOCK 40 | ||
| 155 | #define PF_KCM 41 | ||
| 156 | #define PF_QIPCRTR 42 | ||
| 157 | #define PF_SMC 43 | ||
| 158 | #define PF_XDP 44 | ||
| 159 | #define PF_MAX 45 | ||
| 160 | |||
| 161 | #define AF_UNSPEC PF_UNSPEC | ||
| 162 | #define AF_LOCAL PF_LOCAL | ||
| 163 | #define AF_UNIX AF_LOCAL | ||
| 164 | #define AF_FILE AF_LOCAL | ||
| 165 | #define AF_INET PF_INET | ||
| 166 | #define AF_AX25 PF_AX25 | ||
| 167 | #define AF_IPX PF_IPX | ||
| 168 | #define AF_APPLETALK PF_APPLETALK | ||
| 169 | #define AF_NETROM PF_NETROM | ||
| 170 | #define AF_BRIDGE PF_BRIDGE | ||
| 171 | #define AF_ATMPVC PF_ATMPVC | ||
| 172 | #define AF_X25 PF_X25 | ||
| 173 | #define AF_INET6 PF_INET6 | ||
| 174 | #define AF_ROSE PF_ROSE | ||
| 175 | #define AF_DECnet PF_DECnet | ||
| 176 | #define AF_NETBEUI PF_NETBEUI | ||
| 177 | #define AF_SECURITY PF_SECURITY | ||
| 178 | #define AF_KEY PF_KEY | ||
| 179 | #define AF_NETLINK PF_NETLINK | ||
| 180 | #define AF_ROUTE PF_ROUTE | ||
| 181 | #define AF_PACKET PF_PACKET | ||
| 182 | #define AF_ASH PF_ASH | ||
| 183 | #define AF_ECONET PF_ECONET | ||
| 184 | #define AF_ATMSVC PF_ATMSVC | ||
| 185 | #define AF_RDS PF_RDS | ||
| 186 | #define AF_SNA PF_SNA | ||
| 187 | #define AF_IRDA PF_IRDA | ||
| 188 | #define AF_PPPOX PF_PPPOX | ||
| 189 | #define AF_WANPIPE PF_WANPIPE | ||
| 190 | #define AF_LLC PF_LLC | ||
| 191 | #define AF_IB PF_IB | ||
| 192 | #define AF_MPLS PF_MPLS | ||
| 193 | #define AF_CAN PF_CAN | ||
| 194 | #define AF_TIPC PF_TIPC | ||
| 195 | #define AF_BLUETOOTH PF_BLUETOOTH | ||
| 196 | #define AF_IUCV PF_IUCV | ||
| 197 | #define AF_RXRPC PF_RXRPC | ||
| 198 | #define AF_ISDN PF_ISDN | ||
| 199 | #define AF_PHONET PF_PHONET | ||
| 200 | #define AF_IEEE802154 PF_IEEE802154 | ||
| 201 | #define AF_CAIF PF_CAIF | ||
| 202 | #define AF_ALG PF_ALG | ||
| 203 | #define AF_NFC PF_NFC | ||
| 204 | #define AF_VSOCK PF_VSOCK | ||
| 205 | #define AF_KCM PF_KCM | ||
| 206 | #define AF_QIPCRTR PF_QIPCRTR | ||
| 207 | #define AF_SMC PF_SMC | ||
| 208 | #define AF_XDP PF_XDP | ||
| 209 | #define AF_MAX PF_MAX | ||
| 210 | |||
| 211 | #ifndef SO_DEBUG | ||
| 212 | #define SO_DEBUG 1 | ||
| 213 | #define SO_REUSEADDR 2 | ||
| 214 | #define SO_TYPE 3 | ||
| 215 | #define SO_ERROR 4 | ||
| 216 | #define SO_DONTROUTE 5 | ||
| 217 | #define SO_BROADCAST 6 | ||
| 218 | #define SO_SNDBUF 7 | ||
| 219 | #define SO_RCVBUF 8 | ||
| 220 | #define SO_KEEPALIVE 9 | ||
| 221 | #define SO_OOBINLINE 10 | ||
| 222 | #define SO_NO_CHECK 11 | ||
| 223 | #define SO_PRIORITY 12 | ||
| 224 | #define SO_LINGER 13 | ||
| 225 | #define SO_BSDCOMPAT 14 | ||
| 226 | #define SO_REUSEPORT 15 | ||
| 227 | #define SO_PASSCRED 16 | ||
| 228 | #define SO_PEERCRED 17 | ||
| 229 | #define SO_RCVLOWAT 18 | ||
| 230 | #define SO_SNDLOWAT 19 | ||
| 231 | #define SO_ACCEPTCONN 30 | ||
| 232 | #define SO_PEERSEC 31 | ||
| 233 | #define SO_SNDBUFFORCE 32 | ||
| 234 | #define SO_RCVBUFFORCE 33 | ||
| 235 | #define SO_PROTOCOL 38 | ||
| 236 | #define SO_DOMAIN 39 | ||
| 237 | #endif | ||
| 238 | |||
| 239 | #ifndef SO_RCVTIMEO | ||
| 240 | #if __LONG_MAX == 0x7fffffff | ||
| 241 | #define SO_RCVTIMEO 66 | ||
| 242 | #define SO_SNDTIMEO 67 | ||
| 243 | #else | ||
| 244 | #define SO_RCVTIMEO 20 | ||
| 245 | #define SO_SNDTIMEO 21 | ||
| 246 | #endif | ||
| 247 | #endif | ||
| 248 | |||
| 249 | #ifndef SO_TIMESTAMP | ||
| 250 | #if __LONG_MAX == 0x7fffffff | ||
| 251 | #define SO_TIMESTAMP 63 | ||
| 252 | #define SO_TIMESTAMPNS 64 | ||
| 253 | #define SO_TIMESTAMPING 65 | ||
| 254 | #else | ||
| 255 | #define SO_TIMESTAMP 29 | ||
| 256 | #define SO_TIMESTAMPNS 35 | ||
| 257 | #define SO_TIMESTAMPING 37 | ||
| 258 | #endif | ||
| 259 | #endif | ||
| 260 | |||
| 261 | #define SO_SECURITY_AUTHENTICATION 22 | ||
| 262 | #define SO_SECURITY_ENCRYPTION_TRANSPORT 23 | ||
| 263 | #define SO_SECURITY_ENCRYPTION_NETWORK 24 | ||
| 264 | |||
| 265 | #define SO_BINDTODEVICE 25 | ||
| 266 | |||
| 267 | #define SO_ATTACH_FILTER 26 | ||
| 268 | #define SO_DETACH_FILTER 27 | ||
| 269 | #define SO_GET_FILTER SO_ATTACH_FILTER | ||
| 270 | |||
| 271 | #define SO_PEERNAME 28 | ||
| 272 | #define SCM_TIMESTAMP SO_TIMESTAMP | ||
| 273 | #define SO_PASSSEC 34 | ||
| 274 | #define SCM_TIMESTAMPNS SO_TIMESTAMPNS | ||
| 275 | #define SO_MARK 36 | ||
| 276 | #define SCM_TIMESTAMPING SO_TIMESTAMPING | ||
| 277 | #define SO_RXQ_OVFL 40 | ||
| 278 | #define SO_WIFI_STATUS 41 | ||
| 279 | #define SCM_WIFI_STATUS SO_WIFI_STATUS | ||
| 280 | #define SO_PEEK_OFF 42 | ||
| 281 | #define SO_NOFCS 43 | ||
| 282 | #define SO_LOCK_FILTER 44 | ||
| 283 | #define SO_SELECT_ERR_QUEUE 45 | ||
| 284 | #define SO_BUSY_POLL 46 | ||
| 285 | #define SO_MAX_PACING_RATE 47 | ||
| 286 | #define SO_BPF_EXTENSIONS 48 | ||
| 287 | #define SO_INCOMING_CPU 49 | ||
| 288 | #define SO_ATTACH_BPF 50 | ||
| 289 | #define SO_DETACH_BPF SO_DETACH_FILTER | ||
| 290 | #define SO_ATTACH_REUSEPORT_CBPF 51 | ||
| 291 | #define SO_ATTACH_REUSEPORT_EBPF 52 | ||
| 292 | #define SO_CNX_ADVICE 53 | ||
| 293 | #define SCM_TIMESTAMPING_OPT_STATS 54 | ||
| 294 | #define SO_MEMINFO 55 | ||
| 295 | #define SO_INCOMING_NAPI_ID 56 | ||
| 296 | #define SO_COOKIE 57 | ||
| 297 | #define SCM_TIMESTAMPING_PKTINFO 58 | ||
| 298 | #define SO_PEERGROUPS 59 | ||
| 299 | #define SO_ZEROCOPY 60 | ||
| 300 | #define SO_TXTIME 61 | ||
| 301 | #define SCM_TXTIME SO_TXTIME | ||
| 302 | #define SO_BINDTOIFINDEX 62 | ||
| 303 | #define SO_DETACH_REUSEPORT_BPF 68 | ||
| 304 | #define SO_PREFER_BUSY_POLL 69 | ||
| 305 | #define SO_BUSY_POLL_BUDGET 70 | ||
| 306 | |||
| 307 | #ifndef SOL_SOCKET | ||
| 308 | #define SOL_SOCKET 1 | ||
| 309 | #endif | ||
| 310 | |||
| 311 | #define SOL_IP 0 | ||
| 312 | #define SOL_IPV6 41 | ||
| 313 | #define SOL_ICMPV6 58 | ||
| 314 | |||
| 315 | #define SOL_RAW 255 | ||
| 316 | #define SOL_DECNET 261 | ||
| 317 | #define SOL_X25 262 | ||
| 318 | #define SOL_PACKET 263 | ||
| 319 | #define SOL_ATM 264 | ||
| 320 | #define SOL_AAL 265 | ||
| 321 | #define SOL_IRDA 266 | ||
| 322 | #define SOL_NETBEUI 267 | ||
| 323 | #define SOL_LLC 268 | ||
| 324 | #define SOL_DCCP 269 | ||
| 325 | #define SOL_NETLINK 270 | ||
| 326 | #define SOL_TIPC 271 | ||
| 327 | #define SOL_RXRPC 272 | ||
| 328 | #define SOL_PPPOL2TP 273 | ||
| 329 | #define SOL_BLUETOOTH 274 | ||
| 330 | #define SOL_PNPIPE 275 | ||
| 331 | #define SOL_RDS 276 | ||
| 332 | #define SOL_IUCV 277 | ||
| 333 | #define SOL_CAIF 278 | ||
| 334 | #define SOL_ALG 279 | ||
| 335 | #define SOL_NFC 280 | ||
| 336 | #define SOL_KCM 281 | ||
| 337 | #define SOL_TLS 282 | ||
| 338 | #define SOL_XDP 283 | ||
| 339 | |||
| 340 | #define SOMAXCONN 128 | ||
| 341 | |||
| 342 | #define MSG_OOB 0x0001 | ||
| 343 | #define MSG_PEEK 0x0002 | ||
| 344 | #define MSG_DONTROUTE 0x0004 | ||
| 345 | #define MSG_CTRUNC 0x0008 | ||
| 346 | #define MSG_PROXY 0x0010 | ||
| 347 | #define MSG_TRUNC 0x0020 | ||
| 348 | #define MSG_DONTWAIT 0x0040 | ||
| 349 | #define MSG_EOR 0x0080 | ||
| 350 | #define MSG_WAITALL 0x0100 | ||
| 351 | #define MSG_FIN 0x0200 | ||
| 352 | #define MSG_SYN 0x0400 | ||
| 353 | #define MSG_CONFIRM 0x0800 | ||
| 354 | #define MSG_RST 0x1000 | ||
| 355 | #define MSG_ERRQUEUE 0x2000 | ||
| 356 | #define MSG_NOSIGNAL 0x4000 | ||
| 357 | #define MSG_MORE 0x8000 | ||
| 358 | #define MSG_WAITFORONE 0x10000 | ||
| 359 | #define MSG_BATCH 0x40000 | ||
| 360 | #define MSG_ZEROCOPY 0x4000000 | ||
| 361 | #define MSG_FASTOPEN 0x20000000 | ||
| 362 | #define MSG_CMSG_CLOEXEC 0x40000000 | ||
| 363 | |||
| 364 | #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) | ||
| 365 | #define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) | ||
| 366 | #define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) | ||
| 367 | |||
| 368 | #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) | ||
| 369 | #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ | ||
| 370 | 	__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ | ||
| 371 | 	? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) | ||
| 372 | #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) | ||
| 373 | |||
| 374 | #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) | ||
| 375 | #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) | ||
| 376 | #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) | ||
| 377 | |||
| 378 | #define SCM_RIGHTS 0x01 | ||
| 379 | #define SCM_CREDENTIALS 0x02 | ||
| 380 | #endif | ||
| 381 | |||
| 382 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 383 | struct sockaddr { | ||
| 384 | 	sa_family_t sa_family; | ||
| 385 | 	char sa_data[14]; | ||
| 386 | }; | ||
| 387 | #else | ||
| 388 | #include <__struct_sockaddr.h> | ||
| 389 | #endif | ||
| 390 | |||
| 391 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 392 | struct sockaddr_storage { | ||
| 393 | 	sa_family_t ss_family; | ||
| 394 | 	char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; | ||
| 395 | 	unsigned long __ss_align; | ||
| 396 | }; | ||
| 397 | #else | ||
| 398 | #include <__struct_sockaddr_storage.h> | ||
| 399 | #endif | ||
| 400 | |||
| 401 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 402 | int socket (int, int, int); | ||
| 403 | #endif | ||
| 404 | |||
| 405 | #ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */ | ||
| 406 | int socketpair (int, int, int, int [2]); | ||
| 407 | #endif | ||
| 408 | |||
| 409 | int shutdown (int, int); | ||
| 410 | |||
| 411 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 412 | int connect (int, const struct sockaddr *, socklen_t); | ||
| 413 | int bind (int, const struct sockaddr *, socklen_t); | ||
| 414 | int listen (int, int); | ||
| 415 | #endif | ||
| 416 | |||
| 417 | int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 418 | int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); | ||
| 419 | |||
| 420 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 421 | int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 422 | int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 423 | #endif | ||
| 424 | |||
| 425 | ssize_t send (int, const void *, size_t, int); | ||
| 426 | ssize_t recv (int, void *, size_t, int); | ||
| 427 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 428 | ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); | ||
| 429 | ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 430 | #endif | ||
| 431 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ | ||
| 432 | ssize_t sendmsg (int, const struct msghdr *, int); | ||
| 433 | ssize_t recvmsg (int, struct msghdr *, int); | ||
| 434 | #endif | ||
| 435 | |||
| 436 | int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); | ||
| 437 | #if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2) | ||
| 438 | int setsockopt (int, int, int, const void *, socklen_t); | ||
| 439 | #endif | ||
| 440 | |||
| 441 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ | ||
| 442 | int sockatmark (int); | ||
| 443 | #endif | ||
| 444 | |||
| 445 | #if _REDIR_TIME64 | ||
| 446 | #ifdef _GNU_SOURCE | ||
| 447 | __REDIR(recvmmsg, __recvmmsg_time64); | ||
| 448 | #endif | ||
| 449 | #endif | ||
| 450 | |||
| 451 | #ifdef __cplusplus | ||
| 452 | } | ||
| 453 | #endif | ||
| 454 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/stat.h deleted-198| ... | @@ -1,198 +0,0 @@ | ||
| 1 | #ifndef	_SYS_STAT_H | ||
| 2 | #define	_SYS_STAT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_dev_t | ||
| 10 | #define __NEED_ino_t | ||
| 11 | #define __NEED_mode_t | ||
| 12 | #define __NEED_nlink_t | ||
| 13 | #define __NEED_uid_t | ||
| 14 | #define __NEED_gid_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | #define __NEED_time_t | ||
| 17 | #define __NEED_blksize_t | ||
| 18 | #define __NEED_blkcnt_t | ||
| 19 | #define __NEED_struct_timespec | ||
| 20 | |||
| 21 | #ifdef _GNU_SOURCE | ||
| 22 | #define __NEED_int64_t | ||
| 23 | #define __NEED_uint64_t | ||
| 24 | #define __NEED_uint32_t | ||
| 25 | #define __NEED_uint16_t | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #include <bits/alltypes.h> | ||
| 29 | |||
| 30 | #include <bits/stat.h> | ||
| 31 | |||
| 32 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 33 | #define st_atime st_atim.tv_sec | ||
| 34 | #define st_mtime st_mtim.tv_sec | ||
| 35 | #define st_ctime st_ctim.tv_sec | ||
| 36 | |||
| 37 | #define S_IFMT 0170000 | ||
| 38 | |||
| 39 | #define S_IFDIR 0040000 | ||
| 40 | #define S_IFCHR 0020000 | ||
| 41 | #define S_IFBLK 0060000 | ||
| 42 | #define S_IFREG 0100000 | ||
| 43 | #define S_IFIFO 0010000 | ||
| 44 | #define S_IFLNK 0120000 | ||
| 45 | #define S_IFSOCK 0140000 | ||
| 46 | |||
| 47 | #define S_TYPEISMQ(buf) 0 | ||
| 48 | #define S_TYPEISSEM(buf) 0 | ||
| 49 | #define S_TYPEISSHM(buf) 0 | ||
| 50 | #define S_TYPEISTMO(buf) 0 | ||
| 51 | |||
| 52 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | ||
| 53 | #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) | ||
| 54 | #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) | ||
| 55 | #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) | ||
| 56 | #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) | ||
| 57 | #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) | ||
| 58 | #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) | ||
| 59 | |||
| 60 | #ifndef S_IRUSR | ||
| 61 | #define S_ISUID 04000 | ||
| 62 | #define S_ISGID 02000 | ||
| 63 | #define S_ISVTX 01000 | ||
| 64 | #define S_IRUSR 0400 | ||
| 65 | #define S_IWUSR 0200 | ||
| 66 | #define S_IXUSR 0100 | ||
| 67 | #define S_IRWXU 0700 | ||
| 68 | #define S_IRGRP 0040 | ||
| 69 | #define S_IWGRP 0020 | ||
| 70 | #define S_IXGRP 0010 | ||
| 71 | #define S_IRWXG 0070 | ||
| 72 | #define S_IROTH 0004 | ||
| 73 | #define S_IWOTH 0002 | ||
| 74 | #define S_IXOTH 0001 | ||
| 75 | #define S_IRWXO 0007 | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #define UTIME_NOW 0x3fffffff | ||
| 79 | #define UTIME_OMIT 0x3ffffffe | ||
| 80 | #else | ||
| 81 | #include <__header_sys_stat.h> | ||
| 82 | #endif | ||
| 83 | |||
| 84 | int stat(const char *__restrict, struct stat *__restrict); | ||
| 85 | int fstat(int, struct stat *); | ||
| 86 | int lstat(const char *__restrict, struct stat *__restrict); | ||
| 87 | int fstatat(int, const char *__restrict, struct stat *__restrict, int); | ||
| 88 | int chmod(const char *, mode_t); | ||
| 89 | int fchmod(int, mode_t); | ||
| 90 | int fchmodat(int, const char *, mode_t, int); | ||
| 91 | #ifdef __wasilibc_unmodified_upstream /* WASI has no umask */ | ||
| 92 | mode_t umask(mode_t); | ||
| 93 | #endif | ||
| 94 | int mkdir(const char *, mode_t); | ||
| 95 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 96 | int mkfifo(const char *, mode_t); | ||
| 97 | #endif | ||
| 98 | int mkdirat(int, const char *, mode_t); | ||
| 99 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 100 | int mkfifoat(int, const char *, mode_t); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mknod */ | ||
| 104 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 105 | int mknod(const char *, mode_t, dev_t); | ||
| 106 | int mknodat(int, const char *, mode_t, dev_t); | ||
| 107 | #endif | ||
| 108 | #endif | ||
| 109 | |||
| 110 | int futimens(int, const struct timespec [2]); | ||
| 111 | int utimensat(int, const char *, const struct timespec [2], int); | ||
| 112 | |||
| 113 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 114 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ | ||
| 115 | int lchmod(const char *, mode_t); | ||
| 116 | #endif | ||
| 117 | #define S_IREAD S_IRUSR | ||
| 118 | #define S_IWRITE S_IWUSR | ||
| 119 | #define S_IEXEC S_IXUSR | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifdef __wasilibc_unmodified_upstream /* WASI has no statx */ | ||
| 123 | #if defined(_GNU_SOURCE) | ||
| 124 | #define STATX_TYPE 1U | ||
| 125 | #define STATX_MODE 2U | ||
| 126 | #define STATX_NLINK 4U | ||
| 127 | #define STATX_UID 8U | ||
| 128 | #define STATX_GID 0x10U | ||
| 129 | #define STATX_ATIME 0x20U | ||
| 130 | #define STATX_MTIME 0x40U | ||
| 131 | #define STATX_CTIME 0x80U | ||
| 132 | #define STATX_INO 0x100U | ||
| 133 | #define STATX_SIZE 0x200U | ||
| 134 | #define STATX_BLOCKS 0x400U | ||
| 135 | #define STATX_BASIC_STATS 0x7ffU | ||
| 136 | #define STATX_BTIME 0x800U | ||
| 137 | #define STATX_ALL 0xfffU | ||
| 138 | |||
| 139 | struct statx_timestamp { | ||
| 140 | 	int64_t tv_sec; | ||
| 141 | 	uint32_t tv_nsec, __pad; | ||
| 142 | }; | ||
| 143 | |||
| 144 | struct statx { | ||
| 145 | 	uint32_t stx_mask; | ||
| 146 | 	uint32_t stx_blksize; | ||
| 147 | 	uint64_t stx_attributes; | ||
| 148 | 	uint32_t stx_nlink; | ||
| 149 | 	uint32_t stx_uid; | ||
| 150 | 	uint32_t stx_gid; | ||
| 151 | 	uint16_t stx_mode; | ||
| 152 | 	uint16_t __pad0[1]; | ||
| 153 | 	uint64_t stx_ino; | ||
| 154 | 	uint64_t stx_size; | ||
| 155 | 	uint64_t stx_blocks; | ||
| 156 | 	uint64_t stx_attributes_mask; | ||
| 157 | 	struct statx_timestamp stx_atime; | ||
| 158 | 	struct statx_timestamp stx_btime; | ||
| 159 | 	struct statx_timestamp stx_ctime; | ||
| 160 | 	struct statx_timestamp stx_mtime; | ||
| 161 | 	uint32_t stx_rdev_major; | ||
| 162 | 	uint32_t stx_rdev_minor; | ||
| 163 | 	uint32_t stx_dev_major; | ||
| 164 | 	uint32_t stx_dev_minor; | ||
| 165 | 	uint64_t __pad1[14]; | ||
| 166 | }; | ||
| 167 | |||
| 168 | int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict); | ||
| 169 | #endif | ||
| 170 | #endif | ||
| 171 | |||
| 172 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 173 | #define stat64 stat | ||
| 174 | #define fstat64 fstat | ||
| 175 | #define lstat64 lstat | ||
| 176 | #define fstatat64 fstatat | ||
| 177 | #define blkcnt64_t blkcnt_t | ||
| 178 | #define fsblkcnt64_t fsblkcnt_t | ||
| 179 | #define fsfilcnt64_t fsfilcnt_t | ||
| 180 | #define ino64_t ino_t | ||
| 181 | #define off64_t off_t | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #if _REDIR_TIME64 | ||
| 185 | __REDIR(stat, __stat_time64); | ||
| 186 | __REDIR(fstat, __fstat_time64); | ||
| 187 | __REDIR(lstat, __lstat_time64); | ||
| 188 | __REDIR(fstatat, __fstatat_time64); | ||
| 189 | __REDIR(futimens, __futimens_time64); | ||
| 190 | __REDIR(utimensat, __utimensat_time64); | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #ifdef __cplusplus | ||
| 194 | } | ||
| 195 | #endif | ||
| 196 | #endif | ||
| 197 | |||
| 198 | |||
lib/libc/wasi/libc-top-half/musl/include/sys/statfs.h deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #ifndef	_SYS_STATFS_H | ||
| 2 | #define	_SYS_STATFS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #include <sys/statvfs.h> | ||
| 11 | |||
| 12 | typedef struct __fsid_t { | ||
| 13 | 	int __val[2]; | ||
| 14 | } fsid_t; | ||
| 15 | |||
| 16 | #include <bits/statfs.h> | ||
| 17 | |||
| 18 | int statfs (const char *, struct statfs *); | ||
| 19 | int fstatfs (int, struct statfs *); | ||
| 20 | |||
| 21 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 22 | #define statfs64 statfs | ||
| 23 | #define fstatfs64 fstatfs | ||
| 24 | #define fsblkcnt64_t fsblkcnt_t | ||
| 25 | #define fsfilcnt64_t fsfilcnt_t | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #ifdef __cplusplus | ||
| 29 | } | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/statvfs.h deleted-57| ... | @@ -1,57 +0,0 @@ | ||
| 1 | #ifndef	_SYS_STATVFS_H | ||
| 2 | #define	_SYS_STATVFS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_fsblkcnt_t | ||
| 11 | #define __NEED_fsfilcnt_t | ||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | struct statvfs { | ||
| 15 | 	unsigned long f_bsize, f_frsize; | ||
| 16 | 	fsblkcnt_t f_blocks, f_bfree, f_bavail; | ||
| 17 | 	fsfilcnt_t f_files, f_ffree, f_favail; | ||
| 18 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 19 | 	unsigned long f_fsid; | ||
| 20 | 	unsigned :8*(2*sizeof(int)-sizeof(long)); | ||
| 21 | #else | ||
| 22 | 	unsigned :8*(2*sizeof(int)-sizeof(long)); | ||
| 23 | 	unsigned long f_fsid; | ||
| 24 | #endif | ||
| 25 | 	unsigned long f_flag, f_namemax; | ||
| 26 | 	unsigned int f_type; | ||
| 27 | 	int __reserved[5]; | ||
| 28 | }; | ||
| 29 | |||
| 30 | int statvfs (const char *__restrict, struct statvfs *__restrict); | ||
| 31 | int fstatvfs (int, struct statvfs *); | ||
| 32 | |||
| 33 | #define ST_RDONLY 1 | ||
| 34 | #define ST_NOSUID 2 | ||
| 35 | #define ST_NODEV 4 | ||
| 36 | #define ST_NOEXEC 8 | ||
| 37 | #define ST_SYNCHRONOUS 16 | ||
| 38 | #define ST_MANDLOCK 64 | ||
| 39 | #define ST_WRITE 128 | ||
| 40 | #define ST_APPEND 256 | ||
| 41 | #define ST_IMMUTABLE 512 | ||
| 42 | #define ST_NOATIME 1024 | ||
| 43 | #define ST_NODIRATIME 2048 | ||
| 44 | #define ST_RELATIME 4096 | ||
| 45 | |||
| 46 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 47 | #define statvfs64 statvfs | ||
| 48 | #define fstatvfs64 fstatvfs | ||
| 49 | #define fsblkcnt64_t fsblkcnt_t | ||
| 50 | #define fsfilcnt64_t fsfilcnt_t | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #ifdef __cplusplus | ||
| 54 | } | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/syscall.h deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #ifndef _SYS_SYSCALL_H | ||
| 2 | #define _SYS_SYSCALL_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syscall */ | ||
| 5 | #include <bits/syscall.h> | ||
| 6 | #else | ||
| 7 | /* The generic syscall funtion is not yet implemented. */ | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/time.h deleted-84| ... | @@ -1,84 +0,0 @@ | ||
| 1 | #ifndef _SYS_TIME_H | ||
| 2 | #define _SYS_TIME_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #include <sys/select.h> | ||
| 10 | |||
| 11 | int gettimeofday (struct timeval *__restrict, void *__restrict); | ||
| 12 | |||
| 13 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getitimer */ | ||
| 14 | #define ITIMER_REAL 0 | ||
| 15 | #define ITIMER_VIRTUAL 1 | ||
| 16 | #define ITIMER_PROF 2 | ||
| 17 | |||
| 18 | struct itimerval { | ||
| 19 | 	struct timeval it_interval; | ||
| 20 | 	struct timeval it_value; | ||
| 21 | }; | ||
| 22 | |||
| 23 | int getitimer (int, struct itimerval *); | ||
| 24 | int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict); | ||
| 25 | #endif | ||
| 26 | int utimes (const char *, const struct timeval [2]); | ||
| 27 | |||
| 28 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 29 | struct timezone { | ||
| 30 | 	int tz_minuteswest; | ||
| 31 | 	int tz_dsttime; | ||
| 32 | }; | ||
| 33 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 34 | int futimes(int, const struct timeval [2]); | ||
| 35 | #endif | ||
| 36 | int futimesat(int, const char *, const struct timeval [2]); | ||
| 37 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 38 | int lutimes(const char *, const struct timeval [2]); | ||
| 39 | #endif | ||
| 40 | #ifdef __wasilibc_unmodified_upstream /* WASI has no way to set the time */ | ||
| 41 | int settimeofday(const struct timeval *, const struct timezone *); | ||
| 42 | int adjtime (const struct timeval *, struct timeval *); | ||
| 43 | #endif | ||
| 44 | #define timerisset(t) ((t)->tv_sec || (t)->tv_usec) | ||
| 45 | #define timerclear(t) ((t)->tv_sec = (t)->tv_usec = 0) | ||
| 46 | #define timercmp(s,t,op) ((s)->tv_sec == (t)->tv_sec ? \ | ||
| 47 | 	(s)->tv_usec op (t)->tv_usec : (s)->tv_sec op (t)->tv_sec) | ||
| 48 | #define timeradd(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec + (t)->tv_sec, \ | ||
| 49 | 	((a)->tv_usec = (s)->tv_usec + (t)->tv_usec) >= 1000000 && \ | ||
| 50 | 	((a)->tv_usec -= 1000000, (a)->tv_sec++) ) | ||
| 51 | #define timersub(s,t,a) (void) ( (a)->tv_sec = (s)->tv_sec - (t)->tv_sec, \ | ||
| 52 | 	((a)->tv_usec = (s)->tv_usec - (t)->tv_usec) < 0 && \ | ||
| 53 | 	((a)->tv_usec += 1000000, (a)->tv_sec--) ) | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #if defined(_GNU_SOURCE) | ||
| 57 | #define TIMEVAL_TO_TIMESPEC(tv, ts) ( \ | ||
| 58 | 	(ts)->tv_sec = (tv)->tv_sec, \ | ||
| 59 | 	(ts)->tv_nsec = (tv)->tv_usec * 1000, \ | ||
| 60 | 	(void)0 ) | ||
| 61 | #define TIMESPEC_TO_TIMEVAL(tv, ts) ( \ | ||
| 62 | 	(tv)->tv_sec = (ts)->tv_sec, \ | ||
| 63 | 	(tv)->tv_usec = (ts)->tv_nsec / 1000, \ | ||
| 64 | 	(void)0 ) | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #if _REDIR_TIME64 | ||
| 68 | __REDIR(gettimeofday, __gettimeofday_time64); | ||
| 69 | __REDIR(getitimer, __getitimer_time64); | ||
| 70 | __REDIR(setitimer, __setitimer_time64); | ||
| 71 | __REDIR(utimes, __utimes_time64); | ||
| 72 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 73 | __REDIR(futimes, __futimes_time64); | ||
| 74 | __REDIR(futimesat, __futimesat_time64); | ||
| 75 | __REDIR(lutimes, __lutimes_time64); | ||
| 76 | __REDIR(settimeofday, __settimeofday_time64); | ||
| 77 | __REDIR(adjtime, __adjtime64); | ||
| 78 | #endif | ||
| 79 | #endif | ||
| 80 | |||
| 81 | #ifdef __cplusplus | ||
| 82 | } | ||
| 83 | #endif | ||
| 84 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/times.h deleted-34| ... | @@ -1,34 +0,0 @@ | ||
| 1 | #ifndef _WASI_EMULATED_PROCESS_CLOCKS | ||
| 2 | #error WASI lacks process-associated clocks; to enable emulation of the `times` function using \ | ||
| 3 | the wall clock, which isn't sensitive to whether the program is running or suspended, \ | ||
| 4 | compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks | ||
| 5 | #else | ||
| 6 | #ifndef	_SYS_TIMES_H | ||
| 7 | #define	_SYS_TIMES_H | ||
| 8 | |||
| 9 | #ifdef __cplusplus | ||
| 10 | extern "C" { | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #define __NEED_clock_t | ||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 17 | struct tms { | ||
| 18 | 	clock_t tms_utime; | ||
| 19 | 	clock_t tms_stime; | ||
| 20 | 	clock_t tms_cutime; | ||
| 21 | 	clock_t tms_cstime; | ||
| 22 | }; | ||
| 23 | #else | ||
| 24 | #include <__struct_tms.h> | ||
| 25 | #endif | ||
| 26 | |||
| 27 | clock_t times (struct tms *); | ||
| 28 | |||
| 29 | #ifdef __cplusplus | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #endif | ||
| 34 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/types.h deleted-85| ... | @@ -1,85 +0,0 @@ | ||
| 1 | #ifndef	_SYS_TYPES_H | ||
| 2 | #define	_SYS_TYPES_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_ino_t | ||
| 10 | #define __NEED_dev_t | ||
| 11 | #define __NEED_uid_t | ||
| 12 | #define __NEED_gid_t | ||
| 13 | #define __NEED_mode_t | ||
| 14 | #define __NEED_nlink_t | ||
| 15 | #define __NEED_off_t | ||
| 16 | #define __NEED_pid_t | ||
| 17 | #define __NEED_size_t | ||
| 18 | #define __NEED_ssize_t | ||
| 19 | #define __NEED_time_t | ||
| 20 | #define __NEED_timer_t | ||
| 21 | #define __NEED_clockid_t | ||
| 22 | |||
| 23 | #define __NEED_blkcnt_t | ||
| 24 | #define __NEED_fsblkcnt_t | ||
| 25 | #define __NEED_fsfilcnt_t | ||
| 26 | |||
| 27 | #define __NEED_id_t | ||
| 28 | #define __NEED_key_t | ||
| 29 | #define __NEED_clock_t | ||
| 30 | #define __NEED_suseconds_t | ||
| 31 | #define __NEED_blksize_t | ||
| 32 | |||
| 33 | #define __NEED_pthread_t | ||
| 34 | #define __NEED_pthread_attr_t | ||
| 35 | #define __NEED_pthread_mutexattr_t | ||
| 36 | #define __NEED_pthread_condattr_t | ||
| 37 | #define __NEED_pthread_rwlockattr_t | ||
| 38 | #define __NEED_pthread_barrierattr_t | ||
| 39 | #define __NEED_pthread_mutex_t | ||
| 40 | #define __NEED_pthread_cond_t | ||
| 41 | #define __NEED_pthread_rwlock_t | ||
| 42 | #define __NEED_pthread_barrier_t | ||
| 43 | #define __NEED_pthread_spinlock_t | ||
| 44 | #define __NEED_pthread_key_t | ||
| 45 | #define __NEED_pthread_once_t | ||
| 46 | #define __NEED_useconds_t | ||
| 47 | |||
| 48 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 49 | #define __NEED_int8_t | ||
| 50 | #define __NEED_int16_t | ||
| 51 | #define __NEED_int32_t | ||
| 52 | #define __NEED_int64_t | ||
| 53 | #define __NEED_u_int64_t | ||
| 54 | #define __NEED_register_t | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #include <bits/alltypes.h> | ||
| 58 | |||
| 59 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 60 | typedef unsigned char u_int8_t; | ||
| 61 | typedef unsigned short u_int16_t; | ||
| 62 | typedef unsigned u_int32_t; | ||
| 63 | typedef char *caddr_t; | ||
| 64 | typedef unsigned char u_char; | ||
| 65 | typedef unsigned short u_short, ushort; | ||
| 66 | typedef unsigned u_int, uint; | ||
| 67 | typedef unsigned long u_long, ulong; | ||
| 68 | typedef long long quad_t; | ||
| 69 | typedef unsigned long long u_quad_t; | ||
| 70 | #include <endian.h> | ||
| 71 | #include <sys/select.h> | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 75 | #define blkcnt64_t blkcnt_t | ||
| 76 | #define fsblkcnt64_t fsblkcnt_t | ||
| 77 | #define fsfilcnt64_t fsfilcnt_t | ||
| 78 | #define ino64_t ino_t | ||
| 79 | #define off64_t off_t | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #ifdef __cplusplus | ||
| 83 | } | ||
| 84 | #endif | ||
| 85 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/uio.h deleted-57| ... | @@ -1,57 +0,0 @@ | ||
| 1 | #ifndef _SYS_UIO_H | ||
| 2 | #define _SYS_UIO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | #define __NEED_ssize_t | ||
| 12 | #define __NEED_struct_iovec | ||
| 13 | |||
| 14 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 15 | #define __NEED_off_t | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __NEED_pid_t | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #include <bits/alltypes.h> | ||
| 23 | |||
| 24 | #define UIO_MAXIOV 1024 | ||
| 25 | |||
| 26 | ssize_t readv (int, const struct iovec *, int); | ||
| 27 | ssize_t writev (int, const struct iovec *, int); | ||
| 28 | |||
| 29 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 30 | ssize_t preadv (int, const struct iovec *, int, off_t); | ||
| 31 | ssize_t pwritev (int, const struct iovec *, int, off_t); | ||
| 32 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 33 | #define preadv64 preadv | ||
| 34 | #define pwritev64 pwritev | ||
| 35 | #define off64_t off_t | ||
| 36 | #endif | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have these Linux-specific functions | ||
| 40 | #ifdef _GNU_SOURCE | ||
| 41 | ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 42 | ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 43 | ssize_t preadv2 (int, const struct iovec *, int, off_t, int); | ||
| 44 | ssize_t pwritev2 (int, const struct iovec *, int, off_t, int); | ||
| 45 | #define RWF_HIPRI 0x00000001 | ||
| 46 | #define RWF_DSYNC 0x00000002 | ||
| 47 | #define RWF_SYNC 0x00000004 | ||
| 48 | #define RWF_NOWAIT 0x00000008 | ||
| 49 | #define RWF_APPEND 0x00000010 | ||
| 50 | #endif | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #ifdef __cplusplus | ||
| 54 | } | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/un.h deleted-39| ... | @@ -1,39 +0,0 @@ | ||
| 1 | #ifndef	_SYS_UN_H | ||
| 2 | #define	_SYS_UN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_sa_family_t | ||
| 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 12 | #define __NEED_size_t | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #include <bits/alltypes.h> | ||
| 16 | |||
| 17 | #ifdef __wasilibc_unmodified_upstream /* WASI has no UNIX-domain sockets */ | ||
| 18 | struct sockaddr_un { | ||
| 19 | 	sa_family_t sun_family; | ||
| 20 | 	char sun_path[108]; | ||
| 21 | }; | ||
| 22 | #else | ||
| 23 | #include <__struct_sockaddr_un.h> | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 27 | #ifdef __wasilibc_unmodified_upstream /* Declare strlen with the same attributes as <string.h> uses */ | ||
| 28 | size_t strlen(const char *); | ||
| 29 | #else | ||
| 30 | size_t strlen(const char *) __attribute__((__nothrow__, __leaf__, __pure__, __nonnull__(1))); | ||
| 31 | #endif | ||
| 32 | #define SUN_LEN(s) (2+strlen((s)->sun_path)) | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #ifdef __cplusplus | ||
| 36 | } | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/time.h deleted-204| ... | @@ -1,204 +0,0 @@ | ||
| 1 | #ifndef	_TIME_H | ||
| 2 | #define _TIME_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 11 | #if __cplusplus >= 201103L | ||
| 12 | #define NULL nullptr | ||
| 13 | #elif defined(__cplusplus) | ||
| 14 | #define NULL 0L | ||
| 15 | #else | ||
| 16 | #define NULL ((void*)0) | ||
| 17 | #endif | ||
| 18 | #else | ||
| 19 | #define __need_NULL | ||
| 20 | #include <stddef.h> | ||
| 21 | #endif | ||
| 22 | |||
| 23 | |||
| 24 | #define __NEED_size_t | ||
| 25 | #define __NEED_time_t | ||
| 26 | #define __NEED_clock_t | ||
| 27 | #define __NEED_struct_timespec | ||
| 28 | |||
| 29 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 30 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 31 | || defined(_BSD_SOURCE) | ||
| 32 | #define __NEED_clockid_t | ||
| 33 | #define __NEED_timer_t | ||
| 34 | #define __NEED_pid_t | ||
| 35 | #define __NEED_locale_t | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #include <bits/alltypes.h> | ||
| 39 | |||
| 40 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 41 | #define __tm_gmtoff tm_gmtoff | ||
| 42 | #define __tm_zone tm_zone | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 46 | struct tm { | ||
| 47 | 	int tm_sec; | ||
| 48 | 	int tm_min; | ||
| 49 | 	int tm_hour; | ||
| 50 | 	int tm_mday; | ||
| 51 | 	int tm_mon; | ||
| 52 | 	int tm_year; | ||
| 53 | 	int tm_wday; | ||
| 54 | 	int tm_yday; | ||
| 55 | 	int tm_isdst; | ||
| 56 | 	long __tm_gmtoff; | ||
| 57 | 	const char *__tm_zone; | ||
| 58 | }; | ||
| 59 | #else | ||
| 60 | #include <__header_time.h> | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) | ||
| 64 | clock_t clock (void); | ||
| 65 | #else | ||
| 66 | __attribute__((__deprecated__( | ||
| 67 | "WASI lacks process-associated clocks; to enable emulation of the `clock` function using " | ||
| 68 | "the wall clock, which isn't sensitive to whether the program is running or suspended, " | ||
| 69 | "compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks" | ||
| 70 | ))) | ||
| 71 | clock_t clock (void); | ||
| 72 | #endif | ||
| 73 | time_t time (time_t *); | ||
| 74 | double difftime (time_t, time_t); | ||
| 75 | time_t mktime (struct tm *); | ||
| 76 | size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); | ||
| 77 | struct tm *gmtime (const time_t *); | ||
| 78 | struct tm *localtime (const time_t *); | ||
| 79 | char *asctime (const struct tm *); | ||
| 80 | char *ctime (const time_t *); | ||
| 81 | int timespec_get(struct timespec *, int); | ||
| 82 | |||
| 83 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 84 | #define CLOCKS_PER_SEC 1000000L | ||
| 85 | |||
| 86 | #define TIME_UTC 1 | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 90 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 91 | || defined(_BSD_SOURCE) | ||
| 92 | |||
| 93 | size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); | ||
| 94 | |||
| 95 | struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 96 | struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 97 | char *asctime_r (const struct tm *__restrict, char *__restrict); | ||
| 98 | char *ctime_r (const time_t *, char *); | ||
| 99 | |||
| 100 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 101 | void tzset (void); | ||
| 102 | #endif | ||
| 103 | |||
| 104 | struct itimerspec { | ||
| 105 | 	struct timespec it_interval; | ||
| 106 | 	struct timespec it_value; | ||
| 107 | }; | ||
| 108 | |||
| 109 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 110 | #define CLOCK_REALTIME 0 | ||
| 111 | #define CLOCK_MONOTONIC 1 | ||
| 112 | #define CLOCK_PROCESS_CPUTIME_ID 2 | ||
| 113 | #define CLOCK_THREAD_CPUTIME_ID 3 | ||
| 114 | #define CLOCK_MONOTONIC_RAW 4 | ||
| 115 | #define CLOCK_REALTIME_COARSE 5 | ||
| 116 | #define CLOCK_MONOTONIC_COARSE 6 | ||
| 117 | #define CLOCK_BOOTTIME 7 | ||
| 118 | #define CLOCK_REALTIME_ALARM 8 | ||
| 119 | #define CLOCK_BOOTTIME_ALARM 9 | ||
| 120 | #define CLOCK_SGI_CYCLE 10 | ||
| 121 | #define CLOCK_TAI 11 | ||
| 122 | |||
| 123 | #define TIMER_ABSTIME 1 | ||
| 124 | #endif | ||
| 125 | |||
| 126 | int nanosleep (const struct timespec *, struct timespec *); | ||
| 127 | int clock_getres (clockid_t, struct timespec *); | ||
| 128 | int clock_gettime (clockid_t, struct timespec *); | ||
| 129 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */ | ||
| 130 | int clock_settime (clockid_t, const struct timespec *); | ||
| 131 | #endif | ||
| 132 | int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); | ||
| 133 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */ | ||
| 134 | int clock_getcpuclockid (pid_t, clockid_t *); | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timers */ | ||
| 138 | struct sigevent; | ||
| 139 | int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); | ||
| 140 | int timer_delete (timer_t); | ||
| 141 | int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); | ||
| 142 | int timer_gettime (timer_t, struct itimerspec *); | ||
| 143 | int timer_getoverrun (timer_t); | ||
| 144 | #endif | ||
| 145 | |||
| 146 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 147 | extern char *tzname[2]; | ||
| 148 | #endif | ||
| 149 | |||
| 150 | #endif | ||
| 151 | |||
| 152 | |||
| 153 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 154 | char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); | ||
| 155 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 156 | extern int daylight; | ||
| 157 | extern long timezone; | ||
| 158 | #endif | ||
| 159 | extern int getdate_err; | ||
| 160 | struct tm *getdate (const char *); | ||
| 161 | #endif | ||
| 162 | |||
| 163 | |||
| 164 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 165 | #ifdef __wasilibc_unmodified_upstream /* WASI has no stime */ | ||
| 166 | int stime(const time_t *); | ||
| 167 | #endif | ||
| 168 | time_t timegm(struct tm *); | ||
| 169 | #endif | ||
| 170 | |||
| 171 | #if _REDIR_TIME64 | ||
| 172 | __REDIR(time, __time64); | ||
| 173 | __REDIR(difftime, __difftime64); | ||
| 174 | __REDIR(mktime, __mktime64); | ||
| 175 | __REDIR(gmtime, __gmtime64); | ||
| 176 | __REDIR(localtime, __localtime64); | ||
| 177 | __REDIR(ctime, __ctime64); | ||
| 178 | __REDIR(timespec_get, __timespec_get_time64); | ||
| 179 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 180 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 181 | || defined(_BSD_SOURCE) | ||
| 182 | __REDIR(gmtime_r, __gmtime64_r); | ||
| 183 | __REDIR(localtime_r, __localtime64_r); | ||
| 184 | __REDIR(ctime_r, __ctime64_r); | ||
| 185 | __REDIR(nanosleep, __nanosleep_time64); | ||
| 186 | __REDIR(clock_getres, __clock_getres_time64); | ||
| 187 | __REDIR(clock_gettime, __clock_gettime64); | ||
| 188 | __REDIR(clock_settime, __clock_settime64); | ||
| 189 | __REDIR(clock_nanosleep, __clock_nanosleep_time64); | ||
| 190 | __REDIR(timer_settime, __timer_settime64); | ||
| 191 | __REDIR(timer_gettime, __timer_gettime64); | ||
| 192 | #endif | ||
| 193 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 194 | __REDIR(stime, __stime64); | ||
| 195 | __REDIR(timegm, __timegm_time64); | ||
| 196 | #endif | ||
| 197 | #endif | ||
| 198 | |||
| 199 | #ifdef __cplusplus | ||
| 200 | } | ||
| 201 | #endif | ||
| 202 | |||
| 203 | |||
| 204 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/unistd.h deleted-589| ... | @@ -1,589 +0,0 @@ | ||
| 1 | #ifndef	_UNISTD_H | ||
| 2 | #define	_UNISTD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define STDIN_FILENO 0 | ||
| 11 | #define STDOUT_FILENO 1 | ||
| 12 | #define STDERR_FILENO 2 | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 15 | #define SEEK_SET 0 | ||
| 16 | #define SEEK_CUR 1 | ||
| 17 | #define SEEK_END 2 | ||
| 18 | #define SEEK_DATA 3 | ||
| 19 | #define SEEK_HOLE 4 | ||
| 20 | #else | ||
| 21 | #include <__header_unistd.h> | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 25 | #if __cplusplus >= 201103L | ||
| 26 | #define NULL nullptr | ||
| 27 | #elif defined(__cplusplus) | ||
| 28 | #define NULL 0L | ||
| 29 | #else | ||
| 30 | #define NULL ((void*)0) | ||
| 31 | #endif | ||
| 32 | #else | ||
| 33 | #define __need_NULL | ||
| 34 | #include <stddef.h> | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #define __NEED_size_t | ||
| 38 | #define __NEED_ssize_t | ||
| 39 | #define __NEED_uid_t | ||
| 40 | #define __NEED_gid_t | ||
| 41 | #define __NEED_off_t | ||
| 42 | #define __NEED_pid_t | ||
| 43 | #define __NEED_intptr_t | ||
| 44 | #define __NEED_useconds_t | ||
| 45 | |||
| 46 | #include <bits/alltypes.h> | ||
| 47 | |||
| 48 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pipe */ | ||
| 49 | int pipe(int [2]); | ||
| 50 | int pipe2(int [2], int); | ||
| 51 | #endif | ||
| 52 | int close(int); | ||
| 53 | int posix_close(int, int); | ||
| 54 | #ifdef __wasilibc_unmodified_upstream /* WASI has no dup */ | ||
| 55 | int dup(int); | ||
| 56 | int dup2(int, int); | ||
| 57 | int dup3(int, int, int); | ||
| 58 | #endif | ||
| 59 | off_t lseek(int, off_t, int); | ||
| 60 | #ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */ | ||
| 61 | #else | ||
| 62 | off_t __wasilibc_tell(int); | ||
| 63 | |||
| 64 | #ifndef __cplusplus | ||
| 65 | /* | ||
| 66 | * Optimize lseek in the case where it's just returning the current offset. | ||
| 67 | * This avoids importing `__wasi_fd_seek` altogether in many common cases. | ||
| 68 | * | ||
| 69 | * But don't do this for C++ because a simple macro wouldn't handle namespaces | ||
| 70 | * correctly: | ||
| 71 | * - User code could qualify the `lseek` call with `::`. | ||
| 72 | * - There may be another `lseek` in scope from a `using` declaration. | ||
| 73 | */ | ||
| 74 | #define lseek(fd, offset, whence) \ | ||
| 75 | ({ \ | ||
| 76 | off_t __f = (fd); \ | ||
| 77 | off_t __o = (offset); \ | ||
| 78 | off_t __w = (whence); \ | ||
| 79 | __builtin_constant_p((offset)) && \ | ||
| 80 | __builtin_constant_p((whence)) && \ | ||
| 81 | __o == 0 && \ | ||
| 82 | __w == SEEK_CUR \ | ||
| 83 | ? __wasilibc_tell(__f) \ | ||
| 84 | : lseek(__f, __o, __w); \ | ||
| 85 | }) | ||
| 86 | #endif | ||
| 87 | #endif | ||
| 88 | int fsync(int); | ||
| 89 | int fdatasync(int); | ||
| 90 | |||
| 91 | ssize_t read(int, void *, size_t); | ||
| 92 | ssize_t write(int, const void *, size_t); | ||
| 93 | ssize_t pread(int, void *, size_t, off_t); | ||
| 94 | ssize_t pwrite(int, const void *, size_t, off_t); | ||
| 95 | |||
| 96 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chown */ | ||
| 97 | int chown(const char *, uid_t, gid_t); | ||
| 98 | int fchown(int, uid_t, gid_t); | ||
| 99 | int lchown(const char *, uid_t, gid_t); | ||
| 100 | int fchownat(int, const char *, uid_t, gid_t, int); | ||
| 101 | #endif | ||
| 102 | |||
| 103 | int link(const char *, const char *); | ||
| 104 | int linkat(int, const char *, int, const char *, int); | ||
| 105 | int symlink(const char *, const char *); | ||
| 106 | int symlinkat(const char *, int, const char *); | ||
| 107 | ssize_t readlink(const char *__restrict, char *__restrict, size_t); | ||
| 108 | ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); | ||
| 109 | int unlink(const char *); | ||
| 110 | int unlinkat(int, const char *, int); | ||
| 111 | int rmdir(const char *); | ||
| 112 | int truncate(const char *, off_t); | ||
| 113 | int ftruncate(int, off_t); | ||
| 114 | |||
| 115 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 116 | #define F_OK 0 | ||
| 117 | #define R_OK 4 | ||
| 118 | #define W_OK 2 | ||
| 119 | #define X_OK 1 | ||
| 120 | #endif | ||
| 121 | |||
| 122 | int access(const char *, int); | ||
| 123 | int faccessat(int, const char *, int, int); | ||
| 124 | |||
| 125 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fchdir */ | ||
| 126 | int fchdir(int); | ||
| 127 | #endif | ||
| 128 | int chdir(const char *); | ||
| 129 | char *getcwd(char *, size_t); | ||
| 130 | |||
| 131 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 132 | unsigned alarm(unsigned); | ||
| 133 | #endif | ||
| 134 | unsigned sleep(unsigned); | ||
| 135 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ | ||
| 136 | int pause(void); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ | ||
| 140 | pid_t fork(void); | ||
| 141 | pid_t _Fork(void); | ||
| 142 | int execve(const char *, char *const [], char *const []); | ||
| 143 | int execv(const char *, char *const []); | ||
| 144 | int execle(const char *, const char *, ...); | ||
| 145 | int execl(const char *, const char *, ...); | ||
| 146 | int execvp(const char *, char *const []); | ||
| 147 | int execlp(const char *, const char *, ...); | ||
| 148 | int fexecve(int, char *const [], char *const []); | ||
| 149 | #endif | ||
| 150 | _Noreturn void _exit(int); | ||
| 151 | |||
| 152 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_GETPID) | ||
| 153 | pid_t getpid(void); | ||
| 154 | #else | ||
| 155 | __attribute__((__deprecated__( | ||
| 156 | "WASI lacks process identifiers; to enable emulation of the `getpid` function using " | ||
| 157 | "a placeholder value, which doesn't reflect the host PID of the program, " | ||
| 158 | "compile with -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid" | ||
| 159 | ))) | ||
| 160 | pid_t getpid(void); | ||
| 161 | #endif | ||
| 162 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getpid etc. */ | ||
| 163 | pid_t getppid(void); | ||
| 164 | pid_t getpgrp(void); | ||
| 165 | pid_t getpgid(pid_t); | ||
| 166 | int setpgid(pid_t, pid_t); | ||
| 167 | pid_t setsid(void); | ||
| 168 | pid_t getsid(pid_t); | ||
| 169 | #endif | ||
| 170 | #ifdef __wasilibc_unmodified_upstream /* WASI has no ttyname */ | ||
| 171 | char *ttyname(int); | ||
| 172 | int ttyname_r(int, char *, size_t); | ||
| 173 | #endif | ||
| 174 | int isatty(int); | ||
| 175 | #ifdef __wasilibc_unmodified_upstream /* WASI has no process groups */ | ||
| 176 | pid_t tcgetpgrp(int); | ||
| 177 | int tcsetpgrp(int, pid_t); | ||
| 178 | #endif | ||
| 179 | |||
| 180 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getuid etc. */ | ||
| 181 | uid_t getuid(void); | ||
| 182 | uid_t geteuid(void); | ||
| 183 | gid_t getgid(void); | ||
| 184 | gid_t getegid(void); | ||
| 185 | int getgroups(int, gid_t []); | ||
| 186 | int setuid(uid_t); | ||
| 187 | int seteuid(uid_t); | ||
| 188 | int setgid(gid_t); | ||
| 189 | int setegid(gid_t); | ||
| 190 | #endif | ||
| 191 | |||
| 192 | char *getlogin(void); | ||
| 193 | int getlogin_r(char *, size_t); | ||
| 194 | int gethostname(char *, size_t); | ||
| 195 | char *ctermid(char *); | ||
| 196 | |||
| 197 | int getopt(int, char * const [], const char *); | ||
| 198 | extern char *optarg; | ||
| 199 | extern int optind, opterr, optopt; | ||
| 200 | |||
| 201 | long pathconf(const char *, int); | ||
| 202 | long fpathconf(int, int); | ||
| 203 | long sysconf(int); | ||
| 204 | size_t confstr(int, char *, size_t); | ||
| 205 | |||
| 206 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 207 | #define F_ULOCK 0 | ||
| 208 | #define F_LOCK 1 | ||
| 209 | #define F_TLOCK 2 | ||
| 210 | #define F_TEST 3 | ||
| 211 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setreuid */ | ||
| 212 | int setreuid(uid_t, uid_t); | ||
| 213 | int setregid(gid_t, gid_t); | ||
| 214 | #endif | ||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 216 | int lockf(int, int, off_t); | ||
| 217 | #endif | ||
| 218 | long gethostid(void); | ||
| 219 | #ifdef __wasilibc_unmodified_upstream /* WASI has no nice, sync, or setpgrp */ | ||
| 220 | int nice(int); | ||
| 221 | void sync(void); | ||
| 222 | pid_t setpgrp(void); | ||
| 223 | #endif | ||
| 224 | char *crypt(const char *, const char *); | ||
| 225 | void encrypt(char *, int); | ||
| 226 | void swab(const void *__restrict, void *__restrict, ssize_t); | ||
| 227 | #endif | ||
| 228 | |||
| 229 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 230 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 231 | int usleep(unsigned); | ||
| 232 | unsigned ualarm(unsigned, unsigned); | ||
| 233 | #endif | ||
| 234 | |||
| 235 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 236 | #define L_SET 0 | ||
| 237 | #define L_INCR 1 | ||
| 238 | #define L_XTND 2 | ||
| 239 | #ifdef __wasilibc_unmodified_upstream /* WASI has no brk */ | ||
| 240 | int brk(void *); | ||
| 241 | #endif | ||
| 242 | void *sbrk(intptr_t); | ||
| 243 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 244 | pid_t vfork(void); | ||
| 245 | int vhangup(void); | ||
| 246 | int chroot(const char *); | ||
| 247 | #endif | ||
| 248 | int getpagesize(void); | ||
| 249 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 250 | int getdtablesize(void); | ||
| 251 | int sethostname(const char *, size_t); | ||
| 252 | int getdomainname(char *, size_t); | ||
| 253 | int setdomainname(const char *, size_t); | ||
| 254 | int setgroups(size_t, const gid_t *); | ||
| 255 | char *getpass(const char *); | ||
| 256 | int daemon(int, int); | ||
| 257 | void setusershell(void); | ||
| 258 | void endusershell(void); | ||
| 259 | char *getusershell(void); | ||
| 260 | int acct(const char *); | ||
| 261 | long syscall(long, ...); | ||
| 262 | int execvpe(const char *, char *const [], char *const []); | ||
| 263 | int issetugid(void); | ||
| 264 | #endif | ||
| 265 | int getentropy(void *, size_t); | ||
| 266 | extern int optreset; | ||
| 267 | #endif | ||
| 268 | |||
| 269 | #ifdef _GNU_SOURCE | ||
| 270 | extern char **environ; | ||
| 271 | #ifdef __wasilibc_unmodified_upstream /* WASI has no get/setresuid */ | ||
| 272 | int setresuid(uid_t, uid_t, uid_t); | ||
| 273 | int setresgid(gid_t, gid_t, gid_t); | ||
| 274 | int getresuid(uid_t *, uid_t *, uid_t *); | ||
| 275 | int getresgid(gid_t *, gid_t *, gid_t *); | ||
| 276 | #endif | ||
| 277 | #ifdef __wasilibc_unmodified_upstream /* WASI has no cwd */ | ||
| 278 | char *get_current_dir_name(void); | ||
| 279 | #endif | ||
| 280 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syncfs */ | ||
| 281 | int syncfs(int); | ||
| 282 | #endif | ||
| 283 | #ifdef __wasilibc_unmodified_upstream /* WASI has no eaccess */ | ||
| 284 | int euidaccess(const char *, int); | ||
| 285 | int eaccess(const char *, int); | ||
| 286 | ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 287 | pid_t gettid(void); | ||
| 288 | #endif | ||
| 289 | #endif | ||
| 290 | |||
| 291 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 292 | #define lseek64 lseek | ||
| 293 | #define pread64 pread | ||
| 294 | #define pwrite64 pwrite | ||
| 295 | #ifdef __wasilibc_unmodified_upstream /* WASI has no truncate */ | ||
| 296 | #define truncate64 truncate | ||
| 297 | #endif | ||
| 298 | #define ftruncate64 ftruncate | ||
| 299 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 300 | #define lockf64 lockf | ||
| 301 | #endif | ||
| 302 | #define off64_t off_t | ||
| 303 | #endif | ||
| 304 | |||
| 305 | #define POSIX_CLOSE_RESTART 0 | ||
| 306 | |||
| 307 | #define _XOPEN_VERSION 700 | ||
| 308 | #define _XOPEN_UNIX 1 | ||
| 309 | #define _XOPEN_ENH_I18N 1 | ||
| 310 | |||
| 311 | #define _POSIX_VERSION 200809L | ||
| 312 | #define _POSIX2_VERSION _POSIX_VERSION | ||
| 313 | |||
| 314 | #define _POSIX_ADVISORY_INFO _POSIX_VERSION | ||
| 315 | #define _POSIX_CHOWN_RESTRICTED 1 | ||
| 316 | #define _POSIX_IPV6 _POSIX_VERSION | ||
| 317 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes, mmap, or mq */ | ||
| 318 | #define _POSIX_JOB_CONTROL 1 | ||
| 319 | #define _POSIX_MAPPED_FILES _POSIX_VERSION | ||
| 320 | #define _POSIX_MEMLOCK _POSIX_VERSION | ||
| 321 | #define _POSIX_MEMLOCK_RANGE _POSIX_VERSION | ||
| 322 | #define _POSIX_MEMORY_PROTECTION _POSIX_VERSION | ||
| 323 | #define _POSIX_MESSAGE_PASSING _POSIX_VERSION | ||
| 324 | #endif | ||
| 325 | #define _POSIX_FSYNC _POSIX_VERSION | ||
| 326 | #define _POSIX_NO_TRUNC 1 | ||
| 327 | #ifdef __wasilibc_unmodified_upstream /* WASI has no raw sockets */ | ||
| 328 | #define _POSIX_RAW_SOCKETS _POSIX_VERSION | ||
| 329 | #endif | ||
| 330 | #define _POSIX_REALTIME_SIGNALS _POSIX_VERSION | ||
| 331 | #define _POSIX_REGEXP 1 | ||
| 332 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 333 | #define _POSIX_SAVED_IDS 1 | ||
| 334 | #define _POSIX_SHELL 1 | ||
| 335 | #define _POSIX_SPAWN _POSIX_VERSION | ||
| 336 | #endif | ||
| 337 | #define _POSIX_VDISABLE 0 | ||
| 338 | |||
| 339 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 340 | #define _POSIX_THREADS _POSIX_VERSION | ||
| 341 | #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION | ||
| 342 | #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION | ||
| 343 | #endif | ||
| 344 | #if defined(__wasilibc_unmodified_upstream) /* wasi-libc doesn't provide pthread_attr_{get,set}stackaddr */ | ||
| 345 | #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION | ||
| 346 | #endif | ||
| 347 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) || !defined(_WASI_STRICT_PTHREAD) | ||
| 348 | #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION | ||
| 349 | #endif | ||
| 350 | #if defined(__wasilibc_unmodified_upstream) /* WASI has no scheduling control, and wasi-libc doesn't provide pthread_getcpuclockid */ | ||
| 351 | #define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION | ||
| 352 | #define _POSIX_THREAD_CPUTIME _POSIX_VERSION | ||
| 353 | #endif | ||
| 354 | #define _POSIX_TIMERS _POSIX_VERSION | ||
| 355 | #define _POSIX_TIMEOUTS _POSIX_VERSION | ||
| 356 | #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION | ||
| 357 | #define _POSIX_CPUTIME _POSIX_VERSION | ||
| 358 | #define _POSIX_CLOCK_SELECTION _POSIX_VERSION | ||
| 359 | #define _POSIX_BARRIERS _POSIX_VERSION | ||
| 360 | #define _POSIX_SPIN_LOCKS _POSIX_VERSION | ||
| 361 | #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION | ||
| 362 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX async I/O, semaphores, or shared memory */ | ||
| 363 | #define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION | ||
| 364 | #define _POSIX_SEMAPHORES _POSIX_VERSION | ||
| 365 | #define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION | ||
| 366 | #endif | ||
| 367 | |||
| 368 | #define _POSIX2_C_BIND _POSIX_VERSION | ||
| 369 | |||
| 370 | #include <bits/posix.h> | ||
| 371 | |||
| 372 | |||
| 373 | |||
| 374 | #define _PC_LINK_MAX	0 | ||
| 375 | #define _PC_MAX_CANON	1 | ||
| 376 | #define _PC_MAX_INPUT	2 | ||
| 377 | #define _PC_NAME_MAX	3 | ||
| 378 | #define _PC_PATH_MAX	4 | ||
| 379 | #define _PC_PIPE_BUF	5 | ||
| 380 | #define _PC_CHOWN_RESTRICTED	6 | ||
| 381 | #define _PC_NO_TRUNC	7 | ||
| 382 | #define _PC_VDISABLE	8 | ||
| 383 | #define _PC_SYNC_IO	9 | ||
| 384 | #define _PC_ASYNC_IO	10 | ||
| 385 | #define _PC_PRIO_IO	11 | ||
| 386 | #define _PC_SOCK_MAXBUF	12 | ||
| 387 | #define _PC_FILESIZEBITS	13 | ||
| 388 | #define _PC_REC_INCR_XFER_SIZE	14 | ||
| 389 | #define _PC_REC_MAX_XFER_SIZE	15 | ||
| 390 | #define _PC_REC_MIN_XFER_SIZE	16 | ||
| 391 | #define _PC_REC_XFER_ALIGN	17 | ||
| 392 | #define _PC_ALLOC_SIZE_MIN	18 | ||
| 393 | #define _PC_SYMLINK_MAX	19 | ||
| 394 | #define _PC_2_SYMLINKS	20 | ||
| 395 | |||
| 396 | #define _SC_ARG_MAX	0 | ||
| 397 | #define _SC_CHILD_MAX	1 | ||
| 398 | #define _SC_CLK_TCK	2 | ||
| 399 | #define _SC_NGROUPS_MAX	3 | ||
| 400 | #define _SC_OPEN_MAX	4 | ||
| 401 | #define _SC_STREAM_MAX	5 | ||
| 402 | #define _SC_TZNAME_MAX	6 | ||
| 403 | #define _SC_JOB_CONTROL	7 | ||
| 404 | #define _SC_SAVED_IDS	8 | ||
| 405 | #define _SC_REALTIME_SIGNALS	9 | ||
| 406 | #define _SC_PRIORITY_SCHEDULING	10 | ||
| 407 | #define _SC_TIMERS	11 | ||
| 408 | #define _SC_ASYNCHRONOUS_IO	12 | ||
| 409 | #define _SC_PRIORITIZED_IO	13 | ||
| 410 | #define _SC_SYNCHRONIZED_IO	14 | ||
| 411 | #define _SC_FSYNC	15 | ||
| 412 | #define _SC_MAPPED_FILES	16 | ||
| 413 | #define _SC_MEMLOCK	17 | ||
| 414 | #define _SC_MEMLOCK_RANGE	18 | ||
| 415 | #define _SC_MEMORY_PROTECTION	19 | ||
| 416 | #define _SC_MESSAGE_PASSING	20 | ||
| 417 | #define _SC_SEMAPHORES	21 | ||
| 418 | #define _SC_SHARED_MEMORY_OBJECTS	22 | ||
| 419 | #define _SC_AIO_LISTIO_MAX	23 | ||
| 420 | #define _SC_AIO_MAX	24 | ||
| 421 | #define _SC_AIO_PRIO_DELTA_MAX	25 | ||
| 422 | #define _SC_DELAYTIMER_MAX	26 | ||
| 423 | #define _SC_MQ_OPEN_MAX	27 | ||
| 424 | #define _SC_MQ_PRIO_MAX	28 | ||
| 425 | #define _SC_VERSION	29 | ||
| 426 | #define _SC_PAGE_SIZE	30 | ||
| 427 | #define _SC_PAGESIZE	30 /* !! */ | ||
| 428 | #define _SC_RTSIG_MAX	31 | ||
| 429 | #define _SC_SEM_NSEMS_MAX	32 | ||
| 430 | #define _SC_SEM_VALUE_MAX	33 | ||
| 431 | #define _SC_SIGQUEUE_MAX	34 | ||
| 432 | #define _SC_TIMER_MAX	35 | ||
| 433 | #define _SC_BC_BASE_MAX	36 | ||
| 434 | #define _SC_BC_DIM_MAX	37 | ||
| 435 | #define _SC_BC_SCALE_MAX	38 | ||
| 436 | #define _SC_BC_STRING_MAX	39 | ||
| 437 | #define _SC_COLL_WEIGHTS_MAX	40 | ||
| 438 | #define _SC_EXPR_NEST_MAX	42 | ||
| 439 | #define _SC_LINE_MAX	43 | ||
| 440 | #define _SC_RE_DUP_MAX	44 | ||
| 441 | #define _SC_2_VERSION	46 | ||
| 442 | #define _SC_2_C_BIND	47 | ||
| 443 | #define _SC_2_C_DEV	48 | ||
| 444 | #define _SC_2_FORT_DEV	49 | ||
| 445 | #define _SC_2_FORT_RUN	50 | ||
| 446 | #define _SC_2_SW_DEV	51 | ||
| 447 | #define _SC_2_LOCALEDEF	52 | ||
| 448 | #define _SC_UIO_MAXIOV	60 /* !! */ | ||
| 449 | #define _SC_IOV_MAX	60 | ||
| 450 | #define _SC_THREADS	67 | ||
| 451 | #define _SC_THREAD_SAFE_FUNCTIONS	68 | ||
| 452 | #define _SC_GETGR_R_SIZE_MAX	69 | ||
| 453 | #define _SC_GETPW_R_SIZE_MAX	70 | ||
| 454 | #define _SC_LOGIN_NAME_MAX	71 | ||
| 455 | #define _SC_TTY_NAME_MAX	72 | ||
| 456 | #define _SC_THREAD_DESTRUCTOR_ITERATIONS	73 | ||
| 457 | #define _SC_THREAD_KEYS_MAX	74 | ||
| 458 | #define _SC_THREAD_STACK_MIN	75 | ||
| 459 | #define _SC_THREAD_THREADS_MAX	76 | ||
| 460 | #define _SC_THREAD_ATTR_STACKADDR	77 | ||
| 461 | #define _SC_THREAD_ATTR_STACKSIZE	78 | ||
| 462 | #define _SC_THREAD_PRIORITY_SCHEDULING	79 | ||
| 463 | #define _SC_THREAD_PRIO_INHERIT	80 | ||
| 464 | #define _SC_THREAD_PRIO_PROTECT	81 | ||
| 465 | #define _SC_THREAD_PROCESS_SHARED	82 | ||
| 466 | #define _SC_NPROCESSORS_CONF	83 | ||
| 467 | #define _SC_NPROCESSORS_ONLN	84 | ||
| 468 | #define _SC_PHYS_PAGES	85 | ||
| 469 | #define _SC_AVPHYS_PAGES	86 | ||
| 470 | #define _SC_ATEXIT_MAX	87 | ||
| 471 | #define _SC_PASS_MAX	88 | ||
| 472 | #define _SC_XOPEN_VERSION	89 | ||
| 473 | #define _SC_XOPEN_XCU_VERSION	90 | ||
| 474 | #define _SC_XOPEN_UNIX	91 | ||
| 475 | #define _SC_XOPEN_CRYPT	92 | ||
| 476 | #define _SC_XOPEN_ENH_I18N	93 | ||
| 477 | #define _SC_XOPEN_SHM	94 | ||
| 478 | #define _SC_2_CHAR_TERM	95 | ||
| 479 | #define _SC_2_UPE	97 | ||
| 480 | #define _SC_XOPEN_XPG2	98 | ||
| 481 | #define _SC_XOPEN_XPG3	99 | ||
| 482 | #define _SC_XOPEN_XPG4	100 | ||
| 483 | #define _SC_NZERO	109 | ||
| 484 | #define _SC_XBS5_ILP32_OFF32	125 | ||
| 485 | #define _SC_XBS5_ILP32_OFFBIG	126 | ||
| 486 | #define _SC_XBS5_LP64_OFF64	127 | ||
| 487 | #define _SC_XBS5_LPBIG_OFFBIG	128 | ||
| 488 | #define _SC_XOPEN_LEGACY	129 | ||
| 489 | #define _SC_XOPEN_REALTIME	130 | ||
| 490 | #define _SC_XOPEN_REALTIME_THREADS	131 | ||
| 491 | #define _SC_ADVISORY_INFO	132 | ||
| 492 | #define _SC_BARRIERS	133 | ||
| 493 | #define _SC_CLOCK_SELECTION	137 | ||
| 494 | #define _SC_CPUTIME	138 | ||
| 495 | #define _SC_THREAD_CPUTIME	139 | ||
| 496 | #define _SC_MONOTONIC_CLOCK	149 | ||
| 497 | #define _SC_READER_WRITER_LOCKS	153 | ||
| 498 | #define _SC_SPIN_LOCKS	154 | ||
| 499 | #define _SC_REGEXP	155 | ||
| 500 | #define _SC_SHELL	157 | ||
| 501 | #define _SC_SPAWN	159 | ||
| 502 | #define _SC_SPORADIC_SERVER	160 | ||
| 503 | #define _SC_THREAD_SPORADIC_SERVER	161 | ||
| 504 | #define _SC_TIMEOUTS	164 | ||
| 505 | #define _SC_TYPED_MEMORY_OBJECTS	165 | ||
| 506 | #define _SC_2_PBS	168 | ||
| 507 | #define _SC_2_PBS_ACCOUNTING	169 | ||
| 508 | #define _SC_2_PBS_LOCATE	170 | ||
| 509 | #define _SC_2_PBS_MESSAGE	171 | ||
| 510 | #define _SC_2_PBS_TRACK	172 | ||
| 511 | #define _SC_SYMLOOP_MAX	173 | ||
| 512 | #define _SC_STREAMS	174 | ||
| 513 | #define _SC_2_PBS_CHECKPOINT	175 | ||
| 514 | #define _SC_V6_ILP32_OFF32	176 | ||
| 515 | #define _SC_V6_ILP32_OFFBIG	177 | ||
| 516 | #define _SC_V6_LP64_OFF64	178 | ||
| 517 | #define _SC_V6_LPBIG_OFFBIG	179 | ||
| 518 | #define _SC_HOST_NAME_MAX	180 | ||
| 519 | #define _SC_TRACE	181 | ||
| 520 | #define _SC_TRACE_EVENT_FILTER	182 | ||
| 521 | #define _SC_TRACE_INHERIT	183 | ||
| 522 | #define _SC_TRACE_LOG	184 | ||
| 523 | |||
| 524 | #define _SC_IPV6	235 | ||
| 525 | #define _SC_RAW_SOCKETS	236 | ||
| 526 | #define _SC_V7_ILP32_OFF32	237 | ||
| 527 | #define _SC_V7_ILP32_OFFBIG	238 | ||
| 528 | #define _SC_V7_LP64_OFF64	239 | ||
| 529 | #define _SC_V7_LPBIG_OFFBIG	240 | ||
| 530 | #define _SC_SS_REPL_MAX	241 | ||
| 531 | #define _SC_TRACE_EVENT_NAME_MAX	242 | ||
| 532 | #define _SC_TRACE_NAME_MAX	243 | ||
| 533 | #define _SC_TRACE_SYS_MAX	244 | ||
| 534 | #define _SC_TRACE_USER_EVENT_MAX	245 | ||
| 535 | #define _SC_XOPEN_STREAMS	246 | ||
| 536 | #define _SC_THREAD_ROBUST_PRIO_INHERIT	247 | ||
| 537 | #define _SC_THREAD_ROBUST_PRIO_PROTECT	248 | ||
| 538 | #define _SC_MINSIGSTKSZ	249 | ||
| 539 | #define _SC_SIGSTKSZ	250 | ||
| 540 | |||
| 541 | #define _CS_PATH	0 | ||
| 542 | #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS	1 | ||
| 543 | #define _CS_GNU_LIBC_VERSION	2 | ||
| 544 | #define _CS_GNU_LIBPTHREAD_VERSION	3 | ||
| 545 | #define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS	4 | ||
| 546 | #define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS	5 | ||
| 547 | |||
| 548 | #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS	1116 | ||
| 549 | #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS	1117 | ||
| 550 | #define _CS_POSIX_V6_ILP32_OFF32_LIBS	1118 | ||
| 551 | #define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS	1119 | ||
| 552 | #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS	1120 | ||
| 553 | #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS	1121 | ||
| 554 | #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS	1122 | ||
| 555 | #define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS	1123 | ||
| 556 | #define _CS_POSIX_V6_LP64_OFF64_CFLAGS	1124 | ||
| 557 | #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS	1125 | ||
| 558 | #define _CS_POSIX_V6_LP64_OFF64_LIBS	1126 | ||
| 559 | #define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS	1127 | ||
| 560 | #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS	1128 | ||
| 561 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS	1129 | ||
| 562 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS	1130 | ||
| 563 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS	1131 | ||
| 564 | #define _CS_POSIX_V7_ILP32_OFF32_CFLAGS	1132 | ||
| 565 | #define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS	1133 | ||
| 566 | #define _CS_POSIX_V7_ILP32_OFF32_LIBS	1134 | ||
| 567 | #define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS	1135 | ||
| 568 | #define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS	1136 | ||
| 569 | #define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS	1137 | ||
| 570 | #define _CS_POSIX_V7_ILP32_OFFBIG_LIBS	1138 | ||
| 571 | #define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS	1139 | ||
| 572 | #define _CS_POSIX_V7_LP64_OFF64_CFLAGS	1140 | ||
| 573 | #define _CS_POSIX_V7_LP64_OFF64_LDFLAGS	1141 | ||
| 574 | #define _CS_POSIX_V7_LP64_OFF64_LIBS	1142 | ||
| 575 | #define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS	1143 | ||
| 576 | #define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS	1144 | ||
| 577 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS	1145 | ||
| 578 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS	1146 | ||
| 579 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS	1147 | ||
| 580 | #define _CS_V6_ENV	1148 | ||
| 581 | #define _CS_V7_ENV	1149 | ||
| 582 | #define _CS_POSIX_V7_THREADS_CFLAGS	1150 | ||
| 583 | #define _CS_POSIX_V7_THREADS_LDFLAGS	1151 | ||
| 584 | |||
| 585 | #ifdef __cplusplus | ||
| 586 | } | ||
| 587 | #endif | ||
| 588 | |||
| 589 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/wasi/libc-busywait.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #ifndef __wasi_libc_busywait_h | ||
| 2 | #define __wasi_libc_busywait_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | /// Enable busywait in futex on current thread. | ||
| 9 | void __wasilibc_enable_futex_busywait_on_current_thread(void); | ||
| 10 | |||
| 11 | #ifdef __cplusplus | ||
| 12 | } | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/wchar.h deleted-214| ... | @@ -1,214 +0,0 @@ | ||
| 1 | #ifndef _WCHAR_H | ||
| 2 | #define _WCHAR_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_FILE | ||
| 11 | #define __NEED___isoc_va_list | ||
| 12 | #define __NEED_size_t | ||
| 13 | #define __NEED_wchar_t | ||
| 14 | #define __NEED_wint_t | ||
| 15 | #define __NEED_mbstate_t | ||
| 16 | |||
| 17 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 18 | #if __STDC_VERSION__ < 201112L | ||
| 19 | #define __NEED_struct__IO_FILE | ||
| 20 | #endif | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 24 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 25 | #define __NEED_locale_t | ||
| 26 | #define __NEED_va_list | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 30 | #define __NEED_wctype_t | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #include <bits/alltypes.h> | ||
| 34 | |||
| 35 | #if L'\0'-1 > 0 | ||
| 36 | #define WCHAR_MAX (0xffffffffu+L'\0') | ||
| 37 | #define WCHAR_MIN (0+L'\0') | ||
| 38 | #else | ||
| 39 | #define WCHAR_MAX (0x7fffffff+L'\0') | ||
| 40 | #define WCHAR_MIN (-1-0x7fffffff+L'\0') | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 44 | #if __cplusplus >= 201103L | ||
| 45 | #define NULL nullptr | ||
| 46 | #elif defined(__cplusplus) | ||
| 47 | #define NULL 0L | ||
| 48 | #else | ||
| 49 | #define NULL ((void*)0) | ||
| 50 | #endif | ||
| 51 | #else | ||
| 52 | #define __need_NULL | ||
| 53 | #include <stddef.h> | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #undef WEOF | ||
| 57 | #define WEOF 0xffffffffU | ||
| 58 | |||
| 59 | wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 60 | wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 61 | |||
| 62 | wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 63 | wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 64 | |||
| 65 | int wcscmp (const wchar_t *, const wchar_t *); | ||
| 66 | int wcsncmp (const wchar_t *, const wchar_t *, size_t); | ||
| 67 | |||
| 68 | int wcscoll(const wchar_t *, const wchar_t *); | ||
| 69 | size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 70 | |||
| 71 | wchar_t *wcschr (const wchar_t *, wchar_t); | ||
| 72 | wchar_t *wcsrchr (const wchar_t *, wchar_t); | ||
| 73 | |||
| 74 | size_t wcscspn (const wchar_t *, const wchar_t *); | ||
| 75 | size_t wcsspn (const wchar_t *, const wchar_t *); | ||
| 76 | wchar_t *wcspbrk (const wchar_t *, const wchar_t *); | ||
| 77 | |||
| 78 | wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); | ||
| 79 | |||
| 80 | size_t wcslen (const wchar_t *); | ||
| 81 | |||
| 82 | wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); | ||
| 83 | wchar_t *wcswcs (const wchar_t *, const wchar_t *); | ||
| 84 | |||
| 85 | wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); | ||
| 86 | int wmemcmp (const wchar_t *, const wchar_t *, size_t); | ||
| 87 | wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 88 | wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); | ||
| 89 | wchar_t *wmemset (wchar_t *, wchar_t, size_t); | ||
| 90 | |||
| 91 | wint_t btowc (int); | ||
| 92 | int wctob (wint_t); | ||
| 93 | |||
| 94 | int mbsinit (const mbstate_t *); | ||
| 95 | size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 96 | size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); | ||
| 97 | |||
| 98 | size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 99 | |||
| 100 | size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); | ||
| 101 | size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); | ||
| 102 | |||
| 103 | float wcstof (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 104 | double wcstod (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 105 | long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 106 | |||
| 107 | long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 108 | unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 109 | |||
| 110 | long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 111 | unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 112 | |||
| 113 | |||
| 114 | |||
| 115 | int fwide (FILE *, int); | ||
| 116 | |||
| 117 | |||
| 118 | int wprintf (const wchar_t *__restrict, ...); | ||
| 119 | int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 120 | int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); | ||
| 121 | |||
| 122 | int vwprintf (const wchar_t *__restrict, __isoc_va_list); | ||
| 123 | int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 124 | int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); | ||
| 125 | |||
| 126 | int wscanf (const wchar_t *__restrict, ...); | ||
| 127 | int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 128 | int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); | ||
| 129 | |||
| 130 | int vwscanf (const wchar_t *__restrict, __isoc_va_list); | ||
| 131 | int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 132 | int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 133 | |||
| 134 | wint_t fgetwc (FILE *); | ||
| 135 | wint_t getwc (FILE *); | ||
| 136 | wint_t getwchar (void); | ||
| 137 | |||
| 138 | wint_t fputwc (wchar_t, FILE *); | ||
| 139 | wint_t putwc (wchar_t, FILE *); | ||
| 140 | wint_t putwchar (wchar_t); | ||
| 141 | |||
| 142 | wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); | ||
| 143 | int fputws (const wchar_t *__restrict, FILE *__restrict); | ||
| 144 | |||
| 145 | wint_t ungetwc (wint_t, FILE *); | ||
| 146 | |||
| 147 | struct tm; | ||
| 148 | size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); | ||
| 149 | |||
| 150 | #undef iswdigit | ||
| 151 | |||
| 152 | #if defined(_GNU_SOURCE) | ||
| 153 | wint_t fgetwc_unlocked (FILE *); | ||
| 154 | wint_t getwc_unlocked (FILE *); | ||
| 155 | wint_t getwchar_unlocked (void); | ||
| 156 | wint_t fputwc_unlocked (wchar_t, FILE *); | ||
| 157 | wint_t putwc_unlocked (wchar_t, FILE *); | ||
| 158 | wint_t putwchar_unlocked (wchar_t); | ||
| 159 | wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); | ||
| 160 | int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); | ||
| 161 | #endif | ||
| 162 | |||
| 163 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 164 | size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); | ||
| 165 | #endif | ||
| 166 | |||
| 167 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 168 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 169 | FILE *open_wmemstream(wchar_t **, size_t *); | ||
| 170 | size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 171 | size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 172 | wchar_t *wcsdup(const wchar_t *); | ||
| 173 | size_t wcsnlen (const wchar_t *, size_t); | ||
| 174 | wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 175 | wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 176 | int wcscasecmp(const wchar_t *, const wchar_t *); | ||
| 177 | int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 178 | int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); | ||
| 179 | int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); | ||
| 180 | int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 181 | size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 185 | int wcwidth (wchar_t); | ||
| 186 | int wcswidth (const wchar_t *, size_t); | ||
| 187 | int iswalnum(wint_t); | ||
| 188 | int iswalpha(wint_t); | ||
| 189 | int iswblank(wint_t); | ||
| 190 | int iswcntrl(wint_t); | ||
| 191 | int iswdigit(wint_t); | ||
| 192 | int iswgraph(wint_t); | ||
| 193 | int iswlower(wint_t); | ||
| 194 | int iswprint(wint_t); | ||
| 195 | int iswpunct(wint_t); | ||
| 196 | int iswspace(wint_t); | ||
| 197 | int iswupper(wint_t); | ||
| 198 | int iswxdigit(wint_t); | ||
| 199 | int iswctype(wint_t, wctype_t); | ||
| 200 | wint_t towlower(wint_t); | ||
| 201 | wint_t towupper(wint_t); | ||
| 202 | wctype_t wctype(const char *); | ||
| 203 | |||
| 204 | #ifndef __cplusplus | ||
| 205 | #undef iswdigit | ||
| 206 | #define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 207 | #endif | ||
| 208 | #endif | ||
| 209 | |||
| 210 | #ifdef __cplusplus | ||
| 211 | } | ||
| 212 | #endif | ||
| 213 | |||
| 214 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/conf/fpathconf.c deleted-39| ... | @@ -1,39 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | long fpathconf(int fd, int name) | ||
| 6 | { | ||
| 7 | 	static const short values[] = { | ||
| 8 | 		[_PC_LINK_MAX] = _POSIX_LINK_MAX, | ||
| 9 | 		[_PC_MAX_CANON] = _POSIX_MAX_CANON, | ||
| 10 | 		[_PC_MAX_INPUT] = _POSIX_MAX_INPUT, | ||
| 11 | 		[_PC_NAME_MAX] = NAME_MAX, | ||
| 12 | 		[_PC_PATH_MAX] = PATH_MAX, | ||
| 13 | #ifdef __wasilibc_unmodified_upstream // WASI has no pipes | ||
| 14 | 		[_PC_PIPE_BUF] = PIPE_BUF, | ||
| 15 | #else | ||
| 16 | 		[_PC_PIPE_BUF] = -1, | ||
| 17 | #endif | ||
| 18 | 		[_PC_CHOWN_RESTRICTED] = 1, | ||
| 19 | 		[_PC_NO_TRUNC] = 1, | ||
| 20 | 		[_PC_VDISABLE] = 0, | ||
| 21 | 		[_PC_SYNC_IO] = 1, | ||
| 22 | 		[_PC_ASYNC_IO] = -1, | ||
| 23 | 		[_PC_PRIO_IO] = -1, | ||
| 24 | 		[_PC_SOCK_MAXBUF] = -1, | ||
| 25 | 		[_PC_FILESIZEBITS] = FILESIZEBITS, | ||
| 26 | 		[_PC_REC_INCR_XFER_SIZE] = 4096, | ||
| 27 | 		[_PC_REC_MAX_XFER_SIZE] = 4096, | ||
| 28 | 		[_PC_REC_MIN_XFER_SIZE] = 4096, | ||
| 29 | 		[_PC_REC_XFER_ALIGN] = 4096, | ||
| 30 | 		[_PC_ALLOC_SIZE_MIN] = 4096, | ||
| 31 | 		[_PC_SYMLINK_MAX] = -1, | ||
| 32 | 		[_PC_2_SYMLINKS] = 1 | ||
| 33 | 	}; | ||
| 34 | 	if (name >= sizeof(values)/sizeof(values[0])) { | ||
| 35 | 		errno = EINVAL; | ||
| 36 | 		return -1; | ||
| 37 | 	} | ||
| 38 | 	return values[name]; | ||
| 39 | } | ||
lib/libc/wasi/libc-top-half/musl/src/conf/sysconf.c deleted-297| ... | @@ -1,297 +0,0 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #ifdef __wasilibc_unmodified_upstream // WASI has no process-level accounting | ||
| 5 | #include <sys/resource.h> | ||
| 6 | #endif | ||
| 7 | #ifdef __wasilibc_unmodified_upstream // WASI has no realtime signals | ||
| 8 | #include <signal.h> | ||
| 9 | #endif | ||
| 10 | #include <sys/sysinfo.h> | ||
| 11 | #ifdef __wasilibc_unmodified_upstream | ||
| 12 | #include <sys/auxv.h> | ||
| 13 | #include "syscall.h" | ||
| 14 | #endif | ||
| 15 | #include "libc.h" | ||
| 16 | |||
| 17 | #define JT(x) (-256|(x)) | ||
| 18 | #define VER JT(1) | ||
| 19 | #define JT_ARG_MAX JT(2) | ||
| 20 | #ifdef __wasilibc_unmodified_upstream // WASI has no mq | ||
| 21 | #define JT_MQ_PRIO_MAX JT(3) | ||
| 22 | #endif | ||
| 23 | #define JT_PAGE_SIZE JT(4) | ||
| 24 | #ifdef __wasilibc_unmodified_upstream // WASI has no semaphores | ||
| 25 | #define JT_SEM_VALUE_MAX JT(5) | ||
| 26 | #endif | ||
| 27 | #define JT_NPROCESSORS_CONF JT(6) | ||
| 28 | #define JT_NPROCESSORS_ONLN JT(7) | ||
| 29 | #define JT_PHYS_PAGES JT(8) | ||
| 30 | #define JT_AVPHYS_PAGES JT(9) | ||
| 31 | #define JT_ZERO JT(10) | ||
| 32 | #define JT_DELAYTIMER_MAX JT(11) | ||
| 33 | #define JT_MINSIGSTKSZ JT(12) | ||
| 34 | #define JT_SIGSTKSZ JT(13) | ||
| 35 | |||
| 36 | #define RLIM(x) (-32768|(RLIMIT_ ## x)) | ||
| 37 | |||
| 38 | long sysconf(int name) | ||
| 39 | { | ||
| 40 | 	static const short values[] = { | ||
| 41 | 		[_SC_ARG_MAX] = JT_ARG_MAX, | ||
| 42 | #ifdef __wasilibc_unmodified_upstream // WASI has no processes | ||
| 43 | 		[_SC_CHILD_MAX] = RLIM(NPROC), | ||
| 44 | #else | ||
| 45 | 		// Not supported on wasi. | ||
| 46 | 		[_SC_CHILD_MAX] = -1, | ||
| 47 | #endif | ||
| 48 | 		[_SC_CLK_TCK] = 100, | ||
| 49 | 		[_SC_NGROUPS_MAX] = 32, | ||
| 50 | #ifdef __wasilibc_unmodified_upstream // WASI has no rlimit | ||
| 51 | 		[_SC_OPEN_MAX] = RLIM(NOFILE), | ||
| 52 | #else | ||
| 53 | 		// Rlimit is not supported on wasi. | ||
| 54 | 		[_SC_OPEN_MAX] = -1, | ||
| 55 | #endif | ||
| 56 | |||
| 57 | 		[_SC_STREAM_MAX] = -1, | ||
| 58 | 		[_SC_TZNAME_MAX] = TZNAME_MAX, | ||
| 59 | 		[_SC_JOB_CONTROL] = 1, | ||
| 60 | 		[_SC_SAVED_IDS] = 1, | ||
| 61 | 		[_SC_REALTIME_SIGNALS] = VER, | ||
| 62 | 		[_SC_PRIORITY_SCHEDULING] = -1, | ||
| 63 | 		[_SC_TIMERS] = VER, | ||
| 64 | 		[_SC_ASYNCHRONOUS_IO] = VER, | ||
| 65 | 		[_SC_PRIORITIZED_IO] = -1, | ||
| 66 | 		[_SC_SYNCHRONIZED_IO] = -1, | ||
| 67 | 		[_SC_FSYNC] = VER, | ||
| 68 | 		[_SC_MAPPED_FILES] = VER, | ||
| 69 | 		[_SC_MEMLOCK] = VER, | ||
| 70 | 		[_SC_MEMLOCK_RANGE] = VER, | ||
| 71 | 		[_SC_MEMORY_PROTECTION] = VER, | ||
| 72 | 		[_SC_MESSAGE_PASSING] = VER, | ||
| 73 | 		[_SC_SEMAPHORES] = VER, | ||
| 74 | 		[_SC_SHARED_MEMORY_OBJECTS] = VER, | ||
| 75 | 		[_SC_AIO_LISTIO_MAX] = -1, | ||
| 76 | 		[_SC_AIO_MAX] = -1, | ||
| 77 | 		[_SC_AIO_PRIO_DELTA_MAX] = JT_ZERO, /* ?? */ | ||
| 78 | 		[_SC_DELAYTIMER_MAX] = JT_DELAYTIMER_MAX, | ||
| 79 | #ifdef __wasilibc_unmodified_upstream // WASI has no mq | ||
| 80 | 		[_SC_MQ_OPEN_MAX] = -1, | ||
| 81 | 		[_SC_MQ_PRIO_MAX] = JT_MQ_PRIO_MAX, | ||
| 82 | #endif | ||
| 83 | 		[_SC_VERSION] = VER, | ||
| 84 | 		[_SC_PAGE_SIZE] = JT_PAGE_SIZE, | ||
| 85 | #ifdef __wasilibc_unmodified_upstream // WASI has no realtime signals | ||
| 86 | 		[_SC_RTSIG_MAX] = _NSIG - 1 - 31 - 3, | ||
| 87 | #else | ||
| 88 | 		// Not supported on wasi. | ||
| 89 | 		[_SC_RTSIG_MAX] = -1, | ||
| 90 | #endif | ||
| 91 | #ifdef __wasilibc_unmodified_upstream // WASI has no semaphores | ||
| 92 | 		[_SC_SEM_NSEMS_MAX] = SEM_NSEMS_MAX, | ||
| 93 | 		[_SC_SEM_VALUE_MAX] = JT_SEM_VALUE_MAX, | ||
| 94 | #else | ||
| 95 | 		[_SC_SEM_NSEMS_MAX] = -1, | ||
| 96 | 		[_SC_SEM_VALUE_MAX] = -1, | ||
| 97 | #endif | ||
| 98 | 		[_SC_SIGQUEUE_MAX] = -1, | ||
| 99 | 		[_SC_TIMER_MAX] = -1, | ||
| 100 | #ifdef __wasilibc_unmodified_upstream // WASI has no shell commands | ||
| 101 | 		[_SC_BC_BASE_MAX] = _POSIX2_BC_BASE_MAX, | ||
| 102 | 		[_SC_BC_DIM_MAX] = _POSIX2_BC_DIM_MAX, | ||
| 103 | 		[_SC_BC_SCALE_MAX] = _POSIX2_BC_SCALE_MAX, | ||
| 104 | 		[_SC_BC_STRING_MAX] = _POSIX2_BC_STRING_MAX, | ||
| 105 | #else | ||
| 106 | 		[_SC_BC_BASE_MAX] = -1, | ||
| 107 | 		[_SC_BC_DIM_MAX] = -1, | ||
| 108 | 		[_SC_BC_SCALE_MAX] = -1, | ||
| 109 | 		[_SC_BC_STRING_MAX] = -1, | ||
| 110 | #endif | ||
| 111 | 		[_SC_COLL_WEIGHTS_MAX] = COLL_WEIGHTS_MAX, | ||
| 112 | 		[_SC_EXPR_NEST_MAX] = -1, | ||
| 113 | 		[_SC_LINE_MAX] = -1, | ||
| 114 | 		[_SC_RE_DUP_MAX] = RE_DUP_MAX, | ||
| 115 | 		[_SC_2_VERSION] = VER, | ||
| 116 | 		[_SC_2_C_BIND] = VER, | ||
| 117 | 		[_SC_2_C_DEV] = -1, | ||
| 118 | 		[_SC_2_FORT_DEV] = -1, | ||
| 119 | 		[_SC_2_FORT_RUN] = -1, | ||
| 120 | 		[_SC_2_SW_DEV] = -1, | ||
| 121 | 		[_SC_2_LOCALEDEF] = -1, | ||
| 122 | 		[_SC_IOV_MAX] = IOV_MAX, | ||
| 123 | 		[_SC_THREADS] = VER, | ||
| 124 | 		[_SC_THREAD_SAFE_FUNCTIONS] = VER, | ||
| 125 | 		[_SC_GETGR_R_SIZE_MAX] = -1, | ||
| 126 | 		[_SC_GETPW_R_SIZE_MAX] = -1, | ||
| 127 | 		[_SC_LOGIN_NAME_MAX] = 256, | ||
| 128 | 		[_SC_TTY_NAME_MAX] = TTY_NAME_MAX, | ||
| 129 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 130 | 		[_SC_THREAD_DESTRUCTOR_ITERATIONS] = PTHREAD_DESTRUCTOR_ITERATIONS, | ||
| 131 | 		[_SC_THREAD_KEYS_MAX] = PTHREAD_KEYS_MAX, | ||
| 132 | 		[_SC_THREAD_STACK_MIN] = PTHREAD_STACK_MIN, | ||
| 133 | #else | ||
| 134 | 		[_SC_THREAD_DESTRUCTOR_ITERATIONS] = -1, | ||
| 135 | 		[_SC_THREAD_KEYS_MAX] = -1, | ||
| 136 | 		[_SC_THREAD_STACK_MIN] = -1, | ||
| 137 | #endif | ||
| 138 | 		[_SC_THREAD_THREADS_MAX] = -1, | ||
| 139 | 		[_SC_THREAD_ATTR_STACKADDR] = VER, | ||
| 140 | 		[_SC_THREAD_ATTR_STACKSIZE] = VER, | ||
| 141 | 		[_SC_THREAD_PRIORITY_SCHEDULING] = VER, | ||
| 142 | 		[_SC_THREAD_PRIO_INHERIT] = -1, | ||
| 143 | 		[_SC_THREAD_PRIO_PROTECT] = -1, | ||
| 144 | 		[_SC_THREAD_PROCESS_SHARED] = VER, | ||
| 145 | 		[_SC_NPROCESSORS_CONF] = JT_NPROCESSORS_CONF, | ||
| 146 | 		[_SC_NPROCESSORS_ONLN] = JT_NPROCESSORS_ONLN, | ||
| 147 | 		[_SC_PHYS_PAGES] = JT_PHYS_PAGES, | ||
| 148 | 		[_SC_AVPHYS_PAGES] = JT_AVPHYS_PAGES, | ||
| 149 | 		[_SC_ATEXIT_MAX] = -1, | ||
| 150 | 		[_SC_PASS_MAX] = -1, | ||
| 151 | 		[_SC_XOPEN_VERSION] = _XOPEN_VERSION, | ||
| 152 | 		[_SC_XOPEN_XCU_VERSION] = _XOPEN_VERSION, | ||
| 153 | 		[_SC_XOPEN_UNIX] = 1, | ||
| 154 | 		[_SC_XOPEN_CRYPT] = -1, | ||
| 155 | 		[_SC_XOPEN_ENH_I18N] = 1, | ||
| 156 | 		[_SC_XOPEN_SHM] = 1, | ||
| 157 | 		[_SC_2_CHAR_TERM] = -1, | ||
| 158 | 		[_SC_2_UPE] = -1, | ||
| 159 | 		[_SC_XOPEN_XPG2] = -1, | ||
| 160 | 		[_SC_XOPEN_XPG3] = -1, | ||
| 161 | 		[_SC_XOPEN_XPG4] = -1, | ||
| 162 | 		[_SC_NZERO] = NZERO, | ||
| 163 | 		[_SC_XBS5_ILP32_OFF32] = -1, | ||
| 164 | 		[_SC_XBS5_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, | ||
| 165 | 		[_SC_XBS5_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, | ||
| 166 | 		[_SC_XBS5_LPBIG_OFFBIG] = -1, | ||
| 167 | 		[_SC_XOPEN_LEGACY] = -1, | ||
| 168 | 		[_SC_XOPEN_REALTIME] = -1, | ||
| 169 | 		[_SC_XOPEN_REALTIME_THREADS] = -1, | ||
| 170 | 		[_SC_ADVISORY_INFO] = VER, | ||
| 171 | 		[_SC_BARRIERS] = VER, | ||
| 172 | 		[_SC_CLOCK_SELECTION] = VER, | ||
| 173 | 		[_SC_CPUTIME] = VER, | ||
| 174 | 		[_SC_THREAD_CPUTIME] = VER, | ||
| 175 | 		[_SC_MONOTONIC_CLOCK] = VER, | ||
| 176 | 		[_SC_READER_WRITER_LOCKS] = VER, | ||
| 177 | 		[_SC_SPIN_LOCKS] = VER, | ||
| 178 | 		[_SC_REGEXP] = 1, | ||
| 179 | 		[_SC_SHELL] = 1, | ||
| 180 | 		[_SC_SPAWN] = VER, | ||
| 181 | 		[_SC_SPORADIC_SERVER] = -1, | ||
| 182 | 		[_SC_THREAD_SPORADIC_SERVER] = -1, | ||
| 183 | 		[_SC_TIMEOUTS] = VER, | ||
| 184 | 		[_SC_TYPED_MEMORY_OBJECTS] = -1, | ||
| 185 | 		[_SC_2_PBS] = -1, | ||
| 186 | 		[_SC_2_PBS_ACCOUNTING] = -1, | ||
| 187 | 		[_SC_2_PBS_LOCATE] = -1, | ||
| 188 | 		[_SC_2_PBS_MESSAGE] = -1, | ||
| 189 | 		[_SC_2_PBS_TRACK] = -1, | ||
| 190 | 		[_SC_SYMLOOP_MAX] = SYMLOOP_MAX, | ||
| 191 | 		[_SC_STREAMS] = JT_ZERO, | ||
| 192 | 		[_SC_2_PBS_CHECKPOINT] = -1, | ||
| 193 | 		[_SC_V6_ILP32_OFF32] = -1, | ||
| 194 | 		[_SC_V6_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, | ||
| 195 | 		[_SC_V6_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, | ||
| 196 | 		[_SC_V6_LPBIG_OFFBIG] = -1, | ||
| 197 | 		[_SC_HOST_NAME_MAX] = HOST_NAME_MAX, | ||
| 198 | 		[_SC_TRACE] = -1, | ||
| 199 | 		[_SC_TRACE_EVENT_FILTER] = -1, | ||
| 200 | 		[_SC_TRACE_INHERIT] = -1, | ||
| 201 | 		[_SC_TRACE_LOG] = -1, | ||
| 202 | |||
| 203 | 		[_SC_IPV6] = VER, | ||
| 204 | 		[_SC_RAW_SOCKETS] = VER, | ||
| 205 | 		[_SC_V7_ILP32_OFF32] = -1, | ||
| 206 | 		[_SC_V7_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, | ||
| 207 | 		[_SC_V7_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, | ||
| 208 | 		[_SC_V7_LPBIG_OFFBIG] = -1, | ||
| 209 | 		[_SC_SS_REPL_MAX] = -1, | ||
| 210 | 		[_SC_TRACE_EVENT_NAME_MAX] = -1, | ||
| 211 | 		[_SC_TRACE_NAME_MAX] = -1, | ||
| 212 | 		[_SC_TRACE_SYS_MAX] = -1, | ||
| 213 | 		[_SC_TRACE_USER_EVENT_MAX] = -1, | ||
| 214 | 		[_SC_XOPEN_STREAMS] = JT_ZERO, | ||
| 215 | 		[_SC_THREAD_ROBUST_PRIO_INHERIT] = -1, | ||
| 216 | 		[_SC_THREAD_ROBUST_PRIO_PROTECT] = -1, | ||
| 217 | |||
| 218 | 		[_SC_MINSIGSTKSZ] = JT_MINSIGSTKSZ, | ||
| 219 | 		[_SC_SIGSTKSZ] = JT_SIGSTKSZ, | ||
| 220 | 	}; | ||
| 221 | |||
| 222 | 	if (name >= sizeof(values)/sizeof(values[0]) || !values[name]) { | ||
| 223 | 		errno = EINVAL; | ||
| 224 | 		return -1; | ||
| 225 | 	} else if (values[name] >= -1) { | ||
| 226 | 		return values[name]; | ||
| 227 | 	} else if (values[name] < -256) { | ||
| 228 | #ifdef __wasilibc_unmodified_upstream // WASI has no getrlimit | ||
| 229 | 		struct rlimit lim; | ||
| 230 | 		getrlimit(values[name]&16383, &lim); | ||
| 231 | 		if (lim.rlim_cur == RLIM_INFINITY) | ||
| 232 | 			return -1; | ||
| 233 | 		return lim.rlim_cur > LONG_MAX ? LONG_MAX : lim.rlim_cur; | ||
| 234 | #else | ||
| 235 | 		// Not supported on wasi. | ||
| 236 | 		errno = EINVAL; | ||
| 237 | 		return -1; | ||
| 238 | #endif | ||
| 239 | 	} | ||
| 240 | |||
| 241 | 	switch ((unsigned char)values[name]) { | ||
| 242 | 	case VER & 255: | ||
| 243 | 		return _POSIX_VERSION; | ||
| 244 | 	case JT_ARG_MAX & 255: | ||
| 245 | 		return ARG_MAX; | ||
| 246 | #ifdef __wasilibc_unmodified_upstream // WASI has no mq | ||
| 247 | 	case JT_MQ_PRIO_MAX & 255: | ||
| 248 | 		return MQ_PRIO_MAX; | ||
| 249 | #endif | ||
| 250 | 	case JT_PAGE_SIZE & 255: | ||
| 251 | 		return PAGE_SIZE; | ||
| 252 | #ifdef __wasilibc_unmodified_upstream // WASI has no semaphores | ||
| 253 | 	case JT_SEM_VALUE_MAX & 255: | ||
| 254 | 		return SEM_VALUE_MAX; | ||
| 255 | #endif | ||
| 256 | 	case JT_DELAYTIMER_MAX & 255: | ||
| 257 | 		return DELAYTIMER_MAX; | ||
| 258 | 	case JT_NPROCESSORS_CONF & 255: | ||
| 259 | 	case JT_NPROCESSORS_ONLN & 255: ; | ||
| 260 | #ifdef __wasilibc_unmodified_upstream | ||
| 261 | 		unsigned char set[128] = {1}; | ||
| 262 | 		int i, cnt; | ||
| 263 | 		__syscall(SYS_sched_getaffinity, 0, sizeof set, set); | ||
| 264 | 		for (i=cnt=0; i<sizeof set; i++) | ||
| 265 | 			for (; set[i]; set[i]&=set[i]-1, cnt++); | ||
| 266 | 		return cnt; | ||
| 267 | #else | ||
| 268 | 		// WASI has no way to query the processor count | ||
| 269 | 		return 1; | ||
| 270 | #endif | ||
| 271 | #ifdef __wasilibc_unmodified_upstream // WASI has no sysinfo | ||
| 272 | 	case JT_PHYS_PAGES & 255: | ||
| 273 | 	case JT_AVPHYS_PAGES & 255: ; | ||
| 274 | 		unsigned long long mem; | ||
| 275 | 		struct sysinfo si; | ||
| 276 | 		__lsysinfo(&si); | ||
| 277 | 		if (!si.mem_unit) si.mem_unit = 1; | ||
| 278 | 		if (name==_SC_PHYS_PAGES) mem = si.totalram; | ||
| 279 | 		else mem = si.freeram + si.bufferram; | ||
| 280 | 		mem *= si.mem_unit; | ||
| 281 | 		mem /= PAGE_SIZE; | ||
| 282 | 		return (mem > LONG_MAX) ? LONG_MAX : mem; | ||
| 283 | #endif | ||
| 284 | 	case JT_ZERO & 255: | ||
| 285 | 		return 0; | ||
| 286 | 	} | ||
| 287 | #ifdef __wasilibc_unmodified_upstream // WASI has no auxv | ||
| 288 | 	case JT_MINSIGSTKSZ & 255: | ||
| 289 | 	case JT_SIGSTKSZ & 255: ; | ||
| 290 | 		long val = __getauxval(AT_MINSIGSTKSZ); | ||
| 291 | 		if (val < MINSIGSTKSZ) val = MINSIGSTKSZ; | ||
| 292 | 		if (values[name] == JT_SIGSTKSZ) | ||
| 293 | 			val += SIGSTKSZ - MINSIGSTKSZ; | ||
| 294 | 		return val; | ||
| 295 | #endif | ||
| 296 | 	return values[name]; | ||
| 297 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/alphasort.c deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <dirent.h> | ||
| 3 | |||
| 4 | int alphasort(const struct dirent **a, const struct dirent **b) | ||
| 5 | { | ||
| 6 | 	return strcoll((*a)->d_name, (*b)->d_name); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(alphasort, alphasort64); | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/versionsort.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <dirent.h> | ||
| 4 | |||
| 5 | int versionsort(const struct dirent **a, const struct dirent **b) | ||
| 6 | { | ||
| 7 | 	return strverscmp((*a)->d_name, (*b)->d_name); | ||
| 8 | } | ||
| 9 | |||
| 10 | #undef versionsort64 | ||
| 11 | weak_alias(versionsort, versionsort64); | ||
lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c deleted-59| ... | @@ -1,59 +0,0 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | #else | ||
| 6 | // In non-_REENTRANT, include it for `a_crash` | ||
| 7 | # include "atomic.h" | ||
| 8 | #endif | ||
| 9 | |||
| 10 | uintptr_t __stack_chk_guard; | ||
| 11 | |||
| 12 | void __init_ssp(void *entropy) | ||
| 13 | { | ||
| 14 | 	if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t)); | ||
| 15 | 	else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245; | ||
| 16 | |||
| 17 | #if UINTPTR_MAX >= 0xffffffffffffffff | ||
| 18 | 	/* Sacrifice 8 bits of entropy on 64bit to prevent leaking/ | ||
| 19 | 	 * overwriting the canary via string-manipulation functions. | ||
| 20 | 	 * The NULL byte is on the second byte so that off-by-ones can | ||
| 21 | 	 * still be detected. Endianness is taken care of | ||
| 22 | 	 * automatically. */ | ||
| 23 | 	((char *)&__stack_chk_guard)[1] = 0; | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 27 | 	__pthread_self()->canary = __stack_chk_guard; | ||
| 28 | #endif | ||
| 29 | } | ||
| 30 | |||
| 31 | void __stack_chk_fail(void) | ||
| 32 | { | ||
| 33 | 	a_crash(); | ||
| 34 | } | ||
| 35 | |||
| 36 | hidden void __stack_chk_fail_local(void); | ||
| 37 | |||
| 38 | weak_alias(__stack_chk_fail, __stack_chk_fail_local); | ||
| 39 | |||
| 40 | #ifndef __wasilibc_unmodified_upstream | ||
| 41 | #ifdef __wasilibc_use_wasip2 | ||
| 42 | # include <wasi/libc.h> | ||
| 43 | #else | ||
| 44 | # include <wasi/api.h> | ||
| 45 | #endif | ||
| 46 | |||
| 47 | __attribute__((constructor(60))) | ||
| 48 | static void __wasilibc_init_ssp(void) { | ||
| 49 | 	uintptr_t entropy; | ||
| 50 | #ifdef __wasilibc_use_wasip2 | ||
| 51 | int len = sizeof(uintptr_t); | ||
| 52 | |||
| 53 | int r = __wasilibc_random(&entropy, len); | ||
| 54 | #else | ||
| 55 | 	int r = __wasi_random_get((uint8_t *)&entropy, sizeof(uintptr_t)); | ||
| 56 | #endif | ||
| 57 | 	__init_ssp(r ? NULL : &entropy); | ||
| 58 | } | ||
| 59 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/env/clearenv.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | static void dummy(char *old, char *new) {} | ||
| 6 | weak_alias(dummy, __env_rm_add); | ||
| 7 | |||
| 8 | int clearenv() | ||
| 9 | { | ||
| 10 | #ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. | ||
| 11 | #else | ||
| 12 | // This specialized header is included within the function body to arranges for | ||
| 13 | // the environment variables to be lazily initialized. It redefined `__environ`, | ||
| 14 | // so don't remove or reorder it with respect to other code. | ||
| 15 | #include "wasi/libc-environ-compat.h" | ||
| 16 | #endif | ||
| 17 | 	char **e = __environ; | ||
| 18 | 	__environ = 0; | ||
| 19 | 	if (e) while (*e) __env_rm_add(*e++, 0); | ||
| 20 | 	return 0; | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/getenv.c deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | char *getenv(const char *name) | ||
| 6 | { | ||
| 7 | #ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. | ||
| 8 | #else | ||
| 9 | // This specialized header is included within the function body to arranges for | ||
| 10 | // the environment variables to be lazily initialized. It redefined `__environ`, | ||
| 11 | // so don't remove or reorder it with respect to other code. | ||
| 12 | #include "wasi/libc-environ-compat.h" | ||
| 13 | #endif | ||
| 14 | 	size_t l = __strchrnul(name, '=') - name; | ||
| 15 | 	if (l && !name[l] && __environ) | ||
| 16 | 		for (char **e = __environ; *e; e++) | ||
| 17 | 			if (!strncmp(name, *e, l) && l[*e] == '=') | ||
| 18 | 				return *e + l+1; | ||
| 19 | 	return 0; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/putenv.c deleted-53| ... | @@ -1,53 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | static void dummy(char *old, char *new) {} | ||
| 6 | weak_alias(dummy, __env_rm_add); | ||
| 7 | |||
| 8 | int __putenv(char *s, size_t l, char *r) | ||
| 9 | { | ||
| 10 | #ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. | ||
| 11 | #else | ||
| 12 | // This specialized header is included within the function body to arranges for | ||
| 13 | // the environment variables to be lazily initialized. It redefined `__environ`, | ||
| 14 | // so don't remove or reorder it with respect to other code. | ||
| 15 | #include "wasi/libc-environ-compat.h" | ||
| 16 | #endif | ||
| 17 | 	size_t i=0; | ||
| 18 | 	if (__environ) { | ||
| 19 | 		for (char **e = __environ; *e; e++, i++) | ||
| 20 | 			if (!strncmp(s, *e, l+1)) { | ||
| 21 | 				char *tmp = *e; | ||
| 22 | 				*e = s; | ||
| 23 | 				__env_rm_add(tmp, r); | ||
| 24 | 				return 0; | ||
| 25 | 			} | ||
| 26 | 	} | ||
| 27 | 	static char **oldenv; | ||
| 28 | 	char **newenv; | ||
| 29 | 	if (__environ == oldenv) { | ||
| 30 | 		newenv = realloc(oldenv, sizeof *newenv * (i+2)); | ||
| 31 | 		if (!newenv) goto oom; | ||
| 32 | 	} else { | ||
| 33 | 		newenv = malloc(sizeof *newenv * (i+2)); | ||
| 34 | 		if (!newenv) goto oom; | ||
| 35 | 		if (i) memcpy(newenv, __environ, sizeof *newenv * i); | ||
| 36 | 		free(oldenv); | ||
| 37 | 	} | ||
| 38 | 	newenv[i] = s; | ||
| 39 | 	newenv[i+1] = 0; | ||
| 40 | 	__environ = oldenv = newenv; | ||
| 41 | 	if (r) __env_rm_add(0, r); | ||
| 42 | 	return 0; | ||
| 43 | oom: | ||
| 44 | 	free(r); | ||
| 45 | 	return -1; | ||
| 46 | } | ||
| 47 | |||
| 48 | int putenv(char *s) | ||
| 49 | { | ||
| 50 | 	size_t l = __strchrnul(s, '=') - s; | ||
| 51 | 	if (!l || !s[l]) return unsetenv(s); | ||
| 52 | 	return __putenv(s, l, 0); | ||
| 53 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/unsetenv.c deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | static void dummy(char *old, char *new) {} | ||
| 7 | weak_alias(dummy, __env_rm_add); | ||
| 8 | |||
| 9 | int unsetenv(const char *name) | ||
| 10 | { | ||
| 11 | 	size_t l = __strchrnul(name, '=') - name; | ||
| 12 | 	if (!l || name[l]) { | ||
| 13 | 		errno = EINVAL; | ||
| 14 | 		return -1; | ||
| 15 | 	} | ||
| 16 | #ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. | ||
| 17 | #else | ||
| 18 | // This specialized header is included within the function body to arranges for | ||
| 19 | // the environment variables to be lazily initialized. It redefined `__environ`, | ||
| 20 | // so don't remove or reorder it with respect to other code. | ||
| 21 | #include "wasi/libc-environ-compat.h" | ||
| 22 | #endif | ||
| 23 | 	if (__environ) { | ||
| 24 | 		char **e = __environ, **eo = e; | ||
| 25 | 		for (; *e; e++) | ||
| 26 | 			if (!strncmp(name, *e, l) && l[*e] == '=') | ||
| 27 | 				__env_rm_add(*e, 0); | ||
| 28 | 			else if (eo != e) | ||
| 29 | 				*eo++ = *e; | ||
| 30 | 			else | ||
| 31 | 				eo++; | ||
| 32 | 		if (eo != e) *eo = 0; | ||
| 33 | 	} | ||
| 34 | 	return 0; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/errno/__strerror.h deleted-137| ... | @@ -1,137 +0,0 @@ | ||
| 1 | /* The first entry is a catch-all for codes not enumerated here. | ||
| 2 | * This file is included multiple times to declare and define a structure | ||
| 3 | * with these messages, and then to define a lookup table translating | ||
| 4 | * error codes to offsets of corresponding fields in the structure. */ | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream // Print "Success" for ESUCCESS. | ||
| 7 | E(0, "No error information") | ||
| 8 | #else | ||
| 9 | E(0, "Success") | ||
| 10 | #endif | ||
| 11 | |||
| 12 | E(EILSEQ, "Illegal byte sequence") | ||
| 13 | E(EDOM, "Domain error") | ||
| 14 | E(ERANGE, "Result not representable") | ||
| 15 | |||
| 16 | E(ENOTTY, "Not a tty") | ||
| 17 | E(EACCES, "Permission denied") | ||
| 18 | E(EPERM, "Operation not permitted") | ||
| 19 | E(ENOENT, "No such file or directory") | ||
| 20 | E(ESRCH, "No such process") | ||
| 21 | E(EEXIST, "File exists") | ||
| 22 | |||
| 23 | E(EOVERFLOW, "Value too large for data type") | ||
| 24 | E(ENOSPC, "No space left on device") | ||
| 25 | E(ENOMEM, "Out of memory") | ||
| 26 | |||
| 27 | E(EBUSY, "Resource busy") | ||
| 28 | E(EINTR, "Interrupted system call") | ||
| 29 | E(EAGAIN, "Resource temporarily unavailable") | ||
| 30 | E(ESPIPE, "Invalid seek") | ||
| 31 | |||
| 32 | E(EXDEV, "Cross-device link") | ||
| 33 | E(EROFS, "Read-only file system") | ||
| 34 | E(ENOTEMPTY, "Directory not empty") | ||
| 35 | |||
| 36 | E(ECONNRESET, "Connection reset by peer") | ||
| 37 | E(ETIMEDOUT, "Operation timed out") | ||
| 38 | E(ECONNREFUSED, "Connection refused") | ||
| 39 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 40 | E(EHOSTDOWN, "Host is down") | ||
| 41 | #endif | ||
| 42 | E(EHOSTUNREACH, "Host is unreachable") | ||
| 43 | E(EADDRINUSE, "Address in use") | ||
| 44 | |||
| 45 | E(EPIPE, "Broken pipe") | ||
| 46 | E(EIO, "I/O error") | ||
| 47 | E(ENXIO, "No such device or address") | ||
| 48 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 49 | E(ENOTBLK, "Block device required") | ||
| 50 | #endif | ||
| 51 | E(ENODEV, "No such device") | ||
| 52 | E(ENOTDIR, "Not a directory") | ||
| 53 | E(EISDIR, "Is a directory") | ||
| 54 | E(ETXTBSY, "Text file busy") | ||
| 55 | E(ENOEXEC, "Exec format error") | ||
| 56 | |||
| 57 | E(EINVAL, "Invalid argument") | ||
| 58 | |||
| 59 | E(E2BIG, "Argument list too long") | ||
| 60 | E(ELOOP, "Symbolic link loop") | ||
| 61 | E(ENAMETOOLONG, "Filename too long") | ||
| 62 | E(ENFILE, "Too many open files in system") | ||
| 63 | E(EMFILE, "No file descriptors available") | ||
| 64 | E(EBADF, "Bad file descriptor") | ||
| 65 | E(ECHILD, "No child process") | ||
| 66 | E(EFAULT, "Bad address") | ||
| 67 | E(EFBIG, "File too large") | ||
| 68 | E(EMLINK, "Too many links") | ||
| 69 | E(ENOLCK, "No locks available") | ||
| 70 | |||
| 71 | E(EDEADLK, "Resource deadlock would occur") | ||
| 72 | E(ENOTRECOVERABLE, "State not recoverable") | ||
| 73 | E(EOWNERDEAD, "Previous owner died") | ||
| 74 | E(ECANCELED, "Operation canceled") | ||
| 75 | E(ENOSYS, "Function not implemented") | ||
| 76 | E(ENOMSG, "No message of desired type") | ||
| 77 | E(EIDRM, "Identifier removed") | ||
| 78 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 79 | E(ENOSTR, "Device not a stream") | ||
| 80 | E(ENODATA, "No data available") | ||
| 81 | E(ETIME, "Device timeout") | ||
| 82 | E(ENOSR, "Out of streams resources") | ||
| 83 | #endif | ||
| 84 | E(ENOLINK, "Link has been severed") | ||
| 85 | E(EPROTO, "Protocol error") | ||
| 86 | E(EBADMSG, "Bad message") | ||
| 87 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 88 | E(EBADFD, "File descriptor in bad state") | ||
| 89 | #endif | ||
| 90 | E(ENOTSOCK, "Not a socket") | ||
| 91 | E(EDESTADDRREQ, "Destination address required") | ||
| 92 | E(EMSGSIZE, "Message too large") | ||
| 93 | E(EPROTOTYPE, "Protocol wrong type for socket") | ||
| 94 | E(ENOPROTOOPT, "Protocol not available") | ||
| 95 | E(EPROTONOSUPPORT,"Protocol not supported") | ||
| 96 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 97 | E(ESOCKTNOSUPPORT,"Socket type not supported") | ||
| 98 | #endif | ||
| 99 | E(ENOTSUP, "Not supported") | ||
| 100 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 101 | E(EPFNOSUPPORT, "Protocol family not supported") | ||
| 102 | #endif | ||
| 103 | E(EAFNOSUPPORT, "Address family not supported by protocol") | ||
| 104 | E(EADDRNOTAVAIL,"Address not available") | ||
| 105 | E(ENETDOWN, "Network is down") | ||
| 106 | E(ENETUNREACH, "Network unreachable") | ||
| 107 | E(ENETRESET, "Connection reset by network") | ||
| 108 | E(ECONNABORTED, "Connection aborted") | ||
| 109 | E(ENOBUFS, "No buffer space available") | ||
| 110 | E(EISCONN, "Socket is connected") | ||
| 111 | E(ENOTCONN, "Socket not connected") | ||
| 112 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 113 | E(ESHUTDOWN, "Cannot send after socket shutdown") | ||
| 114 | #endif | ||
| 115 | E(EALREADY, "Operation already in progress") | ||
| 116 | E(EINPROGRESS, "Operation in progress") | ||
| 117 | E(ESTALE, "Stale file handle") | ||
| 118 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 119 | E(EREMOTEIO, "Remote I/O error") | ||
| 120 | #endif | ||
| 121 | E(EDQUOT, "Quota exceeded") | ||
| 122 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 123 | E(ENOMEDIUM, "No medium found") | ||
| 124 | E(EMEDIUMTYPE, "Wrong medium type") | ||
| 125 | #endif | ||
| 126 | E(EMULTIHOP, "Multihop attempted") | ||
| 127 | #ifdef __wasilibc_unmodified_upstream // errno value not in WASI | ||
| 128 | E(ENOKEY, "Required key not available") | ||
| 129 | E(EKEYEXPIRED, "Key has expired") | ||
| 130 | E(EKEYREVOKED, "Key has been revoked") | ||
| 131 | E(EKEYREJECTED, "Key was rejected by service") | ||
| 132 | #endif | ||
| 133 | #ifdef __wasilibc_unmodified_upstream // errno value in WASI and not musl | ||
| 134 | #else | ||
| 135 | // WASI adds this errno code. | ||
| 136 | E(ENOTCAPABLE, "Capabilities insufficient") | ||
| 137 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/errno/strerror.c deleted-47| ... | @@ -1,47 +0,0 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include <stddef.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "locale_impl.h" | ||
| 5 | |||
| 6 | /* mips has one error code outside of the 8-bit range due to a | ||
| 7 | * historical typo, so we just remap it. */ | ||
| 8 | #if EDQUOT==1133 | ||
| 9 | #define EDQUOT_ORIG 1133 | ||
| 10 | #undef EDQUOT | ||
| 11 | #define EDQUOT 109 | ||
| 12 | #endif | ||
| 13 | |||
| 14 | static const struct errmsgstr_t { | ||
| 15 | #define E(n, s) char str##n[sizeof(s)]; | ||
| 16 | #include "__strerror.h" | ||
| 17 | #undef E | ||
| 18 | } errmsgstr = { | ||
| 19 | #define E(n, s) s, | ||
| 20 | #include "__strerror.h" | ||
| 21 | #undef E | ||
| 22 | }; | ||
| 23 | |||
| 24 | static const unsigned short errmsgidx[] = { | ||
| 25 | #define E(n, s) [n] = offsetof(struct errmsgstr_t, str##n), | ||
| 26 | #include "__strerror.h" | ||
| 27 | #undef E | ||
| 28 | }; | ||
| 29 | |||
| 30 | char *__strerror_l(int e, locale_t loc) | ||
| 31 | { | ||
| 32 | 	const char *s; | ||
| 33 | #ifdef EDQUOT_ORIG | ||
| 34 | 	if (e==EDQUOT) e=0; | ||
| 35 | 	else if (e==EDQUOT_ORIG) e=EDQUOT; | ||
| 36 | #endif | ||
| 37 | 	if (e >= sizeof errmsgidx / sizeof *errmsgidx) e = 0; | ||
| 38 | 	s = (char *)&errmsgstr + errmsgidx[e]; | ||
| 39 | 	return (char *)LCTRANS(s, LC_MESSAGES, loc); | ||
| 40 | } | ||
| 41 | |||
| 42 | char *strerror(int e) | ||
| 43 | { | ||
| 44 | 	return __strerror_l(e, CURRENT_LOCALE); | ||
| 45 | } | ||
| 46 | |||
| 47 | weak_alias(__strerror_l, strerror_l); | ||
lib/libc/wasi/libc-top-half/musl/src/exit/at_quick_exit.c deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include "libc.h" | ||
| 3 | #include "lock.h" | ||
| 4 | #include "fork_impl.h" | ||
| 5 | |||
| 6 | #define COUNT 32 | ||
| 7 | |||
| 8 | static void (*funcs[COUNT])(void); | ||
| 9 | static int count; | ||
| 10 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 11 | static volatile int lock[1]; | ||
| 12 | volatile int *const __at_quick_exit_lockptr = lock; | ||
| 13 | #endif | ||
| 14 | |||
| 15 | void __funcs_on_quick_exit() | ||
| 16 | { | ||
| 17 | 	void (*func)(void); | ||
| 18 | 	LOCK(lock); | ||
| 19 | 	while (count > 0) { | ||
| 20 | 		func = funcs[--count]; | ||
| 21 | 		UNLOCK(lock); | ||
| 22 | 		func(); | ||
| 23 | 		LOCK(lock); | ||
| 24 | 	} | ||
| 25 | } | ||
| 26 | |||
| 27 | int at_quick_exit(void (*func)(void)) | ||
| 28 | { | ||
| 29 | 	int r = 0; | ||
| 30 | 	LOCK(lock); | ||
| 31 | 	if (count == 32) r = -1; | ||
| 32 | 	else funcs[count++] = func; | ||
| 33 | 	UNLOCK(lock); | ||
| 34 | 	return r; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/atexit.c deleted-77| ... | @@ -1,77 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "libc.h" | ||
| 4 | #include "lock.h" | ||
| 5 | #include "fork_impl.h" | ||
| 6 | |||
| 7 | /* Ensure that at least 32 atexit handlers can be registered without malloc */ | ||
| 8 | #define COUNT 32 | ||
| 9 | |||
| 10 | static struct fl | ||
| 11 | { | ||
| 12 | 	struct fl *next; | ||
| 13 | 	void (*f[COUNT])(void *); | ||
| 14 | 	void *a[COUNT]; | ||
| 15 | } builtin, *head; | ||
| 16 | |||
| 17 | static int slot; | ||
| 18 | |||
| 19 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 20 | static volatile int lock[1]; | ||
| 21 | volatile int *const __atexit_lockptr = lock; | ||
| 22 | #endif | ||
| 23 | |||
| 24 | void __funcs_on_exit() | ||
| 25 | { | ||
| 26 | 	void (*func)(void *), *arg; | ||
| 27 | 	LOCK(lock); | ||
| 28 | 	for (; head; head=head->next, slot=COUNT) while(slot-->0) { | ||
| 29 | 		func = head->f[slot]; | ||
| 30 | 		arg = head->a[slot]; | ||
| 31 | 		UNLOCK(lock); | ||
| 32 | 		func(arg); | ||
| 33 | 		LOCK(lock); | ||
| 34 | 	} | ||
| 35 | } | ||
| 36 | |||
| 37 | void __cxa_finalize(void *dso) | ||
| 38 | { | ||
| 39 | } | ||
| 40 | |||
| 41 | int __cxa_atexit(void (*func)(void *), void *arg, void *dso) | ||
| 42 | { | ||
| 43 | 	LOCK(lock); | ||
| 44 | |||
| 45 | 	/* Defer initialization of head so it can be in BSS */ | ||
| 46 | 	if (!head) head = &builtin; | ||
| 47 | |||
| 48 | 	/* If the current function list is full, add a new one */ | ||
| 49 | 	if (slot==COUNT) { | ||
| 50 | 		struct fl *new_fl = calloc(sizeof(struct fl), 1); | ||
| 51 | 		if (!new_fl) { | ||
| 52 | 			UNLOCK(lock); | ||
| 53 | 			return -1; | ||
| 54 | 		} | ||
| 55 | 		new_fl->next = head; | ||
| 56 | 		head = new_fl; | ||
| 57 | 		slot = 0; | ||
| 58 | 	} | ||
| 59 | |||
| 60 | 	/* Append function to the list. */ | ||
| 61 | 	head->f[slot] = func; | ||
| 62 | 	head->a[slot] = arg; | ||
| 63 | 	slot++; | ||
| 64 | |||
| 65 | 	UNLOCK(lock); | ||
| 66 | 	return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | static void call(void *p) | ||
| 70 | { | ||
| 71 | 	((void (*)(void))(uintptr_t)p)(); | ||
| 72 | } | ||
| 73 | |||
| 74 | int atexit(void (*func)(void)) | ||
| 75 | { | ||
| 76 | 	return __cxa_atexit(call, (void *)(uintptr_t)func, 0); | ||
| 77 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/exit.c deleted-52| ... | @@ -1,52 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | static void dummy() | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | /* atexit.c and __stdio_exit.c override these. the latter is linked | ||
| 10 | * as a consequence of linking either __toread.c or __towrite.c. */ | ||
| 11 | weak_alias(dummy, __funcs_on_exit); | ||
| 12 | weak_alias(dummy, __stdio_exit); | ||
| 13 | #ifdef __wasilibc_unmodified_upstream // fini | ||
| 14 | weak_alias(dummy, _fini); | ||
| 15 | |||
| 16 | extern weak hidden void (*const __fini_array_start)(void), (*const __fini_array_end)(void); | ||
| 17 | |||
| 18 | static void libc_exit_fini(void) | ||
| 19 | { | ||
| 20 | 	uintptr_t a = (uintptr_t)&__fini_array_end; | ||
| 21 | 	for (; a>(uintptr_t)&__fini_array_start; a-=sizeof(void(*)())) | ||
| 22 | 		(*(void (**)())(a-sizeof(void(*)())))(); | ||
| 23 | 	_fini(); | ||
| 24 | } | ||
| 25 | |||
| 26 | weak_alias(libc_exit_fini, __libc_exit_fini); | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #ifdef __wasilibc_unmodified_upstream // WASI libc uses a custom exit | ||
| 30 | _Noreturn void exit(int code) | ||
| 31 | { | ||
| 32 | 	__funcs_on_exit(); | ||
| 33 | 	__libc_exit_fini(); | ||
| 34 | 	__stdio_exit(); | ||
| 35 | 	_Exit(code); | ||
| 36 | } | ||
| 37 | #else | ||
| 38 | // Split out the cleanup functions so that we can call them without calling | ||
| 39 | // _Exit if we don't need to. This allows _start to just return if main | ||
| 40 | // returns 0. | ||
| 41 | void __wasm_call_dtors(void) | ||
| 42 | { | ||
| 43 | 	__funcs_on_exit(); | ||
| 44 | 	__stdio_exit(); | ||
| 45 | } | ||
| 46 | |||
| 47 | _Noreturn void exit(int code) | ||
| 48 | { | ||
| 49 | 	__wasm_call_dtors(); | ||
| 50 | 	_Exit(code); | ||
| 51 | } | ||
| 52 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fcntl/creat.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | |||
| 3 | int creat(const char *filename, mode_t mode) | ||
| 4 | { | ||
| 5 | 	return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(creat, creat64); | ||
lib/libc/wasi/libc-top-half/musl/src/include/arpa/inet.h deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #ifndef ARPA_INET_H | ||
| 2 | #define ARPA_INET_H | ||
| 3 | |||
| 4 | #include "../../../include/arpa/inet.h" | ||
| 5 | |||
| 6 | hidden int __inet_aton(const char *, struct in_addr *); | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/errno.h deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | #ifndef ERRNO_H | ||
| 2 | #define ERRNO_H | ||
| 3 | |||
| 4 | #include "../../include/errno.h" | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream // Use alternate WASI libc headers | ||
| 7 | #ifdef __GNUC__ | ||
| 8 | __attribute__((const)) | ||
| 9 | #endif | ||
| 10 | hidden int *___errno_location(void); | ||
| 11 | |||
| 12 | #undef errno | ||
| 13 | #define errno (*___errno_location()) | ||
| 14 | #else | ||
| 15 | // Use the WASI libc errno. | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/pthread.h deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | #ifndef PTHREAD_H | ||
| 2 | #define PTHREAD_H | ||
| 3 | |||
| 4 | #include "../../include/pthread.h" | ||
| 5 | |||
| 6 | hidden int __pthread_once(pthread_once_t *, void (*)(void)); | ||
| 7 | hidden void __pthread_testcancel(void); | ||
| 8 | hidden int __pthread_setcancelstate(int, int *); | ||
| 9 | hidden int __pthread_create(pthread_t *restrict, const pthread_attr_t *restrict, void *(*)(void *), void *restrict); | ||
| 10 | #ifdef __wasilibc_unmodified_upstream | ||
| 11 | hidden _Noreturn void __pthread_exit(void *); | ||
| 12 | #endif | ||
| 13 | hidden int __pthread_join(pthread_t, void **); | ||
| 14 | hidden int __pthread_mutex_lock(pthread_mutex_t *); | ||
| 15 | hidden int __pthread_mutex_trylock(pthread_mutex_t *); | ||
| 16 | hidden int __pthread_mutex_trylock_owner(pthread_mutex_t *); | ||
| 17 | hidden int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict); | ||
| 18 | hidden int __pthread_mutex_unlock(pthread_mutex_t *); | ||
| 19 | hidden int __private_cond_signal(pthread_cond_t *, int); | ||
| 20 | hidden int __pthread_cond_timedwait(pthread_cond_t *restrict, pthread_mutex_t *restrict, const struct timespec *restrict); | ||
| 21 | hidden int __pthread_key_create(pthread_key_t *, void (*)(void *)); | ||
| 22 | hidden int __pthread_key_delete(pthread_key_t); | ||
| 23 | hidden int __pthread_rwlock_rdlock(pthread_rwlock_t *); | ||
| 24 | hidden int __pthread_rwlock_tryrdlock(pthread_rwlock_t *); | ||
| 25 | hidden int __pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 26 | hidden int __pthread_rwlock_wrlock(pthread_rwlock_t *); | ||
| 27 | hidden int __pthread_rwlock_trywrlock(pthread_rwlock_t *); | ||
| 28 | hidden int __pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 29 | hidden int __pthread_rwlock_unlock(pthread_rwlock_t *); | ||
| 30 | |||
| 31 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/signal.h deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | #ifndef SIGNAL_H | ||
| 2 | #define SIGNAL_H | ||
| 3 | |||
| 4 | #include "../../include/signal.h" | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream // WASI has no sigaction | ||
| 7 | hidden int __sigaction(int, const struct sigaction *, struct sigaction *); | ||
| 8 | |||
| 9 | hidden void __block_all_sigs(void *); | ||
| 10 | hidden void __block_app_sigs(void *); | ||
| 11 | hidden void __restore_sigs(void *); | ||
| 12 | |||
| 13 | hidden void __get_handler_set(sigset_t *); | ||
| 14 | #endif | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/stdio.h deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | #ifndef STDIO_H | ||
| 2 | #define STDIO_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 5 | #define __DEFINED_struct__IO_FILE | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include "../../include/stdio.h" | ||
| 9 | |||
| 10 | #undef stdin | ||
| 11 | #undef stdout | ||
| 12 | #undef stderr | ||
| 13 | |||
| 14 | extern hidden FILE __stdin_FILE; | ||
| 15 | extern hidden FILE __stdout_FILE; | ||
| 16 | extern hidden FILE __stderr_FILE; | ||
| 17 | |||
| 18 | #define stdin (&__stdin_FILE) | ||
| 19 | #define stdout (&__stdout_FILE) | ||
| 20 | #define stderr (&__stderr_FILE) | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/stdlib.h deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #ifndef STDLIB_H | ||
| 2 | #define STDLIB_H | ||
| 3 | |||
| 4 | #include "../../include/stdlib.h" | ||
| 5 | |||
| 6 | hidden int __putenv(char *, size_t, char *); | ||
| 7 | hidden void __env_rm_add(char *, char *); | ||
| 8 | hidden int __mkostemps(char *, int, int); | ||
| 9 | hidden int __ptsname_r(int, char *, size_t); | ||
| 10 | hidden char *__randname(char *); | ||
| 11 | hidden void __qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *); | ||
| 12 | |||
| 13 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/string.h deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #ifndef STRING_H | ||
| 2 | #define STRING_H | ||
| 3 | |||
| 4 | #include "../../include/string.h" | ||
| 5 | |||
| 6 | hidden void *__memrchr(const void *, int, size_t); | ||
| 7 | hidden char *__stpcpy(char *, const char *); | ||
| 8 | hidden char *__stpncpy(char *, const char *, size_t); | ||
| 9 | hidden char *__strchrnul(const char *, int); | ||
| 10 | |||
| 11 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/sys/mman.h deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #ifndef SYS_MMAN_H | ||
| 2 | #define SYS_MMAN_H | ||
| 3 | |||
| 4 | #include "../../../include/sys/mman.h" | ||
| 5 | |||
| 6 | hidden void __vm_wait(void); | ||
| 7 | hidden void __vm_lock(void); | ||
| 8 | hidden void __vm_unlock(void); | ||
| 9 | |||
| 10 | hidden void *__mmap(void *, size_t, int, int, int, off_t); | ||
| 11 | hidden int __munmap(void *, size_t); | ||
| 12 | hidden void *__mremap(void *, size_t, size_t, int, ...); | ||
| 13 | hidden int __madvise(void *, size_t, int); | ||
| 14 | hidden int __mprotect(void *, size_t, int); | ||
| 15 | |||
| 16 | hidden const unsigned char *__map_file(const char *, size_t *); | ||
| 17 | |||
| 18 | hidden char *__shm_mapname(const char *, char *); | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/sys/stat.h deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #ifndef SYS_STAT_H | ||
| 2 | #define SYS_STAT_H | ||
| 3 | |||
| 4 | #include "../../../include/sys/stat.h" | ||
| 5 | |||
| 6 | hidden int __fstat(int, struct stat *); | ||
| 7 | hidden int __fstatat(int, const char *restrict, struct stat *restrict, int); | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/sys/time.h deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #ifndef SYS_TIME_H | ||
| 2 | #define SYS_TIME_H | ||
| 3 | |||
| 4 | #include "../../../include/sys/time.h" | ||
| 5 | |||
| 6 | hidden int __futimesat(int, const char *, const struct timeval [2]); | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/time.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #ifndef TIME_H | ||
| 2 | #define TIME_H | ||
| 3 | |||
| 4 | #include "../../include/time.h" | ||
| 5 | |||
| 6 | hidden int __clock_gettime(clockid_t, struct timespec *); | ||
| 7 | hidden int __clock_nanosleep(clockid_t, int, const struct timespec *, struct timespec *); | ||
| 8 | |||
| 9 | hidden char *__asctime_r(const struct tm *, char *); | ||
| 10 | hidden struct tm *__gmtime_r(const time_t *restrict, struct tm *restrict); | ||
| 11 | hidden struct tm *__localtime_r(const time_t *restrict, struct tm *restrict); | ||
| 12 | |||
| 13 | hidden size_t __strftime_l(char *restrict, size_t, const char *restrict, const struct tm *restrict, locale_t); | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/unistd.h deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #ifndef UNISTD_H | ||
| 2 | #define UNISTD_H | ||
| 3 | |||
| 4 | #include "../../include/unistd.h" | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream // Lazy environment variable init. | ||
| 7 | extern char **__environ; | ||
| 8 | #else | ||
| 9 | // To support lazy initialization of environment variables, `__environ` is | ||
| 10 | // omitted, and a lazy `__wasilibc_environ` is used instead. Use | ||
| 11 | // "wasi/libc-environ-compat.h" in functions that use `__environ`. | ||
| 12 | #include "wasi/libc-environ.h" | ||
| 13 | #endif | ||
| 14 | |||
| 15 | hidden int __dup3(int, int, int); | ||
| 16 | hidden int __mkostemps(char *, int, int); | ||
| 17 | hidden int __execvpe(const char *, char *const *, char *const *); | ||
| 18 | hidden off_t __lseek(int, off_t, int); | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/wchar.h deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #ifndef WCHAR_H | ||
| 2 | #define WCHAR_H | ||
| 3 | |||
| 4 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 5 | #define __DEFINED_struct__IO_FILE | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include "../../include/wchar.h" | ||
| 9 | |||
| 10 | #endif | ||
| 11 | |||
lib/libc/wasi/libc-top-half/musl/src/internal/complex_impl.h deleted-22| ... | @@ -1,22 +0,0 @@ | ||
| 1 | #ifndef _COMPLEX_IMPL_H | ||
| 2 | #define _COMPLEX_IMPL_H | ||
| 3 | |||
| 4 | #include <complex.h> | ||
| 5 | #include "libm.h" | ||
| 6 | |||
| 7 | #undef __CMPLX | ||
| 8 | #undef CMPLX | ||
| 9 | #undef CMPLXF | ||
| 10 | #undef CMPLXL | ||
| 11 | |||
| 12 | #define __CMPLX(x, y, t) \ | ||
| 13 | 	((union { _Complex t __z; t __xy[2]; }){.__xy = {(x),(y)}}.__z) | ||
| 14 | |||
| 15 | #define CMPLX(x, y) __CMPLX(x, y, double) | ||
| 16 | #define CMPLXF(x, y) __CMPLX(x, y, float) | ||
| 17 | #define CMPLXL(x, y) __CMPLX(x, y, long double) | ||
| 18 | |||
| 19 | hidden double complex __ldexp_cexp(double complex,int); | ||
| 20 | hidden float complex __ldexp_cexpf(float complex,int); | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/defsysinfo.c deleted-3| ... | @@ -1,3 +0,0 @@ | ||
| 1 | #include "libc.h" | ||
| 2 | |||
| 3 | size_t __sysinfo; | ||
lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.c deleted-556| ... | @@ -1,556 +0,0 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <math.h> | ||
| 4 | #include <float.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <ctype.h> | ||
| 8 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 9 | #else | ||
| 10 | #include "printscan.h" | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #include "shgetc.h" | ||
| 14 | #include "floatscan.h" | ||
| 15 | |||
| 16 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 17 | |||
| 18 | #define LD_B1B_DIG 2 | ||
| 19 | #define LD_B1B_MAX 9007199, 254740991 | ||
| 20 | #define KMAX 128 | ||
| 21 | |||
| 22 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 23 | |||
| 24 | #define LD_B1B_DIG 3 | ||
| 25 | #define LD_B1B_MAX 18, 446744073, 709551615 | ||
| 26 | #define KMAX 2048 | ||
| 27 | |||
| 28 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 29 | |||
| 30 | #define LD_B1B_DIG 4 | ||
| 31 | #define LD_B1B_MAX 10384593, 717069655, 257060992, 658440191 | ||
| 32 | #define KMAX 2048 | ||
| 33 | |||
| 34 | #else | ||
| 35 | #error Unsupported long double representation | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #define MASK (KMAX-1) | ||
| 39 | |||
| 40 | static long long scanexp(FILE *f, int pok) | ||
| 41 | { | ||
| 42 | 	int c; | ||
| 43 | 	int x; | ||
| 44 | 	long long y; | ||
| 45 | 	int neg = 0; | ||
| 46 | 	 | ||
| 47 | 	c = shgetc(f); | ||
| 48 | 	if (c=='+' || c=='-') { | ||
| 49 | 		neg = (c=='-'); | ||
| 50 | 		c = shgetc(f); | ||
| 51 | 		if (c-'0'>=10U && pok) shunget(f); | ||
| 52 | 	} | ||
| 53 | 	if (c-'0'>=10U) { | ||
| 54 | 		shunget(f); | ||
| 55 | 		return LLONG_MIN; | ||
| 56 | 	} | ||
| 57 | 	for (x=0; c-'0'<10U && x<INT_MAX/10; c = shgetc(f)) | ||
| 58 | 		x = 10*x + c-'0'; | ||
| 59 | 	for (y=x; c-'0'<10U && y<LLONG_MAX/100; c = shgetc(f)) | ||
| 60 | 		y = 10*y + c-'0'; | ||
| 61 | 	for (; c-'0'<10U; c = shgetc(f)); | ||
| 62 | 	shunget(f); | ||
| 63 | 	return neg ? -y : y; | ||
| 64 | } | ||
| 65 | |||
| 66 | |||
| 67 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 68 | static long_double decfloat(FILE *f, int c, int bits, int emin, int sign, int pok) | ||
| 69 | #else | ||
| 70 | static long double decfloat(FILE *f, int c, int bits, int emin, int sign, int pok) | ||
| 71 | #endif | ||
| 72 | { | ||
| 73 | 	uint32_t x[KMAX]; | ||
| 74 | 	static const uint32_t th[] = { LD_B1B_MAX }; | ||
| 75 | 	int i, j, k, a, z; | ||
| 76 | 	long long lrp=0, dc=0; | ||
| 77 | 	long long e10=0; | ||
| 78 | 	int lnz = 0; | ||
| 79 | 	int gotdig = 0, gotrad = 0; | ||
| 80 | 	int rp; | ||
| 81 | 	int e2; | ||
| 82 | 	int emax = -emin-bits+3; | ||
| 83 | 	int denormal = 0; | ||
| 84 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 85 | 	long_double y; | ||
| 86 | 	long_double frac=0; | ||
| 87 | 	long_double bias=0; | ||
| 88 | #else | ||
| 89 | 	long double y; | ||
| 90 | 	long double frac=0; | ||
| 91 | 	long double bias=0; | ||
| 92 | #endif | ||
| 93 | 	static const int p10s[] = { 10, 100, 1000, 10000, | ||
| 94 | 		100000, 1000000, 10000000, 100000000 }; | ||
| 95 | |||
| 96 | 	j=0; | ||
| 97 | 	k=0; | ||
| 98 | |||
| 99 | 	/* Don't let leading zeros consume buffer space */ | ||
| 100 | 	for (; c=='0'; c = shgetc(f)) gotdig=1; | ||
| 101 | 	if (c=='.') { | ||
| 102 | 		gotrad = 1; | ||
| 103 | 		for (c = shgetc(f); c=='0'; c = shgetc(f)) gotdig=1, lrp--; | ||
| 104 | 	} | ||
| 105 | |||
| 106 | 	x[0] = 0; | ||
| 107 | 	for (; c-'0'<10U || c=='.'; c = shgetc(f)) { | ||
| 108 | 		if (c == '.') { | ||
| 109 | 			if (gotrad) break; | ||
| 110 | 			gotrad = 1; | ||
| 111 | 			lrp = dc; | ||
| 112 | 		} else if (k < KMAX-3) { | ||
| 113 | 			dc++; | ||
| 114 | 			if (c!='0') lnz = dc; | ||
| 115 | 			if (j) x[k] = x[k]*10 + c-'0'; | ||
| 116 | 			else x[k] = c-'0'; | ||
| 117 | 			if (++j==9) { | ||
| 118 | 				k++; | ||
| 119 | 				j=0; | ||
| 120 | 			} | ||
| 121 | 			gotdig=1; | ||
| 122 | 		} else { | ||
| 123 | 			dc++; | ||
| 124 | 			if (c!='0') { | ||
| 125 | 				lnz = (KMAX-4)*9; | ||
| 126 | 				x[KMAX-4] |= 1; | ||
| 127 | 			} | ||
| 128 | 		} | ||
| 129 | 	} | ||
| 130 | 	if (!gotrad) lrp=dc; | ||
| 131 | |||
| 132 | 	if (gotdig && (c|32)=='e') { | ||
| 133 | 		e10 = scanexp(f, pok); | ||
| 134 | 		if (e10 == LLONG_MIN) { | ||
| 135 | 			if (pok) { | ||
| 136 | 				shunget(f); | ||
| 137 | 			} else { | ||
| 138 | 				shlim(f, 0); | ||
| 139 | 				return 0; | ||
| 140 | 			} | ||
| 141 | 			e10 = 0; | ||
| 142 | 		} | ||
| 143 | 		lrp += e10; | ||
| 144 | 	} else if (c>=0) { | ||
| 145 | 		shunget(f); | ||
| 146 | 	} | ||
| 147 | 	if (!gotdig) { | ||
| 148 | 		errno = EINVAL; | ||
| 149 | 		shlim(f, 0); | ||
| 150 | 		return 0; | ||
| 151 | 	} | ||
| 152 | |||
| 153 | 	/* Handle zero specially to avoid nasty special cases later */ | ||
| 154 | 	if (!x[0]) return sign * 0.0; | ||
| 155 | |||
| 156 | 	/* Optimize small integers (w/no exponent) and over/under-flow */ | ||
| 157 | 	if (lrp==dc && dc<10 && (bits>30 || x[0]>>bits==0)) | ||
| 158 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 159 | 		return sign * (long_double)x[0]; | ||
| 160 | #else | ||
| 161 | 		return sign * (long double)x[0]; | ||
| 162 | #endif | ||
| 163 | 	if (lrp > -emin/2) { | ||
| 164 | 		errno = ERANGE; | ||
| 165 | 		return sign * LDBL_MAX * LDBL_MAX; | ||
| 166 | 	} | ||
| 167 | 	if (lrp < emin-2*LDBL_MANT_DIG) { | ||
| 168 | 		errno = ERANGE; | ||
| 169 | 		return sign * LDBL_MIN * LDBL_MIN; | ||
| 170 | 	} | ||
| 171 | |||
| 172 | 	/* Align incomplete final B1B digit */ | ||
| 173 | 	if (j) { | ||
| 174 | 		for (; j<9; j++) x[k]*=10; | ||
| 175 | 		k++; | ||
| 176 | 		j=0; | ||
| 177 | 	} | ||
| 178 | |||
| 179 | 	a = 0; | ||
| 180 | 	z = k; | ||
| 181 | 	e2 = 0; | ||
| 182 | 	rp = lrp; | ||
| 183 | |||
| 184 | 	/* Optimize small to mid-size integers (even in exp. notation) */ | ||
| 185 | 	if (lnz<9 && lnz<=rp && rp < 18) { | ||
| 186 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 187 | 		if (rp == 9) return sign * (long_double)x[0]; | ||
| 188 | 		if (rp < 9) return sign * (long_double)x[0] / p10s[8-rp]; | ||
| 189 | #else | ||
| 190 | 		if (rp == 9) return sign * (long double)x[0]; | ||
| 191 | 		if (rp < 9) return sign * (long double)x[0] / p10s[8-rp]; | ||
| 192 | #endif | ||
| 193 | 		int bitlim = bits-3*(int)(rp-9); | ||
| 194 | 		if (bitlim>30 || x[0]>>bitlim==0) | ||
| 195 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 196 | 			return sign * (long_double)x[0] * p10s[rp-10]; | ||
| 197 | #else | ||
| 198 | 			return sign * (long double)x[0] * p10s[rp-10]; | ||
| 199 | #endif | ||
| 200 | 	} | ||
| 201 | |||
| 202 | 	/* Drop trailing zeros */ | ||
| 203 | 	for (; !x[z-1]; z--); | ||
| 204 | |||
| 205 | 	/* Align radix point to B1B digit boundary */ | ||
| 206 | 	if (rp % 9) { | ||
| 207 | 		int rpm9 = rp>=0 ? rp%9 : rp%9+9; | ||
| 208 | 		int p10 = p10s[8-rpm9]; | ||
| 209 | 		uint32_t carry = 0; | ||
| 210 | 		for (k=a; k!=z; k++) { | ||
| 211 | 			uint32_t tmp = x[k] % p10; | ||
| 212 | 			x[k] = x[k]/p10 + carry; | ||
| 213 | 			carry = 1000000000/p10 * tmp; | ||
| 214 | 			if (k==a && !x[k]) { | ||
| 215 | 				a = (a+1 & MASK); | ||
| 216 | 				rp -= 9; | ||
| 217 | 			} | ||
| 218 | 		} | ||
| 219 | 		if (carry) x[z++] = carry; | ||
| 220 | 		rp += 9-rpm9; | ||
| 221 | 	} | ||
| 222 | |||
| 223 | 	/* Upscale until desired number of bits are left of radix point */ | ||
| 224 | 	while (rp < 9*LD_B1B_DIG || (rp == 9*LD_B1B_DIG && x[a]<th[0])) { | ||
| 225 | 		uint32_t carry = 0; | ||
| 226 | 		e2 -= 29; | ||
| 227 | 		for (k=(z-1 & MASK); ; k=(k-1 & MASK)) { | ||
| 228 | 			uint64_t tmp = ((uint64_t)x[k] << 29) + carry; | ||
| 229 | 			if (tmp > 1000000000) { | ||
| 230 | 				carry = tmp / 1000000000; | ||
| 231 | 				x[k] = tmp % 1000000000; | ||
| 232 | 			} else { | ||
| 233 | 				carry = 0; | ||
| 234 | 				x[k] = tmp; | ||
| 235 | 			} | ||
| 236 | 			if (k==(z-1 & MASK) && k!=a && !x[k]) z = k; | ||
| 237 | 			if (k==a) break; | ||
| 238 | 		} | ||
| 239 | 		if (carry) { | ||
| 240 | 			rp += 9; | ||
| 241 | 			a = (a-1 & MASK); | ||
| 242 | 			if (a == z) { | ||
| 243 | 				z = (z-1 & MASK); | ||
| 244 | 				x[z-1 & MASK] |= x[z]; | ||
| 245 | 			} | ||
| 246 | 			x[a] = carry; | ||
| 247 | 		} | ||
| 248 | 	} | ||
| 249 | |||
| 250 | 	/* Downscale until exactly number of bits are left of radix point */ | ||
| 251 | 	for (;;) { | ||
| 252 | 		uint32_t carry = 0; | ||
| 253 | 		int sh = 1; | ||
| 254 | 		for (i=0; i<LD_B1B_DIG; i++) { | ||
| 255 | 			k = (a+i & MASK); | ||
| 256 | 			if (k == z || x[k] < th[i]) { | ||
| 257 | 				i=LD_B1B_DIG; | ||
| 258 | 				break; | ||
| 259 | 			} | ||
| 260 | 			if (x[a+i & MASK] > th[i]) break; | ||
| 261 | 		} | ||
| 262 | 		if (i==LD_B1B_DIG && rp==9*LD_B1B_DIG) break; | ||
| 263 | 		/* FIXME: find a way to compute optimal sh */ | ||
| 264 | 		if (rp > 9+9*LD_B1B_DIG) sh = 9; | ||
| 265 | 		e2 += sh; | ||
| 266 | 		for (k=a; k!=z; k=(k+1 & MASK)) { | ||
| 267 | 			uint32_t tmp = x[k] & (1<<sh)-1; | ||
| 268 | 			x[k] = (x[k]>>sh) + carry; | ||
| 269 | 			carry = (1000000000>>sh) * tmp; | ||
| 270 | 			if (k==a && !x[k]) { | ||
| 271 | 				a = (a+1 & MASK); | ||
| 272 | 				i--; | ||
| 273 | 				rp -= 9; | ||
| 274 | 			} | ||
| 275 | 		} | ||
| 276 | 		if (carry) { | ||
| 277 | 			if ((z+1 & MASK) != a) { | ||
| 278 | 				x[z] = carry; | ||
| 279 | 				z = (z+1 & MASK); | ||
| 280 | 			} else x[z-1 & MASK] |= 1; | ||
| 281 | 		} | ||
| 282 | 	} | ||
| 283 | |||
| 284 | 	/* Assemble desired bits into floating point variable */ | ||
| 285 | 	for (y=i=0; i<LD_B1B_DIG; i++) { | ||
| 286 | 		if ((a+i & MASK)==z) x[(z=(z+1 & MASK))-1] = 0; | ||
| 287 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 288 | 		y = 1000000000.0 * y + x[a+i & MASK]; | ||
| 289 | #else | ||
| 290 | 		y = 1000000000.0L * y + x[a+i & MASK]; | ||
| 291 | #endif | ||
| 292 | 	} | ||
| 293 | |||
| 294 | 	y *= sign; | ||
| 295 | |||
| 296 | 	/* Limit precision for denormal results */ | ||
| 297 | 	if (bits > LDBL_MANT_DIG+e2-emin) { | ||
| 298 | 		bits = LDBL_MANT_DIG+e2-emin; | ||
| 299 | 		if (bits<0) bits=0; | ||
| 300 | 		denormal = 1; | ||
| 301 | 	} | ||
| 302 | |||
| 303 | 	/* Calculate bias term to force rounding, move out lower bits */ | ||
| 304 | 	if (bits < LDBL_MANT_DIG) { | ||
| 305 | 		bias = copysignl(scalbn(1, 2*LDBL_MANT_DIG-bits-1), y); | ||
| 306 | 		frac = fmodl(y, scalbn(1, LDBL_MANT_DIG-bits)); | ||
| 307 | 		y -= frac; | ||
| 308 | 		y += bias; | ||
| 309 | 	} | ||
| 310 | |||
| 311 | 	/* Process tail of decimal input so it can affect rounding */ | ||
| 312 | 	if ((a+i & MASK) != z) { | ||
| 313 | 		uint32_t t = x[a+i & MASK]; | ||
| 314 | 		if (t < 500000000 && (t || (a+i+1 & MASK) != z)) | ||
| 315 | 			frac += 0.25*sign; | ||
| 316 | 		else if (t > 500000000) | ||
| 317 | 			frac += 0.75*sign; | ||
| 318 | 		else if (t == 500000000) { | ||
| 319 | 			if ((a+i+1 & MASK) == z) | ||
| 320 | 				frac += 0.5*sign; | ||
| 321 | 			else | ||
| 322 | 				frac += 0.75*sign; | ||
| 323 | 		} | ||
| 324 | 		if (LDBL_MANT_DIG-bits >= 2 && !fmodl(frac, 1)) | ||
| 325 | 			frac++; | ||
| 326 | 	} | ||
| 327 | |||
| 328 | 	y += frac; | ||
| 329 | 	y -= bias; | ||
| 330 | |||
| 331 | 	if ((e2+LDBL_MANT_DIG & INT_MAX) > emax-5) { | ||
| 332 | 		if (fabsl(y) >= 2/LDBL_EPSILON) { | ||
| 333 | 			if (denormal && bits==LDBL_MANT_DIG+e2-emin) | ||
| 334 | 				denormal = 0; | ||
| 335 | 			y *= 0.5; | ||
| 336 | 			e2++; | ||
| 337 | 		} | ||
| 338 | 		if (e2+LDBL_MANT_DIG>emax || (denormal && frac)) | ||
| 339 | 			errno = ERANGE; | ||
| 340 | 	} | ||
| 341 | |||
| 342 | 	return scalbnl(y, e2); | ||
| 343 | } | ||
| 344 | |||
| 345 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 346 | static long_double hexfloat(FILE *f, int bits, int emin, int sign, int pok) | ||
| 347 | #else | ||
| 348 | static long double hexfloat(FILE *f, int bits, int emin, int sign, int pok) | ||
| 349 | #endif | ||
| 350 | { | ||
| 351 | 	uint32_t x = 0; | ||
| 352 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 353 | 	long_double y = 0; | ||
| 354 | 	long_double scale = 1; | ||
| 355 | 	long_double bias = 0; | ||
| 356 | #else | ||
| 357 | 	long double y = 0; | ||
| 358 | 	long double scale = 1; | ||
| 359 | 	long double bias = 0; | ||
| 360 | #endif | ||
| 361 | 	int gottail = 0, gotrad = 0, gotdig = 0; | ||
| 362 | 	long long rp = 0; | ||
| 363 | 	long long dc = 0; | ||
| 364 | 	long long e2 = 0; | ||
| 365 | 	int d; | ||
| 366 | 	int c; | ||
| 367 | |||
| 368 | 	c = shgetc(f); | ||
| 369 | |||
| 370 | 	/* Skip leading zeros */ | ||
| 371 | 	for (; c=='0'; c = shgetc(f)) gotdig = 1; | ||
| 372 | |||
| 373 | 	if (c=='.') { | ||
| 374 | 		gotrad = 1; | ||
| 375 | 		c = shgetc(f); | ||
| 376 | 		/* Count zeros after the radix point before significand */ | ||
| 377 | 		for (rp=0; c=='0'; c = shgetc(f), rp--) gotdig = 1; | ||
| 378 | 	} | ||
| 379 | |||
| 380 | 	for (; c-'0'<10U || (c|32)-'a'<6U || c=='.'; c = shgetc(f)) { | ||
| 381 | 		if (c=='.') { | ||
| 382 | 			if (gotrad) break; | ||
| 383 | 			rp = dc; | ||
| 384 | 			gotrad = 1; | ||
| 385 | 		} else { | ||
| 386 | 			gotdig = 1; | ||
| 387 | 			if (c > '9') d = (c|32)+10-'a'; | ||
| 388 | 			else d = c-'0'; | ||
| 389 | 			if (dc<8) { | ||
| 390 | 				x = x*16 + d; | ||
| 391 | 			} else if (dc < (LDBL_MANT_DIG+3)/4+1) { | ||
| 392 | 				y += d*(scale/=16); | ||
| 393 | 			} else if (d && !gottail) { | ||
| 394 | 				y += 0.5*scale; | ||
| 395 | 				gottail = 1; | ||
| 396 | 			} | ||
| 397 | 			dc++; | ||
| 398 | 		} | ||
| 399 | 	} | ||
| 400 | 	if (!gotdig) { | ||
| 401 | 		shunget(f); | ||
| 402 | 		if (pok) { | ||
| 403 | 			shunget(f); | ||
| 404 | 			if (gotrad) shunget(f); | ||
| 405 | 		} else { | ||
| 406 | 			shlim(f, 0); | ||
| 407 | 		} | ||
| 408 | 		return sign * 0.0; | ||
| 409 | 	} | ||
| 410 | 	if (!gotrad) rp = dc; | ||
| 411 | 	while (dc<8) x *= 16, dc++; | ||
| 412 | 	if ((c|32)=='p') { | ||
| 413 | 		e2 = scanexp(f, pok); | ||
| 414 | 		if (e2 == LLONG_MIN) { | ||
| 415 | 			if (pok) { | ||
| 416 | 				shunget(f); | ||
| 417 | 			} else { | ||
| 418 | 				shlim(f, 0); | ||
| 419 | 				return 0; | ||
| 420 | 			} | ||
| 421 | 			e2 = 0; | ||
| 422 | 		} | ||
| 423 | 	} else { | ||
| 424 | 		shunget(f); | ||
| 425 | 	} | ||
| 426 | 	e2 += 4*rp - 32; | ||
| 427 | |||
| 428 | 	if (!x) return sign * 0.0; | ||
| 429 | 	if (e2 > -emin) { | ||
| 430 | 		errno = ERANGE; | ||
| 431 | 		return sign * LDBL_MAX * LDBL_MAX; | ||
| 432 | 	} | ||
| 433 | 	if (e2 < emin-2*LDBL_MANT_DIG) { | ||
| 434 | 		errno = ERANGE; | ||
| 435 | 		return sign * LDBL_MIN * LDBL_MIN; | ||
| 436 | 	} | ||
| 437 | |||
| 438 | 	while (x < 0x80000000) { | ||
| 439 | 		if (y>=0.5) { | ||
| 440 | 			x += x + 1; | ||
| 441 | 			y += y - 1; | ||
| 442 | 		} else { | ||
| 443 | 			x += x; | ||
| 444 | 			y += y; | ||
| 445 | 		} | ||
| 446 | 		e2--; | ||
| 447 | 	} | ||
| 448 | |||
| 449 | 	if (bits > 32+e2-emin) { | ||
| 450 | 		bits = 32+e2-emin; | ||
| 451 | 		if (bits<0) bits=0; | ||
| 452 | 	} | ||
| 453 | |||
| 454 | 	if (bits < LDBL_MANT_DIG) | ||
| 455 | 		bias = copysignl(scalbn(1, 32+LDBL_MANT_DIG-bits-1), sign); | ||
| 456 | |||
| 457 | 	if (bits<32 && y && !(x&1)) x++, y=0; | ||
| 458 | |||
| 459 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 460 | 	y = bias + sign*(long_double)x + sign*y; | ||
| 461 | #else | ||
| 462 | 	y = bias + sign*(long double)x + sign*y; | ||
| 463 | #endif | ||
| 464 | 	y -= bias; | ||
| 465 | |||
| 466 | 	if (!y) errno = ERANGE; | ||
| 467 | |||
| 468 | 	return scalbnl(y, e2); | ||
| 469 | } | ||
| 470 | |||
| 471 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 472 | long_double __floatscan(FILE *f, int prec, int pok) | ||
| 473 | #else | ||
| 474 | long double __floatscan(FILE *f, int prec, int pok) | ||
| 475 | #endif | ||
| 476 | { | ||
| 477 | 	int sign = 1; | ||
| 478 | 	size_t i; | ||
| 479 | 	int bits; | ||
| 480 | 	int emin; | ||
| 481 | 	int c; | ||
| 482 | |||
| 483 | 	switch (prec) { | ||
| 484 | 	case 0: | ||
| 485 | 		bits = FLT_MANT_DIG; | ||
| 486 | 		emin = FLT_MIN_EXP-bits; | ||
| 487 | 		break; | ||
| 488 | 	case 1: | ||
| 489 | 		bits = DBL_MANT_DIG; | ||
| 490 | 		emin = DBL_MIN_EXP-bits; | ||
| 491 | 		break; | ||
| 492 | 	case 2: | ||
| 493 | 		bits = LDBL_MANT_DIG; | ||
| 494 | 		emin = LDBL_MIN_EXP-bits; | ||
| 495 | 		break; | ||
| 496 | 	default: | ||
| 497 | 		return 0; | ||
| 498 | 	} | ||
| 499 | |||
| 500 | 	while (isspace((c=shgetc(f)))); | ||
| 501 | |||
| 502 | 	if (c=='+' || c=='-') { | ||
| 503 | 		sign -= 2*(c=='-'); | ||
| 504 | 		c = shgetc(f); | ||
| 505 | 	} | ||
| 506 | |||
| 507 | 	for (i=0; i<8 && (c|32)=="infinity"[i]; i++) | ||
| 508 | 		if (i<7) c = shgetc(f); | ||
| 509 | 	if (i==3 || i==8 || (i>3 && pok)) { | ||
| 510 | 		if (i!=8) { | ||
| 511 | 			shunget(f); | ||
| 512 | 			if (pok) for (; i>3; i--) shunget(f); | ||
| 513 | 		} | ||
| 514 | 		return sign * INFINITY; | ||
| 515 | 	} | ||
| 516 | 	if (!i) for (i=0; i<3 && (c|32)=="nan"[i]; i++) | ||
| 517 | 		if (i<2) c = shgetc(f); | ||
| 518 | 	if (i==3) { | ||
| 519 | 		if (shgetc(f) != '(') { | ||
| 520 | 			shunget(f); | ||
| 521 | 			return NAN; | ||
| 522 | 		} | ||
| 523 | 		for (i=1; ; i++) { | ||
| 524 | 			c = shgetc(f); | ||
| 525 | 			if (c-'0'<10U || c-'A'<26U || c-'a'<26U || c=='_') | ||
| 526 | 				continue; | ||
| 527 | 			if (c==')') return NAN; | ||
| 528 | 			shunget(f); | ||
| 529 | 			if (!pok) { | ||
| 530 | 				errno = EINVAL; | ||
| 531 | 				shlim(f, 0); | ||
| 532 | 				return 0; | ||
| 533 | 			} | ||
| 534 | 			while (i--) shunget(f); | ||
| 535 | 			return NAN; | ||
| 536 | 		} | ||
| 537 | 		return NAN; | ||
| 538 | 	} | ||
| 539 | |||
| 540 | 	if (i) { | ||
| 541 | 		shunget(f); | ||
| 542 | 		errno = EINVAL; | ||
| 543 | 		shlim(f, 0); | ||
| 544 | 		return 0; | ||
| 545 | 	} | ||
| 546 | |||
| 547 | 	if (c=='0') { | ||
| 548 | 		c = shgetc(f); | ||
| 549 | 		if ((c|32) == 'x') | ||
| 550 | 			return hexfloat(f, bits, emin, sign, pok); | ||
| 551 | 		shunget(f); | ||
| 552 | 		c = '0'; | ||
| 553 | 	} | ||
| 554 | |||
| 555 | 	return decfloat(f, c, bits, emin, sign, pok); | ||
| 556 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.h deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #ifndef FLOATSCAN_H | ||
| 2 | #define FLOATSCAN_H | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 7 | hidden long_double __floatscan(FILE *, int, int); | ||
| 8 | #else | ||
| 9 | hidden long double __floatscan(FILE *, int, int); | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/fork_impl.h deleted-23| ... | @@ -1,23 +0,0 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | #ifdef __wasilibc_unmodified_upstream | ||
| 4 | extern hidden volatile int *const __at_quick_exit_lockptr; | ||
| 5 | extern hidden volatile int *const __atexit_lockptr; | ||
| 6 | extern hidden volatile int *const __gettext_lockptr; | ||
| 7 | extern hidden volatile int *const __locale_lockptr; | ||
| 8 | extern hidden volatile int *const __random_lockptr; | ||
| 9 | extern hidden volatile int *const __sem_open_lockptr; | ||
| 10 | extern hidden volatile int *const __stdio_ofl_lockptr; | ||
| 11 | extern hidden volatile int *const __syslog_lockptr; | ||
| 12 | extern hidden volatile int *const __timezone_lockptr; | ||
| 13 | |||
| 14 | extern hidden volatile int *const __bump_lockptr; | ||
| 15 | |||
| 16 | extern hidden volatile int *const __vmlock_lockptr; | ||
| 17 | |||
| 18 | hidden void __malloc_atfork(int); | ||
| 19 | hidden void __ldso_atfork(int); | ||
| 20 | hidden void __pthread_key_atfork(int); | ||
| 21 | |||
| 22 | hidden void __post_Fork(int); | ||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/intscan.c deleted-100| ... | @@ -1,100 +0,0 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <ctype.h> | ||
| 4 | #include "shgetc.h" | ||
| 5 | |||
| 6 | /* Lookup table for digit values. -1==255>=36 -> invalid */ | ||
| 7 | static const unsigned char table[] = { -1, | ||
| 8 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 9 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 10 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 11 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, | ||
| 12 | -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, | ||
| 13 | 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, | ||
| 14 | -1,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24, | ||
| 15 | 25,26,27,28,29,30,31,32,33,34,35,-1,-1,-1,-1,-1, | ||
| 16 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 17 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 18 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 19 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 20 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 21 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 22 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 23 | -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, | ||
| 24 | }; | ||
| 25 | |||
| 26 | unsigned long long __intscan(FILE *f, unsigned base, int pok, unsigned long long lim) | ||
| 27 | { | ||
| 28 | 	const unsigned char *val = table+1; | ||
| 29 | 	int c, neg=0; | ||
| 30 | 	unsigned x; | ||
| 31 | 	unsigned long long y; | ||
| 32 | 	if (base > 36 || base == 1) { | ||
| 33 | 		errno = EINVAL; | ||
| 34 | 		return 0; | ||
| 35 | 	} | ||
| 36 | 	while (isspace((c=shgetc(f)))); | ||
| 37 | 	if (c=='+' || c=='-') { | ||
| 38 | 		neg = -(c=='-'); | ||
| 39 | 		c = shgetc(f); | ||
| 40 | 	} | ||
| 41 | 	if ((base == 0 || base == 16) && c=='0') { | ||
| 42 | 		c = shgetc(f); | ||
| 43 | 		if ((c|32)=='x') { | ||
| 44 | 			c = shgetc(f); | ||
| 45 | 			if (val[c]>=16) { | ||
| 46 | 				shunget(f); | ||
| 47 | 				if (pok) shunget(f); | ||
| 48 | 				else shlim(f, 0); | ||
| 49 | 				return 0; | ||
| 50 | 			} | ||
| 51 | 			base = 16; | ||
| 52 | 		} else if (base == 0) { | ||
| 53 | 			base = 8; | ||
| 54 | 		} | ||
| 55 | 	} else { | ||
| 56 | 		if (base == 0) base = 10; | ||
| 57 | 		if (val[c] >= base) { | ||
| 58 | 			shunget(f); | ||
| 59 | 			shlim(f, 0); | ||
| 60 | 			errno = EINVAL; | ||
| 61 | 			return 0; | ||
| 62 | 		} | ||
| 63 | 	} | ||
| 64 | 	if (base == 10) { | ||
| 65 | 		for (x=0; c-'0'<10U && x<=UINT_MAX/10-1; c=shgetc(f)) | ||
| 66 | 			x = x*10 + (c-'0'); | ||
| 67 | 		for (y=x; c-'0'<10U && y<=ULLONG_MAX/10 && 10*y<=ULLONG_MAX-(c-'0'); c=shgetc(f)) | ||
| 68 | 			y = y*10 + (c-'0'); | ||
| 69 | 		if (c-'0'>=10U) goto done; | ||
| 70 | 	} else if (!(base & base-1)) { | ||
| 71 | 		int bs = "\0\1\2\4\7\3\6\5"[(0x17*base)>>5&7]; | ||
| 72 | 		for (x=0; val[c]<base && x<=UINT_MAX/32; c=shgetc(f)) | ||
| 73 | 			x = x<<bs | val[c]; | ||
| 74 | 		for (y=x; val[c]<base && y<=ULLONG_MAX>>bs; c=shgetc(f)) | ||
| 75 | 			y = y<<bs | val[c]; | ||
| 76 | 	} else { | ||
| 77 | 		for (x=0; val[c]<base && x<=UINT_MAX/36-1; c=shgetc(f)) | ||
| 78 | 			x = x*base + val[c]; | ||
| 79 | 		for (y=x; val[c]<base && y<=ULLONG_MAX/base && base*y<=ULLONG_MAX-val[c]; c=shgetc(f)) | ||
| 80 | 			y = y*base + val[c]; | ||
| 81 | 	} | ||
| 82 | 	if (val[c]<base) { | ||
| 83 | 		for (; val[c]<base; c=shgetc(f)); | ||
| 84 | 		errno = ERANGE; | ||
| 85 | 		y = lim; | ||
| 86 | 		if (lim&1) neg = 0; | ||
| 87 | 	} | ||
| 88 | done: | ||
| 89 | 	shunget(f); | ||
| 90 | 	if (y>=lim) { | ||
| 91 | 		if (!(lim&1) && !neg) { | ||
| 92 | 			errno = ERANGE; | ||
| 93 | 			return lim-1; | ||
| 94 | 		} else if (y>lim) { | ||
| 95 | 			errno = ERANGE; | ||
| 96 | 			return lim; | ||
| 97 | 		} | ||
| 98 | 	} | ||
| 99 | 	return (y^neg)-neg; | ||
| 100 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/libc.c deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #include "libc.h" | ||
| 2 | |||
| 3 | struct __libc __libc; | ||
| 4 | |||
| 5 | size_t __hwcap; | ||
| 6 | char *__progname=0, *__progname_full=0; | ||
| 7 | |||
| 8 | weak_alias(__progname, program_invocation_short_name); | ||
| 9 | weak_alias(__progname_full, program_invocation_name); | ||
lib/libc/wasi/libc-top-half/musl/src/internal/libc.h deleted-76| ... | @@ -1,76 +0,0 @@ | ||
| 1 | #ifndef LIBC_H | ||
| 2 | #define LIBC_H | ||
| 3 | |||
| 4 | #include <stdlib.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <limits.h> | ||
| 7 | |||
| 8 | struct __locale_map; | ||
| 9 | |||
| 10 | struct __locale_struct { | ||
| 11 | 	const struct __locale_map *cat[6]; | ||
| 12 | }; | ||
| 13 | |||
| 14 | struct tls_module { | ||
| 15 | 	struct tls_module *next; | ||
| 16 | 	void *image; | ||
| 17 | 	size_t len, size, align, offset; | ||
| 18 | }; | ||
| 19 | |||
| 20 | struct __libc { | ||
| 21 | #ifdef __wasilibc_unmodified_upstream | ||
| 22 | 	char can_do_threads; | ||
| 23 | #endif | ||
| 24 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 25 | 	char threaded; | ||
| 26 | #endif | ||
| 27 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't currently use any code that needs "secure" mode | ||
| 28 | 	char secure; | ||
| 29 | #endif | ||
| 30 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 31 | 	volatile signed char need_locks; | ||
| 32 | 	int threads_minus_1; | ||
| 33 | #endif | ||
| 34 | #ifdef __wasilibc_unmodified_upstream // WASI has no auxv | ||
| 35 | 	size_t *auxv; | ||
| 36 | #endif | ||
| 37 | #ifdef __wasilibc_unmodified_upstream // WASI use different TLS implement | ||
| 38 | 	struct tls_module *tls_head; | ||
| 39 | 	size_t tls_size, tls_align, tls_cnt; | ||
| 40 | #endif | ||
| 41 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't get the page size from auxv | ||
| 42 | 	size_t page_size; | ||
| 43 | #endif | ||
| 44 | 	struct __locale_struct global_locale; | ||
| 45 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 46 | #else | ||
| 47 | 	struct __locale_struct *current_locale; | ||
| 48 | #endif | ||
| 49 | }; | ||
| 50 | |||
| 51 | #ifndef PAGE_SIZE | ||
| 52 | #define PAGE_SIZE libc.page_size | ||
| 53 | #endif | ||
| 54 | |||
| 55 | extern hidden struct __libc __libc; | ||
| 56 | #define libc __libc | ||
| 57 | |||
| 58 | hidden void __init_libc(char **, char *); | ||
| 59 | hidden void __init_tls(size_t *); | ||
| 60 | hidden void __init_ssp(void *); | ||
| 61 | hidden void __libc_start_init(void); | ||
| 62 | hidden void __funcs_on_exit(void); | ||
| 63 | hidden void __funcs_on_quick_exit(void); | ||
| 64 | hidden void __libc_exit_fini(void); | ||
| 65 | hidden void __fork_handler(int); | ||
| 66 | |||
| 67 | extern hidden size_t __hwcap; | ||
| 68 | extern hidden size_t __sysinfo; | ||
| 69 | extern char *__progname, *__progname_full; | ||
| 70 | |||
| 71 | extern hidden const char __libc_version[]; | ||
| 72 | |||
| 73 | hidden void __synccall(void (*)(void *), void *); | ||
| 74 | hidden int __setxid(int, int, int, int); | ||
| 75 | |||
| 76 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/libm.h deleted-292| ... | @@ -1,292 +0,0 @@ | ||
| 1 | #ifndef _LIBM_H | ||
| 2 | #define _LIBM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <float.h> | ||
| 6 | #include <math.h> | ||
| 7 | #include <endian.h> | ||
| 8 | #include "fp_arch.h" | ||
| 9 | |||
| 10 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 11 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 12 | union ldshape { | ||
| 13 | 	long double f; | ||
| 14 | 	struct { | ||
| 15 | 		uint64_t m; | ||
| 16 | 		uint16_t se; | ||
| 17 | 	} i; | ||
| 18 | }; | ||
| 19 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN | ||
| 20 | /* This is the m68k variant of 80-bit long double, and this definition only works | ||
| 21 | * on archs where the alignment requirement of uint64_t is <= 4. */ | ||
| 22 | union ldshape { | ||
| 23 | 	long double f; | ||
| 24 | 	struct { | ||
| 25 | 		uint16_t se; | ||
| 26 | 		uint16_t pad; | ||
| 27 | 		uint64_t m; | ||
| 28 | 	} i; | ||
| 29 | }; | ||
| 30 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 31 | union ldshape { | ||
| 32 | 	long double f; | ||
| 33 | 	struct { | ||
| 34 | 		uint64_t lo; | ||
| 35 | 		uint32_t mid; | ||
| 36 | 		uint16_t top; | ||
| 37 | 		uint16_t se; | ||
| 38 | 	} i; | ||
| 39 | 	struct { | ||
| 40 | 		uint64_t lo; | ||
| 41 | 		uint64_t hi; | ||
| 42 | 	} i2; | ||
| 43 | }; | ||
| 44 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 && __BYTE_ORDER == __BIG_ENDIAN | ||
| 45 | union ldshape { | ||
| 46 | 	long double f; | ||
| 47 | 	struct { | ||
| 48 | 		uint16_t se; | ||
| 49 | 		uint16_t top; | ||
| 50 | 		uint32_t mid; | ||
| 51 | 		uint64_t lo; | ||
| 52 | 	} i; | ||
| 53 | 	struct { | ||
| 54 | 		uint64_t hi; | ||
| 55 | 		uint64_t lo; | ||
| 56 | 	} i2; | ||
| 57 | }; | ||
| 58 | #else | ||
| 59 | #error Unsupported long double representation | ||
| 60 | #endif | ||
| 61 | |||
| 62 | /* Support non-nearest rounding mode. */ | ||
| 63 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 64 | #define WANT_ROUNDING 1 | ||
| 65 | #else | ||
| 66 | #define WANT_ROUNDING 0 | ||
| 67 | #endif | ||
| 68 | /* Support signaling NaNs. */ | ||
| 69 | #define WANT_SNAN 0 | ||
| 70 | |||
| 71 | #if WANT_SNAN | ||
| 72 | #error SNaN is unsupported | ||
| 73 | #else | ||
| 74 | #define issignalingf_inline(x) 0 | ||
| 75 | #define issignaling_inline(x) 0 | ||
| 76 | #endif | ||
| 77 | |||
| 78 | #ifndef TOINT_INTRINSICS | ||
| 79 | #define TOINT_INTRINSICS 0 | ||
| 80 | #endif | ||
| 81 | |||
| 82 | #if TOINT_INTRINSICS | ||
| 83 | /* Round x to nearest int in all rounding modes, ties have to be rounded | ||
| 84 | consistently with converttoint so the results match. If the result | ||
| 85 | would be outside of [-2^31, 2^31-1] then the semantics is unspecified. */ | ||
| 86 | static double_t roundtoint(double_t); | ||
| 87 | |||
| 88 | /* Convert x to nearest int in all rounding modes, ties have to be rounded | ||
| 89 | consistently with roundtoint. If the result is not representible in an | ||
| 90 | int32_t then the semantics is unspecified. */ | ||
| 91 | static int32_t converttoint(double_t); | ||
| 92 | #endif | ||
| 93 | |||
| 94 | /* Helps static branch prediction so hot path can be better optimized. */ | ||
| 95 | #ifdef __GNUC__ | ||
| 96 | #define predict_true(x) __builtin_expect(!!(x), 1) | ||
| 97 | #define predict_false(x) __builtin_expect(x, 0) | ||
| 98 | #else | ||
| 99 | #define predict_true(x) (x) | ||
| 100 | #define predict_false(x) (x) | ||
| 101 | #endif | ||
| 102 | |||
| 103 | /* Evaluate an expression as the specified type. With standard excess | ||
| 104 | precision handling a type cast or assignment is enough (with | ||
| 105 | -ffloat-store an assignment is required, in old compilers argument | ||
| 106 | passing and return statement may not drop excess precision). */ | ||
| 107 | |||
| 108 | static inline float eval_as_float(float x) | ||
| 109 | { | ||
| 110 | 	float y = x; | ||
| 111 | 	return y; | ||
| 112 | } | ||
| 113 | |||
| 114 | static inline double eval_as_double(double x) | ||
| 115 | { | ||
| 116 | 	double y = x; | ||
| 117 | 	return y; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* fp_barrier returns its input, but limits code transformations | ||
| 121 | as if it had a side-effect (e.g. observable io) and returned | ||
| 122 | an arbitrary value. */ | ||
| 123 | |||
| 124 | #ifndef fp_barrierf | ||
| 125 | #define fp_barrierf fp_barrierf | ||
| 126 | static inline float fp_barrierf(float x) | ||
| 127 | { | ||
| 128 | 	volatile float y = x; | ||
| 129 | 	return y; | ||
| 130 | } | ||
| 131 | #endif | ||
| 132 | |||
| 133 | #ifndef fp_barrier | ||
| 134 | #define fp_barrier fp_barrier | ||
| 135 | static inline double fp_barrier(double x) | ||
| 136 | { | ||
| 137 | 	volatile double y = x; | ||
| 138 | 	return y; | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | |||
| 142 | #ifndef fp_barrierl | ||
| 143 | #define fp_barrierl fp_barrierl | ||
| 144 | static inline long double fp_barrierl(long double x) | ||
| 145 | { | ||
| 146 | 	volatile long double y = x; | ||
| 147 | 	return y; | ||
| 148 | } | ||
| 149 | #endif | ||
| 150 | |||
| 151 | /* fp_force_eval ensures that the input value is computed when that's | ||
| 152 | otherwise unused. To prevent the constant folding of the input | ||
| 153 | expression, an additional fp_barrier may be needed or a compilation | ||
| 154 | mode that does so (e.g. -frounding-math in gcc). Then it can be | ||
| 155 | used to evaluate an expression for its fenv side-effects only. */ | ||
| 156 | |||
| 157 | #ifndef fp_force_evalf | ||
| 158 | #define fp_force_evalf fp_force_evalf | ||
| 159 | static inline void fp_force_evalf(float x) | ||
| 160 | { | ||
| 161 | 	volatile float y; | ||
| 162 | 	y = x; | ||
| 163 | } | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #ifndef fp_force_eval | ||
| 167 | #define fp_force_eval fp_force_eval | ||
| 168 | static inline void fp_force_eval(double x) | ||
| 169 | { | ||
| 170 | 	volatile double y; | ||
| 171 | 	y = x; | ||
| 172 | } | ||
| 173 | #endif | ||
| 174 | |||
| 175 | #ifndef fp_force_evall | ||
| 176 | #define fp_force_evall fp_force_evall | ||
| 177 | static inline void fp_force_evall(long double x) | ||
| 178 | { | ||
| 179 | 	volatile long double y; | ||
| 180 | 	y = x; | ||
| 181 | } | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #ifdef __wasilibc_unmodified_upstream // WASI has no floating-point status flags | ||
| 185 | #define FORCE_EVAL(x) do { \ | ||
| 186 | 	if (sizeof(x) == sizeof(float)) { \ | ||
| 187 | 		fp_force_evalf(x); \ | ||
| 188 | 	} else if (sizeof(x) == sizeof(double)) { \ | ||
| 189 | 		fp_force_eval(x); \ | ||
| 190 | 	} else { \ | ||
| 191 | 		fp_force_evall(x); \ | ||
| 192 | 	} \ | ||
| 193 | } while(0) | ||
| 194 | #else | ||
| 195 | /* WebAssembly doesn't have floating-point status flags, so there's no reason | ||
| 196 | * to force evaluations. */ | ||
| 197 | #define FORCE_EVAL(x) ((void)(x)) | ||
| 198 | #endif | ||
| 199 | |||
| 200 | #define asuint(f) ((union{float _f; uint32_t _i;}){f})._i | ||
| 201 | #define asfloat(i) ((union{uint32_t _i; float _f;}){i})._f | ||
| 202 | #define asuint64(f) ((union{double _f; uint64_t _i;}){f})._i | ||
| 203 | #define asdouble(i) ((union{uint64_t _i; double _f;}){i})._f | ||
| 204 | |||
| 205 | #define EXTRACT_WORDS(hi,lo,d) \ | ||
| 206 | do { \ | ||
| 207 | uint64_t __u = asuint64(d); \ | ||
| 208 | (hi) = __u >> 32; \ | ||
| 209 | (lo) = (uint32_t)__u; \ | ||
| 210 | } while (0) | ||
| 211 | |||
| 212 | #define GET_HIGH_WORD(hi,d) \ | ||
| 213 | do { \ | ||
| 214 | (hi) = asuint64(d) >> 32; \ | ||
| 215 | } while (0) | ||
| 216 | |||
| 217 | #define GET_LOW_WORD(lo,d) \ | ||
| 218 | do { \ | ||
| 219 | (lo) = (uint32_t)asuint64(d); \ | ||
| 220 | } while (0) | ||
| 221 | |||
| 222 | #define INSERT_WORDS(d,hi,lo) \ | ||
| 223 | do { \ | ||
| 224 | (d) = asdouble(((uint64_t)(hi)<<32) | (uint32_t)(lo)); \ | ||
| 225 | } while (0) | ||
| 226 | |||
| 227 | #define SET_HIGH_WORD(d,hi) \ | ||
| 228 | INSERT_WORDS(d, hi, (uint32_t)asuint64(d)) | ||
| 229 | |||
| 230 | #define SET_LOW_WORD(d,lo) \ | ||
| 231 | INSERT_WORDS(d, asuint64(d)>>32, lo) | ||
| 232 | |||
| 233 | #define GET_FLOAT_WORD(w,d) \ | ||
| 234 | do { \ | ||
| 235 | (w) = asuint(d); \ | ||
| 236 | } while (0) | ||
| 237 | |||
| 238 | #define SET_FLOAT_WORD(d,w) \ | ||
| 239 | do { \ | ||
| 240 | (d) = asfloat(w); \ | ||
| 241 | } while (0) | ||
| 242 | |||
| 243 | hidden int __rem_pio2_large(double*,double*,int,int,int); | ||
| 244 | |||
| 245 | hidden int __rem_pio2(double,double*); | ||
| 246 | hidden double __sin(double,double,int); | ||
| 247 | hidden double __cos(double,double); | ||
| 248 | hidden double __tan(double,double,int); | ||
| 249 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 250 | hidden double __expo2(double,double); | ||
| 251 | #else | ||
| 252 | hidden double __expo2(double); | ||
| 253 | #endif | ||
| 254 | |||
| 255 | hidden int __rem_pio2f(float,double*); | ||
| 256 | hidden float __sindf(double); | ||
| 257 | hidden float __cosdf(double); | ||
| 258 | hidden float __tandf(double,int); | ||
| 259 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 260 | hidden float __expo2f(float,float); | ||
| 261 | #else | ||
| 262 | hidden float __expo2f(float); | ||
| 263 | #endif | ||
| 264 | |||
| 265 | hidden int __rem_pio2l(long double, long double *); | ||
| 266 | hidden long double __sinl(long double, long double, int); | ||
| 267 | hidden long double __cosl(long double, long double); | ||
| 268 | hidden long double __tanl(long double, long double, int); | ||
| 269 | |||
| 270 | hidden long double __polevll(long double, const long double *, int); | ||
| 271 | hidden long double __p1evll(long double, const long double *, int); | ||
| 272 | |||
| 273 | extern int __signgam; | ||
| 274 | hidden double __lgamma_r(double, int *); | ||
| 275 | hidden float __lgammaf_r(float, int *); | ||
| 276 | |||
| 277 | /* error handling functions */ | ||
| 278 | hidden float __math_xflowf(uint32_t, float); | ||
| 279 | hidden float __math_uflowf(uint32_t); | ||
| 280 | hidden float __math_oflowf(uint32_t); | ||
| 281 | hidden float __math_divzerof(uint32_t); | ||
| 282 | hidden float __math_invalidf(float); | ||
| 283 | hidden double __math_xflow(uint32_t, double); | ||
| 284 | hidden double __math_uflow(uint32_t); | ||
| 285 | hidden double __math_oflow(uint32_t); | ||
| 286 | hidden double __math_divzero(uint32_t); | ||
| 287 | hidden double __math_invalid(double); | ||
| 288 | #if LDBL_MANT_DIG != DBL_MANT_DIG | ||
| 289 | hidden long double __math_invalidl(long double); | ||
| 290 | #endif | ||
| 291 | |||
| 292 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/locale_impl.h deleted-73| ... | @@ -1,73 +0,0 @@ | ||
| 1 | #ifndef _LOCALE_IMPL_H | ||
| 2 | #define _LOCALE_IMPL_H | ||
| 3 | |||
| 4 | #include <locale.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include "libc.h" | ||
| 7 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 8 | #include "pthread_impl.h" | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #define LOCALE_NAME_MAX 23 | ||
| 12 | |||
| 13 | struct __locale_map { | ||
| 14 | 	const void *map; | ||
| 15 | 	size_t map_size; | ||
| 16 | 	char name[LOCALE_NAME_MAX+1]; | ||
| 17 | 	const struct __locale_map *next; | ||
| 18 | }; | ||
| 19 | |||
| 20 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 21 | extern hidden volatile int __locale_lock[1]; | ||
| 22 | #endif | ||
| 23 | |||
| 24 | extern hidden const struct __locale_map __c_dot_utf8; | ||
| 25 | extern hidden const struct __locale_struct __c_locale; | ||
| 26 | extern hidden const struct __locale_struct __c_dot_utf8_locale; | ||
| 27 | |||
| 28 | hidden const struct __locale_map *__get_locale(int, const char *); | ||
| 29 | hidden const char *__mo_lookup(const void *, size_t, const char *); | ||
| 30 | hidden const char *__lctrans(const char *, const struct __locale_map *); | ||
| 31 | #ifdef __wasilibc_unmodified_upstream | ||
| 32 | hidden const char *__lctrans_cur(const char *); | ||
| 33 | #else | ||
| 34 | // We make this visible in the wasi-libc build because | ||
| 35 | // libwasi-emulated-signal.so needs to import it from libc.so. If we ever | ||
| 36 | // decide to merge libwasi-emulated-signal.so into libc.so, this will no longer | ||
| 37 | // be necessary. | ||
| 38 | const char *__lctrans_cur(const char *); | ||
| 39 | #endif | ||
| 40 | hidden const char *__lctrans_impl(const char *, const struct __locale_map *); | ||
| 41 | hidden int __loc_is_allocated(locale_t); | ||
| 42 | hidden char *__gettextdomain(void); | ||
| 43 | |||
| 44 | #define LOC_MAP_FAILED ((const struct __locale_map *)-1) | ||
| 45 | |||
| 46 | #define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) | ||
| 47 | #define LCTRANS_CUR(msg) __lctrans_cur(msg) | ||
| 48 | |||
| 49 | #define C_LOCALE ((locale_t)&__c_locale) | ||
| 50 | #define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) | ||
| 51 | |||
| 52 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 53 | #define CURRENT_LOCALE (__pthread_self()->locale) | ||
| 54 | |||
| 55 | #define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) | ||
| 56 | #else | ||
| 57 | // If we haven't set up the current_local field yet, do so. Then return an | ||
| 58 | // lvalue for the current_locale field. | ||
| 59 | #define CURRENT_LOCALE \ | ||
| 60 | (*({ \ | ||
| 61 | if (!libc.current_locale) { \ | ||
| 62 | libc.current_locale = &libc.global_locale; \ | ||
| 63 | } \ | ||
| 64 | &libc.current_locale; \ | ||
| 65 | })) | ||
| 66 | |||
| 67 | #define CURRENT_UTF8 (!!CURRENT_LOCALE->cat[LC_CTYPE]) | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #undef MB_CUR_MAX | ||
| 71 | #define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) | ||
| 72 | |||
| 73 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/lock.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #ifndef LOCK_H | ||
| 2 | #define LOCK_H | ||
| 3 | |||
| 4 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 5 | hidden void __lock(volatile int *); | ||
| 6 | hidden void __unlock(volatile int *); | ||
| 7 | #define LOCK(x) __lock(x) | ||
| 8 | #define UNLOCK(x) __unlock(x) | ||
| 9 | #else | ||
| 10 | // No locking needed. | ||
| 11 | #define LOCK(x) ((void)0) | ||
| 12 | #define UNLOCK(x) ((void)0) | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/pthread_impl.h deleted-233| ... | @@ -1,233 +0,0 @@ | ||
| 1 | #ifndef _PTHREAD_IMPL_H | ||
| 2 | #define _PTHREAD_IMPL_H | ||
| 3 | |||
| 4 | #include <pthread.h> | ||
| 5 | #ifdef __wasilibc_unmodified_upstream | ||
| 6 | #include <signal.h> | ||
| 7 | #endif | ||
| 8 | #include <errno.h> | ||
| 9 | #include <limits.h> | ||
| 10 | #ifdef __wasilibc_unmodified_upstream | ||
| 11 | #include <sys/mman.h> | ||
| 12 | #endif | ||
| 13 | #include "libc.h" | ||
| 14 | #ifdef __wasilibc_unmodified_upstream | ||
| 15 | #include "syscall.h" | ||
| 16 | #endif | ||
| 17 | #include "atomic.h" | ||
| 18 | #include "futex.h" | ||
| 19 | |||
| 20 | #include "pthread_arch.h" | ||
| 21 | |||
| 22 | #define pthread __pthread | ||
| 23 | |||
| 24 | struct pthread { | ||
| 25 | 	/* Part 1 -- these fields may be external or | ||
| 26 | 	 * internal (accessed via asm) ABI. Do not change. */ | ||
| 27 | 	struct pthread *self; | ||
| 28 | #ifdef __wasilibc_unmodified_upstream | ||
| 29 | #ifndef TLS_ABOVE_TP | ||
| 30 | 	uintptr_t *dtv; | ||
| 31 | #endif | ||
| 32 | #endif | ||
| 33 | 	struct pthread *prev, *next; /* non-ABI */ | ||
| 34 | 	uintptr_t sysinfo; | ||
| 35 | #ifndef TLS_ABOVE_TP | ||
| 36 | #ifdef CANARY_PAD | ||
| 37 | 	uintptr_t canary_pad; | ||
| 38 | #endif | ||
| 39 | 	uintptr_t canary; | ||
| 40 | #endif | ||
| 41 | |||
| 42 | 	/* Part 2 -- implementation details, non-ABI. */ | ||
| 43 | 	int tid; | ||
| 44 | 	int errno_val; | ||
| 45 | 	volatile int detach_state; | ||
| 46 | 	volatile int cancel; | ||
| 47 | 	volatile unsigned char canceldisable, cancelasync; | ||
| 48 | 	unsigned char tsd_used:1; | ||
| 49 | 	unsigned char dlerror_flag:1; | ||
| 50 | 	unsigned char *map_base; | ||
| 51 | 	size_t map_size; | ||
| 52 | 	void *stack; | ||
| 53 | 	size_t stack_size; | ||
| 54 | 	size_t guard_size; | ||
| 55 | 	void *result; | ||
| 56 | 	struct __ptcb *cancelbuf; | ||
| 57 | 	void **tsd; | ||
| 58 | 	struct { | ||
| 59 | 		volatile void *volatile head; | ||
| 60 | 		long off; | ||
| 61 | 		volatile void *volatile pending; | ||
| 62 | 	} robust_list; | ||
| 63 | 	int h_errno_val; | ||
| 64 | 	volatile int timer_id; | ||
| 65 | 	locale_t locale; | ||
| 66 | 	volatile int killlock[1]; | ||
| 67 | 	char *dlerror_buf; | ||
| 68 | 	void *stdio_locks; | ||
| 69 | |||
| 70 | 	/* Part 3 -- the positions of these fields relative to | ||
| 71 | 	 * the end of the structure is external and internal ABI. */ | ||
| 72 | #ifdef TLS_ABOVE_TP | ||
| 73 | 	uintptr_t canary; | ||
| 74 | 	uintptr_t *dtv; | ||
| 75 | #endif | ||
| 76 | }; | ||
| 77 | |||
| 78 | enum { | ||
| 79 | 	DT_EXITED = 0, | ||
| 80 | 	DT_EXITING, | ||
| 81 | 	DT_JOINABLE, | ||
| 82 | 	DT_DETACHED, | ||
| 83 | }; | ||
| 84 | |||
| 85 | #define __SU (sizeof(size_t)/sizeof(int)) | ||
| 86 | |||
| 87 | #define _a_stacksize __u.__s[0] | ||
| 88 | #define _a_guardsize __u.__s[1] | ||
| 89 | #define _a_stackaddr __u.__s[2] | ||
| 90 | #define _a_detach __u.__i[3*__SU+0] | ||
| 91 | #define _a_sched __u.__i[3*__SU+1] | ||
| 92 | #define _a_policy __u.__i[3*__SU+2] | ||
| 93 | #define _a_prio __u.__i[3*__SU+3] | ||
| 94 | #define _m_type __u.__i[0] | ||
| 95 | #define _m_lock __u.__vi[1] | ||
| 96 | #define _m_waiters __u.__vi[2] | ||
| 97 | #define _m_prev __u.__p[3] | ||
| 98 | #define _m_next __u.__p[4] | ||
| 99 | #define _m_count __u.__i[5] | ||
| 100 | #define _c_shared __u.__p[0] | ||
| 101 | #define _c_seq __u.__vi[2] | ||
| 102 | #define _c_waiters __u.__vi[3] | ||
| 103 | #define _c_clock __u.__i[4] | ||
| 104 | #define _c_lock __u.__vi[8] | ||
| 105 | #define _c_head __u.__p[1] | ||
| 106 | #define _c_tail __u.__p[5] | ||
| 107 | #define _rw_lock __u.__vi[0] | ||
| 108 | #define _rw_waiters __u.__vi[1] | ||
| 109 | #define _rw_shared __u.__i[2] | ||
| 110 | #define _b_lock __u.__vi[0] | ||
| 111 | #define _b_waiters __u.__vi[1] | ||
| 112 | #define _b_limit __u.__i[2] | ||
| 113 | #define _b_count __u.__vi[3] | ||
| 114 | #define _b_waiters2 __u.__vi[4] | ||
| 115 | #define _b_inst __u.__p[3] | ||
| 116 | |||
| 117 | #ifndef TP_OFFSET | ||
| 118 | #define TP_OFFSET 0 | ||
| 119 | #endif | ||
| 120 | |||
| 121 | #ifndef DTP_OFFSET | ||
| 122 | #define DTP_OFFSET 0 | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #ifdef TLS_ABOVE_TP | ||
| 126 | #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + TP_OFFSET) | ||
| 127 | #define __pthread_self() ((pthread_t)(__get_tp() - sizeof(struct __pthread) - TP_OFFSET)) | ||
| 128 | #else | ||
| 129 | #define TP_ADJ(p) (p) | ||
| 130 | #define __pthread_self() ((pthread_t)__get_tp()) | ||
| 131 | #endif | ||
| 132 | |||
| 133 | #ifndef tls_mod_off_t | ||
| 134 | #define tls_mod_off_t size_t | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #define SIGTIMER 32 | ||
| 138 | #define SIGCANCEL 33 | ||
| 139 | #define SIGSYNCCALL 34 | ||
| 140 | |||
| 141 | #define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) | ||
| 142 | #define SIGPT_SET \ | ||
| 143 | 	((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ | ||
| 144 | 	[sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) | ||
| 145 | #define SIGTIMER_SET \ | ||
| 146 | 	((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ | ||
| 147 | 	 0x80000000 }) | ||
| 148 | |||
| 149 | void *__tls_get_addr(tls_mod_off_t *); | ||
| 150 | hidden int __init_tp(void *); | ||
| 151 | hidden void *__copy_tls(unsigned char *); | ||
| 152 | hidden void __reset_tls(); | ||
| 153 | |||
| 154 | hidden void __membarrier_init(void); | ||
| 155 | hidden void __dl_thread_cleanup(void); | ||
| 156 | hidden void __testcancel(); | ||
| 157 | hidden void __do_cleanup_push(struct __ptcb *); | ||
| 158 | hidden void __do_cleanup_pop(struct __ptcb *); | ||
| 159 | hidden void __pthread_tsd_run_dtors(); | ||
| 160 | |||
| 161 | hidden void __pthread_key_delete_synccall(void (*)(void *), void *); | ||
| 162 | hidden int __pthread_key_delete_impl(pthread_key_t); | ||
| 163 | |||
| 164 | extern hidden volatile size_t __pthread_tsd_size; | ||
| 165 | extern hidden void *__pthread_tsd_main[]; | ||
| 166 | extern hidden volatile int __eintr_valid_flag; | ||
| 167 | |||
| 168 | hidden int __clone(int (*)(void *), void *, int, void *, ...); | ||
| 169 | hidden int __set_thread_area(void *); | ||
| 170 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigaction */ | ||
| 171 | hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); | ||
| 172 | #endif | ||
| 173 | hidden void __unmapself(void *, size_t); | ||
| 174 | |||
| 175 | #ifndef __wasilibc_unmodified_upstream | ||
| 176 | hidden int __wasilibc_futex_wait(volatile void *, int, int, int64_t); | ||
| 177 | #endif | ||
| 178 | hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); | ||
| 179 | hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); | ||
| 180 | hidden void __wait(volatile int *, volatile int *, int, int); | ||
| 181 | static inline void __wake(volatile void *addr, int cnt, int priv) | ||
| 182 | { | ||
| 183 | 	if (priv) priv = FUTEX_PRIVATE; | ||
| 184 | 	if (cnt<0) cnt = INT_MAX; | ||
| 185 | #ifdef __wasilibc_unmodified_upstream | ||
| 186 | 	__syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || | ||
| 187 | 	__syscall(SYS_futex, addr, FUTEX_WAKE, cnt); | ||
| 188 | #else | ||
| 189 | #ifdef _REENTRANT | ||
| 190 | 	__builtin_wasm_memory_atomic_notify((int*)addr, cnt); | ||
| 191 | #endif | ||
| 192 | #endif | ||
| 193 | } | ||
| 194 | static inline void __futexwait(volatile void *addr, int val, int priv) | ||
| 195 | { | ||
| 196 | #ifdef __wasilibc_unmodified_upstream | ||
| 197 | 	if (priv) priv = FUTEX_PRIVATE; | ||
| 198 | 	__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS || | ||
| 199 | 	__syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); | ||
| 200 | #else | ||
| 201 | 	__wait(addr, NULL, val, priv); | ||
| 202 | #endif | ||
| 203 | } | ||
| 204 | |||
| 205 | hidden void __acquire_ptc(void); | ||
| 206 | hidden void __release_ptc(void); | ||
| 207 | hidden void __inhibit_ptc(void); | ||
| 208 | |||
| 209 | hidden void __tl_lock(void); | ||
| 210 | hidden void __tl_unlock(void); | ||
| 211 | hidden void __tl_sync(pthread_t); | ||
| 212 | |||
| 213 | extern hidden volatile int __thread_list_lock; | ||
| 214 | |||
| 215 | extern hidden volatile int __abort_lock[1]; | ||
| 216 | |||
| 217 | extern hidden unsigned __default_stacksize; | ||
| 218 | extern hidden unsigned __default_guardsize; | ||
| 219 | |||
| 220 | #define DEFAULT_STACK_SIZE 131072 | ||
| 221 | #ifdef __wasilibc_unmodified_upstream | ||
| 222 | #define DEFAULT_GUARD_SIZE 8192 | ||
| 223 | #else | ||
| 224 | /* guard doesn't make much sense without mprotect. */ | ||
| 225 | #define DEFAULT_GUARD_SIZE 0 | ||
| 226 | #endif | ||
| 227 | |||
| 228 | #define DEFAULT_STACK_MAX (8<<20) | ||
| 229 | #define DEFAULT_GUARD_MAX (1<<20) | ||
| 230 | |||
| 231 | #define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) | ||
| 232 | |||
| 233 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.c deleted-37| ... | @@ -1,37 +0,0 @@ | ||
| 1 | #include "shgetc.h" | ||
| 2 | |||
| 3 | /* The shcnt field stores the number of bytes read so far, offset by | ||
| 4 | * the value of buf-rpos at the last function call (__shlim or __shgetc), | ||
| 5 | * so that between calls the inline shcnt macro can add rpos-buf to get | ||
| 6 | * the actual count. */ | ||
| 7 | |||
| 8 | void __shlim(FILE *f, off_t lim) | ||
| 9 | { | ||
| 10 | 	f->shlim = lim; | ||
| 11 | 	f->shcnt = f->buf - f->rpos; | ||
| 12 | 	/* If lim is nonzero, rend must be a valid pointer. */ | ||
| 13 | 	if (lim && f->rend - f->rpos > lim) | ||
| 14 | 		f->shend = f->rpos + lim; | ||
| 15 | 	else | ||
| 16 | 		f->shend = f->rend; | ||
| 17 | } | ||
| 18 | |||
| 19 | int __shgetc(FILE *f) | ||
| 20 | { | ||
| 21 | 	int c; | ||
| 22 | 	off_t cnt = shcnt(f); | ||
| 23 | 	if (f->shlim && cnt >= f->shlim || (c=__uflow(f)) < 0) { | ||
| 24 | 		f->shcnt = f->buf - f->rpos + cnt; | ||
| 25 | 		f->shend = f->rpos; | ||
| 26 | 		f->shlim = -1; | ||
| 27 | 		return EOF; | ||
| 28 | 	} | ||
| 29 | 	cnt++; | ||
| 30 | 	if (f->shlim && f->rend - f->rpos > f->shlim - cnt) | ||
| 31 | 		f->shend = f->rpos + (f->shlim - cnt); | ||
| 32 | 	else | ||
| 33 | 		f->shend = f->rend; | ||
| 34 | 	f->shcnt = f->buf - f->rpos + cnt; | ||
| 35 | 	if (f->rpos <= f->buf) f->rpos[-1] = c; | ||
| 36 | 	return c; | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.h deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | /* Scan helper "stdio" functions for use by scanf-family and strto*-family | ||
| 4 | * functions. These accept either a valid stdio FILE, or a minimal pseudo | ||
| 5 | * FILE whose buffer pointers point into a null-terminated string. In the | ||
| 6 | * latter case, the sh_fromstring macro should be used to setup the FILE; | ||
| 7 | * the rest of the structure can be left uninitialized. | ||
| 8 | * | ||
| 9 | * To begin using these functions, shlim must first be called on the FILE | ||
| 10 | * to set a field width limit, or 0 for no limit. For string pseudo-FILEs, | ||
| 11 | * a nonzero limit is not valid and produces undefined behavior. After that, | ||
| 12 | * shgetc, shunget, and shcnt are valid as long as no other stdio functions | ||
| 13 | * are called on the stream. | ||
| 14 | * | ||
| 15 | * When used with a real FILE object, shunget has only one byte of pushback | ||
| 16 | * available. Further shunget (up to a limit of the stdio UNGET buffer size) | ||
| 17 | * will adjust the position but will not restore the data to be read again. | ||
| 18 | * This functionality is needed for the wcsto*-family functions, where it's | ||
| 19 | * okay because the FILE will be discarded immediately anyway. When used | ||
| 20 | * with string pseudo-FILEs, shunget has unlimited pushback, back to the | ||
| 21 | * beginning of the string. */ | ||
| 22 | |||
| 23 | hidden void __shlim(FILE *, off_t); | ||
| 24 | hidden int __shgetc(FILE *); | ||
| 25 | |||
| 26 | #define shcnt(f) ((f)->shcnt + ((f)->rpos - (f)->buf)) | ||
| 27 | #define shlim(f, lim) __shlim((f), (lim)) | ||
| 28 | #define shgetc(f) (((f)->rpos != (f)->shend) ? *(f)->rpos++ : __shgetc(f)) | ||
| 29 | #define shunget(f) ((f)->shlim>=0 ? (void)(f)->rpos-- : (void)0) | ||
| 30 | |||
| 31 | #define sh_fromstring(f, s) \ | ||
| 32 | 	((f)->buf = (f)->rpos = (void *)(s), (f)->rend = (void*)-1) | ||
lib/libc/wasi/libc-top-half/musl/src/internal/stdio_impl.h deleted-137| ... | @@ -1,137 +0,0 @@ | ||
| 1 | #ifndef _STDIO_IMPL_H | ||
| 2 | #define _STDIO_IMPL_H | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | #if defined(__wasilibc_unmodified_upstream) | ||
| 6 | #include "syscall.h" | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #define UNGET 8 | ||
| 10 | |||
| 11 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 12 | #define FFINALLOCK(f) ((f)->lock>=0 ? __lockfile((f)) : 0) | ||
| 13 | #define FLOCK(f) int __need_unlock = ((f)->lock>=0 ? __lockfile((f)) : 0) | ||
| 14 | #define FUNLOCK(f) do { if (__need_unlock) __unlockfile((f)); } while (0) | ||
| 15 | #else | ||
| 16 | // No locking needed. | ||
| 17 | #define FFINALLOCK(f) ((void)(f)) | ||
| 18 | #define FLOCK(f) ((void)(f)) | ||
| 19 | #define FUNLOCK(f) ((void)(f)) | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #define F_PERM 1 | ||
| 23 | #define F_NORD 4 | ||
| 24 | #define F_NOWR 8 | ||
| 25 | #define F_EOF 16 | ||
| 26 | #define F_ERR 32 | ||
| 27 | #define F_SVB 64 | ||
| 28 | #define F_APP 128 | ||
| 29 | |||
| 30 | struct _IO_FILE { | ||
| 31 | 	unsigned flags; | ||
| 32 | 	unsigned char *rpos, *rend; | ||
| 33 | 	int (*close)(FILE *); | ||
| 34 | 	unsigned char *wend, *wpos; | ||
| 35 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields. | ||
| 36 | 	unsigned char *mustbezero_1; | ||
| 37 | #endif | ||
| 38 | 	unsigned char *wbase; | ||
| 39 | 	size_t (*read)(FILE *, unsigned char *, size_t); | ||
| 40 | 	size_t (*write)(FILE *, const unsigned char *, size_t); | ||
| 41 | 	off_t (*seek)(FILE *, off_t, int); | ||
| 42 | 	unsigned char *buf; | ||
| 43 | 	size_t buf_size; | ||
| 44 | 	FILE *prev, *next; | ||
| 45 | 	int fd; | ||
| 46 | #ifdef __wasilibc_unmodified_upstream // WASI has no popen | ||
| 47 | 	int pipe_pid; | ||
| 48 | #endif | ||
| 49 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 50 | 	long lockcount; | ||
| 51 | #endif | ||
| 52 | 	int mode; | ||
| 53 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 54 | 	volatile int lock; | ||
| 55 | #endif | ||
| 56 | 	int lbf; | ||
| 57 | 	void *cookie; | ||
| 58 | 	off_t off; | ||
| 59 | 	char *getln_buf; | ||
| 60 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't need backwards-compatibility fields. | ||
| 61 | 	void *mustbezero_2; | ||
| 62 | #endif | ||
| 63 | 	unsigned char *shend; | ||
| 64 | 	off_t shlim, shcnt; | ||
| 65 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 66 | 	FILE *prev_locked, *next_locked; | ||
| 67 | #endif | ||
| 68 | 	struct __locale_struct *locale; | ||
| 69 | }; | ||
| 70 | |||
| 71 | extern hidden FILE *volatile __stdin_used; | ||
| 72 | extern hidden FILE *volatile __stdout_used; | ||
| 73 | extern hidden FILE *volatile __stderr_used; | ||
| 74 | |||
| 75 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 76 | hidden int __lockfile(FILE *); | ||
| 77 | hidden void __unlockfile(FILE *); | ||
| 78 | #endif | ||
| 79 | |||
| 80 | hidden size_t __stdio_read(FILE *, unsigned char *, size_t); | ||
| 81 | hidden size_t __stdio_write(FILE *, const unsigned char *, size_t); | ||
| 82 | hidden size_t __stdout_write(FILE *, const unsigned char *, size_t); | ||
| 83 | hidden off_t __stdio_seek(FILE *, off_t, int); | ||
| 84 | hidden int __stdio_close(FILE *); | ||
| 85 | |||
| 86 | hidden int __toread(FILE *); | ||
| 87 | hidden int __towrite(FILE *); | ||
| 88 | |||
| 89 | hidden void __stdio_exit(void); | ||
| 90 | hidden void __stdio_exit_needed(void); | ||
| 91 | |||
| 92 | #ifdef __wasilibc_unmodified_upstream // wasm has no "protected" visibility | ||
| 93 | #if defined(__PIC__) && (100*__GNUC__+__GNUC_MINOR__ >= 303) | ||
| 94 | __attribute__((visibility("protected"))) | ||
| 95 | #endif | ||
| 96 | #endif | ||
| 97 | int __overflow(FILE *, int), __uflow(FILE *); | ||
| 98 | |||
| 99 | hidden int __fseeko(FILE *, off_t, int); | ||
| 100 | hidden int __fseeko_unlocked(FILE *, off_t, int); | ||
| 101 | hidden off_t __ftello(FILE *); | ||
| 102 | hidden off_t __ftello_unlocked(FILE *); | ||
| 103 | hidden size_t __fwritex(const unsigned char *, size_t, FILE *); | ||
| 104 | hidden int __putc_unlocked(int, FILE *); | ||
| 105 | |||
| 106 | hidden FILE *__fdopen(int, const char *); | ||
| 107 | hidden int __fmodeflags(const char *); | ||
| 108 | |||
| 109 | hidden FILE *__ofl_add(FILE *f); | ||
| 110 | hidden FILE **__ofl_lock(void); | ||
| 111 | hidden void __ofl_unlock(void); | ||
| 112 | |||
| 113 | struct __pthread; | ||
| 114 | hidden void __register_locked_file(FILE *, struct __pthread *); | ||
| 115 | hidden void __unlist_locked_file(FILE *); | ||
| 116 | hidden void __do_orphaned_stdio_locks(void); | ||
| 117 | |||
| 118 | #define MAYBE_WAITERS 0x40000000 | ||
| 119 | |||
| 120 | hidden void __getopt_msg(const char *, const char *, const char *, size_t); | ||
| 121 | |||
| 122 | #define feof(f) ((f)->flags & F_EOF) | ||
| 123 | #define ferror(f) ((f)->flags & F_ERR) | ||
| 124 | |||
| 125 | #define getc_unlocked(f) \ | ||
| 126 | 	( ((f)->rpos != (f)->rend) ? *(f)->rpos++ : __uflow((f)) ) | ||
| 127 | |||
| 128 | #define putc_unlocked(c, f) \ | ||
| 129 | 	( (((unsigned char)(c)!=(f)->lbf && (f)->wpos!=(f)->wend)) \ | ||
| 130 | 	? *(f)->wpos++ = (unsigned char)(c) \ | ||
| 131 | 	: __overflow((f),(unsigned char)(c)) ) | ||
| 132 | |||
| 133 | /* Caller-allocated FILE * operations */ | ||
| 134 | hidden FILE *__fopen_rb_ca(const char *, FILE *, unsigned char *, size_t); | ||
| 135 | hidden int __fclose_ca(FILE *); | ||
| 136 | |||
| 137 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/syscall.h deleted-412| ... | @@ -1,412 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream | ||
| 2 | #ifndef _INTERNAL_SYSCALL_H | ||
| 3 | #define _INTERNAL_SYSCALL_H | ||
| 4 | |||
| 5 | #include <features.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <sys/syscall.h> | ||
| 8 | #include "syscall_arch.h" | ||
| 9 | |||
| 10 | #ifndef SYSCALL_RLIM_INFINITY | ||
| 11 | #define SYSCALL_RLIM_INFINITY (~0ULL) | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #ifndef SYSCALL_MMAP2_UNIT | ||
| 15 | #define SYSCALL_MMAP2_UNIT 4096ULL | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifndef __SYSCALL_LL_PRW | ||
| 19 | #define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x) | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifndef __scc | ||
| 23 | #define __scc(X) ((long) (X)) | ||
| 24 | typedef long syscall_arg_t; | ||
| 25 | #endif | ||
| 26 | |||
| 27 | hidden long __syscall_ret(unsigned long), | ||
| 28 | 	__syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, | ||
| 29 | 	 syscall_arg_t, syscall_arg_t, syscall_arg_t); | ||
| 30 | |||
| 31 | #define __syscall1(n,a) __syscall1(n,__scc(a)) | ||
| 32 | #define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b)) | ||
| 33 | #define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c)) | ||
| 34 | #define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d)) | ||
| 35 | #define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e)) | ||
| 36 | #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) | ||
| 37 | #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)) | ||
| 38 | |||
| 39 | #define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n | ||
| 40 | #define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,) | ||
| 41 | #define __SYSCALL_CONCAT_X(a,b) a##b | ||
| 42 | #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) | ||
| 43 | #define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) | ||
| 44 | |||
| 45 | #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) | ||
| 46 | #define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) | ||
| 47 | |||
| 48 | #define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f)) | ||
| 49 | #define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f)) | ||
| 50 | |||
| 51 | #define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0) | ||
| 52 | #define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0) | ||
| 53 | #define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0) | ||
| 54 | #define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0) | ||
| 55 | #define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0) | ||
| 56 | #define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0) | ||
| 57 | #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)) | ||
| 58 | |||
| 59 | #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__) | ||
| 60 | #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__)) | ||
| 61 | |||
| 62 | 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) | ||
| 63 | { | ||
| 64 | 	long r; | ||
| 65 | 	if (cp) r = __syscall_cp(sys, a, b, c, d, e, f); | ||
| 66 | 	else r = __syscall(sys, a, b, c, d, e, f); | ||
| 67 | 	if (r != -ENOSYS) return r; | ||
| 68 | #ifdef SYS_socketcall | ||
| 69 | 	if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f})); | ||
| 70 | 	else r = __syscall(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f})); | ||
| 71 | #endif | ||
| 72 | 	return r; | ||
| 73 | } | ||
| 74 | #define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \ | ||
| 75 | 	__scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f)) | ||
| 76 | #define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \ | ||
| 77 | 	__scc(a), __scc(b), __scc(c), __scc(d), __scc(e), __scc(f)) | ||
| 78 | |||
| 79 | /* fixup legacy 16-bit junk */ | ||
| 80 | |||
| 81 | #ifdef SYS_getuid32 | ||
| 82 | #undef SYS_lchown | ||
| 83 | #undef SYS_getuid | ||
| 84 | #undef SYS_getgid | ||
| 85 | #undef SYS_geteuid | ||
| 86 | #undef SYS_getegid | ||
| 87 | #undef SYS_setreuid | ||
| 88 | #undef SYS_setregid | ||
| 89 | #undef SYS_getgroups | ||
| 90 | #undef SYS_setgroups | ||
| 91 | #undef SYS_fchown | ||
| 92 | #undef SYS_setresuid | ||
| 93 | #undef SYS_getresuid | ||
| 94 | #undef SYS_setresgid | ||
| 95 | #undef SYS_getresgid | ||
| 96 | #undef SYS_chown | ||
| 97 | #undef SYS_setuid | ||
| 98 | #undef SYS_setgid | ||
| 99 | #undef SYS_setfsuid | ||
| 100 | #undef SYS_setfsgid | ||
| 101 | #define SYS_lchown SYS_lchown32 | ||
| 102 | #define SYS_getuid SYS_getuid32 | ||
| 103 | #define SYS_getgid SYS_getgid32 | ||
| 104 | #define SYS_geteuid SYS_geteuid32 | ||
| 105 | #define SYS_getegid SYS_getegid32 | ||
| 106 | #define SYS_setreuid SYS_setreuid32 | ||
| 107 | #define SYS_setregid SYS_setregid32 | ||
| 108 | #define SYS_getgroups SYS_getgroups32 | ||
| 109 | #define SYS_setgroups SYS_setgroups32 | ||
| 110 | #define SYS_fchown SYS_fchown32 | ||
| 111 | #define SYS_setresuid SYS_setresuid32 | ||
| 112 | #define SYS_getresuid SYS_getresuid32 | ||
| 113 | #define SYS_setresgid SYS_setresgid32 | ||
| 114 | #define SYS_getresgid SYS_getresgid32 | ||
| 115 | #define SYS_chown SYS_chown32 | ||
| 116 | #define SYS_setuid SYS_setuid32 | ||
| 117 | #define SYS_setgid SYS_setgid32 | ||
| 118 | #define SYS_setfsuid SYS_setfsuid32 | ||
| 119 | #define SYS_setfsgid SYS_setfsgid32 | ||
| 120 | #endif | ||
| 121 | |||
| 122 | |||
| 123 | /* fixup legacy 32-bit-vs-lfs64 junk */ | ||
| 124 | |||
| 125 | #ifdef SYS_fcntl64 | ||
| 126 | #undef SYS_fcntl | ||
| 127 | #define SYS_fcntl SYS_fcntl64 | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #ifdef SYS_getdents64 | ||
| 131 | #undef SYS_getdents | ||
| 132 | #define SYS_getdents SYS_getdents64 | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #ifdef SYS_ftruncate64 | ||
| 136 | #undef SYS_ftruncate | ||
| 137 | #undef SYS_truncate | ||
| 138 | #define SYS_ftruncate SYS_ftruncate64 | ||
| 139 | #define SYS_truncate SYS_truncate64 | ||
| 140 | #endif | ||
| 141 | |||
| 142 | #ifdef SYS_stat64 | ||
| 143 | #undef SYS_stat | ||
| 144 | #define SYS_stat SYS_stat64 | ||
| 145 | #endif | ||
| 146 | |||
| 147 | #ifdef SYS_fstat64 | ||
| 148 | #undef SYS_fstat | ||
| 149 | #define SYS_fstat SYS_fstat64 | ||
| 150 | #endif | ||
| 151 | |||
| 152 | #ifdef SYS_lstat64 | ||
| 153 | #undef SYS_lstat | ||
| 154 | #define SYS_lstat SYS_lstat64 | ||
| 155 | #endif | ||
| 156 | |||
| 157 | #ifdef SYS_statfs64 | ||
| 158 | #undef SYS_statfs | ||
| 159 | #define SYS_statfs SYS_statfs64 | ||
| 160 | #endif | ||
| 161 | |||
| 162 | #ifdef SYS_fstatfs64 | ||
| 163 | #undef SYS_fstatfs | ||
| 164 | #define SYS_fstatfs SYS_fstatfs64 | ||
| 165 | #endif | ||
| 166 | |||
| 167 | #if defined(SYS_newfstatat) | ||
| 168 | #undef SYS_fstatat | ||
| 169 | #define SYS_fstatat SYS_newfstatat | ||
| 170 | #elif defined(SYS_fstatat64) | ||
| 171 | #undef SYS_fstatat | ||
| 172 | #define SYS_fstatat SYS_fstatat64 | ||
| 173 | #endif | ||
| 174 | |||
| 175 | #ifdef SYS_ugetrlimit | ||
| 176 | #undef SYS_getrlimit | ||
| 177 | #define SYS_getrlimit SYS_ugetrlimit | ||
| 178 | #endif | ||
| 179 | |||
| 180 | #ifdef SYS__newselect | ||
| 181 | #undef SYS_select | ||
| 182 | #define SYS_select SYS__newselect | ||
| 183 | #endif | ||
| 184 | |||
| 185 | #ifdef SYS_pread64 | ||
| 186 | #undef SYS_pread | ||
| 187 | #undef SYS_pwrite | ||
| 188 | #define SYS_pread SYS_pread64 | ||
| 189 | #define SYS_pwrite SYS_pwrite64 | ||
| 190 | #endif | ||
| 191 | |||
| 192 | #ifdef SYS_fadvise64_64 | ||
| 193 | #undef SYS_fadvise | ||
| 194 | #define SYS_fadvise SYS_fadvise64_64 | ||
| 195 | #elif defined(SYS_fadvise64) | ||
| 196 | #undef SYS_fadvise | ||
| 197 | #define SYS_fadvise SYS_fadvise64 | ||
| 198 | #endif | ||
| 199 | |||
| 200 | #ifdef SYS_sendfile64 | ||
| 201 | #undef SYS_sendfile | ||
| 202 | #define SYS_sendfile SYS_sendfile64 | ||
| 203 | #endif | ||
| 204 | |||
| 205 | #ifdef SYS_timer_settime32 | ||
| 206 | #define SYS_timer_settime SYS_timer_settime32 | ||
| 207 | #endif | ||
| 208 | |||
| 209 | #ifdef SYS_timer_gettime32 | ||
| 210 | #define SYS_timer_gettime SYS_timer_gettime32 | ||
| 211 | #endif | ||
| 212 | |||
| 213 | #ifdef SYS_timerfd_settime32 | ||
| 214 | #define SYS_timerfd_settime SYS_timerfd_settime32 | ||
| 215 | #endif | ||
| 216 | |||
| 217 | #ifdef SYS_timerfd_gettime32 | ||
| 218 | #define SYS_timerfd_gettime SYS_timerfd_gettime32 | ||
| 219 | #endif | ||
| 220 | |||
| 221 | #ifdef SYS_clock_settime32 | ||
| 222 | #define SYS_clock_settime SYS_clock_settime32 | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #ifdef SYS_clock_gettime32 | ||
| 226 | #define SYS_clock_gettime SYS_clock_gettime32 | ||
| 227 | #endif | ||
| 228 | |||
| 229 | #ifdef SYS_clock_getres_time32 | ||
| 230 | #define SYS_clock_getres SYS_clock_getres_time32 | ||
| 231 | #endif | ||
| 232 | |||
| 233 | #ifdef SYS_clock_nanosleep_time32 | ||
| 234 | #define SYS_clock_nanosleep SYS_clock_nanosleep_time32 | ||
| 235 | #endif | ||
| 236 | |||
| 237 | #ifdef SYS_gettimeofday_time32 | ||
| 238 | #define SYS_gettimeofday SYS_gettimeofday_time32 | ||
| 239 | #endif | ||
| 240 | |||
| 241 | #ifdef SYS_settimeofday_time32 | ||
| 242 | #define SYS_settimeofday SYS_settimeofday_time32 | ||
| 243 | #endif | ||
| 244 | |||
| 245 | /* Ensure that the plain syscall names are defined even for "time64-only" | ||
| 246 | * archs. These facilitate callers passing null time arguments, and make | ||
| 247 | * tests for establishing which to use/fallback-to more consistent when | ||
| 248 | * they do need to be called with time arguments. */ | ||
| 249 | |||
| 250 | #ifndef SYS_clock_gettime | ||
| 251 | #define SYS_clock_gettime SYS_clock_gettime64 | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #ifndef SYS_clock_settime | ||
| 255 | #define SYS_clock_settime SYS_clock_settime64 | ||
| 256 | #endif | ||
| 257 | |||
| 258 | #ifndef SYS_clock_adjtime | ||
| 259 | #define SYS_clock_adjtime SYS_clock_adjtime64 | ||
| 260 | #endif | ||
| 261 | |||
| 262 | #ifndef SYS_clock_getres | ||
| 263 | #define SYS_clock_getres SYS_clock_getres_time64 | ||
| 264 | #endif | ||
| 265 | |||
| 266 | #ifndef SYS_clock_nanosleep | ||
| 267 | #define SYS_clock_nanosleep SYS_clock_nanosleep_time64 | ||
| 268 | #endif | ||
| 269 | |||
| 270 | #ifndef SYS_timer_gettime | ||
| 271 | #define SYS_timer_gettime SYS_timer_gettime64 | ||
| 272 | #endif | ||
| 273 | |||
| 274 | #ifndef SYS_timer_settime | ||
| 275 | #define SYS_timer_settime SYS_timer_settime64 | ||
| 276 | #endif | ||
| 277 | |||
| 278 | #ifndef SYS_timerfd_gettime | ||
| 279 | #define SYS_timerfd_gettime SYS_timerfd_gettime64 | ||
| 280 | #endif | ||
| 281 | |||
| 282 | #ifndef SYS_timerfd_settime | ||
| 283 | #define SYS_timerfd_settime SYS_timerfd_settime64 | ||
| 284 | #endif | ||
| 285 | |||
| 286 | #ifndef SYS_utimensat | ||
| 287 | #define SYS_utimensat SYS_utimensat_time64 | ||
| 288 | #endif | ||
| 289 | |||
| 290 | #ifndef SYS_pselect6 | ||
| 291 | #define SYS_pselect6 SYS_pselect6_time64 | ||
| 292 | #endif | ||
| 293 | |||
| 294 | #ifndef SYS_ppoll | ||
| 295 | #define SYS_ppoll SYS_ppoll_time64 | ||
| 296 | #endif | ||
| 297 | |||
| 298 | #ifndef SYS_recvmmsg | ||
| 299 | #define SYS_recvmmsg SYS_recvmmsg_time64 | ||
| 300 | #endif | ||
| 301 | |||
| 302 | #ifndef SYS_mq_timedsend | ||
| 303 | #define SYS_mq_timedsend SYS_mq_timedsend_time64 | ||
| 304 | #endif | ||
| 305 | |||
| 306 | #ifndef SYS_mq_timedreceive | ||
| 307 | #define SYS_mq_timedreceive SYS_mq_timedreceive_time64 | ||
| 308 | #endif | ||
| 309 | |||
| 310 | /* SYS_semtimedop omitted because SYS_ipc may provide it */ | ||
| 311 | |||
| 312 | #ifndef SYS_rt_sigtimedwait | ||
| 313 | #define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64 | ||
| 314 | #endif | ||
| 315 | |||
| 316 | #ifndef SYS_futex | ||
| 317 | #define SYS_futex SYS_futex_time64 | ||
| 318 | #endif | ||
| 319 | |||
| 320 | #ifndef SYS_sched_rr_get_interval | ||
| 321 | #define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64 | ||
| 322 | #endif | ||
| 323 | |||
| 324 | |||
| 325 | |||
| 326 | |||
| 327 | /* socketcall calls */ | ||
| 328 | |||
| 329 | #define __SC_socket 1 | ||
| 330 | #define __SC_bind 2 | ||
| 331 | #define __SC_connect 3 | ||
| 332 | #define __SC_listen 4 | ||
| 333 | #define __SC_accept 5 | ||
| 334 | #define __SC_getsockname 6 | ||
| 335 | #define __SC_getpeername 7 | ||
| 336 | #define __SC_socketpair 8 | ||
| 337 | #define __SC_send 9 | ||
| 338 | #define __SC_recv 10 | ||
| 339 | #define __SC_sendto 11 | ||
| 340 | #define __SC_recvfrom 12 | ||
| 341 | #define __SC_shutdown 13 | ||
| 342 | #define __SC_setsockopt 14 | ||
| 343 | #define __SC_getsockopt 15 | ||
| 344 | #define __SC_sendmsg 16 | ||
| 345 | #define __SC_recvmsg 17 | ||
| 346 | #define __SC_accept4 18 | ||
| 347 | #define __SC_recvmmsg 19 | ||
| 348 | #define __SC_sendmmsg 20 | ||
| 349 | |||
| 350 | /* This is valid only because all socket syscalls are made via | ||
| 351 | * socketcall, which always fills unused argument slots with zeros. */ | ||
| 352 | #ifndef SYS_accept | ||
| 353 | #define SYS_accept SYS_accept4 | ||
| 354 | #endif | ||
| 355 | |||
| 356 | #ifndef SO_RCVTIMEO_OLD | ||
| 357 | #define SO_RCVTIMEO_OLD 20 | ||
| 358 | #endif | ||
| 359 | #ifndef SO_SNDTIMEO_OLD | ||
| 360 | #define SO_SNDTIMEO_OLD 21 | ||
| 361 | #endif | ||
| 362 | |||
| 363 | #define SO_TIMESTAMP_OLD 29 | ||
| 364 | #define SO_TIMESTAMPNS_OLD 35 | ||
| 365 | #define SO_TIMESTAMPING_OLD 37 | ||
| 366 | #define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD | ||
| 367 | #define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD | ||
| 368 | #define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD | ||
| 369 | |||
| 370 | #ifndef SIOCGSTAMP_OLD | ||
| 371 | #define SIOCGSTAMP_OLD 0x8906 | ||
| 372 | #endif | ||
| 373 | #ifndef SIOCGSTAMPNS_OLD | ||
| 374 | #define SIOCGSTAMPNS_OLD 0x8907 | ||
| 375 | #endif | ||
| 376 | |||
| 377 | #ifdef SYS_open | ||
| 378 | #define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE) | ||
| 379 | #define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo) | ||
| 380 | #define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE) | ||
| 381 | #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo) | ||
| 382 | #else | ||
| 383 | #define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) | ||
| 384 | #define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) | ||
| 385 | #define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) | ||
| 386 | #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) | ||
| 387 | #endif | ||
| 388 | |||
| 389 | #define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__) | ||
| 390 | #define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__)) | ||
| 391 | |||
| 392 | #define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__) | ||
| 393 | #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) | ||
| 394 | |||
| 395 | #ifdef SYS_wait4 | ||
| 396 | #define __sys_wait4(a,b,c,d) __syscall(SYS_wait4,a,b,c,d) | ||
| 397 | #define __sys_wait4_cp(a,b,c,d) __syscall_cp(SYS_wait4,a,b,c,d) | ||
| 398 | #else | ||
| 399 | hidden long __emulate_wait4(int, int *, int, void *, int); | ||
| 400 | #define __sys_wait4(a,b,c,d) __emulate_wait4(a,b,c,d,0) | ||
| 401 | #define __sys_wait4_cp(a,b,c,d) __emulate_wait4(a,b,c,d,1) | ||
| 402 | #endif | ||
| 403 | |||
| 404 | #define sys_wait4(a,b,c,d) __syscall_ret(__sys_wait4(a,b,c,d)) | ||
| 405 | #define sys_wait4_cp(a,b,c,d) __syscall_ret(__sys_wait4_cp(a,b,c,d)) | ||
| 406 | |||
| 407 | hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); | ||
| 408 | |||
| 409 | hidden void *__vdsosym(const char *, const char *); | ||
| 410 | |||
| 411 | #endif | ||
| 412 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/locale/catclose.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <nl_types.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <endian.h> | ||
| 5 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 6 | #include <sys/mman.h> | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #define V(p) be32toh(*(uint32_t *)(p)) | ||
| 10 | |||
| 11 | int catclose (nl_catd catd) | ||
| 12 | { | ||
| 13 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 14 | 	char *map = (char *)catd; | ||
| 15 | 	munmap(map, V(map+8)+20); | ||
| 16 | #endif | ||
| 17 | 	return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/catgets.c deleted-44| ... | @@ -1,44 +0,0 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <nl_types.h> | ||
| 3 | #include <endian.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <errno.h> | ||
| 7 | |||
| 8 | #define V(p) be32toh(*(uint32_t *)(p)) | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 11 | static int cmp(const void *a, const void *b) | ||
| 12 | { | ||
| 13 | 	uint32_t x = V(a), y = V(b); | ||
| 14 | 	return x<y ? -1 : x>y ? 1 : 0; | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | |||
| 18 | char *catgets (nl_catd catd, int set_id, int msg_id, const char *s) | ||
| 19 | { | ||
| 20 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 21 | 	const char *map = (const char *)catd; | ||
| 22 | 	uint32_t nsets = V(map+4); | ||
| 23 | 	const char *sets = map+20; | ||
| 24 | 	const char *msgs = map+20+V(map+12); | ||
| 25 | 	const char *strings = map+20+V(map+16); | ||
| 26 | 	uint32_t set_id_be = htobe32(set_id); | ||
| 27 | 	uint32_t msg_id_be = htobe32(msg_id); | ||
| 28 | 	const char *set = bsearch(&set_id_be, sets, nsets, 12, cmp); | ||
| 29 | 	if (!set) { | ||
| 30 | 		errno = ENOMSG; | ||
| 31 | 		return (char *)s; | ||
| 32 | 	} | ||
| 33 | 	uint32_t nmsgs = V(set+4); | ||
| 34 | 	msgs += 12*V(set+8); | ||
| 35 | 	const char *msg = bsearch(&msg_id_be, msgs, nmsgs, 12, cmp); | ||
| 36 | 	if (!msg) { | ||
| 37 | 		errno = ENOMSG; | ||
| 38 | 		return (char *)s; | ||
| 39 | 	} | ||
| 40 | 	return (char *)(strings + V(msg+8)); | ||
| 41 | #else | ||
| 42 | 	return (char *)s; | ||
| 43 | #endif | ||
| 44 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/catopen.c deleted-87| ... | @@ -1,87 +0,0 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <nl_types.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <endian.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <langinfo.h> | ||
| 8 | #include <locale.h> | ||
| 9 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 10 | #include <sys/mman.h> | ||
| 11 | #endif | ||
| 12 | #include "libc.h" | ||
| 13 | |||
| 14 | #define V(p) be32toh(*(uint32_t *)(p)) | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 17 | static nl_catd do_catopen(const char *name) | ||
| 18 | { | ||
| 19 | 	size_t size; | ||
| 20 | 	const unsigned char *map = __map_file(name, &size); | ||
| 21 | 	/* Size recorded in the file must match file size; otherwise | ||
| 22 | 	 * the information needed to unmap the file will be lost. */ | ||
| 23 | 	if (!map || V(map) != 0xff88ff89 || 20+V(map+8) != size) { | ||
| 24 | 		if(map) munmap((void *)map, size); | ||
| 25 | 		errno = ENOENT; | ||
| 26 | 		return (nl_catd)-1; | ||
| 27 | 	} | ||
| 28 | 	return (nl_catd)map; | ||
| 29 | } | ||
| 30 | #endif | ||
| 31 | |||
| 32 | nl_catd catopen(const char *name, int oflag) | ||
| 33 | { | ||
| 34 | #ifdef __wasilibc_unmodified_upstream // wasi-libc doesn't support catgets yet | ||
| 35 | 	nl_catd catd; | ||
| 36 | |||
| 37 | 	if (strchr(name, '/')) return do_catopen(name); | ||
| 38 | |||
| 39 | 	char buf[PATH_MAX]; | ||
| 40 | 	size_t i; | ||
| 41 | 	const char *path, *lang, *p, *z; | ||
| 42 | 	if (libc.secure || !(path = getenv("NLSPATH"))) { | ||
| 43 | 		errno = ENOENT; | ||
| 44 | 		return (nl_catd)-1; | ||
| 45 | 	} | ||
| 46 | 	lang = oflag ? nl_langinfo(_NL_LOCALE_NAME(LC_MESSAGES)) : getenv("LANG"); | ||
| 47 | 	if (!lang) lang = ""; | ||
| 48 | 	for (p=path; *p; p=z) { | ||
| 49 | 		i = 0; | ||
| 50 | 		z = __strchrnul(p, ':'); | ||
| 51 | 		for (; p<z; p++) { | ||
| 52 | 			const char *v; | ||
| 53 | 			size_t l; | ||
| 54 | 			if (*p!='%') v=p, l=1; | ||
| 55 | 			else switch (*++p) { | ||
| 56 | 			case 'N': v=name; l=strlen(v); break; | ||
| 57 | 			case 'L': v=lang; l=strlen(v); break; | ||
| 58 | 			case 'l': v=lang; l=strcspn(v,"_.@"); break; | ||
| 59 | 			case 't': | ||
| 60 | 				v=__strchrnul(lang,'_'); | ||
| 61 | 				if (*v) v++; | ||
| 62 | 				l=strcspn(v,".@"); | ||
| 63 | 				break; | ||
| 64 | 			case 'c': v="UTF-8"; l=5; break; | ||
| 65 | 			case '%': v="%"; l=1; break; | ||
| 66 | 			default: v=0; | ||
| 67 | 			} | ||
| 68 | 			if (!v || l >= sizeof buf - i) { | ||
| 69 | 				break; | ||
| 70 | 			} | ||
| 71 | 			memcpy(buf+i, v, l); | ||
| 72 | 			i += l; | ||
| 73 | 		} | ||
| 74 | 		if (!*z && (p<z || !i)) break; | ||
| 75 | 		if (p<z) continue; | ||
| 76 | 		if (*z) z++; | ||
| 77 | 		buf[i] = 0; | ||
| 78 | 		/* Leading : or :: in NLSPATH is same as %N */ | ||
| 79 | 		catd = do_catopen(i ? buf : name); | ||
| 80 | 		if (catd != (nl_catd)-1) return catd; | ||
| 81 | 	} | ||
| 82 | 	errno = ENOENT; | ||
| 83 | #else | ||
| 84 | 	errno = EOPNOTSUPP; | ||
| 85 | #endif | ||
| 86 | 	return (nl_catd)-1; | ||
| 87 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/locale_map.c deleted-114| ... | @@ -1,114 +0,0 @@ | ||
| 1 | #include <locale.h> | ||
| 2 | #include <string.h> | ||
| 3 | #ifdef __wasilibc_unmodified_upstream // WASI has no mmap | ||
| 4 | #include <sys/mman.h> | ||
| 5 | #endif | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "locale_impl.h" | ||
| 8 | #include "libc.h" | ||
| 9 | #include "lock.h" | ||
| 10 | #include "fork_impl.h" | ||
| 11 | |||
| 12 | const char *__lctrans_impl(const char *msg, const struct __locale_map *lm) | ||
| 13 | { | ||
| 14 | 	const char *trans = 0; | ||
| 15 | 	if (lm) trans = __mo_lookup(lm->map, lm->map_size, msg); | ||
| 16 | 	return trans ? trans : msg; | ||
| 17 | } | ||
| 18 | |||
| 19 | static const char envvars[][12] = { | ||
| 20 | 	"LC_CTYPE", | ||
| 21 | 	"LC_NUMERIC", | ||
| 22 | 	"LC_TIME", | ||
| 23 | 	"LC_COLLATE", | ||
| 24 | 	"LC_MONETARY", | ||
| 25 | 	"LC_MESSAGES", | ||
| 26 | }; | ||
| 27 | |||
| 28 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 29 | volatile int __locale_lock[1]; | ||
| 30 | volatile int *const __locale_lockptr = __locale_lock; | ||
| 31 | #endif | ||
| 32 | |||
| 33 | const struct __locale_map *__get_locale(int cat, const char *val) | ||
| 34 | { | ||
| 35 | 	static void *volatile loc_head; | ||
| 36 | 	const struct __locale_map *p; | ||
| 37 | 	struct __locale_map *new = 0; | ||
| 38 | 	const char *path = 0, *z; | ||
| 39 | 	char buf[256]; | ||
| 40 | 	size_t l, n; | ||
| 41 | |||
| 42 | 	if (!*val) { | ||
| 43 | 		(val = getenv("LC_ALL")) && *val || | ||
| 44 | 		(val = getenv(envvars[cat])) && *val || | ||
| 45 | 		(val = getenv("LANG")) && *val || | ||
| 46 | 		(val = "C.UTF-8"); | ||
| 47 | 	} | ||
| 48 | |||
| 49 | 	/* Limit name length and forbid leading dot or any slashes. */ | ||
| 50 | 	for (n=0; n<LOCALE_NAME_MAX && val[n] && val[n]!='/'; n++); | ||
| 51 | 	if (val[0]=='.' || val[n]) val = "C.UTF-8"; | ||
| 52 | 	int builtin = (val[0]=='C' && !val[1]) | ||
| 53 | 		|| !strcmp(val, "C.UTF-8") | ||
| 54 | 		|| !strcmp(val, "POSIX"); | ||
| 55 | |||
| 56 | 	if (builtin) { | ||
| 57 | 		if (cat == LC_CTYPE && val[1]=='.') | ||
| 58 | 			return (void *)&__c_dot_utf8; | ||
| 59 | 		return 0; | ||
| 60 | 	} | ||
| 61 | |||
| 62 | 	for (p=loc_head; p; p=p->next) | ||
| 63 | 		if (!strcmp(val, p->name)) return p; | ||
| 64 | |||
| 65 | #ifdef __wasilibc_unmodified_upstream // WASI has no mmap, though this code could be made to use something else | ||
| 66 | 	if (!libc.secure) path = getenv("MUSL_LOCPATH"); | ||
| 67 | 	/* FIXME: add a default path? */ | ||
| 68 | |||
| 69 | 	if (path) for (; *path; path=z+!!*z) { | ||
| 70 | 		z = __strchrnul(path, ':'); | ||
| 71 | 		l = z - path; | ||
| 72 | 		if (l >= sizeof buf - n - 2) continue; | ||
| 73 | 		memcpy(buf, path, l); | ||
| 74 | 		buf[l] = '/'; | ||
| 75 | 		memcpy(buf+l+1, val, n); | ||
| 76 | 		buf[l+1+n] = 0; | ||
| 77 | 		size_t map_size; | ||
| 78 | 		const void *map = __map_file(buf, &map_size); | ||
| 79 | 		if (map) { | ||
| 80 | 			new = malloc(sizeof *new); | ||
| 81 | 			if (!new) { | ||
| 82 | 				__munmap((void *)map, map_size); | ||
| 83 | 				break; | ||
| 84 | 			} | ||
| 85 | 			new->map = map; | ||
| 86 | 			new->map_size = map_size; | ||
| 87 | 			memcpy(new->name, val, n); | ||
| 88 | 			new->name[n] = 0; | ||
| 89 | 			new->next = loc_head; | ||
| 90 | 			loc_head = new; | ||
| 91 | 			break; | ||
| 92 | 		} | ||
| 93 | 	} | ||
| 94 | #endif | ||
| 95 | |||
| 96 | 	/* If no locale definition was found, make a locale map | ||
| 97 | 	 * object anyway to store the name, which is kept for the | ||
| 98 | 	 * sake of being able to do message translations at the | ||
| 99 | 	 * application level. */ | ||
| 100 | 	if (!new && (new = malloc(sizeof *new))) { | ||
| 101 | 		new->map = __c_dot_utf8.map; | ||
| 102 | 		new->map_size = __c_dot_utf8.map_size; | ||
| 103 | 		memcpy(new->name, val, n); | ||
| 104 | 		new->name[n] = 0; | ||
| 105 | 		new->next = loc_head; | ||
| 106 | 		loc_head = new; | ||
| 107 | 	} | ||
| 108 | |||
| 109 | 	/* For LC_CTYPE, never return a null pointer unless the | ||
| 110 | 	 * requested name was "C" or "POSIX". */ | ||
| 111 | 	if (!new && cat == LC_CTYPE) new = (void *)&__c_dot_utf8; | ||
| 112 | |||
| 113 | 	return new; | ||
| 114 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/newlocale.c deleted-67| ... | @@ -1,67 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 4 | #include <pthread.h> | ||
| 5 | #endif | ||
| 6 | #include "locale_impl.h" | ||
| 7 | #include "lock.h" | ||
| 8 | |||
| 9 | static int default_locale_init_done; | ||
| 10 | static struct __locale_struct default_locale, default_ctype_locale; | ||
| 11 | |||
| 12 | int __loc_is_allocated(locale_t loc) | ||
| 13 | { | ||
| 14 | 	return loc && loc != C_LOCALE && loc != UTF8_LOCALE | ||
| 15 | 		&& loc != &default_locale && loc != &default_ctype_locale; | ||
| 16 | } | ||
| 17 | |||
| 18 | static locale_t do_newlocale(int mask, const char *name, locale_t loc) | ||
| 19 | { | ||
| 20 | 	struct __locale_struct tmp; | ||
| 21 | |||
| 22 | 	for (int i=0; i<LC_ALL; i++) { | ||
| 23 | 		tmp.cat[i] = (!(mask & (1<<i)) && loc) ? loc->cat[i] : | ||
| 24 | 			__get_locale(i, (mask & (1<<i)) ? name : ""); | ||
| 25 | 		if (tmp.cat[i] == LOC_MAP_FAILED) | ||
| 26 | 			return 0; | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	/* For locales with allocated storage, modify in-place. */ | ||
| 30 | 	if (__loc_is_allocated(loc)) { | ||
| 31 | 		*loc = tmp; | ||
| 32 | 		return loc; | ||
| 33 | 	} | ||
| 34 | |||
| 35 | 	/* Otherwise, first see if we can use one of the builtin locales. | ||
| 36 | 	 * This makes the common usage case for newlocale, getting a C locale | ||
| 37 | 	 * with predictable behavior, very fast, and more importantly, fail-safe. */ | ||
| 38 | 	if (!memcmp(&tmp, C_LOCALE, sizeof tmp)) return C_LOCALE; | ||
| 39 | 	if (!memcmp(&tmp, UTF8_LOCALE, sizeof tmp)) return UTF8_LOCALE; | ||
| 40 | |||
| 41 | 	/* And provide builtins for the initial default locale, and a | ||
| 42 | 	 * variant of the C locale honoring the default locale's encoding. */ | ||
| 43 | 	if (!default_locale_init_done) { | ||
| 44 | 		for (int i=0; i<LC_ALL; i++) | ||
| 45 | 			default_locale.cat[i] = __get_locale(i, ""); | ||
| 46 | 		default_ctype_locale.cat[LC_CTYPE] = default_locale.cat[LC_CTYPE]; | ||
| 47 | 		default_locale_init_done = 1; | ||
| 48 | 	} | ||
| 49 | 	if (!memcmp(&tmp, &default_locale, sizeof tmp)) return &default_locale; | ||
| 50 | 	if (!memcmp(&tmp, &default_ctype_locale, sizeof tmp)) | ||
| 51 | 		return &default_ctype_locale; | ||
| 52 | |||
| 53 | 	/* If no builtin locale matched, attempt to allocate and copy. */ | ||
| 54 | 	if ((loc = malloc(sizeof *loc))) *loc = tmp; | ||
| 55 | |||
| 56 | 	return loc; | ||
| 57 | } | ||
| 58 | |||
| 59 | locale_t __newlocale(int mask, const char *name, locale_t loc) | ||
| 60 | { | ||
| 61 | 	LOCK(__locale_lock); | ||
| 62 | 	loc = do_newlocale(mask, name, loc); | ||
| 63 | 	UNLOCK(__locale_lock); | ||
| 64 | 	return loc; | ||
| 65 | } | ||
| 66 | |||
| 67 | weak_alias(__newlocale, newlocale); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/uselocale.c deleted-27| ... | @@ -1,27 +0,0 @@ | ||
| 1 | #include "locale_impl.h" | ||
| 2 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | #endif | ||
| 5 | #include "libc.h" | ||
| 6 | |||
| 7 | locale_t __uselocale(locale_t new) | ||
| 8 | { | ||
| 9 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 10 | 	pthread_t self = __pthread_self(); | ||
| 11 | 	locale_t old = self->locale; | ||
| 12 | #else | ||
| 13 | 	locale_t old = libc.current_locale; | ||
| 14 | 	if (!old) old = LC_GLOBAL_LOCALE; | ||
| 15 | #endif | ||
| 16 | 	locale_t global = &libc.global_locale; | ||
| 17 | |||
| 18 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 19 | 	if (new) self->locale = new == LC_GLOBAL_LOCALE ? global : new; | ||
| 20 | #else | ||
| 21 | 	if (new) libc.current_locale = new == LC_GLOBAL_LOCALE ? global : new; | ||
| 22 | #endif | ||
| 23 | |||
| 24 | 	return old == global ? LC_GLOBAL_LOCALE : old; | ||
| 25 | } | ||
| 26 | |||
| 27 | weak_alias(__uselocale, uselocale); | ||
lib/libc/wasi/libc-top-half/musl/src/math/__expo2.c deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* k is such that k*ln2 has minimal relative error and x - kln2 > log(DBL_MIN) */ | ||
| 4 | static const int k = 2043; | ||
| 5 | static const double kln2 = 0x1.62066151add8bp+10; | ||
| 6 | |||
| 7 | /* exp(x)/2 for x >= log(DBL_MAX), slightly better than 0.5*exp(x/2)*exp(x/2) */ | ||
| 8 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 9 | double __expo2(double x, double sign) | ||
| 10 | #else | ||
| 11 | double __expo2(double x) | ||
| 12 | #endif | ||
| 13 | { | ||
| 14 | 	double scale; | ||
| 15 | |||
| 16 | 	/* note that k is odd and scale*scale overflows */ | ||
| 17 | 	INSERT_WORDS(scale, (uint32_t)(0x3ff + k/2) << 20, 0); | ||
| 18 | 	/* exp(x - k ln2) * 2**(k-1) */ | ||
| 19 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 20 | 	/* in directed rounding correct sign before rounding or overflow is important */ | ||
| 21 | 	return exp(x - kln2) * (sign * scale) * scale; | ||
| 22 | #else | ||
| 23 | 	return exp(x - kln2) * scale * scale; | ||
| 24 | #endif | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__expo2f.c deleted-25| ... | @@ -1,25 +0,0 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* k is such that k*ln2 has minimal relative error and x - kln2 > log(FLT_MIN) */ | ||
| 4 | static const int k = 235; | ||
| 5 | static const float kln2 = 0x1.45c778p+7f; | ||
| 6 | |||
| 7 | /* expf(x)/2 for x >= log(FLT_MAX), slightly better than 0.5f*expf(x/2)*expf(x/2) */ | ||
| 8 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 9 | float __expo2f(float x, float sign) | ||
| 10 | #else | ||
| 11 | float __expo2f(float x) | ||
| 12 | #endif | ||
| 13 | { | ||
| 14 | 	float scale; | ||
| 15 | |||
| 16 | 	/* note that k is odd and scale*scale overflows */ | ||
| 17 | 	SET_FLOAT_WORD(scale, (uint32_t)(0x7f + k/2) << 23); | ||
| 18 | 	/* exp(x - k ln2) * 2**(k-1) */ | ||
| 19 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 20 | 	/* in directed rounding correct sign before rounding or overflow is important */ | ||
| 21 | 	return expf(x - kln2) * (sign * scale) * scale; | ||
| 22 | #else | ||
| 23 | 	return expf(x - kln2) * scale * scale; | ||
| 24 | #endif | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2.c deleted-194| ... | @@ -1,194 +0,0 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunSoft, a Sun Microsystems, Inc. business. | ||
| 7 | * Permission to use, copy, modify, and distribute this | ||
| 8 | * software is freely granted, provided that this notice | ||
| 9 | * is preserved. | ||
| 10 | * ==================================================== | ||
| 11 | * | ||
| 12 | * Optimized by Bruce D. Evans. | ||
| 13 | */ | ||
| 14 | /* __rem_pio2(x,y) | ||
| 15 | * | ||
| 16 | * return the remainder of x rem pi/2 in y[0]+y[1] | ||
| 17 | * use __rem_pio2_large() for large x | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include "libm.h" | ||
| 21 | |||
| 22 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 23 | #define EPS DBL_EPSILON | ||
| 24 | #elif FLT_EVAL_METHOD==2 | ||
| 25 | #define EPS LDBL_EPSILON | ||
| 26 | #endif | ||
| 27 | |||
| 28 | /* | ||
| 29 | * invpio2: 53 bits of 2/pi | ||
| 30 | * pio2_1: first 33 bit of pi/2 | ||
| 31 | * pio2_1t: pi/2 - pio2_1 | ||
| 32 | * pio2_2: second 33 bit of pi/2 | ||
| 33 | * pio2_2t: pi/2 - (pio2_1+pio2_2) | ||
| 34 | * pio2_3: third 33 bit of pi/2 | ||
| 35 | * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) | ||
| 36 | */ | ||
| 37 | static const double | ||
| 38 | toint = 1.5/EPS, | ||
| 39 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 40 | pio4 = 0x1.921fb54442d18p-1, | ||
| 41 | #endif | ||
| 42 | invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ | ||
| 43 | pio2_1 = 1.57079632673412561417e+00, /* 0x3FF921FB, 0x54400000 */ | ||
| 44 | pio2_1t = 6.07710050650619224932e-11, /* 0x3DD0B461, 0x1A626331 */ | ||
| 45 | pio2_2 = 6.07710050630396597660e-11, /* 0x3DD0B461, 0x1A600000 */ | ||
| 46 | pio2_2t = 2.02226624879595063154e-21, /* 0x3BA3198A, 0x2E037073 */ | ||
| 47 | pio2_3 = 2.02226624871116645580e-21, /* 0x3BA3198A, 0x2E000000 */ | ||
| 48 | pio2_3t = 8.47842766036889956997e-32; /* 0x397B839A, 0x252049C1 */ | ||
| 49 | |||
| 50 | /* caller must handle the case when reduction is not needed: |x| ~<= pi/4 */ | ||
| 51 | int __rem_pio2(double x, double *y) | ||
| 52 | { | ||
| 53 | 	union {double f; uint64_t i;} u = {x}; | ||
| 54 | 	double_t z,w,t,r,fn; | ||
| 55 | 	double tx[3],ty[2]; | ||
| 56 | 	uint32_t ix; | ||
| 57 | 	int sign, n, ex, ey, i; | ||
| 58 | |||
| 59 | 	sign = u.i>>63; | ||
| 60 | 	ix = u.i>>32 & 0x7fffffff; | ||
| 61 | 	if (ix <= 0x400f6a7a) { /* |x| ~<= 5pi/4 */ | ||
| 62 | 		if ((ix & 0xfffff) == 0x921fb) /* |x| ~= pi/2 or 2pi/2 */ | ||
| 63 | 			goto medium; /* cancellation -- use medium case */ | ||
| 64 | 		if (ix <= 0x4002d97c) { /* |x| ~<= 3pi/4 */ | ||
| 65 | 			if (!sign) { | ||
| 66 | 				z = x - pio2_1; /* one round good to 85 bits */ | ||
| 67 | 				y[0] = z - pio2_1t; | ||
| 68 | 				y[1] = (z-y[0]) - pio2_1t; | ||
| 69 | 				return 1; | ||
| 70 | 			} else { | ||
| 71 | 				z = x + pio2_1; | ||
| 72 | 				y[0] = z + pio2_1t; | ||
| 73 | 				y[1] = (z-y[0]) + pio2_1t; | ||
| 74 | 				return -1; | ||
| 75 | 			} | ||
| 76 | 		} else { | ||
| 77 | 			if (!sign) { | ||
| 78 | 				z = x - 2*pio2_1; | ||
| 79 | 				y[0] = z - 2*pio2_1t; | ||
| 80 | 				y[1] = (z-y[0]) - 2*pio2_1t; | ||
| 81 | 				return 2; | ||
| 82 | 			} else { | ||
| 83 | 				z = x + 2*pio2_1; | ||
| 84 | 				y[0] = z + 2*pio2_1t; | ||
| 85 | 				y[1] = (z-y[0]) + 2*pio2_1t; | ||
| 86 | 				return -2; | ||
| 87 | 			} | ||
| 88 | 		} | ||
| 89 | 	} | ||
| 90 | 	if (ix <= 0x401c463b) { /* |x| ~<= 9pi/4 */ | ||
| 91 | 		if (ix <= 0x4015fdbc) { /* |x| ~<= 7pi/4 */ | ||
| 92 | 			if (ix == 0x4012d97c) /* |x| ~= 3pi/2 */ | ||
| 93 | 				goto medium; | ||
| 94 | 			if (!sign) { | ||
| 95 | 				z = x - 3*pio2_1; | ||
| 96 | 				y[0] = z - 3*pio2_1t; | ||
| 97 | 				y[1] = (z-y[0]) - 3*pio2_1t; | ||
| 98 | 				return 3; | ||
| 99 | 			} else { | ||
| 100 | 				z = x + 3*pio2_1; | ||
| 101 | 				y[0] = z + 3*pio2_1t; | ||
| 102 | 				y[1] = (z-y[0]) + 3*pio2_1t; | ||
| 103 | 				return -3; | ||
| 104 | 			} | ||
| 105 | 		} else { | ||
| 106 | 			if (ix == 0x401921fb) /* |x| ~= 4pi/2 */ | ||
| 107 | 				goto medium; | ||
| 108 | 			if (!sign) { | ||
| 109 | 				z = x - 4*pio2_1; | ||
| 110 | 				y[0] = z - 4*pio2_1t; | ||
| 111 | 				y[1] = (z-y[0]) - 4*pio2_1t; | ||
| 112 | 				return 4; | ||
| 113 | 			} else { | ||
| 114 | 				z = x + 4*pio2_1; | ||
| 115 | 				y[0] = z + 4*pio2_1t; | ||
| 116 | 				y[1] = (z-y[0]) + 4*pio2_1t; | ||
| 117 | 				return -4; | ||
| 118 | 			} | ||
| 119 | 		} | ||
| 120 | 	} | ||
| 121 | 	if (ix < 0x413921fb) { /* |x| ~< 2^20*(pi/2), medium size */ | ||
| 122 | medium: | ||
| 123 | 		/* rint(x/(pi/2)) */ | ||
| 124 | 		fn = (double_t)x*invpio2 + toint - toint; | ||
| 125 | 		n = (int32_t)fn; | ||
| 126 | 		r = x - fn*pio2_1; | ||
| 127 | 		w = fn*pio2_1t; /* 1st round, good to 85 bits */ | ||
| 128 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 129 | 		/* Matters with directed rounding. */ | ||
| 130 | 		if (predict_false(r - w < -pio4)) { | ||
| 131 | 			n--; | ||
| 132 | 			fn--; | ||
| 133 | 			r = x - fn*pio2_1; | ||
| 134 | 			w = fn*pio2_1t; | ||
| 135 | 		} else if (predict_false(r - w > pio4)) { | ||
| 136 | 			n++; | ||
| 137 | 			fn++; | ||
| 138 | 			r = x - fn*pio2_1; | ||
| 139 | 			w = fn*pio2_1t; | ||
| 140 | 		} | ||
| 141 | #endif | ||
| 142 | 		y[0] = r - w; | ||
| 143 | 		u.f = y[0]; | ||
| 144 | 		ey = u.i>>52 & 0x7ff; | ||
| 145 | 		ex = ix>>20; | ||
| 146 | 		if (ex - ey > 16) { /* 2nd round, good to 118 bits */ | ||
| 147 | 			t = r; | ||
| 148 | 			w = fn*pio2_2; | ||
| 149 | 			r = t - w; | ||
| 150 | 			w = fn*pio2_2t - ((t-r)-w); | ||
| 151 | 			y[0] = r - w; | ||
| 152 | 			u.f = y[0]; | ||
| 153 | 			ey = u.i>>52 & 0x7ff; | ||
| 154 | 			if (ex - ey > 49) { /* 3rd round, good to 151 bits, covers all cases */ | ||
| 155 | 				t = r; | ||
| 156 | 				w = fn*pio2_3; | ||
| 157 | 				r = t - w; | ||
| 158 | 				w = fn*pio2_3t - ((t-r)-w); | ||
| 159 | 				y[0] = r - w; | ||
| 160 | 			} | ||
| 161 | 		} | ||
| 162 | 		y[1] = (r - y[0]) - w; | ||
| 163 | 		return n; | ||
| 164 | 	} | ||
| 165 | 	/* | ||
| 166 | 	 * all other (large) arguments | ||
| 167 | 	 */ | ||
| 168 | 	if (ix >= 0x7ff00000) { /* x is inf or NaN */ | ||
| 169 | 		y[0] = y[1] = x - x; | ||
| 170 | 		return 0; | ||
| 171 | 	} | ||
| 172 | 	/* set z = scalbn(|x|,-ilogb(x)+23) */ | ||
| 173 | 	u.f = x; | ||
| 174 | 	u.i &= (uint64_t)-1>>12; | ||
| 175 | 	u.i |= (uint64_t)(0x3ff + 23)<<52; | ||
| 176 | 	z = u.f; | ||
| 177 | 	for (i=0; i < 2; i++) { | ||
| 178 | 		tx[i] = (double)(int32_t)z; | ||
| 179 | 		z = (z-tx[i])*0x1p24; | ||
| 180 | 	} | ||
| 181 | 	tx[i] = z; | ||
| 182 | 	/* skip zero terms, first term is non-zero */ | ||
| 183 | 	while (tx[i] == 0.0) | ||
| 184 | 		i--; | ||
| 185 | 	n = __rem_pio2_large(tx,ty,(int)(ix>>20)-(0x3ff+23),i+1,1); | ||
| 186 | 	if (sign) { | ||
| 187 | 		y[0] = -ty[0]; | ||
| 188 | 		y[1] = -ty[1]; | ||
| 189 | 		return -n; | ||
| 190 | 	} | ||
| 191 | 	y[0] = ty[0]; | ||
| 192 | 	y[1] = ty[1]; | ||
| 193 | 	return n; | ||
| 194 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2f.c deleted-90| ... | @@ -1,90 +0,0 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_rem_pio2f.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * Debugged and optimized by Bruce D. Evans. | ||
| 5 | */ | ||
| 6 | /* | ||
| 7 | * ==================================================== | ||
| 8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 9 | * | ||
| 10 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 11 | * Permission to use, copy, modify, and distribute this | ||
| 12 | * software is freely granted, provided that this notice | ||
| 13 | * is preserved. | ||
| 14 | * ==================================================== | ||
| 15 | */ | ||
| 16 | /* __rem_pio2f(x,y) | ||
| 17 | * | ||
| 18 | * return the remainder of x rem pi/2 in *y | ||
| 19 | * use double precision for everything except passing x | ||
| 20 | * use __rem_pio2_large() for large x | ||
| 21 | */ | ||
| 22 | |||
| 23 | #include "libm.h" | ||
| 24 | |||
| 25 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 26 | #define EPS DBL_EPSILON | ||
| 27 | #elif FLT_EVAL_METHOD==2 | ||
| 28 | #define EPS LDBL_EPSILON | ||
| 29 | #endif | ||
| 30 | |||
| 31 | /* | ||
| 32 | * invpio2: 53 bits of 2/pi | ||
| 33 | * pio2_1: first 25 bits of pi/2 | ||
| 34 | * pio2_1t: pi/2 - pio2_1 | ||
| 35 | */ | ||
| 36 | static const double | ||
| 37 | toint = 1.5/EPS, | ||
| 38 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 39 | pio4 = 0x1.921fb6p-1, | ||
| 40 | #endif | ||
| 41 | invpio2 = 6.36619772367581382433e-01, /* 0x3FE45F30, 0x6DC9C883 */ | ||
| 42 | pio2_1 = 1.57079631090164184570e+00, /* 0x3FF921FB, 0x50000000 */ | ||
| 43 | pio2_1t = 1.58932547735281966916e-08; /* 0x3E5110b4, 0x611A6263 */ | ||
| 44 | |||
| 45 | int __rem_pio2f(float x, double *y) | ||
| 46 | { | ||
| 47 | 	union {float f; uint32_t i;} u = {x}; | ||
| 48 | 	double tx[1],ty[1]; | ||
| 49 | 	double_t fn; | ||
| 50 | 	uint32_t ix; | ||
| 51 | 	int n, sign, e0; | ||
| 52 | |||
| 53 | 	ix = u.i & 0x7fffffff; | ||
| 54 | 	/* 25+53 bit pi is good enough for medium size */ | ||
| 55 | 	if (ix < 0x4dc90fdb) { /* |x| ~< 2^28*(pi/2), medium size */ | ||
| 56 | 		/* Use a specialized rint() to get fn. */ | ||
| 57 | 		fn = (double_t)x*invpio2 + toint - toint; | ||
| 58 | 		n = (int32_t)fn; | ||
| 59 | 		*y = x - fn*pio2_1 - fn*pio2_1t; | ||
| 60 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 61 | 		/* Matters with directed rounding. */ | ||
| 62 | 		if (predict_false(*y < -pio4)) { | ||
| 63 | 			n--; | ||
| 64 | 			fn--; | ||
| 65 | 			*y = x - fn*pio2_1 - fn*pio2_1t; | ||
| 66 | 		} else if (predict_false(*y > pio4)) { | ||
| 67 | 			n++; | ||
| 68 | 			fn++; | ||
| 69 | 			*y = x - fn*pio2_1 - fn*pio2_1t; | ||
| 70 | 		} | ||
| 71 | #endif | ||
| 72 | 		return n; | ||
| 73 | 	} | ||
| 74 | 	if(ix>=0x7f800000) { /* x is inf or NaN */ | ||
| 75 | 		*y = x-x; | ||
| 76 | 		return 0; | ||
| 77 | 	} | ||
| 78 | 	/* scale x into [2^23, 2^24-1] */ | ||
| 79 | 	sign = u.i>>31; | ||
| 80 | 	e0 = (ix>>23) - (0x7f+23); /* e0 = ilogb(|x|)-23, positive */ | ||
| 81 | 	u.i = ix - (e0<<23); | ||
| 82 | 	tx[0] = u.f; | ||
| 83 | 	n = __rem_pio2_large(tx,ty,e0,1,0); | ||
| 84 | 	if (sign) { | ||
| 85 | 		*y = -ty[0]; | ||
| 86 | 		return -n; | ||
| 87 | 	} | ||
| 88 | 	*y = ty[0]; | ||
| 89 | 	return n; | ||
| 90 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2l.c deleted-159| ... | @@ -1,159 +0,0 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/ld80/e_rem_pio2.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. | ||
| 6 | * | ||
| 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. | ||
| 8 | * Permission to use, copy, modify, and distribute this | ||
| 9 | * software is freely granted, provided that this notice | ||
| 10 | * is preserved. | ||
| 11 | * ==================================================== | ||
| 12 | * | ||
| 13 | * Optimized by Bruce D. Evans. | ||
| 14 | */ | ||
| 15 | #include "libm.h" | ||
| 16 | #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 17 | /* ld80 and ld128 version of __rem_pio2(x,y) | ||
| 18 | * | ||
| 19 | * return the remainder of x rem pi/2 in y[0]+y[1] | ||
| 20 | * use __rem_pio2_large() for large x | ||
| 21 | */ | ||
| 22 | |||
| 23 | static const long double toint = 1.5/LDBL_EPSILON; | ||
| 24 | |||
| 25 | #if LDBL_MANT_DIG == 64 | ||
| 26 | /* u ~< 0x1p25*pi/2 */ | ||
| 27 | #define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.m>>48) < ((0x3fff + 25)<<16 | 0x921f>>1 | 0x8000)) | ||
| 28 | #define QUOBITS(x) ((uint32_t)(int32_t)x & 0x7fffffff) | ||
| 29 | #define ROUND1 22 | ||
| 30 | #define ROUND2 61 | ||
| 31 | #define NX 3 | ||
| 32 | #define NY 2 | ||
| 33 | /* | ||
| 34 | * invpio2: 64 bits of 2/pi | ||
| 35 | * pio2_1: first 39 bits of pi/2 | ||
| 36 | * pio2_1t: pi/2 - pio2_1 | ||
| 37 | * pio2_2: second 39 bits of pi/2 | ||
| 38 | * pio2_2t: pi/2 - (pio2_1+pio2_2) | ||
| 39 | * pio2_3: third 39 bits of pi/2 | ||
| 40 | * pio2_3t: pi/2 - (pio2_1+pio2_2+pio2_3) | ||
| 41 | */ | ||
| 42 | static const double | ||
| 43 | pio2_1 = 1.57079632679597125389e+00, /* 0x3FF921FB, 0x54444000 */ | ||
| 44 | pio2_2 = -1.07463465549783099519e-12, /* -0x12e7b967674000.0p-92 */ | ||
| 45 | pio2_3 = 6.36831716351370313614e-25; /* 0x18a2e037074000.0p-133 */ | ||
| 46 | static const long double | ||
| 47 | pio4 = 0x1.921fb54442d1846ap-1L, | ||
| 48 | invpio2 = 6.36619772367581343076e-01L, /* 0xa2f9836e4e44152a.0p-64 */ | ||
| 49 | pio2_1t = -1.07463465549719416346e-12L, /* -0x973dcb3b399d747f.0p-103 */ | ||
| 50 | pio2_2t = 6.36831716351095013979e-25L, /* 0xc51701b839a25205.0p-144 */ | ||
| 51 | pio2_3t = -2.75299651904407171810e-37L; /* -0xbb5bf6c7ddd660ce.0p-185 */ | ||
| 52 | #elif LDBL_MANT_DIG == 113 | ||
| 53 | /* u ~< 0x1p45*pi/2 */ | ||
| 54 | #define SMALL(u) (((u.i.se & 0x7fffU)<<16 | u.i.top) < ((0x3fff + 45)<<16 | 0x921f)) | ||
| 55 | #define QUOBITS(x) ((uint32_t)(int64_t)x & 0x7fffffff) | ||
| 56 | #define ROUND1 51 | ||
| 57 | #define ROUND2 119 | ||
| 58 | #define NX 5 | ||
| 59 | #define NY 3 | ||
| 60 | static const long double | ||
| 61 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 62 | pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, | ||
| 63 | #endif | ||
| 64 | invpio2 = 6.3661977236758134307553505349005747e-01L,	/* 0x145f306dc9c882a53f84eafa3ea6a.0p-113 */ | ||
| 65 | pio2_1 = 1.5707963267948966192292994253909555e+00L,	/* 0x1921fb54442d18469800000000000.0p-112 */ | ||
| 66 | pio2_1t = 2.0222662487959507323996846200947577e-21L,	/* 0x13198a2e03707344a4093822299f3.0p-181 */ | ||
| 67 | pio2_2 = 2.0222662487959507323994779168837751e-21L,	/* 0x13198a2e03707344a400000000000.0p-181 */ | ||
| 68 | pio2_2t = 2.0670321098263988236496903051604844e-43L,	/* 0x127044533e63a0105df531d89cd91.0p-254 */ | ||
| 69 | pio2_3 = 2.0670321098263988236499468110329591e-43L,	/* 0x127044533e63a0105e00000000000.0p-254 */ | ||
| 70 | pio2_3t = -2.5650587247459238361625433492959285e-65L;	/* -0x159c4ec64ddaeb5f78671cbfb2210.0p-327 */ | ||
| 71 | #endif | ||
| 72 | |||
| 73 | int __rem_pio2l(long double x, long double *y) | ||
| 74 | { | ||
| 75 | 	union ldshape u,uz; | ||
| 76 | 	long double z,w,t,r,fn; | ||
| 77 | 	double tx[NX],ty[NY]; | ||
| 78 | 	int ex,ey,n,i; | ||
| 79 | |||
| 80 | 	u.f = x; | ||
| 81 | 	ex = u.i.se & 0x7fff; | ||
| 82 | 	if (SMALL(u)) { | ||
| 83 | 		/* rint(x/(pi/2)) */ | ||
| 84 | 		fn = x*invpio2 + toint - toint; | ||
| 85 | 		n = QUOBITS(fn); | ||
| 86 | 		r = x-fn*pio2_1; | ||
| 87 | 		w = fn*pio2_1t; /* 1st round good to 102/180 bits (ld80/ld128) */ | ||
| 88 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 89 | 		/* Matters with directed rounding. */ | ||
| 90 | 		if (predict_false(r - w < -pio4)) { | ||
| 91 | 			n--; | ||
| 92 | 			fn--; | ||
| 93 | 			r = x - fn*pio2_1; | ||
| 94 | 			w = fn*pio2_1t; | ||
| 95 | 		} else if (predict_false(r - w > pio4)) { | ||
| 96 | 			n++; | ||
| 97 | 			fn++; | ||
| 98 | 			r = x - fn*pio2_1; | ||
| 99 | 			w = fn*pio2_1t; | ||
| 100 | 		} | ||
| 101 | #endif | ||
| 102 | 		y[0] = r-w; | ||
| 103 | 		u.f = y[0]; | ||
| 104 | 		ey = u.i.se & 0x7fff; | ||
| 105 | 		if (ex - ey > ROUND1) { /* 2nd iteration needed, good to 141/248 (ld80/ld128) */ | ||
| 106 | 			t = r; | ||
| 107 | 			w = fn*pio2_2; | ||
| 108 | 			r = t-w; | ||
| 109 | 			w = fn*pio2_2t-((t-r)-w); | ||
| 110 | 			y[0] = r-w; | ||
| 111 | 			u.f = y[0]; | ||
| 112 | 			ey = u.i.se & 0x7fff; | ||
| 113 | 			if (ex - ey > ROUND2) { /* 3rd iteration, good to 180/316 bits */ | ||
| 114 | 				t = r; /* will cover all possible cases (not verified for ld128) */ | ||
| 115 | 				w = fn*pio2_3; | ||
| 116 | 				r = t-w; | ||
| 117 | 				w = fn*pio2_3t-((t-r)-w); | ||
| 118 | 				y[0] = r-w; | ||
| 119 | 			} | ||
| 120 | 		} | ||
| 121 | 		y[1] = (r - y[0]) - w; | ||
| 122 | 		return n; | ||
| 123 | 	} | ||
| 124 | 	/* | ||
| 125 | 	 * all other (large) arguments | ||
| 126 | 	 */ | ||
| 127 | 	if (ex == 0x7fff) { /* x is inf or NaN */ | ||
| 128 | 		y[0] = y[1] = x - x; | ||
| 129 | 		return 0; | ||
| 130 | 	} | ||
| 131 | 	/* set z = scalbn(|x|,-ilogb(x)+23) */ | ||
| 132 | 	uz.f = x; | ||
| 133 | 	uz.i.se = 0x3fff + 23; | ||
| 134 | 	z = uz.f; | ||
| 135 | 	for (i=0; i < NX - 1; i++) { | ||
| 136 | 		tx[i] = (double)(int32_t)z; | ||
| 137 | 		z = (z-tx[i])*0x1p24; | ||
| 138 | 	} | ||
| 139 | 	tx[i] = z; | ||
| 140 | 	while (tx[i] == 0) | ||
| 141 | 		i--; | ||
| 142 | 	n = __rem_pio2_large(tx, ty, ex-0x3fff-23, i+1, NY); | ||
| 143 | 	w = ty[1]; | ||
| 144 | 	if (NY == 3) | ||
| 145 | 		w += ty[2]; | ||
| 146 | 	r = ty[0] + w; | ||
| 147 | 	/* TODO: for ld128 this does not follow the recommendation of the | ||
| 148 | 	comments of __rem_pio2_large which seem wrong if |ty[0]| > |ty[1]+ty[2]| */ | ||
| 149 | 	w -= r - ty[0]; | ||
| 150 | 	if (u.i.se >> 15) { | ||
| 151 | 		y[0] = -r; | ||
| 152 | 		y[1] = -w; | ||
| 153 | 		return -n; | ||
| 154 | 	} | ||
| 155 | 	y[0] = r; | ||
| 156 | 	y[1] = w; | ||
| 157 | 	return n; | ||
| 158 | } | ||
| 159 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmal.c deleted-297| ... | @@ -1,297 +0,0 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_fmal.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2005-2011 David Schultz <das@FreeBSD.ORG> | ||
| 4 | * All rights reserved. | ||
| 5 | * | ||
| 6 | * Redistribution and use in source and binary forms, with or without | ||
| 7 | * modification, are permitted provided that the following conditions | ||
| 8 | * are met: | ||
| 9 | * 1. Redistributions of source code must retain the above copyright | ||
| 10 | * notice, this list of conditions and the following disclaimer. | ||
| 11 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 12 | * notice, this list of conditions and the following disclaimer in the | ||
| 13 | * documentation and/or other materials provided with the distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 25 | * SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | |||
| 28 | |||
| 29 | #include "libm.h" | ||
| 30 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 31 | long double fmal(long double x, long double y, long double z) | ||
| 32 | { | ||
| 33 | 	return fma(x, y, z); | ||
| 34 | } | ||
| 35 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 36 | #include <fenv.h> | ||
| 37 | #if LDBL_MANT_DIG == 64 | ||
| 38 | #define LASTBIT(u) (u.i.m & 1) | ||
| 39 | #define SPLIT (0x1p32L + 1) | ||
| 40 | #elif LDBL_MANT_DIG == 113 | ||
| 41 | #define LASTBIT(u) (u.i.lo & 1) | ||
| 42 | #define SPLIT (0x1p57L + 1) | ||
| 43 | #endif | ||
| 44 | |||
| 45 | /* | ||
| 46 | * A struct dd represents a floating-point number with twice the precision | ||
| 47 | * of a long double. We maintain the invariant that "hi" stores the high-order | ||
| 48 | * bits of the result. | ||
| 49 | */ | ||
| 50 | struct dd { | ||
| 51 | 	long double hi; | ||
| 52 | 	long double lo; | ||
| 53 | }; | ||
| 54 | |||
| 55 | /* | ||
| 56 | * Compute a+b exactly, returning the exact result in a struct dd. We assume | ||
| 57 | * that both a and b are finite, but make no assumptions about their relative | ||
| 58 | * magnitudes. | ||
| 59 | */ | ||
| 60 | static inline struct dd dd_add(long double a, long double b) | ||
| 61 | { | ||
| 62 | 	struct dd ret; | ||
| 63 | 	long double s; | ||
| 64 | |||
| 65 | 	ret.hi = a + b; | ||
| 66 | 	s = ret.hi - a; | ||
| 67 | 	ret.lo = (a - (ret.hi - s)) + (b - s); | ||
| 68 | 	return (ret); | ||
| 69 | } | ||
| 70 | |||
| 71 | /* | ||
| 72 | * Compute a+b, with a small tweak: The least significant bit of the | ||
| 73 | * result is adjusted into a sticky bit summarizing all the bits that | ||
| 74 | * were lost to rounding. This adjustment negates the effects of double | ||
| 75 | * rounding when the result is added to another number with a higher | ||
| 76 | * exponent. For an explanation of round and sticky bits, see any reference | ||
| 77 | * on FPU design, e.g., | ||
| 78 | * | ||
| 79 | * J. Coonen. An Implementation Guide to a Proposed Standard for | ||
| 80 | * Floating-Point Arithmetic. Computer, vol. 13, no. 1, Jan 1980. | ||
| 81 | */ | ||
| 82 | static inline long double add_adjusted(long double a, long double b) | ||
| 83 | { | ||
| 84 | 	struct dd sum; | ||
| 85 | 	union ldshape u; | ||
| 86 | |||
| 87 | 	sum = dd_add(a, b); | ||
| 88 | 	if (sum.lo != 0) { | ||
| 89 | 		u.f = sum.hi; | ||
| 90 | 		if (!LASTBIT(u)) | ||
| 91 | 			sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); | ||
| 92 | 	} | ||
| 93 | 	return (sum.hi); | ||
| 94 | } | ||
| 95 | |||
| 96 | /* | ||
| 97 | * Compute ldexp(a+b, scale) with a single rounding error. It is assumed | ||
| 98 | * that the result will be subnormal, and care is taken to ensure that | ||
| 99 | * double rounding does not occur. | ||
| 100 | */ | ||
| 101 | static inline long double add_and_denormalize(long double a, long double b, int scale) | ||
| 102 | { | ||
| 103 | 	struct dd sum; | ||
| 104 | 	int bits_lost; | ||
| 105 | 	union ldshape u; | ||
| 106 | |||
| 107 | 	sum = dd_add(a, b); | ||
| 108 | |||
| 109 | 	/* | ||
| 110 | 	 * If we are losing at least two bits of accuracy to denormalization, | ||
| 111 | 	 * then the first lost bit becomes a round bit, and we adjust the | ||
| 112 | 	 * lowest bit of sum.hi to make it a sticky bit summarizing all the | ||
| 113 | 	 * bits in sum.lo. With the sticky bit adjusted, the hardware will | ||
| 114 | 	 * break any ties in the correct direction. | ||
| 115 | 	 * | ||
| 116 | 	 * If we are losing only one bit to denormalization, however, we must | ||
| 117 | 	 * break the ties manually. | ||
| 118 | 	 */ | ||
| 119 | 	if (sum.lo != 0) { | ||
| 120 | 		u.f = sum.hi; | ||
| 121 | 		bits_lost = -u.i.se - scale + 1; | ||
| 122 | 		if ((bits_lost != 1) ^ LASTBIT(u)) | ||
| 123 | 			sum.hi = nextafterl(sum.hi, INFINITY * sum.lo); | ||
| 124 | 	} | ||
| 125 | 	return scalbnl(sum.hi, scale); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* | ||
| 129 | * Compute a*b exactly, returning the exact result in a struct dd. We assume | ||
| 130 | * that both a and b are normalized, so no underflow or overflow will occur. | ||
| 131 | * The current rounding mode must be round-to-nearest. | ||
| 132 | */ | ||
| 133 | static inline struct dd dd_mul(long double a, long double b) | ||
| 134 | { | ||
| 135 | 	struct dd ret; | ||
| 136 | 	long double ha, hb, la, lb, p, q; | ||
| 137 | |||
| 138 | 	p = a * SPLIT; | ||
| 139 | 	ha = a - p; | ||
| 140 | 	ha += p; | ||
| 141 | 	la = a - ha; | ||
| 142 | |||
| 143 | 	p = b * SPLIT; | ||
| 144 | 	hb = b - p; | ||
| 145 | 	hb += p; | ||
| 146 | 	lb = b - hb; | ||
| 147 | |||
| 148 | 	p = ha * hb; | ||
| 149 | 	q = ha * lb + la * hb; | ||
| 150 | |||
| 151 | 	ret.hi = p + q; | ||
| 152 | 	ret.lo = p - ret.hi + q + la * lb; | ||
| 153 | 	return (ret); | ||
| 154 | } | ||
| 155 | |||
| 156 | /* | ||
| 157 | * Fused multiply-add: Compute x * y + z with a single rounding error. | ||
| 158 | * | ||
| 159 | * We use scaling to avoid overflow/underflow, along with the | ||
| 160 | * canonical precision-doubling technique adapted from: | ||
| 161 | * | ||
| 162 | * Dekker, T. A Floating-Point Technique for Extending the | ||
| 163 | * Available Precision. Numer. Math. 18, 224-242 (1971). | ||
| 164 | */ | ||
| 165 | long double fmal(long double x, long double y, long double z) | ||
| 166 | { | ||
| 167 | 	#pragma STDC FENV_ACCESS ON | ||
| 168 | 	long double xs, ys, zs, adj; | ||
| 169 | 	struct dd xy, r; | ||
| 170 | 	int oround; | ||
| 171 | 	int ex, ey, ez; | ||
| 172 | 	int spread; | ||
| 173 | |||
| 174 | 	/* | ||
| 175 | 	 * Handle special cases. The order of operations and the particular | ||
| 176 | 	 * return values here are crucial in handling special cases involving | ||
| 177 | 	 * infinities, NaNs, overflows, and signed zeroes correctly. | ||
| 178 | 	 */ | ||
| 179 | 	if (!isfinite(x) || !isfinite(y)) | ||
| 180 | 		return (x * y + z); | ||
| 181 | 	if (!isfinite(z)) | ||
| 182 | 		return (z); | ||
| 183 | 	if (x == 0.0 || y == 0.0) | ||
| 184 | 		return (x * y + z); | ||
| 185 | 	if (z == 0.0) | ||
| 186 | 		return (x * y); | ||
| 187 | |||
| 188 | 	xs = frexpl(x, &ex); | ||
| 189 | 	ys = frexpl(y, &ey); | ||
| 190 | 	zs = frexpl(z, &ez); | ||
| 191 | 	oround = fegetround(); | ||
| 192 | 	spread = ex + ey - ez; | ||
| 193 | |||
| 194 | 	/* | ||
| 195 | 	 * If x * y and z are many orders of magnitude apart, the scaling | ||
| 196 | 	 * will overflow, so we handle these cases specially. Rounding | ||
| 197 | 	 * modes other than FE_TONEAREST are painful. | ||
| 198 | 	 */ | ||
| 199 | 	if (spread < -LDBL_MANT_DIG) { | ||
| 200 | #ifdef FE_INEXACT | ||
| 201 | 		feraiseexcept(FE_INEXACT); | ||
| 202 | #endif | ||
| 203 | #ifdef FE_UNDERFLOW | ||
| 204 | 		if (!isnormal(z)) | ||
| 205 | 			feraiseexcept(FE_UNDERFLOW); | ||
| 206 | #endif | ||
| 207 | 		switch (oround) { | ||
| 208 | 		default: /* FE_TONEAREST */ | ||
| 209 | 			return (z); | ||
| 210 | #ifdef FE_TOWARDZERO | ||
| 211 | 		case FE_TOWARDZERO: | ||
| 212 | 			if (x > 0.0 ^ y < 0.0 ^ z < 0.0) | ||
| 213 | 				return (z); | ||
| 214 | 			else | ||
| 215 | 				return (nextafterl(z, 0)); | ||
| 216 | #endif | ||
| 217 | #ifdef FE_DOWNWARD | ||
| 218 | 		case FE_DOWNWARD: | ||
| 219 | 			if (x > 0.0 ^ y < 0.0) | ||
| 220 | 				return (z); | ||
| 221 | 			else | ||
| 222 | 				return (nextafterl(z, -INFINITY)); | ||
| 223 | #endif | ||
| 224 | #ifdef FE_UPWARD | ||
| 225 | 		case FE_UPWARD: | ||
| 226 | 			if (x > 0.0 ^ y < 0.0) | ||
| 227 | 				return (nextafterl(z, INFINITY)); | ||
| 228 | 			else | ||
| 229 | 				return (z); | ||
| 230 | #endif | ||
| 231 | 		} | ||
| 232 | 	} | ||
| 233 | 	if (spread <= LDBL_MANT_DIG * 2) | ||
| 234 | 		zs = scalbnl(zs, -spread); | ||
| 235 | 	else | ||
| 236 | 		zs = copysignl(LDBL_MIN, zs); | ||
| 237 | |||
| 238 | 	fesetround(FE_TONEAREST); | ||
| 239 | |||
| 240 | 	/* | ||
| 241 | 	 * Basic approach for round-to-nearest: | ||
| 242 | 	 * | ||
| 243 | 	 * (xy.hi, xy.lo) = x * y (exact) | ||
| 244 | 	 * (r.hi, r.lo) = xy.hi + z (exact) | ||
| 245 | 	 * adj = xy.lo + r.lo (inexact; low bit is sticky) | ||
| 246 | 	 * result = r.hi + adj (correctly rounded) | ||
| 247 | 	 */ | ||
| 248 | 	xy = dd_mul(xs, ys); | ||
| 249 | 	r = dd_add(xy.hi, zs); | ||
| 250 | |||
| 251 | 	spread = ex + ey; | ||
| 252 | |||
| 253 | 	if (r.hi == 0.0) { | ||
| 254 | 		/* | ||
| 255 | 		 * When the addends cancel to 0, ensure that the result has | ||
| 256 | 		 * the correct sign. | ||
| 257 | 		 */ | ||
| 258 | 		fesetround(oround); | ||
| 259 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't need old GCC workarounds | ||
| 260 | 		volatile long double vzs = zs; /* XXX gcc CSE bug workaround */ | ||
| 261 | #else | ||
| 262 | 		long double vzs = zs; | ||
| 263 | #endif | ||
| 264 | 		return xy.hi + vzs + scalbnl(xy.lo, spread); | ||
| 265 | 	} | ||
| 266 | |||
| 267 | 	if (oround != FE_TONEAREST) { | ||
| 268 | 		/* | ||
| 269 | 		 * There is no need to worry about double rounding in directed | ||
| 270 | 		 * rounding modes. | ||
| 271 | 		 * But underflow may not be raised correctly, example in downward rounding: | ||
| 272 | 		 * fmal(0x1.0000000001p-16000L, 0x1.0000000001p-400L, -0x1p-16440L) | ||
| 273 | 		 */ | ||
| 274 | 		long double ret; | ||
| 275 | #if defined(FE_INEXACT) && defined(FE_UNDERFLOW) | ||
| 276 | 		int e = fetestexcept(FE_INEXACT); | ||
| 277 | 		feclearexcept(FE_INEXACT); | ||
| 278 | #endif | ||
| 279 | 		fesetround(oround); | ||
| 280 | 		adj = r.lo + xy.lo; | ||
| 281 | 		ret = scalbnl(r.hi + adj, spread); | ||
| 282 | #if defined(FE_INEXACT) && defined(FE_UNDERFLOW) | ||
| 283 | 		if (ilogbl(ret) < -16382 && fetestexcept(FE_INEXACT)) | ||
| 284 | 			feraiseexcept(FE_UNDERFLOW); | ||
| 285 | 		else if (e) | ||
| 286 | 			feraiseexcept(FE_INEXACT); | ||
| 287 | #endif | ||
| 288 | 		return ret; | ||
| 289 | 	} | ||
| 290 | |||
| 291 | 	adj = add_adjusted(r.lo, xy.lo); | ||
| 292 | 	if (spread + ilogbl(r.hi) > -16383) | ||
| 293 | 		return scalbnl(r.hi + adj, spread); | ||
| 294 | 	else | ||
| 295 | 		return add_and_denormalize(r.hi, adj, spread); | ||
| 296 | } | ||
| 297 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powl.c deleted-534| ... | @@ -1,534 +0,0 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_powl.c */ | ||
| 2 | /* | ||
| 3 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 4 | * | ||
| 5 | * Permission to use, copy, modify, and distribute this software for any | ||
| 6 | * purpose with or without fee is hereby granted, provided that the above | ||
| 7 | * copyright notice and this permission notice appear in all copies. | ||
| 8 | * | ||
| 9 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 10 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 11 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 12 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 13 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 14 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 15 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 16 | */ | ||
| 17 | /* powl.c | ||
| 18 | * | ||
| 19 | * Power function, long double precision | ||
| 20 | * | ||
| 21 | * | ||
| 22 | * SYNOPSIS: | ||
| 23 | * | ||
| 24 | * long double x, y, z, powl(); | ||
| 25 | * | ||
| 26 | * z = powl( x, y ); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * Computes x raised to the yth power. Analytically, | ||
| 32 | * | ||
| 33 | * x**y = exp( y log(x) ). | ||
| 34 | * | ||
| 35 | * Following Cody and Waite, this program uses a lookup table | ||
| 36 | * of 2**-i/32 and pseudo extended precision arithmetic to | ||
| 37 | * obtain several extra bits of accuracy in both the logarithm | ||
| 38 | * and the exponential. | ||
| 39 | * | ||
| 40 | * | ||
| 41 | * ACCURACY: | ||
| 42 | * | ||
| 43 | * The relative error of pow(x,y) can be estimated | ||
| 44 | * by y dl ln(2), where dl is the absolute error of | ||
| 45 | * the internally computed base 2 logarithm. At the ends | ||
| 46 | * of the approximation interval the logarithm equal 1/32 | ||
| 47 | * and its relative error is about 1 lsb = 1.1e-19. Hence | ||
| 48 | * the predicted relative error in the result is 2.3e-21 y . | ||
| 49 | * | ||
| 50 | * Relative error: | ||
| 51 | * arithmetic domain # trials peak rms | ||
| 52 | * | ||
| 53 | * IEEE +-1000 40000 2.8e-18 3.7e-19 | ||
| 54 | * .001 < x < 1000, with log(x) uniformly distributed. | ||
| 55 | * -1000 < y < 1000, y uniformly distributed. | ||
| 56 | * | ||
| 57 | * IEEE 0,8700 60000 6.5e-18 1.0e-18 | ||
| 58 | * 0.99 < x < 1.01, 0 < y < 8700, uniformly distributed. | ||
| 59 | * | ||
| 60 | * | ||
| 61 | * ERROR MESSAGES: | ||
| 62 | * | ||
| 63 | * message condition value returned | ||
| 64 | * pow overflow x**y > MAXNUM INFINITY | ||
| 65 | * pow underflow x**y < 1/MAXNUM 0.0 | ||
| 66 | * pow domain x<0 and y noninteger 0.0 | ||
| 67 | * | ||
| 68 | */ | ||
| 69 | |||
| 70 | #include "libm.h" | ||
| 71 | |||
| 72 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 73 | long double powl(long double x, long double y) | ||
| 74 | { | ||
| 75 | 	return pow(x, y); | ||
| 76 | } | ||
| 77 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 78 | |||
| 79 | /* Table size */ | ||
| 80 | #define NXT 32 | ||
| 81 | |||
| 82 | /* log(1+x) = x - .5x^2 + x^3 * P(z)/Q(z) | ||
| 83 | * on the domain 2^(-1/32) - 1 <= x <= 2^(1/32) - 1 | ||
| 84 | */ | ||
| 85 | static const long double P[] = { | ||
| 86 | 8.3319510773868690346226E-4L, | ||
| 87 | 4.9000050881978028599627E-1L, | ||
| 88 | 1.7500123722550302671919E0L, | ||
| 89 | 1.4000100839971580279335E0L, | ||
| 90 | }; | ||
| 91 | static const long double Q[] = { | ||
| 92 | /* 1.0000000000000000000000E0L,*/ | ||
| 93 | 5.2500282295834889175431E0L, | ||
| 94 | 8.4000598057587009834666E0L, | ||
| 95 | 4.2000302519914740834728E0L, | ||
| 96 | }; | ||
| 97 | /* A[i] = 2^(-i/32), rounded to IEEE long double precision. | ||
| 98 | * If i is even, A[i] + B[i/2] gives additional accuracy. | ||
| 99 | */ | ||
| 100 | static const long double A[33] = { | ||
| 101 | 1.0000000000000000000000E0L, | ||
| 102 | 9.7857206208770013448287E-1L, | ||
| 103 | 9.5760328069857364691013E-1L, | ||
| 104 | 9.3708381705514995065011E-1L, | ||
| 105 | 9.1700404320467123175367E-1L, | ||
| 106 | 8.9735453750155359320742E-1L, | ||
| 107 | 8.7812608018664974155474E-1L, | ||
| 108 | 8.5930964906123895780165E-1L, | ||
| 109 | 8.4089641525371454301892E-1L, | ||
| 110 | 8.2287773907698242225554E-1L, | ||
| 111 | 8.0524516597462715409607E-1L, | ||
| 112 | 7.8799042255394324325455E-1L, | ||
| 113 | 7.7110541270397041179298E-1L, | ||
| 114 | 7.5458221379671136985669E-1L, | ||
| 115 | 7.3841307296974965571198E-1L, | ||
| 116 | 7.2259040348852331001267E-1L, | ||
| 117 | 7.0710678118654752438189E-1L, | ||
| 118 | 6.9195494098191597746178E-1L, | ||
| 119 | 6.7712777346844636413344E-1L, | ||
| 120 | 6.6261832157987064729696E-1L, | ||
| 121 | 6.4841977732550483296079E-1L, | ||
| 122 | 6.3452547859586661129850E-1L, | ||
| 123 | 6.2092890603674202431705E-1L, | ||
| 124 | 6.0762367999023443907803E-1L, | ||
| 125 | 5.9460355750136053334378E-1L, | ||
| 126 | 5.8186242938878875689693E-1L, | ||
| 127 | 5.6939431737834582684856E-1L, | ||
| 128 | 5.5719337129794626814472E-1L, | ||
| 129 | 5.4525386633262882960438E-1L, | ||
| 130 | 5.3357020033841180906486E-1L, | ||
| 131 | 5.2213689121370692017331E-1L, | ||
| 132 | 5.1094857432705833910408E-1L, | ||
| 133 | 5.0000000000000000000000E-1L, | ||
| 134 | }; | ||
| 135 | static const long double B[17] = { | ||
| 136 | 0.0000000000000000000000E0L, | ||
| 137 | 2.6176170809902549338711E-20L, | ||
| 138 | -1.0126791927256478897086E-20L, | ||
| 139 | 1.3438228172316276937655E-21L, | ||
| 140 | 1.2207982955417546912101E-20L, | ||
| 141 | -6.3084814358060867200133E-21L, | ||
| 142 | 1.3164426894366316434230E-20L, | ||
| 143 | -1.8527916071632873716786E-20L, | ||
| 144 | 1.8950325588932570796551E-20L, | ||
| 145 | 1.5564775779538780478155E-20L, | ||
| 146 | 6.0859793637556860974380E-21L, | ||
| 147 | -2.0208749253662532228949E-20L, | ||
| 148 | 1.4966292219224761844552E-20L, | ||
| 149 | 3.3540909728056476875639E-21L, | ||
| 150 | -8.6987564101742849540743E-22L, | ||
| 151 | -1.2327176863327626135542E-20L, | ||
| 152 | 0.0000000000000000000000E0L, | ||
| 153 | }; | ||
| 154 | |||
| 155 | /* 2^x = 1 + x P(x), | ||
| 156 | * on the interval -1/32 <= x <= 0 | ||
| 157 | */ | ||
| 158 | static const long double R[] = { | ||
| 159 | 1.5089970579127659901157E-5L, | ||
| 160 | 1.5402715328927013076125E-4L, | ||
| 161 | 1.3333556028915671091390E-3L, | ||
| 162 | 9.6181291046036762031786E-3L, | ||
| 163 | 5.5504108664798463044015E-2L, | ||
| 164 | 2.4022650695910062854352E-1L, | ||
| 165 | 6.9314718055994530931447E-1L, | ||
| 166 | }; | ||
| 167 | |||
| 168 | #define MEXP (NXT*16384.0L) | ||
| 169 | /* The following if denormal numbers are supported, else -MEXP: */ | ||
| 170 | #define MNEXP (-NXT*(16384.0L+64.0L)) | ||
| 171 | /* log2(e) - 1 */ | ||
| 172 | #define LOG2EA 0.44269504088896340735992L | ||
| 173 | |||
| 174 | #define F W | ||
| 175 | #define Fa Wa | ||
| 176 | #define Fb Wb | ||
| 177 | #define G W | ||
| 178 | #define Ga Wa | ||
| 179 | #define Gb u | ||
| 180 | #define H W | ||
| 181 | #define Ha Wb | ||
| 182 | #define Hb Wb | ||
| 183 | |||
| 184 | static const long double MAXLOGL = 1.1356523406294143949492E4L; | ||
| 185 | static const long double MINLOGL = -1.13994985314888605586758E4L; | ||
| 186 | static const long double LOGE2L = 6.9314718055994530941723E-1L; | ||
| 187 | static const long double huge = 0x1p10000L; | ||
| 188 | /* XXX Prevent gcc from erroneously constant folding this. */ | ||
| 189 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't need old GCC workarounds | ||
| 190 | static const volatile long double twom10000 = 0x1p-10000L; | ||
| 191 | #else | ||
| 192 | static const long double twom10000 = 0x1p-10000L; | ||
| 193 | #endif | ||
| 194 | |||
| 195 | static long double reducl(long double); | ||
| 196 | static long double powil(long double, int); | ||
| 197 | |||
| 198 | long double powl(long double x, long double y) | ||
| 199 | { | ||
| 200 | 	/* double F, Fa, Fb, G, Ga, Gb, H, Ha, Hb */ | ||
| 201 | 	int i, nflg, iyflg, yoddint; | ||
| 202 | 	long e; | ||
| 203 | 	volatile long double z=0; | ||
| 204 | 	long double w=0, W=0, Wa=0, Wb=0, ya=0, yb=0, u=0; | ||
| 205 | |||
| 206 | 	/* make sure no invalid exception is raised by nan comparision */ | ||
| 207 | 	if (isnan(x)) { | ||
| 208 | 		if (!isnan(y) && y == 0.0) | ||
| 209 | 			return 1.0; | ||
| 210 | 		return x; | ||
| 211 | 	} | ||
| 212 | 	if (isnan(y)) { | ||
| 213 | 		if (x == 1.0) | ||
| 214 | 			return 1.0; | ||
| 215 | 		return y; | ||
| 216 | 	} | ||
| 217 | 	if (x == 1.0) | ||
| 218 | 		return 1.0; /* 1**y = 1, even if y is nan */ | ||
| 219 | 	if (y == 0.0) | ||
| 220 | 		return 1.0; /* x**0 = 1, even if x is nan */ | ||
| 221 | 	if (y == 1.0) | ||
| 222 | 		return x; | ||
| 223 | 	/* if y*log2(x) < log2(LDBL_TRUE_MIN)-1 then x^y uflows to 0 | ||
| 224 | 	 if y*log2(x) > -log2(LDBL_TRUE_MIN)+1 > LDBL_MAX_EXP then x^y oflows | ||
| 225 | 	 if |x|!=1 then |log2(x)| > |log(x)| > LDBL_EPSILON/2 so | ||
| 226 | 	 x^y oflows/uflows if |y|*LDBL_EPSILON/2 > -log2(LDBL_TRUE_MIN)+1 */ | ||
| 227 | 	if (fabsl(y) > 2*(-LDBL_MIN_EXP+LDBL_MANT_DIG+1)/LDBL_EPSILON) { | ||
| 228 | 		/* y is not an odd int */ | ||
| 229 | 		if (x == -1.0) | ||
| 230 | 			return 1.0; | ||
| 231 | 		if (y == INFINITY) { | ||
| 232 | 			if (x > 1.0 || x < -1.0) | ||
| 233 | 				return INFINITY; | ||
| 234 | 			return 0.0; | ||
| 235 | 		} | ||
| 236 | 		if (y == -INFINITY) { | ||
| 237 | 			if (x > 1.0 || x < -1.0) | ||
| 238 | 				return 0.0; | ||
| 239 | 			return INFINITY; | ||
| 240 | 		} | ||
| 241 | 		if ((x > 1.0 || x < -1.0) == (y > 0)) | ||
| 242 | 			return huge * huge; | ||
| 243 | 		return twom10000 * twom10000; | ||
| 244 | 	} | ||
| 245 | 	if (x == INFINITY) { | ||
| 246 | 		if (y > 0.0) | ||
| 247 | 			return INFINITY; | ||
| 248 | 		return 0.0; | ||
| 249 | 	} | ||
| 250 | |||
| 251 | 	w = floorl(y); | ||
| 252 | |||
| 253 | 	/* Set iyflg to 1 if y is an integer. */ | ||
| 254 | 	iyflg = 0; | ||
| 255 | 	if (w == y) | ||
| 256 | 		iyflg = 1; | ||
| 257 | |||
| 258 | 	/* Test for odd integer y. */ | ||
| 259 | 	yoddint = 0; | ||
| 260 | 	if (iyflg) { | ||
| 261 | 		ya = fabsl(y); | ||
| 262 | 		ya = floorl(0.5 * ya); | ||
| 263 | 		yb = 0.5 * fabsl(w); | ||
| 264 | 		if( ya != yb ) | ||
| 265 | 			yoddint = 1; | ||
| 266 | 	} | ||
| 267 | |||
| 268 | 	if (x == -INFINITY) { | ||
| 269 | 		if (y > 0.0) { | ||
| 270 | 			if (yoddint) | ||
| 271 | 				return -INFINITY; | ||
| 272 | 			return INFINITY; | ||
| 273 | 		} | ||
| 274 | 		if (y < 0.0) { | ||
| 275 | 			if (yoddint) | ||
| 276 | 				return -0.0; | ||
| 277 | 			return 0.0; | ||
| 278 | 		} | ||
| 279 | 	} | ||
| 280 | 	nflg = 0; /* (x<0)**(odd int) */ | ||
| 281 | 	if (x <= 0.0) { | ||
| 282 | 		if (x == 0.0) { | ||
| 283 | 			if (y < 0.0) { | ||
| 284 | 				if (signbit(x) && yoddint) | ||
| 285 | 					/* (-0.0)**(-odd int) = -inf, divbyzero */ | ||
| 286 | 					return -1.0/0.0; | ||
| 287 | 				/* (+-0.0)**(negative) = inf, divbyzero */ | ||
| 288 | 				return 1.0/0.0; | ||
| 289 | 			} | ||
| 290 | 			if (signbit(x) && yoddint) | ||
| 291 | 				return -0.0; | ||
| 292 | 			return 0.0; | ||
| 293 | 		} | ||
| 294 | 		if (iyflg == 0) | ||
| 295 | 			return (x - x) / (x - x); /* (x<0)**(non-int) is NaN */ | ||
| 296 | 		/* (x<0)**(integer) */ | ||
| 297 | 		if (yoddint) | ||
| 298 | 			nflg = 1; /* negate result */ | ||
| 299 | 		x = -x; | ||
| 300 | 	} | ||
| 301 | 	/* (+integer)**(integer) */ | ||
| 302 | 	if (iyflg && floorl(x) == x && fabsl(y) < 32768.0) { | ||
| 303 | 		w = powil(x, (int)y); | ||
| 304 | 		return nflg ? -w : w; | ||
| 305 | 	} | ||
| 306 | |||
| 307 | 	/* separate significand from exponent */ | ||
| 308 | 	x = frexpl(x, &i); | ||
| 309 | 	e = i; | ||
| 310 | |||
| 311 | 	/* find significand in antilog table A[] */ | ||
| 312 | 	i = 1; | ||
| 313 | 	if (x <= A[17]) | ||
| 314 | 		i = 17; | ||
| 315 | 	if (x <= A[i+8]) | ||
| 316 | 		i += 8; | ||
| 317 | 	if (x <= A[i+4]) | ||
| 318 | 		i += 4; | ||
| 319 | 	if (x <= A[i+2]) | ||
| 320 | 		i += 2; | ||
| 321 | 	if (x >= A[1]) | ||
| 322 | 		i = -1; | ||
| 323 | 	i += 1; | ||
| 324 | |||
| 325 | 	/* Find (x - A[i])/A[i] | ||
| 326 | 	 * in order to compute log(x/A[i]): | ||
| 327 | 	 * | ||
| 328 | 	 * log(x) = log( a x/a ) = log(a) + log(x/a) | ||
| 329 | 	 * | ||
| 330 | 	 * log(x/a) = log(1+v), v = x/a - 1 = (x-a)/a | ||
| 331 | 	 */ | ||
| 332 | 	x -= A[i]; | ||
| 333 | 	x -= B[i/2]; | ||
| 334 | 	x /= A[i]; | ||
| 335 | |||
| 336 | 	/* rational approximation for log(1+v): | ||
| 337 | 	 * | ||
| 338 | 	 * log(1+v) = v - v**2/2 + v**3 P(v) / Q(v) | ||
| 339 | 	 */ | ||
| 340 | 	z = x*x; | ||
| 341 | 	w = x * (z * __polevll(x, P, 3) / __p1evll(x, Q, 3)); | ||
| 342 | 	w = w - 0.5*z; | ||
| 343 | |||
| 344 | 	/* Convert to base 2 logarithm: | ||
| 345 | 	 * multiply by log2(e) = 1 + LOG2EA | ||
| 346 | 	 */ | ||
| 347 | 	z = LOG2EA * w; | ||
| 348 | 	z += w; | ||
| 349 | 	z += LOG2EA * x; | ||
| 350 | 	z += x; | ||
| 351 | |||
| 352 | 	/* Compute exponent term of the base 2 logarithm. */ | ||
| 353 | 	w = -i; | ||
| 354 | 	w /= NXT; | ||
| 355 | 	w += e; | ||
| 356 | 	/* Now base 2 log of x is w + z. */ | ||
| 357 | |||
| 358 | 	/* Multiply base 2 log by y, in extended precision. */ | ||
| 359 | |||
| 360 | 	/* separate y into large part ya | ||
| 361 | 	 * and small part yb less than 1/NXT | ||
| 362 | 	 */ | ||
| 363 | 	ya = reducl(y); | ||
| 364 | 	yb = y - ya; | ||
| 365 | |||
| 366 | 	/* (w+z)(ya+yb) | ||
| 367 | 	 * = w*ya + w*yb + z*y | ||
| 368 | 	 */ | ||
| 369 | 	F = z * y + w * yb; | ||
| 370 | 	Fa = reducl(F); | ||
| 371 | 	Fb = F - Fa; | ||
| 372 | |||
| 373 | 	G = Fa + w * ya; | ||
| 374 | 	Ga = reducl(G); | ||
| 375 | 	Gb = G - Ga; | ||
| 376 | |||
| 377 | 	H = Fb + Gb; | ||
| 378 | 	Ha = reducl(H); | ||
| 379 | 	w = (Ga + Ha) * NXT; | ||
| 380 | |||
| 381 | 	/* Test the power of 2 for overflow */ | ||
| 382 | 	if (w > MEXP) | ||
| 383 | 		return huge * huge; /* overflow */ | ||
| 384 | 	if (w < MNEXP) | ||
| 385 | 		return twom10000 * twom10000; /* underflow */ | ||
| 386 | |||
| 387 | 	e = w; | ||
| 388 | 	Hb = H - Ha; | ||
| 389 | |||
| 390 | 	if (Hb > 0.0) { | ||
| 391 | 		e += 1; | ||
| 392 | 		Hb -= 1.0/NXT; /*0.0625L;*/ | ||
| 393 | 	} | ||
| 394 | |||
| 395 | 	/* Now the product y * log2(x) = Hb + e/NXT. | ||
| 396 | 	 * | ||
| 397 | 	 * Compute base 2 exponential of Hb, | ||
| 398 | 	 * where -0.0625 <= Hb <= 0. | ||
| 399 | 	 */ | ||
| 400 | 	z = Hb * __polevll(Hb, R, 6); /* z = 2**Hb - 1 */ | ||
| 401 | |||
| 402 | 	/* Express e/NXT as an integer plus a negative number of (1/NXT)ths. | ||
| 403 | 	 * Find lookup table entry for the fractional power of 2. | ||
| 404 | 	 */ | ||
| 405 | 	if (e < 0) | ||
| 406 | 		i = 0; | ||
| 407 | 	else | ||
| 408 | 		i = 1; | ||
| 409 | 	i = e/NXT + i; | ||
| 410 | 	e = NXT*i - e; | ||
| 411 | 	w = A[e]; | ||
| 412 | 	z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */ | ||
| 413 | 	z = z + w; | ||
| 414 | 	z = scalbnl(z, i); /* multiply by integer power of 2 */ | ||
| 415 | |||
| 416 | 	if (nflg) | ||
| 417 | 		z = -z; | ||
| 418 | 	return z; | ||
| 419 | } | ||
| 420 | |||
| 421 | |||
| 422 | /* Find a multiple of 1/NXT that is within 1/NXT of x. */ | ||
| 423 | static long double reducl(long double x) | ||
| 424 | { | ||
| 425 | 	long double t; | ||
| 426 | |||
| 427 | 	t = x * NXT; | ||
| 428 | 	t = floorl(t); | ||
| 429 | 	t = t / NXT; | ||
| 430 | 	return t; | ||
| 431 | } | ||
| 432 | |||
| 433 | /* | ||
| 434 | * Positive real raised to integer power, long double precision | ||
| 435 | * | ||
| 436 | * | ||
| 437 | * SYNOPSIS: | ||
| 438 | * | ||
| 439 | * long double x, y, powil(); | ||
| 440 | * int n; | ||
| 441 | * | ||
| 442 | * y = powil( x, n ); | ||
| 443 | * | ||
| 444 | * | ||
| 445 | * DESCRIPTION: | ||
| 446 | * | ||
| 447 | * Returns argument x>0 raised to the nth power. | ||
| 448 | * The routine efficiently decomposes n as a sum of powers of | ||
| 449 | * two. The desired power is a product of two-to-the-kth | ||
| 450 | * powers of x. Thus to compute the 32767 power of x requires | ||
| 451 | * 28 multiplications instead of 32767 multiplications. | ||
| 452 | * | ||
| 453 | * | ||
| 454 | * ACCURACY: | ||
| 455 | * | ||
| 456 | * Relative error: | ||
| 457 | * arithmetic x domain n domain # trials peak rms | ||
| 458 | * IEEE .001,1000 -1022,1023 50000 4.3e-17 7.8e-18 | ||
| 459 | * IEEE 1,2 -1022,1023 20000 3.9e-17 7.6e-18 | ||
| 460 | * IEEE .99,1.01 0,8700 10000 3.6e-16 7.2e-17 | ||
| 461 | * | ||
| 462 | * Returns MAXNUM on overflow, zero on underflow. | ||
| 463 | */ | ||
| 464 | |||
| 465 | static long double powil(long double x, int nn) | ||
| 466 | { | ||
| 467 | 	long double ww, y; | ||
| 468 | 	long double s; | ||
| 469 | 	int n, e, sign, lx; | ||
| 470 | |||
| 471 | 	if (nn == 0) | ||
| 472 | 		return 1.0; | ||
| 473 | |||
| 474 | 	if (nn < 0) { | ||
| 475 | 		sign = -1; | ||
| 476 | 		n = -nn; | ||
| 477 | 	} else { | ||
| 478 | 		sign = 1; | ||
| 479 | 		n = nn; | ||
| 480 | 	} | ||
| 481 | |||
| 482 | 	/* Overflow detection */ | ||
| 483 | |||
| 484 | 	/* Calculate approximate logarithm of answer */ | ||
| 485 | 	s = x; | ||
| 486 | 	s = frexpl( s, &lx); | ||
| 487 | 	e = (lx - 1)*n; | ||
| 488 | 	if ((e == 0) || (e > 64) || (e < -64)) { | ||
| 489 | 		s = (s - 7.0710678118654752e-1L) / (s + 7.0710678118654752e-1L); | ||
| 490 | 		s = (2.9142135623730950L * s - 0.5 + lx) * nn * LOGE2L; | ||
| 491 | 	} else { | ||
| 492 | 		s = LOGE2L * e; | ||
| 493 | 	} | ||
| 494 | |||
| 495 | 	if (s > MAXLOGL) | ||
| 496 | 		return huge * huge; /* overflow */ | ||
| 497 | |||
| 498 | 	if (s < MINLOGL) | ||
| 499 | 		return twom10000 * twom10000; /* underflow */ | ||
| 500 | 	/* Handle tiny denormal answer, but with less accuracy | ||
| 501 | 	 * since roundoff error in 1.0/x will be amplified. | ||
| 502 | 	 * The precise demarcation should be the gradual underflow threshold. | ||
| 503 | 	 */ | ||
| 504 | 	if (s < -MAXLOGL+2.0) { | ||
| 505 | 		x = 1.0/x; | ||
| 506 | 		sign = -sign; | ||
| 507 | 	} | ||
| 508 | |||
| 509 | 	/* First bit of the power */ | ||
| 510 | 	if (n & 1) | ||
| 511 | 		y = x; | ||
| 512 | 	else | ||
| 513 | 		y = 1.0; | ||
| 514 | |||
| 515 | 	ww = x; | ||
| 516 | 	n >>= 1; | ||
| 517 | 	while (n) { | ||
| 518 | 		ww = ww * ww; /* arg to the 2-to-the-kth power */ | ||
| 519 | 		if (n & 1) /* if that bit is set, then include in product */ | ||
| 520 | 			y *= ww; | ||
| 521 | 		n >>= 1; | ||
| 522 | 	} | ||
| 523 | |||
| 524 | 	if (sign < 0) | ||
| 525 | 		y = 1.0/y; | ||
| 526 | 	return y; | ||
| 527 | } | ||
| 528 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 529 | // TODO: broken implementation to make things compile | ||
| 530 | long double powl(long double x, long double y) | ||
| 531 | { | ||
| 532 | 	return pow(x, y); | ||
| 533 | } | ||
| 534 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/sinh.c deleted-43| ... | @@ -1,43 +0,0 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* sinh(x) = (exp(x) - 1/exp(x))/2 | ||
| 4 | * = (exp(x)-1 + (exp(x)-1)/exp(x))/2 | ||
| 5 | * = x + x^3/6 + o(x^5) | ||
| 6 | */ | ||
| 7 | double sinh(double x) | ||
| 8 | { | ||
| 9 | 	union {double f; uint64_t i;} u = {.f = x}; | ||
| 10 | 	uint32_t w; | ||
| 11 | 	double t, h, absx; | ||
| 12 | |||
| 13 | 	h = 0.5; | ||
| 14 | 	if (u.i >> 63) | ||
| 15 | 		h = -h; | ||
| 16 | 	/* |x| */ | ||
| 17 | 	u.i &= (uint64_t)-1/2; | ||
| 18 | 	absx = u.f; | ||
| 19 | 	w = u.i >> 32; | ||
| 20 | |||
| 21 | 	/* |x| < log(DBL_MAX) */ | ||
| 22 | 	if (w < 0x40862e42) { | ||
| 23 | 		t = expm1(absx); | ||
| 24 | 		if (w < 0x3ff00000) { | ||
| 25 | 			if (w < 0x3ff00000 - (26<<20)) | ||
| 26 | 				/* note: inexact and underflow are raised by expm1 */ | ||
| 27 | 				/* note: this branch avoids spurious underflow */ | ||
| 28 | 				return x; | ||
| 29 | 			return h*(2*t - t*t/(t+1)); | ||
| 30 | 		} | ||
| 31 | 		/* note: |x|>log(0x1p26)+eps could be just h*exp(x) */ | ||
| 32 | 		return h*(t + t/(t+1)); | ||
| 33 | 	} | ||
| 34 | |||
| 35 | 	/* |x| > log(DBL_MAX) or nan */ | ||
| 36 | 	/* note: the result is stored to handle overflow */ | ||
| 37 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 38 | 	t = __expo2(absx, 2*h); | ||
| 39 | #else | ||
| 40 | 	t = 2*h*__expo2(absx); | ||
| 41 | #endif | ||
| 42 | 	return t; | ||
| 43 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sinhf.c deleted-35| ... | @@ -1,35 +0,0 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float sinhf(float x) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {.f = x}; | ||
| 6 | 	uint32_t w; | ||
| 7 | 	float t, h, absx; | ||
| 8 | |||
| 9 | 	h = 0.5; | ||
| 10 | 	if (u.i >> 31) | ||
| 11 | 		h = -h; | ||
| 12 | 	/* |x| */ | ||
| 13 | 	u.i &= 0x7fffffff; | ||
| 14 | 	absx = u.f; | ||
| 15 | 	w = u.i; | ||
| 16 | |||
| 17 | 	/* |x| < log(FLT_MAX) */ | ||
| 18 | 	if (w < 0x42b17217) { | ||
| 19 | 		t = expm1f(absx); | ||
| 20 | 		if (w < 0x3f800000) { | ||
| 21 | 			if (w < 0x3f800000 - (12<<23)) | ||
| 22 | 				return x; | ||
| 23 | 			return h*(2*t - t*t/(t+1)); | ||
| 24 | 		} | ||
| 25 | 		return h*(t + t/(t+1)); | ||
| 26 | 	} | ||
| 27 | |||
| 28 | 	/* |x| > logf(FLT_MAX) or nan */ | ||
| 29 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 30 | 	t = __expo2f(absx, 2*h); | ||
| 31 | #else | ||
| 32 | 	t = 2*h*__expo2f(absx); | ||
| 33 | #endif | ||
| 34 | 	return t; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/dl.c deleted-45| ... | @@ -1,45 +0,0 @@ | ||
| 1 | /* This file is used to build libdl.so with stub versions of `dlopen`, `dlsym`, | ||
| 2 | * etc. The intention is that this stubbed libdl.so can be used to build | ||
| 3 | * libraries and applications which use `dlopen` without committing to a | ||
| 4 | * specific runtime implementation. Later, it can be replaced with a real, | ||
| 5 | * working libdl.so (e.g. at runtime or component composition time). | ||
| 6 | * | ||
| 7 | * For example, the `wasm-tools component link` subcommand can be used to create | ||
| 8 | * a component that bundles any `dlopen`-able libraries in such a way that their | ||
| 9 | * function exports can be resolved symbolically at runtime using an | ||
| 10 | * implementation of libdl.so designed for that purpose. In other cases, a | ||
| 11 | * runtime might provide Emscripten-style dynamic linking via URLs or else a | ||
| 12 | * more traditional, filesystem-based implementation. Finally, even this | ||
| 13 | * stubbed version of libdl.so can be used at runtime in cases where dynamic | ||
| 14 | * library resolution cannot or should not be supported (and the application can | ||
| 15 | * handle this situation gracefully). */ | ||
| 16 | |||
| 17 | #include <stddef.h> | ||
| 18 | #include <dlfcn.h> | ||
| 19 | |||
| 20 | static const char *error = NULL; | ||
| 21 | |||
| 22 | weak int dlclose(void *library) | ||
| 23 | { | ||
| 24 | 	error = "dlclose not implemented"; | ||
| 25 | 	return -1; | ||
| 26 | } | ||
| 27 | |||
| 28 | weak char *dlerror(void) | ||
| 29 | { | ||
| 30 | 	const char *var = error; | ||
| 31 | 	error = NULL; | ||
| 32 | 	return (char*) var; | ||
| 33 | } | ||
| 34 | |||
| 35 | weak void *dlopen(const char *name, int flags) | ||
| 36 | { | ||
| 37 | 	error = "dlopen not implemented"; | ||
| 38 | 	return NULL; | ||
| 39 | } | ||
| 40 | |||
| 41 | weak void *dlsym(void *library, const char *name) | ||
| 42 | { | ||
| 43 | 	error = "dlsym not implemented"; | ||
| 44 | 	return NULL; | ||
| 45 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/fmtmsg.c deleted-96| ... | @@ -1,96 +0,0 @@ | ||
| 1 | /* Public domain fmtmsg() | ||
| 2 | * Written by Isaac Dunham, 2014 | ||
| 3 | */ | ||
| 4 | #include <fmtmsg.h> | ||
| 5 | #include <fcntl.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include <stdio.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <stdlib.h> | ||
| 10 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 11 | #include <pthread.h> | ||
| 12 | #endif | ||
| 13 | |||
| 14 | /* | ||
| 15 | * If lstr is the first part of bstr, check that the next char in bstr | ||
| 16 | * is either \0 or : | ||
| 17 | */ | ||
| 18 | static int _strcolcmp(const char *lstr, const char *bstr) | ||
| 19 | { | ||
| 20 | 	size_t i = 0; | ||
| 21 | 	while (lstr[i] && bstr[i] && (bstr[i] == lstr[i])) i++; | ||
| 22 | 	if ( lstr[i] || (bstr[i] && bstr[i] != ':')) return 1; | ||
| 23 | 	return 0; | ||
| 24 | } | ||
| 25 | |||
| 26 | int fmtmsg(long classification, const char *label, int severity, | ||
| 27 | const char *text, const char *action, const char *tag) | ||
| 28 | { | ||
| 29 | 	int ret = 0, i, consolefd, verb = 0; | ||
| 30 | 	char *errstring = MM_NULLSEV, *cmsg = getenv("MSGVERB"); | ||
| 31 | 	char *const msgs[] = { | ||
| 32 | 		"label", "severity", "text", "action", "tag", NULL | ||
| 33 | 	}; | ||
| 34 | 	int cs; | ||
| 35 | |||
| 36 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 37 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 38 | #endif | ||
| 39 | |||
| 40 | 	if (severity == MM_HALT) errstring = "HALT: "; | ||
| 41 | 	else if (severity == MM_ERROR) errstring = "ERROR: "; | ||
| 42 | 	else if (severity == MM_WARNING) errstring = "WARNING: "; | ||
| 43 | 	else if (severity == MM_INFO) errstring = "INFO: "; | ||
| 44 | |||
| 45 | 	if (classification & MM_CONSOLE) { | ||
| 46 | 		consolefd = open("/dev/console", O_WRONLY); | ||
| 47 | 		if (consolefd < 0) { | ||
| 48 | 			ret = MM_NOCON; | ||
| 49 | 		} else { | ||
| 50 | 			if (dprintf(consolefd, "%s%s%s%s%s%s%s%s\n", | ||
| 51 | 			 label?label:"", label?": ":"", | ||
| 52 | 			 severity?errstring:"", text?text:"", | ||
| 53 | 			 action?"\nTO FIX: ":"", | ||
| 54 | 			 action?action:"", action?" ":"", | ||
| 55 | 			 tag?tag:"" )<1) | ||
| 56 | 				ret = MM_NOCON; | ||
| 57 | 			close(consolefd); | ||
| 58 | 		} | ||
| 59 | 	} | ||
| 60 | |||
| 61 | 	if (classification & MM_PRINT) { | ||
| 62 | 		while (cmsg && cmsg[0]) { | ||
| 63 | 			for(i=0; msgs[i]; i++) { | ||
| 64 | 				if (!_strcolcmp(msgs[i], cmsg)) break; | ||
| 65 | 			} | ||
| 66 | 			if (msgs[i] == NULL) { | ||
| 67 | 				//ignore MSGVERB-unrecognized component | ||
| 68 | 				verb = 0xFF; | ||
| 69 | 				break; | ||
| 70 | 			} else { | ||
| 71 | 				verb |= (1 << i); | ||
| 72 | 				cmsg = strchr(cmsg, ':'); | ||
| 73 | 				if (cmsg) cmsg++; | ||
| 74 | 			} | ||
| 75 | 		} | ||
| 76 | 		if (!verb) verb = 0xFF; | ||
| 77 | 		if (dprintf(2, "%s%s%s%s%s%s%s%s\n", | ||
| 78 | 		 (verb&1 && label) ? label : "", | ||
| 79 | 		 (verb&1 && label) ? ": " : "", | ||
| 80 | 		 (verb&2 && severity) ? errstring : "", | ||
| 81 | 		 (verb&4 && text) ? text : "", | ||
| 82 | 		 (verb&8 && action) ? "\nTO FIX: " : "", | ||
| 83 | 		 (verb&8 && action) ? action : "", | ||
| 84 | 		 (verb&8 && action) ? " " : "", | ||
| 85 | 		 (verb&16 && tag) ? tag : "" ) < 1) | ||
| 86 | 			ret |= MM_NOMSG; | ||
| 87 | 	} | ||
| 88 | 	if ((ret & (MM_NOCON|MM_NOMSG)) == (MM_NOCON|MM_NOMSG)) | ||
| 89 | 		ret = MM_NOTOK; | ||
| 90 | |||
| 91 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 92 | 	pthread_setcancelstate(cs, 0); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | 	return ret; | ||
| 96 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/nftw.c deleted-150| ... | @@ -1,150 +0,0 @@ | ||
| 1 | #include <ftw.h> | ||
| 2 | #include <dirent.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <sys/stat.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <limits.h> | ||
| 9 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 10 | #include <pthread.h> | ||
| 11 | #endif | ||
| 12 | |||
| 13 | struct history | ||
| 14 | { | ||
| 15 | 	struct history *chain; | ||
| 16 | 	dev_t dev; | ||
| 17 | 	ino_t ino; | ||
| 18 | 	int level; | ||
| 19 | 	int base; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #undef dirfd | ||
| 23 | #define dirfd(d) (*(int *)d) | ||
| 24 | |||
| 25 | static int do_nftw(char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags, struct history *h) | ||
| 26 | { | ||
| 27 | 	size_t l = strlen(path), j = l && path[l-1]=='/' ? l-1 : l; | ||
| 28 | 	struct stat st; | ||
| 29 | 	struct history new; | ||
| 30 | 	int type; | ||
| 31 | 	int r; | ||
| 32 | 	int dfd; | ||
| 33 | 	int err; | ||
| 34 | 	struct FTW lev; | ||
| 35 | |||
| 36 | 	st.st_dev = st.st_ino = 0; | ||
| 37 | |||
| 38 | 	if ((flags & FTW_PHYS) ? lstat(path, &st) : stat(path, &st) < 0) { | ||
| 39 | 		if (!(flags & FTW_PHYS) && errno==ENOENT && !lstat(path, &st)) | ||
| 40 | 			type = FTW_SLN; | ||
| 41 | 		else if (errno != EACCES) return -1; | ||
| 42 | 		else type = FTW_NS; | ||
| 43 | 	} else if (S_ISDIR(st.st_mode)) { | ||
| 44 | 		if (flags & FTW_DEPTH) type = FTW_DP; | ||
| 45 | 		else type = FTW_D; | ||
| 46 | 	} else if (S_ISLNK(st.st_mode)) { | ||
| 47 | 		if (flags & FTW_PHYS) type = FTW_SL; | ||
| 48 | 		else type = FTW_SLN; | ||
| 49 | 	} else { | ||
| 50 | 		type = FTW_F; | ||
| 51 | 	} | ||
| 52 | |||
| 53 | 	if ((flags & FTW_MOUNT) && h && type != FTW_NS && st.st_dev != h->dev) | ||
| 54 | 		return 0; | ||
| 55 | 	 | ||
| 56 | 	new.chain = h; | ||
| 57 | 	new.dev = st.st_dev; | ||
| 58 | 	new.ino = st.st_ino; | ||
| 59 | 	new.level = h ? h->level+1 : 0; | ||
| 60 | 	new.base = j+1; | ||
| 61 | 	 | ||
| 62 | 	lev.level = new.level; | ||
| 63 | 	if (h) { | ||
| 64 | 		lev.base = h->base; | ||
| 65 | 	} else { | ||
| 66 | 		size_t k; | ||
| 67 | 		for (k=j; k && path[k]=='/'; k--); | ||
| 68 | 		for (; k && path[k-1]!='/'; k--); | ||
| 69 | 		lev.base = k; | ||
| 70 | 	} | ||
| 71 | |||
| 72 | 	if (type == FTW_D || type == FTW_DP) { | ||
| 73 | 		dfd = open(path, O_RDONLY); | ||
| 74 | 		err = errno; | ||
| 75 | 		if (dfd < 0 && err == EACCES) type = FTW_DNR; | ||
| 76 | 		if (!fd_limit) close(dfd); | ||
| 77 | 	} | ||
| 78 | |||
| 79 | 	if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) | ||
| 80 | 		return r; | ||
| 81 | |||
| 82 | 	for (; h; h = h->chain) | ||
| 83 | 		if (h->dev == st.st_dev && h->ino == st.st_ino) | ||
| 84 | 			return 0; | ||
| 85 | |||
| 86 | 	if ((type == FTW_D || type == FTW_DP) && fd_limit) { | ||
| 87 | 		if (dfd < 0) { | ||
| 88 | 			errno = err; | ||
| 89 | 			return -1; | ||
| 90 | 		} | ||
| 91 | 		DIR *d = fdopendir(dfd); | ||
| 92 | 		if (d) { | ||
| 93 | 			struct dirent *de; | ||
| 94 | 			while ((de = readdir(d))) { | ||
| 95 | 				if (de->d_name[0] == '.' | ||
| 96 | 				 && (!de->d_name[1] | ||
| 97 | 				 || (de->d_name[1]=='.' | ||
| 98 | 				 && !de->d_name[2]))) continue; | ||
| 99 | 				if (strlen(de->d_name) >= PATH_MAX-l) { | ||
| 100 | 					errno = ENAMETOOLONG; | ||
| 101 | 					closedir(d); | ||
| 102 | 					return -1; | ||
| 103 | 				} | ||
| 104 | 				path[j]='/'; | ||
| 105 | 				strcpy(path+j+1, de->d_name); | ||
| 106 | 				if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { | ||
| 107 | 					closedir(d); | ||
| 108 | 					return r; | ||
| 109 | 				} | ||
| 110 | 			} | ||
| 111 | 			closedir(d); | ||
| 112 | 		} else { | ||
| 113 | 			close(dfd); | ||
| 114 | 			return -1; | ||
| 115 | 		} | ||
| 116 | 	} | ||
| 117 | |||
| 118 | 	path[l] = 0; | ||
| 119 | 	if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) | ||
| 120 | 		return r; | ||
| 121 | |||
| 122 | 	return 0; | ||
| 123 | } | ||
| 124 | |||
| 125 | int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) | ||
| 126 | { | ||
| 127 | 	int r, cs; | ||
| 128 | 	size_t l; | ||
| 129 | 	char pathbuf[PATH_MAX+1]; | ||
| 130 | |||
| 131 | 	if (fd_limit <= 0) return 0; | ||
| 132 | |||
| 133 | 	l = strlen(path); | ||
| 134 | 	if (l > PATH_MAX) { | ||
| 135 | 		errno = ENAMETOOLONG; | ||
| 136 | 		return -1; | ||
| 137 | 	} | ||
| 138 | 	memcpy(pathbuf, path, l+1); | ||
| 139 | 	 | ||
| 140 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 141 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 142 | #endif | ||
| 143 | 	r = do_nftw(pathbuf, fn, fd_limit, flags, NULL); | ||
| 144 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 145 | 	pthread_setcancelstate(cs, 0); | ||
| 146 | #endif | ||
| 147 | 	return r; | ||
| 148 | } | ||
| 149 | |||
| 150 | weak_alias(nftw, nftw64); | ||
lib/libc/wasi/libc-top-half/musl/src/prng/random.c deleted-126| ... | @@ -1,126 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "lock.h" | ||
| 4 | #include "fork_impl.h" | ||
| 5 | |||
| 6 | /* | ||
| 7 | this code uses the same lagged fibonacci generator as the | ||
| 8 | original bsd random implementation except for the seeding | ||
| 9 | which was broken in the original | ||
| 10 | */ | ||
| 11 | |||
| 12 | static uint32_t init[] = { | ||
| 13 | 0x00000000,0x5851f42d,0xc0b18ccf,0xcbb5f646, | ||
| 14 | 0xc7033129,0x30705b04,0x20fd5db4,0x9a8b7f78, | ||
| 15 | 0x502959d8,0xab894868,0x6c0356a7,0x88cdb7ff, | ||
| 16 | 0xb477d43f,0x70a3a52b,0xa8e4baf1,0xfd8341fc, | ||
| 17 | 0x8ae16fd9,0x742d2f7a,0x0d1f0796,0x76035e09, | ||
| 18 | 0x40f7702c,0x6fa72ca5,0xaaa84157,0x58a0df74, | ||
| 19 | 0xc74a0364,0xae533cc4,0x04185faf,0x6de3b115, | ||
| 20 | 0x0cab8628,0xf043bfa4,0x398150e9,0x37521657}; | ||
| 21 | |||
| 22 | static int n = 31; | ||
| 23 | static int i = 3; | ||
| 24 | static int j = 0; | ||
| 25 | static uint32_t *x = init+1; | ||
| 26 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 27 | static volatile int lock[1]; | ||
| 28 | volatile int *const __random_lockptr = lock; | ||
| 29 | #endif | ||
| 30 | |||
| 31 | static uint32_t lcg31(uint32_t x) { | ||
| 32 | 	return (1103515245*x + 12345) & 0x7fffffff; | ||
| 33 | } | ||
| 34 | |||
| 35 | static uint64_t lcg64(uint64_t x) { | ||
| 36 | 	return 6364136223846793005ull*x + 1; | ||
| 37 | } | ||
| 38 | |||
| 39 | static void *savestate() { | ||
| 40 | 	x[-1] = (n<<16)|(i<<8)|j; | ||
| 41 | 	return x-1; | ||
| 42 | } | ||
| 43 | |||
| 44 | static void loadstate(uint32_t *state) { | ||
| 45 | 	x = state+1; | ||
| 46 | 	n = x[-1]>>16; | ||
| 47 | 	i = (x[-1]>>8)&0xff; | ||
| 48 | 	j = x[-1]&0xff; | ||
| 49 | } | ||
| 50 | |||
| 51 | static void __srandom(unsigned seed) { | ||
| 52 | 	int k; | ||
| 53 | 	uint64_t s = seed; | ||
| 54 | |||
| 55 | 	if (n == 0) { | ||
| 56 | 		x[0] = s; | ||
| 57 | 		return; | ||
| 58 | 	} | ||
| 59 | 	i = n == 31 || n == 7 ? 3 : 1; | ||
| 60 | 	j = 0; | ||
| 61 | 	for (k = 0; k < n; k++) { | ||
| 62 | 		s = lcg64(s); | ||
| 63 | 		x[k] = s>>32; | ||
| 64 | 	} | ||
| 65 | 	/* make sure x contains at least one odd number */ | ||
| 66 | 	x[0] |= 1; | ||
| 67 | } | ||
| 68 | |||
| 69 | void srandom(unsigned seed) { | ||
| 70 | 	LOCK(lock); | ||
| 71 | 	__srandom(seed); | ||
| 72 | 	UNLOCK(lock); | ||
| 73 | } | ||
| 74 | |||
| 75 | char *initstate(unsigned seed, char *state, size_t size) { | ||
| 76 | 	void *old; | ||
| 77 | |||
| 78 | 	if (size < 8) | ||
| 79 | 		return 0; | ||
| 80 | 	LOCK(lock); | ||
| 81 | 	old = savestate(); | ||
| 82 | 	if (size < 32) | ||
| 83 | 		n = 0; | ||
| 84 | 	else if (size < 64) | ||
| 85 | 		n = 7; | ||
| 86 | 	else if (size < 128) | ||
| 87 | 		n = 15; | ||
| 88 | 	else if (size < 256) | ||
| 89 | 		n = 31; | ||
| 90 | 	else | ||
| 91 | 		n = 63; | ||
| 92 | 	x = (uint32_t*)state + 1; | ||
| 93 | 	__srandom(seed); | ||
| 94 | 	savestate(); | ||
| 95 | 	UNLOCK(lock); | ||
| 96 | 	return old; | ||
| 97 | } | ||
| 98 | |||
| 99 | char *setstate(char *state) { | ||
| 100 | 	void *old; | ||
| 101 | |||
| 102 | 	LOCK(lock); | ||
| 103 | 	old = savestate(); | ||
| 104 | 	loadstate((uint32_t*)state); | ||
| 105 | 	UNLOCK(lock); | ||
| 106 | 	return old; | ||
| 107 | } | ||
| 108 | |||
| 109 | long random(void) { | ||
| 110 | 	long k; | ||
| 111 | |||
| 112 | 	LOCK(lock); | ||
| 113 | 	if (n == 0) { | ||
| 114 | 		k = x[0] = lcg31(x[0]); | ||
| 115 | 		goto end; | ||
| 116 | 	} | ||
| 117 | 	x[i] += x[j]; | ||
| 118 | 	k = x[i]>>1; | ||
| 119 | 	if (++i == n) | ||
| 120 | 		i = 0; | ||
| 121 | 	if (++j == n) | ||
| 122 | 		j = 0; | ||
| 123 | end: | ||
| 124 | 	UNLOCK(lock); | ||
| 125 | 	return k; | ||
| 126 | } | ||
lib/libc/wasi/libc-top-half/musl/src/regex/glob.c deleted-317| ... | @@ -1,317 +0,0 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <glob.h> | ||
| 3 | #include <fnmatch.h> | ||
| 4 | #include <sys/stat.h> | ||
| 5 | #include <dirent.h> | ||
| 6 | #include <limits.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <stddef.h> | ||
| 11 | #include <unistd.h> | ||
| 12 | #ifdef __wasilibc_unmodified_upstream // WASI has no usernames | ||
| 13 | #include <pwd.h> | ||
| 14 | #endif | ||
| 15 | |||
| 16 | struct match | ||
| 17 | { | ||
| 18 | 	struct match *next; | ||
| 19 | 	char name[]; | ||
| 20 | }; | ||
| 21 | |||
| 22 | static int append(struct match **tail, const char *name, size_t len, int mark) | ||
| 23 | { | ||
| 24 | 	struct match *new = malloc(sizeof(struct match) + len + 2); | ||
| 25 | 	if (!new) return -1; | ||
| 26 | 	(*tail)->next = new; | ||
| 27 | 	new->next = NULL; | ||
| 28 | 	memcpy(new->name, name, len+1); | ||
| 29 | 	if (mark && len && name[len-1]!='/') { | ||
| 30 | 		new->name[len] = '/'; | ||
| 31 | 		new->name[len+1] = 0; | ||
| 32 | 	} | ||
| 33 | 	*tail = new; | ||
| 34 | 	return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | 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) | ||
| 38 | { | ||
| 39 | 	/* If GLOB_MARK is unused, we don't care about type. */ | ||
| 40 | 	if (!type && !(flags & GLOB_MARK)) type = DT_REG; | ||
| 41 | |||
| 42 | 	/* Special-case the remaining pattern being all slashes, in | ||
| 43 | 	 * which case we can use caller-passed type if it's a dir. */ | ||
| 44 | 	if (*pat && type!=DT_DIR) type = 0; | ||
| 45 | 	while (pos+1 < PATH_MAX && *pat=='/') buf[pos++] = *pat++; | ||
| 46 | |||
| 47 | 	/* Consume maximal [escaped-]literal prefix of pattern, copying | ||
| 48 | 	 * and un-escaping it to the running buffer as we go. */ | ||
| 49 | 	ptrdiff_t i=0, j=0; | ||
| 50 | 	int in_bracket = 0, overflow = 0; | ||
| 51 | 	for (; pat[i]!='*' && pat[i]!='?' && (!in_bracket || pat[i]!=']'); i++) { | ||
| 52 | 		if (!pat[i]) { | ||
| 53 | 			if (overflow) return 0; | ||
| 54 | 			pat += i; | ||
| 55 | 			pos += j; | ||
| 56 | 			i = j = 0; | ||
| 57 | 			break; | ||
| 58 | 		} else if (pat[i] == '[') { | ||
| 59 | 			in_bracket = 1; | ||
| 60 | 		} else if (pat[i] == '\\' && !(flags & GLOB_NOESCAPE)) { | ||
| 61 | 			/* Backslashes inside a bracket are (at least by | ||
| 62 | 			 * our interpretation) non-special, so if next | ||
| 63 | 			 * char is ']' we have a complete expression. */ | ||
| 64 | 			if (in_bracket && pat[i+1]==']') break; | ||
| 65 | 			/* Unpaired final backslash never matches. */ | ||
| 66 | 			if (!pat[i+1]) return 0; | ||
| 67 | 			i++; | ||
| 68 | 		} | ||
| 69 | 		if (pat[i] == '/') { | ||
| 70 | 			if (overflow) return 0; | ||
| 71 | 			in_bracket = 0; | ||
| 72 | 			pat += i+1; | ||
| 73 | 			i = -1; | ||
| 74 | 			pos += j+1; | ||
| 75 | 			j = -1; | ||
| 76 | 		} | ||
| 77 | 		/* Only store a character if it fits in the buffer, but if | ||
| 78 | 		 * a potential bracket expression is open, the overflow | ||
| 79 | 		 * must be remembered and handled later only if the bracket | ||
| 80 | 		 * is unterminated (and thereby a literal), so as not to | ||
| 81 | 		 * disallow long bracket expressions with short matches. */ | ||
| 82 | 		if (pos+(j+1) < PATH_MAX) { | ||
| 83 | 			buf[pos+j++] = pat[i]; | ||
| 84 | 		} else if (in_bracket) { | ||
| 85 | 			overflow = 1; | ||
| 86 | 		} else { | ||
| 87 | 			return 0; | ||
| 88 | 		} | ||
| 89 | 		/* If we consume any new components, the caller-passed type | ||
| 90 | 		 * or dummy type from above is no longer valid. */ | ||
| 91 | 		type = 0; | ||
| 92 | 	} | ||
| 93 | 	buf[pos] = 0; | ||
| 94 | 	if (!*pat) { | ||
| 95 | 		/* If we consumed any components above, or if GLOB_MARK is | ||
| 96 | 		 * requested and we don't yet know if the match is a dir, | ||
| 97 | 		 * we must confirm the file exists and/or determine its type. | ||
| 98 | 		 * | ||
| 99 | 		 * If marking dirs, symlink type is inconclusive; we need the | ||
| 100 | 		 * type for the symlink target, and therefore must try stat | ||
| 101 | 		 * first unless type is known not to be a symlink. Otherwise, | ||
| 102 | 		 * or if that fails, use lstat for determining existence to | ||
| 103 | 		 * avoid false negatives in the case of broken symlinks. */ | ||
| 104 | 		struct stat st; | ||
| 105 | 		if ((flags & GLOB_MARK) && (!type||type==DT_LNK) && !stat(buf, &st)) { | ||
| 106 | 			if (S_ISDIR(st.st_mode)) type = DT_DIR; | ||
| 107 | 			else type = DT_REG; | ||
| 108 | 		} | ||
| 109 | 		if (!type && lstat(buf, &st)) { | ||
| 110 | 			if (errno!=ENOENT && (errfunc(buf, errno) || (flags & GLOB_ERR))) | ||
| 111 | 				return GLOB_ABORTED; | ||
| 112 | 			return 0; | ||
| 113 | 		} | ||
| 114 | 		if (append(tail, buf, pos, (flags & GLOB_MARK) && type==DT_DIR)) | ||
| 115 | 			return GLOB_NOSPACE; | ||
| 116 | 		return 0; | ||
| 117 | 	} | ||
| 118 | 	char *p2 = strchr(pat, '/'), saved_sep = '/'; | ||
| 119 | 	/* Check if the '/' was escaped and, if so, remove the escape char | ||
| 120 | 	 * so that it will not be unpaired when passed to fnmatch. */ | ||
| 121 | 	if (p2 && !(flags & GLOB_NOESCAPE)) { | ||
| 122 | 		char *p; | ||
| 123 | 		for (p=p2; p>pat && p[-1]=='\\'; p--); | ||
| 124 | 		if ((p2-p)%2) { | ||
| 125 | 			p2--; | ||
| 126 | 			saved_sep = '\\'; | ||
| 127 | 		} | ||
| 128 | 	} | ||
| 129 | 	DIR *dir = opendir(pos ? buf : "."); | ||
| 130 | 	if (!dir) { | ||
| 131 | 		if (errfunc(buf, errno) || (flags & GLOB_ERR)) | ||
| 132 | 			return GLOB_ABORTED; | ||
| 133 | 		return 0; | ||
| 134 | 	} | ||
| 135 | 	int old_errno = errno; | ||
| 136 | 	struct dirent *de; | ||
| 137 | 	while (errno=0, de=readdir(dir)) { | ||
| 138 | 		/* Quickly skip non-directories when there's pattern left. */ | ||
| 139 | 		if (p2 && de->d_type && de->d_type!=DT_DIR && de->d_type!=DT_LNK) | ||
| 140 | 			continue; | ||
| 141 | |||
| 142 | 		size_t l = strlen(de->d_name); | ||
| 143 | 		if (l >= PATH_MAX-pos) continue; | ||
| 144 | |||
| 145 | 		if (p2) *p2 = 0; | ||
| 146 | |||
| 147 | 		int fnm_flags= ((flags & GLOB_NOESCAPE) ? FNM_NOESCAPE : 0) | ||
| 148 | 			| ((!(flags & GLOB_PERIOD)) ? FNM_PERIOD : 0); | ||
| 149 | |||
| 150 | 		if (fnmatch(pat, de->d_name, fnm_flags)) | ||
| 151 | 			continue; | ||
| 152 | |||
| 153 | 		/* With GLOB_PERIOD, don't allow matching . or .. unless | ||
| 154 | 		 * fnmatch would match them with FNM_PERIOD rules in effect. */ | ||
| 155 | 		if (p2 && (flags & GLOB_PERIOD) && de->d_name[0]=='.' | ||
| 156 | 		 && (!de->d_name[1] || de->d_name[1]=='.' && !de->d_name[2]) | ||
| 157 | 		 && fnmatch(pat, de->d_name, fnm_flags | FNM_PERIOD)) | ||
| 158 | 			continue; | ||
| 159 | |||
| 160 | 		memcpy(buf+pos, de->d_name, l+1); | ||
| 161 | 		if (p2) *p2 = saved_sep; | ||
| 162 | 		int r = do_glob(buf, pos+l, de->d_type, p2 ? p2 : "", flags, errfunc, tail); | ||
| 163 | 		if (r) { | ||
| 164 | 			closedir(dir); | ||
| 165 | 			return r; | ||
| 166 | 		} | ||
| 167 | 	} | ||
| 168 | 	int readerr = errno; | ||
| 169 | 	if (p2) *p2 = saved_sep; | ||
| 170 | 	closedir(dir); | ||
| 171 | 	if (readerr && (errfunc(buf, errno) || (flags & GLOB_ERR))) | ||
| 172 | 		return GLOB_ABORTED; | ||
| 173 | 	errno = old_errno; | ||
| 174 | 	return 0; | ||
| 175 | } | ||
| 176 | |||
| 177 | static int ignore_err(const char *path, int err) | ||
| 178 | { | ||
| 179 | 	return 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | static void freelist(struct match *head) | ||
| 183 | { | ||
| 184 | 	struct match *match, *next; | ||
| 185 | 	for (match=head->next; match; match=next) { | ||
| 186 | 		next = match->next; | ||
| 187 | 		free(match); | ||
| 188 | 	} | ||
| 189 | } | ||
| 190 | |||
| 191 | static int sort(const void *a, const void *b) | ||
| 192 | { | ||
| 193 | 	return strcmp(*(const char **)a, *(const char **)b); | ||
| 194 | } | ||
| 195 | |||
| 196 | #ifdef __wasilibc_unmodified_upstream // WASI has no usernames | ||
| 197 | static int expand_tilde(char **pat, char *buf, size_t *pos) | ||
| 198 | { | ||
| 199 | 	char *p = *pat + 1; | ||
| 200 | 	size_t i = 0; | ||
| 201 | |||
| 202 | 	char delim, *name_end = __strchrnul(p, '/'); | ||
| 203 | 	if ((delim = *name_end)) *name_end++ = 0; | ||
| 204 | 	*pat = name_end; | ||
| 205 | |||
| 206 | 	char *home = *p ? NULL : getenv("HOME"); | ||
| 207 | 	if (!home) { | ||
| 208 | 		struct passwd pw, *res; | ||
| 209 | 		switch (*p ? getpwnam_r(p, &pw, buf, PATH_MAX, &res) | ||
| 210 | 			 : getpwuid_r(getuid(), &pw, buf, PATH_MAX, &res)) { | ||
| 211 | 		case ENOMEM: | ||
| 212 | 			return GLOB_NOSPACE; | ||
| 213 | 		case 0: | ||
| 214 | 			if (!res) | ||
| 215 | 		default: | ||
| 216 | 				return GLOB_NOMATCH; | ||
| 217 | 		} | ||
| 218 | 		home = pw.pw_dir; | ||
| 219 | 	} | ||
| 220 | 	while (i < PATH_MAX - 2 && *home) | ||
| 221 | 		buf[i++] = *home++; | ||
| 222 | 	if (*home) | ||
| 223 | 		return GLOB_NOMATCH; | ||
| 224 | 	if ((buf[i] = delim)) | ||
| 225 | 		buf[++i] = 0; | ||
| 226 | 	*pos = i; | ||
| 227 | 	return 0; | ||
| 228 | } | ||
| 229 | #endif | ||
| 230 | |||
| 231 | int glob(const char *restrict pat, int flags, int (*errfunc)(const char *path, int err), glob_t *restrict g) | ||
| 232 | { | ||
| 233 | 	struct match head = { .next = NULL }, *tail = &head; | ||
| 234 | 	size_t cnt, i; | ||
| 235 | 	size_t offs = (flags & GLOB_DOOFFS) ? g->gl_offs : 0; | ||
| 236 | 	int error = 0; | ||
| 237 | 	char buf[PATH_MAX]; | ||
| 238 | 	 | ||
| 239 | 	if (!errfunc) errfunc = ignore_err; | ||
| 240 | |||
| 241 | 	if (!(flags & GLOB_APPEND)) { | ||
| 242 | 		g->gl_offs = offs; | ||
| 243 | 		g->gl_pathc = 0; | ||
| 244 | 		g->gl_pathv = NULL; | ||
| 245 | 	} | ||
| 246 | |||
| 247 | 	if (*pat) { | ||
| 248 | 		char *p = strdup(pat); | ||
| 249 | 		if (!p) return GLOB_NOSPACE; | ||
| 250 | 		buf[0] = 0; | ||
| 251 | 		size_t pos = 0; | ||
| 252 | 		char *s = p; | ||
| 253 | #ifdef __wasilibc_unmodified_upstream // WASI has no usernames | ||
| 254 | 		if ((flags & (GLOB_TILDE | GLOB_TILDE_CHECK)) && *p == '~') | ||
| 255 | 			error = expand_tilde(&s, buf, &pos); | ||
| 256 | #endif | ||
| 257 | 		if (!error) | ||
| 258 | 			error = do_glob(buf, pos, 0, s, flags, errfunc, &tail); | ||
| 259 | 		free(p); | ||
| 260 | 	} | ||
| 261 | |||
| 262 | 	if (error == GLOB_NOSPACE) { | ||
| 263 | 		freelist(&head); | ||
| 264 | 		return error; | ||
| 265 | 	} | ||
| 266 | 	 | ||
| 267 | 	for (cnt=0, tail=head.next; tail; tail=tail->next, cnt++); | ||
| 268 | 	if (!cnt) { | ||
| 269 | 		if (flags & GLOB_NOCHECK) { | ||
| 270 | 			tail = &head; | ||
| 271 | 			if (append(&tail, pat, strlen(pat), 0)) | ||
| 272 | 				return GLOB_NOSPACE; | ||
| 273 | 			cnt++; | ||
| 274 | 		} else if (!error) | ||
| 275 | 			return GLOB_NOMATCH; | ||
| 276 | 	} | ||
| 277 | |||
| 278 | 	if (flags & GLOB_APPEND) { | ||
| 279 | 		char **pathv = realloc(g->gl_pathv, (offs + g->gl_pathc + cnt + 1) * sizeof(char *)); | ||
| 280 | 		if (!pathv) { | ||
| 281 | 			freelist(&head); | ||
| 282 | 			return GLOB_NOSPACE; | ||
| 283 | 		} | ||
| 284 | 		g->gl_pathv = pathv; | ||
| 285 | 		offs += g->gl_pathc; | ||
| 286 | 	} else { | ||
| 287 | 		g->gl_pathv = malloc((offs + cnt + 1) * sizeof(char *)); | ||
| 288 | 		if (!g->gl_pathv) { | ||
| 289 | 			freelist(&head); | ||
| 290 | 			return GLOB_NOSPACE; | ||
| 291 | 		} | ||
| 292 | 		for (i=0; i<offs; i++) | ||
| 293 | 			g->gl_pathv[i] = NULL; | ||
| 294 | 	} | ||
| 295 | 	for (i=0, tail=head.next; i<cnt; tail=tail->next, i++) | ||
| 296 | 		g->gl_pathv[offs + i] = tail->name; | ||
| 297 | 	g->gl_pathv[offs + i] = NULL; | ||
| 298 | 	g->gl_pathc += cnt; | ||
| 299 | |||
| 300 | 	if (!(flags & GLOB_NOSORT)) | ||
| 301 | 		qsort(g->gl_pathv+offs, cnt, sizeof(char *), sort); | ||
| 302 | 	 | ||
| 303 | 	return error; | ||
| 304 | } | ||
| 305 | |||
| 306 | void globfree(glob_t *g) | ||
| 307 | { | ||
| 308 | 	size_t i; | ||
| 309 | 	for (i=0; i<g->gl_pathc; i++) | ||
| 310 | 		free(g->gl_pathv[g->gl_offs + i] - offsetof(struct match, name)); | ||
| 311 | 	free(g->gl_pathv); | ||
| 312 | 	g->gl_pathc = 0; | ||
| 313 | 	g->gl_pathv = NULL; | ||
| 314 | } | ||
| 315 | |||
| 316 | weak_alias(glob, glob64); | ||
| 317 | weak_alias(globfree, globfree64); | ||
lib/libc/wasi/libc-top-half/musl/src/regex/regcomp.c deleted-2953| ... | @@ -1,2953 +0,0 @@ | ||
| 1 | /* | ||
| 2 | regcomp.c - TRE POSIX compatible regex compilation functions. | ||
| 3 | |||
| 4 | Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi> | ||
| 5 | All rights reserved. | ||
| 6 | |||
| 7 | Redistribution and use in source and binary forms, with or without | ||
| 8 | modification, are permitted provided that the following conditions | ||
| 9 | are met: | ||
| 10 | |||
| 11 | 1. Redistributions of source code must retain the above copyright | ||
| 12 | notice, this list of conditions and the following disclaimer. | ||
| 13 | |||
| 14 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | notice, this list of conditions and the following disclaimer in the | ||
| 16 | documentation and/or other materials provided with the distribution. | ||
| 17 | |||
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS | ||
| 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | */ | ||
| 31 | |||
| 32 | #include <string.h> | ||
| 33 | #include <stdlib.h> | ||
| 34 | #include <regex.h> | ||
| 35 | #include <limits.h> | ||
| 36 | #include <stdint.h> | ||
| 37 | #include <ctype.h> | ||
| 38 | |||
| 39 | #include "tre.h" | ||
| 40 | |||
| 41 | #include <assert.h> | ||
| 42 | |||
| 43 | /*********************************************************************** | ||
| 44 | from tre-compile.h | ||
| 45 | ***********************************************************************/ | ||
| 46 | |||
| 47 | typedef struct { | ||
| 48 | int position; | ||
| 49 | int code_min; | ||
| 50 | int code_max; | ||
| 51 | int *tags; | ||
| 52 | int assertions; | ||
| 53 | tre_ctype_t class; | ||
| 54 | tre_ctype_t *neg_classes; | ||
| 55 | int backref; | ||
| 56 | } tre_pos_and_tags_t; | ||
| 57 | |||
| 58 | |||
| 59 | /*********************************************************************** | ||
| 60 | from tre-ast.c and tre-ast.h | ||
| 61 | ***********************************************************************/ | ||
| 62 | |||
| 63 | /* The different AST node types. */ | ||
| 64 | typedef enum { | ||
| 65 | LITERAL, | ||
| 66 | CATENATION, | ||
| 67 | ITERATION, | ||
| 68 | UNION | ||
| 69 | } tre_ast_type_t; | ||
| 70 | |||
| 71 | /* Special subtypes of TRE_LITERAL. */ | ||
| 72 | #define EMPTY	 -1 /* Empty leaf (denotes empty string). */ | ||
| 73 | #define ASSERTION -2 /* Assertion leaf. */ | ||
| 74 | #define TAG	 -3 /* Tag leaf. */ | ||
| 75 | #define BACKREF	 -4 /* Back reference leaf. */ | ||
| 76 | |||
| 77 | #define IS_SPECIAL(x)	((x)->code_min < 0) | ||
| 78 | #define IS_EMPTY(x)	((x)->code_min == EMPTY) | ||
| 79 | #define IS_ASSERTION(x) ((x)->code_min == ASSERTION) | ||
| 80 | #define IS_TAG(x)	((x)->code_min == TAG) | ||
| 81 | #define IS_BACKREF(x)	((x)->code_min == BACKREF) | ||
| 82 | |||
| 83 | |||
| 84 | /* A generic AST node. All AST nodes consist of this node on the top | ||
| 85 | level with `obj' pointing to the actual content. */ | ||
| 86 | typedef struct { | ||
| 87 | tre_ast_type_t type; /* Type of the node. */ | ||
| 88 | void *obj; /* Pointer to actual node. */ | ||
| 89 | int nullable; | ||
| 90 | int submatch_id; | ||
| 91 | int num_submatches; | ||
| 92 | int num_tags; | ||
| 93 | tre_pos_and_tags_t *firstpos; | ||
| 94 | tre_pos_and_tags_t *lastpos; | ||
| 95 | } tre_ast_node_t; | ||
| 96 | |||
| 97 | |||
| 98 | /* A "literal" node. These are created for assertions, back references, | ||
| 99 | tags, matching parameter settings, and all expressions that match one | ||
| 100 | character. */ | ||
| 101 | typedef struct { | ||
| 102 | long code_min; | ||
| 103 | long code_max; | ||
| 104 | int position; | ||
| 105 | tre_ctype_t class; | ||
| 106 | tre_ctype_t *neg_classes; | ||
| 107 | } tre_literal_t; | ||
| 108 | |||
| 109 | /* A "catenation" node.	 These are created when two regexps are concatenated. | ||
| 110 | If there are more than one subexpressions in sequence, the `left' part | ||
| 111 | holds all but the last, and `right' part holds the last subexpression | ||
| 112 | (catenation is left associative). */ | ||
| 113 | typedef struct { | ||
| 114 | tre_ast_node_t *left; | ||
| 115 | tre_ast_node_t *right; | ||
| 116 | } tre_catenation_t; | ||
| 117 | |||
| 118 | /* An "iteration" node.	 These are created for the "*", "+", "?", and "{m,n}" | ||
| 119 | operators. */ | ||
| 120 | typedef struct { | ||
| 121 | /* Subexpression to match. */ | ||
| 122 | tre_ast_node_t *arg; | ||
| 123 | /* Minimum number of consecutive matches. */ | ||
| 124 | int min; | ||
| 125 | /* Maximum number of consecutive matches. */ | ||
| 126 | int max; | ||
| 127 | /* If 0, match as many characters as possible, if 1 match as few as | ||
| 128 | possible.	Note that this does not always mean the same thing as | ||
| 129 | matching as many/few repetitions as possible. */ | ||
| 130 | unsigned int minimal:1; | ||
| 131 | } tre_iteration_t; | ||
| 132 | |||
| 133 | /* An "union" node. These are created for the "|" operator. */ | ||
| 134 | typedef struct { | ||
| 135 | tre_ast_node_t *left; | ||
| 136 | tre_ast_node_t *right; | ||
| 137 | } tre_union_t; | ||
| 138 | |||
| 139 | |||
| 140 | static tre_ast_node_t * | ||
| 141 | tre_ast_new_node(tre_mem_t mem, int type, void *obj) | ||
| 142 | { | ||
| 143 | 	tre_ast_node_t *node = tre_mem_calloc(mem, sizeof *node); | ||
| 144 | 	if (!node || !obj) | ||
| 145 | 		return 0; | ||
| 146 | 	node->obj = obj; | ||
| 147 | 	node->type = type; | ||
| 148 | 	node->nullable = -1; | ||
| 149 | 	node->submatch_id = -1; | ||
| 150 | 	return node; | ||
| 151 | } | ||
| 152 | |||
| 153 | static tre_ast_node_t * | ||
| 154 | tre_ast_new_literal(tre_mem_t mem, int code_min, int code_max, int position) | ||
| 155 | { | ||
| 156 | 	tre_ast_node_t *node; | ||
| 157 | 	tre_literal_t *lit; | ||
| 158 | |||
| 159 | 	lit = tre_mem_calloc(mem, sizeof *lit); | ||
| 160 | 	node = tre_ast_new_node(mem, LITERAL, lit); | ||
| 161 | 	if (!node) | ||
| 162 | 		return 0; | ||
| 163 | 	lit->code_min = code_min; | ||
| 164 | 	lit->code_max = code_max; | ||
| 165 | 	lit->position = position; | ||
| 166 | 	return node; | ||
| 167 | } | ||
| 168 | |||
| 169 | static tre_ast_node_t * | ||
| 170 | tre_ast_new_iter(tre_mem_t mem, tre_ast_node_t *arg, int min, int max, int minimal) | ||
| 171 | { | ||
| 172 | 	tre_ast_node_t *node; | ||
| 173 | 	tre_iteration_t *iter; | ||
| 174 | |||
| 175 | 	iter = tre_mem_calloc(mem, sizeof *iter); | ||
| 176 | 	node = tre_ast_new_node(mem, ITERATION, iter); | ||
| 177 | 	if (!node) | ||
| 178 | 		return 0; | ||
| 179 | 	iter->arg = arg; | ||
| 180 | 	iter->min = min; | ||
| 181 | 	iter->max = max; | ||
| 182 | 	iter->minimal = minimal; | ||
| 183 | 	node->num_submatches = arg->num_submatches; | ||
| 184 | 	return node; | ||
| 185 | } | ||
| 186 | |||
| 187 | static tre_ast_node_t * | ||
| 188 | tre_ast_new_union(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right) | ||
| 189 | { | ||
| 190 | 	tre_ast_node_t *node; | ||
| 191 | 	tre_union_t *un; | ||
| 192 | |||
| 193 | 	if (!left) | ||
| 194 | 		return right; | ||
| 195 | 	un = tre_mem_calloc(mem, sizeof *un); | ||
| 196 | 	node = tre_ast_new_node(mem, UNION, un); | ||
| 197 | 	if (!node || !right) | ||
| 198 | 		return 0; | ||
| 199 | 	un->left = left; | ||
| 200 | 	un->right = right; | ||
| 201 | 	node->num_submatches = left->num_submatches + right->num_submatches; | ||
| 202 | 	return node; | ||
| 203 | } | ||
| 204 | |||
| 205 | static tre_ast_node_t * | ||
| 206 | tre_ast_new_catenation(tre_mem_t mem, tre_ast_node_t *left, tre_ast_node_t *right) | ||
| 207 | { | ||
| 208 | 	tre_ast_node_t *node; | ||
| 209 | 	tre_catenation_t *cat; | ||
| 210 | |||
| 211 | 	if (!left) | ||
| 212 | 		return right; | ||
| 213 | 	cat = tre_mem_calloc(mem, sizeof *cat); | ||
| 214 | 	node = tre_ast_new_node(mem, CATENATION, cat); | ||
| 215 | 	if (!node) | ||
| 216 | 		return 0; | ||
| 217 | 	cat->left = left; | ||
| 218 | 	cat->right = right; | ||
| 219 | 	node->num_submatches = left->num_submatches + right->num_submatches; | ||
| 220 | 	return node; | ||
| 221 | } | ||
| 222 | |||
| 223 | |||
| 224 | /*********************************************************************** | ||
| 225 | from tre-stack.c and tre-stack.h | ||
| 226 | ***********************************************************************/ | ||
| 227 | |||
| 228 | typedef struct tre_stack_rec tre_stack_t; | ||
| 229 | |||
| 230 | /* Creates a new stack object.	`size' is initial size in bytes, `max_size' | ||
| 231 | is maximum size, and `increment' specifies how much more space will be | ||
| 232 | allocated with realloc() if all space gets used up.	Returns the stack | ||
| 233 | object or NULL if out of memory. */ | ||
| 234 | static tre_stack_t * | ||
| 235 | tre_stack_new(int size, int max_size, int increment); | ||
| 236 | |||
| 237 | /* Frees the stack object. */ | ||
| 238 | static void | ||
| 239 | tre_stack_destroy(tre_stack_t *s); | ||
| 240 | |||
| 241 | /* Returns the current number of objects in the stack. */ | ||
| 242 | static int | ||
| 243 | tre_stack_num_objects(tre_stack_t *s); | ||
| 244 | |||
| 245 | /* Each tre_stack_push_*(tre_stack_t *s, <type> value) function pushes | ||
| 246 | `value' on top of stack `s'. Returns REG_ESPACE if out of memory. | ||
| 247 | This tries to realloc() more space before failing if maximum size | ||
| 248 | has not yet been reached. Returns REG_OK if successful. */ | ||
| 249 | #define declare_pushf(typetag, type)					 \ | ||
| 250 | static reg_errcode_t tre_stack_push_ ## typetag(tre_stack_t *s, type value) | ||
| 251 | |||
| 252 | declare_pushf(voidptr, void *); | ||
| 253 | declare_pushf(int, int); | ||
| 254 | |||
| 255 | /* Each tre_stack_pop_*(tre_stack_t *s) function pops the topmost | ||
| 256 | element off of stack `s' and returns it. The stack must not be | ||
| 257 | empty. */ | ||
| 258 | #define declare_popf(typetag, type)		 \ | ||
| 259 | static type tre_stack_pop_ ## typetag(tre_stack_t *s) | ||
| 260 | |||
| 261 | declare_popf(voidptr, void *); | ||
| 262 | declare_popf(int, int); | ||
| 263 | |||
| 264 | /* Just to save some typing. */ | ||
| 265 | #define STACK_PUSH(s, typetag, value)					 \ | ||
| 266 | do									 \ | ||
| 267 | {									 \ | ||
| 268 | status = tre_stack_push_ ## typetag(s, value);			 \ | ||
| 269 | }									 \ | ||
| 270 | while (/*CONSTCOND*/0) | ||
| 271 | |||
| 272 | #define STACK_PUSHX(s, typetag, value)					 \ | ||
| 273 | {									 \ | ||
| 274 | status = tre_stack_push_ ## typetag(s, value);			 \ | ||
| 275 | if (status != REG_OK)						 \ | ||
| 276 | break;								 \ | ||
| 277 | } | ||
| 278 | |||
| 279 | #define STACK_PUSHR(s, typetag, value)					 \ | ||
| 280 | {									 \ | ||
| 281 | reg_errcode_t _status;						 \ | ||
| 282 | _status = tre_stack_push_ ## typetag(s, value);			 \ | ||
| 283 | if (_status != REG_OK)						 \ | ||
| 284 | return _status;							 \ | ||
| 285 | } | ||
| 286 | |||
| 287 | union tre_stack_item { | ||
| 288 | void *voidptr_value; | ||
| 289 | int int_value; | ||
| 290 | }; | ||
| 291 | |||
| 292 | struct tre_stack_rec { | ||
| 293 | int size; | ||
| 294 | int max_size; | ||
| 295 | int increment; | ||
| 296 | int ptr; | ||
| 297 | union tre_stack_item *stack; | ||
| 298 | }; | ||
| 299 | |||
| 300 | |||
| 301 | static tre_stack_t * | ||
| 302 | tre_stack_new(int size, int max_size, int increment) | ||
| 303 | { | ||
| 304 | tre_stack_t *s; | ||
| 305 | |||
| 306 | s = xmalloc(sizeof(*s)); | ||
| 307 | if (s != NULL) | ||
| 308 | { | ||
| 309 | s->stack = xmalloc(sizeof(*s->stack) * size); | ||
| 310 | if (s->stack == NULL) | ||
| 311 | 	{ | ||
| 312 | 	 xfree(s); | ||
| 313 | 	 return NULL; | ||
| 314 | 	} | ||
| 315 | s->size = size; | ||
| 316 | s->max_size = max_size; | ||
| 317 | s->increment = increment; | ||
| 318 | s->ptr = 0; | ||
| 319 | } | ||
| 320 | return s; | ||
| 321 | } | ||
| 322 | |||
| 323 | static void | ||
| 324 | tre_stack_destroy(tre_stack_t *s) | ||
| 325 | { | ||
| 326 | xfree(s->stack); | ||
| 327 | xfree(s); | ||
| 328 | } | ||
| 329 | |||
| 330 | static int | ||
| 331 | tre_stack_num_objects(tre_stack_t *s) | ||
| 332 | { | ||
| 333 | return s->ptr; | ||
| 334 | } | ||
| 335 | |||
| 336 | static reg_errcode_t | ||
| 337 | tre_stack_push(tre_stack_t *s, union tre_stack_item value) | ||
| 338 | { | ||
| 339 | if (s->ptr < s->size) | ||
| 340 | { | ||
| 341 | s->stack[s->ptr] = value; | ||
| 342 | s->ptr++; | ||
| 343 | } | ||
| 344 | else | ||
| 345 | { | ||
| 346 | if (s->size >= s->max_size) | ||
| 347 | 	{ | ||
| 348 | 	 return REG_ESPACE; | ||
| 349 | 	} | ||
| 350 | else | ||
| 351 | 	{ | ||
| 352 | 	 union tre_stack_item *new_buffer; | ||
| 353 | 	 int new_size; | ||
| 354 | 	 new_size = s->size + s->increment; | ||
| 355 | 	 if (new_size > s->max_size) | ||
| 356 | 	 new_size = s->max_size; | ||
| 357 | 	 new_buffer = xrealloc(s->stack, sizeof(*new_buffer) * new_size); | ||
| 358 | 	 if (new_buffer == NULL) | ||
| 359 | 	 { | ||
| 360 | 	 return REG_ESPACE; | ||
| 361 | 	 } | ||
| 362 | 	 assert(new_size > s->size); | ||
| 363 | 	 s->size = new_size; | ||
| 364 | 	 s->stack = new_buffer; | ||
| 365 | 	 tre_stack_push(s, value); | ||
| 366 | 	} | ||
| 367 | } | ||
| 368 | return REG_OK; | ||
| 369 | } | ||
| 370 | |||
| 371 | #define define_pushf(typetag, type) \ | ||
| 372 | declare_pushf(typetag, type) { \ | ||
| 373 | union tre_stack_item item;	 \ | ||
| 374 | item.typetag ## _value = value; \ | ||
| 375 | return tre_stack_push(s, item); \ | ||
| 376 | } | ||
| 377 | |||
| 378 | define_pushf(int, int) | ||
| 379 | define_pushf(voidptr, void *) | ||
| 380 | |||
| 381 | #define define_popf(typetag, type)		 \ | ||
| 382 | declare_popf(typetag, type) {			 \ | ||
| 383 | return s->stack[--s->ptr].typetag ## _value; \ | ||
| 384 | } | ||
| 385 | |||
| 386 | define_popf(int, int) | ||
| 387 | define_popf(voidptr, void *) | ||
| 388 | |||
| 389 | |||
| 390 | /*********************************************************************** | ||
| 391 | from tre-parse.c and tre-parse.h | ||
| 392 | ***********************************************************************/ | ||
| 393 | |||
| 394 | /* Parse context. */ | ||
| 395 | typedef struct { | ||
| 396 | 	/* Memory allocator. The AST is allocated using this. */ | ||
| 397 | 	tre_mem_t mem; | ||
| 398 | 	/* Stack used for keeping track of regexp syntax. */ | ||
| 399 | 	tre_stack_t *stack; | ||
| 400 | 	/* The parsed node after a parse function returns. */ | ||
| 401 | 	tre_ast_node_t *n; | ||
| 402 | 	/* Position in the regexp pattern after a parse function returns. */ | ||
| 403 | 	const char *s; | ||
| 404 | 	/* The first character of the last subexpression parsed. */ | ||
| 405 | 	const char *start; | ||
| 406 | 	/* Current submatch ID. */ | ||
| 407 | 	int submatch_id; | ||
| 408 | 	/* Current position (number of literal). */ | ||
| 409 | 	int position; | ||
| 410 | 	/* The highest back reference or -1 if none seen so far. */ | ||
| 411 | 	int max_backref; | ||
| 412 | 	/* Compilation flags. */ | ||
| 413 | 	int cflags; | ||
| 414 | } tre_parse_ctx_t; | ||
| 415 | |||
| 416 | /* Some macros for expanding \w, \s, etc. */ | ||
| 417 | static const struct { | ||
| 418 | 	char c; | ||
| 419 | 	const char *expansion; | ||
| 420 | } tre_macros[] = { | ||
| 421 | 	{'t', "\t"}, {'n', "\n"}, {'r', "\r"}, | ||
| 422 | 	{'f', "\f"}, {'a', "\a"}, {'e', "\033"}, | ||
| 423 | 	{'w', "[[:alnum:]_]"}, {'W', "[^[:alnum:]_]"}, {'s', "[[:space:]]"}, | ||
| 424 | 	{'S', "[^[:space:]]"}, {'d', "[[:digit:]]"}, {'D', "[^[:digit:]]"}, | ||
| 425 | 	{ 0, 0 } | ||
| 426 | }; | ||
| 427 | |||
| 428 | /* Expands a macro delimited by `regex' and `regex_end' to `buf', which | ||
| 429 | must have at least `len' items. Sets buf[0] to zero if the there | ||
| 430 | is no match in `tre_macros'. */ | ||
| 431 | static const char *tre_expand_macro(const char *s) | ||
| 432 | { | ||
| 433 | 	int i; | ||
| 434 | 	for (i = 0; tre_macros[i].c && tre_macros[i].c != *s; i++); | ||
| 435 | 	return tre_macros[i].expansion; | ||
| 436 | } | ||
| 437 | |||
| 438 | static int | ||
| 439 | tre_compare_lit(const void *a, const void *b) | ||
| 440 | { | ||
| 441 | 	const tre_literal_t *const *la = a; | ||
| 442 | 	const tre_literal_t *const *lb = b; | ||
| 443 | 	/* assumes the range of valid code_min is < INT_MAX */ | ||
| 444 | 	return la[0]->code_min - lb[0]->code_min; | ||
| 445 | } | ||
| 446 | |||
| 447 | struct literals { | ||
| 448 | 	tre_mem_t mem; | ||
| 449 | 	tre_literal_t **a; | ||
| 450 | 	int len; | ||
| 451 | 	int cap; | ||
| 452 | }; | ||
| 453 | |||
| 454 | static tre_literal_t *tre_new_lit(struct literals *p) | ||
| 455 | { | ||
| 456 | 	tre_literal_t **a; | ||
| 457 | 	if (p->len >= p->cap) { | ||
| 458 | 		if (p->cap >= 1<<15) | ||
| 459 | 			return 0; | ||
| 460 | 		p->cap *= 2; | ||
| 461 | 		a = xrealloc(p->a, p->cap * sizeof *p->a); | ||
| 462 | 		if (!a) | ||
| 463 | 			return 0; | ||
| 464 | 		p->a = a; | ||
| 465 | 	} | ||
| 466 | 	a = p->a + p->len++; | ||
| 467 | 	*a = tre_mem_calloc(p->mem, sizeof **a); | ||
| 468 | 	return *a; | ||
| 469 | } | ||
| 470 | |||
| 471 | static int add_icase_literals(struct literals *ls, int min, int max) | ||
| 472 | { | ||
| 473 | 	tre_literal_t *lit; | ||
| 474 | 	int b, e, c; | ||
| 475 | 	for (c=min; c<=max; ) { | ||
| 476 | 		/* assumes islower(c) and isupper(c) are exclusive | ||
| 477 | 		 and toupper(c)!=c if islower(c). | ||
| 478 | 		 multiple opposite case characters are not supported */ | ||
| 479 | 		if (tre_islower(c)) { | ||
| 480 | 			b = e = tre_toupper(c); | ||
| 481 | 			for (c++, e++; c<=max; c++, e++) | ||
| 482 | 				if (tre_toupper(c) != e) break; | ||
| 483 | 		} else if (tre_isupper(c)) { | ||
| 484 | 			b = e = tre_tolower(c); | ||
| 485 | 			for (c++, e++; c<=max; c++, e++) | ||
| 486 | 				if (tre_tolower(c) != e) break; | ||
| 487 | 		} else { | ||
| 488 | 			c++; | ||
| 489 | 			continue; | ||
| 490 | 		} | ||
| 491 | 		lit = tre_new_lit(ls); | ||
| 492 | 		if (!lit) | ||
| 493 | 			return -1; | ||
| 494 | 		lit->code_min = b; | ||
| 495 | 		lit->code_max = e-1; | ||
| 496 | 		lit->position = -1; | ||
| 497 | 	} | ||
| 498 | 	return 0; | ||
| 499 | } | ||
| 500 | |||
| 501 | |||
| 502 | /* Maximum number of character classes in a negated bracket expression. */ | ||
| 503 | #define MAX_NEG_CLASSES 64 | ||
| 504 | |||
| 505 | struct neg { | ||
| 506 | 	int negate; | ||
| 507 | 	int len; | ||
| 508 | 	tre_ctype_t a[MAX_NEG_CLASSES]; | ||
| 509 | }; | ||
| 510 | |||
| 511 | // TODO: parse bracket into a set of non-overlapping [lo,hi] ranges | ||
| 512 | |||
| 513 | /* | ||
| 514 | bracket grammar: | ||
| 515 | Bracket = '[' List ']' | '[^' List ']' | ||
| 516 | List = Term | List Term | ||
| 517 | Term = Char | Range | Chclass | Eqclass | ||
| 518 | Range = Char '-' Char | Char '-' '-' | ||
| 519 | Char = Coll | coll_single | ||
| 520 | Meta = ']' | '-' | ||
| 521 | Coll = '[.' coll_single '.]' | '[.' coll_multi '.]' | '[.' Meta '.]' | ||
| 522 | Eqclass = '[=' coll_single '=]' | '[=' coll_multi '=]' | ||
| 523 | Chclass = '[:' class ':]' | ||
| 524 | |||
| 525 | coll_single is a single char collating element but it can be | ||
| 526 | '-' only at the beginning or end of a List and | ||
| 527 | ']' only at the beginning of a List and | ||
| 528 | '^' anywhere except after the openning '[' | ||
| 529 | */ | ||
| 530 | |||
| 531 | static reg_errcode_t parse_bracket_terms(tre_parse_ctx_t *ctx, const char *s, struct literals *ls, struct neg *neg) | ||
| 532 | { | ||
| 533 | 	const char *start = s; | ||
| 534 | 	tre_ctype_t class; | ||
| 535 | 	int min, max; | ||
| 536 | 	wchar_t wc; | ||
| 537 | 	int len; | ||
| 538 | |||
| 539 | 	for (;;) { | ||
| 540 | 		class = 0; | ||
| 541 | 		len = mbtowc(&wc, s, -1); | ||
| 542 | 		if (len <= 0) | ||
| 543 | 			return *s ? REG_BADPAT : REG_EBRACK; | ||
| 544 | 		if (*s == ']' && s != start) { | ||
| 545 | 			ctx->s = s+1; | ||
| 546 | 			return REG_OK; | ||
| 547 | 		} | ||
| 548 | 		if (*s == '-' && s != start && s[1] != ']' && | ||
| 549 | 		 /* extension: [a-z--@] is accepted as [a-z]|[--@] */ | ||
| 550 | 		 (s[1] != '-' || s[2] == ']')) | ||
| 551 | 			return REG_ERANGE; | ||
| 552 | 		if (*s == '[' && (s[1] == '.' || s[1] == '=')) | ||
| 553 | 			/* collating symbols and equivalence classes are not supported */ | ||
| 554 | 			return REG_ECOLLATE; | ||
| 555 | 		if (*s == '[' && s[1] == ':') { | ||
| 556 | 			char tmp[CHARCLASS_NAME_MAX+1]; | ||
| 557 | 			s += 2; | ||
| 558 | 			for (len=0; len < CHARCLASS_NAME_MAX && s[len]; len++) { | ||
| 559 | 				if (s[len] == ':') { | ||
| 560 | 					memcpy(tmp, s, len); | ||
| 561 | 					tmp[len] = 0; | ||
| 562 | 					class = tre_ctype(tmp); | ||
| 563 | 					break; | ||
| 564 | 				} | ||
| 565 | 			} | ||
| 566 | 			if (!class || s[len+1] != ']') | ||
| 567 | 				return REG_ECTYPE; | ||
| 568 | 			min = 0; | ||
| 569 | 			max = TRE_CHAR_MAX; | ||
| 570 | 			s += len+2; | ||
| 571 | 		} else { | ||
| 572 | 			min = max = wc; | ||
| 573 | 			s += len; | ||
| 574 | 			if (*s == '-' && s[1] != ']') { | ||
| 575 | 				s++; | ||
| 576 | 				len = mbtowc(&wc, s, -1); | ||
| 577 | 				max = wc; | ||
| 578 | 				/* XXX - Should use collation order instead of | ||
| 579 | 				 encoding values in character ranges. */ | ||
| 580 | 				if (len <= 0 || min > max) | ||
| 581 | 					return REG_ERANGE; | ||
| 582 | 				s += len; | ||
| 583 | 			} | ||
| 584 | 		} | ||
| 585 | |||
| 586 | 		if (class && neg->negate) { | ||
| 587 | 			if (neg->len >= MAX_NEG_CLASSES) | ||
| 588 | 				return REG_ESPACE; | ||
| 589 | 			neg->a[neg->len++] = class; | ||
| 590 | 		} else { | ||
| 591 | 			tre_literal_t *lit = tre_new_lit(ls); | ||
| 592 | 			if (!lit) | ||
| 593 | 				return REG_ESPACE; | ||
| 594 | 			lit->code_min = min; | ||
| 595 | 			lit->code_max = max; | ||
| 596 | 			lit->class = class; | ||
| 597 | 			lit->position = -1; | ||
| 598 | |||
| 599 | 			/* Add opposite-case codepoints if REG_ICASE is present. | ||
| 600 | 			 It seems that POSIX requires that bracket negation | ||
| 601 | 			 should happen before case-folding, but most practical | ||
| 602 | 			 implementations do it the other way around. Changing | ||
| 603 | 			 the order would need efficient representation of | ||
| 604 | 			 case-fold ranges and bracket range sets even with | ||
| 605 | 			 simple patterns so this is ok for now. */ | ||
| 606 | 			if (ctx->cflags & REG_ICASE && !class) | ||
| 607 | 				if (add_icase_literals(ls, min, max)) | ||
| 608 | 					return REG_ESPACE; | ||
| 609 | 		} | ||
| 610 | 	} | ||
| 611 | } | ||
| 612 | |||
| 613 | static reg_errcode_t parse_bracket(tre_parse_ctx_t *ctx, const char *s) | ||
| 614 | { | ||
| 615 | 	int i, max, min, negmax, negmin; | ||
| 616 | 	tre_ast_node_t *node = 0, *n; | ||
| 617 | 	tre_ctype_t *nc = 0; | ||
| 618 | 	tre_literal_t *lit; | ||
| 619 | 	struct literals ls; | ||
| 620 | 	struct neg neg; | ||
| 621 | 	reg_errcode_t err; | ||
| 622 | |||
| 623 | 	ls.mem = ctx->mem; | ||
| 624 | 	ls.len = 0; | ||
| 625 | 	ls.cap = 32; | ||
| 626 | 	ls.a = xmalloc(ls.cap * sizeof *ls.a); | ||
| 627 | 	if (!ls.a) | ||
| 628 | 		return REG_ESPACE; | ||
| 629 | 	neg.len = 0; | ||
| 630 | 	neg.negate = *s == '^'; | ||
| 631 | 	if (neg.negate) | ||
| 632 | 		s++; | ||
| 633 | |||
| 634 | 	err = parse_bracket_terms(ctx, s, &ls, &neg); | ||
| 635 | 	if (err != REG_OK) | ||
| 636 | 		goto parse_bracket_done; | ||
| 637 | |||
| 638 | 	if (neg.negate) { | ||
| 639 | 		/* | ||
| 640 | 		 * With REG_NEWLINE, POSIX requires that newlines are not matched by | ||
| 641 | 		 * any form of a non-matching list. | ||
| 642 | 		 */ | ||
| 643 | 		if (ctx->cflags & REG_NEWLINE) { | ||
| 644 | 			lit = tre_new_lit(&ls); | ||
| 645 | 			if (!lit) { | ||
| 646 | 				err = REG_ESPACE; | ||
| 647 | 				goto parse_bracket_done; | ||
| 648 | 			} | ||
| 649 | 			lit->code_min = '\n'; | ||
| 650 | 			lit->code_max = '\n'; | ||
| 651 | 			lit->position = -1; | ||
| 652 | 		} | ||
| 653 | 		/* Sort the array if we need to negate it. */ | ||
| 654 | 		qsort(ls.a, ls.len, sizeof *ls.a, tre_compare_lit); | ||
| 655 | 		/* extra lit for the last negated range */ | ||
| 656 | 		lit = tre_new_lit(&ls); | ||
| 657 | 		if (!lit) { | ||
| 658 | 			err = REG_ESPACE; | ||
| 659 | 			goto parse_bracket_done; | ||
| 660 | 		} | ||
| 661 | 		lit->code_min = TRE_CHAR_MAX+1; | ||
| 662 | 		lit->code_max = TRE_CHAR_MAX+1; | ||
| 663 | 		lit->position = -1; | ||
| 664 | 		/* negated classes */ | ||
| 665 | 		if (neg.len) { | ||
| 666 | 			nc = tre_mem_alloc(ctx->mem, (neg.len+1)*sizeof *neg.a); | ||
| 667 | 			if (!nc) { | ||
| 668 | 				err = REG_ESPACE; | ||
| 669 | 				goto parse_bracket_done; | ||
| 670 | 			} | ||
| 671 | 			memcpy(nc, neg.a, neg.len*sizeof *neg.a); | ||
| 672 | 			nc[neg.len] = 0; | ||
| 673 | 		} | ||
| 674 | 	} | ||
| 675 | |||
| 676 | 	/* Build a union of the items in the array, negated if necessary. */ | ||
| 677 | 	negmax = negmin = 0; | ||
| 678 | 	for (i = 0; i < ls.len; i++) { | ||
| 679 | 		lit = ls.a[i]; | ||
| 680 | 		min = lit->code_min; | ||
| 681 | 		max = lit->code_max; | ||
| 682 | 		if (neg.negate) { | ||
| 683 | 			if (min <= negmin) { | ||
| 684 | 				/* Overlap. */ | ||
| 685 | 				negmin = MAX(max + 1, negmin); | ||
| 686 | 				continue; | ||
| 687 | 			} | ||
| 688 | 			negmax = min - 1; | ||
| 689 | 			lit->code_min = negmin; | ||
| 690 | 			lit->code_max = negmax; | ||
| 691 | 			negmin = max + 1; | ||
| 692 | 		} | ||
| 693 | 		lit->position = ctx->position; | ||
| 694 | 		lit->neg_classes = nc; | ||
| 695 | 		n = tre_ast_new_node(ctx->mem, LITERAL, lit); | ||
| 696 | 		node = tre_ast_new_union(ctx->mem, node, n); | ||
| 697 | 		if (!node) { | ||
| 698 | 			err = REG_ESPACE; | ||
| 699 | 			break; | ||
| 700 | 		} | ||
| 701 | 	} | ||
| 702 | |||
| 703 | parse_bracket_done: | ||
| 704 | 	xfree(ls.a); | ||
| 705 | 	ctx->position++; | ||
| 706 | 	ctx->n = node; | ||
| 707 | 	return err; | ||
| 708 | } | ||
| 709 | |||
| 710 | static const char *parse_dup_count(const char *s, int *n) | ||
| 711 | { | ||
| 712 | 	*n = -1; | ||
| 713 | 	if (!isdigit(*s)) | ||
| 714 | 		return s; | ||
| 715 | 	*n = 0; | ||
| 716 | 	for (;;) { | ||
| 717 | 		*n = 10 * *n + (*s - '0'); | ||
| 718 | 		s++; | ||
| 719 | 		if (!isdigit(*s) || *n > RE_DUP_MAX) | ||
| 720 | 			break; | ||
| 721 | 	} | ||
| 722 | 	return s; | ||
| 723 | } | ||
| 724 | |||
| 725 | static const char *parse_dup(const char *s, int ere, int *pmin, int *pmax) | ||
| 726 | { | ||
| 727 | 	int min, max; | ||
| 728 | |||
| 729 | 	s = parse_dup_count(s, &min); | ||
| 730 | 	if (*s == ',') | ||
| 731 | 		s = parse_dup_count(s+1, &max); | ||
| 732 | 	else | ||
| 733 | 		max = min; | ||
| 734 | |||
| 735 | 	if ( | ||
| 736 | 		(max < min && max >= 0) || | ||
| 737 | 		max > RE_DUP_MAX || | ||
| 738 | 		min > RE_DUP_MAX || | ||
| 739 | 		min < 0 || | ||
| 740 | 		(!ere && *s++ != '\\') || | ||
| 741 | 		*s++ != '}' | ||
| 742 | 	) | ||
| 743 | 		return 0; | ||
| 744 | 	*pmin = min; | ||
| 745 | 	*pmax = max; | ||
| 746 | 	return s; | ||
| 747 | } | ||
| 748 | |||
| 749 | static int hexval(unsigned c) | ||
| 750 | { | ||
| 751 | 	if (c-'0'<10) return c-'0'; | ||
| 752 | 	c |= 32; | ||
| 753 | 	if (c-'a'<6) return c-'a'+10; | ||
| 754 | 	return -1; | ||
| 755 | } | ||
| 756 | |||
| 757 | static reg_errcode_t marksub(tre_parse_ctx_t *ctx, tre_ast_node_t *node, int subid) | ||
| 758 | { | ||
| 759 | 	if (node->submatch_id >= 0) { | ||
| 760 | 		tre_ast_node_t *n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); | ||
| 761 | 		if (!n) | ||
| 762 | 			return REG_ESPACE; | ||
| 763 | 		n = tre_ast_new_catenation(ctx->mem, n, node); | ||
| 764 | 		if (!n) | ||
| 765 | 			return REG_ESPACE; | ||
| 766 | 		n->num_submatches = node->num_submatches; | ||
| 767 | 		node = n; | ||
| 768 | 	} | ||
| 769 | 	node->submatch_id = subid; | ||
| 770 | 	node->num_submatches++; | ||
| 771 | 	ctx->n = node; | ||
| 772 | 	return REG_OK; | ||
| 773 | } | ||
| 774 | |||
| 775 | /* | ||
| 776 | BRE grammar: | ||
| 777 | Regex = Branch | '^' | '$' | '^$' | '^' Branch | Branch '$' | '^' Branch '$' | ||
| 778 | Branch = Atom | Branch Atom | ||
| 779 | Atom = char | quoted_char | '.' | Bracket | Atom Dup | '\(' Branch '\)' | back_ref | ||
| 780 | Dup = '*' | '\{' Count '\}' | '\{' Count ',\}' | '\{' Count ',' Count '\}' | ||
| 781 | |||
| 782 | (leading ^ and trailing $ in a sub expr may be an anchor or literal as well) | ||
| 783 | |||
| 784 | ERE grammar: | ||
| 785 | Regex = Branch | Regex '|' Branch | ||
| 786 | Branch = Atom | Branch Atom | ||
| 787 | Atom = char | quoted_char | '.' | Bracket | Atom Dup | '(' Regex ')' | '^' | '$' | ||
| 788 | Dup = '*' | '+' | '?' | '{' Count '}' | '{' Count ',}' | '{' Count ',' Count '}' | ||
| 789 | |||
| 790 | (a*+?, ^*, $+, \X, {, (|a) are unspecified) | ||
| 791 | */ | ||
| 792 | |||
| 793 | static reg_errcode_t parse_atom(tre_parse_ctx_t *ctx, const char *s) | ||
| 794 | { | ||
| 795 | 	int len, ere = ctx->cflags & REG_EXTENDED; | ||
| 796 | 	const char *p; | ||
| 797 | 	tre_ast_node_t *node; | ||
| 798 | 	wchar_t wc; | ||
| 799 | 	switch (*s) { | ||
| 800 | 	case '[': | ||
| 801 | 		return parse_bracket(ctx, s+1); | ||
| 802 | 	case '\\': | ||
| 803 | 		p = tre_expand_macro(s+1); | ||
| 804 | 		if (p) { | ||
| 805 | 			/* assume \X expansion is a single atom */ | ||
| 806 | 			reg_errcode_t err = parse_atom(ctx, p); | ||
| 807 | 			ctx->s = s+2; | ||
| 808 | 			return err; | ||
| 809 | 		} | ||
| 810 | 		/* extensions: \b, \B, \<, \>, \xHH \x{HHHH} */ | ||
| 811 | 		switch (*++s) { | ||
| 812 | 		case 0: | ||
| 813 | 			return REG_EESCAPE; | ||
| 814 | 		case 'b': | ||
| 815 | 			node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_WB, -1); | ||
| 816 | 			break; | ||
| 817 | 		case 'B': | ||
| 818 | 			node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_WB_NEG, -1); | ||
| 819 | 			break; | ||
| 820 | 		case '<': | ||
| 821 | 			node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_BOW, -1); | ||
| 822 | 			break; | ||
| 823 | 		case '>': | ||
| 824 | 			node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_EOW, -1); | ||
| 825 | 			break; | ||
| 826 | 		case 'x': | ||
| 827 | 			s++; | ||
| 828 | 			int i, v = 0, c; | ||
| 829 | 			len = 2; | ||
| 830 | 			if (*s == '{') { | ||
| 831 | 				len = 8; | ||
| 832 | 				s++; | ||
| 833 | 			} | ||
| 834 | 			for (i=0; i<len && v<0x110000; i++) { | ||
| 835 | 				c = hexval(s[i]); | ||
| 836 | 				if (c < 0) break; | ||
| 837 | 				v = 16*v + c; | ||
| 838 | 			} | ||
| 839 | 			s += i; | ||
| 840 | 			if (len == 8) { | ||
| 841 | 				if (*s != '}') | ||
| 842 | 					return REG_EBRACE; | ||
| 843 | 				s++; | ||
| 844 | 			} | ||
| 845 | 			node = tre_ast_new_literal(ctx->mem, v, v, ctx->position++); | ||
| 846 | 			s--; | ||
| 847 | 			break; | ||
| 848 | 		case '{': | ||
| 849 | 		case '+': | ||
| 850 | 		case '?': | ||
| 851 | 			/* extension: treat \+, \? as repetitions in BRE */ | ||
| 852 | 			/* reject repetitions after empty expression in BRE */ | ||
| 853 | 			if (!ere) | ||
| 854 | 				return REG_BADRPT; | ||
| 855 | 		case '|': | ||
| 856 | 			/* extension: treat \| as alternation in BRE */ | ||
| 857 | 			if (!ere) { | ||
| 858 | 				node = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); | ||
| 859 | 				s--; | ||
| 860 | 				goto end; | ||
| 861 | 			} | ||
| 862 | 			/* fallthrough */ | ||
| 863 | 		default: | ||
| 864 | 			if (!ere && (unsigned)*s-'1' < 9) { | ||
| 865 | 				/* back reference */ | ||
| 866 | 				int val = *s - '0'; | ||
| 867 | 				node = tre_ast_new_literal(ctx->mem, BACKREF, val, ctx->position++); | ||
| 868 | 				ctx->max_backref = MAX(val, ctx->max_backref); | ||
| 869 | 			} else { | ||
| 870 | 				/* extension: accept unknown escaped char | ||
| 871 | 				 as a literal */ | ||
| 872 | 				goto parse_literal; | ||
| 873 | 			} | ||
| 874 | 		} | ||
| 875 | 		s++; | ||
| 876 | 		break; | ||
| 877 | 	case '.': | ||
| 878 | 		if (ctx->cflags & REG_NEWLINE) { | ||
| 879 | 			tre_ast_node_t *tmp1, *tmp2; | ||
| 880 | 			tmp1 = tre_ast_new_literal(ctx->mem, 0, '\n'-1, ctx->position++); | ||
| 881 | 			tmp2 = tre_ast_new_literal(ctx->mem, '\n'+1, TRE_CHAR_MAX, ctx->position++); | ||
| 882 | 			if (tmp1 && tmp2) | ||
| 883 | 				node = tre_ast_new_union(ctx->mem, tmp1, tmp2); | ||
| 884 | 			else | ||
| 885 | 				node = 0; | ||
| 886 | 		} else { | ||
| 887 | 			node = tre_ast_new_literal(ctx->mem, 0, TRE_CHAR_MAX, ctx->position++); | ||
| 888 | 		} | ||
| 889 | 		s++; | ||
| 890 | 		break; | ||
| 891 | 	case '^': | ||
| 892 | 		/* '^' has a special meaning everywhere in EREs, and at beginning of BRE. */ | ||
| 893 | 		if (!ere && s != ctx->start) | ||
| 894 | 			goto parse_literal; | ||
| 895 | 		node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_BOL, -1); | ||
| 896 | 		s++; | ||
| 897 | 		break; | ||
| 898 | 	case '$': | ||
| 899 | 		/* '$' is special everywhere in EREs, and at the end of a BRE subexpression. */ | ||
| 900 | 		if (!ere && s[1] && (s[1]!='\\'|| (s[2]!=')' && s[2]!='|'))) | ||
| 901 | 			goto parse_literal; | ||
| 902 | 		node = tre_ast_new_literal(ctx->mem, ASSERTION, ASSERT_AT_EOL, -1); | ||
| 903 | 		s++; | ||
| 904 | 		break; | ||
| 905 | 	case '*': | ||
| 906 | 	case '{': | ||
| 907 | 	case '+': | ||
| 908 | 	case '?': | ||
| 909 | 		/* reject repetitions after empty expression in ERE */ | ||
| 910 | 		if (ere) | ||
| 911 | 			return REG_BADRPT; | ||
| 912 | 	case '|': | ||
| 913 | 		if (!ere) | ||
| 914 | 			goto parse_literal; | ||
| 915 | 	case 0: | ||
| 916 | 		node = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); | ||
| 917 | 		break; | ||
| 918 | 	default: | ||
| 919 | parse_literal: | ||
| 920 | 		len = mbtowc(&wc, s, -1); | ||
| 921 | 		if (len < 0) | ||
| 922 | 			return REG_BADPAT; | ||
| 923 | 		if (ctx->cflags & REG_ICASE && (tre_isupper(wc) || tre_islower(wc))) { | ||
| 924 | 			tre_ast_node_t *tmp1, *tmp2; | ||
| 925 | 			/* multiple opposite case characters are not supported */ | ||
| 926 | 			tmp1 = tre_ast_new_literal(ctx->mem, tre_toupper(wc), tre_toupper(wc), ctx->position); | ||
| 927 | 			tmp2 = tre_ast_new_literal(ctx->mem, tre_tolower(wc), tre_tolower(wc), ctx->position); | ||
| 928 | 			if (tmp1 && tmp2) | ||
| 929 | 				node = tre_ast_new_union(ctx->mem, tmp1, tmp2); | ||
| 930 | 			else | ||
| 931 | 				node = 0; | ||
| 932 | 		} else { | ||
| 933 | 			node = tre_ast_new_literal(ctx->mem, wc, wc, ctx->position); | ||
| 934 | 		} | ||
| 935 | 		ctx->position++; | ||
| 936 | 		s += len; | ||
| 937 | 		break; | ||
| 938 | 	} | ||
| 939 | end: | ||
| 940 | 	if (!node) | ||
| 941 | 		return REG_ESPACE; | ||
| 942 | 	ctx->n = node; | ||
| 943 | 	ctx->s = s; | ||
| 944 | 	return REG_OK; | ||
| 945 | } | ||
| 946 | |||
| 947 | #define PUSHPTR(err, s, v) do { \ | ||
| 948 | 	if ((err = tre_stack_push_voidptr(s, v)) != REG_OK) \ | ||
| 949 | 		return err; \ | ||
| 950 | } while(0) | ||
| 951 | |||
| 952 | #define PUSHINT(err, s, v) do { \ | ||
| 953 | 	if ((err = tre_stack_push_int(s, v)) != REG_OK) \ | ||
| 954 | 		return err; \ | ||
| 955 | } while(0) | ||
| 956 | |||
| 957 | static reg_errcode_t tre_parse(tre_parse_ctx_t *ctx) | ||
| 958 | { | ||
| 959 | 	tre_ast_node_t *nbranch=0, *nunion=0; | ||
| 960 | 	int ere = ctx->cflags & REG_EXTENDED; | ||
| 961 | 	const char *s = ctx->start; | ||
| 962 | 	int subid = 0; | ||
| 963 | 	int depth = 0; | ||
| 964 | 	reg_errcode_t err; | ||
| 965 | 	tre_stack_t *stack = ctx->stack; | ||
| 966 | |||
| 967 | 	PUSHINT(err, stack, subid++); | ||
| 968 | 	for (;;) { | ||
| 969 | 		if ((!ere && *s == '\\' && s[1] == '(') || | ||
| 970 | 		 (ere && *s == '(')) { | ||
| 971 | 			PUSHPTR(err, stack, nunion); | ||
| 972 | 			PUSHPTR(err, stack, nbranch); | ||
| 973 | 			PUSHINT(err, stack, subid++); | ||
| 974 | 			s++; | ||
| 975 | 			if (!ere) | ||
| 976 | 				s++; | ||
| 977 | 			depth++; | ||
| 978 | 			nbranch = nunion = 0; | ||
| 979 | 			ctx->start = s; | ||
| 980 | 			continue; | ||
| 981 | 		} | ||
| 982 | 		if ((!ere && *s == '\\' && s[1] == ')') || | ||
| 983 | 		 (ere && *s == ')' && depth)) { | ||
| 984 | 			ctx->n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); | ||
| 985 | 			if (!ctx->n) | ||
| 986 | 				return REG_ESPACE; | ||
| 987 | 		} else { | ||
| 988 | 			err = parse_atom(ctx, s); | ||
| 989 | 			if (err != REG_OK) | ||
| 990 | 				return err; | ||
| 991 | 			s = ctx->s; | ||
| 992 | 		} | ||
| 993 | |||
| 994 | 	parse_iter: | ||
| 995 | 		for (;;) { | ||
| 996 | 			int min, max; | ||
| 997 | |||
| 998 | 			if (*s!='\\' && *s!='*') { | ||
| 999 | 				if (!ere) | ||
| 1000 | 					break; | ||
| 1001 | 				if (*s!='+' && *s!='?' && *s!='{') | ||
| 1002 | 					break; | ||
| 1003 | 			} | ||
| 1004 | 			if (*s=='\\' && ere) | ||
| 1005 | 				break; | ||
| 1006 | 			/* extension: treat \+, \? as repetitions in BRE */ | ||
| 1007 | 			if (*s=='\\' && s[1]!='+' && s[1]!='?' && s[1]!='{') | ||
| 1008 | 				break; | ||
| 1009 | 			if (*s=='\\') | ||
| 1010 | 				s++; | ||
| 1011 | |||
| 1012 | 			/* handle ^* at the start of a BRE. */ | ||
| 1013 | 			if (!ere && s==ctx->start+1 && s[-1]=='^') | ||
| 1014 | 				break; | ||
| 1015 | |||
| 1016 | 			/* extension: multiple consecutive *+?{,} is unspecified, | ||
| 1017 | 			 but (a+)+ has to be supported so accepting a++ makes | ||
| 1018 | 			 sense, note however that the RE_DUP_MAX limit can be | ||
| 1019 | 			 circumvented: (a{255}){255} uses a lot of memory.. */ | ||
| 1020 | 			if (*s=='{') { | ||
| 1021 | 				s = parse_dup(s+1, ere, &min, &max); | ||
| 1022 | 				if (!s) | ||
| 1023 | 					return REG_BADBR; | ||
| 1024 | 			} else { | ||
| 1025 | 				min=0; | ||
| 1026 | 				max=-1; | ||
| 1027 | 				if (*s == '+') | ||
| 1028 | 					min = 1; | ||
| 1029 | 				if (*s == '?') | ||
| 1030 | 					max = 1; | ||
| 1031 | 				s++; | ||
| 1032 | 			} | ||
| 1033 | 			if (max == 0) | ||
| 1034 | 				ctx->n = tre_ast_new_literal(ctx->mem, EMPTY, -1, -1); | ||
| 1035 | 			else | ||
| 1036 | 				ctx->n = tre_ast_new_iter(ctx->mem, ctx->n, min, max, 0); | ||
| 1037 | 			if (!ctx->n) | ||
| 1038 | 				return REG_ESPACE; | ||
| 1039 | 		} | ||
| 1040 | |||
| 1041 | 		nbranch = tre_ast_new_catenation(ctx->mem, nbranch, ctx->n); | ||
| 1042 | 		if ((ere && *s == '|') || | ||
| 1043 | 		 (ere && *s == ')' && depth) || | ||
| 1044 | 		 (!ere && *s == '\\' && s[1] == ')') || | ||
| 1045 | 		 /* extension: treat \| as alternation in BRE */ | ||
| 1046 | 		 (!ere && *s == '\\' && s[1] == '|') || | ||
| 1047 | 		 !*s) { | ||
| 1048 | 			/* extension: empty branch is unspecified (), (|a), (a|) | ||
| 1049 | 			 here they are not rejected but match on empty string */ | ||
| 1050 | 			int c = *s; | ||
| 1051 | 			nunion = tre_ast_new_union(ctx->mem, nunion, nbranch); | ||
| 1052 | 			nbranch = 0; | ||
| 1053 | |||
| 1054 | 			if (c == '\\' && s[1] == '|') { | ||
| 1055 | 				s+=2; | ||
| 1056 | 				ctx->start = s; | ||
| 1057 | 			} else if (c == '|') { | ||
| 1058 | 				s++; | ||
| 1059 | 				ctx->start = s; | ||
| 1060 | 			} else { | ||
| 1061 | 				if (c == '\\') { | ||
| 1062 | 					if (!depth) return REG_EPAREN; | ||
| 1063 | 					s+=2; | ||
| 1064 | 				} else if (c == ')') | ||
| 1065 | 					s++; | ||
| 1066 | 				depth--; | ||
| 1067 | 				err = marksub(ctx, nunion, tre_stack_pop_int(stack)); | ||
| 1068 | 				if (err != REG_OK) | ||
| 1069 | 					return err; | ||
| 1070 | 				if (!c && depth<0) { | ||
| 1071 | 					ctx->submatch_id = subid; | ||
| 1072 | 					return REG_OK; | ||
| 1073 | 				} | ||
| 1074 | 				if (!c || depth<0) | ||
| 1075 | 					return REG_EPAREN; | ||
| 1076 | 				nbranch = tre_stack_pop_voidptr(stack); | ||
| 1077 | 				nunion = tre_stack_pop_voidptr(stack); | ||
| 1078 | 				goto parse_iter; | ||
| 1079 | 			} | ||
| 1080 | 		} | ||
| 1081 | 	} | ||
| 1082 | } | ||
| 1083 | |||
| 1084 | |||
| 1085 | /*********************************************************************** | ||
| 1086 | from tre-compile.c | ||
| 1087 | ***********************************************************************/ | ||
| 1088 | |||
| 1089 | |||
| 1090 | /* | ||
| 1091 | TODO: | ||
| 1092 | - Fix tre_ast_to_tnfa() to recurse using a stack instead of recursive | ||
| 1093 | function calls. | ||
| 1094 | */ | ||
| 1095 | |||
| 1096 | /* | ||
| 1097 | Algorithms to setup tags so that submatch addressing can be done. | ||
| 1098 | */ | ||
| 1099 | |||
| 1100 | |||
| 1101 | /* Inserts a catenation node to the root of the tree given in `node'. | ||
| 1102 | As the left child a new tag with number `tag_id' to `node' is added, | ||
| 1103 | and the right child is the old root. */ | ||
| 1104 | static reg_errcode_t | ||
| 1105 | tre_add_tag_left(tre_mem_t mem, tre_ast_node_t *node, int tag_id) | ||
| 1106 | { | ||
| 1107 | tre_catenation_t *c; | ||
| 1108 | |||
| 1109 | c = tre_mem_alloc(mem, sizeof(*c)); | ||
| 1110 | if (c == NULL) | ||
| 1111 | return REG_ESPACE; | ||
| 1112 | c->left = tre_ast_new_literal(mem, TAG, tag_id, -1); | ||
| 1113 | if (c->left == NULL) | ||
| 1114 | return REG_ESPACE; | ||
| 1115 | c->right = tre_mem_alloc(mem, sizeof(tre_ast_node_t)); | ||
| 1116 | if (c->right == NULL) | ||
| 1117 | return REG_ESPACE; | ||
| 1118 | |||
| 1119 | c->right->obj = node->obj; | ||
| 1120 | c->right->type = node->type; | ||
| 1121 | c->right->nullable = -1; | ||
| 1122 | c->right->submatch_id = -1; | ||
| 1123 | c->right->firstpos = NULL; | ||
| 1124 | c->right->lastpos = NULL; | ||
| 1125 | c->right->num_tags = 0; | ||
| 1126 | c->right->num_submatches = 0; | ||
| 1127 | node->obj = c; | ||
| 1128 | node->type = CATENATION; | ||
| 1129 | return REG_OK; | ||
| 1130 | } | ||
| 1131 | |||
| 1132 | /* Inserts a catenation node to the root of the tree given in `node'. | ||
| 1133 | As the right child a new tag with number `tag_id' to `node' is added, | ||
| 1134 | and the left child is the old root. */ | ||
| 1135 | static reg_errcode_t | ||
| 1136 | tre_add_tag_right(tre_mem_t mem, tre_ast_node_t *node, int tag_id) | ||
| 1137 | { | ||
| 1138 | tre_catenation_t *c; | ||
| 1139 | |||
| 1140 | c = tre_mem_alloc(mem, sizeof(*c)); | ||
| 1141 | if (c == NULL) | ||
| 1142 | return REG_ESPACE; | ||
| 1143 | c->right = tre_ast_new_literal(mem, TAG, tag_id, -1); | ||
| 1144 | if (c->right == NULL) | ||
| 1145 | return REG_ESPACE; | ||
| 1146 | c->left = tre_mem_alloc(mem, sizeof(tre_ast_node_t)); | ||
| 1147 | if (c->left == NULL) | ||
| 1148 | return REG_ESPACE; | ||
| 1149 | |||
| 1150 | c->left->obj = node->obj; | ||
| 1151 | c->left->type = node->type; | ||
| 1152 | c->left->nullable = -1; | ||
| 1153 | c->left->submatch_id = -1; | ||
| 1154 | c->left->firstpos = NULL; | ||
| 1155 | c->left->lastpos = NULL; | ||
| 1156 | c->left->num_tags = 0; | ||
| 1157 | c->left->num_submatches = 0; | ||
| 1158 | node->obj = c; | ||
| 1159 | node->type = CATENATION; | ||
| 1160 | return REG_OK; | ||
| 1161 | } | ||
| 1162 | |||
| 1163 | typedef enum { | ||
| 1164 | ADDTAGS_RECURSE, | ||
| 1165 | ADDTAGS_AFTER_ITERATION, | ||
| 1166 | ADDTAGS_AFTER_UNION_LEFT, | ||
| 1167 | ADDTAGS_AFTER_UNION_RIGHT, | ||
| 1168 | ADDTAGS_AFTER_CAT_LEFT, | ||
| 1169 | ADDTAGS_AFTER_CAT_RIGHT, | ||
| 1170 | ADDTAGS_SET_SUBMATCH_END | ||
| 1171 | } tre_addtags_symbol_t; | ||
| 1172 | |||
| 1173 | |||
| 1174 | typedef struct { | ||
| 1175 | int tag; | ||
| 1176 | int next_tag; | ||
| 1177 | } tre_tag_states_t; | ||
| 1178 | |||
| 1179 | |||
| 1180 | /* Go through `regset' and set submatch data for submatches that are | ||
| 1181 | using this tag. */ | ||
| 1182 | static void | ||
| 1183 | tre_purge_regset(int *regset, tre_tnfa_t *tnfa, int tag) | ||
| 1184 | { | ||
| 1185 | int i; | ||
| 1186 | |||
| 1187 | for (i = 0; regset[i] >= 0; i++) | ||
| 1188 | { | ||
| 1189 | int id = regset[i] / 2; | ||
| 1190 | int start = !(regset[i] % 2); | ||
| 1191 | if (start) | ||
| 1192 | 	tnfa->submatch_data[id].so_tag = tag; | ||
| 1193 | else | ||
| 1194 | 	tnfa->submatch_data[id].eo_tag = tag; | ||
| 1195 | } | ||
| 1196 | regset[0] = -1; | ||
| 1197 | } | ||
| 1198 | |||
| 1199 | |||
| 1200 | /* Adds tags to appropriate locations in the parse tree in `tree', so that | ||
| 1201 | subexpressions marked for submatch addressing can be traced. */ | ||
| 1202 | static reg_errcode_t | ||
| 1203 | tre_add_tags(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree, | ||
| 1204 | 	 tre_tnfa_t *tnfa) | ||
| 1205 | { | ||
| 1206 | reg_errcode_t status = REG_OK; | ||
| 1207 | tre_addtags_symbol_t symbol; | ||
| 1208 | tre_ast_node_t *node = tree; /* Tree node we are currently looking at. */ | ||
| 1209 | int bottom = tre_stack_num_objects(stack); | ||
| 1210 | /* True for first pass (counting number of needed tags) */ | ||
| 1211 | int first_pass = (mem == NULL || tnfa == NULL); | ||
| 1212 | int *regset, *orig_regset; | ||
| 1213 | int num_tags = 0; /* Total number of tags. */ | ||
| 1214 | int num_minimals = 0;	 /* Number of special minimal tags. */ | ||
| 1215 | int tag = 0;	 /* The tag that is to be added next. */ | ||
| 1216 | int next_tag = 1; /* Next tag to use after this one. */ | ||
| 1217 | int *parents;	 /* Stack of submatches the current submatch is | ||
| 1218 | 		 contained in. */ | ||
| 1219 | int minimal_tag = -1; /* Tag that marks the beginning of a minimal match. */ | ||
| 1220 | tre_tag_states_t *saved_states; | ||
| 1221 | |||
| 1222 | tre_tag_direction_t direction = TRE_TAG_MINIMIZE; | ||
| 1223 | if (!first_pass) | ||
| 1224 | { | ||
| 1225 | tnfa->end_tag = 0; | ||
| 1226 | tnfa->minimal_tags[0] = -1; | ||
| 1227 | } | ||
| 1228 | |||
| 1229 | regset = xmalloc(sizeof(*regset) * ((tnfa->num_submatches + 1) * 2)); | ||
| 1230 | if (regset == NULL) | ||
| 1231 | return REG_ESPACE; | ||
| 1232 | regset[0] = -1; | ||
| 1233 | orig_regset = regset; | ||
| 1234 | |||
| 1235 | parents = xmalloc(sizeof(*parents) * (tnfa->num_submatches + 1)); | ||
| 1236 | if (parents == NULL) | ||
| 1237 | { | ||
| 1238 | xfree(regset); | ||
| 1239 | return REG_ESPACE; | ||
| 1240 | } | ||
| 1241 | parents[0] = -1; | ||
| 1242 | |||
| 1243 | saved_states = xmalloc(sizeof(*saved_states) * (tnfa->num_submatches + 1)); | ||
| 1244 | if (saved_states == NULL) | ||
| 1245 | { | ||
| 1246 | xfree(regset); | ||
| 1247 | xfree(parents); | ||
| 1248 | return REG_ESPACE; | ||
| 1249 | } | ||
| 1250 | else | ||
| 1251 | { | ||
| 1252 | unsigned int i; | ||
| 1253 | for (i = 0; i <= tnfa->num_submatches; i++) | ||
| 1254 | 	saved_states[i].tag = -1; | ||
| 1255 | } | ||
| 1256 | |||
| 1257 | STACK_PUSH(stack, voidptr, node); | ||
| 1258 | STACK_PUSH(stack, int, ADDTAGS_RECURSE); | ||
| 1259 | |||
| 1260 | while (tre_stack_num_objects(stack) > bottom) | ||
| 1261 | { | ||
| 1262 | if (status != REG_OK) | ||
| 1263 | 	break; | ||
| 1264 | |||
| 1265 | symbol = (tre_addtags_symbol_t)tre_stack_pop_int(stack); | ||
| 1266 | switch (symbol) | ||
| 1267 | 	{ | ||
| 1268 | |||
| 1269 | 	case ADDTAGS_SET_SUBMATCH_END: | ||
| 1270 | 	 { | ||
| 1271 | 	 int id = tre_stack_pop_int(stack); | ||
| 1272 | 	 int i; | ||
| 1273 | |||
| 1274 | 	 /* Add end of this submatch to regset. */ | ||
| 1275 | 	 for (i = 0; regset[i] >= 0; i++); | ||
| 1276 | 	 regset[i] = id * 2 + 1; | ||
| 1277 | 	 regset[i + 1] = -1; | ||
| 1278 | |||
| 1279 | 	 /* Pop this submatch from the parents stack. */ | ||
| 1280 | 	 for (i = 0; parents[i] >= 0; i++); | ||
| 1281 | 	 parents[i - 1] = -1; | ||
| 1282 | 	 break; | ||
| 1283 | 	 } | ||
| 1284 | |||
| 1285 | 	case ADDTAGS_RECURSE: | ||
| 1286 | 	 node = tre_stack_pop_voidptr(stack); | ||
| 1287 | |||
| 1288 | 	 if (node->submatch_id >= 0) | ||
| 1289 | 	 { | ||
| 1290 | 	 int id = node->submatch_id; | ||
| 1291 | 	 int i; | ||
| 1292 | |||
| 1293 | |||
| 1294 | 	 /* Add start of this submatch to regset. */ | ||
| 1295 | 	 for (i = 0; regset[i] >= 0; i++); | ||
| 1296 | 	 regset[i] = id * 2; | ||
| 1297 | 	 regset[i + 1] = -1; | ||
| 1298 | |||
| 1299 | 	 if (!first_pass) | ||
| 1300 | 		{ | ||
| 1301 | 		 for (i = 0; parents[i] >= 0; i++); | ||
| 1302 | 		 tnfa->submatch_data[id].parents = NULL; | ||
| 1303 | 		 if (i > 0) | ||
| 1304 | 		 { | ||
| 1305 | 		 int *p = xmalloc(sizeof(*p) * (i + 1)); | ||
| 1306 | 		 if (p == NULL) | ||
| 1307 | 			{ | ||
| 1308 | 			 status = REG_ESPACE; | ||
| 1309 | 			 break; | ||
| 1310 | 			} | ||
| 1311 | 		 assert(tnfa->submatch_data[id].parents == NULL); | ||
| 1312 | 		 tnfa->submatch_data[id].parents = p; | ||
| 1313 | 		 for (i = 0; parents[i] >= 0; i++) | ||
| 1314 | 			p[i] = parents[i]; | ||
| 1315 | 		 p[i] = -1; | ||
| 1316 | 		 } | ||
| 1317 | 		} | ||
| 1318 | |||
| 1319 | 	 /* Add end of this submatch to regset after processing this | ||
| 1320 | 		 node. */ | ||
| 1321 | 	 STACK_PUSHX(stack, int, node->submatch_id); | ||
| 1322 | 	 STACK_PUSHX(stack, int, ADDTAGS_SET_SUBMATCH_END); | ||
| 1323 | 	 } | ||
| 1324 | |||
| 1325 | 	 switch (node->type) | ||
| 1326 | 	 { | ||
| 1327 | 	 case LITERAL: | ||
| 1328 | 	 { | ||
| 1329 | 		tre_literal_t *lit = node->obj; | ||
| 1330 | |||
| 1331 | 		if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) | ||
| 1332 | 		 { | ||
| 1333 | 		 int i; | ||
| 1334 | 		 if (regset[0] >= 0) | ||
| 1335 | 		 { | ||
| 1336 | 			/* Regset is not empty, so add a tag before the | ||
| 1337 | 			 literal or backref. */ | ||
| 1338 | 			if (!first_pass) | ||
| 1339 | 			 { | ||
| 1340 | 			 status = tre_add_tag_left(mem, node, tag); | ||
| 1341 | 			 tnfa->tag_directions[tag] = direction; | ||
| 1342 | 			 if (minimal_tag >= 0) | ||
| 1343 | 			 { | ||
| 1344 | 				for (i = 0; tnfa->minimal_tags[i] >= 0; i++); | ||
| 1345 | 				tnfa->minimal_tags[i] = tag; | ||
| 1346 | 				tnfa->minimal_tags[i + 1] = minimal_tag; | ||
| 1347 | 				tnfa->minimal_tags[i + 2] = -1; | ||
| 1348 | 				minimal_tag = -1; | ||
| 1349 | 				num_minimals++; | ||
| 1350 | 			 } | ||
| 1351 | 			 tre_purge_regset(regset, tnfa, tag); | ||
| 1352 | 			 } | ||
| 1353 | 			else | ||
| 1354 | 			 { | ||
| 1355 | 			 node->num_tags = 1; | ||
| 1356 | 			 } | ||
| 1357 | |||
| 1358 | 			regset[0] = -1; | ||
| 1359 | 			tag = next_tag; | ||
| 1360 | 			num_tags++; | ||
| 1361 | 			next_tag++; | ||
| 1362 | 		 } | ||
| 1363 | 		 } | ||
| 1364 | 		else | ||
| 1365 | 		 { | ||
| 1366 | 		 assert(!IS_TAG(lit)); | ||
| 1367 | 		 } | ||
| 1368 | 		break; | ||
| 1369 | 	 } | ||
| 1370 | 	 case CATENATION: | ||
| 1371 | 	 { | ||
| 1372 | 		tre_catenation_t *cat = node->obj; | ||
| 1373 | 		tre_ast_node_t *left = cat->left; | ||
| 1374 | 		tre_ast_node_t *right = cat->right; | ||
| 1375 | 		int reserved_tag = -1; | ||
| 1376 | |||
| 1377 | |||
| 1378 | 		/* After processing right child. */ | ||
| 1379 | 		STACK_PUSHX(stack, voidptr, node); | ||
| 1380 | 		STACK_PUSHX(stack, int, ADDTAGS_AFTER_CAT_RIGHT); | ||
| 1381 | |||
| 1382 | 		/* Process right child. */ | ||
| 1383 | 		STACK_PUSHX(stack, voidptr, right); | ||
| 1384 | 		STACK_PUSHX(stack, int, ADDTAGS_RECURSE); | ||
| 1385 | |||
| 1386 | 		/* After processing left child. */ | ||
| 1387 | 		STACK_PUSHX(stack, int, next_tag + left->num_tags); | ||
| 1388 | 		if (left->num_tags > 0 && right->num_tags > 0) | ||
| 1389 | 		 { | ||
| 1390 | 		 /* Reserve the next tag to the right child. */ | ||
| 1391 | 		 reserved_tag = next_tag; | ||
| 1392 | 		 next_tag++; | ||
| 1393 | 		 } | ||
| 1394 | 		STACK_PUSHX(stack, int, reserved_tag); | ||
| 1395 | 		STACK_PUSHX(stack, int, ADDTAGS_AFTER_CAT_LEFT); | ||
| 1396 | |||
| 1397 | 		/* Process left child. */ | ||
| 1398 | 		STACK_PUSHX(stack, voidptr, left); | ||
| 1399 | 		STACK_PUSHX(stack, int, ADDTAGS_RECURSE); | ||
| 1400 | |||
| 1401 | 		} | ||
| 1402 | 	 break; | ||
| 1403 | 	 case ITERATION: | ||
| 1404 | 	 { | ||
| 1405 | 		tre_iteration_t *iter = node->obj; | ||
| 1406 | |||
| 1407 | 		if (first_pass) | ||
| 1408 | 		 { | ||
| 1409 | 		 STACK_PUSHX(stack, int, regset[0] >= 0 || iter->minimal); | ||
| 1410 | 		 } | ||
| 1411 | 		else | ||
| 1412 | 		 { | ||
| 1413 | 		 STACK_PUSHX(stack, int, tag); | ||
| 1414 | 		 STACK_PUSHX(stack, int, iter->minimal); | ||
| 1415 | 		 } | ||
| 1416 | 		STACK_PUSHX(stack, voidptr, node); | ||
| 1417 | 		STACK_PUSHX(stack, int, ADDTAGS_AFTER_ITERATION); | ||
| 1418 | |||
| 1419 | 		STACK_PUSHX(stack, voidptr, iter->arg); | ||
| 1420 | 		STACK_PUSHX(stack, int, ADDTAGS_RECURSE); | ||
| 1421 | |||
| 1422 | 		/* Regset is not empty, so add a tag here. */ | ||
| 1423 | 		if (regset[0] >= 0 || iter->minimal) | ||
| 1424 | 		 { | ||
| 1425 | 		 if (!first_pass) | ||
| 1426 | 		 { | ||
| 1427 | 			int i; | ||
| 1428 | 			status = tre_add_tag_left(mem, node, tag); | ||
| 1429 | 			if (iter->minimal) | ||
| 1430 | 			 tnfa->tag_directions[tag] = TRE_TAG_MAXIMIZE; | ||
| 1431 | 			else | ||
| 1432 | 			 tnfa->tag_directions[tag] = direction; | ||
| 1433 | 			if (minimal_tag >= 0) | ||
| 1434 | 			 { | ||
| 1435 | 			 for (i = 0; tnfa->minimal_tags[i] >= 0; i++); | ||
| 1436 | 			 tnfa->minimal_tags[i] = tag; | ||
| 1437 | 			 tnfa->minimal_tags[i + 1] = minimal_tag; | ||
| 1438 | 			 tnfa->minimal_tags[i + 2] = -1; | ||
| 1439 | 			 minimal_tag = -1; | ||
| 1440 | 			 num_minimals++; | ||
| 1441 | 			 } | ||
| 1442 | 			tre_purge_regset(regset, tnfa, tag); | ||
| 1443 | 		 } | ||
| 1444 | |||
| 1445 | 		 regset[0] = -1; | ||
| 1446 | 		 tag = next_tag; | ||
| 1447 | 		 num_tags++; | ||
| 1448 | 		 next_tag++; | ||
| 1449 | 		 } | ||
| 1450 | 		direction = TRE_TAG_MINIMIZE; | ||
| 1451 | 	 } | ||
| 1452 | 	 break; | ||
| 1453 | 	 case UNION: | ||
| 1454 | 	 { | ||
| 1455 | 		tre_union_t *uni = node->obj; | ||
| 1456 | 		tre_ast_node_t *left = uni->left; | ||
| 1457 | 		tre_ast_node_t *right = uni->right; | ||
| 1458 | 		int left_tag; | ||
| 1459 | 		int right_tag; | ||
| 1460 | |||
| 1461 | 		if (regset[0] >= 0) | ||
| 1462 | 		 { | ||
| 1463 | 		 left_tag = next_tag; | ||
| 1464 | 		 right_tag = next_tag + 1; | ||
| 1465 | 		 } | ||
| 1466 | 		else | ||
| 1467 | 		 { | ||
| 1468 | 		 left_tag = tag; | ||
| 1469 | 		 right_tag = next_tag; | ||
| 1470 | 		 } | ||
| 1471 | |||
| 1472 | 		/* After processing right child. */ | ||
| 1473 | 		STACK_PUSHX(stack, int, right_tag); | ||
| 1474 | 		STACK_PUSHX(stack, int, left_tag); | ||
| 1475 | 		STACK_PUSHX(stack, voidptr, regset); | ||
| 1476 | 		STACK_PUSHX(stack, int, regset[0] >= 0); | ||
| 1477 | 		STACK_PUSHX(stack, voidptr, node); | ||
| 1478 | 		STACK_PUSHX(stack, voidptr, right); | ||
| 1479 | 		STACK_PUSHX(stack, voidptr, left); | ||
| 1480 | 		STACK_PUSHX(stack, int, ADDTAGS_AFTER_UNION_RIGHT); | ||
| 1481 | |||
| 1482 | 		/* Process right child. */ | ||
| 1483 | 		STACK_PUSHX(stack, voidptr, right); | ||
| 1484 | 		STACK_PUSHX(stack, int, ADDTAGS_RECURSE); | ||
| 1485 | |||
| 1486 | 		/* After processing left child. */ | ||
| 1487 | 		STACK_PUSHX(stack, int, ADDTAGS_AFTER_UNION_LEFT); | ||
| 1488 | |||
| 1489 | 		/* Process left child. */ | ||
| 1490 | 		STACK_PUSHX(stack, voidptr, left); | ||
| 1491 | 		STACK_PUSHX(stack, int, ADDTAGS_RECURSE); | ||
| 1492 | |||
| 1493 | 		/* Regset is not empty, so add a tag here. */ | ||
| 1494 | 		if (regset[0] >= 0) | ||
| 1495 | 		 { | ||
| 1496 | 		 if (!first_pass) | ||
| 1497 | 		 { | ||
| 1498 | 			int i; | ||
| 1499 | 			status = tre_add_tag_left(mem, node, tag); | ||
| 1500 | 			tnfa->tag_directions[tag] = direction; | ||
| 1501 | 			if (minimal_tag >= 0) | ||
| 1502 | 			 { | ||
| 1503 | 			 for (i = 0; tnfa->minimal_tags[i] >= 0; i++); | ||
| 1504 | 			 tnfa->minimal_tags[i] = tag; | ||
| 1505 | 			 tnfa->minimal_tags[i + 1] = minimal_tag; | ||
| 1506 | 			 tnfa->minimal_tags[i + 2] = -1; | ||
| 1507 | 			 minimal_tag = -1; | ||
| 1508 | 			 num_minimals++; | ||
| 1509 | 			 } | ||
| 1510 | 			tre_purge_regset(regset, tnfa, tag); | ||
| 1511 | 		 } | ||
| 1512 | |||
| 1513 | 		 regset[0] = -1; | ||
| 1514 | 		 tag = next_tag; | ||
| 1515 | 		 num_tags++; | ||
| 1516 | 		 next_tag++; | ||
| 1517 | 		 } | ||
| 1518 | |||
| 1519 | 		if (node->num_submatches > 0) | ||
| 1520 | 		 { | ||
| 1521 | 		 /* The next two tags are reserved for markers. */ | ||
| 1522 | 		 next_tag++; | ||
| 1523 | 		 tag = next_tag; | ||
| 1524 | 		 next_tag++; | ||
| 1525 | 		 } | ||
| 1526 | |||
| 1527 | 		break; | ||
| 1528 | 	 } | ||
| 1529 | 	 } | ||
| 1530 | |||
| 1531 | 	 if (node->submatch_id >= 0) | ||
| 1532 | 	 { | ||
| 1533 | 	 int i; | ||
| 1534 | 	 /* Push this submatch on the parents stack. */ | ||
| 1535 | 	 for (i = 0; parents[i] >= 0; i++); | ||
| 1536 | 	 parents[i] = node->submatch_id; | ||
| 1537 | 	 parents[i + 1] = -1; | ||
| 1538 | 	 } | ||
| 1539 | |||
| 1540 | 	 break; /* end case: ADDTAGS_RECURSE */ | ||
| 1541 | |||
| 1542 | 	case ADDTAGS_AFTER_ITERATION: | ||
| 1543 | 	 { | ||
| 1544 | 	 int minimal = 0; | ||
| 1545 | 	 int enter_tag; | ||
| 1546 | 	 node = tre_stack_pop_voidptr(stack); | ||
| 1547 | 	 if (first_pass) | ||
| 1548 | 	 { | ||
| 1549 | 		node->num_tags = ((tre_iteration_t *)node->obj)->arg->num_tags | ||
| 1550 | 		 + tre_stack_pop_int(stack); | ||
| 1551 | 		minimal_tag = -1; | ||
| 1552 | 	 } | ||
| 1553 | 	 else | ||
| 1554 | 	 { | ||
| 1555 | 		minimal = tre_stack_pop_int(stack); | ||
| 1556 | 		enter_tag = tre_stack_pop_int(stack); | ||
| 1557 | 		if (minimal) | ||
| 1558 | 		 minimal_tag = enter_tag; | ||
| 1559 | 	 } | ||
| 1560 | |||
| 1561 | 	 if (!first_pass) | ||
| 1562 | 	 { | ||
| 1563 | 		if (minimal) | ||
| 1564 | 		 direction = TRE_TAG_MINIMIZE; | ||
| 1565 | 		else | ||
| 1566 | 		 direction = TRE_TAG_MAXIMIZE; | ||
| 1567 | 	 } | ||
| 1568 | 	 break; | ||
| 1569 | 	 } | ||
| 1570 | |||
| 1571 | 	case ADDTAGS_AFTER_CAT_LEFT: | ||
| 1572 | 	 { | ||
| 1573 | 	 int new_tag = tre_stack_pop_int(stack); | ||
| 1574 | 	 next_tag = tre_stack_pop_int(stack); | ||
| 1575 | 	 if (new_tag >= 0) | ||
| 1576 | 	 { | ||
| 1577 | 		tag = new_tag; | ||
| 1578 | 	 } | ||
| 1579 | 	 break; | ||
| 1580 | 	 } | ||
| 1581 | |||
| 1582 | 	case ADDTAGS_AFTER_CAT_RIGHT: | ||
| 1583 | 	 node = tre_stack_pop_voidptr(stack); | ||
| 1584 | 	 if (first_pass) | ||
| 1585 | 	 node->num_tags = ((tre_catenation_t *)node->obj)->left->num_tags | ||
| 1586 | 	 + ((tre_catenation_t *)node->obj)->right->num_tags; | ||
| 1587 | 	 break; | ||
| 1588 | |||
| 1589 | 	case ADDTAGS_AFTER_UNION_LEFT: | ||
| 1590 | 	 /* Lift the bottom of the `regset' array so that when processing | ||
| 1591 | 	 the right operand the items currently in the array are | ||
| 1592 | 	 invisible.	 The original bottom was saved at ADDTAGS_UNION and | ||
| 1593 | 	 will be restored at ADDTAGS_AFTER_UNION_RIGHT below. */ | ||
| 1594 | 	 while (*regset >= 0) | ||
| 1595 | 	 regset++; | ||
| 1596 | 	 break; | ||
| 1597 | |||
| 1598 | 	case ADDTAGS_AFTER_UNION_RIGHT: | ||
| 1599 | 	 { | ||
| 1600 | 	 int added_tags, tag_left, tag_right; | ||
| 1601 | 	 tre_ast_node_t *left = tre_stack_pop_voidptr(stack); | ||
| 1602 | 	 tre_ast_node_t *right = tre_stack_pop_voidptr(stack); | ||
| 1603 | 	 node = tre_stack_pop_voidptr(stack); | ||
| 1604 | 	 added_tags = tre_stack_pop_int(stack); | ||
| 1605 | 	 if (first_pass) | ||
| 1606 | 	 { | ||
| 1607 | 		node->num_tags = ((tre_union_t *)node->obj)->left->num_tags | ||
| 1608 | 		 + ((tre_union_t *)node->obj)->right->num_tags + added_tags | ||
| 1609 | 		 + ((node->num_submatches > 0) ? 2 : 0); | ||
| 1610 | 	 } | ||
| 1611 | 	 regset = tre_stack_pop_voidptr(stack); | ||
| 1612 | 	 tag_left = tre_stack_pop_int(stack); | ||
| 1613 | 	 tag_right = tre_stack_pop_int(stack); | ||
| 1614 | |||
| 1615 | 	 /* Add tags after both children, the left child gets a smaller | ||
| 1616 | 	 tag than the right child. This guarantees that we prefer | ||
| 1617 | 	 the left child over the right child. */ | ||
| 1618 | 	 /* XXX - This is not always necessary (if the children have | ||
| 1619 | 	 tags which must be seen for every match of that child). */ | ||
| 1620 | 	 /* XXX - Check if this is the only place where tre_add_tag_right | ||
| 1621 | 	 is used.	 If so, use tre_add_tag_left (putting the tag before | ||
| 1622 | 	 the child as opposed after the child) and throw away | ||
| 1623 | 	 tre_add_tag_right. */ | ||
| 1624 | 	 if (node->num_submatches > 0) | ||
| 1625 | 	 { | ||
| 1626 | 		if (!first_pass) | ||
| 1627 | 		 { | ||
| 1628 | 		 status = tre_add_tag_right(mem, left, tag_left); | ||
| 1629 | 		 tnfa->tag_directions[tag_left] = TRE_TAG_MAXIMIZE; | ||
| 1630 | 		 if (status == REG_OK) | ||
| 1631 | 		 status = tre_add_tag_right(mem, right, tag_right); | ||
| 1632 | 		 tnfa->tag_directions[tag_right] = TRE_TAG_MAXIMIZE; | ||
| 1633 | 		 } | ||
| 1634 | 		num_tags += 2; | ||
| 1635 | 	 } | ||
| 1636 | 	 direction = TRE_TAG_MAXIMIZE; | ||
| 1637 | 	 break; | ||
| 1638 | 	 } | ||
| 1639 | |||
| 1640 | 	default: | ||
| 1641 | 	 assert(0); | ||
| 1642 | 	 break; | ||
| 1643 | |||
| 1644 | 	} /* end switch(symbol) */ | ||
| 1645 | } /* end while(tre_stack_num_objects(stack) > bottom) */ | ||
| 1646 | |||
| 1647 | if (!first_pass) | ||
| 1648 | tre_purge_regset(regset, tnfa, tag); | ||
| 1649 | |||
| 1650 | if (!first_pass && minimal_tag >= 0) | ||
| 1651 | { | ||
| 1652 | int i; | ||
| 1653 | for (i = 0; tnfa->minimal_tags[i] >= 0; i++); | ||
| 1654 | tnfa->minimal_tags[i] = tag; | ||
| 1655 | tnfa->minimal_tags[i + 1] = minimal_tag; | ||
| 1656 | tnfa->minimal_tags[i + 2] = -1; | ||
| 1657 | minimal_tag = -1; | ||
| 1658 | num_minimals++; | ||
| 1659 | } | ||
| 1660 | |||
| 1661 | assert(tree->num_tags == num_tags); | ||
| 1662 | tnfa->end_tag = num_tags; | ||
| 1663 | tnfa->num_tags = num_tags; | ||
| 1664 | tnfa->num_minimals = num_minimals; | ||
| 1665 | xfree(orig_regset); | ||
| 1666 | xfree(parents); | ||
| 1667 | xfree(saved_states); | ||
| 1668 | return status; | ||
| 1669 | } | ||
| 1670 | |||
| 1671 | |||
| 1672 | |||
| 1673 | /* | ||
| 1674 | AST to TNFA compilation routines. | ||
| 1675 | */ | ||
| 1676 | |||
| 1677 | typedef enum { | ||
| 1678 | COPY_RECURSE, | ||
| 1679 | COPY_SET_RESULT_PTR | ||
| 1680 | } tre_copyast_symbol_t; | ||
| 1681 | |||
| 1682 | /* Flags for tre_copy_ast(). */ | ||
| 1683 | #define COPY_REMOVE_TAGS	 1 | ||
| 1684 | #define COPY_MAXIMIZE_FIRST_TAG	 2 | ||
| 1685 | |||
| 1686 | static reg_errcode_t | ||
| 1687 | tre_copy_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, | ||
| 1688 | 	 int flags, int *pos_add, tre_tag_direction_t *tag_directions, | ||
| 1689 | 	 tre_ast_node_t **copy, int *max_pos) | ||
| 1690 | { | ||
| 1691 | reg_errcode_t status = REG_OK; | ||
| 1692 | int bottom = tre_stack_num_objects(stack); | ||
| 1693 | int num_copied = 0; | ||
| 1694 | int first_tag = 1; | ||
| 1695 | tre_ast_node_t **result = copy; | ||
| 1696 | tre_copyast_symbol_t symbol; | ||
| 1697 | |||
| 1698 | STACK_PUSH(stack, voidptr, ast); | ||
| 1699 | STACK_PUSH(stack, int, COPY_RECURSE); | ||
| 1700 | |||
| 1701 | while (status == REG_OK && tre_stack_num_objects(stack) > bottom) | ||
| 1702 | { | ||
| 1703 | tre_ast_node_t *node; | ||
| 1704 | if (status != REG_OK) | ||
| 1705 | 	break; | ||
| 1706 | |||
| 1707 | symbol = (tre_copyast_symbol_t)tre_stack_pop_int(stack); | ||
| 1708 | switch (symbol) | ||
| 1709 | 	{ | ||
| 1710 | 	case COPY_SET_RESULT_PTR: | ||
| 1711 | 	 result = tre_stack_pop_voidptr(stack); | ||
| 1712 | 	 break; | ||
| 1713 | 	case COPY_RECURSE: | ||
| 1714 | 	 node = tre_stack_pop_voidptr(stack); | ||
| 1715 | 	 switch (node->type) | ||
| 1716 | 	 { | ||
| 1717 | 	 case LITERAL: | ||
| 1718 | 	 { | ||
| 1719 | 		tre_literal_t *lit = node->obj; | ||
| 1720 | 		int pos = lit->position; | ||
| 1721 | 		int min = lit->code_min; | ||
| 1722 | 		int max = lit->code_max; | ||
| 1723 | 		if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) | ||
| 1724 | 		 { | ||
| 1725 | 		 /* XXX - e.g. [ab] has only one position but two | ||
| 1726 | 		 nodes, so we are creating holes in the state space | ||
| 1727 | 		 here. Not fatal, just wastes memory. */ | ||
| 1728 | 		 pos += *pos_add; | ||
| 1729 | 		 num_copied++; | ||
| 1730 | 		 } | ||
| 1731 | 		else if (IS_TAG(lit) && (flags & COPY_REMOVE_TAGS)) | ||
| 1732 | 		 { | ||
| 1733 | 		 /* Change this tag to empty. */ | ||
| 1734 | 		 min = EMPTY; | ||
| 1735 | 		 max = pos = -1; | ||
| 1736 | 		 } | ||
| 1737 | 		else if (IS_TAG(lit) && (flags & COPY_MAXIMIZE_FIRST_TAG) | ||
| 1738 | 			 && first_tag) | ||
| 1739 | 		 { | ||
| 1740 | 		 /* Maximize the first tag. */ | ||
| 1741 | 		 tag_directions[max] = TRE_TAG_MAXIMIZE; | ||
| 1742 | 		 first_tag = 0; | ||
| 1743 | 		 } | ||
| 1744 | 		*result = tre_ast_new_literal(mem, min, max, pos); | ||
| 1745 | 		if (*result == NULL) | ||
| 1746 | 		 status = REG_ESPACE; | ||
| 1747 | 		else { | ||
| 1748 | 		 tre_literal_t *p = (*result)->obj; | ||
| 1749 | 		 p->class = lit->class; | ||
| 1750 | 		 p->neg_classes = lit->neg_classes; | ||
| 1751 | 		} | ||
| 1752 | |||
| 1753 | 		if (pos > *max_pos) | ||
| 1754 | 		 *max_pos = pos; | ||
| 1755 | 		break; | ||
| 1756 | 	 } | ||
| 1757 | 	 case UNION: | ||
| 1758 | 	 { | ||
| 1759 | 		tre_union_t *uni = node->obj; | ||
| 1760 | 		tre_union_t *tmp; | ||
| 1761 | 		*result = tre_ast_new_union(mem, uni->left, uni->right); | ||
| 1762 | 		if (*result == NULL) | ||
| 1763 | 		 { | ||
| 1764 | 		 status = REG_ESPACE; | ||
| 1765 | 		 break; | ||
| 1766 | 		 } | ||
| 1767 | 		tmp = (*result)->obj; | ||
| 1768 | 		result = &tmp->left; | ||
| 1769 | 		STACK_PUSHX(stack, voidptr, uni->right); | ||
| 1770 | 		STACK_PUSHX(stack, int, COPY_RECURSE); | ||
| 1771 | 		STACK_PUSHX(stack, voidptr, &tmp->right); | ||
| 1772 | 		STACK_PUSHX(stack, int, COPY_SET_RESULT_PTR); | ||
| 1773 | 		STACK_PUSHX(stack, voidptr, uni->left); | ||
| 1774 | 		STACK_PUSHX(stack, int, COPY_RECURSE); | ||
| 1775 | 		break; | ||
| 1776 | 	 } | ||
| 1777 | 	 case CATENATION: | ||
| 1778 | 	 { | ||
| 1779 | 		tre_catenation_t *cat = node->obj; | ||
| 1780 | 		tre_catenation_t *tmp; | ||
| 1781 | 		*result = tre_ast_new_catenation(mem, cat->left, cat->right); | ||
| 1782 | 		if (*result == NULL) | ||
| 1783 | 		 { | ||
| 1784 | 		 status = REG_ESPACE; | ||
| 1785 | 		 break; | ||
| 1786 | 		 } | ||
| 1787 | 		tmp = (*result)->obj; | ||
| 1788 | 		tmp->left = NULL; | ||
| 1789 | 		tmp->right = NULL; | ||
| 1790 | 		result = &tmp->left; | ||
| 1791 | |||
| 1792 | 		STACK_PUSHX(stack, voidptr, cat->right); | ||
| 1793 | 		STACK_PUSHX(stack, int, COPY_RECURSE); | ||
| 1794 | 		STACK_PUSHX(stack, voidptr, &tmp->right); | ||
| 1795 | 		STACK_PUSHX(stack, int, COPY_SET_RESULT_PTR); | ||
| 1796 | 		STACK_PUSHX(stack, voidptr, cat->left); | ||
| 1797 | 		STACK_PUSHX(stack, int, COPY_RECURSE); | ||
| 1798 | 		break; | ||
| 1799 | 	 } | ||
| 1800 | 	 case ITERATION: | ||
| 1801 | 	 { | ||
| 1802 | 		tre_iteration_t *iter = node->obj; | ||
| 1803 | 		STACK_PUSHX(stack, voidptr, iter->arg); | ||
| 1804 | 		STACK_PUSHX(stack, int, COPY_RECURSE); | ||
| 1805 | 		*result = tre_ast_new_iter(mem, iter->arg, iter->min, | ||
| 1806 | 					 iter->max, iter->minimal); | ||
| 1807 | 		if (*result == NULL) | ||
| 1808 | 		 { | ||
| 1809 | 		 status = REG_ESPACE; | ||
| 1810 | 		 break; | ||
| 1811 | 		 } | ||
| 1812 | 		iter = (*result)->obj; | ||
| 1813 | 		result = &iter->arg; | ||
| 1814 | 		break; | ||
| 1815 | 	 } | ||
| 1816 | 	 default: | ||
| 1817 | 	 assert(0); | ||
| 1818 | 	 break; | ||
| 1819 | 	 } | ||
| 1820 | 	 break; | ||
| 1821 | 	} | ||
| 1822 | } | ||
| 1823 | *pos_add += num_copied; | ||
| 1824 | return status; | ||
| 1825 | } | ||
| 1826 | |||
| 1827 | typedef enum { | ||
| 1828 | EXPAND_RECURSE, | ||
| 1829 | EXPAND_AFTER_ITER | ||
| 1830 | } tre_expand_ast_symbol_t; | ||
| 1831 | |||
| 1832 | /* Expands each iteration node that has a finite nonzero minimum or maximum | ||
| 1833 | iteration count to a catenated sequence of copies of the node. */ | ||
| 1834 | static reg_errcode_t | ||
| 1835 | tre_expand_ast(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *ast, | ||
| 1836 | 	 int *position, tre_tag_direction_t *tag_directions) | ||
| 1837 | { | ||
| 1838 | reg_errcode_t status = REG_OK; | ||
| 1839 | int bottom = tre_stack_num_objects(stack); | ||
| 1840 | int pos_add = 0; | ||
| 1841 | int pos_add_total = 0; | ||
| 1842 | int max_pos = 0; | ||
| 1843 | int iter_depth = 0; | ||
| 1844 | |||
| 1845 | STACK_PUSHR(stack, voidptr, ast); | ||
| 1846 | STACK_PUSHR(stack, int, EXPAND_RECURSE); | ||
| 1847 | while (status == REG_OK && tre_stack_num_objects(stack) > bottom) | ||
| 1848 | { | ||
| 1849 | tre_ast_node_t *node; | ||
| 1850 | tre_expand_ast_symbol_t symbol; | ||
| 1851 | |||
| 1852 | if (status != REG_OK) | ||
| 1853 | 	break; | ||
| 1854 | |||
| 1855 | symbol = (tre_expand_ast_symbol_t)tre_stack_pop_int(stack); | ||
| 1856 | node = tre_stack_pop_voidptr(stack); | ||
| 1857 | switch (symbol) | ||
| 1858 | 	{ | ||
| 1859 | 	case EXPAND_RECURSE: | ||
| 1860 | 	 switch (node->type) | ||
| 1861 | 	 { | ||
| 1862 | 	 case LITERAL: | ||
| 1863 | 	 { | ||
| 1864 | 		tre_literal_t *lit= node->obj; | ||
| 1865 | 		if (!IS_SPECIAL(lit) || IS_BACKREF(lit)) | ||
| 1866 | 		 { | ||
| 1867 | 		 lit->position += pos_add; | ||
| 1868 | 		 if (lit->position > max_pos) | ||
| 1869 | 		 max_pos = lit->position; | ||
| 1870 | 		 } | ||
| 1871 | 		break; | ||
| 1872 | 	 } | ||
| 1873 | 	 case UNION: | ||
| 1874 | 	 { | ||
| 1875 | 		tre_union_t *uni = node->obj; | ||
| 1876 | 		STACK_PUSHX(stack, voidptr, uni->right); | ||
| 1877 | 		STACK_PUSHX(stack, int, EXPAND_RECURSE); | ||
| 1878 | 		STACK_PUSHX(stack, voidptr, uni->left); | ||
| 1879 | 		STACK_PUSHX(stack, int, EXPAND_RECURSE); | ||
| 1880 | 		break; | ||
| 1881 | 	 } | ||
| 1882 | 	 case CATENATION: | ||
| 1883 | 	 { | ||
| 1884 | 		tre_catenation_t *cat = node->obj; | ||
| 1885 | 		STACK_PUSHX(stack, voidptr, cat->right); | ||
| 1886 | 		STACK_PUSHX(stack, int, EXPAND_RECURSE); | ||
| 1887 | 		STACK_PUSHX(stack, voidptr, cat->left); | ||
| 1888 | 		STACK_PUSHX(stack, int, EXPAND_RECURSE); | ||
| 1889 | 		break; | ||
| 1890 | 	 } | ||
| 1891 | 	 case ITERATION: | ||
| 1892 | 	 { | ||
| 1893 | 		tre_iteration_t *iter = node->obj; | ||
| 1894 | 		STACK_PUSHX(stack, int, pos_add); | ||
| 1895 | 		STACK_PUSHX(stack, voidptr, node); | ||
| 1896 | 		STACK_PUSHX(stack, int, EXPAND_AFTER_ITER); | ||
| 1897 | 		STACK_PUSHX(stack, voidptr, iter->arg); | ||
| 1898 | 		STACK_PUSHX(stack, int, EXPAND_RECURSE); | ||
| 1899 | 		/* If we are going to expand this node at EXPAND_AFTER_ITER | ||
| 1900 | 		 then don't increase the `pos' fields of the nodes now, it | ||
| 1901 | 		 will get done when expanding. */ | ||
| 1902 | 		if (iter->min > 1 || iter->max > 1) | ||
| 1903 | 		 pos_add = 0; | ||
| 1904 | 		iter_depth++; | ||
| 1905 | 		break; | ||
| 1906 | 	 } | ||
| 1907 | 	 default: | ||
| 1908 | 	 assert(0); | ||
| 1909 | 	 break; | ||
| 1910 | 	 } | ||
| 1911 | 	 break; | ||
| 1912 | 	case EXPAND_AFTER_ITER: | ||
| 1913 | 	 { | ||
| 1914 | 	 tre_iteration_t *iter = node->obj; | ||
| 1915 | 	 int pos_add_last; | ||
| 1916 | 	 pos_add = tre_stack_pop_int(stack); | ||
| 1917 | 	 pos_add_last = pos_add; | ||
| 1918 | 	 if (iter->min > 1 || iter->max > 1) | ||
| 1919 | 	 { | ||
| 1920 | 		tre_ast_node_t *seq1 = NULL, *seq2 = NULL; | ||
| 1921 | 		int j; | ||
| 1922 | 		int pos_add_save = pos_add; | ||
| 1923 | |||
| 1924 | 		/* Create a catenated sequence of copies of the node. */ | ||
| 1925 | 		for (j = 0; j < iter->min; j++) | ||
| 1926 | 		 { | ||
| 1927 | 		 tre_ast_node_t *copy; | ||
| 1928 | 		 /* Remove tags from all but the last copy. */ | ||
| 1929 | 		 int flags = ((j + 1 < iter->min) | ||
| 1930 | 				 ? COPY_REMOVE_TAGS | ||
| 1931 | 				 : COPY_MAXIMIZE_FIRST_TAG); | ||
| 1932 | 		 pos_add_save = pos_add; | ||
| 1933 | 		 status = tre_copy_ast(mem, stack, iter->arg, flags, | ||
| 1934 | 					 &pos_add, tag_directions, &copy, | ||
| 1935 | 					 &max_pos); | ||
| 1936 | 		 if (status != REG_OK) | ||
| 1937 | 		 return status; | ||
| 1938 | 		 if (seq1 != NULL) | ||
| 1939 | 		 seq1 = tre_ast_new_catenation(mem, seq1, copy); | ||
| 1940 | 		 else | ||
| 1941 | 		 seq1 = copy; | ||
| 1942 | 		 if (seq1 == NULL) | ||
| 1943 | 		 return REG_ESPACE; | ||
| 1944 | 		 } | ||
| 1945 | |||
| 1946 | 		if (iter->max == -1) | ||
| 1947 | 		 { | ||
| 1948 | 		 /* No upper limit. */ | ||
| 1949 | 		 pos_add_save = pos_add; | ||
| 1950 | 		 status = tre_copy_ast(mem, stack, iter->arg, 0, | ||
| 1951 | 					 &pos_add, NULL, &seq2, &max_pos); | ||
| 1952 | 		 if (status != REG_OK) | ||
| 1953 | 		 return status; | ||
| 1954 | 		 seq2 = tre_ast_new_iter(mem, seq2, 0, -1, 0); | ||
| 1955 | 		 if (seq2 == NULL) | ||
| 1956 | 		 return REG_ESPACE; | ||
| 1957 | 		 } | ||
| 1958 | 		else | ||
| 1959 | 		 { | ||
| 1960 | 		 for (j = iter->min; j < iter->max; j++) | ||
| 1961 | 		 { | ||
| 1962 | 			tre_ast_node_t *tmp, *copy; | ||
| 1963 | 			pos_add_save = pos_add; | ||
| 1964 | 			status = tre_copy_ast(mem, stack, iter->arg, 0, | ||
| 1965 | 					 &pos_add, NULL, &copy, &max_pos); | ||
| 1966 | 			if (status != REG_OK) | ||
| 1967 | 			 return status; | ||
| 1968 | 			if (seq2 != NULL) | ||
| 1969 | 			 seq2 = tre_ast_new_catenation(mem, copy, seq2); | ||
| 1970 | 			else | ||
| 1971 | 			 seq2 = copy; | ||
| 1972 | 			if (seq2 == NULL) | ||
| 1973 | 			 return REG_ESPACE; | ||
| 1974 | 			tmp = tre_ast_new_literal(mem, EMPTY, -1, -1); | ||
| 1975 | 			if (tmp == NULL) | ||
| 1976 | 			 return REG_ESPACE; | ||
| 1977 | 			seq2 = tre_ast_new_union(mem, tmp, seq2); | ||
| 1978 | 			if (seq2 == NULL) | ||
| 1979 | 			 return REG_ESPACE; | ||
| 1980 | 		 } | ||
| 1981 | 		 } | ||
| 1982 | |||
| 1983 | 		pos_add = pos_add_save; | ||
| 1984 | 		if (seq1 == NULL) | ||
| 1985 | 		 seq1 = seq2; | ||
| 1986 | 		else if (seq2 != NULL) | ||
| 1987 | 		 seq1 = tre_ast_new_catenation(mem, seq1, seq2); | ||
| 1988 | 		if (seq1 == NULL) | ||
| 1989 | 		 return REG_ESPACE; | ||
| 1990 | 		node->obj = seq1->obj; | ||
| 1991 | 		node->type = seq1->type; | ||
| 1992 | 	 } | ||
| 1993 | |||
| 1994 | 	 iter_depth--; | ||
| 1995 | 	 pos_add_total += pos_add - pos_add_last; | ||
| 1996 | 	 if (iter_depth == 0) | ||
| 1997 | 	 pos_add = pos_add_total; | ||
| 1998 | |||
| 1999 | 	 break; | ||
| 2000 | 	 } | ||
| 2001 | 	default: | ||
| 2002 | 	 assert(0); | ||
| 2003 | 	 break; | ||
| 2004 | 	} | ||
| 2005 | } | ||
| 2006 | |||
| 2007 | *position += pos_add_total; | ||
| 2008 | |||
| 2009 | /* `max_pos' should never be larger than `*position' if the above | ||
| 2010 | code works, but just an extra safeguard let's make sure | ||
| 2011 | `*position' is set large enough so enough memory will be | ||
| 2012 | allocated for the transition table. */ | ||
| 2013 | if (max_pos > *position) | ||
| 2014 | *position = max_pos; | ||
| 2015 | |||
| 2016 | return status; | ||
| 2017 | } | ||
| 2018 | |||
| 2019 | static tre_pos_and_tags_t * | ||
| 2020 | tre_set_empty(tre_mem_t mem) | ||
| 2021 | { | ||
| 2022 | tre_pos_and_tags_t *new_set; | ||
| 2023 | |||
| 2024 | new_set = tre_mem_calloc(mem, sizeof(*new_set)); | ||
| 2025 | if (new_set == NULL) | ||
| 2026 | return NULL; | ||
| 2027 | |||
| 2028 | new_set[0].position = -1; | ||
| 2029 | new_set[0].code_min = -1; | ||
| 2030 | new_set[0].code_max = -1; | ||
| 2031 | |||
| 2032 | return new_set; | ||
| 2033 | } | ||
| 2034 | |||
| 2035 | static tre_pos_and_tags_t * | ||
| 2036 | tre_set_one(tre_mem_t mem, int position, int code_min, int code_max, | ||
| 2037 | 	 tre_ctype_t class, tre_ctype_t *neg_classes, int backref) | ||
| 2038 | { | ||
| 2039 | tre_pos_and_tags_t *new_set; | ||
| 2040 | |||
| 2041 | new_set = tre_mem_calloc(mem, sizeof(*new_set) * 2); | ||
| 2042 | if (new_set == NULL) | ||
| 2043 | return NULL; | ||
| 2044 | |||
| 2045 | new_set[0].position = position; | ||
| 2046 | new_set[0].code_min = code_min; | ||
| 2047 | new_set[0].code_max = code_max; | ||
| 2048 | new_set[0].class = class; | ||
| 2049 | new_set[0].neg_classes = neg_classes; | ||
| 2050 | new_set[0].backref = backref; | ||
| 2051 | new_set[1].position = -1; | ||
| 2052 | new_set[1].code_min = -1; | ||
| 2053 | new_set[1].code_max = -1; | ||
| 2054 | |||
| 2055 | return new_set; | ||
| 2056 | } | ||
| 2057 | |||
| 2058 | static tre_pos_and_tags_t * | ||
| 2059 | tre_set_union(tre_mem_t mem, tre_pos_and_tags_t *set1, tre_pos_and_tags_t *set2, | ||
| 2060 | 	 int *tags, int assertions) | ||
| 2061 | { | ||
| 2062 | int s1, s2, i, j; | ||
| 2063 | tre_pos_and_tags_t *new_set; | ||
| 2064 | int *new_tags; | ||
| 2065 | int num_tags; | ||
| 2066 | |||
| 2067 | for (num_tags = 0; tags != NULL && tags[num_tags] >= 0; num_tags++); | ||
| 2068 | for (s1 = 0; set1[s1].position >= 0; s1++); | ||
| 2069 | for (s2 = 0; set2[s2].position >= 0; s2++); | ||
| 2070 | new_set = tre_mem_calloc(mem, sizeof(*new_set) * (s1 + s2 + 1)); | ||
| 2071 | if (!new_set ) | ||
| 2072 | return NULL; | ||
| 2073 | |||
| 2074 | for (s1 = 0; set1[s1].position >= 0; s1++) | ||
| 2075 | { | ||
| 2076 | new_set[s1].position = set1[s1].position; | ||
| 2077 | new_set[s1].code_min = set1[s1].code_min; | ||
| 2078 | new_set[s1].code_max = set1[s1].code_max; | ||
| 2079 | new_set[s1].assertions = set1[s1].assertions | assertions; | ||
| 2080 | new_set[s1].class = set1[s1].class; | ||
| 2081 | new_set[s1].neg_classes = set1[s1].neg_classes; | ||
| 2082 | new_set[s1].backref = set1[s1].backref; | ||
| 2083 | if (set1[s1].tags == NULL && tags == NULL) | ||
| 2084 | 	new_set[s1].tags = NULL; | ||
| 2085 | else | ||
| 2086 | 	{ | ||
| 2087 | 	 for (i = 0; set1[s1].tags != NULL && set1[s1].tags[i] >= 0; i++); | ||
| 2088 | 	 new_tags = tre_mem_alloc(mem, (sizeof(*new_tags) | ||
| 2089 | 					 * (i + num_tags + 1))); | ||
| 2090 | 	 if (new_tags == NULL) | ||
| 2091 | 	 return NULL; | ||
| 2092 | 	 for (j = 0; j < i; j++) | ||
| 2093 | 	 new_tags[j] = set1[s1].tags[j]; | ||
| 2094 | 	 for (i = 0; i < num_tags; i++) | ||
| 2095 | 	 new_tags[j + i] = tags[i]; | ||
| 2096 | 	 new_tags[j + i] = -1; | ||
| 2097 | 	 new_set[s1].tags = new_tags; | ||
| 2098 | 	} | ||
| 2099 | } | ||
| 2100 | |||
| 2101 | for (s2 = 0; set2[s2].position >= 0; s2++) | ||
| 2102 | { | ||
| 2103 | new_set[s1 + s2].position = set2[s2].position; | ||
| 2104 | new_set[s1 + s2].code_min = set2[s2].code_min; | ||
| 2105 | new_set[s1 + s2].code_max = set2[s2].code_max; | ||
| 2106 | /* XXX - why not | assertions here as well? */ | ||
| 2107 | new_set[s1 + s2].assertions = set2[s2].assertions; | ||
| 2108 | new_set[s1 + s2].class = set2[s2].class; | ||
| 2109 | new_set[s1 + s2].neg_classes = set2[s2].neg_classes; | ||
| 2110 | new_set[s1 + s2].backref = set2[s2].backref; | ||
| 2111 | if (set2[s2].tags == NULL) | ||
| 2112 | 	new_set[s1 + s2].tags = NULL; | ||
| 2113 | else | ||
| 2114 | 	{ | ||
| 2115 | 	 for (i = 0; set2[s2].tags[i] >= 0; i++); | ||
| 2116 | 	 new_tags = tre_mem_alloc(mem, sizeof(*new_tags) * (i + 1)); | ||
| 2117 | 	 if (new_tags == NULL) | ||
| 2118 | 	 return NULL; | ||
| 2119 | 	 for (j = 0; j < i; j++) | ||
| 2120 | 	 new_tags[j] = set2[s2].tags[j]; | ||
| 2121 | 	 new_tags[j] = -1; | ||
| 2122 | 	 new_set[s1 + s2].tags = new_tags; | ||
| 2123 | 	} | ||
| 2124 | } | ||
| 2125 | new_set[s1 + s2].position = -1; | ||
| 2126 | return new_set; | ||
| 2127 | } | ||
| 2128 | |||
| 2129 | /* Finds the empty path through `node' which is the one that should be | ||
| 2130 | taken according to POSIX.2 rules, and adds the tags on that path to | ||
| 2131 | `tags'. `tags' may be NULL. If `num_tags_seen' is not NULL, it is | ||
| 2132 | set to the number of tags seen on the path. */ | ||
| 2133 | static reg_errcode_t | ||
| 2134 | tre_match_empty(tre_stack_t *stack, tre_ast_node_t *node, int *tags, | ||
| 2135 | 		int *assertions, int *num_tags_seen) | ||
| 2136 | { | ||
| 2137 | tre_literal_t *lit; | ||
| 2138 | tre_union_t *uni; | ||
| 2139 | tre_catenation_t *cat; | ||
| 2140 | tre_iteration_t *iter; | ||
| 2141 | int i; | ||
| 2142 | int bottom = tre_stack_num_objects(stack); | ||
| 2143 | reg_errcode_t status = REG_OK; | ||
| 2144 | if (num_tags_seen) | ||
| 2145 | *num_tags_seen = 0; | ||
| 2146 | |||
| 2147 | status = tre_stack_push_voidptr(stack, node); | ||
| 2148 | |||
| 2149 | /* Walk through the tree recursively. */ | ||
| 2150 | while (status == REG_OK && tre_stack_num_objects(stack) > bottom) | ||
| 2151 | { | ||
| 2152 | node = tre_stack_pop_voidptr(stack); | ||
| 2153 | |||
| 2154 | switch (node->type) | ||
| 2155 | 	{ | ||
| 2156 | 	case LITERAL: | ||
| 2157 | 	 lit = (tre_literal_t *)node->obj; | ||
| 2158 | 	 switch (lit->code_min) | ||
| 2159 | 	 { | ||
| 2160 | 	 case TAG: | ||
| 2161 | 	 if (lit->code_max >= 0) | ||
| 2162 | 		{ | ||
| 2163 | 		 if (tags != NULL) | ||
| 2164 | 		 { | ||
| 2165 | 		 /* Add the tag to `tags'. */ | ||
| 2166 | 		 for (i = 0; tags[i] >= 0; i++) | ||
| 2167 | 			if (tags[i] == lit->code_max) | ||
| 2168 | 			 break; | ||
| 2169 | 		 if (tags[i] < 0) | ||
| 2170 | 			{ | ||
| 2171 | 			 tags[i] = lit->code_max; | ||
| 2172 | 			 tags[i + 1] = -1; | ||
| 2173 | 			} | ||
| 2174 | 		 } | ||
| 2175 | 		 if (num_tags_seen) | ||
| 2176 | 		 (*num_tags_seen)++; | ||
| 2177 | 		} | ||
| 2178 | 	 break; | ||
| 2179 | 	 case ASSERTION: | ||
| 2180 | 	 assert(lit->code_max >= 1 | ||
| 2181 | 		 || lit->code_max <= ASSERT_LAST); | ||
| 2182 | 	 if (assertions != NULL) | ||
| 2183 | 		*assertions |= lit->code_max; | ||
| 2184 | 	 break; | ||
| 2185 | 	 case EMPTY: | ||
| 2186 | 	 break; | ||
| 2187 | 	 default: | ||
| 2188 | 	 assert(0); | ||
| 2189 | 	 break; | ||
| 2190 | 	 } | ||
| 2191 | 	 break; | ||
| 2192 | |||
| 2193 | 	case UNION: | ||
| 2194 | 	 /* Subexpressions starting earlier take priority over ones | ||
| 2195 | 	 starting later, so we prefer the left subexpression over the | ||
| 2196 | 	 right subexpression. */ | ||
| 2197 | 	 uni = (tre_union_t *)node->obj; | ||
| 2198 | 	 if (uni->left->nullable) | ||
| 2199 | 	 STACK_PUSHX(stack, voidptr, uni->left) | ||
| 2200 | 	 else if (uni->right->nullable) | ||
| 2201 | 	 STACK_PUSHX(stack, voidptr, uni->right) | ||
| 2202 | 	 else | ||
| 2203 | 	 assert(0); | ||
| 2204 | 	 break; | ||
| 2205 | |||
| 2206 | 	case CATENATION: | ||
| 2207 | 	 /* The path must go through both children. */ | ||
| 2208 | 	 cat = (tre_catenation_t *)node->obj; | ||
| 2209 | 	 assert(cat->left->nullable); | ||
| 2210 | 	 assert(cat->right->nullable); | ||
| 2211 | 	 STACK_PUSHX(stack, voidptr, cat->left); | ||
| 2212 | 	 STACK_PUSHX(stack, voidptr, cat->right); | ||
| 2213 | 	 break; | ||
| 2214 | |||
| 2215 | 	case ITERATION: | ||
| 2216 | 	 /* A match with an empty string is preferred over no match at | ||
| 2217 | 	 all, so we go through the argument if possible. */ | ||
| 2218 | 	 iter = (tre_iteration_t *)node->obj; | ||
| 2219 | 	 if (iter->arg->nullable) | ||
| 2220 | 	 STACK_PUSHX(stack, voidptr, iter->arg); | ||
| 2221 | 	 break; | ||
| 2222 | |||
| 2223 | 	default: | ||
| 2224 | 	 assert(0); | ||
| 2225 | 	 break; | ||
| 2226 | 	} | ||
| 2227 | } | ||
| 2228 | |||
| 2229 | return status; | ||
| 2230 | } | ||
| 2231 | |||
| 2232 | |||
| 2233 | typedef enum { | ||
| 2234 | NFL_RECURSE, | ||
| 2235 | NFL_POST_UNION, | ||
| 2236 | NFL_POST_CATENATION, | ||
| 2237 | NFL_POST_ITERATION | ||
| 2238 | } tre_nfl_stack_symbol_t; | ||
| 2239 | |||
| 2240 | |||
| 2241 | /* Computes and fills in the fields `nullable', `firstpos', and `lastpos' for | ||
| 2242 | the nodes of the AST `tree'. */ | ||
| 2243 | static reg_errcode_t | ||
| 2244 | tre_compute_nfl(tre_mem_t mem, tre_stack_t *stack, tre_ast_node_t *tree) | ||
| 2245 | { | ||
| 2246 | int bottom = tre_stack_num_objects(stack); | ||
| 2247 | |||
| 2248 | STACK_PUSHR(stack, voidptr, tree); | ||
| 2249 | STACK_PUSHR(stack, int, NFL_RECURSE); | ||
| 2250 | |||
| 2251 | while (tre_stack_num_objects(stack) > bottom) | ||
| 2252 | { | ||
| 2253 | tre_nfl_stack_symbol_t symbol; | ||
| 2254 | tre_ast_node_t *node; | ||
| 2255 | |||
| 2256 | symbol = (tre_nfl_stack_symbol_t)tre_stack_pop_int(stack); | ||
| 2257 | node = tre_stack_pop_voidptr(stack); | ||
| 2258 | switch (symbol) | ||
| 2259 | 	{ | ||
| 2260 | 	case NFL_RECURSE: | ||
| 2261 | 	 switch (node->type) | ||
| 2262 | 	 { | ||
| 2263 | 	 case LITERAL: | ||
| 2264 | 	 { | ||
| 2265 | 		tre_literal_t *lit = (tre_literal_t *)node->obj; | ||
| 2266 | 		if (IS_BACKREF(lit)) | ||
| 2267 | 		 { | ||
| 2268 | 		 /* Back references: nullable = false, firstpos = {i}, | ||
| 2269 | 		 lastpos = {i}. */ | ||
| 2270 | 		 node->nullable = 0; | ||
| 2271 | 		 node->firstpos = tre_set_one(mem, lit->position, 0, | ||
| 2272 | 					 TRE_CHAR_MAX, 0, NULL, -1); | ||
| 2273 | 		 if (!node->firstpos) | ||
| 2274 | 		 return REG_ESPACE; | ||
| 2275 | 		 node->lastpos = tre_set_one(mem, lit->position, 0, | ||
| 2276 | 						TRE_CHAR_MAX, 0, NULL, | ||
| 2277 | 						(int)lit->code_max); | ||
| 2278 | 		 if (!node->lastpos) | ||
| 2279 | 		 return REG_ESPACE; | ||
| 2280 | 		 } | ||
| 2281 | 		else if (lit->code_min < 0) | ||
| 2282 | 		 { | ||
| 2283 | 		 /* Tags, empty strings, params, and zero width assertions: | ||
| 2284 | 		 nullable = true, firstpos = {}, and lastpos = {}. */ | ||
| 2285 | 		 node->nullable = 1; | ||
| 2286 | 		 node->firstpos = tre_set_empty(mem); | ||
| 2287 | 		 if (!node->firstpos) | ||
| 2288 | 		 return REG_ESPACE; | ||
| 2289 | 		 node->lastpos = tre_set_empty(mem); | ||
| 2290 | 		 if (!node->lastpos) | ||
| 2291 | 		 return REG_ESPACE; | ||
| 2292 | 		 } | ||
| 2293 | 		else | ||
| 2294 | 		 { | ||
| 2295 | 		 /* Literal at position i: nullable = false, firstpos = {i}, | ||
| 2296 | 		 lastpos = {i}. */ | ||
| 2297 | 		 node->nullable = 0; | ||
| 2298 | 		 node->firstpos = | ||
| 2299 | 		 tre_set_one(mem, lit->position, (int)lit->code_min, | ||
| 2300 | 				 (int)lit->code_max, 0, NULL, -1); | ||
| 2301 | 		 if (!node->firstpos) | ||
| 2302 | 		 return REG_ESPACE; | ||
| 2303 | 		 node->lastpos = tre_set_one(mem, lit->position, | ||
| 2304 | 						(int)lit->code_min, | ||
| 2305 | 						(int)lit->code_max, | ||
| 2306 | 						lit->class, lit->neg_classes, | ||
| 2307 | 						-1); | ||
| 2308 | 		 if (!node->lastpos) | ||
| 2309 | 		 return REG_ESPACE; | ||
| 2310 | 		 } | ||
| 2311 | 		break; | ||
| 2312 | 	 } | ||
| 2313 | |||
| 2314 | 	 case UNION: | ||
| 2315 | 	 /* Compute the attributes for the two subtrees, and after that | ||
| 2316 | 		 for this node. */ | ||
| 2317 | 	 STACK_PUSHR(stack, voidptr, node); | ||
| 2318 | 	 STACK_PUSHR(stack, int, NFL_POST_UNION); | ||
| 2319 | 	 STACK_PUSHR(stack, voidptr, ((tre_union_t *)node->obj)->right); | ||
| 2320 | 	 STACK_PUSHR(stack, int, NFL_RECURSE); | ||
| 2321 | 	 STACK_PUSHR(stack, voidptr, ((tre_union_t *)node->obj)->left); | ||
| 2322 | 	 STACK_PUSHR(stack, int, NFL_RECURSE); | ||
| 2323 | 	 break; | ||
| 2324 | |||
| 2325 | 	 case CATENATION: | ||
| 2326 | 	 /* Compute the attributes for the two subtrees, and after that | ||
| 2327 | 		 for this node. */ | ||
| 2328 | 	 STACK_PUSHR(stack, voidptr, node); | ||
| 2329 | 	 STACK_PUSHR(stack, int, NFL_POST_CATENATION); | ||
| 2330 | 	 STACK_PUSHR(stack, voidptr, ((tre_catenation_t *)node->obj)->right); | ||
| 2331 | 	 STACK_PUSHR(stack, int, NFL_RECURSE); | ||
| 2332 | 	 STACK_PUSHR(stack, voidptr, ((tre_catenation_t *)node->obj)->left); | ||
| 2333 | 	 STACK_PUSHR(stack, int, NFL_RECURSE); | ||
| 2334 | 	 break; | ||
| 2335 | |||
| 2336 | 	 case ITERATION: | ||
| 2337 | 	 /* Compute the attributes for the subtree, and after that for | ||
| 2338 | 		 this node. */ | ||
| 2339 | 	 STACK_PUSHR(stack, voidptr, node); | ||
| 2340 | 	 STACK_PUSHR(stack, int, NFL_POST_ITERATION); | ||
| 2341 | 	 STACK_PUSHR(stack, voidptr, ((tre_iteration_t *)node->obj)->arg); | ||
| 2342 | 	 STACK_PUSHR(stack, int, NFL_RECURSE); | ||
| 2343 | 	 break; | ||
| 2344 | 	 } | ||
| 2345 | 	 break; /* end case: NFL_RECURSE */ | ||
| 2346 | |||
| 2347 | 	case NFL_POST_UNION: | ||
| 2348 | 	 { | ||
| 2349 | 	 tre_union_t *uni = (tre_union_t *)node->obj; | ||
| 2350 | 	 node->nullable = uni->left->nullable || uni->right->nullable; | ||
| 2351 | 	 node->firstpos = tre_set_union(mem, uni->left->firstpos, | ||
| 2352 | 					 uni->right->firstpos, NULL, 0); | ||
| 2353 | 	 if (!node->firstpos) | ||
| 2354 | 	 return REG_ESPACE; | ||
| 2355 | 	 node->lastpos = tre_set_union(mem, uni->left->lastpos, | ||
| 2356 | 					 uni->right->lastpos, NULL, 0); | ||
| 2357 | 	 if (!node->lastpos) | ||
| 2358 | 	 return REG_ESPACE; | ||
| 2359 | 	 break; | ||
| 2360 | 	 } | ||
| 2361 | |||
| 2362 | 	case NFL_POST_ITERATION: | ||
| 2363 | 	 { | ||
| 2364 | 	 tre_iteration_t *iter = (tre_iteration_t *)node->obj; | ||
| 2365 | |||
| 2366 | 	 if (iter->min == 0 || iter->arg->nullable) | ||
| 2367 | 	 node->nullable = 1; | ||
| 2368 | 	 else | ||
| 2369 | 	 node->nullable = 0; | ||
| 2370 | 	 node->firstpos = iter->arg->firstpos; | ||
| 2371 | 	 node->lastpos = iter->arg->lastpos; | ||
| 2372 | 	 break; | ||
| 2373 | 	 } | ||
| 2374 | |||
| 2375 | 	case NFL_POST_CATENATION: | ||
| 2376 | 	 { | ||
| 2377 | 	 int num_tags, *tags, assertions; | ||
| 2378 | 	 reg_errcode_t status; | ||
| 2379 | 	 tre_catenation_t *cat = node->obj; | ||
| 2380 | 	 node->nullable = cat->left->nullable && cat->right->nullable; | ||
| 2381 | |||
| 2382 | 	 /* Compute firstpos. */ | ||
| 2383 | 	 if (cat->left->nullable) | ||
| 2384 | 	 { | ||
| 2385 | 		/* The left side matches the empty string. Make a first pass | ||
| 2386 | 		 with tre_match_empty() to get the number of tags and | ||
| 2387 | 		 parameters. */ | ||
| 2388 | 		status = tre_match_empty(stack, cat->left, | ||
| 2389 | 					 NULL, NULL, &num_tags); | ||
| 2390 | 		if (status != REG_OK) | ||
| 2391 | 		 return status; | ||
| 2392 | 		/* Allocate arrays for the tags and parameters. */ | ||
| 2393 | 		tags = xmalloc(sizeof(*tags) * (num_tags + 1)); | ||
| 2394 | 		if (!tags) | ||
| 2395 | 		 return REG_ESPACE; | ||
| 2396 | 		tags[0] = -1; | ||
| 2397 | 		assertions = 0; | ||
| 2398 | 		/* Second pass with tre_mach_empty() to get the list of | ||
| 2399 | 		 tags and parameters. */ | ||
| 2400 | 		status = tre_match_empty(stack, cat->left, tags, | ||
| 2401 | 					 &assertions, NULL); | ||
| 2402 | 		if (status != REG_OK) | ||
| 2403 | 		 { | ||
| 2404 | 		 xfree(tags); | ||
| 2405 | 		 return status; | ||
| 2406 | 		 } | ||
| 2407 | 		node->firstpos = | ||
| 2408 | 		 tre_set_union(mem, cat->right->firstpos, cat->left->firstpos, | ||
| 2409 | 				tags, assertions); | ||
| 2410 | 		xfree(tags); | ||
| 2411 | 		if (!node->firstpos) | ||
| 2412 | 		 return REG_ESPACE; | ||
| 2413 | 	 } | ||
| 2414 | 	 else | ||
| 2415 | 	 { | ||
| 2416 | 		node->firstpos = cat->left->firstpos; | ||
| 2417 | 	 } | ||
| 2418 | |||
| 2419 | 	 /* Compute lastpos. */ | ||
| 2420 | 	 if (cat->right->nullable) | ||
| 2421 | 	 { | ||
| 2422 | 		/* The right side matches the empty string. Make a first pass | ||
| 2423 | 		 with tre_match_empty() to get the number of tags and | ||
| 2424 | 		 parameters. */ | ||
| 2425 | 		status = tre_match_empty(stack, cat->right, | ||
| 2426 | 					 NULL, NULL, &num_tags); | ||
| 2427 | 		if (status != REG_OK) | ||
| 2428 | 		 return status; | ||
| 2429 | 		/* Allocate arrays for the tags and parameters. */ | ||
| 2430 | 		tags = xmalloc(sizeof(int) * (num_tags + 1)); | ||
| 2431 | 		if (!tags) | ||
| 2432 | 		 return REG_ESPACE; | ||
| 2433 | 		tags[0] = -1; | ||
| 2434 | 		assertions = 0; | ||
| 2435 | 		/* Second pass with tre_mach_empty() to get the list of | ||
| 2436 | 		 tags and parameters. */ | ||
| 2437 | 		status = tre_match_empty(stack, cat->right, tags, | ||
| 2438 | 					 &assertions, NULL); | ||
| 2439 | 		if (status != REG_OK) | ||
| 2440 | 		 { | ||
| 2441 | 		 xfree(tags); | ||
| 2442 | 		 return status; | ||
| 2443 | 		 } | ||
| 2444 | 		node->lastpos = | ||
| 2445 | 		 tre_set_union(mem, cat->left->lastpos, cat->right->lastpos, | ||
| 2446 | 				tags, assertions); | ||
| 2447 | 		xfree(tags); | ||
| 2448 | 		if (!node->lastpos) | ||
| 2449 | 		 return REG_ESPACE; | ||
| 2450 | 	 } | ||
| 2451 | 	 else | ||
| 2452 | 	 { | ||
| 2453 | 		node->lastpos = cat->right->lastpos; | ||
| 2454 | 	 } | ||
| 2455 | 	 break; | ||
| 2456 | 	 } | ||
| 2457 | |||
| 2458 | 	default: | ||
| 2459 | 	 assert(0); | ||
| 2460 | 	 break; | ||
| 2461 | 	} | ||
| 2462 | } | ||
| 2463 | |||
| 2464 | return REG_OK; | ||
| 2465 | } | ||
| 2466 | |||
| 2467 | |||
| 2468 | /* Adds a transition from each position in `p1' to each position in `p2'. */ | ||
| 2469 | static reg_errcode_t | ||
| 2470 | tre_make_trans(tre_pos_and_tags_t *p1, tre_pos_and_tags_t *p2, | ||
| 2471 | 	 tre_tnfa_transition_t *transitions, | ||
| 2472 | 	 int *counts, int *offs) | ||
| 2473 | { | ||
| 2474 | tre_pos_and_tags_t *orig_p2 = p2; | ||
| 2475 | tre_tnfa_transition_t *trans; | ||
| 2476 | int i, j, k, l, dup, prev_p2_pos; | ||
| 2477 | |||
| 2478 | if (transitions != NULL) | ||
| 2479 | while (p1->position >= 0) | ||
| 2480 | { | ||
| 2481 | 	p2 = orig_p2; | ||
| 2482 | 	prev_p2_pos = -1; | ||
| 2483 | 	while (p2->position >= 0) | ||
| 2484 | 	 { | ||
| 2485 | 	 /* Optimization: if this position was already handled, skip it. */ | ||
| 2486 | 	 if (p2->position == prev_p2_pos) | ||
| 2487 | 	 { | ||
| 2488 | 		p2++; | ||
| 2489 | 		continue; | ||
| 2490 | 	 } | ||
| 2491 | 	 prev_p2_pos = p2->position; | ||
| 2492 | 	 /* Set `trans' to point to the next unused transition from | ||
| 2493 | 	 position `p1->position'. */ | ||
| 2494 | 	 trans = transitions + offs[p1->position]; | ||
| 2495 | 	 while (trans->state != NULL) | ||
| 2496 | 	 { | ||
| 2497 | #if 0 | ||
| 2498 | 		/* If we find a previous transition from `p1->position' to | ||
| 2499 | 		 `p2->position', it is overwritten. This can happen only | ||
| 2500 | 		 if there are nested loops in the regexp, like in "((a)*)*". | ||
| 2501 | 		 In POSIX.2 repetition using the outer loop is always | ||
| 2502 | 		 preferred over using the inner loop.	 Therefore the | ||
| 2503 | 		 transition for the inner loop is useless and can be thrown | ||
| 2504 | 		 away. */ | ||
| 2505 | 		/* XXX - The same position is used for all nodes in a bracket | ||
| 2506 | 		 expression, so this optimization cannot be used (it will | ||
| 2507 | 		 break bracket expressions) unless I figure out a way to | ||
| 2508 | 		 detect it here. */ | ||
| 2509 | 		if (trans->state_id == p2->position) | ||
| 2510 | 		 { | ||
| 2511 | 		 break; | ||
| 2512 | 		 } | ||
| 2513 | #endif | ||
| 2514 | 		trans++; | ||
| 2515 | 	 } | ||
| 2516 | |||
| 2517 | 	 if (trans->state == NULL) | ||
| 2518 | 	 (trans + 1)->state = NULL; | ||
| 2519 | 	 /* Use the character ranges, assertions, etc. from `p1' for | ||
| 2520 | 	 the transition from `p1' to `p2'. */ | ||
| 2521 | 	 trans->code_min = p1->code_min; | ||
| 2522 | 	 trans->code_max = p1->code_max; | ||
| 2523 | 	 trans->state = transitions + offs[p2->position]; | ||
| 2524 | 	 trans->state_id = p2->position; | ||
| 2525 | 	 trans->assertions = p1->assertions | p2->assertions | ||
| 2526 | 	 | (p1->class ? ASSERT_CHAR_CLASS : 0) | ||
| 2527 | 	 | (p1->neg_classes != NULL ? ASSERT_CHAR_CLASS_NEG : 0); | ||
| 2528 | 	 if (p1->backref >= 0) | ||
| 2529 | 	 { | ||
| 2530 | 		assert((trans->assertions & ASSERT_CHAR_CLASS) == 0); | ||
| 2531 | 		assert(p2->backref < 0); | ||
| 2532 | 		trans->u.backref = p1->backref; | ||
| 2533 | 		trans->assertions |= ASSERT_BACKREF; | ||
| 2534 | 	 } | ||
| 2535 | 	 else | ||
| 2536 | 	 trans->u.class = p1->class; | ||
| 2537 | 	 if (p1->neg_classes != NULL) | ||
| 2538 | 	 { | ||
| 2539 | 		for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++); | ||
| 2540 | 		trans->neg_classes = | ||
| 2541 | 		 xmalloc(sizeof(*trans->neg_classes) * (i + 1)); | ||
| 2542 | 		if (trans->neg_classes == NULL) | ||
| 2543 | 		 return REG_ESPACE; | ||
| 2544 | 		for (i = 0; p1->neg_classes[i] != (tre_ctype_t)0; i++) | ||
| 2545 | 		 trans->neg_classes[i] = p1->neg_classes[i]; | ||
| 2546 | 		trans->neg_classes[i] = (tre_ctype_t)0; | ||
| 2547 | 	 } | ||
| 2548 | 	 else | ||
| 2549 | 	 trans->neg_classes = NULL; | ||
| 2550 | |||
| 2551 | 	 /* Find out how many tags this transition has. */ | ||
| 2552 | 	 i = 0; | ||
| 2553 | 	 if (p1->tags != NULL) | ||
| 2554 | 	 while(p1->tags[i] >= 0) | ||
| 2555 | 		i++; | ||
| 2556 | 	 j = 0; | ||
| 2557 | 	 if (p2->tags != NULL) | ||
| 2558 | 	 while(p2->tags[j] >= 0) | ||
| 2559 | 		j++; | ||
| 2560 | |||
| 2561 | 	 /* If we are overwriting a transition, free the old tag array. */ | ||
| 2562 | 	 if (trans->tags != NULL) | ||
| 2563 | 	 xfree(trans->tags); | ||
| 2564 | 	 trans->tags = NULL; | ||
| 2565 | |||
| 2566 | 	 /* If there were any tags, allocate an array and fill it. */ | ||
| 2567 | 	 if (i + j > 0) | ||
| 2568 | 	 { | ||
| 2569 | 		trans->tags = xmalloc(sizeof(*trans->tags) * (i + j + 1)); | ||
| 2570 | 		if (!trans->tags) | ||
| 2571 | 		 return REG_ESPACE; | ||
| 2572 | 		i = 0; | ||
| 2573 | 		if (p1->tags != NULL) | ||
| 2574 | 		 while(p1->tags[i] >= 0) | ||
| 2575 | 		 { | ||
| 2576 | 		 trans->tags[i] = p1->tags[i]; | ||
| 2577 | 		 i++; | ||
| 2578 | 		 } | ||
| 2579 | 		l = i; | ||
| 2580 | 		j = 0; | ||
| 2581 | 		if (p2->tags != NULL) | ||
| 2582 | 		 while (p2->tags[j] >= 0) | ||
| 2583 | 		 { | ||
| 2584 | 		 /* Don't add duplicates. */ | ||
| 2585 | 		 dup = 0; | ||
| 2586 | 		 for (k = 0; k < i; k++) | ||
| 2587 | 			if (trans->tags[k] == p2->tags[j]) | ||
| 2588 | 			 { | ||
| 2589 | 			 dup = 1; | ||
| 2590 | 			 break; | ||
| 2591 | 			 } | ||
| 2592 | 		 if (!dup) | ||
| 2593 | 			trans->tags[l++] = p2->tags[j]; | ||
| 2594 | 		 j++; | ||
| 2595 | 		 } | ||
| 2596 | 		trans->tags[l] = -1; | ||
| 2597 | 	 } | ||
| 2598 | |||
| 2599 | 	 p2++; | ||
| 2600 | 	 } | ||
| 2601 | 	p1++; | ||
| 2602 | } | ||
| 2603 | else | ||
| 2604 | /* Compute a maximum limit for the number of transitions leaving | ||
| 2605 | from each state. */ | ||
| 2606 | while (p1->position >= 0) | ||
| 2607 | { | ||
| 2608 | 	p2 = orig_p2; | ||
| 2609 | 	while (p2->position >= 0) | ||
| 2610 | 	 { | ||
| 2611 | 	 counts[p1->position]++; | ||
| 2612 | 	 p2++; | ||
| 2613 | 	 } | ||
| 2614 | 	p1++; | ||
| 2615 | } | ||
| 2616 | return REG_OK; | ||
| 2617 | } | ||
| 2618 | |||
| 2619 | /* Converts the syntax tree to a TNFA.	All the transitions in the TNFA are | ||
| 2620 | labelled with one character range (there are no transitions on empty | ||
| 2621 | strings). The TNFA takes O(n^2) space in the worst case, `n' is size of | ||
| 2622 | the regexp. */ | ||
| 2623 | static reg_errcode_t | ||
| 2624 | tre_ast_to_tnfa(tre_ast_node_t *node, tre_tnfa_transition_t *transitions, | ||
| 2625 | 		int *counts, int *offs) | ||
| 2626 | { | ||
| 2627 | tre_union_t *uni; | ||
| 2628 | tre_catenation_t *cat; | ||
| 2629 | tre_iteration_t *iter; | ||
| 2630 | reg_errcode_t errcode = REG_OK; | ||
| 2631 | |||
| 2632 | /* XXX - recurse using a stack!. */ | ||
| 2633 | switch (node->type) | ||
| 2634 | { | ||
| 2635 | case LITERAL: | ||
| 2636 | break; | ||
| 2637 | case UNION: | ||
| 2638 | uni = (tre_union_t *)node->obj; | ||
| 2639 | errcode = tre_ast_to_tnfa(uni->left, transitions, counts, offs); | ||
| 2640 | if (errcode != REG_OK) | ||
| 2641 | 	return errcode; | ||
| 2642 | errcode = tre_ast_to_tnfa(uni->right, transitions, counts, offs); | ||
| 2643 | break; | ||
| 2644 | |||
| 2645 | case CATENATION: | ||
| 2646 | cat = (tre_catenation_t *)node->obj; | ||
| 2647 | /* Add a transition from each position in cat->left->lastpos | ||
| 2648 | 	 to each position in cat->right->firstpos. */ | ||
| 2649 | errcode = tre_make_trans(cat->left->lastpos, cat->right->firstpos, | ||
| 2650 | 			 transitions, counts, offs); | ||
| 2651 | if (errcode != REG_OK) | ||
| 2652 | 	return errcode; | ||
| 2653 | errcode = tre_ast_to_tnfa(cat->left, transitions, counts, offs); | ||
| 2654 | if (errcode != REG_OK) | ||
| 2655 | 	return errcode; | ||
| 2656 | errcode = tre_ast_to_tnfa(cat->right, transitions, counts, offs); | ||
| 2657 | break; | ||
| 2658 | |||
| 2659 | case ITERATION: | ||
| 2660 | iter = (tre_iteration_t *)node->obj; | ||
| 2661 | assert(iter->max == -1 || iter->max == 1); | ||
| 2662 | |||
| 2663 | if (iter->max == -1) | ||
| 2664 | 	{ | ||
| 2665 | 	 assert(iter->min == 0 || iter->min == 1); | ||
| 2666 | 	 /* Add a transition from each last position in the iterated | ||
| 2667 | 	 expression to each first position. */ | ||
| 2668 | 	 errcode = tre_make_trans(iter->arg->lastpos, iter->arg->firstpos, | ||
| 2669 | 				 transitions, counts, offs); | ||
| 2670 | 	 if (errcode != REG_OK) | ||
| 2671 | 	 return errcode; | ||
| 2672 | 	} | ||
| 2673 | errcode = tre_ast_to_tnfa(iter->arg, transitions, counts, offs); | ||
| 2674 | break; | ||
| 2675 | } | ||
| 2676 | return errcode; | ||
| 2677 | } | ||
| 2678 | |||
| 2679 | |||
| 2680 | #define ERROR_EXIT(err)		 \ | ||
| 2681 | do				 \ | ||
| 2682 | {				 \ | ||
| 2683 | errcode = err;		 \ | ||
| 2684 | if (/*CONSTCOND*/1)	 \ | ||
| 2685 | 	goto error_exit;	 \ | ||
| 2686 | }				 \ | ||
| 2687 | while (/*CONSTCOND*/0) | ||
| 2688 | |||
| 2689 | |||
| 2690 | int | ||
| 2691 | regcomp(regex_t *restrict preg, const char *restrict regex, int cflags) | ||
| 2692 | { | ||
| 2693 | tre_stack_t *stack; | ||
| 2694 | tre_ast_node_t *tree, *tmp_ast_l, *tmp_ast_r; | ||
| 2695 | tre_pos_and_tags_t *p; | ||
| 2696 | int *counts = NULL, *offs = NULL; | ||
| 2697 | int i, add = 0; | ||
| 2698 | tre_tnfa_transition_t *transitions, *initial; | ||
| 2699 | tre_tnfa_t *tnfa = NULL; | ||
| 2700 | tre_submatch_data_t *submatch_data; | ||
| 2701 | tre_tag_direction_t *tag_directions = NULL; | ||
| 2702 | reg_errcode_t errcode; | ||
| 2703 | tre_mem_t mem; | ||
| 2704 | |||
| 2705 | /* Parse context. */ | ||
| 2706 | tre_parse_ctx_t parse_ctx; | ||
| 2707 | |||
| 2708 | /* Allocate a stack used throughout the compilation process for various | ||
| 2709 | purposes. */ | ||
| 2710 | stack = tre_stack_new(512, 1024000, 128); | ||
| 2711 | if (!stack) | ||
| 2712 | return REG_ESPACE; | ||
| 2713 | /* Allocate a fast memory allocator. */ | ||
| 2714 | mem = tre_mem_new(); | ||
| 2715 | if (!mem) | ||
| 2716 | { | ||
| 2717 | tre_stack_destroy(stack); | ||
| 2718 | return REG_ESPACE; | ||
| 2719 | } | ||
| 2720 | |||
| 2721 | /* Parse the regexp. */ | ||
| 2722 | memset(&parse_ctx, 0, sizeof(parse_ctx)); | ||
| 2723 | parse_ctx.mem = mem; | ||
| 2724 | parse_ctx.stack = stack; | ||
| 2725 | parse_ctx.start = regex; | ||
| 2726 | parse_ctx.cflags = cflags; | ||
| 2727 | parse_ctx.max_backref = -1; | ||
| 2728 | errcode = tre_parse(&parse_ctx); | ||
| 2729 | if (errcode != REG_OK) | ||
| 2730 | ERROR_EXIT(errcode); | ||
| 2731 | preg->re_nsub = parse_ctx.submatch_id - 1; | ||
| 2732 | tree = parse_ctx.n; | ||
| 2733 | |||
| 2734 | #ifdef TRE_DEBUG | ||
| 2735 | tre_ast_print(tree); | ||
| 2736 | #endif /* TRE_DEBUG */ | ||
| 2737 | |||
| 2738 | /* Referring to nonexistent subexpressions is illegal. */ | ||
| 2739 | if (parse_ctx.max_backref > (int)preg->re_nsub) | ||
| 2740 | ERROR_EXIT(REG_ESUBREG); | ||
| 2741 | |||
| 2742 | /* Allocate the TNFA struct. */ | ||
| 2743 | tnfa = xcalloc(1, sizeof(tre_tnfa_t)); | ||
| 2744 | if (tnfa == NULL) | ||
| 2745 | ERROR_EXIT(REG_ESPACE); | ||
| 2746 | tnfa->have_backrefs = parse_ctx.max_backref >= 0; | ||
| 2747 | tnfa->have_approx = 0; | ||
| 2748 | tnfa->num_submatches = parse_ctx.submatch_id; | ||
| 2749 | |||
| 2750 | /* Set up tags for submatch addressing. If REG_NOSUB is set and the | ||
| 2751 | regexp does not have back references, this can be skipped. */ | ||
| 2752 | if (tnfa->have_backrefs || !(cflags & REG_NOSUB)) | ||
| 2753 | { | ||
| 2754 | |||
| 2755 | /* Figure out how many tags we will need. */ | ||
| 2756 | errcode = tre_add_tags(NULL, stack, tree, tnfa); | ||
| 2757 | if (errcode != REG_OK) | ||
| 2758 | 	ERROR_EXIT(errcode); | ||
| 2759 | |||
| 2760 | if (tnfa->num_tags > 0) | ||
| 2761 | 	{ | ||
| 2762 | 	 tag_directions = xmalloc(sizeof(*tag_directions) | ||
| 2763 | 				 * (tnfa->num_tags + 1)); | ||
| 2764 | 	 if (tag_directions == NULL) | ||
| 2765 | 	 ERROR_EXIT(REG_ESPACE); | ||
| 2766 | 	 tnfa->tag_directions = tag_directions; | ||
| 2767 | 	 memset(tag_directions, -1, | ||
| 2768 | 		 sizeof(*tag_directions) * (tnfa->num_tags + 1)); | ||
| 2769 | 	} | ||
| 2770 | tnfa->minimal_tags = xcalloc((unsigned)tnfa->num_tags * 2 + 1, | ||
| 2771 | 				 sizeof(*tnfa->minimal_tags)); | ||
| 2772 | if (tnfa->minimal_tags == NULL) | ||
| 2773 | 	ERROR_EXIT(REG_ESPACE); | ||
| 2774 | |||
| 2775 | submatch_data = xcalloc((unsigned)parse_ctx.submatch_id, | ||
| 2776 | 			 sizeof(*submatch_data)); | ||
| 2777 | if (submatch_data == NULL) | ||
| 2778 | 	ERROR_EXIT(REG_ESPACE); | ||
| 2779 | tnfa->submatch_data = submatch_data; | ||
| 2780 | |||
| 2781 | errcode = tre_add_tags(mem, stack, tree, tnfa); | ||
| 2782 | if (errcode != REG_OK) | ||
| 2783 | 	ERROR_EXIT(errcode); | ||
| 2784 | |||
| 2785 | } | ||
| 2786 | |||
| 2787 | /* Expand iteration nodes. */ | ||
| 2788 | errcode = tre_expand_ast(mem, stack, tree, &parse_ctx.position, | ||
| 2789 | 			 tag_directions); | ||
| 2790 | if (errcode != REG_OK) | ||
| 2791 | ERROR_EXIT(errcode); | ||
| 2792 | |||
| 2793 | /* Add a dummy node for the final state. | ||
| 2794 | XXX - For certain patterns this dummy node can be optimized away, | ||
| 2795 | 	 for example "a*" or "ab*".	Figure out a simple way to detect | ||
| 2796 | 	 this possibility. */ | ||
| 2797 | tmp_ast_l = tree; | ||
| 2798 | tmp_ast_r = tre_ast_new_literal(mem, 0, 0, parse_ctx.position++); | ||
| 2799 | if (tmp_ast_r == NULL) | ||
| 2800 | ERROR_EXIT(REG_ESPACE); | ||
| 2801 | |||
| 2802 | tree = tre_ast_new_catenation(mem, tmp_ast_l, tmp_ast_r); | ||
| 2803 | if (tree == NULL) | ||
| 2804 | ERROR_EXIT(REG_ESPACE); | ||
| 2805 | |||
| 2806 | errcode = tre_compute_nfl(mem, stack, tree); | ||
| 2807 | if (errcode != REG_OK) | ||
| 2808 | ERROR_EXIT(errcode); | ||
| 2809 | |||
| 2810 | counts = xmalloc(sizeof(int) * parse_ctx.position); | ||
| 2811 | if (counts == NULL) | ||
| 2812 | ERROR_EXIT(REG_ESPACE); | ||
| 2813 | |||
| 2814 | offs = xmalloc(sizeof(int) * parse_ctx.position); | ||
| 2815 | if (offs == NULL) | ||
| 2816 | ERROR_EXIT(REG_ESPACE); | ||
| 2817 | |||
| 2818 | for (i = 0; i < parse_ctx.position; i++) | ||
| 2819 | counts[i] = 0; | ||
| 2820 | tre_ast_to_tnfa(tree, NULL, counts, NULL); | ||
| 2821 | |||
| 2822 | add = 0; | ||
| 2823 | for (i = 0; i < parse_ctx.position; i++) | ||
| 2824 | { | ||
| 2825 | offs[i] = add; | ||
| 2826 | add += counts[i] + 1; | ||
| 2827 | counts[i] = 0; | ||
| 2828 | } | ||
| 2829 | transitions = xcalloc((unsigned)add + 1, sizeof(*transitions)); | ||
| 2830 | if (transitions == NULL) | ||
| 2831 | ERROR_EXIT(REG_ESPACE); | ||
| 2832 | tnfa->transitions = transitions; | ||
| 2833 | tnfa->num_transitions = add; | ||
| 2834 | |||
| 2835 | errcode = tre_ast_to_tnfa(tree, transitions, counts, offs); | ||
| 2836 | if (errcode != REG_OK) | ||
| 2837 | ERROR_EXIT(errcode); | ||
| 2838 | |||
| 2839 | tnfa->firstpos_chars = NULL; | ||
| 2840 | |||
| 2841 | p = tree->firstpos; | ||
| 2842 | i = 0; | ||
| 2843 | while (p->position >= 0) | ||
| 2844 | { | ||
| 2845 | i++; | ||
| 2846 | p++; | ||
| 2847 | } | ||
| 2848 | |||
| 2849 | initial = xcalloc((unsigned)i + 1, sizeof(tre_tnfa_transition_t)); | ||
| 2850 | if (initial == NULL) | ||
| 2851 | ERROR_EXIT(REG_ESPACE); | ||
| 2852 | tnfa->initial = initial; | ||
| 2853 | |||
| 2854 | i = 0; | ||
| 2855 | for (p = tree->firstpos; p->position >= 0; p++) | ||
| 2856 | { | ||
| 2857 | initial[i].state = transitions + offs[p->position]; | ||
| 2858 | initial[i].state_id = p->position; | ||
| 2859 | initial[i].tags = NULL; | ||
| 2860 | /* Copy the arrays p->tags, and p->params, they are allocated | ||
| 2861 | 	 from a tre_mem object. */ | ||
| 2862 | if (p->tags) | ||
| 2863 | 	{ | ||
| 2864 | 	 int j; | ||
| 2865 | 	 for (j = 0; p->tags[j] >= 0; j++); | ||
| 2866 | 	 initial[i].tags = xmalloc(sizeof(*p->tags) * (j + 1)); | ||
| 2867 | 	 if (!initial[i].tags) | ||
| 2868 | 	 ERROR_EXIT(REG_ESPACE); | ||
| 2869 | 	 memcpy(initial[i].tags, p->tags, sizeof(*p->tags) * (j + 1)); | ||
| 2870 | 	} | ||
| 2871 | initial[i].assertions = p->assertions; | ||
| 2872 | i++; | ||
| 2873 | } | ||
| 2874 | initial[i].state = NULL; | ||
| 2875 | |||
| 2876 | tnfa->num_transitions = add; | ||
| 2877 | tnfa->final = transitions + offs[tree->lastpos[0].position]; | ||
| 2878 | tnfa->num_states = parse_ctx.position; | ||
| 2879 | tnfa->cflags = cflags; | ||
| 2880 | |||
| 2881 | tre_mem_destroy(mem); | ||
| 2882 | tre_stack_destroy(stack); | ||
| 2883 | xfree(counts); | ||
| 2884 | xfree(offs); | ||
| 2885 | |||
| 2886 | preg->TRE_REGEX_T_FIELD = (void *)tnfa; | ||
| 2887 | return REG_OK; | ||
| 2888 | |||
| 2889 | error_exit: | ||
| 2890 | /* Free everything that was allocated and return the error code. */ | ||
| 2891 | tre_mem_destroy(mem); | ||
| 2892 | if (stack != NULL) | ||
| 2893 | tre_stack_destroy(stack); | ||
| 2894 | if (counts != NULL) | ||
| 2895 | xfree(counts); | ||
| 2896 | if (offs != NULL) | ||
| 2897 | xfree(offs); | ||
| 2898 | preg->TRE_REGEX_T_FIELD = (void *)tnfa; | ||
| 2899 | regfree(preg); | ||
| 2900 | return errcode; | ||
| 2901 | } | ||
| 2902 | |||
| 2903 | |||
| 2904 | |||
| 2905 | |||
| 2906 | void | ||
| 2907 | regfree(regex_t *preg) | ||
| 2908 | { | ||
| 2909 | tre_tnfa_t *tnfa; | ||
| 2910 | unsigned int i; | ||
| 2911 | tre_tnfa_transition_t *trans; | ||
| 2912 | |||
| 2913 | tnfa = (void *)preg->TRE_REGEX_T_FIELD; | ||
| 2914 | if (!tnfa) | ||
| 2915 | return; | ||
| 2916 | |||
| 2917 | for (i = 0; i < tnfa->num_transitions; i++) | ||
| 2918 | if (tnfa->transitions[i].state) | ||
| 2919 | { | ||
| 2920 | 	if (tnfa->transitions[i].tags) | ||
| 2921 | 	 xfree(tnfa->transitions[i].tags); | ||
| 2922 | 	if (tnfa->transitions[i].neg_classes) | ||
| 2923 | 	 xfree(tnfa->transitions[i].neg_classes); | ||
| 2924 | } | ||
| 2925 | if (tnfa->transitions) | ||
| 2926 | xfree(tnfa->transitions); | ||
| 2927 | |||
| 2928 | if (tnfa->initial) | ||
| 2929 | { | ||
| 2930 | for (trans = tnfa->initial; trans->state; trans++) | ||
| 2931 | 	{ | ||
| 2932 | 	 if (trans->tags) | ||
| 2933 | 	 xfree(trans->tags); | ||
| 2934 | 	} | ||
| 2935 | xfree(tnfa->initial); | ||
| 2936 | } | ||
| 2937 | |||
| 2938 | if (tnfa->submatch_data) | ||
| 2939 | { | ||
| 2940 | for (i = 0; i < tnfa->num_submatches; i++) | ||
| 2941 | 	if (tnfa->submatch_data[i].parents) | ||
| 2942 | 	 xfree(tnfa->submatch_data[i].parents); | ||
| 2943 | xfree(tnfa->submatch_data); | ||
| 2944 | } | ||
| 2945 | |||
| 2946 | if (tnfa->tag_directions) | ||
| 2947 | xfree(tnfa->tag_directions); | ||
| 2948 | if (tnfa->firstpos_chars) | ||
| 2949 | xfree(tnfa->firstpos_chars); | ||
| 2950 | if (tnfa->minimal_tags) | ||
| 2951 | xfree(tnfa->minimal_tags); | ||
| 2952 | xfree(tnfa); | ||
| 2953 | } | ||
lib/libc/wasi/libc-top-half/musl/src/regex/regexec.c deleted-1028| ... | @@ -1,1028 +0,0 @@ | ||
| 1 | /* | ||
| 2 | regexec.c - TRE POSIX compatible matching functions (and more). | ||
| 3 | |||
| 4 | Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi> | ||
| 5 | All rights reserved. | ||
| 6 | |||
| 7 | Redistribution and use in source and binary forms, with or without | ||
| 8 | modification, are permitted provided that the following conditions | ||
| 9 | are met: | ||
| 10 | |||
| 11 | 1. Redistributions of source code must retain the above copyright | ||
| 12 | notice, this list of conditions and the following disclaimer. | ||
| 13 | |||
| 14 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | notice, this list of conditions and the following disclaimer in the | ||
| 16 | documentation and/or other materials provided with the distribution. | ||
| 17 | |||
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS | ||
| 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | */ | ||
| 31 | |||
| 32 | #include <stdlib.h> | ||
| 33 | #include <string.h> | ||
| 34 | #include <wchar.h> | ||
| 35 | #include <wctype.h> | ||
| 36 | #include <limits.h> | ||
| 37 | #include <stdint.h> | ||
| 38 | |||
| 39 | #include <regex.h> | ||
| 40 | |||
| 41 | #include "tre.h" | ||
| 42 | |||
| 43 | #include <assert.h> | ||
| 44 | |||
| 45 | static void | ||
| 46 | tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, | ||
| 47 | 		const tre_tnfa_t *tnfa, regoff_t *tags, regoff_t match_eo); | ||
| 48 | |||
| 49 | /*********************************************************************** | ||
| 50 | from tre-match-utils.h | ||
| 51 | ***********************************************************************/ | ||
| 52 | |||
| 53 | #define GET_NEXT_WCHAR() do { \ | ||
| 54 | prev_c = next_c; pos += pos_add_next; \ | ||
| 55 | if ((pos_add_next = mbtowc(&next_c, str_byte, MB_LEN_MAX)) <= 0) { \ | ||
| 56 | if (pos_add_next < 0) { ret = REG_NOMATCH; goto error_exit; } \ | ||
| 57 | else pos_add_next++; \ | ||
| 58 | } \ | ||
| 59 | str_byte += pos_add_next; \ | ||
| 60 | } while (0) | ||
| 61 | |||
| 62 | #define IS_WORD_CHAR(c)	 ((c) == L'_' || tre_isalnum(c)) | ||
| 63 | |||
| 64 | #define CHECK_ASSERTIONS(assertions)					 \ | ||
| 65 | (((assertions & ASSERT_AT_BOL)					 \ | ||
| 66 | && (pos > 0 || reg_notbol)						 \ | ||
| 67 | && (prev_c != L'\n' || !reg_newline))				 \ | ||
| 68 | || ((assertions & ASSERT_AT_EOL)					 \ | ||
| 69 | && (next_c != L'\0' || reg_noteol)				 \ | ||
| 70 | && (next_c != L'\n' || !reg_newline))				 \ | ||
| 71 | || ((assertions & ASSERT_AT_BOW)					 \ | ||
| 72 | && (IS_WORD_CHAR(prev_c) || !IS_WORD_CHAR(next_c)))	 \ | ||
| 73 | || ((assertions & ASSERT_AT_EOW)					 \ | ||
| 74 | && (!IS_WORD_CHAR(prev_c) || IS_WORD_CHAR(next_c)))		 \ | ||
| 75 | || ((assertions & ASSERT_AT_WB)					 \ | ||
| 76 | && (pos != 0 && next_c != L'\0'					 \ | ||
| 77 | 	 && IS_WORD_CHAR(prev_c) == IS_WORD_CHAR(next_c)))		 \ | ||
| 78 | || ((assertions & ASSERT_AT_WB_NEG)					 \ | ||
| 79 | && (pos == 0 || next_c == L'\0'					 \ | ||
| 80 | 	 || IS_WORD_CHAR(prev_c) != IS_WORD_CHAR(next_c)))) | ||
| 81 | |||
| 82 | #define CHECK_CHAR_CLASSES(trans_i, tnfa, eflags) \ | ||
| 83 | (((trans_i->assertions & ASSERT_CHAR_CLASS) \ | ||
| 84 | && !(tnfa->cflags & REG_ICASE) \ | ||
| 85 | && !tre_isctype((tre_cint_t)prev_c, trans_i->u.class)) \ | ||
| 86 | || ((trans_i->assertions & ASSERT_CHAR_CLASS) \ | ||
| 87 | && (tnfa->cflags & REG_ICASE) \ | ||
| 88 | && !tre_isctype(tre_tolower((tre_cint_t)prev_c),trans_i->u.class) \ | ||
| 89 | 	&& !tre_isctype(tre_toupper((tre_cint_t)prev_c),trans_i->u.class)) \ | ||
| 90 | || ((trans_i->assertions & ASSERT_CHAR_CLASS_NEG) \ | ||
| 91 | && tre_neg_char_classes_match(trans_i->neg_classes,(tre_cint_t)prev_c,\ | ||
| 92 | tnfa->cflags & REG_ICASE))) | ||
| 93 | |||
| 94 | |||
| 95 | |||
| 96 | |||
| 97 | /* Returns 1 if `t1' wins `t2', 0 otherwise. */ | ||
| 98 | static int | ||
| 99 | tre_tag_order(int num_tags, tre_tag_direction_t *tag_directions, | ||
| 100 | 	 regoff_t *t1, regoff_t *t2) | ||
| 101 | { | ||
| 102 | int i; | ||
| 103 | for (i = 0; i < num_tags; i++) | ||
| 104 | { | ||
| 105 | if (tag_directions[i] == TRE_TAG_MINIMIZE) | ||
| 106 | 	{ | ||
| 107 | 	 if (t1[i] < t2[i]) | ||
| 108 | 	 return 1; | ||
| 109 | 	 if (t1[i] > t2[i]) | ||
| 110 | 	 return 0; | ||
| 111 | 	} | ||
| 112 | else | ||
| 113 | 	{ | ||
| 114 | 	 if (t1[i] > t2[i]) | ||
| 115 | 	 return 1; | ||
| 116 | 	 if (t1[i] < t2[i]) | ||
| 117 | 	 return 0; | ||
| 118 | 	} | ||
| 119 | } | ||
| 120 | /* assert(0);*/ | ||
| 121 | return 0; | ||
| 122 | } | ||
| 123 | |||
| 124 | static int | ||
| 125 | tre_neg_char_classes_match(tre_ctype_t *classes, tre_cint_t wc, int icase) | ||
| 126 | { | ||
| 127 | while (*classes != (tre_ctype_t)0) | ||
| 128 | if ((!icase && tre_isctype(wc, *classes)) | ||
| 129 | 	|| (icase && (tre_isctype(tre_toupper(wc), *classes) | ||
| 130 | 		 || tre_isctype(tre_tolower(wc), *classes)))) | ||
| 131 | return 1; /* Match. */ | ||
| 132 | else | ||
| 133 | classes++; | ||
| 134 | return 0; /* No match. */ | ||
| 135 | } | ||
| 136 | |||
| 137 | |||
| 138 | /*********************************************************************** | ||
| 139 | from tre-match-parallel.c | ||
| 140 | ***********************************************************************/ | ||
| 141 | |||
| 142 | /* | ||
| 143 | This algorithm searches for matches basically by reading characters | ||
| 144 | in the searched string one by one, starting at the beginning.	 All | ||
| 145 | matching paths in the TNFA are traversed in parallel.	 When two or | ||
| 146 | more paths reach the same state, exactly one is chosen according to | ||
| 147 | tag ordering rules; if returning submatches is not required it does | ||
| 148 | not matter which path is chosen. | ||
| 149 | |||
| 150 | The worst case time required for finding the leftmost and longest | ||
| 151 | match, or determining that there is no match, is always linearly | ||
| 152 | dependent on the length of the text being searched. | ||
| 153 | |||
| 154 | This algorithm cannot handle TNFAs with back referencing nodes. | ||
| 155 | See `tre-match-backtrack.c'. | ||
| 156 | */ | ||
| 157 | |||
| 158 | typedef struct { | ||
| 159 | tre_tnfa_transition_t *state; | ||
| 160 | regoff_t *tags; | ||
| 161 | } tre_tnfa_reach_t; | ||
| 162 | |||
| 163 | typedef struct { | ||
| 164 | regoff_t pos; | ||
| 165 | regoff_t **tags; | ||
| 166 | } tre_reach_pos_t; | ||
| 167 | |||
| 168 | |||
| 169 | static reg_errcode_t | ||
| 170 | tre_tnfa_run_parallel(const tre_tnfa_t *tnfa, const void *string, | ||
| 171 | 		 regoff_t *match_tags, int eflags, | ||
| 172 | 		 regoff_t *match_end_ofs) | ||
| 173 | { | ||
| 174 | /* State variables required by GET_NEXT_WCHAR. */ | ||
| 175 | tre_char_t prev_c = 0, next_c = 0; | ||
| 176 | const char *str_byte = string; | ||
| 177 | regoff_t pos = -1; | ||
| 178 | regoff_t pos_add_next = 1; | ||
| 179 | #ifdef TRE_MBSTATE | ||
| 180 | mbstate_t mbstate; | ||
| 181 | #endif /* TRE_MBSTATE */ | ||
| 182 | int reg_notbol = eflags & REG_NOTBOL; | ||
| 183 | int reg_noteol = eflags & REG_NOTEOL; | ||
| 184 | int reg_newline = tnfa->cflags & REG_NEWLINE; | ||
| 185 | reg_errcode_t ret; | ||
| 186 | |||
| 187 | char *buf; | ||
| 188 | tre_tnfa_transition_t *trans_i; | ||
| 189 | tre_tnfa_reach_t *reach, *reach_next, *reach_i, *reach_next_i; | ||
| 190 | tre_reach_pos_t *reach_pos; | ||
| 191 | int *tag_i; | ||
| 192 | int num_tags, i; | ||
| 193 | |||
| 194 | regoff_t match_eo = -1;	 /* end offset of match (-1 if no match found yet) */ | ||
| 195 | int new_match = 0; | ||
| 196 | regoff_t *tmp_tags = NULL; | ||
| 197 | regoff_t *tmp_iptr; | ||
| 198 | |||
| 199 | #ifdef TRE_MBSTATE | ||
| 200 | memset(&mbstate, '\0', sizeof(mbstate)); | ||
| 201 | #endif /* TRE_MBSTATE */ | ||
| 202 | |||
| 203 | if (!match_tags) | ||
| 204 | num_tags = 0; | ||
| 205 | else | ||
| 206 | num_tags = tnfa->num_tags; | ||
| 207 | |||
| 208 | /* Allocate memory for temporary data required for matching.	This needs to | ||
| 209 | be done for every matching operation to be thread safe. This allocates | ||
| 210 | everything in a single large block with calloc(). */ | ||
| 211 | { | ||
| 212 | size_t tbytes, rbytes, pbytes, xbytes, total_bytes; | ||
| 213 | char *tmp_buf; | ||
| 214 | |||
| 215 | /* Ensure that tbytes and xbytes*num_states cannot overflow, and that | ||
| 216 | * they don't contribute more than 1/8 of SIZE_MAX to total_bytes. */ | ||
| 217 | if (num_tags > SIZE_MAX/(8 * sizeof(regoff_t) * tnfa->num_states)) | ||
| 218 | return REG_ESPACE; | ||
| 219 | |||
| 220 | /* Likewise check rbytes. */ | ||
| 221 | if (tnfa->num_states+1 > SIZE_MAX/(8 * sizeof(*reach_next))) | ||
| 222 | return REG_ESPACE; | ||
| 223 | |||
| 224 | /* Likewise check pbytes. */ | ||
| 225 | if (tnfa->num_states > SIZE_MAX/(8 * sizeof(*reach_pos))) | ||
| 226 | return REG_ESPACE; | ||
| 227 | |||
| 228 | /* Compute the length of the block we need. */ | ||
| 229 | tbytes = sizeof(*tmp_tags) * num_tags; | ||
| 230 | rbytes = sizeof(*reach_next) * (tnfa->num_states + 1); | ||
| 231 | pbytes = sizeof(*reach_pos) * tnfa->num_states; | ||
| 232 | xbytes = sizeof(regoff_t) * num_tags; | ||
| 233 | total_bytes = | ||
| 234 | (sizeof(long) - 1) * 4 /* for alignment paddings */ | ||
| 235 | + (rbytes + xbytes * tnfa->num_states) * 2 + tbytes + pbytes; | ||
| 236 | |||
| 237 | /* Allocate the memory. */ | ||
| 238 | buf = calloc(total_bytes, 1); | ||
| 239 | if (buf == NULL) | ||
| 240 | return REG_ESPACE; | ||
| 241 | |||
| 242 | /* Get the various pointers within tmp_buf (properly aligned). */ | ||
| 243 | tmp_tags = (void *)buf; | ||
| 244 | tmp_buf = buf + tbytes; | ||
| 245 | tmp_buf += ALIGN(tmp_buf, long); | ||
| 246 | reach_next = (void *)tmp_buf; | ||
| 247 | tmp_buf += rbytes; | ||
| 248 | tmp_buf += ALIGN(tmp_buf, long); | ||
| 249 | reach = (void *)tmp_buf; | ||
| 250 | tmp_buf += rbytes; | ||
| 251 | tmp_buf += ALIGN(tmp_buf, long); | ||
| 252 | reach_pos = (void *)tmp_buf; | ||
| 253 | tmp_buf += pbytes; | ||
| 254 | tmp_buf += ALIGN(tmp_buf, long); | ||
| 255 | for (i = 0; i < tnfa->num_states; i++) | ||
| 256 | { | ||
| 257 | 	reach[i].tags = (void *)tmp_buf; | ||
| 258 | 	tmp_buf += xbytes; | ||
| 259 | 	reach_next[i].tags = (void *)tmp_buf; | ||
| 260 | 	tmp_buf += xbytes; | ||
| 261 | } | ||
| 262 | } | ||
| 263 | |||
| 264 | for (i = 0; i < tnfa->num_states; i++) | ||
| 265 | reach_pos[i].pos = -1; | ||
| 266 | |||
| 267 | GET_NEXT_WCHAR(); | ||
| 268 | pos = 0; | ||
| 269 | |||
| 270 | reach_next_i = reach_next; | ||
| 271 | while (1) | ||
| 272 | { | ||
| 273 | /* If no match found yet, add the initial states to `reach_next'. */ | ||
| 274 | if (match_eo < 0) | ||
| 275 | 	{ | ||
| 276 | 	 trans_i = tnfa->initial; | ||
| 277 | 	 while (trans_i->state != NULL) | ||
| 278 | 	 { | ||
| 279 | 	 if (reach_pos[trans_i->state_id].pos < pos) | ||
| 280 | 		{ | ||
| 281 | 		 if (trans_i->assertions | ||
| 282 | 		 && CHECK_ASSERTIONS(trans_i->assertions)) | ||
| 283 | 		 { | ||
| 284 | 		 trans_i++; | ||
| 285 | 		 continue; | ||
| 286 | 		 } | ||
| 287 | |||
| 288 | 		 reach_next_i->state = trans_i->state; | ||
| 289 | 		 for (i = 0; i < num_tags; i++) | ||
| 290 | 		 reach_next_i->tags[i] = -1; | ||
| 291 | 		 tag_i = trans_i->tags; | ||
| 292 | 		 if (tag_i) | ||
| 293 | 		 while (*tag_i >= 0) | ||
| 294 | 		 { | ||
| 295 | 			if (*tag_i < num_tags) | ||
| 296 | 			 reach_next_i->tags[*tag_i] = pos; | ||
| 297 | 			tag_i++; | ||
| 298 | 		 } | ||
| 299 | 		 if (reach_next_i->state == tnfa->final) | ||
| 300 | 		 { | ||
| 301 | 		 match_eo = pos; | ||
| 302 | 		 new_match = 1; | ||
| 303 | 		 for (i = 0; i < num_tags; i++) | ||
| 304 | 			match_tags[i] = reach_next_i->tags[i]; | ||
| 305 | 		 } | ||
| 306 | 		 reach_pos[trans_i->state_id].pos = pos; | ||
| 307 | 		 reach_pos[trans_i->state_id].tags = &reach_next_i->tags; | ||
| 308 | 		 reach_next_i++; | ||
| 309 | 		} | ||
| 310 | 	 trans_i++; | ||
| 311 | 	 } | ||
| 312 | 	 reach_next_i->state = NULL; | ||
| 313 | 	} | ||
| 314 | else | ||
| 315 | 	{ | ||
| 316 | 	 if (num_tags == 0 || reach_next_i == reach_next) | ||
| 317 | 	 /* We have found a match. */ | ||
| 318 | 	 break; | ||
| 319 | 	} | ||
| 320 | |||
| 321 | /* Check for end of string. */ | ||
| 322 | if (!next_c) break; | ||
| 323 | |||
| 324 | GET_NEXT_WCHAR(); | ||
| 325 | |||
| 326 | /* Swap `reach' and `reach_next'. */ | ||
| 327 | reach_i = reach; | ||
| 328 | reach = reach_next; | ||
| 329 | reach_next = reach_i; | ||
| 330 | |||
| 331 | /* For each state in `reach', weed out states that don't fulfill the | ||
| 332 | 	 minimal matching conditions. */ | ||
| 333 | if (tnfa->num_minimals && new_match) | ||
| 334 | 	{ | ||
| 335 | 	 new_match = 0; | ||
| 336 | 	 reach_next_i = reach_next; | ||
| 337 | 	 for (reach_i = reach; reach_i->state; reach_i++) | ||
| 338 | 	 { | ||
| 339 | 	 int skip = 0; | ||
| 340 | 	 for (i = 0; tnfa->minimal_tags[i] >= 0; i += 2) | ||
| 341 | 		{ | ||
| 342 | 		 int end = tnfa->minimal_tags[i]; | ||
| 343 | 		 int start = tnfa->minimal_tags[i + 1]; | ||
| 344 | 		 if (end >= num_tags) | ||
| 345 | 		 { | ||
| 346 | 		 skip = 1; | ||
| 347 | 		 break; | ||
| 348 | 		 } | ||
| 349 | 		 else if (reach_i->tags[start] == match_tags[start] | ||
| 350 | 			 && reach_i->tags[end] < match_tags[end]) | ||
| 351 | 		 { | ||
| 352 | 		 skip = 1; | ||
| 353 | 		 break; | ||
| 354 | 		 } | ||
| 355 | 		} | ||
| 356 | 	 if (!skip) | ||
| 357 | 		{ | ||
| 358 | 		 reach_next_i->state = reach_i->state; | ||
| 359 | 		 tmp_iptr = reach_next_i->tags; | ||
| 360 | 		 reach_next_i->tags = reach_i->tags; | ||
| 361 | 		 reach_i->tags = tmp_iptr; | ||
| 362 | 		 reach_next_i++; | ||
| 363 | 		} | ||
| 364 | 	 } | ||
| 365 | 	 reach_next_i->state = NULL; | ||
| 366 | |||
| 367 | 	 /* Swap `reach' and `reach_next'. */ | ||
| 368 | 	 reach_i = reach; | ||
| 369 | 	 reach = reach_next; | ||
| 370 | 	 reach_next = reach_i; | ||
| 371 | 	} | ||
| 372 | |||
| 373 | /* For each state in `reach' see if there is a transition leaving with | ||
| 374 | 	 the current input symbol to a state not yet in `reach_next', and | ||
| 375 | 	 add the destination states to `reach_next'. */ | ||
| 376 | reach_next_i = reach_next; | ||
| 377 | for (reach_i = reach; reach_i->state; reach_i++) | ||
| 378 | 	{ | ||
| 379 | 	 for (trans_i = reach_i->state; trans_i->state; trans_i++) | ||
| 380 | 	 { | ||
| 381 | 	 /* Does this transition match the input symbol? */ | ||
| 382 | 	 if (trans_i->code_min <= (tre_cint_t)prev_c && | ||
| 383 | 		 trans_i->code_max >= (tre_cint_t)prev_c) | ||
| 384 | 		{ | ||
| 385 | 		 if (trans_i->assertions | ||
| 386 | 		 && (CHECK_ASSERTIONS(trans_i->assertions) | ||
| 387 | 			 || CHECK_CHAR_CLASSES(trans_i, tnfa, eflags))) | ||
| 388 | 		 { | ||
| 389 | 		 continue; | ||
| 390 | 		 } | ||
| 391 | |||
| 392 | 		 /* Compute the tags after this transition. */ | ||
| 393 | 		 for (i = 0; i < num_tags; i++) | ||
| 394 | 		 tmp_tags[i] = reach_i->tags[i]; | ||
| 395 | 		 tag_i = trans_i->tags; | ||
| 396 | 		 if (tag_i != NULL) | ||
| 397 | 		 while (*tag_i >= 0) | ||
| 398 | 		 { | ||
| 399 | 			if (*tag_i < num_tags) | ||
| 400 | 			 tmp_tags[*tag_i] = pos; | ||
| 401 | 			tag_i++; | ||
| 402 | 		 } | ||
| 403 | |||
| 404 | 		 if (reach_pos[trans_i->state_id].pos < pos) | ||
| 405 | 		 { | ||
| 406 | 		 /* Found an unvisited node. */ | ||
| 407 | 		 reach_next_i->state = trans_i->state; | ||
| 408 | 		 tmp_iptr = reach_next_i->tags; | ||
| 409 | 		 reach_next_i->tags = tmp_tags; | ||
| 410 | 		 tmp_tags = tmp_iptr; | ||
| 411 | 		 reach_pos[trans_i->state_id].pos = pos; | ||
| 412 | 		 reach_pos[trans_i->state_id].tags = &reach_next_i->tags; | ||
| 413 | |||
| 414 | 		 if (reach_next_i->state == tnfa->final | ||
| 415 | 			 && (match_eo == -1 | ||
| 416 | 			 || (num_tags > 0 | ||
| 417 | 				 && reach_next_i->tags[0] <= match_tags[0]))) | ||
| 418 | 			{ | ||
| 419 | 			 match_eo = pos; | ||
| 420 | 			 new_match = 1; | ||
| 421 | 			 for (i = 0; i < num_tags; i++) | ||
| 422 | 			 match_tags[i] = reach_next_i->tags[i]; | ||
| 423 | 			} | ||
| 424 | 		 reach_next_i++; | ||
| 425 | |||
| 426 | 		 } | ||
| 427 | 		 else | ||
| 428 | 		 { | ||
| 429 | 		 assert(reach_pos[trans_i->state_id].pos == pos); | ||
| 430 | 		 /* Another path has also reached this state. We choose | ||
| 431 | 			 the winner by examining the tag values for both | ||
| 432 | 			 paths. */ | ||
| 433 | 		 if (tre_tag_order(num_tags, tnfa->tag_directions, | ||
| 434 | 					tmp_tags, | ||
| 435 | 					*reach_pos[trans_i->state_id].tags)) | ||
| 436 | 			{ | ||
| 437 | 			 /* The new path wins. */ | ||
| 438 | 			 tmp_iptr = *reach_pos[trans_i->state_id].tags; | ||
| 439 | 			 *reach_pos[trans_i->state_id].tags = tmp_tags; | ||
| 440 | 			 if (trans_i->state == tnfa->final) | ||
| 441 | 			 { | ||
| 442 | 			 match_eo = pos; | ||
| 443 | 			 new_match = 1; | ||
| 444 | 			 for (i = 0; i < num_tags; i++) | ||
| 445 | 				match_tags[i] = tmp_tags[i]; | ||
| 446 | 			 } | ||
| 447 | 			 tmp_tags = tmp_iptr; | ||
| 448 | 			} | ||
| 449 | 		 } | ||
| 450 | 		} | ||
| 451 | 	 } | ||
| 452 | 	} | ||
| 453 | reach_next_i->state = NULL; | ||
| 454 | } | ||
| 455 | |||
| 456 | *match_end_ofs = match_eo; | ||
| 457 | ret = match_eo >= 0 ? REG_OK : REG_NOMATCH; | ||
| 458 | error_exit: | ||
| 459 | xfree(buf); | ||
| 460 | return ret; | ||
| 461 | } | ||
| 462 | |||
| 463 | |||
| 464 | |||
| 465 | /*********************************************************************** | ||
| 466 | from tre-match-backtrack.c | ||
| 467 | ***********************************************************************/ | ||
| 468 | |||
| 469 | /* | ||
| 470 | This matcher is for regexps that use back referencing. Regexp matching | ||
| 471 | with back referencing is an NP-complete problem on the number of back | ||
| 472 | references. The easiest way to match them is to use a backtracking | ||
| 473 | routine which basically goes through all possible paths in the TNFA | ||
| 474 | and chooses the one which results in the best (leftmost and longest) | ||
| 475 | match. This can be spectacularly expensive and may run out of stack | ||
| 476 | space, but there really is no better known generic algorithm.	 Quoting | ||
| 477 | Henry Spencer from comp.compilers: | ||
| 478 | <URL: http://compilers.iecc.com/comparch/article/93-03-102> | ||
| 479 | |||
| 480 | POSIX.2 REs require longest match, which is really exciting to | ||
| 481 | implement since the obsolete ("basic") variant also includes | ||
| 482 | \<digit>. I haven't found a better way of tackling this than doing | ||
| 483 | a preliminary match using a DFA (or simulation) on a modified RE | ||
| 484 | that just replicates subREs for \<digit>, and then doing a | ||
| 485 | backtracking match to determine whether the subRE matches were | ||
| 486 | right. This can be rather slow, but I console myself with the | ||
| 487 | thought that people who use \<digit> deserve very slow execution. | ||
| 488 | (Pun unintentional but very appropriate.) | ||
| 489 | |||
| 490 | */ | ||
| 491 | |||
| 492 | typedef struct { | ||
| 493 | regoff_t pos; | ||
| 494 | const char *str_byte; | ||
| 495 | tre_tnfa_transition_t *state; | ||
| 496 | int state_id; | ||
| 497 | int next_c; | ||
| 498 | regoff_t *tags; | ||
| 499 | #ifdef TRE_MBSTATE | ||
| 500 | mbstate_t mbstate; | ||
| 501 | #endif /* TRE_MBSTATE */ | ||
| 502 | } tre_backtrack_item_t; | ||
| 503 | |||
| 504 | typedef struct tre_backtrack_struct { | ||
| 505 | tre_backtrack_item_t item; | ||
| 506 | struct tre_backtrack_struct *prev; | ||
| 507 | struct tre_backtrack_struct *next; | ||
| 508 | } *tre_backtrack_t; | ||
| 509 | |||
| 510 | #ifdef TRE_MBSTATE | ||
| 511 | #define BT_STACK_MBSTATE_IN stack->item.mbstate = (mbstate) | ||
| 512 | #define BT_STACK_MBSTATE_OUT (mbstate) = stack->item.mbstate | ||
| 513 | #else /* !TRE_MBSTATE */ | ||
| 514 | #define BT_STACK_MBSTATE_IN | ||
| 515 | #define BT_STACK_MBSTATE_OUT | ||
| 516 | #endif /* !TRE_MBSTATE */ | ||
| 517 | |||
| 518 | #define tre_bt_mem_new		 tre_mem_new | ||
| 519 | #define tre_bt_mem_alloc	 tre_mem_alloc | ||
| 520 | #define tre_bt_mem_destroy	 tre_mem_destroy | ||
| 521 | |||
| 522 | |||
| 523 | #define BT_STACK_PUSH(_pos, _str_byte, _str_wide, _state, _state_id, _next_c, _tags, _mbstate) \ | ||
| 524 | do									 \ | ||
| 525 | {									 \ | ||
| 526 | int i;								 \ | ||
| 527 | if (!stack->next)							 \ | ||
| 528 | 	{								 \ | ||
| 529 | 	 tre_backtrack_t s;						 \ | ||
| 530 | 	 s = tre_bt_mem_alloc(mem, sizeof(*s));			 \ | ||
| 531 | 	 if (!s)							 \ | ||
| 532 | 	 {								 \ | ||
| 533 | 	 tre_bt_mem_destroy(mem);					 \ | ||
| 534 | 	 if (tags)							 \ | ||
| 535 | 		xfree(tags);						 \ | ||
| 536 | 	 if (pmatch)						 \ | ||
| 537 | 		xfree(pmatch);						 \ | ||
| 538 | 	 if (states_seen)						 \ | ||
| 539 | 		xfree(states_seen);					 \ | ||
| 540 | 	 return REG_ESPACE;					 \ | ||
| 541 | 	 }								 \ | ||
| 542 | 	 s->prev = stack;						 \ | ||
| 543 | 	 s->next = NULL;						 \ | ||
| 544 | 	 s->item.tags = tre_bt_mem_alloc(mem,				 \ | ||
| 545 | 					 sizeof(*tags) * tnfa->num_tags); \ | ||
| 546 | 	 if (!s->item.tags)						 \ | ||
| 547 | 	 {								 \ | ||
| 548 | 	 tre_bt_mem_destroy(mem);					 \ | ||
| 549 | 	 if (tags)							 \ | ||
| 550 | 		xfree(tags);						 \ | ||
| 551 | 	 if (pmatch)						 \ | ||
| 552 | 		xfree(pmatch);						 \ | ||
| 553 | 	 if (states_seen)						 \ | ||
| 554 | 		xfree(states_seen);					 \ | ||
| 555 | 	 return REG_ESPACE;					 \ | ||
| 556 | 	 }								 \ | ||
| 557 | 	 stack->next = s;						 \ | ||
| 558 | 	 stack = s;							 \ | ||
| 559 | 	}								 \ | ||
| 560 | else								 \ | ||
| 561 | 	stack = stack->next;						 \ | ||
| 562 | stack->item.pos = (_pos);						 \ | ||
| 563 | stack->item.str_byte = (_str_byte);				 \ | ||
| 564 | stack->item.state = (_state);					 \ | ||
| 565 | stack->item.state_id = (_state_id);				 \ | ||
| 566 | stack->item.next_c = (_next_c);					 \ | ||
| 567 | for (i = 0; i < tnfa->num_tags; i++)				 \ | ||
| 568 | 	stack->item.tags[i] = (_tags)[i];				 \ | ||
| 569 | BT_STACK_MBSTATE_IN;						 \ | ||
| 570 | }									 \ | ||
| 571 | while (0) | ||
| 572 | |||
| 573 | #define BT_STACK_POP()							 \ | ||
| 574 | do									 \ | ||
| 575 | {									 \ | ||
| 576 | int i;								 \ | ||
| 577 | assert(stack->prev);						 \ | ||
| 578 | pos = stack->item.pos;						 \ | ||
| 579 | str_byte = stack->item.str_byte;					 \ | ||
| 580 | state = stack->item.state;					 \ | ||
| 581 | next_c = stack->item.next_c;					 \ | ||
| 582 | for (i = 0; i < tnfa->num_tags; i++)				 \ | ||
| 583 | 	tags[i] = stack->item.tags[i];					 \ | ||
| 584 | BT_STACK_MBSTATE_OUT;						 \ | ||
| 585 | stack = stack->prev;						 \ | ||
| 586 | }									 \ | ||
| 587 | while (0) | ||
| 588 | |||
| 589 | #undef MIN | ||
| 590 | #define MIN(a, b) ((a) <= (b) ? (a) : (b)) | ||
| 591 | |||
| 592 | static reg_errcode_t | ||
| 593 | tre_tnfa_run_backtrack(const tre_tnfa_t *tnfa, const void *string, | ||
| 594 | 		 regoff_t *match_tags, int eflags, regoff_t *match_end_ofs) | ||
| 595 | { | ||
| 596 | /* State variables required by GET_NEXT_WCHAR. */ | ||
| 597 | tre_char_t prev_c = 0, next_c = 0; | ||
| 598 | const char *str_byte = string; | ||
| 599 | regoff_t pos = 0; | ||
| 600 | regoff_t pos_add_next = 1; | ||
| 601 | #ifdef TRE_MBSTATE | ||
| 602 | mbstate_t mbstate; | ||
| 603 | #endif /* TRE_MBSTATE */ | ||
| 604 | int reg_notbol = eflags & REG_NOTBOL; | ||
| 605 | int reg_noteol = eflags & REG_NOTEOL; | ||
| 606 | int reg_newline = tnfa->cflags & REG_NEWLINE; | ||
| 607 | |||
| 608 | /* These are used to remember the necessary values of the above | ||
| 609 | variables to return to the position where the current search | ||
| 610 | started from. */ | ||
| 611 | int next_c_start; | ||
| 612 | const char *str_byte_start; | ||
| 613 | regoff_t pos_start = -1; | ||
| 614 | #ifdef TRE_MBSTATE | ||
| 615 | mbstate_t mbstate_start; | ||
| 616 | #endif /* TRE_MBSTATE */ | ||
| 617 | |||
| 618 | /* End offset of best match so far, or -1 if no match found yet. */ | ||
| 619 | regoff_t match_eo = -1; | ||
| 620 | /* Tag arrays. */ | ||
| 621 | int *next_tags; | ||
| 622 | regoff_t *tags = NULL; | ||
| 623 | /* Current TNFA state. */ | ||
| 624 | tre_tnfa_transition_t *state; | ||
| 625 | int *states_seen = NULL; | ||
| 626 | |||
| 627 | /* Memory allocator to for allocating the backtracking stack. */ | ||
| 628 | tre_mem_t mem = tre_bt_mem_new(); | ||
| 629 | |||
| 630 | /* The backtracking stack. */ | ||
| 631 | tre_backtrack_t stack; | ||
| 632 | |||
| 633 | tre_tnfa_transition_t *trans_i; | ||
| 634 | regmatch_t *pmatch = NULL; | ||
| 635 | int ret; | ||
| 636 | |||
| 637 | #ifdef TRE_MBSTATE | ||
| 638 | memset(&mbstate, '\0', sizeof(mbstate)); | ||
| 639 | #endif /* TRE_MBSTATE */ | ||
| 640 | |||
| 641 | if (!mem) | ||
| 642 | return REG_ESPACE; | ||
| 643 | stack = tre_bt_mem_alloc(mem, sizeof(*stack)); | ||
| 644 | if (!stack) | ||
| 645 | { | ||
| 646 | ret = REG_ESPACE; | ||
| 647 | goto error_exit; | ||
| 648 | } | ||
| 649 | stack->prev = NULL; | ||
| 650 | stack->next = NULL; | ||
| 651 | |||
| 652 | if (tnfa->num_tags) | ||
| 653 | { | ||
| 654 | tags = xmalloc(sizeof(*tags) * tnfa->num_tags); | ||
| 655 | if (!tags) | ||
| 656 | 	{ | ||
| 657 | 	 ret = REG_ESPACE; | ||
| 658 | 	 goto error_exit; | ||
| 659 | 	} | ||
| 660 | } | ||
| 661 | if (tnfa->num_submatches) | ||
| 662 | { | ||
| 663 | pmatch = xmalloc(sizeof(*pmatch) * tnfa->num_submatches); | ||
| 664 | if (!pmatch) | ||
| 665 | 	{ | ||
| 666 | 	 ret = REG_ESPACE; | ||
| 667 | 	 goto error_exit; | ||
| 668 | 	} | ||
| 669 | } | ||
| 670 | if (tnfa->num_states) | ||
| 671 | { | ||
| 672 | states_seen = xmalloc(sizeof(*states_seen) * tnfa->num_states); | ||
| 673 | if (!states_seen) | ||
| 674 | 	{ | ||
| 675 | 	 ret = REG_ESPACE; | ||
| 676 | 	 goto error_exit; | ||
| 677 | 	} | ||
| 678 | } | ||
| 679 | |||
| 680 | retry: | ||
| 681 | { | ||
| 682 | int i; | ||
| 683 | for (i = 0; i < tnfa->num_tags; i++) | ||
| 684 | { | ||
| 685 | 	tags[i] = -1; | ||
| 686 | 	if (match_tags) | ||
| 687 | 	 match_tags[i] = -1; | ||
| 688 | } | ||
| 689 | for (i = 0; i < tnfa->num_states; i++) | ||
| 690 | states_seen[i] = 0; | ||
| 691 | } | ||
| 692 | |||
| 693 | state = NULL; | ||
| 694 | pos = pos_start; | ||
| 695 | GET_NEXT_WCHAR(); | ||
| 696 | pos_start = pos; | ||
| 697 | next_c_start = next_c; | ||
| 698 | str_byte_start = str_byte; | ||
| 699 | #ifdef TRE_MBSTATE | ||
| 700 | mbstate_start = mbstate; | ||
| 701 | #endif /* TRE_MBSTATE */ | ||
| 702 | |||
| 703 | /* Handle initial states. */ | ||
| 704 | next_tags = NULL; | ||
| 705 | for (trans_i = tnfa->initial; trans_i->state; trans_i++) | ||
| 706 | { | ||
| 707 | if (trans_i->assertions && CHECK_ASSERTIONS(trans_i->assertions)) | ||
| 708 | 	{ | ||
| 709 | 	 continue; | ||
| 710 | 	} | ||
| 711 | if (state == NULL) | ||
| 712 | 	{ | ||
| 713 | 	 /* Start from this state. */ | ||
| 714 | 	 state = trans_i->state; | ||
| 715 | 	 next_tags = trans_i->tags; | ||
| 716 | 	} | ||
| 717 | else | ||
| 718 | 	{ | ||
| 719 | 	 /* Backtrack to this state. */ | ||
| 720 | 	 BT_STACK_PUSH(pos, str_byte, 0, trans_i->state, | ||
| 721 | 			trans_i->state_id, next_c, tags, mbstate); | ||
| 722 | 	 { | ||
| 723 | 	 int *tmp = trans_i->tags; | ||
| 724 | 	 if (tmp) | ||
| 725 | 	 while (*tmp >= 0) | ||
| 726 | 		stack->item.tags[*tmp++] = pos; | ||
| 727 | 	 } | ||
| 728 | 	} | ||
| 729 | } | ||
| 730 | |||
| 731 | if (next_tags) | ||
| 732 | for (; *next_tags >= 0; next_tags++) | ||
| 733 | tags[*next_tags] = pos; | ||
| 734 | |||
| 735 | |||
| 736 | if (state == NULL) | ||
| 737 | goto backtrack; | ||
| 738 | |||
| 739 | while (1) | ||
| 740 | { | ||
| 741 | tre_tnfa_transition_t *next_state; | ||
| 742 | int empty_br_match; | ||
| 743 | |||
| 744 | if (state == tnfa->final) | ||
| 745 | 	{ | ||
| 746 | 	 if (match_eo < pos | ||
| 747 | 	 || (match_eo == pos | ||
| 748 | 		 && match_tags | ||
| 749 | 		 && tre_tag_order(tnfa->num_tags, tnfa->tag_directions, | ||
| 750 | 				 tags, match_tags))) | ||
| 751 | 	 { | ||
| 752 | 	 int i; | ||
| 753 | 	 /* This match wins the previous match. */ | ||
| 754 | 	 match_eo = pos; | ||
| 755 | 	 if (match_tags) | ||
| 756 | 		for (i = 0; i < tnfa->num_tags; i++) | ||
| 757 | 		 match_tags[i] = tags[i]; | ||
| 758 | 	 } | ||
| 759 | 	 /* Our TNFAs never have transitions leaving from the final state, | ||
| 760 | 	 so we jump right to backtracking. */ | ||
| 761 | 	 goto backtrack; | ||
| 762 | 	} | ||
| 763 | |||
| 764 | /* Go to the next character in the input string. */ | ||
| 765 | empty_br_match = 0; | ||
| 766 | trans_i = state; | ||
| 767 | if (trans_i->state && trans_i->assertions & ASSERT_BACKREF) | ||
| 768 | 	{ | ||
| 769 | 	 /* This is a back reference state. All transitions leaving from | ||
| 770 | 	 this state have the same back reference "assertion". Instead | ||
| 771 | 	 of reading the next character, we match the back reference. */ | ||
| 772 | 	 regoff_t so, eo; | ||
| 773 | 	 int bt = trans_i->u.backref; | ||
| 774 | 	 regoff_t bt_len; | ||
| 775 | 	 int result; | ||
| 776 | |||
| 777 | 	 /* Get the substring we need to match against. Remember to | ||
| 778 | 	 turn off REG_NOSUB temporarily. */ | ||
| 779 | 	 tre_fill_pmatch(bt + 1, pmatch, tnfa->cflags & ~REG_NOSUB, | ||
| 780 | 			 tnfa, tags, pos); | ||
| 781 | 	 so = pmatch[bt].rm_so; | ||
| 782 | 	 eo = pmatch[bt].rm_eo; | ||
| 783 | 	 bt_len = eo - so; | ||
| 784 | |||
| 785 | 	 result = strncmp((const char*)string + so, str_byte - 1, | ||
| 786 | 				 (size_t)bt_len); | ||
| 787 | |||
| 788 | 	 if (result == 0) | ||
| 789 | 	 { | ||
| 790 | 	 /* Back reference matched. Check for infinite loop. */ | ||
| 791 | 	 if (bt_len == 0) | ||
| 792 | 		empty_br_match = 1; | ||
| 793 | 	 if (empty_br_match && states_seen[trans_i->state_id]) | ||
| 794 | 		{ | ||
| 795 | 		 goto backtrack; | ||
| 796 | 		} | ||
| 797 | |||
| 798 | 	 states_seen[trans_i->state_id] = empty_br_match; | ||
| 799 | |||
| 800 | 	 /* Advance in input string and resync `prev_c', `next_c' | ||
| 801 | 		 and pos. */ | ||
| 802 | 	 str_byte += bt_len - 1; | ||
| 803 | 	 pos += bt_len - 1; | ||
| 804 | 	 GET_NEXT_WCHAR(); | ||
| 805 | 	 } | ||
| 806 | 	 else | ||
| 807 | 	 { | ||
| 808 | 	 goto backtrack; | ||
| 809 | 	 } | ||
| 810 | 	} | ||
| 811 | else | ||
| 812 | 	{ | ||
| 813 | 	 /* Check for end of string. */ | ||
| 814 | 	 if (next_c == L'\0') | ||
| 815 | 		goto backtrack; | ||
| 816 | |||
| 817 | 	 /* Read the next character. */ | ||
| 818 | 	 GET_NEXT_WCHAR(); | ||
| 819 | 	} | ||
| 820 | |||
| 821 | next_state = NULL; | ||
| 822 | for (trans_i = state; trans_i->state; trans_i++) | ||
| 823 | 	{ | ||
| 824 | 	 if (trans_i->code_min <= (tre_cint_t)prev_c | ||
| 825 | 	 && trans_i->code_max >= (tre_cint_t)prev_c) | ||
| 826 | 	 { | ||
| 827 | 	 if (trans_i->assertions | ||
| 828 | 		 && (CHECK_ASSERTIONS(trans_i->assertions) | ||
| 829 | 		 || CHECK_CHAR_CLASSES(trans_i, tnfa, eflags))) | ||
| 830 | 		{ | ||
| 831 | 		 continue; | ||
| 832 | 		} | ||
| 833 | |||
| 834 | 	 if (next_state == NULL) | ||
| 835 | 		{ | ||
| 836 | 		 /* First matching transition. */ | ||
| 837 | 		 next_state = trans_i->state; | ||
| 838 | 		 next_tags = trans_i->tags; | ||
| 839 | 		} | ||
| 840 | 	 else | ||
| 841 | 		{ | ||
| 842 | 		 /* Second matching transition. We may need to backtrack here | ||
| 843 | 		 to take this transition instead of the first one, so we | ||
| 844 | 		 push this transition in the backtracking stack so we can | ||
| 845 | 		 jump back here if needed. */ | ||
| 846 | 		 BT_STACK_PUSH(pos, str_byte, 0, trans_i->state, | ||
| 847 | 				trans_i->state_id, next_c, tags, mbstate); | ||
| 848 | 		 { | ||
| 849 | 		 int *tmp; | ||
| 850 | 		 for (tmp = trans_i->tags; tmp && *tmp >= 0; tmp++) | ||
| 851 | 		 stack->item.tags[*tmp] = pos; | ||
| 852 | 		 } | ||
| 853 | #if 0 /* XXX - it's important not to look at all transitions here to keep | ||
| 854 | 	 the stack small! */ | ||
| 855 | 		 break; | ||
| 856 | #endif | ||
| 857 | 		} | ||
| 858 | 	 } | ||
| 859 | 	} | ||
| 860 | |||
| 861 | if (next_state != NULL) | ||
| 862 | 	{ | ||
| 863 | 	 /* Matching transitions were found. Take the first one. */ | ||
| 864 | 	 state = next_state; | ||
| 865 | |||
| 866 | 	 /* Update the tag values. */ | ||
| 867 | 	 if (next_tags) | ||
| 868 | 	 while (*next_tags >= 0) | ||
| 869 | 	 tags[*next_tags++] = pos; | ||
| 870 | 	} | ||
| 871 | else | ||
| 872 | 	{ | ||
| 873 | 	backtrack: | ||
| 874 | 	 /* A matching transition was not found. Try to backtrack. */ | ||
| 875 | 	 if (stack->prev) | ||
| 876 | 	 { | ||
| 877 | 	 if (stack->item.state->assertions & ASSERT_BACKREF) | ||
| 878 | 		{ | ||
| 879 | 		 states_seen[stack->item.state_id] = 0; | ||
| 880 | 		} | ||
| 881 | |||
| 882 | 	 BT_STACK_POP(); | ||
| 883 | 	 } | ||
| 884 | 	 else if (match_eo < 0) | ||
| 885 | 	 { | ||
| 886 | 	 /* Try starting from a later position in the input string. */ | ||
| 887 | 	 /* Check for end of string. */ | ||
| 888 | 	 if (next_c == L'\0') | ||
| 889 | 		 { | ||
| 890 | 		 break; | ||
| 891 | 		 } | ||
| 892 | 	 next_c = next_c_start; | ||
| 893 | #ifdef TRE_MBSTATE | ||
| 894 | 	 mbstate = mbstate_start; | ||
| 895 | #endif /* TRE_MBSTATE */ | ||
| 896 | 	 str_byte = str_byte_start; | ||
| 897 | 	 goto retry; | ||
| 898 | 	 } | ||
| 899 | 	 else | ||
| 900 | 	 { | ||
| 901 | 	 break; | ||
| 902 | 	 } | ||
| 903 | 	} | ||
| 904 | } | ||
| 905 | |||
| 906 | ret = match_eo >= 0 ? REG_OK : REG_NOMATCH; | ||
| 907 | *match_end_ofs = match_eo; | ||
| 908 | |||
| 909 | error_exit: | ||
| 910 | tre_bt_mem_destroy(mem); | ||
| 911 | #ifndef TRE_USE_ALLOCA | ||
| 912 | if (tags) | ||
| 913 | xfree(tags); | ||
| 914 | if (pmatch) | ||
| 915 | xfree(pmatch); | ||
| 916 | if (states_seen) | ||
| 917 | xfree(states_seen); | ||
| 918 | #endif /* !TRE_USE_ALLOCA */ | ||
| 919 | |||
| 920 | return ret; | ||
| 921 | } | ||
| 922 | |||
| 923 | /*********************************************************************** | ||
| 924 | from regexec.c | ||
| 925 | ***********************************************************************/ | ||
| 926 | |||
| 927 | /* Fills the POSIX.2 regmatch_t array according to the TNFA tag and match | ||
| 928 | endpoint values. */ | ||
| 929 | static void | ||
| 930 | tre_fill_pmatch(size_t nmatch, regmatch_t pmatch[], int cflags, | ||
| 931 | 		const tre_tnfa_t *tnfa, regoff_t *tags, regoff_t match_eo) | ||
| 932 | { | ||
| 933 | tre_submatch_data_t *submatch_data; | ||
| 934 | unsigned int i, j; | ||
| 935 | int *parents; | ||
| 936 | |||
| 937 | i = 0; | ||
| 938 | if (match_eo >= 0 && !(cflags & REG_NOSUB)) | ||
| 939 | { | ||
| 940 | /* Construct submatch offsets from the tags. */ | ||
| 941 | submatch_data = tnfa->submatch_data; | ||
| 942 | while (i < tnfa->num_submatches && i < nmatch) | ||
| 943 | 	{ | ||
| 944 | 	 if (submatch_data[i].so_tag == tnfa->end_tag) | ||
| 945 | 	 pmatch[i].rm_so = match_eo; | ||
| 946 | 	 else | ||
| 947 | 	 pmatch[i].rm_so = tags[submatch_data[i].so_tag]; | ||
| 948 | |||
| 949 | 	 if (submatch_data[i].eo_tag == tnfa->end_tag) | ||
| 950 | 	 pmatch[i].rm_eo = match_eo; | ||
| 951 | 	 else | ||
| 952 | 	 pmatch[i].rm_eo = tags[submatch_data[i].eo_tag]; | ||
| 953 | |||
| 954 | 	 /* If either of the endpoints were not used, this submatch | ||
| 955 | 	 was not part of the match. */ | ||
| 956 | 	 if (pmatch[i].rm_so == -1 || pmatch[i].rm_eo == -1) | ||
| 957 | 	 pmatch[i].rm_so = pmatch[i].rm_eo = -1; | ||
| 958 | |||
| 959 | 	 i++; | ||
| 960 | 	} | ||
| 961 | /* Reset all submatches that are not within all of their parent | ||
| 962 | 	 submatches. */ | ||
| 963 | i = 0; | ||
| 964 | while (i < tnfa->num_submatches && i < nmatch) | ||
| 965 | 	{ | ||
| 966 | 	 if (pmatch[i].rm_eo == -1) | ||
| 967 | 	 assert(pmatch[i].rm_so == -1); | ||
| 968 | 	 assert(pmatch[i].rm_so <= pmatch[i].rm_eo); | ||
| 969 | |||
| 970 | 	 parents = submatch_data[i].parents; | ||
| 971 | 	 if (parents != NULL) | ||
| 972 | 	 for (j = 0; parents[j] >= 0; j++) | ||
| 973 | 	 { | ||
| 974 | 		if (pmatch[i].rm_so < pmatch[parents[j]].rm_so | ||
| 975 | 		 || pmatch[i].rm_eo > pmatch[parents[j]].rm_eo) | ||
| 976 | 		 pmatch[i].rm_so = pmatch[i].rm_eo = -1; | ||
| 977 | 	 } | ||
| 978 | 	 i++; | ||
| 979 | 	} | ||
| 980 | } | ||
| 981 | |||
| 982 | while (i < nmatch) | ||
| 983 | { | ||
| 984 | pmatch[i].rm_so = -1; | ||
| 985 | pmatch[i].rm_eo = -1; | ||
| 986 | i++; | ||
| 987 | } | ||
| 988 | } | ||
| 989 | |||
| 990 | |||
| 991 | /* | ||
| 992 | Wrapper functions for POSIX compatible regexp matching. | ||
| 993 | */ | ||
| 994 | |||
| 995 | int | ||
| 996 | regexec(const regex_t *restrict preg, const char *restrict string, | ||
| 997 | 	 size_t nmatch, regmatch_t pmatch[restrict], int eflags) | ||
| 998 | { | ||
| 999 | tre_tnfa_t *tnfa = (void *)preg->TRE_REGEX_T_FIELD; | ||
| 1000 | reg_errcode_t status; | ||
| 1001 | regoff_t *tags = NULL, eo; | ||
| 1002 | if (tnfa->cflags & REG_NOSUB) nmatch = 0; | ||
| 1003 | if (tnfa->num_tags > 0 && nmatch > 0) | ||
| 1004 | { | ||
| 1005 | tags = xmalloc(sizeof(*tags) * tnfa->num_tags); | ||
| 1006 | if (tags == NULL) | ||
| 1007 | 	return REG_ESPACE; | ||
| 1008 | } | ||
| 1009 | |||
| 1010 | /* Dispatch to the appropriate matcher. */ | ||
| 1011 | if (tnfa->have_backrefs) | ||
| 1012 | { | ||
| 1013 | /* The regex has back references, use the backtracking matcher. */ | ||
| 1014 | status = tre_tnfa_run_backtrack(tnfa, string, tags, eflags, &eo); | ||
| 1015 | } | ||
| 1016 | else | ||
| 1017 | { | ||
| 1018 | /* Exact matching, no back references, use the parallel matcher. */ | ||
| 1019 | status = tre_tnfa_run_parallel(tnfa, string, tags, eflags, &eo); | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | if (status == REG_OK) | ||
| 1023 | /* A match was found, so fill the submatch registers. */ | ||
| 1024 | tre_fill_pmatch(nmatch, pmatch, tnfa->cflags, tnfa, tags, eo); | ||
| 1025 | if (tags) | ||
| 1026 | xfree(tags); | ||
| 1027 | return status; | ||
| 1028 | } | ||
lib/libc/wasi/libc-top-half/musl/src/regex/tre-mem.c deleted-158| ... | @@ -1,158 +0,0 @@ | ||
| 1 | /* | ||
| 2 | tre-mem.c - TRE memory allocator | ||
| 3 | |||
| 4 | Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi> | ||
| 5 | All rights reserved. | ||
| 6 | |||
| 7 | Redistribution and use in source and binary forms, with or without | ||
| 8 | modification, are permitted provided that the following conditions | ||
| 9 | are met: | ||
| 10 | |||
| 11 | 1. Redistributions of source code must retain the above copyright | ||
| 12 | notice, this list of conditions and the following disclaimer. | ||
| 13 | |||
| 14 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | notice, this list of conditions and the following disclaimer in the | ||
| 16 | documentation and/or other materials provided with the distribution. | ||
| 17 | |||
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS | ||
| 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | */ | ||
| 31 | |||
| 32 | /* | ||
| 33 | This memory allocator is for allocating small memory blocks efficiently | ||
| 34 | in terms of memory overhead and execution speed. The allocated blocks | ||
| 35 | cannot be freed individually, only all at once. There can be multiple | ||
| 36 | allocators, though. | ||
| 37 | */ | ||
| 38 | |||
| 39 | #include <stdlib.h> | ||
| 40 | #include <string.h> | ||
| 41 | |||
| 42 | #include "tre.h" | ||
| 43 | |||
| 44 | /* | ||
| 45 | This memory allocator is for allocating small memory blocks efficiently | ||
| 46 | in terms of memory overhead and execution speed. The allocated blocks | ||
| 47 | cannot be freed individually, only all at once. There can be multiple | ||
| 48 | allocators, though. | ||
| 49 | */ | ||
| 50 | |||
| 51 | /* Returns a new memory allocator or NULL if out of memory. */ | ||
| 52 | tre_mem_t | ||
| 53 | tre_mem_new_impl(int provided, void *provided_block) | ||
| 54 | { | ||
| 55 | tre_mem_t mem; | ||
| 56 | if (provided) | ||
| 57 | { | ||
| 58 | mem = provided_block; | ||
| 59 | memset(mem, 0, sizeof(*mem)); | ||
| 60 | } | ||
| 61 | else | ||
| 62 | mem = xcalloc(1, sizeof(*mem)); | ||
| 63 | if (mem == NULL) | ||
| 64 | return NULL; | ||
| 65 | return mem; | ||
| 66 | } | ||
| 67 | |||
| 68 | |||
| 69 | /* Frees the memory allocator and all memory allocated with it. */ | ||
| 70 | void | ||
| 71 | tre_mem_destroy(tre_mem_t mem) | ||
| 72 | { | ||
| 73 | tre_list_t *tmp, *l = mem->blocks; | ||
| 74 | |||
| 75 | while (l != NULL) | ||
| 76 | { | ||
| 77 | xfree(l->data); | ||
| 78 | tmp = l->next; | ||
| 79 | xfree(l); | ||
| 80 | l = tmp; | ||
| 81 | } | ||
| 82 | xfree(mem); | ||
| 83 | } | ||
| 84 | |||
| 85 | |||
| 86 | /* Allocates a block of `size' bytes from `mem'. Returns a pointer to the | ||
| 87 | allocated block or NULL if an underlying malloc() failed. */ | ||
| 88 | void * | ||
| 89 | tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, | ||
| 90 | 		 int zero, size_t size) | ||
| 91 | { | ||
| 92 | void *ptr; | ||
| 93 | |||
| 94 | if (mem->failed) | ||
| 95 | { | ||
| 96 | return NULL; | ||
| 97 | } | ||
| 98 | |||
| 99 | if (mem->n < size) | ||
| 100 | { | ||
| 101 | /* We need more memory than is available in the current block. | ||
| 102 | 	 Allocate a new block. */ | ||
| 103 | tre_list_t *l; | ||
| 104 | if (provided) | ||
| 105 | 	{ | ||
| 106 | 	 if (provided_block == NULL) | ||
| 107 | 	 { | ||
| 108 | 	 mem->failed = 1; | ||
| 109 | 	 return NULL; | ||
| 110 | 	 } | ||
| 111 | 	 mem->ptr = provided_block; | ||
| 112 | 	 mem->n = TRE_MEM_BLOCK_SIZE; | ||
| 113 | 	} | ||
| 114 | else | ||
| 115 | 	{ | ||
| 116 | 	 int block_size; | ||
| 117 | 	 if (size * 8 > TRE_MEM_BLOCK_SIZE) | ||
| 118 | 	 block_size = size * 8; | ||
| 119 | 	 else | ||
| 120 | 	 block_size = TRE_MEM_BLOCK_SIZE; | ||
| 121 | 	 l = xmalloc(sizeof(*l)); | ||
| 122 | 	 if (l == NULL) | ||
| 123 | 	 { | ||
| 124 | 	 mem->failed = 1; | ||
| 125 | 	 return NULL; | ||
| 126 | 	 } | ||
| 127 | 	 l->data = xmalloc(block_size); | ||
| 128 | 	 if (l->data == NULL) | ||
| 129 | 	 { | ||
| 130 | 	 xfree(l); | ||
| 131 | 	 mem->failed = 1; | ||
| 132 | 	 return NULL; | ||
| 133 | 	 } | ||
| 134 | 	 l->next = NULL; | ||
| 135 | 	 if (mem->current != NULL) | ||
| 136 | 	 mem->current->next = l; | ||
| 137 | 	 if (mem->blocks == NULL) | ||
| 138 | 	 mem->blocks = l; | ||
| 139 | 	 mem->current = l; | ||
| 140 | 	 mem->ptr = l->data; | ||
| 141 | 	 mem->n = block_size; | ||
| 142 | 	} | ||
| 143 | } | ||
| 144 | |||
| 145 | /* Make sure the next pointer will be aligned. */ | ||
| 146 | size += ALIGN(mem->ptr + size, long); | ||
| 147 | |||
| 148 | /* Allocate from current block. */ | ||
| 149 | ptr = mem->ptr; | ||
| 150 | mem->ptr += size; | ||
| 151 | mem->n -= size; | ||
| 152 | |||
| 153 | /* Set to zero if needed. */ | ||
| 154 | if (zero) | ||
| 155 | memset(ptr, 0, size); | ||
| 156 | |||
| 157 | return ptr; | ||
| 158 | } | ||
lib/libc/wasi/libc-top-half/musl/src/regex/tre.h deleted-233| ... | @@ -1,233 +0,0 @@ | ||
| 1 | /* | ||
| 2 | tre-internal.h - TRE internal definitions | ||
| 3 | |||
| 4 | Copyright (c) 2001-2009 Ville Laurikari <vl@iki.fi> | ||
| 5 | All rights reserved. | ||
| 6 | |||
| 7 | Redistribution and use in source and binary forms, with or without | ||
| 8 | modification, are permitted provided that the following conditions | ||
| 9 | are met: | ||
| 10 | |||
| 11 | 1. Redistributions of source code must retain the above copyright | ||
| 12 | notice, this list of conditions and the following disclaimer. | ||
| 13 | |||
| 14 | 2. Redistributions in binary form must reproduce the above copyright | ||
| 15 | notice, this list of conditions and the following disclaimer in the | ||
| 16 | documentation and/or other materials provided with the distribution. | ||
| 17 | |||
| 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS | ||
| 19 | ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
| 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
| 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
| 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
| 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
| 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 29 | |||
| 30 | */ | ||
| 31 | |||
| 32 | #include <regex.h> | ||
| 33 | #include <wchar.h> | ||
| 34 | #include <wctype.h> | ||
| 35 | |||
| 36 | #undef TRE_MBSTATE | ||
| 37 | |||
| 38 | #ifdef __wasilibc_unmodified_upstream // Allow NDEBUG to be predefined. | ||
| 39 | #define NDEBUG | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #define TRE_REGEX_T_FIELD __opaque | ||
| 43 | typedef int reg_errcode_t; | ||
| 44 | |||
| 45 | typedef wchar_t tre_char_t; | ||
| 46 | |||
| 47 | #define DPRINT(msg) do { } while(0) | ||
| 48 | |||
| 49 | #define elementsof(x)	( sizeof(x) / sizeof(x[0]) ) | ||
| 50 | |||
| 51 | #define tre_mbrtowc(pwc, s, n, ps) (mbtowc((pwc), (s), (n))) | ||
| 52 | |||
| 53 | /* Wide characters. */ | ||
| 54 | typedef wint_t tre_cint_t; | ||
| 55 | #define TRE_CHAR_MAX 0x10ffff | ||
| 56 | |||
| 57 | #define tre_isalnum iswalnum | ||
| 58 | #define tre_isalpha iswalpha | ||
| 59 | #define tre_isblank iswblank | ||
| 60 | #define tre_iscntrl iswcntrl | ||
| 61 | #define tre_isdigit iswdigit | ||
| 62 | #define tre_isgraph iswgraph | ||
| 63 | #define tre_islower iswlower | ||
| 64 | #define tre_isprint iswprint | ||
| 65 | #define tre_ispunct iswpunct | ||
| 66 | #define tre_isspace iswspace | ||
| 67 | #define tre_isupper iswupper | ||
| 68 | #define tre_isxdigit iswxdigit | ||
| 69 | |||
| 70 | #define tre_tolower towlower | ||
| 71 | #define tre_toupper towupper | ||
| 72 | #define tre_strlen wcslen | ||
| 73 | |||
| 74 | /* Use system provided iswctype() and wctype(). */ | ||
| 75 | typedef wctype_t tre_ctype_t; | ||
| 76 | #define tre_isctype iswctype | ||
| 77 | #define tre_ctype wctype | ||
| 78 | |||
| 79 | /* Returns number of bytes to add to (char *)ptr to make it | ||
| 80 | properly aligned for the type. */ | ||
| 81 | #define ALIGN(ptr, type) \ | ||
| 82 | ((((long)ptr) % sizeof(type)) \ | ||
| 83 | ? (sizeof(type) - (((long)ptr) % sizeof(type))) \ | ||
| 84 | : 0) | ||
| 85 | |||
| 86 | #undef MAX | ||
| 87 | #undef MIN | ||
| 88 | #define MAX(a, b) (((a) >= (b)) ? (a) : (b)) | ||
| 89 | #define MIN(a, b) (((a) <= (b)) ? (a) : (b)) | ||
| 90 | |||
| 91 | /* TNFA transition type. A TNFA state is an array of transitions, | ||
| 92 | the terminator is a transition with NULL `state'. */ | ||
| 93 | typedef struct tnfa_transition tre_tnfa_transition_t; | ||
| 94 | |||
| 95 | struct tnfa_transition { | ||
| 96 | /* Range of accepted characters. */ | ||
| 97 | tre_cint_t code_min; | ||
| 98 | tre_cint_t code_max; | ||
| 99 | /* Pointer to the destination state. */ | ||
| 100 | tre_tnfa_transition_t *state; | ||
| 101 | /* ID number of the destination state. */ | ||
| 102 | int state_id; | ||
| 103 | /* -1 terminated array of tags (or NULL). */ | ||
| 104 | int *tags; | ||
| 105 | /* Assertion bitmap. */ | ||
| 106 | int assertions; | ||
| 107 | /* Assertion parameters. */ | ||
| 108 | union { | ||
| 109 | /* Character class assertion. */ | ||
| 110 | tre_ctype_t class; | ||
| 111 | /* Back reference assertion. */ | ||
| 112 | int backref; | ||
| 113 | } u; | ||
| 114 | /* Negative character class assertions. */ | ||
| 115 | tre_ctype_t *neg_classes; | ||
| 116 | }; | ||
| 117 | |||
| 118 | |||
| 119 | /* Assertions. */ | ||
| 120 | #define ASSERT_AT_BOL		 1 /* Beginning of line. */ | ||
| 121 | #define ASSERT_AT_EOL		 2 /* End of line. */ | ||
| 122 | #define ASSERT_CHAR_CLASS	 4 /* Character class in `class'. */ | ||
| 123 | #define ASSERT_CHAR_CLASS_NEG	 8 /* Character classes in `neg_classes'. */ | ||
| 124 | #define ASSERT_AT_BOW		 16 /* Beginning of word. */ | ||
| 125 | #define ASSERT_AT_EOW		 32 /* End of word. */ | ||
| 126 | #define ASSERT_AT_WB		 64 /* Word boundary. */ | ||
| 127 | #define ASSERT_AT_WB_NEG	128 /* Not a word boundary. */ | ||
| 128 | #define ASSERT_BACKREF		256 /* A back reference in `backref'. */ | ||
| 129 | #define ASSERT_LAST		256 | ||
| 130 | |||
| 131 | /* Tag directions. */ | ||
| 132 | typedef enum { | ||
| 133 | TRE_TAG_MINIMIZE = 0, | ||
| 134 | TRE_TAG_MAXIMIZE = 1 | ||
| 135 | } tre_tag_direction_t; | ||
| 136 | |||
| 137 | /* Instructions to compute submatch register values from tag values | ||
| 138 | after a successful match. */ | ||
| 139 | struct tre_submatch_data { | ||
| 140 | /* Tag that gives the value for rm_so (submatch start offset). */ | ||
| 141 | int so_tag; | ||
| 142 | /* Tag that gives the value for rm_eo (submatch end offset). */ | ||
| 143 | int eo_tag; | ||
| 144 | /* List of submatches this submatch is contained in. */ | ||
| 145 | int *parents; | ||
| 146 | }; | ||
| 147 | |||
| 148 | typedef struct tre_submatch_data tre_submatch_data_t; | ||
| 149 | |||
| 150 | |||
| 151 | /* TNFA definition. */ | ||
| 152 | typedef struct tnfa tre_tnfa_t; | ||
| 153 | |||
| 154 | struct tnfa { | ||
| 155 | tre_tnfa_transition_t *transitions; | ||
| 156 | unsigned int num_transitions; | ||
| 157 | tre_tnfa_transition_t *initial; | ||
| 158 | tre_tnfa_transition_t *final; | ||
| 159 | tre_submatch_data_t *submatch_data; | ||
| 160 | char *firstpos_chars; | ||
| 161 | int first_char; | ||
| 162 | unsigned int num_submatches; | ||
| 163 | tre_tag_direction_t *tag_directions; | ||
| 164 | int *minimal_tags; | ||
| 165 | int num_tags; | ||
| 166 | int num_minimals; | ||
| 167 | int end_tag; | ||
| 168 | int num_states; | ||
| 169 | int cflags; | ||
| 170 | int have_backrefs; | ||
| 171 | int have_approx; | ||
| 172 | }; | ||
| 173 | |||
| 174 | /* from tre-mem.h: */ | ||
| 175 | |||
| 176 | #define TRE_MEM_BLOCK_SIZE 1024 | ||
| 177 | |||
| 178 | typedef struct tre_list { | ||
| 179 | void *data; | ||
| 180 | struct tre_list *next; | ||
| 181 | } tre_list_t; | ||
| 182 | |||
| 183 | typedef struct tre_mem_struct { | ||
| 184 | tre_list_t *blocks; | ||
| 185 | tre_list_t *current; | ||
| 186 | char *ptr; | ||
| 187 | size_t n; | ||
| 188 | int failed; | ||
| 189 | void **provided; | ||
| 190 | } *tre_mem_t; | ||
| 191 | |||
| 192 | #define tre_mem_new_impl __tre_mem_new_impl | ||
| 193 | #define tre_mem_alloc_impl __tre_mem_alloc_impl | ||
| 194 | #define tre_mem_destroy __tre_mem_destroy | ||
| 195 | |||
| 196 | hidden tre_mem_t tre_mem_new_impl(int provided, void *provided_block); | ||
| 197 | hidden void *tre_mem_alloc_impl(tre_mem_t mem, int provided, void *provided_block, | ||
| 198 | int zero, size_t size); | ||
| 199 | |||
| 200 | /* Returns a new memory allocator or NULL if out of memory. */ | ||
| 201 | #define tre_mem_new() tre_mem_new_impl(0, NULL) | ||
| 202 | |||
| 203 | /* Allocates a block of `size' bytes from `mem'. Returns a pointer to the | ||
| 204 | allocated block or NULL if an underlying malloc() failed. */ | ||
| 205 | #define tre_mem_alloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 0, size) | ||
| 206 | |||
| 207 | /* Allocates a block of `size' bytes from `mem'. Returns a pointer to the | ||
| 208 | allocated block or NULL if an underlying malloc() failed. The memory | ||
| 209 | is set to zero. */ | ||
| 210 | #define tre_mem_calloc(mem, size) tre_mem_alloc_impl(mem, 0, NULL, 1, size) | ||
| 211 | |||
| 212 | #ifdef TRE_USE_ALLOCA | ||
| 213 | /* alloca() versions. Like above, but memory is allocated with alloca() | ||
| 214 | instead of malloc(). */ | ||
| 215 | |||
| 216 | #define tre_mem_newa() \ | ||
| 217 | tre_mem_new_impl(1, alloca(sizeof(struct tre_mem_struct))) | ||
| 218 | |||
| 219 | #define tre_mem_alloca(mem, size)					 \ | ||
| 220 | ((mem)->n >= (size)							 \ | ||
| 221 | ? tre_mem_alloc_impl((mem), 1, NULL, 0, (size))			 \ | ||
| 222 | : tre_mem_alloc_impl((mem), 1, alloca(TRE_MEM_BLOCK_SIZE), 0, (size))) | ||
| 223 | #endif /* TRE_USE_ALLOCA */ | ||
| 224 | |||
| 225 | |||
| 226 | /* Frees the memory allocator and all memory allocated with it. */ | ||
| 227 | hidden void tre_mem_destroy(tre_mem_t mem); | ||
| 228 | |||
| 229 | #define xmalloc malloc | ||
| 230 | #define xcalloc calloc | ||
| 231 | #define xfree free | ||
| 232 | #define xrealloc realloc | ||
| 233 | |||
lib/libc/wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c deleted-83| ... | @@ -1,83 +0,0 @@ | ||
| 1 | /* | ||
| 2 | * a runtime implementation for | ||
| 3 | * https://github.com/llvm/llvm-project/pull/84137 | ||
| 4 | * https://docs.google.com/document/d/1ZvTPT36K5jjiedF8MCXbEmYjULJjI723aOAks1IdLLg/edit | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <stddef.h> | ||
| 8 | #include <stdint.h> | ||
| 9 | |||
| 10 | /* | ||
| 11 | * function prototypes | ||
| 12 | */ | ||
| 13 | void __wasm_setjmp(void *env, uint32_t label, void *func_invocation_id); | ||
| 14 | uint32_t __wasm_setjmp_test(void *env, void *func_invocation_id); | ||
| 15 | void __wasm_longjmp(void *env, int val); | ||
| 16 | |||
| 17 | /* | ||
| 18 | * jmp_buf should have large enough size and alignment to contain | ||
| 19 | * this structure. | ||
| 20 | */ | ||
| 21 | struct jmp_buf_impl { | ||
| 22 | void *func_invocation_id; | ||
| 23 | uint32_t label; | ||
| 24 | |||
| 25 | /* | ||
| 26 | * this is a temorary storage used by the communication between | ||
| 27 | * __wasm_sjlj_longjmp and WebAssemblyLowerEmscriptenEHSjL-generated | ||
| 28 | * logic. | ||
| 29 | * ideally, this can be replaced with multivalue. | ||
| 30 | */ | ||
| 31 | struct arg { | ||
| 32 | void *env; | ||
| 33 | int val; | ||
| 34 | } arg; | ||
| 35 | }; | ||
| 36 | |||
| 37 | void | ||
| 38 | __wasm_setjmp(void *env, uint32_t label, void *func_invocation_id) | ||
| 39 | { | ||
| 40 | struct jmp_buf_impl *jb = env; | ||
| 41 | if (label == 0) { /* ABI contract */ | ||
| 42 | __builtin_trap(); | ||
| 43 | } | ||
| 44 | if (func_invocation_id == NULL) { /* sanity check */ | ||
| 45 | __builtin_trap(); | ||
| 46 | } | ||
| 47 | jb->func_invocation_id = func_invocation_id; | ||
| 48 | jb->label = label; | ||
| 49 | } | ||
| 50 | |||
| 51 | uint32_t | ||
| 52 | __wasm_setjmp_test(void *env, void *func_invocation_id) | ||
| 53 | { | ||
| 54 | struct jmp_buf_impl *jb = env; | ||
| 55 | if (jb->label == 0) { /* ABI contract */ | ||
| 56 | __builtin_trap(); | ||
| 57 | } | ||
| 58 | if (func_invocation_id == NULL) { /* sanity check */ | ||
| 59 | __builtin_trap(); | ||
| 60 | } | ||
| 61 | if (jb->func_invocation_id == func_invocation_id) { | ||
| 62 | return jb->label; | ||
| 63 | } | ||
| 64 | return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | void | ||
| 68 | __wasm_longjmp(void *env, int val) | ||
| 69 | { | ||
| 70 | struct jmp_buf_impl *jb = env; | ||
| 71 | struct arg *arg = &jb->arg; | ||
| 72 | /* | ||
| 73 | * C standard says: | ||
| 74 | * The longjmp function cannot cause the setjmp macro to return | ||
| 75 | * the value 0; if val is 0, the setjmp macro returns the value 1. | ||
| 76 | */ | ||
| 77 | if (val == 0) { | ||
| 78 | val = 1; | ||
| 79 | } | ||
| 80 | arg->env = env; | ||
| 81 | arg->val = val; | ||
| 82 | __builtin_wasm_throw(1, arg); /* 1 == C_LONGJMP */ | ||
| 83 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/futimesat.c deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <sys/stat.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 6 | #include "syscall.h" | ||
| 7 | #endif | ||
| 8 | |||
| 9 | int __futimesat(int dirfd, const char *pathname, const struct timeval times[2]) | ||
| 10 | { | ||
| 11 | 	struct timespec ts[2]; | ||
| 12 | 	if (times) { | ||
| 13 | 		int i; | ||
| 14 | 		for (i=0; i<2; i++) { | ||
| 15 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 16 | 			if (times[i].tv_usec >= 1000000ULL) | ||
| 17 | 				return __syscall_ret(-EINVAL); | ||
| 18 | #else | ||
| 19 | 			if (times[i].tv_usec >= 1000000ULL) { | ||
| 20 | 				errno = EINVAL; | ||
| 21 | 				return -1; | ||
| 22 | 			} | ||
| 23 | #endif | ||
| 24 | 			ts[i].tv_sec = times[i].tv_sec; | ||
| 25 | 			ts[i].tv_nsec = times[i].tv_usec * 1000; | ||
| 26 | 		} | ||
| 27 | 	} | ||
| 28 | 	return utimensat(dirfd, pathname, times ? ts : 0, 0); | ||
| 29 | } | ||
| 30 | |||
| 31 | weak_alias(__futimesat, futimesat); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__fdopen.c deleted-85| ... | @@ -1,85 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sys/ioctl.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include "libc.h" | ||
| 8 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 9 | #else | ||
| 10 | #include <__function___isatty.h> | ||
| 11 | #endif | ||
| 12 | |||
| 13 | FILE *__fdopen(int fd, const char *mode) | ||
| 14 | { | ||
| 15 | 	FILE *f; | ||
| 16 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 17 | 	struct winsize wsz; | ||
| 18 | #endif | ||
| 19 | |||
| 20 | 	/* Check for valid initial mode character */ | ||
| 21 | 	if (!strchr("rwa", *mode)) { | ||
| 22 | 		errno = EINVAL; | ||
| 23 | 		return 0; | ||
| 24 | 	} | ||
| 25 | |||
| 26 | 	/* Allocate FILE+buffer or fail */ | ||
| 27 | 	if (!(f=malloc(sizeof *f + UNGET + BUFSIZ))) return 0; | ||
| 28 | |||
| 29 | 	/* Zero-fill only the struct, not the buffer */ | ||
| 30 | 	memset(f, 0, sizeof *f); | ||
| 31 | |||
| 32 | 	/* Impose mode restrictions */ | ||
| 33 | 	if (!strchr(mode, '+')) f->flags = (*mode == 'r') ? F_NOWR : F_NORD; | ||
| 34 | |||
| 35 | 	/* Apply close-on-exec flag */ | ||
| 36 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 37 | 	if (strchr(mode, 'e')) __syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); | ||
| 38 | #else | ||
| 39 | 	if (strchr(mode, 'e')) fcntl(fd, F_SETFD, FD_CLOEXEC); | ||
| 40 | #endif | ||
| 41 | |||
| 42 | 	/* Set append mode on fd if opened for append */ | ||
| 43 | 	if (*mode == 'a') { | ||
| 44 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 45 | 		int flags = __syscall(SYS_fcntl, fd, F_GETFL); | ||
| 46 | #else | ||
| 47 | 		int flags = fcntl(fd, F_GETFL); | ||
| 48 | #endif | ||
| 49 | 		if (!(flags & O_APPEND)) | ||
| 50 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 51 | 			__syscall(SYS_fcntl, fd, F_SETFL, flags | O_APPEND); | ||
| 52 | #else | ||
| 53 | 			fcntl(fd, F_SETFL, flags | O_APPEND); | ||
| 54 | #endif | ||
| 55 | 		f->flags |= F_APP; | ||
| 56 | 	} | ||
| 57 | |||
| 58 | 	f->fd = fd; | ||
| 59 | 	f->buf = (unsigned char *)f + sizeof *f + UNGET; | ||
| 60 | 	f->buf_size = BUFSIZ; | ||
| 61 | |||
| 62 | 	/* Activate line buffered mode for terminals */ | ||
| 63 | 	f->lbf = EOF; | ||
| 64 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 65 | 	if (!(f->flags & F_NOWR) && !__syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz)) | ||
| 66 | #else | ||
| 67 | 	if (!(f->flags & F_NOWR) && __isatty(fd)) | ||
| 68 | #endif | ||
| 69 | 		f->lbf = '\n'; | ||
| 70 | |||
| 71 | 	/* Initialize op ptrs. No problem if some are unneeded. */ | ||
| 72 | 	f->read = __stdio_read; | ||
| 73 | 	f->write = __stdio_write; | ||
| 74 | 	f->seek = __stdio_seek; | ||
| 75 | 	f->close = __stdio_close; | ||
| 76 | |||
| 77 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 78 | 	if (!libc.threaded) f->lock = -1; | ||
| 79 | #endif | ||
| 80 | |||
| 81 | 	/* Add new FILE to open file list */ | ||
| 82 | 	return __ofl_add(f); | ||
| 83 | } | ||
| 84 | |||
| 85 | weak_alias(__fdopen, fdopen); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | FILE *__fopen_rb_ca(const char *filename, FILE *f, unsigned char *buf, size_t len) | ||
| 6 | { | ||
| 7 | 	memset(f, 0, sizeof *f); | ||
| 8 | |||
| 9 | #ifdef __wasilibc_unmodified_upstream // WASI has no sys_open | ||
| 10 | 	f->fd = sys_open(filename, O_RDONLY|O_CLOEXEC); | ||
| 11 | #else | ||
| 12 | 	f->fd = open(filename, O_RDONLY|O_CLOEXEC); | ||
| 13 | #endif | ||
| 14 | 	if (f->fd < 0) return 0; | ||
| 15 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 16 | 	__syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC); | ||
| 17 | #else | ||
| 18 | 	fcntl(f->fd, F_SETFD, FD_CLOEXEC); | ||
| 19 | #endif | ||
| 20 | |||
| 21 | 	f->flags = F_NOWR | F_PERM; | ||
| 22 | 	f->buf = buf + UNGET; | ||
| 23 | 	f->buf_size = len - UNGET; | ||
| 24 | 	f->read = __stdio_read; | ||
| 25 | 	f->seek = __stdio_seek; | ||
| 26 | 	f->close = __stdio_close; | ||
| 27 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 28 | 	f->lock = -1; | ||
| 29 | #endif | ||
| 30 | |||
| 31 | 	return f; | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_close.c deleted-26| ... | @@ -1,26 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 2 | #else | ||
| 3 | #include <unistd.h> | ||
| 4 | #endif | ||
| 5 | #include "stdio_impl.h" | ||
| 6 | #include "aio_impl.h" | ||
| 7 | |||
| 8 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 9 | static int dummy(int fd) | ||
| 10 | { | ||
| 11 | 	return fd; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(dummy, __aio_close); | ||
| 15 | #else | ||
| 16 | #define __aio_close(fd) (fd) | ||
| 17 | #endif | ||
| 18 | |||
| 19 | int __stdio_close(FILE *f) | ||
| 20 | { | ||
| 21 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 22 | 	return syscall(SYS_close, __aio_close(f->fd)); | ||
| 23 | #else | ||
| 24 | 	return close(__aio_close(f->fd)); | ||
| 25 | #endif | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_read.c deleted-33| ... | @@ -1,33 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 2 | #else | ||
| 3 | #include <unistd.h> | ||
| 4 | #endif | ||
| 5 | #include "stdio_impl.h" | ||
| 6 | #include <sys/uio.h> | ||
| 7 | |||
| 8 | size_t __stdio_read(FILE *f, unsigned char *buf, size_t len) | ||
| 9 | { | ||
| 10 | 	struct iovec iov[2] = { | ||
| 11 | 		{ .iov_base = buf, .iov_len = len - !!f->buf_size }, | ||
| 12 | 		{ .iov_base = f->buf, .iov_len = f->buf_size } | ||
| 13 | 	}; | ||
| 14 | 	ssize_t cnt; | ||
| 15 | |||
| 16 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 17 | 	cnt = iov[0].iov_len ? syscall(SYS_readv, f->fd, iov, 2) | ||
| 18 | 		: syscall(SYS_read, f->fd, iov[1].iov_base, iov[1].iov_len); | ||
| 19 | #else | ||
| 20 | 	cnt = iov[0].iov_len ? readv(f->fd, iov, 2) | ||
| 21 | 		: read(f->fd, iov[1].iov_base, iov[1].iov_len); | ||
| 22 | #endif | ||
| 23 | 	if (cnt <= 0) { | ||
| 24 | 		f->flags |= cnt ? F_ERR : F_EOF; | ||
| 25 | 		return 0; | ||
| 26 | 	} | ||
| 27 | 	if (cnt <= iov[0].iov_len) return cnt; | ||
| 28 | 	cnt -= iov[0].iov_len; | ||
| 29 | 	f->rpos = f->buf; | ||
| 30 | 	f->rend = f->buf + cnt; | ||
| 31 | 	if (f->buf_size) buf[len-1] = *f->rpos++; | ||
| 32 | 	return len; | ||
| 33 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_seek.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 2 | #else | ||
| 3 | #include <unistd.h> | ||
| 4 | #endif | ||
| 5 | #include "stdio_impl.h" | ||
| 6 | #include "stdio_impl.h" | ||
| 7 | |||
| 8 | off_t __stdio_seek(FILE *f, off_t off, int whence) | ||
| 9 | { | ||
| 10 | 	return __lseek(f->fd, off, whence); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_write.c deleted-38| ... | @@ -1,38 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <sys/uio.h> | ||
| 3 | |||
| 4 | size_t __stdio_write(FILE *f, const unsigned char *buf, size_t len) | ||
| 5 | { | ||
| 6 | 	struct iovec iovs[2] = { | ||
| 7 | 		{ .iov_base = f->wbase, .iov_len = f->wpos-f->wbase }, | ||
| 8 | 		{ .iov_base = (void *)buf, .iov_len = len } | ||
| 9 | 	}; | ||
| 10 | 	struct iovec *iov = iovs; | ||
| 11 | 	size_t rem = iov[0].iov_len + iov[1].iov_len; | ||
| 12 | 	int iovcnt = 2; | ||
| 13 | 	ssize_t cnt; | ||
| 14 | 	for (;;) { | ||
| 15 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 16 | 		cnt = syscall(SYS_writev, f->fd, iov, iovcnt); | ||
| 17 | #else | ||
| 18 | 		cnt = writev(f->fd, iov, iovcnt); | ||
| 19 | #endif | ||
| 20 | 		if (cnt == rem) { | ||
| 21 | 			f->wend = f->buf + f->buf_size; | ||
| 22 | 			f->wpos = f->wbase = f->buf; | ||
| 23 | 			return len; | ||
| 24 | 		} | ||
| 25 | 		if (cnt < 0) { | ||
| 26 | 			f->wpos = f->wbase = f->wend = 0; | ||
| 27 | 			f->flags |= F_ERR; | ||
| 28 | 			return iovcnt == 2 ? 0 : len-iov[0].iov_len; | ||
| 29 | 		} | ||
| 30 | 		rem -= cnt; | ||
| 31 | 		if (cnt > iov[0].iov_len) { | ||
| 32 | 			cnt -= iov[0].iov_len; | ||
| 33 | 			iov++; iovcnt--; | ||
| 34 | 		} | ||
| 35 | 		iov[0].iov_base = (char *)iov[0].iov_base + cnt; | ||
| 36 | 		iov[0].iov_len -= cnt; | ||
| 37 | 	} | ||
| 38 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdout_write.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #ifdef __wasilibc_unmodified_upstream // use isatty rather than manual ioctl | ||
| 4 | #else | ||
| 5 | #include <__function___isatty.h> | ||
| 6 | #endif | ||
| 7 | |||
| 8 | size_t __stdout_write(FILE *f, const unsigned char *buf, size_t len) | ||
| 9 | { | ||
| 10 | #ifdef __wasilibc_unmodified_upstream // use isatty rather than manual ioctl | ||
| 11 | 	struct winsize wsz; | ||
| 12 | #endif | ||
| 13 | 	f->write = __stdio_write; | ||
| 14 | #ifdef __wasilibc_unmodified_upstream // use isatty rather than manual ioctl | ||
| 15 | 	if (!(f->flags & F_SVB) && __syscall(SYS_ioctl, f->fd, TIOCGWINSZ, &wsz)) | ||
| 16 | #else | ||
| 17 | 	if (!(f->flags & F_SVB) && !__isatty(f->fd)) | ||
| 18 | #endif | ||
| 19 | 		f->lbf = -1; | ||
| 20 | 	return __stdio_write(f, buf, len); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetc.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "getc.h" | ||
| 3 | |||
| 4 | int fgetc(FILE *f) | ||
| 5 | { | ||
| 6 | 	return do_getc(f); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetpos.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int fgetpos(FILE *restrict f, fpos_t *restrict pos) | ||
| 4 | { | ||
| 5 | 	off_t off = __ftello(f); | ||
| 6 | 	if (off < 0) return -1; | ||
| 7 | 	*(long long *)pos = off; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
| 10 | |||
| 11 | weak_alias(fgetpos, fgetpos64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fmemopen.c deleted-137| ... | @@ -1,137 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <stddef.h> | ||
| 6 | #include <inttypes.h> | ||
| 7 | #include "libc.h" | ||
| 8 | |||
| 9 | struct cookie { | ||
| 10 | 	size_t pos, len, size; | ||
| 11 | 	unsigned char *buf; | ||
| 12 | 	int mode; | ||
| 13 | }; | ||
| 14 | |||
| 15 | struct mem_FILE { | ||
| 16 | 	FILE f; | ||
| 17 | 	struct cookie c; | ||
| 18 | 	unsigned char buf[UNGET+BUFSIZ], buf2[]; | ||
| 19 | }; | ||
| 20 | |||
| 21 | static off_t mseek(FILE *f, off_t off, int whence) | ||
| 22 | { | ||
| 23 | 	ssize_t base; | ||
| 24 | 	struct cookie *c = f->cookie; | ||
| 25 | 	if (whence>2U) { | ||
| 26 | fail: | ||
| 27 | 		errno = EINVAL; | ||
| 28 | 		return -1; | ||
| 29 | 	} | ||
| 30 | #ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values. | ||
| 31 | 	base = (size_t [3]){0, c->pos, c->len}[whence]; | ||
| 32 | #else | ||
| 33 | 	base = (size_t [3]) { | ||
| 34 | [SEEK_SET] = 0, | ||
| 35 | [SEEK_CUR] = c->pos, | ||
| 36 | [SEEK_END] = c->len | ||
| 37 | }[whence]; | ||
| 38 | #endif | ||
| 39 | 	if (off < -base || off > (ssize_t)c->size-base) goto fail; | ||
| 40 | 	return c->pos = base+off; | ||
| 41 | } | ||
| 42 | |||
| 43 | static size_t mread(FILE *f, unsigned char *buf, size_t len) | ||
| 44 | { | ||
| 45 | 	struct cookie *c = f->cookie; | ||
| 46 | 	size_t rem = c->len - c->pos; | ||
| 47 | 	if (c->pos > c->len) rem = 0; | ||
| 48 | 	if (len > rem) { | ||
| 49 | 		len = rem; | ||
| 50 | 		f->flags |= F_EOF; | ||
| 51 | 	} | ||
| 52 | 	memcpy(buf, c->buf+c->pos, len); | ||
| 53 | 	c->pos += len; | ||
| 54 | 	rem -= len; | ||
| 55 | 	if (rem > f->buf_size) rem = f->buf_size; | ||
| 56 | 	f->rpos = f->buf; | ||
| 57 | 	f->rend = f->buf + rem; | ||
| 58 | 	memcpy(f->rpos, c->buf+c->pos, rem); | ||
| 59 | 	c->pos += rem; | ||
| 60 | 	return len; | ||
| 61 | } | ||
| 62 | |||
| 63 | static size_t mwrite(FILE *f, const unsigned char *buf, size_t len) | ||
| 64 | { | ||
| 65 | 	struct cookie *c = f->cookie; | ||
| 66 | 	size_t rem; | ||
| 67 | 	size_t len2 = f->wpos - f->wbase; | ||
| 68 | 	if (len2) { | ||
| 69 | 		f->wpos = f->wbase; | ||
| 70 | 		if (mwrite(f, f->wpos, len2) < len2) return 0; | ||
| 71 | 	} | ||
| 72 | 	if (c->mode == 'a') c->pos = c->len; | ||
| 73 | 	rem = c->size - c->pos; | ||
| 74 | 	if (len > rem) len = rem; | ||
| 75 | 	memcpy(c->buf+c->pos, buf, len); | ||
| 76 | 	c->pos += len; | ||
| 77 | 	if (c->pos > c->len) { | ||
| 78 | 		c->len = c->pos; | ||
| 79 | 		if (c->len < c->size) c->buf[c->len] = 0; | ||
| 80 | 		else if ((f->flags&F_NORD) && c->size) c->buf[c->size-1] = 0; | ||
| 81 | 	} | ||
| 82 | 	return len; | ||
| 83 | } | ||
| 84 | |||
| 85 | static int mclose(FILE *m) | ||
| 86 | { | ||
| 87 | 	return 0; | ||
| 88 | } | ||
| 89 | |||
| 90 | FILE *fmemopen(void *restrict buf, size_t size, const char *restrict mode) | ||
| 91 | { | ||
| 92 | 	struct mem_FILE *f; | ||
| 93 | 	int plus = !!strchr(mode, '+'); | ||
| 94 | 	 | ||
| 95 | 	if (!strchr("rwa", *mode)) { | ||
| 96 | 		errno = EINVAL; | ||
| 97 | 		return 0; | ||
| 98 | 	} | ||
| 99 | |||
| 100 | 	if (!buf && size > PTRDIFF_MAX) { | ||
| 101 | 		errno = ENOMEM; | ||
| 102 | 		return 0; | ||
| 103 | 	} | ||
| 104 | |||
| 105 | 	f = malloc(sizeof *f + (buf?0:size)); | ||
| 106 | 	if (!f) return 0; | ||
| 107 | 	memset(f, 0, offsetof(struct mem_FILE, buf)); | ||
| 108 | 	f->f.cookie = &f->c; | ||
| 109 | 	f->f.fd = -1; | ||
| 110 | 	f->f.lbf = EOF; | ||
| 111 | 	f->f.buf = f->buf + UNGET; | ||
| 112 | 	f->f.buf_size = sizeof f->buf - UNGET; | ||
| 113 | 	if (!buf) { | ||
| 114 | 		buf = f->buf2; | ||
| 115 | 		memset(buf, 0, size); | ||
| 116 | 	} | ||
| 117 | |||
| 118 | 	f->c.buf = buf; | ||
| 119 | 	f->c.size = size; | ||
| 120 | 	f->c.mode = *mode; | ||
| 121 | 	 | ||
| 122 | 	if (!plus) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD; | ||
| 123 | 	if (*mode == 'r') f->c.len = size; | ||
| 124 | 	else if (*mode == 'a') f->c.len = f->c.pos = strnlen(buf, size); | ||
| 125 | 	else if (plus) *f->c.buf = 0; | ||
| 126 | |||
| 127 | 	f->f.read = mread; | ||
| 128 | 	f->f.write = mwrite; | ||
| 129 | 	f->f.seek = mseek; | ||
| 130 | 	f->f.close = mclose; | ||
| 131 | |||
| 132 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 133 | 	if (!libc.threaded) f->f.lock = -1; | ||
| 134 | #endif | ||
| 135 | |||
| 136 | 	return __ofl_add(&f->f); | ||
| 137 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fopen.c deleted-51| ... | @@ -1,51 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 2 | #else | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <wasi/libc.h> | ||
| 5 | #endif | ||
| 6 | #include "stdio_impl.h" | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <errno.h> | ||
| 10 | |||
| 11 | FILE *fopen(const char *restrict filename, const char *restrict mode) | ||
| 12 | { | ||
| 13 | 	FILE *f; | ||
| 14 | 	int fd; | ||
| 15 | 	int flags; | ||
| 16 | |||
| 17 | 	/* Check for valid initial mode character */ | ||
| 18 | 	if (!strchr("rwa", *mode)) { | ||
| 19 | 		errno = EINVAL; | ||
| 20 | 		return 0; | ||
| 21 | 	} | ||
| 22 | |||
| 23 | 	/* Compute the flags to pass to open() */ | ||
| 24 | 	flags = __fmodeflags(mode); | ||
| 25 | |||
| 26 | #ifdef __wasilibc_unmodified_upstream // WASI has no sys_open | ||
| 27 | 	fd = sys_open(filename, flags, 0666); | ||
| 28 | #else | ||
| 29 | 	// WASI libc ignores the mode parameter anyway, so skip the varargs. | ||
| 30 | 	fd = __wasilibc_open_nomode(filename, flags); | ||
| 31 | #endif | ||
| 32 | 	if (fd < 0) return 0; | ||
| 33 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 34 | 	if (flags & O_CLOEXEC) | ||
| 35 | 		__syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); | ||
| 36 | #else | ||
| 37 | 	/* Avoid __syscall, but also, FD_CLOEXEC is not supported in WASI. */ | ||
| 38 | #endif | ||
| 39 | |||
| 40 | 	f = __fdopen(fd, mode); | ||
| 41 | 	if (f) return f; | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 44 | 	__syscall(SYS_close, fd); | ||
| 45 | #else | ||
| 46 | 	close(fd); | ||
| 47 | #endif | ||
| 48 | 	return 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | weak_alias(fopen, fopen64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fputc.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "putc.h" | ||
| 3 | |||
| 4 | int fputc(int c, FILE *f) | ||
| 5 | { | ||
| 6 | 	return do_putc(c, f); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/freopen.c deleted-82| ... | @@ -1,82 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall, dup | ||
| 2 | #include "stdio_impl.h" | ||
| 3 | #else | ||
| 4 | #include <wasi/libc.h> | ||
| 5 | #endif | ||
| 6 | #include <fcntl.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall, dup | ||
| 9 | #else | ||
| 10 | // Move this below fcntl.h and unistd.h so that the __syscall macro doesn't | ||
| 11 | // cause trouble. | ||
| 12 | #include "stdio_impl.h" | ||
| 13 | #endif | ||
| 14 | |||
| 15 | /* The basic idea of this implementation is to open a new FILE, | ||
| 16 | * hack the necessary parts of the new FILE into the old one, then | ||
| 17 | * close the new FILE. */ | ||
| 18 | |||
| 19 | /* Locking IS necessary because another thread may provably hold the | ||
| 20 | * lock, via flockfile or otherwise, when freopen is called, and in that | ||
| 21 | * case, freopen cannot act until the lock is released. */ | ||
| 22 | |||
| 23 | FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *restrict f) | ||
| 24 | { | ||
| 25 | 	int fl = __fmodeflags(mode); | ||
| 26 | 	FILE *f2; | ||
| 27 | |||
| 28 | 	FLOCK(f); | ||
| 29 | |||
| 30 | 	fflush(f); | ||
| 31 | |||
| 32 | 	if (!filename) { | ||
| 33 | 		if (fl&O_CLOEXEC) | ||
| 34 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 35 | 			__syscall(SYS_fcntl, f->fd, F_SETFD, FD_CLOEXEC); | ||
| 36 | #else | ||
| 37 | 			fcntl(f->fd, F_SETFD, FD_CLOEXEC); | ||
| 38 | #endif | ||
| 39 | 		fl &= ~(O_CREAT|O_EXCL|O_CLOEXEC); | ||
| 40 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 41 | 		if (syscall(SYS_fcntl, f->fd, F_SETFL, fl) < 0) | ||
| 42 | #else | ||
| 43 | 		if (fcntl(f->fd, F_SETFL, fl) < 0) | ||
| 44 | #endif | ||
| 45 | 			goto fail; | ||
| 46 | 	} else { | ||
| 47 | 		f2 = fopen(filename, mode); | ||
| 48 | 		if (!f2) goto fail; | ||
| 49 | 		if (f2->fd == f->fd) f2->fd = -1; /* avoid closing in fclose */ | ||
| 50 | #ifdef __wasilibc_unmodified_upstream // WASI has no dup | ||
| 51 | 		else if (__dup3(f2->fd, f->fd, fl&O_CLOEXEC)<0) goto fail2; | ||
| 52 | #else | ||
| 53 | 		// WASI doesn't have dup3, but does have a way to renumber | ||
| 54 | 		// an existing file descriptor. | ||
| 55 | 		else { | ||
| 56 | 			if (__wasilibc_fd_renumber(f2->fd, f->fd)<0) goto fail2; | ||
| 57 | 			f2->fd = -1; /* avoid closing in fclose */ | ||
| 58 | 		} | ||
| 59 | #endif | ||
| 60 | |||
| 61 | 		f->flags = (f->flags & F_PERM) | f2->flags; | ||
| 62 | 		f->read = f2->read; | ||
| 63 | 		f->write = f2->write; | ||
| 64 | 		f->seek = f2->seek; | ||
| 65 | 		f->close = f2->close; | ||
| 66 | |||
| 67 | 		fclose(f2); | ||
| 68 | 	} | ||
| 69 | |||
| 70 | 	f->mode = 0; | ||
| 71 | 	f->locale = 0; | ||
| 72 | 	FUNLOCK(f); | ||
| 73 | 	return f; | ||
| 74 | |||
| 75 | fail2: | ||
| 76 | 	fclose(f2); | ||
| 77 | fail: | ||
| 78 | 	fclose(f); | ||
| 79 | 	return NULL; | ||
| 80 | } | ||
| 81 | |||
| 82 | weak_alias(freopen, freopen64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fseek.c deleted-50| ... | @@ -1,50 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int __fseeko_unlocked(FILE *f, off_t off, int whence) | ||
| 5 | { | ||
| 6 | 	/* Fail immediately for invalid whence argument. */ | ||
| 7 | 	if (whence != SEEK_CUR && whence != SEEK_SET && whence != SEEK_END) { | ||
| 8 | 		errno = EINVAL; | ||
| 9 | 		return -1; | ||
| 10 | 	} | ||
| 11 | |||
| 12 | 	/* Adjust relative offset for unread data in buffer, if any. */ | ||
| 13 | 	if (whence == SEEK_CUR && f->rend) off -= f->rend - f->rpos; | ||
| 14 | |||
| 15 | 	/* Flush write buffer, and report error on failure. */ | ||
| 16 | 	if (f->wpos != f->wbase) { | ||
| 17 | 		f->write(f, 0, 0); | ||
| 18 | 		if (!f->wpos) return -1; | ||
| 19 | 	} | ||
| 20 | |||
| 21 | 	/* Leave writing mode */ | ||
| 22 | 	f->wpos = f->wbase = f->wend = 0; | ||
| 23 | |||
| 24 | 	/* Perform the underlying seek. */ | ||
| 25 | 	if (f->seek(f, off, whence) < 0) return -1; | ||
| 26 | |||
| 27 | 	/* If seek succeeded, file is seekable and we discard read buffer. */ | ||
| 28 | 	f->rpos = f->rend = 0; | ||
| 29 | 	f->flags &= ~F_EOF; | ||
| 30 | 	 | ||
| 31 | 	return 0; | ||
| 32 | } | ||
| 33 | |||
| 34 | int __fseeko(FILE *f, off_t off, int whence) | ||
| 35 | { | ||
| 36 | 	int result; | ||
| 37 | 	FLOCK(f); | ||
| 38 | 	result = __fseeko_unlocked(f, off, whence); | ||
| 39 | 	FUNLOCK(f); | ||
| 40 | 	return result; | ||
| 41 | } | ||
| 42 | |||
| 43 | int fseek(FILE *f, long off, int whence) | ||
| 44 | { | ||
| 45 | 	return __fseeko(f, off, whence); | ||
| 46 | } | ||
| 47 | |||
| 48 | weak_alias(__fseeko, fseeko); | ||
| 49 | |||
| 50 | weak_alias(fseeko, fseeko64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fsetpos.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int fsetpos(FILE *f, const fpos_t *pos) | ||
| 4 | { | ||
| 5 | 	return __fseeko(f, *(const long long *)pos, SEEK_SET); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(fsetpos, fsetpos64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ftell.c deleted-41| ... | @@ -1,41 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | off_t __ftello_unlocked(FILE *f) | ||
| 6 | { | ||
| 7 | 	off_t pos = f->seek(f, 0, | ||
| 8 | 		(f->flags & F_APP) && f->wpos != f->wbase | ||
| 9 | 		? SEEK_END : SEEK_CUR); | ||
| 10 | 	if (pos < 0) return pos; | ||
| 11 | |||
| 12 | 	/* Adjust for data in buffer. */ | ||
| 13 | 	if (f->rend) | ||
| 14 | 		pos += f->rpos - f->rend; | ||
| 15 | 	else if (f->wbase) | ||
| 16 | 		pos += f->wpos - f->wbase; | ||
| 17 | 	return pos; | ||
| 18 | } | ||
| 19 | |||
| 20 | off_t __ftello(FILE *f) | ||
| 21 | { | ||
| 22 | 	off_t pos; | ||
| 23 | 	FLOCK(f); | ||
| 24 | 	pos = __ftello_unlocked(f); | ||
| 25 | 	FUNLOCK(f); | ||
| 26 | 	return pos; | ||
| 27 | } | ||
| 28 | |||
| 29 | long ftell(FILE *f) | ||
| 30 | { | ||
| 31 | 	off_t pos = __ftello(f); | ||
| 32 | 	if (pos > LONG_MAX) { | ||
| 33 | 		errno = EOVERFLOW; | ||
| 34 | 		return -1; | ||
| 35 | 	} | ||
| 36 | 	return pos; | ||
| 37 | } | ||
| 38 | |||
| 39 | weak_alias(__ftello, ftello); | ||
| 40 | |||
| 41 | weak_alias(ftello, ftello64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getc.c deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "getc.h" | ||
| 3 | |||
| 4 | int getc(FILE *f) | ||
| 5 | { | ||
| 6 | 	return do_getc(f); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(getc, _IO_getc); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getc.h deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | #ifdef __GNUC__ | ||
| 6 | __attribute__((__noinline__)) | ||
| 7 | #endif | ||
| 8 | static int locking_getc(FILE *f) | ||
| 9 | { | ||
| 10 | 	if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f); | ||
| 11 | 	int c = getc_unlocked(f); | ||
| 12 | 	if (a_swap(&f->lock, 0) & MAYBE_WAITERS) | ||
| 13 | 		__wake(&f->lock, 1, 1); | ||
| 14 | 	return c; | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | |||
| 18 | static inline int do_getc(FILE *f) | ||
| 19 | { | ||
| 20 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 21 | 	int l = f->lock; | ||
| 22 | 	if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid) | ||
| 23 | 		return getc_unlocked(f); | ||
| 24 | 	return locking_getc(f); | ||
| 25 | #else | ||
| 26 | 	// With no threads, locking is unnecessary. | ||
| 27 | 	return getc_unlocked(f); | ||
| 28 | #endif | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getchar.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "getc.h" | ||
| 3 | |||
| 4 | int getchar(void) | ||
| 5 | { | ||
| 6 | 	return do_getc(stdin); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ofl.c deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "lock.h" | ||
| 3 | #include "fork_impl.h" | ||
| 4 | |||
| 5 | static FILE *ofl_head; | ||
| 6 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 7 | static volatile int ofl_lock[1]; | ||
| 8 | volatile int *const __stdio_ofl_lockptr = ofl_lock; | ||
| 9 | #endif | ||
| 10 | |||
| 11 | FILE **__ofl_lock() | ||
| 12 | { | ||
| 13 | 	LOCK(ofl_lock); | ||
| 14 | 	return &ofl_head; | ||
| 15 | } | ||
| 16 | |||
| 17 | void __ofl_unlock() | ||
| 18 | { | ||
| 19 | 	UNLOCK(ofl_lock); | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/open_memstream.c deleted-109| ... | @@ -1,109 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include "libc.h" | ||
| 7 | |||
| 8 | struct cookie { | ||
| 9 | 	char **bufp; | ||
| 10 | 	size_t *sizep; | ||
| 11 | 	size_t pos; | ||
| 12 | 	char *buf; | ||
| 13 | 	size_t len; | ||
| 14 | 	size_t space; | ||
| 15 | }; | ||
| 16 | |||
| 17 | struct ms_FILE { | ||
| 18 | 	FILE f; | ||
| 19 | 	struct cookie c; | ||
| 20 | 	unsigned char buf[BUFSIZ]; | ||
| 21 | }; | ||
| 22 | |||
| 23 | static off_t ms_seek(FILE *f, off_t off, int whence) | ||
| 24 | { | ||
| 25 | 	ssize_t base; | ||
| 26 | 	struct cookie *c = f->cookie; | ||
| 27 | 	if (whence>2U) { | ||
| 28 | fail: | ||
| 29 | 		errno = EINVAL; | ||
| 30 | 		return -1; | ||
| 31 | 	} | ||
| 32 | #ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values. | ||
| 33 | 	base = (size_t [3]){0, c->pos, c->len}[whence]; | ||
| 34 | #else | ||
| 35 | 	base = (size_t [3]) { | ||
| 36 | [SEEK_SET] = 0, | ||
| 37 | [SEEK_CUR] = c->pos, | ||
| 38 | [SEEK_END] = c->len | ||
| 39 | }[whence]; | ||
| 40 | #endif | ||
| 41 | 	if (off < -base || off > SSIZE_MAX-base) goto fail; | ||
| 42 | 	return c->pos = base+off; | ||
| 43 | } | ||
| 44 | |||
| 45 | static size_t ms_write(FILE *f, const unsigned char *buf, size_t len) | ||
| 46 | { | ||
| 47 | 	struct cookie *c = f->cookie; | ||
| 48 | 	size_t len2 = f->wpos - f->wbase; | ||
| 49 | 	char *newbuf; | ||
| 50 | 	if (len2) { | ||
| 51 | 		f->wpos = f->wbase; | ||
| 52 | 		if (ms_write(f, f->wbase, len2) < len2) return 0; | ||
| 53 | 	} | ||
| 54 | 	if (len + c->pos >= c->space) { | ||
| 55 | 		len2 = 2*c->space+1 | c->pos+len+1; | ||
| 56 | 		newbuf = realloc(c->buf, len2); | ||
| 57 | 		if (!newbuf) return 0; | ||
| 58 | 		*c->bufp = c->buf = newbuf; | ||
| 59 | 		memset(c->buf + c->space, 0, len2 - c->space); | ||
| 60 | 		c->space = len2; | ||
| 61 | 	} | ||
| 62 | 	memcpy(c->buf+c->pos, buf, len); | ||
| 63 | 	c->pos += len; | ||
| 64 | 	if (c->pos >= c->len) c->len = c->pos; | ||
| 65 | 	*c->sizep = c->pos; | ||
| 66 | 	return len; | ||
| 67 | } | ||
| 68 | |||
| 69 | static int ms_close(FILE *f) | ||
| 70 | { | ||
| 71 | 	return 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | FILE *open_memstream(char **bufp, size_t *sizep) | ||
| 75 | { | ||
| 76 | 	struct ms_FILE *f; | ||
| 77 | 	char *buf; | ||
| 78 | |||
| 79 | 	if (!(f=malloc(sizeof *f))) return 0; | ||
| 80 | 	if (!(buf=malloc(sizeof *buf))) { | ||
| 81 | 		free(f); | ||
| 82 | 		return 0; | ||
| 83 | 	} | ||
| 84 | 	memset(&f->f, 0, sizeof f->f); | ||
| 85 | 	memset(&f->c, 0, sizeof f->c); | ||
| 86 | 	f->f.cookie = &f->c; | ||
| 87 | |||
| 88 | 	f->c.bufp = bufp; | ||
| 89 | 	f->c.sizep = sizep; | ||
| 90 | 	f->c.pos = f->c.len = f->c.space = *sizep = 0; | ||
| 91 | 	f->c.buf = *bufp = buf; | ||
| 92 | 	*buf = 0; | ||
| 93 | |||
| 94 | 	f->f.flags = F_NORD; | ||
| 95 | 	f->f.fd = -1; | ||
| 96 | 	f->f.buf = f->buf; | ||
| 97 | 	f->f.buf_size = sizeof f->buf; | ||
| 98 | 	f->f.lbf = EOF; | ||
| 99 | 	f->f.write = ms_write; | ||
| 100 | 	f->f.seek = ms_seek; | ||
| 101 | 	f->f.close = ms_close; | ||
| 102 | 	f->f.mode = -1; | ||
| 103 | |||
| 104 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 105 | 	if (!libc.threaded) f->f.lock = -1; | ||
| 106 | #endif | ||
| 107 | |||
| 108 | 	return __ofl_add(&f->f); | ||
| 109 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/open_wmemstream.c deleted-116| ... | @@ -1,116 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "libc.h" | ||
| 8 | |||
| 9 | struct cookie { | ||
| 10 | 	wchar_t **bufp; | ||
| 11 | 	size_t *sizep; | ||
| 12 | 	size_t pos; | ||
| 13 | 	wchar_t *buf; | ||
| 14 | 	size_t len; | ||
| 15 | 	size_t space; | ||
| 16 | 	mbstate_t mbs; | ||
| 17 | }; | ||
| 18 | |||
| 19 | struct wms_FILE { | ||
| 20 | 	FILE f; | ||
| 21 | 	struct cookie c; | ||
| 22 | 	unsigned char buf[1]; | ||
| 23 | }; | ||
| 24 | |||
| 25 | static off_t wms_seek(FILE *f, off_t off, int whence) | ||
| 26 | { | ||
| 27 | 	ssize_t base; | ||
| 28 | 	struct cookie *c = f->cookie; | ||
| 29 | 	if (whence>2U) { | ||
| 30 | fail: | ||
| 31 | 		errno = EINVAL; | ||
| 32 | 		return -1; | ||
| 33 | 	} | ||
| 34 | #ifdef __wasilibc_unmodified_upstream // WASI's SEEK_* constants have different values. | ||
| 35 | 	base = (size_t [3]){0, c->pos, c->len}[whence]; | ||
| 36 | #else | ||
| 37 | 	base = (size_t [3]) { | ||
| 38 | [SEEK_SET] = 0, | ||
| 39 | [SEEK_CUR] = c->pos, | ||
| 40 | [SEEK_END] = c->len | ||
| 41 | }[whence]; | ||
| 42 | #endif | ||
| 43 | 	if (off < -base || off > SSIZE_MAX/4-base) goto fail; | ||
| 44 | 	memset(&c->mbs, 0, sizeof c->mbs); | ||
| 45 | 	return c->pos = base+off; | ||
| 46 | } | ||
| 47 | |||
| 48 | static size_t wms_write(FILE *f, const unsigned char *buf, size_t len) | ||
| 49 | { | ||
| 50 | 	struct cookie *c = f->cookie; | ||
| 51 | 	size_t len2 = f->wpos - f->wbase; | ||
| 52 | 	wchar_t *newbuf; | ||
| 53 | 	if (len2) { | ||
| 54 | 		f->wpos = f->wbase; | ||
| 55 | 		if (wms_write(f, f->wbase, len2) < len2) return 0; | ||
| 56 | 	} | ||
| 57 | 	if (len + c->pos >= c->space) { | ||
| 58 | 		len2 = 2*c->space+1 | c->pos+len+1; | ||
| 59 | 		if (len2 > SSIZE_MAX/4) return 0; | ||
| 60 | 		newbuf = realloc(c->buf, len2*4); | ||
| 61 | 		if (!newbuf) return 0; | ||
| 62 | 		*c->bufp = c->buf = newbuf; | ||
| 63 | 		memset(c->buf + c->space, 0, 4*(len2 - c->space)); | ||
| 64 | 		c->space = len2; | ||
| 65 | 	} | ||
| 66 | 	 | ||
| 67 | 	len2 = mbsnrtowcs(c->buf+c->pos, (void *)&buf, len, c->space-c->pos, &c->mbs); | ||
| 68 | 	if (len2 == -1) return 0; | ||
| 69 | 	c->pos += len2; | ||
| 70 | 	if (c->pos >= c->len) c->len = c->pos; | ||
| 71 | 	*c->sizep = c->pos; | ||
| 72 | 	return len; | ||
| 73 | } | ||
| 74 | |||
| 75 | static int wms_close(FILE *f) | ||
| 76 | { | ||
| 77 | 	return 0; | ||
| 78 | } | ||
| 79 | |||
| 80 | FILE *open_wmemstream(wchar_t **bufp, size_t *sizep) | ||
| 81 | { | ||
| 82 | 	struct wms_FILE *f; | ||
| 83 | 	wchar_t *buf; | ||
| 84 | |||
| 85 | 	if (!(f=malloc(sizeof *f))) return 0; | ||
| 86 | 	if (!(buf=malloc(sizeof *buf))) { | ||
| 87 | 		free(f); | ||
| 88 | 		return 0; | ||
| 89 | 	} | ||
| 90 | 	memset(&f->f, 0, sizeof f->f); | ||
| 91 | 	memset(&f->c, 0, sizeof f->c); | ||
| 92 | 	f->f.cookie = &f->c; | ||
| 93 | |||
| 94 | 	f->c.bufp = bufp; | ||
| 95 | 	f->c.sizep = sizep; | ||
| 96 | 	f->c.pos = f->c.len = f->c.space = *sizep = 0; | ||
| 97 | 	f->c.buf = *bufp = buf; | ||
| 98 | 	*buf = 0; | ||
| 99 | |||
| 100 | 	f->f.flags = F_NORD; | ||
| 101 | 	f->f.fd = -1; | ||
| 102 | 	f->f.buf = f->buf; | ||
| 103 | 	f->f.buf_size = 0; | ||
| 104 | 	f->f.lbf = EOF; | ||
| 105 | 	f->f.write = wms_write; | ||
| 106 | 	f->f.seek = wms_seek; | ||
| 107 | 	f->f.close = wms_close; | ||
| 108 | |||
| 109 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 110 | 	if (!libc.threaded) f->f.lock = -1; | ||
| 111 | #endif | ||
| 112 | |||
| 113 | 	fwide(&f->f, 1); | ||
| 114 | |||
| 115 | 	return __ofl_add(&f->f); | ||
| 116 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/printf.c deleted-17| ... | @@ -1,17 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int printf(const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vfprintf(stdout, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 14 | #else | ||
| 15 | weak_alias(printf, iprintf); | ||
| 16 | weak_alias(printf, __small_printf); | ||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putc.c deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "putc.h" | ||
| 3 | |||
| 4 | int putc(int c, FILE *f) | ||
| 5 | { | ||
| 6 | 	return do_putc(c, f); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(putc, _IO_putc); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putc.h deleted-29| ... | @@ -1,29 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | #ifdef __GNUC__ | ||
| 6 | __attribute__((__noinline__)) | ||
| 7 | #endif | ||
| 8 | static int locking_putc(int c, FILE *f) | ||
| 9 | { | ||
| 10 | 	if (a_cas(&f->lock, 0, MAYBE_WAITERS-1)) __lockfile(f); | ||
| 11 | 	c = putc_unlocked(c, f); | ||
| 12 | 	if (a_swap(&f->lock, 0) & MAYBE_WAITERS) | ||
| 13 | 		__wake(&f->lock, 1, 1); | ||
| 14 | 	return c; | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | |||
| 18 | static inline int do_putc(int c, FILE *f) | ||
| 19 | { | ||
| 20 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 21 | 	int l = f->lock; | ||
| 22 | 	if (l < 0 || l && (l & ~MAYBE_WAITERS) == __pthread_self()->tid) | ||
| 23 | 		return putc_unlocked(c, f); | ||
| 24 | 	return locking_putc(c, f); | ||
| 25 | #else | ||
| 26 | 	// With no threads, locking is unnecessary. | ||
| 27 | 	return putc_unlocked(c, f); | ||
| 28 | #endif | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putchar.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "putc.h" | ||
| 3 | |||
| 4 | int putchar(int c) | ||
| 5 | { | ||
| 6 | 	return do_putc(c, stdout); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/stderr.c deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | #undef stderr | ||
| 4 | |||
| 5 | static unsigned char buf[UNGET]; | ||
| 6 | hidden FILE __stderr_FILE = { | ||
| 7 | 	.buf = buf+UNGET, | ||
| 8 | 	.buf_size = 0, | ||
| 9 | 	.fd = 2, | ||
| 10 | 	.flags = F_PERM | F_NORD, | ||
| 11 | 	.lbf = -1, | ||
| 12 | 	.write = __stdio_write, | ||
| 13 | 	.seek = __stdio_seek, | ||
| 14 | 	.close = __stdio_close, | ||
| 15 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 16 | 	.lock = -1, | ||
| 17 | #endif | ||
| 18 | }; | ||
| 19 | FILE *const stderr = &__stderr_FILE; | ||
| 20 | FILE *volatile __stderr_used = &__stderr_FILE; | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/stdin.c deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | #undef stdin | ||
| 4 | |||
| 5 | static unsigned char buf[BUFSIZ+UNGET]; | ||
| 6 | hidden FILE __stdin_FILE = { | ||
| 7 | 	.buf = buf+UNGET, | ||
| 8 | 	.buf_size = sizeof buf-UNGET, | ||
| 9 | 	.fd = 0, | ||
| 10 | 	.flags = F_PERM | F_NOWR, | ||
| 11 | 	.read = __stdio_read, | ||
| 12 | 	.seek = __stdio_seek, | ||
| 13 | 	.close = __stdio_close, | ||
| 14 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 15 | 	.lock = -1, | ||
| 16 | #endif | ||
| 17 | }; | ||
| 18 | FILE *const stdin = &__stdin_FILE; | ||
| 19 | FILE *volatile __stdin_used = &__stdin_FILE; | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/stdout.c deleted-20| ... | @@ -1,20 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | #undef stdout | ||
| 4 | |||
| 5 | static unsigned char buf[BUFSIZ+UNGET]; | ||
| 6 | hidden FILE __stdout_FILE = { | ||
| 7 | 	.buf = buf+UNGET, | ||
| 8 | 	.buf_size = sizeof buf-UNGET, | ||
| 9 | 	.fd = 1, | ||
| 10 | 	.flags = F_PERM | F_NORD, | ||
| 11 | 	.lbf = '\n', | ||
| 12 | 	.write = __stdout_write, | ||
| 13 | 	.seek = __stdio_seek, | ||
| 14 | 	.close = __stdio_close, | ||
| 15 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 16 | 	.lock = -1, | ||
| 17 | #endif | ||
| 18 | }; | ||
| 19 | FILE *const stdout = &__stdout_FILE; | ||
| 20 | FILE *volatile __stdout_used = &__stdout_FILE; | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vdprintf.c deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int vdprintf(int fd, const char *restrict fmt, va_list ap) | ||
| 4 | { | ||
| 5 | 	FILE f = { | ||
| 6 | 		.fd = fd, .lbf = EOF, .write = __stdio_write, | ||
| 7 | 		.buf = (void *)fmt, .buf_size = 0, | ||
| 8 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 9 | 		.lock = -1 | ||
| 10 | #endif | ||
| 11 | 	}; | ||
| 12 | 	return vfprintf(&f, fmt, ap); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vfprintf.c deleted-744| ... | @@ -1,744 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | #include <ctype.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stdarg.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <wchar.h> | ||
| 10 | #include <inttypes.h> | ||
| 11 | #include <math.h> | ||
| 12 | #include <float.h> | ||
| 13 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 14 | #else | ||
| 15 | #include "printscan.h" | ||
| 16 | #endif | ||
| 17 | |||
| 18 | /* Some useful macros */ | ||
| 19 | |||
| 20 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) | ||
| 21 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) | ||
| 22 | |||
| 23 | /* Convenient bit representation for modifier flags, which all fall | ||
| 24 | * within 31 codepoints of the space character. */ | ||
| 25 | |||
| 26 | #define ALT_FORM (1U<<'#'-' ') | ||
| 27 | #define ZERO_PAD (1U<<'0'-' ') | ||
| 28 | #define LEFT_ADJ (1U<<'-'-' ') | ||
| 29 | #define PAD_POS (1U<<' '-' ') | ||
| 30 | #define MARK_POS (1U<<'+'-' ') | ||
| 31 | #define GROUPED (1U<<'\''-' ') | ||
| 32 | |||
| 33 | #define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) | ||
| 34 | |||
| 35 | /* State machine to accept length modifiers + conversion specifiers. | ||
| 36 | * Result is 0 on failure, or an argument type to pop on success. */ | ||
| 37 | |||
| 38 | enum { | ||
| 39 | 	BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, | ||
| 40 | 	ZTPRE, JPRE, | ||
| 41 | 	STOP, | ||
| 42 | 	PTR, INT, UINT, ULLONG, | ||
| 43 | 	LONG, ULONG, | ||
| 44 | 	SHORT, USHORT, CHAR, UCHAR, | ||
| 45 | 	LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, | ||
| 46 | 	DBL, LDBL, | ||
| 47 | 	NOARG, | ||
| 48 | 	MAXSTATE | ||
| 49 | }; | ||
| 50 | |||
| 51 | #define S(x) [(x)-'A'] | ||
| 52 | |||
| 53 | static const unsigned char states[]['z'-'A'+1] = { | ||
| 54 | 	{ /* 0: bare types */ | ||
| 55 | 		S('d') = INT, S('i') = INT, | ||
| 56 | 		S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, | ||
| 57 | 		S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, | ||
| 58 | 		S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, | ||
| 59 | 		S('c') = INT, S('C') = UINT, | ||
| 60 | 		S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, | ||
| 61 | 		S('m') = NOARG, | ||
| 62 | 		S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, | ||
| 63 | 		S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, | ||
| 64 | 	}, { /* 1: l-prefixed */ | ||
| 65 | 		S('d') = LONG, S('i') = LONG, | ||
| 66 | 		S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, | ||
| 67 | 		S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, | ||
| 68 | 		S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, | ||
| 69 | 		S('c') = UINT, S('s') = PTR, S('n') = PTR, | ||
| 70 | 		S('l') = LLPRE, | ||
| 71 | 	}, { /* 2: ll-prefixed */ | ||
| 72 | 		S('d') = LLONG, S('i') = LLONG, | ||
| 73 | 		S('o') = ULLONG, S('u') = ULLONG, | ||
| 74 | 		S('x') = ULLONG, S('X') = ULLONG, | ||
| 75 | 		S('n') = PTR, | ||
| 76 | 	}, { /* 3: h-prefixed */ | ||
| 77 | 		S('d') = SHORT, S('i') = SHORT, | ||
| 78 | 		S('o') = USHORT, S('u') = USHORT, | ||
| 79 | 		S('x') = USHORT, S('X') = USHORT, | ||
| 80 | 		S('n') = PTR, | ||
| 81 | 		S('h') = HHPRE, | ||
| 82 | 	}, { /* 4: hh-prefixed */ | ||
| 83 | 		S('d') = CHAR, S('i') = CHAR, | ||
| 84 | 		S('o') = UCHAR, S('u') = UCHAR, | ||
| 85 | 		S('x') = UCHAR, S('X') = UCHAR, | ||
| 86 | 		S('n') = PTR, | ||
| 87 | 	}, { /* 5: L-prefixed */ | ||
| 88 | 		S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, | ||
| 89 | 		S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, | ||
| 90 | 		S('n') = PTR, | ||
| 91 | 	}, { /* 6: z- or t-prefixed (assumed to be same size) */ | ||
| 92 | 		S('d') = PDIFF, S('i') = PDIFF, | ||
| 93 | 		S('o') = SIZET, S('u') = SIZET, | ||
| 94 | 		S('x') = SIZET, S('X') = SIZET, | ||
| 95 | 		S('n') = PTR, | ||
| 96 | 	}, { /* 7: j-prefixed */ | ||
| 97 | 		S('d') = IMAX, S('i') = IMAX, | ||
| 98 | 		S('o') = UMAX, S('u') = UMAX, | ||
| 99 | 		S('x') = UMAX, S('X') = UMAX, | ||
| 100 | 		S('n') = PTR, | ||
| 101 | 	} | ||
| 102 | }; | ||
| 103 | |||
| 104 | #define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') | ||
| 105 | |||
| 106 | union arg | ||
| 107 | { | ||
| 108 | 	uintmax_t i; | ||
| 109 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 110 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 111 | 	long_double f; | ||
| 112 | #else | ||
| 113 | 	long double f; | ||
| 114 | #endif | ||
| 115 | #endif | ||
| 116 | 	void *p; | ||
| 117 | }; | ||
| 118 | |||
| 119 | static void pop_arg(union arg *arg, int type, va_list *ap) | ||
| 120 | { | ||
| 121 | 	switch (type) { | ||
| 122 | 	 case PTR:	arg->p = va_arg(*ap, void *); | ||
| 123 | 	break; case INT:	arg->i = va_arg(*ap, int); | ||
| 124 | 	break; case UINT:	arg->i = va_arg(*ap, unsigned int); | ||
| 125 | 	break; case LONG:	arg->i = va_arg(*ap, long); | ||
| 126 | 	break; case ULONG:	arg->i = va_arg(*ap, unsigned long); | ||
| 127 | 	break; case ULLONG:	arg->i = va_arg(*ap, unsigned long long); | ||
| 128 | 	break; case SHORT:	arg->i = (short)va_arg(*ap, int); | ||
| 129 | 	break; case USHORT:	arg->i = (unsigned short)va_arg(*ap, int); | ||
| 130 | 	break; case CHAR:	arg->i = (signed char)va_arg(*ap, int); | ||
| 131 | 	break; case UCHAR:	arg->i = (unsigned char)va_arg(*ap, int); | ||
| 132 | 	break; case LLONG:	arg->i = va_arg(*ap, long long); | ||
| 133 | 	break; case SIZET:	arg->i = va_arg(*ap, size_t); | ||
| 134 | 	break; case IMAX:	arg->i = va_arg(*ap, intmax_t); | ||
| 135 | 	break; case UMAX:	arg->i = va_arg(*ap, uintmax_t); | ||
| 136 | 	break; case PDIFF:	arg->i = va_arg(*ap, ptrdiff_t); | ||
| 137 | 	break; case UIPTR:	arg->i = (uintptr_t)va_arg(*ap, void *); | ||
| 138 | #if defined(__wasilibc_printscan_no_floating_point) | ||
| 139 | 	break; case DBL: | ||
| 140 | 	 case LDBL: | ||
| 141 | 	floating_point_not_supported(); | ||
| 142 | #else | ||
| 143 | 	break; case DBL:	arg->f = va_arg(*ap, double); | ||
| 144 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 145 | 	break; case LDBL:	long_double_not_supported(); | ||
| 146 | #else | ||
| 147 | 	break; case LDBL:	arg->f = va_arg(*ap, long double); | ||
| 148 | #endif | ||
| 149 | #endif | ||
| 150 | 	} | ||
| 151 | } | ||
| 152 | |||
| 153 | static void out(FILE *f, const char *s, size_t l) | ||
| 154 | { | ||
| 155 | 	if (!ferror(f)) __fwritex((void *)s, l, f); | ||
| 156 | } | ||
| 157 | |||
| 158 | static void pad(FILE *f, char c, int w, int l, int fl) | ||
| 159 | { | ||
| 160 | 	char pad[256]; | ||
| 161 | 	if (fl & (LEFT_ADJ | ZERO_PAD) || l >= w) return; | ||
| 162 | 	l = w - l; | ||
| 163 | 	memset(pad, c, l>sizeof pad ? sizeof pad : l); | ||
| 164 | 	for (; l >= sizeof pad; l -= sizeof pad) | ||
| 165 | 		out(f, pad, sizeof pad); | ||
| 166 | 	out(f, pad, l); | ||
| 167 | } | ||
| 168 | |||
| 169 | static const char xdigits[16] = { | ||
| 170 | 	"0123456789ABCDEF" | ||
| 171 | }; | ||
| 172 | |||
| 173 | static char *fmt_x(uintmax_t x, char *s, int lower) | ||
| 174 | { | ||
| 175 | 	for (; x; x>>=4) *--s = xdigits[(x&15)]|lower; | ||
| 176 | 	return s; | ||
| 177 | } | ||
| 178 | |||
| 179 | static char *fmt_o(uintmax_t x, char *s) | ||
| 180 | { | ||
| 181 | 	for (; x; x>>=3) *--s = '0' + (x&7); | ||
| 182 | 	return s; | ||
| 183 | } | ||
| 184 | |||
| 185 | static char *fmt_u(uintmax_t x, char *s) | ||
| 186 | { | ||
| 187 | 	unsigned long y; | ||
| 188 | 	for ( ; x>ULONG_MAX; x/=10) *--s = '0' + x%10; | ||
| 189 | 	for (y=x; y; y/=10) *--s = '0' + y%10; | ||
| 190 | 	return s; | ||
| 191 | } | ||
| 192 | |||
| 193 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 194 | /* Do not override this check. The floating point printing code below | ||
| 195 | * depends on the float.h constants being right. If they are wrong, it | ||
| 196 | * may overflow the stack. */ | ||
| 197 | #if LDBL_MANT_DIG == 53 | ||
| 198 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 199 | typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long_double)]; | ||
| 200 | #else | ||
| 201 | typedef char compiler_defines_long_double_incorrectly[9-(int)sizeof(long double)]; | ||
| 202 | #endif | ||
| 203 | #endif | ||
| 204 | |||
| 205 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 206 | static int fmt_fp(FILE *f, long_double y, int w, int p, int fl, int t) | ||
| 207 | #else | ||
| 208 | static int fmt_fp(FILE *f, long double y, int w, int p, int fl, int t) | ||
| 209 | #endif | ||
| 210 | { | ||
| 211 | 	uint32_t big[(LDBL_MANT_DIG+28)/29 + 1 // mantissa expansion | ||
| 212 | 		+ (LDBL_MAX_EXP+LDBL_MANT_DIG+28+8)/9]; // exponent expansion | ||
| 213 | 	uint32_t *a, *d, *r, *z; | ||
| 214 | 	int e2=0, e, i, j, l; | ||
| 215 | 	char buf[9+LDBL_MANT_DIG/4], *s; | ||
| 216 | 	const char *prefix="-0X+0X 0X-0x+0x 0x"; | ||
| 217 | 	int pl; | ||
| 218 | 	char ebuf0[3*sizeof(int)], *ebuf=&ebuf0[3*sizeof(int)], *estr; | ||
| 219 | |||
| 220 | 	pl=1; | ||
| 221 | 	if (signbit(y)) { | ||
| 222 | 		y=-y; | ||
| 223 | 	} else if (fl & MARK_POS) { | ||
| 224 | 		prefix+=3; | ||
| 225 | 	} else if (fl & PAD_POS) { | ||
| 226 | 		prefix+=6; | ||
| 227 | 	} else prefix++, pl=0; | ||
| 228 | |||
| 229 | 	if (!isfinite(y)) { | ||
| 230 | 		char *s = (t&32)?"inf":"INF"; | ||
| 231 | 		if (y!=y) s=(t&32)?"nan":"NAN"; | ||
| 232 | 		pad(f, ' ', w, 3+pl, fl&~ZERO_PAD); | ||
| 233 | 		out(f, prefix, pl); | ||
| 234 | 		out(f, s, 3); | ||
| 235 | 		pad(f, ' ', w, 3+pl, fl^LEFT_ADJ); | ||
| 236 | 		return MAX(w, 3+pl); | ||
| 237 | 	} | ||
| 238 | |||
| 239 | 	y = frexpl(y, &e2) * 2; | ||
| 240 | 	if (y) e2--; | ||
| 241 | |||
| 242 | 	if ((t|32)=='a') { | ||
| 243 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 244 | 		long_double round = 8.0; | ||
| 245 | #else | ||
| 246 | 		long double round = 8.0; | ||
| 247 | #endif | ||
| 248 | 		int re; | ||
| 249 | |||
| 250 | 		if (t&32) prefix += 9; | ||
| 251 | 		pl += 2; | ||
| 252 | |||
| 253 | 		if (p<0 || p>=LDBL_MANT_DIG/4-1) re=0; | ||
| 254 | 		else re=LDBL_MANT_DIG/4-1-p; | ||
| 255 | |||
| 256 | 		if (re) { | ||
| 257 | 			round *= 1<<(LDBL_MANT_DIG%4); | ||
| 258 | 			while (re--) round*=16; | ||
| 259 | 			if (*prefix=='-') { | ||
| 260 | 				y=-y; | ||
| 261 | 				y-=round; | ||
| 262 | 				y+=round; | ||
| 263 | 				y=-y; | ||
| 264 | 			} else { | ||
| 265 | 				y+=round; | ||
| 266 | 				y-=round; | ||
| 267 | 			} | ||
| 268 | 		} | ||
| 269 | |||
| 270 | 		estr=fmt_u(e2<0 ? -e2 : e2, ebuf); | ||
| 271 | 		if (estr==ebuf) *--estr='0'; | ||
| 272 | 		*--estr = (e2<0 ? '-' : '+'); | ||
| 273 | 		*--estr = t+('p'-'a'); | ||
| 274 | |||
| 275 | 		s=buf; | ||
| 276 | 		do { | ||
| 277 | 			int x=y; | ||
| 278 | 			*s++=xdigits[x]|(t&32); | ||
| 279 | 			y=16*(y-x); | ||
| 280 | 			if (s-buf==1 && (y||p>0||(fl&ALT_FORM))) *s++='.'; | ||
| 281 | 		} while (y); | ||
| 282 | |||
| 283 | 		if (p > INT_MAX-2-(ebuf-estr)-pl) | ||
| 284 | 			return -1; | ||
| 285 | 		if (p && s-buf-2 < p) | ||
| 286 | 			l = (p+2) + (ebuf-estr); | ||
| 287 | 		else | ||
| 288 | 			l = (s-buf) + (ebuf-estr); | ||
| 289 | |||
| 290 | 		pad(f, ' ', w, pl+l, fl); | ||
| 291 | 		out(f, prefix, pl); | ||
| 292 | 		pad(f, '0', w, pl+l, fl^ZERO_PAD); | ||
| 293 | 		out(f, buf, s-buf); | ||
| 294 | 		pad(f, '0', l-(ebuf-estr)-(s-buf), 0, 0); | ||
| 295 | 		out(f, estr, ebuf-estr); | ||
| 296 | 		pad(f, ' ', w, pl+l, fl^LEFT_ADJ); | ||
| 297 | 		return MAX(w, pl+l); | ||
| 298 | 	} | ||
| 299 | 	if (p<0) p=6; | ||
| 300 | |||
| 301 | 	if (y) y *= 0x1p28, e2-=28; | ||
| 302 | |||
| 303 | 	if (e2<0) a=r=z=big; | ||
| 304 | 	else a=r=z=big+sizeof(big)/sizeof(*big) - LDBL_MANT_DIG - 1; | ||
| 305 | |||
| 306 | 	do { | ||
| 307 | 		*z = y; | ||
| 308 | 		y = 1000000000*(y-*z++); | ||
| 309 | 	} while (y); | ||
| 310 | |||
| 311 | 	while (e2>0) { | ||
| 312 | 		uint32_t carry=0; | ||
| 313 | 		int sh=MIN(29,e2); | ||
| 314 | 		for (d=z-1; d>=a; d--) { | ||
| 315 | 			uint64_t x = ((uint64_t)*d<<sh)+carry; | ||
| 316 | 			*d = x % 1000000000; | ||
| 317 | 			carry = x / 1000000000; | ||
| 318 | 		} | ||
| 319 | 		if (carry) *--a = carry; | ||
| 320 | 		while (z>a && !z[-1]) z--; | ||
| 321 | 		e2-=sh; | ||
| 322 | 	} | ||
| 323 | 	while (e2<0) { | ||
| 324 | 		uint32_t carry=0, *b; | ||
| 325 | 		int sh=MIN(9,-e2), need=1+(p+LDBL_MANT_DIG/3U+8)/9; | ||
| 326 | 		for (d=a; d<z; d++) { | ||
| 327 | 			uint32_t rm = *d & (1<<sh)-1; | ||
| 328 | 			*d = (*d>>sh) + carry; | ||
| 329 | 			carry = (1000000000>>sh) * rm; | ||
| 330 | 		} | ||
| 331 | 		if (!*a) a++; | ||
| 332 | 		if (carry) *z++ = carry; | ||
| 333 | 		/* Avoid (slow!) computation past requested precision */ | ||
| 334 | 		b = (t|32)=='f' ? r : a; | ||
| 335 | 		if (z-b > need) z = b+need; | ||
| 336 | 		e2+=sh; | ||
| 337 | 	} | ||
| 338 | |||
| 339 | 	if (a<z) for (i=10, e=9*(r-a); *a>=i; i*=10, e++); | ||
| 340 | 	else e=0; | ||
| 341 | |||
| 342 | 	/* Perform rounding: j is precision after the radix (possibly neg) */ | ||
| 343 | 	j = p - ((t|32)!='f')*e - ((t|32)=='g' && p); | ||
| 344 | 	if (j < 9*(z-r-1)) { | ||
| 345 | 		uint32_t x; | ||
| 346 | 		/* We avoid C's broken division of negative numbers */ | ||
| 347 | 		d = r + 1 + ((j+9*LDBL_MAX_EXP)/9 - LDBL_MAX_EXP); | ||
| 348 | 		j += 9*LDBL_MAX_EXP; | ||
| 349 | 		j %= 9; | ||
| 350 | 		for (i=10, j++; j<9; i*=10, j++); | ||
| 351 | 		x = *d % i; | ||
| 352 | 		/* Are there any significant digits past j? */ | ||
| 353 | 		if (x || d+1!=z) { | ||
| 354 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 355 | 			long_double round = 2/LDBL_EPSILON; | ||
| 356 | 			long_double small; | ||
| 357 | #else | ||
| 358 | 			long double round = 2/LDBL_EPSILON; | ||
| 359 | 			long double small; | ||
| 360 | #endif | ||
| 361 | 			if ((*d/i & 1) || (i==1000000000 && d>a && (d[-1]&1))) | ||
| 362 | 				round += 2; | ||
| 363 | 			if (x<i/2) small=0x0.8p0; | ||
| 364 | 			else if (x==i/2 && d+1==z) small=0x1.0p0; | ||
| 365 | 			else small=0x1.8p0; | ||
| 366 | 			if (pl && *prefix=='-') round*=-1, small*=-1; | ||
| 367 | 			*d -= x; | ||
| 368 | 			/* Decide whether to round by probing round+small */ | ||
| 369 | 			if (round+small != round) { | ||
| 370 | 				*d = *d + i; | ||
| 371 | 				while (*d > 999999999) { | ||
| 372 | 					*d--=0; | ||
| 373 | 					if (d<a) *--a=0; | ||
| 374 | 					(*d)++; | ||
| 375 | 				} | ||
| 376 | 				for (i=10, e=9*(r-a); *a>=i; i*=10, e++); | ||
| 377 | 			} | ||
| 378 | 		} | ||
| 379 | 		if (z>d+1) z=d+1; | ||
| 380 | 	} | ||
| 381 | 	for (; z>a && !z[-1]; z--); | ||
| 382 | 	 | ||
| 383 | 	if ((t|32)=='g') { | ||
| 384 | 		if (!p) p++; | ||
| 385 | 		if (p>e && e>=-4) { | ||
| 386 | 			t--; | ||
| 387 | 			p-=e+1; | ||
| 388 | 		} else { | ||
| 389 | 			t-=2; | ||
| 390 | 			p--; | ||
| 391 | 		} | ||
| 392 | 		if (!(fl&ALT_FORM)) { | ||
| 393 | 			/* Count trailing zeros in last place */ | ||
| 394 | 			if (z>a && z[-1]) for (i=10, j=0; z[-1]%i==0; i*=10, j++); | ||
| 395 | 			else j=9; | ||
| 396 | 			if ((t|32)=='f') | ||
| 397 | 				p = MIN(p,MAX(0,9*(z-r-1)-j)); | ||
| 398 | 			else | ||
| 399 | 				p = MIN(p,MAX(0,9*(z-r-1)+e-j)); | ||
| 400 | 		} | ||
| 401 | 	} | ||
| 402 | 	if (p > INT_MAX-1-(p || (fl&ALT_FORM))) | ||
| 403 | 		return -1; | ||
| 404 | 	l = 1 + p + (p || (fl&ALT_FORM)); | ||
| 405 | 	if ((t|32)=='f') { | ||
| 406 | 		if (e > INT_MAX-l) return -1; | ||
| 407 | 		if (e>0) l+=e; | ||
| 408 | 	} else { | ||
| 409 | 		estr=fmt_u(e<0 ? -e : e, ebuf); | ||
| 410 | 		while(ebuf-estr<2) *--estr='0'; | ||
| 411 | 		*--estr = (e<0 ? '-' : '+'); | ||
| 412 | 		*--estr = t; | ||
| 413 | 		if (ebuf-estr > INT_MAX-l) return -1; | ||
| 414 | 		l += ebuf-estr; | ||
| 415 | 	} | ||
| 416 | |||
| 417 | 	if (l > INT_MAX-pl) return -1; | ||
| 418 | 	pad(f, ' ', w, pl+l, fl); | ||
| 419 | 	out(f, prefix, pl); | ||
| 420 | 	pad(f, '0', w, pl+l, fl^ZERO_PAD); | ||
| 421 | |||
| 422 | 	if ((t|32)=='f') { | ||
| 423 | 		if (a>r) a=r; | ||
| 424 | 		for (d=a; d<=r; d++) { | ||
| 425 | 			char *s = fmt_u(*d, buf+9); | ||
| 426 | 			if (d!=a) while (s>buf) *--s='0'; | ||
| 427 | 			else if (s==buf+9) *--s='0'; | ||
| 428 | 			out(f, s, buf+9-s); | ||
| 429 | 		} | ||
| 430 | 		if (p || (fl&ALT_FORM)) out(f, ".", 1); | ||
| 431 | 		for (; d<z && p>0; d++, p-=9) { | ||
| 432 | 			char *s = fmt_u(*d, buf+9); | ||
| 433 | 			while (s>buf) *--s='0'; | ||
| 434 | 			out(f, s, MIN(9,p)); | ||
| 435 | 		} | ||
| 436 | 		pad(f, '0', p+9, 9, 0); | ||
| 437 | 	} else { | ||
| 438 | 		if (z<=a) z=a+1; | ||
| 439 | 		for (d=a; d<z && p>=0; d++) { | ||
| 440 | 			char *s = fmt_u(*d, buf+9); | ||
| 441 | 			if (s==buf+9) *--s='0'; | ||
| 442 | 			if (d!=a) while (s>buf) *--s='0'; | ||
| 443 | 			else { | ||
| 444 | 				out(f, s++, 1); | ||
| 445 | 				if (p>0||(fl&ALT_FORM)) out(f, ".", 1); | ||
| 446 | 			} | ||
| 447 | 			out(f, s, MIN(buf+9-s, p)); | ||
| 448 | 			p -= buf+9-s; | ||
| 449 | 		} | ||
| 450 | 		pad(f, '0', p+18, 18, 0); | ||
| 451 | 		out(f, estr, ebuf-estr); | ||
| 452 | 	} | ||
| 453 | |||
| 454 | 	pad(f, ' ', w, pl+l, fl^LEFT_ADJ); | ||
| 455 | |||
| 456 | 	return MAX(w, pl+l); | ||
| 457 | } | ||
| 458 | #endif | ||
| 459 | |||
| 460 | static int getint(char **s) { | ||
| 461 | 	int i; | ||
| 462 | 	for (i=0; isdigit(**s); (*s)++) { | ||
| 463 | 		if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; | ||
| 464 | 		else i = 10*i + (**s-'0'); | ||
| 465 | 	} | ||
| 466 | 	return i; | ||
| 467 | } | ||
| 468 | |||
| 469 | static int printf_core(FILE *f, const char *fmt, va_list *ap, union arg *nl_arg, int *nl_type) | ||
| 470 | { | ||
| 471 | 	char *a, *z, *s=(char *)fmt; | ||
| 472 | 	unsigned l10n=0, fl; | ||
| 473 | 	int w, p, xp; | ||
| 474 | 	union arg arg; | ||
| 475 | 	int argpos; | ||
| 476 | 	unsigned st, ps; | ||
| 477 | 	int cnt=0, l=0; | ||
| 478 | 	size_t i; | ||
| 479 | 	char buf[sizeof(uintmax_t)*3]; | ||
| 480 | 	const char *prefix; | ||
| 481 | 	int t, pl; | ||
| 482 | 	wchar_t wc[2], *ws; | ||
| 483 | 	char mb[4]; | ||
| 484 | |||
| 485 | 	for (;;) { | ||
| 486 | 		/* This error is only specified for snprintf, but since it's | ||
| 487 | 		 * unspecified for other forms, do the same. Stop immediately | ||
| 488 | 		 * on overflow; otherwise %n could produce wrong results. */ | ||
| 489 | 		if (l > INT_MAX - cnt) goto overflow; | ||
| 490 | |||
| 491 | 		/* Update output count, end loop when fmt is exhausted */ | ||
| 492 | 		cnt += l; | ||
| 493 | 		if (!*s) break; | ||
| 494 | |||
| 495 | 		/* Handle literal text and %% format specifiers */ | ||
| 496 | 		for (a=s; *s && *s!='%'; s++); | ||
| 497 | 		for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); | ||
| 498 | 		if (z-a > INT_MAX-cnt) goto overflow; | ||
| 499 | 		l = z-a; | ||
| 500 | 		if (f) out(f, a, l); | ||
| 501 | 		if (l) continue; | ||
| 502 | |||
| 503 | 		if (isdigit(s[1]) && s[2]=='$') { | ||
| 504 | 			l10n=1; | ||
| 505 | 			argpos = s[1]-'0'; | ||
| 506 | 			s+=3; | ||
| 507 | 		} else { | ||
| 508 | 			argpos = -1; | ||
| 509 | 			s++; | ||
| 510 | 		} | ||
| 511 | |||
| 512 | 		/* Read modifier flags */ | ||
| 513 | 		for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) | ||
| 514 | 			fl |= 1U<<*s-' '; | ||
| 515 | |||
| 516 | 		/* Read field width */ | ||
| 517 | 		if (*s=='*') { | ||
| 518 | 			if (isdigit(s[1]) && s[2]=='$') { | ||
| 519 | 				l10n=1; | ||
| 520 | 				if (!f) nl_type[s[1]-'0'] = INT, w = 0; | ||
| 521 | 				else w = nl_arg[s[1]-'0'].i; | ||
| 522 | 				s+=3; | ||
| 523 | 			} else if (!l10n) { | ||
| 524 | 				w = f ? va_arg(*ap, int) : 0; | ||
| 525 | 				s++; | ||
| 526 | 			} else goto inval; | ||
| 527 | 			if (w<0) fl|=LEFT_ADJ, w=-w; | ||
| 528 | 		} else if ((w=getint(&s))<0) goto overflow; | ||
| 529 | |||
| 530 | 		/* Read precision */ | ||
| 531 | 		if (*s=='.' && s[1]=='*') { | ||
| 532 | 			if (isdigit(s[2]) && s[3]=='$') { | ||
| 533 | 				if (!f) nl_type[s[2]-'0'] = INT, p = 0; | ||
| 534 | 				else p = nl_arg[s[2]-'0'].i; | ||
| 535 | 				s+=4; | ||
| 536 | 			} else if (!l10n) { | ||
| 537 | 				p = f ? va_arg(*ap, int) : 0; | ||
| 538 | 				s+=2; | ||
| 539 | 			} else goto inval; | ||
| 540 | 			xp = (p>=0); | ||
| 541 | 		} else if (*s=='.') { | ||
| 542 | 			s++; | ||
| 543 | 			p = getint(&s); | ||
| 544 | 			xp = 1; | ||
| 545 | 		} else { | ||
| 546 | 			p = -1; | ||
| 547 | 			xp = 0; | ||
| 548 | 		} | ||
| 549 | |||
| 550 | 		/* Format specifier state machine */ | ||
| 551 | 		st=0; | ||
| 552 | 		do { | ||
| 553 | 			if (OOB(*s)) goto inval; | ||
| 554 | 			ps=st; | ||
| 555 | 			st=states[st]S(*s++); | ||
| 556 | 		} while (st-1<STOP); | ||
| 557 | 		if (!st) goto inval; | ||
| 558 | |||
| 559 | 		/* Check validity of argument type (nl/normal) */ | ||
| 560 | 		if (st==NOARG) { | ||
| 561 | 			if (argpos>=0) goto inval; | ||
| 562 | 		} else { | ||
| 563 | 			if (argpos>=0) { | ||
| 564 | 				if (!f) nl_type[argpos]=st; | ||
| 565 | 				else arg=nl_arg[argpos]; | ||
| 566 | 			} else if (f) pop_arg(&arg, st, ap); | ||
| 567 | 			else return 0; | ||
| 568 | 		} | ||
| 569 | |||
| 570 | 		if (!f) continue; | ||
| 571 | |||
| 572 | 		/* Do not process any new directives once in error state. */ | ||
| 573 | 		if (ferror(f)) return -1; | ||
| 574 | |||
| 575 | 		z = buf + sizeof(buf); | ||
| 576 | 		prefix = "-+ 0X0x"; | ||
| 577 | 		pl = 0; | ||
| 578 | 		t = s[-1]; | ||
| 579 | |||
| 580 | 		/* Transform ls,lc -> S,C */ | ||
| 581 | 		if (ps && (t&15)==3) t&=~32; | ||
| 582 | |||
| 583 | 		/* - and 0 flags are mutually exclusive */ | ||
| 584 | 		if (fl & LEFT_ADJ) fl &= ~ZERO_PAD; | ||
| 585 | |||
| 586 | 		switch(t) { | ||
| 587 | 		case 'n': | ||
| 588 | 			switch(ps) { | ||
| 589 | 			case BARE: *(int *)arg.p = cnt; break; | ||
| 590 | 			case LPRE: *(long *)arg.p = cnt; break; | ||
| 591 | 			case LLPRE: *(long long *)arg.p = cnt; break; | ||
| 592 | 			case HPRE: *(unsigned short *)arg.p = cnt; break; | ||
| 593 | 			case HHPRE: *(unsigned char *)arg.p = cnt; break; | ||
| 594 | 			case ZTPRE: *(size_t *)arg.p = cnt; break; | ||
| 595 | 			case JPRE: *(uintmax_t *)arg.p = cnt; break; | ||
| 596 | 			} | ||
| 597 | 			continue; | ||
| 598 | 		case 'p': | ||
| 599 | 			p = MAX(p, 2*sizeof(void*)); | ||
| 600 | 			t = 'x'; | ||
| 601 | 			fl |= ALT_FORM; | ||
| 602 | 		case 'x': case 'X': | ||
| 603 | 			a = fmt_x(arg.i, z, t&32); | ||
| 604 | 			if (arg.i && (fl & ALT_FORM)) prefix+=(t>>4), pl=2; | ||
| 605 | 			if (0) { | ||
| 606 | 		case 'o': | ||
| 607 | 			a = fmt_o(arg.i, z); | ||
| 608 | 			if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1; | ||
| 609 | 			} if (0) { | ||
| 610 | 		case 'd': case 'i': | ||
| 611 | 			pl=1; | ||
| 612 | 			if (arg.i>INTMAX_MAX) { | ||
| 613 | 				arg.i=-arg.i; | ||
| 614 | 			} else if (fl & MARK_POS) { | ||
| 615 | 				prefix++; | ||
| 616 | 			} else if (fl & PAD_POS) { | ||
| 617 | 				prefix+=2; | ||
| 618 | 			} else pl=0; | ||
| 619 | 		case 'u': | ||
| 620 | 			a = fmt_u(arg.i, z); | ||
| 621 | 			} | ||
| 622 | 			if (xp && p<0) goto overflow; | ||
| 623 | 			if (xp) fl &= ~ZERO_PAD; | ||
| 624 | 			if (!arg.i && !p) { | ||
| 625 | 				a=z; | ||
| 626 | 				break; | ||
| 627 | 			} | ||
| 628 | 			p = MAX(p, z-a + !arg.i); | ||
| 629 | 			break; | ||
| 630 | 		narrow_c: | ||
| 631 | 		case 'c': | ||
| 632 | 			*(a=z-(p=1))=arg.i; | ||
| 633 | 			fl &= ~ZERO_PAD; | ||
| 634 | 			break; | ||
| 635 | 		case 'm': | ||
| 636 | 			if (1) a = strerror(errno); else | ||
| 637 | 		case 's': | ||
| 638 | 			a = arg.p ? arg.p : "(null)"; | ||
| 639 | 			z = a + strnlen(a, p<0 ? INT_MAX : p); | ||
| 640 | 			if (p<0 && *z) goto overflow; | ||
| 641 | 			p = z-a; | ||
| 642 | 			fl &= ~ZERO_PAD; | ||
| 643 | 			break; | ||
| 644 | 		case 'C': | ||
| 645 | 			if (!arg.i) goto narrow_c; | ||
| 646 | 			wc[0] = arg.i; | ||
| 647 | 			wc[1] = 0; | ||
| 648 | 			arg.p = wc; | ||
| 649 | 			p = -1; | ||
| 650 | 		case 'S': | ||
| 651 | 			ws = arg.p; | ||
| 652 | 			for (i=l=0; i<p && *ws && (l=wctomb(mb, *ws++))>=0 && l<=p-i; i+=l); | ||
| 653 | 			if (l<0) return -1; | ||
| 654 | 			if (i > INT_MAX) goto overflow; | ||
| 655 | 			p = i; | ||
| 656 | 			pad(f, ' ', w, p, fl); | ||
| 657 | 			ws = arg.p; | ||
| 658 | 			for (i=0; i<0U+p && *ws && i+(l=wctomb(mb, *ws++))<=p; i+=l) | ||
| 659 | 				out(f, mb, l); | ||
| 660 | 			pad(f, ' ', w, p, fl^LEFT_ADJ); | ||
| 661 | 			l = w>p ? w : p; | ||
| 662 | 			continue; | ||
| 663 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 664 | 		case 'e': case 'f': case 'g': case 'a': | ||
| 665 | 		case 'E': case 'F': case 'G': case 'A': | ||
| 666 | 			if (xp && p<0) goto overflow; | ||
| 667 | 			l = fmt_fp(f, arg.f, w, p, fl, t); | ||
| 668 | 			if (l<0) goto overflow; | ||
| 669 | 			continue; | ||
| 670 | #endif | ||
| 671 | 		} | ||
| 672 | |||
| 673 | 		if (p < z-a) p = z-a; | ||
| 674 | 		if (p > INT_MAX-pl) goto overflow; | ||
| 675 | 		if (w < pl+p) w = pl+p; | ||
| 676 | 		if (w > INT_MAX-cnt) goto overflow; | ||
| 677 | |||
| 678 | 		pad(f, ' ', w, pl+p, fl); | ||
| 679 | 		out(f, prefix, pl); | ||
| 680 | 		pad(f, '0', w, pl+p, fl^ZERO_PAD); | ||
| 681 | 		pad(f, '0', p, z-a, 0); | ||
| 682 | 		out(f, a, z-a); | ||
| 683 | 		pad(f, ' ', w, pl+p, fl^LEFT_ADJ); | ||
| 684 | |||
| 685 | 		l = w; | ||
| 686 | 	} | ||
| 687 | |||
| 688 | 	if (f) return cnt; | ||
| 689 | 	if (!l10n) return 0; | ||
| 690 | |||
| 691 | 	for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) | ||
| 692 | 		pop_arg(nl_arg+i, nl_type[i], ap); | ||
| 693 | 	for (; i<=NL_ARGMAX && !nl_type[i]; i++); | ||
| 694 | 	if (i<=NL_ARGMAX) goto inval; | ||
| 695 | 	return 1; | ||
| 696 | |||
| 697 | inval: | ||
| 698 | 	errno = EINVAL; | ||
| 699 | 	return -1; | ||
| 700 | overflow: | ||
| 701 | 	errno = EOVERFLOW; | ||
| 702 | 	return -1; | ||
| 703 | } | ||
| 704 | |||
| 705 | int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) | ||
| 706 | { | ||
| 707 | 	va_list ap2; | ||
| 708 | 	int nl_type[NL_ARGMAX+1] = {0}; | ||
| 709 | 	union arg nl_arg[NL_ARGMAX+1]; | ||
| 710 | 	unsigned char internal_buf[80], *saved_buf = 0; | ||
| 711 | 	int olderr; | ||
| 712 | 	int ret; | ||
| 713 | |||
| 714 | 	/* the copy allows passing va_list* even if va_list is an array */ | ||
| 715 | 	va_copy(ap2, ap); | ||
| 716 | 	if (printf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { | ||
| 717 | 		va_end(ap2); | ||
| 718 | 		return -1; | ||
| 719 | 	} | ||
| 720 | |||
| 721 | 	FLOCK(f); | ||
| 722 | 	olderr = f->flags & F_ERR; | ||
| 723 | 	f->flags &= ~F_ERR; | ||
| 724 | 	if (!f->buf_size) { | ||
| 725 | 		saved_buf = f->buf; | ||
| 726 | 		f->buf = internal_buf; | ||
| 727 | 		f->buf_size = sizeof internal_buf; | ||
| 728 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 729 | 	} | ||
| 730 | 	if (!f->wend && __towrite(f)) ret = -1; | ||
| 731 | 	else ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); | ||
| 732 | 	if (saved_buf) { | ||
| 733 | 		f->write(f, 0, 0); | ||
| 734 | 		if (!f->wpos) ret = -1; | ||
| 735 | 		f->buf = saved_buf; | ||
| 736 | 		f->buf_size = 0; | ||
| 737 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 738 | 	} | ||
| 739 | 	if (ferror(f)) ret = -1; | ||
| 740 | 	f->flags |= olderr; | ||
| 741 | 	FUNLOCK(f); | ||
| 742 | 	va_end(ap2); | ||
| 743 | 	return ret; | ||
| 744 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vfscanf.c deleted-351| ... | @@ -1,351 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <ctype.h> | ||
| 4 | #include <wchar.h> | ||
| 5 | #include <wctype.h> | ||
| 6 | #include <limits.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdint.h> | ||
| 9 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 10 | #else | ||
| 11 | #include "printscan.h" | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #include "stdio_impl.h" | ||
| 15 | #include "shgetc.h" | ||
| 16 | #include "intscan.h" | ||
| 17 | #include "floatscan.h" | ||
| 18 | |||
| 19 | #define SIZE_hh -2 | ||
| 20 | #define SIZE_h -1 | ||
| 21 | #define SIZE_def 0 | ||
| 22 | #define SIZE_l 1 | ||
| 23 | #define SIZE_L 2 | ||
| 24 | #define SIZE_ll 3 | ||
| 25 | |||
| 26 | static void store_int(void *dest, int size, unsigned long long i) | ||
| 27 | { | ||
| 28 | 	if (!dest) return; | ||
| 29 | 	switch (size) { | ||
| 30 | 	case SIZE_hh: | ||
| 31 | 		*(char *)dest = i; | ||
| 32 | 		break; | ||
| 33 | 	case SIZE_h: | ||
| 34 | 		*(short *)dest = i; | ||
| 35 | 		break; | ||
| 36 | 	case SIZE_def: | ||
| 37 | 		*(int *)dest = i; | ||
| 38 | 		break; | ||
| 39 | 	case SIZE_l: | ||
| 40 | 		*(long *)dest = i; | ||
| 41 | 		break; | ||
| 42 | 	case SIZE_ll: | ||
| 43 | 		*(long long *)dest = i; | ||
| 44 | 		break; | ||
| 45 | 	} | ||
| 46 | } | ||
| 47 | |||
| 48 | static void *arg_n(va_list ap, unsigned int n) | ||
| 49 | { | ||
| 50 | 	void *p; | ||
| 51 | 	unsigned int i; | ||
| 52 | 	va_list ap2; | ||
| 53 | 	va_copy(ap2, ap); | ||
| 54 | 	for (i=n; i>1; i--) va_arg(ap2, void *); | ||
| 55 | 	p = va_arg(ap2, void *); | ||
| 56 | 	va_end(ap2); | ||
| 57 | 	return p; | ||
| 58 | } | ||
| 59 | |||
| 60 | int vfscanf(FILE *restrict f, const char *restrict fmt, va_list ap) | ||
| 61 | { | ||
| 62 | 	int width; | ||
| 63 | 	int size; | ||
| 64 | 	int alloc = 0; | ||
| 65 | 	int base; | ||
| 66 | 	const unsigned char *p; | ||
| 67 | 	int c, t; | ||
| 68 | 	char *s; | ||
| 69 | 	wchar_t *wcs; | ||
| 70 | 	mbstate_t st; | ||
| 71 | 	void *dest=NULL; | ||
| 72 | 	int invert; | ||
| 73 | 	int matches=0; | ||
| 74 | 	unsigned long long x; | ||
| 75 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 76 | 	long_double y; | ||
| 77 | #else | ||
| 78 | 	long double y; | ||
| 79 | #endif | ||
| 80 | 	off_t pos = 0; | ||
| 81 | 	unsigned char scanset[257]; | ||
| 82 | 	size_t i, k; | ||
| 83 | 	wchar_t wc; | ||
| 84 | |||
| 85 | 	FLOCK(f); | ||
| 86 | |||
| 87 | 	if (!f->rpos) __toread(f); | ||
| 88 | 	if (!f->rpos) goto input_fail; | ||
| 89 | |||
| 90 | 	for (p=(const unsigned char *)fmt; *p; p++) { | ||
| 91 | |||
| 92 | 		alloc = 0; | ||
| 93 | |||
| 94 | 		if (isspace(*p)) { | ||
| 95 | 			while (isspace(p[1])) p++; | ||
| 96 | 			shlim(f, 0); | ||
| 97 | 			while (isspace(shgetc(f))); | ||
| 98 | 			shunget(f); | ||
| 99 | 			pos += shcnt(f); | ||
| 100 | 			continue; | ||
| 101 | 		} | ||
| 102 | 		if (*p != '%' || p[1] == '%') { | ||
| 103 | 			shlim(f, 0); | ||
| 104 | 			if (*p == '%') { | ||
| 105 | 				p++; | ||
| 106 | 				while (isspace((c=shgetc(f)))); | ||
| 107 | 			} else { | ||
| 108 | 				c = shgetc(f); | ||
| 109 | 			} | ||
| 110 | 			if (c!=*p) { | ||
| 111 | 				shunget(f); | ||
| 112 | 				if (c<0) goto input_fail; | ||
| 113 | 				goto match_fail; | ||
| 114 | 			} | ||
| 115 | 			pos += shcnt(f); | ||
| 116 | 			continue; | ||
| 117 | 		} | ||
| 118 | |||
| 119 | 		p++; | ||
| 120 | 		if (*p=='*') { | ||
| 121 | 			dest = 0; p++; | ||
| 122 | 		} else if (isdigit(*p) && p[1]=='$') { | ||
| 123 | 			dest = arg_n(ap, *p-'0'); p+=2; | ||
| 124 | 		} else { | ||
| 125 | 			dest = va_arg(ap, void *); | ||
| 126 | 		} | ||
| 127 | |||
| 128 | 		for (width=0; isdigit(*p); p++) { | ||
| 129 | 			width = 10*width + *p - '0'; | ||
| 130 | 		} | ||
| 131 | |||
| 132 | 		if (*p=='m') { | ||
| 133 | 			wcs = 0; | ||
| 134 | 			s = 0; | ||
| 135 | 			alloc = !!dest; | ||
| 136 | 			p++; | ||
| 137 | 		} else { | ||
| 138 | 			alloc = 0; | ||
| 139 | 		} | ||
| 140 | |||
| 141 | 		size = SIZE_def; | ||
| 142 | 		switch (*p++) { | ||
| 143 | 		case 'h': | ||
| 144 | 			if (*p == 'h') p++, size = SIZE_hh; | ||
| 145 | 			else size = SIZE_h; | ||
| 146 | 			break; | ||
| 147 | 		case 'l': | ||
| 148 | 			if (*p == 'l') p++, size = SIZE_ll; | ||
| 149 | 			else size = SIZE_l; | ||
| 150 | 			break; | ||
| 151 | 		case 'j': | ||
| 152 | 			size = SIZE_ll; | ||
| 153 | 			break; | ||
| 154 | 		case 'z': | ||
| 155 | 		case 't': | ||
| 156 | 			size = SIZE_l; | ||
| 157 | 			break; | ||
| 158 | 		case 'L': | ||
| 159 | 			size = SIZE_L; | ||
| 160 | 			break; | ||
| 161 | 		case 'd': case 'i': case 'o': case 'u': case 'x': | ||
| 162 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 163 | 		case 'A': case 'E': case 'F': case 'G': case 'X': | ||
| 164 | 		case 's': case 'c': case '[': | ||
| 165 | 		case 'S': case 'C': | ||
| 166 | 		case 'p': case 'n': | ||
| 167 | 			p--; | ||
| 168 | 			break; | ||
| 169 | 		default: | ||
| 170 | 			goto fmt_fail; | ||
| 171 | 		} | ||
| 172 | |||
| 173 | 		t = *p; | ||
| 174 | |||
| 175 | 		/* C or S */ | ||
| 176 | 		if ((t&0x2f) == 3) { | ||
| 177 | 			t |= 32; | ||
| 178 | 			size = SIZE_l; | ||
| 179 | 		} | ||
| 180 | |||
| 181 | 		switch (t) { | ||
| 182 | 		case 'c': | ||
| 183 | 			if (width < 1) width = 1; | ||
| 184 | 		case '[': | ||
| 185 | 			break; | ||
| 186 | 		case 'n': | ||
| 187 | 			store_int(dest, size, pos); | ||
| 188 | 			/* do not increment match count, etc! */ | ||
| 189 | 			continue; | ||
| 190 | 		default: | ||
| 191 | 			shlim(f, 0); | ||
| 192 | 			while (isspace(shgetc(f))); | ||
| 193 | 			shunget(f); | ||
| 194 | 			pos += shcnt(f); | ||
| 195 | 		} | ||
| 196 | |||
| 197 | 		shlim(f, width); | ||
| 198 | 		if (shgetc(f) < 0) goto input_fail; | ||
| 199 | 		shunget(f); | ||
| 200 | |||
| 201 | 		switch (t) { | ||
| 202 | 		case 's': | ||
| 203 | 		case 'c': | ||
| 204 | 		case '[': | ||
| 205 | 			if (t == 'c' || t == 's') { | ||
| 206 | 				memset(scanset, -1, sizeof scanset); | ||
| 207 | 				scanset[0] = 0; | ||
| 208 | 				if (t == 's') { | ||
| 209 | 					scanset[1+'\t'] = 0; | ||
| 210 | 					scanset[1+'\n'] = 0; | ||
| 211 | 					scanset[1+'\v'] = 0; | ||
| 212 | 					scanset[1+'\f'] = 0; | ||
| 213 | 					scanset[1+'\r'] = 0; | ||
| 214 | 					scanset[1+' '] = 0; | ||
| 215 | 				} | ||
| 216 | 			} else { | ||
| 217 | 				if (*++p == '^') p++, invert = 1; | ||
| 218 | 				else invert = 0; | ||
| 219 | 				memset(scanset, invert, sizeof scanset); | ||
| 220 | 				scanset[0] = 0; | ||
| 221 | 				if (*p == '-') p++, scanset[1+'-'] = 1-invert; | ||
| 222 | 				else if (*p == ']') p++, scanset[1+']'] = 1-invert; | ||
| 223 | 				for (; *p != ']'; p++) { | ||
| 224 | 					if (!*p) goto fmt_fail; | ||
| 225 | 					if (*p=='-' && p[1] && p[1] != ']') | ||
| 226 | 						for (c=p++[-1]; c<*p; c++) | ||
| 227 | 							scanset[1+c] = 1-invert; | ||
| 228 | 					scanset[1+*p] = 1-invert; | ||
| 229 | 				} | ||
| 230 | 			} | ||
| 231 | 			wcs = 0; | ||
| 232 | 			s = 0; | ||
| 233 | 			i = 0; | ||
| 234 | 			k = t=='c' ? width+1U : 31; | ||
| 235 | 			if (size == SIZE_l) { | ||
| 236 | 				if (alloc) { | ||
| 237 | 					wcs = malloc(k*sizeof(wchar_t)); | ||
| 238 | 					if (!wcs) goto alloc_fail; | ||
| 239 | 				} else { | ||
| 240 | 					wcs = dest; | ||
| 241 | 				} | ||
| 242 | 				st = (mbstate_t){0}; | ||
| 243 | 				while (scanset[(c=shgetc(f))+1]) { | ||
| 244 | 					switch (mbrtowc(&wc, &(char){c}, 1, &st)) { | ||
| 245 | 					case -1: | ||
| 246 | 						goto input_fail; | ||
| 247 | 					case -2: | ||
| 248 | 						continue; | ||
| 249 | 					} | ||
| 250 | 					if (wcs) wcs[i++] = wc; | ||
| 251 | 					if (alloc && i==k) { | ||
| 252 | 						k+=k+1; | ||
| 253 | 						wchar_t *tmp = realloc(wcs, k*sizeof(wchar_t)); | ||
| 254 | 						if (!tmp) goto alloc_fail; | ||
| 255 | 						wcs = tmp; | ||
| 256 | 					} | ||
| 257 | 				} | ||
| 258 | 				if (!mbsinit(&st)) goto input_fail; | ||
| 259 | 			} else if (alloc) { | ||
| 260 | 				s = malloc(k); | ||
| 261 | 				if (!s) goto alloc_fail; | ||
| 262 | 				while (scanset[(c=shgetc(f))+1]) { | ||
| 263 | 					s[i++] = c; | ||
| 264 | 					if (i==k) { | ||
| 265 | 						k+=k+1; | ||
| 266 | 						char *tmp = realloc(s, k); | ||
| 267 | 						if (!tmp) goto alloc_fail; | ||
| 268 | 						s = tmp; | ||
| 269 | 					} | ||
| 270 | 				} | ||
| 271 | 			} else if ((s = dest)) { | ||
| 272 | 				while (scanset[(c=shgetc(f))+1]) | ||
| 273 | 					s[i++] = c; | ||
| 274 | 			} else { | ||
| 275 | 				while (scanset[(c=shgetc(f))+1]); | ||
| 276 | 			} | ||
| 277 | 			shunget(f); | ||
| 278 | 			if (!shcnt(f)) goto match_fail; | ||
| 279 | 			if (t == 'c' && shcnt(f) != width) goto match_fail; | ||
| 280 | 			if (alloc) { | ||
| 281 | 				if (size == SIZE_l) *(wchar_t **)dest = wcs; | ||
| 282 | 				else *(char **)dest = s; | ||
| 283 | 			} | ||
| 284 | 			if (t != 'c') { | ||
| 285 | 				if (wcs) wcs[i] = 0; | ||
| 286 | 				if (s) s[i] = 0; | ||
| 287 | 			} | ||
| 288 | 			break; | ||
| 289 | 		case 'p': | ||
| 290 | 		case 'X': | ||
| 291 | 		case 'x': | ||
| 292 | 			base = 16; | ||
| 293 | 			goto int_common; | ||
| 294 | 		case 'o': | ||
| 295 | 			base = 8; | ||
| 296 | 			goto int_common; | ||
| 297 | 		case 'd': | ||
| 298 | 		case 'u': | ||
| 299 | 			base = 10; | ||
| 300 | 			goto int_common; | ||
| 301 | 		case 'i': | ||
| 302 | 			base = 0; | ||
| 303 | 		int_common: | ||
| 304 | 			x = __intscan(f, base, 0, ULLONG_MAX); | ||
| 305 | 			if (!shcnt(f)) goto match_fail; | ||
| 306 | 			if (t=='p' && dest) *(void **)dest = (void *)(uintptr_t)x; | ||
| 307 | 			else store_int(dest, size, x); | ||
| 308 | 			break; | ||
| 309 | 		case 'a': case 'A': | ||
| 310 | 		case 'e': case 'E': | ||
| 311 | 		case 'f': case 'F': | ||
| 312 | 		case 'g': case 'G': | ||
| 313 | 			y = __floatscan(f, size, 0); | ||
| 314 | 			if (!shcnt(f)) goto match_fail; | ||
| 315 | 			if (dest) switch (size) { | ||
| 316 | 			case SIZE_def: | ||
| 317 | 				*(float *)dest = y; | ||
| 318 | 				break; | ||
| 319 | 			case SIZE_l: | ||
| 320 | 				*(double *)dest = y; | ||
| 321 | 				break; | ||
| 322 | 			case SIZE_L: | ||
| 323 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 324 | 				long_double_not_supported(); | ||
| 325 | #else | ||
| 326 | 				*(long double *)dest = y; | ||
| 327 | #endif | ||
| 328 | 				break; | ||
| 329 | 			} | ||
| 330 | 			break; | ||
| 331 | 		} | ||
| 332 | |||
| 333 | 		pos += shcnt(f); | ||
| 334 | 		if (dest) matches++; | ||
| 335 | 	} | ||
| 336 | 	if (0) { | ||
| 337 | fmt_fail: | ||
| 338 | alloc_fail: | ||
| 339 | input_fail: | ||
| 340 | 		if (!matches) matches--; | ||
| 341 | match_fail: | ||
| 342 | 		if (alloc) { | ||
| 343 | 			free(s); | ||
| 344 | 			free(wcs); | ||
| 345 | 		} | ||
| 346 | 	} | ||
| 347 | 	FUNLOCK(f); | ||
| 348 | 	return matches; | ||
| 349 | } | ||
| 350 | |||
| 351 | weak_alias(vfscanf,__isoc99_vfscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vfwprintf.c deleted-421| ... | @@ -1,421 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | #include <ctype.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stdarg.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include <wchar.h> | ||
| 10 | #include <inttypes.h> | ||
| 11 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 12 | #else | ||
| 13 | #include "printscan.h" | ||
| 14 | #endif | ||
| 15 | |||
| 16 | /* Convenient bit representation for modifier flags, which all fall | ||
| 17 | * within 31 codepoints of the space character. */ | ||
| 18 | |||
| 19 | #define ALT_FORM (1U<<'#'-' ') | ||
| 20 | #define ZERO_PAD (1U<<'0'-' ') | ||
| 21 | #define LEFT_ADJ (1U<<'-'-' ') | ||
| 22 | #define PAD_POS (1U<<' '-' ') | ||
| 23 | #define MARK_POS (1U<<'+'-' ') | ||
| 24 | #define GROUPED (1U<<'\''-' ') | ||
| 25 | |||
| 26 | #define FLAGMASK (ALT_FORM|ZERO_PAD|LEFT_ADJ|PAD_POS|MARK_POS|GROUPED) | ||
| 27 | |||
| 28 | /* State machine to accept length modifiers + conversion specifiers. | ||
| 29 | * Result is 0 on failure, or an argument type to pop on success. */ | ||
| 30 | |||
| 31 | enum { | ||
| 32 | 	BARE, LPRE, LLPRE, HPRE, HHPRE, BIGLPRE, | ||
| 33 | 	ZTPRE, JPRE, | ||
| 34 | 	STOP, | ||
| 35 | 	PTR, INT, UINT, ULLONG, | ||
| 36 | 	LONG, ULONG, | ||
| 37 | 	SHORT, USHORT, CHAR, UCHAR, | ||
| 38 | 	LLONG, SIZET, IMAX, UMAX, PDIFF, UIPTR, | ||
| 39 | 	DBL, LDBL, | ||
| 40 | 	NOARG, | ||
| 41 | 	MAXSTATE | ||
| 42 | }; | ||
| 43 | |||
| 44 | #define S(x) [(x)-'A'] | ||
| 45 | |||
| 46 | static const unsigned char states[]['z'-'A'+1] = { | ||
| 47 | 	{ /* 0: bare types */ | ||
| 48 | 		S('d') = INT, S('i') = INT, | ||
| 49 | 		S('o') = UINT, S('u') = UINT, S('x') = UINT, S('X') = UINT, | ||
| 50 | 		S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, | ||
| 51 | 		S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, | ||
| 52 | 		S('c') = INT, S('C') = UINT, | ||
| 53 | 		S('s') = PTR, S('S') = PTR, S('p') = UIPTR, S('n') = PTR, | ||
| 54 | 		S('m') = NOARG, | ||
| 55 | 		S('l') = LPRE, S('h') = HPRE, S('L') = BIGLPRE, | ||
| 56 | 		S('z') = ZTPRE, S('j') = JPRE, S('t') = ZTPRE, | ||
| 57 | 	}, { /* 1: l-prefixed */ | ||
| 58 | 		S('d') = LONG, S('i') = LONG, | ||
| 59 | 		S('o') = ULONG, S('u') = ULONG, S('x') = ULONG, S('X') = ULONG, | ||
| 60 | 		S('e') = DBL, S('f') = DBL, S('g') = DBL, S('a') = DBL, | ||
| 61 | 		S('E') = DBL, S('F') = DBL, S('G') = DBL, S('A') = DBL, | ||
| 62 | 		S('c') = UINT, S('s') = PTR, S('n') = PTR, | ||
| 63 | 		S('l') = LLPRE, | ||
| 64 | 	}, { /* 2: ll-prefixed */ | ||
| 65 | 		S('d') = LLONG, S('i') = LLONG, | ||
| 66 | 		S('o') = ULLONG, S('u') = ULLONG, | ||
| 67 | 		S('x') = ULLONG, S('X') = ULLONG, | ||
| 68 | 		S('n') = PTR, | ||
| 69 | 	}, { /* 3: h-prefixed */ | ||
| 70 | 		S('d') = SHORT, S('i') = SHORT, | ||
| 71 | 		S('o') = USHORT, S('u') = USHORT, | ||
| 72 | 		S('x') = USHORT, S('X') = USHORT, | ||
| 73 | 		S('n') = PTR, | ||
| 74 | 		S('h') = HHPRE, | ||
| 75 | 	}, { /* 4: hh-prefixed */ | ||
| 76 | 		S('d') = CHAR, S('i') = CHAR, | ||
| 77 | 		S('o') = UCHAR, S('u') = UCHAR, | ||
| 78 | 		S('x') = UCHAR, S('X') = UCHAR, | ||
| 79 | 		S('n') = PTR, | ||
| 80 | 	}, { /* 5: L-prefixed */ | ||
| 81 | 		S('e') = LDBL, S('f') = LDBL, S('g') = LDBL, S('a') = LDBL, | ||
| 82 | 		S('E') = LDBL, S('F') = LDBL, S('G') = LDBL, S('A') = LDBL, | ||
| 83 | 		S('n') = PTR, | ||
| 84 | 	}, { /* 6: z- or t-prefixed (assumed to be same size) */ | ||
| 85 | 		S('d') = PDIFF, S('i') = PDIFF, | ||
| 86 | 		S('o') = SIZET, S('u') = SIZET, | ||
| 87 | 		S('x') = SIZET, S('X') = SIZET, | ||
| 88 | 		S('n') = PTR, | ||
| 89 | 	}, { /* 7: j-prefixed */ | ||
| 90 | 		S('d') = IMAX, S('i') = IMAX, | ||
| 91 | 		S('o') = UMAX, S('u') = UMAX, | ||
| 92 | 		S('x') = UMAX, S('X') = UMAX, | ||
| 93 | 		S('n') = PTR, | ||
| 94 | 	} | ||
| 95 | }; | ||
| 96 | |||
| 97 | #define OOB(x) ((unsigned)(x)-'A' > 'z'-'A') | ||
| 98 | |||
| 99 | union arg | ||
| 100 | { | ||
| 101 | 	uintmax_t i; | ||
| 102 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 103 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 104 | 	long_double f; | ||
| 105 | #else | ||
| 106 | 	long double f; | ||
| 107 | #endif | ||
| 108 | #endif | ||
| 109 | 	void *p; | ||
| 110 | }; | ||
| 111 | |||
| 112 | static void pop_arg(union arg *arg, int type, va_list *ap) | ||
| 113 | { | ||
| 114 | 	switch (type) { | ||
| 115 | 	 case PTR:	arg->p = va_arg(*ap, void *); | ||
| 116 | 	break; case INT:	arg->i = va_arg(*ap, int); | ||
| 117 | 	break; case UINT:	arg->i = va_arg(*ap, unsigned int); | ||
| 118 | 	break; case LONG:	arg->i = va_arg(*ap, long); | ||
| 119 | 	break; case ULONG:	arg->i = va_arg(*ap, unsigned long); | ||
| 120 | 	break; case ULLONG:	arg->i = va_arg(*ap, unsigned long long); | ||
| 121 | 	break; case SHORT:	arg->i = (short)va_arg(*ap, int); | ||
| 122 | 	break; case USHORT:	arg->i = (unsigned short)va_arg(*ap, int); | ||
| 123 | 	break; case CHAR:	arg->i = (signed char)va_arg(*ap, int); | ||
| 124 | 	break; case UCHAR:	arg->i = (unsigned char)va_arg(*ap, int); | ||
| 125 | 	break; case LLONG:	arg->i = va_arg(*ap, long long); | ||
| 126 | 	break; case SIZET:	arg->i = va_arg(*ap, size_t); | ||
| 127 | 	break; case IMAX:	arg->i = va_arg(*ap, intmax_t); | ||
| 128 | 	break; case UMAX:	arg->i = va_arg(*ap, uintmax_t); | ||
| 129 | 	break; case PDIFF:	arg->i = va_arg(*ap, ptrdiff_t); | ||
| 130 | 	break; case UIPTR:	arg->i = (uintptr_t)va_arg(*ap, void *); | ||
| 131 | #if defined(__wasilibc_printscan_no_floating_point) | ||
| 132 | 	break; case DBL: | ||
| 133 | 	break; case LDBL:	floating_point_not_supported(); | ||
| 134 | #else | ||
| 135 | 	break; case DBL:	arg->f = va_arg(*ap, double); | ||
| 136 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 137 | 	break; case LDBL:	long_double_not_supported(); | ||
| 138 | #else | ||
| 139 | 	break; case LDBL:	arg->f = va_arg(*ap, long double); | ||
| 140 | #endif | ||
| 141 | #endif | ||
| 142 | 	} | ||
| 143 | } | ||
| 144 | |||
| 145 | static void out(FILE *f, const wchar_t *s, size_t l) | ||
| 146 | { | ||
| 147 | 	while (l-- && !ferror(f)) fputwc(*s++, f); | ||
| 148 | } | ||
| 149 | |||
| 150 | static void pad(FILE *f, int n, int fl) | ||
| 151 | { | ||
| 152 | 	if ((fl & LEFT_ADJ) || !n || ferror(f)) return; | ||
| 153 | 	fprintf(f, "%*s", n, ""); | ||
| 154 | } | ||
| 155 | |||
| 156 | static int getint(wchar_t **s) { | ||
| 157 | 	int i; | ||
| 158 | 	for (i=0; iswdigit(**s); (*s)++) { | ||
| 159 | 		if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; | ||
| 160 | 		else i = 10*i + (**s-'0'); | ||
| 161 | 	} | ||
| 162 | 	return i; | ||
| 163 | } | ||
| 164 | |||
| 165 | static const char sizeprefix['y'-'a'] = { | ||
| 166 | ['a'-'a']='L', ['e'-'a']='L', ['f'-'a']='L', ['g'-'a']='L', | ||
| 167 | ['d'-'a']='j', ['i'-'a']='j', ['o'-'a']='j', ['u'-'a']='j', ['x'-'a']='j', | ||
| 168 | ['p'-'a']='j' | ||
| 169 | }; | ||
| 170 | |||
| 171 | static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_arg, int *nl_type) | ||
| 172 | { | ||
| 173 | 	wchar_t *a, *z, *s=(wchar_t *)fmt; | ||
| 174 | 	unsigned l10n=0, fl; | ||
| 175 | 	int w, p, xp; | ||
| 176 | 	union arg arg; | ||
| 177 | 	int argpos; | ||
| 178 | 	unsigned st, ps; | ||
| 179 | 	int cnt=0, l=0; | ||
| 180 | 	int i; | ||
| 181 | 	int t; | ||
| 182 | 	char *bs; | ||
| 183 | 	char charfmt[16]; | ||
| 184 | 	wchar_t wc; | ||
| 185 | |||
| 186 | 	for (;;) { | ||
| 187 | 		/* This error is only specified for snprintf, but since it's | ||
| 188 | 		 * unspecified for other forms, do the same. Stop immediately | ||
| 189 | 		 * on overflow; otherwise %n could produce wrong results. */ | ||
| 190 | 		if (l > INT_MAX - cnt) goto overflow; | ||
| 191 | |||
| 192 | 		/* Update output count, end loop when fmt is exhausted */ | ||
| 193 | 		cnt += l; | ||
| 194 | 		if (!*s) break; | ||
| 195 | |||
| 196 | 		/* Handle literal text and %% format specifiers */ | ||
| 197 | 		for (a=s; *s && *s!='%'; s++); | ||
| 198 | 		for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); | ||
| 199 | 		if (z-a > INT_MAX-cnt) goto overflow; | ||
| 200 | 		l = z-a; | ||
| 201 | 		if (f) out(f, a, l); | ||
| 202 | 		if (l) continue; | ||
| 203 | |||
| 204 | 		if (iswdigit(s[1]) && s[2]=='$') { | ||
| 205 | 			l10n=1; | ||
| 206 | 			argpos = s[1]-'0'; | ||
| 207 | 			s+=3; | ||
| 208 | 		} else { | ||
| 209 | 			argpos = -1; | ||
| 210 | 			s++; | ||
| 211 | 		} | ||
| 212 | |||
| 213 | 		/* Read modifier flags */ | ||
| 214 | 		for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) | ||
| 215 | 			fl |= 1U<<*s-' '; | ||
| 216 | |||
| 217 | 		/* Read field width */ | ||
| 218 | 		if (*s=='*') { | ||
| 219 | 			if (iswdigit(s[1]) && s[2]=='$') { | ||
| 220 | 				l10n=1; | ||
| 221 | 				nl_type[s[1]-'0'] = INT; | ||
| 222 | 				w = nl_arg[s[1]-'0'].i; | ||
| 223 | 				s+=3; | ||
| 224 | 			} else if (!l10n) { | ||
| 225 | 				w = f ? va_arg(*ap, int) : 0; | ||
| 226 | 				s++; | ||
| 227 | 			} else goto inval; | ||
| 228 | 			if (w<0) fl|=LEFT_ADJ, w=-w; | ||
| 229 | 		} else if ((w=getint(&s))<0) goto overflow; | ||
| 230 | |||
| 231 | 		/* Read precision */ | ||
| 232 | 		if (*s=='.' && s[1]=='*') { | ||
| 233 | 			if (isdigit(s[2]) && s[3]=='$') { | ||
| 234 | 				nl_type[s[2]-'0'] = INT; | ||
| 235 | 				p = nl_arg[s[2]-'0'].i; | ||
| 236 | 				s+=4; | ||
| 237 | 			} else if (!l10n) { | ||
| 238 | 				p = f ? va_arg(*ap, int) : 0; | ||
| 239 | 				s+=2; | ||
| 240 | 			} else goto inval; | ||
| 241 | 			xp = (p>=0); | ||
| 242 | 		} else if (*s=='.') { | ||
| 243 | 			s++; | ||
| 244 | 			p = getint(&s); | ||
| 245 | 			xp = 1; | ||
| 246 | 		} else { | ||
| 247 | 			p = -1; | ||
| 248 | 			xp = 0; | ||
| 249 | 		} | ||
| 250 | |||
| 251 | 		/* Format specifier state machine */ | ||
| 252 | 		st=0; | ||
| 253 | 		do { | ||
| 254 | 			if (OOB(*s)) goto inval; | ||
| 255 | 			ps=st; | ||
| 256 | 			st=states[st]S(*s++); | ||
| 257 | 		} while (st-1<STOP); | ||
| 258 | 		if (!st) goto inval; | ||
| 259 | |||
| 260 | 		/* Check validity of argument type (nl/normal) */ | ||
| 261 | 		if (st==NOARG) { | ||
| 262 | 			if (argpos>=0) goto inval; | ||
| 263 | 		} else { | ||
| 264 | 			if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos]; | ||
| 265 | 			else if (f) pop_arg(&arg, st, ap); | ||
| 266 | 			else return 0; | ||
| 267 | 		} | ||
| 268 | |||
| 269 | 		if (!f) continue; | ||
| 270 | |||
| 271 | 		/* Do not process any new directives once in error state. */ | ||
| 272 | 		if (ferror(f)) return -1; | ||
| 273 | |||
| 274 | 		t = s[-1]; | ||
| 275 | 		if (ps && (t&15)==3) t&=~32; | ||
| 276 | |||
| 277 | 		switch (t) { | ||
| 278 | 		case 'n': | ||
| 279 | 			switch(ps) { | ||
| 280 | 			case BARE: *(int *)arg.p = cnt; break; | ||
| 281 | 			case LPRE: *(long *)arg.p = cnt; break; | ||
| 282 | 			case LLPRE: *(long long *)arg.p = cnt; break; | ||
| 283 | 			case HPRE: *(unsigned short *)arg.p = cnt; break; | ||
| 284 | 			case HHPRE: *(unsigned char *)arg.p = cnt; break; | ||
| 285 | 			case ZTPRE: *(size_t *)arg.p = cnt; break; | ||
| 286 | 			case JPRE: *(uintmax_t *)arg.p = cnt; break; | ||
| 287 | 			} | ||
| 288 | 			continue; | ||
| 289 | 		case 'c': | ||
| 290 | 		case 'C': | ||
| 291 | 			if (w<1) w=1; | ||
| 292 | 			pad(f, w-1, fl); | ||
| 293 | 			out(f, &(wchar_t){t=='C' ? arg.i : btowc(arg.i)}, 1); | ||
| 294 | 			pad(f, w-1, fl^LEFT_ADJ); | ||
| 295 | 			l = w; | ||
| 296 | 			continue; | ||
| 297 | 		case 'S': | ||
| 298 | 			a = arg.p; | ||
| 299 | 			z = a + wcsnlen(a, p<0 ? INT_MAX : p); | ||
| 300 | 			if (p<0 && *z) goto overflow; | ||
| 301 | 			p = z-a; | ||
| 302 | 			if (w<p) w=p; | ||
| 303 | 			pad(f, w-p, fl); | ||
| 304 | 			out(f, a, p); | ||
| 305 | 			pad(f, w-p, fl^LEFT_ADJ); | ||
| 306 | 			l=w; | ||
| 307 | 			continue; | ||
| 308 | 		case 'm': | ||
| 309 | 			arg.p = strerror(errno); | ||
| 310 | 		case 's': | ||
| 311 | 			if (!arg.p) arg.p = "(null)"; | ||
| 312 | 			bs = arg.p; | ||
| 313 | 			for (i=l=0; l<(p<0?INT_MAX:p) && (i=mbtowc(&wc, bs, MB_LEN_MAX))>0; bs+=i, l++); | ||
| 314 | 			if (i<0) return -1; | ||
| 315 | 			if (p<0 && *bs) goto overflow; | ||
| 316 | 			p=l; | ||
| 317 | 			if (w<p) w=p; | ||
| 318 | 			pad(f, w-p, fl); | ||
| 319 | 			bs = arg.p; | ||
| 320 | 			while (l--) { | ||
| 321 | 				i=mbtowc(&wc, bs, MB_LEN_MAX); | ||
| 322 | 				bs+=i; | ||
| 323 | 				out(f, &wc, 1); | ||
| 324 | 			} | ||
| 325 | 			pad(f, w-p, fl^LEFT_ADJ); | ||
| 326 | 			l=w; | ||
| 327 | 			continue; | ||
| 328 | 		} | ||
| 329 | |||
| 330 | 		if (xp && p<0) goto overflow; | ||
| 331 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 332 | 		// Omit the 'L' modifier for floating-point cases. | ||
| 333 | 		switch (t|32) { | ||
| 334 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 335 | 			snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c", | ||
| 336 | 				"#"+!(fl & ALT_FORM), | ||
| 337 | 				"+"+!(fl & MARK_POS), | ||
| 338 | 				"-"+!(fl & LEFT_ADJ), | ||
| 339 | 				" "+!(fl & PAD_POS), | ||
| 340 | 				"0"+!(fl & ZERO_PAD), | ||
| 341 | 				t); | ||
| 342 | |||
| 343 | 			l = fprintf(f, charfmt, w, p, arg.f); | ||
| 344 | 			break; | ||
| 345 | 		case 'd': case 'i': case 'o': case 'u': case 'x': case 'p': | ||
| 346 | 			snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c%c", | ||
| 347 | 				"#"+!(fl & ALT_FORM), | ||
| 348 | 				"+"+!(fl & MARK_POS), | ||
| 349 | 				"-"+!(fl & LEFT_ADJ), | ||
| 350 | 				" "+!(fl & PAD_POS), | ||
| 351 | 				"0"+!(fl & ZERO_PAD), | ||
| 352 | 				sizeprefix[(t|32)-'a'], t); | ||
| 353 | |||
| 354 | 			l = fprintf(f, charfmt, w, p, arg.i); | ||
| 355 | 			break; | ||
| 356 | 		} | ||
| 357 | #else | ||
| 358 | 		snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c%c", | ||
| 359 | 			"#"+!(fl & ALT_FORM), | ||
| 360 | 			"+"+!(fl & MARK_POS), | ||
| 361 | 			"-"+!(fl & LEFT_ADJ), | ||
| 362 | 			" "+!(fl & PAD_POS), | ||
| 363 | 			"0"+!(fl & ZERO_PAD), | ||
| 364 | 			sizeprefix[(t|32)-'a'], t); | ||
| 365 | |||
| 366 | 		switch (t|32) { | ||
| 367 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 368 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 369 | 			l = fprintf(f, charfmt, w, p, arg.f); | ||
| 370 | 			break; | ||
| 371 | #endif | ||
| 372 | 		case 'd': case 'i': case 'o': case 'u': case 'x': case 'p': | ||
| 373 | 			l = fprintf(f, charfmt, w, p, arg.i); | ||
| 374 | 			break; | ||
| 375 | 		} | ||
| 376 | #endif | ||
| 377 | 	} | ||
| 378 | |||
| 379 | 	if (f) return cnt; | ||
| 380 | 	if (!l10n) return 0; | ||
| 381 | |||
| 382 | 	for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) | ||
| 383 | 		pop_arg(nl_arg+i, nl_type[i], ap); | ||
| 384 | 	for (; i<=NL_ARGMAX && !nl_type[i]; i++); | ||
| 385 | 	if (i<=NL_ARGMAX) return -1; | ||
| 386 | 	return 1; | ||
| 387 | |||
| 388 | inval: | ||
| 389 | 	errno = EINVAL; | ||
| 390 | 	return -1; | ||
| 391 | overflow: | ||
| 392 | 	errno = EOVERFLOW; | ||
| 393 | 	return -1; | ||
| 394 | } | ||
| 395 | |||
| 396 | int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) | ||
| 397 | { | ||
| 398 | 	va_list ap2; | ||
| 399 | 	int nl_type[NL_ARGMAX+1] = {0}; | ||
| 400 | 	union arg nl_arg[NL_ARGMAX+1]; | ||
| 401 | 	int olderr; | ||
| 402 | 	int ret; | ||
| 403 | |||
| 404 | 	/* the copy allows passing va_list* even if va_list is an array */ | ||
| 405 | 	va_copy(ap2, ap); | ||
| 406 | 	if (wprintf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { | ||
| 407 | 		va_end(ap2); | ||
| 408 | 		return -1; | ||
| 409 | 	} | ||
| 410 | |||
| 411 | 	FLOCK(f); | ||
| 412 | 	fwide(f, 1); | ||
| 413 | 	olderr = f->flags & F_ERR; | ||
| 414 | 	f->flags &= ~F_ERR; | ||
| 415 | 	ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type); | ||
| 416 | 	if (ferror(f)) ret = -1; | ||
| 417 | 	f->flags |= olderr; | ||
| 418 | 	FUNLOCK(f); | ||
| 419 | 	va_end(ap2); | ||
| 420 | 	return ret; | ||
| 421 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vsnprintf.c deleted-52| ... | @@ -1,52 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <limits.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | |||
| 7 | struct cookie { | ||
| 8 | 	char *s; | ||
| 9 | 	size_t n; | ||
| 10 | }; | ||
| 11 | |||
| 12 | #define MIN(a, b) ((a) < (b) ? (a) : (b)) | ||
| 13 | |||
| 14 | static size_t sn_write(FILE *f, const unsigned char *s, size_t l) | ||
| 15 | { | ||
| 16 | 	struct cookie *c = f->cookie; | ||
| 17 | 	size_t k = MIN(c->n, f->wpos - f->wbase); | ||
| 18 | 	if (k) { | ||
| 19 | 		memcpy(c->s, f->wbase, k); | ||
| 20 | 		c->s += k; | ||
| 21 | 		c->n -= k; | ||
| 22 | 	} | ||
| 23 | 	k = MIN(c->n, l); | ||
| 24 | 	if (k) { | ||
| 25 | 		memcpy(c->s, s, k); | ||
| 26 | 		c->s += k; | ||
| 27 | 		c->n -= k; | ||
| 28 | 	} | ||
| 29 | 	*c->s = 0; | ||
| 30 | 	f->wpos = f->wbase = f->buf; | ||
| 31 | 	/* pretend to succeed, even if we discarded extra data */ | ||
| 32 | 	return l; | ||
| 33 | } | ||
| 34 | |||
| 35 | int vsnprintf(char *restrict s, size_t n, const char *restrict fmt, va_list ap) | ||
| 36 | { | ||
| 37 | 	unsigned char buf[1]; | ||
| 38 | 	char dummy[1]; | ||
| 39 | 	struct cookie c = { .s = n ? s : dummy, .n = n ? n-1 : 0 }; | ||
| 40 | 	FILE f = { | ||
| 41 | 		.lbf = EOF, | ||
| 42 | 		.write = sn_write, | ||
| 43 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 44 | 		.lock = -1, | ||
| 45 | #endif | ||
| 46 | 		.buf = buf, | ||
| 47 | 		.cookie = &c, | ||
| 48 | 	}; | ||
| 49 | |||
| 50 | 	*c.s = 0; | ||
| 51 | 	return vfprintf(&f, fmt, ap); | ||
| 52 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vsscanf.c deleted-31| ... | @@ -1,31 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | static size_t string_read(FILE *f, unsigned char *buf, size_t len) | ||
| 5 | { | ||
| 6 | 	char *src = f->cookie; | ||
| 7 | 	size_t k = len+256; | ||
| 8 | 	char *end = memchr(src, 0, k); | ||
| 9 | 	if (end) k = end-src; | ||
| 10 | 	if (k < len) len = k; | ||
| 11 | 	memcpy(buf, src, len); | ||
| 12 | 	f->rpos = (void *)(src+len); | ||
| 13 | 	f->rend = (void *)(src+k); | ||
| 14 | 	f->cookie = src+k; | ||
| 15 | 	return len; | ||
| 16 | } | ||
| 17 | |||
| 18 | int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap) | ||
| 19 | { | ||
| 20 | 	FILE f = { | ||
| 21 | 		.buf = (void *)s, .cookie = (void *)s, | ||
| 22 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 23 | 		.read = string_read, .lock = -1 | ||
| 24 | #else | ||
| 25 | 		.read = string_read | ||
| 26 | #endif | ||
| 27 | 	}; | ||
| 28 | 	return vfscanf(&f, fmt, ap); | ||
| 29 | } | ||
| 30 | |||
| 31 | weak_alias(vsscanf,__isoc99_vsscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vswprintf.c deleted-60| ... | @@ -1,60 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <wchar.h> | ||
| 7 | |||
| 8 | struct cookie { | ||
| 9 | 	wchar_t *ws; | ||
| 10 | 	size_t l; | ||
| 11 | }; | ||
| 12 | |||
| 13 | static size_t sw_write(FILE *f, const unsigned char *s, size_t l) | ||
| 14 | { | ||
| 15 | 	size_t l0 = l; | ||
| 16 | 	int i = 0; | ||
| 17 | 	struct cookie *c = f->cookie; | ||
| 18 | 	if (s!=f->wbase && sw_write(f, f->wbase, f->wpos-f->wbase)==-1) | ||
| 19 | 		return -1; | ||
| 20 | 	while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) { | ||
| 21 | 		if (!i) i=1; | ||
| 22 | 		s+=i; | ||
| 23 | 		l-=i; | ||
| 24 | 		c->l--; | ||
| 25 | 		c->ws++; | ||
| 26 | 	} | ||
| 27 | 	*c->ws = 0; | ||
| 28 | 	if (i < 0) { | ||
| 29 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 30 | 		f->flags |= F_ERR; | ||
| 31 | 		return i; | ||
| 32 | 	} | ||
| 33 | 	f->wend = f->buf + f->buf_size; | ||
| 34 | 	f->wpos = f->wbase = f->buf; | ||
| 35 | 	return l0; | ||
| 36 | } | ||
| 37 | |||
| 38 | int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) | ||
| 39 | { | ||
| 40 | 	int r; | ||
| 41 | 	unsigned char buf[256]; | ||
| 42 | 	struct cookie c = { s, n-1 }; | ||
| 43 | 	FILE f = { | ||
| 44 | 		.lbf = EOF, | ||
| 45 | 		.write = sw_write, | ||
| 46 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 47 | 		.lock = -1, | ||
| 48 | #endif | ||
| 49 | 		.buf = buf, | ||
| 50 | 		.buf_size = sizeof buf, | ||
| 51 | 		.cookie = &c, | ||
| 52 | 	}; | ||
| 53 | |||
| 54 | 	if (!n) { | ||
| 55 | 		return -1; | ||
| 56 | 	} | ||
| 57 | 	r = vfwprintf(&f, fmt, ap); | ||
| 58 | 	sw_write(&f, 0, 0); | ||
| 59 | 	return r>=n ? -1 : r; | ||
| 60 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vswscanf.c deleted-42| ... | @@ -1,42 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | static size_t wstring_read(FILE *f, unsigned char *buf, size_t len) | ||
| 5 | { | ||
| 6 | 	const wchar_t *src = f->cookie; | ||
| 7 | 	size_t k; | ||
| 8 | |||
| 9 | 	if (!src) return 0; | ||
| 10 | |||
| 11 | 	k = wcsrtombs((void *)f->buf, &src, f->buf_size, 0); | ||
| 12 | 	if (k==(size_t)-1) { | ||
| 13 | 		f->rpos = f->rend = 0; | ||
| 14 | 		return 0; | ||
| 15 | 	} | ||
| 16 | |||
| 17 | 	f->rpos = f->buf; | ||
| 18 | 	f->rend = f->buf + k; | ||
| 19 | 	f->cookie = (void *)src; | ||
| 20 | |||
| 21 | 	if (!len || !k) return 0; | ||
| 22 | |||
| 23 | 	*buf = *f->rpos++; | ||
| 24 | 	return 1; | ||
| 25 | } | ||
| 26 | |||
| 27 | int vswscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, va_list ap) | ||
| 28 | { | ||
| 29 | 	unsigned char buf[256]; | ||
| 30 | 	FILE f = { | ||
| 31 | 		.buf = buf, .buf_size = sizeof buf, | ||
| 32 | 		.cookie = (void *)s, | ||
| 33 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 34 | 		.read = wstring_read, .lock = -1 | ||
| 35 | #else | ||
| 36 | 		.read = wstring_read | ||
| 37 | #endif | ||
| 38 | 	}; | ||
| 39 | 	return vfwscanf(&f, fmt, ap); | ||
| 40 | } | ||
| 41 | |||
| 42 | weak_alias(vswscanf,__isoc99_vswscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/strtod.c deleted-48| ... | @@ -1,48 +0,0 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 3 | #else | ||
| 4 | #include "printscan.h" | ||
| 5 | #define __NEED_locale_t | ||
| 6 | #include <bits/alltypes.h> | ||
| 7 | #endif | ||
| 8 | #include "shgetc.h" | ||
| 9 | #include "floatscan.h" | ||
| 10 | #include "stdio_impl.h" | ||
| 11 | |||
| 12 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 13 | static long_double strtox(const char *s, char **p, int prec) | ||
| 14 | #else | ||
| 15 | static long double strtox(const char *s, char **p, int prec) | ||
| 16 | #endif | ||
| 17 | { | ||
| 18 | 	FILE f; | ||
| 19 | 	sh_fromstring(&f, s); | ||
| 20 | 	shlim(&f, 0); | ||
| 21 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 22 | 	long_double y = __floatscan(&f, prec, 1); | ||
| 23 | #else | ||
| 24 | 	long double y = __floatscan(&f, prec, 1); | ||
| 25 | #endif | ||
| 26 | 	off_t cnt = shcnt(&f); | ||
| 27 | 	if (p) *p = cnt ? (char *)s + cnt : (char *)s; | ||
| 28 | 	return y; | ||
| 29 | } | ||
| 30 | |||
| 31 | float strtof(const char *restrict s, char **restrict p) | ||
| 32 | { | ||
| 33 | 	return strtox(s, p, 0); | ||
| 34 | } | ||
| 35 | |||
| 36 | double strtod(const char *restrict s, char **restrict p) | ||
| 37 | { | ||
| 38 | 	return strtox(s, p, 1); | ||
| 39 | } | ||
| 40 | |||
| 41 | long double strtold(const char *restrict s, char **restrict p) | ||
| 42 | { | ||
| 43 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 44 | 	long_double_not_supported(); | ||
| 45 | #else | ||
| 46 | 	return strtox(s, p, 2); | ||
| 47 | #endif | ||
| 48 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstod.c deleted-82| ... | @@ -1,82 +0,0 @@ | ||
| 1 | #ifdef __wasilibc_unmodified_upstream // Changes to optimize printf/scanf when long double isn't needed | ||
| 2 | #else | ||
| 3 | #include "printscan.h" | ||
| 4 | #endif | ||
| 5 | #include "shgetc.h" | ||
| 6 | #include "floatscan.h" | ||
| 7 | #include "stdio_impl.h" | ||
| 8 | #include <wchar.h> | ||
| 9 | #include <wctype.h> | ||
| 10 | |||
| 11 | /* This read function heavily cheats. It knows: | ||
| 12 | * (1) len will always be 1 | ||
| 13 | * (2) non-ascii characters don't matter */ | ||
| 14 | |||
| 15 | static size_t do_read(FILE *f, unsigned char *buf, size_t len) | ||
| 16 | { | ||
| 17 | 	size_t i; | ||
| 18 | 	const wchar_t *wcs = f->cookie; | ||
| 19 | |||
| 20 | 	if (!wcs[0]) wcs=L"@"; | ||
| 21 | 	for (i=0; i<f->buf_size && wcs[i]; i++) | ||
| 22 | 		f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; | ||
| 23 | 	f->rpos = f->buf; | ||
| 24 | 	f->rend = f->buf + i; | ||
| 25 | 	f->cookie = (void *)(wcs+i); | ||
| 26 | |||
| 27 | 	if (i && len) { | ||
| 28 | 		*buf = *f->rpos++; | ||
| 29 | 		return 1; | ||
| 30 | 	} | ||
| 31 | 	return 0; | ||
| 32 | } | ||
| 33 | |||
| 34 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 35 | static long_double wcstox(const wchar_t *s, wchar_t **p, int prec) | ||
| 36 | #else | ||
| 37 | static long double wcstox(const wchar_t *s, wchar_t **p, int prec) | ||
| 38 | #endif | ||
| 39 | { | ||
| 40 | 	wchar_t *t = (wchar_t *)s; | ||
| 41 | 	unsigned char buf[64]; | ||
| 42 | 	FILE f = {0}; | ||
| 43 | 	f.flags = 0; | ||
| 44 | 	f.rpos = f.rend = f.buf = buf + 4; | ||
| 45 | 	f.buf_size = sizeof buf - 4; | ||
| 46 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 47 | 	f.lock = -1; | ||
| 48 | #endif | ||
| 49 | 	f.read = do_read; | ||
| 50 | 	while (iswspace(*t)) t++; | ||
| 51 | 	f.cookie = (void *)t; | ||
| 52 | 	shlim(&f, 0); | ||
| 53 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 54 | 	long_double y = __floatscan(&f, prec, 1); | ||
| 55 | #else | ||
| 56 | 	long double y = __floatscan(&f, prec, 1); | ||
| 57 | #endif | ||
| 58 | 	if (p) { | ||
| 59 | 		size_t cnt = shcnt(&f); | ||
| 60 | 		*p = cnt ? t + cnt : (wchar_t *)s; | ||
| 61 | 	} | ||
| 62 | 	return y; | ||
| 63 | } | ||
| 64 | |||
| 65 | float wcstof(const wchar_t *restrict s, wchar_t **restrict p) | ||
| 66 | { | ||
| 67 | 	return wcstox(s, p, 0); | ||
| 68 | } | ||
| 69 | |||
| 70 | double wcstod(const wchar_t *restrict s, wchar_t **restrict p) | ||
| 71 | { | ||
| 72 | 	return wcstox(s, p, 1); | ||
| 73 | } | ||
| 74 | |||
| 75 | long double wcstold(const wchar_t *restrict s, wchar_t **restrict p) | ||
| 76 | { | ||
| 77 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 78 | 	long_double_not_supported(); | ||
| 79 | #else | ||
| 80 | 	return wcstox(s, p, 2); | ||
| 81 | #endif | ||
| 82 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstol.c deleted-83| ... | @@ -1,83 +0,0 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "intscan.h" | ||
| 3 | #include "shgetc.h" | ||
| 4 | #include <inttypes.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <wctype.h> | ||
| 7 | #include <wchar.h> | ||
| 8 | |||
| 9 | /* This read function heavily cheats. It knows: | ||
| 10 | * (1) len will always be 1 | ||
| 11 | * (2) non-ascii characters don't matter */ | ||
| 12 | |||
| 13 | static size_t do_read(FILE *f, unsigned char *buf, size_t len) | ||
| 14 | { | ||
| 15 | 	size_t i; | ||
| 16 | 	const wchar_t *wcs = f->cookie; | ||
| 17 | |||
| 18 | 	if (!wcs[0]) wcs=L"@"; | ||
| 19 | 	for (i=0; i<f->buf_size && wcs[i]; i++) | ||
| 20 | 		f->buf[i] = wcs[i] < 128 ? wcs[i] : '@'; | ||
| 21 | 	f->rpos = f->buf; | ||
| 22 | 	f->rend = f->buf + i; | ||
| 23 | 	f->cookie = (void *)(wcs+i); | ||
| 24 | |||
| 25 | 	if (i && len) { | ||
| 26 | 		*buf = *f->rpos++; | ||
| 27 | 		return 1; | ||
| 28 | 	} | ||
| 29 | 	return 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | static unsigned long long wcstox(const wchar_t *s, wchar_t **p, int base, unsigned long long lim) | ||
| 33 | { | ||
| 34 | 	wchar_t *t = (wchar_t *)s; | ||
| 35 | 	unsigned char buf[64]; | ||
| 36 | 	FILE f = {0}; | ||
| 37 | 	f.flags = 0; | ||
| 38 | 	f.rpos = f.rend = f.buf = buf + 4; | ||
| 39 | 	f.buf_size = sizeof buf - 4; | ||
| 40 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 41 | 	f.lock = -1; | ||
| 42 | #endif | ||
| 43 | 	f.read = do_read; | ||
| 44 | 	while (iswspace(*t)) t++; | ||
| 45 | 	f.cookie = (void *)t; | ||
| 46 | 	shlim(&f, 0); | ||
| 47 | 	unsigned long long y = __intscan(&f, base, 1, lim); | ||
| 48 | 	if (p) { | ||
| 49 | 		size_t cnt = shcnt(&f); | ||
| 50 | 		*p = cnt ? t + cnt : (wchar_t *)s; | ||
| 51 | 	} | ||
| 52 | 	return y; | ||
| 53 | } | ||
| 54 | |||
| 55 | unsigned long long wcstoull(const wchar_t *restrict s, wchar_t **restrict p, int base) | ||
| 56 | { | ||
| 57 | 	return wcstox(s, p, base, ULLONG_MAX); | ||
| 58 | } | ||
| 59 | |||
| 60 | long long wcstoll(const wchar_t *restrict s, wchar_t **restrict p, int base) | ||
| 61 | { | ||
| 62 | 	return wcstox(s, p, base, LLONG_MIN); | ||
| 63 | } | ||
| 64 | |||
| 65 | unsigned long wcstoul(const wchar_t *restrict s, wchar_t **restrict p, int base) | ||
| 66 | { | ||
| 67 | 	return wcstox(s, p, base, ULONG_MAX); | ||
| 68 | } | ||
| 69 | |||
| 70 | long wcstol(const wchar_t *restrict s, wchar_t **restrict p, int base) | ||
| 71 | { | ||
| 72 | 	return wcstox(s, p, base, 0UL+LONG_MIN); | ||
| 73 | } | ||
| 74 | |||
| 75 | intmax_t wcstoimax(const wchar_t *restrict s, wchar_t **restrict p, int base) | ||
| 76 | { | ||
| 77 | 	return wcstoll(s, p, base); | ||
| 78 | } | ||
| 79 | |||
| 80 | uintmax_t wcstoumax(const wchar_t *restrict s, wchar_t **restrict p, int base) | ||
| 81 | { | ||
| 82 | 	return wcstoull(s, p, base); | ||
| 83 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c deleted-121| ... | @@ -1,121 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | #ifndef __wasilibc_unmodified_upstream | ||
| 4 | #include <common/clock.h> | ||
| 5 | #endif | ||
| 6 | |||
| 7 | int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state) | ||
| 8 | { | ||
| 9 | 	*state = a->_a_detach; | ||
| 10 | 	return 0; | ||
| 11 | } | ||
| 12 | int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) | ||
| 13 | { | ||
| 14 | 	*size = a->_a_guardsize; | ||
| 15 | 	return 0; | ||
| 16 | } | ||
| 17 | |||
| 18 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 19 | int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit) | ||
| 20 | { | ||
| 21 | 	*inherit = a->_a_sched; | ||
| 22 | 	return 0; | ||
| 23 | } | ||
| 24 | |||
| 25 | int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) | ||
| 26 | { | ||
| 27 | 	param->sched_priority = a->_a_prio; | ||
| 28 | 	return 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy) | ||
| 32 | { | ||
| 33 | 	*policy = a->_a_policy; | ||
| 34 | 	return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope) | ||
| 38 | { | ||
| 39 | 	*scope = PTHREAD_SCOPE_SYSTEM; | ||
| 40 | 	return 0; | ||
| 41 | } | ||
| 42 | #else | ||
| 43 | int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) | ||
| 44 | { | ||
| 45 | 	param->sched_priority = 0; | ||
| 46 | 	return 0; | ||
| 47 | } | ||
| 48 | #endif | ||
| 49 | |||
| 50 | int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size) | ||
| 51 | { | ||
| 52 | 	if (!a->_a_stackaddr) | ||
| 53 | 		return EINVAL; | ||
| 54 | 	*size = a->_a_stacksize; | ||
| 55 | 	*addr = (void *)(a->_a_stackaddr - *size); | ||
| 56 | 	return 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) | ||
| 60 | { | ||
| 61 | 	*size = a->_a_stacksize; | ||
| 62 | 	return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared) | ||
| 66 | { | ||
| 67 | 	*pshared = !!a->__attr; | ||
| 68 | 	return 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | #ifdef __wasilibc_unmodified_upstream /* Forward declaration of WASI's `__clockid` type. */ | ||
| 72 | int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) | ||
| 73 | { | ||
| 74 | 	*clk = a->__attr & 0x7fffffff; | ||
| 75 | 	return 0; | ||
| 76 | } | ||
| 77 | #else | ||
| 78 | int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) | ||
| 79 | { | ||
| 80 | 	if (a->__attr & 0x7fffffff == __WASI_CLOCKID_REALTIME) | ||
| 81 | 		*clk = CLOCK_REALTIME; | ||
| 82 | 	if (a->__attr & 0x7fffffff == __WASI_CLOCKID_MONOTONIC) | ||
| 83 | 		*clk = CLOCK_MONOTONIC; | ||
| 84 | 	return 0; | ||
| 85 | } | ||
| 86 | #endif | ||
| 87 | |||
| 88 | int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared) | ||
| 89 | { | ||
| 90 | 	*pshared = a->__attr>>31; | ||
| 91 | 	return 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol) | ||
| 95 | { | ||
| 96 | 	*protocol = a->__attr / 8U % 2; | ||
| 97 | 	return 0; | ||
| 98 | } | ||
| 99 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared) | ||
| 100 | { | ||
| 101 | 	*pshared = a->__attr / 128U % 2; | ||
| 102 | 	return 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) | ||
| 106 | { | ||
| 107 | 	*robust = a->__attr / 4U % 2; | ||
| 108 | 	return 0; | ||
| 109 | } | ||
| 110 | |||
| 111 | int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type) | ||
| 112 | { | ||
| 113 | 	*type = a->__attr & 3; | ||
| 114 | 	return 0; | ||
| 115 | } | ||
| 116 | |||
| 117 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared) | ||
| 118 | { | ||
| 119 | 	*pshared = a->__attr[0]; | ||
| 120 | 	return 0; | ||
| 121 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) | ||
| 4 | { | ||
| 5 | #ifdef __wasilibc_unmodified_upstream | ||
| 6 | 	if (size > SIZE_MAX/8) return EINVAL; | ||
| 7 | #else | ||
| 8 | 	/* WASI doesn't have memory protection required for stack guards. */ | ||
| 9 | 	if (size > 0) return EINVAL; | ||
| 10 | #endif | ||
| 11 | 	a->_a_guardsize = size; | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param) | ||
| 4 | { | ||
| 5 | #ifdef __wasilibc_unmodified_upstream | ||
| 6 | 	a->_a_prio = param->sched_priority; | ||
| 7 | #else | ||
| 8 | 	if (param->sched_priority != 0) return ENOTSUP; | ||
| 9 | #endif | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c deleted-113| ... | @@ -1,113 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | #ifdef __wasilibc_unmodified_upstream | ||
| 7 | hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c(); | ||
| 8 | |||
| 9 | long __cancel() | ||
| 10 | { | ||
| 11 | 	pthread_t self = __pthread_self(); | ||
| 12 | 	if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync) | ||
| 13 | 		pthread_exit(PTHREAD_CANCELED); | ||
| 14 | 	self->canceldisable = PTHREAD_CANCEL_DISABLE; | ||
| 15 | 	return -ECANCELED; | ||
| 16 | } | ||
| 17 | |||
| 18 | long __syscall_cp_asm(volatile void *, syscall_arg_t, | ||
| 19 | syscall_arg_t, syscall_arg_t, syscall_arg_t, | ||
| 20 | syscall_arg_t, syscall_arg_t, syscall_arg_t); | ||
| 21 | |||
| 22 | long __syscall_cp_c(syscall_arg_t nr, | ||
| 23 | syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, | ||
| 24 | syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) | ||
| 25 | { | ||
| 26 | 	pthread_t self; | ||
| 27 | 	long r; | ||
| 28 | 	int st; | ||
| 29 | |||
| 30 | 	if ((st=(self=__pthread_self())->canceldisable) | ||
| 31 | 	 && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close)) | ||
| 32 | 		return __syscall(nr, u, v, w, x, y, z); | ||
| 33 | |||
| 34 | 	r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z); | ||
| 35 | 	if (r==-EINTR && nr!=SYS_close && self->cancel && | ||
| 36 | 	 self->canceldisable != PTHREAD_CANCEL_DISABLE) | ||
| 37 | 		r = __cancel(); | ||
| 38 | 	return r; | ||
| 39 | } | ||
| 40 | |||
| 41 | static void _sigaddset(sigset_t *set, int sig) | ||
| 42 | { | ||
| 43 | 	unsigned s = sig-1; | ||
| 44 | 	set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); | ||
| 45 | } | ||
| 46 | |||
| 47 | extern hidden const char __cp_begin[1], __cp_end[1], __cp_cancel[1]; | ||
| 48 | |||
| 49 | static void cancel_handler(int sig, siginfo_t *si, void *ctx) | ||
| 50 | { | ||
| 51 | 	pthread_t self = __pthread_self(); | ||
| 52 | 	ucontext_t *uc = ctx; | ||
| 53 | 	uintptr_t pc = uc->uc_mcontext.MC_PC; | ||
| 54 | |||
| 55 | 	a_barrier(); | ||
| 56 | 	if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return; | ||
| 57 | |||
| 58 | 	_sigaddset(&uc->uc_sigmask, SIGCANCEL); | ||
| 59 | |||
| 60 | 	if (self->cancelasync) { | ||
| 61 | 		pthread_sigmask(SIG_SETMASK, &uc->uc_sigmask, 0); | ||
| 62 | 		__cancel(); | ||
| 63 | 	} | ||
| 64 | |||
| 65 | 	if (pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) { | ||
| 66 | 		uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel; | ||
| 67 | #ifdef CANCEL_GOT | ||
| 68 | 		uc->uc_mcontext.MC_GOT = CANCEL_GOT; | ||
| 69 | #endif | ||
| 70 | 		return; | ||
| 71 | 	} | ||
| 72 | |||
| 73 | 	__syscall(SYS_tkill, self->tid, SIGCANCEL); | ||
| 74 | } | ||
| 75 | |||
| 76 | void __testcancel() | ||
| 77 | { | ||
| 78 | 	pthread_t self = __pthread_self(); | ||
| 79 | 	if (self->cancel && !self->canceldisable) | ||
| 80 | 		__cancel(); | ||
| 81 | } | ||
| 82 | |||
| 83 | static void init_cancellation() | ||
| 84 | { | ||
| 85 | 	struct sigaction sa = { | ||
| 86 | 		.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK, | ||
| 87 | 		.sa_sigaction = cancel_handler | ||
| 88 | 	}; | ||
| 89 | 	memset(&sa.sa_mask, -1, _NSIG/8); | ||
| 90 | 	__libc_sigaction(SIGCANCEL, &sa, 0); | ||
| 91 | } | ||
| 92 | |||
| 93 | int pthread_cancel(pthread_t t) | ||
| 94 | { | ||
| 95 | 	static int init; | ||
| 96 | 	if (!init) { | ||
| 97 | 		init_cancellation(); | ||
| 98 | 		init = 1; | ||
| 99 | 	} | ||
| 100 | 	a_store(&t->cancel, 1); | ||
| 101 | 	if (t == pthread_self()) { | ||
| 102 | 		if (t->canceldisable == PTHREAD_CANCEL_ENABLE && t->cancelasync) | ||
| 103 | 			pthread_exit(PTHREAD_CANCELED); | ||
| 104 | 		return 0; | ||
| 105 | 	} | ||
| 106 | 	return pthread_kill(t, SIGCANCEL); | ||
| 107 | } | ||
| 108 | #else | ||
| 109 | int pthread_cancel(pthread_t t) | ||
| 110 | { | ||
| 111 | 	return ENOTSUP; | ||
| 112 | } | ||
| 113 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | #ifndef __wasilibc_unmodified_upstream | ||
| 4 | #include <common/clock.h> | ||
| 5 | #endif | ||
| 6 | |||
| 7 | int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk) | ||
| 8 | { | ||
| 9 | #ifdef __wasilibc_unmodified_upstream | ||
| 10 | 	if (clk < 0 || clk-2U < 2) return EINVAL; | ||
| 11 | #else | ||
| 12 | 	if (clk->id < 0 || clk->id-2U < 2) return EINVAL; | ||
| 13 | #endif | ||
| 14 | 	a->__attr &= 0x80000000; | ||
| 15 | #ifdef __wasilibc_unmodified_upstream | ||
| 16 | 	a->__attr |= clk; | ||
| 17 | #else | ||
| 18 | 	a->__attr |= clk->id; | ||
| 19 | #endif | ||
| 20 | 	return 0; | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c deleted-105| ... | @@ -1,105 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "fork_impl.h" | ||
| 3 | |||
| 4 | volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; | ||
| 5 | void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; | ||
| 6 | |||
| 7 | static void (*keys[PTHREAD_KEYS_MAX])(void *); | ||
| 8 | |||
| 9 | static pthread_rwlock_t key_lock = PTHREAD_RWLOCK_INITIALIZER; | ||
| 10 | |||
| 11 | static pthread_key_t next_key; | ||
| 12 | |||
| 13 | static void nodtor(void *dummy) | ||
| 14 | { | ||
| 15 | } | ||
| 16 | |||
| 17 | static void dummy_0(void) | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | weak_alias(dummy_0, __tl_lock); | ||
| 22 | weak_alias(dummy_0, __tl_unlock); | ||
| 23 | |||
| 24 | #ifdef __wasilibc_unmodified_upstream // WASI lacks fork | ||
| 25 | void __pthread_key_atfork(int who) | ||
| 26 | { | ||
| 27 | 	if (who<0) __pthread_rwlock_rdlock(&key_lock); | ||
| 28 | 	else if (!who) __pthread_rwlock_unlock(&key_lock); | ||
| 29 | 	else key_lock = (pthread_rwlock_t)PTHREAD_RWLOCK_INITIALIZER; | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) | ||
| 34 | { | ||
| 35 | 	pthread_t self = __pthread_self(); | ||
| 36 | |||
| 37 | 	/* This can only happen in the main thread before | ||
| 38 | 	 * pthread_create has been called. */ | ||
| 39 | 	if (!self->tsd) self->tsd = __pthread_tsd_main; | ||
| 40 | |||
| 41 | 	/* Purely a sentinel value since null means slot is free. */ | ||
| 42 | 	if (!dtor) dtor = nodtor; | ||
| 43 | |||
| 44 | 	__pthread_rwlock_wrlock(&key_lock); | ||
| 45 | 	pthread_key_t j = next_key; | ||
| 46 | 	do { | ||
| 47 | 		if (!keys[j]) { | ||
| 48 | 			keys[next_key = *k = j] = dtor; | ||
| 49 | 			__pthread_rwlock_unlock(&key_lock); | ||
| 50 | 			return 0; | ||
| 51 | 		} | ||
| 52 | 	} while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key); | ||
| 53 | |||
| 54 | 	__pthread_rwlock_unlock(&key_lock); | ||
| 55 | 	return EAGAIN; | ||
| 56 | } | ||
| 57 | |||
| 58 | int __pthread_key_delete(pthread_key_t k) | ||
| 59 | { | ||
| 60 | 	sigset_t set; | ||
| 61 | 	pthread_t self = __pthread_self(), td=self; | ||
| 62 | |||
| 63 | #ifdef __wasilibc_unmodified_upstream | ||
| 64 | 	__block_app_sigs(&set); | ||
| 65 | #endif | ||
| 66 | 	__pthread_rwlock_wrlock(&key_lock); | ||
| 67 | |||
| 68 | 	__tl_lock(); | ||
| 69 | 	do td->tsd[k] = 0; | ||
| 70 | 	while ((td=td->next)!=self); | ||
| 71 | 	__tl_unlock(); | ||
| 72 | |||
| 73 | 	keys[k] = 0; | ||
| 74 | |||
| 75 | 	__pthread_rwlock_unlock(&key_lock); | ||
| 76 | #ifdef __wasilibc_unmodified_upstream | ||
| 77 | 	__restore_sigs(&set); | ||
| 78 | #endif | ||
| 79 | |||
| 80 | 	return 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | void __pthread_tsd_run_dtors() | ||
| 84 | { | ||
| 85 | 	pthread_t self = __pthread_self(); | ||
| 86 | 	int i, j; | ||
| 87 | 	for (j=0; self->tsd_used && j<PTHREAD_DESTRUCTOR_ITERATIONS; j++) { | ||
| 88 | 		__pthread_rwlock_rdlock(&key_lock); | ||
| 89 | 		self->tsd_used = 0; | ||
| 90 | 		for (i=0; i<PTHREAD_KEYS_MAX; i++) { | ||
| 91 | 			void *val = self->tsd[i]; | ||
| 92 | 			void (*dtor)(void *) = keys[i]; | ||
| 93 | 			self->tsd[i] = 0; | ||
| 94 | 			if (val && dtor && dtor != nodtor) { | ||
| 95 | 				__pthread_rwlock_unlock(&key_lock); | ||
| 96 | 				dtor(val); | ||
| 97 | 				__pthread_rwlock_rdlock(&key_lock); | ||
| 98 | 			} | ||
| 99 | 		} | ||
| 100 | 		__pthread_rwlock_unlock(&key_lock); | ||
| 101 | 	} | ||
| 102 | } | ||
| 103 | |||
| 104 | weak_alias(__pthread_key_create, pthread_key_create); | ||
| 105 | weak_alias(__pthread_key_delete, pthread_key_delete); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutex_destroy(pthread_mutex_t *mutex) | ||
| 4 | { | ||
| 5 | #ifdef __wasilibc_unmodified_upstream | ||
| 6 | 	/* If the mutex being destroyed is process-shared and has nontrivial | ||
| 7 | 	 * type (tracking ownership), it might be in the pending slot of a | ||
| 8 | 	 * robust_list; wait for quiescence. */ | ||
| 9 | 	if (mutex->_m_type > 128) __vm_wait(); | ||
| 10 | #else | ||
| 11 | 	/* For now, wasi-libc chooses to avoid implementing robust mutex support | ||
| 12 | 	 * though this could be added later. The error code indicates that the | ||
| 13 | 	 * mutex was an invalid type, but it would be more accurate as | ||
| 14 | 	 * "unimplemented". */ | ||
| 15 | 	if (mutex->_m_type > 128) return EINVAL; | ||
| 16 | #endif | ||
| 17 | 	return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | static volatile int check_pi_result = -1; | ||
| 5 | |||
| 6 | int pthread_mutexattr_setprotocol(pthread_mutexattr_t *a, int protocol) | ||
| 7 | { | ||
| 8 | 	int r; | ||
| 9 | 	switch (protocol) { | ||
| 10 | 	case PTHREAD_PRIO_NONE: | ||
| 11 | 		a->__attr &= ~8; | ||
| 12 | 		return 0; | ||
| 13 | 	case PTHREAD_PRIO_INHERIT: | ||
| 14 | #ifdef __wasilibc_unmodified_upstream | ||
| 15 | 		r = check_pi_result; | ||
| 16 | 		if (r < 0) { | ||
| 17 | 			volatile int lk = 0; | ||
| 18 | 			r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0); | ||
| 19 | 			a_store(&check_pi_result, r); | ||
| 20 | 		} | ||
| 21 | 		if (r) return r; | ||
| 22 | 		a->__attr |= 8; | ||
| 23 | 		return 0; | ||
| 24 | #else | ||
| 25 | 		return ENOTSUP; | ||
| 26 | #endif | ||
| 27 | 	case PTHREAD_PRIO_PROTECT: | ||
| 28 | 		return ENOTSUP; | ||
| 29 | 	default: | ||
| 30 | 		return EINVAL; | ||
| 31 | 	} | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | static volatile int check_robust_result = -1; | ||
| 5 | |||
| 6 | int pthread_mutexattr_setrobust(pthread_mutexattr_t *a, int robust) | ||
| 7 | { | ||
| 8 | #ifdef __wasilibc_unmodified_upstream | ||
| 9 | 	if (robust > 1U) return EINVAL; | ||
| 10 | 	if (robust) { | ||
| 11 | 		int r = check_robust_result; | ||
| 12 | 		if (r < 0) { | ||
| 13 | 			void *p; | ||
| 14 | 			size_t l; | ||
| 15 | 			r = -__syscall(SYS_get_robust_list, 0, &p, &l); | ||
| 16 | 			a_store(&check_robust_result, r); | ||
| 17 | 		} | ||
| 18 | 		if (r) return r; | ||
| 19 | 		a->__attr |= 4; | ||
| 20 | 		return 0; | ||
| 21 | 	} | ||
| 22 | 	a->__attr &= ~4; | ||
| 23 | 	return 0; | ||
| 24 | #else | ||
| 25 | 	if (robust) return EINVAL; | ||
| 26 | 	return 0; | ||
| 27 | #endif | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c deleted-14| ... | @@ -1,14 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | #if !defined(__wasilibc_unmodified_upstream) && defined(__wasm__) | ||
| 5 | _Thread_local struct pthread __wasilibc_pthread_self; | ||
| 6 | #endif | ||
| 7 | |||
| 8 | static pthread_t __pthread_self_internal() | ||
| 9 | { | ||
| 10 | 	return __pthread_self(); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__pthread_self_internal, pthread_self); | ||
| 14 | weak_alias(__pthread_self_internal, thrd_current); | ||
lib/libc/wasi/libc-top-half/musl/src/time/__secs_to_tm.c deleted-82| ... | @@ -1,82 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | #include <limits.h> | ||
| 3 | |||
| 4 | /* 2000-03-01 (mod 400 year, immediately after feb29 */ | ||
| 5 | #define LEAPOCH (946684800LL + 86400*(31+29)) | ||
| 6 | |||
| 7 | #define DAYS_PER_400Y (365*400 + 97) | ||
| 8 | #define DAYS_PER_100Y (365*100 + 24) | ||
| 9 | #define DAYS_PER_4Y (365*4 + 1) | ||
| 10 | |||
| 11 | int __secs_to_tm(long long t, struct tm *tm) | ||
| 12 | { | ||
| 13 | 	long long days, secs, years; | ||
| 14 | 	int remdays, remsecs, remyears; | ||
| 15 | 	int qc_cycles, c_cycles, q_cycles; | ||
| 16 | 	int months; | ||
| 17 | 	int wday, yday, leap; | ||
| 18 | 	static const char days_in_month[] = {31,30,31,30,31,31,30,31,30,31,31,29}; | ||
| 19 | |||
| 20 | 	/* Reject time_t values whose year would overflow int */ | ||
| 21 | 	if (t < INT_MIN * 31622400LL || t > INT_MAX * 31622400LL) | ||
| 22 | 		return -1; | ||
| 23 | |||
| 24 | 	secs = t - LEAPOCH; | ||
| 25 | 	days = secs / 86400; | ||
| 26 | 	remsecs = secs % 86400; | ||
| 27 | 	if (remsecs < 0) { | ||
| 28 | 		remsecs += 86400; | ||
| 29 | 		days--; | ||
| 30 | 	} | ||
| 31 | |||
| 32 | 	wday = (3+days)%7; | ||
| 33 | 	if (wday < 0) wday += 7; | ||
| 34 | |||
| 35 | 	qc_cycles = days / DAYS_PER_400Y; | ||
| 36 | 	remdays = days % DAYS_PER_400Y; | ||
| 37 | 	if (remdays < 0) { | ||
| 38 | 		remdays += DAYS_PER_400Y; | ||
| 39 | 		qc_cycles--; | ||
| 40 | 	} | ||
| 41 | |||
| 42 | 	c_cycles = remdays / DAYS_PER_100Y; | ||
| 43 | 	if (c_cycles == 4) c_cycles--; | ||
| 44 | 	remdays -= c_cycles * DAYS_PER_100Y; | ||
| 45 | |||
| 46 | 	q_cycles = remdays / DAYS_PER_4Y; | ||
| 47 | 	if (q_cycles == 25) q_cycles--; | ||
| 48 | 	remdays -= q_cycles * DAYS_PER_4Y; | ||
| 49 | |||
| 50 | 	remyears = remdays / 365; | ||
| 51 | 	if (remyears == 4) remyears--; | ||
| 52 | 	remdays -= remyears * 365; | ||
| 53 | |||
| 54 | 	leap = !remyears && (q_cycles || !c_cycles); | ||
| 55 | 	yday = remdays + 31 + 28 + leap; | ||
| 56 | 	if (yday >= 365+leap) yday -= 365+leap; | ||
| 57 | |||
| 58 | 	years = remyears + 4*q_cycles + 100*c_cycles + 400LL*qc_cycles; | ||
| 59 | |||
| 60 | 	for (months=0; days_in_month[months] <= remdays; months++) | ||
| 61 | 		remdays -= days_in_month[months]; | ||
| 62 | |||
| 63 | 	if (months >= 10) { | ||
| 64 | 		months -= 12; | ||
| 65 | 		years++; | ||
| 66 | 	} | ||
| 67 | |||
| 68 | 	if (years+100 > INT_MAX || years+100 < INT_MIN) | ||
| 69 | 		return -1; | ||
| 70 | |||
| 71 | 	tm->tm_year = years + 100; | ||
| 72 | 	tm->tm_mon = months + 2; | ||
| 73 | 	tm->tm_mday = remdays + 1; | ||
| 74 | 	tm->tm_wday = wday; | ||
| 75 | 	tm->tm_yday = yday; | ||
| 76 | |||
| 77 | 	tm->tm_hour = remsecs / 3600; | ||
| 78 | 	tm->tm_min = remsecs / 60 % 60; | ||
| 79 | 	tm->tm_sec = remsecs % 60; | ||
| 80 | |||
| 81 | 	return 0; | ||
| 82 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/__tm_to_secs.c deleted-24| ... | @@ -1,24 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | |||
| 3 | long long __tm_to_secs(const struct tm *tm) | ||
| 4 | { | ||
| 5 | 	int is_leap; | ||
| 6 | 	long long year = tm->tm_year; | ||
| 7 | 	int month = tm->tm_mon; | ||
| 8 | 	if (month >= 12 || month < 0) { | ||
| 9 | 		int adj = month / 12; | ||
| 10 | 		month %= 12; | ||
| 11 | 		if (month < 0) { | ||
| 12 | 			adj--; | ||
| 13 | 			month += 12; | ||
| 14 | 		} | ||
| 15 | 		year += adj; | ||
| 16 | 	} | ||
| 17 | 	long long t = __year_to_secs(year, &is_leap); | ||
| 18 | 	t += __month_to_secs(month, is_leap); | ||
| 19 | 	t += 86400LL * (tm->tm_mday-1); | ||
| 20 | 	t += 3600LL * tm->tm_hour; | ||
| 21 | 	t += 60LL * tm->tm_min; | ||
| 22 | 	t += tm->tm_sec; | ||
| 23 | 	return t; | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/__tz.c deleted-455| ... | @@ -1,455 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <string.h> | ||
| 6 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 7 | #include <sys/mman.h> | ||
| 8 | #include <ctype.h> | ||
| 9 | #endif | ||
| 10 | #include "libc.h" | ||
| 11 | #include "lock.h" | ||
| 12 | #include "fork_impl.h" | ||
| 13 | |||
| 14 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 15 | long __timezone = 0; | ||
| 16 | int __daylight = 0; | ||
| 17 | char *__tzname[2] = { 0, 0 }; | ||
| 18 | |||
| 19 | weak_alias(__timezone, timezone); | ||
| 20 | weak_alias(__daylight, daylight); | ||
| 21 | weak_alias(__tzname, tzname); | ||
| 22 | |||
| 23 | static char std_name[TZNAME_MAX+1]; | ||
| 24 | static char dst_name[TZNAME_MAX+1]; | ||
| 25 | #endif | ||
| 26 | const char __utc[] = "UTC"; | ||
| 27 | |||
| 28 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 29 | static int dst_off; | ||
| 30 | static int r0[5], r1[5]; | ||
| 31 | |||
| 32 | static const unsigned char *zi, *trans, *index, *types, *abbrevs, *abbrevs_end; | ||
| 33 | static size_t map_size; | ||
| 34 | |||
| 35 | static char old_tz_buf[32]; | ||
| 36 | static char *old_tz = old_tz_buf; | ||
| 37 | static size_t old_tz_size = sizeof old_tz_buf; | ||
| 38 | |||
| 39 | static volatile int lock[1]; | ||
| 40 | volatile int *const __timezone_lockptr = lock; | ||
| 41 | |||
| 42 | static int getint(const char **p) | ||
| 43 | { | ||
| 44 | 	unsigned x; | ||
| 45 | 	for (x=0; **p-'0'<10U; (*p)++) x = **p-'0' + 10*x; | ||
| 46 | 	return x; | ||
| 47 | } | ||
| 48 | |||
| 49 | static int getoff(const char **p) | ||
| 50 | { | ||
| 51 | 	int neg = 0; | ||
| 52 | 	if (**p == '-') { | ||
| 53 | 		++*p; | ||
| 54 | 		neg = 1; | ||
| 55 | 	} else if (**p == '+') { | ||
| 56 | 		++*p; | ||
| 57 | 	} | ||
| 58 | 	int off = 3600*getint(p); | ||
| 59 | 	if (**p == ':') { | ||
| 60 | 		++*p; | ||
| 61 | 		off += 60*getint(p); | ||
| 62 | 		if (**p == ':') { | ||
| 63 | 			++*p; | ||
| 64 | 			off += getint(p); | ||
| 65 | 		} | ||
| 66 | 	} | ||
| 67 | 	return neg ? -off : off; | ||
| 68 | } | ||
| 69 | |||
| 70 | static void getrule(const char **p, int rule[5]) | ||
| 71 | { | ||
| 72 | 	int r = rule[0] = **p; | ||
| 73 | |||
| 74 | 	if (r!='M') { | ||
| 75 | 		if (r=='J') ++*p; | ||
| 76 | 		else rule[0] = 0; | ||
| 77 | 		rule[1] = getint(p); | ||
| 78 | 	} else { | ||
| 79 | 		++*p; rule[1] = getint(p); | ||
| 80 | 		++*p; rule[2] = getint(p); | ||
| 81 | 		++*p; rule[3] = getint(p); | ||
| 82 | 	} | ||
| 83 | |||
| 84 | 	if (**p=='/') { | ||
| 85 | 		++*p; | ||
| 86 | 		rule[4] = getoff(p); | ||
| 87 | 	} else { | ||
| 88 | 		rule[4] = 7200; | ||
| 89 | 	} | ||
| 90 | } | ||
| 91 | |||
| 92 | static void getname(char *d, const char **p) | ||
| 93 | { | ||
| 94 | 	int i; | ||
| 95 | 	if (**p == '<') { | ||
| 96 | 		++*p; | ||
| 97 | 		for (i=0; (*p)[i] && (*p)[i]!='>'; i++) | ||
| 98 | 			if (i<TZNAME_MAX) d[i] = (*p)[i]; | ||
| 99 | 		if ((*p)[i]) ++*p; | ||
| 100 | 	} else { | ||
| 101 | 		for (i=0; ((*p)[i]|32)-'a'<26U; i++) | ||
| 102 | 			if (i<TZNAME_MAX) d[i] = (*p)[i]; | ||
| 103 | 	} | ||
| 104 | 	*p += i; | ||
| 105 | 	d[i<TZNAME_MAX?i:TZNAME_MAX] = 0; | ||
| 106 | } | ||
| 107 | |||
| 108 | #define VEC(...) ((const unsigned char[]){__VA_ARGS__}) | ||
| 109 | |||
| 110 | static uint32_t zi_read32(const unsigned char *z) | ||
| 111 | { | ||
| 112 | 	return (unsigned)z[0]<<24 | z[1]<<16 | z[2]<<8 | z[3]; | ||
| 113 | } | ||
| 114 | |||
| 115 | static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t n) | ||
| 116 | { | ||
| 117 | 	size_t y; | ||
| 118 | 	uint32_t x; | ||
| 119 | 	for (y=0; n; n--, z+=4, v++) { | ||
| 120 | 		x = zi_read32(z); | ||
| 121 | 		y += x * *v; | ||
| 122 | 	} | ||
| 123 | 	return y; | ||
| 124 | } | ||
| 125 | |||
| 126 | static void do_tzset() | ||
| 127 | { | ||
| 128 | 	char buf[NAME_MAX+25], *pathname=buf+24; | ||
| 129 | 	const char *try, *s, *p; | ||
| 130 | 	const unsigned char *map = 0; | ||
| 131 | 	size_t i; | ||
| 132 | 	static const char search[] = | ||
| 133 | 		"/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0"; | ||
| 134 | |||
| 135 | 	s = getenv("TZ"); | ||
| 136 | 	if (!s) s = "/etc/localtime"; | ||
| 137 | 	if (!*s) s = __utc; | ||
| 138 | |||
| 139 | 	if (old_tz && !strcmp(s, old_tz)) return; | ||
| 140 | |||
| 141 | 	for (i=0; i<5; i++) r0[i] = r1[i] = 0; | ||
| 142 | |||
| 143 | 	if (zi) __munmap((void *)zi, map_size); | ||
| 144 | |||
| 145 | 	/* Cache the old value of TZ to check if it has changed. Avoid | ||
| 146 | 	 * free so as not to pull it into static programs. Growth | ||
| 147 | 	 * strategy makes it so free would have minimal benefit anyway. */ | ||
| 148 | 	i = strlen(s); | ||
| 149 | 	if (i > PATH_MAX+1) s = __utc, i = 3; | ||
| 150 | 	if (i >= old_tz_size) { | ||
| 151 | 		old_tz_size *= 2; | ||
| 152 | 		if (i >= old_tz_size) old_tz_size = i+1; | ||
| 153 | 		if (old_tz_size > PATH_MAX+2) old_tz_size = PATH_MAX+2; | ||
| 154 | 		old_tz = malloc(old_tz_size); | ||
| 155 | 	} | ||
| 156 | 	if (old_tz) memcpy(old_tz, s, i+1); | ||
| 157 | |||
| 158 | 	int posix_form = 0; | ||
| 159 | 	if (*s != ':') { | ||
| 160 | 		p = s; | ||
| 161 | 		char dummy_name[TZNAME_MAX+1]; | ||
| 162 | 		getname(dummy_name, &p); | ||
| 163 | 		if (p!=s && (*p == '+' || *p == '-' || isdigit(*p) | ||
| 164 | 		 || !strcmp(dummy_name, "UTC") | ||
| 165 | 		 || !strcmp(dummy_name, "GMT"))) | ||
| 166 | 			posix_form = 1; | ||
| 167 | 	}	 | ||
| 168 | |||
| 169 | 	/* Non-suid can use an absolute tzfile pathname or a relative | ||
| 170 | 	 * pathame beginning with "."; in secure mode, only the | ||
| 171 | 	 * standard path will be searched. */ | ||
| 172 | 	if (!posix_form) { | ||
| 173 | 		if (*s == ':') s++; | ||
| 174 | 		if (*s == '/' || *s == '.') { | ||
| 175 | 			if (!libc.secure || !strcmp(s, "/etc/localtime")) | ||
| 176 | 				map = __map_file(s, &map_size); | ||
| 177 | 		} else { | ||
| 178 | 			size_t l = strlen(s); | ||
| 179 | 			if (l <= NAME_MAX && !strchr(s, '.')) { | ||
| 180 | 				memcpy(pathname, s, l+1); | ||
| 181 | 				pathname[l] = 0; | ||
| 182 | 				for (try=search; !map && *try; try+=l+1) { | ||
| 183 | 					l = strlen(try); | ||
| 184 | 					memcpy(pathname-l, try, l); | ||
| 185 | 					map = __map_file(pathname-l, &map_size); | ||
| 186 | 				} | ||
| 187 | 			} | ||
| 188 | 		} | ||
| 189 | 		if (!map) s = __utc; | ||
| 190 | 	} | ||
| 191 | 	if (map && (map_size < 44 || memcmp(map, "TZif", 4))) { | ||
| 192 | 		__munmap((void *)map, map_size); | ||
| 193 | 		map = 0; | ||
| 194 | 		s = __utc; | ||
| 195 | 	} | ||
| 196 | |||
| 197 | 	zi = map; | ||
| 198 | 	if (map) { | ||
| 199 | 		int scale = 2; | ||
| 200 | 		if (map[4]!='1') { | ||
| 201 | 			size_t skip = zi_dotprod(zi+20, VEC(1,1,8,5,6,1), 6); | ||
| 202 | 			trans = zi+skip+44+44; | ||
| 203 | 			scale++; | ||
| 204 | 		} else { | ||
| 205 | 			trans = zi+44; | ||
| 206 | 		} | ||
| 207 | 		index = trans + (zi_read32(trans-12) << scale); | ||
| 208 | 		types = index + zi_read32(trans-12); | ||
| 209 | 		abbrevs = types + 6*zi_read32(trans-8); | ||
| 210 | 		abbrevs_end = abbrevs + zi_read32(trans-4); | ||
| 211 | 		if (zi[map_size-1] == '\n') { | ||
| 212 | 			for (s = (const char *)zi+map_size-2; *s!='\n'; s--); | ||
| 213 | 			s++; | ||
| 214 | 		} else { | ||
| 215 | 			const unsigned char *p; | ||
| 216 | 			__tzname[0] = __tzname[1] = 0; | ||
| 217 | 			__daylight = __timezone = dst_off = 0; | ||
| 218 | 			for (p=types; p<abbrevs; p+=6) { | ||
| 219 | 				if (!p[4] && !__tzname[0]) { | ||
| 220 | 					__tzname[0] = (char *)abbrevs + p[5]; | ||
| 221 | 					__timezone = -zi_read32(p); | ||
| 222 | 				} | ||
| 223 | 				if (p[4] && !__tzname[1]) { | ||
| 224 | 					__tzname[1] = (char *)abbrevs + p[5]; | ||
| 225 | 					dst_off = -zi_read32(p); | ||
| 226 | 					__daylight = 1; | ||
| 227 | 				} | ||
| 228 | 			} | ||
| 229 | 			if (!__tzname[0]) __tzname[0] = __tzname[1]; | ||
| 230 | 			if (!__tzname[0]) __tzname[0] = (char *)__utc; | ||
| 231 | 			if (!__daylight) { | ||
| 232 | 				__tzname[1] = __tzname[0]; | ||
| 233 | 				dst_off = __timezone; | ||
| 234 | 			} | ||
| 235 | 			return; | ||
| 236 | 		} | ||
| 237 | 	} | ||
| 238 | |||
| 239 | 	if (!s) s = __utc; | ||
| 240 | 	getname(std_name, &s); | ||
| 241 | 	__tzname[0] = std_name; | ||
| 242 | 	__timezone = getoff(&s); | ||
| 243 | 	getname(dst_name, &s); | ||
| 244 | 	__tzname[1] = dst_name; | ||
| 245 | 	if (dst_name[0]) { | ||
| 246 | 		__daylight = 1; | ||
| 247 | 		if (*s == '+' || *s=='-' || *s-'0'<10U) | ||
| 248 | 			dst_off = getoff(&s); | ||
| 249 | 		else | ||
| 250 | 			dst_off = __timezone - 3600; | ||
| 251 | 	} else { | ||
| 252 | 		__daylight = 0; | ||
| 253 | 		dst_off = __timezone; | ||
| 254 | 	} | ||
| 255 | |||
| 256 | 	if (*s == ',') s++, getrule(&s, r0); | ||
| 257 | 	if (*s == ',') s++, getrule(&s, r1); | ||
| 258 | } | ||
| 259 | |||
| 260 | /* Search zoneinfo rules to find the one that applies to the given time, | ||
| 261 | * and determine alternate opposite-DST-status rule that may be needed. */ | ||
| 262 | |||
| 263 | static size_t scan_trans(long long t, int local, size_t *alt) | ||
| 264 | { | ||
| 265 | 	int scale = 3 - (trans == zi+44); | ||
| 266 | 	uint64_t x; | ||
| 267 | 	int off = 0; | ||
| 268 | |||
| 269 | 	size_t a = 0, n = (index-trans)>>scale, m; | ||
| 270 | |||
| 271 | 	if (!n) { | ||
| 272 | 		if (alt) *alt = 0; | ||
| 273 | 		return 0; | ||
| 274 | 	} | ||
| 275 | |||
| 276 | 	/* Binary search for 'most-recent rule before t'. */ | ||
| 277 | 	while (n > 1) { | ||
| 278 | 		m = a + n/2; | ||
| 279 | 		x = zi_read32(trans + (m<<scale)); | ||
| 280 | 		if (scale == 3) x = x<<32 | zi_read32(trans + (m<<scale) + 4); | ||
| 281 | 		else x = (int32_t)x; | ||
| 282 | 		if (local) off = (int32_t)zi_read32(types + 6 * index[m-1]); | ||
| 283 | 		if (t - off < (int64_t)x) { | ||
| 284 | 			n /= 2; | ||
| 285 | 		} else { | ||
| 286 | 			a = m; | ||
| 287 | 			n -= n/2; | ||
| 288 | 		} | ||
| 289 | 	} | ||
| 290 | |||
| 291 | 	/* First and last entry are special. First means to use lowest-index | ||
| 292 | 	 * non-DST type. Last means to apply POSIX-style rule if available. */ | ||
| 293 | 	n = (index-trans)>>scale; | ||
| 294 | 	if (a == n-1) return -1; | ||
| 295 | 	if (a == 0) { | ||
| 296 | 		x = zi_read32(trans); | ||
| 297 | 		if (scale == 3) x = x<<32 | zi_read32(trans + 4); | ||
| 298 | 		else x = (int32_t)x; | ||
| 299 | 		/* Find the lowest non-DST type, or 0 if none. */ | ||
| 300 | 		size_t j = 0; | ||
| 301 | 		for (size_t i=abbrevs-types; i; i-=6) { | ||
| 302 | 			if (!types[i-6+4]) j = i-6; | ||
| 303 | 		} | ||
| 304 | 		if (local) off = (int32_t)zi_read32(types + j); | ||
| 305 | 		/* If t is before first transition, use the above-found type | ||
| 306 | 		 * and the index-zero (after transition) type as the alt. */ | ||
| 307 | 		if (t - off < (int64_t)x) { | ||
| 308 | 			if (alt) *alt = index[0]; | ||
| 309 | 			return j/6; | ||
| 310 | 		} | ||
| 311 | 	} | ||
| 312 | |||
| 313 | 	/* Try to find a neighboring opposite-DST-status rule. */ | ||
| 314 | 	if (alt) { | ||
| 315 | 		if (a && types[6*index[a-1]+4] != types[6*index[a]+4]) | ||
| 316 | 			*alt = index[a-1]; | ||
| 317 | 		else if (a+1<n && types[6*index[a+1]+4] != types[6*index[a]+4]) | ||
| 318 | 			*alt = index[a+1]; | ||
| 319 | 		else | ||
| 320 | 			*alt = index[a]; | ||
| 321 | 	} | ||
| 322 | |||
| 323 | 	return index[a]; | ||
| 324 | } | ||
| 325 | |||
| 326 | static int days_in_month(int m, int is_leap) | ||
| 327 | { | ||
| 328 | 	if (m==2) return 28+is_leap; | ||
| 329 | 	else return 30+((0xad5>>(m-1))&1); | ||
| 330 | } | ||
| 331 | |||
| 332 | /* Convert a POSIX DST rule plus year to seconds since epoch. */ | ||
| 333 | |||
| 334 | static long long rule_to_secs(const int *rule, int year) | ||
| 335 | { | ||
| 336 | 	int is_leap; | ||
| 337 | 	long long t = __year_to_secs(year, &is_leap); | ||
| 338 | 	int x, m, n, d; | ||
| 339 | 	if (rule[0]!='M') { | ||
| 340 | 		x = rule[1]; | ||
| 341 | 		if (rule[0]=='J' && (x < 60 || !is_leap)) x--; | ||
| 342 | 		t += 86400 * x; | ||
| 343 | 	} else { | ||
| 344 | 		m = rule[1]; | ||
| 345 | 		n = rule[2]; | ||
| 346 | 		d = rule[3]; | ||
| 347 | 		t += __month_to_secs(m-1, is_leap); | ||
| 348 | 		int wday = (int)((t + 4*86400) % (7*86400)) / 86400; | ||
| 349 | 		int days = d - wday; | ||
| 350 | 		if (days < 0) days += 7; | ||
| 351 | 		if (n == 5 && days+28 >= days_in_month(m, is_leap)) n = 4; | ||
| 352 | 		t += 86400 * (days + 7*(n-1)); | ||
| 353 | 	} | ||
| 354 | 	t += rule[4]; | ||
| 355 | 	return t; | ||
| 356 | } | ||
| 357 | |||
| 358 | /* Determine the time zone in effect for a given time in seconds since the | ||
| 359 | * epoch. It can be given in local or universal time. The results will | ||
| 360 | * indicate whether DST is in effect at the queried time, and will give both | ||
| 361 | * the GMT offset for the active zone/DST rule and the opposite DST. This | ||
| 362 | * enables a caller to efficiently adjust for the case where an explicit | ||
| 363 | * DST specification mismatches what would be in effect at the time. */ | ||
| 364 | |||
| 365 | void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppoff, const char **zonename) | ||
| 366 | { | ||
| 367 | 	LOCK(lock); | ||
| 368 | |||
| 369 | 	do_tzset(); | ||
| 370 | |||
| 371 | 	if (zi) { | ||
| 372 | 		size_t alt, i = scan_trans(t, local, &alt); | ||
| 373 | 		if (i != -1) { | ||
| 374 | 			*isdst = types[6*i+4]; | ||
| 375 | 			*offset = (int32_t)zi_read32(types+6*i); | ||
| 376 | 			*zonename = (const char *)abbrevs + types[6*i+5]; | ||
| 377 | 			if (oppoff) *oppoff = (int32_t)zi_read32(types+6*alt); | ||
| 378 | 			UNLOCK(lock); | ||
| 379 | 			return; | ||
| 380 | 		} | ||
| 381 | 	} | ||
| 382 | |||
| 383 | 	if (!__daylight) goto std; | ||
| 384 | |||
| 385 | 	/* FIXME: may be broken if DST changes right at year boundary? | ||
| 386 | 	 * Also, this could be more efficient.*/ | ||
| 387 | 	long long y = t / 31556952 + 70; | ||
| 388 | 	while (__year_to_secs(y, 0) > t) y--; | ||
| 389 | 	while (__year_to_secs(y+1, 0) < t) y++; | ||
| 390 | |||
| 391 | 	long long t0 = rule_to_secs(r0, y); | ||
| 392 | 	long long t1 = rule_to_secs(r1, y); | ||
| 393 | |||
| 394 | 	if (!local) { | ||
| 395 | 		t0 += __timezone; | ||
| 396 | 		t1 += dst_off; | ||
| 397 | 	} | ||
| 398 | 	if (t0 < t1) { | ||
| 399 | 		if (t >= t0 && t < t1) goto dst; | ||
| 400 | 		goto std; | ||
| 401 | 	} else { | ||
| 402 | 		if (t >= t1 && t < t0) goto std; | ||
| 403 | 		goto dst; | ||
| 404 | 	} | ||
| 405 | std: | ||
| 406 | 	*isdst = 0; | ||
| 407 | 	*offset = -__timezone; | ||
| 408 | 	if (oppoff) *oppoff = -dst_off; | ||
| 409 | 	*zonename = __tzname[0]; | ||
| 410 | 	UNLOCK(lock); | ||
| 411 | 	return; | ||
| 412 | dst: | ||
| 413 | 	*isdst = 1; | ||
| 414 | 	*offset = -dst_off; | ||
| 415 | 	if (oppoff) *oppoff = -__timezone; | ||
| 416 | 	*zonename = __tzname[1]; | ||
| 417 | 	UNLOCK(lock); | ||
| 418 | } | ||
| 419 | |||
| 420 | static void __tzset() | ||
| 421 | { | ||
| 422 | 	LOCK(lock); | ||
| 423 | 	do_tzset(); | ||
| 424 | 	UNLOCK(lock); | ||
| 425 | } | ||
| 426 | |||
| 427 | weak_alias(__tzset, tzset); | ||
| 428 | #else | ||
| 429 | void __secs_to_zone(long long t, int local, int *isdst, int *offset, long *oppoff, const char **zonename) | ||
| 430 | { | ||
| 431 | 	// Minimalist implementation for now. | ||
| 432 | 	if (isdst) | ||
| 433 | 		*isdst = 0; | ||
| 434 | 	if (offset) | ||
| 435 | 		*offset = 0; | ||
| 436 | 	if (oppoff) | ||
| 437 | 		*oppoff = 0; | ||
| 438 | 	if (zonename) | ||
| 439 | 		*zonename = __utc; | ||
| 440 | } | ||
| 441 | #endif | ||
| 442 | |||
| 443 | const char *__tm_to_tzname(const struct tm *tm) | ||
| 444 | { | ||
| 445 | 	const void *p = tm->__tm_zone; | ||
| 446 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 447 | 	LOCK(lock); | ||
| 448 | 	do_tzset(); | ||
| 449 | 	if (p != __utc && p != __tzname[0] && p != __tzname[1] && | ||
| 450 | 	 (!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs)) | ||
| 451 | 		p = ""; | ||
| 452 | 	UNLOCK(lock); | ||
| 453 | #endif | ||
| 454 | 	return p; | ||
| 455 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/getdate.c deleted-52| ... | @@ -1,52 +0,0 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 3 | #include <pthread.h> | ||
| 4 | #endif | ||
| 5 | #include <errno.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | |||
| 9 | int getdate_err; | ||
| 10 | |||
| 11 | struct tm *getdate(const char *s) | ||
| 12 | { | ||
| 13 | 	static struct tm tmbuf; | ||
| 14 | 	struct tm *ret = 0; | ||
| 15 | 	char *datemsk = getenv("DATEMSK"); | ||
| 16 | 	FILE *f = 0; | ||
| 17 | 	char fmt[100], *p; | ||
| 18 | 	int cs; | ||
| 19 | |||
| 20 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 21 | 	pthread_setcancelstate(PTHREAD_CANCEL_DEFERRED, &cs); | ||
| 22 | #endif | ||
| 23 | |||
| 24 | 	if (!datemsk) { | ||
| 25 | 		getdate_err = 1; | ||
| 26 | 		goto out; | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	f = fopen(datemsk, "rbe"); | ||
| 30 | 	if (!f) { | ||
| 31 | 		if (errno == ENOMEM) getdate_err = 6; | ||
| 32 | 		else getdate_err = 2; | ||
| 33 | 		goto out; | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	while (fgets(fmt, sizeof fmt, f)) { | ||
| 37 | 		p = strptime(s, fmt, &tmbuf); | ||
| 38 | 		if (p && !*p) { | ||
| 39 | 			ret = &tmbuf; | ||
| 40 | 			goto out; | ||
| 41 | 		} | ||
| 42 | 	} | ||
| 43 | |||
| 44 | 	if (ferror(f)) getdate_err = 5; | ||
| 45 | 	else getdate_err = 7; | ||
| 46 | out: | ||
| 47 | 	if (f) fclose(f); | ||
| 48 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 49 | 	pthread_setcancelstate(cs, 0); | ||
| 50 | #endif | ||
| 51 | 	return ret; | ||
| 52 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/gmtime.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | struct tm *gmtime(const time_t *t) | ||
| 5 | { | ||
| 6 | 	static struct tm tm; | ||
| 7 | 	return __gmtime_r(t, &tm); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/gmtime_r.c deleted-16| ... | @@ -1,16 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | struct tm *__gmtime_r(const time_t *restrict t, struct tm *restrict tm) | ||
| 5 | { | ||
| 6 | 	if (__secs_to_tm(*t, tm) < 0) { | ||
| 7 | 		errno = EOVERFLOW; | ||
| 8 | 		return 0; | ||
| 9 | 	} | ||
| 10 | 	tm->tm_isdst = 0; | ||
| 11 | 	tm->__tm_gmtoff = 0; | ||
| 12 | 	tm->__tm_zone = __utc; | ||
| 13 | 	return tm; | ||
| 14 | } | ||
| 15 | |||
| 16 | weak_alias(__gmtime_r, gmtime_r); | ||
lib/libc/wasi/libc-top-half/musl/src/time/localtime.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | |||
| 3 | struct tm *localtime(const time_t *t) | ||
| 4 | { | ||
| 5 | 	static struct tm tm; | ||
| 6 | 	return __localtime_r(t, &tm); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/localtime_r.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | struct tm *__localtime_r(const time_t *restrict t, struct tm *restrict tm) | ||
| 6 | { | ||
| 7 | 	/* Reject time_t values whose year would overflow int because | ||
| 8 | 	 * __secs_to_zone cannot safely handle them. */ | ||
| 9 | 	if (*t < INT_MIN * 31622400LL || *t > INT_MAX * 31622400LL) { | ||
| 10 | 		errno = EOVERFLOW; | ||
| 11 | 		return 0; | ||
| 12 | 	} | ||
| 13 | 	__secs_to_zone(*t, 0, &tm->tm_isdst, &tm->__tm_gmtoff, 0, &tm->__tm_zone); | ||
| 14 | 	if (__secs_to_tm((long long)*t + tm->__tm_gmtoff, tm) < 0) { | ||
| 15 | 		errno = EOVERFLOW; | ||
| 16 | 		return 0; | ||
| 17 | 	} | ||
| 18 | 	return tm; | ||
| 19 | } | ||
| 20 | |||
| 21 | weak_alias(__localtime_r, localtime_r); | ||
lib/libc/wasi/libc-top-half/musl/src/time/mktime.c deleted-28| ... | @@ -1,28 +0,0 @@ | ||
| 1 | #include "time_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | time_t mktime(struct tm *tm) | ||
| 5 | { | ||
| 6 | 	struct tm new; | ||
| 7 | 	long opp; | ||
| 8 | 	long long t = __tm_to_secs(tm); | ||
| 9 | |||
| 10 | 	__secs_to_zone(t, 1, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); | ||
| 11 | |||
| 12 | 	if (tm->tm_isdst>=0 && new.tm_isdst!=tm->tm_isdst) | ||
| 13 | 		t -= opp - new.__tm_gmtoff; | ||
| 14 | |||
| 15 | 	t -= new.__tm_gmtoff; | ||
| 16 | 	if ((time_t)t != t) goto error; | ||
| 17 | |||
| 18 | 	__secs_to_zone(t, 0, &new.tm_isdst, &new.__tm_gmtoff, &opp, &new.__tm_zone); | ||
| 19 | |||
| 20 | 	if (__secs_to_tm(t + new.__tm_gmtoff, &new) < 0) goto error; | ||
| 21 | |||
| 22 | 	*tm = new; | ||
| 23 | 	return t; | ||
| 24 | |||
| 25 | error: | ||
| 26 | 	errno = EOVERFLOW; | ||
| 27 | 	return -1; | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/strftime.c deleted-291| ... | @@ -1,291 +0,0 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <langinfo.h> | ||
| 5 | #include <locale.h> | ||
| 6 | #include <ctype.h> | ||
| 7 | #include <time.h> | ||
| 8 | #include <limits.h> | ||
| 9 | #include "locale_impl.h" | ||
| 10 | #include "time_impl.h" | ||
| 11 | |||
| 12 | static int is_leap(int y) | ||
| 13 | { | ||
| 14 | 	/* Avoid overflow */ | ||
| 15 | 	if (y>INT_MAX-1900) y -= 2000; | ||
| 16 | 	y += 1900; | ||
| 17 | 	return !(y%4) && ((y%100) || !(y%400)); | ||
| 18 | } | ||
| 19 | |||
| 20 | static int week_num(const struct tm *tm) | ||
| 21 | { | ||
| 22 | 	int val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; | ||
| 23 | 	/* If 1 Jan is just 1-3 days past Monday, | ||
| 24 | 	 * the previous week is also in this year. */ | ||
| 25 | 	if ((tm->tm_wday + 371U - tm->tm_yday - 2) % 7 <= 2) | ||
| 26 | 		val++; | ||
| 27 | 	if (!val) { | ||
| 28 | 		val = 52; | ||
| 29 | 		/* If 31 December of prev year a Thursday, | ||
| 30 | 		 * or Friday of a leap year, then the | ||
| 31 | 		 * prev year has 53 weeks. */ | ||
| 32 | 		int dec31 = (tm->tm_wday + 7U - tm->tm_yday - 1) % 7; | ||
| 33 | 		if (dec31 == 4 || (dec31 == 5 && is_leap(tm->tm_year%400-1))) | ||
| 34 | 			val++; | ||
| 35 | 	} else if (val == 53) { | ||
| 36 | 		/* If 1 January is not a Thursday, and not | ||
| 37 | 		 * a Wednesday of a leap year, then this | ||
| 38 | 		 * year has only 52 weeks. */ | ||
| 39 | 		int jan1 = (tm->tm_wday + 371U - tm->tm_yday) % 7; | ||
| 40 | 		if (jan1 != 4 && (jan1 != 3 || !is_leap(tm->tm_year))) | ||
| 41 | 			val = 1; | ||
| 42 | 	} | ||
| 43 | 	return val; | ||
| 44 | } | ||
| 45 | |||
| 46 | const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad) | ||
| 47 | { | ||
| 48 | 	nl_item item; | ||
| 49 | 	long long val; | ||
| 50 | 	const char *fmt = "-"; | ||
| 51 | 	int width = 2, def_pad = '0'; | ||
| 52 | |||
| 53 | 	switch (f) { | ||
| 54 | 	case 'a': | ||
| 55 | 		if (tm->tm_wday > 6U) goto string; | ||
| 56 | 		item = ABDAY_1 + tm->tm_wday; | ||
| 57 | 		goto nl_strcat; | ||
| 58 | 	case 'A': | ||
| 59 | 		if (tm->tm_wday > 6U) goto string; | ||
| 60 | 		item = DAY_1 + tm->tm_wday; | ||
| 61 | 		goto nl_strcat; | ||
| 62 | 	case 'h': | ||
| 63 | 	case 'b': | ||
| 64 | 		if (tm->tm_mon > 11U) goto string; | ||
| 65 | 		item = ABMON_1 + tm->tm_mon; | ||
| 66 | 		goto nl_strcat; | ||
| 67 | 	case 'B': | ||
| 68 | 		if (tm->tm_mon > 11U) goto string; | ||
| 69 | 		item = MON_1 + tm->tm_mon; | ||
| 70 | 		goto nl_strcat; | ||
| 71 | 	case 'c': | ||
| 72 | 		item = D_T_FMT; | ||
| 73 | 		goto nl_strftime; | ||
| 74 | 	case 'C': | ||
| 75 | 		val = (1900LL+tm->tm_year) / 100; | ||
| 76 | 		goto number; | ||
| 77 | 	case 'e': | ||
| 78 | 		def_pad = '_'; | ||
| 79 | 	case 'd': | ||
| 80 | 		val = tm->tm_mday; | ||
| 81 | 		goto number; | ||
| 82 | 	case 'D': | ||
| 83 | 		fmt = "%m/%d/%y"; | ||
| 84 | 		goto recu_strftime; | ||
| 85 | 	case 'F': | ||
| 86 | 		fmt = "%Y-%m-%d"; | ||
| 87 | 		goto recu_strftime; | ||
| 88 | 	case 'g': | ||
| 89 | 	case 'G': | ||
| 90 | 		val = tm->tm_year + 1900LL; | ||
| 91 | 		if (tm->tm_yday < 3 && week_num(tm) != 1) val--; | ||
| 92 | 		else if (tm->tm_yday > 360 && week_num(tm) == 1) val++; | ||
| 93 | 		if (f=='g') val %= 100; | ||
| 94 | 		else width = 4; | ||
| 95 | 		goto number; | ||
| 96 | 	case 'H': | ||
| 97 | 		val = tm->tm_hour; | ||
| 98 | 		goto number; | ||
| 99 | 	case 'I': | ||
| 100 | 		val = tm->tm_hour; | ||
| 101 | 		if (!val) val = 12; | ||
| 102 | 		else if (val > 12) val -= 12; | ||
| 103 | 		goto number; | ||
| 104 | 	case 'j': | ||
| 105 | 		val = tm->tm_yday+1; | ||
| 106 | 		width = 3; | ||
| 107 | 		goto number; | ||
| 108 | 	case 'm': | ||
| 109 | 		val = tm->tm_mon+1; | ||
| 110 | 		goto number; | ||
| 111 | 	case 'M': | ||
| 112 | 		val = tm->tm_min; | ||
| 113 | 		goto number; | ||
| 114 | 	case 'n': | ||
| 115 | 		*l = 1; | ||
| 116 | 		return "\n"; | ||
| 117 | 	case 'p': | ||
| 118 | 		item = tm->tm_hour >= 12 ? PM_STR : AM_STR; | ||
| 119 | 		goto nl_strcat; | ||
| 120 | 	case 'r': | ||
| 121 | 		item = T_FMT_AMPM; | ||
| 122 | 		goto nl_strftime; | ||
| 123 | 	case 'R': | ||
| 124 | 		fmt = "%H:%M"; | ||
| 125 | 		goto recu_strftime; | ||
| 126 | 	case 's': | ||
| 127 | 		val = __tm_to_secs(tm) - tm->__tm_gmtoff; | ||
| 128 | 		width = 1; | ||
| 129 | 		goto number; | ||
| 130 | 	case 'S': | ||
| 131 | 		val = tm->tm_sec; | ||
| 132 | 		goto number; | ||
| 133 | 	case 't': | ||
| 134 | 		*l = 1; | ||
| 135 | 		return "\t"; | ||
| 136 | 	case 'T': | ||
| 137 | 		fmt = "%H:%M:%S"; | ||
| 138 | 		goto recu_strftime; | ||
| 139 | 	case 'u': | ||
| 140 | 		val = tm->tm_wday ? tm->tm_wday : 7; | ||
| 141 | 		width = 1; | ||
| 142 | 		goto number; | ||
| 143 | 	case 'U': | ||
| 144 | 		val = (tm->tm_yday + 7U - tm->tm_wday) / 7; | ||
| 145 | 		goto number; | ||
| 146 | 	case 'W': | ||
| 147 | 		val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; | ||
| 148 | 		goto number; | ||
| 149 | 	case 'V': | ||
| 150 | 		val = week_num(tm); | ||
| 151 | 		goto number; | ||
| 152 | 	case 'w': | ||
| 153 | 		val = tm->tm_wday; | ||
| 154 | 		width = 1; | ||
| 155 | 		goto number; | ||
| 156 | 	case 'x': | ||
| 157 | 		item = D_FMT; | ||
| 158 | 		goto nl_strftime; | ||
| 159 | 	case 'X': | ||
| 160 | 		item = T_FMT; | ||
| 161 | 		goto nl_strftime; | ||
| 162 | 	case 'y': | ||
| 163 | 		val = (tm->tm_year + 1900LL) % 100; | ||
| 164 | 		if (val < 0) val = -val; | ||
| 165 | 		goto number; | ||
| 166 | 	case 'Y': | ||
| 167 | 		val = tm->tm_year + 1900LL; | ||
| 168 | 		if (val >= 10000) { | ||
| 169 | 			*l = snprintf(*s, sizeof *s, "+%lld", val); | ||
| 170 | 			return *s; | ||
| 171 | 		} | ||
| 172 | 		width = 4; | ||
| 173 | 		goto number; | ||
| 174 | 	case 'z': | ||
| 175 | 		if (tm->tm_isdst < 0) { | ||
| 176 | 			*l = 0; | ||
| 177 | 			return ""; | ||
| 178 | 		} | ||
| 179 | #ifdef __wasilibc_unmodified_upstream // wasi-libc's __tm_gmtoff is an int | ||
| 180 | 		*l = snprintf(*s, sizeof *s, "%+.4ld", | ||
| 181 | #else | ||
| 182 | 		*l = snprintf(*s, sizeof *s, "%+.4d", | ||
| 183 | #endif | ||
| 184 | 			tm->__tm_gmtoff/3600*100 + tm->__tm_gmtoff%3600/60); | ||
| 185 | 		return *s; | ||
| 186 | 	case 'Z': | ||
| 187 | 		if (tm->tm_isdst < 0) { | ||
| 188 | 			*l = 0; | ||
| 189 | 			return ""; | ||
| 190 | 		} | ||
| 191 | 		fmt = __tm_to_tzname(tm); | ||
| 192 | 		goto string; | ||
| 193 | 	case '%': | ||
| 194 | 		*l = 1; | ||
| 195 | 		return "%"; | ||
| 196 | 	default: | ||
| 197 | 		return 0; | ||
| 198 | 	} | ||
| 199 | number: | ||
| 200 | 	switch (pad ? pad : def_pad) { | ||
| 201 | 	case '-': *l = snprintf(*s, sizeof *s, "%lld", val); break; | ||
| 202 | 	case '_': *l = snprintf(*s, sizeof *s, "%*lld", width, val); break; | ||
| 203 | 	case '0': | ||
| 204 | 	default: *l = snprintf(*s, sizeof *s, "%0*lld", width, val); break; | ||
| 205 | 	} | ||
| 206 | 	return *s; | ||
| 207 | nl_strcat: | ||
| 208 | 	fmt = __nl_langinfo_l(item, loc); | ||
| 209 | string: | ||
| 210 | 	*l = strlen(fmt); | ||
| 211 | 	return fmt; | ||
| 212 | nl_strftime: | ||
| 213 | 	fmt = __nl_langinfo_l(item, loc); | ||
| 214 | recu_strftime: | ||
| 215 | 	*l = __strftime_l(*s, sizeof *s, fmt, tm, loc); | ||
| 216 | 	if (!*l) return 0; | ||
| 217 | 	return *s; | ||
| 218 | } | ||
| 219 | |||
| 220 | size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc) | ||
| 221 | { | ||
| 222 | 	size_t l, k; | ||
| 223 | 	char buf[100]; | ||
| 224 | 	char *p; | ||
| 225 | 	const char *t; | ||
| 226 | 	int pad, plus; | ||
| 227 | 	unsigned long width; | ||
| 228 | 	for (l=0; l<n; f++) { | ||
| 229 | 		if (!*f) { | ||
| 230 | 			s[l] = 0; | ||
| 231 | 			return l; | ||
| 232 | 		} | ||
| 233 | 		if (*f != '%') { | ||
| 234 | 			s[l++] = *f; | ||
| 235 | 			continue; | ||
| 236 | 		} | ||
| 237 | 		f++; | ||
| 238 | 		pad = 0; | ||
| 239 | 		if (*f == '-' || *f == '_' || *f == '0') pad = *f++; | ||
| 240 | 		if ((plus = (*f == '+'))) f++; | ||
| 241 | 		if (isdigit(*f)) { | ||
| 242 | 			width = strtoul(f, &p, 10); | ||
| 243 | 		} else { | ||
| 244 | 			width = 0; | ||
| 245 | 			p = (void *)f; | ||
| 246 | 		} | ||
| 247 | 		if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') { | ||
| 248 | 			if (!width && p!=f) width = 1; | ||
| 249 | 		} else { | ||
| 250 | 			width = 0; | ||
| 251 | 		} | ||
| 252 | 		f = p; | ||
| 253 | 		if (*f == 'E' || *f == 'O') f++; | ||
| 254 | 		t = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad); | ||
| 255 | 		if (!t) break; | ||
| 256 | 		if (width) { | ||
| 257 | 			/* Trim off any sign and leading zeros, then | ||
| 258 | 			 * count remaining digits to determine behavior | ||
| 259 | 			 * for the + flag. */ | ||
| 260 | 			if (*t=='+' || *t=='-') t++, k--; | ||
| 261 | 			for (; *t=='0' && t[1]-'0'<10U; t++, k--); | ||
| 262 | 			if (width < k) width = k; | ||
| 263 | 			size_t d; | ||
| 264 | 			for (d=0; t[d]-'0'<10U; d++); | ||
| 265 | 			if (tm->tm_year < -1900) { | ||
| 266 | 				s[l++] = '-'; | ||
| 267 | 				width--; | ||
| 268 | 			} else if (plus && d+(width-k) >= (*p=='C'?3:5)) { | ||
| 269 | 				s[l++] = '+'; | ||
| 270 | 				width--; | ||
| 271 | 			} | ||
| 272 | 			for (; width > k && l < n; width--) | ||
| 273 | 				s[l++] = '0'; | ||
| 274 | 		} | ||
| 275 | 		if (k > n-l) k = n-l; | ||
| 276 | 		memcpy(s+l, t, k); | ||
| 277 | 		l += k; | ||
| 278 | 	} | ||
| 279 | 	if (n) { | ||
| 280 | 		if (l==n) l=n-1; | ||
| 281 | 		s[l] = 0; | ||
| 282 | 	} | ||
| 283 | 	return 0; | ||
| 284 | } | ||
| 285 | |||
| 286 | size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) | ||
| 287 | { | ||
| 288 | 	return __strftime_l(s, n, f, tm, CURRENT_LOCALE); | ||
| 289 | } | ||
| 290 | |||
| 291 | weak_alias(__strftime_l, strftime_l); | ||
lib/libc/wasi/libc-top-half/musl/src/time/time_impl.h deleted-15| ... | @@ -1,15 +0,0 @@ | ||
| 1 | #include <time.h> | ||
| 2 | |||
| 3 | hidden int __days_in_month(int, int); | ||
| 4 | hidden int __month_to_secs(int, int); | ||
| 5 | hidden long long __year_to_secs(long long, int *); | ||
| 6 | hidden long long __tm_to_secs(const struct tm *); | ||
| 7 | hidden const char *__tm_to_tzname(const struct tm *); | ||
| 8 | hidden int __secs_to_tm(long long, struct tm *); | ||
| 9 | #ifdef __wasilibc_unmodified_upstream // type of __tm_gmtoff | ||
| 10 | hidden void __secs_to_zone(long long, int, int *, long *, long *, const char **); | ||
| 11 | #else | ||
| 12 | hidden void __secs_to_zone(long long, int, int *, int *, long *, const char **); | ||
| 13 | #endif | ||
| 14 | hidden const char *__strftime_fmt_1(char (*)[100], size_t *, int, const struct tm *, locale_t, int); | ||
| 15 | extern hidden const char __utc[]; | ||
lib/libc/wasi/libc-top-half/musl/src/time/timegm.c deleted-18| ... | @@ -1,18 +0,0 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "time_impl.h" | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | time_t timegm(struct tm *tm) | ||
| 6 | { | ||
| 7 | 	struct tm new; | ||
| 8 | 	long long t = __tm_to_secs(tm); | ||
| 9 | 	if (__secs_to_tm(t, &new) < 0) { | ||
| 10 | 		errno = EOVERFLOW; | ||
| 11 | 		return -1; | ||
| 12 | 	} | ||
| 13 | 	*tm = new; | ||
| 14 | 	tm->tm_isdst = 0; | ||
| 15 | 	tm->__tm_gmtoff = 0; | ||
| 16 | 	tm->__tm_zone = __utc; | ||
| 17 | 	return t; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/wcsftime.c deleted-71| ... | @@ -1,71 +0,0 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include <locale.h> | ||
| 4 | #include "locale_impl.h" | ||
| 5 | #include "time_impl.h" | ||
| 6 | |||
| 7 | size_t __wcsftime_l(wchar_t *restrict s, size_t n, const wchar_t *restrict f, const struct tm *restrict tm, locale_t loc) | ||
| 8 | { | ||
| 9 | 	size_t l, k; | ||
| 10 | 	char buf[100]; | ||
| 11 | 	wchar_t wbuf[100]; | ||
| 12 | 	wchar_t *p; | ||
| 13 | 	const char *t_mb; | ||
| 14 | 	const wchar_t *t; | ||
| 15 | 	int pad, plus; | ||
| 16 | 	unsigned long width; | ||
| 17 | 	for (l=0; l<n; f++) { | ||
| 18 | 		if (!*f) { | ||
| 19 | 			s[l] = 0; | ||
| 20 | 			return l; | ||
| 21 | 		} | ||
| 22 | 		if (*f != '%') { | ||
| 23 | 			s[l++] = *f; | ||
| 24 | 			continue; | ||
| 25 | 		} | ||
| 26 | 		f++; | ||
| 27 | 		pad = 0; | ||
| 28 | 		if (*f == '-' || *f == '_' || *f == '0') pad = *f++; | ||
| 29 | 		if ((plus = (*f == '+'))) f++; | ||
| 30 | 		width = wcstoul(f, &p, 10); | ||
| 31 | 		if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') { | ||
| 32 | 			if (!width && p!=f) width = 1; | ||
| 33 | 		} else { | ||
| 34 | 			width = 0; | ||
| 35 | 		} | ||
| 36 | 		f = p; | ||
| 37 | 		if (*f == 'E' || *f == 'O') f++; | ||
| 38 | 		t_mb = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad); | ||
| 39 | 		if (!t_mb) break; | ||
| 40 | 		k = mbstowcs(wbuf, t_mb, sizeof wbuf / sizeof *wbuf); | ||
| 41 | 		if (k == (size_t)-1) return 0; | ||
| 42 | 		t = wbuf; | ||
| 43 | 		if (width) { | ||
| 44 | 			for (; *t=='+' || *t=='-' || (*t=='0'&&t[1]); t++, k--); | ||
| 45 | 			width--; | ||
| 46 | 			if (plus && tm->tm_year >= 10000-1900) | ||
| 47 | 				s[l++] = '+'; | ||
| 48 | 			else if (tm->tm_year < -1900) | ||
| 49 | 				s[l++] = '-'; | ||
| 50 | 			else | ||
| 51 | 				width++; | ||
| 52 | 			for (; width > k && l < n; width--) | ||
| 53 | 				s[l++] = '0'; | ||
| 54 | 		} | ||
| 55 | 		if (k >= n-l) k = n-l; | ||
| 56 | 		wmemcpy(s+l, t, k); | ||
| 57 | 		l += k; | ||
| 58 | 	} | ||
| 59 | 	if (n) { | ||
| 60 | 		if (l==n) l=n-1; | ||
| 61 | 		s[l] = 0; | ||
| 62 | 	} | ||
| 63 | 	return 0; | ||
| 64 | } | ||
| 65 | |||
| 66 | size_t wcsftime(wchar_t *restrict wcs, size_t n, const wchar_t *restrict f, const struct tm *restrict tm) | ||
| 67 | { | ||
| 68 | 	return __wcsftime_l(wcs, n, f, tm, CURRENT_LOCALE); | ||
| 69 | } | ||
| 70 | |||
| 71 | weak_alias(__wcsftime_l, wcsftime_l); | ||
lib/libc/wasi/libc-top-half/sources/arc4random.c deleted-160| ... | @@ -1,160 +0,0 @@ | ||
| 1 | #include <assert.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | #define RNG_RESERVE_LEN 512 | ||
| 8 | |||
| 9 | #define CHACHA20_KEYBYTES 32 | ||
| 10 | #define CHACHA20_BLOCKBYTES 64 | ||
| 11 | |||
| 12 | #define ROTL32(x, b) (uint32_t)(((x) << (b)) | ((x) >> (32 - (b)))) | ||
| 13 | |||
| 14 | #define CHACHA20_QUARTERROUND(A, B, C, D) \ | ||
| 15 | A += B; \ | ||
| 16 | D = ROTL32(D ^ A, 16); \ | ||
| 17 | C += D; \ | ||
| 18 | B = ROTL32(B ^ C, 12); \ | ||
| 19 | A += B; \ | ||
| 20 | D = ROTL32(D ^ A, 8); \ | ||
| 21 | C += D; \ | ||
| 22 | B = ROTL32(B ^ C, 7) | ||
| 23 | |||
| 24 | static void CHACHA20_ROUNDS(uint32_t st[16]) | ||
| 25 | { | ||
| 26 | int i; | ||
| 27 | |||
| 28 | for (i = 0; i < 20; i += 2) { | ||
| 29 | CHACHA20_QUARTERROUND(st[0], st[4], st[8], st[12]); | ||
| 30 | CHACHA20_QUARTERROUND(st[1], st[5], st[9], st[13]); | ||
| 31 | CHACHA20_QUARTERROUND(st[2], st[6], st[10], st[14]); | ||
| 32 | CHACHA20_QUARTERROUND(st[3], st[7], st[11], st[15]); | ||
| 33 | CHACHA20_QUARTERROUND(st[0], st[5], st[10], st[15]); | ||
| 34 | CHACHA20_QUARTERROUND(st[1], st[6], st[11], st[12]); | ||
| 35 | CHACHA20_QUARTERROUND(st[2], st[7], st[8], st[13]); | ||
| 36 | CHACHA20_QUARTERROUND(st[3], st[4], st[9], st[14]); | ||
| 37 | } | ||
| 38 | } | ||
| 39 | |||
| 40 | static void chacha20_update(uint8_t out[CHACHA20_BLOCKBYTES], uint32_t st[16]) | ||
| 41 | { | ||
| 42 | uint32_t ks[16]; | ||
| 43 | int i; | ||
| 44 | |||
| 45 | memcpy(ks, st, 4 * 16); | ||
| 46 | CHACHA20_ROUNDS(st); | ||
| 47 | for (i = 0; i < 16; i++) { | ||
| 48 | ks[i] += st[i]; | ||
| 49 | } | ||
| 50 | memcpy(out, ks, CHACHA20_BLOCKBYTES); | ||
| 51 | st[12]++; | ||
| 52 | } | ||
| 53 | |||
| 54 | static void chacha20_init(uint32_t st[16], const uint8_t key[CHACHA20_KEYBYTES]) | ||
| 55 | { | ||
| 56 | static const uint32_t constants[4] = { 0x61707865, 0x3320646e, 0x79622d32, 0x6b206574 }; | ||
| 57 | memcpy(&st[0], constants, 4 * 4); | ||
| 58 | memcpy(&st[4], key, CHACHA20_KEYBYTES); | ||
| 59 | memset(&st[12], 0, 4 * 4); | ||
| 60 | } | ||
| 61 | |||
| 62 | static int chacha20_rng(uint8_t* out, size_t len, uint8_t key[CHACHA20_KEYBYTES]) | ||
| 63 | { | ||
| 64 | uint32_t st[16]; | ||
| 65 | size_t off; | ||
| 66 | |||
| 67 | chacha20_init(st, key); | ||
| 68 | chacha20_update(&out[0], st); | ||
| 69 | memcpy(key, out, CHACHA20_KEYBYTES); | ||
| 70 | off = 0; | ||
| 71 | while (len >= CHACHA20_BLOCKBYTES) { | ||
| 72 | chacha20_update(&out[off], st); | ||
| 73 | len -= CHACHA20_BLOCKBYTES; | ||
| 74 | off += CHACHA20_BLOCKBYTES; | ||
| 75 | } | ||
| 76 | if (len > 0) { | ||
| 77 | uint8_t tmp[CHACHA20_BLOCKBYTES]; | ||
| 78 | chacha20_update(tmp, st); | ||
| 79 | memcpy(&out[off], tmp, len); | ||
| 80 | } | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | |||
| 84 | struct rng_state { | ||
| 85 | int initialized; | ||
| 86 | size_t off; | ||
| 87 | uint8_t key[CHACHA20_KEYBYTES]; | ||
| 88 | uint8_t reserve[RNG_RESERVE_LEN]; | ||
| 89 | }; | ||
| 90 | |||
| 91 | void arc4random_buf(void* buffer, size_t len) | ||
| 92 | { | ||
| 93 | static _Thread_local struct rng_state rng_state; | ||
| 94 | |||
| 95 | unsigned char* buffer_ = (unsigned char*)buffer; | ||
| 96 | size_t off; | ||
| 97 | size_t remaining; | ||
| 98 | size_t partial; | ||
| 99 | |||
| 100 | if (!rng_state.initialized) { | ||
| 101 | if (getentropy(rng_state.key, sizeof rng_state.key) != 0) { | ||
| 102 | assert(0); | ||
| 103 | } | ||
| 104 | rng_state.off = RNG_RESERVE_LEN; | ||
| 105 | rng_state.initialized = 1; | ||
| 106 | } | ||
| 107 | off = 0; | ||
| 108 | remaining = len; | ||
| 109 | while (remaining > 0) { | ||
| 110 | if (rng_state.off == RNG_RESERVE_LEN) { | ||
| 111 | while (remaining >= RNG_RESERVE_LEN) { | ||
| 112 | chacha20_rng(&buffer_[off], RNG_RESERVE_LEN, rng_state.key); | ||
| 113 | off += RNG_RESERVE_LEN; | ||
| 114 | remaining -= RNG_RESERVE_LEN; | ||
| 115 | } | ||
| 116 | if (remaining == 0) { | ||
| 117 | break; | ||
| 118 | } | ||
| 119 | chacha20_rng(&rng_state.reserve[0], RNG_RESERVE_LEN, rng_state.key); | ||
| 120 | rng_state.off = 0; | ||
| 121 | } | ||
| 122 | partial = RNG_RESERVE_LEN - rng_state.off; | ||
| 123 | if (remaining < partial) { | ||
| 124 | partial = remaining; | ||
| 125 | } | ||
| 126 | memcpy(&buffer_[off], &rng_state.reserve[rng_state.off], partial); | ||
| 127 | memset(&rng_state.reserve[rng_state.off], 0, partial); | ||
| 128 | rng_state.off += partial; | ||
| 129 | remaining -= partial; | ||
| 130 | off += partial; | ||
| 131 | } | ||
| 132 | } | ||
| 133 | |||
| 134 | uint32_t arc4random(void) | ||
| 135 | { | ||
| 136 | uint32_t v; | ||
| 137 | |||
| 138 | arc4random_buf(&v, sizeof v); | ||
| 139 | |||
| 140 | return v; | ||
| 141 | } | ||
| 142 | |||
| 143 | uint32_t arc4random_uniform(const uint32_t upper_bound) | ||
| 144 | { | ||
| 145 | uint32_t min; | ||
| 146 | uint32_t r; | ||
| 147 | |||
| 148 | if (upper_bound < 2U) { | ||
| 149 | return 0; | ||
| 150 | } | ||
| 151 | min = (1U + ~upper_bound) % upper_bound; // = 2**32 mod upper_bound | ||
| 152 | do { | ||
| 153 | r = arc4random(); | ||
| 154 | } while (r < min); | ||
| 155 | |||
| 156 | // r is now clamped to a set whose size mod upper_bound == 0. | ||
| 157 | // The worst case (2**31+1) requires 2 attempts on average. | ||
| 158 | |||
| 159 | return r % upper_bound; | ||
| 160 | } | ||
lib/libc/wasi/thread-stub/pthread_barrier_destroy.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrier_destroy(pthread_barrier_t *b) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/thread-stub/pthread_barrier_init.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrier_init(pthread_barrier_t *restrict b, const pthread_barrierattr_t *restrict a, unsigned count) | ||
| 4 | { | ||
| 5 | 	if (count-1 > INT_MAX-1) return EINVAL; | ||
| 6 | 	*b = (pthread_barrier_t){ ._b_limit = count-1 }; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/thread-stub/pthread_barrier_wait.c deleted-7| ... | @@ -1,7 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrier_wait(pthread_barrier_t *b) | ||
| 4 | { | ||
| 5 | 	if (!b->_b_limit) return PTHREAD_BARRIER_SERIAL_THREAD; | ||
| 6 | 	__builtin_trap(); | ||
| 7 | } | ||
lib/libc/wasi/thread-stub/pthread_cond_broadcast.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_broadcast(pthread_cond_t *c) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/thread-stub/pthread_cond_destroy.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_destroy(pthread_cond_t *c) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/thread-stub/pthread_cond_init.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/thread-stub/pthread_cond_signal.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_signal(pthread_cond_t *c) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/thread-stub/pthread_cond_timedwait.c deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts) | ||
| 4 | { | ||
| 5 | 	/* Error check mutexes must detect if they're not locked (UB for others) */ | ||
| 6 | 	if (!m->_m_count) return EPERM; | ||
| 7 | 	int ret = clock_nanosleep(CLOCK_REALTIME, TIMER_ABSTIME, ts, 0); | ||
| 8 | 	if (ret == 0) return ETIMEDOUT; | ||
| 9 | 	if (ret != EINTR) return ret; | ||
| 10 | 	return 0; | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait); | ||
lib/libc/wasi/thread-stub/pthread_cond_wait.c deleted-9| ... | @@ -1,9 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m) | ||
| 4 | { | ||
| 5 | 	/* Because there is no other thread that can signal us, this is a deadlock immediately. | ||
| 6 | 	The other possible choice is to return immediately (spurious wakeup), but that is likely to | ||
| 7 | 	just result in the program spinning forever on a condition that cannot become true. */ | ||
| 8 | 	__builtin_trap(); | ||
| 9 | } | ||
lib/libc/wasi/thread-stub/pthread_create.c deleted-19| ... | @@ -1,19 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static void dummy_0() | ||
| 4 | { | ||
| 5 | } | ||
| 6 | weak_alias(dummy_0, __acquire_ptc); | ||
| 7 | weak_alias(dummy_0, __release_ptc); | ||
| 8 | |||
| 9 | int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg) | ||
| 10 | { | ||
| 11 | 	/* | ||
| 12 | 		"The system lacked the necessary resources to create another thread, | ||
| 13 | 		or the system-imposed limit on the total number of threads in a process | ||
| 14 | 		{PTHREAD_THREADS_MAX} would be exceeded." | ||
| 15 | 	*/ | ||
| 16 | 	return EAGAIN; | ||
| 17 | } | ||
| 18 | |||
| 19 | weak_alias(__pthread_create, pthread_create); | ||
lib/libc/wasi/thread-stub/pthread_detach.c deleted-13| ... | @@ -1,13 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static int __pthread_detach(pthread_t t) | ||
| 4 | { | ||
| 5 | 	/* | ||
| 6 | 		If we are the only thread, when we exit the whole process exits. | ||
| 7 | 		So the storage will be reclaimed no matter what. | ||
| 8 | 	*/ | ||
| 9 | 	return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(__pthread_detach, pthread_detach); | ||
| 13 | weak_alias(__pthread_detach, thrd_detach); | ||
lib/libc/wasi/thread-stub/pthread_getattr_np.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_getattr_np(pthread_t t, pthread_attr_t *a) | ||
| 4 | { | ||
| 5 | 	*a = (pthread_attr_t){0}; | ||
| 6 | 	/* Can't join main thread. */ | ||
| 7 | 	a->_a_detach = PTHREAD_CREATE_DETACHED; | ||
| 8 | 	/* WASI doesn't have memory protection required for stack guards. */ | ||
| 9 | 	a->_a_guardsize = 0; | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/thread-stub/pthread_join.c deleted-32| ... | @@ -1,32 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static int __pthread_tryjoin_np(pthread_t t, void **res) | ||
| 4 | { | ||
| 5 | 	/* | ||
| 6 | 		"The behavior is undefined if the value specified by the thread argument | ||
| 7 | 		to pthread_join() refers to the calling thread." | ||
| 8 | 	*/ | ||
| 9 | 	return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) | ||
| 13 | { | ||
| 14 | 	/* | ||
| 15 | 		"The behavior is undefined if the value specified by the thread argument | ||
| 16 | 		to pthread_join() refers to the calling thread." | ||
| 17 | 	*/ | ||
| 18 | 	return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | int __pthread_join(pthread_t t, void **res) | ||
| 22 | { | ||
| 23 | 	/* | ||
| 24 | 		"The behavior is undefined if the value specified by the thread argument | ||
| 25 | 		to pthread_join() refers to the calling thread." | ||
| 26 | 	*/ | ||
| 27 | 	return 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); | ||
| 31 | weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np); | ||
| 32 | weak_alias(__pthread_join, pthread_join); | ||
lib/libc/wasi/thread-stub/pthread_mutex_consistent.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutex_consistent(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	/* cannot be a robust mutex, as they're entirely unsupported in WASI */ | ||
| 6 | 	return EINVAL; | ||
| 7 | |||
| 8 | } | ||
lib/libc/wasi/thread-stub/pthread_mutex_getprioceiling.c deleted-6| ... | @@ -1,6 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutex_getprioceiling(const pthread_mutex_t *restrict m, int *restrict ceiling) | ||
| 4 | { | ||
| 5 | 	return EINVAL; | ||
| 6 | } | ||
lib/libc/wasi/thread-stub/pthread_mutex_lock.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_lock(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	/* | ||
| 6 | 		_m_type[1:0] 	- type | ||
| 7 | 		0 - normal | ||
| 8 | 		1 - recursive | ||
| 9 | 		2 - errorcheck | ||
| 10 | 	*/ | ||
| 11 | 	if (m->_m_type&3 != PTHREAD_MUTEX_RECURSIVE) { | ||
| 12 | 		if (m->_m_count) return EDEADLK; | ||
| 13 | 		m->_m_count = 1; | ||
| 14 | 	} else { | ||
| 15 | 		if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN; | ||
| 16 | 		m->_m_count++; | ||
| 17 | 	} | ||
| 18 | 	return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | weak_alias(__pthread_mutex_lock, pthread_mutex_lock); | ||
lib/libc/wasi/thread-stub/pthread_mutex_timedlock.c deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at) | ||
| 4 | { | ||
| 5 | 	/* "The pthread_mutex_timedlock() function may fail if: A deadlock condition was detected." */ | ||
| 6 | 	/* This means that we don't have to wait and then return timeout, we can just detect deadlock. */ | ||
| 7 | 	return pthread_mutex_lock(m); | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); | ||
lib/libc/wasi/thread-stub/pthread_mutex_trylock.c deleted-21| ... | @@ -1,21 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_trylock(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	/* | ||
| 6 | 		_m_type[1:0] 	- type | ||
| 7 | 		0 - normal | ||
| 8 | 		1 - recursive | ||
| 9 | 		2 - errorcheck | ||
| 10 | 	*/ | ||
| 11 | 	if (m->_m_type&3 != PTHREAD_MUTEX_RECURSIVE) { | ||
| 12 | 		if (m->_m_count) return EBUSY; | ||
| 13 | 		m->_m_count = 1; | ||
| 14 | 	} else { | ||
| 15 | 		if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN; | ||
| 16 | 		m->_m_count++; | ||
| 17 | 	} | ||
| 18 | 	return 0; | ||
| 19 | } | ||
| 20 | |||
| 21 | weak_alias(__pthread_mutex_trylock, pthread_mutex_trylock); | ||
lib/libc/wasi/thread-stub/pthread_mutex_unlock.c deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_unlock(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	if (!m->_m_count) return EPERM; | ||
| 6 | 	m->_m_count--; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock); | ||
lib/libc/wasi/thread-stub/pthread_once.c deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_once(pthread_once_t *control, void (*init)(void)) | ||
| 4 | { | ||
| 5 | if (!*control) { | ||
| 6 | init(); | ||
| 7 | *control = 1; | ||
| 8 | } | ||
| 9 | return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(__pthread_once, pthread_once); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_rdlock.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_rdlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	if (rw->_rw_lock == 0x7fffffff) return EDEADLK; | ||
| 6 | 	if (rw->_rw_lock == 0x7ffffffe) return EAGAIN; | ||
| 7 | 	rw->_rw_lock++; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
| 10 | |||
| 11 | weak_alias(__pthread_rwlock_rdlock, pthread_rwlock_rdlock); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_timedrdlock.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) | ||
| 4 | { | ||
| 5 | 	return pthread_rwlock_rdlock(rw); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_timedwrlock.c deleted-8| ... | @@ -1,8 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) | ||
| 4 | { | ||
| 5 | 	return pthread_rwlock_wrlock(rw); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_tryrdlock.c deleted-11| ... | @@ -1,11 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_tryrdlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	if (rw->_rw_lock == 0x7fffffff) return EBUSY; | ||
| 6 | 	if (rw->_rw_lock == 0x7ffffffe) return EAGAIN; | ||
| 7 | 	rw->_rw_lock++; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
| 10 | |||
| 11 | weak_alias(__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_trywrlock.c deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_trywrlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	if (rw->_rw_lock) return EBUSY; | ||
| 6 | 	rw->_rw_lock = 0x7fffffff; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_unlock.c deleted-12| ... | @@ -1,12 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_unlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	if (rw->_rw_lock == 0x7fffffff) | ||
| 6 | 		rw->_rw_lock = 0; | ||
| 7 | 	else | ||
| 8 | 		rw->_rw_lock--; | ||
| 9 | 	return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(__pthread_rwlock_unlock, pthread_rwlock_unlock); | ||
lib/libc/wasi/thread-stub/pthread_rwlock_wrlock.c deleted-10| ... | @@ -1,10 +0,0 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_wrlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	if (rw->_rw_lock) return EDEADLK; | ||
| 6 | 	rw->_rw_lock = 0x7fffffff; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(__pthread_rwlock_wrlock, pthread_rwlock_wrlock); | ||
lib/std/Io/Threaded/test.zig-5| ... | @@ -201,11 +201,6 @@ test "cancel blocked read from pipe" { | ... | @@ -201,11 +201,6 @@ test "cancel blocked read from pipe" { |
| 201 | } | 201 | } |
| 202 | 202 | ||
| 203 | test "memory mapping fallback" { | 203 | test "memory mapping fallback" { |
| 204 | if (builtin.os.tag == .wasi and builtin.link_libc) { | ||
| 205 | // https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission) | ||
| 206 | return error.SkipZigTest; | ||
| 207 | } | ||
| 208 | |||
| 209 | var threaded: std.Io.Threaded = .init(std.testing.allocator, .{ | 204 | var threaded: std.Io.Threaded = .init(std.testing.allocator, .{ |
| 210 | .argv0 = .empty, | 205 | .argv0 = .empty, |
| 211 | .environ = .empty, | 206 | .environ = .empty, |
lib/std/Io/test.zig-7| ... | @@ -135,9 +135,6 @@ test "File.setLength" { | ... | @@ -135,9 +135,6 @@ test "File.setLength" { |
| 135 | } | 135 | } |
| 136 | 136 | ||
| 137 | test "legacy setLength" { | 137 | test "legacy setLength" { |
| 138 | // https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission) | ||
| 139 | if (builtin.os.tag == .wasi and builtin.link_libc) return error.SkipZigTest; | ||
| 140 | |||
| 141 | const io = testing.io; | 138 | const io = testing.io; |
| 142 | 139 | ||
| 143 | var tmp = tmpDir(.{}); | 140 | var tmp = tmpDir(.{}); |
| ... | @@ -629,10 +626,6 @@ test "randomSecure" { | ... | @@ -629,10 +626,6 @@ test "randomSecure" { |
| 629 | test "memory mapping" { | 626 | test "memory mapping" { |
| 630 | if (builtin.cpu.arch == .hexagon) return error.SkipZigTest; // mmap returned EINVAL | 627 | if (builtin.cpu.arch == .hexagon) return error.SkipZigTest; // mmap returned EINVAL |
| 631 | if (builtin.cpu.arch.isSPARC()) return error.SkipZigTest; // mmap returned EINVAL | 628 | if (builtin.cpu.arch.isSPARC()) return error.SkipZigTest; // mmap returned EINVAL |
| 632 | if (builtin.os.tag == .wasi and builtin.link_libc) { | ||
| 633 | // https://github.com/ziglang/zig/issues/20747 (open fd does not have write permission) | ||
| 634 | return error.SkipZigTest; | ||
| 635 | } | ||
| 636 | 629 | ||
| 637 | const io = testing.io; | 630 | const io = testing.io; |
| 638 | 631 |
lib/std/Target.zig+2-5| ... | @@ -950,7 +950,7 @@ pub const Abi = enum { | ... | @@ -950,7 +950,7 @@ pub const Abi = enum { |
| 950 | .psx => .eabi, | 950 | .psx => .eabi, |
| 951 | .psp => .eabihf, | 951 | .psp => .eabihf, |
| 952 | .vita => .eabihf, | 952 | .vita => .eabihf, |
| 953 | .wasi, .emscripten => .musl, | 953 | .emscripten => .musl, |
| 954 | 954 | ||
| 955 | .ashetos => .eabi, | 955 | .ashetos => .eabi, |
| 956 | 956 | ||
| ... | @@ -981,6 +981,7 @@ pub const Abi = enum { | ... | @@ -981,6 +981,7 @@ pub const Abi = enum { |
| 981 | .opengl, | 981 | .opengl, |
| 982 | .vulkan, | 982 | .vulkan, |
| 983 | .tios, | 983 | .tios, |
| 984 | .wasi, | ||
| 984 | => .none, | 985 | => .none, |
| 985 | }; | 986 | }; |
| 986 | } | 987 | } |
| ... | @@ -2290,10 +2291,6 @@ pub inline fn isOpenBSDLibC(target: *const Target) bool { | ... | @@ -2290,10 +2291,6 @@ pub inline fn isOpenBSDLibC(target: *const Target) bool { |
| 2290 | }; | 2291 | }; |
| 2291 | } | 2292 | } |
| 2292 | 2293 | ||
| 2293 | pub inline fn isWasiLibC(target: *const Target) bool { | ||
| 2294 | return target.os.tag == .wasi and target.abi.isMusl(); | ||
| 2295 | } | ||
| 2296 | |||
| 2297 | /// Does this target require linking libc? This may be the case if the target has an unstable | 2294 | /// Does this target require linking libc? This may be the case if the target has an unstable |
| 2298 | /// syscall interface, for example. | 2295 | /// syscall interface, for example. |
| 2299 | pub fn requiresLibC(target: *const Target) bool { | 2296 | pub fn requiresLibC(target: *const Target) bool { |
lib/std/c.zig+24-217| ... | @@ -11,7 +11,6 @@ const assert = std.debug.assert; | ... | @@ -11,7 +11,6 @@ const assert = std.debug.assert; |
| 11 | const page_size = std.heap.page_size_min; | 11 | const page_size = std.heap.page_size_min; |
| 12 | const linux = std.os.linux; | 12 | const linux = std.os.linux; |
| 13 | const emscripten = std.os.emscripten; | 13 | const emscripten = std.os.emscripten; |
| 14 | const wasi = std.os.wasi; | ||
| 15 | const windows = std.os.windows; | 14 | const windows = std.os.windows; |
| 16 | const ws2_32 = std.os.windows.ws2_32; | 15 | const ws2_32 = std.os.windows.ws2_32; |
| 17 | const darwin = @import("c/darwin.zig"); | 16 | const darwin = @import("c/darwin.zig"); |
| ... | @@ -80,7 +79,6 @@ pub fn errno(rc: anytype) E { | ... | @@ -80,7 +79,6 @@ pub fn errno(rc: anytype) E { |
| 80 | pub const ino_t = switch (native_os) { | 79 | pub const ino_t = switch (native_os) { |
| 81 | .linux => linux.ino_t, | 80 | .linux => linux.ino_t, |
| 82 | .emscripten => emscripten.ino_t, | 81 | .emscripten => emscripten.ino_t, |
| 83 | .wasi => wasi.inode_t, | ||
| 84 | .windows => windows.LARGE_INTEGER, | 82 | .windows => windows.LARGE_INTEGER, |
| 85 | .haiku => i64, | 83 | .haiku => i64, |
| 86 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L38 | 84 | // 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) { | ... | @@ -96,7 +94,7 @@ pub const off_t = switch (native_os) { |
| 96 | 94 | ||
| 97 | /// For use with `utimensat` and `futimens`. | 95 | /// For use with `utimensat` and `futimens`. |
| 98 | pub const UTIME = switch (native_os) { | 96 | pub const UTIME = switch (native_os) { |
| 99 | .dragonfly, .freebsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => struct { | 97 | .dragonfly, .freebsd, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 100 | pub const NOW: timespec = .{ .sec = 0, .nsec = -1 }; | 98 | pub const NOW: timespec = .{ .sec = 0, .nsec = -1 }; |
| 101 | pub const OMIT: timespec = .{ .sec = 0, .nsec = -2 }; | 99 | pub const OMIT: timespec = .{ .sec = 0, .nsec = -2 }; |
| 102 | }, | 100 | }, |
| ... | @@ -120,25 +118,6 @@ pub const UTIME = switch (native_os) { | ... | @@ -120,25 +118,6 @@ pub const UTIME = switch (native_os) { |
| 120 | pub const timespec = switch (native_os) { | 118 | pub const timespec = switch (native_os) { |
| 121 | .linux => linux.timespec, | 119 | .linux => linux.timespec, |
| 122 | .emscripten => emscripten.timespec, | 120 | .emscripten => emscripten.timespec, |
| 123 | // lib/libc/include/wasm-wasi-musl/__struct_timespec.h | ||
| 124 | .wasi => extern struct { | ||
| 125 | sec: time_t, | ||
| 126 | nsec: c_long, | ||
| 127 | |||
| 128 | pub fn fromTimestamp(tm: wasi.timestamp_t) timespec { | ||
| 129 | const sec: wasi.timestamp_t = tm / 1_000_000_000; | ||
| 130 | const nsec = tm - sec * 1_000_000_000; | ||
| 131 | return .{ | ||
| 132 | .sec = @as(time_t, @intCast(sec)), | ||
| 133 | .nsec = @as(isize, @intCast(nsec)), | ||
| 134 | }; | ||
| 135 | } | ||
| 136 | |||
| 137 | pub fn toTimestamp(ts: timespec) wasi.timestamp_t { | ||
| 138 | return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) + | ||
| 139 | @as(wasi.timestamp_t, @intCast(ts.nsec)); | ||
| 140 | } | ||
| 141 | }, | ||
| 142 | // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20 | 121 | // https://github.com/SerenityOS/serenity/blob/0a78056453578c18e0a04a0b45ebfb1c96d59005/Kernel/API/POSIX/time.h#L17-L20 |
| 143 | .dragonfly, .freebsd, .netbsd, .openbsd, .illumos, .haiku, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct { | 122 | .dragonfly, .freebsd, .netbsd, .openbsd, .illumos, .haiku, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct { |
| 144 | sec: time_t, | 123 | sec: time_t, |
| ... | @@ -149,7 +128,6 @@ pub const timespec = switch (native_os) { | ... | @@ -149,7 +128,6 @@ pub const timespec = switch (native_os) { |
| 149 | 128 | ||
| 150 | pub const dev_t = switch (native_os) { | 129 | pub const dev_t = switch (native_os) { |
| 151 | .emscripten => emscripten.dev_t, | 130 | .emscripten => emscripten.dev_t, |
| 152 | .wasi => wasi.device_t, | ||
| 153 | .openbsd, .haiku, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => i32, | 131 | .openbsd, .haiku, .illumos, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => i32, |
| 154 | // glibc and musl define dev_t as u64, while in Linux kernel it is u32. | 132 | // glibc and musl define dev_t as u64, while in Linux kernel it is u32. |
| 155 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L43 | 133 | // 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) { | ... | @@ -163,14 +141,12 @@ pub const mode_t = switch (native_os) { |
| 163 | .openbsd, .haiku, .netbsd, .illumos, .windows => u32, | 141 | .openbsd, .haiku, .netbsd, .illumos, .windows => u32, |
| 164 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44 | 142 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L44 |
| 165 | .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16, | 143 | .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .dragonfly, .serenity => u16, |
| 166 | .wasi => if (builtin.link_libc) u32 else u0, // WASI libc emulates mode. | ||
| 167 | else => u0, | 144 | else => u0, |
| 168 | }; | 145 | }; |
| 169 | 146 | ||
| 170 | pub const nlink_t = switch (native_os) { | 147 | pub const nlink_t = switch (native_os) { |
| 171 | .linux => linux.nlink_t, | 148 | .linux => linux.nlink_t, |
| 172 | .emscripten => emscripten.nlink_t, | 149 | .emscripten => emscripten.nlink_t, |
| 173 | .wasi => c_ulonglong, | ||
| 174 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L45 | 150 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L45 |
| 175 | .freebsd, .serenity => u64, | 151 | .freebsd, .serenity => u64, |
| 176 | .openbsd, .netbsd, .dragonfly, .illumos, .windows => u32, | 152 | .openbsd, .netbsd, .dragonfly, .illumos, .windows => u32, |
| ... | @@ -196,7 +172,6 @@ pub const gid_t = switch (native_os) { | ... | @@ -196,7 +172,6 @@ pub const gid_t = switch (native_os) { |
| 196 | pub const blksize_t = switch (native_os) { | 172 | pub const blksize_t = switch (native_os) { |
| 197 | .linux => linux.blksize_t, | 173 | .linux => linux.blksize_t, |
| 198 | .emscripten => emscripten.blksize_t, | 174 | .emscripten => emscripten.blksize_t, |
| 199 | .wasi => c_long, | ||
| 200 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L42 | 175 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L42 |
| 201 | .serenity => u64, | 176 | .serenity => u64, |
| 202 | else => i32, | 177 | else => i32, |
| ... | @@ -254,7 +229,6 @@ pub const group = switch (native_os) { | ... | @@ -254,7 +229,6 @@ pub const group = switch (native_os) { |
| 254 | pub const blkcnt_t = switch (native_os) { | 229 | pub const blkcnt_t = switch (native_os) { |
| 255 | .linux => linux.blkcnt_t, | 230 | .linux => linux.blkcnt_t, |
| 256 | .emscripten => emscripten.blkcnt_t, | 231 | .emscripten => emscripten.blkcnt_t, |
| 257 | .wasi => c_longlong, | ||
| 258 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L41 | 232 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L41 |
| 259 | .serenity => u64, | 233 | .serenity => u64, |
| 260 | else => i64, | 234 | else => i64, |
| ... | @@ -262,7 +236,6 @@ pub const blkcnt_t = switch (native_os) { | ... | @@ -262,7 +236,6 @@ pub const blkcnt_t = switch (native_os) { |
| 262 | 236 | ||
| 263 | pub const fd_t = switch (native_os) { | 237 | pub const fd_t = switch (native_os) { |
| 264 | .linux => linux.fd_t, | 238 | .linux => linux.fd_t, |
| 265 | .wasi => wasi.fd_t, | ||
| 266 | .windows => windows.HANDLE, | 239 | .windows => windows.HANDLE, |
| 267 | .serenity => c_int, | 240 | .serenity => c_int, |
| 268 | else => i32, | 241 | else => i32, |
| ... | @@ -293,7 +266,6 @@ pub const timerfd_clockid_t = switch (native_os) { | ... | @@ -293,7 +266,6 @@ pub const timerfd_clockid_t = switch (native_os) { |
| 293 | pub const CLOCK = clockid_t; | 266 | pub const CLOCK = clockid_t; |
| 294 | pub const clockid_t = switch (native_os) { | 267 | pub const clockid_t = switch (native_os) { |
| 295 | .linux, .emscripten => linux.clockid_t, | 268 | .linux, .emscripten => linux.clockid_t, |
| 296 | .wasi => wasi.clockid_t, | ||
| 297 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(u32) { | 269 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => enum(u32) { |
| 298 | REALTIME = 0, | 270 | REALTIME = 0, |
| 299 | MONOTONIC = 6, | 271 | MONOTONIC = 6, |
| ... | @@ -386,7 +358,6 @@ pub const CPU_COUNT = switch (native_os) { | ... | @@ -386,7 +358,6 @@ pub const CPU_COUNT = switch (native_os) { |
| 386 | pub const E = switch (native_os) { | 358 | pub const E = switch (native_os) { |
| 387 | .linux => linux.E, | 359 | .linux => linux.E, |
| 388 | .emscripten => emscripten.E, | 360 | .emscripten => emscripten.E, |
| 389 | .wasi => wasi.errno_t, | ||
| 390 | .windows => enum(u16) { | 361 | .windows => enum(u16) { |
| 391 | /// No error occurred. | 362 | /// No error occurred. |
| 392 | SUCCESS = 0, | 363 | SUCCESS = 0, |
| ... | @@ -845,13 +816,6 @@ pub const Elf_Symndx = switch (native_os) { | ... | @@ -845,13 +816,6 @@ pub const Elf_Symndx = switch (native_os) { |
| 845 | pub const F = switch (native_os) { | 816 | pub const F = switch (native_os) { |
| 846 | .linux => linux.F, | 817 | .linux => linux.F, |
| 847 | .emscripten => emscripten.F, | 818 | .emscripten => emscripten.F, |
| 848 | .wasi => struct { | ||
| 849 | // Match `F_*` constants from lib/libc/include/wasm-wasi-musl/__header_fcntl.h | ||
| 850 | pub const GETFD = 1; | ||
| 851 | pub const SETFD = 2; | ||
| 852 | pub const GETFL = 3; | ||
| 853 | pub const SETFL = 4; | ||
| 854 | }, | ||
| 855 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { | 819 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 856 | /// duplicate file descriptor | 820 | /// duplicate file descriptor |
| 857 | pub const DUPFD = 0; | 821 | pub const DUPFD = 0; |
| ... | @@ -1323,7 +1287,7 @@ pub const IOV_MAX = switch (native_os) { | ... | @@ -1323,7 +1287,7 @@ pub const IOV_MAX = switch (native_os) { |
| 1323 | .linux => linux.IOV_MAX, | 1287 | .linux => linux.IOV_MAX, |
| 1324 | .emscripten => emscripten.IOV_MAX, | 1288 | .emscripten => emscripten.IOV_MAX, |
| 1325 | // https://github.com/SerenityOS/serenity/blob/098af0f846a87b651731780ff48420205fd33754/Kernel/API/POSIX/sys/uio.h#L16 | 1289 | // https://github.com/SerenityOS/serenity/blob/098af0f846a87b651731780ff48420205fd33754/Kernel/API/POSIX/sys/uio.h#L16 |
| 1326 | .openbsd, .haiku, .illumos, .wasi, .serenity => 1024, | 1290 | .openbsd, .haiku, .illumos, .serenity => 1024, |
| 1327 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 16, | 1291 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => 16, |
| 1328 | .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX, | 1292 | .dragonfly, .netbsd, .freebsd => KERN.IOV_MAX, |
| 1329 | else => {}, | 1293 | else => {}, |
| ... | @@ -1854,7 +1818,6 @@ pub const NAME_MAX = switch (native_os) { | ... | @@ -1854,7 +1818,6 @@ pub const NAME_MAX = switch (native_os) { |
| 1854 | pub const PATH_MAX = switch (native_os) { | 1818 | pub const PATH_MAX = switch (native_os) { |
| 1855 | .linux => linux.PATH_MAX, | 1819 | .linux => linux.PATH_MAX, |
| 1856 | .emscripten => emscripten.PATH_MAX, | 1820 | .emscripten => emscripten.PATH_MAX, |
| 1857 | .wasi => 4096, | ||
| 1858 | .windows => 260, | 1821 | .windows => 260, |
| 1859 | .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 1024, | 1822 | .openbsd, .haiku, .dragonfly, .netbsd, .illumos, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .serenity => 1024, |
| 1860 | else => {}, | 1823 | else => {}, |
| ... | @@ -1863,15 +1826,6 @@ pub const PATH_MAX = switch (native_os) { | ... | @@ -1863,15 +1826,6 @@ pub const PATH_MAX = switch (native_os) { |
| 1863 | pub const POLL = switch (native_os) { | 1826 | pub const POLL = switch (native_os) { |
| 1864 | .linux => linux.POLL, | 1827 | .linux => linux.POLL, |
| 1865 | .emscripten => emscripten.POLL, | 1828 | .emscripten => emscripten.POLL, |
| 1866 | .wasi => struct { | ||
| 1867 | pub const RDNORM = 0x1; | ||
| 1868 | pub const WRNORM = 0x2; | ||
| 1869 | pub const IN = RDNORM; | ||
| 1870 | pub const OUT = WRNORM; | ||
| 1871 | pub const ERR = 0x1000; | ||
| 1872 | pub const HUP = 0x2000; | ||
| 1873 | pub const NVAL = 0x4000; | ||
| 1874 | }, | ||
| 1875 | .windows => ws2_32.POLL, | 1829 | .windows => ws2_32.POLL, |
| 1876 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { | 1830 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 1877 | pub const IN = 0x001; | 1831 | pub const IN = 0x001; |
| ... | @@ -2042,45 +1996,6 @@ pub const RLIM = switch (native_os) { | ... | @@ -2042,45 +1996,6 @@ pub const RLIM = switch (native_os) { |
| 2042 | pub const S = switch (native_os) { | 1996 | pub const S = switch (native_os) { |
| 2043 | .linux => linux.S, | 1997 | .linux => linux.S, |
| 2044 | .emscripten => emscripten.S, | 1998 | .emscripten => emscripten.S, |
| 2045 | .wasi => struct { | ||
| 2046 | // Match `S_*` constants from lib/libc/include/wasm-wasi-musl/__mode_t.h | ||
| 2047 | pub const IFBLK = 0x6000; | ||
| 2048 | pub const IFCHR = 0x2000; | ||
| 2049 | pub const IFDIR = 0x4000; | ||
| 2050 | pub const IFIFO = 0x1000; | ||
| 2051 | pub const IFLNK = 0xa000; | ||
| 2052 | pub const IFMT = IFBLK | IFCHR | IFDIR | IFIFO | IFLNK | IFREG | IFSOCK; | ||
| 2053 | pub const IFREG = 0x8000; | ||
| 2054 | pub const IFSOCK = 0xc000; | ||
| 2055 | |||
| 2056 | pub fn ISBLK(m: u32) bool { | ||
| 2057 | return m & IFMT == IFBLK; | ||
| 2058 | } | ||
| 2059 | |||
| 2060 | pub fn ISCHR(m: u32) bool { | ||
| 2061 | return m & IFMT == IFCHR; | ||
| 2062 | } | ||
| 2063 | |||
| 2064 | pub fn ISDIR(m: u32) bool { | ||
| 2065 | return m & IFMT == IFDIR; | ||
| 2066 | } | ||
| 2067 | |||
| 2068 | pub fn ISFIFO(m: u32) bool { | ||
| 2069 | return m & IFMT == IFIFO; | ||
| 2070 | } | ||
| 2071 | |||
| 2072 | pub fn ISLNK(m: u32) bool { | ||
| 2073 | return m & IFMT == IFLNK; | ||
| 2074 | } | ||
| 2075 | |||
| 2076 | pub fn ISREG(m: u32) bool { | ||
| 2077 | return m & IFMT == IFREG; | ||
| 2078 | } | ||
| 2079 | |||
| 2080 | pub fn ISSOCK(m: u32) bool { | ||
| 2081 | return m & IFMT == IFSOCK; | ||
| 2082 | } | ||
| 2083 | }, | ||
| 2084 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { | 1999 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => struct { |
| 2085 | pub const IFMT = 0o170000; | 2000 | pub const IFMT = 0o170000; |
| 2086 | 2001 | ||
| ... | @@ -2736,11 +2651,6 @@ pub const _SC = if (builtin.abi.isAndroid()) enum(c_int) { | ... | @@ -2736,11 +2651,6 @@ pub const _SC = if (builtin.abi.isAndroid()) enum(c_int) { |
| 2736 | pub const SEEK = switch (native_os) { | 2651 | pub const SEEK = switch (native_os) { |
| 2737 | .linux => linux.SEEK, | 2652 | .linux => linux.SEEK, |
| 2738 | .emscripten => emscripten.SEEK, | 2653 | .emscripten => emscripten.SEEK, |
| 2739 | .wasi => struct { | ||
| 2740 | pub const SET: wasi.whence_t = .SET; | ||
| 2741 | pub const CUR: wasi.whence_t = .CUR; | ||
| 2742 | pub const END: wasi.whence_t = .END; | ||
| 2743 | }, | ||
| 2744 | // https://github.com/SerenityOS/serenity/blob/808ce594db1f2190e5212a250e900bde2ffe710b/Kernel/API/POSIX/stdio.h#L15-L17 | 2654 | // https://github.com/SerenityOS/serenity/blob/808ce594db1f2190e5212a250e900bde2ffe710b/Kernel/API/POSIX/stdio.h#L15-L17 |
| 2745 | .openbsd, .haiku, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .serenity => struct { | 2655 | .openbsd, .haiku, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .serenity => struct { |
| 2746 | pub const SET = 0; | 2656 | pub const SET = 0; |
| ... | @@ -4263,7 +4173,7 @@ pub const in6_pktinfo = switch (native_os) { | ... | @@ -4263,7 +4173,7 @@ pub const in6_pktinfo = switch (native_os) { |
| 4263 | }; | 4173 | }; |
| 4264 | pub const itimerspec = switch (native_os) { | 4174 | pub const itimerspec = switch (native_os) { |
| 4265 | .linux => linux.itimerspec, | 4175 | .linux => linux.itimerspec, |
| 4266 | .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .windows, .wasi => extern struct { | 4176 | .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .windows => extern struct { |
| 4267 | interval: timespec, | 4177 | interval: timespec, |
| 4268 | value: timespec, | 4178 | value: timespec, |
| 4269 | }, | 4179 | }, |
| ... | @@ -4510,7 +4420,7 @@ comptime { | ... | @@ -4510,7 +4420,7 @@ comptime { |
| 4510 | pub const nfds_t = switch (native_os) { | 4420 | pub const nfds_t = switch (native_os) { |
| 4511 | .linux => linux.nfds_t, | 4421 | .linux => linux.nfds_t, |
| 4512 | .emscripten => emscripten.nfds_t, | 4422 | .emscripten => emscripten.nfds_t, |
| 4513 | .haiku, .illumos, .wasi => usize, | 4423 | .haiku, .illumos => usize, |
| 4514 | .windows => c_ulong, | 4424 | .windows => c_ulong, |
| 4515 | .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u32, | 4425 | .openbsd, .dragonfly, .netbsd, .freebsd, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => u32, |
| 4516 | // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L32 | 4426 | // https://github.com/SerenityOS/serenity/blob/265764ff2fec038855193296588a887fc322d76a/Kernel/API/POSIX/poll.h#L32 |
| ... | @@ -7247,15 +7157,14 @@ pub const time_t = switch (native_os) { | ... | @@ -7247,15 +7157,14 @@ pub const time_t = switch (native_os) { |
| 7247 | .emscripten => emscripten.time_t, | 7157 | .emscripten => emscripten.time_t, |
| 7248 | .freebsd, .haiku => if (native_arch == .x86) c_int else c_longlong, | 7158 | .freebsd, .haiku => if (native_arch == .x86) c_int else c_longlong, |
| 7249 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47 | 7159 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L47 |
| 7250 | // lib/libc/include/wasm-wasi-musl/__typedef_time_t.h | 7160 | .netbsd, .openbsd, .serenity => c_longlong, |
| 7251 | .netbsd, .openbsd, .serenity, .wasi => c_longlong, | ||
| 7252 | else => void, | 7161 | else => void, |
| 7253 | }; | 7162 | }; |
| 7254 | pub const suseconds_t = switch (native_os) { | 7163 | pub const suseconds_t = switch (native_os) { |
| 7255 | .dragonfly, .freebsd, .openbsd, .illumos => c_long, | 7164 | .dragonfly, .freebsd, .openbsd, .illumos => c_long, |
| 7256 | .netbsd, .haiku, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_int, | 7165 | .netbsd, .haiku, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => c_int, |
| 7257 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L49 | 7166 | // https://github.com/SerenityOS/serenity/blob/b98f537f117b341788023ab82e0c11ca9ae29a57/Kernel/API/POSIX/sys/types.h#L49 |
| 7258 | .serenity, .wasi => c_longlong, | 7167 | .serenity => c_longlong, |
| 7259 | else => void, | 7168 | else => void, |
| 7260 | }; | 7169 | }; |
| 7261 | 7170 | ||
| ... | @@ -7267,7 +7176,7 @@ pub const timeval = switch (native_os) { | ... | @@ -7267,7 +7176,7 @@ pub const timeval = switch (native_os) { |
| 7267 | usec: c_long, | 7176 | usec: c_long, |
| 7268 | }, | 7177 | }, |
| 7269 | // https://github.com/SerenityOS/serenity/blob/6b6eca0631c893c5f8cfb8274cdfe18e2d0637c0/Kernel/API/POSIX/sys/time.h#L15-L18 | 7178 | // https://github.com/SerenityOS/serenity/blob/6b6eca0631c893c5f8cfb8274cdfe18e2d0637c0/Kernel/API/POSIX/sys/time.h#L15-L18 |
| 7270 | .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .wasi => extern struct { | 7179 | .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 7271 | /// seconds | 7180 | /// seconds |
| 7272 | sec: time_t, | 7181 | sec: time_t, |
| 7273 | /// microseconds | 7182 | /// microseconds |
| ... | @@ -7279,7 +7188,7 @@ pub const timezone = switch (native_os) { | ... | @@ -7279,7 +7188,7 @@ pub const timezone = switch (native_os) { |
| 7279 | .linux => linux.timezone, | 7188 | .linux => linux.timezone, |
| 7280 | .emscripten => emscripten.timezone, | 7189 | .emscripten => emscripten.timezone, |
| 7281 | // https://github.com/SerenityOS/serenity/blob/ba776390b5878ec0be1a9e595a3471a6cfe0a0cf/Userland/Libraries/LibC/sys/time.h#L19-L22 | 7190 | // https://github.com/SerenityOS/serenity/blob/ba776390b5878ec0be1a9e595a3471a6cfe0a0cf/Userland/Libraries/LibC/sys/time.h#L19-L22 |
| 7282 | .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows, .wasi => extern struct { | 7191 | .dragonfly, .freebsd, .netbsd, .openbsd, .haiku, .illumos, .serenity, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .windows => extern struct { |
| 7283 | minuteswest: c_int, | 7192 | minuteswest: c_int, |
| 7284 | dsttime: c_int, | 7193 | dsttime: c_int, |
| 7285 | }, | 7194 | }, |
| ... | @@ -7293,14 +7202,6 @@ pub const user_desc = switch (native_os) { | ... | @@ -7293,14 +7202,6 @@ pub const user_desc = switch (native_os) { |
| 7293 | pub const utsname = switch (native_os) { | 7202 | pub const utsname = switch (native_os) { |
| 7294 | .linux => linux.utsname, | 7203 | .linux => linux.utsname, |
| 7295 | .emscripten => emscripten.utsname, | 7204 | .emscripten => emscripten.utsname, |
| 7296 | .wasi => extern struct { | ||
| 7297 | sysname: [64:0]u8, | ||
| 7298 | nodename: [64:0]u8, | ||
| 7299 | release: [64:0]u8, | ||
| 7300 | version: [64:0]u8, | ||
| 7301 | machine: [64:0]u8, | ||
| 7302 | domainname: [64:0]u8, | ||
| 7303 | }, | ||
| 7304 | .illumos => extern struct { | 7205 | .illumos => extern struct { |
| 7305 | sysname: [256:0]u8, | 7206 | sysname: [256:0]u8, |
| 7306 | nodename: [256:0]u8, | 7207 | nodename: [256:0]u8, |
| ... | @@ -7338,7 +7239,7 @@ pub const _errno = switch (native_os) { | ... | @@ -7338,7 +7239,7 @@ pub const _errno = switch (native_os) { |
| 7338 | else => private.__errno_location, | 7239 | else => private.__errno_location, |
| 7339 | }, | 7240 | }, |
| 7340 | .emscripten => private.__errno_location, | 7241 | .emscripten => private.__errno_location, |
| 7341 | .wasi, .dragonfly => private.errnoFromThreadLocal, | 7242 | .dragonfly => private.errnoFromThreadLocal, |
| 7342 | .windows => private._errno, | 7243 | .windows => private._errno, |
| 7343 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd => private.__error, | 7244 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd => private.__error, |
| 7344 | .illumos => private.___errno, | 7245 | .illumos => private.___errno, |
| ... | @@ -7857,65 +7758,6 @@ pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize | ... | @@ -7857,65 +7758,6 @@ pub const dl_iterate_phdr_callback = *const fn (info: *dl_phdr_info, size: usize |
| 7857 | 7758 | ||
| 7858 | pub const Stat = switch (native_os) { | 7759 | pub const Stat = switch (native_os) { |
| 7859 | .emscripten => emscripten.Stat, | 7760 | .emscripten => emscripten.Stat, |
| 7860 | .wasi => extern struct { | ||
| 7861 | // Match wasi-libc's `struct stat` in lib/libc/include/wasm-wasi-musl/__struct_stat.h | ||
| 7862 | dev: dev_t, | ||
| 7863 | ino: ino_t, | ||
| 7864 | nlink: nlink_t, | ||
| 7865 | mode: mode_t, | ||
| 7866 | uid: uid_t, | ||
| 7867 | gid: gid_t, | ||
| 7868 | __pad0: c_uint = 0, | ||
| 7869 | rdev: dev_t, | ||
| 7870 | size: off_t, | ||
| 7871 | blksize: blksize_t, | ||
| 7872 | blocks: blkcnt_t, | ||
| 7873 | atim: timespec, | ||
| 7874 | mtim: timespec, | ||
| 7875 | ctim: timespec, | ||
| 7876 | __reserved: [3]c_longlong = [3]c_longlong{ 0, 0, 0 }, | ||
| 7877 | |||
| 7878 | pub fn atime(self: @This()) timespec { | ||
| 7879 | return self.atim; | ||
| 7880 | } | ||
| 7881 | |||
| 7882 | pub fn mtime(self: @This()) timespec { | ||
| 7883 | return self.mtim; | ||
| 7884 | } | ||
| 7885 | |||
| 7886 | pub fn ctime(self: @This()) timespec { | ||
| 7887 | return self.ctim; | ||
| 7888 | } | ||
| 7889 | |||
| 7890 | pub fn fromFilestat(st: wasi.filestat_t) Stat { | ||
| 7891 | return .{ | ||
| 7892 | .dev = st.dev, | ||
| 7893 | .ino = st.ino, | ||
| 7894 | .mode = switch (st.filetype) { | ||
| 7895 | .UNKNOWN => 0, | ||
| 7896 | .BLOCK_DEVICE => S.IFBLK, | ||
| 7897 | .CHARACTER_DEVICE => S.IFCHR, | ||
| 7898 | .DIRECTORY => S.IFDIR, | ||
| 7899 | .REGULAR_FILE => S.IFREG, | ||
| 7900 | .SOCKET_DGRAM => S.IFSOCK, | ||
| 7901 | .SOCKET_STREAM => S.IFIFO, | ||
| 7902 | .SYMBOLIC_LINK => S.IFLNK, | ||
| 7903 | _ => 0, | ||
| 7904 | }, | ||
| 7905 | .nlink = st.nlink, | ||
| 7906 | .size = @intCast(st.size), | ||
| 7907 | .atim = timespec.fromTimestamp(st.atim), | ||
| 7908 | .mtim = timespec.fromTimestamp(st.mtim), | ||
| 7909 | .ctim = timespec.fromTimestamp(st.ctim), | ||
| 7910 | |||
| 7911 | .uid = 0, | ||
| 7912 | .gid = 0, | ||
| 7913 | .rdev = 0, | ||
| 7914 | .blksize = 0, | ||
| 7915 | .blocks = 0, | ||
| 7916 | }; | ||
| 7917 | } | ||
| 7918 | }, | ||
| 7919 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { | 7761 | .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos => extern struct { |
| 7920 | dev: i32, | 7762 | dev: i32, |
| 7921 | mode: u16, | 7763 | mode: u16, |
| ... | @@ -8623,19 +8465,6 @@ pub const AT = switch (native_os) { | ... | @@ -8623,19 +8465,6 @@ pub const AT = switch (native_os) { |
| 8623 | pub const STATX_DONT_SYNC = 0x4000; | 8465 | pub const STATX_DONT_SYNC = 0x4000; |
| 8624 | pub const RECURSIVE = 0x8000; | 8466 | pub const RECURSIVE = 0x8000; |
| 8625 | }, | 8467 | }, |
| 8626 | .wasi => struct { | ||
| 8627 | // Match `AT_*` constants in lib/libc/include/wasm-wasi-musl/__header_fcntl.h | ||
| 8628 | pub const EACCESS = 0x0; | ||
| 8629 | pub const SYMLINK_NOFOLLOW = 0x1; | ||
| 8630 | pub const SYMLINK_FOLLOW = 0x2; | ||
| 8631 | pub const REMOVEDIR = 0x4; | ||
| 8632 | /// When linking libc, we follow their convention and use -2 for current working directory. | ||
| 8633 | /// However, without libc, Zig does a different convention: it assumes the | ||
| 8634 | /// current working directory is the first preopen. This behavior can be | ||
| 8635 | /// overridden with a public function called `wasi_cwd` in the root source | ||
| 8636 | /// file. | ||
| 8637 | pub const FDCWD: fd_t = if (builtin.link_libc) -2 else 3; | ||
| 8638 | }, | ||
| 8639 | // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L49-L52 | 8468 | // https://github.com/SerenityOS/serenity/blob/2808b0376406a40e31293bb3bcb9170374e90506/Kernel/API/POSIX/fcntl.h#L49-L52 |
| 8640 | .serenity => struct { | 8469 | .serenity => struct { |
| 8641 | pub const FDCWD = -100; | 8470 | pub const FDCWD = -100; |
| ... | @@ -8671,28 +8500,6 @@ pub const O = switch (native_os) { | ... | @@ -8671,28 +8500,6 @@ pub const O = switch (native_os) { |
| 8671 | TMPFILE: bool = false, | 8500 | TMPFILE: bool = false, |
| 8672 | _: u9 = 0, | 8501 | _: u9 = 0, |
| 8673 | }, | 8502 | }, |
| 8674 | .wasi => packed struct(u32) { | ||
| 8675 | // Match `O_*` bits from lib/libc/include/wasm-wasi-musl/__header_fcntl.h | ||
| 8676 | APPEND: bool = false, | ||
| 8677 | DSYNC: bool = false, | ||
| 8678 | NONBLOCK: bool = false, | ||
| 8679 | RSYNC: bool = false, | ||
| 8680 | SYNC: bool = false, | ||
| 8681 | _5: u7 = 0, | ||
| 8682 | CREAT: bool = false, | ||
| 8683 | DIRECTORY: bool = false, | ||
| 8684 | EXCL: bool = false, | ||
| 8685 | TRUNC: bool = false, | ||
| 8686 | _16: u8 = 0, | ||
| 8687 | NOFOLLOW: bool = false, | ||
| 8688 | EXEC: bool = false, | ||
| 8689 | read: bool = false, | ||
| 8690 | SEARCH: bool = false, | ||
| 8691 | write: bool = false, | ||
| 8692 | // O_CLOEXEC, O_TTY_ININT, O_NOCTTY are 0 in wasi-musl, so they're silently | ||
| 8693 | // ignored in C code. Thus no mapping in Zig. | ||
| 8694 | _: u3 = 0, | ||
| 8695 | }, | ||
| 8696 | .illumos => packed struct(u32) { | 8503 | .illumos => packed struct(u32) { |
| 8697 | ACCMODE: std.posix.ACCMODE = .RDONLY, | 8504 | ACCMODE: std.posix.ACCMODE = .RDONLY, |
| 8698 | NDELAY: bool = false, | 8505 | NDELAY: bool = false, |
| ... | @@ -9131,7 +8938,7 @@ pub const V = switch (native_os) { | ... | @@ -9131,7 +8938,7 @@ pub const V = switch (native_os) { |
| 9131 | STATUS, | 8938 | STATUS, |
| 9132 | ERASE2, | 8939 | ERASE2, |
| 9133 | }, | 8940 | }, |
| 9134 | .emscripten, .wasi => enum { | 8941 | .emscripten => enum { |
| 9135 | INTR, | 8942 | INTR, |
| 9136 | QUIT, | 8943 | QUIT, |
| 9137 | ERASE, | 8944 | ERASE, |
| ... | @@ -9180,7 +8987,7 @@ pub const NCCS = switch (native_os) { | ... | @@ -9180,7 +8987,7 @@ pub const NCCS = switch (native_os) { |
| 9180 | .haiku => 11, | 8987 | .haiku => 11, |
| 9181 | .illumos => 19, | 8988 | .illumos => 19, |
| 9182 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L15 | 8989 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L15 |
| 9183 | .emscripten, .wasi, .serenity => 32, | 8990 | .emscripten, .serenity => 32, |
| 9184 | else => void, | 8991 | else => void, |
| 9185 | }; | 8992 | }; |
| 9186 | 8993 | ||
| ... | @@ -9222,7 +9029,7 @@ pub const termios = switch (native_os) { | ... | @@ -9222,7 +9029,7 @@ pub const termios = switch (native_os) { |
| 9222 | lflag: tc_lflag_t, | 9029 | lflag: tc_lflag_t, |
| 9223 | cc: [NCCS]cc_t, | 9030 | cc: [NCCS]cc_t, |
| 9224 | }, | 9031 | }, |
| 9225 | .emscripten, .wasi => extern struct { | 9032 | .emscripten => extern struct { |
| 9226 | iflag: tc_iflag_t, | 9033 | iflag: tc_iflag_t, |
| 9227 | oflag: tc_oflag_t, | 9034 | oflag: tc_oflag_t, |
| 9228 | cflag: tc_cflag_t, | 9035 | cflag: tc_cflag_t, |
| ... | @@ -9325,7 +9132,7 @@ pub const tc_iflag_t = switch (native_os) { | ... | @@ -9325,7 +9132,7 @@ pub const tc_iflag_t = switch (native_os) { |
| 9325 | _: u16 = 0, | 9132 | _: u16 = 0, |
| 9326 | }, | 9133 | }, |
| 9327 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L52-L66 | 9134 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L52-L66 |
| 9328 | .emscripten, .wasi, .serenity => packed struct(u32) { | 9135 | .emscripten, .serenity => packed struct(u32) { |
| 9329 | IGNBRK: bool = false, | 9136 | IGNBRK: bool = false, |
| 9330 | BRKINT: bool = false, | 9137 | BRKINT: bool = false, |
| 9331 | IGNPAR: bool = false, | 9138 | IGNPAR: bool = false, |
| ... | @@ -9418,7 +9225,7 @@ pub const tc_oflag_t = switch (native_os) { | ... | @@ -9418,7 +9225,7 @@ pub const tc_oflag_t = switch (native_os) { |
| 9418 | _: u14 = 0, | 9225 | _: u14 = 0, |
| 9419 | }, | 9226 | }, |
| 9420 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L69-L97 | 9227 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L69-L97 |
| 9421 | .haiku, .wasi, .emscripten, .serenity => packed struct(u32) { | 9228 | .haiku, .emscripten, .serenity => packed struct(u32) { |
| 9422 | OPOST: bool = false, | 9229 | OPOST: bool = false, |
| 9423 | OLCUC: bool = false, | 9230 | OLCUC: bool = false, |
| 9424 | ONLCR: bool = false, | 9231 | ONLCR: bool = false, |
| ... | @@ -9566,7 +9373,7 @@ pub const tc_cflag_t = switch (native_os) { | ... | @@ -9566,7 +9373,7 @@ pub const tc_cflag_t = switch (native_os) { |
| 9566 | CRTSXOFF: bool = false, | 9373 | CRTSXOFF: bool = false, |
| 9567 | CRTSCTS: bool = false, | 9374 | CRTSCTS: bool = false, |
| 9568 | }, | 9375 | }, |
| 9569 | .wasi, .emscripten => packed struct(u32) { | 9376 | .emscripten => packed struct(u32) { |
| 9570 | _0: u4 = 0, | 9377 | _0: u4 = 0, |
| 9571 | CSIZE: CSIZE = .CS5, | 9378 | CSIZE: CSIZE = .CS5, |
| 9572 | CSTOPB: bool = false, | 9379 | CSTOPB: bool = false, |
| ... | @@ -9702,7 +9509,7 @@ pub const tc_lflag_t = switch (native_os) { | ... | @@ -9702,7 +9509,7 @@ pub const tc_lflag_t = switch (native_os) { |
| 9702 | IEXTEN: bool = false, | 9509 | IEXTEN: bool = false, |
| 9703 | _: u16 = 0, | 9510 | _: u16 = 0, |
| 9704 | }, | 9511 | }, |
| 9705 | .wasi, .emscripten => packed struct(u32) { | 9512 | .emscripten => packed struct(u32) { |
| 9706 | ISIG: bool = false, | 9513 | ISIG: bool = false, |
| 9707 | ICANON: bool = false, | 9514 | ICANON: bool = false, |
| 9708 | _2: u1 = 0, | 9515 | _2: u1 = 0, |
| ... | @@ -9886,7 +9693,7 @@ pub const speed_t = switch (native_os) { | ... | @@ -9886,7 +9693,7 @@ pub const speed_t = switch (native_os) { |
| 9886 | B4000000 = 31, | 9693 | B4000000 = 31, |
| 9887 | }, | 9694 | }, |
| 9888 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L111-L159 | 9695 | // https://github.com/SerenityOS/serenity/blob/d277cdfd4c7ed21d5248a83217ae03b9f890c3c8/Kernel/API/POSIX/termios.h#L111-L159 |
| 9889 | .emscripten, .wasi, .serenity => enum(u32) { | 9696 | .emscripten, .serenity => enum(u32) { |
| 9890 | B0 = 0o0000000, | 9697 | B0 = 0o0000000, |
| 9891 | B50 = 0o0000001, | 9698 | B50 = 0o0000001, |
| 9892 | B75 = 0o0000002, | 9699 | B75 = 0o0000002, |
| ... | @@ -9923,7 +9730,7 @@ pub const speed_t = switch (native_os) { | ... | @@ -9923,7 +9730,7 @@ pub const speed_t = switch (native_os) { |
| 9923 | else => void, | 9730 | else => void, |
| 9924 | }; | 9731 | }; |
| 9925 | 9732 | ||
| 9926 | pub const whence_t = if (native_os == .wasi) std.os.wasi.whence_t else c_int; | 9733 | pub const whence_t = c_int; |
| 9927 | 9734 | ||
| 9928 | pub const sig_atomic_t = switch (native_os) { | 9735 | pub const sig_atomic_t = switch (native_os) { |
| 9929 | // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L20 | 9736 | // https://github.com/SerenityOS/serenity/blob/ec492a1a0819e6239ea44156825c4ee7234ca3db/Kernel/API/POSIX/signal.h#L20 |
| ... | @@ -10881,7 +10688,7 @@ pub const gettimeofday = switch (native_os) { | ... | @@ -10881,7 +10688,7 @@ pub const gettimeofday = switch (native_os) { |
| 10881 | }; | 10688 | }; |
| 10882 | 10689 | ||
| 10883 | pub const mlock = switch (native_os) { | 10690 | pub const mlock = switch (native_os) { |
| 10884 | .windows, .wasi => {}, | 10691 | .windows => {}, |
| 10885 | else => private.mlock, | 10692 | else => private.mlock, |
| 10886 | }; | 10693 | }; |
| 10887 | 10694 | ||
| ... | @@ -10891,7 +10698,7 @@ pub const mlock2 = switch (native_os) { | ... | @@ -10891,7 +10698,7 @@ pub const mlock2 = switch (native_os) { |
| 10891 | }; | 10698 | }; |
| 10892 | 10699 | ||
| 10893 | pub const munlock = switch (native_os) { | 10700 | pub const munlock = switch (native_os) { |
| 10894 | .windows, .wasi => {}, | 10701 | .windows => {}, |
| 10895 | else => private.munlock, | 10702 | else => private.munlock, |
| 10896 | }; | 10703 | }; |
| 10897 | 10704 | ||
| ... | @@ -11042,7 +10849,7 @@ pub const sf_hdtr = switch (native_os) { | ... | @@ -11042,7 +10849,7 @@ pub const sf_hdtr = switch (native_os) { |
| 11042 | }; | 10849 | }; |
| 11043 | 10850 | ||
| 11044 | pub const flock = switch (native_os) { | 10851 | pub const flock = switch (native_os) { |
| 11045 | .windows, .wasi => {}, | 10852 | .windows => {}, |
| 11046 | else => private.flock, | 10853 | else => private.flock, |
| 11047 | }; | 10854 | }; |
| 11048 | 10855 | ||
| ... | @@ -11521,7 +11328,7 @@ pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usi | ... | @@ -11521,7 +11328,7 @@ pub extern "c" fn pthread_get_name_np(thread: pthread_t, name: [*:0]u8, len: usi |
| 11521 | 11328 | ||
| 11522 | pub const TIMER = switch (native_os) { | 11329 | pub const TIMER = switch (native_os) { |
| 11523 | .linux, .emscripten => std.os.linux.TIMER, | 11330 | .linux, .emscripten => std.os.linux.TIMER, |
| 11524 | .openbsd, .netbsd, .wasi, .windows, .freebsd, .serenity => packed struct(u32) { | 11331 | .openbsd, .netbsd, .windows, .freebsd, .serenity => packed struct(u32) { |
| 11525 | ABSTIME: bool, | 11332 | ABSTIME: bool, |
| 11526 | _: u31 = 0, | 11333 | _: u31 = 0, |
| 11527 | }, | 11334 | }, |
| ... | @@ -11529,12 +11336,12 @@ pub const TIMER = switch (native_os) { | ... | @@ -11529,12 +11336,12 @@ pub const TIMER = switch (native_os) { |
| 11529 | }; | 11336 | }; |
| 11530 | 11337 | ||
| 11531 | pub const clock_nanosleep = switch (native_os) { | 11338 | pub const clock_nanosleep = switch (native_os) { |
| 11532 | .linux, .emscripten, .netbsd, .wasi, .windows, .freebsd, .serenity => private.clock_nanosleep, | 11339 | .linux, .emscripten, .netbsd, .windows, .freebsd, .serenity => private.clock_nanosleep, |
| 11533 | else => {}, | 11340 | else => {}, |
| 11534 | }; | 11341 | }; |
| 11535 | 11342 | ||
| 11536 | pub const ioctl = switch (native_os) { | 11343 | pub const ioctl = switch (native_os) { |
| 11537 | .windows, .wasi => {}, | 11344 | .windows => {}, |
| 11538 | else => private.ioctl, | 11345 | else => private.ioctl, |
| 11539 | }; | 11346 | }; |
| 11540 | 11347 |
lib/std/fs/test.zig+3-9| ... | @@ -890,14 +890,8 @@ test "file operations on directories" { | ... | @@ -890,14 +890,8 @@ test "file operations on directories" { |
| 890 | }, | 890 | }, |
| 891 | } | 891 | } |
| 892 | 892 | ||
| 893 | if (native_os == .wasi and builtin.link_libc) { | 893 | // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms. |
| 894 | // wasmtime unexpectedly succeeds here, see https://github.com/ziglang/zig/issues/20747 | 894 | try expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write })); |
| 895 | const handle = try ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write }); | ||
| 896 | handle.close(io); | ||
| 897 | } else { | ||
| 898 | // Note: The `.mode = .read_write` is necessary to ensure the error occurs on all platforms. | ||
| 899 | try expectError(error.IsDir, ctx.dir.openFile(io, test_dir_name, .{ .mode = .read_write })); | ||
| 900 | } | ||
| 901 | 895 | ||
| 902 | { | 896 | { |
| 903 | const handle = try ctx.dir.openFile(io, test_dir_name, .{ .allow_directory = true, .mode = .read_only }); | 897 | 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" { | ... | @@ -2765,7 +2759,7 @@ test "hard link with different directories" { |
| 2765 | } | 2759 | } |
| 2766 | 2760 | ||
| 2767 | test "stat smoke test" { | 2761 | test "stat smoke test" { |
| 2768 | if (native_os == .wasi and !builtin.link_libc) return error.SkipZigTest; | 2762 | if (native_os == .wasi) return error.SkipZigTest; |
| 2769 | 2763 | ||
| 2770 | const io = testing.io; | 2764 | const io = testing.io; |
| 2771 | 2765 |
lib/std/os/wasi.zig+1-1| ... | @@ -1,7 +1,7 @@ | ... | @@ -1,7 +1,7 @@ |
| 1 | //! wasi_snapshot_preview1 spec available (in witx format) here: | 1 | //! wasi_snapshot_preview1 spec available (in witx format) here: |
| 2 | //! * typenames -- https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/typenames.witx | 2 | //! * typenames -- https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/typenames.witx |
| 3 | //! * module -- https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx | 3 | //! * module -- https://github.com/WebAssembly/WASI/blob/main/legacy/preview1/witx/wasi_snapshot_preview1.witx |
| 4 | //! Note that libc API does *not* go in this file. wasi libc API goes into std/c.zig instead. | 4 | //! Note that libc API does *not* go in this file. |
| 5 | const builtin = @import("builtin"); | 5 | const builtin = @import("builtin"); |
| 6 | const std = @import("std"); | 6 | const std = @import("std"); |
| 7 | const assert = std.debug.assert; | 7 | const assert = std.debug.assert; |
lib/std/posix.zig+4-3| ... | @@ -24,7 +24,7 @@ test { | ... | @@ -24,7 +24,7 @@ test { |
| 24 | 24 | ||
| 25 | /// Whether to use libc for the POSIX API layer. | 25 | /// Whether to use libc for the POSIX API layer. |
| 26 | const use_libc = builtin.link_libc or switch (native_os) { | 26 | const use_libc = builtin.link_libc or switch (native_os) { |
| 27 | .windows, .wasi => true, | 27 | .windows => true, |
| 28 | else => false, | 28 | else => false, |
| 29 | }; | 29 | }; |
| 30 | 30 | ||
| ... | @@ -54,6 +54,7 @@ else switch (native_os) { | ... | @@ -54,6 +54,7 @@ else switch (native_os) { |
| 54 | // https://github.com/pspdev/newlib/blob/9e0a073634ad73e8e088f2e071c55a9fe5d39709/newlib/libc/sys/psp/sys/dirent.h#L19 | 54 | // https://github.com/pspdev/newlib/blob/9e0a073634ad73e8e088f2e071c55a9fe5d39709/newlib/libc/sys/psp/sys/dirent.h#L19 |
| 55 | pub const NAME_MAX = 255; | 55 | pub const NAME_MAX = 255; |
| 56 | }, | 56 | }, |
| 57 | .wasi => @import("posix/wasi.zig"), | ||
| 57 | else => struct { | 58 | else => struct { |
| 58 | pub const pid_t = void; | 59 | pub const pid_t = void; |
| 59 | pub const pollfd = void; | 60 | pub const pollfd = void; |
| ... | @@ -443,7 +444,7 @@ pub const OpenError = std.Io.File.OpenError || error{WouldBlock}; | ... | @@ -443,7 +444,7 @@ pub const OpenError = std.Io.File.OpenError || error{WouldBlock}; |
| 443 | pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenError!fd_t { | 444 | pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenError!fd_t { |
| 444 | if (native_os == .windows) { | 445 | if (native_os == .windows) { |
| 445 | @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); | 446 | @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); |
| 446 | } else if (native_os == .wasi and !builtin.link_libc) { | 447 | } else if (native_os == .wasi) { |
| 447 | @compileError("use std.Io instead"); | 448 | @compileError("use std.Io instead"); |
| 448 | } | 449 | } |
| 449 | const file_path_c = try toPosixPath(file_path); | 450 | 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 | ... | @@ -459,7 +460,7 @@ pub fn openat(dir_fd: fd_t, file_path: []const u8, flags: O, mode: mode_t) OpenE |
| 459 | pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: O, mode: mode_t) OpenError!fd_t { | 460 | pub fn openatZ(dir_fd: fd_t, file_path: [*:0]const u8, flags: O, mode: mode_t) OpenError!fd_t { |
| 460 | if (native_os == .windows) { | 461 | if (native_os == .windows) { |
| 461 | @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); | 462 | @compileError("Windows does not support POSIX; use Windows-specific API or cross-platform std.fs API"); |
| 462 | } else if (native_os == .wasi and !builtin.link_libc) { | 463 | } else if (native_os == .wasi) { |
| 463 | return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode); | 464 | return openat(dir_fd, mem.sliceTo(file_path, 0), flags, mode); |
| 464 | } | 465 | } |
| 465 | 466 |
lib/std/posix/wasi.zig created+81| ... | @@ -0,0 +1,81 @@ | ||
| 1 | //! This exists to satisfy the `std.posix` interface for WASI w/o libc. Most of the stuff here is | ||
| 2 | //! taken from wasi-libc, i.e. it is essentially made up from the perspective of pure WASI. This | ||
| 3 | //! should be removed alongside `std.posix` eventually. | ||
| 4 | |||
| 5 | const builtin = @import("builtin"); | ||
| 6 | const std = @import("../std.zig"); | ||
| 7 | |||
| 8 | const wasi = std.os.wasi; | ||
| 9 | |||
| 10 | pub const pid_t = i32; | ||
| 11 | pub const fd_t = wasi.fd_t; | ||
| 12 | pub const uid_t = u32; | ||
| 13 | pub const gid_t = u32; | ||
| 14 | pub const mode_t = u0; | ||
| 15 | pub const nlink_t = u64; | ||
| 16 | pub const ino_t = wasi.inode_t; | ||
| 17 | |||
| 18 | pub const time_t = i64; | ||
| 19 | pub const timespec = extern struct { | ||
| 20 | sec: time_t, | ||
| 21 | nsec: c_long, | ||
| 22 | |||
| 23 | pub fn fromTimestamp(tm: wasi.timestamp_t) @This() { | ||
| 24 | const sec: wasi.timestamp_t = tm / 1_000_000_000; | ||
| 25 | const nsec = tm - sec * 1_000_000_000; | ||
| 26 | return .{ | ||
| 27 | .sec = @as(time_t, @intCast(sec)), | ||
| 28 | .nsec = @as(isize, @intCast(nsec)), | ||
| 29 | }; | ||
| 30 | } | ||
| 31 | |||
| 32 | pub fn toTimestamp(ts: @This()) wasi.timestamp_t { | ||
| 33 | return @as(wasi.timestamp_t, @intCast(ts.sec * 1_000_000_000)) + | ||
| 34 | @as(wasi.timestamp_t, @intCast(ts.nsec)); | ||
| 35 | } | ||
| 36 | }; | ||
| 37 | |||
| 38 | pub const pollfd = extern struct { | ||
| 39 | fd: fd_t, | ||
| 40 | events: i16, | ||
| 41 | revents: i16 = undefined, | ||
| 42 | }; | ||
| 43 | |||
| 44 | pub const rlimit_resource = void; | ||
| 45 | |||
| 46 | pub const E = wasi.errno_t; | ||
| 47 | |||
| 48 | pub const SIG = void; | ||
| 49 | pub const Sigaction = void; | ||
| 50 | |||
| 51 | pub const PROT = void; | ||
| 52 | |||
| 53 | pub const MCL = void; | ||
| 54 | |||
| 55 | pub const AT = struct { | ||
| 56 | pub const EACCESS = 0x0; | ||
| 57 | pub const SYMLINK_NOFOLLOW = 0x1; | ||
| 58 | pub const SYMLINK_FOLLOW = 0x2; | ||
| 59 | pub const REMOVEDIR = 0x4; | ||
| 60 | |||
| 61 | pub const FDCWD: fd_t = 3; | ||
| 62 | }; | ||
| 63 | |||
| 64 | pub const IFNAMESIZE = {}; | ||
| 65 | |||
| 66 | pub const STDIN_FILENO = 0; | ||
| 67 | pub const STDOUT_FILENO = 1; | ||
| 68 | pub const STDERR_FILENO = 2; | ||
| 69 | |||
| 70 | pub const PATH_MAX = 4096; | ||
| 71 | pub const IOV_MAX = 1024; | ||
| 72 | |||
| 73 | pub const getrandom = {}; | ||
| 74 | |||
| 75 | pub const mlock = {}; | ||
| 76 | pub const mlock2 = {}; | ||
| 77 | pub const munlock = {}; | ||
| 78 | pub const mlockall = {}; | ||
| 79 | pub const munlockall = {}; | ||
| 80 | |||
| 81 | pub const cmsg_align = {}; | ||
lib/std/process/Args.zig+5-9| ... | @@ -14,11 +14,7 @@ vector: Vector, | ... | @@ -14,11 +14,7 @@ vector: Vector, |
| 14 | /// queried and heap-allocated at runtime. | 14 | /// queried and heap-allocated at runtime. |
| 15 | pub const Vector = switch (native_os) { | 15 | pub const Vector = switch (native_os) { |
| 16 | .windows => []const u16, // WTF-16 encoded | 16 | .windows => []const u16, // WTF-16 encoded |
| 17 | .wasi => switch (builtin.link_libc) { | 17 | .wasi, .freestanding, .other => void, |
| 18 | false => void, | ||
| 19 | true => []const [*:0]const u8, | ||
| 20 | }, | ||
| 21 | .freestanding, .other => void, | ||
| 22 | else => []const [*:0]const u8, | 18 | else => []const [*:0]const u8, |
| 23 | }; | 19 | }; |
| 24 | 20 | ||
| ... | @@ -26,7 +22,7 @@ pub const Vector = switch (native_os) { | ... | @@ -26,7 +22,7 @@ pub const Vector = switch (native_os) { |
| 26 | pub const Iterator = struct { | 22 | pub const Iterator = struct { |
| 27 | const Inner = switch (native_os) { | 23 | const Inner = switch (native_os) { |
| 28 | .windows => Windows, | 24 | .windows => Windows, |
| 29 | .wasi => if (builtin.link_libc) Posix else Wasi, | 25 | .wasi => Wasi, |
| 30 | else => Posix, | 26 | else => Posix, |
| 31 | }; | 27 | }; |
| 32 | 28 | ||
| ... | @@ -44,7 +40,7 @@ pub const Iterator = struct { | ... | @@ -44,7 +40,7 @@ pub const Iterator = struct { |
| 44 | 40 | ||
| 45 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. | 41 | /// You must deinitialize iterator's internal buffers by calling `deinit` when done. |
| 46 | pub fn initAllocator(a: Args, gpa: Allocator) InitError!Iterator { | 42 | pub fn initAllocator(a: Args, gpa: Allocator) InitError!Iterator { |
| 47 | if (native_os == .wasi and !builtin.link_libc) { | 43 | if (native_os == .wasi) { |
| 48 | return .{ .inner = try .init(gpa) }; | 44 | return .{ .inner = try .init(gpa) }; |
| 49 | } | 45 | } |
| 50 | if (native_os == .windows) { | 46 | if (native_os == .windows) { |
| ... | @@ -73,7 +69,7 @@ pub const Iterator = struct { | ... | @@ -73,7 +69,7 @@ pub const Iterator = struct { |
| 73 | /// `initAllocator` function. | 69 | /// `initAllocator` function. |
| 74 | pub fn deinit(it: *Iterator) void { | 70 | pub fn deinit(it: *Iterator) void { |
| 75 | // Unless we're targeting WASI or Windows, this is a no-op. | 71 | // Unless we're targeting WASI or Windows, this is a no-op. |
| 76 | if (native_os == .wasi and !builtin.link_libc) it.inner.deinit(); | 72 | if (native_os == .wasi) it.inner.deinit(); |
| 77 | if (native_os == .windows) it.inner.deinit(); | 73 | if (native_os == .windows) it.inner.deinit(); |
| 78 | } | 74 | } |
| 79 | 75 | ||
| ... | @@ -504,7 +500,7 @@ pub fn toSlice(a: Args, arena: Allocator) ToSliceError![]const [:0]const u8 { | ... | @@ -504,7 +500,7 @@ pub fn toSlice(a: Args, arena: Allocator) ToSliceError![]const [:0]const u8 { |
| 504 | } | 500 | } |
| 505 | 501 | ||
| 506 | return result_slice_list; | 502 | return result_slice_list; |
| 507 | } else if (native_os == .wasi and !builtin.link_libc) { | 503 | } else if (native_os == .wasi) { |
| 508 | var count: usize = undefined; | 504 | var count: usize = undefined; |
| 509 | var buf_size: usize = undefined; | 505 | var buf_size: usize = undefined; |
| 510 | 506 |
lib/std/process/Environ.zig+4-7| ... | @@ -24,11 +24,8 @@ pub const empty: Environ = .{ .block = .empty }; | ... | @@ -24,11 +24,8 @@ pub const empty: Environ = .{ .block = .empty }; |
| 24 | /// operating system `void` is also used. | 24 | /// operating system `void` is also used. |
| 25 | pub const Block = switch (native_os) { | 25 | pub const Block = switch (native_os) { |
| 26 | .windows => GlobalBlock, | 26 | .windows => GlobalBlock, |
| 27 | .wasi, .emscripten => switch (builtin.link_libc) { | 27 | .emscripten => if (builtin.link_libc) PosixBlock else GlobalBlock, |
| 28 | false => GlobalBlock, | 28 | .wasi, .freestanding, .other => GlobalBlock, |
| 29 | true => PosixBlock, | ||
| 30 | }, | ||
| 31 | .freestanding, .other => GlobalBlock, | ||
| 32 | else => PosixBlock, | 29 | else => PosixBlock, |
| 33 | }; | 30 | }; |
| 34 | 31 | ||
| ... | @@ -513,7 +510,7 @@ pub fn createMap(env: Environ, allocator: Allocator) CreateMapError!Map { | ... | @@ -513,7 +510,7 @@ pub fn createMap(env: Environ, allocator: Allocator) CreateMapError!Map { |
| 513 | assert(std.os.windows.ntdll.RtlEnterCriticalSection(peb.FastPebLock) == .SUCCESS); | 510 | assert(std.os.windows.ntdll.RtlEnterCriticalSection(peb.FastPebLock) == .SUCCESS); |
| 514 | defer assert(std.os.windows.ntdll.RtlLeaveCriticalSection(peb.FastPebLock) == .SUCCESS); | 511 | defer assert(std.os.windows.ntdll.RtlLeaveCriticalSection(peb.FastPebLock) == .SUCCESS); |
| 515 | try map.putWindowsBlock(.{ .ptr = peb.ProcessParameters.Environment }); | 512 | try map.putWindowsBlock(.{ .ptr = peb.ProcessParameters.Environment }); |
| 516 | } else if (native_os == .wasi and !builtin.link_libc) empty: { | 513 | } else if (native_os == .wasi) empty: { |
| 517 | if (!env.block.use_global) break :empty; | 514 | if (!env.block.use_global) break :empty; |
| 518 | 515 | ||
| 519 | var environ_count: usize = undefined; | 516 | var environ_count: usize = undefined; |
| ... | @@ -951,7 +948,7 @@ test Map { | ... | @@ -951,7 +948,7 @@ test Map { |
| 951 | 948 | ||
| 952 | test "convert from Environ to Map and back again" { | 949 | test "convert from Environ to Map and back again" { |
| 953 | if (native_os == .windows) return; | 950 | if (native_os == .windows) return; |
| 954 | if (native_os == .wasi and !builtin.link_libc) return; | 951 | if (native_os == .wasi) return; |
| 955 | 952 | ||
| 956 | const gpa = testing.allocator; | 953 | const gpa = testing.allocator; |
| 957 | 954 |
lib/std/start.zig+1-1| ... | @@ -757,7 +757,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal | ... | @@ -757,7 +757,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal |
| 757 | fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { | 757 | fn mainWithoutEnv(c_argc: c_int, c_argv: [*][*:0]c_char) callconv(.c) c_int { |
| 758 | const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)]; | 758 | const argv = @as([*][*:0]u8, @ptrCast(c_argv))[0..@intCast(c_argc)]; |
| 759 | const environ: [:null]?[*:0]u8 = switch (builtin.os.tag) { | 759 | const environ: [:null]?[*:0]u8 = switch (builtin.os.tag) { |
| 760 | .wasi, .emscripten => environ: { | 760 | .emscripten => environ: { |
| 761 | const c_environ = std.c.environ; | 761 | const c_environ = std.c.environ; |
| 762 | var env_count: usize = 0; | 762 | var env_count: usize = 0; |
| 763 | while (c_environ[env_count] != null) : (env_count += 1) {} | 763 | while (c_environ[env_count] != null) : (env_count += 1) {} |
lib/std/zig/LibCDirs.zig+1-1| ... | @@ -165,7 +165,7 @@ pub fn detectFromBuilding(arena: Allocator, zig_lib_dir: Path, target: *const st | ... | @@ -165,7 +165,7 @@ pub fn detectFromBuilding(arena: Allocator, zig_lib_dir: Path, target: *const st |
| 165 | 165 | ||
| 166 | const generic_name = libCGenericName(target); | 166 | const generic_name = libCGenericName(target); |
| 167 | // Some architecture families are handled by the same set of headers. | 167 | // Some architecture families are handled by the same set of headers. |
| 168 | const arch_name = if (target.isMuslLibC() or target.isWasiLibC()) | 168 | const arch_name = if (target.isMuslLibC()) |
| 169 | std.zig.target.muslArchNameHeaders(target.cpu.arch) | 169 | std.zig.target.muslArchNameHeaders(target.cpu.arch) |
| 170 | else if (target.isGnuLibC()) | 170 | else if (target.isGnuLibC()) |
| 171 | std.zig.target.glibcArchNameHeaders(target.cpu.arch) | 171 | std.zig.target.glibcArchNameHeaders(target.cpu.arch) |
lib/std/zig/target.zig-15| ... | @@ -103,7 +103,6 @@ pub const available_libcs = [_]ArchOsAbi{ | ... | @@ -103,7 +103,6 @@ pub const available_libcs = [_]ArchOsAbi{ |
| 103 | .{ .arch = .sparc64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 1, .patch = 19 } }, | 103 | .{ .arch = .sparc64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 1, .patch = 19 } }, |
| 104 | .{ .arch = .sparc64, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 1, .minor = 4, .patch = 0 } }, | 104 | .{ .arch = .sparc64, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 1, .minor = 4, .patch = 0 } }, |
| 105 | .{ .arch = .sparc64, .os = .openbsd, .abi = .none, .os_ver = .{ .major = 3, .minor = 0, .patch = 0 } }, | 105 | .{ .arch = .sparc64, .os = .openbsd, .abi = .none, .os_ver = .{ .major = 3, .minor = 0, .patch = 0 } }, |
| 106 | .{ .arch = .wasm32, .os = .wasi, .abi = .musl }, | ||
| 107 | .{ .arch = .x86, .os = .freebsd, .abi = .none }, | 106 | .{ .arch = .x86, .os = .freebsd, .abi = .none }, |
| 108 | .{ .arch = .x86, .os = .linux, .abi = .gnu, .glibc_triple = "i686-linux-gnu" }, | 107 | .{ .arch = .x86, .os = .linux, .abi = .gnu, .glibc_triple = "i686-linux-gnu" }, |
| 109 | .{ .arch = .x86, .os = .linux, .abi = .musl }, | 108 | .{ .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 | ... | @@ -241,7 +240,6 @@ pub fn muslArchName(arch: std.Target.Cpu.Arch, abi: std.Target.Abi) [:0]const u8 |
| 241 | .riscv32 => "riscv32", | 240 | .riscv32 => "riscv32", |
| 242 | .riscv64 => "riscv64", | 241 | .riscv64 => "riscv64", |
| 243 | .s390x => "s390x", | 242 | .s390x => "s390x", |
| 244 | .wasm32, .wasm64 => "wasm", | ||
| 245 | .x86 => "i386", | 243 | .x86 => "i386", |
| 246 | .x86_64 => "x86_64", | 244 | .x86_64 => "x86_64", |
| 247 | else => unreachable, | 245 | else => unreachable, |
| ... | @@ -396,19 +394,6 @@ pub fn isLibCLibName(target: *const std.Target, name: []const u8) bool { | ... | @@ -396,19 +394,6 @@ pub fn isLibCLibName(target: *const std.Target, name: []const u8) bool { |
| 396 | return true; | 394 | return true; |
| 397 | if (eqlIgnoreCase(ignore_case, name, "xnet")) | 395 | if (eqlIgnoreCase(ignore_case, name, "xnet")) |
| 398 | return true; | 396 | return true; |
| 399 | |||
| 400 | if (target.os.tag == .wasi) { | ||
| 401 | if (eqlIgnoreCase(ignore_case, name, "setjmp")) | ||
| 402 | return true; | ||
| 403 | if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-getpid")) | ||
| 404 | return true; | ||
| 405 | if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-mman")) | ||
| 406 | return true; | ||
| 407 | if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-process-clocks")) | ||
| 408 | return true; | ||
| 409 | if (eqlIgnoreCase(ignore_case, name, "wasi-emulated-signal")) | ||
| 410 | return true; | ||
| 411 | } | ||
| 412 | } | 397 | } |
| 413 | 398 | ||
| 414 | if (target.os.tag.isDarwin()) { | 399 | if (target.os.tag.isDarwin()) { |
src/Compilation.zig-31| ... | @@ -29,7 +29,6 @@ const openbsd = @import("libs/openbsd.zig"); | ... | @@ -29,7 +29,6 @@ const openbsd = @import("libs/openbsd.zig"); |
| 29 | const mingw = @import("libs/mingw.zig"); | 29 | const mingw = @import("libs/mingw.zig"); |
| 30 | const libunwind = @import("libs/libunwind.zig"); | 30 | const libunwind = @import("libs/libunwind.zig"); |
| 31 | const libcxx = @import("libs/libcxx.zig"); | 31 | const libcxx = @import("libs/libcxx.zig"); |
| 32 | const wasi_libc = @import("libs/wasi_libc.zig"); | ||
| 33 | const clangMain = @import("main.zig").clangMain; | 32 | const clangMain = @import("main.zig").clangMain; |
| 34 | const Zcu = @import("Zcu.zig"); | 33 | const Zcu = @import("Zcu.zig"); |
| 35 | const Sema = @import("Sema.zig"); | 34 | const Sema = @import("Sema.zig"); |
| ... | @@ -294,8 +293,6 @@ const QueuedJobs = struct { | ... | @@ -294,8 +293,6 @@ const QueuedJobs = struct { |
| 294 | freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".field_names.len]bool = @splat(false), | 293 | freebsd_crt_file: [@typeInfo(freebsd.CrtFile).@"enum".field_names.len]bool = @splat(false), |
| 295 | netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), | 294 | netbsd_crt_file: [@typeInfo(netbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), |
| 296 | openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), | 295 | openbsd_crt_file: [@typeInfo(openbsd.CrtFile).@"enum".field_names.len]bool = @splat(false), |
| 297 | /// one of WASI libc static objects | ||
| 298 | wasi_libc_crt_file: [@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len]bool = @splat(false), | ||
| 299 | /// one of the mingw-w64 static objects | 296 | /// one of the mingw-w64 static objects |
| 300 | mingw_crt_file: [@typeInfo(mingw.CrtFile).@"enum".field_names.len]bool = @splat(false), | 297 | mingw_crt_file: [@typeInfo(mingw.CrtFile).@"enum".field_names.len]bool = @splat(false), |
| 301 | /// all of the glibc shared objects | 298 | /// all of the glibc shared objects |
| ... | @@ -1217,7 +1214,6 @@ pub const MiscTask = enum { | ... | @@ -1217,7 +1214,6 @@ pub const MiscTask = enum { |
| 1217 | libtsan, | 1214 | libtsan, |
| 1218 | libubsan, | 1215 | libubsan, |
| 1219 | libfuzzer, | 1216 | libfuzzer, |
| 1220 | wasi_libc_crt_file, | ||
| 1221 | compiler_rt, | 1217 | compiler_rt, |
| 1222 | libzigc, | 1218 | libzigc, |
| 1223 | link_depfile, | 1219 | link_depfile, |
| ... | @@ -1230,10 +1226,6 @@ pub const MiscTask = enum { | ... | @@ -1230,10 +1226,6 @@ pub const MiscTask = enum { |
| 1230 | @"musl libc.a", | 1226 | @"musl libc.a", |
| 1231 | @"musl libc.so", | 1227 | @"musl libc.so", |
| 1232 | 1228 | ||
| 1233 | @"wasi crt1-reactor.o", | ||
| 1234 | @"wasi crt1-command.o", | ||
| 1235 | @"wasi libc.a", | ||
| 1236 | |||
| 1237 | @"glibc Scrt1.o", | 1229 | @"glibc Scrt1.o", |
| 1238 | @"glibc libc_nonshared.a", | 1230 | @"glibc libc_nonshared.a", |
| 1239 | @"glibc shared object", | 1231 | @"glibc shared object", |
| ... | @@ -2502,11 +2494,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, | ... | @@ -2502,11 +2494,6 @@ pub fn create(gpa: Allocator, arena: Allocator, io: Io, diag: *CreateDiagnostic, |
| 2502 | } | 2494 | } |
| 2503 | 2495 | ||
| 2504 | comp.queued_jobs.openbsd_shared_objects = true; | 2496 | comp.queued_jobs.openbsd_shared_objects = true; |
| 2505 | } else if (target.isWasiLibC()) { | ||
| 2506 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); | ||
| 2507 | |||
| 2508 | comp.queued_jobs.wasi_libc_crt_file[@backingInt(wasi_libc.execModelCrtFile(comp.config.wasi_exec_model))] = true; | ||
| 2509 | comp.queued_jobs.wasi_libc_crt_file[@backingInt(wasi_libc.CrtFile.libc_a)] = true; | ||
| 2510 | } else if (target.isMinGW()) { | 2497 | } else if (target.isMinGW()) { |
| 2511 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); | 2498 | if (!std.zig.target.canBuildLibC(target)) return diag.fail(.cross_libc_unavailable); |
| 2512 | 2499 | ||
| ... | @@ -4602,13 +4589,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node | ... | @@ -4602,13 +4589,6 @@ fn dispatchPrelinkWork(comp: *Compilation, main_progress_node: std.Progress.Node |
| 4602 | } | 4589 | } |
| 4603 | } | 4590 | } |
| 4604 | 4591 | ||
| 4605 | for (0..@typeInfo(wasi_libc.CrtFile).@"enum".field_names.len) |i| { | ||
| 4606 | if (comp.queued_jobs.wasi_libc_crt_file[i]) { | ||
| 4607 | const tag: wasi_libc.CrtFile = @fromBackingInt(@intCast(i)); | ||
| 4608 | prelink_group.async(io, buildWasiLibcCrtFile, .{ comp, tag, main_progress_node }); | ||
| 4609 | } | ||
| 4610 | } | ||
| 4611 | |||
| 4612 | for (0..@typeInfo(mingw.CrtFile).@"enum".field_names.len) |i| { | 4592 | for (0..@typeInfo(mingw.CrtFile).@"enum".field_names.len) |i| { |
| 4613 | if (comp.queued_jobs.mingw_crt_file[i]) { | 4593 | if (comp.queued_jobs.mingw_crt_file[i]) { |
| 4614 | const tag: mingw.CrtFile = @fromBackingInt(@intCast(i)); | 4594 | const tag: mingw.CrtFile = @fromBackingInt(@intCast(i)); |
| ... | @@ -5365,17 +5345,6 @@ fn buildMingwImportLib(comp: *Compilation, lib_name: []const u8, is_prelink: boo | ... | @@ -5365,17 +5345,6 @@ fn buildMingwImportLib(comp: *Compilation, lib_name: []const u8, is_prelink: boo |
| 5365 | ); | 5345 | ); |
| 5366 | } | 5346 | } |
| 5367 | 5347 | ||
| 5368 | fn buildWasiLibcCrtFile(comp: *Compilation, crt_file: wasi_libc.CrtFile, prog_node: std.Progress.Node) void { | ||
| 5369 | if (wasi_libc.buildCrtFile(comp, crt_file, prog_node)) |_| { | ||
| 5370 | comp.queued_jobs.wasi_libc_crt_file[@backingInt(crt_file)] = false; | ||
| 5371 | } else |err| switch (err) { | ||
| 5372 | error.AlreadyReported => return, | ||
| 5373 | else => comp.lockAndSetMiscFailure(.wasi_libc_crt_file, "unable to build WASI libc {s}: {s}", .{ | ||
| 5374 | @tagName(crt_file), @errorName(err), | ||
| 5375 | }), | ||
| 5376 | } | ||
| 5377 | } | ||
| 5378 | |||
| 5379 | fn buildLibUnwind(comp: *Compilation, prog_node: std.Progress.Node) void { | 5348 | fn buildLibUnwind(comp: *Compilation, prog_node: std.Progress.Node) void { |
| 5380 | if (libunwind.buildStaticLib(comp, prog_node)) |_| { | 5349 | if (libunwind.buildStaticLib(comp, prog_node)) |_| { |
| 5381 | comp.queued_jobs.libunwind = false; | 5350 | comp.queued_jobs.libunwind = false; |
src/libs/libcxx.zig+2-19| ... | @@ -195,9 +195,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! | ... | @@ -195,9 +195,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! |
| 195 | var c_source_files = try std.array_list.Managed(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len); | 195 | var c_source_files = try std.array_list.Managed(Compilation.CSourceFile).initCapacity(arena, libcxx_files.len); |
| 196 | 196 | ||
| 197 | for (libcxx_files) |cxx_src| { | 197 | for (libcxx_files) |cxx_src| { |
| 198 | // These don't compile on WASI due to e.g. `fchmod` usage. | ||
| 199 | if (std.mem.startsWith(u8, cxx_src, "src/filesystem/") and target.os.tag == .wasi) | ||
| 200 | continue; | ||
| 201 | if (std.mem.startsWith(u8, cxx_src, "src/support/win32/") and target.os.tag != .windows) | 198 | if (std.mem.startsWith(u8, cxx_src, "src/support/win32/") and target.os.tag != .windows) |
| 202 | continue; | 199 | continue; |
| 203 | 200 | ||
| ... | @@ -211,11 +208,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! | ... | @@ -211,11 +208,6 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! |
| 211 | try cflags.append("-D_LIBCPP_BUILDING_LIBRARY"); | 208 | try cflags.append("-D_LIBCPP_BUILDING_LIBRARY"); |
| 212 | try cflags.append("-DLIBCXX_BUILDING_LIBCXXABI"); | 209 | try cflags.append("-DLIBCXX_BUILDING_LIBCXXABI"); |
| 213 | try cflags.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER"); | 210 | try cflags.append("-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER"); |
| 214 | |||
| 215 | if (target.os.tag == .wasi) { | ||
| 216 | try cflags.append("-fno-exceptions"); | ||
| 217 | } | ||
| 218 | |||
| 219 | try cflags.append("-fvisibility=hidden"); | 211 | try cflags.append("-fvisibility=hidden"); |
| 220 | try cflags.append("-fvisibility-inlines-hidden"); | 212 | try cflags.append("-fvisibility-inlines-hidden"); |
| 221 | 213 | ||
| ... | @@ -386,10 +378,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr | ... | @@ -386,10 +378,7 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr |
| 386 | for (libcxxabi_files) |cxxabi_src| { | 378 | for (libcxxabi_files) |cxxabi_src| { |
| 387 | if (!comp.config.any_non_single_threaded and std.mem.eql(u8, cxxabi_src, "src/cxa_thread_atexit.cpp")) | 379 | if (!comp.config.any_non_single_threaded and std.mem.eql(u8, cxxabi_src, "src/cxa_thread_atexit.cpp")) |
| 388 | continue; | 380 | continue; |
| 389 | if (target.os.tag == .wasi and | 381 | if (std.mem.eql(u8, cxxabi_src, "src/cxa_noexception.cpp")) |
| 390 | (std.mem.eql(u8, cxxabi_src, "src/cxa_exception.cpp") or std.mem.eql(u8, cxxabi_src, "src/cxa_personality.cpp"))) | ||
| 391 | continue; | ||
| 392 | if (target.os.tag != .wasi and std.mem.eql(u8, cxxabi_src, "src/cxa_noexception.cpp")) | ||
| 393 | continue; | 382 | continue; |
| 394 | 383 | ||
| 395 | var cflags = std.array_list.Managed([]const u8).init(arena); | 384 | 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 | ... | @@ -408,10 +397,6 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr |
| 408 | try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL"); | 397 | try cflags.append("-DHAVE___CXA_THREAD_ATEXIT_IMPL"); |
| 409 | } | 398 | } |
| 410 | 399 | ||
| 411 | if (target.os.tag == .wasi) { | ||
| 412 | try cflags.append("-fno-exceptions"); | ||
| 413 | } | ||
| 414 | |||
| 415 | try cflags.append("-fvisibility=hidden"); | 400 | try cflags.append("-fvisibility=hidden"); |
| 416 | try cflags.append("-fvisibility-inlines-hidden"); | 401 | try cflags.append("-fvisibility-inlines-hidden"); |
| 417 | 402 | ||
| ... | @@ -519,9 +504,7 @@ pub fn addCxxArgs( | ... | @@ -519,9 +504,7 @@ pub fn addCxxArgs( |
| 519 | try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); | 504 | try cflags.append("-D_LIBCXXABI_DISABLE_VISIBILITY_ANNOTATIONS"); |
| 520 | try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS"); | 505 | try cflags.append("-D_LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS"); |
| 521 | try cflags.append("-D_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS=0"); | 506 | try cflags.append("-D_LIBCPP_HAS_VENDOR_AVAILABILITY_ANNOTATIONS=0"); |
| 522 | try cflags.append(try std.fmt.allocPrint(arena, "-D_LIBCPP_HAS_FILESYSTEM={d}", .{ | 507 | try cflags.append("-D_LIBCPP_HAS_FILESYSTEM"); |
| 523 | @as(u1, if (target.os.tag == .wasi) 0 else 1), | ||
| 524 | })); | ||
| 525 | try cflags.append("-D_LIBCPP_HAS_RANDOM_DEVICE"); | 508 | try cflags.append("-D_LIBCPP_HAS_RANDOM_DEVICE"); |
| 526 | try cflags.append("-D_LIBCPP_HAS_LOCALIZATION"); | 509 | try cflags.append("-D_LIBCPP_HAS_LOCALIZATION"); |
| 527 | try cflags.append("-D_LIBCPP_HAS_UNICODE"); | 510 | try cflags.append("-D_LIBCPP_HAS_UNICODE"); |
src/libs/wasi_libc.zig deleted-1115| ... | @@ -1,1115 +0,0 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const mem = std.mem; | ||
| 3 | const path = std.fs.path; | ||
| 4 | |||
| 5 | const Allocator = std.mem.Allocator; | ||
| 6 | const Compilation = @import("../Compilation.zig"); | ||
| 7 | const build_options = @import("build_options"); | ||
| 8 | |||
| 9 | pub const CrtFile = enum { | ||
| 10 | crt1_reactor_o, | ||
| 11 | crt1_command_o, | ||
| 12 | libc_a, | ||
| 13 | }; | ||
| 14 | |||
| 15 | pub fn execModelCrtFile(wasi_exec_model: std.lang.WasiExecModel) CrtFile { | ||
| 16 | return switch (wasi_exec_model) { | ||
| 17 | .reactor => CrtFile.crt1_reactor_o, | ||
| 18 | .command => CrtFile.crt1_command_o, | ||
| 19 | }; | ||
| 20 | } | ||
| 21 | |||
| 22 | pub fn execModelCrtFileFullName(wasi_exec_model: std.lang.WasiExecModel) []const u8 { | ||
| 23 | return switch (execModelCrtFile(wasi_exec_model)) { | ||
| 24 | .crt1_reactor_o => "crt1-reactor.o", | ||
| 25 | .crt1_command_o => "crt1-command.o", | ||
| 26 | else => unreachable, | ||
| 27 | }; | ||
| 28 | } | ||
| 29 | |||
| 30 | /// TODO replace anyerror with explicit error set, recording user-friendly errors with | ||
| 31 | /// lockAndSetMiscFailure and returning error.AlreadyReported. see libcxx.zig for example. | ||
| 32 | pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progress.Node) anyerror!void { | ||
| 33 | if (!build_options.have_llvm) { | ||
| 34 | return error.ZigCompilerNotBuiltWithLLVMExtensions; | ||
| 35 | } | ||
| 36 | |||
| 37 | const gpa = comp.gpa; | ||
| 38 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); | ||
| 39 | defer arena_allocator.deinit(); | ||
| 40 | const arena = arena_allocator.allocator(); | ||
| 41 | |||
| 42 | switch (crt_file) { | ||
| 43 | .crt1_reactor_o => { | ||
| 44 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 45 | try addCCArgs(comp, arena, &args, .{}); | ||
| 46 | try addLibcBottomHalfIncludes(comp, arena, &args); | ||
| 47 | |||
| 48 | var files = [_]Compilation.CSourceFile{ | ||
| 49 | .{ | ||
| 50 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 51 | "libc", try sanitize(arena, crt1_reactor_src_file), | ||
| 52 | }), | ||
| 53 | .extra_flags = args.items, | ||
| 54 | .owner = undefined, | ||
| 55 | }, | ||
| 56 | }; | ||
| 57 | |||
| 58 | return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files, .{}); | ||
| 59 | }, | ||
| 60 | .crt1_command_o => { | ||
| 61 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 62 | try addCCArgs(comp, arena, &args, .{}); | ||
| 63 | try addLibcBottomHalfIncludes(comp, arena, &args); | ||
| 64 | |||
| 65 | var files = [_]Compilation.CSourceFile{ | ||
| 66 | .{ | ||
| 67 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 68 | "libc", try sanitize(arena, crt1_command_src_file), | ||
| 69 | }), | ||
| 70 | .extra_flags = args.items, | ||
| 71 | .owner = undefined, | ||
| 72 | }, | ||
| 73 | }; | ||
| 74 | |||
| 75 | return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files, .{}); | ||
| 76 | }, | ||
| 77 | .libc_a => { | ||
| 78 | var libc_sources = std.array_list.Managed(Compilation.CSourceFile).init(arena); | ||
| 79 | |||
| 80 | { | ||
| 81 | // Compile libc-bottom-half. | ||
| 82 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 83 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 84 | try addLibcBottomHalfIncludes(comp, arena, &args); | ||
| 85 | |||
| 86 | for (libc_bottom_half_src_files) |file_path| { | ||
| 87 | try libc_sources.append(.{ | ||
| 88 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 89 | "libc", try sanitize(arena, file_path), | ||
| 90 | }), | ||
| 91 | .extra_flags = args.items, | ||
| 92 | .owner = undefined, | ||
| 93 | }); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 97 | { | ||
| 98 | // Compile libc-top-half. | ||
| 99 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 100 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 101 | try addLibcTopHalfIncludes(comp, arena, &args); | ||
| 102 | |||
| 103 | for (libc_top_half_src_files) |file_path| { | ||
| 104 | try libc_sources.append(.{ | ||
| 105 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 106 | "libc", try sanitize(arena, file_path), | ||
| 107 | }), | ||
| 108 | .extra_flags = args.items, | ||
| 109 | .owner = undefined, | ||
| 110 | }); | ||
| 111 | } | ||
| 112 | } | ||
| 113 | |||
| 114 | { | ||
| 115 | // Compile musl-fts. | ||
| 116 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 117 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 118 | try args.appendSlice(&[_][]const u8{ | ||
| 119 | "-I", | ||
| 120 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 121 | "libc", | ||
| 122 | "wasi", | ||
| 123 | "fts", | ||
| 124 | }), | ||
| 125 | }); | ||
| 126 | |||
| 127 | for (fts_src_files) |file_path| { | ||
| 128 | try libc_sources.append(.{ | ||
| 129 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 130 | "libc", try sanitize(arena, file_path), | ||
| 131 | }), | ||
| 132 | .extra_flags = args.items, | ||
| 133 | .owner = undefined, | ||
| 134 | }); | ||
| 135 | } | ||
| 136 | } | ||
| 137 | |||
| 138 | if (comp.getTarget().cpu.has(.wasm, .exception_handling)) { | ||
| 139 | // Compile libsetjmp. | ||
| 140 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 141 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 142 | try addLibcTopHalfIncludes(comp, arena, &args); | ||
| 143 | |||
| 144 | for (setjmp_src_files) |file_path| { | ||
| 145 | try libc_sources.append(.{ | ||
| 146 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 147 | "libc", try sanitize(arena, file_path), | ||
| 148 | }), | ||
| 149 | .extra_flags = args.items, | ||
| 150 | .owner = undefined, | ||
| 151 | }); | ||
| 152 | } | ||
| 153 | } | ||
| 154 | |||
| 155 | { | ||
| 156 | // Compile libdl. | ||
| 157 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 158 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 159 | try addLibcTopHalfIncludes(comp, arena, &args); | ||
| 160 | |||
| 161 | for (emulated_dl_src_files) |file_path| { | ||
| 162 | try libc_sources.append(.{ | ||
| 163 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 164 | "libc", try sanitize(arena, file_path), | ||
| 165 | }), | ||
| 166 | .extra_flags = args.items, | ||
| 167 | .owner = undefined, | ||
| 168 | }); | ||
| 169 | } | ||
| 170 | } | ||
| 171 | |||
| 172 | { | ||
| 173 | // Compile libwasi-emulated-process-clocks. | ||
| 174 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 175 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 176 | |||
| 177 | for (emulated_process_clocks_src_files) |file_path| { | ||
| 178 | try libc_sources.append(.{ | ||
| 179 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 180 | "libc", try sanitize(arena, file_path), | ||
| 181 | }), | ||
| 182 | .extra_flags = args.items, | ||
| 183 | .owner = undefined, | ||
| 184 | }); | ||
| 185 | } | ||
| 186 | } | ||
| 187 | |||
| 188 | { | ||
| 189 | // Compile libwasi-emulated-getpid. | ||
| 190 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 191 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 192 | |||
| 193 | for (emulated_getpid_src_files) |file_path| { | ||
| 194 | try libc_sources.append(.{ | ||
| 195 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 196 | "libc", try sanitize(arena, file_path), | ||
| 197 | }), | ||
| 198 | .extra_flags = args.items, | ||
| 199 | .owner = undefined, | ||
| 200 | }); | ||
| 201 | } | ||
| 202 | } | ||
| 203 | |||
| 204 | { | ||
| 205 | // Compile libwasi-emulated-mman. | ||
| 206 | var args = std.array_list.Managed([]const u8).init(arena); | ||
| 207 | try addCCArgs(comp, arena, &args, .{ .want_O3 = true }); | ||
| 208 | |||
| 209 | for (emulated_mman_src_files) |file_path| { | ||
| 210 | try libc_sources.append(.{ | ||
| 211 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 212 | "libc", try sanitize(arena, file_path), | ||
| 213 | }), | ||
| 214 | .extra_flags = args.items, | ||
| 215 | .owner = undefined, | ||
| 216 | }); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | { | ||
| 221 | // Compile libwasi-emulated-signal. | ||
| 222 | var bottom_args = std.array_list.Managed([]const u8).init(arena); | ||
| 223 | try addCCArgs(comp, arena, &bottom_args, .{ .want_O3 = true }); | ||
| 224 | |||
| 225 | for (emulated_signal_bottom_half_src_files) |file_path| { | ||
| 226 | try libc_sources.append(.{ | ||
| 227 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 228 | "libc", try sanitize(arena, file_path), | ||
| 229 | }), | ||
| 230 | .extra_flags = bottom_args.items, | ||
| 231 | .owner = undefined, | ||
| 232 | }); | ||
| 233 | } | ||
| 234 | |||
| 235 | var top_args = std.array_list.Managed([]const u8).init(arena); | ||
| 236 | try addCCArgs(comp, arena, &top_args, .{ .want_O3 = true }); | ||
| 237 | try addLibcTopHalfIncludes(comp, arena, &top_args); | ||
| 238 | try top_args.append("-D_WASI_EMULATED_SIGNAL"); | ||
| 239 | |||
| 240 | for (emulated_signal_top_half_src_files) |file_path| { | ||
| 241 | try libc_sources.append(.{ | ||
| 242 | .src_path = try comp.dirs.zig_lib.join(arena, &.{ | ||
| 243 | "libc", try sanitize(arena, file_path), | ||
| 244 | }), | ||
| 245 | .extra_flags = top_args.items, | ||
| 246 | .owner = undefined, | ||
| 247 | }); | ||
| 248 | } | ||
| 249 | } | ||
| 250 | |||
| 251 | try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{}); | ||
| 252 | }, | ||
| 253 | } | ||
| 254 | } | ||
| 255 | |||
| 256 | fn sanitize(arena: Allocator, file_path: []const u8) ![]const u8 { | ||
| 257 | // TODO do this at comptime on the comptime data rather than at runtime | ||
| 258 | // probably best to wait until self-hosted is done and our comptime execution | ||
| 259 | // is faster and uses less memory. | ||
| 260 | const out_path = if (path.sep != '/') blk: { | ||
| 261 | const mutable_file_path = try arena.dupe(u8, file_path); | ||
| 262 | for (mutable_file_path) |*c| { | ||
| 263 | if (c.* == '/') { | ||
| 264 | c.* = path.sep; | ||
| 265 | } | ||
| 266 | } | ||
| 267 | break :blk mutable_file_path; | ||
| 268 | } else file_path; | ||
| 269 | return out_path; | ||
| 270 | } | ||
| 271 | |||
| 272 | const CCOptions = struct { | ||
| 273 | want_O3: bool = false, | ||
| 274 | no_strict_aliasing: bool = false, | ||
| 275 | }; | ||
| 276 | |||
| 277 | fn addCCArgs( | ||
| 278 | comp: *Compilation, | ||
| 279 | arena: Allocator, | ||
| 280 | args: *std.array_list.Managed([]const u8), | ||
| 281 | options: CCOptions, | ||
| 282 | ) error{OutOfMemory}!void { | ||
| 283 | const target = comp.getTarget(); | ||
| 284 | const arch_name = std.zig.target.muslArchNameHeaders(target.cpu.arch); | ||
| 285 | const os_name = @tagName(target.os.tag); | ||
| 286 | const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name }); | ||
| 287 | const o_arg = if (options.want_O3) "-O3" else "-Os"; | ||
| 288 | |||
| 289 | try args.appendSlice(&[_][]const u8{ | ||
| 290 | "-std=gnu17", | ||
| 291 | "-fno-trapping-math", | ||
| 292 | "-w", // ignore all warnings | ||
| 293 | |||
| 294 | o_arg, | ||
| 295 | |||
| 296 | "-mthread-model", | ||
| 297 | "single", | ||
| 298 | |||
| 299 | "-I", | ||
| 300 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 301 | "libc", | ||
| 302 | "wasi", | ||
| 303 | "libc-bottom-half", | ||
| 304 | "cloudlibc", | ||
| 305 | "src", | ||
| 306 | }), | ||
| 307 | |||
| 308 | "-isystem", | ||
| 309 | try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", triple }), | ||
| 310 | "-isystem", | ||
| 311 | try comp.dirs.zig_lib.join(arena, &.{ "libc", "include", "generic-musl" }), | ||
| 312 | |||
| 313 | "-DBULK_MEMORY_THRESHOLD=32", | ||
| 314 | }); | ||
| 315 | |||
| 316 | if (options.no_strict_aliasing) { | ||
| 317 | try args.appendSlice(&[_][]const u8{"-fno-strict-aliasing"}); | ||
| 318 | } | ||
| 319 | } | ||
| 320 | |||
| 321 | fn addLibcBottomHalfIncludes( | ||
| 322 | comp: *Compilation, | ||
| 323 | arena: Allocator, | ||
| 324 | args: *std.array_list.Managed([]const u8), | ||
| 325 | ) error{OutOfMemory}!void { | ||
| 326 | try args.appendSlice(&[_][]const u8{ | ||
| 327 | "-I", | ||
| 328 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 329 | "libc", | ||
| 330 | "wasi", | ||
| 331 | "libc-bottom-half", | ||
| 332 | "headers", | ||
| 333 | "private", | ||
| 334 | }), | ||
| 335 | |||
| 336 | "-I", | ||
| 337 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 338 | "libc", | ||
| 339 | "wasi", | ||
| 340 | "libc-bottom-half", | ||
| 341 | "cloudlibc", | ||
| 342 | "src", | ||
| 343 | "include", | ||
| 344 | }), | ||
| 345 | |||
| 346 | "-I", | ||
| 347 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 348 | "libc", | ||
| 349 | "wasi", | ||
| 350 | "libc-bottom-half", | ||
| 351 | "cloudlibc", | ||
| 352 | "src", | ||
| 353 | }), | ||
| 354 | |||
| 355 | "-I", | ||
| 356 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 357 | "libc", | ||
| 358 | "wasi", | ||
| 359 | "libc-top-half", | ||
| 360 | "musl", | ||
| 361 | "src", | ||
| 362 | "include", | ||
| 363 | }), | ||
| 364 | "-I", | ||
| 365 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 366 | "libc", | ||
| 367 | "musl", | ||
| 368 | "src", | ||
| 369 | "include", | ||
| 370 | }), | ||
| 371 | "-I", | ||
| 372 | |||
| 373 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 374 | "libc", | ||
| 375 | "wasi", | ||
| 376 | "libc-top-half", | ||
| 377 | "musl", | ||
| 378 | "src", | ||
| 379 | "internal", | ||
| 380 | }), | ||
| 381 | "-I", | ||
| 382 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 383 | "libc", | ||
| 384 | "musl", | ||
| 385 | "src", | ||
| 386 | "internal", | ||
| 387 | }), | ||
| 388 | }); | ||
| 389 | } | ||
| 390 | |||
| 391 | fn addLibcTopHalfIncludes( | ||
| 392 | comp: *Compilation, | ||
| 393 | arena: Allocator, | ||
| 394 | args: *std.array_list.Managed([]const u8), | ||
| 395 | ) error{OutOfMemory}!void { | ||
| 396 | try args.appendSlice(&[_][]const u8{ | ||
| 397 | "-I", | ||
| 398 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 399 | "libc", | ||
| 400 | "wasi", | ||
| 401 | "libc-top-half", | ||
| 402 | "musl", | ||
| 403 | "src", | ||
| 404 | "include", | ||
| 405 | }), | ||
| 406 | "-I", | ||
| 407 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 408 | "libc", | ||
| 409 | "musl", | ||
| 410 | "src", | ||
| 411 | "include", | ||
| 412 | }), | ||
| 413 | |||
| 414 | "-I", | ||
| 415 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 416 | "libc", | ||
| 417 | "wasi", | ||
| 418 | "libc-top-half", | ||
| 419 | "musl", | ||
| 420 | "src", | ||
| 421 | "internal", | ||
| 422 | }), | ||
| 423 | "-I", | ||
| 424 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 425 | "libc", | ||
| 426 | "musl", | ||
| 427 | "src", | ||
| 428 | "internal", | ||
| 429 | }), | ||
| 430 | |||
| 431 | "-I", | ||
| 432 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 433 | "libc", | ||
| 434 | "wasi", | ||
| 435 | "libc-top-half", | ||
| 436 | "musl", | ||
| 437 | "arch", | ||
| 438 | "wasm32", | ||
| 439 | }), | ||
| 440 | "-I", | ||
| 441 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 442 | "libc", | ||
| 443 | "musl", | ||
| 444 | "arch", | ||
| 445 | "generic", | ||
| 446 | }), | ||
| 447 | |||
| 448 | "-I", | ||
| 449 | try comp.dirs.zig_lib.join(arena, &.{ | ||
| 450 | "libc", | ||
| 451 | "wasi", | ||
| 452 | "libc-top-half", | ||
| 453 | "headers", | ||
| 454 | "private", | ||
| 455 | }), | ||
| 456 | }); | ||
| 457 | } | ||
| 458 | |||
| 459 | const libc_bottom_half_src_files = [_][]const u8{ | ||
| 460 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c", | ||
| 461 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c", | ||
| 462 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c", | ||
| 463 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c", | ||
| 464 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c", | ||
| 465 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c", | ||
| 466 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c", | ||
| 467 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c", | ||
| 468 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c", | ||
| 469 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c", | ||
| 470 | "wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c", | ||
| 471 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c", | ||
| 472 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c", | ||
| 473 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c", | ||
| 474 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c", | ||
| 475 | "wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c", | ||
| 476 | "wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c", | ||
| 477 | "wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c", | ||
| 478 | "wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c", | ||
| 479 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c", | ||
| 480 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c", | ||
| 481 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c", | ||
| 482 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c", | ||
| 483 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c", | ||
| 484 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c", | ||
| 485 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c", | ||
| 486 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c", | ||
| 487 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c", | ||
| 488 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c", | ||
| 489 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c", | ||
| 490 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c", | ||
| 491 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c", | ||
| 492 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c", | ||
| 493 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c", | ||
| 494 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c", | ||
| 495 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c", | ||
| 496 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c", | ||
| 497 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c", | ||
| 498 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c", | ||
| 499 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c", | ||
| 500 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c", | ||
| 501 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c", | ||
| 502 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c", | ||
| 503 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c", | ||
| 504 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c", | ||
| 505 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c", | ||
| 506 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c", | ||
| 507 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c", | ||
| 508 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c", | ||
| 509 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c", | ||
| 510 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c", | ||
| 511 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c", | ||
| 512 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c", | ||
| 513 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c", | ||
| 514 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c", | ||
| 515 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c", | ||
| 516 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c", | ||
| 517 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c", | ||
| 518 | "wasi/libc-bottom-half/sources/abort.c", | ||
| 519 | "wasi/libc-bottom-half/sources/accept-wasip1.c", | ||
| 520 | "wasi/libc-bottom-half/sources/at_fdcwd.c", | ||
| 521 | "wasi/libc-bottom-half/sources/chdir.c", | ||
| 522 | "wasi/libc-bottom-half/sources/complex-builtins.c", | ||
| 523 | "wasi/libc-bottom-half/sources/environ.c", | ||
| 524 | "wasi/libc-bottom-half/sources/errno.c", | ||
| 525 | "wasi/libc-bottom-half/sources/__errno_location.c", | ||
| 526 | "wasi/libc-bottom-half/sources/getcwd.c", | ||
| 527 | "wasi/libc-bottom-half/sources/getentropy.c", | ||
| 528 | "wasi/libc-bottom-half/sources/isatty.c", | ||
| 529 | "wasi/libc-bottom-half/sources/__main_void.c", | ||
| 530 | "wasi/libc-bottom-half/sources/math/math-builtins.c", | ||
| 531 | "wasi/libc-bottom-half/sources/posix.c", | ||
| 532 | "wasi/libc-bottom-half/sources/preopens.c", | ||
| 533 | "wasi/libc-bottom-half/sources/sbrk.c", | ||
| 534 | "wasi/libc-bottom-half/sources/truncate.c", | ||
| 535 | "wasi/libc-bottom-half/sources/__wasilibc_dt.c", | ||
| 536 | "wasi/libc-bottom-half/sources/__wasilibc_environ.c", | ||
| 537 | "wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c", | ||
| 538 | "wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c", | ||
| 539 | "wasi/libc-bottom-half/sources/__wasilibc_random.c", | ||
| 540 | "wasi/libc-bottom-half/sources/__wasilibc_real.c", | ||
| 541 | "wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c", | ||
| 542 | "wasi/libc-bottom-half/sources/__wasilibc_tell.c", | ||
| 543 | "wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c", | ||
| 544 | }; | ||
| 545 | |||
| 546 | const libc_top_half_src_files = [_][]const u8{ | ||
| 547 | "musl/src/complex/cabs.c", | ||
| 548 | "musl/src/complex/cabsf.c", | ||
| 549 | "musl/src/complex/cabsl.c", | ||
| 550 | "musl/src/complex/cacos.c", | ||
| 551 | "musl/src/complex/cacosf.c", | ||
| 552 | "musl/src/complex/cacosh.c", | ||
| 553 | "musl/src/complex/cacoshf.c", | ||
| 554 | "musl/src/complex/cacoshl.c", | ||
| 555 | "musl/src/complex/cacosl.c", | ||
| 556 | "musl/src/complex/carg.c", | ||
| 557 | "musl/src/complex/cargf.c", | ||
| 558 | "musl/src/complex/cargl.c", | ||
| 559 | "musl/src/complex/casin.c", | ||
| 560 | "musl/src/complex/casinf.c", | ||
| 561 | "musl/src/complex/casinh.c", | ||
| 562 | "musl/src/complex/casinhf.c", | ||
| 563 | "musl/src/complex/casinhl.c", | ||
| 564 | "musl/src/complex/casinl.c", | ||
| 565 | "musl/src/complex/catan.c", | ||
| 566 | "musl/src/complex/catanf.c", | ||
| 567 | "musl/src/complex/catanh.c", | ||
| 568 | "musl/src/complex/catanhf.c", | ||
| 569 | "musl/src/complex/catanhl.c", | ||
| 570 | "musl/src/complex/catanl.c", | ||
| 571 | "musl/src/complex/ccos.c", | ||
| 572 | "musl/src/complex/ccosf.c", | ||
| 573 | "musl/src/complex/ccosh.c", | ||
| 574 | "musl/src/complex/ccoshf.c", | ||
| 575 | "musl/src/complex/ccoshl.c", | ||
| 576 | "musl/src/complex/ccosl.c", | ||
| 577 | "musl/src/complex/__cexp.c", | ||
| 578 | "musl/src/complex/cexp.c", | ||
| 579 | "musl/src/complex/__cexpf.c", | ||
| 580 | "musl/src/complex/cexpf.c", | ||
| 581 | "musl/src/complex/cexpl.c", | ||
| 582 | "musl/src/complex/clog.c", | ||
| 583 | "musl/src/complex/clogf.c", | ||
| 584 | "musl/src/complex/clogl.c", | ||
| 585 | "musl/src/complex/conj.c", | ||
| 586 | "musl/src/complex/conjf.c", | ||
| 587 | "musl/src/complex/conjl.c", | ||
| 588 | "musl/src/complex/cpow.c", | ||
| 589 | "musl/src/complex/cpowf.c", | ||
| 590 | "musl/src/complex/cpowl.c", | ||
| 591 | "musl/src/complex/cproj.c", | ||
| 592 | "musl/src/complex/cprojf.c", | ||
| 593 | "musl/src/complex/cprojl.c", | ||
| 594 | "musl/src/complex/csin.c", | ||
| 595 | "musl/src/complex/csinf.c", | ||
| 596 | "musl/src/complex/csinh.c", | ||
| 597 | "musl/src/complex/csinhf.c", | ||
| 598 | "musl/src/complex/csinhl.c", | ||
| 599 | "musl/src/complex/csinl.c", | ||
| 600 | "musl/src/complex/csqrt.c", | ||
| 601 | "musl/src/complex/csqrtf.c", | ||
| 602 | "musl/src/complex/csqrtl.c", | ||
| 603 | "musl/src/complex/ctan.c", | ||
| 604 | "musl/src/complex/ctanf.c", | ||
| 605 | "musl/src/complex/ctanh.c", | ||
| 606 | "musl/src/complex/ctanhf.c", | ||
| 607 | "musl/src/complex/ctanhl.c", | ||
| 608 | "musl/src/complex/ctanl.c", | ||
| 609 | "musl/src/conf/confstr.c", | ||
| 610 | "musl/src/conf/legacy.c", | ||
| 611 | "musl/src/conf/pathconf.c", | ||
| 612 | "musl/src/crypt/crypt_blowfish.c", | ||
| 613 | "musl/src/crypt/crypt.c", | ||
| 614 | "musl/src/crypt/crypt_des.c", | ||
| 615 | "musl/src/crypt/crypt_md5.c", | ||
| 616 | "musl/src/crypt/crypt_r.c", | ||
| 617 | "musl/src/crypt/crypt_sha256.c", | ||
| 618 | "musl/src/crypt/crypt_sha512.c", | ||
| 619 | "musl/src/crypt/encrypt.c", | ||
| 620 | "musl/src/ctype/__ctype_b_loc.c", | ||
| 621 | "musl/src/ctype/__ctype_get_mb_cur_max.c", | ||
| 622 | "musl/src/ctype/__ctype_tolower_loc.c", | ||
| 623 | "musl/src/ctype/__ctype_toupper_loc.c", | ||
| 624 | "musl/src/ctype/iswalnum.c", | ||
| 625 | "musl/src/ctype/iswalpha.c", | ||
| 626 | "musl/src/ctype/iswblank.c", | ||
| 627 | "musl/src/ctype/iswcntrl.c", | ||
| 628 | "musl/src/ctype/iswctype.c", | ||
| 629 | "musl/src/ctype/iswdigit.c", | ||
| 630 | "musl/src/ctype/iswgraph.c", | ||
| 631 | "musl/src/ctype/iswlower.c", | ||
| 632 | "musl/src/ctype/iswprint.c", | ||
| 633 | "musl/src/ctype/iswpunct.c", | ||
| 634 | "musl/src/ctype/iswspace.c", | ||
| 635 | "musl/src/ctype/iswupper.c", | ||
| 636 | "musl/src/ctype/iswxdigit.c", | ||
| 637 | "musl/src/ctype/towctrans.c", | ||
| 638 | "musl/src/ctype/wcswidth.c", | ||
| 639 | "musl/src/ctype/wctrans.c", | ||
| 640 | "musl/src/ctype/wcwidth.c", | ||
| 641 | "musl/src/env/setenv.c", | ||
| 642 | "musl/src/exit/assert.c", | ||
| 643 | "musl/src/exit/quick_exit.c", | ||
| 644 | "musl/src/fenv/fegetexceptflag.c", | ||
| 645 | "musl/src/fenv/feholdexcept.c", | ||
| 646 | "musl/src/fenv/fenv.c", | ||
| 647 | "musl/src/fenv/fesetexceptflag.c", | ||
| 648 | "musl/src/fenv/fesetround.c", | ||
| 649 | "musl/src/fenv/feupdateenv.c", | ||
| 650 | "musl/src/legacy/getpagesize.c", | ||
| 651 | "musl/src/locale/c_locale.c", | ||
| 652 | "musl/src/locale/duplocale.c", | ||
| 653 | "musl/src/locale/freelocale.c", | ||
| 654 | "musl/src/locale/iconv.c", | ||
| 655 | "musl/src/locale/iconv_close.c", | ||
| 656 | "musl/src/locale/langinfo.c", | ||
| 657 | "musl/src/locale/__lctrans.c", | ||
| 658 | "musl/src/locale/localeconv.c", | ||
| 659 | "musl/src/locale/__mo_lookup.c", | ||
| 660 | "musl/src/locale/pleval.c", | ||
| 661 | "musl/src/locale/setlocale.c", | ||
| 662 | "musl/src/locale/strfmon.c", | ||
| 663 | "musl/src/locale/strtod_l.c", | ||
| 664 | "musl/src/locale/wcscoll.c", | ||
| 665 | "musl/src/locale/wcsxfrm.c", | ||
| 666 | "musl/src/math/acosh.c", | ||
| 667 | "musl/src/math/acoshl.c", | ||
| 668 | "musl/src/math/acosl.c", | ||
| 669 | "musl/src/math/asinf.c", | ||
| 670 | "musl/src/math/asinh.c", | ||
| 671 | "musl/src/math/asinhf.c", | ||
| 672 | "musl/src/math/asinhl.c", | ||
| 673 | "musl/src/math/asinl.c", | ||
| 674 | "musl/src/math/atan2.c", | ||
| 675 | "musl/src/math/atan2f.c", | ||
| 676 | "musl/src/math/atan2l.c", | ||
| 677 | "musl/src/math/atanh.c", | ||
| 678 | "musl/src/math/atanhf.c", | ||
| 679 | "musl/src/math/atanhl.c", | ||
| 680 | "musl/src/math/cbrtl.c", | ||
| 681 | "musl/src/math/__cos.c", | ||
| 682 | "musl/src/math/__cosdf.c", | ||
| 683 | "musl/src/math/coshl.c", | ||
| 684 | "musl/src/math/erf.c", | ||
| 685 | "musl/src/math/erff.c", | ||
| 686 | "musl/src/math/erfl.c", | ||
| 687 | "musl/src/math/exp10l.c", | ||
| 688 | "musl/src/math/exp2f_data.c", | ||
| 689 | "musl/src/math/exp2l.c", | ||
| 690 | "musl/src/math/exp_data.c", | ||
| 691 | "musl/src/math/expl.c", | ||
| 692 | "musl/src/math/expm1.c", | ||
| 693 | "musl/src/math/expm1f.c", | ||
| 694 | "musl/src/math/expm1l.c", | ||
| 695 | "musl/src/math/fma.c", | ||
| 696 | "musl/src/math/fmaf.c", | ||
| 697 | "musl/src/math/ilogb.c", | ||
| 698 | "musl/src/math/ilogbf.c", | ||
| 699 | "musl/src/math/ilogbl.c", | ||
| 700 | "musl/src/math/__invtrigl.c", | ||
| 701 | "musl/src/math/j0.c", | ||
| 702 | "musl/src/math/j0f.c", | ||
| 703 | "musl/src/math/j1.c", | ||
| 704 | "musl/src/math/j1f.c", | ||
| 705 | "musl/src/math/jn.c", | ||
| 706 | "musl/src/math/jnf.c", | ||
| 707 | "musl/src/math/ldexp.c", | ||
| 708 | "musl/src/math/ldexpf.c", | ||
| 709 | "musl/src/math/ldexpl.c", | ||
| 710 | "musl/src/math/lgamma.c", | ||
| 711 | "musl/src/math/lgammaf.c", | ||
| 712 | "musl/src/math/lgammaf_r.c", | ||
| 713 | "musl/src/math/lgammal.c", | ||
| 714 | "musl/src/math/lgamma_r.c", | ||
| 715 | "musl/src/math/llrint.c", | ||
| 716 | "musl/src/math/llrintf.c", | ||
| 717 | "musl/src/math/llrintl.c", | ||
| 718 | "musl/src/math/llround.c", | ||
| 719 | "musl/src/math/llroundf.c", | ||
| 720 | "musl/src/math/llroundl.c", | ||
| 721 | "musl/src/math/log10l.c", | ||
| 722 | "musl/src/math/log1pl.c", | ||
| 723 | "musl/src/math/log2l.c", | ||
| 724 | "musl/src/math/logb.c", | ||
| 725 | "musl/src/math/logbf.c", | ||
| 726 | "musl/src/math/logbl.c", | ||
| 727 | "musl/src/math/logl.c", | ||
| 728 | "musl/src/math/__math_divzero.c", | ||
| 729 | "musl/src/math/__math_divzerof.c", | ||
| 730 | "musl/src/math/__math_invalid.c", | ||
| 731 | "musl/src/math/__math_invalidf.c", | ||
| 732 | "musl/src/math/__math_invalidl.c", | ||
| 733 | "musl/src/math/__math_oflow.c", | ||
| 734 | "musl/src/math/__math_oflowf.c", | ||
| 735 | "musl/src/math/__math_uflow.c", | ||
| 736 | "musl/src/math/__math_uflowf.c", | ||
| 737 | "musl/src/math/__math_xflow.c", | ||
| 738 | "musl/src/math/__math_xflowf.c", | ||
| 739 | "musl/src/math/nearbyintl.c", | ||
| 740 | "musl/src/math/nextafter.c", | ||
| 741 | "musl/src/math/nextafterf.c", | ||
| 742 | "musl/src/math/nextafterl.c", | ||
| 743 | "musl/src/math/nexttoward.c", | ||
| 744 | "musl/src/math/nexttowardf.c", | ||
| 745 | "musl/src/math/nexttowardl.c", | ||
| 746 | "musl/src/math/__polevll.c", | ||
| 747 | "musl/src/math/pow.c", | ||
| 748 | "musl/src/math/pow_data.c", | ||
| 749 | "musl/src/math/powf.c", | ||
| 750 | "musl/src/math/powf_data.c", | ||
| 751 | "musl/src/math/remainder.c", | ||
| 752 | "musl/src/math/remainderf.c", | ||
| 753 | "musl/src/math/remainderl.c", | ||
| 754 | "musl/src/math/__rem_pio2_large.c", | ||
| 755 | "musl/src/math/remquo.c", | ||
| 756 | "musl/src/math/remquof.c", | ||
| 757 | "musl/src/math/remquol.c", | ||
| 758 | "musl/src/math/scalb.c", | ||
| 759 | "musl/src/math/scalbf.c", | ||
| 760 | "musl/src/math/scalbln.c", | ||
| 761 | "musl/src/math/scalblnf.c", | ||
| 762 | "musl/src/math/scalblnl.c", | ||
| 763 | "musl/src/math/scalbn.c", | ||
| 764 | "musl/src/math/scalbnf.c", | ||
| 765 | "musl/src/math/scalbnl.c", | ||
| 766 | "musl/src/math/signgam.c", | ||
| 767 | "musl/src/math/significand.c", | ||
| 768 | "musl/src/math/significandf.c", | ||
| 769 | "musl/src/math/__sin.c", | ||
| 770 | "musl/src/math/__sindf.c", | ||
| 771 | "musl/src/math/sinhl.c", | ||
| 772 | "musl/src/math/__tan.c", | ||
| 773 | "musl/src/math/__tandf.c", | ||
| 774 | "musl/src/math/tanhl.c", | ||
| 775 | "musl/src/math/tgamma.c", | ||
| 776 | "musl/src/math/tgammaf.c", | ||
| 777 | "musl/src/math/tgammal.c", | ||
| 778 | "musl/src/misc/a64l.c", | ||
| 779 | "musl/src/misc/basename.c", | ||
| 780 | "musl/src/misc/dirname.c", | ||
| 781 | "musl/src/misc/getdomainname.c", | ||
| 782 | "musl/src/misc/gethostid.c", | ||
| 783 | "musl/src/misc/getopt.c", | ||
| 784 | "musl/src/misc/getopt_long.c", | ||
| 785 | "musl/src/misc/getsubopt.c", | ||
| 786 | "musl/src/misc/realpath.c", | ||
| 787 | "musl/src/multibyte/btowc.c", | ||
| 788 | "musl/src/multibyte/c16rtomb.c", | ||
| 789 | "musl/src/multibyte/c32rtomb.c", | ||
| 790 | "musl/src/multibyte/internal.c", | ||
| 791 | "musl/src/multibyte/mblen.c", | ||
| 792 | "musl/src/multibyte/mbrlen.c", | ||
| 793 | "musl/src/multibyte/mbrtoc16.c", | ||
| 794 | "musl/src/multibyte/mbrtoc32.c", | ||
| 795 | "musl/src/multibyte/mbrtowc.c", | ||
| 796 | "musl/src/multibyte/mbsinit.c", | ||
| 797 | "musl/src/multibyte/mbsnrtowcs.c", | ||
| 798 | "musl/src/multibyte/mbsrtowcs.c", | ||
| 799 | "musl/src/multibyte/mbstowcs.c", | ||
| 800 | "musl/src/multibyte/mbtowc.c", | ||
| 801 | "musl/src/multibyte/wcrtomb.c", | ||
| 802 | "musl/src/multibyte/wcsnrtombs.c", | ||
| 803 | "musl/src/multibyte/wcsrtombs.c", | ||
| 804 | "musl/src/multibyte/wcstombs.c", | ||
| 805 | "musl/src/multibyte/wctob.c", | ||
| 806 | "musl/src/multibyte/wctomb.c", | ||
| 807 | "musl/src/network/htonl.c", | ||
| 808 | "musl/src/network/htons.c", | ||
| 809 | "musl/src/network/in6addr_any.c", | ||
| 810 | "musl/src/network/in6addr_loopback.c", | ||
| 811 | "musl/src/network/inet_aton.c", | ||
| 812 | "musl/src/network/inet_ntop.c", | ||
| 813 | "musl/src/network/inet_pton.c", | ||
| 814 | "musl/src/network/ntohl.c", | ||
| 815 | "musl/src/network/ntohs.c", | ||
| 816 | "musl/src/regex/fnmatch.c", | ||
| 817 | "musl/src/regex/regerror.c", | ||
| 818 | "musl/src/search/hsearch.c", | ||
| 819 | "musl/src/search/lsearch.c", | ||
| 820 | "musl/src/search/tdelete.c", | ||
| 821 | "musl/src/search/tdestroy.c", | ||
| 822 | "musl/src/search/tfind.c", | ||
| 823 | "musl/src/search/tsearch.c", | ||
| 824 | "musl/src/search/twalk.c", | ||
| 825 | "musl/src/stdio/asprintf.c", | ||
| 826 | "musl/src/stdio/clearerr.c", | ||
| 827 | "musl/src/stdio/dprintf.c", | ||
| 828 | "musl/src/stdio/ext2.c", | ||
| 829 | "musl/src/stdio/ext.c", | ||
| 830 | "musl/src/stdio/fclose.c", | ||
| 831 | "musl/src/stdio/__fclose_ca.c", | ||
| 832 | "musl/src/stdio/feof.c", | ||
| 833 | "musl/src/stdio/ferror.c", | ||
| 834 | "musl/src/stdio/fflush.c", | ||
| 835 | "musl/src/stdio/fgetln.c", | ||
| 836 | "musl/src/stdio/fgets.c", | ||
| 837 | "musl/src/stdio/fgetwc.c", | ||
| 838 | "musl/src/stdio/fgetws.c", | ||
| 839 | "musl/src/stdio/fileno.c", | ||
| 840 | "musl/src/stdio/__fmodeflags.c", | ||
| 841 | "musl/src/stdio/fopencookie.c", | ||
| 842 | "musl/src/stdio/fprintf.c", | ||
| 843 | "musl/src/stdio/fputs.c", | ||
| 844 | "musl/src/stdio/fputwc.c", | ||
| 845 | "musl/src/stdio/fputws.c", | ||
| 846 | "musl/src/stdio/fread.c", | ||
| 847 | "musl/src/stdio/fscanf.c", | ||
| 848 | "musl/src/stdio/fwide.c", | ||
| 849 | "musl/src/stdio/fwprintf.c", | ||
| 850 | "musl/src/stdio/fwrite.c", | ||
| 851 | "musl/src/stdio/fwscanf.c", | ||
| 852 | "musl/src/stdio/getchar_unlocked.c", | ||
| 853 | "musl/src/stdio/getc_unlocked.c", | ||
| 854 | "musl/src/stdio/getdelim.c", | ||
| 855 | "musl/src/stdio/getline.c", | ||
| 856 | "musl/src/stdio/getw.c", | ||
| 857 | "musl/src/stdio/getwc.c", | ||
| 858 | "musl/src/stdio/getwchar.c", | ||
| 859 | "musl/src/stdio/ofl_add.c", | ||
| 860 | "musl/src/stdio/__overflow.c", | ||
| 861 | "musl/src/stdio/perror.c", | ||
| 862 | "musl/src/stdio/putchar_unlocked.c", | ||
| 863 | "musl/src/stdio/putc_unlocked.c", | ||
| 864 | "musl/src/stdio/puts.c", | ||
| 865 | "musl/src/stdio/putw.c", | ||
| 866 | "musl/src/stdio/putwc.c", | ||
| 867 | "musl/src/stdio/putwchar.c", | ||
| 868 | "musl/src/stdio/rewind.c", | ||
| 869 | "musl/src/stdio/scanf.c", | ||
| 870 | "musl/src/stdio/setbuf.c", | ||
| 871 | "musl/src/stdio/setbuffer.c", | ||
| 872 | "musl/src/stdio/setlinebuf.c", | ||
| 873 | "musl/src/stdio/setvbuf.c", | ||
| 874 | "musl/src/stdio/snprintf.c", | ||
| 875 | "musl/src/stdio/sprintf.c", | ||
| 876 | "musl/src/stdio/sscanf.c", | ||
| 877 | "musl/src/stdio/__stdio_exit.c", | ||
| 878 | "musl/src/stdio/swprintf.c", | ||
| 879 | "musl/src/stdio/swscanf.c", | ||
| 880 | "musl/src/stdio/__toread.c", | ||
| 881 | "musl/src/stdio/__towrite.c", | ||
| 882 | "musl/src/stdio/__uflow.c", | ||
| 883 | "musl/src/stdio/ungetc.c", | ||
| 884 | "musl/src/stdio/ungetwc.c", | ||
| 885 | "musl/src/stdio/vasprintf.c", | ||
| 886 | "musl/src/stdio/vfwscanf.c", | ||
| 887 | "musl/src/stdio/vprintf.c", | ||
| 888 | "musl/src/stdio/vscanf.c", | ||
| 889 | "musl/src/stdio/vsprintf.c", | ||
| 890 | "musl/src/stdio/vwprintf.c", | ||
| 891 | "musl/src/stdio/vwscanf.c", | ||
| 892 | "musl/src/stdio/wprintf.c", | ||
| 893 | "musl/src/stdio/wscanf.c", | ||
| 894 | "musl/src/stdlib/atof.c", | ||
| 895 | "musl/src/stdlib/ecvt.c", | ||
| 896 | "musl/src/stdlib/fcvt.c", | ||
| 897 | "musl/src/stdlib/gcvt.c", | ||
| 898 | "musl/src/string/strerror_r.c", | ||
| 899 | "musl/src/string/strverscmp.c", | ||
| 900 | "musl/src/string/wcscasecmp.c", | ||
| 901 | "musl/src/string/wcscasecmp_l.c", | ||
| 902 | "musl/src/string/wcsncasecmp.c", | ||
| 903 | "musl/src/string/wcsncasecmp_l.c", | ||
| 904 | "musl/src/thread/default_attr.c", | ||
| 905 | "musl/src/thread/pthread_attr_destroy.c", | ||
| 906 | "musl/src/thread/pthread_attr_init.c", | ||
| 907 | "musl/src/thread/pthread_attr_setdetachstate.c", | ||
| 908 | "musl/src/thread/pthread_attr_setstack.c", | ||
| 909 | "musl/src/thread/pthread_attr_setstacksize.c", | ||
| 910 | "musl/src/thread/pthread_barrierattr_destroy.c", | ||
| 911 | "musl/src/thread/pthread_barrierattr_init.c", | ||
| 912 | "musl/src/thread/pthread_barrierattr_setpshared.c", | ||
| 913 | "musl/src/thread/pthread_cleanup_push.c", | ||
| 914 | "musl/src/thread/pthread_condattr_destroy.c", | ||
| 915 | "musl/src/thread/pthread_condattr_init.c", | ||
| 916 | "musl/src/thread/pthread_condattr_setpshared.c", | ||
| 917 | "musl/src/thread/pthread_equal.c", | ||
| 918 | "musl/src/thread/pthread_getspecific.c", | ||
| 919 | "musl/src/thread/pthread_mutexattr_destroy.c", | ||
| 920 | "musl/src/thread/pthread_mutexattr_init.c", | ||
| 921 | "musl/src/thread/pthread_mutexattr_setpshared.c", | ||
| 922 | "musl/src/thread/pthread_mutexattr_settype.c", | ||
| 923 | "musl/src/thread/pthread_mutex_init.c", | ||
| 924 | "musl/src/thread/pthread_rwlockattr_destroy.c", | ||
| 925 | "musl/src/thread/pthread_rwlockattr_init.c", | ||
| 926 | "musl/src/thread/pthread_rwlockattr_setpshared.c", | ||
| 927 | "musl/src/thread/pthread_rwlock_destroy.c", | ||
| 928 | "musl/src/thread/pthread_rwlock_init.c", | ||
| 929 | "musl/src/thread/pthread_setcancelstate.c", | ||
| 930 | "musl/src/thread/pthread_setcanceltype.c", | ||
| 931 | "musl/src/thread/pthread_setspecific.c", | ||
| 932 | "musl/src/thread/pthread_testcancel.c", | ||
| 933 | "musl/src/thread/thrd_sleep.c", | ||
| 934 | "musl/src/time/asctime.c", | ||
| 935 | "musl/src/time/asctime_r.c", | ||
| 936 | "musl/src/time/ctime.c", | ||
| 937 | "musl/src/time/ctime_r.c", | ||
| 938 | "musl/src/time/difftime.c", | ||
| 939 | "musl/src/time/ftime.c", | ||
| 940 | "musl/src/time/__month_to_secs.c", | ||
| 941 | "musl/src/time/strptime.c", | ||
| 942 | "musl/src/time/timespec_get.c", | ||
| 943 | "musl/src/time/__year_to_secs.c", | ||
| 944 | |||
| 945 | "wasi/libc-top-half/musl/src/conf/fpathconf.c", | ||
| 946 | "wasi/libc-top-half/musl/src/conf/sysconf.c", | ||
| 947 | "wasi/libc-top-half/musl/src/dirent/alphasort.c", | ||
| 948 | "wasi/libc-top-half/musl/src/dirent/versionsort.c", | ||
| 949 | "wasi/libc-top-half/musl/src/env/clearenv.c", | ||
| 950 | "wasi/libc-top-half/musl/src/env/getenv.c", | ||
| 951 | "wasi/libc-top-half/musl/src/env/putenv.c", | ||
| 952 | "wasi/libc-top-half/musl/src/env/__stack_chk_fail.c", | ||
| 953 | "wasi/libc-top-half/musl/src/env/unsetenv.c", | ||
| 954 | "wasi/libc-top-half/musl/src/errno/strerror.c", | ||
| 955 | "wasi/libc-top-half/musl/src/exit/atexit.c", | ||
| 956 | "wasi/libc-top-half/musl/src/exit/at_quick_exit.c", | ||
| 957 | "wasi/libc-top-half/musl/src/exit/exit.c", | ||
| 958 | "wasi/libc-top-half/musl/src/fcntl/creat.c", | ||
| 959 | "wasi/libc-top-half/musl/src/internal/defsysinfo.c", | ||
| 960 | "wasi/libc-top-half/musl/src/internal/floatscan.c", | ||
| 961 | "wasi/libc-top-half/musl/src/internal/intscan.c", | ||
| 962 | "wasi/libc-top-half/musl/src/internal/libc.c", | ||
| 963 | "wasi/libc-top-half/musl/src/internal/shgetc.c", | ||
| 964 | "wasi/libc-top-half/musl/src/locale/catclose.c", | ||
| 965 | "wasi/libc-top-half/musl/src/locale/catgets.c", | ||
| 966 | "wasi/libc-top-half/musl/src/locale/catopen.c", | ||
| 967 | "wasi/libc-top-half/musl/src/locale/locale_map.c", | ||
| 968 | "wasi/libc-top-half/musl/src/locale/newlocale.c", | ||
| 969 | "wasi/libc-top-half/musl/src/locale/uselocale.c", | ||
| 970 | "wasi/libc-top-half/musl/src/math/__expo2.c", | ||
| 971 | "wasi/libc-top-half/musl/src/math/__expo2f.c", | ||
| 972 | "wasi/libc-top-half/musl/src/math/fmal.c", | ||
| 973 | "wasi/libc-top-half/musl/src/math/powl.c", | ||
| 974 | "wasi/libc-top-half/musl/src/math/__rem_pio2.c", | ||
| 975 | "wasi/libc-top-half/musl/src/math/__rem_pio2f.c", | ||
| 976 | "wasi/libc-top-half/musl/src/math/__rem_pio2l.c", | ||
| 977 | "wasi/libc-top-half/musl/src/math/sinh.c", | ||
| 978 | "wasi/libc-top-half/musl/src/math/sinhf.c", | ||
| 979 | "wasi/libc-top-half/musl/src/misc/fmtmsg.c", | ||
| 980 | "wasi/libc-top-half/musl/src/misc/nftw.c", | ||
| 981 | "wasi/libc-top-half/musl/src/prng/random.c", | ||
| 982 | "wasi/libc-top-half/musl/src/regex/glob.c", | ||
| 983 | "wasi/libc-top-half/musl/src/regex/regcomp.c", | ||
| 984 | "wasi/libc-top-half/musl/src/regex/regexec.c", | ||
| 985 | "wasi/libc-top-half/musl/src/regex/tre-mem.c", | ||
| 986 | "wasi/libc-top-half/musl/src/stat/futimesat.c", | ||
| 987 | "wasi/libc-top-half/musl/src/stdio/__fdopen.c", | ||
| 988 | "wasi/libc-top-half/musl/src/stdio/fgetc.c", | ||
| 989 | "wasi/libc-top-half/musl/src/stdio/fgetpos.c", | ||
| 990 | "wasi/libc-top-half/musl/src/stdio/fmemopen.c", | ||
| 991 | "wasi/libc-top-half/musl/src/stdio/fopen.c", | ||
| 992 | "wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c", | ||
| 993 | "wasi/libc-top-half/musl/src/stdio/fputc.c", | ||
| 994 | "wasi/libc-top-half/musl/src/stdio/freopen.c", | ||
| 995 | "wasi/libc-top-half/musl/src/stdio/fseek.c", | ||
| 996 | "wasi/libc-top-half/musl/src/stdio/fsetpos.c", | ||
| 997 | "wasi/libc-top-half/musl/src/stdio/ftell.c", | ||
| 998 | "wasi/libc-top-half/musl/src/stdio/getc.c", | ||
| 999 | "wasi/libc-top-half/musl/src/stdio/getchar.c", | ||
| 1000 | "wasi/libc-top-half/musl/src/stdio/ofl.c", | ||
| 1001 | "wasi/libc-top-half/musl/src/stdio/open_memstream.c", | ||
| 1002 | "wasi/libc-top-half/musl/src/stdio/open_wmemstream.c", | ||
| 1003 | "wasi/libc-top-half/musl/src/stdio/printf.c", | ||
| 1004 | "wasi/libc-top-half/musl/src/stdio/putc.c", | ||
| 1005 | "wasi/libc-top-half/musl/src/stdio/putchar.c", | ||
| 1006 | "wasi/libc-top-half/musl/src/stdio/stderr.c", | ||
| 1007 | "wasi/libc-top-half/musl/src/stdio/stdin.c", | ||
| 1008 | "wasi/libc-top-half/musl/src/stdio/__stdio_close.c", | ||
| 1009 | "wasi/libc-top-half/musl/src/stdio/__stdio_read.c", | ||
| 1010 | "wasi/libc-top-half/musl/src/stdio/__stdio_seek.c", | ||
| 1011 | "wasi/libc-top-half/musl/src/stdio/__stdio_write.c", | ||
| 1012 | "wasi/libc-top-half/musl/src/stdio/stdout.c", | ||
| 1013 | "wasi/libc-top-half/musl/src/stdio/__stdout_write.c", | ||
| 1014 | "wasi/libc-top-half/musl/src/stdio/vdprintf.c", | ||
| 1015 | "wasi/libc-top-half/musl/src/stdio/vfprintf.c", | ||
| 1016 | "wasi/libc-top-half/musl/src/stdio/vfscanf.c", | ||
| 1017 | "wasi/libc-top-half/musl/src/stdio/vfwprintf.c", | ||
| 1018 | "wasi/libc-top-half/musl/src/stdio/vsnprintf.c", | ||
| 1019 | "wasi/libc-top-half/musl/src/stdio/vsscanf.c", | ||
| 1020 | "wasi/libc-top-half/musl/src/stdio/vswprintf.c", | ||
| 1021 | "wasi/libc-top-half/musl/src/stdio/vswscanf.c", | ||
| 1022 | "wasi/libc-top-half/musl/src/stdlib/strtod.c", | ||
| 1023 | "wasi/libc-top-half/musl/src/stdlib/wcstod.c", | ||
| 1024 | "wasi/libc-top-half/musl/src/stdlib/wcstol.c", | ||
| 1025 | "wasi/libc-top-half/musl/src/thread/pthread_attr_get.c", | ||
| 1026 | "wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c", | ||
| 1027 | "wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c", | ||
| 1028 | "wasi/libc-top-half/musl/src/thread/pthread_cancel.c", | ||
| 1029 | "wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c", | ||
| 1030 | "wasi/libc-top-half/musl/src/thread/pthread_key_create.c", | ||
| 1031 | "wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c", | ||
| 1032 | "wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c", | ||
| 1033 | "wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c", | ||
| 1034 | "wasi/libc-top-half/musl/src/thread/pthread_self.c", | ||
| 1035 | "wasi/libc-top-half/musl/src/time/getdate.c", | ||
| 1036 | "wasi/libc-top-half/musl/src/time/gmtime.c", | ||
| 1037 | "wasi/libc-top-half/musl/src/time/gmtime_r.c", | ||
| 1038 | "wasi/libc-top-half/musl/src/time/localtime.c", | ||
| 1039 | "wasi/libc-top-half/musl/src/time/localtime_r.c", | ||
| 1040 | "wasi/libc-top-half/musl/src/time/mktime.c", | ||
| 1041 | "wasi/libc-top-half/musl/src/time/__secs_to_tm.c", | ||
| 1042 | "wasi/libc-top-half/musl/src/time/strftime.c", | ||
| 1043 | "wasi/libc-top-half/musl/src/time/timegm.c", | ||
| 1044 | "wasi/libc-top-half/musl/src/time/__tm_to_secs.c", | ||
| 1045 | "wasi/libc-top-half/musl/src/time/__tz.c", | ||
| 1046 | "wasi/libc-top-half/musl/src/time/wcsftime.c", | ||
| 1047 | |||
| 1048 | "wasi/libc-top-half/sources/arc4random.c", | ||
| 1049 | |||
| 1050 | "wasi/thread-stub/pthread_barrier_destroy.c", | ||
| 1051 | "wasi/thread-stub/pthread_barrier_init.c", | ||
| 1052 | "wasi/thread-stub/pthread_barrier_wait.c", | ||
| 1053 | "wasi/thread-stub/pthread_cond_broadcast.c", | ||
| 1054 | "wasi/thread-stub/pthread_cond_destroy.c", | ||
| 1055 | "wasi/thread-stub/pthread_cond_init.c", | ||
| 1056 | "wasi/thread-stub/pthread_cond_signal.c", | ||
| 1057 | "wasi/thread-stub/pthread_cond_timedwait.c", | ||
| 1058 | "wasi/thread-stub/pthread_cond_wait.c", | ||
| 1059 | "wasi/thread-stub/pthread_create.c", | ||
| 1060 | "wasi/thread-stub/pthread_detach.c", | ||
| 1061 | "wasi/thread-stub/pthread_getattr_np.c", | ||
| 1062 | "wasi/thread-stub/pthread_join.c", | ||
| 1063 | "wasi/thread-stub/pthread_mutex_consistent.c", | ||
| 1064 | "wasi/thread-stub/pthread_mutex_getprioceiling.c", | ||
| 1065 | "wasi/thread-stub/pthread_mutex_lock.c", | ||
| 1066 | "wasi/thread-stub/pthread_mutex_timedlock.c", | ||
| 1067 | "wasi/thread-stub/pthread_mutex_trylock.c", | ||
| 1068 | "wasi/thread-stub/pthread_mutex_unlock.c", | ||
| 1069 | "wasi/thread-stub/pthread_once.c", | ||
| 1070 | "wasi/thread-stub/pthread_rwlock_rdlock.c", | ||
| 1071 | "wasi/thread-stub/pthread_rwlock_timedrdlock.c", | ||
| 1072 | "wasi/thread-stub/pthread_rwlock_timedwrlock.c", | ||
| 1073 | "wasi/thread-stub/pthread_rwlock_tryrdlock.c", | ||
| 1074 | "wasi/thread-stub/pthread_rwlock_trywrlock.c", | ||
| 1075 | "wasi/thread-stub/pthread_rwlock_unlock.c", | ||
| 1076 | "wasi/thread-stub/pthread_rwlock_wrlock.c", | ||
| 1077 | }; | ||
| 1078 | |||
| 1079 | const crt1_command_src_file = "wasi/libc-bottom-half/crt/crt1-command.c"; | ||
| 1080 | const crt1_reactor_src_file = "wasi/libc-bottom-half/crt/crt1-reactor.c"; | ||
| 1081 | |||
| 1082 | const fts_src_files = &[_][]const u8{ | ||
| 1083 | "wasi/fts/musl-fts/fts.c", | ||
| 1084 | }; | ||
| 1085 | |||
| 1086 | const setjmp_src_files = &[_][]const u8{ | ||
| 1087 | "wasi/libc-top-half/musl/src/setjmp/wasm32/rt.c", | ||
| 1088 | }; | ||
| 1089 | |||
| 1090 | const emulated_dl_src_files = &[_][]const u8{ | ||
| 1091 | "wasi/libc-top-half/musl/src/misc/dl.c", | ||
| 1092 | }; | ||
| 1093 | |||
| 1094 | const emulated_process_clocks_src_files = &[_][]const u8{ | ||
| 1095 | "wasi/libc-bottom-half/clocks/clock.c", | ||
| 1096 | "wasi/libc-bottom-half/clocks/getrusage.c", | ||
| 1097 | "wasi/libc-bottom-half/clocks/times.c", | ||
| 1098 | }; | ||
| 1099 | |||
| 1100 | const emulated_getpid_src_files = &[_][]const u8{ | ||
| 1101 | "wasi/libc-bottom-half/getpid/getpid.c", | ||
| 1102 | }; | ||
| 1103 | |||
| 1104 | const emulated_mman_src_files = &[_][]const u8{ | ||
| 1105 | "wasi/libc-bottom-half/mman/mman.c", | ||
| 1106 | }; | ||
| 1107 | |||
| 1108 | const emulated_signal_bottom_half_src_files = &[_][]const u8{ | ||
| 1109 | "wasi/libc-bottom-half/signal/signal.c", | ||
| 1110 | }; | ||
| 1111 | |||
| 1112 | const emulated_signal_top_half_src_files = &[_][]const u8{ | ||
| 1113 | "musl/src/signal/psignal.c", | ||
| 1114 | "musl/src/string/strsignal.c", | ||
| 1115 | }; | ||
src/link.zig-1| ... | @@ -15,7 +15,6 @@ const Compilation = @import("Compilation.zig"); | ... | @@ -15,7 +15,6 @@ const Compilation = @import("Compilation.zig"); |
| 15 | const LibCInstallation = std.zig.LibCInstallation; | 15 | const LibCInstallation = std.zig.LibCInstallation; |
| 16 | 16 | ||
| 17 | const trace = @import("tracy.zig").trace; | 17 | const trace = @import("tracy.zig").trace; |
| 18 | const wasi_libc = @import("libs/wasi_libc.zig"); | ||
| 19 | 18 | ||
| 20 | const Zcu = @import("Zcu.zig"); | 19 | const Zcu = @import("Zcu.zig"); |
| 21 | const InternPool = @import("InternPool.zig"); | 20 | const InternPool = @import("InternPool.zig"); |
src/link/Lld.zig-13| ... | @@ -1565,18 +1565,6 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void { | ... | @@ -1565,18 +1565,6 @@ fn wasmLink(lld: *Lld, arena: Allocator) !void { |
| 1565 | (comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic); | 1565 | (comp.config.output_mode == .Lib and comp.config.link_mode == .dynamic); |
| 1566 | 1566 | ||
| 1567 | if (comp.config.link_libc and is_exe_or_dyn_lib) { | 1567 | if (comp.config.link_libc and is_exe_or_dyn_lib) { |
| 1568 | if (target.os.tag == .wasi) { | ||
| 1569 | try argv.append(try comp.crtFileAsString( | ||
| 1570 | arena, | ||
| 1571 | wasi_libc.execModelCrtFileFullName(comp.config.wasi_exec_model), | ||
| 1572 | )); | ||
| 1573 | try argv.append(try comp.crtFileAsString(arena, "libc.a")); | ||
| 1574 | } | ||
| 1575 | |||
| 1576 | if (comp.zigc_static_lib) |zigc| { | ||
| 1577 | try argv.append(try zigc.full_object_path.toString(arena)); | ||
| 1578 | } | ||
| 1579 | |||
| 1580 | if (comp.config.link_libcpp) { | 1568 | if (comp.config.link_libcpp) { |
| 1581 | try argv.append(try comp.libcxx_static_lib.?.full_object_path.toString(arena)); | 1569 | try argv.append(try comp.libcxx_static_lib.?.full_object_path.toString(arena)); |
| 1582 | try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena)); | 1570 | try argv.append(try comp.libcxxabi_static_lib.?.full_object_path.toString(arena)); |
| ... | @@ -1706,7 +1694,6 @@ const freebsd = @import("../libs/freebsd.zig"); | ... | @@ -1706,7 +1694,6 @@ const freebsd = @import("../libs/freebsd.zig"); |
| 1706 | const glibc = @import("../libs/glibc.zig"); | 1694 | const glibc = @import("../libs/glibc.zig"); |
| 1707 | const netbsd = @import("../libs/netbsd.zig"); | 1695 | const netbsd = @import("../libs/netbsd.zig"); |
| 1708 | const openbsd = @import("../libs/openbsd.zig"); | 1696 | const openbsd = @import("../libs/openbsd.zig"); |
| 1709 | const wasi_libc = @import("../libs/wasi_libc.zig"); | ||
| 1710 | const link = @import("../link.zig"); | 1697 | const link = @import("../link.zig"); |
| 1711 | const lldMain = @import("../main.zig").lldMain; | 1698 | const lldMain = @import("../main.zig").lldMain; |
| 1712 | const target_util = @import("../target.zig"); | 1699 | const target_util = @import("../target.zig"); |
src/link/Wasm.zig-1| ... | @@ -40,7 +40,6 @@ const Zcu = @import("../Zcu.zig"); | ... | @@ -40,7 +40,6 @@ const Zcu = @import("../Zcu.zig"); |
| 40 | const codegen = @import("../codegen.zig"); | 40 | const codegen = @import("../codegen.zig"); |
| 41 | const link = @import("../link.zig"); | 41 | const link = @import("../link.zig"); |
| 42 | const trace = @import("../tracy.zig").trace; | 42 | const trace = @import("../tracy.zig").trace; |
| 43 | const wasi_libc = @import("../libs/wasi_libc.zig"); | ||
| 44 | const Value = @import("../Value.zig"); | 43 | const Value = @import("../Value.zig"); |
| 45 | 44 | ||
| 46 | base: link.File, | 45 | base: link.File, |
src/main.zig-1| ... | @@ -26,7 +26,6 @@ pub const tracy = @import("tracy.zig"); | ... | @@ -26,7 +26,6 @@ pub const tracy = @import("tracy.zig"); |
| 26 | const Compilation = @import("Compilation.zig"); | 26 | const Compilation = @import("Compilation.zig"); |
| 27 | const link = @import("link.zig"); | 27 | const link = @import("link.zig"); |
| 28 | const build_options = @import("build_options"); | 28 | const build_options = @import("build_options"); |
| 29 | const wasi_libc = @import("libs/wasi_libc.zig"); | ||
| 30 | const target_util = @import("target.zig"); | 29 | const target_util = @import("target.zig"); |
| 31 | const crash_report = @import("crash_report.zig"); | 30 | const crash_report = @import("crash_report.zig"); |
| 32 | const Zcu = @import("Zcu.zig"); | 31 | const Zcu = @import("Zcu.zig"); |
src/target.zig+1-5| ... | @@ -365,10 +365,6 @@ pub fn clangSupportsStackProtector(target: *const std.Target) bool { | ... | @@ -365,10 +365,6 @@ pub fn clangSupportsStackProtector(target: *const std.Target) bool { |
| 365 | }; | 365 | }; |
| 366 | } | 366 | } |
| 367 | 367 | ||
| 368 | pub fn libcProvidesStackProtector(target: *const std.Target) bool { | ||
| 369 | return !target.isMinGW() and target.os.tag != .wasi and !target.cpu.arch.isSpirV(); | ||
| 370 | } | ||
| 371 | |||
| 372 | /// Returns true if `@returnAddress()` is supported by the target and has a | 368 | /// Returns true if `@returnAddress()` is supported by the target and has a |
| 373 | /// reasonably performant implementation for the requested optimization mode. | 369 | /// reasonably performant implementation for the requested optimization mode. |
| 374 | pub fn supportsReturnAddress(target: *const std.Target, optimize: std.lang.Optimize) bool { | 370 | 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, | ... | @@ -478,7 +474,7 @@ pub fn canBuildLibUbsanRt(target: *const std.Target) enum { no, yes, llvm_only, |
| 478 | /// Whether libzigc can fill-in the gaps of an existing libc | 474 | /// Whether libzigc can fill-in the gaps of an existing libc |
| 479 | /// or *is* the libc of the target. | 475 | /// or *is* the libc of the target. |
| 480 | pub fn wantsZigC(target: *const std.Target, link_mode: std.lang.LinkMode) bool { | 476 | pub fn wantsZigC(target: *const std.Target, link_mode: std.lang.LinkMode) bool { |
| 481 | return (target.isMuslLibC() and link_mode == .static) or target.isWasiLibC() or target.isMinGW(); | 477 | return (target.isMuslLibC() and link_mode == .static) or target.isMinGW(); |
| 482 | } | 478 | } |
| 483 | 479 | ||
| 484 | pub fn hasRedZone(target: *const std.Target) bool { | 480 | pub fn hasRedZone(target: *const std.Target) bool { |
test/cases/export_override_libc.zig+1| ... | @@ -13,4 +13,5 @@ pub fn main() void { | ... | @@ -13,4 +13,5 @@ pub fn main() void { |
| 13 | } | 13 | } |
| 14 | 14 | ||
| 15 | // run | 15 | // run |
| 16 | // target=native | ||
| 16 | // link_libc=true | 17 | // link_libc=true |
test/libc.zig+325-325| ... | @@ -1,342 +1,342 @@ | ... | @@ -1,342 +1,342 @@ |
| 1 | pub fn addCases(cases: *tests.LibcContext) void { | 1 | pub fn addCases(cases: *tests.LibcContext) void { |
| 2 | cases.addLibcTestCase("api/main.c", true, .{}); | 2 | cases.addLibcTestCase("api/main.c", .{}); |
| 3 | 3 | ||
| 4 | cases.addLibcTestCase("functional/argv.c", true, .{}); | 4 | cases.addLibcTestCase("functional/argv.c", .{}); |
| 5 | cases.addLibcTestCase("functional/basename.c", true, .{}); | 5 | cases.addLibcTestCase("functional/basename.c", .{}); |
| 6 | cases.addLibcTestCase("functional/clocale_mbfuncs.c", true, .{}); | 6 | cases.addLibcTestCase("functional/clocale_mbfuncs.c", .{}); |
| 7 | cases.addLibcTestCase("functional/clock_gettime.c", true, .{}); | 7 | cases.addLibcTestCase("functional/clock_gettime.c", .{}); |
| 8 | cases.addLibcTestCase("functional/crypt.c", true, .{}); | 8 | cases.addLibcTestCase("functional/crypt.c", .{}); |
| 9 | cases.addLibcTestCase("functional/dirname.c", true, .{}); | 9 | cases.addLibcTestCase("functional/dirname.c", .{}); |
| 10 | cases.addLibcTestCase("functional/env.c", true, .{}); | 10 | cases.addLibcTestCase("functional/env.c", .{}); |
| 11 | cases.addLibcTestCase("functional/fcntl.c", false, .{}); | 11 | cases.addLibcTestCase("functional/fcntl.c", .{}); |
| 12 | cases.addLibcTestCase("functional/fdopen.c", false, .{}); | 12 | cases.addLibcTestCase("functional/fdopen.c", .{}); |
| 13 | cases.addLibcTestCase("functional/fnmatch.c", true, .{}); | 13 | cases.addLibcTestCase("functional/fnmatch.c", .{}); |
| 14 | cases.addLibcTestCase("functional/fscanf.c", false, .{}); | 14 | cases.addLibcTestCase("functional/fscanf.c", .{}); |
| 15 | cases.addLibcTestCase("functional/fwscanf.c", false, .{}); | 15 | cases.addLibcTestCase("functional/fwscanf.c", .{}); |
| 16 | cases.addLibcTestCase("functional/iconv_open.c", true, .{}); | 16 | cases.addLibcTestCase("functional/iconv_open.c", .{}); |
| 17 | cases.addLibcTestCase("functional/inet_pton.c", false, .{}); | 17 | cases.addLibcTestCase("functional/inet_pton.c", .{}); |
| 18 | // "functional/ipc_msg.c": Probably a bug in qemu | 18 | // "functional/ipc_msg.c": Probably a bug in qemu |
| 19 | // "functional/ipc_sem.c": Probably a bug in qemu | 19 | // "functional/ipc_sem.c": Probably a bug in qemu |
| 20 | // "functional/ipc_shm.c": Probably a bug in qemu | 20 | // "functional/ipc_shm.c": Probably a bug in qemu |
| 21 | cases.addLibcTestCase("functional/mbc.c", true, .{}); | 21 | cases.addLibcTestCase("functional/mbc.c", .{}); |
| 22 | cases.addLibcTestCase("functional/memstream.c", true, .{}); | 22 | cases.addLibcTestCase("functional/memstream.c", .{}); |
| 23 | // "functional/mntent.c": https://www.openwall.com/lists/musl/2024/10/22/1 | 23 | // "functional/mntent.c": https://www.openwall.com/lists/musl/2024/10/22/1 |
| 24 | cases.addLibcTestCase("functional/popen.c", false, .{}); | 24 | cases.addLibcTestCase("functional/popen.c", .{}); |
| 25 | // cases.addLibcTestCase("functional/pthread_cancel-points.c", false, .{}); - racey if multiple instances of the test run concurrently. | 25 | // cases.addLibcTestCase("functional/pthread_cancel-points.c", .{}); - racey if multiple instances of the test run concurrently. |
| 26 | cases.addLibcTestCase("functional/pthread_cancel.c", false, .{}); | 26 | cases.addLibcTestCase("functional/pthread_cancel.c", .{}); |
| 27 | cases.addLibcTestCase("functional/pthread_cond.c", false, .{}); | 27 | cases.addLibcTestCase("functional/pthread_cond.c", .{}); |
| 28 | cases.addLibcTestCase("functional/pthread_mutex.c", false, .{}); | 28 | cases.addLibcTestCase("functional/pthread_mutex.c", .{}); |
| 29 | // "functional/pthread_mutex_pi.c": Probably a bug in qemu (big/little endian FUTEX_LOCK_PI) | 29 | // "functional/pthread_mutex_pi.c": Probably a bug in qemu (big/little endian FUTEX_LOCK_PI) |
| 30 | // "functional/pthread_robust.c": https://gitlab.com/qemu-project/qemu/-/issues/2424 | 30 | // "functional/pthread_robust.c": https://gitlab.com/qemu-project/qemu/-/issues/2424 |
| 31 | cases.addLibcTestCase("functional/pthread_tsd.c", false, .{}); | 31 | cases.addLibcTestCase("functional/pthread_tsd.c", .{}); |
| 32 | cases.addLibcTestCase("functional/qsort.c", true, .{}); | 32 | cases.addLibcTestCase("functional/qsort.c", .{}); |
| 33 | cases.addLibcTestCase("functional/random.c", true, .{}); | 33 | cases.addLibcTestCase("functional/random.c", .{}); |
| 34 | cases.addLibcTestCase("functional/search_hsearch.c", true, .{}); | 34 | cases.addLibcTestCase("functional/search_hsearch.c", .{}); |
| 35 | cases.addLibcTestCase("functional/search_insque.c", true, .{}); | 35 | cases.addLibcTestCase("functional/search_insque.c", .{}); |
| 36 | cases.addLibcTestCase("functional/search_lsearch.c", true, .{}); | 36 | cases.addLibcTestCase("functional/search_lsearch.c", .{}); |
| 37 | cases.addLibcTestCase("functional/search_tsearch.c", true, .{}); | 37 | cases.addLibcTestCase("functional/search_tsearch.c", .{}); |
| 38 | cases.addLibcTestCase("functional/sem_init.c", false, .{}); | 38 | cases.addLibcTestCase("functional/sem_init.c", .{}); |
| 39 | cases.addLibcTestCase("functional/sem_open.c", false, .{}); | 39 | cases.addLibcTestCase("functional/sem_open.c", .{}); |
| 40 | cases.addLibcTestCase("functional/setjmp.c", false, .{}); | 40 | cases.addLibcTestCase("functional/setjmp.c", .{}); |
| 41 | cases.addLibcTestCase("functional/snprintf.c", true, .{}); | 41 | cases.addLibcTestCase("functional/snprintf.c", .{}); |
| 42 | cases.addLibcTestCase("functional/socket.c", false, .{}); | 42 | cases.addLibcTestCase("functional/socket.c", .{}); |
| 43 | cases.addLibcTestCase("functional/spawn.c", false, .{}); | 43 | cases.addLibcTestCase("functional/spawn.c", .{}); |
| 44 | cases.addLibcTestCase("functional/sscanf.c", true, .{}); | 44 | cases.addLibcTestCase("functional/sscanf.c", .{}); |
| 45 | cases.addLibcTestCase("functional/sscanf_long.c", false, .{}); | 45 | cases.addLibcTestCase("functional/sscanf_long.c", .{}); |
| 46 | cases.addLibcTestCase("functional/stat.c", false, .{}); | 46 | cases.addLibcTestCase("functional/stat.c", .{}); |
| 47 | cases.addLibcTestCase("functional/strftime.c", true, .{}); | 47 | cases.addLibcTestCase("functional/strftime.c", .{}); |
| 48 | cases.addLibcTestCase("functional/string.c", true, .{}); | 48 | cases.addLibcTestCase("functional/string.c", .{}); |
| 49 | cases.addLibcTestCase("functional/string_memcpy.c", true, .{}); | 49 | cases.addLibcTestCase("functional/string_memcpy.c", .{}); |
| 50 | cases.addLibcTestCase("functional/string_memmem.c", true, .{}); | 50 | cases.addLibcTestCase("functional/string_memmem.c", .{}); |
| 51 | cases.addLibcTestCase("functional/string_memset.c", true, .{}); | 51 | cases.addLibcTestCase("functional/string_memset.c", .{}); |
| 52 | cases.addLibcTestCase("functional/string_strchr.c", true, .{}); | 52 | cases.addLibcTestCase("functional/string_strchr.c", .{}); |
| 53 | cases.addLibcTestCase("functional/string_strcspn.c", true, .{}); | 53 | cases.addLibcTestCase("functional/string_strcspn.c", .{}); |
| 54 | cases.addLibcTestCase("functional/string_strstr.c", true, .{}); | 54 | cases.addLibcTestCase("functional/string_strstr.c", .{}); |
| 55 | cases.addLibcTestCase("functional/strtod.c", true, .{}); | 55 | cases.addLibcTestCase("functional/strtod.c", .{}); |
| 56 | cases.addLibcTestCase("functional/strtod_long.c", true, .{}); | 56 | cases.addLibcTestCase("functional/strtod_long.c", .{}); |
| 57 | cases.addLibcTestCase("functional/strtod_simple.c", true, .{}); | 57 | cases.addLibcTestCase("functional/strtod_simple.c", .{}); |
| 58 | cases.addLibcTestCase("functional/strtof.c", true, .{}); | 58 | cases.addLibcTestCase("functional/strtof.c", .{}); |
| 59 | cases.addLibcTestCase("functional/strtol.c", true, .{}); | 59 | cases.addLibcTestCase("functional/strtol.c", .{}); |
| 60 | cases.addLibcTestCase("functional/strtold.c", true, .{}); | 60 | cases.addLibcTestCase("functional/strtold.c", .{}); |
| 61 | cases.addLibcTestCase("functional/swprintf.c", true, .{}); | 61 | cases.addLibcTestCase("functional/swprintf.c", .{}); |
| 62 | cases.addLibcTestCase("functional/tgmath.c", true, .{}); | 62 | cases.addLibcTestCase("functional/tgmath.c", .{}); |
| 63 | cases.addLibcTestCase("functional/time.c", false, .{}); | 63 | cases.addLibcTestCase("functional/time.c", .{}); |
| 64 | cases.addLibcTestCase("functional/tls_align.c", true, .{ .additional_src_file = "functional/tls_align_dso.c" }); | 64 | cases.addLibcTestCase("functional/tls_align.c", .{ .additional_src_file = "functional/tls_align_dso.c" }); |
| 65 | cases.addLibcTestCase("functional/tls_init.c", false, .{}); | 65 | cases.addLibcTestCase("functional/tls_init.c", .{}); |
| 66 | cases.addLibcTestCase("functional/tls_local_exec.c", false, .{}); | 66 | cases.addLibcTestCase("functional/tls_local_exec.c", .{}); |
| 67 | cases.addLibcTestCase("functional/udiv.c", true, .{}); | 67 | cases.addLibcTestCase("functional/udiv.c", .{}); |
| 68 | cases.addLibcTestCase("functional/ungetc.c", false, .{}); | 68 | cases.addLibcTestCase("functional/ungetc.c", .{}); |
| 69 | // cases.addLibcTestCase("functional/utime.c", false, .{}); - fails under heavy load; futimens not reflected in subsequent fstat | 69 | // cases.addLibcTestCase("functional/utime.c", .{}); - fails under heavy load; futimens not reflected in subsequent fstat |
| 70 | cases.addLibcTestCase("functional/vfork.c", false, .{}); | 70 | cases.addLibcTestCase("functional/vfork.c", .{}); |
| 71 | cases.addLibcTestCase("functional/wcsstr.c", true, .{}); | 71 | cases.addLibcTestCase("functional/wcsstr.c", .{}); |
| 72 | cases.addLibcTestCase("functional/wcstol.c", true, .{}); | 72 | cases.addLibcTestCase("functional/wcstol.c", .{}); |
| 73 | 73 | ||
| 74 | // cases.addLibcTestCase("regression/daemon-failure.c", false, .{}); - unexpected ENOMEM with high FD limit | 74 | // cases.addLibcTestCase("regression/daemon-failure.c", .{}); - unexpected ENOMEM with high FD limit |
| 75 | cases.addLibcTestCase("regression/dn_expand-empty.c", false, .{}); | 75 | cases.addLibcTestCase("regression/dn_expand-empty.c", .{}); |
| 76 | cases.addLibcTestCase("regression/dn_expand-ptr-0.c", false, .{}); | 76 | cases.addLibcTestCase("regression/dn_expand-ptr-0.c", .{}); |
| 77 | cases.addLibcTestCase("regression/execle-env.c", false, .{}); | 77 | cases.addLibcTestCase("regression/execle-env.c", .{}); |
| 78 | cases.addLibcTestCase("regression/fflush-exit.c", false, .{}); | 78 | cases.addLibcTestCase("regression/fflush-exit.c", .{}); |
| 79 | cases.addLibcTestCase("regression/fgets-eof.c", true, .{}); | 79 | cases.addLibcTestCase("regression/fgets-eof.c", .{}); |
| 80 | cases.addLibcTestCase("regression/fgetwc-buffering.c", false, .{}); | 80 | cases.addLibcTestCase("regression/fgetwc-buffering.c", .{}); |
| 81 | cases.addLibcTestCase("regression/flockfile-list.c", false, .{}); | 81 | cases.addLibcTestCase("regression/flockfile-list.c", .{}); |
| 82 | cases.addLibcTestCase("regression/fpclassify-invalid-ld80.c", true, .{}); | 82 | cases.addLibcTestCase("regression/fpclassify-invalid-ld80.c", .{}); |
| 83 | cases.addLibcTestCase("regression/ftello-unflushed-append.c", false, .{}); | 83 | cases.addLibcTestCase("regression/ftello-unflushed-append.c", .{}); |
| 84 | cases.addLibcTestCase("regression/getpwnam_r-crash.c", false, .{}); | 84 | cases.addLibcTestCase("regression/getpwnam_r-crash.c", .{}); |
| 85 | cases.addLibcTestCase("regression/getpwnam_r-errno.c", false, .{}); | 85 | cases.addLibcTestCase("regression/getpwnam_r-errno.c", .{}); |
| 86 | cases.addLibcTestCase("regression/iconv-roundtrips.c", true, .{}); | 86 | cases.addLibcTestCase("regression/iconv-roundtrips.c", .{}); |
| 87 | cases.addLibcTestCase("regression/inet_ntop-v4mapped.c", true, .{}); | 87 | cases.addLibcTestCase("regression/inet_ntop-v4mapped.c", .{}); |
| 88 | cases.addLibcTestCase("regression/inet_pton-empty-last-field.c", true, .{}); | 88 | cases.addLibcTestCase("regression/inet_pton-empty-last-field.c", .{}); |
| 89 | cases.addLibcTestCase("regression/iswspace-null.c", true, .{}); | 89 | cases.addLibcTestCase("regression/iswspace-null.c", .{}); |
| 90 | cases.addLibcTestCase("regression/lrand48-signextend.c", true, .{}); | 90 | cases.addLibcTestCase("regression/lrand48-signextend.c", .{}); |
| 91 | cases.addLibcTestCase("regression/lseek-large.c", false, .{}); | 91 | cases.addLibcTestCase("regression/lseek-large.c", .{}); |
| 92 | cases.addLibcTestCase("regression/malloc-0.c", true, .{}); | 92 | cases.addLibcTestCase("regression/malloc-0.c", .{}); |
| 93 | // "regression/malloc-brk-fail.c": QEMU OOM | 93 | // "regression/malloc-brk-fail.c": QEMU OOM |
| 94 | // cases.addLibcTestCase("regression/malloc-oom.c", false, .{}); // wasi-libc: requires t_memfill; QEMU OOM | 94 | // cases.addLibcTestCase("regression/malloc-oom.c", .{}); // QEMU OOM |
| 95 | cases.addLibcTestCase("regression/mbsrtowcs-overflow.c", true, .{}); | 95 | cases.addLibcTestCase("regression/mbsrtowcs-overflow.c", .{}); |
| 96 | cases.addLibcTestCase("regression/memmem-oob-read.c", true, .{}); | 96 | cases.addLibcTestCase("regression/memmem-oob-read.c", .{}); |
| 97 | cases.addLibcTestCase("regression/memmem-oob.c", true, .{}); | 97 | cases.addLibcTestCase("regression/memmem-oob.c", .{}); |
| 98 | cases.addLibcTestCase("regression/mkdtemp-failure.c", false, .{}); | 98 | cases.addLibcTestCase("regression/mkdtemp-failure.c", .{}); |
| 99 | cases.addLibcTestCase("regression/mkstemp-failure.c", false, .{}); | 99 | cases.addLibcTestCase("regression/mkstemp-failure.c", .{}); |
| 100 | cases.addLibcTestCase("regression/printf-1e9-oob.c", true, .{}); | 100 | cases.addLibcTestCase("regression/printf-1e9-oob.c", .{}); |
| 101 | cases.addLibcTestCase("regression/printf-fmt-g-round.c", true, .{}); | 101 | cases.addLibcTestCase("regression/printf-fmt-g-round.c", .{}); |
| 102 | cases.addLibcTestCase("regression/printf-fmt-g-zeros.c", true, .{}); | 102 | cases.addLibcTestCase("regression/printf-fmt-g-zeros.c", .{}); |
| 103 | cases.addLibcTestCase("regression/printf-fmt-n.c", true, .{}); | 103 | cases.addLibcTestCase("regression/printf-fmt-n.c", .{}); |
| 104 | // "regression/pthread-robust-detach.c": https://gitlab.com/qemu-project/qemu/-/issues/2424 | 104 | // "regression/pthread-robust-detach.c": https://gitlab.com/qemu-project/qemu/-/issues/2424 |
| 105 | cases.addLibcTestCase("regression/pthread_atfork-errno-clobber.c", false, .{}); | 105 | cases.addLibcTestCase("regression/pthread_atfork-errno-clobber.c", .{}); |
| 106 | cases.addLibcTestCase("regression/pthread_cancel-sem_wait.c", false, .{}); | 106 | cases.addLibcTestCase("regression/pthread_cancel-sem_wait.c", .{}); |
| 107 | // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond-smasher.c", false, .{}); | 107 | // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond-smasher.c", .{}); |
| 108 | // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond_wait-cancel_ignored.c", false, .{}); | 108 | // Flaky under heavy load: cases.addLibcTestCase("regression/pthread_cond_wait-cancel_ignored.c", .{}); |
| 109 | cases.addLibcTestCase("regression/pthread_condattr_setclock.c", false, .{}); | 109 | cases.addLibcTestCase("regression/pthread_condattr_setclock.c", .{}); |
| 110 | // "regression/pthread_create-oom.c": QEMU OOM | 110 | // "regression/pthread_create-oom.c": QEMU OOM |
| 111 | cases.addLibcTestCase("regression/pthread_exit-cancel.c", false, .{}); | 111 | cases.addLibcTestCase("regression/pthread_exit-cancel.c", .{}); |
| 112 | cases.addLibcTestCase("regression/pthread_exit-dtor.c", false, .{}); | 112 | cases.addLibcTestCase("regression/pthread_exit-dtor.c", .{}); |
| 113 | cases.addLibcTestCase("regression/pthread_once-deadlock.c", false, .{}); | 113 | cases.addLibcTestCase("regression/pthread_once-deadlock.c", .{}); |
| 114 | cases.addLibcTestCase("regression/pthread_rwlock-ebusy.c", false, .{}); | 114 | cases.addLibcTestCase("regression/pthread_rwlock-ebusy.c", .{}); |
| 115 | cases.addLibcTestCase("regression/putenv-doublefree.c", true, .{}); | 115 | cases.addLibcTestCase("regression/putenv-doublefree.c", .{}); |
| 116 | // cases.addLibcTestCase("regression/raise-race.c", false, .{}); - Sometimes hangs when run natively on x86_64-linux. | 116 | // cases.addLibcTestCase("regression/raise-race.c", .{}); - Sometimes hangs when run natively on x86_64-linux. |
| 117 | cases.addLibcTestCase("regression/regex-backref-0.c", true, .{}); | 117 | cases.addLibcTestCase("regression/regex-backref-0.c", .{}); |
| 118 | cases.addLibcTestCase("regression/regex-bracket-icase.c", true, .{}); | 118 | cases.addLibcTestCase("regression/regex-bracket-icase.c", .{}); |
| 119 | cases.addLibcTestCase("regression/regex-ere-backref.c", true, .{}); | 119 | cases.addLibcTestCase("regression/regex-ere-backref.c", .{}); |
| 120 | cases.addLibcTestCase("regression/regex-escaped-high-byte.c", true, .{}); | 120 | cases.addLibcTestCase("regression/regex-escaped-high-byte.c", .{}); |
| 121 | cases.addLibcTestCase("regression/regex-negated-range.c", true, .{}); | 121 | cases.addLibcTestCase("regression/regex-negated-range.c", .{}); |
| 122 | cases.addLibcTestCase("regression/regexec-nosub.c", true, .{}); | 122 | cases.addLibcTestCase("regression/regexec-nosub.c", .{}); |
| 123 | cases.addLibcTestCase("regression/rewind-clear-error.c", false, .{}); | 123 | cases.addLibcTestCase("regression/rewind-clear-error.c", .{}); |
| 124 | // cases.addLibcTestCase("regression/rlimit-open-files.c", false, .{}); - fails when machine is under heavy load | 124 | // cases.addLibcTestCase("regression/rlimit-open-files.c", .{}); - fails when machine is under heavy load |
| 125 | cases.addLibcTestCase("regression/scanf-bytes-consumed.c", true, .{}); | 125 | cases.addLibcTestCase("regression/scanf-bytes-consumed.c", .{}); |
| 126 | cases.addLibcTestCase("regression/scanf-match-literal-eof.c", true, .{}); | 126 | cases.addLibcTestCase("regression/scanf-match-literal-eof.c", .{}); |
| 127 | cases.addLibcTestCase("regression/scanf-nullbyte-char.c", true, .{}); | 127 | cases.addLibcTestCase("regression/scanf-nullbyte-char.c", .{}); |
| 128 | cases.addLibcTestCase("regression/sem_close-unmap.c", false, .{}); | 128 | cases.addLibcTestCase("regression/sem_close-unmap.c", .{}); |
| 129 | // "regression/setenv-oom.c": QEMU OOM | 129 | // "regression/setenv-oom.c": QEMU OOM |
| 130 | cases.addLibcTestCase("regression/setvbuf-unget.c", true, .{}); | 130 | cases.addLibcTestCase("regression/setvbuf-unget.c", .{}); |
| 131 | cases.addLibcTestCase("regression/sigaltstack.c", false, .{}); | 131 | cases.addLibcTestCase("regression/sigaltstack.c", .{}); |
| 132 | cases.addLibcTestCase("regression/sigprocmask-internal.c", false, .{}); | 132 | cases.addLibcTestCase("regression/sigprocmask-internal.c", .{}); |
| 133 | cases.addLibcTestCase("regression/sigreturn.c", true, .{}); | 133 | cases.addLibcTestCase("regression/sigreturn.c", .{}); |
| 134 | cases.addLibcTestCase("regression/sscanf-eof.c", true, .{}); | 134 | cases.addLibcTestCase("regression/sscanf-eof.c", .{}); |
| 135 | cases.addLibcTestCase("regression/strverscmp.c", true, .{}); | 135 | cases.addLibcTestCase("regression/strverscmp.c", .{}); |
| 136 | cases.addLibcTestCase("regression/syscall-sign-extend.c", false, .{}); | 136 | cases.addLibcTestCase("regression/syscall-sign-extend.c", .{}); |
| 137 | cases.addLibcTestCase("regression/uselocale-0.c", true, .{}); | 137 | cases.addLibcTestCase("regression/uselocale-0.c", .{}); |
| 138 | cases.addLibcTestCase("regression/wcsncpy-read-overflow.c", true, .{}); | 138 | cases.addLibcTestCase("regression/wcsncpy-read-overflow.c", .{}); |
| 139 | cases.addLibcTestCase("regression/wcsstr-false-negative.c", true, .{}); | 139 | cases.addLibcTestCase("regression/wcsstr-false-negative.c", .{}); |
| 140 | 140 | ||
| 141 | cases.addLibcTestCase("math/acos.c", true, .{}); | 141 | cases.addLibcTestCase("math/acos.c", .{}); |
| 142 | cases.addLibcTestCase("math/acosf.c", true, .{}); | 142 | cases.addLibcTestCase("math/acosf.c", .{}); |
| 143 | // cases.addLibcTestCase("math/acosh.c", true, .{}); | 143 | // cases.addLibcTestCase("math/acosh.c", .{}); |
| 144 | cases.addLibcTestCase("math/acoshf.c", true, .{}); | 144 | cases.addLibcTestCase("math/acoshf.c", .{}); |
| 145 | // cases.addLibcTestCase("math/acoshl.c", true, .{}); | 145 | // cases.addLibcTestCase("math/acoshl.c", .{}); |
| 146 | // cases.addLibcTestCase("math/acosl.c", true, .{}); | 146 | // cases.addLibcTestCase("math/acosl.c", .{}); |
| 147 | cases.addLibcTestCase("math/asin.c", true, .{}); | 147 | cases.addLibcTestCase("math/asin.c", .{}); |
| 148 | cases.addLibcTestCase("math/asinf.c", true, .{}); | 148 | cases.addLibcTestCase("math/asinf.c", .{}); |
| 149 | // cases.addLibcTestCase("math/asinh.c", true, .{}); | 149 | // cases.addLibcTestCase("math/asinh.c", .{}); |
| 150 | cases.addLibcTestCase("math/asinhf.c", true, .{}); | 150 | cases.addLibcTestCase("math/asinhf.c", .{}); |
| 151 | // cases.addLibcTestCase("math/asinhl.c", true, .{}); | 151 | // cases.addLibcTestCase("math/asinhl.c", .{}); |
| 152 | cases.addLibcTestCase("math/asinl.c", true, .{}); | 152 | cases.addLibcTestCase("math/asinl.c", .{}); |
| 153 | cases.addLibcTestCase("math/atan.c", true, .{}); | 153 | cases.addLibcTestCase("math/atan.c", .{}); |
| 154 | cases.addLibcTestCase("math/atan2.c", true, .{}); | 154 | cases.addLibcTestCase("math/atan2.c", .{}); |
| 155 | cases.addLibcTestCase("math/atan2f.c", true, .{}); | 155 | cases.addLibcTestCase("math/atan2f.c", .{}); |
| 156 | cases.addLibcTestCase("math/atan2l.c", true, .{}); | 156 | cases.addLibcTestCase("math/atan2l.c", .{}); |
| 157 | cases.addLibcTestCase("math/atanf.c", true, .{}); | 157 | cases.addLibcTestCase("math/atanf.c", .{}); |
| 158 | cases.addLibcTestCase("math/atanh.c", true, .{}); | 158 | cases.addLibcTestCase("math/atanh.c", .{}); |
| 159 | cases.addLibcTestCase("math/atanhf.c", true, .{}); | 159 | cases.addLibcTestCase("math/atanhf.c", .{}); |
| 160 | cases.addLibcTestCase("math/atanhl.c", true, .{}); | 160 | cases.addLibcTestCase("math/atanhl.c", .{}); |
| 161 | cases.addLibcTestCase("math/atanl.c", true, .{}); | 161 | cases.addLibcTestCase("math/atanl.c", .{}); |
| 162 | cases.addLibcTestCase("math/cbrt.c", true, .{}); | 162 | cases.addLibcTestCase("math/cbrt.c", .{}); |
| 163 | cases.addLibcTestCase("math/cbrtf.c", true, .{}); | 163 | cases.addLibcTestCase("math/cbrtf.c", .{}); |
| 164 | cases.addLibcTestCase("math/cbrtl.c", true, .{}); | 164 | cases.addLibcTestCase("math/cbrtl.c", .{}); |
| 165 | cases.addLibcTestCase("math/ceil.c", true, .{}); | 165 | cases.addLibcTestCase("math/ceil.c", .{}); |
| 166 | cases.addLibcTestCase("math/ceilf.c", true, .{}); | 166 | cases.addLibcTestCase("math/ceilf.c", .{}); |
| 167 | cases.addLibcTestCase("math/ceill.c", true, .{}); | 167 | cases.addLibcTestCase("math/ceill.c", .{}); |
| 168 | cases.addLibcTestCase("math/copysign.c", true, .{}); | 168 | cases.addLibcTestCase("math/copysign.c", .{}); |
| 169 | cases.addLibcTestCase("math/copysignf.c", true, .{}); | 169 | cases.addLibcTestCase("math/copysignf.c", .{}); |
| 170 | cases.addLibcTestCase("math/copysignl.c", true, .{}); | 170 | cases.addLibcTestCase("math/copysignl.c", .{}); |
| 171 | cases.addLibcTestCase("math/cos.c", true, .{}); | 171 | cases.addLibcTestCase("math/cos.c", .{}); |
| 172 | cases.addLibcTestCase("math/cosf.c", true, .{}); | 172 | cases.addLibcTestCase("math/cosf.c", .{}); |
| 173 | cases.addLibcTestCase("math/cosh.c", true, .{}); | 173 | cases.addLibcTestCase("math/cosh.c", .{}); |
| 174 | cases.addLibcTestCase("math/coshf.c", true, .{}); | 174 | cases.addLibcTestCase("math/coshf.c", .{}); |
| 175 | cases.addLibcTestCase("math/coshl.c", true, .{}); | 175 | cases.addLibcTestCase("math/coshl.c", .{}); |
| 176 | cases.addLibcTestCase("math/cosl.c", true, .{}); | 176 | cases.addLibcTestCase("math/cosl.c", .{}); |
| 177 | cases.addLibcTestCase("math/drem.c", true, .{}); | 177 | cases.addLibcTestCase("math/drem.c", .{}); |
| 178 | cases.addLibcTestCase("math/dremf.c", true, .{}); | 178 | cases.addLibcTestCase("math/dremf.c", .{}); |
| 179 | cases.addLibcTestCase("math/erf.c", true, .{}); | 179 | cases.addLibcTestCase("math/erf.c", .{}); |
| 180 | cases.addLibcTestCase("math/erfc.c", true, .{}); | 180 | cases.addLibcTestCase("math/erfc.c", .{}); |
| 181 | // cases.addLibcTestCase("math/erfcf.c", true, .{}); | 181 | // cases.addLibcTestCase("math/erfcf.c", .{}); |
| 182 | cases.addLibcTestCase("math/erfcl.c", true, .{}); | 182 | cases.addLibcTestCase("math/erfcl.c", .{}); |
| 183 | cases.addLibcTestCase("math/erff.c", true, .{}); | 183 | cases.addLibcTestCase("math/erff.c", .{}); |
| 184 | cases.addLibcTestCase("math/erfl.c", true, .{}); | 184 | cases.addLibcTestCase("math/erfl.c", .{}); |
| 185 | cases.addLibcTestCase("math/exp.c", true, .{}); | 185 | cases.addLibcTestCase("math/exp.c", .{}); |
| 186 | cases.addLibcTestCase("math/exp10.c", true, .{}); | 186 | cases.addLibcTestCase("math/exp10.c", .{}); |
| 187 | cases.addLibcTestCase("math/exp10f.c", true, .{}); | 187 | cases.addLibcTestCase("math/exp10f.c", .{}); |
| 188 | cases.addLibcTestCase("math/exp10l.c", true, .{}); | 188 | cases.addLibcTestCase("math/exp10l.c", .{}); |
| 189 | cases.addLibcTestCase("math/exp2.c", true, .{}); | 189 | cases.addLibcTestCase("math/exp2.c", .{}); |
| 190 | cases.addLibcTestCase("math/exp2f.c", true, .{}); | 190 | cases.addLibcTestCase("math/exp2f.c", .{}); |
| 191 | cases.addLibcTestCase("math/exp2l.c", true, .{}); | 191 | cases.addLibcTestCase("math/exp2l.c", .{}); |
| 192 | cases.addLibcTestCase("math/expf.c", true, .{}); | 192 | cases.addLibcTestCase("math/expf.c", .{}); |
| 193 | cases.addLibcTestCase("math/expl.c", true, .{}); | 193 | cases.addLibcTestCase("math/expl.c", .{}); |
| 194 | // cases.addLibcTestCase("math/expm1.c", true, .{}); | 194 | // cases.addLibcTestCase("math/expm1.c", .{}); |
| 195 | // cases.addLibcTestCase("math/expm1f.c", true, .{}); | 195 | // cases.addLibcTestCase("math/expm1f.c", .{}); |
| 196 | // cases.addLibcTestCase("math/expm1l.c", true, .{}); | 196 | // cases.addLibcTestCase("math/expm1l.c", .{}); |
| 197 | cases.addLibcTestCase("math/fabs.c", true, .{}); | 197 | cases.addLibcTestCase("math/fabs.c", .{}); |
| 198 | cases.addLibcTestCase("math/fabsf.c", true, .{}); | 198 | cases.addLibcTestCase("math/fabsf.c", .{}); |
| 199 | cases.addLibcTestCase("math/fabsl.c", true, .{}); | 199 | cases.addLibcTestCase("math/fabsl.c", .{}); |
| 200 | cases.addLibcTestCase("math/fdim.c", true, .{}); | 200 | cases.addLibcTestCase("math/fdim.c", .{}); |
| 201 | cases.addLibcTestCase("math/fdimf.c", true, .{}); | 201 | cases.addLibcTestCase("math/fdimf.c", .{}); |
| 202 | cases.addLibcTestCase("math/fdiml.c", true, .{}); | 202 | cases.addLibcTestCase("math/fdiml.c", .{}); |
| 203 | cases.addLibcTestCase("math/fenv.c", true, .{}); | 203 | cases.addLibcTestCase("math/fenv.c", .{}); |
| 204 | cases.addLibcTestCase("math/floor.c", true, .{}); | 204 | cases.addLibcTestCase("math/floor.c", .{}); |
| 205 | cases.addLibcTestCase("math/floorf.c", true, .{}); | 205 | cases.addLibcTestCase("math/floorf.c", .{}); |
| 206 | cases.addLibcTestCase("math/floorl.c", true, .{}); | 206 | cases.addLibcTestCase("math/floorl.c", .{}); |
| 207 | // cases.addLibcTestCase("math/fma.c", true, .{}); | 207 | // cases.addLibcTestCase("math/fma.c", .{}); |
| 208 | // cases.addLibcTestCase("math/fmaf.c", true, .{}); | 208 | // cases.addLibcTestCase("math/fmaf.c", .{}); |
| 209 | // cases.addLibcTestCase("math/fmal.c", true, .{}); | 209 | // cases.addLibcTestCase("math/fmal.c", .{}); |
| 210 | cases.addLibcTestCase("math/fmax.c", true, .{}); | 210 | cases.addLibcTestCase("math/fmax.c", .{}); |
| 211 | cases.addLibcTestCase("math/fmaxf.c", true, .{}); | 211 | cases.addLibcTestCase("math/fmaxf.c", .{}); |
| 212 | cases.addLibcTestCase("math/fmaxl.c", true, .{}); | 212 | cases.addLibcTestCase("math/fmaxl.c", .{}); |
| 213 | cases.addLibcTestCase("math/fmin.c", true, .{}); | 213 | cases.addLibcTestCase("math/fmin.c", .{}); |
| 214 | cases.addLibcTestCase("math/fminf.c", true, .{}); | 214 | cases.addLibcTestCase("math/fminf.c", .{}); |
| 215 | cases.addLibcTestCase("math/fminl.c", true, .{}); | 215 | cases.addLibcTestCase("math/fminl.c", .{}); |
| 216 | cases.addLibcTestCase("math/fmod.c", true, .{}); | 216 | cases.addLibcTestCase("math/fmod.c", .{}); |
| 217 | cases.addLibcTestCase("math/fmodf.c", true, .{}); | 217 | cases.addLibcTestCase("math/fmodf.c", .{}); |
| 218 | cases.addLibcTestCase("math/fmodl.c", true, .{}); | 218 | cases.addLibcTestCase("math/fmodl.c", .{}); |
| 219 | cases.addLibcTestCase("math/fpclassify.c", true, .{}); | 219 | cases.addLibcTestCase("math/fpclassify.c", .{}); |
| 220 | cases.addLibcTestCase("math/frexp.c", true, .{}); | 220 | cases.addLibcTestCase("math/frexp.c", .{}); |
| 221 | cases.addLibcTestCase("math/frexpf.c", true, .{}); | 221 | cases.addLibcTestCase("math/frexpf.c", .{}); |
| 222 | cases.addLibcTestCase("math/frexpl.c", true, .{}); | 222 | cases.addLibcTestCase("math/frexpl.c", .{}); |
| 223 | cases.addLibcTestCase("math/hypot.c", true, .{}); | 223 | cases.addLibcTestCase("math/hypot.c", .{}); |
| 224 | cases.addLibcTestCase("math/hypotf.c", true, .{}); | 224 | cases.addLibcTestCase("math/hypotf.c", .{}); |
| 225 | cases.addLibcTestCase("math/hypotl.c", true, .{}); | 225 | cases.addLibcTestCase("math/hypotl.c", .{}); |
| 226 | // cases.addLibcTestCase("math/ilogb.c", true, .{}); | 226 | // cases.addLibcTestCase("math/ilogb.c", .{}); |
| 227 | // cases.addLibcTestCase("math/ilogbf.c", true, .{}); | 227 | // cases.addLibcTestCase("math/ilogbf.c", .{}); |
| 228 | // cases.addLibcTestCase("math/ilogbl.c", true, .{}); | 228 | // cases.addLibcTestCase("math/ilogbl.c", .{}); |
| 229 | cases.addLibcTestCase("math/isless.c", true, .{}); | 229 | cases.addLibcTestCase("math/isless.c", .{}); |
| 230 | // cases.addLibcTestCase("math/j0.c", true, .{}); | 230 | // cases.addLibcTestCase("math/j0.c", .{}); |
| 231 | cases.addLibcTestCase("math/j0f.c", true, .{}); | 231 | cases.addLibcTestCase("math/j0f.c", .{}); |
| 232 | cases.addLibcTestCase("math/j1.c", true, .{}); | 232 | cases.addLibcTestCase("math/j1.c", .{}); |
| 233 | cases.addLibcTestCase("math/j1f.c", true, .{}); | 233 | cases.addLibcTestCase("math/j1f.c", .{}); |
| 234 | // cases.addLibcTestCase("math/jn.c", true, .{}); | 234 | // cases.addLibcTestCase("math/jn.c", .{}); |
| 235 | // cases.addLibcTestCase("math/jnf.c", true, .{}); | 235 | // cases.addLibcTestCase("math/jnf.c", .{}); |
| 236 | cases.addLibcTestCase("math/ldexp.c", true, .{}); | 236 | cases.addLibcTestCase("math/ldexp.c", .{}); |
| 237 | cases.addLibcTestCase("math/ldexpf.c", true, .{}); | 237 | cases.addLibcTestCase("math/ldexpf.c", .{}); |
| 238 | cases.addLibcTestCase("math/ldexpl.c", true, .{}); | 238 | cases.addLibcTestCase("math/ldexpl.c", .{}); |
| 239 | // cases.addLibcTestCase("math/lgamma.c", true, .{}); | 239 | // cases.addLibcTestCase("math/lgamma.c", .{}); |
| 240 | cases.addLibcTestCase("math/lgamma_r.c", true, .{}); | 240 | cases.addLibcTestCase("math/lgamma_r.c", .{}); |
| 241 | // cases.addLibcTestCase("math/lgammaf.c", true, .{}); | 241 | // cases.addLibcTestCase("math/lgammaf.c", .{}); |
| 242 | // cases.addLibcTestCase("math/lgammaf_r.c", true, .{}); | 242 | // cases.addLibcTestCase("math/lgammaf_r.c", .{}); |
| 243 | // cases.addLibcTestCase("math/lgammal.c", true, .{}); | 243 | // cases.addLibcTestCase("math/lgammal.c", .{}); |
| 244 | cases.addLibcTestCase("math/lgammal_r.c", true, .{}); | 244 | cases.addLibcTestCase("math/lgammal_r.c", .{}); |
| 245 | // cases.addLibcTestCase("math/llrint.c", true, .{}); | 245 | // cases.addLibcTestCase("math/llrint.c", .{}); |
| 246 | // cases.addLibcTestCase("math/llrintf.c", true, .{}); | 246 | // cases.addLibcTestCase("math/llrintf.c", .{}); |
| 247 | // cases.addLibcTestCase("math/llrintl.c", true, .{}); | 247 | // cases.addLibcTestCase("math/llrintl.c", .{}); |
| 248 | // cases.addLibcTestCase("math/llround.c", true, .{}); | 248 | // cases.addLibcTestCase("math/llround.c", .{}); |
| 249 | // cases.addLibcTestCase("math/llroundf.c", true, .{}); | 249 | // cases.addLibcTestCase("math/llroundf.c", .{}); |
| 250 | // cases.addLibcTestCase("math/llroundl.c", true, .{}); | 250 | // cases.addLibcTestCase("math/llroundl.c", .{}); |
| 251 | cases.addLibcTestCase("math/log.c", true, .{}); | 251 | cases.addLibcTestCase("math/log.c", .{}); |
| 252 | cases.addLibcTestCase("math/log10.c", true, .{}); | 252 | cases.addLibcTestCase("math/log10.c", .{}); |
| 253 | cases.addLibcTestCase("math/log10f.c", true, .{}); | 253 | cases.addLibcTestCase("math/log10f.c", .{}); |
| 254 | cases.addLibcTestCase("math/log10l.c", true, .{}); | 254 | cases.addLibcTestCase("math/log10l.c", .{}); |
| 255 | cases.addLibcTestCase("math/log1p.c", true, .{}); | 255 | cases.addLibcTestCase("math/log1p.c", .{}); |
| 256 | cases.addLibcTestCase("math/log1pf.c", true, .{}); | 256 | cases.addLibcTestCase("math/log1pf.c", .{}); |
| 257 | // cases.addLibcTestCase("math/log1pl.c", true, .{}); | 257 | // cases.addLibcTestCase("math/log1pl.c", .{}); |
| 258 | cases.addLibcTestCase("math/log2.c", true, .{}); | 258 | cases.addLibcTestCase("math/log2.c", .{}); |
| 259 | cases.addLibcTestCase("math/log2f.c", true, .{}); | 259 | cases.addLibcTestCase("math/log2f.c", .{}); |
| 260 | cases.addLibcTestCase("math/log2l.c", true, .{}); | 260 | cases.addLibcTestCase("math/log2l.c", .{}); |
| 261 | cases.addLibcTestCase("math/logb.c", true, .{}); | 261 | cases.addLibcTestCase("math/logb.c", .{}); |
| 262 | cases.addLibcTestCase("math/logbf.c", true, .{}); | 262 | cases.addLibcTestCase("math/logbf.c", .{}); |
| 263 | cases.addLibcTestCase("math/logbl.c", true, .{}); | 263 | cases.addLibcTestCase("math/logbl.c", .{}); |
| 264 | cases.addLibcTestCase("math/logf.c", true, .{}); | 264 | cases.addLibcTestCase("math/logf.c", .{}); |
| 265 | cases.addLibcTestCase("math/logl.c", true, .{}); | 265 | cases.addLibcTestCase("math/logl.c", .{}); |
| 266 | cases.addLibcTestCase("math/lrint.c", true, .{}); | 266 | cases.addLibcTestCase("math/lrint.c", .{}); |
| 267 | cases.addLibcTestCase("math/lrintf.c", true, .{}); | 267 | cases.addLibcTestCase("math/lrintf.c", .{}); |
| 268 | cases.addLibcTestCase("math/lrintl.c", true, .{}); | 268 | cases.addLibcTestCase("math/lrintl.c", .{}); |
| 269 | cases.addLibcTestCase("math/lround.c", true, .{}); | 269 | cases.addLibcTestCase("math/lround.c", .{}); |
| 270 | cases.addLibcTestCase("math/lroundf.c", true, .{}); | 270 | cases.addLibcTestCase("math/lroundf.c", .{}); |
| 271 | cases.addLibcTestCase("math/lroundl.c", true, .{}); | 271 | cases.addLibcTestCase("math/lroundl.c", .{}); |
| 272 | cases.addLibcTestCase("math/modf.c", true, .{}); | 272 | cases.addLibcTestCase("math/modf.c", .{}); |
| 273 | cases.addLibcTestCase("math/modff.c", true, .{}); | 273 | cases.addLibcTestCase("math/modff.c", .{}); |
| 274 | cases.addLibcTestCase("math/modfl.c", true, .{}); | 274 | cases.addLibcTestCase("math/modfl.c", .{}); |
| 275 | // cases.addLibcTestCase("math/nearbyint.c", true, .{}); | 275 | // cases.addLibcTestCase("math/nearbyint.c", .{}); |
| 276 | cases.addLibcTestCase("math/nearbyintf.c", true, .{}); | 276 | cases.addLibcTestCase("math/nearbyintf.c", .{}); |
| 277 | // cases.addLibcTestCase("math/nearbyintl.c", true, .{}); | 277 | // cases.addLibcTestCase("math/nearbyintl.c", .{}); |
| 278 | cases.addLibcTestCase("math/nextafter.c", true, .{}); | 278 | cases.addLibcTestCase("math/nextafter.c", .{}); |
| 279 | cases.addLibcTestCase("math/nextafterf.c", true, .{}); | 279 | cases.addLibcTestCase("math/nextafterf.c", .{}); |
| 280 | cases.addLibcTestCase("math/nextafterl.c", true, .{}); | 280 | cases.addLibcTestCase("math/nextafterl.c", .{}); |
| 281 | cases.addLibcTestCase("math/nexttoward.c", true, .{}); | 281 | cases.addLibcTestCase("math/nexttoward.c", .{}); |
| 282 | cases.addLibcTestCase("math/nexttowardf.c", true, .{}); | 282 | cases.addLibcTestCase("math/nexttowardf.c", .{}); |
| 283 | cases.addLibcTestCase("math/nexttowardl.c", true, .{}); | 283 | cases.addLibcTestCase("math/nexttowardl.c", .{}); |
| 284 | // cases.addLibcTestCase("math/pow.c", true, .{}); | 284 | // cases.addLibcTestCase("math/pow.c", .{}); |
| 285 | cases.addLibcTestCase("math/pow10.c", true, .{}); | 285 | cases.addLibcTestCase("math/pow10.c", .{}); |
| 286 | cases.addLibcTestCase("math/pow10f.c", true, .{}); | 286 | cases.addLibcTestCase("math/pow10f.c", .{}); |
| 287 | cases.addLibcTestCase("math/pow10l.c", true, .{}); | 287 | cases.addLibcTestCase("math/pow10l.c", .{}); |
| 288 | // cases.addLibcTestCase("math/powf.c", true, .{}); | 288 | // cases.addLibcTestCase("math/powf.c", .{}); |
| 289 | // cases.addLibcTestCase("math/powl.c", true, .{}); | 289 | // cases.addLibcTestCase("math/powl.c", .{}); |
| 290 | cases.addLibcTestCase("math/remainder.c", true, .{}); | 290 | cases.addLibcTestCase("math/remainder.c", .{}); |
| 291 | cases.addLibcTestCase("math/remainderf.c", true, .{}); | 291 | cases.addLibcTestCase("math/remainderf.c", .{}); |
| 292 | cases.addLibcTestCase("math/remainderl.c", true, .{}); | 292 | cases.addLibcTestCase("math/remainderl.c", .{}); |
| 293 | cases.addLibcTestCase("math/remquo.c", true, .{}); | 293 | cases.addLibcTestCase("math/remquo.c", .{}); |
| 294 | cases.addLibcTestCase("math/remquof.c", true, .{}); | 294 | cases.addLibcTestCase("math/remquof.c", .{}); |
| 295 | cases.addLibcTestCase("math/remquol.c", true, .{}); | 295 | cases.addLibcTestCase("math/remquol.c", .{}); |
| 296 | cases.addLibcTestCase("math/rint.c", true, .{}); | 296 | cases.addLibcTestCase("math/rint.c", .{}); |
| 297 | cases.addLibcTestCase("math/rintf.c", true, .{}); | 297 | cases.addLibcTestCase("math/rintf.c", .{}); |
| 298 | cases.addLibcTestCase("math/rintl.c", true, .{}); | 298 | cases.addLibcTestCase("math/rintl.c", .{}); |
| 299 | cases.addLibcTestCase("math/round.c", true, .{}); | 299 | cases.addLibcTestCase("math/round.c", .{}); |
| 300 | cases.addLibcTestCase("math/roundf.c", true, .{}); | 300 | cases.addLibcTestCase("math/roundf.c", .{}); |
| 301 | cases.addLibcTestCase("math/roundl.c", true, .{}); | 301 | cases.addLibcTestCase("math/roundl.c", .{}); |
| 302 | cases.addLibcTestCase("math/scalb.c", true, .{}); | 302 | cases.addLibcTestCase("math/scalb.c", .{}); |
| 303 | cases.addLibcTestCase("math/scalbf.c", true, .{}); | 303 | cases.addLibcTestCase("math/scalbf.c", .{}); |
| 304 | cases.addLibcTestCase("math/scalbln.c", true, .{}); | 304 | cases.addLibcTestCase("math/scalbln.c", .{}); |
| 305 | cases.addLibcTestCase("math/scalblnf.c", true, .{}); | 305 | cases.addLibcTestCase("math/scalblnf.c", .{}); |
| 306 | cases.addLibcTestCase("math/scalblnl.c", true, .{}); | 306 | cases.addLibcTestCase("math/scalblnl.c", .{}); |
| 307 | cases.addLibcTestCase("math/scalbn.c", true, .{}); | 307 | cases.addLibcTestCase("math/scalbn.c", .{}); |
| 308 | cases.addLibcTestCase("math/scalbnf.c", true, .{}); | 308 | cases.addLibcTestCase("math/scalbnf.c", .{}); |
| 309 | cases.addLibcTestCase("math/scalbnl.c", true, .{}); | 309 | cases.addLibcTestCase("math/scalbnl.c", .{}); |
| 310 | cases.addLibcTestCase("math/sin.c", true, .{}); | 310 | cases.addLibcTestCase("math/sin.c", .{}); |
| 311 | cases.addLibcTestCase("math/sincos.c", true, .{}); | 311 | cases.addLibcTestCase("math/sincos.c", .{}); |
| 312 | cases.addLibcTestCase("math/sincosf.c", true, .{}); | 312 | cases.addLibcTestCase("math/sincosf.c", .{}); |
| 313 | cases.addLibcTestCase("math/sincosl.c", true, .{}); | 313 | cases.addLibcTestCase("math/sincosl.c", .{}); |
| 314 | cases.addLibcTestCase("math/sinf.c", true, .{}); | 314 | cases.addLibcTestCase("math/sinf.c", .{}); |
| 315 | // cases.addLibcTestCase("math/sinh.c", true, .{}); | 315 | // cases.addLibcTestCase("math/sinh.c", .{}); |
| 316 | cases.addLibcTestCase("math/sinhf.c", true, .{}); | 316 | cases.addLibcTestCase("math/sinhf.c", .{}); |
| 317 | // cases.addLibcTestCase("math/sinhl.c", true, .{}); | 317 | // cases.addLibcTestCase("math/sinhl.c", .{}); |
| 318 | cases.addLibcTestCase("math/sinl.c", true, .{}); | 318 | cases.addLibcTestCase("math/sinl.c", .{}); |
| 319 | cases.addLibcTestCase("math/sqrt.c", true, .{}); | 319 | cases.addLibcTestCase("math/sqrt.c", .{}); |
| 320 | cases.addLibcTestCase("math/sqrtf.c", true, .{}); | 320 | cases.addLibcTestCase("math/sqrtf.c", .{}); |
| 321 | cases.addLibcTestCase("math/sqrtl.c", true, .{}); | 321 | cases.addLibcTestCase("math/sqrtl.c", .{}); |
| 322 | cases.addLibcTestCase("math/tan.c", true, .{}); | 322 | cases.addLibcTestCase("math/tan.c", .{}); |
| 323 | cases.addLibcTestCase("math/tanf.c", true, .{}); | 323 | cases.addLibcTestCase("math/tanf.c", .{}); |
| 324 | cases.addLibcTestCase("math/tanh.c", true, .{}); | 324 | cases.addLibcTestCase("math/tanh.c", .{}); |
| 325 | cases.addLibcTestCase("math/tanhf.c", true, .{}); | 325 | cases.addLibcTestCase("math/tanhf.c", .{}); |
| 326 | cases.addLibcTestCase("math/tanhl.c", true, .{}); | 326 | cases.addLibcTestCase("math/tanhl.c", .{}); |
| 327 | cases.addLibcTestCase("math/tanl.c", true, .{}); | 327 | cases.addLibcTestCase("math/tanl.c", .{}); |
| 328 | // cases.addLibcTestCase("math/tgamma.c", true, .{}); | 328 | // cases.addLibcTestCase("math/tgamma.c", .{}); |
| 329 | // cases.addLibcTestCase("math/tgammaf.c", true, .{}); | 329 | // cases.addLibcTestCase("math/tgammaf.c", .{}); |
| 330 | // cases.addLibcTestCase("math/tgammal.c", true, .{}); | 330 | // cases.addLibcTestCase("math/tgammal.c", .{}); |
| 331 | cases.addLibcTestCase("math/trunc.c", true, .{}); | 331 | cases.addLibcTestCase("math/trunc.c", .{}); |
| 332 | cases.addLibcTestCase("math/truncf.c", true, .{}); | 332 | cases.addLibcTestCase("math/truncf.c", .{}); |
| 333 | cases.addLibcTestCase("math/truncl.c", true, .{}); | 333 | cases.addLibcTestCase("math/truncl.c", .{}); |
| 334 | // cases.addLibcTestCase("math/y0.c", true, .{}); | 334 | // cases.addLibcTestCase("math/y0.c", .{}); |
| 335 | // cases.addLibcTestCase("math/y0f.c", true, .{}); | 335 | // cases.addLibcTestCase("math/y0f.c", .{}); |
| 336 | // cases.addLibcTestCase("math/y1.c", true, .{}); | 336 | // cases.addLibcTestCase("math/y1.c", .{}); |
| 337 | // cases.addLibcTestCase("math/y1f.c", true, .{}); | 337 | // cases.addLibcTestCase("math/y1f.c", .{}); |
| 338 | // cases.addLibcTestCase("math/yn.c", true, .{}); | 338 | // cases.addLibcTestCase("math/yn.c", .{}); |
| 339 | // cases.addLibcTestCase("math/ynf.c", true, .{}); | 339 | // cases.addLibcTestCase("math/ynf.c", .{}); |
| 340 | } | 340 | } |
| 341 | 341 | ||
| 342 | const std = @import("std"); | 342 | const std = @import("std"); |
test/llvm_targets.zig-2| ... | @@ -290,12 +290,10 @@ const targets = [_]std.Target.Query{ | ... | @@ -290,12 +290,10 @@ const targets = [_]std.Target.Query{ |
| 290 | 290 | ||
| 291 | .{ .cpu_arch = .wasm32, .os_tag = .emscripten, .abi = .none }, | 291 | .{ .cpu_arch = .wasm32, .os_tag = .emscripten, .abi = .none }, |
| 292 | .{ .cpu_arch = .wasm32, .os_tag = .freestanding, .abi = .none }, | 292 | .{ .cpu_arch = .wasm32, .os_tag = .freestanding, .abi = .none }, |
| 293 | .{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .musl }, | ||
| 294 | .{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .none }, | 293 | .{ .cpu_arch = .wasm32, .os_tag = .wasi, .abi = .none }, |
| 295 | 294 | ||
| 296 | .{ .cpu_arch = .wasm64, .os_tag = .emscripten, .abi = .none }, | 295 | .{ .cpu_arch = .wasm64, .os_tag = .emscripten, .abi = .none }, |
| 297 | .{ .cpu_arch = .wasm64, .os_tag = .freestanding, .abi = .none }, | 296 | .{ .cpu_arch = .wasm64, .os_tag = .freestanding, .abi = .none }, |
| 298 | .{ .cpu_arch = .wasm64, .os_tag = .wasi, .abi = .musl }, | ||
| 299 | .{ .cpu_arch = .wasm64, .os_tag = .wasi, .abi = .none }, | 297 | .{ .cpu_arch = .wasm64, .os_tag = .wasi, .abi = .none }, |
| 300 | 298 | ||
| 301 | .{ .cpu_arch = .x86, .os_tag = .freestanding, .abi = .none }, | 299 | .{ .cpu_arch = .x86, .os_tag = .freestanding, .abi = .none }, |
test/src/Libc.zig-11| ... | @@ -10,7 +10,6 @@ pub const Options = struct { | ... | @@ -10,7 +10,6 @@ pub const Options = struct { |
| 10 | optimize_modes: []const std.builtin.Optimize, | 10 | optimize_modes: []const std.builtin.Optimize, |
| 11 | test_filters: []const []const u8, | 11 | test_filters: []const []const u8, |
| 12 | test_target_filters: []const []const u8, | 12 | test_target_filters: []const []const u8, |
| 13 | skip_wasm: bool, | ||
| 14 | max_rss: u64, | 13 | max_rss: u64, |
| 15 | }; | 14 | }; |
| 16 | 15 | ||
| ... | @@ -18,7 +17,6 @@ const TestCase = struct { | ... | @@ -18,7 +17,6 @@ const TestCase = struct { |
| 18 | name: []const u8, | 17 | name: []const u8, |
| 19 | src_file: std.Build.LazyPath, | 18 | src_file: std.Build.LazyPath, |
| 20 | additional_src_file: ?std.Build.LazyPath, | 19 | additional_src_file: ?std.Build.LazyPath, |
| 21 | supports_wasi_libc: bool, | ||
| 22 | }; | 20 | }; |
| 23 | 21 | ||
| 24 | pub const LibcTestCaseOption = struct { | 22 | pub const LibcTestCaseOption = struct { |
| ... | @@ -28,7 +26,6 @@ pub const LibcTestCaseOption = struct { | ... | @@ -28,7 +26,6 @@ pub const LibcTestCaseOption = struct { |
| 28 | pub fn addLibcTestCase( | 26 | pub fn addLibcTestCase( |
| 29 | libc: *Libc, | 27 | libc: *Libc, |
| 30 | path: []const u8, | 28 | path: []const u8, |
| 31 | supports_wasi_libc: bool, | ||
| 32 | options: LibcTestCaseOption, | 29 | options: LibcTestCaseOption, |
| 33 | ) void { | 30 | ) void { |
| 34 | const graph = libc.b.graph; | 31 | const graph = libc.b.graph; |
| ... | @@ -39,7 +36,6 @@ pub fn addLibcTestCase( | ... | @@ -39,7 +36,6 @@ pub fn addLibcTestCase( |
| 39 | .name = name, | 36 | .name = name, |
| 40 | .src_file = libc.libc_test_src_path.path(libc.b, path), | 37 | .src_file = libc.libc_test_src_path.path(libc.b, path), |
| 41 | .additional_src_file = if (options.additional_src_file) |additional_src_file| libc.libc_test_src_path.path(libc.b, additional_src_file) else null, | 38 | .additional_src_file = if (options.additional_src_file) |additional_src_file| libc.libc_test_src_path.path(libc.b, additional_src_file) else null, |
| 42 | .supports_wasi_libc = supports_wasi_libc, | ||
| 43 | }) catch @panic("OOM"); | 39 | }) catch @panic("OOM"); |
| 44 | } | 40 | } |
| 45 | 41 | ||
| ... | @@ -49,8 +45,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { | ... | @@ -49,8 +45,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { |
| 49 | } else false; | 45 | } else false; |
| 50 | if (!want_debug) return; | 46 | if (!want_debug) return; |
| 51 | 47 | ||
| 52 | if (libc.options.skip_wasm and target.query.cpu_arch != null and target.query.cpu_arch.?.isWasm()) return; | ||
| 53 | |||
| 54 | if (libc.options.test_target_filters.len > 0) { | 48 | if (libc.options.test_target_filters.len > 0) { |
| 55 | const triple_txt = target.query.zigTriple(libc.b.allocator) catch @panic("OOM"); | 49 | const triple_txt = target.query.zigTriple(libc.b.allocator) catch @panic("OOM"); |
| 56 | for (libc.options.test_target_filters) |filter| { | 50 | for (libc.options.test_target_filters) |filter| { |
| ... | @@ -81,9 +75,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { | ... | @@ -81,9 +75,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { |
| 81 | }); | 75 | }); |
| 82 | 76 | ||
| 83 | for (libc.test_cases.items) |*test_case| { | 77 | for (libc.test_cases.items) |*test_case| { |
| 84 | if (target.result.isWasiLibC() and !test_case.supports_wasi_libc) | ||
| 85 | continue; | ||
| 86 | |||
| 87 | const annotated_case_name = libc.b.fmt("run libc-test {s}", .{test_case.name}); | 78 | const annotated_case_name = libc.b.fmt("run libc-test {s}", .{test_case.name}); |
| 88 | for (libc.options.test_filters) |test_filter| { | 79 | for (libc.options.test_filters) |test_filter| { |
| 89 | if (std.mem.find(u8, annotated_case_name, test_filter)) |_| break; | 80 | 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 { | ... | @@ -95,8 +86,6 @@ pub fn addTarget(libc: *const Libc, target: std.Build.ResolvedTarget) void { |
| 95 | .link_libc = true, | 86 | .link_libc = true, |
| 96 | }); | 87 | }); |
| 97 | mod.addIncludePath(common); | 88 | mod.addIncludePath(common); |
| 98 | if (target.result.isWasiLibC()) | ||
| 99 | mod.addCMacro("_WASI_EMULATED_SIGNAL", ""); | ||
| 100 | mod.addCSourceFile(.{ | 89 | mod.addCSourceFile(.{ |
| 101 | .file = test_case.src_file, | 90 | .file = test_case.src_file, |
| 102 | .flags = &.{"-fno-builtin"}, | 91 | .flags = &.{"-fno-builtin"}, |
test/standalone/posix/getenv.zig+1-1| ... | @@ -5,7 +5,7 @@ const builtin = @import("builtin"); | ... | @@ -5,7 +5,7 @@ const builtin = @import("builtin"); |
| 5 | 5 | ||
| 6 | pub fn main(init: std.process.Init.Minimal) !void { | 6 | pub fn main(init: std.process.Init.Minimal) !void { |
| 7 | if (builtin.target.os.tag == .windows) return; | 7 | if (builtin.target.os.tag == .windows) return; |
| 8 | if (builtin.target.os.tag == .wasi and !builtin.link_libc) return; | 8 | if (builtin.target.os.tag == .wasi) return; |
| 9 | 9 | ||
| 10 | const environ = init.environ; | 10 | const environ = init.environ; |
| 11 | 11 |
test/tests.zig-32| ... | @@ -1616,14 +1616,6 @@ const module_test_targets = blk: { | ... | @@ -1616,14 +1616,6 @@ const module_test_targets = blk: { |
| 1616 | .abi = .none, | 1616 | .abi = .none, |
| 1617 | }, | 1617 | }, |
| 1618 | }, | 1618 | }, |
| 1619 | .{ | ||
| 1620 | .target = .{ | ||
| 1621 | .cpu_arch = .wasm32, | ||
| 1622 | .os_tag = .wasi, | ||
| 1623 | .abi = .musl, | ||
| 1624 | }, | ||
| 1625 | .link_libc = true, | ||
| 1626 | }, | ||
| 1627 | 1619 | ||
| 1628 | // Windows Targets | 1620 | // Windows Targets |
| 1629 | 1621 | ||
| ... | @@ -2050,25 +2042,6 @@ const c_abi_targets = blk: { | ... | @@ -2050,25 +2042,6 @@ const c_abi_targets = blk: { |
| 2050 | }, | 2042 | }, |
| 2051 | }, | 2043 | }, |
| 2052 | 2044 | ||
| 2053 | // WASI Targets | ||
| 2054 | |||
| 2055 | .{ | ||
| 2056 | .target = .{ | ||
| 2057 | .cpu_arch = .wasm32, | ||
| 2058 | .os_tag = .wasi, | ||
| 2059 | .abi = .musl, | ||
| 2060 | }, | ||
| 2061 | }, | ||
| 2062 | .{ | ||
| 2063 | .target = .{ | ||
| 2064 | .cpu_arch = .wasm32, | ||
| 2065 | .os_tag = .wasi, | ||
| 2066 | .abi = .musl, | ||
| 2067 | }, | ||
| 2068 | .use_llvm = false, | ||
| 2069 | .use_lld = false, | ||
| 2070 | }, | ||
| 2071 | |||
| 2072 | // Windows Targets | 2045 | // Windows Targets |
| 2073 | 2046 | ||
| 2074 | .{ | 2047 | .{ |
| ... | @@ -3633,11 +3606,6 @@ const libc_test_nsz_targets: []const std.Target.Query = &.{ | ... | @@ -3633,11 +3606,6 @@ const libc_test_nsz_targets: []const std.Target.Query = &.{ |
| 3633 | .os_tag = .linux, | 3606 | .os_tag = .linux, |
| 3634 | .abi = .musl, | 3607 | .abi = .musl, |
| 3635 | }, | 3608 | }, |
| 3636 | .{ | ||
| 3637 | .cpu_arch = .wasm32, | ||
| 3638 | .os_tag = .wasi, | ||
| 3639 | .abi = .musl, | ||
| 3640 | }, | ||
| 3641 | .{ | 3609 | .{ |
| 3642 | .cpu_arch = .x86, | 3610 | .cpu_arch = .x86, |
| 3643 | .os_tag = .linux, | 3611 | .os_tag = .linux, |