| author | |
| committer | |
| log | 4b69bd61e41f1a49bb0b00ac00a7e499ab7974a7 |
| tree | f2a7d43ea77e01d6010c2256b79801769680acec |
| parent | 0267abfe9b14b07dcf98f06218416f4b8aaeda48 |
| parent | b63c92f0b9ce7b3876c5f51e12a6ae249dfa4bac |
| signature |
cc,wasi: ship WASI libc and autobuild it when needed2439 files changed, 125821 insertions(+), 16 deletions(-)
CMakeLists.txt+1| ... | @@ -593,6 +593,7 @@ set(ZIG_STAGE2_SOURCES | ... | @@ -593,6 +593,7 @@ set(ZIG_STAGE2_SOURCES |
| 593 | "${CMAKE_SOURCE_DIR}/src/translate_c/ast.zig" | 593 | "${CMAKE_SOURCE_DIR}/src/translate_c/ast.zig" |
| 594 | "${CMAKE_SOURCE_DIR}/src/type.zig" | 594 | "${CMAKE_SOURCE_DIR}/src/type.zig" |
| 595 | "${CMAKE_SOURCE_DIR}/src/value.zig" | 595 | "${CMAKE_SOURCE_DIR}/src/value.zig" |
| 596 | "${CMAKE_SOURCE_DIR}/src/wasi_libc.zig" | ||
| 596 | "${CMAKE_SOURCE_DIR}/src/windows_sdk.zig" | 597 | "${CMAKE_SOURCE_DIR}/src/windows_sdk.zig" |
| 597 | "${CMAKE_SOURCE_DIR}/src/Zir.zig" | 598 | "${CMAKE_SOURCE_DIR}/src/Zir.zig" |
| 598 | "${CMAKE_SOURCE_DIR}/src/Sema.zig" | 599 | "${CMAKE_SOURCE_DIR}/src/Sema.zig" |
doc/langref.html.in+2| ... | @@ -10280,6 +10280,7 @@ Operating Systems: | ... | @@ -10280,6 +10280,7 @@ Operating Systems: |
| 10280 | ps4 | 10280 | ps4 |
| 10281 | elfiamcu | 10281 | elfiamcu |
| 10282 | tvos | 10282 | tvos |
| 10283 | wasi | ||
| 10283 | watchos | 10284 | watchos |
| 10284 | mesa3d | 10285 | mesa3d |
| 10285 | contiki | 10286 | contiki |
| ... | @@ -10348,6 +10349,7 @@ Available libcs: | ... | @@ -10348,6 +10349,7 @@ Available libcs: |
| 10348 | sparc-linux-gnu | 10349 | sparc-linux-gnu |
| 10349 | sparcv9-linux-gnu | 10350 | sparcv9-linux-gnu |
| 10350 | wasm32-freestanding-musl | 10351 | wasm32-freestanding-musl |
| 10352 | wasm32-wasi-musl | ||
| 10351 | x86_64-linux-gnu | 10353 | x86_64-linux-gnu |
| 10352 | x86_64-linux-gnux32 | 10354 | x86_64-linux-gnux32 |
| 10353 | x86_64-linux-musl</code></pre> | 10355 | x86_64-linux-musl</code></pre> |
lib/libc/include/wasm-wasi-musl/__errno.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef __wasilibc___errno_h | ||
| 2 | #define __wasilibc___errno_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern thread_local int errno; | ||
| 10 | #else | ||
| 11 | extern _Thread_local int errno; | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #define errno errno | ||
| 15 | |||
| 16 | #ifdef __cplusplus | ||
| 17 | } | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/include/wasm-wasi-musl/__errno_values.h created+86| ... | @@ -0,0 +1,86 @@ | ||
| 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 created+76| ... | @@ -0,0 +1,76 @@ | ||
| 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 created+14| ... | @@ -0,0 +1,14 @@ | ||
| 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 created+26| ... | @@ -0,0 +1,26 @@ | ||
| 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 created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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 created+39| ... | @@ -0,0 +1,39 @@ | ||
| 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 | #include <__struct_dirent.h> | ||
| 15 | #include <__typedef_DIR.h> | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | extern "C" { | ||
| 19 | #endif | ||
| 20 | |||
| 21 | int closedir(DIR *); | ||
| 22 | DIR *opendir(const char *); | ||
| 23 | DIR *fdopendir(int); | ||
| 24 | int fdclosedir(DIR *); | ||
| 25 | struct dirent *readdir(DIR *); | ||
| 26 | void rewinddir(DIR *); | ||
| 27 | void seekdir(DIR *, long); | ||
| 28 | long telldir(DIR *); | ||
| 29 | DIR *opendirat(int, const char *); | ||
| 30 | void rewinddir(DIR *); | ||
| 31 | int scandirat(int, const char *, struct dirent ***, | ||
| 32 | int (*)(const struct dirent *), | ||
| 33 | int (*)(const struct dirent **, const struct dirent **)); | ||
| 34 | |||
| 35 | #ifdef __cplusplus | ||
| 36 | } | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_fcntl.h created+61| ... | @@ -0,0 +1,61 @@ | ||
| 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 created+182| ... | @@ -0,0 +1,182 @@ | ||
| 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 created+30| ... | @@ -0,0 +1,30 @@ | ||
| 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 created+27| ... | @@ -0,0 +1,27 @@ | ||
| 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 created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 created+23| ... | @@ -0,0 +1,23 @@ | ||
| 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 created+17| ... | @@ -0,0 +1,17 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 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 created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #ifndef __wasilibc___header_sys_socket_h | ||
| 2 | #define __wasilibc___header_sys_socket_h | ||
| 3 | |||
| 4 | #include <__struct_msghdr.h> | ||
| 5 | #include <__struct_sockaddr.h> | ||
| 6 | #include <__struct_sockaddr_storage.h> | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | |||
| 10 | #define SHUT_RD __WASI_SDFLAGS_RD | ||
| 11 | #define SHUT_WR __WASI_SDFLAGS_WR | ||
| 12 | #define SHUT_RDWR (SHUT_RD | SHUT_WR) | ||
| 13 | |||
| 14 | #define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK | ||
| 15 | #define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL | ||
| 16 | #define MSG_TRUNC __WASI_RIFLAGS_RECV_DATA_TRUNCATED | ||
| 17 | |||
| 18 | #define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM | ||
| 19 | #define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM | ||
| 20 | |||
| 21 | #define SOCK_NONBLOCK (0x00004000) | ||
| 22 | #define SOCK_CLOEXEC (0x00002000) | ||
| 23 | |||
| 24 | #define SOL_SOCKET 0x7fffffff | ||
| 25 | |||
| 26 | #define SO_TYPE 3 | ||
| 27 | |||
| 28 | #define AF_UNSPEC 0 | ||
| 29 | #define AF_INET 1 | ||
| 30 | #define AF_INET6 2 | ||
| 31 | #define AF_UNIX 3 | ||
| 32 | |||
| 33 | #ifdef __cplusplus | ||
| 34 | extern "C" { | ||
| 35 | #endif | ||
| 36 | |||
| 37 | #ifdef __cplusplus | ||
| 38 | } | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_sys_stat.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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 created+37| ... | @@ -0,0 +1,37 @@ | ||
| 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_PROCESS_CPUTIME_ID; | ||
| 20 | #define CLOCK_PROCESS_CPUTIME_ID (&_CLOCK_PROCESS_CPUTIME_ID) | ||
| 21 | extern const struct __clockid _CLOCK_REALTIME; | ||
| 22 | #define CLOCK_REALTIME (&_CLOCK_REALTIME) | ||
| 23 | extern const struct __clockid _CLOCK_THREAD_CPUTIME_ID; | ||
| 24 | #define CLOCK_THREAD_CPUTIME_ID (&_CLOCK_THREAD_CPUTIME_ID) | ||
| 25 | |||
| 26 | /* | ||
| 27 | * TIME_UTC is the only standardized time base value. | ||
| 28 | */ | ||
| 29 | #define TIME_UTC 1 | ||
| 30 | |||
| 31 | /* | ||
| 32 | * Note that XSI specifies CLOCKS_PER_SEC to be 1000000, rather than | ||
| 33 | * 1000000000; the clock API is providing more precision than XSI specifies. | ||
| 34 | */ | ||
| 35 | #define CLOCKS_PER_SEC ((clock_t)1000000000) | ||
| 36 | |||
| 37 | #endif | ||
lib/libc/include/wasm-wasi-musl/__header_unistd.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #ifndef __wasilibc___macro_PAGESIZE_h | ||
| 2 | #define __wasilibc___macro_PAGESIZE_h | ||
| 3 | |||
| 4 | /* | ||
| 5 | * The page size in WebAssembly is fixed at 64 KiB. If this ever changes, | ||
| 6 | * it's expected that applications will need to opt in, so we can change | ||
| 7 | * this. | ||
| 8 | */ | ||
| 9 | #define PAGESIZE (0x10000) | ||
| 10 | |||
| 11 | #endif | ||
lib/libc/include/wasm-wasi-musl/__mode_t.h created+38| ... | @@ -0,0 +1,38 @@ | ||
| 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 (0xc000) | ||
| 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 created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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 created+14| ... | @@ -0,0 +1,14 @@ | ||
| 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 created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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 created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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 created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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 created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_h | ||
| 2 | #define __wasilibc___struct_sockaddr_h | ||
| 3 | |||
| 4 | #define __need_STDDEF_H_misc | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__typedef_sa_family_t.h> | ||
| 8 | |||
| 9 | struct sockaddr { | ||
| 10 | _Alignas(max_align_t) sa_family_t sa_family; | ||
| 11 | char sa_data[0]; | ||
| 12 | }; | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_in_h | ||
| 2 | #define __wasilibc___struct_sockaddr_in_h | ||
| 3 | |||
| 4 | #define __need_STDDEF_H_misc | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__typedef_sa_family_t.h> | ||
| 8 | #include <__typedef_in_port_t.h> | ||
| 9 | #include <__struct_in_addr.h> | ||
| 10 | |||
| 11 | struct sockaddr_in { | ||
| 12 | _Alignas(max_align_t) sa_family_t sin_family; | ||
| 13 | in_port_t sin_port; | ||
| 14 | struct in_addr sin_addr; | ||
| 15 | }; | ||
| 16 | |||
| 17 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_in6_h | ||
| 2 | #define __wasilibc___struct_sockaddr_in6_h | ||
| 3 | |||
| 4 | #define __need_STDDEF_H_misc | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__typedef_sa_family_t.h> | ||
| 8 | #include <__typedef_in_port_t.h> | ||
| 9 | #include <__struct_in6_addr.h> | ||
| 10 | |||
| 11 | struct sockaddr_in6 { | ||
| 12 | _Alignas(max_align_t) sa_family_t sin6_family; | ||
| 13 | in_port_t sin6_port; | ||
| 14 | unsigned sin6_flowinfo; | ||
| 15 | struct in6_addr sin6_addr; | ||
| 16 | unsigned sin6_scope_id; | ||
| 17 | }; | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_storage_h | ||
| 2 | #define __wasilibc___struct_sockaddr_storage_h | ||
| 3 | |||
| 4 | #define __need_STDDEF_H_misc | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__typedef_sa_family_t.h> | ||
| 8 | |||
| 9 | struct sockaddr_storage { | ||
| 10 | _Alignas(max_align_t) sa_family_t ss_family; | ||
| 11 | char __ss_data[32]; | ||
| 12 | }; | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_sockaddr_un.h created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #ifndef __wasilibc___struct_sockaddr_un_h | ||
| 2 | #define __wasilibc___struct_sockaddr_un_h | ||
| 3 | |||
| 4 | #define __need_STDDEF_H_misc | ||
| 5 | #include <stddef.h> | ||
| 6 | |||
| 7 | #include <__typedef_sa_family_t.h> | ||
| 8 | |||
| 9 | struct sockaddr_un { | ||
| 10 | _Alignas(max_align_t) sa_family_t sun_family; | ||
| 11 | }; | ||
| 12 | |||
| 13 | #endif | ||
lib/libc/include/wasm-wasi-musl/__struct_stat.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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 created+13| ... | @@ -0,0 +1,13 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 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 created+13| ... | @@ -0,0 +1,13 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+14| ... | @@ -0,0 +1,14 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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/alloca.h created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #ifndef	_ALLOCA_H | ||
| 2 | #define	_ALLOCA_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define	__NEED_size_t | ||
| 9 | #include <bits/alltypes.h> | ||
| 10 | |||
| 11 | void *alloca(size_t); | ||
| 12 | |||
| 13 | #define alloca __builtin_alloca | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | } | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/include/wasm-wasi-musl/ar.h created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #ifndef _AR_H | ||
| 2 | #define _AR_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define ARMAG "!<arch>\n" | ||
| 9 | #define SARMAG 8 | ||
| 10 | #define ARFMAG "`\n" | ||
| 11 | |||
| 12 | struct ar_hdr { | ||
| 13 | 	char ar_name[16]; | ||
| 14 | 	char ar_date[12]; | ||
| 15 | 	char ar_uid[6], ar_gid[6]; | ||
| 16 | 	char ar_mode[8]; | ||
| 17 | 	char ar_size[10]; | ||
| 18 | 	char ar_fmag[2]; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #ifdef __cplusplus | ||
| 22 | } | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #endif | ||
lib/libc/include/wasm-wasi-musl/arpa/ftp.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #ifndef _ARPA_FTP_H | ||
| 2 | #define _ARPA_FTP_H | ||
| 3 | #define PRELIM 1 | ||
| 4 | #define COMPLETE 2 | ||
| 5 | #define CONTINUE 3 | ||
| 6 | #define TRANSIENT 4 | ||
| 7 | #define ERROR 5 | ||
| 8 | #define TYPE_A 1 | ||
| 9 | #define TYPE_E 2 | ||
| 10 | #define TYPE_I 3 | ||
| 11 | #define TYPE_L 4 | ||
| 12 | #define FORM_N 1 | ||
| 13 | #define FORM_T 2 | ||
| 14 | #define FORM_C 3 | ||
| 15 | #define STRU_F 1 | ||
| 16 | #define STRU_R 2 | ||
| 17 | #define STRU_P 3 | ||
| 18 | #define MODE_S 1 | ||
| 19 | #define MODE_B 2 | ||
| 20 | #define MODE_C 3 | ||
| 21 | #define REC_ESC '\377' | ||
| 22 | #define REC_EOR '\001' | ||
| 23 | #define REC_EOF '\002' | ||
| 24 | #define BLK_EOR 0x80 | ||
| 25 | #define BLK_EOF 0x40 | ||
| 26 | #define BLK_ERRORS 0x20 | ||
| 27 | #define BLK_RESTART 0x10 | ||
| 28 | #define BLK_BYTECOUNT 2 | ||
| 29 | #ifdef FTP_NAMES | ||
| 30 | char *modenames[] = {"0", "Stream", "Block", "Compressed" }; | ||
| 31 | char *strunames[] = {"0", "File", "Record", "Page" }; | ||
| 32 | char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; | ||
| 33 | char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; | ||
| 34 | #endif | ||
| 35 | #endif | ||
lib/libc/include/wasm-wasi-musl/arpa/inet.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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.h created+455| ... | @@ -0,0 +1,455 @@ | ||
| 1 | #ifndef _ARPA_NAMESER_H | ||
| 2 | #define _ARPA_NAMESER_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stddef.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #define __NAMESER	19991006 | ||
| 12 | #define NS_PACKETSZ	512 | ||
| 13 | #define NS_MAXDNAME	1025 | ||
| 14 | #define NS_MAXMSG	65535 | ||
| 15 | #define NS_MAXCDNAME	255 | ||
| 16 | #define NS_MAXLABEL	63 | ||
| 17 | #define NS_HFIXEDSZ	12 | ||
| 18 | #define NS_QFIXEDSZ	4 | ||
| 19 | #define NS_RRFIXEDSZ	10 | ||
| 20 | #define NS_INT32SZ	4 | ||
| 21 | #define NS_INT16SZ	2 | ||
| 22 | #define NS_INT8SZ	1 | ||
| 23 | #define NS_INADDRSZ	4 | ||
| 24 | #define NS_IN6ADDRSZ	16 | ||
| 25 | #define NS_CMPRSFLGS	0xc0 | ||
| 26 | #define NS_DEFAULTPORT	53 | ||
| 27 | |||
| 28 | typedef enum __ns_sect { | ||
| 29 | 	ns_s_qd = 0, | ||
| 30 | 	ns_s_zn = 0, | ||
| 31 | 	ns_s_an = 1, | ||
| 32 | 	ns_s_pr = 1, | ||
| 33 | 	ns_s_ns = 2, | ||
| 34 | 	ns_s_ud = 2, | ||
| 35 | 	ns_s_ar = 3, | ||
| 36 | 	ns_s_max = 4 | ||
| 37 | } ns_sect; | ||
| 38 | |||
| 39 | typedef struct __ns_msg { | ||
| 40 | 	const unsigned char *_msg, *_eom; | ||
| 41 | 	uint16_t _id, _flags, _counts[ns_s_max]; | ||
| 42 | 	const unsigned char *_sections[ns_s_max]; | ||
| 43 | 	ns_sect _sect; | ||
| 44 | 	int _rrnum; | ||
| 45 | 	const unsigned char *_msg_ptr; | ||
| 46 | } ns_msg; | ||
| 47 | |||
| 48 | struct _ns_flagdata { int mask, shift; }; | ||
| 49 | extern const struct _ns_flagdata _ns_flagdata[]; | ||
| 50 | |||
| 51 | #define ns_msg_id(handle) ((handle)._id + 0) | ||
| 52 | #define ns_msg_base(handle) ((handle)._msg + 0) | ||
| 53 | #define ns_msg_end(handle) ((handle)._eom + 0) | ||
| 54 | #define ns_msg_size(handle) ((handle)._eom - (handle)._msg) | ||
| 55 | #define ns_msg_count(handle, section) ((handle)._counts[section] + 0) | ||
| 56 | #define ns_msg_getflag(handle, flag) \ | ||
| 57 | 	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) | ||
| 58 | |||
| 59 | typedef	struct __ns_rr { | ||
| 60 | 	char		name[NS_MAXDNAME]; | ||
| 61 | 	uint16_t	type; | ||
| 62 | 	uint16_t	rr_class; | ||
| 63 | 	uint32_t	ttl; | ||
| 64 | 	uint16_t	rdlength; | ||
| 65 | 	const unsigned char *rdata; | ||
| 66 | } ns_rr; | ||
| 67 | |||
| 68 | #define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".") | ||
| 69 | #define ns_rr_type(rr)	((ns_type)((rr).type + 0)) | ||
| 70 | #define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0)) | ||
| 71 | #define ns_rr_ttl(rr)	((rr).ttl + 0) | ||
| 72 | #define ns_rr_rdlen(rr)	((rr).rdlength + 0) | ||
| 73 | #define ns_rr_rdata(rr)	((rr).rdata + 0) | ||
| 74 | |||
| 75 | typedef enum __ns_flag { | ||
| 76 | 	ns_f_qr, | ||
| 77 | 	ns_f_opcode, | ||
| 78 | 	ns_f_aa, | ||
| 79 | 	ns_f_tc, | ||
| 80 | 	ns_f_rd, | ||
| 81 | 	ns_f_ra, | ||
| 82 | 	ns_f_z, | ||
| 83 | 	ns_f_ad, | ||
| 84 | 	ns_f_cd, | ||
| 85 | 	ns_f_rcode, | ||
| 86 | 	ns_f_max | ||
| 87 | } ns_flag; | ||
| 88 | |||
| 89 | typedef enum __ns_opcode { | ||
| 90 | 	ns_o_query = 0, | ||
| 91 | 	ns_o_iquery = 1, | ||
| 92 | 	ns_o_status = 2, | ||
| 93 | 	ns_o_notify = 4, | ||
| 94 | 	ns_o_update = 5, | ||
| 95 | 	ns_o_max = 6 | ||
| 96 | } ns_opcode; | ||
| 97 | |||
| 98 | typedef	enum __ns_rcode { | ||
| 99 | 	ns_r_noerror = 0, | ||
| 100 | 	ns_r_formerr = 1, | ||
| 101 | 	ns_r_servfail = 2, | ||
| 102 | 	ns_r_nxdomain = 3, | ||
| 103 | 	ns_r_notimpl = 4, | ||
| 104 | 	ns_r_refused = 5, | ||
| 105 | 	ns_r_yxdomain = 6, | ||
| 106 | 	ns_r_yxrrset = 7, | ||
| 107 | 	ns_r_nxrrset = 8, | ||
| 108 | 	ns_r_notauth = 9, | ||
| 109 | 	ns_r_notzone = 10, | ||
| 110 | 	ns_r_max = 11, | ||
| 111 | 	ns_r_badvers = 16, | ||
| 112 | 	ns_r_badsig = 16, | ||
| 113 | 	ns_r_badkey = 17, | ||
| 114 | 	ns_r_badtime = 18 | ||
| 115 | } ns_rcode; | ||
| 116 | |||
| 117 | typedef enum __ns_update_operation { | ||
| 118 | 	ns_uop_delete = 0, | ||
| 119 | 	ns_uop_add = 1, | ||
| 120 | 	ns_uop_max = 2 | ||
| 121 | } ns_update_operation; | ||
| 122 | |||
| 123 | struct ns_tsig_key { | ||
| 124 | char name[NS_MAXDNAME], alg[NS_MAXDNAME]; | ||
| 125 | unsigned char *data; | ||
| 126 | int len; | ||
| 127 | }; | ||
| 128 | typedef struct ns_tsig_key ns_tsig_key; | ||
| 129 | |||
| 130 | struct ns_tcp_tsig_state { | ||
| 131 | 	int counter; | ||
| 132 | 	struct dst_key *key; | ||
| 133 | 	void *ctx; | ||
| 134 | 	unsigned char sig[NS_PACKETSZ]; | ||
| 135 | 	int siglen; | ||
| 136 | }; | ||
| 137 | typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; | ||
| 138 | |||
| 139 | #define NS_TSIG_FUDGE 300 | ||
| 140 | #define NS_TSIG_TCP_COUNT 100 | ||
| 141 | #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" | ||
| 142 | |||
| 143 | #define NS_TSIG_ERROR_NO_TSIG -10 | ||
| 144 | #define NS_TSIG_ERROR_NO_SPACE -11 | ||
| 145 | #define NS_TSIG_ERROR_FORMERR -12 | ||
| 146 | |||
| 147 | typedef enum __ns_type { | ||
| 148 | 	ns_t_invalid = 0, | ||
| 149 | 	ns_t_a = 1, | ||
| 150 | 	ns_t_ns = 2, | ||
| 151 | 	ns_t_md = 3, | ||
| 152 | 	ns_t_mf = 4, | ||
| 153 | 	ns_t_cname = 5, | ||
| 154 | 	ns_t_soa = 6, | ||
| 155 | 	ns_t_mb = 7, | ||
| 156 | 	ns_t_mg = 8, | ||
| 157 | 	ns_t_mr = 9, | ||
| 158 | 	ns_t_null = 10, | ||
| 159 | 	ns_t_wks = 11, | ||
| 160 | 	ns_t_ptr = 12, | ||
| 161 | 	ns_t_hinfo = 13, | ||
| 162 | 	ns_t_minfo = 14, | ||
| 163 | 	ns_t_mx = 15, | ||
| 164 | 	ns_t_txt = 16, | ||
| 165 | 	ns_t_rp = 17, | ||
| 166 | 	ns_t_afsdb = 18, | ||
| 167 | 	ns_t_x25 = 19, | ||
| 168 | 	ns_t_isdn = 20, | ||
| 169 | 	ns_t_rt = 21, | ||
| 170 | 	ns_t_nsap = 22, | ||
| 171 | 	ns_t_nsap_ptr = 23, | ||
| 172 | 	ns_t_sig = 24, | ||
| 173 | 	ns_t_key = 25, | ||
| 174 | 	ns_t_px = 26, | ||
| 175 | 	ns_t_gpos = 27, | ||
| 176 | 	ns_t_aaaa = 28, | ||
| 177 | 	ns_t_loc = 29, | ||
| 178 | 	ns_t_nxt = 30, | ||
| 179 | 	ns_t_eid = 31, | ||
| 180 | 	ns_t_nimloc = 32, | ||
| 181 | 	ns_t_srv = 33, | ||
| 182 | 	ns_t_atma = 34, | ||
| 183 | 	ns_t_naptr = 35, | ||
| 184 | 	ns_t_kx = 36, | ||
| 185 | 	ns_t_cert = 37, | ||
| 186 | 	ns_t_a6 = 38, | ||
| 187 | 	ns_t_dname = 39, | ||
| 188 | 	ns_t_sink = 40, | ||
| 189 | 	ns_t_opt = 41, | ||
| 190 | 	ns_t_apl = 42, | ||
| 191 | 	ns_t_tkey = 249, | ||
| 192 | 	ns_t_tsig = 250, | ||
| 193 | 	ns_t_ixfr = 251, | ||
| 194 | 	ns_t_axfr = 252, | ||
| 195 | 	ns_t_mailb = 253, | ||
| 196 | 	ns_t_maila = 254, | ||
| 197 | 	ns_t_any = 255, | ||
| 198 | 	ns_t_zxfr = 256, | ||
| 199 | 	ns_t_max = 65536 | ||
| 200 | } ns_type; | ||
| 201 | |||
| 202 | #define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ | ||
| 203 | 		 (t) == ns_t_mailb || (t) == ns_t_maila) | ||
| 204 | #define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) | ||
| 205 | #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) | ||
| 206 | #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) | ||
| 207 | #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ | ||
| 208 | 		 (t) == ns_t_zxfr) | ||
| 209 | |||
| 210 | typedef enum __ns_class { | ||
| 211 | 	ns_c_invalid = 0, | ||
| 212 | 	ns_c_in = 1, | ||
| 213 | 	ns_c_2 = 2, | ||
| 214 | 	ns_c_chaos = 3, | ||
| 215 | 	ns_c_hs = 4, | ||
| 216 | 	ns_c_none = 254, | ||
| 217 | 	ns_c_any = 255, | ||
| 218 | 	ns_c_max = 65536 | ||
| 219 | } ns_class; | ||
| 220 | |||
| 221 | typedef enum __ns_key_types { | ||
| 222 | 	ns_kt_rsa = 1, | ||
| 223 | 	ns_kt_dh = 2, | ||
| 224 | 	ns_kt_dsa = 3, | ||
| 225 | 	ns_kt_private = 254 | ||
| 226 | } ns_key_types; | ||
| 227 | |||
| 228 | typedef enum __ns_cert_types { | ||
| 229 | 	cert_t_pkix = 1, | ||
| 230 | 	cert_t_spki = 2, | ||
| 231 | 	cert_t_pgp = 3, | ||
| 232 | 	cert_t_url = 253, | ||
| 233 | 	cert_t_oid = 254 | ||
| 234 | } ns_cert_types; | ||
| 235 | |||
| 236 | #define	NS_KEY_TYPEMASK		0xC000 | ||
| 237 | #define	NS_KEY_TYPE_AUTH_CONF	0x0000 | ||
| 238 | #define	NS_KEY_TYPE_CONF_ONLY	0x8000 | ||
| 239 | #define	NS_KEY_TYPE_AUTH_ONLY	0x4000 | ||
| 240 | #define	NS_KEY_TYPE_NO_KEY	0xC000 | ||
| 241 | #define	NS_KEY_NO_AUTH		0x8000 | ||
| 242 | #define	NS_KEY_NO_CONF		0x4000 | ||
| 243 | #define	NS_KEY_RESERVED2	0x2000 | ||
| 244 | #define	NS_KEY_EXTENDED_FLAGS	0x1000 | ||
| 245 | #define	NS_KEY_RESERVED4	0x0800 | ||
| 246 | #define	NS_KEY_RESERVED5	0x0400 | ||
| 247 | #define	NS_KEY_NAME_TYPE	0x0300 | ||
| 248 | #define	NS_KEY_NAME_USER	0x0000 | ||
| 249 | #define	NS_KEY_NAME_ENTITY	0x0200 | ||
| 250 | #define	NS_KEY_NAME_ZONE	0x0100 | ||
| 251 | #define	NS_KEY_NAME_RESERVED	0x0300 | ||
| 252 | #define	NS_KEY_RESERVED8	0x0080 | ||
| 253 | #define	NS_KEY_RESERVED9	0x0040 | ||
| 254 | #define	NS_KEY_RESERVED10	0x0020 | ||
| 255 | #define	NS_KEY_RESERVED11	0x0010 | ||
| 256 | #define	NS_KEY_SIGNATORYMASK	0x000F | ||
| 257 | #define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ | ||
| 258 | 				 NS_KEY_RESERVED4 | \ | ||
| 259 | 				 NS_KEY_RESERVED5 | \ | ||
| 260 | 				 NS_KEY_RESERVED8 | \ | ||
| 261 | 				 NS_KEY_RESERVED9 | \ | ||
| 262 | 				 NS_KEY_RESERVED10 | \ | ||
| 263 | 				 NS_KEY_RESERVED11 ) | ||
| 264 | #define NS_KEY_RESERVED_BITMASK2 0xFFFF | ||
| 265 | #define	NS_ALG_MD5RSA		1 | ||
| 266 | #define	NS_ALG_DH 2 | ||
| 267 | #define	NS_ALG_DSA 3 | ||
| 268 | #define	NS_ALG_DSS NS_ALG_DSA | ||
| 269 | #define	NS_ALG_EXPIRE_ONLY	253 | ||
| 270 | #define	NS_ALG_PRIVATE_OID	254 | ||
| 271 | |||
| 272 | #define NS_KEY_PROT_TLS 1 | ||
| 273 | #define NS_KEY_PROT_EMAIL 2 | ||
| 274 | #define NS_KEY_PROT_DNSSEC 3 | ||
| 275 | #define NS_KEY_PROT_IPSEC 4 | ||
| 276 | #define NS_KEY_PROT_ANY		255 | ||
| 277 | |||
| 278 | #define	NS_MD5RSA_MIN_BITS	 512 | ||
| 279 | #define	NS_MD5RSA_MAX_BITS	4096 | ||
| 280 | #define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3) | ||
| 281 | #define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4) | ||
| 282 | #define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8) | ||
| 283 | #define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8) | ||
| 284 | |||
| 285 | #define NS_DSA_SIG_SIZE 41 | ||
| 286 | #define NS_DSA_MIN_SIZE 213 | ||
| 287 | #define NS_DSA_MAX_BYTES 405 | ||
| 288 | |||
| 289 | #define	NS_SIG_TYPE	0 | ||
| 290 | #define	NS_SIG_ALG	2 | ||
| 291 | #define	NS_SIG_LABELS	3 | ||
| 292 | #define	NS_SIG_OTTL	4 | ||
| 293 | #define	NS_SIG_EXPIR	8 | ||
| 294 | #define	NS_SIG_SIGNED	12 | ||
| 295 | #define	NS_SIG_FOOT	16 | ||
| 296 | #define	NS_SIG_SIGNER	18 | ||
| 297 | #define	NS_NXT_BITS 8 | ||
| 298 | #define	NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) | ||
| 299 | #define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) | ||
| 300 | #define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) | ||
| 301 | #define NS_NXT_MAX 127 | ||
| 302 | |||
| 303 | #define NS_OPT_DNSSEC_OK 0x8000U | ||
| 304 | #define NS_OPT_NSID		3 | ||
| 305 | |||
| 306 | #define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) | ||
| 307 | #define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) | ||
| 308 | #define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2) | ||
| 309 | #define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4) | ||
| 310 | |||
| 311 | unsigned ns_get16(const unsigned char *); | ||
| 312 | unsigned long ns_get32(const unsigned char *); | ||
| 313 | void ns_put16(unsigned, unsigned char *); | ||
| 314 | void ns_put32(unsigned long, unsigned char *); | ||
| 315 | |||
| 316 | int ns_initparse(const unsigned char *, int, ns_msg *); | ||
| 317 | int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); | ||
| 318 | int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int); | ||
| 319 | int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t); | ||
| 320 | |||
| 321 | |||
| 322 | #define	__BIND		19950621 | ||
| 323 | |||
| 324 | typedef struct { | ||
| 325 | 	unsigned	id :16; | ||
| 326 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 327 | 	unsigned	qr: 1; | ||
| 328 | 	unsigned	opcode: 4; | ||
| 329 | 	unsigned	aa: 1; | ||
| 330 | 	unsigned	tc: 1; | ||
| 331 | 	unsigned	rd: 1; | ||
| 332 | 	unsigned	ra: 1; | ||
| 333 | 	unsigned	unused :1; | ||
| 334 | 	unsigned	ad: 1; | ||
| 335 | 	unsigned	cd: 1; | ||
| 336 | 	unsigned	rcode :4; | ||
| 337 | #else | ||
| 338 | 	unsigned	rd :1; | ||
| 339 | 	unsigned	tc :1; | ||
| 340 | 	unsigned	aa :1; | ||
| 341 | 	unsigned	opcode :4; | ||
| 342 | 	unsigned	qr :1; | ||
| 343 | 	unsigned	rcode :4; | ||
| 344 | 	unsigned	cd: 1; | ||
| 345 | 	unsigned	ad: 1; | ||
| 346 | 	unsigned	unused :1; | ||
| 347 | 	unsigned	ra :1; | ||
| 348 | #endif | ||
| 349 | 	unsigned	qdcount :16; | ||
| 350 | 	unsigned	ancount :16; | ||
| 351 | 	unsigned	nscount :16; | ||
| 352 | 	unsigned	arcount :16; | ||
| 353 | } HEADER; | ||
| 354 | |||
| 355 | #define PACKETSZ	NS_PACKETSZ | ||
| 356 | #define MAXDNAME	NS_MAXDNAME | ||
| 357 | #define MAXCDNAME	NS_MAXCDNAME | ||
| 358 | #define MAXLABEL	NS_MAXLABEL | ||
| 359 | #define	HFIXEDSZ	NS_HFIXEDSZ | ||
| 360 | #define QFIXEDSZ	NS_QFIXEDSZ | ||
| 361 | #define RRFIXEDSZ	NS_RRFIXEDSZ | ||
| 362 | #define	INT32SZ		NS_INT32SZ | ||
| 363 | #define	INT16SZ		NS_INT16SZ | ||
| 364 | #define INT8SZ		NS_INT8SZ | ||
| 365 | #define	INADDRSZ	NS_INADDRSZ | ||
| 366 | #define	IN6ADDRSZ	NS_IN6ADDRSZ | ||
| 367 | #define	INDIR_MASK	NS_CMPRSFLGS | ||
| 368 | #define NAMESERVER_PORT	NS_DEFAULTPORT | ||
| 369 | |||
| 370 | #define S_ZONE		ns_s_zn | ||
| 371 | #define S_PREREQ	ns_s_pr | ||
| 372 | #define S_UPDATE	ns_s_ud | ||
| 373 | #define S_ADDT		ns_s_ar | ||
| 374 | |||
| 375 | #define QUERY		ns_o_query | ||
| 376 | #define IQUERY		ns_o_iquery | ||
| 377 | #define STATUS		ns_o_status | ||
| 378 | #define	NS_NOTIFY_OP	ns_o_notify | ||
| 379 | #define	NS_UPDATE_OP	ns_o_update | ||
| 380 | |||
| 381 | #define NOERROR		ns_r_noerror | ||
| 382 | #define FORMERR		ns_r_formerr | ||
| 383 | #define SERVFAIL	ns_r_servfail | ||
| 384 | #define NXDOMAIN	ns_r_nxdomain | ||
| 385 | #define NOTIMP		ns_r_notimpl | ||
| 386 | #define REFUSED		ns_r_refused | ||
| 387 | #define YXDOMAIN	ns_r_yxdomain | ||
| 388 | #define YXRRSET		ns_r_yxrrset | ||
| 389 | #define NXRRSET		ns_r_nxrrset | ||
| 390 | #define NOTAUTH		ns_r_notauth | ||
| 391 | #define NOTZONE		ns_r_notzone | ||
| 392 | |||
| 393 | #define DELETE		ns_uop_delete | ||
| 394 | #define ADD		ns_uop_add | ||
| 395 | |||
| 396 | #define T_A		ns_t_a | ||
| 397 | #define T_NS		ns_t_ns | ||
| 398 | #define T_MD		ns_t_md | ||
| 399 | #define T_MF		ns_t_mf | ||
| 400 | #define T_CNAME		ns_t_cname | ||
| 401 | #define T_SOA		ns_t_soa | ||
| 402 | #define T_MB		ns_t_mb | ||
| 403 | #define T_MG		ns_t_mg | ||
| 404 | #define T_MR		ns_t_mr | ||
| 405 | #define T_NULL		ns_t_null | ||
| 406 | #define T_WKS		ns_t_wks | ||
| 407 | #define T_PTR		ns_t_ptr | ||
| 408 | #define T_HINFO		ns_t_hinfo | ||
| 409 | #define T_MINFO		ns_t_minfo | ||
| 410 | #define T_MX		ns_t_mx | ||
| 411 | #define T_TXT		ns_t_txt | ||
| 412 | #define	T_RP		ns_t_rp | ||
| 413 | #define T_AFSDB		ns_t_afsdb | ||
| 414 | #define T_X25		ns_t_x25 | ||
| 415 | #define T_ISDN		ns_t_isdn | ||
| 416 | #define T_RT		ns_t_rt | ||
| 417 | #define T_NSAP		ns_t_nsap | ||
| 418 | #define T_NSAP_PTR	ns_t_nsap_ptr | ||
| 419 | #define	T_SIG		ns_t_sig | ||
| 420 | #define	T_KEY		ns_t_key | ||
| 421 | #define	T_PX		ns_t_px | ||
| 422 | #define	T_GPOS		ns_t_gpos | ||
| 423 | #define	T_AAAA		ns_t_aaaa | ||
| 424 | #define	T_LOC		ns_t_loc | ||
| 425 | #define	T_NXT		ns_t_nxt | ||
| 426 | #define	T_EID		ns_t_eid | ||
| 427 | #define	T_NIMLOC	ns_t_nimloc | ||
| 428 | #define	T_SRV		ns_t_srv | ||
| 429 | #define T_ATMA		ns_t_atma | ||
| 430 | #define T_NAPTR		ns_t_naptr | ||
| 431 | #define T_A6		ns_t_a6 | ||
| 432 | #define T_DNAME		ns_t_dname | ||
| 433 | #define	T_TSIG		ns_t_tsig | ||
| 434 | #define	T_IXFR		ns_t_ixfr | ||
| 435 | #define T_AXFR		ns_t_axfr | ||
| 436 | #define T_MAILB		ns_t_mailb | ||
| 437 | #define T_MAILA		ns_t_maila | ||
| 438 | #define T_ANY		ns_t_any | ||
| 439 | |||
| 440 | #define C_IN		ns_c_in | ||
| 441 | #define C_CHAOS		ns_c_chaos | ||
| 442 | #define C_HS		ns_c_hs | ||
| 443 | #define C_NONE		ns_c_none | ||
| 444 | #define C_ANY		ns_c_any | ||
| 445 | |||
| 446 | #define	GETSHORT		NS_GET16 | ||
| 447 | #define	GETLONG			NS_GET32 | ||
| 448 | #define	PUTSHORT		NS_PUT16 | ||
| 449 | #define	PUTLONG			NS_PUT32 | ||
| 450 | |||
| 451 | #ifdef __cplusplus | ||
| 452 | } | ||
| 453 | #endif | ||
| 454 | |||
| 455 | #endif | ||
lib/libc/include/wasm-wasi-musl/arpa/nameser_compat.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <arpa/nameser.h> | ||
| 2 | |||
lib/libc/include/wasm-wasi-musl/arpa/telnet.h created+251| ... | @@ -0,0 +1,251 @@ | ||
| 1 | #ifndef _ARPA_TELNET_H | ||
| 2 | #define	_ARPA_TELNET_H | ||
| 3 | |||
| 4 | #define	IAC	255 | ||
| 5 | #define	DONT	254 | ||
| 6 | #define	DO	253 | ||
| 7 | #define	WONT	252 | ||
| 8 | #define	WILL	251 | ||
| 9 | #define	SB	250 | ||
| 10 | #define	GA	249 | ||
| 11 | #define	EL	248 | ||
| 12 | #define	EC	247 | ||
| 13 | #define	AYT	246 | ||
| 14 | #define	AO	245 | ||
| 15 | #define	IP	244 | ||
| 16 | #define	BREAK	243 | ||
| 17 | #define	DM	242 | ||
| 18 | #define	NOP	241 | ||
| 19 | #define	SE	240 | ||
| 20 | #define EOR 239 | ||
| 21 | #define	ABORT	238 | ||
| 22 | #define	SUSP	237 | ||
| 23 | #define	xEOF	236 | ||
| 24 | |||
| 25 | #define SYNCH	242 | ||
| 26 | |||
| 27 | #define telcmds ((char [][6]){ "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0 }) | ||
| 28 | |||
| 29 | #define	TELCMD_FIRST	xEOF | ||
| 30 | #define	TELCMD_LAST	IAC | ||
| 31 | #define	TELCMD_OK(x)	((unsigned int)(x) <= TELCMD_LAST && \ | ||
| 32 | 			 (unsigned int)(x) >= TELCMD_FIRST) | ||
| 33 | #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST] | ||
| 34 | |||
| 35 | #define TELOPT_BINARY	0 | ||
| 36 | #define TELOPT_ECHO	1 | ||
| 37 | #define	TELOPT_RCP	2 | ||
| 38 | #define	TELOPT_SGA	3 | ||
| 39 | #define	TELOPT_NAMS	4 | ||
| 40 | #define	TELOPT_STATUS	5 | ||
| 41 | #define	TELOPT_TM	6 | ||
| 42 | #define	TELOPT_RCTE	7 | ||
| 43 | #define TELOPT_NAOL 	8 | ||
| 44 | #define TELOPT_NAOP 	9 | ||
| 45 | #define TELOPT_NAOCRD	10 | ||
| 46 | #define TELOPT_NAOHTS	11 | ||
| 47 | #define TELOPT_NAOHTD	12 | ||
| 48 | #define TELOPT_NAOFFD	13 | ||
| 49 | #define TELOPT_NAOVTS	14 | ||
| 50 | #define TELOPT_NAOVTD	15 | ||
| 51 | #define TELOPT_NAOLFD	16 | ||
| 52 | #define TELOPT_XASCII	17 | ||
| 53 | #define	TELOPT_LOGOUT	18 | ||
| 54 | #define	TELOPT_BM	19 | ||
| 55 | #define	TELOPT_DET	20 | ||
| 56 | #define	TELOPT_SUPDUP	21 | ||
| 57 | #define	TELOPT_SUPDUPOUTPUT 22 | ||
| 58 | #define	TELOPT_SNDLOC	23 | ||
| 59 | #define	TELOPT_TTYPE	24 | ||
| 60 | #define	TELOPT_EOR	25 | ||
| 61 | #define	TELOPT_TUID	26 | ||
| 62 | #define	TELOPT_OUTMRK	27 | ||
| 63 | #define	TELOPT_TTYLOC	28 | ||
| 64 | #define	TELOPT_3270REGIME 29 | ||
| 65 | #define	TELOPT_X3PAD	30 | ||
| 66 | #define	TELOPT_NAWS	31 | ||
| 67 | #define	TELOPT_TSPEED	32 | ||
| 68 | #define	TELOPT_LFLOW	33 | ||
| 69 | #define TELOPT_LINEMODE	34 | ||
| 70 | #define TELOPT_XDISPLOC	35 | ||
| 71 | #define TELOPT_OLD_ENVIRON 36 | ||
| 72 | #define	TELOPT_AUTHENTICATION 37/* Authenticate */ | ||
| 73 | #define	TELOPT_ENCRYPT	38 | ||
| 74 | #define TELOPT_NEW_ENVIRON 39 | ||
| 75 | #define	TELOPT_EXOPL	255 | ||
| 76 | |||
| 77 | |||
| 78 | #define	NTELOPTS	(1+TELOPT_NEW_ENVIRON) | ||
| 79 | #ifdef TELOPTS | ||
| 80 | char *telopts[NTELOPTS+1] = { | ||
| 81 | 	"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", | ||
| 82 | 	"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", | ||
| 83 | 	"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", | ||
| 84 | 	"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", | ||
| 85 | 	"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", | ||
| 86 | 	"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", | ||
| 87 | 	"TACACS UID", "OUTPUT MARKING", "TTYLOC", | ||
| 88 | 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", | ||
| 89 | 	"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", | ||
| 90 | 	"ENCRYPT", "NEW-ENVIRON", | ||
| 91 | 	0, | ||
| 92 | }; | ||
| 93 | #define	TELOPT_FIRST	TELOPT_BINARY | ||
| 94 | #define	TELOPT_LAST	TELOPT_NEW_ENVIRON | ||
| 95 | #define	TELOPT_OK(x)	((unsigned int)(x) <= TELOPT_LAST) | ||
| 96 | #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST] | ||
| 97 | #endif | ||
| 98 | |||
| 99 | #define	TELQUAL_IS	0 | ||
| 100 | #define	TELQUAL_SEND	1 | ||
| 101 | #define	TELQUAL_INFO	2 | ||
| 102 | #define	TELQUAL_REPLY	2 | ||
| 103 | #define	TELQUAL_NAME	3 | ||
| 104 | |||
| 105 | #define	LFLOW_OFF		0 | ||
| 106 | #define	LFLOW_ON		1 | ||
| 107 | #define	LFLOW_RESTART_ANY	2 | ||
| 108 | #define	LFLOW_RESTART_XON	3 | ||
| 109 | |||
| 110 | |||
| 111 | #define	LM_MODE		1 | ||
| 112 | #define	LM_FORWARDMASK	2 | ||
| 113 | #define	LM_SLC		3 | ||
| 114 | |||
| 115 | #define	MODE_EDIT	0x01 | ||
| 116 | #define	MODE_TRAPSIG	0x02 | ||
| 117 | #define	MODE_ACK	0x04 | ||
| 118 | #define MODE_SOFT_TAB	0x08 | ||
| 119 | #define MODE_LIT_ECHO	0x10 | ||
| 120 | |||
| 121 | #define	MODE_MASK	0x1f | ||
| 122 | |||
| 123 | #define MODE_FLOW		0x0100 | ||
| 124 | #define MODE_ECHO		0x0200 | ||
| 125 | #define MODE_INBIN		0x0400 | ||
| 126 | #define MODE_OUTBIN		0x0800 | ||
| 127 | #define MODE_FORCE		0x1000 | ||
| 128 | |||
| 129 | #define	SLC_SYNCH	1 | ||
| 130 | #define	SLC_BRK		2 | ||
| 131 | #define	SLC_IP		3 | ||
| 132 | #define	SLC_AO		4 | ||
| 133 | #define	SLC_AYT		5 | ||
| 134 | #define	SLC_EOR		6 | ||
| 135 | #define	SLC_ABORT	7 | ||
| 136 | #define	SLC_EOF		8 | ||
| 137 | #define	SLC_SUSP	9 | ||
| 138 | #define	SLC_EC		10 | ||
| 139 | #define	SLC_EL		11 | ||
| 140 | #define	SLC_EW		12 | ||
| 141 | #define	SLC_RP		13 | ||
| 142 | #define	SLC_LNEXT	14 | ||
| 143 | #define	SLC_XON		15 | ||
| 144 | #define	SLC_XOFF	16 | ||
| 145 | #define	SLC_FORW1	17 | ||
| 146 | #define	SLC_FORW2	18 | ||
| 147 | |||
| 148 | #define	NSLC		18 | ||
| 149 | |||
| 150 | #define	SLC_NAMELIST	"0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ | ||
| 151 | 			"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ | ||
| 152 | 			"LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0, | ||
| 153 | #ifdef	SLC_NAMES | ||
| 154 | char *slc_names[] = { | ||
| 155 | 	SLC_NAMELIST | ||
| 156 | }; | ||
| 157 | #else | ||
| 158 | extern char *slc_names[]; | ||
| 159 | #define	SLC_NAMES SLC_NAMELIST | ||
| 160 | #endif | ||
| 161 | |||
| 162 | #define	SLC_NAME_OK(x)	((unsigned int)(x) <= NSLC) | ||
| 163 | #define SLC_NAME(x)	slc_names[x] | ||
| 164 | |||
| 165 | #define	SLC_NOSUPPORT	0 | ||
| 166 | #define	SLC_CANTCHANGE	1 | ||
| 167 | #define	SLC_VARIABLE	2 | ||
| 168 | #define	SLC_DEFAULT	3 | ||
| 169 | #define	SLC_LEVELBITS	0x03 | ||
| 170 | |||
| 171 | #define	SLC_FUNC	0 | ||
| 172 | #define	SLC_FLAGS	1 | ||
| 173 | #define	SLC_VALUE	2 | ||
| 174 | |||
| 175 | #define	SLC_ACK		0x80 | ||
| 176 | #define	SLC_FLUSHIN	0x40 | ||
| 177 | #define	SLC_FLUSHOUT	0x20 | ||
| 178 | |||
| 179 | #define	OLD_ENV_VAR	1 | ||
| 180 | #define	OLD_ENV_VALUE	0 | ||
| 181 | #define	NEW_ENV_VAR	0 | ||
| 182 | #define	NEW_ENV_VALUE	1 | ||
| 183 | #define	ENV_ESC		2 | ||
| 184 | #define ENV_USERVAR	3 | ||
| 185 | |||
| 186 | #define	AUTH_WHO_CLIENT		0 | ||
| 187 | #define	AUTH_WHO_SERVER		1 | ||
| 188 | #define	AUTH_WHO_MASK		1 | ||
| 189 | |||
| 190 | #define	AUTH_HOW_ONE_WAY	0 | ||
| 191 | #define	AUTH_HOW_MUTUAL		2 | ||
| 192 | #define	AUTH_HOW_MASK		2 | ||
| 193 | |||
| 194 | #define	AUTHTYPE_NULL		0 | ||
| 195 | #define	AUTHTYPE_KERBEROS_V4	1 | ||
| 196 | #define	AUTHTYPE_KERBEROS_V5	2 | ||
| 197 | #define	AUTHTYPE_SPX		3 | ||
| 198 | #define	AUTHTYPE_MINK		4 | ||
| 199 | #define	AUTHTYPE_CNT		5 | ||
| 200 | |||
| 201 | #define	AUTHTYPE_TEST		99 | ||
| 202 | |||
| 203 | #ifdef	AUTH_NAMES | ||
| 204 | char *authtype_names[] = { | ||
| 205 | 	"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, | ||
| 206 | }; | ||
| 207 | #else | ||
| 208 | extern char *authtype_names[]; | ||
| 209 | #endif | ||
| 210 | |||
| 211 | #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT) | ||
| 212 | #define	AUTHTYPE_NAME(x)	authtype_names[x] | ||
| 213 | |||
| 214 | #define	ENCRYPT_IS		0 | ||
| 215 | #define	ENCRYPT_SUPPORT		1 | ||
| 216 | #define	ENCRYPT_REPLY		2 | ||
| 217 | #define	ENCRYPT_START		3 | ||
| 218 | #define	ENCRYPT_END		4 | ||
| 219 | #define	ENCRYPT_REQSTART	5 | ||
| 220 | #define	ENCRYPT_REQEND		6 | ||
| 221 | #define	ENCRYPT_ENC_KEYID	7 | ||
| 222 | #define	ENCRYPT_DEC_KEYID	8 | ||
| 223 | #define	ENCRYPT_CNT		9 | ||
| 224 | |||
| 225 | #define	ENCTYPE_ANY		0 | ||
| 226 | #define	ENCTYPE_DES_CFB64	1 | ||
| 227 | #define	ENCTYPE_DES_OFB64	2 | ||
| 228 | #define	ENCTYPE_CNT		3 | ||
| 229 | |||
| 230 | #ifdef	ENCRYPT_NAMES | ||
| 231 | char *encrypt_names[] = { | ||
| 232 | 	"IS", "SUPPORT", "REPLY", "START", "END", | ||
| 233 | 	"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", | ||
| 234 | 	0, | ||
| 235 | }; | ||
| 236 | char *enctype_names[] = { | ||
| 237 | 	"ANY", "DES_CFB64", "DES_OFB64", 0, | ||
| 238 | }; | ||
| 239 | #else | ||
| 240 | extern char *encrypt_names[]; | ||
| 241 | extern char *enctype_names[]; | ||
| 242 | #endif | ||
| 243 | |||
| 244 | |||
| 245 | #define	ENCRYPT_NAME_OK(x)	((unsigned int)(x) < ENCRYPT_CNT) | ||
| 246 | #define	ENCRYPT_NAME(x)		encrypt_names[x] | ||
| 247 | |||
| 248 | #define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < ENCTYPE_CNT) | ||
| 249 | #define	ENCTYPE_NAME(x)		enctype_names[x] | ||
| 250 | |||
| 251 | #endif | ||
lib/libc/include/wasm-wasi-musl/arpa/tftp.h created+31| ... | @@ -0,0 +1,31 @@ | ||
| 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/assert.h created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | #undef assert | ||
| 4 | |||
| 5 | #ifdef NDEBUG | ||
| 6 | #define	assert(x) (void)0 | ||
| 7 | #else | ||
| 8 | #define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #if __STDC_VERSION__ >= 201112L && !defined(__cplusplus) | ||
| 12 | #define static_assert _Static_assert | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | extern "C" { | ||
| 17 | #endif | ||
| 18 | |||
| 19 | _Noreturn void __assert_fail (const char *, const char *, int, const char *); | ||
| 20 | |||
| 21 | #ifdef __cplusplus | ||
| 22 | } | ||
| 23 | #endif | ||
lib/libc/include/wasm-wasi-musl/bits/alltypes.h created+460| ... | @@ -0,0 +1,460 @@ | ||
| 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 created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__struct_dirent.h> | ||
lib/libc/include/wasm-wasi-musl/bits/fcntl.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | /* Use the WASI libc fcntl implementation bits. */ | ||
lib/libc/include/wasm-wasi-musl/bits/fenv.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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/float.h created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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/include/wasm-wasi-musl/bits/hwcap.h createdlib/libc/include/wasm-wasi-musl/bits/io.h createdlib/libc/include/wasm-wasi-musl/bits/ioctl.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | /* Use the WASI libc ioctl implementation bits. */ | ||
lib/libc/include/wasm-wasi-musl/bits/ioctl_fix.h createdlib/libc/include/wasm-wasi-musl/bits/ipcstat.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #define IPC_STAT 2 | ||
lib/libc/include/wasm-wasi-musl/bits/limits.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__macro_PAGESIZE.h> | ||
lib/libc/include/wasm-wasi-musl/bits/mman.h createdlib/libc/include/wasm-wasi-musl/bits/poll.h createdlib/libc/include/wasm-wasi-musl/bits/posix.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #define _POSIX_V6_ILP32_OFFBIG (1) | ||
| 2 | #define _POSIX_V7_ILP32_OFFBIG (1) | ||
lib/libc/include/wasm-wasi-musl/bits/reg.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #undef __WORDSIZE | ||
| 2 | #define __WORDSIZE 64 | ||
lib/libc/include/wasm-wasi-musl/bits/resource.h createdlib/libc/include/wasm-wasi-musl/bits/signal.h created+40| ... | @@ -0,0 +1,40 @@ | ||
| 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/socket.h createdlib/libc/include/wasm-wasi-musl/bits/stat.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__struct_stat.h> | ||
lib/libc/include/wasm-wasi-musl/bits/stdint.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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/byteswap.h created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #ifndef _BYTESWAP_H | ||
| 2 | #define _BYTESWAP_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | |||
| 7 | static __inline uint16_t __bswap_16(uint16_t __x) | ||
| 8 | { | ||
| 9 | 	return __x<<8 | __x>>8; | ||
| 10 | } | ||
| 11 | |||
| 12 | static __inline uint32_t __bswap_32(uint32_t __x) | ||
| 13 | { | ||
| 14 | 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; | ||
| 15 | } | ||
| 16 | |||
| 17 | static __inline uint64_t __bswap_64(uint64_t __x) | ||
| 18 | { | ||
| 19 | 	return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32); | ||
| 20 | } | ||
| 21 | |||
| 22 | #define bswap_16(x) __bswap_16(x) | ||
| 23 | #define bswap_32(x) __bswap_32(x) | ||
| 24 | #define bswap_64(x) __bswap_64(x) | ||
| 25 | |||
| 26 | #endif | ||
lib/libc/include/wasm-wasi-musl/complex.h created+143| ... | @@ -0,0 +1,143 @@ | ||
| 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/cpio.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef _CPIO_H | ||
| 2 | #define _CPIO_H | ||
| 3 | |||
| 4 | #define MAGIC "070707" | ||
| 5 | |||
| 6 | #define C_IRUSR 000400 | ||
| 7 | #define C_IWUSR 000200 | ||
| 8 | #define C_IXUSR 000100 | ||
| 9 | #define C_IRGRP 000040 | ||
| 10 | #define C_IWGRP 000020 | ||
| 11 | #define C_IXGRP 000010 | ||
| 12 | #define C_IROTH 000004 | ||
| 13 | #define C_IWOTH 000002 | ||
| 14 | #define C_IXOTH 000001 | ||
| 15 | |||
| 16 | #define C_ISUID 004000 | ||
| 17 | #define C_ISGID 002000 | ||
| 18 | #define C_ISVTX 001000 | ||
| 19 | |||
| 20 | #define C_ISBLK 060000 | ||
| 21 | #define C_ISCHR 020000 | ||
| 22 | #define C_ISDIR 040000 | ||
| 23 | #define C_ISFIFO 010000 | ||
| 24 | #define C_ISSOCK 0140000 | ||
| 25 | #define C_ISLNK 0120000 | ||
| 26 | #define C_ISCTG 0110000 | ||
| 27 | #define C_ISREG 0100000 | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/include/wasm-wasi-musl/crypt.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _CRYPT_H | ||
| 2 | #define _CRYPT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | struct crypt_data { | ||
| 9 | 	int initialized; | ||
| 10 | 	char __buf[256]; | ||
| 11 | }; | ||
| 12 | |||
| 13 | char *crypt(const char *, const char *); | ||
| 14 | char *crypt_r(const char *, const char *, struct crypt_data *); | ||
| 15 | |||
| 16 | #ifdef __cplusplus | ||
| 17 | } | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/include/wasm-wasi-musl/ctype.h created+75| ... | @@ -0,0 +1,75 @@ | ||
| 1 | #ifndef	_CTYPE_H | ||
| 2 | #define	_CTYPE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | int isalnum(int); | ||
| 11 | int isalpha(int); | ||
| 12 | int isblank(int); | ||
| 13 | int iscntrl(int); | ||
| 14 | int isdigit(int); | ||
| 15 | int isgraph(int); | ||
| 16 | int islower(int); | ||
| 17 | int isprint(int); | ||
| 18 | int ispunct(int); | ||
| 19 | int isspace(int); | ||
| 20 | int isupper(int); | ||
| 21 | int isxdigit(int); | ||
| 22 | int tolower(int); | ||
| 23 | int toupper(int); | ||
| 24 | |||
| 25 | #ifndef __cplusplus | ||
| 26 | static __inline int __isspace(int _c) | ||
| 27 | { | ||
| 28 | 	return _c == ' ' || (unsigned)_c-'\t' < 5; | ||
| 29 | } | ||
| 30 | |||
| 31 | #define isalpha(a) (0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26) | ||
| 32 | #define isdigit(a) (0 ? isdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 33 | #define islower(a) (0 ? islower(a) : ((unsigned)(a)-'a') < 26) | ||
| 34 | #define isupper(a) (0 ? isupper(a) : ((unsigned)(a)-'A') < 26) | ||
| 35 | #define isprint(a) (0 ? isprint(a) : ((unsigned)(a)-0x20) < 0x5f) | ||
| 36 | #define isgraph(a) (0 ? isgraph(a) : ((unsigned)(a)-0x21) < 0x5e) | ||
| 37 | #define isspace(a) __isspace(a) | ||
| 38 | #endif | ||
| 39 | |||
| 40 | |||
| 41 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 42 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 43 | || defined(_BSD_SOURCE) | ||
| 44 | |||
| 45 | #define __NEED_locale_t | ||
| 46 | #include <bits/alltypes.h> | ||
| 47 | |||
| 48 | int isalnum_l(int, locale_t); | ||
| 49 | int isalpha_l(int, locale_t); | ||
| 50 | int isblank_l(int, locale_t); | ||
| 51 | int iscntrl_l(int, locale_t); | ||
| 52 | int isdigit_l(int, locale_t); | ||
| 53 | int isgraph_l(int, locale_t); | ||
| 54 | int islower_l(int, locale_t); | ||
| 55 | int isprint_l(int, locale_t); | ||
| 56 | int ispunct_l(int, locale_t); | ||
| 57 | int isspace_l(int, locale_t); | ||
| 58 | int isupper_l(int, locale_t); | ||
| 59 | int isxdigit_l(int, locale_t); | ||
| 60 | int tolower_l(int, locale_t); | ||
| 61 | int toupper_l(int, locale_t); | ||
| 62 | |||
| 63 | int isascii(int); | ||
| 64 | int toascii(int); | ||
| 65 | #define _tolower(a) ((a)|0x20) | ||
| 66 | #define _toupper(a) ((a)&0x5f) | ||
| 67 | #define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128) | ||
| 68 | |||
| 69 | #endif | ||
| 70 | |||
| 71 | #ifdef __cplusplus | ||
| 72 | } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #endif | ||
lib/libc/include/wasm-wasi-musl/dirent.h created+89| ... | @@ -0,0 +1,89 @@ | ||
| 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/endian.h created+80| ... | @@ -0,0 +1,80 @@ | ||
| 1 | #ifndef _ENDIAN_H | ||
| 2 | #define _ENDIAN_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | #define __NEED_uint16_t | ||
| 7 | #define __NEED_uint32_t | ||
| 8 | #define __NEED_uint64_t | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #define __PDP_ENDIAN 3412 | ||
| 13 | |||
| 14 | #define BIG_ENDIAN __BIG_ENDIAN | ||
| 15 | #define LITTLE_ENDIAN __LITTLE_ENDIAN | ||
| 16 | #define PDP_ENDIAN __PDP_ENDIAN | ||
| 17 | #define BYTE_ORDER __BYTE_ORDER | ||
| 18 | |||
| 19 | static __inline uint16_t __bswap16(uint16_t __x) | ||
| 20 | { | ||
| 21 | 	return __x<<8 | __x>>8; | ||
| 22 | } | ||
| 23 | |||
| 24 | static __inline uint32_t __bswap32(uint32_t __x) | ||
| 25 | { | ||
| 26 | 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; | ||
| 27 | } | ||
| 28 | |||
| 29 | static __inline uint64_t __bswap64(uint64_t __x) | ||
| 30 | { | ||
| 31 | 	return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32); | ||
| 32 | } | ||
| 33 | |||
| 34 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 35 | #define htobe16(x) __bswap16(x) | ||
| 36 | #define be16toh(x) __bswap16(x) | ||
| 37 | #define htobe32(x) __bswap32(x) | ||
| 38 | #define be32toh(x) __bswap32(x) | ||
| 39 | #define htobe64(x) __bswap64(x) | ||
| 40 | #define be64toh(x) __bswap64(x) | ||
| 41 | #define htole16(x) (uint16_t)(x) | ||
| 42 | #define le16toh(x) (uint16_t)(x) | ||
| 43 | #define htole32(x) (uint32_t)(x) | ||
| 44 | #define le32toh(x) (uint32_t)(x) | ||
| 45 | #define htole64(x) (uint64_t)(x) | ||
| 46 | #define le64toh(x) (uint64_t)(x) | ||
| 47 | #else | ||
| 48 | #define htobe16(x) (uint16_t)(x) | ||
| 49 | #define be16toh(x) (uint16_t)(x) | ||
| 50 | #define htobe32(x) (uint32_t)(x) | ||
| 51 | #define be32toh(x) (uint32_t)(x) | ||
| 52 | #define htobe64(x) (uint64_t)(x) | ||
| 53 | #define be64toh(x) (uint64_t)(x) | ||
| 54 | #define htole16(x) __bswap16(x) | ||
| 55 | #define le16toh(x) __bswap16(x) | ||
| 56 | #define htole32(x) __bswap32(x) | ||
| 57 | #define le32toh(x) __bswap32(x) | ||
| 58 | #define htole64(x) __bswap64(x) | ||
| 59 | #define le64toh(x) __bswap64(x) | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 63 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 64 | #define betoh16(x) __bswap16(x) | ||
| 65 | #define betoh32(x) __bswap32(x) | ||
| 66 | #define betoh64(x) __bswap64(x) | ||
| 67 | #define letoh16(x) (uint16_t)(x) | ||
| 68 | #define letoh32(x) (uint32_t)(x) | ||
| 69 | #define letoh64(x) (uint64_t)(x) | ||
| 70 | #else | ||
| 71 | #define betoh16(x) (uint16_t)(x) | ||
| 72 | #define betoh32(x) (uint32_t)(x) | ||
| 73 | #define betoh64(x) (uint64_t)(x) | ||
| 74 | #define letoh16(x) __bswap16(x) | ||
| 75 | #define letoh32(x) __bswap32(x) | ||
| 76 | #define letoh64(x) __bswap64(x) | ||
| 77 | #endif | ||
| 78 | #endif | ||
| 79 | |||
| 80 | #endif | ||
lib/libc/include/wasm-wasi-musl/err.h created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #ifndef _ERR_H | ||
| 2 | #define _ERR_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <stdarg.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | void warn(const char *, ...); | ||
| 12 | void vwarn(const char *, va_list); | ||
| 13 | void warnx(const char *, ...); | ||
| 14 | void vwarnx(const char *, va_list); | ||
| 15 | |||
| 16 | _Noreturn void err(int, const char *, ...); | ||
| 17 | _Noreturn void verr(int, const char *, va_list); | ||
| 18 | _Noreturn void errx(int, const char *, ...); | ||
| 19 | _Noreturn void verrx(int, const char *, va_list); | ||
| 20 | |||
| 21 | #ifdef __cplusplus | ||
| 22 | } | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #endif | ||
lib/libc/include/wasm-wasi-musl/errno.h created+32| ... | @@ -0,0 +1,32 @@ | ||
| 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 created+246| ... | @@ -0,0 +1,246 @@ | ||
| 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 | #define fallocate64 fallocate | ||
| 207 | #endif | ||
| 208 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 209 | int name_to_handle_at(int, const char *, struct file_handle *, int *, int); | ||
| 210 | int open_by_handle_at(int, struct file_handle *, int); | ||
| 211 | #endif | ||
| 212 | #ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */ | ||
| 213 | ssize_t readahead(int, off_t, size_t); | ||
| 214 | #endif | ||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */ | ||
| 216 | int sync_file_range(int, off_t, off_t, unsigned); | ||
| 217 | ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); | ||
| 218 | ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 219 | ssize_t tee(int, int, size_t, unsigned); | ||
| 220 | #endif | ||
| 221 | #define loff_t off_t | ||
| 222 | #endif | ||
| 223 | |||
| 224 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 225 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 226 | #define F_GETLK64 F_GETLK | ||
| 227 | #define F_SETLK64 F_SETLK | ||
| 228 | #define F_SETLKW64 F_SETLKW | ||
| 229 | #define flock64 flock | ||
| 230 | #endif | ||
| 231 | #define open64 open | ||
| 232 | #define openat64 openat | ||
| 233 | #define creat64 creat | ||
| 234 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 235 | #define lockf64 lockf | ||
| 236 | #endif | ||
| 237 | #define posix_fadvise64 posix_fadvise | ||
| 238 | #define posix_fallocate64 posix_fallocate | ||
| 239 | #define off64_t off_t | ||
| 240 | #endif | ||
| 241 | |||
| 242 | #ifdef __cplusplus | ||
| 243 | } | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #endif | ||
lib/libc/include/wasm-wasi-musl/features.h created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #ifndef _FEATURES_H | ||
| 2 | #define _FEATURES_H | ||
| 3 | |||
| 4 | #if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) | ||
| 5 | #define _GNU_SOURCE 1 | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) | ||
| 9 | #define _BSD_SOURCE 1 | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ | ||
| 13 | && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ | ||
| 14 | && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) | ||
| 15 | #define _BSD_SOURCE 1 | ||
| 16 | #define _XOPEN_SOURCE 700 | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #if __STDC_VERSION__ >= 199901L | ||
| 20 | #define __restrict restrict | ||
| 21 | #elif !defined(__GNUC__) | ||
| 22 | #define __restrict | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) | ||
| 26 | #define __inline inline | ||
| 27 | #elif !defined(__GNUC__) | ||
| 28 | #define __inline | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #if __STDC_VERSION__ >= 201112L | ||
| 32 | #elif defined(__GNUC__) | ||
| 33 | #define _Noreturn __attribute__((__noreturn__)) | ||
| 34 | #else | ||
| 35 | #define _Noreturn | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #define __REDIR(x,y) __typeof__(x) x __asm__(#y) | ||
| 39 | |||
| 40 | #endif | ||
lib/libc/include/wasm-wasi-musl/fenv.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 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 created+56| ... | @@ -0,0 +1,56 @@ | ||
| 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/fmtmsg.h created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #ifndef _FMTMSG_H | ||
| 2 | #define _FMTMSG_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define MM_HARD		1 | ||
| 9 | #define MM_SOFT		2 | ||
| 10 | #define MM_FIRM		4 | ||
| 11 | |||
| 12 | #define MM_APPL		8 | ||
| 13 | #define MM_UTIL		16 | ||
| 14 | #define MM_OPSYS	32 | ||
| 15 | |||
| 16 | #define MM_RECOVER	64 | ||
| 17 | #define MM_NRECOV	128 | ||
| 18 | |||
| 19 | #define MM_PRINT	256 | ||
| 20 | #define MM_CONSOLE	512 | ||
| 21 | |||
| 22 | #define MM_NULLMC	0L | ||
| 23 | |||
| 24 | #define MM_HALT		1 | ||
| 25 | #define MM_ERROR	2 | ||
| 26 | #define MM_WARNING	3 | ||
| 27 | #define MM_INFO		4 | ||
| 28 | #define MM_NOSEV	0 | ||
| 29 | |||
| 30 | #define MM_OK		0 | ||
| 31 | #define MM_NOTOK	(-1) | ||
| 32 | #define MM_NOMSG	1 | ||
| 33 | #define MM_NOCON	4 | ||
| 34 | |||
| 35 | #define MM_NULLLBL	((char*)0) | ||
| 36 | #define MM_NULLTXT	((char*)0) | ||
| 37 | #define MM_NULLACT	((char*)0) | ||
| 38 | #define MM_NULLTAG	((char*)0) | ||
| 39 | #define MM_NULLSEV	0 | ||
| 40 | |||
| 41 | int fmtmsg(long, const char *, int, const char *, const char *, const char *); | ||
| 42 | |||
| 43 | #ifdef __cplusplus | ||
| 44 | } | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #endif | ||
lib/libc/include/wasm-wasi-musl/fnmatch.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #ifndef	_FNMATCH_H | ||
| 2 | #define	_FNMATCH_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define	FNM_PATHNAME 0x1 | ||
| 9 | #define	FNM_NOESCAPE 0x2 | ||
| 10 | #define	FNM_PERIOD 0x4 | ||
| 11 | #define	FNM_LEADING_DIR	0x8 | ||
| 12 | #define	FNM_CASEFOLD	0x10 | ||
| 13 | #define	FNM_FILE_NAME	FNM_PATHNAME | ||
| 14 | |||
| 15 | #define	FNM_NOMATCH 1 | ||
| 16 | #define FNM_NOSYS (-1) | ||
| 17 | |||
| 18 | int fnmatch(const char *, const char *, int); | ||
| 19 | |||
| 20 | #ifdef __cplusplus | ||
| 21 | } | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif | ||
lib/libc/include/wasm-wasi-musl/ftw.h created+45| ... | @@ -0,0 +1,45 @@ | ||
| 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/getopt.h created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #ifndef _GETOPT_H | ||
| 2 | #define _GETOPT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | int getopt(int, char * const [], const char *); | ||
| 9 | extern char *optarg; | ||
| 10 | extern int optind, opterr, optopt, optreset; | ||
| 11 | |||
| 12 | struct option { | ||
| 13 | 	const char *name; | ||
| 14 | 	int has_arg; | ||
| 15 | 	int *flag; | ||
| 16 | 	int val; | ||
| 17 | }; | ||
| 18 | |||
| 19 | int getopt_long(int, char *const *, const char *, const struct option *, int *); | ||
| 20 | int getopt_long_only(int, char *const *, const char *, const struct option *, int *); | ||
| 21 | |||
| 22 | #define no_argument 0 | ||
| 23 | #define required_argument 1 | ||
| 24 | #define optional_argument 2 | ||
| 25 | |||
| 26 | #ifdef __cplusplus | ||
| 27 | } | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #endif | ||
lib/libc/include/wasm-wasi-musl/glob.h created+54| ... | @@ -0,0 +1,54 @@ | ||
| 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/iconv.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #ifndef _ICONV_H | ||
| 2 | #define _ICONV_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 void *iconv_t; | ||
| 15 | |||
| 16 | iconv_t iconv_open(const char *, const char *); | ||
| 17 | size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict); | ||
| 18 | int iconv_close(iconv_t); | ||
| 19 | |||
| 20 | #ifdef __cplusplus | ||
| 21 | } | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif | ||
lib/libc/include/wasm-wasi-musl/ifaddrs.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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 created+233| ... | @@ -0,0 +1,233 @@ | ||
| 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/iso646.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _ISO646_H | ||
| 2 | #define _ISO646_H | ||
| 3 | |||
| 4 | #ifndef __cplusplus | ||
| 5 | |||
| 6 | #define and && | ||
| 7 | #define and_eq &= | ||
| 8 | #define bitand & | ||
| 9 | #define bitor | | ||
| 10 | #define compl ~ | ||
| 11 | #define not ! | ||
| 12 | #define not_eq != | ||
| 13 | #define or || | ||
| 14 | #define or_eq |= | ||
| 15 | #define xor ^ | ||
| 16 | #define xor_eq ^= | ||
| 17 | |||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/include/wasm-wasi-musl/langinfo.h created+98| ... | @@ -0,0 +1,98 @@ | ||
| 1 | #ifndef _LANGINFO_H | ||
| 2 | #define _LANGINFO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <nl_types.h> | ||
| 10 | |||
| 11 | #define __NEED_locale_t | ||
| 12 | |||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | #define ABDAY_1 0x20000 | ||
| 16 | #define ABDAY_2 0x20001 | ||
| 17 | #define ABDAY_3 0x20002 | ||
| 18 | #define ABDAY_4 0x20003 | ||
| 19 | #define ABDAY_5 0x20004 | ||
| 20 | #define ABDAY_6 0x20005 | ||
| 21 | #define ABDAY_7 0x20006 | ||
| 22 | |||
| 23 | #define DAY_1 0x20007 | ||
| 24 | #define DAY_2 0x20008 | ||
| 25 | #define DAY_3 0x20009 | ||
| 26 | #define DAY_4 0x2000A | ||
| 27 | #define DAY_5 0x2000B | ||
| 28 | #define DAY_6 0x2000C | ||
| 29 | #define DAY_7 0x2000D | ||
| 30 | |||
| 31 | #define ABMON_1 0x2000E | ||
| 32 | #define ABMON_2 0x2000F | ||
| 33 | #define ABMON_3 0x20010 | ||
| 34 | #define ABMON_4 0x20011 | ||
| 35 | #define ABMON_5 0x20012 | ||
| 36 | #define ABMON_6 0x20013 | ||
| 37 | #define ABMON_7 0x20014 | ||
| 38 | #define ABMON_8 0x20015 | ||
| 39 | #define ABMON_9 0x20016 | ||
| 40 | #define ABMON_10 0x20017 | ||
| 41 | #define ABMON_11 0x20018 | ||
| 42 | #define ABMON_12 0x20019 | ||
| 43 | |||
| 44 | #define MON_1 0x2001A | ||
| 45 | #define MON_2 0x2001B | ||
| 46 | #define MON_3 0x2001C | ||
| 47 | #define MON_4 0x2001D | ||
| 48 | #define MON_5 0x2001E | ||
| 49 | #define MON_6 0x2001F | ||
| 50 | #define MON_7 0x20020 | ||
| 51 | #define MON_8 0x20021 | ||
| 52 | #define MON_9 0x20022 | ||
| 53 | #define MON_10 0x20023 | ||
| 54 | #define MON_11 0x20024 | ||
| 55 | #define MON_12 0x20025 | ||
| 56 | |||
| 57 | #define AM_STR 0x20026 | ||
| 58 | #define PM_STR 0x20027 | ||
| 59 | |||
| 60 | #define D_T_FMT 0x20028 | ||
| 61 | #define D_FMT 0x20029 | ||
| 62 | #define T_FMT 0x2002A | ||
| 63 | #define T_FMT_AMPM 0x2002B | ||
| 64 | |||
| 65 | #define ERA 0x2002C | ||
| 66 | #define ERA_D_FMT 0x2002E | ||
| 67 | #define ALT_DIGITS 0x2002F | ||
| 68 | #define ERA_D_T_FMT 0x20030 | ||
| 69 | #define ERA_T_FMT 0x20031 | ||
| 70 | |||
| 71 | #define CODESET 14 | ||
| 72 | |||
| 73 | #define CRNCYSTR 0x4000F | ||
| 74 | |||
| 75 | #define RADIXCHAR 0x10000 | ||
| 76 | #define THOUSEP 0x10001 | ||
| 77 | #define YESEXPR 0x50000 | ||
| 78 | #define NOEXPR 0x50001 | ||
| 79 | |||
| 80 | #define _NL_LOCALE_NAME(cat) (((cat)<<16) | 0xffff) | ||
| 81 | |||
| 82 | #if defined(_GNU_SOURCE) | ||
| 83 | #define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat) | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 87 | #define YESSTR 0x50002 | ||
| 88 | #define NOSTR 0x50003 | ||
| 89 | #endif | ||
| 90 | |||
| 91 | char *nl_langinfo(nl_item); | ||
| 92 | char *nl_langinfo_l(nl_item, locale_t); | ||
| 93 | |||
| 94 | #ifdef __cplusplus | ||
| 95 | } | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #endif | ||
lib/libc/include/wasm-wasi-musl/libgen.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #ifndef _LIBGEN_H | ||
| 2 | #define _LIBGEN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | char *dirname(char *); | ||
| 9 | char *basename(char *); | ||
| 10 | |||
| 11 | #ifdef __cplusplus | ||
| 12 | } | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/include/wasm-wasi-musl/limits.h created+180| ... | @@ -0,0 +1,180 @@ | ||
| 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 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 69 | #define PTHREAD_KEYS_MAX 128 | ||
| 70 | #define PTHREAD_STACK_MIN 2048 | ||
| 71 | #define PTHREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 72 | #endif | ||
| 73 | #ifdef __wasilibc_unmodified_upstream /* WASI has no semaphores */ | ||
| 74 | #define SEM_VALUE_MAX 0x7fffffff | ||
| 75 | #define SEM_NSEMS_MAX 256 | ||
| 76 | #endif | ||
| 77 | #define DELAYTIMER_MAX 0x7fffffff | ||
| 78 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mq */ | ||
| 79 | #define MQ_PRIO_MAX 32768 | ||
| 80 | #endif | ||
| 81 | #ifdef __wasilibc_unmodified_upstream /* WASI has no usernames */ | ||
| 82 | #define LOGIN_NAME_MAX 256 | ||
| 83 | #endif | ||
| 84 | |||
| 85 | /* Arbitrary numbers... */ | ||
| 86 | |||
| 87 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 88 | #define BC_BASE_MAX 99 | ||
| 89 | #define BC_DIM_MAX 2048 | ||
| 90 | #define BC_SCALE_MAX 99 | ||
| 91 | #define BC_STRING_MAX 1000 | ||
| 92 | #endif | ||
| 93 | #define CHARCLASS_NAME_MAX 14 | ||
| 94 | #define COLL_WEIGHTS_MAX 2 | ||
| 95 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 96 | #define EXPR_NEST_MAX 32 | ||
| 97 | #define LINE_MAX 4096 | ||
| 98 | #endif | ||
| 99 | #define RE_DUP_MAX 255 | ||
| 100 | |||
| 101 | #define NL_ARGMAX 9 | ||
| 102 | #define NL_MSGMAX 32767 | ||
| 103 | #define NL_SETMAX 255 | ||
| 104 | #define NL_TEXTMAX 2048 | ||
| 105 | |||
| 106 | #endif | ||
| 107 | |||
| 108 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) | ||
| 109 | |||
| 110 | #ifdef PAGESIZE | ||
| 111 | #define PAGE_SIZE PAGESIZE | ||
| 112 | #endif | ||
| 113 | #define NZERO 20 | ||
| 114 | #define NL_LANGMAX 32 | ||
| 115 | |||
| 116 | #endif | ||
| 117 | |||
| 118 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 119 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 120 | |||
| 121 | #define NL_NMAX 16 | ||
| 122 | |||
| 123 | #endif | ||
| 124 | |||
| 125 | /* POSIX/SUS requirements follow. These numbers come directly | ||
| 126 | * from SUS and have nothing to do with the host system. */ | ||
| 127 | |||
| 128 | #define _POSIX_AIO_LISTIO_MAX 2 | ||
| 129 | #define _POSIX_AIO_MAX 1 | ||
| 130 | #define _POSIX_ARG_MAX 4096 | ||
| 131 | #define _POSIX_CHILD_MAX 25 | ||
| 132 | #define _POSIX_CLOCKRES_MIN 20000000 | ||
| 133 | #define _POSIX_DELAYTIMER_MAX 32 | ||
| 134 | #define _POSIX_HOST_NAME_MAX 255 | ||
| 135 | #define _POSIX_LINK_MAX 8 | ||
| 136 | #define _POSIX_LOGIN_NAME_MAX 9 | ||
| 137 | #define _POSIX_MAX_CANON 255 | ||
| 138 | #define _POSIX_MAX_INPUT 255 | ||
| 139 | #define _POSIX_MQ_OPEN_MAX 8 | ||
| 140 | #define _POSIX_MQ_PRIO_MAX 32 | ||
| 141 | #define _POSIX_NAME_MAX 14 | ||
| 142 | #define _POSIX_NGROUPS_MAX 8 | ||
| 143 | #define _POSIX_OPEN_MAX 20 | ||
| 144 | #define _POSIX_PATH_MAX 256 | ||
| 145 | #define _POSIX_PIPE_BUF 512 | ||
| 146 | #define _POSIX_RE_DUP_MAX 255 | ||
| 147 | #define _POSIX_RTSIG_MAX 8 | ||
| 148 | #define _POSIX_SEM_NSEMS_MAX 256 | ||
| 149 | #define _POSIX_SEM_VALUE_MAX 32767 | ||
| 150 | #define _POSIX_SIGQUEUE_MAX 32 | ||
| 151 | #define _POSIX_SSIZE_MAX 32767 | ||
| 152 | #define _POSIX_STREAM_MAX 8 | ||
| 153 | #define _POSIX_SS_REPL_MAX 4 | ||
| 154 | #define _POSIX_SYMLINK_MAX 255 | ||
| 155 | #define _POSIX_SYMLOOP_MAX 8 | ||
| 156 | #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 157 | #define _POSIX_THREAD_KEYS_MAX 128 | ||
| 158 | #define _POSIX_THREAD_THREADS_MAX 64 | ||
| 159 | #define _POSIX_TIMER_MAX 32 | ||
| 160 | #define _POSIX_TRACE_EVENT_NAME_MAX 30 | ||
| 161 | #define _POSIX_TRACE_NAME_MAX 8 | ||
| 162 | #define _POSIX_TRACE_SYS_MAX 8 | ||
| 163 | #define _POSIX_TRACE_USER_EVENT_MAX 32 | ||
| 164 | #define _POSIX_TTY_NAME_MAX 9 | ||
| 165 | #define _POSIX_TZNAME_MAX 6 | ||
| 166 | #define _POSIX2_BC_BASE_MAX 99 | ||
| 167 | #define _POSIX2_BC_DIM_MAX 2048 | ||
| 168 | #define _POSIX2_BC_SCALE_MAX 99 | ||
| 169 | #define _POSIX2_BC_STRING_MAX 1000 | ||
| 170 | #define _POSIX2_CHARCLASS_NAME_MAX 14 | ||
| 171 | #define _POSIX2_COLL_WEIGHTS_MAX 2 | ||
| 172 | #define _POSIX2_EXPR_NEST_MAX 32 | ||
| 173 | #define _POSIX2_LINE_MAX 2048 | ||
| 174 | #define _POSIX2_RE_DUP_MAX 255 | ||
| 175 | |||
| 176 | #define _XOPEN_IOV_MAX 16 | ||
| 177 | #define _XOPEN_NAME_MAX 255 | ||
| 178 | #define _XOPEN_PATH_MAX 1024 | ||
| 179 | |||
| 180 | #endif | ||
lib/libc/include/wasm-wasi-musl/locale.h created+91| ... | @@ -0,0 +1,91 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 12 | #define NULL 0L | ||
| 13 | #else | ||
| 14 | #define NULL ((void*)0) | ||
| 15 | #endif | ||
| 16 | #else | ||
| 17 | #define __need_NULL | ||
| 18 | #include <stddef.h> | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #define LC_CTYPE 0 | ||
| 22 | #define LC_NUMERIC 1 | ||
| 23 | #define LC_TIME 2 | ||
| 24 | #define LC_COLLATE 3 | ||
| 25 | #define LC_MONETARY 4 | ||
| 26 | #define LC_MESSAGES 5 | ||
| 27 | #define LC_ALL 6 | ||
| 28 | |||
| 29 | struct lconv { | ||
| 30 | 	char *decimal_point; | ||
| 31 | 	char *thousands_sep; | ||
| 32 | 	char *grouping; | ||
| 33 | |||
| 34 | 	char *int_curr_symbol; | ||
| 35 | 	char *currency_symbol; | ||
| 36 | 	char *mon_decimal_point; | ||
| 37 | 	char *mon_thousands_sep; | ||
| 38 | 	char *mon_grouping; | ||
| 39 | 	char *positive_sign; | ||
| 40 | 	char *negative_sign; | ||
| 41 | 	char int_frac_digits; | ||
| 42 | 	char frac_digits; | ||
| 43 | 	char p_cs_precedes; | ||
| 44 | 	char p_sep_by_space; | ||
| 45 | 	char n_cs_precedes; | ||
| 46 | 	char n_sep_by_space; | ||
| 47 | 	char p_sign_posn; | ||
| 48 | 	char n_sign_posn; | ||
| 49 | 	char int_p_cs_precedes; | ||
| 50 | 	char int_p_sep_by_space; | ||
| 51 | 	char int_n_cs_precedes; | ||
| 52 | 	char int_n_sep_by_space; | ||
| 53 | 	char int_p_sign_posn; | ||
| 54 | 	char int_n_sign_posn; | ||
| 55 | }; | ||
| 56 | |||
| 57 | |||
| 58 | char *setlocale (int, const char *); | ||
| 59 | struct lconv *localeconv(void); | ||
| 60 | |||
| 61 | |||
| 62 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 63 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 64 | |||
| 65 | #define __NEED_locale_t | ||
| 66 | |||
| 67 | #include <bits/alltypes.h> | ||
| 68 | |||
| 69 | #define LC_GLOBAL_LOCALE ((locale_t)-1) | ||
| 70 | |||
| 71 | #define LC_CTYPE_MASK (1<<LC_CTYPE) | ||
| 72 | #define LC_NUMERIC_MASK (1<<LC_NUMERIC) | ||
| 73 | #define LC_TIME_MASK (1<<LC_TIME) | ||
| 74 | #define LC_COLLATE_MASK (1<<LC_COLLATE) | ||
| 75 | #define LC_MONETARY_MASK (1<<LC_MONETARY) | ||
| 76 | #define LC_MESSAGES_MASK (1<<LC_MESSAGES) | ||
| 77 | #define LC_ALL_MASK 0x7fffffff | ||
| 78 | |||
| 79 | locale_t duplocale(locale_t); | ||
| 80 | void freelocale(locale_t); | ||
| 81 | locale_t newlocale(int, const char *, locale_t); | ||
| 82 | locale_t uselocale(locale_t); | ||
| 83 | |||
| 84 | #endif | ||
| 85 | |||
| 86 | |||
| 87 | #ifdef __cplusplus | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #endif | ||
lib/libc/include/wasm-wasi-musl/malloc.h created+33| ... | @@ -0,0 +1,33 @@ | ||
| 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 created+459| ... | @@ -0,0 +1,459 @@ | ||
| 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/memory.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <string.h> | ||
lib/libc/include/wasm-wasi-musl/monetary.h created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #ifndef _MONETARY_H | ||
| 2 | #define _MONETARY_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_ssize_t | ||
| 11 | #define __NEED_size_t | ||
| 12 | #define __NEED_locale_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | ssize_t strfmon(char *__restrict, size_t, const char *__restrict, ...); | ||
| 17 | ssize_t strfmon_l(char *__restrict, size_t, locale_t, const char *__restrict, ...); | ||
| 18 | |||
| 19 | #ifdef __cplusplus | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/include/wasm-wasi-musl/mqueue.h created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #ifndef _MQUEUE_H | ||
| 2 | #define _MQUEUE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_ssize_t | ||
| 11 | #define __NEED_pthread_attr_t | ||
| 12 | #define __NEED_time_t | ||
| 13 | #define __NEED_struct_timespec | ||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | typedef int mqd_t; | ||
| 17 | struct mq_attr { | ||
| 18 | 	long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, __unused[4]; | ||
| 19 | }; | ||
| 20 | struct sigevent; | ||
| 21 | |||
| 22 | int mq_close(mqd_t); | ||
| 23 | int mq_getattr(mqd_t, struct mq_attr *); | ||
| 24 | int mq_notify(mqd_t, const struct sigevent *); | ||
| 25 | mqd_t mq_open(const char *, int, ...); | ||
| 26 | ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); | ||
| 27 | int mq_send(mqd_t, const char *, size_t, unsigned); | ||
| 28 | int mq_setattr(mqd_t, const struct mq_attr *__restrict, struct mq_attr *__restrict); | ||
| 29 | ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, unsigned *__restrict, const struct timespec *__restrict); | ||
| 30 | int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *); | ||
| 31 | int mq_unlink(const char *); | ||
| 32 | |||
| 33 | #if _REDIR_TIME64 | ||
| 34 | __REDIR(mq_timedreceive, __mq_timedreceive_time64); | ||
| 35 | __REDIR(mq_timedsend, __mq_timedsend_time64); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef __cplusplus | ||
| 39 | } | ||
| 40 | #endif | ||
| 41 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/icmp6.h created+305| ... | @@ -0,0 +1,305 @@ | ||
| 1 | #ifndef _NETINET_ICMP6_H | ||
| 2 | #define _NETINET_ICMP6_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <sys/types.h> | ||
| 11 | #include <netinet/in.h> | ||
| 12 | |||
| 13 | #define ICMP6_FILTER 1 | ||
| 14 | |||
| 15 | #define ICMP6_FILTER_BLOCK		1 | ||
| 16 | #define ICMP6_FILTER_PASS		2 | ||
| 17 | #define ICMP6_FILTER_BLOCKOTHERS	3 | ||
| 18 | #define ICMP6_FILTER_PASSONLY		4 | ||
| 19 | |||
| 20 | struct icmp6_filter { | ||
| 21 | 	uint32_t icmp6_filt[8]; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct icmp6_hdr { | ||
| 25 | 	uint8_t icmp6_type; | ||
| 26 | 	uint8_t icmp6_code; | ||
| 27 | 	uint16_t icmp6_cksum; | ||
| 28 | 	union { | ||
| 29 | 		uint32_t icmp6_un_data32[1]; | ||
| 30 | 		uint16_t icmp6_un_data16[2]; | ||
| 31 | 		uint8_t icmp6_un_data8[4]; | ||
| 32 | 	} icmp6_dataun; | ||
| 33 | }; | ||
| 34 | |||
| 35 | #define icmp6_data32 icmp6_dataun.icmp6_un_data32 | ||
| 36 | #define icmp6_data16 icmp6_dataun.icmp6_un_data16 | ||
| 37 | #define icmp6_data8 icmp6_dataun.icmp6_un_data8 | ||
| 38 | #define icmp6_pptr icmp6_data32[0] | ||
| 39 | #define icmp6_mtu icmp6_data32[0] | ||
| 40 | #define icmp6_id icmp6_data16[0] | ||
| 41 | #define icmp6_seq icmp6_data16[1] | ||
| 42 | #define icmp6_maxdelay icmp6_data16[0] | ||
| 43 | |||
| 44 | #define ICMP6_DST_UNREACH 1 | ||
| 45 | #define ICMP6_PACKET_TOO_BIG 2 | ||
| 46 | #define ICMP6_TIME_EXCEEDED 3 | ||
| 47 | #define ICMP6_PARAM_PROB 4 | ||
| 48 | |||
| 49 | #define ICMP6_INFOMSG_MASK 0x80 | ||
| 50 | |||
| 51 | #define ICMP6_ECHO_REQUEST 128 | ||
| 52 | #define ICMP6_ECHO_REPLY 129 | ||
| 53 | #define MLD_LISTENER_QUERY 130 | ||
| 54 | #define MLD_LISTENER_REPORT 131 | ||
| 55 | #define MLD_LISTENER_REDUCTION 132 | ||
| 56 | |||
| 57 | #define ICMP6_DST_UNREACH_NOROUTE 0 | ||
| 58 | #define ICMP6_DST_UNREACH_ADMIN 1 | ||
| 59 | #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 | ||
| 60 | #define ICMP6_DST_UNREACH_ADDR 3 | ||
| 61 | #define ICMP6_DST_UNREACH_NOPORT 4 | ||
| 62 | |||
| 63 | #define ICMP6_TIME_EXCEED_TRANSIT 0 | ||
| 64 | #define ICMP6_TIME_EXCEED_REASSEMBLY 1 | ||
| 65 | |||
| 66 | #define ICMP6_PARAMPROB_HEADER 0 | ||
| 67 | #define ICMP6_PARAMPROB_NEXTHEADER 1 | ||
| 68 | #define ICMP6_PARAMPROB_OPTION 2 | ||
| 69 | |||
| 70 | #define ICMP6_FILTER_WILLPASS(type, filterp) \ | ||
| 71 | 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) | ||
| 72 | |||
| 73 | #define ICMP6_FILTER_WILLBLOCK(type, filterp) \ | ||
| 74 | 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) | ||
| 75 | |||
| 76 | #define ICMP6_FILTER_SETPASS(type, filterp) \ | ||
| 77 | 	((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))) | ||
| 78 | |||
| 79 | #define ICMP6_FILTER_SETBLOCK(type, filterp) \ | ||
| 80 | 	((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))) | ||
| 81 | |||
| 82 | #define ICMP6_FILTER_SETPASSALL(filterp) \ | ||
| 83 | 	memset (filterp, 0, sizeof (struct icmp6_filter)); | ||
| 84 | |||
| 85 | #define ICMP6_FILTER_SETBLOCKALL(filterp) \ | ||
| 86 | 	memset (filterp, 0xFF, sizeof (struct icmp6_filter)); | ||
| 87 | |||
| 88 | #define ND_ROUTER_SOLICIT 133 | ||
| 89 | #define ND_ROUTER_ADVERT 134 | ||
| 90 | #define ND_NEIGHBOR_SOLICIT 135 | ||
| 91 | #define ND_NEIGHBOR_ADVERT 136 | ||
| 92 | #define ND_REDIRECT 137 | ||
| 93 | |||
| 94 | struct nd_router_solicit { | ||
| 95 | 	struct icmp6_hdr nd_rs_hdr; | ||
| 96 | }; | ||
| 97 | |||
| 98 | #define nd_rs_type nd_rs_hdr.icmp6_type | ||
| 99 | #define nd_rs_code nd_rs_hdr.icmp6_code | ||
| 100 | #define nd_rs_cksum nd_rs_hdr.icmp6_cksum | ||
| 101 | #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] | ||
| 102 | |||
| 103 | struct nd_router_advert { | ||
| 104 | 	struct icmp6_hdr nd_ra_hdr; | ||
| 105 | 	uint32_t nd_ra_reachable; | ||
| 106 | 	uint32_t nd_ra_retransmit; | ||
| 107 | }; | ||
| 108 | |||
| 109 | #define nd_ra_type nd_ra_hdr.icmp6_type | ||
| 110 | #define nd_ra_code nd_ra_hdr.icmp6_code | ||
| 111 | #define nd_ra_cksum nd_ra_hdr.icmp6_cksum | ||
| 112 | #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] | ||
| 113 | #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] | ||
| 114 | #define ND_RA_FLAG_MANAGED 0x80 | ||
| 115 | #define ND_RA_FLAG_OTHER 0x40 | ||
| 116 | #define ND_RA_FLAG_HOME_AGENT 0x20 | ||
| 117 | #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] | ||
| 118 | |||
| 119 | struct nd_neighbor_solicit { | ||
| 120 | 	struct icmp6_hdr nd_ns_hdr; | ||
| 121 | 	struct in6_addr nd_ns_target; | ||
| 122 | }; | ||
| 123 | |||
| 124 | #define nd_ns_type nd_ns_hdr.icmp6_type | ||
| 125 | #define nd_ns_code nd_ns_hdr.icmp6_code | ||
| 126 | #define nd_ns_cksum nd_ns_hdr.icmp6_cksum | ||
| 127 | #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] | ||
| 128 | |||
| 129 | struct nd_neighbor_advert { | ||
| 130 | 	struct icmp6_hdr nd_na_hdr; | ||
| 131 | 	struct in6_addr nd_na_target; | ||
| 132 | }; | ||
| 133 | |||
| 134 | #define nd_na_type nd_na_hdr.icmp6_type | ||
| 135 | #define nd_na_code nd_na_hdr.icmp6_code | ||
| 136 | #define nd_na_cksum nd_na_hdr.icmp6_cksum | ||
| 137 | #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] | ||
| 138 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 139 | #define ND_NA_FLAG_ROUTER 0x80000000 | ||
| 140 | #define ND_NA_FLAG_SOLICITED 0x40000000 | ||
| 141 | #define ND_NA_FLAG_OVERRIDE 0x20000000 | ||
| 142 | #else | ||
| 143 | #define ND_NA_FLAG_ROUTER 0x00000080 | ||
| 144 | #define ND_NA_FLAG_SOLICITED 0x00000040 | ||
| 145 | #define ND_NA_FLAG_OVERRIDE 0x00000020 | ||
| 146 | #endif | ||
| 147 | |||
| 148 | struct nd_redirect { | ||
| 149 | 	struct icmp6_hdr nd_rd_hdr; | ||
| 150 | 	struct in6_addr nd_rd_target; | ||
| 151 | 	struct in6_addr nd_rd_dst; | ||
| 152 | }; | ||
| 153 | |||
| 154 | #define nd_rd_type nd_rd_hdr.icmp6_type | ||
| 155 | #define nd_rd_code nd_rd_hdr.icmp6_code | ||
| 156 | #define nd_rd_cksum nd_rd_hdr.icmp6_cksum | ||
| 157 | #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] | ||
| 158 | |||
| 159 | struct nd_opt_hdr { | ||
| 160 | 	uint8_t nd_opt_type; | ||
| 161 | 	uint8_t nd_opt_len; | ||
| 162 | }; | ||
| 163 | |||
| 164 | #define ND_OPT_SOURCE_LINKADDR		1 | ||
| 165 | #define ND_OPT_TARGET_LINKADDR		2 | ||
| 166 | #define ND_OPT_PREFIX_INFORMATION	3 | ||
| 167 | #define ND_OPT_REDIRECTED_HEADER	4 | ||
| 168 | #define ND_OPT_MTU			5 | ||
| 169 | #define ND_OPT_RTR_ADV_INTERVAL		7 | ||
| 170 | #define ND_OPT_HOME_AGENT_INFO		8 | ||
| 171 | |||
| 172 | struct nd_opt_prefix_info { | ||
| 173 | 	uint8_t nd_opt_pi_type; | ||
| 174 | 	uint8_t nd_opt_pi_len; | ||
| 175 | 	uint8_t nd_opt_pi_prefix_len; | ||
| 176 | 	uint8_t nd_opt_pi_flags_reserved; | ||
| 177 | 	uint32_t nd_opt_pi_valid_time; | ||
| 178 | 	uint32_t nd_opt_pi_preferred_time; | ||
| 179 | 	uint32_t nd_opt_pi_reserved2; | ||
| 180 | 	struct in6_addr nd_opt_pi_prefix; | ||
| 181 | }; | ||
| 182 | |||
| 183 | #define ND_OPT_PI_FLAG_ONLINK	0x80 | ||
| 184 | #define ND_OPT_PI_FLAG_AUTO	0x40 | ||
| 185 | #define ND_OPT_PI_FLAG_RADDR	0x20 | ||
| 186 | |||
| 187 | struct nd_opt_rd_hdr { | ||
| 188 | 	uint8_t nd_opt_rh_type; | ||
| 189 | 	uint8_t nd_opt_rh_len; | ||
| 190 | 	uint16_t nd_opt_rh_reserved1; | ||
| 191 | 	uint32_t nd_opt_rh_reserved2; | ||
| 192 | }; | ||
| 193 | |||
| 194 | struct nd_opt_mtu { | ||
| 195 | 	uint8_t nd_opt_mtu_type; | ||
| 196 | 	uint8_t nd_opt_mtu_len; | ||
| 197 | 	uint16_t nd_opt_mtu_reserved; | ||
| 198 | 	uint32_t nd_opt_mtu_mtu; | ||
| 199 | }; | ||
| 200 | |||
| 201 | struct mld_hdr { | ||
| 202 | 	struct icmp6_hdr mld_icmp6_hdr; | ||
| 203 | 	struct in6_addr mld_addr; | ||
| 204 | }; | ||
| 205 | |||
| 206 | #define mld_type mld_icmp6_hdr.icmp6_type | ||
| 207 | #define mld_code mld_icmp6_hdr.icmp6_code | ||
| 208 | #define mld_cksum mld_icmp6_hdr.icmp6_cksum | ||
| 209 | #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] | ||
| 210 | #define mld_reserved mld_icmp6_hdr.icmp6_data16[1] | ||
| 211 | |||
| 212 | #define ICMP6_ROUTER_RENUMBERING 138 | ||
| 213 | |||
| 214 | struct icmp6_router_renum { | ||
| 215 | 	struct icmp6_hdr rr_hdr; | ||
| 216 | 	uint8_t rr_segnum; | ||
| 217 | 	uint8_t rr_flags; | ||
| 218 | 	uint16_t rr_maxdelay; | ||
| 219 | 	uint32_t rr_reserved; | ||
| 220 | }; | ||
| 221 | |||
| 222 | #define rr_type		rr_hdr.icmp6_type | ||
| 223 | #define rr_code rr_hdr.icmp6_code | ||
| 224 | #define rr_cksum rr_hdr.icmp6_cksum | ||
| 225 | #define rr_seqnum rr_hdr.icmp6_data32[0] | ||
| 226 | |||
| 227 | #define ICMP6_RR_FLAGS_TEST 0x80 | ||
| 228 | #define ICMP6_RR_FLAGS_REQRESULT 0x40 | ||
| 229 | #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 | ||
| 230 | #define ICMP6_RR_FLAGS_SPECSITE 0x10 | ||
| 231 | #define ICMP6_RR_FLAGS_PREVDONE 0x08 | ||
| 232 | |||
| 233 | struct rr_pco_match { | ||
| 234 | 	uint8_t rpm_code; | ||
| 235 | 	uint8_t rpm_len; | ||
| 236 | 	uint8_t rpm_ordinal; | ||
| 237 | 	uint8_t rpm_matchlen; | ||
| 238 | 	uint8_t rpm_minlen; | ||
| 239 | 	uint8_t rpm_maxlen; | ||
| 240 | 	uint16_t rpm_reserved; | ||
| 241 | 	struct in6_addr rpm_prefix; | ||
| 242 | }; | ||
| 243 | |||
| 244 | #define RPM_PCO_ADD 1 | ||
| 245 | #define RPM_PCO_CHANGE 2 | ||
| 246 | #define RPM_PCO_SETGLOBAL 3 | ||
| 247 | |||
| 248 | struct rr_pco_use { | ||
| 249 | 	uint8_t rpu_uselen; | ||
| 250 | 	uint8_t rpu_keeplen; | ||
| 251 | 	uint8_t rpu_ramask; | ||
| 252 | 	uint8_t rpu_raflags; | ||
| 253 | 	uint32_t rpu_vltime; | ||
| 254 | 	uint32_t rpu_pltime; | ||
| 255 | 	uint32_t rpu_flags; | ||
| 256 | 	struct in6_addr rpu_prefix; | ||
| 257 | }; | ||
| 258 | |||
| 259 | #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20 | ||
| 260 | #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10 | ||
| 261 | |||
| 262 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 263 | #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 | ||
| 264 | #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 | ||
| 265 | #else | ||
| 266 | #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 | ||
| 267 | #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 | ||
| 268 | #endif | ||
| 269 | |||
| 270 | struct rr_result { | ||
| 271 | 	uint16_t rrr_flags; | ||
| 272 | 	uint8_t rrr_ordinal; | ||
| 273 | 	uint8_t rrr_matchedlen; | ||
| 274 | 	uint32_t rrr_ifid; | ||
| 275 | 	struct in6_addr rrr_prefix; | ||
| 276 | }; | ||
| 277 | |||
| 278 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 279 | #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 | ||
| 280 | #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 | ||
| 281 | #else | ||
| 282 | #define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 | ||
| 283 | #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 | ||
| 284 | #endif | ||
| 285 | |||
| 286 | struct nd_opt_adv_interval { | ||
| 287 | 	uint8_t nd_opt_adv_interval_type; | ||
| 288 | 	uint8_t nd_opt_adv_interval_len; | ||
| 289 | 	uint16_t nd_opt_adv_interval_reserved; | ||
| 290 | 	uint32_t nd_opt_adv_interval_ival; | ||
| 291 | }; | ||
| 292 | |||
| 293 | struct nd_opt_home_agent_info { | ||
| 294 | 	uint8_t nd_opt_home_agent_info_type; | ||
| 295 | 	uint8_t nd_opt_home_agent_info_len; | ||
| 296 | 	uint16_t nd_opt_home_agent_info_reserved; | ||
| 297 | 	uint16_t nd_opt_home_agent_info_preference; | ||
| 298 | 	uint16_t nd_opt_home_agent_info_lifetime; | ||
| 299 | }; | ||
| 300 | |||
| 301 | #ifdef __cplusplus | ||
| 302 | } | ||
| 303 | #endif | ||
| 304 | |||
| 305 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/igmp.h created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | #ifndef _NETINET_IGMP_H | ||
| 2 | #define _NETINET_IGMP_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <netinet/in.h> | ||
| 6 | |||
| 7 | struct igmp { | ||
| 8 | 	uint8_t igmp_type; | ||
| 9 | 	uint8_t igmp_code; | ||
| 10 | 	uint16_t igmp_cksum; | ||
| 11 | 	struct in_addr igmp_group; | ||
| 12 | }; | ||
| 13 | |||
| 14 | #define IGMP_MINLEN			8 | ||
| 15 | |||
| 16 | #define IGMP_MEMBERSHIP_QUERY 	0x11 | ||
| 17 | #define IGMP_V1_MEMBERSHIP_REPORT	0x12 | ||
| 18 | #define IGMP_V2_MEMBERSHIP_REPORT	0x16 | ||
| 19 | #define IGMP_V2_LEAVE_GROUP		0x17 | ||
| 20 | |||
| 21 | #define IGMP_DVMRP			0x13 | ||
| 22 | #define IGMP_PIM			0x14 | ||
| 23 | #define IGMP_TRACE			0x15 | ||
| 24 | |||
| 25 | #define IGMP_MTRACE_RESP		0x1e | ||
| 26 | #define IGMP_MTRACE			0x1f | ||
| 27 | |||
| 28 | #define IGMP_MAX_HOST_REPORT_DELAY	10 | ||
| 29 | #define IGMP_TIMER_SCALE		10 | ||
| 30 | |||
| 31 | #define IGMP_DELAYING_MEMBER	1 | ||
| 32 | #define IGMP_IDLE_MEMBER	2 | ||
| 33 | #define IGMP_LAZY_MEMBER	3 | ||
| 34 | #define IGMP_SLEEPING_MEMBER	4 | ||
| 35 | #define IGMP_AWAKENING_MEMBER	5 | ||
| 36 | |||
| 37 | #define IGMP_v1_ROUTER		1 | ||
| 38 | #define IGMP_v2_ROUTER		2 | ||
| 39 | |||
| 40 | #define IGMP_HOST_MEMBERSHIP_QUERY	IGMP_MEMBERSHIP_QUERY | ||
| 41 | #define IGMP_HOST_MEMBERSHIP_REPORT	IGMP_V1_MEMBERSHIP_REPORT | ||
| 42 | #define IGMP_HOST_NEW_MEMBERSHIP_REPORT	IGMP_V2_MEMBERSHIP_REPORT | ||
| 43 | #define IGMP_HOST_LEAVE_MESSAGE		IGMP_V2_LEAVE_GROUP | ||
| 44 | |||
| 45 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/in.h created+432| ... | @@ -0,0 +1,432 @@ | ||
| 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 | |||
| 64 | #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) | ||
| 65 | #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) | ||
| 66 | #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) | ||
| 67 | #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) | ||
| 68 | #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) | ||
| 69 | |||
| 70 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 71 | #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } | ||
| 72 | #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | extern const struct in6_addr in6addr_any, in6addr_loopback; | ||
| 76 | |||
| 77 | #define INET_ADDRSTRLEN 16 | ||
| 78 | #define INET6_ADDRSTRLEN 46 | ||
| 79 | |||
| 80 | uint32_t htonl(uint32_t); | ||
| 81 | uint16_t htons(uint16_t); | ||
| 82 | uint32_t ntohl(uint32_t); | ||
| 83 | uint16_t ntohs(uint16_t); | ||
| 84 | |||
| 85 | #define IPPORT_RESERVED 1024 | ||
| 86 | |||
| 87 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 88 | #define IPPROTO_IP 0 | ||
| 89 | #define IPPROTO_HOPOPTS 0 | ||
| 90 | #define IPPROTO_ICMP 1 | ||
| 91 | #define IPPROTO_IGMP 2 | ||
| 92 | #define IPPROTO_IPIP 4 | ||
| 93 | #define IPPROTO_TCP 6 | ||
| 94 | #define IPPROTO_EGP 8 | ||
| 95 | #define IPPROTO_PUP 12 | ||
| 96 | #define IPPROTO_UDP 17 | ||
| 97 | #define IPPROTO_IDP 22 | ||
| 98 | #define IPPROTO_TP 29 | ||
| 99 | #define IPPROTO_DCCP 33 | ||
| 100 | #define IPPROTO_IPV6 41 | ||
| 101 | #define IPPROTO_ROUTING 43 | ||
| 102 | #define IPPROTO_FRAGMENT 44 | ||
| 103 | #define IPPROTO_RSVP 46 | ||
| 104 | #define IPPROTO_GRE 47 | ||
| 105 | #define IPPROTO_ESP 50 | ||
| 106 | #define IPPROTO_AH 51 | ||
| 107 | #define IPPROTO_ICMPV6 58 | ||
| 108 | #define IPPROTO_NONE 59 | ||
| 109 | #define IPPROTO_DSTOPTS 60 | ||
| 110 | #define IPPROTO_MTP 92 | ||
| 111 | #define IPPROTO_BEETPH 94 | ||
| 112 | #define IPPROTO_ENCAP 98 | ||
| 113 | #define IPPROTO_PIM 103 | ||
| 114 | #define IPPROTO_COMP 108 | ||
| 115 | #define IPPROTO_SCTP 132 | ||
| 116 | #define IPPROTO_MH 135 | ||
| 117 | #define IPPROTO_UDPLITE 136 | ||
| 118 | #define IPPROTO_MPLS 137 | ||
| 119 | #define IPPROTO_ETHERNET 143 | ||
| 120 | #define IPPROTO_RAW 255 | ||
| 121 | #define IPPROTO_MPTCP 262 | ||
| 122 | #define IPPROTO_MAX 263 | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #define IN6_IS_ADDR_UNSPECIFIED(a) \ | ||
| 126 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 127 | ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) | ||
| 128 | |||
| 129 | #define IN6_IS_ADDR_LOOPBACK(a) \ | ||
| 130 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 131 | ((uint32_t *) (a))[2] == 0 && \ | ||
| 132 | ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ | ||
| 133 | ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) | ||
| 134 | |||
| 135 | #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) | ||
| 136 | |||
| 137 | #define IN6_IS_ADDR_LINKLOCAL(a) \ | ||
| 138 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) | ||
| 139 | |||
| 140 | #define IN6_IS_ADDR_SITELOCAL(a) \ | ||
| 141 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) | ||
| 142 | |||
| 143 | #define IN6_IS_ADDR_V4MAPPED(a) \ | ||
| 144 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 145 | ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ | ||
| 146 | ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) | ||
| 147 | |||
| 148 | #define IN6_IS_ADDR_V4COMPAT(a) \ | ||
| 149 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 150 | ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) | ||
| 151 | |||
| 152 | #define IN6_IS_ADDR_MC_NODELOCAL(a) \ | ||
| 153 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) | ||
| 154 | |||
| 155 | #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ | ||
| 156 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) | ||
| 157 | |||
| 158 | #define IN6_IS_ADDR_MC_SITELOCAL(a) \ | ||
| 159 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) | ||
| 160 | |||
| 161 | #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ | ||
| 162 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) | ||
| 163 | |||
| 164 | #define IN6_IS_ADDR_MC_GLOBAL(a) \ | ||
| 165 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) | ||
| 166 | |||
| 167 | #define __ARE_4_EQUAL(a,b) \ | ||
| 168 | 	(!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) | ||
| 169 | #define IN6_ARE_ADDR_EQUAL(a,b) \ | ||
| 170 | 	__ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) | ||
| 171 | |||
| 172 | #define	IN_CLASSA(a)		((((in_addr_t)(a)) & 0x80000000) == 0) | ||
| 173 | #define	IN_CLASSA_NET		0xff000000 | ||
| 174 | #define	IN_CLASSA_NSHIFT	24 | ||
| 175 | #define	IN_CLASSA_HOST		(0xffffffff & ~IN_CLASSA_NET) | ||
| 176 | #define	IN_CLASSA_MAX		128 | ||
| 177 | #define	IN_CLASSB(a)		((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) | ||
| 178 | #define	IN_CLASSB_NET		0xffff0000 | ||
| 179 | #define	IN_CLASSB_NSHIFT	16 | ||
| 180 | #define	IN_CLASSB_HOST		(0xffffffff & ~IN_CLASSB_NET) | ||
| 181 | #define	IN_CLASSB_MAX		65536 | ||
| 182 | #define	IN_CLASSC(a)		((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) | ||
| 183 | #define	IN_CLASSC_NET		0xffffff00 | ||
| 184 | #define	IN_CLASSC_NSHIFT	8 | ||
| 185 | #define	IN_CLASSC_HOST		(0xffffffff & ~IN_CLASSC_NET) | ||
| 186 | #define	IN_CLASSD(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) | ||
| 187 | #define	IN_MULTICAST(a)		IN_CLASSD(a) | ||
| 188 | #define	IN_EXPERIMENTAL(a)	((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) | ||
| 189 | #define	IN_BADCLASS(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) | ||
| 190 | |||
| 191 | #define IN_LOOPBACKNET 127 | ||
| 192 | |||
| 193 | |||
| 194 | #define IP_TOS 1 | ||
| 195 | #define IP_TTL 2 | ||
| 196 | #define IP_HDRINCL 3 | ||
| 197 | #define IP_OPTIONS 4 | ||
| 198 | #define IP_ROUTER_ALERT 5 | ||
| 199 | #define IP_RECVOPTS 6 | ||
| 200 | #define IP_RETOPTS 7 | ||
| 201 | #define IP_PKTINFO 8 | ||
| 202 | #define IP_PKTOPTIONS 9 | ||
| 203 | #define IP_PMTUDISC 10 | ||
| 204 | #define IP_MTU_DISCOVER 10 | ||
| 205 | #define IP_RECVERR 11 | ||
| 206 | #define IP_RECVTTL 12 | ||
| 207 | #define IP_RECVTOS 13 | ||
| 208 | #define IP_MTU 14 | ||
| 209 | #define IP_FREEBIND 15 | ||
| 210 | #define IP_IPSEC_POLICY 16 | ||
| 211 | #define IP_XFRM_POLICY 17 | ||
| 212 | #define IP_PASSSEC 18 | ||
| 213 | #define IP_TRANSPARENT 19 | ||
| 214 | #define IP_ORIGDSTADDR 20 | ||
| 215 | #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR | ||
| 216 | #define IP_MINTTL 21 | ||
| 217 | #define IP_NODEFRAG 22 | ||
| 218 | #define IP_CHECKSUM 23 | ||
| 219 | #define IP_BIND_ADDRESS_NO_PORT 24 | ||
| 220 | #define IP_RECVFRAGSIZE 25 | ||
| 221 | #define IP_RECVERR_RFC4884 26 | ||
| 222 | #define IP_MULTICAST_IF 32 | ||
| 223 | #define IP_MULTICAST_TTL 33 | ||
| 224 | #define IP_MULTICAST_LOOP 34 | ||
| 225 | #define IP_ADD_MEMBERSHIP 35 | ||
| 226 | #define IP_DROP_MEMBERSHIP 36 | ||
| 227 | #define IP_UNBLOCK_SOURCE 37 | ||
| 228 | #define IP_BLOCK_SOURCE 38 | ||
| 229 | #define IP_ADD_SOURCE_MEMBERSHIP 39 | ||
| 230 | #define IP_DROP_SOURCE_MEMBERSHIP 40 | ||
| 231 | #define IP_MSFILTER 41 | ||
| 232 | #define IP_MULTICAST_ALL 49 | ||
| 233 | #define IP_UNICAST_IF 50 | ||
| 234 | |||
| 235 | #define IP_RECVRETOPTS IP_RETOPTS | ||
| 236 | |||
| 237 | #define IP_PMTUDISC_DONT 0 | ||
| 238 | #define IP_PMTUDISC_WANT 1 | ||
| 239 | #define IP_PMTUDISC_DO 2 | ||
| 240 | #define IP_PMTUDISC_PROBE 3 | ||
| 241 | #define IP_PMTUDISC_INTERFACE 4 | ||
| 242 | #define IP_PMTUDISC_OMIT 5 | ||
| 243 | |||
| 244 | #define IP_DEFAULT_MULTICAST_TTL 1 | ||
| 245 | #define IP_DEFAULT_MULTICAST_LOOP 1 | ||
| 246 | #define IP_MAX_MEMBERSHIPS 20 | ||
| 247 | |||
| 248 | struct ip_opts { | ||
| 249 | 	struct in_addr ip_dst; | ||
| 250 | 	char ip_opts[40]; | ||
| 251 | }; | ||
| 252 | |||
| 253 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 254 | |||
| 255 | #define MCAST_JOIN_GROUP 42 | ||
| 256 | #define MCAST_BLOCK_SOURCE 43 | ||
| 257 | #define MCAST_UNBLOCK_SOURCE 44 | ||
| 258 | #define MCAST_LEAVE_GROUP 45 | ||
| 259 | #define MCAST_JOIN_SOURCE_GROUP 46 | ||
| 260 | #define MCAST_LEAVE_SOURCE_GROUP 47 | ||
| 261 | #define MCAST_MSFILTER 48 | ||
| 262 | |||
| 263 | #define MCAST_EXCLUDE 0 | ||
| 264 | #define MCAST_INCLUDE 1 | ||
| 265 | |||
| 266 | struct ip_mreq { | ||
| 267 | 	struct in_addr imr_multiaddr; | ||
| 268 | 	struct in_addr imr_interface; | ||
| 269 | }; | ||
| 270 | |||
| 271 | struct ip_mreqn { | ||
| 272 | 	struct in_addr imr_multiaddr; | ||
| 273 | 	struct in_addr imr_address; | ||
| 274 | 	int imr_ifindex; | ||
| 275 | }; | ||
| 276 | |||
| 277 | struct ip_mreq_source { | ||
| 278 | 	struct in_addr imr_multiaddr; | ||
| 279 | 	struct in_addr imr_interface; | ||
| 280 | 	struct in_addr imr_sourceaddr; | ||
| 281 | }; | ||
| 282 | |||
| 283 | struct ip_msfilter { | ||
| 284 | 	struct in_addr imsf_multiaddr; | ||
| 285 | 	struct in_addr imsf_interface; | ||
| 286 | 	uint32_t imsf_fmode; | ||
| 287 | 	uint32_t imsf_numsrc; | ||
| 288 | 	struct in_addr imsf_slist[1]; | ||
| 289 | }; | ||
| 290 | #define IP_MSFILTER_SIZE(numsrc) \ | ||
| 291 | 	(sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ | ||
| 292 | 	+ (numsrc) * sizeof(struct in_addr)) | ||
| 293 | |||
| 294 | struct group_req { | ||
| 295 | 	uint32_t gr_interface; | ||
| 296 | 	struct sockaddr_storage gr_group; | ||
| 297 | }; | ||
| 298 | |||
| 299 | struct group_source_req { | ||
| 300 | 	uint32_t gsr_interface; | ||
| 301 | 	struct sockaddr_storage gsr_group; | ||
| 302 | 	struct sockaddr_storage gsr_source; | ||
| 303 | }; | ||
| 304 | |||
| 305 | struct group_filter { | ||
| 306 | 	uint32_t gf_interface; | ||
| 307 | 	struct sockaddr_storage gf_group; | ||
| 308 | 	uint32_t gf_fmode; | ||
| 309 | 	uint32_t gf_numsrc; | ||
| 310 | 	struct sockaddr_storage gf_slist[1]; | ||
| 311 | }; | ||
| 312 | #define GROUP_FILTER_SIZE(numsrc) \ | ||
| 313 | 	(sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ | ||
| 314 | 	+ (numsrc) * sizeof(struct sockaddr_storage)) | ||
| 315 | |||
| 316 | struct in_pktinfo { | ||
| 317 | 	int ipi_ifindex; | ||
| 318 | 	struct in_addr ipi_spec_dst; | ||
| 319 | 	struct in_addr ipi_addr; | ||
| 320 | }; | ||
| 321 | |||
| 322 | struct in6_pktinfo { | ||
| 323 | 	struct in6_addr ipi6_addr; | ||
| 324 | 	unsigned ipi6_ifindex; | ||
| 325 | }; | ||
| 326 | |||
| 327 | struct ip6_mtuinfo { | ||
| 328 | 	struct sockaddr_in6 ip6m_addr; | ||
| 329 | 	uint32_t ip6m_mtu; | ||
| 330 | }; | ||
| 331 | #endif | ||
| 332 | |||
| 333 | #define IPV6_ADDRFORM 1 | ||
| 334 | #define IPV6_2292PKTINFO 2 | ||
| 335 | #define IPV6_2292HOPOPTS 3 | ||
| 336 | #define IPV6_2292DSTOPTS 4 | ||
| 337 | #define IPV6_2292RTHDR 5 | ||
| 338 | #define IPV6_2292PKTOPTIONS 6 | ||
| 339 | #define IPV6_CHECKSUM 7 | ||
| 340 | #define IPV6_2292HOPLIMIT 8 | ||
| 341 | #define IPV6_NEXTHOP 9 | ||
| 342 | #define IPV6_AUTHHDR 10 | ||
| 343 | #define IPV6_UNICAST_HOPS 16 | ||
| 344 | #define IPV6_MULTICAST_IF 17 | ||
| 345 | #define IPV6_MULTICAST_HOPS 18 | ||
| 346 | #define IPV6_MULTICAST_LOOP 19 | ||
| 347 | #define IPV6_JOIN_GROUP 20 | ||
| 348 | #define IPV6_LEAVE_GROUP 21 | ||
| 349 | #define IPV6_ROUTER_ALERT 22 | ||
| 350 | #define IPV6_MTU_DISCOVER 23 | ||
| 351 | #define IPV6_MTU 24 | ||
| 352 | #define IPV6_RECVERR 25 | ||
| 353 | #define IPV6_V6ONLY 26 | ||
| 354 | #define IPV6_JOIN_ANYCAST 27 | ||
| 355 | #define IPV6_LEAVE_ANYCAST 28 | ||
| 356 | #define IPV6_MULTICAST_ALL 29 | ||
| 357 | #define IPV6_ROUTER_ALERT_ISOLATE 30 | ||
| 358 | #define IPV6_IPSEC_POLICY 34 | ||
| 359 | #define IPV6_XFRM_POLICY 35 | ||
| 360 | #define IPV6_HDRINCL 36 | ||
| 361 | |||
| 362 | #define IPV6_RECVPKTINFO 49 | ||
| 363 | #define IPV6_PKTINFO 50 | ||
| 364 | #define IPV6_RECVHOPLIMIT 51 | ||
| 365 | #define IPV6_HOPLIMIT 52 | ||
| 366 | #define IPV6_RECVHOPOPTS 53 | ||
| 367 | #define IPV6_HOPOPTS 54 | ||
| 368 | #define IPV6_RTHDRDSTOPTS 55 | ||
| 369 | #define IPV6_RECVRTHDR 56 | ||
| 370 | #define IPV6_RTHDR 57 | ||
| 371 | #define IPV6_RECVDSTOPTS 58 | ||
| 372 | #define IPV6_DSTOPTS 59 | ||
| 373 | #define IPV6_RECVPATHMTU 60 | ||
| 374 | #define IPV6_PATHMTU 61 | ||
| 375 | #define IPV6_DONTFRAG 62 | ||
| 376 | #define IPV6_RECVTCLASS 66 | ||
| 377 | #define IPV6_TCLASS 67 | ||
| 378 | #define IPV6_AUTOFLOWLABEL 70 | ||
| 379 | #define IPV6_ADDR_PREFERENCES 72 | ||
| 380 | #define IPV6_MINHOPCOUNT 73 | ||
| 381 | #define IPV6_ORIGDSTADDR 74 | ||
| 382 | #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR | ||
| 383 | #define IPV6_TRANSPARENT 75 | ||
| 384 | #define IPV6_UNICAST_IF 76 | ||
| 385 | #define IPV6_RECVFRAGSIZE 77 | ||
| 386 | #define IPV6_FREEBIND 78 | ||
| 387 | |||
| 388 | #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP | ||
| 389 | #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP | ||
| 390 | #define IPV6_RXHOPOPTS IPV6_HOPOPTS | ||
| 391 | #define IPV6_RXDSTOPTS IPV6_DSTOPTS | ||
| 392 | |||
| 393 | #define IPV6_PMTUDISC_DONT 0 | ||
| 394 | #define IPV6_PMTUDISC_WANT 1 | ||
| 395 | #define IPV6_PMTUDISC_DO 2 | ||
| 396 | #define IPV6_PMTUDISC_PROBE 3 | ||
| 397 | #define IPV6_PMTUDISC_INTERFACE 4 | ||
| 398 | #define IPV6_PMTUDISC_OMIT 5 | ||
| 399 | |||
| 400 | #define IPV6_PREFER_SRC_TMP 0x0001 | ||
| 401 | #define IPV6_PREFER_SRC_PUBLIC 0x0002 | ||
| 402 | #define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 | ||
| 403 | #define IPV6_PREFER_SRC_COA 0x0004 | ||
| 404 | #define IPV6_PREFER_SRC_HOME 0x0400 | ||
| 405 | #define IPV6_PREFER_SRC_CGA 0x0008 | ||
| 406 | #define IPV6_PREFER_SRC_NONCGA 0x0800 | ||
| 407 | |||
| 408 | #define IPV6_RTHDR_LOOSE 0 | ||
| 409 | #define IPV6_RTHDR_STRICT 1 | ||
| 410 | |||
| 411 | #define IPV6_RTHDR_TYPE_0 0 | ||
| 412 | |||
| 413 | #define __UAPI_DEF_IN_ADDR 0 | ||
| 414 | #define __UAPI_DEF_IN_IPPROTO 0 | ||
| 415 | #define __UAPI_DEF_IN_PKTINFO 0 | ||
| 416 | #define __UAPI_DEF_IP_MREQ 0 | ||
| 417 | #define __UAPI_DEF_SOCKADDR_IN 0 | ||
| 418 | #define __UAPI_DEF_IN_CLASS 0 | ||
| 419 | #define __UAPI_DEF_IN6_ADDR 0 | ||
| 420 | #define __UAPI_DEF_IN6_ADDR_ALT 0 | ||
| 421 | #define __UAPI_DEF_SOCKADDR_IN6 0 | ||
| 422 | #define __UAPI_DEF_IPV6_MREQ 0 | ||
| 423 | #define __UAPI_DEF_IPPROTO_V6 0 | ||
| 424 | #define __UAPI_DEF_IPV6_OPTIONS 0 | ||
| 425 | #define __UAPI_DEF_IN6_PKTINFO 0 | ||
| 426 | #define __UAPI_DEF_IP6_MTUINFO 0 | ||
| 427 | |||
| 428 | #ifdef __cplusplus | ||
| 429 | } | ||
| 430 | #endif | ||
| 431 | |||
| 432 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/in_systm.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef _NETINET_IN_SYSTM_H | ||
| 2 | #define _NETINET_IN_SYSTM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | typedef uint16_t n_short; | ||
| 7 | typedef uint32_t n_long, n_time; | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/ip.h created+199| ... | @@ -0,0 +1,199 @@ | ||
| 1 | #ifndef _NETINET_IP_H | ||
| 2 | #define _NETINET_IP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | struct timestamp { | ||
| 12 | 	uint8_t len; | ||
| 13 | 	uint8_t ptr; | ||
| 14 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 15 | 	unsigned int flags:4; | ||
| 16 | 	unsigned int overflow:4; | ||
| 17 | #else | ||
| 18 | 	unsigned int overflow:4; | ||
| 19 | 	unsigned int flags:4; | ||
| 20 | #endif | ||
| 21 | 	uint32_t data[9]; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct iphdr { | ||
| 25 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 26 | 	unsigned int ihl:4; | ||
| 27 | 	unsigned int version:4; | ||
| 28 | #else | ||
| 29 | 	unsigned int version:4; | ||
| 30 | 	unsigned int ihl:4; | ||
| 31 | #endif | ||
| 32 | 	uint8_t tos; | ||
| 33 | 	uint16_t tot_len; | ||
| 34 | 	uint16_t id; | ||
| 35 | 	uint16_t frag_off; | ||
| 36 | 	uint8_t ttl; | ||
| 37 | 	uint8_t protocol; | ||
| 38 | 	uint16_t check; | ||
| 39 | 	uint32_t saddr; | ||
| 40 | 	uint32_t daddr; | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct ip { | ||
| 44 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 45 | 	unsigned int ip_hl:4; | ||
| 46 | 	unsigned int ip_v:4; | ||
| 47 | #else | ||
| 48 | 	unsigned int ip_v:4; | ||
| 49 | 	unsigned int ip_hl:4; | ||
| 50 | #endif | ||
| 51 | 	uint8_t ip_tos; | ||
| 52 | 	uint16_t ip_len; | ||
| 53 | 	uint16_t ip_id; | ||
| 54 | 	uint16_t ip_off; | ||
| 55 | 	uint8_t ip_ttl; | ||
| 56 | 	uint8_t ip_p; | ||
| 57 | 	uint16_t ip_sum; | ||
| 58 | 	struct in_addr ip_src, ip_dst; | ||
| 59 | }; | ||
| 60 | |||
| 61 | #define	IP_RF 0x8000 | ||
| 62 | #define	IP_DF 0x4000 | ||
| 63 | #define	IP_MF 0x2000 | ||
| 64 | #define	IP_OFFMASK 0x1fff | ||
| 65 | |||
| 66 | struct ip_timestamp { | ||
| 67 | 	uint8_t ipt_code; | ||
| 68 | 	uint8_t ipt_len; | ||
| 69 | 	uint8_t ipt_ptr; | ||
| 70 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 71 | 	unsigned int ipt_flg:4; | ||
| 72 | 	unsigned int ipt_oflw:4; | ||
| 73 | #else | ||
| 74 | 	unsigned int ipt_oflw:4; | ||
| 75 | 	unsigned int ipt_flg:4; | ||
| 76 | #endif | ||
| 77 | 	uint32_t data[9]; | ||
| 78 | }; | ||
| 79 | |||
| 80 | #define	IPVERSION	4 | ||
| 81 | #define	IP_MAXPACKET	65535 | ||
| 82 | |||
| 83 | #define	IPTOS_ECN_MASK		0x03 | ||
| 84 | #define	IPTOS_ECN(x)		((x) & IPTOS_ECN_MASK) | ||
| 85 | #define	IPTOS_ECN_NOT_ECT	0x00 | ||
| 86 | #define	IPTOS_ECN_ECT1		0x01 | ||
| 87 | #define	IPTOS_ECN_ECT0		0x02 | ||
| 88 | #define	IPTOS_ECN_CE		0x03 | ||
| 89 | |||
| 90 | #define	IPTOS_DSCP_MASK		0xfc | ||
| 91 | #define	IPTOS_DSCP(x)		((x) & IPTOS_DSCP_MASK) | ||
| 92 | #define	IPTOS_DSCP_AF11		0x28 | ||
| 93 | #define	IPTOS_DSCP_AF12		0x30 | ||
| 94 | #define	IPTOS_DSCP_AF13		0x38 | ||
| 95 | #define	IPTOS_DSCP_AF21		0x48 | ||
| 96 | #define	IPTOS_DSCP_AF22		0x50 | ||
| 97 | #define	IPTOS_DSCP_AF23		0x58 | ||
| 98 | #define	IPTOS_DSCP_AF31		0x68 | ||
| 99 | #define	IPTOS_DSCP_AF32		0x70 | ||
| 100 | #define	IPTOS_DSCP_AF33		0x78 | ||
| 101 | #define	IPTOS_DSCP_AF41		0x88 | ||
| 102 | #define	IPTOS_DSCP_AF42		0x90 | ||
| 103 | #define	IPTOS_DSCP_AF43		0x98 | ||
| 104 | #define	IPTOS_DSCP_EF		0xb8 | ||
| 105 | |||
| 106 | #define	IPTOS_CLASS_MASK	0xe0 | ||
| 107 | #define	IPTOS_CLASS(x)		((x) & IPTOS_CLASS_MASK) | ||
| 108 | #define	IPTOS_CLASS_CS0		0x00 | ||
| 109 | #define	IPTOS_CLASS_CS1		0x20 | ||
| 110 | #define	IPTOS_CLASS_CS2		0x40 | ||
| 111 | #define	IPTOS_CLASS_CS3		0x60 | ||
| 112 | #define	IPTOS_CLASS_CS4		0x80 | ||
| 113 | #define	IPTOS_CLASS_CS5		0xa0 | ||
| 114 | #define	IPTOS_CLASS_CS6		0xc0 | ||
| 115 | #define	IPTOS_CLASS_CS7		0xe0 | ||
| 116 | #define	IPTOS_CLASS_DEFAULT	IPTOS_CLASS_CS0 | ||
| 117 | |||
| 118 | #define	IPTOS_TOS_MASK		0x1E | ||
| 119 | #define	IPTOS_TOS(tos)		((tos) & IPTOS_TOS_MASK) | ||
| 120 | #define	IPTOS_LOWDELAY		0x10 | ||
| 121 | #define	IPTOS_THROUGHPUT	0x08 | ||
| 122 | #define	IPTOS_RELIABILITY	0x04 | ||
| 123 | #define	IPTOS_LOWCOST		0x02 | ||
| 124 | #define	IPTOS_MINCOST		IPTOS_LOWCOST | ||
| 125 | |||
| 126 | #define	IPTOS_PREC_MASK			0xe0 | ||
| 127 | #define	IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) | ||
| 128 | #define	IPTOS_PREC_NETCONTROL		0xe0 | ||
| 129 | #define	IPTOS_PREC_INTERNETCONTROL	0xc0 | ||
| 130 | #define	IPTOS_PREC_CRITIC_ECP		0xa0 | ||
| 131 | #define	IPTOS_PREC_FLASHOVERRIDE	0x80 | ||
| 132 | #define	IPTOS_PREC_FLASH		0x60 | ||
| 133 | #define	IPTOS_PREC_IMMEDIATE		0x40 | ||
| 134 | #define	IPTOS_PREC_PRIORITY		0x20 | ||
| 135 | #define	IPTOS_PREC_ROUTINE		0x00 | ||
| 136 | |||
| 137 | #define	IPOPT_COPY		0x80 | ||
| 138 | #define	IPOPT_CLASS_MASK	0x60 | ||
| 139 | #define	IPOPT_NUMBER_MASK	0x1f | ||
| 140 | |||
| 141 | #define	IPOPT_COPIED(o)		((o) & IPOPT_COPY) | ||
| 142 | #define	IPOPT_CLASS(o)		((o) & IPOPT_CLASS_MASK) | ||
| 143 | #define	IPOPT_NUMBER(o)		((o) & IPOPT_NUMBER_MASK) | ||
| 144 | |||
| 145 | #define	IPOPT_CONTROL		0x00 | ||
| 146 | #define	IPOPT_RESERVED1		0x20 | ||
| 147 | #define	IPOPT_DEBMEAS		0x40 | ||
| 148 | #define	IPOPT_MEASUREMENT IPOPT_DEBMEAS | ||
| 149 | #define	IPOPT_RESERVED2		0x60 | ||
| 150 | |||
| 151 | #define	IPOPT_EOL		0 | ||
| 152 | #define	IPOPT_END		IPOPT_EOL | ||
| 153 | #define	IPOPT_NOP		1 | ||
| 154 | #define	IPOPT_NOOP		IPOPT_NOP | ||
| 155 | |||
| 156 | #define	IPOPT_RR		7 | ||
| 157 | #define	IPOPT_TS		68 | ||
| 158 | #define	IPOPT_TIMESTAMP		IPOPT_TS | ||
| 159 | #define	IPOPT_SECURITY		130 | ||
| 160 | #define	IPOPT_SEC		IPOPT_SECURITY | ||
| 161 | #define	IPOPT_LSRR		131 | ||
| 162 | #define	IPOPT_SATID		136 | ||
| 163 | #define	IPOPT_SID		IPOPT_SATID | ||
| 164 | #define	IPOPT_SSRR		137 | ||
| 165 | #define	IPOPT_RA		148 | ||
| 166 | |||
| 167 | #define	IPOPT_OPTVAL		0 | ||
| 168 | #define	IPOPT_OLEN		1 | ||
| 169 | #define	IPOPT_OFFSET		2 | ||
| 170 | #define	IPOPT_MINOFF		4 | ||
| 171 | |||
| 172 | #define	MAX_IPOPTLEN		40 | ||
| 173 | |||
| 174 | #define	IPOPT_TS_TSONLY		0 | ||
| 175 | #define	IPOPT_TS_TSANDADDR	1 | ||
| 176 | #define	IPOPT_TS_PRESPEC	3 | ||
| 177 | |||
| 178 | #define	IPOPT_SECUR_UNCLASS	0x0000 | ||
| 179 | #define	IPOPT_SECUR_CONFID	0xf135 | ||
| 180 | #define	IPOPT_SECUR_EFTO	0x789a | ||
| 181 | #define	IPOPT_SECUR_MMMM	0xbc4d | ||
| 182 | #define	IPOPT_SECUR_RESTR	0xaf13 | ||
| 183 | #define	IPOPT_SECUR_SECRET	0xd788 | ||
| 184 | #define	IPOPT_SECUR_TOPSECRET	0x6bc5 | ||
| 185 | |||
| 186 | #define	MAXTTL		255 | ||
| 187 | #define	IPDEFTTL	64 | ||
| 188 | #define	IPFRAGTTL	60 | ||
| 189 | #define	IPTTLDEC	1 | ||
| 190 | |||
| 191 | #define	IP_MSS		576 | ||
| 192 | |||
| 193 | #define __UAPI_DEF_IPHDR	0 | ||
| 194 | |||
| 195 | #ifdef __cplusplus | ||
| 196 | } | ||
| 197 | #endif | ||
| 198 | |||
| 199 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/ip6.h created+141| ... | @@ -0,0 +1,141 @@ | ||
| 1 | #ifndef _NETINET_IP6_H | ||
| 2 | #define _NETINET_IP6_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | struct ip6_hdr { | ||
| 12 | 	union { | ||
| 13 | 		struct ip6_hdrctl { | ||
| 14 | 			uint32_t ip6_un1_flow; | ||
| 15 | 			uint16_t ip6_un1_plen; | ||
| 16 | 			uint8_t ip6_un1_nxt; | ||
| 17 | 			uint8_t ip6_un1_hlim; | ||
| 18 | 		} ip6_un1; | ||
| 19 | 		uint8_t ip6_un2_vfc; | ||
| 20 | 	} ip6_ctlun; | ||
| 21 | 	struct in6_addr ip6_src; | ||
| 22 | 	struct in6_addr ip6_dst; | ||
| 23 | }; | ||
| 24 | |||
| 25 | #define ip6_vfc ip6_ctlun.ip6_un2_vfc | ||
| 26 | #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow | ||
| 27 | #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen | ||
| 28 | #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt | ||
| 29 | #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim | ||
| 30 | #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim | ||
| 31 | |||
| 32 | struct ip6_ext { | ||
| 33 | 	uint8_t ip6e_nxt; | ||
| 34 | 	uint8_t ip6e_len; | ||
| 35 | }; | ||
| 36 | |||
| 37 | struct ip6_hbh { | ||
| 38 | 	uint8_t ip6h_nxt; | ||
| 39 | 	uint8_t ip6h_len; | ||
| 40 | }; | ||
| 41 | |||
| 42 | struct ip6_dest { | ||
| 43 | 	uint8_t ip6d_nxt; | ||
| 44 | 	uint8_t ip6d_len; | ||
| 45 | }; | ||
| 46 | |||
| 47 | struct ip6_rthdr { | ||
| 48 | 	uint8_t ip6r_nxt; | ||
| 49 | 	uint8_t ip6r_len; | ||
| 50 | 	uint8_t ip6r_type; | ||
| 51 | 	uint8_t ip6r_segleft; | ||
| 52 | }; | ||
| 53 | |||
| 54 | struct ip6_rthdr0 { | ||
| 55 | 	uint8_t ip6r0_nxt; | ||
| 56 | 	uint8_t ip6r0_len; | ||
| 57 | 	uint8_t ip6r0_type; | ||
| 58 | 	uint8_t ip6r0_segleft; | ||
| 59 | 	uint8_t ip6r0_reserved; | ||
| 60 | 	uint8_t ip6r0_slmap[3]; | ||
| 61 | 	struct in6_addr ip6r0_addr[]; | ||
| 62 | }; | ||
| 63 | |||
| 64 | struct ip6_frag { | ||
| 65 | 	uint8_t ip6f_nxt; | ||
| 66 | 	uint8_t ip6f_reserved; | ||
| 67 | 	uint16_t ip6f_offlg; | ||
| 68 | 	uint32_t ip6f_ident; | ||
| 69 | }; | ||
| 70 | |||
| 71 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 72 | #define IP6F_OFF_MASK 0xfff8 | ||
| 73 | #define IP6F_RESERVED_MASK 0x0006 | ||
| 74 | #define IP6F_MORE_FRAG 0x0001 | ||
| 75 | #else | ||
| 76 | #define IP6F_OFF_MASK 0xf8ff | ||
| 77 | #define IP6F_RESERVED_MASK 0x0600 | ||
| 78 | #define IP6F_MORE_FRAG 0x0100 | ||
| 79 | #endif | ||
| 80 | |||
| 81 | struct ip6_opt { | ||
| 82 | 	uint8_t ip6o_type; | ||
| 83 | 	uint8_t ip6o_len; | ||
| 84 | }; | ||
| 85 | |||
| 86 | #define IP6OPT_TYPE(o)		((o) & 0xc0) | ||
| 87 | #define IP6OPT_TYPE_SKIP	0x00 | ||
| 88 | #define IP6OPT_TYPE_DISCARD	0x40 | ||
| 89 | #define IP6OPT_TYPE_FORCEICMP	0x80 | ||
| 90 | #define IP6OPT_TYPE_ICMP	0xc0 | ||
| 91 | #define IP6OPT_TYPE_MUTABLE	0x20 | ||
| 92 | |||
| 93 | #define IP6OPT_PAD1	0 | ||
| 94 | #define IP6OPT_PADN	1 | ||
| 95 | |||
| 96 | #define IP6OPT_JUMBO		0xc2 | ||
| 97 | #define IP6OPT_NSAP_ADDR	0xc3 | ||
| 98 | #define IP6OPT_TUNNEL_LIMIT	0x04 | ||
| 99 | #define IP6OPT_ROUTER_ALERT	0x05 | ||
| 100 | |||
| 101 | struct ip6_opt_jumbo { | ||
| 102 | 	uint8_t ip6oj_type; | ||
| 103 | 	uint8_t ip6oj_len; | ||
| 104 | 	uint8_t ip6oj_jumbo_len[4]; | ||
| 105 | }; | ||
| 106 | #define IP6OPT_JUMBO_LEN	6 | ||
| 107 | |||
| 108 | struct ip6_opt_nsap { | ||
| 109 | 	uint8_t ip6on_type; | ||
| 110 | 	uint8_t ip6on_len; | ||
| 111 | 	uint8_t ip6on_src_nsap_len; | ||
| 112 | 	uint8_t ip6on_dst_nsap_len; | ||
| 113 | }; | ||
| 114 | |||
| 115 | struct ip6_opt_tunnel { | ||
| 116 | 	uint8_t ip6ot_type; | ||
| 117 | 	uint8_t ip6ot_len; | ||
| 118 | 	uint8_t ip6ot_encap_limit; | ||
| 119 | }; | ||
| 120 | |||
| 121 | struct ip6_opt_router { | ||
| 122 | 	uint8_t ip6or_type; | ||
| 123 | 	uint8_t ip6or_len; | ||
| 124 | 	uint8_t ip6or_value[2]; | ||
| 125 | }; | ||
| 126 | |||
| 127 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 128 | #define IP6_ALERT_MLD	0x0000 | ||
| 129 | #define IP6_ALERT_RSVP	0x0001 | ||
| 130 | #define IP6_ALERT_AN	0x0002 | ||
| 131 | #else | ||
| 132 | #define IP6_ALERT_MLD	0x0000 | ||
| 133 | #define IP6_ALERT_RSVP	0x0100 | ||
| 134 | #define IP6_ALERT_AN	0x0200 | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #ifdef __cplusplus | ||
| 138 | } | ||
| 139 | #endif | ||
| 140 | |||
| 141 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/ip_icmp.h created+193| ... | @@ -0,0 +1,193 @@ | ||
| 1 | #ifndef _NETINET_IP_ICMP_H | ||
| 2 | #define _NETINET_IP_ICMP_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <netinet/in.h> | ||
| 6 | #include <netinet/ip.h> | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | struct icmphdr { | ||
| 13 | 	uint8_t type; | ||
| 14 | 	uint8_t code; | ||
| 15 | 	uint16_t checksum; | ||
| 16 | 	union { | ||
| 17 | 		struct { | ||
| 18 | 			uint16_t id; | ||
| 19 | 			uint16_t sequence; | ||
| 20 | 		} echo; | ||
| 21 | 		uint32_t gateway; | ||
| 22 | 		struct { | ||
| 23 | 			uint16_t __unused; | ||
| 24 | 			uint16_t mtu; | ||
| 25 | 		} frag; | ||
| 26 | 		uint8_t reserved[4]; | ||
| 27 | 	} un; | ||
| 28 | }; | ||
| 29 | |||
| 30 | #define ICMP_ECHOREPLY		0 | ||
| 31 | #define ICMP_DEST_UNREACH	3 | ||
| 32 | #define ICMP_SOURCE_QUENCH	4 | ||
| 33 | #define ICMP_REDIRECT		5 | ||
| 34 | #define ICMP_ECHO		8 | ||
| 35 | #define ICMP_TIME_EXCEEDED	11 | ||
| 36 | #define ICMP_PARAMETERPROB	12 | ||
| 37 | #define ICMP_TIMESTAMP		13 | ||
| 38 | #define ICMP_TIMESTAMPREPLY	14 | ||
| 39 | #define ICMP_INFO_REQUEST	15 | ||
| 40 | #define ICMP_INFO_REPLY		16 | ||
| 41 | #define ICMP_ADDRESS		17 | ||
| 42 | #define ICMP_ADDRESSREPLY	18 | ||
| 43 | #define NR_ICMP_TYPES		18 | ||
| 44 | |||
| 45 | |||
| 46 | #define ICMP_NET_UNREACH	0 | ||
| 47 | #define ICMP_HOST_UNREACH	1 | ||
| 48 | #define ICMP_PROT_UNREACH	2 | ||
| 49 | #define ICMP_PORT_UNREACH	3 | ||
| 50 | #define ICMP_FRAG_NEEDED	4 | ||
| 51 | #define ICMP_SR_FAILED		5 | ||
| 52 | #define ICMP_NET_UNKNOWN	6 | ||
| 53 | #define ICMP_HOST_UNKNOWN	7 | ||
| 54 | #define ICMP_HOST_ISOLATED	8 | ||
| 55 | #define ICMP_NET_ANO		9 | ||
| 56 | #define ICMP_HOST_ANO		10 | ||
| 57 | #define ICMP_NET_UNR_TOS	11 | ||
| 58 | #define ICMP_HOST_UNR_TOS	12 | ||
| 59 | #define ICMP_PKT_FILTERED	13 | ||
| 60 | #define ICMP_PREC_VIOLATION	14 | ||
| 61 | #define ICMP_PREC_CUTOFF	15 | ||
| 62 | #define NR_ICMP_UNREACH		15 | ||
| 63 | |||
| 64 | #define ICMP_REDIR_NET		0 | ||
| 65 | #define ICMP_REDIR_HOST		1 | ||
| 66 | #define ICMP_REDIR_NETTOS	2 | ||
| 67 | #define ICMP_REDIR_HOSTTOS	3 | ||
| 68 | |||
| 69 | #define ICMP_EXC_TTL		0 | ||
| 70 | #define ICMP_EXC_FRAGTIME	1 | ||
| 71 | |||
| 72 | |||
| 73 | struct icmp_ra_addr { | ||
| 74 | 	uint32_t ira_addr; | ||
| 75 | 	uint32_t ira_preference; | ||
| 76 | }; | ||
| 77 | |||
| 78 | struct icmp { | ||
| 79 | 	uint8_t icmp_type; | ||
| 80 | 	uint8_t icmp_code; | ||
| 81 | 	uint16_t icmp_cksum; | ||
| 82 | 	union { | ||
| 83 | 		uint8_t ih_pptr; | ||
| 84 | 		struct in_addr ih_gwaddr; | ||
| 85 | 		struct ih_idseq { | ||
| 86 | 			uint16_t icd_id; | ||
| 87 | 			uint16_t icd_seq; | ||
| 88 | 		} ih_idseq; | ||
| 89 | 		uint32_t ih_void; | ||
| 90 | |||
| 91 | 		struct ih_pmtu { | ||
| 92 | 			uint16_t ipm_void; | ||
| 93 | 			uint16_t ipm_nextmtu; | ||
| 94 | 		} ih_pmtu; | ||
| 95 | |||
| 96 | 		struct ih_rtradv { | ||
| 97 | 			uint8_t irt_num_addrs; | ||
| 98 | 			uint8_t irt_wpa; | ||
| 99 | 			uint16_t irt_lifetime; | ||
| 100 | 		} ih_rtradv; | ||
| 101 | 	} icmp_hun; | ||
| 102 | 	union { | ||
| 103 | 		struct { | ||
| 104 | 			uint32_t its_otime; | ||
| 105 | 			uint32_t its_rtime; | ||
| 106 | 			uint32_t its_ttime; | ||
| 107 | 		} id_ts; | ||
| 108 | 		struct { | ||
| 109 | 			struct ip idi_ip; | ||
| 110 | 		} id_ip; | ||
| 111 | 		struct icmp_ra_addr id_radv; | ||
| 112 | 		uint32_t id_mask; | ||
| 113 | 		uint8_t id_data[1]; | ||
| 114 | 	} icmp_dun; | ||
| 115 | }; | ||
| 116 | |||
| 117 | #define	icmp_pptr	icmp_hun.ih_pptr | ||
| 118 | #define	icmp_gwaddr	icmp_hun.ih_gwaddr | ||
| 119 | #define	icmp_id		icmp_hun.ih_idseq.icd_id | ||
| 120 | #define	icmp_seq	icmp_hun.ih_idseq.icd_seq | ||
| 121 | #define	icmp_void	icmp_hun.ih_void | ||
| 122 | #define	icmp_pmvoid	icmp_hun.ih_pmtu.ipm_void | ||
| 123 | #define	icmp_nextmtu	icmp_hun.ih_pmtu.ipm_nextmtu | ||
| 124 | #define	icmp_num_addrs	icmp_hun.ih_rtradv.irt_num_addrs | ||
| 125 | #define	icmp_wpa	icmp_hun.ih_rtradv.irt_wpa | ||
| 126 | #define	icmp_lifetime	icmp_hun.ih_rtradv.irt_lifetime | ||
| 127 | #define	icmp_otime	icmp_dun.id_ts.its_otime | ||
| 128 | #define	icmp_rtime	icmp_dun.id_ts.its_rtime | ||
| 129 | #define	icmp_ttime	icmp_dun.id_ts.its_ttime | ||
| 130 | #define	icmp_ip		icmp_dun.id_ip.idi_ip | ||
| 131 | #define	icmp_radv	icmp_dun.id_radv | ||
| 132 | #define	icmp_mask	icmp_dun.id_mask | ||
| 133 | #define	icmp_data	icmp_dun.id_data | ||
| 134 | |||
| 135 | #define	ICMP_MINLEN	8 | ||
| 136 | #define	ICMP_TSLEN	(8 + 3 * sizeof (n_time)) | ||
| 137 | #define	ICMP_MASKLEN	12 | ||
| 138 | #define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8) | ||
| 139 | #define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8) | ||
| 140 | |||
| 141 | #define	ICMP_UNREACH		3 | ||
| 142 | #define	ICMP_SOURCEQUENCH	4 | ||
| 143 | #define	ICMP_ROUTERADVERT	9 | ||
| 144 | #define	ICMP_ROUTERSOLICIT	10 | ||
| 145 | #define	ICMP_TIMXCEED		11 | ||
| 146 | #define	ICMP_PARAMPROB		12 | ||
| 147 | #define	ICMP_TSTAMP		13 | ||
| 148 | #define	ICMP_TSTAMPREPLY	14 | ||
| 149 | #define	ICMP_IREQ		15 | ||
| 150 | #define	ICMP_IREQREPLY		16 | ||
| 151 | #define	ICMP_MASKREQ		17 | ||
| 152 | #define	ICMP_MASKREPLY		18 | ||
| 153 | #define	ICMP_MAXTYPE		18 | ||
| 154 | |||
| 155 | #define	ICMP_UNREACH_NET	 0 | ||
| 156 | #define	ICMP_UNREACH_HOST	 1 | ||
| 157 | #define	ICMP_UNREACH_PROTOCOL	 2 | ||
| 158 | #define	ICMP_UNREACH_PORT	 3 | ||
| 159 | #define	ICMP_UNREACH_NEEDFRAG	 4 | ||
| 160 | #define	ICMP_UNREACH_SRCFAIL	 5 | ||
| 161 | #define	ICMP_UNREACH_NET_UNKNOWN 6 | ||
| 162 | #define	ICMP_UNREACH_HOST_UNKNOWN 7 | ||
| 163 | #define	ICMP_UNREACH_ISOLATED	 8 | ||
| 164 | #define	ICMP_UNREACH_NET_PROHIB	 9 | ||
| 165 | #define	ICMP_UNREACH_HOST_PROHIB 10 | ||
| 166 | #define	ICMP_UNREACH_TOSNET	 11 | ||
| 167 | #define	ICMP_UNREACH_TOSHOST	 12 | ||
| 168 | #define	ICMP_UNREACH_FILTER_PROHIB 13 | ||
| 169 | #define	ICMP_UNREACH_HOST_PRECEDENCE 14 | ||
| 170 | #define	ICMP_UNREACH_PRECEDENCE_CUTOFF 15 | ||
| 171 | |||
| 172 | #define	ICMP_REDIRECT_NET	0 | ||
| 173 | #define	ICMP_REDIRECT_HOST	1 | ||
| 174 | #define	ICMP_REDIRECT_TOSNET	2 | ||
| 175 | #define	ICMP_REDIRECT_TOSHOST	3 | ||
| 176 | |||
| 177 | #define	ICMP_TIMXCEED_INTRANS	0 | ||
| 178 | #define	ICMP_TIMXCEED_REASS	1 | ||
| 179 | |||
| 180 | #define	ICMP_PARAMPROB_OPTABSENT 1 | ||
| 181 | |||
| 182 | #define	ICMP_INFOTYPE(type) \ | ||
| 183 | 	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ | ||
| 184 | 	(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ | ||
| 185 | 	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ | ||
| 186 | 	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ | ||
| 187 | 	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) | ||
| 188 | |||
| 189 | #ifdef __cplusplus | ||
| 190 | } | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/tcp.h created+294| ... | @@ -0,0 +1,294 @@ | ||
| 1 | #ifndef _NETINET_TCP_H | ||
| 2 | #define _NETINET_TCP_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | #define TCP_NODELAY 1 | ||
| 7 | #define TCP_MAXSEG	 2 | ||
| 8 | #define TCP_CORK	 3 | ||
| 9 | #define TCP_KEEPIDLE	 4 | ||
| 10 | #define TCP_KEEPINTVL	 5 | ||
| 11 | #define TCP_KEEPCNT	 6 | ||
| 12 | #define TCP_SYNCNT	 7 | ||
| 13 | #define TCP_LINGER2	 8 | ||
| 14 | #define TCP_DEFER_ACCEPT 9 | ||
| 15 | #define TCP_WINDOW_CLAMP 10 | ||
| 16 | #define TCP_INFO	 11 | ||
| 17 | #define	TCP_QUICKACK	 12 | ||
| 18 | #define TCP_CONGESTION	 13 | ||
| 19 | #define TCP_MD5SIG	 14 | ||
| 20 | #define TCP_THIN_LINEAR_TIMEOUTS 16 | ||
| 21 | #define TCP_THIN_DUPACK 17 | ||
| 22 | #define TCP_USER_TIMEOUT 18 | ||
| 23 | #define TCP_REPAIR 19 | ||
| 24 | #define TCP_REPAIR_QUEUE 20 | ||
| 25 | #define TCP_QUEUE_SEQ 21 | ||
| 26 | #define TCP_REPAIR_OPTIONS 22 | ||
| 27 | #define TCP_FASTOPEN 23 | ||
| 28 | #define TCP_TIMESTAMP 24 | ||
| 29 | #define TCP_NOTSENT_LOWAT 25 | ||
| 30 | #define TCP_CC_INFO 26 | ||
| 31 | #define TCP_SAVE_SYN 27 | ||
| 32 | #define TCP_SAVED_SYN 28 | ||
| 33 | #define TCP_REPAIR_WINDOW 29 | ||
| 34 | #define TCP_FASTOPEN_CONNECT 30 | ||
| 35 | #define TCP_ULP 31 | ||
| 36 | #define TCP_MD5SIG_EXT 32 | ||
| 37 | #define TCP_FASTOPEN_KEY 33 | ||
| 38 | #define TCP_FASTOPEN_NO_COOKIE 34 | ||
| 39 | #define TCP_ZEROCOPY_RECEIVE 35 | ||
| 40 | #define TCP_INQ 36 | ||
| 41 | #define TCP_TX_DELAY 37 | ||
| 42 | |||
| 43 | #define TCP_CM_INQ TCP_INQ | ||
| 44 | |||
| 45 | #define TCP_ESTABLISHED 1 | ||
| 46 | #define TCP_SYN_SENT 2 | ||
| 47 | #define TCP_SYN_RECV 3 | ||
| 48 | #define TCP_FIN_WAIT1 4 | ||
| 49 | #define TCP_FIN_WAIT2 5 | ||
| 50 | #define TCP_TIME_WAIT 6 | ||
| 51 | #define TCP_CLOSE 7 | ||
| 52 | #define TCP_CLOSE_WAIT 8 | ||
| 53 | #define TCP_LAST_ACK 9 | ||
| 54 | #define TCP_LISTEN 10 | ||
| 55 | #define TCP_CLOSING 11 | ||
| 56 | |||
| 57 | enum { | ||
| 58 | 	TCP_NLA_PAD, | ||
| 59 | 	TCP_NLA_BUSY, | ||
| 60 | 	TCP_NLA_RWND_LIMITED, | ||
| 61 | 	TCP_NLA_SNDBUF_LIMITED, | ||
| 62 | 	TCP_NLA_DATA_SEGS_OUT, | ||
| 63 | 	TCP_NLA_TOTAL_RETRANS, | ||
| 64 | 	TCP_NLA_PACING_RATE, | ||
| 65 | 	TCP_NLA_DELIVERY_RATE, | ||
| 66 | 	TCP_NLA_SND_CWND, | ||
| 67 | 	TCP_NLA_REORDERING, | ||
| 68 | 	TCP_NLA_MIN_RTT, | ||
| 69 | 	TCP_NLA_RECUR_RETRANS, | ||
| 70 | 	TCP_NLA_DELIVERY_RATE_APP_LMT, | ||
| 71 | 	TCP_NLA_SNDQ_SIZE, | ||
| 72 | 	TCP_NLA_CA_STATE, | ||
| 73 | 	TCP_NLA_SND_SSTHRESH, | ||
| 74 | 	TCP_NLA_DELIVERED, | ||
| 75 | 	TCP_NLA_DELIVERED_CE, | ||
| 76 | 	TCP_NLA_BYTES_SENT, | ||
| 77 | 	TCP_NLA_BYTES_RETRANS, | ||
| 78 | 	TCP_NLA_DSACK_DUPS, | ||
| 79 | 	TCP_NLA_REORD_SEEN, | ||
| 80 | 	TCP_NLA_SRTT, | ||
| 81 | 	TCP_NLA_TIMEOUT_REHASH, | ||
| 82 | 	TCP_NLA_BYTES_NOTSENT, | ||
| 83 | }; | ||
| 84 | |||
| 85 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 86 | #define TCPOPT_EOL 0 | ||
| 87 | #define TCPOPT_NOP 1 | ||
| 88 | #define TCPOPT_MAXSEG 2 | ||
| 89 | #define TCPOPT_WINDOW 3 | ||
| 90 | #define TCPOPT_SACK_PERMITTED 4 | ||
| 91 | #define TCPOPT_SACK 5 | ||
| 92 | #define TCPOPT_TIMESTAMP 8 | ||
| 93 | #define TCPOLEN_SACK_PERMITTED 2 | ||
| 94 | #define TCPOLEN_WINDOW 3 | ||
| 95 | #define TCPOLEN_MAXSEG 4 | ||
| 96 | #define TCPOLEN_TIMESTAMP 10 | ||
| 97 | |||
| 98 | #define SOL_TCP 6 | ||
| 99 | |||
| 100 | #include <sys/types.h> | ||
| 101 | #include <sys/socket.h> | ||
| 102 | #include <stdint.h> | ||
| 103 | |||
| 104 | typedef uint32_t tcp_seq; | ||
| 105 | |||
| 106 | #define TH_FIN 0x01 | ||
| 107 | #define TH_SYN 0x02 | ||
| 108 | #define TH_RST 0x04 | ||
| 109 | #define TH_PUSH 0x08 | ||
| 110 | #define TH_ACK 0x10 | ||
| 111 | #define TH_URG 0x20 | ||
| 112 | |||
| 113 | struct tcphdr { | ||
| 114 | #ifdef _GNU_SOURCE | ||
| 115 | #ifdef __GNUC__ | ||
| 116 | 	__extension__ | ||
| 117 | #endif | ||
| 118 | 	union { struct { | ||
| 119 | |||
| 120 | 	uint16_t source; | ||
| 121 | 	uint16_t dest; | ||
| 122 | 	uint32_t seq; | ||
| 123 | 	uint32_t ack_seq; | ||
| 124 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 125 | 	uint16_t res1:4; | ||
| 126 | 	uint16_t doff:4; | ||
| 127 | 	uint16_t fin:1; | ||
| 128 | 	uint16_t syn:1; | ||
| 129 | 	uint16_t rst:1; | ||
| 130 | 	uint16_t psh:1; | ||
| 131 | 	uint16_t ack:1; | ||
| 132 | 	uint16_t urg:1; | ||
| 133 | 	uint16_t res2:2; | ||
| 134 | #else | ||
| 135 | 	uint16_t doff:4; | ||
| 136 | 	uint16_t res1:4; | ||
| 137 | 	uint16_t res2:2; | ||
| 138 | 	uint16_t urg:1; | ||
| 139 | 	uint16_t ack:1; | ||
| 140 | 	uint16_t psh:1; | ||
| 141 | 	uint16_t rst:1; | ||
| 142 | 	uint16_t syn:1; | ||
| 143 | 	uint16_t fin:1; | ||
| 144 | #endif | ||
| 145 | 	uint16_t window; | ||
| 146 | 	uint16_t check; | ||
| 147 | 	uint16_t urg_ptr; | ||
| 148 | |||
| 149 | 	}; struct { | ||
| 150 | #endif | ||
| 151 | |||
| 152 | 	uint16_t th_sport; | ||
| 153 | 	uint16_t th_dport; | ||
| 154 | 	uint32_t th_seq; | ||
| 155 | 	uint32_t th_ack; | ||
| 156 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 157 | 	uint8_t th_x2:4; | ||
| 158 | 	uint8_t th_off:4; | ||
| 159 | #else | ||
| 160 | 	uint8_t th_off:4; | ||
| 161 | 	uint8_t th_x2:4; | ||
| 162 | #endif | ||
| 163 | 	uint8_t th_flags; | ||
| 164 | 	uint16_t th_win; | ||
| 165 | 	uint16_t th_sum; | ||
| 166 | 	uint16_t th_urp; | ||
| 167 | |||
| 168 | #ifdef _GNU_SOURCE | ||
| 169 | 	}; }; | ||
| 170 | #endif | ||
| 171 | }; | ||
| 172 | #endif | ||
| 173 | |||
| 174 | #ifdef _GNU_SOURCE | ||
| 175 | #define TCPI_OPT_TIMESTAMPS	1 | ||
| 176 | #define TCPI_OPT_SACK		2 | ||
| 177 | #define TCPI_OPT_WSCALE		4 | ||
| 178 | #define TCPI_OPT_ECN		8 | ||
| 179 | |||
| 180 | #define TCP_CA_Open		0 | ||
| 181 | #define TCP_CA_Disorder		1 | ||
| 182 | #define TCP_CA_CWR		2 | ||
| 183 | #define TCP_CA_Recovery		3 | ||
| 184 | #define TCP_CA_Loss		4 | ||
| 185 | |||
| 186 | enum tcp_fastopen_client_fail { | ||
| 187 | 	TFO_STATUS_UNSPEC, | ||
| 188 | 	TFO_COOKIE_UNAVAILABLE, | ||
| 189 | 	TFO_DATA_NOT_ACKED, | ||
| 190 | 	TFO_SYN_RETRANSMITTED, | ||
| 191 | }; | ||
| 192 | |||
| 193 | struct tcp_info { | ||
| 194 | 	uint8_t tcpi_state; | ||
| 195 | 	uint8_t tcpi_ca_state; | ||
| 196 | 	uint8_t tcpi_retransmits; | ||
| 197 | 	uint8_t tcpi_probes; | ||
| 198 | 	uint8_t tcpi_backoff; | ||
| 199 | 	uint8_t tcpi_options; | ||
| 200 | 	uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; | ||
| 201 | 	uint8_t tcpi_delivery_rate_app_limited : 1, tcpi_fastopen_client_fail : 2; | ||
| 202 | 	uint32_t tcpi_rto; | ||
| 203 | 	uint32_t tcpi_ato; | ||
| 204 | 	uint32_t tcpi_snd_mss; | ||
| 205 | 	uint32_t tcpi_rcv_mss; | ||
| 206 | 	uint32_t tcpi_unacked; | ||
| 207 | 	uint32_t tcpi_sacked; | ||
| 208 | 	uint32_t tcpi_lost; | ||
| 209 | 	uint32_t tcpi_retrans; | ||
| 210 | 	uint32_t tcpi_fackets; | ||
| 211 | 	uint32_t tcpi_last_data_sent; | ||
| 212 | 	uint32_t tcpi_last_ack_sent; | ||
| 213 | 	uint32_t tcpi_last_data_recv; | ||
| 214 | 	uint32_t tcpi_last_ack_recv; | ||
| 215 | 	uint32_t tcpi_pmtu; | ||
| 216 | 	uint32_t tcpi_rcv_ssthresh; | ||
| 217 | 	uint32_t tcpi_rtt; | ||
| 218 | 	uint32_t tcpi_rttvar; | ||
| 219 | 	uint32_t tcpi_snd_ssthresh; | ||
| 220 | 	uint32_t tcpi_snd_cwnd; | ||
| 221 | 	uint32_t tcpi_advmss; | ||
| 222 | 	uint32_t tcpi_reordering; | ||
| 223 | 	uint32_t tcpi_rcv_rtt; | ||
| 224 | 	uint32_t tcpi_rcv_space; | ||
| 225 | 	uint32_t tcpi_total_retrans; | ||
| 226 | 	uint64_t tcpi_pacing_rate; | ||
| 227 | 	uint64_t tcpi_max_pacing_rate; | ||
| 228 | 	uint64_t tcpi_bytes_acked; | ||
| 229 | 	uint64_t tcpi_bytes_received; | ||
| 230 | 	uint32_t tcpi_segs_out; | ||
| 231 | 	uint32_t tcpi_segs_in; | ||
| 232 | 	uint32_t tcpi_notsent_bytes; | ||
| 233 | 	uint32_t tcpi_min_rtt; | ||
| 234 | 	uint32_t tcpi_data_segs_in; | ||
| 235 | 	uint32_t tcpi_data_segs_out; | ||
| 236 | 	uint64_t tcpi_delivery_rate; | ||
| 237 | 	uint64_t tcpi_busy_time; | ||
| 238 | 	uint64_t tcpi_rwnd_limited; | ||
| 239 | 	uint64_t tcpi_sndbuf_limited; | ||
| 240 | 	uint32_t tcpi_delivered; | ||
| 241 | 	uint32_t tcpi_delivered_ce; | ||
| 242 | 	uint64_t tcpi_bytes_sent; | ||
| 243 | 	uint64_t tcpi_bytes_retrans; | ||
| 244 | 	uint32_t tcpi_dsack_dups; | ||
| 245 | 	uint32_t tcpi_reord_seen; | ||
| 246 | 	uint32_t tcpi_rcv_ooopack; | ||
| 247 | 	uint32_t tcpi_snd_wnd; | ||
| 248 | }; | ||
| 249 | |||
| 250 | #define TCP_MD5SIG_MAXKEYLEN 80 | ||
| 251 | |||
| 252 | #define TCP_MD5SIG_FLAG_PREFIX 0x1 | ||
| 253 | #define TCP_MD5SIG_FLAG_IFINDEX 0x2 | ||
| 254 | |||
| 255 | struct tcp_md5sig { | ||
| 256 | 	struct sockaddr_storage tcpm_addr; | ||
| 257 | 	uint8_t tcpm_flags; | ||
| 258 | 	uint8_t tcpm_prefixlen; | ||
| 259 | 	uint16_t tcpm_keylen; | ||
| 260 | 	int tcpm_ifindex; | ||
| 261 | 	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; | ||
| 262 | }; | ||
| 263 | |||
| 264 | struct tcp_diag_md5sig { | ||
| 265 | 	uint8_t tcpm_family; | ||
| 266 | 	uint8_t tcpm_prefixlen; | ||
| 267 | 	uint16_t tcpm_keylen; | ||
| 268 | 	uint32_t tcpm_addr[4]; | ||
| 269 | 	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; | ||
| 270 | }; | ||
| 271 | |||
| 272 | #define TCP_REPAIR_ON		1 | ||
| 273 | #define TCP_REPAIR_OFF		0 | ||
| 274 | #define TCP_REPAIR_OFF_NO_WP	-1 | ||
| 275 | |||
| 276 | struct tcp_repair_window { | ||
| 277 | 	uint32_t snd_wl1; | ||
| 278 | 	uint32_t snd_wnd; | ||
| 279 | 	uint32_t max_window; | ||
| 280 | 	uint32_t rcv_wnd; | ||
| 281 | 	uint32_t rcv_wup; | ||
| 282 | }; | ||
| 283 | |||
| 284 | struct tcp_zerocopy_receive { | ||
| 285 | 	uint64_t address; | ||
| 286 | 	uint32_t length; | ||
| 287 | 	uint32_t recv_skip_hint; | ||
| 288 | 	uint32_t inq; | ||
| 289 | 	int32_t err; | ||
| 290 | }; | ||
| 291 | |||
| 292 | #endif | ||
| 293 | |||
| 294 | #endif | ||
lib/libc/include/wasm-wasi-musl/netinet/udp.h created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #ifndef _NETINET_UDP_H | ||
| 2 | #define _NETINET_UDP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #ifdef _GNU_SOURCE | ||
| 12 | #define uh_sport source | ||
| 13 | #define uh_dport dest | ||
| 14 | #define uh_ulen len | ||
| 15 | #define uh_sum check | ||
| 16 | #endif | ||
| 17 | |||
| 18 | struct udphdr { | ||
| 19 | 	uint16_t uh_sport; | ||
| 20 | 	uint16_t uh_dport; | ||
| 21 | 	uint16_t uh_ulen; | ||
| 22 | 	uint16_t uh_sum; | ||
| 23 | }; | ||
| 24 | |||
| 25 | #define UDP_CORK	1 | ||
| 26 | #define UDP_ENCAP	100 | ||
| 27 | #define UDP_NO_CHECK6_TX 101 | ||
| 28 | #define UDP_NO_CHECK6_RX 102 | ||
| 29 | #define UDP_SEGMENT	103 | ||
| 30 | #define UDP_GRO		104 | ||
| 31 | |||
| 32 | #define UDP_ENCAP_ESPINUDP_NON_IKE 1 | ||
| 33 | #define UDP_ENCAP_ESPINUDP	2 | ||
| 34 | #define UDP_ENCAP_L2TPINUDP	3 | ||
| 35 | #define UDP_ENCAP_GTP0		4 | ||
| 36 | #define UDP_ENCAP_GTP1U		5 | ||
| 37 | #define UDP_ENCAP_RXRPC		6 | ||
| 38 | #define TCP_ENCAP_ESPINTCP	7 | ||
| 39 | |||
| 40 | #define SOL_UDP 17 | ||
| 41 | |||
| 42 | #ifdef __cplusplus | ||
| 43 | } | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #endif | ||
lib/libc/include/wasm-wasi-musl/netpacket/packet.h created+62| ... | @@ -0,0 +1,62 @@ | ||
| 1 | #ifndef _NETPACKET_PACKET_H | ||
| 2 | #define _NETPACKET_PACKET_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | struct sockaddr_ll { | ||
| 9 | 	unsigned short sll_family, sll_protocol; | ||
| 10 | 	int sll_ifindex; | ||
| 11 | 	unsigned short sll_hatype; | ||
| 12 | 	unsigned char sll_pkttype, sll_halen; | ||
| 13 | 	unsigned char sll_addr[8]; | ||
| 14 | }; | ||
| 15 | |||
| 16 | struct packet_mreq { | ||
| 17 | 	int mr_ifindex; | ||
| 18 | 	unsigned short int mr_type, mr_alen; | ||
| 19 | 	unsigned char mr_address[8]; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #define PACKET_HOST		0 | ||
| 23 | #define PACKET_BROADCAST	1 | ||
| 24 | #define PACKET_MULTICAST	2 | ||
| 25 | #define PACKET_OTHERHOST	3 | ||
| 26 | #define PACKET_OUTGOING		4 | ||
| 27 | #define PACKET_LOOPBACK		5 | ||
| 28 | #define PACKET_FASTROUTE	6 | ||
| 29 | |||
| 30 | #define PACKET_ADD_MEMBERSHIP		1 | ||
| 31 | #define PACKET_DROP_MEMBERSHIP		2 | ||
| 32 | #define	PACKET_RECV_OUTPUT		3 | ||
| 33 | #define	PACKET_RX_RING			5 | ||
| 34 | #define	PACKET_STATISTICS		6 | ||
| 35 | #define PACKET_COPY_THRESH		7 | ||
| 36 | #define PACKET_AUXDATA			8 | ||
| 37 | #define PACKET_ORIGDEV			9 | ||
| 38 | #define PACKET_VERSION			10 | ||
| 39 | #define PACKET_HDRLEN			11 | ||
| 40 | #define PACKET_RESERVE			12 | ||
| 41 | #define PACKET_TX_RING			13 | ||
| 42 | #define PACKET_LOSS			14 | ||
| 43 | #define PACKET_VNET_HDR			15 | ||
| 44 | #define PACKET_TX_TIMESTAMP		16 | ||
| 45 | #define PACKET_TIMESTAMP		17 | ||
| 46 | #define PACKET_FANOUT			18 | ||
| 47 | #define PACKET_TX_HAS_OFF		19 | ||
| 48 | #define PACKET_QDISC_BYPASS		20 | ||
| 49 | #define PACKET_ROLLOVER_STATS		21 | ||
| 50 | #define PACKET_FANOUT_DATA		22 | ||
| 51 | #define PACKET_IGNORE_OUTGOING		23 | ||
| 52 | |||
| 53 | #define PACKET_MR_MULTICAST	0 | ||
| 54 | #define PACKET_MR_PROMISC	1 | ||
| 55 | #define PACKET_MR_ALLMULTI	2 | ||
| 56 | #define PACKET_MR_UNICAST	3 | ||
| 57 | |||
| 58 | #ifdef __cplusplus | ||
| 59 | } | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #endif | ||
lib/libc/include/wasm-wasi-musl/nl_types.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #ifndef _NL_TYPES_H | ||
| 2 | #define _NL_TYPES_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define NL_SETD 1 | ||
| 9 | #define NL_CAT_LOCALE 1 | ||
| 10 | |||
| 11 | typedef int nl_item; | ||
| 12 | typedef void *nl_catd; | ||
| 13 | |||
| 14 | nl_catd catopen (const char *, int); | ||
| 15 | char *catgets (nl_catd, int, int, const char *); | ||
| 16 | int catclose (nl_catd); | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/include/wasm-wasi-musl/poll.h created+69| ... | @@ -0,0 +1,69 @@ | ||
| 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 | #ifdef _GNU_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 | #ifdef _GNU_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/regex.h created+62| ... | @@ -0,0 +1,62 @@ | ||
| 1 | #ifndef _REGEX_H | ||
| 2 | #define _REGEX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_regoff_t | ||
| 11 | #define __NEED_size_t | ||
| 12 | |||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | typedef struct re_pattern_buffer { | ||
| 16 | 	size_t re_nsub; | ||
| 17 | 	void *__opaque, *__padding[4]; | ||
| 18 | 	size_t __nsub2; | ||
| 19 | 	char __padding2; | ||
| 20 | } regex_t; | ||
| 21 | |||
| 22 | typedef struct { | ||
| 23 | 	regoff_t rm_so; | ||
| 24 | 	regoff_t rm_eo; | ||
| 25 | } regmatch_t; | ||
| 26 | |||
| 27 | #define REG_EXTENDED 1 | ||
| 28 | #define REG_ICASE 2 | ||
| 29 | #define REG_NEWLINE 4 | ||
| 30 | #define REG_NOSUB 8 | ||
| 31 | |||
| 32 | #define REG_NOTBOL 1 | ||
| 33 | #define REG_NOTEOL 2 | ||
| 34 | |||
| 35 | #define REG_OK 0 | ||
| 36 | #define REG_NOMATCH 1 | ||
| 37 | #define REG_BADPAT 2 | ||
| 38 | #define REG_ECOLLATE 3 | ||
| 39 | #define REG_ECTYPE 4 | ||
| 40 | #define REG_EESCAPE 5 | ||
| 41 | #define REG_ESUBREG 6 | ||
| 42 | #define REG_EBRACK 7 | ||
| 43 | #define REG_EPAREN 8 | ||
| 44 | #define REG_EBRACE 9 | ||
| 45 | #define REG_BADBR 10 | ||
| 46 | #define REG_ERANGE 11 | ||
| 47 | #define REG_ESPACE 12 | ||
| 48 | #define REG_BADRPT 13 | ||
| 49 | |||
| 50 | #define REG_ENOSYS -1 | ||
| 51 | |||
| 52 | int regcomp(regex_t *__restrict, const char *__restrict, int); | ||
| 53 | int regexec(const regex_t *__restrict, const char *__restrict, size_t, regmatch_t *__restrict, int); | ||
| 54 | void regfree(regex_t *); | ||
| 55 | |||
| 56 | size_t regerror(int, const regex_t *__restrict, char *__restrict, size_t); | ||
| 57 | |||
| 58 | #ifdef __cplusplus | ||
| 59 | } | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #endif | ||
lib/libc/include/wasm-wasi-musl/sched.h created+152| ... | @@ -0,0 +1,152 @@ | ||
| 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 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 20 | struct sched_param { | ||
| 21 | 	int sched_priority; | ||
| 22 | 	int __reserved1; | ||
| 23 | #if _REDIR_TIME64 | ||
| 24 | 	long __reserved2[4]; | ||
| 25 | #else | ||
| 26 | 	struct { | ||
| 27 | 		time_t __reserved1; | ||
| 28 | 		long __reserved2; | ||
| 29 | 	} __reserved2[2]; | ||
| 30 | #endif | ||
| 31 | 	int __reserved3; | ||
| 32 | }; | ||
| 33 | |||
| 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 128 | ||
| 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/search.h created+63| ... | @@ -0,0 +1,63 @@ | ||
| 1 | #ifndef _SEARCH_H | ||
| 2 | #define _SEARCH_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | typedef enum { FIND, ENTER } ACTION; | ||
| 14 | typedef enum { preorder, postorder, endorder, leaf } VISIT; | ||
| 15 | |||
| 16 | typedef struct entry { | ||
| 17 | 	char *key; | ||
| 18 | 	void *data; | ||
| 19 | } ENTRY; | ||
| 20 | |||
| 21 | int hcreate(size_t); | ||
| 22 | void hdestroy(void); | ||
| 23 | ENTRY *hsearch(ENTRY, ACTION); | ||
| 24 | |||
| 25 | #ifdef _GNU_SOURCE | ||
| 26 | struct hsearch_data { | ||
| 27 | 	struct __tab *__tab; | ||
| 28 | 	unsigned int __unused1; | ||
| 29 | 	unsigned int __unused2; | ||
| 30 | }; | ||
| 31 | |||
| 32 | int hcreate_r(size_t, struct hsearch_data *); | ||
| 33 | void hdestroy_r(struct hsearch_data *); | ||
| 34 | int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); | ||
| 35 | #endif | ||
| 36 | |||
| 37 | void insque(void *, void *); | ||
| 38 | void remque(void *); | ||
| 39 | |||
| 40 | void *lsearch(const void *, void *, size_t *, size_t, | ||
| 41 | 	int (*)(const void *, const void *)); | ||
| 42 | void *lfind(const void *, const void *, size_t *, size_t, | ||
| 43 | 	int (*)(const void *, const void *)); | ||
| 44 | |||
| 45 | void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *)); | ||
| 46 | void *tfind(const void *, void *const *, int(*)(const void *, const void *)); | ||
| 47 | void *tsearch(const void *, void **, int (*)(const void *, const void *)); | ||
| 48 | void twalk(const void *, void (*)(const void *, VISIT, int)); | ||
| 49 | |||
| 50 | #ifdef _GNU_SOURCE | ||
| 51 | struct qelem { | ||
| 52 | 	struct qelem *q_forw, *q_back; | ||
| 53 | 	char q_data[1]; | ||
| 54 | }; | ||
| 55 | |||
| 56 | void tdestroy(void *, void (*)(void *)); | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #ifdef __cplusplus | ||
| 60 | } | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #endif | ||
lib/libc/include/wasm-wasi-musl/semaphore.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef _SEMAPHORE_H | ||
| 2 | #define _SEMAPHORE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_time_t | ||
| 10 | #define __NEED_struct_timespec | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | #include <fcntl.h> | ||
| 14 | |||
| 15 | #define SEM_FAILED ((sem_t *)0) | ||
| 16 | |||
| 17 | typedef struct { | ||
| 18 | 	volatile int __val[4*sizeof(long)/sizeof(int)]; | ||
| 19 | } sem_t; | ||
| 20 | |||
| 21 | int sem_close(sem_t *); | ||
| 22 | int sem_destroy(sem_t *); | ||
| 23 | int sem_getvalue(sem_t *__restrict, int *__restrict); | ||
| 24 | int sem_init(sem_t *, int, unsigned); | ||
| 25 | sem_t *sem_open(const char *, int, ...); | ||
| 26 | int sem_post(sem_t *); | ||
| 27 | int sem_timedwait(sem_t *__restrict, const struct timespec *__restrict); | ||
| 28 | int sem_trywait(sem_t *); | ||
| 29 | int sem_unlink(const char *); | ||
| 30 | int sem_wait(sem_t *); | ||
| 31 | |||
| 32 | #if _REDIR_TIME64 | ||
| 33 | __REDIR(sem_timedwait, __sem_timedwait_time64); | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #ifdef __cplusplus | ||
| 37 | } | ||
| 38 | #endif | ||
| 39 | #endif | ||
lib/libc/include/wasm-wasi-musl/signal.h created+331| ... | @@ -0,0 +1,331 @@ | ||
| 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 | |||
| 86 | #define BUS_ADRALN 1 | ||
| 87 | #define BUS_ADRERR 2 | ||
| 88 | #define BUS_OBJERR 3 | ||
| 89 | #define BUS_MCEERR_AR 4 | ||
| 90 | #define BUS_MCEERR_AO 5 | ||
| 91 | |||
| 92 | #define CLD_EXITED 1 | ||
| 93 | #define CLD_KILLED 2 | ||
| 94 | #define CLD_DUMPED 3 | ||
| 95 | #define CLD_TRAPPED 4 | ||
| 96 | #define CLD_STOPPED 5 | ||
| 97 | #define CLD_CONTINUED 6 | ||
| 98 | |||
| 99 | union sigval { | ||
| 100 | 	int sival_int; | ||
| 101 | 	void *sival_ptr; | ||
| 102 | }; | ||
| 103 | |||
| 104 | typedef struct { | ||
| 105 | #ifdef __SI_SWAP_ERRNO_CODE | ||
| 106 | 	int si_signo, si_code, si_errno; | ||
| 107 | #else | ||
| 108 | 	int si_signo, si_errno, si_code; | ||
| 109 | #endif | ||
| 110 | 	union { | ||
| 111 | 		char __pad[128 - 2*sizeof(int) - sizeof(long)]; | ||
| 112 | 		struct { | ||
| 113 | 			union { | ||
| 114 | 				struct { | ||
| 115 | 					pid_t si_pid; | ||
| 116 | 					uid_t si_uid; | ||
| 117 | 				} __piduid; | ||
| 118 | 				struct { | ||
| 119 | 					int si_timerid; | ||
| 120 | 					int si_overrun; | ||
| 121 | 				} __timer; | ||
| 122 | 			} __first; | ||
| 123 | 			union { | ||
| 124 | 				union sigval si_value; | ||
| 125 | 				struct { | ||
| 126 | 					int si_status; | ||
| 127 | 					clock_t si_utime, si_stime; | ||
| 128 | 				} __sigchld; | ||
| 129 | 			} __second; | ||
| 130 | 		} __si_common; | ||
| 131 | 		struct { | ||
| 132 | 			void *si_addr; | ||
| 133 | 			short si_addr_lsb; | ||
| 134 | 			union { | ||
| 135 | 				struct { | ||
| 136 | 					void *si_lower; | ||
| 137 | 					void *si_upper; | ||
| 138 | 				} __addr_bnd; | ||
| 139 | 				unsigned si_pkey; | ||
| 140 | 			} __first; | ||
| 141 | 		} __sigfault; | ||
| 142 | 		struct { | ||
| 143 | 			long si_band; | ||
| 144 | 			int si_fd; | ||
| 145 | 		} __sigpoll; | ||
| 146 | 		struct { | ||
| 147 | 			void *si_call_addr; | ||
| 148 | 			int si_syscall; | ||
| 149 | 			unsigned si_arch; | ||
| 150 | 		} __sigsys; | ||
| 151 | 	} __si_fields; | ||
| 152 | } siginfo_t; | ||
| 153 | #define si_pid __si_fields.__si_common.__first.__piduid.si_pid | ||
| 154 | #define si_uid __si_fields.__si_common.__first.__piduid.si_uid | ||
| 155 | #define si_status __si_fields.__si_common.__second.__sigchld.si_status | ||
| 156 | #define si_utime __si_fields.__si_common.__second.__sigchld.si_utime | ||
| 157 | #define si_stime __si_fields.__si_common.__second.__sigchld.si_stime | ||
| 158 | #define si_value __si_fields.__si_common.__second.si_value | ||
| 159 | #define si_addr __si_fields.__sigfault.si_addr | ||
| 160 | #define si_addr_lsb __si_fields.__sigfault.si_addr_lsb | ||
| 161 | #define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower | ||
| 162 | #define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper | ||
| 163 | #define si_pkey __si_fields.__sigfault.__first.si_pkey | ||
| 164 | #define si_band __si_fields.__sigpoll.si_band | ||
| 165 | #define si_fd __si_fields.__sigpoll.si_fd | ||
| 166 | #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid | ||
| 167 | #define si_overrun __si_fields.__si_common.__first.__timer.si_overrun | ||
| 168 | #define si_ptr si_value.sival_ptr | ||
| 169 | #define si_int si_value.sival_int | ||
| 170 | #define si_call_addr __si_fields.__sigsys.si_call_addr | ||
| 171 | #define si_syscall __si_fields.__sigsys.si_syscall | ||
| 172 | #define si_arch __si_fields.__sigsys.si_arch | ||
| 173 | |||
| 174 | struct sigaction { | ||
| 175 | 	union { | ||
| 176 | 		void (*sa_handler)(int); | ||
| 177 | 		void (*sa_sigaction)(int, siginfo_t *, void *); | ||
| 178 | 	} __sa_handler; | ||
| 179 | 	sigset_t sa_mask; | ||
| 180 | 	int sa_flags; | ||
| 181 | 	void (*sa_restorer)(void); | ||
| 182 | }; | ||
| 183 | #define sa_handler __sa_handler.sa_handler | ||
| 184 | #define sa_sigaction __sa_handler.sa_sigaction | ||
| 185 | |||
| 186 | struct sigevent { | ||
| 187 | 	union sigval sigev_value; | ||
| 188 | 	int sigev_signo; | ||
| 189 | 	int sigev_notify; | ||
| 190 | 	union { | ||
| 191 | 		char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; | ||
| 192 | 		pid_t sigev_notify_thread_id; | ||
| 193 | 		struct { | ||
| 194 | 			void (*sigev_notify_function)(union sigval); | ||
| 195 | 			pthread_attr_t *sigev_notify_attributes; | ||
| 196 | 		} __sev_thread; | ||
| 197 | 	} __sev_fields; | ||
| 198 | }; | ||
| 199 | |||
| 200 | #define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id | ||
| 201 | #define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function | ||
| 202 | #define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes | ||
| 203 | |||
| 204 | #define SIGEV_SIGNAL 0 | ||
| 205 | #define SIGEV_NONE 1 | ||
| 206 | #define SIGEV_THREAD 2 | ||
| 207 | #define SIGEV_THREAD_ID 4 | ||
| 208 | #endif | ||
| 209 | |||
| 210 | #ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ | ||
| 211 | int __libc_current_sigrtmin(void); | ||
| 212 | int __libc_current_sigrtmax(void); | ||
| 213 | |||
| 214 | #define SIGRTMIN (__libc_current_sigrtmin()) | ||
| 215 | #define SIGRTMAX (__libc_current_sigrtmax()) | ||
| 216 | #endif | ||
| 217 | |||
| 218 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 219 | int kill(pid_t, int); | ||
| 220 | |||
| 221 | int sigemptyset(sigset_t *); | ||
| 222 | int sigfillset(sigset_t *); | ||
| 223 | int sigaddset(sigset_t *, int); | ||
| 224 | int sigdelset(sigset_t *, int); | ||
| 225 | int sigismember(const sigset_t *, int); | ||
| 226 | |||
| 227 | int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 228 | int sigsuspend(const sigset_t *); | ||
| 229 | int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); | ||
| 230 | int sigpending(sigset_t *); | ||
| 231 | int sigwait(const sigset_t *__restrict, int *__restrict); | ||
| 232 | int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); | ||
| 233 | int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); | ||
| 234 | int sigqueue(pid_t, int, union sigval); | ||
| 235 | #endif | ||
| 236 | |||
| 237 | #ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ | ||
| 238 | int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 239 | int pthread_kill(pthread_t, int); | ||
| 240 | #endif | ||
| 241 | |||
| 242 | #ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ | ||
| 243 | void psiginfo(const siginfo_t *, const char *); | ||
| 244 | #endif | ||
| 245 | void psignal(int, const char *); | ||
| 246 | |||
| 247 | #endif | ||
| 248 | |||
| 249 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 250 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 251 | int killpg(pid_t, int); | ||
| 252 | int sigaltstack(const stack_t *__restrict, stack_t *__restrict); | ||
| 253 | int sighold(int); | ||
| 254 | int sigignore(int); | ||
| 255 | int siginterrupt(int, int); | ||
| 256 | int sigpause(int); | ||
| 257 | int sigrelse(int); | ||
| 258 | void (*sigset(int, void (*)(int)))(int); | ||
| 259 | #define TRAP_BRKPT 1 | ||
| 260 | #define TRAP_TRACE 2 | ||
| 261 | #define TRAP_BRANCH 3 | ||
| 262 | #define TRAP_HWBKPT 4 | ||
| 263 | #define TRAP_UNK 5 | ||
| 264 | #define POLL_IN 1 | ||
| 265 | #define POLL_OUT 2 | ||
| 266 | #define POLL_MSG 3 | ||
| 267 | #define POLL_ERR 4 | ||
| 268 | #define POLL_PRI 5 | ||
| 269 | #define POLL_HUP 6 | ||
| 270 | #define SS_ONSTACK 1 | ||
| 271 | #define SS_DISABLE 2 | ||
| 272 | #define SS_AUTODISARM (1U << 31) | ||
| 273 | #define SS_FLAG_BITS SS_AUTODISARM | ||
| 274 | #endif | ||
| 275 | #endif | ||
| 276 | |||
| 277 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 278 | #define NSIG _NSIG | ||
| 279 | typedef void (*sig_t)(int); | ||
| 280 | #endif | ||
| 281 | |||
| 282 | #ifdef _GNU_SOURCE | ||
| 283 | typedef void (*sighandler_t)(int); | ||
| 284 | void (*bsd_signal(int, void (*)(int)))(int); | ||
| 285 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ | ||
| 286 | int sigisemptyset(const sigset_t *); | ||
| 287 | int sigorset (sigset_t *, const sigset_t *, const sigset_t *); | ||
| 288 | int sigandset(sigset_t *, const sigset_t *, const sigset_t *); | ||
| 289 | |||
| 290 | #define SA_NOMASK SA_NODEFER | ||
| 291 | #define SA_ONESHOT SA_RESETHAND | ||
| 292 | #endif | ||
| 293 | #endif | ||
| 294 | |||
| 295 | #ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ | ||
| 296 | #define SIG_ERR ((void (*)(int))-1) | ||
| 297 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 298 | #define SIG_IGN ((void (*)(int)) 1) | ||
| 299 | #else | ||
| 300 | void __SIG_ERR(int); | ||
| 301 | void __SIG_IGN(int); | ||
| 302 | #define SIG_ERR (__SIG_ERR) | ||
| 303 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 304 | #define SIG_IGN (__SIG_IGN) | ||
| 305 | #endif | ||
| 306 | |||
| 307 | #ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ | ||
| 308 | typedef int sig_atomic_t; | ||
| 309 | #else | ||
| 310 | typedef long sig_atomic_t; | ||
| 311 | #endif | ||
| 312 | |||
| 313 | void (*signal(int, void (*)(int)))(int); | ||
| 314 | int raise(int); | ||
| 315 | |||
| 316 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ | ||
| 317 | #if _REDIR_TIME64 | ||
| 318 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 319 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 320 | || defined(_BSD_SOURCE) | ||
| 321 | __REDIR(sigtimedwait, __sigtimedwait_time64); | ||
| 322 | #endif | ||
| 323 | #endif | ||
| 324 | #endif | ||
| 325 | |||
| 326 | #ifdef __cplusplus | ||
| 327 | } | ||
| 328 | #endif | ||
| 329 | |||
| 330 | #endif | ||
| 331 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdalign.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _STDALIGN_H | ||
| 2 | #define _STDALIGN_H | ||
| 3 | |||
| 4 | #ifndef __cplusplus | ||
| 5 | |||
| 6 | /* this whole header only works in C11 or with compiler extensions */ | ||
| 7 | #if __STDC_VERSION__ < 201112L && defined( __GNUC__) | ||
| 8 | #define _Alignas(t) __attribute__((__aligned__(t))) | ||
| 9 | #define _Alignof(t) __alignof__(t) | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #define alignas _Alignas | ||
| 13 | #define alignof _Alignof | ||
| 14 | |||
| 15 | #endif | ||
| 16 | |||
| 17 | #define __alignas_is_defined 1 | ||
| 18 | #define __alignof_is_defined 1 | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdbool.h created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #ifndef _STDBOOL_H | ||
| 2 | #define _STDBOOL_H | ||
| 3 | |||
| 4 | #ifndef __cplusplus | ||
| 5 | |||
| 6 | #define true 1 | ||
| 7 | #define false 0 | ||
| 8 | #define bool _Bool | ||
| 9 | |||
| 10 | #endif | ||
| 11 | |||
| 12 | #define __bool_true_false_are_defined 1 | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdc-predef.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #ifndef _STDC_PREDEF_H | ||
| 2 | #define _STDC_PREDEF_H | ||
| 3 | |||
| 4 | #define __STDC_ISO_10646__ 201206L | ||
| 5 | |||
| 6 | #if !defined(__GCC_IEC_559) || __GCC_IEC_559 > 0 | ||
| 7 | #define __STDC_IEC_559__ 1 | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdint.h created+117| ... | @@ -0,0 +1,117 @@ | ||
| 1 | #ifndef _STDINT_H | ||
| 2 | #define _STDINT_H | ||
| 3 | |||
| 4 | #define __NEED_int8_t | ||
| 5 | #define __NEED_int16_t | ||
| 6 | #define __NEED_int32_t | ||
| 7 | #define __NEED_int64_t | ||
| 8 | |||
| 9 | #define __NEED_uint8_t | ||
| 10 | #define __NEED_uint16_t | ||
| 11 | #define __NEED_uint32_t | ||
| 12 | #define __NEED_uint64_t | ||
| 13 | |||
| 14 | #define __NEED_intptr_t | ||
| 15 | #define __NEED_uintptr_t | ||
| 16 | |||
| 17 | #define __NEED_intmax_t | ||
| 18 | #define __NEED_uintmax_t | ||
| 19 | |||
| 20 | #include <bits/alltypes.h> | ||
| 21 | |||
| 22 | typedef int8_t int_fast8_t; | ||
| 23 | typedef int64_t int_fast64_t; | ||
| 24 | |||
| 25 | typedef int8_t int_least8_t; | ||
| 26 | typedef int16_t int_least16_t; | ||
| 27 | typedef int32_t int_least32_t; | ||
| 28 | typedef int64_t int_least64_t; | ||
| 29 | |||
| 30 | typedef uint8_t uint_fast8_t; | ||
| 31 | typedef uint64_t uint_fast64_t; | ||
| 32 | |||
| 33 | typedef uint8_t uint_least8_t; | ||
| 34 | typedef uint16_t uint_least16_t; | ||
| 35 | typedef uint32_t uint_least32_t; | ||
| 36 | typedef uint64_t uint_least64_t; | ||
| 37 | |||
| 38 | #define INT8_MIN (-1-0x7f) | ||
| 39 | #define INT16_MIN (-1-0x7fff) | ||
| 40 | #define INT32_MIN (-1-0x7fffffff) | ||
| 41 | #define INT64_MIN (-1-0x7fffffffffffffff) | ||
| 42 | |||
| 43 | #define INT8_MAX (0x7f) | ||
| 44 | #define INT16_MAX (0x7fff) | ||
| 45 | #define INT32_MAX (0x7fffffff) | ||
| 46 | #define INT64_MAX (0x7fffffffffffffff) | ||
| 47 | |||
| 48 | #define UINT8_MAX (0xff) | ||
| 49 | #define UINT16_MAX (0xffff) | ||
| 50 | #define UINT32_MAX (0xffffffffu) | ||
| 51 | #define UINT64_MAX (0xffffffffffffffffu) | ||
| 52 | |||
| 53 | #define INT_FAST8_MIN INT8_MIN | ||
| 54 | #define INT_FAST64_MIN INT64_MIN | ||
| 55 | |||
| 56 | #define INT_LEAST8_MIN INT8_MIN | ||
| 57 | #define INT_LEAST16_MIN INT16_MIN | ||
| 58 | #define INT_LEAST32_MIN INT32_MIN | ||
| 59 | #define INT_LEAST64_MIN INT64_MIN | ||
| 60 | |||
| 61 | #define INT_FAST8_MAX INT8_MAX | ||
| 62 | #define INT_FAST64_MAX INT64_MAX | ||
| 63 | |||
| 64 | #define INT_LEAST8_MAX INT8_MAX | ||
| 65 | #define INT_LEAST16_MAX INT16_MAX | ||
| 66 | #define INT_LEAST32_MAX INT32_MAX | ||
| 67 | #define INT_LEAST64_MAX INT64_MAX | ||
| 68 | |||
| 69 | #define UINT_FAST8_MAX UINT8_MAX | ||
| 70 | #define UINT_FAST64_MAX UINT64_MAX | ||
| 71 | |||
| 72 | #define UINT_LEAST8_MAX UINT8_MAX | ||
| 73 | #define UINT_LEAST16_MAX UINT16_MAX | ||
| 74 | #define UINT_LEAST32_MAX UINT32_MAX | ||
| 75 | #define UINT_LEAST64_MAX UINT64_MAX | ||
| 76 | |||
| 77 | #define INTMAX_MIN INT64_MIN | ||
| 78 | #define INTMAX_MAX INT64_MAX | ||
| 79 | #define UINTMAX_MAX UINT64_MAX | ||
| 80 | |||
| 81 | #define WINT_MIN 0U | ||
| 82 | #define WINT_MAX UINT32_MAX | ||
| 83 | |||
| 84 | #if L'\0'-1 > 0 | ||
| 85 | #define WCHAR_MAX (0xffffffffu+L'\0') | ||
| 86 | #define WCHAR_MIN (0+L'\0') | ||
| 87 | #else | ||
| 88 | #define WCHAR_MAX (0x7fffffff+L'\0') | ||
| 89 | #define WCHAR_MIN (-1-0x7fffffff+L'\0') | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #define SIG_ATOMIC_MIN INT32_MIN | ||
| 93 | #define SIG_ATOMIC_MAX INT32_MAX | ||
| 94 | |||
| 95 | #include <bits/stdint.h> | ||
| 96 | |||
| 97 | #define INT8_C(c) c | ||
| 98 | #define INT16_C(c) c | ||
| 99 | #define INT32_C(c) c | ||
| 100 | |||
| 101 | #define UINT8_C(c) c | ||
| 102 | #define UINT16_C(c) c | ||
| 103 | #define UINT32_C(c) c ## U | ||
| 104 | |||
| 105 | #if UINTPTR_MAX == UINT64_MAX | ||
| 106 | #define INT64_C(c) c ## L | ||
| 107 | #define UINT64_C(c) c ## UL | ||
| 108 | #define INTMAX_C(c) c ## L | ||
| 109 | #define UINTMAX_C(c) c ## UL | ||
| 110 | #else | ||
| 111 | #define INT64_C(c) c ## LL | ||
| 112 | #define UINT64_C(c) c ## ULL | ||
| 113 | #define INTMAX_C(c) c ## LL | ||
| 114 | #define UINTMAX_C(c) c ## ULL | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdio.h created+252| ... | @@ -0,0 +1,252 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 32 | #define NULL 0L | ||
| 33 | #else | ||
| 34 | #define NULL ((void*)0) | ||
| 35 | #endif | ||
| 36 | #else | ||
| 37 | #define __need_NULL | ||
| 38 | #include <stddef.h> | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #undef EOF | ||
| 42 | #define EOF (-1) | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 45 | #undef SEEK_SET | ||
| 46 | #undef SEEK_CUR | ||
| 47 | #undef SEEK_END | ||
| 48 | #define SEEK_SET 0 | ||
| 49 | #define SEEK_CUR 1 | ||
| 50 | #define SEEK_END 2 | ||
| 51 | #else | ||
| 52 | #include <__seek.h> | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #define _IOFBF 0 | ||
| 56 | #define _IOLBF 1 | ||
| 57 | #define _IONBF 2 | ||
| 58 | |||
| 59 | #define BUFSIZ 1024 | ||
| 60 | #define FILENAME_MAX 4096 | ||
| 61 | #define FOPEN_MAX 1000 | ||
| 62 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 63 | #define TMP_MAX 10000 | ||
| 64 | #define L_tmpnam 20 | ||
| 65 | #endif | ||
| 66 | |||
| 67 | typedef union _G_fpos64_t { | ||
| 68 | 	char __opaque[16]; | ||
| 69 | 	long long __lldata; | ||
| 70 | 	double __align; | ||
| 71 | } fpos_t; | ||
| 72 | |||
| 73 | extern FILE *const stdin; | ||
| 74 | extern FILE *const stdout; | ||
| 75 | extern FILE *const stderr; | ||
| 76 | |||
| 77 | #define stdin (stdin) | ||
| 78 | #define stdout (stdout) | ||
| 79 | #define stderr (stderr) | ||
| 80 | |||
| 81 | FILE *fopen(const char *__restrict, const char *__restrict); | ||
| 82 | FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); | ||
| 83 | int fclose(FILE *); | ||
| 84 | |||
| 85 | int remove(const char *); | ||
| 86 | int rename(const char *, const char *); | ||
| 87 | |||
| 88 | int feof(FILE *); | ||
| 89 | int ferror(FILE *); | ||
| 90 | int fflush(FILE *); | ||
| 91 | void clearerr(FILE *); | ||
| 92 | |||
| 93 | int fseek(FILE *, long, int); | ||
| 94 | long ftell(FILE *); | ||
| 95 | void rewind(FILE *); | ||
| 96 | |||
| 97 | int fgetpos(FILE *__restrict, fpos_t *__restrict); | ||
| 98 | int fsetpos(FILE *, const fpos_t *); | ||
| 99 | |||
| 100 | size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 101 | size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 102 | |||
| 103 | int fgetc(FILE *); | ||
| 104 | int getc(FILE *); | ||
| 105 | int getchar(void); | ||
| 106 | int ungetc(int, FILE *); | ||
| 107 | |||
| 108 | int fputc(int, FILE *); | ||
| 109 | int putc(int, FILE *); | ||
| 110 | int putchar(int); | ||
| 111 | |||
| 112 | char *fgets(char *__restrict, int, FILE *__restrict); | ||
| 113 | #if __STDC_VERSION__ < 201112L | ||
| 114 | #ifdef __wasilibc_unmodified_upstream /* gets is obsolete */ | ||
| 115 | char *gets(char *); | ||
| 116 | #else | ||
| 117 | char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI"))); | ||
| 118 | #endif | ||
| 119 | #endif | ||
| 120 | |||
| 121 | int fputs(const char *__restrict, FILE *__restrict); | ||
| 122 | int puts(const char *); | ||
| 123 | |||
| 124 | int printf(const char *__restrict, ...); | ||
| 125 | int fprintf(FILE *__restrict, const char *__restrict, ...); | ||
| 126 | int sprintf(char *__restrict, const char *__restrict, ...); | ||
| 127 | int snprintf(char *__restrict, size_t, const char *__restrict, ...); | ||
| 128 | |||
| 129 | int vprintf(const char *__restrict, __isoc_va_list); | ||
| 130 | int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 131 | int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 132 | int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); | ||
| 133 | |||
| 134 | int scanf(const char *__restrict, ...); | ||
| 135 | int fscanf(FILE *__restrict, const char *__restrict, ...); | ||
| 136 | int sscanf(const char *__restrict, const char *__restrict, ...); | ||
| 137 | int vscanf(const char *__restrict, __isoc_va_list); | ||
| 138 | int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 139 | int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 140 | |||
| 141 | void perror(const char *); | ||
| 142 | |||
| 143 | int setvbuf(FILE *__restrict, char *__restrict, int, size_t); | ||
| 144 | void setbuf(FILE *__restrict, char *__restrict); | ||
| 145 | |||
| 146 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 147 | char *tmpnam(char *); | ||
| 148 | FILE *tmpfile(void); | ||
| 149 | #else | ||
| 150 | char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI"))); | ||
| 151 | FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI"))); | ||
| 152 | #endif | ||
| 153 | |||
| 154 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 155 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 156 | || defined(_BSD_SOURCE) | ||
| 157 | FILE *fmemopen(void *__restrict, size_t, const char *__restrict); | ||
| 158 | FILE *open_memstream(char **, size_t *); | ||
| 159 | FILE *fdopen(int, const char *); | ||
| 160 | #ifdef __wasilibc_unmodified_upstream /* WASI has no popen */ | ||
| 161 | FILE *popen(const char *, const char *); | ||
| 162 | int pclose(FILE *); | ||
| 163 | #endif | ||
| 164 | int fileno(FILE *); | ||
| 165 | int fseeko(FILE *, off_t, int); | ||
| 166 | off_t ftello(FILE *); | ||
| 167 | int dprintf(int, const char *__restrict, ...); | ||
| 168 | int vdprintf(int, const char *__restrict, __isoc_va_list); | ||
| 169 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 170 | void flockfile(FILE *); | ||
| 171 | int ftrylockfile(FILE *); | ||
| 172 | void funlockfile(FILE *); | ||
| 173 | #endif | ||
| 174 | int getc_unlocked(FILE *); | ||
| 175 | int getchar_unlocked(void); | ||
| 176 | int putc_unlocked(int, FILE *); | ||
| 177 | int putchar_unlocked(int); | ||
| 178 | ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); | ||
| 179 | ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); | ||
| 180 | int renameat(int, const char *, int, const char *); | ||
| 181 | char *ctermid(char *); | ||
| 182 | #define L_ctermid 20 | ||
| 183 | #endif | ||
| 184 | |||
| 185 | |||
| 186 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 187 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 188 | || defined(_BSD_SOURCE) | ||
| 189 | #define P_tmpdir "/tmp" | ||
| 190 | char *tempnam(const char *, const char *); | ||
| 191 | #endif | ||
| 192 | #endif | ||
| 193 | |||
| 194 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 195 | #define L_cuserid 20 | ||
| 196 | char *cuserid(char *); | ||
| 197 | void setlinebuf(FILE *); | ||
| 198 | void setbuffer(FILE *, char *, size_t); | ||
| 199 | int fgetc_unlocked(FILE *); | ||
| 200 | int fputc_unlocked(int, FILE *); | ||
| 201 | int fflush_unlocked(FILE *); | ||
| 202 | size_t fread_unlocked(void *, size_t, size_t, FILE *); | ||
| 203 | size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); | ||
| 204 | void clearerr_unlocked(FILE *); | ||
| 205 | int feof_unlocked(FILE *); | ||
| 206 | int ferror_unlocked(FILE *); | ||
| 207 | int fileno_unlocked(FILE *); | ||
| 208 | int getw(FILE *); | ||
| 209 | int putw(int, FILE *); | ||
| 210 | char *fgetln(FILE *, size_t *); | ||
| 211 | int asprintf(char **, const char *, ...); | ||
| 212 | int vasprintf(char **, const char *, __isoc_va_list); | ||
| 213 | #endif | ||
| 214 | |||
| 215 | #ifdef _GNU_SOURCE | ||
| 216 | char *fgets_unlocked(char *, int, FILE *); | ||
| 217 | int fputs_unlocked(const char *, FILE *); | ||
| 218 | |||
| 219 | typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); | ||
| 220 | typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); | ||
| 221 | typedef int (cookie_seek_function_t)(void *, off_t *, int); | ||
| 222 | typedef int (cookie_close_function_t)(void *); | ||
| 223 | |||
| 224 | typedef struct _IO_cookie_io_functions_t { | ||
| 225 | 	cookie_read_function_t *read; | ||
| 226 | 	cookie_write_function_t *write; | ||
| 227 | 	cookie_seek_function_t *seek; | ||
| 228 | 	cookie_close_function_t *close; | ||
| 229 | } cookie_io_functions_t; | ||
| 230 | |||
| 231 | FILE *fopencookie(void *, const char *, cookie_io_functions_t); | ||
| 232 | #endif | ||
| 233 | |||
| 234 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 235 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 236 | #define tmpfile64 tmpfile | ||
| 237 | #endif | ||
| 238 | #define fopen64 fopen | ||
| 239 | #define freopen64 freopen | ||
| 240 | #define fseeko64 fseeko | ||
| 241 | #define ftello64 ftello | ||
| 242 | #define fgetpos64 fgetpos | ||
| 243 | #define fsetpos64 fsetpos | ||
| 244 | #define fpos64_t fpos_t | ||
| 245 | #define off64_t off_t | ||
| 246 | #endif | ||
| 247 | |||
| 248 | #ifdef __cplusplus | ||
| 249 | } | ||
| 250 | #endif | ||
| 251 | |||
| 252 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdio_ext.h created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #ifndef _STDIO_EXT_H | ||
| 2 | #define _STDIO_EXT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | |||
| 10 | #define FSETLOCKING_QUERY 0 | ||
| 11 | #define FSETLOCKING_INTERNAL 1 | ||
| 12 | #define FSETLOCKING_BYCALLER 2 | ||
| 13 | |||
| 14 | void _flushlbf(void); | ||
| 15 | int __fsetlocking(FILE *, int); | ||
| 16 | int __fwriting(FILE *); | ||
| 17 | int __freading(FILE *); | ||
| 18 | int __freadable(FILE *); | ||
| 19 | int __fwritable(FILE *); | ||
| 20 | int __flbf(FILE *); | ||
| 21 | size_t __fbufsize(FILE *); | ||
| 22 | size_t __fpending(FILE *); | ||
| 23 | int __fpurge(FILE *); | ||
| 24 | |||
| 25 | size_t __freadahead(FILE *); | ||
| 26 | const char *__freadptr(FILE *, size_t *); | ||
| 27 | void __freadptrinc(FILE *, size_t); | ||
| 28 | void __fseterr(FILE *); | ||
| 29 | |||
| 30 | #ifdef __cplusplus | ||
| 31 | } | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdlib.h created+216| ... | @@ -0,0 +1,216 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 17 | #define NULL 0L | ||
| 18 | #else | ||
| 19 | #define NULL ((void*)0) | ||
| 20 | #endif | ||
| 21 | #else | ||
| 22 | #define __need_NULL | ||
| 23 | #include <stddef.h> | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #define __NEED_size_t | ||
| 27 | #define __NEED_wchar_t | ||
| 28 | |||
| 29 | #include <bits/alltypes.h> | ||
| 30 | |||
| 31 | int atoi (const char *); | ||
| 32 | long atol (const char *); | ||
| 33 | long long atoll (const char *); | ||
| 34 | double atof (const char *); | ||
| 35 | |||
| 36 | float strtof (const char *__restrict, char **__restrict); | ||
| 37 | double strtod (const char *__restrict, char **__restrict); | ||
| 38 | long double strtold (const char *__restrict, char **__restrict); | ||
| 39 | |||
| 40 | long strtol (const char *__restrict, char **__restrict, int); | ||
| 41 | unsigned long strtoul (const char *__restrict, char **__restrict, int); | ||
| 42 | long long strtoll (const char *__restrict, char **__restrict, int); | ||
| 43 | unsigned long long strtoull (const char *__restrict, char **__restrict, int); | ||
| 44 | |||
| 45 | int rand (void); | ||
| 46 | void srand (unsigned); | ||
| 47 | |||
| 48 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 49 | void *malloc (size_t); | ||
| 50 | void *calloc (size_t, size_t); | ||
| 51 | void *realloc (void *, size_t); | ||
| 52 | void free (void *); | ||
| 53 | #endif | ||
| 54 | void *aligned_alloc(size_t, size_t); | ||
| 55 | |||
| 56 | _Noreturn void abort (void); | ||
| 57 | int atexit (void (*) (void)); | ||
| 58 | _Noreturn void exit (int); | ||
| 59 | _Noreturn void _Exit (int); | ||
| 60 | int at_quick_exit (void (*) (void)); | ||
| 61 | _Noreturn void quick_exit (int); | ||
| 62 | |||
| 63 | char *getenv (const char *); | ||
| 64 | |||
| 65 | int system (const char *); | ||
| 66 | |||
| 67 | void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 68 | void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 69 | |||
| 70 | int abs (int); | ||
| 71 | long labs (long); | ||
| 72 | long long llabs (long long); | ||
| 73 | |||
| 74 | typedef struct { int quot, rem; } div_t; | ||
| 75 | typedef struct { long quot, rem; } ldiv_t; | ||
| 76 | typedef struct { long long quot, rem; } lldiv_t; | ||
| 77 | |||
| 78 | div_t div (int, int); | ||
| 79 | ldiv_t ldiv (long, long); | ||
| 80 | lldiv_t lldiv (long long, long long); | ||
| 81 | |||
| 82 | int mblen (const char *, size_t); | ||
| 83 | int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 84 | int wctomb (char *, wchar_t); | ||
| 85 | size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 86 | size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); | ||
| 87 | |||
| 88 | #define EXIT_FAILURE 1 | ||
| 89 | #define EXIT_SUCCESS 0 | ||
| 90 | |||
| 91 | size_t __ctype_get_mb_cur_max(void); | ||
| 92 | #define MB_CUR_MAX (__ctype_get_mb_cur_max()) | ||
| 93 | |||
| 94 | #define RAND_MAX (0x7fffffff) | ||
| 95 | |||
| 96 | |||
| 97 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 98 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 99 | || defined(_BSD_SOURCE) | ||
| 100 | |||
| 101 | #ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ | ||
| 102 | #define WNOHANG 1 | ||
| 103 | #define WUNTRACED 2 | ||
| 104 | |||
| 105 | #define WEXITSTATUS(s) (((s) & 0xff00) >> 8) | ||
| 106 | #define WTERMSIG(s) ((s) & 0x7f) | ||
| 107 | #define WSTOPSIG(s) WEXITSTATUS(s) | ||
| 108 | #define WIFEXITED(s) (!WTERMSIG(s)) | ||
| 109 | #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) | ||
| 110 | #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) | ||
| 111 | #endif | ||
| 112 | |||
| 113 | int posix_memalign (void **, size_t, size_t); | ||
| 114 | int setenv (const char *, const char *, int); | ||
| 115 | int unsetenv (const char *); | ||
| 116 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 117 | int mkstemp (char *); | ||
| 118 | int mkostemp (char *, int); | ||
| 119 | char *mkdtemp (char *); | ||
| 120 | #endif | ||
| 121 | int getsubopt (char **, char *const *, char **); | ||
| 122 | int rand_r (unsigned *); | ||
| 123 | |||
| 124 | #endif | ||
| 125 | |||
| 126 | |||
| 127 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 128 | || defined(_BSD_SOURCE) | ||
| 129 | #ifdef __wasilibc_unmodified_upstream /* WASI has no absolute paths */ | ||
| 130 | char *realpath (const char *__restrict, char *__restrict); | ||
| 131 | #endif | ||
| 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 | #endif | ||
| 175 | #endif | ||
| 176 | |||
| 177 | #ifdef _GNU_SOURCE | ||
| 178 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ | ||
| 179 | int ptsname_r(int, char *, size_t); | ||
| 180 | #endif | ||
| 181 | char *ecvt(double, int, int *, int *); | ||
| 182 | char *fcvt(double, int, int *, int *); | ||
| 183 | char *gcvt(double, int, char *); | ||
| 184 | char *secure_getenv(const char *); | ||
| 185 | struct __locale_struct; | ||
| 186 | float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 187 | double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 188 | long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 189 | #endif | ||
| 190 | |||
| 191 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 192 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 193 | #define mkstemp64 mkstemp | ||
| 194 | #define mkostemp64 mkostemp | ||
| 195 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 196 | #define mkstemps64 mkstemps | ||
| 197 | #define mkostemps64 mkostemps | ||
| 198 | #endif | ||
| 199 | #endif | ||
| 200 | #endif | ||
| 201 | |||
| 202 | #ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */ | ||
| 203 | #else | ||
| 204 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 205 | #include <stdint.h> | ||
| 206 | uint32_t arc4random(void); | ||
| 207 | void arc4random_buf(void *, size_t); | ||
| 208 | uint32_t arc4random_uniform(uint32_t); | ||
| 209 | #endif | ||
| 210 | #endif | ||
| 211 | |||
| 212 | #ifdef __cplusplus | ||
| 213 | } | ||
| 214 | #endif | ||
| 215 | |||
| 216 | #endif | ||
lib/libc/include/wasm-wasi-musl/stdnoreturn.h created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #ifndef _STDNORETURN_H | ||
| 2 | #define _STDNORETURN_H | ||
| 3 | #ifndef __cplusplus | ||
| 4 | #include <features.h> | ||
| 5 | #define noreturn _Noreturn | ||
| 6 | #endif | ||
| 7 | #endif | ||
lib/libc/include/wasm-wasi-musl/string.h created+126| ... | @@ -0,0 +1,126 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 16 | #define NULL 0L | ||
| 17 | #else | ||
| 18 | #define NULL ((void*)0) | ||
| 19 | #endif | ||
| 20 | #else | ||
| 21 | #define __need_NULL | ||
| 22 | #include <stddef.h> | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #define __NEED_size_t | ||
| 26 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 27 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 28 | || defined(_BSD_SOURCE) | ||
| 29 | #define __NEED_locale_t | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #include <bits/alltypes.h> | ||
| 33 | |||
| 34 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 35 | void *memcpy (void *__restrict, const void *__restrict, size_t); | ||
| 36 | void *memmove (void *, const void *, size_t); | ||
| 37 | void *memset (void *, int, size_t); | ||
| 38 | #endif | ||
| 39 | int memcmp (const void *, const void *, size_t); | ||
| 40 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 41 | void *memchr (const void *, int, size_t); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | char *strcpy (char *__restrict, const char *__restrict); | ||
| 45 | char *strncpy (char *__restrict, const char *__restrict, size_t); | ||
| 46 | |||
| 47 | char *strcat (char *__restrict, const char *__restrict); | ||
| 48 | char *strncat (char *__restrict, const char *__restrict, size_t); | ||
| 49 | |||
| 50 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 51 | int strcmp (const char *, const char *); | ||
| 52 | #endif | ||
| 53 | int strncmp (const char *, const char *, size_t); | ||
| 54 | |||
| 55 | int strcoll (const char *, const char *); | ||
| 56 | size_t strxfrm (char *__restrict, const char *__restrict, size_t); | ||
| 57 | |||
| 58 | char *strchr (const char *, int); | ||
| 59 | char *strrchr (const char *, int); | ||
| 60 | |||
| 61 | size_t strcspn (const char *, const char *); | ||
| 62 | size_t strspn (const char *, const char *); | ||
| 63 | char *strpbrk (const char *, const char *); | ||
| 64 | char *strstr (const char *, const char *); | ||
| 65 | char *strtok (char *__restrict, const char *__restrict); | ||
| 66 | |||
| 67 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 68 | size_t strlen (const char *); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | char *strerror (int); | ||
| 72 | |||
| 73 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 74 | #include <strings.h> | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 78 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 79 | || defined(_BSD_SOURCE) | ||
| 80 | char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); | ||
| 81 | int strerror_r (int, char *, size_t); | ||
| 82 | char *stpcpy(char *__restrict, const char *__restrict); | ||
| 83 | char *stpncpy(char *__restrict, const char *__restrict, size_t); | ||
| 84 | size_t strnlen (const char *, size_t); | ||
| 85 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 86 | char *strdup (const char *); | ||
| 87 | #endif | ||
| 88 | char *strndup (const char *, size_t); | ||
| 89 | char *strsignal(int); | ||
| 90 | char *strerror_l (int, locale_t); | ||
| 91 | int strcoll_l (const char *, const char *, locale_t); | ||
| 92 | size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 96 | || defined(_BSD_SOURCE) | ||
| 97 | void *memccpy (void *__restrict, const void *__restrict, int, size_t); | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 101 | char *strsep(char **, const char *); | ||
| 102 | size_t strlcat (char *, const char *, size_t); | ||
| 103 | size_t strlcpy (char *, const char *, size_t); | ||
| 104 | void explicit_bzero (void *, size_t); | ||
| 105 | #endif | ||
| 106 | |||
| 107 | #ifdef _GNU_SOURCE | ||
| 108 | #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x) | ||
| 109 | int strverscmp (const char *, const char *); | ||
| 110 | char *strchrnul(const char *, int); | ||
| 111 | char *strcasestr(const char *, const char *); | ||
| 112 | void *memmem(const void *, size_t, const void *, size_t); | ||
| 113 | void *memrchr(const void *, int, size_t); | ||
| 114 | void *mempcpy(void *, const void *, size_t); | ||
| 115 | #ifdef __wasilibc_unmodified_upstream /* avoid unprototyped decls; use <libgen.h> */ | ||
| 116 | #ifndef __cplusplus | ||
| 117 | char *basename(); | ||
| 118 | #endif | ||
| 119 | #endif | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifdef __cplusplus | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #endif | ||
lib/libc/include/wasm-wasi-musl/strings.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef	_STRINGS_H | ||
| 2 | #define	_STRINGS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_locale_t | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | ||
| 14 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | ||
| 15 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 16 | int bcmp (const void *, const void *, size_t); | ||
| 17 | void bcopy (const void *, void *, size_t); | ||
| 18 | void bzero (void *, size_t); | ||
| 19 | char *index (const char *, int); | ||
| 20 | char *rindex (const char *, int); | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 24 | int ffs (int); | ||
| 25 | int ffsl (long); | ||
| 26 | int ffsll (long long); | ||
| 27 | #endif | ||
| 28 | |||
| 29 | int strcasecmp (const char *, const char *); | ||
| 30 | int strncasecmp (const char *, const char *, size_t); | ||
| 31 | |||
| 32 | int strcasecmp_l (const char *, const char *, locale_t); | ||
| 33 | int strncasecmp_l (const char *, const char *, size_t, locale_t); | ||
| 34 | |||
| 35 | #ifdef __cplusplus | ||
| 36 | } | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/include/wasm-wasi-musl/stropts.h created+139| ... | @@ -0,0 +1,139 @@ | ||
| 1 | #ifndef _STROPTS_H | ||
| 2 | #define _STROPTS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __SID		('S' << 8) | ||
| 9 | |||
| 10 | #define I_NREAD		(__SID | 1) | ||
| 11 | #define I_PUSH		(__SID | 2) | ||
| 12 | #define I_POP		(__SID | 3) | ||
| 13 | #define I_LOOK		(__SID | 4) | ||
| 14 | #define I_FLUSH		(__SID | 5) | ||
| 15 | #define I_SRDOPT	(__SID | 6) | ||
| 16 | #define I_GRDOPT	(__SID | 7) | ||
| 17 | #define I_STR		(__SID | 8) | ||
| 18 | #define I_SETSIG	(__SID | 9) | ||
| 19 | #define I_GETSIG	(__SID |10) | ||
| 20 | #define I_FIND		(__SID |11) | ||
| 21 | #define I_LINK		(__SID |12) | ||
| 22 | #define I_UNLINK	(__SID |13) | ||
| 23 | #define I_PEEK		(__SID |15) | ||
| 24 | #define I_FDINSERT	(__SID |16) | ||
| 25 | #define I_SENDFD	(__SID |17) | ||
| 26 | #define I_RECVFD	(__SID |14) | ||
| 27 | #define I_SWROPT	(__SID |19) | ||
| 28 | #define I_GWROPT	(__SID |20) | ||
| 29 | #define I_LIST		(__SID |21) | ||
| 30 | #define I_PLINK		(__SID |22) | ||
| 31 | #define I_PUNLINK	(__SID |23) | ||
| 32 | #define I_FLUSHBAND	(__SID |28) | ||
| 33 | #define I_CKBAND	(__SID |29) | ||
| 34 | #define I_GETBAND	(__SID |30) | ||
| 35 | #define I_ATMARK	(__SID |31) | ||
| 36 | #define I_SETCLTIME	(__SID |32) | ||
| 37 | #define I_GETCLTIME	(__SID |33) | ||
| 38 | #define I_CANPUT	(__SID |34) | ||
| 39 | |||
| 40 | #define FMNAMESZ	8 | ||
| 41 | |||
| 42 | #define FLUSHR		0x01 | ||
| 43 | #define FLUSHW		0x02 | ||
| 44 | #define FLUSHRW		0x03 | ||
| 45 | #define FLUSHBAND	0x04 | ||
| 46 | |||
| 47 | #define S_INPUT		0x0001 | ||
| 48 | #define S_HIPRI		0x0002 | ||
| 49 | #define S_OUTPUT	0x0004 | ||
| 50 | #define S_MSG		0x0008 | ||
| 51 | #define S_ERROR		0x0010 | ||
| 52 | #define S_HANGUP	0x0020 | ||
| 53 | #define S_RDNORM	0x0040 | ||
| 54 | #define S_WRNORM	S_OUTPUT | ||
| 55 | #define S_RDBAND	0x0080 | ||
| 56 | #define S_WRBAND	0x0100 | ||
| 57 | #define S_BANDURG	0x0200 | ||
| 58 | |||
| 59 | #define RS_HIPRI	0x01 | ||
| 60 | |||
| 61 | #define RNORM		0x0000 | ||
| 62 | #define RMSGD		0x0001 | ||
| 63 | #define RMSGN		0x0002 | ||
| 64 | #define RPROTDAT	0x0004 | ||
| 65 | #define RPROTDIS	0x0008 | ||
| 66 | #define RPROTNORM	0x0010 | ||
| 67 | #define RPROTMASK	0x001C | ||
| 68 | |||
| 69 | #define SNDZERO		0x001 | ||
| 70 | #define SNDPIPE		0x002 | ||
| 71 | |||
| 72 | #define ANYMARK		0x01 | ||
| 73 | #define LASTMARK	0x02 | ||
| 74 | |||
| 75 | #define MUXID_ALL	(-1) | ||
| 76 | |||
| 77 | #define MSG_HIPRI	0x01 | ||
| 78 | #define MSG_ANY		0x02 | ||
| 79 | #define MSG_BAND	0x04 | ||
| 80 | |||
| 81 | #define MORECTL		1 | ||
| 82 | #define MOREDATA	2 | ||
| 83 | |||
| 84 | struct bandinfo { | ||
| 85 | 	unsigned char bi_pri; | ||
| 86 | 	int bi_flag; | ||
| 87 | }; | ||
| 88 | |||
| 89 | struct strbuf { | ||
| 90 | 	int maxlen; | ||
| 91 | 	int len; | ||
| 92 | 	char *buf; | ||
| 93 | }; | ||
| 94 | |||
| 95 | struct strpeek { | ||
| 96 | 	struct strbuf ctlbuf; | ||
| 97 | 	struct strbuf databuf; | ||
| 98 | 	unsigned flags; | ||
| 99 | }; | ||
| 100 | |||
| 101 | struct strfdinsert { | ||
| 102 | 	struct strbuf ctlbuf; | ||
| 103 | 	struct strbuf databuf; | ||
| 104 | 	unsigned flags; | ||
| 105 | 	int fildes; | ||
| 106 | 	int offset; | ||
| 107 | }; | ||
| 108 | |||
| 109 | struct strioctl { | ||
| 110 | 	int ic_cmd; | ||
| 111 | 	int ic_timout; | ||
| 112 | 	int ic_len; | ||
| 113 | 	char *ic_dp; | ||
| 114 | }; | ||
| 115 | |||
| 116 | struct strrecvfd { | ||
| 117 | 	int fd; | ||
| 118 | 	int uid; | ||
| 119 | 	int gid; | ||
| 120 | 	char __fill[8]; | ||
| 121 | }; | ||
| 122 | |||
| 123 | struct str_mlist { | ||
| 124 | 	char l_name[FMNAMESZ + 1]; | ||
| 125 | }; | ||
| 126 | |||
| 127 | struct str_list { | ||
| 128 | 	int sl_nmods; | ||
| 129 | 	struct str_mlist *sl_modlist; | ||
| 130 | }; | ||
| 131 | |||
| 132 | int isastream(int); | ||
| 133 | int ioctl(int, int, ...); | ||
| 134 | |||
| 135 | #ifdef __cplusplus | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/dir.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #define direct dirent | ||
lib/libc/include/wasm-wasi-musl/sys/errno.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/errno.h> to <errno.h> | ||
| 2 | #include <errno.h> | ||
lib/libc/include/wasm-wasi-musl/sys/eventfd.h created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #ifndef _SYS_EVENTFD_H | ||
| 2 | #define _SYS_EVENTFD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | |||
| 11 | typedef uint64_t eventfd_t; | ||
| 12 | |||
| 13 | #define EFD_SEMAPHORE 1 | ||
| 14 | #define EFD_CLOEXEC O_CLOEXEC | ||
| 15 | #define EFD_NONBLOCK O_NONBLOCK | ||
| 16 | |||
| 17 | int eventfd(unsigned int, int); | ||
| 18 | int eventfd_read(int, eventfd_t *); | ||
| 19 | int eventfd_write(int, eventfd_t); | ||
| 20 | |||
| 21 | |||
| 22 | #ifdef __cplusplus | ||
| 23 | } | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #endif /* sys/eventfd.h */ | ||
lib/libc/include/wasm-wasi-musl/sys/fcntl.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> | ||
| 2 | #include <fcntl.h> | ||
lib/libc/include/wasm-wasi-musl/sys/file.h created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #ifndef _SYS_FILE_H | ||
| 2 | #define _SYS_FILE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #define LOCK_SH	1 | ||
| 8 | #define LOCK_EX	2 | ||
| 9 | #define LOCK_NB	4 | ||
| 10 | #define LOCK_UN	8 | ||
| 11 | |||
| 12 | #define L_SET 0 | ||
| 13 | #define L_INCR 1 | ||
| 14 | #define L_XTND 2 | ||
| 15 | |||
| 16 | int flock(int, int); | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/ioctl.h created+124| ... | @@ -0,0 +1,124 @@ | ||
| 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 created+156| ... | @@ -0,0 +1,156 @@ | ||
| 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_64KB (16 << 26) | ||
| 48 | #define MAP_HUGE_512KB (19 << 26) | ||
| 49 | #define MAP_HUGE_1MB (20 << 26) | ||
| 50 | #define MAP_HUGE_2MB (21 << 26) | ||
| 51 | #define MAP_HUGE_8MB (23 << 26) | ||
| 52 | #define MAP_HUGE_16MB (24 << 26) | ||
| 53 | #define MAP_HUGE_32MB (25 << 26) | ||
| 54 | #define MAP_HUGE_256MB (28 << 26) | ||
| 55 | #define MAP_HUGE_512MB (29 << 26) | ||
| 56 | #define MAP_HUGE_1GB (30 << 26) | ||
| 57 | #define MAP_HUGE_2GB (31 << 26) | ||
| 58 | #define MAP_HUGE_16GB (34U << 26) | ||
| 59 | |||
| 60 | #define PROT_NONE 0 | ||
| 61 | #define PROT_READ 1 | ||
| 62 | #define PROT_WRITE 2 | ||
| 63 | #define PROT_EXEC 4 | ||
| 64 | #define PROT_GROWSDOWN 0x01000000 | ||
| 65 | #define PROT_GROWSUP 0x02000000 | ||
| 66 | |||
| 67 | #define MS_ASYNC 1 | ||
| 68 | #define MS_INVALIDATE 2 | ||
| 69 | #define MS_SYNC 4 | ||
| 70 | |||
| 71 | #define MCL_CURRENT 1 | ||
| 72 | #define MCL_FUTURE 2 | ||
| 73 | #define MCL_ONFAULT 4 | ||
| 74 | |||
| 75 | #define POSIX_MADV_NORMAL 0 | ||
| 76 | #define POSIX_MADV_RANDOM 1 | ||
| 77 | #define POSIX_MADV_SEQUENTIAL 2 | ||
| 78 | #define POSIX_MADV_WILLNEED 3 | ||
| 79 | #define POSIX_MADV_DONTNEED 4 | ||
| 80 | |||
| 81 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 82 | #define MADV_NORMAL 0 | ||
| 83 | #define MADV_RANDOM 1 | ||
| 84 | #define MADV_SEQUENTIAL 2 | ||
| 85 | #define MADV_WILLNEED 3 | ||
| 86 | #define MADV_DONTNEED 4 | ||
| 87 | #define MADV_FREE 8 | ||
| 88 | #define MADV_REMOVE 9 | ||
| 89 | #define MADV_DONTFORK 10 | ||
| 90 | #define MADV_DOFORK 11 | ||
| 91 | #define MADV_MERGEABLE 12 | ||
| 92 | #define MADV_UNMERGEABLE 13 | ||
| 93 | #define MADV_HUGEPAGE 14 | ||
| 94 | #define MADV_NOHUGEPAGE 15 | ||
| 95 | #define MADV_DONTDUMP 16 | ||
| 96 | #define MADV_DODUMP 17 | ||
| 97 | #define MADV_WIPEONFORK 18 | ||
| 98 | #define MADV_KEEPONFORK 19 | ||
| 99 | #define MADV_COLD 20 | ||
| 100 | #define MADV_PAGEOUT 21 | ||
| 101 | #define MADV_HWPOISON 100 | ||
| 102 | #define MADV_SOFT_OFFLINE 101 | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifdef _GNU_SOURCE | ||
| 106 | #define MREMAP_MAYMOVE 1 | ||
| 107 | #define MREMAP_FIXED 2 | ||
| 108 | #define MREMAP_DONTUNMAP 4 | ||
| 109 | |||
| 110 | #define MLOCK_ONFAULT 0x01 | ||
| 111 | |||
| 112 | #define MFD_CLOEXEC 0x0001U | ||
| 113 | #define MFD_ALLOW_SEALING 0x0002U | ||
| 114 | #define MFD_HUGETLB 0x0004U | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #include <bits/mman.h> | ||
| 118 | |||
| 119 | void *mmap (void *, size_t, int, int, int, off_t); | ||
| 120 | int munmap (void *, size_t); | ||
| 121 | |||
| 122 | int mprotect (void *, size_t, int); | ||
| 123 | int msync (void *, size_t, int); | ||
| 124 | |||
| 125 | int posix_madvise (void *, size_t, int); | ||
| 126 | |||
| 127 | int mlock (const void *, size_t); | ||
| 128 | int munlock (const void *, size_t); | ||
| 129 | int mlockall (int); | ||
| 130 | int munlockall (void); | ||
| 131 | |||
| 132 | #ifdef _GNU_SOURCE | ||
| 133 | void *mremap (void *, size_t, size_t, int, ...); | ||
| 134 | int remap_file_pages (void *, size_t, int, size_t, int); | ||
| 135 | int memfd_create (const char *, unsigned); | ||
| 136 | int mlock2 (const void *, size_t, unsigned); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 140 | int madvise (void *, size_t, int); | ||
| 141 | int mincore (void *, size_t, unsigned char *); | ||
| 142 | #endif | ||
| 143 | |||
| 144 | int shm_open (const char *, int, mode_t); | ||
| 145 | int shm_unlink (const char *); | ||
| 146 | |||
| 147 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 148 | #define mmap64 mmap | ||
| 149 | #define off64_t off_t | ||
| 150 | #endif | ||
| 151 | |||
| 152 | #ifdef __cplusplus | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | #endif | ||
| 156 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/param.h created+37| ... | @@ -0,0 +1,37 @@ | ||
| 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/poll.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/poll.h> to <poll.h> | ||
| 2 | #include <poll.h> | ||
lib/libc/include/wasm-wasi-musl/sys/random.h created+27| ... | @@ -0,0 +1,27 @@ | ||
| 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/reg.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef _SYS_REG_H | ||
| 2 | #define _SYS_REG_H | ||
| 3 | |||
| 4 | #include <limits.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | |||
| 7 | #include <bits/reg.h> | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/resource.h created+126| ... | @@ -0,0 +1,126 @@ | ||
| 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 created+54| ... | @@ -0,0 +1,54 @@ | ||
| 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/signal.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/signal.h> to <signal.h> | ||
| 2 | #include <signal.h> | ||
lib/libc/include/wasm-wasi-musl/sys/socket.h created+445| ... | @@ -0,0 +1,445 @@ | ||
| 1 | #ifndef	_SYS_SOCKET_H | ||
| 2 | #define	_SYS_SOCKET_H | ||
| 3 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 4 | #else | ||
| 5 | #include <__header_sys_socket.h> | ||
| 6 | #endif | ||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #include <features.h> | ||
| 12 | |||
| 13 | #define __NEED_socklen_t | ||
| 14 | #define __NEED_sa_family_t | ||
| 15 | #define __NEED_size_t | ||
| 16 | #define __NEED_ssize_t | ||
| 17 | #define __NEED_uid_t | ||
| 18 | #define __NEED_pid_t | ||
| 19 | #define __NEED_gid_t | ||
| 20 | #define __NEED_struct_iovec | ||
| 21 | |||
| 22 | #include <bits/alltypes.h> | ||
| 23 | |||
| 24 | #include <bits/socket.h> | ||
| 25 | |||
| 26 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 27 | struct msghdr { | ||
| 28 | 	void *msg_name; | ||
| 29 | 	socklen_t msg_namelen; | ||
| 30 | 	struct iovec *msg_iov; | ||
| 31 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 32 | 	int __pad1; | ||
| 33 | #endif | ||
| 34 | 	int msg_iovlen; | ||
| 35 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 36 | 	int __pad1; | ||
| 37 | #endif | ||
| 38 | 	void *msg_control; | ||
| 39 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 40 | 	int __pad2; | ||
| 41 | #endif | ||
| 42 | 	socklen_t msg_controllen; | ||
| 43 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 44 | 	int __pad2; | ||
| 45 | #endif | ||
| 46 | 	int msg_flags; | ||
| 47 | }; | ||
| 48 | |||
| 49 | struct cmsghdr { | ||
| 50 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 51 | 	int __pad1; | ||
| 52 | #endif | ||
| 53 | 	socklen_t cmsg_len; | ||
| 54 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 55 | 	int __pad1; | ||
| 56 | #endif | ||
| 57 | 	int cmsg_level; | ||
| 58 | 	int cmsg_type; | ||
| 59 | }; | ||
| 60 | #else | ||
| 61 | #include <__struct_msghdr.h> | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #ifdef _GNU_SOURCE | ||
| 65 | struct ucred { | ||
| 66 | 	pid_t pid; | ||
| 67 | 	uid_t uid; | ||
| 68 | 	gid_t gid; | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct mmsghdr { | ||
| 72 | 	struct msghdr msg_hdr; | ||
| 73 | 	unsigned int msg_len; | ||
| 74 | }; | ||
| 75 | |||
| 76 | struct timespec; | ||
| 77 | |||
| 78 | int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); | ||
| 79 | int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); | ||
| 80 | #endif | ||
| 81 | |||
| 82 | struct linger { | ||
| 83 | 	int l_onoff; | ||
| 84 | 	int l_linger; | ||
| 85 | }; | ||
| 86 | |||
| 87 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 88 | #define SHUT_RD 0 | ||
| 89 | #define SHUT_WR 1 | ||
| 90 | #define SHUT_RDWR 2 | ||
| 91 | |||
| 92 | #ifndef SOCK_STREAM | ||
| 93 | #define SOCK_STREAM 1 | ||
| 94 | #define SOCK_DGRAM 2 | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #define SOCK_RAW 3 | ||
| 98 | #define SOCK_RDM 4 | ||
| 99 | #define SOCK_SEQPACKET 5 | ||
| 100 | #define SOCK_DCCP 6 | ||
| 101 | #define SOCK_PACKET 10 | ||
| 102 | |||
| 103 | #ifndef SOCK_CLOEXEC | ||
| 104 | #define SOCK_CLOEXEC 02000000 | ||
| 105 | #define SOCK_NONBLOCK 04000 | ||
| 106 | #endif | ||
| 107 | |||
| 108 | #define PF_UNSPEC 0 | ||
| 109 | #define PF_LOCAL 1 | ||
| 110 | #define PF_UNIX PF_LOCAL | ||
| 111 | #define PF_FILE PF_LOCAL | ||
| 112 | #define PF_INET 2 | ||
| 113 | #define PF_AX25 3 | ||
| 114 | #define PF_IPX 4 | ||
| 115 | #define PF_APPLETALK 5 | ||
| 116 | #define PF_NETROM 6 | ||
| 117 | #define PF_BRIDGE 7 | ||
| 118 | #define PF_ATMPVC 8 | ||
| 119 | #define PF_X25 9 | ||
| 120 | #define PF_INET6 10 | ||
| 121 | #define PF_ROSE 11 | ||
| 122 | #define PF_DECnet 12 | ||
| 123 | #define PF_NETBEUI 13 | ||
| 124 | #define PF_SECURITY 14 | ||
| 125 | #define PF_KEY 15 | ||
| 126 | #define PF_NETLINK 16 | ||
| 127 | #define PF_ROUTE PF_NETLINK | ||
| 128 | #define PF_PACKET 17 | ||
| 129 | #define PF_ASH 18 | ||
| 130 | #define PF_ECONET 19 | ||
| 131 | #define PF_ATMSVC 20 | ||
| 132 | #define PF_RDS 21 | ||
| 133 | #define PF_SNA 22 | ||
| 134 | #define PF_IRDA 23 | ||
| 135 | #define PF_PPPOX 24 | ||
| 136 | #define PF_WANPIPE 25 | ||
| 137 | #define PF_LLC 26 | ||
| 138 | #define PF_IB 27 | ||
| 139 | #define PF_MPLS 28 | ||
| 140 | #define PF_CAN 29 | ||
| 141 | #define PF_TIPC 30 | ||
| 142 | #define PF_BLUETOOTH 31 | ||
| 143 | #define PF_IUCV 32 | ||
| 144 | #define PF_RXRPC 33 | ||
| 145 | #define PF_ISDN 34 | ||
| 146 | #define PF_PHONET 35 | ||
| 147 | #define PF_IEEE802154 36 | ||
| 148 | #define PF_CAIF 37 | ||
| 149 | #define PF_ALG 38 | ||
| 150 | #define PF_NFC 39 | ||
| 151 | #define PF_VSOCK 40 | ||
| 152 | #define PF_KCM 41 | ||
| 153 | #define PF_QIPCRTR 42 | ||
| 154 | #define PF_SMC 43 | ||
| 155 | #define PF_XDP 44 | ||
| 156 | #define PF_MAX 45 | ||
| 157 | |||
| 158 | #define AF_UNSPEC PF_UNSPEC | ||
| 159 | #define AF_LOCAL PF_LOCAL | ||
| 160 | #define AF_UNIX AF_LOCAL | ||
| 161 | #define AF_FILE AF_LOCAL | ||
| 162 | #define AF_INET PF_INET | ||
| 163 | #define AF_AX25 PF_AX25 | ||
| 164 | #define AF_IPX PF_IPX | ||
| 165 | #define AF_APPLETALK PF_APPLETALK | ||
| 166 | #define AF_NETROM PF_NETROM | ||
| 167 | #define AF_BRIDGE PF_BRIDGE | ||
| 168 | #define AF_ATMPVC PF_ATMPVC | ||
| 169 | #define AF_X25 PF_X25 | ||
| 170 | #define AF_INET6 PF_INET6 | ||
| 171 | #define AF_ROSE PF_ROSE | ||
| 172 | #define AF_DECnet PF_DECnet | ||
| 173 | #define AF_NETBEUI PF_NETBEUI | ||
| 174 | #define AF_SECURITY PF_SECURITY | ||
| 175 | #define AF_KEY PF_KEY | ||
| 176 | #define AF_NETLINK PF_NETLINK | ||
| 177 | #define AF_ROUTE PF_ROUTE | ||
| 178 | #define AF_PACKET PF_PACKET | ||
| 179 | #define AF_ASH PF_ASH | ||
| 180 | #define AF_ECONET PF_ECONET | ||
| 181 | #define AF_ATMSVC PF_ATMSVC | ||
| 182 | #define AF_RDS PF_RDS | ||
| 183 | #define AF_SNA PF_SNA | ||
| 184 | #define AF_IRDA PF_IRDA | ||
| 185 | #define AF_PPPOX PF_PPPOX | ||
| 186 | #define AF_WANPIPE PF_WANPIPE | ||
| 187 | #define AF_LLC PF_LLC | ||
| 188 | #define AF_IB PF_IB | ||
| 189 | #define AF_MPLS PF_MPLS | ||
| 190 | #define AF_CAN PF_CAN | ||
| 191 | #define AF_TIPC PF_TIPC | ||
| 192 | #define AF_BLUETOOTH PF_BLUETOOTH | ||
| 193 | #define AF_IUCV PF_IUCV | ||
| 194 | #define AF_RXRPC PF_RXRPC | ||
| 195 | #define AF_ISDN PF_ISDN | ||
| 196 | #define AF_PHONET PF_PHONET | ||
| 197 | #define AF_IEEE802154 PF_IEEE802154 | ||
| 198 | #define AF_CAIF PF_CAIF | ||
| 199 | #define AF_ALG PF_ALG | ||
| 200 | #define AF_NFC PF_NFC | ||
| 201 | #define AF_VSOCK PF_VSOCK | ||
| 202 | #define AF_KCM PF_KCM | ||
| 203 | #define AF_QIPCRTR PF_QIPCRTR | ||
| 204 | #define AF_SMC PF_SMC | ||
| 205 | #define AF_XDP PF_XDP | ||
| 206 | #define AF_MAX PF_MAX | ||
| 207 | |||
| 208 | #ifndef SO_DEBUG | ||
| 209 | #define SO_DEBUG 1 | ||
| 210 | #define SO_REUSEADDR 2 | ||
| 211 | #define SO_TYPE 3 | ||
| 212 | #define SO_ERROR 4 | ||
| 213 | #define SO_DONTROUTE 5 | ||
| 214 | #define SO_BROADCAST 6 | ||
| 215 | #define SO_SNDBUF 7 | ||
| 216 | #define SO_RCVBUF 8 | ||
| 217 | #define SO_KEEPALIVE 9 | ||
| 218 | #define SO_OOBINLINE 10 | ||
| 219 | #define SO_NO_CHECK 11 | ||
| 220 | #define SO_PRIORITY 12 | ||
| 221 | #define SO_LINGER 13 | ||
| 222 | #define SO_BSDCOMPAT 14 | ||
| 223 | #define SO_REUSEPORT 15 | ||
| 224 | #define SO_PASSCRED 16 | ||
| 225 | #define SO_PEERCRED 17 | ||
| 226 | #define SO_RCVLOWAT 18 | ||
| 227 | #define SO_SNDLOWAT 19 | ||
| 228 | #define SO_ACCEPTCONN 30 | ||
| 229 | #define SO_PEERSEC 31 | ||
| 230 | #define SO_SNDBUFFORCE 32 | ||
| 231 | #define SO_RCVBUFFORCE 33 | ||
| 232 | #define SO_PROTOCOL 38 | ||
| 233 | #define SO_DOMAIN 39 | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #ifndef SO_RCVTIMEO | ||
| 237 | #if __LONG_MAX == 0x7fffffff | ||
| 238 | #define SO_RCVTIMEO 66 | ||
| 239 | #define SO_SNDTIMEO 67 | ||
| 240 | #else | ||
| 241 | #define SO_RCVTIMEO 20 | ||
| 242 | #define SO_SNDTIMEO 21 | ||
| 243 | #endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifndef SO_TIMESTAMP | ||
| 247 | #if __LONG_MAX == 0x7fffffff | ||
| 248 | #define SO_TIMESTAMP 63 | ||
| 249 | #define SO_TIMESTAMPNS 64 | ||
| 250 | #define SO_TIMESTAMPING 65 | ||
| 251 | #else | ||
| 252 | #define SO_TIMESTAMP 29 | ||
| 253 | #define SO_TIMESTAMPNS 35 | ||
| 254 | #define SO_TIMESTAMPING 37 | ||
| 255 | #endif | ||
| 256 | #endif | ||
| 257 | |||
| 258 | #define SO_SECURITY_AUTHENTICATION 22 | ||
| 259 | #define SO_SECURITY_ENCRYPTION_TRANSPORT 23 | ||
| 260 | #define SO_SECURITY_ENCRYPTION_NETWORK 24 | ||
| 261 | |||
| 262 | #define SO_BINDTODEVICE 25 | ||
| 263 | |||
| 264 | #define SO_ATTACH_FILTER 26 | ||
| 265 | #define SO_DETACH_FILTER 27 | ||
| 266 | #define SO_GET_FILTER SO_ATTACH_FILTER | ||
| 267 | |||
| 268 | #define SO_PEERNAME 28 | ||
| 269 | #define SCM_TIMESTAMP SO_TIMESTAMP | ||
| 270 | #define SO_PASSSEC 34 | ||
| 271 | #define SCM_TIMESTAMPNS SO_TIMESTAMPNS | ||
| 272 | #define SO_MARK 36 | ||
| 273 | #define SCM_TIMESTAMPING SO_TIMESTAMPING | ||
| 274 | #define SO_RXQ_OVFL 40 | ||
| 275 | #define SO_WIFI_STATUS 41 | ||
| 276 | #define SCM_WIFI_STATUS SO_WIFI_STATUS | ||
| 277 | #define SO_PEEK_OFF 42 | ||
| 278 | #define SO_NOFCS 43 | ||
| 279 | #define SO_LOCK_FILTER 44 | ||
| 280 | #define SO_SELECT_ERR_QUEUE 45 | ||
| 281 | #define SO_BUSY_POLL 46 | ||
| 282 | #define SO_MAX_PACING_RATE 47 | ||
| 283 | #define SO_BPF_EXTENSIONS 48 | ||
| 284 | #define SO_INCOMING_CPU 49 | ||
| 285 | #define SO_ATTACH_BPF 50 | ||
| 286 | #define SO_DETACH_BPF SO_DETACH_FILTER | ||
| 287 | #define SO_ATTACH_REUSEPORT_CBPF 51 | ||
| 288 | #define SO_ATTACH_REUSEPORT_EBPF 52 | ||
| 289 | #define SO_CNX_ADVICE 53 | ||
| 290 | #define SCM_TIMESTAMPING_OPT_STATS 54 | ||
| 291 | #define SO_MEMINFO 55 | ||
| 292 | #define SO_INCOMING_NAPI_ID 56 | ||
| 293 | #define SO_COOKIE 57 | ||
| 294 | #define SCM_TIMESTAMPING_PKTINFO 58 | ||
| 295 | #define SO_PEERGROUPS 59 | ||
| 296 | #define SO_ZEROCOPY 60 | ||
| 297 | #define SO_TXTIME 61 | ||
| 298 | #define SCM_TXTIME SO_TXTIME | ||
| 299 | #define SO_BINDTOIFINDEX 62 | ||
| 300 | #define SO_DETACH_REUSEPORT_BPF 68 | ||
| 301 | |||
| 302 | #ifndef SOL_SOCKET | ||
| 303 | #define SOL_SOCKET 1 | ||
| 304 | #endif | ||
| 305 | |||
| 306 | #define SOL_IP 0 | ||
| 307 | #define SOL_IPV6 41 | ||
| 308 | #define SOL_ICMPV6 58 | ||
| 309 | |||
| 310 | #define SOL_RAW 255 | ||
| 311 | #define SOL_DECNET 261 | ||
| 312 | #define SOL_X25 262 | ||
| 313 | #define SOL_PACKET 263 | ||
| 314 | #define SOL_ATM 264 | ||
| 315 | #define SOL_AAL 265 | ||
| 316 | #define SOL_IRDA 266 | ||
| 317 | #define SOL_NETBEUI 267 | ||
| 318 | #define SOL_LLC 268 | ||
| 319 | #define SOL_DCCP 269 | ||
| 320 | #define SOL_NETLINK 270 | ||
| 321 | #define SOL_TIPC 271 | ||
| 322 | #define SOL_RXRPC 272 | ||
| 323 | #define SOL_PPPOL2TP 273 | ||
| 324 | #define SOL_BLUETOOTH 274 | ||
| 325 | #define SOL_PNPIPE 275 | ||
| 326 | #define SOL_RDS 276 | ||
| 327 | #define SOL_IUCV 277 | ||
| 328 | #define SOL_CAIF 278 | ||
| 329 | #define SOL_ALG 279 | ||
| 330 | #define SOL_NFC 280 | ||
| 331 | #define SOL_KCM 281 | ||
| 332 | #define SOL_TLS 282 | ||
| 333 | #define SOL_XDP 283 | ||
| 334 | |||
| 335 | #define SOMAXCONN 128 | ||
| 336 | |||
| 337 | #define MSG_OOB 0x0001 | ||
| 338 | #define MSG_PEEK 0x0002 | ||
| 339 | #define MSG_DONTROUTE 0x0004 | ||
| 340 | #define MSG_CTRUNC 0x0008 | ||
| 341 | #define MSG_PROXY 0x0010 | ||
| 342 | #define MSG_TRUNC 0x0020 | ||
| 343 | #define MSG_DONTWAIT 0x0040 | ||
| 344 | #define MSG_EOR 0x0080 | ||
| 345 | #define MSG_WAITALL 0x0100 | ||
| 346 | #define MSG_FIN 0x0200 | ||
| 347 | #define MSG_SYN 0x0400 | ||
| 348 | #define MSG_CONFIRM 0x0800 | ||
| 349 | #define MSG_RST 0x1000 | ||
| 350 | #define MSG_ERRQUEUE 0x2000 | ||
| 351 | #define MSG_NOSIGNAL 0x4000 | ||
| 352 | #define MSG_MORE 0x8000 | ||
| 353 | #define MSG_WAITFORONE 0x10000 | ||
| 354 | #define MSG_BATCH 0x40000 | ||
| 355 | #define MSG_ZEROCOPY 0x4000000 | ||
| 356 | #define MSG_FASTOPEN 0x20000000 | ||
| 357 | #define MSG_CMSG_CLOEXEC 0x40000000 | ||
| 358 | |||
| 359 | #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) | ||
| 360 | #define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) | ||
| 361 | #define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) | ||
| 362 | |||
| 363 | #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) | ||
| 364 | #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ | ||
| 365 | 	__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ | ||
| 366 | 	? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) | ||
| 367 | #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) | ||
| 368 | |||
| 369 | #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) | ||
| 370 | #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) | ||
| 371 | #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) | ||
| 372 | |||
| 373 | #define SCM_RIGHTS 0x01 | ||
| 374 | #define SCM_CREDENTIALS 0x02 | ||
| 375 | #endif | ||
| 376 | |||
| 377 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 378 | struct sockaddr { | ||
| 379 | 	sa_family_t sa_family; | ||
| 380 | 	char sa_data[14]; | ||
| 381 | }; | ||
| 382 | #else | ||
| 383 | #include <__struct_sockaddr.h> | ||
| 384 | #endif | ||
| 385 | |||
| 386 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 387 | struct sockaddr_storage { | ||
| 388 | 	sa_family_t ss_family; | ||
| 389 | 	char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; | ||
| 390 | 	unsigned long __ss_align; | ||
| 391 | }; | ||
| 392 | #else | ||
| 393 | #include <__struct_sockaddr_storage.h> | ||
| 394 | #endif | ||
| 395 | |||
| 396 | #ifdef __wasilibc_unmodified_upstream /* WASI has no socket/socketpair */ | ||
| 397 | int socket (int, int, int); | ||
| 398 | int socketpair (int, int, int, int [2]); | ||
| 399 | #endif | ||
| 400 | |||
| 401 | int shutdown (int, int); | ||
| 402 | |||
| 403 | #ifdef __wasilibc_unmodified_upstream /* WASI has no bind/connect/listen/accept */ | ||
| 404 | int bind (int, const struct sockaddr *, socklen_t); | ||
| 405 | int connect (int, const struct sockaddr *, socklen_t); | ||
| 406 | int listen (int, int); | ||
| 407 | int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 408 | int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); | ||
| 409 | #endif | ||
| 410 | |||
| 411 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */ | ||
| 412 | int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 413 | int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 414 | #endif | ||
| 415 | |||
| 416 | ssize_t send (int, const void *, size_t, int); | ||
| 417 | ssize_t recv (int, void *, size_t, int); | ||
| 418 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sendto/recvfrom */ | ||
| 419 | ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); | ||
| 420 | ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 421 | #endif | ||
| 422 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ | ||
| 423 | ssize_t sendmsg (int, const struct msghdr *, int); | ||
| 424 | ssize_t recvmsg (int, struct msghdr *, int); | ||
| 425 | #endif | ||
| 426 | |||
| 427 | int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); | ||
| 428 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setsockopt */ | ||
| 429 | int setsockopt (int, int, int, const void *, socklen_t); | ||
| 430 | #endif | ||
| 431 | |||
| 432 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ | ||
| 433 | int sockatmark (int); | ||
| 434 | #endif | ||
| 435 | |||
| 436 | #if _REDIR_TIME64 | ||
| 437 | #ifdef _GNU_SOURCE | ||
| 438 | __REDIR(recvmmsg, __recvmmsg_time64); | ||
| 439 | #endif | ||
| 440 | #endif | ||
| 441 | |||
| 442 | #ifdef __cplusplus | ||
| 443 | } | ||
| 444 | #endif | ||
| 445 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/stat.h created+143| ... | @@ -0,0 +1,143 @@ | ||
| 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 | #include <bits/alltypes.h> | ||
| 22 | |||
| 23 | #include <bits/stat.h> | ||
| 24 | |||
| 25 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 26 | #define st_atime st_atim.tv_sec | ||
| 27 | #define st_mtime st_mtim.tv_sec | ||
| 28 | #define st_ctime st_ctim.tv_sec | ||
| 29 | |||
| 30 | #define S_IFMT 0170000 | ||
| 31 | |||
| 32 | #define S_IFDIR 0040000 | ||
| 33 | #define S_IFCHR 0020000 | ||
| 34 | #define S_IFBLK 0060000 | ||
| 35 | #define S_IFREG 0100000 | ||
| 36 | #define S_IFIFO 0010000 | ||
| 37 | #define S_IFLNK 0120000 | ||
| 38 | #define S_IFSOCK 0140000 | ||
| 39 | |||
| 40 | #define S_TYPEISMQ(buf) 0 | ||
| 41 | #define S_TYPEISSEM(buf) 0 | ||
| 42 | #define S_TYPEISSHM(buf) 0 | ||
| 43 | #define S_TYPEISTMO(buf) 0 | ||
| 44 | |||
| 45 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | ||
| 46 | #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) | ||
| 47 | #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) | ||
| 48 | #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) | ||
| 49 | #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) | ||
| 50 | #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) | ||
| 51 | #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) | ||
| 52 | |||
| 53 | #ifndef S_IRUSR | ||
| 54 | #define S_ISUID 04000 | ||
| 55 | #define S_ISGID 02000 | ||
| 56 | #define S_ISVTX 01000 | ||
| 57 | #define S_IRUSR 0400 | ||
| 58 | #define S_IWUSR 0200 | ||
| 59 | #define S_IXUSR 0100 | ||
| 60 | #define S_IRWXU 0700 | ||
| 61 | #define S_IRGRP 0040 | ||
| 62 | #define S_IWGRP 0020 | ||
| 63 | #define S_IXGRP 0010 | ||
| 64 | #define S_IRWXG 0070 | ||
| 65 | #define S_IROTH 0004 | ||
| 66 | #define S_IWOTH 0002 | ||
| 67 | #define S_IXOTH 0001 | ||
| 68 | #define S_IRWXO 0007 | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #define UTIME_NOW 0x3fffffff | ||
| 72 | #define UTIME_OMIT 0x3ffffffe | ||
| 73 | #else | ||
| 74 | #include <__header_sys_stat.h> | ||
| 75 | #endif | ||
| 76 | |||
| 77 | int stat(const char *__restrict, struct stat *__restrict); | ||
| 78 | int fstat(int, struct stat *); | ||
| 79 | int lstat(const char *__restrict, struct stat *__restrict); | ||
| 80 | int fstatat(int, const char *__restrict, struct stat *__restrict, int); | ||
| 81 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ | ||
| 82 | int chmod(const char *, mode_t); | ||
| 83 | int fchmod(int, mode_t); | ||
| 84 | int fchmodat(int, const char *, mode_t, int); | ||
| 85 | #endif | ||
| 86 | #ifdef __wasilibc_unmodified_upstream /* WASI has no umask */ | ||
| 87 | mode_t umask(mode_t); | ||
| 88 | #endif | ||
| 89 | int mkdir(const char *, mode_t); | ||
| 90 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 91 | int mkfifo(const char *, mode_t); | ||
| 92 | #endif | ||
| 93 | int mkdirat(int, const char *, mode_t); | ||
| 94 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 95 | int mkfifoat(int, const char *, mode_t); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mknod */ | ||
| 99 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 100 | int mknod(const char *, mode_t, dev_t); | ||
| 101 | int mknodat(int, const char *, mode_t, dev_t); | ||
| 102 | #endif | ||
| 103 | #endif | ||
| 104 | |||
| 105 | int futimens(int, const struct timespec [2]); | ||
| 106 | int utimensat(int, const char *, const struct timespec [2], int); | ||
| 107 | |||
| 108 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 109 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ | ||
| 110 | int lchmod(const char *, mode_t); | ||
| 111 | #endif | ||
| 112 | #define S_IREAD S_IRUSR | ||
| 113 | #define S_IWRITE S_IWUSR | ||
| 114 | #define S_IEXEC S_IXUSR | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 118 | #define stat64 stat | ||
| 119 | #define fstat64 fstat | ||
| 120 | #define lstat64 lstat | ||
| 121 | #define fstatat64 fstatat | ||
| 122 | #define blkcnt64_t blkcnt_t | ||
| 123 | #define fsblkcnt64_t fsblkcnt_t | ||
| 124 | #define fsfilcnt64_t fsfilcnt_t | ||
| 125 | #define ino64_t ino_t | ||
| 126 | #define off64_t off_t | ||
| 127 | #endif | ||
| 128 | |||
| 129 | #if _REDIR_TIME64 | ||
| 130 | __REDIR(stat, __stat_time64); | ||
| 131 | __REDIR(fstat, __fstat_time64); | ||
| 132 | __REDIR(lstat, __lstat_time64); | ||
| 133 | __REDIR(fstatat, __fstatat_time64); | ||
| 134 | __REDIR(futimens, __futimens_time64); | ||
| 135 | __REDIR(utimensat, __utimensat_time64); | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #ifdef __cplusplus | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | #endif | ||
| 142 | |||
| 143 | |||
lib/libc/include/wasm-wasi-musl/sys/stropts.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <stropts.h> | ||
lib/libc/include/wasm-wasi-musl/sys/syscall.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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/sysinfo.h created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #ifndef _SYS_SYSINFO_H | ||
| 2 | #define _SYS_SYSINFO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define SI_LOAD_SHIFT 16 | ||
| 9 | |||
| 10 | struct sysinfo { | ||
| 11 | 	unsigned long uptime; | ||
| 12 | 	unsigned long loads[3]; | ||
| 13 | 	unsigned long totalram; | ||
| 14 | 	unsigned long freeram; | ||
| 15 | 	unsigned long sharedram; | ||
| 16 | 	unsigned long bufferram; | ||
| 17 | 	unsigned long totalswap; | ||
| 18 | 	unsigned long freeswap; | ||
| 19 | 	unsigned short procs, pad; | ||
| 20 | 	unsigned long totalhigh; | ||
| 21 | 	unsigned long freehigh; | ||
| 22 | 	unsigned mem_unit; | ||
| 23 | 	char __reserved[256]; | ||
| 24 | }; | ||
| 25 | |||
| 26 | int sysinfo (struct sysinfo *); | ||
| 27 | int get_nprocs_conf (void); | ||
| 28 | int get_nprocs (void); | ||
| 29 | long get_phys_pages (void); | ||
| 30 | long get_avphys_pages (void); | ||
| 31 | |||
| 32 | #ifdef __cplusplus | ||
| 33 | } | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/time.h created+84| ... | @@ -0,0 +1,84 @@ | ||
| 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 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 27 | int utimes (const char *, const struct timeval [2]); | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 31 | struct timezone { | ||
| 32 | 	int tz_minuteswest; | ||
| 33 | 	int tz_dsttime; | ||
| 34 | }; | ||
| 35 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 36 | int futimes(int, const struct timeval [2]); | ||
| 37 | int futimesat(int, const char *, const struct timeval [2]); | ||
| 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/timeb.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #ifndef _SYS_TIMEB_H | ||
| 2 | #define _SYS_TIMEB_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_time_t | ||
| 10 | |||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | struct timeb { | ||
| 14 | 	time_t time; | ||
| 15 | 	unsigned short millitm; | ||
| 16 | 	short timezone, dstflag; | ||
| 17 | }; | ||
| 18 | |||
| 19 | int ftime(struct timeb *); | ||
| 20 | |||
| 21 | #if _REDIR_TIME64 | ||
| 22 | __REDIR(ftime, __ftime64); | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/times.h created+34| ... | @@ -0,0 +1,34 @@ | ||
| 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/timex.h created+103| ... | @@ -0,0 +1,103 @@ | ||
| 1 | #ifndef _SYS_TIMEX_H | ||
| 2 | #define _SYS_TIMEX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_clockid_t | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #include <sys/time.h> | ||
| 13 | |||
| 14 | struct ntptimeval { | ||
| 15 | 	struct timeval time; | ||
| 16 | 	long maxerror, esterror; | ||
| 17 | }; | ||
| 18 | |||
| 19 | struct timex { | ||
| 20 | 	unsigned modes; | ||
| 21 | 	long offset, freq, maxerror, esterror; | ||
| 22 | 	int status; | ||
| 23 | 	long constant, precision, tolerance; | ||
| 24 | 	struct timeval time; | ||
| 25 | 	long tick, ppsfreq, jitter; | ||
| 26 | 	int shift; | ||
| 27 | 	long stabil, jitcnt, calcnt, errcnt, stbcnt; | ||
| 28 | 	int tai; | ||
| 29 | 	int __padding[11]; | ||
| 30 | }; | ||
| 31 | |||
| 32 | #define ADJ_OFFSET		0x0001 | ||
| 33 | #define ADJ_FREQUENCY		0x0002 | ||
| 34 | #define ADJ_MAXERROR		0x0004 | ||
| 35 | #define ADJ_ESTERROR		0x0008 | ||
| 36 | #define ADJ_STATUS		0x0010 | ||
| 37 | #define ADJ_TIMECONST		0x0020 | ||
| 38 | #define ADJ_TAI			0x0080 | ||
| 39 | #define ADJ_SETOFFSET		0x0100 | ||
| 40 | #define ADJ_MICRO		0x1000 | ||
| 41 | #define ADJ_NANO		0x2000 | ||
| 42 | #define ADJ_TICK		0x4000 | ||
| 43 | #define ADJ_OFFSET_SINGLESHOT	0x8001 | ||
| 44 | #define ADJ_OFFSET_SS_READ	0xa001 | ||
| 45 | |||
| 46 | #define MOD_OFFSET	ADJ_OFFSET | ||
| 47 | #define MOD_FREQUENCY	ADJ_FREQUENCY | ||
| 48 | #define MOD_MAXERROR	ADJ_MAXERROR | ||
| 49 | #define MOD_ESTERROR	ADJ_ESTERROR | ||
| 50 | #define MOD_STATUS	ADJ_STATUS | ||
| 51 | #define MOD_TIMECONST	ADJ_TIMECONST | ||
| 52 | #define MOD_CLKB	ADJ_TICK | ||
| 53 | #define MOD_CLKA	ADJ_OFFSET_SINGLESHOT | ||
| 54 | #define MOD_TAI		ADJ_TAI | ||
| 55 | #define MOD_MICRO	ADJ_MICRO | ||
| 56 | #define MOD_NANO	ADJ_NANO | ||
| 57 | |||
| 58 | #define STA_PLL		0x0001 | ||
| 59 | #define STA_PPSFREQ	0x0002 | ||
| 60 | #define STA_PPSTIME	0x0004 | ||
| 61 | #define STA_FLL		0x0008 | ||
| 62 | |||
| 63 | #define STA_INS		0x0010 | ||
| 64 | #define STA_DEL		0x0020 | ||
| 65 | #define STA_UNSYNC	0x0040 | ||
| 66 | #define STA_FREQHOLD	0x0080 | ||
| 67 | |||
| 68 | #define STA_PPSSIGNAL	0x0100 | ||
| 69 | #define STA_PPSJITTER	0x0200 | ||
| 70 | #define STA_PPSWANDER	0x0400 | ||
| 71 | #define STA_PPSERROR	0x0800 | ||
| 72 | |||
| 73 | #define STA_CLOCKERR	0x1000 | ||
| 74 | #define STA_NANO	0x2000 | ||
| 75 | #define STA_MODE	0x4000 | ||
| 76 | #define STA_CLK		0x8000 | ||
| 77 | |||
| 78 | #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ | ||
| 79 | STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) | ||
| 80 | |||
| 81 | #define TIME_OK		0 | ||
| 82 | #define TIME_INS	1 | ||
| 83 | #define TIME_DEL	2 | ||
| 84 | #define TIME_OOP	3 | ||
| 85 | #define TIME_WAIT	4 | ||
| 86 | #define TIME_ERROR	5 | ||
| 87 | #define TIME_BAD	TIME_ERROR | ||
| 88 | |||
| 89 | #define MAXTC		6 | ||
| 90 | |||
| 91 | int adjtimex(struct timex *); | ||
| 92 | int clock_adjtime(clockid_t, struct timex *); | ||
| 93 | |||
| 94 | #if _REDIR_TIME64 | ||
| 95 | __REDIR(adjtimex, __adjtimex_time64); | ||
| 96 | __REDIR(clock_adjtime, __clock_adjtime64); | ||
| 97 | #endif | ||
| 98 | |||
| 99 | #ifdef __cplusplus | ||
| 100 | } | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/ttydefaults.h created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #ifndef _SYS_TTYDEFAULTS_H | ||
| 2 | #define _SYS_TTYDEFAULTS_H | ||
| 3 | |||
| 4 | #define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY) | ||
| 5 | #define TTYDEF_OFLAG (OPOST | ONLCR | XTABS) | ||
| 6 | #define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) | ||
| 7 | #define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL) | ||
| 8 | #define TTYDEF_SPEED (B9600) | ||
| 9 | #define CTRL(x) ((x)&037) | ||
| 10 | #define CEOF CTRL('d') | ||
| 11 | |||
| 12 | #define CEOL '\0' | ||
| 13 | #define CSTATUS '\0' | ||
| 14 | |||
| 15 | #define CERASE 0177 | ||
| 16 | #define CINTR CTRL('c') | ||
| 17 | #define CKILL CTRL('u') | ||
| 18 | #define CMIN 1 | ||
| 19 | #define CQUIT 034 | ||
| 20 | #define CSUSP CTRL('z') | ||
| 21 | #define CTIME 0 | ||
| 22 | #define CDSUSP CTRL('y') | ||
| 23 | #define CSTART CTRL('q') | ||
| 24 | #define CSTOP CTRL('s') | ||
| 25 | #define CLNEXT CTRL('v') | ||
| 26 | #define CDISCARD CTRL('o') | ||
| 27 | #define CWERASE CTRL('w') | ||
| 28 | #define CREPRINT CTRL('r') | ||
| 29 | #define CEOT CEOF | ||
| 30 | #define CBRK CEOL | ||
| 31 | #define CRPRNT CREPRINT | ||
| 32 | #define CFLUSH CDISCARD | ||
| 33 | |||
| 34 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/types.h created+85| ... | @@ -0,0 +1,85 @@ | ||
| 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 created+48| ... | @@ -0,0 +1,48 @@ | ||
| 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 _GNU_SOURCE | ||
| 40 | ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 41 | ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifdef __cplusplus | ||
| 45 | } | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #endif | ||
lib/libc/include/wasm-wasi-musl/sys/un.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 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/sys/utsname.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef	_SYS_UTSNAME_H | ||
| 2 | #define	_SYS_UTSNAME_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | struct utsname { | ||
| 11 | 	char sysname[65]; | ||
| 12 | 	char nodename[65]; | ||
| 13 | 	char release[65]; | ||
| 14 | 	char version[65]; | ||
| 15 | 	char machine[65]; | ||
| 16 | #ifdef _GNU_SOURCE | ||
| 17 | 	char domainname[65]; | ||
| 18 | #else | ||
| 19 | 	char __domainname[65]; | ||
| 20 | #endif | ||
| 21 | }; | ||
| 22 | |||
| 23 | int uname (struct utsname *); | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/include/wasm-wasi-musl/syscall.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <sys/syscall.h> | ||
lib/libc/include/wasm-wasi-musl/sysexits.h created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #ifndef	_SYSEXITS_H | ||
| 2 | #define _SYSEXITS_H | ||
| 3 | #define EX_OK 0 | ||
| 4 | #define EX__BASE 64 | ||
| 5 | #define EX_USAGE 64 | ||
| 6 | #define EX_DATAERR 65 | ||
| 7 | #define EX_NOINPUT 66 | ||
| 8 | #define EX_NOUSER 67 | ||
| 9 | #define EX_NOHOST 68 | ||
| 10 | #define EX_UNAVAILABLE 69 | ||
| 11 | #define EX_SOFTWARE 70 | ||
| 12 | #define EX_OSERR 71 | ||
| 13 | #define EX_OSFILE 72 | ||
| 14 | #define EX_CANTCREAT 73 | ||
| 15 | #define EX_IOERR 74 | ||
| 16 | #define EX_TEMPFAIL 75 | ||
| 17 | #define EX_PROTOCOL 76 | ||
| 18 | #define EX_NOPERM 77 | ||
| 19 | #define EX_CONFIG 78 | ||
| 20 | #define EX__MAX 78 | ||
| 21 | #endif | ||
lib/libc/include/wasm-wasi-musl/tar.h created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #ifndef	_TAR_H | ||
| 2 | #define	_TAR_H | ||
| 3 | |||
| 4 | #define TSUID 04000 | ||
| 5 | #define TSGID 02000 | ||
| 6 | #define TSVTX 01000 | ||
| 7 | #define TUREAD 00400 | ||
| 8 | #define TUWRITE 00200 | ||
| 9 | #define TUEXEC 00100 | ||
| 10 | #define TGREAD 00040 | ||
| 11 | #define TGWRITE 00020 | ||
| 12 | #define TGEXEC 00010 | ||
| 13 | #define TOREAD 00004 | ||
| 14 | #define TOWRITE 00002 | ||
| 15 | #define TOEXEC 00001 | ||
| 16 | |||
| 17 | #define REGTYPE '0' | ||
| 18 | #define AREGTYPE '\0' | ||
| 19 | #define LNKTYPE '1' | ||
| 20 | #define SYMTYPE '2' | ||
| 21 | #define CHRTYPE '3' | ||
| 22 | #define BLKTYPE '4' | ||
| 23 | #define DIRTYPE '5' | ||
| 24 | #define FIFOTYPE '6' | ||
| 25 | #define CONTTYPE '7' | ||
| 26 | |||
| 27 | #define TMAGIC "ustar" | ||
| 28 | #define TMAGLEN 6 | ||
| 29 | |||
| 30 | #define TVERSION "00" | ||
| 31 | #define TVERSLEN 2 | ||
| 32 | |||
| 33 | #endif | ||
lib/libc/include/wasm-wasi-musl/tgmath.h created+270| ... | @@ -0,0 +1,270 @@ | ||
| 1 | #ifndef _TGMATH_H | ||
| 2 | #define _TGMATH_H | ||
| 3 | |||
| 4 | /* | ||
| 5 | the return types are only correct with gcc (__GNUC__) | ||
| 6 | otherwise they are long double or long double complex | ||
| 7 | |||
| 8 | the long double version of a function is never chosen when | ||
| 9 | sizeof(double) == sizeof(long double) | ||
| 10 | (but the return type is set correctly with gcc) | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <math.h> | ||
| 14 | #include <complex.h> | ||
| 15 | |||
| 16 | #define __IS_FP(x) (sizeof((x)+1ULL) == sizeof((x)+1.0f)) | ||
| 17 | #define __IS_CX(x) (__IS_FP(x) && sizeof(x) == sizeof((x)+I)) | ||
| 18 | #define __IS_REAL(x) (__IS_FP(x) && 2*sizeof(x) == sizeof((x)+I)) | ||
| 19 | |||
| 20 | #define __FLT(x) (__IS_REAL(x) && sizeof(x) == sizeof(float)) | ||
| 21 | #define __LDBL(x) (__IS_REAL(x) && sizeof(x) == sizeof(long double) && sizeof(long double) != sizeof(double)) | ||
| 22 | |||
| 23 | #define __FLTCX(x) (__IS_CX(x) && sizeof(x) == sizeof(float complex)) | ||
| 24 | #define __DBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(double complex)) | ||
| 25 | #define __LDBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(long double complex) && sizeof(long double) != sizeof(double)) | ||
| 26 | |||
| 27 | /* return type */ | ||
| 28 | |||
| 29 | #ifdef __GNUC__ | ||
| 30 | /* | ||
| 31 | the result must be casted to the right type | ||
| 32 | (otherwise the result type is determined by the conversion | ||
| 33 | rules applied to all the function return types so it is long | ||
| 34 | double or long double complex except for integral functions) | ||
| 35 | |||
| 36 | this cannot be done in c99, so the typeof gcc extension is | ||
| 37 | used and that the type of ?: depends on wether an operand is | ||
| 38 | a null pointer constant or not | ||
| 39 | (in c11 _Generic can be used) | ||
| 40 | |||
| 41 | the c arguments below must be integer constant expressions | ||
| 42 | so they can be in null pointer constants | ||
| 43 | (__IS_FP above was carefully chosen this way) | ||
| 44 | */ | ||
| 45 | /* if c then t else void */ | ||
| 46 | #define __type1(c,t) __typeof__(*(0?(t*)0:(void*)!(c))) | ||
| 47 | /* if c then t1 else t2 */ | ||
| 48 | #define __type2(c,t1,t2) __typeof__(*(0?(__type1(c,t1)*)0:(__type1(!(c),t2)*)0)) | ||
| 49 | /* cast to double when x is integral, otherwise use typeof(x) */ | ||
| 50 | #define __RETCAST(x) ( \ | ||
| 51 | 	__type2(__IS_FP(x), __typeof__(x), double)) | ||
| 52 | /* 2 args case, should work for complex types (cpow) */ | ||
| 53 | #define __RETCAST_2(x, y) ( \ | ||
| 54 | 	__type2(__IS_FP(x) && __IS_FP(y), \ | ||
| 55 | 		__typeof__((x)+(y)), \ | ||
| 56 | 		__typeof__((x)+(y)+1.0))) | ||
| 57 | /* 3 args case (fma only) */ | ||
| 58 | #define __RETCAST_3(x, y, z) ( \ | ||
| 59 | 	__type2(__IS_FP(x) && __IS_FP(y) && __IS_FP(z), \ | ||
| 60 | 		__typeof__((x)+(y)+(z)), \ | ||
| 61 | 		__typeof__((x)+(y)+(z)+1.0))) | ||
| 62 | /* drop complex from the type of x */ | ||
| 63 | /* TODO: wrong when sizeof(long double)==sizeof(double) */ | ||
| 64 | #define __RETCAST_REAL(x) ( \ | ||
| 65 | 	__type2(__IS_FP(x) && sizeof((x)+I) == sizeof(float complex), float, \ | ||
| 66 | 	__type2(sizeof((x)+1.0+I) == sizeof(double complex), double, \ | ||
| 67 | 		long double))) | ||
| 68 | /* add complex to the type of x */ | ||
| 69 | #define __RETCAST_CX(x) (__typeof__(__RETCAST(x)0+I)) | ||
| 70 | #else | ||
| 71 | #define __RETCAST(x) | ||
| 72 | #define __RETCAST_2(x, y) | ||
| 73 | #define __RETCAST_3(x, y, z) | ||
| 74 | #define __RETCAST_REAL(x) | ||
| 75 | #define __RETCAST_CX(x) | ||
| 76 | #endif | ||
| 77 | |||
| 78 | /* function selection */ | ||
| 79 | |||
| 80 | #define __tg_real_nocast(fun, x) ( \ | ||
| 81 | 	__FLT(x) ? fun ## f (x) : \ | ||
| 82 | 	__LDBL(x) ? fun ## l (x) : \ | ||
| 83 | 	fun(x) ) | ||
| 84 | |||
| 85 | #define __tg_real(fun, x) (__RETCAST(x)__tg_real_nocast(fun, x)) | ||
| 86 | |||
| 87 | #define __tg_real_2_1(fun, x, y) (__RETCAST(x)( \ | ||
| 88 | 	__FLT(x) ? fun ## f (x, y) : \ | ||
| 89 | 	__LDBL(x) ? fun ## l (x, y) : \ | ||
| 90 | 	fun(x, y) )) | ||
| 91 | |||
| 92 | #define __tg_real_2(fun, x, y) (__RETCAST_2(x, y)( \ | ||
| 93 | 	__FLT(x) && __FLT(y) ? fun ## f (x, y) : \ | ||
| 94 | 	__LDBL((x)+(y)) ? fun ## l (x, y) : \ | ||
| 95 | 	fun(x, y) )) | ||
| 96 | |||
| 97 | #define __tg_complex(fun, x) (__RETCAST_CX(x)( \ | ||
| 98 | 	__FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : \ | ||
| 99 | 	__LDBLCX((x)+I) ? fun ## l (x) : \ | ||
| 100 | 	fun(x) )) | ||
| 101 | |||
| 102 | #define __tg_complex_retreal(fun, x) (__RETCAST_REAL(x)( \ | ||
| 103 | 	__FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : \ | ||
| 104 | 	__LDBLCX((x)+I) ? fun ## l (x) : \ | ||
| 105 | 	fun(x) )) | ||
| 106 | |||
| 107 | #define __tg_real_complex(fun, x) (__RETCAST(x)( \ | ||
| 108 | 	__FLTCX(x) ? c ## fun ## f (x) : \ | ||
| 109 | 	__DBLCX(x) ? c ## fun (x) : \ | ||
| 110 | 	__LDBLCX(x) ? c ## fun ## l (x) : \ | ||
| 111 | 	__FLT(x) ? fun ## f (x) : \ | ||
| 112 | 	__LDBL(x) ? fun ## l (x) : \ | ||
| 113 | 	fun(x) )) | ||
| 114 | |||
| 115 | /* special cases */ | ||
| 116 | |||
| 117 | #define __tg_real_remquo(x, y, z) (__RETCAST_2(x, y)( \ | ||
| 118 | 	__FLT(x) && __FLT(y) ? remquof(x, y, z) : \ | ||
| 119 | 	__LDBL((x)+(y)) ? remquol(x, y, z) : \ | ||
| 120 | 	remquo(x, y, z) )) | ||
| 121 | |||
| 122 | #define __tg_real_fma(x, y, z) (__RETCAST_3(x, y, z)( \ | ||
| 123 | 	__FLT(x) && __FLT(y) && __FLT(z) ? fmaf(x, y, z) : \ | ||
| 124 | 	__LDBL((x)+(y)+(z)) ? fmal(x, y, z) : \ | ||
| 125 | 	fma(x, y, z) )) | ||
| 126 | |||
| 127 | #define __tg_real_complex_pow(x, y) (__RETCAST_2(x, y)( \ | ||
| 128 | 	__FLTCX((x)+(y)) && __IS_FP(x) && __IS_FP(y) ? cpowf(x, y) : \ | ||
| 129 | 	__FLTCX((x)+(y)) ? cpow(x, y) : \ | ||
| 130 | 	__DBLCX((x)+(y)) ? cpow(x, y) : \ | ||
| 131 | 	__LDBLCX((x)+(y)) ? cpowl(x, y) : \ | ||
| 132 | 	__FLT(x) && __FLT(y) ? powf(x, y) : \ | ||
| 133 | 	__LDBL((x)+(y)) ? powl(x, y) : \ | ||
| 134 | 	pow(x, y) )) | ||
| 135 | |||
| 136 | #define __tg_real_complex_fabs(x) (__RETCAST_REAL(x)( \ | ||
| 137 | 	__FLTCX(x) ? cabsf(x) : \ | ||
| 138 | 	__DBLCX(x) ? cabs(x) : \ | ||
| 139 | 	__LDBLCX(x) ? cabsl(x) : \ | ||
| 140 | 	__FLT(x) ? fabsf(x) : \ | ||
| 141 | 	__LDBL(x) ? fabsl(x) : \ | ||
| 142 | 	fabs(x) )) | ||
| 143 | |||
| 144 | /* suppress any macros in math.h or complex.h */ | ||
| 145 | |||
| 146 | #undef acos | ||
| 147 | #undef acosh | ||
| 148 | #undef asin | ||
| 149 | #undef asinh | ||
| 150 | #undef atan | ||
| 151 | #undef atan2 | ||
| 152 | #undef atanh | ||
| 153 | #undef carg | ||
| 154 | #undef cbrt | ||
| 155 | #undef ceil | ||
| 156 | #undef cimag | ||
| 157 | #undef conj | ||
| 158 | #undef copysign | ||
| 159 | #undef cos | ||
| 160 | #undef cosh | ||
| 161 | #undef cproj | ||
| 162 | #undef creal | ||
| 163 | #undef erf | ||
| 164 | #undef erfc | ||
| 165 | #undef exp | ||
| 166 | #undef exp2 | ||
| 167 | #undef expm1 | ||
| 168 | #undef fabs | ||
| 169 | #undef fdim | ||
| 170 | #undef floor | ||
| 171 | #undef fma | ||
| 172 | #undef fmax | ||
| 173 | #undef fmin | ||
| 174 | #undef fmod | ||
| 175 | #undef frexp | ||
| 176 | #undef hypot | ||
| 177 | #undef ilogb | ||
| 178 | #undef ldexp | ||
| 179 | #undef lgamma | ||
| 180 | #undef llrint | ||
| 181 | #undef llround | ||
| 182 | #undef log | ||
| 183 | #undef log10 | ||
| 184 | #undef log1p | ||
| 185 | #undef log2 | ||
| 186 | #undef logb | ||
| 187 | #undef lrint | ||
| 188 | #undef lround | ||
| 189 | #undef nearbyint | ||
| 190 | #undef nextafter | ||
| 191 | #undef nexttoward | ||
| 192 | #undef pow | ||
| 193 | #undef remainder | ||
| 194 | #undef remquo | ||
| 195 | #undef rint | ||
| 196 | #undef round | ||
| 197 | #undef scalbln | ||
| 198 | #undef scalbn | ||
| 199 | #undef sin | ||
| 200 | #undef sinh | ||
| 201 | #undef sqrt | ||
| 202 | #undef tan | ||
| 203 | #undef tanh | ||
| 204 | #undef tgamma | ||
| 205 | #undef trunc | ||
| 206 | |||
| 207 | /* tg functions */ | ||
| 208 | |||
| 209 | #define acos(x) __tg_real_complex(acos, (x)) | ||
| 210 | #define acosh(x) __tg_real_complex(acosh, (x)) | ||
| 211 | #define asin(x) __tg_real_complex(asin, (x)) | ||
| 212 | #define asinh(x) __tg_real_complex(asinh, (x)) | ||
| 213 | #define atan(x) __tg_real_complex(atan, (x)) | ||
| 214 | #define atan2(x,y) __tg_real_2(atan2, (x), (y)) | ||
| 215 | #define atanh(x) __tg_real_complex(atanh, (x)) | ||
| 216 | #define carg(x) __tg_complex_retreal(carg, (x)) | ||
| 217 | #define cbrt(x) __tg_real(cbrt, (x)) | ||
| 218 | #define ceil(x) __tg_real(ceil, (x)) | ||
| 219 | #define cimag(x) __tg_complex_retreal(cimag, (x)) | ||
| 220 | #define conj(x) __tg_complex(conj, (x)) | ||
| 221 | #define copysign(x,y) __tg_real_2(copysign, (x), (y)) | ||
| 222 | #define cos(x) __tg_real_complex(cos, (x)) | ||
| 223 | #define cosh(x) __tg_real_complex(cosh, (x)) | ||
| 224 | #define cproj(x) __tg_complex(cproj, (x)) | ||
| 225 | #define creal(x) __tg_complex_retreal(creal, (x)) | ||
| 226 | #define erf(x) __tg_real(erf, (x)) | ||
| 227 | #define erfc(x) __tg_real(erfc, (x)) | ||
| 228 | #define exp(x) __tg_real_complex(exp, (x)) | ||
| 229 | #define exp2(x) __tg_real(exp2, (x)) | ||
| 230 | #define expm1(x) __tg_real(expm1, (x)) | ||
| 231 | #define fabs(x) __tg_real_complex_fabs(x) | ||
| 232 | #define fdim(x,y) __tg_real_2(fdim, (x), (y)) | ||
| 233 | #define floor(x) __tg_real(floor, (x)) | ||
| 234 | #define fma(x,y,z) __tg_real_fma((x), (y), (z)) | ||
| 235 | #define fmax(x,y) __tg_real_2(fmax, (x), (y)) | ||
| 236 | #define fmin(x,y) __tg_real_2(fmin, (x), (y)) | ||
| 237 | #define fmod(x,y) __tg_real_2(fmod, (x), (y)) | ||
| 238 | #define frexp(x,y) __tg_real_2_1(frexp, (x), (y)) | ||
| 239 | #define hypot(x,y) __tg_real_2(hypot, (x), (y)) | ||
| 240 | #define ilogb(x) __tg_real_nocast(ilogb, (x)) | ||
| 241 | #define ldexp(x,y) __tg_real_2_1(ldexp, (x), (y)) | ||
| 242 | #define lgamma(x) __tg_real(lgamma, (x)) | ||
| 243 | #define llrint(x) __tg_real_nocast(llrint, (x)) | ||
| 244 | #define llround(x) __tg_real_nocast(llround, (x)) | ||
| 245 | #define log(x) __tg_real_complex(log, (x)) | ||
| 246 | #define log10(x) __tg_real(log10, (x)) | ||
| 247 | #define log1p(x) __tg_real(log1p, (x)) | ||
| 248 | #define log2(x) __tg_real(log2, (x)) | ||
| 249 | #define logb(x) __tg_real(logb, (x)) | ||
| 250 | #define lrint(x) __tg_real_nocast(lrint, (x)) | ||
| 251 | #define lround(x) __tg_real_nocast(lround, (x)) | ||
| 252 | #define nearbyint(x) __tg_real(nearbyint, (x)) | ||
| 253 | #define nextafter(x,y) __tg_real_2(nextafter, (x), (y)) | ||
| 254 | #define nexttoward(x,y) __tg_real_2(nexttoward, (x), (y)) | ||
| 255 | #define pow(x,y) __tg_real_complex_pow((x), (y)) | ||
| 256 | #define remainder(x,y) __tg_real_2(remainder, (x), (y)) | ||
| 257 | #define remquo(x,y,z) __tg_real_remquo((x), (y), (z)) | ||
| 258 | #define rint(x) __tg_real(rint, (x)) | ||
| 259 | #define round(x) __tg_real(round, (x)) | ||
| 260 | #define scalbln(x,y) __tg_real_2_1(scalbln, (x), (y)) | ||
| 261 | #define scalbn(x,y) __tg_real_2_1(scalbn, (x), (y)) | ||
| 262 | #define sin(x) __tg_real_complex(sin, (x)) | ||
| 263 | #define sinh(x) __tg_real_complex(sinh, (x)) | ||
| 264 | #define sqrt(x) __tg_real_complex(sqrt, (x)) | ||
| 265 | #define tan(x) __tg_real_complex(tan, (x)) | ||
| 266 | #define tanh(x) __tg_real_complex(tanh, (x)) | ||
| 267 | #define tgamma(x) __tg_real(tgamma, (x)) | ||
| 268 | #define trunc(x) __tg_real(trunc, (x)) | ||
| 269 | |||
| 270 | #endif | ||
lib/libc/include/wasm-wasi-musl/threads.h created+93| ... | @@ -0,0 +1,93 @@ | ||
| 1 | #ifndef _THREADS_H | ||
| 2 | #define _THREADS_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <time.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | typedef unsigned long thrd_t; | ||
| 10 | #else | ||
| 11 | typedef struct __pthread *thrd_t; | ||
| 12 | #define thread_local _Thread_local | ||
| 13 | #endif | ||
| 14 | |||
| 15 | typedef int once_flag; | ||
| 16 | typedef unsigned tss_t; | ||
| 17 | typedef int (*thrd_start_t)(void *); | ||
| 18 | typedef void (*tss_dtor_t)(void *); | ||
| 19 | |||
| 20 | #define __NEED_cnd_t | ||
| 21 | #define __NEED_mtx_t | ||
| 22 | |||
| 23 | #include <bits/alltypes.h> | ||
| 24 | |||
| 25 | #define TSS_DTOR_ITERATIONS 4 | ||
| 26 | |||
| 27 | enum { | ||
| 28 | 	thrd_success = 0, | ||
| 29 | 	thrd_busy = 1, | ||
| 30 | 	thrd_error = 2, | ||
| 31 | 	thrd_nomem = 3, | ||
| 32 | 	thrd_timedout = 4, | ||
| 33 | }; | ||
| 34 | |||
| 35 | enum { | ||
| 36 | 	mtx_plain = 0, | ||
| 37 | 	mtx_recursive = 1, | ||
| 38 | 	mtx_timed = 2, | ||
| 39 | }; | ||
| 40 | |||
| 41 | #define ONCE_FLAG_INIT 0 | ||
| 42 | |||
| 43 | int thrd_create(thrd_t *, thrd_start_t, void *); | ||
| 44 | _Noreturn void thrd_exit(int); | ||
| 45 | |||
| 46 | int thrd_detach(thrd_t); | ||
| 47 | int thrd_join(thrd_t, int *); | ||
| 48 | |||
| 49 | int thrd_sleep(const struct timespec *, struct timespec *); | ||
| 50 | void thrd_yield(void); | ||
| 51 | |||
| 52 | thrd_t thrd_current(void); | ||
| 53 | int thrd_equal(thrd_t, thrd_t); | ||
| 54 | #ifndef __cplusplus | ||
| 55 | #define thrd_equal(A, B) ((A) == (B)) | ||
| 56 | #endif | ||
| 57 | |||
| 58 | void call_once(once_flag *, void (*)(void)); | ||
| 59 | |||
| 60 | int mtx_init(mtx_t *, int); | ||
| 61 | void mtx_destroy(mtx_t *); | ||
| 62 | |||
| 63 | int mtx_lock(mtx_t *); | ||
| 64 | int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); | ||
| 65 | int mtx_trylock(mtx_t *); | ||
| 66 | int mtx_unlock(mtx_t *); | ||
| 67 | |||
| 68 | int cnd_init(cnd_t *); | ||
| 69 | void cnd_destroy(cnd_t *); | ||
| 70 | |||
| 71 | int cnd_broadcast(cnd_t *); | ||
| 72 | int cnd_signal(cnd_t *); | ||
| 73 | |||
| 74 | int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict); | ||
| 75 | int cnd_wait(cnd_t *, mtx_t *); | ||
| 76 | |||
| 77 | int tss_create(tss_t *, tss_dtor_t); | ||
| 78 | void tss_delete(tss_t); | ||
| 79 | |||
| 80 | int tss_set(tss_t, void *); | ||
| 81 | void *tss_get(tss_t); | ||
| 82 | |||
| 83 | #if _REDIR_TIME64 | ||
| 84 | __REDIR(thrd_sleep, __thrd_sleep_time64); | ||
| 85 | __REDIR(mtx_timedlock, __mtx_timedlock_time64); | ||
| 86 | __REDIR(cnd_timedwait, __cnd_timedwait_time64); | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #ifdef __cplusplus | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #endif | ||
lib/libc/include/wasm-wasi-musl/time.h created+202| ... | @@ -0,0 +1,202 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 12 | #define NULL 0L | ||
| 13 | #else | ||
| 14 | #define NULL ((void*)0) | ||
| 15 | #endif | ||
| 16 | #else | ||
| 17 | #define __need_NULL | ||
| 18 | #include <stddef.h> | ||
| 19 | #endif | ||
| 20 | |||
| 21 | |||
| 22 | #define __NEED_size_t | ||
| 23 | #define __NEED_time_t | ||
| 24 | #define __NEED_clock_t | ||
| 25 | #define __NEED_struct_timespec | ||
| 26 | |||
| 27 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 28 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 29 | || defined(_BSD_SOURCE) | ||
| 30 | #define __NEED_clockid_t | ||
| 31 | #define __NEED_timer_t | ||
| 32 | #define __NEED_pid_t | ||
| 33 | #define __NEED_locale_t | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include <bits/alltypes.h> | ||
| 37 | |||
| 38 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 39 | #define __tm_gmtoff tm_gmtoff | ||
| 40 | #define __tm_zone tm_zone | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 44 | struct tm { | ||
| 45 | 	int tm_sec; | ||
| 46 | 	int tm_min; | ||
| 47 | 	int tm_hour; | ||
| 48 | 	int tm_mday; | ||
| 49 | 	int tm_mon; | ||
| 50 | 	int tm_year; | ||
| 51 | 	int tm_wday; | ||
| 52 | 	int tm_yday; | ||
| 53 | 	int tm_isdst; | ||
| 54 | 	long __tm_gmtoff; | ||
| 55 | 	const char *__tm_zone; | ||
| 56 | }; | ||
| 57 | #else | ||
| 58 | #include <__header_time.h> | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) | ||
| 62 | clock_t clock (void); | ||
| 63 | #else | ||
| 64 | __attribute__((__deprecated__( | ||
| 65 | "WASI lacks process-associated clocks; to enable emulation of the `clock` function using " | ||
| 66 | "the wall clock, which isn't sensitive to whether the program is running or suspended, " | ||
| 67 | "compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks" | ||
| 68 | ))) | ||
| 69 | clock_t clock (void); | ||
| 70 | #endif | ||
| 71 | time_t time (time_t *); | ||
| 72 | double difftime (time_t, time_t); | ||
| 73 | time_t mktime (struct tm *); | ||
| 74 | size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); | ||
| 75 | struct tm *gmtime (const time_t *); | ||
| 76 | struct tm *localtime (const time_t *); | ||
| 77 | char *asctime (const struct tm *); | ||
| 78 | char *ctime (const time_t *); | ||
| 79 | int timespec_get(struct timespec *, int); | ||
| 80 | |||
| 81 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 82 | #define CLOCKS_PER_SEC 1000000L | ||
| 83 | |||
| 84 | #define TIME_UTC 1 | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 88 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 89 | || defined(_BSD_SOURCE) | ||
| 90 | |||
| 91 | size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); | ||
| 92 | |||
| 93 | struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 94 | struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 95 | char *asctime_r (const struct tm *__restrict, char *__restrict); | ||
| 96 | char *ctime_r (const time_t *, char *); | ||
| 97 | |||
| 98 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 99 | void tzset (void); | ||
| 100 | #endif | ||
| 101 | |||
| 102 | struct itimerspec { | ||
| 103 | 	struct timespec it_interval; | ||
| 104 | 	struct timespec it_value; | ||
| 105 | }; | ||
| 106 | |||
| 107 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 108 | #define CLOCK_REALTIME 0 | ||
| 109 | #define CLOCK_MONOTONIC 1 | ||
| 110 | #define CLOCK_PROCESS_CPUTIME_ID 2 | ||
| 111 | #define CLOCK_THREAD_CPUTIME_ID 3 | ||
| 112 | #define CLOCK_MONOTONIC_RAW 4 | ||
| 113 | #define CLOCK_REALTIME_COARSE 5 | ||
| 114 | #define CLOCK_MONOTONIC_COARSE 6 | ||
| 115 | #define CLOCK_BOOTTIME 7 | ||
| 116 | #define CLOCK_REALTIME_ALARM 8 | ||
| 117 | #define CLOCK_BOOTTIME_ALARM 9 | ||
| 118 | #define CLOCK_SGI_CYCLE 10 | ||
| 119 | #define CLOCK_TAI 11 | ||
| 120 | |||
| 121 | #define TIMER_ABSTIME 1 | ||
| 122 | #endif | ||
| 123 | |||
| 124 | int nanosleep (const struct timespec *, struct timespec *); | ||
| 125 | int clock_getres (clockid_t, struct timespec *); | ||
| 126 | int clock_gettime (clockid_t, struct timespec *); | ||
| 127 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */ | ||
| 128 | int clock_settime (clockid_t, const struct timespec *); | ||
| 129 | #endif | ||
| 130 | int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); | ||
| 131 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */ | ||
| 132 | int clock_getcpuclockid (pid_t, clockid_t *); | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timers */ | ||
| 136 | struct sigevent; | ||
| 137 | int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); | ||
| 138 | int timer_delete (timer_t); | ||
| 139 | int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); | ||
| 140 | int timer_gettime (timer_t, struct itimerspec *); | ||
| 141 | int timer_getoverrun (timer_t); | ||
| 142 | #endif | ||
| 143 | |||
| 144 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 145 | extern char *tzname[2]; | ||
| 146 | #endif | ||
| 147 | |||
| 148 | #endif | ||
| 149 | |||
| 150 | |||
| 151 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 152 | char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); | ||
| 153 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 154 | extern int daylight; | ||
| 155 | extern long timezone; | ||
| 156 | #endif | ||
| 157 | extern int getdate_err; | ||
| 158 | struct tm *getdate (const char *); | ||
| 159 | #endif | ||
| 160 | |||
| 161 | |||
| 162 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 163 | #ifdef __wasilibc_unmodified_upstream /* WASI has no stime */ | ||
| 164 | int stime(const time_t *); | ||
| 165 | #endif | ||
| 166 | time_t timegm(struct tm *); | ||
| 167 | #endif | ||
| 168 | |||
| 169 | #if _REDIR_TIME64 | ||
| 170 | __REDIR(time, __time64); | ||
| 171 | __REDIR(difftime, __difftime64); | ||
| 172 | __REDIR(mktime, __mktime64); | ||
| 173 | __REDIR(gmtime, __gmtime64); | ||
| 174 | __REDIR(localtime, __localtime64); | ||
| 175 | __REDIR(ctime, __ctime64); | ||
| 176 | __REDIR(timespec_get, __timespec_get_time64); | ||
| 177 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 178 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 179 | || defined(_BSD_SOURCE) | ||
| 180 | __REDIR(gmtime_r, __gmtime64_r); | ||
| 181 | __REDIR(localtime_r, __localtime64_r); | ||
| 182 | __REDIR(ctime_r, __ctime64_r); | ||
| 183 | __REDIR(nanosleep, __nanosleep_time64); | ||
| 184 | __REDIR(clock_getres, __clock_getres_time64); | ||
| 185 | __REDIR(clock_gettime, __clock_gettime64); | ||
| 186 | __REDIR(clock_settime, __clock_settime64); | ||
| 187 | __REDIR(clock_nanosleep, __clock_nanosleep_time64); | ||
| 188 | __REDIR(timer_settime, __timer_settime64); | ||
| 189 | __REDIR(timer_gettime, __timer_gettime64); | ||
| 190 | #endif | ||
| 191 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 192 | __REDIR(stime, __stime64); | ||
| 193 | __REDIR(timegm, __timegm_time64); | ||
| 194 | #endif | ||
| 195 | #endif | ||
| 196 | |||
| 197 | #ifdef __cplusplus | ||
| 198 | } | ||
| 199 | #endif | ||
| 200 | |||
| 201 | |||
| 202 | #endif | ||
lib/libc/include/wasm-wasi-musl/uchar.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef _UCHAR_H | ||
| 2 | #define _UCHAR_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #if __cplusplus < 201103L | ||
| 9 | typedef unsigned short char16_t; | ||
| 10 | typedef unsigned char32_t; | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #define __NEED_mbstate_t | ||
| 14 | #define __NEED_size_t | ||
| 15 | |||
| 16 | #include <features.h> | ||
| 17 | #include <bits/alltypes.h> | ||
| 18 | |||
| 19 | size_t c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict); | ||
| 20 | size_t mbrtoc16(char16_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 21 | |||
| 22 | size_t c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict); | ||
| 23 | size_t mbrtoc32(char32_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/include/wasm-wasi-musl/unistd.h created+571| ... | @@ -0,0 +1,571 @@ | ||
| 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 | #else | ||
| 19 | #include <__header_unistd.h> | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 23 | #ifdef __cplusplus | ||
| 24 | #define NULL 0L | ||
| 25 | #else | ||
| 26 | #define NULL ((void*)0) | ||
| 27 | #endif | ||
| 28 | #else | ||
| 29 | #define __need_NULL | ||
| 30 | #include <stddef.h> | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #define __NEED_size_t | ||
| 34 | #define __NEED_ssize_t | ||
| 35 | #define __NEED_uid_t | ||
| 36 | #define __NEED_gid_t | ||
| 37 | #define __NEED_off_t | ||
| 38 | #define __NEED_pid_t | ||
| 39 | #define __NEED_intptr_t | ||
| 40 | #define __NEED_useconds_t | ||
| 41 | |||
| 42 | #include <bits/alltypes.h> | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pipe */ | ||
| 45 | int pipe(int [2]); | ||
| 46 | int pipe2(int [2], int); | ||
| 47 | #endif | ||
| 48 | int close(int); | ||
| 49 | int posix_close(int, int); | ||
| 50 | #ifdef __wasilibc_unmodified_upstream /* WASI has no dup */ | ||
| 51 | int dup(int); | ||
| 52 | int dup2(int, int); | ||
| 53 | int dup3(int, int, int); | ||
| 54 | #endif | ||
| 55 | off_t lseek(int, off_t, int); | ||
| 56 | #ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */ | ||
| 57 | #else | ||
| 58 | off_t __wasilibc_tell(int); | ||
| 59 | |||
| 60 | #ifndef __cplusplus | ||
| 61 | /* | ||
| 62 | * Optimize lseek in the case where it's just returning the current offset. | ||
| 63 | * This avoids importing `__wasi_fd_seek` altogether in many common cases. | ||
| 64 | * | ||
| 65 | * But don't do this for C++ because a simple macro wouldn't handle namespaces | ||
| 66 | * correctly: | ||
| 67 | * - User code could qualify the `lseek` call with `::`. | ||
| 68 | * - There may be another `lseek` in scope from a `using` declaration. | ||
| 69 | */ | ||
| 70 | #define lseek(fd, offset, whence) \ | ||
| 71 | ({ \ | ||
| 72 | off_t __f = (fd); \ | ||
| 73 | off_t __o = (offset); \ | ||
| 74 | off_t __w = (whence); \ | ||
| 75 | __builtin_constant_p((offset)) && \ | ||
| 76 | __builtin_constant_p((whence)) && \ | ||
| 77 | __o == 0 && \ | ||
| 78 | __w == SEEK_CUR \ | ||
| 79 | ? __wasilibc_tell(__f) \ | ||
| 80 | : lseek(__f, __o, __w); \ | ||
| 81 | }) | ||
| 82 | #endif | ||
| 83 | #endif | ||
| 84 | int fsync(int); | ||
| 85 | int fdatasync(int); | ||
| 86 | |||
| 87 | ssize_t read(int, void *, size_t); | ||
| 88 | ssize_t write(int, const void *, size_t); | ||
| 89 | ssize_t pread(int, void *, size_t, off_t); | ||
| 90 | ssize_t pwrite(int, const void *, size_t, off_t); | ||
| 91 | |||
| 92 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chown */ | ||
| 93 | int chown(const char *, uid_t, gid_t); | ||
| 94 | int fchown(int, uid_t, gid_t); | ||
| 95 | int lchown(const char *, uid_t, gid_t); | ||
| 96 | int fchownat(int, const char *, uid_t, gid_t, int); | ||
| 97 | #endif | ||
| 98 | |||
| 99 | int link(const char *, const char *); | ||
| 100 | int linkat(int, const char *, int, const char *, int); | ||
| 101 | int symlink(const char *, const char *); | ||
| 102 | int symlinkat(const char *, int, const char *); | ||
| 103 | ssize_t readlink(const char *__restrict, char *__restrict, size_t); | ||
| 104 | ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); | ||
| 105 | int unlink(const char *); | ||
| 106 | int unlinkat(int, const char *, int); | ||
| 107 | int rmdir(const char *); | ||
| 108 | int truncate(const char *, off_t); | ||
| 109 | int ftruncate(int, off_t); | ||
| 110 | |||
| 111 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 112 | #define F_OK 0 | ||
| 113 | #define R_OK 4 | ||
| 114 | #define W_OK 2 | ||
| 115 | #define X_OK 1 | ||
| 116 | #endif | ||
| 117 | |||
| 118 | int access(const char *, int); | ||
| 119 | int faccessat(int, const char *, int, int); | ||
| 120 | |||
| 121 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fchdir */ | ||
| 122 | int fchdir(int); | ||
| 123 | #endif | ||
| 124 | int chdir(const char *); | ||
| 125 | char *getcwd(char *, size_t); | ||
| 126 | |||
| 127 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 128 | unsigned alarm(unsigned); | ||
| 129 | #endif | ||
| 130 | unsigned sleep(unsigned); | ||
| 131 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ | ||
| 132 | int pause(void); | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ | ||
| 136 | pid_t fork(void); | ||
| 137 | pid_t _Fork(void); | ||
| 138 | int execve(const char *, char *const [], char *const []); | ||
| 139 | int execv(const char *, char *const []); | ||
| 140 | int execle(const char *, const char *, ...); | ||
| 141 | int execl(const char *, const char *, ...); | ||
| 142 | int execvp(const char *, char *const []); | ||
| 143 | int execlp(const char *, const char *, ...); | ||
| 144 | int fexecve(int, char *const [], char *const []); | ||
| 145 | #endif | ||
| 146 | _Noreturn void _exit(int); | ||
| 147 | |||
| 148 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_GETPID) | ||
| 149 | pid_t getpid(void); | ||
| 150 | #else | ||
| 151 | __attribute__((__deprecated__( | ||
| 152 | "WASI lacks process identifiers; to enable emulation of the `getpid` function using " | ||
| 153 | "a placeholder value, which doesn't reflect the host PID of the program, " | ||
| 154 | "compile with -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid" | ||
| 155 | ))) | ||
| 156 | pid_t getpid(void); | ||
| 157 | #endif | ||
| 158 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getpid etc. */ | ||
| 159 | pid_t getppid(void); | ||
| 160 | pid_t getpgrp(void); | ||
| 161 | pid_t getpgid(pid_t); | ||
| 162 | int setpgid(pid_t, pid_t); | ||
| 163 | pid_t setsid(void); | ||
| 164 | pid_t getsid(pid_t); | ||
| 165 | #endif | ||
| 166 | #ifdef __wasilibc_unmodified_upstream /* WASI has no ttyname */ | ||
| 167 | char *ttyname(int); | ||
| 168 | int ttyname_r(int, char *, size_t); | ||
| 169 | #endif | ||
| 170 | int isatty(int); | ||
| 171 | #ifdef __wasilibc_unmodified_upstream /* WASI has no process groups */ | ||
| 172 | pid_t tcgetpgrp(int); | ||
| 173 | int tcsetpgrp(int, pid_t); | ||
| 174 | #endif | ||
| 175 | |||
| 176 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getuid etc. */ | ||
| 177 | uid_t getuid(void); | ||
| 178 | uid_t geteuid(void); | ||
| 179 | gid_t getgid(void); | ||
| 180 | gid_t getegid(void); | ||
| 181 | int getgroups(int, gid_t []); | ||
| 182 | int setuid(uid_t); | ||
| 183 | int seteuid(uid_t); | ||
| 184 | int setgid(gid_t); | ||
| 185 | int setegid(gid_t); | ||
| 186 | #endif | ||
| 187 | |||
| 188 | char *getlogin(void); | ||
| 189 | int getlogin_r(char *, size_t); | ||
| 190 | int gethostname(char *, size_t); | ||
| 191 | char *ctermid(char *); | ||
| 192 | |||
| 193 | int getopt(int, char * const [], const char *); | ||
| 194 | extern char *optarg; | ||
| 195 | extern int optind, opterr, optopt; | ||
| 196 | |||
| 197 | long pathconf(const char *, int); | ||
| 198 | long fpathconf(int, int); | ||
| 199 | long sysconf(int); | ||
| 200 | size_t confstr(int, char *, size_t); | ||
| 201 | |||
| 202 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 203 | #define F_ULOCK 0 | ||
| 204 | #define F_LOCK 1 | ||
| 205 | #define F_TLOCK 2 | ||
| 206 | #define F_TEST 3 | ||
| 207 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setreuid */ | ||
| 208 | int setreuid(uid_t, uid_t); | ||
| 209 | int setregid(gid_t, gid_t); | ||
| 210 | #endif | ||
| 211 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 212 | int lockf(int, int, off_t); | ||
| 213 | #endif | ||
| 214 | long gethostid(void); | ||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no nice, sync, or setpgrp */ | ||
| 216 | int nice(int); | ||
| 217 | void sync(void); | ||
| 218 | pid_t setpgrp(void); | ||
| 219 | #endif | ||
| 220 | char *crypt(const char *, const char *); | ||
| 221 | void encrypt(char *, int); | ||
| 222 | void swab(const void *__restrict, void *__restrict, ssize_t); | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 226 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 227 | int usleep(unsigned); | ||
| 228 | unsigned ualarm(unsigned, unsigned); | ||
| 229 | #endif | ||
| 230 | |||
| 231 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 232 | #define L_SET 0 | ||
| 233 | #define L_INCR 1 | ||
| 234 | #define L_XTND 2 | ||
| 235 | #ifdef __wasilibc_unmodified_upstream /* WASI has no brk */ | ||
| 236 | int brk(void *); | ||
| 237 | #endif | ||
| 238 | void *sbrk(intptr_t); | ||
| 239 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 240 | pid_t vfork(void); | ||
| 241 | int vhangup(void); | ||
| 242 | int chroot(const char *); | ||
| 243 | int getpagesize(void); | ||
| 244 | int getdtablesize(void); | ||
| 245 | int sethostname(const char *, size_t); | ||
| 246 | int getdomainname(char *, size_t); | ||
| 247 | int setdomainname(const char *, size_t); | ||
| 248 | int setgroups(size_t, const gid_t *); | ||
| 249 | char *getpass(const char *); | ||
| 250 | int daemon(int, int); | ||
| 251 | void setusershell(void); | ||
| 252 | void endusershell(void); | ||
| 253 | char *getusershell(void); | ||
| 254 | int acct(const char *); | ||
| 255 | long syscall(long, ...); | ||
| 256 | int execvpe(const char *, char *const [], char *const []); | ||
| 257 | int issetugid(void); | ||
| 258 | #endif | ||
| 259 | int getentropy(void *, size_t); | ||
| 260 | extern int optreset; | ||
| 261 | #endif | ||
| 262 | |||
| 263 | #ifdef _GNU_SOURCE | ||
| 264 | extern char **environ; | ||
| 265 | #ifdef __wasilibc_unmodified_upstream /* WASI has no get/setresuid */ | ||
| 266 | int setresuid(uid_t, uid_t, uid_t); | ||
| 267 | int setresgid(gid_t, gid_t, gid_t); | ||
| 268 | int getresuid(uid_t *, uid_t *, uid_t *); | ||
| 269 | int getresgid(gid_t *, gid_t *, gid_t *); | ||
| 270 | #endif | ||
| 271 | #ifdef __wasilibc_unmodified_upstream /* WASI has no cwd */ | ||
| 272 | char *get_current_dir_name(void); | ||
| 273 | #endif | ||
| 274 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syncfs */ | ||
| 275 | int syncfs(int); | ||
| 276 | #endif | ||
| 277 | #ifdef __wasilibc_unmodified_upstream /* WASI has no eaccess */ | ||
| 278 | int euidaccess(const char *, int); | ||
| 279 | int eaccess(const char *, int); | ||
| 280 | ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 281 | pid_t gettid(void); | ||
| 282 | #endif | ||
| 283 | #endif | ||
| 284 | |||
| 285 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 286 | #define lseek64 lseek | ||
| 287 | #define pread64 pread | ||
| 288 | #define pwrite64 pwrite | ||
| 289 | #ifdef __wasilibc_unmodified_upstream /* WASI has no truncate */ | ||
| 290 | #define truncate64 truncate | ||
| 291 | #endif | ||
| 292 | #define ftruncate64 ftruncate | ||
| 293 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 294 | #define lockf64 lockf | ||
| 295 | #endif | ||
| 296 | #define off64_t off_t | ||
| 297 | #endif | ||
| 298 | |||
| 299 | #define POSIX_CLOSE_RESTART 0 | ||
| 300 | |||
| 301 | #define _XOPEN_VERSION 700 | ||
| 302 | #define _XOPEN_UNIX 1 | ||
| 303 | #define _XOPEN_ENH_I18N 1 | ||
| 304 | |||
| 305 | #define _POSIX_VERSION 200809L | ||
| 306 | #define _POSIX2_VERSION _POSIX_VERSION | ||
| 307 | |||
| 308 | #define _POSIX_ADVISORY_INFO _POSIX_VERSION | ||
| 309 | #define _POSIX_CHOWN_RESTRICTED 1 | ||
| 310 | #define _POSIX_IPV6 _POSIX_VERSION | ||
| 311 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes, mmap, or mq */ | ||
| 312 | #define _POSIX_JOB_CONTROL 1 | ||
| 313 | #define _POSIX_MAPPED_FILES _POSIX_VERSION | ||
| 314 | #define _POSIX_MEMLOCK _POSIX_VERSION | ||
| 315 | #define _POSIX_MEMLOCK_RANGE _POSIX_VERSION | ||
| 316 | #define _POSIX_MEMORY_PROTECTION _POSIX_VERSION | ||
| 317 | #define _POSIX_MESSAGE_PASSING _POSIX_VERSION | ||
| 318 | #endif | ||
| 319 | #define _POSIX_FSYNC _POSIX_VERSION | ||
| 320 | #define _POSIX_NO_TRUNC 1 | ||
| 321 | #ifdef __wasilibc_unmodified_upstream /* WASI has no raw sockets */ | ||
| 322 | #define _POSIX_RAW_SOCKETS _POSIX_VERSION | ||
| 323 | #endif | ||
| 324 | #define _POSIX_REALTIME_SIGNALS _POSIX_VERSION | ||
| 325 | #define _POSIX_REGEXP 1 | ||
| 326 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 327 | #define _POSIX_SAVED_IDS 1 | ||
| 328 | #define _POSIX_SHELL 1 | ||
| 329 | #define _POSIX_SPAWN _POSIX_VERSION | ||
| 330 | #endif | ||
| 331 | #define _POSIX_VDISABLE 0 | ||
| 332 | |||
| 333 | #define _POSIX_THREADS _POSIX_VERSION | ||
| 334 | #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION | ||
| 335 | #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION | ||
| 336 | #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION | ||
| 337 | #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION | ||
| 338 | #define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION | ||
| 339 | #define _POSIX_THREAD_CPUTIME _POSIX_VERSION | ||
| 340 | #define _POSIX_TIMERS _POSIX_VERSION | ||
| 341 | #define _POSIX_TIMEOUTS _POSIX_VERSION | ||
| 342 | #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION | ||
| 343 | #define _POSIX_CPUTIME _POSIX_VERSION | ||
| 344 | #define _POSIX_CLOCK_SELECTION _POSIX_VERSION | ||
| 345 | #define _POSIX_BARRIERS _POSIX_VERSION | ||
| 346 | #define _POSIX_SPIN_LOCKS _POSIX_VERSION | ||
| 347 | #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION | ||
| 348 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX async I/O, semaphores, or shared memory */ | ||
| 349 | #define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION | ||
| 350 | #define _POSIX_SEMAPHORES _POSIX_VERSION | ||
| 351 | #define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION | ||
| 352 | #endif | ||
| 353 | |||
| 354 | #define _POSIX2_C_BIND _POSIX_VERSION | ||
| 355 | |||
| 356 | #include <bits/posix.h> | ||
| 357 | |||
| 358 | |||
| 359 | |||
| 360 | #define _PC_LINK_MAX	0 | ||
| 361 | #define _PC_MAX_CANON	1 | ||
| 362 | #define _PC_MAX_INPUT	2 | ||
| 363 | #define _PC_NAME_MAX	3 | ||
| 364 | #define _PC_PATH_MAX	4 | ||
| 365 | #define _PC_PIPE_BUF	5 | ||
| 366 | #define _PC_CHOWN_RESTRICTED	6 | ||
| 367 | #define _PC_NO_TRUNC	7 | ||
| 368 | #define _PC_VDISABLE	8 | ||
| 369 | #define _PC_SYNC_IO	9 | ||
| 370 | #define _PC_ASYNC_IO	10 | ||
| 371 | #define _PC_PRIO_IO	11 | ||
| 372 | #define _PC_SOCK_MAXBUF	12 | ||
| 373 | #define _PC_FILESIZEBITS	13 | ||
| 374 | #define _PC_REC_INCR_XFER_SIZE	14 | ||
| 375 | #define _PC_REC_MAX_XFER_SIZE	15 | ||
| 376 | #define _PC_REC_MIN_XFER_SIZE	16 | ||
| 377 | #define _PC_REC_XFER_ALIGN	17 | ||
| 378 | #define _PC_ALLOC_SIZE_MIN	18 | ||
| 379 | #define _PC_SYMLINK_MAX	19 | ||
| 380 | #define _PC_2_SYMLINKS	20 | ||
| 381 | |||
| 382 | #define _SC_ARG_MAX	0 | ||
| 383 | #define _SC_CHILD_MAX	1 | ||
| 384 | #define _SC_CLK_TCK	2 | ||
| 385 | #define _SC_NGROUPS_MAX	3 | ||
| 386 | #define _SC_OPEN_MAX	4 | ||
| 387 | #define _SC_STREAM_MAX	5 | ||
| 388 | #define _SC_TZNAME_MAX	6 | ||
| 389 | #define _SC_JOB_CONTROL	7 | ||
| 390 | #define _SC_SAVED_IDS	8 | ||
| 391 | #define _SC_REALTIME_SIGNALS	9 | ||
| 392 | #define _SC_PRIORITY_SCHEDULING	10 | ||
| 393 | #define _SC_TIMERS	11 | ||
| 394 | #define _SC_ASYNCHRONOUS_IO	12 | ||
| 395 | #define _SC_PRIORITIZED_IO	13 | ||
| 396 | #define _SC_SYNCHRONIZED_IO	14 | ||
| 397 | #define _SC_FSYNC	15 | ||
| 398 | #define _SC_MAPPED_FILES	16 | ||
| 399 | #define _SC_MEMLOCK	17 | ||
| 400 | #define _SC_MEMLOCK_RANGE	18 | ||
| 401 | #define _SC_MEMORY_PROTECTION	19 | ||
| 402 | #define _SC_MESSAGE_PASSING	20 | ||
| 403 | #define _SC_SEMAPHORES	21 | ||
| 404 | #define _SC_SHARED_MEMORY_OBJECTS	22 | ||
| 405 | #define _SC_AIO_LISTIO_MAX	23 | ||
| 406 | #define _SC_AIO_MAX	24 | ||
| 407 | #define _SC_AIO_PRIO_DELTA_MAX	25 | ||
| 408 | #define _SC_DELAYTIMER_MAX	26 | ||
| 409 | #define _SC_MQ_OPEN_MAX	27 | ||
| 410 | #define _SC_MQ_PRIO_MAX	28 | ||
| 411 | #define _SC_VERSION	29 | ||
| 412 | #define _SC_PAGE_SIZE	30 | ||
| 413 | #define _SC_PAGESIZE	30 /* !! */ | ||
| 414 | #define _SC_RTSIG_MAX	31 | ||
| 415 | #define _SC_SEM_NSEMS_MAX	32 | ||
| 416 | #define _SC_SEM_VALUE_MAX	33 | ||
| 417 | #define _SC_SIGQUEUE_MAX	34 | ||
| 418 | #define _SC_TIMER_MAX	35 | ||
| 419 | #define _SC_BC_BASE_MAX	36 | ||
| 420 | #define _SC_BC_DIM_MAX	37 | ||
| 421 | #define _SC_BC_SCALE_MAX	38 | ||
| 422 | #define _SC_BC_STRING_MAX	39 | ||
| 423 | #define _SC_COLL_WEIGHTS_MAX	40 | ||
| 424 | #define _SC_EXPR_NEST_MAX	42 | ||
| 425 | #define _SC_LINE_MAX	43 | ||
| 426 | #define _SC_RE_DUP_MAX	44 | ||
| 427 | #define _SC_2_VERSION	46 | ||
| 428 | #define _SC_2_C_BIND	47 | ||
| 429 | #define _SC_2_C_DEV	48 | ||
| 430 | #define _SC_2_FORT_DEV	49 | ||
| 431 | #define _SC_2_FORT_RUN	50 | ||
| 432 | #define _SC_2_SW_DEV	51 | ||
| 433 | #define _SC_2_LOCALEDEF	52 | ||
| 434 | #define _SC_UIO_MAXIOV	60 /* !! */ | ||
| 435 | #define _SC_IOV_MAX	60 | ||
| 436 | #define _SC_THREADS	67 | ||
| 437 | #define _SC_THREAD_SAFE_FUNCTIONS	68 | ||
| 438 | #define _SC_GETGR_R_SIZE_MAX	69 | ||
| 439 | #define _SC_GETPW_R_SIZE_MAX	70 | ||
| 440 | #define _SC_LOGIN_NAME_MAX	71 | ||
| 441 | #define _SC_TTY_NAME_MAX	72 | ||
| 442 | #define _SC_THREAD_DESTRUCTOR_ITERATIONS	73 | ||
| 443 | #define _SC_THREAD_KEYS_MAX	74 | ||
| 444 | #define _SC_THREAD_STACK_MIN	75 | ||
| 445 | #define _SC_THREAD_THREADS_MAX	76 | ||
| 446 | #define _SC_THREAD_ATTR_STACKADDR	77 | ||
| 447 | #define _SC_THREAD_ATTR_STACKSIZE	78 | ||
| 448 | #define _SC_THREAD_PRIORITY_SCHEDULING	79 | ||
| 449 | #define _SC_THREAD_PRIO_INHERIT	80 | ||
| 450 | #define _SC_THREAD_PRIO_PROTECT	81 | ||
| 451 | #define _SC_THREAD_PROCESS_SHARED	82 | ||
| 452 | #define _SC_NPROCESSORS_CONF	83 | ||
| 453 | #define _SC_NPROCESSORS_ONLN	84 | ||
| 454 | #define _SC_PHYS_PAGES	85 | ||
| 455 | #define _SC_AVPHYS_PAGES	86 | ||
| 456 | #define _SC_ATEXIT_MAX	87 | ||
| 457 | #define _SC_PASS_MAX	88 | ||
| 458 | #define _SC_XOPEN_VERSION	89 | ||
| 459 | #define _SC_XOPEN_XCU_VERSION	90 | ||
| 460 | #define _SC_XOPEN_UNIX	91 | ||
| 461 | #define _SC_XOPEN_CRYPT	92 | ||
| 462 | #define _SC_XOPEN_ENH_I18N	93 | ||
| 463 | #define _SC_XOPEN_SHM	94 | ||
| 464 | #define _SC_2_CHAR_TERM	95 | ||
| 465 | #define _SC_2_UPE	97 | ||
| 466 | #define _SC_XOPEN_XPG2	98 | ||
| 467 | #define _SC_XOPEN_XPG3	99 | ||
| 468 | #define _SC_XOPEN_XPG4	100 | ||
| 469 | #define _SC_NZERO	109 | ||
| 470 | #define _SC_XBS5_ILP32_OFF32	125 | ||
| 471 | #define _SC_XBS5_ILP32_OFFBIG	126 | ||
| 472 | #define _SC_XBS5_LP64_OFF64	127 | ||
| 473 | #define _SC_XBS5_LPBIG_OFFBIG	128 | ||
| 474 | #define _SC_XOPEN_LEGACY	129 | ||
| 475 | #define _SC_XOPEN_REALTIME	130 | ||
| 476 | #define _SC_XOPEN_REALTIME_THREADS	131 | ||
| 477 | #define _SC_ADVISORY_INFO	132 | ||
| 478 | #define _SC_BARRIERS	133 | ||
| 479 | #define _SC_CLOCK_SELECTION	137 | ||
| 480 | #define _SC_CPUTIME	138 | ||
| 481 | #define _SC_THREAD_CPUTIME	139 | ||
| 482 | #define _SC_MONOTONIC_CLOCK	149 | ||
| 483 | #define _SC_READER_WRITER_LOCKS	153 | ||
| 484 | #define _SC_SPIN_LOCKS	154 | ||
| 485 | #define _SC_REGEXP	155 | ||
| 486 | #define _SC_SHELL	157 | ||
| 487 | #define _SC_SPAWN	159 | ||
| 488 | #define _SC_SPORADIC_SERVER	160 | ||
| 489 | #define _SC_THREAD_SPORADIC_SERVER	161 | ||
| 490 | #define _SC_TIMEOUTS	164 | ||
| 491 | #define _SC_TYPED_MEMORY_OBJECTS	165 | ||
| 492 | #define _SC_2_PBS	168 | ||
| 493 | #define _SC_2_PBS_ACCOUNTING	169 | ||
| 494 | #define _SC_2_PBS_LOCATE	170 | ||
| 495 | #define _SC_2_PBS_MESSAGE	171 | ||
| 496 | #define _SC_2_PBS_TRACK	172 | ||
| 497 | #define _SC_SYMLOOP_MAX	173 | ||
| 498 | #define _SC_STREAMS	174 | ||
| 499 | #define _SC_2_PBS_CHECKPOINT	175 | ||
| 500 | #define _SC_V6_ILP32_OFF32	176 | ||
| 501 | #define _SC_V6_ILP32_OFFBIG	177 | ||
| 502 | #define _SC_V6_LP64_OFF64	178 | ||
| 503 | #define _SC_V6_LPBIG_OFFBIG	179 | ||
| 504 | #define _SC_HOST_NAME_MAX	180 | ||
| 505 | #define _SC_TRACE	181 | ||
| 506 | #define _SC_TRACE_EVENT_FILTER	182 | ||
| 507 | #define _SC_TRACE_INHERIT	183 | ||
| 508 | #define _SC_TRACE_LOG	184 | ||
| 509 | |||
| 510 | #define _SC_IPV6	235 | ||
| 511 | #define _SC_RAW_SOCKETS	236 | ||
| 512 | #define _SC_V7_ILP32_OFF32	237 | ||
| 513 | #define _SC_V7_ILP32_OFFBIG	238 | ||
| 514 | #define _SC_V7_LP64_OFF64	239 | ||
| 515 | #define _SC_V7_LPBIG_OFFBIG	240 | ||
| 516 | #define _SC_SS_REPL_MAX	241 | ||
| 517 | #define _SC_TRACE_EVENT_NAME_MAX	242 | ||
| 518 | #define _SC_TRACE_NAME_MAX	243 | ||
| 519 | #define _SC_TRACE_SYS_MAX	244 | ||
| 520 | #define _SC_TRACE_USER_EVENT_MAX	245 | ||
| 521 | #define _SC_XOPEN_STREAMS	246 | ||
| 522 | #define _SC_THREAD_ROBUST_PRIO_INHERIT	247 | ||
| 523 | #define _SC_THREAD_ROBUST_PRIO_PROTECT	248 | ||
| 524 | |||
| 525 | #define _CS_PATH	0 | ||
| 526 | #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS	1 | ||
| 527 | #define _CS_GNU_LIBC_VERSION	2 | ||
| 528 | #define _CS_GNU_LIBPTHREAD_VERSION	3 | ||
| 529 | #define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS	4 | ||
| 530 | #define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS	5 | ||
| 531 | |||
| 532 | #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS	1116 | ||
| 533 | #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS	1117 | ||
| 534 | #define _CS_POSIX_V6_ILP32_OFF32_LIBS	1118 | ||
| 535 | #define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS	1119 | ||
| 536 | #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS	1120 | ||
| 537 | #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS	1121 | ||
| 538 | #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS	1122 | ||
| 539 | #define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS	1123 | ||
| 540 | #define _CS_POSIX_V6_LP64_OFF64_CFLAGS	1124 | ||
| 541 | #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS	1125 | ||
| 542 | #define _CS_POSIX_V6_LP64_OFF64_LIBS	1126 | ||
| 543 | #define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS	1127 | ||
| 544 | #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS	1128 | ||
| 545 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS	1129 | ||
| 546 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS	1130 | ||
| 547 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS	1131 | ||
| 548 | #define _CS_POSIX_V7_ILP32_OFF32_CFLAGS	1132 | ||
| 549 | #define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS	1133 | ||
| 550 | #define _CS_POSIX_V7_ILP32_OFF32_LIBS	1134 | ||
| 551 | #define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS	1135 | ||
| 552 | #define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS	1136 | ||
| 553 | #define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS	1137 | ||
| 554 | #define _CS_POSIX_V7_ILP32_OFFBIG_LIBS	1138 | ||
| 555 | #define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS	1139 | ||
| 556 | #define _CS_POSIX_V7_LP64_OFF64_CFLAGS	1140 | ||
| 557 | #define _CS_POSIX_V7_LP64_OFF64_LDFLAGS	1141 | ||
| 558 | #define _CS_POSIX_V7_LP64_OFF64_LIBS	1142 | ||
| 559 | #define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS	1143 | ||
| 560 | #define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS	1144 | ||
| 561 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS	1145 | ||
| 562 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS	1146 | ||
| 563 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS	1147 | ||
| 564 | #define _CS_V6_ENV	1148 | ||
| 565 | #define _CS_V7_ENV	1149 | ||
| 566 | |||
| 567 | #ifdef __cplusplus | ||
| 568 | } | ||
| 569 | #endif | ||
| 570 | |||
| 571 | #endif | ||
lib/libc/include/wasm-wasi-musl/utime.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef	_UTIME_H | ||
| 2 | #define	_UTIME_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_time_t | ||
| 11 | |||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | struct utimbuf { | ||
| 15 | 	time_t actime; | ||
| 16 | 	time_t modtime; | ||
| 17 | }; | ||
| 18 | |||
| 19 | int utime (const char *, const struct utimbuf *); | ||
| 20 | |||
| 21 | #if _REDIR_TIME64 | ||
| 22 | __REDIR(utime, __utime64); | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/include/wasm-wasi-musl/values.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef _VALUES_H | ||
| 2 | #define _VALUES_H | ||
| 3 | |||
| 4 | #include <limits.h> | ||
| 5 | |||
| 6 | #define CHARBITS (sizeof(char) * 8) | ||
| 7 | #define SHORTBITS (sizeof(short) * 8) | ||
| 8 | #define INTBITS (sizeof(int) * 8) | ||
| 9 | #define LONGBITS (sizeof(long) * 8) | ||
| 10 | #define PTRBITS (sizeof(char *) * 8) | ||
| 11 | #define DOUBLEBITS (sizeof(double) * 8) | ||
| 12 | #define FLOATBITS (sizeof(float) * 8) | ||
| 13 | |||
| 14 | #define MINSHORT SHRT_MIN | ||
| 15 | #define MININT INT_MIN | ||
| 16 | #define MINLONG LONG_MIN | ||
| 17 | |||
| 18 | #define MAXSHORT SHRT_MAX | ||
| 19 | #define MAXINT INT_MAX | ||
| 20 | #define MAXLONG LONG_MAX | ||
| 21 | |||
| 22 | #define HIBITS MINSHORT | ||
| 23 | #define HIBITL MINLONG | ||
| 24 | |||
| 25 | #include <float.h> | ||
| 26 | |||
| 27 | #define MAXDOUBLE DBL_MAX | ||
| 28 | #undef MAXFLOAT | ||
| 29 | #define MAXFLOAT FLT_MAX | ||
| 30 | #define MINDOUBLE DBL_MIN | ||
| 31 | #define MINFLOAT FLT_MIN | ||
| 32 | #define DMINEXP DBL_MIN_EXP | ||
| 33 | #define FMINEXP FLT_MIN_EXP | ||
| 34 | #define DMAXEXP DBL_MAX_EXP | ||
| 35 | #define FMAXEXP FLT_MAX_EXP | ||
| 36 | |||
| 37 | #define BITSPERBYTE CHAR_BIT | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/api.h created+2280| ... | @@ -0,0 +1,2280 @@ | ||
| 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 | * @file | ||
| 13 | * This file describes the [WASI] interface, consisting of functions, types, | ||
| 14 | * and defined values (macros). | ||
| 15 | * | ||
| 16 | * The interface described here is greatly inspired by [CloudABI]'s clean, | ||
| 17 | * thoughtfully-designed, capability-oriented, POSIX-style API. | ||
| 18 | * | ||
| 19 | * [CloudABI]: https://github.com/NuxiNL/cloudlibc | ||
| 20 | * [WASI]: https://github.com/WebAssembly/WASI/ | ||
| 21 | */ | ||
| 22 | |||
| 23 | #ifndef __wasi_api_h | ||
| 24 | #define __wasi_api_h | ||
| 25 | |||
| 26 | #ifndef __wasi__ | ||
| 27 | #error <wasi/api.h> is only supported on WASI platforms. | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #ifndef __wasm32__ | ||
| 31 | #error <wasi/api.h> only supports wasm32; doesn't yet support wasm64 | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #include <stddef.h> | ||
| 35 | #include <stdint.h> | ||
| 36 | |||
| 37 | _Static_assert(_Alignof(int8_t) == 1, "non-wasi data layout"); | ||
| 38 | _Static_assert(_Alignof(uint8_t) == 1, "non-wasi data layout"); | ||
| 39 | _Static_assert(_Alignof(int16_t) == 2, "non-wasi data layout"); | ||
| 40 | _Static_assert(_Alignof(uint16_t) == 2, "non-wasi data layout"); | ||
| 41 | _Static_assert(_Alignof(int32_t) == 4, "non-wasi data layout"); | ||
| 42 | _Static_assert(_Alignof(uint32_t) == 4, "non-wasi data layout"); | ||
| 43 | _Static_assert(_Alignof(int64_t) == 8, "non-wasi data layout"); | ||
| 44 | _Static_assert(_Alignof(uint64_t) == 8, "non-wasi data layout"); | ||
| 45 | _Static_assert(_Alignof(void*) == 4, "non-wasi data layout"); | ||
| 46 | |||
| 47 | #ifdef __cplusplus | ||
| 48 | extern "C" { | ||
| 49 | #endif | ||
| 50 | |||
| 51 | // TODO: Encoding this in witx. | ||
| 52 | #define __WASI_DIRCOOKIE_START (UINT64_C(0)) | ||
| 53 | typedef __SIZE_TYPE__ __wasi_size_t; | ||
| 54 | |||
| 55 | _Static_assert(sizeof(__wasi_size_t) == 4, "witx calculated size"); | ||
| 56 | _Static_assert(_Alignof(__wasi_size_t) == 4, "witx calculated align"); | ||
| 57 | |||
| 58 | /** | ||
| 59 | * Non-negative file size or length of a region within a file. | ||
| 60 | */ | ||
| 61 | typedef uint64_t __wasi_filesize_t; | ||
| 62 | |||
| 63 | _Static_assert(sizeof(__wasi_filesize_t) == 8, "witx calculated size"); | ||
| 64 | _Static_assert(_Alignof(__wasi_filesize_t) == 8, "witx calculated align"); | ||
| 65 | |||
| 66 | /** | ||
| 67 | * Timestamp in nanoseconds. | ||
| 68 | */ | ||
| 69 | typedef uint64_t __wasi_timestamp_t; | ||
| 70 | |||
| 71 | _Static_assert(sizeof(__wasi_timestamp_t) == 8, "witx calculated size"); | ||
| 72 | _Static_assert(_Alignof(__wasi_timestamp_t) == 8, "witx calculated align"); | ||
| 73 | |||
| 74 | /** | ||
| 75 | * Identifiers for clocks. | ||
| 76 | */ | ||
| 77 | typedef uint32_t __wasi_clockid_t; | ||
| 78 | |||
| 79 | /** | ||
| 80 | * The clock measuring real time. Time value zero corresponds with | ||
| 81 | * 1970-01-01T00:00:00Z. | ||
| 82 | */ | ||
| 83 | #define __WASI_CLOCKID_REALTIME (UINT32_C(0)) | ||
| 84 | |||
| 85 | /** | ||
| 86 | * The store-wide monotonic clock, which is defined as a clock measuring | ||
| 87 | * real time, whose value cannot be adjusted and which cannot have negative | ||
| 88 | * clock jumps. The epoch of this clock is undefined. The absolute time | ||
| 89 | * value of this clock therefore has no meaning. | ||
| 90 | */ | ||
| 91 | #define __WASI_CLOCKID_MONOTONIC (UINT32_C(1)) | ||
| 92 | |||
| 93 | /** | ||
| 94 | * The CPU-time clock associated with the current process. | ||
| 95 | */ | ||
| 96 | #define __WASI_CLOCKID_PROCESS_CPUTIME_ID (UINT32_C(2)) | ||
| 97 | |||
| 98 | /** | ||
| 99 | * The CPU-time clock associated with the current thread. | ||
| 100 | */ | ||
| 101 | #define __WASI_CLOCKID_THREAD_CPUTIME_ID (UINT32_C(3)) | ||
| 102 | |||
| 103 | _Static_assert(sizeof(__wasi_clockid_t) == 4, "witx calculated size"); | ||
| 104 | _Static_assert(_Alignof(__wasi_clockid_t) == 4, "witx calculated align"); | ||
| 105 | |||
| 106 | /** | ||
| 107 | * Error codes returned by functions. | ||
| 108 | * Not all of these error codes are returned by the functions provided by this | ||
| 109 | * API; some are used in higher-level library layers, and others are provided | ||
| 110 | * merely for alignment with POSIX. | ||
| 111 | */ | ||
| 112 | typedef uint16_t __wasi_errno_t; | ||
| 113 | |||
| 114 | /** | ||
| 115 | * No error occurred. System call completed successfully. | ||
| 116 | */ | ||
| 117 | #define __WASI_ERRNO_SUCCESS (UINT16_C(0)) | ||
| 118 | |||
| 119 | /** | ||
| 120 | * Argument list too long. | ||
| 121 | */ | ||
| 122 | #define __WASI_ERRNO_2BIG (UINT16_C(1)) | ||
| 123 | |||
| 124 | /** | ||
| 125 | * Permission denied. | ||
| 126 | */ | ||
| 127 | #define __WASI_ERRNO_ACCES (UINT16_C(2)) | ||
| 128 | |||
| 129 | /** | ||
| 130 | * Address in use. | ||
| 131 | */ | ||
| 132 | #define __WASI_ERRNO_ADDRINUSE (UINT16_C(3)) | ||
| 133 | |||
| 134 | /** | ||
| 135 | * Address not available. | ||
| 136 | */ | ||
| 137 | #define __WASI_ERRNO_ADDRNOTAVAIL (UINT16_C(4)) | ||
| 138 | |||
| 139 | /** | ||
| 140 | * Address family not supported. | ||
| 141 | */ | ||
| 142 | #define __WASI_ERRNO_AFNOSUPPORT (UINT16_C(5)) | ||
| 143 | |||
| 144 | /** | ||
| 145 | * Resource unavailable, or operation would block. | ||
| 146 | */ | ||
| 147 | #define __WASI_ERRNO_AGAIN (UINT16_C(6)) | ||
| 148 | |||
| 149 | /** | ||
| 150 | * Connection already in progress. | ||
| 151 | */ | ||
| 152 | #define __WASI_ERRNO_ALREADY (UINT16_C(7)) | ||
| 153 | |||
| 154 | /** | ||
| 155 | * Bad file descriptor. | ||
| 156 | */ | ||
| 157 | #define __WASI_ERRNO_BADF (UINT16_C(8)) | ||
| 158 | |||
| 159 | /** | ||
| 160 | * Bad message. | ||
| 161 | */ | ||
| 162 | #define __WASI_ERRNO_BADMSG (UINT16_C(9)) | ||
| 163 | |||
| 164 | /** | ||
| 165 | * Device or resource busy. | ||
| 166 | */ | ||
| 167 | #define __WASI_ERRNO_BUSY (UINT16_C(10)) | ||
| 168 | |||
| 169 | /** | ||
| 170 | * Operation canceled. | ||
| 171 | */ | ||
| 172 | #define __WASI_ERRNO_CANCELED (UINT16_C(11)) | ||
| 173 | |||
| 174 | /** | ||
| 175 | * No child processes. | ||
| 176 | */ | ||
| 177 | #define __WASI_ERRNO_CHILD (UINT16_C(12)) | ||
| 178 | |||
| 179 | /** | ||
| 180 | * Connection aborted. | ||
| 181 | */ | ||
| 182 | #define __WASI_ERRNO_CONNABORTED (UINT16_C(13)) | ||
| 183 | |||
| 184 | /** | ||
| 185 | * Connection refused. | ||
| 186 | */ | ||
| 187 | #define __WASI_ERRNO_CONNREFUSED (UINT16_C(14)) | ||
| 188 | |||
| 189 | /** | ||
| 190 | * Connection reset. | ||
| 191 | */ | ||
| 192 | #define __WASI_ERRNO_CONNRESET (UINT16_C(15)) | ||
| 193 | |||
| 194 | /** | ||
| 195 | * Resource deadlock would occur. | ||
| 196 | */ | ||
| 197 | #define __WASI_ERRNO_DEADLK (UINT16_C(16)) | ||
| 198 | |||
| 199 | /** | ||
| 200 | * Destination address required. | ||
| 201 | */ | ||
| 202 | #define __WASI_ERRNO_DESTADDRREQ (UINT16_C(17)) | ||
| 203 | |||
| 204 | /** | ||
| 205 | * Mathematics argument out of domain of function. | ||
| 206 | */ | ||
| 207 | #define __WASI_ERRNO_DOM (UINT16_C(18)) | ||
| 208 | |||
| 209 | /** | ||
| 210 | * Reserved. | ||
| 211 | */ | ||
| 212 | #define __WASI_ERRNO_DQUOT (UINT16_C(19)) | ||
| 213 | |||
| 214 | /** | ||
| 215 | * File exists. | ||
| 216 | */ | ||
| 217 | #define __WASI_ERRNO_EXIST (UINT16_C(20)) | ||
| 218 | |||
| 219 | /** | ||
| 220 | * Bad address. | ||
| 221 | */ | ||
| 222 | #define __WASI_ERRNO_FAULT (UINT16_C(21)) | ||
| 223 | |||
| 224 | /** | ||
| 225 | * File too large. | ||
| 226 | */ | ||
| 227 | #define __WASI_ERRNO_FBIG (UINT16_C(22)) | ||
| 228 | |||
| 229 | /** | ||
| 230 | * Host is unreachable. | ||
| 231 | */ | ||
| 232 | #define __WASI_ERRNO_HOSTUNREACH (UINT16_C(23)) | ||
| 233 | |||
| 234 | /** | ||
| 235 | * Identifier removed. | ||
| 236 | */ | ||
| 237 | #define __WASI_ERRNO_IDRM (UINT16_C(24)) | ||
| 238 | |||
| 239 | /** | ||
| 240 | * Illegal byte sequence. | ||
| 241 | */ | ||
| 242 | #define __WASI_ERRNO_ILSEQ (UINT16_C(25)) | ||
| 243 | |||
| 244 | /** | ||
| 245 | * Operation in progress. | ||
| 246 | */ | ||
| 247 | #define __WASI_ERRNO_INPROGRESS (UINT16_C(26)) | ||
| 248 | |||
| 249 | /** | ||
| 250 | * Interrupted function. | ||
| 251 | */ | ||
| 252 | #define __WASI_ERRNO_INTR (UINT16_C(27)) | ||
| 253 | |||
| 254 | /** | ||
| 255 | * Invalid argument. | ||
| 256 | */ | ||
| 257 | #define __WASI_ERRNO_INVAL (UINT16_C(28)) | ||
| 258 | |||
| 259 | /** | ||
| 260 | * I/O error. | ||
| 261 | */ | ||
| 262 | #define __WASI_ERRNO_IO (UINT16_C(29)) | ||
| 263 | |||
| 264 | /** | ||
| 265 | * Socket is connected. | ||
| 266 | */ | ||
| 267 | #define __WASI_ERRNO_ISCONN (UINT16_C(30)) | ||
| 268 | |||
| 269 | /** | ||
| 270 | * Is a directory. | ||
| 271 | */ | ||
| 272 | #define __WASI_ERRNO_ISDIR (UINT16_C(31)) | ||
| 273 | |||
| 274 | /** | ||
| 275 | * Too many levels of symbolic links. | ||
| 276 | */ | ||
| 277 | #define __WASI_ERRNO_LOOP (UINT16_C(32)) | ||
| 278 | |||
| 279 | /** | ||
| 280 | * File descriptor value too large. | ||
| 281 | */ | ||
| 282 | #define __WASI_ERRNO_MFILE (UINT16_C(33)) | ||
| 283 | |||
| 284 | /** | ||
| 285 | * Too many links. | ||
| 286 | */ | ||
| 287 | #define __WASI_ERRNO_MLINK (UINT16_C(34)) | ||
| 288 | |||
| 289 | /** | ||
| 290 | * Message too large. | ||
| 291 | */ | ||
| 292 | #define __WASI_ERRNO_MSGSIZE (UINT16_C(35)) | ||
| 293 | |||
| 294 | /** | ||
| 295 | * Reserved. | ||
| 296 | */ | ||
| 297 | #define __WASI_ERRNO_MULTIHOP (UINT16_C(36)) | ||
| 298 | |||
| 299 | /** | ||
| 300 | * Filename too long. | ||
| 301 | */ | ||
| 302 | #define __WASI_ERRNO_NAMETOOLONG (UINT16_C(37)) | ||
| 303 | |||
| 304 | /** | ||
| 305 | * Network is down. | ||
| 306 | */ | ||
| 307 | #define __WASI_ERRNO_NETDOWN (UINT16_C(38)) | ||
| 308 | |||
| 309 | /** | ||
| 310 | * Connection aborted by network. | ||
| 311 | */ | ||
| 312 | #define __WASI_ERRNO_NETRESET (UINT16_C(39)) | ||
| 313 | |||
| 314 | /** | ||
| 315 | * Network unreachable. | ||
| 316 | */ | ||
| 317 | #define __WASI_ERRNO_NETUNREACH (UINT16_C(40)) | ||
| 318 | |||
| 319 | /** | ||
| 320 | * Too many files open in system. | ||
| 321 | */ | ||
| 322 | #define __WASI_ERRNO_NFILE (UINT16_C(41)) | ||
| 323 | |||
| 324 | /** | ||
| 325 | * No buffer space available. | ||
| 326 | */ | ||
| 327 | #define __WASI_ERRNO_NOBUFS (UINT16_C(42)) | ||
| 328 | |||
| 329 | /** | ||
| 330 | * No such device. | ||
| 331 | */ | ||
| 332 | #define __WASI_ERRNO_NODEV (UINT16_C(43)) | ||
| 333 | |||
| 334 | /** | ||
| 335 | * No such file or directory. | ||
| 336 | */ | ||
| 337 | #define __WASI_ERRNO_NOENT (UINT16_C(44)) | ||
| 338 | |||
| 339 | /** | ||
| 340 | * Executable file format error. | ||
| 341 | */ | ||
| 342 | #define __WASI_ERRNO_NOEXEC (UINT16_C(45)) | ||
| 343 | |||
| 344 | /** | ||
| 345 | * No locks available. | ||
| 346 | */ | ||
| 347 | #define __WASI_ERRNO_NOLCK (UINT16_C(46)) | ||
| 348 | |||
| 349 | /** | ||
| 350 | * Reserved. | ||
| 351 | */ | ||
| 352 | #define __WASI_ERRNO_NOLINK (UINT16_C(47)) | ||
| 353 | |||
| 354 | /** | ||
| 355 | * Not enough space. | ||
| 356 | */ | ||
| 357 | #define __WASI_ERRNO_NOMEM (UINT16_C(48)) | ||
| 358 | |||
| 359 | /** | ||
| 360 | * No message of the desired type. | ||
| 361 | */ | ||
| 362 | #define __WASI_ERRNO_NOMSG (UINT16_C(49)) | ||
| 363 | |||
| 364 | /** | ||
| 365 | * Protocol not available. | ||
| 366 | */ | ||
| 367 | #define __WASI_ERRNO_NOPROTOOPT (UINT16_C(50)) | ||
| 368 | |||
| 369 | /** | ||
| 370 | * No space left on device. | ||
| 371 | */ | ||
| 372 | #define __WASI_ERRNO_NOSPC (UINT16_C(51)) | ||
| 373 | |||
| 374 | /** | ||
| 375 | * Function not supported. | ||
| 376 | */ | ||
| 377 | #define __WASI_ERRNO_NOSYS (UINT16_C(52)) | ||
| 378 | |||
| 379 | /** | ||
| 380 | * The socket is not connected. | ||
| 381 | */ | ||
| 382 | #define __WASI_ERRNO_NOTCONN (UINT16_C(53)) | ||
| 383 | |||
| 384 | /** | ||
| 385 | * Not a directory or a symbolic link to a directory. | ||
| 386 | */ | ||
| 387 | #define __WASI_ERRNO_NOTDIR (UINT16_C(54)) | ||
| 388 | |||
| 389 | /** | ||
| 390 | * Directory not empty. | ||
| 391 | */ | ||
| 392 | #define __WASI_ERRNO_NOTEMPTY (UINT16_C(55)) | ||
| 393 | |||
| 394 | /** | ||
| 395 | * State not recoverable. | ||
| 396 | */ | ||
| 397 | #define __WASI_ERRNO_NOTRECOVERABLE (UINT16_C(56)) | ||
| 398 | |||
| 399 | /** | ||
| 400 | * Not a socket. | ||
| 401 | */ | ||
| 402 | #define __WASI_ERRNO_NOTSOCK (UINT16_C(57)) | ||
| 403 | |||
| 404 | /** | ||
| 405 | * Not supported, or operation not supported on socket. | ||
| 406 | */ | ||
| 407 | #define __WASI_ERRNO_NOTSUP (UINT16_C(58)) | ||
| 408 | |||
| 409 | /** | ||
| 410 | * Inappropriate I/O control operation. | ||
| 411 | */ | ||
| 412 | #define __WASI_ERRNO_NOTTY (UINT16_C(59)) | ||
| 413 | |||
| 414 | /** | ||
| 415 | * No such device or address. | ||
| 416 | */ | ||
| 417 | #define __WASI_ERRNO_NXIO (UINT16_C(60)) | ||
| 418 | |||
| 419 | /** | ||
| 420 | * Value too large to be stored in data type. | ||
| 421 | */ | ||
| 422 | #define __WASI_ERRNO_OVERFLOW (UINT16_C(61)) | ||
| 423 | |||
| 424 | /** | ||
| 425 | * Previous owner died. | ||
| 426 | */ | ||
| 427 | #define __WASI_ERRNO_OWNERDEAD (UINT16_C(62)) | ||
| 428 | |||
| 429 | /** | ||
| 430 | * Operation not permitted. | ||
| 431 | */ | ||
| 432 | #define __WASI_ERRNO_PERM (UINT16_C(63)) | ||
| 433 | |||
| 434 | /** | ||
| 435 | * Broken pipe. | ||
| 436 | */ | ||
| 437 | #define __WASI_ERRNO_PIPE (UINT16_C(64)) | ||
| 438 | |||
| 439 | /** | ||
| 440 | * Protocol error. | ||
| 441 | */ | ||
| 442 | #define __WASI_ERRNO_PROTO (UINT16_C(65)) | ||
| 443 | |||
| 444 | /** | ||
| 445 | * Protocol not supported. | ||
| 446 | */ | ||
| 447 | #define __WASI_ERRNO_PROTONOSUPPORT (UINT16_C(66)) | ||
| 448 | |||
| 449 | /** | ||
| 450 | * Protocol wrong type for socket. | ||
| 451 | */ | ||
| 452 | #define __WASI_ERRNO_PROTOTYPE (UINT16_C(67)) | ||
| 453 | |||
| 454 | /** | ||
| 455 | * Result too large. | ||
| 456 | */ | ||
| 457 | #define __WASI_ERRNO_RANGE (UINT16_C(68)) | ||
| 458 | |||
| 459 | /** | ||
| 460 | * Read-only file system. | ||
| 461 | */ | ||
| 462 | #define __WASI_ERRNO_ROFS (UINT16_C(69)) | ||
| 463 | |||
| 464 | /** | ||
| 465 | * Invalid seek. | ||
| 466 | */ | ||
| 467 | #define __WASI_ERRNO_SPIPE (UINT16_C(70)) | ||
| 468 | |||
| 469 | /** | ||
| 470 | * No such process. | ||
| 471 | */ | ||
| 472 | #define __WASI_ERRNO_SRCH (UINT16_C(71)) | ||
| 473 | |||
| 474 | /** | ||
| 475 | * Reserved. | ||
| 476 | */ | ||
| 477 | #define __WASI_ERRNO_STALE (UINT16_C(72)) | ||
| 478 | |||
| 479 | /** | ||
| 480 | * Connection timed out. | ||
| 481 | */ | ||
| 482 | #define __WASI_ERRNO_TIMEDOUT (UINT16_C(73)) | ||
| 483 | |||
| 484 | /** | ||
| 485 | * Text file busy. | ||
| 486 | */ | ||
| 487 | #define __WASI_ERRNO_TXTBSY (UINT16_C(74)) | ||
| 488 | |||
| 489 | /** | ||
| 490 | * Cross-device link. | ||
| 491 | */ | ||
| 492 | #define __WASI_ERRNO_XDEV (UINT16_C(75)) | ||
| 493 | |||
| 494 | /** | ||
| 495 | * Extension: Capabilities insufficient. | ||
| 496 | */ | ||
| 497 | #define __WASI_ERRNO_NOTCAPABLE (UINT16_C(76)) | ||
| 498 | |||
| 499 | _Static_assert(sizeof(__wasi_errno_t) == 2, "witx calculated size"); | ||
| 500 | _Static_assert(_Alignof(__wasi_errno_t) == 2, "witx calculated align"); | ||
| 501 | |||
| 502 | /** | ||
| 503 | * File descriptor rights, determining which actions may be performed. | ||
| 504 | */ | ||
| 505 | typedef uint64_t __wasi_rights_t; | ||
| 506 | |||
| 507 | /** | ||
| 508 | * The right to invoke `fd_datasync`. | ||
| 509 | * If `path_open` is set, includes the right to invoke | ||
| 510 | * `path_open` with `fdflags::dsync`. | ||
| 511 | */ | ||
| 512 | #define __WASI_RIGHTS_FD_DATASYNC ((__wasi_rights_t)(1 << 0)) | ||
| 513 | |||
| 514 | /** | ||
| 515 | * The right to invoke `fd_read` and `sock_recv`. | ||
| 516 | * If `rights::fd_seek` is set, includes the right to invoke `fd_pread`. | ||
| 517 | */ | ||
| 518 | #define __WASI_RIGHTS_FD_READ ((__wasi_rights_t)(1 << 1)) | ||
| 519 | |||
| 520 | /** | ||
| 521 | * The right to invoke `fd_seek`. This flag implies `rights::fd_tell`. | ||
| 522 | */ | ||
| 523 | #define __WASI_RIGHTS_FD_SEEK ((__wasi_rights_t)(1 << 2)) | ||
| 524 | |||
| 525 | /** | ||
| 526 | * The right to invoke `fd_fdstat_set_flags`. | ||
| 527 | */ | ||
| 528 | #define __WASI_RIGHTS_FD_FDSTAT_SET_FLAGS ((__wasi_rights_t)(1 << 3)) | ||
| 529 | |||
| 530 | /** | ||
| 531 | * The right to invoke `fd_sync`. | ||
| 532 | * If `path_open` is set, includes the right to invoke | ||
| 533 | * `path_open` with `fdflags::rsync` and `fdflags::dsync`. | ||
| 534 | */ | ||
| 535 | #define __WASI_RIGHTS_FD_SYNC ((__wasi_rights_t)(1 << 4)) | ||
| 536 | |||
| 537 | /** | ||
| 538 | * The right to invoke `fd_seek` in such a way that the file offset | ||
| 539 | * remains unaltered (i.e., `whence::cur` with offset zero), or to | ||
| 540 | * invoke `fd_tell`. | ||
| 541 | */ | ||
| 542 | #define __WASI_RIGHTS_FD_TELL ((__wasi_rights_t)(1 << 5)) | ||
| 543 | |||
| 544 | /** | ||
| 545 | * The right to invoke `fd_write` and `sock_send`. | ||
| 546 | * If `rights::fd_seek` is set, includes the right to invoke `fd_pwrite`. | ||
| 547 | */ | ||
| 548 | #define __WASI_RIGHTS_FD_WRITE ((__wasi_rights_t)(1 << 6)) | ||
| 549 | |||
| 550 | /** | ||
| 551 | * The right to invoke `fd_advise`. | ||
| 552 | */ | ||
| 553 | #define __WASI_RIGHTS_FD_ADVISE ((__wasi_rights_t)(1 << 7)) | ||
| 554 | |||
| 555 | /** | ||
| 556 | * The right to invoke `fd_allocate`. | ||
| 557 | */ | ||
| 558 | #define __WASI_RIGHTS_FD_ALLOCATE ((__wasi_rights_t)(1 << 8)) | ||
| 559 | |||
| 560 | /** | ||
| 561 | * The right to invoke `path_create_directory`. | ||
| 562 | */ | ||
| 563 | #define __WASI_RIGHTS_PATH_CREATE_DIRECTORY ((__wasi_rights_t)(1 << 9)) | ||
| 564 | |||
| 565 | /** | ||
| 566 | * If `path_open` is set, the right to invoke `path_open` with `oflags::creat`. | ||
| 567 | */ | ||
| 568 | #define __WASI_RIGHTS_PATH_CREATE_FILE ((__wasi_rights_t)(1 << 10)) | ||
| 569 | |||
| 570 | /** | ||
| 571 | * The right to invoke `path_link` with the file descriptor as the | ||
| 572 | * source directory. | ||
| 573 | */ | ||
| 574 | #define __WASI_RIGHTS_PATH_LINK_SOURCE ((__wasi_rights_t)(1 << 11)) | ||
| 575 | |||
| 576 | /** | ||
| 577 | * The right to invoke `path_link` with the file descriptor as the | ||
| 578 | * target directory. | ||
| 579 | */ | ||
| 580 | #define __WASI_RIGHTS_PATH_LINK_TARGET ((__wasi_rights_t)(1 << 12)) | ||
| 581 | |||
| 582 | /** | ||
| 583 | * The right to invoke `path_open`. | ||
| 584 | */ | ||
| 585 | #define __WASI_RIGHTS_PATH_OPEN ((__wasi_rights_t)(1 << 13)) | ||
| 586 | |||
| 587 | /** | ||
| 588 | * The right to invoke `fd_readdir`. | ||
| 589 | */ | ||
| 590 | #define __WASI_RIGHTS_FD_READDIR ((__wasi_rights_t)(1 << 14)) | ||
| 591 | |||
| 592 | /** | ||
| 593 | * The right to invoke `path_readlink`. | ||
| 594 | */ | ||
| 595 | #define __WASI_RIGHTS_PATH_READLINK ((__wasi_rights_t)(1 << 15)) | ||
| 596 | |||
| 597 | /** | ||
| 598 | * The right to invoke `path_rename` with the file descriptor as the source directory. | ||
| 599 | */ | ||
| 600 | #define __WASI_RIGHTS_PATH_RENAME_SOURCE ((__wasi_rights_t)(1 << 16)) | ||
| 601 | |||
| 602 | /** | ||
| 603 | * The right to invoke `path_rename` with the file descriptor as the target directory. | ||
| 604 | */ | ||
| 605 | #define __WASI_RIGHTS_PATH_RENAME_TARGET ((__wasi_rights_t)(1 << 17)) | ||
| 606 | |||
| 607 | /** | ||
| 608 | * The right to invoke `path_filestat_get`. | ||
| 609 | */ | ||
| 610 | #define __WASI_RIGHTS_PATH_FILESTAT_GET ((__wasi_rights_t)(1 << 18)) | ||
| 611 | |||
| 612 | /** | ||
| 613 | * The right to change a file's size (there is no `path_filestat_set_size`). | ||
| 614 | * If `path_open` is set, includes the right to invoke `path_open` with `oflags::trunc`. | ||
| 615 | */ | ||
| 616 | #define __WASI_RIGHTS_PATH_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 19)) | ||
| 617 | |||
| 618 | /** | ||
| 619 | * The right to invoke `path_filestat_set_times`. | ||
| 620 | */ | ||
| 621 | #define __WASI_RIGHTS_PATH_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 20)) | ||
| 622 | |||
| 623 | /** | ||
| 624 | * The right to invoke `fd_filestat_get`. | ||
| 625 | */ | ||
| 626 | #define __WASI_RIGHTS_FD_FILESTAT_GET ((__wasi_rights_t)(1 << 21)) | ||
| 627 | |||
| 628 | /** | ||
| 629 | * The right to invoke `fd_filestat_set_size`. | ||
| 630 | */ | ||
| 631 | #define __WASI_RIGHTS_FD_FILESTAT_SET_SIZE ((__wasi_rights_t)(1 << 22)) | ||
| 632 | |||
| 633 | /** | ||
| 634 | * The right to invoke `fd_filestat_set_times`. | ||
| 635 | */ | ||
| 636 | #define __WASI_RIGHTS_FD_FILESTAT_SET_TIMES ((__wasi_rights_t)(1 << 23)) | ||
| 637 | |||
| 638 | /** | ||
| 639 | * The right to invoke `path_symlink`. | ||
| 640 | */ | ||
| 641 | #define __WASI_RIGHTS_PATH_SYMLINK ((__wasi_rights_t)(1 << 24)) | ||
| 642 | |||
| 643 | /** | ||
| 644 | * The right to invoke `path_remove_directory`. | ||
| 645 | */ | ||
| 646 | #define __WASI_RIGHTS_PATH_REMOVE_DIRECTORY ((__wasi_rights_t)(1 << 25)) | ||
| 647 | |||
| 648 | /** | ||
| 649 | * The right to invoke `path_unlink_file`. | ||
| 650 | */ | ||
| 651 | #define __WASI_RIGHTS_PATH_UNLINK_FILE ((__wasi_rights_t)(1 << 26)) | ||
| 652 | |||
| 653 | /** | ||
| 654 | * If `rights::fd_read` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_read`. | ||
| 655 | * If `rights::fd_write` is set, includes the right to invoke `poll_oneoff` to subscribe to `eventtype::fd_write`. | ||
| 656 | */ | ||
| 657 | #define __WASI_RIGHTS_POLL_FD_READWRITE ((__wasi_rights_t)(1 << 27)) | ||
| 658 | |||
| 659 | /** | ||
| 660 | * The right to invoke `sock_shutdown`. | ||
| 661 | */ | ||
| 662 | #define __WASI_RIGHTS_SOCK_SHUTDOWN ((__wasi_rights_t)(1 << 28)) | ||
| 663 | |||
| 664 | /** | ||
| 665 | * A file descriptor handle. | ||
| 666 | */ | ||
| 667 | typedef int __wasi_fd_t; | ||
| 668 | |||
| 669 | _Static_assert(sizeof(__wasi_fd_t) == 4, "witx calculated size"); | ||
| 670 | _Static_assert(_Alignof(__wasi_fd_t) == 4, "witx calculated align"); | ||
| 671 | |||
| 672 | /** | ||
| 673 | * A region of memory for scatter/gather reads. | ||
| 674 | */ | ||
| 675 | typedef struct __wasi_iovec_t { | ||
| 676 | /** | ||
| 677 | * The address of the buffer to be filled. | ||
| 678 | */ | ||
| 679 | uint8_t * buf; | ||
| 680 | |||
| 681 | /** | ||
| 682 | * The length of the buffer to be filled. | ||
| 683 | */ | ||
| 684 | __wasi_size_t buf_len; | ||
| 685 | |||
| 686 | } __wasi_iovec_t; | ||
| 687 | |||
| 688 | _Static_assert(sizeof(__wasi_iovec_t) == 8, "witx calculated size"); | ||
| 689 | _Static_assert(_Alignof(__wasi_iovec_t) == 4, "witx calculated align"); | ||
| 690 | _Static_assert(offsetof(__wasi_iovec_t, buf) == 0, "witx calculated offset"); | ||
| 691 | _Static_assert(offsetof(__wasi_iovec_t, buf_len) == 4, "witx calculated offset"); | ||
| 692 | |||
| 693 | /** | ||
| 694 | * A region of memory for scatter/gather writes. | ||
| 695 | */ | ||
| 696 | typedef struct __wasi_ciovec_t { | ||
| 697 | /** | ||
| 698 | * The address of the buffer to be written. | ||
| 699 | */ | ||
| 700 | const uint8_t * buf; | ||
| 701 | |||
| 702 | /** | ||
| 703 | * The length of the buffer to be written. | ||
| 704 | */ | ||
| 705 | __wasi_size_t buf_len; | ||
| 706 | |||
| 707 | } __wasi_ciovec_t; | ||
| 708 | |||
| 709 | _Static_assert(sizeof(__wasi_ciovec_t) == 8, "witx calculated size"); | ||
| 710 | _Static_assert(_Alignof(__wasi_ciovec_t) == 4, "witx calculated align"); | ||
| 711 | _Static_assert(offsetof(__wasi_ciovec_t, buf) == 0, "witx calculated offset"); | ||
| 712 | _Static_assert(offsetof(__wasi_ciovec_t, buf_len) == 4, "witx calculated offset"); | ||
| 713 | |||
| 714 | /** | ||
| 715 | * Relative offset within a file. | ||
| 716 | */ | ||
| 717 | typedef int64_t __wasi_filedelta_t; | ||
| 718 | |||
| 719 | _Static_assert(sizeof(__wasi_filedelta_t) == 8, "witx calculated size"); | ||
| 720 | _Static_assert(_Alignof(__wasi_filedelta_t) == 8, "witx calculated align"); | ||
| 721 | |||
| 722 | /** | ||
| 723 | * The position relative to which to set the offset of the file descriptor. | ||
| 724 | */ | ||
| 725 | typedef uint8_t __wasi_whence_t; | ||
| 726 | |||
| 727 | /** | ||
| 728 | * Seek relative to start-of-file. | ||
| 729 | */ | ||
| 730 | #define __WASI_WHENCE_SET (UINT8_C(0)) | ||
| 731 | |||
| 732 | /** | ||
| 733 | * Seek relative to current position. | ||
| 734 | */ | ||
| 735 | #define __WASI_WHENCE_CUR (UINT8_C(1)) | ||
| 736 | |||
| 737 | /** | ||
| 738 | * Seek relative to end-of-file. | ||
| 739 | */ | ||
| 740 | #define __WASI_WHENCE_END (UINT8_C(2)) | ||
| 741 | |||
| 742 | _Static_assert(sizeof(__wasi_whence_t) == 1, "witx calculated size"); | ||
| 743 | _Static_assert(_Alignof(__wasi_whence_t) == 1, "witx calculated align"); | ||
| 744 | |||
| 745 | /** | ||
| 746 | * A reference to the offset of a directory entry. | ||
| 747 | * | ||
| 748 | * The value 0 signifies the start of the directory. | ||
| 749 | */ | ||
| 750 | typedef uint64_t __wasi_dircookie_t; | ||
| 751 | |||
| 752 | _Static_assert(sizeof(__wasi_dircookie_t) == 8, "witx calculated size"); | ||
| 753 | _Static_assert(_Alignof(__wasi_dircookie_t) == 8, "witx calculated align"); | ||
| 754 | |||
| 755 | /** | ||
| 756 | * The type for the `dirent::d_namlen` field of `dirent` struct. | ||
| 757 | */ | ||
| 758 | typedef uint32_t __wasi_dirnamlen_t; | ||
| 759 | |||
| 760 | _Static_assert(sizeof(__wasi_dirnamlen_t) == 4, "witx calculated size"); | ||
| 761 | _Static_assert(_Alignof(__wasi_dirnamlen_t) == 4, "witx calculated align"); | ||
| 762 | |||
| 763 | /** | ||
| 764 | * File serial number that is unique within its file system. | ||
| 765 | */ | ||
| 766 | typedef uint64_t __wasi_inode_t; | ||
| 767 | |||
| 768 | _Static_assert(sizeof(__wasi_inode_t) == 8, "witx calculated size"); | ||
| 769 | _Static_assert(_Alignof(__wasi_inode_t) == 8, "witx calculated align"); | ||
| 770 | |||
| 771 | /** | ||
| 772 | * The type of a file descriptor or file. | ||
| 773 | */ | ||
| 774 | typedef uint8_t __wasi_filetype_t; | ||
| 775 | |||
| 776 | /** | ||
| 777 | * The type of the file descriptor or file is unknown or is different from any of the other types specified. | ||
| 778 | */ | ||
| 779 | #define __WASI_FILETYPE_UNKNOWN (UINT8_C(0)) | ||
| 780 | |||
| 781 | /** | ||
| 782 | * The file descriptor or file refers to a block device inode. | ||
| 783 | */ | ||
| 784 | #define __WASI_FILETYPE_BLOCK_DEVICE (UINT8_C(1)) | ||
| 785 | |||
| 786 | /** | ||
| 787 | * The file descriptor or file refers to a character device inode. | ||
| 788 | */ | ||
| 789 | #define __WASI_FILETYPE_CHARACTER_DEVICE (UINT8_C(2)) | ||
| 790 | |||
| 791 | /** | ||
| 792 | * The file descriptor or file refers to a directory inode. | ||
| 793 | */ | ||
| 794 | #define __WASI_FILETYPE_DIRECTORY (UINT8_C(3)) | ||
| 795 | |||
| 796 | /** | ||
| 797 | * The file descriptor or file refers to a regular file inode. | ||
| 798 | */ | ||
| 799 | #define __WASI_FILETYPE_REGULAR_FILE (UINT8_C(4)) | ||
| 800 | |||
| 801 | /** | ||
| 802 | * The file descriptor or file refers to a datagram socket. | ||
| 803 | */ | ||
| 804 | #define __WASI_FILETYPE_SOCKET_DGRAM (UINT8_C(5)) | ||
| 805 | |||
| 806 | /** | ||
| 807 | * The file descriptor or file refers to a byte-stream socket. | ||
| 808 | */ | ||
| 809 | #define __WASI_FILETYPE_SOCKET_STREAM (UINT8_C(6)) | ||
| 810 | |||
| 811 | /** | ||
| 812 | * The file refers to a symbolic link inode. | ||
| 813 | */ | ||
| 814 | #define __WASI_FILETYPE_SYMBOLIC_LINK (UINT8_C(7)) | ||
| 815 | |||
| 816 | _Static_assert(sizeof(__wasi_filetype_t) == 1, "witx calculated size"); | ||
| 817 | _Static_assert(_Alignof(__wasi_filetype_t) == 1, "witx calculated align"); | ||
| 818 | |||
| 819 | /** | ||
| 820 | * A directory entry. | ||
| 821 | */ | ||
| 822 | typedef struct __wasi_dirent_t { | ||
| 823 | /** | ||
| 824 | * The offset of the next directory entry stored in this directory. | ||
| 825 | */ | ||
| 826 | __wasi_dircookie_t d_next; | ||
| 827 | |||
| 828 | /** | ||
| 829 | * The serial number of the file referred to by this directory entry. | ||
| 830 | */ | ||
| 831 | __wasi_inode_t d_ino; | ||
| 832 | |||
| 833 | /** | ||
| 834 | * The length of the name of the directory entry. | ||
| 835 | */ | ||
| 836 | __wasi_dirnamlen_t d_namlen; | ||
| 837 | |||
| 838 | /** | ||
| 839 | * The type of the file referred to by this directory entry. | ||
| 840 | */ | ||
| 841 | __wasi_filetype_t d_type; | ||
| 842 | |||
| 843 | } __wasi_dirent_t; | ||
| 844 | |||
| 845 | _Static_assert(sizeof(__wasi_dirent_t) == 24, "witx calculated size"); | ||
| 846 | _Static_assert(_Alignof(__wasi_dirent_t) == 8, "witx calculated align"); | ||
| 847 | _Static_assert(offsetof(__wasi_dirent_t, d_next) == 0, "witx calculated offset"); | ||
| 848 | _Static_assert(offsetof(__wasi_dirent_t, d_ino) == 8, "witx calculated offset"); | ||
| 849 | _Static_assert(offsetof(__wasi_dirent_t, d_namlen) == 16, "witx calculated offset"); | ||
| 850 | _Static_assert(offsetof(__wasi_dirent_t, d_type) == 20, "witx calculated offset"); | ||
| 851 | |||
| 852 | /** | ||
| 853 | * File or memory access pattern advisory information. | ||
| 854 | */ | ||
| 855 | typedef uint8_t __wasi_advice_t; | ||
| 856 | |||
| 857 | /** | ||
| 858 | * The application has no advice to give on its behavior with respect to the specified data. | ||
| 859 | */ | ||
| 860 | #define __WASI_ADVICE_NORMAL (UINT8_C(0)) | ||
| 861 | |||
| 862 | /** | ||
| 863 | * The application expects to access the specified data sequentially from lower offsets to higher offsets. | ||
| 864 | */ | ||
| 865 | #define __WASI_ADVICE_SEQUENTIAL (UINT8_C(1)) | ||
| 866 | |||
| 867 | /** | ||
| 868 | * The application expects to access the specified data in a random order. | ||
| 869 | */ | ||
| 870 | #define __WASI_ADVICE_RANDOM (UINT8_C(2)) | ||
| 871 | |||
| 872 | /** | ||
| 873 | * The application expects to access the specified data in the near future. | ||
| 874 | */ | ||
| 875 | #define __WASI_ADVICE_WILLNEED (UINT8_C(3)) | ||
| 876 | |||
| 877 | /** | ||
| 878 | * The application expects that it will not access the specified data in the near future. | ||
| 879 | */ | ||
| 880 | #define __WASI_ADVICE_DONTNEED (UINT8_C(4)) | ||
| 881 | |||
| 882 | /** | ||
| 883 | * The application expects to access the specified data once and then not reuse it thereafter. | ||
| 884 | */ | ||
| 885 | #define __WASI_ADVICE_NOREUSE (UINT8_C(5)) | ||
| 886 | |||
| 887 | _Static_assert(sizeof(__wasi_advice_t) == 1, "witx calculated size"); | ||
| 888 | _Static_assert(_Alignof(__wasi_advice_t) == 1, "witx calculated align"); | ||
| 889 | |||
| 890 | /** | ||
| 891 | * File descriptor flags. | ||
| 892 | */ | ||
| 893 | typedef uint16_t __wasi_fdflags_t; | ||
| 894 | |||
| 895 | /** | ||
| 896 | * Append mode: Data written to the file is always appended to the file's end. | ||
| 897 | */ | ||
| 898 | #define __WASI_FDFLAGS_APPEND ((__wasi_fdflags_t)(1 << 0)) | ||
| 899 | |||
| 900 | /** | ||
| 901 | * Write according to synchronized I/O data integrity completion. Only the data stored in the file is synchronized. | ||
| 902 | */ | ||
| 903 | #define __WASI_FDFLAGS_DSYNC ((__wasi_fdflags_t)(1 << 1)) | ||
| 904 | |||
| 905 | /** | ||
| 906 | * Non-blocking mode. | ||
| 907 | */ | ||
| 908 | #define __WASI_FDFLAGS_NONBLOCK ((__wasi_fdflags_t)(1 << 2)) | ||
| 909 | |||
| 910 | /** | ||
| 911 | * Synchronized read I/O operations. | ||
| 912 | */ | ||
| 913 | #define __WASI_FDFLAGS_RSYNC ((__wasi_fdflags_t)(1 << 3)) | ||
| 914 | |||
| 915 | /** | ||
| 916 | * Write according to synchronized I/O file integrity completion. In | ||
| 917 | * addition to synchronizing the data stored in the file, the implementation | ||
| 918 | * may also synchronously update the file's metadata. | ||
| 919 | */ | ||
| 920 | #define __WASI_FDFLAGS_SYNC ((__wasi_fdflags_t)(1 << 4)) | ||
| 921 | |||
| 922 | /** | ||
| 923 | * File descriptor attributes. | ||
| 924 | */ | ||
| 925 | typedef struct __wasi_fdstat_t { | ||
| 926 | /** | ||
| 927 | * File type. | ||
| 928 | */ | ||
| 929 | __wasi_filetype_t fs_filetype; | ||
| 930 | |||
| 931 | /** | ||
| 932 | * File descriptor flags. | ||
| 933 | */ | ||
| 934 | __wasi_fdflags_t fs_flags; | ||
| 935 | |||
| 936 | /** | ||
| 937 | * Rights that apply to this file descriptor. | ||
| 938 | */ | ||
| 939 | __wasi_rights_t fs_rights_base; | ||
| 940 | |||
| 941 | /** | ||
| 942 | * Maximum set of rights that may be installed on new file descriptors that | ||
| 943 | * are created through this file descriptor, e.g., through `path_open`. | ||
| 944 | */ | ||
| 945 | __wasi_rights_t fs_rights_inheriting; | ||
| 946 | |||
| 947 | } __wasi_fdstat_t; | ||
| 948 | |||
| 949 | _Static_assert(sizeof(__wasi_fdstat_t) == 24, "witx calculated size"); | ||
| 950 | _Static_assert(_Alignof(__wasi_fdstat_t) == 8, "witx calculated align"); | ||
| 951 | _Static_assert(offsetof(__wasi_fdstat_t, fs_filetype) == 0, "witx calculated offset"); | ||
| 952 | _Static_assert(offsetof(__wasi_fdstat_t, fs_flags) == 2, "witx calculated offset"); | ||
| 953 | _Static_assert(offsetof(__wasi_fdstat_t, fs_rights_base) == 8, "witx calculated offset"); | ||
| 954 | _Static_assert(offsetof(__wasi_fdstat_t, fs_rights_inheriting) == 16, "witx calculated offset"); | ||
| 955 | |||
| 956 | /** | ||
| 957 | * Identifier for a device containing a file system. Can be used in combination | ||
| 958 | * with `inode` to uniquely identify a file or directory in the filesystem. | ||
| 959 | */ | ||
| 960 | typedef uint64_t __wasi_device_t; | ||
| 961 | |||
| 962 | _Static_assert(sizeof(__wasi_device_t) == 8, "witx calculated size"); | ||
| 963 | _Static_assert(_Alignof(__wasi_device_t) == 8, "witx calculated align"); | ||
| 964 | |||
| 965 | /** | ||
| 966 | * Which file time attributes to adjust. | ||
| 967 | */ | ||
| 968 | typedef uint16_t __wasi_fstflags_t; | ||
| 969 | |||
| 970 | /** | ||
| 971 | * Adjust the last data access timestamp to the value stored in `filestat::atim`. | ||
| 972 | */ | ||
| 973 | #define __WASI_FSTFLAGS_ATIM ((__wasi_fstflags_t)(1 << 0)) | ||
| 974 | |||
| 975 | /** | ||
| 976 | * Adjust the last data access timestamp to the time of clock `clockid::realtime`. | ||
| 977 | */ | ||
| 978 | #define __WASI_FSTFLAGS_ATIM_NOW ((__wasi_fstflags_t)(1 << 1)) | ||
| 979 | |||
| 980 | /** | ||
| 981 | * Adjust the last data modification timestamp to the value stored in `filestat::mtim`. | ||
| 982 | */ | ||
| 983 | #define __WASI_FSTFLAGS_MTIM ((__wasi_fstflags_t)(1 << 2)) | ||
| 984 | |||
| 985 | /** | ||
| 986 | * Adjust the last data modification timestamp to the time of clock `clockid::realtime`. | ||
| 987 | */ | ||
| 988 | #define __WASI_FSTFLAGS_MTIM_NOW ((__wasi_fstflags_t)(1 << 3)) | ||
| 989 | |||
| 990 | /** | ||
| 991 | * Flags determining the method of how paths are resolved. | ||
| 992 | */ | ||
| 993 | typedef uint32_t __wasi_lookupflags_t; | ||
| 994 | |||
| 995 | /** | ||
| 996 | * As long as the resolved path corresponds to a symbolic link, it is expanded. | ||
| 997 | */ | ||
| 998 | #define __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW ((__wasi_lookupflags_t)(1 << 0)) | ||
| 999 | |||
| 1000 | /** | ||
| 1001 | * Open flags used by `path_open`. | ||
| 1002 | */ | ||
| 1003 | typedef uint16_t __wasi_oflags_t; | ||
| 1004 | |||
| 1005 | /** | ||
| 1006 | * Create file if it does not exist. | ||
| 1007 | */ | ||
| 1008 | #define __WASI_OFLAGS_CREAT ((__wasi_oflags_t)(1 << 0)) | ||
| 1009 | |||
| 1010 | /** | ||
| 1011 | * Fail if not a directory. | ||
| 1012 | */ | ||
| 1013 | #define __WASI_OFLAGS_DIRECTORY ((__wasi_oflags_t)(1 << 1)) | ||
| 1014 | |||
| 1015 | /** | ||
| 1016 | * Fail if file already exists. | ||
| 1017 | */ | ||
| 1018 | #define __WASI_OFLAGS_EXCL ((__wasi_oflags_t)(1 << 2)) | ||
| 1019 | |||
| 1020 | /** | ||
| 1021 | * Truncate file to size 0. | ||
| 1022 | */ | ||
| 1023 | #define __WASI_OFLAGS_TRUNC ((__wasi_oflags_t)(1 << 3)) | ||
| 1024 | |||
| 1025 | /** | ||
| 1026 | * Number of hard links to an inode. | ||
| 1027 | */ | ||
| 1028 | typedef uint64_t __wasi_linkcount_t; | ||
| 1029 | |||
| 1030 | _Static_assert(sizeof(__wasi_linkcount_t) == 8, "witx calculated size"); | ||
| 1031 | _Static_assert(_Alignof(__wasi_linkcount_t) == 8, "witx calculated align"); | ||
| 1032 | |||
| 1033 | /** | ||
| 1034 | * File attributes. | ||
| 1035 | */ | ||
| 1036 | typedef struct __wasi_filestat_t { | ||
| 1037 | /** | ||
| 1038 | * Device ID of device containing the file. | ||
| 1039 | */ | ||
| 1040 | __wasi_device_t dev; | ||
| 1041 | |||
| 1042 | /** | ||
| 1043 | * File serial number. | ||
| 1044 | */ | ||
| 1045 | __wasi_inode_t ino; | ||
| 1046 | |||
| 1047 | /** | ||
| 1048 | * File type. | ||
| 1049 | */ | ||
| 1050 | __wasi_filetype_t filetype; | ||
| 1051 | |||
| 1052 | /** | ||
| 1053 | * Number of hard links to the file. | ||
| 1054 | */ | ||
| 1055 | __wasi_linkcount_t nlink; | ||
| 1056 | |||
| 1057 | /** | ||
| 1058 | * For regular files, the file size in bytes. For symbolic links, the length in bytes of the pathname contained in the symbolic link. | ||
| 1059 | */ | ||
| 1060 | __wasi_filesize_t size; | ||
| 1061 | |||
| 1062 | /** | ||
| 1063 | * Last data access timestamp. | ||
| 1064 | */ | ||
| 1065 | __wasi_timestamp_t atim; | ||
| 1066 | |||
| 1067 | /** | ||
| 1068 | * Last data modification timestamp. | ||
| 1069 | */ | ||
| 1070 | __wasi_timestamp_t mtim; | ||
| 1071 | |||
| 1072 | /** | ||
| 1073 | * Last file status change timestamp. | ||
| 1074 | */ | ||
| 1075 | __wasi_timestamp_t ctim; | ||
| 1076 | |||
| 1077 | } __wasi_filestat_t; | ||
| 1078 | |||
| 1079 | _Static_assert(sizeof(__wasi_filestat_t) == 64, "witx calculated size"); | ||
| 1080 | _Static_assert(_Alignof(__wasi_filestat_t) == 8, "witx calculated align"); | ||
| 1081 | _Static_assert(offsetof(__wasi_filestat_t, dev) == 0, "witx calculated offset"); | ||
| 1082 | _Static_assert(offsetof(__wasi_filestat_t, ino) == 8, "witx calculated offset"); | ||
| 1083 | _Static_assert(offsetof(__wasi_filestat_t, filetype) == 16, "witx calculated offset"); | ||
| 1084 | _Static_assert(offsetof(__wasi_filestat_t, nlink) == 24, "witx calculated offset"); | ||
| 1085 | _Static_assert(offsetof(__wasi_filestat_t, size) == 32, "witx calculated offset"); | ||
| 1086 | _Static_assert(offsetof(__wasi_filestat_t, atim) == 40, "witx calculated offset"); | ||
| 1087 | _Static_assert(offsetof(__wasi_filestat_t, mtim) == 48, "witx calculated offset"); | ||
| 1088 | _Static_assert(offsetof(__wasi_filestat_t, ctim) == 56, "witx calculated offset"); | ||
| 1089 | |||
| 1090 | /** | ||
| 1091 | * User-provided value that may be attached to objects that is retained when | ||
| 1092 | * extracted from the implementation. | ||
| 1093 | */ | ||
| 1094 | typedef uint64_t __wasi_userdata_t; | ||
| 1095 | |||
| 1096 | _Static_assert(sizeof(__wasi_userdata_t) == 8, "witx calculated size"); | ||
| 1097 | _Static_assert(_Alignof(__wasi_userdata_t) == 8, "witx calculated align"); | ||
| 1098 | |||
| 1099 | /** | ||
| 1100 | * Type of a subscription to an event or its occurrence. | ||
| 1101 | */ | ||
| 1102 | typedef uint8_t __wasi_eventtype_t; | ||
| 1103 | |||
| 1104 | /** | ||
| 1105 | * The time value of clock `subscription_clock::id` has | ||
| 1106 | * reached timestamp `subscription_clock::timeout`. | ||
| 1107 | */ | ||
| 1108 | #define __WASI_EVENTTYPE_CLOCK (UINT8_C(0)) | ||
| 1109 | |||
| 1110 | /** | ||
| 1111 | * File descriptor `subscription_fd_readwrite::file_descriptor` has data | ||
| 1112 | * available for reading. This event always triggers for regular files. | ||
| 1113 | */ | ||
| 1114 | #define __WASI_EVENTTYPE_FD_READ (UINT8_C(1)) | ||
| 1115 | |||
| 1116 | /** | ||
| 1117 | * File descriptor `subscription_fd_readwrite::file_descriptor` has capacity | ||
| 1118 | * available for writing. This event always triggers for regular files. | ||
| 1119 | */ | ||
| 1120 | #define __WASI_EVENTTYPE_FD_WRITE (UINT8_C(2)) | ||
| 1121 | |||
| 1122 | _Static_assert(sizeof(__wasi_eventtype_t) == 1, "witx calculated size"); | ||
| 1123 | _Static_assert(_Alignof(__wasi_eventtype_t) == 1, "witx calculated align"); | ||
| 1124 | |||
| 1125 | /** | ||
| 1126 | * The state of the file descriptor subscribed to with | ||
| 1127 | * `eventtype::fd_read` or `eventtype::fd_write`. | ||
| 1128 | */ | ||
| 1129 | typedef uint16_t __wasi_eventrwflags_t; | ||
| 1130 | |||
| 1131 | /** | ||
| 1132 | * The peer of this socket has closed or disconnected. | ||
| 1133 | */ | ||
| 1134 | #define __WASI_EVENTRWFLAGS_FD_READWRITE_HANGUP ((__wasi_eventrwflags_t)(1 << 0)) | ||
| 1135 | |||
| 1136 | /** | ||
| 1137 | * The contents of an `event` when type is `eventtype::fd_read` or | ||
| 1138 | * `eventtype::fd_write`. | ||
| 1139 | */ | ||
| 1140 | typedef struct __wasi_event_fd_readwrite_t { | ||
| 1141 | /** | ||
| 1142 | * The number of bytes available for reading or writing. | ||
| 1143 | */ | ||
| 1144 | __wasi_filesize_t nbytes; | ||
| 1145 | |||
| 1146 | /** | ||
| 1147 | * The state of the file descriptor. | ||
| 1148 | */ | ||
| 1149 | __wasi_eventrwflags_t flags; | ||
| 1150 | |||
| 1151 | } __wasi_event_fd_readwrite_t; | ||
| 1152 | |||
| 1153 | _Static_assert(sizeof(__wasi_event_fd_readwrite_t) == 16, "witx calculated size"); | ||
| 1154 | _Static_assert(_Alignof(__wasi_event_fd_readwrite_t) == 8, "witx calculated align"); | ||
| 1155 | _Static_assert(offsetof(__wasi_event_fd_readwrite_t, nbytes) == 0, "witx calculated offset"); | ||
| 1156 | _Static_assert(offsetof(__wasi_event_fd_readwrite_t, flags) == 8, "witx calculated offset"); | ||
| 1157 | |||
| 1158 | /** | ||
| 1159 | * An event that occurred. | ||
| 1160 | */ | ||
| 1161 | typedef struct __wasi_event_t { | ||
| 1162 | /** | ||
| 1163 | * User-provided value that got attached to `subscription::userdata`. | ||
| 1164 | */ | ||
| 1165 | __wasi_userdata_t userdata; | ||
| 1166 | |||
| 1167 | /** | ||
| 1168 | * If non-zero, an error that occurred while processing the subscription request. | ||
| 1169 | */ | ||
| 1170 | __wasi_errno_t error; | ||
| 1171 | |||
| 1172 | /** | ||
| 1173 | * The type of event that occured | ||
| 1174 | */ | ||
| 1175 | __wasi_eventtype_t type; | ||
| 1176 | |||
| 1177 | /** | ||
| 1178 | * The contents of the event, if it is an `eventtype::fd_read` or | ||
| 1179 | * `eventtype::fd_write`. `eventtype::clock` events ignore this field. | ||
| 1180 | */ | ||
| 1181 | __wasi_event_fd_readwrite_t fd_readwrite; | ||
| 1182 | |||
| 1183 | } __wasi_event_t; | ||
| 1184 | |||
| 1185 | _Static_assert(sizeof(__wasi_event_t) == 32, "witx calculated size"); | ||
| 1186 | _Static_assert(_Alignof(__wasi_event_t) == 8, "witx calculated align"); | ||
| 1187 | _Static_assert(offsetof(__wasi_event_t, userdata) == 0, "witx calculated offset"); | ||
| 1188 | _Static_assert(offsetof(__wasi_event_t, error) == 8, "witx calculated offset"); | ||
| 1189 | _Static_assert(offsetof(__wasi_event_t, type) == 10, "witx calculated offset"); | ||
| 1190 | _Static_assert(offsetof(__wasi_event_t, fd_readwrite) == 16, "witx calculated offset"); | ||
| 1191 | |||
| 1192 | /** | ||
| 1193 | * Flags determining how to interpret the timestamp provided in | ||
| 1194 | * `subscription_clock::timeout`. | ||
| 1195 | */ | ||
| 1196 | typedef uint16_t __wasi_subclockflags_t; | ||
| 1197 | |||
| 1198 | /** | ||
| 1199 | * If set, treat the timestamp provided in | ||
| 1200 | * `subscription_clock::timeout` as an absolute timestamp of clock | ||
| 1201 | * `subscription_clock::id`. If clear, treat the timestamp | ||
| 1202 | * provided in `subscription_clock::timeout` relative to the | ||
| 1203 | * current time value of clock `subscription_clock::id`. | ||
| 1204 | */ | ||
| 1205 | #define __WASI_SUBCLOCKFLAGS_SUBSCRIPTION_CLOCK_ABSTIME ((__wasi_subclockflags_t)(1 << 0)) | ||
| 1206 | |||
| 1207 | /** | ||
| 1208 | * The contents of a `subscription` when type is `eventtype::clock`. | ||
| 1209 | */ | ||
| 1210 | typedef struct __wasi_subscription_clock_t { | ||
| 1211 | /** | ||
| 1212 | * The clock against which to compare the timestamp. | ||
| 1213 | */ | ||
| 1214 | __wasi_clockid_t id; | ||
| 1215 | |||
| 1216 | /** | ||
| 1217 | * The absolute or relative timestamp. | ||
| 1218 | */ | ||
| 1219 | __wasi_timestamp_t timeout; | ||
| 1220 | |||
| 1221 | /** | ||
| 1222 | * The amount of time that the implementation may wait additionally | ||
| 1223 | * to coalesce with other events. | ||
| 1224 | */ | ||
| 1225 | __wasi_timestamp_t precision; | ||
| 1226 | |||
| 1227 | /** | ||
| 1228 | * Flags specifying whether the timeout is absolute or relative | ||
| 1229 | */ | ||
| 1230 | __wasi_subclockflags_t flags; | ||
| 1231 | |||
| 1232 | } __wasi_subscription_clock_t; | ||
| 1233 | |||
| 1234 | _Static_assert(sizeof(__wasi_subscription_clock_t) == 32, "witx calculated size"); | ||
| 1235 | _Static_assert(_Alignof(__wasi_subscription_clock_t) == 8, "witx calculated align"); | ||
| 1236 | _Static_assert(offsetof(__wasi_subscription_clock_t, id) == 0, "witx calculated offset"); | ||
| 1237 | _Static_assert(offsetof(__wasi_subscription_clock_t, timeout) == 8, "witx calculated offset"); | ||
| 1238 | _Static_assert(offsetof(__wasi_subscription_clock_t, precision) == 16, "witx calculated offset"); | ||
| 1239 | _Static_assert(offsetof(__wasi_subscription_clock_t, flags) == 24, "witx calculated offset"); | ||
| 1240 | |||
| 1241 | /** | ||
| 1242 | * The contents of a `subscription` when type is type is | ||
| 1243 | * `eventtype::fd_read` or `eventtype::fd_write`. | ||
| 1244 | */ | ||
| 1245 | typedef struct __wasi_subscription_fd_readwrite_t { | ||
| 1246 | /** | ||
| 1247 | * The file descriptor on which to wait for it to become ready for reading or writing. | ||
| 1248 | */ | ||
| 1249 | __wasi_fd_t file_descriptor; | ||
| 1250 | |||
| 1251 | } __wasi_subscription_fd_readwrite_t; | ||
| 1252 | |||
| 1253 | _Static_assert(sizeof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated size"); | ||
| 1254 | _Static_assert(_Alignof(__wasi_subscription_fd_readwrite_t) == 4, "witx calculated align"); | ||
| 1255 | _Static_assert(offsetof(__wasi_subscription_fd_readwrite_t, file_descriptor) == 0, "witx calculated offset"); | ||
| 1256 | |||
| 1257 | /** | ||
| 1258 | * The contents of a `subscription`. | ||
| 1259 | */ | ||
| 1260 | typedef union __wasi_subscription_u_u_t { | ||
| 1261 | __wasi_subscription_clock_t clock; | ||
| 1262 | __wasi_subscription_fd_readwrite_t fd_read; | ||
| 1263 | __wasi_subscription_fd_readwrite_t fd_write; | ||
| 1264 | } __wasi_subscription_u_u_t; | ||
| 1265 | typedef struct __wasi_subscription_u_t { | ||
| 1266 | uint8_t tag; | ||
| 1267 | __wasi_subscription_u_u_t u; | ||
| 1268 | } __wasi_subscription_u_t; | ||
| 1269 | |||
| 1270 | _Static_assert(sizeof(__wasi_subscription_u_t) == 40, "witx calculated size"); | ||
| 1271 | _Static_assert(_Alignof(__wasi_subscription_u_t) == 8, "witx calculated align"); | ||
| 1272 | |||
| 1273 | /** | ||
| 1274 | * Subscription to an event. | ||
| 1275 | */ | ||
| 1276 | typedef struct __wasi_subscription_t { | ||
| 1277 | /** | ||
| 1278 | * User-provided value that is attached to the subscription in the | ||
| 1279 | * implementation and returned through `event::userdata`. | ||
| 1280 | */ | ||
| 1281 | __wasi_userdata_t userdata; | ||
| 1282 | |||
| 1283 | /** | ||
| 1284 | * The type of the event to which to subscribe, and its contents | ||
| 1285 | */ | ||
| 1286 | __wasi_subscription_u_t u; | ||
| 1287 | |||
| 1288 | } __wasi_subscription_t; | ||
| 1289 | |||
| 1290 | _Static_assert(sizeof(__wasi_subscription_t) == 48, "witx calculated size"); | ||
| 1291 | _Static_assert(_Alignof(__wasi_subscription_t) == 8, "witx calculated align"); | ||
| 1292 | _Static_assert(offsetof(__wasi_subscription_t, userdata) == 0, "witx calculated offset"); | ||
| 1293 | _Static_assert(offsetof(__wasi_subscription_t, u) == 8, "witx calculated offset"); | ||
| 1294 | |||
| 1295 | /** | ||
| 1296 | * Exit code generated by a process when exiting. | ||
| 1297 | */ | ||
| 1298 | typedef uint32_t __wasi_exitcode_t; | ||
| 1299 | |||
| 1300 | _Static_assert(sizeof(__wasi_exitcode_t) == 4, "witx calculated size"); | ||
| 1301 | _Static_assert(_Alignof(__wasi_exitcode_t) == 4, "witx calculated align"); | ||
| 1302 | |||
| 1303 | /** | ||
| 1304 | * Signal condition. | ||
| 1305 | */ | ||
| 1306 | typedef uint8_t __wasi_signal_t; | ||
| 1307 | |||
| 1308 | /** | ||
| 1309 | * No signal. Note that POSIX has special semantics for `kill(pid, 0)`, | ||
| 1310 | * so this value is reserved. | ||
| 1311 | */ | ||
| 1312 | #define __WASI_SIGNAL_NONE (UINT8_C(0)) | ||
| 1313 | |||
| 1314 | /** | ||
| 1315 | * Hangup. | ||
| 1316 | * Action: Terminates the process. | ||
| 1317 | */ | ||
| 1318 | #define __WASI_SIGNAL_HUP (UINT8_C(1)) | ||
| 1319 | |||
| 1320 | /** | ||
| 1321 | * Terminate interrupt signal. | ||
| 1322 | * Action: Terminates the process. | ||
| 1323 | */ | ||
| 1324 | #define __WASI_SIGNAL_INT (UINT8_C(2)) | ||
| 1325 | |||
| 1326 | /** | ||
| 1327 | * Terminal quit signal. | ||
| 1328 | * Action: Terminates the process. | ||
| 1329 | */ | ||
| 1330 | #define __WASI_SIGNAL_QUIT (UINT8_C(3)) | ||
| 1331 | |||
| 1332 | /** | ||
| 1333 | * Illegal instruction. | ||
| 1334 | * Action: Terminates the process. | ||
| 1335 | */ | ||
| 1336 | #define __WASI_SIGNAL_ILL (UINT8_C(4)) | ||
| 1337 | |||
| 1338 | /** | ||
| 1339 | * Trace/breakpoint trap. | ||
| 1340 | * Action: Terminates the process. | ||
| 1341 | */ | ||
| 1342 | #define __WASI_SIGNAL_TRAP (UINT8_C(5)) | ||
| 1343 | |||
| 1344 | /** | ||
| 1345 | * Process abort signal. | ||
| 1346 | * Action: Terminates the process. | ||
| 1347 | */ | ||
| 1348 | #define __WASI_SIGNAL_ABRT (UINT8_C(6)) | ||
| 1349 | |||
| 1350 | /** | ||
| 1351 | * Access to an undefined portion of a memory object. | ||
| 1352 | * Action: Terminates the process. | ||
| 1353 | */ | ||
| 1354 | #define __WASI_SIGNAL_BUS (UINT8_C(7)) | ||
| 1355 | |||
| 1356 | /** | ||
| 1357 | * Erroneous arithmetic operation. | ||
| 1358 | * Action: Terminates the process. | ||
| 1359 | */ | ||
| 1360 | #define __WASI_SIGNAL_FPE (UINT8_C(8)) | ||
| 1361 | |||
| 1362 | /** | ||
| 1363 | * Kill. | ||
| 1364 | * Action: Terminates the process. | ||
| 1365 | */ | ||
| 1366 | #define __WASI_SIGNAL_KILL (UINT8_C(9)) | ||
| 1367 | |||
| 1368 | /** | ||
| 1369 | * User-defined signal 1. | ||
| 1370 | * Action: Terminates the process. | ||
| 1371 | */ | ||
| 1372 | #define __WASI_SIGNAL_USR1 (UINT8_C(10)) | ||
| 1373 | |||
| 1374 | /** | ||
| 1375 | * Invalid memory reference. | ||
| 1376 | * Action: Terminates the process. | ||
| 1377 | */ | ||
| 1378 | #define __WASI_SIGNAL_SEGV (UINT8_C(11)) | ||
| 1379 | |||
| 1380 | /** | ||
| 1381 | * User-defined signal 2. | ||
| 1382 | * Action: Terminates the process. | ||
| 1383 | */ | ||
| 1384 | #define __WASI_SIGNAL_USR2 (UINT8_C(12)) | ||
| 1385 | |||
| 1386 | /** | ||
| 1387 | * Write on a pipe with no one to read it. | ||
| 1388 | * Action: Ignored. | ||
| 1389 | */ | ||
| 1390 | #define __WASI_SIGNAL_PIPE (UINT8_C(13)) | ||
| 1391 | |||
| 1392 | /** | ||
| 1393 | * Alarm clock. | ||
| 1394 | * Action: Terminates the process. | ||
| 1395 | */ | ||
| 1396 | #define __WASI_SIGNAL_ALRM (UINT8_C(14)) | ||
| 1397 | |||
| 1398 | /** | ||
| 1399 | * Termination signal. | ||
| 1400 | * Action: Terminates the process. | ||
| 1401 | */ | ||
| 1402 | #define __WASI_SIGNAL_TERM (UINT8_C(15)) | ||
| 1403 | |||
| 1404 | /** | ||
| 1405 | * Child process terminated, stopped, or continued. | ||
| 1406 | * Action: Ignored. | ||
| 1407 | */ | ||
| 1408 | #define __WASI_SIGNAL_CHLD (UINT8_C(16)) | ||
| 1409 | |||
| 1410 | /** | ||
| 1411 | * Continue executing, if stopped. | ||
| 1412 | * Action: Continues executing, if stopped. | ||
| 1413 | */ | ||
| 1414 | #define __WASI_SIGNAL_CONT (UINT8_C(17)) | ||
| 1415 | |||
| 1416 | /** | ||
| 1417 | * Stop executing. | ||
| 1418 | * Action: Stops executing. | ||
| 1419 | */ | ||
| 1420 | #define __WASI_SIGNAL_STOP (UINT8_C(18)) | ||
| 1421 | |||
| 1422 | /** | ||
| 1423 | * Terminal stop signal. | ||
| 1424 | * Action: Stops executing. | ||
| 1425 | */ | ||
| 1426 | #define __WASI_SIGNAL_TSTP (UINT8_C(19)) | ||
| 1427 | |||
| 1428 | /** | ||
| 1429 | * Background process attempting read. | ||
| 1430 | * Action: Stops executing. | ||
| 1431 | */ | ||
| 1432 | #define __WASI_SIGNAL_TTIN (UINT8_C(20)) | ||
| 1433 | |||
| 1434 | /** | ||
| 1435 | * Background process attempting write. | ||
| 1436 | * Action: Stops executing. | ||
| 1437 | */ | ||
| 1438 | #define __WASI_SIGNAL_TTOU (UINT8_C(21)) | ||
| 1439 | |||
| 1440 | /** | ||
| 1441 | * High bandwidth data is available at a socket. | ||
| 1442 | * Action: Ignored. | ||
| 1443 | */ | ||
| 1444 | #define __WASI_SIGNAL_URG (UINT8_C(22)) | ||
| 1445 | |||
| 1446 | /** | ||
| 1447 | * CPU time limit exceeded. | ||
| 1448 | * Action: Terminates the process. | ||
| 1449 | */ | ||
| 1450 | #define __WASI_SIGNAL_XCPU (UINT8_C(23)) | ||
| 1451 | |||
| 1452 | /** | ||
| 1453 | * File size limit exceeded. | ||
| 1454 | * Action: Terminates the process. | ||
| 1455 | */ | ||
| 1456 | #define __WASI_SIGNAL_XFSZ (UINT8_C(24)) | ||
| 1457 | |||
| 1458 | /** | ||
| 1459 | * Virtual timer expired. | ||
| 1460 | * Action: Terminates the process. | ||
| 1461 | */ | ||
| 1462 | #define __WASI_SIGNAL_VTALRM (UINT8_C(25)) | ||
| 1463 | |||
| 1464 | /** | ||
| 1465 | * Profiling timer expired. | ||
| 1466 | * Action: Terminates the process. | ||
| 1467 | */ | ||
| 1468 | #define __WASI_SIGNAL_PROF (UINT8_C(26)) | ||
| 1469 | |||
| 1470 | /** | ||
| 1471 | * Window changed. | ||
| 1472 | * Action: Ignored. | ||
| 1473 | */ | ||
| 1474 | #define __WASI_SIGNAL_WINCH (UINT8_C(27)) | ||
| 1475 | |||
| 1476 | /** | ||
| 1477 | * I/O possible. | ||
| 1478 | * Action: Terminates the process. | ||
| 1479 | */ | ||
| 1480 | #define __WASI_SIGNAL_POLL (UINT8_C(28)) | ||
| 1481 | |||
| 1482 | /** | ||
| 1483 | * Power failure. | ||
| 1484 | * Action: Terminates the process. | ||
| 1485 | */ | ||
| 1486 | #define __WASI_SIGNAL_PWR (UINT8_C(29)) | ||
| 1487 | |||
| 1488 | /** | ||
| 1489 | * Bad system call. | ||
| 1490 | * Action: Terminates the process. | ||
| 1491 | */ | ||
| 1492 | #define __WASI_SIGNAL_SYS (UINT8_C(30)) | ||
| 1493 | |||
| 1494 | _Static_assert(sizeof(__wasi_signal_t) == 1, "witx calculated size"); | ||
| 1495 | _Static_assert(_Alignof(__wasi_signal_t) == 1, "witx calculated align"); | ||
| 1496 | |||
| 1497 | /** | ||
| 1498 | * Flags provided to `sock_recv`. | ||
| 1499 | */ | ||
| 1500 | typedef uint16_t __wasi_riflags_t; | ||
| 1501 | |||
| 1502 | /** | ||
| 1503 | * Returns the message without removing it from the socket's receive queue. | ||
| 1504 | */ | ||
| 1505 | #define __WASI_RIFLAGS_RECV_PEEK ((__wasi_riflags_t)(1 << 0)) | ||
| 1506 | |||
| 1507 | /** | ||
| 1508 | * On byte-stream sockets, block until the full amount of data can be returned. | ||
| 1509 | */ | ||
| 1510 | #define __WASI_RIFLAGS_RECV_WAITALL ((__wasi_riflags_t)(1 << 1)) | ||
| 1511 | |||
| 1512 | /** | ||
| 1513 | * Flags returned by `sock_recv`. | ||
| 1514 | */ | ||
| 1515 | typedef uint16_t __wasi_roflags_t; | ||
| 1516 | |||
| 1517 | /** | ||
| 1518 | * Returned by `sock_recv`: Message data has been truncated. | ||
| 1519 | */ | ||
| 1520 | #define __WASI_ROFLAGS_RECV_DATA_TRUNCATED ((__wasi_roflags_t)(1 << 0)) | ||
| 1521 | |||
| 1522 | /** | ||
| 1523 | * Flags provided to `sock_send`. As there are currently no flags | ||
| 1524 | * defined, it must be set to zero. | ||
| 1525 | */ | ||
| 1526 | typedef uint16_t __wasi_siflags_t; | ||
| 1527 | |||
| 1528 | _Static_assert(sizeof(__wasi_siflags_t) == 2, "witx calculated size"); | ||
| 1529 | _Static_assert(_Alignof(__wasi_siflags_t) == 2, "witx calculated align"); | ||
| 1530 | |||
| 1531 | /** | ||
| 1532 | * Which channels on a socket to shut down. | ||
| 1533 | */ | ||
| 1534 | typedef uint8_t __wasi_sdflags_t; | ||
| 1535 | |||
| 1536 | /** | ||
| 1537 | * Disables further receive operations. | ||
| 1538 | */ | ||
| 1539 | #define __WASI_SDFLAGS_RD ((__wasi_sdflags_t)(1 << 0)) | ||
| 1540 | |||
| 1541 | /** | ||
| 1542 | * Disables further send operations. | ||
| 1543 | */ | ||
| 1544 | #define __WASI_SDFLAGS_WR ((__wasi_sdflags_t)(1 << 1)) | ||
| 1545 | |||
| 1546 | /** | ||
| 1547 | * Identifiers for preopened capabilities. | ||
| 1548 | */ | ||
| 1549 | typedef uint8_t __wasi_preopentype_t; | ||
| 1550 | |||
| 1551 | /** | ||
| 1552 | * A pre-opened directory. | ||
| 1553 | */ | ||
| 1554 | #define __WASI_PREOPENTYPE_DIR (UINT8_C(0)) | ||
| 1555 | |||
| 1556 | _Static_assert(sizeof(__wasi_preopentype_t) == 1, "witx calculated size"); | ||
| 1557 | _Static_assert(_Alignof(__wasi_preopentype_t) == 1, "witx calculated align"); | ||
| 1558 | |||
| 1559 | /** | ||
| 1560 | * The contents of a $prestat when type is `preopentype::dir`. | ||
| 1561 | */ | ||
| 1562 | typedef struct __wasi_prestat_dir_t { | ||
| 1563 | /** | ||
| 1564 | * The length of the directory name for use with `fd_prestat_dir_name`. | ||
| 1565 | */ | ||
| 1566 | __wasi_size_t pr_name_len; | ||
| 1567 | |||
| 1568 | } __wasi_prestat_dir_t; | ||
| 1569 | |||
| 1570 | _Static_assert(sizeof(__wasi_prestat_dir_t) == 4, "witx calculated size"); | ||
| 1571 | _Static_assert(_Alignof(__wasi_prestat_dir_t) == 4, "witx calculated align"); | ||
| 1572 | _Static_assert(offsetof(__wasi_prestat_dir_t, pr_name_len) == 0, "witx calculated offset"); | ||
| 1573 | |||
| 1574 | /** | ||
| 1575 | * Information about a pre-opened capability. | ||
| 1576 | */ | ||
| 1577 | typedef union __wasi_prestat_u_t { | ||
| 1578 | __wasi_prestat_dir_t dir; | ||
| 1579 | } __wasi_prestat_u_t; | ||
| 1580 | typedef struct __wasi_prestat_t { | ||
| 1581 | uint8_t tag; | ||
| 1582 | __wasi_prestat_u_t u; | ||
| 1583 | } __wasi_prestat_t; | ||
| 1584 | |||
| 1585 | _Static_assert(sizeof(__wasi_prestat_t) == 8, "witx calculated size"); | ||
| 1586 | _Static_assert(_Alignof(__wasi_prestat_t) == 4, "witx calculated align"); | ||
| 1587 | |||
| 1588 | /** | ||
| 1589 | * @defgroup wasi_snapshot_preview1 | ||
| 1590 | * @{ | ||
| 1591 | */ | ||
| 1592 | |||
| 1593 | /** | ||
| 1594 | * Read command-line argument data. | ||
| 1595 | * The size of the array should match that returned by `args_sizes_get` | ||
| 1596 | */ | ||
| 1597 | __wasi_errno_t __wasi_args_get( | ||
| 1598 | uint8_t * * argv, | ||
| 1599 | uint8_t * argv_buf | ||
| 1600 | ) __attribute__((__warn_unused_result__)); | ||
| 1601 | /** | ||
| 1602 | * Return command-line argument data sizes. | ||
| 1603 | * @return | ||
| 1604 | * Returns the number of arguments and the size of the argument string | ||
| 1605 | * data, or an error. | ||
| 1606 | */ | ||
| 1607 | __wasi_errno_t __wasi_args_sizes_get( | ||
| 1608 | __wasi_size_t *retptr0, | ||
| 1609 | __wasi_size_t *retptr1 | ||
| 1610 | ) __attribute__((__warn_unused_result__)); | ||
| 1611 | /** | ||
| 1612 | * Read environment variable data. | ||
| 1613 | * The sizes of the buffers should match that returned by `environ_sizes_get`. | ||
| 1614 | */ | ||
| 1615 | __wasi_errno_t __wasi_environ_get( | ||
| 1616 | uint8_t * * environ, | ||
| 1617 | uint8_t * environ_buf | ||
| 1618 | ) __attribute__((__warn_unused_result__)); | ||
| 1619 | /** | ||
| 1620 | * Return environment variable data sizes. | ||
| 1621 | * @return | ||
| 1622 | * Returns the number of environment variable arguments and the size of the | ||
| 1623 | * environment variable data. | ||
| 1624 | */ | ||
| 1625 | __wasi_errno_t __wasi_environ_sizes_get( | ||
| 1626 | __wasi_size_t *retptr0, | ||
| 1627 | __wasi_size_t *retptr1 | ||
| 1628 | ) __attribute__((__warn_unused_result__)); | ||
| 1629 | /** | ||
| 1630 | * Return the resolution of a clock. | ||
| 1631 | * Implementations are required to provide a non-zero value for supported clocks. For unsupported clocks, | ||
| 1632 | * return `errno::inval`. | ||
| 1633 | * Note: This is similar to `clock_getres` in POSIX. | ||
| 1634 | * @return | ||
| 1635 | * The resolution of the clock, or an error if one happened. | ||
| 1636 | */ | ||
| 1637 | __wasi_errno_t __wasi_clock_res_get( | ||
| 1638 | /** | ||
| 1639 | * The clock for which to return the resolution. | ||
| 1640 | */ | ||
| 1641 | __wasi_clockid_t id, | ||
| 1642 | __wasi_timestamp_t *retptr0 | ||
| 1643 | ) __attribute__((__warn_unused_result__)); | ||
| 1644 | /** | ||
| 1645 | * Return the time value of a clock. | ||
| 1646 | * Note: This is similar to `clock_gettime` in POSIX. | ||
| 1647 | * @return | ||
| 1648 | * The time value of the clock. | ||
| 1649 | */ | ||
| 1650 | __wasi_errno_t __wasi_clock_time_get( | ||
| 1651 | /** | ||
| 1652 | * The clock for which to return the time. | ||
| 1653 | */ | ||
| 1654 | __wasi_clockid_t id, | ||
| 1655 | /** | ||
| 1656 | * The maximum lag (exclusive) that the returned time value may have, compared to its actual value. | ||
| 1657 | */ | ||
| 1658 | __wasi_timestamp_t precision, | ||
| 1659 | __wasi_timestamp_t *retptr0 | ||
| 1660 | ) __attribute__((__warn_unused_result__)); | ||
| 1661 | /** | ||
| 1662 | * Provide file advisory information on a file descriptor. | ||
| 1663 | * Note: This is similar to `posix_fadvise` in POSIX. | ||
| 1664 | */ | ||
| 1665 | __wasi_errno_t __wasi_fd_advise( | ||
| 1666 | __wasi_fd_t fd, | ||
| 1667 | /** | ||
| 1668 | * The offset within the file to which the advisory applies. | ||
| 1669 | */ | ||
| 1670 | __wasi_filesize_t offset, | ||
| 1671 | /** | ||
| 1672 | * The length of the region to which the advisory applies. | ||
| 1673 | */ | ||
| 1674 | __wasi_filesize_t len, | ||
| 1675 | /** | ||
| 1676 | * The advice. | ||
| 1677 | */ | ||
| 1678 | __wasi_advice_t advice | ||
| 1679 | ) __attribute__((__warn_unused_result__)); | ||
| 1680 | /** | ||
| 1681 | * Force the allocation of space in a file. | ||
| 1682 | * Note: This is similar to `posix_fallocate` in POSIX. | ||
| 1683 | */ | ||
| 1684 | __wasi_errno_t __wasi_fd_allocate( | ||
| 1685 | __wasi_fd_t fd, | ||
| 1686 | /** | ||
| 1687 | * The offset at which to start the allocation. | ||
| 1688 | */ | ||
| 1689 | __wasi_filesize_t offset, | ||
| 1690 | /** | ||
| 1691 | * The length of the area that is allocated. | ||
| 1692 | */ | ||
| 1693 | __wasi_filesize_t len | ||
| 1694 | ) __attribute__((__warn_unused_result__)); | ||
| 1695 | /** | ||
| 1696 | * Close a file descriptor. | ||
| 1697 | * Note: This is similar to `close` in POSIX. | ||
| 1698 | */ | ||
| 1699 | __wasi_errno_t __wasi_fd_close( | ||
| 1700 | __wasi_fd_t fd | ||
| 1701 | ) __attribute__((__warn_unused_result__)); | ||
| 1702 | /** | ||
| 1703 | * Synchronize the data of a file to disk. | ||
| 1704 | * Note: This is similar to `fdatasync` in POSIX. | ||
| 1705 | */ | ||
| 1706 | __wasi_errno_t __wasi_fd_datasync( | ||
| 1707 | __wasi_fd_t fd | ||
| 1708 | ) __attribute__((__warn_unused_result__)); | ||
| 1709 | /** | ||
| 1710 | * Get the attributes of a file descriptor. | ||
| 1711 | * Note: This returns similar flags to `fsync(fd, F_GETFL)` in POSIX, as well as additional fields. | ||
| 1712 | * @return | ||
| 1713 | * The buffer where the file descriptor's attributes are stored. | ||
| 1714 | */ | ||
| 1715 | __wasi_errno_t __wasi_fd_fdstat_get( | ||
| 1716 | __wasi_fd_t fd, | ||
| 1717 | __wasi_fdstat_t *retptr0 | ||
| 1718 | ) __attribute__((__warn_unused_result__)); | ||
| 1719 | /** | ||
| 1720 | * Adjust the flags associated with a file descriptor. | ||
| 1721 | * Note: This is similar to `fcntl(fd, F_SETFL, flags)` in POSIX. | ||
| 1722 | */ | ||
| 1723 | __wasi_errno_t __wasi_fd_fdstat_set_flags( | ||
| 1724 | __wasi_fd_t fd, | ||
| 1725 | /** | ||
| 1726 | * The desired values of the file descriptor flags. | ||
| 1727 | */ | ||
| 1728 | __wasi_fdflags_t flags | ||
| 1729 | ) __attribute__((__warn_unused_result__)); | ||
| 1730 | /** | ||
| 1731 | * Adjust the rights associated with a file descriptor. | ||
| 1732 | * This can only be used to remove rights, and returns `errno::notcapable` if called in a way that would attempt to add rights | ||
| 1733 | */ | ||
| 1734 | __wasi_errno_t __wasi_fd_fdstat_set_rights( | ||
| 1735 | __wasi_fd_t fd, | ||
| 1736 | /** | ||
| 1737 | * The desired rights of the file descriptor. | ||
| 1738 | */ | ||
| 1739 | __wasi_rights_t fs_rights_base, | ||
| 1740 | __wasi_rights_t fs_rights_inheriting | ||
| 1741 | ) __attribute__((__warn_unused_result__)); | ||
| 1742 | /** | ||
| 1743 | * Return the attributes of an open file. | ||
| 1744 | * @return | ||
| 1745 | * The buffer where the file's attributes are stored. | ||
| 1746 | */ | ||
| 1747 | __wasi_errno_t __wasi_fd_filestat_get( | ||
| 1748 | __wasi_fd_t fd, | ||
| 1749 | __wasi_filestat_t *retptr0 | ||
| 1750 | ) __attribute__((__warn_unused_result__)); | ||
| 1751 | /** | ||
| 1752 | * Adjust the size of an open file. If this increases the file's size, the extra bytes are filled with zeros. | ||
| 1753 | * Note: This is similar to `ftruncate` in POSIX. | ||
| 1754 | */ | ||
| 1755 | __wasi_errno_t __wasi_fd_filestat_set_size( | ||
| 1756 | __wasi_fd_t fd, | ||
| 1757 | /** | ||
| 1758 | * The desired file size. | ||
| 1759 | */ | ||
| 1760 | __wasi_filesize_t size | ||
| 1761 | ) __attribute__((__warn_unused_result__)); | ||
| 1762 | /** | ||
| 1763 | * Adjust the timestamps of an open file or directory. | ||
| 1764 | * Note: This is similar to `futimens` in POSIX. | ||
| 1765 | */ | ||
| 1766 | __wasi_errno_t __wasi_fd_filestat_set_times( | ||
| 1767 | __wasi_fd_t fd, | ||
| 1768 | /** | ||
| 1769 | * The desired values of the data access timestamp. | ||
| 1770 | */ | ||
| 1771 | __wasi_timestamp_t atim, | ||
| 1772 | /** | ||
| 1773 | * The desired values of the data modification timestamp. | ||
| 1774 | */ | ||
| 1775 | __wasi_timestamp_t mtim, | ||
| 1776 | /** | ||
| 1777 | * A bitmask indicating which timestamps to adjust. | ||
| 1778 | */ | ||
| 1779 | __wasi_fstflags_t fst_flags | ||
| 1780 | ) __attribute__((__warn_unused_result__)); | ||
| 1781 | /** | ||
| 1782 | * Read from a file descriptor, without using and updating the file descriptor's offset. | ||
| 1783 | * Note: This is similar to `preadv` in POSIX. | ||
| 1784 | * @return | ||
| 1785 | * The number of bytes read. | ||
| 1786 | */ | ||
| 1787 | __wasi_errno_t __wasi_fd_pread( | ||
| 1788 | __wasi_fd_t fd, | ||
| 1789 | /** | ||
| 1790 | * List of scatter/gather vectors in which to store data. | ||
| 1791 | */ | ||
| 1792 | const __wasi_iovec_t *iovs, | ||
| 1793 | /** | ||
| 1794 | * The length of the array pointed to by `iovs`. | ||
| 1795 | */ | ||
| 1796 | size_t iovs_len, | ||
| 1797 | /** | ||
| 1798 | * The offset within the file at which to read. | ||
| 1799 | */ | ||
| 1800 | __wasi_filesize_t offset, | ||
| 1801 | __wasi_size_t *retptr0 | ||
| 1802 | ) __attribute__((__warn_unused_result__)); | ||
| 1803 | /** | ||
| 1804 | * Return a description of the given preopened file descriptor. | ||
| 1805 | * @return | ||
| 1806 | * The buffer where the description is stored. | ||
| 1807 | */ | ||
| 1808 | __wasi_errno_t __wasi_fd_prestat_get( | ||
| 1809 | __wasi_fd_t fd, | ||
| 1810 | __wasi_prestat_t *retptr0 | ||
| 1811 | ) __attribute__((__warn_unused_result__)); | ||
| 1812 | /** | ||
| 1813 | * Return a description of the given preopened file descriptor. | ||
| 1814 | */ | ||
| 1815 | __wasi_errno_t __wasi_fd_prestat_dir_name( | ||
| 1816 | __wasi_fd_t fd, | ||
| 1817 | /** | ||
| 1818 | * A buffer into which to write the preopened directory name. | ||
| 1819 | */ | ||
| 1820 | uint8_t * path, | ||
| 1821 | __wasi_size_t path_len | ||
| 1822 | ) __attribute__((__warn_unused_result__)); | ||
| 1823 | /** | ||
| 1824 | * Write to a file descriptor, without using and updating the file descriptor's offset. | ||
| 1825 | * Note: This is similar to `pwritev` in POSIX. | ||
| 1826 | * @return | ||
| 1827 | * The number of bytes written. | ||
| 1828 | */ | ||
| 1829 | __wasi_errno_t __wasi_fd_pwrite( | ||
| 1830 | __wasi_fd_t fd, | ||
| 1831 | /** | ||
| 1832 | * List of scatter/gather vectors from which to retrieve data. | ||
| 1833 | */ | ||
| 1834 | const __wasi_ciovec_t *iovs, | ||
| 1835 | /** | ||
| 1836 | * The length of the array pointed to by `iovs`. | ||
| 1837 | */ | ||
| 1838 | size_t iovs_len, | ||
| 1839 | /** | ||
| 1840 | * The offset within the file at which to write. | ||
| 1841 | */ | ||
| 1842 | __wasi_filesize_t offset, | ||
| 1843 | __wasi_size_t *retptr0 | ||
| 1844 | ) __attribute__((__warn_unused_result__)); | ||
| 1845 | /** | ||
| 1846 | * Read from a file descriptor. | ||
| 1847 | * Note: This is similar to `readv` in POSIX. | ||
| 1848 | * @return | ||
| 1849 | * The number of bytes read. | ||
| 1850 | */ | ||
| 1851 | __wasi_errno_t __wasi_fd_read( | ||
| 1852 | __wasi_fd_t fd, | ||
| 1853 | /** | ||
| 1854 | * List of scatter/gather vectors to which to store data. | ||
| 1855 | */ | ||
| 1856 | const __wasi_iovec_t *iovs, | ||
| 1857 | /** | ||
| 1858 | * The length of the array pointed to by `iovs`. | ||
| 1859 | */ | ||
| 1860 | size_t iovs_len, | ||
| 1861 | __wasi_size_t *retptr0 | ||
| 1862 | ) __attribute__((__warn_unused_result__)); | ||
| 1863 | /** | ||
| 1864 | * Read directory entries from a directory. | ||
| 1865 | * When successful, the contents of the output buffer consist of a sequence of | ||
| 1866 | * directory entries. Each directory entry consists of a `dirent` object, | ||
| 1867 | * followed by `dirent::d_namlen` bytes holding the name of the directory | ||
| 1868 | * entry. | ||
| 1869 | * This function fills the output buffer as much as possible, potentially | ||
| 1870 | * truncating the last directory entry. This allows the caller to grow its | ||
| 1871 | * read buffer size in case it's too small to fit a single large directory | ||
| 1872 | * entry, or skip the oversized directory entry. | ||
| 1873 | * @return | ||
| 1874 | * 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. | ||
| 1875 | */ | ||
| 1876 | __wasi_errno_t __wasi_fd_readdir( | ||
| 1877 | __wasi_fd_t fd, | ||
| 1878 | /** | ||
| 1879 | * The buffer where directory entries are stored | ||
| 1880 | */ | ||
| 1881 | uint8_t * buf, | ||
| 1882 | __wasi_size_t buf_len, | ||
| 1883 | /** | ||
| 1884 | * The location within the directory to start reading | ||
| 1885 | */ | ||
| 1886 | __wasi_dircookie_t cookie, | ||
| 1887 | __wasi_size_t *retptr0 | ||
| 1888 | ) __attribute__((__warn_unused_result__)); | ||
| 1889 | /** | ||
| 1890 | * Atomically replace a file descriptor by renumbering another file descriptor. | ||
| 1891 | * Due to the strong focus on thread safety, this environment does not provide | ||
| 1892 | * a mechanism to duplicate or renumber a file descriptor to an arbitrary | ||
| 1893 | * number, like `dup2()`. This would be prone to race conditions, as an actual | ||
| 1894 | * file descriptor with the same number could be allocated by a different | ||
| 1895 | * thread at the same time. | ||
| 1896 | * This function provides a way to atomically renumber file descriptors, which | ||
| 1897 | * would disappear if `dup2()` were to be removed entirely. | ||
| 1898 | */ | ||
| 1899 | __wasi_errno_t __wasi_fd_renumber( | ||
| 1900 | __wasi_fd_t fd, | ||
| 1901 | /** | ||
| 1902 | * The file descriptor to overwrite. | ||
| 1903 | */ | ||
| 1904 | __wasi_fd_t to | ||
| 1905 | ) __attribute__((__warn_unused_result__)); | ||
| 1906 | /** | ||
| 1907 | * Move the offset of a file descriptor. | ||
| 1908 | * Note: This is similar to `lseek` in POSIX. | ||
| 1909 | * @return | ||
| 1910 | * The new offset of the file descriptor, relative to the start of the file. | ||
| 1911 | */ | ||
| 1912 | __wasi_errno_t __wasi_fd_seek( | ||
| 1913 | __wasi_fd_t fd, | ||
| 1914 | /** | ||
| 1915 | * The number of bytes to move. | ||
| 1916 | */ | ||
| 1917 | __wasi_filedelta_t offset, | ||
| 1918 | /** | ||
| 1919 | * The base from which the offset is relative. | ||
| 1920 | */ | ||
| 1921 | __wasi_whence_t whence, | ||
| 1922 | __wasi_filesize_t *retptr0 | ||
| 1923 | ) __attribute__((__warn_unused_result__)); | ||
| 1924 | /** | ||
| 1925 | * Synchronize the data and metadata of a file to disk. | ||
| 1926 | * Note: This is similar to `fsync` in POSIX. | ||
| 1927 | */ | ||
| 1928 | __wasi_errno_t __wasi_fd_sync( | ||
| 1929 | __wasi_fd_t fd | ||
| 1930 | ) __attribute__((__warn_unused_result__)); | ||
| 1931 | /** | ||
| 1932 | * Return the current offset of a file descriptor. | ||
| 1933 | * Note: This is similar to `lseek(fd, 0, SEEK_CUR)` in POSIX. | ||
| 1934 | * @return | ||
| 1935 | * The current offset of the file descriptor, relative to the start of the file. | ||
| 1936 | */ | ||
| 1937 | __wasi_errno_t __wasi_fd_tell( | ||
| 1938 | __wasi_fd_t fd, | ||
| 1939 | __wasi_filesize_t *retptr0 | ||
| 1940 | ) __attribute__((__warn_unused_result__)); | ||
| 1941 | /** | ||
| 1942 | * Write to a file descriptor. | ||
| 1943 | * Note: This is similar to `writev` in POSIX. | ||
| 1944 | */ | ||
| 1945 | __wasi_errno_t __wasi_fd_write( | ||
| 1946 | __wasi_fd_t fd, | ||
| 1947 | /** | ||
| 1948 | * List of scatter/gather vectors from which to retrieve data. | ||
| 1949 | */ | ||
| 1950 | const __wasi_ciovec_t *iovs, | ||
| 1951 | /** | ||
| 1952 | * The length of the array pointed to by `iovs`. | ||
| 1953 | */ | ||
| 1954 | size_t iovs_len, | ||
| 1955 | __wasi_size_t *retptr0 | ||
| 1956 | ) __attribute__((__warn_unused_result__)); | ||
| 1957 | /** | ||
| 1958 | * Create a directory. | ||
| 1959 | * Note: This is similar to `mkdirat` in POSIX. | ||
| 1960 | */ | ||
| 1961 | __wasi_errno_t __wasi_path_create_directory( | ||
| 1962 | __wasi_fd_t fd, | ||
| 1963 | /** | ||
| 1964 | * The path at which to create the directory. | ||
| 1965 | */ | ||
| 1966 | const char *path | ||
| 1967 | ) __attribute__((__warn_unused_result__)); | ||
| 1968 | /** | ||
| 1969 | * Return the attributes of a file or directory. | ||
| 1970 | * Note: This is similar to `stat` in POSIX. | ||
| 1971 | * @return | ||
| 1972 | * The buffer where the file's attributes are stored. | ||
| 1973 | */ | ||
| 1974 | __wasi_errno_t __wasi_path_filestat_get( | ||
| 1975 | __wasi_fd_t fd, | ||
| 1976 | /** | ||
| 1977 | * Flags determining the method of how the path is resolved. | ||
| 1978 | */ | ||
| 1979 | __wasi_lookupflags_t flags, | ||
| 1980 | /** | ||
| 1981 | * The path of the file or directory to inspect. | ||
| 1982 | */ | ||
| 1983 | const char *path, | ||
| 1984 | __wasi_filestat_t *retptr0 | ||
| 1985 | ) __attribute__((__warn_unused_result__)); | ||
| 1986 | /** | ||
| 1987 | * Adjust the timestamps of a file or directory. | ||
| 1988 | * Note: This is similar to `utimensat` in POSIX. | ||
| 1989 | */ | ||
| 1990 | __wasi_errno_t __wasi_path_filestat_set_times( | ||
| 1991 | __wasi_fd_t fd, | ||
| 1992 | /** | ||
| 1993 | * Flags determining the method of how the path is resolved. | ||
| 1994 | */ | ||
| 1995 | __wasi_lookupflags_t flags, | ||
| 1996 | /** | ||
| 1997 | * The path of the file or directory to operate on. | ||
| 1998 | */ | ||
| 1999 | const char *path, | ||
| 2000 | /** | ||
| 2001 | * The desired values of the data access timestamp. | ||
| 2002 | */ | ||
| 2003 | __wasi_timestamp_t atim, | ||
| 2004 | /** | ||
| 2005 | * The desired values of the data modification timestamp. | ||
| 2006 | */ | ||
| 2007 | __wasi_timestamp_t mtim, | ||
| 2008 | /** | ||
| 2009 | * A bitmask indicating which timestamps to adjust. | ||
| 2010 | */ | ||
| 2011 | __wasi_fstflags_t fst_flags | ||
| 2012 | ) __attribute__((__warn_unused_result__)); | ||
| 2013 | /** | ||
| 2014 | * Create a hard link. | ||
| 2015 | * Note: This is similar to `linkat` in POSIX. | ||
| 2016 | */ | ||
| 2017 | __wasi_errno_t __wasi_path_link( | ||
| 2018 | __wasi_fd_t old_fd, | ||
| 2019 | /** | ||
| 2020 | * Flags determining the method of how the path is resolved. | ||
| 2021 | */ | ||
| 2022 | __wasi_lookupflags_t old_flags, | ||
| 2023 | /** | ||
| 2024 | * The source path from which to link. | ||
| 2025 | */ | ||
| 2026 | const char *old_path, | ||
| 2027 | /** | ||
| 2028 | * The working directory at which the resolution of the new path starts. | ||
| 2029 | */ | ||
| 2030 | __wasi_fd_t new_fd, | ||
| 2031 | /** | ||
| 2032 | * The destination path at which to create the hard link. | ||
| 2033 | */ | ||
| 2034 | const char *new_path | ||
| 2035 | ) __attribute__((__warn_unused_result__)); | ||
| 2036 | /** | ||
| 2037 | * Open a file or directory. | ||
| 2038 | * The returned file descriptor is not guaranteed to be the lowest-numbered | ||
| 2039 | * file descriptor not currently open; it is randomized to prevent | ||
| 2040 | * applications from depending on making assumptions about indexes, since this | ||
| 2041 | * is error-prone in multi-threaded contexts. The returned file descriptor is | ||
| 2042 | * guaranteed to be less than 2**31. | ||
| 2043 | * Note: This is similar to `openat` in POSIX. | ||
| 2044 | * @return | ||
| 2045 | * The file descriptor of the file that has been opened. | ||
| 2046 | */ | ||
| 2047 | __wasi_errno_t __wasi_path_open( | ||
| 2048 | __wasi_fd_t fd, | ||
| 2049 | /** | ||
| 2050 | * Flags determining the method of how the path is resolved. | ||
| 2051 | */ | ||
| 2052 | __wasi_lookupflags_t dirflags, | ||
| 2053 | /** | ||
| 2054 | * The relative path of the file or directory to open, relative to the | ||
| 2055 | * `path_open::fd` directory. | ||
| 2056 | */ | ||
| 2057 | const char *path, | ||
| 2058 | /** | ||
| 2059 | * The method by which to open the file. | ||
| 2060 | */ | ||
| 2061 | __wasi_oflags_t oflags, | ||
| 2062 | /** | ||
| 2063 | * The initial rights of the newly created file descriptor. The | ||
| 2064 | * implementation is allowed to return a file descriptor with fewer rights | ||
| 2065 | * than specified, if and only if those rights do not apply to the type of | ||
| 2066 | * file being opened. | ||
| 2067 | * The *base* rights are rights that will apply to operations using the file | ||
| 2068 | * descriptor itself, while the *inheriting* rights are rights that apply to | ||
| 2069 | * file descriptors derived from it. | ||
| 2070 | */ | ||
| 2071 | __wasi_rights_t fs_rights_base, | ||
| 2072 | __wasi_rights_t fs_rights_inheriting, | ||
| 2073 | __wasi_fdflags_t fdflags, | ||
| 2074 | __wasi_fd_t *retptr0 | ||
| 2075 | ) __attribute__((__warn_unused_result__)); | ||
| 2076 | /** | ||
| 2077 | * Read the contents of a symbolic link. | ||
| 2078 | * Note: This is similar to `readlinkat` in POSIX. | ||
| 2079 | * @return | ||
| 2080 | * The number of bytes placed in the buffer. | ||
| 2081 | */ | ||
| 2082 | __wasi_errno_t __wasi_path_readlink( | ||
| 2083 | __wasi_fd_t fd, | ||
| 2084 | /** | ||
| 2085 | * The path of the symbolic link from which to read. | ||
| 2086 | */ | ||
| 2087 | const char *path, | ||
| 2088 | /** | ||
| 2089 | * The buffer to which to write the contents of the symbolic link. | ||
| 2090 | */ | ||
| 2091 | uint8_t * buf, | ||
| 2092 | __wasi_size_t buf_len, | ||
| 2093 | __wasi_size_t *retptr0 | ||
| 2094 | ) __attribute__((__warn_unused_result__)); | ||
| 2095 | /** | ||
| 2096 | * Remove a directory. | ||
| 2097 | * Return `errno::notempty` if the directory is not empty. | ||
| 2098 | * Note: This is similar to `unlinkat(fd, path, AT_REMOVEDIR)` in POSIX. | ||
| 2099 | */ | ||
| 2100 | __wasi_errno_t __wasi_path_remove_directory( | ||
| 2101 | __wasi_fd_t fd, | ||
| 2102 | /** | ||
| 2103 | * The path to a directory to remove. | ||
| 2104 | */ | ||
| 2105 | const char *path | ||
| 2106 | ) __attribute__((__warn_unused_result__)); | ||
| 2107 | /** | ||
| 2108 | * Rename a file or directory. | ||
| 2109 | * Note: This is similar to `renameat` in POSIX. | ||
| 2110 | */ | ||
| 2111 | __wasi_errno_t __wasi_path_rename( | ||
| 2112 | __wasi_fd_t fd, | ||
| 2113 | /** | ||
| 2114 | * The source path of the file or directory to rename. | ||
| 2115 | */ | ||
| 2116 | const char *old_path, | ||
| 2117 | /** | ||
| 2118 | * The working directory at which the resolution of the new path starts. | ||
| 2119 | */ | ||
| 2120 | __wasi_fd_t new_fd, | ||
| 2121 | /** | ||
| 2122 | * The destination path to which to rename the file or directory. | ||
| 2123 | */ | ||
| 2124 | const char *new_path | ||
| 2125 | ) __attribute__((__warn_unused_result__)); | ||
| 2126 | /** | ||
| 2127 | * Create a symbolic link. | ||
| 2128 | * Note: This is similar to `symlinkat` in POSIX. | ||
| 2129 | */ | ||
| 2130 | __wasi_errno_t __wasi_path_symlink( | ||
| 2131 | /** | ||
| 2132 | * The contents of the symbolic link. | ||
| 2133 | */ | ||
| 2134 | const char *old_path, | ||
| 2135 | __wasi_fd_t fd, | ||
| 2136 | /** | ||
| 2137 | * The destination path at which to create the symbolic link. | ||
| 2138 | */ | ||
| 2139 | const char *new_path | ||
| 2140 | ) __attribute__((__warn_unused_result__)); | ||
| 2141 | /** | ||
| 2142 | * Unlink a file. | ||
| 2143 | * Return `errno::isdir` if the path refers to a directory. | ||
| 2144 | * Note: This is similar to `unlinkat(fd, path, 0)` in POSIX. | ||
| 2145 | */ | ||
| 2146 | __wasi_errno_t __wasi_path_unlink_file( | ||
| 2147 | __wasi_fd_t fd, | ||
| 2148 | /** | ||
| 2149 | * The path to a file to unlink. | ||
| 2150 | */ | ||
| 2151 | const char *path | ||
| 2152 | ) __attribute__((__warn_unused_result__)); | ||
| 2153 | /** | ||
| 2154 | * Concurrently poll for the occurrence of a set of events. | ||
| 2155 | * @return | ||
| 2156 | * The number of events stored. | ||
| 2157 | */ | ||
| 2158 | __wasi_errno_t __wasi_poll_oneoff( | ||
| 2159 | /** | ||
| 2160 | * The events to which to subscribe. | ||
| 2161 | */ | ||
| 2162 | const __wasi_subscription_t * in, | ||
| 2163 | /** | ||
| 2164 | * The events that have occurred. | ||
| 2165 | */ | ||
| 2166 | __wasi_event_t * out, | ||
| 2167 | /** | ||
| 2168 | * Both the number of subscriptions and events. | ||
| 2169 | */ | ||
| 2170 | __wasi_size_t nsubscriptions, | ||
| 2171 | __wasi_size_t *retptr0 | ||
| 2172 | ) __attribute__((__warn_unused_result__)); | ||
| 2173 | /** | ||
| 2174 | * Terminate the process normally. An exit code of 0 indicates successful | ||
| 2175 | * termination of the program. The meanings of other values is dependent on | ||
| 2176 | * the environment. | ||
| 2177 | */ | ||
| 2178 | _Noreturn void __wasi_proc_exit( | ||
| 2179 | /** | ||
| 2180 | * The exit code returned by the process. | ||
| 2181 | */ | ||
| 2182 | __wasi_exitcode_t rval | ||
| 2183 | ); | ||
| 2184 | /** | ||
| 2185 | * Send a signal to the process of the calling thread. | ||
| 2186 | * Note: This is similar to `raise` in POSIX. | ||
| 2187 | */ | ||
| 2188 | __wasi_errno_t __wasi_proc_raise( | ||
| 2189 | /** | ||
| 2190 | * The signal condition to trigger. | ||
| 2191 | */ | ||
| 2192 | __wasi_signal_t sig | ||
| 2193 | ) __attribute__((__warn_unused_result__)); | ||
| 2194 | /** | ||
| 2195 | * Temporarily yield execution of the calling thread. | ||
| 2196 | * Note: This is similar to `sched_yield` in POSIX. | ||
| 2197 | */ | ||
| 2198 | __wasi_errno_t __wasi_sched_yield( | ||
| 2199 | void | ||
| 2200 | ) __attribute__((__warn_unused_result__)); | ||
| 2201 | /** | ||
| 2202 | * Write high-quality random data into a buffer. | ||
| 2203 | * This function blocks when the implementation is unable to immediately | ||
| 2204 | * provide sufficient high-quality random data. | ||
| 2205 | * This function may execute slowly, so when large mounts of random data are | ||
| 2206 | * required, it's advisable to use this function to seed a pseudo-random | ||
| 2207 | * number generator, rather than to provide the random data directly. | ||
| 2208 | */ | ||
| 2209 | __wasi_errno_t __wasi_random_get( | ||
| 2210 | /** | ||
| 2211 | * The buffer to fill with random data. | ||
| 2212 | */ | ||
| 2213 | uint8_t * buf, | ||
| 2214 | __wasi_size_t buf_len | ||
| 2215 | ) __attribute__((__warn_unused_result__)); | ||
| 2216 | /** | ||
| 2217 | * Receive a message from a socket. | ||
| 2218 | * Note: This is similar to `recv` in POSIX, though it also supports reading | ||
| 2219 | * the data into multiple buffers in the manner of `readv`. | ||
| 2220 | * @return | ||
| 2221 | * Number of bytes stored in ri_data and message flags. | ||
| 2222 | */ | ||
| 2223 | __wasi_errno_t __wasi_sock_recv( | ||
| 2224 | __wasi_fd_t fd, | ||
| 2225 | /** | ||
| 2226 | * List of scatter/gather vectors to which to store data. | ||
| 2227 | */ | ||
| 2228 | const __wasi_iovec_t *ri_data, | ||
| 2229 | /** | ||
| 2230 | * The length of the array pointed to by `ri_data`. | ||
| 2231 | */ | ||
| 2232 | size_t ri_data_len, | ||
| 2233 | /** | ||
| 2234 | * Message flags. | ||
| 2235 | */ | ||
| 2236 | __wasi_riflags_t ri_flags, | ||
| 2237 | __wasi_size_t *retptr0, | ||
| 2238 | __wasi_roflags_t *retptr1 | ||
| 2239 | ) __attribute__((__warn_unused_result__)); | ||
| 2240 | /** | ||
| 2241 | * Send a message on a socket. | ||
| 2242 | * Note: This is similar to `send` in POSIX, though it also supports writing | ||
| 2243 | * the data from multiple buffers in the manner of `writev`. | ||
| 2244 | * @return | ||
| 2245 | * Number of bytes transmitted. | ||
| 2246 | */ | ||
| 2247 | __wasi_errno_t __wasi_sock_send( | ||
| 2248 | __wasi_fd_t fd, | ||
| 2249 | /** | ||
| 2250 | * List of scatter/gather vectors to which to retrieve data | ||
| 2251 | */ | ||
| 2252 | const __wasi_ciovec_t *si_data, | ||
| 2253 | /** | ||
| 2254 | * The length of the array pointed to by `si_data`. | ||
| 2255 | */ | ||
| 2256 | size_t si_data_len, | ||
| 2257 | /** | ||
| 2258 | * Message flags. | ||
| 2259 | */ | ||
| 2260 | __wasi_siflags_t si_flags, | ||
| 2261 | __wasi_size_t *retptr0 | ||
| 2262 | ) __attribute__((__warn_unused_result__)); | ||
| 2263 | /** | ||
| 2264 | * Shut down socket send and receive channels. | ||
| 2265 | * Note: This is similar to `shutdown` in POSIX. | ||
| 2266 | */ | ||
| 2267 | __wasi_errno_t __wasi_sock_shutdown( | ||
| 2268 | __wasi_fd_t fd, | ||
| 2269 | /** | ||
| 2270 | * Which channels on the socket to shut down. | ||
| 2271 | */ | ||
| 2272 | __wasi_sdflags_t how | ||
| 2273 | ) __attribute__((__warn_unused_result__)); | ||
| 2274 | /** @} */ | ||
| 2275 | |||
| 2276 | #ifdef __cplusplus | ||
| 2277 | } | ||
| 2278 | #endif | ||
| 2279 | |||
| 2280 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc-environ.h created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #ifndef __wasi_libc_environ_h | ||
| 2 | #define __wasi_libc_environ_h | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | /// Initialize the global environment variable state. Only needs to be | ||
| 9 | /// called once; most users should call `__wasilibc_ensure_environ` instead. | ||
| 10 | void __wasilibc_initialize_environ(void); | ||
| 11 | |||
| 12 | /// If `__wasilibc_initialize_environ` has not yet been called, call it. | ||
| 13 | void __wasilibc_ensure_environ(void); | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | } | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/include/wasm-wasi-musl/wasi/libc-find-relpath.h created+79| ... | @@ -0,0 +1,79 @@ | ||
| 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 created+58| ... | @@ -0,0 +1,58 @@ | ||
| 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 created+65| ... | @@ -0,0 +1,65 @@ | ||
| 1 | #ifndef __wasi_libc_h | ||
| 2 | #define __wasi_libc_h | ||
| 3 | |||
| 4 | #include <__typedef_off_t.h> | ||
| 5 | #include <__struct_timespec.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | struct stat; | ||
| 12 | struct timespec; | ||
| 13 | |||
| 14 | /// Register the given pre-opened file descriptor under the given path. | ||
| 15 | /// | ||
| 16 | /// This function does not take ownership of `prefix` (it makes its own copy). | ||
| 17 | int __wasilibc_register_preopened_fd(int fd, const char *prefix); | ||
| 18 | |||
| 19 | /// Renumber `fd` to `newfd`; similar to `dup2` but does a move rather than a | ||
| 20 | /// copy. | ||
| 21 | int __wasilibc_fd_renumber(int fd, int newfd) | ||
| 22 | __attribute__((__warn_unused_result__)); | ||
| 23 | |||
| 24 | /// Like `unlinkat`, but without depending on `__wasi_path_remove_directory`. | ||
| 25 | int __wasilibc_unlinkat(int fd, const char *path) | ||
| 26 | __attribute__((__warn_unused_result__)); | ||
| 27 | |||
| 28 | /// An `*at` version of rmdir. | ||
| 29 | int __wasilibc_rmdirat(int fd, const char *path) | ||
| 30 | __attribute__((__warn_unused_result__)); | ||
| 31 | |||
| 32 | /// Like `open`, but without the varargs in the signature. | ||
| 33 | int __wasilibc_open_nomode(const char *path, int oflag); | ||
| 34 | |||
| 35 | /// Like `openat`, but without the varargs in the signature. | ||
| 36 | int __wasilibc_openat_nomode(int fd, const char *path, int oflag); | ||
| 37 | |||
| 38 | /// Return the current file offset. Like `lseek(fd, 0, SEEK_CUR)`, but without | ||
| 39 | /// depending on `lseek`. | ||
| 40 | off_t __wasilibc_tell(int fd) | ||
| 41 | __attribute__((__warn_unused_result__)); | ||
| 42 | |||
| 43 | /* Non-`at` forms of various `*at` functions. */ | ||
| 44 | int __wasilibc_access(const char *pathname, int mode, int flags) | ||
| 45 | __attribute__((__warn_unused_result__)); | ||
| 46 | int __wasilibc_stat(const char *__restrict pathname, struct stat *__restrict statbuf, int flags) | ||
| 47 | __attribute__((__warn_unused_result__)); | ||
| 48 | int __wasilibc_utimens(const char *pathname, const struct timespec times[2], int flags) | ||
| 49 | __attribute__((__warn_unused_result__)); | ||
| 50 | int __wasilibc_link(const char *oldpath, const char *newpath, int flags) | ||
| 51 | __attribute__((__warn_unused_result__)); | ||
| 52 | int __wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags) | ||
| 53 | __attribute__((__warn_unused_result__)); | ||
| 54 | int __wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags) | ||
| 55 | __attribute__((__warn_unused_result__)); | ||
| 56 | int __wasilibc_rename_oldat(int olddirfd, const char *oldpath, const char *newpath) | ||
| 57 | __attribute__((__warn_unused_result__)); | ||
| 58 | int __wasilibc_rename_newat(const char *oldpath, int newdirfd, const char *newpath) | ||
| 59 | __attribute__((__warn_unused_result__)); | ||
| 60 | |||
| 61 | #ifdef __cplusplus | ||
| 62 | } | ||
| 63 | #endif | ||
| 64 | |||
| 65 | #endif | ||
lib/libc/include/wasm-wasi-musl/wchar.h created+212| ... | @@ -0,0 +1,212 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 45 | #define NULL 0L | ||
| 46 | #else | ||
| 47 | #define NULL ((void*)0) | ||
| 48 | #endif | ||
| 49 | #else | ||
| 50 | #define __need_NULL | ||
| 51 | #include <stddef.h> | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #undef WEOF | ||
| 55 | #define WEOF 0xffffffffU | ||
| 56 | |||
| 57 | wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 58 | wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 59 | |||
| 60 | wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 61 | wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 62 | |||
| 63 | int wcscmp (const wchar_t *, const wchar_t *); | ||
| 64 | int wcsncmp (const wchar_t *, const wchar_t *, size_t); | ||
| 65 | |||
| 66 | int wcscoll(const wchar_t *, const wchar_t *); | ||
| 67 | size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 68 | |||
| 69 | wchar_t *wcschr (const wchar_t *, wchar_t); | ||
| 70 | wchar_t *wcsrchr (const wchar_t *, wchar_t); | ||
| 71 | |||
| 72 | size_t wcscspn (const wchar_t *, const wchar_t *); | ||
| 73 | size_t wcsspn (const wchar_t *, const wchar_t *); | ||
| 74 | wchar_t *wcspbrk (const wchar_t *, const wchar_t *); | ||
| 75 | |||
| 76 | wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); | ||
| 77 | |||
| 78 | size_t wcslen (const wchar_t *); | ||
| 79 | |||
| 80 | wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); | ||
| 81 | wchar_t *wcswcs (const wchar_t *, const wchar_t *); | ||
| 82 | |||
| 83 | wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); | ||
| 84 | int wmemcmp (const wchar_t *, const wchar_t *, size_t); | ||
| 85 | wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 86 | wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); | ||
| 87 | wchar_t *wmemset (wchar_t *, wchar_t, size_t); | ||
| 88 | |||
| 89 | wint_t btowc (int); | ||
| 90 | int wctob (wint_t); | ||
| 91 | |||
| 92 | int mbsinit (const mbstate_t *); | ||
| 93 | size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 94 | size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); | ||
| 95 | |||
| 96 | size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 97 | |||
| 98 | size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); | ||
| 99 | size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); | ||
| 100 | |||
| 101 | float wcstof (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 102 | double wcstod (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 103 | long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 104 | |||
| 105 | long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 106 | unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 107 | |||
| 108 | long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 109 | unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | int fwide (FILE *, int); | ||
| 114 | |||
| 115 | |||
| 116 | int wprintf (const wchar_t *__restrict, ...); | ||
| 117 | int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 118 | int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); | ||
| 119 | |||
| 120 | int vwprintf (const wchar_t *__restrict, __isoc_va_list); | ||
| 121 | int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 122 | int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); | ||
| 123 | |||
| 124 | int wscanf (const wchar_t *__restrict, ...); | ||
| 125 | int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 126 | int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); | ||
| 127 | |||
| 128 | int vwscanf (const wchar_t *__restrict, __isoc_va_list); | ||
| 129 | int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 130 | int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 131 | |||
| 132 | wint_t fgetwc (FILE *); | ||
| 133 | wint_t getwc (FILE *); | ||
| 134 | wint_t getwchar (void); | ||
| 135 | |||
| 136 | wint_t fputwc (wchar_t, FILE *); | ||
| 137 | wint_t putwc (wchar_t, FILE *); | ||
| 138 | wint_t putwchar (wchar_t); | ||
| 139 | |||
| 140 | wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); | ||
| 141 | int fputws (const wchar_t *__restrict, FILE *__restrict); | ||
| 142 | |||
| 143 | wint_t ungetwc (wint_t, FILE *); | ||
| 144 | |||
| 145 | struct tm; | ||
| 146 | size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); | ||
| 147 | |||
| 148 | #undef iswdigit | ||
| 149 | |||
| 150 | #if defined(_GNU_SOURCE) | ||
| 151 | wint_t fgetwc_unlocked (FILE *); | ||
| 152 | wint_t getwc_unlocked (FILE *); | ||
| 153 | wint_t getwchar_unlocked (void); | ||
| 154 | wint_t fputwc_unlocked (wchar_t, FILE *); | ||
| 155 | wint_t putwc_unlocked (wchar_t, FILE *); | ||
| 156 | wint_t putwchar_unlocked (wchar_t); | ||
| 157 | wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); | ||
| 158 | int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); | ||
| 159 | #endif | ||
| 160 | |||
| 161 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 162 | size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); | ||
| 163 | #endif | ||
| 164 | |||
| 165 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 166 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 167 | FILE *open_wmemstream(wchar_t **, size_t *); | ||
| 168 | size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 169 | size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 170 | wchar_t *wcsdup(const wchar_t *); | ||
| 171 | size_t wcsnlen (const wchar_t *, size_t); | ||
| 172 | wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 173 | wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 174 | int wcscasecmp(const wchar_t *, const wchar_t *); | ||
| 175 | int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 176 | int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); | ||
| 177 | int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); | ||
| 178 | int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 179 | size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); | ||
| 180 | #endif | ||
| 181 | |||
| 182 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 183 | int wcwidth (wchar_t); | ||
| 184 | int wcswidth (const wchar_t *, size_t); | ||
| 185 | int iswalnum(wint_t); | ||
| 186 | int iswalpha(wint_t); | ||
| 187 | int iswblank(wint_t); | ||
| 188 | int iswcntrl(wint_t); | ||
| 189 | int iswdigit(wint_t); | ||
| 190 | int iswgraph(wint_t); | ||
| 191 | int iswlower(wint_t); | ||
| 192 | int iswprint(wint_t); | ||
| 193 | int iswpunct(wint_t); | ||
| 194 | int iswspace(wint_t); | ||
| 195 | int iswupper(wint_t); | ||
| 196 | int iswxdigit(wint_t); | ||
| 197 | int iswctype(wint_t, wctype_t); | ||
| 198 | wint_t towlower(wint_t); | ||
| 199 | wint_t towupper(wint_t); | ||
| 200 | wctype_t wctype(const char *); | ||
| 201 | |||
| 202 | #ifndef __cplusplus | ||
| 203 | #undef iswdigit | ||
| 204 | #define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 205 | #endif | ||
| 206 | #endif | ||
| 207 | |||
| 208 | #ifdef __cplusplus | ||
| 209 | } | ||
| 210 | #endif | ||
| 211 | |||
| 212 | #endif | ||
lib/libc/include/wasm-wasi-musl/wctype.h created+79| ... | @@ -0,0 +1,79 @@ | ||
| 1 | #ifndef _WCTYPE_H | ||
| 2 | #define _WCTYPE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_wint_t | ||
| 11 | #define __NEED_wctype_t | ||
| 12 | |||
| 13 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 14 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 15 | #define __NEED_locale_t | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #include <bits/alltypes.h> | ||
| 19 | |||
| 20 | typedef const int * wctrans_t; | ||
| 21 | |||
| 22 | #undef WEOF | ||
| 23 | #define WEOF 0xffffffffU | ||
| 24 | |||
| 25 | #undef iswdigit | ||
| 26 | |||
| 27 | int iswalnum(wint_t); | ||
| 28 | int iswalpha(wint_t); | ||
| 29 | int iswblank(wint_t); | ||
| 30 | int iswcntrl(wint_t); | ||
| 31 | int iswdigit(wint_t); | ||
| 32 | int iswgraph(wint_t); | ||
| 33 | int iswlower(wint_t); | ||
| 34 | int iswprint(wint_t); | ||
| 35 | int iswpunct(wint_t); | ||
| 36 | int iswspace(wint_t); | ||
| 37 | int iswupper(wint_t); | ||
| 38 | int iswxdigit(wint_t); | ||
| 39 | int iswctype(wint_t, wctype_t); | ||
| 40 | wint_t towctrans(wint_t, wctrans_t); | ||
| 41 | wint_t towlower(wint_t); | ||
| 42 | wint_t towupper(wint_t); | ||
| 43 | wctrans_t wctrans(const char *); | ||
| 44 | wctype_t wctype(const char *); | ||
| 45 | |||
| 46 | #ifndef __cplusplus | ||
| 47 | #undef iswdigit | ||
| 48 | #define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 52 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 53 | |||
| 54 | int iswalnum_l(wint_t, locale_t); | ||
| 55 | int iswalpha_l(wint_t, locale_t); | ||
| 56 | int iswblank_l(wint_t, locale_t); | ||
| 57 | int iswcntrl_l(wint_t, locale_t); | ||
| 58 | int iswdigit_l(wint_t, locale_t); | ||
| 59 | int iswgraph_l(wint_t, locale_t); | ||
| 60 | int iswlower_l(wint_t, locale_t); | ||
| 61 | int iswprint_l(wint_t, locale_t); | ||
| 62 | int iswpunct_l(wint_t, locale_t); | ||
| 63 | int iswspace_l(wint_t, locale_t); | ||
| 64 | int iswupper_l(wint_t, locale_t); | ||
| 65 | int iswxdigit_l(wint_t, locale_t); | ||
| 66 | int iswctype_l(wint_t, wctype_t, locale_t); | ||
| 67 | wint_t towlower_l(wint_t, locale_t); | ||
| 68 | wint_t towupper_l(wint_t, locale_t); | ||
| 69 | wint_t towctrans_l(wint_t, wctrans_t, locale_t); | ||
| 70 | wctrans_t wctrans_l(const char *, locale_t); | ||
| 71 | wctype_t wctype_l(const char *, locale_t); | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef __cplusplus | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #endif | ||
lib/libc/wasi/LICENSE created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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 | libc-bottom-half/cloudlibc/ - BSD-2-Clause; see the LICENSE file for details | ||
| 11 | libc-top-half/musl/ - MIT; see the COPYRIGHT file for details | ||
| 12 | |||
| 13 | wasi-libc's changes to these files are multi-licensed under the | ||
| 14 | Apache License v2.0 with LLVM Exceptions, the Apache License v2.0, | ||
| 15 | the MIT License, and the original licenses of the third-party works. | ||
lib/libc/wasi/LICENSE-APACHE created+201| ... | @@ -0,0 +1,201 @@ | ||
| 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 created+220| ... | @@ -0,0 +1,220 @@ | ||
| 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 created+23| ... | @@ -0,0 +1,23 @@ | ||
| 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/dlmalloc/include/unistd.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | /* Stub include file to support dlmalloc. */ | ||
| 2 | |||
| 3 | #include <stdint.h> | ||
| 4 | #include <__macro_PAGESIZE.h> | ||
| 5 | |||
| 6 | #define sysconf(name) PAGESIZE | ||
| 7 | #define _SC_PAGESIZE | ||
| 8 | |||
| 9 | /* Declare sbrk. */ | ||
| 10 | void *sbrk(intptr_t increment) __attribute__((__warn_unused_result__)); | ||
lib/libc/wasi/dlmalloc/src/dlmalloc.c created+98| ... | @@ -0,0 +1,98 @@ | ||
| 1 | // This file is a wrapper around malloc.c, which is the upstream source file. | ||
| 2 | // It sets configuration flags and controls which symbols are exported. | ||
| 3 | |||
| 4 | #include <stddef.h> | ||
| 5 | #include <malloc.h> | ||
| 6 | |||
| 7 | // Define configuration macros for dlmalloc. | ||
| 8 | |||
| 9 | // WebAssembly doesn't have mmap-style memory allocation. | ||
| 10 | #define HAVE_MMAP 0 | ||
| 11 | |||
| 12 | // WebAssembly doesn't support shrinking linear memory. | ||
| 13 | #define MORECORE_CANNOT_TRIM 1 | ||
| 14 | |||
| 15 | // Disable sanity checks to reduce code size. | ||
| 16 | #define ABORT __builtin_unreachable() | ||
| 17 | |||
| 18 | // If threads are enabled, enable support for threads. | ||
| 19 | #ifdef _REENTRANT | ||
| 20 | #define USE_LOCKS 1 | ||
| 21 | #endif | ||
| 22 | |||
| 23 | // Make malloc deterministic. | ||
| 24 | #define LACKS_TIME_H 1 | ||
| 25 | |||
| 26 | // Disable malloc statistics generation to reduce code size. | ||
| 27 | #define NO_MALLINFO 1 | ||
| 28 | #define NO_MALLOC_STATS 1 | ||
| 29 | |||
| 30 | // Align malloc regions to 16, to avoid unaligned SIMD accesses. | ||
| 31 | #define MALLOC_ALIGNMENT 16 | ||
| 32 | |||
| 33 | // Declare errno values used by dlmalloc. We define them like this to avoid | ||
| 34 | // putting specific errno values in the ABI. | ||
| 35 | extern const int __ENOMEM; | ||
| 36 | #define ENOMEM __ENOMEM | ||
| 37 | extern const int __EINVAL; | ||
| 38 | #define EINVAL __EINVAL | ||
| 39 | |||
| 40 | // Define USE_DL_PREFIX so that we leave dlmalloc's names prefixed with 'dl'. | ||
| 41 | // We define them as "static", and we wrap them with public names below. This | ||
| 42 | // serves two purposes: | ||
| 43 | // | ||
| 44 | // One is to make it easy to control which symbols are exported; dlmalloc | ||
| 45 | // defines several non-standard functions and we wish to explicitly control | ||
| 46 | // which functions are part of our public-facing interface. | ||
| 47 | // | ||
| 48 | // The other is to protect against compilers optimizing based on the assumption | ||
| 49 | // that they know what functions with names like "malloc" do. Code in the | ||
| 50 | // implementation will call functions like "dlmalloc" and assume it can use | ||
| 51 | // the resulting pointers to access the metadata outside of the nominally | ||
| 52 | // allocated objects. However, if the function were named "malloc", compilers | ||
| 53 | // might see code like that and assume it has undefined behavior and can be | ||
| 54 | // optimized away. By using "dlmalloc" in the implementation, we don't need | ||
| 55 | // -fno-builtin to avoid this problem. | ||
| 56 | #define USE_DL_PREFIX 1 | ||
| 57 | #define DLMALLOC_EXPORT static inline | ||
| 58 | |||
| 59 | // This isn't declared with DLMALLOC_EXPORT so make it static explicitly. | ||
| 60 | static size_t dlmalloc_usable_size(void*); | ||
| 61 | |||
| 62 | // Include the upstream dlmalloc's malloc.c. | ||
| 63 | #include "malloc.c" | ||
| 64 | |||
| 65 | // Export the public names. | ||
| 66 | |||
| 67 | void *malloc(size_t size) { | ||
| 68 | return dlmalloc(size); | ||
| 69 | } | ||
| 70 | |||
| 71 | void free(void *ptr) { | ||
| 72 | dlfree(ptr); | ||
| 73 | } | ||
| 74 | |||
| 75 | void *calloc(size_t nmemb, size_t size) { | ||
| 76 | return dlcalloc(nmemb, size); | ||
| 77 | } | ||
| 78 | |||
| 79 | void *realloc(void *ptr, size_t size) { | ||
| 80 | return dlrealloc(ptr, size); | ||
| 81 | } | ||
| 82 | |||
| 83 | int posix_memalign(void **memptr, size_t alignment, size_t size) { | ||
| 84 | return dlposix_memalign(memptr, alignment, size); | ||
| 85 | } | ||
| 86 | |||
| 87 | void* aligned_alloc(size_t alignment, size_t bytes) { | ||
| 88 | return dlmemalign(alignment, bytes); | ||
| 89 | } | ||
| 90 | |||
| 91 | size_t malloc_usable_size(void *ptr) { | ||
| 92 | return dlmalloc_usable_size(ptr); | ||
| 93 | } | ||
| 94 | |||
| 95 | // Define these to satisfy musl references. | ||
| 96 | void *__libc_malloc(size_t) __attribute__((alias("malloc"))); | ||
| 97 | void __libc_free(void *) __attribute__((alias("free"))); | ||
| 98 | void *__libc_calloc(size_t nmemb, size_t size) __attribute__((alias("calloc"))); | ||
lib/libc/wasi/dlmalloc/src/malloc.c created+6352| ... | @@ -0,0 +1,6352 @@ | ||
| 1 | /* | ||
| 2 | This is a version (aka dlmalloc) of malloc/free/realloc written by | ||
| 3 | Doug Lea and released to the public domain, as explained at | ||
| 4 | http://creativecommons.org/publicdomain/zero/1.0/ Send questions, | ||
| 5 | comments, complaints, performance data, etc to dl@cs.oswego.edu | ||
| 6 | |||
| 7 | * Version 2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea | ||
| 8 | Note: There may be an updated version of this malloc obtainable at | ||
| 9 | ftp://gee.cs.oswego.edu/pub/misc/malloc.c | ||
| 10 | Check before installing! | ||
| 11 | |||
| 12 | * Quickstart | ||
| 13 | |||
| 14 | This library is all in one file to simplify the most common usage: | ||
| 15 | ftp it, compile it (-O3), and link it into another program. All of | ||
| 16 | the compile-time options default to reasonable values for use on | ||
| 17 | most platforms. You might later want to step through various | ||
| 18 | compile-time and dynamic tuning options. | ||
| 19 | |||
| 20 | For convenience, an include file for code using this malloc is at: | ||
| 21 | ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.6.h | ||
| 22 | You don't really need this .h file unless you call functions not | ||
| 23 | defined in your system include files. The .h file contains only the | ||
| 24 | excerpts from this file needed for using this malloc on ANSI C/C++ | ||
| 25 | systems, so long as you haven't changed compile-time options about | ||
| 26 | naming and tuning parameters. If you do, then you can create your | ||
| 27 | own malloc.h that does include all settings by cutting at the point | ||
| 28 | indicated below. Note that you may already by default be using a C | ||
| 29 | library containing a malloc that is based on some version of this | ||
| 30 | malloc (for example in linux). You might still want to use the one | ||
| 31 | in this file to customize settings or to avoid overheads associated | ||
| 32 | with library versions. | ||
| 33 | |||
| 34 | * Vital statistics: | ||
| 35 | |||
| 36 | Supported pointer/size_t representation: 4 or 8 bytes | ||
| 37 | size_t MUST be an unsigned type of the same width as | ||
| 38 | pointers. (If you are using an ancient system that declares | ||
| 39 | size_t as a signed type, or need it to be a different width | ||
| 40 | than pointers, you can use a previous release of this malloc | ||
| 41 | (e.g. 2.7.2) supporting these.) | ||
| 42 | |||
| 43 | Alignment: 8 bytes (minimum) | ||
| 44 | This suffices for nearly all current machines and C compilers. | ||
| 45 | However, you can define MALLOC_ALIGNMENT to be wider than this | ||
| 46 | if necessary (up to 128bytes), at the expense of using more space. | ||
| 47 | |||
| 48 | Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes) | ||
| 49 | 8 or 16 bytes (if 8byte sizes) | ||
| 50 | Each malloced chunk has a hidden word of overhead holding size | ||
| 51 | and status information, and additional cross-check word | ||
| 52 | if FOOTERS is defined. | ||
| 53 | |||
| 54 | Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead) | ||
| 55 | 8-byte ptrs: 32 bytes (including overhead) | ||
| 56 | |||
| 57 | Even a request for zero bytes (i.e., malloc(0)) returns a | ||
| 58 | pointer to something of the minimum allocatable size. | ||
| 59 | The maximum overhead wastage (i.e., number of extra bytes | ||
| 60 | allocated than were requested in malloc) is less than or equal | ||
| 61 | to the minimum size, except for requests >= mmap_threshold that | ||
| 62 | are serviced via mmap(), where the worst case wastage is about | ||
| 63 | 32 bytes plus the remainder from a system page (the minimal | ||
| 64 | mmap unit); typically 4096 or 8192 bytes. | ||
| 65 | |||
| 66 | Security: static-safe; optionally more or less | ||
| 67 | The "security" of malloc refers to the ability of malicious | ||
| 68 | code to accentuate the effects of errors (for example, freeing | ||
| 69 | space that is not currently malloc'ed or overwriting past the | ||
| 70 | ends of chunks) in code that calls malloc. This malloc | ||
| 71 | guarantees not to modify any memory locations below the base of | ||
| 72 | heap, i.e., static variables, even in the presence of usage | ||
| 73 | errors. The routines additionally detect most improper frees | ||
| 74 | and reallocs. All this holds as long as the static bookkeeping | ||
| 75 | for malloc itself is not corrupted by some other means. This | ||
| 76 | is only one aspect of security -- these checks do not, and | ||
| 77 | cannot, detect all possible programming errors. | ||
| 78 | |||
| 79 | If FOOTERS is defined nonzero, then each allocated chunk | ||
| 80 | carries an additional check word to verify that it was malloced | ||
| 81 | from its space. These check words are the same within each | ||
| 82 | execution of a program using malloc, but differ across | ||
| 83 | executions, so externally crafted fake chunks cannot be | ||
| 84 | freed. This improves security by rejecting frees/reallocs that | ||
| 85 | could corrupt heap memory, in addition to the checks preventing | ||
| 86 | writes to statics that are always on. This may further improve | ||
| 87 | security at the expense of time and space overhead. (Note that | ||
| 88 | FOOTERS may also be worth using with MSPACES.) | ||
| 89 | |||
| 90 | By default detected errors cause the program to abort (calling | ||
| 91 | "abort()"). You can override this to instead proceed past | ||
| 92 | errors by defining PROCEED_ON_ERROR. In this case, a bad free | ||
| 93 | has no effect, and a malloc that encounters a bad address | ||
| 94 | caused by user overwrites will ignore the bad address by | ||
| 95 | dropping pointers and indices to all known memory. This may | ||
| 96 | be appropriate for programs that should continue if at all | ||
| 97 | possible in the face of programming errors, although they may | ||
| 98 | run out of memory because dropped memory is never reclaimed. | ||
| 99 | |||
| 100 | If you don't like either of these options, you can define | ||
| 101 | CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything | ||
| 102 | else. And if if you are sure that your program using malloc has | ||
| 103 | no errors or vulnerabilities, you can define INSECURE to 1, | ||
| 104 | which might (or might not) provide a small performance improvement. | ||
| 105 | |||
| 106 | It is also possible to limit the maximum total allocatable | ||
| 107 | space, using malloc_set_footprint_limit. This is not | ||
| 108 | designed as a security feature in itself (calls to set limits | ||
| 109 | are not screened or privileged), but may be useful as one | ||
| 110 | aspect of a secure implementation. | ||
| 111 | |||
| 112 | Thread-safety: NOT thread-safe unless USE_LOCKS defined non-zero | ||
| 113 | When USE_LOCKS is defined, each public call to malloc, free, | ||
| 114 | etc is surrounded with a lock. By default, this uses a plain | ||
| 115 | pthread mutex, win32 critical section, or a spin-lock if if | ||
| 116 | available for the platform and not disabled by setting | ||
| 117 | USE_SPIN_LOCKS=0. However, if USE_RECURSIVE_LOCKS is defined, | ||
| 118 | recursive versions are used instead (which are not required for | ||
| 119 | base functionality but may be needed in layered extensions). | ||
| 120 | Using a global lock is not especially fast, and can be a major | ||
| 121 | bottleneck. It is designed only to provide minimal protection | ||
| 122 | in concurrent environments, and to provide a basis for | ||
| 123 | extensions. If you are using malloc in a concurrent program, | ||
| 124 | consider instead using nedmalloc | ||
| 125 | (http://www.nedprod.com/programs/portable/nedmalloc/) or | ||
| 126 | ptmalloc (See http://www.malloc.de), which are derived from | ||
| 127 | versions of this malloc. | ||
| 128 | |||
| 129 | System requirements: Any combination of MORECORE and/or MMAP/MUNMAP | ||
| 130 | This malloc can use unix sbrk or any emulation (invoked using | ||
| 131 | the CALL_MORECORE macro) and/or mmap/munmap or any emulation | ||
| 132 | (invoked using CALL_MMAP/CALL_MUNMAP) to get and release system | ||
| 133 | memory. On most unix systems, it tends to work best if both | ||
| 134 | MORECORE and MMAP are enabled. On Win32, it uses emulations | ||
| 135 | based on VirtualAlloc. It also uses common C library functions | ||
| 136 | like memset. | ||
| 137 | |||
| 138 | Compliance: I believe it is compliant with the Single Unix Specification | ||
| 139 | (See http://www.unix.org). Also SVID/XPG, ANSI C, and probably | ||
| 140 | others as well. | ||
| 141 | |||
| 142 | * Overview of algorithms | ||
| 143 | |||
| 144 | This is not the fastest, most space-conserving, most portable, or | ||
| 145 | most tunable malloc ever written. However it is among the fastest | ||
| 146 | while also being among the most space-conserving, portable and | ||
| 147 | tunable. Consistent balance across these factors results in a good | ||
| 148 | general-purpose allocator for malloc-intensive programs. | ||
| 149 | |||
| 150 | In most ways, this malloc is a best-fit allocator. Generally, it | ||
| 151 | chooses the best-fitting existing chunk for a request, with ties | ||
| 152 | broken in approximately least-recently-used order. (This strategy | ||
| 153 | normally maintains low fragmentation.) However, for requests less | ||
| 154 | than 256bytes, it deviates from best-fit when there is not an | ||
| 155 | exactly fitting available chunk by preferring to use space adjacent | ||
| 156 | to that used for the previous small request, as well as by breaking | ||
| 157 | ties in approximately most-recently-used order. (These enhance | ||
| 158 | locality of series of small allocations.) And for very large requests | ||
| 159 | (>= 256Kb by default), it relies on system memory mapping | ||
| 160 | facilities, if supported. (This helps avoid carrying around and | ||
| 161 | possibly fragmenting memory used only for large chunks.) | ||
| 162 | |||
| 163 | All operations (except malloc_stats and mallinfo) have execution | ||
| 164 | times that are bounded by a constant factor of the number of bits in | ||
| 165 | a size_t, not counting any clearing in calloc or copying in realloc, | ||
| 166 | or actions surrounding MORECORE and MMAP that have times | ||
| 167 | proportional to the number of non-contiguous regions returned by | ||
| 168 | system allocation routines, which is often just 1. In real-time | ||
| 169 | applications, you can optionally suppress segment traversals using | ||
| 170 | NO_SEGMENT_TRAVERSAL, which assures bounded execution even when | ||
| 171 | system allocators return non-contiguous spaces, at the typical | ||
| 172 | expense of carrying around more memory and increased fragmentation. | ||
| 173 | |||
| 174 | The implementation is not very modular and seriously overuses | ||
| 175 | macros. Perhaps someday all C compilers will do as good a job | ||
| 176 | inlining modular code as can now be done by brute-force expansion, | ||
| 177 | but now, enough of them seem not to. | ||
| 178 | |||
| 179 | Some compilers issue a lot of warnings about code that is | ||
| 180 | dead/unreachable only on some platforms, and also about intentional | ||
| 181 | uses of negation on unsigned types. All known cases of each can be | ||
| 182 | ignored. | ||
| 183 | |||
| 184 | For a longer but out of date high-level description, see | ||
| 185 | http://gee.cs.oswego.edu/dl/html/malloc.html | ||
| 186 | |||
| 187 | * MSPACES | ||
| 188 | If MSPACES is defined, then in addition to malloc, free, etc., | ||
| 189 | this file also defines mspace_malloc, mspace_free, etc. These | ||
| 190 | are versions of malloc routines that take an "mspace" argument | ||
| 191 | obtained using create_mspace, to control all internal bookkeeping. | ||
| 192 | If ONLY_MSPACES is defined, only these versions are compiled. | ||
| 193 | So if you would like to use this allocator for only some allocations, | ||
| 194 | and your system malloc for others, you can compile with | ||
| 195 | ONLY_MSPACES and then do something like... | ||
| 196 | static mspace mymspace = create_mspace(0,0); // for example | ||
| 197 | #define mymalloc(bytes) mspace_malloc(mymspace, bytes) | ||
| 198 | |||
| 199 | (Note: If you only need one instance of an mspace, you can instead | ||
| 200 | use "USE_DL_PREFIX" to relabel the global malloc.) | ||
| 201 | |||
| 202 | You can similarly create thread-local allocators by storing | ||
| 203 | mspaces as thread-locals. For example: | ||
| 204 | static __thread mspace tlms = 0; | ||
| 205 | void* tlmalloc(size_t bytes) { | ||
| 206 | if (tlms == 0) tlms = create_mspace(0, 0); | ||
| 207 | return mspace_malloc(tlms, bytes); | ||
| 208 | } | ||
| 209 | void tlfree(void* mem) { mspace_free(tlms, mem); } | ||
| 210 | |||
| 211 | Unless FOOTERS is defined, each mspace is completely independent. | ||
| 212 | You cannot allocate from one and free to another (although | ||
| 213 | conformance is only weakly checked, so usage errors are not always | ||
| 214 | caught). If FOOTERS is defined, then each chunk carries around a tag | ||
| 215 | indicating its originating mspace, and frees are directed to their | ||
| 216 | originating spaces. Normally, this requires use of locks. | ||
| 217 | |||
| 218 | ------------------------- Compile-time options --------------------------- | ||
| 219 | |||
| 220 | Be careful in setting #define values for numerical constants of type | ||
| 221 | size_t. On some systems, literal values are not automatically extended | ||
| 222 | to size_t precision unless they are explicitly casted. You can also | ||
| 223 | use the symbolic values MAX_SIZE_T, SIZE_T_ONE, etc below. | ||
| 224 | |||
| 225 | WIN32 default: defined if _WIN32 defined | ||
| 226 | Defining WIN32 sets up defaults for MS environment and compilers. | ||
| 227 | Otherwise defaults are for unix. Beware that there seem to be some | ||
| 228 | cases where this malloc might not be a pure drop-in replacement for | ||
| 229 | Win32 malloc: Random-looking failures from Win32 GDI API's (eg; | ||
| 230 | SetDIBits()) may be due to bugs in some video driver implementations | ||
| 231 | when pixel buffers are malloc()ed, and the region spans more than | ||
| 232 | one VirtualAlloc()ed region. Because dlmalloc uses a small (64Kb) | ||
| 233 | default granularity, pixel buffers may straddle virtual allocation | ||
| 234 | regions more often than when using the Microsoft allocator. You can | ||
| 235 | avoid this by using VirtualAlloc() and VirtualFree() for all pixel | ||
| 236 | buffers rather than using malloc(). If this is not possible, | ||
| 237 | recompile this malloc with a larger DEFAULT_GRANULARITY. Note: | ||
| 238 | in cases where MSC and gcc (cygwin) are known to differ on WIN32, | ||
| 239 | conditions use _MSC_VER to distinguish them. | ||
| 240 | |||
| 241 | DLMALLOC_EXPORT default: extern | ||
| 242 | Defines how public APIs are declared. If you want to export via a | ||
| 243 | Windows DLL, you might define this as | ||
| 244 | #define DLMALLOC_EXPORT extern __declspec(dllexport) | ||
| 245 | If you want a POSIX ELF shared object, you might use | ||
| 246 | #define DLMALLOC_EXPORT extern __attribute__((visibility("default"))) | ||
| 247 | |||
| 248 | MALLOC_ALIGNMENT default: (size_t)(2 * sizeof(void *)) | ||
| 249 | Controls the minimum alignment for malloc'ed chunks. It must be a | ||
| 250 | power of two and at least 8, even on machines for which smaller | ||
| 251 | alignments would suffice. It may be defined as larger than this | ||
| 252 | though. Note however that code and data structures are optimized for | ||
| 253 | the case of 8-byte alignment. | ||
| 254 | |||
| 255 | MSPACES default: 0 (false) | ||
| 256 | If true, compile in support for independent allocation spaces. | ||
| 257 | This is only supported if HAVE_MMAP is true. | ||
| 258 | |||
| 259 | ONLY_MSPACES default: 0 (false) | ||
| 260 | If true, only compile in mspace versions, not regular versions. | ||
| 261 | |||
| 262 | USE_LOCKS default: 0 (false) | ||
| 263 | Causes each call to each public routine to be surrounded with | ||
| 264 | pthread or WIN32 mutex lock/unlock. (If set true, this can be | ||
| 265 | overridden on a per-mspace basis for mspace versions.) If set to a | ||
| 266 | non-zero value other than 1, locks are used, but their | ||
| 267 | implementation is left out, so lock functions must be supplied manually, | ||
| 268 | as described below. | ||
| 269 | |||
| 270 | USE_SPIN_LOCKS default: 1 iff USE_LOCKS and spin locks available | ||
| 271 | If true, uses custom spin locks for locking. This is currently | ||
| 272 | supported only gcc >= 4.1, older gccs on x86 platforms, and recent | ||
| 273 | MS compilers. Otherwise, posix locks or win32 critical sections are | ||
| 274 | used. | ||
| 275 | |||
| 276 | USE_RECURSIVE_LOCKS default: not defined | ||
| 277 | If defined nonzero, uses recursive (aka reentrant) locks, otherwise | ||
| 278 | uses plain mutexes. This is not required for malloc proper, but may | ||
| 279 | be needed for layered allocators such as nedmalloc. | ||
| 280 | |||
| 281 | LOCK_AT_FORK default: not defined | ||
| 282 | If defined nonzero, performs pthread_atfork upon initialization | ||
| 283 | to initialize child lock while holding parent lock. The implementation | ||
| 284 | assumes that pthread locks (not custom locks) are being used. In other | ||
| 285 | cases, you may need to customize the implementation. | ||
| 286 | |||
| 287 | FOOTERS default: 0 | ||
| 288 | If true, provide extra checking and dispatching by placing | ||
| 289 | information in the footers of allocated chunks. This adds | ||
| 290 | space and time overhead. | ||
| 291 | |||
| 292 | INSECURE default: 0 | ||
| 293 | If true, omit checks for usage errors and heap space overwrites. | ||
| 294 | |||
| 295 | USE_DL_PREFIX default: NOT defined | ||
| 296 | Causes compiler to prefix all public routines with the string 'dl'. | ||
| 297 | This can be useful when you only want to use this malloc in one part | ||
| 298 | of a program, using your regular system malloc elsewhere. | ||
| 299 | |||
| 300 | MALLOC_INSPECT_ALL default: NOT defined | ||
| 301 | If defined, compiles malloc_inspect_all and mspace_inspect_all, that | ||
| 302 | perform traversal of all heap space. Unless access to these | ||
| 303 | functions is otherwise restricted, you probably do not want to | ||
| 304 | include them in secure implementations. | ||
| 305 | |||
| 306 | ABORT default: defined as abort() | ||
| 307 | Defines how to abort on failed checks. On most systems, a failed | ||
| 308 | check cannot die with an "assert" or even print an informative | ||
| 309 | message, because the underlying print routines in turn call malloc, | ||
| 310 | which will fail again. Generally, the best policy is to simply call | ||
| 311 | abort(). It's not very useful to do more than this because many | ||
| 312 | errors due to overwriting will show up as address faults (null, odd | ||
| 313 | addresses etc) rather than malloc-triggered checks, so will also | ||
| 314 | abort. Also, most compilers know that abort() does not return, so | ||
| 315 | can better optimize code conditionally calling it. | ||
| 316 | |||
| 317 | PROCEED_ON_ERROR default: defined as 0 (false) | ||
| 318 | Controls whether detected bad addresses cause them to bypassed | ||
| 319 | rather than aborting. If set, detected bad arguments to free and | ||
| 320 | realloc are ignored. And all bookkeeping information is zeroed out | ||
| 321 | upon a detected overwrite of freed heap space, thus losing the | ||
| 322 | ability to ever return it from malloc again, but enabling the | ||
| 323 | application to proceed. If PROCEED_ON_ERROR is defined, the | ||
| 324 | static variable malloc_corruption_error_count is compiled in | ||
| 325 | and can be examined to see if errors have occurred. This option | ||
| 326 | generates slower code than the default abort policy. | ||
| 327 | |||
| 328 | DEBUG default: NOT defined | ||
| 329 | The DEBUG setting is mainly intended for people trying to modify | ||
| 330 | this code or diagnose problems when porting to new platforms. | ||
| 331 | However, it may also be able to better isolate user errors than just | ||
| 332 | using runtime checks. The assertions in the check routines spell | ||
| 333 | out in more detail the assumptions and invariants underlying the | ||
| 334 | algorithms. The checking is fairly extensive, and will slow down | ||
| 335 | execution noticeably. Calling malloc_stats or mallinfo with DEBUG | ||
| 336 | set will attempt to check every non-mmapped allocated and free chunk | ||
| 337 | in the course of computing the summaries. | ||
| 338 | |||
| 339 | ABORT_ON_ASSERT_FAILURE default: defined as 1 (true) | ||
| 340 | Debugging assertion failures can be nearly impossible if your | ||
| 341 | version of the assert macro causes malloc to be called, which will | ||
| 342 | lead to a cascade of further failures, blowing the runtime stack. | ||
| 343 | ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(), | ||
| 344 | which will usually make debugging easier. | ||
| 345 | |||
| 346 | MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32 | ||
| 347 | The action to take before "return 0" when malloc fails to be able to | ||
| 348 | return memory because there is none available. | ||
| 349 | |||
| 350 | HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES | ||
| 351 | True if this system supports sbrk or an emulation of it. | ||
| 352 | |||
| 353 | MORECORE default: sbrk | ||
| 354 | The name of the sbrk-style system routine to call to obtain more | ||
| 355 | memory. See below for guidance on writing custom MORECORE | ||
| 356 | functions. The type of the argument to sbrk/MORECORE varies across | ||
| 357 | systems. It cannot be size_t, because it supports negative | ||
| 358 | arguments, so it is normally the signed type of the same width as | ||
| 359 | size_t (sometimes declared as "intptr_t"). It doesn't much matter | ||
| 360 | though. Internally, we only call it with arguments less than half | ||
| 361 | the max value of a size_t, which should work across all reasonable | ||
| 362 | possibilities, although sometimes generating compiler warnings. | ||
| 363 | |||
| 364 | MORECORE_CONTIGUOUS default: 1 (true) if HAVE_MORECORE | ||
| 365 | If true, take advantage of fact that consecutive calls to MORECORE | ||
| 366 | with positive arguments always return contiguous increasing | ||
| 367 | addresses. This is true of unix sbrk. It does not hurt too much to | ||
| 368 | set it true anyway, since malloc copes with non-contiguities. | ||
| 369 | Setting it false when definitely non-contiguous saves time | ||
| 370 | and possibly wasted space it would take to discover this though. | ||
| 371 | |||
| 372 | MORECORE_CANNOT_TRIM default: NOT defined | ||
| 373 | True if MORECORE cannot release space back to the system when given | ||
| 374 | negative arguments. This is generally necessary only if you are | ||
| 375 | using a hand-crafted MORECORE function that cannot handle negative | ||
| 376 | arguments. | ||
| 377 | |||
| 378 | NO_SEGMENT_TRAVERSAL default: 0 | ||
| 379 | If non-zero, suppresses traversals of memory segments | ||
| 380 | returned by either MORECORE or CALL_MMAP. This disables | ||
| 381 | merging of segments that are contiguous, and selectively | ||
| 382 | releasing them to the OS if unused, but bounds execution times. | ||
| 383 | |||
| 384 | HAVE_MMAP default: 1 (true) | ||
| 385 | True if this system supports mmap or an emulation of it. If so, and | ||
| 386 | HAVE_MORECORE is not true, MMAP is used for all system | ||
| 387 | allocation. If set and HAVE_MORECORE is true as well, MMAP is | ||
| 388 | primarily used to directly allocate very large blocks. It is also | ||
| 389 | used as a backup strategy in cases where MORECORE fails to provide | ||
| 390 | space from system. Note: A single call to MUNMAP is assumed to be | ||
| 391 | able to unmap memory that may have be allocated using multiple calls | ||
| 392 | to MMAP, so long as they are adjacent. | ||
| 393 | |||
| 394 | HAVE_MREMAP default: 1 on linux, else 0 | ||
| 395 | If true realloc() uses mremap() to re-allocate large blocks and | ||
| 396 | extend or shrink allocation spaces. | ||
| 397 | |||
| 398 | MMAP_CLEARS default: 1 except on WINCE. | ||
| 399 | True if mmap clears memory so calloc doesn't need to. This is true | ||
| 400 | for standard unix mmap using /dev/zero and on WIN32 except for WINCE. | ||
| 401 | |||
| 402 | USE_BUILTIN_FFS default: 0 (i.e., not used) | ||
| 403 | Causes malloc to use the builtin ffs() function to compute indices. | ||
| 404 | Some compilers may recognize and intrinsify ffs to be faster than the | ||
| 405 | supplied C version. Also, the case of x86 using gcc is special-cased | ||
| 406 | to an asm instruction, so is already as fast as it can be, and so | ||
| 407 | this setting has no effect. Similarly for Win32 under recent MS compilers. | ||
| 408 | (On most x86s, the asm version is only slightly faster than the C version.) | ||
| 409 | |||
| 410 | malloc_getpagesize default: derive from system includes, or 4096. | ||
| 411 | The system page size. To the extent possible, this malloc manages | ||
| 412 | memory from the system in page-size units. This may be (and | ||
| 413 | usually is) a function rather than a constant. This is ignored | ||
| 414 | if WIN32, where page size is determined using getSystemInfo during | ||
| 415 | initialization. | ||
| 416 | |||
| 417 | USE_DEV_RANDOM default: 0 (i.e., not used) | ||
| 418 | Causes malloc to use /dev/random to initialize secure magic seed for | ||
| 419 | stamping footers. Otherwise, the current time is used. | ||
| 420 | |||
| 421 | NO_MALLINFO default: 0 | ||
| 422 | If defined, don't compile "mallinfo". This can be a simple way | ||
| 423 | of dealing with mismatches between system declarations and | ||
| 424 | those in this file. | ||
| 425 | |||
| 426 | MALLINFO_FIELD_TYPE default: size_t | ||
| 427 | The type of the fields in the mallinfo struct. This was originally | ||
| 428 | defined as "int" in SVID etc, but is more usefully defined as | ||
| 429 | size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set | ||
| 430 | |||
| 431 | NO_MALLOC_STATS default: 0 | ||
| 432 | If defined, don't compile "malloc_stats". This avoids calls to | ||
| 433 | fprintf and bringing in stdio dependencies you might not want. | ||
| 434 | |||
| 435 | REALLOC_ZERO_BYTES_FREES default: not defined | ||
| 436 | This should be set if a call to realloc with zero bytes should | ||
| 437 | be the same as a call to free. Some people think it should. Otherwise, | ||
| 438 | since this malloc returns a unique pointer for malloc(0), so does | ||
| 439 | realloc(p, 0). | ||
| 440 | |||
| 441 | LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H | ||
| 442 | LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H | ||
| 443 | LACKS_STDLIB_H LACKS_SCHED_H LACKS_TIME_H default: NOT defined unless on WIN32 | ||
| 444 | Define these if your system does not have these header files. | ||
| 445 | You might need to manually insert some of the declarations they provide. | ||
| 446 | |||
| 447 | DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS, | ||
| 448 | system_info.dwAllocationGranularity in WIN32, | ||
| 449 | otherwise 64K. | ||
| 450 | Also settable using mallopt(M_GRANULARITY, x) | ||
| 451 | The unit for allocating and deallocating memory from the system. On | ||
| 452 | most systems with contiguous MORECORE, there is no reason to | ||
| 453 | make this more than a page. However, systems with MMAP tend to | ||
| 454 | either require or encourage larger granularities. You can increase | ||
| 455 | this value to prevent system allocation functions to be called so | ||
| 456 | often, especially if they are slow. The value must be at least one | ||
| 457 | page and must be a power of two. Setting to 0 causes initialization | ||
| 458 | to either page size or win32 region size. (Note: In previous | ||
| 459 | versions of malloc, the equivalent of this option was called | ||
| 460 | "TOP_PAD") | ||
| 461 | |||
| 462 | DEFAULT_TRIM_THRESHOLD default: 2MB | ||
| 463 | Also settable using mallopt(M_TRIM_THRESHOLD, x) | ||
| 464 | The maximum amount of unused top-most memory to keep before | ||
| 465 | releasing via malloc_trim in free(). Automatic trimming is mainly | ||
| 466 | useful in long-lived programs using contiguous MORECORE. Because | ||
| 467 | trimming via sbrk can be slow on some systems, and can sometimes be | ||
| 468 | wasteful (in cases where programs immediately afterward allocate | ||
| 469 | more large chunks) the value should be high enough so that your | ||
| 470 | overall system performance would improve by releasing this much | ||
| 471 | memory. As a rough guide, you might set to a value close to the | ||
| 472 | average size of a process (program) running on your system. | ||
| 473 | Releasing this much memory would allow such a process to run in | ||
| 474 | memory. Generally, it is worth tuning trim thresholds when a | ||
| 475 | program undergoes phases where several large chunks are allocated | ||
| 476 | and released in ways that can reuse each other's storage, perhaps | ||
| 477 | mixed with phases where there are no such chunks at all. The trim | ||
| 478 | value must be greater than page size to have any useful effect. To | ||
| 479 | disable trimming completely, you can set to MAX_SIZE_T. Note that the trick | ||
| 480 | some people use of mallocing a huge space and then freeing it at | ||
| 481 | program startup, in an attempt to reserve system memory, doesn't | ||
| 482 | have the intended effect under automatic trimming, since that memory | ||
| 483 | will immediately be returned to the system. | ||
| 484 | |||
| 485 | DEFAULT_MMAP_THRESHOLD default: 256K | ||
| 486 | Also settable using mallopt(M_MMAP_THRESHOLD, x) | ||
| 487 | The request size threshold for using MMAP to directly service a | ||
| 488 | request. Requests of at least this size that cannot be allocated | ||
| 489 | using already-existing space will be serviced via mmap. (If enough | ||
| 490 | normal freed space already exists it is used instead.) Using mmap | ||
| 491 | segregates relatively large chunks of memory so that they can be | ||
| 492 | individually obtained and released from the host system. A request | ||
| 493 | serviced through mmap is never reused by any other request (at least | ||
| 494 | not directly; the system may just so happen to remap successive | ||
| 495 | requests to the same locations). Segregating space in this way has | ||
| 496 | the benefits that: Mmapped space can always be individually released | ||
| 497 | back to the system, which helps keep the system level memory demands | ||
| 498 | of a long-lived program low. Also, mapped memory doesn't become | ||
| 499 | `locked' between other chunks, as can happen with normally allocated | ||
| 500 | chunks, which means that even trimming via malloc_trim would not | ||
| 501 | release them. However, it has the disadvantage that the space | ||
| 502 | cannot be reclaimed, consolidated, and then used to service later | ||
| 503 | requests, as happens with normal chunks. The advantages of mmap | ||
| 504 | nearly always outweigh disadvantages for "large" chunks, but the | ||
| 505 | value of "large" may vary across systems. The default is an | ||
| 506 | empirically derived value that works well in most systems. You can | ||
| 507 | disable mmap by setting to MAX_SIZE_T. | ||
| 508 | |||
| 509 | MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP | ||
| 510 | The number of consolidated frees between checks to release | ||
| 511 | unused segments when freeing. When using non-contiguous segments, | ||
| 512 | especially with multiple mspaces, checking only for topmost space | ||
| 513 | doesn't always suffice to trigger trimming. To compensate for this, | ||
| 514 | free() will, with a period of MAX_RELEASE_CHECK_RATE (or the | ||
| 515 | current number of segments, if greater) try to release unused | ||
| 516 | segments to the OS when freeing chunks that result in | ||
| 517 | consolidation. The best value for this parameter is a compromise | ||
| 518 | between slowing down frees with relatively costly checks that | ||
| 519 | rarely trigger versus holding on to unused memory. To effectively | ||
| 520 | disable, set to MAX_SIZE_T. This may lead to a very slight speed | ||
| 521 | improvement at the expense of carrying around more memory. | ||
| 522 | */ | ||
| 523 | |||
| 524 | /* Version identifier to allow people to support multiple versions */ | ||
| 525 | #ifndef DLMALLOC_VERSION | ||
| 526 | #define DLMALLOC_VERSION 20806 | ||
| 527 | #endif /* DLMALLOC_VERSION */ | ||
| 528 | |||
| 529 | #ifndef DLMALLOC_EXPORT | ||
| 530 | #define DLMALLOC_EXPORT extern | ||
| 531 | #endif | ||
| 532 | |||
| 533 | #ifndef WIN32 | ||
| 534 | #ifdef _WIN32 | ||
| 535 | #define WIN32 1 | ||
| 536 | #endif /* _WIN32 */ | ||
| 537 | #ifdef _WIN32_WCE | ||
| 538 | #define LACKS_FCNTL_H | ||
| 539 | #define WIN32 1 | ||
| 540 | #endif /* _WIN32_WCE */ | ||
| 541 | #endif /* WIN32 */ | ||
| 542 | #ifdef WIN32 | ||
| 543 | #define WIN32_LEAN_AND_MEAN | ||
| 544 | #include <windows.h> | ||
| 545 | #include <tchar.h> | ||
| 546 | #define HAVE_MMAP 1 | ||
| 547 | #define HAVE_MORECORE 0 | ||
| 548 | #define LACKS_UNISTD_H | ||
| 549 | #define LACKS_SYS_PARAM_H | ||
| 550 | #define LACKS_SYS_MMAN_H | ||
| 551 | #define LACKS_STRING_H | ||
| 552 | #define LACKS_STRINGS_H | ||
| 553 | #define LACKS_SYS_TYPES_H | ||
| 554 | #define LACKS_ERRNO_H | ||
| 555 | #define LACKS_SCHED_H | ||
| 556 | #ifndef MALLOC_FAILURE_ACTION | ||
| 557 | #define MALLOC_FAILURE_ACTION | ||
| 558 | #endif /* MALLOC_FAILURE_ACTION */ | ||
| 559 | #ifndef MMAP_CLEARS | ||
| 560 | #ifdef _WIN32_WCE /* WINCE reportedly does not clear */ | ||
| 561 | #define MMAP_CLEARS 0 | ||
| 562 | #else | ||
| 563 | #define MMAP_CLEARS 1 | ||
| 564 | #endif /* _WIN32_WCE */ | ||
| 565 | #endif /*MMAP_CLEARS */ | ||
| 566 | #endif /* WIN32 */ | ||
| 567 | |||
| 568 | #if defined(DARWIN) || defined(_DARWIN) | ||
| 569 | /* Mac OSX docs advise not to use sbrk; it seems better to use mmap */ | ||
| 570 | #ifndef HAVE_MORECORE | ||
| 571 | #define HAVE_MORECORE 0 | ||
| 572 | #define HAVE_MMAP 1 | ||
| 573 | /* OSX allocators provide 16 byte alignment */ | ||
| 574 | #ifndef MALLOC_ALIGNMENT | ||
| 575 | #define MALLOC_ALIGNMENT ((size_t)16U) | ||
| 576 | #endif | ||
| 577 | #endif /* HAVE_MORECORE */ | ||
| 578 | #endif /* DARWIN */ | ||
| 579 | |||
| 580 | #ifndef LACKS_SYS_TYPES_H | ||
| 581 | #include <sys/types.h> /* For size_t */ | ||
| 582 | #endif /* LACKS_SYS_TYPES_H */ | ||
| 583 | |||
| 584 | /* The maximum possible size_t value has all bits set */ | ||
| 585 | #define MAX_SIZE_T (~(size_t)0) | ||
| 586 | |||
| 587 | #ifndef USE_LOCKS /* ensure true if spin or recursive locks set */ | ||
| 588 | #if 0 | ||
| 589 | #define USE_LOCKS ((defined(USE_SPIN_LOCKS) && USE_SPIN_LOCKS != 0) || \ | ||
| 590 | (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0)) | ||
| 591 | #else | ||
| 592 | /* Avoid a -Wexpansion-to-defined compiler warning. */ | ||
| 593 | #if (defined(USE_SPIN_LOCKS) && USE_SPIN_LOCKS != 0) || \ | ||
| 594 | (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0) | ||
| 595 | #define USE_LOCKS 1 | ||
| 596 | #else | ||
| 597 | #define USE_LOCKS 0 | ||
| 598 | #endif | ||
| 599 | #endif | ||
| 600 | #endif /* USE_LOCKS */ | ||
| 601 | |||
| 602 | #if USE_LOCKS /* Spin locks for gcc >= 4.1, older gcc on x86, MSC >= 1310 */ | ||
| 603 | #if ((defined(__GNUC__) && \ | ||
| 604 | ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) || \ | ||
| 605 | defined(__i386__) || defined(__x86_64__))) || \ | ||
| 606 | (defined(_MSC_VER) && _MSC_VER>=1310)) | ||
| 607 | #ifndef USE_SPIN_LOCKS | ||
| 608 | #define USE_SPIN_LOCKS 1 | ||
| 609 | #endif /* USE_SPIN_LOCKS */ | ||
| 610 | #elif USE_SPIN_LOCKS | ||
| 611 | #error "USE_SPIN_LOCKS defined without implementation" | ||
| 612 | #endif /* ... locks available... */ | ||
| 613 | #elif !defined(USE_SPIN_LOCKS) | ||
| 614 | #define USE_SPIN_LOCKS 0 | ||
| 615 | #endif /* USE_LOCKS */ | ||
| 616 | |||
| 617 | #ifndef ONLY_MSPACES | ||
| 618 | #define ONLY_MSPACES 0 | ||
| 619 | #endif /* ONLY_MSPACES */ | ||
| 620 | #ifndef MSPACES | ||
| 621 | #if ONLY_MSPACES | ||
| 622 | #define MSPACES 1 | ||
| 623 | #else /* ONLY_MSPACES */ | ||
| 624 | #define MSPACES 0 | ||
| 625 | #endif /* ONLY_MSPACES */ | ||
| 626 | #endif /* MSPACES */ | ||
| 627 | #ifndef MALLOC_ALIGNMENT | ||
| 628 | #define MALLOC_ALIGNMENT ((size_t)(2 * sizeof(void *))) | ||
| 629 | #endif /* MALLOC_ALIGNMENT */ | ||
| 630 | #ifndef FOOTERS | ||
| 631 | #define FOOTERS 0 | ||
| 632 | #endif /* FOOTERS */ | ||
| 633 | #ifndef ABORT | ||
| 634 | #define ABORT abort() | ||
| 635 | #endif /* ABORT */ | ||
| 636 | #ifndef ABORT_ON_ASSERT_FAILURE | ||
| 637 | #define ABORT_ON_ASSERT_FAILURE 1 | ||
| 638 | #endif /* ABORT_ON_ASSERT_FAILURE */ | ||
| 639 | #ifndef PROCEED_ON_ERROR | ||
| 640 | #define PROCEED_ON_ERROR 0 | ||
| 641 | #endif /* PROCEED_ON_ERROR */ | ||
| 642 | |||
| 643 | #ifndef INSECURE | ||
| 644 | #define INSECURE 0 | ||
| 645 | #endif /* INSECURE */ | ||
| 646 | #ifndef MALLOC_INSPECT_ALL | ||
| 647 | #define MALLOC_INSPECT_ALL 0 | ||
| 648 | #endif /* MALLOC_INSPECT_ALL */ | ||
| 649 | #ifndef HAVE_MMAP | ||
| 650 | #define HAVE_MMAP 1 | ||
| 651 | #endif /* HAVE_MMAP */ | ||
| 652 | #ifndef MMAP_CLEARS | ||
| 653 | #define MMAP_CLEARS 1 | ||
| 654 | #endif /* MMAP_CLEARS */ | ||
| 655 | #ifndef HAVE_MREMAP | ||
| 656 | #ifdef linux | ||
| 657 | #define HAVE_MREMAP 1 | ||
| 658 | #define _GNU_SOURCE /* Turns on mremap() definition */ | ||
| 659 | #else /* linux */ | ||
| 660 | #define HAVE_MREMAP 0 | ||
| 661 | #endif /* linux */ | ||
| 662 | #endif /* HAVE_MREMAP */ | ||
| 663 | #ifndef MALLOC_FAILURE_ACTION | ||
| 664 | #define MALLOC_FAILURE_ACTION errno = ENOMEM; | ||
| 665 | #endif /* MALLOC_FAILURE_ACTION */ | ||
| 666 | #ifndef HAVE_MORECORE | ||
| 667 | #if ONLY_MSPACES | ||
| 668 | #define HAVE_MORECORE 0 | ||
| 669 | #else /* ONLY_MSPACES */ | ||
| 670 | #define HAVE_MORECORE 1 | ||
| 671 | #endif /* ONLY_MSPACES */ | ||
| 672 | #endif /* HAVE_MORECORE */ | ||
| 673 | #if !HAVE_MORECORE | ||
| 674 | #define MORECORE_CONTIGUOUS 0 | ||
| 675 | #else /* !HAVE_MORECORE */ | ||
| 676 | #define MORECORE_DEFAULT sbrk | ||
| 677 | #ifndef MORECORE_CONTIGUOUS | ||
| 678 | #define MORECORE_CONTIGUOUS 1 | ||
| 679 | #endif /* MORECORE_CONTIGUOUS */ | ||
| 680 | #endif /* HAVE_MORECORE */ | ||
| 681 | #ifndef DEFAULT_GRANULARITY | ||
| 682 | #if (MORECORE_CONTIGUOUS || defined(WIN32)) | ||
| 683 | #define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ | ||
| 684 | #else /* MORECORE_CONTIGUOUS */ | ||
| 685 | #define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U) | ||
| 686 | #endif /* MORECORE_CONTIGUOUS */ | ||
| 687 | #endif /* DEFAULT_GRANULARITY */ | ||
| 688 | #ifndef DEFAULT_TRIM_THRESHOLD | ||
| 689 | #ifndef MORECORE_CANNOT_TRIM | ||
| 690 | #define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) | ||
| 691 | #else /* MORECORE_CANNOT_TRIM */ | ||
| 692 | #define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T | ||
| 693 | #endif /* MORECORE_CANNOT_TRIM */ | ||
| 694 | #endif /* DEFAULT_TRIM_THRESHOLD */ | ||
| 695 | #ifndef DEFAULT_MMAP_THRESHOLD | ||
| 696 | #if HAVE_MMAP | ||
| 697 | #define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U) | ||
| 698 | #else /* HAVE_MMAP */ | ||
| 699 | #define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T | ||
| 700 | #endif /* HAVE_MMAP */ | ||
| 701 | #endif /* DEFAULT_MMAP_THRESHOLD */ | ||
| 702 | #ifndef MAX_RELEASE_CHECK_RATE | ||
| 703 | #if HAVE_MMAP | ||
| 704 | #define MAX_RELEASE_CHECK_RATE 4095 | ||
| 705 | #else | ||
| 706 | #define MAX_RELEASE_CHECK_RATE MAX_SIZE_T | ||
| 707 | #endif /* HAVE_MMAP */ | ||
| 708 | #endif /* MAX_RELEASE_CHECK_RATE */ | ||
| 709 | #ifndef USE_BUILTIN_FFS | ||
| 710 | #define USE_BUILTIN_FFS 0 | ||
| 711 | #endif /* USE_BUILTIN_FFS */ | ||
| 712 | #ifndef USE_DEV_RANDOM | ||
| 713 | #define USE_DEV_RANDOM 0 | ||
| 714 | #endif /* USE_DEV_RANDOM */ | ||
| 715 | #ifndef NO_MALLINFO | ||
| 716 | #define NO_MALLINFO 0 | ||
| 717 | #endif /* NO_MALLINFO */ | ||
| 718 | #ifndef MALLINFO_FIELD_TYPE | ||
| 719 | #define MALLINFO_FIELD_TYPE size_t | ||
| 720 | #endif /* MALLINFO_FIELD_TYPE */ | ||
| 721 | #ifndef NO_MALLOC_STATS | ||
| 722 | #define NO_MALLOC_STATS 0 | ||
| 723 | #endif /* NO_MALLOC_STATS */ | ||
| 724 | #ifndef NO_SEGMENT_TRAVERSAL | ||
| 725 | #define NO_SEGMENT_TRAVERSAL 0 | ||
| 726 | #endif /* NO_SEGMENT_TRAVERSAL */ | ||
| 727 | |||
| 728 | /* | ||
| 729 | mallopt tuning options. SVID/XPG defines four standard parameter | ||
| 730 | numbers for mallopt, normally defined in malloc.h. None of these | ||
| 731 | are used in this malloc, so setting them has no effect. But this | ||
| 732 | malloc does support the following options. | ||
| 733 | */ | ||
| 734 | |||
| 735 | #define M_TRIM_THRESHOLD (-1) | ||
| 736 | #define M_GRANULARITY (-2) | ||
| 737 | #define M_MMAP_THRESHOLD (-3) | ||
| 738 | |||
| 739 | /* ------------------------ Mallinfo declarations ------------------------ */ | ||
| 740 | |||
| 741 | #if !NO_MALLINFO | ||
| 742 | /* | ||
| 743 | This version of malloc supports the standard SVID/XPG mallinfo | ||
| 744 | routine that returns a struct containing usage properties and | ||
| 745 | statistics. It should work on any system that has a | ||
| 746 | /usr/include/malloc.h defining struct mallinfo. The main | ||
| 747 | declaration needed is the mallinfo struct that is returned (by-copy) | ||
| 748 | by mallinfo(). The malloinfo struct contains a bunch of fields that | ||
| 749 | are not even meaningful in this version of malloc. These fields are | ||
| 750 | are instead filled by mallinfo() with other numbers that might be of | ||
| 751 | interest. | ||
| 752 | |||
| 753 | HAVE_USR_INCLUDE_MALLOC_H should be set if you have a | ||
| 754 | /usr/include/malloc.h file that includes a declaration of struct | ||
| 755 | mallinfo. If so, it is included; else a compliant version is | ||
| 756 | declared below. These must be precisely the same for mallinfo() to | ||
| 757 | work. The original SVID version of this struct, defined on most | ||
| 758 | systems with mallinfo, declares all fields as ints. But some others | ||
| 759 | define as unsigned long. If your system defines the fields using a | ||
| 760 | type of different width than listed here, you MUST #include your | ||
| 761 | system version and #define HAVE_USR_INCLUDE_MALLOC_H. | ||
| 762 | */ | ||
| 763 | |||
| 764 | /* #define HAVE_USR_INCLUDE_MALLOC_H */ | ||
| 765 | |||
| 766 | #ifdef HAVE_USR_INCLUDE_MALLOC_H | ||
| 767 | #include "/usr/include/malloc.h" | ||
| 768 | #else /* HAVE_USR_INCLUDE_MALLOC_H */ | ||
| 769 | #ifndef STRUCT_MALLINFO_DECLARED | ||
| 770 | /* HP-UX (and others?) redefines mallinfo unless _STRUCT_MALLINFO is defined */ | ||
| 771 | #define _STRUCT_MALLINFO | ||
| 772 | #define STRUCT_MALLINFO_DECLARED 1 | ||
| 773 | struct mallinfo { | ||
| 774 | MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ | ||
| 775 | MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ | ||
| 776 | MALLINFO_FIELD_TYPE smblks; /* always 0 */ | ||
| 777 | MALLINFO_FIELD_TYPE hblks; /* always 0 */ | ||
| 778 | MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ | ||
| 779 | MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ | ||
| 780 | MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ | ||
| 781 | MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ | ||
| 782 | MALLINFO_FIELD_TYPE fordblks; /* total free space */ | ||
| 783 | MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ | ||
| 784 | }; | ||
| 785 | #endif /* STRUCT_MALLINFO_DECLARED */ | ||
| 786 | #endif /* HAVE_USR_INCLUDE_MALLOC_H */ | ||
| 787 | #endif /* NO_MALLINFO */ | ||
| 788 | |||
| 789 | /* | ||
| 790 | Try to persuade compilers to inline. The most critical functions for | ||
| 791 | inlining are defined as macros, so these aren't used for them. | ||
| 792 | */ | ||
| 793 | |||
| 794 | #ifndef FORCEINLINE | ||
| 795 | #if defined(__GNUC__) | ||
| 796 | #define FORCEINLINE __inline __attribute__ ((always_inline)) | ||
| 797 | #elif defined(_MSC_VER) | ||
| 798 | #define FORCEINLINE __forceinline | ||
| 799 | #endif | ||
| 800 | #endif | ||
| 801 | #ifndef NOINLINE | ||
| 802 | #if defined(__GNUC__) | ||
| 803 | #define NOINLINE __attribute__ ((noinline)) | ||
| 804 | #elif defined(_MSC_VER) | ||
| 805 | #define NOINLINE __declspec(noinline) | ||
| 806 | #else | ||
| 807 | #define NOINLINE | ||
| 808 | #endif | ||
| 809 | #endif | ||
| 810 | |||
| 811 | #ifdef __cplusplus | ||
| 812 | extern "C" { | ||
| 813 | #ifndef FORCEINLINE | ||
| 814 | #define FORCEINLINE inline | ||
| 815 | #endif | ||
| 816 | #endif /* __cplusplus */ | ||
| 817 | #ifndef FORCEINLINE | ||
| 818 | #define FORCEINLINE | ||
| 819 | #endif | ||
| 820 | |||
| 821 | #if !ONLY_MSPACES | ||
| 822 | |||
| 823 | /* ------------------- Declarations of public routines ------------------- */ | ||
| 824 | |||
| 825 | #ifndef USE_DL_PREFIX | ||
| 826 | #define dlcalloc calloc | ||
| 827 | #define dlfree free | ||
| 828 | #define dlmalloc malloc | ||
| 829 | #define dlmemalign memalign | ||
| 830 | #define dlposix_memalign posix_memalign | ||
| 831 | #define dlrealloc realloc | ||
| 832 | #define dlrealloc_in_place realloc_in_place | ||
| 833 | #define dlvalloc valloc | ||
| 834 | #define dlpvalloc pvalloc | ||
| 835 | #define dlmallinfo mallinfo | ||
| 836 | #define dlmallopt mallopt | ||
| 837 | #define dlmalloc_trim malloc_trim | ||
| 838 | #define dlmalloc_stats malloc_stats | ||
| 839 | #define dlmalloc_usable_size malloc_usable_size | ||
| 840 | #define dlmalloc_footprint malloc_footprint | ||
| 841 | #define dlmalloc_max_footprint malloc_max_footprint | ||
| 842 | #define dlmalloc_footprint_limit malloc_footprint_limit | ||
| 843 | #define dlmalloc_set_footprint_limit malloc_set_footprint_limit | ||
| 844 | #define dlmalloc_inspect_all malloc_inspect_all | ||
| 845 | #define dlindependent_calloc independent_calloc | ||
| 846 | #define dlindependent_comalloc independent_comalloc | ||
| 847 | #define dlbulk_free bulk_free | ||
| 848 | #endif /* USE_DL_PREFIX */ | ||
| 849 | |||
| 850 | /* | ||
| 851 | malloc(size_t n) | ||
| 852 | Returns a pointer to a newly allocated chunk of at least n bytes, or | ||
| 853 | null if no space is available, in which case errno is set to ENOMEM | ||
| 854 | on ANSI C systems. | ||
| 855 | |||
| 856 | If n is zero, malloc returns a minimum-sized chunk. (The minimum | ||
| 857 | size is 16 bytes on most 32bit systems, and 32 bytes on 64bit | ||
| 858 | systems.) Note that size_t is an unsigned type, so calls with | ||
| 859 | arguments that would be negative if signed are interpreted as | ||
| 860 | requests for huge amounts of space, which will often fail. The | ||
| 861 | maximum supported value of n differs across systems, but is in all | ||
| 862 | cases less than the maximum representable value of a size_t. | ||
| 863 | */ | ||
| 864 | DLMALLOC_EXPORT void* dlmalloc(size_t); | ||
| 865 | |||
| 866 | /* | ||
| 867 | free(void* p) | ||
| 868 | Releases the chunk of memory pointed to by p, that had been previously | ||
| 869 | allocated using malloc or a related routine such as realloc. | ||
| 870 | It has no effect if p is null. If p was not malloced or already | ||
| 871 | freed, free(p) will by default cause the current program to abort. | ||
| 872 | */ | ||
| 873 | DLMALLOC_EXPORT void dlfree(void*); | ||
| 874 | |||
| 875 | /* | ||
| 876 | calloc(size_t n_elements, size_t element_size); | ||
| 877 | Returns a pointer to n_elements * element_size bytes, with all locations | ||
| 878 | set to zero. | ||
| 879 | */ | ||
| 880 | DLMALLOC_EXPORT void* dlcalloc(size_t, size_t); | ||
| 881 | |||
| 882 | /* | ||
| 883 | realloc(void* p, size_t n) | ||
| 884 | Returns a pointer to a chunk of size n that contains the same data | ||
| 885 | as does chunk p up to the minimum of (n, p's size) bytes, or null | ||
| 886 | if no space is available. | ||
| 887 | |||
| 888 | The returned pointer may or may not be the same as p. The algorithm | ||
| 889 | prefers extending p in most cases when possible, otherwise it | ||
| 890 | employs the equivalent of a malloc-copy-free sequence. | ||
| 891 | |||
| 892 | If p is null, realloc is equivalent to malloc. | ||
| 893 | |||
| 894 | If space is not available, realloc returns null, errno is set (if on | ||
| 895 | ANSI) and p is NOT freed. | ||
| 896 | |||
| 897 | if n is for fewer bytes than already held by p, the newly unused | ||
| 898 | space is lopped off and freed if possible. realloc with a size | ||
| 899 | argument of zero (re)allocates a minimum-sized chunk. | ||
| 900 | |||
| 901 | The old unix realloc convention of allowing the last-free'd chunk | ||
| 902 | to be used as an argument to realloc is not supported. | ||
| 903 | */ | ||
| 904 | DLMALLOC_EXPORT void* dlrealloc(void*, size_t); | ||
| 905 | |||
| 906 | /* | ||
| 907 | realloc_in_place(void* p, size_t n) | ||
| 908 | Resizes the space allocated for p to size n, only if this can be | ||
| 909 | done without moving p (i.e., only if there is adjacent space | ||
| 910 | available if n is greater than p's current allocated size, or n is | ||
| 911 | less than or equal to p's size). This may be used instead of plain | ||
| 912 | realloc if an alternative allocation strategy is needed upon failure | ||
| 913 | to expand space; for example, reallocation of a buffer that must be | ||
| 914 | memory-aligned or cleared. You can use realloc_in_place to trigger | ||
| 915 | these alternatives only when needed. | ||
| 916 | |||
| 917 | Returns p if successful; otherwise null. | ||
| 918 | */ | ||
| 919 | DLMALLOC_EXPORT void* dlrealloc_in_place(void*, size_t); | ||
| 920 | |||
| 921 | /* | ||
| 922 | memalign(size_t alignment, size_t n); | ||
| 923 | Returns a pointer to a newly allocated chunk of n bytes, aligned | ||
| 924 | in accord with the alignment argument. | ||
| 925 | |||
| 926 | The alignment argument should be a power of two. If the argument is | ||
| 927 | not a power of two, the nearest greater power is used. | ||
| 928 | 8-byte alignment is guaranteed by normal malloc calls, so don't | ||
| 929 | bother calling memalign with an argument of 8 or less. | ||
| 930 | |||
| 931 | Overreliance on memalign is a sure way to fragment space. | ||
| 932 | */ | ||
| 933 | DLMALLOC_EXPORT void* dlmemalign(size_t, size_t); | ||
| 934 | |||
| 935 | /* | ||
| 936 | int posix_memalign(void** pp, size_t alignment, size_t n); | ||
| 937 | Allocates a chunk of n bytes, aligned in accord with the alignment | ||
| 938 | argument. Differs from memalign only in that it (1) assigns the | ||
| 939 | allocated memory to *pp rather than returning it, (2) fails and | ||
| 940 | returns EINVAL if the alignment is not a power of two (3) fails and | ||
| 941 | returns ENOMEM if memory cannot be allocated. | ||
| 942 | */ | ||
| 943 | DLMALLOC_EXPORT int dlposix_memalign(void**, size_t, size_t); | ||
| 944 | |||
| 945 | /* | ||
| 946 | valloc(size_t n); | ||
| 947 | Equivalent to memalign(pagesize, n), where pagesize is the page | ||
| 948 | size of the system. If the pagesize is unknown, 4096 is used. | ||
| 949 | */ | ||
| 950 | DLMALLOC_EXPORT void* dlvalloc(size_t); | ||
| 951 | |||
| 952 | /* | ||
| 953 | mallopt(int parameter_number, int parameter_value) | ||
| 954 | Sets tunable parameters The format is to provide a | ||
| 955 | (parameter-number, parameter-value) pair. mallopt then sets the | ||
| 956 | corresponding parameter to the argument value if it can (i.e., so | ||
| 957 | long as the value is meaningful), and returns 1 if successful else | ||
| 958 | 0. To workaround the fact that mallopt is specified to use int, | ||
| 959 | not size_t parameters, the value -1 is specially treated as the | ||
| 960 | maximum unsigned size_t value. | ||
| 961 | |||
| 962 | SVID/XPG/ANSI defines four standard param numbers for mallopt, | ||
| 963 | normally defined in malloc.h. None of these are use in this malloc, | ||
| 964 | so setting them has no effect. But this malloc also supports other | ||
| 965 | options in mallopt. See below for details. Briefly, supported | ||
| 966 | parameters are as follows (listed defaults are for "typical" | ||
| 967 | configurations). | ||
| 968 | |||
| 969 | Symbol param # default allowed param values | ||
| 970 | M_TRIM_THRESHOLD -1 2*1024*1024 any (-1 disables) | ||
| 971 | M_GRANULARITY -2 page size any power of 2 >= page size | ||
| 972 | M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support) | ||
| 973 | */ | ||
| 974 | DLMALLOC_EXPORT int dlmallopt(int, int); | ||
| 975 | |||
| 976 | /* | ||
| 977 | malloc_footprint(); | ||
| 978 | Returns the number of bytes obtained from the system. The total | ||
| 979 | number of bytes allocated by malloc, realloc etc., is less than this | ||
| 980 | value. Unlike mallinfo, this function returns only a precomputed | ||
| 981 | result, so can be called frequently to monitor memory consumption. | ||
| 982 | Even if locks are otherwise defined, this function does not use them, | ||
| 983 | so results might not be up to date. | ||
| 984 | */ | ||
| 985 | DLMALLOC_EXPORT size_t dlmalloc_footprint(void); | ||
| 986 | |||
| 987 | /* | ||
| 988 | malloc_max_footprint(); | ||
| 989 | Returns the maximum number of bytes obtained from the system. This | ||
| 990 | value will be greater than current footprint if deallocated space | ||
| 991 | has been reclaimed by the system. The peak number of bytes allocated | ||
| 992 | by malloc, realloc etc., is less than this value. Unlike mallinfo, | ||
| 993 | this function returns only a precomputed result, so can be called | ||
| 994 | frequently to monitor memory consumption. Even if locks are | ||
| 995 | otherwise defined, this function does not use them, so results might | ||
| 996 | not be up to date. | ||
| 997 | */ | ||
| 998 | DLMALLOC_EXPORT size_t dlmalloc_max_footprint(void); | ||
| 999 | |||
| 1000 | /* | ||
| 1001 | malloc_footprint_limit(); | ||
| 1002 | Returns the number of bytes that the heap is allowed to obtain from | ||
| 1003 | the system, returning the last value returned by | ||
| 1004 | malloc_set_footprint_limit, or the maximum size_t value if | ||
| 1005 | never set. The returned value reflects a permission. There is no | ||
| 1006 | guarantee that this number of bytes can actually be obtained from | ||
| 1007 | the system. | ||
| 1008 | */ | ||
| 1009 | DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(); | ||
| 1010 | |||
| 1011 | /* | ||
| 1012 | malloc_set_footprint_limit(); | ||
| 1013 | Sets the maximum number of bytes to obtain from the system, causing | ||
| 1014 | failure returns from malloc and related functions upon attempts to | ||
| 1015 | exceed this value. The argument value may be subject to page | ||
| 1016 | rounding to an enforceable limit; this actual value is returned. | ||
| 1017 | Using an argument of the maximum possible size_t effectively | ||
| 1018 | disables checks. If the argument is less than or equal to the | ||
| 1019 | current malloc_footprint, then all future allocations that require | ||
| 1020 | additional system memory will fail. However, invocation cannot | ||
| 1021 | retroactively deallocate existing used memory. | ||
| 1022 | */ | ||
| 1023 | DLMALLOC_EXPORT size_t dlmalloc_set_footprint_limit(size_t bytes); | ||
| 1024 | |||
| 1025 | #if MALLOC_INSPECT_ALL | ||
| 1026 | /* | ||
| 1027 | malloc_inspect_all(void(*handler)(void *start, | ||
| 1028 | void *end, | ||
| 1029 | size_t used_bytes, | ||
| 1030 | void* callback_arg), | ||
| 1031 | void* arg); | ||
| 1032 | Traverses the heap and calls the given handler for each managed | ||
| 1033 | region, skipping all bytes that are (or may be) used for bookkeeping | ||
| 1034 | purposes. Traversal does not include include chunks that have been | ||
| 1035 | directly memory mapped. Each reported region begins at the start | ||
| 1036 | address, and continues up to but not including the end address. The | ||
| 1037 | first used_bytes of the region contain allocated data. If | ||
| 1038 | used_bytes is zero, the region is unallocated. The handler is | ||
| 1039 | invoked with the given callback argument. If locks are defined, they | ||
| 1040 | are held during the entire traversal. It is a bad idea to invoke | ||
| 1041 | other malloc functions from within the handler. | ||
| 1042 | |||
| 1043 | For example, to count the number of in-use chunks with size greater | ||
| 1044 | than 1000, you could write: | ||
| 1045 | static int count = 0; | ||
| 1046 | void count_chunks(void* start, void* end, size_t used, void* arg) { | ||
| 1047 | if (used >= 1000) ++count; | ||
| 1048 | } | ||
| 1049 | then: | ||
| 1050 | malloc_inspect_all(count_chunks, NULL); | ||
| 1051 | |||
| 1052 | malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined. | ||
| 1053 | */ | ||
| 1054 | DLMALLOC_EXPORT void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*), | ||
| 1055 | void* arg); | ||
| 1056 | |||
| 1057 | #endif /* MALLOC_INSPECT_ALL */ | ||
| 1058 | |||
| 1059 | #if !NO_MALLINFO | ||
| 1060 | /* | ||
| 1061 | mallinfo() | ||
| 1062 | Returns (by copy) a struct containing various summary statistics: | ||
| 1063 | |||
| 1064 | arena: current total non-mmapped bytes allocated from system | ||
| 1065 | ordblks: the number of free chunks | ||
| 1066 | smblks: always zero. | ||
| 1067 | hblks: current number of mmapped regions | ||
| 1068 | hblkhd: total bytes held in mmapped regions | ||
| 1069 | usmblks: the maximum total allocated space. This will be greater | ||
| 1070 | than current total if trimming has occurred. | ||
| 1071 | fsmblks: always zero | ||
| 1072 | uordblks: current total allocated space (normal or mmapped) | ||
| 1073 | fordblks: total free space | ||
| 1074 | keepcost: the maximum number of bytes that could ideally be released | ||
| 1075 | back to system via malloc_trim. ("ideally" means that | ||
| 1076 | it ignores page restrictions etc.) | ||
| 1077 | |||
| 1078 | Because these fields are ints, but internal bookkeeping may | ||
| 1079 | be kept as longs, the reported values may wrap around zero and | ||
| 1080 | thus be inaccurate. | ||
| 1081 | */ | ||
| 1082 | DLMALLOC_EXPORT struct mallinfo dlmallinfo(void); | ||
| 1083 | #endif /* NO_MALLINFO */ | ||
| 1084 | |||
| 1085 | /* | ||
| 1086 | independent_calloc(size_t n_elements, size_t element_size, void* chunks[]); | ||
| 1087 | |||
| 1088 | independent_calloc is similar to calloc, but instead of returning a | ||
| 1089 | single cleared space, it returns an array of pointers to n_elements | ||
| 1090 | independent elements that can hold contents of size elem_size, each | ||
| 1091 | of which starts out cleared, and can be independently freed, | ||
| 1092 | realloc'ed etc. The elements are guaranteed to be adjacently | ||
| 1093 | allocated (this is not guaranteed to occur with multiple callocs or | ||
| 1094 | mallocs), which may also improve cache locality in some | ||
| 1095 | applications. | ||
| 1096 | |||
| 1097 | The "chunks" argument is optional (i.e., may be null, which is | ||
| 1098 | probably the most typical usage). If it is null, the returned array | ||
| 1099 | is itself dynamically allocated and should also be freed when it is | ||
| 1100 | no longer needed. Otherwise, the chunks array must be of at least | ||
| 1101 | n_elements in length. It is filled in with the pointers to the | ||
| 1102 | chunks. | ||
| 1103 | |||
| 1104 | In either case, independent_calloc returns this pointer array, or | ||
| 1105 | null if the allocation failed. If n_elements is zero and "chunks" | ||
| 1106 | is null, it returns a chunk representing an array with zero elements | ||
| 1107 | (which should be freed if not wanted). | ||
| 1108 | |||
| 1109 | Each element must be freed when it is no longer needed. This can be | ||
| 1110 | done all at once using bulk_free. | ||
| 1111 | |||
| 1112 | independent_calloc simplifies and speeds up implementations of many | ||
| 1113 | kinds of pools. It may also be useful when constructing large data | ||
| 1114 | structures that initially have a fixed number of fixed-sized nodes, | ||
| 1115 | but the number is not known at compile time, and some of the nodes | ||
| 1116 | may later need to be freed. For example: | ||
| 1117 | |||
| 1118 | struct Node { int item; struct Node* next; }; | ||
| 1119 | |||
| 1120 | struct Node* build_list() { | ||
| 1121 | struct Node** pool; | ||
| 1122 | int n = read_number_of_nodes_needed(); | ||
| 1123 | if (n <= 0) return 0; | ||
| 1124 | pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0); | ||
| 1125 | if (pool == 0) die(); | ||
| 1126 | // organize into a linked list... | ||
| 1127 | struct Node* first = pool[0]; | ||
| 1128 | for (i = 0; i < n-1; ++i) | ||
| 1129 | pool[i]->next = pool[i+1]; | ||
| 1130 | free(pool); // Can now free the array (or not, if it is needed later) | ||
| 1131 | return first; | ||
| 1132 | } | ||
| 1133 | */ | ||
| 1134 | DLMALLOC_EXPORT void** dlindependent_calloc(size_t, size_t, void**); | ||
| 1135 | |||
| 1136 | /* | ||
| 1137 | independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]); | ||
| 1138 | |||
| 1139 | independent_comalloc allocates, all at once, a set of n_elements | ||
| 1140 | chunks with sizes indicated in the "sizes" array. It returns | ||
| 1141 | an array of pointers to these elements, each of which can be | ||
| 1142 | independently freed, realloc'ed etc. The elements are guaranteed to | ||
| 1143 | be adjacently allocated (this is not guaranteed to occur with | ||
| 1144 | multiple callocs or mallocs), which may also improve cache locality | ||
| 1145 | in some applications. | ||
| 1146 | |||
| 1147 | The "chunks" argument is optional (i.e., may be null). If it is null | ||
| 1148 | the returned array is itself dynamically allocated and should also | ||
| 1149 | be freed when it is no longer needed. Otherwise, the chunks array | ||
| 1150 | must be of at least n_elements in length. It is filled in with the | ||
| 1151 | pointers to the chunks. | ||
| 1152 | |||
| 1153 | In either case, independent_comalloc returns this pointer array, or | ||
| 1154 | null if the allocation failed. If n_elements is zero and chunks is | ||
| 1155 | null, it returns a chunk representing an array with zero elements | ||
| 1156 | (which should be freed if not wanted). | ||
| 1157 | |||
| 1158 | Each element must be freed when it is no longer needed. This can be | ||
| 1159 | done all at once using bulk_free. | ||
| 1160 | |||
| 1161 | independent_comallac differs from independent_calloc in that each | ||
| 1162 | element may have a different size, and also that it does not | ||
| 1163 | automatically clear elements. | ||
| 1164 | |||
| 1165 | independent_comalloc can be used to speed up allocation in cases | ||
| 1166 | where several structs or objects must always be allocated at the | ||
| 1167 | same time. For example: | ||
| 1168 | |||
| 1169 | struct Head { ... } | ||
| 1170 | struct Foot { ... } | ||
| 1171 | |||
| 1172 | void send_message(char* msg) { | ||
| 1173 | int msglen = strlen(msg); | ||
| 1174 | size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) }; | ||
| 1175 | void* chunks[3]; | ||
| 1176 | if (independent_comalloc(3, sizes, chunks) == 0) | ||
| 1177 | die(); | ||
| 1178 | struct Head* head = (struct Head*)(chunks[0]); | ||
| 1179 | char* body = (char*)(chunks[1]); | ||
| 1180 | struct Foot* foot = (struct Foot*)(chunks[2]); | ||
| 1181 | // ... | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | In general though, independent_comalloc is worth using only for | ||
| 1185 | larger values of n_elements. For small values, you probably won't | ||
| 1186 | detect enough difference from series of malloc calls to bother. | ||
| 1187 | |||
| 1188 | Overuse of independent_comalloc can increase overall memory usage, | ||
| 1189 | since it cannot reuse existing noncontiguous small chunks that | ||
| 1190 | might be available for some of the elements. | ||
| 1191 | */ | ||
| 1192 | DLMALLOC_EXPORT void** dlindependent_comalloc(size_t, size_t*, void**); | ||
| 1193 | |||
| 1194 | /* | ||
| 1195 | bulk_free(void* array[], size_t n_elements) | ||
| 1196 | Frees and clears (sets to null) each non-null pointer in the given | ||
| 1197 | array. This is likely to be faster than freeing them one-by-one. | ||
| 1198 | If footers are used, pointers that have been allocated in different | ||
| 1199 | mspaces are not freed or cleared, and the count of all such pointers | ||
| 1200 | is returned. For large arrays of pointers with poor locality, it | ||
| 1201 | may be worthwhile to sort this array before calling bulk_free. | ||
| 1202 | */ | ||
| 1203 | DLMALLOC_EXPORT size_t dlbulk_free(void**, size_t n_elements); | ||
| 1204 | |||
| 1205 | /* | ||
| 1206 | pvalloc(size_t n); | ||
| 1207 | Equivalent to valloc(minimum-page-that-holds(n)), that is, | ||
| 1208 | round up n to nearest pagesize. | ||
| 1209 | */ | ||
| 1210 | DLMALLOC_EXPORT void* dlpvalloc(size_t); | ||
| 1211 | |||
| 1212 | /* | ||
| 1213 | malloc_trim(size_t pad); | ||
| 1214 | |||
| 1215 | If possible, gives memory back to the system (via negative arguments | ||
| 1216 | to sbrk) if there is unused memory at the `high' end of the malloc | ||
| 1217 | pool or in unused MMAP segments. You can call this after freeing | ||
| 1218 | large blocks of memory to potentially reduce the system-level memory | ||
| 1219 | requirements of a program. However, it cannot guarantee to reduce | ||
| 1220 | memory. Under some allocation patterns, some large free blocks of | ||
| 1221 | memory will be locked between two used chunks, so they cannot be | ||
| 1222 | given back to the system. | ||
| 1223 | |||
| 1224 | The `pad' argument to malloc_trim represents the amount of free | ||
| 1225 | trailing space to leave untrimmed. If this argument is zero, only | ||
| 1226 | the minimum amount of memory to maintain internal data structures | ||
| 1227 | will be left. Non-zero arguments can be supplied to maintain enough | ||
| 1228 | trailing space to service future expected allocations without having | ||
| 1229 | to re-obtain memory from the system. | ||
| 1230 | |||
| 1231 | Malloc_trim returns 1 if it actually released any memory, else 0. | ||
| 1232 | */ | ||
| 1233 | DLMALLOC_EXPORT int dlmalloc_trim(size_t); | ||
| 1234 | |||
| 1235 | /* | ||
| 1236 | malloc_stats(); | ||
| 1237 | Prints on stderr the amount of space obtained from the system (both | ||
| 1238 | via sbrk and mmap), the maximum amount (which may be more than | ||
| 1239 | current if malloc_trim and/or munmap got called), and the current | ||
| 1240 | number of bytes allocated via malloc (or realloc, etc) but not yet | ||
| 1241 | freed. Note that this is the number of bytes allocated, not the | ||
| 1242 | number requested. It will be larger than the number requested | ||
| 1243 | because of alignment and bookkeeping overhead. Because it includes | ||
| 1244 | alignment wastage as being in use, this figure may be greater than | ||
| 1245 | zero even when no user-level chunks are allocated. | ||
| 1246 | |||
| 1247 | The reported current and maximum system memory can be inaccurate if | ||
| 1248 | a program makes other calls to system memory allocation functions | ||
| 1249 | (normally sbrk) outside of malloc. | ||
| 1250 | |||
| 1251 | malloc_stats prints only the most commonly interesting statistics. | ||
| 1252 | More information can be obtained by calling mallinfo. | ||
| 1253 | */ | ||
| 1254 | DLMALLOC_EXPORT void dlmalloc_stats(void); | ||
| 1255 | |||
| 1256 | /* | ||
| 1257 | malloc_usable_size(void* p); | ||
| 1258 | |||
| 1259 | Returns the number of bytes you can actually use in | ||
| 1260 | an allocated chunk, which may be more than you requested (although | ||
| 1261 | often not) due to alignment and minimum size constraints. | ||
| 1262 | You can use this many bytes without worrying about | ||
| 1263 | overwriting other allocated objects. This is not a particularly great | ||
| 1264 | programming practice. malloc_usable_size can be more useful in | ||
| 1265 | debugging and assertions, for example: | ||
| 1266 | |||
| 1267 | p = malloc(n); | ||
| 1268 | assert(malloc_usable_size(p) >= 256); | ||
| 1269 | */ | ||
| 1270 | size_t dlmalloc_usable_size(void*); | ||
| 1271 | |||
| 1272 | #endif /* ONLY_MSPACES */ | ||
| 1273 | |||
| 1274 | #if MSPACES | ||
| 1275 | |||
| 1276 | /* | ||
| 1277 | mspace is an opaque type representing an independent | ||
| 1278 | region of space that supports mspace_malloc, etc. | ||
| 1279 | */ | ||
| 1280 | typedef void* mspace; | ||
| 1281 | |||
| 1282 | /* | ||
| 1283 | create_mspace creates and returns a new independent space with the | ||
| 1284 | given initial capacity, or, if 0, the default granularity size. It | ||
| 1285 | returns null if there is no system memory available to create the | ||
| 1286 | space. If argument locked is non-zero, the space uses a separate | ||
| 1287 | lock to control access. The capacity of the space will grow | ||
| 1288 | dynamically as needed to service mspace_malloc requests. You can | ||
| 1289 | control the sizes of incremental increases of this space by | ||
| 1290 | compiling with a different DEFAULT_GRANULARITY or dynamically | ||
| 1291 | setting with mallopt(M_GRANULARITY, value). | ||
| 1292 | */ | ||
| 1293 | DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked); | ||
| 1294 | |||
| 1295 | /* | ||
| 1296 | destroy_mspace destroys the given space, and attempts to return all | ||
| 1297 | of its memory back to the system, returning the total number of | ||
| 1298 | bytes freed. After destruction, the results of access to all memory | ||
| 1299 | used by the space become undefined. | ||
| 1300 | */ | ||
| 1301 | DLMALLOC_EXPORT size_t destroy_mspace(mspace msp); | ||
| 1302 | |||
| 1303 | /* | ||
| 1304 | create_mspace_with_base uses the memory supplied as the initial base | ||
| 1305 | of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this | ||
| 1306 | space is used for bookkeeping, so the capacity must be at least this | ||
| 1307 | large. (Otherwise 0 is returned.) When this initial space is | ||
| 1308 | exhausted, additional memory will be obtained from the system. | ||
| 1309 | Destroying this space will deallocate all additionally allocated | ||
| 1310 | space (if possible) but not the initial base. | ||
| 1311 | */ | ||
| 1312 | DLMALLOC_EXPORT mspace create_mspace_with_base(void* base, size_t capacity, int locked); | ||
| 1313 | |||
| 1314 | /* | ||
| 1315 | mspace_track_large_chunks controls whether requests for large chunks | ||
| 1316 | are allocated in their own untracked mmapped regions, separate from | ||
| 1317 | others in this mspace. By default large chunks are not tracked, | ||
| 1318 | which reduces fragmentation. However, such chunks are not | ||
| 1319 | necessarily released to the system upon destroy_mspace. Enabling | ||
| 1320 | tracking by setting to true may increase fragmentation, but avoids | ||
| 1321 | leakage when relying on destroy_mspace to release all memory | ||
| 1322 | allocated using this space. The function returns the previous | ||
| 1323 | setting. | ||
| 1324 | */ | ||
| 1325 | DLMALLOC_EXPORT int mspace_track_large_chunks(mspace msp, int enable); | ||
| 1326 | |||
| 1327 | |||
| 1328 | /* | ||
| 1329 | mspace_malloc behaves as malloc, but operates within | ||
| 1330 | the given space. | ||
| 1331 | */ | ||
| 1332 | DLMALLOC_EXPORT void* mspace_malloc(mspace msp, size_t bytes); | ||
| 1333 | |||
| 1334 | /* | ||
| 1335 | mspace_free behaves as free, but operates within | ||
| 1336 | the given space. | ||
| 1337 | |||
| 1338 | If compiled with FOOTERS==1, mspace_free is not actually needed. | ||
| 1339 | free may be called instead of mspace_free because freed chunks from | ||
| 1340 | any space are handled by their originating spaces. | ||
| 1341 | */ | ||
| 1342 | DLMALLOC_EXPORT void mspace_free(mspace msp, void* mem); | ||
| 1343 | |||
| 1344 | /* | ||
| 1345 | mspace_realloc behaves as realloc, but operates within | ||
| 1346 | the given space. | ||
| 1347 | |||
| 1348 | If compiled with FOOTERS==1, mspace_realloc is not actually | ||
| 1349 | needed. realloc may be called instead of mspace_realloc because | ||
| 1350 | realloced chunks from any space are handled by their originating | ||
| 1351 | spaces. | ||
| 1352 | */ | ||
| 1353 | DLMALLOC_EXPORT void* mspace_realloc(mspace msp, void* mem, size_t newsize); | ||
| 1354 | |||
| 1355 | /* | ||
| 1356 | mspace_calloc behaves as calloc, but operates within | ||
| 1357 | the given space. | ||
| 1358 | */ | ||
| 1359 | DLMALLOC_EXPORT void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size); | ||
| 1360 | |||
| 1361 | /* | ||
| 1362 | mspace_memalign behaves as memalign, but operates within | ||
| 1363 | the given space. | ||
| 1364 | */ | ||
| 1365 | DLMALLOC_EXPORT void* mspace_memalign(mspace msp, size_t alignment, size_t bytes); | ||
| 1366 | |||
| 1367 | /* | ||
| 1368 | mspace_independent_calloc behaves as independent_calloc, but | ||
| 1369 | operates within the given space. | ||
| 1370 | */ | ||
| 1371 | DLMALLOC_EXPORT void** mspace_independent_calloc(mspace msp, size_t n_elements, | ||
| 1372 | size_t elem_size, void* chunks[]); | ||
| 1373 | |||
| 1374 | /* | ||
| 1375 | mspace_independent_comalloc behaves as independent_comalloc, but | ||
| 1376 | operates within the given space. | ||
| 1377 | */ | ||
| 1378 | DLMALLOC_EXPORT void** mspace_independent_comalloc(mspace msp, size_t n_elements, | ||
| 1379 | size_t sizes[], void* chunks[]); | ||
| 1380 | |||
| 1381 | /* | ||
| 1382 | mspace_footprint() returns the number of bytes obtained from the | ||
| 1383 | system for this space. | ||
| 1384 | */ | ||
| 1385 | DLMALLOC_EXPORT size_t mspace_footprint(mspace msp); | ||
| 1386 | |||
| 1387 | /* | ||
| 1388 | mspace_max_footprint() returns the peak number of bytes obtained from the | ||
| 1389 | system for this space. | ||
| 1390 | */ | ||
| 1391 | DLMALLOC_EXPORT size_t mspace_max_footprint(mspace msp); | ||
| 1392 | |||
| 1393 | |||
| 1394 | #if !NO_MALLINFO | ||
| 1395 | /* | ||
| 1396 | mspace_mallinfo behaves as mallinfo, but reports properties of | ||
| 1397 | the given space. | ||
| 1398 | */ | ||
| 1399 | DLMALLOC_EXPORT struct mallinfo mspace_mallinfo(mspace msp); | ||
| 1400 | #endif /* NO_MALLINFO */ | ||
| 1401 | |||
| 1402 | /* | ||
| 1403 | malloc_usable_size(void* p) behaves the same as malloc_usable_size; | ||
| 1404 | */ | ||
| 1405 | DLMALLOC_EXPORT size_t mspace_usable_size(const void* mem); | ||
| 1406 | |||
| 1407 | /* | ||
| 1408 | mspace_malloc_stats behaves as malloc_stats, but reports | ||
| 1409 | properties of the given space. | ||
| 1410 | */ | ||
| 1411 | DLMALLOC_EXPORT void mspace_malloc_stats(mspace msp); | ||
| 1412 | |||
| 1413 | /* | ||
| 1414 | mspace_trim behaves as malloc_trim, but | ||
| 1415 | operates within the given space. | ||
| 1416 | */ | ||
| 1417 | DLMALLOC_EXPORT int mspace_trim(mspace msp, size_t pad); | ||
| 1418 | |||
| 1419 | /* | ||
| 1420 | An alias for mallopt. | ||
| 1421 | */ | ||
| 1422 | DLMALLOC_EXPORT int mspace_mallopt(int, int); | ||
| 1423 | |||
| 1424 | #endif /* MSPACES */ | ||
| 1425 | |||
| 1426 | #ifdef __cplusplus | ||
| 1427 | } /* end of extern "C" */ | ||
| 1428 | #endif /* __cplusplus */ | ||
| 1429 | |||
| 1430 | /* | ||
| 1431 | ======================================================================== | ||
| 1432 | To make a fully customizable malloc.h header file, cut everything | ||
| 1433 | above this line, put into file malloc.h, edit to suit, and #include it | ||
| 1434 | on the next line, as well as in programs that use this malloc. | ||
| 1435 | ======================================================================== | ||
| 1436 | */ | ||
| 1437 | |||
| 1438 | /* #include "malloc.h" */ | ||
| 1439 | |||
| 1440 | /*------------------------------ internal #includes ---------------------- */ | ||
| 1441 | |||
| 1442 | #ifdef _MSC_VER | ||
| 1443 | #pragma warning( disable : 4146 ) /* no "unsigned" warnings */ | ||
| 1444 | #endif /* _MSC_VER */ | ||
| 1445 | #if !NO_MALLOC_STATS | ||
| 1446 | #include <stdio.h> /* for printing in malloc_stats */ | ||
| 1447 | #endif /* NO_MALLOC_STATS */ | ||
| 1448 | #ifndef LACKS_ERRNO_H | ||
| 1449 | #include <errno.h> /* for MALLOC_FAILURE_ACTION */ | ||
| 1450 | #endif /* LACKS_ERRNO_H */ | ||
| 1451 | #ifdef DEBUG | ||
| 1452 | #if ABORT_ON_ASSERT_FAILURE | ||
| 1453 | #undef assert | ||
| 1454 | #define assert(x) if(!(x)) ABORT | ||
| 1455 | #else /* ABORT_ON_ASSERT_FAILURE */ | ||
| 1456 | #include <assert.h> | ||
| 1457 | #endif /* ABORT_ON_ASSERT_FAILURE */ | ||
| 1458 | #else /* DEBUG */ | ||
| 1459 | #ifndef assert | ||
| 1460 | #define assert(x) | ||
| 1461 | #endif | ||
| 1462 | #define DEBUG 0 | ||
| 1463 | #endif /* DEBUG */ | ||
| 1464 | #if !defined(WIN32) && !defined(LACKS_TIME_H) | ||
| 1465 | #include <time.h> /* for magic initialization */ | ||
| 1466 | #endif /* WIN32 */ | ||
| 1467 | #ifndef LACKS_STDLIB_H | ||
| 1468 | #include <stdlib.h> /* for abort() */ | ||
| 1469 | #endif /* LACKS_STDLIB_H */ | ||
| 1470 | #ifndef LACKS_STRING_H | ||
| 1471 | #include <string.h> /* for memset etc */ | ||
| 1472 | #endif /* LACKS_STRING_H */ | ||
| 1473 | #if USE_BUILTIN_FFS | ||
| 1474 | #ifndef LACKS_STRINGS_H | ||
| 1475 | #include <strings.h> /* for ffs */ | ||
| 1476 | #endif /* LACKS_STRINGS_H */ | ||
| 1477 | #endif /* USE_BUILTIN_FFS */ | ||
| 1478 | #if HAVE_MMAP | ||
| 1479 | #ifndef LACKS_SYS_MMAN_H | ||
| 1480 | /* On some versions of linux, mremap decl in mman.h needs __USE_GNU set */ | ||
| 1481 | #if (defined(linux) && !defined(__USE_GNU)) | ||
| 1482 | #define __USE_GNU 1 | ||
| 1483 | #include <sys/mman.h> /* for mmap */ | ||
| 1484 | #undef __USE_GNU | ||
| 1485 | #else | ||
| 1486 | #include <sys/mman.h> /* for mmap */ | ||
| 1487 | #endif /* linux */ | ||
| 1488 | #endif /* LACKS_SYS_MMAN_H */ | ||
| 1489 | #ifndef LACKS_FCNTL_H | ||
| 1490 | #include <fcntl.h> | ||
| 1491 | #endif /* LACKS_FCNTL_H */ | ||
| 1492 | #endif /* HAVE_MMAP */ | ||
| 1493 | #ifndef LACKS_UNISTD_H | ||
| 1494 | #include <unistd.h> /* for sbrk, sysconf */ | ||
| 1495 | #else /* LACKS_UNISTD_H */ | ||
| 1496 | #if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) | ||
| 1497 | extern void* sbrk(ptrdiff_t); | ||
| 1498 | #endif /* FreeBSD etc */ | ||
| 1499 | #endif /* LACKS_UNISTD_H */ | ||
| 1500 | |||
| 1501 | /* Declarations for locking */ | ||
| 1502 | #if USE_LOCKS | ||
| 1503 | #ifndef WIN32 | ||
| 1504 | #if defined (__SVR4) && defined (__sun) /* solaris */ | ||
| 1505 | #include <thread.h> | ||
| 1506 | #elif !defined(LACKS_SCHED_H) | ||
| 1507 | #include <sched.h> | ||
| 1508 | #endif /* solaris or LACKS_SCHED_H */ | ||
| 1509 | #if (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0) || !USE_SPIN_LOCKS | ||
| 1510 | #include <pthread.h> | ||
| 1511 | #endif /* USE_RECURSIVE_LOCKS ... */ | ||
| 1512 | #elif defined(_MSC_VER) | ||
| 1513 | #ifndef _M_AMD64 | ||
| 1514 | /* These are already defined on AMD64 builds */ | ||
| 1515 | #ifdef __cplusplus | ||
| 1516 | extern "C" { | ||
| 1517 | #endif /* __cplusplus */ | ||
| 1518 | LONG __cdecl _InterlockedCompareExchange(LONG volatile *Dest, LONG Exchange, LONG Comp); | ||
| 1519 | LONG __cdecl _InterlockedExchange(LONG volatile *Target, LONG Value); | ||
| 1520 | #ifdef __cplusplus | ||
| 1521 | } | ||
| 1522 | #endif /* __cplusplus */ | ||
| 1523 | #endif /* _M_AMD64 */ | ||
| 1524 | #pragma intrinsic (_InterlockedCompareExchange) | ||
| 1525 | #pragma intrinsic (_InterlockedExchange) | ||
| 1526 | #define interlockedcompareexchange _InterlockedCompareExchange | ||
| 1527 | #define interlockedexchange _InterlockedExchange | ||
| 1528 | #elif defined(WIN32) && defined(__GNUC__) | ||
| 1529 | #define interlockedcompareexchange(a, b, c) __sync_val_compare_and_swap(a, c, b) | ||
| 1530 | #define interlockedexchange __sync_lock_test_and_set | ||
| 1531 | #endif /* Win32 */ | ||
| 1532 | #else /* USE_LOCKS */ | ||
| 1533 | #endif /* USE_LOCKS */ | ||
| 1534 | |||
| 1535 | #ifndef LOCK_AT_FORK | ||
| 1536 | #define LOCK_AT_FORK 0 | ||
| 1537 | #endif | ||
| 1538 | |||
| 1539 | /* Declarations for bit scanning on win32 */ | ||
| 1540 | #if defined(_MSC_VER) && _MSC_VER>=1300 | ||
| 1541 | #ifndef BitScanForward /* Try to avoid pulling in WinNT.h */ | ||
| 1542 | #ifdef __cplusplus | ||
| 1543 | extern "C" { | ||
| 1544 | #endif /* __cplusplus */ | ||
| 1545 | unsigned char _BitScanForward(unsigned long *index, unsigned long mask); | ||
| 1546 | unsigned char _BitScanReverse(unsigned long *index, unsigned long mask); | ||
| 1547 | #ifdef __cplusplus | ||
| 1548 | } | ||
| 1549 | #endif /* __cplusplus */ | ||
| 1550 | |||
| 1551 | #define BitScanForward _BitScanForward | ||
| 1552 | #define BitScanReverse _BitScanReverse | ||
| 1553 | #pragma intrinsic(_BitScanForward) | ||
| 1554 | #pragma intrinsic(_BitScanReverse) | ||
| 1555 | #endif /* BitScanForward */ | ||
| 1556 | #endif /* defined(_MSC_VER) && _MSC_VER>=1300 */ | ||
| 1557 | |||
| 1558 | #ifndef WIN32 | ||
| 1559 | #ifndef malloc_getpagesize | ||
| 1560 | # ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ | ||
| 1561 | # ifndef _SC_PAGE_SIZE | ||
| 1562 | # define _SC_PAGE_SIZE _SC_PAGESIZE | ||
| 1563 | # endif | ||
| 1564 | # endif | ||
| 1565 | # ifdef _SC_PAGE_SIZE | ||
| 1566 | # define malloc_getpagesize sysconf(_SC_PAGE_SIZE) | ||
| 1567 | # else | ||
| 1568 | # if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) | ||
| 1569 | extern size_t getpagesize(); | ||
| 1570 | # define malloc_getpagesize getpagesize() | ||
| 1571 | # else | ||
| 1572 | # ifdef WIN32 /* use supplied emulation of getpagesize */ | ||
| 1573 | # define malloc_getpagesize getpagesize() | ||
| 1574 | # else | ||
| 1575 | # ifndef LACKS_SYS_PARAM_H | ||
| 1576 | # include <sys/param.h> | ||
| 1577 | # endif | ||
| 1578 | # ifdef EXEC_PAGESIZE | ||
| 1579 | # define malloc_getpagesize EXEC_PAGESIZE | ||
| 1580 | # else | ||
| 1581 | # ifdef NBPG | ||
| 1582 | # ifndef CLSIZE | ||
| 1583 | # define malloc_getpagesize NBPG | ||
| 1584 | # else | ||
| 1585 | # define malloc_getpagesize (NBPG * CLSIZE) | ||
| 1586 | # endif | ||
| 1587 | # else | ||
| 1588 | # ifdef NBPC | ||
| 1589 | # define malloc_getpagesize NBPC | ||
| 1590 | # else | ||
| 1591 | # ifdef PAGESIZE | ||
| 1592 | # define malloc_getpagesize PAGESIZE | ||
| 1593 | # else /* just guess */ | ||
| 1594 | # define malloc_getpagesize ((size_t)4096U) | ||
| 1595 | # endif | ||
| 1596 | # endif | ||
| 1597 | # endif | ||
| 1598 | # endif | ||
| 1599 | # endif | ||
| 1600 | # endif | ||
| 1601 | # endif | ||
| 1602 | #endif | ||
| 1603 | #endif | ||
| 1604 | |||
| 1605 | /* ------------------- size_t and alignment properties -------------------- */ | ||
| 1606 | |||
| 1607 | /* The byte and bit size of a size_t */ | ||
| 1608 | #define SIZE_T_SIZE (sizeof(size_t)) | ||
| 1609 | #define SIZE_T_BITSIZE (sizeof(size_t) << 3) | ||
| 1610 | |||
| 1611 | /* Some constants coerced to size_t */ | ||
| 1612 | /* Annoying but necessary to avoid errors on some platforms */ | ||
| 1613 | #define SIZE_T_ZERO ((size_t)0) | ||
| 1614 | #define SIZE_T_ONE ((size_t)1) | ||
| 1615 | #define SIZE_T_TWO ((size_t)2) | ||
| 1616 | #define SIZE_T_FOUR ((size_t)4) | ||
| 1617 | #define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) | ||
| 1618 | #define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) | ||
| 1619 | #define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) | ||
| 1620 | #define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) | ||
| 1621 | |||
| 1622 | /* The bit mask value corresponding to MALLOC_ALIGNMENT */ | ||
| 1623 | #define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) | ||
| 1624 | |||
| 1625 | /* True if address a has acceptable alignment */ | ||
| 1626 | #define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) | ||
| 1627 | |||
| 1628 | /* the number of bytes to offset an address to align it */ | ||
| 1629 | #define align_offset(A)\ | ||
| 1630 | ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ | ||
| 1631 | ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) | ||
| 1632 | |||
| 1633 | /* -------------------------- MMAP preliminaries ------------------------- */ | ||
| 1634 | |||
| 1635 | /* | ||
| 1636 | If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and | ||
| 1637 | checks to fail so compiler optimizer can delete code rather than | ||
| 1638 | using so many "#if"s. | ||
| 1639 | */ | ||
| 1640 | |||
| 1641 | |||
| 1642 | /* MORECORE and MMAP must return MFAIL on failure */ | ||
| 1643 | #define MFAIL ((void*)(MAX_SIZE_T)) | ||
| 1644 | #define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ | ||
| 1645 | |||
| 1646 | #if HAVE_MMAP | ||
| 1647 | |||
| 1648 | #ifndef WIN32 | ||
| 1649 | #define MUNMAP_DEFAULT(a, s) munmap((a), (s)) | ||
| 1650 | #define MMAP_PROT (PROT_READ|PROT_WRITE) | ||
| 1651 | #if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) | ||
| 1652 | #define MAP_ANONYMOUS MAP_ANON | ||
| 1653 | #endif /* MAP_ANON */ | ||
| 1654 | #ifdef MAP_ANONYMOUS | ||
| 1655 | #define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) | ||
| 1656 | #define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) | ||
| 1657 | #else /* MAP_ANONYMOUS */ | ||
| 1658 | /* | ||
| 1659 | Nearly all versions of mmap support MAP_ANONYMOUS, so the following | ||
| 1660 | is unlikely to be needed, but is supplied just in case. | ||
| 1661 | */ | ||
| 1662 | #define MMAP_FLAGS (MAP_PRIVATE) | ||
| 1663 | static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ | ||
| 1664 | #define MMAP_DEFAULT(s) ((dev_zero_fd < 0) ? \ | ||
| 1665 | (dev_zero_fd = open("/dev/zero", O_RDWR), \ | ||
| 1666 | mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \ | ||
| 1667 | mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) | ||
| 1668 | #endif /* MAP_ANONYMOUS */ | ||
| 1669 | |||
| 1670 | #define DIRECT_MMAP_DEFAULT(s) MMAP_DEFAULT(s) | ||
| 1671 | |||
| 1672 | #else /* WIN32 */ | ||
| 1673 | |||
| 1674 | /* Win32 MMAP via VirtualAlloc */ | ||
| 1675 | static FORCEINLINE void* win32mmap(size_t size) { | ||
| 1676 | void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); | ||
| 1677 | return (ptr != 0)? ptr: MFAIL; | ||
| 1678 | } | ||
| 1679 | |||
| 1680 | /* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ | ||
| 1681 | static FORCEINLINE void* win32direct_mmap(size_t size) { | ||
| 1682 | void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, | ||
| 1683 | PAGE_READWRITE); | ||
| 1684 | return (ptr != 0)? ptr: MFAIL; | ||
| 1685 | } | ||
| 1686 | |||
| 1687 | /* This function supports releasing coalesed segments */ | ||
| 1688 | static FORCEINLINE int win32munmap(void* ptr, size_t size) { | ||
| 1689 | MEMORY_BASIC_INFORMATION minfo; | ||
| 1690 | char* cptr = (char*)ptr; | ||
| 1691 | while (size) { | ||
| 1692 | if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) | ||
| 1693 | return -1; | ||
| 1694 | if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || | ||
| 1695 | minfo.State != MEM_COMMIT || minfo.RegionSize > size) | ||
| 1696 | return -1; | ||
| 1697 | if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) | ||
| 1698 | return -1; | ||
| 1699 | cptr += minfo.RegionSize; | ||
| 1700 | size -= minfo.RegionSize; | ||
| 1701 | } | ||
| 1702 | return 0; | ||
| 1703 | } | ||
| 1704 | |||
| 1705 | #define MMAP_DEFAULT(s) win32mmap(s) | ||
| 1706 | #define MUNMAP_DEFAULT(a, s) win32munmap((a), (s)) | ||
| 1707 | #define DIRECT_MMAP_DEFAULT(s) win32direct_mmap(s) | ||
| 1708 | #endif /* WIN32 */ | ||
| 1709 | #endif /* HAVE_MMAP */ | ||
| 1710 | |||
| 1711 | #if HAVE_MREMAP | ||
| 1712 | #ifndef WIN32 | ||
| 1713 | #define MREMAP_DEFAULT(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) | ||
| 1714 | #endif /* WIN32 */ | ||
| 1715 | #endif /* HAVE_MREMAP */ | ||
| 1716 | |||
| 1717 | /** | ||
| 1718 | * Define CALL_MORECORE | ||
| 1719 | */ | ||
| 1720 | #if HAVE_MORECORE | ||
| 1721 | #ifdef MORECORE | ||
| 1722 | #define CALL_MORECORE(S) MORECORE(S) | ||
| 1723 | #else /* MORECORE */ | ||
| 1724 | #define CALL_MORECORE(S) MORECORE_DEFAULT(S) | ||
| 1725 | #endif /* MORECORE */ | ||
| 1726 | #else /* HAVE_MORECORE */ | ||
| 1727 | #define CALL_MORECORE(S) MFAIL | ||
| 1728 | #endif /* HAVE_MORECORE */ | ||
| 1729 | |||
| 1730 | /** | ||
| 1731 | * Define CALL_MMAP/CALL_MUNMAP/CALL_DIRECT_MMAP | ||
| 1732 | */ | ||
| 1733 | #if HAVE_MMAP | ||
| 1734 | #define USE_MMAP_BIT (SIZE_T_ONE) | ||
| 1735 | |||
| 1736 | #ifdef MMAP | ||
| 1737 | #define CALL_MMAP(s) MMAP(s) | ||
| 1738 | #else /* MMAP */ | ||
| 1739 | #define CALL_MMAP(s) MMAP_DEFAULT(s) | ||
| 1740 | #endif /* MMAP */ | ||
| 1741 | #ifdef MUNMAP | ||
| 1742 | #define CALL_MUNMAP(a, s) MUNMAP((a), (s)) | ||
| 1743 | #else /* MUNMAP */ | ||
| 1744 | #define CALL_MUNMAP(a, s) MUNMAP_DEFAULT((a), (s)) | ||
| 1745 | #endif /* MUNMAP */ | ||
| 1746 | #ifdef DIRECT_MMAP | ||
| 1747 | #define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s) | ||
| 1748 | #else /* DIRECT_MMAP */ | ||
| 1749 | #define CALL_DIRECT_MMAP(s) DIRECT_MMAP_DEFAULT(s) | ||
| 1750 | #endif /* DIRECT_MMAP */ | ||
| 1751 | #else /* HAVE_MMAP */ | ||
| 1752 | #define USE_MMAP_BIT (SIZE_T_ZERO) | ||
| 1753 | |||
| 1754 | #define MMAP(s) MFAIL | ||
| 1755 | #define MUNMAP(a, s) (-1) | ||
| 1756 | #define DIRECT_MMAP(s) MFAIL | ||
| 1757 | #define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s) | ||
| 1758 | #define CALL_MMAP(s) MMAP(s) | ||
| 1759 | #define CALL_MUNMAP(a, s) MUNMAP((a), (s)) | ||
| 1760 | #endif /* HAVE_MMAP */ | ||
| 1761 | |||
| 1762 | /** | ||
| 1763 | * Define CALL_MREMAP | ||
| 1764 | */ | ||
| 1765 | #if HAVE_MMAP && HAVE_MREMAP | ||
| 1766 | #ifdef MREMAP | ||
| 1767 | #define CALL_MREMAP(addr, osz, nsz, mv) MREMAP((addr), (osz), (nsz), (mv)) | ||
| 1768 | #else /* MREMAP */ | ||
| 1769 | #define CALL_MREMAP(addr, osz, nsz, mv) MREMAP_DEFAULT((addr), (osz), (nsz), (mv)) | ||
| 1770 | #endif /* MREMAP */ | ||
| 1771 | #else /* HAVE_MMAP && HAVE_MREMAP */ | ||
| 1772 | #define CALL_MREMAP(addr, osz, nsz, mv) MFAIL | ||
| 1773 | #endif /* HAVE_MMAP && HAVE_MREMAP */ | ||
| 1774 | |||
| 1775 | /* mstate bit set if continguous morecore disabled or failed */ | ||
| 1776 | #define USE_NONCONTIGUOUS_BIT (4U) | ||
| 1777 | |||
| 1778 | /* segment bit set in create_mspace_with_base */ | ||
| 1779 | #define EXTERN_BIT (8U) | ||
| 1780 | |||
| 1781 | |||
| 1782 | /* --------------------------- Lock preliminaries ------------------------ */ | ||
| 1783 | |||
| 1784 | /* | ||
| 1785 | When locks are defined, there is one global lock, plus | ||
| 1786 | one per-mspace lock. | ||
| 1787 | |||
| 1788 | The global lock_ensures that mparams.magic and other unique | ||
| 1789 | mparams values are initialized only once. It also protects | ||
| 1790 | sequences of calls to MORECORE. In many cases sys_alloc requires | ||
| 1791 | two calls, that should not be interleaved with calls by other | ||
| 1792 | threads. This does not protect against direct calls to MORECORE | ||
| 1793 | by other threads not using this lock, so there is still code to | ||
| 1794 | cope the best we can on interference. | ||
| 1795 | |||
| 1796 | Per-mspace locks surround calls to malloc, free, etc. | ||
| 1797 | By default, locks are simple non-reentrant mutexes. | ||
| 1798 | |||
| 1799 | Because lock-protected regions generally have bounded times, it is | ||
| 1800 | OK to use the supplied simple spinlocks. Spinlocks are likely to | ||
| 1801 | improve performance for lightly contended applications, but worsen | ||
| 1802 | performance under heavy contention. | ||
| 1803 | |||
| 1804 | If USE_LOCKS is > 1, the definitions of lock routines here are | ||
| 1805 | bypassed, in which case you will need to define the type MLOCK_T, | ||
| 1806 | and at least INITIAL_LOCK, DESTROY_LOCK, ACQUIRE_LOCK, RELEASE_LOCK | ||
| 1807 | and TRY_LOCK. You must also declare a | ||
| 1808 | static MLOCK_T malloc_global_mutex = { initialization values };. | ||
| 1809 | |||
| 1810 | */ | ||
| 1811 | |||
| 1812 | #if !USE_LOCKS | ||
| 1813 | #define USE_LOCK_BIT (0U) | ||
| 1814 | #define INITIAL_LOCK(l) (0) | ||
| 1815 | #define DESTROY_LOCK(l) (0) | ||
| 1816 | #define ACQUIRE_MALLOC_GLOBAL_LOCK() | ||
| 1817 | #define RELEASE_MALLOC_GLOBAL_LOCK() | ||
| 1818 | |||
| 1819 | #else | ||
| 1820 | #if USE_LOCKS > 1 | ||
| 1821 | /* ----------------------- User-defined locks ------------------------ */ | ||
| 1822 | /* Define your own lock implementation here */ | ||
| 1823 | /* #define INITIAL_LOCK(lk) ... */ | ||
| 1824 | /* #define DESTROY_LOCK(lk) ... */ | ||
| 1825 | /* #define ACQUIRE_LOCK(lk) ... */ | ||
| 1826 | /* #define RELEASE_LOCK(lk) ... */ | ||
| 1827 | /* #define TRY_LOCK(lk) ... */ | ||
| 1828 | /* static MLOCK_T malloc_global_mutex = ... */ | ||
| 1829 | |||
| 1830 | #elif USE_SPIN_LOCKS | ||
| 1831 | |||
| 1832 | /* First, define CAS_LOCK and CLEAR_LOCK on ints */ | ||
| 1833 | /* Note CAS_LOCK defined to return 0 on success */ | ||
| 1834 | |||
| 1835 | #if defined(__GNUC__)&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) | ||
| 1836 | #define CAS_LOCK(sl) __sync_lock_test_and_set(sl, 1) | ||
| 1837 | #define CLEAR_LOCK(sl) __sync_lock_release(sl) | ||
| 1838 | |||
| 1839 | #elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) | ||
| 1840 | /* Custom spin locks for older gcc on x86 */ | ||
| 1841 | static FORCEINLINE int x86_cas_lock(int *sl) { | ||
| 1842 | int ret; | ||
| 1843 | int val = 1; | ||
| 1844 | int cmp = 0; | ||
| 1845 | __asm__ __volatile__ ("lock; cmpxchgl %1, %2" | ||
| 1846 | : "=a" (ret) | ||
| 1847 | : "r" (val), "m" (*(sl)), "0"(cmp) | ||
| 1848 | : "memory", "cc"); | ||
| 1849 | return ret; | ||
| 1850 | } | ||
| 1851 | |||
| 1852 | static FORCEINLINE void x86_clear_lock(int* sl) { | ||
| 1853 | assert(*sl != 0); | ||
| 1854 | int prev = 0; | ||
| 1855 | int ret; | ||
| 1856 | __asm__ __volatile__ ("lock; xchgl %0, %1" | ||
| 1857 | : "=r" (ret) | ||
| 1858 | : "m" (*(sl)), "0"(prev) | ||
| 1859 | : "memory"); | ||
| 1860 | } | ||
| 1861 | |||
| 1862 | #define CAS_LOCK(sl) x86_cas_lock(sl) | ||
| 1863 | #define CLEAR_LOCK(sl) x86_clear_lock(sl) | ||
| 1864 | |||
| 1865 | #else /* Win32 MSC */ | ||
| 1866 | #define CAS_LOCK(sl) interlockedexchange(sl, (LONG)1) | ||
| 1867 | #define CLEAR_LOCK(sl) interlockedexchange (sl, (LONG)0) | ||
| 1868 | |||
| 1869 | #endif /* ... gcc spins locks ... */ | ||
| 1870 | |||
| 1871 | /* How to yield for a spin lock */ | ||
| 1872 | #define SPINS_PER_YIELD 63 | ||
| 1873 | #if defined(_MSC_VER) | ||
| 1874 | #define SLEEP_EX_DURATION 50 /* delay for yield/sleep */ | ||
| 1875 | #define SPIN_LOCK_YIELD SleepEx(SLEEP_EX_DURATION, FALSE) | ||
| 1876 | #elif defined (__SVR4) && defined (__sun) /* solaris */ | ||
| 1877 | #define SPIN_LOCK_YIELD thr_yield(); | ||
| 1878 | #elif !defined(LACKS_SCHED_H) | ||
| 1879 | #define SPIN_LOCK_YIELD sched_yield(); | ||
| 1880 | #else | ||
| 1881 | #define SPIN_LOCK_YIELD | ||
| 1882 | #endif /* ... yield ... */ | ||
| 1883 | |||
| 1884 | #if !defined(USE_RECURSIVE_LOCKS) || USE_RECURSIVE_LOCKS == 0 | ||
| 1885 | /* Plain spin locks use single word (embedded in malloc_states) */ | ||
| 1886 | static int spin_acquire_lock(int *sl) { | ||
| 1887 | int spins = 0; | ||
| 1888 | while (*(volatile int *)sl != 0 || CAS_LOCK(sl)) { | ||
| 1889 | if ((++spins & SPINS_PER_YIELD) == 0) { | ||
| 1890 | SPIN_LOCK_YIELD; | ||
| 1891 | } | ||
| 1892 | } | ||
| 1893 | return 0; | ||
| 1894 | } | ||
| 1895 | |||
| 1896 | #define MLOCK_T int | ||
| 1897 | #define TRY_LOCK(sl) !CAS_LOCK(sl) | ||
| 1898 | #define RELEASE_LOCK(sl) CLEAR_LOCK(sl) | ||
| 1899 | #define ACQUIRE_LOCK(sl) (CAS_LOCK(sl)? spin_acquire_lock(sl) : 0) | ||
| 1900 | #define INITIAL_LOCK(sl) (*sl = 0) | ||
| 1901 | #define DESTROY_LOCK(sl) (0) | ||
| 1902 | static MLOCK_T malloc_global_mutex = 0; | ||
| 1903 | |||
| 1904 | #else /* USE_RECURSIVE_LOCKS */ | ||
| 1905 | /* types for lock owners */ | ||
| 1906 | #ifdef WIN32 | ||
| 1907 | #define THREAD_ID_T DWORD | ||
| 1908 | #define CURRENT_THREAD GetCurrentThreadId() | ||
| 1909 | #define EQ_OWNER(X,Y) ((X) == (Y)) | ||
| 1910 | #else | ||
| 1911 | /* | ||
| 1912 | Note: the following assume that pthread_t is a type that can be | ||
| 1913 | initialized to (casted) zero. If this is not the case, you will need to | ||
| 1914 | somehow redefine these or not use spin locks. | ||
| 1915 | */ | ||
| 1916 | #define THREAD_ID_T pthread_t | ||
| 1917 | #define CURRENT_THREAD pthread_self() | ||
| 1918 | #define EQ_OWNER(X,Y) pthread_equal(X, Y) | ||
| 1919 | #endif | ||
| 1920 | |||
| 1921 | struct malloc_recursive_lock { | ||
| 1922 | int sl; | ||
| 1923 | unsigned int c; | ||
| 1924 | THREAD_ID_T threadid; | ||
| 1925 | }; | ||
| 1926 | |||
| 1927 | #define MLOCK_T struct malloc_recursive_lock | ||
| 1928 | static MLOCK_T malloc_global_mutex = { 0, 0, (THREAD_ID_T)0}; | ||
| 1929 | |||
| 1930 | static FORCEINLINE void recursive_release_lock(MLOCK_T *lk) { | ||
| 1931 | assert(lk->sl != 0); | ||
| 1932 | if (--lk->c == 0) { | ||
| 1933 | CLEAR_LOCK(&lk->sl); | ||
| 1934 | } | ||
| 1935 | } | ||
| 1936 | |||
| 1937 | static FORCEINLINE int recursive_acquire_lock(MLOCK_T *lk) { | ||
| 1938 | THREAD_ID_T mythreadid = CURRENT_THREAD; | ||
| 1939 | int spins = 0; | ||
| 1940 | for (;;) { | ||
| 1941 | if (*((volatile int *)(&lk->sl)) == 0) { | ||
| 1942 | if (!CAS_LOCK(&lk->sl)) { | ||
| 1943 | lk->threadid = mythreadid; | ||
| 1944 | lk->c = 1; | ||
| 1945 | return 0; | ||
| 1946 | } | ||
| 1947 | } | ||
| 1948 | else if (EQ_OWNER(lk->threadid, mythreadid)) { | ||
| 1949 | ++lk->c; | ||
| 1950 | return 0; | ||
| 1951 | } | ||
| 1952 | if ((++spins & SPINS_PER_YIELD) == 0) { | ||
| 1953 | SPIN_LOCK_YIELD; | ||
| 1954 | } | ||
| 1955 | } | ||
| 1956 | } | ||
| 1957 | |||
| 1958 | static FORCEINLINE int recursive_try_lock(MLOCK_T *lk) { | ||
| 1959 | THREAD_ID_T mythreadid = CURRENT_THREAD; | ||
| 1960 | if (*((volatile int *)(&lk->sl)) == 0) { | ||
| 1961 | if (!CAS_LOCK(&lk->sl)) { | ||
| 1962 | lk->threadid = mythreadid; | ||
| 1963 | lk->c = 1; | ||
| 1964 | return 1; | ||
| 1965 | } | ||
| 1966 | } | ||
| 1967 | else if (EQ_OWNER(lk->threadid, mythreadid)) { | ||
| 1968 | ++lk->c; | ||
| 1969 | return 1; | ||
| 1970 | } | ||
| 1971 | return 0; | ||
| 1972 | } | ||
| 1973 | |||
| 1974 | #define RELEASE_LOCK(lk) recursive_release_lock(lk) | ||
| 1975 | #define TRY_LOCK(lk) recursive_try_lock(lk) | ||
| 1976 | #define ACQUIRE_LOCK(lk) recursive_acquire_lock(lk) | ||
| 1977 | #define INITIAL_LOCK(lk) ((lk)->threadid = (THREAD_ID_T)0, (lk)->sl = 0, (lk)->c = 0) | ||
| 1978 | #define DESTROY_LOCK(lk) (0) | ||
| 1979 | #endif /* USE_RECURSIVE_LOCKS */ | ||
| 1980 | |||
| 1981 | #elif defined(WIN32) /* Win32 critical sections */ | ||
| 1982 | #define MLOCK_T CRITICAL_SECTION | ||
| 1983 | #define ACQUIRE_LOCK(lk) (EnterCriticalSection(lk), 0) | ||
| 1984 | #define RELEASE_LOCK(lk) LeaveCriticalSection(lk) | ||
| 1985 | #define TRY_LOCK(lk) TryEnterCriticalSection(lk) | ||
| 1986 | #define INITIAL_LOCK(lk) (!InitializeCriticalSectionAndSpinCount((lk), 0x80000000|4000)) | ||
| 1987 | #define DESTROY_LOCK(lk) (DeleteCriticalSection(lk), 0) | ||
| 1988 | #define NEED_GLOBAL_LOCK_INIT | ||
| 1989 | |||
| 1990 | static MLOCK_T malloc_global_mutex; | ||
| 1991 | static volatile LONG malloc_global_mutex_status; | ||
| 1992 | |||
| 1993 | /* Use spin loop to initialize global lock */ | ||
| 1994 | static void init_malloc_global_mutex() { | ||
| 1995 | for (;;) { | ||
| 1996 | long stat = malloc_global_mutex_status; | ||
| 1997 | if (stat > 0) | ||
| 1998 | return; | ||
| 1999 | /* transition to < 0 while initializing, then to > 0) */ | ||
| 2000 | if (stat == 0 && | ||
| 2001 | interlockedcompareexchange(&malloc_global_mutex_status, (LONG)-1, (LONG)0) == 0) { | ||
| 2002 | InitializeCriticalSection(&malloc_global_mutex); | ||
| 2003 | interlockedexchange(&malloc_global_mutex_status, (LONG)1); | ||
| 2004 | return; | ||
| 2005 | } | ||
| 2006 | SleepEx(0, FALSE); | ||
| 2007 | } | ||
| 2008 | } | ||
| 2009 | |||
| 2010 | #else /* pthreads-based locks */ | ||
| 2011 | #define MLOCK_T pthread_mutex_t | ||
| 2012 | #define ACQUIRE_LOCK(lk) pthread_mutex_lock(lk) | ||
| 2013 | #define RELEASE_LOCK(lk) pthread_mutex_unlock(lk) | ||
| 2014 | #define TRY_LOCK(lk) (!pthread_mutex_trylock(lk)) | ||
| 2015 | #define INITIAL_LOCK(lk) pthread_init_lock(lk) | ||
| 2016 | #define DESTROY_LOCK(lk) pthread_mutex_destroy(lk) | ||
| 2017 | |||
| 2018 | #if defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0 && defined(linux) && !defined(PTHREAD_MUTEX_RECURSIVE) | ||
| 2019 | /* Cope with old-style linux recursive lock initialization by adding */ | ||
| 2020 | /* skipped internal declaration from pthread.h */ | ||
| 2021 | extern int pthread_mutexattr_setkind_np __P ((pthread_mutexattr_t *__attr, | ||
| 2022 | int __kind)); | ||
| 2023 | #define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP | ||
| 2024 | #define pthread_mutexattr_settype(x,y) pthread_mutexattr_setkind_np(x,y) | ||
| 2025 | #endif /* USE_RECURSIVE_LOCKS ... */ | ||
| 2026 | |||
| 2027 | static MLOCK_T malloc_global_mutex = PTHREAD_MUTEX_INITIALIZER; | ||
| 2028 | |||
| 2029 | static int pthread_init_lock (MLOCK_T *lk) { | ||
| 2030 | pthread_mutexattr_t attr; | ||
| 2031 | if (pthread_mutexattr_init(&attr)) return 1; | ||
| 2032 | #if defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0 | ||
| 2033 | if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) return 1; | ||
| 2034 | #endif | ||
| 2035 | if (pthread_mutex_init(lk, &attr)) return 1; | ||
| 2036 | if (pthread_mutexattr_destroy(&attr)) return 1; | ||
| 2037 | return 0; | ||
| 2038 | } | ||
| 2039 | |||
| 2040 | #endif /* ... lock types ... */ | ||
| 2041 | |||
| 2042 | /* Common code for all lock types */ | ||
| 2043 | #define USE_LOCK_BIT (2U) | ||
| 2044 | |||
| 2045 | #ifndef ACQUIRE_MALLOC_GLOBAL_LOCK | ||
| 2046 | #define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex); | ||
| 2047 | #endif | ||
| 2048 | |||
| 2049 | #ifndef RELEASE_MALLOC_GLOBAL_LOCK | ||
| 2050 | #define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex); | ||
| 2051 | #endif | ||
| 2052 | |||
| 2053 | #endif /* USE_LOCKS */ | ||
| 2054 | |||
| 2055 | /* ----------------------- Chunk representations ------------------------ */ | ||
| 2056 | |||
| 2057 | /* | ||
| 2058 | (The following includes lightly edited explanations by Colin Plumb.) | ||
| 2059 | |||
| 2060 | The malloc_chunk declaration below is misleading (but accurate and | ||
| 2061 | necessary). It declares a "view" into memory allowing access to | ||
| 2062 | necessary fields at known offsets from a given base. | ||
| 2063 | |||
| 2064 | Chunks of memory are maintained using a `boundary tag' method as | ||
| 2065 | originally described by Knuth. (See the paper by Paul Wilson | ||
| 2066 | ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such | ||
| 2067 | techniques.) Sizes of free chunks are stored both in the front of | ||
| 2068 | each chunk and at the end. This makes consolidating fragmented | ||
| 2069 | chunks into bigger chunks fast. The head fields also hold bits | ||
| 2070 | representing whether chunks are free or in use. | ||
| 2071 | |||
| 2072 | Here are some pictures to make it clearer. They are "exploded" to | ||
| 2073 | show that the state of a chunk can be thought of as extending from | ||
| 2074 | the high 31 bits of the head field of its header through the | ||
| 2075 | prev_foot and PINUSE_BIT bit of the following chunk header. | ||
| 2076 | |||
| 2077 | A chunk that's in use looks like: | ||
| 2078 | |||
| 2079 | chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2080 | | Size of previous chunk (if P = 0) | | ||
| 2081 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2082 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| | ||
| 2083 | | Size of this chunk 1| +-+ | ||
| 2084 | mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2085 | | | | ||
| 2086 | +- -+ | ||
| 2087 | | | | ||
| 2088 | +- -+ | ||
| 2089 | | : | ||
| 2090 | +- size - sizeof(size_t) available payload bytes -+ | ||
| 2091 | : | | ||
| 2092 | chunk-> +- -+ | ||
| 2093 | | | | ||
| 2094 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2095 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1| | ||
| 2096 | | Size of next chunk (may or may not be in use) | +-+ | ||
| 2097 | mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2098 | |||
| 2099 | And if it's free, it looks like this: | ||
| 2100 | |||
| 2101 | chunk-> +- -+ | ||
| 2102 | | User payload (must be in use, or we would have merged!) | | ||
| 2103 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2104 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| | ||
| 2105 | | Size of this chunk 0| +-+ | ||
| 2106 | mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2107 | | Next pointer | | ||
| 2108 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2109 | | Prev pointer | | ||
| 2110 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2111 | | : | ||
| 2112 | +- size - sizeof(struct chunk) unused bytes -+ | ||
| 2113 | : | | ||
| 2114 | chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2115 | | Size of this chunk | | ||
| 2116 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2117 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0| | ||
| 2118 | | Size of next chunk (must be in use, or we would have merged)| +-+ | ||
| 2119 | mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2120 | | : | ||
| 2121 | +- User payload -+ | ||
| 2122 | : | | ||
| 2123 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2124 | |0| | ||
| 2125 | +-+ | ||
| 2126 | Note that since we always merge adjacent free chunks, the chunks | ||
| 2127 | adjacent to a free chunk must be in use. | ||
| 2128 | |||
| 2129 | Given a pointer to a chunk (which can be derived trivially from the | ||
| 2130 | payload pointer) we can, in O(1) time, find out whether the adjacent | ||
| 2131 | chunks are free, and if so, unlink them from the lists that they | ||
| 2132 | are on and merge them with the current chunk. | ||
| 2133 | |||
| 2134 | Chunks always begin on even word boundaries, so the mem portion | ||
| 2135 | (which is returned to the user) is also on an even word boundary, and | ||
| 2136 | thus at least double-word aligned. | ||
| 2137 | |||
| 2138 | The P (PINUSE_BIT) bit, stored in the unused low-order bit of the | ||
| 2139 | chunk size (which is always a multiple of two words), is an in-use | ||
| 2140 | bit for the *previous* chunk. If that bit is *clear*, then the | ||
| 2141 | word before the current chunk size contains the previous chunk | ||
| 2142 | size, and can be used to find the front of the previous chunk. | ||
| 2143 | The very first chunk allocated always has this bit set, preventing | ||
| 2144 | access to non-existent (or non-owned) memory. If pinuse is set for | ||
| 2145 | any given chunk, then you CANNOT determine the size of the | ||
| 2146 | previous chunk, and might even get a memory addressing fault when | ||
| 2147 | trying to do so. | ||
| 2148 | |||
| 2149 | The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of | ||
| 2150 | the chunk size redundantly records whether the current chunk is | ||
| 2151 | inuse (unless the chunk is mmapped). This redundancy enables usage | ||
| 2152 | checks within free and realloc, and reduces indirection when freeing | ||
| 2153 | and consolidating chunks. | ||
| 2154 | |||
| 2155 | Each freshly allocated chunk must have both cinuse and pinuse set. | ||
| 2156 | That is, each allocated chunk borders either a previously allocated | ||
| 2157 | and still in-use chunk, or the base of its memory arena. This is | ||
| 2158 | ensured by making all allocations from the `lowest' part of any | ||
| 2159 | found chunk. Further, no free chunk physically borders another one, | ||
| 2160 | so each free chunk is known to be preceded and followed by either | ||
| 2161 | inuse chunks or the ends of memory. | ||
| 2162 | |||
| 2163 | Note that the `foot' of the current chunk is actually represented | ||
| 2164 | as the prev_foot of the NEXT chunk. This makes it easier to | ||
| 2165 | deal with alignments etc but can be very confusing when trying | ||
| 2166 | to extend or adapt this code. | ||
| 2167 | |||
| 2168 | The exceptions to all this are | ||
| 2169 | |||
| 2170 | 1. The special chunk `top' is the top-most available chunk (i.e., | ||
| 2171 | the one bordering the end of available memory). It is treated | ||
| 2172 | specially. Top is never included in any bin, is used only if | ||
| 2173 | no other chunk is available, and is released back to the | ||
| 2174 | system if it is very large (see M_TRIM_THRESHOLD). In effect, | ||
| 2175 | the top chunk is treated as larger (and thus less well | ||
| 2176 | fitting) than any other available chunk. The top chunk | ||
| 2177 | doesn't update its trailing size field since there is no next | ||
| 2178 | contiguous chunk that would have to index off it. However, | ||
| 2179 | space is still allocated for it (TOP_FOOT_SIZE) to enable | ||
| 2180 | separation or merging when space is extended. | ||
| 2181 | |||
| 2182 | 3. Chunks allocated via mmap, have both cinuse and pinuse bits | ||
| 2183 | cleared in their head fields. Because they are allocated | ||
| 2184 | one-by-one, each must carry its own prev_foot field, which is | ||
| 2185 | also used to hold the offset this chunk has within its mmapped | ||
| 2186 | region, which is needed to preserve alignment. Each mmapped | ||
| 2187 | chunk is trailed by the first two fields of a fake next-chunk | ||
| 2188 | for sake of usage checks. | ||
| 2189 | |||
| 2190 | */ | ||
| 2191 | |||
| 2192 | struct malloc_chunk { | ||
| 2193 | size_t prev_foot; /* Size of previous chunk (if free). */ | ||
| 2194 | size_t head; /* Size and inuse bits. */ | ||
| 2195 | struct malloc_chunk* fd; /* double links -- used only if free. */ | ||
| 2196 | struct malloc_chunk* bk; | ||
| 2197 | }; | ||
| 2198 | |||
| 2199 | typedef struct malloc_chunk mchunk; | ||
| 2200 | typedef struct malloc_chunk* mchunkptr; | ||
| 2201 | typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */ | ||
| 2202 | typedef unsigned int bindex_t; /* Described below */ | ||
| 2203 | typedef unsigned int binmap_t; /* Described below */ | ||
| 2204 | typedef unsigned int flag_t; /* The type of various bit flag sets */ | ||
| 2205 | |||
| 2206 | /* ------------------- Chunks sizes and alignments ----------------------- */ | ||
| 2207 | |||
| 2208 | #define MCHUNK_SIZE (sizeof(mchunk)) | ||
| 2209 | |||
| 2210 | #if FOOTERS | ||
| 2211 | #define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) | ||
| 2212 | #else /* FOOTERS */ | ||
| 2213 | #define CHUNK_OVERHEAD (SIZE_T_SIZE) | ||
| 2214 | #endif /* FOOTERS */ | ||
| 2215 | |||
| 2216 | /* MMapped chunks need a second word of overhead ... */ | ||
| 2217 | #define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) | ||
| 2218 | /* ... and additional padding for fake next-chunk at foot */ | ||
| 2219 | #define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) | ||
| 2220 | |||
| 2221 | /* The smallest size we can malloc is an aligned minimal chunk */ | ||
| 2222 | #define MIN_CHUNK_SIZE\ | ||
| 2223 | ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) | ||
| 2224 | |||
| 2225 | /* conversion from malloc headers to user pointers, and back */ | ||
| 2226 | #define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) | ||
| 2227 | #define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) | ||
| 2228 | /* chunk associated with aligned address A */ | ||
| 2229 | #define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) | ||
| 2230 | |||
| 2231 | /* Bounds on request (not chunk) sizes. */ | ||
| 2232 | #define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) | ||
| 2233 | #define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) | ||
| 2234 | |||
| 2235 | /* pad request bytes into a usable size */ | ||
| 2236 | #define pad_request(req) \ | ||
| 2237 | (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) | ||
| 2238 | |||
| 2239 | /* pad request, checking for minimum (but not maximum) */ | ||
| 2240 | #define request2size(req) \ | ||
| 2241 | (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) | ||
| 2242 | |||
| 2243 | |||
| 2244 | /* ------------------ Operations on head and foot fields ----------------- */ | ||
| 2245 | |||
| 2246 | /* | ||
| 2247 | The head field of a chunk is or'ed with PINUSE_BIT when previous | ||
| 2248 | adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in | ||
| 2249 | use, unless mmapped, in which case both bits are cleared. | ||
| 2250 | |||
| 2251 | FLAG4_BIT is not used by this malloc, but might be useful in extensions. | ||
| 2252 | */ | ||
| 2253 | |||
| 2254 | #define PINUSE_BIT (SIZE_T_ONE) | ||
| 2255 | #define CINUSE_BIT (SIZE_T_TWO) | ||
| 2256 | #define FLAG4_BIT (SIZE_T_FOUR) | ||
| 2257 | #define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) | ||
| 2258 | #define FLAG_BITS (PINUSE_BIT|CINUSE_BIT|FLAG4_BIT) | ||
| 2259 | |||
| 2260 | /* Head value for fenceposts */ | ||
| 2261 | #define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) | ||
| 2262 | |||
| 2263 | /* extraction of fields from head words */ | ||
| 2264 | #define cinuse(p) ((p)->head & CINUSE_BIT) | ||
| 2265 | #define pinuse(p) ((p)->head & PINUSE_BIT) | ||
| 2266 | #define flag4inuse(p) ((p)->head & FLAG4_BIT) | ||
| 2267 | #define is_inuse(p) (((p)->head & INUSE_BITS) != PINUSE_BIT) | ||
| 2268 | #define is_mmapped(p) (((p)->head & INUSE_BITS) == 0) | ||
| 2269 | |||
| 2270 | #define chunksize(p) ((p)->head & ~(FLAG_BITS)) | ||
| 2271 | |||
| 2272 | #define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) | ||
| 2273 | #define set_flag4(p) ((p)->head |= FLAG4_BIT) | ||
| 2274 | #define clear_flag4(p) ((p)->head &= ~FLAG4_BIT) | ||
| 2275 | |||
| 2276 | /* Treat space at ptr +/- offset as a chunk */ | ||
| 2277 | #define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) | ||
| 2278 | #define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s))) | ||
| 2279 | |||
| 2280 | /* Ptr to next or previous physical malloc_chunk. */ | ||
| 2281 | #define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~FLAG_BITS))) | ||
| 2282 | #define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) | ||
| 2283 | |||
| 2284 | /* extract next chunk's pinuse bit */ | ||
| 2285 | #define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) | ||
| 2286 | |||
| 2287 | /* Get/set size at footer */ | ||
| 2288 | #define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot) | ||
| 2289 | #define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s)) | ||
| 2290 | |||
| 2291 | /* Set size, pinuse bit, and foot */ | ||
| 2292 | #define set_size_and_pinuse_of_free_chunk(p, s)\ | ||
| 2293 | ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) | ||
| 2294 | |||
| 2295 | /* Set size, pinuse bit, foot, and clear next pinuse */ | ||
| 2296 | #define set_free_with_pinuse(p, s, n)\ | ||
| 2297 | (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) | ||
| 2298 | |||
| 2299 | /* Get the internal overhead associated with chunk p */ | ||
| 2300 | #define overhead_for(p)\ | ||
| 2301 | (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) | ||
| 2302 | |||
| 2303 | /* Return true if malloced space is not necessarily cleared */ | ||
| 2304 | #if MMAP_CLEARS | ||
| 2305 | #define calloc_must_clear(p) (!is_mmapped(p)) | ||
| 2306 | #else /* MMAP_CLEARS */ | ||
| 2307 | #define calloc_must_clear(p) (1) | ||
| 2308 | #endif /* MMAP_CLEARS */ | ||
| 2309 | |||
| 2310 | /* ---------------------- Overlaid data structures ----------------------- */ | ||
| 2311 | |||
| 2312 | /* | ||
| 2313 | When chunks are not in use, they are treated as nodes of either | ||
| 2314 | lists or trees. | ||
| 2315 | |||
| 2316 | "Small" chunks are stored in circular doubly-linked lists, and look | ||
| 2317 | like this: | ||
| 2318 | |||
| 2319 | chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2320 | | Size of previous chunk | | ||
| 2321 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2322 | `head:' | Size of chunk, in bytes |P| | ||
| 2323 | mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2324 | | Forward pointer to next chunk in list | | ||
| 2325 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2326 | | Back pointer to previous chunk in list | | ||
| 2327 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2328 | | Unused space (may be 0 bytes long) . | ||
| 2329 | . . | ||
| 2330 | . | | ||
| 2331 | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2332 | `foot:' | Size of chunk, in bytes | | ||
| 2333 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2334 | |||
| 2335 | Larger chunks are kept in a form of bitwise digital trees (aka | ||
| 2336 | tries) keyed on chunksizes. Because malloc_tree_chunks are only for | ||
| 2337 | free chunks greater than 256 bytes, their size doesn't impose any | ||
| 2338 | constraints on user chunk sizes. Each node looks like: | ||
| 2339 | |||
| 2340 | chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2341 | | Size of previous chunk | | ||
| 2342 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2343 | `head:' | Size of chunk, in bytes |P| | ||
| 2344 | mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2345 | | Forward pointer to next chunk of same size | | ||
| 2346 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2347 | | Back pointer to previous chunk of same size | | ||
| 2348 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2349 | | Pointer to left child (child[0]) | | ||
| 2350 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2351 | | Pointer to right child (child[1]) | | ||
| 2352 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2353 | | Pointer to parent | | ||
| 2354 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2355 | | bin index of this chunk | | ||
| 2356 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2357 | | Unused space . | ||
| 2358 | . | | ||
| 2359 | nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2360 | `foot:' | Size of chunk, in bytes | | ||
| 2361 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | ||
| 2362 | |||
| 2363 | Each tree holding treenodes is a tree of unique chunk sizes. Chunks | ||
| 2364 | of the same size are arranged in a circularly-linked list, with only | ||
| 2365 | the oldest chunk (the next to be used, in our FIFO ordering) | ||
| 2366 | actually in the tree. (Tree members are distinguished by a non-null | ||
| 2367 | parent pointer.) If a chunk with the same size an an existing node | ||
| 2368 | is inserted, it is linked off the existing node using pointers that | ||
| 2369 | work in the same way as fd/bk pointers of small chunks. | ||
| 2370 | |||
| 2371 | Each tree contains a power of 2 sized range of chunk sizes (the | ||
| 2372 | smallest is 0x100 <= x < 0x180), which is is divided in half at each | ||
| 2373 | tree level, with the chunks in the smaller half of the range (0x100 | ||
| 2374 | <= x < 0x140 for the top nose) in the left subtree and the larger | ||
| 2375 | half (0x140 <= x < 0x180) in the right subtree. This is, of course, | ||
| 2376 | done by inspecting individual bits. | ||
| 2377 | |||
| 2378 | Using these rules, each node's left subtree contains all smaller | ||
| 2379 | sizes than its right subtree. However, the node at the root of each | ||
| 2380 | subtree has no particular ordering relationship to either. (The | ||
| 2381 | dividing line between the subtree sizes is based on trie relation.) | ||
| 2382 | If we remove the last chunk of a given size from the interior of the | ||
| 2383 | tree, we need to replace it with a leaf node. The tree ordering | ||
| 2384 | rules permit a node to be replaced by any leaf below it. | ||
| 2385 | |||
| 2386 | The smallest chunk in a tree (a common operation in a best-fit | ||
| 2387 | allocator) can be found by walking a path to the leftmost leaf in | ||
| 2388 | the tree. Unlike a usual binary tree, where we follow left child | ||
| 2389 | pointers until we reach a null, here we follow the right child | ||
| 2390 | pointer any time the left one is null, until we reach a leaf with | ||
| 2391 | both child pointers null. The smallest chunk in the tree will be | ||
| 2392 | somewhere along that path. | ||
| 2393 | |||
| 2394 | The worst case number of steps to add, find, or remove a node is | ||
| 2395 | bounded by the number of bits differentiating chunks within | ||
| 2396 | bins. Under current bin calculations, this ranges from 6 up to 21 | ||
| 2397 | (for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case | ||
| 2398 | is of course much better. | ||
| 2399 | */ | ||
| 2400 | |||
| 2401 | struct malloc_tree_chunk { | ||
| 2402 | /* The first four fields must be compatible with malloc_chunk */ | ||
| 2403 | size_t prev_foot; | ||
| 2404 | size_t head; | ||
| 2405 | struct malloc_tree_chunk* fd; | ||
| 2406 | struct malloc_tree_chunk* bk; | ||
| 2407 | |||
| 2408 | struct malloc_tree_chunk* child[2]; | ||
| 2409 | struct malloc_tree_chunk* parent; | ||
| 2410 | bindex_t index; | ||
| 2411 | }; | ||
| 2412 | |||
| 2413 | typedef struct malloc_tree_chunk tchunk; | ||
| 2414 | typedef struct malloc_tree_chunk* tchunkptr; | ||
| 2415 | typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */ | ||
| 2416 | |||
| 2417 | /* A little helper macro for trees */ | ||
| 2418 | #define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) | ||
| 2419 | |||
| 2420 | /* ----------------------------- Segments -------------------------------- */ | ||
| 2421 | |||
| 2422 | /* | ||
| 2423 | Each malloc space may include non-contiguous segments, held in a | ||
| 2424 | list headed by an embedded malloc_segment record representing the | ||
| 2425 | top-most space. Segments also include flags holding properties of | ||
| 2426 | the space. Large chunks that are directly allocated by mmap are not | ||
| 2427 | included in this list. They are instead independently created and | ||
| 2428 | destroyed without otherwise keeping track of them. | ||
| 2429 | |||
| 2430 | Segment management mainly comes into play for spaces allocated by | ||
| 2431 | MMAP. Any call to MMAP might or might not return memory that is | ||
| 2432 | adjacent to an existing segment. MORECORE normally contiguously | ||
| 2433 | extends the current space, so this space is almost always adjacent, | ||
| 2434 | which is simpler and faster to deal with. (This is why MORECORE is | ||
| 2435 | used preferentially to MMAP when both are available -- see | ||
| 2436 | sys_alloc.) When allocating using MMAP, we don't use any of the | ||
| 2437 | hinting mechanisms (inconsistently) supported in various | ||
| 2438 | implementations of unix mmap, or distinguish reserving from | ||
| 2439 | committing memory. Instead, we just ask for space, and exploit | ||
| 2440 | contiguity when we get it. It is probably possible to do | ||
| 2441 | better than this on some systems, but no general scheme seems | ||
| 2442 | to be significantly better. | ||
| 2443 | |||
| 2444 | Management entails a simpler variant of the consolidation scheme | ||
| 2445 | used for chunks to reduce fragmentation -- new adjacent memory is | ||
| 2446 | normally prepended or appended to an existing segment. However, | ||
| 2447 | there are limitations compared to chunk consolidation that mostly | ||
| 2448 | reflect the fact that segment processing is relatively infrequent | ||
| 2449 | (occurring only when getting memory from system) and that we | ||
| 2450 | don't expect to have huge numbers of segments: | ||
| 2451 | |||
| 2452 | * Segments are not indexed, so traversal requires linear scans. (It | ||
| 2453 | would be possible to index these, but is not worth the extra | ||
| 2454 | overhead and complexity for most programs on most platforms.) | ||
| 2455 | * New segments are only appended to old ones when holding top-most | ||
| 2456 | memory; if they cannot be prepended to others, they are held in | ||
| 2457 | different segments. | ||
| 2458 | |||
| 2459 | Except for the top-most segment of an mstate, each segment record | ||
| 2460 | is kept at the tail of its segment. Segments are added by pushing | ||
| 2461 | segment records onto the list headed by &mstate.seg for the | ||
| 2462 | containing mstate. | ||
| 2463 | |||
| 2464 | Segment flags control allocation/merge/deallocation policies: | ||
| 2465 | * If EXTERN_BIT set, then we did not allocate this segment, | ||
| 2466 | and so should not try to deallocate or merge with others. | ||
| 2467 | (This currently holds only for the initial segment passed | ||
| 2468 | into create_mspace_with_base.) | ||
| 2469 | * If USE_MMAP_BIT set, the segment may be merged with | ||
| 2470 | other surrounding mmapped segments and trimmed/de-allocated | ||
| 2471 | using munmap. | ||
| 2472 | * If neither bit is set, then the segment was obtained using | ||
| 2473 | MORECORE so can be merged with surrounding MORECORE'd segments | ||
| 2474 | and deallocated/trimmed using MORECORE with negative arguments. | ||
| 2475 | */ | ||
| 2476 | |||
| 2477 | struct malloc_segment { | ||
| 2478 | char* base; /* base address */ | ||
| 2479 | size_t size; /* allocated size */ | ||
| 2480 | struct malloc_segment* next; /* ptr to next segment */ | ||
| 2481 | flag_t sflags; /* mmap and extern flag */ | ||
| 2482 | }; | ||
| 2483 | |||
| 2484 | #define is_mmapped_segment(S) ((S)->sflags & USE_MMAP_BIT) | ||
| 2485 | #define is_extern_segment(S) ((S)->sflags & EXTERN_BIT) | ||
| 2486 | |||
| 2487 | typedef struct malloc_segment msegment; | ||
| 2488 | typedef struct malloc_segment* msegmentptr; | ||
| 2489 | |||
| 2490 | /* ---------------------------- malloc_state ----------------------------- */ | ||
| 2491 | |||
| 2492 | /* | ||
| 2493 | A malloc_state holds all of the bookkeeping for a space. | ||
| 2494 | The main fields are: | ||
| 2495 | |||
| 2496 | Top | ||
| 2497 | The topmost chunk of the currently active segment. Its size is | ||
| 2498 | cached in topsize. The actual size of topmost space is | ||
| 2499 | topsize+TOP_FOOT_SIZE, which includes space reserved for adding | ||
| 2500 | fenceposts and segment records if necessary when getting more | ||
| 2501 | space from the system. The size at which to autotrim top is | ||
| 2502 | cached from mparams in trim_check, except that it is disabled if | ||
| 2503 | an autotrim fails. | ||
| 2504 | |||
| 2505 | Designated victim (dv) | ||
| 2506 | This is the preferred chunk for servicing small requests that | ||
| 2507 | don't have exact fits. It is normally the chunk split off most | ||
| 2508 | recently to service another small request. Its size is cached in | ||
| 2509 | dvsize. The link fields of this chunk are not maintained since it | ||
| 2510 | is not kept in a bin. | ||
| 2511 | |||
| 2512 | SmallBins | ||
| 2513 | An array of bin headers for free chunks. These bins hold chunks | ||
| 2514 | with sizes less than MIN_LARGE_SIZE bytes. Each bin contains | ||
| 2515 | chunks of all the same size, spaced 8 bytes apart. To simplify | ||
| 2516 | use in double-linked lists, each bin header acts as a malloc_chunk | ||
| 2517 | pointing to the real first node, if it exists (else pointing to | ||
| 2518 | itself). This avoids special-casing for headers. But to avoid | ||
| 2519 | waste, we allocate only the fd/bk pointers of bins, and then use | ||
| 2520 | repositioning tricks to treat these as the fields of a chunk. | ||
| 2521 | |||
| 2522 | TreeBins | ||
| 2523 | Treebins are pointers to the roots of trees holding a range of | ||
| 2524 | sizes. There are 2 equally spaced treebins for each power of two | ||
| 2525 | from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything | ||
| 2526 | larger. | ||
| 2527 | |||
| 2528 | Bin maps | ||
| 2529 | There is one bit map for small bins ("smallmap") and one for | ||
| 2530 | treebins ("treemap). Each bin sets its bit when non-empty, and | ||
| 2531 | clears the bit when empty. Bit operations are then used to avoid | ||
| 2532 | bin-by-bin searching -- nearly all "search" is done without ever | ||
| 2533 | looking at bins that won't be selected. The bit maps | ||
| 2534 | conservatively use 32 bits per map word, even if on 64bit system. | ||
| 2535 | For a good description of some of the bit-based techniques used | ||
| 2536 | here, see Henry S. Warren Jr's book "Hacker's Delight" (and | ||
| 2537 | supplement at http://hackersdelight.org/). Many of these are | ||
| 2538 | intended to reduce the branchiness of paths through malloc etc, as | ||
| 2539 | well as to reduce the number of memory locations read or written. | ||
| 2540 | |||
| 2541 | Segments | ||
| 2542 | A list of segments headed by an embedded malloc_segment record | ||
| 2543 | representing the initial space. | ||
| 2544 | |||
| 2545 | Address check support | ||
| 2546 | The least_addr field is the least address ever obtained from | ||
| 2547 | MORECORE or MMAP. Attempted frees and reallocs of any address less | ||
| 2548 | than this are trapped (unless INSECURE is defined). | ||
| 2549 | |||
| 2550 | Magic tag | ||
| 2551 | A cross-check field that should always hold same value as mparams.magic. | ||
| 2552 | |||
| 2553 | Max allowed footprint | ||
| 2554 | The maximum allowed bytes to allocate from system (zero means no limit) | ||
| 2555 | |||
| 2556 | Flags | ||
| 2557 | Bits recording whether to use MMAP, locks, or contiguous MORECORE | ||
| 2558 | |||
| 2559 | Statistics | ||
| 2560 | Each space keeps track of current and maximum system memory | ||
| 2561 | obtained via MORECORE or MMAP. | ||
| 2562 | |||
| 2563 | Trim support | ||
| 2564 | Fields holding the amount of unused topmost memory that should trigger | ||
| 2565 | trimming, and a counter to force periodic scanning to release unused | ||
| 2566 | non-topmost segments. | ||
| 2567 | |||
| 2568 | Locking | ||
| 2569 | If USE_LOCKS is defined, the "mutex" lock is acquired and released | ||
| 2570 | around every public call using this mspace. | ||
| 2571 | |||
| 2572 | Extension support | ||
| 2573 | A void* pointer and a size_t field that can be used to help implement | ||
| 2574 | extensions to this malloc. | ||
| 2575 | */ | ||
| 2576 | |||
| 2577 | /* Bin types, widths and sizes */ | ||
| 2578 | #define NSMALLBINS (32U) | ||
| 2579 | #define NTREEBINS (32U) | ||
| 2580 | #define SMALLBIN_SHIFT (3U) | ||
| 2581 | #define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) | ||
| 2582 | #define TREEBIN_SHIFT (8U) | ||
| 2583 | #define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) | ||
| 2584 | #define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) | ||
| 2585 | #define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) | ||
| 2586 | |||
| 2587 | struct malloc_state { | ||
| 2588 | binmap_t smallmap; | ||
| 2589 | binmap_t treemap; | ||
| 2590 | size_t dvsize; | ||
| 2591 | size_t topsize; | ||
| 2592 | char* least_addr; | ||
| 2593 | mchunkptr dv; | ||
| 2594 | mchunkptr top; | ||
| 2595 | size_t trim_check; | ||
| 2596 | size_t release_checks; | ||
| 2597 | size_t magic; | ||
| 2598 | mchunkptr smallbins[(NSMALLBINS+1)*2]; | ||
| 2599 | tbinptr treebins[NTREEBINS]; | ||
| 2600 | size_t footprint; | ||
| 2601 | size_t max_footprint; | ||
| 2602 | size_t footprint_limit; /* zero means no limit */ | ||
| 2603 | flag_t mflags; | ||
| 2604 | #if USE_LOCKS | ||
| 2605 | MLOCK_T mutex; /* locate lock among fields that rarely change */ | ||
| 2606 | #endif /* USE_LOCKS */ | ||
| 2607 | msegment seg; | ||
| 2608 | void* extp; /* Unused but available for extensions */ | ||
| 2609 | size_t exts; | ||
| 2610 | }; | ||
| 2611 | |||
| 2612 | typedef struct malloc_state* mstate; | ||
| 2613 | |||
| 2614 | /* ------------- Global malloc_state and malloc_params ------------------- */ | ||
| 2615 | |||
| 2616 | /* | ||
| 2617 | malloc_params holds global properties, including those that can be | ||
| 2618 | dynamically set using mallopt. There is a single instance, mparams, | ||
| 2619 | initialized in init_mparams. Note that the non-zeroness of "magic" | ||
| 2620 | also serves as an initialization flag. | ||
| 2621 | */ | ||
| 2622 | |||
| 2623 | struct malloc_params { | ||
| 2624 | size_t magic; | ||
| 2625 | size_t page_size; | ||
| 2626 | size_t granularity; | ||
| 2627 | size_t mmap_threshold; | ||
| 2628 | size_t trim_threshold; | ||
| 2629 | flag_t default_mflags; | ||
| 2630 | }; | ||
| 2631 | |||
| 2632 | static struct malloc_params mparams; | ||
| 2633 | |||
| 2634 | /* Ensure mparams initialized */ | ||
| 2635 | #define ensure_initialization() (void)(mparams.magic != 0 || init_mparams()) | ||
| 2636 | |||
| 2637 | #if !ONLY_MSPACES | ||
| 2638 | |||
| 2639 | /* The global malloc_state used for all non-"mspace" calls */ | ||
| 2640 | static struct malloc_state _gm_; | ||
| 2641 | #define gm (&_gm_) | ||
| 2642 | #define is_global(M) ((M) == &_gm_) | ||
| 2643 | |||
| 2644 | #endif /* !ONLY_MSPACES */ | ||
| 2645 | |||
| 2646 | #define is_initialized(M) ((M)->top != 0) | ||
| 2647 | |||
| 2648 | /* -------------------------- system alloc setup ------------------------- */ | ||
| 2649 | |||
| 2650 | /* Operations on mflags */ | ||
| 2651 | |||
| 2652 | #define use_lock(M) ((M)->mflags & USE_LOCK_BIT) | ||
| 2653 | #define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT) | ||
| 2654 | #if USE_LOCKS | ||
| 2655 | #define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT) | ||
| 2656 | #else | ||
| 2657 | #define disable_lock(M) | ||
| 2658 | #endif | ||
| 2659 | |||
| 2660 | #define use_mmap(M) ((M)->mflags & USE_MMAP_BIT) | ||
| 2661 | #define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT) | ||
| 2662 | #if HAVE_MMAP | ||
| 2663 | #define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT) | ||
| 2664 | #else | ||
| 2665 | #define disable_mmap(M) | ||
| 2666 | #endif | ||
| 2667 | |||
| 2668 | #define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT) | ||
| 2669 | #define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT) | ||
| 2670 | |||
| 2671 | #define set_lock(M,L)\ | ||
| 2672 | ((M)->mflags = (L)?\ | ||
| 2673 | ((M)->mflags | USE_LOCK_BIT) :\ | ||
| 2674 | ((M)->mflags & ~USE_LOCK_BIT)) | ||
| 2675 | |||
| 2676 | /* page-align a size */ | ||
| 2677 | #define page_align(S)\ | ||
| 2678 | (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) | ||
| 2679 | |||
| 2680 | /* granularity-align a size */ | ||
| 2681 | #define granularity_align(S)\ | ||
| 2682 | (((S) + (mparams.granularity - SIZE_T_ONE))\ | ||
| 2683 | & ~(mparams.granularity - SIZE_T_ONE)) | ||
| 2684 | |||
| 2685 | |||
| 2686 | /* For mmap, use granularity alignment on windows, else page-align */ | ||
| 2687 | #ifdef WIN32 | ||
| 2688 | #define mmap_align(S) granularity_align(S) | ||
| 2689 | #else | ||
| 2690 | #define mmap_align(S) page_align(S) | ||
| 2691 | #endif | ||
| 2692 | |||
| 2693 | /* For sys_alloc, enough padding to ensure can malloc request on success */ | ||
| 2694 | #define SYS_ALLOC_PADDING (TOP_FOOT_SIZE + MALLOC_ALIGNMENT) | ||
| 2695 | |||
| 2696 | #define is_page_aligned(S)\ | ||
| 2697 | (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) | ||
| 2698 | #define is_granularity_aligned(S)\ | ||
| 2699 | (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) | ||
| 2700 | |||
| 2701 | /* True if segment S holds address A */ | ||
| 2702 | #define segment_holds(S, A)\ | ||
| 2703 | ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) | ||
| 2704 | |||
| 2705 | /* Return segment holding given address */ | ||
| 2706 | static msegmentptr segment_holding(mstate m, char* addr) { | ||
| 2707 | msegmentptr sp = &m->seg; | ||
| 2708 | for (;;) { | ||
| 2709 | if (addr >= sp->base && addr < sp->base + sp->size) | ||
| 2710 | return sp; | ||
| 2711 | if ((sp = sp->next) == 0) | ||
| 2712 | return 0; | ||
| 2713 | } | ||
| 2714 | } | ||
| 2715 | |||
| 2716 | /* Return true if segment contains a segment link */ | ||
| 2717 | static int has_segment_link(mstate m, msegmentptr ss) { | ||
| 2718 | msegmentptr sp = &m->seg; | ||
| 2719 | for (;;) { | ||
| 2720 | if ((char*)sp >= ss->base && (char*)sp < ss->base + ss->size) | ||
| 2721 | return 1; | ||
| 2722 | if ((sp = sp->next) == 0) | ||
| 2723 | return 0; | ||
| 2724 | } | ||
| 2725 | } | ||
| 2726 | |||
| 2727 | #ifndef MORECORE_CANNOT_TRIM | ||
| 2728 | #define should_trim(M,s) ((s) > (M)->trim_check) | ||
| 2729 | #else /* MORECORE_CANNOT_TRIM */ | ||
| 2730 | #define should_trim(M,s) (0) | ||
| 2731 | #endif /* MORECORE_CANNOT_TRIM */ | ||
| 2732 | |||
| 2733 | /* | ||
| 2734 | TOP_FOOT_SIZE is padding at the end of a segment, including space | ||
| 2735 | that may be needed to place segment records and fenceposts when new | ||
| 2736 | noncontiguous segments are added. | ||
| 2737 | */ | ||
| 2738 | #define TOP_FOOT_SIZE\ | ||
| 2739 | (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) | ||
| 2740 | |||
| 2741 | |||
| 2742 | /* ------------------------------- Hooks -------------------------------- */ | ||
| 2743 | |||
| 2744 | /* | ||
| 2745 | PREACTION should be defined to return 0 on success, and nonzero on | ||
| 2746 | failure. If you are not using locking, you can redefine these to do | ||
| 2747 | anything you like. | ||
| 2748 | */ | ||
| 2749 | |||
| 2750 | #if USE_LOCKS | ||
| 2751 | #define PREACTION(M) ((use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0) | ||
| 2752 | #define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); } | ||
| 2753 | #else /* USE_LOCKS */ | ||
| 2754 | |||
| 2755 | #ifndef PREACTION | ||
| 2756 | #define PREACTION(M) (0) | ||
| 2757 | #endif /* PREACTION */ | ||
| 2758 | |||
| 2759 | #ifndef POSTACTION | ||
| 2760 | #define POSTACTION(M) | ||
| 2761 | #endif /* POSTACTION */ | ||
| 2762 | |||
| 2763 | #endif /* USE_LOCKS */ | ||
| 2764 | |||
| 2765 | /* | ||
| 2766 | CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses. | ||
| 2767 | USAGE_ERROR_ACTION is triggered on detected bad frees and | ||
| 2768 | reallocs. The argument p is an address that might have triggered the | ||
| 2769 | fault. It is ignored by the two predefined actions, but might be | ||
| 2770 | useful in custom actions that try to help diagnose errors. | ||
| 2771 | */ | ||
| 2772 | |||
| 2773 | #if PROCEED_ON_ERROR | ||
| 2774 | |||
| 2775 | /* A count of the number of corruption errors causing resets */ | ||
| 2776 | int malloc_corruption_error_count; | ||
| 2777 | |||
| 2778 | /* default corruption action */ | ||
| 2779 | static void reset_on_error(mstate m); | ||
| 2780 | |||
| 2781 | #define CORRUPTION_ERROR_ACTION(m) reset_on_error(m) | ||
| 2782 | #define USAGE_ERROR_ACTION(m, p) | ||
| 2783 | |||
| 2784 | #else /* PROCEED_ON_ERROR */ | ||
| 2785 | |||
| 2786 | #ifndef CORRUPTION_ERROR_ACTION | ||
| 2787 | #define CORRUPTION_ERROR_ACTION(m) ABORT | ||
| 2788 | #endif /* CORRUPTION_ERROR_ACTION */ | ||
| 2789 | |||
| 2790 | #ifndef USAGE_ERROR_ACTION | ||
| 2791 | #define USAGE_ERROR_ACTION(m,p) ABORT | ||
| 2792 | #endif /* USAGE_ERROR_ACTION */ | ||
| 2793 | |||
| 2794 | #endif /* PROCEED_ON_ERROR */ | ||
| 2795 | |||
| 2796 | |||
| 2797 | /* -------------------------- Debugging setup ---------------------------- */ | ||
| 2798 | |||
| 2799 | #if ! DEBUG | ||
| 2800 | |||
| 2801 | #define check_free_chunk(M,P) | ||
| 2802 | #define check_inuse_chunk(M,P) | ||
| 2803 | #define check_malloced_chunk(M,P,N) | ||
| 2804 | #define check_mmapped_chunk(M,P) | ||
| 2805 | #define check_malloc_state(M) | ||
| 2806 | #define check_top_chunk(M,P) | ||
| 2807 | |||
| 2808 | #else /* DEBUG */ | ||
| 2809 | #define check_free_chunk(M,P) do_check_free_chunk(M,P) | ||
| 2810 | #define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P) | ||
| 2811 | #define check_top_chunk(M,P) do_check_top_chunk(M,P) | ||
| 2812 | #define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N) | ||
| 2813 | #define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P) | ||
| 2814 | #define check_malloc_state(M) do_check_malloc_state(M) | ||
| 2815 | |||
| 2816 | static void do_check_any_chunk(mstate m, mchunkptr p); | ||
| 2817 | static void do_check_top_chunk(mstate m, mchunkptr p); | ||
| 2818 | static void do_check_mmapped_chunk(mstate m, mchunkptr p); | ||
| 2819 | static void do_check_inuse_chunk(mstate m, mchunkptr p); | ||
| 2820 | static void do_check_free_chunk(mstate m, mchunkptr p); | ||
| 2821 | static void do_check_malloced_chunk(mstate m, void* mem, size_t s); | ||
| 2822 | static void do_check_tree(mstate m, tchunkptr t); | ||
| 2823 | static void do_check_treebin(mstate m, bindex_t i); | ||
| 2824 | static void do_check_smallbin(mstate m, bindex_t i); | ||
| 2825 | static void do_check_malloc_state(mstate m); | ||
| 2826 | static int bin_find(mstate m, mchunkptr x); | ||
| 2827 | static size_t traverse_and_check(mstate m); | ||
| 2828 | #endif /* DEBUG */ | ||
| 2829 | |||
| 2830 | /* ---------------------------- Indexing Bins ---------------------------- */ | ||
| 2831 | |||
| 2832 | #define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) | ||
| 2833 | #define small_index(s) (bindex_t)((s) >> SMALLBIN_SHIFT) | ||
| 2834 | #define small_index2size(i) ((i) << SMALLBIN_SHIFT) | ||
| 2835 | #define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) | ||
| 2836 | |||
| 2837 | /* addressing by index. See above about smallbin repositioning */ | ||
| 2838 | #define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1]))) | ||
| 2839 | #define treebin_at(M,i) (&((M)->treebins[i])) | ||
| 2840 | |||
| 2841 | /* assign tree index for size S to variable I. Use x86 asm if possible */ | ||
| 2842 | #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | ||
| 2843 | #define compute_tree_index(S, I)\ | ||
| 2844 | {\ | ||
| 2845 | unsigned int X = S >> TREEBIN_SHIFT;\ | ||
| 2846 | if (X == 0)\ | ||
| 2847 | I = 0;\ | ||
| 2848 | else if (X > 0xFFFF)\ | ||
| 2849 | I = NTREEBINS-1;\ | ||
| 2850 | else {\ | ||
| 2851 | unsigned int K = (unsigned) sizeof(X)*__CHAR_BIT__ - 1 - (unsigned) __builtin_clz(X); \ | ||
| 2852 | I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ | ||
| 2853 | }\ | ||
| 2854 | } | ||
| 2855 | |||
| 2856 | #elif defined (__INTEL_COMPILER) | ||
| 2857 | #define compute_tree_index(S, I)\ | ||
| 2858 | {\ | ||
| 2859 | size_t X = S >> TREEBIN_SHIFT;\ | ||
| 2860 | if (X == 0)\ | ||
| 2861 | I = 0;\ | ||
| 2862 | else if (X > 0xFFFF)\ | ||
| 2863 | I = NTREEBINS-1;\ | ||
| 2864 | else {\ | ||
| 2865 | unsigned int K = _bit_scan_reverse (X); \ | ||
| 2866 | I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ | ||
| 2867 | }\ | ||
| 2868 | } | ||
| 2869 | |||
| 2870 | #elif defined(_MSC_VER) && _MSC_VER>=1300 | ||
| 2871 | #define compute_tree_index(S, I)\ | ||
| 2872 | {\ | ||
| 2873 | size_t X = S >> TREEBIN_SHIFT;\ | ||
| 2874 | if (X == 0)\ | ||
| 2875 | I = 0;\ | ||
| 2876 | else if (X > 0xFFFF)\ | ||
| 2877 | I = NTREEBINS-1;\ | ||
| 2878 | else {\ | ||
| 2879 | unsigned int K;\ | ||
| 2880 | _BitScanReverse((DWORD *) &K, (DWORD) X);\ | ||
| 2881 | I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ | ||
| 2882 | }\ | ||
| 2883 | } | ||
| 2884 | |||
| 2885 | #else /* GNUC */ | ||
| 2886 | #define compute_tree_index(S, I)\ | ||
| 2887 | {\ | ||
| 2888 | size_t X = S >> TREEBIN_SHIFT;\ | ||
| 2889 | if (X == 0)\ | ||
| 2890 | I = 0;\ | ||
| 2891 | else if (X > 0xFFFF)\ | ||
| 2892 | I = NTREEBINS-1;\ | ||
| 2893 | else {\ | ||
| 2894 | unsigned int Y = (unsigned int)X;\ | ||
| 2895 | unsigned int N = ((Y - 0x100) >> 16) & 8;\ | ||
| 2896 | unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\ | ||
| 2897 | N += K;\ | ||
| 2898 | N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\ | ||
| 2899 | K = 14 - N + ((Y <<= K) >> 15);\ | ||
| 2900 | I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\ | ||
| 2901 | }\ | ||
| 2902 | } | ||
| 2903 | #endif /* GNUC */ | ||
| 2904 | |||
| 2905 | /* Bit representing maximum resolved size in a treebin at i */ | ||
| 2906 | #define bit_for_tree_index(i) \ | ||
| 2907 | (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) | ||
| 2908 | |||
| 2909 | /* Shift placing maximum resolved bit in a treebin at i as sign bit */ | ||
| 2910 | #define leftshift_for_tree_index(i) \ | ||
| 2911 | ((i == NTREEBINS-1)? 0 : \ | ||
| 2912 | ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) | ||
| 2913 | |||
| 2914 | /* The size of the smallest chunk held in bin with index i */ | ||
| 2915 | #define minsize_for_tree_index(i) \ | ||
| 2916 | ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ | ||
| 2917 | (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) | ||
| 2918 | |||
| 2919 | |||
| 2920 | /* ------------------------ Operations on bin maps ----------------------- */ | ||
| 2921 | |||
| 2922 | /* bit corresponding to given index */ | ||
| 2923 | #define idx2bit(i) ((binmap_t)(1) << (i)) | ||
| 2924 | |||
| 2925 | /* Mark/Clear bits with given index */ | ||
| 2926 | #define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) | ||
| 2927 | #define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) | ||
| 2928 | #define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) | ||
| 2929 | |||
| 2930 | #define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) | ||
| 2931 | #define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) | ||
| 2932 | #define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) | ||
| 2933 | |||
| 2934 | /* isolate the least set bit of a bitmap */ | ||
| 2935 | #define least_bit(x) ((x) & -(x)) | ||
| 2936 | |||
| 2937 | /* mask with all bits to left of least bit of x on */ | ||
| 2938 | #define left_bits(x) ((x<<1) | -(x<<1)) | ||
| 2939 | |||
| 2940 | /* mask with all bits to left of or equal to least bit of x on */ | ||
| 2941 | #define same_or_left_bits(x) ((x) | -(x)) | ||
| 2942 | |||
| 2943 | /* index corresponding to given bit. Use x86 asm if possible */ | ||
| 2944 | |||
| 2945 | #if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) | ||
| 2946 | #define compute_bit2idx(X, I)\ | ||
| 2947 | {\ | ||
| 2948 | unsigned int J;\ | ||
| 2949 | J = __builtin_ctz(X); \ | ||
| 2950 | I = (bindex_t)J;\ | ||
| 2951 | } | ||
| 2952 | |||
| 2953 | #elif defined (__INTEL_COMPILER) | ||
| 2954 | #define compute_bit2idx(X, I)\ | ||
| 2955 | {\ | ||
| 2956 | unsigned int J;\ | ||
| 2957 | J = _bit_scan_forward (X); \ | ||
| 2958 | I = (bindex_t)J;\ | ||
| 2959 | } | ||
| 2960 | |||
| 2961 | #elif defined(_MSC_VER) && _MSC_VER>=1300 | ||
| 2962 | #define compute_bit2idx(X, I)\ | ||
| 2963 | {\ | ||
| 2964 | unsigned int J;\ | ||
| 2965 | _BitScanForward((DWORD *) &J, X);\ | ||
| 2966 | I = (bindex_t)J;\ | ||
| 2967 | } | ||
| 2968 | |||
| 2969 | #elif USE_BUILTIN_FFS | ||
| 2970 | #define compute_bit2idx(X, I) I = ffs(X)-1 | ||
| 2971 | |||
| 2972 | #else | ||
| 2973 | #define compute_bit2idx(X, I)\ | ||
| 2974 | {\ | ||
| 2975 | unsigned int Y = X - 1;\ | ||
| 2976 | unsigned int K = Y >> (16-4) & 16;\ | ||
| 2977 | unsigned int N = K; Y >>= K;\ | ||
| 2978 | N += K = Y >> (8-3) & 8; Y >>= K;\ | ||
| 2979 | N += K = Y >> (4-2) & 4; Y >>= K;\ | ||
| 2980 | N += K = Y >> (2-1) & 2; Y >>= K;\ | ||
| 2981 | N += K = Y >> (1-0) & 1; Y >>= K;\ | ||
| 2982 | I = (bindex_t)(N + Y);\ | ||
| 2983 | } | ||
| 2984 | #endif /* GNUC */ | ||
| 2985 | |||
| 2986 | |||
| 2987 | /* ----------------------- Runtime Check Support ------------------------- */ | ||
| 2988 | |||
| 2989 | /* | ||
| 2990 | For security, the main invariant is that malloc/free/etc never | ||
| 2991 | writes to a static address other than malloc_state, unless static | ||
| 2992 | malloc_state itself has been corrupted, which cannot occur via | ||
| 2993 | malloc (because of these checks). In essence this means that we | ||
| 2994 | believe all pointers, sizes, maps etc held in malloc_state, but | ||
| 2995 | check all of those linked or offsetted from other embedded data | ||
| 2996 | structures. These checks are interspersed with main code in a way | ||
| 2997 | that tends to minimize their run-time cost. | ||
| 2998 | |||
| 2999 | When FOOTERS is defined, in addition to range checking, we also | ||
| 3000 | verify footer fields of inuse chunks, which can be used guarantee | ||
| 3001 | that the mstate controlling malloc/free is intact. This is a | ||
| 3002 | streamlined version of the approach described by William Robertson | ||
| 3003 | et al in "Run-time Detection of Heap-based Overflows" LISA'03 | ||
| 3004 | http://www.usenix.org/events/lisa03/tech/robertson.html The footer | ||
| 3005 | of an inuse chunk holds the xor of its mstate and a random seed, | ||
| 3006 | that is checked upon calls to free() and realloc(). This is | ||
| 3007 | (probabalistically) unguessable from outside the program, but can be | ||
| 3008 | computed by any code successfully malloc'ing any chunk, so does not | ||
| 3009 | itself provide protection against code that has already broken | ||
| 3010 | security through some other means. Unlike Robertson et al, we | ||
| 3011 | always dynamically check addresses of all offset chunks (previous, | ||
| 3012 | next, etc). This turns out to be cheaper than relying on hashes. | ||
| 3013 | */ | ||
| 3014 | |||
| 3015 | #if !INSECURE | ||
| 3016 | /* Check if address a is at least as high as any from MORECORE or MMAP */ | ||
| 3017 | #define ok_address(M, a) ((char*)(a) >= (M)->least_addr) | ||
| 3018 | /* Check if address of next chunk n is higher than base chunk p */ | ||
| 3019 | #define ok_next(p, n) ((char*)(p) < (char*)(n)) | ||
| 3020 | /* Check if p has inuse status */ | ||
| 3021 | #define ok_inuse(p) is_inuse(p) | ||
| 3022 | /* Check if p has its pinuse bit on */ | ||
| 3023 | #define ok_pinuse(p) pinuse(p) | ||
| 3024 | |||
| 3025 | #else /* !INSECURE */ | ||
| 3026 | #define ok_address(M, a) (1) | ||
| 3027 | #define ok_next(b, n) (1) | ||
| 3028 | #define ok_inuse(p) (1) | ||
| 3029 | #define ok_pinuse(p) (1) | ||
| 3030 | #endif /* !INSECURE */ | ||
| 3031 | |||
| 3032 | #if (FOOTERS && !INSECURE) | ||
| 3033 | /* Check if (alleged) mstate m has expected magic field */ | ||
| 3034 | #define ok_magic(M) ((M)->magic == mparams.magic) | ||
| 3035 | #else /* (FOOTERS && !INSECURE) */ | ||
| 3036 | #define ok_magic(M) (1) | ||
| 3037 | #endif /* (FOOTERS && !INSECURE) */ | ||
| 3038 | |||
| 3039 | /* In gcc, use __builtin_expect to minimize impact of checks */ | ||
| 3040 | #if !INSECURE | ||
| 3041 | #if defined(__GNUC__) && __GNUC__ >= 3 | ||
| 3042 | #define RTCHECK(e) __builtin_expect(e, 1) | ||
| 3043 | #else /* GNUC */ | ||
| 3044 | #define RTCHECK(e) (e) | ||
| 3045 | #endif /* GNUC */ | ||
| 3046 | #else /* !INSECURE */ | ||
| 3047 | #define RTCHECK(e) (1) | ||
| 3048 | #endif /* !INSECURE */ | ||
| 3049 | |||
| 3050 | /* macros to set up inuse chunks with or without footers */ | ||
| 3051 | |||
| 3052 | #if !FOOTERS | ||
| 3053 | |||
| 3054 | #define mark_inuse_foot(M,p,s) | ||
| 3055 | |||
| 3056 | /* Macros for setting head/foot of non-mmapped chunks */ | ||
| 3057 | |||
| 3058 | /* Set cinuse bit and pinuse bit of next chunk */ | ||
| 3059 | #define set_inuse(M,p,s)\ | ||
| 3060 | ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ | ||
| 3061 | ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) | ||
| 3062 | |||
| 3063 | /* Set cinuse and pinuse of this chunk and pinuse of next chunk */ | ||
| 3064 | #define set_inuse_and_pinuse(M,p,s)\ | ||
| 3065 | ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ | ||
| 3066 | ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) | ||
| 3067 | |||
| 3068 | /* Set size, cinuse and pinuse bit of this chunk */ | ||
| 3069 | #define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ | ||
| 3070 | ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) | ||
| 3071 | |||
| 3072 | #else /* FOOTERS */ | ||
| 3073 | |||
| 3074 | /* Set foot of inuse chunk to be xor of mstate and seed */ | ||
| 3075 | #define mark_inuse_foot(M,p,s)\ | ||
| 3076 | (((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic)) | ||
| 3077 | |||
| 3078 | #define get_mstate_for(p)\ | ||
| 3079 | ((mstate)(((mchunkptr)((char*)(p) +\ | ||
| 3080 | (chunksize(p))))->prev_foot ^ mparams.magic)) | ||
| 3081 | |||
| 3082 | #define set_inuse(M,p,s)\ | ||
| 3083 | ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ | ||
| 3084 | (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \ | ||
| 3085 | mark_inuse_foot(M,p,s)) | ||
| 3086 | |||
| 3087 | #define set_inuse_and_pinuse(M,p,s)\ | ||
| 3088 | ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ | ||
| 3089 | (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\ | ||
| 3090 | mark_inuse_foot(M,p,s)) | ||
| 3091 | |||
| 3092 | #define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ | ||
| 3093 | ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ | ||
| 3094 | mark_inuse_foot(M, p, s)) | ||
| 3095 | |||
| 3096 | #endif /* !FOOTERS */ | ||
| 3097 | |||
| 3098 | /* ---------------------------- setting mparams -------------------------- */ | ||
| 3099 | |||
| 3100 | #if LOCK_AT_FORK | ||
| 3101 | static void pre_fork(void) { ACQUIRE_LOCK(&(gm)->mutex); } | ||
| 3102 | static void post_fork_parent(void) { RELEASE_LOCK(&(gm)->mutex); } | ||
| 3103 | static void post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); } | ||
| 3104 | #endif /* LOCK_AT_FORK */ | ||
| 3105 | |||
| 3106 | /* Initialize mparams */ | ||
| 3107 | static int init_mparams(void) { | ||
| 3108 | #ifdef NEED_GLOBAL_LOCK_INIT | ||
| 3109 | if (malloc_global_mutex_status <= 0) | ||
| 3110 | init_malloc_global_mutex(); | ||
| 3111 | #endif | ||
| 3112 | |||
| 3113 | ACQUIRE_MALLOC_GLOBAL_LOCK(); | ||
| 3114 | if (mparams.magic == 0) { | ||
| 3115 | size_t magic; | ||
| 3116 | size_t psize; | ||
| 3117 | size_t gsize; | ||
| 3118 | |||
| 3119 | #ifndef WIN32 | ||
| 3120 | psize = malloc_getpagesize; | ||
| 3121 | gsize = ((DEFAULT_GRANULARITY != 0)? DEFAULT_GRANULARITY : psize); | ||
| 3122 | #else /* WIN32 */ | ||
| 3123 | { | ||
| 3124 | SYSTEM_INFO system_info; | ||
| 3125 | GetSystemInfo(&system_info); | ||
| 3126 | psize = system_info.dwPageSize; | ||
| 3127 | gsize = ((DEFAULT_GRANULARITY != 0)? | ||
| 3128 | DEFAULT_GRANULARITY : system_info.dwAllocationGranularity); | ||
| 3129 | } | ||
| 3130 | #endif /* WIN32 */ | ||
| 3131 | |||
| 3132 | /* Sanity-check configuration: | ||
| 3133 | size_t must be unsigned and as wide as pointer type. | ||
| 3134 | ints must be at least 4 bytes. | ||
| 3135 | alignment must be at least 8. | ||
| 3136 | Alignment, min chunk size, and page size must all be powers of 2. | ||
| 3137 | */ | ||
| 3138 | if ((sizeof(size_t) != sizeof(char*)) || | ||
| 3139 | (MAX_SIZE_T < MIN_CHUNK_SIZE) || | ||
| 3140 | (sizeof(int) < 4) || | ||
| 3141 | (MALLOC_ALIGNMENT < (size_t)8U) || | ||
| 3142 | ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-SIZE_T_ONE)) != 0) || | ||
| 3143 | ((MCHUNK_SIZE & (MCHUNK_SIZE-SIZE_T_ONE)) != 0) || | ||
| 3144 | ((gsize & (gsize-SIZE_T_ONE)) != 0) || | ||
| 3145 | ((psize & (psize-SIZE_T_ONE)) != 0)) | ||
| 3146 | ABORT; | ||
| 3147 | mparams.granularity = gsize; | ||
| 3148 | mparams.page_size = psize; | ||
| 3149 | mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; | ||
| 3150 | mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; | ||
| 3151 | #if MORECORE_CONTIGUOUS | ||
| 3152 | mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT; | ||
| 3153 | #else /* MORECORE_CONTIGUOUS */ | ||
| 3154 | mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT|USE_NONCONTIGUOUS_BIT; | ||
| 3155 | #endif /* MORECORE_CONTIGUOUS */ | ||
| 3156 | |||
| 3157 | #if !ONLY_MSPACES | ||
| 3158 | /* Set up lock for main malloc area */ | ||
| 3159 | gm->mflags = mparams.default_mflags; | ||
| 3160 | (void)INITIAL_LOCK(&gm->mutex); | ||
| 3161 | #endif | ||
| 3162 | #if LOCK_AT_FORK | ||
| 3163 | pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child); | ||
| 3164 | #endif | ||
| 3165 | |||
| 3166 | { | ||
| 3167 | #if USE_DEV_RANDOM | ||
| 3168 | int fd; | ||
| 3169 | unsigned char buf[sizeof(size_t)]; | ||
| 3170 | /* Try to use /dev/urandom, else fall back on using time */ | ||
| 3171 | if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 && | ||
| 3172 | read(fd, buf, sizeof(buf)) == sizeof(buf)) { | ||
| 3173 | magic = *((size_t *) buf); | ||
| 3174 | close(fd); | ||
| 3175 | } | ||
| 3176 | else | ||
| 3177 | #endif /* USE_DEV_RANDOM */ | ||
| 3178 | #ifdef WIN32 | ||
| 3179 | magic = (size_t)(GetTickCount() ^ (size_t)0x55555555U); | ||
| 3180 | #elif defined(LACKS_TIME_H) | ||
| 3181 | magic = (size_t)&magic ^ (size_t)0x55555555U; | ||
| 3182 | #else | ||
| 3183 | magic = (size_t)(time(0) ^ (size_t)0x55555555U); | ||
| 3184 | #endif | ||
| 3185 | magic |= (size_t)8U; /* ensure nonzero */ | ||
| 3186 | magic &= ~(size_t)7U; /* improve chances of fault for bad values */ | ||
| 3187 | /* Until memory modes commonly available, use volatile-write */ | ||
| 3188 | (*(volatile size_t *)(&(mparams.magic))) = magic; | ||
| 3189 | } | ||
| 3190 | } | ||
| 3191 | |||
| 3192 | RELEASE_MALLOC_GLOBAL_LOCK(); | ||
| 3193 | return 1; | ||
| 3194 | } | ||
| 3195 | |||
| 3196 | /* support for mallopt */ | ||
| 3197 | static int change_mparam(int param_number, int value) { | ||
| 3198 | size_t val; | ||
| 3199 | ensure_initialization(); | ||
| 3200 | val = (value == -1)? MAX_SIZE_T : (size_t)value; | ||
| 3201 | switch(param_number) { | ||
| 3202 | case M_TRIM_THRESHOLD: | ||
| 3203 | mparams.trim_threshold = val; | ||
| 3204 | return 1; | ||
| 3205 | case M_GRANULARITY: | ||
| 3206 | if (val >= mparams.page_size && ((val & (val-1)) == 0)) { | ||
| 3207 | mparams.granularity = val; | ||
| 3208 | return 1; | ||
| 3209 | } | ||
| 3210 | else | ||
| 3211 | return 0; | ||
| 3212 | case M_MMAP_THRESHOLD: | ||
| 3213 | mparams.mmap_threshold = val; | ||
| 3214 | return 1; | ||
| 3215 | default: | ||
| 3216 | return 0; | ||
| 3217 | } | ||
| 3218 | } | ||
| 3219 | |||
| 3220 | #if DEBUG | ||
| 3221 | /* ------------------------- Debugging Support --------------------------- */ | ||
| 3222 | |||
| 3223 | /* Check properties of any chunk, whether free, inuse, mmapped etc */ | ||
| 3224 | static void do_check_any_chunk(mstate m, mchunkptr p) { | ||
| 3225 | assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); | ||
| 3226 | assert(ok_address(m, p)); | ||
| 3227 | } | ||
| 3228 | |||
| 3229 | /* Check properties of top chunk */ | ||
| 3230 | static void do_check_top_chunk(mstate m, mchunkptr p) { | ||
| 3231 | msegmentptr sp = segment_holding(m, (char*)p); | ||
| 3232 | size_t sz = p->head & ~INUSE_BITS; /* third-lowest bit can be set! */ | ||
| 3233 | assert(sp != 0); | ||
| 3234 | assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); | ||
| 3235 | assert(ok_address(m, p)); | ||
| 3236 | assert(sz == m->topsize); | ||
| 3237 | assert(sz > 0); | ||
| 3238 | assert(sz == ((sp->base + sp->size) - (char*)p) - TOP_FOOT_SIZE); | ||
| 3239 | assert(pinuse(p)); | ||
| 3240 | assert(!pinuse(chunk_plus_offset(p, sz))); | ||
| 3241 | } | ||
| 3242 | |||
| 3243 | /* Check properties of (inuse) mmapped chunks */ | ||
| 3244 | static void do_check_mmapped_chunk(mstate m, mchunkptr p) { | ||
| 3245 | size_t sz = chunksize(p); | ||
| 3246 | size_t len = (sz + (p->prev_foot) + MMAP_FOOT_PAD); | ||
| 3247 | assert(is_mmapped(p)); | ||
| 3248 | assert(use_mmap(m)); | ||
| 3249 | assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); | ||
| 3250 | assert(ok_address(m, p)); | ||
| 3251 | assert(!is_small(sz)); | ||
| 3252 | assert((len & (mparams.page_size-SIZE_T_ONE)) == 0); | ||
| 3253 | assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD); | ||
| 3254 | assert(chunk_plus_offset(p, sz+SIZE_T_SIZE)->head == 0); | ||
| 3255 | } | ||
| 3256 | |||
| 3257 | /* Check properties of inuse chunks */ | ||
| 3258 | static void do_check_inuse_chunk(mstate m, mchunkptr p) { | ||
| 3259 | do_check_any_chunk(m, p); | ||
| 3260 | assert(is_inuse(p)); | ||
| 3261 | assert(next_pinuse(p)); | ||
| 3262 | /* If not pinuse and not mmapped, previous chunk has OK offset */ | ||
| 3263 | assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p); | ||
| 3264 | if (is_mmapped(p)) | ||
| 3265 | do_check_mmapped_chunk(m, p); | ||
| 3266 | } | ||
| 3267 | |||
| 3268 | /* Check properties of free chunks */ | ||
| 3269 | static void do_check_free_chunk(mstate m, mchunkptr p) { | ||
| 3270 | size_t sz = chunksize(p); | ||
| 3271 | mchunkptr next = chunk_plus_offset(p, sz); | ||
| 3272 | do_check_any_chunk(m, p); | ||
| 3273 | assert(!is_inuse(p)); | ||
| 3274 | assert(!next_pinuse(p)); | ||
| 3275 | assert (!is_mmapped(p)); | ||
| 3276 | if (p != m->dv && p != m->top) { | ||
| 3277 | if (sz >= MIN_CHUNK_SIZE) { | ||
| 3278 | assert((sz & CHUNK_ALIGN_MASK) == 0); | ||
| 3279 | assert(is_aligned(chunk2mem(p))); | ||
| 3280 | assert(next->prev_foot == sz); | ||
| 3281 | assert(pinuse(p)); | ||
| 3282 | assert (next == m->top || is_inuse(next)); | ||
| 3283 | assert(p->fd->bk == p); | ||
| 3284 | assert(p->bk->fd == p); | ||
| 3285 | } | ||
| 3286 | else /* markers are always of size SIZE_T_SIZE */ | ||
| 3287 | assert(sz == SIZE_T_SIZE); | ||
| 3288 | } | ||
| 3289 | } | ||
| 3290 | |||
| 3291 | /* Check properties of malloced chunks at the point they are malloced */ | ||
| 3292 | static void do_check_malloced_chunk(mstate m, void* mem, size_t s) { | ||
| 3293 | if (mem != 0) { | ||
| 3294 | mchunkptr p = mem2chunk(mem); | ||
| 3295 | size_t sz = p->head & ~INUSE_BITS; | ||
| 3296 | do_check_inuse_chunk(m, p); | ||
| 3297 | assert((sz & CHUNK_ALIGN_MASK) == 0); | ||
| 3298 | assert(sz >= MIN_CHUNK_SIZE); | ||
| 3299 | assert(sz >= s); | ||
| 3300 | /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ | ||
| 3301 | assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE)); | ||
| 3302 | } | ||
| 3303 | } | ||
| 3304 | |||
| 3305 | /* Check a tree and its subtrees. */ | ||
| 3306 | static void do_check_tree(mstate m, tchunkptr t) { | ||
| 3307 | tchunkptr head = 0; | ||
| 3308 | tchunkptr u = t; | ||
| 3309 | bindex_t tindex = t->index; | ||
| 3310 | size_t tsize = chunksize(t); | ||
| 3311 | bindex_t idx; | ||
| 3312 | compute_tree_index(tsize, idx); | ||
| 3313 | assert(tindex == idx); | ||
| 3314 | assert(tsize >= MIN_LARGE_SIZE); | ||
| 3315 | assert(tsize >= minsize_for_tree_index(idx)); | ||
| 3316 | assert((idx == NTREEBINS-1) || (tsize < minsize_for_tree_index((idx+1)))); | ||
| 3317 | |||
| 3318 | do { /* traverse through chain of same-sized nodes */ | ||
| 3319 | do_check_any_chunk(m, ((mchunkptr)u)); | ||
| 3320 | assert(u->index == tindex); | ||
| 3321 | assert(chunksize(u) == tsize); | ||
| 3322 | assert(!is_inuse(u)); | ||
| 3323 | assert(!next_pinuse(u)); | ||
| 3324 | assert(u->fd->bk == u); | ||
| 3325 | assert(u->bk->fd == u); | ||
| 3326 | if (u->parent == 0) { | ||
| 3327 | assert(u->child[0] == 0); | ||
| 3328 | assert(u->child[1] == 0); | ||
| 3329 | } | ||
| 3330 | else { | ||
| 3331 | assert(head == 0); /* only one node on chain has parent */ | ||
| 3332 | head = u; | ||
| 3333 | assert(u->parent != u); | ||
| 3334 | assert (u->parent->child[0] == u || | ||
| 3335 | u->parent->child[1] == u || | ||
| 3336 | *((tbinptr*)(u->parent)) == u); | ||
| 3337 | if (u->child[0] != 0) { | ||
| 3338 | assert(u->child[0]->parent == u); | ||
| 3339 | assert(u->child[0] != u); | ||
| 3340 | do_check_tree(m, u->child[0]); | ||
| 3341 | } | ||
| 3342 | if (u->child[1] != 0) { | ||
| 3343 | assert(u->child[1]->parent == u); | ||
| 3344 | assert(u->child[1] != u); | ||
| 3345 | do_check_tree(m, u->child[1]); | ||
| 3346 | } | ||
| 3347 | if (u->child[0] != 0 && u->child[1] != 0) { | ||
| 3348 | assert(chunksize(u->child[0]) < chunksize(u->child[1])); | ||
| 3349 | } | ||
| 3350 | } | ||
| 3351 | u = u->fd; | ||
| 3352 | } while (u != t); | ||
| 3353 | assert(head != 0); | ||
| 3354 | } | ||
| 3355 | |||
| 3356 | /* Check all the chunks in a treebin. */ | ||
| 3357 | static void do_check_treebin(mstate m, bindex_t i) { | ||
| 3358 | tbinptr* tb = treebin_at(m, i); | ||
| 3359 | tchunkptr t = *tb; | ||
| 3360 | int empty = (m->treemap & (1U << i)) == 0; | ||
| 3361 | if (t == 0) | ||
| 3362 | assert(empty); | ||
| 3363 | if (!empty) | ||
| 3364 | do_check_tree(m, t); | ||
| 3365 | } | ||
| 3366 | |||
| 3367 | /* Check all the chunks in a smallbin. */ | ||
| 3368 | static void do_check_smallbin(mstate m, bindex_t i) { | ||
| 3369 | sbinptr b = smallbin_at(m, i); | ||
| 3370 | mchunkptr p = b->bk; | ||
| 3371 | unsigned int empty = (m->smallmap & (1U << i)) == 0; | ||
| 3372 | if (p == b) | ||
| 3373 | assert(empty); | ||
| 3374 | if (!empty) { | ||
| 3375 | for (; p != b; p = p->bk) { | ||
| 3376 | size_t size = chunksize(p); | ||
| 3377 | mchunkptr q; | ||
| 3378 | /* each chunk claims to be free */ | ||
| 3379 | do_check_free_chunk(m, p); | ||
| 3380 | /* chunk belongs in bin */ | ||
| 3381 | assert(small_index(size) == i); | ||
| 3382 | assert(p->bk == b || chunksize(p->bk) == chunksize(p)); | ||
| 3383 | /* chunk is followed by an inuse chunk */ | ||
| 3384 | q = next_chunk(p); | ||
| 3385 | if (q->head != FENCEPOST_HEAD) | ||
| 3386 | do_check_inuse_chunk(m, q); | ||
| 3387 | } | ||
| 3388 | } | ||
| 3389 | } | ||
| 3390 | |||
| 3391 | /* Find x in a bin. Used in other check functions. */ | ||
| 3392 | static int bin_find(mstate m, mchunkptr x) { | ||
| 3393 | size_t size = chunksize(x); | ||
| 3394 | if (is_small(size)) { | ||
| 3395 | bindex_t sidx = small_index(size); | ||
| 3396 | sbinptr b = smallbin_at(m, sidx); | ||
| 3397 | if (smallmap_is_marked(m, sidx)) { | ||
| 3398 | mchunkptr p = b; | ||
| 3399 | do { | ||
| 3400 | if (p == x) | ||
| 3401 | return 1; | ||
| 3402 | } while ((p = p->fd) != b); | ||
| 3403 | } | ||
| 3404 | } | ||
| 3405 | else { | ||
| 3406 | bindex_t tidx; | ||
| 3407 | compute_tree_index(size, tidx); | ||
| 3408 | if (treemap_is_marked(m, tidx)) { | ||
| 3409 | tchunkptr t = *treebin_at(m, tidx); | ||
| 3410 | size_t sizebits = size << leftshift_for_tree_index(tidx); | ||
| 3411 | while (t != 0 && chunksize(t) != size) { | ||
| 3412 | t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; | ||
| 3413 | sizebits <<= 1; | ||
| 3414 | } | ||
| 3415 | if (t != 0) { | ||
| 3416 | tchunkptr u = t; | ||
| 3417 | do { | ||
| 3418 | if (u == (tchunkptr)x) | ||
| 3419 | return 1; | ||
| 3420 | } while ((u = u->fd) != t); | ||
| 3421 | } | ||
| 3422 | } | ||
| 3423 | } | ||
| 3424 | return 0; | ||
| 3425 | } | ||
| 3426 | |||
| 3427 | /* Traverse each chunk and check it; return total */ | ||
| 3428 | static size_t traverse_and_check(mstate m) { | ||
| 3429 | size_t sum = 0; | ||
| 3430 | if (is_initialized(m)) { | ||
| 3431 | msegmentptr s = &m->seg; | ||
| 3432 | sum += m->topsize + TOP_FOOT_SIZE; | ||
| 3433 | while (s != 0) { | ||
| 3434 | mchunkptr q = align_as_chunk(s->base); | ||
| 3435 | mchunkptr lastq = 0; | ||
| 3436 | assert(pinuse(q)); | ||
| 3437 | while (segment_holds(s, q) && | ||
| 3438 | q != m->top && q->head != FENCEPOST_HEAD) { | ||
| 3439 | sum += chunksize(q); | ||
| 3440 | if (is_inuse(q)) { | ||
| 3441 | assert(!bin_find(m, q)); | ||
| 3442 | do_check_inuse_chunk(m, q); | ||
| 3443 | } | ||
| 3444 | else { | ||
| 3445 | assert(q == m->dv || bin_find(m, q)); | ||
| 3446 | assert(lastq == 0 || is_inuse(lastq)); /* Not 2 consecutive free */ | ||
| 3447 | do_check_free_chunk(m, q); | ||
| 3448 | } | ||
| 3449 | lastq = q; | ||
| 3450 | q = next_chunk(q); | ||
| 3451 | } | ||
| 3452 | s = s->next; | ||
| 3453 | } | ||
| 3454 | } | ||
| 3455 | return sum; | ||
| 3456 | } | ||
| 3457 | |||
| 3458 | |||
| 3459 | /* Check all properties of malloc_state. */ | ||
| 3460 | static void do_check_malloc_state(mstate m) { | ||
| 3461 | bindex_t i; | ||
| 3462 | size_t total; | ||
| 3463 | /* check bins */ | ||
| 3464 | for (i = 0; i < NSMALLBINS; ++i) | ||
| 3465 | do_check_smallbin(m, i); | ||
| 3466 | for (i = 0; i < NTREEBINS; ++i) | ||
| 3467 | do_check_treebin(m, i); | ||
| 3468 | |||
| 3469 | if (m->dvsize != 0) { /* check dv chunk */ | ||
| 3470 | do_check_any_chunk(m, m->dv); | ||
| 3471 | assert(m->dvsize == chunksize(m->dv)); | ||
| 3472 | assert(m->dvsize >= MIN_CHUNK_SIZE); | ||
| 3473 | assert(bin_find(m, m->dv) == 0); | ||
| 3474 | } | ||
| 3475 | |||
| 3476 | if (m->top != 0) { /* check top chunk */ | ||
| 3477 | do_check_top_chunk(m, m->top); | ||
| 3478 | /*assert(m->topsize == chunksize(m->top)); redundant */ | ||
| 3479 | assert(m->topsize > 0); | ||
| 3480 | assert(bin_find(m, m->top) == 0); | ||
| 3481 | } | ||
| 3482 | |||
| 3483 | total = traverse_and_check(m); | ||
| 3484 | assert(total <= m->footprint); | ||
| 3485 | assert(m->footprint <= m->max_footprint); | ||
| 3486 | } | ||
| 3487 | #endif /* DEBUG */ | ||
| 3488 | |||
| 3489 | /* ----------------------------- statistics ------------------------------ */ | ||
| 3490 | |||
| 3491 | #if !NO_MALLINFO | ||
| 3492 | static struct mallinfo internal_mallinfo(mstate m) { | ||
| 3493 | struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; | ||
| 3494 | ensure_initialization(); | ||
| 3495 | if (!PREACTION(m)) { | ||
| 3496 | check_malloc_state(m); | ||
| 3497 | if (is_initialized(m)) { | ||
| 3498 | size_t nfree = SIZE_T_ONE; /* top always free */ | ||
| 3499 | size_t mfree = m->topsize + TOP_FOOT_SIZE; | ||
| 3500 | size_t sum = mfree; | ||
| 3501 | msegmentptr s = &m->seg; | ||
| 3502 | while (s != 0) { | ||
| 3503 | mchunkptr q = align_as_chunk(s->base); | ||
| 3504 | while (segment_holds(s, q) && | ||
| 3505 | q != m->top && q->head != FENCEPOST_HEAD) { | ||
| 3506 | size_t sz = chunksize(q); | ||
| 3507 | sum += sz; | ||
| 3508 | if (!is_inuse(q)) { | ||
| 3509 | mfree += sz; | ||
| 3510 | ++nfree; | ||
| 3511 | } | ||
| 3512 | q = next_chunk(q); | ||
| 3513 | } | ||
| 3514 | s = s->next; | ||
| 3515 | } | ||
| 3516 | |||
| 3517 | nm.arena = sum; | ||
| 3518 | nm.ordblks = nfree; | ||
| 3519 | nm.hblkhd = m->footprint - sum; | ||
| 3520 | nm.usmblks = m->max_footprint; | ||
| 3521 | nm.uordblks = m->footprint - mfree; | ||
| 3522 | nm.fordblks = mfree; | ||
| 3523 | nm.keepcost = m->topsize; | ||
| 3524 | } | ||
| 3525 | |||
| 3526 | POSTACTION(m); | ||
| 3527 | } | ||
| 3528 | return nm; | ||
| 3529 | } | ||
| 3530 | #endif /* !NO_MALLINFO */ | ||
| 3531 | |||
| 3532 | #if !NO_MALLOC_STATS | ||
| 3533 | static void internal_malloc_stats(mstate m) { | ||
| 3534 | ensure_initialization(); | ||
| 3535 | if (!PREACTION(m)) { | ||
| 3536 | size_t maxfp = 0; | ||
| 3537 | size_t fp = 0; | ||
| 3538 | size_t used = 0; | ||
| 3539 | check_malloc_state(m); | ||
| 3540 | if (is_initialized(m)) { | ||
| 3541 | msegmentptr s = &m->seg; | ||
| 3542 | maxfp = m->max_footprint; | ||
| 3543 | fp = m->footprint; | ||
| 3544 | used = fp - (m->topsize + TOP_FOOT_SIZE); | ||
| 3545 | |||
| 3546 | while (s != 0) { | ||
| 3547 | mchunkptr q = align_as_chunk(s->base); | ||
| 3548 | while (segment_holds(s, q) && | ||
| 3549 | q != m->top && q->head != FENCEPOST_HEAD) { | ||
| 3550 | if (!is_inuse(q)) | ||
| 3551 | used -= chunksize(q); | ||
| 3552 | q = next_chunk(q); | ||
| 3553 | } | ||
| 3554 | s = s->next; | ||
| 3555 | } | ||
| 3556 | } | ||
| 3557 | POSTACTION(m); /* drop lock */ | ||
| 3558 | fprintf(stderr, "max system bytes = %10lu\n", (unsigned long)(maxfp)); | ||
| 3559 | fprintf(stderr, "system bytes = %10lu\n", (unsigned long)(fp)); | ||
| 3560 | fprintf(stderr, "in use bytes = %10lu\n", (unsigned long)(used)); | ||
| 3561 | } | ||
| 3562 | } | ||
| 3563 | #endif /* NO_MALLOC_STATS */ | ||
| 3564 | |||
| 3565 | /* ----------------------- Operations on smallbins ----------------------- */ | ||
| 3566 | |||
| 3567 | /* | ||
| 3568 | Various forms of linking and unlinking are defined as macros. Even | ||
| 3569 | the ones for trees, which are very long but have very short typical | ||
| 3570 | paths. This is ugly but reduces reliance on inlining support of | ||
| 3571 | compilers. | ||
| 3572 | */ | ||
| 3573 | |||
| 3574 | /* Link a free chunk into a smallbin */ | ||
| 3575 | #define insert_small_chunk(M, P, S) {\ | ||
| 3576 | bindex_t I = small_index(S);\ | ||
| 3577 | mchunkptr B = smallbin_at(M, I);\ | ||
| 3578 | mchunkptr F = B;\ | ||
| 3579 | assert(S >= MIN_CHUNK_SIZE);\ | ||
| 3580 | if (!smallmap_is_marked(M, I))\ | ||
| 3581 | mark_smallmap(M, I);\ | ||
| 3582 | else if (RTCHECK(ok_address(M, B->fd)))\ | ||
| 3583 | F = B->fd;\ | ||
| 3584 | else {\ | ||
| 3585 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3586 | }\ | ||
| 3587 | B->fd = P;\ | ||
| 3588 | F->bk = P;\ | ||
| 3589 | P->fd = F;\ | ||
| 3590 | P->bk = B;\ | ||
| 3591 | } | ||
| 3592 | |||
| 3593 | /* Unlink a chunk from a smallbin */ | ||
| 3594 | #define unlink_small_chunk(M, P, S) {\ | ||
| 3595 | mchunkptr F = P->fd;\ | ||
| 3596 | mchunkptr B = P->bk;\ | ||
| 3597 | bindex_t I = small_index(S);\ | ||
| 3598 | assert(P != B);\ | ||
| 3599 | assert(P != F);\ | ||
| 3600 | assert(chunksize(P) == small_index2size(I));\ | ||
| 3601 | if (RTCHECK(F == smallbin_at(M,I) || (ok_address(M, F) && F->bk == P))) { \ | ||
| 3602 | if (B == F) {\ | ||
| 3603 | clear_smallmap(M, I);\ | ||
| 3604 | }\ | ||
| 3605 | else if (RTCHECK(B == smallbin_at(M,I) ||\ | ||
| 3606 | (ok_address(M, B) && B->fd == P))) {\ | ||
| 3607 | F->bk = B;\ | ||
| 3608 | B->fd = F;\ | ||
| 3609 | }\ | ||
| 3610 | else {\ | ||
| 3611 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3612 | }\ | ||
| 3613 | }\ | ||
| 3614 | else {\ | ||
| 3615 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3616 | }\ | ||
| 3617 | } | ||
| 3618 | |||
| 3619 | /* Unlink the first chunk from a smallbin */ | ||
| 3620 | #define unlink_first_small_chunk(M, B, P, I) {\ | ||
| 3621 | mchunkptr F = P->fd;\ | ||
| 3622 | assert(P != B);\ | ||
| 3623 | assert(P != F);\ | ||
| 3624 | assert(chunksize(P) == small_index2size(I));\ | ||
| 3625 | if (B == F) {\ | ||
| 3626 | clear_smallmap(M, I);\ | ||
| 3627 | }\ | ||
| 3628 | else if (RTCHECK(ok_address(M, F) && F->bk == P)) {\ | ||
| 3629 | F->bk = B;\ | ||
| 3630 | B->fd = F;\ | ||
| 3631 | }\ | ||
| 3632 | else {\ | ||
| 3633 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3634 | }\ | ||
| 3635 | } | ||
| 3636 | |||
| 3637 | /* Replace dv node, binning the old one */ | ||
| 3638 | /* Used only when dvsize known to be small */ | ||
| 3639 | #define replace_dv(M, P, S) {\ | ||
| 3640 | size_t DVS = M->dvsize;\ | ||
| 3641 | assert(is_small(DVS));\ | ||
| 3642 | if (DVS != 0) {\ | ||
| 3643 | mchunkptr DV = M->dv;\ | ||
| 3644 | insert_small_chunk(M, DV, DVS);\ | ||
| 3645 | }\ | ||
| 3646 | M->dvsize = S;\ | ||
| 3647 | M->dv = P;\ | ||
| 3648 | } | ||
| 3649 | |||
| 3650 | /* ------------------------- Operations on trees ------------------------- */ | ||
| 3651 | |||
| 3652 | /* Insert chunk into tree */ | ||
| 3653 | #define insert_large_chunk(M, X, S) {\ | ||
| 3654 | tbinptr* H;\ | ||
| 3655 | bindex_t I;\ | ||
| 3656 | compute_tree_index(S, I);\ | ||
| 3657 | H = treebin_at(M, I);\ | ||
| 3658 | X->index = I;\ | ||
| 3659 | X->child[0] = X->child[1] = 0;\ | ||
| 3660 | if (!treemap_is_marked(M, I)) {\ | ||
| 3661 | mark_treemap(M, I);\ | ||
| 3662 | *H = X;\ | ||
| 3663 | X->parent = (tchunkptr)H;\ | ||
| 3664 | X->fd = X->bk = X;\ | ||
| 3665 | }\ | ||
| 3666 | else {\ | ||
| 3667 | tchunkptr T = *H;\ | ||
| 3668 | size_t K = S << leftshift_for_tree_index(I);\ | ||
| 3669 | for (;;) {\ | ||
| 3670 | if (chunksize(T) != S) {\ | ||
| 3671 | tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ | ||
| 3672 | K <<= 1;\ | ||
| 3673 | if (*C != 0)\ | ||
| 3674 | T = *C;\ | ||
| 3675 | else if (RTCHECK(ok_address(M, C))) {\ | ||
| 3676 | *C = X;\ | ||
| 3677 | X->parent = T;\ | ||
| 3678 | X->fd = X->bk = X;\ | ||
| 3679 | break;\ | ||
| 3680 | }\ | ||
| 3681 | else {\ | ||
| 3682 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3683 | break;\ | ||
| 3684 | }\ | ||
| 3685 | }\ | ||
| 3686 | else {\ | ||
| 3687 | tchunkptr F = T->fd;\ | ||
| 3688 | if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\ | ||
| 3689 | T->fd = F->bk = X;\ | ||
| 3690 | X->fd = F;\ | ||
| 3691 | X->bk = T;\ | ||
| 3692 | X->parent = 0;\ | ||
| 3693 | break;\ | ||
| 3694 | }\ | ||
| 3695 | else {\ | ||
| 3696 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3697 | break;\ | ||
| 3698 | }\ | ||
| 3699 | }\ | ||
| 3700 | }\ | ||
| 3701 | }\ | ||
| 3702 | } | ||
| 3703 | |||
| 3704 | /* | ||
| 3705 | Unlink steps: | ||
| 3706 | |||
| 3707 | 1. If x is a chained node, unlink it from its same-sized fd/bk links | ||
| 3708 | and choose its bk node as its replacement. | ||
| 3709 | 2. If x was the last node of its size, but not a leaf node, it must | ||
| 3710 | be replaced with a leaf node (not merely one with an open left or | ||
| 3711 | right), to make sure that lefts and rights of descendents | ||
| 3712 | correspond properly to bit masks. We use the rightmost descendent | ||
| 3713 | of x. We could use any other leaf, but this is easy to locate and | ||
| 3714 | tends to counteract removal of leftmosts elsewhere, and so keeps | ||
| 3715 | paths shorter than minimally guaranteed. This doesn't loop much | ||
| 3716 | because on average a node in a tree is near the bottom. | ||
| 3717 | 3. If x is the base of a chain (i.e., has parent links) relink | ||
| 3718 | x's parent and children to x's replacement (or null if none). | ||
| 3719 | */ | ||
| 3720 | |||
| 3721 | #define unlink_large_chunk(M, X) {\ | ||
| 3722 | tchunkptr XP = X->parent;\ | ||
| 3723 | tchunkptr R;\ | ||
| 3724 | if (X->bk != X) {\ | ||
| 3725 | tchunkptr F = X->fd;\ | ||
| 3726 | R = X->bk;\ | ||
| 3727 | if (RTCHECK(ok_address(M, F) && F->bk == X && R->fd == X)) {\ | ||
| 3728 | F->bk = R;\ | ||
| 3729 | R->fd = F;\ | ||
| 3730 | }\ | ||
| 3731 | else {\ | ||
| 3732 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3733 | }\ | ||
| 3734 | }\ | ||
| 3735 | else {\ | ||
| 3736 | tchunkptr* RP;\ | ||
| 3737 | if (((R = *(RP = &(X->child[1]))) != 0) ||\ | ||
| 3738 | ((R = *(RP = &(X->child[0]))) != 0)) {\ | ||
| 3739 | tchunkptr* CP;\ | ||
| 3740 | while ((*(CP = &(R->child[1])) != 0) ||\ | ||
| 3741 | (*(CP = &(R->child[0])) != 0)) {\ | ||
| 3742 | R = *(RP = CP);\ | ||
| 3743 | }\ | ||
| 3744 | if (RTCHECK(ok_address(M, RP)))\ | ||
| 3745 | *RP = 0;\ | ||
| 3746 | else {\ | ||
| 3747 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3748 | }\ | ||
| 3749 | }\ | ||
| 3750 | }\ | ||
| 3751 | if (XP != 0) {\ | ||
| 3752 | tbinptr* H = treebin_at(M, X->index);\ | ||
| 3753 | if (X == *H) {\ | ||
| 3754 | if ((*H = R) == 0) \ | ||
| 3755 | clear_treemap(M, X->index);\ | ||
| 3756 | }\ | ||
| 3757 | else if (RTCHECK(ok_address(M, XP))) {\ | ||
| 3758 | if (XP->child[0] == X) \ | ||
| 3759 | XP->child[0] = R;\ | ||
| 3760 | else \ | ||
| 3761 | XP->child[1] = R;\ | ||
| 3762 | }\ | ||
| 3763 | else\ | ||
| 3764 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3765 | if (R != 0) {\ | ||
| 3766 | if (RTCHECK(ok_address(M, R))) {\ | ||
| 3767 | tchunkptr C0, C1;\ | ||
| 3768 | R->parent = XP;\ | ||
| 3769 | if ((C0 = X->child[0]) != 0) {\ | ||
| 3770 | if (RTCHECK(ok_address(M, C0))) {\ | ||
| 3771 | R->child[0] = C0;\ | ||
| 3772 | C0->parent = R;\ | ||
| 3773 | }\ | ||
| 3774 | else\ | ||
| 3775 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3776 | }\ | ||
| 3777 | if ((C1 = X->child[1]) != 0) {\ | ||
| 3778 | if (RTCHECK(ok_address(M, C1))) {\ | ||
| 3779 | R->child[1] = C1;\ | ||
| 3780 | C1->parent = R;\ | ||
| 3781 | }\ | ||
| 3782 | else\ | ||
| 3783 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3784 | }\ | ||
| 3785 | }\ | ||
| 3786 | else\ | ||
| 3787 | CORRUPTION_ERROR_ACTION(M);\ | ||
| 3788 | }\ | ||
| 3789 | }\ | ||
| 3790 | } | ||
| 3791 | |||
| 3792 | /* Relays to large vs small bin operations */ | ||
| 3793 | |||
| 3794 | #define insert_chunk(M, P, S)\ | ||
| 3795 | if (is_small(S)) insert_small_chunk(M, P, S)\ | ||
| 3796 | else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } | ||
| 3797 | |||
| 3798 | #define unlink_chunk(M, P, S)\ | ||
| 3799 | if (is_small(S)) unlink_small_chunk(M, P, S)\ | ||
| 3800 | else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } | ||
| 3801 | |||
| 3802 | |||
| 3803 | /* Relays to internal calls to malloc/free from realloc, memalign etc */ | ||
| 3804 | |||
| 3805 | #if ONLY_MSPACES | ||
| 3806 | #define internal_malloc(m, b) mspace_malloc(m, b) | ||
| 3807 | #define internal_free(m, mem) mspace_free(m,mem); | ||
| 3808 | #else /* ONLY_MSPACES */ | ||
| 3809 | #if MSPACES | ||
| 3810 | #define internal_malloc(m, b)\ | ||
| 3811 | ((m == gm)? dlmalloc(b) : mspace_malloc(m, b)) | ||
| 3812 | #define internal_free(m, mem)\ | ||
| 3813 | if (m == gm) dlfree(mem); else mspace_free(m,mem); | ||
| 3814 | #else /* MSPACES */ | ||
| 3815 | #define internal_malloc(m, b) dlmalloc(b) | ||
| 3816 | #define internal_free(m, mem) dlfree(mem) | ||
| 3817 | #endif /* MSPACES */ | ||
| 3818 | #endif /* ONLY_MSPACES */ | ||
| 3819 | |||
| 3820 | /* ----------------------- Direct-mmapping chunks ----------------------- */ | ||
| 3821 | |||
| 3822 | /* | ||
| 3823 | Directly mmapped chunks are set up with an offset to the start of | ||
| 3824 | the mmapped region stored in the prev_foot field of the chunk. This | ||
| 3825 | allows reconstruction of the required argument to MUNMAP when freed, | ||
| 3826 | and also allows adjustment of the returned chunk to meet alignment | ||
| 3827 | requirements (especially in memalign). | ||
| 3828 | */ | ||
| 3829 | |||
| 3830 | /* Malloc using mmap */ | ||
| 3831 | static void* mmap_alloc(mstate m, size_t nb) { | ||
| 3832 | size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); | ||
| 3833 | if (m->footprint_limit != 0) { | ||
| 3834 | size_t fp = m->footprint + mmsize; | ||
| 3835 | if (fp <= m->footprint || fp > m->footprint_limit) | ||
| 3836 | return 0; | ||
| 3837 | } | ||
| 3838 | if (mmsize > nb) { /* Check for wrap around 0 */ | ||
| 3839 | char* mm = (char*)(CALL_DIRECT_MMAP(mmsize)); | ||
| 3840 | if (mm != CMFAIL) { | ||
| 3841 | size_t offset = align_offset(chunk2mem(mm)); | ||
| 3842 | size_t psize = mmsize - offset - MMAP_FOOT_PAD; | ||
| 3843 | mchunkptr p = (mchunkptr)(mm + offset); | ||
| 3844 | p->prev_foot = offset; | ||
| 3845 | p->head = psize; | ||
| 3846 | mark_inuse_foot(m, p, psize); | ||
| 3847 | chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; | ||
| 3848 | chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; | ||
| 3849 | |||
| 3850 | if (m->least_addr == 0 || mm < m->least_addr) | ||
| 3851 | m->least_addr = mm; | ||
| 3852 | if ((m->footprint += mmsize) > m->max_footprint) | ||
| 3853 | m->max_footprint = m->footprint; | ||
| 3854 | assert(is_aligned(chunk2mem(p))); | ||
| 3855 | check_mmapped_chunk(m, p); | ||
| 3856 | return chunk2mem(p); | ||
| 3857 | } | ||
| 3858 | } | ||
| 3859 | return 0; | ||
| 3860 | } | ||
| 3861 | |||
| 3862 | /* Realloc using mmap */ | ||
| 3863 | static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) { | ||
| 3864 | size_t oldsize = chunksize(oldp); | ||
| 3865 | (void)flags; /* placate people compiling -Wunused */ | ||
| 3866 | if (is_small(nb)) /* Can't shrink mmap regions below small size */ | ||
| 3867 | return 0; | ||
| 3868 | /* Keep old chunk if big enough but not too big */ | ||
| 3869 | if (oldsize >= nb + SIZE_T_SIZE && | ||
| 3870 | (oldsize - nb) <= (mparams.granularity << 1)) | ||
| 3871 | return oldp; | ||
| 3872 | else { | ||
| 3873 | size_t offset = oldp->prev_foot; | ||
| 3874 | size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; | ||
| 3875 | size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); | ||
| 3876 | char* cp = (char*)CALL_MREMAP((char*)oldp - offset, | ||
| 3877 | oldmmsize, newmmsize, flags); | ||
| 3878 | if (cp != CMFAIL) { | ||
| 3879 | mchunkptr newp = (mchunkptr)(cp + offset); | ||
| 3880 | size_t psize = newmmsize - offset - MMAP_FOOT_PAD; | ||
| 3881 | newp->head = psize; | ||
| 3882 | mark_inuse_foot(m, newp, psize); | ||
| 3883 | chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; | ||
| 3884 | chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0; | ||
| 3885 | |||
| 3886 | if (cp < m->least_addr) | ||
| 3887 | m->least_addr = cp; | ||
| 3888 | if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) | ||
| 3889 | m->max_footprint = m->footprint; | ||
| 3890 | check_mmapped_chunk(m, newp); | ||
| 3891 | return newp; | ||
| 3892 | } | ||
| 3893 | } | ||
| 3894 | return 0; | ||
| 3895 | } | ||
| 3896 | |||
| 3897 | |||
| 3898 | /* -------------------------- mspace management -------------------------- */ | ||
| 3899 | |||
| 3900 | /* Initialize top chunk and its size */ | ||
| 3901 | static void init_top(mstate m, mchunkptr p, size_t psize) { | ||
| 3902 | /* Ensure alignment */ | ||
| 3903 | size_t offset = align_offset(chunk2mem(p)); | ||
| 3904 | p = (mchunkptr)((char*)p + offset); | ||
| 3905 | psize -= offset; | ||
| 3906 | |||
| 3907 | m->top = p; | ||
| 3908 | m->topsize = psize; | ||
| 3909 | p->head = psize | PINUSE_BIT; | ||
| 3910 | /* set size of fake trailing chunk holding overhead space only once */ | ||
| 3911 | chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; | ||
| 3912 | m->trim_check = mparams.trim_threshold; /* reset on each update */ | ||
| 3913 | } | ||
| 3914 | |||
| 3915 | /* Initialize bins for a new mstate that is otherwise zeroed out */ | ||
| 3916 | static void init_bins(mstate m) { | ||
| 3917 | /* Establish circular links for smallbins */ | ||
| 3918 | bindex_t i; | ||
| 3919 | for (i = 0; i < NSMALLBINS; ++i) { | ||
| 3920 | sbinptr bin = smallbin_at(m,i); | ||
| 3921 | bin->fd = bin->bk = bin; | ||
| 3922 | } | ||
| 3923 | } | ||
| 3924 | |||
| 3925 | #if PROCEED_ON_ERROR | ||
| 3926 | |||
| 3927 | /* default corruption action */ | ||
| 3928 | static void reset_on_error(mstate m) { | ||
| 3929 | int i; | ||
| 3930 | ++malloc_corruption_error_count; | ||
| 3931 | /* Reinitialize fields to forget about all memory */ | ||
| 3932 | m->smallmap = m->treemap = 0; | ||
| 3933 | m->dvsize = m->topsize = 0; | ||
| 3934 | m->seg.base = 0; | ||
| 3935 | m->seg.size = 0; | ||
| 3936 | m->seg.next = 0; | ||
| 3937 | m->top = m->dv = 0; | ||
| 3938 | for (i = 0; i < NTREEBINS; ++i) | ||
| 3939 | *treebin_at(m, i) = 0; | ||
| 3940 | init_bins(m); | ||
| 3941 | } | ||
| 3942 | #endif /* PROCEED_ON_ERROR */ | ||
| 3943 | |||
| 3944 | /* Allocate chunk and prepend remainder with chunk in successor base. */ | ||
| 3945 | static void* prepend_alloc(mstate m, char* newbase, char* oldbase, | ||
| 3946 | size_t nb) { | ||
| 3947 | mchunkptr p = align_as_chunk(newbase); | ||
| 3948 | mchunkptr oldfirst = align_as_chunk(oldbase); | ||
| 3949 | size_t psize = (char*)oldfirst - (char*)p; | ||
| 3950 | mchunkptr q = chunk_plus_offset(p, nb); | ||
| 3951 | size_t qsize = psize - nb; | ||
| 3952 | set_size_and_pinuse_of_inuse_chunk(m, p, nb); | ||
| 3953 | |||
| 3954 | assert((char*)oldfirst > (char*)q); | ||
| 3955 | assert(pinuse(oldfirst)); | ||
| 3956 | assert(qsize >= MIN_CHUNK_SIZE); | ||
| 3957 | |||
| 3958 | /* consolidate remainder with first chunk of old base */ | ||
| 3959 | if (oldfirst == m->top) { | ||
| 3960 | size_t tsize = m->topsize += qsize; | ||
| 3961 | m->top = q; | ||
| 3962 | q->head = tsize | PINUSE_BIT; | ||
| 3963 | check_top_chunk(m, q); | ||
| 3964 | } | ||
| 3965 | else if (oldfirst == m->dv) { | ||
| 3966 | size_t dsize = m->dvsize += qsize; | ||
| 3967 | m->dv = q; | ||
| 3968 | set_size_and_pinuse_of_free_chunk(q, dsize); | ||
| 3969 | } | ||
| 3970 | else { | ||
| 3971 | if (!is_inuse(oldfirst)) { | ||
| 3972 | size_t nsize = chunksize(oldfirst); | ||
| 3973 | unlink_chunk(m, oldfirst, nsize); | ||
| 3974 | oldfirst = chunk_plus_offset(oldfirst, nsize); | ||
| 3975 | qsize += nsize; | ||
| 3976 | } | ||
| 3977 | set_free_with_pinuse(q, qsize, oldfirst); | ||
| 3978 | insert_chunk(m, q, qsize); | ||
| 3979 | check_free_chunk(m, q); | ||
| 3980 | } | ||
| 3981 | |||
| 3982 | check_malloced_chunk(m, chunk2mem(p), nb); | ||
| 3983 | return chunk2mem(p); | ||
| 3984 | } | ||
| 3985 | |||
| 3986 | /* Add a segment to hold a new noncontiguous region */ | ||
| 3987 | static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) { | ||
| 3988 | /* Determine locations and sizes of segment, fenceposts, old top */ | ||
| 3989 | char* old_top = (char*)m->top; | ||
| 3990 | msegmentptr oldsp = segment_holding(m, old_top); | ||
| 3991 | char* old_end = oldsp->base + oldsp->size; | ||
| 3992 | size_t ssize = pad_request(sizeof(struct malloc_segment)); | ||
| 3993 | char* rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); | ||
| 3994 | size_t offset = align_offset(chunk2mem(rawsp)); | ||
| 3995 | char* asp = rawsp + offset; | ||
| 3996 | char* csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp; | ||
| 3997 | mchunkptr sp = (mchunkptr)csp; | ||
| 3998 | msegmentptr ss = (msegmentptr)(chunk2mem(sp)); | ||
| 3999 | mchunkptr tnext = chunk_plus_offset(sp, ssize); | ||
| 4000 | mchunkptr p = tnext; | ||
| 4001 | int nfences = 0; | ||
| 4002 | |||
| 4003 | /* reset top to new space */ | ||
| 4004 | init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); | ||
| 4005 | |||
| 4006 | /* Set up segment record */ | ||
| 4007 | assert(is_aligned(ss)); | ||
| 4008 | set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); | ||
| 4009 | *ss = m->seg; /* Push current record */ | ||
| 4010 | m->seg.base = tbase; | ||
| 4011 | m->seg.size = tsize; | ||
| 4012 | m->seg.sflags = mmapped; | ||
| 4013 | m->seg.next = ss; | ||
| 4014 | |||
| 4015 | /* Insert trailing fenceposts */ | ||
| 4016 | for (;;) { | ||
| 4017 | mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); | ||
| 4018 | p->head = FENCEPOST_HEAD; | ||
| 4019 | ++nfences; | ||
| 4020 | if ((char*)(&(nextp->head)) < old_end) | ||
| 4021 | p = nextp; | ||
| 4022 | else | ||
| 4023 | break; | ||
| 4024 | } | ||
| 4025 | assert(nfences >= 2); | ||
| 4026 | |||
| 4027 | /* Insert the rest of old top into a bin as an ordinary free chunk */ | ||
| 4028 | if (csp != old_top) { | ||
| 4029 | mchunkptr q = (mchunkptr)old_top; | ||
| 4030 | size_t psize = csp - old_top; | ||
| 4031 | mchunkptr tn = chunk_plus_offset(q, psize); | ||
| 4032 | set_free_with_pinuse(q, psize, tn); | ||
| 4033 | insert_chunk(m, q, psize); | ||
| 4034 | } | ||
| 4035 | |||
| 4036 | check_top_chunk(m, m->top); | ||
| 4037 | } | ||
| 4038 | |||
| 4039 | /* -------------------------- System allocation -------------------------- */ | ||
| 4040 | |||
| 4041 | /* Get memory from system using MORECORE or MMAP */ | ||
| 4042 | static void* sys_alloc(mstate m, size_t nb) { | ||
| 4043 | char* tbase = CMFAIL; | ||
| 4044 | size_t tsize = 0; | ||
| 4045 | flag_t mmap_flag = 0; | ||
| 4046 | size_t asize; /* allocation size */ | ||
| 4047 | |||
| 4048 | ensure_initialization(); | ||
| 4049 | |||
| 4050 | /* Directly map large chunks, but only if already initialized */ | ||
| 4051 | if (use_mmap(m) && nb >= mparams.mmap_threshold && m->topsize != 0) { | ||
| 4052 | void* mem = mmap_alloc(m, nb); | ||
| 4053 | if (mem != 0) | ||
| 4054 | return mem; | ||
| 4055 | } | ||
| 4056 | |||
| 4057 | asize = granularity_align(nb + SYS_ALLOC_PADDING); | ||
| 4058 | #ifdef __wasilibc_unmodified_upstream // Bug fix: set ENOMEM on size overflow | ||
| 4059 | if (asize <= nb) | ||
| 4060 | return 0; /* wraparound */ | ||
| 4061 | #else | ||
| 4062 | if (asize <= nb) { | ||
| 4063 | MALLOC_FAILURE_ACTION; | ||
| 4064 | return 0; /* wraparound */ | ||
| 4065 | } | ||
| 4066 | #endif | ||
| 4067 | if (m->footprint_limit != 0) { | ||
| 4068 | size_t fp = m->footprint + asize; | ||
| 4069 | #ifdef __wasilibc_unmodified_upstream // Bug fix: set ENOMEM on footprint overrun | ||
| 4070 | if (fp <= m->footprint || fp > m->footprint_limit) | ||
| 4071 | return 0; | ||
| 4072 | #else | ||
| 4073 | if (fp <= m->footprint || fp > m->footprint_limit) { | ||
| 4074 | MALLOC_FAILURE_ACTION; | ||
| 4075 | return 0; | ||
| 4076 | } | ||
| 4077 | #endif | ||
| 4078 | } | ||
| 4079 | |||
| 4080 | /* | ||
| 4081 | Try getting memory in any of three ways (in most-preferred to | ||
| 4082 | least-preferred order): | ||
| 4083 | 1. A call to MORECORE that can normally contiguously extend memory. | ||
| 4084 | (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or | ||
| 4085 | or main space is mmapped or a previous contiguous call failed) | ||
| 4086 | 2. A call to MMAP new space (disabled if not HAVE_MMAP). | ||
| 4087 | Note that under the default settings, if MORECORE is unable to | ||
| 4088 | fulfill a request, and HAVE_MMAP is true, then mmap is | ||
| 4089 | used as a noncontiguous system allocator. This is a useful backup | ||
| 4090 | strategy for systems with holes in address spaces -- in this case | ||
| 4091 | sbrk cannot contiguously expand the heap, but mmap may be able to | ||
| 4092 | find space. | ||
| 4093 | 3. A call to MORECORE that cannot usually contiguously extend memory. | ||
| 4094 | (disabled if not HAVE_MORECORE) | ||
| 4095 | |||
| 4096 | In all cases, we need to request enough bytes from system to ensure | ||
| 4097 | we can malloc nb bytes upon success, so pad with enough space for | ||
| 4098 | top_foot, plus alignment-pad to make sure we don't lose bytes if | ||
| 4099 | not on boundary, and round this up to a granularity unit. | ||
| 4100 | */ | ||
| 4101 | |||
| 4102 | if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) { | ||
| 4103 | char* br = CMFAIL; | ||
| 4104 | size_t ssize = asize; /* sbrk call size */ | ||
| 4105 | msegmentptr ss = (m->top == 0)? 0 : segment_holding(m, (char*)m->top); | ||
| 4106 | ACQUIRE_MALLOC_GLOBAL_LOCK(); | ||
| 4107 | |||
| 4108 | if (ss == 0) { /* First time through or recovery */ | ||
| 4109 | char* base = (char*)CALL_MORECORE(0); | ||
| 4110 | if (base != CMFAIL) { | ||
| 4111 | size_t fp; | ||
| 4112 | /* Adjust to end on a page boundary */ | ||
| 4113 | if (!is_page_aligned(base)) | ||
| 4114 | ssize += (page_align((size_t)base) - (size_t)base); | ||
| 4115 | fp = m->footprint + ssize; /* recheck limits */ | ||
| 4116 | if (ssize > nb && ssize < HALF_MAX_SIZE_T && | ||
| 4117 | (m->footprint_limit == 0 || | ||
| 4118 | (fp > m->footprint && fp <= m->footprint_limit)) && | ||
| 4119 | (br = (char*)(CALL_MORECORE(ssize))) == base) { | ||
| 4120 | tbase = base; | ||
| 4121 | tsize = ssize; | ||
| 4122 | } | ||
| 4123 | } | ||
| 4124 | } | ||
| 4125 | else { | ||
| 4126 | /* Subtract out existing available top space from MORECORE request. */ | ||
| 4127 | ssize = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING); | ||
| 4128 | /* Use mem here only if it did continuously extend old space */ | ||
| 4129 | if (ssize < HALF_MAX_SIZE_T && | ||
| 4130 | (br = (char*)(CALL_MORECORE(ssize))) == ss->base+ss->size) { | ||
| 4131 | tbase = br; | ||
| 4132 | tsize = ssize; | ||
| 4133 | } | ||
| 4134 | } | ||
| 4135 | |||
| 4136 | if (tbase == CMFAIL) { /* Cope with partial failure */ | ||
| 4137 | if (br != CMFAIL) { /* Try to use/extend the space we did get */ | ||
| 4138 | if (ssize < HALF_MAX_SIZE_T && | ||
| 4139 | ssize < nb + SYS_ALLOC_PADDING) { | ||
| 4140 | size_t esize = granularity_align(nb + SYS_ALLOC_PADDING - ssize); | ||
| 4141 | if (esize < HALF_MAX_SIZE_T) { | ||
| 4142 | char* end = (char*)CALL_MORECORE(esize); | ||
| 4143 | if (end != CMFAIL) | ||
| 4144 | ssize += esize; | ||
| 4145 | else { /* Can't use; try to release */ | ||
| 4146 | (void) CALL_MORECORE(-ssize); | ||
| 4147 | br = CMFAIL; | ||
| 4148 | } | ||
| 4149 | } | ||
| 4150 | } | ||
| 4151 | } | ||
| 4152 | if (br != CMFAIL) { /* Use the space we did get */ | ||
| 4153 | tbase = br; | ||
| 4154 | tsize = ssize; | ||
| 4155 | } | ||
| 4156 | else | ||
| 4157 | disable_contiguous(m); /* Don't try contiguous path in the future */ | ||
| 4158 | } | ||
| 4159 | |||
| 4160 | RELEASE_MALLOC_GLOBAL_LOCK(); | ||
| 4161 | } | ||
| 4162 | |||
| 4163 | if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ | ||
| 4164 | char* mp = (char*)(CALL_MMAP(asize)); | ||
| 4165 | if (mp != CMFAIL) { | ||
| 4166 | tbase = mp; | ||
| 4167 | tsize = asize; | ||
| 4168 | mmap_flag = USE_MMAP_BIT; | ||
| 4169 | } | ||
| 4170 | } | ||
| 4171 | |||
| 4172 | if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ | ||
| 4173 | if (asize < HALF_MAX_SIZE_T) { | ||
| 4174 | char* br = CMFAIL; | ||
| 4175 | char* end = CMFAIL; | ||
| 4176 | ACQUIRE_MALLOC_GLOBAL_LOCK(); | ||
| 4177 | br = (char*)(CALL_MORECORE(asize)); | ||
| 4178 | end = (char*)(CALL_MORECORE(0)); | ||
| 4179 | RELEASE_MALLOC_GLOBAL_LOCK(); | ||
| 4180 | if (br != CMFAIL && end != CMFAIL && br < end) { | ||
| 4181 | size_t ssize = end - br; | ||
| 4182 | if (ssize > nb + TOP_FOOT_SIZE) { | ||
| 4183 | tbase = br; | ||
| 4184 | tsize = ssize; | ||
| 4185 | } | ||
| 4186 | } | ||
| 4187 | } | ||
| 4188 | } | ||
| 4189 | |||
| 4190 | if (tbase != CMFAIL) { | ||
| 4191 | |||
| 4192 | if ((m->footprint += tsize) > m->max_footprint) | ||
| 4193 | m->max_footprint = m->footprint; | ||
| 4194 | |||
| 4195 | if (!is_initialized(m)) { /* first-time initialization */ | ||
| 4196 | if (m->least_addr == 0 || tbase < m->least_addr) | ||
| 4197 | m->least_addr = tbase; | ||
| 4198 | m->seg.base = tbase; | ||
| 4199 | m->seg.size = tsize; | ||
| 4200 | m->seg.sflags = mmap_flag; | ||
| 4201 | m->magic = mparams.magic; | ||
| 4202 | m->release_checks = MAX_RELEASE_CHECK_RATE; | ||
| 4203 | init_bins(m); | ||
| 4204 | #if !ONLY_MSPACES | ||
| 4205 | if (is_global(m)) | ||
| 4206 | init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); | ||
| 4207 | else | ||
| 4208 | #endif | ||
| 4209 | { | ||
| 4210 | /* Offset top by embedded malloc_state */ | ||
| 4211 | mchunkptr mn = next_chunk(mem2chunk(m)); | ||
| 4212 | init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE); | ||
| 4213 | } | ||
| 4214 | } | ||
| 4215 | |||
| 4216 | else { | ||
| 4217 | /* Try to merge with an existing segment */ | ||
| 4218 | msegmentptr sp = &m->seg; | ||
| 4219 | /* Only consider most recent segment if traversal suppressed */ | ||
| 4220 | while (sp != 0 && tbase != sp->base + sp->size) | ||
| 4221 | sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next; | ||
| 4222 | if (sp != 0 && | ||
| 4223 | !is_extern_segment(sp) && | ||
| 4224 | (sp->sflags & USE_MMAP_BIT) == mmap_flag && | ||
| 4225 | segment_holds(sp, m->top)) { /* append */ | ||
| 4226 | sp->size += tsize; | ||
| 4227 | init_top(m, m->top, m->topsize + tsize); | ||
| 4228 | } | ||
| 4229 | else { | ||
| 4230 | if (tbase < m->least_addr) | ||
| 4231 | m->least_addr = tbase; | ||
| 4232 | sp = &m->seg; | ||
| 4233 | while (sp != 0 && sp->base != tbase + tsize) | ||
| 4234 | sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next; | ||
| 4235 | if (sp != 0 && | ||
| 4236 | !is_extern_segment(sp) && | ||
| 4237 | (sp->sflags & USE_MMAP_BIT) == mmap_flag) { | ||
| 4238 | char* oldbase = sp->base; | ||
| 4239 | sp->base = tbase; | ||
| 4240 | sp->size += tsize; | ||
| 4241 | return prepend_alloc(m, tbase, oldbase, nb); | ||
| 4242 | } | ||
| 4243 | else | ||
| 4244 | add_segment(m, tbase, tsize, mmap_flag); | ||
| 4245 | } | ||
| 4246 | } | ||
| 4247 | |||
| 4248 | if (nb < m->topsize) { /* Allocate from new or extended top space */ | ||
| 4249 | size_t rsize = m->topsize -= nb; | ||
| 4250 | mchunkptr p = m->top; | ||
| 4251 | mchunkptr r = m->top = chunk_plus_offset(p, nb); | ||
| 4252 | r->head = rsize | PINUSE_BIT; | ||
| 4253 | set_size_and_pinuse_of_inuse_chunk(m, p, nb); | ||
| 4254 | check_top_chunk(m, m->top); | ||
| 4255 | check_malloced_chunk(m, chunk2mem(p), nb); | ||
| 4256 | return chunk2mem(p); | ||
| 4257 | } | ||
| 4258 | } | ||
| 4259 | |||
| 4260 | MALLOC_FAILURE_ACTION; | ||
| 4261 | return 0; | ||
| 4262 | } | ||
| 4263 | |||
| 4264 | /* ----------------------- system deallocation -------------------------- */ | ||
| 4265 | |||
| 4266 | /* Unmap and unlink any mmapped segments that don't contain used chunks */ | ||
| 4267 | static size_t release_unused_segments(mstate m) { | ||
| 4268 | size_t released = 0; | ||
| 4269 | int nsegs = 0; | ||
| 4270 | msegmentptr pred = &m->seg; | ||
| 4271 | msegmentptr sp = pred->next; | ||
| 4272 | while (sp != 0) { | ||
| 4273 | char* base = sp->base; | ||
| 4274 | size_t size = sp->size; | ||
| 4275 | msegmentptr next = sp->next; | ||
| 4276 | ++nsegs; | ||
| 4277 | if (is_mmapped_segment(sp) && !is_extern_segment(sp)) { | ||
| 4278 | mchunkptr p = align_as_chunk(base); | ||
| 4279 | size_t psize = chunksize(p); | ||
| 4280 | /* Can unmap if first chunk holds entire segment and not pinned */ | ||
| 4281 | if (!is_inuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) { | ||
| 4282 | tchunkptr tp = (tchunkptr)p; | ||
| 4283 | assert(segment_holds(sp, (char*)sp)); | ||
| 4284 | if (p == m->dv) { | ||
| 4285 | m->dv = 0; | ||
| 4286 | m->dvsize = 0; | ||
| 4287 | } | ||
| 4288 | else { | ||
| 4289 | unlink_large_chunk(m, tp); | ||
| 4290 | } | ||
| 4291 | if (CALL_MUNMAP(base, size) == 0) { | ||
| 4292 | released += size; | ||
| 4293 | m->footprint -= size; | ||
| 4294 | /* unlink obsoleted record */ | ||
| 4295 | sp = pred; | ||
| 4296 | sp->next = next; | ||
| 4297 | } | ||
| 4298 | else { /* back out if cannot unmap */ | ||
| 4299 | insert_large_chunk(m, tp, psize); | ||
| 4300 | } | ||
| 4301 | } | ||
| 4302 | } | ||
| 4303 | if (NO_SEGMENT_TRAVERSAL) /* scan only first segment */ | ||
| 4304 | break; | ||
| 4305 | pred = sp; | ||
| 4306 | sp = next; | ||
| 4307 | } | ||
| 4308 | /* Reset check counter */ | ||
| 4309 | m->release_checks = (((size_t) nsegs > (size_t) MAX_RELEASE_CHECK_RATE)? | ||
| 4310 | (size_t) nsegs : (size_t) MAX_RELEASE_CHECK_RATE); | ||
| 4311 | return released; | ||
| 4312 | } | ||
| 4313 | |||
| 4314 | static int sys_trim(mstate m, size_t pad) { | ||
| 4315 | size_t released = 0; | ||
| 4316 | ensure_initialization(); | ||
| 4317 | if (pad < MAX_REQUEST && is_initialized(m)) { | ||
| 4318 | pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ | ||
| 4319 | |||
| 4320 | if (m->topsize > pad) { | ||
| 4321 | /* Shrink top space in granularity-size units, keeping at least one */ | ||
| 4322 | size_t unit = mparams.granularity; | ||
| 4323 | size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - | ||
| 4324 | SIZE_T_ONE) * unit; | ||
| 4325 | msegmentptr sp = segment_holding(m, (char*)m->top); | ||
| 4326 | |||
| 4327 | if (!is_extern_segment(sp)) { | ||
| 4328 | if (is_mmapped_segment(sp)) { | ||
| 4329 | if (HAVE_MMAP && | ||
| 4330 | sp->size >= extra && | ||
| 4331 | !has_segment_link(m, sp)) { /* can't shrink if pinned */ | ||
| 4332 | size_t newsize = sp->size - extra; | ||
| 4333 | (void)newsize; /* placate people compiling -Wunused-variable */ | ||
| 4334 | /* Prefer mremap, fall back to munmap */ | ||
| 4335 | if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) || | ||
| 4336 | (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { | ||
| 4337 | released = extra; | ||
| 4338 | } | ||
| 4339 | } | ||
| 4340 | } | ||
| 4341 | else if (HAVE_MORECORE) { | ||
| 4342 | if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ | ||
| 4343 | extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; | ||
| 4344 | ACQUIRE_MALLOC_GLOBAL_LOCK(); | ||
| 4345 | { | ||
| 4346 | /* Make sure end of memory is where we last set it. */ | ||
| 4347 | char* old_br = (char*)(CALL_MORECORE(0)); | ||
| 4348 | if (old_br == sp->base + sp->size) { | ||
| 4349 | char* rel_br = (char*)(CALL_MORECORE(-extra)); | ||
| 4350 | char* new_br = (char*)(CALL_MORECORE(0)); | ||
| 4351 | if (rel_br != CMFAIL && new_br < old_br) | ||
| 4352 | released = old_br - new_br; | ||
| 4353 | } | ||
| 4354 | } | ||
| 4355 | RELEASE_MALLOC_GLOBAL_LOCK(); | ||
| 4356 | } | ||
| 4357 | } | ||
| 4358 | |||
| 4359 | if (released != 0) { | ||
| 4360 | sp->size -= released; | ||
| 4361 | m->footprint -= released; | ||
| 4362 | init_top(m, m->top, m->topsize - released); | ||
| 4363 | check_top_chunk(m, m->top); | ||
| 4364 | } | ||
| 4365 | } | ||
| 4366 | |||
| 4367 | /* Unmap any unused mmapped segments */ | ||
| 4368 | if (HAVE_MMAP) | ||
| 4369 | released += release_unused_segments(m); | ||
| 4370 | |||
| 4371 | /* On failure, disable autotrim to avoid repeated failed future calls */ | ||
| 4372 | if (released == 0 && m->topsize > m->trim_check) | ||
| 4373 | m->trim_check = MAX_SIZE_T; | ||
| 4374 | } | ||
| 4375 | |||
| 4376 | return (released != 0)? 1 : 0; | ||
| 4377 | } | ||
| 4378 | |||
| 4379 | /* Consolidate and bin a chunk. Differs from exported versions | ||
| 4380 | of free mainly in that the chunk need not be marked as inuse. | ||
| 4381 | */ | ||
| 4382 | static void dispose_chunk(mstate m, mchunkptr p, size_t psize) { | ||
| 4383 | mchunkptr next = chunk_plus_offset(p, psize); | ||
| 4384 | if (!pinuse(p)) { | ||
| 4385 | mchunkptr prev; | ||
| 4386 | size_t prevsize = p->prev_foot; | ||
| 4387 | if (is_mmapped(p)) { | ||
| 4388 | psize += prevsize + MMAP_FOOT_PAD; | ||
| 4389 | if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) | ||
| 4390 | m->footprint -= psize; | ||
| 4391 | return; | ||
| 4392 | } | ||
| 4393 | prev = chunk_minus_offset(p, prevsize); | ||
| 4394 | psize += prevsize; | ||
| 4395 | p = prev; | ||
| 4396 | if (RTCHECK(ok_address(m, prev))) { /* consolidate backward */ | ||
| 4397 | if (p != m->dv) { | ||
| 4398 | unlink_chunk(m, p, prevsize); | ||
| 4399 | } | ||
| 4400 | else if ((next->head & INUSE_BITS) == INUSE_BITS) { | ||
| 4401 | m->dvsize = psize; | ||
| 4402 | set_free_with_pinuse(p, psize, next); | ||
| 4403 | return; | ||
| 4404 | } | ||
| 4405 | } | ||
| 4406 | else { | ||
| 4407 | CORRUPTION_ERROR_ACTION(m); | ||
| 4408 | return; | ||
| 4409 | } | ||
| 4410 | } | ||
| 4411 | if (RTCHECK(ok_address(m, next))) { | ||
| 4412 | if (!cinuse(next)) { /* consolidate forward */ | ||
| 4413 | if (next == m->top) { | ||
| 4414 | size_t tsize = m->topsize += psize; | ||
| 4415 | m->top = p; | ||
| 4416 | p->head = tsize | PINUSE_BIT; | ||
| 4417 | if (p == m->dv) { | ||
| 4418 | m->dv = 0; | ||
| 4419 | m->dvsize = 0; | ||
| 4420 | } | ||
| 4421 | return; | ||
| 4422 | } | ||
| 4423 | else if (next == m->dv) { | ||
| 4424 | size_t dsize = m->dvsize += psize; | ||
| 4425 | m->dv = p; | ||
| 4426 | set_size_and_pinuse_of_free_chunk(p, dsize); | ||
| 4427 | return; | ||
| 4428 | } | ||
| 4429 | else { | ||
| 4430 | size_t nsize = chunksize(next); | ||
| 4431 | psize += nsize; | ||
| 4432 | unlink_chunk(m, next, nsize); | ||
| 4433 | set_size_and_pinuse_of_free_chunk(p, psize); | ||
| 4434 | if (p == m->dv) { | ||
| 4435 | m->dvsize = psize; | ||
| 4436 | return; | ||
| 4437 | } | ||
| 4438 | } | ||
| 4439 | } | ||
| 4440 | else { | ||
| 4441 | set_free_with_pinuse(p, psize, next); | ||
| 4442 | } | ||
| 4443 | insert_chunk(m, p, psize); | ||
| 4444 | } | ||
| 4445 | else { | ||
| 4446 | CORRUPTION_ERROR_ACTION(m); | ||
| 4447 | } | ||
| 4448 | } | ||
| 4449 | |||
| 4450 | /* ---------------------------- malloc --------------------------- */ | ||
| 4451 | |||
| 4452 | /* allocate a large request from the best fitting chunk in a treebin */ | ||
| 4453 | static void* tmalloc_large(mstate m, size_t nb) { | ||
| 4454 | tchunkptr v = 0; | ||
| 4455 | size_t rsize = -nb; /* Unsigned negation */ | ||
| 4456 | tchunkptr t; | ||
| 4457 | bindex_t idx; | ||
| 4458 | compute_tree_index(nb, idx); | ||
| 4459 | if ((t = *treebin_at(m, idx)) != 0) { | ||
| 4460 | /* Traverse tree for this bin looking for node with size == nb */ | ||
| 4461 | size_t sizebits = nb << leftshift_for_tree_index(idx); | ||
| 4462 | tchunkptr rst = 0; /* The deepest untaken right subtree */ | ||
| 4463 | for (;;) { | ||
| 4464 | tchunkptr rt; | ||
| 4465 | size_t trem = chunksize(t) - nb; | ||
| 4466 | if (trem < rsize) { | ||
| 4467 | v = t; | ||
| 4468 | if ((rsize = trem) == 0) | ||
| 4469 | break; | ||
| 4470 | } | ||
| 4471 | rt = t->child[1]; | ||
| 4472 | t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; | ||
| 4473 | if (rt != 0 && rt != t) | ||
| 4474 | rst = rt; | ||
| 4475 | if (t == 0) { | ||
| 4476 | t = rst; /* set t to least subtree holding sizes > nb */ | ||
| 4477 | break; | ||
| 4478 | } | ||
| 4479 | sizebits <<= 1; | ||
| 4480 | } | ||
| 4481 | } | ||
| 4482 | if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ | ||
| 4483 | binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; | ||
| 4484 | if (leftbits != 0) { | ||
| 4485 | bindex_t i; | ||
| 4486 | binmap_t leastbit = least_bit(leftbits); | ||
| 4487 | compute_bit2idx(leastbit, i); | ||
| 4488 | t = *treebin_at(m, i); | ||
| 4489 | } | ||
| 4490 | } | ||
| 4491 | |||
| 4492 | while (t != 0) { /* find smallest of tree or subtree */ | ||
| 4493 | size_t trem = chunksize(t) - nb; | ||
| 4494 | if (trem < rsize) { | ||
| 4495 | rsize = trem; | ||
| 4496 | v = t; | ||
| 4497 | } | ||
| 4498 | t = leftmost_child(t); | ||
| 4499 | } | ||
| 4500 | |||
| 4501 | /* If dv is a better fit, return 0 so malloc will use it */ | ||
| 4502 | if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { | ||
| 4503 | if (RTCHECK(ok_address(m, v))) { /* split */ | ||
| 4504 | mchunkptr r = chunk_plus_offset(v, nb); | ||
| 4505 | assert(chunksize(v) == rsize + nb); | ||
| 4506 | if (RTCHECK(ok_next(v, r))) { | ||
| 4507 | unlink_large_chunk(m, v); | ||
| 4508 | if (rsize < MIN_CHUNK_SIZE) | ||
| 4509 | set_inuse_and_pinuse(m, v, (rsize + nb)); | ||
| 4510 | else { | ||
| 4511 | set_size_and_pinuse_of_inuse_chunk(m, v, nb); | ||
| 4512 | set_size_and_pinuse_of_free_chunk(r, rsize); | ||
| 4513 | insert_chunk(m, r, rsize); | ||
| 4514 | } | ||
| 4515 | return chunk2mem(v); | ||
| 4516 | } | ||
| 4517 | } | ||
| 4518 | CORRUPTION_ERROR_ACTION(m); | ||
| 4519 | } | ||
| 4520 | return 0; | ||
| 4521 | } | ||
| 4522 | |||
| 4523 | /* allocate a small request from the best fitting chunk in a treebin */ | ||
| 4524 | static void* tmalloc_small(mstate m, size_t nb) { | ||
| 4525 | tchunkptr t, v; | ||
| 4526 | size_t rsize; | ||
| 4527 | bindex_t i; | ||
| 4528 | binmap_t leastbit = least_bit(m->treemap); | ||
| 4529 | compute_bit2idx(leastbit, i); | ||
| 4530 | v = t = *treebin_at(m, i); | ||
| 4531 | rsize = chunksize(t) - nb; | ||
| 4532 | |||
| 4533 | while ((t = leftmost_child(t)) != 0) { | ||
| 4534 | size_t trem = chunksize(t) - nb; | ||
| 4535 | if (trem < rsize) { | ||
| 4536 | rsize = trem; | ||
| 4537 | v = t; | ||
| 4538 | } | ||
| 4539 | } | ||
| 4540 | |||
| 4541 | if (RTCHECK(ok_address(m, v))) { | ||
| 4542 | mchunkptr r = chunk_plus_offset(v, nb); | ||
| 4543 | assert(chunksize(v) == rsize + nb); | ||
| 4544 | if (RTCHECK(ok_next(v, r))) { | ||
| 4545 | unlink_large_chunk(m, v); | ||
| 4546 | if (rsize < MIN_CHUNK_SIZE) | ||
| 4547 | set_inuse_and_pinuse(m, v, (rsize + nb)); | ||
| 4548 | else { | ||
| 4549 | set_size_and_pinuse_of_inuse_chunk(m, v, nb); | ||
| 4550 | set_size_and_pinuse_of_free_chunk(r, rsize); | ||
| 4551 | replace_dv(m, r, rsize); | ||
| 4552 | } | ||
| 4553 | return chunk2mem(v); | ||
| 4554 | } | ||
| 4555 | } | ||
| 4556 | |||
| 4557 | CORRUPTION_ERROR_ACTION(m); | ||
| 4558 | return 0; | ||
| 4559 | } | ||
| 4560 | |||
| 4561 | #if !ONLY_MSPACES | ||
| 4562 | |||
| 4563 | #if __wasilibc_unmodified_upstream // Forward declaration of try_init_allocator. | ||
| 4564 | #else | ||
| 4565 | static void try_init_allocator(void); | ||
| 4566 | #endif | ||
| 4567 | |||
| 4568 | void* dlmalloc(size_t bytes) { | ||
| 4569 | /* | ||
| 4570 | Basic algorithm: | ||
| 4571 | If a small request (< 256 bytes minus per-chunk overhead): | ||
| 4572 | 1. If one exists, use a remainderless chunk in associated smallbin. | ||
| 4573 | (Remainderless means that there are too few excess bytes to | ||
| 4574 | represent as a chunk.) | ||
| 4575 | 2. If it is big enough, use the dv chunk, which is normally the | ||
| 4576 | chunk adjacent to the one used for the most recent small request. | ||
| 4577 | 3. If one exists, split the smallest available chunk in a bin, | ||
| 4578 | saving remainder in dv. | ||
| 4579 | 4. If it is big enough, use the top chunk. | ||
| 4580 | 5. If available, get memory from system and use it | ||
| 4581 | Otherwise, for a large request: | ||
| 4582 | 1. Find the smallest available binned chunk that fits, and use it | ||
| 4583 | if it is better fitting than dv chunk, splitting if necessary. | ||
| 4584 | 2. If better fitting than any binned chunk, use the dv chunk. | ||
| 4585 | 3. If it is big enough, use the top chunk. | ||
| 4586 | 4. If request size >= mmap threshold, try to directly mmap this chunk. | ||
| 4587 | 5. If available, get memory from system and use it | ||
| 4588 | |||
| 4589 | The ugly goto's here ensure that postaction occurs along all paths. | ||
| 4590 | */ | ||
| 4591 | |||
| 4592 | #if USE_LOCKS | ||
| 4593 | ensure_initialization(); /* initialize in sys_alloc if not using locks */ | ||
| 4594 | #endif | ||
| 4595 | |||
| 4596 | #if __wasilibc_unmodified_upstream // Try to initialize the allocator. | ||
| 4597 | #else | ||
| 4598 | if (!is_initialized(gm)) { | ||
| 4599 | try_init_allocator(); | ||
| 4600 | } | ||
| 4601 | #endif | ||
| 4602 | |||
| 4603 | if (!PREACTION(gm)) { | ||
| 4604 | void* mem; | ||
| 4605 | size_t nb; | ||
| 4606 | if (bytes <= MAX_SMALL_REQUEST) { | ||
| 4607 | bindex_t idx; | ||
| 4608 | binmap_t smallbits; | ||
| 4609 | nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); | ||
| 4610 | idx = small_index(nb); | ||
| 4611 | smallbits = gm->smallmap >> idx; | ||
| 4612 | |||
| 4613 | if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ | ||
| 4614 | mchunkptr b, p; | ||
| 4615 | idx += ~smallbits & 1; /* Uses next bin if idx empty */ | ||
| 4616 | b = smallbin_at(gm, idx); | ||
| 4617 | p = b->fd; | ||
| 4618 | assert(chunksize(p) == small_index2size(idx)); | ||
| 4619 | unlink_first_small_chunk(gm, b, p, idx); | ||
| 4620 | set_inuse_and_pinuse(gm, p, small_index2size(idx)); | ||
| 4621 | mem = chunk2mem(p); | ||
| 4622 | check_malloced_chunk(gm, mem, nb); | ||
| 4623 | goto postaction; | ||
| 4624 | } | ||
| 4625 | |||
| 4626 | else if (nb > gm->dvsize) { | ||
| 4627 | if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ | ||
| 4628 | mchunkptr b, p, r; | ||
| 4629 | size_t rsize; | ||
| 4630 | bindex_t i; | ||
| 4631 | binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); | ||
| 4632 | binmap_t leastbit = least_bit(leftbits); | ||
| 4633 | compute_bit2idx(leastbit, i); | ||
| 4634 | b = smallbin_at(gm, i); | ||
| 4635 | p = b->fd; | ||
| 4636 | assert(chunksize(p) == small_index2size(i)); | ||
| 4637 | unlink_first_small_chunk(gm, b, p, i); | ||
| 4638 | rsize = small_index2size(i) - nb; | ||
| 4639 | /* Fit here cannot be remainderless if 4byte sizes */ | ||
| 4640 | if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) | ||
| 4641 | set_inuse_and_pinuse(gm, p, small_index2size(i)); | ||
| 4642 | else { | ||
| 4643 | set_size_and_pinuse_of_inuse_chunk(gm, p, nb); | ||
| 4644 | r = chunk_plus_offset(p, nb); | ||
| 4645 | set_size_and_pinuse_of_free_chunk(r, rsize); | ||
| 4646 | replace_dv(gm, r, rsize); | ||
| 4647 | } | ||
| 4648 | mem = chunk2mem(p); | ||
| 4649 | check_malloced_chunk(gm, mem, nb); | ||
| 4650 | goto postaction; | ||
| 4651 | } | ||
| 4652 | |||
| 4653 | else if (gm->treemap != 0 && (mem = tmalloc_small(gm, nb)) != 0) { | ||
| 4654 | check_malloced_chunk(gm, mem, nb); | ||
| 4655 | goto postaction; | ||
| 4656 | } | ||
| 4657 | } | ||
| 4658 | } | ||
| 4659 | else if (bytes >= MAX_REQUEST) | ||
| 4660 | nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ | ||
| 4661 | else { | ||
| 4662 | nb = pad_request(bytes); | ||
| 4663 | if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) { | ||
| 4664 | check_malloced_chunk(gm, mem, nb); | ||
| 4665 | goto postaction; | ||
| 4666 | } | ||
| 4667 | } | ||
| 4668 | |||
| 4669 | if (nb <= gm->dvsize) { | ||
| 4670 | size_t rsize = gm->dvsize - nb; | ||
| 4671 | mchunkptr p = gm->dv; | ||
| 4672 | if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ | ||
| 4673 | mchunkptr r = gm->dv = chunk_plus_offset(p, nb); | ||
| 4674 | gm->dvsize = rsize; | ||
| 4675 | set_size_and_pinuse_of_free_chunk(r, rsize); | ||
| 4676 | set_size_and_pinuse_of_inuse_chunk(gm, p, nb); | ||
| 4677 | } | ||
| 4678 | else { /* exhaust dv */ | ||
| 4679 | size_t dvs = gm->dvsize; | ||
| 4680 | gm->dvsize = 0; | ||
| 4681 | gm->dv = 0; | ||
| 4682 | set_inuse_and_pinuse(gm, p, dvs); | ||
| 4683 | } | ||
| 4684 | mem = chunk2mem(p); | ||
| 4685 | check_malloced_chunk(gm, mem, nb); | ||
| 4686 | goto postaction; | ||
| 4687 | } | ||
| 4688 | |||
| 4689 | else if (nb < gm->topsize) { /* Split top */ | ||
| 4690 | size_t rsize = gm->topsize -= nb; | ||
| 4691 | mchunkptr p = gm->top; | ||
| 4692 | mchunkptr r = gm->top = chunk_plus_offset(p, nb); | ||
| 4693 | r->head = rsize | PINUSE_BIT; | ||
| 4694 | set_size_and_pinuse_of_inuse_chunk(gm, p, nb); | ||
| 4695 | mem = chunk2mem(p); | ||
| 4696 | check_top_chunk(gm, gm->top); | ||
| 4697 | check_malloced_chunk(gm, mem, nb); | ||
| 4698 | goto postaction; | ||
| 4699 | } | ||
| 4700 | |||
| 4701 | mem = sys_alloc(gm, nb); | ||
| 4702 | |||
| 4703 | postaction: | ||
| 4704 | POSTACTION(gm); | ||
| 4705 | return mem; | ||
| 4706 | } | ||
| 4707 | |||
| 4708 | return 0; | ||
| 4709 | } | ||
| 4710 | |||
| 4711 | /* ---------------------------- free --------------------------- */ | ||
| 4712 | |||
| 4713 | void dlfree(void* mem) { | ||
| 4714 | /* | ||
| 4715 | Consolidate freed chunks with preceeding or succeeding bordering | ||
| 4716 | free chunks, if they exist, and then place in a bin. Intermixed | ||
| 4717 | with special cases for top, dv, mmapped chunks, and usage errors. | ||
| 4718 | */ | ||
| 4719 | |||
| 4720 | if (mem != 0) { | ||
| 4721 | mchunkptr p = mem2chunk(mem); | ||
| 4722 | #if FOOTERS | ||
| 4723 | mstate fm = get_mstate_for(p); | ||
| 4724 | if (!ok_magic(fm)) { | ||
| 4725 | USAGE_ERROR_ACTION(fm, p); | ||
| 4726 | return; | ||
| 4727 | } | ||
| 4728 | #else /* FOOTERS */ | ||
| 4729 | #define fm gm | ||
| 4730 | #endif /* FOOTERS */ | ||
| 4731 | if (!PREACTION(fm)) { | ||
| 4732 | check_inuse_chunk(fm, p); | ||
| 4733 | if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) { | ||
| 4734 | size_t psize = chunksize(p); | ||
| 4735 | mchunkptr next = chunk_plus_offset(p, psize); | ||
| 4736 | if (!pinuse(p)) { | ||
| 4737 | size_t prevsize = p->prev_foot; | ||
| 4738 | if (is_mmapped(p)) { | ||
| 4739 | psize += prevsize + MMAP_FOOT_PAD; | ||
| 4740 | if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) | ||
| 4741 | fm->footprint -= psize; | ||
| 4742 | goto postaction; | ||
| 4743 | } | ||
| 4744 | else { | ||
| 4745 | mchunkptr prev = chunk_minus_offset(p, prevsize); | ||
| 4746 | psize += prevsize; | ||
| 4747 | p = prev; | ||
| 4748 | if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ | ||
| 4749 | if (p != fm->dv) { | ||
| 4750 | unlink_chunk(fm, p, prevsize); | ||
| 4751 | } | ||
| 4752 | else if ((next->head & INUSE_BITS) == INUSE_BITS) { | ||
| 4753 | fm->dvsize = psize; | ||
| 4754 | set_free_with_pinuse(p, psize, next); | ||
| 4755 | goto postaction; | ||
| 4756 | } | ||
| 4757 | } | ||
| 4758 | else | ||
| 4759 | goto erroraction; | ||
| 4760 | } | ||
| 4761 | } | ||
| 4762 | |||
| 4763 | if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { | ||
| 4764 | if (!cinuse(next)) { /* consolidate forward */ | ||
| 4765 | if (next == fm->top) { | ||
| 4766 | size_t tsize = fm->topsize += psize; | ||
| 4767 | fm->top = p; | ||
| 4768 | p->head = tsize | PINUSE_BIT; | ||
| 4769 | if (p == fm->dv) { | ||
| 4770 | fm->dv = 0; | ||
| 4771 | fm->dvsize = 0; | ||
| 4772 | } | ||
| 4773 | if (should_trim(fm, tsize)) | ||
| 4774 | sys_trim(fm, 0); | ||
| 4775 | goto postaction; | ||
| 4776 | } | ||
| 4777 | else if (next == fm->dv) { | ||
| 4778 | size_t dsize = fm->dvsize += psize; | ||
| 4779 | fm->dv = p; | ||
| 4780 | set_size_and_pinuse_of_free_chunk(p, dsize); | ||
| 4781 | goto postaction; | ||
| 4782 | } | ||
| 4783 | else { | ||
| 4784 | size_t nsize = chunksize(next); | ||
| 4785 | psize += nsize; | ||
| 4786 | unlink_chunk(fm, next, nsize); | ||
| 4787 | set_size_and_pinuse_of_free_chunk(p, psize); | ||
| 4788 | if (p == fm->dv) { | ||
| 4789 | fm->dvsize = psize; | ||
| 4790 | goto postaction; | ||
| 4791 | } | ||
| 4792 | } | ||
| 4793 | } | ||
| 4794 | else | ||
| 4795 | set_free_with_pinuse(p, psize, next); | ||
| 4796 | |||
| 4797 | if (is_small(psize)) { | ||
| 4798 | insert_small_chunk(fm, p, psize); | ||
| 4799 | check_free_chunk(fm, p); | ||
| 4800 | } | ||
| 4801 | else { | ||
| 4802 | tchunkptr tp = (tchunkptr)p; | ||
| 4803 | insert_large_chunk(fm, tp, psize); | ||
| 4804 | check_free_chunk(fm, p); | ||
| 4805 | if (--fm->release_checks == 0) | ||
| 4806 | release_unused_segments(fm); | ||
| 4807 | } | ||
| 4808 | goto postaction; | ||
| 4809 | } | ||
| 4810 | } | ||
| 4811 | erroraction: | ||
| 4812 | USAGE_ERROR_ACTION(fm, p); | ||
| 4813 | postaction: | ||
| 4814 | POSTACTION(fm); | ||
| 4815 | } | ||
| 4816 | } | ||
| 4817 | #if !FOOTERS | ||
| 4818 | #undef fm | ||
| 4819 | #endif /* FOOTERS */ | ||
| 4820 | } | ||
| 4821 | |||
| 4822 | void* dlcalloc(size_t n_elements, size_t elem_size) { | ||
| 4823 | void* mem; | ||
| 4824 | size_t req = 0; | ||
| 4825 | if (n_elements != 0) { | ||
| 4826 | req = n_elements * elem_size; | ||
| 4827 | if (((n_elements | elem_size) & ~(size_t)0xffff) && | ||
| 4828 | (req / n_elements != elem_size)) | ||
| 4829 | req = MAX_SIZE_T; /* force downstream failure on overflow */ | ||
| 4830 | } | ||
| 4831 | mem = dlmalloc(req); | ||
| 4832 | if (mem != 0 && calloc_must_clear(mem2chunk(mem))) | ||
| 4833 | memset(mem, 0, req); | ||
| 4834 | return mem; | ||
| 4835 | } | ||
| 4836 | |||
| 4837 | #endif /* !ONLY_MSPACES */ | ||
| 4838 | |||
| 4839 | /* ------------ Internal support for realloc, memalign, etc -------------- */ | ||
| 4840 | |||
| 4841 | /* Try to realloc; only in-place unless can_move true */ | ||
| 4842 | static mchunkptr try_realloc_chunk(mstate m, mchunkptr p, size_t nb, | ||
| 4843 | int can_move) { | ||
| 4844 | mchunkptr newp = 0; | ||
| 4845 | size_t oldsize = chunksize(p); | ||
| 4846 | mchunkptr next = chunk_plus_offset(p, oldsize); | ||
| 4847 | if (RTCHECK(ok_address(m, p) && ok_inuse(p) && | ||
| 4848 | ok_next(p, next) && ok_pinuse(next))) { | ||
| 4849 | if (is_mmapped(p)) { | ||
| 4850 | newp = mmap_resize(m, p, nb, can_move); | ||
| 4851 | } | ||
| 4852 | else if (oldsize >= nb) { /* already big enough */ | ||
| 4853 | size_t rsize = oldsize - nb; | ||
| 4854 | if (rsize >= MIN_CHUNK_SIZE) { /* split off remainder */ | ||
| 4855 | mchunkptr r = chunk_plus_offset(p, nb); | ||
| 4856 | set_inuse(m, p, nb); | ||
| 4857 | set_inuse(m, r, rsize); | ||
| 4858 | dispose_chunk(m, r, rsize); | ||
| 4859 | } | ||
| 4860 | newp = p; | ||
| 4861 | } | ||
| 4862 | else if (next == m->top) { /* extend into top */ | ||
| 4863 | if (oldsize + m->topsize > nb) { | ||
| 4864 | size_t newsize = oldsize + m->topsize; | ||
| 4865 | size_t newtopsize = newsize - nb; | ||
| 4866 | mchunkptr newtop = chunk_plus_offset(p, nb); | ||
| 4867 | set_inuse(m, p, nb); | ||
| 4868 | newtop->head = newtopsize |PINUSE_BIT; | ||
| 4869 | m->top = newtop; | ||
| 4870 | m->topsize = newtopsize; | ||
| 4871 | newp = p; | ||
| 4872 | } | ||
| 4873 | } | ||
| 4874 | else if (next == m->dv) { /* extend into dv */ | ||
| 4875 | size_t dvs = m->dvsize; | ||
| 4876 | if (oldsize + dvs >= nb) { | ||
| 4877 | size_t dsize = oldsize + dvs - nb; | ||
| 4878 | if (dsize >= MIN_CHUNK_SIZE) { | ||
| 4879 | mchunkptr r = chunk_plus_offset(p, nb); | ||
| 4880 | mchunkptr n = chunk_plus_offset(r, dsize); | ||
| 4881 | set_inuse(m, p, nb); | ||
| 4882 | set_size_and_pinuse_of_free_chunk(r, dsize); | ||
| 4883 | clear_pinuse(n); | ||
| 4884 | m->dvsize = dsize; | ||
| 4885 | m->dv = r; | ||
| 4886 | } | ||
| 4887 | else { /* exhaust dv */ | ||
| 4888 | size_t newsize = oldsize + dvs; | ||
| 4889 | set_inuse(m, p, newsize); | ||
| 4890 | m->dvsize = 0; | ||
| 4891 | m->dv = 0; | ||
| 4892 | } | ||
| 4893 | newp = p; | ||
| 4894 | } | ||
| 4895 | } | ||
| 4896 | else if (!cinuse(next)) { /* extend into next free chunk */ | ||
| 4897 | size_t nextsize = chunksize(next); | ||
| 4898 | if (oldsize + nextsize >= nb) { | ||
| 4899 | size_t rsize = oldsize + nextsize - nb; | ||
| 4900 | unlink_chunk(m, next, nextsize); | ||
| 4901 | if (rsize < MIN_CHUNK_SIZE) { | ||
| 4902 | size_t newsize = oldsize + nextsize; | ||
| 4903 | set_inuse(m, p, newsize); | ||
| 4904 | } | ||
| 4905 | else { | ||
| 4906 | mchunkptr r = chunk_plus_offset(p, nb); | ||
| 4907 | set_inuse(m, p, nb); | ||
| 4908 | set_inuse(m, r, rsize); | ||
| 4909 | dispose_chunk(m, r, rsize); | ||
| 4910 | } | ||
| 4911 | newp = p; | ||
| 4912 | } | ||
| 4913 | } | ||
| 4914 | } | ||
| 4915 | else { | ||
| 4916 | USAGE_ERROR_ACTION(m, chunk2mem(p)); | ||
| 4917 | } | ||
| 4918 | return newp; | ||
| 4919 | } | ||
| 4920 | |||
| 4921 | static void* internal_memalign(mstate m, size_t alignment, size_t bytes) { | ||
| 4922 | void* mem = 0; | ||
| 4923 | if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ | ||
| 4924 | alignment = MIN_CHUNK_SIZE; | ||
| 4925 | if ((alignment & (alignment-SIZE_T_ONE)) != 0) {/* Ensure a power of 2 */ | ||
| 4926 | size_t a = MALLOC_ALIGNMENT << 1; | ||
| 4927 | while (a < alignment) a <<= 1; | ||
| 4928 | alignment = a; | ||
| 4929 | } | ||
| 4930 | if (bytes >= MAX_REQUEST - alignment) { | ||
| 4931 | if (m != 0) { /* Test isn't needed but avoids compiler warning */ | ||
| 4932 | MALLOC_FAILURE_ACTION; | ||
| 4933 | } | ||
| 4934 | } | ||
| 4935 | else { | ||
| 4936 | size_t nb = request2size(bytes); | ||
| 4937 | size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; | ||
| 4938 | mem = internal_malloc(m, req); | ||
| 4939 | if (mem != 0) { | ||
| 4940 | mchunkptr p = mem2chunk(mem); | ||
| 4941 | if (PREACTION(m)) | ||
| 4942 | return 0; | ||
| 4943 | if ((((size_t)(mem)) & (alignment - 1)) != 0) { /* misaligned */ | ||
| 4944 | /* | ||
| 4945 | Find an aligned spot inside chunk. Since we need to give | ||
| 4946 | back leading space in a chunk of at least MIN_CHUNK_SIZE, if | ||
| 4947 | the first calculation places us at a spot with less than | ||
| 4948 | MIN_CHUNK_SIZE leader, we can move to the next aligned spot. | ||
| 4949 | We've allocated enough total room so that this is always | ||
| 4950 | possible. | ||
| 4951 | */ | ||
| 4952 | char* br = (char*)mem2chunk((size_t)(((size_t)((char*)mem + alignment - | ||
| 4953 | SIZE_T_ONE)) & | ||
| 4954 | -alignment)); | ||
| 4955 | char* pos = ((size_t)(br - (char*)(p)) >= MIN_CHUNK_SIZE)? | ||
| 4956 | br : br+alignment; | ||
| 4957 | mchunkptr newp = (mchunkptr)pos; | ||
| 4958 | size_t leadsize = pos - (char*)(p); | ||
| 4959 | size_t newsize = chunksize(p) - leadsize; | ||
| 4960 | |||
| 4961 | if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */ | ||
| 4962 | newp->prev_foot = p->prev_foot + leadsize; | ||
| 4963 | newp->head = newsize; | ||
| 4964 | } | ||
| 4965 | else { /* Otherwise, give back leader, use the rest */ | ||
| 4966 | set_inuse(m, newp, newsize); | ||
| 4967 | set_inuse(m, p, leadsize); | ||
| 4968 | dispose_chunk(m, p, leadsize); | ||
| 4969 | } | ||
| 4970 | p = newp; | ||
| 4971 | } | ||
| 4972 | |||
| 4973 | /* Give back spare room at the end */ | ||
| 4974 | if (!is_mmapped(p)) { | ||
| 4975 | size_t size = chunksize(p); | ||
| 4976 | if (size > nb + MIN_CHUNK_SIZE) { | ||
| 4977 | size_t remainder_size = size - nb; | ||
| 4978 | mchunkptr remainder = chunk_plus_offset(p, nb); | ||
| 4979 | set_inuse(m, p, nb); | ||
| 4980 | set_inuse(m, remainder, remainder_size); | ||
| 4981 | dispose_chunk(m, remainder, remainder_size); | ||
| 4982 | } | ||
| 4983 | } | ||
| 4984 | |||
| 4985 | mem = chunk2mem(p); | ||
| 4986 | assert (chunksize(p) >= nb); | ||
| 4987 | assert(((size_t)mem & (alignment - 1)) == 0); | ||
| 4988 | check_inuse_chunk(m, p); | ||
| 4989 | POSTACTION(m); | ||
| 4990 | } | ||
| 4991 | } | ||
| 4992 | return mem; | ||
| 4993 | } | ||
| 4994 | |||
| 4995 | /* | ||
| 4996 | Common support for independent_X routines, handling | ||
| 4997 | all of the combinations that can result. | ||
| 4998 | The opts arg has: | ||
| 4999 | bit 0 set if all elements are same size (using sizes[0]) | ||
| 5000 | bit 1 set if elements should be zeroed | ||
| 5001 | */ | ||
| 5002 | static void** ialloc(mstate m, | ||
| 5003 | size_t n_elements, | ||
| 5004 | size_t* sizes, | ||
| 5005 | int opts, | ||
| 5006 | void* chunks[]) { | ||
| 5007 | |||
| 5008 | size_t element_size; /* chunksize of each element, if all same */ | ||
| 5009 | size_t contents_size; /* total size of elements */ | ||
| 5010 | size_t array_size; /* request size of pointer array */ | ||
| 5011 | void* mem; /* malloced aggregate space */ | ||
| 5012 | mchunkptr p; /* corresponding chunk */ | ||
| 5013 | size_t remainder_size; /* remaining bytes while splitting */ | ||
| 5014 | void** marray; /* either "chunks" or malloced ptr array */ | ||
| 5015 | mchunkptr array_chunk; /* chunk for malloced ptr array */ | ||
| 5016 | flag_t was_enabled; /* to disable mmap */ | ||
| 5017 | size_t size; | ||
| 5018 | size_t i; | ||
| 5019 | |||
| 5020 | ensure_initialization(); | ||
| 5021 | /* compute array length, if needed */ | ||
| 5022 | if (chunks != 0) { | ||
| 5023 | if (n_elements == 0) | ||
| 5024 | return chunks; /* nothing to do */ | ||
| 5025 | marray = chunks; | ||
| 5026 | array_size = 0; | ||
| 5027 | } | ||
| 5028 | else { | ||
| 5029 | /* if empty req, must still return chunk representing empty array */ | ||
| 5030 | if (n_elements == 0) | ||
| 5031 | return (void**)internal_malloc(m, 0); | ||
| 5032 | marray = 0; | ||
| 5033 | array_size = request2size(n_elements * (sizeof(void*))); | ||
| 5034 | } | ||
| 5035 | |||
| 5036 | /* compute total element size */ | ||
| 5037 | if (opts & 0x1) { /* all-same-size */ | ||
| 5038 | element_size = request2size(*sizes); | ||
| 5039 | contents_size = n_elements * element_size; | ||
| 5040 | } | ||
| 5041 | else { /* add up all the sizes */ | ||
| 5042 | element_size = 0; | ||
| 5043 | contents_size = 0; | ||
| 5044 | for (i = 0; i != n_elements; ++i) | ||
| 5045 | contents_size += request2size(sizes[i]); | ||
| 5046 | } | ||
| 5047 | |||
| 5048 | size = contents_size + array_size; | ||
| 5049 | |||
| 5050 | /* | ||
| 5051 | Allocate the aggregate chunk. First disable direct-mmapping so | ||
| 5052 | malloc won't use it, since we would not be able to later | ||
| 5053 | free/realloc space internal to a segregated mmap region. | ||
| 5054 | */ | ||
| 5055 | was_enabled = use_mmap(m); | ||
| 5056 | disable_mmap(m); | ||
| 5057 | mem = internal_malloc(m, size - CHUNK_OVERHEAD); | ||
| 5058 | if (was_enabled) | ||
| 5059 | enable_mmap(m); | ||
| 5060 | if (mem == 0) | ||
| 5061 | return 0; | ||
| 5062 | |||
| 5063 | if (PREACTION(m)) return 0; | ||
| 5064 | p = mem2chunk(mem); | ||
| 5065 | remainder_size = chunksize(p); | ||
| 5066 | |||
| 5067 | assert(!is_mmapped(p)); | ||
| 5068 | |||
| 5069 | if (opts & 0x2) { /* optionally clear the elements */ | ||
| 5070 | memset((size_t*)mem, 0, remainder_size - SIZE_T_SIZE - array_size); | ||
| 5071 | } | ||
| 5072 | |||
| 5073 | /* If not provided, allocate the pointer array as final part of chunk */ | ||
| 5074 | if (marray == 0) { | ||
| 5075 | size_t array_chunk_size; | ||
| 5076 | array_chunk = chunk_plus_offset(p, contents_size); | ||
| 5077 | array_chunk_size = remainder_size - contents_size; | ||
| 5078 | marray = (void**) (chunk2mem(array_chunk)); | ||
| 5079 | set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size); | ||
| 5080 | remainder_size = contents_size; | ||
| 5081 | } | ||
| 5082 | |||
| 5083 | /* split out elements */ | ||
| 5084 | for (i = 0; ; ++i) { | ||
| 5085 | marray[i] = chunk2mem(p); | ||
| 5086 | if (i != n_elements-1) { | ||
| 5087 | if (element_size != 0) | ||
| 5088 | size = element_size; | ||
| 5089 | else | ||
| 5090 | size = request2size(sizes[i]); | ||
| 5091 | remainder_size -= size; | ||
| 5092 | set_size_and_pinuse_of_inuse_chunk(m, p, size); | ||
| 5093 | p = chunk_plus_offset(p, size); | ||
| 5094 | } | ||
| 5095 | else { /* the final element absorbs any overallocation slop */ | ||
| 5096 | set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size); | ||
| 5097 | break; | ||
| 5098 | } | ||
| 5099 | } | ||
| 5100 | |||
| 5101 | #if DEBUG | ||
| 5102 | if (marray != chunks) { | ||
| 5103 | /* final element must have exactly exhausted chunk */ | ||
| 5104 | if (element_size != 0) { | ||
| 5105 | assert(remainder_size == element_size); | ||
| 5106 | } | ||
| 5107 | else { | ||
| 5108 | assert(remainder_size == request2size(sizes[i])); | ||
| 5109 | } | ||
| 5110 | check_inuse_chunk(m, mem2chunk(marray)); | ||
| 5111 | } | ||
| 5112 | for (i = 0; i != n_elements; ++i) | ||
| 5113 | check_inuse_chunk(m, mem2chunk(marray[i])); | ||
| 5114 | |||
| 5115 | #endif /* DEBUG */ | ||
| 5116 | |||
| 5117 | POSTACTION(m); | ||
| 5118 | return marray; | ||
| 5119 | } | ||
| 5120 | |||
| 5121 | /* Try to free all pointers in the given array. | ||
| 5122 | Note: this could be made faster, by delaying consolidation, | ||
| 5123 | at the price of disabling some user integrity checks, We | ||
| 5124 | still optimize some consolidations by combining adjacent | ||
| 5125 | chunks before freeing, which will occur often if allocated | ||
| 5126 | with ialloc or the array is sorted. | ||
| 5127 | */ | ||
| 5128 | static size_t internal_bulk_free(mstate m, void* array[], size_t nelem) { | ||
| 5129 | size_t unfreed = 0; | ||
| 5130 | if (!PREACTION(m)) { | ||
| 5131 | void** a; | ||
| 5132 | void** fence = &(array[nelem]); | ||
| 5133 | for (a = array; a != fence; ++a) { | ||
| 5134 | void* mem = *a; | ||
| 5135 | if (mem != 0) { | ||
| 5136 | mchunkptr p = mem2chunk(mem); | ||
| 5137 | size_t psize = chunksize(p); | ||
| 5138 | #if FOOTERS | ||
| 5139 | if (get_mstate_for(p) != m) { | ||
| 5140 | ++unfreed; | ||
| 5141 | continue; | ||
| 5142 | } | ||
| 5143 | #endif | ||
| 5144 | check_inuse_chunk(m, p); | ||
| 5145 | *a = 0; | ||
| 5146 | if (RTCHECK(ok_address(m, p) && ok_inuse(p))) { | ||
| 5147 | void ** b = a + 1; /* try to merge with next chunk */ | ||
| 5148 | mchunkptr next = next_chunk(p); | ||
| 5149 | if (b != fence && *b == chunk2mem(next)) { | ||
| 5150 | size_t newsize = chunksize(next) + psize; | ||
| 5151 | set_inuse(m, p, newsize); | ||
| 5152 | *b = chunk2mem(p); | ||
| 5153 | } | ||
| 5154 | else | ||
| 5155 | dispose_chunk(m, p, psize); | ||
| 5156 | } | ||
| 5157 | else { | ||
| 5158 | CORRUPTION_ERROR_ACTION(m); | ||
| 5159 | break; | ||
| 5160 | } | ||
| 5161 | } | ||
| 5162 | } | ||
| 5163 | if (should_trim(m, m->topsize)) | ||
| 5164 | sys_trim(m, 0); | ||
| 5165 | POSTACTION(m); | ||
| 5166 | } | ||
| 5167 | return unfreed; | ||
| 5168 | } | ||
| 5169 | |||
| 5170 | /* Traversal */ | ||
| 5171 | #if MALLOC_INSPECT_ALL | ||
| 5172 | static void internal_inspect_all(mstate m, | ||
| 5173 | void(*handler)(void *start, | ||
| 5174 | void *end, | ||
| 5175 | size_t used_bytes, | ||
| 5176 | void* callback_arg), | ||
| 5177 | void* arg) { | ||
| 5178 | if (is_initialized(m)) { | ||
| 5179 | mchunkptr top = m->top; | ||
| 5180 | msegmentptr s; | ||
| 5181 | for (s = &m->seg; s != 0; s = s->next) { | ||
| 5182 | mchunkptr q = align_as_chunk(s->base); | ||
| 5183 | while (segment_holds(s, q) && q->head != FENCEPOST_HEAD) { | ||
| 5184 | mchunkptr next = next_chunk(q); | ||
| 5185 | size_t sz = chunksize(q); | ||
| 5186 | size_t used; | ||
| 5187 | void* start; | ||
| 5188 | if (is_inuse(q)) { | ||
| 5189 | used = sz - CHUNK_OVERHEAD; /* must not be mmapped */ | ||
| 5190 | start = chunk2mem(q); | ||
| 5191 | } | ||
| 5192 | else { | ||
| 5193 | used = 0; | ||
| 5194 | if (is_small(sz)) { /* offset by possible bookkeeping */ | ||
| 5195 | start = (void*)((char*)q + sizeof(struct malloc_chunk)); | ||
| 5196 | } | ||
| 5197 | else { | ||
| 5198 | start = (void*)((char*)q + sizeof(struct malloc_tree_chunk)); | ||
| 5199 | } | ||
| 5200 | } | ||
| 5201 | if (start < (void*)next) /* skip if all space is bookkeeping */ | ||
| 5202 | handler(start, next, used, arg); | ||
| 5203 | if (q == top) | ||
| 5204 | break; | ||
| 5205 | q = next; | ||
| 5206 | } | ||
| 5207 | } | ||
| 5208 | } | ||
| 5209 | } | ||
| 5210 | #endif /* MALLOC_INSPECT_ALL */ | ||
| 5211 | |||
| 5212 | #ifdef __wasilibc_unmodified_upstream // Define a function that initializes the initial state of dlmalloc. | ||
| 5213 | #else | ||
| 5214 | /* ------------------ Exported try_init_allocator -------------------- */ | ||
| 5215 | |||
| 5216 | /* Symbol marking the end of data, bss and explicit stack, provided by wasm-ld. */ | ||
| 5217 | extern unsigned char __heap_base; | ||
| 5218 | |||
| 5219 | /* Initialize the initial state of dlmalloc to be able to use free memory between __heap_base and initial. */ | ||
| 5220 | static void try_init_allocator(void) { | ||
| 5221 | /* Check that it is a first-time initialization. */ | ||
| 5222 | assert(!is_initialized(gm)); | ||
| 5223 | |||
| 5224 | char *base = (char *)&__heap_base; | ||
| 5225 | /* Calls sbrk(0) that returns the initial memory position. */ | ||
| 5226 | char *init = (char *)CALL_MORECORE(0); | ||
| 5227 | int initial_heap_size = init - base; | ||
| 5228 | |||
| 5229 | /* Check that initial heap is long enough to serve a minimal allocation request. */ | ||
| 5230 | if (initial_heap_size <= MIN_CHUNK_SIZE + TOP_FOOT_SIZE + MALLOC_ALIGNMENT) { | ||
| 5231 | return; | ||
| 5232 | } | ||
| 5233 | |||
| 5234 | /* Initialize mstate. */ | ||
| 5235 | ensure_initialization(); | ||
| 5236 | |||
| 5237 | /* Initialize the dlmalloc internal state. */ | ||
| 5238 | gm->least_addr = base; | ||
| 5239 | gm->seg.base = base; | ||
| 5240 | gm->seg.size = initial_heap_size; | ||
| 5241 | gm->magic = mparams.magic; | ||
| 5242 | gm->release_checks = MAX_RELEASE_CHECK_RATE; | ||
| 5243 | init_bins(gm); | ||
| 5244 | init_top(gm, (mchunkptr)base, initial_heap_size - TOP_FOOT_SIZE); | ||
| 5245 | } | ||
| 5246 | #endif | ||
| 5247 | |||
| 5248 | /* ------------------ Exported realloc, memalign, etc -------------------- */ | ||
| 5249 | |||
| 5250 | #if !ONLY_MSPACES | ||
| 5251 | |||
| 5252 | void* dlrealloc(void* oldmem, size_t bytes) { | ||
| 5253 | void* mem = 0; | ||
| 5254 | if (oldmem == 0) { | ||
| 5255 | mem = dlmalloc(bytes); | ||
| 5256 | } | ||
| 5257 | else if (bytes >= MAX_REQUEST) { | ||
| 5258 | MALLOC_FAILURE_ACTION; | ||
| 5259 | } | ||
| 5260 | #ifdef REALLOC_ZERO_BYTES_FREES | ||
| 5261 | else if (bytes == 0) { | ||
| 5262 | dlfree(oldmem); | ||
| 5263 | } | ||
| 5264 | #endif /* REALLOC_ZERO_BYTES_FREES */ | ||
| 5265 | else { | ||
| 5266 | size_t nb = request2size(bytes); | ||
| 5267 | mchunkptr oldp = mem2chunk(oldmem); | ||
| 5268 | #if ! FOOTERS | ||
| 5269 | mstate m = gm; | ||
| 5270 | #else /* FOOTERS */ | ||
| 5271 | mstate m = get_mstate_for(oldp); | ||
| 5272 | if (!ok_magic(m)) { | ||
| 5273 | USAGE_ERROR_ACTION(m, oldmem); | ||
| 5274 | return 0; | ||
| 5275 | } | ||
| 5276 | #endif /* FOOTERS */ | ||
| 5277 | if (!PREACTION(m)) { | ||
| 5278 | mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1); | ||
| 5279 | POSTACTION(m); | ||
| 5280 | if (newp != 0) { | ||
| 5281 | check_inuse_chunk(m, newp); | ||
| 5282 | mem = chunk2mem(newp); | ||
| 5283 | } | ||
| 5284 | else { | ||
| 5285 | mem = internal_malloc(m, bytes); | ||
| 5286 | if (mem != 0) { | ||
| 5287 | size_t oc = chunksize(oldp) - overhead_for(oldp); | ||
| 5288 | memcpy(mem, oldmem, (oc < bytes)? oc : bytes); | ||
| 5289 | internal_free(m, oldmem); | ||
| 5290 | } | ||
| 5291 | } | ||
| 5292 | } | ||
| 5293 | } | ||
| 5294 | return mem; | ||
| 5295 | } | ||
| 5296 | |||
| 5297 | void* dlrealloc_in_place(void* oldmem, size_t bytes) { | ||
| 5298 | void* mem = 0; | ||
| 5299 | if (oldmem != 0) { | ||
| 5300 | if (bytes >= MAX_REQUEST) { | ||
| 5301 | MALLOC_FAILURE_ACTION; | ||
| 5302 | } | ||
| 5303 | else { | ||
| 5304 | size_t nb = request2size(bytes); | ||
| 5305 | mchunkptr oldp = mem2chunk(oldmem); | ||
| 5306 | #if ! FOOTERS | ||
| 5307 | mstate m = gm; | ||
| 5308 | #else /* FOOTERS */ | ||
| 5309 | mstate m = get_mstate_for(oldp); | ||
| 5310 | if (!ok_magic(m)) { | ||
| 5311 | USAGE_ERROR_ACTION(m, oldmem); | ||
| 5312 | return 0; | ||
| 5313 | } | ||
| 5314 | #endif /* FOOTERS */ | ||
| 5315 | if (!PREACTION(m)) { | ||
| 5316 | mchunkptr newp = try_realloc_chunk(m, oldp, nb, 0); | ||
| 5317 | POSTACTION(m); | ||
| 5318 | if (newp == oldp) { | ||
| 5319 | check_inuse_chunk(m, newp); | ||
| 5320 | mem = oldmem; | ||
| 5321 | } | ||
| 5322 | } | ||
| 5323 | } | ||
| 5324 | } | ||
| 5325 | return mem; | ||
| 5326 | } | ||
| 5327 | |||
| 5328 | void* dlmemalign(size_t alignment, size_t bytes) { | ||
| 5329 | if (alignment <= MALLOC_ALIGNMENT) { | ||
| 5330 | return dlmalloc(bytes); | ||
| 5331 | } | ||
| 5332 | return internal_memalign(gm, alignment, bytes); | ||
| 5333 | } | ||
| 5334 | |||
| 5335 | int dlposix_memalign(void** pp, size_t alignment, size_t bytes) { | ||
| 5336 | void* mem = 0; | ||
| 5337 | if (alignment == MALLOC_ALIGNMENT) | ||
| 5338 | mem = dlmalloc(bytes); | ||
| 5339 | else { | ||
| 5340 | size_t d = alignment / sizeof(void*); | ||
| 5341 | size_t r = alignment % sizeof(void*); | ||
| 5342 | if (r != 0 || d == 0 || (d & (d-SIZE_T_ONE)) != 0) | ||
| 5343 | return EINVAL; | ||
| 5344 | else if (bytes <= MAX_REQUEST - alignment) { | ||
| 5345 | if (alignment < MIN_CHUNK_SIZE) | ||
| 5346 | alignment = MIN_CHUNK_SIZE; | ||
| 5347 | mem = internal_memalign(gm, alignment, bytes); | ||
| 5348 | } | ||
| 5349 | } | ||
| 5350 | if (mem == 0) | ||
| 5351 | return ENOMEM; | ||
| 5352 | else { | ||
| 5353 | *pp = mem; | ||
| 5354 | return 0; | ||
| 5355 | } | ||
| 5356 | } | ||
| 5357 | |||
| 5358 | void* dlvalloc(size_t bytes) { | ||
| 5359 | size_t pagesz; | ||
| 5360 | ensure_initialization(); | ||
| 5361 | pagesz = mparams.page_size; | ||
| 5362 | return dlmemalign(pagesz, bytes); | ||
| 5363 | } | ||
| 5364 | |||
| 5365 | void* dlpvalloc(size_t bytes) { | ||
| 5366 | size_t pagesz; | ||
| 5367 | ensure_initialization(); | ||
| 5368 | pagesz = mparams.page_size; | ||
| 5369 | return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); | ||
| 5370 | } | ||
| 5371 | |||
| 5372 | void** dlindependent_calloc(size_t n_elements, size_t elem_size, | ||
| 5373 | void* chunks[]) { | ||
| 5374 | size_t sz = elem_size; /* serves as 1-element array */ | ||
| 5375 | return ialloc(gm, n_elements, &sz, 3, chunks); | ||
| 5376 | } | ||
| 5377 | |||
| 5378 | void** dlindependent_comalloc(size_t n_elements, size_t sizes[], | ||
| 5379 | void* chunks[]) { | ||
| 5380 | return ialloc(gm, n_elements, sizes, 0, chunks); | ||
| 5381 | } | ||
| 5382 | |||
| 5383 | size_t dlbulk_free(void* array[], size_t nelem) { | ||
| 5384 | return internal_bulk_free(gm, array, nelem); | ||
| 5385 | } | ||
| 5386 | |||
| 5387 | #if MALLOC_INSPECT_ALL | ||
| 5388 | void dlmalloc_inspect_all(void(*handler)(void *start, | ||
| 5389 | void *end, | ||
| 5390 | size_t used_bytes, | ||
| 5391 | void* callback_arg), | ||
| 5392 | void* arg) { | ||
| 5393 | ensure_initialization(); | ||
| 5394 | if (!PREACTION(gm)) { | ||
| 5395 | internal_inspect_all(gm, handler, arg); | ||
| 5396 | POSTACTION(gm); | ||
| 5397 | } | ||
| 5398 | } | ||
| 5399 | #endif /* MALLOC_INSPECT_ALL */ | ||
| 5400 | |||
| 5401 | int dlmalloc_trim(size_t pad) { | ||
| 5402 | int result = 0; | ||
| 5403 | ensure_initialization(); | ||
| 5404 | if (!PREACTION(gm)) { | ||
| 5405 | result = sys_trim(gm, pad); | ||
| 5406 | POSTACTION(gm); | ||
| 5407 | } | ||
| 5408 | return result; | ||
| 5409 | } | ||
| 5410 | |||
| 5411 | size_t dlmalloc_footprint(void) { | ||
| 5412 | return gm->footprint; | ||
| 5413 | } | ||
| 5414 | |||
| 5415 | size_t dlmalloc_max_footprint(void) { | ||
| 5416 | return gm->max_footprint; | ||
| 5417 | } | ||
| 5418 | |||
| 5419 | size_t dlmalloc_footprint_limit(void) { | ||
| 5420 | size_t maf = gm->footprint_limit; | ||
| 5421 | return maf == 0 ? MAX_SIZE_T : maf; | ||
| 5422 | } | ||
| 5423 | |||
| 5424 | size_t dlmalloc_set_footprint_limit(size_t bytes) { | ||
| 5425 | size_t result; /* invert sense of 0 */ | ||
| 5426 | if (bytes == 0) | ||
| 5427 | result = granularity_align(1); /* Use minimal size */ | ||
| 5428 | if (bytes == MAX_SIZE_T) | ||
| 5429 | result = 0; /* disable */ | ||
| 5430 | else | ||
| 5431 | result = granularity_align(bytes); | ||
| 5432 | return gm->footprint_limit = result; | ||
| 5433 | } | ||
| 5434 | |||
| 5435 | #if !NO_MALLINFO | ||
| 5436 | struct mallinfo dlmallinfo(void) { | ||
| 5437 | return internal_mallinfo(gm); | ||
| 5438 | } | ||
| 5439 | #endif /* NO_MALLINFO */ | ||
| 5440 | |||
| 5441 | #if !NO_MALLOC_STATS | ||
| 5442 | void dlmalloc_stats() { | ||
| 5443 | internal_malloc_stats(gm); | ||
| 5444 | } | ||
| 5445 | #endif /* NO_MALLOC_STATS */ | ||
| 5446 | |||
| 5447 | int dlmallopt(int param_number, int value) { | ||
| 5448 | return change_mparam(param_number, value); | ||
| 5449 | } | ||
| 5450 | |||
| 5451 | size_t dlmalloc_usable_size(void* mem) { | ||
| 5452 | if (mem != 0) { | ||
| 5453 | mchunkptr p = mem2chunk(mem); | ||
| 5454 | if (is_inuse(p)) | ||
| 5455 | return chunksize(p) - overhead_for(p); | ||
| 5456 | } | ||
| 5457 | return 0; | ||
| 5458 | } | ||
| 5459 | |||
| 5460 | #endif /* !ONLY_MSPACES */ | ||
| 5461 | |||
| 5462 | /* ----------------------------- user mspaces ---------------------------- */ | ||
| 5463 | |||
| 5464 | #if MSPACES | ||
| 5465 | |||
| 5466 | static mstate init_user_mstate(char* tbase, size_t tsize) { | ||
| 5467 | size_t msize = pad_request(sizeof(struct malloc_state)); | ||
| 5468 | mchunkptr mn; | ||
| 5469 | mchunkptr msp = align_as_chunk(tbase); | ||
| 5470 | mstate m = (mstate)(chunk2mem(msp)); | ||
| 5471 | memset(m, 0, msize); | ||
| 5472 | (void)INITIAL_LOCK(&m->mutex); | ||
| 5473 | msp->head = (msize|INUSE_BITS); | ||
| 5474 | m->seg.base = m->least_addr = tbase; | ||
| 5475 | m->seg.size = m->footprint = m->max_footprint = tsize; | ||
| 5476 | m->magic = mparams.magic; | ||
| 5477 | m->release_checks = MAX_RELEASE_CHECK_RATE; | ||
| 5478 | m->mflags = mparams.default_mflags; | ||
| 5479 | m->extp = 0; | ||
| 5480 | m->exts = 0; | ||
| 5481 | disable_contiguous(m); | ||
| 5482 | init_bins(m); | ||
| 5483 | mn = next_chunk(mem2chunk(m)); | ||
| 5484 | init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) - TOP_FOOT_SIZE); | ||
| 5485 | check_top_chunk(m, m->top); | ||
| 5486 | return m; | ||
| 5487 | } | ||
| 5488 | |||
| 5489 | mspace create_mspace(size_t capacity, int locked) { | ||
| 5490 | mstate m = 0; | ||
| 5491 | size_t msize; | ||
| 5492 | ensure_initialization(); | ||
| 5493 | msize = pad_request(sizeof(struct malloc_state)); | ||
| 5494 | if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { | ||
| 5495 | size_t rs = ((capacity == 0)? mparams.granularity : | ||
| 5496 | (capacity + TOP_FOOT_SIZE + msize)); | ||
| 5497 | size_t tsize = granularity_align(rs); | ||
| 5498 | char* tbase = (char*)(CALL_MMAP(tsize)); | ||
| 5499 | if (tbase != CMFAIL) { | ||
| 5500 | m = init_user_mstate(tbase, tsize); | ||
| 5501 | m->seg.sflags = USE_MMAP_BIT; | ||
| 5502 | set_lock(m, locked); | ||
| 5503 | } | ||
| 5504 | } | ||
| 5505 | return (mspace)m; | ||
| 5506 | } | ||
| 5507 | |||
| 5508 | mspace create_mspace_with_base(void* base, size_t capacity, int locked) { | ||
| 5509 | mstate m = 0; | ||
| 5510 | size_t msize; | ||
| 5511 | ensure_initialization(); | ||
| 5512 | msize = pad_request(sizeof(struct malloc_state)); | ||
| 5513 | if (capacity > msize + TOP_FOOT_SIZE && | ||
| 5514 | capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { | ||
| 5515 | m = init_user_mstate((char*)base, capacity); | ||
| 5516 | m->seg.sflags = EXTERN_BIT; | ||
| 5517 | set_lock(m, locked); | ||
| 5518 | } | ||
| 5519 | return (mspace)m; | ||
| 5520 | } | ||
| 5521 | |||
| 5522 | int mspace_track_large_chunks(mspace msp, int enable) { | ||
| 5523 | int ret = 0; | ||
| 5524 | mstate ms = (mstate)msp; | ||
| 5525 | if (!PREACTION(ms)) { | ||
| 5526 | if (!use_mmap(ms)) { | ||
| 5527 | ret = 1; | ||
| 5528 | } | ||
| 5529 | if (!enable) { | ||
| 5530 | enable_mmap(ms); | ||
| 5531 | } else { | ||
| 5532 | disable_mmap(ms); | ||
| 5533 | } | ||
| 5534 | POSTACTION(ms); | ||
| 5535 | } | ||
| 5536 | return ret; | ||
| 5537 | } | ||
| 5538 | |||
| 5539 | size_t destroy_mspace(mspace msp) { | ||
| 5540 | size_t freed = 0; | ||
| 5541 | mstate ms = (mstate)msp; | ||
| 5542 | if (ok_magic(ms)) { | ||
| 5543 | msegmentptr sp = &ms->seg; | ||
| 5544 | (void)DESTROY_LOCK(&ms->mutex); /* destroy before unmapped */ | ||
| 5545 | while (sp != 0) { | ||
| 5546 | char* base = sp->base; | ||
| 5547 | size_t size = sp->size; | ||
| 5548 | flag_t flag = sp->sflags; | ||
| 5549 | (void)base; /* placate people compiling -Wunused-variable */ | ||
| 5550 | sp = sp->next; | ||
| 5551 | if ((flag & USE_MMAP_BIT) && !(flag & EXTERN_BIT) && | ||
| 5552 | CALL_MUNMAP(base, size) == 0) | ||
| 5553 | freed += size; | ||
| 5554 | } | ||
| 5555 | } | ||
| 5556 | else { | ||
| 5557 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5558 | } | ||
| 5559 | return freed; | ||
| 5560 | } | ||
| 5561 | |||
| 5562 | /* | ||
| 5563 | mspace versions of routines are near-clones of the global | ||
| 5564 | versions. This is not so nice but better than the alternatives. | ||
| 5565 | */ | ||
| 5566 | |||
| 5567 | void* mspace_malloc(mspace msp, size_t bytes) { | ||
| 5568 | mstate ms = (mstate)msp; | ||
| 5569 | if (!ok_magic(ms)) { | ||
| 5570 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5571 | return 0; | ||
| 5572 | } | ||
| 5573 | if (!PREACTION(ms)) { | ||
| 5574 | void* mem; | ||
| 5575 | size_t nb; | ||
| 5576 | if (bytes <= MAX_SMALL_REQUEST) { | ||
| 5577 | bindex_t idx; | ||
| 5578 | binmap_t smallbits; | ||
| 5579 | nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); | ||
| 5580 | idx = small_index(nb); | ||
| 5581 | smallbits = ms->smallmap >> idx; | ||
| 5582 | |||
| 5583 | if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ | ||
| 5584 | mchunkptr b, p; | ||
| 5585 | idx += ~smallbits & 1; /* Uses next bin if idx empty */ | ||
| 5586 | b = smallbin_at(ms, idx); | ||
| 5587 | p = b->fd; | ||
| 5588 | assert(chunksize(p) == small_index2size(idx)); | ||
| 5589 | unlink_first_small_chunk(ms, b, p, idx); | ||
| 5590 | set_inuse_and_pinuse(ms, p, small_index2size(idx)); | ||
| 5591 | mem = chunk2mem(p); | ||
| 5592 | check_malloced_chunk(ms, mem, nb); | ||
| 5593 | goto postaction; | ||
| 5594 | } | ||
| 5595 | |||
| 5596 | else if (nb > ms->dvsize) { | ||
| 5597 | if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ | ||
| 5598 | mchunkptr b, p, r; | ||
| 5599 | size_t rsize; | ||
| 5600 | bindex_t i; | ||
| 5601 | binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); | ||
| 5602 | binmap_t leastbit = least_bit(leftbits); | ||
| 5603 | compute_bit2idx(leastbit, i); | ||
| 5604 | b = smallbin_at(ms, i); | ||
| 5605 | p = b->fd; | ||
| 5606 | assert(chunksize(p) == small_index2size(i)); | ||
| 5607 | unlink_first_small_chunk(ms, b, p, i); | ||
| 5608 | rsize = small_index2size(i) - nb; | ||
| 5609 | /* Fit here cannot be remainderless if 4byte sizes */ | ||
| 5610 | if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) | ||
| 5611 | set_inuse_and_pinuse(ms, p, small_index2size(i)); | ||
| 5612 | else { | ||
| 5613 | set_size_and_pinuse_of_inuse_chunk(ms, p, nb); | ||
| 5614 | r = chunk_plus_offset(p, nb); | ||
| 5615 | set_size_and_pinuse_of_free_chunk(r, rsize); | ||
| 5616 | replace_dv(ms, r, rsize); | ||
| 5617 | } | ||
| 5618 | mem = chunk2mem(p); | ||
| 5619 | check_malloced_chunk(ms, mem, nb); | ||
| 5620 | goto postaction; | ||
| 5621 | } | ||
| 5622 | |||
| 5623 | else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { | ||
| 5624 | check_malloced_chunk(ms, mem, nb); | ||
| 5625 | goto postaction; | ||
| 5626 | } | ||
| 5627 | } | ||
| 5628 | } | ||
| 5629 | else if (bytes >= MAX_REQUEST) | ||
| 5630 | nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ | ||
| 5631 | else { | ||
| 5632 | nb = pad_request(bytes); | ||
| 5633 | if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { | ||
| 5634 | check_malloced_chunk(ms, mem, nb); | ||
| 5635 | goto postaction; | ||
| 5636 | } | ||
| 5637 | } | ||
| 5638 | |||
| 5639 | if (nb <= ms->dvsize) { | ||
| 5640 | size_t rsize = ms->dvsize - nb; | ||
| 5641 | mchunkptr p = ms->dv; | ||
| 5642 | if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ | ||
| 5643 | mchunkptr r = ms->dv = chunk_plus_offset(p, nb); | ||
| 5644 | ms->dvsize = rsize; | ||
| 5645 | set_size_and_pinuse_of_free_chunk(r, rsize); | ||
| 5646 | set_size_and_pinuse_of_inuse_chunk(ms, p, nb); | ||
| 5647 | } | ||
| 5648 | else { /* exhaust dv */ | ||
| 5649 | size_t dvs = ms->dvsize; | ||
| 5650 | ms->dvsize = 0; | ||
| 5651 | ms->dv = 0; | ||
| 5652 | set_inuse_and_pinuse(ms, p, dvs); | ||
| 5653 | } | ||
| 5654 | mem = chunk2mem(p); | ||
| 5655 | check_malloced_chunk(ms, mem, nb); | ||
| 5656 | goto postaction; | ||
| 5657 | } | ||
| 5658 | |||
| 5659 | else if (nb < ms->topsize) { /* Split top */ | ||
| 5660 | size_t rsize = ms->topsize -= nb; | ||
| 5661 | mchunkptr p = ms->top; | ||
| 5662 | mchunkptr r = ms->top = chunk_plus_offset(p, nb); | ||
| 5663 | r->head = rsize | PINUSE_BIT; | ||
| 5664 | set_size_and_pinuse_of_inuse_chunk(ms, p, nb); | ||
| 5665 | mem = chunk2mem(p); | ||
| 5666 | check_top_chunk(ms, ms->top); | ||
| 5667 | check_malloced_chunk(ms, mem, nb); | ||
| 5668 | goto postaction; | ||
| 5669 | } | ||
| 5670 | |||
| 5671 | mem = sys_alloc(ms, nb); | ||
| 5672 | |||
| 5673 | postaction: | ||
| 5674 | POSTACTION(ms); | ||
| 5675 | return mem; | ||
| 5676 | } | ||
| 5677 | |||
| 5678 | return 0; | ||
| 5679 | } | ||
| 5680 | |||
| 5681 | void mspace_free(mspace msp, void* mem) { | ||
| 5682 | if (mem != 0) { | ||
| 5683 | mchunkptr p = mem2chunk(mem); | ||
| 5684 | #if FOOTERS | ||
| 5685 | mstate fm = get_mstate_for(p); | ||
| 5686 | (void)msp; /* placate people compiling -Wunused */ | ||
| 5687 | #else /* FOOTERS */ | ||
| 5688 | mstate fm = (mstate)msp; | ||
| 5689 | #endif /* FOOTERS */ | ||
| 5690 | if (!ok_magic(fm)) { | ||
| 5691 | USAGE_ERROR_ACTION(fm, p); | ||
| 5692 | return; | ||
| 5693 | } | ||
| 5694 | if (!PREACTION(fm)) { | ||
| 5695 | check_inuse_chunk(fm, p); | ||
| 5696 | if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) { | ||
| 5697 | size_t psize = chunksize(p); | ||
| 5698 | mchunkptr next = chunk_plus_offset(p, psize); | ||
| 5699 | if (!pinuse(p)) { | ||
| 5700 | size_t prevsize = p->prev_foot; | ||
| 5701 | if (is_mmapped(p)) { | ||
| 5702 | psize += prevsize + MMAP_FOOT_PAD; | ||
| 5703 | if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) | ||
| 5704 | fm->footprint -= psize; | ||
| 5705 | goto postaction; | ||
| 5706 | } | ||
| 5707 | else { | ||
| 5708 | mchunkptr prev = chunk_minus_offset(p, prevsize); | ||
| 5709 | psize += prevsize; | ||
| 5710 | p = prev; | ||
| 5711 | if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ | ||
| 5712 | if (p != fm->dv) { | ||
| 5713 | unlink_chunk(fm, p, prevsize); | ||
| 5714 | } | ||
| 5715 | else if ((next->head & INUSE_BITS) == INUSE_BITS) { | ||
| 5716 | fm->dvsize = psize; | ||
| 5717 | set_free_with_pinuse(p, psize, next); | ||
| 5718 | goto postaction; | ||
| 5719 | } | ||
| 5720 | } | ||
| 5721 | else | ||
| 5722 | goto erroraction; | ||
| 5723 | } | ||
| 5724 | } | ||
| 5725 | |||
| 5726 | if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { | ||
| 5727 | if (!cinuse(next)) { /* consolidate forward */ | ||
| 5728 | if (next == fm->top) { | ||
| 5729 | size_t tsize = fm->topsize += psize; | ||
| 5730 | fm->top = p; | ||
| 5731 | p->head = tsize | PINUSE_BIT; | ||
| 5732 | if (p == fm->dv) { | ||
| 5733 | fm->dv = 0; | ||
| 5734 | fm->dvsize = 0; | ||
| 5735 | } | ||
| 5736 | if (should_trim(fm, tsize)) | ||
| 5737 | sys_trim(fm, 0); | ||
| 5738 | goto postaction; | ||
| 5739 | } | ||
| 5740 | else if (next == fm->dv) { | ||
| 5741 | size_t dsize = fm->dvsize += psize; | ||
| 5742 | fm->dv = p; | ||
| 5743 | set_size_and_pinuse_of_free_chunk(p, dsize); | ||
| 5744 | goto postaction; | ||
| 5745 | } | ||
| 5746 | else { | ||
| 5747 | size_t nsize = chunksize(next); | ||
| 5748 | psize += nsize; | ||
| 5749 | unlink_chunk(fm, next, nsize); | ||
| 5750 | set_size_and_pinuse_of_free_chunk(p, psize); | ||
| 5751 | if (p == fm->dv) { | ||
| 5752 | fm->dvsize = psize; | ||
| 5753 | goto postaction; | ||
| 5754 | } | ||
| 5755 | } | ||
| 5756 | } | ||
| 5757 | else | ||
| 5758 | set_free_with_pinuse(p, psize, next); | ||
| 5759 | |||
| 5760 | if (is_small(psize)) { | ||
| 5761 | insert_small_chunk(fm, p, psize); | ||
| 5762 | check_free_chunk(fm, p); | ||
| 5763 | } | ||
| 5764 | else { | ||
| 5765 | tchunkptr tp = (tchunkptr)p; | ||
| 5766 | insert_large_chunk(fm, tp, psize); | ||
| 5767 | check_free_chunk(fm, p); | ||
| 5768 | if (--fm->release_checks == 0) | ||
| 5769 | release_unused_segments(fm); | ||
| 5770 | } | ||
| 5771 | goto postaction; | ||
| 5772 | } | ||
| 5773 | } | ||
| 5774 | erroraction: | ||
| 5775 | USAGE_ERROR_ACTION(fm, p); | ||
| 5776 | postaction: | ||
| 5777 | POSTACTION(fm); | ||
| 5778 | } | ||
| 5779 | } | ||
| 5780 | } | ||
| 5781 | |||
| 5782 | void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) { | ||
| 5783 | void* mem; | ||
| 5784 | size_t req = 0; | ||
| 5785 | mstate ms = (mstate)msp; | ||
| 5786 | if (!ok_magic(ms)) { | ||
| 5787 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5788 | return 0; | ||
| 5789 | } | ||
| 5790 | if (n_elements != 0) { | ||
| 5791 | req = n_elements * elem_size; | ||
| 5792 | if (((n_elements | elem_size) & ~(size_t)0xffff) && | ||
| 5793 | (req / n_elements != elem_size)) | ||
| 5794 | req = MAX_SIZE_T; /* force downstream failure on overflow */ | ||
| 5795 | } | ||
| 5796 | mem = internal_malloc(ms, req); | ||
| 5797 | if (mem != 0 && calloc_must_clear(mem2chunk(mem))) | ||
| 5798 | memset(mem, 0, req); | ||
| 5799 | return mem; | ||
| 5800 | } | ||
| 5801 | |||
| 5802 | void* mspace_realloc(mspace msp, void* oldmem, size_t bytes) { | ||
| 5803 | void* mem = 0; | ||
| 5804 | if (oldmem == 0) { | ||
| 5805 | mem = mspace_malloc(msp, bytes); | ||
| 5806 | } | ||
| 5807 | else if (bytes >= MAX_REQUEST) { | ||
| 5808 | MALLOC_FAILURE_ACTION; | ||
| 5809 | } | ||
| 5810 | #ifdef REALLOC_ZERO_BYTES_FREES | ||
| 5811 | else if (bytes == 0) { | ||
| 5812 | mspace_free(msp, oldmem); | ||
| 5813 | } | ||
| 5814 | #endif /* REALLOC_ZERO_BYTES_FREES */ | ||
| 5815 | else { | ||
| 5816 | size_t nb = request2size(bytes); | ||
| 5817 | mchunkptr oldp = mem2chunk(oldmem); | ||
| 5818 | #if ! FOOTERS | ||
| 5819 | mstate m = (mstate)msp; | ||
| 5820 | #else /* FOOTERS */ | ||
| 5821 | mstate m = get_mstate_for(oldp); | ||
| 5822 | if (!ok_magic(m)) { | ||
| 5823 | USAGE_ERROR_ACTION(m, oldmem); | ||
| 5824 | return 0; | ||
| 5825 | } | ||
| 5826 | #endif /* FOOTERS */ | ||
| 5827 | if (!PREACTION(m)) { | ||
| 5828 | mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1); | ||
| 5829 | POSTACTION(m); | ||
| 5830 | if (newp != 0) { | ||
| 5831 | check_inuse_chunk(m, newp); | ||
| 5832 | mem = chunk2mem(newp); | ||
| 5833 | } | ||
| 5834 | else { | ||
| 5835 | mem = mspace_malloc(m, bytes); | ||
| 5836 | if (mem != 0) { | ||
| 5837 | size_t oc = chunksize(oldp) - overhead_for(oldp); | ||
| 5838 | memcpy(mem, oldmem, (oc < bytes)? oc : bytes); | ||
| 5839 | mspace_free(m, oldmem); | ||
| 5840 | } | ||
| 5841 | } | ||
| 5842 | } | ||
| 5843 | } | ||
| 5844 | return mem; | ||
| 5845 | } | ||
| 5846 | |||
| 5847 | void* mspace_realloc_in_place(mspace msp, void* oldmem, size_t bytes) { | ||
| 5848 | void* mem = 0; | ||
| 5849 | if (oldmem != 0) { | ||
| 5850 | if (bytes >= MAX_REQUEST) { | ||
| 5851 | MALLOC_FAILURE_ACTION; | ||
| 5852 | } | ||
| 5853 | else { | ||
| 5854 | size_t nb = request2size(bytes); | ||
| 5855 | mchunkptr oldp = mem2chunk(oldmem); | ||
| 5856 | #if ! FOOTERS | ||
| 5857 | mstate m = (mstate)msp; | ||
| 5858 | #else /* FOOTERS */ | ||
| 5859 | mstate m = get_mstate_for(oldp); | ||
| 5860 | (void)msp; /* placate people compiling -Wunused */ | ||
| 5861 | if (!ok_magic(m)) { | ||
| 5862 | USAGE_ERROR_ACTION(m, oldmem); | ||
| 5863 | return 0; | ||
| 5864 | } | ||
| 5865 | #endif /* FOOTERS */ | ||
| 5866 | if (!PREACTION(m)) { | ||
| 5867 | mchunkptr newp = try_realloc_chunk(m, oldp, nb, 0); | ||
| 5868 | POSTACTION(m); | ||
| 5869 | if (newp == oldp) { | ||
| 5870 | check_inuse_chunk(m, newp); | ||
| 5871 | mem = oldmem; | ||
| 5872 | } | ||
| 5873 | } | ||
| 5874 | } | ||
| 5875 | } | ||
| 5876 | return mem; | ||
| 5877 | } | ||
| 5878 | |||
| 5879 | void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) { | ||
| 5880 | mstate ms = (mstate)msp; | ||
| 5881 | if (!ok_magic(ms)) { | ||
| 5882 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5883 | return 0; | ||
| 5884 | } | ||
| 5885 | if (alignment <= MALLOC_ALIGNMENT) | ||
| 5886 | return mspace_malloc(msp, bytes); | ||
| 5887 | return internal_memalign(ms, alignment, bytes); | ||
| 5888 | } | ||
| 5889 | |||
| 5890 | void** mspace_independent_calloc(mspace msp, size_t n_elements, | ||
| 5891 | size_t elem_size, void* chunks[]) { | ||
| 5892 | size_t sz = elem_size; /* serves as 1-element array */ | ||
| 5893 | mstate ms = (mstate)msp; | ||
| 5894 | if (!ok_magic(ms)) { | ||
| 5895 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5896 | return 0; | ||
| 5897 | } | ||
| 5898 | return ialloc(ms, n_elements, &sz, 3, chunks); | ||
| 5899 | } | ||
| 5900 | |||
| 5901 | void** mspace_independent_comalloc(mspace msp, size_t n_elements, | ||
| 5902 | size_t sizes[], void* chunks[]) { | ||
| 5903 | mstate ms = (mstate)msp; | ||
| 5904 | if (!ok_magic(ms)) { | ||
| 5905 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5906 | return 0; | ||
| 5907 | } | ||
| 5908 | return ialloc(ms, n_elements, sizes, 0, chunks); | ||
| 5909 | } | ||
| 5910 | |||
| 5911 | size_t mspace_bulk_free(mspace msp, void* array[], size_t nelem) { | ||
| 5912 | return internal_bulk_free((mstate)msp, array, nelem); | ||
| 5913 | } | ||
| 5914 | |||
| 5915 | #if MALLOC_INSPECT_ALL | ||
| 5916 | void mspace_inspect_all(mspace msp, | ||
| 5917 | void(*handler)(void *start, | ||
| 5918 | void *end, | ||
| 5919 | size_t used_bytes, | ||
| 5920 | void* callback_arg), | ||
| 5921 | void* arg) { | ||
| 5922 | mstate ms = (mstate)msp; | ||
| 5923 | if (ok_magic(ms)) { | ||
| 5924 | if (!PREACTION(ms)) { | ||
| 5925 | internal_inspect_all(ms, handler, arg); | ||
| 5926 | POSTACTION(ms); | ||
| 5927 | } | ||
| 5928 | } | ||
| 5929 | else { | ||
| 5930 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5931 | } | ||
| 5932 | } | ||
| 5933 | #endif /* MALLOC_INSPECT_ALL */ | ||
| 5934 | |||
| 5935 | int mspace_trim(mspace msp, size_t pad) { | ||
| 5936 | int result = 0; | ||
| 5937 | mstate ms = (mstate)msp; | ||
| 5938 | if (ok_magic(ms)) { | ||
| 5939 | if (!PREACTION(ms)) { | ||
| 5940 | result = sys_trim(ms, pad); | ||
| 5941 | POSTACTION(ms); | ||
| 5942 | } | ||
| 5943 | } | ||
| 5944 | else { | ||
| 5945 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5946 | } | ||
| 5947 | return result; | ||
| 5948 | } | ||
| 5949 | |||
| 5950 | #if !NO_MALLOC_STATS | ||
| 5951 | void mspace_malloc_stats(mspace msp) { | ||
| 5952 | mstate ms = (mstate)msp; | ||
| 5953 | if (ok_magic(ms)) { | ||
| 5954 | internal_malloc_stats(ms); | ||
| 5955 | } | ||
| 5956 | else { | ||
| 5957 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5958 | } | ||
| 5959 | } | ||
| 5960 | #endif /* NO_MALLOC_STATS */ | ||
| 5961 | |||
| 5962 | size_t mspace_footprint(mspace msp) { | ||
| 5963 | size_t result = 0; | ||
| 5964 | mstate ms = (mstate)msp; | ||
| 5965 | if (ok_magic(ms)) { | ||
| 5966 | result = ms->footprint; | ||
| 5967 | } | ||
| 5968 | else { | ||
| 5969 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5970 | } | ||
| 5971 | return result; | ||
| 5972 | } | ||
| 5973 | |||
| 5974 | size_t mspace_max_footprint(mspace msp) { | ||
| 5975 | size_t result = 0; | ||
| 5976 | mstate ms = (mstate)msp; | ||
| 5977 | if (ok_magic(ms)) { | ||
| 5978 | result = ms->max_footprint; | ||
| 5979 | } | ||
| 5980 | else { | ||
| 5981 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5982 | } | ||
| 5983 | return result; | ||
| 5984 | } | ||
| 5985 | |||
| 5986 | size_t mspace_footprint_limit(mspace msp) { | ||
| 5987 | size_t result = 0; | ||
| 5988 | mstate ms = (mstate)msp; | ||
| 5989 | if (ok_magic(ms)) { | ||
| 5990 | size_t maf = ms->footprint_limit; | ||
| 5991 | result = (maf == 0) ? MAX_SIZE_T : maf; | ||
| 5992 | } | ||
| 5993 | else { | ||
| 5994 | USAGE_ERROR_ACTION(ms,ms); | ||
| 5995 | } | ||
| 5996 | return result; | ||
| 5997 | } | ||
| 5998 | |||
| 5999 | size_t mspace_set_footprint_limit(mspace msp, size_t bytes) { | ||
| 6000 | size_t result = 0; | ||
| 6001 | mstate ms = (mstate)msp; | ||
| 6002 | if (ok_magic(ms)) { | ||
| 6003 | if (bytes == 0) | ||
| 6004 | result = granularity_align(1); /* Use minimal size */ | ||
| 6005 | if (bytes == MAX_SIZE_T) | ||
| 6006 | result = 0; /* disable */ | ||
| 6007 | else | ||
| 6008 | result = granularity_align(bytes); | ||
| 6009 | ms->footprint_limit = result; | ||
| 6010 | } | ||
| 6011 | else { | ||
| 6012 | USAGE_ERROR_ACTION(ms,ms); | ||
| 6013 | } | ||
| 6014 | return result; | ||
| 6015 | } | ||
| 6016 | |||
| 6017 | #if !NO_MALLINFO | ||
| 6018 | struct mallinfo mspace_mallinfo(mspace msp) { | ||
| 6019 | mstate ms = (mstate)msp; | ||
| 6020 | if (!ok_magic(ms)) { | ||
| 6021 | USAGE_ERROR_ACTION(ms,ms); | ||
| 6022 | } | ||
| 6023 | return internal_mallinfo(ms); | ||
| 6024 | } | ||
| 6025 | #endif /* NO_MALLINFO */ | ||
| 6026 | |||
| 6027 | size_t mspace_usable_size(const void* mem) { | ||
| 6028 | if (mem != 0) { | ||
| 6029 | mchunkptr p = mem2chunk(mem); | ||
| 6030 | if (is_inuse(p)) | ||
| 6031 | return chunksize(p) - overhead_for(p); | ||
| 6032 | } | ||
| 6033 | return 0; | ||
| 6034 | } | ||
| 6035 | |||
| 6036 | int mspace_mallopt(int param_number, int value) { | ||
| 6037 | return change_mparam(param_number, value); | ||
| 6038 | } | ||
| 6039 | |||
| 6040 | #endif /* MSPACES */ | ||
| 6041 | |||
| 6042 | |||
| 6043 | /* -------------------- Alternative MORECORE functions ------------------- */ | ||
| 6044 | |||
| 6045 | /* | ||
| 6046 | Guidelines for creating a custom version of MORECORE: | ||
| 6047 | |||
| 6048 | * For best performance, MORECORE should allocate in multiples of pagesize. | ||
| 6049 | * MORECORE may allocate more memory than requested. (Or even less, | ||
| 6050 | but this will usually result in a malloc failure.) | ||
| 6051 | * MORECORE must not allocate memory when given argument zero, but | ||
| 6052 | instead return one past the end address of memory from previous | ||
| 6053 | nonzero call. | ||
| 6054 | * For best performance, consecutive calls to MORECORE with positive | ||
| 6055 | arguments should return increasing addresses, indicating that | ||
| 6056 | space has been contiguously extended. | ||
| 6057 | * Even though consecutive calls to MORECORE need not return contiguous | ||
| 6058 | addresses, it must be OK for malloc'ed chunks to span multiple | ||
| 6059 | regions in those cases where they do happen to be contiguous. | ||
| 6060 | * MORECORE need not handle negative arguments -- it may instead | ||
| 6061 | just return MFAIL when given negative arguments. | ||
| 6062 | Negative arguments are always multiples of pagesize. MORECORE | ||
| 6063 | must not misinterpret negative args as large positive unsigned | ||
| 6064 | args. You can suppress all such calls from even occurring by defining | ||
| 6065 | MORECORE_CANNOT_TRIM, | ||
| 6066 | |||
| 6067 | As an example alternative MORECORE, here is a custom allocator | ||
| 6068 | kindly contributed for pre-OSX macOS. It uses virtually but not | ||
| 6069 | necessarily physically contiguous non-paged memory (locked in, | ||
| 6070 | present and won't get swapped out). You can use it by uncommenting | ||
| 6071 | this section, adding some #includes, and setting up the appropriate | ||
| 6072 | defines above: | ||
| 6073 | |||
| 6074 | #define MORECORE osMoreCore | ||
| 6075 | |||
| 6076 | There is also a shutdown routine that should somehow be called for | ||
| 6077 | cleanup upon program exit. | ||
| 6078 | |||
| 6079 | #define MAX_POOL_ENTRIES 100 | ||
| 6080 | #define MINIMUM_MORECORE_SIZE (64 * 1024U) | ||
| 6081 | static int next_os_pool; | ||
| 6082 | void *our_os_pools[MAX_POOL_ENTRIES]; | ||
| 6083 | |||
| 6084 | void *osMoreCore(int size) | ||
| 6085 | { | ||
| 6086 | void *ptr = 0; | ||
| 6087 | static void *sbrk_top = 0; | ||
| 6088 | |||
| 6089 | if (size > 0) | ||
| 6090 | { | ||
| 6091 | if (size < MINIMUM_MORECORE_SIZE) | ||
| 6092 | size = MINIMUM_MORECORE_SIZE; | ||
| 6093 | if (CurrentExecutionLevel() == kTaskLevel) | ||
| 6094 | ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0); | ||
| 6095 | if (ptr == 0) | ||
| 6096 | { | ||
| 6097 | return (void *) MFAIL; | ||
| 6098 | } | ||
| 6099 | // save ptrs so they can be freed during cleanup | ||
| 6100 | our_os_pools[next_os_pool] = ptr; | ||
| 6101 | next_os_pool++; | ||
| 6102 | ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK); | ||
| 6103 | sbrk_top = (char *) ptr + size; | ||
| 6104 | return ptr; | ||
| 6105 | } | ||
| 6106 | else if (size < 0) | ||
| 6107 | { | ||
| 6108 | // we don't currently support shrink behavior | ||
| 6109 | return (void *) MFAIL; | ||
| 6110 | } | ||
| 6111 | else | ||
| 6112 | { | ||
| 6113 | return sbrk_top; | ||
| 6114 | } | ||
| 6115 | } | ||
| 6116 | |||
| 6117 | // cleanup any allocated memory pools | ||
| 6118 | // called as last thing before shutting down driver | ||
| 6119 | |||
| 6120 | void osCleanupMem(void) | ||
| 6121 | { | ||
| 6122 | void **ptr; | ||
| 6123 | |||
| 6124 | for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++) | ||
| 6125 | if (*ptr) | ||
| 6126 | { | ||
| 6127 | PoolDeallocate(*ptr); | ||
| 6128 | *ptr = 0; | ||
| 6129 | } | ||
| 6130 | } | ||
| 6131 | |||
| 6132 | */ | ||
| 6133 | |||
| 6134 | |||
| 6135 | /* ----------------------------------------------------------------------- | ||
| 6136 | History: | ||
| 6137 | v2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea | ||
| 6138 | * fix bad comparison in dlposix_memalign | ||
| 6139 | * don't reuse adjusted asize in sys_alloc | ||
| 6140 | * add LOCK_AT_FORK -- thanks to Kirill Artamonov for the suggestion | ||
| 6141 | * reduce compiler warnings -- thanks to all who reported/suggested these | ||
| 6142 | |||
| 6143 | v2.8.5 Sun May 22 10:26:02 2011 Doug Lea (dl at gee) | ||
| 6144 | * Always perform unlink checks unless INSECURE | ||
| 6145 | * Add posix_memalign. | ||
| 6146 | * Improve realloc to expand in more cases; expose realloc_in_place. | ||
| 6147 | Thanks to Peter Buhr for the suggestion. | ||
| 6148 | * Add footprint_limit, inspect_all, bulk_free. Thanks | ||
| 6149 | to Barry Hayes and others for the suggestions. | ||
| 6150 | * Internal refactorings to avoid calls while holding locks | ||
| 6151 | * Use non-reentrant locks by default. Thanks to Roland McGrath | ||
| 6152 | for the suggestion. | ||
| 6153 | * Small fixes to mspace_destroy, reset_on_error. | ||
| 6154 | * Various configuration extensions/changes. Thanks | ||
| 6155 | to all who contributed these. | ||
| 6156 | |||
| 6157 | V2.8.4a Thu Apr 28 14:39:43 2011 (dl at gee.cs.oswego.edu) | ||
| 6158 | * Update Creative Commons URL | ||
| 6159 | |||
| 6160 | V2.8.4 Wed May 27 09:56:23 2009 Doug Lea (dl at gee) | ||
| 6161 | * Use zeros instead of prev foot for is_mmapped | ||
| 6162 | * Add mspace_track_large_chunks; thanks to Jean Brouwers | ||
| 6163 | * Fix set_inuse in internal_realloc; thanks to Jean Brouwers | ||
| 6164 | * Fix insufficient sys_alloc padding when using 16byte alignment | ||
| 6165 | * Fix bad error check in mspace_footprint | ||
| 6166 | * Adaptations for ptmalloc; thanks to Wolfram Gloger. | ||
| 6167 | * Reentrant spin locks; thanks to Earl Chew and others | ||
| 6168 | * Win32 improvements; thanks to Niall Douglas and Earl Chew | ||
| 6169 | * Add NO_SEGMENT_TRAVERSAL and MAX_RELEASE_CHECK_RATE options | ||
| 6170 | * Extension hook in malloc_state | ||
| 6171 | * Various small adjustments to reduce warnings on some compilers | ||
| 6172 | * Various configuration extensions/changes for more platforms. Thanks | ||
| 6173 | to all who contributed these. | ||
| 6174 | |||
| 6175 | V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee) | ||
| 6176 | * Add max_footprint functions | ||
| 6177 | * Ensure all appropriate literals are size_t | ||
| 6178 | * Fix conditional compilation problem for some #define settings | ||
| 6179 | * Avoid concatenating segments with the one provided | ||
| 6180 | in create_mspace_with_base | ||
| 6181 | * Rename some variables to avoid compiler shadowing warnings | ||
| 6182 | * Use explicit lock initialization. | ||
| 6183 | * Better handling of sbrk interference. | ||
| 6184 | * Simplify and fix segment insertion, trimming and mspace_destroy | ||
| 6185 | * Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x | ||
| 6186 | * Thanks especially to Dennis Flanagan for help on these. | ||
| 6187 | |||
| 6188 | V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee) | ||
| 6189 | * Fix memalign brace error. | ||
| 6190 | |||
| 6191 | V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee) | ||
| 6192 | * Fix improper #endif nesting in C++ | ||
| 6193 | * Add explicit casts needed for C++ | ||
| 6194 | |||
| 6195 | V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee) | ||
| 6196 | * Use trees for large bins | ||
| 6197 | * Support mspaces | ||
| 6198 | * Use segments to unify sbrk-based and mmap-based system allocation, | ||
| 6199 | removing need for emulation on most platforms without sbrk. | ||
| 6200 | * Default safety checks | ||
| 6201 | * Optional footer checks. Thanks to William Robertson for the idea. | ||
| 6202 | * Internal code refactoring | ||
| 6203 | * Incorporate suggestions and platform-specific changes. | ||
| 6204 | Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas, | ||
| 6205 | Aaron Bachmann, Emery Berger, and others. | ||
| 6206 | * Speed up non-fastbin processing enough to remove fastbins. | ||
| 6207 | * Remove useless cfree() to avoid conflicts with other apps. | ||
| 6208 | * Remove internal memcpy, memset. Compilers handle builtins better. | ||
| 6209 | * Remove some options that no one ever used and rename others. | ||
| 6210 | |||
| 6211 | V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee) | ||
| 6212 | * Fix malloc_state bitmap array misdeclaration | ||
| 6213 | |||
| 6214 | V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee) | ||
| 6215 | * Allow tuning of FIRST_SORTED_BIN_SIZE | ||
| 6216 | * Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte. | ||
| 6217 | * Better detection and support for non-contiguousness of MORECORE. | ||
| 6218 | Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger | ||
| 6219 | * Bypass most of malloc if no frees. Thanks To Emery Berger. | ||
| 6220 | * Fix freeing of old top non-contiguous chunk im sysmalloc. | ||
| 6221 | * Raised default trim and map thresholds to 256K. | ||
| 6222 | * Fix mmap-related #defines. Thanks to Lubos Lunak. | ||
| 6223 | * Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield. | ||
| 6224 | * Branch-free bin calculation | ||
| 6225 | * Default trim and mmap thresholds now 256K. | ||
| 6226 | |||
| 6227 | V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee) | ||
| 6228 | * Introduce independent_comalloc and independent_calloc. | ||
| 6229 | Thanks to Michael Pachos for motivation and help. | ||
| 6230 | * Make optional .h file available | ||
| 6231 | * Allow > 2GB requests on 32bit systems. | ||
| 6232 | * new WIN32 sbrk, mmap, munmap, lock code from <Walter@GeNeSys-e.de>. | ||
| 6233 | Thanks also to Andreas Mueller <a.mueller at paradatec.de>, | ||
| 6234 | and Anonymous. | ||
| 6235 | * Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for | ||
| 6236 | helping test this.) | ||
| 6237 | * memalign: check alignment arg | ||
| 6238 | * realloc: don't try to shift chunks backwards, since this | ||
| 6239 | leads to more fragmentation in some programs and doesn't | ||
| 6240 | seem to help in any others. | ||
| 6241 | * Collect all cases in malloc requiring system memory into sysmalloc | ||
| 6242 | * Use mmap as backup to sbrk | ||
| 6243 | * Place all internal state in malloc_state | ||
| 6244 | * Introduce fastbins (although similar to 2.5.1) | ||
| 6245 | * Many minor tunings and cosmetic improvements | ||
| 6246 | * Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK | ||
| 6247 | * Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS | ||
| 6248 | Thanks to Tony E. Bennett <tbennett@nvidia.com> and others. | ||
| 6249 | * Include errno.h to support default failure action. | ||
| 6250 | |||
| 6251 | V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) | ||
| 6252 | * return null for negative arguments | ||
| 6253 | * Added Several WIN32 cleanups from Martin C. Fong <mcfong at yahoo.com> | ||
| 6254 | * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' | ||
| 6255 | (e.g. WIN32 platforms) | ||
| 6256 | * Cleanup header file inclusion for WIN32 platforms | ||
| 6257 | * Cleanup code to avoid Microsoft Visual C++ compiler complaints | ||
| 6258 | * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing | ||
| 6259 | memory allocation routines | ||
| 6260 | * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) | ||
| 6261 | * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to | ||
| 6262 | usage of 'assert' in non-WIN32 code | ||
| 6263 | * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to | ||
| 6264 | avoid infinite loop | ||
| 6265 | * Always call 'fREe()' rather than 'free()' | ||
| 6266 | |||
| 6267 | V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) | ||
| 6268 | * Fixed ordering problem with boundary-stamping | ||
| 6269 | |||
| 6270 | V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee) | ||
| 6271 | * Added pvalloc, as recommended by H.J. Liu | ||
| 6272 | * Added 64bit pointer support mainly from Wolfram Gloger | ||
| 6273 | * Added anonymously donated WIN32 sbrk emulation | ||
| 6274 | * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen | ||
| 6275 | * malloc_extend_top: fix mask error that caused wastage after | ||
| 6276 | foreign sbrks | ||
| 6277 | * Add linux mremap support code from HJ Liu | ||
| 6278 | |||
| 6279 | V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) | ||
| 6280 | * Integrated most documentation with the code. | ||
| 6281 | * Add support for mmap, with help from | ||
| 6282 | Wolfram Gloger (Gloger@lrz.uni-muenchen.de). | ||
| 6283 | * Use last_remainder in more cases. | ||
| 6284 | * Pack bins using idea from colin@nyx10.cs.du.edu | ||
| 6285 | * Use ordered bins instead of best-fit threshhold | ||
| 6286 | * Eliminate block-local decls to simplify tracing and debugging. | ||
| 6287 | * Support another case of realloc via move into top | ||
| 6288 | * Fix error occuring when initial sbrk_base not word-aligned. | ||
| 6289 | * Rely on page size for units instead of SBRK_UNIT to | ||
| 6290 | avoid surprises about sbrk alignment conventions. | ||
| 6291 | * Add mallinfo, mallopt. Thanks to Raymond Nijssen | ||
| 6292 | (raymond@es.ele.tue.nl) for the suggestion. | ||
| 6293 | * Add `pad' argument to malloc_trim and top_pad mallopt parameter. | ||
| 6294 | * More precautions for cases where other routines call sbrk, | ||
| 6295 | courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). | ||
| 6296 | * Added macros etc., allowing use in linux libc from | ||
| 6297 | H.J. Lu (hjl@gnu.ai.mit.edu) | ||
| 6298 | * Inverted this history list | ||
| 6299 | |||
| 6300 | V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) | ||
| 6301 | * Re-tuned and fixed to behave more nicely with V2.6.0 changes. | ||
| 6302 | * Removed all preallocation code since under current scheme | ||
| 6303 | the work required to undo bad preallocations exceeds | ||
| 6304 | the work saved in good cases for most test programs. | ||
| 6305 | * No longer use return list or unconsolidated bins since | ||
| 6306 | no scheme using them consistently outperforms those that don't | ||
| 6307 | given above changes. | ||
| 6308 | * Use best fit for very large chunks to prevent some worst-cases. | ||
| 6309 | * Added some support for debugging | ||
| 6310 | |||
| 6311 | V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) | ||
| 6312 | * Removed footers when chunks are in use. Thanks to | ||
| 6313 | Paul Wilson (wilson@cs.texas.edu) for the suggestion. | ||
| 6314 | |||
| 6315 | V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) | ||
| 6316 | * Added malloc_trim, with help from Wolfram Gloger | ||
| 6317 | (wmglo@Dent.MED.Uni-Muenchen.DE). | ||
| 6318 | |||
| 6319 | V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) | ||
| 6320 | |||
| 6321 | V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g) | ||
| 6322 | * realloc: try to expand in both directions | ||
| 6323 | * malloc: swap order of clean-bin strategy; | ||
| 6324 | * realloc: only conditionally expand backwards | ||
| 6325 | * Try not to scavenge used bins | ||
| 6326 | * Use bin counts as a guide to preallocation | ||
| 6327 | * Occasionally bin return list chunks in first scan | ||
| 6328 | * Add a few optimizations from colin@nyx10.cs.du.edu | ||
| 6329 | |||
| 6330 | V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) | ||
| 6331 | * faster bin computation & slightly different binning | ||
| 6332 | * merged all consolidations to one part of malloc proper | ||
| 6333 | (eliminating old malloc_find_space & malloc_clean_bin) | ||
| 6334 | * Scan 2 returns chunks (not just 1) | ||
| 6335 | * Propagate failure in realloc if malloc returns 0 | ||
| 6336 | * Add stuff to allow compilation on non-ANSI compilers | ||
| 6337 | from kpv@research.att.com | ||
| 6338 | |||
| 6339 | V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) | ||
| 6340 | * removed potential for odd address access in prev_chunk | ||
| 6341 | * removed dependency on getpagesize.h | ||
| 6342 | * misc cosmetics and a bit more internal documentation | ||
| 6343 | * anticosmetics: mangled names in macros to evade debugger strangeness | ||
| 6344 | * tested on sparc, hp-700, dec-mips, rs6000 | ||
| 6345 | with gcc & native cc (hp, dec only) allowing | ||
| 6346 | Detlefs & Zorn comparison study (in SIGPLAN Notices.) | ||
| 6347 | |||
| 6348 | Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) | ||
| 6349 | * Based loosely on libg++-1.2X malloc. (It retains some of the overall | ||
| 6350 | structure of old version, but most details differ.) | ||
| 6351 | |||
| 6352 | */ | ||
lib/libc/wasi/libc-bottom-half/clocks/clock.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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 created+28| ... | @@ -0,0 +1,28 @@ | ||
| 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 created+26| ... | @@ -0,0 +1,26 @@ | ||
| 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 | .tms_cutime = user | ||
| 21 | }; | ||
| 22 | |||
| 23 | __wasi_timestamp_t realtime = 0; | ||
| 24 | (void)__wasi_clock_time_get(__WASI_CLOCKID_MONOTONIC, 0, &realtime); | ||
| 25 | return realtime; | ||
| 26 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/LICENSE created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 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/errno.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef COMMON_ERRNO_H | ||
| 6 | #define COMMON_ERRNO_H | ||
| 7 | |||
| 8 | #include <wasi/api.h> | ||
| 9 | |||
| 10 | // WASI syscalls should just return ENOTDIR if that's what the problem is. | ||
| 11 | static inline __wasi_errno_t errno_fixup_directory(__wasi_fd_t fd, | ||
| 12 | __wasi_errno_t error) { | ||
| 13 | return error; | ||
| 14 | } | ||
| 15 | |||
| 16 | // WASI syscalls should just return ENOTSOCK if that's what the problem is. | ||
| 17 | static inline __wasi_errno_t errno_fixup_socket(__wasi_fd_t fd, | ||
| 18 | __wasi_errno_t error) { | ||
| 19 | return error; | ||
| 20 | } | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/limits.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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/overflow.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #ifndef COMMON_OVERFLOW_H | ||
| 6 | #define COMMON_OVERFLOW_H | ||
| 7 | |||
| 8 | // Performs an addition, subtraction or multiplication operation, | ||
| 9 | // returning whether the computation caused an overflow. These | ||
| 10 | // intrinsics are available as of Clang 3.8 and GCC 5. | ||
| 11 | #define add_overflow(x, y, out) __builtin_add_overflow(x, y, out) | ||
| 12 | #define sub_overflow(x, y, out) __builtin_sub_overflow(x, y, out) | ||
| 13 | #define mul_overflow(x, y, out) __builtin_mul_overflow(x, y, out) | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/common/time.h created+101| ... | @@ -0,0 +1,101 @@ | ||
| 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 | #include <common/overflow.h> | ||
| 10 | |||
| 11 | #include <sys/time.h> | ||
| 12 | |||
| 13 | #include <wasi/api.h> | ||
| 14 | #include <stdbool.h> | ||
| 15 | #include <time.h> | ||
| 16 | |||
| 17 | #define NSEC_PER_SEC 1000000000 | ||
| 18 | |||
| 19 | // Timezone agnostic conversion routines. | ||
| 20 | int __localtime_utc(time_t, struct tm *); | ||
| 21 | void __mktime_utc(const struct tm *, struct timespec *); | ||
| 22 | |||
| 23 | static inline bool is_leap(time_t year) { | ||
| 24 | year %= 400; | ||
| 25 | if (year < 0) | ||
| 26 | year += 400; | ||
| 27 | return ((year % 4) == 0 && (year % 100) != 0) || year == 100; | ||
| 28 | } | ||
| 29 | |||
| 30 | // Gets the length of the months in a year. | ||
| 31 | static inline const char *get_months(time_t year) { | ||
| 32 | static const char leap[12] = { | ||
| 33 | 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, | ||
| 34 | }; | ||
| 35 | static const char common[12] = { | ||
| 36 | 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, | ||
| 37 | }; | ||
| 38 | return is_leap(year) ? leap : common; | ||
| 39 | } | ||
| 40 | |||
| 41 | // Gets the cumulative length of the months in a year. | ||
| 42 | static inline const short *get_months_cumulative(time_t year) { | ||
| 43 | static const short leap[13] = { | ||
| 44 | 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366, | ||
| 45 | }; | ||
| 46 | static const short common[13] = { | ||
| 47 | 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365, | ||
| 48 | }; | ||
| 49 | return is_leap(year) ? leap : common; | ||
| 50 | } | ||
| 51 | |||
| 52 | static inline short get_ydays(time_t year) { | ||
| 53 | return is_leap(year) ? 366 : 365; | ||
| 54 | } | ||
| 55 | |||
| 56 | static inline bool timespec_to_timestamp_exact( | ||
| 57 | const struct timespec *timespec, __wasi_timestamp_t *timestamp) { | ||
| 58 | // Invalid nanoseconds field. | ||
| 59 | if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) | ||
| 60 | return false; | ||
| 61 | |||
| 62 | // Timestamps before the Epoch are not supported. | ||
| 63 | if (timespec->tv_sec < 0) | ||
| 64 | return false; | ||
| 65 | |||
| 66 | // Make sure our timestamp does not overflow. | ||
| 67 | return !mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) && | ||
| 68 | !add_overflow(*timestamp, timespec->tv_nsec, timestamp); | ||
| 69 | } | ||
| 70 | |||
| 71 | static inline bool timespec_to_timestamp_clamp( | ||
| 72 | const struct timespec *timespec, __wasi_timestamp_t *timestamp) { | ||
| 73 | // Invalid nanoseconds field. | ||
| 74 | if (timespec->tv_nsec < 0 || timespec->tv_nsec >= NSEC_PER_SEC) | ||
| 75 | return false; | ||
| 76 | |||
| 77 | if (timespec->tv_sec < 0) { | ||
| 78 | // Timestamps before the Epoch are not supported. | ||
| 79 | *timestamp = 0; | ||
| 80 | } else if (mul_overflow(timespec->tv_sec, NSEC_PER_SEC, timestamp) || | ||
| 81 | add_overflow(*timestamp, timespec->tv_nsec, timestamp)) { | ||
| 82 | // Make sure our timestamp does not overflow. | ||
| 83 | *timestamp = NUMERIC_MAX(__wasi_timestamp_t); | ||
| 84 | } | ||
| 85 | return true; | ||
| 86 | } | ||
| 87 | |||
| 88 | static inline struct timespec timestamp_to_timespec( | ||
| 89 | __wasi_timestamp_t timestamp) { | ||
| 90 | // Decompose timestamp into seconds and nanoseconds. | ||
| 91 | return (struct timespec){.tv_sec = timestamp / NSEC_PER_SEC, | ||
| 92 | .tv_nsec = timestamp % NSEC_PER_SEC}; | ||
| 93 | } | ||
| 94 | |||
| 95 | static inline struct timeval timestamp_to_timeval( | ||
| 96 | __wasi_timestamp_t timestamp) { | ||
| 97 | struct timespec ts = timestamp_to_timespec(timestamp); | ||
| 98 | return (struct timeval){.tv_sec = ts.tv_sec, ts.tv_nsec / 1000}; | ||
| 99 | } | ||
| 100 | |||
| 101 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/include/_/cdefs.h created+149| ... | @@ -0,0 +1,149 @@ | ||
| 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 | // Version information. | ||
| 28 | #define __cloudlibc__ 1 | ||
| 29 | #define __cloudlibc_major__ 0 | ||
| 30 | #define __cloudlibc_minor__ 102 | ||
| 31 | |||
| 32 | #ifdef __cplusplus | ||
| 33 | #define __BEGIN_DECLS extern "C" { | ||
| 34 | #define __END_DECLS } | ||
| 35 | #else | ||
| 36 | #define __BEGIN_DECLS | ||
| 37 | #define __END_DECLS | ||
| 38 | #endif | ||
| 39 | |||
| 40 | // Whether we should provide inline versions of functions. Due to C++'s | ||
| 41 | // support for namespaces, it is generally a bad idea to declare | ||
| 42 | // function macros. | ||
| 43 | #ifdef __cplusplus | ||
| 44 | #define _CLOUDLIBC_INLINE_FUNCTIONS 0 | ||
| 45 | #else | ||
| 46 | #define _CLOUDLIBC_INLINE_FUNCTIONS 1 | ||
| 47 | #endif | ||
| 48 | |||
| 49 | // Compiler-independent annotations. | ||
| 50 | |||
| 51 | #ifndef __has_builtin | ||
| 52 | #define __has_builtin(x) 0 | ||
| 53 | #endif | ||
| 54 | #ifndef __has_extension | ||
| 55 | #define __has_extension(x) __has_feature(x) | ||
| 56 | #endif | ||
| 57 | #ifndef __has_feature | ||
| 58 | #define __has_feature(x) 0 | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #define __offsetof(type, member) __builtin_offsetof(type, member) | ||
| 62 | #define __containerof(ptr, type, member) \ | ||
| 63 | ((type *)((char *)(ptr)-__offsetof(type, member))) | ||
| 64 | |||
| 65 | #define __extname(x) __asm__(x) | ||
| 66 | #define __malloc_like __attribute__((__malloc__)) | ||
| 67 | #define __pure2 __attribute__((__const__)) | ||
| 68 | #define __pure __attribute__((__pure__)) | ||
| 69 | #define __section(x) __attribute__((__section__(x))) | ||
| 70 | #define __unused __attribute__((__unused__)) | ||
| 71 | #define __used __attribute__((__used__)) | ||
| 72 | #define __weak_symbol __attribute__((__weak__)) | ||
| 73 | |||
| 74 | // Format string argument type checking. | ||
| 75 | #define __printflike(format, va) \ | ||
| 76 | __attribute__((__format__(__printf__, format, va))) | ||
| 77 | #define __scanflike(format, va) \ | ||
| 78 | __attribute__((__format__(__scanf__, format, va))) | ||
| 79 | // TODO(ed): Enable this once supported by LLVM: | ||
| 80 | // https://llvm.org/bugs/show_bug.cgi?id=16810 | ||
| 81 | #define __wprintflike(format, va) | ||
| 82 | #define __wscanflike(format, va) | ||
| 83 | |||
| 84 | #define __strong_reference(oldsym, newsym) \ | ||
| 85 | extern __typeof__(oldsym) newsym __attribute__((__alias__(#oldsym))) | ||
| 86 | |||
| 87 | // Convenience macros. | ||
| 88 | |||
| 89 | #define __arraycount(x) (sizeof(x) / sizeof((x)[0])) | ||
| 90 | #define __howmany(x, y) (((x) + (y)-1) / (y)) | ||
| 91 | #define __rounddown(x, y) (((x) / (y)) * (y)) | ||
| 92 | #define __roundup(x, y) ((((x) + (y)-1) / (y)) * (y)) | ||
| 93 | |||
| 94 | // Lock annotations. | ||
| 95 | |||
| 96 | #if __has_extension(c_thread_safety_attributes) | ||
| 97 | #define __lock_annotate(x) __attribute__((x)) | ||
| 98 | #else | ||
| 99 | #define __lock_annotate(x) | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #define __lockable __lock_annotate(lockable) | ||
| 103 | |||
| 104 | #define __locks_exclusive(...) \ | ||
| 105 | __lock_annotate(exclusive_lock_function(__VA_ARGS__)) | ||
| 106 | #define __locks_shared(...) __lock_annotate(shared_lock_function(__VA_ARGS__)) | ||
| 107 | |||
| 108 | #define __trylocks_exclusive(...) \ | ||
| 109 | __lock_annotate(exclusive_trylock_function(__VA_ARGS__)) | ||
| 110 | #define __trylocks_shared(...) \ | ||
| 111 | __lock_annotate(shared_trylock_function(__VA_ARGS__)) | ||
| 112 | |||
| 113 | #define __unlocks(...) __lock_annotate(unlock_function(__VA_ARGS__)) | ||
| 114 | |||
| 115 | #define __asserts_exclusive(...) \ | ||
| 116 | __lock_annotate(assert_exclusive_lock(__VA_ARGS__)) | ||
| 117 | #define __asserts_shared(...) __lock_annotate(assert_shared_lock(__VA_ARGS__)) | ||
| 118 | |||
| 119 | #define __requires_exclusive(...) \ | ||
| 120 | __lock_annotate(exclusive_locks_required(__VA_ARGS__)) | ||
| 121 | #define __requires_shared(...) \ | ||
| 122 | __lock_annotate(shared_locks_required(__VA_ARGS__)) | ||
| 123 | #define __requires_unlocked(...) __lock_annotate(locks_excluded(__VA_ARGS__)) | ||
| 124 | |||
| 125 | #define __no_lock_analysis __lock_annotate(no_thread_safety_analysis) | ||
| 126 | |||
| 127 | #define __guarded_by(x) __lock_annotate(guarded_by(x)) | ||
| 128 | #define __pt_guarded_by(x) __lock_annotate(pt_guarded_by(x)) | ||
| 129 | |||
| 130 | // Const preservation. | ||
| 131 | // | ||
| 132 | // Functions like strchr() allow you to silently discard a const | ||
| 133 | // qualifier from a string. This macro can be used to wrap such | ||
| 134 | // functions to propagate the const keyword where possible. | ||
| 135 | // | ||
| 136 | // This macro has many limitations, such as only being able to detect | ||
| 137 | // constness for void, char and wchar_t. For Clang, it also doesn't seem | ||
| 138 | // to work on string literals. | ||
| 139 | |||
| 140 | #define __preserve_const(type, name, arg, ...) \ | ||
| 141 | _Generic(arg, \ | ||
| 142 | const void *: (const type *)name(__VA_ARGS__), \ | ||
| 143 | const char *: (const type *)name(__VA_ARGS__), \ | ||
| 144 | const signed char *: (const type *)name(__VA_ARGS__), \ | ||
| 145 | const unsigned char *: (const type *)name(__VA_ARGS__), \ | ||
| 146 | const __wchar_t *: (const type *)name(__VA_ARGS__), \ | ||
| 147 | default: name(__VA_ARGS__)) | ||
| 148 | |||
| 149 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/include/stdlib.h created+241| ... | @@ -0,0 +1,241 @@ | ||
| 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 | // <stdlib.h> - standard library definitions | ||
| 25 | // | ||
| 26 | // Extensions: | ||
| 27 | // - MB_CUR_MAX_L(), mblen_l(), mbstowcs_l(), mbtowc_l(), wcstombs_l() | ||
| 28 | // and wctomb_l(): | ||
| 29 | // Regular functions always use the C locale. Available on many other | ||
| 30 | // operating systems. | ||
| 31 | // - alloca(): | ||
| 32 | // Present on most other operating systems. | ||
| 33 | // - arc4random(), arc4random_buf() and arc4random_uniform(): | ||
| 34 | // Secure random number generator. Available on many other operating | ||
| 35 | // systems. | ||
| 36 | // - l64a_r(): | ||
| 37 | // Thread-safe replacement for l64a(). Part of the SVID, 4th edition. | ||
| 38 | // - qsort_r(): | ||
| 39 | // Available on many other operating systems, although the prototype | ||
| 40 | // is not consistent. This implementation is compatible with glibc. | ||
| 41 | // It is expected that this version will be standardized in the future. | ||
| 42 | // - reallocarray(): | ||
| 43 | // Allows for reallocation of buffers without integer overflows. | ||
| 44 | // | ||
| 45 | // Features missing: | ||
| 46 | // - initstate(), lcong48(), seed48(), setstate(), srand(), srand48() | ||
| 47 | // and srandom(): | ||
| 48 | // Randomizer is seeded securely by default. There is no need to seed | ||
| 49 | // manually. | ||
| 50 | // - WEXITSTATUS(), WIFEXITED(), WIFSIGNALED(), WIFSTOPPED(), WNOHANG, | ||
| 51 | // WSTOPSIG(), WTERMSIG(), WUNTRACED: | ||
| 52 | // Only useful if system() would actually work. | ||
| 53 | // - l64a(): | ||
| 54 | // Not thread-safe. Use l64a_r() instead. | ||
| 55 | // - putenv(), setenv() and unsetenv(): | ||
| 56 | // Environment variables are not available. | ||
| 57 | // - grantpt(), posix_openpt(), ptsname() and unlockpt(): | ||
| 58 | // Pseudo-terminals are not available. | ||
| 59 | // - mkdtemp(), mkstemp() and realpath(): | ||
| 60 | // Requires global filesystem namespace. | ||
| 61 | // - setkey(): | ||
| 62 | // Password database and encryption schemes not available. | ||
| 63 | // - system(): | ||
| 64 | // Requires a command shell. | ||
| 65 | |||
| 66 | #ifndef _STDLIB_H_ | ||
| 67 | #define _STDLIB_H_ | ||
| 68 | |||
| 69 | #include <_/limits.h> | ||
| 70 | #include <_/types.h> | ||
| 71 | |||
| 72 | __BEGIN_DECLS | ||
| 73 | _Noreturn void _Exit(int); | ||
| 74 | _Noreturn void abort(void); | ||
| 75 | void *calloc(size_t, size_t); | ||
| 76 | _Noreturn void exit(int); | ||
| 77 | void free(void *); | ||
| 78 | void *malloc(size_t); | ||
| 79 | void qsort(void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 80 | void *realloc(void *, size_t); | ||
| 81 | __END_DECLS | ||
| 82 | |||
| 83 | #if _CLOUDLIBC_INLINE_FUNCTIONS | ||
| 84 | |||
| 85 | // qsort_r() implementation from Bentley and McIlroy's | ||
| 86 | // "Engineering a Sort Function". | ||
| 87 | // | ||
| 88 | // This sorting function is inlined into this header, so that the | ||
| 89 | // compiler can create an optimized version that takes the alignment and | ||
| 90 | // size of the elements into account. It also reduces the overhead of | ||
| 91 | // indirect function calls. | ||
| 92 | |||
| 93 | static __inline void __qsort_r(void *, size_t, size_t, | ||
| 94 | int (*)(const void *, const void *, void *), | ||
| 95 | void *); | ||
| 96 | |||
| 97 | static __inline size_t __qsort_min(size_t __a, size_t __b) { | ||
| 98 | return __a < __b ? __a : __b; | ||
| 99 | } | ||
| 100 | |||
| 101 | // Swaps the contents of two buffers. | ||
| 102 | static __inline void __qsort_swap(char *__a, char *__b, size_t __n) { | ||
| 103 | char __t; | ||
| 104 | |||
| 105 | while (__n-- > 0) { | ||
| 106 | __t = *__a; | ||
| 107 | *__a++ = *__b; | ||
| 108 | *__b++ = __t; | ||
| 109 | } | ||
| 110 | } | ||
| 111 | |||
| 112 | // Implementation of insertionsort for small lists. | ||
| 113 | static __inline void __qsort_insertionsort( | ||
| 114 | char *__a, size_t __nel, size_t __width, | ||
| 115 | int (*__cmp)(const void *, const void *, void *), void *__thunk) { | ||
| 116 | char *__pm, *__pl; | ||
| 117 | |||
| 118 | for (__pm = __a + __width; __pm < __a + __nel * __width; __pm += __width) | ||
| 119 | for (__pl = __pm; __pl > __a && __cmp(__pl - __width, __pl, __thunk) > 0; | ||
| 120 | __pl -= __width) | ||
| 121 | __qsort_swap(__pl, __pl - __width, __width); | ||
| 122 | } | ||
| 123 | |||
| 124 | // Returns the median of three elements. | ||
| 125 | static __inline char *__qsort_med3(char *__a, char *__b, char *__c, | ||
| 126 | int (*__cmp)(const void *, const void *, | ||
| 127 | void *), | ||
| 128 | void *__thunk) { | ||
| 129 | return __cmp(__a, __b, __thunk) < 0 | ||
| 130 | ? (__cmp(__b, __c, __thunk) < 0 | ||
| 131 | ? __b | ||
| 132 | : __cmp(__a, __c, __thunk) < 0 ? __c : __a) | ||
| 133 | : (__cmp(__b, __c, __thunk) > 0 | ||
| 134 | ? __b | ||
| 135 | : __cmp(__a, __c, __thunk) > 0 ? __c : __a); | ||
| 136 | } | ||
| 137 | |||
| 138 | // Picks a pivot based on a pseudo-median of three or nine. | ||
| 139 | // TODO(ed): Does this still guarantee an O(n log n) running time? | ||
| 140 | static __inline char *__qsort_pickpivot(char *__a, size_t __nel, size_t __width, | ||
| 141 | int (*__cmp)(const void *, const void *, | ||
| 142 | void *), | ||
| 143 | void *__thunk) { | ||
| 144 | char *__pl, *__pm, *__pn; | ||
| 145 | size_t __s; | ||
| 146 | |||
| 147 | __pl = __a; | ||
| 148 | __pm = __a + (__nel / 2) * __width; | ||
| 149 | __pn = __a + (__nel - 1) * __width; | ||
| 150 | if (__nel > 40) { | ||
| 151 | __s = (__nel / 8) * __width; | ||
| 152 | __pl = __qsort_med3(__pl, __pl + __s, __pl + 2 * __s, __cmp, __thunk); | ||
| 153 | __pm = __qsort_med3(__pm - __s, __pm, __pm + __s, __cmp, __thunk); | ||
| 154 | __pn = __qsort_med3(__pn - 2 * __s, __pn - __s, __pn, __cmp, __thunk); | ||
| 155 | } | ||
| 156 | return __qsort_med3(__pl, __pm, __pn, __cmp, __thunk); | ||
| 157 | } | ||
| 158 | |||
| 159 | // Implementation of quicksort for larger lists. | ||
| 160 | static __inline void __qsort_quicksort(char *__a, size_t __nel, size_t __width, | ||
| 161 | int (*__cmp)(const void *, const void *, | ||
| 162 | void *), | ||
| 163 | void *__thunk) { | ||
| 164 | char *__pa, *__pb, *__pc, *__pd, *__pn; | ||
| 165 | int __r; | ||
| 166 | size_t __s; | ||
| 167 | |||
| 168 | // Select pivot and move it to the head of the list. | ||
| 169 | __qsort_swap(__a, __qsort_pickpivot(__a, __nel, __width, __cmp, __thunk), | ||
| 170 | __width); | ||
| 171 | |||
| 172 | // Perform partitioning. | ||
| 173 | __pa = __pb = __a; | ||
| 174 | __pc = __pd = __a + (__nel - 1) * __width; | ||
| 175 | for (;;) { | ||
| 176 | while (__pb <= __pc && (__r = __cmp(__pb, __a, __thunk)) <= 0) { | ||
| 177 | if (__r == 0) { | ||
| 178 | __qsort_swap(__pa, __pb, __width); | ||
| 179 | __pa += __width; | ||
| 180 | } | ||
| 181 | __pb += __width; | ||
| 182 | } | ||
| 183 | while (__pc >= __pb && (__r = __cmp(__pc, __a, __thunk)) >= 0) { | ||
| 184 | if (__r == 0) { | ||
| 185 | __qsort_swap(__pc, __pd, __width); | ||
| 186 | __pd -= __width; | ||
| 187 | } | ||
| 188 | __pc -= __width; | ||
| 189 | } | ||
| 190 | if (__pb > __pc) | ||
| 191 | break; | ||
| 192 | __qsort_swap(__pb, __pc, __width); | ||
| 193 | __pb += __width; | ||
| 194 | __pc -= __width; | ||
| 195 | } | ||
| 196 | |||
| 197 | // Store pivot between the two partitions. | ||
| 198 | __pn = __a + __nel * __width; | ||
| 199 | __s = __qsort_min((size_t)(__pa - __a), (size_t)(__pb - __pa)); | ||
| 200 | __qsort_swap(__a, __pb - __s, __s); | ||
| 201 | __s = __qsort_min((size_t)(__pd - __pc), (size_t)(__pn - __pd) - __width); | ||
| 202 | __qsort_swap(__pb, __pn - __s, __s); | ||
| 203 | |||
| 204 | // Sort the two partitions. | ||
| 205 | __s = (size_t)(__pb - __pa); | ||
| 206 | __qsort_r(__a, __s / __width, __width, __cmp, __thunk); | ||
| 207 | __s = (size_t)(__pd - __pc); | ||
| 208 | __qsort_r(__pn - __s, __s / __width, __width, __cmp, __thunk); | ||
| 209 | } | ||
| 210 | |||
| 211 | static __inline void __qsort_r(void *__base, size_t __nel, size_t __width, | ||
| 212 | int (*__cmp)(const void *, const void *, void *), | ||
| 213 | void *__thunk) { | ||
| 214 | char *__a; | ||
| 215 | |||
| 216 | __a = (char *)__base; | ||
| 217 | if (__nel < 8) { | ||
| 218 | __qsort_insertionsort(__a, __nel, __width, __cmp, __thunk); | ||
| 219 | } else { | ||
| 220 | __qsort_quicksort(__a, __nel, __width, __cmp, __thunk); | ||
| 221 | } | ||
| 222 | } | ||
| 223 | #define qsort_r(base, nel, width, compar, thunk) \ | ||
| 224 | __qsort_r(base, nel, width, compar, thunk) | ||
| 225 | |||
| 226 | // qsort(): Call into qsort_r(), providing the callback as the thunk. | ||
| 227 | // We assume that the optimizer is smart enough to simplify. | ||
| 228 | |||
| 229 | static __inline int __qsort_cmp(const void *__a, const void *__b, | ||
| 230 | void *__thunk) { | ||
| 231 | return ((int (*)(const void *, const void *))__thunk)(__a, __b); | ||
| 232 | } | ||
| 233 | |||
| 234 | static __inline void __qsort(void *__base, size_t __nel, size_t __width, | ||
| 235 | int (*__cmp)(const void *, const void *)) { | ||
| 236 | qsort_r(__base, __nel, __width, __qsort_cmp, (void *)__cmp); | ||
| 237 | } | ||
| 238 | #define qsort(base, nel, width, compar) __qsort(base, nel, width, compar) | ||
| 239 | #endif | ||
| 240 | |||
| 241 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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 created+31| ... | @@ -0,0 +1,31 @@ | ||
| 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 created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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 created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <dirent.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <stdlib.h> | ||
| 11 | |||
| 12 | #include "dirent_impl.h" | ||
| 13 | |||
| 14 | DIR *fdopendir(int fd) { | ||
| 15 | // Allocate new directory object and read buffer. | ||
| 16 | DIR *dirp = malloc(sizeof(*dirp)); | ||
| 17 | if (dirp == NULL) | ||
| 18 | return NULL; | ||
| 19 | dirp->buffer = malloc(DIRENT_DEFAULT_BUFFER_SIZE); | ||
| 20 | if (dirp->buffer == NULL) { | ||
| 21 | free(dirp); | ||
| 22 | return NULL; | ||
| 23 | } | ||
| 24 | |||
| 25 | // Ensure that this is really a directory by already loading the first | ||
| 26 | // chunk of data. | ||
| 27 | __wasi_errno_t error = | ||
| 28 | // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support. | ||
| 29 | __wasi_fd_readdir(fd, (uint8_t *)dirp->buffer, DIRENT_DEFAULT_BUFFER_SIZE, | ||
| 30 | __WASI_DIRCOOKIE_START, &dirp->buffer_used); | ||
| 31 | if (error != 0) { | ||
| 32 | free(dirp->buffer); | ||
| 33 | free(dirp); | ||
| 34 | errno = errno_fixup_directory(fd, error); | ||
| 35 | return NULL; | ||
| 36 | } | ||
| 37 | |||
| 38 | // Initialize other members. | ||
| 39 | dirp->fd = fd; | ||
| 40 | dirp->cookie = __WASI_DIRCOOKIE_START; | ||
| 41 | dirp->buffer_processed = 0; | ||
| 42 | dirp->buffer_size = DIRENT_DEFAULT_BUFFER_SIZE; | ||
| 43 | dirp->dirent = NULL; | ||
| 44 | dirp->dirent_size = 1; | ||
| 45 | return dirp; | ||
| 46 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 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 created+103| ... | @@ -0,0 +1,103 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <dirent.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <stddef.h> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <string.h> | ||
| 14 | |||
| 15 | #include "dirent_impl.h" | ||
| 16 | |||
| 17 | static_assert(DT_BLK == __WASI_FILETYPE_BLOCK_DEVICE, "Value mismatch"); | ||
| 18 | static_assert(DT_CHR == __WASI_FILETYPE_CHARACTER_DEVICE, "Value mismatch"); | ||
| 19 | static_assert(DT_DIR == __WASI_FILETYPE_DIRECTORY, "Value mismatch"); | ||
| 20 | static_assert(DT_FIFO == __WASI_FILETYPE_SOCKET_STREAM, "Value mismatch"); | ||
| 21 | static_assert(DT_LNK == __WASI_FILETYPE_SYMBOLIC_LINK, "Value mismatch"); | ||
| 22 | static_assert(DT_REG == __WASI_FILETYPE_REGULAR_FILE, "Value mismatch"); | ||
| 23 | static_assert(DT_UNKNOWN == __WASI_FILETYPE_UNKNOWN, "Value mismatch"); | ||
| 24 | |||
| 25 | // Grows a buffer to be large enough to hold a certain amount of data. | ||
| 26 | #define GROW(buffer, buffer_size, target_size) \ | ||
| 27 | do { \ | ||
| 28 | if ((buffer_size) < (target_size)) { \ | ||
| 29 | size_t new_size = (buffer_size); \ | ||
| 30 | while (new_size < (target_size)) \ | ||
| 31 | new_size *= 2; \ | ||
| 32 | void *new_buffer = realloc(buffer, new_size); \ | ||
| 33 | if (new_buffer == NULL) \ | ||
| 34 | return NULL; \ | ||
| 35 | (buffer) = new_buffer; \ | ||
| 36 | (buffer_size) = new_size; \ | ||
| 37 | } \ | ||
| 38 | } while (0) | ||
| 39 | |||
| 40 | struct dirent *readdir(DIR *dirp) { | ||
| 41 | for (;;) { | ||
| 42 | // Extract the next dirent header. | ||
| 43 | size_t buffer_left = dirp->buffer_used - dirp->buffer_processed; | ||
| 44 | if (buffer_left < sizeof(__wasi_dirent_t)) { | ||
| 45 | // End-of-file. | ||
| 46 | if (dirp->buffer_used < dirp->buffer_size) | ||
| 47 | return NULL; | ||
| 48 | goto read_entries; | ||
| 49 | } | ||
| 50 | __wasi_dirent_t entry; | ||
| 51 | memcpy(&entry, dirp->buffer + dirp->buffer_processed, sizeof(entry)); | ||
| 52 | |||
| 53 | size_t entry_size = sizeof(__wasi_dirent_t) + entry.d_namlen; | ||
| 54 | if (entry.d_namlen == 0) { | ||
| 55 | // Invalid pathname length. Skip the entry. | ||
| 56 | dirp->buffer_processed += entry_size; | ||
| 57 | continue; | ||
| 58 | } | ||
| 59 | |||
| 60 | // The entire entry must be present in buffer space. If not, read | ||
| 61 | // the entry another time. Ensure that the read buffer is large | ||
| 62 | // enough to fit at least this single entry. | ||
| 63 | if (buffer_left < entry_size) { | ||
| 64 | GROW(dirp->buffer, dirp->buffer_size, entry_size); | ||
| 65 | goto read_entries; | ||
| 66 | } | ||
| 67 | |||
| 68 | // Skip entries having null bytes in the filename. | ||
| 69 | const char *name = dirp->buffer + dirp->buffer_processed + sizeof(entry); | ||
| 70 | if (memchr(name, '\0', entry.d_namlen) != NULL) { | ||
| 71 | dirp->buffer_processed += entry_size; | ||
| 72 | continue; | ||
| 73 | } | ||
| 74 | |||
| 75 | // Return the next directory entry. Ensure that the dirent is large | ||
| 76 | // enough to fit the filename. | ||
| 77 | GROW(dirp->dirent, dirp->dirent_size, | ||
| 78 | offsetof(struct dirent, d_name) + entry.d_namlen + 1); | ||
| 79 | struct dirent *dirent = dirp->dirent; | ||
| 80 | dirent->d_ino = entry.d_ino; | ||
| 81 | dirent->d_type = entry.d_type; | ||
| 82 | memcpy(dirent->d_name, name, entry.d_namlen); | ||
| 83 | dirent->d_name[entry.d_namlen] = '\0'; | ||
| 84 | dirp->cookie = entry.d_next; | ||
| 85 | dirp->buffer_processed += entry_size; | ||
| 86 | return dirent; | ||
| 87 | |||
| 88 | read_entries: | ||
| 89 | // Discard data currently stored in the input buffer. | ||
| 90 | dirp->buffer_used = dirp->buffer_processed = dirp->buffer_size; | ||
| 91 | |||
| 92 | // Load more directory entries and continue. | ||
| 93 | __wasi_errno_t error = | ||
| 94 | // TODO: Remove the cast on `dirp->buffer` once the witx is updated with char8 support. | ||
| 95 | __wasi_fd_readdir(dirp->fd, (uint8_t *)dirp->buffer, dirp->buffer_size, | ||
| 96 | dirp->cookie, &dirp->buffer_used); | ||
| 97 | if (error != 0) { | ||
| 98 | errno = error; | ||
| 99 | return NULL; | ||
| 100 | } | ||
| 101 | dirp->buffer_processed = 0; | ||
| 102 | } | ||
| 103 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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 created+145| ... | @@ -0,0 +1,145 @@ | ||
| 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 | |||
| 15 | #include "dirent_impl.h" | ||
| 16 | |||
| 17 | static int sel_true(const struct dirent *de) { | ||
| 18 | return 1; | ||
| 19 | } | ||
| 20 | |||
| 21 | int __wasilibc_nocwd_scandirat(int dirfd, const char *dir, struct dirent ***namelist, | ||
| 22 | int (*sel)(const struct dirent *), | ||
| 23 | int (*compar)(const struct dirent **, const struct dirent **)) { | ||
| 24 | // Match all files if no select function is provided. | ||
| 25 | if (sel == NULL) | ||
| 26 | sel = sel_true; | ||
| 27 | |||
| 28 | // Open the directory. | ||
| 29 | int fd = __wasilibc_nocwd_openat_nomode(dirfd, dir, O_RDONLY | O_NONBLOCK | O_DIRECTORY); | ||
| 30 | if (fd == -1) | ||
| 31 | return -1; | ||
| 32 | |||
| 33 | // Allocate a read buffer for the directory entries. | ||
| 34 | size_t buffer_size = DIRENT_DEFAULT_BUFFER_SIZE; | ||
| 35 | char *buffer = malloc(buffer_size); | ||
| 36 | if (buffer == NULL) { | ||
| 37 | close(fd); | ||
| 38 | return -1; | ||
| 39 | } | ||
| 40 | size_t buffer_processed = buffer_size; | ||
| 41 | size_t buffer_used = buffer_size; | ||
| 42 | |||
| 43 | // Space for the array to return to the caller. | ||
| 44 | struct dirent **dirents = NULL; | ||
| 45 | size_t dirents_size = 0; | ||
| 46 | size_t dirents_used = 0; | ||
| 47 | |||
| 48 | __wasi_dircookie_t cookie = __WASI_DIRCOOKIE_START; | ||
| 49 | for (;;) { | ||
| 50 | // Extract the next dirent header. | ||
| 51 | size_t buffer_left = buffer_used - buffer_processed; | ||
| 52 | if (buffer_left < sizeof(__wasi_dirent_t)) { | ||
| 53 | // End-of-file. | ||
| 54 | if (buffer_used < buffer_size) | ||
| 55 | break; | ||
| 56 | goto read_entries; | ||
| 57 | } | ||
| 58 | __wasi_dirent_t entry; | ||
| 59 | memcpy(&entry, buffer + buffer_processed, sizeof(entry)); | ||
| 60 | |||
| 61 | size_t entry_size = sizeof(__wasi_dirent_t) + entry.d_namlen; | ||
| 62 | if (entry.d_namlen == 0) { | ||
| 63 | // Invalid pathname length. Skip the entry. | ||
| 64 | buffer_processed += entry_size; | ||
| 65 | continue; | ||
| 66 | } | ||
| 67 | |||
| 68 | // The entire entry must be present in buffer space. If not, read | ||
| 69 | // the entry another time. Ensure that the read buffer is large | ||
| 70 | // enough to fit at least this single entry. | ||
| 71 | if (buffer_left < entry_size) { | ||
| 72 | while (buffer_size < entry_size) | ||
| 73 | buffer_size *= 2; | ||
| 74 | char *new_buffer = realloc(buffer, buffer_size); | ||
| 75 | if (new_buffer == NULL) | ||
| 76 | goto bad; | ||
| 77 | buffer = new_buffer; | ||
| 78 | goto read_entries; | ||
| 79 | } | ||
| 80 | |||
| 81 | // Skip entries having null bytes in the filename. | ||
| 82 | const char *name = buffer + buffer_processed + sizeof(entry); | ||
| 83 | buffer_processed += entry_size; | ||
| 84 | if (memchr(name, '\0', entry.d_namlen) != NULL) | ||
| 85 | continue; | ||
| 86 | |||
| 87 | // Create the new directory entry. | ||
| 88 | struct dirent *dirent = | ||
| 89 | malloc(offsetof(struct dirent, d_name) + entry.d_namlen + 1); | ||
| 90 | if (dirent == NULL) | ||
| 91 | goto bad; | ||
| 92 | dirent->d_ino = entry.d_ino; | ||
| 93 | dirent->d_type = entry.d_type; | ||
| 94 | memcpy(dirent->d_name, name, entry.d_namlen); | ||
| 95 | dirent->d_name[entry.d_namlen] = '\0'; | ||
| 96 | cookie = entry.d_next; | ||
| 97 | |||
| 98 | if (sel(dirent)) { | ||
| 99 | // Add the entry to the results. | ||
| 100 | if (dirents_used == dirents_size) { | ||
| 101 | dirents_size = dirents_size < 8 ? 8 : dirents_size * 2; | ||
| 102 | struct dirent **new_dirents = | ||
| 103 | realloc(dirents, dirents_size * sizeof(*dirents)); | ||
| 104 | if (new_dirents == NULL) { | ||
| 105 | free(dirent); | ||
| 106 | goto bad; | ||
| 107 | } | ||
| 108 | dirents = new_dirents; | ||
| 109 | } | ||
| 110 | dirents[dirents_used++] = dirent; | ||
| 111 | } else { | ||
| 112 | // Discard the entry. | ||
| 113 | free(dirent); | ||
| 114 | } | ||
| 115 | continue; | ||
| 116 | |||
| 117 | read_entries:; | ||
| 118 | // Load more directory entries and continue. | ||
| 119 | // TODO: Remove the cast on `buffer` once the witx is updated with char8 support. | ||
| 120 | __wasi_errno_t error = __wasi_fd_readdir(fd, (uint8_t *)buffer, buffer_size, | ||
| 121 | cookie, &buffer_used); | ||
| 122 | if (error != 0) { | ||
| 123 | errno = error; | ||
| 124 | goto bad; | ||
| 125 | } | ||
| 126 | buffer_processed = 0; | ||
| 127 | } | ||
| 128 | |||
| 129 | // Sort results and return them. | ||
| 130 | free(buffer); | ||
| 131 | close(fd); | ||
| 132 | (qsort)(dirents, dirents_used, sizeof(*dirents), | ||
| 133 | (int (*)(const void *, const void *))compar); | ||
| 134 | *namelist = dirents; | ||
| 135 | return dirents_used; | ||
| 136 | |||
| 137 | bad: | ||
| 138 | // Deallocate partially created results. | ||
| 139 | for (size_t i = 0; i < dirents_used; ++i) | ||
| 140 | free(dirents[i]); | ||
| 141 | free(dirents); | ||
| 142 | free(buffer); | ||
| 143 | close(fd); | ||
| 144 | return -1; | ||
| 145 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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 created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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 created+87| ... | @@ -0,0 +1,87 @@ | ||
| 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 created+62| ... | @@ -0,0 +1,62 @@ | ||
| 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 created+82| ... | @@ -0,0 +1,82 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <assert.h> | ||
| 8 | #include <wasi/api.h> | ||
| 9 | #include <wasi/libc.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <fcntl.h> | ||
| 12 | #include <string.h> | ||
| 13 | |||
| 14 | static_assert(O_APPEND == __WASI_FDFLAGS_APPEND, "Value mismatch"); | ||
| 15 | static_assert(O_DSYNC == __WASI_FDFLAGS_DSYNC, "Value mismatch"); | ||
| 16 | static_assert(O_NONBLOCK == __WASI_FDFLAGS_NONBLOCK, "Value mismatch"); | ||
| 17 | static_assert(O_RSYNC == __WASI_FDFLAGS_RSYNC, "Value mismatch"); | ||
| 18 | static_assert(O_SYNC == __WASI_FDFLAGS_SYNC, "Value mismatch"); | ||
| 19 | |||
| 20 | static_assert(O_CREAT >> 12 == __WASI_OFLAGS_CREAT, "Value mismatch"); | ||
| 21 | static_assert(O_DIRECTORY >> 12 == __WASI_OFLAGS_DIRECTORY, "Value mismatch"); | ||
| 22 | static_assert(O_EXCL >> 12 == __WASI_OFLAGS_EXCL, "Value mismatch"); | ||
| 23 | static_assert(O_TRUNC >> 12 == __WASI_OFLAGS_TRUNC, "Value mismatch"); | ||
| 24 | |||
| 25 | int __wasilibc_nocwd_openat_nomode(int fd, const char *path, int oflag) { | ||
| 26 | // Compute rights corresponding with the access modes provided. | ||
| 27 | // Attempt to obtain all rights, except the ones that contradict the | ||
| 28 | // access mode provided to openat(). | ||
| 29 | __wasi_rights_t max = | ||
| 30 | ~(__WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_READ | | ||
| 31 | __WASI_RIGHTS_FD_WRITE | __WASI_RIGHTS_FD_ALLOCATE | | ||
| 32 | __WASI_RIGHTS_FD_READDIR | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE); | ||
| 33 | switch (oflag & O_ACCMODE) { | ||
| 34 | case O_RDONLY: | ||
| 35 | case O_RDWR: | ||
| 36 | case O_WRONLY: | ||
| 37 | if ((oflag & O_RDONLY) != 0) { | ||
| 38 | max |= __WASI_RIGHTS_FD_READ | __WASI_RIGHTS_FD_READDIR; | ||
| 39 | } | ||
| 40 | if ((oflag & O_WRONLY) != 0) { | ||
| 41 | max |= __WASI_RIGHTS_FD_DATASYNC | __WASI_RIGHTS_FD_WRITE | | ||
| 42 | __WASI_RIGHTS_FD_ALLOCATE | | ||
| 43 | __WASI_RIGHTS_FD_FILESTAT_SET_SIZE; | ||
| 44 | } | ||
| 45 | break; | ||
| 46 | case O_EXEC: | ||
| 47 | break; | ||
| 48 | case O_SEARCH: | ||
| 49 | break; | ||
| 50 | default: | ||
| 51 | errno = EINVAL; | ||
| 52 | return -1; | ||
| 53 | } | ||
| 54 | |||
| 55 | // Ensure that we can actually obtain the minimal rights needed. | ||
| 56 | __wasi_fdstat_t fsb_cur; | ||
| 57 | __wasi_errno_t error = __wasi_fd_fdstat_get(fd, &fsb_cur); | ||
| 58 | if (error != 0) { | ||
| 59 | errno = error; | ||
| 60 | return -1; | ||
| 61 | } | ||
| 62 | |||
| 63 | // Path lookup properties. | ||
| 64 | __wasi_lookupflags_t lookup_flags = 0; | ||
| 65 | if ((oflag & O_NOFOLLOW) == 0) | ||
| 66 | lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 67 | |||
| 68 | // Open file with appropriate rights. | ||
| 69 | __wasi_fdflags_t fs_flags = oflag & 0xfff; | ||
| 70 | __wasi_rights_t fs_rights_base = max & fsb_cur.fs_rights_inheriting; | ||
| 71 | __wasi_rights_t fs_rights_inheriting = fsb_cur.fs_rights_inheriting; | ||
| 72 | __wasi_fd_t newfd; | ||
| 73 | error = __wasi_path_open(fd, lookup_flags, path, | ||
| 74 | (oflag >> 12) & 0xfff, | ||
| 75 | fs_rights_base, fs_rights_inheriting, fs_flags, | ||
| 76 | &newfd); | ||
| 77 | if (error != 0) { | ||
| 78 | errno = errno_fixup_directory(fd, error); | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | return newfd; | ||
| 82 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 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 created+13| ... | @@ -0,0 +1,13 @@ | ||
| 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 created+129| ... | @@ -0,0 +1,129 @@ | ||
| 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 | int poll(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 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <string.h> | ||
| 11 | |||
| 12 | int __wasilibc_nocwd_renameat(int oldfd, const char *old, int newfd, const char *new) { | ||
| 13 | __wasi_errno_t error = __wasi_path_rename(oldfd, old, newfd, new); | ||
| 14 | if (error != 0) { | ||
| 15 | errno = errno_fixup_directory(oldfd, errno_fixup_directory(newfd, error)); | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | return 0; | ||
| 19 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 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 <stdlib.h> | ||
| 7 | #include <stdnoreturn.h> | ||
| 8 | #include <unistd.h> | ||
| 9 | |||
| 10 | noreturn void _Exit(int status) { | ||
| 11 | __wasi_proc_exit(status); | ||
| 12 | } | ||
| 13 | |||
| 14 | __strong_reference(_Exit, _exit); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c created+88| ... | @@ -0,0 +1,88 @@ | ||
| 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 <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <stdarg.h> | ||
| 10 | |||
| 11 | int ioctl(int fildes, int request, ...) { | ||
| 12 | switch (request) { | ||
| 13 | case FIONREAD: { | ||
| 14 | // Poll the file descriptor to determine how many bytes can be read. | ||
| 15 | __wasi_subscription_t subscriptions[2] = { | ||
| 16 | { | ||
| 17 | .u.tag = __WASI_EVENTTYPE_FD_READ, | ||
| 18 | .u.u.fd_read.file_descriptor = fildes, | ||
| 19 | }, | ||
| 20 | { | ||
| 21 | .u.tag = __WASI_EVENTTYPE_CLOCK, | ||
| 22 | .u.u.clock.id = __WASI_CLOCKID_MONOTONIC, | ||
| 23 | }, | ||
| 24 | }; | ||
| 25 | __wasi_event_t events[__arraycount(subscriptions)]; | ||
| 26 | size_t nevents; | ||
| 27 | __wasi_errno_t error = __wasi_poll_oneoff( | ||
| 28 | subscriptions, events, __arraycount(subscriptions), &nevents); | ||
| 29 | if (error != 0) { | ||
| 30 | errno = error; | ||
| 31 | return -1; | ||
| 32 | } | ||
| 33 | |||
| 34 | // Location where result should be written. | ||
| 35 | va_list ap; | ||
| 36 | va_start(ap, request); | ||
| 37 | int *result = va_arg(ap, int *); | ||
| 38 | va_end(ap); | ||
| 39 | |||
| 40 | // Extract number of bytes for reading from poll results. | ||
| 41 | for (size_t i = 0; i < nevents; ++i) { | ||
| 42 | __wasi_event_t *event = &events[i]; | ||
| 43 | if (event->error != 0) { | ||
| 44 | errno = event->error; | ||
| 45 | return -1; | ||
| 46 | } | ||
| 47 | if (event->type == __WASI_EVENTTYPE_FD_READ) { | ||
| 48 | *result = event->fd_readwrite.nbytes; | ||
| 49 | return 0; | ||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | // No data available for reading. | ||
| 54 | *result = 0; | ||
| 55 | return 0; | ||
| 56 | } | ||
| 57 | case FIONBIO: { | ||
| 58 | // Obtain the current file descriptor flags. | ||
| 59 | __wasi_fdstat_t fds; | ||
| 60 | __wasi_errno_t error = __wasi_fd_fdstat_get(fildes, &fds); | ||
| 61 | if (error != 0) { | ||
| 62 | errno = error; | ||
| 63 | return -1; | ||
| 64 | } | ||
| 65 | |||
| 66 | // Toggle the non-blocking flag based on the argument. | ||
| 67 | va_list ap; | ||
| 68 | va_start(ap, request); | ||
| 69 | if (*va_arg(ap, const int *) != 0) | ||
| 70 | fds.fs_flags |= __WASI_FDFLAGS_NONBLOCK; | ||
| 71 | else | ||
| 72 | fds.fs_flags &= ~__WASI_FDFLAGS_NONBLOCK; | ||
| 73 | va_end(ap); | ||
| 74 | |||
| 75 | // Update the file descriptor flags. | ||
| 76 | error = __wasi_fd_fdstat_set_flags(fildes, fds.fs_flags); | ||
| 77 | if (error != 0) { | ||
| 78 | errno = error; | ||
| 79 | return -1; | ||
| 80 | } | ||
| 81 | return 0; | ||
| 82 | } | ||
| 83 | default: | ||
| 84 | // Invalid request. | ||
| 85 | errno = EINVAL; | ||
| 86 | return -1; | ||
| 87 | } | ||
| 88 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c created+125| ... | @@ -0,0 +1,125 @@ | ||
| 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 | |||
| 12 | int pselect(int nfds, fd_set *restrict readfds, fd_set *restrict writefds, | ||
| 13 | fd_set *restrict errorfds, const struct timespec *restrict timeout, | ||
| 14 | const sigset_t *sigmask) { | ||
| 15 | // Negative file descriptor upperbound. | ||
| 16 | if (nfds < 0) { | ||
| 17 | errno = EINVAL; | ||
| 18 | return -1; | ||
| 19 | } | ||
| 20 | |||
| 21 | // This implementation does not support polling for exceptional | ||
| 22 | // conditions, such as out-of-band data on TCP sockets. | ||
| 23 | if (errorfds != NULL && errorfds->__nfds > 0) { | ||
| 24 | errno = ENOSYS; | ||
| 25 | return -1; | ||
| 26 | } | ||
| 27 | |||
| 28 | // Replace NULL pointers by the empty set. | ||
| 29 | fd_set empty; | ||
| 30 | FD_ZERO(&empty); | ||
| 31 | if (readfds == NULL) | ||
| 32 | readfds = &empty; | ||
| 33 | if (writefds == NULL) | ||
| 34 | writefds = &empty; | ||
| 35 | |||
| 36 | // Determine the maximum number of events. | ||
| 37 | size_t maxevents = readfds->__nfds + writefds->__nfds + 1; | ||
| 38 | __wasi_subscription_t subscriptions[maxevents]; | ||
| 39 | size_t nsubscriptions = 0; | ||
| 40 | |||
| 41 | // Convert the readfds set. | ||
| 42 | for (size_t i = 0; i < readfds->__nfds; ++i) { | ||
| 43 | int fd = readfds->__fds[i]; | ||
| 44 | if (fd < nfds) { | ||
| 45 | __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; | ||
| 46 | *subscription = (__wasi_subscription_t){ | ||
| 47 | .userdata = fd, | ||
| 48 | .u.tag = __WASI_EVENTTYPE_FD_READ, | ||
| 49 | .u.u.fd_read.file_descriptor = fd, | ||
| 50 | }; | ||
| 51 | } | ||
| 52 | } | ||
| 53 | |||
| 54 | // Convert the writefds set. | ||
| 55 | for (size_t i = 0; i < writefds->__nfds; ++i) { | ||
| 56 | int fd = writefds->__fds[i]; | ||
| 57 | if (fd < nfds) { | ||
| 58 | __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; | ||
| 59 | *subscription = (__wasi_subscription_t){ | ||
| 60 | .userdata = fd, | ||
| 61 | .u.tag = __WASI_EVENTTYPE_FD_WRITE, | ||
| 62 | .u.u.fd_write.file_descriptor = fd, | ||
| 63 | }; | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | // Create extra event for the timeout. | ||
| 68 | if (timeout != NULL) { | ||
| 69 | __wasi_subscription_t *subscription = &subscriptions[nsubscriptions++]; | ||
| 70 | *subscription = (__wasi_subscription_t){ | ||
| 71 | .u.tag = __WASI_EVENTTYPE_CLOCK, | ||
| 72 | .u.u.clock.id = __WASI_CLOCKID_REALTIME, | ||
| 73 | }; | ||
| 74 | if (!timespec_to_timestamp_clamp(timeout, &subscription->u.u.clock.timeout)) { | ||
| 75 | errno = EINVAL; | ||
| 76 | return -1; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | // Execute poll(). | ||
| 81 | size_t nevents; | ||
| 82 | __wasi_event_t events[nsubscriptions]; | ||
| 83 | __wasi_errno_t error = | ||
| 84 | __wasi_poll_oneoff(subscriptions, events, nsubscriptions, &nevents); | ||
| 85 | if (error != 0) { | ||
| 86 | // WASI's poll requires at least one subscription, or else it returns | ||
| 87 | // `EINVAL`. Since a `pselect` with nothing to wait for is valid in POSIX, | ||
| 88 | // return `ENOTSUP` to indicate that we don't support that case. | ||
| 89 | // | ||
| 90 | // Wasm has no signal handling, so if none of the user-provided `pollfd` | ||
| 91 | // elements, nor the timeout, led us to producing even one subscription | ||
| 92 | // to wait for, there would be no way for the poll to wake up. WASI | ||
| 93 | // returns `EINVAL` in this case, but for users of `poll`, `ENOTSUP` is | ||
| 94 | // more likely to be understood. | ||
| 95 | if (nsubscriptions == 0) | ||
| 96 | errno = ENOTSUP; | ||
| 97 | else | ||
| 98 | errno = error; | ||
| 99 | return -1; | ||
| 100 | } | ||
| 101 | |||
| 102 | // Test for EBADF. | ||
| 103 | for (size_t i = 0; i < nevents; ++i) { | ||
| 104 | const __wasi_event_t *event = &events[i]; | ||
| 105 | if ((event->type == __WASI_EVENTTYPE_FD_READ || | ||
| 106 | event->type == __WASI_EVENTTYPE_FD_WRITE) && | ||
| 107 | event->error == __WASI_ERRNO_BADF) { | ||
| 108 | errno = EBADF; | ||
| 109 | return -1; | ||
| 110 | } | ||
| 111 | } | ||
| 112 | |||
| 113 | // Clear and set entries in the result sets. | ||
| 114 | FD_ZERO(readfds); | ||
| 115 | FD_ZERO(writefds); | ||
| 116 | for (size_t i = 0; i < nevents; ++i) { | ||
| 117 | const __wasi_event_t *event = &events[i]; | ||
| 118 | if (event->type == __WASI_EVENTTYPE_FD_READ) { | ||
| 119 | readfds->__fds[readfds->__nfds++] = event->userdata; | ||
| 120 | } else if (event->type == __WASI_EVENTTYPE_FD_WRITE) { | ||
| 121 | writefds->__fds[writefds->__nfds++] = event->userdata; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | return readfds->__nfds + writefds->__nfds; | ||
| 125 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 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 created+48| ... | @@ -0,0 +1,48 @@ | ||
| 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 created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <sys/socket.h> | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <wasi/api.h> | ||
| 11 | #include <errno.h> | ||
| 12 | #include <stdint.h> | ||
| 13 | |||
| 14 | static_assert(MSG_PEEK == __WASI_RIFLAGS_RECV_PEEK, "Value mismatch"); | ||
| 15 | static_assert(MSG_WAITALL == __WASI_RIFLAGS_RECV_WAITALL, "Value mismatch"); | ||
| 16 | |||
| 17 | ssize_t recv(int socket, void *restrict buffer, size_t length, int flags) { | ||
| 18 | // Validate flags. | ||
| 19 | if ((flags & ~(MSG_PEEK | MSG_WAITALL)) != 0) { | ||
| 20 | errno = EOPNOTSUPP; | ||
| 21 | return -1; | ||
| 22 | } | ||
| 23 | |||
| 24 | // Prepare input parameters. | ||
| 25 | __wasi_iovec_t iov = {.buf = buffer, .buf_len = length}; | ||
| 26 | __wasi_iovec_t *ri_data = &iov; | ||
| 27 | size_t ri_data_len = 1; | ||
| 28 | __wasi_riflags_t ri_flags = flags; | ||
| 29 | |||
| 30 | // Perform system call. | ||
| 31 | size_t ro_datalen; | ||
| 32 | __wasi_roflags_t ro_flags; | ||
| 33 | __wasi_errno_t error = __wasi_sock_recv(socket, | ||
| 34 | ri_data, ri_data_len, ri_flags, | ||
| 35 | &ro_datalen, | ||
| 36 | &ro_flags); | ||
| 37 | if (error != 0) { | ||
| 38 | errno = errno_fixup_socket(socket, error); | ||
| 39 | return -1; | ||
| 40 | } | ||
| 41 | return ro_datalen; | ||
| 42 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | // Copyright (c) 2015-2017 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <sys/socket.h> | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <wasi/api.h> | ||
| 11 | #include <errno.h> | ||
| 12 | |||
| 13 | ssize_t send(int socket, const void *buffer, size_t length, int flags) { | ||
| 14 | // This implementation does not support any flags. | ||
| 15 | if (flags != 0) { | ||
| 16 | errno = EOPNOTSUPP; | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | |||
| 20 | // Prepare input parameters. | ||
| 21 | __wasi_ciovec_t iov = {.buf = buffer, .buf_len = length}; | ||
| 22 | __wasi_ciovec_t *si_data = &iov; | ||
| 23 | size_t si_data_len = 1; | ||
| 24 | __wasi_siflags_t si_flags = 0; | ||
| 25 | |||
| 26 | // Perform system call. | ||
| 27 | size_t so_datalen; | ||
| 28 | __wasi_errno_t error = __wasi_sock_send(socket, si_data, si_data_len, si_flags, &so_datalen); | ||
| 29 | if (error != 0) { | ||
| 30 | errno = errno_fixup_socket(socket, error); | ||
| 31 | return -1; | ||
| 32 | } | ||
| 33 | return so_datalen; | ||
| 34 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <sys/socket.h> | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <wasi/api.h> | ||
| 11 | #include <errno.h> | ||
| 12 | |||
| 13 | static_assert(SHUT_RD == __WASI_SDFLAGS_RD, "Value mismatch"); | ||
| 14 | static_assert(SHUT_WR == __WASI_SDFLAGS_WR, "Value mismatch"); | ||
| 15 | |||
| 16 | int shutdown(int socket, int how) { | ||
| 17 | // Validate shutdown flags. | ||
| 18 | if (how != SHUT_RD && how != SHUT_WR && how != SHUT_RDWR) { | ||
| 19 | errno = EINVAL; | ||
| 20 | return -1; | ||
| 21 | } | ||
| 22 | |||
| 23 | __wasi_errno_t error = __wasi_sock_shutdown(socket, how); | ||
| 24 | if (error != 0) { | ||
| 25 | errno = errno_fixup_socket(socket, error); | ||
| 26 | return -1; | ||
| 27 | } | ||
| 28 | return error; | ||
| 29 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/socket_impl.h created+57| ... | @@ -0,0 +1,57 @@ | ||
| 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 created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <sys/stat.h> | ||
| 8 | |||
| 9 | #include <wasi/api.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <fcntl.h> | ||
| 12 | #include <string.h> | ||
| 13 | |||
| 14 | #include "stat_impl.h" | ||
| 15 | |||
| 16 | int __wasilibc_nocwd_fstatat(int fd, const char *restrict path, struct stat *restrict buf, | ||
| 17 | int flag) { | ||
| 18 | // Create lookup properties. | ||
| 19 | __wasi_lookupflags_t lookup_flags = 0; | ||
| 20 | if ((flag & AT_SYMLINK_NOFOLLOW) == 0) | ||
| 21 | lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 22 | |||
| 23 | // Perform system call. | ||
| 24 | __wasi_filestat_t internal_stat; | ||
| 25 | __wasi_errno_t error = | ||
| 26 | __wasi_path_filestat_get(fd, lookup_flags, path, &internal_stat); | ||
| 27 | if (error != 0) { | ||
| 28 | errno = errno_fixup_directory(fd, error); | ||
| 29 | return -1; | ||
| 30 | } | ||
| 31 | to_public_stat(&internal_stat, buf); | ||
| 32 | return 0; | ||
| 33 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 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 created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <sys/stat.h> | ||
| 8 | |||
| 9 | #include <wasi/api.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <string.h> | ||
| 12 | |||
| 13 | int __wasilibc_nocwd_mkdirat_nomode(int fd, const char *path) { | ||
| 14 | __wasi_errno_t error = __wasi_path_create_directory(fd, path); | ||
| 15 | if (error != 0) { | ||
| 16 | errno = errno_fixup_directory(fd, error); | ||
| 17 | return -1; | ||
| 18 | } | ||
| 19 | return 0; | ||
| 20 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h created+110| ... | @@ -0,0 +1,110 @@ | ||
| 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 | } else { | ||
| 79 | // Set individual timestamps. | ||
| 80 | *flags = 0; | ||
| 81 | switch (times[0].tv_nsec) { | ||
| 82 | case UTIME_NOW: | ||
| 83 | *flags |= __WASI_FSTFLAGS_ATIM_NOW; | ||
| 84 | break; | ||
| 85 | case UTIME_OMIT: | ||
| 86 | break; | ||
| 87 | default: | ||
| 88 | *flags |= __WASI_FSTFLAGS_ATIM; | ||
| 89 | if (!timespec_to_timestamp_exact(&times[0], st_atim)) | ||
| 90 | return false; | ||
| 91 | break; | ||
| 92 | } | ||
| 93 | |||
| 94 | switch (times[1].tv_nsec) { | ||
| 95 | case UTIME_NOW: | ||
| 96 | *flags |= __WASI_FSTFLAGS_MTIM_NOW; | ||
| 97 | break; | ||
| 98 | case UTIME_OMIT: | ||
| 99 | break; | ||
| 100 | default: | ||
| 101 | *flags |= __WASI_FSTFLAGS_MTIM; | ||
| 102 | if (!timespec_to_timestamp_exact(&times[1], st_mtim)) | ||
| 103 | return false; | ||
| 104 | break; | ||
| 105 | } | ||
| 106 | } | ||
| 107 | return true; | ||
| 108 | } | ||
| 109 | |||
| 110 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <sys/stat.h> | ||
| 8 | |||
| 9 | #include <wasi/api.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <fcntl.h> | ||
| 12 | #include <string.h> | ||
| 13 | |||
| 14 | #include "stat_impl.h" | ||
| 15 | |||
| 16 | int __wasilibc_nocwd_utimensat(int fd, const char *path, const struct timespec times[2], | ||
| 17 | int flag) { | ||
| 18 | // Convert timestamps and extract NOW/OMIT flags. | ||
| 19 | __wasi_timestamp_t st_atim; | ||
| 20 | __wasi_timestamp_t st_mtim; | ||
| 21 | __wasi_fstflags_t flags; | ||
| 22 | if (!utimens_get_timestamps(times, &st_atim, &st_mtim, &flags)) { | ||
| 23 | errno = EINVAL; | ||
| 24 | return -1; | ||
| 25 | } | ||
| 26 | |||
| 27 | // Create lookup properties. | ||
| 28 | __wasi_lookupflags_t lookup_flags = 0; | ||
| 29 | if ((flag & AT_SYMLINK_NOFOLLOW) == 0) | ||
| 30 | lookup_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 31 | |||
| 32 | // Perform system call. | ||
| 33 | __wasi_errno_t error = | ||
| 34 | __wasi_path_filestat_set_times(fd, lookup_flags, path, st_atim, st_mtim, flags); | ||
| 35 | if (error != 0) { | ||
| 36 | errno = errno_fixup_directory(fd, error); | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | return 0; | ||
| 40 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 | __wasi_timestamp_t ts = 0; | ||
| 13 | (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts); | ||
| 14 | *tp = timestamp_to_timeval(ts); | ||
| 15 | return 0; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 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 created+24| ... | @@ -0,0 +1,24 @@ | ||
| 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 created+40| ... | @@ -0,0 +1,40 @@ | ||
| 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 created+40| ... | @@ -0,0 +1,40 @@ | ||
| 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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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_PROCESS_CPUTIME_ID.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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_PROCESS_CPUTIME_ID = { | ||
| 11 | .id = __WASI_CLOCKID_PROCESS_CPUTIME_ID, | ||
| 12 | }; | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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_THREAD_CPUTIME_ID.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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_THREAD_CPUTIME_ID = { | ||
| 11 | .id = __WASI_CLOCKID_THREAD_CPUTIME_ID, | ||
| 12 | }; | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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 | extern __typeof(__clock_gettime) clock_gettime __attribute__((weak, alias("__clock_gettime"))); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | // Copyright (c) 2015 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <errno.h> | ||
| 6 | #include <threads.h> | ||
| 7 | #include <time.h> | ||
| 8 | |||
| 9 | int nanosleep(const struct timespec *rqtp, struct timespec *rem) { | ||
| 10 | int error = clock_nanosleep(CLOCK_REALTIME, 0, rqtp, rem); | ||
| 11 | if (error != 0) { | ||
| 12 | errno = error; | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | return 0; | ||
| 16 | } | ||
| 17 | |||
| 18 | #if defined(_REENTRANT) | ||
| 19 | __strong_reference(nanosleep, thrd_sleep); | ||
| 20 | #endif | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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/close.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 close(int fildes) { | ||
| 10 | __wasi_errno_t error = __wasi_fd_close(fildes); | ||
| 11 | if (error != 0) { | ||
| 12 | errno = error; | ||
| 13 | return -1; | ||
| 14 | } | ||
| 15 | return 0; | ||
| 16 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | // Copyright (c) 2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <string.h> | ||
| 11 | #include <unistd.h> | ||
| 12 | |||
| 13 | int __wasilibc_nocwd_faccessat(int fd, const char *path, int amode, int flag) { | ||
| 14 | // Validate function parameters. | ||
| 15 | if ((amode & ~(F_OK | R_OK | W_OK | X_OK)) != 0 || | ||
| 16 | (flag & ~AT_EACCESS) != 0) { | ||
| 17 | errno = EINVAL; | ||
| 18 | return -1; | ||
| 19 | } | ||
| 20 | |||
| 21 | // Check for target file existence and obtain the file type. | ||
| 22 | __wasi_lookupflags_t lookup_flags = __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 23 | __wasi_filestat_t file; | ||
| 24 | __wasi_errno_t error = | ||
| 25 | __wasi_path_filestat_get(fd, lookup_flags, path, &file); | ||
| 26 | if (error != 0) { | ||
| 27 | errno = errno_fixup_directory(fd, error); | ||
| 28 | return -1; | ||
| 29 | } | ||
| 30 | |||
| 31 | // Test whether the requested access rights are present on the | ||
| 32 | // directory file descriptor. | ||
| 33 | if (amode != 0) { | ||
| 34 | __wasi_fdstat_t directory; | ||
| 35 | error = __wasi_fd_fdstat_get(fd, &directory); | ||
| 36 | if (error != 0) { | ||
| 37 | errno = error; | ||
| 38 | return -1; | ||
| 39 | } | ||
| 40 | |||
| 41 | __wasi_rights_t min = 0; | ||
| 42 | if ((amode & R_OK) != 0) | ||
| 43 | min |= file.filetype == __WASI_FILETYPE_DIRECTORY | ||
| 44 | ? __WASI_RIGHTS_FD_READDIR | ||
| 45 | : __WASI_RIGHTS_FD_READ; | ||
| 46 | if ((amode & W_OK) != 0) | ||
| 47 | min |= __WASI_RIGHTS_FD_WRITE; | ||
| 48 | |||
| 49 | if ((min & directory.fs_rights_inheriting) != min) { | ||
| 50 | errno = EACCES; | ||
| 51 | return -1; | ||
| 52 | } | ||
| 53 | } | ||
| 54 | return 0; | ||
| 55 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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 created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <string.h> | ||
| 11 | #include <unistd.h> | ||
| 12 | |||
| 13 | int __wasilibc_nocwd_linkat(int fd1, const char *path1, int fd2, const char *path2, int flag) { | ||
| 14 | // Create lookup properties. | ||
| 15 | __wasi_lookupflags_t lookup1_flags = 0; | ||
| 16 | if ((flag & AT_SYMLINK_FOLLOW) != 0) | ||
| 17 | lookup1_flags |= __WASI_LOOKUPFLAGS_SYMLINK_FOLLOW; | ||
| 18 | |||
| 19 | // Perform system call. | ||
| 20 | __wasi_errno_t error = __wasi_path_link(fd1, lookup1_flags, path1, fd2, path2); | ||
| 21 | if (error != 0) { | ||
| 22 | errno = errno_fixup_directory(fd1, errno_fixup_directory(fd2, error)); | ||
| 23 | return -1; | ||
| 24 | } | ||
| 25 | return 0; | ||
| 26 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 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 | extern __typeof(__lseek) lseek __attribute__((weak, alias("__lseek"))); | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 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 created+31| ... | @@ -0,0 +1,31 @@ | ||
| 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 created+18| ... | @@ -0,0 +1,18 @@ | ||
| 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 created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | ssize_t __wasilibc_nocwd_readlinkat(int fd, const char *restrict path, char *restrict buf, | ||
| 13 | size_t bufsize) { | ||
| 14 | size_t bufused; | ||
| 15 | // TODO: Remove the cast on `buf` once the witx is updated with char8 support. | ||
| 16 | __wasi_errno_t error = __wasi_path_readlink(fd, path, | ||
| 17 | (uint8_t*)buf, bufsize, &bufused); | ||
| 18 | if (error != 0) { | ||
| 19 | errno = errno_fixup_directory(fd, error); | ||
| 20 | return -1; | ||
| 21 | } | ||
| 22 | return bufused; | ||
| 23 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | |||
| 12 | int __wasilibc_nocwd_symlinkat(const char *path1, int fd, const char *path2) { | ||
| 13 | __wasi_errno_t error = __wasi_path_symlink(path1, fd, path2); | ||
| 14 | if (error != 0) { | ||
| 15 | errno = errno_fixup_directory(fd, error); | ||
| 16 | return -1; | ||
| 17 | } | ||
| 18 | return 0; | ||
| 19 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | // Copyright (c) 2015-2016 Nuxi, https://nuxi.nl/ | ||
| 2 | // | ||
| 3 | // SPDX-License-Identifier: BSD-2-Clause | ||
| 4 | |||
| 5 | #include <common/errno.h> | ||
| 6 | |||
| 7 | #include <wasi/api.h> | ||
| 8 | #include <wasi/libc.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include <fcntl.h> | ||
| 11 | #include <string.h> | ||
| 12 | #include <unistd.h> | ||
| 13 | |||
| 14 | int unlinkat(int fd, const char *path, int flag) { | ||
| 15 | if ((flag & AT_REMOVEDIR) != 0) { | ||
| 16 | return __wasilibc_rmdirat(fd, path); | ||
| 17 | } | ||
| 18 | return __wasilibc_unlinkat(fd, path); | ||
| 19 | } | ||
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 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 created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | extern void __wasm_call_ctors(void); | ||
| 4 | extern int __original_main(void); | ||
| 5 | extern void __wasm_call_dtors(void); | ||
| 6 | |||
| 7 | __attribute__((export_name("_start"))) | ||
| 8 | void _start(void) { | ||
| 9 | // Call `__original_main` which will either be the application's zero-argument | ||
| 10 | // `__original_main` function or a libc routine which calls `__main_void`. | ||
| 11 | // TODO: Call `main` directly once we no longer have to support old compilers. | ||
| 12 | int r = __original_main(); | ||
| 13 | |||
| 14 | // If main exited successfully, just return, otherwise call `exit`. | ||
| 15 | if (r != 0) { | ||
| 16 | exit(r); | ||
| 17 | } | ||
| 18 | } | ||
lib/libc/wasi/libc-bottom-half/crt/crt1-reactor.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | extern void __wasm_call_ctors(void); | ||
| 2 | |||
| 3 | __attribute__((export_name("_initialize"))) | ||
| 4 | void _initialize(void) { | ||
| 5 | // The linker synthesizes this to call constructors. | ||
| 6 | __wasm_call_ctors(); | ||
| 7 | } | ||
lib/libc/wasi/libc-bottom-half/crt/crt1.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | extern void __wasm_call_ctors(void); | ||
| 3 | extern int __original_main(void); | ||
| 4 | extern void __wasm_call_dtors(void); | ||
| 5 | |||
| 6 | __attribute__((export_name("_start"))) | ||
| 7 | void _start(void) { | ||
| 8 | // The linker synthesizes this to call constructors. | ||
| 9 | __wasm_call_ctors(); | ||
| 10 | |||
| 11 | // Call `__original_main` which will either be the application's zero-argument | ||
| 12 | // `__original_main` function or a libc routine which calls `__main_void`. | ||
| 13 | // TODO: Call `main` directly once we no longer have to support old compilers. | ||
| 14 | int r = __original_main(); | ||
| 15 | |||
| 16 | // Call atexit functions, destructors, stdio cleanup, etc. | ||
| 17 | __wasm_call_dtors(); | ||
| 18 | |||
| 19 | // If main exited successfully, just return, otherwise call | ||
| 20 | // `__wasi_proc_exit`. | ||
| 21 | if (r != 0) { | ||
| 22 | __wasi_proc_exit(r); | ||
| 23 | } | ||
| 24 | } | ||
lib/libc/wasi/libc-bottom-half/getpid/getpid.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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 created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <limits.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timespec.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__struct_timespec.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/struct/timeval.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__struct_timeval.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/_/types.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 createdlib/libc/wasi/libc-bottom-half/headers/private/errno.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include_next <errno.h> | ||
| 2 | #define EOPNOTSUPP ENOTSUP | ||
lib/libc/wasi/libc-bottom-half/headers/private/fcntl.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include_next <fcntl.h> | ||
| 2 | #include <_/types.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/sched.h createdlib/libc/wasi/libc-bottom-half/headers/private/stdarg.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include_next <stdarg.h> | ||
| 2 | #include <_/cdefs.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/stdint.h created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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 created+3| ... | @@ -0,0 +1,3 @@ | ||
| 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 created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #define __need_size_t | ||
| 2 | #define __need_wchar_t | ||
| 3 | #define __need_NULL | ||
| 4 | #include <stddef.h> | ||
| 5 | |||
| 6 | #include_next <stdlib.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/string.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include_next <string.h> | ||
| 2 | #include <_/cdefs.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/sys/mman.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include_next <sys/mman.h> | ||
| 2 | #include <_/types.h> | ||
lib/libc/wasi/libc-bottom-half/headers/private/threads.h created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #ifndef __cplusplus | ||
| 2 | #define thread_local _Thread_local | ||
| 3 | #endif | ||
lib/libc/wasi/libc-bottom-half/mman/mman.c created+124| ... | @@ -0,0 +1,124 @@ | ||
| 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 <sys/mman.h> | ||
| 13 | #include <sys/types.h> | ||
| 14 | |||
| 15 | struct map { | ||
| 16 | int prot; | ||
| 17 | int flags; | ||
| 18 | off_t offset; | ||
| 19 | size_t length; | ||
| 20 | }; | ||
| 21 | |||
| 22 | void *mmap(void *addr, size_t length, int prot, int flags, | ||
| 23 | int fd, off_t offset) { | ||
| 24 | // Check for unsupported flags. | ||
| 25 | if ((flags & (MAP_PRIVATE | MAP_SHARED)) == 0 || | ||
| 26 | (flags & MAP_FIXED) != 0 || | ||
| 27 | #ifdef MAP_SHARED_VALIDATE | ||
| 28 | (flags & MAP_SHARED_VALIDATE) == MAP_SHARED_VALIDATE || | ||
| 29 | #endif | ||
| 30 | #ifdef MAP_NORESERVE | ||
| 31 | (flags & MAP_NORESERVE) != 0 || | ||
| 32 | #endif | ||
| 33 | #ifdef MAP_GROWSDOWN | ||
| 34 | (flags & MAP_GROWSDOWN) != 0 || | ||
| 35 | #endif | ||
| 36 | #ifdef MAP_HUGETLB | ||
| 37 | (flags & MAP_HUGETLB) != 0 || | ||
| 38 | #endif | ||
| 39 | #ifdef MAP_FIXED_NOREPLACE | ||
| 40 | (flags & MAP_FIXED_NOREPLACE) != 0 || | ||
| 41 | #endif | ||
| 42 | 0) | ||
| 43 | { | ||
| 44 | errno = EINVAL; | ||
| 45 | return MAP_FAILED; | ||
| 46 | } | ||
| 47 | |||
| 48 | // Check for unsupported protection requests. | ||
| 49 | if (prot == PROT_NONE || | ||
| 50 | #ifdef PROT_EXEC | ||
| 51 | (prot & PROT_EXEC) != 0 || | ||
| 52 | #endif | ||
| 53 | 0) | ||
| 54 | { | ||
| 55 | errno = EINVAL; | ||
| 56 | return MAP_FAILED; | ||
| 57 | } | ||
| 58 | |||
| 59 | // To be consistent with POSIX. | ||
| 60 | if (length == 0) { | ||
| 61 | errno = EINVAL; | ||
| 62 | return MAP_FAILED; | ||
| 63 | } | ||
| 64 | |||
| 65 | // Check for integer overflow. | ||
| 66 | size_t buf_len = 0; | ||
| 67 | if (__builtin_add_overflow(length, sizeof(struct map), &buf_len)) { | ||
| 68 | errno = ENOMEM; | ||
| 69 | return MAP_FAILED; | ||
| 70 | } | ||
| 71 | |||
| 72 | // Allocate the memory. | ||
| 73 | struct map *map = malloc(buf_len); | ||
| 74 | if (!map) { | ||
| 75 | errno = ENOMEM; | ||
| 76 | return MAP_FAILED; | ||
| 77 | } | ||
| 78 | |||
| 79 | // Initialize the header. | ||
| 80 | map->prot = prot; | ||
| 81 | map->flags = flags; | ||
| 82 | map->offset = offset; | ||
| 83 | map->length = length; | ||
| 84 | |||
| 85 | // Initialize the main memory buffer, either with the contents of a file, | ||
| 86 | // or with zeros. | ||
| 87 | addr = map + 1; | ||
| 88 | if ((flags & MAP_ANON) == 0) { | ||
| 89 | char *body = (char *)addr; | ||
| 90 | while (length > 0) { | ||
| 91 | const ssize_t nread = pread(fd, body, length, offset); | ||
| 92 | if (nread < 0) { | ||
| 93 | if (errno == EINTR) | ||
| 94 | continue; | ||
| 95 | return MAP_FAILED; | ||
| 96 | } | ||
| 97 | if (nread == 0) | ||
| 98 | break; | ||
| 99 | length -= (size_t)nread; | ||
| 100 | offset += (size_t)nread; | ||
| 101 | body += (size_t)nread; | ||
| 102 | } | ||
| 103 | } else { | ||
| 104 | memset(addr, 0, length); | ||
| 105 | } | ||
| 106 | |||
| 107 | return addr; | ||
| 108 | } | ||
| 109 | |||
| 110 | int munmap(void *addr, size_t length) { | ||
| 111 | struct map *map = (struct map *)addr - 1; | ||
| 112 | |||
| 113 | // We don't support partial munmapping. | ||
| 114 | if (map->length != length) { | ||
| 115 | errno = EINVAL; | ||
| 116 | return -1; | ||
| 117 | } | ||
| 118 | |||
| 119 | // Release the memory. | ||
| 120 | free(map); | ||
| 121 | |||
| 122 | // Success! | ||
| 123 | return 0; | ||
| 124 | } | ||
lib/libc/wasi/libc-bottom-half/signal/signal.c created+142| ... | @@ -0,0 +1,142 @@ | ||
| 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 recieved fatal signal: %s\n", strsignal(sig)); | ||
| 28 | abort(); | ||
| 29 | } | ||
| 30 | |||
| 31 | _Noreturn | ||
| 32 | static void terminate_handler(int sig) { | ||
| 33 | fprintf(stderr, "Program recieved termination signal: %s\n", strsignal(sig)); | ||
| 34 | abort(); | ||
| 35 | } | ||
| 36 | |||
| 37 | _Noreturn | ||
| 38 | static void stop_handler(int sig) { | ||
| 39 | fprintf(stderr, "Program recieved 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/__main_argc_argv.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | // New compilers define `__main_argc_argv`. If that doesn't exist, we | ||
| 2 | // may get called here. Old compilers define `main` expecting an | ||
| 3 | // argv/argc, so call that. | ||
| 4 | // TODO: Remove this layer when we no longer have to support old compilers. | ||
| 5 | int __wasilibc_main(int argc, char *argv[]) asm("main"); | ||
| 6 | |||
| 7 | __attribute__((weak, nodebug)) | ||
| 8 | int __main_argc_argv(int argc, char *argv[]) { | ||
| 9 | return __wasilibc_main(argc, argv); | ||
| 10 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__main_void.c created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sysexits.h> | ||
| 4 | |||
| 5 | // The user's `main` function, expecting arguments. | ||
| 6 | int __main_argc_argv(int argc, char *argv[]); | ||
| 7 | |||
| 8 | // If the user's `main` function expects arguments, the compiler will rename | ||
| 9 | // it to `__main_argc_argv`, and this version will get linked in, which | ||
| 10 | // initializes the argument data and calls `__main_argc_argv`. | ||
| 11 | __attribute__((weak, nodebug)) | ||
| 12 | int __main_void(void) { | ||
| 13 | __wasi_errno_t err; | ||
| 14 | |||
| 15 | // Get the sizes of the arrays we'll have to create to copy in the args. | ||
| 16 | size_t argv_buf_size; | ||
| 17 | size_t argc; | ||
| 18 | err = __wasi_args_sizes_get(&argc, &argv_buf_size); | ||
| 19 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 20 | _Exit(EX_OSERR); | ||
| 21 | } | ||
| 22 | |||
| 23 | // Add 1 for the NULL pointer to mark the end, and check for overflow. | ||
| 24 | size_t num_ptrs = argc + 1; | ||
| 25 | if (num_ptrs == 0) { | ||
| 26 | _Exit(EX_SOFTWARE); | ||
| 27 | } | ||
| 28 | |||
| 29 | // Allocate memory for storing the argument chars. | ||
| 30 | char *argv_buf = malloc(argv_buf_size); | ||
| 31 | if (argv_buf == NULL) { | ||
| 32 | _Exit(EX_SOFTWARE); | ||
| 33 | } | ||
| 34 | |||
| 35 | // Allocate memory for the array of pointers. This uses `calloc` both to | ||
| 36 | // handle overflow and to initialize the NULL pointer at the end. | ||
| 37 | char **argv = calloc(num_ptrs, sizeof(char *)); | ||
| 38 | if (argv == NULL) { | ||
| 39 | free(argv_buf); | ||
| 40 | _Exit(EX_SOFTWARE); | ||
| 41 | } | ||
| 42 | |||
| 43 | // Fill the argument chars, and the argv array with pointers into those chars. | ||
| 44 | // TODO: Remove the casts on `argv_ptrs` and `argv_buf` once the witx is updated with char8 support. | ||
| 45 | err = __wasi_args_get((uint8_t **)argv, (uint8_t *)argv_buf); | ||
| 46 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 47 | free(argv_buf); | ||
| 48 | free(argv); | ||
| 49 | _Exit(EX_OSERR); | ||
| 50 | } | ||
| 51 | |||
| 52 | // Call `__main_argc_argv` with the arguments! | ||
| 53 | return __main_argc_argv(argc, argv); | ||
| 54 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__original_main.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | // Old compilers define `__original_main`. If that doesn't exist, we | ||
| 2 | // get called here. New compilers define `__main_void`. If that doesn't | ||
| 3 | // exist, we'll try something else. | ||
| 4 | // TODO: Remove this layer when we no longer have to support old compilers. | ||
| 5 | int __main_void(void); | ||
| 6 | |||
| 7 | __attribute__((weak)) | ||
| 8 | int __original_main(void) { | ||
| 9 | return __main_void(); | ||
| 10 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 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 | __wasi_errno_t error = __wasi_fd_renumber(fd, newfd); | ||
| 8 | if (error != 0) { | ||
| 9 | errno = error; | ||
| 10 | return -1; | ||
| 11 | } | ||
| 12 | return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c created+77| ... | @@ -0,0 +1,77 @@ | ||
| 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 doesn't use `environ`, it'll get this version of | ||
| 9 | /// `__wasilibc_environ`, which isn't initialized with a constructor function. | ||
| 10 | /// `getenv` etc. call `__wasilibc_ensure_environ()` before accessing it. | ||
| 11 | /// Statically-initialize it to an invalid pointer value so that we can | ||
| 12 | /// detect if it's been explicitly initialized (we can't use `NULL` because | ||
| 13 | /// `clearenv` sets it to NULL. | ||
| 14 | char **__wasilibc_environ __attribute__((weak)) = (char **)-1; | ||
| 15 | |||
| 16 | // See the comments in libc-environ.h. | ||
| 17 | void __wasilibc_ensure_environ(void) { | ||
| 18 | if (__wasilibc_environ == (char **)-1) { | ||
| 19 | __wasilibc_initialize_environ(); | ||
| 20 | } | ||
| 21 | } | ||
| 22 | |||
| 23 | /// Avoid dynamic allocation for the case where there are no environment | ||
| 24 | /// variables, but we still need a non-NULL pointer to an (empty) array. | ||
| 25 | static char *empty_environ[1] = { NULL }; | ||
| 26 | |||
| 27 | // See the comments in libc-environ.h. | ||
| 28 | void __wasilibc_initialize_environ(void) { | ||
| 29 | // Get the sizes of the arrays we'll have to create to copy in the environment. | ||
| 30 | size_t environ_count; | ||
| 31 | size_t environ_buf_size; | ||
| 32 | __wasi_errno_t err = __wasi_environ_sizes_get(&environ_count, &environ_buf_size); | ||
| 33 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 34 | goto oserr; | ||
| 35 | } | ||
| 36 | if (environ_count == 0) { | ||
| 37 | __wasilibc_environ = empty_environ; | ||
| 38 | return; | ||
| 39 | } | ||
| 40 | |||
| 41 | // Add 1 for the NULL pointer to mark the end, and check for overflow. | ||
| 42 | size_t num_ptrs = environ_count + 1; | ||
| 43 | if (num_ptrs == 0) { | ||
| 44 | goto software; | ||
| 45 | } | ||
| 46 | |||
| 47 | // Allocate memory for storing the environment chars. | ||
| 48 | char *environ_buf = malloc(environ_buf_size); | ||
| 49 | if (environ_buf == NULL) { | ||
| 50 | goto software; | ||
| 51 | } | ||
| 52 | |||
| 53 | // Allocate memory for the array of pointers. This uses `calloc` both to | ||
| 54 | // handle overflow and to initialize the NULL pointer at the end. | ||
| 55 | char **environ_ptrs = calloc(num_ptrs, sizeof(char *)); | ||
| 56 | if (environ_ptrs == NULL) { | ||
| 57 | free(environ_buf); | ||
| 58 | goto software; | ||
| 59 | } | ||
| 60 | |||
| 61 | // Fill the environment chars, and the `__wasilibc_environ` array with | ||
| 62 | // pointers into those chars. | ||
| 63 | // TODO: Remove the casts on `environ_ptrs` and `environ_buf` once the witx is updated with char8 support. | ||
| 64 | err = __wasi_environ_get((uint8_t **)environ_ptrs, (uint8_t *)environ_buf); | ||
| 65 | if (err != __WASI_ERRNO_SUCCESS) { | ||
| 66 | free(environ_buf); | ||
| 67 | free(environ_ptrs); | ||
| 68 | goto oserr; | ||
| 69 | } | ||
| 70 | |||
| 71 | __wasilibc_environ = environ_ptrs; | ||
| 72 | return; | ||
| 73 | oserr: | ||
| 74 | _Exit(EX_OSERR); | ||
| 75 | software: | ||
| 76 | _Exit(EX_SOFTWARE); | ||
| 77 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c created+659| ... | @@ -0,0 +1,659 @@ | ||
| 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_proc_raise(int32_t arg0) __attribute__(( | ||
| 578 | __import_module__("wasi_snapshot_preview1"), | ||
| 579 | __import_name__("proc_raise") | ||
| 580 | )); | ||
| 581 | |||
| 582 | __wasi_errno_t __wasi_proc_raise( | ||
| 583 | __wasi_signal_t sig | ||
| 584 | ){ | ||
| 585 | int32_t ret = __imported_wasi_snapshot_preview1_proc_raise((int32_t) sig); | ||
| 586 | return (uint16_t) ret; | ||
| 587 | } | ||
| 588 | |||
| 589 | int32_t __imported_wasi_snapshot_preview1_sched_yield() __attribute__(( | ||
| 590 | __import_module__("wasi_snapshot_preview1"), | ||
| 591 | __import_name__("sched_yield") | ||
| 592 | )); | ||
| 593 | |||
| 594 | __wasi_errno_t __wasi_sched_yield( | ||
| 595 | void | ||
| 596 | ){ | ||
| 597 | int32_t ret = __imported_wasi_snapshot_preview1_sched_yield(); | ||
| 598 | return (uint16_t) ret; | ||
| 599 | } | ||
| 600 | |||
| 601 | int32_t __imported_wasi_snapshot_preview1_random_get(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 602 | __import_module__("wasi_snapshot_preview1"), | ||
| 603 | __import_name__("random_get") | ||
| 604 | )); | ||
| 605 | |||
| 606 | __wasi_errno_t __wasi_random_get( | ||
| 607 | uint8_t * buf, | ||
| 608 | __wasi_size_t buf_len | ||
| 609 | ){ | ||
| 610 | int32_t ret = __imported_wasi_snapshot_preview1_random_get((int32_t) buf, (int32_t) buf_len); | ||
| 611 | return (uint16_t) ret; | ||
| 612 | } | ||
| 613 | |||
| 614 | 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__(( | ||
| 615 | __import_module__("wasi_snapshot_preview1"), | ||
| 616 | __import_name__("sock_recv") | ||
| 617 | )); | ||
| 618 | |||
| 619 | __wasi_errno_t __wasi_sock_recv( | ||
| 620 | __wasi_fd_t fd, | ||
| 621 | const __wasi_iovec_t *ri_data, | ||
| 622 | size_t ri_data_len, | ||
| 623 | __wasi_riflags_t ri_flags, | ||
| 624 | __wasi_size_t *retptr0, | ||
| 625 | __wasi_roflags_t *retptr1 | ||
| 626 | ){ | ||
| 627 | 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); | ||
| 628 | return (uint16_t) ret; | ||
| 629 | } | ||
| 630 | |||
| 631 | int32_t __imported_wasi_snapshot_preview1_sock_send(int32_t arg0, int32_t arg1, int32_t arg2, int32_t arg3, int32_t arg4) __attribute__(( | ||
| 632 | __import_module__("wasi_snapshot_preview1"), | ||
| 633 | __import_name__("sock_send") | ||
| 634 | )); | ||
| 635 | |||
| 636 | __wasi_errno_t __wasi_sock_send( | ||
| 637 | __wasi_fd_t fd, | ||
| 638 | const __wasi_ciovec_t *si_data, | ||
| 639 | size_t si_data_len, | ||
| 640 | __wasi_siflags_t si_flags, | ||
| 641 | __wasi_size_t *retptr0 | ||
| 642 | ){ | ||
| 643 | 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); | ||
| 644 | return (uint16_t) ret; | ||
| 645 | } | ||
| 646 | |||
| 647 | int32_t __imported_wasi_snapshot_preview1_sock_shutdown(int32_t arg0, int32_t arg1) __attribute__(( | ||
| 648 | __import_module__("wasi_snapshot_preview1"), | ||
| 649 | __import_name__("sock_shutdown") | ||
| 650 | )); | ||
| 651 | |||
| 652 | __wasi_errno_t __wasi_sock_shutdown( | ||
| 653 | __wasi_fd_t fd, | ||
| 654 | __wasi_sdflags_t how | ||
| 655 | ){ | ||
| 656 | int32_t ret = __imported_wasi_snapshot_preview1_sock_shutdown((int32_t) fd, how); | ||
| 657 | return (uint16_t) ret; | ||
| 658 | } | ||
| 659 | |||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <common/errno.h> | ||
| 2 | #include <wasi/api.h> | ||
| 3 | #include <wasi/libc.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | int __wasilibc_nocwd___wasilibc_rmdirat(int fd, const char *path) { | ||
| 7 | __wasi_errno_t error = __wasi_path_remove_directory(fd, path); | ||
| 8 | if (error != 0) { | ||
| 9 | errno = errno_fixup_directory(fd, error); | ||
| 10 | return -1; | ||
| 11 | } | ||
| 12 | return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_tell.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 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 created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <common/errno.h> | ||
| 2 | #include <wasi/api.h> | ||
| 3 | #include <wasi/libc.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | int __wasilibc_nocwd___wasilibc_unlinkat(int fd, const char *path) { | ||
| 7 | __wasi_errno_t error = __wasi_path_unlink_file(fd, path); | ||
| 8 | if (error != 0) { | ||
| 9 | errno = error; | ||
| 10 | return -1; | ||
| 11 | } | ||
| 12 | return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-bottom-half/sources/abort.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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/at_fdcwd.c created+141| ... | @@ -0,0 +1,141 @@ | ||
| 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 created+151| ... | @@ -0,0 +1,151 @@ | ||
| 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 | #error "chdir doesn't yet support multiple threads" | ||
| 13 | #endif | ||
| 14 | |||
| 15 | extern char *__wasilibc_cwd; | ||
| 16 | static int __wasilibc_cwd_mallocd = 0; | ||
| 17 | |||
| 18 | int chdir(const char *path) | ||
| 19 | { | ||
| 20 | static char *relative_buf = NULL; | ||
| 21 | static size_t relative_buf_len = 0; | ||
| 22 | |||
| 23 | // Find a preopen'd directory as well as a relative path we're anchored | ||
| 24 | // from which we're changing directories to. | ||
| 25 | const char *abs; | ||
| 26 | int parent_fd = __wasilibc_find_relpath_alloc(path, &abs, &relative_buf, &relative_buf_len, 1); | ||
| 27 | if (parent_fd == -1) | ||
| 28 | return -1; | ||
| 29 | |||
| 30 | // Make sure that this directory we're accessing is indeed a directory. | ||
| 31 | struct stat dirinfo; | ||
| 32 | int ret = fstatat(parent_fd, relative_buf, &dirinfo, 0); | ||
| 33 | if (ret == -1) | ||
| 34 | return -1; | ||
| 35 | if (!S_ISDIR(dirinfo.st_mode)) { | ||
| 36 | errno = ENOTDIR; | ||
| 37 | return -1; | ||
| 38 | } | ||
| 39 | |||
| 40 | // Create a string that looks like: | ||
| 41 | // | ||
| 42 | // __wasilibc_cwd = "/" + abs + "/" + relative_buf | ||
| 43 | // | ||
| 44 | // If `relative_buf` is equal to "." or `abs` is equal to the empty string, | ||
| 45 | // however, we skip that part and the middle slash. | ||
| 46 | size_t len = strlen(abs) + 1; | ||
| 47 | int copy_relative = strcmp(relative_buf, ".") != 0; | ||
| 48 | int mid = copy_relative && abs[0] != 0; | ||
| 49 | char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0)); | ||
| 50 | if (new_cwd == NULL) { | ||
| 51 | errno = ENOMEM; | ||
| 52 | return -1; | ||
| 53 | } | ||
| 54 | new_cwd[0] = '/'; | ||
| 55 | strcpy(new_cwd + 1, abs); | ||
| 56 | if (mid) | ||
| 57 | new_cwd[strlen(abs) + 1] = '/'; | ||
| 58 | if (copy_relative) | ||
| 59 | strcpy(new_cwd + 1 + mid + strlen(abs), relative_buf); | ||
| 60 | |||
| 61 | // And set our new malloc'd buffer into the global cwd, freeing the | ||
| 62 | // previous one if necessary. | ||
| 63 | char *prev_cwd = __wasilibc_cwd; | ||
| 64 | __wasilibc_cwd = new_cwd; | ||
| 65 | if (__wasilibc_cwd_mallocd) | ||
| 66 | free(prev_cwd); | ||
| 67 | __wasilibc_cwd_mallocd = 1; | ||
| 68 | return 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | static const char *make_absolute(const char *path) { | ||
| 72 | static char *make_absolute_buf = NULL; | ||
| 73 | static size_t make_absolute_len = 0; | ||
| 74 | |||
| 75 | // If this path is absolute, then we return it as-is. | ||
| 76 | if (path[0] == '/') { | ||
| 77 | return path; | ||
| 78 | } | ||
| 79 | |||
| 80 | // If the path is empty, or points to the current directory, then return | ||
| 81 | // the current directory. | ||
| 82 | if (path[0] == 0 || !strcmp(path, ".") || !strcmp(path, "./")) { | ||
| 83 | return __wasilibc_cwd; | ||
| 84 | } | ||
| 85 | |||
| 86 | // If the path starts with `./` then we won't be appending that to the cwd. | ||
| 87 | if (path[0] == '.' && path[1] == '/') | ||
| 88 | path += 2; | ||
| 89 | |||
| 90 | // Otherwise we'll take the current directory, add a `/`, and then add the | ||
| 91 | // input `path`. Note that this doesn't do any normalization (like removing | ||
| 92 | // `/./`). | ||
| 93 | size_t cwd_len = strlen(__wasilibc_cwd); | ||
| 94 | size_t path_len = strlen(path); | ||
| 95 | int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1; | ||
| 96 | size_t alloc_len = cwd_len + path_len + 1 + need_slash; | ||
| 97 | if (alloc_len > make_absolute_len) { | ||
| 98 | make_absolute_buf = realloc(make_absolute_buf, alloc_len); | ||
| 99 | if (make_absolute_buf == NULL) | ||
| 100 | return NULL; | ||
| 101 | make_absolute_len = alloc_len; | ||
| 102 | } | ||
| 103 | strcpy(make_absolute_buf, __wasilibc_cwd); | ||
| 104 | if (need_slash) | ||
| 105 | strcpy(make_absolute_buf + cwd_len, "/"); | ||
| 106 | strcpy(make_absolute_buf + cwd_len + need_slash, path); | ||
| 107 | return make_absolute_buf; | ||
| 108 | } | ||
| 109 | |||
| 110 | // Helper function defined only in this object file and weakly referenced from | ||
| 111 | // `preopens.c` and `posix.c` This function isn't necessary unless `chdir` is | ||
| 112 | // pulled in because all paths are otherwise absolute or relative to the root. | ||
| 113 | int __wasilibc_find_relpath_alloc( | ||
| 114 | const char *path, | ||
| 115 | const char **abs_prefix, | ||
| 116 | char **relative_buf, | ||
| 117 | size_t *relative_buf_len, | ||
| 118 | int can_realloc | ||
| 119 | ) { | ||
| 120 | // First, make our path absolute taking the cwd into account. | ||
| 121 | const char *abspath = make_absolute(path); | ||
| 122 | if (abspath == NULL) { | ||
| 123 | errno = ENOMEM; | ||
| 124 | return -1; | ||
| 125 | } | ||
| 126 | |||
| 127 | // Next use our absolute path and split it. Find the preopened `fd` parent | ||
| 128 | // directory and set `abs_prefix`. Next up we'll be trying to fit `rel` | ||
| 129 | // into `relative_buf`. | ||
| 130 | const char *rel; | ||
| 131 | int fd = __wasilibc_find_abspath(abspath, abs_prefix, &rel); | ||
| 132 | if (fd == -1) | ||
| 133 | return -1; | ||
| 134 | |||
| 135 | size_t rel_len = strlen(rel); | ||
| 136 | if (*relative_buf_len < rel_len + 1) { | ||
| 137 | if (!can_realloc) { | ||
| 138 | errno = ERANGE; | ||
| 139 | return -1; | ||
| 140 | } | ||
| 141 | char *tmp = realloc(*relative_buf, rel_len + 1); | ||
| 142 | if (tmp == NULL) { | ||
| 143 | errno = ENOMEM; | ||
| 144 | return -1; | ||
| 145 | } | ||
| 146 | *relative_buf = tmp; | ||
| 147 | *relative_buf_len = rel_len + 1; | ||
| 148 | } | ||
| 149 | strcpy(*relative_buf, rel); | ||
| 150 | return fd; | ||
| 151 | } | ||
lib/libc/wasi/libc-bottom-half/sources/complex-builtins.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 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 created+26| ... | @@ -0,0 +1,26 @@ | ||
| 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 | extern __typeof(__wasilibc_environ) _environ | ||
| 13 | __attribute__((weak, alias("__wasilibc_environ"))); | ||
| 14 | extern __typeof(__wasilibc_environ) environ | ||
| 15 | __attribute__((weak, alias("__wasilibc_environ"))); | ||
| 16 | |||
| 17 | // We define this function here in the same source file as | ||
| 18 | // `__wasilibc_environ`, so that this function is called in iff environment | ||
| 19 | // variable support is used. | ||
| 20 | // Concerning the 50 -- levels up to 100 are reserved for the implementation, | ||
| 21 | // so we an arbitrary number in the middle of the range to allow other | ||
| 22 | // reserved things to go before or after. | ||
| 23 | __attribute__((constructor(50))) | ||
| 24 | static void __wasilibc_initialize_environ_eagerly(void) { | ||
| 25 | __wasilibc_initialize_environ(); | ||
| 26 | } | ||
lib/libc/wasi/libc-bottom-half/sources/errno.c created+5| ... | @@ -0,0 +1,5 @@ | ||
| 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 created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | // For threads this needs to synchronize with chdir | ||
| 6 | #ifdef _REENTRANT | ||
| 7 | #error "getcwd doesn't yet support multiple threads" | ||
| 8 | #endif | ||
| 9 | |||
| 10 | char *__wasilibc_cwd = "/"; | ||
| 11 | |||
| 12 | char *getcwd(char *buf, size_t size) | ||
| 13 | { | ||
| 14 | if (!buf) { | ||
| 15 | buf = strdup(__wasilibc_cwd); | ||
| 16 | if (!buf) { | ||
| 17 | errno = ENOMEM; | ||
| 18 | return NULL; | ||
| 19 | } | ||
| 20 | } else { | ||
| 21 | size_t len = strlen(__wasilibc_cwd); | ||
| 22 | if (size < len + 1) { | ||
| 23 | errno = ERANGE; | ||
| 24 | return NULL; | ||
| 25 | } | ||
| 26 | strcpy(buf, __wasilibc_cwd); | ||
| 27 | } | ||
| 28 | return buf; | ||
| 29 | } | ||
| 30 | |||
lib/libc/wasi/libc-bottom-half/sources/getentropy.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include <wasi/api.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | #ifdef _REENTRANT | ||
| 6 | #error With threads support, getentropy is not intended to be a cancellation point. | ||
| 7 | #endif | ||
| 8 | |||
| 9 | int __getentropy(void *buffer, size_t len) { | ||
| 10 | if (len > 256) { | ||
| 11 | errno = EIO; | ||
| 12 | return -1; | ||
| 13 | } | ||
| 14 | |||
| 15 | int r = __wasi_random_get(buffer, len); | ||
| 16 | |||
| 17 | if (r != 0) { | ||
| 18 | errno = r; | ||
| 19 | return -1; | ||
| 20 | } | ||
| 21 | |||
| 22 | return 0; | ||
| 23 | } | ||
| 24 | extern __typeof(__getentropy) getentropy __attribute__((weak, alias("__getentropy"))); | ||
lib/libc/wasi/libc-bottom-half/sources/isatty.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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/fmin-fmax.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | // Wasm's `min` and `max` operators implement the IEEE 754-2019 | ||
| 2 | // `minimum` and `maximum` operations, meaning that given a choice | ||
| 3 | // between NaN and a number, they return NaN. This differs from | ||
| 4 | // the C standard library's `fmin` and `fmax` functions, which | ||
| 5 | // return the number. However, we can still use wasm's builtins | ||
| 6 | // by handling the NaN cases explicitly, and it still turns out | ||
| 7 | // to be faster than doing the whole operation in | ||
| 8 | // target-independent C. And, it's smaller. | ||
| 9 | |||
| 10 | #include <math.h> | ||
| 11 | |||
| 12 | float fminf(float x, float y) { | ||
| 13 | if (isnan(x)) return y; | ||
| 14 | if (isnan(y)) return x; | ||
| 15 | return __builtin_wasm_min_f32(x, y); | ||
| 16 | } | ||
| 17 | |||
| 18 | float fmaxf(float x, float y) { | ||
| 19 | if (isnan(x)) return y; | ||
| 20 | if (isnan(y)) return x; | ||
| 21 | return __builtin_wasm_max_f32(x, y); | ||
| 22 | } | ||
| 23 | |||
| 24 | double fmin(double x, double y) { | ||
| 25 | if (isnan(x)) return y; | ||
| 26 | if (isnan(y)) return x; | ||
| 27 | return __builtin_wasm_min_f64(x, y); | ||
| 28 | } | ||
| 29 | |||
| 30 | double fmax(double x, double y) { | ||
| 31 | if (isnan(x)) return y; | ||
| 32 | if (isnan(y)) return x; | ||
| 33 | return __builtin_wasm_max_f64(x, y); | ||
| 34 | } | ||
lib/libc/wasi/libc-bottom-half/sources/math/math-builtins.c created+69| ... | @@ -0,0 +1,69 @@ | ||
| 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 created+423| ... | @@ -0,0 +1,423 @@ | ||
| 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 <unistd.h> | ||
| 10 | #include <utime.h> | ||
| 11 | #include <wasi/libc.h> | ||
| 12 | #include <wasi/libc-find-relpath.h> | ||
| 13 | #include <wasi/libc-nocwd.h> | ||
| 14 | |||
| 15 | static int find_relpath2( | ||
| 16 | const char *path, | ||
| 17 | char **relative, | ||
| 18 | size_t *relative_len | ||
| 19 | ) { | ||
| 20 | // See comments in `preopens.c` for what this trick is doing. | ||
| 21 | const char *abs; | ||
| 22 | if (__wasilibc_find_relpath_alloc) | ||
| 23 | return __wasilibc_find_relpath_alloc(path, &abs, relative, relative_len, 1); | ||
| 24 | return __wasilibc_find_relpath(path, &abs, relative, *relative_len); | ||
| 25 | } | ||
| 26 | |||
| 27 | // Helper to call `__wasilibc_find_relpath` and return an already-managed | ||
| 28 | // pointer for the `relative` path. This function is not reentrant since the | ||
| 29 | // `relative` pointer will point to static data that cannot be reused until | ||
| 30 | // `relative` is no longer used. | ||
| 31 | static int find_relpath(const char *path, char **relative) { | ||
| 32 | static __thread char *relative_buf = NULL; | ||
| 33 | static __thread size_t relative_buf_len = 0; | ||
| 34 | *relative = relative_buf; | ||
| 35 | return find_relpath2(path, relative, &relative_buf_len); | ||
| 36 | } | ||
| 37 | |||
| 38 | // same as `find_relpath`, but uses another set of static variables to cache | ||
| 39 | static int find_relpath_alt(const char *path, char **relative) { | ||
| 40 | static __thread char *relative_buf = NULL; | ||
| 41 | static __thread size_t relative_buf_len = 0; | ||
| 42 | *relative = relative_buf; | ||
| 43 | return find_relpath2(path, relative, &relative_buf_len); | ||
| 44 | } | ||
| 45 | |||
| 46 | int open(const char *path, int oflag, ...) { | ||
| 47 | // WASI libc's `openat` ignores the mode argument, so call a special | ||
| 48 | // entrypoint which avoids the varargs calling convention. | ||
| 49 | return __wasilibc_open_nomode(path, oflag); | ||
| 50 | } | ||
| 51 | |||
| 52 | // See the documentation in libc.h | ||
| 53 | int __wasilibc_open_nomode(const char *path, int oflag) { | ||
| 54 | char *relative_path; | ||
| 55 | int dirfd = find_relpath(path, &relative_path); | ||
| 56 | |||
| 57 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 58 | if (dirfd == -1) { | ||
| 59 | errno = ENOTCAPABLE; | ||
| 60 | return -1; | ||
| 61 | } | ||
| 62 | |||
| 63 | return __wasilibc_nocwd_openat_nomode(dirfd, relative_path, oflag); | ||
| 64 | } | ||
| 65 | |||
| 66 | int access(const char *path, int amode) { | ||
| 67 | char *relative_path; | ||
| 68 | int dirfd = find_relpath(path, &relative_path); | ||
| 69 | |||
| 70 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 71 | if (dirfd == -1) { | ||
| 72 | errno = ENOTCAPABLE; | ||
| 73 | return -1; | ||
| 74 | } | ||
| 75 | |||
| 76 | return __wasilibc_nocwd_faccessat(dirfd, relative_path, amode, 0); | ||
| 77 | } | ||
| 78 | |||
| 79 | ssize_t readlink( | ||
| 80 | const char *restrict path, | ||
| 81 | char *restrict buf, | ||
| 82 | size_t bufsize) | ||
| 83 | { | ||
| 84 | char *relative_path; | ||
| 85 | int dirfd = find_relpath(path, &relative_path); | ||
| 86 | |||
| 87 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 88 | if (dirfd == -1) { | ||
| 89 | errno = ENOTCAPABLE; | ||
| 90 | return -1; | ||
| 91 | } | ||
| 92 | |||
| 93 | return __wasilibc_nocwd_readlinkat(dirfd, relative_path, buf, bufsize); | ||
| 94 | } | ||
| 95 | |||
| 96 | int stat(const char *restrict path, struct stat *restrict buf) { | ||
| 97 | char *relative_path; | ||
| 98 | int dirfd = find_relpath(path, &relative_path); | ||
| 99 | |||
| 100 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 101 | if (dirfd == -1) { | ||
| 102 | errno = ENOTCAPABLE; | ||
| 103 | return -1; | ||
| 104 | } | ||
| 105 | |||
| 106 | return __wasilibc_nocwd_fstatat(dirfd, relative_path, buf, 0); | ||
| 107 | } | ||
| 108 | |||
| 109 | int lstat(const char *restrict path, struct stat *restrict buf) { | ||
| 110 | char *relative_path; | ||
| 111 | int dirfd = find_relpath(path, &relative_path); | ||
| 112 | |||
| 113 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 114 | if (dirfd == -1) { | ||
| 115 | errno = ENOTCAPABLE; | ||
| 116 | return -1; | ||
| 117 | } | ||
| 118 | |||
| 119 | return __wasilibc_nocwd_fstatat(dirfd, relative_path, buf, AT_SYMLINK_NOFOLLOW); | ||
| 120 | } | ||
| 121 | |||
| 122 | int utime(const char *path, const struct utimbuf *times) { | ||
| 123 | char *relative_path; | ||
| 124 | int dirfd = find_relpath(path, &relative_path); | ||
| 125 | |||
| 126 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 127 | if (dirfd == -1) { | ||
| 128 | errno = ENOTCAPABLE; | ||
| 129 | return -1; | ||
| 130 | } | ||
| 131 | |||
| 132 | return __wasilibc_nocwd_utimensat( | ||
| 133 | dirfd, relative_path, | ||
| 134 | times ? ((struct timespec [2]) { | ||
| 135 | { .tv_sec = times->actime }, | ||
| 136 | { .tv_sec = times->modtime } | ||
| 137 | }) | ||
| 138 | : NULL, | ||
| 139 | 0); | ||
| 140 | } | ||
| 141 | |||
| 142 | int unlink(const char *path) { | ||
| 143 | char *relative_path; | ||
| 144 | int dirfd = find_relpath(path, &relative_path); | ||
| 145 | |||
| 146 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 147 | if (dirfd == -1) { | ||
| 148 | errno = ENOTCAPABLE; | ||
| 149 | return -1; | ||
| 150 | } | ||
| 151 | |||
| 152 | // `unlinkat` imports `__wasi_path_remove_directory` even when | ||
| 153 | // `AT_REMOVEDIR` isn't passed. Instead, use a specialized function which | ||
| 154 | // just imports `__wasi_path_unlink_file`. | ||
| 155 | return __wasilibc_nocwd___wasilibc_unlinkat(dirfd, relative_path); | ||
| 156 | } | ||
| 157 | |||
| 158 | int rmdir(const char *path) { | ||
| 159 | char *relative_path; | ||
| 160 | int dirfd = find_relpath(path, &relative_path); | ||
| 161 | |||
| 162 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 163 | if (dirfd == -1) { | ||
| 164 | errno = ENOTCAPABLE; | ||
| 165 | return -1; | ||
| 166 | } | ||
| 167 | |||
| 168 | return __wasilibc_nocwd___wasilibc_rmdirat(dirfd, relative_path); | ||
| 169 | } | ||
| 170 | |||
| 171 | int remove(const char *path) { | ||
| 172 | char *relative_path; | ||
| 173 | int dirfd = find_relpath(path, &relative_path); | ||
| 174 | |||
| 175 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 176 | if (dirfd == -1) { | ||
| 177 | errno = ENOTCAPABLE; | ||
| 178 | return -1; | ||
| 179 | } | ||
| 180 | |||
| 181 | // First try to remove it as a file. | ||
| 182 | int r = __wasilibc_nocwd___wasilibc_unlinkat(dirfd, relative_path); | ||
| 183 | if (r != 0 && (errno == EISDIR || errno == ENOTCAPABLE)) { | ||
| 184 | // That failed, but it might be a directory. | ||
| 185 | r = __wasilibc_nocwd___wasilibc_rmdirat(dirfd, relative_path); | ||
| 186 | |||
| 187 | // If it isn't a directory, we lack capabilities to remove it as a file. | ||
| 188 | if (errno == ENOTDIR) | ||
| 189 | errno = ENOTCAPABLE; | ||
| 190 | } | ||
| 191 | return r; | ||
| 192 | } | ||
| 193 | |||
| 194 | int mkdir(const char *path, mode_t mode) { | ||
| 195 | char *relative_path; | ||
| 196 | int dirfd = find_relpath(path, &relative_path); | ||
| 197 | |||
| 198 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 199 | if (dirfd == -1) { | ||
| 200 | errno = ENOTCAPABLE; | ||
| 201 | return -1; | ||
| 202 | } | ||
| 203 | |||
| 204 | return __wasilibc_nocwd_mkdirat_nomode(dirfd, relative_path); | ||
| 205 | } | ||
| 206 | |||
| 207 | DIR *opendir(const char *dirname) { | ||
| 208 | char *relative_path; | ||
| 209 | int dirfd = find_relpath(dirname, &relative_path); | ||
| 210 | |||
| 211 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 212 | if (dirfd == -1) { | ||
| 213 | errno = ENOTCAPABLE; | ||
| 214 | return NULL; | ||
| 215 | } | ||
| 216 | |||
| 217 | return __wasilibc_nocwd_opendirat(dirfd, relative_path); | ||
| 218 | } | ||
| 219 | |||
| 220 | int scandir( | ||
| 221 | const char *restrict dir, | ||
| 222 | struct dirent ***restrict namelist, | ||
| 223 | int (*filter)(const struct dirent *), | ||
| 224 | int (*compar)(const struct dirent **, const struct dirent **) | ||
| 225 | ) { | ||
| 226 | char *relative_path; | ||
| 227 | int dirfd = find_relpath(dir, &relative_path); | ||
| 228 | |||
| 229 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 230 | if (dirfd == -1) { | ||
| 231 | errno = ENOTCAPABLE; | ||
| 232 | return -1; | ||
| 233 | } | ||
| 234 | |||
| 235 | return __wasilibc_nocwd_scandirat(dirfd, relative_path, namelist, filter, compar); | ||
| 236 | } | ||
| 237 | |||
| 238 | int symlink(const char *target, const char *linkpath) { | ||
| 239 | char *relative_path; | ||
| 240 | int dirfd = find_relpath(linkpath, &relative_path); | ||
| 241 | |||
| 242 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 243 | if (dirfd == -1) { | ||
| 244 | errno = ENOTCAPABLE; | ||
| 245 | return -1; | ||
| 246 | } | ||
| 247 | |||
| 248 | return __wasilibc_nocwd_symlinkat(target, dirfd, relative_path); | ||
| 249 | } | ||
| 250 | |||
| 251 | int link(const char *old, const char *new) { | ||
| 252 | char *old_relative_path; | ||
| 253 | int old_dirfd = find_relpath_alt(old, &old_relative_path); | ||
| 254 | |||
| 255 | if (old_dirfd != -1) { | ||
| 256 | char *new_relative_path; | ||
| 257 | int new_dirfd = find_relpath(new, &new_relative_path); | ||
| 258 | |||
| 259 | if (new_dirfd != -1) | ||
| 260 | return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, | ||
| 261 | new_dirfd, new_relative_path, 0); | ||
| 262 | } | ||
| 263 | |||
| 264 | // We couldn't find a preopen for it; indicate that we lack capabilities. | ||
| 265 | errno = ENOTCAPABLE; | ||
| 266 | return -1; | ||
| 267 | } | ||
| 268 | |||
| 269 | int rename(const char *old, const char *new) { | ||
| 270 | char *old_relative_path; | ||
| 271 | int old_dirfd = find_relpath_alt(old, &old_relative_path); | ||
| 272 | |||
| 273 | if (old_dirfd != -1) { | ||
| 274 | char *new_relative_path; | ||
| 275 | int new_dirfd = find_relpath(new, &new_relative_path); | ||
| 276 | |||
| 277 | if (new_dirfd != -1) | ||
| 278 | return __wasilibc_nocwd_renameat(old_dirfd, old_relative_path, | ||
| 279 | new_dirfd, new_relative_path); | ||
| 280 | } | ||
| 281 | |||
| 282 | // We couldn't find a preopen for it; indicate that we lack capabilities. | ||
| 283 | errno = ENOTCAPABLE; | ||
| 284 | return -1; | ||
| 285 | } | ||
| 286 | |||
| 287 | // Like `access`, but with `faccessat`'s flags argument. | ||
| 288 | int | ||
| 289 | __wasilibc_access(const char *path, int mode, int flags) | ||
| 290 | { | ||
| 291 | char *relative_path; | ||
| 292 | int dirfd = find_relpath(path, &relative_path); | ||
| 293 | |||
| 294 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 295 | if (dirfd == -1) { | ||
| 296 | errno = ENOTCAPABLE; | ||
| 297 | return -1; | ||
| 298 | } | ||
| 299 | |||
| 300 | return __wasilibc_nocwd_faccessat(dirfd, relative_path, | ||
| 301 | mode, flags); | ||
| 302 | } | ||
| 303 | |||
| 304 | // Like `utimensat`, but without the `at` part. | ||
| 305 | int | ||
| 306 | __wasilibc_utimens(const char *path, const struct timespec times[2], int flags) | ||
| 307 | { | ||
| 308 | char *relative_path; | ||
| 309 | int dirfd = find_relpath(path, &relative_path); | ||
| 310 | |||
| 311 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 312 | if (dirfd == -1) { | ||
| 313 | errno = ENOTCAPABLE; | ||
| 314 | return -1; | ||
| 315 | } | ||
| 316 | |||
| 317 | return __wasilibc_nocwd_utimensat(dirfd, relative_path, | ||
| 318 | times, flags); | ||
| 319 | } | ||
| 320 | |||
| 321 | // Like `stat`, but with `fstatat`'s flags argument. | ||
| 322 | int | ||
| 323 | __wasilibc_stat(const char *__restrict path, struct stat *__restrict st, int flags) | ||
| 324 | { | ||
| 325 | char *relative_path; | ||
| 326 | int dirfd = find_relpath(path, &relative_path); | ||
| 327 | |||
| 328 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 329 | if (dirfd == -1) { | ||
| 330 | errno = ENOTCAPABLE; | ||
| 331 | return -1; | ||
| 332 | } | ||
| 333 | |||
| 334 | return __wasilibc_nocwd_fstatat(dirfd, relative_path, st, flags); | ||
| 335 | } | ||
| 336 | |||
| 337 | // Like `link`, but with `linkat`'s flags argument. | ||
| 338 | int | ||
| 339 | __wasilibc_link(const char *oldpath, const char *newpath, int flags) | ||
| 340 | { | ||
| 341 | char *old_relative_path; | ||
| 342 | char *new_relative_path; | ||
| 343 | int old_dirfd = find_relpath(oldpath, &old_relative_path); | ||
| 344 | int new_dirfd = find_relpath(newpath, &new_relative_path); | ||
| 345 | |||
| 346 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 347 | if (old_dirfd == -1 || new_dirfd == -1) { | ||
| 348 | errno = ENOTCAPABLE; | ||
| 349 | return -1; | ||
| 350 | } | ||
| 351 | |||
| 352 | return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, | ||
| 353 | new_dirfd, new_relative_path, | ||
| 354 | flags); | ||
| 355 | } | ||
| 356 | |||
| 357 | // Like `__wasilibc_link`, but oldpath is relative to olddirfd. | ||
| 358 | int | ||
| 359 | __wasilibc_link_oldat(int olddirfd, const char *oldpath, const char *newpath, int flags) | ||
| 360 | { | ||
| 361 | char *new_relative_path; | ||
| 362 | int new_dirfd = find_relpath(newpath, &new_relative_path); | ||
| 363 | |||
| 364 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 365 | if (new_dirfd == -1) { | ||
| 366 | errno = ENOTCAPABLE; | ||
| 367 | return -1; | ||
| 368 | } | ||
| 369 | |||
| 370 | return __wasilibc_nocwd_linkat(olddirfd, oldpath, | ||
| 371 | new_dirfd, new_relative_path, | ||
| 372 | flags); | ||
| 373 | } | ||
| 374 | |||
| 375 | // Like `__wasilibc_link`, but newpath is relative to newdirfd. | ||
| 376 | int | ||
| 377 | __wasilibc_link_newat(const char *oldpath, int newdirfd, const char *newpath, int flags) | ||
| 378 | { | ||
| 379 | char *old_relative_path; | ||
| 380 | int old_dirfd = find_relpath(oldpath, &old_relative_path); | ||
| 381 | |||
| 382 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 383 | if (old_dirfd == -1) { | ||
| 384 | errno = ENOTCAPABLE; | ||
| 385 | return -1; | ||
| 386 | } | ||
| 387 | |||
| 388 | return __wasilibc_nocwd_linkat(old_dirfd, old_relative_path, | ||
| 389 | newdirfd, newpath, | ||
| 390 | flags); | ||
| 391 | } | ||
| 392 | |||
| 393 | // Like `rename`, but from is relative to fromdirfd. | ||
| 394 | int | ||
| 395 | __wasilibc_rename_oldat(int fromdirfd, const char *from, const char *to) | ||
| 396 | { | ||
| 397 | char *to_relative_path; | ||
| 398 | int to_dirfd = find_relpath(to, &to_relative_path); | ||
| 399 | |||
| 400 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 401 | if (to_dirfd == -1) { | ||
| 402 | errno = ENOTCAPABLE; | ||
| 403 | return -1; | ||
| 404 | } | ||
| 405 | |||
| 406 | return __wasilibc_nocwd_renameat(fromdirfd, from, to_dirfd, to_relative_path); | ||
| 407 | } | ||
| 408 | |||
| 409 | // Like `rename`, but to is relative to todirfd. | ||
| 410 | int | ||
| 411 | __wasilibc_rename_newat(const char *from, int todirfd, const char *to) | ||
| 412 | { | ||
| 413 | char *from_relative_path; | ||
| 414 | int from_dirfd = find_relpath(from, &from_relative_path); | ||
| 415 | |||
| 416 | // If we can't find a preopen for it, indicate that we lack capabilities. | ||
| 417 | if (from_dirfd == -1) { | ||
| 418 | errno = ENOTCAPABLE; | ||
| 419 | return -1; | ||
| 420 | } | ||
| 421 | |||
| 422 | return __wasilibc_nocwd_renameat(from_dirfd, from_relative_path, todirfd, to); | ||
| 423 | } | ||
lib/libc/wasi/libc-bottom-half/sources/preopens.c created+252| ... | @@ -0,0 +1,252 @@ | ||
| 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 | #ifdef _REENTRANT | ||
| 6 | #error "__wasilibc_register_preopened_fd doesn't yet support multiple threads" | ||
| 7 | #endif | ||
| 8 | |||
| 9 | #include <assert.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <fcntl.h> | ||
| 12 | #include <limits.h> | ||
| 13 | #include <stdbool.h> | ||
| 14 | #include <stdlib.h> | ||
| 15 | #include <string.h> | ||
| 16 | #include <sysexits.h> | ||
| 17 | #include <wasi/api.h> | ||
| 18 | #include <wasi/libc-find-relpath.h> | ||
| 19 | #include <wasi/libc.h> | ||
| 20 | |||
| 21 | /// A name and file descriptor pair. | ||
| 22 | typedef struct preopen { | ||
| 23 | /// The path prefix associated with the file descriptor. | ||
| 24 | const char *prefix; | ||
| 25 | |||
| 26 | /// The file descriptor. | ||
| 27 | __wasi_fd_t fd; | ||
| 28 | } preopen; | ||
| 29 | |||
| 30 | /// A simple growable array of `preopen`. | ||
| 31 | static preopen *preopens; | ||
| 32 | static size_t num_preopens; | ||
| 33 | static size_t preopen_capacity; | ||
| 34 | |||
| 35 | #ifdef NDEBUG | ||
| 36 | #define assert_invariants() // assertions disabled | ||
| 37 | #else | ||
| 38 | static void assert_invariants(void) { | ||
| 39 | assert(num_preopens <= preopen_capacity); | ||
| 40 | assert(preopen_capacity == 0 || preopens != NULL); | ||
| 41 | assert(preopen_capacity == 0 || | ||
| 42 | preopen_capacity * sizeof(preopen) > preopen_capacity); | ||
| 43 | |||
| 44 | for (size_t i = 0; i < num_preopens; ++i) { | ||
| 45 | const preopen *pre = &preopens[i]; | ||
| 46 | assert(pre->prefix != NULL); | ||
| 47 | assert(pre->fd != (__wasi_fd_t)-1); | ||
| 48 | #ifdef __wasm__ | ||
| 49 | assert((uintptr_t)pre->prefix < | ||
| 50 | (__uint128_t)__builtin_wasm_memory_size(0) * PAGESIZE); | ||
| 51 | #endif | ||
| 52 | } | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | /// Allocate space for more preopens. Returns 0 on success and -1 on failure. | ||
| 57 | static int resize(void) { | ||
| 58 | size_t start_capacity = 4; | ||
| 59 | size_t old_capacity = preopen_capacity; | ||
| 60 | size_t new_capacity = old_capacity == 0 ? start_capacity : old_capacity * 2; | ||
| 61 | |||
| 62 | preopen *old_preopens = preopens; | ||
| 63 | preopen *new_preopens = calloc(sizeof(preopen), new_capacity); | ||
| 64 | if (new_preopens == NULL) | ||
| 65 | return -1; | ||
| 66 | |||
| 67 | memcpy(new_preopens, old_preopens, num_preopens * sizeof(preopen)); | ||
| 68 | preopens = new_preopens; | ||
| 69 | preopen_capacity = new_capacity; | ||
| 70 | free(old_preopens); | ||
| 71 | |||
| 72 | assert_invariants(); | ||
| 73 | return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | // Normalize an absolute path. Removes leading `/` and leading `./`, so the | ||
| 77 | // first character is the start of a directory name. This works because our | ||
| 78 | // process always starts with a working directory of `/`. Additionally translate | ||
| 79 | // `.` to the empty string. | ||
| 80 | static const char *strip_prefixes(const char *path) { | ||
| 81 | while (1) { | ||
| 82 | if (path[0] == '/') { | ||
| 83 | path++; | ||
| 84 | } else if (path[0] == '.' && path[1] == '/') { | ||
| 85 | path += 2; | ||
| 86 | } else if (path[0] == '.' && path[1] == 0) { | ||
| 87 | path++; | ||
| 88 | } else { | ||
| 89 | break; | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | return path; | ||
| 94 | } | ||
| 95 | |||
| 96 | /// Register the given preopened file descriptor under the given path. | ||
| 97 | /// | ||
| 98 | /// This function takes ownership of `prefix`. | ||
| 99 | static int internal_register_preopened_fd(__wasi_fd_t fd, const char *relprefix) { | ||
| 100 | // Check preconditions. | ||
| 101 | assert_invariants(); | ||
| 102 | assert(fd != AT_FDCWD); | ||
| 103 | assert(fd != -1); | ||
| 104 | assert(relprefix != NULL); | ||
| 105 | |||
| 106 | if (num_preopens == preopen_capacity && resize() != 0) | ||
| 107 | return -1; | ||
| 108 | |||
| 109 | char *prefix = strdup(strip_prefixes(relprefix)); | ||
| 110 | if (prefix == NULL) | ||
| 111 | return -1; | ||
| 112 | preopens[num_preopens++] = (preopen) { prefix, fd, }; | ||
| 113 | |||
| 114 | assert_invariants(); | ||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | /// Are the `prefix_len` bytes pointed to by `prefix` a prefix of `path`? | ||
| 119 | static bool prefix_matches(const char *prefix, size_t prefix_len, const char *path) { | ||
| 120 | // Allow an empty string as a prefix of any relative path. | ||
| 121 | if (path[0] != '/' && prefix_len == 0) | ||
| 122 | return true; | ||
| 123 | |||
| 124 | // Check whether any bytes of the prefix differ. | ||
| 125 | if (memcmp(path, prefix, prefix_len) != 0) | ||
| 126 | return false; | ||
| 127 | |||
| 128 | // Ignore trailing slashes in directory names. | ||
| 129 | size_t i = prefix_len; | ||
| 130 | while (i > 0 && prefix[i - 1] == '/') { | ||
| 131 | --i; | ||
| 132 | } | ||
| 133 | |||
| 134 | // Match only complete path components. | ||
| 135 | char last = path[i]; | ||
| 136 | return last == '/' || last == '\0'; | ||
| 137 | } | ||
| 138 | |||
| 139 | // See the documentation in libc.h | ||
| 140 | int __wasilibc_register_preopened_fd(int fd, const char *prefix) { | ||
| 141 | return internal_register_preopened_fd((__wasi_fd_t)fd, prefix); | ||
| 142 | } | ||
| 143 | |||
| 144 | // See the documentation in libc-find-relpath.h. | ||
| 145 | int __wasilibc_find_relpath(const char *path, | ||
| 146 | const char **abs_prefix, | ||
| 147 | char **relative_path, | ||
| 148 | size_t relative_path_len) { | ||
| 149 | // If `chdir` is linked, whose object file defines this symbol, then we | ||
| 150 | // call that. Otherwise if the program can't `chdir` then `path` is | ||
| 151 | // absolute (or relative to the root dir), so we delegate to `find_abspath` | ||
| 152 | if (__wasilibc_find_relpath_alloc) | ||
| 153 | return __wasilibc_find_relpath_alloc(path, abs_prefix, relative_path, &relative_path_len, 0); | ||
| 154 | return __wasilibc_find_abspath(path, abs_prefix, (const char**) relative_path); | ||
| 155 | } | ||
| 156 | |||
| 157 | // See the documentation in libc-find-relpath.h. | ||
| 158 | int __wasilibc_find_abspath(const char *path, | ||
| 159 | const char **abs_prefix, | ||
| 160 | const char **relative_path) { | ||
| 161 | // Strip leading `/` characters, the prefixes we're mataching won't have | ||
| 162 | // them. | ||
| 163 | while (*path == '/') | ||
| 164 | path++; | ||
| 165 | // Search through the preopens table. Iterate in reverse so that more | ||
| 166 | // recently added preopens take precedence over less recently addded ones. | ||
| 167 | size_t match_len = 0; | ||
| 168 | int fd = -1; | ||
| 169 | for (size_t i = num_preopens; i > 0; --i) { | ||
| 170 | const preopen *pre = &preopens[i - 1]; | ||
| 171 | const char *prefix = pre->prefix; | ||
| 172 | size_t len = strlen(prefix); | ||
| 173 | |||
| 174 | // If we haven't had a match yet, or the candidate path is longer than | ||
| 175 | // our current best match's path, and the candidate path is a prefix of | ||
| 176 | // the requested path, take that as the new best path. | ||
| 177 | if ((fd == -1 || len > match_len) && | ||
| 178 | prefix_matches(prefix, len, path)) | ||
| 179 | { | ||
| 180 | fd = pre->fd; | ||
| 181 | match_len = len; | ||
| 182 | *abs_prefix = prefix; | ||
| 183 | } | ||
| 184 | } | ||
| 185 | |||
| 186 | if (fd == -1) { | ||
| 187 | errno = ENOENT; | ||
| 188 | return -1; | ||
| 189 | } | ||
| 190 | |||
| 191 | // The relative path is the substring after the portion that was matched. | ||
| 192 | const char *computed = path + match_len; | ||
| 193 | |||
| 194 | // Omit leading slashes in the relative path. | ||
| 195 | while (*computed == '/') | ||
| 196 | ++computed; | ||
| 197 | |||
| 198 | // *at syscalls don't accept empty relative paths, so use "." instead. | ||
| 199 | if (*computed == '\0') | ||
| 200 | computed = "."; | ||
| 201 | |||
| 202 | *relative_path = computed; | ||
| 203 | return fd; | ||
| 204 | } | ||
| 205 | |||
| 206 | /// This is referenced by weak reference from crt1.c and lives in the same | ||
| 207 | /// source file as `__wasilibc_find_relpath` so that it's linked in when it's | ||
| 208 | /// needed. | ||
| 209 | // Concerning the 51 -- see the comment by the constructor priority in | ||
| 210 | // libc-bottom-half/sources/environ.c. | ||
| 211 | __attribute__((constructor(51))) | ||
| 212 | static void __wasilibc_populate_preopens(void) { | ||
| 213 | // Skip stdin, stdout, and stderr, and count up until we reach an invalid | ||
| 214 | // file descriptor. | ||
| 215 | for (__wasi_fd_t fd = 3; fd != 0; ++fd) { | ||
| 216 | __wasi_prestat_t prestat; | ||
| 217 | __wasi_errno_t ret = __wasi_fd_prestat_get(fd, &prestat); | ||
| 218 | if (ret == __WASI_ERRNO_BADF) | ||
| 219 | break; | ||
| 220 | if (ret != __WASI_ERRNO_SUCCESS) | ||
| 221 | goto oserr; | ||
| 222 | switch (prestat.tag) { | ||
| 223 | case __WASI_PREOPENTYPE_DIR: { | ||
| 224 | char *prefix = malloc(prestat.u.dir.pr_name_len + 1); | ||
| 225 | if (prefix == NULL) | ||
| 226 | goto software; | ||
| 227 | |||
| 228 | // TODO: Remove the cast on `path` once the witx is updated with | ||
| 229 | // char8 support. | ||
| 230 | ret = __wasi_fd_prestat_dir_name(fd, (uint8_t *)prefix, | ||
| 231 | prestat.u.dir.pr_name_len); | ||
| 232 | if (ret != __WASI_ERRNO_SUCCESS) | ||
| 233 | goto oserr; | ||
| 234 | prefix[prestat.u.dir.pr_name_len] = '\0'; | ||
| 235 | |||
| 236 | if (internal_register_preopened_fd(fd, prefix) != 0) | ||
| 237 | goto software; | ||
| 238 | free(prefix); | ||
| 239 | |||
| 240 | break; | ||
| 241 | } | ||
| 242 | default: | ||
| 243 | break; | ||
| 244 | } | ||
| 245 | } | ||
| 246 | |||
| 247 | return; | ||
| 248 | oserr: | ||
| 249 | _Exit(EX_OSERR); | ||
| 250 | software: | ||
| 251 | _Exit(EX_SOFTWARE); | ||
| 252 | } | ||
lib/libc/wasi/libc-bottom-half/sources/reallocarray.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | void *__reallocarray(void *ptr, size_t nmemb, size_t size) { | ||
| 5 | size_t bytes; | ||
| 6 | if (__builtin_umull_overflow(nmemb, size, &bytes)) { | ||
| 7 | errno = ENOMEM; | ||
| 8 | return NULL; | ||
| 9 | } | ||
| 10 | return realloc(ptr, bytes); | ||
| 11 | } | ||
| 12 | |||
| 13 | void *reallocarray(void *ptr, size_t nmemb, size_t size) | ||
| 14 | __attribute__((__weak__, __alias__("__reallocarray"))); | ||
lib/libc/wasi/libc-bottom-half/sources/sbrk.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 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 created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 created+59| ... | @@ -0,0 +1,59 @@ | ||
| 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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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/.mailmap created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | Ada Worcester <oss@ada.pikhq.com> <josiahw@gmail.com> | ||
lib/libc/wasi/libc-top-half/musl/COPYRIGHT created+193| ... | @@ -0,0 +1,193 @@ | ||
| 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/generic/bits/dirent.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _DIRENT_HAVE_D_RECLEN | ||
| 2 | #define _DIRENT_HAVE_D_OFF | ||
| 3 | #define _DIRENT_HAVE_D_TYPE | ||
| 4 | |||
| 5 | struct dirent { | ||
| 6 | 	ino_t d_ino; | ||
| 7 | 	off_t d_off; | ||
| 8 | 	unsigned short d_reclen; | ||
| 9 | 	unsigned char d_type; | ||
| 10 | 	char d_name[256]; | ||
| 11 | }; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/errno.h created+134| ... | @@ -0,0 +1,134 @@ | ||
| 1 | #define EPERM 1 | ||
| 2 | #define ENOENT 2 | ||
| 3 | #define ESRCH 3 | ||
| 4 | #define EINTR 4 | ||
| 5 | #define EIO 5 | ||
| 6 | #define ENXIO 6 | ||
| 7 | #define E2BIG 7 | ||
| 8 | #define ENOEXEC 8 | ||
| 9 | #define EBADF 9 | ||
| 10 | #define ECHILD 10 | ||
| 11 | #define EAGAIN 11 | ||
| 12 | #define ENOMEM 12 | ||
| 13 | #define EACCES 13 | ||
| 14 | #define EFAULT 14 | ||
| 15 | #define ENOTBLK 15 | ||
| 16 | #define EBUSY 16 | ||
| 17 | #define EEXIST 17 | ||
| 18 | #define EXDEV 18 | ||
| 19 | #define ENODEV 19 | ||
| 20 | #define ENOTDIR 20 | ||
| 21 | #define EISDIR 21 | ||
| 22 | #define EINVAL 22 | ||
| 23 | #define ENFILE 23 | ||
| 24 | #define EMFILE 24 | ||
| 25 | #define ENOTTY 25 | ||
| 26 | #define ETXTBSY 26 | ||
| 27 | #define EFBIG 27 | ||
| 28 | #define ENOSPC 28 | ||
| 29 | #define ESPIPE 29 | ||
| 30 | #define EROFS 30 | ||
| 31 | #define EMLINK 31 | ||
| 32 | #define EPIPE 32 | ||
| 33 | #define EDOM 33 | ||
| 34 | #define ERANGE 34 | ||
| 35 | #define EDEADLK 35 | ||
| 36 | #define ENAMETOOLONG 36 | ||
| 37 | #define ENOLCK 37 | ||
| 38 | #define ENOSYS 38 | ||
| 39 | #define ENOTEMPTY 39 | ||
| 40 | #define ELOOP 40 | ||
| 41 | #define EWOULDBLOCK EAGAIN | ||
| 42 | #define ENOMSG 42 | ||
| 43 | #define EIDRM 43 | ||
| 44 | #define ECHRNG 44 | ||
| 45 | #define EL2NSYNC 45 | ||
| 46 | #define EL3HLT 46 | ||
| 47 | #define EL3RST 47 | ||
| 48 | #define ELNRNG 48 | ||
| 49 | #define EUNATCH 49 | ||
| 50 | #define ENOCSI 50 | ||
| 51 | #define EL2HLT 51 | ||
| 52 | #define EBADE 52 | ||
| 53 | #define EBADR 53 | ||
| 54 | #define EXFULL 54 | ||
| 55 | #define ENOANO 55 | ||
| 56 | #define EBADRQC 56 | ||
| 57 | #define EBADSLT 57 | ||
| 58 | #define EDEADLOCK EDEADLK | ||
| 59 | #define EBFONT 59 | ||
| 60 | #define ENOSTR 60 | ||
| 61 | #define ENODATA 61 | ||
| 62 | #define ETIME 62 | ||
| 63 | #define ENOSR 63 | ||
| 64 | #define ENONET 64 | ||
| 65 | #define ENOPKG 65 | ||
| 66 | #define EREMOTE 66 | ||
| 67 | #define ENOLINK 67 | ||
| 68 | #define EADV 68 | ||
| 69 | #define ESRMNT 69 | ||
| 70 | #define ECOMM 70 | ||
| 71 | #define EPROTO 71 | ||
| 72 | #define EMULTIHOP 72 | ||
| 73 | #define EDOTDOT 73 | ||
| 74 | #define EBADMSG 74 | ||
| 75 | #define EOVERFLOW 75 | ||
| 76 | #define ENOTUNIQ 76 | ||
| 77 | #define EBADFD 77 | ||
| 78 | #define EREMCHG 78 | ||
| 79 | #define ELIBACC 79 | ||
| 80 | #define ELIBBAD 80 | ||
| 81 | #define ELIBSCN 81 | ||
| 82 | #define ELIBMAX 82 | ||
| 83 | #define ELIBEXEC 83 | ||
| 84 | #define EILSEQ 84 | ||
| 85 | #define ERESTART 85 | ||
| 86 | #define ESTRPIPE 86 | ||
| 87 | #define EUSERS 87 | ||
| 88 | #define ENOTSOCK 88 | ||
| 89 | #define EDESTADDRREQ 89 | ||
| 90 | #define EMSGSIZE 90 | ||
| 91 | #define EPROTOTYPE 91 | ||
| 92 | #define ENOPROTOOPT 92 | ||
| 93 | #define EPROTONOSUPPORT 93 | ||
| 94 | #define ESOCKTNOSUPPORT 94 | ||
| 95 | #define EOPNOTSUPP 95 | ||
| 96 | #define ENOTSUP EOPNOTSUPP | ||
| 97 | #define EPFNOSUPPORT 96 | ||
| 98 | #define EAFNOSUPPORT 97 | ||
| 99 | #define EADDRINUSE 98 | ||
| 100 | #define EADDRNOTAVAIL 99 | ||
| 101 | #define ENETDOWN 100 | ||
| 102 | #define ENETUNREACH 101 | ||
| 103 | #define ENETRESET 102 | ||
| 104 | #define ECONNABORTED 103 | ||
| 105 | #define ECONNRESET 104 | ||
| 106 | #define ENOBUFS 105 | ||
| 107 | #define EISCONN 106 | ||
| 108 | #define ENOTCONN 107 | ||
| 109 | #define ESHUTDOWN 108 | ||
| 110 | #define ETOOMANYREFS 109 | ||
| 111 | #define ETIMEDOUT 110 | ||
| 112 | #define ECONNREFUSED 111 | ||
| 113 | #define EHOSTDOWN 112 | ||
| 114 | #define EHOSTUNREACH 113 | ||
| 115 | #define EALREADY 114 | ||
| 116 | #define EINPROGRESS 115 | ||
| 117 | #define ESTALE 116 | ||
| 118 | #define EUCLEAN 117 | ||
| 119 | #define ENOTNAM 118 | ||
| 120 | #define ENAVAIL 119 | ||
| 121 | #define EISNAM 120 | ||
| 122 | #define EREMOTEIO 121 | ||
| 123 | #define EDQUOT 122 | ||
| 124 | #define ENOMEDIUM 123 | ||
| 125 | #define EMEDIUMTYPE 124 | ||
| 126 | #define ECANCELED 125 | ||
| 127 | #define ENOKEY 126 | ||
| 128 | #define EKEYEXPIRED 127 | ||
| 129 | #define EKEYREVOKED 128 | ||
| 130 | #define EKEYREJECTED 129 | ||
| 131 | #define EOWNERDEAD 130 | ||
| 132 | #define ENOTRECOVERABLE 131 | ||
| 133 | #define ERFKILL 132 | ||
| 134 | #define EHWPOISON 133 | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/fcntl.h created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #define O_CREAT 0100 | ||
| 2 | #define O_EXCL 0200 | ||
| 3 | #define O_NOCTTY 0400 | ||
| 4 | #define O_TRUNC 01000 | ||
| 5 | #define O_APPEND 02000 | ||
| 6 | #define O_NONBLOCK 04000 | ||
| 7 | #define O_DSYNC 010000 | ||
| 8 | #define O_SYNC 04010000 | ||
| 9 | #define O_RSYNC 04010000 | ||
| 10 | #define O_DIRECTORY 0200000 | ||
| 11 | #define O_NOFOLLOW 0400000 | ||
| 12 | #define O_CLOEXEC 02000000 | ||
| 13 | |||
| 14 | #define O_ASYNC 020000 | ||
| 15 | #define O_DIRECT 040000 | ||
| 16 | #define O_LARGEFILE 0100000 | ||
| 17 | #define O_NOATIME 01000000 | ||
| 18 | #define O_PATH 010000000 | ||
| 19 | #define O_TMPFILE 020200000 | ||
| 20 | #define O_NDELAY O_NONBLOCK | ||
| 21 | |||
| 22 | #define F_DUPFD 0 | ||
| 23 | #define F_GETFD 1 | ||
| 24 | #define F_SETFD 2 | ||
| 25 | #define F_GETFL 3 | ||
| 26 | #define F_SETFL 4 | ||
| 27 | |||
| 28 | #define F_SETOWN 8 | ||
| 29 | #define F_GETOWN 9 | ||
| 30 | #define F_SETSIG 10 | ||
| 31 | #define F_GETSIG 11 | ||
| 32 | |||
| 33 | #if __LONG_MAX == 0x7fffffffL | ||
| 34 | #define F_GETLK 12 | ||
| 35 | #define F_SETLK 13 | ||
| 36 | #define F_SETLKW 14 | ||
| 37 | #else | ||
| 38 | #define F_GETLK 5 | ||
| 39 | #define F_SETLK 6 | ||
| 40 | #define F_SETLKW 7 | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #define F_SETOWN_EX 15 | ||
| 44 | #define F_GETOWN_EX 16 | ||
| 45 | |||
| 46 | #define F_GETOWNER_UIDS 17 | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/fenv.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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/wasi/libc-top-half/musl/arch/generic/bits/hwcap.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/io.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/ioctl.h created+115| ... | @@ -0,0 +1,115 @@ | ||
| 1 | #define _IOC(a,b,c,d) ( ((a)<<30) | ((b)<<8) | (c) | ((d)<<16) ) | ||
| 2 | #define _IOC_NONE 0U | ||
| 3 | #define _IOC_WRITE 1U | ||
| 4 | #define _IOC_READ 2U | ||
| 5 | |||
| 6 | #define _IO(a,b) _IOC(_IOC_NONE,(a),(b),0) | ||
| 7 | #define _IOW(a,b,c) _IOC(_IOC_WRITE,(a),(b),sizeof(c)) | ||
| 8 | #define _IOR(a,b,c) _IOC(_IOC_READ,(a),(b),sizeof(c)) | ||
| 9 | #define _IOWR(a,b,c) _IOC(_IOC_READ|_IOC_WRITE,(a),(b),sizeof(c)) | ||
| 10 | |||
| 11 | #define TCGETS		0x5401 | ||
| 12 | #define TCSETS		0x5402 | ||
| 13 | #define TCSETSW		0x5403 | ||
| 14 | #define TCSETSF		0x5404 | ||
| 15 | #define TCGETA		0x5405 | ||
| 16 | #define TCSETA		0x5406 | ||
| 17 | #define TCSETAW		0x5407 | ||
| 18 | #define TCSETAF		0x5408 | ||
| 19 | #define TCSBRK		0x5409 | ||
| 20 | #define TCXONC		0x540A | ||
| 21 | #define TCFLSH		0x540B | ||
| 22 | #define TIOCEXCL	0x540C | ||
| 23 | #define TIOCNXCL	0x540D | ||
| 24 | #define TIOCSCTTY	0x540E | ||
| 25 | #define TIOCGPGRP	0x540F | ||
| 26 | #define TIOCSPGRP	0x5410 | ||
| 27 | #define TIOCOUTQ	0x5411 | ||
| 28 | #define TIOCSTI		0x5412 | ||
| 29 | #define TIOCGWINSZ	0x5413 | ||
| 30 | #define TIOCSWINSZ	0x5414 | ||
| 31 | #define TIOCMGET	0x5415 | ||
| 32 | #define TIOCMBIS	0x5416 | ||
| 33 | #define TIOCMBIC	0x5417 | ||
| 34 | #define TIOCMSET	0x5418 | ||
| 35 | #define TIOCGSOFTCAR	0x5419 | ||
| 36 | #define TIOCSSOFTCAR	0x541A | ||
| 37 | #define FIONREAD	0x541B | ||
| 38 | #define TIOCINQ		FIONREAD | ||
| 39 | #define TIOCLINUX	0x541C | ||
| 40 | #define TIOCCONS	0x541D | ||
| 41 | #define TIOCGSERIAL	0x541E | ||
| 42 | #define TIOCSSERIAL	0x541F | ||
| 43 | #define TIOCPKT		0x5420 | ||
| 44 | #define FIONBIO		0x5421 | ||
| 45 | #define TIOCNOTTY	0x5422 | ||
| 46 | #define TIOCSETD	0x5423 | ||
| 47 | #define TIOCGETD	0x5424 | ||
| 48 | #define TCSBRKP		0x5425 | ||
| 49 | #define TIOCSBRK	0x5427 | ||
| 50 | #define TIOCCBRK	0x5428 | ||
| 51 | #define TIOCGSID	0x5429 | ||
| 52 | #define TIOCGRS485	0x542E | ||
| 53 | #define TIOCSRS485	0x542F | ||
| 54 | #define TIOCGPTN	0x80045430 | ||
| 55 | #define TIOCSPTLCK	0x40045431 | ||
| 56 | #define TIOCGDEV	0x80045432 | ||
| 57 | #define TCGETX		0x5432 | ||
| 58 | #define TCSETX		0x5433 | ||
| 59 | #define TCSETXF		0x5434 | ||
| 60 | #define TCSETXW		0x5435 | ||
| 61 | #define TIOCSIG		0x40045436 | ||
| 62 | #define TIOCVHANGUP	0x5437 | ||
| 63 | #define TIOCGPKT	0x80045438 | ||
| 64 | #define TIOCGPTLCK	0x80045439 | ||
| 65 | #define TIOCGEXCL	0x80045440 | ||
| 66 | #define TIOCGPTPEER	0x5441 | ||
| 67 | #define TIOCGISO7816	0x80285442 | ||
| 68 | #define TIOCSISO7816	0xc0285443 | ||
| 69 | |||
| 70 | #define FIONCLEX	0x5450 | ||
| 71 | #define FIOCLEX		0x5451 | ||
| 72 | #define FIOASYNC	0x5452 | ||
| 73 | #define TIOCSERCONFIG	0x5453 | ||
| 74 | #define TIOCSERGWILD	0x5454 | ||
| 75 | #define TIOCSERSWILD	0x5455 | ||
| 76 | #define TIOCGLCKTRMIOS	0x5456 | ||
| 77 | #define TIOCSLCKTRMIOS	0x5457 | ||
| 78 | #define TIOCSERGSTRUCT	0x5458 | ||
| 79 | #define TIOCSERGETLSR 0x5459 | ||
| 80 | #define TIOCSERGETMULTI 0x545A | ||
| 81 | #define TIOCSERSETMULTI 0x545B | ||
| 82 | |||
| 83 | #define TIOCMIWAIT	0x545C | ||
| 84 | #define TIOCGICOUNT	0x545D | ||
| 85 | #define FIOQSIZE	0x5460 | ||
| 86 | |||
| 87 | #define TIOCM_LE 0x001 | ||
| 88 | #define TIOCM_DTR 0x002 | ||
| 89 | #define TIOCM_RTS 0x004 | ||
| 90 | #define TIOCM_ST 0x008 | ||
| 91 | #define TIOCM_SR 0x010 | ||
| 92 | #define TIOCM_CTS 0x020 | ||
| 93 | #define TIOCM_CAR 0x040 | ||
| 94 | #define TIOCM_RNG 0x080 | ||
| 95 | #define TIOCM_DSR 0x100 | ||
| 96 | #define TIOCM_CD TIOCM_CAR | ||
| 97 | #define TIOCM_RI TIOCM_RNG | ||
| 98 | #define TIOCM_OUT1 0x2000 | ||
| 99 | #define TIOCM_OUT2 0x4000 | ||
| 100 | #define TIOCM_LOOP 0x8000 | ||
| 101 | |||
| 102 | #define FIOSETOWN 0x8901 | ||
| 103 | #define SIOCSPGRP 0x8902 | ||
| 104 | #define FIOGETOWN 0x8903 | ||
| 105 | #define SIOCGPGRP 0x8904 | ||
| 106 | #define SIOCATMARK 0x8905 | ||
| 107 | #if __LONG_MAX == 0x7fffffff | ||
| 108 | #define SIOCGSTAMP _IOR(0x89, 6, char[16]) | ||
| 109 | #define SIOCGSTAMPNS _IOR(0x89, 7, char[16]) | ||
| 110 | #else | ||
| 111 | #define SIOCGSTAMP 0x8906 | ||
| 112 | #define SIOCGSTAMPNS 0x8907 | ||
| 113 | #endif | ||
| 114 | |||
| 115 | #include <bits/ioctl_fix.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/ioctl_fix.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/ipc.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | struct ipc_perm { | ||
| 2 | 	key_t __ipc_perm_key; | ||
| 3 | 	uid_t uid; | ||
| 4 | 	gid_t gid; | ||
| 5 | 	uid_t cuid; | ||
| 6 | 	gid_t cgid; | ||
| 7 | 	mode_t mode; | ||
| 8 | 	int __ipc_perm_seq; | ||
| 9 | 	long __pad1; | ||
| 10 | 	long __pad2; | ||
| 11 | }; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/ipcstat.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #define IPC_STAT 2 | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/kd.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <linux/kd.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/limits.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/link.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | typedef uint32_t Elf_Symndx; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/mman.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/msg.h created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | struct msqid_ds { | ||
| 2 | 	struct ipc_perm msg_perm; | ||
| 3 | 	time_t msg_stime; | ||
| 4 | 	time_t msg_rtime; | ||
| 5 | 	time_t msg_ctime; | ||
| 6 | 	unsigned long msg_cbytes; | ||
| 7 | 	msgqnum_t msg_qnum; | ||
| 8 | 	msglen_t msg_qbytes; | ||
| 9 | 	pid_t msg_lspid; | ||
| 10 | 	pid_t msg_lrpid; | ||
| 11 | 	unsigned long __unused[2]; | ||
| 12 | }; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/poll.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/ptrace.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/resource.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/sem.h created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | struct semid_ds { | ||
| 2 | 	struct ipc_perm sem_perm; | ||
| 3 | 	time_t sem_otime; | ||
| 4 | 	time_t sem_ctime; | ||
| 5 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 6 | 	unsigned short sem_nsems; | ||
| 7 | 	char __sem_nsems_pad[sizeof(long)-sizeof(short)]; | ||
| 8 | #else | ||
| 9 | 	char __sem_nsems_pad[sizeof(long)-sizeof(short)]; | ||
| 10 | 	unsigned short sem_nsems; | ||
| 11 | #endif | ||
| 12 | 	long __unused3; | ||
| 13 | 	long __unused4; | ||
| 14 | }; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/shm.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #define SHMLBA 4096 | ||
| 2 | |||
| 3 | struct shmid_ds { | ||
| 4 | 	struct ipc_perm shm_perm; | ||
| 5 | 	size_t shm_segsz; | ||
| 6 | 	time_t shm_atime; | ||
| 7 | 	time_t shm_dtime; | ||
| 8 | 	time_t shm_ctime; | ||
| 9 | 	pid_t shm_cpid; | ||
| 10 | 	pid_t shm_lpid; | ||
| 11 | 	unsigned long shm_nattch; | ||
| 12 | 	unsigned long __pad1; | ||
| 13 | 	unsigned long __pad2; | ||
| 14 | }; | ||
| 15 | |||
| 16 | struct shminfo { | ||
| 17 | 	unsigned long shmmax, shmmin, shmmni, shmseg, shmall, __unused[4]; | ||
| 18 | }; | ||
| 19 | |||
| 20 | struct shm_info { | ||
| 21 | 	int __used_ids; | ||
| 22 | 	unsigned long shm_tot, shm_rss, shm_swp; | ||
| 23 | 	unsigned long __swap_attempts, __swap_successes; | ||
| 24 | }; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/socket.h createdlib/libc/wasi/libc-top-half/musl/arch/generic/bits/soundcard.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <linux/soundcard.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/statfs.h created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | struct statfs { | ||
| 2 | 	unsigned long f_type, f_bsize; | ||
| 3 | 	fsblkcnt_t f_blocks, f_bfree, f_bavail; | ||
| 4 | 	fsfilcnt_t f_files, f_ffree; | ||
| 5 | 	fsid_t f_fsid; | ||
| 6 | 	unsigned long f_namelen, f_frsize, f_flags, f_spare[4]; | ||
| 7 | }; | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/termios.h created+166| ... | @@ -0,0 +1,166 @@ | ||
| 1 | struct termios { | ||
| 2 | 	tcflag_t c_iflag; | ||
| 3 | 	tcflag_t c_oflag; | ||
| 4 | 	tcflag_t c_cflag; | ||
| 5 | 	tcflag_t c_lflag; | ||
| 6 | 	cc_t c_line; | ||
| 7 | 	cc_t c_cc[NCCS]; | ||
| 8 | 	speed_t __c_ispeed; | ||
| 9 | 	speed_t __c_ospeed; | ||
| 10 | }; | ||
| 11 | |||
| 12 | #define VINTR 0 | ||
| 13 | #define VQUIT 1 | ||
| 14 | #define VERASE 2 | ||
| 15 | #define VKILL 3 | ||
| 16 | #define VEOF 4 | ||
| 17 | #define VTIME 5 | ||
| 18 | #define VMIN 6 | ||
| 19 | #define VSWTC 7 | ||
| 20 | #define VSTART 8 | ||
| 21 | #define VSTOP 9 | ||
| 22 | #define VSUSP 10 | ||
| 23 | #define VEOL 11 | ||
| 24 | #define VREPRINT 12 | ||
| 25 | #define VDISCARD 13 | ||
| 26 | #define VWERASE 14 | ||
| 27 | #define VLNEXT 15 | ||
| 28 | #define VEOL2 16 | ||
| 29 | |||
| 30 | #define IGNBRK 0000001 | ||
| 31 | #define BRKINT 0000002 | ||
| 32 | #define IGNPAR 0000004 | ||
| 33 | #define PARMRK 0000010 | ||
| 34 | #define INPCK 0000020 | ||
| 35 | #define ISTRIP 0000040 | ||
| 36 | #define INLCR 0000100 | ||
| 37 | #define IGNCR 0000200 | ||
| 38 | #define ICRNL 0000400 | ||
| 39 | #define IUCLC 0001000 | ||
| 40 | #define IXON 0002000 | ||
| 41 | #define IXANY 0004000 | ||
| 42 | #define IXOFF 0010000 | ||
| 43 | #define IMAXBEL 0020000 | ||
| 44 | #define IUTF8 0040000 | ||
| 45 | |||
| 46 | #define OPOST 0000001 | ||
| 47 | #define OLCUC 0000002 | ||
| 48 | #define ONLCR 0000004 | ||
| 49 | #define OCRNL 0000010 | ||
| 50 | #define ONOCR 0000020 | ||
| 51 | #define ONLRET 0000040 | ||
| 52 | #define OFILL 0000100 | ||
| 53 | #define OFDEL 0000200 | ||
| 54 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) | ||
| 55 | #define NLDLY 0000400 | ||
| 56 | #define NL0 0000000 | ||
| 57 | #define NL1 0000400 | ||
| 58 | #define CRDLY 0003000 | ||
| 59 | #define CR0 0000000 | ||
| 60 | #define CR1 0001000 | ||
| 61 | #define CR2 0002000 | ||
| 62 | #define CR3 0003000 | ||
| 63 | #define TABDLY 0014000 | ||
| 64 | #define TAB0 0000000 | ||
| 65 | #define TAB1 0004000 | ||
| 66 | #define TAB2 0010000 | ||
| 67 | #define TAB3 0014000 | ||
| 68 | #define BSDLY 0020000 | ||
| 69 | #define BS0 0000000 | ||
| 70 | #define BS1 0020000 | ||
| 71 | #define FFDLY 0100000 | ||
| 72 | #define FF0 0000000 | ||
| 73 | #define FF1 0100000 | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #define VTDLY 0040000 | ||
| 77 | #define VT0 0000000 | ||
| 78 | #define VT1 0040000 | ||
| 79 | |||
| 80 | #define B0 0000000 | ||
| 81 | #define B50 0000001 | ||
| 82 | #define B75 0000002 | ||
| 83 | #define B110 0000003 | ||
| 84 | #define B134 0000004 | ||
| 85 | #define B150 0000005 | ||
| 86 | #define B200 0000006 | ||
| 87 | #define B300 0000007 | ||
| 88 | #define B600 0000010 | ||
| 89 | #define B1200 0000011 | ||
| 90 | #define B1800 0000012 | ||
| 91 | #define B2400 0000013 | ||
| 92 | #define B4800 0000014 | ||
| 93 | #define B9600 0000015 | ||
| 94 | #define B19200 0000016 | ||
| 95 | #define B38400 0000017 | ||
| 96 | |||
| 97 | #define B57600 0010001 | ||
| 98 | #define B115200 0010002 | ||
| 99 | #define B230400 0010003 | ||
| 100 | #define B460800 0010004 | ||
| 101 | #define B500000 0010005 | ||
| 102 | #define B576000 0010006 | ||
| 103 | #define B921600 0010007 | ||
| 104 | #define B1000000 0010010 | ||
| 105 | #define B1152000 0010011 | ||
| 106 | #define B1500000 0010012 | ||
| 107 | #define B2000000 0010013 | ||
| 108 | #define B2500000 0010014 | ||
| 109 | #define B3000000 0010015 | ||
| 110 | #define B3500000 0010016 | ||
| 111 | #define B4000000 0010017 | ||
| 112 | |||
| 113 | #define CSIZE 0000060 | ||
| 114 | #define CS5 0000000 | ||
| 115 | #define CS6 0000020 | ||
| 116 | #define CS7 0000040 | ||
| 117 | #define CS8 0000060 | ||
| 118 | #define CSTOPB 0000100 | ||
| 119 | #define CREAD 0000200 | ||
| 120 | #define PARENB 0000400 | ||
| 121 | #define PARODD 0001000 | ||
| 122 | #define HUPCL 0002000 | ||
| 123 | #define CLOCAL 0004000 | ||
| 124 | |||
| 125 | #define ISIG 0000001 | ||
| 126 | #define ICANON 0000002 | ||
| 127 | #define ECHO 0000010 | ||
| 128 | #define ECHOE 0000020 | ||
| 129 | #define ECHOK 0000040 | ||
| 130 | #define ECHONL 0000100 | ||
| 131 | #define NOFLSH 0000200 | ||
| 132 | #define TOSTOP 0000400 | ||
| 133 | #define IEXTEN 0100000 | ||
| 134 | |||
| 135 | #define TCOOFF 0 | ||
| 136 | #define TCOON 1 | ||
| 137 | #define TCIOFF 2 | ||
| 138 | #define TCION 3 | ||
| 139 | |||
| 140 | #define TCIFLUSH 0 | ||
| 141 | #define TCOFLUSH 1 | ||
| 142 | #define TCIOFLUSH 2 | ||
| 143 | |||
| 144 | #define TCSANOW 0 | ||
| 145 | #define TCSADRAIN 1 | ||
| 146 | #define TCSAFLUSH 2 | ||
| 147 | |||
| 148 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 149 | #define EXTA 0000016 | ||
| 150 | #define EXTB 0000017 | ||
| 151 | #define CBAUD 0010017 | ||
| 152 | #define CBAUDEX 0010000 | ||
| 153 | #define CIBAUD 002003600000 | ||
| 154 | #define CMSPAR 010000000000 | ||
| 155 | #define CRTSCTS 020000000000 | ||
| 156 | |||
| 157 | #define XCASE 0000004 | ||
| 158 | #define ECHOCTL 0001000 | ||
| 159 | #define ECHOPRT 0002000 | ||
| 160 | #define ECHOKE 0004000 | ||
| 161 | #define FLUSHO 0010000 | ||
| 162 | #define PENDIN 0040000 | ||
| 163 | #define EXTPROC 0200000 | ||
| 164 | |||
| 165 | #define XTABS 0014000 | ||
| 166 | #endif | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/bits/vt.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <linux/vt.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/generic/fp_arch.h createdlib/libc/wasi/libc-top-half/musl/arch/wasm32/atomic_arch.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #ifdef _REENTRANT | ||
| 2 | #error "multiple threads not supported in musl yet" | ||
| 3 | #endif | ||
| 4 | |||
| 5 | #define a_barrier() (__sync_synchronize()) | ||
| 6 | #define a_cas(p, t, s) (__sync_val_compare_and_swap((p), (t), (s))) | ||
| 7 | #define a_crash() (__builtin_trap()) | ||
| 8 | #define a_clz_32 __builtin_clz | ||
| 9 | #define a_clz_64 __builtin_clzll | ||
| 10 | #define a_ctz_32 __builtin_ctz | ||
| 11 | #define a_ctz_64 __builtin_ctzll | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/alltypes.h.in created+58| ... | @@ -0,0 +1,58 @@ | ||
| 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 | TYPEDEF float float_t; | ||
| 27 | TYPEDEF double double_t; | ||
| 28 | |||
| 29 | #if defined(__NEED_max_align_t) && !defined(__DEFINED_max_align_t) | ||
| 30 | #define __need_max_align_t | ||
| 31 | #include <stddef.h> | ||
| 32 | #define __DEFINED_max_align_t | ||
| 33 | #endif | ||
| 34 | |||
| 35 | #if defined(__NEED_time_t) && !defined(__DEFINED_time_t) | ||
| 36 | #include <__typedef_time_t.h> | ||
| 37 | #define __DEFINED_time_t | ||
| 38 | #endif | ||
| 39 | |||
| 40 | #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) | ||
| 41 | #include <__typedef_suseconds_t.h> | ||
| 42 | #define __DEFINED_suseconds_t | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #if defined(__NEED_clockid_t) && !defined(__DEFINED_clockid_t) | ||
| 46 | #include <__typedef_clockid_t.h> | ||
| 47 | #define __DEFINED_clockid_t | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if defined(__NEED_sigset_t) && !defined(__DEFINED_sigset_t) | ||
| 51 | #include <__typedef_sigset_t.h> | ||
| 52 | #define __DEFINED_sigset_t | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #if defined(__NEED_clock_t) && !defined(__DEFINED_clock_t) | ||
| 56 | #include <__typedef_clock_t.h> | ||
| 57 | #define __DEFINED_clock_t | ||
| 58 | #endif | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/dirent.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__struct_dirent.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/fcntl.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | /* Use the WASI libc fcntl implementation bits. */ | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/float.h created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | /* Use the WASI libc ioctl implementation bits. */ | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/limits.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__macro_PAGESIZE.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/posix.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 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 created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #undef __WORDSIZE | ||
| 2 | #define __WORDSIZE 64 | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/signal.h created+40| ... | @@ -0,0 +1,40 @@ | ||
| 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 created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <__struct_stat.h> | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/bits/stdint.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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 created+25| ... | @@ -0,0 +1,25 @@ | ||
| 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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #ifdef _REENTRANT | ||
| 2 | #error "multiple threads not supported in musl yet" | ||
| 3 | #endif | ||
| 4 | |||
| 5 | static inline struct pthread *__pthread_self(void) | ||
| 6 | { | ||
| 7 | return (struct pthread *)-1; | ||
| 8 | } | ||
| 9 | |||
| 10 | #define TP_ADJ(p) (p) | ||
| 11 | |||
| 12 | #define tls_mod_off_t unsigned long long | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/reloc.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #define LDSO_ARCH "wasm32" | ||
lib/libc/wasi/libc-top-half/musl/arch/wasm32/syscall_arch.h createdlib/libc/wasi/libc-top-half/musl/include/aio.h created+73| ... | @@ -0,0 +1,73 @@ | ||
| 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/alloca.h created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #ifndef	_ALLOCA_H | ||
| 2 | #define	_ALLOCA_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define	__NEED_size_t | ||
| 9 | #include <bits/alltypes.h> | ||
| 10 | |||
| 11 | void *alloca(size_t); | ||
| 12 | |||
| 13 | #define alloca __builtin_alloca | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | } | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/alltypes.h.in created+118| ... | @@ -0,0 +1,118 @@ | ||
| 1 | #define __LITTLE_ENDIAN 1234 | ||
| 2 | #define __BIG_ENDIAN 4321 | ||
| 3 | #define __USE_TIME_BITS64 1 | ||
| 4 | |||
| 5 | TYPEDEF unsigned _Addr size_t; | ||
| 6 | TYPEDEF unsigned _Addr uintptr_t; | ||
| 7 | TYPEDEF _Addr ptrdiff_t; | ||
| 8 | TYPEDEF _Addr ssize_t; | ||
| 9 | TYPEDEF _Addr intptr_t; | ||
| 10 | TYPEDEF _Addr regoff_t; | ||
| 11 | TYPEDEF _Reg register_t; | ||
| 12 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 13 | TYPEDEF _Int64 time_t; | ||
| 14 | TYPEDEF _Int64 suseconds_t; | ||
| 15 | #else | ||
| 16 | #if defined(__NEED_time_t) && !defined(__DEFINED_time_t) | ||
| 17 | #include <__typedef_time_t.h> | ||
| 18 | #define __DEFINED_time_t | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #if defined(__NEED_suseconds_t) && !defined(__DEFINED_suseconds_t) | ||
| 22 | #include <__typedef_suseconds_t.h> | ||
| 23 | #define __DEFINED_suseconds_t | ||
| 24 | #endif | ||
| 25 | #endif | ||
| 26 | |||
| 27 | TYPEDEF signed char int8_t; | ||
| 28 | TYPEDEF signed short int16_t; | ||
| 29 | TYPEDEF signed int int32_t; | ||
| 30 | TYPEDEF signed _Int64 int64_t; | ||
| 31 | TYPEDEF signed _Int64 intmax_t; | ||
| 32 | TYPEDEF unsigned char uint8_t; | ||
| 33 | TYPEDEF unsigned short uint16_t; | ||
| 34 | TYPEDEF unsigned int uint32_t; | ||
| 35 | TYPEDEF unsigned _Int64 uint64_t; | ||
| 36 | TYPEDEF unsigned _Int64 u_int64_t; | ||
| 37 | TYPEDEF unsigned _Int64 uintmax_t; | ||
| 38 | |||
| 39 | TYPEDEF unsigned mode_t; | ||
| 40 | TYPEDEF unsigned _Reg nlink_t; | ||
| 41 | TYPEDEF _Int64 off_t; | ||
| 42 | TYPEDEF unsigned _Int64 ino_t; | ||
| 43 | TYPEDEF unsigned _Int64 dev_t; | ||
| 44 | TYPEDEF long blksize_t; | ||
| 45 | TYPEDEF _Int64 blkcnt_t; | ||
| 46 | TYPEDEF unsigned _Int64 fsblkcnt_t; | ||
| 47 | TYPEDEF unsigned _Int64 fsfilcnt_t; | ||
| 48 | |||
| 49 | TYPEDEF unsigned wint_t; | ||
| 50 | TYPEDEF unsigned long wctype_t; | ||
| 51 | |||
| 52 | TYPEDEF void * timer_t; | ||
| 53 | TYPEDEF int clockid_t; | ||
| 54 | TYPEDEF long clock_t; | ||
| 55 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 56 | STRUCT timeval { time_t tv_sec; suseconds_t tv_usec; }; | ||
| 57 | 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); }; | ||
| 58 | #else | ||
| 59 | #include <__struct_timeval.h> | ||
| 60 | #include <__struct_timespec.h> | ||
| 61 | #endif | ||
| 62 | |||
| 63 | TYPEDEF int pid_t; | ||
| 64 | TYPEDEF unsigned id_t; | ||
| 65 | TYPEDEF unsigned uid_t; | ||
| 66 | TYPEDEF unsigned gid_t; | ||
| 67 | TYPEDEF int key_t; | ||
| 68 | TYPEDEF unsigned useconds_t; | ||
| 69 | |||
| 70 | #ifdef __cplusplus | ||
| 71 | TYPEDEF unsigned long pthread_t; | ||
| 72 | #else | ||
| 73 | TYPEDEF struct __pthread * pthread_t; | ||
| 74 | #endif | ||
| 75 | TYPEDEF int pthread_once_t; | ||
| 76 | TYPEDEF unsigned pthread_key_t; | ||
| 77 | TYPEDEF int pthread_spinlock_t; | ||
| 78 | TYPEDEF struct { unsigned __attr; } pthread_mutexattr_t; | ||
| 79 | TYPEDEF struct { unsigned __attr; } pthread_condattr_t; | ||
| 80 | TYPEDEF struct { unsigned __attr; } pthread_barrierattr_t; | ||
| 81 | TYPEDEF struct { unsigned __attr[2]; } pthread_rwlockattr_t; | ||
| 82 | |||
| 83 | #ifdef __wasilibc_unmodified_upstream /* WASI doesn't need to define FILE as a complete type */ | ||
| 84 | STRUCT _IO_FILE { char __x; }; | ||
| 85 | #endif | ||
| 86 | TYPEDEF struct _IO_FILE FILE; | ||
| 87 | |||
| 88 | TYPEDEF __builtin_va_list va_list; | ||
| 89 | TYPEDEF __builtin_va_list __isoc_va_list; | ||
| 90 | |||
| 91 | TYPEDEF struct __mbstate_t { unsigned __opaque1, __opaque2; } mbstate_t; | ||
| 92 | |||
| 93 | TYPEDEF struct __locale_struct * locale_t; | ||
| 94 | |||
| 95 | TYPEDEF struct __sigset_t { unsigned long __bits[128/sizeof(long)]; } sigset_t; | ||
| 96 | |||
| 97 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 98 | STRUCT iovec { void *iov_base; size_t iov_len; }; | ||
| 99 | #else | ||
| 100 | #include <__struct_iovec.h> | ||
| 101 | #endif | ||
| 102 | |||
| 103 | STRUCT winsize { unsigned short ws_row, ws_col, ws_xpixel, ws_ypixel; }; | ||
| 104 | |||
| 105 | TYPEDEF unsigned socklen_t; | ||
| 106 | TYPEDEF unsigned short sa_family_t; | ||
| 107 | |||
| 108 | 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; | ||
| 109 | 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; | ||
| 110 | 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; | ||
| 111 | TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } pthread_cond_t; | ||
| 112 | TYPEDEF struct { union { int __i[12]; volatile int __vi[12]; void *__p[12*sizeof(int)/sizeof(void*)]; } __u; } cnd_t; | ||
| 113 | 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; | ||
| 114 | 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; | ||
| 115 | |||
| 116 | #undef _Addr | ||
| 117 | #undef _Int64 | ||
| 118 | #undef _Reg | ||
lib/libc/wasi/libc-top-half/musl/include/ar.h created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #ifndef _AR_H | ||
| 2 | #define _AR_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define ARMAG "!<arch>\n" | ||
| 9 | #define SARMAG 8 | ||
| 10 | #define ARFMAG "`\n" | ||
| 11 | |||
| 12 | struct ar_hdr { | ||
| 13 | 	char ar_name[16]; | ||
| 14 | 	char ar_date[12]; | ||
| 15 | 	char ar_uid[6], ar_gid[6]; | ||
| 16 | 	char ar_mode[8]; | ||
| 17 | 	char ar_size[10]; | ||
| 18 | 	char ar_fmag[2]; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #ifdef __cplusplus | ||
| 22 | } | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/arpa/ftp.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #ifndef _ARPA_FTP_H | ||
| 2 | #define _ARPA_FTP_H | ||
| 3 | #define PRELIM 1 | ||
| 4 | #define COMPLETE 2 | ||
| 5 | #define CONTINUE 3 | ||
| 6 | #define TRANSIENT 4 | ||
| 7 | #define ERROR 5 | ||
| 8 | #define TYPE_A 1 | ||
| 9 | #define TYPE_E 2 | ||
| 10 | #define TYPE_I 3 | ||
| 11 | #define TYPE_L 4 | ||
| 12 | #define FORM_N 1 | ||
| 13 | #define FORM_T 2 | ||
| 14 | #define FORM_C 3 | ||
| 15 | #define STRU_F 1 | ||
| 16 | #define STRU_R 2 | ||
| 17 | #define STRU_P 3 | ||
| 18 | #define MODE_S 1 | ||
| 19 | #define MODE_B 2 | ||
| 20 | #define MODE_C 3 | ||
| 21 | #define REC_ESC '\377' | ||
| 22 | #define REC_EOR '\001' | ||
| 23 | #define REC_EOF '\002' | ||
| 24 | #define BLK_EOR 0x80 | ||
| 25 | #define BLK_EOF 0x40 | ||
| 26 | #define BLK_ERRORS 0x20 | ||
| 27 | #define BLK_RESTART 0x10 | ||
| 28 | #define BLK_BYTECOUNT 2 | ||
| 29 | #ifdef FTP_NAMES | ||
| 30 | char *modenames[] = {"0", "Stream", "Block", "Compressed" }; | ||
| 31 | char *strunames[] = {"0", "File", "Record", "Page" }; | ||
| 32 | char *typenames[] = {"0", "ASCII", "EBCDIC", "Image", "Local" }; | ||
| 33 | char *formnames[] = {"0", "Nonprint", "Telnet", "Carriage-control" }; | ||
| 34 | #endif | ||
| 35 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/arpa/inet.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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/arpa/nameser.h created+455| ... | @@ -0,0 +1,455 @@ | ||
| 1 | #ifndef _ARPA_NAMESER_H | ||
| 2 | #define _ARPA_NAMESER_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stddef.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #define __NAMESER	19991006 | ||
| 12 | #define NS_PACKETSZ	512 | ||
| 13 | #define NS_MAXDNAME	1025 | ||
| 14 | #define NS_MAXMSG	65535 | ||
| 15 | #define NS_MAXCDNAME	255 | ||
| 16 | #define NS_MAXLABEL	63 | ||
| 17 | #define NS_HFIXEDSZ	12 | ||
| 18 | #define NS_QFIXEDSZ	4 | ||
| 19 | #define NS_RRFIXEDSZ	10 | ||
| 20 | #define NS_INT32SZ	4 | ||
| 21 | #define NS_INT16SZ	2 | ||
| 22 | #define NS_INT8SZ	1 | ||
| 23 | #define NS_INADDRSZ	4 | ||
| 24 | #define NS_IN6ADDRSZ	16 | ||
| 25 | #define NS_CMPRSFLGS	0xc0 | ||
| 26 | #define NS_DEFAULTPORT	53 | ||
| 27 | |||
| 28 | typedef enum __ns_sect { | ||
| 29 | 	ns_s_qd = 0, | ||
| 30 | 	ns_s_zn = 0, | ||
| 31 | 	ns_s_an = 1, | ||
| 32 | 	ns_s_pr = 1, | ||
| 33 | 	ns_s_ns = 2, | ||
| 34 | 	ns_s_ud = 2, | ||
| 35 | 	ns_s_ar = 3, | ||
| 36 | 	ns_s_max = 4 | ||
| 37 | } ns_sect; | ||
| 38 | |||
| 39 | typedef struct __ns_msg { | ||
| 40 | 	const unsigned char *_msg, *_eom; | ||
| 41 | 	uint16_t _id, _flags, _counts[ns_s_max]; | ||
| 42 | 	const unsigned char *_sections[ns_s_max]; | ||
| 43 | 	ns_sect _sect; | ||
| 44 | 	int _rrnum; | ||
| 45 | 	const unsigned char *_msg_ptr; | ||
| 46 | } ns_msg; | ||
| 47 | |||
| 48 | struct _ns_flagdata { int mask, shift; }; | ||
| 49 | extern const struct _ns_flagdata _ns_flagdata[]; | ||
| 50 | |||
| 51 | #define ns_msg_id(handle) ((handle)._id + 0) | ||
| 52 | #define ns_msg_base(handle) ((handle)._msg + 0) | ||
| 53 | #define ns_msg_end(handle) ((handle)._eom + 0) | ||
| 54 | #define ns_msg_size(handle) ((handle)._eom - (handle)._msg) | ||
| 55 | #define ns_msg_count(handle, section) ((handle)._counts[section] + 0) | ||
| 56 | #define ns_msg_getflag(handle, flag) \ | ||
| 57 | 	(((handle)._flags & _ns_flagdata[flag].mask) >> _ns_flagdata[flag].shift) | ||
| 58 | |||
| 59 | typedef	struct __ns_rr { | ||
| 60 | 	char		name[NS_MAXDNAME]; | ||
| 61 | 	uint16_t	type; | ||
| 62 | 	uint16_t	rr_class; | ||
| 63 | 	uint32_t	ttl; | ||
| 64 | 	uint16_t	rdlength; | ||
| 65 | 	const unsigned char *rdata; | ||
| 66 | } ns_rr; | ||
| 67 | |||
| 68 | #define ns_rr_name(rr)	(((rr).name[0] != '\0') ? (rr).name : ".") | ||
| 69 | #define ns_rr_type(rr)	((ns_type)((rr).type + 0)) | ||
| 70 | #define ns_rr_class(rr)	((ns_class)((rr).rr_class + 0)) | ||
| 71 | #define ns_rr_ttl(rr)	((rr).ttl + 0) | ||
| 72 | #define ns_rr_rdlen(rr)	((rr).rdlength + 0) | ||
| 73 | #define ns_rr_rdata(rr)	((rr).rdata + 0) | ||
| 74 | |||
| 75 | typedef enum __ns_flag { | ||
| 76 | 	ns_f_qr, | ||
| 77 | 	ns_f_opcode, | ||
| 78 | 	ns_f_aa, | ||
| 79 | 	ns_f_tc, | ||
| 80 | 	ns_f_rd, | ||
| 81 | 	ns_f_ra, | ||
| 82 | 	ns_f_z, | ||
| 83 | 	ns_f_ad, | ||
| 84 | 	ns_f_cd, | ||
| 85 | 	ns_f_rcode, | ||
| 86 | 	ns_f_max | ||
| 87 | } ns_flag; | ||
| 88 | |||
| 89 | typedef enum __ns_opcode { | ||
| 90 | 	ns_o_query = 0, | ||
| 91 | 	ns_o_iquery = 1, | ||
| 92 | 	ns_o_status = 2, | ||
| 93 | 	ns_o_notify = 4, | ||
| 94 | 	ns_o_update = 5, | ||
| 95 | 	ns_o_max = 6 | ||
| 96 | } ns_opcode; | ||
| 97 | |||
| 98 | typedef	enum __ns_rcode { | ||
| 99 | 	ns_r_noerror = 0, | ||
| 100 | 	ns_r_formerr = 1, | ||
| 101 | 	ns_r_servfail = 2, | ||
| 102 | 	ns_r_nxdomain = 3, | ||
| 103 | 	ns_r_notimpl = 4, | ||
| 104 | 	ns_r_refused = 5, | ||
| 105 | 	ns_r_yxdomain = 6, | ||
| 106 | 	ns_r_yxrrset = 7, | ||
| 107 | 	ns_r_nxrrset = 8, | ||
| 108 | 	ns_r_notauth = 9, | ||
| 109 | 	ns_r_notzone = 10, | ||
| 110 | 	ns_r_max = 11, | ||
| 111 | 	ns_r_badvers = 16, | ||
| 112 | 	ns_r_badsig = 16, | ||
| 113 | 	ns_r_badkey = 17, | ||
| 114 | 	ns_r_badtime = 18 | ||
| 115 | } ns_rcode; | ||
| 116 | |||
| 117 | typedef enum __ns_update_operation { | ||
| 118 | 	ns_uop_delete = 0, | ||
| 119 | 	ns_uop_add = 1, | ||
| 120 | 	ns_uop_max = 2 | ||
| 121 | } ns_update_operation; | ||
| 122 | |||
| 123 | struct ns_tsig_key { | ||
| 124 | char name[NS_MAXDNAME], alg[NS_MAXDNAME]; | ||
| 125 | unsigned char *data; | ||
| 126 | int len; | ||
| 127 | }; | ||
| 128 | typedef struct ns_tsig_key ns_tsig_key; | ||
| 129 | |||
| 130 | struct ns_tcp_tsig_state { | ||
| 131 | 	int counter; | ||
| 132 | 	struct dst_key *key; | ||
| 133 | 	void *ctx; | ||
| 134 | 	unsigned char sig[NS_PACKETSZ]; | ||
| 135 | 	int siglen; | ||
| 136 | }; | ||
| 137 | typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; | ||
| 138 | |||
| 139 | #define NS_TSIG_FUDGE 300 | ||
| 140 | #define NS_TSIG_TCP_COUNT 100 | ||
| 141 | #define NS_TSIG_ALG_HMAC_MD5 "HMAC-MD5.SIG-ALG.REG.INT" | ||
| 142 | |||
| 143 | #define NS_TSIG_ERROR_NO_TSIG -10 | ||
| 144 | #define NS_TSIG_ERROR_NO_SPACE -11 | ||
| 145 | #define NS_TSIG_ERROR_FORMERR -12 | ||
| 146 | |||
| 147 | typedef enum __ns_type { | ||
| 148 | 	ns_t_invalid = 0, | ||
| 149 | 	ns_t_a = 1, | ||
| 150 | 	ns_t_ns = 2, | ||
| 151 | 	ns_t_md = 3, | ||
| 152 | 	ns_t_mf = 4, | ||
| 153 | 	ns_t_cname = 5, | ||
| 154 | 	ns_t_soa = 6, | ||
| 155 | 	ns_t_mb = 7, | ||
| 156 | 	ns_t_mg = 8, | ||
| 157 | 	ns_t_mr = 9, | ||
| 158 | 	ns_t_null = 10, | ||
| 159 | 	ns_t_wks = 11, | ||
| 160 | 	ns_t_ptr = 12, | ||
| 161 | 	ns_t_hinfo = 13, | ||
| 162 | 	ns_t_minfo = 14, | ||
| 163 | 	ns_t_mx = 15, | ||
| 164 | 	ns_t_txt = 16, | ||
| 165 | 	ns_t_rp = 17, | ||
| 166 | 	ns_t_afsdb = 18, | ||
| 167 | 	ns_t_x25 = 19, | ||
| 168 | 	ns_t_isdn = 20, | ||
| 169 | 	ns_t_rt = 21, | ||
| 170 | 	ns_t_nsap = 22, | ||
| 171 | 	ns_t_nsap_ptr = 23, | ||
| 172 | 	ns_t_sig = 24, | ||
| 173 | 	ns_t_key = 25, | ||
| 174 | 	ns_t_px = 26, | ||
| 175 | 	ns_t_gpos = 27, | ||
| 176 | 	ns_t_aaaa = 28, | ||
| 177 | 	ns_t_loc = 29, | ||
| 178 | 	ns_t_nxt = 30, | ||
| 179 | 	ns_t_eid = 31, | ||
| 180 | 	ns_t_nimloc = 32, | ||
| 181 | 	ns_t_srv = 33, | ||
| 182 | 	ns_t_atma = 34, | ||
| 183 | 	ns_t_naptr = 35, | ||
| 184 | 	ns_t_kx = 36, | ||
| 185 | 	ns_t_cert = 37, | ||
| 186 | 	ns_t_a6 = 38, | ||
| 187 | 	ns_t_dname = 39, | ||
| 188 | 	ns_t_sink = 40, | ||
| 189 | 	ns_t_opt = 41, | ||
| 190 | 	ns_t_apl = 42, | ||
| 191 | 	ns_t_tkey = 249, | ||
| 192 | 	ns_t_tsig = 250, | ||
| 193 | 	ns_t_ixfr = 251, | ||
| 194 | 	ns_t_axfr = 252, | ||
| 195 | 	ns_t_mailb = 253, | ||
| 196 | 	ns_t_maila = 254, | ||
| 197 | 	ns_t_any = 255, | ||
| 198 | 	ns_t_zxfr = 256, | ||
| 199 | 	ns_t_max = 65536 | ||
| 200 | } ns_type; | ||
| 201 | |||
| 202 | #define	ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ | ||
| 203 | 		 (t) == ns_t_mailb || (t) == ns_t_maila) | ||
| 204 | #define	ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) | ||
| 205 | #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) | ||
| 206 | #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) | ||
| 207 | #define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ | ||
| 208 | 		 (t) == ns_t_zxfr) | ||
| 209 | |||
| 210 | typedef enum __ns_class { | ||
| 211 | 	ns_c_invalid = 0, | ||
| 212 | 	ns_c_in = 1, | ||
| 213 | 	ns_c_2 = 2, | ||
| 214 | 	ns_c_chaos = 3, | ||
| 215 | 	ns_c_hs = 4, | ||
| 216 | 	ns_c_none = 254, | ||
| 217 | 	ns_c_any = 255, | ||
| 218 | 	ns_c_max = 65536 | ||
| 219 | } ns_class; | ||
| 220 | |||
| 221 | typedef enum __ns_key_types { | ||
| 222 | 	ns_kt_rsa = 1, | ||
| 223 | 	ns_kt_dh = 2, | ||
| 224 | 	ns_kt_dsa = 3, | ||
| 225 | 	ns_kt_private = 254 | ||
| 226 | } ns_key_types; | ||
| 227 | |||
| 228 | typedef enum __ns_cert_types { | ||
| 229 | 	cert_t_pkix = 1, | ||
| 230 | 	cert_t_spki = 2, | ||
| 231 | 	cert_t_pgp = 3, | ||
| 232 | 	cert_t_url = 253, | ||
| 233 | 	cert_t_oid = 254 | ||
| 234 | } ns_cert_types; | ||
| 235 | |||
| 236 | #define	NS_KEY_TYPEMASK		0xC000 | ||
| 237 | #define	NS_KEY_TYPE_AUTH_CONF	0x0000 | ||
| 238 | #define	NS_KEY_TYPE_CONF_ONLY	0x8000 | ||
| 239 | #define	NS_KEY_TYPE_AUTH_ONLY	0x4000 | ||
| 240 | #define	NS_KEY_TYPE_NO_KEY	0xC000 | ||
| 241 | #define	NS_KEY_NO_AUTH		0x8000 | ||
| 242 | #define	NS_KEY_NO_CONF		0x4000 | ||
| 243 | #define	NS_KEY_RESERVED2	0x2000 | ||
| 244 | #define	NS_KEY_EXTENDED_FLAGS	0x1000 | ||
| 245 | #define	NS_KEY_RESERVED4	0x0800 | ||
| 246 | #define	NS_KEY_RESERVED5	0x0400 | ||
| 247 | #define	NS_KEY_NAME_TYPE	0x0300 | ||
| 248 | #define	NS_KEY_NAME_USER	0x0000 | ||
| 249 | #define	NS_KEY_NAME_ENTITY	0x0200 | ||
| 250 | #define	NS_KEY_NAME_ZONE	0x0100 | ||
| 251 | #define	NS_KEY_NAME_RESERVED	0x0300 | ||
| 252 | #define	NS_KEY_RESERVED8	0x0080 | ||
| 253 | #define	NS_KEY_RESERVED9	0x0040 | ||
| 254 | #define	NS_KEY_RESERVED10	0x0020 | ||
| 255 | #define	NS_KEY_RESERVED11	0x0010 | ||
| 256 | #define	NS_KEY_SIGNATORYMASK	0x000F | ||
| 257 | #define	NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ | ||
| 258 | 				 NS_KEY_RESERVED4 | \ | ||
| 259 | 				 NS_KEY_RESERVED5 | \ | ||
| 260 | 				 NS_KEY_RESERVED8 | \ | ||
| 261 | 				 NS_KEY_RESERVED9 | \ | ||
| 262 | 				 NS_KEY_RESERVED10 | \ | ||
| 263 | 				 NS_KEY_RESERVED11 ) | ||
| 264 | #define NS_KEY_RESERVED_BITMASK2 0xFFFF | ||
| 265 | #define	NS_ALG_MD5RSA		1 | ||
| 266 | #define	NS_ALG_DH 2 | ||
| 267 | #define	NS_ALG_DSA 3 | ||
| 268 | #define	NS_ALG_DSS NS_ALG_DSA | ||
| 269 | #define	NS_ALG_EXPIRE_ONLY	253 | ||
| 270 | #define	NS_ALG_PRIVATE_OID	254 | ||
| 271 | |||
| 272 | #define NS_KEY_PROT_TLS 1 | ||
| 273 | #define NS_KEY_PROT_EMAIL 2 | ||
| 274 | #define NS_KEY_PROT_DNSSEC 3 | ||
| 275 | #define NS_KEY_PROT_IPSEC 4 | ||
| 276 | #define NS_KEY_PROT_ANY		255 | ||
| 277 | |||
| 278 | #define	NS_MD5RSA_MIN_BITS	 512 | ||
| 279 | #define	NS_MD5RSA_MAX_BITS	4096 | ||
| 280 | #define	NS_MD5RSA_MAX_BYTES	((NS_MD5RSA_MAX_BITS+7/8)*2+3) | ||
| 281 | #define	NS_MD5RSA_MAX_BASE64	(((NS_MD5RSA_MAX_BYTES+2)/3)*4) | ||
| 282 | #define NS_MD5RSA_MIN_SIZE	((NS_MD5RSA_MIN_BITS+7)/8) | ||
| 283 | #define NS_MD5RSA_MAX_SIZE	((NS_MD5RSA_MAX_BITS+7)/8) | ||
| 284 | |||
| 285 | #define NS_DSA_SIG_SIZE 41 | ||
| 286 | #define NS_DSA_MIN_SIZE 213 | ||
| 287 | #define NS_DSA_MAX_BYTES 405 | ||
| 288 | |||
| 289 | #define	NS_SIG_TYPE	0 | ||
| 290 | #define	NS_SIG_ALG	2 | ||
| 291 | #define	NS_SIG_LABELS	3 | ||
| 292 | #define	NS_SIG_OTTL	4 | ||
| 293 | #define	NS_SIG_EXPIR	8 | ||
| 294 | #define	NS_SIG_SIGNED	12 | ||
| 295 | #define	NS_SIG_FOOT	16 | ||
| 296 | #define	NS_SIG_SIGNER	18 | ||
| 297 | #define	NS_NXT_BITS 8 | ||
| 298 | #define	NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) | ||
| 299 | #define	NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) | ||
| 300 | #define	NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) | ||
| 301 | #define NS_NXT_MAX 127 | ||
| 302 | |||
| 303 | #define NS_OPT_DNSSEC_OK 0x8000U | ||
| 304 | #define NS_OPT_NSID		3 | ||
| 305 | |||
| 306 | #define NS_GET16(s, cp) (void)((s) = ns_get16(((cp)+=2)-2)) | ||
| 307 | #define NS_GET32(l, cp) (void)((l) = ns_get32(((cp)+=4)-4)) | ||
| 308 | #define NS_PUT16(s, cp) ns_put16((s), ((cp)+=2)-2) | ||
| 309 | #define NS_PUT32(l, cp) ns_put32((l), ((cp)+=4)-4) | ||
| 310 | |||
| 311 | unsigned ns_get16(const unsigned char *); | ||
| 312 | unsigned long ns_get32(const unsigned char *); | ||
| 313 | void ns_put16(unsigned, unsigned char *); | ||
| 314 | void ns_put32(unsigned long, unsigned char *); | ||
| 315 | |||
| 316 | int ns_initparse(const unsigned char *, int, ns_msg *); | ||
| 317 | int ns_parserr(ns_msg *, ns_sect, int, ns_rr *); | ||
| 318 | int ns_skiprr(const unsigned char *, const unsigned char *, ns_sect, int); | ||
| 319 | int ns_name_uncompress(const unsigned char *, const unsigned char *, const unsigned char *, char *, size_t); | ||
| 320 | |||
| 321 | |||
| 322 | #define	__BIND		19950621 | ||
| 323 | |||
| 324 | typedef struct { | ||
| 325 | 	unsigned	id :16; | ||
| 326 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 327 | 	unsigned	qr: 1; | ||
| 328 | 	unsigned	opcode: 4; | ||
| 329 | 	unsigned	aa: 1; | ||
| 330 | 	unsigned	tc: 1; | ||
| 331 | 	unsigned	rd: 1; | ||
| 332 | 	unsigned	ra: 1; | ||
| 333 | 	unsigned	unused :1; | ||
| 334 | 	unsigned	ad: 1; | ||
| 335 | 	unsigned	cd: 1; | ||
| 336 | 	unsigned	rcode :4; | ||
| 337 | #else | ||
| 338 | 	unsigned	rd :1; | ||
| 339 | 	unsigned	tc :1; | ||
| 340 | 	unsigned	aa :1; | ||
| 341 | 	unsigned	opcode :4; | ||
| 342 | 	unsigned	qr :1; | ||
| 343 | 	unsigned	rcode :4; | ||
| 344 | 	unsigned	cd: 1; | ||
| 345 | 	unsigned	ad: 1; | ||
| 346 | 	unsigned	unused :1; | ||
| 347 | 	unsigned	ra :1; | ||
| 348 | #endif | ||
| 349 | 	unsigned	qdcount :16; | ||
| 350 | 	unsigned	ancount :16; | ||
| 351 | 	unsigned	nscount :16; | ||
| 352 | 	unsigned	arcount :16; | ||
| 353 | } HEADER; | ||
| 354 | |||
| 355 | #define PACKETSZ	NS_PACKETSZ | ||
| 356 | #define MAXDNAME	NS_MAXDNAME | ||
| 357 | #define MAXCDNAME	NS_MAXCDNAME | ||
| 358 | #define MAXLABEL	NS_MAXLABEL | ||
| 359 | #define	HFIXEDSZ	NS_HFIXEDSZ | ||
| 360 | #define QFIXEDSZ	NS_QFIXEDSZ | ||
| 361 | #define RRFIXEDSZ	NS_RRFIXEDSZ | ||
| 362 | #define	INT32SZ		NS_INT32SZ | ||
| 363 | #define	INT16SZ		NS_INT16SZ | ||
| 364 | #define INT8SZ		NS_INT8SZ | ||
| 365 | #define	INADDRSZ	NS_INADDRSZ | ||
| 366 | #define	IN6ADDRSZ	NS_IN6ADDRSZ | ||
| 367 | #define	INDIR_MASK	NS_CMPRSFLGS | ||
| 368 | #define NAMESERVER_PORT	NS_DEFAULTPORT | ||
| 369 | |||
| 370 | #define S_ZONE		ns_s_zn | ||
| 371 | #define S_PREREQ	ns_s_pr | ||
| 372 | #define S_UPDATE	ns_s_ud | ||
| 373 | #define S_ADDT		ns_s_ar | ||
| 374 | |||
| 375 | #define QUERY		ns_o_query | ||
| 376 | #define IQUERY		ns_o_iquery | ||
| 377 | #define STATUS		ns_o_status | ||
| 378 | #define	NS_NOTIFY_OP	ns_o_notify | ||
| 379 | #define	NS_UPDATE_OP	ns_o_update | ||
| 380 | |||
| 381 | #define NOERROR		ns_r_noerror | ||
| 382 | #define FORMERR		ns_r_formerr | ||
| 383 | #define SERVFAIL	ns_r_servfail | ||
| 384 | #define NXDOMAIN	ns_r_nxdomain | ||
| 385 | #define NOTIMP		ns_r_notimpl | ||
| 386 | #define REFUSED		ns_r_refused | ||
| 387 | #define YXDOMAIN	ns_r_yxdomain | ||
| 388 | #define YXRRSET		ns_r_yxrrset | ||
| 389 | #define NXRRSET		ns_r_nxrrset | ||
| 390 | #define NOTAUTH		ns_r_notauth | ||
| 391 | #define NOTZONE		ns_r_notzone | ||
| 392 | |||
| 393 | #define DELETE		ns_uop_delete | ||
| 394 | #define ADD		ns_uop_add | ||
| 395 | |||
| 396 | #define T_A		ns_t_a | ||
| 397 | #define T_NS		ns_t_ns | ||
| 398 | #define T_MD		ns_t_md | ||
| 399 | #define T_MF		ns_t_mf | ||
| 400 | #define T_CNAME		ns_t_cname | ||
| 401 | #define T_SOA		ns_t_soa | ||
| 402 | #define T_MB		ns_t_mb | ||
| 403 | #define T_MG		ns_t_mg | ||
| 404 | #define T_MR		ns_t_mr | ||
| 405 | #define T_NULL		ns_t_null | ||
| 406 | #define T_WKS		ns_t_wks | ||
| 407 | #define T_PTR		ns_t_ptr | ||
| 408 | #define T_HINFO		ns_t_hinfo | ||
| 409 | #define T_MINFO		ns_t_minfo | ||
| 410 | #define T_MX		ns_t_mx | ||
| 411 | #define T_TXT		ns_t_txt | ||
| 412 | #define	T_RP		ns_t_rp | ||
| 413 | #define T_AFSDB		ns_t_afsdb | ||
| 414 | #define T_X25		ns_t_x25 | ||
| 415 | #define T_ISDN		ns_t_isdn | ||
| 416 | #define T_RT		ns_t_rt | ||
| 417 | #define T_NSAP		ns_t_nsap | ||
| 418 | #define T_NSAP_PTR	ns_t_nsap_ptr | ||
| 419 | #define	T_SIG		ns_t_sig | ||
| 420 | #define	T_KEY		ns_t_key | ||
| 421 | #define	T_PX		ns_t_px | ||
| 422 | #define	T_GPOS		ns_t_gpos | ||
| 423 | #define	T_AAAA		ns_t_aaaa | ||
| 424 | #define	T_LOC		ns_t_loc | ||
| 425 | #define	T_NXT		ns_t_nxt | ||
| 426 | #define	T_EID		ns_t_eid | ||
| 427 | #define	T_NIMLOC	ns_t_nimloc | ||
| 428 | #define	T_SRV		ns_t_srv | ||
| 429 | #define T_ATMA		ns_t_atma | ||
| 430 | #define T_NAPTR		ns_t_naptr | ||
| 431 | #define T_A6		ns_t_a6 | ||
| 432 | #define T_DNAME		ns_t_dname | ||
| 433 | #define	T_TSIG		ns_t_tsig | ||
| 434 | #define	T_IXFR		ns_t_ixfr | ||
| 435 | #define T_AXFR		ns_t_axfr | ||
| 436 | #define T_MAILB		ns_t_mailb | ||
| 437 | #define T_MAILA		ns_t_maila | ||
| 438 | #define T_ANY		ns_t_any | ||
| 439 | |||
| 440 | #define C_IN		ns_c_in | ||
| 441 | #define C_CHAOS		ns_c_chaos | ||
| 442 | #define C_HS		ns_c_hs | ||
| 443 | #define C_NONE		ns_c_none | ||
| 444 | #define C_ANY		ns_c_any | ||
| 445 | |||
| 446 | #define	GETSHORT		NS_GET16 | ||
| 447 | #define	GETLONG			NS_GET32 | ||
| 448 | #define	PUTSHORT		NS_PUT16 | ||
| 449 | #define	PUTLONG			NS_PUT32 | ||
| 450 | |||
| 451 | #ifdef __cplusplus | ||
| 452 | } | ||
| 453 | #endif | ||
| 454 | |||
| 455 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/arpa/nameser_compat.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <arpa/nameser.h> | ||
| 2 | |||
lib/libc/wasi/libc-top-half/musl/include/arpa/telnet.h created+251| ... | @@ -0,0 +1,251 @@ | ||
| 1 | #ifndef _ARPA_TELNET_H | ||
| 2 | #define	_ARPA_TELNET_H | ||
| 3 | |||
| 4 | #define	IAC	255 | ||
| 5 | #define	DONT	254 | ||
| 6 | #define	DO	253 | ||
| 7 | #define	WONT	252 | ||
| 8 | #define	WILL	251 | ||
| 9 | #define	SB	250 | ||
| 10 | #define	GA	249 | ||
| 11 | #define	EL	248 | ||
| 12 | #define	EC	247 | ||
| 13 | #define	AYT	246 | ||
| 14 | #define	AO	245 | ||
| 15 | #define	IP	244 | ||
| 16 | #define	BREAK	243 | ||
| 17 | #define	DM	242 | ||
| 18 | #define	NOP	241 | ||
| 19 | #define	SE	240 | ||
| 20 | #define EOR 239 | ||
| 21 | #define	ABORT	238 | ||
| 22 | #define	SUSP	237 | ||
| 23 | #define	xEOF	236 | ||
| 24 | |||
| 25 | #define SYNCH	242 | ||
| 26 | |||
| 27 | #define telcmds ((char [][6]){ "EOF", "SUSP", "ABORT", "EOR", "SE", "NOP", "DMARK", "BRK", "IP", "AO", "AYT", "EC", "EL", "GA", "SB", "WILL", "WONT", "DO", "DONT", "IAC", 0 }) | ||
| 28 | |||
| 29 | #define	TELCMD_FIRST	xEOF | ||
| 30 | #define	TELCMD_LAST	IAC | ||
| 31 | #define	TELCMD_OK(x)	((unsigned int)(x) <= TELCMD_LAST && \ | ||
| 32 | 			 (unsigned int)(x) >= TELCMD_FIRST) | ||
| 33 | #define	TELCMD(x)	telcmds[(x)-TELCMD_FIRST] | ||
| 34 | |||
| 35 | #define TELOPT_BINARY	0 | ||
| 36 | #define TELOPT_ECHO	1 | ||
| 37 | #define	TELOPT_RCP	2 | ||
| 38 | #define	TELOPT_SGA	3 | ||
| 39 | #define	TELOPT_NAMS	4 | ||
| 40 | #define	TELOPT_STATUS	5 | ||
| 41 | #define	TELOPT_TM	6 | ||
| 42 | #define	TELOPT_RCTE	7 | ||
| 43 | #define TELOPT_NAOL 	8 | ||
| 44 | #define TELOPT_NAOP 	9 | ||
| 45 | #define TELOPT_NAOCRD	10 | ||
| 46 | #define TELOPT_NAOHTS	11 | ||
| 47 | #define TELOPT_NAOHTD	12 | ||
| 48 | #define TELOPT_NAOFFD	13 | ||
| 49 | #define TELOPT_NAOVTS	14 | ||
| 50 | #define TELOPT_NAOVTD	15 | ||
| 51 | #define TELOPT_NAOLFD	16 | ||
| 52 | #define TELOPT_XASCII	17 | ||
| 53 | #define	TELOPT_LOGOUT	18 | ||
| 54 | #define	TELOPT_BM	19 | ||
| 55 | #define	TELOPT_DET	20 | ||
| 56 | #define	TELOPT_SUPDUP	21 | ||
| 57 | #define	TELOPT_SUPDUPOUTPUT 22 | ||
| 58 | #define	TELOPT_SNDLOC	23 | ||
| 59 | #define	TELOPT_TTYPE	24 | ||
| 60 | #define	TELOPT_EOR	25 | ||
| 61 | #define	TELOPT_TUID	26 | ||
| 62 | #define	TELOPT_OUTMRK	27 | ||
| 63 | #define	TELOPT_TTYLOC	28 | ||
| 64 | #define	TELOPT_3270REGIME 29 | ||
| 65 | #define	TELOPT_X3PAD	30 | ||
| 66 | #define	TELOPT_NAWS	31 | ||
| 67 | #define	TELOPT_TSPEED	32 | ||
| 68 | #define	TELOPT_LFLOW	33 | ||
| 69 | #define TELOPT_LINEMODE	34 | ||
| 70 | #define TELOPT_XDISPLOC	35 | ||
| 71 | #define TELOPT_OLD_ENVIRON 36 | ||
| 72 | #define	TELOPT_AUTHENTICATION 37/* Authenticate */ | ||
| 73 | #define	TELOPT_ENCRYPT	38 | ||
| 74 | #define TELOPT_NEW_ENVIRON 39 | ||
| 75 | #define	TELOPT_EXOPL	255 | ||
| 76 | |||
| 77 | |||
| 78 | #define	NTELOPTS	(1+TELOPT_NEW_ENVIRON) | ||
| 79 | #ifdef TELOPTS | ||
| 80 | char *telopts[NTELOPTS+1] = { | ||
| 81 | 	"BINARY", "ECHO", "RCP", "SUPPRESS GO AHEAD", "NAME", | ||
| 82 | 	"STATUS", "TIMING MARK", "RCTE", "NAOL", "NAOP", | ||
| 83 | 	"NAOCRD", "NAOHTS", "NAOHTD", "NAOFFD", "NAOVTS", | ||
| 84 | 	"NAOVTD", "NAOLFD", "EXTEND ASCII", "LOGOUT", "BYTE MACRO", | ||
| 85 | 	"DATA ENTRY TERMINAL", "SUPDUP", "SUPDUP OUTPUT", | ||
| 86 | 	"SEND LOCATION", "TERMINAL TYPE", "END OF RECORD", | ||
| 87 | 	"TACACS UID", "OUTPUT MARKING", "TTYLOC", | ||
| 88 | 	"3270 REGIME", "X.3 PAD", "NAWS", "TSPEED", "LFLOW", | ||
| 89 | 	"LINEMODE", "XDISPLOC", "OLD-ENVIRON", "AUTHENTICATION", | ||
| 90 | 	"ENCRYPT", "NEW-ENVIRON", | ||
| 91 | 	0, | ||
| 92 | }; | ||
| 93 | #define	TELOPT_FIRST	TELOPT_BINARY | ||
| 94 | #define	TELOPT_LAST	TELOPT_NEW_ENVIRON | ||
| 95 | #define	TELOPT_OK(x)	((unsigned int)(x) <= TELOPT_LAST) | ||
| 96 | #define	TELOPT(x)	telopts[(x)-TELOPT_FIRST] | ||
| 97 | #endif | ||
| 98 | |||
| 99 | #define	TELQUAL_IS	0 | ||
| 100 | #define	TELQUAL_SEND	1 | ||
| 101 | #define	TELQUAL_INFO	2 | ||
| 102 | #define	TELQUAL_REPLY	2 | ||
| 103 | #define	TELQUAL_NAME	3 | ||
| 104 | |||
| 105 | #define	LFLOW_OFF		0 | ||
| 106 | #define	LFLOW_ON		1 | ||
| 107 | #define	LFLOW_RESTART_ANY	2 | ||
| 108 | #define	LFLOW_RESTART_XON	3 | ||
| 109 | |||
| 110 | |||
| 111 | #define	LM_MODE		1 | ||
| 112 | #define	LM_FORWARDMASK	2 | ||
| 113 | #define	LM_SLC		3 | ||
| 114 | |||
| 115 | #define	MODE_EDIT	0x01 | ||
| 116 | #define	MODE_TRAPSIG	0x02 | ||
| 117 | #define	MODE_ACK	0x04 | ||
| 118 | #define MODE_SOFT_TAB	0x08 | ||
| 119 | #define MODE_LIT_ECHO	0x10 | ||
| 120 | |||
| 121 | #define	MODE_MASK	0x1f | ||
| 122 | |||
| 123 | #define MODE_FLOW		0x0100 | ||
| 124 | #define MODE_ECHO		0x0200 | ||
| 125 | #define MODE_INBIN		0x0400 | ||
| 126 | #define MODE_OUTBIN		0x0800 | ||
| 127 | #define MODE_FORCE		0x1000 | ||
| 128 | |||
| 129 | #define	SLC_SYNCH	1 | ||
| 130 | #define	SLC_BRK		2 | ||
| 131 | #define	SLC_IP		3 | ||
| 132 | #define	SLC_AO		4 | ||
| 133 | #define	SLC_AYT		5 | ||
| 134 | #define	SLC_EOR		6 | ||
| 135 | #define	SLC_ABORT	7 | ||
| 136 | #define	SLC_EOF		8 | ||
| 137 | #define	SLC_SUSP	9 | ||
| 138 | #define	SLC_EC		10 | ||
| 139 | #define	SLC_EL		11 | ||
| 140 | #define	SLC_EW		12 | ||
| 141 | #define	SLC_RP		13 | ||
| 142 | #define	SLC_LNEXT	14 | ||
| 143 | #define	SLC_XON		15 | ||
| 144 | #define	SLC_XOFF	16 | ||
| 145 | #define	SLC_FORW1	17 | ||
| 146 | #define	SLC_FORW2	18 | ||
| 147 | |||
| 148 | #define	NSLC		18 | ||
| 149 | |||
| 150 | #define	SLC_NAMELIST	"0", "SYNCH", "BRK", "IP", "AO", "AYT", "EOR", \ | ||
| 151 | 			"ABORT", "EOF", "SUSP", "EC", "EL", "EW", "RP", \ | ||
| 152 | 			"LNEXT", "XON", "XOFF", "FORW1", "FORW2", 0, | ||
| 153 | #ifdef	SLC_NAMES | ||
| 154 | char *slc_names[] = { | ||
| 155 | 	SLC_NAMELIST | ||
| 156 | }; | ||
| 157 | #else | ||
| 158 | extern char *slc_names[]; | ||
| 159 | #define	SLC_NAMES SLC_NAMELIST | ||
| 160 | #endif | ||
| 161 | |||
| 162 | #define	SLC_NAME_OK(x)	((unsigned int)(x) <= NSLC) | ||
| 163 | #define SLC_NAME(x)	slc_names[x] | ||
| 164 | |||
| 165 | #define	SLC_NOSUPPORT	0 | ||
| 166 | #define	SLC_CANTCHANGE	1 | ||
| 167 | #define	SLC_VARIABLE	2 | ||
| 168 | #define	SLC_DEFAULT	3 | ||
| 169 | #define	SLC_LEVELBITS	0x03 | ||
| 170 | |||
| 171 | #define	SLC_FUNC	0 | ||
| 172 | #define	SLC_FLAGS	1 | ||
| 173 | #define	SLC_VALUE	2 | ||
| 174 | |||
| 175 | #define	SLC_ACK		0x80 | ||
| 176 | #define	SLC_FLUSHIN	0x40 | ||
| 177 | #define	SLC_FLUSHOUT	0x20 | ||
| 178 | |||
| 179 | #define	OLD_ENV_VAR	1 | ||
| 180 | #define	OLD_ENV_VALUE	0 | ||
| 181 | #define	NEW_ENV_VAR	0 | ||
| 182 | #define	NEW_ENV_VALUE	1 | ||
| 183 | #define	ENV_ESC		2 | ||
| 184 | #define ENV_USERVAR	3 | ||
| 185 | |||
| 186 | #define	AUTH_WHO_CLIENT		0 | ||
| 187 | #define	AUTH_WHO_SERVER		1 | ||
| 188 | #define	AUTH_WHO_MASK		1 | ||
| 189 | |||
| 190 | #define	AUTH_HOW_ONE_WAY	0 | ||
| 191 | #define	AUTH_HOW_MUTUAL		2 | ||
| 192 | #define	AUTH_HOW_MASK		2 | ||
| 193 | |||
| 194 | #define	AUTHTYPE_NULL		0 | ||
| 195 | #define	AUTHTYPE_KERBEROS_V4	1 | ||
| 196 | #define	AUTHTYPE_KERBEROS_V5	2 | ||
| 197 | #define	AUTHTYPE_SPX		3 | ||
| 198 | #define	AUTHTYPE_MINK		4 | ||
| 199 | #define	AUTHTYPE_CNT		5 | ||
| 200 | |||
| 201 | #define	AUTHTYPE_TEST		99 | ||
| 202 | |||
| 203 | #ifdef	AUTH_NAMES | ||
| 204 | char *authtype_names[] = { | ||
| 205 | 	"NULL", "KERBEROS_V4", "KERBEROS_V5", "SPX", "MINK", 0, | ||
| 206 | }; | ||
| 207 | #else | ||
| 208 | extern char *authtype_names[]; | ||
| 209 | #endif | ||
| 210 | |||
| 211 | #define	AUTHTYPE_NAME_OK(x)	((unsigned int)(x) < AUTHTYPE_CNT) | ||
| 212 | #define	AUTHTYPE_NAME(x)	authtype_names[x] | ||
| 213 | |||
| 214 | #define	ENCRYPT_IS		0 | ||
| 215 | #define	ENCRYPT_SUPPORT		1 | ||
| 216 | #define	ENCRYPT_REPLY		2 | ||
| 217 | #define	ENCRYPT_START		3 | ||
| 218 | #define	ENCRYPT_END		4 | ||
| 219 | #define	ENCRYPT_REQSTART	5 | ||
| 220 | #define	ENCRYPT_REQEND		6 | ||
| 221 | #define	ENCRYPT_ENC_KEYID	7 | ||
| 222 | #define	ENCRYPT_DEC_KEYID	8 | ||
| 223 | #define	ENCRYPT_CNT		9 | ||
| 224 | |||
| 225 | #define	ENCTYPE_ANY		0 | ||
| 226 | #define	ENCTYPE_DES_CFB64	1 | ||
| 227 | #define	ENCTYPE_DES_OFB64	2 | ||
| 228 | #define	ENCTYPE_CNT		3 | ||
| 229 | |||
| 230 | #ifdef	ENCRYPT_NAMES | ||
| 231 | char *encrypt_names[] = { | ||
| 232 | 	"IS", "SUPPORT", "REPLY", "START", "END", | ||
| 233 | 	"REQUEST-START", "REQUEST-END", "ENC-KEYID", "DEC-KEYID", | ||
| 234 | 	0, | ||
| 235 | }; | ||
| 236 | char *enctype_names[] = { | ||
| 237 | 	"ANY", "DES_CFB64", "DES_OFB64", 0, | ||
| 238 | }; | ||
| 239 | #else | ||
| 240 | extern char *encrypt_names[]; | ||
| 241 | extern char *enctype_names[]; | ||
| 242 | #endif | ||
| 243 | |||
| 244 | |||
| 245 | #define	ENCRYPT_NAME_OK(x)	((unsigned int)(x) < ENCRYPT_CNT) | ||
| 246 | #define	ENCRYPT_NAME(x)		encrypt_names[x] | ||
| 247 | |||
| 248 | #define	ENCTYPE_NAME_OK(x)	((unsigned int)(x) < ENCTYPE_CNT) | ||
| 249 | #define	ENCTYPE_NAME(x)		enctype_names[x] | ||
| 250 | |||
| 251 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/arpa/tftp.h created+31| ... | @@ -0,0 +1,31 @@ | ||
| 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/wasi/libc-top-half/musl/include/assert.h created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | #undef assert | ||
| 4 | |||
| 5 | #ifdef NDEBUG | ||
| 6 | #define	assert(x) (void)0 | ||
| 7 | #else | ||
| 8 | #define assert(x) ((void)((x) || (__assert_fail(#x, __FILE__, __LINE__, __func__),0))) | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #if __STDC_VERSION__ >= 201112L && !defined(__cplusplus) | ||
| 12 | #define static_assert _Static_assert | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #ifdef __cplusplus | ||
| 16 | extern "C" { | ||
| 17 | #endif | ||
| 18 | |||
| 19 | _Noreturn void __assert_fail (const char *, const char *, int, const char *); | ||
| 20 | |||
| 21 | #ifdef __cplusplus | ||
| 22 | } | ||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/byteswap.h created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #ifndef _BYTESWAP_H | ||
| 2 | #define _BYTESWAP_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | |||
| 7 | static __inline uint16_t __bswap_16(uint16_t __x) | ||
| 8 | { | ||
| 9 | 	return __x<<8 | __x>>8; | ||
| 10 | } | ||
| 11 | |||
| 12 | static __inline uint32_t __bswap_32(uint32_t __x) | ||
| 13 | { | ||
| 14 | 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; | ||
| 15 | } | ||
| 16 | |||
| 17 | static __inline uint64_t __bswap_64(uint64_t __x) | ||
| 18 | { | ||
| 19 | 	return __bswap_32(__x)+0ULL<<32 | __bswap_32(__x>>32); | ||
| 20 | } | ||
| 21 | |||
| 22 | #define bswap_16(x) __bswap_16(x) | ||
| 23 | #define bswap_32(x) __bswap_32(x) | ||
| 24 | #define bswap_64(x) __bswap_64(x) | ||
| 25 | |||
| 26 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/complex.h created+143| ... | @@ -0,0 +1,143 @@ | ||
| 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/cpio.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef _CPIO_H | ||
| 2 | #define _CPIO_H | ||
| 3 | |||
| 4 | #define MAGIC "070707" | ||
| 5 | |||
| 6 | #define C_IRUSR 000400 | ||
| 7 | #define C_IWUSR 000200 | ||
| 8 | #define C_IXUSR 000100 | ||
| 9 | #define C_IRGRP 000040 | ||
| 10 | #define C_IWGRP 000020 | ||
| 11 | #define C_IXGRP 000010 | ||
| 12 | #define C_IROTH 000004 | ||
| 13 | #define C_IWOTH 000002 | ||
| 14 | #define C_IXOTH 000001 | ||
| 15 | |||
| 16 | #define C_ISUID 004000 | ||
| 17 | #define C_ISGID 002000 | ||
| 18 | #define C_ISVTX 001000 | ||
| 19 | |||
| 20 | #define C_ISBLK 060000 | ||
| 21 | #define C_ISCHR 020000 | ||
| 22 | #define C_ISDIR 040000 | ||
| 23 | #define C_ISFIFO 010000 | ||
| 24 | #define C_ISSOCK 0140000 | ||
| 25 | #define C_ISLNK 0120000 | ||
| 26 | #define C_ISCTG 0110000 | ||
| 27 | #define C_ISREG 0100000 | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/crypt.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _CRYPT_H | ||
| 2 | #define _CRYPT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | struct crypt_data { | ||
| 9 | 	int initialized; | ||
| 10 | 	char __buf[256]; | ||
| 11 | }; | ||
| 12 | |||
| 13 | char *crypt(const char *, const char *); | ||
| 14 | char *crypt_r(const char *, const char *, struct crypt_data *); | ||
| 15 | |||
| 16 | #ifdef __cplusplus | ||
| 17 | } | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/ctype.h created+75| ... | @@ -0,0 +1,75 @@ | ||
| 1 | #ifndef	_CTYPE_H | ||
| 2 | #define	_CTYPE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | int isalnum(int); | ||
| 11 | int isalpha(int); | ||
| 12 | int isblank(int); | ||
| 13 | int iscntrl(int); | ||
| 14 | int isdigit(int); | ||
| 15 | int isgraph(int); | ||
| 16 | int islower(int); | ||
| 17 | int isprint(int); | ||
| 18 | int ispunct(int); | ||
| 19 | int isspace(int); | ||
| 20 | int isupper(int); | ||
| 21 | int isxdigit(int); | ||
| 22 | int tolower(int); | ||
| 23 | int toupper(int); | ||
| 24 | |||
| 25 | #ifndef __cplusplus | ||
| 26 | static __inline int __isspace(int _c) | ||
| 27 | { | ||
| 28 | 	return _c == ' ' || (unsigned)_c-'\t' < 5; | ||
| 29 | } | ||
| 30 | |||
| 31 | #define isalpha(a) (0 ? isalpha(a) : (((unsigned)(a)|32)-'a') < 26) | ||
| 32 | #define isdigit(a) (0 ? isdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 33 | #define islower(a) (0 ? islower(a) : ((unsigned)(a)-'a') < 26) | ||
| 34 | #define isupper(a) (0 ? isupper(a) : ((unsigned)(a)-'A') < 26) | ||
| 35 | #define isprint(a) (0 ? isprint(a) : ((unsigned)(a)-0x20) < 0x5f) | ||
| 36 | #define isgraph(a) (0 ? isgraph(a) : ((unsigned)(a)-0x21) < 0x5e) | ||
| 37 | #define isspace(a) __isspace(a) | ||
| 38 | #endif | ||
| 39 | |||
| 40 | |||
| 41 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 42 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 43 | || defined(_BSD_SOURCE) | ||
| 44 | |||
| 45 | #define __NEED_locale_t | ||
| 46 | #include <bits/alltypes.h> | ||
| 47 | |||
| 48 | int isalnum_l(int, locale_t); | ||
| 49 | int isalpha_l(int, locale_t); | ||
| 50 | int isblank_l(int, locale_t); | ||
| 51 | int iscntrl_l(int, locale_t); | ||
| 52 | int isdigit_l(int, locale_t); | ||
| 53 | int isgraph_l(int, locale_t); | ||
| 54 | int islower_l(int, locale_t); | ||
| 55 | int isprint_l(int, locale_t); | ||
| 56 | int ispunct_l(int, locale_t); | ||
| 57 | int isspace_l(int, locale_t); | ||
| 58 | int isupper_l(int, locale_t); | ||
| 59 | int isxdigit_l(int, locale_t); | ||
| 60 | int tolower_l(int, locale_t); | ||
| 61 | int toupper_l(int, locale_t); | ||
| 62 | |||
| 63 | int isascii(int); | ||
| 64 | int toascii(int); | ||
| 65 | #define _tolower(a) ((a)|0x20) | ||
| 66 | #define _toupper(a) ((a)&0x5f) | ||
| 67 | #define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128) | ||
| 68 | |||
| 69 | #endif | ||
| 70 | |||
| 71 | #ifdef __cplusplus | ||
| 72 | } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/dirent.h created+89| ... | @@ -0,0 +1,89 @@ | ||
| 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 created+46| ... | @@ -0,0 +1,46 @@ | ||
| 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 | #define RTLD_LOCAL 0 | ||
| 16 | |||
| 17 | #define RTLD_NEXT ((void *)-1) | ||
| 18 | #define RTLD_DEFAULT ((void *)0) | ||
| 19 | |||
| 20 | #define RTLD_DI_LINKMAP 2 | ||
| 21 | |||
| 22 | int dlclose(void *); | ||
| 23 | char *dlerror(void); | ||
| 24 | void *dlopen(const char *, int); | ||
| 25 | void *dlsym(void *__restrict, const char *__restrict); | ||
| 26 | |||
| 27 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 28 | typedef struct { | ||
| 29 | 	const char *dli_fname; | ||
| 30 | 	void *dli_fbase; | ||
| 31 | 	const char *dli_sname; | ||
| 32 | 	void *dli_saddr; | ||
| 33 | } Dl_info; | ||
| 34 | int dladdr(const void *, Dl_info *); | ||
| 35 | int dlinfo(void *, int, void *); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #if _REDIR_TIME64 | ||
| 39 | __REDIR(dlsym, __dlsym_time64); | ||
| 40 | #endif | ||
| 41 | |||
| 42 | #ifdef __cplusplus | ||
| 43 | } | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/elf.h created+3294| ... | @@ -0,0 +1,3294 @@ | ||
| 1 | #ifndef _ELF_H | ||
| 2 | #define _ELF_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | |||
| 10 | typedef uint16_t Elf32_Half; | ||
| 11 | typedef uint16_t Elf64_Half; | ||
| 12 | |||
| 13 | typedef uint32_t Elf32_Word; | ||
| 14 | typedef	int32_t Elf32_Sword; | ||
| 15 | typedef uint32_t Elf64_Word; | ||
| 16 | typedef	int32_t Elf64_Sword; | ||
| 17 | |||
| 18 | typedef uint64_t Elf32_Xword; | ||
| 19 | typedef	int64_t Elf32_Sxword; | ||
| 20 | typedef uint64_t Elf64_Xword; | ||
| 21 | typedef	int64_t Elf64_Sxword; | ||
| 22 | |||
| 23 | typedef uint32_t Elf32_Addr; | ||
| 24 | typedef uint64_t Elf64_Addr; | ||
| 25 | |||
| 26 | typedef uint32_t Elf32_Off; | ||
| 27 | typedef uint64_t Elf64_Off; | ||
| 28 | |||
| 29 | typedef uint16_t Elf32_Section; | ||
| 30 | typedef uint16_t Elf64_Section; | ||
| 31 | |||
| 32 | typedef Elf32_Half Elf32_Versym; | ||
| 33 | typedef Elf64_Half Elf64_Versym; | ||
| 34 | |||
| 35 | #define EI_NIDENT (16) | ||
| 36 | |||
| 37 | typedef struct { | ||
| 38 | unsigned char	e_ident[EI_NIDENT]; | ||
| 39 | Elf32_Half	e_type; | ||
| 40 | Elf32_Half	e_machine; | ||
| 41 | Elf32_Word	e_version; | ||
| 42 | Elf32_Addr	e_entry; | ||
| 43 | Elf32_Off	e_phoff; | ||
| 44 | Elf32_Off	e_shoff; | ||
| 45 | Elf32_Word	e_flags; | ||
| 46 | Elf32_Half	e_ehsize; | ||
| 47 | Elf32_Half	e_phentsize; | ||
| 48 | Elf32_Half	e_phnum; | ||
| 49 | Elf32_Half	e_shentsize; | ||
| 50 | Elf32_Half	e_shnum; | ||
| 51 | Elf32_Half	e_shstrndx; | ||
| 52 | } Elf32_Ehdr; | ||
| 53 | |||
| 54 | typedef struct { | ||
| 55 | unsigned char	e_ident[EI_NIDENT]; | ||
| 56 | Elf64_Half	e_type; | ||
| 57 | Elf64_Half	e_machine; | ||
| 58 | Elf64_Word	e_version; | ||
| 59 | Elf64_Addr	e_entry; | ||
| 60 | Elf64_Off	e_phoff; | ||
| 61 | Elf64_Off	e_shoff; | ||
| 62 | Elf64_Word	e_flags; | ||
| 63 | Elf64_Half	e_ehsize; | ||
| 64 | Elf64_Half	e_phentsize; | ||
| 65 | Elf64_Half	e_phnum; | ||
| 66 | Elf64_Half	e_shentsize; | ||
| 67 | Elf64_Half	e_shnum; | ||
| 68 | Elf64_Half	e_shstrndx; | ||
| 69 | } Elf64_Ehdr; | ||
| 70 | |||
| 71 | #define EI_MAG0		0 | ||
| 72 | #define ELFMAG0		0x7f | ||
| 73 | |||
| 74 | #define EI_MAG1		1 | ||
| 75 | #define ELFMAG1		'E' | ||
| 76 | |||
| 77 | #define EI_MAG2		2 | ||
| 78 | #define ELFMAG2		'L' | ||
| 79 | |||
| 80 | #define EI_MAG3		3 | ||
| 81 | #define ELFMAG3		'F' | ||
| 82 | |||
| 83 | |||
| 84 | #define	ELFMAG		"\177ELF" | ||
| 85 | #define	SELFMAG		4 | ||
| 86 | |||
| 87 | #define EI_CLASS	4 | ||
| 88 | #define ELFCLASSNONE	0 | ||
| 89 | #define ELFCLASS32	1 | ||
| 90 | #define ELFCLASS64	2 | ||
| 91 | #define ELFCLASSNUM	3 | ||
| 92 | |||
| 93 | #define EI_DATA		5 | ||
| 94 | #define ELFDATANONE	0 | ||
| 95 | #define ELFDATA2LSB	1 | ||
| 96 | #define ELFDATA2MSB	2 | ||
| 97 | #define ELFDATANUM	3 | ||
| 98 | |||
| 99 | #define EI_VERSION	6 | ||
| 100 | |||
| 101 | |||
| 102 | #define EI_OSABI	7 | ||
| 103 | #define ELFOSABI_NONE		0 | ||
| 104 | #define ELFOSABI_SYSV		0 | ||
| 105 | #define ELFOSABI_HPUX		1 | ||
| 106 | #define ELFOSABI_NETBSD		2 | ||
| 107 | #define ELFOSABI_LINUX		3 | ||
| 108 | #define ELFOSABI_GNU		3 | ||
| 109 | #define ELFOSABI_SOLARIS	6 | ||
| 110 | #define ELFOSABI_AIX		7 | ||
| 111 | #define ELFOSABI_IRIX		8 | ||
| 112 | #define ELFOSABI_FREEBSD	9 | ||
| 113 | #define ELFOSABI_TRU64		10 | ||
| 114 | #define ELFOSABI_MODESTO	11 | ||
| 115 | #define ELFOSABI_OPENBSD	12 | ||
| 116 | #define ELFOSABI_ARM		97 | ||
| 117 | #define ELFOSABI_STANDALONE	255 | ||
| 118 | |||
| 119 | #define EI_ABIVERSION	8 | ||
| 120 | |||
| 121 | #define EI_PAD		9 | ||
| 122 | |||
| 123 | |||
| 124 | |||
| 125 | #define ET_NONE		0 | ||
| 126 | #define ET_REL		1 | ||
| 127 | #define ET_EXEC		2 | ||
| 128 | #define ET_DYN		3 | ||
| 129 | #define ET_CORE		4 | ||
| 130 | #define	ET_NUM		5 | ||
| 131 | #define ET_LOOS		0xfe00 | ||
| 132 | #define ET_HIOS		0xfeff | ||
| 133 | #define ET_LOPROC	0xff00 | ||
| 134 | #define ET_HIPROC	0xffff | ||
| 135 | |||
| 136 | |||
| 137 | |||
| 138 | #define EM_NONE		 0 | ||
| 139 | #define EM_M32		 1 | ||
| 140 | #define EM_SPARC	 2 | ||
| 141 | #define EM_386		 3 | ||
| 142 | #define EM_68K		 4 | ||
| 143 | #define EM_88K		 5 | ||
| 144 | #define EM_860		 7 | ||
| 145 | #define EM_MIPS		 8 | ||
| 146 | #define EM_S370		 9 | ||
| 147 | #define EM_MIPS_RS3_LE	10 | ||
| 148 | |||
| 149 | #define EM_PARISC	15 | ||
| 150 | #define EM_VPP500	17 | ||
| 151 | #define EM_SPARC32PLUS	18 | ||
| 152 | #define EM_960		19 | ||
| 153 | #define EM_PPC		20 | ||
| 154 | #define EM_PPC64	21 | ||
| 155 | #define EM_S390		22 | ||
| 156 | |||
| 157 | #define EM_V800		36 | ||
| 158 | #define EM_FR20		37 | ||
| 159 | #define EM_RH32		38 | ||
| 160 | #define EM_RCE		39 | ||
| 161 | #define EM_ARM		40 | ||
| 162 | #define EM_FAKE_ALPHA	41 | ||
| 163 | #define EM_SH		42 | ||
| 164 | #define EM_SPARCV9	43 | ||
| 165 | #define EM_TRICORE	44 | ||
| 166 | #define EM_ARC		45 | ||
| 167 | #define EM_H8_300	46 | ||
| 168 | #define EM_H8_300H	47 | ||
| 169 | #define EM_H8S		48 | ||
| 170 | #define EM_H8_500	49 | ||
| 171 | #define EM_IA_64	50 | ||
| 172 | #define EM_MIPS_X	51 | ||
| 173 | #define EM_COLDFIRE	52 | ||
| 174 | #define EM_68HC12	53 | ||
| 175 | #define EM_MMA		54 | ||
| 176 | #define EM_PCP		55 | ||
| 177 | #define EM_NCPU		56 | ||
| 178 | #define EM_NDR1		57 | ||
| 179 | #define EM_STARCORE	58 | ||
| 180 | #define EM_ME16		59 | ||
| 181 | #define EM_ST100	60 | ||
| 182 | #define EM_TINYJ	61 | ||
| 183 | #define EM_X86_64	62 | ||
| 184 | #define EM_PDSP		63 | ||
| 185 | |||
| 186 | #define EM_FX66		66 | ||
| 187 | #define EM_ST9PLUS	67 | ||
| 188 | #define EM_ST7		68 | ||
| 189 | #define EM_68HC16	69 | ||
| 190 | #define EM_68HC11	70 | ||
| 191 | #define EM_68HC08	71 | ||
| 192 | #define EM_68HC05	72 | ||
| 193 | #define EM_SVX		73 | ||
| 194 | #define EM_ST19		74 | ||
| 195 | #define EM_VAX		75 | ||
| 196 | #define EM_CRIS		76 | ||
| 197 | #define EM_JAVELIN	77 | ||
| 198 | #define EM_FIREPATH	78 | ||
| 199 | #define EM_ZSP		79 | ||
| 200 | #define EM_MMIX		80 | ||
| 201 | #define EM_HUANY	81 | ||
| 202 | #define EM_PRISM	82 | ||
| 203 | #define EM_AVR		83 | ||
| 204 | #define EM_FR30		84 | ||
| 205 | #define EM_D10V		85 | ||
| 206 | #define EM_D30V		86 | ||
| 207 | #define EM_V850		87 | ||
| 208 | #define EM_M32R		88 | ||
| 209 | #define EM_MN10300	89 | ||
| 210 | #define EM_MN10200	90 | ||
| 211 | #define EM_PJ		91 | ||
| 212 | #define EM_OR1K		92 | ||
| 213 | #define EM_OPENRISC	92 | ||
| 214 | #define EM_ARC_A5	93 | ||
| 215 | #define EM_ARC_COMPACT	93 | ||
| 216 | #define EM_XTENSA	94 | ||
| 217 | #define EM_VIDEOCORE	95 | ||
| 218 | #define EM_TMM_GPP	96 | ||
| 219 | #define EM_NS32K	97 | ||
| 220 | #define EM_TPC		98 | ||
| 221 | #define EM_SNP1K	99 | ||
| 222 | #define EM_ST200	100 | ||
| 223 | #define EM_IP2K		101 | ||
| 224 | #define EM_MAX		102 | ||
| 225 | #define EM_CR		103 | ||
| 226 | #define EM_F2MC16	104 | ||
| 227 | #define EM_MSP430	105 | ||
| 228 | #define EM_BLACKFIN	106 | ||
| 229 | #define EM_SE_C33	107 | ||
| 230 | #define EM_SEP		108 | ||
| 231 | #define EM_ARCA		109 | ||
| 232 | #define EM_UNICORE	110 | ||
| 233 | #define EM_EXCESS	111 | ||
| 234 | #define EM_DXP		112 | ||
| 235 | #define EM_ALTERA_NIOS2 113 | ||
| 236 | #define EM_CRX		114 | ||
| 237 | #define EM_XGATE	115 | ||
| 238 | #define EM_C166		116 | ||
| 239 | #define EM_M16C		117 | ||
| 240 | #define EM_DSPIC30F	118 | ||
| 241 | #define EM_CE		119 | ||
| 242 | #define EM_M32C		120 | ||
| 243 | #define EM_TSK3000	131 | ||
| 244 | #define EM_RS08		132 | ||
| 245 | #define EM_SHARC	133 | ||
| 246 | #define EM_ECOG2	134 | ||
| 247 | #define EM_SCORE7	135 | ||
| 248 | #define EM_DSP24	136 | ||
| 249 | #define EM_VIDEOCORE3	137 | ||
| 250 | #define EM_LATTICEMICO32 138 | ||
| 251 | #define EM_SE_C17	139 | ||
| 252 | #define EM_TI_C6000	140 | ||
| 253 | #define EM_TI_C2000	141 | ||
| 254 | #define EM_TI_C5500	142 | ||
| 255 | #define EM_TI_ARP32	143 | ||
| 256 | #define EM_TI_PRU	144 | ||
| 257 | #define EM_MMDSP_PLUS	160 | ||
| 258 | #define EM_CYPRESS_M8C	161 | ||
| 259 | #define EM_R32C		162 | ||
| 260 | #define EM_TRIMEDIA	163 | ||
| 261 | #define EM_QDSP6	164 | ||
| 262 | #define EM_8051		165 | ||
| 263 | #define EM_STXP7X	166 | ||
| 264 | #define EM_NDS32	167 | ||
| 265 | #define EM_ECOG1X	168 | ||
| 266 | #define EM_MAXQ30	169 | ||
| 267 | #define EM_XIMO16	170 | ||
| 268 | #define EM_MANIK	171 | ||
| 269 | #define EM_CRAYNV2	172 | ||
| 270 | #define EM_RX		173 | ||
| 271 | #define EM_METAG	174 | ||
| 272 | #define EM_MCST_ELBRUS	175 | ||
| 273 | #define EM_ECOG16	176 | ||
| 274 | #define EM_CR16		177 | ||
| 275 | #define EM_ETPU		178 | ||
| 276 | #define EM_SLE9X	179 | ||
| 277 | #define EM_L10M		180 | ||
| 278 | #define EM_K10M		181 | ||
| 279 | #define EM_AARCH64	183 | ||
| 280 | #define EM_AVR32	185 | ||
| 281 | #define EM_STM8		186 | ||
| 282 | #define EM_TILE64	187 | ||
| 283 | #define EM_TILEPRO	188 | ||
| 284 | #define EM_MICROBLAZE	189 | ||
| 285 | #define EM_CUDA		190 | ||
| 286 | #define EM_TILEGX	191 | ||
| 287 | #define EM_CLOUDSHIELD	192 | ||
| 288 | #define EM_COREA_1ST	193 | ||
| 289 | #define EM_COREA_2ND	194 | ||
| 290 | #define EM_ARC_COMPACT2	195 | ||
| 291 | #define EM_OPEN8	196 | ||
| 292 | #define EM_RL78		197 | ||
| 293 | #define EM_VIDEOCORE5	198 | ||
| 294 | #define EM_78KOR	199 | ||
| 295 | #define EM_56800EX	200 | ||
| 296 | #define EM_BA1		201 | ||
| 297 | #define EM_BA2		202 | ||
| 298 | #define EM_XCORE	203 | ||
| 299 | #define EM_MCHP_PIC	204 | ||
| 300 | #define EM_KM32		210 | ||
| 301 | #define EM_KMX32	211 | ||
| 302 | #define EM_EMX16	212 | ||
| 303 | #define EM_EMX8		213 | ||
| 304 | #define EM_KVARC	214 | ||
| 305 | #define EM_CDP		215 | ||
| 306 | #define EM_COGE		216 | ||
| 307 | #define EM_COOL		217 | ||
| 308 | #define EM_NORC		218 | ||
| 309 | #define EM_CSR_KALIMBA	219 | ||
| 310 | #define EM_Z80		220 | ||
| 311 | #define EM_VISIUM	221 | ||
| 312 | #define EM_FT32		222 | ||
| 313 | #define EM_MOXIE	223 | ||
| 314 | #define EM_AMDGPU	224 | ||
| 315 | #define EM_RISCV	243 | ||
| 316 | #define EM_BPF		247 | ||
| 317 | #define EM_CSKY		252 | ||
| 318 | #define EM_NUM		253 | ||
| 319 | |||
| 320 | #define EM_ALPHA	0x9026 | ||
| 321 | |||
| 322 | #define EV_NONE		0 | ||
| 323 | #define EV_CURRENT	1 | ||
| 324 | #define EV_NUM		2 | ||
| 325 | |||
| 326 | typedef struct { | ||
| 327 | Elf32_Word	sh_name; | ||
| 328 | Elf32_Word	sh_type; | ||
| 329 | Elf32_Word	sh_flags; | ||
| 330 | Elf32_Addr	sh_addr; | ||
| 331 | Elf32_Off	sh_offset; | ||
| 332 | Elf32_Word	sh_size; | ||
| 333 | Elf32_Word	sh_link; | ||
| 334 | Elf32_Word	sh_info; | ||
| 335 | Elf32_Word	sh_addralign; | ||
| 336 | Elf32_Word	sh_entsize; | ||
| 337 | } Elf32_Shdr; | ||
| 338 | |||
| 339 | typedef struct { | ||
| 340 | Elf64_Word	sh_name; | ||
| 341 | Elf64_Word	sh_type; | ||
| 342 | Elf64_Xword	sh_flags; | ||
| 343 | Elf64_Addr	sh_addr; | ||
| 344 | Elf64_Off	sh_offset; | ||
| 345 | Elf64_Xword	sh_size; | ||
| 346 | Elf64_Word	sh_link; | ||
| 347 | Elf64_Word	sh_info; | ||
| 348 | Elf64_Xword	sh_addralign; | ||
| 349 | Elf64_Xword	sh_entsize; | ||
| 350 | } Elf64_Shdr; | ||
| 351 | |||
| 352 | |||
| 353 | |||
| 354 | #define SHN_UNDEF	0 | ||
| 355 | #define SHN_LORESERVE	0xff00 | ||
| 356 | #define SHN_LOPROC	0xff00 | ||
| 357 | #define SHN_BEFORE	0xff00 | ||
| 358 | |||
| 359 | #define SHN_AFTER	0xff01 | ||
| 360 | |||
| 361 | #define SHN_HIPROC	0xff1f | ||
| 362 | #define SHN_LOOS	0xff20 | ||
| 363 | #define SHN_HIOS	0xff3f | ||
| 364 | #define SHN_ABS		0xfff1 | ||
| 365 | #define SHN_COMMON	0xfff2 | ||
| 366 | #define SHN_XINDEX	0xffff | ||
| 367 | #define SHN_HIRESERVE	0xffff | ||
| 368 | |||
| 369 | |||
| 370 | |||
| 371 | #define SHT_NULL	 0 | ||
| 372 | #define SHT_PROGBITS	 1 | ||
| 373 | #define SHT_SYMTAB	 2 | ||
| 374 | #define SHT_STRTAB	 3 | ||
| 375 | #define SHT_RELA	 4 | ||
| 376 | #define SHT_HASH	 5 | ||
| 377 | #define SHT_DYNAMIC	 6 | ||
| 378 | #define SHT_NOTE	 7 | ||
| 379 | #define SHT_NOBITS	 8 | ||
| 380 | #define SHT_REL		 9 | ||
| 381 | #define SHT_SHLIB	 10 | ||
| 382 | #define SHT_DYNSYM	 11 | ||
| 383 | #define SHT_INIT_ARRAY	 14 | ||
| 384 | #define SHT_FINI_ARRAY	 15 | ||
| 385 | #define SHT_PREINIT_ARRAY 16 | ||
| 386 | #define SHT_GROUP	 17 | ||
| 387 | #define SHT_SYMTAB_SHNDX 18 | ||
| 388 | #define	SHT_NUM		 19 | ||
| 389 | #define SHT_LOOS	 0x60000000 | ||
| 390 | #define SHT_GNU_ATTRIBUTES 0x6ffffff5 | ||
| 391 | #define SHT_GNU_HASH	 0x6ffffff6 | ||
| 392 | #define SHT_GNU_LIBLIST	 0x6ffffff7 | ||
| 393 | #define SHT_CHECKSUM	 0x6ffffff8 | ||
| 394 | #define SHT_LOSUNW	 0x6ffffffa | ||
| 395 | #define SHT_SUNW_move	 0x6ffffffa | ||
| 396 | #define SHT_SUNW_COMDAT 0x6ffffffb | ||
| 397 | #define SHT_SUNW_syminfo 0x6ffffffc | ||
| 398 | #define SHT_GNU_verdef	 0x6ffffffd | ||
| 399 | #define SHT_GNU_verneed	 0x6ffffffe | ||
| 400 | #define SHT_GNU_versym	 0x6fffffff | ||
| 401 | #define SHT_HISUNW	 0x6fffffff | ||
| 402 | #define SHT_HIOS	 0x6fffffff | ||
| 403 | #define SHT_LOPROC	 0x70000000 | ||
| 404 | #define SHT_HIPROC	 0x7fffffff | ||
| 405 | #define SHT_LOUSER	 0x80000000 | ||
| 406 | #define SHT_HIUSER	 0x8fffffff | ||
| 407 | |||
| 408 | #define SHF_WRITE	 (1 << 0) | ||
| 409 | #define SHF_ALLOC	 (1 << 1) | ||
| 410 | #define SHF_EXECINSTR	 (1 << 2) | ||
| 411 | #define SHF_MERGE	 (1 << 4) | ||
| 412 | #define SHF_STRINGS	 (1 << 5) | ||
| 413 | #define SHF_INFO_LINK	 (1 << 6) | ||
| 414 | #define SHF_LINK_ORDER	 (1 << 7) | ||
| 415 | #define SHF_OS_NONCONFORMING (1 << 8) | ||
| 416 | |||
| 417 | #define SHF_GROUP	 (1 << 9) | ||
| 418 | #define SHF_TLS		 (1 << 10) | ||
| 419 | #define SHF_COMPRESSED	 (1 << 11) | ||
| 420 | #define SHF_MASKOS	 0x0ff00000 | ||
| 421 | #define SHF_MASKPROC	 0xf0000000 | ||
| 422 | #define SHF_ORDERED	 (1 << 30) | ||
| 423 | #define SHF_EXCLUDE	 (1U << 31) | ||
| 424 | |||
| 425 | typedef struct { | ||
| 426 | Elf32_Word	ch_type; | ||
| 427 | Elf32_Word	ch_size; | ||
| 428 | Elf32_Word	ch_addralign; | ||
| 429 | } Elf32_Chdr; | ||
| 430 | |||
| 431 | typedef struct { | ||
| 432 | Elf64_Word	ch_type; | ||
| 433 | Elf64_Word	ch_reserved; | ||
| 434 | Elf64_Xword	ch_size; | ||
| 435 | Elf64_Xword	ch_addralign; | ||
| 436 | } Elf64_Chdr; | ||
| 437 | |||
| 438 | #define ELFCOMPRESS_ZLIB	1 | ||
| 439 | #define ELFCOMPRESS_LOOS	0x60000000 | ||
| 440 | #define ELFCOMPRESS_HIOS	0x6fffffff | ||
| 441 | #define ELFCOMPRESS_LOPROC	0x70000000 | ||
| 442 | #define ELFCOMPRESS_HIPROC	0x7fffffff | ||
| 443 | |||
| 444 | |||
| 445 | #define GRP_COMDAT	0x1 | ||
| 446 | |||
| 447 | typedef struct { | ||
| 448 | Elf32_Word	st_name; | ||
| 449 | Elf32_Addr	st_value; | ||
| 450 | Elf32_Word	st_size; | ||
| 451 | unsigned char	st_info; | ||
| 452 | unsigned char	st_other; | ||
| 453 | Elf32_Section	st_shndx; | ||
| 454 | } Elf32_Sym; | ||
| 455 | |||
| 456 | typedef struct { | ||
| 457 | Elf64_Word	st_name; | ||
| 458 | unsigned char	st_info; | ||
| 459 | unsigned char st_other; | ||
| 460 | Elf64_Section	st_shndx; | ||
| 461 | Elf64_Addr	st_value; | ||
| 462 | Elf64_Xword	st_size; | ||
| 463 | } Elf64_Sym; | ||
| 464 | |||
| 465 | typedef struct { | ||
| 466 | Elf32_Half si_boundto; | ||
| 467 | Elf32_Half si_flags; | ||
| 468 | } Elf32_Syminfo; | ||
| 469 | |||
| 470 | typedef struct { | ||
| 471 | Elf64_Half si_boundto; | ||
| 472 | Elf64_Half si_flags; | ||
| 473 | } Elf64_Syminfo; | ||
| 474 | |||
| 475 | #define SYMINFO_BT_SELF		0xffff | ||
| 476 | #define SYMINFO_BT_PARENT	0xfffe | ||
| 477 | #define SYMINFO_BT_LOWRESERVE	0xff00 | ||
| 478 | |||
| 479 | #define SYMINFO_FLG_DIRECT	0x0001 | ||
| 480 | #define SYMINFO_FLG_PASSTHRU	0x0002 | ||
| 481 | #define SYMINFO_FLG_COPY	0x0004 | ||
| 482 | #define SYMINFO_FLG_LAZYLOAD	0x0008 | ||
| 483 | |||
| 484 | #define SYMINFO_NONE		0 | ||
| 485 | #define SYMINFO_CURRENT		1 | ||
| 486 | #define SYMINFO_NUM		2 | ||
| 487 | |||
| 488 | #define ELF32_ST_BIND(val)		(((unsigned char) (val)) >> 4) | ||
| 489 | #define ELF32_ST_TYPE(val)		((val) & 0xf) | ||
| 490 | #define ELF32_ST_INFO(bind, type)	(((bind) << 4) + ((type) & 0xf)) | ||
| 491 | |||
| 492 | #define ELF64_ST_BIND(val)		ELF32_ST_BIND (val) | ||
| 493 | #define ELF64_ST_TYPE(val)		ELF32_ST_TYPE (val) | ||
| 494 | #define ELF64_ST_INFO(bind, type)	ELF32_ST_INFO ((bind), (type)) | ||
| 495 | |||
| 496 | #define STB_LOCAL	0 | ||
| 497 | #define STB_GLOBAL	1 | ||
| 498 | #define STB_WEAK	2 | ||
| 499 | #define	STB_NUM		3 | ||
| 500 | #define STB_LOOS	10 | ||
| 501 | #define STB_GNU_UNIQUE	10 | ||
| 502 | #define STB_HIOS	12 | ||
| 503 | #define STB_LOPROC	13 | ||
| 504 | #define STB_HIPROC	15 | ||
| 505 | |||
| 506 | #define STT_NOTYPE	0 | ||
| 507 | #define STT_OBJECT	1 | ||
| 508 | #define STT_FUNC	2 | ||
| 509 | #define STT_SECTION	3 | ||
| 510 | #define STT_FILE	4 | ||
| 511 | #define STT_COMMON	5 | ||
| 512 | #define STT_TLS		6 | ||
| 513 | #define	STT_NUM		7 | ||
| 514 | #define STT_LOOS	10 | ||
| 515 | #define STT_GNU_IFUNC	10 | ||
| 516 | #define STT_HIOS	12 | ||
| 517 | #define STT_LOPROC	13 | ||
| 518 | #define STT_HIPROC	15 | ||
| 519 | |||
| 520 | #define STN_UNDEF	0 | ||
| 521 | |||
| 522 | #define ELF32_ST_VISIBILITY(o)	((o) & 0x03) | ||
| 523 | #define ELF64_ST_VISIBILITY(o)	ELF32_ST_VISIBILITY (o) | ||
| 524 | |||
| 525 | #define STV_DEFAULT	0 | ||
| 526 | #define STV_INTERNAL	1 | ||
| 527 | #define STV_HIDDEN	2 | ||
| 528 | #define STV_PROTECTED	3 | ||
| 529 | |||
| 530 | |||
| 531 | |||
| 532 | |||
| 533 | typedef struct { | ||
| 534 | Elf32_Addr	r_offset; | ||
| 535 | Elf32_Word	r_info; | ||
| 536 | } Elf32_Rel; | ||
| 537 | |||
| 538 | typedef struct { | ||
| 539 | Elf64_Addr	r_offset; | ||
| 540 | Elf64_Xword	r_info; | ||
| 541 | } Elf64_Rel; | ||
| 542 | |||
| 543 | |||
| 544 | |||
| 545 | typedef struct { | ||
| 546 | Elf32_Addr	r_offset; | ||
| 547 | Elf32_Word	r_info; | ||
| 548 | Elf32_Sword	r_addend; | ||
| 549 | } Elf32_Rela; | ||
| 550 | |||
| 551 | typedef struct { | ||
| 552 | Elf64_Addr	r_offset; | ||
| 553 | Elf64_Xword	r_info; | ||
| 554 | Elf64_Sxword	r_addend; | ||
| 555 | } Elf64_Rela; | ||
| 556 | |||
| 557 | |||
| 558 | |||
| 559 | #define ELF32_R_SYM(val)		((val) >> 8) | ||
| 560 | #define ELF32_R_TYPE(val)		((val) & 0xff) | ||
| 561 | #define ELF32_R_INFO(sym, type)		(((sym) << 8) + ((type) & 0xff)) | ||
| 562 | |||
| 563 | #define ELF64_R_SYM(i)			((i) >> 32) | ||
| 564 | #define ELF64_R_TYPE(i)			((i) & 0xffffffff) | ||
| 565 | #define ELF64_R_INFO(sym,type)		((((Elf64_Xword) (sym)) << 32) + (type)) | ||
| 566 | |||
| 567 | |||
| 568 | |||
| 569 | typedef struct { | ||
| 570 | Elf32_Word	p_type; | ||
| 571 | Elf32_Off	p_offset; | ||
| 572 | Elf32_Addr	p_vaddr; | ||
| 573 | Elf32_Addr	p_paddr; | ||
| 574 | Elf32_Word	p_filesz; | ||
| 575 | Elf32_Word	p_memsz; | ||
| 576 | Elf32_Word	p_flags; | ||
| 577 | Elf32_Word	p_align; | ||
| 578 | } Elf32_Phdr; | ||
| 579 | |||
| 580 | typedef struct { | ||
| 581 | Elf64_Word	p_type; | ||
| 582 | Elf64_Word	p_flags; | ||
| 583 | Elf64_Off	p_offset; | ||
| 584 | Elf64_Addr	p_vaddr; | ||
| 585 | Elf64_Addr	p_paddr; | ||
| 586 | Elf64_Xword	p_filesz; | ||
| 587 | Elf64_Xword	p_memsz; | ||
| 588 | Elf64_Xword	p_align; | ||
| 589 | } Elf64_Phdr; | ||
| 590 | |||
| 591 | |||
| 592 | |||
| 593 | #define	PT_NULL		0 | ||
| 594 | #define PT_LOAD		1 | ||
| 595 | #define PT_DYNAMIC	2 | ||
| 596 | #define PT_INTERP	3 | ||
| 597 | #define PT_NOTE		4 | ||
| 598 | #define PT_SHLIB	5 | ||
| 599 | #define PT_PHDR		6 | ||
| 600 | #define PT_TLS		7 | ||
| 601 | #define	PT_NUM		8 | ||
| 602 | #define PT_LOOS		0x60000000 | ||
| 603 | #define PT_GNU_EH_FRAME	0x6474e550 | ||
| 604 | #define PT_GNU_STACK	0x6474e551 | ||
| 605 | #define PT_GNU_RELRO	0x6474e552 | ||
| 606 | #define PT_GNU_PROPERTY	0x6474e553 | ||
| 607 | #define PT_LOSUNW	0x6ffffffa | ||
| 608 | #define PT_SUNWBSS	0x6ffffffa | ||
| 609 | #define PT_SUNWSTACK	0x6ffffffb | ||
| 610 | #define PT_HISUNW	0x6fffffff | ||
| 611 | #define PT_HIOS		0x6fffffff | ||
| 612 | #define PT_LOPROC	0x70000000 | ||
| 613 | #define PT_HIPROC	0x7fffffff | ||
| 614 | |||
| 615 | |||
| 616 | #define PN_XNUM 0xffff | ||
| 617 | |||
| 618 | |||
| 619 | #define PF_X		(1 << 0) | ||
| 620 | #define PF_W		(1 << 1) | ||
| 621 | #define PF_R		(1 << 2) | ||
| 622 | #define PF_MASKOS	0x0ff00000 | ||
| 623 | #define PF_MASKPROC	0xf0000000 | ||
| 624 | |||
| 625 | |||
| 626 | |||
| 627 | #define NT_PRSTATUS	1 | ||
| 628 | #define NT_PRFPREG	2 | ||
| 629 | #define NT_FPREGSET	2 | ||
| 630 | #define NT_PRPSINFO	3 | ||
| 631 | #define NT_PRXREG	4 | ||
| 632 | #define NT_TASKSTRUCT	4 | ||
| 633 | #define NT_PLATFORM	5 | ||
| 634 | #define NT_AUXV		6 | ||
| 635 | #define NT_GWINDOWS	7 | ||
| 636 | #define NT_ASRS		8 | ||
| 637 | #define NT_PSTATUS	10 | ||
| 638 | #define NT_PSINFO	13 | ||
| 639 | #define NT_PRCRED	14 | ||
| 640 | #define NT_UTSNAME	15 | ||
| 641 | #define NT_LWPSTATUS	16 | ||
| 642 | #define NT_LWPSINFO	17 | ||
| 643 | #define NT_PRFPXREG	20 | ||
| 644 | #define NT_SIGINFO	0x53494749 | ||
| 645 | #define NT_FILE		0x46494c45 | ||
| 646 | #define NT_PRXFPREG	0x46e62b7f | ||
| 647 | #define NT_PPC_VMX	0x100 | ||
| 648 | #define NT_PPC_SPE	0x101 | ||
| 649 | #define NT_PPC_VSX	0x102 | ||
| 650 | #define NT_PPC_TAR	0x103 | ||
| 651 | #define NT_PPC_PPR	0x104 | ||
| 652 | #define NT_PPC_DSCR	0x105 | ||
| 653 | #define NT_PPC_EBB	0x106 | ||
| 654 | #define NT_PPC_PMU	0x107 | ||
| 655 | #define NT_PPC_TM_CGPR	0x108 | ||
| 656 | #define NT_PPC_TM_CFPR	0x109 | ||
| 657 | #define NT_PPC_TM_CVMX	0x10a | ||
| 658 | #define NT_PPC_TM_CVSX	0x10b | ||
| 659 | #define NT_PPC_TM_SPR	0x10c | ||
| 660 | #define NT_PPC_TM_CTAR	0x10d | ||
| 661 | #define NT_PPC_TM_CPPR	0x10e | ||
| 662 | #define NT_PPC_TM_CDSCR	0x10f | ||
| 663 | #define NT_386_TLS	0x200 | ||
| 664 | #define NT_386_IOPERM	0x201 | ||
| 665 | #define NT_X86_XSTATE	0x202 | ||
| 666 | #define NT_S390_HIGH_GPRS	0x300 | ||
| 667 | #define NT_S390_TIMER	0x301 | ||
| 668 | #define NT_S390_TODCMP	0x302 | ||
| 669 | #define NT_S390_TODPREG	0x303 | ||
| 670 | #define NT_S390_CTRS	0x304 | ||
| 671 | #define NT_S390_PREFIX	0x305 | ||
| 672 | #define NT_S390_LAST_BREAK	0x306 | ||
| 673 | #define NT_S390_SYSTEM_CALL	0x307 | ||
| 674 | #define NT_S390_TDB	0x308 | ||
| 675 | #define NT_S390_VXRS_LOW	0x309 | ||
| 676 | #define NT_S390_VXRS_HIGH	0x30a | ||
| 677 | #define NT_S390_GS_CB	0x30b | ||
| 678 | #define NT_S390_GS_BC	0x30c | ||
| 679 | #define NT_S390_RI_CB	0x30d | ||
| 680 | #define NT_ARM_VFP	0x400 | ||
| 681 | #define NT_ARM_TLS	0x401 | ||
| 682 | #define NT_ARM_HW_BREAK	0x402 | ||
| 683 | #define NT_ARM_HW_WATCH	0x403 | ||
| 684 | #define NT_ARM_SYSTEM_CALL	0x404 | ||
| 685 | #define NT_ARM_SVE	0x405 | ||
| 686 | #define NT_ARM_PAC_MASK	0x406 | ||
| 687 | #define NT_ARM_PACA_KEYS	0x407 | ||
| 688 | #define NT_ARM_PACG_KEYS	0x408 | ||
| 689 | #define NT_METAG_CBUF	0x500 | ||
| 690 | #define NT_METAG_RPIPE	0x501 | ||
| 691 | #define NT_METAG_TLS	0x502 | ||
| 692 | #define NT_ARC_V2	0x600 | ||
| 693 | #define NT_VMCOREDD	0x700 | ||
| 694 | #define NT_MIPS_DSP	0x800 | ||
| 695 | #define NT_MIPS_FP_MODE	0x801 | ||
| 696 | #define NT_MIPS_MSA	0x802 | ||
| 697 | #define NT_VERSION	1 | ||
| 698 | |||
| 699 | |||
| 700 | |||
| 701 | |||
| 702 | typedef struct { | ||
| 703 | Elf32_Sword d_tag; | ||
| 704 | union { | ||
| 705 | Elf32_Word d_val; | ||
| 706 | Elf32_Addr d_ptr; | ||
| 707 | } d_un; | ||
| 708 | } Elf32_Dyn; | ||
| 709 | |||
| 710 | typedef struct { | ||
| 711 | Elf64_Sxword d_tag; | ||
| 712 | union { | ||
| 713 | Elf64_Xword d_val; | ||
| 714 | Elf64_Addr d_ptr; | ||
| 715 | } d_un; | ||
| 716 | } Elf64_Dyn; | ||
| 717 | |||
| 718 | |||
| 719 | |||
| 720 | #define DT_NULL		0 | ||
| 721 | #define DT_NEEDED	1 | ||
| 722 | #define DT_PLTRELSZ	2 | ||
| 723 | #define DT_PLTGOT	3 | ||
| 724 | #define DT_HASH		4 | ||
| 725 | #define DT_STRTAB	5 | ||
| 726 | #define DT_SYMTAB	6 | ||
| 727 | #define DT_RELA		7 | ||
| 728 | #define DT_RELASZ	8 | ||
| 729 | #define DT_RELAENT	9 | ||
| 730 | #define DT_STRSZ	10 | ||
| 731 | #define DT_SYMENT	11 | ||
| 732 | #define DT_INIT		12 | ||
| 733 | #define DT_FINI		13 | ||
| 734 | #define DT_SONAME	14 | ||
| 735 | #define DT_RPATH	15 | ||
| 736 | #define DT_SYMBOLIC	16 | ||
| 737 | #define DT_REL		17 | ||
| 738 | #define DT_RELSZ	18 | ||
| 739 | #define DT_RELENT	19 | ||
| 740 | #define DT_PLTREL	20 | ||
| 741 | #define DT_DEBUG	21 | ||
| 742 | #define DT_TEXTREL	22 | ||
| 743 | #define DT_JMPREL	23 | ||
| 744 | #define	DT_BIND_NOW	24 | ||
| 745 | #define	DT_INIT_ARRAY	25 | ||
| 746 | #define	DT_FINI_ARRAY	26 | ||
| 747 | #define	DT_INIT_ARRAYSZ	27 | ||
| 748 | #define	DT_FINI_ARRAYSZ	28 | ||
| 749 | #define DT_RUNPATH	29 | ||
| 750 | #define DT_FLAGS	30 | ||
| 751 | #define DT_ENCODING	32 | ||
| 752 | #define DT_PREINIT_ARRAY 32 | ||
| 753 | #define DT_PREINIT_ARRAYSZ 33 | ||
| 754 | #define DT_SYMTAB_SHNDX	34 | ||
| 755 | #define	DT_NUM		35 | ||
| 756 | #define DT_LOOS		0x6000000d | ||
| 757 | #define DT_HIOS		0x6ffff000 | ||
| 758 | #define DT_LOPROC	0x70000000 | ||
| 759 | #define DT_HIPROC	0x7fffffff | ||
| 760 | #define	DT_PROCNUM	DT_MIPS_NUM | ||
| 761 | |||
| 762 | #define DT_VALRNGLO	0x6ffffd00 | ||
| 763 | #define DT_GNU_PRELINKED 0x6ffffdf5 | ||
| 764 | #define DT_GNU_CONFLICTSZ 0x6ffffdf6 | ||
| 765 | #define DT_GNU_LIBLISTSZ 0x6ffffdf7 | ||
| 766 | #define DT_CHECKSUM	0x6ffffdf8 | ||
| 767 | #define DT_PLTPADSZ	0x6ffffdf9 | ||
| 768 | #define DT_MOVEENT	0x6ffffdfa | ||
| 769 | #define DT_MOVESZ	0x6ffffdfb | ||
| 770 | #define DT_FEATURE_1	0x6ffffdfc | ||
| 771 | #define DT_POSFLAG_1	0x6ffffdfd | ||
| 772 | |||
| 773 | #define DT_SYMINSZ	0x6ffffdfe | ||
| 774 | #define DT_SYMINENT	0x6ffffdff | ||
| 775 | #define DT_VALRNGHI	0x6ffffdff | ||
| 776 | #define DT_VALTAGIDX(tag)	(DT_VALRNGHI - (tag)) | ||
| 777 | #define DT_VALNUM 12 | ||
| 778 | |||
| 779 | #define DT_ADDRRNGLO	0x6ffffe00 | ||
| 780 | #define DT_GNU_HASH	0x6ffffef5 | ||
| 781 | #define DT_TLSDESC_PLT	0x6ffffef6 | ||
| 782 | #define DT_TLSDESC_GOT	0x6ffffef7 | ||
| 783 | #define DT_GNU_CONFLICT	0x6ffffef8 | ||
| 784 | #define DT_GNU_LIBLIST	0x6ffffef9 | ||
| 785 | #define DT_CONFIG	0x6ffffefa | ||
| 786 | #define DT_DEPAUDIT	0x6ffffefb | ||
| 787 | #define DT_AUDIT	0x6ffffefc | ||
| 788 | #define	DT_PLTPAD	0x6ffffefd | ||
| 789 | #define	DT_MOVETAB	0x6ffffefe | ||
| 790 | #define DT_SYMINFO	0x6ffffeff | ||
| 791 | #define DT_ADDRRNGHI	0x6ffffeff | ||
| 792 | #define DT_ADDRTAGIDX(tag)	(DT_ADDRRNGHI - (tag)) | ||
| 793 | #define DT_ADDRNUM 11 | ||
| 794 | |||
| 795 | |||
| 796 | |||
| 797 | #define DT_VERSYM	0x6ffffff0 | ||
| 798 | |||
| 799 | #define DT_RELACOUNT	0x6ffffff9 | ||
| 800 | #define DT_RELCOUNT	0x6ffffffa | ||
| 801 | |||
| 802 | |||
| 803 | #define DT_FLAGS_1	0x6ffffffb | ||
| 804 | #define	DT_VERDEF	0x6ffffffc | ||
| 805 | |||
| 806 | #define	DT_VERDEFNUM	0x6ffffffd | ||
| 807 | #define	DT_VERNEED	0x6ffffffe | ||
| 808 | |||
| 809 | #define	DT_VERNEEDNUM	0x6fffffff | ||
| 810 | #define DT_VERSIONTAGIDX(tag)	(DT_VERNEEDNUM - (tag)) | ||
| 811 | #define DT_VERSIONTAGNUM 16 | ||
| 812 | |||
| 813 | |||
| 814 | |||
| 815 | #define DT_AUXILIARY 0x7ffffffd | ||
| 816 | #define DT_FILTER 0x7fffffff | ||
| 817 | #define DT_EXTRATAGIDX(tag)	((Elf32_Word)-((Elf32_Sword) (tag) <<1>>1)-1) | ||
| 818 | #define DT_EXTRANUM	3 | ||
| 819 | |||
| 820 | |||
| 821 | #define DF_ORIGIN	0x00000001 | ||
| 822 | #define DF_SYMBOLIC	0x00000002 | ||
| 823 | #define DF_TEXTREL	0x00000004 | ||
| 824 | #define DF_BIND_NOW	0x00000008 | ||
| 825 | #define DF_STATIC_TLS	0x00000010 | ||
| 826 | |||
| 827 | |||
| 828 | |||
| 829 | #define DF_1_NOW	0x00000001 | ||
| 830 | #define DF_1_GLOBAL	0x00000002 | ||
| 831 | #define DF_1_GROUP	0x00000004 | ||
| 832 | #define DF_1_NODELETE	0x00000008 | ||
| 833 | #define DF_1_LOADFLTR	0x00000010 | ||
| 834 | #define DF_1_INITFIRST	0x00000020 | ||
| 835 | #define DF_1_NOOPEN	0x00000040 | ||
| 836 | #define DF_1_ORIGIN	0x00000080 | ||
| 837 | #define DF_1_DIRECT	0x00000100 | ||
| 838 | #define DF_1_TRANS	0x00000200 | ||
| 839 | #define DF_1_INTERPOSE	0x00000400 | ||
| 840 | #define DF_1_NODEFLIB	0x00000800 | ||
| 841 | #define DF_1_NODUMP	0x00001000 | ||
| 842 | #define DF_1_CONFALT	0x00002000 | ||
| 843 | #define DF_1_ENDFILTEE	0x00004000 | ||
| 844 | #define	DF_1_DISPRELDNE	0x00008000 | ||
| 845 | #define	DF_1_DISPRELPND	0x00010000 | ||
| 846 | #define	DF_1_NODIRECT	0x00020000 | ||
| 847 | #define	DF_1_IGNMULDEF	0x00040000 | ||
| 848 | #define	DF_1_NOKSYMS	0x00080000 | ||
| 849 | #define	DF_1_NOHDR	0x00100000 | ||
| 850 | #define	DF_1_EDITED	0x00200000 | ||
| 851 | #define	DF_1_NORELOC	0x00400000 | ||
| 852 | #define	DF_1_SYMINTPOSE	0x00800000 | ||
| 853 | #define	DF_1_GLOBAUDIT	0x01000000 | ||
| 854 | #define	DF_1_SINGLETON	0x02000000 | ||
| 855 | #define	DF_1_STUB	0x04000000 | ||
| 856 | #define	DF_1_PIE	0x08000000 | ||
| 857 | |||
| 858 | #define DTF_1_PARINIT	0x00000001 | ||
| 859 | #define DTF_1_CONFEXP	0x00000002 | ||
| 860 | |||
| 861 | |||
| 862 | #define DF_P1_LAZYLOAD	0x00000001 | ||
| 863 | #define DF_P1_GROUPPERM	0x00000002 | ||
| 864 | |||
| 865 | |||
| 866 | |||
| 867 | |||
| 868 | typedef struct { | ||
| 869 | Elf32_Half	vd_version; | ||
| 870 | Elf32_Half	vd_flags; | ||
| 871 | Elf32_Half	vd_ndx; | ||
| 872 | Elf32_Half	vd_cnt; | ||
| 873 | Elf32_Word	vd_hash; | ||
| 874 | Elf32_Word	vd_aux; | ||
| 875 | Elf32_Word	vd_next; | ||
| 876 | } Elf32_Verdef; | ||
| 877 | |||
| 878 | typedef struct { | ||
| 879 | Elf64_Half	vd_version; | ||
| 880 | Elf64_Half	vd_flags; | ||
| 881 | Elf64_Half	vd_ndx; | ||
| 882 | Elf64_Half	vd_cnt; | ||
| 883 | Elf64_Word	vd_hash; | ||
| 884 | Elf64_Word	vd_aux; | ||
| 885 | Elf64_Word	vd_next; | ||
| 886 | } Elf64_Verdef; | ||
| 887 | |||
| 888 | |||
| 889 | |||
| 890 | #define VER_DEF_NONE	0 | ||
| 891 | #define VER_DEF_CURRENT	1 | ||
| 892 | #define VER_DEF_NUM	2 | ||
| 893 | |||
| 894 | |||
| 895 | #define VER_FLG_BASE	0x1 | ||
| 896 | #define VER_FLG_WEAK	0x2 | ||
| 897 | |||
| 898 | |||
| 899 | #define	VER_NDX_LOCAL		0 | ||
| 900 | #define	VER_NDX_GLOBAL		1 | ||
| 901 | #define	VER_NDX_LORESERVE	0xff00 | ||
| 902 | #define	VER_NDX_ELIMINATE	0xff01 | ||
| 903 | |||
| 904 | |||
| 905 | |||
| 906 | typedef struct { | ||
| 907 | Elf32_Word	vda_name; | ||
| 908 | Elf32_Word	vda_next; | ||
| 909 | } Elf32_Verdaux; | ||
| 910 | |||
| 911 | typedef struct { | ||
| 912 | Elf64_Word	vda_name; | ||
| 913 | Elf64_Word	vda_next; | ||
| 914 | } Elf64_Verdaux; | ||
| 915 | |||
| 916 | |||
| 917 | |||
| 918 | |||
| 919 | typedef struct { | ||
| 920 | Elf32_Half	vn_version; | ||
| 921 | Elf32_Half	vn_cnt; | ||
| 922 | Elf32_Word	vn_file; | ||
| 923 | Elf32_Word	vn_aux; | ||
| 924 | Elf32_Word	vn_next; | ||
| 925 | } Elf32_Verneed; | ||
| 926 | |||
| 927 | typedef struct { | ||
| 928 | Elf64_Half	vn_version; | ||
| 929 | Elf64_Half	vn_cnt; | ||
| 930 | Elf64_Word	vn_file; | ||
| 931 | Elf64_Word	vn_aux; | ||
| 932 | Elf64_Word	vn_next; | ||
| 933 | } Elf64_Verneed; | ||
| 934 | |||
| 935 | |||
| 936 | |||
| 937 | #define VER_NEED_NONE	 0 | ||
| 938 | #define VER_NEED_CURRENT 1 | ||
| 939 | #define VER_NEED_NUM	 2 | ||
| 940 | |||
| 941 | |||
| 942 | |||
| 943 | typedef struct { | ||
| 944 | Elf32_Word	vna_hash; | ||
| 945 | Elf32_Half	vna_flags; | ||
| 946 | Elf32_Half	vna_other; | ||
| 947 | Elf32_Word	vna_name; | ||
| 948 | Elf32_Word	vna_next; | ||
| 949 | } Elf32_Vernaux; | ||
| 950 | |||
| 951 | typedef struct { | ||
| 952 | Elf64_Word	vna_hash; | ||
| 953 | Elf64_Half	vna_flags; | ||
| 954 | Elf64_Half	vna_other; | ||
| 955 | Elf64_Word	vna_name; | ||
| 956 | Elf64_Word	vna_next; | ||
| 957 | } Elf64_Vernaux; | ||
| 958 | |||
| 959 | |||
| 960 | |||
| 961 | #define VER_FLG_WEAK	0x2 | ||
| 962 | |||
| 963 | |||
| 964 | |||
| 965 | typedef struct { | ||
| 966 | uint32_t a_type; | ||
| 967 | union { | ||
| 968 | uint32_t a_val; | ||
| 969 | } a_un; | ||
| 970 | } Elf32_auxv_t; | ||
| 971 | |||
| 972 | typedef struct { | ||
| 973 | uint64_t a_type; | ||
| 974 | union { | ||
| 975 | uint64_t a_val; | ||
| 976 | } a_un; | ||
| 977 | } Elf64_auxv_t; | ||
| 978 | |||
| 979 | |||
| 980 | |||
| 981 | #define AT_NULL		0 | ||
| 982 | #define AT_IGNORE	1 | ||
| 983 | #define AT_EXECFD	2 | ||
| 984 | #define AT_PHDR		3 | ||
| 985 | #define AT_PHENT	4 | ||
| 986 | #define AT_PHNUM	5 | ||
| 987 | #define AT_PAGESZ	6 | ||
| 988 | #define AT_BASE		7 | ||
| 989 | #define AT_FLAGS	8 | ||
| 990 | #define AT_ENTRY	9 | ||
| 991 | #define AT_NOTELF	10 | ||
| 992 | #define AT_UID		11 | ||
| 993 | #define AT_EUID		12 | ||
| 994 | #define AT_GID		13 | ||
| 995 | #define AT_EGID		14 | ||
| 996 | #define AT_CLKTCK	17 | ||
| 997 | |||
| 998 | |||
| 999 | #define AT_PLATFORM	15 | ||
| 1000 | #define AT_HWCAP	16 | ||
| 1001 | |||
| 1002 | |||
| 1003 | |||
| 1004 | |||
| 1005 | #define AT_FPUCW	18 | ||
| 1006 | |||
| 1007 | |||
| 1008 | #define AT_DCACHEBSIZE	19 | ||
| 1009 | #define AT_ICACHEBSIZE	20 | ||
| 1010 | #define AT_UCACHEBSIZE	21 | ||
| 1011 | |||
| 1012 | |||
| 1013 | |||
| 1014 | #define AT_IGNOREPPC	22 | ||
| 1015 | |||
| 1016 | #define	AT_SECURE	23 | ||
| 1017 | |||
| 1018 | #define AT_BASE_PLATFORM 24 | ||
| 1019 | |||
| 1020 | #define AT_RANDOM	25 | ||
| 1021 | |||
| 1022 | #define AT_HWCAP2	26 | ||
| 1023 | |||
| 1024 | #define AT_EXECFN	31 | ||
| 1025 | |||
| 1026 | |||
| 1027 | |||
| 1028 | #define AT_SYSINFO	32 | ||
| 1029 | #define AT_SYSINFO_EHDR	33 | ||
| 1030 | |||
| 1031 | |||
| 1032 | |||
| 1033 | #define AT_L1I_CACHESHAPE	34 | ||
| 1034 | #define AT_L1D_CACHESHAPE	35 | ||
| 1035 | #define AT_L2_CACHESHAPE	36 | ||
| 1036 | #define AT_L3_CACHESHAPE	37 | ||
| 1037 | |||
| 1038 | #define AT_L1I_CACHESIZE	40 | ||
| 1039 | #define AT_L1I_CACHEGEOMETRY	41 | ||
| 1040 | #define AT_L1D_CACHESIZE	42 | ||
| 1041 | #define AT_L1D_CACHEGEOMETRY	43 | ||
| 1042 | #define AT_L2_CACHESIZE		44 | ||
| 1043 | #define AT_L2_CACHEGEOMETRY	45 | ||
| 1044 | #define AT_L3_CACHESIZE		46 | ||
| 1045 | #define AT_L3_CACHEGEOMETRY	47 | ||
| 1046 | |||
| 1047 | #define AT_MINSIGSTKSZ		51 | ||
| 1048 | |||
| 1049 | |||
| 1050 | typedef struct { | ||
| 1051 | Elf32_Word n_namesz; | ||
| 1052 | Elf32_Word n_descsz; | ||
| 1053 | Elf32_Word n_type; | ||
| 1054 | } Elf32_Nhdr; | ||
| 1055 | |||
| 1056 | typedef struct { | ||
| 1057 | Elf64_Word n_namesz; | ||
| 1058 | Elf64_Word n_descsz; | ||
| 1059 | Elf64_Word n_type; | ||
| 1060 | } Elf64_Nhdr; | ||
| 1061 | |||
| 1062 | |||
| 1063 | |||
| 1064 | |||
| 1065 | #define ELF_NOTE_SOLARIS	"SUNW Solaris" | ||
| 1066 | |||
| 1067 | |||
| 1068 | #define ELF_NOTE_GNU		"GNU" | ||
| 1069 | |||
| 1070 | |||
| 1071 | |||
| 1072 | |||
| 1073 | |||
| 1074 | #define ELF_NOTE_PAGESIZE_HINT	1 | ||
| 1075 | |||
| 1076 | |||
| 1077 | #define NT_GNU_ABI_TAG	1 | ||
| 1078 | #define ELF_NOTE_ABI	NT_GNU_ABI_TAG | ||
| 1079 | |||
| 1080 | |||
| 1081 | |||
| 1082 | #define ELF_NOTE_OS_LINUX	0 | ||
| 1083 | #define ELF_NOTE_OS_GNU		1 | ||
| 1084 | #define ELF_NOTE_OS_SOLARIS2	2 | ||
| 1085 | #define ELF_NOTE_OS_FREEBSD	3 | ||
| 1086 | |||
| 1087 | #define NT_GNU_BUILD_ID	3 | ||
| 1088 | #define NT_GNU_GOLD_VERSION	4 | ||
| 1089 | #define NT_GNU_PROPERTY_TYPE_0	5 | ||
| 1090 | |||
| 1091 | |||
| 1092 | |||
| 1093 | typedef struct { | ||
| 1094 | Elf32_Xword m_value; | ||
| 1095 | Elf32_Word m_info; | ||
| 1096 | Elf32_Word m_poffset; | ||
| 1097 | Elf32_Half m_repeat; | ||
| 1098 | Elf32_Half m_stride; | ||
| 1099 | } Elf32_Move; | ||
| 1100 | |||
| 1101 | typedef struct { | ||
| 1102 | Elf64_Xword m_value; | ||
| 1103 | Elf64_Xword m_info; | ||
| 1104 | Elf64_Xword m_poffset; | ||
| 1105 | Elf64_Half m_repeat; | ||
| 1106 | Elf64_Half m_stride; | ||
| 1107 | } Elf64_Move; | ||
| 1108 | |||
| 1109 | |||
| 1110 | #define ELF32_M_SYM(info)	((info) >> 8) | ||
| 1111 | #define ELF32_M_SIZE(info)	((unsigned char) (info)) | ||
| 1112 | #define ELF32_M_INFO(sym, size)	(((sym) << 8) + (unsigned char) (size)) | ||
| 1113 | |||
| 1114 | #define ELF64_M_SYM(info)	ELF32_M_SYM (info) | ||
| 1115 | #define ELF64_M_SIZE(info)	ELF32_M_SIZE (info) | ||
| 1116 | #define ELF64_M_INFO(sym, size)	ELF32_M_INFO (sym, size) | ||
| 1117 | |||
| 1118 | #define EF_CPU32	0x00810000 | ||
| 1119 | |||
| 1120 | #define R_68K_NONE	0 | ||
| 1121 | #define R_68K_32	1 | ||
| 1122 | #define R_68K_16	2 | ||
| 1123 | #define R_68K_8		3 | ||
| 1124 | #define R_68K_PC32	4 | ||
| 1125 | #define R_68K_PC16	5 | ||
| 1126 | #define R_68K_PC8	6 | ||
| 1127 | #define R_68K_GOT32	7 | ||
| 1128 | #define R_68K_GOT16	8 | ||
| 1129 | #define R_68K_GOT8	9 | ||
| 1130 | #define R_68K_GOT32O	10 | ||
| 1131 | #define R_68K_GOT16O	11 | ||
| 1132 | #define R_68K_GOT8O	12 | ||
| 1133 | #define R_68K_PLT32	13 | ||
| 1134 | #define R_68K_PLT16	14 | ||
| 1135 | #define R_68K_PLT8	15 | ||
| 1136 | #define R_68K_PLT32O	16 | ||
| 1137 | #define R_68K_PLT16O	17 | ||
| 1138 | #define R_68K_PLT8O	18 | ||
| 1139 | #define R_68K_COPY	19 | ||
| 1140 | #define R_68K_GLOB_DAT	20 | ||
| 1141 | #define R_68K_JMP_SLOT	21 | ||
| 1142 | #define R_68K_RELATIVE	22 | ||
| 1143 | #define R_68K_TLS_GD32	25 | ||
| 1144 | #define R_68K_TLS_GD16	26 | ||
| 1145 | #define R_68K_TLS_GD8	27 | ||
| 1146 | #define R_68K_TLS_LDM32	28 | ||
| 1147 | #define R_68K_TLS_LDM16	29 | ||
| 1148 | #define R_68K_TLS_LDM8	30 | ||
| 1149 | #define R_68K_TLS_LDO32	31 | ||
| 1150 | #define R_68K_TLS_LDO16	32 | ||
| 1151 | #define R_68K_TLS_LDO8	33 | ||
| 1152 | #define R_68K_TLS_IE32	34 | ||
| 1153 | #define R_68K_TLS_IE16	35 | ||
| 1154 | #define R_68K_TLS_IE8	36 | ||
| 1155 | #define R_68K_TLS_LE32	37 | ||
| 1156 | #define R_68K_TLS_LE16	38 | ||
| 1157 | #define R_68K_TLS_LE8	39 | ||
| 1158 | #define R_68K_TLS_DTPMOD32	40 | ||
| 1159 | #define R_68K_TLS_DTPREL32	41 | ||
| 1160 | #define R_68K_TLS_TPREL32	42 | ||
| 1161 | #define R_68K_NUM	43 | ||
| 1162 | |||
| 1163 | #define R_386_NONE	 0 | ||
| 1164 | #define R_386_32	 1 | ||
| 1165 | #define R_386_PC32	 2 | ||
| 1166 | #define R_386_GOT32	 3 | ||
| 1167 | #define R_386_PLT32	 4 | ||
| 1168 | #define R_386_COPY	 5 | ||
| 1169 | #define R_386_GLOB_DAT	 6 | ||
| 1170 | #define R_386_JMP_SLOT	 7 | ||
| 1171 | #define R_386_RELATIVE	 8 | ||
| 1172 | #define R_386_GOTOFF	 9 | ||
| 1173 | #define R_386_GOTPC	 10 | ||
| 1174 | #define R_386_32PLT	 11 | ||
| 1175 | #define R_386_TLS_TPOFF	 14 | ||
| 1176 | #define R_386_TLS_IE	 15 | ||
| 1177 | #define R_386_TLS_GOTIE	 16 | ||
| 1178 | #define R_386_TLS_LE	 17 | ||
| 1179 | #define R_386_TLS_GD	 18 | ||
| 1180 | #define R_386_TLS_LDM	 19 | ||
| 1181 | #define R_386_16	 20 | ||
| 1182 | #define R_386_PC16	 21 | ||
| 1183 | #define R_386_8		 22 | ||
| 1184 | #define R_386_PC8	 23 | ||
| 1185 | #define R_386_TLS_GD_32	 24 | ||
| 1186 | #define R_386_TLS_GD_PUSH 25 | ||
| 1187 | #define R_386_TLS_GD_CALL 26 | ||
| 1188 | #define R_386_TLS_GD_POP 27 | ||
| 1189 | #define R_386_TLS_LDM_32 28 | ||
| 1190 | #define R_386_TLS_LDM_PUSH 29 | ||
| 1191 | #define R_386_TLS_LDM_CALL 30 | ||
| 1192 | #define R_386_TLS_LDM_POP 31 | ||
| 1193 | #define R_386_TLS_LDO_32 32 | ||
| 1194 | #define R_386_TLS_IE_32	 33 | ||
| 1195 | #define R_386_TLS_LE_32	 34 | ||
| 1196 | #define R_386_TLS_DTPMOD32 35 | ||
| 1197 | #define R_386_TLS_DTPOFF32 36 | ||
| 1198 | #define R_386_TLS_TPOFF32 37 | ||
| 1199 | #define R_386_SIZE32 38 | ||
| 1200 | #define R_386_TLS_GOTDESC 39 | ||
| 1201 | #define R_386_TLS_DESC_CALL 40 | ||
| 1202 | #define R_386_TLS_DESC 41 | ||
| 1203 | #define R_386_IRELATIVE	 42 | ||
| 1204 | #define R_386_GOT32X	 43 | ||
| 1205 | #define R_386_NUM	 44 | ||
| 1206 | |||
| 1207 | |||
| 1208 | |||
| 1209 | |||
| 1210 | |||
| 1211 | #define STT_SPARC_REGISTER	13 | ||
| 1212 | |||
| 1213 | |||
| 1214 | |||
| 1215 | #define EF_SPARCV9_MM		3 | ||
| 1216 | #define EF_SPARCV9_TSO		0 | ||
| 1217 | #define EF_SPARCV9_PSO		1 | ||
| 1218 | #define EF_SPARCV9_RMO		2 | ||
| 1219 | #define EF_SPARC_LEDATA		0x800000 | ||
| 1220 | #define EF_SPARC_EXT_MASK	0xFFFF00 | ||
| 1221 | #define EF_SPARC_32PLUS		0x000100 | ||
| 1222 | #define EF_SPARC_SUN_US1	0x000200 | ||
| 1223 | #define EF_SPARC_HAL_R1		0x000400 | ||
| 1224 | #define EF_SPARC_SUN_US3	0x000800 | ||
| 1225 | |||
| 1226 | |||
| 1227 | |||
| 1228 | #define R_SPARC_NONE		0 | ||
| 1229 | #define R_SPARC_8		1 | ||
| 1230 | #define R_SPARC_16		2 | ||
| 1231 | #define R_SPARC_32		3 | ||
| 1232 | #define R_SPARC_DISP8		4 | ||
| 1233 | #define R_SPARC_DISP16		5 | ||
| 1234 | #define R_SPARC_DISP32		6 | ||
| 1235 | #define R_SPARC_WDISP30		7 | ||
| 1236 | #define R_SPARC_WDISP22		8 | ||
| 1237 | #define R_SPARC_HI22		9 | ||
| 1238 | #define R_SPARC_22		10 | ||
| 1239 | #define R_SPARC_13		11 | ||
| 1240 | #define R_SPARC_LO10		12 | ||
| 1241 | #define R_SPARC_GOT10		13 | ||
| 1242 | #define R_SPARC_GOT13		14 | ||
| 1243 | #define R_SPARC_GOT22		15 | ||
| 1244 | #define R_SPARC_PC10		16 | ||
| 1245 | #define R_SPARC_PC22		17 | ||
| 1246 | #define R_SPARC_WPLT30		18 | ||
| 1247 | #define R_SPARC_COPY		19 | ||
| 1248 | #define R_SPARC_GLOB_DAT	20 | ||
| 1249 | #define R_SPARC_JMP_SLOT	21 | ||
| 1250 | #define R_SPARC_RELATIVE	22 | ||
| 1251 | #define R_SPARC_UA32		23 | ||
| 1252 | |||
| 1253 | |||
| 1254 | |||
| 1255 | #define R_SPARC_PLT32		24 | ||
| 1256 | #define R_SPARC_HIPLT22		25 | ||
| 1257 | #define R_SPARC_LOPLT10		26 | ||
| 1258 | #define R_SPARC_PCPLT32		27 | ||
| 1259 | #define R_SPARC_PCPLT22		28 | ||
| 1260 | #define R_SPARC_PCPLT10		29 | ||
| 1261 | #define R_SPARC_10		30 | ||
| 1262 | #define R_SPARC_11		31 | ||
| 1263 | #define R_SPARC_64		32 | ||
| 1264 | #define R_SPARC_OLO10		33 | ||
| 1265 | #define R_SPARC_HH22		34 | ||
| 1266 | #define R_SPARC_HM10		35 | ||
| 1267 | #define R_SPARC_LM22		36 | ||
| 1268 | #define R_SPARC_PC_HH22		37 | ||
| 1269 | #define R_SPARC_PC_HM10		38 | ||
| 1270 | #define R_SPARC_PC_LM22		39 | ||
| 1271 | #define R_SPARC_WDISP16		40 | ||
| 1272 | #define R_SPARC_WDISP19		41 | ||
| 1273 | #define R_SPARC_GLOB_JMP	42 | ||
| 1274 | #define R_SPARC_7		43 | ||
| 1275 | #define R_SPARC_5		44 | ||
| 1276 | #define R_SPARC_6		45 | ||
| 1277 | #define R_SPARC_DISP64		46 | ||
| 1278 | #define R_SPARC_PLT64		47 | ||
| 1279 | #define R_SPARC_HIX22		48 | ||
| 1280 | #define R_SPARC_LOX10		49 | ||
| 1281 | #define R_SPARC_H44		50 | ||
| 1282 | #define R_SPARC_M44		51 | ||
| 1283 | #define R_SPARC_L44		52 | ||
| 1284 | #define R_SPARC_REGISTER	53 | ||
| 1285 | #define R_SPARC_UA64		54 | ||
| 1286 | #define R_SPARC_UA16		55 | ||
| 1287 | #define R_SPARC_TLS_GD_HI22	56 | ||
| 1288 | #define R_SPARC_TLS_GD_LO10	57 | ||
| 1289 | #define R_SPARC_TLS_GD_ADD	58 | ||
| 1290 | #define R_SPARC_TLS_GD_CALL	59 | ||
| 1291 | #define R_SPARC_TLS_LDM_HI22	60 | ||
| 1292 | #define R_SPARC_TLS_LDM_LO10	61 | ||
| 1293 | #define R_SPARC_TLS_LDM_ADD	62 | ||
| 1294 | #define R_SPARC_TLS_LDM_CALL	63 | ||
| 1295 | #define R_SPARC_TLS_LDO_HIX22	64 | ||
| 1296 | #define R_SPARC_TLS_LDO_LOX10	65 | ||
| 1297 | #define R_SPARC_TLS_LDO_ADD	66 | ||
| 1298 | #define R_SPARC_TLS_IE_HI22	67 | ||
| 1299 | #define R_SPARC_TLS_IE_LO10	68 | ||
| 1300 | #define R_SPARC_TLS_IE_LD	69 | ||
| 1301 | #define R_SPARC_TLS_IE_LDX	70 | ||
| 1302 | #define R_SPARC_TLS_IE_ADD	71 | ||
| 1303 | #define R_SPARC_TLS_LE_HIX22	72 | ||
| 1304 | #define R_SPARC_TLS_LE_LOX10	73 | ||
| 1305 | #define R_SPARC_TLS_DTPMOD32	74 | ||
| 1306 | #define R_SPARC_TLS_DTPMOD64	75 | ||
| 1307 | #define R_SPARC_TLS_DTPOFF32	76 | ||
| 1308 | #define R_SPARC_TLS_DTPOFF64	77 | ||
| 1309 | #define R_SPARC_TLS_TPOFF32	78 | ||
| 1310 | #define R_SPARC_TLS_TPOFF64	79 | ||
| 1311 | #define R_SPARC_GOTDATA_HIX22	80 | ||
| 1312 | #define R_SPARC_GOTDATA_LOX10	81 | ||
| 1313 | #define R_SPARC_GOTDATA_OP_HIX22	82 | ||
| 1314 | #define R_SPARC_GOTDATA_OP_LOX10	83 | ||
| 1315 | #define R_SPARC_GOTDATA_OP	84 | ||
| 1316 | #define R_SPARC_H34		85 | ||
| 1317 | #define R_SPARC_SIZE32		86 | ||
| 1318 | #define R_SPARC_SIZE64		87 | ||
| 1319 | #define R_SPARC_GNU_VTINHERIT	250 | ||
| 1320 | #define R_SPARC_GNU_VTENTRY	251 | ||
| 1321 | #define R_SPARC_REV32		252 | ||
| 1322 | |||
| 1323 | #define R_SPARC_NUM		253 | ||
| 1324 | |||
| 1325 | |||
| 1326 | |||
| 1327 | #define DT_SPARC_REGISTER 0x70000001 | ||
| 1328 | #define DT_SPARC_NUM	2 | ||
| 1329 | |||
| 1330 | |||
| 1331 | #define EF_MIPS_NOREORDER 1 | ||
| 1332 | #define EF_MIPS_PIC	 2 | ||
| 1333 | #define EF_MIPS_CPIC	 4 | ||
| 1334 | #define EF_MIPS_XGOT	 8 | ||
| 1335 | #define EF_MIPS_64BIT_WHIRL 16 | ||
| 1336 | #define EF_MIPS_ABI2	 32 | ||
| 1337 | #define EF_MIPS_ABI_ON32 64 | ||
| 1338 | #define EF_MIPS_FP64	 512 | ||
| 1339 | #define EF_MIPS_NAN2008 1024 | ||
| 1340 | #define EF_MIPS_ARCH	 0xf0000000 | ||
| 1341 | |||
| 1342 | |||
| 1343 | |||
| 1344 | #define EF_MIPS_ARCH_1	 0x00000000 | ||
| 1345 | #define EF_MIPS_ARCH_2	 0x10000000 | ||
| 1346 | #define EF_MIPS_ARCH_3	 0x20000000 | ||
| 1347 | #define EF_MIPS_ARCH_4	 0x30000000 | ||
| 1348 | #define EF_MIPS_ARCH_5	 0x40000000 | ||
| 1349 | #define EF_MIPS_ARCH_32 0x50000000 | ||
| 1350 | #define EF_MIPS_ARCH_64 0x60000000 | ||
| 1351 | #define EF_MIPS_ARCH_32R2 0x70000000 | ||
| 1352 | #define EF_MIPS_ARCH_64R2 0x80000000 | ||
| 1353 | |||
| 1354 | |||
| 1355 | #define E_MIPS_ARCH_1	 0x00000000 | ||
| 1356 | #define E_MIPS_ARCH_2	 0x10000000 | ||
| 1357 | #define E_MIPS_ARCH_3	 0x20000000 | ||
| 1358 | #define E_MIPS_ARCH_4	 0x30000000 | ||
| 1359 | #define E_MIPS_ARCH_5	 0x40000000 | ||
| 1360 | #define E_MIPS_ARCH_32	 0x50000000 | ||
| 1361 | #define E_MIPS_ARCH_64	 0x60000000 | ||
| 1362 | |||
| 1363 | |||
| 1364 | |||
| 1365 | #define SHN_MIPS_ACOMMON 0xff00 | ||
| 1366 | #define SHN_MIPS_TEXT	 0xff01 | ||
| 1367 | #define SHN_MIPS_DATA	 0xff02 | ||
| 1368 | #define SHN_MIPS_SCOMMON 0xff03 | ||
| 1369 | #define SHN_MIPS_SUNDEFINED 0xff04 | ||
| 1370 | |||
| 1371 | |||
| 1372 | |||
| 1373 | #define SHT_MIPS_LIBLIST 0x70000000 | ||
| 1374 | #define SHT_MIPS_MSYM	 0x70000001 | ||
| 1375 | #define SHT_MIPS_CONFLICT 0x70000002 | ||
| 1376 | #define SHT_MIPS_GPTAB	 0x70000003 | ||
| 1377 | #define SHT_MIPS_UCODE	 0x70000004 | ||
| 1378 | #define SHT_MIPS_DEBUG	 0x70000005 | ||
| 1379 | #define SHT_MIPS_REGINFO 0x70000006 | ||
| 1380 | #define SHT_MIPS_PACKAGE 0x70000007 | ||
| 1381 | #define SHT_MIPS_PACKSYM 0x70000008 | ||
| 1382 | #define SHT_MIPS_RELD	 0x70000009 | ||
| 1383 | #define SHT_MIPS_IFACE 0x7000000b | ||
| 1384 | #define SHT_MIPS_CONTENT 0x7000000c | ||
| 1385 | #define SHT_MIPS_OPTIONS 0x7000000d | ||
| 1386 | #define SHT_MIPS_SHDR	 0x70000010 | ||
| 1387 | #define SHT_MIPS_FDESC	 0x70000011 | ||
| 1388 | #define SHT_MIPS_EXTSYM	 0x70000012 | ||
| 1389 | #define SHT_MIPS_DENSE	 0x70000013 | ||
| 1390 | #define SHT_MIPS_PDESC	 0x70000014 | ||
| 1391 | #define SHT_MIPS_LOCSYM	 0x70000015 | ||
| 1392 | #define SHT_MIPS_AUXSYM	 0x70000016 | ||
| 1393 | #define SHT_MIPS_OPTSYM	 0x70000017 | ||
| 1394 | #define SHT_MIPS_LOCSTR	 0x70000018 | ||
| 1395 | #define SHT_MIPS_LINE	 0x70000019 | ||
| 1396 | #define SHT_MIPS_RFDESC	 0x7000001a | ||
| 1397 | #define SHT_MIPS_DELTASYM 0x7000001b | ||
| 1398 | #define SHT_MIPS_DELTAINST 0x7000001c | ||
| 1399 | #define SHT_MIPS_DELTACLASS 0x7000001d | ||
| 1400 | #define SHT_MIPS_DWARF 0x7000001e | ||
| 1401 | #define SHT_MIPS_DELTADECL 0x7000001f | ||
| 1402 | #define SHT_MIPS_SYMBOL_LIB 0x70000020 | ||
| 1403 | #define SHT_MIPS_EVENTS	 0x70000021 | ||
| 1404 | #define SHT_MIPS_TRANSLATE 0x70000022 | ||
| 1405 | #define SHT_MIPS_PIXIE	 0x70000023 | ||
| 1406 | #define SHT_MIPS_XLATE	 0x70000024 | ||
| 1407 | #define SHT_MIPS_XLATE_DEBUG 0x70000025 | ||
| 1408 | #define SHT_MIPS_WHIRL	 0x70000026 | ||
| 1409 | #define SHT_MIPS_EH_REGION 0x70000027 | ||
| 1410 | #define SHT_MIPS_XLATE_OLD 0x70000028 | ||
| 1411 | #define SHT_MIPS_PDR_EXCEPTION 0x70000029 | ||
| 1412 | |||
| 1413 | |||
| 1414 | |||
| 1415 | #define SHF_MIPS_GPREL	 0x10000000 | ||
| 1416 | #define SHF_MIPS_MERGE	 0x20000000 | ||
| 1417 | #define SHF_MIPS_ADDR	 0x40000000 | ||
| 1418 | #define SHF_MIPS_STRINGS 0x80000000 | ||
| 1419 | #define SHF_MIPS_NOSTRIP 0x08000000 | ||
| 1420 | #define SHF_MIPS_LOCAL	 0x04000000 | ||
| 1421 | #define SHF_MIPS_NAMES	 0x02000000 | ||
| 1422 | #define SHF_MIPS_NODUPE	 0x01000000 | ||
| 1423 | |||
| 1424 | |||
| 1425 | |||
| 1426 | |||
| 1427 | |||
| 1428 | #define STO_MIPS_DEFAULT		0x0 | ||
| 1429 | #define STO_MIPS_INTERNAL		0x1 | ||
| 1430 | #define STO_MIPS_HIDDEN			0x2 | ||
| 1431 | #define STO_MIPS_PROTECTED		0x3 | ||
| 1432 | #define STO_MIPS_PLT			0x8 | ||
| 1433 | #define STO_MIPS_SC_ALIGN_UNUSED	0xff | ||
| 1434 | |||
| 1435 | |||
| 1436 | #define STB_MIPS_SPLIT_COMMON		13 | ||
| 1437 | |||
| 1438 | |||
| 1439 | |||
| 1440 | typedef union { | ||
| 1441 | struct { | ||
| 1442 | Elf32_Word gt_current_g_value; | ||
| 1443 | Elf32_Word gt_unused; | ||
| 1444 | } gt_header; | ||
| 1445 | struct { | ||
| 1446 | Elf32_Word gt_g_value; | ||
| 1447 | Elf32_Word gt_bytes; | ||
| 1448 | } gt_entry; | ||
| 1449 | } Elf32_gptab; | ||
| 1450 | |||
| 1451 | |||
| 1452 | |||
| 1453 | typedef struct { | ||
| 1454 | Elf32_Word	ri_gprmask; | ||
| 1455 | Elf32_Word	ri_cprmask[4]; | ||
| 1456 | Elf32_Sword	ri_gp_value; | ||
| 1457 | } Elf32_RegInfo; | ||
| 1458 | |||
| 1459 | |||
| 1460 | |||
| 1461 | typedef struct { | ||
| 1462 | unsigned char kind; | ||
| 1463 | |||
| 1464 | unsigned char size; | ||
| 1465 | Elf32_Section section; | ||
| 1466 | |||
| 1467 | Elf32_Word info; | ||
| 1468 | } Elf_Options; | ||
| 1469 | |||
| 1470 | |||
| 1471 | |||
| 1472 | #define ODK_NULL	0 | ||
| 1473 | #define ODK_REGINFO	1 | ||
| 1474 | #define ODK_EXCEPTIONS	2 | ||
| 1475 | #define ODK_PAD		3 | ||
| 1476 | #define ODK_HWPATCH	4 | ||
| 1477 | #define ODK_FILL	5 | ||
| 1478 | #define ODK_TAGS	6 | ||
| 1479 | #define ODK_HWAND	7 | ||
| 1480 | #define ODK_HWOR	8 | ||
| 1481 | |||
| 1482 | |||
| 1483 | |||
| 1484 | #define OEX_FPU_MIN	0x1f | ||
| 1485 | #define OEX_FPU_MAX	0x1f00 | ||
| 1486 | #define OEX_PAGE0	0x10000 | ||
| 1487 | #define OEX_SMM		0x20000 | ||
| 1488 | #define OEX_FPDBUG	0x40000 | ||
| 1489 | #define OEX_PRECISEFP	OEX_FPDBUG | ||
| 1490 | #define OEX_DISMISS	0x80000 | ||
| 1491 | |||
| 1492 | #define OEX_FPU_INVAL	0x10 | ||
| 1493 | #define OEX_FPU_DIV0	0x08 | ||
| 1494 | #define OEX_FPU_OFLO	0x04 | ||
| 1495 | #define OEX_FPU_UFLO	0x02 | ||
| 1496 | #define OEX_FPU_INEX	0x01 | ||
| 1497 | |||
| 1498 | |||
| 1499 | |||
| 1500 | #define OHW_R4KEOP	0x1 | ||
| 1501 | #define OHW_R8KPFETCH	0x2 | ||
| 1502 | #define OHW_R5KEOP	0x4 | ||
| 1503 | #define OHW_R5KCVTL	0x8 | ||
| 1504 | |||
| 1505 | #define OPAD_PREFIX	0x1 | ||
| 1506 | #define OPAD_POSTFIX	0x2 | ||
| 1507 | #define OPAD_SYMBOL	0x4 | ||
| 1508 | |||
| 1509 | |||
| 1510 | |||
| 1511 | typedef struct { | ||
| 1512 | Elf32_Word hwp_flags1; | ||
| 1513 | Elf32_Word hwp_flags2; | ||
| 1514 | } Elf_Options_Hw; | ||
| 1515 | |||
| 1516 | |||
| 1517 | |||
| 1518 | #define OHWA0_R4KEOP_CHECKED	0x00000001 | ||
| 1519 | #define OHWA1_R4KEOP_CLEAN	0x00000002 | ||
| 1520 | |||
| 1521 | |||
| 1522 | |||
| 1523 | #define R_MIPS_NONE		0 | ||
| 1524 | #define R_MIPS_16		1 | ||
| 1525 | #define R_MIPS_32		2 | ||
| 1526 | #define R_MIPS_REL32		3 | ||
| 1527 | #define R_MIPS_26		4 | ||
| 1528 | #define R_MIPS_HI16		5 | ||
| 1529 | #define R_MIPS_LO16		6 | ||
| 1530 | #define R_MIPS_GPREL16		7 | ||
| 1531 | #define R_MIPS_LITERAL		8 | ||
| 1532 | #define R_MIPS_GOT16		9 | ||
| 1533 | #define R_MIPS_PC16		10 | ||
| 1534 | #define R_MIPS_CALL16		11 | ||
| 1535 | #define R_MIPS_GPREL32		12 | ||
| 1536 | |||
| 1537 | #define R_MIPS_SHIFT5		16 | ||
| 1538 | #define R_MIPS_SHIFT6		17 | ||
| 1539 | #define R_MIPS_64		18 | ||
| 1540 | #define R_MIPS_GOT_DISP		19 | ||
| 1541 | #define R_MIPS_GOT_PAGE		20 | ||
| 1542 | #define R_MIPS_GOT_OFST		21 | ||
| 1543 | #define R_MIPS_GOT_HI16		22 | ||
| 1544 | #define R_MIPS_GOT_LO16		23 | ||
| 1545 | #define R_MIPS_SUB		24 | ||
| 1546 | #define R_MIPS_INSERT_A		25 | ||
| 1547 | #define R_MIPS_INSERT_B		26 | ||
| 1548 | #define R_MIPS_DELETE		27 | ||
| 1549 | #define R_MIPS_HIGHER		28 | ||
| 1550 | #define R_MIPS_HIGHEST		29 | ||
| 1551 | #define R_MIPS_CALL_HI16	30 | ||
| 1552 | #define R_MIPS_CALL_LO16	31 | ||
| 1553 | #define R_MIPS_SCN_DISP		32 | ||
| 1554 | #define R_MIPS_REL16		33 | ||
| 1555 | #define R_MIPS_ADD_IMMEDIATE	34 | ||
| 1556 | #define R_MIPS_PJUMP		35 | ||
| 1557 | #define R_MIPS_RELGOT		36 | ||
| 1558 | #define R_MIPS_JALR		37 | ||
| 1559 | #define R_MIPS_TLS_DTPMOD32	38 | ||
| 1560 | #define R_MIPS_TLS_DTPREL32	39 | ||
| 1561 | #define R_MIPS_TLS_DTPMOD64	40 | ||
| 1562 | #define R_MIPS_TLS_DTPREL64	41 | ||
| 1563 | #define R_MIPS_TLS_GD		42 | ||
| 1564 | #define R_MIPS_TLS_LDM		43 | ||
| 1565 | #define R_MIPS_TLS_DTPREL_HI16	44 | ||
| 1566 | #define R_MIPS_TLS_DTPREL_LO16	45 | ||
| 1567 | #define R_MIPS_TLS_GOTTPREL	46 | ||
| 1568 | #define R_MIPS_TLS_TPREL32	47 | ||
| 1569 | #define R_MIPS_TLS_TPREL64	48 | ||
| 1570 | #define R_MIPS_TLS_TPREL_HI16	49 | ||
| 1571 | #define R_MIPS_TLS_TPREL_LO16	50 | ||
| 1572 | #define R_MIPS_GLOB_DAT		51 | ||
| 1573 | #define R_MIPS_COPY		126 | ||
| 1574 | #define R_MIPS_JUMP_SLOT 127 | ||
| 1575 | |||
| 1576 | #define R_MIPS_NUM		128 | ||
| 1577 | |||
| 1578 | |||
| 1579 | |||
| 1580 | #define PT_MIPS_REGINFO	0x70000000 | ||
| 1581 | #define PT_MIPS_RTPROC 0x70000001 | ||
| 1582 | #define PT_MIPS_OPTIONS 0x70000002 | ||
| 1583 | #define PT_MIPS_ABIFLAGS 0x70000003 | ||
| 1584 | |||
| 1585 | |||
| 1586 | |||
| 1587 | #define PF_MIPS_LOCAL	0x10000000 | ||
| 1588 | |||
| 1589 | |||
| 1590 | |||
| 1591 | #define DT_MIPS_RLD_VERSION 0x70000001 | ||
| 1592 | #define DT_MIPS_TIME_STAMP 0x70000002 | ||
| 1593 | #define DT_MIPS_ICHECKSUM 0x70000003 | ||
| 1594 | #define DT_MIPS_IVERSION 0x70000004 | ||
| 1595 | #define DT_MIPS_FLAGS	 0x70000005 | ||
| 1596 | #define DT_MIPS_BASE_ADDRESS 0x70000006 | ||
| 1597 | #define DT_MIPS_MSYM	 0x70000007 | ||
| 1598 | #define DT_MIPS_CONFLICT 0x70000008 | ||
| 1599 | #define DT_MIPS_LIBLIST	 0x70000009 | ||
| 1600 | #define DT_MIPS_LOCAL_GOTNO 0x7000000a | ||
| 1601 | #define DT_MIPS_CONFLICTNO 0x7000000b | ||
| 1602 | #define DT_MIPS_LIBLISTNO 0x70000010 | ||
| 1603 | #define DT_MIPS_SYMTABNO 0x70000011 | ||
| 1604 | #define DT_MIPS_UNREFEXTNO 0x70000012 | ||
| 1605 | #define DT_MIPS_GOTSYM	 0x70000013 | ||
| 1606 | #define DT_MIPS_HIPAGENO 0x70000014 | ||
| 1607 | #define DT_MIPS_RLD_MAP	 0x70000016 | ||
| 1608 | #define DT_MIPS_DELTA_CLASS 0x70000017 | ||
| 1609 | #define DT_MIPS_DELTA_CLASS_NO 0x70000018 | ||
| 1610 | |||
| 1611 | #define DT_MIPS_DELTA_INSTANCE 0x70000019 | ||
| 1612 | #define DT_MIPS_DELTA_INSTANCE_NO 0x7000001a | ||
| 1613 | |||
| 1614 | #define DT_MIPS_DELTA_RELOC 0x7000001b | ||
| 1615 | #define DT_MIPS_DELTA_RELOC_NO 0x7000001c | ||
| 1616 | |||
| 1617 | #define DT_MIPS_DELTA_SYM 0x7000001d | ||
| 1618 | |||
| 1619 | #define DT_MIPS_DELTA_SYM_NO 0x7000001e | ||
| 1620 | |||
| 1621 | #define DT_MIPS_DELTA_CLASSSYM 0x70000020 | ||
| 1622 | |||
| 1623 | #define DT_MIPS_DELTA_CLASSSYM_NO 0x70000021 | ||
| 1624 | |||
| 1625 | #define DT_MIPS_CXX_FLAGS 0x70000022 | ||
| 1626 | #define DT_MIPS_PIXIE_INIT 0x70000023 | ||
| 1627 | #define DT_MIPS_SYMBOL_LIB 0x70000024 | ||
| 1628 | #define DT_MIPS_LOCALPAGE_GOTIDX 0x70000025 | ||
| 1629 | #define DT_MIPS_LOCAL_GOTIDX 0x70000026 | ||
| 1630 | #define DT_MIPS_HIDDEN_GOTIDX 0x70000027 | ||
| 1631 | #define DT_MIPS_PROTECTED_GOTIDX 0x70000028 | ||
| 1632 | #define DT_MIPS_OPTIONS	 0x70000029 | ||
| 1633 | #define DT_MIPS_INTERFACE 0x7000002a | ||
| 1634 | #define DT_MIPS_DYNSTR_ALIGN 0x7000002b | ||
| 1635 | #define DT_MIPS_INTERFACE_SIZE 0x7000002c | ||
| 1636 | #define DT_MIPS_RLD_TEXT_RESOLVE_ADDR 0x7000002d | ||
| 1637 | |||
| 1638 | #define DT_MIPS_PERF_SUFFIX 0x7000002e | ||
| 1639 | |||
| 1640 | #define DT_MIPS_COMPACT_SIZE 0x7000002f | ||
| 1641 | #define DT_MIPS_GP_VALUE 0x70000030 | ||
| 1642 | #define DT_MIPS_AUX_DYNAMIC 0x70000031 | ||
| 1643 | |||
| 1644 | #define DT_MIPS_PLTGOT	 0x70000032 | ||
| 1645 | |||
| 1646 | #define DT_MIPS_RWPLT 0x70000034 | ||
| 1647 | #define DT_MIPS_RLD_MAP_REL 0x70000035 | ||
| 1648 | #define DT_MIPS_NUM	 0x36 | ||
| 1649 | |||
| 1650 | |||
| 1651 | |||
| 1652 | #define RHF_NONE		 0 | ||
| 1653 | #define RHF_QUICKSTART		 (1 << 0) | ||
| 1654 | #define RHF_NOTPOT		 (1 << 1) | ||
| 1655 | #define RHF_NO_LIBRARY_REPLACEMENT (1 << 2) | ||
| 1656 | #define RHF_NO_MOVE		 (1 << 3) | ||
| 1657 | #define RHF_SGI_ONLY		 (1 << 4) | ||
| 1658 | #define RHF_GUARANTEE_INIT	 (1 << 5) | ||
| 1659 | #define RHF_DELTA_C_PLUS_PLUS	 (1 << 6) | ||
| 1660 | #define RHF_GUARANTEE_START_INIT (1 << 7) | ||
| 1661 | #define RHF_PIXIE		 (1 << 8) | ||
| 1662 | #define RHF_DEFAULT_DELAY_LOAD	 (1 << 9) | ||
| 1663 | #define RHF_REQUICKSTART	 (1 << 10) | ||
| 1664 | #define RHF_REQUICKSTARTED	 (1 << 11) | ||
| 1665 | #define RHF_CORD		 (1 << 12) | ||
| 1666 | #define RHF_NO_UNRES_UNDEF	 (1 << 13) | ||
| 1667 | #define RHF_RLD_ORDER_SAFE	 (1 << 14) | ||
| 1668 | |||
| 1669 | |||
| 1670 | |||
| 1671 | typedef struct { | ||
| 1672 | Elf32_Word l_name; | ||
| 1673 | Elf32_Word l_time_stamp; | ||
| 1674 | Elf32_Word l_checksum; | ||
| 1675 | Elf32_Word l_version; | ||
| 1676 | Elf32_Word l_flags; | ||
| 1677 | } Elf32_Lib; | ||
| 1678 | |||
| 1679 | typedef struct { | ||
| 1680 | Elf64_Word l_name; | ||
| 1681 | Elf64_Word l_time_stamp; | ||
| 1682 | Elf64_Word l_checksum; | ||
| 1683 | Elf64_Word l_version; | ||
| 1684 | Elf64_Word l_flags; | ||
| 1685 | } Elf64_Lib; | ||
| 1686 | |||
| 1687 | |||
| 1688 | |||
| 1689 | |||
| 1690 | #define LL_NONE		 0 | ||
| 1691 | #define LL_EXACT_MATCH	 (1 << 0) | ||
| 1692 | #define LL_IGNORE_INT_VER (1 << 1) | ||
| 1693 | #define LL_REQUIRE_MINOR (1 << 2) | ||
| 1694 | #define LL_EXPORTS	 (1 << 3) | ||
| 1695 | #define LL_DELAY_LOAD	 (1 << 4) | ||
| 1696 | #define LL_DELTA	 (1 << 5) | ||
| 1697 | |||
| 1698 | |||
| 1699 | |||
| 1700 | typedef Elf32_Addr Elf32_Conflict; | ||
| 1701 | |||
| 1702 | typedef struct { | ||
| 1703 | Elf32_Half version; | ||
| 1704 | unsigned char isa_level; | ||
| 1705 | unsigned char isa_rev; | ||
| 1706 | unsigned char gpr_size; | ||
| 1707 | unsigned char cpr1_size; | ||
| 1708 | unsigned char cpr2_size; | ||
| 1709 | unsigned char fp_abi; | ||
| 1710 | Elf32_Word isa_ext; | ||
| 1711 | Elf32_Word ases; | ||
| 1712 | Elf32_Word flags1; | ||
| 1713 | Elf32_Word flags2; | ||
| 1714 | } Elf_MIPS_ABIFlags_v0; | ||
| 1715 | |||
| 1716 | #define MIPS_AFL_REG_NONE	0x00 | ||
| 1717 | #define MIPS_AFL_REG_32		0x01 | ||
| 1718 | #define MIPS_AFL_REG_64		0x02 | ||
| 1719 | #define MIPS_AFL_REG_128	0x03 | ||
| 1720 | |||
| 1721 | #define MIPS_AFL_ASE_DSP	0x00000001 | ||
| 1722 | #define MIPS_AFL_ASE_DSPR2	0x00000002 | ||
| 1723 | #define MIPS_AFL_ASE_EVA	0x00000004 | ||
| 1724 | #define MIPS_AFL_ASE_MCU	0x00000008 | ||
| 1725 | #define MIPS_AFL_ASE_MDMX	0x00000010 | ||
| 1726 | #define MIPS_AFL_ASE_MIPS3D	0x00000020 | ||
| 1727 | #define MIPS_AFL_ASE_MT		0x00000040 | ||
| 1728 | #define MIPS_AFL_ASE_SMARTMIPS	0x00000080 | ||
| 1729 | #define MIPS_AFL_ASE_VIRT	0x00000100 | ||
| 1730 | #define MIPS_AFL_ASE_MSA	0x00000200 | ||
| 1731 | #define MIPS_AFL_ASE_MIPS16	0x00000400 | ||
| 1732 | #define MIPS_AFL_ASE_MICROMIPS	0x00000800 | ||
| 1733 | #define MIPS_AFL_ASE_XPA	0x00001000 | ||
| 1734 | #define MIPS_AFL_ASE_MASK	0x00001fff | ||
| 1735 | |||
| 1736 | #define MIPS_AFL_EXT_XLR	 1 | ||
| 1737 | #define MIPS_AFL_EXT_OCTEON2	 2 | ||
| 1738 | #define MIPS_AFL_EXT_OCTEONP	 3 | ||
| 1739 | #define MIPS_AFL_EXT_LOONGSON_3A 4 | ||
| 1740 | #define MIPS_AFL_EXT_OCTEON	 5 | ||
| 1741 | #define MIPS_AFL_EXT_5900	 6 | ||
| 1742 | #define MIPS_AFL_EXT_4650	 7 | ||
| 1743 | #define MIPS_AFL_EXT_4010	 8 | ||
| 1744 | #define MIPS_AFL_EXT_4100	 9 | ||
| 1745 | #define MIPS_AFL_EXT_3900	 10 | ||
| 1746 | #define MIPS_AFL_EXT_10000	 11 | ||
| 1747 | #define MIPS_AFL_EXT_SB1	 12 | ||
| 1748 | #define MIPS_AFL_EXT_4111	 13 | ||
| 1749 | #define MIPS_AFL_EXT_4120	 14 | ||
| 1750 | #define MIPS_AFL_EXT_5400	 15 | ||
| 1751 | #define MIPS_AFL_EXT_5500	 16 | ||
| 1752 | #define MIPS_AFL_EXT_LOONGSON_2E 17 | ||
| 1753 | #define MIPS_AFL_EXT_LOONGSON_2F 18 | ||
| 1754 | |||
| 1755 | #define MIPS_AFL_FLAGS1_ODDSPREG 1 | ||
| 1756 | |||
| 1757 | enum | ||
| 1758 | { | ||
| 1759 | Val_GNU_MIPS_ABI_FP_ANY = 0, | ||
| 1760 | Val_GNU_MIPS_ABI_FP_DOUBLE = 1, | ||
| 1761 | Val_GNU_MIPS_ABI_FP_SINGLE = 2, | ||
| 1762 | Val_GNU_MIPS_ABI_FP_SOFT = 3, | ||
| 1763 | Val_GNU_MIPS_ABI_FP_OLD_64 = 4, | ||
| 1764 | Val_GNU_MIPS_ABI_FP_XX = 5, | ||
| 1765 | Val_GNU_MIPS_ABI_FP_64 = 6, | ||
| 1766 | Val_GNU_MIPS_ABI_FP_64A = 7, | ||
| 1767 | Val_GNU_MIPS_ABI_FP_MAX = 7 | ||
| 1768 | }; | ||
| 1769 | |||
| 1770 | |||
| 1771 | |||
| 1772 | |||
| 1773 | #define EF_PARISC_TRAPNIL	0x00010000 | ||
| 1774 | #define EF_PARISC_EXT		0x00020000 | ||
| 1775 | #define EF_PARISC_LSB		0x00040000 | ||
| 1776 | #define EF_PARISC_WIDE		0x00080000 | ||
| 1777 | #define EF_PARISC_NO_KABP	0x00100000 | ||
| 1778 | |||
| 1779 | #define EF_PARISC_LAZYSWAP	0x00400000 | ||
| 1780 | #define EF_PARISC_ARCH		0x0000ffff | ||
| 1781 | |||
| 1782 | |||
| 1783 | |||
| 1784 | #define EFA_PARISC_1_0		 0x020b | ||
| 1785 | #define EFA_PARISC_1_1		 0x0210 | ||
| 1786 | #define EFA_PARISC_2_0		 0x0214 | ||
| 1787 | |||
| 1788 | |||
| 1789 | |||
| 1790 | #define SHN_PARISC_ANSI_COMMON	0xff00 | ||
| 1791 | |||
| 1792 | #define SHN_PARISC_HUGE_COMMON	0xff01 | ||
| 1793 | |||
| 1794 | |||
| 1795 | |||
| 1796 | #define SHT_PARISC_EXT		0x70000000 | ||
| 1797 | #define SHT_PARISC_UNWIND	0x70000001 | ||
| 1798 | #define SHT_PARISC_DOC		0x70000002 | ||
| 1799 | |||
| 1800 | |||
| 1801 | |||
| 1802 | #define SHF_PARISC_SHORT	0x20000000 | ||
| 1803 | #define SHF_PARISC_HUGE		0x40000000 | ||
| 1804 | #define SHF_PARISC_SBP		0x80000000 | ||
| 1805 | |||
| 1806 | |||
| 1807 | |||
| 1808 | #define STT_PARISC_MILLICODE	13 | ||
| 1809 | |||
| 1810 | #define STT_HP_OPAQUE		(STT_LOOS + 0x1) | ||
| 1811 | #define STT_HP_STUB		(STT_LOOS + 0x2) | ||
| 1812 | |||
| 1813 | |||
| 1814 | |||
| 1815 | #define R_PARISC_NONE		0 | ||
| 1816 | #define R_PARISC_DIR32		1 | ||
| 1817 | #define R_PARISC_DIR21L		2 | ||
| 1818 | #define R_PARISC_DIR17R		3 | ||
| 1819 | #define R_PARISC_DIR17F		4 | ||
| 1820 | #define R_PARISC_DIR14R		6 | ||
| 1821 | #define R_PARISC_PCREL32	9 | ||
| 1822 | #define R_PARISC_PCREL21L	10 | ||
| 1823 | #define R_PARISC_PCREL17R	11 | ||
| 1824 | #define R_PARISC_PCREL17F	12 | ||
| 1825 | #define R_PARISC_PCREL14R	14 | ||
| 1826 | #define R_PARISC_DPREL21L	18 | ||
| 1827 | #define R_PARISC_DPREL14R	22 | ||
| 1828 | #define R_PARISC_GPREL21L	26 | ||
| 1829 | #define R_PARISC_GPREL14R	30 | ||
| 1830 | #define R_PARISC_LTOFF21L	34 | ||
| 1831 | #define R_PARISC_LTOFF14R	38 | ||
| 1832 | #define R_PARISC_SECREL32	41 | ||
| 1833 | #define R_PARISC_SEGBASE	48 | ||
| 1834 | #define R_PARISC_SEGREL32	49 | ||
| 1835 | #define R_PARISC_PLTOFF21L	50 | ||
| 1836 | #define R_PARISC_PLTOFF14R	54 | ||
| 1837 | #define R_PARISC_LTOFF_FPTR32	57 | ||
| 1838 | #define R_PARISC_LTOFF_FPTR21L	58 | ||
| 1839 | #define R_PARISC_LTOFF_FPTR14R	62 | ||
| 1840 | #define R_PARISC_FPTR64		64 | ||
| 1841 | #define R_PARISC_PLABEL32	65 | ||
| 1842 | #define R_PARISC_PLABEL21L	66 | ||
| 1843 | #define R_PARISC_PLABEL14R	70 | ||
| 1844 | #define R_PARISC_PCREL64	72 | ||
| 1845 | #define R_PARISC_PCREL22F	74 | ||
| 1846 | #define R_PARISC_PCREL14WR	75 | ||
| 1847 | #define R_PARISC_PCREL14DR	76 | ||
| 1848 | #define R_PARISC_PCREL16F	77 | ||
| 1849 | #define R_PARISC_PCREL16WF	78 | ||
| 1850 | #define R_PARISC_PCREL16DF	79 | ||
| 1851 | #define R_PARISC_DIR64		80 | ||
| 1852 | #define R_PARISC_DIR14WR	83 | ||
| 1853 | #define R_PARISC_DIR14DR	84 | ||
| 1854 | #define R_PARISC_DIR16F		85 | ||
| 1855 | #define R_PARISC_DIR16WF	86 | ||
| 1856 | #define R_PARISC_DIR16DF	87 | ||
| 1857 | #define R_PARISC_GPREL64	88 | ||
| 1858 | #define R_PARISC_GPREL14WR	91 | ||
| 1859 | #define R_PARISC_GPREL14DR	92 | ||
| 1860 | #define R_PARISC_GPREL16F	93 | ||
| 1861 | #define R_PARISC_GPREL16WF	94 | ||
| 1862 | #define R_PARISC_GPREL16DF	95 | ||
| 1863 | #define R_PARISC_LTOFF64	96 | ||
| 1864 | #define R_PARISC_LTOFF14WR	99 | ||
| 1865 | #define R_PARISC_LTOFF14DR	100 | ||
| 1866 | #define R_PARISC_LTOFF16F	101 | ||
| 1867 | #define R_PARISC_LTOFF16WF	102 | ||
| 1868 | #define R_PARISC_LTOFF16DF	103 | ||
| 1869 | #define R_PARISC_SECREL64	104 | ||
| 1870 | #define R_PARISC_SEGREL64	112 | ||
| 1871 | #define R_PARISC_PLTOFF14WR	115 | ||
| 1872 | #define R_PARISC_PLTOFF14DR	116 | ||
| 1873 | #define R_PARISC_PLTOFF16F	117 | ||
| 1874 | #define R_PARISC_PLTOFF16WF	118 | ||
| 1875 | #define R_PARISC_PLTOFF16DF	119 | ||
| 1876 | #define R_PARISC_LTOFF_FPTR64	120 | ||
| 1877 | #define R_PARISC_LTOFF_FPTR14WR	123 | ||
| 1878 | #define R_PARISC_LTOFF_FPTR14DR	124 | ||
| 1879 | #define R_PARISC_LTOFF_FPTR16F	125 | ||
| 1880 | #define R_PARISC_LTOFF_FPTR16WF	126 | ||
| 1881 | #define R_PARISC_LTOFF_FPTR16DF	127 | ||
| 1882 | #define R_PARISC_LORESERVE	128 | ||
| 1883 | #define R_PARISC_COPY		128 | ||
| 1884 | #define R_PARISC_IPLT		129 | ||
| 1885 | #define R_PARISC_EPLT		130 | ||
| 1886 | #define R_PARISC_TPREL32	153 | ||
| 1887 | #define R_PARISC_TPREL21L	154 | ||
| 1888 | #define R_PARISC_TPREL14R	158 | ||
| 1889 | #define R_PARISC_LTOFF_TP21L	162 | ||
| 1890 | #define R_PARISC_LTOFF_TP14R	166 | ||
| 1891 | #define R_PARISC_LTOFF_TP14F	167 | ||
| 1892 | #define R_PARISC_TPREL64	216 | ||
| 1893 | #define R_PARISC_TPREL14WR	219 | ||
| 1894 | #define R_PARISC_TPREL14DR	220 | ||
| 1895 | #define R_PARISC_TPREL16F	221 | ||
| 1896 | #define R_PARISC_TPREL16WF	222 | ||
| 1897 | #define R_PARISC_TPREL16DF	223 | ||
| 1898 | #define R_PARISC_LTOFF_TP64	224 | ||
| 1899 | #define R_PARISC_LTOFF_TP14WR	227 | ||
| 1900 | #define R_PARISC_LTOFF_TP14DR	228 | ||
| 1901 | #define R_PARISC_LTOFF_TP16F	229 | ||
| 1902 | #define R_PARISC_LTOFF_TP16WF	230 | ||
| 1903 | #define R_PARISC_LTOFF_TP16DF	231 | ||
| 1904 | #define R_PARISC_GNU_VTENTRY	232 | ||
| 1905 | #define R_PARISC_GNU_VTINHERIT	233 | ||
| 1906 | #define R_PARISC_TLS_GD21L	234 | ||
| 1907 | #define R_PARISC_TLS_GD14R	235 | ||
| 1908 | #define R_PARISC_TLS_GDCALL	236 | ||
| 1909 | #define R_PARISC_TLS_LDM21L	237 | ||
| 1910 | #define R_PARISC_TLS_LDM14R	238 | ||
| 1911 | #define R_PARISC_TLS_LDMCALL	239 | ||
| 1912 | #define R_PARISC_TLS_LDO21L	240 | ||
| 1913 | #define R_PARISC_TLS_LDO14R	241 | ||
| 1914 | #define R_PARISC_TLS_DTPMOD32	242 | ||
| 1915 | #define R_PARISC_TLS_DTPMOD64	243 | ||
| 1916 | #define R_PARISC_TLS_DTPOFF32	244 | ||
| 1917 | #define R_PARISC_TLS_DTPOFF64	245 | ||
| 1918 | #define R_PARISC_TLS_LE21L	R_PARISC_TPREL21L | ||
| 1919 | #define R_PARISC_TLS_LE14R	R_PARISC_TPREL14R | ||
| 1920 | #define R_PARISC_TLS_IE21L	R_PARISC_LTOFF_TP21L | ||
| 1921 | #define R_PARISC_TLS_IE14R	R_PARISC_LTOFF_TP14R | ||
| 1922 | #define R_PARISC_TLS_TPREL32	R_PARISC_TPREL32 | ||
| 1923 | #define R_PARISC_TLS_TPREL64	R_PARISC_TPREL64 | ||
| 1924 | #define R_PARISC_HIRESERVE	255 | ||
| 1925 | |||
| 1926 | |||
| 1927 | |||
| 1928 | #define PT_HP_TLS		(PT_LOOS + 0x0) | ||
| 1929 | #define PT_HP_CORE_NONE		(PT_LOOS + 0x1) | ||
| 1930 | #define PT_HP_CORE_VERSION	(PT_LOOS + 0x2) | ||
| 1931 | #define PT_HP_CORE_KERNEL	(PT_LOOS + 0x3) | ||
| 1932 | #define PT_HP_CORE_COMM		(PT_LOOS + 0x4) | ||
| 1933 | #define PT_HP_CORE_PROC		(PT_LOOS + 0x5) | ||
| 1934 | #define PT_HP_CORE_LOADABLE	(PT_LOOS + 0x6) | ||
| 1935 | #define PT_HP_CORE_STACK	(PT_LOOS + 0x7) | ||
| 1936 | #define PT_HP_CORE_SHM		(PT_LOOS + 0x8) | ||
| 1937 | #define PT_HP_CORE_MMF		(PT_LOOS + 0x9) | ||
| 1938 | #define PT_HP_PARALLEL		(PT_LOOS + 0x10) | ||
| 1939 | #define PT_HP_FASTBIND		(PT_LOOS + 0x11) | ||
| 1940 | #define PT_HP_OPT_ANNOT		(PT_LOOS + 0x12) | ||
| 1941 | #define PT_HP_HSL_ANNOT		(PT_LOOS + 0x13) | ||
| 1942 | #define PT_HP_STACK		(PT_LOOS + 0x14) | ||
| 1943 | |||
| 1944 | #define PT_PARISC_ARCHEXT	0x70000000 | ||
| 1945 | #define PT_PARISC_UNWIND	0x70000001 | ||
| 1946 | |||
| 1947 | |||
| 1948 | |||
| 1949 | #define PF_PARISC_SBP		0x08000000 | ||
| 1950 | |||
| 1951 | #define PF_HP_PAGE_SIZE		0x00100000 | ||
| 1952 | #define PF_HP_FAR_SHARED	0x00200000 | ||
| 1953 | #define PF_HP_NEAR_SHARED	0x00400000 | ||
| 1954 | #define PF_HP_CODE		0x01000000 | ||
| 1955 | #define PF_HP_MODIFY		0x02000000 | ||
| 1956 | #define PF_HP_LAZYSWAP		0x04000000 | ||
| 1957 | #define PF_HP_SBP		0x08000000 | ||
| 1958 | |||
| 1959 | |||
| 1960 | |||
| 1961 | |||
| 1962 | |||
| 1963 | |||
| 1964 | #define EF_ALPHA_32BIT		1 | ||
| 1965 | #define EF_ALPHA_CANRELAX	2 | ||
| 1966 | |||
| 1967 | |||
| 1968 | |||
| 1969 | |||
| 1970 | #define SHT_ALPHA_DEBUG		0x70000001 | ||
| 1971 | #define SHT_ALPHA_REGINFO	0x70000002 | ||
| 1972 | |||
| 1973 | |||
| 1974 | |||
| 1975 | #define SHF_ALPHA_GPREL		0x10000000 | ||
| 1976 | |||
| 1977 | |||
| 1978 | #define STO_ALPHA_NOPV		0x80 | ||
| 1979 | #define STO_ALPHA_STD_GPLOAD	0x88 | ||
| 1980 | |||
| 1981 | |||
| 1982 | |||
| 1983 | #define R_ALPHA_NONE		0 | ||
| 1984 | #define R_ALPHA_REFLONG		1 | ||
| 1985 | #define R_ALPHA_REFQUAD		2 | ||
| 1986 | #define R_ALPHA_GPREL32		3 | ||
| 1987 | #define R_ALPHA_LITERAL		4 | ||
| 1988 | #define R_ALPHA_LITUSE		5 | ||
| 1989 | #define R_ALPHA_GPDISP		6 | ||
| 1990 | #define R_ALPHA_BRADDR		7 | ||
| 1991 | #define R_ALPHA_HINT		8 | ||
| 1992 | #define R_ALPHA_SREL16		9 | ||
| 1993 | #define R_ALPHA_SREL32		10 | ||
| 1994 | #define R_ALPHA_SREL64		11 | ||
| 1995 | #define R_ALPHA_GPRELHIGH	17 | ||
| 1996 | #define R_ALPHA_GPRELLOW	18 | ||
| 1997 | #define R_ALPHA_GPREL16		19 | ||
| 1998 | #define R_ALPHA_COPY		24 | ||
| 1999 | #define R_ALPHA_GLOB_DAT	25 | ||
| 2000 | #define R_ALPHA_JMP_SLOT	26 | ||
| 2001 | #define R_ALPHA_RELATIVE	27 | ||
| 2002 | #define R_ALPHA_TLS_GD_HI	28 | ||
| 2003 | #define R_ALPHA_TLSGD		29 | ||
| 2004 | #define R_ALPHA_TLS_LDM		30 | ||
| 2005 | #define R_ALPHA_DTPMOD64	31 | ||
| 2006 | #define R_ALPHA_GOTDTPREL	32 | ||
| 2007 | #define R_ALPHA_DTPREL64	33 | ||
| 2008 | #define R_ALPHA_DTPRELHI	34 | ||
| 2009 | #define R_ALPHA_DTPRELLO	35 | ||
| 2010 | #define R_ALPHA_DTPREL16	36 | ||
| 2011 | #define R_ALPHA_GOTTPREL	37 | ||
| 2012 | #define R_ALPHA_TPREL64		38 | ||
| 2013 | #define R_ALPHA_TPRELHI		39 | ||
| 2014 | #define R_ALPHA_TPRELLO		40 | ||
| 2015 | #define R_ALPHA_TPREL16		41 | ||
| 2016 | |||
| 2017 | #define R_ALPHA_NUM		46 | ||
| 2018 | |||
| 2019 | |||
| 2020 | #define LITUSE_ALPHA_ADDR	0 | ||
| 2021 | #define LITUSE_ALPHA_BASE	1 | ||
| 2022 | #define LITUSE_ALPHA_BYTOFF	2 | ||
| 2023 | #define LITUSE_ALPHA_JSR	3 | ||
| 2024 | #define LITUSE_ALPHA_TLS_GD	4 | ||
| 2025 | #define LITUSE_ALPHA_TLS_LDM	5 | ||
| 2026 | |||
| 2027 | |||
| 2028 | #define DT_ALPHA_PLTRO		(DT_LOPROC + 0) | ||
| 2029 | #define DT_ALPHA_NUM		1 | ||
| 2030 | |||
| 2031 | |||
| 2032 | |||
| 2033 | |||
| 2034 | #define EF_PPC_EMB		0x80000000 | ||
| 2035 | |||
| 2036 | |||
| 2037 | #define EF_PPC_RELOCATABLE	0x00010000 | ||
| 2038 | #define EF_PPC_RELOCATABLE_LIB	0x00008000 | ||
| 2039 | |||
| 2040 | |||
| 2041 | |||
| 2042 | #define R_PPC_NONE		0 | ||
| 2043 | #define R_PPC_ADDR32		1 | ||
| 2044 | #define R_PPC_ADDR24		2 | ||
| 2045 | #define R_PPC_ADDR16		3 | ||
| 2046 | #define R_PPC_ADDR16_LO		4 | ||
| 2047 | #define R_PPC_ADDR16_HI		5 | ||
| 2048 | #define R_PPC_ADDR16_HA		6 | ||
| 2049 | #define R_PPC_ADDR14		7 | ||
| 2050 | #define R_PPC_ADDR14_BRTAKEN	8 | ||
| 2051 | #define R_PPC_ADDR14_BRNTAKEN	9 | ||
| 2052 | #define R_PPC_REL24		10 | ||
| 2053 | #define R_PPC_REL14		11 | ||
| 2054 | #define R_PPC_REL14_BRTAKEN	12 | ||
| 2055 | #define R_PPC_REL14_BRNTAKEN	13 | ||
| 2056 | #define R_PPC_GOT16		14 | ||
| 2057 | #define R_PPC_GOT16_LO		15 | ||
| 2058 | #define R_PPC_GOT16_HI		16 | ||
| 2059 | #define R_PPC_GOT16_HA		17 | ||
| 2060 | #define R_PPC_PLTREL24		18 | ||
| 2061 | #define R_PPC_COPY		19 | ||
| 2062 | #define R_PPC_GLOB_DAT		20 | ||
| 2063 | #define R_PPC_JMP_SLOT		21 | ||
| 2064 | #define R_PPC_RELATIVE		22 | ||
| 2065 | #define R_PPC_LOCAL24PC		23 | ||
| 2066 | #define R_PPC_UADDR32		24 | ||
| 2067 | #define R_PPC_UADDR16		25 | ||
| 2068 | #define R_PPC_REL32		26 | ||
| 2069 | #define R_PPC_PLT32		27 | ||
| 2070 | #define R_PPC_PLTREL32		28 | ||
| 2071 | #define R_PPC_PLT16_LO		29 | ||
| 2072 | #define R_PPC_PLT16_HI		30 | ||
| 2073 | #define R_PPC_PLT16_HA		31 | ||
| 2074 | #define R_PPC_SDAREL16		32 | ||
| 2075 | #define R_PPC_SECTOFF		33 | ||
| 2076 | #define R_PPC_SECTOFF_LO	34 | ||
| 2077 | #define R_PPC_SECTOFF_HI	35 | ||
| 2078 | #define R_PPC_SECTOFF_HA	36 | ||
| 2079 | |||
| 2080 | |||
| 2081 | #define R_PPC_TLS		67 | ||
| 2082 | #define R_PPC_DTPMOD32		68 | ||
| 2083 | #define R_PPC_TPREL16		69 | ||
| 2084 | #define R_PPC_TPREL16_LO	70 | ||
| 2085 | #define R_PPC_TPREL16_HI	71 | ||
| 2086 | #define R_PPC_TPREL16_HA	72 | ||
| 2087 | #define R_PPC_TPREL32		73 | ||
| 2088 | #define R_PPC_DTPREL16		74 | ||
| 2089 | #define R_PPC_DTPREL16_LO	75 | ||
| 2090 | #define R_PPC_DTPREL16_HI	76 | ||
| 2091 | #define R_PPC_DTPREL16_HA	77 | ||
| 2092 | #define R_PPC_DTPREL32		78 | ||
| 2093 | #define R_PPC_GOT_TLSGD16	79 | ||
| 2094 | #define R_PPC_GOT_TLSGD16_LO	80 | ||
| 2095 | #define R_PPC_GOT_TLSGD16_HI	81 | ||
| 2096 | #define R_PPC_GOT_TLSGD16_HA	82 | ||
| 2097 | #define R_PPC_GOT_TLSLD16	83 | ||
| 2098 | #define R_PPC_GOT_TLSLD16_LO	84 | ||
| 2099 | #define R_PPC_GOT_TLSLD16_HI	85 | ||
| 2100 | #define R_PPC_GOT_TLSLD16_HA	86 | ||
| 2101 | #define R_PPC_GOT_TPREL16	87 | ||
| 2102 | #define R_PPC_GOT_TPREL16_LO	88 | ||
| 2103 | #define R_PPC_GOT_TPREL16_HI	89 | ||
| 2104 | #define R_PPC_GOT_TPREL16_HA	90 | ||
| 2105 | #define R_PPC_GOT_DTPREL16	91 | ||
| 2106 | #define R_PPC_GOT_DTPREL16_LO	92 | ||
| 2107 | #define R_PPC_GOT_DTPREL16_HI	93 | ||
| 2108 | #define R_PPC_GOT_DTPREL16_HA	94 | ||
| 2109 | #define R_PPC_TLSGD		95 | ||
| 2110 | #define R_PPC_TLSLD		96 | ||
| 2111 | |||
| 2112 | |||
| 2113 | #define R_PPC_EMB_NADDR32	101 | ||
| 2114 | #define R_PPC_EMB_NADDR16	102 | ||
| 2115 | #define R_PPC_EMB_NADDR16_LO	103 | ||
| 2116 | #define R_PPC_EMB_NADDR16_HI	104 | ||
| 2117 | #define R_PPC_EMB_NADDR16_HA	105 | ||
| 2118 | #define R_PPC_EMB_SDAI16	106 | ||
| 2119 | #define R_PPC_EMB_SDA2I16	107 | ||
| 2120 | #define R_PPC_EMB_SDA2REL	108 | ||
| 2121 | #define R_PPC_EMB_SDA21		109 | ||
| 2122 | #define R_PPC_EMB_MRKREF	110 | ||
| 2123 | #define R_PPC_EMB_RELSEC16	111 | ||
| 2124 | #define R_PPC_EMB_RELST_LO	112 | ||
| 2125 | #define R_PPC_EMB_RELST_HI	113 | ||
| 2126 | #define R_PPC_EMB_RELST_HA	114 | ||
| 2127 | #define R_PPC_EMB_BIT_FLD	115 | ||
| 2128 | #define R_PPC_EMB_RELSDA	116 | ||
| 2129 | |||
| 2130 | |||
| 2131 | #define R_PPC_DIAB_SDA21_LO	180 | ||
| 2132 | #define R_PPC_DIAB_SDA21_HI	181 | ||
| 2133 | #define R_PPC_DIAB_SDA21_HA	182 | ||
| 2134 | #define R_PPC_DIAB_RELSDA_LO	183 | ||
| 2135 | #define R_PPC_DIAB_RELSDA_HI	184 | ||
| 2136 | #define R_PPC_DIAB_RELSDA_HA	185 | ||
| 2137 | |||
| 2138 | |||
| 2139 | #define R_PPC_IRELATIVE		248 | ||
| 2140 | |||
| 2141 | |||
| 2142 | #define R_PPC_REL16		249 | ||
| 2143 | #define R_PPC_REL16_LO		250 | ||
| 2144 | #define R_PPC_REL16_HI		251 | ||
| 2145 | #define R_PPC_REL16_HA		252 | ||
| 2146 | |||
| 2147 | |||
| 2148 | |||
| 2149 | #define R_PPC_TOC16		255 | ||
| 2150 | |||
| 2151 | |||
| 2152 | #define DT_PPC_GOT		(DT_LOPROC + 0) | ||
| 2153 | #define DT_PPC_OPT		(DT_LOPROC + 1) | ||
| 2154 | #define DT_PPC_NUM		2 | ||
| 2155 | |||
| 2156 | #define PPC_OPT_TLS		1 | ||
| 2157 | |||
| 2158 | |||
| 2159 | #define R_PPC64_NONE		R_PPC_NONE | ||
| 2160 | #define R_PPC64_ADDR32		R_PPC_ADDR32 | ||
| 2161 | #define R_PPC64_ADDR24		R_PPC_ADDR24 | ||
| 2162 | #define R_PPC64_ADDR16		R_PPC_ADDR16 | ||
| 2163 | #define R_PPC64_ADDR16_LO	R_PPC_ADDR16_LO | ||
| 2164 | #define R_PPC64_ADDR16_HI	R_PPC_ADDR16_HI | ||
| 2165 | #define R_PPC64_ADDR16_HA	R_PPC_ADDR16_HA | ||
| 2166 | #define R_PPC64_ADDR14		R_PPC_ADDR14 | ||
| 2167 | #define R_PPC64_ADDR14_BRTAKEN	R_PPC_ADDR14_BRTAKEN | ||
| 2168 | #define R_PPC64_ADDR14_BRNTAKEN	R_PPC_ADDR14_BRNTAKEN | ||
| 2169 | #define R_PPC64_REL24		R_PPC_REL24 | ||
| 2170 | #define R_PPC64_REL14		R_PPC_REL14 | ||
| 2171 | #define R_PPC64_REL14_BRTAKEN	R_PPC_REL14_BRTAKEN | ||
| 2172 | #define R_PPC64_REL14_BRNTAKEN	R_PPC_REL14_BRNTAKEN | ||
| 2173 | #define R_PPC64_GOT16		R_PPC_GOT16 | ||
| 2174 | #define R_PPC64_GOT16_LO	R_PPC_GOT16_LO | ||
| 2175 | #define R_PPC64_GOT16_HI	R_PPC_GOT16_HI | ||
| 2176 | #define R_PPC64_GOT16_HA	R_PPC_GOT16_HA | ||
| 2177 | |||
| 2178 | #define R_PPC64_COPY		R_PPC_COPY | ||
| 2179 | #define R_PPC64_GLOB_DAT	R_PPC_GLOB_DAT | ||
| 2180 | #define R_PPC64_JMP_SLOT	R_PPC_JMP_SLOT | ||
| 2181 | #define R_PPC64_RELATIVE	R_PPC_RELATIVE | ||
| 2182 | |||
| 2183 | #define R_PPC64_UADDR32		R_PPC_UADDR32 | ||
| 2184 | #define R_PPC64_UADDR16		R_PPC_UADDR16 | ||
| 2185 | #define R_PPC64_REL32		R_PPC_REL32 | ||
| 2186 | #define R_PPC64_PLT32		R_PPC_PLT32 | ||
| 2187 | #define R_PPC64_PLTREL32	R_PPC_PLTREL32 | ||
| 2188 | #define R_PPC64_PLT16_LO	R_PPC_PLT16_LO | ||
| 2189 | #define R_PPC64_PLT16_HI	R_PPC_PLT16_HI | ||
| 2190 | #define R_PPC64_PLT16_HA	R_PPC_PLT16_HA | ||
| 2191 | |||
| 2192 | #define R_PPC64_SECTOFF		R_PPC_SECTOFF | ||
| 2193 | #define R_PPC64_SECTOFF_LO	R_PPC_SECTOFF_LO | ||
| 2194 | #define R_PPC64_SECTOFF_HI	R_PPC_SECTOFF_HI | ||
| 2195 | #define R_PPC64_SECTOFF_HA	R_PPC_SECTOFF_HA | ||
| 2196 | #define R_PPC64_ADDR30		37 | ||
| 2197 | #define R_PPC64_ADDR64		38 | ||
| 2198 | #define R_PPC64_ADDR16_HIGHER	39 | ||
| 2199 | #define R_PPC64_ADDR16_HIGHERA	40 | ||
| 2200 | #define R_PPC64_ADDR16_HIGHEST	41 | ||
| 2201 | #define R_PPC64_ADDR16_HIGHESTA	42 | ||
| 2202 | #define R_PPC64_UADDR64		43 | ||
| 2203 | #define R_PPC64_REL64		44 | ||
| 2204 | #define R_PPC64_PLT64		45 | ||
| 2205 | #define R_PPC64_PLTREL64	46 | ||
| 2206 | #define R_PPC64_TOC16		47 | ||
| 2207 | #define R_PPC64_TOC16_LO	48 | ||
| 2208 | #define R_PPC64_TOC16_HI	49 | ||
| 2209 | #define R_PPC64_TOC16_HA	50 | ||
| 2210 | #define R_PPC64_TOC		51 | ||
| 2211 | #define R_PPC64_PLTGOT16	52 | ||
| 2212 | #define R_PPC64_PLTGOT16_LO	53 | ||
| 2213 | #define R_PPC64_PLTGOT16_HI	54 | ||
| 2214 | #define R_PPC64_PLTGOT16_HA	55 | ||
| 2215 | |||
| 2216 | #define R_PPC64_ADDR16_DS	56 | ||
| 2217 | #define R_PPC64_ADDR16_LO_DS	57 | ||
| 2218 | #define R_PPC64_GOT16_DS	58 | ||
| 2219 | #define R_PPC64_GOT16_LO_DS	59 | ||
| 2220 | #define R_PPC64_PLT16_LO_DS	60 | ||
| 2221 | #define R_PPC64_SECTOFF_DS	61 | ||
| 2222 | #define R_PPC64_SECTOFF_LO_DS	62 | ||
| 2223 | #define R_PPC64_TOC16_DS	63 | ||
| 2224 | #define R_PPC64_TOC16_LO_DS	64 | ||
| 2225 | #define R_PPC64_PLTGOT16_DS	65 | ||
| 2226 | #define R_PPC64_PLTGOT16_LO_DS	66 | ||
| 2227 | |||
| 2228 | |||
| 2229 | #define R_PPC64_TLS		67 | ||
| 2230 | #define R_PPC64_DTPMOD64	68 | ||
| 2231 | #define R_PPC64_TPREL16		69 | ||
| 2232 | #define R_PPC64_TPREL16_LO	70 | ||
| 2233 | #define R_PPC64_TPREL16_HI	71 | ||
| 2234 | #define R_PPC64_TPREL16_HA	72 | ||
| 2235 | #define R_PPC64_TPREL64		73 | ||
| 2236 | #define R_PPC64_DTPREL16	74 | ||
| 2237 | #define R_PPC64_DTPREL16_LO	75 | ||
| 2238 | #define R_PPC64_DTPREL16_HI	76 | ||
| 2239 | #define R_PPC64_DTPREL16_HA	77 | ||
| 2240 | #define R_PPC64_DTPREL64	78 | ||
| 2241 | #define R_PPC64_GOT_TLSGD16	79 | ||
| 2242 | #define R_PPC64_GOT_TLSGD16_LO	80 | ||
| 2243 | #define R_PPC64_GOT_TLSGD16_HI	81 | ||
| 2244 | #define R_PPC64_GOT_TLSGD16_HA	82 | ||
| 2245 | #define R_PPC64_GOT_TLSLD16	83 | ||
| 2246 | #define R_PPC64_GOT_TLSLD16_LO	84 | ||
| 2247 | #define R_PPC64_GOT_TLSLD16_HI	85 | ||
| 2248 | #define R_PPC64_GOT_TLSLD16_HA	86 | ||
| 2249 | #define R_PPC64_GOT_TPREL16_DS	87 | ||
| 2250 | #define R_PPC64_GOT_TPREL16_LO_DS 88 | ||
| 2251 | #define R_PPC64_GOT_TPREL16_HI	89 | ||
| 2252 | #define R_PPC64_GOT_TPREL16_HA	90 | ||
| 2253 | #define R_PPC64_GOT_DTPREL16_DS	91 | ||
| 2254 | #define R_PPC64_GOT_DTPREL16_LO_DS 92 | ||
| 2255 | #define R_PPC64_GOT_DTPREL16_HI	93 | ||
| 2256 | #define R_PPC64_GOT_DTPREL16_HA	94 | ||
| 2257 | #define R_PPC64_TPREL16_DS	95 | ||
| 2258 | #define R_PPC64_TPREL16_LO_DS	96 | ||
| 2259 | #define R_PPC64_TPREL16_HIGHER	97 | ||
| 2260 | #define R_PPC64_TPREL16_HIGHERA	98 | ||
| 2261 | #define R_PPC64_TPREL16_HIGHEST	99 | ||
| 2262 | #define R_PPC64_TPREL16_HIGHESTA 100 | ||
| 2263 | #define R_PPC64_DTPREL16_DS	101 | ||
| 2264 | #define R_PPC64_DTPREL16_LO_DS	102 | ||
| 2265 | #define R_PPC64_DTPREL16_HIGHER	103 | ||
| 2266 | #define R_PPC64_DTPREL16_HIGHERA 104 | ||
| 2267 | #define R_PPC64_DTPREL16_HIGHEST 105 | ||
| 2268 | #define R_PPC64_DTPREL16_HIGHESTA 106 | ||
| 2269 | #define R_PPC64_TLSGD		107 | ||
| 2270 | #define R_PPC64_TLSLD		108 | ||
| 2271 | #define R_PPC64_TOCSAVE		109 | ||
| 2272 | #define R_PPC64_ADDR16_HIGH	110 | ||
| 2273 | #define R_PPC64_ADDR16_HIGHA	111 | ||
| 2274 | #define R_PPC64_TPREL16_HIGH	112 | ||
| 2275 | #define R_PPC64_TPREL16_HIGHA	113 | ||
| 2276 | #define R_PPC64_DTPREL16_HIGH	114 | ||
| 2277 | #define R_PPC64_DTPREL16_HIGHA	115 | ||
| 2278 | |||
| 2279 | |||
| 2280 | #define R_PPC64_JMP_IREL	247 | ||
| 2281 | #define R_PPC64_IRELATIVE	248 | ||
| 2282 | #define R_PPC64_REL16		249 | ||
| 2283 | #define R_PPC64_REL16_LO	250 | ||
| 2284 | #define R_PPC64_REL16_HI	251 | ||
| 2285 | #define R_PPC64_REL16_HA	252 | ||
| 2286 | |||
| 2287 | #define EF_PPC64_ABI	3 | ||
| 2288 | |||
| 2289 | #define DT_PPC64_GLINK (DT_LOPROC + 0) | ||
| 2290 | #define DT_PPC64_OPD	(DT_LOPROC + 1) | ||
| 2291 | #define DT_PPC64_OPDSZ	(DT_LOPROC + 2) | ||
| 2292 | #define DT_PPC64_OPT	(DT_LOPROC + 3) | ||
| 2293 | #define DT_PPC64_NUM	4 | ||
| 2294 | |||
| 2295 | #define PPC64_OPT_TLS		1 | ||
| 2296 | #define PPC64_OPT_MULTI_TOC	2 | ||
| 2297 | #define PPC64_OPT_LOCALENTRY	4 | ||
| 2298 | |||
| 2299 | #define STO_PPC64_LOCAL_BIT	5 | ||
| 2300 | #define STO_PPC64_LOCAL_MASK	0xe0 | ||
| 2301 | #define PPC64_LOCAL_ENTRY_OFFSET(x) (1 << (((x)&0xe0)>>5) & 0xfc) | ||
| 2302 | |||
| 2303 | |||
| 2304 | #define EF_ARM_RELEXEC		0x01 | ||
| 2305 | #define EF_ARM_HASENTRY		0x02 | ||
| 2306 | #define EF_ARM_INTERWORK	0x04 | ||
| 2307 | #define EF_ARM_APCS_26		0x08 | ||
| 2308 | #define EF_ARM_APCS_FLOAT	0x10 | ||
| 2309 | #define EF_ARM_PIC		0x20 | ||
| 2310 | #define EF_ARM_ALIGN8		0x40 | ||
| 2311 | #define EF_ARM_NEW_ABI		0x80 | ||
| 2312 | #define EF_ARM_OLD_ABI		0x100 | ||
| 2313 | #define EF_ARM_SOFT_FLOAT	0x200 | ||
| 2314 | #define EF_ARM_VFP_FLOAT	0x400 | ||
| 2315 | #define EF_ARM_MAVERICK_FLOAT	0x800 | ||
| 2316 | |||
| 2317 | #define EF_ARM_ABI_FLOAT_SOFT	0x200 | ||
| 2318 | #define EF_ARM_ABI_FLOAT_HARD	0x400 | ||
| 2319 | |||
| 2320 | |||
| 2321 | #define EF_ARM_SYMSARESORTED	0x04 | ||
| 2322 | #define EF_ARM_DYNSYMSUSESEGIDX	0x08 | ||
| 2323 | #define EF_ARM_MAPSYMSFIRST	0x10 | ||
| 2324 | #define EF_ARM_EABIMASK		0XFF000000 | ||
| 2325 | |||
| 2326 | |||
| 2327 | #define EF_ARM_BE8	 0x00800000 | ||
| 2328 | #define EF_ARM_LE8	 0x00400000 | ||
| 2329 | |||
| 2330 | #define EF_ARM_EABI_VERSION(flags)	((flags) & EF_ARM_EABIMASK) | ||
| 2331 | #define EF_ARM_EABI_UNKNOWN	0x00000000 | ||
| 2332 | #define EF_ARM_EABI_VER1	0x01000000 | ||
| 2333 | #define EF_ARM_EABI_VER2	0x02000000 | ||
| 2334 | #define EF_ARM_EABI_VER3	0x03000000 | ||
| 2335 | #define EF_ARM_EABI_VER4	0x04000000 | ||
| 2336 | #define EF_ARM_EABI_VER5	0x05000000 | ||
| 2337 | |||
| 2338 | |||
| 2339 | #define STT_ARM_TFUNC		STT_LOPROC | ||
| 2340 | #define STT_ARM_16BIT		STT_HIPROC | ||
| 2341 | |||
| 2342 | |||
| 2343 | #define SHF_ARM_ENTRYSECT	0x10000000 | ||
| 2344 | #define SHF_ARM_COMDEF		0x80000000 | ||
| 2345 | |||
| 2346 | |||
| 2347 | |||
| 2348 | #define PF_ARM_SB		0x10000000 | ||
| 2349 | |||
| 2350 | #define PF_ARM_PI		0x20000000 | ||
| 2351 | #define PF_ARM_ABS		0x40000000 | ||
| 2352 | |||
| 2353 | |||
| 2354 | #define PT_ARM_EXIDX		(PT_LOPROC + 1) | ||
| 2355 | |||
| 2356 | |||
| 2357 | #define SHT_ARM_EXIDX		(SHT_LOPROC + 1) | ||
| 2358 | #define SHT_ARM_PREEMPTMAP	(SHT_LOPROC + 2) | ||
| 2359 | #define SHT_ARM_ATTRIBUTES	(SHT_LOPROC + 3) | ||
| 2360 | |||
| 2361 | #define R_AARCH64_NONE 0 | ||
| 2362 | #define R_AARCH64_P32_ABS32	1 | ||
| 2363 | #define R_AARCH64_P32_COPY	180 | ||
| 2364 | #define R_AARCH64_P32_GLOB_DAT	181 | ||
| 2365 | #define R_AARCH64_P32_JUMP_SLOT	182 | ||
| 2366 | #define R_AARCH64_P32_RELATIVE	183 | ||
| 2367 | #define R_AARCH64_P32_TLS_DTPMOD 184 | ||
| 2368 | #define R_AARCH64_P32_TLS_DTPREL 185 | ||
| 2369 | #define R_AARCH64_P32_TLS_TPREL	186 | ||
| 2370 | #define R_AARCH64_P32_TLSDESC	187 | ||
| 2371 | #define R_AARCH64_P32_IRELATIVE	188 | ||
| 2372 | #define R_AARCH64_ABS64 257 | ||
| 2373 | #define R_AARCH64_ABS32 258 | ||
| 2374 | #define R_AARCH64_ABS16		259 | ||
| 2375 | #define R_AARCH64_PREL64	260 | ||
| 2376 | #define R_AARCH64_PREL32	261 | ||
| 2377 | #define R_AARCH64_PREL16	262 | ||
| 2378 | #define R_AARCH64_MOVW_UABS_G0	263 | ||
| 2379 | #define R_AARCH64_MOVW_UABS_G0_NC 264 | ||
| 2380 | #define R_AARCH64_MOVW_UABS_G1	265 | ||
| 2381 | #define R_AARCH64_MOVW_UABS_G1_NC 266 | ||
| 2382 | #define R_AARCH64_MOVW_UABS_G2	267 | ||
| 2383 | #define R_AARCH64_MOVW_UABS_G2_NC 268 | ||
| 2384 | #define R_AARCH64_MOVW_UABS_G3	269 | ||
| 2385 | #define R_AARCH64_MOVW_SABS_G0	270 | ||
| 2386 | #define R_AARCH64_MOVW_SABS_G1	271 | ||
| 2387 | #define R_AARCH64_MOVW_SABS_G2	272 | ||
| 2388 | #define R_AARCH64_LD_PREL_LO19	273 | ||
| 2389 | #define R_AARCH64_ADR_PREL_LO21	274 | ||
| 2390 | #define R_AARCH64_ADR_PREL_PG_HI21 275 | ||
| 2391 | #define R_AARCH64_ADR_PREL_PG_HI21_NC 276 | ||
| 2392 | #define R_AARCH64_ADD_ABS_LO12_NC 277 | ||
| 2393 | #define R_AARCH64_LDST8_ABS_LO12_NC 278 | ||
| 2394 | #define R_AARCH64_TSTBR14	279 | ||
| 2395 | #define R_AARCH64_CONDBR19	280 | ||
| 2396 | #define R_AARCH64_JUMP26	282 | ||
| 2397 | #define R_AARCH64_CALL26	283 | ||
| 2398 | #define R_AARCH64_LDST16_ABS_LO12_NC 284 | ||
| 2399 | #define R_AARCH64_LDST32_ABS_LO12_NC 285 | ||
| 2400 | #define R_AARCH64_LDST64_ABS_LO12_NC 286 | ||
| 2401 | #define R_AARCH64_MOVW_PREL_G0	287 | ||
| 2402 | #define R_AARCH64_MOVW_PREL_G0_NC 288 | ||
| 2403 | #define R_AARCH64_MOVW_PREL_G1	289 | ||
| 2404 | #define R_AARCH64_MOVW_PREL_G1_NC 290 | ||
| 2405 | #define R_AARCH64_MOVW_PREL_G2	291 | ||
| 2406 | #define R_AARCH64_MOVW_PREL_G2_NC 292 | ||
| 2407 | #define R_AARCH64_MOVW_PREL_G3	293 | ||
| 2408 | #define R_AARCH64_LDST128_ABS_LO12_NC 299 | ||
| 2409 | #define R_AARCH64_MOVW_GOTOFF_G0 300 | ||
| 2410 | #define R_AARCH64_MOVW_GOTOFF_G0_NC 301 | ||
| 2411 | #define R_AARCH64_MOVW_GOTOFF_G1 302 | ||
| 2412 | #define R_AARCH64_MOVW_GOTOFF_G1_NC 303 | ||
| 2413 | #define R_AARCH64_MOVW_GOTOFF_G2 304 | ||
| 2414 | #define R_AARCH64_MOVW_GOTOFF_G2_NC 305 | ||
| 2415 | #define R_AARCH64_MOVW_GOTOFF_G3 306 | ||
| 2416 | #define R_AARCH64_GOTREL64	307 | ||
| 2417 | #define R_AARCH64_GOTREL32	308 | ||
| 2418 | #define R_AARCH64_GOT_LD_PREL19	309 | ||
| 2419 | #define R_AARCH64_LD64_GOTOFF_LO15 310 | ||
| 2420 | #define R_AARCH64_ADR_GOT_PAGE	311 | ||
| 2421 | #define R_AARCH64_LD64_GOT_LO12_NC 312 | ||
| 2422 | #define R_AARCH64_LD64_GOTPAGE_LO15 313 | ||
| 2423 | #define R_AARCH64_TLSGD_ADR_PREL21 512 | ||
| 2424 | #define R_AARCH64_TLSGD_ADR_PAGE21 513 | ||
| 2425 | #define R_AARCH64_TLSGD_ADD_LO12_NC 514 | ||
| 2426 | #define R_AARCH64_TLSGD_MOVW_G1	515 | ||
| 2427 | #define R_AARCH64_TLSGD_MOVW_G0_NC 516 | ||
| 2428 | #define R_AARCH64_TLSLD_ADR_PREL21 517 | ||
| 2429 | #define R_AARCH64_TLSLD_ADR_PAGE21 518 | ||
| 2430 | #define R_AARCH64_TLSLD_ADD_LO12_NC 519 | ||
| 2431 | #define R_AARCH64_TLSLD_MOVW_G1	520 | ||
| 2432 | #define R_AARCH64_TLSLD_MOVW_G0_NC 521 | ||
| 2433 | #define R_AARCH64_TLSLD_LD_PREL19 522 | ||
| 2434 | #define R_AARCH64_TLSLD_MOVW_DTPREL_G2 523 | ||
| 2435 | #define R_AARCH64_TLSLD_MOVW_DTPREL_G1 524 | ||
| 2436 | #define R_AARCH64_TLSLD_MOVW_DTPREL_G1_NC 525 | ||
| 2437 | #define R_AARCH64_TLSLD_MOVW_DTPREL_G0 526 | ||
| 2438 | #define R_AARCH64_TLSLD_MOVW_DTPREL_G0_NC 527 | ||
| 2439 | #define R_AARCH64_TLSLD_ADD_DTPREL_HI12 528 | ||
| 2440 | #define R_AARCH64_TLSLD_ADD_DTPREL_LO12 529 | ||
| 2441 | #define R_AARCH64_TLSLD_ADD_DTPREL_LO12_NC 530 | ||
| 2442 | #define R_AARCH64_TLSLD_LDST8_DTPREL_LO12 531 | ||
| 2443 | #define R_AARCH64_TLSLD_LDST8_DTPREL_LO12_NC 532 | ||
| 2444 | #define R_AARCH64_TLSLD_LDST16_DTPREL_LO12 533 | ||
| 2445 | #define R_AARCH64_TLSLD_LDST16_DTPREL_LO12_NC 534 | ||
| 2446 | #define R_AARCH64_TLSLD_LDST32_DTPREL_LO12 535 | ||
| 2447 | #define R_AARCH64_TLSLD_LDST32_DTPREL_LO12_NC 536 | ||
| 2448 | #define R_AARCH64_TLSLD_LDST64_DTPREL_LO12 537 | ||
| 2449 | #define R_AARCH64_TLSLD_LDST64_DTPREL_LO12_NC 538 | ||
| 2450 | #define R_AARCH64_TLSIE_MOVW_GOTTPREL_G1 539 | ||
| 2451 | #define R_AARCH64_TLSIE_MOVW_GOTTPREL_G0_NC 540 | ||
| 2452 | #define R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21 541 | ||
| 2453 | #define R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC 542 | ||
| 2454 | #define R_AARCH64_TLSIE_LD_GOTTPREL_PREL19 543 | ||
| 2455 | #define R_AARCH64_TLSLE_MOVW_TPREL_G2 544 | ||
| 2456 | #define R_AARCH64_TLSLE_MOVW_TPREL_G1 545 | ||
| 2457 | #define R_AARCH64_TLSLE_MOVW_TPREL_G1_NC 546 | ||
| 2458 | #define R_AARCH64_TLSLE_MOVW_TPREL_G0 547 | ||
| 2459 | #define R_AARCH64_TLSLE_MOVW_TPREL_G0_NC 548 | ||
| 2460 | #define R_AARCH64_TLSLE_ADD_TPREL_HI12 549 | ||
| 2461 | #define R_AARCH64_TLSLE_ADD_TPREL_LO12 550 | ||
| 2462 | #define R_AARCH64_TLSLE_ADD_TPREL_LO12_NC 551 | ||
| 2463 | #define R_AARCH64_TLSLE_LDST8_TPREL_LO12 552 | ||
| 2464 | #define R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC 553 | ||
| 2465 | #define R_AARCH64_TLSLE_LDST16_TPREL_LO12 554 | ||
| 2466 | #define R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC 555 | ||
| 2467 | #define R_AARCH64_TLSLE_LDST32_TPREL_LO12 556 | ||
| 2468 | #define R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC 557 | ||
| 2469 | #define R_AARCH64_TLSLE_LDST64_TPREL_LO12 558 | ||
| 2470 | #define R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC 559 | ||
| 2471 | #define R_AARCH64_TLSDESC_LD_PREL19 560 | ||
| 2472 | #define R_AARCH64_TLSDESC_ADR_PREL21 561 | ||
| 2473 | #define R_AARCH64_TLSDESC_ADR_PAGE21 562 | ||
| 2474 | #define R_AARCH64_TLSDESC_LD64_LO12 563 | ||
| 2475 | #define R_AARCH64_TLSDESC_ADD_LO12 564 | ||
| 2476 | #define R_AARCH64_TLSDESC_OFF_G1 565 | ||
| 2477 | #define R_AARCH64_TLSDESC_OFF_G0_NC 566 | ||
| 2478 | #define R_AARCH64_TLSDESC_LDR	567 | ||
| 2479 | #define R_AARCH64_TLSDESC_ADD	568 | ||
| 2480 | #define R_AARCH64_TLSDESC_CALL	569 | ||
| 2481 | #define R_AARCH64_TLSLE_LDST128_TPREL_LO12 570 | ||
| 2482 | #define R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC 571 | ||
| 2483 | #define R_AARCH64_TLSLD_LDST128_DTPREL_LO12 572 | ||
| 2484 | #define R_AARCH64_TLSLD_LDST128_DTPREL_LO12_NC 573 | ||
| 2485 | #define R_AARCH64_COPY 1024 | ||
| 2486 | #define R_AARCH64_GLOB_DAT 1025 | ||
| 2487 | #define R_AARCH64_JUMP_SLOT 1026 | ||
| 2488 | #define R_AARCH64_RELATIVE 1027 | ||
| 2489 | #define R_AARCH64_TLS_DTPMOD 1028 | ||
| 2490 | #define R_AARCH64_TLS_DTPMOD64 1028 | ||
| 2491 | #define R_AARCH64_TLS_DTPREL 1029 | ||
| 2492 | #define R_AARCH64_TLS_DTPREL64 1029 | ||
| 2493 | #define R_AARCH64_TLS_TPREL 1030 | ||
| 2494 | #define R_AARCH64_TLS_TPREL64 1030 | ||
| 2495 | #define R_AARCH64_TLSDESC 1031 | ||
| 2496 | |||
| 2497 | |||
| 2498 | #define R_ARM_NONE		0 | ||
| 2499 | #define R_ARM_PC24		1 | ||
| 2500 | #define R_ARM_ABS32		2 | ||
| 2501 | #define R_ARM_REL32		3 | ||
| 2502 | #define R_ARM_PC13		4 | ||
| 2503 | #define R_ARM_ABS16		5 | ||
| 2504 | #define R_ARM_ABS12		6 | ||
| 2505 | #define R_ARM_THM_ABS5		7 | ||
| 2506 | #define R_ARM_ABS8		8 | ||
| 2507 | #define R_ARM_SBREL32		9 | ||
| 2508 | #define R_ARM_THM_PC22		10 | ||
| 2509 | #define R_ARM_THM_PC8		11 | ||
| 2510 | #define R_ARM_AMP_VCALL9	12 | ||
| 2511 | #define R_ARM_TLS_DESC		13 | ||
| 2512 | #define R_ARM_THM_SWI8		14 | ||
| 2513 | #define R_ARM_XPC25		15 | ||
| 2514 | #define R_ARM_THM_XPC22		16 | ||
| 2515 | #define R_ARM_TLS_DTPMOD32	17 | ||
| 2516 | #define R_ARM_TLS_DTPOFF32	18 | ||
| 2517 | #define R_ARM_TLS_TPOFF32	19 | ||
| 2518 | #define R_ARM_COPY		20 | ||
| 2519 | #define R_ARM_GLOB_DAT		21 | ||
| 2520 | #define R_ARM_JUMP_SLOT		22 | ||
| 2521 | #define R_ARM_RELATIVE		23 | ||
| 2522 | #define R_ARM_GOTOFF		24 | ||
| 2523 | #define R_ARM_GOTPC		25 | ||
| 2524 | #define R_ARM_GOT32		26 | ||
| 2525 | #define R_ARM_PLT32		27 | ||
| 2526 | #define R_ARM_CALL		28 | ||
| 2527 | #define R_ARM_JUMP24		29 | ||
| 2528 | #define R_ARM_THM_JUMP24	30 | ||
| 2529 | #define R_ARM_BASE_ABS		31 | ||
| 2530 | #define R_ARM_ALU_PCREL_7_0	32 | ||
| 2531 | #define R_ARM_ALU_PCREL_15_8	33 | ||
| 2532 | #define R_ARM_ALU_PCREL_23_15	34 | ||
| 2533 | #define R_ARM_LDR_SBREL_11_0	35 | ||
| 2534 | #define R_ARM_ALU_SBREL_19_12	36 | ||
| 2535 | #define R_ARM_ALU_SBREL_27_20	37 | ||
| 2536 | #define R_ARM_TARGET1		38 | ||
| 2537 | #define R_ARM_SBREL31		39 | ||
| 2538 | #define R_ARM_V4BX		40 | ||
| 2539 | #define R_ARM_TARGET2		41 | ||
| 2540 | #define R_ARM_PREL31		42 | ||
| 2541 | #define R_ARM_MOVW_ABS_NC	43 | ||
| 2542 | #define R_ARM_MOVT_ABS		44 | ||
| 2543 | #define R_ARM_MOVW_PREL_NC	45 | ||
| 2544 | #define R_ARM_MOVT_PREL		46 | ||
| 2545 | #define R_ARM_THM_MOVW_ABS_NC	47 | ||
| 2546 | #define R_ARM_THM_MOVT_ABS	48 | ||
| 2547 | #define R_ARM_THM_MOVW_PREL_NC	49 | ||
| 2548 | #define R_ARM_THM_MOVT_PREL	50 | ||
| 2549 | #define R_ARM_THM_JUMP19	51 | ||
| 2550 | #define R_ARM_THM_JUMP6		52 | ||
| 2551 | #define R_ARM_THM_ALU_PREL_11_0	53 | ||
| 2552 | #define R_ARM_THM_PC12		54 | ||
| 2553 | #define R_ARM_ABS32_NOI		55 | ||
| 2554 | #define R_ARM_REL32_NOI		56 | ||
| 2555 | #define R_ARM_ALU_PC_G0_NC	57 | ||
| 2556 | #define R_ARM_ALU_PC_G0		58 | ||
| 2557 | #define R_ARM_ALU_PC_G1_NC	59 | ||
| 2558 | #define R_ARM_ALU_PC_G1		60 | ||
| 2559 | #define R_ARM_ALU_PC_G2		61 | ||
| 2560 | #define R_ARM_LDR_PC_G1		62 | ||
| 2561 | #define R_ARM_LDR_PC_G2		63 | ||
| 2562 | #define R_ARM_LDRS_PC_G0	64 | ||
| 2563 | #define R_ARM_LDRS_PC_G1	65 | ||
| 2564 | #define R_ARM_LDRS_PC_G2	66 | ||
| 2565 | #define R_ARM_LDC_PC_G0		67 | ||
| 2566 | #define R_ARM_LDC_PC_G1		68 | ||
| 2567 | #define R_ARM_LDC_PC_G2		69 | ||
| 2568 | #define R_ARM_ALU_SB_G0_NC	70 | ||
| 2569 | #define R_ARM_ALU_SB_G0		71 | ||
| 2570 | #define R_ARM_ALU_SB_G1_NC	72 | ||
| 2571 | #define R_ARM_ALU_SB_G1		73 | ||
| 2572 | #define R_ARM_ALU_SB_G2		74 | ||
| 2573 | #define R_ARM_LDR_SB_G0		75 | ||
| 2574 | #define R_ARM_LDR_SB_G1		76 | ||
| 2575 | #define R_ARM_LDR_SB_G2		77 | ||
| 2576 | #define R_ARM_LDRS_SB_G0	78 | ||
| 2577 | #define R_ARM_LDRS_SB_G1	79 | ||
| 2578 | #define R_ARM_LDRS_SB_G2	80 | ||
| 2579 | #define R_ARM_LDC_SB_G0		81 | ||
| 2580 | #define R_ARM_LDC_SB_G1		82 | ||
| 2581 | #define R_ARM_LDC_SB_G2		83 | ||
| 2582 | #define R_ARM_MOVW_BREL_NC	84 | ||
| 2583 | #define R_ARM_MOVT_BREL		85 | ||
| 2584 | #define R_ARM_MOVW_BREL		86 | ||
| 2585 | #define R_ARM_THM_MOVW_BREL_NC	87 | ||
| 2586 | #define R_ARM_THM_MOVT_BREL	88 | ||
| 2587 | #define R_ARM_THM_MOVW_BREL	89 | ||
| 2588 | #define R_ARM_TLS_GOTDESC	90 | ||
| 2589 | #define R_ARM_TLS_CALL		91 | ||
| 2590 | #define R_ARM_TLS_DESCSEQ	92 | ||
| 2591 | #define R_ARM_THM_TLS_CALL	93 | ||
| 2592 | #define R_ARM_PLT32_ABS		94 | ||
| 2593 | #define R_ARM_GOT_ABS		95 | ||
| 2594 | #define R_ARM_GOT_PREL		96 | ||
| 2595 | #define R_ARM_GOT_BREL12	97 | ||
| 2596 | #define R_ARM_GOTOFF12		98 | ||
| 2597 | #define R_ARM_GOTRELAX		99 | ||
| 2598 | #define R_ARM_GNU_VTENTRY	100 | ||
| 2599 | #define R_ARM_GNU_VTINHERIT	101 | ||
| 2600 | #define R_ARM_THM_PC11		102 | ||
| 2601 | #define R_ARM_THM_PC9		103 | ||
| 2602 | #define R_ARM_TLS_GD32		104 | ||
| 2603 | |||
| 2604 | #define R_ARM_TLS_LDM32		105 | ||
| 2605 | |||
| 2606 | #define R_ARM_TLS_LDO32		106 | ||
| 2607 | |||
| 2608 | #define R_ARM_TLS_IE32		107 | ||
| 2609 | |||
| 2610 | #define R_ARM_TLS_LE32		108 | ||
| 2611 | #define R_ARM_TLS_LDO12		109 | ||
| 2612 | #define R_ARM_TLS_LE12		110 | ||
| 2613 | #define R_ARM_TLS_IE12GP	111 | ||
| 2614 | #define R_ARM_ME_TOO		128 | ||
| 2615 | #define R_ARM_THM_TLS_DESCSEQ	129 | ||
| 2616 | #define R_ARM_THM_TLS_DESCSEQ16	129 | ||
| 2617 | #define R_ARM_THM_TLS_DESCSEQ32	130 | ||
| 2618 | #define R_ARM_THM_GOT_BREL12	131 | ||
| 2619 | #define R_ARM_IRELATIVE		160 | ||
| 2620 | #define R_ARM_RXPC25		249 | ||
| 2621 | #define R_ARM_RSBREL32		250 | ||
| 2622 | #define R_ARM_THM_RPC22		251 | ||
| 2623 | #define R_ARM_RREL32		252 | ||
| 2624 | #define R_ARM_RABS22		253 | ||
| 2625 | #define R_ARM_RPC24		254 | ||
| 2626 | #define R_ARM_RBASE		255 | ||
| 2627 | |||
| 2628 | #define R_ARM_NUM		256 | ||
| 2629 | |||
| 2630 | |||
| 2631 | #define R_CKCORE_NONE 0 | ||
| 2632 | #define R_CKCORE_ADDR32 1 | ||
| 2633 | #define R_CKCORE_PCRELIMM8BY4 2 | ||
| 2634 | #define R_CKCORE_PCRELIMM11BY2 3 | ||
| 2635 | #define R_CKCORE_PCREL32 5 | ||
| 2636 | #define R_CKCORE_PCRELJSR_IMM11BY2 6 | ||
| 2637 | #define R_CKCORE_RELATIVE 9 | ||
| 2638 | #define R_CKCORE_COPY 10 | ||
| 2639 | #define R_CKCORE_GLOB_DAT 11 | ||
| 2640 | #define R_CKCORE_JUMP_SLOT 12 | ||
| 2641 | #define R_CKCORE_GOTOFF 13 | ||
| 2642 | #define R_CKCORE_GOTPC 14 | ||
| 2643 | #define R_CKCORE_GOT32 15 | ||
| 2644 | #define R_CKCORE_PLT32 16 | ||
| 2645 | #define R_CKCORE_ADDRGOT 17 | ||
| 2646 | #define R_CKCORE_ADDRPLT 18 | ||
| 2647 | #define R_CKCORE_PCREL_IMM26BY2 19 | ||
| 2648 | #define R_CKCORE_PCREL_IMM16BY2 20 | ||
| 2649 | #define R_CKCORE_PCREL_IMM16BY4 21 | ||
| 2650 | #define R_CKCORE_PCREL_IMM10BY2 22 | ||
| 2651 | #define R_CKCORE_PCREL_IMM10BY4 23 | ||
| 2652 | #define R_CKCORE_ADDR_HI16 24 | ||
| 2653 | #define R_CKCORE_ADDR_LO16 25 | ||
| 2654 | #define R_CKCORE_GOTPC_HI16 26 | ||
| 2655 | #define R_CKCORE_GOTPC_LO16 27 | ||
| 2656 | #define R_CKCORE_GOTOFF_HI16 28 | ||
| 2657 | #define R_CKCORE_GOTOFF_LO16 29 | ||
| 2658 | #define R_CKCORE_GOT12 30 | ||
| 2659 | #define R_CKCORE_GOT_HI16 31 | ||
| 2660 | #define R_CKCORE_GOT_LO16 32 | ||
| 2661 | #define R_CKCORE_PLT12 33 | ||
| 2662 | #define R_CKCORE_PLT_HI16 34 | ||
| 2663 | #define R_CKCORE_PLT_LO16 35 | ||
| 2664 | #define R_CKCORE_ADDRGOT_HI16 36 | ||
| 2665 | #define R_CKCORE_ADDRGOT_LO16 37 | ||
| 2666 | #define R_CKCORE_ADDRPLT_HI16 38 | ||
| 2667 | #define R_CKCORE_ADDRPLT_LO16 39 | ||
| 2668 | #define R_CKCORE_PCREL_JSR_IMM26BY2 40 | ||
| 2669 | #define R_CKCORE_TOFFSET_LO16 41 | ||
| 2670 | #define R_CKCORE_DOFFSET_LO16 42 | ||
| 2671 | #define R_CKCORE_PCREL_IMM18BY2 43 | ||
| 2672 | #define R_CKCORE_DOFFSET_IMM18 44 | ||
| 2673 | #define R_CKCORE_DOFFSET_IMM18BY2 45 | ||
| 2674 | #define R_CKCORE_DOFFSET_IMM18BY4 46 | ||
| 2675 | #define R_CKCORE_GOT_IMM18BY4 48 | ||
| 2676 | #define R_CKCORE_PLT_IMM18BY4 49 | ||
| 2677 | #define R_CKCORE_PCREL_IMM7BY4 50 | ||
| 2678 | #define R_CKCORE_TLS_LE32 51 | ||
| 2679 | #define R_CKCORE_TLS_IE32 52 | ||
| 2680 | #define R_CKCORE_TLS_GD32 53 | ||
| 2681 | #define R_CKCORE_TLS_LDM32 54 | ||
| 2682 | #define R_CKCORE_TLS_LDO32 55 | ||
| 2683 | #define R_CKCORE_TLS_DTPMOD32 56 | ||
| 2684 | #define R_CKCORE_TLS_DTPOFF32 57 | ||
| 2685 | #define R_CKCORE_TLS_TPOFF32 58 | ||
| 2686 | |||
| 2687 | |||
| 2688 | #define EF_IA_64_MASKOS		0x0000000f | ||
| 2689 | #define EF_IA_64_ABI64		0x00000010 | ||
| 2690 | #define EF_IA_64_ARCH		0xff000000 | ||
| 2691 | |||
| 2692 | |||
| 2693 | #define PT_IA_64_ARCHEXT	(PT_LOPROC + 0) | ||
| 2694 | #define PT_IA_64_UNWIND		(PT_LOPROC + 1) | ||
| 2695 | #define PT_IA_64_HP_OPT_ANOT	(PT_LOOS + 0x12) | ||
| 2696 | #define PT_IA_64_HP_HSL_ANOT	(PT_LOOS + 0x13) | ||
| 2697 | #define PT_IA_64_HP_STACK	(PT_LOOS + 0x14) | ||
| 2698 | |||
| 2699 | |||
| 2700 | #define PF_IA_64_NORECOV	0x80000000 | ||
| 2701 | |||
| 2702 | |||
| 2703 | #define SHT_IA_64_EXT		(SHT_LOPROC + 0) | ||
| 2704 | #define SHT_IA_64_UNWIND	(SHT_LOPROC + 1) | ||
| 2705 | |||
| 2706 | |||
| 2707 | #define SHF_IA_64_SHORT		0x10000000 | ||
| 2708 | #define SHF_IA_64_NORECOV	0x20000000 | ||
| 2709 | |||
| 2710 | |||
| 2711 | #define DT_IA_64_PLT_RESERVE	(DT_LOPROC + 0) | ||
| 2712 | #define DT_IA_64_NUM		1 | ||
| 2713 | |||
| 2714 | |||
| 2715 | #define R_IA64_NONE		0x00 | ||
| 2716 | #define R_IA64_IMM14		0x21 | ||
| 2717 | #define R_IA64_IMM22		0x22 | ||
| 2718 | #define R_IA64_IMM64		0x23 | ||
| 2719 | #define R_IA64_DIR32MSB		0x24 | ||
| 2720 | #define R_IA64_DIR32LSB		0x25 | ||
| 2721 | #define R_IA64_DIR64MSB		0x26 | ||
| 2722 | #define R_IA64_DIR64LSB		0x27 | ||
| 2723 | #define R_IA64_GPREL22		0x2a | ||
| 2724 | #define R_IA64_GPREL64I		0x2b | ||
| 2725 | #define R_IA64_GPREL32MSB	0x2c | ||
| 2726 | #define R_IA64_GPREL32LSB	0x2d | ||
| 2727 | #define R_IA64_GPREL64MSB	0x2e | ||
| 2728 | #define R_IA64_GPREL64LSB	0x2f | ||
| 2729 | #define R_IA64_LTOFF22		0x32 | ||
| 2730 | #define R_IA64_LTOFF64I		0x33 | ||
| 2731 | #define R_IA64_PLTOFF22		0x3a | ||
| 2732 | #define R_IA64_PLTOFF64I	0x3b | ||
| 2733 | #define R_IA64_PLTOFF64MSB	0x3e | ||
| 2734 | #define R_IA64_PLTOFF64LSB	0x3f | ||
| 2735 | #define R_IA64_FPTR64I		0x43 | ||
| 2736 | #define R_IA64_FPTR32MSB	0x44 | ||
| 2737 | #define R_IA64_FPTR32LSB	0x45 | ||
| 2738 | #define R_IA64_FPTR64MSB	0x46 | ||
| 2739 | #define R_IA64_FPTR64LSB	0x47 | ||
| 2740 | #define R_IA64_PCREL60B		0x48 | ||
| 2741 | #define R_IA64_PCREL21B		0x49 | ||
| 2742 | #define R_IA64_PCREL21M		0x4a | ||
| 2743 | #define R_IA64_PCREL21F		0x4b | ||
| 2744 | #define R_IA64_PCREL32MSB	0x4c | ||
| 2745 | #define R_IA64_PCREL32LSB	0x4d | ||
| 2746 | #define R_IA64_PCREL64MSB	0x4e | ||
| 2747 | #define R_IA64_PCREL64LSB	0x4f | ||
| 2748 | #define R_IA64_LTOFF_FPTR22	0x52 | ||
| 2749 | #define R_IA64_LTOFF_FPTR64I	0x53 | ||
| 2750 | #define R_IA64_LTOFF_FPTR32MSB	0x54 | ||
| 2751 | #define R_IA64_LTOFF_FPTR32LSB	0x55 | ||
| 2752 | #define R_IA64_LTOFF_FPTR64MSB	0x56 | ||
| 2753 | #define R_IA64_LTOFF_FPTR64LSB	0x57 | ||
| 2754 | #define R_IA64_SEGREL32MSB	0x5c | ||
| 2755 | #define R_IA64_SEGREL32LSB	0x5d | ||
| 2756 | #define R_IA64_SEGREL64MSB	0x5e | ||
| 2757 | #define R_IA64_SEGREL64LSB	0x5f | ||
| 2758 | #define R_IA64_SECREL32MSB	0x64 | ||
| 2759 | #define R_IA64_SECREL32LSB	0x65 | ||
| 2760 | #define R_IA64_SECREL64MSB	0x66 | ||
| 2761 | #define R_IA64_SECREL64LSB	0x67 | ||
| 2762 | #define R_IA64_REL32MSB		0x6c | ||
| 2763 | #define R_IA64_REL32LSB		0x6d | ||
| 2764 | #define R_IA64_REL64MSB		0x6e | ||
| 2765 | #define R_IA64_REL64LSB		0x6f | ||
| 2766 | #define R_IA64_LTV32MSB		0x74 | ||
| 2767 | #define R_IA64_LTV32LSB		0x75 | ||
| 2768 | #define R_IA64_LTV64MSB		0x76 | ||
| 2769 | #define R_IA64_LTV64LSB		0x77 | ||
| 2770 | #define R_IA64_PCREL21BI	0x79 | ||
| 2771 | #define R_IA64_PCREL22		0x7a | ||
| 2772 | #define R_IA64_PCREL64I		0x7b | ||
| 2773 | #define R_IA64_IPLTMSB		0x80 | ||
| 2774 | #define R_IA64_IPLTLSB		0x81 | ||
| 2775 | #define R_IA64_COPY		0x84 | ||
| 2776 | #define R_IA64_SUB		0x85 | ||
| 2777 | #define R_IA64_LTOFF22X		0x86 | ||
| 2778 | #define R_IA64_LDXMOV		0x87 | ||
| 2779 | #define R_IA64_TPREL14		0x91 | ||
| 2780 | #define R_IA64_TPREL22		0x92 | ||
| 2781 | #define R_IA64_TPREL64I		0x93 | ||
| 2782 | #define R_IA64_TPREL64MSB	0x96 | ||
| 2783 | #define R_IA64_TPREL64LSB	0x97 | ||
| 2784 | #define R_IA64_LTOFF_TPREL22	0x9a | ||
| 2785 | #define R_IA64_DTPMOD64MSB	0xa6 | ||
| 2786 | #define R_IA64_DTPMOD64LSB	0xa7 | ||
| 2787 | #define R_IA64_LTOFF_DTPMOD22	0xaa | ||
| 2788 | #define R_IA64_DTPREL14		0xb1 | ||
| 2789 | #define R_IA64_DTPREL22		0xb2 | ||
| 2790 | #define R_IA64_DTPREL64I	0xb3 | ||
| 2791 | #define R_IA64_DTPREL32MSB	0xb4 | ||
| 2792 | #define R_IA64_DTPREL32LSB	0xb5 | ||
| 2793 | #define R_IA64_DTPREL64MSB	0xb6 | ||
| 2794 | #define R_IA64_DTPREL64LSB	0xb7 | ||
| 2795 | #define R_IA64_LTOFF_DTPREL22	0xba | ||
| 2796 | |||
| 2797 | |||
| 2798 | #define EF_SH_MACH_MASK		0x1f | ||
| 2799 | #define EF_SH_UNKNOWN		0x0 | ||
| 2800 | #define EF_SH1			0x1 | ||
| 2801 | #define EF_SH2			0x2 | ||
| 2802 | #define EF_SH3			0x3 | ||
| 2803 | #define EF_SH_DSP		0x4 | ||
| 2804 | #define EF_SH3_DSP		0x5 | ||
| 2805 | #define EF_SH4AL_DSP		0x6 | ||
| 2806 | #define EF_SH3E			0x8 | ||
| 2807 | #define EF_SH4			0x9 | ||
| 2808 | #define EF_SH2E			0xb | ||
| 2809 | #define EF_SH4A			0xc | ||
| 2810 | #define EF_SH2A			0xd | ||
| 2811 | #define EF_SH4_NOFPU		0x10 | ||
| 2812 | #define EF_SH4A_NOFPU		0x11 | ||
| 2813 | #define EF_SH4_NOMMU_NOFPU	0x12 | ||
| 2814 | #define EF_SH2A_NOFPU		0x13 | ||
| 2815 | #define EF_SH3_NOMMU		0x14 | ||
| 2816 | #define EF_SH2A_SH4_NOFPU	0x15 | ||
| 2817 | #define EF_SH2A_SH3_NOFPU	0x16 | ||
| 2818 | #define EF_SH2A_SH4		0x17 | ||
| 2819 | #define EF_SH2A_SH3E		0x18 | ||
| 2820 | |||
| 2821 | #define	R_SH_NONE		0 | ||
| 2822 | #define	R_SH_DIR32		1 | ||
| 2823 | #define	R_SH_REL32		2 | ||
| 2824 | #define	R_SH_DIR8WPN		3 | ||
| 2825 | #define	R_SH_IND12W		4 | ||
| 2826 | #define	R_SH_DIR8WPL		5 | ||
| 2827 | #define	R_SH_DIR8WPZ		6 | ||
| 2828 | #define	R_SH_DIR8BP		7 | ||
| 2829 | #define	R_SH_DIR8W		8 | ||
| 2830 | #define	R_SH_DIR8L		9 | ||
| 2831 | #define	R_SH_SWITCH16		25 | ||
| 2832 | #define	R_SH_SWITCH32		26 | ||
| 2833 | #define	R_SH_USES		27 | ||
| 2834 | #define	R_SH_COUNT		28 | ||
| 2835 | #define	R_SH_ALIGN		29 | ||
| 2836 | #define	R_SH_CODE		30 | ||
| 2837 | #define	R_SH_DATA		31 | ||
| 2838 | #define	R_SH_LABEL		32 | ||
| 2839 | #define	R_SH_SWITCH8		33 | ||
| 2840 | #define	R_SH_GNU_VTINHERIT	34 | ||
| 2841 | #define	R_SH_GNU_VTENTRY	35 | ||
| 2842 | #define	R_SH_TLS_GD_32		144 | ||
| 2843 | #define	R_SH_TLS_LD_32		145 | ||
| 2844 | #define	R_SH_TLS_LDO_32		146 | ||
| 2845 | #define	R_SH_TLS_IE_32		147 | ||
| 2846 | #define	R_SH_TLS_LE_32		148 | ||
| 2847 | #define	R_SH_TLS_DTPMOD32	149 | ||
| 2848 | #define	R_SH_TLS_DTPOFF32	150 | ||
| 2849 | #define	R_SH_TLS_TPOFF32	151 | ||
| 2850 | #define	R_SH_GOT32		160 | ||
| 2851 | #define	R_SH_PLT32		161 | ||
| 2852 | #define	R_SH_COPY		162 | ||
| 2853 | #define	R_SH_GLOB_DAT		163 | ||
| 2854 | #define	R_SH_JMP_SLOT		164 | ||
| 2855 | #define	R_SH_RELATIVE		165 | ||
| 2856 | #define	R_SH_GOTOFF		166 | ||
| 2857 | #define	R_SH_GOTPC		167 | ||
| 2858 | #define	R_SH_GOT20		201 | ||
| 2859 | #define	R_SH_GOTOFF20		202 | ||
| 2860 | #define	R_SH_GOTFUNCDESC	203 | ||
| 2861 | #define	R_SH_GOTFUNCDEST20	204 | ||
| 2862 | #define	R_SH_GOTOFFFUNCDESC	205 | ||
| 2863 | #define	R_SH_GOTOFFFUNCDEST20	206 | ||
| 2864 | #define	R_SH_FUNCDESC		207 | ||
| 2865 | #define	R_SH_FUNCDESC_VALUE	208 | ||
| 2866 | |||
| 2867 | #define	R_SH_NUM		256 | ||
| 2868 | |||
| 2869 | |||
| 2870 | |||
| 2871 | #define R_390_NONE		0 | ||
| 2872 | #define R_390_8			1 | ||
| 2873 | #define R_390_12		2 | ||
| 2874 | #define R_390_16		3 | ||
| 2875 | #define R_390_32		4 | ||
| 2876 | #define R_390_PC32		5 | ||
| 2877 | #define R_390_GOT12		6 | ||
| 2878 | #define R_390_GOT32		7 | ||
| 2879 | #define R_390_PLT32		8 | ||
| 2880 | #define R_390_COPY		9 | ||
| 2881 | #define R_390_GLOB_DAT		10 | ||
| 2882 | #define R_390_JMP_SLOT		11 | ||
| 2883 | #define R_390_RELATIVE		12 | ||
| 2884 | #define R_390_GOTOFF32		13 | ||
| 2885 | #define R_390_GOTPC		14 | ||
| 2886 | #define R_390_GOT16		15 | ||
| 2887 | #define R_390_PC16		16 | ||
| 2888 | #define R_390_PC16DBL		17 | ||
| 2889 | #define R_390_PLT16DBL		18 | ||
| 2890 | #define R_390_PC32DBL		19 | ||
| 2891 | #define R_390_PLT32DBL		20 | ||
| 2892 | #define R_390_GOTPCDBL		21 | ||
| 2893 | #define R_390_64		22 | ||
| 2894 | #define R_390_PC64		23 | ||
| 2895 | #define R_390_GOT64		24 | ||
| 2896 | #define R_390_PLT64		25 | ||
| 2897 | #define R_390_GOTENT		26 | ||
| 2898 | #define R_390_GOTOFF16		27 | ||
| 2899 | #define R_390_GOTOFF64		28 | ||
| 2900 | #define R_390_GOTPLT12		29 | ||
| 2901 | #define R_390_GOTPLT16		30 | ||
| 2902 | #define R_390_GOTPLT32		31 | ||
| 2903 | #define R_390_GOTPLT64		32 | ||
| 2904 | #define R_390_GOTPLTENT		33 | ||
| 2905 | #define R_390_PLTOFF16		34 | ||
| 2906 | #define R_390_PLTOFF32		35 | ||
| 2907 | #define R_390_PLTOFF64		36 | ||
| 2908 | #define R_390_TLS_LOAD		37 | ||
| 2909 | #define R_390_TLS_GDCALL	38 | ||
| 2910 | |||
| 2911 | #define R_390_TLS_LDCALL	39 | ||
| 2912 | |||
| 2913 | #define R_390_TLS_GD32		40 | ||
| 2914 | |||
| 2915 | #define R_390_TLS_GD64		41 | ||
| 2916 | |||
| 2917 | #define R_390_TLS_GOTIE12	42 | ||
| 2918 | |||
| 2919 | #define R_390_TLS_GOTIE32	43 | ||
| 2920 | |||
| 2921 | #define R_390_TLS_GOTIE64	44 | ||
| 2922 | |||
| 2923 | #define R_390_TLS_LDM32		45 | ||
| 2924 | |||
| 2925 | #define R_390_TLS_LDM64		46 | ||
| 2926 | |||
| 2927 | #define R_390_TLS_IE32		47 | ||
| 2928 | |||
| 2929 | #define R_390_TLS_IE64		48 | ||
| 2930 | |||
| 2931 | #define R_390_TLS_IEENT		49 | ||
| 2932 | |||
| 2933 | #define R_390_TLS_LE32		50 | ||
| 2934 | |||
| 2935 | #define R_390_TLS_LE64		51 | ||
| 2936 | |||
| 2937 | #define R_390_TLS_LDO32		52 | ||
| 2938 | |||
| 2939 | #define R_390_TLS_LDO64		53 | ||
| 2940 | |||
| 2941 | #define R_390_TLS_DTPMOD	54 | ||
| 2942 | #define R_390_TLS_DTPOFF	55 | ||
| 2943 | #define R_390_TLS_TPOFF		56 | ||
| 2944 | |||
| 2945 | #define R_390_20		57 | ||
| 2946 | #define R_390_GOT20		58 | ||
| 2947 | #define R_390_GOTPLT20		59 | ||
| 2948 | #define R_390_TLS_GOTIE20	60 | ||
| 2949 | |||
| 2950 | |||
| 2951 | #define R_390_NUM		61 | ||
| 2952 | |||
| 2953 | |||
| 2954 | |||
| 2955 | #define R_CRIS_NONE		0 | ||
| 2956 | #define R_CRIS_8		1 | ||
| 2957 | #define R_CRIS_16		2 | ||
| 2958 | #define R_CRIS_32		3 | ||
| 2959 | #define R_CRIS_8_PCREL		4 | ||
| 2960 | #define R_CRIS_16_PCREL		5 | ||
| 2961 | #define R_CRIS_32_PCREL		6 | ||
| 2962 | #define R_CRIS_GNU_VTINHERIT	7 | ||
| 2963 | #define R_CRIS_GNU_VTENTRY	8 | ||
| 2964 | #define R_CRIS_COPY		9 | ||
| 2965 | #define R_CRIS_GLOB_DAT		10 | ||
| 2966 | #define R_CRIS_JUMP_SLOT	11 | ||
| 2967 | #define R_CRIS_RELATIVE		12 | ||
| 2968 | #define R_CRIS_16_GOT		13 | ||
| 2969 | #define R_CRIS_32_GOT		14 | ||
| 2970 | #define R_CRIS_16_GOTPLT	15 | ||
| 2971 | #define R_CRIS_32_GOTPLT	16 | ||
| 2972 | #define R_CRIS_32_GOTREL	17 | ||
| 2973 | #define R_CRIS_32_PLT_GOTREL	18 | ||
| 2974 | #define R_CRIS_32_PLT_PCREL	19 | ||
| 2975 | |||
| 2976 | #define R_CRIS_NUM		20 | ||
| 2977 | |||
| 2978 | |||
| 2979 | |||
| 2980 | #define R_X86_64_NONE		0 | ||
| 2981 | #define R_X86_64_64		1 | ||
| 2982 | #define R_X86_64_PC32		2 | ||
| 2983 | #define R_X86_64_GOT32		3 | ||
| 2984 | #define R_X86_64_PLT32		4 | ||
| 2985 | #define R_X86_64_COPY		5 | ||
| 2986 | #define R_X86_64_GLOB_DAT	6 | ||
| 2987 | #define R_X86_64_JUMP_SLOT	7 | ||
| 2988 | #define R_X86_64_RELATIVE	8 | ||
| 2989 | #define R_X86_64_GOTPCREL	9 | ||
| 2990 | |||
| 2991 | #define R_X86_64_32		10 | ||
| 2992 | #define R_X86_64_32S		11 | ||
| 2993 | #define R_X86_64_16		12 | ||
| 2994 | #define R_X86_64_PC16		13 | ||
| 2995 | #define R_X86_64_8		14 | ||
| 2996 | #define R_X86_64_PC8		15 | ||
| 2997 | #define R_X86_64_DTPMOD64	16 | ||
| 2998 | #define R_X86_64_DTPOFF64	17 | ||
| 2999 | #define R_X86_64_TPOFF64	18 | ||
| 3000 | #define R_X86_64_TLSGD		19 | ||
| 3001 | |||
| 3002 | #define R_X86_64_TLSLD		20 | ||
| 3003 | |||
| 3004 | #define R_X86_64_DTPOFF32	21 | ||
| 3005 | #define R_X86_64_GOTTPOFF	22 | ||
| 3006 | |||
| 3007 | #define R_X86_64_TPOFF32	23 | ||
| 3008 | #define R_X86_64_PC64		24 | ||
| 3009 | #define R_X86_64_GOTOFF64	25 | ||
| 3010 | #define R_X86_64_GOTPC32	26 | ||
| 3011 | #define R_X86_64_GOT64		27 | ||
| 3012 | #define R_X86_64_GOTPCREL64	28 | ||
| 3013 | #define R_X86_64_GOTPC64	29 | ||
| 3014 | #define R_X86_64_GOTPLT64	30 | ||
| 3015 | #define R_X86_64_PLTOFF64	31 | ||
| 3016 | #define R_X86_64_SIZE32		32 | ||
| 3017 | #define R_X86_64_SIZE64		33 | ||
| 3018 | |||
| 3019 | #define R_X86_64_GOTPC32_TLSDESC 34 | ||
| 3020 | #define R_X86_64_TLSDESC_CALL 35 | ||
| 3021 | |||
| 3022 | #define R_X86_64_TLSDESC 36 | ||
| 3023 | #define R_X86_64_IRELATIVE	37 | ||
| 3024 | #define R_X86_64_RELATIVE64	38 | ||
| 3025 | #define R_X86_64_GOTPCRELX	41 | ||
| 3026 | #define R_X86_64_REX_GOTPCRELX	42 | ||
| 3027 | #define R_X86_64_NUM		43 | ||
| 3028 | |||
| 3029 | |||
| 3030 | |||
| 3031 | #define R_MN10300_NONE		0 | ||
| 3032 | #define R_MN10300_32		1 | ||
| 3033 | #define R_MN10300_16		2 | ||
| 3034 | #define R_MN10300_8		3 | ||
| 3035 | #define R_MN10300_PCREL32	4 | ||
| 3036 | #define R_MN10300_PCREL16	5 | ||
| 3037 | #define R_MN10300_PCREL8	6 | ||
| 3038 | #define R_MN10300_GNU_VTINHERIT	7 | ||
| 3039 | #define R_MN10300_GNU_VTENTRY	8 | ||
| 3040 | #define R_MN10300_24		9 | ||
| 3041 | #define R_MN10300_GOTPC32	10 | ||
| 3042 | #define R_MN10300_GOTPC16	11 | ||
| 3043 | #define R_MN10300_GOTOFF32	12 | ||
| 3044 | #define R_MN10300_GOTOFF24	13 | ||
| 3045 | #define R_MN10300_GOTOFF16	14 | ||
| 3046 | #define R_MN10300_PLT32		15 | ||
| 3047 | #define R_MN10300_PLT16		16 | ||
| 3048 | #define R_MN10300_GOT32		17 | ||
| 3049 | #define R_MN10300_GOT24		18 | ||
| 3050 | #define R_MN10300_GOT16		19 | ||
| 3051 | #define R_MN10300_COPY		20 | ||
| 3052 | #define R_MN10300_GLOB_DAT	21 | ||
| 3053 | #define R_MN10300_JMP_SLOT	22 | ||
| 3054 | #define R_MN10300_RELATIVE	23 | ||
| 3055 | |||
| 3056 | #define R_MN10300_NUM		24 | ||
| 3057 | |||
| 3058 | |||
| 3059 | |||
| 3060 | #define R_M32R_NONE		0 | ||
| 3061 | #define R_M32R_16		1 | ||
| 3062 | #define R_M32R_32		2 | ||
| 3063 | #define R_M32R_24		3 | ||
| 3064 | #define R_M32R_10_PCREL		4 | ||
| 3065 | #define R_M32R_18_PCREL		5 | ||
| 3066 | #define R_M32R_26_PCREL		6 | ||
| 3067 | #define R_M32R_HI16_ULO		7 | ||
| 3068 | #define R_M32R_HI16_SLO		8 | ||
| 3069 | #define R_M32R_LO16		9 | ||
| 3070 | #define R_M32R_SDA16		10 | ||
| 3071 | #define R_M32R_GNU_VTINHERIT	11 | ||
| 3072 | #define R_M32R_GNU_VTENTRY	12 | ||
| 3073 | |||
| 3074 | #define R_M32R_16_RELA		33 | ||
| 3075 | #define R_M32R_32_RELA		34 | ||
| 3076 | #define R_M32R_24_RELA		35 | ||
| 3077 | #define R_M32R_10_PCREL_RELA	36 | ||
| 3078 | #define R_M32R_18_PCREL_RELA	37 | ||
| 3079 | #define R_M32R_26_PCREL_RELA	38 | ||
| 3080 | #define R_M32R_HI16_ULO_RELA	39 | ||
| 3081 | #define R_M32R_HI16_SLO_RELA	40 | ||
| 3082 | #define R_M32R_LO16_RELA	41 | ||
| 3083 | #define R_M32R_SDA16_RELA	42 | ||
| 3084 | #define R_M32R_RELA_GNU_VTINHERIT	43 | ||
| 3085 | #define R_M32R_RELA_GNU_VTENTRY	44 | ||
| 3086 | #define R_M32R_REL32		45 | ||
| 3087 | |||
| 3088 | #define R_M32R_GOT24		48 | ||
| 3089 | #define R_M32R_26_PLTREL	49 | ||
| 3090 | #define R_M32R_COPY		50 | ||
| 3091 | #define R_M32R_GLOB_DAT		51 | ||
| 3092 | #define R_M32R_JMP_SLOT		52 | ||
| 3093 | #define R_M32R_RELATIVE		53 | ||
| 3094 | #define R_M32R_GOTOFF		54 | ||
| 3095 | #define R_M32R_GOTPC24		55 | ||
| 3096 | #define R_M32R_GOT16_HI_ULO	56 | ||
| 3097 | |||
| 3098 | #define R_M32R_GOT16_HI_SLO	57 | ||
| 3099 | |||
| 3100 | #define R_M32R_GOT16_LO		58 | ||
| 3101 | #define R_M32R_GOTPC_HI_ULO	59 | ||
| 3102 | |||
| 3103 | #define R_M32R_GOTPC_HI_SLO	60 | ||
| 3104 | |||
| 3105 | #define R_M32R_GOTPC_LO		61 | ||
| 3106 | |||
| 3107 | #define R_M32R_GOTOFF_HI_ULO	62 | ||
| 3108 | |||
| 3109 | #define R_M32R_GOTOFF_HI_SLO	63 | ||
| 3110 | |||
| 3111 | #define R_M32R_GOTOFF_LO	64 | ||
| 3112 | #define R_M32R_NUM		256 | ||
| 3113 | |||
| 3114 | #define R_MICROBLAZE_NONE 0 | ||
| 3115 | #define R_MICROBLAZE_32 1 | ||
| 3116 | #define R_MICROBLAZE_32_PCREL 2 | ||
| 3117 | #define R_MICROBLAZE_64_PCREL 3 | ||
| 3118 | #define R_MICROBLAZE_32_PCREL_LO 4 | ||
| 3119 | #define R_MICROBLAZE_64 5 | ||
| 3120 | #define R_MICROBLAZE_32_LO 6 | ||
| 3121 | #define R_MICROBLAZE_SRO32 7 | ||
| 3122 | #define R_MICROBLAZE_SRW32 8 | ||
| 3123 | #define R_MICROBLAZE_64_NONE 9 | ||
| 3124 | #define R_MICROBLAZE_32_SYM_OP_SYM 10 | ||
| 3125 | #define R_MICROBLAZE_GNU_VTINHERIT 11 | ||
| 3126 | #define R_MICROBLAZE_GNU_VTENTRY 12 | ||
| 3127 | #define R_MICROBLAZE_GOTPC_64 13 | ||
| 3128 | #define R_MICROBLAZE_GOT_64 14 | ||
| 3129 | #define R_MICROBLAZE_PLT_64 15 | ||
| 3130 | #define R_MICROBLAZE_REL 16 | ||
| 3131 | #define R_MICROBLAZE_JUMP_SLOT 17 | ||
| 3132 | #define R_MICROBLAZE_GLOB_DAT 18 | ||
| 3133 | #define R_MICROBLAZE_GOTOFF_64 19 | ||
| 3134 | #define R_MICROBLAZE_GOTOFF_32 20 | ||
| 3135 | #define R_MICROBLAZE_COPY 21 | ||
| 3136 | #define R_MICROBLAZE_TLS 22 | ||
| 3137 | #define R_MICROBLAZE_TLSGD 23 | ||
| 3138 | #define R_MICROBLAZE_TLSLD 24 | ||
| 3139 | #define R_MICROBLAZE_TLSDTPMOD32 25 | ||
| 3140 | #define R_MICROBLAZE_TLSDTPREL32 26 | ||
| 3141 | #define R_MICROBLAZE_TLSDTPREL64 27 | ||
| 3142 | #define R_MICROBLAZE_TLSGOTTPREL32 28 | ||
| 3143 | #define R_MICROBLAZE_TLSTPREL32	 29 | ||
| 3144 | |||
| 3145 | #define DT_NIOS2_GP 0x70000002 | ||
| 3146 | |||
| 3147 | #define R_NIOS2_NONE		0 | ||
| 3148 | #define R_NIOS2_S16		1 | ||
| 3149 | #define R_NIOS2_U16		2 | ||
| 3150 | #define R_NIOS2_PCREL16		3 | ||
| 3151 | #define R_NIOS2_CALL26		4 | ||
| 3152 | #define R_NIOS2_IMM5		5 | ||
| 3153 | #define R_NIOS2_CACHE_OPX	6 | ||
| 3154 | #define R_NIOS2_IMM6		7 | ||
| 3155 | #define R_NIOS2_IMM8		8 | ||
| 3156 | #define R_NIOS2_HI16		9 | ||
| 3157 | #define R_NIOS2_LO16		10 | ||
| 3158 | #define R_NIOS2_HIADJ16		11 | ||
| 3159 | #define R_NIOS2_BFD_RELOC_32	12 | ||
| 3160 | #define R_NIOS2_BFD_RELOC_16	13 | ||
| 3161 | #define R_NIOS2_BFD_RELOC_8	14 | ||
| 3162 | #define R_NIOS2_GPREL		15 | ||
| 3163 | #define R_NIOS2_GNU_VTINHERIT	16 | ||
| 3164 | #define R_NIOS2_GNU_VTENTRY	17 | ||
| 3165 | #define R_NIOS2_UJMP		18 | ||
| 3166 | #define R_NIOS2_CJMP		19 | ||
| 3167 | #define R_NIOS2_CALLR		20 | ||
| 3168 | #define R_NIOS2_ALIGN		21 | ||
| 3169 | #define R_NIOS2_GOT16		22 | ||
| 3170 | #define R_NIOS2_CALL16		23 | ||
| 3171 | #define R_NIOS2_GOTOFF_LO	24 | ||
| 3172 | #define R_NIOS2_GOTOFF_HA	25 | ||
| 3173 | #define R_NIOS2_PCREL_LO	26 | ||
| 3174 | #define R_NIOS2_PCREL_HA	27 | ||
| 3175 | #define R_NIOS2_TLS_GD16	28 | ||
| 3176 | #define R_NIOS2_TLS_LDM16	29 | ||
| 3177 | #define R_NIOS2_TLS_LDO16	30 | ||
| 3178 | #define R_NIOS2_TLS_IE16	31 | ||
| 3179 | #define R_NIOS2_TLS_LE16	32 | ||
| 3180 | #define R_NIOS2_TLS_DTPMOD	33 | ||
| 3181 | #define R_NIOS2_TLS_DTPREL	34 | ||
| 3182 | #define R_NIOS2_TLS_TPREL	35 | ||
| 3183 | #define R_NIOS2_COPY		36 | ||
| 3184 | #define R_NIOS2_GLOB_DAT	37 | ||
| 3185 | #define R_NIOS2_JUMP_SLOT	38 | ||
| 3186 | #define R_NIOS2_RELATIVE	39 | ||
| 3187 | #define R_NIOS2_GOTOFF		40 | ||
| 3188 | #define R_NIOS2_CALL26_NOAT	41 | ||
| 3189 | #define R_NIOS2_GOT_LO		42 | ||
| 3190 | #define R_NIOS2_GOT_HA		43 | ||
| 3191 | #define R_NIOS2_CALL_LO		44 | ||
| 3192 | #define R_NIOS2_CALL_HA		45 | ||
| 3193 | |||
| 3194 | #define R_OR1K_NONE		0 | ||
| 3195 | #define R_OR1K_32		1 | ||
| 3196 | #define R_OR1K_16		2 | ||
| 3197 | #define R_OR1K_8		3 | ||
| 3198 | #define R_OR1K_LO_16_IN_INSN	4 | ||
| 3199 | #define R_OR1K_HI_16_IN_INSN	5 | ||
| 3200 | #define R_OR1K_INSN_REL_26	6 | ||
| 3201 | #define R_OR1K_GNU_VTENTRY	7 | ||
| 3202 | #define R_OR1K_GNU_VTINHERIT	8 | ||
| 3203 | #define R_OR1K_32_PCREL		9 | ||
| 3204 | #define R_OR1K_16_PCREL		10 | ||
| 3205 | #define R_OR1K_8_PCREL		11 | ||
| 3206 | #define R_OR1K_GOTPC_HI16	12 | ||
| 3207 | #define R_OR1K_GOTPC_LO16	13 | ||
| 3208 | #define R_OR1K_GOT16		14 | ||
| 3209 | #define R_OR1K_PLT26		15 | ||
| 3210 | #define R_OR1K_GOTOFF_HI16	16 | ||
| 3211 | #define R_OR1K_GOTOFF_LO16	17 | ||
| 3212 | #define R_OR1K_COPY		18 | ||
| 3213 | #define R_OR1K_GLOB_DAT		19 | ||
| 3214 | #define R_OR1K_JMP_SLOT		20 | ||
| 3215 | #define R_OR1K_RELATIVE		21 | ||
| 3216 | #define R_OR1K_TLS_GD_HI16	22 | ||
| 3217 | #define R_OR1K_TLS_GD_LO16	23 | ||
| 3218 | #define R_OR1K_TLS_LDM_HI16	24 | ||
| 3219 | #define R_OR1K_TLS_LDM_LO16	25 | ||
| 3220 | #define R_OR1K_TLS_LDO_HI16	26 | ||
| 3221 | #define R_OR1K_TLS_LDO_LO16	27 | ||
| 3222 | #define R_OR1K_TLS_IE_HI16	28 | ||
| 3223 | #define R_OR1K_TLS_IE_LO16	29 | ||
| 3224 | #define R_OR1K_TLS_LE_HI16	30 | ||
| 3225 | #define R_OR1K_TLS_LE_LO16	31 | ||
| 3226 | #define R_OR1K_TLS_TPOFF	32 | ||
| 3227 | #define R_OR1K_TLS_DTPOFF	33 | ||
| 3228 | #define R_OR1K_TLS_DTPMOD	34 | ||
| 3229 | |||
| 3230 | #define R_BPF_NONE		0 | ||
| 3231 | #define R_BPF_MAP_FD		1 | ||
| 3232 | |||
| 3233 | #define R_RISCV_NONE 0 | ||
| 3234 | #define R_RISCV_32 1 | ||
| 3235 | #define R_RISCV_64 2 | ||
| 3236 | #define R_RISCV_RELATIVE 3 | ||
| 3237 | #define R_RISCV_COPY 4 | ||
| 3238 | #define R_RISCV_JUMP_SLOT 5 | ||
| 3239 | #define R_RISCV_TLS_DTPMOD32 6 | ||
| 3240 | #define R_RISCV_TLS_DTPMOD64 7 | ||
| 3241 | #define R_RISCV_TLS_DTPREL32 8 | ||
| 3242 | #define R_RISCV_TLS_DTPREL64 9 | ||
| 3243 | #define R_RISCV_TLS_TPREL32 10 | ||
| 3244 | #define R_RISCV_TLS_TPREL64 11 | ||
| 3245 | |||
| 3246 | #define R_RISCV_BRANCH 16 | ||
| 3247 | #define R_RISCV_JAL 17 | ||
| 3248 | #define R_RISCV_CALL 18 | ||
| 3249 | #define R_RISCV_CALL_PLT 19 | ||
| 3250 | #define R_RISCV_GOT_HI20 20 | ||
| 3251 | #define R_RISCV_TLS_GOT_HI20 21 | ||
| 3252 | #define R_RISCV_TLS_GD_HI20 22 | ||
| 3253 | #define R_RISCV_PCREL_HI20 23 | ||
| 3254 | #define R_RISCV_PCREL_LO12_I 24 | ||
| 3255 | #define R_RISCV_PCREL_LO12_S 25 | ||
| 3256 | #define R_RISCV_HI20 26 | ||
| 3257 | #define R_RISCV_LO12_I 27 | ||
| 3258 | #define R_RISCV_LO12_S 28 | ||
| 3259 | #define R_RISCV_TPREL_HI20 29 | ||
| 3260 | #define R_RISCV_TPREL_LO12_I 30 | ||
| 3261 | #define R_RISCV_TPREL_LO12_S 31 | ||
| 3262 | #define R_RISCV_TPREL_ADD 32 | ||
| 3263 | #define R_RISCV_ADD8 33 | ||
| 3264 | #define R_RISCV_ADD16 34 | ||
| 3265 | #define R_RISCV_ADD32 35 | ||
| 3266 | #define R_RISCV_ADD64 36 | ||
| 3267 | #define R_RISCV_SUB8 37 | ||
| 3268 | #define R_RISCV_SUB16 38 | ||
| 3269 | #define R_RISCV_SUB32 39 | ||
| 3270 | #define R_RISCV_SUB64 40 | ||
| 3271 | #define R_RISCV_GNU_VTINHERIT 41 | ||
| 3272 | #define R_RISCV_GNU_VTENTRY 42 | ||
| 3273 | #define R_RISCV_ALIGN 43 | ||
| 3274 | #define R_RISCV_RVC_BRANCH 44 | ||
| 3275 | #define R_RISCV_RVC_JUMP 45 | ||
| 3276 | #define R_RISCV_RVC_LUI 46 | ||
| 3277 | #define R_RISCV_GPREL_I 47 | ||
| 3278 | #define R_RISCV_GPREL_S 48 | ||
| 3279 | #define R_RISCV_TPREL_I 49 | ||
| 3280 | #define R_RISCV_TPREL_S 50 | ||
| 3281 | #define R_RISCV_RELAX 51 | ||
| 3282 | #define R_RISCV_SUB6 52 | ||
| 3283 | #define R_RISCV_SET6 53 | ||
| 3284 | #define R_RISCV_SET8 54 | ||
| 3285 | #define R_RISCV_SET16 55 | ||
| 3286 | #define R_RISCV_SET32 56 | ||
| 3287 | #define R_RISCV_32_PCREL 57 | ||
| 3288 | |||
| 3289 | #ifdef __cplusplus | ||
| 3290 | } | ||
| 3291 | #endif | ||
| 3292 | |||
| 3293 | |||
| 3294 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/endian.h created+80| ... | @@ -0,0 +1,80 @@ | ||
| 1 | #ifndef _ENDIAN_H | ||
| 2 | #define _ENDIAN_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | #define __NEED_uint16_t | ||
| 7 | #define __NEED_uint32_t | ||
| 8 | #define __NEED_uint64_t | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #define __PDP_ENDIAN 3412 | ||
| 13 | |||
| 14 | #define BIG_ENDIAN __BIG_ENDIAN | ||
| 15 | #define LITTLE_ENDIAN __LITTLE_ENDIAN | ||
| 16 | #define PDP_ENDIAN __PDP_ENDIAN | ||
| 17 | #define BYTE_ORDER __BYTE_ORDER | ||
| 18 | |||
| 19 | static __inline uint16_t __bswap16(uint16_t __x) | ||
| 20 | { | ||
| 21 | 	return __x<<8 | __x>>8; | ||
| 22 | } | ||
| 23 | |||
| 24 | static __inline uint32_t __bswap32(uint32_t __x) | ||
| 25 | { | ||
| 26 | 	return __x>>24 | __x>>8&0xff00 | __x<<8&0xff0000 | __x<<24; | ||
| 27 | } | ||
| 28 | |||
| 29 | static __inline uint64_t __bswap64(uint64_t __x) | ||
| 30 | { | ||
| 31 | 	return __bswap32(__x)+0ULL<<32 | __bswap32(__x>>32); | ||
| 32 | } | ||
| 33 | |||
| 34 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 35 | #define htobe16(x) __bswap16(x) | ||
| 36 | #define be16toh(x) __bswap16(x) | ||
| 37 | #define htobe32(x) __bswap32(x) | ||
| 38 | #define be32toh(x) __bswap32(x) | ||
| 39 | #define htobe64(x) __bswap64(x) | ||
| 40 | #define be64toh(x) __bswap64(x) | ||
| 41 | #define htole16(x) (uint16_t)(x) | ||
| 42 | #define le16toh(x) (uint16_t)(x) | ||
| 43 | #define htole32(x) (uint32_t)(x) | ||
| 44 | #define le32toh(x) (uint32_t)(x) | ||
| 45 | #define htole64(x) (uint64_t)(x) | ||
| 46 | #define le64toh(x) (uint64_t)(x) | ||
| 47 | #else | ||
| 48 | #define htobe16(x) (uint16_t)(x) | ||
| 49 | #define be16toh(x) (uint16_t)(x) | ||
| 50 | #define htobe32(x) (uint32_t)(x) | ||
| 51 | #define be32toh(x) (uint32_t)(x) | ||
| 52 | #define htobe64(x) (uint64_t)(x) | ||
| 53 | #define be64toh(x) (uint64_t)(x) | ||
| 54 | #define htole16(x) __bswap16(x) | ||
| 55 | #define le16toh(x) __bswap16(x) | ||
| 56 | #define htole32(x) __bswap32(x) | ||
| 57 | #define le32toh(x) __bswap32(x) | ||
| 58 | #define htole64(x) __bswap64(x) | ||
| 59 | #define le64toh(x) __bswap64(x) | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 63 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 64 | #define betoh16(x) __bswap16(x) | ||
| 65 | #define betoh32(x) __bswap32(x) | ||
| 66 | #define betoh64(x) __bswap64(x) | ||
| 67 | #define letoh16(x) (uint16_t)(x) | ||
| 68 | #define letoh32(x) (uint32_t)(x) | ||
| 69 | #define letoh64(x) (uint64_t)(x) | ||
| 70 | #else | ||
| 71 | #define betoh16(x) (uint16_t)(x) | ||
| 72 | #define betoh32(x) (uint32_t)(x) | ||
| 73 | #define betoh64(x) (uint64_t)(x) | ||
| 74 | #define letoh16(x) __bswap16(x) | ||
| 75 | #define letoh32(x) __bswap32(x) | ||
| 76 | #define letoh64(x) __bswap64(x) | ||
| 77 | #endif | ||
| 78 | #endif | ||
| 79 | |||
| 80 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/err.h created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #ifndef _ERR_H | ||
| 2 | #define _ERR_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <stdarg.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | void warn(const char *, ...); | ||
| 12 | void vwarn(const char *, va_list); | ||
| 13 | void warnx(const char *, ...); | ||
| 14 | void vwarnx(const char *, va_list); | ||
| 15 | |||
| 16 | _Noreturn void err(int, const char *, ...); | ||
| 17 | _Noreturn void verr(int, const char *, va_list); | ||
| 18 | _Noreturn void errx(int, const char *, ...); | ||
| 19 | _Noreturn void verrx(int, const char *, va_list); | ||
| 20 | |||
| 21 | #ifdef __cplusplus | ||
| 22 | } | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/errno.h created+32| ... | @@ -0,0 +1,32 @@ | ||
| 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 created+246| ... | @@ -0,0 +1,246 @@ | ||
| 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 | #define fallocate64 fallocate | ||
| 207 | #endif | ||
| 208 | #ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */ | ||
| 209 | int name_to_handle_at(int, const char *, struct file_handle *, int *, int); | ||
| 210 | int open_by_handle_at(int, struct file_handle *, int); | ||
| 211 | #endif | ||
| 212 | #ifdef __wasilibc_unmodified_upstream /* WASI has no readahead */ | ||
| 213 | ssize_t readahead(int, off_t, size_t); | ||
| 214 | #endif | ||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no splice, syc_file_range, or tee */ | ||
| 216 | int sync_file_range(int, off_t, off_t, unsigned); | ||
| 217 | ssize_t vmsplice(int, const struct iovec *, size_t, unsigned); | ||
| 218 | ssize_t splice(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 219 | ssize_t tee(int, int, size_t, unsigned); | ||
| 220 | #endif | ||
| 221 | #define loff_t off_t | ||
| 222 | #endif | ||
| 223 | |||
| 224 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 225 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 226 | #define F_GETLK64 F_GETLK | ||
| 227 | #define F_SETLK64 F_SETLK | ||
| 228 | #define F_SETLKW64 F_SETLKW | ||
| 229 | #define flock64 flock | ||
| 230 | #endif | ||
| 231 | #define open64 open | ||
| 232 | #define openat64 openat | ||
| 233 | #define creat64 creat | ||
| 234 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 235 | #define lockf64 lockf | ||
| 236 | #endif | ||
| 237 | #define posix_fadvise64 posix_fadvise | ||
| 238 | #define posix_fallocate64 posix_fallocate | ||
| 239 | #define off64_t off_t | ||
| 240 | #endif | ||
| 241 | |||
| 242 | #ifdef __cplusplus | ||
| 243 | } | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/features.h created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #ifndef _FEATURES_H | ||
| 2 | #define _FEATURES_H | ||
| 3 | |||
| 4 | #if defined(_ALL_SOURCE) && !defined(_GNU_SOURCE) | ||
| 5 | #define _GNU_SOURCE 1 | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #if defined(_DEFAULT_SOURCE) && !defined(_BSD_SOURCE) | ||
| 9 | #define _BSD_SOURCE 1 | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #if !defined(_POSIX_SOURCE) && !defined(_POSIX_C_SOURCE) \ | ||
| 13 | && !defined(_XOPEN_SOURCE) && !defined(_GNU_SOURCE) \ | ||
| 14 | && !defined(_BSD_SOURCE) && !defined(__STRICT_ANSI__) | ||
| 15 | #define _BSD_SOURCE 1 | ||
| 16 | #define _XOPEN_SOURCE 700 | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #if __STDC_VERSION__ >= 199901L | ||
| 20 | #define __restrict restrict | ||
| 21 | #elif !defined(__GNUC__) | ||
| 22 | #define __restrict | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #if __STDC_VERSION__ >= 199901L || defined(__cplusplus) | ||
| 26 | #define __inline inline | ||
| 27 | #elif !defined(__GNUC__) | ||
| 28 | #define __inline | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #if __STDC_VERSION__ >= 201112L | ||
| 32 | #elif defined(__GNUC__) | ||
| 33 | #define _Noreturn __attribute__((__noreturn__)) | ||
| 34 | #else | ||
| 35 | #define _Noreturn | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #define __REDIR(x,y) __typeof__(x) x __asm__(#y) | ||
| 39 | |||
| 40 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/fenv.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 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/wasi/libc-top-half/musl/include/float.h created+56| ... | @@ -0,0 +1,56 @@ | ||
| 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/fmtmsg.h created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #ifndef _FMTMSG_H | ||
| 2 | #define _FMTMSG_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define MM_HARD		1 | ||
| 9 | #define MM_SOFT		2 | ||
| 10 | #define MM_FIRM		4 | ||
| 11 | |||
| 12 | #define MM_APPL		8 | ||
| 13 | #define MM_UTIL		16 | ||
| 14 | #define MM_OPSYS	32 | ||
| 15 | |||
| 16 | #define MM_RECOVER	64 | ||
| 17 | #define MM_NRECOV	128 | ||
| 18 | |||
| 19 | #define MM_PRINT	256 | ||
| 20 | #define MM_CONSOLE	512 | ||
| 21 | |||
| 22 | #define MM_NULLMC	0L | ||
| 23 | |||
| 24 | #define MM_HALT		1 | ||
| 25 | #define MM_ERROR	2 | ||
| 26 | #define MM_WARNING	3 | ||
| 27 | #define MM_INFO		4 | ||
| 28 | #define MM_NOSEV	0 | ||
| 29 | |||
| 30 | #define MM_OK		0 | ||
| 31 | #define MM_NOTOK	(-1) | ||
| 32 | #define MM_NOMSG	1 | ||
| 33 | #define MM_NOCON	4 | ||
| 34 | |||
| 35 | #define MM_NULLLBL	((char*)0) | ||
| 36 | #define MM_NULLTXT	((char*)0) | ||
| 37 | #define MM_NULLACT	((char*)0) | ||
| 38 | #define MM_NULLTAG	((char*)0) | ||
| 39 | #define MM_NULLSEV	0 | ||
| 40 | |||
| 41 | int fmtmsg(long, const char *, int, const char *, const char *, const char *); | ||
| 42 | |||
| 43 | #ifdef __cplusplus | ||
| 44 | } | ||
| 45 | #endif | ||
| 46 | |||
| 47 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/fnmatch.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #ifndef	_FNMATCH_H | ||
| 2 | #define	_FNMATCH_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define	FNM_PATHNAME 0x1 | ||
| 9 | #define	FNM_NOESCAPE 0x2 | ||
| 10 | #define	FNM_PERIOD 0x4 | ||
| 11 | #define	FNM_LEADING_DIR	0x8 | ||
| 12 | #define	FNM_CASEFOLD	0x10 | ||
| 13 | #define	FNM_FILE_NAME	FNM_PATHNAME | ||
| 14 | |||
| 15 | #define	FNM_NOMATCH 1 | ||
| 16 | #define FNM_NOSYS (-1) | ||
| 17 | |||
| 18 | int fnmatch(const char *, const char *, int); | ||
| 19 | |||
| 20 | #ifdef __cplusplus | ||
| 21 | } | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/ftw.h created+45| ... | @@ -0,0 +1,45 @@ | ||
| 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/getopt.h created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #ifndef _GETOPT_H | ||
| 2 | #define _GETOPT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | int getopt(int, char * const [], const char *); | ||
| 9 | extern char *optarg; | ||
| 10 | extern int optind, opterr, optopt, optreset; | ||
| 11 | |||
| 12 | struct option { | ||
| 13 | 	const char *name; | ||
| 14 | 	int has_arg; | ||
| 15 | 	int *flag; | ||
| 16 | 	int val; | ||
| 17 | }; | ||
| 18 | |||
| 19 | int getopt_long(int, char *const *, const char *, const struct option *, int *); | ||
| 20 | int getopt_long_only(int, char *const *, const char *, const struct option *, int *); | ||
| 21 | |||
| 22 | #define no_argument 0 | ||
| 23 | #define required_argument 1 | ||
| 24 | #define optional_argument 2 | ||
| 25 | |||
| 26 | #ifdef __cplusplus | ||
| 27 | } | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/glob.h created+54| ... | @@ -0,0 +1,54 @@ | ||
| 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/grp.h created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | #ifndef	_GRP_H | ||
| 2 | #define	_GRP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | #define __NEED_gid_t | ||
| 12 | |||
| 13 | #ifdef _GNU_SOURCE | ||
| 14 | #define __NEED_FILE | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #include <bits/alltypes.h> | ||
| 18 | |||
| 19 | struct group { | ||
| 20 | 	char *gr_name; | ||
| 21 | 	char *gr_passwd; | ||
| 22 | 	gid_t gr_gid; | ||
| 23 | 	char **gr_mem; | ||
| 24 | }; | ||
| 25 | |||
| 26 | struct group *getgrgid(gid_t); | ||
| 27 | struct group *getgrnam(const char *); | ||
| 28 | |||
| 29 | int getgrgid_r(gid_t, struct group *, char *, size_t, struct group **); | ||
| 30 | int getgrnam_r(const char *, struct group *, char *, size_t, struct group **); | ||
| 31 | |||
| 32 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 33 | struct group *getgrent(void); | ||
| 34 | void endgrent(void); | ||
| 35 | void setgrent(void); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef _GNU_SOURCE | ||
| 39 | struct group *fgetgrent(FILE *); | ||
| 40 | int putgrent(const struct group *, FILE *); | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 44 | int getgrouplist(const char *, gid_t, gid_t *, int *); | ||
| 45 | int setgroups(size_t, const gid_t *); | ||
| 46 | int initgroups(const char *, gid_t); | ||
| 47 | #endif | ||
| 48 | |||
| 49 | #ifdef __cplusplus | ||
| 50 | } | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/iconv.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #ifndef _ICONV_H | ||
| 2 | #define _ICONV_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 void *iconv_t; | ||
| 15 | |||
| 16 | iconv_t iconv_open(const char *, const char *); | ||
| 17 | size_t iconv(iconv_t, char **__restrict, size_t *__restrict, char **__restrict, size_t *__restrict); | ||
| 18 | int iconv_close(iconv_t); | ||
| 19 | |||
| 20 | #ifdef __cplusplus | ||
| 21 | } | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/ifaddrs.h created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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/wasi/libc-top-half/musl/include/inttypes.h created+233| ... | @@ -0,0 +1,233 @@ | ||
| 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/iso646.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _ISO646_H | ||
| 2 | #define _ISO646_H | ||
| 3 | |||
| 4 | #ifndef __cplusplus | ||
| 5 | |||
| 6 | #define and && | ||
| 7 | #define and_eq &= | ||
| 8 | #define bitand & | ||
| 9 | #define bitor | | ||
| 10 | #define compl ~ | ||
| 11 | #define not ! | ||
| 12 | #define not_eq != | ||
| 13 | #define or || | ||
| 14 | #define or_eq |= | ||
| 15 | #define xor ^ | ||
| 16 | #define xor_eq ^= | ||
| 17 | |||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/langinfo.h created+98| ... | @@ -0,0 +1,98 @@ | ||
| 1 | #ifndef _LANGINFO_H | ||
| 2 | #define _LANGINFO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <nl_types.h> | ||
| 10 | |||
| 11 | #define __NEED_locale_t | ||
| 12 | |||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | #define ABDAY_1 0x20000 | ||
| 16 | #define ABDAY_2 0x20001 | ||
| 17 | #define ABDAY_3 0x20002 | ||
| 18 | #define ABDAY_4 0x20003 | ||
| 19 | #define ABDAY_5 0x20004 | ||
| 20 | #define ABDAY_6 0x20005 | ||
| 21 | #define ABDAY_7 0x20006 | ||
| 22 | |||
| 23 | #define DAY_1 0x20007 | ||
| 24 | #define DAY_2 0x20008 | ||
| 25 | #define DAY_3 0x20009 | ||
| 26 | #define DAY_4 0x2000A | ||
| 27 | #define DAY_5 0x2000B | ||
| 28 | #define DAY_6 0x2000C | ||
| 29 | #define DAY_7 0x2000D | ||
| 30 | |||
| 31 | #define ABMON_1 0x2000E | ||
| 32 | #define ABMON_2 0x2000F | ||
| 33 | #define ABMON_3 0x20010 | ||
| 34 | #define ABMON_4 0x20011 | ||
| 35 | #define ABMON_5 0x20012 | ||
| 36 | #define ABMON_6 0x20013 | ||
| 37 | #define ABMON_7 0x20014 | ||
| 38 | #define ABMON_8 0x20015 | ||
| 39 | #define ABMON_9 0x20016 | ||
| 40 | #define ABMON_10 0x20017 | ||
| 41 | #define ABMON_11 0x20018 | ||
| 42 | #define ABMON_12 0x20019 | ||
| 43 | |||
| 44 | #define MON_1 0x2001A | ||
| 45 | #define MON_2 0x2001B | ||
| 46 | #define MON_3 0x2001C | ||
| 47 | #define MON_4 0x2001D | ||
| 48 | #define MON_5 0x2001E | ||
| 49 | #define MON_6 0x2001F | ||
| 50 | #define MON_7 0x20020 | ||
| 51 | #define MON_8 0x20021 | ||
| 52 | #define MON_9 0x20022 | ||
| 53 | #define MON_10 0x20023 | ||
| 54 | #define MON_11 0x20024 | ||
| 55 | #define MON_12 0x20025 | ||
| 56 | |||
| 57 | #define AM_STR 0x20026 | ||
| 58 | #define PM_STR 0x20027 | ||
| 59 | |||
| 60 | #define D_T_FMT 0x20028 | ||
| 61 | #define D_FMT 0x20029 | ||
| 62 | #define T_FMT 0x2002A | ||
| 63 | #define T_FMT_AMPM 0x2002B | ||
| 64 | |||
| 65 | #define ERA 0x2002C | ||
| 66 | #define ERA_D_FMT 0x2002E | ||
| 67 | #define ALT_DIGITS 0x2002F | ||
| 68 | #define ERA_D_T_FMT 0x20030 | ||
| 69 | #define ERA_T_FMT 0x20031 | ||
| 70 | |||
| 71 | #define CODESET 14 | ||
| 72 | |||
| 73 | #define CRNCYSTR 0x4000F | ||
| 74 | |||
| 75 | #define RADIXCHAR 0x10000 | ||
| 76 | #define THOUSEP 0x10001 | ||
| 77 | #define YESEXPR 0x50000 | ||
| 78 | #define NOEXPR 0x50001 | ||
| 79 | |||
| 80 | #define _NL_LOCALE_NAME(cat) (((cat)<<16) | 0xffff) | ||
| 81 | |||
| 82 | #if defined(_GNU_SOURCE) | ||
| 83 | #define NL_LOCALE_NAME(cat) _NL_LOCALE_NAME(cat) | ||
| 84 | #endif | ||
| 85 | |||
| 86 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 87 | #define YESSTR 0x50002 | ||
| 88 | #define NOSTR 0x50003 | ||
| 89 | #endif | ||
| 90 | |||
| 91 | char *nl_langinfo(nl_item); | ||
| 92 | char *nl_langinfo_l(nl_item, locale_t); | ||
| 93 | |||
| 94 | #ifdef __cplusplus | ||
| 95 | } | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/lastlog.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <utmp.h> | ||
lib/libc/wasi/libc-top-half/musl/include/libgen.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #ifndef _LIBGEN_H | ||
| 2 | #define _LIBGEN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | char *dirname(char *); | ||
| 9 | char *basename(char *); | ||
| 10 | |||
| 11 | #ifdef __cplusplus | ||
| 12 | } | ||
| 13 | #endif | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/libintl.h created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #ifndef _LIBINTL_H | ||
| 2 | #define _LIBINTL_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __USE_GNU_GETTEXT 1 | ||
| 9 | #define __GNU_GETTEXT_SUPPORTED_REVISION(major) ((major) == 0 ? 1 : -1) | ||
| 10 | |||
| 11 | #if __GNUC__ >= 3 | ||
| 12 | #define __fa(n) __attribute__ ((__format_arg__ (n))) | ||
| 13 | #else | ||
| 14 | #define __fa(n) | ||
| 15 | #endif | ||
| 16 | |||
| 17 | char *gettext(const char *) __fa(1); | ||
| 18 | char *dgettext(const char *, const char *) __fa(2); | ||
| 19 | char *dcgettext(const char *, const char *, int) __fa(2); | ||
| 20 | char *ngettext(const char *, const char *, unsigned long) __fa(1) __fa(2); | ||
| 21 | char *dngettext(const char *, const char *, const char *, unsigned long) __fa(2) __fa(3); | ||
| 22 | char *dcngettext(const char *, const char *, const char *, unsigned long, int) __fa(2) __fa(3); | ||
| 23 | char *textdomain(const char *); | ||
| 24 | char *bindtextdomain (const char *, const char *); | ||
| 25 | char *bind_textdomain_codeset(const char *, const char *); | ||
| 26 | |||
| 27 | #undef __fa | ||
| 28 | |||
| 29 | #ifdef __cplusplus | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/limits.h created+180| ... | @@ -0,0 +1,180 @@ | ||
| 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 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 69 | #define PTHREAD_KEYS_MAX 128 | ||
| 70 | #define PTHREAD_STACK_MIN 2048 | ||
| 71 | #define PTHREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 72 | #endif | ||
| 73 | #ifdef __wasilibc_unmodified_upstream /* WASI has no semaphores */ | ||
| 74 | #define SEM_VALUE_MAX 0x7fffffff | ||
| 75 | #define SEM_NSEMS_MAX 256 | ||
| 76 | #endif | ||
| 77 | #define DELAYTIMER_MAX 0x7fffffff | ||
| 78 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mq */ | ||
| 79 | #define MQ_PRIO_MAX 32768 | ||
| 80 | #endif | ||
| 81 | #ifdef __wasilibc_unmodified_upstream /* WASI has no usernames */ | ||
| 82 | #define LOGIN_NAME_MAX 256 | ||
| 83 | #endif | ||
| 84 | |||
| 85 | /* Arbitrary numbers... */ | ||
| 86 | |||
| 87 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 88 | #define BC_BASE_MAX 99 | ||
| 89 | #define BC_DIM_MAX 2048 | ||
| 90 | #define BC_SCALE_MAX 99 | ||
| 91 | #define BC_STRING_MAX 1000 | ||
| 92 | #endif | ||
| 93 | #define CHARCLASS_NAME_MAX 14 | ||
| 94 | #define COLL_WEIGHTS_MAX 2 | ||
| 95 | #ifdef __wasilibc_unmodified_upstream /* WASI has no shell commands */ | ||
| 96 | #define EXPR_NEST_MAX 32 | ||
| 97 | #define LINE_MAX 4096 | ||
| 98 | #endif | ||
| 99 | #define RE_DUP_MAX 255 | ||
| 100 | |||
| 101 | #define NL_ARGMAX 9 | ||
| 102 | #define NL_MSGMAX 32767 | ||
| 103 | #define NL_SETMAX 255 | ||
| 104 | #define NL_TEXTMAX 2048 | ||
| 105 | |||
| 106 | #endif | ||
| 107 | |||
| 108 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_XOPEN_SOURCE) | ||
| 109 | |||
| 110 | #ifdef PAGESIZE | ||
| 111 | #define PAGE_SIZE PAGESIZE | ||
| 112 | #endif | ||
| 113 | #define NZERO 20 | ||
| 114 | #define NL_LANGMAX 32 | ||
| 115 | |||
| 116 | #endif | ||
| 117 | |||
| 118 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 119 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 120 | |||
| 121 | #define NL_NMAX 16 | ||
| 122 | |||
| 123 | #endif | ||
| 124 | |||
| 125 | /* POSIX/SUS requirements follow. These numbers come directly | ||
| 126 | * from SUS and have nothing to do with the host system. */ | ||
| 127 | |||
| 128 | #define _POSIX_AIO_LISTIO_MAX 2 | ||
| 129 | #define _POSIX_AIO_MAX 1 | ||
| 130 | #define _POSIX_ARG_MAX 4096 | ||
| 131 | #define _POSIX_CHILD_MAX 25 | ||
| 132 | #define _POSIX_CLOCKRES_MIN 20000000 | ||
| 133 | #define _POSIX_DELAYTIMER_MAX 32 | ||
| 134 | #define _POSIX_HOST_NAME_MAX 255 | ||
| 135 | #define _POSIX_LINK_MAX 8 | ||
| 136 | #define _POSIX_LOGIN_NAME_MAX 9 | ||
| 137 | #define _POSIX_MAX_CANON 255 | ||
| 138 | #define _POSIX_MAX_INPUT 255 | ||
| 139 | #define _POSIX_MQ_OPEN_MAX 8 | ||
| 140 | #define _POSIX_MQ_PRIO_MAX 32 | ||
| 141 | #define _POSIX_NAME_MAX 14 | ||
| 142 | #define _POSIX_NGROUPS_MAX 8 | ||
| 143 | #define _POSIX_OPEN_MAX 20 | ||
| 144 | #define _POSIX_PATH_MAX 256 | ||
| 145 | #define _POSIX_PIPE_BUF 512 | ||
| 146 | #define _POSIX_RE_DUP_MAX 255 | ||
| 147 | #define _POSIX_RTSIG_MAX 8 | ||
| 148 | #define _POSIX_SEM_NSEMS_MAX 256 | ||
| 149 | #define _POSIX_SEM_VALUE_MAX 32767 | ||
| 150 | #define _POSIX_SIGQUEUE_MAX 32 | ||
| 151 | #define _POSIX_SSIZE_MAX 32767 | ||
| 152 | #define _POSIX_STREAM_MAX 8 | ||
| 153 | #define _POSIX_SS_REPL_MAX 4 | ||
| 154 | #define _POSIX_SYMLINK_MAX 255 | ||
| 155 | #define _POSIX_SYMLOOP_MAX 8 | ||
| 156 | #define _POSIX_THREAD_DESTRUCTOR_ITERATIONS 4 | ||
| 157 | #define _POSIX_THREAD_KEYS_MAX 128 | ||
| 158 | #define _POSIX_THREAD_THREADS_MAX 64 | ||
| 159 | #define _POSIX_TIMER_MAX 32 | ||
| 160 | #define _POSIX_TRACE_EVENT_NAME_MAX 30 | ||
| 161 | #define _POSIX_TRACE_NAME_MAX 8 | ||
| 162 | #define _POSIX_TRACE_SYS_MAX 8 | ||
| 163 | #define _POSIX_TRACE_USER_EVENT_MAX 32 | ||
| 164 | #define _POSIX_TTY_NAME_MAX 9 | ||
| 165 | #define _POSIX_TZNAME_MAX 6 | ||
| 166 | #define _POSIX2_BC_BASE_MAX 99 | ||
| 167 | #define _POSIX2_BC_DIM_MAX 2048 | ||
| 168 | #define _POSIX2_BC_SCALE_MAX 99 | ||
| 169 | #define _POSIX2_BC_STRING_MAX 1000 | ||
| 170 | #define _POSIX2_CHARCLASS_NAME_MAX 14 | ||
| 171 | #define _POSIX2_COLL_WEIGHTS_MAX 2 | ||
| 172 | #define _POSIX2_EXPR_NEST_MAX 32 | ||
| 173 | #define _POSIX2_LINE_MAX 2048 | ||
| 174 | #define _POSIX2_RE_DUP_MAX 255 | ||
| 175 | |||
| 176 | #define _XOPEN_IOV_MAX 16 | ||
| 177 | #define _XOPEN_NAME_MAX 255 | ||
| 178 | #define _XOPEN_PATH_MAX 1024 | ||
| 179 | |||
| 180 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/link.h created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | #ifndef _LINK_H | ||
| 2 | #define _LINK_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <elf.h> | ||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_uint32_t | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | #if UINTPTR_MAX > 0xffffffff | ||
| 14 | #define ElfW(type) Elf64_ ## type | ||
| 15 | #else | ||
| 16 | #define ElfW(type) Elf32_ ## type | ||
| 17 | #endif | ||
| 18 | |||
| 19 | #include <bits/link.h> | ||
| 20 | |||
| 21 | struct dl_phdr_info { | ||
| 22 | 	ElfW(Addr) dlpi_addr; | ||
| 23 | 	const char *dlpi_name; | ||
| 24 | 	const ElfW(Phdr) *dlpi_phdr; | ||
| 25 | 	ElfW(Half) dlpi_phnum; | ||
| 26 | 	unsigned long long int dlpi_adds; | ||
| 27 | 	unsigned long long int dlpi_subs; | ||
| 28 | 	size_t dlpi_tls_modid; | ||
| 29 | 	void *dlpi_tls_data; | ||
| 30 | }; | ||
| 31 | |||
| 32 | struct link_map { | ||
| 33 | 	ElfW(Addr) l_addr; | ||
| 34 | 	char *l_name; | ||
| 35 | 	ElfW(Dyn) *l_ld; | ||
| 36 | 	struct link_map *l_next, *l_prev; | ||
| 37 | }; | ||
| 38 | |||
| 39 | struct r_debug { | ||
| 40 | 	int r_version; | ||
| 41 | 	struct link_map *r_map; | ||
| 42 | 	ElfW(Addr) r_brk; | ||
| 43 | 	enum { RT_CONSISTENT, RT_ADD, RT_DELETE } r_state; | ||
| 44 | 	ElfW(Addr) r_ldbase; | ||
| 45 | }; | ||
| 46 | |||
| 47 | int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *), void *); | ||
| 48 | |||
| 49 | #ifdef __cplusplus | ||
| 50 | } | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/locale.h created+91| ... | @@ -0,0 +1,91 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 12 | #define NULL 0L | ||
| 13 | #else | ||
| 14 | #define NULL ((void*)0) | ||
| 15 | #endif | ||
| 16 | #else | ||
| 17 | #define __need_NULL | ||
| 18 | #include <stddef.h> | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #define LC_CTYPE 0 | ||
| 22 | #define LC_NUMERIC 1 | ||
| 23 | #define LC_TIME 2 | ||
| 24 | #define LC_COLLATE 3 | ||
| 25 | #define LC_MONETARY 4 | ||
| 26 | #define LC_MESSAGES 5 | ||
| 27 | #define LC_ALL 6 | ||
| 28 | |||
| 29 | struct lconv { | ||
| 30 | 	char *decimal_point; | ||
| 31 | 	char *thousands_sep; | ||
| 32 | 	char *grouping; | ||
| 33 | |||
| 34 | 	char *int_curr_symbol; | ||
| 35 | 	char *currency_symbol; | ||
| 36 | 	char *mon_decimal_point; | ||
| 37 | 	char *mon_thousands_sep; | ||
| 38 | 	char *mon_grouping; | ||
| 39 | 	char *positive_sign; | ||
| 40 | 	char *negative_sign; | ||
| 41 | 	char int_frac_digits; | ||
| 42 | 	char frac_digits; | ||
| 43 | 	char p_cs_precedes; | ||
| 44 | 	char p_sep_by_space; | ||
| 45 | 	char n_cs_precedes; | ||
| 46 | 	char n_sep_by_space; | ||
| 47 | 	char p_sign_posn; | ||
| 48 | 	char n_sign_posn; | ||
| 49 | 	char int_p_cs_precedes; | ||
| 50 | 	char int_p_sep_by_space; | ||
| 51 | 	char int_n_cs_precedes; | ||
| 52 | 	char int_n_sep_by_space; | ||
| 53 | 	char int_p_sign_posn; | ||
| 54 | 	char int_n_sign_posn; | ||
| 55 | }; | ||
| 56 | |||
| 57 | |||
| 58 | char *setlocale (int, const char *); | ||
| 59 | struct lconv *localeconv(void); | ||
| 60 | |||
| 61 | |||
| 62 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 63 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 64 | |||
| 65 | #define __NEED_locale_t | ||
| 66 | |||
| 67 | #include <bits/alltypes.h> | ||
| 68 | |||
| 69 | #define LC_GLOBAL_LOCALE ((locale_t)-1) | ||
| 70 | |||
| 71 | #define LC_CTYPE_MASK (1<<LC_CTYPE) | ||
| 72 | #define LC_NUMERIC_MASK (1<<LC_NUMERIC) | ||
| 73 | #define LC_TIME_MASK (1<<LC_TIME) | ||
| 74 | #define LC_COLLATE_MASK (1<<LC_COLLATE) | ||
| 75 | #define LC_MONETARY_MASK (1<<LC_MONETARY) | ||
| 76 | #define LC_MESSAGES_MASK (1<<LC_MESSAGES) | ||
| 77 | #define LC_ALL_MASK 0x7fffffff | ||
| 78 | |||
| 79 | locale_t duplocale(locale_t); | ||
| 80 | void freelocale(locale_t); | ||
| 81 | locale_t newlocale(int, const char *, locale_t); | ||
| 82 | locale_t uselocale(locale_t); | ||
| 83 | |||
| 84 | #endif | ||
| 85 | |||
| 86 | |||
| 87 | #ifdef __cplusplus | ||
| 88 | } | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/malloc.h created+33| ... | @@ -0,0 +1,33 @@ | ||
| 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 created+459| ... | @@ -0,0 +1,459 @@ | ||
| 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/memory.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <string.h> | ||
lib/libc/wasi/libc-top-half/musl/include/mntent.h created+43| ... | @@ -0,0 +1,43 @@ | ||
| 1 | #ifndef _MNTENT_H | ||
| 2 | #define _MNTENT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_FILE | ||
| 9 | #include <bits/alltypes.h> | ||
| 10 | |||
| 11 | #define MOUNTED "/etc/mtab" | ||
| 12 | |||
| 13 | #define MNTTYPE_IGNORE	"ignore" | ||
| 14 | #define MNTTYPE_NFS	"nfs" | ||
| 15 | #define MNTTYPE_SWAP	"swap" | ||
| 16 | #define MNTOPT_DEFAULTS	"defaults" | ||
| 17 | #define MNTOPT_RO	"ro" | ||
| 18 | #define MNTOPT_RW	"rw" | ||
| 19 | #define MNTOPT_SUID	"suid" | ||
| 20 | #define MNTOPT_NOSUID	"nosuid" | ||
| 21 | #define MNTOPT_NOAUTO	"noauto" | ||
| 22 | |||
| 23 | struct mntent { | ||
| 24 | 	char *mnt_fsname; | ||
| 25 | 	char *mnt_dir; | ||
| 26 | 	char *mnt_type; | ||
| 27 | 	char *mnt_opts; | ||
| 28 | 	int mnt_freq; | ||
| 29 | 	int mnt_passno; | ||
| 30 | }; | ||
| 31 | |||
| 32 | FILE *setmntent(const char *, const char *); | ||
| 33 | int endmntent(FILE *); | ||
| 34 | struct mntent *getmntent(FILE *); | ||
| 35 | struct mntent *getmntent_r(FILE *, struct mntent *, char *, int); | ||
| 36 | int addmntent(FILE *, const struct mntent *); | ||
| 37 | char *hasmntopt(const struct mntent *, const char *); | ||
| 38 | |||
| 39 | #ifdef __cplusplus | ||
| 40 | } | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/monetary.h created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #ifndef _MONETARY_H | ||
| 2 | #define _MONETARY_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_ssize_t | ||
| 11 | #define __NEED_size_t | ||
| 12 | #define __NEED_locale_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | ssize_t strfmon(char *__restrict, size_t, const char *__restrict, ...); | ||
| 17 | ssize_t strfmon_l(char *__restrict, size_t, locale_t, const char *__restrict, ...); | ||
| 18 | |||
| 19 | #ifdef __cplusplus | ||
| 20 | } | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/mqueue.h created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #ifndef _MQUEUE_H | ||
| 2 | #define _MQUEUE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_ssize_t | ||
| 11 | #define __NEED_pthread_attr_t | ||
| 12 | #define __NEED_time_t | ||
| 13 | #define __NEED_struct_timespec | ||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | typedef int mqd_t; | ||
| 17 | struct mq_attr { | ||
| 18 | 	long mq_flags, mq_maxmsg, mq_msgsize, mq_curmsgs, __unused[4]; | ||
| 19 | }; | ||
| 20 | struct sigevent; | ||
| 21 | |||
| 22 | int mq_close(mqd_t); | ||
| 23 | int mq_getattr(mqd_t, struct mq_attr *); | ||
| 24 | int mq_notify(mqd_t, const struct sigevent *); | ||
| 25 | mqd_t mq_open(const char *, int, ...); | ||
| 26 | ssize_t mq_receive(mqd_t, char *, size_t, unsigned *); | ||
| 27 | int mq_send(mqd_t, const char *, size_t, unsigned); | ||
| 28 | int mq_setattr(mqd_t, const struct mq_attr *__restrict, struct mq_attr *__restrict); | ||
| 29 | ssize_t mq_timedreceive(mqd_t, char *__restrict, size_t, unsigned *__restrict, const struct timespec *__restrict); | ||
| 30 | int mq_timedsend(mqd_t, const char *, size_t, unsigned, const struct timespec *); | ||
| 31 | int mq_unlink(const char *); | ||
| 32 | |||
| 33 | #if _REDIR_TIME64 | ||
| 34 | __REDIR(mq_timedreceive, __mq_timedreceive_time64); | ||
| 35 | __REDIR(mq_timedsend, __mq_timedsend_time64); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef __cplusplus | ||
| 39 | } | ||
| 40 | #endif | ||
| 41 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/net/ethernet.h created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #ifndef _NET_ETHERNET_H | ||
| 2 | #define _NET_ETHERNET_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <netinet/if_ether.h> | ||
| 11 | |||
| 12 | struct ether_addr { | ||
| 13 | 	uint8_t ether_addr_octet[ETH_ALEN]; | ||
| 14 | }; | ||
| 15 | |||
| 16 | struct ether_header { | ||
| 17 | 	uint8_t ether_dhost[ETH_ALEN]; | ||
| 18 | 	uint8_t ether_shost[ETH_ALEN]; | ||
| 19 | 	uint16_t ether_type; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #define	ETHERTYPE_PUP		0x0200 | ||
| 23 | #define ETHERTYPE_SPRITE	0x0500 | ||
| 24 | #define	ETHERTYPE_IP		0x0800 | ||
| 25 | #define	ETHERTYPE_ARP		0x0806 | ||
| 26 | #define	ETHERTYPE_REVARP	0x8035 | ||
| 27 | #define ETHERTYPE_AT		0x809B | ||
| 28 | #define ETHERTYPE_AARP		0x80F3 | ||
| 29 | #define	ETHERTYPE_VLAN		0x8100 | ||
| 30 | #define ETHERTYPE_IPX		0x8137 | ||
| 31 | #define	ETHERTYPE_IPV6		0x86dd | ||
| 32 | #define ETHERTYPE_LOOPBACK	0x9000 | ||
| 33 | |||
| 34 | |||
| 35 | #define	ETHER_ADDR_LEN	ETH_ALEN | ||
| 36 | #define	ETHER_TYPE_LEN	2 | ||
| 37 | #define	ETHER_CRC_LEN	4 | ||
| 38 | #define	ETHER_HDR_LEN	ETH_HLEN | ||
| 39 | #define	ETHER_MIN_LEN	(ETH_ZLEN + ETHER_CRC_LEN) | ||
| 40 | #define	ETHER_MAX_LEN	(ETH_FRAME_LEN + ETHER_CRC_LEN) | ||
| 41 | |||
| 42 | #define	ETHER_IS_VALID_LEN(foo)	\ | ||
| 43 | 	((foo) >= ETHER_MIN_LEN && (foo) <= ETHER_MAX_LEN) | ||
| 44 | |||
| 45 | #define	ETHERTYPE_TRAIL		0x1000 | ||
| 46 | #define	ETHERTYPE_NTRAILER	16 | ||
| 47 | |||
| 48 | #define	ETHERMTU	ETH_DATA_LEN | ||
| 49 | #define	ETHERMIN	(ETHER_MIN_LEN - ETHER_HDR_LEN - ETHER_CRC_LEN) | ||
| 50 | |||
| 51 | #ifdef __cplusplus | ||
| 52 | } | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/net/if.h created+141| ... | @@ -0,0 +1,141 @@ | ||
| 1 | #ifndef _NET_IF_H | ||
| 2 | #define _NET_IF_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define IF_NAMESIZE 16 | ||
| 11 | |||
| 12 | struct if_nameindex { | ||
| 13 | 	unsigned int if_index; | ||
| 14 | 	char *if_name; | ||
| 15 | }; | ||
| 16 | |||
| 17 | unsigned int if_nametoindex (const char *); | ||
| 18 | char *if_indextoname (unsigned int, char *); | ||
| 19 | struct if_nameindex *if_nameindex (void); | ||
| 20 | void if_freenameindex (struct if_nameindex *); | ||
| 21 | |||
| 22 | |||
| 23 | |||
| 24 | |||
| 25 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 26 | |||
| 27 | #include <sys/socket.h> | ||
| 28 | |||
| 29 | #define IFF_UP	0x1 | ||
| 30 | #define IFF_BROADCAST 0x2 | ||
| 31 | #define IFF_DEBUG 0x4 | ||
| 32 | #define IFF_LOOPBACK 0x8 | ||
| 33 | #define IFF_POINTOPOINT 0x10 | ||
| 34 | #define IFF_NOTRAILERS 0x20 | ||
| 35 | #define IFF_RUNNING 0x40 | ||
| 36 | #define IFF_NOARP 0x80 | ||
| 37 | #define IFF_PROMISC 0x100 | ||
| 38 | #define IFF_ALLMULTI 0x200 | ||
| 39 | #define IFF_MASTER 0x400 | ||
| 40 | #define IFF_SLAVE 0x800 | ||
| 41 | #define IFF_MULTICAST 0x1000 | ||
| 42 | #define IFF_PORTSEL 0x2000 | ||
| 43 | #define IFF_AUTOMEDIA 0x4000 | ||
| 44 | #define IFF_DYNAMIC 0x8000 | ||
| 45 | #define IFF_LOWER_UP 0x10000 | ||
| 46 | #define IFF_DORMANT 0x20000 | ||
| 47 | #define IFF_ECHO 0x40000 | ||
| 48 | #define IFF_VOLATILE (IFF_LOOPBACK|IFF_POINTOPOINT|IFF_BROADCAST| \ | ||
| 49 | IFF_ECHO|IFF_MASTER|IFF_SLAVE|IFF_RUNNING|IFF_LOWER_UP|IFF_DORMANT) | ||
| 50 | |||
| 51 | struct ifaddr { | ||
| 52 | 	struct sockaddr ifa_addr; | ||
| 53 | 	union { | ||
| 54 | 		struct sockaddr	ifu_broadaddr; | ||
| 55 | 		struct sockaddr	ifu_dstaddr; | ||
| 56 | 	} ifa_ifu; | ||
| 57 | 	struct iface *ifa_ifp; | ||
| 58 | 	struct ifaddr *ifa_next; | ||
| 59 | }; | ||
| 60 | |||
| 61 | #define ifa_broadaddr	ifa_ifu.ifu_broadaddr | ||
| 62 | #define ifa_dstaddr	ifa_ifu.ifu_dstaddr | ||
| 63 | |||
| 64 | struct ifmap { | ||
| 65 | 	unsigned long int mem_start; | ||
| 66 | 	unsigned long int mem_end; | ||
| 67 | 	unsigned short int base_addr; | ||
| 68 | 	unsigned char irq; | ||
| 69 | 	unsigned char dma; | ||
| 70 | 	unsigned char port; | ||
| 71 | }; | ||
| 72 | |||
| 73 | #define IFHWADDRLEN	6 | ||
| 74 | #define IFNAMSIZ	IF_NAMESIZE | ||
| 75 | |||
| 76 | struct ifreq { | ||
| 77 | 	union { | ||
| 78 | 		char ifrn_name[IFNAMSIZ]; | ||
| 79 | 	} ifr_ifrn; | ||
| 80 | 	union { | ||
| 81 | 		struct sockaddr ifru_addr; | ||
| 82 | 		struct sockaddr ifru_dstaddr; | ||
| 83 | 		struct sockaddr ifru_broadaddr; | ||
| 84 | 		struct sockaddr ifru_netmask; | ||
| 85 | 		struct sockaddr ifru_hwaddr; | ||
| 86 | 		short int ifru_flags; | ||
| 87 | 		int ifru_ivalue; | ||
| 88 | 		int ifru_mtu; | ||
| 89 | 		struct ifmap ifru_map; | ||
| 90 | 		char ifru_slave[IFNAMSIZ]; | ||
| 91 | 		char ifru_newname[IFNAMSIZ]; | ||
| 92 | 		char *ifru_data; | ||
| 93 | 	} ifr_ifru; | ||
| 94 | }; | ||
| 95 | |||
| 96 | #define ifr_name	ifr_ifrn.ifrn_name | ||
| 97 | #define ifr_hwaddr	ifr_ifru.ifru_hwaddr | ||
| 98 | #define ifr_addr	ifr_ifru.ifru_addr | ||
| 99 | #define ifr_dstaddr	ifr_ifru.ifru_dstaddr | ||
| 100 | #define ifr_broadaddr	ifr_ifru.ifru_broadaddr | ||
| 101 | #define ifr_netmask	ifr_ifru.ifru_netmask | ||
| 102 | #define ifr_flags	ifr_ifru.ifru_flags | ||
| 103 | #define ifr_metric	ifr_ifru.ifru_ivalue | ||
| 104 | #define ifr_mtu		ifr_ifru.ifru_mtu | ||
| 105 | #define ifr_map		ifr_ifru.ifru_map | ||
| 106 | #define ifr_slave	ifr_ifru.ifru_slave | ||
| 107 | #define ifr_data	ifr_ifru.ifru_data | ||
| 108 | #define ifr_ifindex	ifr_ifru.ifru_ivalue | ||
| 109 | #define ifr_bandwidth	ifr_ifru.ifru_ivalue | ||
| 110 | #define ifr_qlen	ifr_ifru.ifru_ivalue | ||
| 111 | #define ifr_newname	ifr_ifru.ifru_newname | ||
| 112 | #define _IOT_ifreq	_IOT(_IOTS(char),IFNAMSIZ,_IOTS(char),16,0,0) | ||
| 113 | #define _IOT_ifreq_short _IOT(_IOTS(char),IFNAMSIZ,_IOTS(short),1,0,0) | ||
| 114 | #define _IOT_ifreq_int	_IOT(_IOTS(char),IFNAMSIZ,_IOTS(int),1,0,0) | ||
| 115 | |||
| 116 | struct ifconf { | ||
| 117 | 	int ifc_len;		 | ||
| 118 | 	union { | ||
| 119 | 		char *ifcu_buf; | ||
| 120 | 		struct ifreq *ifcu_req; | ||
| 121 | 	} ifc_ifcu; | ||
| 122 | }; | ||
| 123 | |||
| 124 | #define ifc_buf		ifc_ifcu.ifcu_buf | ||
| 125 | #define ifc_req		ifc_ifcu.ifcu_req | ||
| 126 | #define _IOT_ifconf _IOT(_IOTS(struct ifconf),1,0,0,0,0) | ||
| 127 | |||
| 128 | #define __UAPI_DEF_IF_IFCONF 0 | ||
| 129 | #define __UAPI_DEF_IF_IFMAP 0 | ||
| 130 | #define __UAPI_DEF_IF_IFNAMSIZ 0 | ||
| 131 | #define __UAPI_DEF_IF_IFREQ 0 | ||
| 132 | #define __UAPI_DEF_IF_NET_DEVICE_FLAGS 0 | ||
| 133 | #define __UAPI_DEF_IF_NET_DEVICE_FLAGS_LOWER_UP_DORMANT_ECHO 0 | ||
| 134 | |||
| 135 | #endif | ||
| 136 | |||
| 137 | #ifdef __cplusplus | ||
| 138 | } | ||
| 139 | #endif | ||
| 140 | |||
| 141 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/net/if_arp.h created+142| ... | @@ -0,0 +1,142 @@ | ||
| 1 | /* Nonstandard header */ | ||
| 2 | #ifndef _NET_IF_ARP_H | ||
| 3 | #define _NET_IF_ARP_H | ||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <inttypes.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <sys/socket.h> | ||
| 11 | |||
| 12 | #define MAX_ADDR_LEN	7 | ||
| 13 | |||
| 14 | #define	ARPOP_REQUEST	1 | ||
| 15 | #define	ARPOP_REPLY	2 | ||
| 16 | #define	ARPOP_RREQUEST	3 | ||
| 17 | #define	ARPOP_RREPLY	4 | ||
| 18 | #define	ARPOP_InREQUEST	8 | ||
| 19 | #define	ARPOP_InREPLY	9 | ||
| 20 | #define	ARPOP_NAK	10 | ||
| 21 | |||
| 22 | struct arphdr { | ||
| 23 | 	uint16_t ar_hrd; | ||
| 24 | 	uint16_t ar_pro; | ||
| 25 | 	uint8_t ar_hln; | ||
| 26 | 	uint8_t ar_pln; | ||
| 27 | 	uint16_t ar_op; | ||
| 28 | }; | ||
| 29 | |||
| 30 | |||
| 31 | #define ARPHRD_NETROM	0 | ||
| 32 | #define ARPHRD_ETHER 	1 | ||
| 33 | #define	ARPHRD_EETHER	2 | ||
| 34 | #define	ARPHRD_AX25	3 | ||
| 35 | #define	ARPHRD_PRONET	4 | ||
| 36 | #define	ARPHRD_CHAOS	5 | ||
| 37 | #define	ARPHRD_IEEE802	6 | ||
| 38 | #define	ARPHRD_ARCNET	7 | ||
| 39 | #define	ARPHRD_APPLETLK	8 | ||
| 40 | #define	ARPHRD_DLCI	15 | ||
| 41 | #define	ARPHRD_ATM	19 | ||
| 42 | #define	ARPHRD_METRICOM	23 | ||
| 43 | #define ARPHRD_IEEE1394	24 | ||
| 44 | #define ARPHRD_EUI64		27 | ||
| 45 | #define ARPHRD_INFINIBAND	32 | ||
| 46 | #define ARPHRD_SLIP	256 | ||
| 47 | #define ARPHRD_CSLIP	257 | ||
| 48 | #define ARPHRD_SLIP6	258 | ||
| 49 | #define ARPHRD_CSLIP6	259 | ||
| 50 | #define ARPHRD_RSRVD	260 | ||
| 51 | #define ARPHRD_ADAPT	264 | ||
| 52 | #define ARPHRD_ROSE	270 | ||
| 53 | #define ARPHRD_X25	271 | ||
| 54 | #define ARPHRD_HWX25	272 | ||
| 55 | #define ARPHRD_CAN	280 | ||
| 56 | #define ARPHRD_PPP	512 | ||
| 57 | #define ARPHRD_CISCO	513 | ||
| 58 | #define ARPHRD_HDLC	ARPHRD_CISCO | ||
| 59 | #define ARPHRD_LAPB	516 | ||
| 60 | #define ARPHRD_DDCMP	517 | ||
| 61 | #define	ARPHRD_RAWHDLC	518 | ||
| 62 | #define ARPHRD_RAWIP	519 | ||
| 63 | |||
| 64 | #define ARPHRD_TUNNEL	768 | ||
| 65 | #define ARPHRD_TUNNEL6	769 | ||
| 66 | #define ARPHRD_FRAD	770 | ||
| 67 | #define ARPHRD_SKIP	771 | ||
| 68 | #define ARPHRD_LOOPBACK	772 | ||
| 69 | #define ARPHRD_LOCALTLK 773 | ||
| 70 | #define ARPHRD_FDDI	774 | ||
| 71 | #define ARPHRD_BIF	775 | ||
| 72 | #define ARPHRD_SIT	776 | ||
| 73 | #define ARPHRD_IPDDP	777 | ||
| 74 | #define ARPHRD_IPGRE	778 | ||
| 75 | #define ARPHRD_PIMREG	779 | ||
| 76 | #define ARPHRD_HIPPI	780 | ||
| 77 | #define ARPHRD_ASH	781 | ||
| 78 | #define ARPHRD_ECONET	782 | ||
| 79 | #define ARPHRD_IRDA	783 | ||
| 80 | #define ARPHRD_FCPP	784 | ||
| 81 | #define ARPHRD_FCAL	785 | ||
| 82 | #define ARPHRD_FCPL	786 | ||
| 83 | #define ARPHRD_FCFABRIC 787 | ||
| 84 | #define ARPHRD_IEEE802_TR 800 | ||
| 85 | #define ARPHRD_IEEE80211 801 | ||
| 86 | #define ARPHRD_IEEE80211_PRISM 802 | ||
| 87 | #define ARPHRD_IEEE80211_RADIOTAP 803 | ||
| 88 | #define ARPHRD_IEEE802154 804 | ||
| 89 | #define ARPHRD_IEEE802154_MONITOR 805 | ||
| 90 | #define ARPHRD_PHONET 820 | ||
| 91 | #define ARPHRD_PHONET_PIPE 821 | ||
| 92 | #define ARPHRD_CAIF 822 | ||
| 93 | #define ARPHRD_IP6GRE 823 | ||
| 94 | #define ARPHRD_NETLINK 824 | ||
| 95 | #define ARPHRD_6LOWPAN 825 | ||
| 96 | #define ARPHRD_VSOCKMON 826 | ||
| 97 | |||
| 98 | #define ARPHRD_VOID	 0xFFFF | ||
| 99 | #define ARPHRD_NONE	 0xFFFE | ||
| 100 | |||
| 101 | struct arpreq { | ||
| 102 | 	struct sockaddr arp_pa; | ||
| 103 | 	struct sockaddr arp_ha; | ||
| 104 | 	int arp_flags; | ||
| 105 | 	struct sockaddr arp_netmask; | ||
| 106 | 	char arp_dev[16]; | ||
| 107 | }; | ||
| 108 | |||
| 109 | struct arpreq_old { | ||
| 110 | 	struct sockaddr arp_pa; | ||
| 111 | 	struct sockaddr arp_ha; | ||
| 112 | 	int arp_flags; | ||
| 113 | 	struct sockaddr arp_netmask; | ||
| 114 | }; | ||
| 115 | |||
| 116 | #define ATF_COM		0x02 | ||
| 117 | #define	ATF_PERM	0x04 | ||
| 118 | #define	ATF_PUBL	0x08 | ||
| 119 | #define	ATF_USETRAILERS	0x10 | ||
| 120 | #define ATF_NETMASK 0x20 | ||
| 121 | #define ATF_DONTPUB	0x40 | ||
| 122 | #define ATF_MAGIC	0x80 | ||
| 123 | |||
| 124 | #define ARPD_UPDATE	0x01 | ||
| 125 | #define ARPD_LOOKUP	0x02 | ||
| 126 | #define ARPD_FLUSH	0x03 | ||
| 127 | |||
| 128 | struct arpd_request { | ||
| 129 | 	unsigned short req; | ||
| 130 | 	uint32_t ip; | ||
| 131 | 	unsigned long dev; | ||
| 132 | 	unsigned long stamp; | ||
| 133 | 	unsigned long updated; | ||
| 134 | 	unsigned char ha[MAX_ADDR_LEN]; | ||
| 135 | }; | ||
| 136 | |||
| 137 | |||
| 138 | |||
| 139 | #ifdef __cplusplus | ||
| 140 | } | ||
| 141 | #endif | ||
| 142 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/net/route.h created+124| ... | @@ -0,0 +1,124 @@ | ||
| 1 | #ifndef _NET_ROUTE_H | ||
| 2 | #define _NET_ROUTE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <sys/socket.h> | ||
| 10 | #include <sys/types.h> | ||
| 11 | #include <netinet/in.h> | ||
| 12 | |||
| 13 | |||
| 14 | struct rtentry { | ||
| 15 | 	unsigned long int rt_pad1; | ||
| 16 | 	struct sockaddr rt_dst; | ||
| 17 | 	struct sockaddr rt_gateway; | ||
| 18 | 	struct sockaddr rt_genmask; | ||
| 19 | 	unsigned short int rt_flags; | ||
| 20 | 	short int rt_pad2; | ||
| 21 | 	unsigned long int rt_pad3; | ||
| 22 | 	unsigned char rt_tos; | ||
| 23 | 	unsigned char rt_class; | ||
| 24 | 	short int rt_pad4[sizeof(long)/2-1]; | ||
| 25 | 	short int rt_metric; | ||
| 26 | 	char *rt_dev; | ||
| 27 | 	unsigned long int rt_mtu; | ||
| 28 | 	unsigned long int rt_window; | ||
| 29 | 	unsigned short int rt_irtt; | ||
| 30 | }; | ||
| 31 | |||
| 32 | #define rt_mss	rt_mtu | ||
| 33 | |||
| 34 | |||
| 35 | struct in6_rtmsg { | ||
| 36 | 	struct in6_addr rtmsg_dst; | ||
| 37 | 	struct in6_addr rtmsg_src; | ||
| 38 | 	struct in6_addr rtmsg_gateway; | ||
| 39 | 	uint32_t rtmsg_type; | ||
| 40 | 	uint16_t rtmsg_dst_len; | ||
| 41 | 	uint16_t rtmsg_src_len; | ||
| 42 | 	uint32_t rtmsg_metric; | ||
| 43 | 	unsigned long int rtmsg_info; | ||
| 44 | 	uint32_t rtmsg_flags; | ||
| 45 | 	int rtmsg_ifindex; | ||
| 46 | }; | ||
| 47 | |||
| 48 | |||
| 49 | #define	RTF_UP		0x0001 | ||
| 50 | #define	RTF_GATEWAY	0x0002 | ||
| 51 | |||
| 52 | #define	RTF_HOST	0x0004 | ||
| 53 | #define RTF_REINSTATE	0x0008 | ||
| 54 | #define	RTF_DYNAMIC	0x0010 | ||
| 55 | #define	RTF_MODIFIED	0x0020 | ||
| 56 | #define RTF_MTU		0x0040 | ||
| 57 | #define RTF_MSS		RTF_MTU | ||
| 58 | #define RTF_WINDOW	0x0080 | ||
| 59 | #define RTF_IRTT	0x0100 | ||
| 60 | #define RTF_REJECT	0x0200 | ||
| 61 | #define	RTF_STATIC	0x0400 | ||
| 62 | #define	RTF_XRESOLVE	0x0800 | ||
| 63 | #define RTF_NOFORWARD 0x1000 | ||
| 64 | #define RTF_THROW	0x2000 | ||
| 65 | #define RTF_NOPMTUDISC 0x4000 | ||
| 66 | |||
| 67 | #define RTF_DEFAULT	0x00010000 | ||
| 68 | #define RTF_ALLONLINK	0x00020000 | ||
| 69 | #define RTF_ADDRCONF	0x00040000 | ||
| 70 | |||
| 71 | #define RTF_LINKRT	0x00100000 | ||
| 72 | #define RTF_NONEXTHOP	0x00200000 | ||
| 73 | |||
| 74 | #define RTF_CACHE	0x01000000 | ||
| 75 | #define RTF_FLOW	0x02000000 | ||
| 76 | #define RTF_POLICY	0x04000000 | ||
| 77 | |||
| 78 | #define RTCF_VALVE	0x00200000 | ||
| 79 | #define RTCF_MASQ	0x00400000 | ||
| 80 | #define RTCF_NAT	0x00800000 | ||
| 81 | #define RTCF_DOREDIRECT 0x01000000 | ||
| 82 | #define RTCF_LOG	0x02000000 | ||
| 83 | #define RTCF_DIRECTSRC	0x04000000 | ||
| 84 | |||
| 85 | #define RTF_LOCAL	0x80000000 | ||
| 86 | #define RTF_INTERFACE	0x40000000 | ||
| 87 | #define RTF_MULTICAST	0x20000000 | ||
| 88 | #define RTF_BROADCAST	0x10000000 | ||
| 89 | #define RTF_NAT		0x08000000 | ||
| 90 | |||
| 91 | #define RTF_ADDRCLASSMASK	0xF8000000 | ||
| 92 | #define RT_ADDRCLASS(flags)	((uint32_t) flags >> 23) | ||
| 93 | |||
| 94 | #define RT_TOS(tos)		((tos) & IPTOS_TOS_MASK) | ||
| 95 | |||
| 96 | #define RT_LOCALADDR(flags)	((flags & RTF_ADDRCLASSMASK) \ | ||
| 97 | 				 == (RTF_LOCAL|RTF_INTERFACE)) | ||
| 98 | |||
| 99 | #define RT_CLASS_UNSPEC		0 | ||
| 100 | #define RT_CLASS_DEFAULT	253 | ||
| 101 | |||
| 102 | #define RT_CLASS_MAIN		254 | ||
| 103 | #define RT_CLASS_LOCAL		255 | ||
| 104 | #define RT_CLASS_MAX		255 | ||
| 105 | |||
| 106 | |||
| 107 | #define RTMSG_ACK		NLMSG_ACK | ||
| 108 | #define RTMSG_OVERRUN		NLMSG_OVERRUN | ||
| 109 | |||
| 110 | #define RTMSG_NEWDEVICE		0x11 | ||
| 111 | #define RTMSG_DELDEVICE		0x12 | ||
| 112 | #define RTMSG_NEWROUTE		0x21 | ||
| 113 | #define RTMSG_DELROUTE		0x22 | ||
| 114 | #define RTMSG_NEWRULE		0x31 | ||
| 115 | #define RTMSG_DELRULE		0x32 | ||
| 116 | #define RTMSG_CONTROL		0x40 | ||
| 117 | |||
| 118 | #define RTMSG_AR_FAILED		0x51 | ||
| 119 | |||
| 120 | #ifdef __cplusplus | ||
| 121 | } | ||
| 122 | #endif | ||
| 123 | |||
| 124 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netdb.h created+156| ... | @@ -0,0 +1,156 @@ | ||
| 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_FAMILY -6 | ||
| 48 | #define EAI_SOCKTYPE -7 | ||
| 49 | #define EAI_SERVICE -8 | ||
| 50 | #define EAI_MEMORY -10 | ||
| 51 | #define EAI_SYSTEM -11 | ||
| 52 | #define EAI_OVERFLOW -12 | ||
| 53 | |||
| 54 | int getaddrinfo (const char *__restrict, const char *__restrict, const struct addrinfo *__restrict, struct addrinfo **__restrict); | ||
| 55 | void freeaddrinfo (struct addrinfo *); | ||
| 56 | int getnameinfo (const struct sockaddr *__restrict, socklen_t, char *__restrict, socklen_t, char *__restrict, socklen_t, int); | ||
| 57 | const char *gai_strerror(int); | ||
| 58 | |||
| 59 | |||
| 60 | /* Legacy functions follow (marked OBsolete in SUS) */ | ||
| 61 | |||
| 62 | struct netent { | ||
| 63 | 	char *n_name; | ||
| 64 | 	char **n_aliases; | ||
| 65 | 	int n_addrtype; | ||
| 66 | 	uint32_t n_net; | ||
| 67 | }; | ||
| 68 | |||
| 69 | struct hostent { | ||
| 70 | 	char *h_name; | ||
| 71 | 	char **h_aliases; | ||
| 72 | 	int h_addrtype; | ||
| 73 | 	int h_length; | ||
| 74 | 	char **h_addr_list; | ||
| 75 | }; | ||
| 76 | #define h_addr h_addr_list[0] | ||
| 77 | |||
| 78 | struct servent { | ||
| 79 | 	char *s_name; | ||
| 80 | 	char **s_aliases; | ||
| 81 | 	int s_port; | ||
| 82 | 	char *s_proto; | ||
| 83 | }; | ||
| 84 | |||
| 85 | struct protoent { | ||
| 86 | 	char *p_name; | ||
| 87 | 	char **p_aliases; | ||
| 88 | 	int p_proto; | ||
| 89 | }; | ||
| 90 | |||
| 91 | void sethostent (int); | ||
| 92 | void endhostent (void); | ||
| 93 | struct hostent *gethostent (void); | ||
| 94 | |||
| 95 | void setnetent (int); | ||
| 96 | void endnetent (void); | ||
| 97 | struct netent *getnetent (void); | ||
| 98 | struct netent *getnetbyaddr (uint32_t, int); | ||
| 99 | struct netent *getnetbyname (const char *); | ||
| 100 | |||
| 101 | void setservent (int); | ||
| 102 | void endservent (void); | ||
| 103 | struct servent *getservent (void); | ||
| 104 | struct servent *getservbyname (const char *, const char *); | ||
| 105 | struct servent *getservbyport (int, const char *); | ||
| 106 | |||
| 107 | void setprotoent (int); | ||
| 108 | void endprotoent (void); | ||
| 109 | struct protoent *getprotoent (void); | ||
| 110 | struct protoent *getprotobyname (const char *); | ||
| 111 | struct protoent *getprotobynumber (int); | ||
| 112 | |||
| 113 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | ||
| 114 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | ||
| 115 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 116 | struct hostent *gethostbyname (const char *); | ||
| 117 | struct hostent *gethostbyaddr (const void *, socklen_t, int); | ||
| 118 | #ifdef __GNUC__ | ||
| 119 | __attribute__((const)) | ||
| 120 | #endif | ||
| 121 | int *__h_errno_location(void); | ||
| 122 | #define h_errno (*__h_errno_location()) | ||
| 123 | #define HOST_NOT_FOUND 1 | ||
| 124 | #define TRY_AGAIN 2 | ||
| 125 | #define NO_RECOVERY 3 | ||
| 126 | #define NO_DATA 4 | ||
| 127 | #define NO_ADDRESS NO_DATA | ||
| 128 | #endif | ||
| 129 | |||
| 130 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 131 | void herror(const char *); | ||
| 132 | const char *hstrerror(int); | ||
| 133 | int gethostbyname_r(const char *, struct hostent *, char *, size_t, struct hostent **, int *); | ||
| 134 | int gethostbyname2_r(const char *, int, struct hostent *, char *, size_t, struct hostent **, int *); | ||
| 135 | struct hostent *gethostbyname2(const char *, int); | ||
| 136 | int gethostbyaddr_r(const void *, socklen_t, int, struct hostent *, char *, size_t, struct hostent **, int *); | ||
| 137 | int getservbyport_r(int, const char *, struct servent *, char *, size_t, struct servent **); | ||
| 138 | int getservbyname_r(const char *, const char *, struct servent *, char *, size_t, struct servent **); | ||
| 139 | #define EAI_NODATA -5 | ||
| 140 | #define EAI_ADDRFAMILY -9 | ||
| 141 | #define EAI_INPROGRESS -100 | ||
| 142 | #define EAI_CANCELED -101 | ||
| 143 | #define EAI_NOTCANCELED -102 | ||
| 144 | #define EAI_ALLDONE -103 | ||
| 145 | #define EAI_INTR -104 | ||
| 146 | #define EAI_IDN_ENCODE -105 | ||
| 147 | #define NI_MAXHOST 255 | ||
| 148 | #define NI_MAXSERV 32 | ||
| 149 | #endif | ||
| 150 | |||
| 151 | |||
| 152 | #ifdef __cplusplus | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | |||
| 156 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/ether.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #ifndef _NETINET_ETHER_H | ||
| 2 | #define _NETINET_ETHER_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <netinet/if_ether.h> | ||
| 9 | |||
| 10 | char *ether_ntoa (const struct ether_addr *); | ||
| 11 | struct ether_addr *ether_aton (const char *); | ||
| 12 | char *ether_ntoa_r (const struct ether_addr *, char *); | ||
| 13 | struct ether_addr *ether_aton_r (const char *, struct ether_addr *); | ||
| 14 | int ether_line(const char *, struct ether_addr *, char *); | ||
| 15 | int ether_ntohost(char *, const struct ether_addr *); | ||
| 16 | int ether_hostton(const char *, struct ether_addr *); | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/icmp6.h created+305| ... | @@ -0,0 +1,305 @@ | ||
| 1 | #ifndef _NETINET_ICMP6_H | ||
| 2 | #define _NETINET_ICMP6_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include <sys/types.h> | ||
| 11 | #include <netinet/in.h> | ||
| 12 | |||
| 13 | #define ICMP6_FILTER 1 | ||
| 14 | |||
| 15 | #define ICMP6_FILTER_BLOCK		1 | ||
| 16 | #define ICMP6_FILTER_PASS		2 | ||
| 17 | #define ICMP6_FILTER_BLOCKOTHERS	3 | ||
| 18 | #define ICMP6_FILTER_PASSONLY		4 | ||
| 19 | |||
| 20 | struct icmp6_filter { | ||
| 21 | 	uint32_t icmp6_filt[8]; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct icmp6_hdr { | ||
| 25 | 	uint8_t icmp6_type; | ||
| 26 | 	uint8_t icmp6_code; | ||
| 27 | 	uint16_t icmp6_cksum; | ||
| 28 | 	union { | ||
| 29 | 		uint32_t icmp6_un_data32[1]; | ||
| 30 | 		uint16_t icmp6_un_data16[2]; | ||
| 31 | 		uint8_t icmp6_un_data8[4]; | ||
| 32 | 	} icmp6_dataun; | ||
| 33 | }; | ||
| 34 | |||
| 35 | #define icmp6_data32 icmp6_dataun.icmp6_un_data32 | ||
| 36 | #define icmp6_data16 icmp6_dataun.icmp6_un_data16 | ||
| 37 | #define icmp6_data8 icmp6_dataun.icmp6_un_data8 | ||
| 38 | #define icmp6_pptr icmp6_data32[0] | ||
| 39 | #define icmp6_mtu icmp6_data32[0] | ||
| 40 | #define icmp6_id icmp6_data16[0] | ||
| 41 | #define icmp6_seq icmp6_data16[1] | ||
| 42 | #define icmp6_maxdelay icmp6_data16[0] | ||
| 43 | |||
| 44 | #define ICMP6_DST_UNREACH 1 | ||
| 45 | #define ICMP6_PACKET_TOO_BIG 2 | ||
| 46 | #define ICMP6_TIME_EXCEEDED 3 | ||
| 47 | #define ICMP6_PARAM_PROB 4 | ||
| 48 | |||
| 49 | #define ICMP6_INFOMSG_MASK 0x80 | ||
| 50 | |||
| 51 | #define ICMP6_ECHO_REQUEST 128 | ||
| 52 | #define ICMP6_ECHO_REPLY 129 | ||
| 53 | #define MLD_LISTENER_QUERY 130 | ||
| 54 | #define MLD_LISTENER_REPORT 131 | ||
| 55 | #define MLD_LISTENER_REDUCTION 132 | ||
| 56 | |||
| 57 | #define ICMP6_DST_UNREACH_NOROUTE 0 | ||
| 58 | #define ICMP6_DST_UNREACH_ADMIN 1 | ||
| 59 | #define ICMP6_DST_UNREACH_BEYONDSCOPE 2 | ||
| 60 | #define ICMP6_DST_UNREACH_ADDR 3 | ||
| 61 | #define ICMP6_DST_UNREACH_NOPORT 4 | ||
| 62 | |||
| 63 | #define ICMP6_TIME_EXCEED_TRANSIT 0 | ||
| 64 | #define ICMP6_TIME_EXCEED_REASSEMBLY 1 | ||
| 65 | |||
| 66 | #define ICMP6_PARAMPROB_HEADER 0 | ||
| 67 | #define ICMP6_PARAMPROB_NEXTHEADER 1 | ||
| 68 | #define ICMP6_PARAMPROB_OPTION 2 | ||
| 69 | |||
| 70 | #define ICMP6_FILTER_WILLPASS(type, filterp) \ | ||
| 71 | 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) == 0) | ||
| 72 | |||
| 73 | #define ICMP6_FILTER_WILLBLOCK(type, filterp) \ | ||
| 74 | 	((((filterp)->icmp6_filt[(type) >> 5]) & (1 << ((type) & 31))) != 0) | ||
| 75 | |||
| 76 | #define ICMP6_FILTER_SETPASS(type, filterp) \ | ||
| 77 | 	((((filterp)->icmp6_filt[(type) >> 5]) &= ~(1 << ((type) & 31)))) | ||
| 78 | |||
| 79 | #define ICMP6_FILTER_SETBLOCK(type, filterp) \ | ||
| 80 | 	((((filterp)->icmp6_filt[(type) >> 5]) |= (1 << ((type) & 31)))) | ||
| 81 | |||
| 82 | #define ICMP6_FILTER_SETPASSALL(filterp) \ | ||
| 83 | 	memset (filterp, 0, sizeof (struct icmp6_filter)); | ||
| 84 | |||
| 85 | #define ICMP6_FILTER_SETBLOCKALL(filterp) \ | ||
| 86 | 	memset (filterp, 0xFF, sizeof (struct icmp6_filter)); | ||
| 87 | |||
| 88 | #define ND_ROUTER_SOLICIT 133 | ||
| 89 | #define ND_ROUTER_ADVERT 134 | ||
| 90 | #define ND_NEIGHBOR_SOLICIT 135 | ||
| 91 | #define ND_NEIGHBOR_ADVERT 136 | ||
| 92 | #define ND_REDIRECT 137 | ||
| 93 | |||
| 94 | struct nd_router_solicit { | ||
| 95 | 	struct icmp6_hdr nd_rs_hdr; | ||
| 96 | }; | ||
| 97 | |||
| 98 | #define nd_rs_type nd_rs_hdr.icmp6_type | ||
| 99 | #define nd_rs_code nd_rs_hdr.icmp6_code | ||
| 100 | #define nd_rs_cksum nd_rs_hdr.icmp6_cksum | ||
| 101 | #define nd_rs_reserved nd_rs_hdr.icmp6_data32[0] | ||
| 102 | |||
| 103 | struct nd_router_advert { | ||
| 104 | 	struct icmp6_hdr nd_ra_hdr; | ||
| 105 | 	uint32_t nd_ra_reachable; | ||
| 106 | 	uint32_t nd_ra_retransmit; | ||
| 107 | }; | ||
| 108 | |||
| 109 | #define nd_ra_type nd_ra_hdr.icmp6_type | ||
| 110 | #define nd_ra_code nd_ra_hdr.icmp6_code | ||
| 111 | #define nd_ra_cksum nd_ra_hdr.icmp6_cksum | ||
| 112 | #define nd_ra_curhoplimit nd_ra_hdr.icmp6_data8[0] | ||
| 113 | #define nd_ra_flags_reserved nd_ra_hdr.icmp6_data8[1] | ||
| 114 | #define ND_RA_FLAG_MANAGED 0x80 | ||
| 115 | #define ND_RA_FLAG_OTHER 0x40 | ||
| 116 | #define ND_RA_FLAG_HOME_AGENT 0x20 | ||
| 117 | #define nd_ra_router_lifetime nd_ra_hdr.icmp6_data16[1] | ||
| 118 | |||
| 119 | struct nd_neighbor_solicit { | ||
| 120 | 	struct icmp6_hdr nd_ns_hdr; | ||
| 121 | 	struct in6_addr nd_ns_target; | ||
| 122 | }; | ||
| 123 | |||
| 124 | #define nd_ns_type nd_ns_hdr.icmp6_type | ||
| 125 | #define nd_ns_code nd_ns_hdr.icmp6_code | ||
| 126 | #define nd_ns_cksum nd_ns_hdr.icmp6_cksum | ||
| 127 | #define nd_ns_reserved nd_ns_hdr.icmp6_data32[0] | ||
| 128 | |||
| 129 | struct nd_neighbor_advert { | ||
| 130 | 	struct icmp6_hdr nd_na_hdr; | ||
| 131 | 	struct in6_addr nd_na_target; | ||
| 132 | }; | ||
| 133 | |||
| 134 | #define nd_na_type nd_na_hdr.icmp6_type | ||
| 135 | #define nd_na_code nd_na_hdr.icmp6_code | ||
| 136 | #define nd_na_cksum nd_na_hdr.icmp6_cksum | ||
| 137 | #define nd_na_flags_reserved nd_na_hdr.icmp6_data32[0] | ||
| 138 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 139 | #define ND_NA_FLAG_ROUTER 0x80000000 | ||
| 140 | #define ND_NA_FLAG_SOLICITED 0x40000000 | ||
| 141 | #define ND_NA_FLAG_OVERRIDE 0x20000000 | ||
| 142 | #else | ||
| 143 | #define ND_NA_FLAG_ROUTER 0x00000080 | ||
| 144 | #define ND_NA_FLAG_SOLICITED 0x00000040 | ||
| 145 | #define ND_NA_FLAG_OVERRIDE 0x00000020 | ||
| 146 | #endif | ||
| 147 | |||
| 148 | struct nd_redirect { | ||
| 149 | 	struct icmp6_hdr nd_rd_hdr; | ||
| 150 | 	struct in6_addr nd_rd_target; | ||
| 151 | 	struct in6_addr nd_rd_dst; | ||
| 152 | }; | ||
| 153 | |||
| 154 | #define nd_rd_type nd_rd_hdr.icmp6_type | ||
| 155 | #define nd_rd_code nd_rd_hdr.icmp6_code | ||
| 156 | #define nd_rd_cksum nd_rd_hdr.icmp6_cksum | ||
| 157 | #define nd_rd_reserved nd_rd_hdr.icmp6_data32[0] | ||
| 158 | |||
| 159 | struct nd_opt_hdr { | ||
| 160 | 	uint8_t nd_opt_type; | ||
| 161 | 	uint8_t nd_opt_len; | ||
| 162 | }; | ||
| 163 | |||
| 164 | #define ND_OPT_SOURCE_LINKADDR		1 | ||
| 165 | #define ND_OPT_TARGET_LINKADDR		2 | ||
| 166 | #define ND_OPT_PREFIX_INFORMATION	3 | ||
| 167 | #define ND_OPT_REDIRECTED_HEADER	4 | ||
| 168 | #define ND_OPT_MTU			5 | ||
| 169 | #define ND_OPT_RTR_ADV_INTERVAL		7 | ||
| 170 | #define ND_OPT_HOME_AGENT_INFO		8 | ||
| 171 | |||
| 172 | struct nd_opt_prefix_info { | ||
| 173 | 	uint8_t nd_opt_pi_type; | ||
| 174 | 	uint8_t nd_opt_pi_len; | ||
| 175 | 	uint8_t nd_opt_pi_prefix_len; | ||
| 176 | 	uint8_t nd_opt_pi_flags_reserved; | ||
| 177 | 	uint32_t nd_opt_pi_valid_time; | ||
| 178 | 	uint32_t nd_opt_pi_preferred_time; | ||
| 179 | 	uint32_t nd_opt_pi_reserved2; | ||
| 180 | 	struct in6_addr nd_opt_pi_prefix; | ||
| 181 | }; | ||
| 182 | |||
| 183 | #define ND_OPT_PI_FLAG_ONLINK	0x80 | ||
| 184 | #define ND_OPT_PI_FLAG_AUTO	0x40 | ||
| 185 | #define ND_OPT_PI_FLAG_RADDR	0x20 | ||
| 186 | |||
| 187 | struct nd_opt_rd_hdr { | ||
| 188 | 	uint8_t nd_opt_rh_type; | ||
| 189 | 	uint8_t nd_opt_rh_len; | ||
| 190 | 	uint16_t nd_opt_rh_reserved1; | ||
| 191 | 	uint32_t nd_opt_rh_reserved2; | ||
| 192 | }; | ||
| 193 | |||
| 194 | struct nd_opt_mtu { | ||
| 195 | 	uint8_t nd_opt_mtu_type; | ||
| 196 | 	uint8_t nd_opt_mtu_len; | ||
| 197 | 	uint16_t nd_opt_mtu_reserved; | ||
| 198 | 	uint32_t nd_opt_mtu_mtu; | ||
| 199 | }; | ||
| 200 | |||
| 201 | struct mld_hdr { | ||
| 202 | 	struct icmp6_hdr mld_icmp6_hdr; | ||
| 203 | 	struct in6_addr mld_addr; | ||
| 204 | }; | ||
| 205 | |||
| 206 | #define mld_type mld_icmp6_hdr.icmp6_type | ||
| 207 | #define mld_code mld_icmp6_hdr.icmp6_code | ||
| 208 | #define mld_cksum mld_icmp6_hdr.icmp6_cksum | ||
| 209 | #define mld_maxdelay mld_icmp6_hdr.icmp6_data16[0] | ||
| 210 | #define mld_reserved mld_icmp6_hdr.icmp6_data16[1] | ||
| 211 | |||
| 212 | #define ICMP6_ROUTER_RENUMBERING 138 | ||
| 213 | |||
| 214 | struct icmp6_router_renum { | ||
| 215 | 	struct icmp6_hdr rr_hdr; | ||
| 216 | 	uint8_t rr_segnum; | ||
| 217 | 	uint8_t rr_flags; | ||
| 218 | 	uint16_t rr_maxdelay; | ||
| 219 | 	uint32_t rr_reserved; | ||
| 220 | }; | ||
| 221 | |||
| 222 | #define rr_type		rr_hdr.icmp6_type | ||
| 223 | #define rr_code rr_hdr.icmp6_code | ||
| 224 | #define rr_cksum rr_hdr.icmp6_cksum | ||
| 225 | #define rr_seqnum rr_hdr.icmp6_data32[0] | ||
| 226 | |||
| 227 | #define ICMP6_RR_FLAGS_TEST 0x80 | ||
| 228 | #define ICMP6_RR_FLAGS_REQRESULT 0x40 | ||
| 229 | #define ICMP6_RR_FLAGS_FORCEAPPLY 0x20 | ||
| 230 | #define ICMP6_RR_FLAGS_SPECSITE 0x10 | ||
| 231 | #define ICMP6_RR_FLAGS_PREVDONE 0x08 | ||
| 232 | |||
| 233 | struct rr_pco_match { | ||
| 234 | 	uint8_t rpm_code; | ||
| 235 | 	uint8_t rpm_len; | ||
| 236 | 	uint8_t rpm_ordinal; | ||
| 237 | 	uint8_t rpm_matchlen; | ||
| 238 | 	uint8_t rpm_minlen; | ||
| 239 | 	uint8_t rpm_maxlen; | ||
| 240 | 	uint16_t rpm_reserved; | ||
| 241 | 	struct in6_addr rpm_prefix; | ||
| 242 | }; | ||
| 243 | |||
| 244 | #define RPM_PCO_ADD 1 | ||
| 245 | #define RPM_PCO_CHANGE 2 | ||
| 246 | #define RPM_PCO_SETGLOBAL 3 | ||
| 247 | |||
| 248 | struct rr_pco_use { | ||
| 249 | 	uint8_t rpu_uselen; | ||
| 250 | 	uint8_t rpu_keeplen; | ||
| 251 | 	uint8_t rpu_ramask; | ||
| 252 | 	uint8_t rpu_raflags; | ||
| 253 | 	uint32_t rpu_vltime; | ||
| 254 | 	uint32_t rpu_pltime; | ||
| 255 | 	uint32_t rpu_flags; | ||
| 256 | 	struct in6_addr rpu_prefix; | ||
| 257 | }; | ||
| 258 | |||
| 259 | #define ICMP6_RR_PCOUSE_RAFLAGS_ONLINK 0x20 | ||
| 260 | #define ICMP6_RR_PCOUSE_RAFLAGS_AUTO 0x10 | ||
| 261 | |||
| 262 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 263 | #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80000000 | ||
| 264 | #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40000000 | ||
| 265 | #else | ||
| 266 | #define ICMP6_RR_PCOUSE_FLAGS_DECRVLTIME 0x80 | ||
| 267 | #define ICMP6_RR_PCOUSE_FLAGS_DECRPLTIME 0x40 | ||
| 268 | #endif | ||
| 269 | |||
| 270 | struct rr_result { | ||
| 271 | 	uint16_t rrr_flags; | ||
| 272 | 	uint8_t rrr_ordinal; | ||
| 273 | 	uint8_t rrr_matchedlen; | ||
| 274 | 	uint32_t rrr_ifid; | ||
| 275 | 	struct in6_addr rrr_prefix; | ||
| 276 | }; | ||
| 277 | |||
| 278 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 279 | #define ICMP6_RR_RESULT_FLAGS_OOB 0x0002 | ||
| 280 | #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0001 | ||
| 281 | #else | ||
| 282 | #define ICMP6_RR_RESULT_FLAGS_OOB 0x0200 | ||
| 283 | #define ICMP6_RR_RESULT_FLAGS_FORBIDDEN 0x0100 | ||
| 284 | #endif | ||
| 285 | |||
| 286 | struct nd_opt_adv_interval { | ||
| 287 | 	uint8_t nd_opt_adv_interval_type; | ||
| 288 | 	uint8_t nd_opt_adv_interval_len; | ||
| 289 | 	uint16_t nd_opt_adv_interval_reserved; | ||
| 290 | 	uint32_t nd_opt_adv_interval_ival; | ||
| 291 | }; | ||
| 292 | |||
| 293 | struct nd_opt_home_agent_info { | ||
| 294 | 	uint8_t nd_opt_home_agent_info_type; | ||
| 295 | 	uint8_t nd_opt_home_agent_info_len; | ||
| 296 | 	uint16_t nd_opt_home_agent_info_reserved; | ||
| 297 | 	uint16_t nd_opt_home_agent_info_preference; | ||
| 298 | 	uint16_t nd_opt_home_agent_info_lifetime; | ||
| 299 | }; | ||
| 300 | |||
| 301 | #ifdef __cplusplus | ||
| 302 | } | ||
| 303 | #endif | ||
| 304 | |||
| 305 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/if_ether.h created+148| ... | @@ -0,0 +1,148 @@ | ||
| 1 | #ifndef _NETINET_IF_ETHER_H | ||
| 2 | #define _NETINET_IF_ETHER_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <sys/types.h> | ||
| 6 | |||
| 7 | #define ETH_ALEN	6 | ||
| 8 | #define ETH_TLEN	2 | ||
| 9 | #define ETH_HLEN	14 | ||
| 10 | #define ETH_ZLEN	60 | ||
| 11 | #define ETH_DATA_LEN	1500 | ||
| 12 | #define ETH_FRAME_LEN	1514 | ||
| 13 | #define ETH_FCS_LEN	4 | ||
| 14 | #define ETH_MIN_MTU	68 | ||
| 15 | #define ETH_MAX_MTU	0xFFFFU | ||
| 16 | |||
| 17 | #define ETH_P_LOOP	0x0060 | ||
| 18 | #define ETH_P_PUP	0x0200 | ||
| 19 | #define ETH_P_PUPAT	0x0201 | ||
| 20 | #define ETH_P_TSN	0x22F0 | ||
| 21 | #define ETH_P_ERSPAN2	0x22EB | ||
| 22 | #define ETH_P_IP	0x0800 | ||
| 23 | #define ETH_P_X25	0x0805 | ||
| 24 | #define ETH_P_ARP	0x0806 | ||
| 25 | #define	ETH_P_BPQ	0x08FF | ||
| 26 | #define ETH_P_IEEEPUP	0x0a00 | ||
| 27 | #define ETH_P_IEEEPUPAT	0x0a01 | ||
| 28 | #define ETH_P_BATMAN	0x4305 | ||
| 29 | #define ETH_P_DEC 0x6000 | ||
| 30 | #define ETH_P_DNA_DL 0x6001 | ||
| 31 | #define ETH_P_DNA_RC 0x6002 | ||
| 32 | #define ETH_P_DNA_RT 0x6003 | ||
| 33 | #define ETH_P_LAT 0x6004 | ||
| 34 | #define ETH_P_DIAG 0x6005 | ||
| 35 | #define ETH_P_CUST 0x6006 | ||
| 36 | #define ETH_P_SCA 0x6007 | ||
| 37 | #define ETH_P_TEB	0x6558 | ||
| 38 | #define ETH_P_RARP 0x8035 | ||
| 39 | #define ETH_P_ATALK	0x809B | ||
| 40 | #define ETH_P_AARP	0x80F3 | ||
| 41 | #define ETH_P_8021Q	0x8100 | ||
| 42 | #define ETH_P_IPX	0x8137 | ||
| 43 | #define ETH_P_IPV6	0x86DD | ||
| 44 | #define ETH_P_PAUSE	0x8808 | ||
| 45 | #define ETH_P_SLOW	0x8809 | ||
| 46 | #define ETH_P_WCCP	0x883E | ||
| 47 | #define ETH_P_MPLS_UC	0x8847 | ||
| 48 | #define ETH_P_MPLS_MC	0x8848 | ||
| 49 | #define ETH_P_ATMMPOA	0x884c | ||
| 50 | #define ETH_P_PPP_DISC	0x8863 | ||
| 51 | #define ETH_P_PPP_SES	0x8864 | ||
| 52 | #define ETH_P_LINK_CTL	0x886c | ||
| 53 | #define ETH_P_ATMFATE	0x8884 | ||
| 54 | #define ETH_P_PAE	0x888E | ||
| 55 | #define ETH_P_AOE	0x88A2 | ||
| 56 | #define ETH_P_8021AD	0x88A8 | ||
| 57 | #define ETH_P_802_EX1	0x88B5 | ||
| 58 | #define ETH_P_ERSPAN	0x88BE | ||
| 59 | #define ETH_P_PREAUTH	0x88C7 | ||
| 60 | #define ETH_P_TIPC	0x88CA | ||
| 61 | #define ETH_P_LLDP	0x88CC | ||
| 62 | #define ETH_P_MRP	0x88E3 | ||
| 63 | #define ETH_P_MACSEC	0x88E5 | ||
| 64 | #define ETH_P_8021AH	0x88E7 | ||
| 65 | #define ETH_P_MVRP	0x88F5 | ||
| 66 | #define ETH_P_1588	0x88F7 | ||
| 67 | #define ETH_P_NCSI	0x88F8 | ||
| 68 | #define ETH_P_PRP	0x88FB | ||
| 69 | #define ETH_P_FCOE	0x8906 | ||
| 70 | #define ETH_P_TDLS	0x890D | ||
| 71 | #define ETH_P_FIP	0x8914 | ||
| 72 | #define ETH_P_IBOE	0x8915 | ||
| 73 | #define ETH_P_80221	0x8917 | ||
| 74 | #define ETH_P_HSR	0x892F | ||
| 75 | #define ETH_P_NSH	0x894F | ||
| 76 | #define ETH_P_LOOPBACK	0x9000 | ||
| 77 | #define ETH_P_QINQ1	0x9100 | ||
| 78 | #define ETH_P_QINQ2	0x9200 | ||
| 79 | #define ETH_P_QINQ3	0x9300 | ||
| 80 | #define ETH_P_EDSA	0xDADA | ||
| 81 | #define ETH_P_DSA_8021Q	0xDADB | ||
| 82 | #define ETH_P_IFE	0xED3E | ||
| 83 | #define ETH_P_AF_IUCV	0xFBFB | ||
| 84 | |||
| 85 | #define ETH_P_802_3_MIN	0x0600 | ||
| 86 | |||
| 87 | #define ETH_P_802_3	0x0001 | ||
| 88 | #define ETH_P_AX25	0x0002 | ||
| 89 | #define ETH_P_ALL	0x0003 | ||
| 90 | #define ETH_P_802_2	0x0004 | ||
| 91 | #define ETH_P_SNAP	0x0005 | ||
| 92 | #define ETH_P_DDCMP 0x0006 | ||
| 93 | #define ETH_P_WAN_PPP 0x0007 | ||
| 94 | #define ETH_P_PPP_MP 0x0008 | ||
| 95 | #define ETH_P_LOCALTALK 0x0009 | ||
| 96 | #define ETH_P_CAN	0x000C | ||
| 97 | #define ETH_P_CANFD	0x000D | ||
| 98 | #define ETH_P_PPPTALK	0x0010 | ||
| 99 | #define ETH_P_TR_802_2	0x0011 | ||
| 100 | #define ETH_P_MOBITEX	0x0015 | ||
| 101 | #define ETH_P_CONTROL	0x0016 | ||
| 102 | #define ETH_P_IRDA	0x0017 | ||
| 103 | #define ETH_P_ECONET	0x0018 | ||
| 104 | #define ETH_P_HDLC	0x0019 | ||
| 105 | #define ETH_P_ARCNET	0x001A | ||
| 106 | #define ETH_P_DSA	0x001B | ||
| 107 | #define ETH_P_TRAILER	0x001C | ||
| 108 | #define ETH_P_PHONET	0x00F5 | ||
| 109 | #define ETH_P_IEEE802154 0x00F6 | ||
| 110 | #define ETH_P_CAIF	0x00F7 | ||
| 111 | #define ETH_P_XDSA	0x00F8 | ||
| 112 | #define ETH_P_MAP	0x00F9 | ||
| 113 | |||
| 114 | struct ethhdr { | ||
| 115 | 	uint8_t h_dest[ETH_ALEN]; | ||
| 116 | 	uint8_t h_source[ETH_ALEN]; | ||
| 117 | 	uint16_t h_proto; | ||
| 118 | }; | ||
| 119 | |||
| 120 | #include <net/ethernet.h> | ||
| 121 | #include <net/if_arp.h> | ||
| 122 | |||
| 123 | struct	ether_arp { | ||
| 124 | 	struct	arphdr ea_hdr; | ||
| 125 | 	uint8_t arp_sha[ETH_ALEN]; | ||
| 126 | 	uint8_t arp_spa[4]; | ||
| 127 | 	uint8_t arp_tha[ETH_ALEN]; | ||
| 128 | 	uint8_t arp_tpa[4]; | ||
| 129 | }; | ||
| 130 | #define	arp_hrd	ea_hdr.ar_hrd | ||
| 131 | #define	arp_pro	ea_hdr.ar_pro | ||
| 132 | #define	arp_hln	ea_hdr.ar_hln | ||
| 133 | #define	arp_pln	ea_hdr.ar_pln | ||
| 134 | #define	arp_op	ea_hdr.ar_op | ||
| 135 | |||
| 136 | #define ETHER_MAP_IP_MULTICAST(ipaddr, enaddr) \ | ||
| 137 | do { \ | ||
| 138 | 	(enaddr)[0] = 0x01; \ | ||
| 139 | 	(enaddr)[1] = 0x00; \ | ||
| 140 | 	(enaddr)[2] = 0x5e; \ | ||
| 141 | 	(enaddr)[3] = ((uint8_t *)ipaddr)[1] & 0x7f; \ | ||
| 142 | 	(enaddr)[4] = ((uint8_t *)ipaddr)[2]; \ | ||
| 143 | 	(enaddr)[5] = ((uint8_t *)ipaddr)[3]; \ | ||
| 144 | } while(0) | ||
| 145 | |||
| 146 | #define __UAPI_DEF_ETHHDR 0 | ||
| 147 | |||
| 148 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/igmp.h created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | #ifndef _NETINET_IGMP_H | ||
| 2 | #define _NETINET_IGMP_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <netinet/in.h> | ||
| 6 | |||
| 7 | struct igmp { | ||
| 8 | 	uint8_t igmp_type; | ||
| 9 | 	uint8_t igmp_code; | ||
| 10 | 	uint16_t igmp_cksum; | ||
| 11 | 	struct in_addr igmp_group; | ||
| 12 | }; | ||
| 13 | |||
| 14 | #define IGMP_MINLEN			8 | ||
| 15 | |||
| 16 | #define IGMP_MEMBERSHIP_QUERY 	0x11 | ||
| 17 | #define IGMP_V1_MEMBERSHIP_REPORT	0x12 | ||
| 18 | #define IGMP_V2_MEMBERSHIP_REPORT	0x16 | ||
| 19 | #define IGMP_V2_LEAVE_GROUP		0x17 | ||
| 20 | |||
| 21 | #define IGMP_DVMRP			0x13 | ||
| 22 | #define IGMP_PIM			0x14 | ||
| 23 | #define IGMP_TRACE			0x15 | ||
| 24 | |||
| 25 | #define IGMP_MTRACE_RESP		0x1e | ||
| 26 | #define IGMP_MTRACE			0x1f | ||
| 27 | |||
| 28 | #define IGMP_MAX_HOST_REPORT_DELAY	10 | ||
| 29 | #define IGMP_TIMER_SCALE		10 | ||
| 30 | |||
| 31 | #define IGMP_DELAYING_MEMBER	1 | ||
| 32 | #define IGMP_IDLE_MEMBER	2 | ||
| 33 | #define IGMP_LAZY_MEMBER	3 | ||
| 34 | #define IGMP_SLEEPING_MEMBER	4 | ||
| 35 | #define IGMP_AWAKENING_MEMBER	5 | ||
| 36 | |||
| 37 | #define IGMP_v1_ROUTER		1 | ||
| 38 | #define IGMP_v2_ROUTER		2 | ||
| 39 | |||
| 40 | #define IGMP_HOST_MEMBERSHIP_QUERY	IGMP_MEMBERSHIP_QUERY | ||
| 41 | #define IGMP_HOST_MEMBERSHIP_REPORT	IGMP_V1_MEMBERSHIP_REPORT | ||
| 42 | #define IGMP_HOST_NEW_MEMBERSHIP_REPORT	IGMP_V2_MEMBERSHIP_REPORT | ||
| 43 | #define IGMP_HOST_LEAVE_MESSAGE		IGMP_V2_LEAVE_GROUP | ||
| 44 | |||
| 45 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/in.h created+432| ... | @@ -0,0 +1,432 @@ | ||
| 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 | |||
| 64 | #define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000) | ||
| 65 | #define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001) | ||
| 66 | #define INADDR_ALLRTRS_GROUP ((in_addr_t) 0xe0000002) | ||
| 67 | #define INADDR_ALLSNOOPERS_GROUP ((in_addr_t) 0xe000006a) | ||
| 68 | #define INADDR_MAX_LOCAL_GROUP ((in_addr_t) 0xe00000ff) | ||
| 69 | |||
| 70 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 71 | #define IN6ADDR_ANY_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 } } } | ||
| 72 | #define IN6ADDR_LOOPBACK_INIT { { { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 } } } | ||
| 73 | #endif | ||
| 74 | |||
| 75 | extern const struct in6_addr in6addr_any, in6addr_loopback; | ||
| 76 | |||
| 77 | #define INET_ADDRSTRLEN 16 | ||
| 78 | #define INET6_ADDRSTRLEN 46 | ||
| 79 | |||
| 80 | uint32_t htonl(uint32_t); | ||
| 81 | uint16_t htons(uint16_t); | ||
| 82 | uint32_t ntohl(uint32_t); | ||
| 83 | uint16_t ntohs(uint16_t); | ||
| 84 | |||
| 85 | #define IPPORT_RESERVED 1024 | ||
| 86 | |||
| 87 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 88 | #define IPPROTO_IP 0 | ||
| 89 | #define IPPROTO_HOPOPTS 0 | ||
| 90 | #define IPPROTO_ICMP 1 | ||
| 91 | #define IPPROTO_IGMP 2 | ||
| 92 | #define IPPROTO_IPIP 4 | ||
| 93 | #define IPPROTO_TCP 6 | ||
| 94 | #define IPPROTO_EGP 8 | ||
| 95 | #define IPPROTO_PUP 12 | ||
| 96 | #define IPPROTO_UDP 17 | ||
| 97 | #define IPPROTO_IDP 22 | ||
| 98 | #define IPPROTO_TP 29 | ||
| 99 | #define IPPROTO_DCCP 33 | ||
| 100 | #define IPPROTO_IPV6 41 | ||
| 101 | #define IPPROTO_ROUTING 43 | ||
| 102 | #define IPPROTO_FRAGMENT 44 | ||
| 103 | #define IPPROTO_RSVP 46 | ||
| 104 | #define IPPROTO_GRE 47 | ||
| 105 | #define IPPROTO_ESP 50 | ||
| 106 | #define IPPROTO_AH 51 | ||
| 107 | #define IPPROTO_ICMPV6 58 | ||
| 108 | #define IPPROTO_NONE 59 | ||
| 109 | #define IPPROTO_DSTOPTS 60 | ||
| 110 | #define IPPROTO_MTP 92 | ||
| 111 | #define IPPROTO_BEETPH 94 | ||
| 112 | #define IPPROTO_ENCAP 98 | ||
| 113 | #define IPPROTO_PIM 103 | ||
| 114 | #define IPPROTO_COMP 108 | ||
| 115 | #define IPPROTO_SCTP 132 | ||
| 116 | #define IPPROTO_MH 135 | ||
| 117 | #define IPPROTO_UDPLITE 136 | ||
| 118 | #define IPPROTO_MPLS 137 | ||
| 119 | #define IPPROTO_ETHERNET 143 | ||
| 120 | #define IPPROTO_RAW 255 | ||
| 121 | #define IPPROTO_MPTCP 262 | ||
| 122 | #define IPPROTO_MAX 263 | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #define IN6_IS_ADDR_UNSPECIFIED(a) \ | ||
| 126 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 127 | ((uint32_t *) (a))[2] == 0 && ((uint32_t *) (a))[3] == 0) | ||
| 128 | |||
| 129 | #define IN6_IS_ADDR_LOOPBACK(a) \ | ||
| 130 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 131 | ((uint32_t *) (a))[2] == 0 && \ | ||
| 132 | ((uint8_t *) (a))[12] == 0 && ((uint8_t *) (a))[13] == 0 && \ | ||
| 133 | ((uint8_t *) (a))[14] == 0 && ((uint8_t *) (a))[15] == 1 ) | ||
| 134 | |||
| 135 | #define IN6_IS_ADDR_MULTICAST(a) (((uint8_t *) (a))[0] == 0xff) | ||
| 136 | |||
| 137 | #define IN6_IS_ADDR_LINKLOCAL(a) \ | ||
| 138 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0x80) | ||
| 139 | |||
| 140 | #define IN6_IS_ADDR_SITELOCAL(a) \ | ||
| 141 | ((((uint8_t *) (a))[0]) == 0xfe && (((uint8_t *) (a))[1] & 0xc0) == 0xc0) | ||
| 142 | |||
| 143 | #define IN6_IS_ADDR_V4MAPPED(a) \ | ||
| 144 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 145 | ((uint8_t *) (a))[8] == 0 && ((uint8_t *) (a))[9] == 0 && \ | ||
| 146 | ((uint8_t *) (a))[10] == 0xff && ((uint8_t *) (a))[11] == 0xff) | ||
| 147 | |||
| 148 | #define IN6_IS_ADDR_V4COMPAT(a) \ | ||
| 149 | (((uint32_t *) (a))[0] == 0 && ((uint32_t *) (a))[1] == 0 && \ | ||
| 150 | ((uint32_t *) (a))[2] == 0 && ((uint8_t *) (a))[15] > 1) | ||
| 151 | |||
| 152 | #define IN6_IS_ADDR_MC_NODELOCAL(a) \ | ||
| 153 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x1)) | ||
| 154 | |||
| 155 | #define IN6_IS_ADDR_MC_LINKLOCAL(a) \ | ||
| 156 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x2)) | ||
| 157 | |||
| 158 | #define IN6_IS_ADDR_MC_SITELOCAL(a) \ | ||
| 159 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x5)) | ||
| 160 | |||
| 161 | #define IN6_IS_ADDR_MC_ORGLOCAL(a) \ | ||
| 162 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0x8)) | ||
| 163 | |||
| 164 | #define IN6_IS_ADDR_MC_GLOBAL(a) \ | ||
| 165 | (IN6_IS_ADDR_MULTICAST(a) && ((((uint8_t *) (a))[1] & 0xf) == 0xe)) | ||
| 166 | |||
| 167 | #define __ARE_4_EQUAL(a,b) \ | ||
| 168 | 	(!( (0[a]-0[b]) | (1[a]-1[b]) | (2[a]-2[b]) | (3[a]-3[b]) )) | ||
| 169 | #define IN6_ARE_ADDR_EQUAL(a,b) \ | ||
| 170 | 	__ARE_4_EQUAL((const uint32_t *)(a), (const uint32_t *)(b)) | ||
| 171 | |||
| 172 | #define	IN_CLASSA(a)		((((in_addr_t)(a)) & 0x80000000) == 0) | ||
| 173 | #define	IN_CLASSA_NET		0xff000000 | ||
| 174 | #define	IN_CLASSA_NSHIFT	24 | ||
| 175 | #define	IN_CLASSA_HOST		(0xffffffff & ~IN_CLASSA_NET) | ||
| 176 | #define	IN_CLASSA_MAX		128 | ||
| 177 | #define	IN_CLASSB(a)		((((in_addr_t)(a)) & 0xc0000000) == 0x80000000) | ||
| 178 | #define	IN_CLASSB_NET		0xffff0000 | ||
| 179 | #define	IN_CLASSB_NSHIFT	16 | ||
| 180 | #define	IN_CLASSB_HOST		(0xffffffff & ~IN_CLASSB_NET) | ||
| 181 | #define	IN_CLASSB_MAX		65536 | ||
| 182 | #define	IN_CLASSC(a)		((((in_addr_t)(a)) & 0xe0000000) == 0xc0000000) | ||
| 183 | #define	IN_CLASSC_NET		0xffffff00 | ||
| 184 | #define	IN_CLASSC_NSHIFT	8 | ||
| 185 | #define	IN_CLASSC_HOST		(0xffffffff & ~IN_CLASSC_NET) | ||
| 186 | #define	IN_CLASSD(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xe0000000) | ||
| 187 | #define	IN_MULTICAST(a)		IN_CLASSD(a) | ||
| 188 | #define	IN_EXPERIMENTAL(a)	((((in_addr_t)(a)) & 0xe0000000) == 0xe0000000) | ||
| 189 | #define	IN_BADCLASS(a)		((((in_addr_t)(a)) & 0xf0000000) == 0xf0000000) | ||
| 190 | |||
| 191 | #define IN_LOOPBACKNET 127 | ||
| 192 | |||
| 193 | |||
| 194 | #define IP_TOS 1 | ||
| 195 | #define IP_TTL 2 | ||
| 196 | #define IP_HDRINCL 3 | ||
| 197 | #define IP_OPTIONS 4 | ||
| 198 | #define IP_ROUTER_ALERT 5 | ||
| 199 | #define IP_RECVOPTS 6 | ||
| 200 | #define IP_RETOPTS 7 | ||
| 201 | #define IP_PKTINFO 8 | ||
| 202 | #define IP_PKTOPTIONS 9 | ||
| 203 | #define IP_PMTUDISC 10 | ||
| 204 | #define IP_MTU_DISCOVER 10 | ||
| 205 | #define IP_RECVERR 11 | ||
| 206 | #define IP_RECVTTL 12 | ||
| 207 | #define IP_RECVTOS 13 | ||
| 208 | #define IP_MTU 14 | ||
| 209 | #define IP_FREEBIND 15 | ||
| 210 | #define IP_IPSEC_POLICY 16 | ||
| 211 | #define IP_XFRM_POLICY 17 | ||
| 212 | #define IP_PASSSEC 18 | ||
| 213 | #define IP_TRANSPARENT 19 | ||
| 214 | #define IP_ORIGDSTADDR 20 | ||
| 215 | #define IP_RECVORIGDSTADDR IP_ORIGDSTADDR | ||
| 216 | #define IP_MINTTL 21 | ||
| 217 | #define IP_NODEFRAG 22 | ||
| 218 | #define IP_CHECKSUM 23 | ||
| 219 | #define IP_BIND_ADDRESS_NO_PORT 24 | ||
| 220 | #define IP_RECVFRAGSIZE 25 | ||
| 221 | #define IP_RECVERR_RFC4884 26 | ||
| 222 | #define IP_MULTICAST_IF 32 | ||
| 223 | #define IP_MULTICAST_TTL 33 | ||
| 224 | #define IP_MULTICAST_LOOP 34 | ||
| 225 | #define IP_ADD_MEMBERSHIP 35 | ||
| 226 | #define IP_DROP_MEMBERSHIP 36 | ||
| 227 | #define IP_UNBLOCK_SOURCE 37 | ||
| 228 | #define IP_BLOCK_SOURCE 38 | ||
| 229 | #define IP_ADD_SOURCE_MEMBERSHIP 39 | ||
| 230 | #define IP_DROP_SOURCE_MEMBERSHIP 40 | ||
| 231 | #define IP_MSFILTER 41 | ||
| 232 | #define IP_MULTICAST_ALL 49 | ||
| 233 | #define IP_UNICAST_IF 50 | ||
| 234 | |||
| 235 | #define IP_RECVRETOPTS IP_RETOPTS | ||
| 236 | |||
| 237 | #define IP_PMTUDISC_DONT 0 | ||
| 238 | #define IP_PMTUDISC_WANT 1 | ||
| 239 | #define IP_PMTUDISC_DO 2 | ||
| 240 | #define IP_PMTUDISC_PROBE 3 | ||
| 241 | #define IP_PMTUDISC_INTERFACE 4 | ||
| 242 | #define IP_PMTUDISC_OMIT 5 | ||
| 243 | |||
| 244 | #define IP_DEFAULT_MULTICAST_TTL 1 | ||
| 245 | #define IP_DEFAULT_MULTICAST_LOOP 1 | ||
| 246 | #define IP_MAX_MEMBERSHIPS 20 | ||
| 247 | |||
| 248 | struct ip_opts { | ||
| 249 | 	struct in_addr ip_dst; | ||
| 250 | 	char ip_opts[40]; | ||
| 251 | }; | ||
| 252 | |||
| 253 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 254 | |||
| 255 | #define MCAST_JOIN_GROUP 42 | ||
| 256 | #define MCAST_BLOCK_SOURCE 43 | ||
| 257 | #define MCAST_UNBLOCK_SOURCE 44 | ||
| 258 | #define MCAST_LEAVE_GROUP 45 | ||
| 259 | #define MCAST_JOIN_SOURCE_GROUP 46 | ||
| 260 | #define MCAST_LEAVE_SOURCE_GROUP 47 | ||
| 261 | #define MCAST_MSFILTER 48 | ||
| 262 | |||
| 263 | #define MCAST_EXCLUDE 0 | ||
| 264 | #define MCAST_INCLUDE 1 | ||
| 265 | |||
| 266 | struct ip_mreq { | ||
| 267 | 	struct in_addr imr_multiaddr; | ||
| 268 | 	struct in_addr imr_interface; | ||
| 269 | }; | ||
| 270 | |||
| 271 | struct ip_mreqn { | ||
| 272 | 	struct in_addr imr_multiaddr; | ||
| 273 | 	struct in_addr imr_address; | ||
| 274 | 	int imr_ifindex; | ||
| 275 | }; | ||
| 276 | |||
| 277 | struct ip_mreq_source { | ||
| 278 | 	struct in_addr imr_multiaddr; | ||
| 279 | 	struct in_addr imr_interface; | ||
| 280 | 	struct in_addr imr_sourceaddr; | ||
| 281 | }; | ||
| 282 | |||
| 283 | struct ip_msfilter { | ||
| 284 | 	struct in_addr imsf_multiaddr; | ||
| 285 | 	struct in_addr imsf_interface; | ||
| 286 | 	uint32_t imsf_fmode; | ||
| 287 | 	uint32_t imsf_numsrc; | ||
| 288 | 	struct in_addr imsf_slist[1]; | ||
| 289 | }; | ||
| 290 | #define IP_MSFILTER_SIZE(numsrc) \ | ||
| 291 | 	(sizeof(struct ip_msfilter) - sizeof(struct in_addr) \ | ||
| 292 | 	+ (numsrc) * sizeof(struct in_addr)) | ||
| 293 | |||
| 294 | struct group_req { | ||
| 295 | 	uint32_t gr_interface; | ||
| 296 | 	struct sockaddr_storage gr_group; | ||
| 297 | }; | ||
| 298 | |||
| 299 | struct group_source_req { | ||
| 300 | 	uint32_t gsr_interface; | ||
| 301 | 	struct sockaddr_storage gsr_group; | ||
| 302 | 	struct sockaddr_storage gsr_source; | ||
| 303 | }; | ||
| 304 | |||
| 305 | struct group_filter { | ||
| 306 | 	uint32_t gf_interface; | ||
| 307 | 	struct sockaddr_storage gf_group; | ||
| 308 | 	uint32_t gf_fmode; | ||
| 309 | 	uint32_t gf_numsrc; | ||
| 310 | 	struct sockaddr_storage gf_slist[1]; | ||
| 311 | }; | ||
| 312 | #define GROUP_FILTER_SIZE(numsrc) \ | ||
| 313 | 	(sizeof(struct group_filter) - sizeof(struct sockaddr_storage) \ | ||
| 314 | 	+ (numsrc) * sizeof(struct sockaddr_storage)) | ||
| 315 | |||
| 316 | struct in_pktinfo { | ||
| 317 | 	int ipi_ifindex; | ||
| 318 | 	struct in_addr ipi_spec_dst; | ||
| 319 | 	struct in_addr ipi_addr; | ||
| 320 | }; | ||
| 321 | |||
| 322 | struct in6_pktinfo { | ||
| 323 | 	struct in6_addr ipi6_addr; | ||
| 324 | 	unsigned ipi6_ifindex; | ||
| 325 | }; | ||
| 326 | |||
| 327 | struct ip6_mtuinfo { | ||
| 328 | 	struct sockaddr_in6 ip6m_addr; | ||
| 329 | 	uint32_t ip6m_mtu; | ||
| 330 | }; | ||
| 331 | #endif | ||
| 332 | |||
| 333 | #define IPV6_ADDRFORM 1 | ||
| 334 | #define IPV6_2292PKTINFO 2 | ||
| 335 | #define IPV6_2292HOPOPTS 3 | ||
| 336 | #define IPV6_2292DSTOPTS 4 | ||
| 337 | #define IPV6_2292RTHDR 5 | ||
| 338 | #define IPV6_2292PKTOPTIONS 6 | ||
| 339 | #define IPV6_CHECKSUM 7 | ||
| 340 | #define IPV6_2292HOPLIMIT 8 | ||
| 341 | #define IPV6_NEXTHOP 9 | ||
| 342 | #define IPV6_AUTHHDR 10 | ||
| 343 | #define IPV6_UNICAST_HOPS 16 | ||
| 344 | #define IPV6_MULTICAST_IF 17 | ||
| 345 | #define IPV6_MULTICAST_HOPS 18 | ||
| 346 | #define IPV6_MULTICAST_LOOP 19 | ||
| 347 | #define IPV6_JOIN_GROUP 20 | ||
| 348 | #define IPV6_LEAVE_GROUP 21 | ||
| 349 | #define IPV6_ROUTER_ALERT 22 | ||
| 350 | #define IPV6_MTU_DISCOVER 23 | ||
| 351 | #define IPV6_MTU 24 | ||
| 352 | #define IPV6_RECVERR 25 | ||
| 353 | #define IPV6_V6ONLY 26 | ||
| 354 | #define IPV6_JOIN_ANYCAST 27 | ||
| 355 | #define IPV6_LEAVE_ANYCAST 28 | ||
| 356 | #define IPV6_MULTICAST_ALL 29 | ||
| 357 | #define IPV6_ROUTER_ALERT_ISOLATE 30 | ||
| 358 | #define IPV6_IPSEC_POLICY 34 | ||
| 359 | #define IPV6_XFRM_POLICY 35 | ||
| 360 | #define IPV6_HDRINCL 36 | ||
| 361 | |||
| 362 | #define IPV6_RECVPKTINFO 49 | ||
| 363 | #define IPV6_PKTINFO 50 | ||
| 364 | #define IPV6_RECVHOPLIMIT 51 | ||
| 365 | #define IPV6_HOPLIMIT 52 | ||
| 366 | #define IPV6_RECVHOPOPTS 53 | ||
| 367 | #define IPV6_HOPOPTS 54 | ||
| 368 | #define IPV6_RTHDRDSTOPTS 55 | ||
| 369 | #define IPV6_RECVRTHDR 56 | ||
| 370 | #define IPV6_RTHDR 57 | ||
| 371 | #define IPV6_RECVDSTOPTS 58 | ||
| 372 | #define IPV6_DSTOPTS 59 | ||
| 373 | #define IPV6_RECVPATHMTU 60 | ||
| 374 | #define IPV6_PATHMTU 61 | ||
| 375 | #define IPV6_DONTFRAG 62 | ||
| 376 | #define IPV6_RECVTCLASS 66 | ||
| 377 | #define IPV6_TCLASS 67 | ||
| 378 | #define IPV6_AUTOFLOWLABEL 70 | ||
| 379 | #define IPV6_ADDR_PREFERENCES 72 | ||
| 380 | #define IPV6_MINHOPCOUNT 73 | ||
| 381 | #define IPV6_ORIGDSTADDR 74 | ||
| 382 | #define IPV6_RECVORIGDSTADDR IPV6_ORIGDSTADDR | ||
| 383 | #define IPV6_TRANSPARENT 75 | ||
| 384 | #define IPV6_UNICAST_IF 76 | ||
| 385 | #define IPV6_RECVFRAGSIZE 77 | ||
| 386 | #define IPV6_FREEBIND 78 | ||
| 387 | |||
| 388 | #define IPV6_ADD_MEMBERSHIP IPV6_JOIN_GROUP | ||
| 389 | #define IPV6_DROP_MEMBERSHIP IPV6_LEAVE_GROUP | ||
| 390 | #define IPV6_RXHOPOPTS IPV6_HOPOPTS | ||
| 391 | #define IPV6_RXDSTOPTS IPV6_DSTOPTS | ||
| 392 | |||
| 393 | #define IPV6_PMTUDISC_DONT 0 | ||
| 394 | #define IPV6_PMTUDISC_WANT 1 | ||
| 395 | #define IPV6_PMTUDISC_DO 2 | ||
| 396 | #define IPV6_PMTUDISC_PROBE 3 | ||
| 397 | #define IPV6_PMTUDISC_INTERFACE 4 | ||
| 398 | #define IPV6_PMTUDISC_OMIT 5 | ||
| 399 | |||
| 400 | #define IPV6_PREFER_SRC_TMP 0x0001 | ||
| 401 | #define IPV6_PREFER_SRC_PUBLIC 0x0002 | ||
| 402 | #define IPV6_PREFER_SRC_PUBTMP_DEFAULT 0x0100 | ||
| 403 | #define IPV6_PREFER_SRC_COA 0x0004 | ||
| 404 | #define IPV6_PREFER_SRC_HOME 0x0400 | ||
| 405 | #define IPV6_PREFER_SRC_CGA 0x0008 | ||
| 406 | #define IPV6_PREFER_SRC_NONCGA 0x0800 | ||
| 407 | |||
| 408 | #define IPV6_RTHDR_LOOSE 0 | ||
| 409 | #define IPV6_RTHDR_STRICT 1 | ||
| 410 | |||
| 411 | #define IPV6_RTHDR_TYPE_0 0 | ||
| 412 | |||
| 413 | #define __UAPI_DEF_IN_ADDR 0 | ||
| 414 | #define __UAPI_DEF_IN_IPPROTO 0 | ||
| 415 | #define __UAPI_DEF_IN_PKTINFO 0 | ||
| 416 | #define __UAPI_DEF_IP_MREQ 0 | ||
| 417 | #define __UAPI_DEF_SOCKADDR_IN 0 | ||
| 418 | #define __UAPI_DEF_IN_CLASS 0 | ||
| 419 | #define __UAPI_DEF_IN6_ADDR 0 | ||
| 420 | #define __UAPI_DEF_IN6_ADDR_ALT 0 | ||
| 421 | #define __UAPI_DEF_SOCKADDR_IN6 0 | ||
| 422 | #define __UAPI_DEF_IPV6_MREQ 0 | ||
| 423 | #define __UAPI_DEF_IPPROTO_V6 0 | ||
| 424 | #define __UAPI_DEF_IPV6_OPTIONS 0 | ||
| 425 | #define __UAPI_DEF_IN6_PKTINFO 0 | ||
| 426 | #define __UAPI_DEF_IP6_MTUINFO 0 | ||
| 427 | |||
| 428 | #ifdef __cplusplus | ||
| 429 | } | ||
| 430 | #endif | ||
| 431 | |||
| 432 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/in_systm.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef _NETINET_IN_SYSTM_H | ||
| 2 | #define _NETINET_IN_SYSTM_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | typedef uint16_t n_short; | ||
| 7 | typedef uint32_t n_long, n_time; | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/ip.h created+199| ... | @@ -0,0 +1,199 @@ | ||
| 1 | #ifndef _NETINET_IP_H | ||
| 2 | #define _NETINET_IP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | struct timestamp { | ||
| 12 | 	uint8_t len; | ||
| 13 | 	uint8_t ptr; | ||
| 14 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 15 | 	unsigned int flags:4; | ||
| 16 | 	unsigned int overflow:4; | ||
| 17 | #else | ||
| 18 | 	unsigned int overflow:4; | ||
| 19 | 	unsigned int flags:4; | ||
| 20 | #endif | ||
| 21 | 	uint32_t data[9]; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct iphdr { | ||
| 25 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 26 | 	unsigned int ihl:4; | ||
| 27 | 	unsigned int version:4; | ||
| 28 | #else | ||
| 29 | 	unsigned int version:4; | ||
| 30 | 	unsigned int ihl:4; | ||
| 31 | #endif | ||
| 32 | 	uint8_t tos; | ||
| 33 | 	uint16_t tot_len; | ||
| 34 | 	uint16_t id; | ||
| 35 | 	uint16_t frag_off; | ||
| 36 | 	uint8_t ttl; | ||
| 37 | 	uint8_t protocol; | ||
| 38 | 	uint16_t check; | ||
| 39 | 	uint32_t saddr; | ||
| 40 | 	uint32_t daddr; | ||
| 41 | }; | ||
| 42 | |||
| 43 | struct ip { | ||
| 44 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 45 | 	unsigned int ip_hl:4; | ||
| 46 | 	unsigned int ip_v:4; | ||
| 47 | #else | ||
| 48 | 	unsigned int ip_v:4; | ||
| 49 | 	unsigned int ip_hl:4; | ||
| 50 | #endif | ||
| 51 | 	uint8_t ip_tos; | ||
| 52 | 	uint16_t ip_len; | ||
| 53 | 	uint16_t ip_id; | ||
| 54 | 	uint16_t ip_off; | ||
| 55 | 	uint8_t ip_ttl; | ||
| 56 | 	uint8_t ip_p; | ||
| 57 | 	uint16_t ip_sum; | ||
| 58 | 	struct in_addr ip_src, ip_dst; | ||
| 59 | }; | ||
| 60 | |||
| 61 | #define	IP_RF 0x8000 | ||
| 62 | #define	IP_DF 0x4000 | ||
| 63 | #define	IP_MF 0x2000 | ||
| 64 | #define	IP_OFFMASK 0x1fff | ||
| 65 | |||
| 66 | struct ip_timestamp { | ||
| 67 | 	uint8_t ipt_code; | ||
| 68 | 	uint8_t ipt_len; | ||
| 69 | 	uint8_t ipt_ptr; | ||
| 70 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 71 | 	unsigned int ipt_flg:4; | ||
| 72 | 	unsigned int ipt_oflw:4; | ||
| 73 | #else | ||
| 74 | 	unsigned int ipt_oflw:4; | ||
| 75 | 	unsigned int ipt_flg:4; | ||
| 76 | #endif | ||
| 77 | 	uint32_t data[9]; | ||
| 78 | }; | ||
| 79 | |||
| 80 | #define	IPVERSION	4 | ||
| 81 | #define	IP_MAXPACKET	65535 | ||
| 82 | |||
| 83 | #define	IPTOS_ECN_MASK		0x03 | ||
| 84 | #define	IPTOS_ECN(x)		((x) & IPTOS_ECN_MASK) | ||
| 85 | #define	IPTOS_ECN_NOT_ECT	0x00 | ||
| 86 | #define	IPTOS_ECN_ECT1		0x01 | ||
| 87 | #define	IPTOS_ECN_ECT0		0x02 | ||
| 88 | #define	IPTOS_ECN_CE		0x03 | ||
| 89 | |||
| 90 | #define	IPTOS_DSCP_MASK		0xfc | ||
| 91 | #define	IPTOS_DSCP(x)		((x) & IPTOS_DSCP_MASK) | ||
| 92 | #define	IPTOS_DSCP_AF11		0x28 | ||
| 93 | #define	IPTOS_DSCP_AF12		0x30 | ||
| 94 | #define	IPTOS_DSCP_AF13		0x38 | ||
| 95 | #define	IPTOS_DSCP_AF21		0x48 | ||
| 96 | #define	IPTOS_DSCP_AF22		0x50 | ||
| 97 | #define	IPTOS_DSCP_AF23		0x58 | ||
| 98 | #define	IPTOS_DSCP_AF31		0x68 | ||
| 99 | #define	IPTOS_DSCP_AF32		0x70 | ||
| 100 | #define	IPTOS_DSCP_AF33		0x78 | ||
| 101 | #define	IPTOS_DSCP_AF41		0x88 | ||
| 102 | #define	IPTOS_DSCP_AF42		0x90 | ||
| 103 | #define	IPTOS_DSCP_AF43		0x98 | ||
| 104 | #define	IPTOS_DSCP_EF		0xb8 | ||
| 105 | |||
| 106 | #define	IPTOS_CLASS_MASK	0xe0 | ||
| 107 | #define	IPTOS_CLASS(x)		((x) & IPTOS_CLASS_MASK) | ||
| 108 | #define	IPTOS_CLASS_CS0		0x00 | ||
| 109 | #define	IPTOS_CLASS_CS1		0x20 | ||
| 110 | #define	IPTOS_CLASS_CS2		0x40 | ||
| 111 | #define	IPTOS_CLASS_CS3		0x60 | ||
| 112 | #define	IPTOS_CLASS_CS4		0x80 | ||
| 113 | #define	IPTOS_CLASS_CS5		0xa0 | ||
| 114 | #define	IPTOS_CLASS_CS6		0xc0 | ||
| 115 | #define	IPTOS_CLASS_CS7		0xe0 | ||
| 116 | #define	IPTOS_CLASS_DEFAULT	IPTOS_CLASS_CS0 | ||
| 117 | |||
| 118 | #define	IPTOS_TOS_MASK		0x1E | ||
| 119 | #define	IPTOS_TOS(tos)		((tos) & IPTOS_TOS_MASK) | ||
| 120 | #define	IPTOS_LOWDELAY		0x10 | ||
| 121 | #define	IPTOS_THROUGHPUT	0x08 | ||
| 122 | #define	IPTOS_RELIABILITY	0x04 | ||
| 123 | #define	IPTOS_LOWCOST		0x02 | ||
| 124 | #define	IPTOS_MINCOST		IPTOS_LOWCOST | ||
| 125 | |||
| 126 | #define	IPTOS_PREC_MASK			0xe0 | ||
| 127 | #define	IPTOS_PREC(tos) ((tos) & IPTOS_PREC_MASK) | ||
| 128 | #define	IPTOS_PREC_NETCONTROL		0xe0 | ||
| 129 | #define	IPTOS_PREC_INTERNETCONTROL	0xc0 | ||
| 130 | #define	IPTOS_PREC_CRITIC_ECP		0xa0 | ||
| 131 | #define	IPTOS_PREC_FLASHOVERRIDE	0x80 | ||
| 132 | #define	IPTOS_PREC_FLASH		0x60 | ||
| 133 | #define	IPTOS_PREC_IMMEDIATE		0x40 | ||
| 134 | #define	IPTOS_PREC_PRIORITY		0x20 | ||
| 135 | #define	IPTOS_PREC_ROUTINE		0x00 | ||
| 136 | |||
| 137 | #define	IPOPT_COPY		0x80 | ||
| 138 | #define	IPOPT_CLASS_MASK	0x60 | ||
| 139 | #define	IPOPT_NUMBER_MASK	0x1f | ||
| 140 | |||
| 141 | #define	IPOPT_COPIED(o)		((o) & IPOPT_COPY) | ||
| 142 | #define	IPOPT_CLASS(o)		((o) & IPOPT_CLASS_MASK) | ||
| 143 | #define	IPOPT_NUMBER(o)		((o) & IPOPT_NUMBER_MASK) | ||
| 144 | |||
| 145 | #define	IPOPT_CONTROL		0x00 | ||
| 146 | #define	IPOPT_RESERVED1		0x20 | ||
| 147 | #define	IPOPT_DEBMEAS		0x40 | ||
| 148 | #define	IPOPT_MEASUREMENT IPOPT_DEBMEAS | ||
| 149 | #define	IPOPT_RESERVED2		0x60 | ||
| 150 | |||
| 151 | #define	IPOPT_EOL		0 | ||
| 152 | #define	IPOPT_END		IPOPT_EOL | ||
| 153 | #define	IPOPT_NOP		1 | ||
| 154 | #define	IPOPT_NOOP		IPOPT_NOP | ||
| 155 | |||
| 156 | #define	IPOPT_RR		7 | ||
| 157 | #define	IPOPT_TS		68 | ||
| 158 | #define	IPOPT_TIMESTAMP		IPOPT_TS | ||
| 159 | #define	IPOPT_SECURITY		130 | ||
| 160 | #define	IPOPT_SEC		IPOPT_SECURITY | ||
| 161 | #define	IPOPT_LSRR		131 | ||
| 162 | #define	IPOPT_SATID		136 | ||
| 163 | #define	IPOPT_SID		IPOPT_SATID | ||
| 164 | #define	IPOPT_SSRR		137 | ||
| 165 | #define	IPOPT_RA		148 | ||
| 166 | |||
| 167 | #define	IPOPT_OPTVAL		0 | ||
| 168 | #define	IPOPT_OLEN		1 | ||
| 169 | #define	IPOPT_OFFSET		2 | ||
| 170 | #define	IPOPT_MINOFF		4 | ||
| 171 | |||
| 172 | #define	MAX_IPOPTLEN		40 | ||
| 173 | |||
| 174 | #define	IPOPT_TS_TSONLY		0 | ||
| 175 | #define	IPOPT_TS_TSANDADDR	1 | ||
| 176 | #define	IPOPT_TS_PRESPEC	3 | ||
| 177 | |||
| 178 | #define	IPOPT_SECUR_UNCLASS	0x0000 | ||
| 179 | #define	IPOPT_SECUR_CONFID	0xf135 | ||
| 180 | #define	IPOPT_SECUR_EFTO	0x789a | ||
| 181 | #define	IPOPT_SECUR_MMMM	0xbc4d | ||
| 182 | #define	IPOPT_SECUR_RESTR	0xaf13 | ||
| 183 | #define	IPOPT_SECUR_SECRET	0xd788 | ||
| 184 | #define	IPOPT_SECUR_TOPSECRET	0x6bc5 | ||
| 185 | |||
| 186 | #define	MAXTTL		255 | ||
| 187 | #define	IPDEFTTL	64 | ||
| 188 | #define	IPFRAGTTL	60 | ||
| 189 | #define	IPTTLDEC	1 | ||
| 190 | |||
| 191 | #define	IP_MSS		576 | ||
| 192 | |||
| 193 | #define __UAPI_DEF_IPHDR	0 | ||
| 194 | |||
| 195 | #ifdef __cplusplus | ||
| 196 | } | ||
| 197 | #endif | ||
| 198 | |||
| 199 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/ip6.h created+141| ... | @@ -0,0 +1,141 @@ | ||
| 1 | #ifndef _NETINET_IP6_H | ||
| 2 | #define _NETINET_IP6_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | |||
| 11 | struct ip6_hdr { | ||
| 12 | 	union { | ||
| 13 | 		struct ip6_hdrctl { | ||
| 14 | 			uint32_t ip6_un1_flow; | ||
| 15 | 			uint16_t ip6_un1_plen; | ||
| 16 | 			uint8_t ip6_un1_nxt; | ||
| 17 | 			uint8_t ip6_un1_hlim; | ||
| 18 | 		} ip6_un1; | ||
| 19 | 		uint8_t ip6_un2_vfc; | ||
| 20 | 	} ip6_ctlun; | ||
| 21 | 	struct in6_addr ip6_src; | ||
| 22 | 	struct in6_addr ip6_dst; | ||
| 23 | }; | ||
| 24 | |||
| 25 | #define ip6_vfc ip6_ctlun.ip6_un2_vfc | ||
| 26 | #define ip6_flow ip6_ctlun.ip6_un1.ip6_un1_flow | ||
| 27 | #define ip6_plen ip6_ctlun.ip6_un1.ip6_un1_plen | ||
| 28 | #define ip6_nxt ip6_ctlun.ip6_un1.ip6_un1_nxt | ||
| 29 | #define ip6_hlim ip6_ctlun.ip6_un1.ip6_un1_hlim | ||
| 30 | #define ip6_hops ip6_ctlun.ip6_un1.ip6_un1_hlim | ||
| 31 | |||
| 32 | struct ip6_ext { | ||
| 33 | 	uint8_t ip6e_nxt; | ||
| 34 | 	uint8_t ip6e_len; | ||
| 35 | }; | ||
| 36 | |||
| 37 | struct ip6_hbh { | ||
| 38 | 	uint8_t ip6h_nxt; | ||
| 39 | 	uint8_t ip6h_len; | ||
| 40 | }; | ||
| 41 | |||
| 42 | struct ip6_dest { | ||
| 43 | 	uint8_t ip6d_nxt; | ||
| 44 | 	uint8_t ip6d_len; | ||
| 45 | }; | ||
| 46 | |||
| 47 | struct ip6_rthdr { | ||
| 48 | 	uint8_t ip6r_nxt; | ||
| 49 | 	uint8_t ip6r_len; | ||
| 50 | 	uint8_t ip6r_type; | ||
| 51 | 	uint8_t ip6r_segleft; | ||
| 52 | }; | ||
| 53 | |||
| 54 | struct ip6_rthdr0 { | ||
| 55 | 	uint8_t ip6r0_nxt; | ||
| 56 | 	uint8_t ip6r0_len; | ||
| 57 | 	uint8_t ip6r0_type; | ||
| 58 | 	uint8_t ip6r0_segleft; | ||
| 59 | 	uint8_t ip6r0_reserved; | ||
| 60 | 	uint8_t ip6r0_slmap[3]; | ||
| 61 | 	struct in6_addr ip6r0_addr[]; | ||
| 62 | }; | ||
| 63 | |||
| 64 | struct ip6_frag { | ||
| 65 | 	uint8_t ip6f_nxt; | ||
| 66 | 	uint8_t ip6f_reserved; | ||
| 67 | 	uint16_t ip6f_offlg; | ||
| 68 | 	uint32_t ip6f_ident; | ||
| 69 | }; | ||
| 70 | |||
| 71 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 72 | #define IP6F_OFF_MASK 0xfff8 | ||
| 73 | #define IP6F_RESERVED_MASK 0x0006 | ||
| 74 | #define IP6F_MORE_FRAG 0x0001 | ||
| 75 | #else | ||
| 76 | #define IP6F_OFF_MASK 0xf8ff | ||
| 77 | #define IP6F_RESERVED_MASK 0x0600 | ||
| 78 | #define IP6F_MORE_FRAG 0x0100 | ||
| 79 | #endif | ||
| 80 | |||
| 81 | struct ip6_opt { | ||
| 82 | 	uint8_t ip6o_type; | ||
| 83 | 	uint8_t ip6o_len; | ||
| 84 | }; | ||
| 85 | |||
| 86 | #define IP6OPT_TYPE(o)		((o) & 0xc0) | ||
| 87 | #define IP6OPT_TYPE_SKIP	0x00 | ||
| 88 | #define IP6OPT_TYPE_DISCARD	0x40 | ||
| 89 | #define IP6OPT_TYPE_FORCEICMP	0x80 | ||
| 90 | #define IP6OPT_TYPE_ICMP	0xc0 | ||
| 91 | #define IP6OPT_TYPE_MUTABLE	0x20 | ||
| 92 | |||
| 93 | #define IP6OPT_PAD1	0 | ||
| 94 | #define IP6OPT_PADN	1 | ||
| 95 | |||
| 96 | #define IP6OPT_JUMBO		0xc2 | ||
| 97 | #define IP6OPT_NSAP_ADDR	0xc3 | ||
| 98 | #define IP6OPT_TUNNEL_LIMIT	0x04 | ||
| 99 | #define IP6OPT_ROUTER_ALERT	0x05 | ||
| 100 | |||
| 101 | struct ip6_opt_jumbo { | ||
| 102 | 	uint8_t ip6oj_type; | ||
| 103 | 	uint8_t ip6oj_len; | ||
| 104 | 	uint8_t ip6oj_jumbo_len[4]; | ||
| 105 | }; | ||
| 106 | #define IP6OPT_JUMBO_LEN	6 | ||
| 107 | |||
| 108 | struct ip6_opt_nsap { | ||
| 109 | 	uint8_t ip6on_type; | ||
| 110 | 	uint8_t ip6on_len; | ||
| 111 | 	uint8_t ip6on_src_nsap_len; | ||
| 112 | 	uint8_t ip6on_dst_nsap_len; | ||
| 113 | }; | ||
| 114 | |||
| 115 | struct ip6_opt_tunnel { | ||
| 116 | 	uint8_t ip6ot_type; | ||
| 117 | 	uint8_t ip6ot_len; | ||
| 118 | 	uint8_t ip6ot_encap_limit; | ||
| 119 | }; | ||
| 120 | |||
| 121 | struct ip6_opt_router { | ||
| 122 | 	uint8_t ip6or_type; | ||
| 123 | 	uint8_t ip6or_len; | ||
| 124 | 	uint8_t ip6or_value[2]; | ||
| 125 | }; | ||
| 126 | |||
| 127 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 128 | #define IP6_ALERT_MLD	0x0000 | ||
| 129 | #define IP6_ALERT_RSVP	0x0001 | ||
| 130 | #define IP6_ALERT_AN	0x0002 | ||
| 131 | #else | ||
| 132 | #define IP6_ALERT_MLD	0x0000 | ||
| 133 | #define IP6_ALERT_RSVP	0x0100 | ||
| 134 | #define IP6_ALERT_AN	0x0200 | ||
| 135 | #endif | ||
| 136 | |||
| 137 | #ifdef __cplusplus | ||
| 138 | } | ||
| 139 | #endif | ||
| 140 | |||
| 141 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/ip_icmp.h created+193| ... | @@ -0,0 +1,193 @@ | ||
| 1 | #ifndef _NETINET_IP_ICMP_H | ||
| 2 | #define _NETINET_IP_ICMP_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <netinet/in.h> | ||
| 6 | #include <netinet/ip.h> | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | struct icmphdr { | ||
| 13 | 	uint8_t type; | ||
| 14 | 	uint8_t code; | ||
| 15 | 	uint16_t checksum; | ||
| 16 | 	union { | ||
| 17 | 		struct { | ||
| 18 | 			uint16_t id; | ||
| 19 | 			uint16_t sequence; | ||
| 20 | 		} echo; | ||
| 21 | 		uint32_t gateway; | ||
| 22 | 		struct { | ||
| 23 | 			uint16_t __unused; | ||
| 24 | 			uint16_t mtu; | ||
| 25 | 		} frag; | ||
| 26 | 		uint8_t reserved[4]; | ||
| 27 | 	} un; | ||
| 28 | }; | ||
| 29 | |||
| 30 | #define ICMP_ECHOREPLY		0 | ||
| 31 | #define ICMP_DEST_UNREACH	3 | ||
| 32 | #define ICMP_SOURCE_QUENCH	4 | ||
| 33 | #define ICMP_REDIRECT		5 | ||
| 34 | #define ICMP_ECHO		8 | ||
| 35 | #define ICMP_TIME_EXCEEDED	11 | ||
| 36 | #define ICMP_PARAMETERPROB	12 | ||
| 37 | #define ICMP_TIMESTAMP		13 | ||
| 38 | #define ICMP_TIMESTAMPREPLY	14 | ||
| 39 | #define ICMP_INFO_REQUEST	15 | ||
| 40 | #define ICMP_INFO_REPLY		16 | ||
| 41 | #define ICMP_ADDRESS		17 | ||
| 42 | #define ICMP_ADDRESSREPLY	18 | ||
| 43 | #define NR_ICMP_TYPES		18 | ||
| 44 | |||
| 45 | |||
| 46 | #define ICMP_NET_UNREACH	0 | ||
| 47 | #define ICMP_HOST_UNREACH	1 | ||
| 48 | #define ICMP_PROT_UNREACH	2 | ||
| 49 | #define ICMP_PORT_UNREACH	3 | ||
| 50 | #define ICMP_FRAG_NEEDED	4 | ||
| 51 | #define ICMP_SR_FAILED		5 | ||
| 52 | #define ICMP_NET_UNKNOWN	6 | ||
| 53 | #define ICMP_HOST_UNKNOWN	7 | ||
| 54 | #define ICMP_HOST_ISOLATED	8 | ||
| 55 | #define ICMP_NET_ANO		9 | ||
| 56 | #define ICMP_HOST_ANO		10 | ||
| 57 | #define ICMP_NET_UNR_TOS	11 | ||
| 58 | #define ICMP_HOST_UNR_TOS	12 | ||
| 59 | #define ICMP_PKT_FILTERED	13 | ||
| 60 | #define ICMP_PREC_VIOLATION	14 | ||
| 61 | #define ICMP_PREC_CUTOFF	15 | ||
| 62 | #define NR_ICMP_UNREACH		15 | ||
| 63 | |||
| 64 | #define ICMP_REDIR_NET		0 | ||
| 65 | #define ICMP_REDIR_HOST		1 | ||
| 66 | #define ICMP_REDIR_NETTOS	2 | ||
| 67 | #define ICMP_REDIR_HOSTTOS	3 | ||
| 68 | |||
| 69 | #define ICMP_EXC_TTL		0 | ||
| 70 | #define ICMP_EXC_FRAGTIME	1 | ||
| 71 | |||
| 72 | |||
| 73 | struct icmp_ra_addr { | ||
| 74 | 	uint32_t ira_addr; | ||
| 75 | 	uint32_t ira_preference; | ||
| 76 | }; | ||
| 77 | |||
| 78 | struct icmp { | ||
| 79 | 	uint8_t icmp_type; | ||
| 80 | 	uint8_t icmp_code; | ||
| 81 | 	uint16_t icmp_cksum; | ||
| 82 | 	union { | ||
| 83 | 		uint8_t ih_pptr; | ||
| 84 | 		struct in_addr ih_gwaddr; | ||
| 85 | 		struct ih_idseq { | ||
| 86 | 			uint16_t icd_id; | ||
| 87 | 			uint16_t icd_seq; | ||
| 88 | 		} ih_idseq; | ||
| 89 | 		uint32_t ih_void; | ||
| 90 | |||
| 91 | 		struct ih_pmtu { | ||
| 92 | 			uint16_t ipm_void; | ||
| 93 | 			uint16_t ipm_nextmtu; | ||
| 94 | 		} ih_pmtu; | ||
| 95 | |||
| 96 | 		struct ih_rtradv { | ||
| 97 | 			uint8_t irt_num_addrs; | ||
| 98 | 			uint8_t irt_wpa; | ||
| 99 | 			uint16_t irt_lifetime; | ||
| 100 | 		} ih_rtradv; | ||
| 101 | 	} icmp_hun; | ||
| 102 | 	union { | ||
| 103 | 		struct { | ||
| 104 | 			uint32_t its_otime; | ||
| 105 | 			uint32_t its_rtime; | ||
| 106 | 			uint32_t its_ttime; | ||
| 107 | 		} id_ts; | ||
| 108 | 		struct { | ||
| 109 | 			struct ip idi_ip; | ||
| 110 | 		} id_ip; | ||
| 111 | 		struct icmp_ra_addr id_radv; | ||
| 112 | 		uint32_t id_mask; | ||
| 113 | 		uint8_t id_data[1]; | ||
| 114 | 	} icmp_dun; | ||
| 115 | }; | ||
| 116 | |||
| 117 | #define	icmp_pptr	icmp_hun.ih_pptr | ||
| 118 | #define	icmp_gwaddr	icmp_hun.ih_gwaddr | ||
| 119 | #define	icmp_id		icmp_hun.ih_idseq.icd_id | ||
| 120 | #define	icmp_seq	icmp_hun.ih_idseq.icd_seq | ||
| 121 | #define	icmp_void	icmp_hun.ih_void | ||
| 122 | #define	icmp_pmvoid	icmp_hun.ih_pmtu.ipm_void | ||
| 123 | #define	icmp_nextmtu	icmp_hun.ih_pmtu.ipm_nextmtu | ||
| 124 | #define	icmp_num_addrs	icmp_hun.ih_rtradv.irt_num_addrs | ||
| 125 | #define	icmp_wpa	icmp_hun.ih_rtradv.irt_wpa | ||
| 126 | #define	icmp_lifetime	icmp_hun.ih_rtradv.irt_lifetime | ||
| 127 | #define	icmp_otime	icmp_dun.id_ts.its_otime | ||
| 128 | #define	icmp_rtime	icmp_dun.id_ts.its_rtime | ||
| 129 | #define	icmp_ttime	icmp_dun.id_ts.its_ttime | ||
| 130 | #define	icmp_ip		icmp_dun.id_ip.idi_ip | ||
| 131 | #define	icmp_radv	icmp_dun.id_radv | ||
| 132 | #define	icmp_mask	icmp_dun.id_mask | ||
| 133 | #define	icmp_data	icmp_dun.id_data | ||
| 134 | |||
| 135 | #define	ICMP_MINLEN	8 | ||
| 136 | #define	ICMP_TSLEN	(8 + 3 * sizeof (n_time)) | ||
| 137 | #define	ICMP_MASKLEN	12 | ||
| 138 | #define	ICMP_ADVLENMIN	(8 + sizeof (struct ip) + 8) | ||
| 139 | #define	ICMP_ADVLEN(p)	(8 + ((p)->icmp_ip.ip_hl << 2) + 8) | ||
| 140 | |||
| 141 | #define	ICMP_UNREACH		3 | ||
| 142 | #define	ICMP_SOURCEQUENCH	4 | ||
| 143 | #define	ICMP_ROUTERADVERT	9 | ||
| 144 | #define	ICMP_ROUTERSOLICIT	10 | ||
| 145 | #define	ICMP_TIMXCEED		11 | ||
| 146 | #define	ICMP_PARAMPROB		12 | ||
| 147 | #define	ICMP_TSTAMP		13 | ||
| 148 | #define	ICMP_TSTAMPREPLY	14 | ||
| 149 | #define	ICMP_IREQ		15 | ||
| 150 | #define	ICMP_IREQREPLY		16 | ||
| 151 | #define	ICMP_MASKREQ		17 | ||
| 152 | #define	ICMP_MASKREPLY		18 | ||
| 153 | #define	ICMP_MAXTYPE		18 | ||
| 154 | |||
| 155 | #define	ICMP_UNREACH_NET	 0 | ||
| 156 | #define	ICMP_UNREACH_HOST	 1 | ||
| 157 | #define	ICMP_UNREACH_PROTOCOL	 2 | ||
| 158 | #define	ICMP_UNREACH_PORT	 3 | ||
| 159 | #define	ICMP_UNREACH_NEEDFRAG	 4 | ||
| 160 | #define	ICMP_UNREACH_SRCFAIL	 5 | ||
| 161 | #define	ICMP_UNREACH_NET_UNKNOWN 6 | ||
| 162 | #define	ICMP_UNREACH_HOST_UNKNOWN 7 | ||
| 163 | #define	ICMP_UNREACH_ISOLATED	 8 | ||
| 164 | #define	ICMP_UNREACH_NET_PROHIB	 9 | ||
| 165 | #define	ICMP_UNREACH_HOST_PROHIB 10 | ||
| 166 | #define	ICMP_UNREACH_TOSNET	 11 | ||
| 167 | #define	ICMP_UNREACH_TOSHOST	 12 | ||
| 168 | #define	ICMP_UNREACH_FILTER_PROHIB 13 | ||
| 169 | #define	ICMP_UNREACH_HOST_PRECEDENCE 14 | ||
| 170 | #define	ICMP_UNREACH_PRECEDENCE_CUTOFF 15 | ||
| 171 | |||
| 172 | #define	ICMP_REDIRECT_NET	0 | ||
| 173 | #define	ICMP_REDIRECT_HOST	1 | ||
| 174 | #define	ICMP_REDIRECT_TOSNET	2 | ||
| 175 | #define	ICMP_REDIRECT_TOSHOST	3 | ||
| 176 | |||
| 177 | #define	ICMP_TIMXCEED_INTRANS	0 | ||
| 178 | #define	ICMP_TIMXCEED_REASS	1 | ||
| 179 | |||
| 180 | #define	ICMP_PARAMPROB_OPTABSENT 1 | ||
| 181 | |||
| 182 | #define	ICMP_INFOTYPE(type) \ | ||
| 183 | 	((type) == ICMP_ECHOREPLY || (type) == ICMP_ECHO || \ | ||
| 184 | 	(type) == ICMP_ROUTERADVERT || (type) == ICMP_ROUTERSOLICIT || \ | ||
| 185 | 	(type) == ICMP_TSTAMP || (type) == ICMP_TSTAMPREPLY || \ | ||
| 186 | 	(type) == ICMP_IREQ || (type) == ICMP_IREQREPLY || \ | ||
| 187 | 	(type) == ICMP_MASKREQ || (type) == ICMP_MASKREPLY) | ||
| 188 | |||
| 189 | #ifdef __cplusplus | ||
| 190 | } | ||
| 191 | #endif | ||
| 192 | |||
| 193 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/tcp.h created+294| ... | @@ -0,0 +1,294 @@ | ||
| 1 | #ifndef _NETINET_TCP_H | ||
| 2 | #define _NETINET_TCP_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | #define TCP_NODELAY 1 | ||
| 7 | #define TCP_MAXSEG	 2 | ||
| 8 | #define TCP_CORK	 3 | ||
| 9 | #define TCP_KEEPIDLE	 4 | ||
| 10 | #define TCP_KEEPINTVL	 5 | ||
| 11 | #define TCP_KEEPCNT	 6 | ||
| 12 | #define TCP_SYNCNT	 7 | ||
| 13 | #define TCP_LINGER2	 8 | ||
| 14 | #define TCP_DEFER_ACCEPT 9 | ||
| 15 | #define TCP_WINDOW_CLAMP 10 | ||
| 16 | #define TCP_INFO	 11 | ||
| 17 | #define	TCP_QUICKACK	 12 | ||
| 18 | #define TCP_CONGESTION	 13 | ||
| 19 | #define TCP_MD5SIG	 14 | ||
| 20 | #define TCP_THIN_LINEAR_TIMEOUTS 16 | ||
| 21 | #define TCP_THIN_DUPACK 17 | ||
| 22 | #define TCP_USER_TIMEOUT 18 | ||
| 23 | #define TCP_REPAIR 19 | ||
| 24 | #define TCP_REPAIR_QUEUE 20 | ||
| 25 | #define TCP_QUEUE_SEQ 21 | ||
| 26 | #define TCP_REPAIR_OPTIONS 22 | ||
| 27 | #define TCP_FASTOPEN 23 | ||
| 28 | #define TCP_TIMESTAMP 24 | ||
| 29 | #define TCP_NOTSENT_LOWAT 25 | ||
| 30 | #define TCP_CC_INFO 26 | ||
| 31 | #define TCP_SAVE_SYN 27 | ||
| 32 | #define TCP_SAVED_SYN 28 | ||
| 33 | #define TCP_REPAIR_WINDOW 29 | ||
| 34 | #define TCP_FASTOPEN_CONNECT 30 | ||
| 35 | #define TCP_ULP 31 | ||
| 36 | #define TCP_MD5SIG_EXT 32 | ||
| 37 | #define TCP_FASTOPEN_KEY 33 | ||
| 38 | #define TCP_FASTOPEN_NO_COOKIE 34 | ||
| 39 | #define TCP_ZEROCOPY_RECEIVE 35 | ||
| 40 | #define TCP_INQ 36 | ||
| 41 | #define TCP_TX_DELAY 37 | ||
| 42 | |||
| 43 | #define TCP_CM_INQ TCP_INQ | ||
| 44 | |||
| 45 | #define TCP_ESTABLISHED 1 | ||
| 46 | #define TCP_SYN_SENT 2 | ||
| 47 | #define TCP_SYN_RECV 3 | ||
| 48 | #define TCP_FIN_WAIT1 4 | ||
| 49 | #define TCP_FIN_WAIT2 5 | ||
| 50 | #define TCP_TIME_WAIT 6 | ||
| 51 | #define TCP_CLOSE 7 | ||
| 52 | #define TCP_CLOSE_WAIT 8 | ||
| 53 | #define TCP_LAST_ACK 9 | ||
| 54 | #define TCP_LISTEN 10 | ||
| 55 | #define TCP_CLOSING 11 | ||
| 56 | |||
| 57 | enum { | ||
| 58 | 	TCP_NLA_PAD, | ||
| 59 | 	TCP_NLA_BUSY, | ||
| 60 | 	TCP_NLA_RWND_LIMITED, | ||
| 61 | 	TCP_NLA_SNDBUF_LIMITED, | ||
| 62 | 	TCP_NLA_DATA_SEGS_OUT, | ||
| 63 | 	TCP_NLA_TOTAL_RETRANS, | ||
| 64 | 	TCP_NLA_PACING_RATE, | ||
| 65 | 	TCP_NLA_DELIVERY_RATE, | ||
| 66 | 	TCP_NLA_SND_CWND, | ||
| 67 | 	TCP_NLA_REORDERING, | ||
| 68 | 	TCP_NLA_MIN_RTT, | ||
| 69 | 	TCP_NLA_RECUR_RETRANS, | ||
| 70 | 	TCP_NLA_DELIVERY_RATE_APP_LMT, | ||
| 71 | 	TCP_NLA_SNDQ_SIZE, | ||
| 72 | 	TCP_NLA_CA_STATE, | ||
| 73 | 	TCP_NLA_SND_SSTHRESH, | ||
| 74 | 	TCP_NLA_DELIVERED, | ||
| 75 | 	TCP_NLA_DELIVERED_CE, | ||
| 76 | 	TCP_NLA_BYTES_SENT, | ||
| 77 | 	TCP_NLA_BYTES_RETRANS, | ||
| 78 | 	TCP_NLA_DSACK_DUPS, | ||
| 79 | 	TCP_NLA_REORD_SEEN, | ||
| 80 | 	TCP_NLA_SRTT, | ||
| 81 | 	TCP_NLA_TIMEOUT_REHASH, | ||
| 82 | 	TCP_NLA_BYTES_NOTSENT, | ||
| 83 | }; | ||
| 84 | |||
| 85 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 86 | #define TCPOPT_EOL 0 | ||
| 87 | #define TCPOPT_NOP 1 | ||
| 88 | #define TCPOPT_MAXSEG 2 | ||
| 89 | #define TCPOPT_WINDOW 3 | ||
| 90 | #define TCPOPT_SACK_PERMITTED 4 | ||
| 91 | #define TCPOPT_SACK 5 | ||
| 92 | #define TCPOPT_TIMESTAMP 8 | ||
| 93 | #define TCPOLEN_SACK_PERMITTED 2 | ||
| 94 | #define TCPOLEN_WINDOW 3 | ||
| 95 | #define TCPOLEN_MAXSEG 4 | ||
| 96 | #define TCPOLEN_TIMESTAMP 10 | ||
| 97 | |||
| 98 | #define SOL_TCP 6 | ||
| 99 | |||
| 100 | #include <sys/types.h> | ||
| 101 | #include <sys/socket.h> | ||
| 102 | #include <stdint.h> | ||
| 103 | |||
| 104 | typedef uint32_t tcp_seq; | ||
| 105 | |||
| 106 | #define TH_FIN 0x01 | ||
| 107 | #define TH_SYN 0x02 | ||
| 108 | #define TH_RST 0x04 | ||
| 109 | #define TH_PUSH 0x08 | ||
| 110 | #define TH_ACK 0x10 | ||
| 111 | #define TH_URG 0x20 | ||
| 112 | |||
| 113 | struct tcphdr { | ||
| 114 | #ifdef _GNU_SOURCE | ||
| 115 | #ifdef __GNUC__ | ||
| 116 | 	__extension__ | ||
| 117 | #endif | ||
| 118 | 	union { struct { | ||
| 119 | |||
| 120 | 	uint16_t source; | ||
| 121 | 	uint16_t dest; | ||
| 122 | 	uint32_t seq; | ||
| 123 | 	uint32_t ack_seq; | ||
| 124 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 125 | 	uint16_t res1:4; | ||
| 126 | 	uint16_t doff:4; | ||
| 127 | 	uint16_t fin:1; | ||
| 128 | 	uint16_t syn:1; | ||
| 129 | 	uint16_t rst:1; | ||
| 130 | 	uint16_t psh:1; | ||
| 131 | 	uint16_t ack:1; | ||
| 132 | 	uint16_t urg:1; | ||
| 133 | 	uint16_t res2:2; | ||
| 134 | #else | ||
| 135 | 	uint16_t doff:4; | ||
| 136 | 	uint16_t res1:4; | ||
| 137 | 	uint16_t res2:2; | ||
| 138 | 	uint16_t urg:1; | ||
| 139 | 	uint16_t ack:1; | ||
| 140 | 	uint16_t psh:1; | ||
| 141 | 	uint16_t rst:1; | ||
| 142 | 	uint16_t syn:1; | ||
| 143 | 	uint16_t fin:1; | ||
| 144 | #endif | ||
| 145 | 	uint16_t window; | ||
| 146 | 	uint16_t check; | ||
| 147 | 	uint16_t urg_ptr; | ||
| 148 | |||
| 149 | 	}; struct { | ||
| 150 | #endif | ||
| 151 | |||
| 152 | 	uint16_t th_sport; | ||
| 153 | 	uint16_t th_dport; | ||
| 154 | 	uint32_t th_seq; | ||
| 155 | 	uint32_t th_ack; | ||
| 156 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 157 | 	uint8_t th_x2:4; | ||
| 158 | 	uint8_t th_off:4; | ||
| 159 | #else | ||
| 160 | 	uint8_t th_off:4; | ||
| 161 | 	uint8_t th_x2:4; | ||
| 162 | #endif | ||
| 163 | 	uint8_t th_flags; | ||
| 164 | 	uint16_t th_win; | ||
| 165 | 	uint16_t th_sum; | ||
| 166 | 	uint16_t th_urp; | ||
| 167 | |||
| 168 | #ifdef _GNU_SOURCE | ||
| 169 | 	}; }; | ||
| 170 | #endif | ||
| 171 | }; | ||
| 172 | #endif | ||
| 173 | |||
| 174 | #ifdef _GNU_SOURCE | ||
| 175 | #define TCPI_OPT_TIMESTAMPS	1 | ||
| 176 | #define TCPI_OPT_SACK		2 | ||
| 177 | #define TCPI_OPT_WSCALE		4 | ||
| 178 | #define TCPI_OPT_ECN		8 | ||
| 179 | |||
| 180 | #define TCP_CA_Open		0 | ||
| 181 | #define TCP_CA_Disorder		1 | ||
| 182 | #define TCP_CA_CWR		2 | ||
| 183 | #define TCP_CA_Recovery		3 | ||
| 184 | #define TCP_CA_Loss		4 | ||
| 185 | |||
| 186 | enum tcp_fastopen_client_fail { | ||
| 187 | 	TFO_STATUS_UNSPEC, | ||
| 188 | 	TFO_COOKIE_UNAVAILABLE, | ||
| 189 | 	TFO_DATA_NOT_ACKED, | ||
| 190 | 	TFO_SYN_RETRANSMITTED, | ||
| 191 | }; | ||
| 192 | |||
| 193 | struct tcp_info { | ||
| 194 | 	uint8_t tcpi_state; | ||
| 195 | 	uint8_t tcpi_ca_state; | ||
| 196 | 	uint8_t tcpi_retransmits; | ||
| 197 | 	uint8_t tcpi_probes; | ||
| 198 | 	uint8_t tcpi_backoff; | ||
| 199 | 	uint8_t tcpi_options; | ||
| 200 | 	uint8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; | ||
| 201 | 	uint8_t tcpi_delivery_rate_app_limited : 1, tcpi_fastopen_client_fail : 2; | ||
| 202 | 	uint32_t tcpi_rto; | ||
| 203 | 	uint32_t tcpi_ato; | ||
| 204 | 	uint32_t tcpi_snd_mss; | ||
| 205 | 	uint32_t tcpi_rcv_mss; | ||
| 206 | 	uint32_t tcpi_unacked; | ||
| 207 | 	uint32_t tcpi_sacked; | ||
| 208 | 	uint32_t tcpi_lost; | ||
| 209 | 	uint32_t tcpi_retrans; | ||
| 210 | 	uint32_t tcpi_fackets; | ||
| 211 | 	uint32_t tcpi_last_data_sent; | ||
| 212 | 	uint32_t tcpi_last_ack_sent; | ||
| 213 | 	uint32_t tcpi_last_data_recv; | ||
| 214 | 	uint32_t tcpi_last_ack_recv; | ||
| 215 | 	uint32_t tcpi_pmtu; | ||
| 216 | 	uint32_t tcpi_rcv_ssthresh; | ||
| 217 | 	uint32_t tcpi_rtt; | ||
| 218 | 	uint32_t tcpi_rttvar; | ||
| 219 | 	uint32_t tcpi_snd_ssthresh; | ||
| 220 | 	uint32_t tcpi_snd_cwnd; | ||
| 221 | 	uint32_t tcpi_advmss; | ||
| 222 | 	uint32_t tcpi_reordering; | ||
| 223 | 	uint32_t tcpi_rcv_rtt; | ||
| 224 | 	uint32_t tcpi_rcv_space; | ||
| 225 | 	uint32_t tcpi_total_retrans; | ||
| 226 | 	uint64_t tcpi_pacing_rate; | ||
| 227 | 	uint64_t tcpi_max_pacing_rate; | ||
| 228 | 	uint64_t tcpi_bytes_acked; | ||
| 229 | 	uint64_t tcpi_bytes_received; | ||
| 230 | 	uint32_t tcpi_segs_out; | ||
| 231 | 	uint32_t tcpi_segs_in; | ||
| 232 | 	uint32_t tcpi_notsent_bytes; | ||
| 233 | 	uint32_t tcpi_min_rtt; | ||
| 234 | 	uint32_t tcpi_data_segs_in; | ||
| 235 | 	uint32_t tcpi_data_segs_out; | ||
| 236 | 	uint64_t tcpi_delivery_rate; | ||
| 237 | 	uint64_t tcpi_busy_time; | ||
| 238 | 	uint64_t tcpi_rwnd_limited; | ||
| 239 | 	uint64_t tcpi_sndbuf_limited; | ||
| 240 | 	uint32_t tcpi_delivered; | ||
| 241 | 	uint32_t tcpi_delivered_ce; | ||
| 242 | 	uint64_t tcpi_bytes_sent; | ||
| 243 | 	uint64_t tcpi_bytes_retrans; | ||
| 244 | 	uint32_t tcpi_dsack_dups; | ||
| 245 | 	uint32_t tcpi_reord_seen; | ||
| 246 | 	uint32_t tcpi_rcv_ooopack; | ||
| 247 | 	uint32_t tcpi_snd_wnd; | ||
| 248 | }; | ||
| 249 | |||
| 250 | #define TCP_MD5SIG_MAXKEYLEN 80 | ||
| 251 | |||
| 252 | #define TCP_MD5SIG_FLAG_PREFIX 0x1 | ||
| 253 | #define TCP_MD5SIG_FLAG_IFINDEX 0x2 | ||
| 254 | |||
| 255 | struct tcp_md5sig { | ||
| 256 | 	struct sockaddr_storage tcpm_addr; | ||
| 257 | 	uint8_t tcpm_flags; | ||
| 258 | 	uint8_t tcpm_prefixlen; | ||
| 259 | 	uint16_t tcpm_keylen; | ||
| 260 | 	int tcpm_ifindex; | ||
| 261 | 	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; | ||
| 262 | }; | ||
| 263 | |||
| 264 | struct tcp_diag_md5sig { | ||
| 265 | 	uint8_t tcpm_family; | ||
| 266 | 	uint8_t tcpm_prefixlen; | ||
| 267 | 	uint16_t tcpm_keylen; | ||
| 268 | 	uint32_t tcpm_addr[4]; | ||
| 269 | 	uint8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; | ||
| 270 | }; | ||
| 271 | |||
| 272 | #define TCP_REPAIR_ON		1 | ||
| 273 | #define TCP_REPAIR_OFF		0 | ||
| 274 | #define TCP_REPAIR_OFF_NO_WP	-1 | ||
| 275 | |||
| 276 | struct tcp_repair_window { | ||
| 277 | 	uint32_t snd_wl1; | ||
| 278 | 	uint32_t snd_wnd; | ||
| 279 | 	uint32_t max_window; | ||
| 280 | 	uint32_t rcv_wnd; | ||
| 281 | 	uint32_t rcv_wup; | ||
| 282 | }; | ||
| 283 | |||
| 284 | struct tcp_zerocopy_receive { | ||
| 285 | 	uint64_t address; | ||
| 286 | 	uint32_t length; | ||
| 287 | 	uint32_t recv_skip_hint; | ||
| 288 | 	uint32_t inq; | ||
| 289 | 	int32_t err; | ||
| 290 | }; | ||
| 291 | |||
| 292 | #endif | ||
| 293 | |||
| 294 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netinet/udp.h created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #ifndef _NETINET_UDP_H | ||
| 2 | #define _NETINET_UDP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #ifdef _GNU_SOURCE | ||
| 12 | #define uh_sport source | ||
| 13 | #define uh_dport dest | ||
| 14 | #define uh_ulen len | ||
| 15 | #define uh_sum check | ||
| 16 | #endif | ||
| 17 | |||
| 18 | struct udphdr { | ||
| 19 | 	uint16_t uh_sport; | ||
| 20 | 	uint16_t uh_dport; | ||
| 21 | 	uint16_t uh_ulen; | ||
| 22 | 	uint16_t uh_sum; | ||
| 23 | }; | ||
| 24 | |||
| 25 | #define UDP_CORK	1 | ||
| 26 | #define UDP_ENCAP	100 | ||
| 27 | #define UDP_NO_CHECK6_TX 101 | ||
| 28 | #define UDP_NO_CHECK6_RX 102 | ||
| 29 | #define UDP_SEGMENT	103 | ||
| 30 | #define UDP_GRO		104 | ||
| 31 | |||
| 32 | #define UDP_ENCAP_ESPINUDP_NON_IKE 1 | ||
| 33 | #define UDP_ENCAP_ESPINUDP	2 | ||
| 34 | #define UDP_ENCAP_L2TPINUDP	3 | ||
| 35 | #define UDP_ENCAP_GTP0		4 | ||
| 36 | #define UDP_ENCAP_GTP1U		5 | ||
| 37 | #define UDP_ENCAP_RXRPC		6 | ||
| 38 | #define TCP_ENCAP_ESPINTCP	7 | ||
| 39 | |||
| 40 | #define SOL_UDP 17 | ||
| 41 | |||
| 42 | #ifdef __cplusplus | ||
| 43 | } | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/netpacket/packet.h created+62| ... | @@ -0,0 +1,62 @@ | ||
| 1 | #ifndef _NETPACKET_PACKET_H | ||
| 2 | #define _NETPACKET_PACKET_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | struct sockaddr_ll { | ||
| 9 | 	unsigned short sll_family, sll_protocol; | ||
| 10 | 	int sll_ifindex; | ||
| 11 | 	unsigned short sll_hatype; | ||
| 12 | 	unsigned char sll_pkttype, sll_halen; | ||
| 13 | 	unsigned char sll_addr[8]; | ||
| 14 | }; | ||
| 15 | |||
| 16 | struct packet_mreq { | ||
| 17 | 	int mr_ifindex; | ||
| 18 | 	unsigned short int mr_type, mr_alen; | ||
| 19 | 	unsigned char mr_address[8]; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #define PACKET_HOST		0 | ||
| 23 | #define PACKET_BROADCAST	1 | ||
| 24 | #define PACKET_MULTICAST	2 | ||
| 25 | #define PACKET_OTHERHOST	3 | ||
| 26 | #define PACKET_OUTGOING		4 | ||
| 27 | #define PACKET_LOOPBACK		5 | ||
| 28 | #define PACKET_FASTROUTE	6 | ||
| 29 | |||
| 30 | #define PACKET_ADD_MEMBERSHIP		1 | ||
| 31 | #define PACKET_DROP_MEMBERSHIP		2 | ||
| 32 | #define	PACKET_RECV_OUTPUT		3 | ||
| 33 | #define	PACKET_RX_RING			5 | ||
| 34 | #define	PACKET_STATISTICS		6 | ||
| 35 | #define PACKET_COPY_THRESH		7 | ||
| 36 | #define PACKET_AUXDATA			8 | ||
| 37 | #define PACKET_ORIGDEV			9 | ||
| 38 | #define PACKET_VERSION			10 | ||
| 39 | #define PACKET_HDRLEN			11 | ||
| 40 | #define PACKET_RESERVE			12 | ||
| 41 | #define PACKET_TX_RING			13 | ||
| 42 | #define PACKET_LOSS			14 | ||
| 43 | #define PACKET_VNET_HDR			15 | ||
| 44 | #define PACKET_TX_TIMESTAMP		16 | ||
| 45 | #define PACKET_TIMESTAMP		17 | ||
| 46 | #define PACKET_FANOUT			18 | ||
| 47 | #define PACKET_TX_HAS_OFF		19 | ||
| 48 | #define PACKET_QDISC_BYPASS		20 | ||
| 49 | #define PACKET_ROLLOVER_STATS		21 | ||
| 50 | #define PACKET_FANOUT_DATA		22 | ||
| 51 | #define PACKET_IGNORE_OUTGOING		23 | ||
| 52 | |||
| 53 | #define PACKET_MR_MULTICAST	0 | ||
| 54 | #define PACKET_MR_PROMISC	1 | ||
| 55 | #define PACKET_MR_ALLMULTI	2 | ||
| 56 | #define PACKET_MR_UNICAST	3 | ||
| 57 | |||
| 58 | #ifdef __cplusplus | ||
| 59 | } | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/nl_types.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #ifndef _NL_TYPES_H | ||
| 2 | #define _NL_TYPES_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define NL_SETD 1 | ||
| 9 | #define NL_CAT_LOCALE 1 | ||
| 10 | |||
| 11 | typedef int nl_item; | ||
| 12 | typedef void *nl_catd; | ||
| 13 | |||
| 14 | nl_catd catopen (const char *, int); | ||
| 15 | char *catgets (nl_catd, int, int, const char *); | ||
| 16 | int catclose (nl_catd); | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/paths.h created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #ifndef _PATHS_H | ||
| 2 | #define _PATHS_H | ||
| 3 | |||
| 4 | #define	_PATH_DEFPATH "/usr/local/bin:/bin:/usr/bin" | ||
| 5 | #define	_PATH_STDPATH "/bin:/usr/bin:/sbin:/usr/sbin" | ||
| 6 | |||
| 7 | #define	_PATH_BSHELL	"/bin/sh" | ||
| 8 | #define	_PATH_CONSOLE	"/dev/console" | ||
| 9 | #define	_PATH_DEVNULL	"/dev/null" | ||
| 10 | #define	_PATH_KLOG	"/proc/kmsg" | ||
| 11 | #define	_PATH_LASTLOG	"/var/log/lastlog" | ||
| 12 | #define	_PATH_MAILDIR	"/var/mail" | ||
| 13 | #define	_PATH_MAN	"/usr/share/man" | ||
| 14 | #define	_PATH_MNTTAB	"/etc/fstab" | ||
| 15 | #define	_PATH_MOUNTED	"/etc/mtab" | ||
| 16 | #define	_PATH_NOLOGIN	"/etc/nologin" | ||
| 17 | #define	_PATH_SENDMAIL	"/usr/sbin/sendmail" | ||
| 18 | #define	_PATH_SHADOW	"/etc/shadow" | ||
| 19 | #define	_PATH_SHELLS	"/etc/shells" | ||
| 20 | #define	_PATH_TTY	"/dev/tty" | ||
| 21 | #define _PATH_UTMP	"/dev/null/utmp" | ||
| 22 | #define	_PATH_VI	"/usr/bin/vi" | ||
| 23 | #define _PATH_WTMP	"/dev/null/wtmp" | ||
| 24 | |||
| 25 | #define	_PATH_DEV	"/dev/" | ||
| 26 | #define	_PATH_TMP	"/tmp/" | ||
| 27 | #define	_PATH_VARDB	"/var/lib/misc/" | ||
| 28 | #define	_PATH_VARRUN	"/var/run/" | ||
| 29 | #define	_PATH_VARTMP	"/var/tmp/" | ||
| 30 | |||
| 31 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/poll.h created+69| ... | @@ -0,0 +1,69 @@ | ||
| 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 | #ifdef _GNU_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 | #ifdef _GNU_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 created+249| ... | @@ -0,0 +1,249 @@ | ||
| 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 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 59 | #define PTHREAD_MUTEX_INITIALIZER {{{0}}} | ||
| 60 | #define PTHREAD_RWLOCK_INITIALIZER {{{0}}} | ||
| 61 | #define PTHREAD_COND_INITIALIZER {{{0}}} | ||
| 62 | #else | ||
| 63 | #define PTHREAD_MUTEX_INITIALIZER 0 | ||
| 64 | #define PTHREAD_RWLOCK_INITIALIZER 0 | ||
| 65 | #define PTHREAD_COND_INITIALIZER 0 | ||
| 66 | #endif | ||
| 67 | #define PTHREAD_ONCE_INIT 0 | ||
| 68 | |||
| 69 | |||
| 70 | #define PTHREAD_CANCEL_ENABLE 0 | ||
| 71 | #define PTHREAD_CANCEL_DISABLE 1 | ||
| 72 | #define PTHREAD_CANCEL_MASKED 2 | ||
| 73 | |||
| 74 | #define PTHREAD_CANCEL_DEFERRED 0 | ||
| 75 | #define PTHREAD_CANCEL_ASYNCHRONOUS 1 | ||
| 76 | |||
| 77 | #define PTHREAD_CANCELED ((void *)-1) | ||
| 78 | |||
| 79 | |||
| 80 | #define PTHREAD_BARRIER_SERIAL_THREAD (-1) | ||
| 81 | |||
| 82 | |||
| 83 | #define PTHREAD_NULL ((pthread_t)0) | ||
| 84 | |||
| 85 | |||
| 86 | int pthread_create(pthread_t *__restrict, const pthread_attr_t *__restrict, void *(*)(void *), void *__restrict); | ||
| 87 | int pthread_detach(pthread_t); | ||
| 88 | _Noreturn void pthread_exit(void *); | ||
| 89 | int pthread_join(pthread_t, void **); | ||
| 90 | |||
| 91 | #ifdef __GNUC__ | ||
| 92 | __attribute__((const)) | ||
| 93 | #endif | ||
| 94 | pthread_t pthread_self(void); | ||
| 95 | |||
| 96 | int pthread_equal(pthread_t, pthread_t); | ||
| 97 | #ifndef __cplusplus | ||
| 98 | #define pthread_equal(x,y) ((x)==(y)) | ||
| 99 | #endif | ||
| 100 | |||
| 101 | int pthread_setcancelstate(int, int *); | ||
| 102 | int pthread_setcanceltype(int, int *); | ||
| 103 | void pthread_testcancel(void); | ||
| 104 | int pthread_cancel(pthread_t); | ||
| 105 | |||
| 106 | int pthread_getschedparam(pthread_t, int *__restrict, struct sched_param *__restrict); | ||
| 107 | int pthread_setschedparam(pthread_t, int, const struct sched_param *); | ||
| 108 | int pthread_setschedprio(pthread_t, int); | ||
| 109 | |||
| 110 | int pthread_once(pthread_once_t *, void (*)(void)); | ||
| 111 | |||
| 112 | int pthread_mutex_init(pthread_mutex_t *__restrict, const pthread_mutexattr_t *__restrict); | ||
| 113 | int pthread_mutex_lock(pthread_mutex_t *); | ||
| 114 | int pthread_mutex_unlock(pthread_mutex_t *); | ||
| 115 | int pthread_mutex_trylock(pthread_mutex_t *); | ||
| 116 | int pthread_mutex_timedlock(pthread_mutex_t *__restrict, const struct timespec *__restrict); | ||
| 117 | int pthread_mutex_destroy(pthread_mutex_t *); | ||
| 118 | int pthread_mutex_consistent(pthread_mutex_t *); | ||
| 119 | |||
| 120 | int pthread_mutex_getprioceiling(const pthread_mutex_t *__restrict, int *__restrict); | ||
| 121 | int pthread_mutex_setprioceiling(pthread_mutex_t *__restrict, int, int *__restrict); | ||
| 122 | |||
| 123 | int pthread_cond_init(pthread_cond_t *__restrict, const pthread_condattr_t *__restrict); | ||
| 124 | int pthread_cond_destroy(pthread_cond_t *); | ||
| 125 | int pthread_cond_wait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict); | ||
| 126 | int pthread_cond_timedwait(pthread_cond_t *__restrict, pthread_mutex_t *__restrict, const struct timespec *__restrict); | ||
| 127 | int pthread_cond_broadcast(pthread_cond_t *); | ||
| 128 | int pthread_cond_signal(pthread_cond_t *); | ||
| 129 | |||
| 130 | int pthread_rwlock_init(pthread_rwlock_t *__restrict, const pthread_rwlockattr_t *__restrict); | ||
| 131 | int pthread_rwlock_destroy(pthread_rwlock_t *); | ||
| 132 | int pthread_rwlock_rdlock(pthread_rwlock_t *); | ||
| 133 | int pthread_rwlock_tryrdlock(pthread_rwlock_t *); | ||
| 134 | int pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 135 | int pthread_rwlock_wrlock(pthread_rwlock_t *); | ||
| 136 | int pthread_rwlock_trywrlock(pthread_rwlock_t *); | ||
| 137 | int pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 138 | int pthread_rwlock_unlock(pthread_rwlock_t *); | ||
| 139 | |||
| 140 | int pthread_spin_init(pthread_spinlock_t *, int); | ||
| 141 | int pthread_spin_destroy(pthread_spinlock_t *); | ||
| 142 | int pthread_spin_lock(pthread_spinlock_t *); | ||
| 143 | int pthread_spin_trylock(pthread_spinlock_t *); | ||
| 144 | int pthread_spin_unlock(pthread_spinlock_t *); | ||
| 145 | |||
| 146 | int pthread_barrier_init(pthread_barrier_t *__restrict, const pthread_barrierattr_t *__restrict, unsigned); | ||
| 147 | int pthread_barrier_destroy(pthread_barrier_t *); | ||
| 148 | int pthread_barrier_wait(pthread_barrier_t *); | ||
| 149 | |||
| 150 | int pthread_key_create(pthread_key_t *, void (*)(void *)); | ||
| 151 | int pthread_key_delete(pthread_key_t); | ||
| 152 | void *pthread_getspecific(pthread_key_t); | ||
| 153 | int pthread_setspecific(pthread_key_t, const void *); | ||
| 154 | |||
| 155 | int pthread_attr_init(pthread_attr_t *); | ||
| 156 | int pthread_attr_destroy(pthread_attr_t *); | ||
| 157 | |||
| 158 | int pthread_attr_getguardsize(const pthread_attr_t *__restrict, size_t *__restrict); | ||
| 159 | int pthread_attr_setguardsize(pthread_attr_t *, size_t); | ||
| 160 | int pthread_attr_getstacksize(const pthread_attr_t *__restrict, size_t *__restrict); | ||
| 161 | int pthread_attr_setstacksize(pthread_attr_t *, size_t); | ||
| 162 | int pthread_attr_getdetachstate(const pthread_attr_t *, int *); | ||
| 163 | int pthread_attr_setdetachstate(pthread_attr_t *, int); | ||
| 164 | int pthread_attr_getstack(const pthread_attr_t *__restrict, void **__restrict, size_t *__restrict); | ||
| 165 | int pthread_attr_setstack(pthread_attr_t *, void *, size_t); | ||
| 166 | int pthread_attr_getscope(const pthread_attr_t *__restrict, int *__restrict); | ||
| 167 | int pthread_attr_setscope(pthread_attr_t *, int); | ||
| 168 | int pthread_attr_getschedpolicy(const pthread_attr_t *__restrict, int *__restrict); | ||
| 169 | int pthread_attr_setschedpolicy(pthread_attr_t *, int); | ||
| 170 | int pthread_attr_getschedparam(const pthread_attr_t *__restrict, struct sched_param *__restrict); | ||
| 171 | int pthread_attr_setschedparam(pthread_attr_t *__restrict, const struct sched_param *__restrict); | ||
| 172 | int pthread_attr_getinheritsched(const pthread_attr_t *__restrict, int *__restrict); | ||
| 173 | int pthread_attr_setinheritsched(pthread_attr_t *, int); | ||
| 174 | |||
| 175 | int pthread_mutexattr_destroy(pthread_mutexattr_t *); | ||
| 176 | int pthread_mutexattr_getprioceiling(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 177 | int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 178 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 179 | int pthread_mutexattr_getrobust(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 180 | int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict, int *__restrict); | ||
| 181 | int pthread_mutexattr_init(pthread_mutexattr_t *); | ||
| 182 | int pthread_mutexattr_setprioceiling(pthread_mutexattr_t *, int); | ||
| 183 | int pthread_mutexattr_setprotocol(pthread_mutexattr_t *, int); | ||
| 184 | int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int); | ||
| 185 | int pthread_mutexattr_setrobust(pthread_mutexattr_t *, int); | ||
| 186 | int pthread_mutexattr_settype(pthread_mutexattr_t *, int); | ||
| 187 | |||
| 188 | int pthread_condattr_init(pthread_condattr_t *); | ||
| 189 | int pthread_condattr_destroy(pthread_condattr_t *); | ||
| 190 | int pthread_condattr_setclock(pthread_condattr_t *, clockid_t); | ||
| 191 | int pthread_condattr_setpshared(pthread_condattr_t *, int); | ||
| 192 | int pthread_condattr_getclock(const pthread_condattr_t *__restrict, clockid_t *__restrict); | ||
| 193 | int pthread_condattr_getpshared(const pthread_condattr_t *__restrict, int *__restrict); | ||
| 194 | |||
| 195 | int pthread_rwlockattr_init(pthread_rwlockattr_t *); | ||
| 196 | int pthread_rwlockattr_destroy(pthread_rwlockattr_t *); | ||
| 197 | int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *, int); | ||
| 198 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *__restrict, int *__restrict); | ||
| 199 | |||
| 200 | int pthread_barrierattr_destroy(pthread_barrierattr_t *); | ||
| 201 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *__restrict, int *__restrict); | ||
| 202 | int pthread_barrierattr_init(pthread_barrierattr_t *); | ||
| 203 | int pthread_barrierattr_setpshared(pthread_barrierattr_t *, int); | ||
| 204 | |||
| 205 | int pthread_atfork(void (*)(void), void (*)(void), void (*)(void)); | ||
| 206 | |||
| 207 | int pthread_getconcurrency(void); | ||
| 208 | int pthread_setconcurrency(int); | ||
| 209 | |||
| 210 | int pthread_getcpuclockid(pthread_t, clockid_t *); | ||
| 211 | |||
| 212 | struct __ptcb { | ||
| 213 | 	void (*__f)(void *); | ||
| 214 | 	void *__x; | ||
| 215 | 	struct __ptcb *__next; | ||
| 216 | }; | ||
| 217 | |||
| 218 | void _pthread_cleanup_push(struct __ptcb *, void (*)(void *), void *); | ||
| 219 | void _pthread_cleanup_pop(struct __ptcb *, int); | ||
| 220 | |||
| 221 | #define pthread_cleanup_push(f, x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); | ||
| 222 | #define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) | ||
| 223 | |||
| 224 | #ifdef _GNU_SOURCE | ||
| 225 | struct cpu_set_t; | ||
| 226 | int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *); | ||
| 227 | int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *); | ||
| 228 | int pthread_getattr_np(pthread_t, pthread_attr_t *); | ||
| 229 | int pthread_setname_np(pthread_t, const char *); | ||
| 230 | int pthread_getattr_default_np(pthread_attr_t *); | ||
| 231 | int pthread_setattr_default_np(const pthread_attr_t *); | ||
| 232 | int pthread_tryjoin_np(pthread_t, void **); | ||
| 233 | int pthread_timedjoin_np(pthread_t, void **, const struct timespec *); | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #if _REDIR_TIME64 | ||
| 237 | __REDIR(pthread_mutex_timedlock, __pthread_mutex_timedlock_time64); | ||
| 238 | __REDIR(pthread_cond_timedwait, __pthread_cond_timedwait_time64); | ||
| 239 | __REDIR(pthread_rwlock_timedrdlock, __pthread_rwlock_timedrdlock_time64); | ||
| 240 | __REDIR(pthread_rwlock_timedwrlock, __pthread_rwlock_timedwrlock_time64); | ||
| 241 | #ifdef _GNU_SOURCE | ||
| 242 | __REDIR(pthread_timedjoin_np, __pthread_timedjoin_np_time64); | ||
| 243 | #endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifdef __cplusplus | ||
| 247 | } | ||
| 248 | #endif | ||
| 249 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/pty.h created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #ifndef	_PTY_H | ||
| 2 | #define	_PTY_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <termios.h> | ||
| 9 | #include <sys/ioctl.h> | ||
| 10 | |||
| 11 | int openpty(int *, int *, char *, const struct termios *, const struct winsize *); | ||
| 12 | int forkpty(int *, char *, const struct termios *, const struct winsize *); | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/pwd.h created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | #ifndef _PWD_H | ||
| 2 | #define _PWD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | #define __NEED_uid_t | ||
| 12 | #define __NEED_gid_t | ||
| 13 | |||
| 14 | #ifdef _GNU_SOURCE | ||
| 15 | #define __NEED_FILE | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #include <bits/alltypes.h> | ||
| 19 | |||
| 20 | struct passwd { | ||
| 21 | 	char *pw_name; | ||
| 22 | 	char *pw_passwd; | ||
| 23 | 	uid_t pw_uid; | ||
| 24 | 	gid_t pw_gid; | ||
| 25 | 	char *pw_gecos; | ||
| 26 | 	char *pw_dir; | ||
| 27 | 	char *pw_shell; | ||
| 28 | }; | ||
| 29 | |||
| 30 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 31 | void setpwent (void); | ||
| 32 | void endpwent (void); | ||
| 33 | struct passwd *getpwent (void); | ||
| 34 | #endif | ||
| 35 | |||
| 36 | struct passwd *getpwuid (uid_t); | ||
| 37 | struct passwd *getpwnam (const char *); | ||
| 38 | int getpwuid_r (uid_t, struct passwd *, char *, size_t, struct passwd **); | ||
| 39 | int getpwnam_r (const char *, struct passwd *, char *, size_t, struct passwd **); | ||
| 40 | |||
| 41 | #ifdef _GNU_SOURCE | ||
| 42 | struct passwd *fgetpwent(FILE *); | ||
| 43 | int putpwent(const struct passwd *, FILE *); | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #ifdef __cplusplus | ||
| 47 | } | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/regex.h created+62| ... | @@ -0,0 +1,62 @@ | ||
| 1 | #ifndef _REGEX_H | ||
| 2 | #define _REGEX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_regoff_t | ||
| 11 | #define __NEED_size_t | ||
| 12 | |||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | typedef struct re_pattern_buffer { | ||
| 16 | 	size_t re_nsub; | ||
| 17 | 	void *__opaque, *__padding[4]; | ||
| 18 | 	size_t __nsub2; | ||
| 19 | 	char __padding2; | ||
| 20 | } regex_t; | ||
| 21 | |||
| 22 | typedef struct { | ||
| 23 | 	regoff_t rm_so; | ||
| 24 | 	regoff_t rm_eo; | ||
| 25 | } regmatch_t; | ||
| 26 | |||
| 27 | #define REG_EXTENDED 1 | ||
| 28 | #define REG_ICASE 2 | ||
| 29 | #define REG_NEWLINE 4 | ||
| 30 | #define REG_NOSUB 8 | ||
| 31 | |||
| 32 | #define REG_NOTBOL 1 | ||
| 33 | #define REG_NOTEOL 2 | ||
| 34 | |||
| 35 | #define REG_OK 0 | ||
| 36 | #define REG_NOMATCH 1 | ||
| 37 | #define REG_BADPAT 2 | ||
| 38 | #define REG_ECOLLATE 3 | ||
| 39 | #define REG_ECTYPE 4 | ||
| 40 | #define REG_EESCAPE 5 | ||
| 41 | #define REG_ESUBREG 6 | ||
| 42 | #define REG_EBRACK 7 | ||
| 43 | #define REG_EPAREN 8 | ||
| 44 | #define REG_EBRACE 9 | ||
| 45 | #define REG_BADBR 10 | ||
| 46 | #define REG_ERANGE 11 | ||
| 47 | #define REG_ESPACE 12 | ||
| 48 | #define REG_BADRPT 13 | ||
| 49 | |||
| 50 | #define REG_ENOSYS -1 | ||
| 51 | |||
| 52 | int regcomp(regex_t *__restrict, const char *__restrict, int); | ||
| 53 | int regexec(const regex_t *__restrict, const char *__restrict, size_t, regmatch_t *__restrict, int); | ||
| 54 | void regfree(regex_t *); | ||
| 55 | |||
| 56 | size_t regerror(int, const regex_t *__restrict, char *__restrict, size_t); | ||
| 57 | |||
| 58 | #ifdef __cplusplus | ||
| 59 | } | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/resolv.h created+142| ... | @@ -0,0 +1,142 @@ | ||
| 1 | #ifndef _RESOLV_H | ||
| 2 | #define _RESOLV_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <arpa/nameser.h> | ||
| 6 | #include <netinet/in.h> | ||
| 7 | |||
| 8 | #ifdef __cplusplus | ||
| 9 | extern "C" { | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #define MAXNS			3 | ||
| 13 | #define MAXDFLSRCH		3 | ||
| 14 | #define MAXDNSRCH		6 | ||
| 15 | #define LOCALDOMAINPARTS	2 | ||
| 16 | |||
| 17 | #define RES_TIMEOUT		5 | ||
| 18 | #define MAXRESOLVSORT		10 | ||
| 19 | #define RES_MAXNDOTS		15 | ||
| 20 | #define RES_MAXRETRANS		30 | ||
| 21 | #define RES_MAXRETRY		5 | ||
| 22 | #define RES_DFLRETRY		2 | ||
| 23 | #define RES_MAXTIME		65535 | ||
| 24 | |||
| 25 | /* unused; purely for broken apps */ | ||
| 26 | typedef struct __res_state { | ||
| 27 | 	int retrans; | ||
| 28 | 	int retry; | ||
| 29 | 	unsigned long options; | ||
| 30 | 	int nscount; | ||
| 31 | 	struct sockaddr_in nsaddr_list[MAXNS]; | ||
| 32 | # define nsaddr	nsaddr_list[0] | ||
| 33 | 	unsigned short id; | ||
| 34 | 	char *dnsrch[MAXDNSRCH+1]; | ||
| 35 | 	char defdname[256]; | ||
| 36 | 	unsigned long pfcode; | ||
| 37 | 	unsigned ndots:4; | ||
| 38 | 	unsigned nsort:4; | ||
| 39 | 	unsigned ipv6_unavail:1; | ||
| 40 | 	unsigned unused:23; | ||
| 41 | 	struct { | ||
| 42 | 		struct in_addr addr; | ||
| 43 | 		uint32_t mask; | ||
| 44 | 	} sort_list[MAXRESOLVSORT]; | ||
| 45 | 	void *qhook; | ||
| 46 | 	void *rhook; | ||
| 47 | 	int res_h_errno; | ||
| 48 | 	int _vcsock; | ||
| 49 | 	unsigned _flags; | ||
| 50 | 	union { | ||
| 51 | 		char pad[52]; | ||
| 52 | 		struct { | ||
| 53 | 			uint16_t		nscount; | ||
| 54 | 			uint16_t		nsmap[MAXNS]; | ||
| 55 | 			int			nssocks[MAXNS]; | ||
| 56 | 			uint16_t		nscount6; | ||
| 57 | 			uint16_t		nsinit; | ||
| 58 | 			struct sockaddr_in6	*nsaddrs[MAXNS]; | ||
| 59 | 			unsigned int		_initstamp[2]; | ||
| 60 | 		} _ext; | ||
| 61 | 	} _u; | ||
| 62 | } *res_state; | ||
| 63 | |||
| 64 | #define	__RES	19960801 | ||
| 65 | |||
| 66 | #ifndef _PATH_RESCONF | ||
| 67 | #define _PATH_RESCONF "/etc/resolv.conf" | ||
| 68 | #endif | ||
| 69 | |||
| 70 | struct res_sym { | ||
| 71 | 	int number; | ||
| 72 | 	char *name; | ||
| 73 | 	char *humanname; | ||
| 74 | }; | ||
| 75 | |||
| 76 | #define	RES_F_VC	0x00000001 | ||
| 77 | #define	RES_F_CONN	0x00000002 | ||
| 78 | #define RES_F_EDNS0ERR	0x00000004 | ||
| 79 | |||
| 80 | #define	RES_EXHAUSTIVE	0x00000001 | ||
| 81 | |||
| 82 | #define RES_INIT	0x00000001 | ||
| 83 | #define RES_DEBUG	0x00000002 | ||
| 84 | #define RES_AAONLY	0x00000004 | ||
| 85 | #define RES_USEVC	0x00000008 | ||
| 86 | #define RES_PRIMARY	0x00000010 | ||
| 87 | #define RES_IGNTC	0x00000020 | ||
| 88 | #define RES_RECURSE	0x00000040 | ||
| 89 | #define RES_DEFNAMES	0x00000080 | ||
| 90 | #define RES_STAYOPEN	0x00000100 | ||
| 91 | #define RES_DNSRCH	0x00000200 | ||
| 92 | #define	RES_INSECURE1	0x00000400 | ||
| 93 | #define	RES_INSECURE2	0x00000800 | ||
| 94 | #define	RES_NOALIASES	0x00001000 | ||
| 95 | #define	RES_USE_INET6	0x00002000 | ||
| 96 | #define RES_ROTATE	0x00004000 | ||
| 97 | #define	RES_NOCHECKNAME	0x00008000 | ||
| 98 | #define	RES_KEEPTSIG	0x00010000 | ||
| 99 | #define	RES_BLAST	0x00020000 | ||
| 100 | #define RES_USEBSTRING	0x00040000 | ||
| 101 | #define RES_NOIP6DOTINT	0x00080000 | ||
| 102 | #define RES_USE_EDNS0	0x00100000 | ||
| 103 | #define RES_SNGLKUP	0x00200000 | ||
| 104 | #define RES_SNGLKUPREOP	0x00400000 | ||
| 105 | #define RES_USE_DNSSEC	0x00800000 | ||
| 106 | |||
| 107 | #define RES_DEFAULT	(RES_RECURSE|RES_DEFNAMES|RES_DNSRCH|RES_NOIP6DOTINT) | ||
| 108 | |||
| 109 | #define RES_PRF_STATS	0x00000001 | ||
| 110 | #define RES_PRF_UPDATE	0x00000002 | ||
| 111 | #define RES_PRF_CLASS 0x00000004 | ||
| 112 | #define RES_PRF_CMD	0x00000008 | ||
| 113 | #define RES_PRF_QUES	0x00000010 | ||
| 114 | #define RES_PRF_ANS	0x00000020 | ||
| 115 | #define RES_PRF_AUTH	0x00000040 | ||
| 116 | #define RES_PRF_ADD	0x00000080 | ||
| 117 | #define RES_PRF_HEAD1	0x00000100 | ||
| 118 | #define RES_PRF_HEAD2	0x00000200 | ||
| 119 | #define RES_PRF_TTLID	0x00000400 | ||
| 120 | #define RES_PRF_HEADX	0x00000800 | ||
| 121 | #define RES_PRF_QUERY	0x00001000 | ||
| 122 | #define RES_PRF_REPLY	0x00002000 | ||
| 123 | #define RES_PRF_INIT	0x00004000 | ||
| 124 | |||
| 125 | struct __res_state *__res_state(void); | ||
| 126 | #define _res (*__res_state()) | ||
| 127 | |||
| 128 | int res_init(void); | ||
| 129 | int res_query(const char *, int, int, unsigned char *, int); | ||
| 130 | int res_querydomain(const char *, const char *, int, int, unsigned char *, int); | ||
| 131 | int res_search(const char *, int, int, unsigned char *, int); | ||
| 132 | int res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int); | ||
| 133 | int res_send(const unsigned char *, int, unsigned char *, int); | ||
| 134 | int dn_comp(const char *, unsigned char *, int, unsigned char **, unsigned char **); | ||
| 135 | int dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); | ||
| 136 | int dn_skipname(const unsigned char *, const unsigned char *); | ||
| 137 | |||
| 138 | #ifdef __cplusplus | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | |||
| 142 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sched.h created+152| ... | @@ -0,0 +1,152 @@ | ||
| 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 | #ifdef __wasilibc_unmodified_upstream /* WASI has no CPU scheduling support. */ | ||
| 20 | struct sched_param { | ||
| 21 | 	int sched_priority; | ||
| 22 | 	int __reserved1; | ||
| 23 | #if _REDIR_TIME64 | ||
| 24 | 	long __reserved2[4]; | ||
| 25 | #else | ||
| 26 | 	struct { | ||
| 27 | 		time_t __reserved1; | ||
| 28 | 		long __reserved2; | ||
| 29 | 	} __reserved2[2]; | ||
| 30 | #endif | ||
| 31 | 	int __reserved3; | ||
| 32 | }; | ||
| 33 | |||
| 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 128 | ||
| 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/scsi/scsi.h created+150| ... | @@ -0,0 +1,150 @@ | ||
| 1 | #ifndef _SCSI_SCSI_H | ||
| 2 | #define _SCSI_SCSI_H | ||
| 3 | |||
| 4 | #define TEST_UNIT_READY 0x00 | ||
| 5 | #define REZERO_UNIT 0x01 | ||
| 6 | #define REQUEST_SENSE 0x03 | ||
| 7 | #define FORMAT_UNIT 0x04 | ||
| 8 | #define READ_BLOCK_LIMITS 0x05 | ||
| 9 | #define REASSIGN_BLOCKS 0x07 | ||
| 10 | #define READ_6 0x08 | ||
| 11 | #define WRITE_6 0x0a | ||
| 12 | #define SEEK_6 0x0b | ||
| 13 | #define READ_REVERSE 0x0f | ||
| 14 | #define WRITE_FILEMARKS 0x10 | ||
| 15 | #define SPACE 0x11 | ||
| 16 | #define INQUIRY 0x12 | ||
| 17 | #define RECOVER_BUFFERED_DATA 0x14 | ||
| 18 | #define MODE_SELECT 0x15 | ||
| 19 | #define RESERVE 0x16 | ||
| 20 | #define RELEASE 0x17 | ||
| 21 | #define COPY 0x18 | ||
| 22 | #define ERASE 0x19 | ||
| 23 | #define MODE_SENSE 0x1a | ||
| 24 | #define START_STOP 0x1b | ||
| 25 | #define RECEIVE_DIAGNOSTIC 0x1c | ||
| 26 | #define SEND_DIAGNOSTIC 0x1d | ||
| 27 | #define ALLOW_MEDIUM_REMOVAL 0x1e | ||
| 28 | #define SET_WINDOW 0x24 | ||
| 29 | #define READ_CAPACITY 0x25 | ||
| 30 | #define READ_10 0x28 | ||
| 31 | #define WRITE_10 0x2a | ||
| 32 | #define SEEK_10 0x2b | ||
| 33 | #define WRITE_VERIFY 0x2e | ||
| 34 | #define VERIFY 0x2f | ||
| 35 | #define SEARCH_HIGH 0x30 | ||
| 36 | #define SEARCH_EQUAL 0x31 | ||
| 37 | #define SEARCH_LOW 0x32 | ||
| 38 | #define SET_LIMITS 0x33 | ||
| 39 | #define PRE_FETCH 0x34 | ||
| 40 | #define READ_POSITION 0x34 | ||
| 41 | #define SYNCHRONIZE_CACHE 0x35 | ||
| 42 | #define LOCK_UNLOCK_CACHE 0x36 | ||
| 43 | #define READ_DEFECT_DATA 0x37 | ||
| 44 | #define MEDIUM_SCAN 0x38 | ||
| 45 | #define COMPARE 0x39 | ||
| 46 | #define COPY_VERIFY 0x3a | ||
| 47 | #define WRITE_BUFFER 0x3b | ||
| 48 | #define READ_BUFFER 0x3c | ||
| 49 | #define UPDATE_BLOCK 0x3d | ||
| 50 | #define READ_LONG 0x3e | ||
| 51 | #define WRITE_LONG 0x3f | ||
| 52 | #define CHANGE_DEFINITION 0x40 | ||
| 53 | #define WRITE_SAME 0x41 | ||
| 54 | #define READ_TOC 0x43 | ||
| 55 | #define LOG_SELECT 0x4c | ||
| 56 | #define LOG_SENSE 0x4d | ||
| 57 | #define MODE_SELECT_10 0x55 | ||
| 58 | #define RESERVE_10 0x56 | ||
| 59 | #define RELEASE_10 0x57 | ||
| 60 | #define MODE_SENSE_10 0x5a | ||
| 61 | #define PERSISTENT_RESERVE_IN 0x5e | ||
| 62 | #define PERSISTENT_RESERVE_OUT 0x5f | ||
| 63 | #define MOVE_MEDIUM 0xa5 | ||
| 64 | #define READ_12 0xa8 | ||
| 65 | #define WRITE_12 0xaa | ||
| 66 | #define WRITE_VERIFY_12 0xae | ||
| 67 | #define SEARCH_HIGH_12 0xb0 | ||
| 68 | #define SEARCH_EQUAL_12 0xb1 | ||
| 69 | #define SEARCH_LOW_12 0xb2 | ||
| 70 | #define READ_ELEMENT_STATUS 0xb8 | ||
| 71 | #define SEND_VOLUME_TAG 0xb6 | ||
| 72 | #define WRITE_LONG_2 0xea | ||
| 73 | #define GOOD 0x00 | ||
| 74 | #define CHECK_CONDITION 0x01 | ||
| 75 | #define CONDITION_GOOD 0x02 | ||
| 76 | #define BUSY 0x04 | ||
| 77 | #define INTERMEDIATE_GOOD 0x08 | ||
| 78 | #define INTERMEDIATE_C_GOOD 0x0a | ||
| 79 | #define RESERVATION_CONFLICT 0x0c | ||
| 80 | #define COMMAND_TERMINATED 0x11 | ||
| 81 | #define QUEUE_FULL 0x14 | ||
| 82 | #define STATUS_MASK 0x3e | ||
| 83 | #define NO_SENSE 0x00 | ||
| 84 | #define RECOVERED_ERROR 0x01 | ||
| 85 | #define NOT_READY 0x02 | ||
| 86 | #define MEDIUM_ERROR 0x03 | ||
| 87 | #define HARDWARE_ERROR 0x04 | ||
| 88 | #define ILLEGAL_REQUEST 0x05 | ||
| 89 | #define UNIT_ATTENTION 0x06 | ||
| 90 | #define DATA_PROTECT 0x07 | ||
| 91 | #define BLANK_CHECK 0x08 | ||
| 92 | #define COPY_ABORTED 0x0a | ||
| 93 | #define ABORTED_COMMAND 0x0b | ||
| 94 | #define VOLUME_OVERFLOW 0x0d | ||
| 95 | #define MISCOMPARE 0x0e | ||
| 96 | #define TYPE_DISK 0x00 | ||
| 97 | #define TYPE_TAPE 0x01 | ||
| 98 | #define TYPE_PROCESSOR 0x03 | ||
| 99 | #define TYPE_WORM 0x04 | ||
| 100 | #define TYPE_ROM 0x05 | ||
| 101 | #define TYPE_SCANNER 0x06 | ||
| 102 | #define TYPE_MOD 0x07 | ||
| 103 | #define TYPE_MEDIUM_CHANGER 0x08 | ||
| 104 | #define TYPE_ENCLOSURE 0x0d | ||
| 105 | #define TYPE_NO_LUN 0x7f | ||
| 106 | #define COMMAND_COMPLETE 0x00 | ||
| 107 | #define EXTENDED_MESSAGE 0x01 | ||
| 108 | #define EXTENDED_MODIFY_DATA_POINTER 0x00 | ||
| 109 | #define EXTENDED_SDTR 0x01 | ||
| 110 | #define EXTENDED_EXTENDED_IDENTIFY 0x02 | ||
| 111 | #define EXTENDED_WDTR 0x03 | ||
| 112 | #define SAVE_POINTERS 0x02 | ||
| 113 | #define RESTORE_POINTERS 0x03 | ||
| 114 | #define DISCONNECT 0x04 | ||
| 115 | #define INITIATOR_ERROR 0x05 | ||
| 116 | #define ABORT 0x06 | ||
| 117 | #define MESSAGE_REJECT 0x07 | ||
| 118 | #define NOP 0x08 | ||
| 119 | #define MSG_PARITY_ERROR 0x09 | ||
| 120 | #define LINKED_CMD_COMPLETE 0x0a | ||
| 121 | #define LINKED_FLG_CMD_COMPLETE 0x0b | ||
| 122 | #define BUS_DEVICE_RESET 0x0c | ||
| 123 | #define INITIATE_RECOVERY 0x0f | ||
| 124 | #define RELEASE_RECOVERY 0x10 | ||
| 125 | #define SIMPLE_QUEUE_TAG 0x20 | ||
| 126 | #define HEAD_OF_QUEUE_TAG 0x21 | ||
| 127 | #define ORDERED_QUEUE_TAG 0x22 | ||
| 128 | #define SCSI_IOCTL_GET_IDLUN 0x5382 | ||
| 129 | #define SCSI_IOCTL_TAGGED_ENABLE 0x5383 | ||
| 130 | #define SCSI_IOCTL_TAGGED_DISABLE 0x5384 | ||
| 131 | #define SCSI_IOCTL_PROBE_HOST 0x5385 | ||
| 132 | #define SCSI_IOCTL_GET_BUS_NUMBER 0x5386 | ||
| 133 | |||
| 134 | struct ccs_modesel_head { | ||
| 135 | 	unsigned char _r1; | ||
| 136 | 	unsigned char medium; | ||
| 137 | 	unsigned char _r2; | ||
| 138 | 	unsigned char block_desc_length; | ||
| 139 | 	unsigned char density; | ||
| 140 | 	unsigned char number_blocks_hi; | ||
| 141 | 	unsigned char number_blocks_med; | ||
| 142 | 	unsigned char number_blocks_lo; | ||
| 143 | 	unsigned char _r3; | ||
| 144 | 	unsigned char block_length_hi; | ||
| 145 | 	unsigned char block_length_med; | ||
| 146 | 	unsigned char block_length_lo; | ||
| 147 | }; | ||
| 148 | |||
| 149 | #endif | ||
| 150 | |||
lib/libc/wasi/libc-top-half/musl/include/scsi/scsi_ioctl.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #ifndef _SCSI_IOCTL_H | ||
| 2 | #define _SCSI_IOCTL_H | ||
| 3 | #define SCSI_IOCTL_SEND_COMMAND 1 | ||
| 4 | #define SCSI_IOCTL_TEST_UNIT_READY 2 | ||
| 5 | #define SCSI_IOCTL_BENCHMARK_COMMAND 3 | ||
| 6 | #define SCSI_IOCTL_SYNC 4 | ||
| 7 | #define SCSI_IOCTL_START_UNIT 5 | ||
| 8 | #define SCSI_IOCTL_STOP_UNIT 6 | ||
| 9 | #define SCSI_IOCTL_DOORLOCK 0x5380 | ||
| 10 | #define SCSI_IOCTL_DOORUNLOCK 0x5381 | ||
| 11 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/scsi/sg.h created+129| ... | @@ -0,0 +1,129 @@ | ||
| 1 | #ifndef _SCSI_SG_H | ||
| 2 | #define _SCSI_SG_H | ||
| 3 | |||
| 4 | #define SG_DXFER_NONE -1 | ||
| 5 | #define SG_DXFER_TO_DEV -2 | ||
| 6 | #define SG_DXFER_FROM_DEV -3 | ||
| 7 | #define SG_DXFER_TO_FROM_DEV -4 | ||
| 8 | #define SG_FLAG_DIRECT_IO 1 | ||
| 9 | #define SG_FLAG_LUN_INHIBIT 2 | ||
| 10 | #define SG_FLAG_NO_DXFER 0x10000 | ||
| 11 | #define SG_INFO_OK_MASK 0x1 | ||
| 12 | #define SG_INFO_OK 0x0 | ||
| 13 | #define SG_INFO_CHECK 0x1 | ||
| 14 | #define SG_INFO_DIRECT_IO_MASK 0x6 | ||
| 15 | #define SG_INFO_INDIRECT_IO 0x0 | ||
| 16 | #define SG_INFO_DIRECT_IO 0x2 | ||
| 17 | #define SG_INFO_MIXED_IO 0x4 | ||
| 18 | #define SG_EMULATED_HOST 0x2203 | ||
| 19 | #define SG_SET_TRANSFORM 0x2204 | ||
| 20 | #define SG_GET_TRANSFORM 0x2205 | ||
| 21 | #define SG_SET_RESERVED_SIZE 0x2275 | ||
| 22 | #define SG_GET_RESERVED_SIZE 0x2272 | ||
| 23 | #define SG_GET_SCSI_ID 0x2276 | ||
| 24 | #define SG_SET_FORCE_LOW_DMA 0x2279 | ||
| 25 | #define SG_GET_LOW_DMA 0x227a | ||
| 26 | #define SG_SET_FORCE_PACK_ID 0x227b | ||
| 27 | #define SG_GET_PACK_ID 0x227c | ||
| 28 | #define SG_GET_NUM_WAITING 0x227d | ||
| 29 | #define SG_GET_SG_TABLESIZE 0x227F | ||
| 30 | #define SG_GET_VERSION_NUM 0x2282 | ||
| 31 | #define SG_SCSI_RESET 0x2284 | ||
| 32 | #define SG_SCSI_RESET_NOTHING 0 | ||
| 33 | #define SG_SCSI_RESET_DEVICE 1 | ||
| 34 | #define SG_SCSI_RESET_BUS 2 | ||
| 35 | #define SG_SCSI_RESET_HOST 3 | ||
| 36 | #define SG_IO 0x2285 | ||
| 37 | #define SG_GET_REQUEST_TABLE 0x2286 | ||
| 38 | #define SG_SET_KEEP_ORPHAN 0x2287 | ||
| 39 | #define SG_GET_KEEP_ORPHAN 0x2288 | ||
| 40 | #define SG_SCATTER_SZ (8 * 4096) | ||
| 41 | #define SG_DEFAULT_RETRIES 1 | ||
| 42 | #define SG_DEF_FORCE_LOW_DMA 0 | ||
| 43 | #define SG_DEF_FORCE_PACK_ID 0 | ||
| 44 | #define SG_DEF_KEEP_ORPHAN 0 | ||
| 45 | #define SG_DEF_RESERVED_SIZE SG_SCATTER_SZ | ||
| 46 | #define SG_MAX_QUEUE 16 | ||
| 47 | #define SG_BIG_BUFF SG_DEF_RESERVED_SIZE | ||
| 48 | #define SG_MAX_SENSE 16 | ||
| 49 | #define SG_SET_TIMEOUT 0x2201 | ||
| 50 | #define SG_GET_TIMEOUT 0x2202 | ||
| 51 | #define SG_GET_COMMAND_Q 0x2270 | ||
| 52 | #define SG_SET_COMMAND_Q 0x2271 | ||
| 53 | #define SG_SET_DEBUG 0x227e | ||
| 54 | #define SG_NEXT_CMD_LEN 0x2283 | ||
| 55 | #define SG_DEFAULT_TIMEOUT (60*100) /* 60*HZ */ | ||
| 56 | #define SG_DEF_COMMAND_Q 0 | ||
| 57 | #define SG_DEF_UNDERRUN_FLAG 0 | ||
| 58 | |||
| 59 | typedef struct sg_iovec { | ||
| 60 | 	void *iov_base; | ||
| 61 | 	unsigned long iov_len; | ||
| 62 | } sg_iovec_t; | ||
| 63 | |||
| 64 | typedef struct sg_io_hdr { | ||
| 65 | 	int interface_id; | ||
| 66 | 	int dxfer_direction; | ||
| 67 | 	unsigned char cmd_len; | ||
| 68 | 	unsigned char mx_sb_len; | ||
| 69 | 	unsigned short iovec_count; | ||
| 70 | 	unsigned dxfer_len; | ||
| 71 | 	void *dxferp; | ||
| 72 | 	unsigned char *cmdp; | ||
| 73 | 	unsigned char *sbp; | ||
| 74 | 	unsigned timeout; | ||
| 75 | 	unsigned flags; | ||
| 76 | 	int pack_id; | ||
| 77 | 	void *usr_ptr; | ||
| 78 | 	unsigned char status; | ||
| 79 | 	unsigned char masked_status; | ||
| 80 | 	unsigned char msg_status; | ||
| 81 | 	unsigned char sb_len_wr; | ||
| 82 | 	unsigned short host_status; | ||
| 83 | 	unsigned short driver_status; | ||
| 84 | 	int resid; | ||
| 85 | 	unsigned int duration; | ||
| 86 | 	unsigned int info; | ||
| 87 | } sg_io_hdr_t; | ||
| 88 | |||
| 89 | struct sg_scsi_id { | ||
| 90 | 	int host_no; | ||
| 91 | 	int channel; | ||
| 92 | 	int scsi_id; | ||
| 93 | 	int lun; | ||
| 94 | 	int scsi_type; | ||
| 95 | 	short h_cmd_per_lun; | ||
| 96 | 	short d_queue_depth; | ||
| 97 | 	int unused[2]; | ||
| 98 | }; | ||
| 99 | |||
| 100 | typedef struct sg_req_info { | ||
| 101 | 	char req_state; | ||
| 102 | 	char orphan; | ||
| 103 | 	char sg_io_owned; | ||
| 104 | 	char problem; | ||
| 105 | 	int pack_id; | ||
| 106 | 	void *usr_ptr; | ||
| 107 | 	unsigned duration; | ||
| 108 | 	int unused; | ||
| 109 | } sg_req_info_t; | ||
| 110 | |||
| 111 | typedef struct sg_io_hdr Sg_io_hdr; | ||
| 112 | typedef struct sg_io_vec Sg_io_vec; | ||
| 113 | typedef struct sg_scsi_id Sg_scsi_id; | ||
| 114 | typedef struct sg_req_info Sg_req_info; | ||
| 115 | |||
| 116 | struct sg_header { | ||
| 117 | 	int pack_len; | ||
| 118 | 	int reply_len; | ||
| 119 | 	int pack_id; | ||
| 120 | 	int result; | ||
| 121 | 	unsigned twelve_byte:1; | ||
| 122 | 	unsigned target_status:5; | ||
| 123 | 	unsigned host_status:8; | ||
| 124 | 	unsigned driver_status:8; | ||
| 125 | 	unsigned other_flags:10; | ||
| 126 | 	unsigned char sense_buffer[SG_MAX_SENSE]; | ||
| 127 | }; | ||
| 128 | |||
| 129 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/search.h created+63| ... | @@ -0,0 +1,63 @@ | ||
| 1 | #ifndef _SEARCH_H | ||
| 2 | #define _SEARCH_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_size_t | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | typedef enum { FIND, ENTER } ACTION; | ||
| 14 | typedef enum { preorder, postorder, endorder, leaf } VISIT; | ||
| 15 | |||
| 16 | typedef struct entry { | ||
| 17 | 	char *key; | ||
| 18 | 	void *data; | ||
| 19 | } ENTRY; | ||
| 20 | |||
| 21 | int hcreate(size_t); | ||
| 22 | void hdestroy(void); | ||
| 23 | ENTRY *hsearch(ENTRY, ACTION); | ||
| 24 | |||
| 25 | #ifdef _GNU_SOURCE | ||
| 26 | struct hsearch_data { | ||
| 27 | 	struct __tab *__tab; | ||
| 28 | 	unsigned int __unused1; | ||
| 29 | 	unsigned int __unused2; | ||
| 30 | }; | ||
| 31 | |||
| 32 | int hcreate_r(size_t, struct hsearch_data *); | ||
| 33 | void hdestroy_r(struct hsearch_data *); | ||
| 34 | int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); | ||
| 35 | #endif | ||
| 36 | |||
| 37 | void insque(void *, void *); | ||
| 38 | void remque(void *); | ||
| 39 | |||
| 40 | void *lsearch(const void *, void *, size_t *, size_t, | ||
| 41 | 	int (*)(const void *, const void *)); | ||
| 42 | void *lfind(const void *, const void *, size_t *, size_t, | ||
| 43 | 	int (*)(const void *, const void *)); | ||
| 44 | |||
| 45 | void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *)); | ||
| 46 | void *tfind(const void *, void *const *, int(*)(const void *, const void *)); | ||
| 47 | void *tsearch(const void *, void **, int (*)(const void *, const void *)); | ||
| 48 | void twalk(const void *, void (*)(const void *, VISIT, int)); | ||
| 49 | |||
| 50 | #ifdef _GNU_SOURCE | ||
| 51 | struct qelem { | ||
| 52 | 	struct qelem *q_forw, *q_back; | ||
| 53 | 	char q_data[1]; | ||
| 54 | }; | ||
| 55 | |||
| 56 | void tdestroy(void *, void (*)(void *)); | ||
| 57 | #endif | ||
| 58 | |||
| 59 | #ifdef __cplusplus | ||
| 60 | } | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/semaphore.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef _SEMAPHORE_H | ||
| 2 | #define _SEMAPHORE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_time_t | ||
| 10 | #define __NEED_struct_timespec | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | #include <fcntl.h> | ||
| 14 | |||
| 15 | #define SEM_FAILED ((sem_t *)0) | ||
| 16 | |||
| 17 | typedef struct { | ||
| 18 | 	volatile int __val[4*sizeof(long)/sizeof(int)]; | ||
| 19 | } sem_t; | ||
| 20 | |||
| 21 | int sem_close(sem_t *); | ||
| 22 | int sem_destroy(sem_t *); | ||
| 23 | int sem_getvalue(sem_t *__restrict, int *__restrict); | ||
| 24 | int sem_init(sem_t *, int, unsigned); | ||
| 25 | sem_t *sem_open(const char *, int, ...); | ||
| 26 | int sem_post(sem_t *); | ||
| 27 | int sem_timedwait(sem_t *__restrict, const struct timespec *__restrict); | ||
| 28 | int sem_trywait(sem_t *); | ||
| 29 | int sem_unlink(const char *); | ||
| 30 | int sem_wait(sem_t *); | ||
| 31 | |||
| 32 | #if _REDIR_TIME64 | ||
| 33 | __REDIR(sem_timedwait, __sem_timedwait_time64); | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #ifdef __cplusplus | ||
| 37 | } | ||
| 38 | #endif | ||
| 39 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/setjmp.h created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | #ifndef	_SETJMP_H | ||
| 2 | #define	_SETJMP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setjmp */ | ||
| 11 | #include <bits/setjmp.h> | ||
| 12 | |||
| 13 | typedef struct __jmp_buf_tag { | ||
| 14 | 	__jmp_buf __jb; | ||
| 15 | 	unsigned long __fl; | ||
| 16 | 	unsigned long __ss[128/sizeof(long)]; | ||
| 17 | } jmp_buf[1]; | ||
| 18 | |||
| 19 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 20 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 21 | || defined(_BSD_SOURCE) | ||
| 22 | typedef jmp_buf sigjmp_buf; | ||
| 23 | int sigsetjmp (sigjmp_buf, int); | ||
| 24 | _Noreturn void siglongjmp (sigjmp_buf, int); | ||
| 25 | #endif | ||
| 26 | |||
| 27 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 28 | || defined(_BSD_SOURCE) | ||
| 29 | int _setjmp (jmp_buf); | ||
| 30 | _Noreturn void _longjmp (jmp_buf, int); | ||
| 31 | #endif | ||
| 32 | |||
| 33 | int setjmp (jmp_buf); | ||
| 34 | _Noreturn void longjmp (jmp_buf, int); | ||
| 35 | |||
| 36 | #define setjmp setjmp | ||
| 37 | #else | ||
| 38 | #warning setjmp is not yet implemented for WASI | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #ifdef __cplusplus | ||
| 42 | } | ||
| 43 | #endif | ||
| 44 | |||
| 45 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/shadow.h created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | #ifndef _SHADOW_H | ||
| 2 | #define _SHADOW_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define	__NEED_FILE | ||
| 9 | #define __NEED_size_t | ||
| 10 | |||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | #define	SHADOW "/etc/shadow" | ||
| 14 | |||
| 15 | struct spwd { | ||
| 16 | 	char *sp_namp; | ||
| 17 | 	char *sp_pwdp; | ||
| 18 | 	long sp_lstchg; | ||
| 19 | 	long sp_min; | ||
| 20 | 	long sp_max; | ||
| 21 | 	long sp_warn; | ||
| 22 | 	long sp_inact; | ||
| 23 | 	long sp_expire; | ||
| 24 | 	unsigned long sp_flag; | ||
| 25 | }; | ||
| 26 | |||
| 27 | void setspent(void); | ||
| 28 | void endspent(void); | ||
| 29 | struct spwd *getspent(void); | ||
| 30 | struct spwd *fgetspent(FILE *); | ||
| 31 | struct spwd *sgetspent(const char *); | ||
| 32 | int putspent(const struct spwd *, FILE *); | ||
| 33 | |||
| 34 | struct spwd *getspnam(const char *); | ||
| 35 | int getspnam_r(const char *, struct spwd *, char *, size_t, struct spwd **); | ||
| 36 | |||
| 37 | int lckpwdf(void); | ||
| 38 | int ulckpwdf(void); | ||
| 39 | |||
| 40 | #ifdef __cplusplus | ||
| 41 | } | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/signal.h created+331| ... | @@ -0,0 +1,331 @@ | ||
| 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 | |||
| 86 | #define BUS_ADRALN 1 | ||
| 87 | #define BUS_ADRERR 2 | ||
| 88 | #define BUS_OBJERR 3 | ||
| 89 | #define BUS_MCEERR_AR 4 | ||
| 90 | #define BUS_MCEERR_AO 5 | ||
| 91 | |||
| 92 | #define CLD_EXITED 1 | ||
| 93 | #define CLD_KILLED 2 | ||
| 94 | #define CLD_DUMPED 3 | ||
| 95 | #define CLD_TRAPPED 4 | ||
| 96 | #define CLD_STOPPED 5 | ||
| 97 | #define CLD_CONTINUED 6 | ||
| 98 | |||
| 99 | union sigval { | ||
| 100 | 	int sival_int; | ||
| 101 | 	void *sival_ptr; | ||
| 102 | }; | ||
| 103 | |||
| 104 | typedef struct { | ||
| 105 | #ifdef __SI_SWAP_ERRNO_CODE | ||
| 106 | 	int si_signo, si_code, si_errno; | ||
| 107 | #else | ||
| 108 | 	int si_signo, si_errno, si_code; | ||
| 109 | #endif | ||
| 110 | 	union { | ||
| 111 | 		char __pad[128 - 2*sizeof(int) - sizeof(long)]; | ||
| 112 | 		struct { | ||
| 113 | 			union { | ||
| 114 | 				struct { | ||
| 115 | 					pid_t si_pid; | ||
| 116 | 					uid_t si_uid; | ||
| 117 | 				} __piduid; | ||
| 118 | 				struct { | ||
| 119 | 					int si_timerid; | ||
| 120 | 					int si_overrun; | ||
| 121 | 				} __timer; | ||
| 122 | 			} __first; | ||
| 123 | 			union { | ||
| 124 | 				union sigval si_value; | ||
| 125 | 				struct { | ||
| 126 | 					int si_status; | ||
| 127 | 					clock_t si_utime, si_stime; | ||
| 128 | 				} __sigchld; | ||
| 129 | 			} __second; | ||
| 130 | 		} __si_common; | ||
| 131 | 		struct { | ||
| 132 | 			void *si_addr; | ||
| 133 | 			short si_addr_lsb; | ||
| 134 | 			union { | ||
| 135 | 				struct { | ||
| 136 | 					void *si_lower; | ||
| 137 | 					void *si_upper; | ||
| 138 | 				} __addr_bnd; | ||
| 139 | 				unsigned si_pkey; | ||
| 140 | 			} __first; | ||
| 141 | 		} __sigfault; | ||
| 142 | 		struct { | ||
| 143 | 			long si_band; | ||
| 144 | 			int si_fd; | ||
| 145 | 		} __sigpoll; | ||
| 146 | 		struct { | ||
| 147 | 			void *si_call_addr; | ||
| 148 | 			int si_syscall; | ||
| 149 | 			unsigned si_arch; | ||
| 150 | 		} __sigsys; | ||
| 151 | 	} __si_fields; | ||
| 152 | } siginfo_t; | ||
| 153 | #define si_pid __si_fields.__si_common.__first.__piduid.si_pid | ||
| 154 | #define si_uid __si_fields.__si_common.__first.__piduid.si_uid | ||
| 155 | #define si_status __si_fields.__si_common.__second.__sigchld.si_status | ||
| 156 | #define si_utime __si_fields.__si_common.__second.__sigchld.si_utime | ||
| 157 | #define si_stime __si_fields.__si_common.__second.__sigchld.si_stime | ||
| 158 | #define si_value __si_fields.__si_common.__second.si_value | ||
| 159 | #define si_addr __si_fields.__sigfault.si_addr | ||
| 160 | #define si_addr_lsb __si_fields.__sigfault.si_addr_lsb | ||
| 161 | #define si_lower __si_fields.__sigfault.__first.__addr_bnd.si_lower | ||
| 162 | #define si_upper __si_fields.__sigfault.__first.__addr_bnd.si_upper | ||
| 163 | #define si_pkey __si_fields.__sigfault.__first.si_pkey | ||
| 164 | #define si_band __si_fields.__sigpoll.si_band | ||
| 165 | #define si_fd __si_fields.__sigpoll.si_fd | ||
| 166 | #define si_timerid __si_fields.__si_common.__first.__timer.si_timerid | ||
| 167 | #define si_overrun __si_fields.__si_common.__first.__timer.si_overrun | ||
| 168 | #define si_ptr si_value.sival_ptr | ||
| 169 | #define si_int si_value.sival_int | ||
| 170 | #define si_call_addr __si_fields.__sigsys.si_call_addr | ||
| 171 | #define si_syscall __si_fields.__sigsys.si_syscall | ||
| 172 | #define si_arch __si_fields.__sigsys.si_arch | ||
| 173 | |||
| 174 | struct sigaction { | ||
| 175 | 	union { | ||
| 176 | 		void (*sa_handler)(int); | ||
| 177 | 		void (*sa_sigaction)(int, siginfo_t *, void *); | ||
| 178 | 	} __sa_handler; | ||
| 179 | 	sigset_t sa_mask; | ||
| 180 | 	int sa_flags; | ||
| 181 | 	void (*sa_restorer)(void); | ||
| 182 | }; | ||
| 183 | #define sa_handler __sa_handler.sa_handler | ||
| 184 | #define sa_sigaction __sa_handler.sa_sigaction | ||
| 185 | |||
| 186 | struct sigevent { | ||
| 187 | 	union sigval sigev_value; | ||
| 188 | 	int sigev_signo; | ||
| 189 | 	int sigev_notify; | ||
| 190 | 	union { | ||
| 191 | 		char __pad[64 - 2*sizeof(int) - sizeof(union sigval)]; | ||
| 192 | 		pid_t sigev_notify_thread_id; | ||
| 193 | 		struct { | ||
| 194 | 			void (*sigev_notify_function)(union sigval); | ||
| 195 | 			pthread_attr_t *sigev_notify_attributes; | ||
| 196 | 		} __sev_thread; | ||
| 197 | 	} __sev_fields; | ||
| 198 | }; | ||
| 199 | |||
| 200 | #define sigev_notify_thread_id __sev_fields.sigev_notify_thread_id | ||
| 201 | #define sigev_notify_function __sev_fields.__sev_thread.sigev_notify_function | ||
| 202 | #define sigev_notify_attributes __sev_fields.__sev_thread.sigev_notify_attributes | ||
| 203 | |||
| 204 | #define SIGEV_SIGNAL 0 | ||
| 205 | #define SIGEV_NONE 1 | ||
| 206 | #define SIGEV_THREAD 2 | ||
| 207 | #define SIGEV_THREAD_ID 4 | ||
| 208 | #endif | ||
| 209 | |||
| 210 | #ifdef __wasilibc_unmodified_upstream /* WASI has no realtime signals */ | ||
| 211 | int __libc_current_sigrtmin(void); | ||
| 212 | int __libc_current_sigrtmax(void); | ||
| 213 | |||
| 214 | #define SIGRTMIN (__libc_current_sigrtmin()) | ||
| 215 | #define SIGRTMAX (__libc_current_sigrtmax()) | ||
| 216 | #endif | ||
| 217 | |||
| 218 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 219 | int kill(pid_t, int); | ||
| 220 | |||
| 221 | int sigemptyset(sigset_t *); | ||
| 222 | int sigfillset(sigset_t *); | ||
| 223 | int sigaddset(sigset_t *, int); | ||
| 224 | int sigdelset(sigset_t *, int); | ||
| 225 | int sigismember(const sigset_t *, int); | ||
| 226 | |||
| 227 | int sigprocmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 228 | int sigsuspend(const sigset_t *); | ||
| 229 | int sigaction(int, const struct sigaction *__restrict, struct sigaction *__restrict); | ||
| 230 | int sigpending(sigset_t *); | ||
| 231 | int sigwait(const sigset_t *__restrict, int *__restrict); | ||
| 232 | int sigwaitinfo(const sigset_t *__restrict, siginfo_t *__restrict); | ||
| 233 | int sigtimedwait(const sigset_t *__restrict, siginfo_t *__restrict, const struct timespec *__restrict); | ||
| 234 | int sigqueue(pid_t, int, union sigval); | ||
| 235 | #endif | ||
| 236 | |||
| 237 | #ifdef __wasilibc_unmodified_upstream /* WASI has no threads yet */ | ||
| 238 | int pthread_sigmask(int, const sigset_t *__restrict, sigset_t *__restrict); | ||
| 239 | int pthread_kill(pthread_t, int); | ||
| 240 | #endif | ||
| 241 | |||
| 242 | #ifdef __wasilibc_unmodified_upstream /* WASI has no siginfo */ | ||
| 243 | void psiginfo(const siginfo_t *, const char *); | ||
| 244 | #endif | ||
| 245 | void psignal(int, const char *); | ||
| 246 | |||
| 247 | #endif | ||
| 248 | |||
| 249 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 250 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 251 | int killpg(pid_t, int); | ||
| 252 | int sigaltstack(const stack_t *__restrict, stack_t *__restrict); | ||
| 253 | int sighold(int); | ||
| 254 | int sigignore(int); | ||
| 255 | int siginterrupt(int, int); | ||
| 256 | int sigpause(int); | ||
| 257 | int sigrelse(int); | ||
| 258 | void (*sigset(int, void (*)(int)))(int); | ||
| 259 | #define TRAP_BRKPT 1 | ||
| 260 | #define TRAP_TRACE 2 | ||
| 261 | #define TRAP_BRANCH 3 | ||
| 262 | #define TRAP_HWBKPT 4 | ||
| 263 | #define TRAP_UNK 5 | ||
| 264 | #define POLL_IN 1 | ||
| 265 | #define POLL_OUT 2 | ||
| 266 | #define POLL_MSG 3 | ||
| 267 | #define POLL_ERR 4 | ||
| 268 | #define POLL_PRI 5 | ||
| 269 | #define POLL_HUP 6 | ||
| 270 | #define SS_ONSTACK 1 | ||
| 271 | #define SS_DISABLE 2 | ||
| 272 | #define SS_AUTODISARM (1U << 31) | ||
| 273 | #define SS_FLAG_BITS SS_AUTODISARM | ||
| 274 | #endif | ||
| 275 | #endif | ||
| 276 | |||
| 277 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 278 | #define NSIG _NSIG | ||
| 279 | typedef void (*sig_t)(int); | ||
| 280 | #endif | ||
| 281 | |||
| 282 | #ifdef _GNU_SOURCE | ||
| 283 | typedef void (*sighandler_t)(int); | ||
| 284 | void (*bsd_signal(int, void (*)(int)))(int); | ||
| 285 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signal sets */ | ||
| 286 | int sigisemptyset(const sigset_t *); | ||
| 287 | int sigorset (sigset_t *, const sigset_t *, const sigset_t *); | ||
| 288 | int sigandset(sigset_t *, const sigset_t *, const sigset_t *); | ||
| 289 | |||
| 290 | #define SA_NOMASK SA_NODEFER | ||
| 291 | #define SA_ONESHOT SA_RESETHAND | ||
| 292 | #endif | ||
| 293 | #endif | ||
| 294 | |||
| 295 | #ifdef __wasilibc_unmodified_upstream /* 1 is a valid function pointer on wasm */ | ||
| 296 | #define SIG_ERR ((void (*)(int))-1) | ||
| 297 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 298 | #define SIG_IGN ((void (*)(int)) 1) | ||
| 299 | #else | ||
| 300 | void __SIG_ERR(int); | ||
| 301 | void __SIG_IGN(int); | ||
| 302 | #define SIG_ERR (__SIG_ERR) | ||
| 303 | #define SIG_DFL ((void (*)(int)) 0) | ||
| 304 | #define SIG_IGN (__SIG_IGN) | ||
| 305 | #endif | ||
| 306 | |||
| 307 | #ifdef __wasilibc_unmodified_upstream /* Make sig_atomic_t 64-bit on wasm64 */ | ||
| 308 | typedef int sig_atomic_t; | ||
| 309 | #else | ||
| 310 | typedef long sig_atomic_t; | ||
| 311 | #endif | ||
| 312 | |||
| 313 | void (*signal(int, void (*)(int)))(int); | ||
| 314 | int raise(int); | ||
| 315 | |||
| 316 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sigtimedwait */ | ||
| 317 | #if _REDIR_TIME64 | ||
| 318 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 319 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 320 | || defined(_BSD_SOURCE) | ||
| 321 | __REDIR(sigtimedwait, __sigtimedwait_time64); | ||
| 322 | #endif | ||
| 323 | #endif | ||
| 324 | #endif | ||
| 325 | |||
| 326 | #ifdef __cplusplus | ||
| 327 | } | ||
| 328 | #endif | ||
| 329 | |||
| 330 | #endif | ||
| 331 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/spawn.h created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | #ifndef _SPAWN_H | ||
| 2 | #define _SPAWN_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_mode_t | ||
| 11 | #define __NEED_pid_t | ||
| 12 | #define __NEED_sigset_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | struct sched_param; | ||
| 17 | |||
| 18 | #define POSIX_SPAWN_RESETIDS 1 | ||
| 19 | #define POSIX_SPAWN_SETPGROUP 2 | ||
| 20 | #define POSIX_SPAWN_SETSIGDEF 4 | ||
| 21 | #define POSIX_SPAWN_SETSIGMASK 8 | ||
| 22 | #define POSIX_SPAWN_SETSCHEDPARAM 16 | ||
| 23 | #define POSIX_SPAWN_SETSCHEDULER 32 | ||
| 24 | #define POSIX_SPAWN_USEVFORK 64 | ||
| 25 | #define POSIX_SPAWN_SETSID 128 | ||
| 26 | |||
| 27 | typedef struct { | ||
| 28 | 	int __flags; | ||
| 29 | 	pid_t __pgrp; | ||
| 30 | 	sigset_t __def, __mask; | ||
| 31 | 	int __prio, __pol; | ||
| 32 | 	void *__fn; | ||
| 33 | 	char __pad[64-sizeof(void *)]; | ||
| 34 | } posix_spawnattr_t; | ||
| 35 | |||
| 36 | typedef struct { | ||
| 37 | 	int __pad0[2]; | ||
| 38 | 	void *__actions; | ||
| 39 | 	int __pad[16]; | ||
| 40 | } posix_spawn_file_actions_t; | ||
| 41 | |||
| 42 | int posix_spawn(pid_t *__restrict, const char *__restrict, const posix_spawn_file_actions_t *, | ||
| 43 | 	const posix_spawnattr_t *__restrict, char *const *__restrict, char *const *__restrict); | ||
| 44 | int posix_spawnp(pid_t *__restrict, const char *__restrict, const posix_spawn_file_actions_t *, | ||
| 45 | 	const posix_spawnattr_t *__restrict, char *const *__restrict, char *const *__restrict); | ||
| 46 | |||
| 47 | int posix_spawnattr_init(posix_spawnattr_t *); | ||
| 48 | int posix_spawnattr_destroy(posix_spawnattr_t *); | ||
| 49 | |||
| 50 | int posix_spawnattr_setflags(posix_spawnattr_t *, short); | ||
| 51 | int posix_spawnattr_getflags(const posix_spawnattr_t *__restrict, short *__restrict); | ||
| 52 | |||
| 53 | int posix_spawnattr_setpgroup(posix_spawnattr_t *, pid_t); | ||
| 54 | int posix_spawnattr_getpgroup(const posix_spawnattr_t *__restrict, pid_t *__restrict); | ||
| 55 | |||
| 56 | int posix_spawnattr_setsigmask(posix_spawnattr_t *__restrict, const sigset_t *__restrict); | ||
| 57 | int posix_spawnattr_getsigmask(const posix_spawnattr_t *__restrict, sigset_t *__restrict); | ||
| 58 | |||
| 59 | int posix_spawnattr_setsigdefault(posix_spawnattr_t *__restrict, const sigset_t *__restrict); | ||
| 60 | int posix_spawnattr_getsigdefault(const posix_spawnattr_t *__restrict, sigset_t *__restrict); | ||
| 61 | |||
| 62 | int posix_spawnattr_setschedparam(posix_spawnattr_t *__restrict, const struct sched_param *__restrict); | ||
| 63 | int posix_spawnattr_getschedparam(const posix_spawnattr_t *__restrict, struct sched_param *__restrict); | ||
| 64 | int posix_spawnattr_setschedpolicy(posix_spawnattr_t *, int); | ||
| 65 | int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *__restrict, int *__restrict); | ||
| 66 | |||
| 67 | int posix_spawn_file_actions_init(posix_spawn_file_actions_t *); | ||
| 68 | int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *); | ||
| 69 | |||
| 70 | int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *__restrict, int, const char *__restrict, int, mode_t); | ||
| 71 | int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *, int); | ||
| 72 | int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *, int, int); | ||
| 73 | |||
| 74 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 75 | int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *__restrict, const char *__restrict); | ||
| 76 | int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *, int); | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #ifdef __cplusplus | ||
| 80 | } | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdalign.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _STDALIGN_H | ||
| 2 | #define _STDALIGN_H | ||
| 3 | |||
| 4 | #ifndef __cplusplus | ||
| 5 | |||
| 6 | /* this whole header only works in C11 or with compiler extensions */ | ||
| 7 | #if __STDC_VERSION__ < 201112L && defined( __GNUC__) | ||
| 8 | #define _Alignas(t) __attribute__((__aligned__(t))) | ||
| 9 | #define _Alignof(t) __alignof__(t) | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #define alignas _Alignas | ||
| 13 | #define alignof _Alignof | ||
| 14 | |||
| 15 | #endif | ||
| 16 | |||
| 17 | #define __alignas_is_defined 1 | ||
| 18 | #define __alignof_is_defined 1 | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdarg.h created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #ifndef _STDARG_H | ||
| 2 | #define _STDARG_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_va_list | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #define va_start(v,l) __builtin_va_start(v,l) | ||
| 13 | #define va_end(v) __builtin_va_end(v) | ||
| 14 | #define va_arg(v,l) __builtin_va_arg(v,l) | ||
| 15 | #define va_copy(d,s) __builtin_va_copy(d,s) | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | } | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdbool.h created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #ifndef _STDBOOL_H | ||
| 2 | #define _STDBOOL_H | ||
| 3 | |||
| 4 | #ifndef __cplusplus | ||
| 5 | |||
| 6 | #define true 1 | ||
| 7 | #define false 0 | ||
| 8 | #define bool _Bool | ||
| 9 | |||
| 10 | #endif | ||
| 11 | |||
| 12 | #define __bool_true_false_are_defined 1 | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdc-predef.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #ifndef _STDC_PREDEF_H | ||
| 2 | #define _STDC_PREDEF_H | ||
| 3 | |||
| 4 | #define __STDC_ISO_10646__ 201206L | ||
| 5 | |||
| 6 | #if !defined(__GCC_IEC_559) || __GCC_IEC_559 > 0 | ||
| 7 | #define __STDC_IEC_559__ 1 | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stddef.h created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #ifndef _STDDEF_H | ||
| 2 | #define _STDDEF_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | #define NULL 0L | ||
| 6 | #else | ||
| 7 | #define NULL ((void*)0) | ||
| 8 | #endif | ||
| 9 | |||
| 10 | #define __NEED_ptrdiff_t | ||
| 11 | #define __NEED_size_t | ||
| 12 | #define __NEED_wchar_t | ||
| 13 | #if __STDC_VERSION__ >= 201112L || __cplusplus >= 201103L | ||
| 14 | #define __NEED_max_align_t | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #include <bits/alltypes.h> | ||
| 18 | |||
| 19 | #if __GNUC__ > 3 | ||
| 20 | #define offsetof(type, member) __builtin_offsetof(type, member) | ||
| 21 | #else | ||
| 22 | #define offsetof(type, member) ((size_t)( (char *)&(((type *)0)->member) - (char *)0 )) | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdint.h created+117| ... | @@ -0,0 +1,117 @@ | ||
| 1 | #ifndef _STDINT_H | ||
| 2 | #define _STDINT_H | ||
| 3 | |||
| 4 | #define __NEED_int8_t | ||
| 5 | #define __NEED_int16_t | ||
| 6 | #define __NEED_int32_t | ||
| 7 | #define __NEED_int64_t | ||
| 8 | |||
| 9 | #define __NEED_uint8_t | ||
| 10 | #define __NEED_uint16_t | ||
| 11 | #define __NEED_uint32_t | ||
| 12 | #define __NEED_uint64_t | ||
| 13 | |||
| 14 | #define __NEED_intptr_t | ||
| 15 | #define __NEED_uintptr_t | ||
| 16 | |||
| 17 | #define __NEED_intmax_t | ||
| 18 | #define __NEED_uintmax_t | ||
| 19 | |||
| 20 | #include <bits/alltypes.h> | ||
| 21 | |||
| 22 | typedef int8_t int_fast8_t; | ||
| 23 | typedef int64_t int_fast64_t; | ||
| 24 | |||
| 25 | typedef int8_t int_least8_t; | ||
| 26 | typedef int16_t int_least16_t; | ||
| 27 | typedef int32_t int_least32_t; | ||
| 28 | typedef int64_t int_least64_t; | ||
| 29 | |||
| 30 | typedef uint8_t uint_fast8_t; | ||
| 31 | typedef uint64_t uint_fast64_t; | ||
| 32 | |||
| 33 | typedef uint8_t uint_least8_t; | ||
| 34 | typedef uint16_t uint_least16_t; | ||
| 35 | typedef uint32_t uint_least32_t; | ||
| 36 | typedef uint64_t uint_least64_t; | ||
| 37 | |||
| 38 | #define INT8_MIN (-1-0x7f) | ||
| 39 | #define INT16_MIN (-1-0x7fff) | ||
| 40 | #define INT32_MIN (-1-0x7fffffff) | ||
| 41 | #define INT64_MIN (-1-0x7fffffffffffffff) | ||
| 42 | |||
| 43 | #define INT8_MAX (0x7f) | ||
| 44 | #define INT16_MAX (0x7fff) | ||
| 45 | #define INT32_MAX (0x7fffffff) | ||
| 46 | #define INT64_MAX (0x7fffffffffffffff) | ||
| 47 | |||
| 48 | #define UINT8_MAX (0xff) | ||
| 49 | #define UINT16_MAX (0xffff) | ||
| 50 | #define UINT32_MAX (0xffffffffu) | ||
| 51 | #define UINT64_MAX (0xffffffffffffffffu) | ||
| 52 | |||
| 53 | #define INT_FAST8_MIN INT8_MIN | ||
| 54 | #define INT_FAST64_MIN INT64_MIN | ||
| 55 | |||
| 56 | #define INT_LEAST8_MIN INT8_MIN | ||
| 57 | #define INT_LEAST16_MIN INT16_MIN | ||
| 58 | #define INT_LEAST32_MIN INT32_MIN | ||
| 59 | #define INT_LEAST64_MIN INT64_MIN | ||
| 60 | |||
| 61 | #define INT_FAST8_MAX INT8_MAX | ||
| 62 | #define INT_FAST64_MAX INT64_MAX | ||
| 63 | |||
| 64 | #define INT_LEAST8_MAX INT8_MAX | ||
| 65 | #define INT_LEAST16_MAX INT16_MAX | ||
| 66 | #define INT_LEAST32_MAX INT32_MAX | ||
| 67 | #define INT_LEAST64_MAX INT64_MAX | ||
| 68 | |||
| 69 | #define UINT_FAST8_MAX UINT8_MAX | ||
| 70 | #define UINT_FAST64_MAX UINT64_MAX | ||
| 71 | |||
| 72 | #define UINT_LEAST8_MAX UINT8_MAX | ||
| 73 | #define UINT_LEAST16_MAX UINT16_MAX | ||
| 74 | #define UINT_LEAST32_MAX UINT32_MAX | ||
| 75 | #define UINT_LEAST64_MAX UINT64_MAX | ||
| 76 | |||
| 77 | #define INTMAX_MIN INT64_MIN | ||
| 78 | #define INTMAX_MAX INT64_MAX | ||
| 79 | #define UINTMAX_MAX UINT64_MAX | ||
| 80 | |||
| 81 | #define WINT_MIN 0U | ||
| 82 | #define WINT_MAX UINT32_MAX | ||
| 83 | |||
| 84 | #if L'\0'-1 > 0 | ||
| 85 | #define WCHAR_MAX (0xffffffffu+L'\0') | ||
| 86 | #define WCHAR_MIN (0+L'\0') | ||
| 87 | #else | ||
| 88 | #define WCHAR_MAX (0x7fffffff+L'\0') | ||
| 89 | #define WCHAR_MIN (-1-0x7fffffff+L'\0') | ||
| 90 | #endif | ||
| 91 | |||
| 92 | #define SIG_ATOMIC_MIN INT32_MIN | ||
| 93 | #define SIG_ATOMIC_MAX INT32_MAX | ||
| 94 | |||
| 95 | #include <bits/stdint.h> | ||
| 96 | |||
| 97 | #define INT8_C(c) c | ||
| 98 | #define INT16_C(c) c | ||
| 99 | #define INT32_C(c) c | ||
| 100 | |||
| 101 | #define UINT8_C(c) c | ||
| 102 | #define UINT16_C(c) c | ||
| 103 | #define UINT32_C(c) c ## U | ||
| 104 | |||
| 105 | #if UINTPTR_MAX == UINT64_MAX | ||
| 106 | #define INT64_C(c) c ## L | ||
| 107 | #define UINT64_C(c) c ## UL | ||
| 108 | #define INTMAX_C(c) c ## L | ||
| 109 | #define UINTMAX_C(c) c ## UL | ||
| 110 | #else | ||
| 111 | #define INT64_C(c) c ## LL | ||
| 112 | #define UINT64_C(c) c ## ULL | ||
| 113 | #define INTMAX_C(c) c ## LL | ||
| 114 | #define UINTMAX_C(c) c ## ULL | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdio.h created+252| ... | @@ -0,0 +1,252 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 32 | #define NULL 0L | ||
| 33 | #else | ||
| 34 | #define NULL ((void*)0) | ||
| 35 | #endif | ||
| 36 | #else | ||
| 37 | #define __need_NULL | ||
| 38 | #include <stddef.h> | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #undef EOF | ||
| 42 | #define EOF (-1) | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 45 | #undef SEEK_SET | ||
| 46 | #undef SEEK_CUR | ||
| 47 | #undef SEEK_END | ||
| 48 | #define SEEK_SET 0 | ||
| 49 | #define SEEK_CUR 1 | ||
| 50 | #define SEEK_END 2 | ||
| 51 | #else | ||
| 52 | #include <__seek.h> | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #define _IOFBF 0 | ||
| 56 | #define _IOLBF 1 | ||
| 57 | #define _IONBF 2 | ||
| 58 | |||
| 59 | #define BUFSIZ 1024 | ||
| 60 | #define FILENAME_MAX 4096 | ||
| 61 | #define FOPEN_MAX 1000 | ||
| 62 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 63 | #define TMP_MAX 10000 | ||
| 64 | #define L_tmpnam 20 | ||
| 65 | #endif | ||
| 66 | |||
| 67 | typedef union _G_fpos64_t { | ||
| 68 | 	char __opaque[16]; | ||
| 69 | 	long long __lldata; | ||
| 70 | 	double __align; | ||
| 71 | } fpos_t; | ||
| 72 | |||
| 73 | extern FILE *const stdin; | ||
| 74 | extern FILE *const stdout; | ||
| 75 | extern FILE *const stderr; | ||
| 76 | |||
| 77 | #define stdin (stdin) | ||
| 78 | #define stdout (stdout) | ||
| 79 | #define stderr (stderr) | ||
| 80 | |||
| 81 | FILE *fopen(const char *__restrict, const char *__restrict); | ||
| 82 | FILE *freopen(const char *__restrict, const char *__restrict, FILE *__restrict); | ||
| 83 | int fclose(FILE *); | ||
| 84 | |||
| 85 | int remove(const char *); | ||
| 86 | int rename(const char *, const char *); | ||
| 87 | |||
| 88 | int feof(FILE *); | ||
| 89 | int ferror(FILE *); | ||
| 90 | int fflush(FILE *); | ||
| 91 | void clearerr(FILE *); | ||
| 92 | |||
| 93 | int fseek(FILE *, long, int); | ||
| 94 | long ftell(FILE *); | ||
| 95 | void rewind(FILE *); | ||
| 96 | |||
| 97 | int fgetpos(FILE *__restrict, fpos_t *__restrict); | ||
| 98 | int fsetpos(FILE *, const fpos_t *); | ||
| 99 | |||
| 100 | size_t fread(void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 101 | size_t fwrite(const void *__restrict, size_t, size_t, FILE *__restrict); | ||
| 102 | |||
| 103 | int fgetc(FILE *); | ||
| 104 | int getc(FILE *); | ||
| 105 | int getchar(void); | ||
| 106 | int ungetc(int, FILE *); | ||
| 107 | |||
| 108 | int fputc(int, FILE *); | ||
| 109 | int putc(int, FILE *); | ||
| 110 | int putchar(int); | ||
| 111 | |||
| 112 | char *fgets(char *__restrict, int, FILE *__restrict); | ||
| 113 | #if __STDC_VERSION__ < 201112L | ||
| 114 | #ifdef __wasilibc_unmodified_upstream /* gets is obsolete */ | ||
| 115 | char *gets(char *); | ||
| 116 | #else | ||
| 117 | char *gets(char *) __attribute__((__deprecated__("gets is not defined on WASI"))); | ||
| 118 | #endif | ||
| 119 | #endif | ||
| 120 | |||
| 121 | int fputs(const char *__restrict, FILE *__restrict); | ||
| 122 | int puts(const char *); | ||
| 123 | |||
| 124 | int printf(const char *__restrict, ...); | ||
| 125 | int fprintf(FILE *__restrict, const char *__restrict, ...); | ||
| 126 | int sprintf(char *__restrict, const char *__restrict, ...); | ||
| 127 | int snprintf(char *__restrict, size_t, const char *__restrict, ...); | ||
| 128 | |||
| 129 | int vprintf(const char *__restrict, __isoc_va_list); | ||
| 130 | int vfprintf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 131 | int vsprintf(char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 132 | int vsnprintf(char *__restrict, size_t, const char *__restrict, __isoc_va_list); | ||
| 133 | |||
| 134 | int scanf(const char *__restrict, ...); | ||
| 135 | int fscanf(FILE *__restrict, const char *__restrict, ...); | ||
| 136 | int sscanf(const char *__restrict, const char *__restrict, ...); | ||
| 137 | int vscanf(const char *__restrict, __isoc_va_list); | ||
| 138 | int vfscanf(FILE *__restrict, const char *__restrict, __isoc_va_list); | ||
| 139 | int vsscanf(const char *__restrict, const char *__restrict, __isoc_va_list); | ||
| 140 | |||
| 141 | void perror(const char *); | ||
| 142 | |||
| 143 | int setvbuf(FILE *__restrict, char *__restrict, int, size_t); | ||
| 144 | void setbuf(FILE *__restrict, char *__restrict); | ||
| 145 | |||
| 146 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 147 | char *tmpnam(char *); | ||
| 148 | FILE *tmpfile(void); | ||
| 149 | #else | ||
| 150 | char *tmpnam(char *) __attribute__((__deprecated__("tmpnam is not defined on WASI"))); | ||
| 151 | FILE *tmpfile(void) __attribute__((__deprecated__("tmpfile is not defined on WASI"))); | ||
| 152 | #endif | ||
| 153 | |||
| 154 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 155 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 156 | || defined(_BSD_SOURCE) | ||
| 157 | FILE *fmemopen(void *__restrict, size_t, const char *__restrict); | ||
| 158 | FILE *open_memstream(char **, size_t *); | ||
| 159 | FILE *fdopen(int, const char *); | ||
| 160 | #ifdef __wasilibc_unmodified_upstream /* WASI has no popen */ | ||
| 161 | FILE *popen(const char *, const char *); | ||
| 162 | int pclose(FILE *); | ||
| 163 | #endif | ||
| 164 | int fileno(FILE *); | ||
| 165 | int fseeko(FILE *, off_t, int); | ||
| 166 | off_t ftello(FILE *); | ||
| 167 | int dprintf(int, const char *__restrict, ...); | ||
| 168 | int vdprintf(int, const char *__restrict, __isoc_va_list); | ||
| 169 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 170 | void flockfile(FILE *); | ||
| 171 | int ftrylockfile(FILE *); | ||
| 172 | void funlockfile(FILE *); | ||
| 173 | #endif | ||
| 174 | int getc_unlocked(FILE *); | ||
| 175 | int getchar_unlocked(void); | ||
| 176 | int putc_unlocked(int, FILE *); | ||
| 177 | int putchar_unlocked(int); | ||
| 178 | ssize_t getdelim(char **__restrict, size_t *__restrict, int, FILE *__restrict); | ||
| 179 | ssize_t getline(char **__restrict, size_t *__restrict, FILE *__restrict); | ||
| 180 | int renameat(int, const char *, int, const char *); | ||
| 181 | char *ctermid(char *); | ||
| 182 | #define L_ctermid 20 | ||
| 183 | #endif | ||
| 184 | |||
| 185 | |||
| 186 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 187 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 188 | || defined(_BSD_SOURCE) | ||
| 189 | #define P_tmpdir "/tmp" | ||
| 190 | char *tempnam(const char *, const char *); | ||
| 191 | #endif | ||
| 192 | #endif | ||
| 193 | |||
| 194 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 195 | #define L_cuserid 20 | ||
| 196 | char *cuserid(char *); | ||
| 197 | void setlinebuf(FILE *); | ||
| 198 | void setbuffer(FILE *, char *, size_t); | ||
| 199 | int fgetc_unlocked(FILE *); | ||
| 200 | int fputc_unlocked(int, FILE *); | ||
| 201 | int fflush_unlocked(FILE *); | ||
| 202 | size_t fread_unlocked(void *, size_t, size_t, FILE *); | ||
| 203 | size_t fwrite_unlocked(const void *, size_t, size_t, FILE *); | ||
| 204 | void clearerr_unlocked(FILE *); | ||
| 205 | int feof_unlocked(FILE *); | ||
| 206 | int ferror_unlocked(FILE *); | ||
| 207 | int fileno_unlocked(FILE *); | ||
| 208 | int getw(FILE *); | ||
| 209 | int putw(int, FILE *); | ||
| 210 | char *fgetln(FILE *, size_t *); | ||
| 211 | int asprintf(char **, const char *, ...); | ||
| 212 | int vasprintf(char **, const char *, __isoc_va_list); | ||
| 213 | #endif | ||
| 214 | |||
| 215 | #ifdef _GNU_SOURCE | ||
| 216 | char *fgets_unlocked(char *, int, FILE *); | ||
| 217 | int fputs_unlocked(const char *, FILE *); | ||
| 218 | |||
| 219 | typedef ssize_t (cookie_read_function_t)(void *, char *, size_t); | ||
| 220 | typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t); | ||
| 221 | typedef int (cookie_seek_function_t)(void *, off_t *, int); | ||
| 222 | typedef int (cookie_close_function_t)(void *); | ||
| 223 | |||
| 224 | typedef struct _IO_cookie_io_functions_t { | ||
| 225 | 	cookie_read_function_t *read; | ||
| 226 | 	cookie_write_function_t *write; | ||
| 227 | 	cookie_seek_function_t *seek; | ||
| 228 | 	cookie_close_function_t *close; | ||
| 229 | } cookie_io_functions_t; | ||
| 230 | |||
| 231 | FILE *fopencookie(void *, const char *, cookie_io_functions_t); | ||
| 232 | #endif | ||
| 233 | |||
| 234 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 235 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 236 | #define tmpfile64 tmpfile | ||
| 237 | #endif | ||
| 238 | #define fopen64 fopen | ||
| 239 | #define freopen64 freopen | ||
| 240 | #define fseeko64 fseeko | ||
| 241 | #define ftello64 ftello | ||
| 242 | #define fgetpos64 fgetpos | ||
| 243 | #define fsetpos64 fsetpos | ||
| 244 | #define fpos64_t fpos_t | ||
| 245 | #define off64_t off_t | ||
| 246 | #endif | ||
| 247 | |||
| 248 | #ifdef __cplusplus | ||
| 249 | } | ||
| 250 | #endif | ||
| 251 | |||
| 252 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdio_ext.h created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #ifndef _STDIO_EXT_H | ||
| 2 | #define _STDIO_EXT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdio.h> | ||
| 9 | |||
| 10 | #define FSETLOCKING_QUERY 0 | ||
| 11 | #define FSETLOCKING_INTERNAL 1 | ||
| 12 | #define FSETLOCKING_BYCALLER 2 | ||
| 13 | |||
| 14 | void _flushlbf(void); | ||
| 15 | int __fsetlocking(FILE *, int); | ||
| 16 | int __fwriting(FILE *); | ||
| 17 | int __freading(FILE *); | ||
| 18 | int __freadable(FILE *); | ||
| 19 | int __fwritable(FILE *); | ||
| 20 | int __flbf(FILE *); | ||
| 21 | size_t __fbufsize(FILE *); | ||
| 22 | size_t __fpending(FILE *); | ||
| 23 | int __fpurge(FILE *); | ||
| 24 | |||
| 25 | size_t __freadahead(FILE *); | ||
| 26 | const char *__freadptr(FILE *, size_t *); | ||
| 27 | void __freadptrinc(FILE *, size_t); | ||
| 28 | void __fseterr(FILE *); | ||
| 29 | |||
| 30 | #ifdef __cplusplus | ||
| 31 | } | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdlib.h created+216| ... | @@ -0,0 +1,216 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 17 | #define NULL 0L | ||
| 18 | #else | ||
| 19 | #define NULL ((void*)0) | ||
| 20 | #endif | ||
| 21 | #else | ||
| 22 | #define __need_NULL | ||
| 23 | #include <stddef.h> | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #define __NEED_size_t | ||
| 27 | #define __NEED_wchar_t | ||
| 28 | |||
| 29 | #include <bits/alltypes.h> | ||
| 30 | |||
| 31 | int atoi (const char *); | ||
| 32 | long atol (const char *); | ||
| 33 | long long atoll (const char *); | ||
| 34 | double atof (const char *); | ||
| 35 | |||
| 36 | float strtof (const char *__restrict, char **__restrict); | ||
| 37 | double strtod (const char *__restrict, char **__restrict); | ||
| 38 | long double strtold (const char *__restrict, char **__restrict); | ||
| 39 | |||
| 40 | long strtol (const char *__restrict, char **__restrict, int); | ||
| 41 | unsigned long strtoul (const char *__restrict, char **__restrict, int); | ||
| 42 | long long strtoll (const char *__restrict, char **__restrict, int); | ||
| 43 | unsigned long long strtoull (const char *__restrict, char **__restrict, int); | ||
| 44 | |||
| 45 | int rand (void); | ||
| 46 | void srand (unsigned); | ||
| 47 | |||
| 48 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 49 | void *malloc (size_t); | ||
| 50 | void *calloc (size_t, size_t); | ||
| 51 | void *realloc (void *, size_t); | ||
| 52 | void free (void *); | ||
| 53 | #endif | ||
| 54 | void *aligned_alloc(size_t, size_t); | ||
| 55 | |||
| 56 | _Noreturn void abort (void); | ||
| 57 | int atexit (void (*) (void)); | ||
| 58 | _Noreturn void exit (int); | ||
| 59 | _Noreturn void _Exit (int); | ||
| 60 | int at_quick_exit (void (*) (void)); | ||
| 61 | _Noreturn void quick_exit (int); | ||
| 62 | |||
| 63 | char *getenv (const char *); | ||
| 64 | |||
| 65 | int system (const char *); | ||
| 66 | |||
| 67 | void *bsearch (const void *, const void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 68 | void qsort (void *, size_t, size_t, int (*)(const void *, const void *)); | ||
| 69 | |||
| 70 | int abs (int); | ||
| 71 | long labs (long); | ||
| 72 | long long llabs (long long); | ||
| 73 | |||
| 74 | typedef struct { int quot, rem; } div_t; | ||
| 75 | typedef struct { long quot, rem; } ldiv_t; | ||
| 76 | typedef struct { long long quot, rem; } lldiv_t; | ||
| 77 | |||
| 78 | div_t div (int, int); | ||
| 79 | ldiv_t ldiv (long, long); | ||
| 80 | lldiv_t lldiv (long long, long long); | ||
| 81 | |||
| 82 | int mblen (const char *, size_t); | ||
| 83 | int mbtowc (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 84 | int wctomb (char *, wchar_t); | ||
| 85 | size_t mbstowcs (wchar_t *__restrict, const char *__restrict, size_t); | ||
| 86 | size_t wcstombs (char *__restrict, const wchar_t *__restrict, size_t); | ||
| 87 | |||
| 88 | #define EXIT_FAILURE 1 | ||
| 89 | #define EXIT_SUCCESS 0 | ||
| 90 | |||
| 91 | size_t __ctype_get_mb_cur_max(void); | ||
| 92 | #define MB_CUR_MAX (__ctype_get_mb_cur_max()) | ||
| 93 | |||
| 94 | #define RAND_MAX (0x7fffffff) | ||
| 95 | |||
| 96 | |||
| 97 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 98 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 99 | || defined(_BSD_SOURCE) | ||
| 100 | |||
| 101 | #ifdef __wasilibc_unmodified_upstream /* WASI has no wait */ | ||
| 102 | #define WNOHANG 1 | ||
| 103 | #define WUNTRACED 2 | ||
| 104 | |||
| 105 | #define WEXITSTATUS(s) (((s) & 0xff00) >> 8) | ||
| 106 | #define WTERMSIG(s) ((s) & 0x7f) | ||
| 107 | #define WSTOPSIG(s) WEXITSTATUS(s) | ||
| 108 | #define WIFEXITED(s) (!WTERMSIG(s)) | ||
| 109 | #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) | ||
| 110 | #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) | ||
| 111 | #endif | ||
| 112 | |||
| 113 | int posix_memalign (void **, size_t, size_t); | ||
| 114 | int setenv (const char *, const char *, int); | ||
| 115 | int unsetenv (const char *); | ||
| 116 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 117 | int mkstemp (char *); | ||
| 118 | int mkostemp (char *, int); | ||
| 119 | char *mkdtemp (char *); | ||
| 120 | #endif | ||
| 121 | int getsubopt (char **, char *const *, char **); | ||
| 122 | int rand_r (unsigned *); | ||
| 123 | |||
| 124 | #endif | ||
| 125 | |||
| 126 | |||
| 127 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 128 | || defined(_BSD_SOURCE) | ||
| 129 | #ifdef __wasilibc_unmodified_upstream /* WASI has no absolute paths */ | ||
| 130 | char *realpath (const char *__restrict, char *__restrict); | ||
| 131 | #endif | ||
| 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 | #endif | ||
| 175 | #endif | ||
| 176 | |||
| 177 | #ifdef _GNU_SOURCE | ||
| 178 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pseudo-terminals */ | ||
| 179 | int ptsname_r(int, char *, size_t); | ||
| 180 | #endif | ||
| 181 | char *ecvt(double, int, int *, int *); | ||
| 182 | char *fcvt(double, int, int *, int *); | ||
| 183 | char *gcvt(double, int, char *); | ||
| 184 | char *secure_getenv(const char *); | ||
| 185 | struct __locale_struct; | ||
| 186 | float strtof_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 187 | double strtod_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 188 | long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *); | ||
| 189 | #endif | ||
| 190 | |||
| 191 | #ifdef __wasilibc_unmodified_upstream /* WASI has no temp directories */ | ||
| 192 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 193 | #define mkstemp64 mkstemp | ||
| 194 | #define mkostemp64 mkostemp | ||
| 195 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 196 | #define mkstemps64 mkstemps | ||
| 197 | #define mkostemps64 mkostemps | ||
| 198 | #endif | ||
| 199 | #endif | ||
| 200 | #endif | ||
| 201 | |||
| 202 | #ifdef __wasilibc_unmodified_upstream /* Declare arc4random functions */ | ||
| 203 | #else | ||
| 204 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 205 | #include <stdint.h> | ||
| 206 | uint32_t arc4random(void); | ||
| 207 | void arc4random_buf(void *, size_t); | ||
| 208 | uint32_t arc4random_uniform(uint32_t); | ||
| 209 | #endif | ||
| 210 | #endif | ||
| 211 | |||
| 212 | #ifdef __cplusplus | ||
| 213 | } | ||
| 214 | #endif | ||
| 215 | |||
| 216 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stdnoreturn.h created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #ifndef _STDNORETURN_H | ||
| 2 | #define _STDNORETURN_H | ||
| 3 | #ifndef __cplusplus | ||
| 4 | #include <features.h> | ||
| 5 | #define noreturn _Noreturn | ||
| 6 | #endif | ||
| 7 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/string.h created+126| ... | @@ -0,0 +1,126 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 16 | #define NULL 0L | ||
| 17 | #else | ||
| 18 | #define NULL ((void*)0) | ||
| 19 | #endif | ||
| 20 | #else | ||
| 21 | #define __need_NULL | ||
| 22 | #include <stddef.h> | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #define __NEED_size_t | ||
| 26 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 27 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 28 | || defined(_BSD_SOURCE) | ||
| 29 | #define __NEED_locale_t | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #include <bits/alltypes.h> | ||
| 33 | |||
| 34 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 35 | void *memcpy (void *__restrict, const void *__restrict, size_t); | ||
| 36 | void *memmove (void *, const void *, size_t); | ||
| 37 | void *memset (void *, int, size_t); | ||
| 38 | #endif | ||
| 39 | int memcmp (const void *, const void *, size_t); | ||
| 40 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 41 | void *memchr (const void *, int, size_t); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | char *strcpy (char *__restrict, const char *__restrict); | ||
| 45 | char *strncpy (char *__restrict, const char *__restrict, size_t); | ||
| 46 | |||
| 47 | char *strcat (char *__restrict, const char *__restrict); | ||
| 48 | char *strncat (char *__restrict, const char *__restrict, size_t); | ||
| 49 | |||
| 50 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 51 | int strcmp (const char *, const char *); | ||
| 52 | #endif | ||
| 53 | int strncmp (const char *, const char *, size_t); | ||
| 54 | |||
| 55 | int strcoll (const char *, const char *); | ||
| 56 | size_t strxfrm (char *__restrict, const char *__restrict, size_t); | ||
| 57 | |||
| 58 | char *strchr (const char *, int); | ||
| 59 | char *strrchr (const char *, int); | ||
| 60 | |||
| 61 | size_t strcspn (const char *, const char *); | ||
| 62 | size_t strspn (const char *, const char *); | ||
| 63 | char *strpbrk (const char *, const char *); | ||
| 64 | char *strstr (const char *, const char *); | ||
| 65 | char *strtok (char *__restrict, const char *__restrict); | ||
| 66 | |||
| 67 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 68 | size_t strlen (const char *); | ||
| 69 | #endif | ||
| 70 | |||
| 71 | char *strerror (int); | ||
| 72 | |||
| 73 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 74 | #include <strings.h> | ||
| 75 | #endif | ||
| 76 | |||
| 77 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 78 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 79 | || defined(_BSD_SOURCE) | ||
| 80 | char *strtok_r (char *__restrict, const char *__restrict, char **__restrict); | ||
| 81 | int strerror_r (int, char *, size_t); | ||
| 82 | char *stpcpy(char *__restrict, const char *__restrict); | ||
| 83 | char *stpncpy(char *__restrict, const char *__restrict, size_t); | ||
| 84 | size_t strnlen (const char *, size_t); | ||
| 85 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 86 | char *strdup (const char *); | ||
| 87 | #endif | ||
| 88 | char *strndup (const char *, size_t); | ||
| 89 | char *strsignal(int); | ||
| 90 | char *strerror_l (int, locale_t); | ||
| 91 | int strcoll_l (const char *, const char *, locale_t); | ||
| 92 | size_t strxfrm_l (char *__restrict, const char *__restrict, size_t, locale_t); | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 96 | || defined(_BSD_SOURCE) | ||
| 97 | void *memccpy (void *__restrict, const void *__restrict, int, size_t); | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 101 | char *strsep(char **, const char *); | ||
| 102 | size_t strlcat (char *, const char *, size_t); | ||
| 103 | size_t strlcpy (char *, const char *, size_t); | ||
| 104 | void explicit_bzero (void *, size_t); | ||
| 105 | #endif | ||
| 106 | |||
| 107 | #ifdef _GNU_SOURCE | ||
| 108 | #define	strdupa(x)	strcpy(alloca(strlen(x)+1),x) | ||
| 109 | int strverscmp (const char *, const char *); | ||
| 110 | char *strchrnul(const char *, int); | ||
| 111 | char *strcasestr(const char *, const char *); | ||
| 112 | void *memmem(const void *, size_t, const void *, size_t); | ||
| 113 | void *memrchr(const void *, int, size_t); | ||
| 114 | void *mempcpy(void *, const void *, size_t); | ||
| 115 | #ifdef __wasilibc_unmodified_upstream /* avoid unprototyped decls; use <libgen.h> */ | ||
| 116 | #ifndef __cplusplus | ||
| 117 | char *basename(); | ||
| 118 | #endif | ||
| 119 | #endif | ||
| 120 | #endif | ||
| 121 | |||
| 122 | #ifdef __cplusplus | ||
| 123 | } | ||
| 124 | #endif | ||
| 125 | |||
| 126 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/strings.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef	_STRINGS_H | ||
| 2 | #define	_STRINGS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_locale_t | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) || defined(_POSIX_SOURCE) \ | ||
| 14 | || (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE+0 < 200809L) \ | ||
| 15 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 16 | int bcmp (const void *, const void *, size_t); | ||
| 17 | void bcopy (const void *, void *, size_t); | ||
| 18 | void bzero (void *, size_t); | ||
| 19 | char *index (const char *, int); | ||
| 20 | char *rindex (const char *, int); | ||
| 21 | #endif | ||
| 22 | |||
| 23 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 24 | int ffs (int); | ||
| 25 | int ffsl (long); | ||
| 26 | int ffsll (long long); | ||
| 27 | #endif | ||
| 28 | |||
| 29 | int strcasecmp (const char *, const char *); | ||
| 30 | int strncasecmp (const char *, const char *, size_t); | ||
| 31 | |||
| 32 | int strcasecmp_l (const char *, const char *, locale_t); | ||
| 33 | int strncasecmp_l (const char *, const char *, size_t, locale_t); | ||
| 34 | |||
| 35 | #ifdef __cplusplus | ||
| 36 | } | ||
| 37 | #endif | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/stropts.h created+139| ... | @@ -0,0 +1,139 @@ | ||
| 1 | #ifndef _STROPTS_H | ||
| 2 | #define _STROPTS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __SID		('S' << 8) | ||
| 9 | |||
| 10 | #define I_NREAD		(__SID | 1) | ||
| 11 | #define I_PUSH		(__SID | 2) | ||
| 12 | #define I_POP		(__SID | 3) | ||
| 13 | #define I_LOOK		(__SID | 4) | ||
| 14 | #define I_FLUSH		(__SID | 5) | ||
| 15 | #define I_SRDOPT	(__SID | 6) | ||
| 16 | #define I_GRDOPT	(__SID | 7) | ||
| 17 | #define I_STR		(__SID | 8) | ||
| 18 | #define I_SETSIG	(__SID | 9) | ||
| 19 | #define I_GETSIG	(__SID |10) | ||
| 20 | #define I_FIND		(__SID |11) | ||
| 21 | #define I_LINK		(__SID |12) | ||
| 22 | #define I_UNLINK	(__SID |13) | ||
| 23 | #define I_PEEK		(__SID |15) | ||
| 24 | #define I_FDINSERT	(__SID |16) | ||
| 25 | #define I_SENDFD	(__SID |17) | ||
| 26 | #define I_RECVFD	(__SID |14) | ||
| 27 | #define I_SWROPT	(__SID |19) | ||
| 28 | #define I_GWROPT	(__SID |20) | ||
| 29 | #define I_LIST		(__SID |21) | ||
| 30 | #define I_PLINK		(__SID |22) | ||
| 31 | #define I_PUNLINK	(__SID |23) | ||
| 32 | #define I_FLUSHBAND	(__SID |28) | ||
| 33 | #define I_CKBAND	(__SID |29) | ||
| 34 | #define I_GETBAND	(__SID |30) | ||
| 35 | #define I_ATMARK	(__SID |31) | ||
| 36 | #define I_SETCLTIME	(__SID |32) | ||
| 37 | #define I_GETCLTIME	(__SID |33) | ||
| 38 | #define I_CANPUT	(__SID |34) | ||
| 39 | |||
| 40 | #define FMNAMESZ	8 | ||
| 41 | |||
| 42 | #define FLUSHR		0x01 | ||
| 43 | #define FLUSHW		0x02 | ||
| 44 | #define FLUSHRW		0x03 | ||
| 45 | #define FLUSHBAND	0x04 | ||
| 46 | |||
| 47 | #define S_INPUT		0x0001 | ||
| 48 | #define S_HIPRI		0x0002 | ||
| 49 | #define S_OUTPUT	0x0004 | ||
| 50 | #define S_MSG		0x0008 | ||
| 51 | #define S_ERROR		0x0010 | ||
| 52 | #define S_HANGUP	0x0020 | ||
| 53 | #define S_RDNORM	0x0040 | ||
| 54 | #define S_WRNORM	S_OUTPUT | ||
| 55 | #define S_RDBAND	0x0080 | ||
| 56 | #define S_WRBAND	0x0100 | ||
| 57 | #define S_BANDURG	0x0200 | ||
| 58 | |||
| 59 | #define RS_HIPRI	0x01 | ||
| 60 | |||
| 61 | #define RNORM		0x0000 | ||
| 62 | #define RMSGD		0x0001 | ||
| 63 | #define RMSGN		0x0002 | ||
| 64 | #define RPROTDAT	0x0004 | ||
| 65 | #define RPROTDIS	0x0008 | ||
| 66 | #define RPROTNORM	0x0010 | ||
| 67 | #define RPROTMASK	0x001C | ||
| 68 | |||
| 69 | #define SNDZERO		0x001 | ||
| 70 | #define SNDPIPE		0x002 | ||
| 71 | |||
| 72 | #define ANYMARK		0x01 | ||
| 73 | #define LASTMARK	0x02 | ||
| 74 | |||
| 75 | #define MUXID_ALL	(-1) | ||
| 76 | |||
| 77 | #define MSG_HIPRI	0x01 | ||
| 78 | #define MSG_ANY		0x02 | ||
| 79 | #define MSG_BAND	0x04 | ||
| 80 | |||
| 81 | #define MORECTL		1 | ||
| 82 | #define MOREDATA	2 | ||
| 83 | |||
| 84 | struct bandinfo { | ||
| 85 | 	unsigned char bi_pri; | ||
| 86 | 	int bi_flag; | ||
| 87 | }; | ||
| 88 | |||
| 89 | struct strbuf { | ||
| 90 | 	int maxlen; | ||
| 91 | 	int len; | ||
| 92 | 	char *buf; | ||
| 93 | }; | ||
| 94 | |||
| 95 | struct strpeek { | ||
| 96 | 	struct strbuf ctlbuf; | ||
| 97 | 	struct strbuf databuf; | ||
| 98 | 	unsigned flags; | ||
| 99 | }; | ||
| 100 | |||
| 101 | struct strfdinsert { | ||
| 102 | 	struct strbuf ctlbuf; | ||
| 103 | 	struct strbuf databuf; | ||
| 104 | 	unsigned flags; | ||
| 105 | 	int fildes; | ||
| 106 | 	int offset; | ||
| 107 | }; | ||
| 108 | |||
| 109 | struct strioctl { | ||
| 110 | 	int ic_cmd; | ||
| 111 | 	int ic_timout; | ||
| 112 | 	int ic_len; | ||
| 113 | 	char *ic_dp; | ||
| 114 | }; | ||
| 115 | |||
| 116 | struct strrecvfd { | ||
| 117 | 	int fd; | ||
| 118 | 	int uid; | ||
| 119 | 	int gid; | ||
| 120 | 	char __fill[8]; | ||
| 121 | }; | ||
| 122 | |||
| 123 | struct str_mlist { | ||
| 124 | 	char l_name[FMNAMESZ + 1]; | ||
| 125 | }; | ||
| 126 | |||
| 127 | struct str_list { | ||
| 128 | 	int sl_nmods; | ||
| 129 | 	struct str_mlist *sl_modlist; | ||
| 130 | }; | ||
| 131 | |||
| 132 | int isastream(int); | ||
| 133 | int ioctl(int, int, ...); | ||
| 134 | |||
| 135 | #ifdef __cplusplus | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/acct.h created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | #ifndef _SYS_ACCT_H | ||
| 2 | #define _SYS_ACCT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <time.h> | ||
| 10 | #include <stdint.h> | ||
| 11 | |||
| 12 | #define ACCT_COMM 16 | ||
| 13 | |||
| 14 | typedef uint16_t comp_t; | ||
| 15 | |||
| 16 | struct acct { | ||
| 17 | 	char ac_flag; | ||
| 18 | 	uint16_t ac_uid; | ||
| 19 | 	uint16_t ac_gid; | ||
| 20 | 	uint16_t ac_tty; | ||
| 21 | 	uint32_t ac_btime; | ||
| 22 | 	comp_t ac_utime; | ||
| 23 | 	comp_t ac_stime; | ||
| 24 | 	comp_t ac_etime; | ||
| 25 | 	comp_t ac_mem; | ||
| 26 | 	comp_t ac_io; | ||
| 27 | 	comp_t ac_rw; | ||
| 28 | 	comp_t ac_minflt; | ||
| 29 | 	comp_t ac_majflt; | ||
| 30 | 	comp_t ac_swaps; | ||
| 31 | 	uint32_t ac_exitcode; | ||
| 32 | 	char ac_comm[ACCT_COMM+1]; | ||
| 33 | 	char ac_pad[10]; | ||
| 34 | }; | ||
| 35 | |||
| 36 | |||
| 37 | struct acct_v3 { | ||
| 38 | 	char ac_flag; | ||
| 39 | 	char ac_version; | ||
| 40 | 	uint16_t ac_tty; | ||
| 41 | 	uint32_t ac_exitcode; | ||
| 42 | 	uint32_t ac_uid; | ||
| 43 | 	uint32_t ac_gid; | ||
| 44 | 	uint32_t ac_pid; | ||
| 45 | 	uint32_t ac_ppid; | ||
| 46 | 	uint32_t ac_btime; | ||
| 47 | 	float ac_etime; | ||
| 48 | 	comp_t ac_utime; | ||
| 49 | 	comp_t ac_stime; | ||
| 50 | 	comp_t ac_mem; | ||
| 51 | 	comp_t ac_io; | ||
| 52 | 	comp_t ac_rw; | ||
| 53 | 	comp_t ac_minflt; | ||
| 54 | 	comp_t ac_majflt; | ||
| 55 | 	comp_t ac_swaps; | ||
| 56 | 	char ac_comm[ACCT_COMM]; | ||
| 57 | }; | ||
| 58 | |||
| 59 | #define AFORK 1 | ||
| 60 | #define ASU 2 | ||
| 61 | #define ACORE 8 | ||
| 62 | #define AXSIG 16 | ||
| 63 | #define ACCT_BYTEORDER (128*(__BYTE_ORDER==__BIG_ENDIAN)) | ||
| 64 | #define AHZ 100 | ||
| 65 | |||
| 66 | int acct(const char *); | ||
| 67 | |||
| 68 | #ifdef __cplusplus | ||
| 69 | } | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/auxv.h created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #ifndef _SYS_AUXV_H | ||
| 2 | #define _SYS_AUXV_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <elf.h> | ||
| 9 | #include <bits/hwcap.h> | ||
| 10 | |||
| 11 | unsigned long getauxval(unsigned long); | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | } | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/cachectl.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #ifndef _SYS_CACHECTL_H | ||
| 2 | #define _SYS_CACHECTL_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define ICACHE (1<<0) | ||
| 9 | #define DCACHE (1<<1) | ||
| 10 | #define BCACHE (ICACHE|DCACHE) | ||
| 11 | #define CACHEABLE 0 | ||
| 12 | #define UNCACHEABLE 1 | ||
| 13 | |||
| 14 | int cachectl(void *, int, int); | ||
| 15 | int cacheflush(void *, int, int); | ||
| 16 | int _flush_cache(void *, int, int); | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/dir.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #define direct dirent | ||
lib/libc/wasi/libc-top-half/musl/include/sys/epoll.h created+69| ... | @@ -0,0 +1,69 @@ | ||
| 1 | #ifndef	_SYS_EPOLL_H | ||
| 2 | #define	_SYS_EPOLL_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <sys/types.h> | ||
| 10 | #include <fcntl.h> | ||
| 11 | |||
| 12 | #define __NEED_sigset_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #define EPOLL_CLOEXEC O_CLOEXEC | ||
| 17 | #define EPOLL_NONBLOCK O_NONBLOCK | ||
| 18 | |||
| 19 | enum EPOLL_EVENTS { __EPOLL_DUMMY }; | ||
| 20 | #define EPOLLIN 0x001 | ||
| 21 | #define EPOLLPRI 0x002 | ||
| 22 | #define EPOLLOUT 0x004 | ||
| 23 | #define EPOLLRDNORM 0x040 | ||
| 24 | #define EPOLLNVAL 0x020 | ||
| 25 | #define EPOLLRDBAND 0x080 | ||
| 26 | #define EPOLLWRNORM 0x100 | ||
| 27 | #define EPOLLWRBAND 0x200 | ||
| 28 | #define EPOLLMSG 0x400 | ||
| 29 | #define EPOLLERR 0x008 | ||
| 30 | #define EPOLLHUP 0x010 | ||
| 31 | #define EPOLLRDHUP 0x2000 | ||
| 32 | #define EPOLLEXCLUSIVE (1U<<28) | ||
| 33 | #define EPOLLWAKEUP (1U<<29) | ||
| 34 | #define EPOLLONESHOT (1U<<30) | ||
| 35 | #define EPOLLET (1U<<31) | ||
| 36 | |||
| 37 | #define EPOLL_CTL_ADD 1 | ||
| 38 | #define EPOLL_CTL_DEL 2 | ||
| 39 | #define EPOLL_CTL_MOD 3 | ||
| 40 | |||
| 41 | typedef union epoll_data { | ||
| 42 | 	void *ptr; | ||
| 43 | 	int fd; | ||
| 44 | 	uint32_t u32; | ||
| 45 | 	uint64_t u64; | ||
| 46 | } epoll_data_t; | ||
| 47 | |||
| 48 | struct epoll_event { | ||
| 49 | 	uint32_t events; | ||
| 50 | 	epoll_data_t data; | ||
| 51 | } | ||
| 52 | #ifdef __x86_64__ | ||
| 53 | __attribute__ ((__packed__)) | ||
| 54 | #endif | ||
| 55 | ; | ||
| 56 | |||
| 57 | |||
| 58 | int epoll_create(int); | ||
| 59 | int epoll_create1(int); | ||
| 60 | int epoll_ctl(int, int, int, struct epoll_event *); | ||
| 61 | int epoll_wait(int, struct epoll_event *, int, int); | ||
| 62 | int epoll_pwait(int, struct epoll_event *, int, int, const sigset_t *); | ||
| 63 | |||
| 64 | |||
| 65 | #ifdef __cplusplus | ||
| 66 | } | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #endif /* sys/epoll.h */ | ||
lib/libc/wasi/libc-top-half/musl/include/sys/errno.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/errno.h> to <errno.h> | ||
| 2 | #include <errno.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/eventfd.h created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #ifndef _SYS_EVENTFD_H | ||
| 2 | #define _SYS_EVENTFD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | |||
| 11 | typedef uint64_t eventfd_t; | ||
| 12 | |||
| 13 | #define EFD_SEMAPHORE 1 | ||
| 14 | #define EFD_CLOEXEC O_CLOEXEC | ||
| 15 | #define EFD_NONBLOCK O_NONBLOCK | ||
| 16 | |||
| 17 | int eventfd(unsigned int, int); | ||
| 18 | int eventfd_read(int, eventfd_t *); | ||
| 19 | int eventfd_write(int, eventfd_t); | ||
| 20 | |||
| 21 | |||
| 22 | #ifdef __cplusplus | ||
| 23 | } | ||
| 24 | #endif | ||
| 25 | |||
| 26 | #endif /* sys/eventfd.h */ | ||
lib/libc/wasi/libc-top-half/musl/include/sys/fanotify.h created+111| ... | @@ -0,0 +1,111 @@ | ||
| 1 | #ifndef _FANOTIFY_H | ||
| 2 | #define _FANOTIFY_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <sys/statfs.h> | ||
| 9 | |||
| 10 | struct fanotify_event_metadata { | ||
| 11 | 	unsigned event_len; | ||
| 12 | 	unsigned char vers; | ||
| 13 | 	unsigned char reserved; | ||
| 14 | 	unsigned short metadata_len; | ||
| 15 | 	unsigned long long mask | ||
| 16 | #ifdef __GNUC__ | ||
| 17 | 	__attribute__((__aligned__(8))) | ||
| 18 | #endif | ||
| 19 | 	; | ||
| 20 | 	int fd; | ||
| 21 | 	int pid; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct fanotify_event_info_header { | ||
| 25 | 	unsigned char info_type; | ||
| 26 | 	unsigned char pad; | ||
| 27 | 	unsigned short len; | ||
| 28 | }; | ||
| 29 | |||
| 30 | struct fanotify_event_info_fid { | ||
| 31 | 	struct fanotify_event_info_header hdr; | ||
| 32 | 	fsid_t fsid; | ||
| 33 | 	unsigned char handle[]; | ||
| 34 | }; | ||
| 35 | |||
| 36 | struct fanotify_response { | ||
| 37 | 	int fd; | ||
| 38 | 	unsigned response; | ||
| 39 | }; | ||
| 40 | |||
| 41 | #define FAN_ACCESS 0x01 | ||
| 42 | #define FAN_MODIFY 0x02 | ||
| 43 | #define FAN_ATTRIB 0x04 | ||
| 44 | #define FAN_CLOSE_WRITE 0x08 | ||
| 45 | #define FAN_CLOSE_NOWRITE 0x10 | ||
| 46 | #define FAN_OPEN 0x20 | ||
| 47 | #define FAN_MOVED_FROM 0x40 | ||
| 48 | #define FAN_MOVED_TO 0x80 | ||
| 49 | #define FAN_CREATE 0x100 | ||
| 50 | #define FAN_DELETE 0x200 | ||
| 51 | #define FAN_DELETE_SELF 0x400 | ||
| 52 | #define FAN_MOVE_SELF 0x800 | ||
| 53 | #define FAN_OPEN_EXEC 0x1000 | ||
| 54 | #define FAN_Q_OVERFLOW 0x4000 | ||
| 55 | #define FAN_OPEN_PERM 0x10000 | ||
| 56 | #define FAN_ACCESS_PERM 0x20000 | ||
| 57 | #define FAN_OPEN_EXEC_PERM 0x40000 | ||
| 58 | #define FAN_DIR_MODIFY 0x00080000 | ||
| 59 | #define FAN_EVENT_ON_CHILD 0x08000000 | ||
| 60 | #define FAN_ONDIR 0x40000000 | ||
| 61 | #define FAN_CLOSE (FAN_CLOSE_WRITE | FAN_CLOSE_NOWRITE) | ||
| 62 | #define FAN_MOVE (FAN_MOVED_FROM | FAN_MOVED_TO) | ||
| 63 | #define FAN_CLOEXEC 0x01 | ||
| 64 | #define FAN_NONBLOCK 0x02 | ||
| 65 | #define FAN_CLASS_NOTIF 0 | ||
| 66 | #define FAN_CLASS_CONTENT 0x04 | ||
| 67 | #define FAN_CLASS_PRE_CONTENT 0x08 | ||
| 68 | #define FAN_ALL_CLASS_BITS (FAN_CLASS_NOTIF | FAN_CLASS_CONTENT | FAN_CLASS_PRE_CONTENT) | ||
| 69 | #define FAN_UNLIMITED_QUEUE 0x10 | ||
| 70 | #define FAN_UNLIMITED_MARKS 0x20 | ||
| 71 | #define FAN_ENABLE_AUDIT 0x40 | ||
| 72 | #define FAN_REPORT_TID 0x100 | ||
| 73 | #define FAN_REPORT_FID 0x200 | ||
| 74 | #define FAN_REPORT_DIR_FID 0x00000400 | ||
| 75 | #define FAN_REPORT_NAME 0x00000800 | ||
| 76 | #define FAN_REPORT_DFID_NAME (FAN_REPORT_DIR_FID | FAN_REPORT_NAME) | ||
| 77 | #define FAN_ALL_INIT_FLAGS (FAN_CLOEXEC | FAN_NONBLOCK | FAN_ALL_CLASS_BITS | FAN_UNLIMITED_QUEUE | FAN_UNLIMITED_MARKS) | ||
| 78 | #define FAN_MARK_ADD 0x01 | ||
| 79 | #define FAN_MARK_REMOVE 0x02 | ||
| 80 | #define FAN_MARK_DONT_FOLLOW 0x04 | ||
| 81 | #define FAN_MARK_ONLYDIR 0x08 | ||
| 82 | #define FAN_MARK_IGNORED_MASK 0x20 | ||
| 83 | #define FAN_MARK_IGNORED_SURV_MODIFY 0x40 | ||
| 84 | #define FAN_MARK_FLUSH 0x80 | ||
| 85 | #define FAN_MARK_INODE 0x00 | ||
| 86 | #define FAN_MARK_MOUNT 0x10 | ||
| 87 | #define FAN_MARK_FILESYSTEM 0x100 | ||
| 88 | #define FAN_MARK_TYPE_MASK (FAN_MARK_INODE | FAN_MARK_MOUNT | FAN_MARK_FILESYSTEM) | ||
| 89 | #define FAN_ALL_MARK_FLAGS (FAN_MARK_ADD | FAN_MARK_REMOVE | FAN_MARK_DONT_FOLLOW | FAN_MARK_ONLYDIR | FAN_MARK_MOUNT | FAN_MARK_IGNORED_MASK | FAN_MARK_IGNORED_SURV_MODIFY | FAN_MARK_FLUSH) | ||
| 90 | #define FAN_ALL_EVENTS (FAN_ACCESS | FAN_MODIFY | FAN_CLOSE | FAN_OPEN) | ||
| 91 | #define FAN_ALL_PERM_EVENTS (FAN_OPEN_PERM | FAN_ACCESS_PERM) | ||
| 92 | #define FAN_ALL_OUTGOING_EVENTS (FAN_ALL_EVENTS | FAN_ALL_PERM_EVENTS | FAN_Q_OVERFLOW) | ||
| 93 | #define FANOTIFY_METADATA_VERSION 3 | ||
| 94 | #define FAN_EVENT_INFO_TYPE_FID 1 | ||
| 95 | #define FAN_EVENT_INFO_TYPE_DFID_NAME 2 | ||
| 96 | #define FAN_EVENT_INFO_TYPE_DFID 3 | ||
| 97 | #define FAN_ALLOW 0x01 | ||
| 98 | #define FAN_DENY 0x02 | ||
| 99 | #define FAN_AUDIT 0x10 | ||
| 100 | #define FAN_NOFD -1 | ||
| 101 | #define FAN_EVENT_METADATA_LEN (sizeof(struct fanotify_event_metadata)) | ||
| 102 | #define FAN_EVENT_NEXT(meta, len) ((len) -= (meta)->event_len, (struct fanotify_event_metadata*)(((char *)(meta)) + (meta)->event_len)) | ||
| 103 | #define FAN_EVENT_OK(meta, len) ((long)(len) >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len >= (long)FAN_EVENT_METADATA_LEN && (long)(meta)->event_len <= (long)(len)) | ||
| 104 | |||
| 105 | int fanotify_init(unsigned, unsigned); | ||
| 106 | int fanotify_mark(int, unsigned, unsigned long long, int, const char *); | ||
| 107 | |||
| 108 | #ifdef __cplusplus | ||
| 109 | } | ||
| 110 | #endif | ||
| 111 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/fcntl.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/fcntl.h> to <fcntl.h> | ||
| 2 | #include <fcntl.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/file.h created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #ifndef _SYS_FILE_H | ||
| 2 | #define _SYS_FILE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #define LOCK_SH	1 | ||
| 8 | #define LOCK_EX	2 | ||
| 9 | #define LOCK_NB	4 | ||
| 10 | #define LOCK_UN	8 | ||
| 11 | |||
| 12 | #define L_SET 0 | ||
| 13 | #define L_INCR 1 | ||
| 14 | #define L_XTND 2 | ||
| 15 | |||
| 16 | int flock(int, int); | ||
| 17 | |||
| 18 | #ifdef __cplusplus | ||
| 19 | } | ||
| 20 | #endif | ||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/fsuid.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _SYS_FSUID_H | ||
| 2 | #define _SYS_FSUID_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_uid_t | ||
| 9 | #define __NEED_gid_t | ||
| 10 | |||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | int setfsuid(uid_t); | ||
| 14 | int setfsgid(gid_t); | ||
| 15 | |||
| 16 | #ifdef __cplusplus | ||
| 17 | } | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/inotify.h created+58| ... | @@ -0,0 +1,58 @@ | ||
| 1 | #ifndef _SYS_INOTIFY_H | ||
| 2 | #define _SYS_INOTIFY_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | |||
| 11 | struct inotify_event { | ||
| 12 | 	int wd; | ||
| 13 | 	uint32_t mask, cookie, len; | ||
| 14 | 	char name[]; | ||
| 15 | }; | ||
| 16 | |||
| 17 | #define IN_CLOEXEC O_CLOEXEC | ||
| 18 | #define IN_NONBLOCK O_NONBLOCK | ||
| 19 | |||
| 20 | #define IN_ACCESS 0x00000001 | ||
| 21 | #define IN_MODIFY 0x00000002 | ||
| 22 | #define IN_ATTRIB 0x00000004 | ||
| 23 | #define IN_CLOSE_WRITE 0x00000008 | ||
| 24 | #define IN_CLOSE_NOWRITE 0x00000010 | ||
| 25 | #define IN_CLOSE (IN_CLOSE_WRITE | IN_CLOSE_NOWRITE) | ||
| 26 | #define IN_OPEN 0x00000020 | ||
| 27 | #define IN_MOVED_FROM 0x00000040 | ||
| 28 | #define IN_MOVED_TO 0x00000080 | ||
| 29 | #define IN_MOVE (IN_MOVED_FROM | IN_MOVED_TO) | ||
| 30 | #define IN_CREATE 0x00000100 | ||
| 31 | #define IN_DELETE 0x00000200 | ||
| 32 | #define IN_DELETE_SELF 0x00000400 | ||
| 33 | #define IN_MOVE_SELF 0x00000800 | ||
| 34 | #define IN_ALL_EVENTS 0x00000fff | ||
| 35 | |||
| 36 | #define IN_UNMOUNT 0x00002000 | ||
| 37 | #define IN_Q_OVERFLOW 0x00004000 | ||
| 38 | #define IN_IGNORED 0x00008000 | ||
| 39 | |||
| 40 | #define IN_ONLYDIR 0x01000000 | ||
| 41 | #define IN_DONT_FOLLOW 0x02000000 | ||
| 42 | #define IN_EXCL_UNLINK 0x04000000 | ||
| 43 | #define IN_MASK_CREATE 0x10000000 | ||
| 44 | #define IN_MASK_ADD 0x20000000 | ||
| 45 | |||
| 46 | #define IN_ISDIR 0x40000000 | ||
| 47 | #define IN_ONESHOT 0x80000000 | ||
| 48 | |||
| 49 | int inotify_init(void); | ||
| 50 | int inotify_init1(int); | ||
| 51 | int inotify_add_watch(int, const char *, uint32_t); | ||
| 52 | int inotify_rm_watch(int, int); | ||
| 53 | |||
| 54 | #ifdef __cplusplus | ||
| 55 | } | ||
| 56 | #endif | ||
| 57 | |||
| 58 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/io.h created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #ifndef	_SYS_IO_H | ||
| 2 | #define	_SYS_IO_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #include <bits/io.h> | ||
| 10 | |||
| 11 | int iopl(int); | ||
| 12 | int ioperm(unsigned long, unsigned long, int); | ||
| 13 | |||
| 14 | #ifdef __cplusplus | ||
| 15 | } | ||
| 16 | #endif | ||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/ioctl.h created+124| ... | @@ -0,0 +1,124 @@ | ||
| 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/ipc.h created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #ifndef _SYS_IPC_H | ||
| 2 | #define _SYS_IPC_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_uid_t | ||
| 10 | #define __NEED_gid_t | ||
| 11 | #define __NEED_mode_t | ||
| 12 | #define __NEED_key_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #define __ipc_perm_key __key | ||
| 17 | #define __ipc_perm_seq __seq | ||
| 18 | |||
| 19 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 20 | #define __key key | ||
| 21 | #define __seq seq | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include <bits/ipc.h> | ||
| 25 | #include <bits/ipcstat.h> | ||
| 26 | |||
| 27 | #define IPC_CREAT 01000 | ||
| 28 | #define IPC_EXCL 02000 | ||
| 29 | #define IPC_NOWAIT 04000 | ||
| 30 | |||
| 31 | #define IPC_RMID 0 | ||
| 32 | #define IPC_SET 1 | ||
| 33 | #define IPC_INFO 3 | ||
| 34 | |||
| 35 | #define IPC_PRIVATE ((key_t) 0) | ||
| 36 | |||
| 37 | key_t ftok (const char *, int); | ||
| 38 | |||
| 39 | #ifdef __cplusplus | ||
| 40 | } | ||
| 41 | #endif | ||
| 42 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/kd.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <bits/kd.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/klog.h created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #ifndef	_SYS_KLOG_H | ||
| 2 | #define	_SYS_KLOG_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | int klogctl (int, char *, int); | ||
| 9 | |||
| 10 | #ifdef __cplusplus | ||
| 11 | } | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/membarrier.h created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #ifndef _SYS_MEMBARRIER_H | ||
| 2 | #define _SYS_MEMBARRIER_H | ||
| 3 | |||
| 4 | #define MEMBARRIER_CMD_QUERY 0 | ||
| 5 | #define MEMBARRIER_CMD_GLOBAL 1 | ||
| 6 | #define MEMBARRIER_CMD_GLOBAL_EXPEDITED 2 | ||
| 7 | #define MEMBARRIER_CMD_REGISTER_GLOBAL_EXPEDITED 4 | ||
| 8 | #define MEMBARRIER_CMD_PRIVATE_EXPEDITED 8 | ||
| 9 | #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED 16 | ||
| 10 | #define MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 32 | ||
| 11 | #define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE 64 | ||
| 12 | |||
| 13 | #define MEMBARRIER_CMD_SHARED MEMBARRIER_CMD_GLOBAL | ||
| 14 | |||
| 15 | int membarrier(int, int); | ||
| 16 | |||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/mman.h created+156| ... | @@ -0,0 +1,156 @@ | ||
| 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_64KB (16 << 26) | ||
| 48 | #define MAP_HUGE_512KB (19 << 26) | ||
| 49 | #define MAP_HUGE_1MB (20 << 26) | ||
| 50 | #define MAP_HUGE_2MB (21 << 26) | ||
| 51 | #define MAP_HUGE_8MB (23 << 26) | ||
| 52 | #define MAP_HUGE_16MB (24 << 26) | ||
| 53 | #define MAP_HUGE_32MB (25 << 26) | ||
| 54 | #define MAP_HUGE_256MB (28 << 26) | ||
| 55 | #define MAP_HUGE_512MB (29 << 26) | ||
| 56 | #define MAP_HUGE_1GB (30 << 26) | ||
| 57 | #define MAP_HUGE_2GB (31 << 26) | ||
| 58 | #define MAP_HUGE_16GB (34U << 26) | ||
| 59 | |||
| 60 | #define PROT_NONE 0 | ||
| 61 | #define PROT_READ 1 | ||
| 62 | #define PROT_WRITE 2 | ||
| 63 | #define PROT_EXEC 4 | ||
| 64 | #define PROT_GROWSDOWN 0x01000000 | ||
| 65 | #define PROT_GROWSUP 0x02000000 | ||
| 66 | |||
| 67 | #define MS_ASYNC 1 | ||
| 68 | #define MS_INVALIDATE 2 | ||
| 69 | #define MS_SYNC 4 | ||
| 70 | |||
| 71 | #define MCL_CURRENT 1 | ||
| 72 | #define MCL_FUTURE 2 | ||
| 73 | #define MCL_ONFAULT 4 | ||
| 74 | |||
| 75 | #define POSIX_MADV_NORMAL 0 | ||
| 76 | #define POSIX_MADV_RANDOM 1 | ||
| 77 | #define POSIX_MADV_SEQUENTIAL 2 | ||
| 78 | #define POSIX_MADV_WILLNEED 3 | ||
| 79 | #define POSIX_MADV_DONTNEED 4 | ||
| 80 | |||
| 81 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 82 | #define MADV_NORMAL 0 | ||
| 83 | #define MADV_RANDOM 1 | ||
| 84 | #define MADV_SEQUENTIAL 2 | ||
| 85 | #define MADV_WILLNEED 3 | ||
| 86 | #define MADV_DONTNEED 4 | ||
| 87 | #define MADV_FREE 8 | ||
| 88 | #define MADV_REMOVE 9 | ||
| 89 | #define MADV_DONTFORK 10 | ||
| 90 | #define MADV_DOFORK 11 | ||
| 91 | #define MADV_MERGEABLE 12 | ||
| 92 | #define MADV_UNMERGEABLE 13 | ||
| 93 | #define MADV_HUGEPAGE 14 | ||
| 94 | #define MADV_NOHUGEPAGE 15 | ||
| 95 | #define MADV_DONTDUMP 16 | ||
| 96 | #define MADV_DODUMP 17 | ||
| 97 | #define MADV_WIPEONFORK 18 | ||
| 98 | #define MADV_KEEPONFORK 19 | ||
| 99 | #define MADV_COLD 20 | ||
| 100 | #define MADV_PAGEOUT 21 | ||
| 101 | #define MADV_HWPOISON 100 | ||
| 102 | #define MADV_SOFT_OFFLINE 101 | ||
| 103 | #endif | ||
| 104 | |||
| 105 | #ifdef _GNU_SOURCE | ||
| 106 | #define MREMAP_MAYMOVE 1 | ||
| 107 | #define MREMAP_FIXED 2 | ||
| 108 | #define MREMAP_DONTUNMAP 4 | ||
| 109 | |||
| 110 | #define MLOCK_ONFAULT 0x01 | ||
| 111 | |||
| 112 | #define MFD_CLOEXEC 0x0001U | ||
| 113 | #define MFD_ALLOW_SEALING 0x0002U | ||
| 114 | #define MFD_HUGETLB 0x0004U | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #include <bits/mman.h> | ||
| 118 | |||
| 119 | void *mmap (void *, size_t, int, int, int, off_t); | ||
| 120 | int munmap (void *, size_t); | ||
| 121 | |||
| 122 | int mprotect (void *, size_t, int); | ||
| 123 | int msync (void *, size_t, int); | ||
| 124 | |||
| 125 | int posix_madvise (void *, size_t, int); | ||
| 126 | |||
| 127 | int mlock (const void *, size_t); | ||
| 128 | int munlock (const void *, size_t); | ||
| 129 | int mlockall (int); | ||
| 130 | int munlockall (void); | ||
| 131 | |||
| 132 | #ifdef _GNU_SOURCE | ||
| 133 | void *mremap (void *, size_t, size_t, int, ...); | ||
| 134 | int remap_file_pages (void *, size_t, int, size_t, int); | ||
| 135 | int memfd_create (const char *, unsigned); | ||
| 136 | int mlock2 (const void *, size_t, unsigned); | ||
| 137 | #endif | ||
| 138 | |||
| 139 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 140 | int madvise (void *, size_t, int); | ||
| 141 | int mincore (void *, size_t, unsigned char *); | ||
| 142 | #endif | ||
| 143 | |||
| 144 | int shm_open (const char *, int, mode_t); | ||
| 145 | int shm_unlink (const char *); | ||
| 146 | |||
| 147 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 148 | #define mmap64 mmap | ||
| 149 | #define off64_t off_t | ||
| 150 | #endif | ||
| 151 | |||
| 152 | #ifdef __cplusplus | ||
| 153 | } | ||
| 154 | #endif | ||
| 155 | #endif | ||
| 156 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/mount.h created+74| ... | @@ -0,0 +1,74 @@ | ||
| 1 | #ifndef _SYS_MOUNT_H | ||
| 2 | #define _SYS_MOUNT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <sys/ioctl.h> | ||
| 9 | |||
| 10 | #define BLKROSET _IO(0x12, 93) | ||
| 11 | #define BLKROGET _IO(0x12, 94) | ||
| 12 | #define BLKRRPART _IO(0x12, 95) | ||
| 13 | #define BLKGETSIZE _IO(0x12, 96) | ||
| 14 | #define BLKFLSBUF _IO(0x12, 97) | ||
| 15 | #define BLKRASET _IO(0x12, 98) | ||
| 16 | #define BLKRAGET _IO(0x12, 99) | ||
| 17 | #define BLKFRASET _IO(0x12,100) | ||
| 18 | #define BLKFRAGET _IO(0x12,101) | ||
| 19 | #define BLKSECTSET _IO(0x12,102) | ||
| 20 | #define BLKSECTGET _IO(0x12,103) | ||
| 21 | #define BLKSSZGET _IO(0x12,104) | ||
| 22 | #define BLKBSZGET _IOR(0x12,112,size_t) | ||
| 23 | #define BLKBSZSET _IOW(0x12,113,size_t) | ||
| 24 | #define BLKGETSIZE64 _IOR(0x12,114,size_t) | ||
| 25 | |||
| 26 | #define MS_RDONLY 1 | ||
| 27 | #define MS_NOSUID 2 | ||
| 28 | #define MS_NODEV 4 | ||
| 29 | #define MS_NOEXEC 8 | ||
| 30 | #define MS_SYNCHRONOUS 16 | ||
| 31 | #define MS_REMOUNT 32 | ||
| 32 | #define MS_MANDLOCK 64 | ||
| 33 | #define MS_DIRSYNC 128 | ||
| 34 | #define MS_NOATIME 1024 | ||
| 35 | #define MS_NODIRATIME 2048 | ||
| 36 | #define MS_BIND 4096 | ||
| 37 | #define MS_MOVE 8192 | ||
| 38 | #define MS_REC 16384 | ||
| 39 | #define MS_SILENT 32768 | ||
| 40 | #define MS_POSIXACL (1<<16) | ||
| 41 | #define MS_UNBINDABLE (1<<17) | ||
| 42 | #define MS_PRIVATE (1<<18) | ||
| 43 | #define MS_SLAVE (1<<19) | ||
| 44 | #define MS_SHARED (1<<20) | ||
| 45 | #define MS_RELATIME (1<<21) | ||
| 46 | #define MS_KERNMOUNT (1<<22) | ||
| 47 | #define MS_I_VERSION (1<<23) | ||
| 48 | #define MS_STRICTATIME (1<<24) | ||
| 49 | #define MS_LAZYTIME (1<<25) | ||
| 50 | #define MS_NOREMOTELOCK (1<<27) | ||
| 51 | #define MS_NOSEC (1<<28) | ||
| 52 | #define MS_BORN (1<<29) | ||
| 53 | #define MS_ACTIVE (1<<30) | ||
| 54 | #define MS_NOUSER (1U<<31) | ||
| 55 | |||
| 56 | #define MS_RMT_MASK (MS_RDONLY|MS_SYNCHRONOUS|MS_MANDLOCK|MS_I_VERSION|MS_LAZYTIME) | ||
| 57 | |||
| 58 | #define MS_MGC_VAL 0xc0ed0000 | ||
| 59 | #define MS_MGC_MSK 0xffff0000 | ||
| 60 | |||
| 61 | #define MNT_FORCE 1 | ||
| 62 | #define MNT_DETACH 2 | ||
| 63 | #define MNT_EXPIRE 4 | ||
| 64 | #define UMOUNT_NOFOLLOW 8 | ||
| 65 | |||
| 66 | int mount(const char *, const char *, const char *, unsigned long, const void *); | ||
| 67 | int umount(const char *); | ||
| 68 | int umount2(const char *, int); | ||
| 69 | |||
| 70 | #ifdef __cplusplus | ||
| 71 | } | ||
| 72 | #endif | ||
| 73 | |||
| 74 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/msg.h created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | #ifndef _SYS_MSG_H | ||
| 2 | #define _SYS_MSG_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <sys/ipc.h> | ||
| 9 | |||
| 10 | #define __NEED_pid_t | ||
| 11 | #define __NEED_key_t | ||
| 12 | #define __NEED_time_t | ||
| 13 | #define __NEED_size_t | ||
| 14 | #define __NEED_ssize_t | ||
| 15 | |||
| 16 | #include <bits/alltypes.h> | ||
| 17 | |||
| 18 | typedef unsigned long msgqnum_t; | ||
| 19 | typedef unsigned long msglen_t; | ||
| 20 | |||
| 21 | #include <bits/msg.h> | ||
| 22 | |||
| 23 | #define __msg_cbytes msg_cbytes | ||
| 24 | |||
| 25 | #define MSG_NOERROR 010000 | ||
| 26 | #define MSG_EXCEPT 020000 | ||
| 27 | |||
| 28 | #define MSG_STAT (11 | (IPC_STAT & 0x100)) | ||
| 29 | #define MSG_INFO 12 | ||
| 30 | #define MSG_STAT_ANY (13 | (IPC_STAT & 0x100)) | ||
| 31 | |||
| 32 | struct msginfo { | ||
| 33 | 	int msgpool, msgmap, msgmax, msgmnb, msgmni, msgssz, msgtql; | ||
| 34 | 	unsigned short msgseg; | ||
| 35 | }; | ||
| 36 | |||
| 37 | int msgctl (int, int, struct msqid_ds *); | ||
| 38 | int msgget (key_t, int); | ||
| 39 | ssize_t msgrcv (int, void *, size_t, long, int); | ||
| 40 | int msgsnd (int, const void *, size_t, int); | ||
| 41 | |||
| 42 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 43 | struct msgbuf { | ||
| 44 | 	long mtype; | ||
| 45 | 	char mtext[1]; | ||
| 46 | }; | ||
| 47 | #endif | ||
| 48 | |||
| 49 | #ifdef __cplusplus | ||
| 50 | } | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/mtio.h created+188| ... | @@ -0,0 +1,188 @@ | ||
| 1 | #ifndef _SYS_MTIO_H | ||
| 2 | #define _SYS_MTIO_H | ||
| 3 | |||
| 4 | #include <sys/types.h> | ||
| 5 | #include <sys/ioctl.h> | ||
| 6 | |||
| 7 | struct mtop { | ||
| 8 | 	short mt_op; | ||
| 9 | 	int mt_count; | ||
| 10 | }; | ||
| 11 | |||
| 12 | #define _IOT_mtop _IOT (_IOTS (short), 1, _IOTS (int), 1, 0, 0) | ||
| 13 | #define _IOT_mtget _IOT (_IOTS (long), 7, 0, 0, 0, 0) | ||
| 14 | #define _IOT_mtpos _IOT_SIMPLE (long) | ||
| 15 | #define _IOT_mtconfiginfo _IOT (_IOTS (long), 2, _IOTS (short), 3, _IOTS (long), 1) | ||
| 16 | |||
| 17 | |||
| 18 | #define MTRESET 0 | ||
| 19 | #define MTFSF	1 | ||
| 20 | #define MTBSF	2 | ||
| 21 | #define MTFSR	3 | ||
| 22 | #define MTBSR	4 | ||
| 23 | #define MTWEOF	5 | ||
| 24 | #define MTREW	6 | ||
| 25 | #define MTOFFL	7 | ||
| 26 | #define MTNOP	8 | ||
| 27 | #define MTRETEN 9 | ||
| 28 | #define MTBSFM	10 | ||
| 29 | #define MTFSFM 11 | ||
| 30 | #define MTEOM	12 | ||
| 31 | #define MTERASE 13 | ||
| 32 | #define MTRAS1 14 | ||
| 33 | #define MTRAS2	15 | ||
| 34 | #define MTRAS3 16 | ||
| 35 | #define MTSETBLK 20 | ||
| 36 | #define MTSETDENSITY 21 | ||
| 37 | #define MTSEEK	22 | ||
| 38 | #define MTTELL	23 | ||
| 39 | #define MTSETDRVBUFFER 24 | ||
| 40 | #define MTFSS	25 | ||
| 41 | #define MTBSS	26 | ||
| 42 | #define MTWSM	27 | ||
| 43 | #define MTLOCK 28 | ||
| 44 | #define MTUNLOCK 29 | ||
| 45 | #define MTLOAD 30 | ||
| 46 | #define MTUNLOAD 31 | ||
| 47 | #define MTCOMPRESSION 32 | ||
| 48 | #define MTSETPART 33 | ||
| 49 | #define MTMKPART 34 | ||
| 50 | |||
| 51 | struct mtget { | ||
| 52 | 	long mt_type; | ||
| 53 | 	long mt_resid; | ||
| 54 | 	long mt_dsreg; | ||
| 55 | 	long mt_gstat; | ||
| 56 | 	long mt_erreg; | ||
| 57 | 	int mt_fileno; | ||
| 58 | 	int mt_blkno; | ||
| 59 | }; | ||
| 60 | |||
| 61 | #define MT_ISUNKNOWN		0x01 | ||
| 62 | #define MT_ISQIC02		0x02 | ||
| 63 | #define MT_ISWT5150		0x03 | ||
| 64 | #define MT_ISARCHIVE_5945L2	0x04 | ||
| 65 | #define MT_ISCMSJ500		0x05 | ||
| 66 | #define MT_ISTDC3610		0x06 | ||
| 67 | #define MT_ISARCHIVE_VP60I	0x07 | ||
| 68 | #define MT_ISARCHIVE_2150L	0x08 | ||
| 69 | #define MT_ISARCHIVE_2060L	0x09 | ||
| 70 | #define MT_ISARCHIVESC499	0x0A | ||
| 71 | #define MT_ISQIC02_ALL_FEATURES	0x0F | ||
| 72 | #define MT_ISWT5099EEN24	0x11 | ||
| 73 | #define MT_ISTEAC_MT2ST		0x12 | ||
| 74 | #define MT_ISEVEREX_FT40A	0x32 | ||
| 75 | #define MT_ISDDS1		0x51 | ||
| 76 | #define MT_ISDDS2		0x52 | ||
| 77 | #define MT_ISSCSI1		0x71 | ||
| 78 | #define MT_ISSCSI2		0x72 | ||
| 79 | #define MT_ISFTAPE_UNKNOWN	0x800000 | ||
| 80 | #define MT_ISFTAPE_FLAG		0x800000 | ||
| 81 | |||
| 82 | struct mt_tape_info { | ||
| 83 | 	long t_type; | ||
| 84 | 	char *t_name; | ||
| 85 | }; | ||
| 86 | |||
| 87 | #define MT_TAPE_INFO \ | ||
| 88 | {									 \ | ||
| 89 | 	{MT_ISUNKNOWN,		"Unknown type of tape device"},		 \ | ||
| 90 | 	{MT_ISQIC02,		"Generic QIC-02 tape streamer"},	 \ | ||
| 91 | 	{MT_ISWT5150,		"Wangtek 5150, QIC-150"},		 \ | ||
| 92 | 	{MT_ISARCHIVE_5945L2,	"Archive 5945L-2"},			 \ | ||
| 93 | 	{MT_ISCMSJ500,		"CMS Jumbo 500"},			 \ | ||
| 94 | 	{MT_ISTDC3610,		"Tandberg TDC 3610, QIC-24"},		 \ | ||
| 95 | 	{MT_ISARCHIVE_VP60I,	"Archive VP60i, QIC-02"},		 \ | ||
| 96 | 	{MT_ISARCHIVE_2150L,	"Archive Viper 2150L"},			 \ | ||
| 97 | 	{MT_ISARCHIVE_2060L,	"Archive Viper 2060L"},			 \ | ||
| 98 | 	{MT_ISARCHIVESC499,	"Archive SC-499 QIC-36 controller"},	 \ | ||
| 99 | 	{MT_ISQIC02_ALL_FEATURES, "Generic QIC-02 tape, all features"},	 \ | ||
| 100 | 	{MT_ISWT5099EEN24,	"Wangtek 5099-een24, 60MB"},		 \ | ||
| 101 | 	{MT_ISTEAC_MT2ST,	"Teac MT-2ST 155mb data cassette drive"}, \ | ||
| 102 | 	{MT_ISEVEREX_FT40A,	"Everex FT40A, QIC-40"},		 \ | ||
| 103 | 	{MT_ISSCSI1,		"Generic SCSI-1 tape"},			 \ | ||
| 104 | 	{MT_ISSCSI2,		"Generic SCSI-2 tape"},			 \ | ||
| 105 | 	{0, 0}								 \ | ||
| 106 | } | ||
| 107 | |||
| 108 | struct mtpos { | ||
| 109 | 	long mt_blkno; | ||
| 110 | }; | ||
| 111 | |||
| 112 | struct mtconfiginfo { | ||
| 113 | 	long mt_type; | ||
| 114 | 	long ifc_type; | ||
| 115 | 	unsigned short irqnr; | ||
| 116 | 	unsigned short dmanr; | ||
| 117 | 	unsigned short port; | ||
| 118 | 	unsigned long debug; | ||
| 119 | 	unsigned have_dens:1; | ||
| 120 | 	unsigned have_bsf:1; | ||
| 121 | 	unsigned have_fsr:1; | ||
| 122 | 	unsigned have_bsr:1; | ||
| 123 | 	unsigned have_eod:1; | ||
| 124 | 	unsigned have_seek:1; | ||
| 125 | 	unsigned have_tell:1; | ||
| 126 | 	unsigned have_ras1:1; | ||
| 127 | 	unsigned have_ras2:1; | ||
| 128 | 	unsigned have_ras3:1; | ||
| 129 | 	unsigned have_qfa:1; | ||
| 130 | 	unsigned pad1:5; | ||
| 131 | 	char reserved[10]; | ||
| 132 | }; | ||
| 133 | |||
| 134 | #define	MTIOCTOP _IOW('m', 1, struct mtop) | ||
| 135 | #define	MTIOCGET _IOR('m', 2, struct mtget) | ||
| 136 | #define	MTIOCPOS _IOR('m', 3, struct mtpos) | ||
| 137 | |||
| 138 | #define	MTIOCGETCONFIG	_IOR('m', 4, struct mtconfiginfo) | ||
| 139 | #define	MTIOCSETCONFIG	_IOW('m', 5, struct mtconfiginfo) | ||
| 140 | |||
| 141 | #define GMT_EOF(x) ((x) & 0x80000000) | ||
| 142 | #define GMT_BOT(x) ((x) & 0x40000000) | ||
| 143 | #define GMT_EOT(x) ((x) & 0x20000000) | ||
| 144 | #define GMT_SM(x) ((x) & 0x10000000) | ||
| 145 | #define GMT_EOD(x) ((x) & 0x08000000) | ||
| 146 | #define GMT_WR_PROT(x) ((x) & 0x04000000) | ||
| 147 | #define GMT_ONLINE(x) ((x) & 0x01000000) | ||
| 148 | #define GMT_D_6250(x) ((x) & 0x00800000) | ||
| 149 | #define GMT_D_1600(x) ((x) & 0x00400000) | ||
| 150 | #define GMT_D_800(x) ((x) & 0x00200000) | ||
| 151 | #define GMT_DR_OPEN(x) ((x) & 0x00040000) | ||
| 152 | #define GMT_IM_REP_EN(x) ((x) & 0x00010000) | ||
| 153 | |||
| 154 | #define MT_ST_BLKSIZE_SHIFT	0 | ||
| 155 | #define MT_ST_BLKSIZE_MASK	0xffffff | ||
| 156 | #define MT_ST_DENSITY_SHIFT	24 | ||
| 157 | #define MT_ST_DENSITY_MASK	0xff000000 | ||
| 158 | #define MT_ST_SOFTERR_SHIFT	0 | ||
| 159 | #define MT_ST_SOFTERR_MASK	0xffff | ||
| 160 | #define MT_ST_OPTIONS		0xf0000000 | ||
| 161 | #define MT_ST_BOOLEANS		0x10000000 | ||
| 162 | #define MT_ST_SETBOOLEANS	0x30000000 | ||
| 163 | #define MT_ST_CLEARBOOLEANS	0x40000000 | ||
| 164 | #define MT_ST_WRITE_THRESHOLD	0x20000000 | ||
| 165 | #define MT_ST_DEF_BLKSIZE	0x50000000 | ||
| 166 | #define MT_ST_DEF_OPTIONS	0x60000000 | ||
| 167 | #define MT_ST_BUFFER_WRITES	0x1 | ||
| 168 | #define MT_ST_ASYNC_WRITES	0x2 | ||
| 169 | #define MT_ST_READ_AHEAD	0x4 | ||
| 170 | #define MT_ST_DEBUGGING		0x8 | ||
| 171 | #define MT_ST_TWO_FM		0x10 | ||
| 172 | #define MT_ST_FAST_MTEOM	0x20 | ||
| 173 | #define MT_ST_AUTO_LOCK		0x40 | ||
| 174 | #define MT_ST_DEF_WRITES	0x80 | ||
| 175 | #define MT_ST_CAN_BSR		0x100 | ||
| 176 | #define MT_ST_NO_BLKLIMS	0x200 | ||
| 177 | #define MT_ST_CAN_PARTITIONS 0x400 | ||
| 178 | #define MT_ST_SCSI2LOGICAL 0x800 | ||
| 179 | #define MT_ST_CLEAR_DEFAULT	0xfffff | ||
| 180 | #define MT_ST_DEF_DENSITY	(MT_ST_DEF_OPTIONS | 0x100000) | ||
| 181 | #define MT_ST_DEF_COMPRESSION	(MT_ST_DEF_OPTIONS | 0x200000) | ||
| 182 | #define MT_ST_DEF_DRVBUFFER	(MT_ST_DEF_OPTIONS | 0x300000) | ||
| 183 | #define MT_ST_HPLOADER_OFFSET 10000 | ||
| 184 | #ifndef DEFTAPE | ||
| 185 | # define DEFTAPE	"/dev/tape" | ||
| 186 | #endif | ||
| 187 | |||
| 188 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/param.h created+37| ... | @@ -0,0 +1,37 @@ | ||
| 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/personality.h created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #ifndef _PERSONALITY_H | ||
| 2 | #define _PERSONALITY_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define UNAME26 0x0020000 | ||
| 9 | #define ADDR_NO_RANDOMIZE 0x0040000 | ||
| 10 | #define FDPIC_FUNCPTRS 0x0080000 | ||
| 11 | #define MMAP_PAGE_ZERO 0x0100000 | ||
| 12 | #define ADDR_COMPAT_LAYOUT 0x0200000 | ||
| 13 | #define READ_IMPLIES_EXEC 0x0400000 | ||
| 14 | #define ADDR_LIMIT_32BIT 0x0800000 | ||
| 15 | #define SHORT_INODE 0x1000000 | ||
| 16 | #define WHOLE_SECONDS 0x2000000 | ||
| 17 | #define STICKY_TIMEOUTS 0x4000000 | ||
| 18 | #define ADDR_LIMIT_3GB 0x8000000 | ||
| 19 | |||
| 20 | #define PER_LINUX 0 | ||
| 21 | #define PER_LINUX_32BIT ADDR_LIMIT_32BIT | ||
| 22 | #define PER_LINUX_FDPIC FDPIC_FUNCPTRS | ||
| 23 | #define PER_SVR4 (1 | STICKY_TIMEOUTS | MMAP_PAGE_ZERO) | ||
| 24 | #define PER_SVR3 (2 | STICKY_TIMEOUTS | SHORT_INODE) | ||
| 25 | #define PER_SCOSVR3 (3 | STICKY_TIMEOUTS | WHOLE_SECONDS | SHORT_INODE) | ||
| 26 | #define PER_OSR5 (3 | STICKY_TIMEOUTS | WHOLE_SECONDS) | ||
| 27 | #define PER_WYSEV386 (4 | STICKY_TIMEOUTS | SHORT_INODE) | ||
| 28 | #define PER_ISCR4 (5 | STICKY_TIMEOUTS) | ||
| 29 | #define PER_BSD 6 | ||
| 30 | #define PER_SUNOS (6 | STICKY_TIMEOUTS) | ||
| 31 | #define PER_XENIX (7 | STICKY_TIMEOUTS | SHORT_INODE) | ||
| 32 | #define PER_LINUX32 8 | ||
| 33 | #define PER_LINUX32_3GB (8 | ADDR_LIMIT_3GB) | ||
| 34 | #define PER_IRIX32 (9 | STICKY_TIMEOUTS) | ||
| 35 | #define PER_IRIXN32 (0xa | STICKY_TIMEOUTS) | ||
| 36 | #define PER_IRIX64 (0x0b | STICKY_TIMEOUTS) | ||
| 37 | #define PER_RISCOS 0xc | ||
| 38 | #define PER_SOLARIS (0xd | STICKY_TIMEOUTS) | ||
| 39 | #define PER_UW7 (0xe | STICKY_TIMEOUTS | MMAP_PAGE_ZERO) | ||
| 40 | #define PER_OSF4 0xf | ||
| 41 | #define PER_HPUX 0x10 | ||
| 42 | #define PER_MASK 0xff | ||
| 43 | |||
| 44 | int personality(unsigned long); | ||
| 45 | |||
| 46 | #ifdef __cplusplus | ||
| 47 | } | ||
| 48 | #endif | ||
| 49 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/poll.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/poll.h> to <poll.h> | ||
| 2 | #include <poll.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/prctl.h created+170| ... | @@ -0,0 +1,170 @@ | ||
| 1 | #ifndef _SYS_PRCTL_H | ||
| 2 | #define _SYS_PRCTL_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | |||
| 10 | #define PR_SET_PDEATHSIG 1 | ||
| 11 | #define PR_GET_PDEATHSIG 2 | ||
| 12 | #define PR_GET_DUMPABLE 3 | ||
| 13 | #define PR_SET_DUMPABLE 4 | ||
| 14 | #define PR_GET_UNALIGN 5 | ||
| 15 | #define PR_SET_UNALIGN 6 | ||
| 16 | #define PR_UNALIGN_NOPRINT 1 | ||
| 17 | #define PR_UNALIGN_SIGBUS 2 | ||
| 18 | #define PR_GET_KEEPCAPS 7 | ||
| 19 | #define PR_SET_KEEPCAPS 8 | ||
| 20 | #define PR_GET_FPEMU 9 | ||
| 21 | #define PR_SET_FPEMU 10 | ||
| 22 | #define PR_FPEMU_NOPRINT 1 | ||
| 23 | #define PR_FPEMU_SIGFPE 2 | ||
| 24 | #define PR_GET_FPEXC 11 | ||
| 25 | #define PR_SET_FPEXC 12 | ||
| 26 | #define PR_FP_EXC_SW_ENABLE 0x80 | ||
| 27 | #define PR_FP_EXC_DIV 0x010000 | ||
| 28 | #define PR_FP_EXC_OVF 0x020000 | ||
| 29 | #define PR_FP_EXC_UND 0x040000 | ||
| 30 | #define PR_FP_EXC_RES 0x080000 | ||
| 31 | #define PR_FP_EXC_INV 0x100000 | ||
| 32 | #define PR_FP_EXC_DISABLED 0 | ||
| 33 | #define PR_FP_EXC_NONRECOV 1 | ||
| 34 | #define PR_FP_EXC_ASYNC 2 | ||
| 35 | #define PR_FP_EXC_PRECISE 3 | ||
| 36 | #define PR_GET_TIMING 13 | ||
| 37 | #define PR_SET_TIMING 14 | ||
| 38 | #define PR_TIMING_STATISTICAL 0 | ||
| 39 | #define PR_TIMING_TIMESTAMP 1 | ||
| 40 | #define PR_SET_NAME 15 | ||
| 41 | #define PR_GET_NAME 16 | ||
| 42 | #define PR_GET_ENDIAN 19 | ||
| 43 | #define PR_SET_ENDIAN 20 | ||
| 44 | #define PR_ENDIAN_BIG 0 | ||
| 45 | #define PR_ENDIAN_LITTLE 1 | ||
| 46 | #define PR_ENDIAN_PPC_LITTLE 2 | ||
| 47 | #define PR_GET_SECCOMP 21 | ||
| 48 | #define PR_SET_SECCOMP 22 | ||
| 49 | #define PR_CAPBSET_READ 23 | ||
| 50 | #define PR_CAPBSET_DROP 24 | ||
| 51 | #define PR_GET_TSC 25 | ||
| 52 | #define PR_SET_TSC 26 | ||
| 53 | #define PR_TSC_ENABLE 1 | ||
| 54 | #define PR_TSC_SIGSEGV 2 | ||
| 55 | #define PR_GET_SECUREBITS 27 | ||
| 56 | #define PR_SET_SECUREBITS 28 | ||
| 57 | #define PR_SET_TIMERSLACK 29 | ||
| 58 | #define PR_GET_TIMERSLACK 30 | ||
| 59 | |||
| 60 | #define PR_TASK_PERF_EVENTS_DISABLE 31 | ||
| 61 | #define PR_TASK_PERF_EVENTS_ENABLE 32 | ||
| 62 | |||
| 63 | #define PR_MCE_KILL 33 | ||
| 64 | #define PR_MCE_KILL_CLEAR 0 | ||
| 65 | #define PR_MCE_KILL_SET 1 | ||
| 66 | #define PR_MCE_KILL_LATE 0 | ||
| 67 | #define PR_MCE_KILL_EARLY 1 | ||
| 68 | #define PR_MCE_KILL_DEFAULT 2 | ||
| 69 | #define PR_MCE_KILL_GET 34 | ||
| 70 | |||
| 71 | #define PR_SET_MM 35 | ||
| 72 | #define PR_SET_MM_START_CODE 1 | ||
| 73 | #define PR_SET_MM_END_CODE 2 | ||
| 74 | #define PR_SET_MM_START_DATA 3 | ||
| 75 | #define PR_SET_MM_END_DATA 4 | ||
| 76 | #define PR_SET_MM_START_STACK 5 | ||
| 77 | #define PR_SET_MM_START_BRK 6 | ||
| 78 | #define PR_SET_MM_BRK 7 | ||
| 79 | #define PR_SET_MM_ARG_START 8 | ||
| 80 | #define PR_SET_MM_ARG_END 9 | ||
| 81 | #define PR_SET_MM_ENV_START 10 | ||
| 82 | #define PR_SET_MM_ENV_END 11 | ||
| 83 | #define PR_SET_MM_AUXV 12 | ||
| 84 | #define PR_SET_MM_EXE_FILE 13 | ||
| 85 | #define PR_SET_MM_MAP 14 | ||
| 86 | #define PR_SET_MM_MAP_SIZE 15 | ||
| 87 | |||
| 88 | struct prctl_mm_map { | ||
| 89 | 	uint64_t start_code; | ||
| 90 | 	uint64_t end_code; | ||
| 91 | 	uint64_t start_data; | ||
| 92 | 	uint64_t end_data; | ||
| 93 | 	uint64_t start_brk; | ||
| 94 | 	uint64_t brk; | ||
| 95 | 	uint64_t start_stack; | ||
| 96 | 	uint64_t arg_start; | ||
| 97 | 	uint64_t arg_end; | ||
| 98 | 	uint64_t env_start; | ||
| 99 | 	uint64_t env_end; | ||
| 100 | 	uint64_t *auxv; | ||
| 101 | 	uint32_t auxv_size; | ||
| 102 | 	uint32_t exe_fd; | ||
| 103 | }; | ||
| 104 | |||
| 105 | #define PR_SET_PTRACER 0x59616d61 | ||
| 106 | #define PR_SET_PTRACER_ANY (-1UL) | ||
| 107 | |||
| 108 | #define PR_SET_CHILD_SUBREAPER 36 | ||
| 109 | #define PR_GET_CHILD_SUBREAPER 37 | ||
| 110 | |||
| 111 | #define PR_SET_NO_NEW_PRIVS 38 | ||
| 112 | #define PR_GET_NO_NEW_PRIVS 39 | ||
| 113 | |||
| 114 | #define PR_GET_TID_ADDRESS 40 | ||
| 115 | |||
| 116 | #define PR_SET_THP_DISABLE 41 | ||
| 117 | #define PR_GET_THP_DISABLE 42 | ||
| 118 | |||
| 119 | #define PR_MPX_ENABLE_MANAGEMENT 43 | ||
| 120 | #define PR_MPX_DISABLE_MANAGEMENT 44 | ||
| 121 | |||
| 122 | #define PR_SET_FP_MODE 45 | ||
| 123 | #define PR_GET_FP_MODE 46 | ||
| 124 | #define PR_FP_MODE_FR (1 << 0) | ||
| 125 | #define PR_FP_MODE_FRE (1 << 1) | ||
| 126 | |||
| 127 | #define PR_CAP_AMBIENT 47 | ||
| 128 | #define PR_CAP_AMBIENT_IS_SET 1 | ||
| 129 | #define PR_CAP_AMBIENT_RAISE 2 | ||
| 130 | #define PR_CAP_AMBIENT_LOWER 3 | ||
| 131 | #define PR_CAP_AMBIENT_CLEAR_ALL 4 | ||
| 132 | |||
| 133 | #define PR_SVE_SET_VL 50 | ||
| 134 | #define PR_SVE_SET_VL_ONEXEC (1 << 18) | ||
| 135 | #define PR_SVE_GET_VL 51 | ||
| 136 | #define PR_SVE_VL_LEN_MASK 0xffff | ||
| 137 | #define PR_SVE_VL_INHERIT (1 << 17) | ||
| 138 | |||
| 139 | #define PR_GET_SPECULATION_CTRL 52 | ||
| 140 | #define PR_SET_SPECULATION_CTRL 53 | ||
| 141 | #define PR_SPEC_STORE_BYPASS 0 | ||
| 142 | #define PR_SPEC_INDIRECT_BRANCH 1 | ||
| 143 | #define PR_SPEC_NOT_AFFECTED 0 | ||
| 144 | #define PR_SPEC_PRCTL (1UL << 0) | ||
| 145 | #define PR_SPEC_ENABLE (1UL << 1) | ||
| 146 | #define PR_SPEC_DISABLE (1UL << 2) | ||
| 147 | #define PR_SPEC_FORCE_DISABLE (1UL << 3) | ||
| 148 | #define PR_SPEC_DISABLE_NOEXEC (1UL << 4) | ||
| 149 | |||
| 150 | #define PR_PAC_RESET_KEYS 54 | ||
| 151 | #define PR_PAC_APIAKEY (1UL << 0) | ||
| 152 | #define PR_PAC_APIBKEY (1UL << 1) | ||
| 153 | #define PR_PAC_APDAKEY (1UL << 2) | ||
| 154 | #define PR_PAC_APDBKEY (1UL << 3) | ||
| 155 | #define PR_PAC_APGAKEY (1UL << 4) | ||
| 156 | |||
| 157 | #define PR_SET_TAGGED_ADDR_CTRL 55 | ||
| 158 | #define PR_GET_TAGGED_ADDR_CTRL 56 | ||
| 159 | #define PR_TAGGED_ADDR_ENABLE (1UL << 0) | ||
| 160 | |||
| 161 | #define PR_SET_IO_FLUSHER 57 | ||
| 162 | #define PR_GET_IO_FLUSHER 58 | ||
| 163 | |||
| 164 | int prctl (int, ...); | ||
| 165 | |||
| 166 | #ifdef __cplusplus | ||
| 167 | } | ||
| 168 | #endif | ||
| 169 | |||
| 170 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/procfs.h created+63| ... | @@ -0,0 +1,63 @@ | ||
| 1 | #ifndef _SYS_PROCFS_H | ||
| 2 | #define _SYS_PROCFS_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <sys/time.h> | ||
| 8 | #include <sys/types.h> | ||
| 9 | #include <sys/user.h> | ||
| 10 | |||
| 11 | struct elf_siginfo { | ||
| 12 | 	int si_signo; | ||
| 13 | 	int si_code; | ||
| 14 | 	int si_errno; | ||
| 15 | }; | ||
| 16 | |||
| 17 | struct elf_prstatus { | ||
| 18 | 	struct elf_siginfo pr_info; | ||
| 19 | 	short int pr_cursig; | ||
| 20 | 	unsigned long int pr_sigpend; | ||
| 21 | 	unsigned long int pr_sighold; | ||
| 22 | 	pid_t pr_pid; | ||
| 23 | 	pid_t pr_ppid; | ||
| 24 | 	pid_t pr_pgrp; | ||
| 25 | 	pid_t pr_sid; | ||
| 26 | 	struct { | ||
| 27 | 		long tv_sec, tv_usec; | ||
| 28 | 	} pr_utime, pr_stime, pr_cutime, pr_cstime; | ||
| 29 | 	elf_gregset_t pr_reg; | ||
| 30 | 	int pr_fpvalid; | ||
| 31 | }; | ||
| 32 | |||
| 33 | #define ELF_PRARGSZ 80 | ||
| 34 | |||
| 35 | struct elf_prpsinfo { | ||
| 36 | 	char pr_state; | ||
| 37 | 	char pr_sname; | ||
| 38 | 	char pr_zomb; | ||
| 39 | 	char pr_nice; | ||
| 40 | 	unsigned long int pr_flag; | ||
| 41 | #if UINTPTR_MAX == 0xffffffff | ||
| 42 | 	unsigned short int pr_uid; | ||
| 43 | 	unsigned short int pr_gid; | ||
| 44 | #else | ||
| 45 | 	unsigned int pr_uid; | ||
| 46 | 	unsigned int pr_gid; | ||
| 47 | #endif | ||
| 48 | 	int pr_pid, pr_ppid, pr_pgrp, pr_sid; | ||
| 49 | 	char pr_fname[16]; | ||
| 50 | 	char pr_psargs[ELF_PRARGSZ]; | ||
| 51 | }; | ||
| 52 | |||
| 53 | typedef void *psaddr_t; | ||
| 54 | typedef elf_gregset_t prgregset_t; | ||
| 55 | typedef elf_fpregset_t prfpregset_t; | ||
| 56 | typedef pid_t lwpid_t; | ||
| 57 | typedef struct elf_prstatus prstatus_t; | ||
| 58 | typedef struct elf_prpsinfo prpsinfo_t; | ||
| 59 | |||
| 60 | #ifdef __cplusplus | ||
| 61 | } | ||
| 62 | #endif | ||
| 63 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/ptrace.h created+138| ... | @@ -0,0 +1,138 @@ | ||
| 1 | #ifndef _SYS_PTRACE_H | ||
| 2 | #define _SYS_PTRACE_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <stdint.h> | ||
| 8 | |||
| 9 | #define PTRACE_TRACEME 0 | ||
| 10 | #define PT_TRACE_ME PTRACE_TRACEME | ||
| 11 | |||
| 12 | #define PTRACE_PEEKTEXT 1 | ||
| 13 | #define PTRACE_PEEKDATA 2 | ||
| 14 | #define PTRACE_PEEKUSER 3 | ||
| 15 | #define PTRACE_POKETEXT 4 | ||
| 16 | #define PTRACE_POKEDATA 5 | ||
| 17 | #define PTRACE_POKEUSER 6 | ||
| 18 | #define PTRACE_CONT 7 | ||
| 19 | #define PTRACE_KILL 8 | ||
| 20 | #define PTRACE_SINGLESTEP 9 | ||
| 21 | #define PTRACE_GETREGS 12 | ||
| 22 | #define PTRACE_SETREGS 13 | ||
| 23 | #define PTRACE_GETFPREGS 14 | ||
| 24 | #define PTRACE_SETFPREGS 15 | ||
| 25 | #define PTRACE_ATTACH 16 | ||
| 26 | #define PTRACE_DETACH 17 | ||
| 27 | #define PTRACE_GETFPXREGS 18 | ||
| 28 | #define PTRACE_SETFPXREGS 19 | ||
| 29 | #define PTRACE_SYSCALL 24 | ||
| 30 | #define PTRACE_SETOPTIONS 0x4200 | ||
| 31 | #define PTRACE_GETEVENTMSG 0x4201 | ||
| 32 | #define PTRACE_GETSIGINFO 0x4202 | ||
| 33 | #define PTRACE_SETSIGINFO 0x4203 | ||
| 34 | #define PTRACE_GETREGSET 0x4204 | ||
| 35 | #define PTRACE_SETREGSET 0x4205 | ||
| 36 | #define PTRACE_SEIZE 0x4206 | ||
| 37 | #define PTRACE_INTERRUPT 0x4207 | ||
| 38 | #define PTRACE_LISTEN 0x4208 | ||
| 39 | #define PTRACE_PEEKSIGINFO 0x4209 | ||
| 40 | #define PTRACE_GETSIGMASK 0x420a | ||
| 41 | #define PTRACE_SETSIGMASK 0x420b | ||
| 42 | #define PTRACE_SECCOMP_GET_FILTER 0x420c | ||
| 43 | #define PTRACE_SECCOMP_GET_METADATA 0x420d | ||
| 44 | #define PTRACE_GET_SYSCALL_INFO 0x420e | ||
| 45 | |||
| 46 | #define PT_READ_I PTRACE_PEEKTEXT | ||
| 47 | #define PT_READ_D PTRACE_PEEKDATA | ||
| 48 | #define PT_READ_U PTRACE_PEEKUSER | ||
| 49 | #define PT_WRITE_I PTRACE_POKETEXT | ||
| 50 | #define PT_WRITE_D PTRACE_POKEDATA | ||
| 51 | #define PT_WRITE_U PTRACE_POKEUSER | ||
| 52 | #define PT_CONTINUE PTRACE_CONT | ||
| 53 | #define PT_KILL PTRACE_KILL | ||
| 54 | #define PT_STEP PTRACE_SINGLESTEP | ||
| 55 | #define PT_GETREGS PTRACE_GETREGS | ||
| 56 | #define PT_SETREGS PTRACE_SETREGS | ||
| 57 | #define PT_GETFPREGS PTRACE_GETFPREGS | ||
| 58 | #define PT_SETFPREGS PTRACE_SETFPREGS | ||
| 59 | #define PT_ATTACH PTRACE_ATTACH | ||
| 60 | #define PT_DETACH PTRACE_DETACH | ||
| 61 | #define PT_GETFPXREGS PTRACE_GETFPXREGS | ||
| 62 | #define PT_SETFPXREGS PTRACE_SETFPXREGS | ||
| 63 | #define PT_SYSCALL PTRACE_SYSCALL | ||
| 64 | #define PT_SETOPTIONS PTRACE_SETOPTIONS | ||
| 65 | #define PT_GETEVENTMSG PTRACE_GETEVENTMSG | ||
| 66 | #define PT_GETSIGINFO PTRACE_GETSIGINFO | ||
| 67 | #define PT_SETSIGINFO PTRACE_SETSIGINFO | ||
| 68 | |||
| 69 | #define PTRACE_O_TRACESYSGOOD 0x00000001 | ||
| 70 | #define PTRACE_O_TRACEFORK 0x00000002 | ||
| 71 | #define PTRACE_O_TRACEVFORK 0x00000004 | ||
| 72 | #define PTRACE_O_TRACECLONE 0x00000008 | ||
| 73 | #define PTRACE_O_TRACEEXEC 0x00000010 | ||
| 74 | #define PTRACE_O_TRACEVFORKDONE 0x00000020 | ||
| 75 | #define PTRACE_O_TRACEEXIT 0x00000040 | ||
| 76 | #define PTRACE_O_TRACESECCOMP 0x00000080 | ||
| 77 | #define PTRACE_O_EXITKILL 0x00100000 | ||
| 78 | #define PTRACE_O_SUSPEND_SECCOMP 0x00200000 | ||
| 79 | #define PTRACE_O_MASK 0x003000ff | ||
| 80 | |||
| 81 | #define PTRACE_EVENT_FORK 1 | ||
| 82 | #define PTRACE_EVENT_VFORK 2 | ||
| 83 | #define PTRACE_EVENT_CLONE 3 | ||
| 84 | #define PTRACE_EVENT_EXEC 4 | ||
| 85 | #define PTRACE_EVENT_VFORK_DONE 5 | ||
| 86 | #define PTRACE_EVENT_EXIT 6 | ||
| 87 | #define PTRACE_EVENT_SECCOMP 7 | ||
| 88 | #define PTRACE_EVENT_STOP 128 | ||
| 89 | |||
| 90 | #define PTRACE_PEEKSIGINFO_SHARED 1 | ||
| 91 | |||
| 92 | #define PTRACE_SYSCALL_INFO_NONE 0 | ||
| 93 | #define PTRACE_SYSCALL_INFO_ENTRY 1 | ||
| 94 | #define PTRACE_SYSCALL_INFO_EXIT 2 | ||
| 95 | #define PTRACE_SYSCALL_INFO_SECCOMP 3 | ||
| 96 | |||
| 97 | #include <bits/ptrace.h> | ||
| 98 | |||
| 99 | struct __ptrace_peeksiginfo_args { | ||
| 100 | 	uint64_t off; | ||
| 101 | 	uint32_t flags; | ||
| 102 | 	int32_t nr; | ||
| 103 | }; | ||
| 104 | |||
| 105 | struct __ptrace_seccomp_metadata { | ||
| 106 | 	uint64_t filter_off; | ||
| 107 | 	uint64_t flags; | ||
| 108 | }; | ||
| 109 | |||
| 110 | struct __ptrace_syscall_info { | ||
| 111 | 	uint8_t op; | ||
| 112 | 	uint8_t __pad[3]; | ||
| 113 | 	uint32_t arch; | ||
| 114 | 	uint64_t instruction_pointer; | ||
| 115 | 	uint64_t stack_pointer; | ||
| 116 | 	union { | ||
| 117 | 		struct { | ||
| 118 | 			uint64_t nr; | ||
| 119 | 			uint64_t args[6]; | ||
| 120 | 		} entry; | ||
| 121 | 		struct { | ||
| 122 | 			int64_t rval; | ||
| 123 | 			uint8_t is_error; | ||
| 124 | 		} exit; | ||
| 125 | 		struct { | ||
| 126 | 			uint64_t nr; | ||
| 127 | 			uint64_t args[6]; | ||
| 128 | 			uint32_t ret_data; | ||
| 129 | 		} seccomp; | ||
| 130 | 	}; | ||
| 131 | }; | ||
| 132 | |||
| 133 | long ptrace(int, ...); | ||
| 134 | |||
| 135 | #ifdef __cplusplus | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/quota.h created+102| ... | @@ -0,0 +1,102 @@ | ||
| 1 | #ifndef _SYS_QUOTA_H | ||
| 2 | #define _SYS_QUOTA_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | |||
| 10 | #define _LINUX_QUOTA_VERSION 2 | ||
| 11 | |||
| 12 | #define dbtob(num) ((num) << 10) | ||
| 13 | #define btodb(num) ((num) >> 10) | ||
| 14 | #define fs_to_dq_blocks(num, blksize) (((num) * (blksize)) / 1024) | ||
| 15 | |||
| 16 | #define MAX_IQ_TIME 604800 | ||
| 17 | #define MAX_DQ_TIME 604800 | ||
| 18 | |||
| 19 | #define MAXQUOTAS 2 | ||
| 20 | #define USRQUOTA 0 | ||
| 21 | #define GRPQUOTA 1 | ||
| 22 | |||
| 23 | #define INITQFNAMES { "user", "group", "undefined" }; | ||
| 24 | |||
| 25 | #define QUOTAFILENAME "quota" | ||
| 26 | #define QUOTAGROUP "staff" | ||
| 27 | |||
| 28 | #define NR_DQHASH 43 | ||
| 29 | #define NR_DQUOTS 256 | ||
| 30 | |||
| 31 | #define SUBCMDMASK 0x00ff | ||
| 32 | #define SUBCMDSHIFT 8 | ||
| 33 | #define QCMD(cmd, type) (((cmd) << SUBCMDSHIFT) | ((type) & SUBCMDMASK)) | ||
| 34 | |||
| 35 | #define Q_SYNC 0x800001 | ||
| 36 | #define Q_QUOTAON 0x800002 | ||
| 37 | #define Q_QUOTAOFF 0x800003 | ||
| 38 | #define Q_GETFMT 0x800004 | ||
| 39 | #define Q_GETINFO 0x800005 | ||
| 40 | #define Q_SETINFO 0x800006 | ||
| 41 | #define Q_GETQUOTA 0x800007 | ||
| 42 | #define Q_SETQUOTA 0x800008 | ||
| 43 | |||
| 44 | #define	QFMT_VFS_OLD 1 | ||
| 45 | #define	QFMT_VFS_V0 2 | ||
| 46 | #define QFMT_OCFS2 3 | ||
| 47 | #define	QFMT_VFS_V1 4 | ||
| 48 | |||
| 49 | #define QIF_BLIMITS	1 | ||
| 50 | #define QIF_SPACE	2 | ||
| 51 | #define QIF_ILIMITS	4 | ||
| 52 | #define QIF_INODES	8 | ||
| 53 | #define QIF_BTIME	16 | ||
| 54 | #define QIF_ITIME	32 | ||
| 55 | #define QIF_LIMITS	(QIF_BLIMITS | QIF_ILIMITS) | ||
| 56 | #define QIF_USAGE	(QIF_SPACE | QIF_INODES) | ||
| 57 | #define QIF_TIMES	(QIF_BTIME | QIF_ITIME) | ||
| 58 | #define QIF_ALL		(QIF_LIMITS | QIF_USAGE | QIF_TIMES) | ||
| 59 | |||
| 60 | struct dqblk { | ||
| 61 | 	uint64_t dqb_bhardlimit; | ||
| 62 | 	uint64_t dqb_bsoftlimit; | ||
| 63 | 	uint64_t dqb_curspace; | ||
| 64 | 	uint64_t dqb_ihardlimit; | ||
| 65 | 	uint64_t dqb_isoftlimit; | ||
| 66 | 	uint64_t dqb_curinodes; | ||
| 67 | 	uint64_t dqb_btime; | ||
| 68 | 	uint64_t dqb_itime; | ||
| 69 | 	uint32_t dqb_valid; | ||
| 70 | }; | ||
| 71 | |||
| 72 | #define	dq_bhardlimit	dq_dqb.dqb_bhardlimit | ||
| 73 | #define	dq_bsoftlimit	dq_dqb.dqb_bsoftlimit | ||
| 74 | #define dq_curspace	dq_dqb.dqb_curspace | ||
| 75 | #define dq_valid	dq_dqb.dqb_valid | ||
| 76 | #define	dq_ihardlimit	dq_dqb.dqb_ihardlimit | ||
| 77 | #define	dq_isoftlimit	dq_dqb.dqb_isoftlimit | ||
| 78 | #define	dq_curinodes	dq_dqb.dqb_curinodes | ||
| 79 | #define	dq_btime	dq_dqb.dqb_btime | ||
| 80 | #define	dq_itime	dq_dqb.dqb_itime | ||
| 81 | |||
| 82 | #define dqoff(UID) ((long long)(UID) * sizeof (struct dqblk)) | ||
| 83 | |||
| 84 | #define IIF_BGRACE	1 | ||
| 85 | #define IIF_IGRACE	2 | ||
| 86 | #define IIF_FLAGS	4 | ||
| 87 | #define IIF_ALL		(IIF_BGRACE | IIF_IGRACE | IIF_FLAGS) | ||
| 88 | |||
| 89 | struct dqinfo { | ||
| 90 | 	uint64_t dqi_bgrace; | ||
| 91 | 	uint64_t dqi_igrace; | ||
| 92 | 	uint32_t dqi_flags; | ||
| 93 | 	uint32_t dqi_valid; | ||
| 94 | }; | ||
| 95 | |||
| 96 | int quotactl(int, const char *, int, char *); | ||
| 97 | |||
| 98 | #ifdef __cplusplus | ||
| 99 | } | ||
| 100 | #endif | ||
| 101 | |||
| 102 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/random.h created+27| ... | @@ -0,0 +1,27 @@ | ||
| 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/reboot.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #ifndef _SYS_REBOOT_H | ||
| 2 | #define _SYS_REBOOT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #define RB_AUTOBOOT 0x01234567 | ||
| 8 | #define RB_HALT_SYSTEM 0xcdef0123 | ||
| 9 | #define RB_ENABLE_CAD 0x89abcdef | ||
| 10 | #define RB_DISABLE_CAD 0 | ||
| 11 | #define RB_POWER_OFF 0x4321fedc | ||
| 12 | #define RB_SW_SUSPEND 0xd000fce2 | ||
| 13 | #define RB_KEXEC 0x45584543 | ||
| 14 | |||
| 15 | int reboot(int); | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | } | ||
| 19 | #endif | ||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/reg.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef _SYS_REG_H | ||
| 2 | #define _SYS_REG_H | ||
| 3 | |||
| 4 | #include <limits.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | |||
| 7 | #include <bits/reg.h> | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/resource.h created+126| ... | @@ -0,0 +1,126 @@ | ||
| 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 created+54| ... | @@ -0,0 +1,54 @@ | ||
| 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/sem.h created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | #ifndef _SYS_SEM_H | ||
| 2 | #define _SYS_SEM_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_size_t | ||
| 10 | #define __NEED_pid_t | ||
| 11 | #define __NEED_time_t | ||
| 12 | #ifdef _GNU_SOURCE | ||
| 13 | #define __NEED_struct_timespec | ||
| 14 | #endif | ||
| 15 | #include <bits/alltypes.h> | ||
| 16 | |||
| 17 | #include <sys/ipc.h> | ||
| 18 | |||
| 19 | #define SEM_UNDO	0x1000 | ||
| 20 | #define GETPID		11 | ||
| 21 | #define GETVAL		12 | ||
| 22 | #define GETALL		13 | ||
| 23 | #define GETNCNT		14 | ||
| 24 | #define GETZCNT		15 | ||
| 25 | #define SETVAL		16 | ||
| 26 | #define SETALL		17 | ||
| 27 | |||
| 28 | #include <bits/sem.h> | ||
| 29 | |||
| 30 | #define _SEM_SEMUN_UNDEFINED 1 | ||
| 31 | |||
| 32 | #define SEM_STAT (18 | (IPC_STAT & 0x100)) | ||
| 33 | #define SEM_INFO 19 | ||
| 34 | #define SEM_STAT_ANY (20 | (IPC_STAT & 0x100)) | ||
| 35 | |||
| 36 | struct seminfo { | ||
| 37 | 	int semmap; | ||
| 38 | 	int semmni; | ||
| 39 | 	int semmns; | ||
| 40 | 	int semmnu; | ||
| 41 | 	int semmsl; | ||
| 42 | 	int semopm; | ||
| 43 | 	int semume; | ||
| 44 | 	int semusz; | ||
| 45 | 	int semvmx; | ||
| 46 | 	int semaem; | ||
| 47 | }; | ||
| 48 | |||
| 49 | struct sembuf { | ||
| 50 | 	unsigned short sem_num; | ||
| 51 | 	short sem_op; | ||
| 52 | 	short sem_flg; | ||
| 53 | }; | ||
| 54 | |||
| 55 | int semctl(int, int, int, ...); | ||
| 56 | int semget(key_t, int, int); | ||
| 57 | int semop(int, struct sembuf *, size_t); | ||
| 58 | |||
| 59 | #ifdef _GNU_SOURCE | ||
| 60 | int semtimedop(int, struct sembuf *, size_t, const struct timespec *); | ||
| 61 | #endif | ||
| 62 | |||
| 63 | #if _REDIR_TIME64 | ||
| 64 | #ifdef _GNU_SOURCE | ||
| 65 | __REDIR(semtimedop, __semtimedop_time64); | ||
| 66 | #endif | ||
| 67 | #endif | ||
| 68 | |||
| 69 | #ifdef __cplusplus | ||
| 70 | } | ||
| 71 | #endif | ||
| 72 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/sendfile.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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/shm.h created+70| ... | @@ -0,0 +1,70 @@ | ||
| 1 | #ifndef _SYS_SHM_H | ||
| 2 | #define _SYS_SHM_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_time_t | ||
| 11 | #define __NEED_size_t | ||
| 12 | #define __NEED_pid_t | ||
| 13 | |||
| 14 | #include <bits/alltypes.h> | ||
| 15 | |||
| 16 | #include <sys/ipc.h> | ||
| 17 | |||
| 18 | #ifdef _GNU_SOURCE | ||
| 19 | #define __used_ids used_ids | ||
| 20 | #define __swap_attempts swap_attempts | ||
| 21 | #define __swap_successes swap_successes | ||
| 22 | #endif | ||
| 23 | |||
| 24 | #include <bits/shm.h> | ||
| 25 | |||
| 26 | #define SHM_R 0400 | ||
| 27 | #define SHM_W 0200 | ||
| 28 | |||
| 29 | #define SHM_RDONLY 010000 | ||
| 30 | #define SHM_RND 020000 | ||
| 31 | #define SHM_REMAP 040000 | ||
| 32 | #define SHM_EXEC 0100000 | ||
| 33 | |||
| 34 | #define SHM_LOCK 11 | ||
| 35 | #define SHM_UNLOCK 12 | ||
| 36 | #define SHM_STAT (13 | (IPC_STAT & 0x100)) | ||
| 37 | #define SHM_INFO 14 | ||
| 38 | #define SHM_STAT_ANY (15 | (IPC_STAT & 0x100)) | ||
| 39 | #define SHM_DEST 01000 | ||
| 40 | #define SHM_LOCKED 02000 | ||
| 41 | #define SHM_HUGETLB 04000 | ||
| 42 | #define SHM_NORESERVE 010000 | ||
| 43 | |||
| 44 | #define SHM_HUGE_SHIFT 26 | ||
| 45 | #define SHM_HUGE_MASK 0x3f | ||
| 46 | #define SHM_HUGE_64KB (16 << 26) | ||
| 47 | #define SHM_HUGE_512KB (19 << 26) | ||
| 48 | #define SHM_HUGE_1MB (20 << 26) | ||
| 49 | #define SHM_HUGE_2MB (21 << 26) | ||
| 50 | #define SHM_HUGE_8MB (23 << 26) | ||
| 51 | #define SHM_HUGE_16MB (24 << 26) | ||
| 52 | #define SHM_HUGE_32MB (25 << 26) | ||
| 53 | #define SHM_HUGE_256MB (28 << 26) | ||
| 54 | #define SHM_HUGE_512MB (29 << 26) | ||
| 55 | #define SHM_HUGE_1GB (30 << 26) | ||
| 56 | #define SHM_HUGE_2GB (31 << 26) | ||
| 57 | #define SHM_HUGE_16GB (34U << 26) | ||
| 58 | |||
| 59 | typedef unsigned long shmatt_t; | ||
| 60 | |||
| 61 | void *shmat(int, const void *, int); | ||
| 62 | int shmctl(int, int, struct shmid_ds *); | ||
| 63 | int shmdt(const void *); | ||
| 64 | int shmget(key_t, size_t, int); | ||
| 65 | |||
| 66 | #ifdef __cplusplus | ||
| 67 | } | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/signal.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/signal.h> to <signal.h> | ||
| 2 | #include <signal.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/signalfd.h created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #ifndef _SYS_SIGNALFD_H | ||
| 2 | #define _SYS_SIGNALFD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <stdint.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | |||
| 11 | #define __NEED_sigset_t | ||
| 12 | |||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | #define SFD_CLOEXEC O_CLOEXEC | ||
| 16 | #define SFD_NONBLOCK O_NONBLOCK | ||
| 17 | |||
| 18 | int signalfd(int, const sigset_t *, int); | ||
| 19 | |||
| 20 | struct signalfd_siginfo { | ||
| 21 | 	uint32_t ssi_signo; | ||
| 22 | 	int32_t ssi_errno; | ||
| 23 | 	int32_t ssi_code; | ||
| 24 | 	uint32_t ssi_pid; | ||
| 25 | 	uint32_t ssi_uid; | ||
| 26 | 	int32_t ssi_fd; | ||
| 27 | 	uint32_t ssi_tid; | ||
| 28 | 	uint32_t ssi_band; | ||
| 29 | 	uint32_t ssi_overrun; | ||
| 30 | 	uint32_t ssi_trapno; | ||
| 31 | 	int32_t ssi_status; | ||
| 32 | 	int32_t ssi_int; | ||
| 33 | 	uint64_t ssi_ptr; | ||
| 34 | 	uint64_t ssi_utime; | ||
| 35 | 	uint64_t ssi_stime; | ||
| 36 | 	uint64_t ssi_addr; | ||
| 37 | 	uint16_t ssi_addr_lsb; | ||
| 38 | 	uint16_t __pad2; | ||
| 39 | 	int32_t ssi_syscall; | ||
| 40 | 	uint64_t ssi_call_addr; | ||
| 41 | 	uint32_t ssi_arch; | ||
| 42 | 	uint8_t __pad[128-14*4-5*8-2*2]; | ||
| 43 | }; | ||
| 44 | |||
| 45 | #ifdef __cplusplus | ||
| 46 | } | ||
| 47 | #endif | ||
| 48 | |||
| 49 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/socket.h created+445| ... | @@ -0,0 +1,445 @@ | ||
| 1 | #ifndef	_SYS_SOCKET_H | ||
| 2 | #define	_SYS_SOCKET_H | ||
| 3 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 4 | #else | ||
| 5 | #include <__header_sys_socket.h> | ||
| 6 | #endif | ||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | #endif | ||
| 10 | |||
| 11 | #include <features.h> | ||
| 12 | |||
| 13 | #define __NEED_socklen_t | ||
| 14 | #define __NEED_sa_family_t | ||
| 15 | #define __NEED_size_t | ||
| 16 | #define __NEED_ssize_t | ||
| 17 | #define __NEED_uid_t | ||
| 18 | #define __NEED_pid_t | ||
| 19 | #define __NEED_gid_t | ||
| 20 | #define __NEED_struct_iovec | ||
| 21 | |||
| 22 | #include <bits/alltypes.h> | ||
| 23 | |||
| 24 | #include <bits/socket.h> | ||
| 25 | |||
| 26 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 27 | struct msghdr { | ||
| 28 | 	void *msg_name; | ||
| 29 | 	socklen_t msg_namelen; | ||
| 30 | 	struct iovec *msg_iov; | ||
| 31 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 32 | 	int __pad1; | ||
| 33 | #endif | ||
| 34 | 	int msg_iovlen; | ||
| 35 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 36 | 	int __pad1; | ||
| 37 | #endif | ||
| 38 | 	void *msg_control; | ||
| 39 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 40 | 	int __pad2; | ||
| 41 | #endif | ||
| 42 | 	socklen_t msg_controllen; | ||
| 43 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 44 | 	int __pad2; | ||
| 45 | #endif | ||
| 46 | 	int msg_flags; | ||
| 47 | }; | ||
| 48 | |||
| 49 | struct cmsghdr { | ||
| 50 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN | ||
| 51 | 	int __pad1; | ||
| 52 | #endif | ||
| 53 | 	socklen_t cmsg_len; | ||
| 54 | #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 55 | 	int __pad1; | ||
| 56 | #endif | ||
| 57 | 	int cmsg_level; | ||
| 58 | 	int cmsg_type; | ||
| 59 | }; | ||
| 60 | #else | ||
| 61 | #include <__struct_msghdr.h> | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #ifdef _GNU_SOURCE | ||
| 65 | struct ucred { | ||
| 66 | 	pid_t pid; | ||
| 67 | 	uid_t uid; | ||
| 68 | 	gid_t gid; | ||
| 69 | }; | ||
| 70 | |||
| 71 | struct mmsghdr { | ||
| 72 | 	struct msghdr msg_hdr; | ||
| 73 | 	unsigned int msg_len; | ||
| 74 | }; | ||
| 75 | |||
| 76 | struct timespec; | ||
| 77 | |||
| 78 | int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int); | ||
| 79 | int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *); | ||
| 80 | #endif | ||
| 81 | |||
| 82 | struct linger { | ||
| 83 | 	int l_onoff; | ||
| 84 | 	int l_linger; | ||
| 85 | }; | ||
| 86 | |||
| 87 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 88 | #define SHUT_RD 0 | ||
| 89 | #define SHUT_WR 1 | ||
| 90 | #define SHUT_RDWR 2 | ||
| 91 | |||
| 92 | #ifndef SOCK_STREAM | ||
| 93 | #define SOCK_STREAM 1 | ||
| 94 | #define SOCK_DGRAM 2 | ||
| 95 | #endif | ||
| 96 | |||
| 97 | #define SOCK_RAW 3 | ||
| 98 | #define SOCK_RDM 4 | ||
| 99 | #define SOCK_SEQPACKET 5 | ||
| 100 | #define SOCK_DCCP 6 | ||
| 101 | #define SOCK_PACKET 10 | ||
| 102 | |||
| 103 | #ifndef SOCK_CLOEXEC | ||
| 104 | #define SOCK_CLOEXEC 02000000 | ||
| 105 | #define SOCK_NONBLOCK 04000 | ||
| 106 | #endif | ||
| 107 | |||
| 108 | #define PF_UNSPEC 0 | ||
| 109 | #define PF_LOCAL 1 | ||
| 110 | #define PF_UNIX PF_LOCAL | ||
| 111 | #define PF_FILE PF_LOCAL | ||
| 112 | #define PF_INET 2 | ||
| 113 | #define PF_AX25 3 | ||
| 114 | #define PF_IPX 4 | ||
| 115 | #define PF_APPLETALK 5 | ||
| 116 | #define PF_NETROM 6 | ||
| 117 | #define PF_BRIDGE 7 | ||
| 118 | #define PF_ATMPVC 8 | ||
| 119 | #define PF_X25 9 | ||
| 120 | #define PF_INET6 10 | ||
| 121 | #define PF_ROSE 11 | ||
| 122 | #define PF_DECnet 12 | ||
| 123 | #define PF_NETBEUI 13 | ||
| 124 | #define PF_SECURITY 14 | ||
| 125 | #define PF_KEY 15 | ||
| 126 | #define PF_NETLINK 16 | ||
| 127 | #define PF_ROUTE PF_NETLINK | ||
| 128 | #define PF_PACKET 17 | ||
| 129 | #define PF_ASH 18 | ||
| 130 | #define PF_ECONET 19 | ||
| 131 | #define PF_ATMSVC 20 | ||
| 132 | #define PF_RDS 21 | ||
| 133 | #define PF_SNA 22 | ||
| 134 | #define PF_IRDA 23 | ||
| 135 | #define PF_PPPOX 24 | ||
| 136 | #define PF_WANPIPE 25 | ||
| 137 | #define PF_LLC 26 | ||
| 138 | #define PF_IB 27 | ||
| 139 | #define PF_MPLS 28 | ||
| 140 | #define PF_CAN 29 | ||
| 141 | #define PF_TIPC 30 | ||
| 142 | #define PF_BLUETOOTH 31 | ||
| 143 | #define PF_IUCV 32 | ||
| 144 | #define PF_RXRPC 33 | ||
| 145 | #define PF_ISDN 34 | ||
| 146 | #define PF_PHONET 35 | ||
| 147 | #define PF_IEEE802154 36 | ||
| 148 | #define PF_CAIF 37 | ||
| 149 | #define PF_ALG 38 | ||
| 150 | #define PF_NFC 39 | ||
| 151 | #define PF_VSOCK 40 | ||
| 152 | #define PF_KCM 41 | ||
| 153 | #define PF_QIPCRTR 42 | ||
| 154 | #define PF_SMC 43 | ||
| 155 | #define PF_XDP 44 | ||
| 156 | #define PF_MAX 45 | ||
| 157 | |||
| 158 | #define AF_UNSPEC PF_UNSPEC | ||
| 159 | #define AF_LOCAL PF_LOCAL | ||
| 160 | #define AF_UNIX AF_LOCAL | ||
| 161 | #define AF_FILE AF_LOCAL | ||
| 162 | #define AF_INET PF_INET | ||
| 163 | #define AF_AX25 PF_AX25 | ||
| 164 | #define AF_IPX PF_IPX | ||
| 165 | #define AF_APPLETALK PF_APPLETALK | ||
| 166 | #define AF_NETROM PF_NETROM | ||
| 167 | #define AF_BRIDGE PF_BRIDGE | ||
| 168 | #define AF_ATMPVC PF_ATMPVC | ||
| 169 | #define AF_X25 PF_X25 | ||
| 170 | #define AF_INET6 PF_INET6 | ||
| 171 | #define AF_ROSE PF_ROSE | ||
| 172 | #define AF_DECnet PF_DECnet | ||
| 173 | #define AF_NETBEUI PF_NETBEUI | ||
| 174 | #define AF_SECURITY PF_SECURITY | ||
| 175 | #define AF_KEY PF_KEY | ||
| 176 | #define AF_NETLINK PF_NETLINK | ||
| 177 | #define AF_ROUTE PF_ROUTE | ||
| 178 | #define AF_PACKET PF_PACKET | ||
| 179 | #define AF_ASH PF_ASH | ||
| 180 | #define AF_ECONET PF_ECONET | ||
| 181 | #define AF_ATMSVC PF_ATMSVC | ||
| 182 | #define AF_RDS PF_RDS | ||
| 183 | #define AF_SNA PF_SNA | ||
| 184 | #define AF_IRDA PF_IRDA | ||
| 185 | #define AF_PPPOX PF_PPPOX | ||
| 186 | #define AF_WANPIPE PF_WANPIPE | ||
| 187 | #define AF_LLC PF_LLC | ||
| 188 | #define AF_IB PF_IB | ||
| 189 | #define AF_MPLS PF_MPLS | ||
| 190 | #define AF_CAN PF_CAN | ||
| 191 | #define AF_TIPC PF_TIPC | ||
| 192 | #define AF_BLUETOOTH PF_BLUETOOTH | ||
| 193 | #define AF_IUCV PF_IUCV | ||
| 194 | #define AF_RXRPC PF_RXRPC | ||
| 195 | #define AF_ISDN PF_ISDN | ||
| 196 | #define AF_PHONET PF_PHONET | ||
| 197 | #define AF_IEEE802154 PF_IEEE802154 | ||
| 198 | #define AF_CAIF PF_CAIF | ||
| 199 | #define AF_ALG PF_ALG | ||
| 200 | #define AF_NFC PF_NFC | ||
| 201 | #define AF_VSOCK PF_VSOCK | ||
| 202 | #define AF_KCM PF_KCM | ||
| 203 | #define AF_QIPCRTR PF_QIPCRTR | ||
| 204 | #define AF_SMC PF_SMC | ||
| 205 | #define AF_XDP PF_XDP | ||
| 206 | #define AF_MAX PF_MAX | ||
| 207 | |||
| 208 | #ifndef SO_DEBUG | ||
| 209 | #define SO_DEBUG 1 | ||
| 210 | #define SO_REUSEADDR 2 | ||
| 211 | #define SO_TYPE 3 | ||
| 212 | #define SO_ERROR 4 | ||
| 213 | #define SO_DONTROUTE 5 | ||
| 214 | #define SO_BROADCAST 6 | ||
| 215 | #define SO_SNDBUF 7 | ||
| 216 | #define SO_RCVBUF 8 | ||
| 217 | #define SO_KEEPALIVE 9 | ||
| 218 | #define SO_OOBINLINE 10 | ||
| 219 | #define SO_NO_CHECK 11 | ||
| 220 | #define SO_PRIORITY 12 | ||
| 221 | #define SO_LINGER 13 | ||
| 222 | #define SO_BSDCOMPAT 14 | ||
| 223 | #define SO_REUSEPORT 15 | ||
| 224 | #define SO_PASSCRED 16 | ||
| 225 | #define SO_PEERCRED 17 | ||
| 226 | #define SO_RCVLOWAT 18 | ||
| 227 | #define SO_SNDLOWAT 19 | ||
| 228 | #define SO_ACCEPTCONN 30 | ||
| 229 | #define SO_PEERSEC 31 | ||
| 230 | #define SO_SNDBUFFORCE 32 | ||
| 231 | #define SO_RCVBUFFORCE 33 | ||
| 232 | #define SO_PROTOCOL 38 | ||
| 233 | #define SO_DOMAIN 39 | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #ifndef SO_RCVTIMEO | ||
| 237 | #if __LONG_MAX == 0x7fffffff | ||
| 238 | #define SO_RCVTIMEO 66 | ||
| 239 | #define SO_SNDTIMEO 67 | ||
| 240 | #else | ||
| 241 | #define SO_RCVTIMEO 20 | ||
| 242 | #define SO_SNDTIMEO 21 | ||
| 243 | #endif | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifndef SO_TIMESTAMP | ||
| 247 | #if __LONG_MAX == 0x7fffffff | ||
| 248 | #define SO_TIMESTAMP 63 | ||
| 249 | #define SO_TIMESTAMPNS 64 | ||
| 250 | #define SO_TIMESTAMPING 65 | ||
| 251 | #else | ||
| 252 | #define SO_TIMESTAMP 29 | ||
| 253 | #define SO_TIMESTAMPNS 35 | ||
| 254 | #define SO_TIMESTAMPING 37 | ||
| 255 | #endif | ||
| 256 | #endif | ||
| 257 | |||
| 258 | #define SO_SECURITY_AUTHENTICATION 22 | ||
| 259 | #define SO_SECURITY_ENCRYPTION_TRANSPORT 23 | ||
| 260 | #define SO_SECURITY_ENCRYPTION_NETWORK 24 | ||
| 261 | |||
| 262 | #define SO_BINDTODEVICE 25 | ||
| 263 | |||
| 264 | #define SO_ATTACH_FILTER 26 | ||
| 265 | #define SO_DETACH_FILTER 27 | ||
| 266 | #define SO_GET_FILTER SO_ATTACH_FILTER | ||
| 267 | |||
| 268 | #define SO_PEERNAME 28 | ||
| 269 | #define SCM_TIMESTAMP SO_TIMESTAMP | ||
| 270 | #define SO_PASSSEC 34 | ||
| 271 | #define SCM_TIMESTAMPNS SO_TIMESTAMPNS | ||
| 272 | #define SO_MARK 36 | ||
| 273 | #define SCM_TIMESTAMPING SO_TIMESTAMPING | ||
| 274 | #define SO_RXQ_OVFL 40 | ||
| 275 | #define SO_WIFI_STATUS 41 | ||
| 276 | #define SCM_WIFI_STATUS SO_WIFI_STATUS | ||
| 277 | #define SO_PEEK_OFF 42 | ||
| 278 | #define SO_NOFCS 43 | ||
| 279 | #define SO_LOCK_FILTER 44 | ||
| 280 | #define SO_SELECT_ERR_QUEUE 45 | ||
| 281 | #define SO_BUSY_POLL 46 | ||
| 282 | #define SO_MAX_PACING_RATE 47 | ||
| 283 | #define SO_BPF_EXTENSIONS 48 | ||
| 284 | #define SO_INCOMING_CPU 49 | ||
| 285 | #define SO_ATTACH_BPF 50 | ||
| 286 | #define SO_DETACH_BPF SO_DETACH_FILTER | ||
| 287 | #define SO_ATTACH_REUSEPORT_CBPF 51 | ||
| 288 | #define SO_ATTACH_REUSEPORT_EBPF 52 | ||
| 289 | #define SO_CNX_ADVICE 53 | ||
| 290 | #define SCM_TIMESTAMPING_OPT_STATS 54 | ||
| 291 | #define SO_MEMINFO 55 | ||
| 292 | #define SO_INCOMING_NAPI_ID 56 | ||
| 293 | #define SO_COOKIE 57 | ||
| 294 | #define SCM_TIMESTAMPING_PKTINFO 58 | ||
| 295 | #define SO_PEERGROUPS 59 | ||
| 296 | #define SO_ZEROCOPY 60 | ||
| 297 | #define SO_TXTIME 61 | ||
| 298 | #define SCM_TXTIME SO_TXTIME | ||
| 299 | #define SO_BINDTOIFINDEX 62 | ||
| 300 | #define SO_DETACH_REUSEPORT_BPF 68 | ||
| 301 | |||
| 302 | #ifndef SOL_SOCKET | ||
| 303 | #define SOL_SOCKET 1 | ||
| 304 | #endif | ||
| 305 | |||
| 306 | #define SOL_IP 0 | ||
| 307 | #define SOL_IPV6 41 | ||
| 308 | #define SOL_ICMPV6 58 | ||
| 309 | |||
| 310 | #define SOL_RAW 255 | ||
| 311 | #define SOL_DECNET 261 | ||
| 312 | #define SOL_X25 262 | ||
| 313 | #define SOL_PACKET 263 | ||
| 314 | #define SOL_ATM 264 | ||
| 315 | #define SOL_AAL 265 | ||
| 316 | #define SOL_IRDA 266 | ||
| 317 | #define SOL_NETBEUI 267 | ||
| 318 | #define SOL_LLC 268 | ||
| 319 | #define SOL_DCCP 269 | ||
| 320 | #define SOL_NETLINK 270 | ||
| 321 | #define SOL_TIPC 271 | ||
| 322 | #define SOL_RXRPC 272 | ||
| 323 | #define SOL_PPPOL2TP 273 | ||
| 324 | #define SOL_BLUETOOTH 274 | ||
| 325 | #define SOL_PNPIPE 275 | ||
| 326 | #define SOL_RDS 276 | ||
| 327 | #define SOL_IUCV 277 | ||
| 328 | #define SOL_CAIF 278 | ||
| 329 | #define SOL_ALG 279 | ||
| 330 | #define SOL_NFC 280 | ||
| 331 | #define SOL_KCM 281 | ||
| 332 | #define SOL_TLS 282 | ||
| 333 | #define SOL_XDP 283 | ||
| 334 | |||
| 335 | #define SOMAXCONN 128 | ||
| 336 | |||
| 337 | #define MSG_OOB 0x0001 | ||
| 338 | #define MSG_PEEK 0x0002 | ||
| 339 | #define MSG_DONTROUTE 0x0004 | ||
| 340 | #define MSG_CTRUNC 0x0008 | ||
| 341 | #define MSG_PROXY 0x0010 | ||
| 342 | #define MSG_TRUNC 0x0020 | ||
| 343 | #define MSG_DONTWAIT 0x0040 | ||
| 344 | #define MSG_EOR 0x0080 | ||
| 345 | #define MSG_WAITALL 0x0100 | ||
| 346 | #define MSG_FIN 0x0200 | ||
| 347 | #define MSG_SYN 0x0400 | ||
| 348 | #define MSG_CONFIRM 0x0800 | ||
| 349 | #define MSG_RST 0x1000 | ||
| 350 | #define MSG_ERRQUEUE 0x2000 | ||
| 351 | #define MSG_NOSIGNAL 0x4000 | ||
| 352 | #define MSG_MORE 0x8000 | ||
| 353 | #define MSG_WAITFORONE 0x10000 | ||
| 354 | #define MSG_BATCH 0x40000 | ||
| 355 | #define MSG_ZEROCOPY 0x4000000 | ||
| 356 | #define MSG_FASTOPEN 0x20000000 | ||
| 357 | #define MSG_CMSG_CLOEXEC 0x40000000 | ||
| 358 | |||
| 359 | #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1)) | ||
| 360 | #define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg)) | ||
| 361 | #define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen) | ||
| 362 | |||
| 363 | #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1)) | ||
| 364 | #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \ | ||
| 365 | 	__CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \ | ||
| 366 | 	? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg)) | ||
| 367 | #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0) | ||
| 368 | |||
| 369 | #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1)) | ||
| 370 | #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr))) | ||
| 371 | #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len)) | ||
| 372 | |||
| 373 | #define SCM_RIGHTS 0x01 | ||
| 374 | #define SCM_CREDENTIALS 0x02 | ||
| 375 | #endif | ||
| 376 | |||
| 377 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 378 | struct sockaddr { | ||
| 379 | 	sa_family_t sa_family; | ||
| 380 | 	char sa_data[14]; | ||
| 381 | }; | ||
| 382 | #else | ||
| 383 | #include <__struct_sockaddr.h> | ||
| 384 | #endif | ||
| 385 | |||
| 386 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 387 | struct sockaddr_storage { | ||
| 388 | 	sa_family_t ss_family; | ||
| 389 | 	char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)]; | ||
| 390 | 	unsigned long __ss_align; | ||
| 391 | }; | ||
| 392 | #else | ||
| 393 | #include <__struct_sockaddr_storage.h> | ||
| 394 | #endif | ||
| 395 | |||
| 396 | #ifdef __wasilibc_unmodified_upstream /* WASI has no socket/socketpair */ | ||
| 397 | int socket (int, int, int); | ||
| 398 | int socketpair (int, int, int, int [2]); | ||
| 399 | #endif | ||
| 400 | |||
| 401 | int shutdown (int, int); | ||
| 402 | |||
| 403 | #ifdef __wasilibc_unmodified_upstream /* WASI has no bind/connect/listen/accept */ | ||
| 404 | int bind (int, const struct sockaddr *, socklen_t); | ||
| 405 | int connect (int, const struct sockaddr *, socklen_t); | ||
| 406 | int listen (int, int); | ||
| 407 | int accept (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 408 | int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int); | ||
| 409 | #endif | ||
| 410 | |||
| 411 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */ | ||
| 412 | int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 413 | int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 414 | #endif | ||
| 415 | |||
| 416 | ssize_t send (int, const void *, size_t, int); | ||
| 417 | ssize_t recv (int, void *, size_t, int); | ||
| 418 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sendto/recvfrom */ | ||
| 419 | ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t); | ||
| 420 | ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict); | ||
| 421 | #endif | ||
| 422 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sendmsg/recvmsg */ | ||
| 423 | ssize_t sendmsg (int, const struct msghdr *, int); | ||
| 424 | ssize_t recvmsg (int, struct msghdr *, int); | ||
| 425 | #endif | ||
| 426 | |||
| 427 | int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict); | ||
| 428 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setsockopt */ | ||
| 429 | int setsockopt (int, int, int, const void *, socklen_t); | ||
| 430 | #endif | ||
| 431 | |||
| 432 | #ifdef __wasilibc_unmodified_upstream /* WASI has no sockatmark */ | ||
| 433 | int sockatmark (int); | ||
| 434 | #endif | ||
| 435 | |||
| 436 | #if _REDIR_TIME64 | ||
| 437 | #ifdef _GNU_SOURCE | ||
| 438 | __REDIR(recvmmsg, __recvmmsg_time64); | ||
| 439 | #endif | ||
| 440 | #endif | ||
| 441 | |||
| 442 | #ifdef __cplusplus | ||
| 443 | } | ||
| 444 | #endif | ||
| 445 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/soundcard.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <bits/soundcard.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/stat.h created+143| ... | @@ -0,0 +1,143 @@ | ||
| 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 | #include <bits/alltypes.h> | ||
| 22 | |||
| 23 | #include <bits/stat.h> | ||
| 24 | |||
| 25 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 26 | #define st_atime st_atim.tv_sec | ||
| 27 | #define st_mtime st_mtim.tv_sec | ||
| 28 | #define st_ctime st_ctim.tv_sec | ||
| 29 | |||
| 30 | #define S_IFMT 0170000 | ||
| 31 | |||
| 32 | #define S_IFDIR 0040000 | ||
| 33 | #define S_IFCHR 0020000 | ||
| 34 | #define S_IFBLK 0060000 | ||
| 35 | #define S_IFREG 0100000 | ||
| 36 | #define S_IFIFO 0010000 | ||
| 37 | #define S_IFLNK 0120000 | ||
| 38 | #define S_IFSOCK 0140000 | ||
| 39 | |||
| 40 | #define S_TYPEISMQ(buf) 0 | ||
| 41 | #define S_TYPEISSEM(buf) 0 | ||
| 42 | #define S_TYPEISSHM(buf) 0 | ||
| 43 | #define S_TYPEISTMO(buf) 0 | ||
| 44 | |||
| 45 | #define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR) | ||
| 46 | #define S_ISCHR(mode) (((mode) & S_IFMT) == S_IFCHR) | ||
| 47 | #define S_ISBLK(mode) (((mode) & S_IFMT) == S_IFBLK) | ||
| 48 | #define S_ISREG(mode) (((mode) & S_IFMT) == S_IFREG) | ||
| 49 | #define S_ISFIFO(mode) (((mode) & S_IFMT) == S_IFIFO) | ||
| 50 | #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) | ||
| 51 | #define S_ISSOCK(mode) (((mode) & S_IFMT) == S_IFSOCK) | ||
| 52 | |||
| 53 | #ifndef S_IRUSR | ||
| 54 | #define S_ISUID 04000 | ||
| 55 | #define S_ISGID 02000 | ||
| 56 | #define S_ISVTX 01000 | ||
| 57 | #define S_IRUSR 0400 | ||
| 58 | #define S_IWUSR 0200 | ||
| 59 | #define S_IXUSR 0100 | ||
| 60 | #define S_IRWXU 0700 | ||
| 61 | #define S_IRGRP 0040 | ||
| 62 | #define S_IWGRP 0020 | ||
| 63 | #define S_IXGRP 0010 | ||
| 64 | #define S_IRWXG 0070 | ||
| 65 | #define S_IROTH 0004 | ||
| 66 | #define S_IWOTH 0002 | ||
| 67 | #define S_IXOTH 0001 | ||
| 68 | #define S_IRWXO 0007 | ||
| 69 | #endif | ||
| 70 | |||
| 71 | #define UTIME_NOW 0x3fffffff | ||
| 72 | #define UTIME_OMIT 0x3ffffffe | ||
| 73 | #else | ||
| 74 | #include <__header_sys_stat.h> | ||
| 75 | #endif | ||
| 76 | |||
| 77 | int stat(const char *__restrict, struct stat *__restrict); | ||
| 78 | int fstat(int, struct stat *); | ||
| 79 | int lstat(const char *__restrict, struct stat *__restrict); | ||
| 80 | int fstatat(int, const char *__restrict, struct stat *__restrict, int); | ||
| 81 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ | ||
| 82 | int chmod(const char *, mode_t); | ||
| 83 | int fchmod(int, mode_t); | ||
| 84 | int fchmodat(int, const char *, mode_t, int); | ||
| 85 | #endif | ||
| 86 | #ifdef __wasilibc_unmodified_upstream /* WASI has no umask */ | ||
| 87 | mode_t umask(mode_t); | ||
| 88 | #endif | ||
| 89 | int mkdir(const char *, mode_t); | ||
| 90 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 91 | int mkfifo(const char *, mode_t); | ||
| 92 | #endif | ||
| 93 | int mkdirat(int, const char *, mode_t); | ||
| 94 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fifo */ | ||
| 95 | int mkfifoat(int, const char *, mode_t); | ||
| 96 | #endif | ||
| 97 | |||
| 98 | #ifdef __wasilibc_unmodified_upstream /* WASI has no mknod */ | ||
| 99 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 100 | int mknod(const char *, mode_t, dev_t); | ||
| 101 | int mknodat(int, const char *, mode_t, dev_t); | ||
| 102 | #endif | ||
| 103 | #endif | ||
| 104 | |||
| 105 | int futimens(int, const struct timespec [2]); | ||
| 106 | int utimensat(int, const char *, const struct timespec [2], int); | ||
| 107 | |||
| 108 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 109 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */ | ||
| 110 | int lchmod(const char *, mode_t); | ||
| 111 | #endif | ||
| 112 | #define S_IREAD S_IRUSR | ||
| 113 | #define S_IWRITE S_IWUSR | ||
| 114 | #define S_IEXEC S_IXUSR | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 118 | #define stat64 stat | ||
| 119 | #define fstat64 fstat | ||
| 120 | #define lstat64 lstat | ||
| 121 | #define fstatat64 fstatat | ||
| 122 | #define blkcnt64_t blkcnt_t | ||
| 123 | #define fsblkcnt64_t fsblkcnt_t | ||
| 124 | #define fsfilcnt64_t fsfilcnt_t | ||
| 125 | #define ino64_t ino_t | ||
| 126 | #define off64_t off_t | ||
| 127 | #endif | ||
| 128 | |||
| 129 | #if _REDIR_TIME64 | ||
| 130 | __REDIR(stat, __stat_time64); | ||
| 131 | __REDIR(fstat, __fstat_time64); | ||
| 132 | __REDIR(lstat, __lstat_time64); | ||
| 133 | __REDIR(fstatat, __fstatat_time64); | ||
| 134 | __REDIR(futimens, __futimens_time64); | ||
| 135 | __REDIR(utimensat, __utimensat_time64); | ||
| 136 | #endif | ||
| 137 | |||
| 138 | #ifdef __cplusplus | ||
| 139 | } | ||
| 140 | #endif | ||
| 141 | #endif | ||
| 142 | |||
| 143 | |||
lib/libc/wasi/libc-top-half/musl/include/sys/statfs.h created+32| ... | @@ -0,0 +1,32 @@ | ||
| 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 created+56| ... | @@ -0,0 +1,56 @@ | ||
| 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 | 	int __reserved[6]; | ||
| 27 | }; | ||
| 28 | |||
| 29 | int statvfs (const char *__restrict, struct statvfs *__restrict); | ||
| 30 | int fstatvfs (int, struct statvfs *); | ||
| 31 | |||
| 32 | #define ST_RDONLY 1 | ||
| 33 | #define ST_NOSUID 2 | ||
| 34 | #define ST_NODEV 4 | ||
| 35 | #define ST_NOEXEC 8 | ||
| 36 | #define ST_SYNCHRONOUS 16 | ||
| 37 | #define ST_MANDLOCK 64 | ||
| 38 | #define ST_WRITE 128 | ||
| 39 | #define ST_APPEND 256 | ||
| 40 | #define ST_IMMUTABLE 512 | ||
| 41 | #define ST_NOATIME 1024 | ||
| 42 | #define ST_NODIRATIME 2048 | ||
| 43 | #define ST_RELATIME 4096 | ||
| 44 | |||
| 45 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 46 | #define statvfs64 statvfs | ||
| 47 | #define fstatvfs64 fstatvfs | ||
| 48 | #define fsblkcnt64_t fsblkcnt_t | ||
| 49 | #define fsfilcnt64_t fsfilcnt_t | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #ifdef __cplusplus | ||
| 53 | } | ||
| 54 | #endif | ||
| 55 | |||
| 56 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/stropts.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <stropts.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/swap.h created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #ifndef _SYS_SWAP_H | ||
| 2 | #define _SYS_SWAP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | |||
| 9 | #define	SWAP_FLAG_PREFER 0x8000 | ||
| 10 | #define	SWAP_FLAG_PRIO_MASK 0x7fff | ||
| 11 | #define	SWAP_FLAG_PRIO_SHIFT 0 | ||
| 12 | #define SWAP_FLAG_DISCARD 0x10000 | ||
| 13 | |||
| 14 | int swapon (const char *, int); | ||
| 15 | int swapoff (const char *); | ||
| 16 | |||
| 17 | #ifdef __cplusplus | ||
| 18 | } | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/syscall.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 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/sysinfo.h created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #ifndef _SYS_SYSINFO_H | ||
| 2 | #define _SYS_SYSINFO_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define SI_LOAD_SHIFT 16 | ||
| 9 | |||
| 10 | struct sysinfo { | ||
| 11 | 	unsigned long uptime; | ||
| 12 | 	unsigned long loads[3]; | ||
| 13 | 	unsigned long totalram; | ||
| 14 | 	unsigned long freeram; | ||
| 15 | 	unsigned long sharedram; | ||
| 16 | 	unsigned long bufferram; | ||
| 17 | 	unsigned long totalswap; | ||
| 18 | 	unsigned long freeswap; | ||
| 19 | 	unsigned short procs, pad; | ||
| 20 | 	unsigned long totalhigh; | ||
| 21 | 	unsigned long freehigh; | ||
| 22 | 	unsigned mem_unit; | ||
| 23 | 	char __reserved[256]; | ||
| 24 | }; | ||
| 25 | |||
| 26 | int sysinfo (struct sysinfo *); | ||
| 27 | int get_nprocs_conf (void); | ||
| 28 | int get_nprocs (void); | ||
| 29 | long get_phys_pages (void); | ||
| 30 | long get_avphys_pages (void); | ||
| 31 | |||
| 32 | #ifdef __cplusplus | ||
| 33 | } | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/syslog.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <syslog.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/sysmacros.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #ifndef _SYS_SYSMACROS_H | ||
| 2 | #define _SYS_SYSMACROS_H | ||
| 3 | |||
| 4 | #define major(x) \ | ||
| 5 | 	((unsigned)( (((x)>>31>>1) & 0xfffff000) | (((x)>>8) & 0x00000fff) )) | ||
| 6 | #define minor(x) \ | ||
| 7 | 	((unsigned)( (((x)>>12) & 0xffffff00) | ((x) & 0x000000ff) )) | ||
| 8 | |||
| 9 | #define makedev(x,y) ( \ | ||
| 10 | (((x)&0xfffff000ULL) << 32) | \ | ||
| 11 | 	(((x)&0x00000fffULL) << 8) | \ | ||
| 12 | (((y)&0xffffff00ULL) << 12) | \ | ||
| 13 | 	(((y)&0x000000ffULL)) ) | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/termios.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <sys/termios.h> to <termios.h> | ||
| 2 | #include <termios.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/time.h created+84| ... | @@ -0,0 +1,84 @@ | ||
| 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 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 27 | int utimes (const char *, const struct timeval [2]); | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 31 | struct timezone { | ||
| 32 | 	int tz_minuteswest; | ||
| 33 | 	int tz_dsttime; | ||
| 34 | }; | ||
| 35 | #ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */ | ||
| 36 | int futimes(int, const struct timeval [2]); | ||
| 37 | int futimesat(int, const char *, const struct timeval [2]); | ||
| 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/timeb.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #ifndef _SYS_TIMEB_H | ||
| 2 | #define _SYS_TIMEB_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_time_t | ||
| 10 | |||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | struct timeb { | ||
| 14 | 	time_t time; | ||
| 15 | 	unsigned short millitm; | ||
| 16 | 	short timezone, dstflag; | ||
| 17 | }; | ||
| 18 | |||
| 19 | int ftime(struct timeb *); | ||
| 20 | |||
| 21 | #if _REDIR_TIME64 | ||
| 22 | __REDIR(ftime, __ftime64); | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/timerfd.h created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #ifndef _SYS_TIMERFD_H | ||
| 2 | #define _SYS_TIMERFD_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <time.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | |||
| 11 | #define TFD_NONBLOCK O_NONBLOCK | ||
| 12 | #define TFD_CLOEXEC O_CLOEXEC | ||
| 13 | |||
| 14 | #define TFD_TIMER_ABSTIME 1 | ||
| 15 | #define TFD_TIMER_CANCEL_ON_SET (1 << 1) | ||
| 16 | |||
| 17 | struct itimerspec; | ||
| 18 | |||
| 19 | int timerfd_create(int, int); | ||
| 20 | int timerfd_settime(int, int, const struct itimerspec *, struct itimerspec *); | ||
| 21 | int timerfd_gettime(int, struct itimerspec *); | ||
| 22 | |||
| 23 | #if _REDIR_TIME64 | ||
| 24 | __REDIR(timerfd_settime, __timerfd_settime64); | ||
| 25 | __REDIR(timerfd_gettime, __timerfd_gettime64); | ||
| 26 | #endif | ||
| 27 | |||
| 28 | #ifdef __cplusplus | ||
| 29 | } | ||
| 30 | #endif | ||
| 31 | |||
| 32 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/times.h created+34| ... | @@ -0,0 +1,34 @@ | ||
| 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/timex.h created+103| ... | @@ -0,0 +1,103 @@ | ||
| 1 | #ifndef _SYS_TIMEX_H | ||
| 2 | #define _SYS_TIMEX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define __NEED_clockid_t | ||
| 9 | |||
| 10 | #include <bits/alltypes.h> | ||
| 11 | |||
| 12 | #include <sys/time.h> | ||
| 13 | |||
| 14 | struct ntptimeval { | ||
| 15 | 	struct timeval time; | ||
| 16 | 	long maxerror, esterror; | ||
| 17 | }; | ||
| 18 | |||
| 19 | struct timex { | ||
| 20 | 	unsigned modes; | ||
| 21 | 	long offset, freq, maxerror, esterror; | ||
| 22 | 	int status; | ||
| 23 | 	long constant, precision, tolerance; | ||
| 24 | 	struct timeval time; | ||
| 25 | 	long tick, ppsfreq, jitter; | ||
| 26 | 	int shift; | ||
| 27 | 	long stabil, jitcnt, calcnt, errcnt, stbcnt; | ||
| 28 | 	int tai; | ||
| 29 | 	int __padding[11]; | ||
| 30 | }; | ||
| 31 | |||
| 32 | #define ADJ_OFFSET		0x0001 | ||
| 33 | #define ADJ_FREQUENCY		0x0002 | ||
| 34 | #define ADJ_MAXERROR		0x0004 | ||
| 35 | #define ADJ_ESTERROR		0x0008 | ||
| 36 | #define ADJ_STATUS		0x0010 | ||
| 37 | #define ADJ_TIMECONST		0x0020 | ||
| 38 | #define ADJ_TAI			0x0080 | ||
| 39 | #define ADJ_SETOFFSET		0x0100 | ||
| 40 | #define ADJ_MICRO		0x1000 | ||
| 41 | #define ADJ_NANO		0x2000 | ||
| 42 | #define ADJ_TICK		0x4000 | ||
| 43 | #define ADJ_OFFSET_SINGLESHOT	0x8001 | ||
| 44 | #define ADJ_OFFSET_SS_READ	0xa001 | ||
| 45 | |||
| 46 | #define MOD_OFFSET	ADJ_OFFSET | ||
| 47 | #define MOD_FREQUENCY	ADJ_FREQUENCY | ||
| 48 | #define MOD_MAXERROR	ADJ_MAXERROR | ||
| 49 | #define MOD_ESTERROR	ADJ_ESTERROR | ||
| 50 | #define MOD_STATUS	ADJ_STATUS | ||
| 51 | #define MOD_TIMECONST	ADJ_TIMECONST | ||
| 52 | #define MOD_CLKB	ADJ_TICK | ||
| 53 | #define MOD_CLKA	ADJ_OFFSET_SINGLESHOT | ||
| 54 | #define MOD_TAI		ADJ_TAI | ||
| 55 | #define MOD_MICRO	ADJ_MICRO | ||
| 56 | #define MOD_NANO	ADJ_NANO | ||
| 57 | |||
| 58 | #define STA_PLL		0x0001 | ||
| 59 | #define STA_PPSFREQ	0x0002 | ||
| 60 | #define STA_PPSTIME	0x0004 | ||
| 61 | #define STA_FLL		0x0008 | ||
| 62 | |||
| 63 | #define STA_INS		0x0010 | ||
| 64 | #define STA_DEL		0x0020 | ||
| 65 | #define STA_UNSYNC	0x0040 | ||
| 66 | #define STA_FREQHOLD	0x0080 | ||
| 67 | |||
| 68 | #define STA_PPSSIGNAL	0x0100 | ||
| 69 | #define STA_PPSJITTER	0x0200 | ||
| 70 | #define STA_PPSWANDER	0x0400 | ||
| 71 | #define STA_PPSERROR	0x0800 | ||
| 72 | |||
| 73 | #define STA_CLOCKERR	0x1000 | ||
| 74 | #define STA_NANO	0x2000 | ||
| 75 | #define STA_MODE	0x4000 | ||
| 76 | #define STA_CLK		0x8000 | ||
| 77 | |||
| 78 | #define STA_RONLY (STA_PPSSIGNAL | STA_PPSJITTER | STA_PPSWANDER | \ | ||
| 79 | STA_PPSERROR | STA_CLOCKERR | STA_NANO | STA_MODE | STA_CLK) | ||
| 80 | |||
| 81 | #define TIME_OK		0 | ||
| 82 | #define TIME_INS	1 | ||
| 83 | #define TIME_DEL	2 | ||
| 84 | #define TIME_OOP	3 | ||
| 85 | #define TIME_WAIT	4 | ||
| 86 | #define TIME_ERROR	5 | ||
| 87 | #define TIME_BAD	TIME_ERROR | ||
| 88 | |||
| 89 | #define MAXTC		6 | ||
| 90 | |||
| 91 | int adjtimex(struct timex *); | ||
| 92 | int clock_adjtime(clockid_t, struct timex *); | ||
| 93 | |||
| 94 | #if _REDIR_TIME64 | ||
| 95 | __REDIR(adjtimex, __adjtimex_time64); | ||
| 96 | __REDIR(clock_adjtime, __clock_adjtime64); | ||
| 97 | #endif | ||
| 98 | |||
| 99 | #ifdef __cplusplus | ||
| 100 | } | ||
| 101 | #endif | ||
| 102 | |||
| 103 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/ttydefaults.h created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #ifndef _SYS_TTYDEFAULTS_H | ||
| 2 | #define _SYS_TTYDEFAULTS_H | ||
| 3 | |||
| 4 | #define TTYDEF_IFLAG (BRKINT | ISTRIP | ICRNL | IMAXBEL | IXON | IXANY) | ||
| 5 | #define TTYDEF_OFLAG (OPOST | ONLCR | XTABS) | ||
| 6 | #define TTYDEF_LFLAG (ECHO | ICANON | ISIG | IEXTEN | ECHOE|ECHOKE|ECHOCTL) | ||
| 7 | #define TTYDEF_CFLAG (CREAD | CS7 | PARENB | HUPCL) | ||
| 8 | #define TTYDEF_SPEED (B9600) | ||
| 9 | #define CTRL(x) ((x)&037) | ||
| 10 | #define CEOF CTRL('d') | ||
| 11 | |||
| 12 | #define CEOL '\0' | ||
| 13 | #define CSTATUS '\0' | ||
| 14 | |||
| 15 | #define CERASE 0177 | ||
| 16 | #define CINTR CTRL('c') | ||
| 17 | #define CKILL CTRL('u') | ||
| 18 | #define CMIN 1 | ||
| 19 | #define CQUIT 034 | ||
| 20 | #define CSUSP CTRL('z') | ||
| 21 | #define CTIME 0 | ||
| 22 | #define CDSUSP CTRL('y') | ||
| 23 | #define CSTART CTRL('q') | ||
| 24 | #define CSTOP CTRL('s') | ||
| 25 | #define CLNEXT CTRL('v') | ||
| 26 | #define CDISCARD CTRL('o') | ||
| 27 | #define CWERASE CTRL('w') | ||
| 28 | #define CREPRINT CTRL('r') | ||
| 29 | #define CEOT CEOF | ||
| 30 | #define CBRK CEOL | ||
| 31 | #define CRPRNT CREPRINT | ||
| 32 | #define CFLUSH CDISCARD | ||
| 33 | |||
| 34 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/types.h created+85| ... | @@ -0,0 +1,85 @@ | ||
| 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/ucontext.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <ucontext.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/uio.h created+48| ... | @@ -0,0 +1,48 @@ | ||
| 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 _GNU_SOURCE | ||
| 40 | ssize_t process_vm_writev(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 41 | ssize_t process_vm_readv(pid_t, const struct iovec *, unsigned long, const struct iovec *, unsigned long, unsigned long); | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifdef __cplusplus | ||
| 45 | } | ||
| 46 | #endif | ||
| 47 | |||
| 48 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/un.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 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/sys/user.h created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #ifndef _SYS_USER_H | ||
| 2 | #define _SYS_USER_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <limits.h> | ||
| 8 | #include <stdint.h> | ||
| 9 | #include <unistd.h> | ||
| 10 | |||
| 11 | #include <bits/user.h> | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | } | ||
| 15 | #endif | ||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/utsname.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef	_SYS_UTSNAME_H | ||
| 2 | #define	_SYS_UTSNAME_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | struct utsname { | ||
| 11 | 	char sysname[65]; | ||
| 12 | 	char nodename[65]; | ||
| 13 | 	char release[65]; | ||
| 14 | 	char version[65]; | ||
| 15 | 	char machine[65]; | ||
| 16 | #ifdef _GNU_SOURCE | ||
| 17 | 	char domainname[65]; | ||
| 18 | #else | ||
| 19 | 	char __domainname[65]; | ||
| 20 | #endif | ||
| 21 | }; | ||
| 22 | |||
| 23 | int uname (struct utsname *); | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/vfs.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <sys/statfs.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/vt.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <bits/vt.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sys/wait.h created+67| ... | @@ -0,0 +1,67 @@ | ||
| 1 | #ifndef	_SYS_WAIT_H | ||
| 2 | #define	_SYS_WAIT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #define __NEED_pid_t | ||
| 10 | #define __NEED_id_t | ||
| 11 | #include <bits/alltypes.h> | ||
| 12 | |||
| 13 | typedef enum { | ||
| 14 | 	P_ALL = 0, | ||
| 15 | 	P_PID = 1, | ||
| 16 | 	P_PGID = 2, | ||
| 17 | 	P_PIDFD = 3 | ||
| 18 | } idtype_t; | ||
| 19 | |||
| 20 | pid_t wait (int *); | ||
| 21 | pid_t waitpid (pid_t, int *, int ); | ||
| 22 | |||
| 23 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 24 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 25 | || defined(_BSD_SOURCE) | ||
| 26 | #include <signal.h> | ||
| 27 | int waitid (idtype_t, id_t, siginfo_t *, int); | ||
| 28 | #endif | ||
| 29 | |||
| 30 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 31 | #include <sys/resource.h> | ||
| 32 | pid_t wait3 (int *, int, struct rusage *); | ||
| 33 | pid_t wait4 (pid_t, int *, int, struct rusage *); | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #define WNOHANG 1 | ||
| 37 | #define WUNTRACED 2 | ||
| 38 | |||
| 39 | #define WSTOPPED 2 | ||
| 40 | #define WEXITED 4 | ||
| 41 | #define WCONTINUED 8 | ||
| 42 | #define WNOWAIT 0x1000000 | ||
| 43 | |||
| 44 | #define __WNOTHREAD 0x20000000 | ||
| 45 | #define __WALL 0x40000000 | ||
| 46 | #define __WCLONE 0x80000000 | ||
| 47 | |||
| 48 | #define WEXITSTATUS(s) (((s) & 0xff00) >> 8) | ||
| 49 | #define WTERMSIG(s) ((s) & 0x7f) | ||
| 50 | #define WSTOPSIG(s) WEXITSTATUS(s) | ||
| 51 | #define WCOREDUMP(s) ((s) & 0x80) | ||
| 52 | #define WIFEXITED(s) (!WTERMSIG(s)) | ||
| 53 | #define WIFSTOPPED(s) ((short)((((s)&0xffff)*0x10001)>>8) > 0x7f00) | ||
| 54 | #define WIFSIGNALED(s) (((s)&0xffff)-1U < 0xffu) | ||
| 55 | #define WIFCONTINUED(s) ((s) == 0xffff) | ||
| 56 | |||
| 57 | #if _REDIR_TIME64 | ||
| 58 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 59 | __REDIR(wait3, __wait3_time64); | ||
| 60 | __REDIR(wait4, __wait4_time64); | ||
| 61 | #endif | ||
| 62 | #endif | ||
| 63 | |||
| 64 | #ifdef __cplusplus | ||
| 65 | } | ||
| 66 | #endif | ||
| 67 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/sys/xattr.h created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #ifndef	_SYS_XATTR_H | ||
| 2 | #define	_SYS_XATTR_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #define __NEED_ssize_t | ||
| 8 | #define __NEED_size_t | ||
| 9 | #include <bits/alltypes.h> | ||
| 10 | |||
| 11 | #define XATTR_CREATE 1 | ||
| 12 | #define XATTR_REPLACE 2 | ||
| 13 | |||
| 14 | ssize_t getxattr(const char *, const char *, void *, size_t); | ||
| 15 | ssize_t lgetxattr(const char *, const char *, void *, size_t); | ||
| 16 | ssize_t fgetxattr(int, const char *, void *, size_t); | ||
| 17 | ssize_t listxattr(const char *, char *, size_t); | ||
| 18 | ssize_t llistxattr(const char *, char *, size_t); | ||
| 19 | ssize_t flistxattr(int, char *, size_t); | ||
| 20 | int setxattr(const char *, const char *, const void *, size_t, int); | ||
| 21 | int lsetxattr(const char *, const char *, const void *, size_t, int); | ||
| 22 | int fsetxattr(int, const char *, const void *, size_t, int); | ||
| 23 | int removexattr(const char *, const char *); | ||
| 24 | int lremovexattr(const char *, const char *); | ||
| 25 | int fremovexattr(int, const char *); | ||
| 26 | |||
| 27 | #define __UAPI_DEF_XATTR 0 | ||
| 28 | |||
| 29 | #ifdef __cplusplus | ||
| 30 | } | ||
| 31 | #endif | ||
| 32 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/syscall.h created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | #include <sys/syscall.h> | ||
lib/libc/wasi/libc-top-half/musl/include/sysexits.h created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #ifndef	_SYSEXITS_H | ||
| 2 | #define _SYSEXITS_H | ||
| 3 | #define EX_OK 0 | ||
| 4 | #define EX__BASE 64 | ||
| 5 | #define EX_USAGE 64 | ||
| 6 | #define EX_DATAERR 65 | ||
| 7 | #define EX_NOINPUT 66 | ||
| 8 | #define EX_NOUSER 67 | ||
| 9 | #define EX_NOHOST 68 | ||
| 10 | #define EX_UNAVAILABLE 69 | ||
| 11 | #define EX_SOFTWARE 70 | ||
| 12 | #define EX_OSERR 71 | ||
| 13 | #define EX_OSFILE 72 | ||
| 14 | #define EX_CANTCREAT 73 | ||
| 15 | #define EX_IOERR 74 | ||
| 16 | #define EX_TEMPFAIL 75 | ||
| 17 | #define EX_PROTOCOL 76 | ||
| 18 | #define EX_NOPERM 77 | ||
| 19 | #define EX_CONFIG 78 | ||
| 20 | #define EX__MAX 78 | ||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/syslog.h created+100| ... | @@ -0,0 +1,100 @@ | ||
| 1 | #ifndef _SYSLOG_H | ||
| 2 | #define _SYSLOG_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define LOG_EMERG 0 | ||
| 11 | #define LOG_ALERT 1 | ||
| 12 | #define LOG_CRIT 2 | ||
| 13 | #define LOG_ERR 3 | ||
| 14 | #define LOG_WARNING 4 | ||
| 15 | #define LOG_NOTICE 5 | ||
| 16 | #define LOG_INFO 6 | ||
| 17 | #define LOG_DEBUG 7 | ||
| 18 | |||
| 19 | #define LOG_PRIMASK 7 | ||
| 20 | #define LOG_PRI(p) ((p)&LOG_PRIMASK) | ||
| 21 | #define	LOG_MAKEPRI(f, p) (((f)<<3)|(p)) | ||
| 22 | |||
| 23 | #define LOG_MASK(p) (1<<(p)) | ||
| 24 | #define LOG_UPTO(p) ((1<<((p)+1))-1) | ||
| 25 | |||
| 26 | #define LOG_KERN (0<<3) | ||
| 27 | #define LOG_USER (1<<3) | ||
| 28 | #define LOG_MAIL (2<<3) | ||
| 29 | #define LOG_DAEMON (3<<3) | ||
| 30 | #define LOG_AUTH (4<<3) | ||
| 31 | #define LOG_SYSLOG (5<<3) | ||
| 32 | #define LOG_LPR (6<<3) | ||
| 33 | #define LOG_NEWS (7<<3) | ||
| 34 | #define LOG_UUCP (8<<3) | ||
| 35 | #define LOG_CRON (9<<3) | ||
| 36 | #define	LOG_AUTHPRIV (10<<3) | ||
| 37 | #define	LOG_FTP (11<<3) | ||
| 38 | |||
| 39 | #define LOG_LOCAL0 (16<<3) | ||
| 40 | #define LOG_LOCAL1 (17<<3) | ||
| 41 | #define LOG_LOCAL2 (18<<3) | ||
| 42 | #define LOG_LOCAL3 (19<<3) | ||
| 43 | #define LOG_LOCAL4 (20<<3) | ||
| 44 | #define LOG_LOCAL5 (21<<3) | ||
| 45 | #define LOG_LOCAL6 (22<<3) | ||
| 46 | #define LOG_LOCAL7 (23<<3) | ||
| 47 | |||
| 48 | #define LOG_NFACILITIES 24 | ||
| 49 | #define LOG_FACMASK 0x3f8 | ||
| 50 | #define LOG_FAC(p) (((p)&LOG_FACMASK)>>3) | ||
| 51 | |||
| 52 | #define LOG_PID 0x01 | ||
| 53 | #define LOG_CONS 0x02 | ||
| 54 | #define LOG_ODELAY 0x04 | ||
| 55 | #define LOG_NDELAY 0x08 | ||
| 56 | #define LOG_NOWAIT 0x10 | ||
| 57 | #define LOG_PERROR 0x20 | ||
| 58 | |||
| 59 | void closelog (void); | ||
| 60 | void openlog (const char *, int, int); | ||
| 61 | int setlogmask (int); | ||
| 62 | void syslog (int, const char *, ...); | ||
| 63 | |||
| 64 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 65 | #define _PATH_LOG "/dev/log" | ||
| 66 | #define __NEED_va_list | ||
| 67 | #include <bits/alltypes.h> | ||
| 68 | void vsyslog (int, const char *, va_list); | ||
| 69 | #if defined(SYSLOG_NAMES) | ||
| 70 | #define	INTERNAL_NOPRI 0x10 | ||
| 71 | #define	INTERNAL_MARK (LOG_NFACILITIES<<3) | ||
| 72 | typedef struct { | ||
| 73 | 	char *c_name; | ||
| 74 | 	int c_val; | ||
| 75 | } CODE; | ||
| 76 | #define prioritynames ((CODE *)(const CODE []){ \ | ||
| 77 | 	{ "alert", LOG_ALERT }, { "crit", LOG_CRIT }, { "debug", LOG_DEBUG }, \ | ||
| 78 | 	{ "emerg", LOG_EMERG }, { "err", LOG_ERR }, { "error", LOG_ERR }, \ | ||
| 79 | 	{ "info", LOG_INFO }, { "none", INTERNAL_NOPRI }, \ | ||
| 80 | 	{ "notice", LOG_NOTICE }, { "panic", LOG_EMERG }, \ | ||
| 81 | 	{ "warn", LOG_WARNING }, { "warning", LOG_WARNING }, { 0, -1 } }) | ||
| 82 | #define facilitynames ((CODE *)(const CODE []){ \ | ||
| 83 | 	{ "auth", LOG_AUTH }, { "authpriv", LOG_AUTHPRIV }, \ | ||
| 84 | 	{ "cron", LOG_CRON }, { "daemon", LOG_DAEMON }, { "ftp", LOG_FTP }, \ | ||
| 85 | 	{ "kern", LOG_KERN }, { "lpr", LOG_LPR }, { "mail", LOG_MAIL }, \ | ||
| 86 | 	{ "mark", INTERNAL_MARK }, { "news", LOG_NEWS }, \ | ||
| 87 | 	{ "security", LOG_AUTH }, { "syslog", LOG_SYSLOG }, \ | ||
| 88 | 	{ "user", LOG_USER }, { "uucp", LOG_UUCP }, \ | ||
| 89 | 	{ "local0", LOG_LOCAL0 }, { "local1", LOG_LOCAL1 }, \ | ||
| 90 | 	{ "local2", LOG_LOCAL2 }, { "local3", LOG_LOCAL3 }, \ | ||
| 91 | 	{ "local4", LOG_LOCAL4 }, { "local5", LOG_LOCAL5 }, \ | ||
| 92 | 	{ "local6", LOG_LOCAL6 }, { "local7", LOG_LOCAL7 }, { 0, -1 } }) | ||
| 93 | #endif | ||
| 94 | #endif | ||
| 95 | |||
| 96 | #ifdef __cplusplus | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/tar.h created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #ifndef	_TAR_H | ||
| 2 | #define	_TAR_H | ||
| 3 | |||
| 4 | #define TSUID 04000 | ||
| 5 | #define TSGID 02000 | ||
| 6 | #define TSVTX 01000 | ||
| 7 | #define TUREAD 00400 | ||
| 8 | #define TUWRITE 00200 | ||
| 9 | #define TUEXEC 00100 | ||
| 10 | #define TGREAD 00040 | ||
| 11 | #define TGWRITE 00020 | ||
| 12 | #define TGEXEC 00010 | ||
| 13 | #define TOREAD 00004 | ||
| 14 | #define TOWRITE 00002 | ||
| 15 | #define TOEXEC 00001 | ||
| 16 | |||
| 17 | #define REGTYPE '0' | ||
| 18 | #define AREGTYPE '\0' | ||
| 19 | #define LNKTYPE '1' | ||
| 20 | #define SYMTYPE '2' | ||
| 21 | #define CHRTYPE '3' | ||
| 22 | #define BLKTYPE '4' | ||
| 23 | #define DIRTYPE '5' | ||
| 24 | #define FIFOTYPE '6' | ||
| 25 | #define CONTTYPE '7' | ||
| 26 | |||
| 27 | #define TMAGIC "ustar" | ||
| 28 | #define TMAGLEN 6 | ||
| 29 | |||
| 30 | #define TVERSION "00" | ||
| 31 | #define TVERSLEN 2 | ||
| 32 | |||
| 33 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/termios.h created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | #ifndef	_TERMIOS_H | ||
| 2 | #define	_TERMIOS_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_pid_t | ||
| 11 | #define __NEED_struct_winsize | ||
| 12 | |||
| 13 | #include <bits/alltypes.h> | ||
| 14 | |||
| 15 | typedef unsigned char cc_t; | ||
| 16 | typedef unsigned int speed_t; | ||
| 17 | typedef unsigned int tcflag_t; | ||
| 18 | |||
| 19 | #define NCCS 32 | ||
| 20 | |||
| 21 | #include <bits/termios.h> | ||
| 22 | |||
| 23 | speed_t cfgetospeed (const struct termios *); | ||
| 24 | speed_t cfgetispeed (const struct termios *); | ||
| 25 | int cfsetospeed (struct termios *, speed_t); | ||
| 26 | int cfsetispeed (struct termios *, speed_t); | ||
| 27 | |||
| 28 | int tcgetattr (int, struct termios *); | ||
| 29 | int tcsetattr (int, int, const struct termios *); | ||
| 30 | |||
| 31 | int tcgetwinsize (int, struct winsize *); | ||
| 32 | int tcsetwinsize (int, const struct winsize *); | ||
| 33 | |||
| 34 | int tcsendbreak (int, int); | ||
| 35 | int tcdrain (int); | ||
| 36 | int tcflush (int, int); | ||
| 37 | int tcflow (int, int); | ||
| 38 | |||
| 39 | pid_t tcgetsid (int); | ||
| 40 | |||
| 41 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 42 | void cfmakeraw(struct termios *); | ||
| 43 | int cfsetspeed(struct termios *, speed_t); | ||
| 44 | #endif | ||
| 45 | |||
| 46 | #ifdef __cplusplus | ||
| 47 | } | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/tgmath.h created+270| ... | @@ -0,0 +1,270 @@ | ||
| 1 | #ifndef _TGMATH_H | ||
| 2 | #define _TGMATH_H | ||
| 3 | |||
| 4 | /* | ||
| 5 | the return types are only correct with gcc (__GNUC__) | ||
| 6 | otherwise they are long double or long double complex | ||
| 7 | |||
| 8 | the long double version of a function is never chosen when | ||
| 9 | sizeof(double) == sizeof(long double) | ||
| 10 | (but the return type is set correctly with gcc) | ||
| 11 | */ | ||
| 12 | |||
| 13 | #include <math.h> | ||
| 14 | #include <complex.h> | ||
| 15 | |||
| 16 | #define __IS_FP(x) (sizeof((x)+1ULL) == sizeof((x)+1.0f)) | ||
| 17 | #define __IS_CX(x) (__IS_FP(x) && sizeof(x) == sizeof((x)+I)) | ||
| 18 | #define __IS_REAL(x) (__IS_FP(x) && 2*sizeof(x) == sizeof((x)+I)) | ||
| 19 | |||
| 20 | #define __FLT(x) (__IS_REAL(x) && sizeof(x) == sizeof(float)) | ||
| 21 | #define __LDBL(x) (__IS_REAL(x) && sizeof(x) == sizeof(long double) && sizeof(long double) != sizeof(double)) | ||
| 22 | |||
| 23 | #define __FLTCX(x) (__IS_CX(x) && sizeof(x) == sizeof(float complex)) | ||
| 24 | #define __DBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(double complex)) | ||
| 25 | #define __LDBLCX(x) (__IS_CX(x) && sizeof(x) == sizeof(long double complex) && sizeof(long double) != sizeof(double)) | ||
| 26 | |||
| 27 | /* return type */ | ||
| 28 | |||
| 29 | #ifdef __GNUC__ | ||
| 30 | /* | ||
| 31 | the result must be casted to the right type | ||
| 32 | (otherwise the result type is determined by the conversion | ||
| 33 | rules applied to all the function return types so it is long | ||
| 34 | double or long double complex except for integral functions) | ||
| 35 | |||
| 36 | this cannot be done in c99, so the typeof gcc extension is | ||
| 37 | used and that the type of ?: depends on wether an operand is | ||
| 38 | a null pointer constant or not | ||
| 39 | (in c11 _Generic can be used) | ||
| 40 | |||
| 41 | the c arguments below must be integer constant expressions | ||
| 42 | so they can be in null pointer constants | ||
| 43 | (__IS_FP above was carefully chosen this way) | ||
| 44 | */ | ||
| 45 | /* if c then t else void */ | ||
| 46 | #define __type1(c,t) __typeof__(*(0?(t*)0:(void*)!(c))) | ||
| 47 | /* if c then t1 else t2 */ | ||
| 48 | #define __type2(c,t1,t2) __typeof__(*(0?(__type1(c,t1)*)0:(__type1(!(c),t2)*)0)) | ||
| 49 | /* cast to double when x is integral, otherwise use typeof(x) */ | ||
| 50 | #define __RETCAST(x) ( \ | ||
| 51 | 	__type2(__IS_FP(x), __typeof__(x), double)) | ||
| 52 | /* 2 args case, should work for complex types (cpow) */ | ||
| 53 | #define __RETCAST_2(x, y) ( \ | ||
| 54 | 	__type2(__IS_FP(x) && __IS_FP(y), \ | ||
| 55 | 		__typeof__((x)+(y)), \ | ||
| 56 | 		__typeof__((x)+(y)+1.0))) | ||
| 57 | /* 3 args case (fma only) */ | ||
| 58 | #define __RETCAST_3(x, y, z) ( \ | ||
| 59 | 	__type2(__IS_FP(x) && __IS_FP(y) && __IS_FP(z), \ | ||
| 60 | 		__typeof__((x)+(y)+(z)), \ | ||
| 61 | 		__typeof__((x)+(y)+(z)+1.0))) | ||
| 62 | /* drop complex from the type of x */ | ||
| 63 | /* TODO: wrong when sizeof(long double)==sizeof(double) */ | ||
| 64 | #define __RETCAST_REAL(x) ( \ | ||
| 65 | 	__type2(__IS_FP(x) && sizeof((x)+I) == sizeof(float complex), float, \ | ||
| 66 | 	__type2(sizeof((x)+1.0+I) == sizeof(double complex), double, \ | ||
| 67 | 		long double))) | ||
| 68 | /* add complex to the type of x */ | ||
| 69 | #define __RETCAST_CX(x) (__typeof__(__RETCAST(x)0+I)) | ||
| 70 | #else | ||
| 71 | #define __RETCAST(x) | ||
| 72 | #define __RETCAST_2(x, y) | ||
| 73 | #define __RETCAST_3(x, y, z) | ||
| 74 | #define __RETCAST_REAL(x) | ||
| 75 | #define __RETCAST_CX(x) | ||
| 76 | #endif | ||
| 77 | |||
| 78 | /* function selection */ | ||
| 79 | |||
| 80 | #define __tg_real_nocast(fun, x) ( \ | ||
| 81 | 	__FLT(x) ? fun ## f (x) : \ | ||
| 82 | 	__LDBL(x) ? fun ## l (x) : \ | ||
| 83 | 	fun(x) ) | ||
| 84 | |||
| 85 | #define __tg_real(fun, x) (__RETCAST(x)__tg_real_nocast(fun, x)) | ||
| 86 | |||
| 87 | #define __tg_real_2_1(fun, x, y) (__RETCAST(x)( \ | ||
| 88 | 	__FLT(x) ? fun ## f (x, y) : \ | ||
| 89 | 	__LDBL(x) ? fun ## l (x, y) : \ | ||
| 90 | 	fun(x, y) )) | ||
| 91 | |||
| 92 | #define __tg_real_2(fun, x, y) (__RETCAST_2(x, y)( \ | ||
| 93 | 	__FLT(x) && __FLT(y) ? fun ## f (x, y) : \ | ||
| 94 | 	__LDBL((x)+(y)) ? fun ## l (x, y) : \ | ||
| 95 | 	fun(x, y) )) | ||
| 96 | |||
| 97 | #define __tg_complex(fun, x) (__RETCAST_CX(x)( \ | ||
| 98 | 	__FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : \ | ||
| 99 | 	__LDBLCX((x)+I) ? fun ## l (x) : \ | ||
| 100 | 	fun(x) )) | ||
| 101 | |||
| 102 | #define __tg_complex_retreal(fun, x) (__RETCAST_REAL(x)( \ | ||
| 103 | 	__FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : \ | ||
| 104 | 	__LDBLCX((x)+I) ? fun ## l (x) : \ | ||
| 105 | 	fun(x) )) | ||
| 106 | |||
| 107 | #define __tg_real_complex(fun, x) (__RETCAST(x)( \ | ||
| 108 | 	__FLTCX(x) ? c ## fun ## f (x) : \ | ||
| 109 | 	__DBLCX(x) ? c ## fun (x) : \ | ||
| 110 | 	__LDBLCX(x) ? c ## fun ## l (x) : \ | ||
| 111 | 	__FLT(x) ? fun ## f (x) : \ | ||
| 112 | 	__LDBL(x) ? fun ## l (x) : \ | ||
| 113 | 	fun(x) )) | ||
| 114 | |||
| 115 | /* special cases */ | ||
| 116 | |||
| 117 | #define __tg_real_remquo(x, y, z) (__RETCAST_2(x, y)( \ | ||
| 118 | 	__FLT(x) && __FLT(y) ? remquof(x, y, z) : \ | ||
| 119 | 	__LDBL((x)+(y)) ? remquol(x, y, z) : \ | ||
| 120 | 	remquo(x, y, z) )) | ||
| 121 | |||
| 122 | #define __tg_real_fma(x, y, z) (__RETCAST_3(x, y, z)( \ | ||
| 123 | 	__FLT(x) && __FLT(y) && __FLT(z) ? fmaf(x, y, z) : \ | ||
| 124 | 	__LDBL((x)+(y)+(z)) ? fmal(x, y, z) : \ | ||
| 125 | 	fma(x, y, z) )) | ||
| 126 | |||
| 127 | #define __tg_real_complex_pow(x, y) (__RETCAST_2(x, y)( \ | ||
| 128 | 	__FLTCX((x)+(y)) && __IS_FP(x) && __IS_FP(y) ? cpowf(x, y) : \ | ||
| 129 | 	__FLTCX((x)+(y)) ? cpow(x, y) : \ | ||
| 130 | 	__DBLCX((x)+(y)) ? cpow(x, y) : \ | ||
| 131 | 	__LDBLCX((x)+(y)) ? cpowl(x, y) : \ | ||
| 132 | 	__FLT(x) && __FLT(y) ? powf(x, y) : \ | ||
| 133 | 	__LDBL((x)+(y)) ? powl(x, y) : \ | ||
| 134 | 	pow(x, y) )) | ||
| 135 | |||
| 136 | #define __tg_real_complex_fabs(x) (__RETCAST_REAL(x)( \ | ||
| 137 | 	__FLTCX(x) ? cabsf(x) : \ | ||
| 138 | 	__DBLCX(x) ? cabs(x) : \ | ||
| 139 | 	__LDBLCX(x) ? cabsl(x) : \ | ||
| 140 | 	__FLT(x) ? fabsf(x) : \ | ||
| 141 | 	__LDBL(x) ? fabsl(x) : \ | ||
| 142 | 	fabs(x) )) | ||
| 143 | |||
| 144 | /* suppress any macros in math.h or complex.h */ | ||
| 145 | |||
| 146 | #undef acos | ||
| 147 | #undef acosh | ||
| 148 | #undef asin | ||
| 149 | #undef asinh | ||
| 150 | #undef atan | ||
| 151 | #undef atan2 | ||
| 152 | #undef atanh | ||
| 153 | #undef carg | ||
| 154 | #undef cbrt | ||
| 155 | #undef ceil | ||
| 156 | #undef cimag | ||
| 157 | #undef conj | ||
| 158 | #undef copysign | ||
| 159 | #undef cos | ||
| 160 | #undef cosh | ||
| 161 | #undef cproj | ||
| 162 | #undef creal | ||
| 163 | #undef erf | ||
| 164 | #undef erfc | ||
| 165 | #undef exp | ||
| 166 | #undef exp2 | ||
| 167 | #undef expm1 | ||
| 168 | #undef fabs | ||
| 169 | #undef fdim | ||
| 170 | #undef floor | ||
| 171 | #undef fma | ||
| 172 | #undef fmax | ||
| 173 | #undef fmin | ||
| 174 | #undef fmod | ||
| 175 | #undef frexp | ||
| 176 | #undef hypot | ||
| 177 | #undef ilogb | ||
| 178 | #undef ldexp | ||
| 179 | #undef lgamma | ||
| 180 | #undef llrint | ||
| 181 | #undef llround | ||
| 182 | #undef log | ||
| 183 | #undef log10 | ||
| 184 | #undef log1p | ||
| 185 | #undef log2 | ||
| 186 | #undef logb | ||
| 187 | #undef lrint | ||
| 188 | #undef lround | ||
| 189 | #undef nearbyint | ||
| 190 | #undef nextafter | ||
| 191 | #undef nexttoward | ||
| 192 | #undef pow | ||
| 193 | #undef remainder | ||
| 194 | #undef remquo | ||
| 195 | #undef rint | ||
| 196 | #undef round | ||
| 197 | #undef scalbln | ||
| 198 | #undef scalbn | ||
| 199 | #undef sin | ||
| 200 | #undef sinh | ||
| 201 | #undef sqrt | ||
| 202 | #undef tan | ||
| 203 | #undef tanh | ||
| 204 | #undef tgamma | ||
| 205 | #undef trunc | ||
| 206 | |||
| 207 | /* tg functions */ | ||
| 208 | |||
| 209 | #define acos(x) __tg_real_complex(acos, (x)) | ||
| 210 | #define acosh(x) __tg_real_complex(acosh, (x)) | ||
| 211 | #define asin(x) __tg_real_complex(asin, (x)) | ||
| 212 | #define asinh(x) __tg_real_complex(asinh, (x)) | ||
| 213 | #define atan(x) __tg_real_complex(atan, (x)) | ||
| 214 | #define atan2(x,y) __tg_real_2(atan2, (x), (y)) | ||
| 215 | #define atanh(x) __tg_real_complex(atanh, (x)) | ||
| 216 | #define carg(x) __tg_complex_retreal(carg, (x)) | ||
| 217 | #define cbrt(x) __tg_real(cbrt, (x)) | ||
| 218 | #define ceil(x) __tg_real(ceil, (x)) | ||
| 219 | #define cimag(x) __tg_complex_retreal(cimag, (x)) | ||
| 220 | #define conj(x) __tg_complex(conj, (x)) | ||
| 221 | #define copysign(x,y) __tg_real_2(copysign, (x), (y)) | ||
| 222 | #define cos(x) __tg_real_complex(cos, (x)) | ||
| 223 | #define cosh(x) __tg_real_complex(cosh, (x)) | ||
| 224 | #define cproj(x) __tg_complex(cproj, (x)) | ||
| 225 | #define creal(x) __tg_complex_retreal(creal, (x)) | ||
| 226 | #define erf(x) __tg_real(erf, (x)) | ||
| 227 | #define erfc(x) __tg_real(erfc, (x)) | ||
| 228 | #define exp(x) __tg_real_complex(exp, (x)) | ||
| 229 | #define exp2(x) __tg_real(exp2, (x)) | ||
| 230 | #define expm1(x) __tg_real(expm1, (x)) | ||
| 231 | #define fabs(x) __tg_real_complex_fabs(x) | ||
| 232 | #define fdim(x,y) __tg_real_2(fdim, (x), (y)) | ||
| 233 | #define floor(x) __tg_real(floor, (x)) | ||
| 234 | #define fma(x,y,z) __tg_real_fma((x), (y), (z)) | ||
| 235 | #define fmax(x,y) __tg_real_2(fmax, (x), (y)) | ||
| 236 | #define fmin(x,y) __tg_real_2(fmin, (x), (y)) | ||
| 237 | #define fmod(x,y) __tg_real_2(fmod, (x), (y)) | ||
| 238 | #define frexp(x,y) __tg_real_2_1(frexp, (x), (y)) | ||
| 239 | #define hypot(x,y) __tg_real_2(hypot, (x), (y)) | ||
| 240 | #define ilogb(x) __tg_real_nocast(ilogb, (x)) | ||
| 241 | #define ldexp(x,y) __tg_real_2_1(ldexp, (x), (y)) | ||
| 242 | #define lgamma(x) __tg_real(lgamma, (x)) | ||
| 243 | #define llrint(x) __tg_real_nocast(llrint, (x)) | ||
| 244 | #define llround(x) __tg_real_nocast(llround, (x)) | ||
| 245 | #define log(x) __tg_real_complex(log, (x)) | ||
| 246 | #define log10(x) __tg_real(log10, (x)) | ||
| 247 | #define log1p(x) __tg_real(log1p, (x)) | ||
| 248 | #define log2(x) __tg_real(log2, (x)) | ||
| 249 | #define logb(x) __tg_real(logb, (x)) | ||
| 250 | #define lrint(x) __tg_real_nocast(lrint, (x)) | ||
| 251 | #define lround(x) __tg_real_nocast(lround, (x)) | ||
| 252 | #define nearbyint(x) __tg_real(nearbyint, (x)) | ||
| 253 | #define nextafter(x,y) __tg_real_2(nextafter, (x), (y)) | ||
| 254 | #define nexttoward(x,y) __tg_real_2(nexttoward, (x), (y)) | ||
| 255 | #define pow(x,y) __tg_real_complex_pow((x), (y)) | ||
| 256 | #define remainder(x,y) __tg_real_2(remainder, (x), (y)) | ||
| 257 | #define remquo(x,y,z) __tg_real_remquo((x), (y), (z)) | ||
| 258 | #define rint(x) __tg_real(rint, (x)) | ||
| 259 | #define round(x) __tg_real(round, (x)) | ||
| 260 | #define scalbln(x,y) __tg_real_2_1(scalbln, (x), (y)) | ||
| 261 | #define scalbn(x,y) __tg_real_2_1(scalbn, (x), (y)) | ||
| 262 | #define sin(x) __tg_real_complex(sin, (x)) | ||
| 263 | #define sinh(x) __tg_real_complex(sinh, (x)) | ||
| 264 | #define sqrt(x) __tg_real_complex(sqrt, (x)) | ||
| 265 | #define tan(x) __tg_real_complex(tan, (x)) | ||
| 266 | #define tanh(x) __tg_real_complex(tanh, (x)) | ||
| 267 | #define tgamma(x) __tg_real(tgamma, (x)) | ||
| 268 | #define trunc(x) __tg_real(trunc, (x)) | ||
| 269 | |||
| 270 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/threads.h created+93| ... | @@ -0,0 +1,93 @@ | ||
| 1 | #ifndef _THREADS_H | ||
| 2 | #define _THREADS_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <time.h> | ||
| 6 | |||
| 7 | #ifdef __cplusplus | ||
| 8 | extern "C" { | ||
| 9 | typedef unsigned long thrd_t; | ||
| 10 | #else | ||
| 11 | typedef struct __pthread *thrd_t; | ||
| 12 | #define thread_local _Thread_local | ||
| 13 | #endif | ||
| 14 | |||
| 15 | typedef int once_flag; | ||
| 16 | typedef unsigned tss_t; | ||
| 17 | typedef int (*thrd_start_t)(void *); | ||
| 18 | typedef void (*tss_dtor_t)(void *); | ||
| 19 | |||
| 20 | #define __NEED_cnd_t | ||
| 21 | #define __NEED_mtx_t | ||
| 22 | |||
| 23 | #include <bits/alltypes.h> | ||
| 24 | |||
| 25 | #define TSS_DTOR_ITERATIONS 4 | ||
| 26 | |||
| 27 | enum { | ||
| 28 | 	thrd_success = 0, | ||
| 29 | 	thrd_busy = 1, | ||
| 30 | 	thrd_error = 2, | ||
| 31 | 	thrd_nomem = 3, | ||
| 32 | 	thrd_timedout = 4, | ||
| 33 | }; | ||
| 34 | |||
| 35 | enum { | ||
| 36 | 	mtx_plain = 0, | ||
| 37 | 	mtx_recursive = 1, | ||
| 38 | 	mtx_timed = 2, | ||
| 39 | }; | ||
| 40 | |||
| 41 | #define ONCE_FLAG_INIT 0 | ||
| 42 | |||
| 43 | int thrd_create(thrd_t *, thrd_start_t, void *); | ||
| 44 | _Noreturn void thrd_exit(int); | ||
| 45 | |||
| 46 | int thrd_detach(thrd_t); | ||
| 47 | int thrd_join(thrd_t, int *); | ||
| 48 | |||
| 49 | int thrd_sleep(const struct timespec *, struct timespec *); | ||
| 50 | void thrd_yield(void); | ||
| 51 | |||
| 52 | thrd_t thrd_current(void); | ||
| 53 | int thrd_equal(thrd_t, thrd_t); | ||
| 54 | #ifndef __cplusplus | ||
| 55 | #define thrd_equal(A, B) ((A) == (B)) | ||
| 56 | #endif | ||
| 57 | |||
| 58 | void call_once(once_flag *, void (*)(void)); | ||
| 59 | |||
| 60 | int mtx_init(mtx_t *, int); | ||
| 61 | void mtx_destroy(mtx_t *); | ||
| 62 | |||
| 63 | int mtx_lock(mtx_t *); | ||
| 64 | int mtx_timedlock(mtx_t *__restrict, const struct timespec *__restrict); | ||
| 65 | int mtx_trylock(mtx_t *); | ||
| 66 | int mtx_unlock(mtx_t *); | ||
| 67 | |||
| 68 | int cnd_init(cnd_t *); | ||
| 69 | void cnd_destroy(cnd_t *); | ||
| 70 | |||
| 71 | int cnd_broadcast(cnd_t *); | ||
| 72 | int cnd_signal(cnd_t *); | ||
| 73 | |||
| 74 | int cnd_timedwait(cnd_t *__restrict, mtx_t *__restrict, const struct timespec *__restrict); | ||
| 75 | int cnd_wait(cnd_t *, mtx_t *); | ||
| 76 | |||
| 77 | int tss_create(tss_t *, tss_dtor_t); | ||
| 78 | void tss_delete(tss_t); | ||
| 79 | |||
| 80 | int tss_set(tss_t, void *); | ||
| 81 | void *tss_get(tss_t); | ||
| 82 | |||
| 83 | #if _REDIR_TIME64 | ||
| 84 | __REDIR(thrd_sleep, __thrd_sleep_time64); | ||
| 85 | __REDIR(mtx_timedlock, __mtx_timedlock_time64); | ||
| 86 | __REDIR(cnd_timedwait, __cnd_timedwait_time64); | ||
| 87 | #endif | ||
| 88 | |||
| 89 | #ifdef __cplusplus | ||
| 90 | } | ||
| 91 | #endif | ||
| 92 | |||
| 93 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/time.h created+202| ... | @@ -0,0 +1,202 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 12 | #define NULL 0L | ||
| 13 | #else | ||
| 14 | #define NULL ((void*)0) | ||
| 15 | #endif | ||
| 16 | #else | ||
| 17 | #define __need_NULL | ||
| 18 | #include <stddef.h> | ||
| 19 | #endif | ||
| 20 | |||
| 21 | |||
| 22 | #define __NEED_size_t | ||
| 23 | #define __NEED_time_t | ||
| 24 | #define __NEED_clock_t | ||
| 25 | #define __NEED_struct_timespec | ||
| 26 | |||
| 27 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 28 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 29 | || defined(_BSD_SOURCE) | ||
| 30 | #define __NEED_clockid_t | ||
| 31 | #define __NEED_timer_t | ||
| 32 | #define __NEED_pid_t | ||
| 33 | #define __NEED_locale_t | ||
| 34 | #endif | ||
| 35 | |||
| 36 | #include <bits/alltypes.h> | ||
| 37 | |||
| 38 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 39 | #define __tm_gmtoff tm_gmtoff | ||
| 40 | #define __tm_zone tm_zone | ||
| 41 | #endif | ||
| 42 | |||
| 43 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 44 | struct tm { | ||
| 45 | 	int tm_sec; | ||
| 46 | 	int tm_min; | ||
| 47 | 	int tm_hour; | ||
| 48 | 	int tm_mday; | ||
| 49 | 	int tm_mon; | ||
| 50 | 	int tm_year; | ||
| 51 | 	int tm_wday; | ||
| 52 | 	int tm_yday; | ||
| 53 | 	int tm_isdst; | ||
| 54 | 	long __tm_gmtoff; | ||
| 55 | 	const char *__tm_zone; | ||
| 56 | }; | ||
| 57 | #else | ||
| 58 | #include <__header_time.h> | ||
| 59 | #endif | ||
| 60 | |||
| 61 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_PROCESS_CLOCKS) | ||
| 62 | clock_t clock (void); | ||
| 63 | #else | ||
| 64 | __attribute__((__deprecated__( | ||
| 65 | "WASI lacks process-associated clocks; to enable emulation of the `clock` function using " | ||
| 66 | "the wall clock, which isn't sensitive to whether the program is running or suspended, " | ||
| 67 | "compile with -D_WASI_EMULATED_PROCESS_CLOCKS and link with -lwasi-emulated-process-clocks" | ||
| 68 | ))) | ||
| 69 | clock_t clock (void); | ||
| 70 | #endif | ||
| 71 | time_t time (time_t *); | ||
| 72 | double difftime (time_t, time_t); | ||
| 73 | time_t mktime (struct tm *); | ||
| 74 | size_t strftime (char *__restrict, size_t, const char *__restrict, const struct tm *__restrict); | ||
| 75 | struct tm *gmtime (const time_t *); | ||
| 76 | struct tm *localtime (const time_t *); | ||
| 77 | char *asctime (const struct tm *); | ||
| 78 | char *ctime (const time_t *); | ||
| 79 | int timespec_get(struct timespec *, int); | ||
| 80 | |||
| 81 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 82 | #define CLOCKS_PER_SEC 1000000L | ||
| 83 | |||
| 84 | #define TIME_UTC 1 | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 88 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 89 | || defined(_BSD_SOURCE) | ||
| 90 | |||
| 91 | size_t strftime_l (char * __restrict, size_t, const char * __restrict, const struct tm * __restrict, locale_t); | ||
| 92 | |||
| 93 | struct tm *gmtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 94 | struct tm *localtime_r (const time_t *__restrict, struct tm *__restrict); | ||
| 95 | char *asctime_r (const struct tm *__restrict, char *__restrict); | ||
| 96 | char *ctime_r (const time_t *, char *); | ||
| 97 | |||
| 98 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 99 | void tzset (void); | ||
| 100 | #endif | ||
| 101 | |||
| 102 | struct itimerspec { | ||
| 103 | 	struct timespec it_interval; | ||
| 104 | 	struct timespec it_value; | ||
| 105 | }; | ||
| 106 | |||
| 107 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 108 | #define CLOCK_REALTIME 0 | ||
| 109 | #define CLOCK_MONOTONIC 1 | ||
| 110 | #define CLOCK_PROCESS_CPUTIME_ID 2 | ||
| 111 | #define CLOCK_THREAD_CPUTIME_ID 3 | ||
| 112 | #define CLOCK_MONOTONIC_RAW 4 | ||
| 113 | #define CLOCK_REALTIME_COARSE 5 | ||
| 114 | #define CLOCK_MONOTONIC_COARSE 6 | ||
| 115 | #define CLOCK_BOOTTIME 7 | ||
| 116 | #define CLOCK_REALTIME_ALARM 8 | ||
| 117 | #define CLOCK_BOOTTIME_ALARM 9 | ||
| 118 | #define CLOCK_SGI_CYCLE 10 | ||
| 119 | #define CLOCK_TAI 11 | ||
| 120 | |||
| 121 | #define TIMER_ABSTIME 1 | ||
| 122 | #endif | ||
| 123 | |||
| 124 | int nanosleep (const struct timespec *, struct timespec *); | ||
| 125 | int clock_getres (clockid_t, struct timespec *); | ||
| 126 | int clock_gettime (clockid_t, struct timespec *); | ||
| 127 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_settime */ | ||
| 128 | int clock_settime (clockid_t, const struct timespec *); | ||
| 129 | #endif | ||
| 130 | int clock_nanosleep (clockid_t, int, const struct timespec *, struct timespec *); | ||
| 131 | #ifdef __wasilibc_unmodified_upstream /* WASI has no clock_getcpuclockid */ | ||
| 132 | int clock_getcpuclockid (pid_t, clockid_t *); | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timers */ | ||
| 136 | struct sigevent; | ||
| 137 | int timer_create (clockid_t, struct sigevent *__restrict, timer_t *__restrict); | ||
| 138 | int timer_delete (timer_t); | ||
| 139 | int timer_settime (timer_t, int, const struct itimerspec *__restrict, struct itimerspec *__restrict); | ||
| 140 | int timer_gettime (timer_t, struct itimerspec *); | ||
| 141 | int timer_getoverrun (timer_t); | ||
| 142 | #endif | ||
| 143 | |||
| 144 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 145 | extern char *tzname[2]; | ||
| 146 | #endif | ||
| 147 | |||
| 148 | #endif | ||
| 149 | |||
| 150 | |||
| 151 | #if defined(_XOPEN_SOURCE) || defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 152 | char *strptime (const char *__restrict, const char *__restrict, struct tm *__restrict); | ||
| 153 | #ifdef __wasilibc_unmodified_upstream /* WASI has no timezone tables */ | ||
| 154 | extern int daylight; | ||
| 155 | extern long timezone; | ||
| 156 | #endif | ||
| 157 | extern int getdate_err; | ||
| 158 | struct tm *getdate (const char *); | ||
| 159 | #endif | ||
| 160 | |||
| 161 | |||
| 162 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 163 | #ifdef __wasilibc_unmodified_upstream /* WASI has no stime */ | ||
| 164 | int stime(const time_t *); | ||
| 165 | #endif | ||
| 166 | time_t timegm(struct tm *); | ||
| 167 | #endif | ||
| 168 | |||
| 169 | #if _REDIR_TIME64 | ||
| 170 | __REDIR(time, __time64); | ||
| 171 | __REDIR(difftime, __difftime64); | ||
| 172 | __REDIR(mktime, __mktime64); | ||
| 173 | __REDIR(gmtime, __gmtime64); | ||
| 174 | __REDIR(localtime, __localtime64); | ||
| 175 | __REDIR(ctime, __ctime64); | ||
| 176 | __REDIR(timespec_get, __timespec_get_time64); | ||
| 177 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 178 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ | ||
| 179 | || defined(_BSD_SOURCE) | ||
| 180 | __REDIR(gmtime_r, __gmtime64_r); | ||
| 181 | __REDIR(localtime_r, __localtime64_r); | ||
| 182 | __REDIR(ctime_r, __ctime64_r); | ||
| 183 | __REDIR(nanosleep, __nanosleep_time64); | ||
| 184 | __REDIR(clock_getres, __clock_getres_time64); | ||
| 185 | __REDIR(clock_gettime, __clock_gettime64); | ||
| 186 | __REDIR(clock_settime, __clock_settime64); | ||
| 187 | __REDIR(clock_nanosleep, __clock_nanosleep_time64); | ||
| 188 | __REDIR(timer_settime, __timer_settime64); | ||
| 189 | __REDIR(timer_gettime, __timer_gettime64); | ||
| 190 | #endif | ||
| 191 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 192 | __REDIR(stime, __stime64); | ||
| 193 | __REDIR(timegm, __timegm_time64); | ||
| 194 | #endif | ||
| 195 | #endif | ||
| 196 | |||
| 197 | #ifdef __cplusplus | ||
| 198 | } | ||
| 199 | #endif | ||
| 200 | |||
| 201 | |||
| 202 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/uchar.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef _UCHAR_H | ||
| 2 | #define _UCHAR_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #if __cplusplus < 201103L | ||
| 9 | typedef unsigned short char16_t; | ||
| 10 | typedef unsigned char32_t; | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #define __NEED_mbstate_t | ||
| 14 | #define __NEED_size_t | ||
| 15 | |||
| 16 | #include <features.h> | ||
| 17 | #include <bits/alltypes.h> | ||
| 18 | |||
| 19 | size_t c16rtomb(char *__restrict, char16_t, mbstate_t *__restrict); | ||
| 20 | size_t mbrtoc16(char16_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 21 | |||
| 22 | size_t c32rtomb(char *__restrict, char32_t, mbstate_t *__restrict); | ||
| 23 | size_t mbrtoc32(char32_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/ucontext.h created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #ifndef _UCONTEXT_H | ||
| 2 | #define _UCONTEXT_H | ||
| 3 | #ifdef __cplusplus | ||
| 4 | extern "C" { | ||
| 5 | #endif | ||
| 6 | |||
| 7 | #include <features.h> | ||
| 8 | |||
| 9 | #include <signal.h> | ||
| 10 | |||
| 11 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 12 | #define NGREG (sizeof(gregset_t)/sizeof(greg_t)) | ||
| 13 | #endif | ||
| 14 | |||
| 15 | struct __ucontext; | ||
| 16 | |||
| 17 | int getcontext(struct __ucontext *); | ||
| 18 | void makecontext(struct __ucontext *, void (*)(), int, ...); | ||
| 19 | int setcontext(const struct __ucontext *); | ||
| 20 | int swapcontext(struct __ucontext *, const struct __ucontext *); | ||
| 21 | |||
| 22 | #ifdef __cplusplus | ||
| 23 | } | ||
| 24 | #endif | ||
| 25 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/ulimit.h created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #ifndef _ULIMIT_H | ||
| 2 | #define _ULIMIT_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #define UL_GETFSIZE 1 | ||
| 9 | #define UL_SETFSIZE 2 | ||
| 10 | |||
| 11 | long ulimit (int, ...); | ||
| 12 | |||
| 13 | #ifdef __cplusplus | ||
| 14 | } | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/unistd.h created+571| ... | @@ -0,0 +1,571 @@ | ||
| 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 | #else | ||
| 19 | #include <__header_unistd.h> | ||
| 20 | #endif | ||
| 21 | |||
| 22 | #ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */ | ||
| 23 | #ifdef __cplusplus | ||
| 24 | #define NULL 0L | ||
| 25 | #else | ||
| 26 | #define NULL ((void*)0) | ||
| 27 | #endif | ||
| 28 | #else | ||
| 29 | #define __need_NULL | ||
| 30 | #include <stddef.h> | ||
| 31 | #endif | ||
| 32 | |||
| 33 | #define __NEED_size_t | ||
| 34 | #define __NEED_ssize_t | ||
| 35 | #define __NEED_uid_t | ||
| 36 | #define __NEED_gid_t | ||
| 37 | #define __NEED_off_t | ||
| 38 | #define __NEED_pid_t | ||
| 39 | #define __NEED_intptr_t | ||
| 40 | #define __NEED_useconds_t | ||
| 41 | |||
| 42 | #include <bits/alltypes.h> | ||
| 43 | |||
| 44 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pipe */ | ||
| 45 | int pipe(int [2]); | ||
| 46 | int pipe2(int [2], int); | ||
| 47 | #endif | ||
| 48 | int close(int); | ||
| 49 | int posix_close(int, int); | ||
| 50 | #ifdef __wasilibc_unmodified_upstream /* WASI has no dup */ | ||
| 51 | int dup(int); | ||
| 52 | int dup2(int, int); | ||
| 53 | int dup3(int, int, int); | ||
| 54 | #endif | ||
| 55 | off_t lseek(int, off_t, int); | ||
| 56 | #ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */ | ||
| 57 | #else | ||
| 58 | off_t __wasilibc_tell(int); | ||
| 59 | |||
| 60 | #ifndef __cplusplus | ||
| 61 | /* | ||
| 62 | * Optimize lseek in the case where it's just returning the current offset. | ||
| 63 | * This avoids importing `__wasi_fd_seek` altogether in many common cases. | ||
| 64 | * | ||
| 65 | * But don't do this for C++ because a simple macro wouldn't handle namespaces | ||
| 66 | * correctly: | ||
| 67 | * - User code could qualify the `lseek` call with `::`. | ||
| 68 | * - There may be another `lseek` in scope from a `using` declaration. | ||
| 69 | */ | ||
| 70 | #define lseek(fd, offset, whence) \ | ||
| 71 | ({ \ | ||
| 72 | off_t __f = (fd); \ | ||
| 73 | off_t __o = (offset); \ | ||
| 74 | off_t __w = (whence); \ | ||
| 75 | __builtin_constant_p((offset)) && \ | ||
| 76 | __builtin_constant_p((whence)) && \ | ||
| 77 | __o == 0 && \ | ||
| 78 | __w == SEEK_CUR \ | ||
| 79 | ? __wasilibc_tell(__f) \ | ||
| 80 | : lseek(__f, __o, __w); \ | ||
| 81 | }) | ||
| 82 | #endif | ||
| 83 | #endif | ||
| 84 | int fsync(int); | ||
| 85 | int fdatasync(int); | ||
| 86 | |||
| 87 | ssize_t read(int, void *, size_t); | ||
| 88 | ssize_t write(int, const void *, size_t); | ||
| 89 | ssize_t pread(int, void *, size_t, off_t); | ||
| 90 | ssize_t pwrite(int, const void *, size_t, off_t); | ||
| 91 | |||
| 92 | #ifdef __wasilibc_unmodified_upstream /* WASI has no chown */ | ||
| 93 | int chown(const char *, uid_t, gid_t); | ||
| 94 | int fchown(int, uid_t, gid_t); | ||
| 95 | int lchown(const char *, uid_t, gid_t); | ||
| 96 | int fchownat(int, const char *, uid_t, gid_t, int); | ||
| 97 | #endif | ||
| 98 | |||
| 99 | int link(const char *, const char *); | ||
| 100 | int linkat(int, const char *, int, const char *, int); | ||
| 101 | int symlink(const char *, const char *); | ||
| 102 | int symlinkat(const char *, int, const char *); | ||
| 103 | ssize_t readlink(const char *__restrict, char *__restrict, size_t); | ||
| 104 | ssize_t readlinkat(int, const char *__restrict, char *__restrict, size_t); | ||
| 105 | int unlink(const char *); | ||
| 106 | int unlinkat(int, const char *, int); | ||
| 107 | int rmdir(const char *); | ||
| 108 | int truncate(const char *, off_t); | ||
| 109 | int ftruncate(int, off_t); | ||
| 110 | |||
| 111 | #ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */ | ||
| 112 | #define F_OK 0 | ||
| 113 | #define R_OK 4 | ||
| 114 | #define W_OK 2 | ||
| 115 | #define X_OK 1 | ||
| 116 | #endif | ||
| 117 | |||
| 118 | int access(const char *, int); | ||
| 119 | int faccessat(int, const char *, int, int); | ||
| 120 | |||
| 121 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fchdir */ | ||
| 122 | int fchdir(int); | ||
| 123 | #endif | ||
| 124 | int chdir(const char *); | ||
| 125 | char *getcwd(char *, size_t); | ||
| 126 | |||
| 127 | #ifdef __wasilibc_unmodified_upstream /* WASI has no signals */ | ||
| 128 | unsigned alarm(unsigned); | ||
| 129 | #endif | ||
| 130 | unsigned sleep(unsigned); | ||
| 131 | #ifdef __wasilibc_unmodified_upstream /* WASI has no pause */ | ||
| 132 | int pause(void); | ||
| 133 | #endif | ||
| 134 | |||
| 135 | #ifdef __wasilibc_unmodified_upstream /* WASI has no fork/exec */ | ||
| 136 | pid_t fork(void); | ||
| 137 | pid_t _Fork(void); | ||
| 138 | int execve(const char *, char *const [], char *const []); | ||
| 139 | int execv(const char *, char *const []); | ||
| 140 | int execle(const char *, const char *, ...); | ||
| 141 | int execl(const char *, const char *, ...); | ||
| 142 | int execvp(const char *, char *const []); | ||
| 143 | int execlp(const char *, const char *, ...); | ||
| 144 | int fexecve(int, char *const [], char *const []); | ||
| 145 | #endif | ||
| 146 | _Noreturn void _exit(int); | ||
| 147 | |||
| 148 | #if defined(__wasilibc_unmodified_upstream) || defined(_WASI_EMULATED_GETPID) | ||
| 149 | pid_t getpid(void); | ||
| 150 | #else | ||
| 151 | __attribute__((__deprecated__( | ||
| 152 | "WASI lacks process identifiers; to enable emulation of the `getpid` function using " | ||
| 153 | "a placeholder value, which doesn't reflect the host PID of the program, " | ||
| 154 | "compile with -D_WASI_EMULATED_GETPID and link with -lwasi-emulated-getpid" | ||
| 155 | ))) | ||
| 156 | pid_t getpid(void); | ||
| 157 | #endif | ||
| 158 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getpid etc. */ | ||
| 159 | pid_t getppid(void); | ||
| 160 | pid_t getpgrp(void); | ||
| 161 | pid_t getpgid(pid_t); | ||
| 162 | int setpgid(pid_t, pid_t); | ||
| 163 | pid_t setsid(void); | ||
| 164 | pid_t getsid(pid_t); | ||
| 165 | #endif | ||
| 166 | #ifdef __wasilibc_unmodified_upstream /* WASI has no ttyname */ | ||
| 167 | char *ttyname(int); | ||
| 168 | int ttyname_r(int, char *, size_t); | ||
| 169 | #endif | ||
| 170 | int isatty(int); | ||
| 171 | #ifdef __wasilibc_unmodified_upstream /* WASI has no process groups */ | ||
| 172 | pid_t tcgetpgrp(int); | ||
| 173 | int tcsetpgrp(int, pid_t); | ||
| 174 | #endif | ||
| 175 | |||
| 176 | #ifdef __wasilibc_unmodified_upstream /* WASI has no getuid etc. */ | ||
| 177 | uid_t getuid(void); | ||
| 178 | uid_t geteuid(void); | ||
| 179 | gid_t getgid(void); | ||
| 180 | gid_t getegid(void); | ||
| 181 | int getgroups(int, gid_t []); | ||
| 182 | int setuid(uid_t); | ||
| 183 | int seteuid(uid_t); | ||
| 184 | int setgid(gid_t); | ||
| 185 | int setegid(gid_t); | ||
| 186 | #endif | ||
| 187 | |||
| 188 | char *getlogin(void); | ||
| 189 | int getlogin_r(char *, size_t); | ||
| 190 | int gethostname(char *, size_t); | ||
| 191 | char *ctermid(char *); | ||
| 192 | |||
| 193 | int getopt(int, char * const [], const char *); | ||
| 194 | extern char *optarg; | ||
| 195 | extern int optind, opterr, optopt; | ||
| 196 | |||
| 197 | long pathconf(const char *, int); | ||
| 198 | long fpathconf(int, int); | ||
| 199 | long sysconf(int); | ||
| 200 | size_t confstr(int, char *, size_t); | ||
| 201 | |||
| 202 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 203 | #define F_ULOCK 0 | ||
| 204 | #define F_LOCK 1 | ||
| 205 | #define F_TLOCK 2 | ||
| 206 | #define F_TEST 3 | ||
| 207 | #ifdef __wasilibc_unmodified_upstream /* WASI has no setreuid */ | ||
| 208 | int setreuid(uid_t, uid_t); | ||
| 209 | int setregid(gid_t, gid_t); | ||
| 210 | #endif | ||
| 211 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 212 | int lockf(int, int, off_t); | ||
| 213 | #endif | ||
| 214 | long gethostid(void); | ||
| 215 | #ifdef __wasilibc_unmodified_upstream /* WASI has no nice, sync, or setpgrp */ | ||
| 216 | int nice(int); | ||
| 217 | void sync(void); | ||
| 218 | pid_t setpgrp(void); | ||
| 219 | #endif | ||
| 220 | char *crypt(const char *, const char *); | ||
| 221 | void encrypt(char *, int); | ||
| 222 | void swab(const void *__restrict, void *__restrict, ssize_t); | ||
| 223 | #endif | ||
| 224 | |||
| 225 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) \ | ||
| 226 | || (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE+0 < 700) | ||
| 227 | int usleep(unsigned); | ||
| 228 | unsigned ualarm(unsigned, unsigned); | ||
| 229 | #endif | ||
| 230 | |||
| 231 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 232 | #define L_SET 0 | ||
| 233 | #define L_INCR 1 | ||
| 234 | #define L_XTND 2 | ||
| 235 | #ifdef __wasilibc_unmodified_upstream /* WASI has no brk */ | ||
| 236 | int brk(void *); | ||
| 237 | #endif | ||
| 238 | void *sbrk(intptr_t); | ||
| 239 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 240 | pid_t vfork(void); | ||
| 241 | int vhangup(void); | ||
| 242 | int chroot(const char *); | ||
| 243 | int getpagesize(void); | ||
| 244 | int getdtablesize(void); | ||
| 245 | int sethostname(const char *, size_t); | ||
| 246 | int getdomainname(char *, size_t); | ||
| 247 | int setdomainname(const char *, size_t); | ||
| 248 | int setgroups(size_t, const gid_t *); | ||
| 249 | char *getpass(const char *); | ||
| 250 | int daemon(int, int); | ||
| 251 | void setusershell(void); | ||
| 252 | void endusershell(void); | ||
| 253 | char *getusershell(void); | ||
| 254 | int acct(const char *); | ||
| 255 | long syscall(long, ...); | ||
| 256 | int execvpe(const char *, char *const [], char *const []); | ||
| 257 | int issetugid(void); | ||
| 258 | #endif | ||
| 259 | int getentropy(void *, size_t); | ||
| 260 | extern int optreset; | ||
| 261 | #endif | ||
| 262 | |||
| 263 | #ifdef _GNU_SOURCE | ||
| 264 | extern char **environ; | ||
| 265 | #ifdef __wasilibc_unmodified_upstream /* WASI has no get/setresuid */ | ||
| 266 | int setresuid(uid_t, uid_t, uid_t); | ||
| 267 | int setresgid(gid_t, gid_t, gid_t); | ||
| 268 | int getresuid(uid_t *, uid_t *, uid_t *); | ||
| 269 | int getresgid(gid_t *, gid_t *, gid_t *); | ||
| 270 | #endif | ||
| 271 | #ifdef __wasilibc_unmodified_upstream /* WASI has no cwd */ | ||
| 272 | char *get_current_dir_name(void); | ||
| 273 | #endif | ||
| 274 | #ifdef __wasilibc_unmodified_upstream /* WASI has no syncfs */ | ||
| 275 | int syncfs(int); | ||
| 276 | #endif | ||
| 277 | #ifdef __wasilibc_unmodified_upstream /* WASI has no eaccess */ | ||
| 278 | int euidaccess(const char *, int); | ||
| 279 | int eaccess(const char *, int); | ||
| 280 | ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned); | ||
| 281 | pid_t gettid(void); | ||
| 282 | #endif | ||
| 283 | #endif | ||
| 284 | |||
| 285 | #if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE) | ||
| 286 | #define lseek64 lseek | ||
| 287 | #define pread64 pread | ||
| 288 | #define pwrite64 pwrite | ||
| 289 | #ifdef __wasilibc_unmodified_upstream /* WASI has no truncate */ | ||
| 290 | #define truncate64 truncate | ||
| 291 | #endif | ||
| 292 | #define ftruncate64 ftruncate | ||
| 293 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX file locking */ | ||
| 294 | #define lockf64 lockf | ||
| 295 | #endif | ||
| 296 | #define off64_t off_t | ||
| 297 | #endif | ||
| 298 | |||
| 299 | #define POSIX_CLOSE_RESTART 0 | ||
| 300 | |||
| 301 | #define _XOPEN_VERSION 700 | ||
| 302 | #define _XOPEN_UNIX 1 | ||
| 303 | #define _XOPEN_ENH_I18N 1 | ||
| 304 | |||
| 305 | #define _POSIX_VERSION 200809L | ||
| 306 | #define _POSIX2_VERSION _POSIX_VERSION | ||
| 307 | |||
| 308 | #define _POSIX_ADVISORY_INFO _POSIX_VERSION | ||
| 309 | #define _POSIX_CHOWN_RESTRICTED 1 | ||
| 310 | #define _POSIX_IPV6 _POSIX_VERSION | ||
| 311 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes, mmap, or mq */ | ||
| 312 | #define _POSIX_JOB_CONTROL 1 | ||
| 313 | #define _POSIX_MAPPED_FILES _POSIX_VERSION | ||
| 314 | #define _POSIX_MEMLOCK _POSIX_VERSION | ||
| 315 | #define _POSIX_MEMLOCK_RANGE _POSIX_VERSION | ||
| 316 | #define _POSIX_MEMORY_PROTECTION _POSIX_VERSION | ||
| 317 | #define _POSIX_MESSAGE_PASSING _POSIX_VERSION | ||
| 318 | #endif | ||
| 319 | #define _POSIX_FSYNC _POSIX_VERSION | ||
| 320 | #define _POSIX_NO_TRUNC 1 | ||
| 321 | #ifdef __wasilibc_unmodified_upstream /* WASI has no raw sockets */ | ||
| 322 | #define _POSIX_RAW_SOCKETS _POSIX_VERSION | ||
| 323 | #endif | ||
| 324 | #define _POSIX_REALTIME_SIGNALS _POSIX_VERSION | ||
| 325 | #define _POSIX_REGEXP 1 | ||
| 326 | #ifdef __wasilibc_unmodified_upstream /* WASI has no processes */ | ||
| 327 | #define _POSIX_SAVED_IDS 1 | ||
| 328 | #define _POSIX_SHELL 1 | ||
| 329 | #define _POSIX_SPAWN _POSIX_VERSION | ||
| 330 | #endif | ||
| 331 | #define _POSIX_VDISABLE 0 | ||
| 332 | |||
| 333 | #define _POSIX_THREADS _POSIX_VERSION | ||
| 334 | #define _POSIX_THREAD_PROCESS_SHARED _POSIX_VERSION | ||
| 335 | #define _POSIX_THREAD_SAFE_FUNCTIONS _POSIX_VERSION | ||
| 336 | #define _POSIX_THREAD_ATTR_STACKADDR _POSIX_VERSION | ||
| 337 | #define _POSIX_THREAD_ATTR_STACKSIZE _POSIX_VERSION | ||
| 338 | #define _POSIX_THREAD_PRIORITY_SCHEDULING _POSIX_VERSION | ||
| 339 | #define _POSIX_THREAD_CPUTIME _POSIX_VERSION | ||
| 340 | #define _POSIX_TIMERS _POSIX_VERSION | ||
| 341 | #define _POSIX_TIMEOUTS _POSIX_VERSION | ||
| 342 | #define _POSIX_MONOTONIC_CLOCK _POSIX_VERSION | ||
| 343 | #define _POSIX_CPUTIME _POSIX_VERSION | ||
| 344 | #define _POSIX_CLOCK_SELECTION _POSIX_VERSION | ||
| 345 | #define _POSIX_BARRIERS _POSIX_VERSION | ||
| 346 | #define _POSIX_SPIN_LOCKS _POSIX_VERSION | ||
| 347 | #define _POSIX_READER_WRITER_LOCKS _POSIX_VERSION | ||
| 348 | #ifdef __wasilibc_unmodified_upstream /* WASI has no POSIX async I/O, semaphores, or shared memory */ | ||
| 349 | #define _POSIX_ASYNCHRONOUS_IO _POSIX_VERSION | ||
| 350 | #define _POSIX_SEMAPHORES _POSIX_VERSION | ||
| 351 | #define _POSIX_SHARED_MEMORY_OBJECTS _POSIX_VERSION | ||
| 352 | #endif | ||
| 353 | |||
| 354 | #define _POSIX2_C_BIND _POSIX_VERSION | ||
| 355 | |||
| 356 | #include <bits/posix.h> | ||
| 357 | |||
| 358 | |||
| 359 | |||
| 360 | #define _PC_LINK_MAX	0 | ||
| 361 | #define _PC_MAX_CANON	1 | ||
| 362 | #define _PC_MAX_INPUT	2 | ||
| 363 | #define _PC_NAME_MAX	3 | ||
| 364 | #define _PC_PATH_MAX	4 | ||
| 365 | #define _PC_PIPE_BUF	5 | ||
| 366 | #define _PC_CHOWN_RESTRICTED	6 | ||
| 367 | #define _PC_NO_TRUNC	7 | ||
| 368 | #define _PC_VDISABLE	8 | ||
| 369 | #define _PC_SYNC_IO	9 | ||
| 370 | #define _PC_ASYNC_IO	10 | ||
| 371 | #define _PC_PRIO_IO	11 | ||
| 372 | #define _PC_SOCK_MAXBUF	12 | ||
| 373 | #define _PC_FILESIZEBITS	13 | ||
| 374 | #define _PC_REC_INCR_XFER_SIZE	14 | ||
| 375 | #define _PC_REC_MAX_XFER_SIZE	15 | ||
| 376 | #define _PC_REC_MIN_XFER_SIZE	16 | ||
| 377 | #define _PC_REC_XFER_ALIGN	17 | ||
| 378 | #define _PC_ALLOC_SIZE_MIN	18 | ||
| 379 | #define _PC_SYMLINK_MAX	19 | ||
| 380 | #define _PC_2_SYMLINKS	20 | ||
| 381 | |||
| 382 | #define _SC_ARG_MAX	0 | ||
| 383 | #define _SC_CHILD_MAX	1 | ||
| 384 | #define _SC_CLK_TCK	2 | ||
| 385 | #define _SC_NGROUPS_MAX	3 | ||
| 386 | #define _SC_OPEN_MAX	4 | ||
| 387 | #define _SC_STREAM_MAX	5 | ||
| 388 | #define _SC_TZNAME_MAX	6 | ||
| 389 | #define _SC_JOB_CONTROL	7 | ||
| 390 | #define _SC_SAVED_IDS	8 | ||
| 391 | #define _SC_REALTIME_SIGNALS	9 | ||
| 392 | #define _SC_PRIORITY_SCHEDULING	10 | ||
| 393 | #define _SC_TIMERS	11 | ||
| 394 | #define _SC_ASYNCHRONOUS_IO	12 | ||
| 395 | #define _SC_PRIORITIZED_IO	13 | ||
| 396 | #define _SC_SYNCHRONIZED_IO	14 | ||
| 397 | #define _SC_FSYNC	15 | ||
| 398 | #define _SC_MAPPED_FILES	16 | ||
| 399 | #define _SC_MEMLOCK	17 | ||
| 400 | #define _SC_MEMLOCK_RANGE	18 | ||
| 401 | #define _SC_MEMORY_PROTECTION	19 | ||
| 402 | #define _SC_MESSAGE_PASSING	20 | ||
| 403 | #define _SC_SEMAPHORES	21 | ||
| 404 | #define _SC_SHARED_MEMORY_OBJECTS	22 | ||
| 405 | #define _SC_AIO_LISTIO_MAX	23 | ||
| 406 | #define _SC_AIO_MAX	24 | ||
| 407 | #define _SC_AIO_PRIO_DELTA_MAX	25 | ||
| 408 | #define _SC_DELAYTIMER_MAX	26 | ||
| 409 | #define _SC_MQ_OPEN_MAX	27 | ||
| 410 | #define _SC_MQ_PRIO_MAX	28 | ||
| 411 | #define _SC_VERSION	29 | ||
| 412 | #define _SC_PAGE_SIZE	30 | ||
| 413 | #define _SC_PAGESIZE	30 /* !! */ | ||
| 414 | #define _SC_RTSIG_MAX	31 | ||
| 415 | #define _SC_SEM_NSEMS_MAX	32 | ||
| 416 | #define _SC_SEM_VALUE_MAX	33 | ||
| 417 | #define _SC_SIGQUEUE_MAX	34 | ||
| 418 | #define _SC_TIMER_MAX	35 | ||
| 419 | #define _SC_BC_BASE_MAX	36 | ||
| 420 | #define _SC_BC_DIM_MAX	37 | ||
| 421 | #define _SC_BC_SCALE_MAX	38 | ||
| 422 | #define _SC_BC_STRING_MAX	39 | ||
| 423 | #define _SC_COLL_WEIGHTS_MAX	40 | ||
| 424 | #define _SC_EXPR_NEST_MAX	42 | ||
| 425 | #define _SC_LINE_MAX	43 | ||
| 426 | #define _SC_RE_DUP_MAX	44 | ||
| 427 | #define _SC_2_VERSION	46 | ||
| 428 | #define _SC_2_C_BIND	47 | ||
| 429 | #define _SC_2_C_DEV	48 | ||
| 430 | #define _SC_2_FORT_DEV	49 | ||
| 431 | #define _SC_2_FORT_RUN	50 | ||
| 432 | #define _SC_2_SW_DEV	51 | ||
| 433 | #define _SC_2_LOCALEDEF	52 | ||
| 434 | #define _SC_UIO_MAXIOV	60 /* !! */ | ||
| 435 | #define _SC_IOV_MAX	60 | ||
| 436 | #define _SC_THREADS	67 | ||
| 437 | #define _SC_THREAD_SAFE_FUNCTIONS	68 | ||
| 438 | #define _SC_GETGR_R_SIZE_MAX	69 | ||
| 439 | #define _SC_GETPW_R_SIZE_MAX	70 | ||
| 440 | #define _SC_LOGIN_NAME_MAX	71 | ||
| 441 | #define _SC_TTY_NAME_MAX	72 | ||
| 442 | #define _SC_THREAD_DESTRUCTOR_ITERATIONS	73 | ||
| 443 | #define _SC_THREAD_KEYS_MAX	74 | ||
| 444 | #define _SC_THREAD_STACK_MIN	75 | ||
| 445 | #define _SC_THREAD_THREADS_MAX	76 | ||
| 446 | #define _SC_THREAD_ATTR_STACKADDR	77 | ||
| 447 | #define _SC_THREAD_ATTR_STACKSIZE	78 | ||
| 448 | #define _SC_THREAD_PRIORITY_SCHEDULING	79 | ||
| 449 | #define _SC_THREAD_PRIO_INHERIT	80 | ||
| 450 | #define _SC_THREAD_PRIO_PROTECT	81 | ||
| 451 | #define _SC_THREAD_PROCESS_SHARED	82 | ||
| 452 | #define _SC_NPROCESSORS_CONF	83 | ||
| 453 | #define _SC_NPROCESSORS_ONLN	84 | ||
| 454 | #define _SC_PHYS_PAGES	85 | ||
| 455 | #define _SC_AVPHYS_PAGES	86 | ||
| 456 | #define _SC_ATEXIT_MAX	87 | ||
| 457 | #define _SC_PASS_MAX	88 | ||
| 458 | #define _SC_XOPEN_VERSION	89 | ||
| 459 | #define _SC_XOPEN_XCU_VERSION	90 | ||
| 460 | #define _SC_XOPEN_UNIX	91 | ||
| 461 | #define _SC_XOPEN_CRYPT	92 | ||
| 462 | #define _SC_XOPEN_ENH_I18N	93 | ||
| 463 | #define _SC_XOPEN_SHM	94 | ||
| 464 | #define _SC_2_CHAR_TERM	95 | ||
| 465 | #define _SC_2_UPE	97 | ||
| 466 | #define _SC_XOPEN_XPG2	98 | ||
| 467 | #define _SC_XOPEN_XPG3	99 | ||
| 468 | #define _SC_XOPEN_XPG4	100 | ||
| 469 | #define _SC_NZERO	109 | ||
| 470 | #define _SC_XBS5_ILP32_OFF32	125 | ||
| 471 | #define _SC_XBS5_ILP32_OFFBIG	126 | ||
| 472 | #define _SC_XBS5_LP64_OFF64	127 | ||
| 473 | #define _SC_XBS5_LPBIG_OFFBIG	128 | ||
| 474 | #define _SC_XOPEN_LEGACY	129 | ||
| 475 | #define _SC_XOPEN_REALTIME	130 | ||
| 476 | #define _SC_XOPEN_REALTIME_THREADS	131 | ||
| 477 | #define _SC_ADVISORY_INFO	132 | ||
| 478 | #define _SC_BARRIERS	133 | ||
| 479 | #define _SC_CLOCK_SELECTION	137 | ||
| 480 | #define _SC_CPUTIME	138 | ||
| 481 | #define _SC_THREAD_CPUTIME	139 | ||
| 482 | #define _SC_MONOTONIC_CLOCK	149 | ||
| 483 | #define _SC_READER_WRITER_LOCKS	153 | ||
| 484 | #define _SC_SPIN_LOCKS	154 | ||
| 485 | #define _SC_REGEXP	155 | ||
| 486 | #define _SC_SHELL	157 | ||
| 487 | #define _SC_SPAWN	159 | ||
| 488 | #define _SC_SPORADIC_SERVER	160 | ||
| 489 | #define _SC_THREAD_SPORADIC_SERVER	161 | ||
| 490 | #define _SC_TIMEOUTS	164 | ||
| 491 | #define _SC_TYPED_MEMORY_OBJECTS	165 | ||
| 492 | #define _SC_2_PBS	168 | ||
| 493 | #define _SC_2_PBS_ACCOUNTING	169 | ||
| 494 | #define _SC_2_PBS_LOCATE	170 | ||
| 495 | #define _SC_2_PBS_MESSAGE	171 | ||
| 496 | #define _SC_2_PBS_TRACK	172 | ||
| 497 | #define _SC_SYMLOOP_MAX	173 | ||
| 498 | #define _SC_STREAMS	174 | ||
| 499 | #define _SC_2_PBS_CHECKPOINT	175 | ||
| 500 | #define _SC_V6_ILP32_OFF32	176 | ||
| 501 | #define _SC_V6_ILP32_OFFBIG	177 | ||
| 502 | #define _SC_V6_LP64_OFF64	178 | ||
| 503 | #define _SC_V6_LPBIG_OFFBIG	179 | ||
| 504 | #define _SC_HOST_NAME_MAX	180 | ||
| 505 | #define _SC_TRACE	181 | ||
| 506 | #define _SC_TRACE_EVENT_FILTER	182 | ||
| 507 | #define _SC_TRACE_INHERIT	183 | ||
| 508 | #define _SC_TRACE_LOG	184 | ||
| 509 | |||
| 510 | #define _SC_IPV6	235 | ||
| 511 | #define _SC_RAW_SOCKETS	236 | ||
| 512 | #define _SC_V7_ILP32_OFF32	237 | ||
| 513 | #define _SC_V7_ILP32_OFFBIG	238 | ||
| 514 | #define _SC_V7_LP64_OFF64	239 | ||
| 515 | #define _SC_V7_LPBIG_OFFBIG	240 | ||
| 516 | #define _SC_SS_REPL_MAX	241 | ||
| 517 | #define _SC_TRACE_EVENT_NAME_MAX	242 | ||
| 518 | #define _SC_TRACE_NAME_MAX	243 | ||
| 519 | #define _SC_TRACE_SYS_MAX	244 | ||
| 520 | #define _SC_TRACE_USER_EVENT_MAX	245 | ||
| 521 | #define _SC_XOPEN_STREAMS	246 | ||
| 522 | #define _SC_THREAD_ROBUST_PRIO_INHERIT	247 | ||
| 523 | #define _SC_THREAD_ROBUST_PRIO_PROTECT	248 | ||
| 524 | |||
| 525 | #define _CS_PATH	0 | ||
| 526 | #define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS	1 | ||
| 527 | #define _CS_GNU_LIBC_VERSION	2 | ||
| 528 | #define _CS_GNU_LIBPTHREAD_VERSION	3 | ||
| 529 | #define _CS_POSIX_V5_WIDTH_RESTRICTED_ENVS	4 | ||
| 530 | #define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS	5 | ||
| 531 | |||
| 532 | #define _CS_POSIX_V6_ILP32_OFF32_CFLAGS	1116 | ||
| 533 | #define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS	1117 | ||
| 534 | #define _CS_POSIX_V6_ILP32_OFF32_LIBS	1118 | ||
| 535 | #define _CS_POSIX_V6_ILP32_OFF32_LINTFLAGS	1119 | ||
| 536 | #define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS	1120 | ||
| 537 | #define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS	1121 | ||
| 538 | #define _CS_POSIX_V6_ILP32_OFFBIG_LIBS	1122 | ||
| 539 | #define _CS_POSIX_V6_ILP32_OFFBIG_LINTFLAGS	1123 | ||
| 540 | #define _CS_POSIX_V6_LP64_OFF64_CFLAGS	1124 | ||
| 541 | #define _CS_POSIX_V6_LP64_OFF64_LDFLAGS	1125 | ||
| 542 | #define _CS_POSIX_V6_LP64_OFF64_LIBS	1126 | ||
| 543 | #define _CS_POSIX_V6_LP64_OFF64_LINTFLAGS	1127 | ||
| 544 | #define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS	1128 | ||
| 545 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS	1129 | ||
| 546 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS	1130 | ||
| 547 | #define _CS_POSIX_V6_LPBIG_OFFBIG_LINTFLAGS	1131 | ||
| 548 | #define _CS_POSIX_V7_ILP32_OFF32_CFLAGS	1132 | ||
| 549 | #define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS	1133 | ||
| 550 | #define _CS_POSIX_V7_ILP32_OFF32_LIBS	1134 | ||
| 551 | #define _CS_POSIX_V7_ILP32_OFF32_LINTFLAGS	1135 | ||
| 552 | #define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS	1136 | ||
| 553 | #define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS	1137 | ||
| 554 | #define _CS_POSIX_V7_ILP32_OFFBIG_LIBS	1138 | ||
| 555 | #define _CS_POSIX_V7_ILP32_OFFBIG_LINTFLAGS	1139 | ||
| 556 | #define _CS_POSIX_V7_LP64_OFF64_CFLAGS	1140 | ||
| 557 | #define _CS_POSIX_V7_LP64_OFF64_LDFLAGS	1141 | ||
| 558 | #define _CS_POSIX_V7_LP64_OFF64_LIBS	1142 | ||
| 559 | #define _CS_POSIX_V7_LP64_OFF64_LINTFLAGS	1143 | ||
| 560 | #define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS	1144 | ||
| 561 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS	1145 | ||
| 562 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS	1146 | ||
| 563 | #define _CS_POSIX_V7_LPBIG_OFFBIG_LINTFLAGS	1147 | ||
| 564 | #define _CS_V6_ENV	1148 | ||
| 565 | #define _CS_V7_ENV	1149 | ||
| 566 | |||
| 567 | #ifdef __cplusplus | ||
| 568 | } | ||
| 569 | #endif | ||
| 570 | |||
| 571 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/utime.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #ifndef	_UTIME_H | ||
| 2 | #define	_UTIME_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_time_t | ||
| 11 | |||
| 12 | #include <bits/alltypes.h> | ||
| 13 | |||
| 14 | struct utimbuf { | ||
| 15 | 	time_t actime; | ||
| 16 | 	time_t modtime; | ||
| 17 | }; | ||
| 18 | |||
| 19 | int utime (const char *, const struct utimbuf *); | ||
| 20 | |||
| 21 | #if _REDIR_TIME64 | ||
| 22 | __REDIR(utime, __utime64); | ||
| 23 | #endif | ||
| 24 | |||
| 25 | #ifdef __cplusplus | ||
| 26 | } | ||
| 27 | #endif | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/utmp.h created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | #ifndef _UTMP_H | ||
| 2 | #define _UTMP_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <utmpx.h> | ||
| 9 | |||
| 10 | #define ACCOUNTING 9 | ||
| 11 | #define UT_NAMESIZE 32 | ||
| 12 | #define UT_HOSTSIZE 256 | ||
| 13 | #define UT_LINESIZE 32 | ||
| 14 | |||
| 15 | struct lastlog { | ||
| 16 | 	time_t ll_time; | ||
| 17 | 	char ll_line[UT_LINESIZE]; | ||
| 18 | 	char ll_host[UT_HOSTSIZE]; | ||
| 19 | }; | ||
| 20 | |||
| 21 | #define ut_time ut_tv.tv_sec | ||
| 22 | #define ut_name ut_user | ||
| 23 | #define ut_addr ut_addr_v6[0] | ||
| 24 | #define utmp utmpx | ||
| 25 | #define e_exit __e_exit | ||
| 26 | #define e_termination __e_termination | ||
| 27 | |||
| 28 | void endutent(void); | ||
| 29 | struct utmp *getutent(void); | ||
| 30 | struct utmp *getutid(const struct utmp *); | ||
| 31 | struct utmp *getutline(const struct utmp *); | ||
| 32 | struct utmp *pututline(const struct utmp *); | ||
| 33 | void setutent(void); | ||
| 34 | |||
| 35 | void updwtmp(const char *, const struct utmp *); | ||
| 36 | int utmpname(const char *); | ||
| 37 | |||
| 38 | int login_tty(int); | ||
| 39 | |||
| 40 | #define _PATH_UTMP "/dev/null/utmp" | ||
| 41 | #define _PATH_WTMP "/dev/null/wtmp" | ||
| 42 | |||
| 43 | #define UTMP_FILE _PATH_UTMP | ||
| 44 | #define WTMP_FILE _PATH_WTMP | ||
| 45 | #define UTMP_FILENAME _PATH_UTMP | ||
| 46 | #define WTMP_FILENAME _PATH_WTMP | ||
| 47 | |||
| 48 | #ifdef __cplusplus | ||
| 49 | } | ||
| 50 | #endif | ||
| 51 | |||
| 52 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/utmpx.h created+67| ... | @@ -0,0 +1,67 @@ | ||
| 1 | #ifndef _UTMPX_H | ||
| 2 | #define _UTMPX_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_pid_t | ||
| 11 | #define __NEED_time_t | ||
| 12 | #define __NEED_suseconds_t | ||
| 13 | #define __NEED_struct_timeval | ||
| 14 | |||
| 15 | #include <bits/alltypes.h> | ||
| 16 | |||
| 17 | struct utmpx { | ||
| 18 | 	short ut_type; | ||
| 19 | 	short __ut_pad1; | ||
| 20 | 	pid_t ut_pid; | ||
| 21 | 	char ut_line[32]; | ||
| 22 | 	char ut_id[4]; | ||
| 23 | 	char ut_user[32]; | ||
| 24 | 	char ut_host[256]; | ||
| 25 | 	struct { | ||
| 26 | 		short __e_termination; | ||
| 27 | 		short __e_exit; | ||
| 28 | 	} ut_exit; | ||
| 29 | #if __BYTE_ORDER == 1234 | ||
| 30 | 	int ut_session, __ut_pad2; | ||
| 31 | #else | ||
| 32 | 	int __ut_pad2, ut_session; | ||
| 33 | #endif | ||
| 34 | 	struct timeval ut_tv; | ||
| 35 | 	unsigned ut_addr_v6[4]; | ||
| 36 | 	char __unused[20]; | ||
| 37 | }; | ||
| 38 | |||
| 39 | void endutxent(void); | ||
| 40 | struct utmpx *getutxent(void); | ||
| 41 | struct utmpx *getutxid(const struct utmpx *); | ||
| 42 | struct utmpx *getutxline(const struct utmpx *); | ||
| 43 | struct utmpx *pututxline(const struct utmpx *); | ||
| 44 | void setutxent(void); | ||
| 45 | |||
| 46 | #if defined(_BSD_SOURCE) || defined(_GNU_SOURCE) | ||
| 47 | #define e_exit __e_exit | ||
| 48 | #define e_termination __e_termination | ||
| 49 | void updwtmpx(const char *, const struct utmpx *); | ||
| 50 | int utmpxname(const char *); | ||
| 51 | #endif | ||
| 52 | |||
| 53 | #define EMPTY 0 | ||
| 54 | #define RUN_LVL 1 | ||
| 55 | #define BOOT_TIME 2 | ||
| 56 | #define NEW_TIME 3 | ||
| 57 | #define OLD_TIME 4 | ||
| 58 | #define INIT_PROCESS 5 | ||
| 59 | #define LOGIN_PROCESS 6 | ||
| 60 | #define USER_PROCESS 7 | ||
| 61 | #define DEAD_PROCESS 8 | ||
| 62 | |||
| 63 | #ifdef __cplusplus | ||
| 64 | } | ||
| 65 | #endif | ||
| 66 | |||
| 67 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/values.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef _VALUES_H | ||
| 2 | #define _VALUES_H | ||
| 3 | |||
| 4 | #include <limits.h> | ||
| 5 | |||
| 6 | #define CHARBITS (sizeof(char) * 8) | ||
| 7 | #define SHORTBITS (sizeof(short) * 8) | ||
| 8 | #define INTBITS (sizeof(int) * 8) | ||
| 9 | #define LONGBITS (sizeof(long) * 8) | ||
| 10 | #define PTRBITS (sizeof(char *) * 8) | ||
| 11 | #define DOUBLEBITS (sizeof(double) * 8) | ||
| 12 | #define FLOATBITS (sizeof(float) * 8) | ||
| 13 | |||
| 14 | #define MINSHORT SHRT_MIN | ||
| 15 | #define MININT INT_MIN | ||
| 16 | #define MINLONG LONG_MIN | ||
| 17 | |||
| 18 | #define MAXSHORT SHRT_MAX | ||
| 19 | #define MAXINT INT_MAX | ||
| 20 | #define MAXLONG LONG_MAX | ||
| 21 | |||
| 22 | #define HIBITS MINSHORT | ||
| 23 | #define HIBITL MINLONG | ||
| 24 | |||
| 25 | #include <float.h> | ||
| 26 | |||
| 27 | #define MAXDOUBLE DBL_MAX | ||
| 28 | #undef MAXFLOAT | ||
| 29 | #define MAXFLOAT FLT_MAX | ||
| 30 | #define MINDOUBLE DBL_MIN | ||
| 31 | #define MINFLOAT FLT_MIN | ||
| 32 | #define DMINEXP DBL_MIN_EXP | ||
| 33 | #define FMINEXP FLT_MIN_EXP | ||
| 34 | #define DMAXEXP DBL_MAX_EXP | ||
| 35 | #define FMAXEXP FLT_MAX_EXP | ||
| 36 | |||
| 37 | #define BITSPERBYTE CHAR_BIT | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/wait.h created+2| ... | @@ -0,0 +1,2 @@ | ||
| 1 | #warning redirecting incorrect #include <wait.h> to <sys/wait.h> | ||
| 2 | #include <sys/wait.h> | ||
lib/libc/wasi/libc-top-half/musl/include/wchar.h created+212| ... | @@ -0,0 +1,212 @@ | ||
| 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 | #ifdef __cplusplus | ||
| 45 | #define NULL 0L | ||
| 46 | #else | ||
| 47 | #define NULL ((void*)0) | ||
| 48 | #endif | ||
| 49 | #else | ||
| 50 | #define __need_NULL | ||
| 51 | #include <stddef.h> | ||
| 52 | #endif | ||
| 53 | |||
| 54 | #undef WEOF | ||
| 55 | #define WEOF 0xffffffffU | ||
| 56 | |||
| 57 | wchar_t *wcscpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 58 | wchar_t *wcsncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 59 | |||
| 60 | wchar_t *wcscat (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 61 | wchar_t *wcsncat (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 62 | |||
| 63 | int wcscmp (const wchar_t *, const wchar_t *); | ||
| 64 | int wcsncmp (const wchar_t *, const wchar_t *, size_t); | ||
| 65 | |||
| 66 | int wcscoll(const wchar_t *, const wchar_t *); | ||
| 67 | size_t wcsxfrm (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 68 | |||
| 69 | wchar_t *wcschr (const wchar_t *, wchar_t); | ||
| 70 | wchar_t *wcsrchr (const wchar_t *, wchar_t); | ||
| 71 | |||
| 72 | size_t wcscspn (const wchar_t *, const wchar_t *); | ||
| 73 | size_t wcsspn (const wchar_t *, const wchar_t *); | ||
| 74 | wchar_t *wcspbrk (const wchar_t *, const wchar_t *); | ||
| 75 | |||
| 76 | wchar_t *wcstok (wchar_t *__restrict, const wchar_t *__restrict, wchar_t **__restrict); | ||
| 77 | |||
| 78 | size_t wcslen (const wchar_t *); | ||
| 79 | |||
| 80 | wchar_t *wcsstr (const wchar_t *__restrict, const wchar_t *__restrict); | ||
| 81 | wchar_t *wcswcs (const wchar_t *, const wchar_t *); | ||
| 82 | |||
| 83 | wchar_t *wmemchr (const wchar_t *, wchar_t, size_t); | ||
| 84 | int wmemcmp (const wchar_t *, const wchar_t *, size_t); | ||
| 85 | wchar_t *wmemcpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 86 | wchar_t *wmemmove (wchar_t *, const wchar_t *, size_t); | ||
| 87 | wchar_t *wmemset (wchar_t *, wchar_t, size_t); | ||
| 88 | |||
| 89 | wint_t btowc (int); | ||
| 90 | int wctob (wint_t); | ||
| 91 | |||
| 92 | int mbsinit (const mbstate_t *); | ||
| 93 | size_t mbrtowc (wchar_t *__restrict, const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 94 | size_t wcrtomb (char *__restrict, wchar_t, mbstate_t *__restrict); | ||
| 95 | |||
| 96 | size_t mbrlen (const char *__restrict, size_t, mbstate_t *__restrict); | ||
| 97 | |||
| 98 | size_t mbsrtowcs (wchar_t *__restrict, const char **__restrict, size_t, mbstate_t *__restrict); | ||
| 99 | size_t wcsrtombs (char *__restrict, const wchar_t **__restrict, size_t, mbstate_t *__restrict); | ||
| 100 | |||
| 101 | float wcstof (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 102 | double wcstod (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 103 | long double wcstold (const wchar_t *__restrict, wchar_t **__restrict); | ||
| 104 | |||
| 105 | long wcstol (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 106 | unsigned long wcstoul (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 107 | |||
| 108 | long long wcstoll (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 109 | unsigned long long wcstoull (const wchar_t *__restrict, wchar_t **__restrict, int); | ||
| 110 | |||
| 111 | |||
| 112 | |||
| 113 | int fwide (FILE *, int); | ||
| 114 | |||
| 115 | |||
| 116 | int wprintf (const wchar_t *__restrict, ...); | ||
| 117 | int fwprintf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 118 | int swprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, ...); | ||
| 119 | |||
| 120 | int vwprintf (const wchar_t *__restrict, __isoc_va_list); | ||
| 121 | int vfwprintf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 122 | int vswprintf (wchar_t *__restrict, size_t, const wchar_t *__restrict, __isoc_va_list); | ||
| 123 | |||
| 124 | int wscanf (const wchar_t *__restrict, ...); | ||
| 125 | int fwscanf (FILE *__restrict, const wchar_t *__restrict, ...); | ||
| 126 | int swscanf (const wchar_t *__restrict, const wchar_t *__restrict, ...); | ||
| 127 | |||
| 128 | int vwscanf (const wchar_t *__restrict, __isoc_va_list); | ||
| 129 | int vfwscanf (FILE *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 130 | int vswscanf (const wchar_t *__restrict, const wchar_t *__restrict, __isoc_va_list); | ||
| 131 | |||
| 132 | wint_t fgetwc (FILE *); | ||
| 133 | wint_t getwc (FILE *); | ||
| 134 | wint_t getwchar (void); | ||
| 135 | |||
| 136 | wint_t fputwc (wchar_t, FILE *); | ||
| 137 | wint_t putwc (wchar_t, FILE *); | ||
| 138 | wint_t putwchar (wchar_t); | ||
| 139 | |||
| 140 | wchar_t *fgetws (wchar_t *__restrict, int, FILE *__restrict); | ||
| 141 | int fputws (const wchar_t *__restrict, FILE *__restrict); | ||
| 142 | |||
| 143 | wint_t ungetwc (wint_t, FILE *); | ||
| 144 | |||
| 145 | struct tm; | ||
| 146 | size_t wcsftime (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict); | ||
| 147 | |||
| 148 | #undef iswdigit | ||
| 149 | |||
| 150 | #if defined(_GNU_SOURCE) | ||
| 151 | wint_t fgetwc_unlocked (FILE *); | ||
| 152 | wint_t getwc_unlocked (FILE *); | ||
| 153 | wint_t getwchar_unlocked (void); | ||
| 154 | wint_t fputwc_unlocked (wchar_t, FILE *); | ||
| 155 | wint_t putwc_unlocked (wchar_t, FILE *); | ||
| 156 | wint_t putwchar_unlocked (wchar_t); | ||
| 157 | wchar_t *fgetws_unlocked (wchar_t *__restrict, int, FILE *__restrict); | ||
| 158 | int fputws_unlocked (const wchar_t *__restrict, FILE *__restrict); | ||
| 159 | #endif | ||
| 160 | |||
| 161 | #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 162 | size_t wcsftime_l (wchar_t *__restrict, size_t, const wchar_t *__restrict, const struct tm *__restrict, locale_t); | ||
| 163 | #endif | ||
| 164 | |||
| 165 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 166 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 167 | FILE *open_wmemstream(wchar_t **, size_t *); | ||
| 168 | size_t mbsnrtowcs(wchar_t *__restrict, const char **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 169 | size_t wcsnrtombs(char *__restrict, const wchar_t **__restrict, size_t, size_t, mbstate_t *__restrict); | ||
| 170 | wchar_t *wcsdup(const wchar_t *); | ||
| 171 | size_t wcsnlen (const wchar_t *, size_t); | ||
| 172 | wchar_t *wcpcpy (wchar_t *__restrict, const wchar_t *__restrict); | ||
| 173 | wchar_t *wcpncpy (wchar_t *__restrict, const wchar_t *__restrict, size_t); | ||
| 174 | int wcscasecmp(const wchar_t *, const wchar_t *); | ||
| 175 | int wcscasecmp_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 176 | int wcsncasecmp(const wchar_t *, const wchar_t *, size_t); | ||
| 177 | int wcsncasecmp_l(const wchar_t *, const wchar_t *, size_t, locale_t); | ||
| 178 | int wcscoll_l(const wchar_t *, const wchar_t *, locale_t); | ||
| 179 | size_t wcsxfrm_l(wchar_t *__restrict, const wchar_t *__restrict, size_t, locale_t); | ||
| 180 | #endif | ||
| 181 | |||
| 182 | #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 183 | int wcwidth (wchar_t); | ||
| 184 | int wcswidth (const wchar_t *, size_t); | ||
| 185 | int iswalnum(wint_t); | ||
| 186 | int iswalpha(wint_t); | ||
| 187 | int iswblank(wint_t); | ||
| 188 | int iswcntrl(wint_t); | ||
| 189 | int iswdigit(wint_t); | ||
| 190 | int iswgraph(wint_t); | ||
| 191 | int iswlower(wint_t); | ||
| 192 | int iswprint(wint_t); | ||
| 193 | int iswpunct(wint_t); | ||
| 194 | int iswspace(wint_t); | ||
| 195 | int iswupper(wint_t); | ||
| 196 | int iswxdigit(wint_t); | ||
| 197 | int iswctype(wint_t, wctype_t); | ||
| 198 | wint_t towlower(wint_t); | ||
| 199 | wint_t towupper(wint_t); | ||
| 200 | wctype_t wctype(const char *); | ||
| 201 | |||
| 202 | #ifndef __cplusplus | ||
| 203 | #undef iswdigit | ||
| 204 | #define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 205 | #endif | ||
| 206 | #endif | ||
| 207 | |||
| 208 | #ifdef __cplusplus | ||
| 209 | } | ||
| 210 | #endif | ||
| 211 | |||
| 212 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/wctype.h created+79| ... | @@ -0,0 +1,79 @@ | ||
| 1 | #ifndef _WCTYPE_H | ||
| 2 | #define _WCTYPE_H | ||
| 3 | |||
| 4 | #ifdef __cplusplus | ||
| 5 | extern "C" { | ||
| 6 | #endif | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define __NEED_wint_t | ||
| 11 | #define __NEED_wctype_t | ||
| 12 | |||
| 13 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 14 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 15 | #define __NEED_locale_t | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #include <bits/alltypes.h> | ||
| 19 | |||
| 20 | typedef const int * wctrans_t; | ||
| 21 | |||
| 22 | #undef WEOF | ||
| 23 | #define WEOF 0xffffffffU | ||
| 24 | |||
| 25 | #undef iswdigit | ||
| 26 | |||
| 27 | int iswalnum(wint_t); | ||
| 28 | int iswalpha(wint_t); | ||
| 29 | int iswblank(wint_t); | ||
| 30 | int iswcntrl(wint_t); | ||
| 31 | int iswdigit(wint_t); | ||
| 32 | int iswgraph(wint_t); | ||
| 33 | int iswlower(wint_t); | ||
| 34 | int iswprint(wint_t); | ||
| 35 | int iswpunct(wint_t); | ||
| 36 | int iswspace(wint_t); | ||
| 37 | int iswupper(wint_t); | ||
| 38 | int iswxdigit(wint_t); | ||
| 39 | int iswctype(wint_t, wctype_t); | ||
| 40 | wint_t towctrans(wint_t, wctrans_t); | ||
| 41 | wint_t towlower(wint_t); | ||
| 42 | wint_t towupper(wint_t); | ||
| 43 | wctrans_t wctrans(const char *); | ||
| 44 | wctype_t wctype(const char *); | ||
| 45 | |||
| 46 | #ifndef __cplusplus | ||
| 47 | #undef iswdigit | ||
| 48 | #define iswdigit(a) (0 ? iswdigit(a) : ((unsigned)(a)-'0') < 10) | ||
| 49 | #endif | ||
| 50 | |||
| 51 | #if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \ | ||
| 52 | || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) || defined(_BSD_SOURCE) | ||
| 53 | |||
| 54 | int iswalnum_l(wint_t, locale_t); | ||
| 55 | int iswalpha_l(wint_t, locale_t); | ||
| 56 | int iswblank_l(wint_t, locale_t); | ||
| 57 | int iswcntrl_l(wint_t, locale_t); | ||
| 58 | int iswdigit_l(wint_t, locale_t); | ||
| 59 | int iswgraph_l(wint_t, locale_t); | ||
| 60 | int iswlower_l(wint_t, locale_t); | ||
| 61 | int iswprint_l(wint_t, locale_t); | ||
| 62 | int iswpunct_l(wint_t, locale_t); | ||
| 63 | int iswspace_l(wint_t, locale_t); | ||
| 64 | int iswupper_l(wint_t, locale_t); | ||
| 65 | int iswxdigit_l(wint_t, locale_t); | ||
| 66 | int iswctype_l(wint_t, wctype_t, locale_t); | ||
| 67 | wint_t towlower_l(wint_t, locale_t); | ||
| 68 | wint_t towupper_l(wint_t, locale_t); | ||
| 69 | wint_t towctrans_l(wint_t, wctrans_t, locale_t); | ||
| 70 | wctrans_t wctrans_l(const char *, locale_t); | ||
| 71 | wctype_t wctype_l(const char *, locale_t); | ||
| 72 | |||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef __cplusplus | ||
| 76 | } | ||
| 77 | #endif | ||
| 78 | |||
| 79 | #endif | ||
lib/libc/wasi/libc-top-half/musl/include/wordexp.h created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #ifndef	_WORDEXP_H | ||
| 2 | #define	_WORDEXP_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 | #define WRDE_DOOFFS 1 | ||
| 15 | #define WRDE_APPEND 2 | ||
| 16 | #define WRDE_NOCMD 4 | ||
| 17 | #define WRDE_REUSE 8 | ||
| 18 | #define WRDE_SHOWERR 16 | ||
| 19 | #define WRDE_UNDEF 32 | ||
| 20 | |||
| 21 | typedef struct { | ||
| 22 | 	size_t we_wordc; | ||
| 23 | 	char **we_wordv; | ||
| 24 | 	size_t we_offs; | ||
| 25 | } wordexp_t; | ||
| 26 | |||
| 27 | #define WRDE_NOSYS -1 | ||
| 28 | #define WRDE_NOSPACE 1 | ||
| 29 | #define WRDE_BADCHAR 2 | ||
| 30 | #define WRDE_BADVAL 3 | ||
| 31 | #define WRDE_CMDSUB 4 | ||
| 32 | #define WRDE_SYNTAX 5 | ||
| 33 | |||
| 34 | int wordexp (const char *__restrict, wordexp_t *__restrict, int); | ||
| 35 | void wordfree (wordexp_t *); | ||
| 36 | |||
| 37 | #ifdef __cplusplus | ||
| 38 | } | ||
| 39 | #endif | ||
| 40 | |||
| 41 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/aio/aio.c created+418| ... | @@ -0,0 +1,418 @@ | ||
| 1 | #include <aio.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | #include <semaphore.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <sys/auxv.h> | ||
| 9 | #include "syscall.h" | ||
| 10 | #include "atomic.h" | ||
| 11 | #include "pthread_impl.h" | ||
| 12 | #include "aio_impl.h" | ||
| 13 | |||
| 14 | #define malloc __libc_malloc | ||
| 15 | #define calloc __libc_calloc | ||
| 16 | #define realloc __libc_realloc | ||
| 17 | #define free __libc_free | ||
| 18 | |||
| 19 | /* The following is a threads-based implementation of AIO with minimal | ||
| 20 | * dependence on implementation details. Most synchronization is | ||
| 21 | * performed with pthread primitives, but atomics and futex operations | ||
| 22 | * are used for notification in a couple places where the pthread | ||
| 23 | * primitives would be inefficient or impractical. | ||
| 24 | * | ||
| 25 | * For each fd with outstanding aio operations, an aio_queue structure | ||
| 26 | * is maintained. These are reference-counted and destroyed by the last | ||
| 27 | * aio worker thread to exit. Accessing any member of the aio_queue | ||
| 28 | * structure requires a lock on the aio_queue. Adding and removing aio | ||
| 29 | * queues themselves requires a write lock on the global map object, | ||
| 30 | * a 4-level table mapping file descriptor numbers to aio queues. A | ||
| 31 | * read lock on the map is used to obtain locks on existing queues by | ||
| 32 | * excluding destruction of the queue by a different thread while it is | ||
| 33 | * being locked. | ||
| 34 | * | ||
| 35 | * Each aio queue has a list of active threads/operations. Presently there | ||
| 36 | * is a one to one relationship between threads and operations. The only | ||
| 37 | * members of the aio_thread structure which are accessed by other threads | ||
| 38 | * are the linked list pointers, op (which is immutable), running (which | ||
| 39 | * is updated atomically), and err (which is synchronized via running), | ||
| 40 | * so no locking is necessary. Most of the other other members are used | ||
| 41 | * for sharing data between the main flow of execution and cancellation | ||
| 42 | * cleanup handler. | ||
| 43 | * | ||
| 44 | * Taking any aio locks requires having all signals blocked. This is | ||
| 45 | * necessary because aio_cancel is needed by close, and close is required | ||
| 46 | * to be async-signal safe. All aio worker threads run with all signals | ||
| 47 | * blocked permanently. | ||
| 48 | */ | ||
| 49 | |||
| 50 | struct aio_thread { | ||
| 51 | 	pthread_t td; | ||
| 52 | 	struct aiocb *cb; | ||
| 53 | 	struct aio_thread *next, *prev; | ||
| 54 | 	struct aio_queue *q; | ||
| 55 | 	volatile int running; | ||
| 56 | 	int err, op; | ||
| 57 | 	ssize_t ret; | ||
| 58 | }; | ||
| 59 | |||
| 60 | struct aio_queue { | ||
| 61 | 	int fd, seekable, append, ref, init; | ||
| 62 | 	pthread_mutex_t lock; | ||
| 63 | 	pthread_cond_t cond; | ||
| 64 | 	struct aio_thread *head; | ||
| 65 | }; | ||
| 66 | |||
| 67 | struct aio_args { | ||
| 68 | 	struct aiocb *cb; | ||
| 69 | 	struct aio_queue *q; | ||
| 70 | 	int op; | ||
| 71 | 	sem_t sem; | ||
| 72 | }; | ||
| 73 | |||
| 74 | static pthread_rwlock_t maplock = PTHREAD_RWLOCK_INITIALIZER; | ||
| 75 | static struct aio_queue *****map; | ||
| 76 | static volatile int aio_fd_cnt; | ||
| 77 | volatile int __aio_fut; | ||
| 78 | |||
| 79 | static size_t io_thread_stack_size; | ||
| 80 | |||
| 81 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) | ||
| 82 | |||
| 83 | static struct aio_queue *__aio_get_queue(int fd, int need) | ||
| 84 | { | ||
| 85 | 	if (fd < 0) { | ||
| 86 | 		errno = EBADF; | ||
| 87 | 		return 0; | ||
| 88 | 	} | ||
| 89 | 	int a=fd>>24; | ||
| 90 | 	unsigned char b=fd>>16, c=fd>>8, d=fd; | ||
| 91 | 	struct aio_queue *q = 0; | ||
| 92 | 	pthread_rwlock_rdlock(&maplock); | ||
| 93 | 	if ((!map || !map[a] || !map[a][b] || !map[a][b][c] || !(q=map[a][b][c][d])) && need) { | ||
| 94 | 		pthread_rwlock_unlock(&maplock); | ||
| 95 | 		if (fcntl(fd, F_GETFD) < 0) return 0; | ||
| 96 | 		pthread_rwlock_wrlock(&maplock); | ||
| 97 | 		if (!io_thread_stack_size) { | ||
| 98 | 			unsigned long val = __getauxval(AT_MINSIGSTKSZ); | ||
| 99 | 			io_thread_stack_size = MAX(MINSIGSTKSZ+2048, val+512); | ||
| 100 | 		} | ||
| 101 | 		if (!map) map = calloc(sizeof *map, (-1U/2+1)>>24); | ||
| 102 | 		if (!map) goto out; | ||
| 103 | 		if (!map[a]) map[a] = calloc(sizeof **map, 256); | ||
| 104 | 		if (!map[a]) goto out; | ||
| 105 | 		if (!map[a][b]) map[a][b] = calloc(sizeof ***map, 256); | ||
| 106 | 		if (!map[a][b]) goto out; | ||
| 107 | 		if (!map[a][b][c]) map[a][b][c] = calloc(sizeof ****map, 256); | ||
| 108 | 		if (!map[a][b][c]) goto out; | ||
| 109 | 		if (!(q = map[a][b][c][d])) { | ||
| 110 | 			map[a][b][c][d] = q = calloc(sizeof *****map, 1); | ||
| 111 | 			if (q) { | ||
| 112 | 				q->fd = fd; | ||
| 113 | 				pthread_mutex_init(&q->lock, 0); | ||
| 114 | 				pthread_cond_init(&q->cond, 0); | ||
| 115 | 				a_inc(&aio_fd_cnt); | ||
| 116 | 			} | ||
| 117 | 		} | ||
| 118 | 	} | ||
| 119 | 	if (q) pthread_mutex_lock(&q->lock); | ||
| 120 | out: | ||
| 121 | 	pthread_rwlock_unlock(&maplock); | ||
| 122 | 	return q; | ||
| 123 | } | ||
| 124 | |||
| 125 | static void __aio_unref_queue(struct aio_queue *q) | ||
| 126 | { | ||
| 127 | 	if (q->ref > 1) { | ||
| 128 | 		q->ref--; | ||
| 129 | 		pthread_mutex_unlock(&q->lock); | ||
| 130 | 		return; | ||
| 131 | 	} | ||
| 132 | |||
| 133 | 	/* This is potentially the last reference, but a new reference | ||
| 134 | 	 * may arrive since we cannot free the queue object without first | ||
| 135 | 	 * taking the maplock, which requires releasing the queue lock. */ | ||
| 136 | 	pthread_mutex_unlock(&q->lock); | ||
| 137 | 	pthread_rwlock_wrlock(&maplock); | ||
| 138 | 	pthread_mutex_lock(&q->lock); | ||
| 139 | 	if (q->ref == 1) { | ||
| 140 | 		int fd=q->fd; | ||
| 141 | 		int a=fd>>24; | ||
| 142 | 		unsigned char b=fd>>16, c=fd>>8, d=fd; | ||
| 143 | 		map[a][b][c][d] = 0; | ||
| 144 | 		a_dec(&aio_fd_cnt); | ||
| 145 | 		pthread_rwlock_unlock(&maplock); | ||
| 146 | 		pthread_mutex_unlock(&q->lock); | ||
| 147 | 		free(q); | ||
| 148 | 	} else { | ||
| 149 | 		q->ref--; | ||
| 150 | 		pthread_rwlock_unlock(&maplock); | ||
| 151 | 		pthread_mutex_unlock(&q->lock); | ||
| 152 | 	} | ||
| 153 | } | ||
| 154 | |||
| 155 | static void cleanup(void *ctx) | ||
| 156 | { | ||
| 157 | 	struct aio_thread *at = ctx; | ||
| 158 | 	struct aio_queue *q = at->q; | ||
| 159 | 	struct aiocb *cb = at->cb; | ||
| 160 | 	struct sigevent sev = cb->aio_sigevent; | ||
| 161 | |||
| 162 | 	/* There are four potential types of waiters we could need to wake: | ||
| 163 | 	 * 1. Callers of aio_cancel/close. | ||
| 164 | 	 * 2. Callers of aio_suspend with a single aiocb. | ||
| 165 | 	 * 3. Callers of aio_suspend with a list. | ||
| 166 | 	 * 4. AIO worker threads waiting for sequenced operations. | ||
| 167 | 	 * Types 1-3 are notified via atomics/futexes, mainly for AS-safety | ||
| 168 | 	 * considerations. Type 4 is notified later via a cond var. */ | ||
| 169 | |||
| 170 | 	cb->__ret = at->ret; | ||
| 171 | 	if (a_swap(&at->running, 0) < 0) | ||
| 172 | 		__wake(&at->running, -1, 1); | ||
| 173 | 	if (a_swap(&cb->__err, at->err) != EINPROGRESS) | ||
| 174 | 		__wake(&cb->__err, -1, 1); | ||
| 175 | 	if (a_swap(&__aio_fut, 0)) | ||
| 176 | 		__wake(&__aio_fut, -1, 1); | ||
| 177 | |||
| 178 | 	pthread_mutex_lock(&q->lock); | ||
| 179 | |||
| 180 | 	if (at->next) at->next->prev = at->prev; | ||
| 181 | 	if (at->prev) at->prev->next = at->next; | ||
| 182 | 	else q->head = at->next; | ||
| 183 | |||
| 184 | 	/* Signal aio worker threads waiting for sequenced operations. */ | ||
| 185 | 	pthread_cond_broadcast(&q->cond); | ||
| 186 | |||
| 187 | 	__aio_unref_queue(q); | ||
| 188 | |||
| 189 | 	if (sev.sigev_notify == SIGEV_SIGNAL) { | ||
| 190 | 		siginfo_t si = { | ||
| 191 | 			.si_signo = sev.sigev_signo, | ||
| 192 | 			.si_value = sev.sigev_value, | ||
| 193 | 			.si_code = SI_ASYNCIO, | ||
| 194 | 			.si_pid = getpid(), | ||
| 195 | 			.si_uid = getuid() | ||
| 196 | 		}; | ||
| 197 | 		__syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si); | ||
| 198 | 	} | ||
| 199 | 	if (sev.sigev_notify == SIGEV_THREAD) { | ||
| 200 | 		a_store(&__pthread_self()->cancel, 0); | ||
| 201 | 		sev.sigev_notify_function(sev.sigev_value); | ||
| 202 | 	} | ||
| 203 | } | ||
| 204 | |||
| 205 | static void *io_thread_func(void *ctx) | ||
| 206 | { | ||
| 207 | 	struct aio_thread at, *p; | ||
| 208 | |||
| 209 | 	struct aio_args *args = ctx; | ||
| 210 | 	struct aiocb *cb = args->cb; | ||
| 211 | 	int fd = cb->aio_fildes; | ||
| 212 | 	int op = args->op; | ||
| 213 | 	void *buf = (void *)cb->aio_buf; | ||
| 214 | 	size_t len = cb->aio_nbytes; | ||
| 215 | 	off_t off = cb->aio_offset; | ||
| 216 | |||
| 217 | 	struct aio_queue *q = args->q; | ||
| 218 | 	ssize_t ret; | ||
| 219 | |||
| 220 | 	pthread_mutex_lock(&q->lock); | ||
| 221 | 	sem_post(&args->sem); | ||
| 222 | |||
| 223 | 	at.op = op; | ||
| 224 | 	at.running = 1; | ||
| 225 | 	at.ret = -1; | ||
| 226 | 	at.err = ECANCELED; | ||
| 227 | 	at.q = q; | ||
| 228 | 	at.td = __pthread_self(); | ||
| 229 | 	at.cb = cb; | ||
| 230 | 	at.prev = 0; | ||
| 231 | 	if ((at.next = q->head)) at.next->prev = &at; | ||
| 232 | 	q->head = &at; | ||
| 233 | |||
| 234 | 	if (!q->init) { | ||
| 235 | 		int seekable = lseek(fd, 0, SEEK_CUR) >= 0; | ||
| 236 | 		q->seekable = seekable; | ||
| 237 | 		q->append = !seekable || (fcntl(fd, F_GETFL) & O_APPEND); | ||
| 238 | 		q->init = 1; | ||
| 239 | 	} | ||
| 240 | |||
| 241 | 	pthread_cleanup_push(cleanup, &at); | ||
| 242 | |||
| 243 | 	/* Wait for sequenced operations. */ | ||
| 244 | 	if (op!=LIO_READ && (op!=LIO_WRITE || q->append)) { | ||
| 245 | 		for (;;) { | ||
| 246 | 			for (p=at.next; p && p->op!=LIO_WRITE; p=p->next); | ||
| 247 | 			if (!p) break; | ||
| 248 | 			pthread_cond_wait(&q->cond, &q->lock); | ||
| 249 | 		} | ||
| 250 | 	} | ||
| 251 | |||
| 252 | 	pthread_mutex_unlock(&q->lock); | ||
| 253 | |||
| 254 | 	switch (op) { | ||
| 255 | 	case LIO_WRITE: | ||
| 256 | 		ret = q->append ? write(fd, buf, len) : pwrite(fd, buf, len, off); | ||
| 257 | 		break; | ||
| 258 | 	case LIO_READ: | ||
| 259 | 		ret = !q->seekable ? read(fd, buf, len) : pread(fd, buf, len, off); | ||
| 260 | 		break; | ||
| 261 | 	case O_SYNC: | ||
| 262 | 		ret = fsync(fd); | ||
| 263 | 		break; | ||
| 264 | 	case O_DSYNC: | ||
| 265 | 		ret = fdatasync(fd); | ||
| 266 | 		break; | ||
| 267 | 	} | ||
| 268 | 	at.ret = ret; | ||
| 269 | 	at.err = ret<0 ? errno : 0; | ||
| 270 | 	 | ||
| 271 | 	pthread_cleanup_pop(1); | ||
| 272 | |||
| 273 | 	return 0; | ||
| 274 | } | ||
| 275 | |||
| 276 | static int submit(struct aiocb *cb, int op) | ||
| 277 | { | ||
| 278 | 	int ret = 0; | ||
| 279 | 	pthread_attr_t a; | ||
| 280 | 	sigset_t allmask, origmask; | ||
| 281 | 	pthread_t td; | ||
| 282 | 	struct aio_queue *q = __aio_get_queue(cb->aio_fildes, 1); | ||
| 283 | 	struct aio_args args = { .cb = cb, .op = op, .q = q }; | ||
| 284 | 	sem_init(&args.sem, 0, 0); | ||
| 285 | |||
| 286 | 	if (!q) { | ||
| 287 | 		if (errno != EBADF) errno = EAGAIN; | ||
| 288 | 		cb->__ret = -1; | ||
| 289 | 		cb->__err = errno; | ||
| 290 | 		return -1; | ||
| 291 | 	} | ||
| 292 | 	q->ref++; | ||
| 293 | 	pthread_mutex_unlock(&q->lock); | ||
| 294 | |||
| 295 | 	if (cb->aio_sigevent.sigev_notify == SIGEV_THREAD) { | ||
| 296 | 		if (cb->aio_sigevent.sigev_notify_attributes) | ||
| 297 | 			a = *cb->aio_sigevent.sigev_notify_attributes; | ||
| 298 | 		else | ||
| 299 | 			pthread_attr_init(&a); | ||
| 300 | 	} else { | ||
| 301 | 		pthread_attr_init(&a); | ||
| 302 | 		pthread_attr_setstacksize(&a, io_thread_stack_size); | ||
| 303 | 		pthread_attr_setguardsize(&a, 0); | ||
| 304 | 	} | ||
| 305 | 	pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); | ||
| 306 | 	sigfillset(&allmask); | ||
| 307 | 	pthread_sigmask(SIG_BLOCK, &allmask, &origmask); | ||
| 308 | 	cb->__err = EINPROGRESS; | ||
| 309 | 	if (pthread_create(&td, &a, io_thread_func, &args)) { | ||
| 310 | 		pthread_mutex_lock(&q->lock); | ||
| 311 | 		__aio_unref_queue(q); | ||
| 312 | 		cb->__err = errno = EAGAIN; | ||
| 313 | 		cb->__ret = ret = -1; | ||
| 314 | 	} | ||
| 315 | 	pthread_sigmask(SIG_SETMASK, &origmask, 0); | ||
| 316 | |||
| 317 | 	if (!ret) { | ||
| 318 | 		while (sem_wait(&args.sem)); | ||
| 319 | 	} | ||
| 320 | |||
| 321 | 	return ret; | ||
| 322 | } | ||
| 323 | |||
| 324 | int aio_read(struct aiocb *cb) | ||
| 325 | { | ||
| 326 | 	return submit(cb, LIO_READ); | ||
| 327 | } | ||
| 328 | |||
| 329 | int aio_write(struct aiocb *cb) | ||
| 330 | { | ||
| 331 | 	return submit(cb, LIO_WRITE); | ||
| 332 | } | ||
| 333 | |||
| 334 | int aio_fsync(int op, struct aiocb *cb) | ||
| 335 | { | ||
| 336 | 	if (op != O_SYNC && op != O_DSYNC) { | ||
| 337 | 		errno = EINVAL; | ||
| 338 | 		return -1; | ||
| 339 | 	} | ||
| 340 | 	return submit(cb, op); | ||
| 341 | } | ||
| 342 | |||
| 343 | ssize_t aio_return(struct aiocb *cb) | ||
| 344 | { | ||
| 345 | 	return cb->__ret; | ||
| 346 | } | ||
| 347 | |||
| 348 | int aio_error(const struct aiocb *cb) | ||
| 349 | { | ||
| 350 | 	a_barrier(); | ||
| 351 | 	return cb->__err & 0x7fffffff; | ||
| 352 | } | ||
| 353 | |||
| 354 | int aio_cancel(int fd, struct aiocb *cb) | ||
| 355 | { | ||
| 356 | 	sigset_t allmask, origmask; | ||
| 357 | 	int ret = AIO_ALLDONE; | ||
| 358 | 	struct aio_thread *p; | ||
| 359 | 	struct aio_queue *q; | ||
| 360 | |||
| 361 | 	/* Unspecified behavior case. Report an error. */ | ||
| 362 | 	if (cb && fd != cb->aio_fildes) { | ||
| 363 | 		errno = EINVAL; | ||
| 364 | 		return -1; | ||
| 365 | 	} | ||
| 366 | |||
| 367 | 	sigfillset(&allmask); | ||
| 368 | 	pthread_sigmask(SIG_BLOCK, &allmask, &origmask); | ||
| 369 | |||
| 370 | 	errno = ENOENT; | ||
| 371 | 	if (!(q = __aio_get_queue(fd, 0))) { | ||
| 372 | 		if (errno == EBADF) ret = -1; | ||
| 373 | 		goto done; | ||
| 374 | 	} | ||
| 375 | |||
| 376 | 	for (p = q->head; p; p = p->next) { | ||
| 377 | 		if (cb && cb != p->cb) continue; | ||
| 378 | 		/* Transition target from running to running-with-waiters */ | ||
| 379 | 		if (a_cas(&p->running, 1, -1)) { | ||
| 380 | 			pthread_cancel(p->td); | ||
| 381 | 			__wait(&p->running, 0, -1, 1); | ||
| 382 | 			if (p->err == ECANCELED) ret = AIO_CANCELED; | ||
| 383 | 		} | ||
| 384 | 	} | ||
| 385 | |||
| 386 | 	pthread_mutex_unlock(&q->lock); | ||
| 387 | done: | ||
| 388 | 	pthread_sigmask(SIG_SETMASK, &origmask, 0); | ||
| 389 | 	return ret; | ||
| 390 | } | ||
| 391 | |||
| 392 | int __aio_close(int fd) | ||
| 393 | { | ||
| 394 | 	a_barrier(); | ||
| 395 | 	if (aio_fd_cnt) aio_cancel(fd, 0); | ||
| 396 | 	return fd; | ||
| 397 | } | ||
| 398 | |||
| 399 | void __aio_atfork(int who) | ||
| 400 | { | ||
| 401 | 	if (who<0) { | ||
| 402 | 		pthread_rwlock_rdlock(&maplock); | ||
| 403 | 		return; | ||
| 404 | 	} | ||
| 405 | 	if (who>0 && map) for (int a=0; a<(-1U/2+1)>>24; a++) | ||
| 406 | 		if (map[a]) for (int b=0; b<256; b++) | ||
| 407 | 			if (map[a][b]) for (int c=0; c<256; c++) | ||
| 408 | 				if (map[a][b][c]) for (int d=0; d<256; d++) | ||
| 409 | 					map[a][b][c][d] = 0; | ||
| 410 | 	pthread_rwlock_unlock(&maplock); | ||
| 411 | } | ||
| 412 | |||
| 413 | weak_alias(aio_cancel, aio_cancel64); | ||
| 414 | weak_alias(aio_error, aio_error64); | ||
| 415 | weak_alias(aio_fsync, aio_fsync64); | ||
| 416 | weak_alias(aio_read, aio_read64); | ||
| 417 | weak_alias(aio_write, aio_write64); | ||
| 418 | weak_alias(aio_return, aio_return64); | ||
lib/libc/wasi/libc-top-half/musl/src/aio/aio_suspend.c created+79| ... | @@ -0,0 +1,79 @@ | ||
| 1 | #include <aio.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <time.h> | ||
| 4 | #include "atomic.h" | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | #include "aio_impl.h" | ||
| 7 | |||
| 8 | int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec *ts) | ||
| 9 | { | ||
| 10 | 	int i, tid = 0, ret, expect = 0; | ||
| 11 | 	struct timespec at; | ||
| 12 | 	volatile int dummy_fut, *pfut; | ||
| 13 | 	int nzcnt = 0; | ||
| 14 | 	const struct aiocb *cb = 0; | ||
| 15 | |||
| 16 | 	pthread_testcancel(); | ||
| 17 | |||
| 18 | 	if (cnt<0) { | ||
| 19 | 		errno = EINVAL; | ||
| 20 | 		return -1; | ||
| 21 | 	} | ||
| 22 | |||
| 23 | 	for (i=0; i<cnt; i++) if (cbs[i]) { | ||
| 24 | 		if (aio_error(cbs[i]) != EINPROGRESS) return 0; | ||
| 25 | 		nzcnt++; | ||
| 26 | 		cb = cbs[i]; | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	if (ts) { | ||
| 30 | 		clock_gettime(CLOCK_MONOTONIC, &at); | ||
| 31 | 		at.tv_sec += ts->tv_sec; | ||
| 32 | 		if ((at.tv_nsec += ts->tv_nsec) >= 1000000000) { | ||
| 33 | 			at.tv_nsec -= 1000000000; | ||
| 34 | 			at.tv_sec++; | ||
| 35 | 		} | ||
| 36 | 	} | ||
| 37 | |||
| 38 | 	for (;;) { | ||
| 39 | 		for (i=0; i<cnt; i++) | ||
| 40 | 			if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS) | ||
| 41 | 				return 0; | ||
| 42 | |||
| 43 | 		switch (nzcnt) { | ||
| 44 | 		case 0: | ||
| 45 | 			pfut = &dummy_fut; | ||
| 46 | 			break; | ||
| 47 | 		case 1: | ||
| 48 | 			pfut = (void *)&cb->__err; | ||
| 49 | 			expect = EINPROGRESS | 0x80000000; | ||
| 50 | 			a_cas(pfut, EINPROGRESS, expect); | ||
| 51 | 			break; | ||
| 52 | 		default: | ||
| 53 | 			pfut = &__aio_fut; | ||
| 54 | 			if (!tid) tid = __pthread_self()->tid; | ||
| 55 | 			expect = a_cas(pfut, 0, tid); | ||
| 56 | 			if (!expect) expect = tid; | ||
| 57 | 			/* Need to recheck the predicate before waiting. */ | ||
| 58 | 			for (i=0; i<cnt; i++) | ||
| 59 | 				if (cbs[i] && aio_error(cbs[i]) != EINPROGRESS) | ||
| 60 | 					return 0; | ||
| 61 | 			break; | ||
| 62 | 		} | ||
| 63 | |||
| 64 | 		ret = __timedwait_cp(pfut, expect, CLOCK_MONOTONIC, ts?&at:0, 1); | ||
| 65 | |||
| 66 | 		switch (ret) { | ||
| 67 | 		case ETIMEDOUT: | ||
| 68 | 			ret = EAGAIN; | ||
| 69 | 		case ECANCELED: | ||
| 70 | 		case EINTR: | ||
| 71 | 			errno = ret; | ||
| 72 | 			return -1; | ||
| 73 | 		} | ||
| 74 | 	} | ||
| 75 | } | ||
| 76 | |||
| 77 | #if !_REDIR_TIME64 | ||
| 78 | weak_alias(aio_suspend, aio_suspend64); | ||
| 79 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/aio/lio_listio.c created+143| ... | @@ -0,0 +1,143 @@ | ||
| 1 | #include <aio.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | |||
| 7 | struct lio_state { | ||
| 8 | 	struct sigevent *sev; | ||
| 9 | 	int cnt; | ||
| 10 | 	struct aiocb *cbs[]; | ||
| 11 | }; | ||
| 12 | |||
| 13 | static int lio_wait(struct lio_state *st) | ||
| 14 | { | ||
| 15 | 	int i, err, got_err = 0; | ||
| 16 | 	int cnt = st->cnt; | ||
| 17 | 	struct aiocb **cbs = st->cbs; | ||
| 18 | |||
| 19 | 	for (;;) { | ||
| 20 | 		for (i=0; i<cnt; i++) { | ||
| 21 | 			if (!cbs[i]) continue; | ||
| 22 | 			err = aio_error(cbs[i]); | ||
| 23 | 			if (err==EINPROGRESS) | ||
| 24 | 				break; | ||
| 25 | 			if (err) got_err=1; | ||
| 26 | 			cbs[i] = 0; | ||
| 27 | 		} | ||
| 28 | 		if (i==cnt) { | ||
| 29 | 			if (got_err) { | ||
| 30 | 				errno = EIO; | ||
| 31 | 				return -1; | ||
| 32 | 			} | ||
| 33 | 			return 0; | ||
| 34 | 		} | ||
| 35 | 		if (aio_suspend((void *)cbs, cnt, 0)) | ||
| 36 | 			return -1; | ||
| 37 | 	} | ||
| 38 | } | ||
| 39 | |||
| 40 | static void notify_signal(struct sigevent *sev) | ||
| 41 | { | ||
| 42 | 	siginfo_t si = { | ||
| 43 | 		.si_signo = sev->sigev_signo, | ||
| 44 | 		.si_value = sev->sigev_value, | ||
| 45 | 		.si_code = SI_ASYNCIO, | ||
| 46 | 		.si_pid = getpid(), | ||
| 47 | 		.si_uid = getuid() | ||
| 48 | 	}; | ||
| 49 | 	__syscall(SYS_rt_sigqueueinfo, si.si_pid, si.si_signo, &si); | ||
| 50 | } | ||
| 51 | |||
| 52 | static void *wait_thread(void *p) | ||
| 53 | { | ||
| 54 | 	struct lio_state *st = p; | ||
| 55 | 	struct sigevent *sev = st->sev; | ||
| 56 | 	lio_wait(st); | ||
| 57 | 	free(st); | ||
| 58 | 	switch (sev->sigev_notify) { | ||
| 59 | 	case SIGEV_SIGNAL: | ||
| 60 | 		notify_signal(sev); | ||
| 61 | 		break; | ||
| 62 | 	case SIGEV_THREAD: | ||
| 63 | 		sev->sigev_notify_function(sev->sigev_value); | ||
| 64 | 		break; | ||
| 65 | 	} | ||
| 66 | 	return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, struct sigevent *restrict sev) | ||
| 70 | { | ||
| 71 | 	int i, ret; | ||
| 72 | 	struct lio_state *st=0; | ||
| 73 | |||
| 74 | 	if (cnt < 0) { | ||
| 75 | 		errno = EINVAL; | ||
| 76 | 		return -1; | ||
| 77 | 	} | ||
| 78 | |||
| 79 | 	if (mode == LIO_WAIT || (sev && sev->sigev_notify != SIGEV_NONE)) { | ||
| 80 | 		if (!(st = malloc(sizeof *st + cnt*sizeof *cbs))) { | ||
| 81 | 			errno = EAGAIN; | ||
| 82 | 			return -1; | ||
| 83 | 		} | ||
| 84 | 		st->cnt = cnt; | ||
| 85 | 		st->sev = sev; | ||
| 86 | 		memcpy(st->cbs, (void*) cbs, cnt*sizeof *cbs); | ||
| 87 | 	} | ||
| 88 | |||
| 89 | 	for (i=0; i<cnt; i++) { | ||
| 90 | 		if (!cbs[i]) continue; | ||
| 91 | 		switch (cbs[i]->aio_lio_opcode) { | ||
| 92 | 		case LIO_READ: | ||
| 93 | 			ret = aio_read(cbs[i]); | ||
| 94 | 			break; | ||
| 95 | 		case LIO_WRITE: | ||
| 96 | 			ret = aio_write(cbs[i]); | ||
| 97 | 			break; | ||
| 98 | 		default: | ||
| 99 | 			continue; | ||
| 100 | 		} | ||
| 101 | 		if (ret) { | ||
| 102 | 			free(st); | ||
| 103 | 			errno = EAGAIN; | ||
| 104 | 			return -1; | ||
| 105 | 		} | ||
| 106 | 	} | ||
| 107 | |||
| 108 | 	if (mode == LIO_WAIT) { | ||
| 109 | 		ret = lio_wait(st); | ||
| 110 | 		free(st); | ||
| 111 | 		return ret; | ||
| 112 | 	} | ||
| 113 | |||
| 114 | 	if (st) { | ||
| 115 | 		pthread_attr_t a; | ||
| 116 | 		sigset_t set, set_old; | ||
| 117 | 		pthread_t td; | ||
| 118 | |||
| 119 | 		if (sev->sigev_notify == SIGEV_THREAD) { | ||
| 120 | 			if (sev->sigev_notify_attributes) | ||
| 121 | 				a = *sev->sigev_notify_attributes; | ||
| 122 | 			else | ||
| 123 | 				pthread_attr_init(&a); | ||
| 124 | 		} else { | ||
| 125 | 			pthread_attr_init(&a); | ||
| 126 | 			pthread_attr_setstacksize(&a, PAGE_SIZE); | ||
| 127 | 			pthread_attr_setguardsize(&a, 0); | ||
| 128 | 		} | ||
| 129 | 		pthread_attr_setdetachstate(&a, PTHREAD_CREATE_DETACHED); | ||
| 130 | 		sigfillset(&set); | ||
| 131 | 		pthread_sigmask(SIG_BLOCK, &set, &set_old); | ||
| 132 | 		if (pthread_create(&td, &a, wait_thread, st)) { | ||
| 133 | 			free(st); | ||
| 134 | 			errno = EAGAIN; | ||
| 135 | 			return -1; | ||
| 136 | 		} | ||
| 137 | 		pthread_sigmask(SIG_SETMASK, &set_old, 0); | ||
| 138 | 	} | ||
| 139 | |||
| 140 | 	return 0; | ||
| 141 | } | ||
| 142 | |||
| 143 | weak_alias(lio_listio, lio_listio64); | ||
lib/libc/wasi/libc-top-half/musl/src/complex/__cexp.c created+87| ... | @@ -0,0 +1,87 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_exp.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 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 | #include "complex_impl.h" | ||
| 29 | |||
| 30 | static const uint32_t k = 1799; /* constant for reduction */ | ||
| 31 | static const double kln2 = 1246.97177782734161156; /* k * ln2 */ | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Compute exp(x), scaled to avoid spurious overflow. An exponent is | ||
| 35 | * returned separately in 'expt'. | ||
| 36 | * | ||
| 37 | * Input: ln(DBL_MAX) <= x < ln(2 * DBL_MAX / DBL_MIN_DENORM) ~= 1454.91 | ||
| 38 | * Output: 2**1023 <= y < 2**1024 | ||
| 39 | */ | ||
| 40 | static double __frexp_exp(double x, int *expt) | ||
| 41 | { | ||
| 42 | 	double exp_x; | ||
| 43 | 	uint32_t hx; | ||
| 44 | |||
| 45 | 	/* | ||
| 46 | 	 * We use exp(x) = exp(x - kln2) * 2**k, carefully chosen to | ||
| 47 | 	 * minimize |exp(kln2) - 2**k|. We also scale the exponent of | ||
| 48 | 	 * exp_x to MAX_EXP so that the result can be multiplied by | ||
| 49 | 	 * a tiny number without losing accuracy due to denormalization. | ||
| 50 | 	 */ | ||
| 51 | 	exp_x = exp(x - kln2); | ||
| 52 | 	GET_HIGH_WORD(hx, exp_x); | ||
| 53 | 	*expt = (hx >> 20) - (0x3ff + 1023) + k; | ||
| 54 | 	SET_HIGH_WORD(exp_x, (hx & 0xfffff) | ((0x3ff + 1023) << 20)); | ||
| 55 | 	return exp_x; | ||
| 56 | } | ||
| 57 | |||
| 58 | /* | ||
| 59 | * __ldexp_cexp(x, expt) compute exp(x) * 2**expt. | ||
| 60 | * It is intended for large arguments (real part >= ln(DBL_MAX)) | ||
| 61 | * where care is needed to avoid overflow. | ||
| 62 | * | ||
| 63 | * The present implementation is narrowly tailored for our hyperbolic and | ||
| 64 | * exponential functions. We assume expt is small (0 or -1), and the caller | ||
| 65 | * has filtered out very large x, for which overflow would be inevitable. | ||
| 66 | */ | ||
| 67 | double complex __ldexp_cexp(double complex z, int expt) | ||
| 68 | { | ||
| 69 | 	double x, y, exp_x, scale1, scale2; | ||
| 70 | 	int ex_expt, half_expt; | ||
| 71 | |||
| 72 | 	x = creal(z); | ||
| 73 | 	y = cimag(z); | ||
| 74 | 	exp_x = __frexp_exp(x, &ex_expt); | ||
| 75 | 	expt += ex_expt; | ||
| 76 | |||
| 77 | 	/* | ||
| 78 | 	 * Arrange so that scale1 * scale2 == 2**expt. We use this to | ||
| 79 | 	 * compensate for scalbn being horrendously slow. | ||
| 80 | 	 */ | ||
| 81 | 	half_expt = expt / 2; | ||
| 82 | 	INSERT_WORDS(scale1, (0x3ff + half_expt) << 20, 0); | ||
| 83 | 	half_expt = expt - half_expt; | ||
| 84 | 	INSERT_WORDS(scale2, (0x3ff + half_expt) << 20, 0); | ||
| 85 | |||
| 86 | 	return CMPLX(cos(y) * exp_x * scale1 * scale2, sin(y) * exp_x * scale1 * scale2); | ||
| 87 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/__cexpf.c created+68| ... | @@ -0,0 +1,68 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_expf.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 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 | #include "complex_impl.h" | ||
| 29 | |||
| 30 | static const uint32_t k = 235; /* constant for reduction */ | ||
| 31 | static const float kln2 = 162.88958740F; /* k * ln2 */ | ||
| 32 | |||
| 33 | /* | ||
| 34 | * See __cexp.c for details. | ||
| 35 | * | ||
| 36 | * Input: ln(FLT_MAX) <= x < ln(2 * FLT_MAX / FLT_MIN_DENORM) ~= 192.7 | ||
| 37 | * Output: 2**127 <= y < 2**128 | ||
| 38 | */ | ||
| 39 | static float __frexp_expf(float x, int *expt) | ||
| 40 | { | ||
| 41 | 	float exp_x; | ||
| 42 | 	uint32_t hx; | ||
| 43 | |||
| 44 | 	exp_x = expf(x - kln2); | ||
| 45 | 	GET_FLOAT_WORD(hx, exp_x); | ||
| 46 | 	*expt = (hx >> 23) - (0x7f + 127) + k; | ||
| 47 | 	SET_FLOAT_WORD(exp_x, (hx & 0x7fffff) | ((0x7f + 127) << 23)); | ||
| 48 | 	return exp_x; | ||
| 49 | } | ||
| 50 | |||
| 51 | float complex __ldexp_cexpf(float complex z, int expt) | ||
| 52 | { | ||
| 53 | 	float x, y, exp_x, scale1, scale2; | ||
| 54 | 	int ex_expt, half_expt; | ||
| 55 | |||
| 56 | 	x = crealf(z); | ||
| 57 | 	y = cimagf(z); | ||
| 58 | 	exp_x = __frexp_expf(x, &ex_expt); | ||
| 59 | 	expt += ex_expt; | ||
| 60 | |||
| 61 | 	half_expt = expt / 2; | ||
| 62 | 	SET_FLOAT_WORD(scale1, (0x7f + half_expt) << 23); | ||
| 63 | 	half_expt = expt - half_expt; | ||
| 64 | 	SET_FLOAT_WORD(scale2, (0x7f + half_expt) << 23); | ||
| 65 | |||
| 66 | 	return CMPLXF(cosf(y) * exp_x * scale1 * scale2, | ||
| 67 | 	 sinf(y) * exp_x * scale1 * scale2); | ||
| 68 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cabs.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | double cabs(double complex z) | ||
| 4 | { | ||
| 5 | 	return hypot(creal(z), cimag(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cabsf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float cabsf(float complex z) | ||
| 4 | { | ||
| 5 | 	return hypotf(crealf(z), cimagf(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cabsl.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double cabsl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return cabs(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double cabsl(long double complex z) | ||
| 10 | { | ||
| 11 | 	return hypotl(creall(z), cimagl(z)); | ||
| 12 | } | ||
| 13 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cacos.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | // FIXME: Hull et al. "Implementing the complex arcsine and arccosine functions using exception handling" 1997 | ||
| 4 | |||
| 5 | /* acos(z) = pi/2 - asin(z) */ | ||
| 6 | |||
| 7 | double complex cacos(double complex z) | ||
| 8 | { | ||
| 9 | 	z = casin(z); | ||
| 10 | 	return CMPLX(M_PI_2 - creal(z), -cimag(z)); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cacosf.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | // FIXME | ||
| 4 | |||
| 5 | float complex cacosf(float complex z) | ||
| 6 | { | ||
| 7 | 	z = casinf(z); | ||
| 8 | 	return CMPLXF((float)M_PI_2 - crealf(z), -cimagf(z)); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cacosh.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* acosh(z) = i acos(z) */ | ||
| 4 | |||
| 5 | double complex cacosh(double complex z) | ||
| 6 | { | ||
| 7 | 	int zineg = signbit(cimag(z)); | ||
| 8 | |||
| 9 | 	z = cacos(z); | ||
| 10 | 	if (zineg) return CMPLX(cimag(z), -creal(z)); | ||
| 11 | 	else return CMPLX(-cimag(z), creal(z)); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cacoshf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex cacoshf(float complex z) | ||
| 4 | { | ||
| 5 | 	int zineg = signbit(cimagf(z)); | ||
| 6 | |||
| 7 | 	z = cacosf(z); | ||
| 8 | 	if (zineg) return CMPLXF(cimagf(z), -crealf(z)); | ||
| 9 | 	else return CMPLXF(-cimagf(z), crealf(z)); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cacoshl.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex cacoshl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return cacosh(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex cacoshl(long double complex z) | ||
| 10 | { | ||
| 11 | 	int zineg = signbit(cimagl(z)); | ||
| 12 | |||
| 13 | 	z = cacosl(z); | ||
| 14 | 	if (zineg) return CMPLXL(cimagl(z), -creall(z)); | ||
| 15 | 	else return CMPLXL(-cimagl(z), creall(z)); | ||
| 16 | } | ||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cacosl.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex cacosl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return cacos(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | // FIXME | ||
| 10 | #define PI_2 1.57079632679489661923132169163975144L | ||
| 11 | long double complex cacosl(long double complex z) | ||
| 12 | { | ||
| 13 | 	z = casinl(z); | ||
| 14 | 	return CMPLXL(PI_2 - creall(z), -cimagl(z)); | ||
| 15 | } | ||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/carg.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | double carg(double complex z) | ||
| 4 | { | ||
| 5 | 	return atan2(cimag(z), creal(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cargf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float cargf(float complex z) | ||
| 4 | { | ||
| 5 | 	return atan2f(cimagf(z), crealf(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cargl.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double cargl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return carg(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double cargl(long double complex z) | ||
| 10 | { | ||
| 11 | 	return atan2l(cimagl(z), creall(z)); | ||
| 12 | } | ||
| 13 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/casin.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | // FIXME | ||
| 4 | |||
| 5 | /* asin(z) = -i log(i z + sqrt(1 - z*z)) */ | ||
| 6 | |||
| 7 | double complex casin(double complex z) | ||
| 8 | { | ||
| 9 | 	double complex w; | ||
| 10 | 	double x, y; | ||
| 11 | |||
| 12 | 	x = creal(z); | ||
| 13 | 	y = cimag(z); | ||
| 14 | 	w = CMPLX(1.0 - (x - y)*(x + y), -2.0*x*y); | ||
| 15 | 	double complex r = clog(CMPLX(-y, x) + csqrt(w)); | ||
| 16 | 	return CMPLX(cimag(r), -creal(r)); | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/casinf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | // FIXME | ||
| 4 | |||
| 5 | float complex casinf(float complex z) | ||
| 6 | { | ||
| 7 | 	float complex w; | ||
| 8 | 	float x, y; | ||
| 9 | |||
| 10 | 	x = crealf(z); | ||
| 11 | 	y = cimagf(z); | ||
| 12 | 	w = CMPLXF(1.0 - (x - y)*(x + y), -2.0*x*y); | ||
| 13 | 	float complex r = clogf(CMPLXF(-y, x) + csqrtf(w)); | ||
| 14 | 	return CMPLXF(cimagf(r), -crealf(r)); | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/casinh.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* asinh(z) = -i asin(i z) */ | ||
| 4 | |||
| 5 | double complex casinh(double complex z) | ||
| 6 | { | ||
| 7 | 	z = casin(CMPLX(-cimag(z), creal(z))); | ||
| 8 | 	return CMPLX(cimag(z), -creal(z)); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/casinhf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex casinhf(float complex z) | ||
| 4 | { | ||
| 5 | 	z = casinf(CMPLXF(-cimagf(z), crealf(z))); | ||
| 6 | 	return CMPLXF(cimagf(z), -crealf(z)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/casinhl.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex casinhl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return casinh(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex casinhl(long double complex z) | ||
| 10 | { | ||
| 11 | 	z = casinl(CMPLXL(-cimagl(z), creall(z))); | ||
| 12 | 	return CMPLXL(cimagl(z), -creall(z)); | ||
| 13 | } | ||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/casinl.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex casinl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return casin(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | // FIXME | ||
| 10 | long double complex casinl(long double complex z) | ||
| 11 | { | ||
| 12 | 	long double complex w; | ||
| 13 | 	long double x, y; | ||
| 14 | |||
| 15 | 	x = creall(z); | ||
| 16 | 	y = cimagl(z); | ||
| 17 | 	w = CMPLXL(1.0 - (x - y)*(x + y), -2.0*x*y); | ||
| 18 | 	long double complex r = clogl(CMPLXL(-y, x) + csqrtl(w)); | ||
| 19 | 	return CMPLXL(cimagl(r), -creall(r)); | ||
| 20 | } | ||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/catan.c created+107| ... | @@ -0,0 +1,107 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/s_catan.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 | /* | ||
| 18 | * Complex circular arc tangent | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * double complex catan(); | ||
| 24 | * double complex z, w; | ||
| 25 | * | ||
| 26 | * w = catan (z); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * If | ||
| 32 | * z = x + iy, | ||
| 33 | * | ||
| 34 | * then | ||
| 35 | * 1 ( 2x ) | ||
| 36 | * Re w = - arctan(-----------) + k PI | ||
| 37 | * 2 ( 2 2) | ||
| 38 | * (1 - x - y ) | ||
| 39 | * | ||
| 40 | * ( 2 2) | ||
| 41 | * 1 (x + (y+1) ) | ||
| 42 | * Im w = - log(------------) | ||
| 43 | * 4 ( 2 2) | ||
| 44 | * (x + (y-1) ) | ||
| 45 | * | ||
| 46 | * Where k is an arbitrary integer. | ||
| 47 | * | ||
| 48 | * catan(z) = -i catanh(iz). | ||
| 49 | * | ||
| 50 | * ACCURACY: | ||
| 51 | * | ||
| 52 | * Relative error: | ||
| 53 | * arithmetic domain # trials peak rms | ||
| 54 | * DEC -10,+10 5900 1.3e-16 7.8e-18 | ||
| 55 | * IEEE -10,+10 30000 2.3e-15 8.5e-17 | ||
| 56 | * The check catan( ctan(z) ) = z, with |x| and |y| < PI/2, | ||
| 57 | * had peak relative error 1.5e-16, rms relative error | ||
| 58 | * 2.9e-17. See also clog(). | ||
| 59 | */ | ||
| 60 | |||
| 61 | #include "complex_impl.h" | ||
| 62 | |||
| 63 | #define MAXNUM 1.0e308 | ||
| 64 | |||
| 65 | static const double DP1 = 3.14159265160560607910E0; | ||
| 66 | static const double DP2 = 1.98418714791870343106E-9; | ||
| 67 | static const double DP3 = 1.14423774522196636802E-17; | ||
| 68 | |||
| 69 | static double _redupi(double x) | ||
| 70 | { | ||
| 71 | 	double t; | ||
| 72 | 	long i; | ||
| 73 | |||
| 74 | 	t = x/M_PI; | ||
| 75 | 	if (t >= 0.0) | ||
| 76 | 		t += 0.5; | ||
| 77 | 	else | ||
| 78 | 		t -= 0.5; | ||
| 79 | |||
| 80 | 	i = t; /* the multiple */ | ||
| 81 | 	t = i; | ||
| 82 | 	t = ((x - t * DP1) - t * DP2) - t * DP3; | ||
| 83 | 	return t; | ||
| 84 | } | ||
| 85 | |||
| 86 | double complex catan(double complex z) | ||
| 87 | { | ||
| 88 | 	double complex w; | ||
| 89 | 	double a, t, x, x2, y; | ||
| 90 | |||
| 91 | 	x = creal(z); | ||
| 92 | 	y = cimag(z); | ||
| 93 | |||
| 94 | 	x2 = x * x; | ||
| 95 | 	a = 1.0 - x2 - (y * y); | ||
| 96 | |||
| 97 | 	t = 0.5 * atan2(2.0 * x, a); | ||
| 98 | 	w = _redupi(t); | ||
| 99 | |||
| 100 | 	t = y - 1.0; | ||
| 101 | 	a = x2 + (t * t); | ||
| 102 | |||
| 103 | 	t = y + 1.0; | ||
| 104 | 	a = (x2 + t * t)/a; | ||
| 105 | 	w = CMPLX(w, 0.25 * log(a)); | ||
| 106 | 	return w; | ||
| 107 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/catanf.c created+103| ... | @@ -0,0 +1,103 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/s_catanf.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 | /* | ||
| 18 | * Complex circular arc tangent | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * float complex catanf(); | ||
| 24 | * float complex z, w; | ||
| 25 | * | ||
| 26 | * w = catanf( z ); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * If | ||
| 32 | * z = x + iy, | ||
| 33 | * | ||
| 34 | * then | ||
| 35 | * 1 ( 2x ) | ||
| 36 | * Re w = - arctan(-----------) + k PI | ||
| 37 | * 2 ( 2 2) | ||
| 38 | * (1 - x - y ) | ||
| 39 | * | ||
| 40 | * ( 2 2) | ||
| 41 | * 1 (x + (y+1) ) | ||
| 42 | * Im w = - log(------------) | ||
| 43 | * 4 ( 2 2) | ||
| 44 | * (x + (y-1) ) | ||
| 45 | * | ||
| 46 | * Where k is an arbitrary integer. | ||
| 47 | * | ||
| 48 | * | ||
| 49 | * ACCURACY: | ||
| 50 | * | ||
| 51 | * Relative error: | ||
| 52 | * arithmetic domain # trials peak rms | ||
| 53 | * IEEE -10,+10 30000 2.3e-6 5.2e-8 | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include "complex_impl.h" | ||
| 57 | |||
| 58 | #define MAXNUMF 1.0e38F | ||
| 59 | |||
| 60 | static const double DP1 = 3.140625; | ||
| 61 | static const double DP2 = 9.67502593994140625E-4; | ||
| 62 | static const double DP3 = 1.509957990978376432E-7; | ||
| 63 | |||
| 64 | static float _redupif(float xx) | ||
| 65 | { | ||
| 66 | 	float x, t; | ||
| 67 | 	long i; | ||
| 68 | |||
| 69 | 	x = xx; | ||
| 70 | 	t = x/(float)M_PI; | ||
| 71 | 	if (t >= 0.0f) | ||
| 72 | 		t += 0.5f; | ||
| 73 | 	else | ||
| 74 | 		t -= 0.5f; | ||
| 75 | |||
| 76 | 	i = t; /* the multiple */ | ||
| 77 | 	t = i; | ||
| 78 | 	t = ((x - t * DP1) - t * DP2) - t * DP3; | ||
| 79 | 	return t; | ||
| 80 | } | ||
| 81 | |||
| 82 | float complex catanf(float complex z) | ||
| 83 | { | ||
| 84 | 	float complex w; | ||
| 85 | 	float a, t, x, x2, y; | ||
| 86 | |||
| 87 | 	x = crealf(z); | ||
| 88 | 	y = cimagf(z); | ||
| 89 | |||
| 90 | 	x2 = x * x; | ||
| 91 | 	a = 1.0f - x2 - (y * y); | ||
| 92 | |||
| 93 | 	t = 0.5f * atan2f(2.0f * x, a); | ||
| 94 | 	w = _redupif(t); | ||
| 95 | |||
| 96 | 	t = y - 1.0f; | ||
| 97 | 	a = x2 + (t * t); | ||
| 98 | |||
| 99 | 	t = y + 1.0f; | ||
| 100 | 	a = (x2 + (t * t))/a; | ||
| 101 | 	w = CMPLXF(w, 0.25f * logf(a)); | ||
| 102 | 	return w; | ||
| 103 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/catanh.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* atanh = -i atan(i z) */ | ||
| 4 | |||
| 5 | double complex catanh(double complex z) | ||
| 6 | { | ||
| 7 | 	z = catan(CMPLX(-cimag(z), creal(z))); | ||
| 8 | 	return CMPLX(cimag(z), -creal(z)); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/catanhf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex catanhf(float complex z) | ||
| 4 | { | ||
| 5 | 	z = catanf(CMPLXF(-cimagf(z), crealf(z))); | ||
| 6 | 	return CMPLXF(cimagf(z), -crealf(z)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/catanhl.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex catanhl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return catanh(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex catanhl(long double complex z) | ||
| 10 | { | ||
| 11 | 	z = catanl(CMPLXL(-cimagl(z), creall(z))); | ||
| 12 | 	return CMPLXL(cimagl(z), -creall(z)); | ||
| 13 | } | ||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/catanl.c created+114| ... | @@ -0,0 +1,114 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/s_catanl.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 | /* | ||
| 18 | * Complex circular arc tangent | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * long double complex catanl(); | ||
| 24 | * long double complex z, w; | ||
| 25 | * | ||
| 26 | * w = catanl( z ); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * If | ||
| 32 | * z = x + iy, | ||
| 33 | * | ||
| 34 | * then | ||
| 35 | * 1 ( 2x ) | ||
| 36 | * Re w = - arctan(-----------) + k PI | ||
| 37 | * 2 ( 2 2) | ||
| 38 | * (1 - x - y ) | ||
| 39 | * | ||
| 40 | * ( 2 2) | ||
| 41 | * 1 (x + (y+1) ) | ||
| 42 | * Im w = - log(------------) | ||
| 43 | * 4 ( 2 2) | ||
| 44 | * (x + (y-1) ) | ||
| 45 | * | ||
| 46 | * Where k is an arbitrary integer. | ||
| 47 | * | ||
| 48 | * | ||
| 49 | * ACCURACY: | ||
| 50 | * | ||
| 51 | * Relative error: | ||
| 52 | * arithmetic domain # trials peak rms | ||
| 53 | * DEC -10,+10 5900 1.3e-16 7.8e-18 | ||
| 54 | * IEEE -10,+10 30000 2.3e-15 8.5e-17 | ||
| 55 | * The check catan( ctan(z) ) = z, with |x| and |y| < PI/2, | ||
| 56 | * had peak relative error 1.5e-16, rms relative error | ||
| 57 | * 2.9e-17. See also clog(). | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include <complex.h> | ||
| 61 | #include <float.h> | ||
| 62 | #include "complex_impl.h" | ||
| 63 | |||
| 64 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 65 | long double complex catanl(long double complex z) | ||
| 66 | { | ||
| 67 | 	return catan(z); | ||
| 68 | } | ||
| 69 | #else | ||
| 70 | static const long double PIL = 3.141592653589793238462643383279502884197169L; | ||
| 71 | static const long double DP1 = 3.14159265358979323829596852490908531763125L; | ||
| 72 | static const long double DP2 = 1.6667485837041756656403424829301998703007e-19L; | ||
| 73 | static const long double DP3 = 1.8830410776607851167459095484560349402753e-39L; | ||
| 74 | |||
| 75 | static long double redupil(long double x) | ||
| 76 | { | ||
| 77 | 	long double t; | ||
| 78 | 	long i; | ||
| 79 | |||
| 80 | 	t = x / PIL; | ||
| 81 | 	if (t >= 0.0L) | ||
| 82 | 		t += 0.5L; | ||
| 83 | 	else | ||
| 84 | 		t -= 0.5L; | ||
| 85 | |||
| 86 | 	i = t; /* the multiple */ | ||
| 87 | 	t = i; | ||
| 88 | 	t = ((x - t * DP1) - t * DP2) - t * DP3; | ||
| 89 | 	return t; | ||
| 90 | } | ||
| 91 | |||
| 92 | long double complex catanl(long double complex z) | ||
| 93 | { | ||
| 94 | 	long double complex w; | ||
| 95 | 	long double a, t, x, x2, y; | ||
| 96 | |||
| 97 | 	x = creall(z); | ||
| 98 | 	y = cimagl(z); | ||
| 99 | |||
| 100 | 	x2 = x * x; | ||
| 101 | 	a = 1.0L - x2 - (y * y); | ||
| 102 | |||
| 103 | 	t = atan2l(2.0L * x, a) * 0.5L; | ||
| 104 | 	w = redupil(t); | ||
| 105 | |||
| 106 | 	t = y - 1.0L; | ||
| 107 | 	a = x2 + (t * t); | ||
| 108 | |||
| 109 | 	t = y + 1.0L; | ||
| 110 | 	a = (x2 + (t * t)) / a; | ||
| 111 | 	w = CMPLXF(w, 0.25L * logl(a)); | ||
| 112 | 	return w; | ||
| 113 | } | ||
| 114 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ccos.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* cos(z) = cosh(i z) */ | ||
| 4 | |||
| 5 | double complex ccos(double complex z) | ||
| 6 | { | ||
| 7 | 	return ccosh(CMPLX(-cimag(z), creal(z))); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ccosf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex ccosf(float complex z) | ||
| 4 | { | ||
| 5 | 	return ccoshf(CMPLXF(-cimagf(z), crealf(z))); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ccosh.c created+140| ... | @@ -0,0 +1,140 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_ccosh.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl | ||
| 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 unmodified, this list of conditions, and the following | ||
| 11 | * 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 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | /* | ||
| 28 | * Hyperbolic cosine of a complex argument z = x + i y. | ||
| 29 | * | ||
| 30 | * cosh(z) = cosh(x+iy) | ||
| 31 | * = cosh(x) cos(y) + i sinh(x) sin(y). | ||
| 32 | * | ||
| 33 | * Exceptional values are noted in the comments within the source code. | ||
| 34 | * These values and the return value were taken from n1124.pdf. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include "complex_impl.h" | ||
| 38 | |||
| 39 | static const double huge = 0x1p1023; | ||
| 40 | |||
| 41 | double complex ccosh(double complex z) | ||
| 42 | { | ||
| 43 | 	double x, y, h; | ||
| 44 | 	int32_t hx, hy, ix, iy, lx, ly; | ||
| 45 | |||
| 46 | 	x = creal(z); | ||
| 47 | 	y = cimag(z); | ||
| 48 | |||
| 49 | 	EXTRACT_WORDS(hx, lx, x); | ||
| 50 | 	EXTRACT_WORDS(hy, ly, y); | ||
| 51 | |||
| 52 | 	ix = 0x7fffffff & hx; | ||
| 53 | 	iy = 0x7fffffff & hy; | ||
| 54 | |||
| 55 | 	/* Handle the nearly-non-exceptional cases where x and y are finite. */ | ||
| 56 | 	if (ix < 0x7ff00000 && iy < 0x7ff00000) { | ||
| 57 | 		if ((iy | ly) == 0) | ||
| 58 | 			return CMPLX(cosh(x), x * y); | ||
| 59 | 		if (ix < 0x40360000) /* small x: normal case */ | ||
| 60 | 			return CMPLX(cosh(x) * cos(y), sinh(x) * sin(y)); | ||
| 61 | |||
| 62 | 		/* |x| >= 22, so cosh(x) ~= exp(|x|) */ | ||
| 63 | 		if (ix < 0x40862e42) { | ||
| 64 | 			/* x < 710: exp(|x|) won't overflow */ | ||
| 65 | 			h = exp(fabs(x)) * 0.5; | ||
| 66 | 			return CMPLX(h * cos(y), copysign(h, x) * sin(y)); | ||
| 67 | 		} else if (ix < 0x4096bbaa) { | ||
| 68 | 			/* x < 1455: scale to avoid overflow */ | ||
| 69 | 			z = __ldexp_cexp(CMPLX(fabs(x), y), -1); | ||
| 70 | 			return CMPLX(creal(z), cimag(z) * copysign(1, x)); | ||
| 71 | 		} else { | ||
| 72 | 			/* x >= 1455: the result always overflows */ | ||
| 73 | 			h = huge * x; | ||
| 74 | 			return CMPLX(h * h * cos(y), h * sin(y)); | ||
| 75 | 		} | ||
| 76 | 	} | ||
| 77 | |||
| 78 | 	/* | ||
| 79 | 	 * cosh(+-0 +- I Inf) = dNaN + I sign(d(+-0, dNaN))0. | ||
| 80 | 	 * The sign of 0 in the result is unspecified. Choice = normally | ||
| 81 | 	 * the same as dNaN. Raise the invalid floating-point exception. | ||
| 82 | 	 * | ||
| 83 | 	 * cosh(+-0 +- I NaN) = d(NaN) + I sign(d(+-0, NaN))0. | ||
| 84 | 	 * The sign of 0 in the result is unspecified. Choice = normally | ||
| 85 | 	 * the same as d(NaN). | ||
| 86 | 	 */ | ||
| 87 | 	if ((ix | lx) == 0 && iy >= 0x7ff00000) | ||
| 88 | 		return CMPLX(y - y, copysign(0, x * (y - y))); | ||
| 89 | |||
| 90 | 	/* | ||
| 91 | 	 * cosh(+-Inf +- I 0) = +Inf + I (+-)(+-)0. | ||
| 92 | 	 * | ||
| 93 | 	 * cosh(NaN +- I 0) = d(NaN) + I sign(d(NaN, +-0))0. | ||
| 94 | 	 * The sign of 0 in the result is unspecified. | ||
| 95 | 	 */ | ||
| 96 | 	if ((iy | ly) == 0 && ix >= 0x7ff00000) { | ||
| 97 | 		if (((hx & 0xfffff) | lx) == 0) | ||
| 98 | 			return CMPLX(x * x, copysign(0, x) * y); | ||
| 99 | 		return CMPLX(x * x, copysign(0, (x + x) * y)); | ||
| 100 | 	} | ||
| 101 | |||
| 102 | 	/* | ||
| 103 | 	 * cosh(x +- I Inf) = dNaN + I dNaN. | ||
| 104 | 	 * Raise the invalid floating-point exception for finite nonzero x. | ||
| 105 | 	 * | ||
| 106 | 	 * cosh(x + I NaN) = d(NaN) + I d(NaN). | ||
| 107 | 	 * Optionally raises the invalid floating-point exception for finite | ||
| 108 | 	 * nonzero x. Choice = don't raise (except for signaling NaNs). | ||
| 109 | 	 */ | ||
| 110 | 	if (ix < 0x7ff00000 && iy >= 0x7ff00000) | ||
| 111 | 		return CMPLX(y - y, x * (y - y)); | ||
| 112 | |||
| 113 | 	/* | ||
| 114 | 	 * cosh(+-Inf + I NaN) = +Inf + I d(NaN). | ||
| 115 | 	 * | ||
| 116 | 	 * cosh(+-Inf +- I Inf) = +Inf + I dNaN. | ||
| 117 | 	 * The sign of Inf in the result is unspecified. Choice = always +. | ||
| 118 | 	 * Raise the invalid floating-point exception. | ||
| 119 | 	 * | ||
| 120 | 	 * cosh(+-Inf + I y) = +Inf cos(y) +- I Inf sin(y) | ||
| 121 | 	 */ | ||
| 122 | 	if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { | ||
| 123 | 		if (iy >= 0x7ff00000) | ||
| 124 | 			return CMPLX(x * x, x * (y - y)); | ||
| 125 | 		return CMPLX((x * x) * cos(y), x * sin(y)); | ||
| 126 | 	} | ||
| 127 | |||
| 128 | 	/* | ||
| 129 | 	 * cosh(NaN + I NaN) = d(NaN) + I d(NaN). | ||
| 130 | 	 * | ||
| 131 | 	 * cosh(NaN +- I Inf) = d(NaN) + I d(NaN). | ||
| 132 | 	 * Optionally raises the invalid floating-point exception. | ||
| 133 | 	 * Choice = raise. | ||
| 134 | 	 * | ||
| 135 | 	 * cosh(NaN + I y) = d(NaN) + I d(NaN). | ||
| 136 | 	 * Optionally raises the invalid floating-point exception for finite | ||
| 137 | 	 * nonzero y. Choice = don't raise (except for signaling NaNs). | ||
| 138 | 	 */ | ||
| 139 | 	return CMPLX((x * x) * (y - y), (x + x) * (y - y)); | ||
| 140 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ccoshf.c created+90| ... | @@ -0,0 +1,90 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_ccoshf.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl | ||
| 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 unmodified, this list of conditions, and the following | ||
| 11 | * 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 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | /* | ||
| 28 | * Hyperbolic cosine of a complex argument. See s_ccosh.c for details. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include "complex_impl.h" | ||
| 32 | |||
| 33 | static const float huge = 0x1p127; | ||
| 34 | |||
| 35 | float complex ccoshf(float complex z) | ||
| 36 | { | ||
| 37 | 	float x, y, h; | ||
| 38 | 	int32_t hx, hy, ix, iy; | ||
| 39 | |||
| 40 | 	x = crealf(z); | ||
| 41 | 	y = cimagf(z); | ||
| 42 | |||
| 43 | 	GET_FLOAT_WORD(hx, x); | ||
| 44 | 	GET_FLOAT_WORD(hy, y); | ||
| 45 | |||
| 46 | 	ix = 0x7fffffff & hx; | ||
| 47 | 	iy = 0x7fffffff & hy; | ||
| 48 | |||
| 49 | 	if (ix < 0x7f800000 && iy < 0x7f800000) { | ||
| 50 | 		if (iy == 0) | ||
| 51 | 			return CMPLXF(coshf(x), x * y); | ||
| 52 | 		if (ix < 0x41100000) /* small x: normal case */ | ||
| 53 | 			return CMPLXF(coshf(x) * cosf(y), sinhf(x) * sinf(y)); | ||
| 54 | |||
| 55 | 		/* |x| >= 9, so cosh(x) ~= exp(|x|) */ | ||
| 56 | 		if (ix < 0x42b17218) { | ||
| 57 | 			/* x < 88.7: expf(|x|) won't overflow */ | ||
| 58 | 			h = expf(fabsf(x)) * 0.5f; | ||
| 59 | 			return CMPLXF(h * cosf(y), copysignf(h, x) * sinf(y)); | ||
| 60 | 		} else if (ix < 0x4340b1e7) { | ||
| 61 | 			/* x < 192.7: scale to avoid overflow */ | ||
| 62 | 			z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); | ||
| 63 | 			return CMPLXF(crealf(z), cimagf(z) * copysignf(1, x)); | ||
| 64 | 		} else { | ||
| 65 | 			/* x >= 192.7: the result always overflows */ | ||
| 66 | 			h = huge * x; | ||
| 67 | 			return CMPLXF(h * h * cosf(y), h * sinf(y)); | ||
| 68 | 		} | ||
| 69 | 	} | ||
| 70 | |||
| 71 | 	if (ix == 0 && iy >= 0x7f800000) | ||
| 72 | 		return CMPLXF(y - y, copysignf(0, x * (y - y))); | ||
| 73 | |||
| 74 | 	if (iy == 0 && ix >= 0x7f800000) { | ||
| 75 | 		if ((hx & 0x7fffff) == 0) | ||
| 76 | 			return CMPLXF(x * x, copysignf(0, x) * y); | ||
| 77 | 		return CMPLXF(x * x, copysignf(0, (x + x) * y)); | ||
| 78 | 	} | ||
| 79 | |||
| 80 | 	if (ix < 0x7f800000 && iy >= 0x7f800000) | ||
| 81 | 		return CMPLXF(y - y, x * (y - y)); | ||
| 82 | |||
| 83 | 	if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { | ||
| 84 | 		if (iy >= 0x7f800000) | ||
| 85 | 			return CMPLXF(x * x, x * (y - y)); | ||
| 86 | 		return CMPLXF((x * x) * cosf(y), x * sinf(y)); | ||
| 87 | 	} | ||
| 88 | |||
| 89 | 	return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); | ||
| 90 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ccoshl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | //FIXME | ||
| 4 | long double complex ccoshl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return ccosh(z); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ccosl.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex ccosl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return ccos(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex ccosl(long double complex z) | ||
| 10 | { | ||
| 11 | 	return ccoshl(CMPLXL(-cimagl(z), creall(z))); | ||
| 12 | } | ||
| 13 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cexp.c created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cexp.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 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 | #include "complex_impl.h" | ||
| 29 | |||
| 30 | static const uint32_t | ||
| 31 | exp_ovfl = 0x40862e42, /* high bits of MAX_EXP * ln2 ~= 710 */ | ||
| 32 | cexp_ovfl = 0x4096b8e4; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ | ||
| 33 | |||
| 34 | double complex cexp(double complex z) | ||
| 35 | { | ||
| 36 | 	double x, y, exp_x; | ||
| 37 | 	uint32_t hx, hy, lx, ly; | ||
| 38 | |||
| 39 | 	x = creal(z); | ||
| 40 | 	y = cimag(z); | ||
| 41 | |||
| 42 | 	EXTRACT_WORDS(hy, ly, y); | ||
| 43 | 	hy &= 0x7fffffff; | ||
| 44 | |||
| 45 | 	/* cexp(x + I 0) = exp(x) + I 0 */ | ||
| 46 | 	if ((hy | ly) == 0) | ||
| 47 | 		return CMPLX(exp(x), y); | ||
| 48 | 	EXTRACT_WORDS(hx, lx, x); | ||
| 49 | 	/* cexp(0 + I y) = cos(y) + I sin(y) */ | ||
| 50 | 	if (((hx & 0x7fffffff) | lx) == 0) | ||
| 51 | 		return CMPLX(cos(y), sin(y)); | ||
| 52 | |||
| 53 | 	if (hy >= 0x7ff00000) { | ||
| 54 | 		if (lx != 0 || (hx & 0x7fffffff) != 0x7ff00000) { | ||
| 55 | 			/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ | ||
| 56 | 			return CMPLX(y - y, y - y); | ||
| 57 | 		} else if (hx & 0x80000000) { | ||
| 58 | 			/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ | ||
| 59 | 			return CMPLX(0.0, 0.0); | ||
| 60 | 		} else { | ||
| 61 | 			/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ | ||
| 62 | 			return CMPLX(x, y - y); | ||
| 63 | 		} | ||
| 64 | 	} | ||
| 65 | |||
| 66 | 	if (hx >= exp_ovfl && hx <= cexp_ovfl) { | ||
| 67 | 		/* | ||
| 68 | 		 * x is between 709.7 and 1454.3, so we must scale to avoid | ||
| 69 | 		 * overflow in exp(x). | ||
| 70 | 		 */ | ||
| 71 | 		return __ldexp_cexp(z, 0); | ||
| 72 | 	} else { | ||
| 73 | 		/* | ||
| 74 | 		 * Cases covered here: | ||
| 75 | 		 * - x < exp_ovfl and exp(x) won't overflow (common case) | ||
| 76 | 		 * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 | ||
| 77 | 		 * - x = +-Inf (generated by exp()) | ||
| 78 | 		 * - x = NaN (spurious inexact exception from y) | ||
| 79 | 		 */ | ||
| 80 | 		exp_x = exp(x); | ||
| 81 | 		return CMPLX(exp_x * cos(y), exp_x * sin(y)); | ||
| 82 | 	} | ||
| 83 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cexpf.c created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cexpf.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 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 | #include "complex_impl.h" | ||
| 29 | |||
| 30 | static const uint32_t | ||
| 31 | exp_ovfl = 0x42b17218, /* MAX_EXP * ln2 ~= 88.722839355 */ | ||
| 32 | cexp_ovfl = 0x43400074; /* (MAX_EXP - MIN_DENORM_EXP) * ln2 */ | ||
| 33 | |||
| 34 | float complex cexpf(float complex z) | ||
| 35 | { | ||
| 36 | 	float x, y, exp_x; | ||
| 37 | 	uint32_t hx, hy; | ||
| 38 | |||
| 39 | 	x = crealf(z); | ||
| 40 | 	y = cimagf(z); | ||
| 41 | |||
| 42 | 	GET_FLOAT_WORD(hy, y); | ||
| 43 | 	hy &= 0x7fffffff; | ||
| 44 | |||
| 45 | 	/* cexp(x + I 0) = exp(x) + I 0 */ | ||
| 46 | 	if (hy == 0) | ||
| 47 | 		return CMPLXF(expf(x), y); | ||
| 48 | 	GET_FLOAT_WORD(hx, x); | ||
| 49 | 	/* cexp(0 + I y) = cos(y) + I sin(y) */ | ||
| 50 | 	if ((hx & 0x7fffffff) == 0) | ||
| 51 | 		return CMPLXF(cosf(y), sinf(y)); | ||
| 52 | |||
| 53 | 	if (hy >= 0x7f800000) { | ||
| 54 | 		if ((hx & 0x7fffffff) != 0x7f800000) { | ||
| 55 | 			/* cexp(finite|NaN +- I Inf|NaN) = NaN + I NaN */ | ||
| 56 | 			return CMPLXF(y - y, y - y); | ||
| 57 | 		} else if (hx & 0x80000000) { | ||
| 58 | 			/* cexp(-Inf +- I Inf|NaN) = 0 + I 0 */ | ||
| 59 | 			return CMPLXF(0.0, 0.0); | ||
| 60 | 		} else { | ||
| 61 | 			/* cexp(+Inf +- I Inf|NaN) = Inf + I NaN */ | ||
| 62 | 			return CMPLXF(x, y - y); | ||
| 63 | 		} | ||
| 64 | 	} | ||
| 65 | |||
| 66 | 	if (hx >= exp_ovfl && hx <= cexp_ovfl) { | ||
| 67 | 		/* | ||
| 68 | 		 * x is between 88.7 and 192, so we must scale to avoid | ||
| 69 | 		 * overflow in expf(x). | ||
| 70 | 		 */ | ||
| 71 | 		return __ldexp_cexpf(z, 0); | ||
| 72 | 	} else { | ||
| 73 | 		/* | ||
| 74 | 		 * Cases covered here: | ||
| 75 | 		 * - x < exp_ovfl and exp(x) won't overflow (common case) | ||
| 76 | 		 * - x > cexp_ovfl, so exp(x) * s overflows for all s > 0 | ||
| 77 | 		 * - x = +-Inf (generated by exp()) | ||
| 78 | 		 * - x = NaN (spurious inexact exception from y) | ||
| 79 | 		 */ | ||
| 80 | 		exp_x = expf(x); | ||
| 81 | 		return CMPLXF(exp_x * cosf(y), exp_x * sinf(y)); | ||
| 82 | 	} | ||
| 83 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cexpl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | //FIXME | ||
| 4 | long double complex cexpl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return cexp(z); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cimag.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | double (cimag)(double complex z) | ||
| 4 | { | ||
| 5 | 	return cimag(z); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cimagf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float (cimagf)(float complex z) | ||
| 4 | { | ||
| 5 | 	return cimagf(z); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cimagl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | long double (cimagl)(long double complex z) | ||
| 4 | { | ||
| 5 | 	return cimagl(z); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/clog.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | // FIXME | ||
| 4 | |||
| 5 | /* log(z) = log(|z|) + i arg(z) */ | ||
| 6 | |||
| 7 | double complex clog(double complex z) | ||
| 8 | { | ||
| 9 | 	double r, phi; | ||
| 10 | |||
| 11 | 	r = cabs(z); | ||
| 12 | 	phi = carg(z); | ||
| 13 | 	return CMPLX(log(r), phi); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/clogf.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | // FIXME | ||
| 4 | |||
| 5 | float complex clogf(float complex z) | ||
| 6 | { | ||
| 7 | 	float r, phi; | ||
| 8 | |||
| 9 | 	r = cabsf(z); | ||
| 10 | 	phi = cargf(z); | ||
| 11 | 	return CMPLXF(logf(r), phi); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/clogl.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex clogl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return clog(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | // FIXME | ||
| 10 | long double complex clogl(long double complex z) | ||
| 11 | { | ||
| 12 | 	long double r, phi; | ||
| 13 | |||
| 14 | 	r = cabsl(z); | ||
| 15 | 	phi = cargl(z); | ||
| 16 | 	return CMPLXL(logl(r), phi); | ||
| 17 | } | ||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/conj.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | double complex conj(double complex z) | ||
| 4 | { | ||
| 5 | 	return CMPLX(creal(z), -cimag(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/conjf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex conjf(float complex z) | ||
| 4 | { | ||
| 5 | 	return CMPLXF(crealf(z), -cimagf(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/conjl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | long double complex conjl(long double complex z) | ||
| 4 | { | ||
| 5 | 	return CMPLXL(creall(z), -cimagl(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cpow.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* pow(z, c) = exp(c log(z)), See C99 G.6.4.1 */ | ||
| 4 | |||
| 5 | double complex cpow(double complex z, double complex c) | ||
| 6 | { | ||
| 7 | 	return cexp(c * clog(z)); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cpowf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex cpowf(float complex z, float complex c) | ||
| 4 | { | ||
| 5 | 	return cexpf(c * clogf(z)); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cpowl.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex cpowl(long double complex z, long double complex c) | ||
| 5 | { | ||
| 6 | 	return cpow(z, c); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex cpowl(long double complex z, long double complex c) | ||
| 10 | { | ||
| 11 | 	return cexpl(c * clogl(z)); | ||
| 12 | } | ||
| 13 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cproj.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | double complex cproj(double complex z) | ||
| 4 | { | ||
| 5 | 	if (isinf(creal(z)) || isinf(cimag(z))) | ||
| 6 | 		return CMPLX(INFINITY, copysign(0.0, creal(z))); | ||
| 7 | 	return z; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cprojf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex cprojf(float complex z) | ||
| 4 | { | ||
| 5 | 	if (isinf(crealf(z)) || isinf(cimagf(z))) | ||
| 6 | 		return CMPLXF(INFINITY, copysignf(0.0, crealf(z))); | ||
| 7 | 	return z; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/cprojl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex cprojl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return cproj(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex cprojl(long double complex z) | ||
| 10 | { | ||
| 11 | 	if (isinf(creall(z)) || isinf(cimagl(z))) | ||
| 12 | 		return CMPLXL(INFINITY, copysignl(0.0, creall(z))); | ||
| 13 | 	return z; | ||
| 14 | } | ||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/creal.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <complex.h> | ||
| 2 | |||
| 3 | double (creal)(double complex z) | ||
| 4 | { | ||
| 5 | 	return creal(z); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/crealf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <complex.h> | ||
| 2 | |||
| 3 | float (crealf)(float complex z) | ||
| 4 | { | ||
| 5 | 	return crealf(z); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/creall.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <complex.h> | ||
| 2 | |||
| 3 | long double (creall)(long double complex z) | ||
| 4 | { | ||
| 5 | 	return creall(z); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csin.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* sin(z) = -i sinh(i z) */ | ||
| 4 | |||
| 5 | double complex csin(double complex z) | ||
| 6 | { | ||
| 7 | 	z = csinh(CMPLX(-cimag(z), creal(z))); | ||
| 8 | 	return CMPLX(cimag(z), -creal(z)); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csinf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex csinf(float complex z) | ||
| 4 | { | ||
| 5 | 	z = csinhf(CMPLXF(-cimagf(z), crealf(z))); | ||
| 6 | 	return CMPLXF(cimagf(z), -crealf(z)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csinh.c created+141| ... | @@ -0,0 +1,141 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_csinh.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl | ||
| 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 unmodified, this list of conditions, and the following | ||
| 11 | * 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 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | /* | ||
| 28 | * Hyperbolic sine of a complex argument z = x + i y. | ||
| 29 | * | ||
| 30 | * sinh(z) = sinh(x+iy) | ||
| 31 | * = sinh(x) cos(y) + i cosh(x) sin(y). | ||
| 32 | * | ||
| 33 | * Exceptional values are noted in the comments within the source code. | ||
| 34 | * These values and the return value were taken from n1124.pdf. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include "complex_impl.h" | ||
| 38 | |||
| 39 | static const double huge = 0x1p1023; | ||
| 40 | |||
| 41 | double complex csinh(double complex z) | ||
| 42 | { | ||
| 43 | 	double x, y, h; | ||
| 44 | 	int32_t hx, hy, ix, iy, lx, ly; | ||
| 45 | |||
| 46 | 	x = creal(z); | ||
| 47 | 	y = cimag(z); | ||
| 48 | |||
| 49 | 	EXTRACT_WORDS(hx, lx, x); | ||
| 50 | 	EXTRACT_WORDS(hy, ly, y); | ||
| 51 | |||
| 52 | 	ix = 0x7fffffff & hx; | ||
| 53 | 	iy = 0x7fffffff & hy; | ||
| 54 | |||
| 55 | 	/* Handle the nearly-non-exceptional cases where x and y are finite. */ | ||
| 56 | 	if (ix < 0x7ff00000 && iy < 0x7ff00000) { | ||
| 57 | 		if ((iy | ly) == 0) | ||
| 58 | 			return CMPLX(sinh(x), y); | ||
| 59 | 		if (ix < 0x40360000) /* small x: normal case */ | ||
| 60 | 			return CMPLX(sinh(x) * cos(y), cosh(x) * sin(y)); | ||
| 61 | |||
| 62 | 		/* |x| >= 22, so cosh(x) ~= exp(|x|) */ | ||
| 63 | 		if (ix < 0x40862e42) { | ||
| 64 | 			/* x < 710: exp(|x|) won't overflow */ | ||
| 65 | 			h = exp(fabs(x)) * 0.5; | ||
| 66 | 			return CMPLX(copysign(h, x) * cos(y), h * sin(y)); | ||
| 67 | 		} else if (ix < 0x4096bbaa) { | ||
| 68 | 			/* x < 1455: scale to avoid overflow */ | ||
| 69 | 			z = __ldexp_cexp(CMPLX(fabs(x), y), -1); | ||
| 70 | 			return CMPLX(creal(z) * copysign(1, x), cimag(z)); | ||
| 71 | 		} else { | ||
| 72 | 			/* x >= 1455: the result always overflows */ | ||
| 73 | 			h = huge * x; | ||
| 74 | 			return CMPLX(h * cos(y), h * h * sin(y)); | ||
| 75 | 		} | ||
| 76 | 	} | ||
| 77 | |||
| 78 | 	/* | ||
| 79 | 	 * sinh(+-0 +- I Inf) = sign(d(+-0, dNaN))0 + I dNaN. | ||
| 80 | 	 * The sign of 0 in the result is unspecified. Choice = normally | ||
| 81 | 	 * the same as dNaN. Raise the invalid floating-point exception. | ||
| 82 | 	 * | ||
| 83 | 	 * sinh(+-0 +- I NaN) = sign(d(+-0, NaN))0 + I d(NaN). | ||
| 84 | 	 * The sign of 0 in the result is unspecified. Choice = normally | ||
| 85 | 	 * the same as d(NaN). | ||
| 86 | 	 */ | ||
| 87 | 	if ((ix | lx) == 0 && iy >= 0x7ff00000) | ||
| 88 | 		return CMPLX(copysign(0, x * (y - y)), y - y); | ||
| 89 | |||
| 90 | 	/* | ||
| 91 | 	 * sinh(+-Inf +- I 0) = +-Inf + I +-0. | ||
| 92 | 	 * | ||
| 93 | 	 * sinh(NaN +- I 0) = d(NaN) + I +-0. | ||
| 94 | 	 */ | ||
| 95 | 	if ((iy | ly) == 0 && ix >= 0x7ff00000) { | ||
| 96 | 		if (((hx & 0xfffff) | lx) == 0) | ||
| 97 | 			return CMPLX(x, y); | ||
| 98 | 		return CMPLX(x, copysign(0, y)); | ||
| 99 | 	} | ||
| 100 | |||
| 101 | 	/* | ||
| 102 | 	 * sinh(x +- I Inf) = dNaN + I dNaN. | ||
| 103 | 	 * Raise the invalid floating-point exception for finite nonzero x. | ||
| 104 | 	 * | ||
| 105 | 	 * sinh(x + I NaN) = d(NaN) + I d(NaN). | ||
| 106 | 	 * Optionally raises the invalid floating-point exception for finite | ||
| 107 | 	 * nonzero x. Choice = don't raise (except for signaling NaNs). | ||
| 108 | 	 */ | ||
| 109 | 	if (ix < 0x7ff00000 && iy >= 0x7ff00000) | ||
| 110 | 		return CMPLX(y - y, x * (y - y)); | ||
| 111 | |||
| 112 | 	/* | ||
| 113 | 	 * sinh(+-Inf + I NaN) = +-Inf + I d(NaN). | ||
| 114 | 	 * The sign of Inf in the result is unspecified. Choice = normally | ||
| 115 | 	 * the same as d(NaN). | ||
| 116 | 	 * | ||
| 117 | 	 * sinh(+-Inf +- I Inf) = +Inf + I dNaN. | ||
| 118 | 	 * The sign of Inf in the result is unspecified. Choice = always +. | ||
| 119 | 	 * Raise the invalid floating-point exception. | ||
| 120 | 	 * | ||
| 121 | 	 * sinh(+-Inf + I y) = +-Inf cos(y) + I Inf sin(y) | ||
| 122 | 	 */ | ||
| 123 | 	if (ix >= 0x7ff00000 && ((hx & 0xfffff) | lx) == 0) { | ||
| 124 | 		if (iy >= 0x7ff00000) | ||
| 125 | 			return CMPLX(x * x, x * (y - y)); | ||
| 126 | 		return CMPLX(x * cos(y), INFINITY * sin(y)); | ||
| 127 | 	} | ||
| 128 | |||
| 129 | 	/* | ||
| 130 | 	 * sinh(NaN + I NaN) = d(NaN) + I d(NaN). | ||
| 131 | 	 * | ||
| 132 | 	 * sinh(NaN +- I Inf) = d(NaN) + I d(NaN). | ||
| 133 | 	 * Optionally raises the invalid floating-point exception. | ||
| 134 | 	 * Choice = raise. | ||
| 135 | 	 * | ||
| 136 | 	 * sinh(NaN + I y) = d(NaN) + I d(NaN). | ||
| 137 | 	 * Optionally raises the invalid floating-point exception for finite | ||
| 138 | 	 * nonzero y. Choice = don't raise (except for signaling NaNs). | ||
| 139 | 	 */ | ||
| 140 | 	return CMPLX((x * x) * (y - y), (x + x) * (y - y)); | ||
| 141 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csinhf.c created+90| ... | @@ -0,0 +1,90 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_csinhf.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2005 Bruce D. Evans and Steven G. Kargl | ||
| 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 unmodified, this list of conditions, and the following | ||
| 11 | * 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 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | /* | ||
| 28 | * Hyperbolic sine of a complex argument z. See s_csinh.c for details. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include "complex_impl.h" | ||
| 32 | |||
| 33 | static const float huge = 0x1p127; | ||
| 34 | |||
| 35 | float complex csinhf(float complex z) | ||
| 36 | { | ||
| 37 | 	float x, y, h; | ||
| 38 | 	int32_t hx, hy, ix, iy; | ||
| 39 | |||
| 40 | 	x = crealf(z); | ||
| 41 | 	y = cimagf(z); | ||
| 42 | |||
| 43 | 	GET_FLOAT_WORD(hx, x); | ||
| 44 | 	GET_FLOAT_WORD(hy, y); | ||
| 45 | |||
| 46 | 	ix = 0x7fffffff & hx; | ||
| 47 | 	iy = 0x7fffffff & hy; | ||
| 48 | |||
| 49 | 	if (ix < 0x7f800000 && iy < 0x7f800000) { | ||
| 50 | 		if (iy == 0) | ||
| 51 | 			return CMPLXF(sinhf(x), y); | ||
| 52 | 		if (ix < 0x41100000) /* small x: normal case */ | ||
| 53 | 			return CMPLXF(sinhf(x) * cosf(y), coshf(x) * sinf(y)); | ||
| 54 | |||
| 55 | 		/* |x| >= 9, so cosh(x) ~= exp(|x|) */ | ||
| 56 | 		if (ix < 0x42b17218) { | ||
| 57 | 			/* x < 88.7: expf(|x|) won't overflow */ | ||
| 58 | 			h = expf(fabsf(x)) * 0.5f; | ||
| 59 | 			return CMPLXF(copysignf(h, x) * cosf(y), h * sinf(y)); | ||
| 60 | 		} else if (ix < 0x4340b1e7) { | ||
| 61 | 			/* x < 192.7: scale to avoid overflow */ | ||
| 62 | 			z = __ldexp_cexpf(CMPLXF(fabsf(x), y), -1); | ||
| 63 | 			return CMPLXF(crealf(z) * copysignf(1, x), cimagf(z)); | ||
| 64 | 		} else { | ||
| 65 | 			/* x >= 192.7: the result always overflows */ | ||
| 66 | 			h = huge * x; | ||
| 67 | 			return CMPLXF(h * cosf(y), h * h * sinf(y)); | ||
| 68 | 		} | ||
| 69 | 	} | ||
| 70 | |||
| 71 | 	if (ix == 0 && iy >= 0x7f800000) | ||
| 72 | 		return CMPLXF(copysignf(0, x * (y - y)), y - y); | ||
| 73 | |||
| 74 | 	if (iy == 0 && ix >= 0x7f800000) { | ||
| 75 | 		if ((hx & 0x7fffff) == 0) | ||
| 76 | 			return CMPLXF(x, y); | ||
| 77 | 		return CMPLXF(x, copysignf(0, y)); | ||
| 78 | 	} | ||
| 79 | |||
| 80 | 	if (ix < 0x7f800000 && iy >= 0x7f800000) | ||
| 81 | 		return CMPLXF(y - y, x * (y - y)); | ||
| 82 | |||
| 83 | 	if (ix >= 0x7f800000 && (hx & 0x7fffff) == 0) { | ||
| 84 | 		if (iy >= 0x7f800000) | ||
| 85 | 			return CMPLXF(x * x, x * (y - y)); | ||
| 86 | 		return CMPLXF(x * cosf(y), INFINITY * sinf(y)); | ||
| 87 | 	} | ||
| 88 | |||
| 89 | 	return CMPLXF((x * x) * (y - y), (x + x) * (y - y)); | ||
| 90 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csinhl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | //FIXME | ||
| 4 | long double complex csinhl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return csinh(z); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csinl.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex csinl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return csin(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex csinl(long double complex z) | ||
| 10 | { | ||
| 11 | 	z = csinhl(CMPLXL(-cimagl(z), creall(z))); | ||
| 12 | 	return CMPLXL(cimagl(z), -creall(z)); | ||
| 13 | } | ||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csqrt.c created+100| ... | @@ -0,0 +1,100 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_csqrt.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2007 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 | #include "complex_impl.h" | ||
| 29 | |||
| 30 | /* | ||
| 31 | * gcc doesn't implement complex multiplication or division correctly, | ||
| 32 | * so we need to handle infinities specially. We turn on this pragma to | ||
| 33 | * notify conforming c99 compilers that the fast-but-incorrect code that | ||
| 34 | * gcc generates is acceptable, since the special cases have already been | ||
| 35 | * handled. | ||
| 36 | */ | ||
| 37 | #pragma STDC CX_LIMITED_RANGE ON | ||
| 38 | |||
| 39 | /* We risk spurious overflow for components >= DBL_MAX / (1 + sqrt(2)). */ | ||
| 40 | #define THRESH 0x1.a827999fcef32p+1022 | ||
| 41 | |||
| 42 | double complex csqrt(double complex z) | ||
| 43 | { | ||
| 44 | 	double complex result; | ||
| 45 | 	double a, b; | ||
| 46 | 	double t; | ||
| 47 | 	int scale; | ||
| 48 | |||
| 49 | 	a = creal(z); | ||
| 50 | 	b = cimag(z); | ||
| 51 | |||
| 52 | 	/* Handle special cases. */ | ||
| 53 | 	if (z == 0) | ||
| 54 | 		return CMPLX(0, b); | ||
| 55 | 	if (isinf(b)) | ||
| 56 | 		return CMPLX(INFINITY, b); | ||
| 57 | 	if (isnan(a)) { | ||
| 58 | 		t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ | ||
| 59 | 		return CMPLX(a, t); /* return NaN + NaN i */ | ||
| 60 | 	} | ||
| 61 | 	if (isinf(a)) { | ||
| 62 | 		/* | ||
| 63 | 		 * csqrt(inf + NaN i) = inf + NaN i | ||
| 64 | 		 * csqrt(inf + y i) = inf + 0 i | ||
| 65 | 		 * csqrt(-inf + NaN i) = NaN +- inf i | ||
| 66 | 		 * csqrt(-inf + y i) = 0 + inf i | ||
| 67 | 		 */ | ||
| 68 | 		if (signbit(a)) | ||
| 69 | 			return CMPLX(fabs(b - b), copysign(a, b)); | ||
| 70 | 		else | ||
| 71 | 			return CMPLX(a, copysign(b - b, b)); | ||
| 72 | 	} | ||
| 73 | 	/* | ||
| 74 | 	 * The remaining special case (b is NaN) is handled just fine by | ||
| 75 | 	 * the normal code path below. | ||
| 76 | 	 */ | ||
| 77 | |||
| 78 | 	/* Scale to avoid overflow. */ | ||
| 79 | 	if (fabs(a) >= THRESH || fabs(b) >= THRESH) { | ||
| 80 | 		a *= 0.25; | ||
| 81 | 		b *= 0.25; | ||
| 82 | 		scale = 1; | ||
| 83 | 	} else { | ||
| 84 | 		scale = 0; | ||
| 85 | 	} | ||
| 86 | |||
| 87 | 	/* Algorithm 312, CACM vol 10, Oct 1967. */ | ||
| 88 | 	if (a >= 0) { | ||
| 89 | 		t = sqrt((a + hypot(a, b)) * 0.5); | ||
| 90 | 		result = CMPLX(t, b / (2 * t)); | ||
| 91 | 	} else { | ||
| 92 | 		t = sqrt((-a + hypot(a, b)) * 0.5); | ||
| 93 | 		result = CMPLX(fabs(b) / (2 * t), copysign(t, b)); | ||
| 94 | 	} | ||
| 95 | |||
| 96 | 	/* Rescale. */ | ||
| 97 | 	if (scale) | ||
| 98 | 		result *= 2; | ||
| 99 | 	return result; | ||
| 100 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csqrtf.c created+82| ... | @@ -0,0 +1,82 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_csqrtf.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2007 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 | #include "complex_impl.h" | ||
| 29 | |||
| 30 | /* | ||
| 31 | * gcc doesn't implement complex multiplication or division correctly, | ||
| 32 | * so we need to handle infinities specially. We turn on this pragma to | ||
| 33 | * notify conforming c99 compilers that the fast-but-incorrect code that | ||
| 34 | * gcc generates is acceptable, since the special cases have already been | ||
| 35 | * handled. | ||
| 36 | */ | ||
| 37 | #pragma STDC CX_LIMITED_RANGE ON | ||
| 38 | |||
| 39 | float complex csqrtf(float complex z) | ||
| 40 | { | ||
| 41 | 	float a = crealf(z), b = cimagf(z); | ||
| 42 | 	double t; | ||
| 43 | |||
| 44 | 	/* Handle special cases. */ | ||
| 45 | 	if (z == 0) | ||
| 46 | 		return CMPLXF(0, b); | ||
| 47 | 	if (isinf(b)) | ||
| 48 | 		return CMPLXF(INFINITY, b); | ||
| 49 | 	if (isnan(a)) { | ||
| 50 | 		t = (b - b) / (b - b); /* raise invalid if b is not a NaN */ | ||
| 51 | 		return CMPLXF(a, t); /* return NaN + NaN i */ | ||
| 52 | 	} | ||
| 53 | 	if (isinf(a)) { | ||
| 54 | 		/* | ||
| 55 | 		 * csqrtf(inf + NaN i) = inf + NaN i | ||
| 56 | 		 * csqrtf(inf + y i) = inf + 0 i | ||
| 57 | 		 * csqrtf(-inf + NaN i) = NaN +- inf i | ||
| 58 | 		 * csqrtf(-inf + y i) = 0 + inf i | ||
| 59 | 		 */ | ||
| 60 | 		if (signbit(a)) | ||
| 61 | 			return CMPLXF(fabsf(b - b), copysignf(a, b)); | ||
| 62 | 		else | ||
| 63 | 			return CMPLXF(a, copysignf(b - b, b)); | ||
| 64 | 	} | ||
| 65 | 	/* | ||
| 66 | 	 * The remaining special case (b is NaN) is handled just fine by | ||
| 67 | 	 * the normal code path below. | ||
| 68 | 	 */ | ||
| 69 | |||
| 70 | 	/* | ||
| 71 | 	 * We compute t in double precision to avoid overflow and to | ||
| 72 | 	 * provide correct rounding in nearly all cases. | ||
| 73 | 	 * This is Algorithm 312, CACM vol 10, Oct 1967. | ||
| 74 | 	 */ | ||
| 75 | 	if (a >= 0) { | ||
| 76 | 		t = sqrt((a + hypot(a, b)) * 0.5); | ||
| 77 | 		return CMPLXF(t, b / (2.0 * t)); | ||
| 78 | 	} else { | ||
| 79 | 		t = sqrt((-a + hypot(a, b)) * 0.5); | ||
| 80 | 		return CMPLXF(fabsf(b) / (2.0 * t), copysignf(t, b)); | ||
| 81 | 	} | ||
| 82 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/csqrtl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | //FIXME | ||
| 4 | long double complex csqrtl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return csqrt(z); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ctan.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | /* tan(z) = -i tanh(i z) */ | ||
| 4 | |||
| 5 | double complex ctan(double complex z) | ||
| 6 | { | ||
| 7 | 	z = ctanh(CMPLX(-cimag(z), creal(z))); | ||
| 8 | 	return CMPLX(cimag(z), -creal(z)); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ctanf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | float complex ctanf(float complex z) | ||
| 4 | { | ||
| 5 | 	z = ctanhf(CMPLXF(-cimagf(z), crealf(z))); | ||
| 6 | 	return CMPLXF(cimagf(z), -crealf(z)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ctanh.c created+129| ... | @@ -0,0 +1,129 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_ctanh.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2011 David Schultz | ||
| 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 unmodified, this list of conditions, and the following | ||
| 11 | * 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 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | /* | ||
| 28 | * Hyperbolic tangent of a complex argument z = x + i y. | ||
| 29 | * | ||
| 30 | * The algorithm is from: | ||
| 31 | * | ||
| 32 | * W. Kahan. Branch Cuts for Complex Elementary Functions or Much | ||
| 33 | * Ado About Nothing's Sign Bit. In The State of the Art in | ||
| 34 | * Numerical Analysis, pp. 165 ff. Iserles and Powell, eds., 1987. | ||
| 35 | * | ||
| 36 | * Method: | ||
| 37 | * | ||
| 38 | * Let t = tan(x) | ||
| 39 | * beta = 1/cos^2(y) | ||
| 40 | * s = sinh(x) | ||
| 41 | * rho = cosh(x) | ||
| 42 | * | ||
| 43 | * We have: | ||
| 44 | * | ||
| 45 | * tanh(z) = sinh(z) / cosh(z) | ||
| 46 | * | ||
| 47 | * sinh(x) cos(y) + i cosh(x) sin(y) | ||
| 48 | * = --------------------------------- | ||
| 49 | * cosh(x) cos(y) + i sinh(x) sin(y) | ||
| 50 | * | ||
| 51 | * cosh(x) sinh(x) / cos^2(y) + i tan(y) | ||
| 52 | * = ------------------------------------- | ||
| 53 | * 1 + sinh^2(x) / cos^2(y) | ||
| 54 | * | ||
| 55 | * beta rho s + i t | ||
| 56 | * = ---------------- | ||
| 57 | * 1 + beta s^2 | ||
| 58 | * | ||
| 59 | * Modifications: | ||
| 60 | * | ||
| 61 | * I omitted the original algorithm's handling of overflow in tan(x) after | ||
| 62 | * verifying with nearpi.c that this can't happen in IEEE single or double | ||
| 63 | * precision. I also handle large x differently. | ||
| 64 | */ | ||
| 65 | |||
| 66 | #include "complex_impl.h" | ||
| 67 | |||
| 68 | double complex ctanh(double complex z) | ||
| 69 | { | ||
| 70 | 	double x, y; | ||
| 71 | 	double t, beta, s, rho, denom; | ||
| 72 | 	uint32_t hx, ix, lx; | ||
| 73 | |||
| 74 | 	x = creal(z); | ||
| 75 | 	y = cimag(z); | ||
| 76 | |||
| 77 | 	EXTRACT_WORDS(hx, lx, x); | ||
| 78 | 	ix = hx & 0x7fffffff; | ||
| 79 | |||
| 80 | 	/* | ||
| 81 | 	 * ctanh(NaN + i 0) = NaN + i 0 | ||
| 82 | 	 * | ||
| 83 | 	 * ctanh(NaN + i y) = NaN + i NaN for y != 0 | ||
| 84 | 	 * | ||
| 85 | 	 * The imaginary part has the sign of x*sin(2*y), but there's no | ||
| 86 | 	 * special effort to get this right. | ||
| 87 | 	 * | ||
| 88 | 	 * ctanh(+-Inf +- i Inf) = +-1 +- 0 | ||
| 89 | 	 * | ||
| 90 | 	 * ctanh(+-Inf + i y) = +-1 + 0 sin(2y) for y finite | ||
| 91 | 	 * | ||
| 92 | 	 * The imaginary part of the sign is unspecified. This special | ||
| 93 | 	 * case is only needed to avoid a spurious invalid exception when | ||
| 94 | 	 * y is infinite. | ||
| 95 | 	 */ | ||
| 96 | 	if (ix >= 0x7ff00000) { | ||
| 97 | 		if ((ix & 0xfffff) | lx) /* x is NaN */ | ||
| 98 | 			return CMPLX(x, (y == 0 ? y : x * y)); | ||
| 99 | 		SET_HIGH_WORD(x, hx - 0x40000000); /* x = copysign(1, x) */ | ||
| 100 | 		return CMPLX(x, copysign(0, isinf(y) ? y : sin(y) * cos(y))); | ||
| 101 | 	} | ||
| 102 | |||
| 103 | 	/* | ||
| 104 | 	 * ctanh(+-0 + i NAN) = +-0 + i NaN | ||
| 105 | 	 * ctanh(+-0 +- i Inf) = +-0 + i NaN | ||
| 106 | 	 * ctanh(x + i NAN) = NaN + i NaN | ||
| 107 | 	 * ctanh(x +- i Inf) = NaN + i NaN | ||
| 108 | 	 */ | ||
| 109 | 	if (!isfinite(y)) | ||
| 110 | 		return CMPLX(x ? y - y : x, y - y); | ||
| 111 | |||
| 112 | 	/* | ||
| 113 | 	 * ctanh(+-huge + i +-y) ~= +-1 +- i 2sin(2y)/exp(2x), using the | ||
| 114 | 	 * approximation sinh^2(huge) ~= exp(2*huge) / 4. | ||
| 115 | 	 * We use a modified formula to avoid spurious overflow. | ||
| 116 | 	 */ | ||
| 117 | 	if (ix >= 0x40360000) { /* x >= 22 */ | ||
| 118 | 		double exp_mx = exp(-fabs(x)); | ||
| 119 | 		return CMPLX(copysign(1, x), 4 * sin(y) * cos(y) * exp_mx * exp_mx); | ||
| 120 | 	} | ||
| 121 | |||
| 122 | 	/* Kahan's algorithm */ | ||
| 123 | 	t = tan(y); | ||
| 124 | 	beta = 1.0 + t * t; /* = 1 / cos^2(y) */ | ||
| 125 | 	s = sinh(x); | ||
| 126 | 	rho = sqrt(1 + s * s); /* = cosh(x) */ | ||
| 127 | 	denom = 1 + beta * s * s; | ||
| 128 | 	return CMPLX((beta * rho * s) / denom, t / denom); | ||
| 129 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ctanhf.c created+66| ... | @@ -0,0 +1,66 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_ctanhf.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2011 David Schultz | ||
| 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 unmodified, this list of conditions, and the following | ||
| 11 | * 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 | * | ||
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | ||
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | ||
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | ||
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
| 26 | */ | ||
| 27 | /* | ||
| 28 | * Hyperbolic tangent of a complex argument z. See s_ctanh.c for details. | ||
| 29 | */ | ||
| 30 | |||
| 31 | #include "complex_impl.h" | ||
| 32 | |||
| 33 | float complex ctanhf(float complex z) | ||
| 34 | { | ||
| 35 | 	float x, y; | ||
| 36 | 	float t, beta, s, rho, denom; | ||
| 37 | 	uint32_t hx, ix; | ||
| 38 | |||
| 39 | 	x = crealf(z); | ||
| 40 | 	y = cimagf(z); | ||
| 41 | |||
| 42 | 	GET_FLOAT_WORD(hx, x); | ||
| 43 | 	ix = hx & 0x7fffffff; | ||
| 44 | |||
| 45 | 	if (ix >= 0x7f800000) { | ||
| 46 | 		if (ix & 0x7fffff) | ||
| 47 | 			return CMPLXF(x, (y == 0 ? y : x * y)); | ||
| 48 | 		SET_FLOAT_WORD(x, hx - 0x40000000); | ||
| 49 | 		return CMPLXF(x, copysignf(0, isinf(y) ? y : sinf(y) * cosf(y))); | ||
| 50 | 	} | ||
| 51 | |||
| 52 | 	if (!isfinite(y)) | ||
| 53 | 		return CMPLXF(ix ? y - y : x, y - y); | ||
| 54 | |||
| 55 | 	if (ix >= 0x41300000) { /* x >= 11 */ | ||
| 56 | 		float exp_mx = expf(-fabsf(x)); | ||
| 57 | 		return CMPLXF(copysignf(1, x), 4 * sinf(y) * cosf(y) * exp_mx * exp_mx); | ||
| 58 | 	} | ||
| 59 | |||
| 60 | 	t = tanf(y); | ||
| 61 | 	beta = 1.0 + t * t; | ||
| 62 | 	s = sinhf(x); | ||
| 63 | 	rho = sqrtf(1 + s * s); | ||
| 64 | 	denom = 1 + beta * s * s; | ||
| 65 | 	return CMPLXF((beta * rho * s) / denom, t / denom); | ||
| 66 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ctanhl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | //FIXME | ||
| 4 | long double complex ctanhl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return ctanh(z); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/complex/ctanl.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "complex_impl.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double complex ctanl(long double complex z) | ||
| 5 | { | ||
| 6 | 	return ctan(z); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | long double complex ctanl(long double complex z) | ||
| 10 | { | ||
| 11 | 	z = ctanhl(CMPLXL(-cimagl(z), creall(z))); | ||
| 12 | 	return CMPLXL(cimagl(z), -creall(z)); | ||
| 13 | } | ||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/conf/confstr.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | size_t confstr(int name, char *buf, size_t len) | ||
| 6 | { | ||
| 7 | 	const char *s = ""; | ||
| 8 | 	if (!name) { | ||
| 9 | 		s = "/bin:/usr/bin"; | ||
| 10 | 	} else if ((name&~4U)!=1 && name-_CS_POSIX_V6_ILP32_OFF32_CFLAGS>33U) { | ||
| 11 | 		errno = EINVAL; | ||
| 12 | 		return 0; | ||
| 13 | 	} | ||
| 14 | 	// snprintf is overkill but avoid wasting code size to implement | ||
| 15 | 	// this completely useless function and its truncation semantics | ||
| 16 | 	return snprintf(buf, len, "%s", s) + 1; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/conf/fpathconf.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 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/legacy.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <sys/sysinfo.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | |||
| 4 | int get_nprocs_conf() | ||
| 5 | { | ||
| 6 | 	return sysconf(_SC_NPROCESSORS_CONF); | ||
| 7 | } | ||
| 8 | |||
| 9 | int get_nprocs() | ||
| 10 | { | ||
| 11 | 	return sysconf(_SC_NPROCESSORS_ONLN); | ||
| 12 | } | ||
| 13 | |||
| 14 | long get_phys_pages() | ||
| 15 | { | ||
| 16 | 	return sysconf(_SC_PHYS_PAGES);	 | ||
| 17 | } | ||
| 18 | |||
| 19 | long get_avphys_pages() | ||
| 20 | { | ||
| 21 | 	return sysconf(_SC_AVPHYS_PAGES);	 | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/conf/pathconf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | long pathconf(const char *path, int name) | ||
| 4 | { | ||
| 5 | 	return fpathconf(-1, name); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/conf/sysconf.c created+282| ... | @@ -0,0 +1,282 @@ | ||
| 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 "syscall.h" | ||
| 13 | #endif | ||
| 14 | #include "libc.h" | ||
| 15 | |||
| 16 | #define JT(x) (-256|(x)) | ||
| 17 | #define VER JT(1) | ||
| 18 | #define JT_ARG_MAX JT(2) | ||
| 19 | #ifdef __wasilibc_unmodified_upstream // WASI has no mq | ||
| 20 | #define JT_MQ_PRIO_MAX JT(3) | ||
| 21 | #endif | ||
| 22 | #define JT_PAGE_SIZE JT(4) | ||
| 23 | #ifdef __wasilibc_unmodified_upstream // WASI has no semaphores | ||
| 24 | #define JT_SEM_VALUE_MAX JT(5) | ||
| 25 | #endif | ||
| 26 | #define JT_NPROCESSORS_CONF JT(6) | ||
| 27 | #define JT_NPROCESSORS_ONLN JT(7) | ||
| 28 | #define JT_PHYS_PAGES JT(8) | ||
| 29 | #define JT_AVPHYS_PAGES JT(9) | ||
| 30 | #define JT_ZERO JT(10) | ||
| 31 | #define JT_DELAYTIMER_MAX JT(11) | ||
| 32 | |||
| 33 | #define RLIM(x) (-32768|(RLIMIT_ ## x)) | ||
| 34 | |||
| 35 | long sysconf(int name) | ||
| 36 | { | ||
| 37 | 	static const short values[] = { | ||
| 38 | 		[_SC_ARG_MAX] = JT_ARG_MAX, | ||
| 39 | #ifdef __wasilibc_unmodified_upstream // WASI has no processes | ||
| 40 | 		[_SC_CHILD_MAX] = RLIM(NPROC), | ||
| 41 | #else | ||
| 42 | 		// Not supported on wasi. | ||
| 43 | 		[_SC_CHILD_MAX] = -1, | ||
| 44 | #endif | ||
| 45 | 		[_SC_CLK_TCK] = 100, | ||
| 46 | 		[_SC_NGROUPS_MAX] = 32, | ||
| 47 | #ifdef __wasilibc_unmodified_upstream // WASI has no rlimit | ||
| 48 | 		[_SC_OPEN_MAX] = RLIM(NOFILE), | ||
| 49 | #else | ||
| 50 | 		// Rlimit is not supported on wasi. | ||
| 51 | 		[_SC_OPEN_MAX] = -1, | ||
| 52 | #endif | ||
| 53 | |||
| 54 | 		[_SC_STREAM_MAX] = -1, | ||
| 55 | 		[_SC_TZNAME_MAX] = TZNAME_MAX, | ||
| 56 | 		[_SC_JOB_CONTROL] = 1, | ||
| 57 | 		[_SC_SAVED_IDS] = 1, | ||
| 58 | 		[_SC_REALTIME_SIGNALS] = VER, | ||
| 59 | 		[_SC_PRIORITY_SCHEDULING] = -1, | ||
| 60 | 		[_SC_TIMERS] = VER, | ||
| 61 | 		[_SC_ASYNCHRONOUS_IO] = VER, | ||
| 62 | 		[_SC_PRIORITIZED_IO] = -1, | ||
| 63 | 		[_SC_SYNCHRONIZED_IO] = -1, | ||
| 64 | 		[_SC_FSYNC] = VER, | ||
| 65 | 		[_SC_MAPPED_FILES] = VER, | ||
| 66 | 		[_SC_MEMLOCK] = VER, | ||
| 67 | 		[_SC_MEMLOCK_RANGE] = VER, | ||
| 68 | 		[_SC_MEMORY_PROTECTION] = VER, | ||
| 69 | 		[_SC_MESSAGE_PASSING] = VER, | ||
| 70 | 		[_SC_SEMAPHORES] = VER, | ||
| 71 | 		[_SC_SHARED_MEMORY_OBJECTS] = VER, | ||
| 72 | 		[_SC_AIO_LISTIO_MAX] = -1, | ||
| 73 | 		[_SC_AIO_MAX] = -1, | ||
| 74 | 		[_SC_AIO_PRIO_DELTA_MAX] = JT_ZERO, /* ?? */ | ||
| 75 | 		[_SC_DELAYTIMER_MAX] = JT_DELAYTIMER_MAX, | ||
| 76 | #ifdef __wasilibc_unmodified_upstream // WASI has no mq | ||
| 77 | 		[_SC_MQ_OPEN_MAX] = -1, | ||
| 78 | 		[_SC_MQ_PRIO_MAX] = JT_MQ_PRIO_MAX, | ||
| 79 | #endif | ||
| 80 | 		[_SC_VERSION] = VER, | ||
| 81 | 		[_SC_PAGE_SIZE] = JT_PAGE_SIZE, | ||
| 82 | #ifdef __wasilibc_unmodified_upstream // WASI has no realtime signals | ||
| 83 | 		[_SC_RTSIG_MAX] = _NSIG - 1 - 31 - 3, | ||
| 84 | #else | ||
| 85 | 		// Not supported on wasi. | ||
| 86 | 		[_SC_RTSIG_MAX] = -1, | ||
| 87 | #endif | ||
| 88 | #ifdef __wasilibc_unmodified_upstream // WASI has no semaphores | ||
| 89 | 		[_SC_SEM_NSEMS_MAX] = SEM_NSEMS_MAX, | ||
| 90 | 		[_SC_SEM_VALUE_MAX] = JT_SEM_VALUE_MAX, | ||
| 91 | #else | ||
| 92 | 		[_SC_SEM_NSEMS_MAX] = -1, | ||
| 93 | 		[_SC_SEM_VALUE_MAX] = -1, | ||
| 94 | #endif | ||
| 95 | 		[_SC_SIGQUEUE_MAX] = -1, | ||
| 96 | 		[_SC_TIMER_MAX] = -1, | ||
| 97 | #ifdef __wasilibc_unmodified_upstream // WASI has no shell commands | ||
| 98 | 		[_SC_BC_BASE_MAX] = _POSIX2_BC_BASE_MAX, | ||
| 99 | 		[_SC_BC_DIM_MAX] = _POSIX2_BC_DIM_MAX, | ||
| 100 | 		[_SC_BC_SCALE_MAX] = _POSIX2_BC_SCALE_MAX, | ||
| 101 | 		[_SC_BC_STRING_MAX] = _POSIX2_BC_STRING_MAX, | ||
| 102 | #else | ||
| 103 | 		[_SC_BC_BASE_MAX] = -1, | ||
| 104 | 		[_SC_BC_DIM_MAX] = -1, | ||
| 105 | 		[_SC_BC_SCALE_MAX] = -1, | ||
| 106 | 		[_SC_BC_STRING_MAX] = -1, | ||
| 107 | #endif | ||
| 108 | 		[_SC_COLL_WEIGHTS_MAX] = COLL_WEIGHTS_MAX, | ||
| 109 | 		[_SC_EXPR_NEST_MAX] = -1, | ||
| 110 | 		[_SC_LINE_MAX] = -1, | ||
| 111 | 		[_SC_RE_DUP_MAX] = RE_DUP_MAX, | ||
| 112 | 		[_SC_2_VERSION] = VER, | ||
| 113 | 		[_SC_2_C_BIND] = VER, | ||
| 114 | 		[_SC_2_C_DEV] = -1, | ||
| 115 | 		[_SC_2_FORT_DEV] = -1, | ||
| 116 | 		[_SC_2_FORT_RUN] = -1, | ||
| 117 | 		[_SC_2_SW_DEV] = -1, | ||
| 118 | 		[_SC_2_LOCALEDEF] = -1, | ||
| 119 | 		[_SC_IOV_MAX] = IOV_MAX, | ||
| 120 | 		[_SC_THREADS] = VER, | ||
| 121 | 		[_SC_THREAD_SAFE_FUNCTIONS] = VER, | ||
| 122 | 		[_SC_GETGR_R_SIZE_MAX] = -1, | ||
| 123 | 		[_SC_GETPW_R_SIZE_MAX] = -1, | ||
| 124 | 		[_SC_LOGIN_NAME_MAX] = 256, | ||
| 125 | 		[_SC_TTY_NAME_MAX] = TTY_NAME_MAX, | ||
| 126 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 127 | 		[_SC_THREAD_DESTRUCTOR_ITERATIONS] = PTHREAD_DESTRUCTOR_ITERATIONS, | ||
| 128 | 		[_SC_THREAD_KEYS_MAX] = PTHREAD_KEYS_MAX, | ||
| 129 | 		[_SC_THREAD_STACK_MIN] = PTHREAD_STACK_MIN, | ||
| 130 | #else | ||
| 131 | 		[_SC_THREAD_DESTRUCTOR_ITERATIONS] = -1, | ||
| 132 | 		[_SC_THREAD_KEYS_MAX] = -1, | ||
| 133 | 		[_SC_THREAD_STACK_MIN] = -1, | ||
| 134 | #endif | ||
| 135 | 		[_SC_THREAD_THREADS_MAX] = -1, | ||
| 136 | 		[_SC_THREAD_ATTR_STACKADDR] = VER, | ||
| 137 | 		[_SC_THREAD_ATTR_STACKSIZE] = VER, | ||
| 138 | 		[_SC_THREAD_PRIORITY_SCHEDULING] = VER, | ||
| 139 | 		[_SC_THREAD_PRIO_INHERIT] = -1, | ||
| 140 | 		[_SC_THREAD_PRIO_PROTECT] = -1, | ||
| 141 | 		[_SC_THREAD_PROCESS_SHARED] = VER, | ||
| 142 | 		[_SC_NPROCESSORS_CONF] = JT_NPROCESSORS_CONF, | ||
| 143 | 		[_SC_NPROCESSORS_ONLN] = JT_NPROCESSORS_ONLN, | ||
| 144 | 		[_SC_PHYS_PAGES] = JT_PHYS_PAGES, | ||
| 145 | 		[_SC_AVPHYS_PAGES] = JT_AVPHYS_PAGES, | ||
| 146 | 		[_SC_ATEXIT_MAX] = -1, | ||
| 147 | 		[_SC_PASS_MAX] = -1, | ||
| 148 | 		[_SC_XOPEN_VERSION] = _XOPEN_VERSION, | ||
| 149 | 		[_SC_XOPEN_XCU_VERSION] = _XOPEN_VERSION, | ||
| 150 | 		[_SC_XOPEN_UNIX] = 1, | ||
| 151 | 		[_SC_XOPEN_CRYPT] = -1, | ||
| 152 | 		[_SC_XOPEN_ENH_I18N] = 1, | ||
| 153 | 		[_SC_XOPEN_SHM] = 1, | ||
| 154 | 		[_SC_2_CHAR_TERM] = -1, | ||
| 155 | 		[_SC_2_UPE] = -1, | ||
| 156 | 		[_SC_XOPEN_XPG2] = -1, | ||
| 157 | 		[_SC_XOPEN_XPG3] = -1, | ||
| 158 | 		[_SC_XOPEN_XPG4] = -1, | ||
| 159 | 		[_SC_NZERO] = NZERO, | ||
| 160 | 		[_SC_XBS5_ILP32_OFF32] = -1, | ||
| 161 | 		[_SC_XBS5_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, | ||
| 162 | 		[_SC_XBS5_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, | ||
| 163 | 		[_SC_XBS5_LPBIG_OFFBIG] = -1, | ||
| 164 | 		[_SC_XOPEN_LEGACY] = -1, | ||
| 165 | 		[_SC_XOPEN_REALTIME] = -1, | ||
| 166 | 		[_SC_XOPEN_REALTIME_THREADS] = -1, | ||
| 167 | 		[_SC_ADVISORY_INFO] = VER, | ||
| 168 | 		[_SC_BARRIERS] = VER, | ||
| 169 | 		[_SC_CLOCK_SELECTION] = VER, | ||
| 170 | 		[_SC_CPUTIME] = VER, | ||
| 171 | 		[_SC_THREAD_CPUTIME] = VER, | ||
| 172 | 		[_SC_MONOTONIC_CLOCK] = VER, | ||
| 173 | 		[_SC_READER_WRITER_LOCKS] = VER, | ||
| 174 | 		[_SC_SPIN_LOCKS] = VER, | ||
| 175 | 		[_SC_REGEXP] = 1, | ||
| 176 | 		[_SC_SHELL] = 1, | ||
| 177 | 		[_SC_SPAWN] = VER, | ||
| 178 | 		[_SC_SPORADIC_SERVER] = -1, | ||
| 179 | 		[_SC_THREAD_SPORADIC_SERVER] = -1, | ||
| 180 | 		[_SC_TIMEOUTS] = VER, | ||
| 181 | 		[_SC_TYPED_MEMORY_OBJECTS] = -1, | ||
| 182 | 		[_SC_2_PBS] = -1, | ||
| 183 | 		[_SC_2_PBS_ACCOUNTING] = -1, | ||
| 184 | 		[_SC_2_PBS_LOCATE] = -1, | ||
| 185 | 		[_SC_2_PBS_MESSAGE] = -1, | ||
| 186 | 		[_SC_2_PBS_TRACK] = -1, | ||
| 187 | 		[_SC_SYMLOOP_MAX] = SYMLOOP_MAX, | ||
| 188 | 		[_SC_STREAMS] = JT_ZERO, | ||
| 189 | 		[_SC_2_PBS_CHECKPOINT] = -1, | ||
| 190 | 		[_SC_V6_ILP32_OFF32] = -1, | ||
| 191 | 		[_SC_V6_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, | ||
| 192 | 		[_SC_V6_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, | ||
| 193 | 		[_SC_V6_LPBIG_OFFBIG] = -1, | ||
| 194 | 		[_SC_HOST_NAME_MAX] = HOST_NAME_MAX, | ||
| 195 | 		[_SC_TRACE] = -1, | ||
| 196 | 		[_SC_TRACE_EVENT_FILTER] = -1, | ||
| 197 | 		[_SC_TRACE_INHERIT] = -1, | ||
| 198 | 		[_SC_TRACE_LOG] = -1, | ||
| 199 | |||
| 200 | 		[_SC_IPV6] = VER, | ||
| 201 | 		[_SC_RAW_SOCKETS] = VER, | ||
| 202 | 		[_SC_V7_ILP32_OFF32] = -1, | ||
| 203 | 		[_SC_V7_ILP32_OFFBIG] = sizeof(long)==4 ? 1 : -1, | ||
| 204 | 		[_SC_V7_LP64_OFF64] = sizeof(long)==8 ? 1 : -1, | ||
| 205 | 		[_SC_V7_LPBIG_OFFBIG] = -1, | ||
| 206 | 		[_SC_SS_REPL_MAX] = -1, | ||
| 207 | 		[_SC_TRACE_EVENT_NAME_MAX] = -1, | ||
| 208 | 		[_SC_TRACE_NAME_MAX] = -1, | ||
| 209 | 		[_SC_TRACE_SYS_MAX] = -1, | ||
| 210 | 		[_SC_TRACE_USER_EVENT_MAX] = -1, | ||
| 211 | 		[_SC_XOPEN_STREAMS] = JT_ZERO, | ||
| 212 | 		[_SC_THREAD_ROBUST_PRIO_INHERIT] = -1, | ||
| 213 | 		[_SC_THREAD_ROBUST_PRIO_PROTECT] = -1, | ||
| 214 | 	}; | ||
| 215 | |||
| 216 | 	if (name >= sizeof(values)/sizeof(values[0]) || !values[name]) { | ||
| 217 | 		errno = EINVAL; | ||
| 218 | 		return -1; | ||
| 219 | 	} else if (values[name] >= -1) { | ||
| 220 | 		return values[name]; | ||
| 221 | 	} else if (values[name] < -256) { | ||
| 222 | #ifdef __wasilibc_unmodified_upstream // WASI has no getrlimit | ||
| 223 | 		struct rlimit lim; | ||
| 224 | 		getrlimit(values[name]&16383, &lim); | ||
| 225 | 		if (lim.rlim_cur == RLIM_INFINITY) | ||
| 226 | 			return -1; | ||
| 227 | 		return lim.rlim_cur > LONG_MAX ? LONG_MAX : lim.rlim_cur; | ||
| 228 | #else | ||
| 229 | 		// Not supported on wasi. | ||
| 230 | 		errno = EINVAL; | ||
| 231 | 		return -1; | ||
| 232 | #endif | ||
| 233 | 	} | ||
| 234 | |||
| 235 | 	switch ((unsigned char)values[name]) { | ||
| 236 | 	case VER & 255: | ||
| 237 | 		return _POSIX_VERSION; | ||
| 238 | 	case JT_ARG_MAX & 255: | ||
| 239 | 		return ARG_MAX; | ||
| 240 | #ifdef __wasilibc_unmodified_upstream // WASI has no mq | ||
| 241 | 	case JT_MQ_PRIO_MAX & 255: | ||
| 242 | 		return MQ_PRIO_MAX; | ||
| 243 | #endif | ||
| 244 | 	case JT_PAGE_SIZE & 255: | ||
| 245 | 		return PAGE_SIZE; | ||
| 246 | #ifdef __wasilibc_unmodified_upstream // WASI has no semaphores | ||
| 247 | 	case JT_SEM_VALUE_MAX & 255: | ||
| 248 | 		return SEM_VALUE_MAX; | ||
| 249 | #endif | ||
| 250 | 	case JT_DELAYTIMER_MAX & 255: | ||
| 251 | 		return DELAYTIMER_MAX; | ||
| 252 | 	case JT_NPROCESSORS_CONF & 255: | ||
| 253 | 	case JT_NPROCESSORS_ONLN & 255: ; | ||
| 254 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 255 | 		unsigned char set[128] = {1}; | ||
| 256 | 		int i, cnt; | ||
| 257 | 		__syscall(SYS_sched_getaffinity, 0, sizeof set, set); | ||
| 258 | 		for (i=cnt=0; i<sizeof set; i++) | ||
| 259 | 			for (; set[i]; set[i]&=set[i]-1, cnt++); | ||
| 260 | 		return cnt; | ||
| 261 | #else | ||
| 262 | 		// With no thread support, just say there's 1 processor. | ||
| 263 | 		return 1; | ||
| 264 | #endif | ||
| 265 | #ifdef __wasilibc_unmodified_upstream // WASI has no sysinfo | ||
| 266 | 	case JT_PHYS_PAGES & 255: | ||
| 267 | 	case JT_AVPHYS_PAGES & 255: ; | ||
| 268 | 		unsigned long long mem; | ||
| 269 | 		struct sysinfo si; | ||
| 270 | 		__lsysinfo(&si); | ||
| 271 | 		if (!si.mem_unit) si.mem_unit = 1; | ||
| 272 | 		if (name==_SC_PHYS_PAGES) mem = si.totalram; | ||
| 273 | 		else mem = si.freeram + si.bufferram; | ||
| 274 | 		mem *= si.mem_unit; | ||
| 275 | 		mem /= PAGE_SIZE; | ||
| 276 | 		return (mem > LONG_MAX) ? LONG_MAX : mem; | ||
| 277 | #endif | ||
| 278 | 	case JT_ZERO & 255: | ||
| 279 | 		return 0; | ||
| 280 | 	} | ||
| 281 | 	return values[name]; | ||
| 282 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <crypt.h> | ||
| 3 | |||
| 4 | char *crypt(const char *key, const char *salt) | ||
| 5 | { | ||
| 6 | 	/* This buffer is sufficiently large for all | ||
| 7 | 	 * currently-supported hash types. It needs to be updated if | ||
| 8 | 	 * longer hashes are added. The cast to struct crypt_data * is | ||
| 9 | 	 * purely to meet the public API requirements of the crypt_r | ||
| 10 | 	 * function; the implementation of crypt_r uses the object | ||
| 11 | 	 * purely as a char buffer. */ | ||
| 12 | 	static char buf[128]; | ||
| 13 | 	return __crypt_r(key, salt, (struct crypt_data *)buf); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_blowfish.c created+806| ... | @@ -0,0 +1,806 @@ | ||
| 1 | /* Modified by Rich Felker in for inclusion in musl libc, based on | ||
| 2 | * Solar Designer's second size-optimized version sent to the musl | ||
| 3 | * mailing list. */ | ||
| 4 | |||
| 5 | /* | ||
| 6 | * The crypt_blowfish homepage is: | ||
| 7 | * | ||
| 8 | *	http://www.openwall.com/crypt/ | ||
| 9 | * | ||
| 10 | * This code comes from John the Ripper password cracker, with reentrant | ||
| 11 | * and crypt(3) interfaces added, but optimizations specific to password | ||
| 12 | * cracking removed. | ||
| 13 | * | ||
| 14 | * Written by Solar Designer <solar at openwall.com> in 1998-2012. | ||
| 15 | * No copyright is claimed, and the software is hereby placed in the public | ||
| 16 | * domain. In case this attempt to disclaim copyright and place the software | ||
| 17 | * in the public domain is deemed null and void, then the software is | ||
| 18 | * Copyright (c) 1998-2014 Solar Designer and it is hereby released to the | ||
| 19 | * general public under the following terms: | ||
| 20 | * | ||
| 21 | * Redistribution and use in source and binary forms, with or without | ||
| 22 | * modification, are permitted. | ||
| 23 | * | ||
| 24 | * There's ABSOLUTELY NO WARRANTY, express or implied. | ||
| 25 | * | ||
| 26 | * It is my intent that you should be able to use this on your system, | ||
| 27 | * as part of a software package, or anywhere else to improve security, | ||
| 28 | * ensure compatibility, or for any other purpose. I would appreciate | ||
| 29 | * it if you give credit where it is due and keep your modifications in | ||
| 30 | * the public domain as well, but I don't require that in order to let | ||
| 31 | * you place this code and any modifications you make under a license | ||
| 32 | * of your choice. | ||
| 33 | * | ||
| 34 | * This implementation is fully compatible with OpenBSD's bcrypt.c for prefix | ||
| 35 | * "$2b$", originally by Niels Provos <provos at citi.umich.edu>, and it uses | ||
| 36 | * some of his ideas. The password hashing algorithm was designed by David | ||
| 37 | * Mazieres <dm at lcs.mit.edu>. For information on the level of | ||
| 38 | * compatibility for bcrypt hash prefixes other than "$2b$", please refer to | ||
| 39 | * the comments in BF_set_key() below and to the included crypt(3) man page. | ||
| 40 | * | ||
| 41 | * There's a paper on the algorithm that explains its design decisions: | ||
| 42 | * | ||
| 43 | *	http://www.usenix.org/events/usenix99/provos.html | ||
| 44 | * | ||
| 45 | * Some of the tricks in BF_ROUND might be inspired by Eric Young's | ||
| 46 | * Blowfish library (I can't be sure if I would think of something if I | ||
| 47 | * hadn't seen his code). | ||
| 48 | */ | ||
| 49 | |||
| 50 | #include <string.h> | ||
| 51 | #include <stdint.h> | ||
| 52 | |||
| 53 | typedef uint32_t BF_word; | ||
| 54 | typedef int32_t BF_word_signed; | ||
| 55 | |||
| 56 | /* Number of Blowfish rounds, this is also hardcoded into a few places */ | ||
| 57 | #define BF_N				16 | ||
| 58 | |||
| 59 | typedef BF_word BF_key[BF_N + 2]; | ||
| 60 | |||
| 61 | typedef union { | ||
| 62 | 	struct { | ||
| 63 | 		BF_key P; | ||
| 64 | 		BF_word S[4][0x100]; | ||
| 65 | 	} s; | ||
| 66 | 	BF_word PS[BF_N + 2 + 4 * 0x100]; | ||
| 67 | } BF_ctx; | ||
| 68 | |||
| 69 | /* | ||
| 70 | * Magic IV for 64 Blowfish encryptions that we do at the end. | ||
| 71 | * The string is "OrpheanBeholderScryDoubt" on big-endian. | ||
| 72 | */ | ||
| 73 | static const BF_word BF_magic_w[6] = { | ||
| 74 | 	0x4F727068, 0x65616E42, 0x65686F6C, | ||
| 75 | 	0x64657253, 0x63727944, 0x6F756274 | ||
| 76 | }; | ||
| 77 | |||
| 78 | /* | ||
| 79 | * P-box and S-box tables initialized with digits of Pi. | ||
| 80 | */ | ||
| 81 | static const BF_ctx BF_init_state = {{ | ||
| 82 | 	{ | ||
| 83 | 		0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344, | ||
| 84 | 		0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89, | ||
| 85 | 		0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c, | ||
| 86 | 		0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917, | ||
| 87 | 		0x9216d5d9, 0x8979fb1b | ||
| 88 | 	}, { | ||
| 89 | 		{ | ||
| 90 | 			0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7, | ||
| 91 | 			0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99, | ||
| 92 | 			0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16, | ||
| 93 | 			0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e, | ||
| 94 | 			0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee, | ||
| 95 | 			0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013, | ||
| 96 | 			0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef, | ||
| 97 | 			0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e, | ||
| 98 | 			0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60, | ||
| 99 | 			0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440, | ||
| 100 | 			0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce, | ||
| 101 | 			0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a, | ||
| 102 | 			0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e, | ||
| 103 | 			0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677, | ||
| 104 | 			0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193, | ||
| 105 | 			0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032, | ||
| 106 | 			0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88, | ||
| 107 | 			0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239, | ||
| 108 | 			0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e, | ||
| 109 | 			0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0, | ||
| 110 | 			0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3, | ||
| 111 | 			0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98, | ||
| 112 | 			0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88, | ||
| 113 | 			0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe, | ||
| 114 | 			0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6, | ||
| 115 | 			0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d, | ||
| 116 | 			0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b, | ||
| 117 | 			0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7, | ||
| 118 | 			0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba, | ||
| 119 | 			0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463, | ||
| 120 | 			0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f, | ||
| 121 | 			0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09, | ||
| 122 | 			0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3, | ||
| 123 | 			0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb, | ||
| 124 | 			0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279, | ||
| 125 | 			0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8, | ||
| 126 | 			0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab, | ||
| 127 | 			0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82, | ||
| 128 | 			0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db, | ||
| 129 | 			0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573, | ||
| 130 | 			0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0, | ||
| 131 | 			0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b, | ||
| 132 | 			0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790, | ||
| 133 | 			0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8, | ||
| 134 | 			0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4, | ||
| 135 | 			0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0, | ||
| 136 | 			0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7, | ||
| 137 | 			0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c, | ||
| 138 | 			0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad, | ||
| 139 | 			0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1, | ||
| 140 | 			0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299, | ||
| 141 | 			0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9, | ||
| 142 | 			0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477, | ||
| 143 | 			0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf, | ||
| 144 | 			0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49, | ||
| 145 | 			0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af, | ||
| 146 | 			0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa, | ||
| 147 | 			0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5, | ||
| 148 | 			0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41, | ||
| 149 | 			0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915, | ||
| 150 | 			0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400, | ||
| 151 | 			0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915, | ||
| 152 | 			0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664, | ||
| 153 | 			0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a | ||
| 154 | 		}, { | ||
| 155 | 			0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623, | ||
| 156 | 			0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266, | ||
| 157 | 			0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1, | ||
| 158 | 			0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e, | ||
| 159 | 			0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6, | ||
| 160 | 			0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1, | ||
| 161 | 			0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e, | ||
| 162 | 			0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1, | ||
| 163 | 			0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737, | ||
| 164 | 			0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8, | ||
| 165 | 			0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff, | ||
| 166 | 			0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd, | ||
| 167 | 			0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701, | ||
| 168 | 			0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7, | ||
| 169 | 			0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41, | ||
| 170 | 			0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331, | ||
| 171 | 			0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf, | ||
| 172 | 			0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af, | ||
| 173 | 			0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e, | ||
| 174 | 			0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87, | ||
| 175 | 			0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c, | ||
| 176 | 			0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2, | ||
| 177 | 			0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16, | ||
| 178 | 			0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd, | ||
| 179 | 			0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b, | ||
| 180 | 			0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509, | ||
| 181 | 			0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e, | ||
| 182 | 			0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3, | ||
| 183 | 			0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f, | ||
| 184 | 			0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a, | ||
| 185 | 			0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4, | ||
| 186 | 			0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960, | ||
| 187 | 			0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66, | ||
| 188 | 			0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28, | ||
| 189 | 			0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802, | ||
| 190 | 			0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84, | ||
| 191 | 			0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510, | ||
| 192 | 			0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf, | ||
| 193 | 			0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14, | ||
| 194 | 			0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e, | ||
| 195 | 			0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50, | ||
| 196 | 			0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7, | ||
| 197 | 			0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8, | ||
| 198 | 			0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281, | ||
| 199 | 			0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99, | ||
| 200 | 			0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696, | ||
| 201 | 			0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128, | ||
| 202 | 			0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73, | ||
| 203 | 			0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0, | ||
| 204 | 			0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0, | ||
| 205 | 			0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105, | ||
| 206 | 			0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250, | ||
| 207 | 			0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3, | ||
| 208 | 			0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285, | ||
| 209 | 			0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00, | ||
| 210 | 			0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061, | ||
| 211 | 			0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb, | ||
| 212 | 			0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e, | ||
| 213 | 			0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735, | ||
| 214 | 			0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc, | ||
| 215 | 			0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9, | ||
| 216 | 			0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340, | ||
| 217 | 			0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20, | ||
| 218 | 			0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7 | ||
| 219 | 		}, { | ||
| 220 | 			0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934, | ||
| 221 | 			0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068, | ||
| 222 | 			0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af, | ||
| 223 | 			0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840, | ||
| 224 | 			0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45, | ||
| 225 | 			0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504, | ||
| 226 | 			0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a, | ||
| 227 | 			0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb, | ||
| 228 | 			0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee, | ||
| 229 | 			0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6, | ||
| 230 | 			0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42, | ||
| 231 | 			0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b, | ||
| 232 | 			0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2, | ||
| 233 | 			0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb, | ||
| 234 | 			0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527, | ||
| 235 | 			0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b, | ||
| 236 | 			0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33, | ||
| 237 | 			0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c, | ||
| 238 | 			0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3, | ||
| 239 | 			0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc, | ||
| 240 | 			0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17, | ||
| 241 | 			0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564, | ||
| 242 | 			0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b, | ||
| 243 | 			0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115, | ||
| 244 | 			0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922, | ||
| 245 | 			0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728, | ||
| 246 | 			0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0, | ||
| 247 | 			0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e, | ||
| 248 | 			0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37, | ||
| 249 | 			0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d, | ||
| 250 | 			0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804, | ||
| 251 | 			0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b, | ||
| 252 | 			0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3, | ||
| 253 | 			0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb, | ||
| 254 | 			0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d, | ||
| 255 | 			0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c, | ||
| 256 | 			0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350, | ||
| 257 | 			0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9, | ||
| 258 | 			0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a, | ||
| 259 | 			0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe, | ||
| 260 | 			0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d, | ||
| 261 | 			0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc, | ||
| 262 | 			0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f, | ||
| 263 | 			0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61, | ||
| 264 | 			0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2, | ||
| 265 | 			0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9, | ||
| 266 | 			0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2, | ||
| 267 | 			0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c, | ||
| 268 | 			0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e, | ||
| 269 | 			0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633, | ||
| 270 | 			0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10, | ||
| 271 | 			0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169, | ||
| 272 | 			0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52, | ||
| 273 | 			0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027, | ||
| 274 | 			0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5, | ||
| 275 | 			0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62, | ||
| 276 | 			0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634, | ||
| 277 | 			0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76, | ||
| 278 | 			0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24, | ||
| 279 | 			0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc, | ||
| 280 | 			0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4, | ||
| 281 | 			0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c, | ||
| 282 | 			0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837, | ||
| 283 | 			0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0 | ||
| 284 | 		}, { | ||
| 285 | 			0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b, | ||
| 286 | 			0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe, | ||
| 287 | 			0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b, | ||
| 288 | 			0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4, | ||
| 289 | 			0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8, | ||
| 290 | 			0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6, | ||
| 291 | 			0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304, | ||
| 292 | 			0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22, | ||
| 293 | 			0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4, | ||
| 294 | 			0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6, | ||
| 295 | 			0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9, | ||
| 296 | 			0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59, | ||
| 297 | 			0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593, | ||
| 298 | 			0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51, | ||
| 299 | 			0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28, | ||
| 300 | 			0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c, | ||
| 301 | 			0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b, | ||
| 302 | 			0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28, | ||
| 303 | 			0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c, | ||
| 304 | 			0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd, | ||
| 305 | 			0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a, | ||
| 306 | 			0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319, | ||
| 307 | 			0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb, | ||
| 308 | 			0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f, | ||
| 309 | 			0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991, | ||
| 310 | 			0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32, | ||
| 311 | 			0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680, | ||
| 312 | 			0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166, | ||
| 313 | 			0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae, | ||
| 314 | 			0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb, | ||
| 315 | 			0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5, | ||
| 316 | 			0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47, | ||
| 317 | 			0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370, | ||
| 318 | 			0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d, | ||
| 319 | 			0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84, | ||
| 320 | 			0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048, | ||
| 321 | 			0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8, | ||
| 322 | 			0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd, | ||
| 323 | 			0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9, | ||
| 324 | 			0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7, | ||
| 325 | 			0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38, | ||
| 326 | 			0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f, | ||
| 327 | 			0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c, | ||
| 328 | 			0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525, | ||
| 329 | 			0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1, | ||
| 330 | 			0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442, | ||
| 331 | 			0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964, | ||
| 332 | 			0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e, | ||
| 333 | 			0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8, | ||
| 334 | 			0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d, | ||
| 335 | 			0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f, | ||
| 336 | 			0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299, | ||
| 337 | 			0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02, | ||
| 338 | 			0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc, | ||
| 339 | 			0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614, | ||
| 340 | 			0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a, | ||
| 341 | 			0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6, | ||
| 342 | 			0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b, | ||
| 343 | 			0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0, | ||
| 344 | 			0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060, | ||
| 345 | 			0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e, | ||
| 346 | 			0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9, | ||
| 347 | 			0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f, | ||
| 348 | 			0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6 | ||
| 349 | 		} | ||
| 350 | 	} | ||
| 351 | }}; | ||
| 352 | |||
| 353 | static const unsigned char BF_itoa64[64 + 1] = | ||
| 354 | 	"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | ||
| 355 | |||
| 356 | static const unsigned char BF_atoi64[0x60] = { | ||
| 357 | 	64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0, 1, | ||
| 358 | 	54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 64, 64, 64, 64, 64, | ||
| 359 | 	64, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, | ||
| 360 | 	17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 64, 64, 64, 64, 64, | ||
| 361 | 	64, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, | ||
| 362 | 	43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 64, 64, 64, 64, 64 | ||
| 363 | }; | ||
| 364 | |||
| 365 | #define BF_safe_atoi64(dst, src) \ | ||
| 366 | { \ | ||
| 367 | 	tmp = (unsigned char)(src); \ | ||
| 368 | 	if ((unsigned int)(tmp -= 0x20) >= 0x60) return -1; \ | ||
| 369 | 	tmp = BF_atoi64[tmp]; \ | ||
| 370 | 	if (tmp > 63) return -1; \ | ||
| 371 | 	(dst) = tmp; \ | ||
| 372 | } | ||
| 373 | |||
| 374 | static int BF_decode(BF_word *dst, const char *src, int size) | ||
| 375 | { | ||
| 376 | 	unsigned char *dptr = (unsigned char *)dst; | ||
| 377 | 	unsigned char *end = dptr + size; | ||
| 378 | 	const unsigned char *sptr = (const unsigned char *)src; | ||
| 379 | 	unsigned int tmp, c1, c2, c3, c4; | ||
| 380 | |||
| 381 | 	do { | ||
| 382 | 		BF_safe_atoi64(c1, *sptr++); | ||
| 383 | 		BF_safe_atoi64(c2, *sptr++); | ||
| 384 | 		*dptr++ = (c1 << 2) | ((c2 & 0x30) >> 4); | ||
| 385 | 		if (dptr >= end) break; | ||
| 386 | |||
| 387 | 		BF_safe_atoi64(c3, *sptr++); | ||
| 388 | 		*dptr++ = ((c2 & 0x0F) << 4) | ((c3 & 0x3C) >> 2); | ||
| 389 | 		if (dptr >= end) break; | ||
| 390 | |||
| 391 | 		BF_safe_atoi64(c4, *sptr++); | ||
| 392 | 		*dptr++ = ((c3 & 0x03) << 6) | c4; | ||
| 393 | 	} while (dptr < end); | ||
| 394 | |||
| 395 | 	return 0; | ||
| 396 | } | ||
| 397 | |||
| 398 | static void BF_encode(char *dst, const BF_word *src, int size) | ||
| 399 | { | ||
| 400 | 	const unsigned char *sptr = (const unsigned char *)src; | ||
| 401 | 	const unsigned char *end = sptr + size; | ||
| 402 | 	unsigned char *dptr = (unsigned char *)dst; | ||
| 403 | 	unsigned int c1, c2; | ||
| 404 | |||
| 405 | 	do { | ||
| 406 | 		c1 = *sptr++; | ||
| 407 | 		*dptr++ = BF_itoa64[c1 >> 2]; | ||
| 408 | 		c1 = (c1 & 0x03) << 4; | ||
| 409 | 		if (sptr >= end) { | ||
| 410 | 			*dptr++ = BF_itoa64[c1]; | ||
| 411 | 			break; | ||
| 412 | 		} | ||
| 413 | |||
| 414 | 		c2 = *sptr++; | ||
| 415 | 		c1 |= c2 >> 4; | ||
| 416 | 		*dptr++ = BF_itoa64[c1]; | ||
| 417 | 		c1 = (c2 & 0x0f) << 2; | ||
| 418 | 		if (sptr >= end) { | ||
| 419 | 			*dptr++ = BF_itoa64[c1]; | ||
| 420 | 			break; | ||
| 421 | 		} | ||
| 422 | |||
| 423 | 		c2 = *sptr++; | ||
| 424 | 		c1 |= c2 >> 6; | ||
| 425 | 		*dptr++ = BF_itoa64[c1]; | ||
| 426 | 		*dptr++ = BF_itoa64[c2 & 0x3f]; | ||
| 427 | 	} while (sptr < end); | ||
| 428 | } | ||
| 429 | |||
| 430 | static void BF_swap(BF_word *x, int count) | ||
| 431 | { | ||
| 432 | 	if ((union { int i; char c; }){1}.c) | ||
| 433 | 	do { | ||
| 434 | 		BF_word tmp = *x; | ||
| 435 | 		tmp = (tmp << 16) | (tmp >> 16); | ||
| 436 | 		*x++ = ((tmp & 0x00FF00FF) << 8) | ((tmp >> 8) & 0x00FF00FF); | ||
| 437 | 	} while (--count); | ||
| 438 | } | ||
| 439 | |||
| 440 | #define BF_ROUND(L, R, N) \ | ||
| 441 | 	tmp1 = L & 0xFF; \ | ||
| 442 | 	tmp2 = L >> 8; \ | ||
| 443 | 	tmp2 &= 0xFF; \ | ||
| 444 | 	tmp3 = L >> 16; \ | ||
| 445 | 	tmp3 &= 0xFF; \ | ||
| 446 | 	tmp4 = L >> 24; \ | ||
| 447 | 	tmp1 = ctx->s.S[3][tmp1]; \ | ||
| 448 | 	tmp2 = ctx->s.S[2][tmp2]; \ | ||
| 449 | 	tmp3 = ctx->s.S[1][tmp3]; \ | ||
| 450 | 	tmp3 += ctx->s.S[0][tmp4]; \ | ||
| 451 | 	tmp3 ^= tmp2; \ | ||
| 452 | 	R ^= ctx->s.P[N + 1]; \ | ||
| 453 | 	tmp3 += tmp1; \ | ||
| 454 | 	R ^= tmp3; | ||
| 455 | |||
| 456 | static BF_word BF_encrypt(BF_ctx *ctx, | ||
| 457 | BF_word L, BF_word R, | ||
| 458 | BF_word *start, BF_word *end) | ||
| 459 | { | ||
| 460 | 	BF_word tmp1, tmp2, tmp3, tmp4; | ||
| 461 | 	BF_word *ptr = start; | ||
| 462 | |||
| 463 | 	do { | ||
| 464 | 		L ^= ctx->s.P[0]; | ||
| 465 | #if 0 | ||
| 466 | 		BF_ROUND(L, R, 0); | ||
| 467 | 		BF_ROUND(R, L, 1); | ||
| 468 | 		BF_ROUND(L, R, 2); | ||
| 469 | 		BF_ROUND(R, L, 3); | ||
| 470 | 		BF_ROUND(L, R, 4); | ||
| 471 | 		BF_ROUND(R, L, 5); | ||
| 472 | 		BF_ROUND(L, R, 6); | ||
| 473 | 		BF_ROUND(R, L, 7); | ||
| 474 | 		BF_ROUND(L, R, 8); | ||
| 475 | 		BF_ROUND(R, L, 9); | ||
| 476 | 		BF_ROUND(L, R, 10); | ||
| 477 | 		BF_ROUND(R, L, 11); | ||
| 478 | 		BF_ROUND(L, R, 12); | ||
| 479 | 		BF_ROUND(R, L, 13); | ||
| 480 | 		BF_ROUND(L, R, 14); | ||
| 481 | 		BF_ROUND(R, L, 15); | ||
| 482 | #else | ||
| 483 | 		for (int i=0; i<16; i+=2) { | ||
| 484 | 			BF_ROUND(L, R, i); | ||
| 485 | 			BF_ROUND(R, L, i+1); | ||
| 486 | 		} | ||
| 487 | #endif | ||
| 488 | 		tmp4 = R; | ||
| 489 | 		R = L; | ||
| 490 | 		L = tmp4 ^ ctx->s.P[BF_N + 1]; | ||
| 491 | 		*ptr++ = L; | ||
| 492 | 		*ptr++ = R; | ||
| 493 | 	} while (ptr < end); | ||
| 494 | |||
| 495 | 	return L; | ||
| 496 | } | ||
| 497 | |||
| 498 | static void BF_set_key(const char *key, BF_key expanded, BF_key initial, | ||
| 499 | unsigned char flags) | ||
| 500 | { | ||
| 501 | 	const char *ptr = key; | ||
| 502 | 	unsigned int bug, i, j; | ||
| 503 | 	BF_word safety, sign, diff, tmp[2]; | ||
| 504 | |||
| 505 | /* | ||
| 506 | * There was a sign extension bug in older revisions of this function. While | ||
| 507 | * we would have liked to simply fix the bug and move on, we have to provide | ||
| 508 | * a backwards compatibility feature (essentially the bug) for some systems and | ||
| 509 | * a safety measure for some others. The latter is needed because for certain | ||
| 510 | * multiple inputs to the buggy algorithm there exist easily found inputs to | ||
| 511 | * the correct algorithm that produce the same hash. Thus, we optionally | ||
| 512 | * deviate from the correct algorithm just enough to avoid such collisions. | ||
| 513 | * While the bug itself affected the majority of passwords containing | ||
| 514 | * characters with the 8th bit set (although only a percentage of those in a | ||
| 515 | * collision-producing way), the anti-collision safety measure affects | ||
| 516 | * only a subset of passwords containing the '\xff' character (not even all of | ||
| 517 | * those passwords, just some of them). This character is not found in valid | ||
| 518 | * UTF-8 sequences and is rarely used in popular 8-bit character encodings. | ||
| 519 | * Thus, the safety measure is unlikely to cause much annoyance, and is a | ||
| 520 | * reasonable tradeoff to use when authenticating against existing hashes that | ||
| 521 | * are not reliably known to have been computed with the correct algorithm. | ||
| 522 | * | ||
| 523 | * We use an approach that tries to minimize side-channel leaks of password | ||
| 524 | * information - that is, we mostly use fixed-cost bitwise operations instead | ||
| 525 | * of branches or table lookups. (One conditional branch based on password | ||
| 526 | * length remains. It is not part of the bug aftermath, though, and is | ||
| 527 | * difficult and possibly unreasonable to avoid given the use of C strings by | ||
| 528 | * the caller, which results in similar timing leaks anyway.) | ||
| 529 | * | ||
| 530 | * For actual implementation, we set an array index in the variable "bug" | ||
| 531 | * (0 means no bug, 1 means sign extension bug emulation) and a flag in the | ||
| 532 | * variable "safety" (bit 16 is set when the safety measure is requested). | ||
| 533 | * Valid combinations of settings are: | ||
| 534 | * | ||
| 535 | * Prefix "$2a$": bug = 0, safety = 0x10000 | ||
| 536 | * Prefix "$2b$": bug = 0, safety = 0 | ||
| 537 | * Prefix "$2x$": bug = 1, safety = 0 | ||
| 538 | * Prefix "$2y$": bug = 0, safety = 0 | ||
| 539 | */ | ||
| 540 | 	bug = flags & 1; | ||
| 541 | 	safety = ((BF_word)flags & 2) << 15; | ||
| 542 | |||
| 543 | 	sign = diff = 0; | ||
| 544 | |||
| 545 | 	for (i = 0; i < BF_N + 2; i++) { | ||
| 546 | 		tmp[0] = tmp[1] = 0; | ||
| 547 | 		for (j = 0; j < 4; j++) { | ||
| 548 | 			tmp[0] <<= 8; | ||
| 549 | 			tmp[0] |= (unsigned char)*ptr; /* correct */ | ||
| 550 | 			tmp[1] <<= 8; | ||
| 551 | 			tmp[1] |= (signed char)*ptr; /* bug */ | ||
| 552 | /* | ||
| 553 | * Sign extension in the first char has no effect - nothing to overwrite yet, | ||
| 554 | * and those extra 24 bits will be fully shifted out of the 32-bit word. For | ||
| 555 | * chars 2, 3, 4 in each four-char block, we set bit 7 of "sign" if sign | ||
| 556 | * extension in tmp[1] occurs. Once this flag is set, it remains set. | ||
| 557 | */ | ||
| 558 | 			if (j) | ||
| 559 | 				sign |= tmp[1] & 0x80; | ||
| 560 | 			if (!*ptr) | ||
| 561 | 				ptr = key; | ||
| 562 | 			else | ||
| 563 | 				ptr++; | ||
| 564 | 		} | ||
| 565 | 		diff |= tmp[0] ^ tmp[1]; /* Non-zero on any differences */ | ||
| 566 | |||
| 567 | 		expanded[i] = tmp[bug]; | ||
| 568 | 		initial[i] = BF_init_state.s.P[i] ^ tmp[bug]; | ||
| 569 | 	} | ||
| 570 | |||
| 571 | /* | ||
| 572 | * At this point, "diff" is zero iff the correct and buggy algorithms produced | ||
| 573 | * exactly the same result. If so and if "sign" is non-zero, which indicates | ||
| 574 | * that there was a non-benign sign extension, this means that we have a | ||
| 575 | * collision between the correctly computed hash for this password and a set of | ||
| 576 | * passwords that could be supplied to the buggy algorithm. Our safety measure | ||
| 577 | * is meant to protect from such many-buggy to one-correct collisions, by | ||
| 578 | * deviating from the correct algorithm in such cases. Let's check for this. | ||
| 579 | */ | ||
| 580 | 	diff |= diff >> 16; /* still zero iff exact match */ | ||
| 581 | 	diff &= 0xffff; /* ditto */ | ||
| 582 | 	diff += 0xffff; /* bit 16 set iff "diff" was non-zero (on non-match) */ | ||
| 583 | 	sign <<= 9; /* move the non-benign sign extension flag to bit 16 */ | ||
| 584 | 	sign &= ~diff & safety; /* action needed? */ | ||
| 585 | |||
| 586 | /* | ||
| 587 | * If we have determined that we need to deviate from the correct algorithm, | ||
| 588 | * flip bit 16 in initial expanded key. (The choice of 16 is arbitrary, but | ||
| 589 | * let's stick to it now. It came out of the approach we used above, and it's | ||
| 590 | * not any worse than any other choice we could make.) | ||
| 591 | * | ||
| 592 | * It is crucial that we don't do the same to the expanded key used in the main | ||
| 593 | * Eksblowfish loop. By doing it to only one of these two, we deviate from a | ||
| 594 | * state that could be directly specified by a password to the buggy algorithm | ||
| 595 | * (and to the fully correct one as well, but that's a side-effect). | ||
| 596 | */ | ||
| 597 | 	initial[0] ^= sign; | ||
| 598 | } | ||
| 599 | |||
| 600 | static const unsigned char flags_by_subtype[26] = { | ||
| 601 | 	2, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 602 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 4, 0 | ||
| 603 | }; | ||
| 604 | |||
| 605 | static char *BF_crypt(const char *key, const char *setting, | ||
| 606 | 	char *output, BF_word min) | ||
| 607 | { | ||
| 608 | 	struct { | ||
| 609 | 		BF_ctx ctx; | ||
| 610 | 		BF_key expanded_key; | ||
| 611 | 		union { | ||
| 612 | 			BF_word salt[4]; | ||
| 613 | 			BF_word output[6]; | ||
| 614 | 		} binary; | ||
| 615 | 	} data; | ||
| 616 | 	BF_word count; | ||
| 617 | 	int i; | ||
| 618 | |||
| 619 | 	if (setting[0] != '$' || | ||
| 620 | 	 setting[1] != '2' || | ||
| 621 | 	 setting[2] - 'a' > 25U || | ||
| 622 | 	 !flags_by_subtype[setting[2] - 'a'] || | ||
| 623 | 	 setting[3] != '$' || | ||
| 624 | 	 setting[4] - '0' > 1U || | ||
| 625 | 	 setting[5] - '0' > 9U || | ||
| 626 | 	 setting[6] != '$') { | ||
| 627 | 		return NULL; | ||
| 628 | 	} | ||
| 629 | |||
| 630 | 	count = (BF_word)1 << ((setting[4] - '0') * 10 + (setting[5] - '0')); | ||
| 631 | 	if (count < min || BF_decode(data.binary.salt, &setting[7], 16)) { | ||
| 632 | 		return NULL; | ||
| 633 | 	} | ||
| 634 | 	BF_swap(data.binary.salt, 4); | ||
| 635 | |||
| 636 | 	BF_set_key(key, data.expanded_key, data.ctx.s.P, | ||
| 637 | 	 flags_by_subtype[setting[2] - 'a']); | ||
| 638 | |||
| 639 | 	memcpy(data.ctx.s.S, BF_init_state.s.S, sizeof(data.ctx.s.S)); | ||
| 640 | |||
| 641 | 	{ | ||
| 642 | 		BF_word L = 0, R = 0; | ||
| 643 | 		BF_word *ptr = &data.ctx.PS[0]; | ||
| 644 | 		do { | ||
| 645 | 			L = BF_encrypt(&data.ctx, | ||
| 646 | 			 L ^ data.binary.salt[0], R ^ data.binary.salt[1], | ||
| 647 | 			 ptr, ptr); | ||
| 648 | 			R = *(ptr + 1); | ||
| 649 | 			ptr += 2; | ||
| 650 | |||
| 651 | 			if (ptr >= &data.ctx.PS[BF_N + 2 + 4 * 0x100]) | ||
| 652 | 				break; | ||
| 653 | |||
| 654 | 			L = BF_encrypt(&data.ctx, | ||
| 655 | 			 L ^ data.binary.salt[2], R ^ data.binary.salt[3], | ||
| 656 | 			 ptr, ptr); | ||
| 657 | 			R = *(ptr + 1); | ||
| 658 | 			ptr += 2; | ||
| 659 | 		} while (1); | ||
| 660 | 	} | ||
| 661 | |||
| 662 | 	do { | ||
| 663 | 		int done; | ||
| 664 | |||
| 665 | 		for (i = 0; i < BF_N + 2; i += 2) { | ||
| 666 | 			data.ctx.s.P[i] ^= data.expanded_key[i]; | ||
| 667 | 			data.ctx.s.P[i + 1] ^= data.expanded_key[i + 1]; | ||
| 668 | 		} | ||
| 669 | |||
| 670 | 		done = 0; | ||
| 671 | 		do { | ||
| 672 | 			BF_encrypt(&data.ctx, 0, 0, | ||
| 673 | 			 &data.ctx.PS[0], | ||
| 674 | 			 &data.ctx.PS[BF_N + 2 + 4 * 0x100]); | ||
| 675 | |||
| 676 | 			if (done) | ||
| 677 | 				break; | ||
| 678 | 			done = 1; | ||
| 679 | |||
| 680 | 			{ | ||
| 681 | 				BF_word tmp1, tmp2, tmp3, tmp4; | ||
| 682 | |||
| 683 | 				tmp1 = data.binary.salt[0]; | ||
| 684 | 				tmp2 = data.binary.salt[1]; | ||
| 685 | 				tmp3 = data.binary.salt[2]; | ||
| 686 | 				tmp4 = data.binary.salt[3]; | ||
| 687 | 				for (i = 0; i < BF_N; i += 4) { | ||
| 688 | 					data.ctx.s.P[i] ^= tmp1; | ||
| 689 | 					data.ctx.s.P[i + 1] ^= tmp2; | ||
| 690 | 					data.ctx.s.P[i + 2] ^= tmp3; | ||
| 691 | 					data.ctx.s.P[i + 3] ^= tmp4; | ||
| 692 | 				} | ||
| 693 | 				data.ctx.s.P[16] ^= tmp1; | ||
| 694 | 				data.ctx.s.P[17] ^= tmp2; | ||
| 695 | 			} | ||
| 696 | 		} while (1); | ||
| 697 | 	} while (--count); | ||
| 698 | |||
| 699 | 	for (i = 0; i < 6; i += 2) { | ||
| 700 | 		BF_word L, LR[2]; | ||
| 701 | |||
| 702 | 		L = BF_magic_w[i]; | ||
| 703 | 		LR[1] = BF_magic_w[i + 1]; | ||
| 704 | |||
| 705 | 		count = 64; | ||
| 706 | 		do { | ||
| 707 | 			L = BF_encrypt(&data.ctx, L, LR[1], | ||
| 708 | 			 &LR[0], &LR[0]); | ||
| 709 | 		} while (--count); | ||
| 710 | |||
| 711 | 		data.binary.output[i] = L; | ||
| 712 | 		data.binary.output[i + 1] = LR[1]; | ||
| 713 | 	} | ||
| 714 | |||
| 715 | 	memcpy(output, setting, 7 + 22 - 1); | ||
| 716 | 	output[7 + 22 - 1] = BF_itoa64[ | ||
| 717 | 		BF_atoi64[setting[7 + 22 - 1] - 0x20] & 0x30]; | ||
| 718 | |||
| 719 | /* This has to be bug-compatible with the original implementation, so | ||
| 720 | * only encode 23 of the 24 bytes. :-) */ | ||
| 721 | 	BF_swap(data.binary.output, 6); | ||
| 722 | 	BF_encode(&output[7 + 22], data.binary.output, 23); | ||
| 723 | 	output[7 + 22 + 31] = '\0'; | ||
| 724 | |||
| 725 | 	return output; | ||
| 726 | } | ||
| 727 | |||
| 728 | /* | ||
| 729 | * Please preserve the runtime self-test. It serves two purposes at once: | ||
| 730 | * | ||
| 731 | * 1. We really can't afford the risk of producing incompatible hashes e.g. | ||
| 732 | * when there's something like gcc bug 26587 again, whereas an application or | ||
| 733 | * library integrating this code might not also integrate our external tests or | ||
| 734 | * it might not run them after every build. Even if it does, the miscompile | ||
| 735 | * might only occur on the production build, but not on a testing build (such | ||
| 736 | * as because of different optimization settings). It is painful to recover | ||
| 737 | * from incorrectly-computed hashes - merely fixing whatever broke is not | ||
| 738 | * enough. Thus, a proactive measure like this self-test is needed. | ||
| 739 | * | ||
| 740 | * 2. We don't want to leave sensitive data from our actual password hash | ||
| 741 | * computation on the stack or in registers. Previous revisions of the code | ||
| 742 | * would do explicit cleanups, but simply running the self-test after hash | ||
| 743 | * computation is more reliable. | ||
| 744 | * | ||
| 745 | * The performance cost of this quick self-test is around 0.6% at the "$2a$08" | ||
| 746 | * setting. | ||
| 747 | */ | ||
| 748 | char *__crypt_blowfish(const char *key, const char *setting, char *output) | ||
| 749 | { | ||
| 750 | 	const char *test_key = "8b \xd0\xc1\xd2\xcf\xcc\xd8"; | ||
| 751 | 	const char *test_setting = "$2a$00$abcdefghijklmnopqrstuu"; | ||
| 752 | 	static const char test_hashes[2][34] = { | ||
| 753 | 		"i1D709vfamulimlGcq0qq3UvuUasvEa\0\x55", /* 'a', 'b', 'y' */ | ||
| 754 | 		"VUrPmXD6q/nVSSp7pNDhCR9071IfIRe\0\x55", /* 'x' */ | ||
| 755 | 	}; | ||
| 756 | 	const char *test_hash = test_hashes[0]; | ||
| 757 | 	char *retval; | ||
| 758 | 	const char *p; | ||
| 759 | 	int ok; | ||
| 760 | 	struct { | ||
| 761 | 		char s[7 + 22 + 1]; | ||
| 762 | 		char o[7 + 22 + 31 + 1 + 1 + 1]; | ||
| 763 | 	} buf; | ||
| 764 | |||
| 765 | /* Hash the supplied password */ | ||
| 766 | 	retval = BF_crypt(key, setting, output, 16); | ||
| 767 | |||
| 768 | /* | ||
| 769 | * Do a quick self-test. It is important that we make both calls to BF_crypt() | ||
| 770 | * from the same scope such that they likely use the same stack locations, | ||
| 771 | * which makes the second call overwrite the first call's sensitive data on the | ||
| 772 | * stack and makes it more likely that any alignment related issues would be | ||
| 773 | * detected by the self-test. | ||
| 774 | */ | ||
| 775 | 	memcpy(buf.s, test_setting, sizeof(buf.s)); | ||
| 776 | 	if (retval) { | ||
| 777 | 		unsigned int flags = flags_by_subtype[setting[2] - 'a']; | ||
| 778 | 		test_hash = test_hashes[flags & 1]; | ||
| 779 | 		buf.s[2] = setting[2]; | ||
| 780 | 	} | ||
| 781 | 	memset(buf.o, 0x55, sizeof(buf.o)); | ||
| 782 | 	buf.o[sizeof(buf.o) - 1] = 0; | ||
| 783 | 	p = BF_crypt(test_key, buf.s, buf.o, 1); | ||
| 784 | |||
| 785 | 	ok = (p == buf.o && | ||
| 786 | 	 !memcmp(p, buf.s, 7 + 22) && | ||
| 787 | 	 !memcmp(p + (7 + 22), | ||
| 788 | 	 test_hash, | ||
| 789 | 	 31 + 1 + 1 + 1)); | ||
| 790 | |||
| 791 | 	{ | ||
| 792 | 		const char *k = "\xff\xa3" "34" "\xff\xff\xff\xa3" "345"; | ||
| 793 | 		BF_key ae, ai, ye, yi; | ||
| 794 | 		BF_set_key(k, ae, ai, 2); /* $2a$ */ | ||
| 795 | 		BF_set_key(k, ye, yi, 4); /* $2y$ */ | ||
| 796 | 		ai[0] ^= 0x10000; /* undo the safety (for comparison) */ | ||
| 797 | 		ok = ok && ai[0] == 0xdb9c59bc && ye[17] == 0x33343500 && | ||
| 798 | 		 !memcmp(ae, ye, sizeof(ae)) && | ||
| 799 | 		 !memcmp(ai, yi, sizeof(ai)); | ||
| 800 | 	} | ||
| 801 | |||
| 802 | 	if (ok && retval) | ||
| 803 | 		return retval; | ||
| 804 | |||
| 805 | 	return "*"; | ||
| 806 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_des.c created+1016| ... | @@ -0,0 +1,1016 @@ | ||
| 1 | /* | ||
| 2 | * This version has been further modified by Rich Felker, primary author | ||
| 3 | * and maintainer of musl libc, to remove table generation code and | ||
| 4 | * replaced all runtime-generated constant tables with static-initialized | ||
| 5 | * tables in the binary, in the interest of minimizing non-shareable | ||
| 6 | * memory usage and stack size requirements. | ||
| 7 | */ | ||
| 8 | /* | ||
| 9 | * This version is derived from the original implementation of FreeSec | ||
| 10 | * (release 1.1) by David Burren. I've made it reentrant, reduced its memory | ||
| 11 | * usage from about 70 KB to about 7 KB (with only minimal performance impact | ||
| 12 | * and keeping code size about the same), made the handling of invalid salts | ||
| 13 | * mostly UFC-crypt compatible, added a quick runtime self-test (which also | ||
| 14 | * serves to zeroize the stack from sensitive data), and added optional tests. | ||
| 15 | * - Solar Designer <solar at openwall.com> | ||
| 16 | */ | ||
| 17 | |||
| 18 | /* | ||
| 19 | * FreeSec: libcrypt for NetBSD | ||
| 20 | * | ||
| 21 | * Copyright (c) 1994 David Burren | ||
| 22 | * Copyright (c) 2000,2002,2010,2012 Solar Designer | ||
| 23 | * All rights reserved. | ||
| 24 | * | ||
| 25 | * Redistribution and use in source and binary forms, with or without | ||
| 26 | * modification, are permitted provided that the following conditions | ||
| 27 | * are met: | ||
| 28 | * 1. Redistributions of source code must retain the above copyright | ||
| 29 | * notice, this list of conditions and the following disclaimer. | ||
| 30 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 31 | * notice, this list of conditions and the following disclaimer in the | ||
| 32 | * documentation and/or other materials provided with the distribution. | ||
| 33 | * 3. Neither the name of the author nor the names of other contributors | ||
| 34 | * may be used to endorse or promote products derived from this software | ||
| 35 | * without specific prior written permission. | ||
| 36 | * | ||
| 37 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 38 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 39 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 40 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 41 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 42 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 43 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 45 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 46 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 47 | * SUCH DAMAGE. | ||
| 48 | * | ||
| 49 | *	$Owl: Owl/packages/glibc/crypt_freesec.c,v 1.6 2010/02/20 14:45:06 solar Exp $ | ||
| 50 | *	$Id: crypt.c,v 1.15 1994/09/13 04:58:49 davidb Exp $ | ||
| 51 | * | ||
| 52 | * This is an original implementation of the DES and the crypt(3) interfaces | ||
| 53 | * by David Burren. It has been heavily re-worked by Solar Designer. | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include <stdint.h> | ||
| 57 | #include <string.h> | ||
| 58 | |||
| 59 | #include "crypt_des.h" | ||
| 60 | |||
| 61 | #define _PASSWORD_EFMT1 '_' | ||
| 62 | |||
| 63 | static const unsigned char key_shifts[16] = { | ||
| 64 | 	1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1 | ||
| 65 | }; | ||
| 66 | |||
| 67 | static const uint32_t psbox[8][64] = { | ||
| 68 | 	{ | ||
| 69 | 		0x00808200,0x00000000,0x00008000,0x00808202, | ||
| 70 | 		0x00808002,0x00008202,0x00000002,0x00008000, | ||
| 71 | 		0x00000200,0x00808200,0x00808202,0x00000200, | ||
| 72 | 		0x00800202,0x00808002,0x00800000,0x00000002, | ||
| 73 | 		0x00000202,0x00800200,0x00800200,0x00008200, | ||
| 74 | 		0x00008200,0x00808000,0x00808000,0x00800202, | ||
| 75 | 		0x00008002,0x00800002,0x00800002,0x00008002, | ||
| 76 | 		0x00000000,0x00000202,0x00008202,0x00800000, | ||
| 77 | 		0x00008000,0x00808202,0x00000002,0x00808000, | ||
| 78 | 		0x00808200,0x00800000,0x00800000,0x00000200, | ||
| 79 | 		0x00808002,0x00008000,0x00008200,0x00800002, | ||
| 80 | 		0x00000200,0x00000002,0x00800202,0x00008202, | ||
| 81 | 		0x00808202,0x00008002,0x00808000,0x00800202, | ||
| 82 | 		0x00800002,0x00000202,0x00008202,0x00808200, | ||
| 83 | 		0x00000202,0x00800200,0x00800200,0x00000000, | ||
| 84 | 		0x00008002,0x00008200,0x00000000,0x00808002, | ||
| 85 | 	},{ | ||
| 86 | 		0x40084010,0x40004000,0x00004000,0x00084010, | ||
| 87 | 		0x00080000,0x00000010,0x40080010,0x40004010, | ||
| 88 | 		0x40000010,0x40084010,0x40084000,0x40000000, | ||
| 89 | 		0x40004000,0x00080000,0x00000010,0x40080010, | ||
| 90 | 		0x00084000,0x00080010,0x40004010,0x00000000, | ||
| 91 | 		0x40000000,0x00004000,0x00084010,0x40080000, | ||
| 92 | 		0x00080010,0x40000010,0x00000000,0x00084000, | ||
| 93 | 		0x00004010,0x40084000,0x40080000,0x00004010, | ||
| 94 | 		0x00000000,0x00084010,0x40080010,0x00080000, | ||
| 95 | 		0x40004010,0x40080000,0x40084000,0x00004000, | ||
| 96 | 		0x40080000,0x40004000,0x00000010,0x40084010, | ||
| 97 | 		0x00084010,0x00000010,0x00004000,0x40000000, | ||
| 98 | 		0x00004010,0x40084000,0x00080000,0x40000010, | ||
| 99 | 		0x00080010,0x40004010,0x40000010,0x00080010, | ||
| 100 | 		0x00084000,0x00000000,0x40004000,0x00004010, | ||
| 101 | 		0x40000000,0x40080010,0x40084010,0x00084000, | ||
| 102 | 	},{ | ||
| 103 | 		0x00000104,0x04010100,0x00000000,0x04010004, | ||
| 104 | 		0x04000100,0x00000000,0x00010104,0x04000100, | ||
| 105 | 		0x00010004,0x04000004,0x04000004,0x00010000, | ||
| 106 | 		0x04010104,0x00010004,0x04010000,0x00000104, | ||
| 107 | 		0x04000000,0x00000004,0x04010100,0x00000100, | ||
| 108 | 		0x00010100,0x04010000,0x04010004,0x00010104, | ||
| 109 | 		0x04000104,0x00010100,0x00010000,0x04000104, | ||
| 110 | 		0x00000004,0x04010104,0x00000100,0x04000000, | ||
| 111 | 		0x04010100,0x04000000,0x00010004,0x00000104, | ||
| 112 | 		0x00010000,0x04010100,0x04000100,0x00000000, | ||
| 113 | 		0x00000100,0x00010004,0x04010104,0x04000100, | ||
| 114 | 		0x04000004,0x00000100,0x00000000,0x04010004, | ||
| 115 | 		0x04000104,0x00010000,0x04000000,0x04010104, | ||
| 116 | 		0x00000004,0x00010104,0x00010100,0x04000004, | ||
| 117 | 		0x04010000,0x04000104,0x00000104,0x04010000, | ||
| 118 | 		0x00010104,0x00000004,0x04010004,0x00010100, | ||
| 119 | 	},{ | ||
| 120 | 		0x80401000,0x80001040,0x80001040,0x00000040, | ||
| 121 | 		0x00401040,0x80400040,0x80400000,0x80001000, | ||
| 122 | 		0x00000000,0x00401000,0x00401000,0x80401040, | ||
| 123 | 		0x80000040,0x00000000,0x00400040,0x80400000, | ||
| 124 | 		0x80000000,0x00001000,0x00400000,0x80401000, | ||
| 125 | 		0x00000040,0x00400000,0x80001000,0x00001040, | ||
| 126 | 		0x80400040,0x80000000,0x00001040,0x00400040, | ||
| 127 | 		0x00001000,0x00401040,0x80401040,0x80000040, | ||
| 128 | 		0x00400040,0x80400000,0x00401000,0x80401040, | ||
| 129 | 		0x80000040,0x00000000,0x00000000,0x00401000, | ||
| 130 | 		0x00001040,0x00400040,0x80400040,0x80000000, | ||
| 131 | 		0x80401000,0x80001040,0x80001040,0x00000040, | ||
| 132 | 		0x80401040,0x80000040,0x80000000,0x00001000, | ||
| 133 | 		0x80400000,0x80001000,0x00401040,0x80400040, | ||
| 134 | 		0x80001000,0x00001040,0x00400000,0x80401000, | ||
| 135 | 		0x00000040,0x00400000,0x00001000,0x00401040, | ||
| 136 | 	},{ | ||
| 137 | 		0x00000080,0x01040080,0x01040000,0x21000080, | ||
| 138 | 		0x00040000,0x00000080,0x20000000,0x01040000, | ||
| 139 | 		0x20040080,0x00040000,0x01000080,0x20040080, | ||
| 140 | 		0x21000080,0x21040000,0x00040080,0x20000000, | ||
| 141 | 		0x01000000,0x20040000,0x20040000,0x00000000, | ||
| 142 | 		0x20000080,0x21040080,0x21040080,0x01000080, | ||
| 143 | 		0x21040000,0x20000080,0x00000000,0x21000000, | ||
| 144 | 		0x01040080,0x01000000,0x21000000,0x00040080, | ||
| 145 | 		0x00040000,0x21000080,0x00000080,0x01000000, | ||
| 146 | 		0x20000000,0x01040000,0x21000080,0x20040080, | ||
| 147 | 		0x01000080,0x20000000,0x21040000,0x01040080, | ||
| 148 | 		0x20040080,0x00000080,0x01000000,0x21040000, | ||
| 149 | 		0x21040080,0x00040080,0x21000000,0x21040080, | ||
| 150 | 		0x01040000,0x00000000,0x20040000,0x21000000, | ||
| 151 | 		0x00040080,0x01000080,0x20000080,0x00040000, | ||
| 152 | 		0x00000000,0x20040000,0x01040080,0x20000080, | ||
| 153 | 	},{ | ||
| 154 | 		0x10000008,0x10200000,0x00002000,0x10202008, | ||
| 155 | 		0x10200000,0x00000008,0x10202008,0x00200000, | ||
| 156 | 		0x10002000,0x00202008,0x00200000,0x10000008, | ||
| 157 | 		0x00200008,0x10002000,0x10000000,0x00002008, | ||
| 158 | 		0x00000000,0x00200008,0x10002008,0x00002000, | ||
| 159 | 		0x00202000,0x10002008,0x00000008,0x10200008, | ||
| 160 | 		0x10200008,0x00000000,0x00202008,0x10202000, | ||
| 161 | 		0x00002008,0x00202000,0x10202000,0x10000000, | ||
| 162 | 		0x10002000,0x00000008,0x10200008,0x00202000, | ||
| 163 | 		0x10202008,0x00200000,0x00002008,0x10000008, | ||
| 164 | 		0x00200000,0x10002000,0x10000000,0x00002008, | ||
| 165 | 		0x10000008,0x10202008,0x00202000,0x10200000, | ||
| 166 | 		0x00202008,0x10202000,0x00000000,0x10200008, | ||
| 167 | 		0x00000008,0x00002000,0x10200000,0x00202008, | ||
| 168 | 		0x00002000,0x00200008,0x10002008,0x00000000, | ||
| 169 | 		0x10202000,0x10000000,0x00200008,0x10002008, | ||
| 170 | 	},{ | ||
| 171 | 		0x00100000,0x02100001,0x02000401,0x00000000, | ||
| 172 | 		0x00000400,0x02000401,0x00100401,0x02100400, | ||
| 173 | 		0x02100401,0x00100000,0x00000000,0x02000001, | ||
| 174 | 		0x00000001,0x02000000,0x02100001,0x00000401, | ||
| 175 | 		0x02000400,0x00100401,0x00100001,0x02000400, | ||
| 176 | 		0x02000001,0x02100000,0x02100400,0x00100001, | ||
| 177 | 		0x02100000,0x00000400,0x00000401,0x02100401, | ||
| 178 | 		0x00100400,0x00000001,0x02000000,0x00100400, | ||
| 179 | 		0x02000000,0x00100400,0x00100000,0x02000401, | ||
| 180 | 		0x02000401,0x02100001,0x02100001,0x00000001, | ||
| 181 | 		0x00100001,0x02000000,0x02000400,0x00100000, | ||
| 182 | 		0x02100400,0x00000401,0x00100401,0x02100400, | ||
| 183 | 		0x00000401,0x02000001,0x02100401,0x02100000, | ||
| 184 | 		0x00100400,0x00000000,0x00000001,0x02100401, | ||
| 185 | 		0x00000000,0x00100401,0x02100000,0x00000400, | ||
| 186 | 		0x02000001,0x02000400,0x00000400,0x00100001, | ||
| 187 | 	},{ | ||
| 188 | 		0x08000820,0x00000800,0x00020000,0x08020820, | ||
| 189 | 		0x08000000,0x08000820,0x00000020,0x08000000, | ||
| 190 | 		0x00020020,0x08020000,0x08020820,0x00020800, | ||
| 191 | 		0x08020800,0x00020820,0x00000800,0x00000020, | ||
| 192 | 		0x08020000,0x08000020,0x08000800,0x00000820, | ||
| 193 | 		0x00020800,0x00020020,0x08020020,0x08020800, | ||
| 194 | 		0x00000820,0x00000000,0x00000000,0x08020020, | ||
| 195 | 		0x08000020,0x08000800,0x00020820,0x00020000, | ||
| 196 | 		0x00020820,0x00020000,0x08020800,0x00000800, | ||
| 197 | 		0x00000020,0x08020020,0x00000800,0x00020820, | ||
| 198 | 		0x08000800,0x00000020,0x08000020,0x08020000, | ||
| 199 | 		0x08020020,0x08000000,0x00020000,0x08000820, | ||
| 200 | 		0x00000000,0x08020820,0x00020020,0x08000020, | ||
| 201 | 		0x08020000,0x08000800,0x08000820,0x00000000, | ||
| 202 | 		0x08020820,0x00020800,0x00020800,0x00000820, | ||
| 203 | 		0x00000820,0x00020020,0x08000000,0x08020800, | ||
| 204 | 	}, | ||
| 205 | }; | ||
| 206 | static const uint32_t ip_maskl[16][16] = { | ||
| 207 | 	{ | ||
| 208 | 		0x00000000,0x00010000,0x00000000,0x00010000, | ||
| 209 | 		0x01000000,0x01010000,0x01000000,0x01010000, | ||
| 210 | 		0x00000000,0x00010000,0x00000000,0x00010000, | ||
| 211 | 		0x01000000,0x01010000,0x01000000,0x01010000, | ||
| 212 | 	},{ | ||
| 213 | 		0x00000000,0x00000001,0x00000000,0x00000001, | ||
| 214 | 		0x00000100,0x00000101,0x00000100,0x00000101, | ||
| 215 | 		0x00000000,0x00000001,0x00000000,0x00000001, | ||
| 216 | 		0x00000100,0x00000101,0x00000100,0x00000101, | ||
| 217 | 	},{ | ||
| 218 | 		0x00000000,0x00020000,0x00000000,0x00020000, | ||
| 219 | 		0x02000000,0x02020000,0x02000000,0x02020000, | ||
| 220 | 		0x00000000,0x00020000,0x00000000,0x00020000, | ||
| 221 | 		0x02000000,0x02020000,0x02000000,0x02020000, | ||
| 222 | 	},{ | ||
| 223 | 		0x00000000,0x00000002,0x00000000,0x00000002, | ||
| 224 | 		0x00000200,0x00000202,0x00000200,0x00000202, | ||
| 225 | 		0x00000000,0x00000002,0x00000000,0x00000002, | ||
| 226 | 		0x00000200,0x00000202,0x00000200,0x00000202, | ||
| 227 | 	},{ | ||
| 228 | 		0x00000000,0x00040000,0x00000000,0x00040000, | ||
| 229 | 		0x04000000,0x04040000,0x04000000,0x04040000, | ||
| 230 | 		0x00000000,0x00040000,0x00000000,0x00040000, | ||
| 231 | 		0x04000000,0x04040000,0x04000000,0x04040000, | ||
| 232 | 	},{ | ||
| 233 | 		0x00000000,0x00000004,0x00000000,0x00000004, | ||
| 234 | 		0x00000400,0x00000404,0x00000400,0x00000404, | ||
| 235 | 		0x00000000,0x00000004,0x00000000,0x00000004, | ||
| 236 | 		0x00000400,0x00000404,0x00000400,0x00000404, | ||
| 237 | 	},{ | ||
| 238 | 		0x00000000,0x00080000,0x00000000,0x00080000, | ||
| 239 | 		0x08000000,0x08080000,0x08000000,0x08080000, | ||
| 240 | 		0x00000000,0x00080000,0x00000000,0x00080000, | ||
| 241 | 		0x08000000,0x08080000,0x08000000,0x08080000, | ||
| 242 | 	},{ | ||
| 243 | 		0x00000000,0x00000008,0x00000000,0x00000008, | ||
| 244 | 		0x00000800,0x00000808,0x00000800,0x00000808, | ||
| 245 | 		0x00000000,0x00000008,0x00000000,0x00000008, | ||
| 246 | 		0x00000800,0x00000808,0x00000800,0x00000808, | ||
| 247 | 	},{ | ||
| 248 | 		0x00000000,0x00100000,0x00000000,0x00100000, | ||
| 249 | 		0x10000000,0x10100000,0x10000000,0x10100000, | ||
| 250 | 		0x00000000,0x00100000,0x00000000,0x00100000, | ||
| 251 | 		0x10000000,0x10100000,0x10000000,0x10100000, | ||
| 252 | 	},{ | ||
| 253 | 		0x00000000,0x00000010,0x00000000,0x00000010, | ||
| 254 | 		0x00001000,0x00001010,0x00001000,0x00001010, | ||
| 255 | 		0x00000000,0x00000010,0x00000000,0x00000010, | ||
| 256 | 		0x00001000,0x00001010,0x00001000,0x00001010, | ||
| 257 | 	},{ | ||
| 258 | 		0x00000000,0x00200000,0x00000000,0x00200000, | ||
| 259 | 		0x20000000,0x20200000,0x20000000,0x20200000, | ||
| 260 | 		0x00000000,0x00200000,0x00000000,0x00200000, | ||
| 261 | 		0x20000000,0x20200000,0x20000000,0x20200000, | ||
| 262 | 	},{ | ||
| 263 | 		0x00000000,0x00000020,0x00000000,0x00000020, | ||
| 264 | 		0x00002000,0x00002020,0x00002000,0x00002020, | ||
| 265 | 		0x00000000,0x00000020,0x00000000,0x00000020, | ||
| 266 | 		0x00002000,0x00002020,0x00002000,0x00002020, | ||
| 267 | 	},{ | ||
| 268 | 		0x00000000,0x00400000,0x00000000,0x00400000, | ||
| 269 | 		0x40000000,0x40400000,0x40000000,0x40400000, | ||
| 270 | 		0x00000000,0x00400000,0x00000000,0x00400000, | ||
| 271 | 		0x40000000,0x40400000,0x40000000,0x40400000, | ||
| 272 | 	},{ | ||
| 273 | 		0x00000000,0x00000040,0x00000000,0x00000040, | ||
| 274 | 		0x00004000,0x00004040,0x00004000,0x00004040, | ||
| 275 | 		0x00000000,0x00000040,0x00000000,0x00000040, | ||
| 276 | 		0x00004000,0x00004040,0x00004000,0x00004040, | ||
| 277 | 	},{ | ||
| 278 | 		0x00000000,0x00800000,0x00000000,0x00800000, | ||
| 279 | 		0x80000000,0x80800000,0x80000000,0x80800000, | ||
| 280 | 		0x00000000,0x00800000,0x00000000,0x00800000, | ||
| 281 | 		0x80000000,0x80800000,0x80000000,0x80800000, | ||
| 282 | 	},{ | ||
| 283 | 		0x00000000,0x00000080,0x00000000,0x00000080, | ||
| 284 | 		0x00008000,0x00008080,0x00008000,0x00008080, | ||
| 285 | 		0x00000000,0x00000080,0x00000000,0x00000080, | ||
| 286 | 		0x00008000,0x00008080,0x00008000,0x00008080, | ||
| 287 | 	}, | ||
| 288 | }; | ||
| 289 | static const uint32_t ip_maskr[16][16] = { | ||
| 290 | 	{ | ||
| 291 | 		0x00000000,0x00000000,0x00010000,0x00010000, | ||
| 292 | 		0x00000000,0x00000000,0x00010000,0x00010000, | ||
| 293 | 		0x01000000,0x01000000,0x01010000,0x01010000, | ||
| 294 | 		0x01000000,0x01000000,0x01010000,0x01010000, | ||
| 295 | 	},{ | ||
| 296 | 		0x00000000,0x00000000,0x00000001,0x00000001, | ||
| 297 | 		0x00000000,0x00000000,0x00000001,0x00000001, | ||
| 298 | 		0x00000100,0x00000100,0x00000101,0x00000101, | ||
| 299 | 		0x00000100,0x00000100,0x00000101,0x00000101, | ||
| 300 | 	},{ | ||
| 301 | 		0x00000000,0x00000000,0x00020000,0x00020000, | ||
| 302 | 		0x00000000,0x00000000,0x00020000,0x00020000, | ||
| 303 | 		0x02000000,0x02000000,0x02020000,0x02020000, | ||
| 304 | 		0x02000000,0x02000000,0x02020000,0x02020000, | ||
| 305 | 	},{ | ||
| 306 | 		0x00000000,0x00000000,0x00000002,0x00000002, | ||
| 307 | 		0x00000000,0x00000000,0x00000002,0x00000002, | ||
| 308 | 		0x00000200,0x00000200,0x00000202,0x00000202, | ||
| 309 | 		0x00000200,0x00000200,0x00000202,0x00000202, | ||
| 310 | 	},{ | ||
| 311 | 		0x00000000,0x00000000,0x00040000,0x00040000, | ||
| 312 | 		0x00000000,0x00000000,0x00040000,0x00040000, | ||
| 313 | 		0x04000000,0x04000000,0x04040000,0x04040000, | ||
| 314 | 		0x04000000,0x04000000,0x04040000,0x04040000, | ||
| 315 | 	},{ | ||
| 316 | 		0x00000000,0x00000000,0x00000004,0x00000004, | ||
| 317 | 		0x00000000,0x00000000,0x00000004,0x00000004, | ||
| 318 | 		0x00000400,0x00000400,0x00000404,0x00000404, | ||
| 319 | 		0x00000400,0x00000400,0x00000404,0x00000404, | ||
| 320 | 	},{ | ||
| 321 | 		0x00000000,0x00000000,0x00080000,0x00080000, | ||
| 322 | 		0x00000000,0x00000000,0x00080000,0x00080000, | ||
| 323 | 		0x08000000,0x08000000,0x08080000,0x08080000, | ||
| 324 | 		0x08000000,0x08000000,0x08080000,0x08080000, | ||
| 325 | 	},{ | ||
| 326 | 		0x00000000,0x00000000,0x00000008,0x00000008, | ||
| 327 | 		0x00000000,0x00000000,0x00000008,0x00000008, | ||
| 328 | 		0x00000800,0x00000800,0x00000808,0x00000808, | ||
| 329 | 		0x00000800,0x00000800,0x00000808,0x00000808, | ||
| 330 | 	},{ | ||
| 331 | 		0x00000000,0x00000000,0x00100000,0x00100000, | ||
| 332 | 		0x00000000,0x00000000,0x00100000,0x00100000, | ||
| 333 | 		0x10000000,0x10000000,0x10100000,0x10100000, | ||
| 334 | 		0x10000000,0x10000000,0x10100000,0x10100000, | ||
| 335 | 	},{ | ||
| 336 | 		0x00000000,0x00000000,0x00000010,0x00000010, | ||
| 337 | 		0x00000000,0x00000000,0x00000010,0x00000010, | ||
| 338 | 		0x00001000,0x00001000,0x00001010,0x00001010, | ||
| 339 | 		0x00001000,0x00001000,0x00001010,0x00001010, | ||
| 340 | 	},{ | ||
| 341 | 		0x00000000,0x00000000,0x00200000,0x00200000, | ||
| 342 | 		0x00000000,0x00000000,0x00200000,0x00200000, | ||
| 343 | 		0x20000000,0x20000000,0x20200000,0x20200000, | ||
| 344 | 		0x20000000,0x20000000,0x20200000,0x20200000, | ||
| 345 | 	},{ | ||
| 346 | 		0x00000000,0x00000000,0x00000020,0x00000020, | ||
| 347 | 		0x00000000,0x00000000,0x00000020,0x00000020, | ||
| 348 | 		0x00002000,0x00002000,0x00002020,0x00002020, | ||
| 349 | 		0x00002000,0x00002000,0x00002020,0x00002020, | ||
| 350 | 	},{ | ||
| 351 | 		0x00000000,0x00000000,0x00400000,0x00400000, | ||
| 352 | 		0x00000000,0x00000000,0x00400000,0x00400000, | ||
| 353 | 		0x40000000,0x40000000,0x40400000,0x40400000, | ||
| 354 | 		0x40000000,0x40000000,0x40400000,0x40400000, | ||
| 355 | 	},{ | ||
| 356 | 		0x00000000,0x00000000,0x00000040,0x00000040, | ||
| 357 | 		0x00000000,0x00000000,0x00000040,0x00000040, | ||
| 358 | 		0x00004000,0x00004000,0x00004040,0x00004040, | ||
| 359 | 		0x00004000,0x00004000,0x00004040,0x00004040, | ||
| 360 | 	},{ | ||
| 361 | 		0x00000000,0x00000000,0x00800000,0x00800000, | ||
| 362 | 		0x00000000,0x00000000,0x00800000,0x00800000, | ||
| 363 | 		0x80000000,0x80000000,0x80800000,0x80800000, | ||
| 364 | 		0x80000000,0x80000000,0x80800000,0x80800000, | ||
| 365 | 	},{ | ||
| 366 | 		0x00000000,0x00000000,0x00000080,0x00000080, | ||
| 367 | 		0x00000000,0x00000000,0x00000080,0x00000080, | ||
| 368 | 		0x00008000,0x00008000,0x00008080,0x00008080, | ||
| 369 | 		0x00008000,0x00008000,0x00008080,0x00008080, | ||
| 370 | 	}, | ||
| 371 | }; | ||
| 372 | static const uint32_t fp_maskl[8][16] = { | ||
| 373 | 	{ | ||
| 374 | 		0x00000000,0x40000000,0x00400000,0x40400000, | ||
| 375 | 		0x00004000,0x40004000,0x00404000,0x40404000, | ||
| 376 | 		0x00000040,0x40000040,0x00400040,0x40400040, | ||
| 377 | 		0x00004040,0x40004040,0x00404040,0x40404040, | ||
| 378 | 	},{ | ||
| 379 | 		0x00000000,0x10000000,0x00100000,0x10100000, | ||
| 380 | 		0x00001000,0x10001000,0x00101000,0x10101000, | ||
| 381 | 		0x00000010,0x10000010,0x00100010,0x10100010, | ||
| 382 | 		0x00001010,0x10001010,0x00101010,0x10101010, | ||
| 383 | 	},{ | ||
| 384 | 		0x00000000,0x04000000,0x00040000,0x04040000, | ||
| 385 | 		0x00000400,0x04000400,0x00040400,0x04040400, | ||
| 386 | 		0x00000004,0x04000004,0x00040004,0x04040004, | ||
| 387 | 		0x00000404,0x04000404,0x00040404,0x04040404, | ||
| 388 | 	},{ | ||
| 389 | 		0x00000000,0x01000000,0x00010000,0x01010000, | ||
| 390 | 		0x00000100,0x01000100,0x00010100,0x01010100, | ||
| 391 | 		0x00000001,0x01000001,0x00010001,0x01010001, | ||
| 392 | 		0x00000101,0x01000101,0x00010101,0x01010101, | ||
| 393 | 	},{ | ||
| 394 | 		0x00000000,0x80000000,0x00800000,0x80800000, | ||
| 395 | 		0x00008000,0x80008000,0x00808000,0x80808000, | ||
| 396 | 		0x00000080,0x80000080,0x00800080,0x80800080, | ||
| 397 | 		0x00008080,0x80008080,0x00808080,0x80808080, | ||
| 398 | 	},{ | ||
| 399 | 		0x00000000,0x20000000,0x00200000,0x20200000, | ||
| 400 | 		0x00002000,0x20002000,0x00202000,0x20202000, | ||
| 401 | 		0x00000020,0x20000020,0x00200020,0x20200020, | ||
| 402 | 		0x00002020,0x20002020,0x00202020,0x20202020, | ||
| 403 | 	},{ | ||
| 404 | 		0x00000000,0x08000000,0x00080000,0x08080000, | ||
| 405 | 		0x00000800,0x08000800,0x00080800,0x08080800, | ||
| 406 | 		0x00000008,0x08000008,0x00080008,0x08080008, | ||
| 407 | 		0x00000808,0x08000808,0x00080808,0x08080808, | ||
| 408 | 	},{ | ||
| 409 | 		0x00000000,0x02000000,0x00020000,0x02020000, | ||
| 410 | 		0x00000200,0x02000200,0x00020200,0x02020200, | ||
| 411 | 		0x00000002,0x02000002,0x00020002,0x02020002, | ||
| 412 | 		0x00000202,0x02000202,0x00020202,0x02020202, | ||
| 413 | 	}, | ||
| 414 | }; | ||
| 415 | static const uint32_t fp_maskr[8][16] = { | ||
| 416 | 	{ | ||
| 417 | 		0x00000000,0x40000000,0x00400000,0x40400000, | ||
| 418 | 		0x00004000,0x40004000,0x00404000,0x40404000, | ||
| 419 | 		0x00000040,0x40000040,0x00400040,0x40400040, | ||
| 420 | 		0x00004040,0x40004040,0x00404040,0x40404040, | ||
| 421 | 	},{ | ||
| 422 | 		0x00000000,0x10000000,0x00100000,0x10100000, | ||
| 423 | 		0x00001000,0x10001000,0x00101000,0x10101000, | ||
| 424 | 		0x00000010,0x10000010,0x00100010,0x10100010, | ||
| 425 | 		0x00001010,0x10001010,0x00101010,0x10101010, | ||
| 426 | 	},{ | ||
| 427 | 		0x00000000,0x04000000,0x00040000,0x04040000, | ||
| 428 | 		0x00000400,0x04000400,0x00040400,0x04040400, | ||
| 429 | 		0x00000004,0x04000004,0x00040004,0x04040004, | ||
| 430 | 		0x00000404,0x04000404,0x00040404,0x04040404, | ||
| 431 | 	},{ | ||
| 432 | 		0x00000000,0x01000000,0x00010000,0x01010000, | ||
| 433 | 		0x00000100,0x01000100,0x00010100,0x01010100, | ||
| 434 | 		0x00000001,0x01000001,0x00010001,0x01010001, | ||
| 435 | 		0x00000101,0x01000101,0x00010101,0x01010101, | ||
| 436 | 	},{ | ||
| 437 | 		0x00000000,0x80000000,0x00800000,0x80800000, | ||
| 438 | 		0x00008000,0x80008000,0x00808000,0x80808000, | ||
| 439 | 		0x00000080,0x80000080,0x00800080,0x80800080, | ||
| 440 | 		0x00008080,0x80008080,0x00808080,0x80808080, | ||
| 441 | 	},{ | ||
| 442 | 		0x00000000,0x20000000,0x00200000,0x20200000, | ||
| 443 | 		0x00002000,0x20002000,0x00202000,0x20202000, | ||
| 444 | 		0x00000020,0x20000020,0x00200020,0x20200020, | ||
| 445 | 		0x00002020,0x20002020,0x00202020,0x20202020, | ||
| 446 | 	},{ | ||
| 447 | 		0x00000000,0x08000000,0x00080000,0x08080000, | ||
| 448 | 		0x00000800,0x08000800,0x00080800,0x08080800, | ||
| 449 | 		0x00000008,0x08000008,0x00080008,0x08080008, | ||
| 450 | 		0x00000808,0x08000808,0x00080808,0x08080808, | ||
| 451 | 	},{ | ||
| 452 | 		0x00000000,0x02000000,0x00020000,0x02020000, | ||
| 453 | 		0x00000200,0x02000200,0x00020200,0x02020200, | ||
| 454 | 		0x00000002,0x02000002,0x00020002,0x02020002, | ||
| 455 | 		0x00000202,0x02000202,0x00020202,0x02020202, | ||
| 456 | 	}, | ||
| 457 | }; | ||
| 458 | static const uint32_t key_perm_maskl[8][16] = { | ||
| 459 | 	{ | ||
| 460 | 		0x00000000,0x00000000,0x00000010,0x00000010, | ||
| 461 | 		0x00001000,0x00001000,0x00001010,0x00001010, | ||
| 462 | 		0x00100000,0x00100000,0x00100010,0x00100010, | ||
| 463 | 		0x00101000,0x00101000,0x00101010,0x00101010, | ||
| 464 | 	},{ | ||
| 465 | 		0x00000000,0x00000000,0x00000020,0x00000020, | ||
| 466 | 		0x00002000,0x00002000,0x00002020,0x00002020, | ||
| 467 | 		0x00200000,0x00200000,0x00200020,0x00200020, | ||
| 468 | 		0x00202000,0x00202000,0x00202020,0x00202020, | ||
| 469 | 	},{ | ||
| 470 | 		0x00000000,0x00000000,0x00000040,0x00000040, | ||
| 471 | 		0x00004000,0x00004000,0x00004040,0x00004040, | ||
| 472 | 		0x00400000,0x00400000,0x00400040,0x00400040, | ||
| 473 | 		0x00404000,0x00404000,0x00404040,0x00404040, | ||
| 474 | 	},{ | ||
| 475 | 		0x00000000,0x00000000,0x00000080,0x00000080, | ||
| 476 | 		0x00008000,0x00008000,0x00008080,0x00008080, | ||
| 477 | 		0x00800000,0x00800000,0x00800080,0x00800080, | ||
| 478 | 		0x00808000,0x00808000,0x00808080,0x00808080, | ||
| 479 | 	},{ | ||
| 480 | 		0x00000000,0x00000001,0x00000100,0x00000101, | ||
| 481 | 		0x00010000,0x00010001,0x00010100,0x00010101, | ||
| 482 | 		0x01000000,0x01000001,0x01000100,0x01000101, | ||
| 483 | 		0x01010000,0x01010001,0x01010100,0x01010101, | ||
| 484 | 	},{ | ||
| 485 | 		0x00000000,0x00000002,0x00000200,0x00000202, | ||
| 486 | 		0x00020000,0x00020002,0x00020200,0x00020202, | ||
| 487 | 		0x02000000,0x02000002,0x02000200,0x02000202, | ||
| 488 | 		0x02020000,0x02020002,0x02020200,0x02020202, | ||
| 489 | 	},{ | ||
| 490 | 		0x00000000,0x00000004,0x00000400,0x00000404, | ||
| 491 | 		0x00040000,0x00040004,0x00040400,0x00040404, | ||
| 492 | 		0x04000000,0x04000004,0x04000400,0x04000404, | ||
| 493 | 		0x04040000,0x04040004,0x04040400,0x04040404, | ||
| 494 | 	},{ | ||
| 495 | 		0x00000000,0x00000008,0x00000800,0x00000808, | ||
| 496 | 		0x00080000,0x00080008,0x00080800,0x00080808, | ||
| 497 | 		0x08000000,0x08000008,0x08000800,0x08000808, | ||
| 498 | 		0x08080000,0x08080008,0x08080800,0x08080808, | ||
| 499 | 	}, | ||
| 500 | }; | ||
| 501 | static const uint32_t key_perm_maskr[12][16] = { | ||
| 502 | 	{ | ||
| 503 | 		0x00000000,0x00000001,0x00000000,0x00000001, | ||
| 504 | 		0x00000000,0x00000001,0x00000000,0x00000001, | ||
| 505 | 		0x00000000,0x00000001,0x00000000,0x00000001, | ||
| 506 | 		0x00000000,0x00000001,0x00000000,0x00000001, | ||
| 507 | 	},{ | ||
| 508 | 		0x00000000,0x00000000,0x00100000,0x00100000, | ||
| 509 | 		0x00001000,0x00001000,0x00101000,0x00101000, | ||
| 510 | 		0x00000010,0x00000010,0x00100010,0x00100010, | ||
| 511 | 		0x00001010,0x00001010,0x00101010,0x00101010, | ||
| 512 | 	},{ | ||
| 513 | 		0x00000000,0x00000002,0x00000000,0x00000002, | ||
| 514 | 		0x00000000,0x00000002,0x00000000,0x00000002, | ||
| 515 | 		0x00000000,0x00000002,0x00000000,0x00000002, | ||
| 516 | 		0x00000000,0x00000002,0x00000000,0x00000002, | ||
| 517 | 	},{ | ||
| 518 | 		0x00000000,0x00000000,0x00200000,0x00200000, | ||
| 519 | 		0x00002000,0x00002000,0x00202000,0x00202000, | ||
| 520 | 		0x00000020,0x00000020,0x00200020,0x00200020, | ||
| 521 | 		0x00002020,0x00002020,0x00202020,0x00202020, | ||
| 522 | 	},{ | ||
| 523 | 		0x00000000,0x00000004,0x00000000,0x00000004, | ||
| 524 | 		0x00000000,0x00000004,0x00000000,0x00000004, | ||
| 525 | 		0x00000000,0x00000004,0x00000000,0x00000004, | ||
| 526 | 		0x00000000,0x00000004,0x00000000,0x00000004, | ||
| 527 | 	},{ | ||
| 528 | 		0x00000000,0x00000000,0x00400000,0x00400000, | ||
| 529 | 		0x00004000,0x00004000,0x00404000,0x00404000, | ||
| 530 | 		0x00000040,0x00000040,0x00400040,0x00400040, | ||
| 531 | 		0x00004040,0x00004040,0x00404040,0x00404040, | ||
| 532 | 	},{ | ||
| 533 | 		0x00000000,0x00000008,0x00000000,0x00000008, | ||
| 534 | 		0x00000000,0x00000008,0x00000000,0x00000008, | ||
| 535 | 		0x00000000,0x00000008,0x00000000,0x00000008, | ||
| 536 | 		0x00000000,0x00000008,0x00000000,0x00000008, | ||
| 537 | 	},{ | ||
| 538 | 		0x00000000,0x00000000,0x00800000,0x00800000, | ||
| 539 | 		0x00008000,0x00008000,0x00808000,0x00808000, | ||
| 540 | 		0x00000080,0x00000080,0x00800080,0x00800080, | ||
| 541 | 		0x00008080,0x00008080,0x00808080,0x00808080, | ||
| 542 | 	},{ | ||
| 543 | 		0x00000000,0x00000000,0x01000000,0x01000000, | ||
| 544 | 		0x00010000,0x00010000,0x01010000,0x01010000, | ||
| 545 | 		0x00000100,0x00000100,0x01000100,0x01000100, | ||
| 546 | 		0x00010100,0x00010100,0x01010100,0x01010100, | ||
| 547 | 	},{ | ||
| 548 | 		0x00000000,0x00000000,0x02000000,0x02000000, | ||
| 549 | 		0x00020000,0x00020000,0x02020000,0x02020000, | ||
| 550 | 		0x00000200,0x00000200,0x02000200,0x02000200, | ||
| 551 | 		0x00020200,0x00020200,0x02020200,0x02020200, | ||
| 552 | 	},{ | ||
| 553 | 		0x00000000,0x00000000,0x04000000,0x04000000, | ||
| 554 | 		0x00040000,0x00040000,0x04040000,0x04040000, | ||
| 555 | 		0x00000400,0x00000400,0x04000400,0x04000400, | ||
| 556 | 		0x00040400,0x00040400,0x04040400,0x04040400, | ||
| 557 | 	},{ | ||
| 558 | 		0x00000000,0x00000000,0x08000000,0x08000000, | ||
| 559 | 		0x00080000,0x00080000,0x08080000,0x08080000, | ||
| 560 | 		0x00000800,0x00000800,0x08000800,0x08000800, | ||
| 561 | 		0x00080800,0x00080800,0x08080800,0x08080800, | ||
| 562 | 	}, | ||
| 563 | }; | ||
| 564 | static const uint32_t comp_maskl0[4][8] = { | ||
| 565 | 	{ | ||
| 566 | 		0x00000000,0x00020000,0x00000001,0x00020001, | ||
| 567 | 		0x00080000,0x000a0000,0x00080001,0x000a0001, | ||
| 568 | 	},{ | ||
| 569 | 		0x00000000,0x00001000,0x00000000,0x00001000, | ||
| 570 | 		0x00000040,0x00001040,0x00000040,0x00001040, | ||
| 571 | 	},{ | ||
| 572 | 		0x00000000,0x00400000,0x00000020,0x00400020, | ||
| 573 | 		0x00008000,0x00408000,0x00008020,0x00408020, | ||
| 574 | 	},{ | ||
| 575 | 		0x00000000,0x00100000,0x00000800,0x00100800, | ||
| 576 | 		0x00000000,0x00100000,0x00000800,0x00100800, | ||
| 577 | 	}, | ||
| 578 | }; | ||
| 579 | static const uint32_t comp_maskr0[4][8] = { | ||
| 580 | 	{ | ||
| 581 | 		0x00000000,0x00200000,0x00020000,0x00220000, | ||
| 582 | 		0x00000002,0x00200002,0x00020002,0x00220002, | ||
| 583 | 	},{ | ||
| 584 | 		0x00000000,0x00000000,0x00100000,0x00100000, | ||
| 585 | 		0x00000004,0x00000004,0x00100004,0x00100004, | ||
| 586 | 	},{ | ||
| 587 | 		0x00000000,0x00004000,0x00000800,0x00004800, | ||
| 588 | 		0x00000000,0x00004000,0x00000800,0x00004800, | ||
| 589 | 	},{ | ||
| 590 | 		0x00000000,0x00400000,0x00008000,0x00408000, | ||
| 591 | 		0x00000008,0x00400008,0x00008008,0x00408008, | ||
| 592 | 	}, | ||
| 593 | }; | ||
| 594 | static const uint32_t comp_maskl1[4][16] = { | ||
| 595 | 	{ | ||
| 596 | 		0x00000000,0x00000010,0x00004000,0x00004010, | ||
| 597 | 		0x00040000,0x00040010,0x00044000,0x00044010, | ||
| 598 | 		0x00000100,0x00000110,0x00004100,0x00004110, | ||
| 599 | 		0x00040100,0x00040110,0x00044100,0x00044110, | ||
| 600 | 	},{ | ||
| 601 | 		0x00000000,0x00800000,0x00000002,0x00800002, | ||
| 602 | 		0x00000200,0x00800200,0x00000202,0x00800202, | ||
| 603 | 		0x00200000,0x00a00000,0x00200002,0x00a00002, | ||
| 604 | 		0x00200200,0x00a00200,0x00200202,0x00a00202, | ||
| 605 | 	},{ | ||
| 606 | 		0x00000000,0x00002000,0x00000004,0x00002004, | ||
| 607 | 		0x00000400,0x00002400,0x00000404,0x00002404, | ||
| 608 | 		0x00000000,0x00002000,0x00000004,0x00002004, | ||
| 609 | 		0x00000400,0x00002400,0x00000404,0x00002404, | ||
| 610 | 	},{ | ||
| 611 | 		0x00000000,0x00010000,0x00000008,0x00010008, | ||
| 612 | 		0x00000080,0x00010080,0x00000088,0x00010088, | ||
| 613 | 		0x00000000,0x00010000,0x00000008,0x00010008, | ||
| 614 | 		0x00000080,0x00010080,0x00000088,0x00010088, | ||
| 615 | 	}, | ||
| 616 | }; | ||
| 617 | static const uint32_t comp_maskr1[4][16] = { | ||
| 618 | 	{ | ||
| 619 | 		0x00000000,0x00000000,0x00000080,0x00000080, | ||
| 620 | 		0x00002000,0x00002000,0x00002080,0x00002080, | ||
| 621 | 		0x00000001,0x00000001,0x00000081,0x00000081, | ||
| 622 | 		0x00002001,0x00002001,0x00002081,0x00002081, | ||
| 623 | 	},{ | ||
| 624 | 		0x00000000,0x00000010,0x00800000,0x00800010, | ||
| 625 | 		0x00010000,0x00010010,0x00810000,0x00810010, | ||
| 626 | 		0x00000200,0x00000210,0x00800200,0x00800210, | ||
| 627 | 		0x00010200,0x00010210,0x00810200,0x00810210, | ||
| 628 | 	},{ | ||
| 629 | 		0x00000000,0x00000400,0x00001000,0x00001400, | ||
| 630 | 		0x00080000,0x00080400,0x00081000,0x00081400, | ||
| 631 | 		0x00000020,0x00000420,0x00001020,0x00001420, | ||
| 632 | 		0x00080020,0x00080420,0x00081020,0x00081420, | ||
| 633 | 	},{ | ||
| 634 | 		0x00000000,0x00000100,0x00040000,0x00040100, | ||
| 635 | 		0x00000000,0x00000100,0x00040000,0x00040100, | ||
| 636 | 		0x00000040,0x00000140,0x00040040,0x00040140, | ||
| 637 | 		0x00000040,0x00000140,0x00040040,0x00040140, | ||
| 638 | 	}, | ||
| 639 | }; | ||
| 640 | |||
| 641 | static const unsigned char ascii64[] = | ||
| 642 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
| 643 | /* 0000000000111111111122222222223333333333444444444455555555556666 */ | ||
| 644 | /* 0123456789012345678901234567890123456789012345678901234567890123 */ | ||
| 645 | |||
| 646 | /* | ||
| 647 | * We match the behavior of UFC-crypt on systems where "char" is signed by | ||
| 648 | * default (the majority), regardless of char's signedness on our system. | ||
| 649 | */ | ||
| 650 | static uint32_t ascii_to_bin(int ch) | ||
| 651 | { | ||
| 652 | 	int sch = (ch < 0x80) ? ch : -(0x100 - ch); | ||
| 653 | 	int retval; | ||
| 654 | |||
| 655 | 	retval = sch - '.'; | ||
| 656 | 	if (sch >= 'A') { | ||
| 657 | 		retval = sch - ('A' - 12); | ||
| 658 | 		if (sch >= 'a') | ||
| 659 | 			retval = sch - ('a' - 38); | ||
| 660 | 	} | ||
| 661 | 	retval &= 0x3f; | ||
| 662 | |||
| 663 | 	return retval; | ||
| 664 | } | ||
| 665 | |||
| 666 | /* | ||
| 667 | * When we choose to "support" invalid salts, nevertheless disallow those | ||
| 668 | * containing characters that would violate the passwd file format. | ||
| 669 | */ | ||
| 670 | static inline int ascii_is_unsafe(unsigned char ch) | ||
| 671 | { | ||
| 672 | 	return !ch || ch == '\n' || ch == ':'; | ||
| 673 | } | ||
| 674 | |||
| 675 | static uint32_t setup_salt(uint32_t salt) | ||
| 676 | { | ||
| 677 | 	uint32_t obit, saltbit, saltbits; | ||
| 678 | 	unsigned int i; | ||
| 679 | |||
| 680 | 	saltbits = 0; | ||
| 681 | 	saltbit = 1; | ||
| 682 | 	obit = 0x800000; | ||
| 683 | 	for (i = 0; i < 24; i++) { | ||
| 684 | 		if (salt & saltbit) | ||
| 685 | 			saltbits |= obit; | ||
| 686 | 		saltbit <<= 1; | ||
| 687 | 		obit >>= 1; | ||
| 688 | 	} | ||
| 689 | |||
| 690 | 	return saltbits; | ||
| 691 | } | ||
| 692 | |||
| 693 | void __des_setkey(const unsigned char *key, struct expanded_key *ekey) | ||
| 694 | { | ||
| 695 | 	uint32_t k0, k1, rawkey0, rawkey1; | ||
| 696 | 	unsigned int shifts, round, i, ibit; | ||
| 697 | |||
| 698 | 	rawkey0 = | ||
| 699 | 	 (uint32_t)key[3] | | ||
| 700 | 	 ((uint32_t)key[2] << 8) | | ||
| 701 | 	 ((uint32_t)key[1] << 16) | | ||
| 702 | 	 ((uint32_t)key[0] << 24); | ||
| 703 | 	rawkey1 = | ||
| 704 | 	 (uint32_t)key[7] | | ||
| 705 | 	 ((uint32_t)key[6] << 8) | | ||
| 706 | 	 ((uint32_t)key[5] << 16) | | ||
| 707 | 	 ((uint32_t)key[4] << 24); | ||
| 708 | |||
| 709 | 	/* | ||
| 710 | 	 * Do key permutation and split into two 28-bit subkeys. | ||
| 711 | 	 */ | ||
| 712 | 	k0 = k1 = 0; | ||
| 713 | 	for (i = 0, ibit = 28; i < 4; i++, ibit -= 4) { | ||
| 714 | 		unsigned int j = i << 1; | ||
| 715 | 		k0 |= key_perm_maskl[i][(rawkey0 >> ibit) & 0xf] | | ||
| 716 | 		 key_perm_maskl[i + 4][(rawkey1 >> ibit) & 0xf]; | ||
| 717 | 		k1 |= key_perm_maskr[j][(rawkey0 >> ibit) & 0xf]; | ||
| 718 | 		ibit -= 4; | ||
| 719 | 		k1 |= key_perm_maskr[j + 1][(rawkey0 >> ibit) & 0xf] | | ||
| 720 | 		 key_perm_maskr[i + 8][(rawkey1 >> ibit) & 0xf]; | ||
| 721 | 	} | ||
| 722 | |||
| 723 | 	/* | ||
| 724 | 	 * Rotate subkeys and do compression permutation. | ||
| 725 | 	 */ | ||
| 726 | 	shifts = 0; | ||
| 727 | 	for (round = 0; round < 16; round++) { | ||
| 728 | 		uint32_t t0, t1; | ||
| 729 | 		uint32_t kl, kr; | ||
| 730 | |||
| 731 | 		shifts += key_shifts[round]; | ||
| 732 | |||
| 733 | 		t0 = (k0 << shifts) | (k0 >> (28 - shifts)); | ||
| 734 | 		t1 = (k1 << shifts) | (k1 >> (28 - shifts)); | ||
| 735 | |||
| 736 | 		kl = kr = 0; | ||
| 737 | 		ibit = 25; | ||
| 738 | 		for (i = 0; i < 4; i++) { | ||
| 739 | 			kl |= comp_maskl0[i][(t0 >> ibit) & 7]; | ||
| 740 | 			kr |= comp_maskr0[i][(t1 >> ibit) & 7]; | ||
| 741 | 			ibit -= 4; | ||
| 742 | 			kl |= comp_maskl1[i][(t0 >> ibit) & 0xf]; | ||
| 743 | 			kr |= comp_maskr1[i][(t1 >> ibit) & 0xf]; | ||
| 744 | 			ibit -= 3; | ||
| 745 | 		} | ||
| 746 | 		ekey->l[round] = kl; | ||
| 747 | 		ekey->r[round] = kr; | ||
| 748 | 	} | ||
| 749 | } | ||
| 750 | |||
| 751 | /* | ||
| 752 | * l_in, r_in, l_out, and r_out are in pseudo-"big-endian" format. | ||
| 753 | */ | ||
| 754 | void __do_des(uint32_t l_in, uint32_t r_in, | ||
| 755 | uint32_t *l_out, uint32_t *r_out, | ||
| 756 | uint32_t count, uint32_t saltbits, const struct expanded_key *ekey) | ||
| 757 | { | ||
| 758 | 	uint32_t l, r; | ||
| 759 | |||
| 760 | 	/* | ||
| 761 | 	 * Do initial permutation (IP). | ||
| 762 | 	 */ | ||
| 763 | 	l = r = 0; | ||
| 764 | 	if (l_in | r_in) { | ||
| 765 | 		unsigned int i, ibit; | ||
| 766 | 		for (i = 0, ibit = 28; i < 8; i++, ibit -= 4) { | ||
| 767 | 			l |= ip_maskl[i][(l_in >> ibit) & 0xf] | | ||
| 768 | 			 ip_maskl[i + 8][(r_in >> ibit) & 0xf]; | ||
| 769 | 			r |= ip_maskr[i][(l_in >> ibit) & 0xf] | | ||
| 770 | 			 ip_maskr[i + 8][(r_in >> ibit) & 0xf]; | ||
| 771 | 		} | ||
| 772 | 	} | ||
| 773 | |||
| 774 | 	while (count--) { | ||
| 775 | 		/* | ||
| 776 | 		 * Do each round. | ||
| 777 | 		 */ | ||
| 778 | 		unsigned int round = 16; | ||
| 779 | 		const uint32_t *kl = ekey->l; | ||
| 780 | 		const uint32_t *kr = ekey->r; | ||
| 781 | 		uint32_t f; | ||
| 782 | 		while (round--) { | ||
| 783 | 			uint32_t r48l, r48r; | ||
| 784 | 			/* | ||
| 785 | 			 * Expand R to 48 bits (simulate the E-box). | ||
| 786 | 			 */ | ||
| 787 | 			r48l	= ((r & 0x00000001) << 23) | ||
| 788 | 				| ((r & 0xf8000000) >> 9) | ||
| 789 | 				| ((r & 0x1f800000) >> 11) | ||
| 790 | 				| ((r & 0x01f80000) >> 13) | ||
| 791 | 				| ((r & 0x001f8000) >> 15); | ||
| 792 | |||
| 793 | 			r48r	= ((r & 0x0001f800) << 7) | ||
| 794 | 				| ((r & 0x00001f80) << 5) | ||
| 795 | 				| ((r & 0x000001f8) << 3) | ||
| 796 | 				| ((r & 0x0000001f) << 1) | ||
| 797 | 				| ((r & 0x80000000) >> 31); | ||
| 798 | 			/* | ||
| 799 | 			 * Do salting for crypt() and friends, and | ||
| 800 | 			 * XOR with the permuted key. | ||
| 801 | 			 */ | ||
| 802 | 			f = (r48l ^ r48r) & saltbits; | ||
| 803 | 			r48l ^= f ^ *kl++; | ||
| 804 | 			r48r ^= f ^ *kr++; | ||
| 805 | 			/* | ||
| 806 | 			 * Do S-box lookups (which shrink it back to 32 bits) | ||
| 807 | 			 * and do the P-box permutation at the same time. | ||
| 808 | 			 */ | ||
| 809 | 			f = psbox[0][r48l >> 18] | ||
| 810 | 			 | psbox[1][(r48l >> 12) & 0x3f] | ||
| 811 | 			 | psbox[2][(r48l >> 6) & 0x3f] | ||
| 812 | 			 | psbox[3][r48l & 0x3f] | ||
| 813 | 			 | psbox[4][r48r >> 18] | ||
| 814 | 			 | psbox[5][(r48r >> 12) & 0x3f] | ||
| 815 | 			 | psbox[6][(r48r >> 6) & 0x3f] | ||
| 816 | 			 | psbox[7][r48r & 0x3f]; | ||
| 817 | 			/* | ||
| 818 | 			 * Now that we've permuted things, complete f(). | ||
| 819 | 			 */ | ||
| 820 | 			f ^= l; | ||
| 821 | 			l = r; | ||
| 822 | 			r = f; | ||
| 823 | 		} | ||
| 824 | 		r = l; | ||
| 825 | 		l = f; | ||
| 826 | 	} | ||
| 827 | |||
| 828 | 	/* | ||
| 829 | 	 * Do final permutation (inverse of IP). | ||
| 830 | 	 */ | ||
| 831 | 	{ | ||
| 832 | 		unsigned int i, ibit; | ||
| 833 | 		uint32_t lo, ro; | ||
| 834 | 		lo = ro = 0; | ||
| 835 | 		for (i = 0, ibit = 28; i < 4; i++, ibit -= 4) { | ||
| 836 | 			ro |= fp_maskr[i][(l >> ibit) & 0xf] | | ||
| 837 | 			 fp_maskr[i + 4][(r >> ibit) & 0xf]; | ||
| 838 | 			ibit -= 4; | ||
| 839 | 			lo |= fp_maskl[i][(l >> ibit) & 0xf] | | ||
| 840 | 			 fp_maskl[i + 4][(r >> ibit) & 0xf]; | ||
| 841 | 		} | ||
| 842 | 		*l_out = lo; | ||
| 843 | 		*r_out = ro; | ||
| 844 | 	} | ||
| 845 | } | ||
| 846 | |||
| 847 | static void des_cipher(const unsigned char *in, unsigned char *out, | ||
| 848 | uint32_t count, uint32_t saltbits, const struct expanded_key *ekey) | ||
| 849 | { | ||
| 850 | 	uint32_t l_out, r_out, rawl, rawr; | ||
| 851 | |||
| 852 | 	rawl = | ||
| 853 | 	 (uint32_t)in[3] | | ||
| 854 | 	 ((uint32_t)in[2] << 8) | | ||
| 855 | 	 ((uint32_t)in[1] << 16) | | ||
| 856 | 	 ((uint32_t)in[0] << 24); | ||
| 857 | 	rawr = | ||
| 858 | 	 (uint32_t)in[7] | | ||
| 859 | 	 ((uint32_t)in[6] << 8) | | ||
| 860 | 	 ((uint32_t)in[5] << 16) | | ||
| 861 | 	 ((uint32_t)in[4] << 24); | ||
| 862 | |||
| 863 | 	__do_des(rawl, rawr, &l_out, &r_out, count, saltbits, ekey); | ||
| 864 | |||
| 865 | 	out[0] = l_out >> 24; | ||
| 866 | 	out[1] = l_out >> 16; | ||
| 867 | 	out[2] = l_out >> 8; | ||
| 868 | 	out[3] = l_out; | ||
| 869 | 	out[4] = r_out >> 24; | ||
| 870 | 	out[5] = r_out >> 16; | ||
| 871 | 	out[6] = r_out >> 8; | ||
| 872 | 	out[7] = r_out; | ||
| 873 | } | ||
| 874 | |||
| 875 | static char *_crypt_extended_r_uut(const char *_key, const char *_setting, char *output) | ||
| 876 | { | ||
| 877 | 	const unsigned char *key = (const unsigned char *)_key; | ||
| 878 | 	const unsigned char *setting = (const unsigned char *)_setting; | ||
| 879 | 	struct expanded_key ekey; | ||
| 880 | 	unsigned char keybuf[8]; | ||
| 881 | 	unsigned char *p, *q; | ||
| 882 | 	uint32_t count, salt, l, r0, r1; | ||
| 883 | 	unsigned int i; | ||
| 884 | |||
| 885 | 	/* | ||
| 886 | 	 * Copy the key, shifting each character left by one bit and padding | ||
| 887 | 	 * with zeroes. | ||
| 888 | 	 */ | ||
| 889 | 	q = keybuf; | ||
| 890 | 	while (q <= &keybuf[sizeof(keybuf) - 1]) { | ||
| 891 | 		*q++ = *key << 1; | ||
| 892 | 		if (*key) | ||
| 893 | 			key++; | ||
| 894 | 	} | ||
| 895 | 	__des_setkey(keybuf, &ekey); | ||
| 896 | |||
| 897 | 	if (*setting == _PASSWORD_EFMT1) { | ||
| 898 | 		/* | ||
| 899 | 		 * "new"-style: | ||
| 900 | 		 *	setting - underscore, 4 chars of count, 4 chars of salt | ||
| 901 | 		 *	key - unlimited characters | ||
| 902 | 		 */ | ||
| 903 | 		for (i = 1, count = 0; i < 5; i++) { | ||
| 904 | 			uint32_t value = ascii_to_bin(setting[i]); | ||
| 905 | 			if (ascii64[value] != setting[i]) | ||
| 906 | 				return NULL; | ||
| 907 | 			count |= value << (i - 1) * 6; | ||
| 908 | 		} | ||
| 909 | 		if (!count) | ||
| 910 | 			return NULL; | ||
| 911 | |||
| 912 | 		for (i = 5, salt = 0; i < 9; i++) { | ||
| 913 | 			uint32_t value = ascii_to_bin(setting[i]); | ||
| 914 | 			if (ascii64[value] != setting[i]) | ||
| 915 | 				return NULL; | ||
| 916 | 			salt |= value << (i - 5) * 6; | ||
| 917 | 		} | ||
| 918 | |||
| 919 | 		while (*key) { | ||
| 920 | 			/* | ||
| 921 | 			 * Encrypt the key with itself. | ||
| 922 | 			 */ | ||
| 923 | 			des_cipher(keybuf, keybuf, 1, 0, &ekey); | ||
| 924 | 			/* | ||
| 925 | 			 * And XOR with the next 8 characters of the key. | ||
| 926 | 			 */ | ||
| 927 | 			q = keybuf; | ||
| 928 | 			while (q <= &keybuf[sizeof(keybuf) - 1] && *key) | ||
| 929 | 				*q++ ^= *key++ << 1; | ||
| 930 | 			__des_setkey(keybuf, &ekey); | ||
| 931 | 		} | ||
| 932 | |||
| 933 | 		memcpy(output, setting, 9); | ||
| 934 | 		output[9] = '\0'; | ||
| 935 | 		p = (unsigned char *)output + 9; | ||
| 936 | 	} else { | ||
| 937 | 		/* | ||
| 938 | 		 * "old"-style: | ||
| 939 | 		 *	setting - 2 chars of salt | ||
| 940 | 		 *	key - up to 8 characters | ||
| 941 | 		 */ | ||
| 942 | 		count = 25; | ||
| 943 | |||
| 944 | 		if (ascii_is_unsafe(setting[0]) || ascii_is_unsafe(setting[1])) | ||
| 945 | 			return NULL; | ||
| 946 | |||
| 947 | 		salt = (ascii_to_bin(setting[1]) << 6) | ||
| 948 | 		 | ascii_to_bin(setting[0]); | ||
| 949 | |||
| 950 | 		output[0] = setting[0]; | ||
| 951 | 		output[1] = setting[1]; | ||
| 952 | 		p = (unsigned char *)output + 2; | ||
| 953 | 	} | ||
| 954 | |||
| 955 | 	/* | ||
| 956 | 	 * Do it. | ||
| 957 | 	 */ | ||
| 958 | 	__do_des(0, 0, &r0, &r1, count, setup_salt(salt), &ekey); | ||
| 959 | |||
| 960 | 	/* | ||
| 961 | 	 * Now encode the result... | ||
| 962 | 	 */ | ||
| 963 | 	l = (r0 >> 8); | ||
| 964 | 	*p++ = ascii64[(l >> 18) & 0x3f]; | ||
| 965 | 	*p++ = ascii64[(l >> 12) & 0x3f]; | ||
| 966 | 	*p++ = ascii64[(l >> 6) & 0x3f]; | ||
| 967 | 	*p++ = ascii64[l & 0x3f]; | ||
| 968 | |||
| 969 | 	l = (r0 << 16) | ((r1 >> 16) & 0xffff); | ||
| 970 | 	*p++ = ascii64[(l >> 18) & 0x3f]; | ||
| 971 | 	*p++ = ascii64[(l >> 12) & 0x3f]; | ||
| 972 | 	*p++ = ascii64[(l >> 6) & 0x3f]; | ||
| 973 | 	*p++ = ascii64[l & 0x3f]; | ||
| 974 | |||
| 975 | 	l = r1 << 2; | ||
| 976 | 	*p++ = ascii64[(l >> 12) & 0x3f]; | ||
| 977 | 	*p++ = ascii64[(l >> 6) & 0x3f]; | ||
| 978 | 	*p++ = ascii64[l & 0x3f]; | ||
| 979 | 	*p = 0; | ||
| 980 | |||
| 981 | 	return output; | ||
| 982 | } | ||
| 983 | |||
| 984 | char *__crypt_des(const char *key, const char *setting, char *output) | ||
| 985 | { | ||
| 986 | 	const char *test_key = "\x80\xff\x80\x01 " | ||
| 987 | 	 "\x7f\x81\x80\x80\x0d\x0a\xff\x7f \x81 test"; | ||
| 988 | 	const char *test_setting = "_0.../9Zz"; | ||
| 989 | 	const char *test_hash = "_0.../9ZzX7iSJNd21sU"; | ||
| 990 | 	char test_buf[21]; | ||
| 991 | 	char *retval; | ||
| 992 | 	const char *p; | ||
| 993 | |||
| 994 | 	if (*setting != _PASSWORD_EFMT1) { | ||
| 995 | 		test_setting = "\x80x"; | ||
| 996 | 		test_hash = "\x80x22/wK52ZKGA"; | ||
| 997 | 	} | ||
| 998 | |||
| 999 | 	/* | ||
| 1000 | 	 * Hash the supplied password. | ||
| 1001 | 	 */ | ||
| 1002 | 	retval = _crypt_extended_r_uut(key, setting, output); | ||
| 1003 | |||
| 1004 | 	/* | ||
| 1005 | 	 * Perform a quick self-test. It is important that we make both calls | ||
| 1006 | 	 * to _crypt_extended_r_uut() from the same scope such that they likely | ||
| 1007 | 	 * use the same stack locations, which makes the second call overwrite | ||
| 1008 | 	 * the first call's sensitive data on the stack and makes it more | ||
| 1009 | 	 * likely that any alignment related issues would be detected. | ||
| 1010 | 	 */ | ||
| 1011 | 	p = _crypt_extended_r_uut(test_key, test_setting, test_buf); | ||
| 1012 | 	if (p && !strcmp(p, test_hash) && retval) | ||
| 1013 | 		return retval; | ||
| 1014 | |||
| 1015 | 	return (setting[0]=='*') ? "x" : "*"; | ||
| 1016 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_des.h created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #ifndef CRYPT_DES_H | ||
| 2 | #define CRYPT_DES_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | struct expanded_key { | ||
| 7 | 	uint32_t l[16], r[16]; | ||
| 8 | }; | ||
| 9 | |||
| 10 | hidden void __des_setkey(const unsigned char *, struct expanded_key *); | ||
| 11 | hidden void __do_des(uint32_t, uint32_t, uint32_t *, uint32_t *, | ||
| 12 | uint32_t, uint32_t, const struct expanded_key *); | ||
| 13 | |||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_md5.c created+285| ... | @@ -0,0 +1,285 @@ | ||
| 1 | /* | ||
| 2 | * md5 crypt implementation | ||
| 3 | * | ||
| 4 | * original md5 crypt design is from Poul-Henning Kamp | ||
| 5 | * this implementation was created based on the code in freebsd | ||
| 6 | * at least 32bit int is assumed, key is limited and $1$ prefix is mandatory, | ||
| 7 | * on error "*" is returned | ||
| 8 | */ | ||
| 9 | #include <string.h> | ||
| 10 | #include <stdint.h> | ||
| 11 | |||
| 12 | /* public domain md5 implementation based on rfc1321 and libtomcrypt */ | ||
| 13 | |||
| 14 | struct md5 { | ||
| 15 | 	uint64_t len; /* processed message length */ | ||
| 16 | 	uint32_t h[4]; /* hash state */ | ||
| 17 | 	uint8_t buf[64]; /* message block buffer */ | ||
| 18 | }; | ||
| 19 | |||
| 20 | static uint32_t rol(uint32_t n, int k) { return (n << k) | (n >> (32-k)); } | ||
| 21 | #define F(x,y,z) (z ^ (x & (y ^ z))) | ||
| 22 | #define G(x,y,z) (y ^ (z & (y ^ x))) | ||
| 23 | #define H(x,y,z) (x ^ y ^ z) | ||
| 24 | #define I(x,y,z) (y ^ (x | ~z)) | ||
| 25 | #define FF(a,b,c,d,w,s,t) a += F(b,c,d) + w + t; a = rol(a,s) + b | ||
| 26 | #define GG(a,b,c,d,w,s,t) a += G(b,c,d) + w + t; a = rol(a,s) + b | ||
| 27 | #define HH(a,b,c,d,w,s,t) a += H(b,c,d) + w + t; a = rol(a,s) + b | ||
| 28 | #define II(a,b,c,d,w,s,t) a += I(b,c,d) + w + t; a = rol(a,s) + b | ||
| 29 | |||
| 30 | static const uint32_t tab[64] = { | ||
| 31 | 0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, | ||
| 32 | 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821, | ||
| 33 | 0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x02441453, 0xd8a1e681, 0xe7d3fbc8, | ||
| 34 | 0x21e1cde6, 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a, | ||
| 35 | 0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, | ||
| 36 | 0x289b7ec6, 0xeaa127fa, 0xd4ef3085, 0x04881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665, | ||
| 37 | 0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, | ||
| 38 | 0x6fa87e4f, 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391 | ||
| 39 | }; | ||
| 40 | |||
| 41 | static void processblock(struct md5 *s, const uint8_t *buf) | ||
| 42 | { | ||
| 43 | 	uint32_t i, W[16], a, b, c, d; | ||
| 44 | |||
| 45 | 	for (i = 0; i < 16; i++) { | ||
| 46 | 		W[i] = buf[4*i]; | ||
| 47 | 		W[i] |= (uint32_t)buf[4*i+1]<<8; | ||
| 48 | 		W[i] |= (uint32_t)buf[4*i+2]<<16; | ||
| 49 | 		W[i] |= (uint32_t)buf[4*i+3]<<24; | ||
| 50 | 	} | ||
| 51 | |||
| 52 | 	a = s->h[0]; | ||
| 53 | 	b = s->h[1]; | ||
| 54 | 	c = s->h[2]; | ||
| 55 | 	d = s->h[3]; | ||
| 56 | |||
| 57 | 	i = 0; | ||
| 58 | 	while (i < 16) { | ||
| 59 | 		FF(a,b,c,d, W[i], 7, tab[i]); i++; | ||
| 60 | 		FF(d,a,b,c, W[i], 12, tab[i]); i++; | ||
| 61 | 		FF(c,d,a,b, W[i], 17, tab[i]); i++; | ||
| 62 | 		FF(b,c,d,a, W[i], 22, tab[i]); i++; | ||
| 63 | 	} | ||
| 64 | 	while (i < 32) { | ||
| 65 | 		GG(a,b,c,d, W[(5*i+1)%16], 5, tab[i]); i++; | ||
| 66 | 		GG(d,a,b,c, W[(5*i+1)%16], 9, tab[i]); i++; | ||
| 67 | 		GG(c,d,a,b, W[(5*i+1)%16], 14, tab[i]); i++; | ||
| 68 | 		GG(b,c,d,a, W[(5*i+1)%16], 20, tab[i]); i++; | ||
| 69 | 	} | ||
| 70 | 	while (i < 48) { | ||
| 71 | 		HH(a,b,c,d, W[(3*i+5)%16], 4, tab[i]); i++; | ||
| 72 | 		HH(d,a,b,c, W[(3*i+5)%16], 11, tab[i]); i++; | ||
| 73 | 		HH(c,d,a,b, W[(3*i+5)%16], 16, tab[i]); i++; | ||
| 74 | 		HH(b,c,d,a, W[(3*i+5)%16], 23, tab[i]); i++; | ||
| 75 | 	} | ||
| 76 | 	while (i < 64) { | ||
| 77 | 		II(a,b,c,d, W[7*i%16], 6, tab[i]); i++; | ||
| 78 | 		II(d,a,b,c, W[7*i%16], 10, tab[i]); i++; | ||
| 79 | 		II(c,d,a,b, W[7*i%16], 15, tab[i]); i++; | ||
| 80 | 		II(b,c,d,a, W[7*i%16], 21, tab[i]); i++; | ||
| 81 | 	} | ||
| 82 | |||
| 83 | 	s->h[0] += a; | ||
| 84 | 	s->h[1] += b; | ||
| 85 | 	s->h[2] += c; | ||
| 86 | 	s->h[3] += d; | ||
| 87 | } | ||
| 88 | |||
| 89 | static void pad(struct md5 *s) | ||
| 90 | { | ||
| 91 | 	unsigned r = s->len % 64; | ||
| 92 | |||
| 93 | 	s->buf[r++] = 0x80; | ||
| 94 | 	if (r > 56) { | ||
| 95 | 		memset(s->buf + r, 0, 64 - r); | ||
| 96 | 		r = 0; | ||
| 97 | 		processblock(s, s->buf); | ||
| 98 | 	} | ||
| 99 | 	memset(s->buf + r, 0, 56 - r); | ||
| 100 | 	s->len *= 8; | ||
| 101 | 	s->buf[56] = s->len; | ||
| 102 | 	s->buf[57] = s->len >> 8; | ||
| 103 | 	s->buf[58] = s->len >> 16; | ||
| 104 | 	s->buf[59] = s->len >> 24; | ||
| 105 | 	s->buf[60] = s->len >> 32; | ||
| 106 | 	s->buf[61] = s->len >> 40; | ||
| 107 | 	s->buf[62] = s->len >> 48; | ||
| 108 | 	s->buf[63] = s->len >> 56; | ||
| 109 | 	processblock(s, s->buf); | ||
| 110 | } | ||
| 111 | |||
| 112 | static void md5_init(struct md5 *s) | ||
| 113 | { | ||
| 114 | 	s->len = 0; | ||
| 115 | 	s->h[0] = 0x67452301; | ||
| 116 | 	s->h[1] = 0xefcdab89; | ||
| 117 | 	s->h[2] = 0x98badcfe; | ||
| 118 | 	s->h[3] = 0x10325476; | ||
| 119 | } | ||
| 120 | |||
| 121 | static void md5_sum(struct md5 *s, uint8_t *md) | ||
| 122 | { | ||
| 123 | 	int i; | ||
| 124 | |||
| 125 | 	pad(s); | ||
| 126 | 	for (i = 0; i < 4; i++) { | ||
| 127 | 		md[4*i] = s->h[i]; | ||
| 128 | 		md[4*i+1] = s->h[i] >> 8; | ||
| 129 | 		md[4*i+2] = s->h[i] >> 16; | ||
| 130 | 		md[4*i+3] = s->h[i] >> 24; | ||
| 131 | 	} | ||
| 132 | } | ||
| 133 | |||
| 134 | static void md5_update(struct md5 *s, const void *m, unsigned long len) | ||
| 135 | { | ||
| 136 | 	const uint8_t *p = m; | ||
| 137 | 	unsigned r = s->len % 64; | ||
| 138 | |||
| 139 | 	s->len += len; | ||
| 140 | 	if (r) { | ||
| 141 | 		if (len < 64 - r) { | ||
| 142 | 			memcpy(s->buf + r, p, len); | ||
| 143 | 			return; | ||
| 144 | 		} | ||
| 145 | 		memcpy(s->buf + r, p, 64 - r); | ||
| 146 | 		len -= 64 - r; | ||
| 147 | 		p += 64 - r; | ||
| 148 | 		processblock(s, s->buf); | ||
| 149 | 	} | ||
| 150 | 	for (; len >= 64; len -= 64, p += 64) | ||
| 151 | 		processblock(s, p); | ||
| 152 | 	memcpy(s->buf, p, len); | ||
| 153 | } | ||
| 154 | |||
| 155 | /*- | ||
| 156 | * Copyright (c) 2003 Poul-Henning Kamp | ||
| 157 | * All rights reserved. | ||
| 158 | * | ||
| 159 | * Redistribution and use in source and binary forms, with or without | ||
| 160 | * modification, are permitted provided that the following conditions | ||
| 161 | * are met: | ||
| 162 | * 1. Redistributions of source code must retain the above copyright | ||
| 163 | * notice, this list of conditions and the following disclaimer. | ||
| 164 | * 2. Redistributions in binary form must reproduce the above copyright | ||
| 165 | * notice, this list of conditions and the following disclaimer in the | ||
| 166 | * documentation and/or other materials provided with the distribution. | ||
| 167 | * | ||
| 168 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND | ||
| 169 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 170 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 171 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE | ||
| 172 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
| 173 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
| 174 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
| 175 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
| 176 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
| 177 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 178 | * SUCH DAMAGE. | ||
| 179 | */ | ||
| 180 | |||
| 181 | /* key limit is not part of the original design, added for DoS protection */ | ||
| 182 | #define KEY_MAX 30000 | ||
| 183 | #define SALT_MAX 8 | ||
| 184 | |||
| 185 | static const unsigned char b64[] = | ||
| 186 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
| 187 | |||
| 188 | static char *to64(char *s, unsigned int u, int n) | ||
| 189 | { | ||
| 190 | 	while (--n >= 0) { | ||
| 191 | 		*s++ = b64[u % 64]; | ||
| 192 | 		u /= 64; | ||
| 193 | 	} | ||
| 194 | 	return s; | ||
| 195 | } | ||
| 196 | |||
| 197 | static char *md5crypt(const char *key, const char *setting, char *output) | ||
| 198 | { | ||
| 199 | 	struct md5 ctx; | ||
| 200 | 	unsigned char md[16]; | ||
| 201 | 	unsigned int i, klen, slen; | ||
| 202 | 	const char *salt; | ||
| 203 | 	char *p; | ||
| 204 | |||
| 205 | 	/* reject large keys */ | ||
| 206 | 	klen = strnlen(key, KEY_MAX+1); | ||
| 207 | 	if (klen > KEY_MAX) | ||
| 208 | 		return 0; | ||
| 209 | |||
| 210 | 	/* setting: $1$salt$ (closing $ is optional) */ | ||
| 211 | 	if (strncmp(setting, "$1$", 3) != 0) | ||
| 212 | 		return 0; | ||
| 213 | 	salt = setting + 3; | ||
| 214 | 	for (i = 0; i < SALT_MAX && salt[i] && salt[i] != '$'; i++); | ||
| 215 | 	slen = i; | ||
| 216 | |||
| 217 | 	/* md5(key salt key) */ | ||
| 218 | 	md5_init(&ctx); | ||
| 219 | 	md5_update(&ctx, key, klen); | ||
| 220 | 	md5_update(&ctx, salt, slen); | ||
| 221 | 	md5_update(&ctx, key, klen); | ||
| 222 | 	md5_sum(&ctx, md); | ||
| 223 | |||
| 224 | 	/* md5(key $1$ salt repeated-md weird-key[0]-0) */ | ||
| 225 | 	md5_init(&ctx); | ||
| 226 | 	md5_update(&ctx, key, klen); | ||
| 227 | 	md5_update(&ctx, setting, 3 + slen); | ||
| 228 | 	for (i = klen; i > sizeof md; i -= sizeof md) | ||
| 229 | 		md5_update(&ctx, md, sizeof md); | ||
| 230 | 	md5_update(&ctx, md, i); | ||
| 231 | 	md[0] = 0; | ||
| 232 | 	for (i = klen; i; i >>= 1) | ||
| 233 | 		if (i & 1) | ||
| 234 | 			md5_update(&ctx, md, 1); | ||
| 235 | 		else | ||
| 236 | 			md5_update(&ctx, key, 1); | ||
| 237 | 	md5_sum(&ctx, md); | ||
| 238 | |||
| 239 | 	/* md = f(md, key, salt) iteration */ | ||
| 240 | 	for (i = 0; i < 1000; i++) { | ||
| 241 | 		md5_init(&ctx); | ||
| 242 | 		if (i % 2) | ||
| 243 | 			md5_update(&ctx, key, klen); | ||
| 244 | 		else | ||
| 245 | 			md5_update(&ctx, md, sizeof md); | ||
| 246 | 		if (i % 3) | ||
| 247 | 			md5_update(&ctx, salt, slen); | ||
| 248 | 		if (i % 7) | ||
| 249 | 			md5_update(&ctx, key, klen); | ||
| 250 | 		if (i % 2) | ||
| 251 | 			md5_update(&ctx, md, sizeof md); | ||
| 252 | 		else | ||
| 253 | 			md5_update(&ctx, key, klen); | ||
| 254 | 		md5_sum(&ctx, md); | ||
| 255 | 	} | ||
| 256 | |||
| 257 | 	/* output is $1$salt$hash */ | ||
| 258 | 	memcpy(output, setting, 3 + slen); | ||
| 259 | 	p = output + 3 + slen; | ||
| 260 | 	*p++ = '$'; | ||
| 261 | 	static const unsigned char perm[][3] = { | ||
| 262 | 		0,6,12,1,7,13,2,8,14,3,9,15,4,10,5 }; | ||
| 263 | 	for (i=0; i<5; i++) p = to64(p, | ||
| 264 | 		(md[perm[i][0]]<<16)|(md[perm[i][1]]<<8)|md[perm[i][2]], 4); | ||
| 265 | 	p = to64(p, md[11], 2); | ||
| 266 | 	*p = 0; | ||
| 267 | |||
| 268 | 	return output; | ||
| 269 | } | ||
| 270 | |||
| 271 | char *__crypt_md5(const char *key, const char *setting, char *output) | ||
| 272 | { | ||
| 273 | 	static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"; | ||
| 274 | 	static const char testsetting[] = "$1$abcd0123$"; | ||
| 275 | 	static const char testhash[] = "$1$abcd0123$9Qcg8DyviekV3tDGMZynJ1"; | ||
| 276 | 	char testbuf[64]; | ||
| 277 | 	char *p, *q; | ||
| 278 | |||
| 279 | 	p = md5crypt(key, setting, output); | ||
| 280 | 	/* self test and stack cleanup */ | ||
| 281 | 	q = md5crypt(testkey, testsetting, testbuf); | ||
| 282 | 	if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) | ||
| 283 | 		return "*"; | ||
| 284 | 	return p; | ||
| 285 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_r.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <crypt.h> | ||
| 2 | |||
| 3 | char *__crypt_r(const char *key, const char *salt, struct crypt_data *data) | ||
| 4 | { | ||
| 5 | 	/* Per the crypt_r API, the caller has provided a pointer to | ||
| 6 | 	 * struct crypt_data; however, this implementation does not | ||
| 7 | 	 * use the structure to store any internal state, and treats | ||
| 8 | 	 * it purely as a char buffer for storing the result. */ | ||
| 9 | 	char *output = (char *)data; | ||
| 10 | 	if (salt[0] == '$' && salt[1] && salt[2]) { | ||
| 11 | 		if (salt[1] == '1' && salt[2] == '$') | ||
| 12 | 			return __crypt_md5(key, salt, output); | ||
| 13 | 		if (salt[1] == '2' && salt[3] == '$') | ||
| 14 | 			return __crypt_blowfish(key, salt, output); | ||
| 15 | 		if (salt[1] == '5' && salt[2] == '$') | ||
| 16 | 			return __crypt_sha256(key, salt, output); | ||
| 17 | 		if (salt[1] == '6' && salt[2] == '$') | ||
| 18 | 			return __crypt_sha512(key, salt, output); | ||
| 19 | 	} | ||
| 20 | 	return __crypt_des(key, salt, output); | ||
| 21 | } | ||
| 22 | |||
| 23 | weak_alias(__crypt_r, crypt_r); | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_sha256.c created+322| ... | @@ -0,0 +1,322 @@ | ||
| 1 | /* | ||
| 2 | * public domain sha256 crypt implementation | ||
| 3 | * | ||
| 4 | * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt | ||
| 5 | * in this implementation at least 32bit int is assumed, | ||
| 6 | * key length is limited, the $5$ prefix is mandatory, '\n' and ':' is rejected | ||
| 7 | * in the salt and rounds= setting must contain a valid iteration count, | ||
| 8 | * on error "*" is returned. | ||
| 9 | */ | ||
| 10 | #include <ctype.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <stdio.h> | ||
| 13 | #include <string.h> | ||
| 14 | #include <stdint.h> | ||
| 15 | |||
| 16 | /* public domain sha256 implementation based on fips180-3 */ | ||
| 17 | |||
| 18 | struct sha256 { | ||
| 19 | 	uint64_t len; /* processed message length */ | ||
| 20 | 	uint32_t h[8]; /* hash state */ | ||
| 21 | 	uint8_t buf[64]; /* message block buffer */ | ||
| 22 | }; | ||
| 23 | |||
| 24 | static uint32_t ror(uint32_t n, int k) { return (n >> k) | (n << (32-k)); } | ||
| 25 | #define Ch(x,y,z) (z ^ (x & (y ^ z))) | ||
| 26 | #define Maj(x,y,z) ((x & y) | (z & (x | y))) | ||
| 27 | #define S0(x) (ror(x,2) ^ ror(x,13) ^ ror(x,22)) | ||
| 28 | #define S1(x) (ror(x,6) ^ ror(x,11) ^ ror(x,25)) | ||
| 29 | #define R0(x) (ror(x,7) ^ ror(x,18) ^ (x>>3)) | ||
| 30 | #define R1(x) (ror(x,17) ^ ror(x,19) ^ (x>>10)) | ||
| 31 | |||
| 32 | static const uint32_t K[64] = { | ||
| 33 | 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, | ||
| 34 | 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, | ||
| 35 | 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da, | ||
| 36 | 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967, | ||
| 37 | 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, | ||
| 38 | 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, | ||
| 39 | 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, | ||
| 40 | 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2 | ||
| 41 | }; | ||
| 42 | |||
| 43 | static void processblock(struct sha256 *s, const uint8_t *buf) | ||
| 44 | { | ||
| 45 | 	uint32_t W[64], t1, t2, a, b, c, d, e, f, g, h; | ||
| 46 | 	int i; | ||
| 47 | |||
| 48 | 	for (i = 0; i < 16; i++) { | ||
| 49 | 		W[i] = (uint32_t)buf[4*i]<<24; | ||
| 50 | 		W[i] |= (uint32_t)buf[4*i+1]<<16; | ||
| 51 | 		W[i] |= (uint32_t)buf[4*i+2]<<8; | ||
| 52 | 		W[i] |= buf[4*i+3]; | ||
| 53 | 	} | ||
| 54 | 	for (; i < 64; i++) | ||
| 55 | 		W[i] = R1(W[i-2]) + W[i-7] + R0(W[i-15]) + W[i-16]; | ||
| 56 | 	a = s->h[0]; | ||
| 57 | 	b = s->h[1]; | ||
| 58 | 	c = s->h[2]; | ||
| 59 | 	d = s->h[3]; | ||
| 60 | 	e = s->h[4]; | ||
| 61 | 	f = s->h[5]; | ||
| 62 | 	g = s->h[6]; | ||
| 63 | 	h = s->h[7]; | ||
| 64 | 	for (i = 0; i < 64; i++) { | ||
| 65 | 		t1 = h + S1(e) + Ch(e,f,g) + K[i] + W[i]; | ||
| 66 | 		t2 = S0(a) + Maj(a,b,c); | ||
| 67 | 		h = g; | ||
| 68 | 		g = f; | ||
| 69 | 		f = e; | ||
| 70 | 		e = d + t1; | ||
| 71 | 		d = c; | ||
| 72 | 		c = b; | ||
| 73 | 		b = a; | ||
| 74 | 		a = t1 + t2; | ||
| 75 | 	} | ||
| 76 | 	s->h[0] += a; | ||
| 77 | 	s->h[1] += b; | ||
| 78 | 	s->h[2] += c; | ||
| 79 | 	s->h[3] += d; | ||
| 80 | 	s->h[4] += e; | ||
| 81 | 	s->h[5] += f; | ||
| 82 | 	s->h[6] += g; | ||
| 83 | 	s->h[7] += h; | ||
| 84 | } | ||
| 85 | |||
| 86 | static void pad(struct sha256 *s) | ||
| 87 | { | ||
| 88 | 	unsigned r = s->len % 64; | ||
| 89 | |||
| 90 | 	s->buf[r++] = 0x80; | ||
| 91 | 	if (r > 56) { | ||
| 92 | 		memset(s->buf + r, 0, 64 - r); | ||
| 93 | 		r = 0; | ||
| 94 | 		processblock(s, s->buf); | ||
| 95 | 	} | ||
| 96 | 	memset(s->buf + r, 0, 56 - r); | ||
| 97 | 	s->len *= 8; | ||
| 98 | 	s->buf[56] = s->len >> 56; | ||
| 99 | 	s->buf[57] = s->len >> 48; | ||
| 100 | 	s->buf[58] = s->len >> 40; | ||
| 101 | 	s->buf[59] = s->len >> 32; | ||
| 102 | 	s->buf[60] = s->len >> 24; | ||
| 103 | 	s->buf[61] = s->len >> 16; | ||
| 104 | 	s->buf[62] = s->len >> 8; | ||
| 105 | 	s->buf[63] = s->len; | ||
| 106 | 	processblock(s, s->buf); | ||
| 107 | } | ||
| 108 | |||
| 109 | static void sha256_init(struct sha256 *s) | ||
| 110 | { | ||
| 111 | 	s->len = 0; | ||
| 112 | 	s->h[0] = 0x6a09e667; | ||
| 113 | 	s->h[1] = 0xbb67ae85; | ||
| 114 | 	s->h[2] = 0x3c6ef372; | ||
| 115 | 	s->h[3] = 0xa54ff53a; | ||
| 116 | 	s->h[4] = 0x510e527f; | ||
| 117 | 	s->h[5] = 0x9b05688c; | ||
| 118 | 	s->h[6] = 0x1f83d9ab; | ||
| 119 | 	s->h[7] = 0x5be0cd19; | ||
| 120 | } | ||
| 121 | |||
| 122 | static void sha256_sum(struct sha256 *s, uint8_t *md) | ||
| 123 | { | ||
| 124 | 	int i; | ||
| 125 | |||
| 126 | 	pad(s); | ||
| 127 | 	for (i = 0; i < 8; i++) { | ||
| 128 | 		md[4*i] = s->h[i] >> 24; | ||
| 129 | 		md[4*i+1] = s->h[i] >> 16; | ||
| 130 | 		md[4*i+2] = s->h[i] >> 8; | ||
| 131 | 		md[4*i+3] = s->h[i]; | ||
| 132 | 	} | ||
| 133 | } | ||
| 134 | |||
| 135 | static void sha256_update(struct sha256 *s, const void *m, unsigned long len) | ||
| 136 | { | ||
| 137 | 	const uint8_t *p = m; | ||
| 138 | 	unsigned r = s->len % 64; | ||
| 139 | |||
| 140 | 	s->len += len; | ||
| 141 | 	if (r) { | ||
| 142 | 		if (len < 64 - r) { | ||
| 143 | 			memcpy(s->buf + r, p, len); | ||
| 144 | 			return; | ||
| 145 | 		} | ||
| 146 | 		memcpy(s->buf + r, p, 64 - r); | ||
| 147 | 		len -= 64 - r; | ||
| 148 | 		p += 64 - r; | ||
| 149 | 		processblock(s, s->buf); | ||
| 150 | 	} | ||
| 151 | 	for (; len >= 64; len -= 64, p += 64) | ||
| 152 | 		processblock(s, p); | ||
| 153 | 	memcpy(s->buf, p, len); | ||
| 154 | } | ||
| 155 | |||
| 156 | static const unsigned char b64[] = | ||
| 157 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
| 158 | |||
| 159 | static char *to64(char *s, unsigned int u, int n) | ||
| 160 | { | ||
| 161 | 	while (--n >= 0) { | ||
| 162 | 		*s++ = b64[u % 64]; | ||
| 163 | 		u /= 64; | ||
| 164 | 	} | ||
| 165 | 	return s; | ||
| 166 | } | ||
| 167 | |||
| 168 | /* key limit is not part of the original design, added for DoS protection. | ||
| 169 | * rounds limit has been lowered (versus the reference/spec), also for DoS | ||
| 170 | * protection. runtime is O(klen^2 + klen*rounds) */ | ||
| 171 | #define KEY_MAX 256 | ||
| 172 | #define SALT_MAX 16 | ||
| 173 | #define ROUNDS_DEFAULT 5000 | ||
| 174 | #define ROUNDS_MIN 1000 | ||
| 175 | #define ROUNDS_MAX 9999999 | ||
| 176 | |||
| 177 | /* hash n bytes of the repeated md message digest */ | ||
| 178 | static void hashmd(struct sha256 *s, unsigned int n, const void *md) | ||
| 179 | { | ||
| 180 | 	unsigned int i; | ||
| 181 | |||
| 182 | 	for (i = n; i > 32; i -= 32) | ||
| 183 | 		sha256_update(s, md, 32); | ||
| 184 | 	sha256_update(s, md, i); | ||
| 185 | } | ||
| 186 | |||
| 187 | static char *sha256crypt(const char *key, const char *setting, char *output) | ||
| 188 | { | ||
| 189 | 	struct sha256 ctx; | ||
| 190 | 	unsigned char md[32], kmd[32], smd[32]; | ||
| 191 | 	unsigned int i, r, klen, slen; | ||
| 192 | 	char rounds[20] = ""; | ||
| 193 | 	const char *salt; | ||
| 194 | 	char *p; | ||
| 195 | |||
| 196 | 	/* reject large keys */ | ||
| 197 | 	klen = strnlen(key, KEY_MAX+1); | ||
| 198 | 	if (klen > KEY_MAX) | ||
| 199 | 		return 0; | ||
| 200 | |||
| 201 | 	/* setting: $5$rounds=n$salt$ (rounds=n$ and closing $ are optional) */ | ||
| 202 | 	if (strncmp(setting, "$5$", 3) != 0) | ||
| 203 | 		return 0; | ||
| 204 | 	salt = setting + 3; | ||
| 205 | |||
| 206 | 	r = ROUNDS_DEFAULT; | ||
| 207 | 	if (strncmp(salt, "rounds=", sizeof "rounds=" - 1) == 0) { | ||
| 208 | 		unsigned long u; | ||
| 209 | 		char *end; | ||
| 210 | |||
| 211 | 		/* | ||
| 212 | 		 * this is a deviation from the reference: | ||
| 213 | 		 * bad rounds setting is rejected if it is | ||
| 214 | 		 * - empty | ||
| 215 | 		 * - unterminated (missing '$') | ||
| 216 | 		 * - begins with anything but a decimal digit | ||
| 217 | 		 * the reference implementation treats these bad | ||
| 218 | 		 * rounds as part of the salt or parse them with | ||
| 219 | 		 * strtoul semantics which may cause problems | ||
| 220 | 		 * including non-portable hashes that depend on | ||
| 221 | 		 * the host's value of ULONG_MAX. | ||
| 222 | 		 */ | ||
| 223 | 		salt += sizeof "rounds=" - 1; | ||
| 224 | 		if (!isdigit(*salt)) | ||
| 225 | 			return 0; | ||
| 226 | 		u = strtoul(salt, &end, 10); | ||
| 227 | 		if (*end != '$') | ||
| 228 | 			return 0; | ||
| 229 | 		salt = end+1; | ||
| 230 | 		if (u < ROUNDS_MIN) | ||
| 231 | 			r = ROUNDS_MIN; | ||
| 232 | 		else if (u > ROUNDS_MAX) | ||
| 233 | 			return 0; | ||
| 234 | 		else | ||
| 235 | 			r = u; | ||
| 236 | 		/* needed when rounds is zero prefixed or out of bounds */ | ||
| 237 | 		sprintf(rounds, "rounds=%u$", r); | ||
| 238 | 	} | ||
| 239 | |||
| 240 | 	for (i = 0; i < SALT_MAX && salt[i] && salt[i] != '$'; i++) | ||
| 241 | 		/* reject characters that interfere with /etc/shadow parsing */ | ||
| 242 | 		if (salt[i] == '\n' || salt[i] == ':') | ||
| 243 | 			return 0; | ||
| 244 | 	slen = i; | ||
| 245 | |||
| 246 | 	/* B = sha(key salt key) */ | ||
| 247 | 	sha256_init(&ctx); | ||
| 248 | 	sha256_update(&ctx, key, klen); | ||
| 249 | 	sha256_update(&ctx, salt, slen); | ||
| 250 | 	sha256_update(&ctx, key, klen); | ||
| 251 | 	sha256_sum(&ctx, md); | ||
| 252 | |||
| 253 | 	/* A = sha(key salt repeat-B alternate-B-key) */ | ||
| 254 | 	sha256_init(&ctx); | ||
| 255 | 	sha256_update(&ctx, key, klen); | ||
| 256 | 	sha256_update(&ctx, salt, slen); | ||
| 257 | 	hashmd(&ctx, klen, md); | ||
| 258 | 	for (i = klen; i > 0; i >>= 1) | ||
| 259 | 		if (i & 1) | ||
| 260 | 			sha256_update(&ctx, md, sizeof md); | ||
| 261 | 		else | ||
| 262 | 			sha256_update(&ctx, key, klen); | ||
| 263 | 	sha256_sum(&ctx, md); | ||
| 264 | |||
| 265 | 	/* DP = sha(repeat-key), this step takes O(klen^2) time */ | ||
| 266 | 	sha256_init(&ctx); | ||
| 267 | 	for (i = 0; i < klen; i++) | ||
| 268 | 		sha256_update(&ctx, key, klen); | ||
| 269 | 	sha256_sum(&ctx, kmd); | ||
| 270 | |||
| 271 | 	/* DS = sha(repeat-salt) */ | ||
| 272 | 	sha256_init(&ctx); | ||
| 273 | 	for (i = 0; i < 16 + md[0]; i++) | ||
| 274 | 		sha256_update(&ctx, salt, slen); | ||
| 275 | 	sha256_sum(&ctx, smd); | ||
| 276 | |||
| 277 | 	/* iterate A = f(A,DP,DS), this step takes O(rounds*klen) time */ | ||
| 278 | 	for (i = 0; i < r; i++) { | ||
| 279 | 		sha256_init(&ctx); | ||
| 280 | 		if (i % 2) | ||
| 281 | 			hashmd(&ctx, klen, kmd); | ||
| 282 | 		else | ||
| 283 | 			sha256_update(&ctx, md, sizeof md); | ||
| 284 | 		if (i % 3) | ||
| 285 | 			sha256_update(&ctx, smd, slen); | ||
| 286 | 		if (i % 7) | ||
| 287 | 			hashmd(&ctx, klen, kmd); | ||
| 288 | 		if (i % 2) | ||
| 289 | 			sha256_update(&ctx, md, sizeof md); | ||
| 290 | 		else | ||
| 291 | 			hashmd(&ctx, klen, kmd); | ||
| 292 | 		sha256_sum(&ctx, md); | ||
| 293 | 	} | ||
| 294 | |||
| 295 | 	/* output is $5$rounds=n$salt$hash */ | ||
| 296 | 	p = output; | ||
| 297 | 	p += sprintf(p, "$5$%s%.*s$", rounds, slen, salt); | ||
| 298 | 	static const unsigned char perm[][3] = { | ||
| 299 | 		0,10,20,21,1,11,12,22,2,3,13,23,24,4,14, | ||
| 300 | 		15,25,5,6,16,26,27,7,17,18,28,8,9,19,29 }; | ||
| 301 | 	for (i=0; i<10; i++) p = to64(p, | ||
| 302 | 		(md[perm[i][0]]<<16)|(md[perm[i][1]]<<8)|md[perm[i][2]], 4); | ||
| 303 | 	p = to64(p, (md[31]<<8)|md[30], 3); | ||
| 304 | 	*p = 0; | ||
| 305 | 	return output; | ||
| 306 | } | ||
| 307 | |||
| 308 | char *__crypt_sha256(const char *key, const char *setting, char *output) | ||
| 309 | { | ||
| 310 | 	static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"; | ||
| 311 | 	static const char testsetting[] = "$5$rounds=1234$abc0123456789$"; | ||
| 312 | 	static const char testhash[] = "$5$rounds=1234$abc0123456789$3VfDjPt05VHFn47C/ojFZ6KRPYrOjj1lLbH.dkF3bZ6"; | ||
| 313 | 	char testbuf[128]; | ||
| 314 | 	char *p, *q; | ||
| 315 | |||
| 316 | 	p = sha256crypt(key, setting, output); | ||
| 317 | 	/* self test and stack cleanup */ | ||
| 318 | 	q = sha256crypt(testkey, testsetting, testbuf); | ||
| 319 | 	if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) | ||
| 320 | 		return "*"; | ||
| 321 | 	return p; | ||
| 322 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/crypt_sha512.c created+371| ... | @@ -0,0 +1,371 @@ | ||
| 1 | /* | ||
| 2 | * public domain sha512 crypt implementation | ||
| 3 | * | ||
| 4 | * original sha crypt design: http://people.redhat.com/drepper/SHA-crypt.txt | ||
| 5 | * in this implementation at least 32bit int is assumed, | ||
| 6 | * key length is limited, the $6$ prefix is mandatory, '\n' and ':' is rejected | ||
| 7 | * in the salt and rounds= setting must contain a valid iteration count, | ||
| 8 | * on error "*" is returned. | ||
| 9 | */ | ||
| 10 | #include <ctype.h> | ||
| 11 | #include <stdlib.h> | ||
| 12 | #include <stdio.h> | ||
| 13 | #include <string.h> | ||
| 14 | #include <stdint.h> | ||
| 15 | |||
| 16 | /* public domain sha512 implementation based on fips180-3 */ | ||
| 17 | /* >=2^64 bits messages are not supported (about 2000 peta bytes) */ | ||
| 18 | |||
| 19 | struct sha512 { | ||
| 20 | 	uint64_t len; /* processed message length */ | ||
| 21 | 	uint64_t h[8]; /* hash state */ | ||
| 22 | 	uint8_t buf[128]; /* message block buffer */ | ||
| 23 | }; | ||
| 24 | |||
| 25 | static uint64_t ror(uint64_t n, int k) { return (n >> k) | (n << (64-k)); } | ||
| 26 | #define Ch(x,y,z) (z ^ (x & (y ^ z))) | ||
| 27 | #define Maj(x,y,z) ((x & y) | (z & (x | y))) | ||
| 28 | #define S0(x) (ror(x,28) ^ ror(x,34) ^ ror(x,39)) | ||
| 29 | #define S1(x) (ror(x,14) ^ ror(x,18) ^ ror(x,41)) | ||
| 30 | #define R0(x) (ror(x,1) ^ ror(x,8) ^ (x>>7)) | ||
| 31 | #define R1(x) (ror(x,19) ^ ror(x,61) ^ (x>>6)) | ||
| 32 | |||
| 33 | static const uint64_t K[80] = { | ||
| 34 | 0x428a2f98d728ae22ULL, 0x7137449123ef65cdULL, 0xb5c0fbcfec4d3b2fULL, 0xe9b5dba58189dbbcULL, | ||
| 35 | 0x3956c25bf348b538ULL, 0x59f111f1b605d019ULL, 0x923f82a4af194f9bULL, 0xab1c5ed5da6d8118ULL, | ||
| 36 | 0xd807aa98a3030242ULL, 0x12835b0145706fbeULL, 0x243185be4ee4b28cULL, 0x550c7dc3d5ffb4e2ULL, | ||
| 37 | 0x72be5d74f27b896fULL, 0x80deb1fe3b1696b1ULL, 0x9bdc06a725c71235ULL, 0xc19bf174cf692694ULL, | ||
| 38 | 0xe49b69c19ef14ad2ULL, 0xefbe4786384f25e3ULL, 0x0fc19dc68b8cd5b5ULL, 0x240ca1cc77ac9c65ULL, | ||
| 39 | 0x2de92c6f592b0275ULL, 0x4a7484aa6ea6e483ULL, 0x5cb0a9dcbd41fbd4ULL, 0x76f988da831153b5ULL, | ||
| 40 | 0x983e5152ee66dfabULL, 0xa831c66d2db43210ULL, 0xb00327c898fb213fULL, 0xbf597fc7beef0ee4ULL, | ||
| 41 | 0xc6e00bf33da88fc2ULL, 0xd5a79147930aa725ULL, 0x06ca6351e003826fULL, 0x142929670a0e6e70ULL, | ||
| 42 | 0x27b70a8546d22ffcULL, 0x2e1b21385c26c926ULL, 0x4d2c6dfc5ac42aedULL, 0x53380d139d95b3dfULL, | ||
| 43 | 0x650a73548baf63deULL, 0x766a0abb3c77b2a8ULL, 0x81c2c92e47edaee6ULL, 0x92722c851482353bULL, | ||
| 44 | 0xa2bfe8a14cf10364ULL, 0xa81a664bbc423001ULL, 0xc24b8b70d0f89791ULL, 0xc76c51a30654be30ULL, | ||
| 45 | 0xd192e819d6ef5218ULL, 0xd69906245565a910ULL, 0xf40e35855771202aULL, 0x106aa07032bbd1b8ULL, | ||
| 46 | 0x19a4c116b8d2d0c8ULL, 0x1e376c085141ab53ULL, 0x2748774cdf8eeb99ULL, 0x34b0bcb5e19b48a8ULL, | ||
| 47 | 0x391c0cb3c5c95a63ULL, 0x4ed8aa4ae3418acbULL, 0x5b9cca4f7763e373ULL, 0x682e6ff3d6b2b8a3ULL, | ||
| 48 | 0x748f82ee5defb2fcULL, 0x78a5636f43172f60ULL, 0x84c87814a1f0ab72ULL, 0x8cc702081a6439ecULL, | ||
| 49 | 0x90befffa23631e28ULL, 0xa4506cebde82bde9ULL, 0xbef9a3f7b2c67915ULL, 0xc67178f2e372532bULL, | ||
| 50 | 0xca273eceea26619cULL, 0xd186b8c721c0c207ULL, 0xeada7dd6cde0eb1eULL, 0xf57d4f7fee6ed178ULL, | ||
| 51 | 0x06f067aa72176fbaULL, 0x0a637dc5a2c898a6ULL, 0x113f9804bef90daeULL, 0x1b710b35131c471bULL, | ||
| 52 | 0x28db77f523047d84ULL, 0x32caab7b40c72493ULL, 0x3c9ebe0a15c9bebcULL, 0x431d67c49c100d4cULL, | ||
| 53 | 0x4cc5d4becb3e42b6ULL, 0x597f299cfc657e2aULL, 0x5fcb6fab3ad6faecULL, 0x6c44198c4a475817ULL | ||
| 54 | }; | ||
| 55 | |||
| 56 | static void processblock(struct sha512 *s, const uint8_t *buf) | ||
| 57 | { | ||
| 58 | 	uint64_t W[80], t1, t2, a, b, c, d, e, f, g, h; | ||
| 59 | 	int i; | ||
| 60 | |||
| 61 | 	for (i = 0; i < 16; i++) { | ||
| 62 | 		W[i] = (uint64_t)buf[8*i]<<56; | ||
| 63 | 		W[i] |= (uint64_t)buf[8*i+1]<<48; | ||
| 64 | 		W[i] |= (uint64_t)buf[8*i+2]<<40; | ||
| 65 | 		W[i] |= (uint64_t)buf[8*i+3]<<32; | ||
| 66 | 		W[i] |= (uint64_t)buf[8*i+4]<<24; | ||
| 67 | 		W[i] |= (uint64_t)buf[8*i+5]<<16; | ||
| 68 | 		W[i] |= (uint64_t)buf[8*i+6]<<8; | ||
| 69 | 		W[i] |= buf[8*i+7]; | ||
| 70 | 	} | ||
| 71 | 	for (; i < 80; i++) | ||
| 72 | 		W[i] = R1(W[i-2]) + W[i-7] + R0(W[i-15]) + W[i-16]; | ||
| 73 | 	a = s->h[0]; | ||
| 74 | 	b = s->h[1]; | ||
| 75 | 	c = s->h[2]; | ||
| 76 | 	d = s->h[3]; | ||
| 77 | 	e = s->h[4]; | ||
| 78 | 	f = s->h[5]; | ||
| 79 | 	g = s->h[6]; | ||
| 80 | 	h = s->h[7]; | ||
| 81 | 	for (i = 0; i < 80; i++) { | ||
| 82 | 		t1 = h + S1(e) + Ch(e,f,g) + K[i] + W[i]; | ||
| 83 | 		t2 = S0(a) + Maj(a,b,c); | ||
| 84 | 		h = g; | ||
| 85 | 		g = f; | ||
| 86 | 		f = e; | ||
| 87 | 		e = d + t1; | ||
| 88 | 		d = c; | ||
| 89 | 		c = b; | ||
| 90 | 		b = a; | ||
| 91 | 		a = t1 + t2; | ||
| 92 | 	} | ||
| 93 | 	s->h[0] += a; | ||
| 94 | 	s->h[1] += b; | ||
| 95 | 	s->h[2] += c; | ||
| 96 | 	s->h[3] += d; | ||
| 97 | 	s->h[4] += e; | ||
| 98 | 	s->h[5] += f; | ||
| 99 | 	s->h[6] += g; | ||
| 100 | 	s->h[7] += h; | ||
| 101 | } | ||
| 102 | |||
| 103 | static void pad(struct sha512 *s) | ||
| 104 | { | ||
| 105 | 	unsigned r = s->len % 128; | ||
| 106 | |||
| 107 | 	s->buf[r++] = 0x80; | ||
| 108 | 	if (r > 112) { | ||
| 109 | 		memset(s->buf + r, 0, 128 - r); | ||
| 110 | 		r = 0; | ||
| 111 | 		processblock(s, s->buf); | ||
| 112 | 	} | ||
| 113 | 	memset(s->buf + r, 0, 120 - r); | ||
| 114 | 	s->len *= 8; | ||
| 115 | 	s->buf[120] = s->len >> 56; | ||
| 116 | 	s->buf[121] = s->len >> 48; | ||
| 117 | 	s->buf[122] = s->len >> 40; | ||
| 118 | 	s->buf[123] = s->len >> 32; | ||
| 119 | 	s->buf[124] = s->len >> 24; | ||
| 120 | 	s->buf[125] = s->len >> 16; | ||
| 121 | 	s->buf[126] = s->len >> 8; | ||
| 122 | 	s->buf[127] = s->len; | ||
| 123 | 	processblock(s, s->buf); | ||
| 124 | } | ||
| 125 | |||
| 126 | static void sha512_init(struct sha512 *s) | ||
| 127 | { | ||
| 128 | 	s->len = 0; | ||
| 129 | 	s->h[0] = 0x6a09e667f3bcc908ULL; | ||
| 130 | 	s->h[1] = 0xbb67ae8584caa73bULL; | ||
| 131 | 	s->h[2] = 0x3c6ef372fe94f82bULL; | ||
| 132 | 	s->h[3] = 0xa54ff53a5f1d36f1ULL; | ||
| 133 | 	s->h[4] = 0x510e527fade682d1ULL; | ||
| 134 | 	s->h[5] = 0x9b05688c2b3e6c1fULL; | ||
| 135 | 	s->h[6] = 0x1f83d9abfb41bd6bULL; | ||
| 136 | 	s->h[7] = 0x5be0cd19137e2179ULL; | ||
| 137 | } | ||
| 138 | |||
| 139 | static void sha512_sum(struct sha512 *s, uint8_t *md) | ||
| 140 | { | ||
| 141 | 	int i; | ||
| 142 | |||
| 143 | 	pad(s); | ||
| 144 | 	for (i = 0; i < 8; i++) { | ||
| 145 | 		md[8*i] = s->h[i] >> 56; | ||
| 146 | 		md[8*i+1] = s->h[i] >> 48; | ||
| 147 | 		md[8*i+2] = s->h[i] >> 40; | ||
| 148 | 		md[8*i+3] = s->h[i] >> 32; | ||
| 149 | 		md[8*i+4] = s->h[i] >> 24; | ||
| 150 | 		md[8*i+5] = s->h[i] >> 16; | ||
| 151 | 		md[8*i+6] = s->h[i] >> 8; | ||
| 152 | 		md[8*i+7] = s->h[i]; | ||
| 153 | 	} | ||
| 154 | } | ||
| 155 | |||
| 156 | static void sha512_update(struct sha512 *s, const void *m, unsigned long len) | ||
| 157 | { | ||
| 158 | 	const uint8_t *p = m; | ||
| 159 | 	unsigned r = s->len % 128; | ||
| 160 | |||
| 161 | 	s->len += len; | ||
| 162 | 	if (r) { | ||
| 163 | 		if (len < 128 - r) { | ||
| 164 | 			memcpy(s->buf + r, p, len); | ||
| 165 | 			return; | ||
| 166 | 		} | ||
| 167 | 		memcpy(s->buf + r, p, 128 - r); | ||
| 168 | 		len -= 128 - r; | ||
| 169 | 		p += 128 - r; | ||
| 170 | 		processblock(s, s->buf); | ||
| 171 | 	} | ||
| 172 | 	for (; len >= 128; len -= 128, p += 128) | ||
| 173 | 		processblock(s, p); | ||
| 174 | 	memcpy(s->buf, p, len); | ||
| 175 | } | ||
| 176 | |||
| 177 | static const unsigned char b64[] = | ||
| 178 | "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
| 179 | |||
| 180 | static char *to64(char *s, unsigned int u, int n) | ||
| 181 | { | ||
| 182 | 	while (--n >= 0) { | ||
| 183 | 		*s++ = b64[u % 64]; | ||
| 184 | 		u /= 64; | ||
| 185 | 	} | ||
| 186 | 	return s; | ||
| 187 | } | ||
| 188 | |||
| 189 | /* key limit is not part of the original design, added for DoS protection. | ||
| 190 | * rounds limit has been lowered (versus the reference/spec), also for DoS | ||
| 191 | * protection. runtime is O(klen^2 + klen*rounds) */ | ||
| 192 | #define KEY_MAX 256 | ||
| 193 | #define SALT_MAX 16 | ||
| 194 | #define ROUNDS_DEFAULT 5000 | ||
| 195 | #define ROUNDS_MIN 1000 | ||
| 196 | #define ROUNDS_MAX 9999999 | ||
| 197 | |||
| 198 | /* hash n bytes of the repeated md message digest */ | ||
| 199 | static void hashmd(struct sha512 *s, unsigned int n, const void *md) | ||
| 200 | { | ||
| 201 | 	unsigned int i; | ||
| 202 | |||
| 203 | 	for (i = n; i > 64; i -= 64) | ||
| 204 | 		sha512_update(s, md, 64); | ||
| 205 | 	sha512_update(s, md, i); | ||
| 206 | } | ||
| 207 | |||
| 208 | static char *sha512crypt(const char *key, const char *setting, char *output) | ||
| 209 | { | ||
| 210 | 	struct sha512 ctx; | ||
| 211 | 	unsigned char md[64], kmd[64], smd[64]; | ||
| 212 | 	unsigned int i, r, klen, slen; | ||
| 213 | 	char rounds[20] = ""; | ||
| 214 | 	const char *salt; | ||
| 215 | 	char *p; | ||
| 216 | |||
| 217 | 	/* reject large keys */ | ||
| 218 | 	for (i = 0; i <= KEY_MAX && key[i]; i++); | ||
| 219 | 	if (i > KEY_MAX) | ||
| 220 | 		return 0; | ||
| 221 | 	klen = i; | ||
| 222 | |||
| 223 | 	/* setting: $6$rounds=n$salt$ (rounds=n$ and closing $ are optional) */ | ||
| 224 | 	if (strncmp(setting, "$6$", 3) != 0) | ||
| 225 | 		return 0; | ||
| 226 | 	salt = setting + 3; | ||
| 227 | |||
| 228 | 	r = ROUNDS_DEFAULT; | ||
| 229 | 	if (strncmp(salt, "rounds=", sizeof "rounds=" - 1) == 0) { | ||
| 230 | 		unsigned long u; | ||
| 231 | 		char *end; | ||
| 232 | |||
| 233 | 		/* | ||
| 234 | 		 * this is a deviation from the reference: | ||
| 235 | 		 * bad rounds setting is rejected if it is | ||
| 236 | 		 * - empty | ||
| 237 | 		 * - unterminated (missing '$') | ||
| 238 | 		 * - begins with anything but a decimal digit | ||
| 239 | 		 * the reference implementation treats these bad | ||
| 240 | 		 * rounds as part of the salt or parse them with | ||
| 241 | 		 * strtoul semantics which may cause problems | ||
| 242 | 		 * including non-portable hashes that depend on | ||
| 243 | 		 * the host's value of ULONG_MAX. | ||
| 244 | 		 */ | ||
| 245 | 		salt += sizeof "rounds=" - 1; | ||
| 246 | 		if (!isdigit(*salt)) | ||
| 247 | 			return 0; | ||
| 248 | 		u = strtoul(salt, &end, 10); | ||
| 249 | 		if (*end != '$') | ||
| 250 | 			return 0; | ||
| 251 | 		salt = end+1; | ||
| 252 | 		if (u < ROUNDS_MIN) | ||
| 253 | 			r = ROUNDS_MIN; | ||
| 254 | 		else if (u > ROUNDS_MAX) | ||
| 255 | 			return 0; | ||
| 256 | 		else | ||
| 257 | 			r = u; | ||
| 258 | 		/* needed when rounds is zero prefixed or out of bounds */ | ||
| 259 | 		sprintf(rounds, "rounds=%u$", r); | ||
| 260 | 	} | ||
| 261 | |||
| 262 | 	for (i = 0; i < SALT_MAX && salt[i] && salt[i] != '$'; i++) | ||
| 263 | 		/* reject characters that interfere with /etc/shadow parsing */ | ||
| 264 | 		if (salt[i] == '\n' || salt[i] == ':') | ||
| 265 | 			return 0; | ||
| 266 | 	slen = i; | ||
| 267 | |||
| 268 | 	/* B = sha(key salt key) */ | ||
| 269 | 	sha512_init(&ctx); | ||
| 270 | 	sha512_update(&ctx, key, klen); | ||
| 271 | 	sha512_update(&ctx, salt, slen); | ||
| 272 | 	sha512_update(&ctx, key, klen); | ||
| 273 | 	sha512_sum(&ctx, md); | ||
| 274 | |||
| 275 | 	/* A = sha(key salt repeat-B alternate-B-key) */ | ||
| 276 | 	sha512_init(&ctx); | ||
| 277 | 	sha512_update(&ctx, key, klen); | ||
| 278 | 	sha512_update(&ctx, salt, slen); | ||
| 279 | 	hashmd(&ctx, klen, md); | ||
| 280 | 	for (i = klen; i > 0; i >>= 1) | ||
| 281 | 		if (i & 1) | ||
| 282 | 			sha512_update(&ctx, md, sizeof md); | ||
| 283 | 		else | ||
| 284 | 			sha512_update(&ctx, key, klen); | ||
| 285 | 	sha512_sum(&ctx, md); | ||
| 286 | |||
| 287 | 	/* DP = sha(repeat-key), this step takes O(klen^2) time */ | ||
| 288 | 	sha512_init(&ctx); | ||
| 289 | 	for (i = 0; i < klen; i++) | ||
| 290 | 		sha512_update(&ctx, key, klen); | ||
| 291 | 	sha512_sum(&ctx, kmd); | ||
| 292 | |||
| 293 | 	/* DS = sha(repeat-salt) */ | ||
| 294 | 	sha512_init(&ctx); | ||
| 295 | 	for (i = 0; i < 16 + md[0]; i++) | ||
| 296 | 		sha512_update(&ctx, salt, slen); | ||
| 297 | 	sha512_sum(&ctx, smd); | ||
| 298 | |||
| 299 | 	/* iterate A = f(A,DP,DS), this step takes O(rounds*klen) time */ | ||
| 300 | 	for (i = 0; i < r; i++) { | ||
| 301 | 		sha512_init(&ctx); | ||
| 302 | 		if (i % 2) | ||
| 303 | 			hashmd(&ctx, klen, kmd); | ||
| 304 | 		else | ||
| 305 | 			sha512_update(&ctx, md, sizeof md); | ||
| 306 | 		if (i % 3) | ||
| 307 | 			sha512_update(&ctx, smd, slen); | ||
| 308 | 		if (i % 7) | ||
| 309 | 			hashmd(&ctx, klen, kmd); | ||
| 310 | 		if (i % 2) | ||
| 311 | 			sha512_update(&ctx, md, sizeof md); | ||
| 312 | 		else | ||
| 313 | 			hashmd(&ctx, klen, kmd); | ||
| 314 | 		sha512_sum(&ctx, md); | ||
| 315 | 	} | ||
| 316 | |||
| 317 | 	/* output is $6$rounds=n$salt$hash */ | ||
| 318 | 	p = output; | ||
| 319 | 	p += sprintf(p, "$6$%s%.*s$", rounds, slen, salt); | ||
| 320 | #if 1 | ||
| 321 | 	static const unsigned char perm[][3] = { | ||
| 322 | 		0,21,42,22,43,1,44,2,23,3,24,45,25,46,4, | ||
| 323 | 		47,5,26,6,27,48,28,49,7,50,8,29,9,30,51, | ||
| 324 | 		31,52,10,53,11,32,12,33,54,34,55,13,56,14,35, | ||
| 325 | 		15,36,57,37,58,16,59,17,38,18,39,60,40,61,19, | ||
| 326 | 		62,20,41 }; | ||
| 327 | 	for (i=0; i<21; i++) p = to64(p, | ||
| 328 | 		(md[perm[i][0]]<<16)|(md[perm[i][1]]<<8)|md[perm[i][2]], 4); | ||
| 329 | #else | ||
| 330 | 	p = to64(p, (md[0]<<16)|(md[21]<<8)|md[42], 4); | ||
| 331 | 	p = to64(p, (md[22]<<16)|(md[43]<<8)|md[1], 4); | ||
| 332 | 	p = to64(p, (md[44]<<16)|(md[2]<<8)|md[23], 4); | ||
| 333 | 	p = to64(p, (md[3]<<16)|(md[24]<<8)|md[45], 4); | ||
| 334 | 	p = to64(p, (md[25]<<16)|(md[46]<<8)|md[4], 4); | ||
| 335 | 	p = to64(p, (md[47]<<16)|(md[5]<<8)|md[26], 4); | ||
| 336 | 	p = to64(p, (md[6]<<16)|(md[27]<<8)|md[48], 4); | ||
| 337 | 	p = to64(p, (md[28]<<16)|(md[49]<<8)|md[7], 4); | ||
| 338 | 	p = to64(p, (md[50]<<16)|(md[8]<<8)|md[29], 4); | ||
| 339 | 	p = to64(p, (md[9]<<16)|(md[30]<<8)|md[51], 4); | ||
| 340 | 	p = to64(p, (md[31]<<16)|(md[52]<<8)|md[10], 4); | ||
| 341 | 	p = to64(p, (md[53]<<16)|(md[11]<<8)|md[32], 4); | ||
| 342 | 	p = to64(p, (md[12]<<16)|(md[33]<<8)|md[54], 4); | ||
| 343 | 	p = to64(p, (md[34]<<16)|(md[55]<<8)|md[13], 4); | ||
| 344 | 	p = to64(p, (md[56]<<16)|(md[14]<<8)|md[35], 4); | ||
| 345 | 	p = to64(p, (md[15]<<16)|(md[36]<<8)|md[57], 4); | ||
| 346 | 	p = to64(p, (md[37]<<16)|(md[58]<<8)|md[16], 4); | ||
| 347 | 	p = to64(p, (md[59]<<16)|(md[17]<<8)|md[38], 4); | ||
| 348 | 	p = to64(p, (md[18]<<16)|(md[39]<<8)|md[60], 4); | ||
| 349 | 	p = to64(p, (md[40]<<16)|(md[61]<<8)|md[19], 4); | ||
| 350 | 	p = to64(p, (md[62]<<16)|(md[20]<<8)|md[41], 4); | ||
| 351 | #endif | ||
| 352 | 	p = to64(p, md[63], 2); | ||
| 353 | 	*p = 0; | ||
| 354 | 	return output; | ||
| 355 | } | ||
| 356 | |||
| 357 | char *__crypt_sha512(const char *key, const char *setting, char *output) | ||
| 358 | { | ||
| 359 | 	static const char testkey[] = "Xy01@#\x01\x02\x80\x7f\xff\r\n\x81\t !"; | ||
| 360 | 	static const char testsetting[] = "$6$rounds=1234$abc0123456789$"; | ||
| 361 | 	static const char testhash[] = "$6$rounds=1234$abc0123456789$BCpt8zLrc/RcyuXmCDOE1ALqMXB2MH6n1g891HhFj8.w7LxGv.FTkqq6Vxc/km3Y0jE0j24jY5PIv/oOu6reg1"; | ||
| 362 | 	char testbuf[128]; | ||
| 363 | 	char *p, *q; | ||
| 364 | |||
| 365 | 	p = sha512crypt(key, setting, output); | ||
| 366 | 	/* self test and stack cleanup */ | ||
| 367 | 	q = sha512crypt(testkey, testsetting, testbuf); | ||
| 368 | 	if (!p || q != testbuf || memcmp(testbuf, testhash, sizeof testhash)) | ||
| 369 | 		return "*"; | ||
| 370 | 	return p; | ||
| 371 | } | ||
lib/libc/wasi/libc-top-half/musl/src/crypt/encrypt.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | #include "crypt_des.h" | ||
| 6 | |||
| 7 | static struct expanded_key __encrypt_key; | ||
| 8 | |||
| 9 | void setkey(const char *key) | ||
| 10 | { | ||
| 11 | 	unsigned char bkey[8]; | ||
| 12 | 	int i, j; | ||
| 13 | |||
| 14 | 	for (i = 0; i < 8; i++) { | ||
| 15 | 		bkey[i] = 0; | ||
| 16 | 		for (j = 7; j >= 0; j--, key++) | ||
| 17 | 			bkey[i] |= (uint32_t)(*key & 1) << j; | ||
| 18 | 	} | ||
| 19 | |||
| 20 | 	__des_setkey(bkey, &__encrypt_key); | ||
| 21 | } | ||
| 22 | |||
| 23 | void encrypt(char *block, int edflag) | ||
| 24 | { | ||
| 25 | 	struct expanded_key decrypt_key, *key; | ||
| 26 | 	uint32_t b[2]; | ||
| 27 | 	int i, j; | ||
| 28 | 	char *p; | ||
| 29 | |||
| 30 | 	p = block; | ||
| 31 | 	for (i = 0; i < 2; i++) { | ||
| 32 | 		b[i] = 0; | ||
| 33 | 		for (j = 31; j >= 0; j--, p++) | ||
| 34 | 			b[i] |= (uint32_t)(*p & 1) << j; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	key = &__encrypt_key; | ||
| 38 | 	if (edflag) { | ||
| 39 | 		key = &decrypt_key; | ||
| 40 | 		for (i = 0; i < 16; i++) { | ||
| 41 | 			decrypt_key.l[i] = __encrypt_key.l[15-i]; | ||
| 42 | 			decrypt_key.r[i] = __encrypt_key.r[15-i]; | ||
| 43 | 		} | ||
| 44 | 	} | ||
| 45 | |||
| 46 | 	__do_des(b[0], b[1], b, b + 1, 1, 0, key); | ||
| 47 | |||
| 48 | 	p = block; | ||
| 49 | 	for (i = 0; i < 2; i++) | ||
| 50 | 		for (j = 31; j >= 0; j--) | ||
| 51 | 			*p++ = b[i]>>j & 1; | ||
| 52 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/__ctype_b_loc.c created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #include <endian.h> | ||
| 2 | |||
| 3 | #if __BYTE_ORDER == __BIG_ENDIAN | ||
| 4 | #define X(x) x | ||
| 5 | #else | ||
| 6 | #define X(x) (((x)/256 | (x)*256) % 65536) | ||
| 7 | #endif | ||
| 8 | |||
| 9 | static const unsigned short table[] = { | ||
| 10 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 11 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 12 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 13 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 14 | X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200), | ||
| 15 | X(0x200),X(0x320),X(0x220),X(0x220),X(0x220),X(0x220),X(0x200),X(0x200), | ||
| 16 | X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200), | ||
| 17 | X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200),X(0x200), | ||
| 18 | X(0x160),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), | ||
| 19 | X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), | ||
| 20 | X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8),X(0x8d8), | ||
| 21 | X(0x8d8),X(0x8d8),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), | ||
| 22 | X(0x4c0),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8d5),X(0x8c5), | ||
| 23 | X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5), | ||
| 24 | X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5),X(0x8c5), | ||
| 25 | X(0x8c5),X(0x8c5),X(0x8c5),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0), | ||
| 26 | X(0x4c0),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8d6),X(0x8c6), | ||
| 27 | X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6), | ||
| 28 | X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6),X(0x8c6), | ||
| 29 | X(0x8c6),X(0x8c6),X(0x8c6),X(0x4c0),X(0x4c0),X(0x4c0),X(0x4c0),X(0x200), | ||
| 30 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 31 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 32 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 33 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 34 | }; | ||
| 35 | |||
| 36 | static const unsigned short *const ptable = table+128; | ||
| 37 | |||
| 38 | const unsigned short **__ctype_b_loc(void) | ||
| 39 | { | ||
| 40 | 	return (void *)&ptable; | ||
| 41 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/__ctype_get_mb_cur_max.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include "locale_impl.h" | ||
| 3 | |||
| 4 | size_t __ctype_get_mb_cur_max() | ||
| 5 | { | ||
| 6 | 	return MB_CUR_MAX; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/__ctype_tolower_loc.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | |||
| 3 | static const int32_t table[] = { | ||
| 4 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 5 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 6 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 7 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 8 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, | ||
| 9 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, | ||
| 10 | 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, | ||
| 11 | 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, | ||
| 12 | 64, | ||
| 13 | 'a','b','c','d','e','f','g','h','i','j','k','l','m', | ||
| 14 | 'n','o','p','q','r','s','t','u','v','w','x','y','z', | ||
| 15 | 91,92,93,94,95,96, | ||
| 16 | 'a','b','c','d','e','f','g','h','i','j','k','l','m', | ||
| 17 | 'n','o','p','q','r','s','t','u','v','w','x','y','z', | ||
| 18 | 123,124,125,126,127, | ||
| 19 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 20 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 21 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 23 | }; | ||
| 24 | |||
| 25 | static const int32_t *const ptable = table+128; | ||
| 26 | |||
| 27 | const int32_t **__ctype_tolower_loc(void) | ||
| 28 | { | ||
| 29 | 	return (void *)&ptable; | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/__ctype_toupper_loc.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | |||
| 3 | static const int32_t table[] = { | ||
| 4 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 5 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 6 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 7 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 8 | 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15, | ||
| 9 | 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31, | ||
| 10 | 32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47, | ||
| 11 | 48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63, | ||
| 12 | 64, | ||
| 13 | 'A','B','C','D','E','F','G','H','I','J','K','L','M', | ||
| 14 | 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', | ||
| 15 | 91,92,93,94,95,96, | ||
| 16 | 'A','B','C','D','E','F','G','H','I','J','K','L','M', | ||
| 17 | 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', | ||
| 18 | 123,124,125,126,127, | ||
| 19 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 20 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 21 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 22 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 23 | }; | ||
| 24 | |||
| 25 | static const int32_t *const ptable = table+128; | ||
| 26 | |||
| 27 | const int32_t **__ctype_toupper_loc(void) | ||
| 28 | { | ||
| 29 | 	return (void *)&ptable; | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/alpha.h created+172| ... | @@ -0,0 +1,172 @@ | ||
| 1 | 18,17,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,17,34,35,36,17,37,38,39,40, | ||
| 2 | 41,42,43,44,17,45,46,47,16,16,48,16,16,16,16,16,16,16,49,50,51,16,52,53,16,16, | ||
| 3 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,54, | ||
| 4 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 5 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 6 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 7 | 17,17,17,55,17,17,17,17,56,17,57,58,59,60,61,62,17,17,17,17,17,17,17,17,17,17, | ||
| 8 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 9 | 17,17,17,17,17,17,17,63,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 10 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,64,65,17,66,67, | ||
| 11 | 68,69,70,71,72,73,74,17,75,76,77,78,79,80,81,16,82,83,84,85,86,87,88,89,90,91, | ||
| 12 | 92,93,16,94,95,96,16,17,17,17,97,98,99,16,16,16,16,16,16,16,16,16,16,17,17,17, | ||
| 13 | 17,100,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,101,16,16,16,16,16, | ||
| 14 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 15 | 16,16,17,17,102,103,16,16,104,105,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 16 | 17,17,17,17,17,17,17,17,17,106,17,17,107,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 17 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17, | ||
| 18 | 108,109,16,16,16,16,16,16,16,16,16,110,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 19 | 16,16,16,16,16,16,16,16,16,16,111,112,113,114,16,16,16,16,16,16,16,16,115,116, | ||
| 20 | 117,16,16,16,16,16,118,119,16,16,16,16,120,16,16,121,16,16,16,16,16,16,16,16, | ||
| 21 | 16,16,16,16,16, | ||
| 22 | 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, | ||
| 23 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 24 | 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,254,255,255,7,254, | ||
| 25 | 255,255,7,0,0,0,0,0,4,32,4,255,255,127,255,255,255,127,255,255,255,255,255, | ||
| 26 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 27 | 255,195,255,3,0,31,80,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,223,188,64,215,255,255, | ||
| 28 | 251,255,255,255,255,255,255,255,255,255,191,255,255,255,255,255,255,255,255, | ||
| 29 | 255,255,255,255,255,255,255,255,255,3,252,255,255,255,255,255,255,255,255,255, | ||
| 30 | 255,255,255,255,255,255,255,255,255,255,255,254,255,255,255,127,2,255,255,255, | ||
| 31 | 255,255,1,0,0,0,0,255,191,182,0,255,255,255,135,7,0,0,0,255,7,255,255,255,255, | ||
| 32 | 255,255,255,254,255,195,255,255,255,255,255,255,255,255,255,255,255,255,239, | ||
| 33 | 31,254,225,255, | ||
| 34 | 159,0,0,255,255,255,255,255,255,0,224,255,255,255,255,255,255,255,255,255,255, | ||
| 35 | 255,255,3,0,255,255,255,255,255,7,48,4,255,255,255,252,255,31,0,0,255,255,255, | ||
| 36 | 1,255,7,0,0,0,0,0,0,255,255,223,63,0,0,240,255,248,3,255,255,255,255,255,255, | ||
| 37 | 255,255,255,239,255,223,225,255,207,255,254,255,239,159,249,255,255,253,197, | ||
| 38 | 227,159,89,128,176,207,255,3,16,238,135,249,255,255,253,109,195,135,25,2,94, | ||
| 39 | 192,255,63,0,238,191,251,255,255,253,237,227,191,27,1,0,207,255,0,30,238,159, | ||
| 40 | 249,255,255,253,237,227,159,25,192,176,207,255,2,0,236,199,61,214,24,199,255, | ||
| 41 | 195,199,29,129,0,192,255,0,0,239,223,253,255,255,253,255,227,223,29,96,7,207, | ||
| 42 | 255,0,0,239,223,253,255,255,253,239,227,223,29,96,64,207,255,6,0,239,223,253, | ||
| 43 | 255,255,255,255,231,223,93,240,128,207,255,0,252,236,255,127,252,255,255,251, | ||
| 44 | 47,127,128,95,255,192,255,12,0,254,255,255,255,255,127,255,7,63,32,255,3,0,0, | ||
| 45 | 0,0,214,247,255,255,175,255,255,59,95,32,255,243,0,0,0, | ||
| 46 | 0,1,0,0,0,255,3,0,0,255,254,255,255,255,31,254,255,3,255,255,254,255,255,255, | ||
| 47 | 31,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,249,255,3,255,255,255,255,255, | ||
| 48 | 255,255,255,255,63,255,255,255,255,191,32,255,255,255,255,255,247,255,255,255, | ||
| 49 | 255,255,255,255,255,255,61,127,61,255,255,255,255,255,61,255,255,255,255,61, | ||
| 50 | 127,61,255,127,255,255,255,255,255,255,255,61,255,255,255,255,255,255,255,255, | ||
| 51 | 7,0,0,0,0,255,255,0,0,255,255,255,255,255,255,255,255,255,255,63,63,254,255, | ||
| 52 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 53 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 54 | 255,255,255,255,255,159,255,255,254,255,255,7,255,255,255,255,255,255,255,255, | ||
| 55 | 255,199,255,1,255,223,15,0,255,255,15,0,255,255,15,0,255,223,13,0,255,255,255, | ||
| 56 | 255,255,255,207,255,255,1,128,16,255,3,0,0,0,0,255,3,255,255,255,255,255,255, | ||
| 57 | 255,255,255,255,255,1,255,255,255,255,255,7,255,255,255,255,255,255,255,255, | ||
| 58 | 63, | ||
| 59 | 0,255,255,255,127,255,15,255,1,192,255,255,255,255,63,31,0,255,255,255,255, | ||
| 60 | 255,15,255,255,255,3,255,3,0,0,0,0,255,255,255,15,255,255,255,255,255,255,255, | ||
| 61 | 127,254,255,31,0,255,3,255,3,128,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, | ||
| 62 | 255,239,255,239,15,255,3,0,0,0,0,255,255,255,255,255,243,255,255,255,255,255, | ||
| 63 | 255,191,255,3,0,255,255,255,255,255,255,127,0,255,227,255,255,255,255,255,63, | ||
| 64 | 255,1,255,255,255,255,255,231,0,0,0,0,0,222,111,4,255,255,255,255,255,255,255, | ||
| 65 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0, | ||
| 66 | 128,255,31,0,255,255,63,63,255,255,255,255,63,63,255,170,255,255,255,63,255, | ||
| 67 | 255,255,255,255,255,223,95,220,31,207,15,255,31,220,31,0,0,0,0,0,0,0,0,0,0,0, | ||
| 68 | 0,0,0,2,128,0,0,255,31,0,0,0,0,0,0,0,0,0,0,0,0,132,252,47,62,80,189,255,243, | ||
| 69 | 224,67,0,0,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 70 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,255,255,255,255,255,255,3,0, | ||
| 71 | 0,255,255,255,255,255,127,255,255,255,255,255,127,255,255,255,255,255,255,255, | ||
| 72 | 255,255,255,255,255,255,255,255,255,31,120,12,0,255,255,255,255,191,32,255, | ||
| 73 | 255,255,255,255,255,255,128,0,0,255,255,127,0,127,127,127,127,127,127,127,127, | ||
| 74 | 255,255,255,255,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 75 | 0,0,224,0,0,0,254,3,62,31,254,255,255,255,255,255,255,255,255,255,127,224,254, | ||
| 76 | 255,255,255,255,255,255,255,255,255,255,247,224,255,255,255,255,255,254,255, | ||
| 77 | 255,255,255,255,255,255,255,255,255,127,0,0,255,255,255,7,0,0,0,0,0,0,255,255, | ||
| 78 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 79 | 255,255,255,63,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255, | ||
| 80 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0, | ||
| 81 | 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0, | ||
| 82 | 0,0,0,0,0,0,255,255,255,255,255,63,255,31,255,255,255,15,0,0,255,255,255,255, | ||
| 83 | 255,127,240,143,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0, | ||
| 84 | 0,128,255,252,255,255,255,255,255,255,255,255,255,255,255,255,249,255,255,255, | ||
| 85 | 255,255,255,124,0,0,0,0,0,128,255,191,255,255,255,255,0,0,0,255,255,255,255, | ||
| 86 | 255,255,15,0,255,255,255,255,255,255,255,255,47,0,255,3,0,0,252,232,255,255, | ||
| 87 | 255,255,255,7,255,255,255,255,7,0,255,255,255,31,255,255,255,255,255,255,247, | ||
| 88 | 255,0,128,255,3,255,255,255,127,255,255,255,255,255,255,127,0,255,63,255,3, | ||
| 89 | 255,255,127,252,255,255,255,255,255,255,255,127,5,0,0,56,255,255,60,0,126,126, | ||
| 90 | 126,0,127,127,255,255,255,255,255,247,255,0,255,255,255,255,255,255,255,255, | ||
| 91 | 255,255,255,255,255,255,255,7,255,3,255,255,255,255,255,255,255,255,255,255, | ||
| 92 | 255,255,255,255,255,255,255,255,255,255,15,0,255,255,127,248,255,255,255,255, | ||
| 93 | 255, | ||
| 94 | 15,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255,255,255, | ||
| 95 | 255,255,255,255,255,255,255,255,3,0,0,0,0,127,0,248,224,255,253,127,95,219, | ||
| 96 | 255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0,0,248,255,255,255, | ||
| 97 | 255,255,255,255,255,255,255,255,255,63,0,0,255,255,255,255,255,255,255,255, | ||
| 98 | 252,255,255,255,255,255,255,0,0,0,0,0,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,223, | ||
| 99 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,31,0,0,255,3, | ||
| 100 | 254,255,255,7,254,255,255,7,192,255,255,255,255,255,255,255,255,255,255,127, | ||
| 101 | 252,252,252,28,0,0,0,0,255,239,255,255,127,255,255,183,255,63,255,63,0,0,0,0, | ||
| 102 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,7,0,0,0,0,0,0,0,0, | ||
| 103 | 255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 104 | 0,0,0,0,0,0,0,0,255,255,255,31,255,255,255,255,255,255,1,0,0,0,0, | ||
| 105 | 0,255,255,255,255,0,224,255,255,255,7,255,255,255,255,255,7,255,255,255,63, | ||
| 106 | 255,255,255,255,15,255,62,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255, | ||
| 107 | 255,255,255,255,255,255,255,255,255,63,255,3,255,255,255,255,15,255,255,255, | ||
| 108 | 255,15,255,255,255,255,255,0,255,255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0, | ||
| 109 | 0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,255,255,63,0,255,0,0,0,0,0,0,0, | ||
| 110 | 0,0,0,0,0,0,0,0,0,0,0,0,63,253,255,255,255,255,191,145,255,255,63,0,255,255, | ||
| 111 | 127,0,255,255,255,127,0,0,0,0,0,0,0,0,255,255,55,0,255,255,63,0,255,255,255,3, | ||
| 112 | 0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,192,0,0,0,0,0,0,0,0,111,240,239, | ||
| 113 | 254,255,255,63,0,0,0,0,0,255,255,255,31,255,255,255,31,0,0,0,0,255,254,255, | ||
| 114 | 255,31,0,0,0,255,255,255,255,255,255,63,0,255,255,63,0,255,255,7,0,255,255,3, | ||
| 115 | 0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 116 | 0,255,255,255,255,255,255,255,255,255,1,0,0,0,0,0,0,255,255,255,255,255,255,7, | ||
| 117 | 0,255,255,255,255,255,255,7,0,255,255,255,255,255,0,255,3,0,0,0,0,0,0,0,0,0,0, | ||
| 118 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,31,128,0,255,255,63,0,0,0,0,0,0,0,0,0, | ||
| 119 | 0,0,0,0,0,0,0,0,0,0,255,255,127,0,255,255,255,255,255,255,255,255,63,0,0,0, | ||
| 120 | 192,255,0,0,252,255,255,255,255,255,255,1,0,0,255,255,255,1,255,3,255,255,255, | ||
| 121 | 255,255,255,199,255,112,0,255,255,255,255,71,0,255,255,255,255,255,255,255, | ||
| 122 | 255,30,0,255,23,0,0,0,0,255,255,251,255,255,255,159,64,0,0,0,0,0,0,0,0,127, | ||
| 123 | 189,255,191,255,1,255,255,255,255,255,255,255,1,255,3,239,159,249,255,255,253, | ||
| 124 | 237,227,159,25,129,224,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, | ||
| 125 | 255,255,255,255,255,187,7,255,131,0,0,0,0,255,255,255,255,255,255,255,255,179, | ||
| 126 | 0,255,3,0,0,0, | ||
| 127 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,63,127,0,0,0,63,0,0, | ||
| 128 | 0,0,255,255,255,255,255,255,255,127,17,0,255,3,0,0,0,0,255,255,255,255,255, | ||
| 129 | 255,63,1,255,3,0,0,0,0,0,0,255,255,255,231,255,7,255,3,0,0,0,0,0,0,0,0,0,0,0, | ||
| 130 | 0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0, | ||
| 131 | 0,255,255,255,255,255,255,255,255,255,3,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 132 | 0,0,0,0,255,252,255,255,255,255,255,252,26,0,0,0,255,255,255,255,255,255,231, | ||
| 133 | 127,0,0,255,255,255,255,255,255,255,255,255,32,0,0,0,0,255,255,255,255,255, | ||
| 134 | 255,255,1,255,253,255,255,255,255,127,127,1,0,255,3,0,0,252,255,255,255,252, | ||
| 135 | 255,255,254,127,0,0,0,0,0,0,0,0,0,127,251,255,255,255,255,127,180,203,0,255,3, | ||
| 136 | 191,253,255,255,255,127,123,1,255,3,0,0,0,0,0,0,0,0,0, | ||
| 137 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,127,0,255, | ||
| 138 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,3,0,0, | ||
| 139 | 0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,127,0, | ||
| 140 | 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 141 | 255,255,255,255,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, | ||
| 142 | 255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, | ||
| 143 | 255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255, | ||
| 144 | 255,255,255,255,255,255,1,255,255,255,127,255,3,0,0,0,0,0,0,0,0,0,0,0,0,255, | ||
| 145 | 255,255,63,0,0,255,255,255,255,255,255,0,0,15,0,255,3,248,255,255,224,255,255, | ||
| 146 | 0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 147 | 0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 148 | 0,0,255,255,255,255,255,255,255,255,255,135,255,255,255,255,255,255,255,128, | ||
| 149 | 255,255,0,0,0,0,0,0,0,0,11,0,0,0,255,255,255,255,255,255,255,255,255,255,255, | ||
| 150 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 151 | 255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 152 | 255,255,255,255,255,255,255,255,255,255,255,255,7,0,255,255,255,127,0,0,0,0,0, | ||
| 153 | 0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 154 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 155 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,15,255,255,255,255, | ||
| 156 | 255,255,255,255,255,255,255,255,255,7,255,31,255,1,255,67,0,0,0,0,0,0,0,0,0,0, | ||
| 157 | 0,0,255,255,255,255,255,255,255,255,255,255,223,255,255,255,255,255,255,255, | ||
| 158 | 255,223,100,222,255,235,239,255,255,255,255,255,255, | ||
| 159 | 255,191,231,223,223,255,255,255,123,95,252,253,255,255,255,255,255,255,255, | ||
| 160 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 161 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,63,255,255,255, | ||
| 162 | 253,255,255,247,255,255,255,247,255,255,223,255,255,255,223,255,255,127,255, | ||
| 163 | 255,255,127,255,255,255,253,255,255,255,253,255,255,247,207,255,255,255,255, | ||
| 164 | 255,255,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 165 | 0,0,255,255,255,255,255,31,128,63,255,67,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 166 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, | ||
| 167 | 15,255,3,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 168 | 255,255,255,255,255,255,255,31,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, | ||
| 169 | 143,8,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 170 | 0,239,255,255,255,150,254,247,10,132,234,150,170,150,247,247,94,255,251,255, | ||
| 171 | 15,238,251,255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,3,255,255,255,3,255, | ||
| 172 | 255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/casemap.h created+297| ... | @@ -0,0 +1,297 @@ | ||
| 1 | static const unsigned char tab[] = { | ||
| 2 | 	7, 8, 9, 10, 11, 12, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 3 | 	13, 6, 6, 14, 6, 6, 6, 6, 6, 6, 6, 6, 15, 16, 17, 18, | ||
| 4 | 	6, 19, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 20, 21, 6, 6, | ||
| 5 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 6 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 7 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 8 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 9 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 10 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 11 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 12 | 	6, 6, 6, 6, 6, 6, 22, 23, 6, 6, 6, 24, 6, 6, 6, 6, | ||
| 13 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 14 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 15 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 16 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 17 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 25, | ||
| 18 | 	6, 6, 6, 6, 26, 6, 6, 6, 6, 6, 6, 6, 27, 6, 6, 6, | ||
| 19 | 	6, 6, 6, 6, 6, 6, 6, 6, 28, 6, 6, 6, 6, 6, 6, 6, | ||
| 20 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 21 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 22 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 23 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 24 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 29, 6, | ||
| 25 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 26 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 27 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 28 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 29 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 30 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 31 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 32 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 30, 6, 6, 6, 6, 6, 6, | ||
| 33 | 	6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, | ||
| 34 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 35 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 36 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 37 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 38 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 39 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 40 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, | ||
| 41 | 	43, 43, 43, 43, 43, 43, 43, 43, 1, 0, 84, 86, 86, 86, 86, 86, | ||
| 42 | 	86, 86, 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 43 | 	0, 0, 0, 0, 0, 0, 24, 0, 0, 0, 43, 43, 43, 43, 43, 43, | ||
| 44 | 	43, 7, 43, 43, 91, 86, 86, 86, 86, 86, 86, 86, 74, 86, 86, 5, | ||
| 45 | 	49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, | ||
| 46 | 	36, 80, 121, 49, 80, 49, 80, 49, 56, 80, 49, 80, 49, 80, 49, 80, | ||
| 47 | 	49, 80, 49, 80, 49, 80, 49, 80, 78, 49, 2, 78, 13, 13, 78, 3, | ||
| 48 | 	78, 0, 36, 110, 0, 78, 49, 38, 110, 81, 78, 36, 80, 78, 57, 20, | ||
| 49 | 	129, 27, 29, 29, 83, 49, 80, 49, 80, 13, 49, 80, 49, 80, 49, 80, | ||
| 50 | 	27, 83, 36, 80, 49, 2, 92, 123, 92, 123, 92, 123, 92, 123, 92, 123, | ||
| 51 | 	20, 121, 92, 123, 92, 123, 92, 45, 43, 73, 3, 72, 3, 120, 92, 123, | ||
| 52 | 	20, 0, 150, 10, 1, 43, 40, 6, 6, 0, 42, 6, 42, 42, 43, 7, | ||
| 53 | 	187, 181, 43, 30, 0, 43, 7, 43, 43, 43, 1, 43, 43, 43, 43, 43, | ||
| 54 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 55 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 1, 43, 43, 43, 43, | ||
| 56 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 57 | 	43, 43, 43, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 58 | 	43, 205, 70, 205, 43, 0, 37, 43, 7, 1, 6, 1, 85, 86, 86, 86, | ||
| 59 | 	86, 86, 85, 86, 86, 2, 36, 129, 129, 129, 129, 129, 21, 129, 129, 129, | ||
| 60 | 	0, 0, 43, 0, 178, 209, 178, 209, 178, 209, 178, 209, 0, 0, 205, 204, | ||
| 61 | 	1, 0, 215, 215, 215, 215, 215, 131, 129, 129, 129, 129, 129, 129, 129, 129, | ||
| 62 | 	129, 129, 172, 172, 172, 172, 172, 172, 172, 172, 172, 172, 28, 0, 0, 0, | ||
| 63 | 	0, 0, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 2, 0, 0, | ||
| 64 | 	49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, | ||
| 65 | 	49, 80, 78, 49, 80, 49, 80, 78, 49, 80, 49, 80, 49, 80, 49, 80, | ||
| 66 | 	49, 80, 49, 80, 49, 80, 49, 2, 135, 166, 135, 166, 135, 166, 135, 166, | ||
| 67 | 	135, 166, 135, 166, 135, 166, 135, 166, 42, 43, 43, 43, 43, 43, 43, 43, | ||
| 68 | 	43, 43, 43, 43, 43, 0, 0, 0, 84, 86, 86, 86, 86, 86, 86, 86, | ||
| 69 | 	86, 86, 86, 86, 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 70 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 71 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 72 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 73 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 74 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 75 | 	0, 0, 0, 84, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, | ||
| 76 | 	12, 0, 12, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 77 | 	43, 7, 42, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 78 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 79 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 80 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 43, 43, 43, 43, 43, 43, | ||
| 81 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 82 | 	43, 43, 43, 43, 86, 86, 108, 129, 21, 0, 43, 43, 43, 43, 43, 43, | ||
| 83 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 84 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 85 | 	43, 43, 43, 43, 7, 108, 3, 65, 43, 43, 86, 86, 86, 86, 86, 86, | ||
| 86 | 	86, 86, 86, 86, 86, 86, 86, 86, 44, 86, 43, 43, 43, 43, 43, 43, | ||
| 87 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 1, | ||
| 88 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 89 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 90 | 	0, 0, 0, 0, 0, 0, 0, 0, 12, 108, 0, 0, 0, 0, 0, 6, | ||
| 91 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 92 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 93 | 	0, 0, 0, 0, 0, 0, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, | ||
| 94 | 	6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, | ||
| 95 | 	6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, | ||
| 96 | 	6, 37, 6, 37, 6, 37, 6, 37, 86, 122, 158, 38, 6, 37, 6, 37, | ||
| 97 | 	6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 37, | ||
| 98 | 	6, 37, 6, 37, 6, 37, 6, 37, 6, 37, 6, 1, 43, 43, 79, 86, | ||
| 99 | 	86, 44, 43, 127, 86, 86, 57, 43, 43, 85, 86, 86, 43, 43, 79, 86, | ||
| 100 | 	86, 44, 43, 127, 86, 86, 129, 55, 117, 91, 123, 92, 43, 43, 79, 86, | ||
| 101 | 	86, 2, 172, 4, 0, 0, 57, 43, 43, 85, 86, 86, 43, 43, 79, 86, | ||
| 102 | 	86, 44, 43, 43, 86, 86, 50, 19, 129, 87, 0, 111, 129, 126, 201, 215, | ||
| 103 | 	126, 45, 129, 129, 14, 126, 57, 127, 111, 87, 0, 129, 129, 126, 21, 0, | ||
| 104 | 	126, 3, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 7, 43, | ||
| 105 | 	36, 43, 151, 43, 43, 43, 43, 43, 43, 43, 43, 43, 42, 43, 43, 43, | ||
| 106 | 	43, 43, 86, 86, 86, 86, 86, 128, 129, 129, 129, 129, 57, 187, 42, 43, | ||
| 107 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 108 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 109 | 	43, 43, 43, 43, 43, 43, 43, 1, 129, 129, 129, 129, 129, 129, 129, 129, | ||
| 110 | 	129, 129, 129, 129, 129, 129, 129, 201, 172, 172, 172, 172, 172, 172, 172, 172, | ||
| 111 | 	172, 172, 172, 172, 172, 172, 172, 208, 13, 0, 78, 49, 2, 180, 193, 193, | ||
| 112 | 	215, 215, 36, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, | ||
| 113 | 	49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, 49, 80, | ||
| 114 | 	49, 80, 49, 80, 215, 215, 83, 193, 71, 212, 215, 215, 215, 5, 43, 43, | ||
| 115 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 7, 1, 0, 1, 0, 0, | ||
| 116 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 117 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 118 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 119 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 120 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 121 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 78, 49, 80, 49, 80, 49, 80, | ||
| 122 | 	49, 80, 49, 80, 49, 80, 49, 80, 13, 0, 0, 0, 0, 0, 36, 80, | ||
| 123 | 	49, 80, 49, 80, 49, 80, 49, 80, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 124 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 125 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 43, 43, 43, 43, 43, | ||
| 126 | 	43, 43, 43, 43, 43, 121, 92, 123, 92, 123, 79, 123, 92, 123, 92, 123, | ||
| 127 | 	92, 123, 92, 123, 92, 123, 92, 123, 92, 123, 92, 123, 92, 123, 92, 45, | ||
| 128 | 	43, 43, 121, 20, 92, 123, 92, 45, 121, 42, 92, 39, 92, 123, 92, 123, | ||
| 129 | 	92, 123, 164, 0, 10, 180, 92, 123, 92, 123, 79, 3, 42, 43, 43, 43, | ||
| 130 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 1, | ||
| 131 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 132 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 72, 0, 0, 0, 0, | ||
| 133 | 	0, 0, 0, 0, 0, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 134 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 135 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 136 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 137 | 	0, 43, 43, 43, 43, 43, 43, 43, 43, 7, 0, 72, 86, 86, 86, 86, | ||
| 138 | 	86, 86, 86, 86, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 139 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 140 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 141 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 43, 43, 43, 43, | ||
| 142 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 85, 86, 86, 86, 86, 86, 86, | ||
| 143 | 	86, 86, 86, 86, 86, 86, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 144 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 145 | 	0, 0, 0, 0, 0, 0, 36, 43, 43, 43, 43, 43, 43, 43, 43, 43, | ||
| 146 | 	43, 43, 7, 0, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, | ||
| 147 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 148 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 149 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 36, 43, 43, 43, | ||
| 150 | 	43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 7, 0, 0, | ||
| 151 | 	0, 0, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 86, | ||
| 152 | 	86, 86, 86, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 153 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 154 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 155 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 43, 43, | ||
| 156 | 	43, 43, 43, 43, 43, 43, 43, 43, 86, 86, 86, 86, 86, 86, 86, 86, | ||
| 157 | 	86, 86, 14, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 158 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 159 | 	0, 0, 0, 42, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 86, 86, | ||
| 160 | 	86, 86, 86, 86, 86, 86, 86, 86, 14, 0, 0, 0, 0, 0, 0, 0, | ||
| 161 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 162 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 163 | 	0, 0, 0, 0, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 43, 85, | ||
| 164 | 	86, 86, 86, 86, 86, 86, 86, 86, 86, 86, 14, 0, 0, 0, 0, 0, | ||
| 165 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 166 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 167 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 168 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 169 | }; | ||
| 170 | static const int rules[] = { | ||
| 171 | 	0x0, 0x2001, -0x2000, 0x1dbf00, 0x2e700, 0x7900, | ||
| 172 | 	0x2402, 0x101, -0x100, 0x0, 0x201, -0x200, | ||
| 173 | 	-0xc6ff, -0xe800, -0x78ff, -0x12c00, 0xc300, 0xd201, | ||
| 174 | 	0xce01, 0xcd01, 0x4f01, 0xca01, 0xcb01, 0xcf01, | ||
| 175 | 	0x6100, 0xd301, 0xd101, 0xa300, 0xd501, 0x8200, | ||
| 176 | 	0xd601, 0xda01, 0xd901, 0xdb01, 0x3800, 0x3, | ||
| 177 | 	-0x4f00, -0x60ff, -0x37ff, 0x242802, 0x0, 0x101, | ||
| 178 | 	-0x100, -0xcd00, -0xda00, -0x81ff, 0x2a2b01, -0xa2ff, | ||
| 179 | 	0x2a2801, 0x2a3f00, -0xc2ff, 0x4501, 0x4701, 0x2a1f00, | ||
| 180 | 	0x2a1c00, 0x2a1e00, -0xd200, -0xce00, -0xca00, -0xcb00, | ||
| 181 | 	0xa54f00, 0xa54b00, -0xcf00, 0xa52800, 0xa54400, -0xd100, | ||
| 182 | 	-0xd300, 0x29f700, 0xa54100, 0x29fd00, -0xd500, -0xd600, | ||
| 183 | 	0x29e700, 0xa54300, 0xa52a00, -0x4500, -0xd900, -0x4700, | ||
| 184 | 	-0xdb00, 0xa51500, 0xa51200, 0x4c2402, 0x0, 0x2001, | ||
| 185 | 	-0x2000, 0x101, -0x100, 0x5400, 0x7401, 0x2601, | ||
| 186 | 	0x2501, 0x4001, 0x3f01, -0x2600, -0x2500, -0x1f00, | ||
| 187 | 	-0x4000, -0x3f00, 0x801, -0x3e00, -0x3900, -0x2f00, | ||
| 188 | 	-0x3600, -0x800, -0x5600, -0x5000, 0x700, -0x7400, | ||
| 189 | 	-0x3bff, -0x6000, -0x6ff, 0x701a02, 0x101, -0x100, | ||
| 190 | 	0x2001, -0x2000, 0x5001, 0xf01, -0xf00, 0x0, | ||
| 191 | 	0x3001, -0x3000, 0x101, -0x100, 0x0, 0xbc000, | ||
| 192 | 	0x1c6001, 0x0, 0x97d001, 0x801, -0x800, 0x8a0502, | ||
| 193 | 	0x0, -0xbbfff, -0x186200, 0x89c200, -0x182500, -0x186e00, | ||
| 194 | 	-0x186d00, -0x186400, -0x186300, -0x185c00, 0x0, 0x8a3800, | ||
| 195 | 	0x8a0400, 0xee600, 0x101, -0x100, 0x0, -0x3b00, | ||
| 196 | 	-0x1dbeff, 0x8f1d02, 0x800, -0x7ff, 0x0, 0x5600, | ||
| 197 | 	-0x55ff, 0x4a00, 0x6400, 0x8000, 0x7000, 0x7e00, | ||
| 198 | 	0x900, -0x49ff, -0x8ff, -0x1c2500, -0x63ff, -0x6fff, | ||
| 199 | 	-0x7fff, -0x7dff, 0xac0502, 0x0, 0x1001, -0x1000, | ||
| 200 | 	0x1c01, 0x101, -0x1d5cff, -0x20beff, -0x2045ff, -0x1c00, | ||
| 201 | 	0xb10b02, 0x101, -0x100, 0x3001, -0x3000, 0x0, | ||
| 202 | 	-0x29f6ff, -0xee5ff, -0x29e6ff, -0x2a2b00, -0x2a2800, -0x2a1bff, | ||
| 203 | 	-0x29fcff, -0x2a1eff, -0x2a1dff, -0x2a3eff, 0x0, -0x1c6000, | ||
| 204 | 	0x0, 0x101, -0x100, 0xbc0c02, 0x0, 0x101, | ||
| 205 | 	-0x100, -0xa543ff, 0x3a001, -0x8a03ff, -0xa527ff, 0x3000, | ||
| 206 | 	-0xa54eff, -0xa54aff, -0xa540ff, -0xa511ff, -0xa529ff, -0xa514ff, | ||
| 207 | 	-0x2fff, -0xa542ff, -0x8a37ff, 0x0, -0x97d000, -0x3a000, | ||
| 208 | 	0x0, 0x2001, -0x2000, 0x0, 0x2801, -0x2800, | ||
| 209 | 	0x0, 0x4001, -0x4000, 0x0, 0x2001, -0x2000, | ||
| 210 | 	0x0, 0x2001, -0x2000, 0x0, 0x2201, -0x2200, | ||
| 211 | }; | ||
| 212 | static const unsigned char rulebases[] = { | ||
| 213 | 	0, 6, 39, 81, 111, 119, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 214 | 	124, 0, 0, 127, 0, 0, 0, 0, 0, 0, 0, 0, 131, 142, 146, 151, | ||
| 215 | 	0, 170, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 180, 196, 0, 0, | ||
| 216 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 217 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 218 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 219 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 220 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 221 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 222 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 223 | 	0, 0, 0, 0, 0, 0, 198, 201, 0, 0, 0, 219, 0, 0, 0, 0, | ||
| 224 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 225 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 226 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 227 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 228 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 222, | ||
| 229 | 	0, 0, 0, 0, 225, 0, 0, 0, 0, 0, 0, 0, 228, 0, 0, 0, | ||
| 230 | 	0, 0, 0, 0, 0, 0, 0, 0, 231, 0, 0, 0, 0, 0, 0, 0, | ||
| 231 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 232 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 233 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 234 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 235 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 234, 0, | ||
| 236 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 237 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 238 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 239 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 240 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 241 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 242 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 243 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 237, 0, 0, 0, 0, 0, 0, | ||
| 244 | 	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | ||
| 245 | }; | ||
| 246 | static const unsigned char exceptions[][2] = { | ||
| 247 | 	{ 48, 12 }, { 49, 13 }, { 120, 14 }, { 127, 15 }, | ||
| 248 | 	{ 128, 16 }, { 129, 17 }, { 134, 18 }, { 137, 19 }, | ||
| 249 | 	{ 138, 19 }, { 142, 20 }, { 143, 21 }, { 144, 22 }, | ||
| 250 | 	{ 147, 19 }, { 148, 23 }, { 149, 24 }, { 150, 25 }, | ||
| 251 | 	{ 151, 26 }, { 154, 27 }, { 156, 25 }, { 157, 28 }, | ||
| 252 | 	{ 158, 29 }, { 159, 30 }, { 166, 31 }, { 169, 31 }, | ||
| 253 | 	{ 174, 31 }, { 177, 32 }, { 178, 32 }, { 183, 33 }, | ||
| 254 | 	{ 191, 34 }, { 197, 35 }, { 200, 35 }, { 203, 35 }, | ||
| 255 | 	{ 221, 36 }, { 242, 35 }, { 246, 37 }, { 247, 38 }, | ||
| 256 | 	{ 32, 45 }, { 58, 46 }, { 61, 47 }, { 62, 48 }, | ||
| 257 | 	{ 63, 49 }, { 64, 49 }, { 67, 50 }, { 68, 51 }, | ||
| 258 | 	{ 69, 52 }, { 80, 53 }, { 81, 54 }, { 82, 55 }, | ||
| 259 | 	{ 83, 56 }, { 84, 57 }, { 89, 58 }, { 91, 59 }, | ||
| 260 | 	{ 92, 60 }, { 97, 61 }, { 99, 62 }, { 101, 63 }, | ||
| 261 | 	{ 102, 64 }, { 104, 65 }, { 105, 66 }, { 106, 64 }, | ||
| 262 | 	{ 107, 67 }, { 108, 68 }, { 111, 66 }, { 113, 69 }, | ||
| 263 | 	{ 114, 70 }, { 117, 71 }, { 125, 72 }, { 130, 73 }, | ||
| 264 | 	{ 135, 74 }, { 137, 75 }, { 138, 76 }, { 139, 76 }, | ||
| 265 | 	{ 140, 77 }, { 146, 78 }, { 157, 79 }, { 158, 80 }, | ||
| 266 | 	{ 69, 87 }, { 123, 29 }, { 124, 29 }, { 125, 29 }, | ||
| 267 | 	{ 127, 88 }, { 134, 89 }, { 136, 90 }, { 137, 90 }, | ||
| 268 | 	{ 138, 90 }, { 140, 91 }, { 142, 92 }, { 143, 92 }, | ||
| 269 | 	{ 172, 93 }, { 173, 94 }, { 174, 94 }, { 175, 94 }, | ||
| 270 | 	{ 194, 95 }, { 204, 96 }, { 205, 97 }, { 206, 97 }, | ||
| 271 | 	{ 207, 98 }, { 208, 99 }, { 209, 100 }, { 213, 101 }, | ||
| 272 | 	{ 214, 102 }, { 215, 103 }, { 240, 104 }, { 241, 105 }, | ||
| 273 | 	{ 242, 106 }, { 243, 107 }, { 244, 108 }, { 245, 109 }, | ||
| 274 | 	{ 249, 110 }, { 253, 45 }, { 254, 45 }, { 255, 45 }, | ||
| 275 | 	{ 80, 105 }, { 81, 105 }, { 82, 105 }, { 83, 105 }, | ||
| 276 | 	{ 84, 105 }, { 85, 105 }, { 86, 105 }, { 87, 105 }, | ||
| 277 | 	{ 88, 105 }, { 89, 105 }, { 90, 105 }, { 91, 105 }, | ||
| 278 | 	{ 92, 105 }, { 93, 105 }, { 94, 105 }, { 95, 105 }, | ||
| 279 | 	{ 130, 0 }, { 131, 0 }, { 132, 0 }, { 133, 0 }, | ||
| 280 | 	{ 134, 0 }, { 135, 0 }, { 136, 0 }, { 137, 0 }, | ||
| 281 | 	{ 192, 117 }, { 207, 118 }, { 128, 137 }, { 129, 138 }, | ||
| 282 | 	{ 130, 139 }, { 133, 140 }, { 134, 141 }, { 112, 157 }, | ||
| 283 | 	{ 113, 157 }, { 118, 158 }, { 119, 158 }, { 120, 159 }, | ||
| 284 | 	{ 121, 159 }, { 122, 160 }, { 123, 160 }, { 124, 161 }, | ||
| 285 | 	{ 125, 161 }, { 179, 162 }, { 186, 163 }, { 187, 163 }, | ||
| 286 | 	{ 188, 164 }, { 190, 165 }, { 195, 162 }, { 204, 164 }, | ||
| 287 | 	{ 218, 166 }, { 219, 166 }, { 229, 106 }, { 234, 167 }, | ||
| 288 | 	{ 235, 167 }, { 236, 110 }, { 243, 162 }, { 248, 168 }, | ||
| 289 | 	{ 249, 168 }, { 250, 169 }, { 251, 169 }, { 252, 164 }, | ||
| 290 | 	{ 38, 176 }, { 42, 177 }, { 43, 178 }, { 78, 179 }, | ||
| 291 | 	{ 132, 8 }, { 98, 186 }, { 99, 187 }, { 100, 188 }, | ||
| 292 | 	{ 101, 189 }, { 102, 190 }, { 109, 191 }, { 110, 192 }, | ||
| 293 | 	{ 111, 193 }, { 112, 194 }, { 126, 195 }, { 127, 195 }, | ||
| 294 | 	{ 125, 207 }, { 141, 208 }, { 148, 209 }, { 171, 210 }, | ||
| 295 | 	{ 172, 211 }, { 173, 212 }, { 176, 213 }, { 177, 214 }, | ||
| 296 | 	{ 178, 215 }, { 196, 216 }, { 197, 217 }, { 198, 218 }, | ||
| 297 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isalnum.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int isalnum(int c) | ||
| 4 | { | ||
| 5 | 	return isalpha(c) || isdigit(c); | ||
| 6 | } | ||
| 7 | |||
| 8 | int __isalnum_l(int c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return isalnum(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__isalnum_l, isalnum_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isalpha.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isalpha | ||
| 3 | |||
| 4 | int isalpha(int c) | ||
| 5 | { | ||
| 6 | 	return ((unsigned)c|32)-'a' < 26; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __isalpha_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return isalpha(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__isalpha_l, isalpha_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isascii.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isascii | ||
| 3 | |||
| 4 | int isascii(int c) | ||
| 5 | { | ||
| 6 | 	return !(c&~0x7f); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isblank.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int isblank(int c) | ||
| 4 | { | ||
| 5 | 	return (c == ' ' || c == '\t'); | ||
| 6 | } | ||
| 7 | |||
| 8 | int __isblank_l(int c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return isblank(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__isblank_l, isblank_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iscntrl.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int iscntrl(int c) | ||
| 4 | { | ||
| 5 | 	return (unsigned)c < 0x20 || c == 0x7f; | ||
| 6 | } | ||
| 7 | |||
| 8 | int __iscntrl_l(int c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return iscntrl(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__iscntrl_l, iscntrl_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isdigit.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isdigit | ||
| 3 | |||
| 4 | int isdigit(int c) | ||
| 5 | { | ||
| 6 | 	return (unsigned)c-'0' < 10; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __isdigit_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return isdigit(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__isdigit_l, isdigit_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isgraph.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isgraph | ||
| 3 | |||
| 4 | int isgraph(int c) | ||
| 5 | { | ||
| 6 | 	return (unsigned)c-0x21 < 0x5e; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __isgraph_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return isgraph(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__isgraph_l, isgraph_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/islower.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef islower | ||
| 3 | |||
| 4 | int islower(int c) | ||
| 5 | { | ||
| 6 | 	return (unsigned)c-'a' < 26; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __islower_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return islower(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__islower_l, islower_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isprint.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isprint | ||
| 3 | |||
| 4 | int isprint(int c) | ||
| 5 | { | ||
| 6 | 	return (unsigned)c-0x20 < 0x5f; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __isprint_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return isprint(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__isprint_l, isprint_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/ispunct.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int ispunct(int c) | ||
| 4 | { | ||
| 5 | 	return isgraph(c) && !isalnum(c); | ||
| 6 | } | ||
| 7 | |||
| 8 | int __ispunct_l(int c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return ispunct(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__ispunct_l, ispunct_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isspace.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isspace | ||
| 3 | |||
| 4 | int isspace(int c) | ||
| 5 | { | ||
| 6 | 	return c == ' ' || (unsigned)c-'\t' < 5; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __isspace_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return isspace(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__isspace_l, isspace_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isupper.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #undef isupper | ||
| 3 | |||
| 4 | int isupper(int c) | ||
| 5 | { | ||
| 6 | 	return (unsigned)c-'A' < 26; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __isupper_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return isupper(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__isupper_l, isupper_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswalnum.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | int iswalnum(wint_t wc) | ||
| 4 | { | ||
| 5 | 	return iswdigit(wc) || iswalpha(wc); | ||
| 6 | } | ||
| 7 | |||
| 8 | int __iswalnum_l(wint_t c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return iswalnum(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__iswalnum_l, iswalnum_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswalpha.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | static const unsigned char table[] = { | ||
| 4 | #include "alpha.h" | ||
| 5 | }; | ||
| 6 | |||
| 7 | int iswalpha(wint_t wc) | ||
| 8 | { | ||
| 9 | 	if (wc<0x20000U) | ||
| 10 | 		return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; | ||
| 11 | 	if (wc<0x2fffeU) | ||
| 12 | 		return 1; | ||
| 13 | 	return 0; | ||
| 14 | } | ||
| 15 | |||
| 16 | int __iswalpha_l(wint_t c, locale_t l) | ||
| 17 | { | ||
| 18 | 	return iswalpha(c); | ||
| 19 | } | ||
| 20 | |||
| 21 | weak_alias(__iswalpha_l, iswalpha_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswblank.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | |||
| 4 | int iswblank(wint_t wc) | ||
| 5 | { | ||
| 6 | 	return isblank(wc); | ||
| 7 | } | ||
| 8 | |||
| 9 | int __iswblank_l(wint_t c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return iswblank(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__iswblank_l, iswblank_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswcntrl.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | int iswcntrl(wint_t wc) | ||
| 4 | { | ||
| 5 | 	return (unsigned)wc < 32 | ||
| 6 | 	 || (unsigned)(wc-0x7f) < 33 | ||
| 7 | 	 || (unsigned)(wc-0x2028) < 2 | ||
| 8 | 	 || (unsigned)(wc-0xfff9) < 3; | ||
| 9 | } | ||
| 10 | |||
| 11 | int __iswcntrl_l(wint_t c, locale_t l) | ||
| 12 | { | ||
| 13 | 	return iswcntrl(c); | ||
| 14 | } | ||
| 15 | |||
| 16 | weak_alias(__iswcntrl_l, iswcntrl_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswctype.c created+75| ... | @@ -0,0 +1,75 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | #define WCTYPE_ALNUM 1 | ||
| 5 | #define WCTYPE_ALPHA 2 | ||
| 6 | #define WCTYPE_BLANK 3 | ||
| 7 | #define WCTYPE_CNTRL 4 | ||
| 8 | #define WCTYPE_DIGIT 5 | ||
| 9 | #define WCTYPE_GRAPH 6 | ||
| 10 | #define WCTYPE_LOWER 7 | ||
| 11 | #define WCTYPE_PRINT 8 | ||
| 12 | #define WCTYPE_PUNCT 9 | ||
| 13 | #define WCTYPE_SPACE 10 | ||
| 14 | #define WCTYPE_UPPER 11 | ||
| 15 | #define WCTYPE_XDIGIT 12 | ||
| 16 | |||
| 17 | int iswctype(wint_t wc, wctype_t type) | ||
| 18 | { | ||
| 19 | 	switch (type) { | ||
| 20 | 	case WCTYPE_ALNUM: | ||
| 21 | 		return iswalnum(wc); | ||
| 22 | 	case WCTYPE_ALPHA: | ||
| 23 | 		return iswalpha(wc); | ||
| 24 | 	case WCTYPE_BLANK: | ||
| 25 | 		return iswblank(wc); | ||
| 26 | 	case WCTYPE_CNTRL: | ||
| 27 | 		return iswcntrl(wc); | ||
| 28 | 	case WCTYPE_DIGIT: | ||
| 29 | 		return iswdigit(wc); | ||
| 30 | 	case WCTYPE_GRAPH: | ||
| 31 | 		return iswgraph(wc); | ||
| 32 | 	case WCTYPE_LOWER: | ||
| 33 | 		return iswlower(wc); | ||
| 34 | 	case WCTYPE_PRINT: | ||
| 35 | 		return iswprint(wc); | ||
| 36 | 	case WCTYPE_PUNCT: | ||
| 37 | 		return iswpunct(wc); | ||
| 38 | 	case WCTYPE_SPACE: | ||
| 39 | 		return iswspace(wc); | ||
| 40 | 	case WCTYPE_UPPER: | ||
| 41 | 		return iswupper(wc); | ||
| 42 | 	case WCTYPE_XDIGIT: | ||
| 43 | 		return iswxdigit(wc); | ||
| 44 | 	} | ||
| 45 | 	return 0; | ||
| 46 | } | ||
| 47 | |||
| 48 | wctype_t wctype(const char *s) | ||
| 49 | { | ||
| 50 | 	int i; | ||
| 51 | 	const char *p; | ||
| 52 | 	/* order must match! */ | ||
| 53 | 	static const char names[] = | ||
| 54 | 		"alnum\0" "alpha\0" "blank\0" | ||
| 55 | 		"cntrl\0" "digit\0" "graph\0" | ||
| 56 | 		"lower\0" "print\0" "punct\0" | ||
| 57 | 		"space\0" "upper\0" "xdigit"; | ||
| 58 | 	for (i=1, p=names; *p; i++, p+=6) | ||
| 59 | 		if (*s == *p && !strcmp(s, p)) | ||
| 60 | 			return i; | ||
| 61 | 	return 0; | ||
| 62 | } | ||
| 63 | |||
| 64 | int __iswctype_l(wint_t c, wctype_t t, locale_t l) | ||
| 65 | { | ||
| 66 | 	return iswctype(c, t); | ||
| 67 | } | ||
| 68 | |||
| 69 | wctype_t __wctype_l(const char *s, locale_t l) | ||
| 70 | { | ||
| 71 | 	return wctype(s); | ||
| 72 | } | ||
| 73 | |||
| 74 | weak_alias(__iswctype_l, iswctype_l); | ||
| 75 | weak_alias(__wctype_l, wctype_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswdigit.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | #undef iswdigit | ||
| 4 | |||
| 5 | int iswdigit(wint_t wc) | ||
| 6 | { | ||
| 7 | 	return (unsigned)wc-'0' < 10; | ||
| 8 | } | ||
| 9 | |||
| 10 | int __iswdigit_l(wint_t c, locale_t l) | ||
| 11 | { | ||
| 12 | 	return iswdigit(c); | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(__iswdigit_l, iswdigit_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswgraph.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | int iswgraph(wint_t wc) | ||
| 4 | { | ||
| 5 | 	/* ISO C defines this function as: */ | ||
| 6 | 	return !iswspace(wc) && iswprint(wc); | ||
| 7 | } | ||
| 8 | |||
| 9 | int __iswgraph_l(wint_t c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return iswgraph(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__iswgraph_l, iswgraph_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswlower.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | int iswlower(wint_t wc) | ||
| 4 | { | ||
| 5 | 	return towupper(wc) != wc; | ||
| 6 | } | ||
| 7 | |||
| 8 | int __iswlower_l(wint_t c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return iswlower(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__iswlower_l, iswlower_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswprint.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | /* Consider all legal codepoints as printable except for: | ||
| 4 | * - C0 and C1 control characters | ||
| 5 | * - U+2028 and U+2029 (line/para break) | ||
| 6 | * - U+FFF9 through U+FFFB (interlinear annotation controls) | ||
| 7 | * The following code is optimized heavily to make hot paths for the | ||
| 8 | * expected printable characters. */ | ||
| 9 | |||
| 10 | int iswprint(wint_t wc) | ||
| 11 | { | ||
| 12 | 	if (wc < 0xffU) | ||
| 13 | 		return (wc+1 & 0x7f) >= 0x21; | ||
| 14 | 	if (wc < 0x2028U || wc-0x202aU < 0xd800-0x202a || wc-0xe000U < 0xfff9-0xe000) | ||
| 15 | 		return 1; | ||
| 16 | 	if (wc-0xfffcU > 0x10ffff-0xfffc || (wc&0xfffe)==0xfffe) | ||
| 17 | 		return 0; | ||
| 18 | 	return 1; | ||
| 19 | } | ||
| 20 | |||
| 21 | int __iswprint_l(wint_t c, locale_t l) | ||
| 22 | { | ||
| 23 | 	return iswprint(c); | ||
| 24 | } | ||
| 25 | |||
| 26 | weak_alias(__iswprint_l, iswprint_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswpunct.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | static const unsigned char table[] = { | ||
| 4 | #include "punct.h" | ||
| 5 | }; | ||
| 6 | |||
| 7 | int iswpunct(wint_t wc) | ||
| 8 | { | ||
| 9 | 	if (wc<0x20000U) | ||
| 10 | 		return (table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1; | ||
| 11 | 	return 0; | ||
| 12 | } | ||
| 13 | |||
| 14 | int __iswpunct_l(wint_t c, locale_t l) | ||
| 15 | { | ||
| 16 | 	return iswpunct(c); | ||
| 17 | } | ||
| 18 | |||
| 19 | weak_alias(__iswpunct_l, iswpunct_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswspace.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <wctype.h> | ||
| 3 | |||
| 4 | /* Our definition of whitespace is the Unicode White_Space property, | ||
| 5 | * minus non-breaking spaces (U+00A0, U+2007, and U+202F) and script- | ||
| 6 | * specific characters with non-blank glyphs (U+1680 and U+180E). */ | ||
| 7 | |||
| 8 | int iswspace(wint_t wc) | ||
| 9 | { | ||
| 10 | 	static const wchar_t spaces[] = { | ||
| 11 | 		' ', '\t', '\n', '\r', 11, 12, 0x0085, | ||
| 12 | 		0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, | ||
| 13 | 		0x2006, 0x2008, 0x2009, 0x200a, | ||
| 14 | 		0x2028, 0x2029, 0x205f, 0x3000, 0 | ||
| 15 | 	}; | ||
| 16 | 	return wc && wcschr(spaces, wc); | ||
| 17 | } | ||
| 18 | |||
| 19 | int __iswspace_l(wint_t c, locale_t l) | ||
| 20 | { | ||
| 21 | 	return iswspace(c); | ||
| 22 | } | ||
| 23 | |||
| 24 | weak_alias(__iswspace_l, iswspace_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswupper.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | int iswupper(wint_t wc) | ||
| 4 | { | ||
| 5 | 	return towlower(wc) != wc; | ||
| 6 | } | ||
| 7 | |||
| 8 | int __iswupper_l(wint_t c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return iswupper(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__iswupper_l, iswupper_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/iswxdigit.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | int iswxdigit(wint_t wc) | ||
| 4 | { | ||
| 5 | 	return (unsigned)(wc-'0') < 10 || (unsigned)((wc|32)-'a') < 6; | ||
| 6 | } | ||
| 7 | |||
| 8 | int __iswxdigit_l(wint_t c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return iswxdigit(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__iswxdigit_l, iswxdigit_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/isxdigit.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int isxdigit(int c) | ||
| 4 | { | ||
| 5 | 	return isdigit(c) || ((unsigned)c|32)-'a' < 6; | ||
| 6 | } | ||
| 7 | |||
| 8 | int __isxdigit_l(int c, locale_t l) | ||
| 9 | { | ||
| 10 | 	return isxdigit(c); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__isxdigit_l, isxdigit_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/nonspacing.h created+89| ... | @@ -0,0 +1,89 @@ | ||
| 1 | 16,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,16,16,32,16,16,16,33,34,35, | ||
| 2 | 36,37,38,39,16,16,40,16,16,16,16,16,16,16,16,16,16,16,41,42,16,16,43,16,16,16, | ||
| 3 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 4 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 5 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 6 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 7 | 16,16,16,16,16,16,16,16,16,16,44,16,45,46,47,48,16,16,16,16,16,16,16,16,16,16, | ||
| 8 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 9 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 10 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50, | ||
| 11 | 51,16,52,53,54,16,16,16,16,16,16,55,16,16,56,16,57,58,59,60,61,62,63,64,65,66, | ||
| 12 | 67,68,16,69,70,71,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 13 | 16,72,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 14 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 15 | 16,16,16,73,74,16,16,16,75,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 16 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 17 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 18 | 16,16,16,16,16,16,16,76,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 19 | 16,16,77,78,16,16,16,16,16,16,16,79,16,16,16,16,16,80,81,82,16,16,16,16,16,83, | ||
| 20 | 84,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 21 | 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, | ||
| 22 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 23 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 24 | 255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 25 | 0,0,0,0,0,0,0,248,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 26 | 0,0,0,254,255,255,255,255,191,182,0,0,0,0,0,0,0,63,0,255,23,0,0,0,0,0,248,255, | ||
| 27 | 255,0,0,1,0,0,0,0,0,0,0,0,0,0,0,192,191,159,61,0,0,0,128,2,0,0,0,255,255,255, | ||
| 28 | 7,0,0,0,0,0,0,0,0,0,0,192,255,1,0,0,0,0,0,0,248,15,32,0,0,192,251,239,62,0,0, | ||
| 29 | 0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,255,255,255,255, | ||
| 30 | 255,7,0,0,0,0,0,0,20,254,33,254,0,12,0,0,0,2,0,0,0,0,0,0,16,30,32,0,0,12,0,0, | ||
| 31 | 64,6,0,0,0,0,0,0,16,134,57,2,0,0,0,35,0,6,0,0,0,0,0,0,16,190,33,0,0,12,0,0, | ||
| 32 | 252,2,0,0,0,0,0,0,144,30,32,64,0,12,0,0,0,4,0,0,0,0,0,0,0,1,32,0,0,0,0,0,0,17, | ||
| 33 | 0,0,0,0,0,0,192,193,61,96,0,12,0,0,0,2,0,0,0,0,0,0,144,64,48,0,0,12,0,0,0,3,0, | ||
| 34 | 0,0,0,0,0,24,30,32,0,0,12,0,0,0,0,0,0,0,0,0,0,0,0,4,92,0,0,0,0,0,0,0,0,0,0,0, | ||
| 35 | 242,7,128,127,0,0,0,0,0,0,0,0,0,0,0,0,242,31,0,63,0,0,0,0,0,0,0,0,0,3,0,0,160, | ||
| 36 | 2,0,0,0,0,0,0,254,127,223,224,255,254,255,255,255,31,64,0,0,0,0,0,0,0,0,0,0,0, | ||
| 37 | 0,224,253,102,0,0,0,195,1,0,30,0,100,32,0,32,0,0,0,0,0,0,0,0,0,0,0, | ||
| 38 | 0,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0, | ||
| 39 | 0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,15,32,0,0,0,0,0,120,0,0, | ||
| 40 | 0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0,0,0,0,0,135,1,4,14,0, | ||
| 41 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,9,0,0,0,0,0,0,64,127, | ||
| 42 | 229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,15,0,0,0,0,0,208,23,4,0,0, | ||
| 43 | 0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,0,0,0,0,240,207,0,0,0,0,0, | ||
| 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 45 | 0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255, | ||
| 46 | 251,0,248,0,0,0,124,0,0,0,0,0,0,223,255,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, | ||
| 47 | 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,0,0,0, | ||
| 48 | 0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,0,0,0,0, | ||
| 49 | 0,60,0,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 50 | 0,0,0,128,247,63,0,0,0,192,0,0,0,0,0,0,0,0,0,0,3,0,68,8,0,0,96,0,0,0,0,0,0,0, | ||
| 51 | 0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,0,255,255,3,128,0,0,0,0,192,63,0,0,128,255,3,0, | ||
| 52 | 0,0,0,0,7,0,0,0,0,0,200,51,0,0,0,0,32,0,0,0,0,0,0,0,0,126,102,0,8,16,0,0,0,0, | ||
| 53 | 0,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64, | ||
| 54 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,33,0,0,0,0,0,64, | ||
| 55 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,0,0,255,255,0, | ||
| 56 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 57 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 58 | 0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 59 | 0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 60 | 0,110,240,0,0,0,0,0,135,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0, | ||
| 61 | 0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 62 | 0,0,0,192,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,255, | ||
| 63 | 127,0,0,0,0,0,0,128,3,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0, | ||
| 64 | 0,0,0,0,0,0,8,0,3,0,0,0,0,0,192,127,0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0, | ||
| 65 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,1,0,0,0,192, | ||
| 66 | 31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0, | ||
| 67 | 0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 68 | 0,60,176,1,0,0,48,0,0,0, | ||
| 69 | 0,0,0,0,0,0,0,248,167,1,0,0,0,0,0,0,0,0,0,0,0,0,40,191,0,0,0,0,0,0,0,0,0,0,0, | ||
| 70 | 0,224,188,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 71 | 128,255,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 72 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0, | ||
| 73 | 126,14,0,0,0,0,0,252,127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0, | ||
| 74 | 0,0,0,0,0,0,0,252,255,255,252,109,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,126,180,191,0, | ||
| 75 | 0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 76 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,24, | ||
| 77 | 0,0,0,0,0,0,0,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 78 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,127,0,0,0, | ||
| 79 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0, | ||
| 80 | 0,128,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,15, | ||
| 81 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0, | ||
| 82 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,28,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 83 | 0,0,0,255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248, | ||
| 84 | 254,255,0,0,0,0,0,0,0,0,0, | ||
| 85 | 0,127,255,255,249,219,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 86 | 0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 87 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 88 | 0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,240,7,0,0,0,0,0,0,0,0, | ||
| 89 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/punct.h created+141| ... | @@ -0,0 +1,141 @@ | ||
| 1 | 18,16,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,16,16,34,35,16,36,37,38,39, | ||
| 2 | 40,41,42,43,16,44,45,46,17,17,47,17,17,17,17,17,17,48,49,50,51,52,53,54,55,17, | ||
| 3 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,56, | ||
| 4 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 5 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 6 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 7 | 16,16,16,16,16,16,16,16,57,16,58,59,60,61,62,63,16,16,16,16,16,16,16,16,16,16, | ||
| 8 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 9 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,64,16,16,16,16,16,16,16,16,16, | ||
| 10 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,65,16,16,66,16,67,68, | ||
| 11 | 69,16,70,71,72,16,73,16,16,74,75,76,77,78,16,79,80,81,82,83,84,85,86,87,88,89, | ||
| 12 | 90,91,16,92,93,94,95,16,16,16,16,96,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 13 | 16,97,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 14 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 15 | 16,16,16,98,99,16,16,100,101,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 16 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 17 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 18 | 16,16,16,16,16,16,16,16,102,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 19 | 16,16,16,103,104,105,106,16,16,107,108,17,17,109,16,16,16,16,16,16,110,111,16, | ||
| 20 | 16,16,16,16,112,113,16,16,114,115,116,16,117,118,119,17,17,17,120,121,122,123, | ||
| 21 | 124,16,16,16,16, | ||
| 22 | 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, | ||
| 23 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 24 | 255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,254,255,0,252,1,0,0,248,1, | ||
| 25 | 0,0,120,0,0,0,0,255,251,223,251,0,0,128,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 26 | 0,0,0,0,0,0,0,0,0,0,0,60,0,252,255,224,175,255,255,255,255,255,255,255,255, | ||
| 27 | 255,255,223,255,255,255,255,255,32,64,176,0,0,0,0,0,0,0,0,0,0,0,0,0,64,0,0,0, | ||
| 28 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 29 | 0,0,0,252,0,0,0,0,0,230,254,255,255,255,0,64,73,0,0,0,0,0,24,0,255,255,0,216, | ||
| 30 | 0,0,0,0,0,0,0,1,0,60,0,0,0,0,0,0,0,0,0,0,0,0,16,224,1,30,0, | ||
| 31 | 96,255,191,0,0,0,0,0,0,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,248,207, | ||
| 32 | 227,0,0,0,3,0,32,255,127,0,0,0,78,0,0,0,0,0,0,0,0,0,0,0,0,0,0,8,0,7,252,0,0,0, | ||
| 33 | 0,0,0,0,0,0,16,0,32,30,0,48,0,1,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,252,111,0,0,0, | ||
| 34 | 0,0,0,0,16,0,32,0,0,0,0,64,0,0,0,0,0,0,0,0,16,0,32,0,0,0,0,3,224,0,0,0,0,0,0, | ||
| 35 | 0,16,0,32,0,0,0,0,253,0,0,0,0,0,0,0,0,0,0,32,0,0,0,0,255,7,16,0,0,0,0,0,0,0,0, | ||
| 36 | 32,0,0,0,0,128,255,16,0,0,0,0,0,0,16,0,32,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,160, | ||
| 37 | 0,127,0,0,255,3,0,0,0,0,0,0,0,0,0,4,0,0,0,0,16,0,0,0,0,0,0,128,0,128,192,223, | ||
| 38 | 0,12,0,0,0,0,0,0,0,0,0,0,0,4,0,31,0,0,0,0,0, | ||
| 39 | 0,254,255,255,255,0,252,255,255,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,192,255,223, | ||
| 40 | 255,7,0,0,0,0,0,0,0,0,0,0,128,6,0,252,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,0, | ||
| 41 | 0,0,8,0,0,0,0,0,0,0,0,0,0,0,224,255,255,255,31,0,0,255,3,0,0,0,0,0,0,0,0,0,0, | ||
| 42 | 0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 43 | 0,0,0,0,0,0,0,0,96,0,0,1,0,0,24,0,0,0,0,0,0,0,0,0,56,0,0,0,0,16,0,0,0,112,0,0, | ||
| 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,48,0,0,254,127,47,0,0,255,3,255,127,0,0,0,0,0,0,0,0, | ||
| 45 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,14,49,0,0,0,0,0,0,0, | ||
| 46 | 0,0,0,0,0,0,0,0,0,0,0,196,255,255,255, | ||
| 47 | 255,0,0,0,192,0,0,0,0,0,0,0,0,1,0,224,159,0,0,0,0,127,63,255,127,0,0,0,0,0,0, | ||
| 48 | 0,0,0,0,0,0,0,0,16,0,16,0,0,252,255,255,255,31,0,0,0,0,0,12,0,0,0,0,0,0,64,0, | ||
| 49 | 12,240,0,0,0,0,0,0,128,248,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0,255,0,255,255, | ||
| 50 | 255,33,144,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, | ||
| 51 | 127,0,224,251,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,160,3,224,0,224,0, | ||
| 52 | 224,0,96,128,248,255,255,255,252,255,255,255,255,255,127,223,255,241,127,255, | ||
| 53 | 127,0,0,255,255,255,255,0,0,255,255,255,255,1,0,123,3,208,193,175,66,0,12,31, | ||
| 54 | 188,255,255,0,0,0,0,0,14,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 55 | 255,255,255,255,255,127,0,0,0,255,7,0,0,255,255,255,255,255,255,255,255,255, | ||
| 56 | 255,63,0,0,0,0,0,0,252,255, | ||
| 57 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,207,255,255,255, | ||
| 58 | 63,255,255,255,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0, | ||
| 59 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,224,135,3,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | ||
| 60 | 128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,127,255,255,255,255,0, | ||
| 61 | 0,0,0,0,0,255,255,255,251,255,255,255,255,255,255,255,255,255,255,15,0,255, | ||
| 62 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 63 | 255,255,255,255,255,255,63,0,0,0,255,15,30,255,255,255,1,252,193,224,0,0,0,0, | ||
| 64 | 0,0,0,0,0,0,0,30,1,0,0,0,0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 65 | 255,255,0,0,0,0,255,255,255,255,15,0,0,0,255,255,255,127,255,255,255,255,255, | ||
| 66 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 67 | 255,255,255, | ||
| 68 | 255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255, | ||
| 69 | 255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,127,0,0,0, | ||
| 70 | 0,0,0,192,0,224,0,0,0,0,0,0,0,0,0,0,0,128,15,112,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 71 | 255,0,255,255,127,0,3,0,0,0,0,0,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 72 | 64,0,0,0,0,15,255,3,0,0,0,0,0,0,240,0,0,0,0,0,0,0,0,0,16,192,0,0,255,255,3,23, | ||
| 73 | 0,0,0,0,0,248,0,0,0,0,8,128,0,0,0,0,0,0,0,0,0,0,8,0,255,63,0,192,0,0,0,0,0,0, | ||
| 74 | 0,0,0,0,0,0,0,0,0,240,0,0,128,3,0,0,0,0,0,0,0,128,2,0,0,192,0,0,67,0,0,0,0,0, | ||
| 75 | 0,0,0,0,0,0,0,8,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,56,0, | ||
| 76 | 0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 77 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,2,0,0,0,0,0,0, | ||
| 78 | 0,0,0,0,0,0,0,0,0,0,252,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0, | ||
| 79 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,255,255,255,3,255,255,255,255,255,255,247, | ||
| 80 | 255,127,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,254,255,0,252,1,0,0,248,1,0, | ||
| 81 | 0,248,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,127,0,48,135,255,255,255,255,255, | ||
| 82 | 143,255,0,0,0,0,0,0,224,255,255,127,255,15,1,0,0,0,0,0,255,255,255,255,255,63, | ||
| 83 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255, | ||
| 84 | 15,0,0,0,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0, | ||
| 85 | 0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 86 | 128,255,0,0,128,255,0,0,0,0,128,255,0,0,0,0,0,0,0,0,0,248,0,0,192,143,0,0,0, | ||
| 87 | 128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,48,255,255,252,255,255,255,255,255,0,0,0,0, | ||
| 88 | 0,0,0,135,255,1,255,1,0,0,0,224,0,0,0,224,0,0,0,0,0,1,0,0,96,248,127,0,0,0,0, | ||
| 89 | 0,0,0,0,254,0,0,0,255,0,0,0,255,0,0,0,30,0,254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 90 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,0,0,0,0,0,0,0,0,0,0,0, | ||
| 91 | 0,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 92 | 0,0,0,0,224,127,0,0,0,192,255,255,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 93 | 0,0,0,0,0,0,0,192,63,252,255,63,0,0,128,3,0,0,0,0,0,0,254,3,32,0,0,0,0,0,0,0, | ||
| 94 | 0,0,0,0,0,24,0,15,0,0,0,0,0,56,0,0,0,0,0,0,0,0,0,225,63,0,232,254,255,31,0,0, | ||
| 95 | 0,0,0,0,0,96,63,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,0,0,0,0,0,6,0,0,0,0,0,0,0,0,0, | ||
| 96 | 24,0,32,0,0,192,31,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,68, | ||
| 97 | 248,0,104,0,0,0,0,0,0,0,0,0,0,0,0,76,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 98 | 0,0,0,0,0,0,0,0,0,0,128,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,128,14,0,0,0,255, | ||
| 99 | 31,0,0,0,0,0,0,0,0,192,0,0,0,0,0,0,0,0, | ||
| 100 | 0,0,0,0,0,0,8,0,252,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 101 | 0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,252,7,0,0,0,0,0,0,0,0,0,0,0, | ||
| 102 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,0,0,0,0,0,0,0,0,24,128,255,0,0,0,0,0, | ||
| 103 | 0,0,0,0,0,223,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,62,0,0,252,255,31,3,0, | ||
| 104 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,52,0,0,0,0,0,0,0,0,0,128,0,0, | ||
| 105 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 106 | 0,0,128,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255, | ||
| 107 | 255,3, | ||
| 108 | 128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 109 | 0,0,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 110 | 0,0,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,63,0,0,0,0,0,0,0,255,255,48,0,0,248, | ||
| 111 | 3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255, | ||
| 112 | 255,255,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 113 | 0,0,0,0,0,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,176,15,0,0,0,0,0,0, | ||
| 114 | 0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 115 | 255,255,255,255,255,255,255,255,255,255,255,255,255,63, | ||
| 116 | 0,255,255,255,255,127,254,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 117 | 255,255,255,255,255,255,255,255,255,255,1,0,0,255,255,255,255,255,255,255,255, | ||
| 118 | 63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,15,0,255,255,255,255,255,255, | ||
| 119 | 255,255,255,255,127,0,255,255,255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 120 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,0,0,8,0,0,0,8,0,0,32,0,0,0,32,0,0,128, | ||
| 121 | 0,0,0,128,0,0,0,2,0,0,0,2,0,0,8,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255, | ||
| 122 | 255,255,255,255,255,255,255,255,255,15,0,248,254,255,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 123 | 0,0,0,0,127,0,0,128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 124 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,240,0, | ||
| 125 | 128,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,255,127,0,0,0,0,0,0,0, | ||
| 126 | 0,0,0,0,0,0,112,7,0,192,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 127 | 0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,31,0,0,0,0,0,0,0,0,0,254,255, | ||
| 128 | 255,255,255,255,255,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 129 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,3,0,255,255,255,255,255, | ||
| 130 | 15,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,127,254,255,254, | ||
| 131 | 255,254,255,255,255,63,0,255,31,255,255,255,255,0,0,0,252,0,0,0,28,0,0,0,252, | ||
| 132 | 255,255,255,31,0,0,0,0,0,0,192,255,255,255,7,0,255,255,255,255,255,15,255,1,3, | ||
| 133 | 0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 134 | 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 135 | 255,255,255,255,255,255,255,63,0,255,31,255,7,255,255,255,255,255,255,255,255, | ||
| 136 | 255,255,255,255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,1, | ||
| 137 | 255,15,0,0,255,15,255,255,255,255,255,255,255,0,255,3,255,255,255,255,255,0, | ||
| 138 | 255,255,255,63,0,0,0,0,0,0,0,0,0,0,255,239,255,255,255,255,255,255,255,255, | ||
| 139 | 255,255,255,255,123,252,255,255,255,255,231,199,255,255,255,231,255,255,255, | ||
| 140 | 255,255,255,255,255,255,255,255,255,255,255,255,255,15,0,255,63,15,7,7,0,63,0, | ||
| 141 | 0,0,0,0,0,0,0,0,0,0,0,0, | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/toascii.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | /* nonsense function that should NEVER be used! */ | ||
| 4 | int toascii(int c) | ||
| 5 | { | ||
| 6 | 	return c & 0x7f; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/tolower.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int tolower(int c) | ||
| 4 | { | ||
| 5 | 	if (isupper(c)) return c | 32; | ||
| 6 | 	return c; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __tolower_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return tolower(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__tolower_l, tolower_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/toupper.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | |||
| 3 | int toupper(int c) | ||
| 4 | { | ||
| 5 | 	if (islower(c)) return c & 0x5f; | ||
| 6 | 	return c; | ||
| 7 | } | ||
| 8 | |||
| 9 | int __toupper_l(int c, locale_t l) | ||
| 10 | { | ||
| 11 | 	return toupper(c); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__toupper_l, toupper_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/towctrans.c created+84| ... | @@ -0,0 +1,84 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | |||
| 3 | static const unsigned char tab[]; | ||
| 4 | |||
| 5 | static const unsigned char rulebases[512]; | ||
| 6 | static const int rules[]; | ||
| 7 | |||
| 8 | static const unsigned char exceptions[][2]; | ||
| 9 | |||
| 10 | #include "casemap.h" | ||
| 11 | |||
| 12 | static int casemap(unsigned c, int dir) | ||
| 13 | { | ||
| 14 | 	unsigned b, x, y, v, rt, xb, xn; | ||
| 15 | 	int r, rd, c0 = c; | ||
| 16 | |||
| 17 | 	if (c >= 0x20000) return c; | ||
| 18 | |||
| 19 | 	b = c>>8; | ||
| 20 | 	c &= 255; | ||
| 21 | 	x = c/3; | ||
| 22 | 	y = c%3; | ||
| 23 | |||
| 24 | 	/* lookup entry in two-level base-6 table */ | ||
| 25 | 	v = tab[tab[b]*86+x]; | ||
| 26 | 	static const int mt[] = { 2048, 342, 57 }; | ||
| 27 | 	v = (v*mt[y]>>11)%6; | ||
| 28 | |||
| 29 | 	/* use the bit vector out of the tables as an index into | ||
| 30 | 	 * a block-specific set of rules and decode the rule into | ||
| 31 | 	 * a type and a case-mapping delta. */ | ||
| 32 | 	r = rules[rulebases[b]+v]; | ||
| 33 | 	rt = r & 255; | ||
| 34 | 	rd = r >> 8; | ||
| 35 | |||
| 36 | 	/* rules 0/1 are simple lower/upper case with a delta. | ||
| 37 | 	 * apply according to desired mapping direction. */ | ||
| 38 | 	if (rt < 2) return c0 + (rd & -(rt^dir)); | ||
| 39 | |||
| 40 | 	/* binary search. endpoints of the binary search for | ||
| 41 | 	 * this block are stored in the rule delta field. */ | ||
| 42 | 	xn = rd & 0xff; | ||
| 43 | 	xb = (unsigned)rd >> 8; | ||
| 44 | 	while (xn) { | ||
| 45 | 		unsigned try = exceptions[xb+xn/2][0]; | ||
| 46 | 		if (try == c) { | ||
| 47 | 			r = rules[exceptions[xb+xn/2][1]]; | ||
| 48 | 			rt = r & 255; | ||
| 49 | 			rd = r >> 8; | ||
| 50 | 			if (rt < 2) return c0 + (rd & -(rt^dir)); | ||
| 51 | 			/* Hard-coded for the four exceptional titlecase */ | ||
| 52 | 			return c0 + (dir ? -1 : 1); | ||
| 53 | 		} else if (try > c) { | ||
| 54 | 			xn /= 2; | ||
| 55 | 		} else { | ||
| 56 | 			xb += xn/2; | ||
| 57 | 			xn -= xn/2; | ||
| 58 | 		} | ||
| 59 | 	} | ||
| 60 | 	return c0; | ||
| 61 | } | ||
| 62 | |||
| 63 | wint_t towlower(wint_t wc) | ||
| 64 | { | ||
| 65 | 	return casemap(wc, 0); | ||
| 66 | } | ||
| 67 | |||
| 68 | wint_t towupper(wint_t wc) | ||
| 69 | { | ||
| 70 | 	return casemap(wc, 1); | ||
| 71 | } | ||
| 72 | |||
| 73 | wint_t __towupper_l(wint_t c, locale_t l) | ||
| 74 | { | ||
| 75 | 	return towupper(c); | ||
| 76 | } | ||
| 77 | |||
| 78 | wint_t __towlower_l(wint_t c, locale_t l) | ||
| 79 | { | ||
| 80 | 	return towlower(c); | ||
| 81 | } | ||
| 82 | |||
| 83 | weak_alias(__towupper_l, towupper_l); | ||
| 84 | weak_alias(__towlower_l, towlower_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/wcswidth.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int wcswidth(const wchar_t *wcs, size_t n) | ||
| 4 | { | ||
| 5 | 	int l=0, k=0; | ||
| 6 | 	for (; n-- && *wcs && (k = wcwidth(*wcs)) >= 0; l+=k, wcs++); | ||
| 7 | 	return (k < 0) ? k : l; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/wctrans.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <wctype.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | wctrans_t wctrans(const char *class) | ||
| 5 | { | ||
| 6 | 	if (!strcmp(class, "toupper")) return (wctrans_t)1; | ||
| 7 | 	if (!strcmp(class, "tolower")) return (wctrans_t)2; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
| 10 | |||
| 11 | wint_t towctrans(wint_t wc, wctrans_t trans) | ||
| 12 | { | ||
| 13 | 	if (trans == (wctrans_t)1) return towupper(wc); | ||
| 14 | 	if (trans == (wctrans_t)2) return towlower(wc); | ||
| 15 | 	return wc; | ||
| 16 | } | ||
| 17 | |||
| 18 | wctrans_t __wctrans_l(const char *s, locale_t l) | ||
| 19 | { | ||
| 20 | 	return wctrans(s); | ||
| 21 | } | ||
| 22 | |||
| 23 | wint_t __towctrans_l(wint_t c, wctrans_t t, locale_t l) | ||
| 24 | { | ||
| 25 | 	return towctrans(c, t); | ||
| 26 | } | ||
| 27 | |||
| 28 | weak_alias(__wctrans_l, wctrans_l); | ||
| 29 | weak_alias(__towctrans_l, towctrans_l); | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/wcwidth.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | static const unsigned char table[] = { | ||
| 4 | #include "nonspacing.h" | ||
| 5 | }; | ||
| 6 | |||
| 7 | static const unsigned char wtable[] = { | ||
| 8 | #include "wide.h" | ||
| 9 | }; | ||
| 10 | |||
| 11 | int wcwidth(wchar_t wc) | ||
| 12 | { | ||
| 13 | 	if (wc < 0xffU) | ||
| 14 | 		return (wc+1 & 0x7f) >= 0x21 ? 1 : wc ? -1 : 0; | ||
| 15 | 	if ((wc & 0xfffeffffU) < 0xfffe) { | ||
| 16 | 		if ((table[table[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1) | ||
| 17 | 			return 0; | ||
| 18 | 		if ((wtable[wtable[wc>>8]*32+((wc&255)>>3)]>>(wc&7))&1) | ||
| 19 | 			return 2; | ||
| 20 | 		return 1; | ||
| 21 | 	} | ||
| 22 | 	if ((wc & 0xfffe) == 0xfffe) | ||
| 23 | 		return -1; | ||
| 24 | 	if (wc-0x20000U < 0x20000) | ||
| 25 | 		return 2; | ||
| 26 | 	if (wc == 0xe0001 || wc-0xe0020U < 0x5f || wc-0xe0100U < 0xef) | ||
| 27 | 		return 0; | ||
| 28 | 	return 1; | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ctype/wide.h created+65| ... | @@ -0,0 +1,65 @@ | ||
| 1 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,18,16,16,16,16,16,16,16,16, | ||
| 2 | 16,16,16,16,16,16,16,16,16,19,16,20,21,22,16,16,16,23,16,16,24,25,26,27,28,17, | ||
| 3 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,29, | ||
| 4 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 5 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 6 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 7 | 17,17,17,17,17,17,17,17,30,16,16,16,16,31,16,16,17,17,17,17,17,17,17,17,17,17, | ||
| 8 | 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 9 | 17,17,17,17,17,17,17,32,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 10 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,17,16,16,16,33, | ||
| 11 | 34,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 12 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 13 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 14 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 15 | 16,16,16,16,16,16,16,16,35,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17, | ||
| 16 | 17,17,17,17,17,17,36,17,17,37,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 17 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,17,38,39,16,16, | ||
| 18 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 19 | 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16, | ||
| 20 | 16,16,16,16,16,16,16,40,41,42,43,44,45,46,47,16,48,49,16,16,16,16, | ||
| 21 | 16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255, | ||
| 22 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 23 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 24 | 255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12,0,6,0,0,0,0, | ||
| 25 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,30,9,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 26 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,96,0,0,48,0,0,0,0,0,0,255,15,0,0,0,0,128,0,0,8, | ||
| 27 | 0,2,12,0,96,48,64,16,0,0,4,44,36,32,12,0,0,0,1,0,0,0,80,184,0,0,0,0,0,0,0,224, | ||
| 28 | 0,0,0,1,128,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,33,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 29 | 0,0,0,0,0,0,0, | ||
| 30 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,251,255,255,255,255,255,255,255, | ||
| 31 | 255,255,255,15,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 32 | 255,255,255,255,255,255,255,255,255,255,255,63,0,0,0,255,15,255,255,255,255, | ||
| 33 | 255,255,255,127,254,255,255,255,255,255,255,255,255,255,127,254,255,255,255, | ||
| 34 | 255,255,255,255,255,255,255,255,255,224,255,255,255,255,255,254,255,255,255, | ||
| 35 | 255,255,255,255,255,255,255,127,255,255,255,255,255,7,255,255,255,255,15,0, | ||
| 36 | 255,255,255,255,255,127,255,255,255,255,255,0,255,255,255,255,255,255,255,255, | ||
| 37 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 38 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,0, | ||
| 39 | 0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 40 | 255,31,255,255,255,255,255,255,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255, | ||
| 41 | 255,255,31,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 42 | 0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 43 | 255,15,0,0,0,0,0,0,0,0,0,0,0,0,0,255,3,0,0,255,255,255,255,247,255,127,15,0,0, | ||
| 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,254,255,255,255,255,255,255,255,255,255,255, | ||
| 45 | 255,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 46 | 0,0,0,0,0,0,0,0,0,0,0,0,15,0,0,0,255,255,255,255,255,255,255,255,255,255,255, | ||
| 47 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 48 | 255,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 49 | 255,255,255,255,255,255,255,255,255,255,255,255,7,0,255,255,255,127,0,0,0,0,0, | ||
| 50 | 0,7,0,240,0,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 51 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 52 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 53 | 15,16,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,128,0,0,0,0,0,0,0,0,0,0, | ||
| 54 | 0,0,0,0,0,0,0,0,0,0,0,0,0,64,254,7,0,0,0,0,0,0,0,0,0,0,0,0,7,0,255,255,255, | ||
| 55 | 255,255,15,255,1,3,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255, | ||
| 56 | 1,224,191,255,255,255,255,255,255,255,255,223,255,255,15,0,255,255,255,255, | ||
| 57 | 255,135,15,0,255,255,17,255,255,255,255,255,255,255,255,127,253,255,255,255, | ||
| 58 | 255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255, | ||
| 59 | 159,255,255,255,255,255,255,255,63,0,120,255,255,255,0,0,4,0,0,96,0,16,0,0,0, | ||
| 60 | 0,0,0,0,0,0,0,248,255,255,255,255,255,255,255,255,255,255,0,0,0,0,0,0,255,255, | ||
| 61 | 255,255,255,255,255,255,63,16,39,0,0,24,240,7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 62 | 0,0,0,0,0,0,0,0,0,0,0,0,255,15,0, | ||
| 63 | 0,0,224,255,255,255,255,255,255,255,255,255,255,255,255,123,252,255,255,255, | ||
| 64 | 255,231,199,255,255,255,231,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 65 | 0,15,7,7,0,63,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/__dirent.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | struct __dirstream | ||
| 2 | { | ||
| 3 | 	off_t tell; | ||
| 4 | 	int fd; | ||
| 5 | 	int buf_pos; | ||
| 6 | 	int buf_end; | ||
| 7 | 	volatile int lock[1]; | ||
| 8 | 	/* Any changes to this struct must preserve the property: | ||
| 9 | 	 * offsetof(struct __dirent, buf) % sizeof(off_t) == 0 */ | ||
| 10 | 	char buf[2048]; | ||
| 11 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/alphasort.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 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/closedir.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include "__dirent.h" | ||
| 5 | |||
| 6 | int closedir(DIR *dir) | ||
| 7 | { | ||
| 8 | 	int ret = close(dir->fd); | ||
| 9 | 	free(dir); | ||
| 10 | 	return ret; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/dirfd.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include "__dirent.h" | ||
| 3 | |||
| 4 | int dirfd(DIR *d) | ||
| 5 | { | ||
| 6 | 	return d->fd; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/fdopendir.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <sys/stat.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include "__dirent.h" | ||
| 7 | |||
| 8 | DIR *fdopendir(int fd) | ||
| 9 | { | ||
| 10 | 	DIR *dir; | ||
| 11 | 	struct stat st; | ||
| 12 | |||
| 13 | 	if (fstat(fd, &st) < 0) { | ||
| 14 | 		return 0; | ||
| 15 | 	} | ||
| 16 | 	if (fcntl(fd, F_GETFL) & O_PATH) { | ||
| 17 | 		errno = EBADF; | ||
| 18 | 		return 0; | ||
| 19 | 	} | ||
| 20 | 	if (!S_ISDIR(st.st_mode)) { | ||
| 21 | 		errno = ENOTDIR; | ||
| 22 | 		return 0; | ||
| 23 | 	} | ||
| 24 | 	if (!(dir = calloc(1, sizeof *dir))) { | ||
| 25 | 		return 0; | ||
| 26 | 	} | ||
| 27 | |||
| 28 | 	fcntl(fd, F_SETFD, FD_CLOEXEC); | ||
| 29 | 	dir->fd = fd; | ||
| 30 | 	return dir; | ||
| 31 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/opendir.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <dirent.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include "__dirent.h" | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | DIR *opendir(const char *name) | ||
| 9 | { | ||
| 10 | 	int fd; | ||
| 11 | 	DIR *dir; | ||
| 12 | |||
| 13 | 	if ((fd = open(name, O_RDONLY|O_DIRECTORY|O_CLOEXEC)) < 0) | ||
| 14 | 		return 0; | ||
| 15 | 	if (!(dir = calloc(1, sizeof *dir))) { | ||
| 16 | 		__syscall(SYS_close, fd); | ||
| 17 | 		return 0; | ||
| 18 | 	} | ||
| 19 | 	dir->fd = fd; | ||
| 20 | 	return dir; | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/readdir.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <stddef.h> | ||
| 4 | #include "__dirent.h" | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | typedef char dirstream_buf_alignment_check[1-2*(int)( | ||
| 8 | 	offsetof(struct __dirstream, buf) % sizeof(off_t))]; | ||
| 9 | |||
| 10 | struct dirent *readdir(DIR *dir) | ||
| 11 | { | ||
| 12 | 	struct dirent *de; | ||
| 13 | 	 | ||
| 14 | 	if (dir->buf_pos >= dir->buf_end) { | ||
| 15 | 		int len = __syscall(SYS_getdents, dir->fd, dir->buf, sizeof dir->buf); | ||
| 16 | 		if (len <= 0) { | ||
| 17 | 			if (len < 0 && len != -ENOENT) errno = -len; | ||
| 18 | 			return 0; | ||
| 19 | 		} | ||
| 20 | 		dir->buf_end = len; | ||
| 21 | 		dir->buf_pos = 0; | ||
| 22 | 	} | ||
| 23 | 	de = (void *)(dir->buf + dir->buf_pos); | ||
| 24 | 	dir->buf_pos += de->d_reclen; | ||
| 25 | 	dir->tell = de->d_off; | ||
| 26 | 	return de; | ||
| 27 | } | ||
| 28 | |||
| 29 | weak_alias(readdir, readdir64); | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/readdir_r.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "__dirent.h" | ||
| 5 | #include "lock.h" | ||
| 6 | |||
| 7 | int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **restrict result) | ||
| 8 | { | ||
| 9 | 	struct dirent *de; | ||
| 10 | 	int errno_save = errno; | ||
| 11 | 	int ret; | ||
| 12 | 	 | ||
| 13 | 	LOCK(dir->lock); | ||
| 14 | 	errno = 0; | ||
| 15 | 	de = readdir(dir); | ||
| 16 | 	if ((ret = errno)) { | ||
| 17 | 		UNLOCK(dir->lock); | ||
| 18 | 		return ret; | ||
| 19 | 	} | ||
| 20 | 	errno = errno_save; | ||
| 21 | 	if (de) memcpy(buf, de, de->d_reclen); | ||
| 22 | 	else buf = NULL; | ||
| 23 | |||
| 24 | 	UNLOCK(dir->lock); | ||
| 25 | 	*result = buf; | ||
| 26 | 	return 0; | ||
| 27 | } | ||
| 28 | |||
| 29 | weak_alias(readdir_r, readdir64_r); | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/rewinddir.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "__dirent.h" | ||
| 4 | #include "lock.h" | ||
| 5 | |||
| 6 | void rewinddir(DIR *dir) | ||
| 7 | { | ||
| 8 | 	LOCK(dir->lock); | ||
| 9 | 	lseek(dir->fd, 0, SEEK_SET); | ||
| 10 | 	dir->buf_pos = dir->buf_end = 0; | ||
| 11 | 	dir->tell = 0; | ||
| 12 | 	UNLOCK(dir->lock); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/scandir.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <stddef.h> | ||
| 7 | |||
| 8 | int scandir(const char *path, struct dirent ***res, | ||
| 9 | 	int (*sel)(const struct dirent *), | ||
| 10 | 	int (*cmp)(const struct dirent **, const struct dirent **)) | ||
| 11 | { | ||
| 12 | 	DIR *d = opendir(path); | ||
| 13 | 	struct dirent *de, **names=0, **tmp; | ||
| 14 | 	size_t cnt=0, len=0; | ||
| 15 | 	int old_errno = errno; | ||
| 16 | |||
| 17 | 	if (!d) return -1; | ||
| 18 | |||
| 19 | 	while ((errno=0), (de = readdir(d))) { | ||
| 20 | 		if (sel && !sel(de)) continue; | ||
| 21 | 		if (cnt >= len) { | ||
| 22 | 			len = 2*len+1; | ||
| 23 | 			if (len > SIZE_MAX/sizeof *names) break; | ||
| 24 | 			tmp = realloc(names, len * sizeof *names); | ||
| 25 | 			if (!tmp) break; | ||
| 26 | 			names = tmp; | ||
| 27 | 		} | ||
| 28 | 		names[cnt] = malloc(de->d_reclen); | ||
| 29 | 		if (!names[cnt]) break; | ||
| 30 | 		memcpy(names[cnt++], de, de->d_reclen); | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	closedir(d); | ||
| 34 | |||
| 35 | 	if (errno) { | ||
| 36 | 		if (names) while (cnt-->0) free(names[cnt]); | ||
| 37 | 		free(names); | ||
| 38 | 		return -1; | ||
| 39 | 	} | ||
| 40 | 	errno = old_errno; | ||
| 41 | |||
| 42 | 	if (cmp) qsort(names, cnt, sizeof *names, (int (*)(const void *, const void *))cmp); | ||
| 43 | 	*res = names; | ||
| 44 | 	return cnt; | ||
| 45 | } | ||
| 46 | |||
| 47 | weak_alias(scandir, scandir64); | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/seekdir.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "__dirent.h" | ||
| 4 | #include "lock.h" | ||
| 5 | |||
| 6 | void seekdir(DIR *dir, long off) | ||
| 7 | { | ||
| 8 | 	LOCK(dir->lock); | ||
| 9 | 	dir->tell = lseek(dir->fd, off, SEEK_SET); | ||
| 10 | 	dir->buf_pos = dir->buf_end = 0; | ||
| 11 | 	UNLOCK(dir->lock); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/telldir.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <dirent.h> | ||
| 2 | #include "__dirent.h" | ||
| 3 | |||
| 4 | long telldir(DIR *dir) | ||
| 5 | { | ||
| 6 | 	return dir->tell; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/dirent/versionsort.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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/__environ.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | char **__environ = 0; | ||
| 4 | weak_alias(__environ, ___environ); | ||
| 5 | weak_alias(__environ, _environ); | ||
| 6 | weak_alias(__environ, environ); | ||
lib/libc/wasi/libc-top-half/musl/src/env/__init_tls.c created+153| ... | @@ -0,0 +1,153 @@ | ||
| 1 | #define SYSCALL_NO_TLS 1 | ||
| 2 | #include <elf.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <sys/mman.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stddef.h> | ||
| 7 | #include "pthread_impl.h" | ||
| 8 | #include "libc.h" | ||
| 9 | #include "atomic.h" | ||
| 10 | #include "syscall.h" | ||
| 11 | |||
| 12 | volatile int __thread_list_lock; | ||
| 13 | |||
| 14 | int __init_tp(void *p) | ||
| 15 | { | ||
| 16 | 	pthread_t td = p; | ||
| 17 | 	td->self = td; | ||
| 18 | 	int r = __set_thread_area(TP_ADJ(p)); | ||
| 19 | 	if (r < 0) return -1; | ||
| 20 | 	if (!r) libc.can_do_threads = 1; | ||
| 21 | 	td->detach_state = DT_JOINABLE; | ||
| 22 | 	td->tid = __syscall(SYS_set_tid_address, &__thread_list_lock); | ||
| 23 | 	td->locale = &libc.global_locale; | ||
| 24 | 	td->robust_list.head = &td->robust_list.head; | ||
| 25 | 	td->sysinfo = __sysinfo; | ||
| 26 | 	td->next = td->prev = td; | ||
| 27 | 	return 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | static struct builtin_tls { | ||
| 31 | 	char c; | ||
| 32 | 	struct pthread pt; | ||
| 33 | 	void *space[16]; | ||
| 34 | } builtin_tls[1]; | ||
| 35 | #define MIN_TLS_ALIGN offsetof(struct builtin_tls, pt) | ||
| 36 | |||
| 37 | static struct tls_module main_tls; | ||
| 38 | |||
| 39 | void *__copy_tls(unsigned char *mem) | ||
| 40 | { | ||
| 41 | 	pthread_t td; | ||
| 42 | 	struct tls_module *p; | ||
| 43 | 	size_t i; | ||
| 44 | 	uintptr_t *dtv; | ||
| 45 | |||
| 46 | #ifdef TLS_ABOVE_TP | ||
| 47 | 	dtv = (uintptr_t*)(mem + libc.tls_size) - (libc.tls_cnt + 1); | ||
| 48 | |||
| 49 | 	mem += -((uintptr_t)mem + sizeof(struct pthread)) & (libc.tls_align-1); | ||
| 50 | 	td = (pthread_t)mem; | ||
| 51 | 	mem += sizeof(struct pthread); | ||
| 52 | |||
| 53 | 	for (i=1, p=libc.tls_head; p; i++, p=p->next) { | ||
| 54 | 		dtv[i] = (uintptr_t)(mem + p->offset) + DTP_OFFSET; | ||
| 55 | 		memcpy(mem + p->offset, p->image, p->len); | ||
| 56 | 	} | ||
| 57 | #else | ||
| 58 | 	dtv = (uintptr_t *)mem; | ||
| 59 | |||
| 60 | 	mem += libc.tls_size - sizeof(struct pthread); | ||
| 61 | 	mem -= (uintptr_t)mem & (libc.tls_align-1); | ||
| 62 | 	td = (pthread_t)mem; | ||
| 63 | |||
| 64 | 	for (i=1, p=libc.tls_head; p; i++, p=p->next) { | ||
| 65 | 		dtv[i] = (uintptr_t)(mem - p->offset) + DTP_OFFSET; | ||
| 66 | 		memcpy(mem - p->offset, p->image, p->len); | ||
| 67 | 	} | ||
| 68 | #endif | ||
| 69 | 	dtv[0] = libc.tls_cnt; | ||
| 70 | 	td->dtv = dtv; | ||
| 71 | 	return td; | ||
| 72 | } | ||
| 73 | |||
| 74 | #if ULONG_MAX == 0xffffffff | ||
| 75 | typedef Elf32_Phdr Phdr; | ||
| 76 | #else | ||
| 77 | typedef Elf64_Phdr Phdr; | ||
| 78 | #endif | ||
| 79 | |||
| 80 | extern weak hidden const size_t _DYNAMIC[]; | ||
| 81 | |||
| 82 | static void static_init_tls(size_t *aux) | ||
| 83 | { | ||
| 84 | 	unsigned char *p; | ||
| 85 | 	size_t n; | ||
| 86 | 	Phdr *phdr, *tls_phdr=0; | ||
| 87 | 	size_t base = 0; | ||
| 88 | 	void *mem; | ||
| 89 | |||
| 90 | 	for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { | ||
| 91 | 		phdr = (void *)p; | ||
| 92 | 		if (phdr->p_type == PT_PHDR) | ||
| 93 | 			base = aux[AT_PHDR] - phdr->p_vaddr; | ||
| 94 | 		if (phdr->p_type == PT_DYNAMIC && _DYNAMIC) | ||
| 95 | 			base = (size_t)_DYNAMIC - phdr->p_vaddr; | ||
| 96 | 		if (phdr->p_type == PT_TLS) | ||
| 97 | 			tls_phdr = phdr; | ||
| 98 | 		if (phdr->p_type == PT_GNU_STACK && | ||
| 99 | 		 phdr->p_memsz > __default_stacksize) | ||
| 100 | 			__default_stacksize = | ||
| 101 | 				phdr->p_memsz < DEFAULT_STACK_MAX ? | ||
| 102 | 				phdr->p_memsz : DEFAULT_STACK_MAX; | ||
| 103 | 	} | ||
| 104 | |||
| 105 | 	if (tls_phdr) { | ||
| 106 | 		main_tls.image = (void *)(base + tls_phdr->p_vaddr); | ||
| 107 | 		main_tls.len = tls_phdr->p_filesz; | ||
| 108 | 		main_tls.size = tls_phdr->p_memsz; | ||
| 109 | 		main_tls.align = tls_phdr->p_align; | ||
| 110 | 		libc.tls_cnt = 1; | ||
| 111 | 		libc.tls_head = &main_tls; | ||
| 112 | 	} | ||
| 113 | |||
| 114 | 	main_tls.size += (-main_tls.size - (uintptr_t)main_tls.image) | ||
| 115 | 		& (main_tls.align-1); | ||
| 116 | #ifdef TLS_ABOVE_TP | ||
| 117 | 	main_tls.offset = GAP_ABOVE_TP; | ||
| 118 | 	main_tls.offset += (-GAP_ABOVE_TP + (uintptr_t)main_tls.image) | ||
| 119 | 		& (main_tls.align-1); | ||
| 120 | #else | ||
| 121 | 	main_tls.offset = main_tls.size; | ||
| 122 | #endif | ||
| 123 | 	if (main_tls.align < MIN_TLS_ALIGN) main_tls.align = MIN_TLS_ALIGN; | ||
| 124 | |||
| 125 | 	libc.tls_align = main_tls.align; | ||
| 126 | 	libc.tls_size = 2*sizeof(void *) + sizeof(struct pthread) | ||
| 127 | #ifdef TLS_ABOVE_TP | ||
| 128 | 		+ main_tls.offset | ||
| 129 | #endif | ||
| 130 | 		+ main_tls.size + main_tls.align | ||
| 131 | 		+ MIN_TLS_ALIGN-1 & -MIN_TLS_ALIGN; | ||
| 132 | |||
| 133 | 	if (libc.tls_size > sizeof builtin_tls) { | ||
| 134 | #ifndef SYS_mmap2 | ||
| 135 | #define SYS_mmap2 SYS_mmap | ||
| 136 | #endif | ||
| 137 | 		mem = (void *)__syscall( | ||
| 138 | 			SYS_mmap2, | ||
| 139 | 			0, libc.tls_size, PROT_READ|PROT_WRITE, | ||
| 140 | 			MAP_ANONYMOUS|MAP_PRIVATE, -1, 0); | ||
| 141 | 		/* -4095...-1 cast to void * will crash on dereference anyway, | ||
| 142 | 		 * so don't bloat the init code checking for error codes and | ||
| 143 | 		 * explicitly calling a_crash(). */ | ||
| 144 | 	} else { | ||
| 145 | 		mem = builtin_tls; | ||
| 146 | 	} | ||
| 147 | |||
| 148 | 	/* Failure to initialize thread pointer is always fatal. */ | ||
| 149 | 	if (__init_tp(__copy_tls(mem)) < 0) | ||
| 150 | 		a_crash(); | ||
| 151 | } | ||
| 152 | |||
| 153 | weak_alias(static_init_tls, __init_tls); | ||
lib/libc/wasi/libc-top-half/musl/src/env/__libc_start_main.c created+96| ... | @@ -0,0 +1,96 @@ | ||
| 1 | #include <elf.h> | ||
| 2 | #include <poll.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <signal.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | #include "atomic.h" | ||
| 8 | #include "libc.h" | ||
| 9 | |||
| 10 | static void dummy(void) {} | ||
| 11 | weak_alias(dummy, _init); | ||
| 12 | |||
| 13 | extern weak hidden void (*const __init_array_start)(void), (*const __init_array_end)(void); | ||
| 14 | |||
| 15 | static void dummy1(void *p) {} | ||
| 16 | weak_alias(dummy1, __init_ssp); | ||
| 17 | |||
| 18 | #define AUX_CNT 38 | ||
| 19 | |||
| 20 | #ifdef __GNUC__ | ||
| 21 | __attribute__((__noinline__)) | ||
| 22 | #endif | ||
| 23 | void __init_libc(char **envp, char *pn) | ||
| 24 | { | ||
| 25 | 	size_t i, *auxv, aux[AUX_CNT] = { 0 }; | ||
| 26 | 	__environ = envp; | ||
| 27 | 	for (i=0; envp[i]; i++); | ||
| 28 | 	libc.auxv = auxv = (void *)(envp+i+1); | ||
| 29 | 	for (i=0; auxv[i]; i+=2) if (auxv[i]<AUX_CNT) aux[auxv[i]] = auxv[i+1]; | ||
| 30 | 	__hwcap = aux[AT_HWCAP]; | ||
| 31 | 	if (aux[AT_SYSINFO]) __sysinfo = aux[AT_SYSINFO]; | ||
| 32 | 	libc.page_size = aux[AT_PAGESZ]; | ||
| 33 | |||
| 34 | 	if (!pn) pn = (void*)aux[AT_EXECFN]; | ||
| 35 | 	if (!pn) pn = ""; | ||
| 36 | 	__progname = __progname_full = pn; | ||
| 37 | 	for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1; | ||
| 38 | |||
| 39 | 	__init_tls(aux); | ||
| 40 | 	__init_ssp((void *)aux[AT_RANDOM]); | ||
| 41 | |||
| 42 | 	if (aux[AT_UID]==aux[AT_EUID] && aux[AT_GID]==aux[AT_EGID] | ||
| 43 | 		&& !aux[AT_SECURE]) return; | ||
| 44 | |||
| 45 | 	struct pollfd pfd[3] = { {.fd=0}, {.fd=1}, {.fd=2} }; | ||
| 46 | 	int r = | ||
| 47 | #ifdef SYS_poll | ||
| 48 | 	__syscall(SYS_poll, pfd, 3, 0); | ||
| 49 | #else | ||
| 50 | 	__syscall(SYS_ppoll, pfd, 3, &(struct timespec){0}, 0, _NSIG/8); | ||
| 51 | #endif | ||
| 52 | 	if (r<0) a_crash(); | ||
| 53 | 	for (i=0; i<3; i++) if (pfd[i].revents&POLLNVAL) | ||
| 54 | 		if (__sys_open("/dev/null", O_RDWR)<0) | ||
| 55 | 			a_crash(); | ||
| 56 | 	libc.secure = 1; | ||
| 57 | } | ||
| 58 | |||
| 59 | static void libc_start_init(void) | ||
| 60 | { | ||
| 61 | 	_init(); | ||
| 62 | 	uintptr_t a = (uintptr_t)&__init_array_start; | ||
| 63 | 	for (; a<(uintptr_t)&__init_array_end; a+=sizeof(void(*)())) | ||
| 64 | 		(*(void (**)(void))a)(); | ||
| 65 | } | ||
| 66 | |||
| 67 | weak_alias(libc_start_init, __libc_start_init); | ||
| 68 | |||
| 69 | typedef int lsm2_fn(int (*)(int,char **,char **), int, char **); | ||
| 70 | static lsm2_fn libc_start_main_stage2; | ||
| 71 | |||
| 72 | int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv) | ||
| 73 | { | ||
| 74 | 	char **envp = argv+argc+1; | ||
| 75 | |||
| 76 | 	/* External linkage, and explicit noinline attribute if available, | ||
| 77 | 	 * are used to prevent the stack frame used during init from | ||
| 78 | 	 * persisting for the entire process lifetime. */ | ||
| 79 | 	__init_libc(envp, argv[0]); | ||
| 80 | |||
| 81 | 	/* Barrier against hoisting application code or anything using ssp | ||
| 82 | 	 * or thread pointer prior to its initialization above. */ | ||
| 83 | 	lsm2_fn *stage2 = libc_start_main_stage2; | ||
| 84 | 	__asm__ ( "" : "+r"(stage2) : : "memory" ); | ||
| 85 | 	return stage2(main, argc, argv); | ||
| 86 | } | ||
| 87 | |||
| 88 | static int libc_start_main_stage2(int (*main)(int,char **,char **), int argc, char **argv) | ||
| 89 | { | ||
| 90 | 	char **envp = argv+argc+1; | ||
| 91 | 	__libc_start_init(); | ||
| 92 | |||
| 93 | 	/* Pass control to the application */ | ||
| 94 | 	exit(main(argc, argv, envp)); | ||
| 95 | 	return 0; | ||
| 96 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/__reset_tls.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | void __reset_tls() | ||
| 6 | { | ||
| 7 | 	pthread_t self = __pthread_self(); | ||
| 8 | 	struct tls_module *p; | ||
| 9 | 	size_t i, n = self->dtv[0]; | ||
| 10 | 	if (n) for (p=libc.tls_head, i=1; i<=n; i++, p=p->next) { | ||
| 11 | 		char *mem = (char *)(self->dtv[i] - DTP_OFFSET); | ||
| 12 | 		memcpy(mem, p->image, p->len); | ||
| 13 | 		memset(mem+p->len, 0, p->size - p->len); | ||
| 14 | 	} | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | uintptr_t __stack_chk_guard; | ||
| 6 | |||
| 7 | void __init_ssp(void *entropy) | ||
| 8 | { | ||
| 9 | 	if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t)); | ||
| 10 | 	else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245; | ||
| 11 | |||
| 12 | 	__pthread_self()->canary = __stack_chk_guard; | ||
| 13 | } | ||
| 14 | |||
| 15 | void __stack_chk_fail(void) | ||
| 16 | { | ||
| 17 | 	a_crash(); | ||
| 18 | } | ||
| 19 | |||
| 20 | hidden void __stack_chk_fail_local(void); | ||
| 21 | |||
| 22 | weak_alias(__stack_chk_fail, __stack_chk_fail_local); | ||
lib/libc/wasi/libc-top-half/musl/src/env/clearenv.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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 created+53| ... | @@ -0,0 +1,53 @@ | ||
| 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/secure_getenv.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | char *secure_getenv(const char *name) | ||
| 6 | { | ||
| 7 | 	return libc.secure ? NULL : getenv(name); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/setenv.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | void __env_rm_add(char *old, char *new) | ||
| 6 | { | ||
| 7 | 	static char **env_alloced; | ||
| 8 | 	static size_t env_alloced_n; | ||
| 9 | 	for (size_t i=0; i < env_alloced_n; i++) | ||
| 10 | 		if (env_alloced[i] == old) { | ||
| 11 | 			env_alloced[i] = new; | ||
| 12 | 			free(old); | ||
| 13 | 			return; | ||
| 14 | 		} else if (!env_alloced[i] && new) { | ||
| 15 | 			env_alloced[i] = new; | ||
| 16 | 			new = 0; | ||
| 17 | 		} | ||
| 18 | 	if (!new) return; | ||
| 19 | 	char **t = realloc(env_alloced, sizeof *t * (env_alloced_n+1)); | ||
| 20 | 	if (!t) return; | ||
| 21 | 	(env_alloced = t)[env_alloced_n++] = new; | ||
| 22 | } | ||
| 23 | |||
| 24 | int setenv(const char *var, const char *value, int overwrite) | ||
| 25 | { | ||
| 26 | 	char *s; | ||
| 27 | 	size_t l1, l2; | ||
| 28 | |||
| 29 | 	if (!var || !(l1 = __strchrnul(var, '=') - var) || var[l1]) { | ||
| 30 | 		errno = EINVAL; | ||
| 31 | 		return -1; | ||
| 32 | 	} | ||
| 33 | 	if (!overwrite && getenv(var)) return 0; | ||
| 34 | |||
| 35 | 	l2 = strlen(value); | ||
| 36 | 	s = malloc(l1+l2+2); | ||
| 37 | 	if (!s) return -1; | ||
| 38 | 	memcpy(s, var, l1); | ||
| 39 | 	s[l1] = '='; | ||
| 40 | 	memcpy(s+l1+1, value, l2+1); | ||
| 41 | 	return __putenv(s, l1, s); | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/env/unsetenv.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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/__errno_location.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | int *__errno_location(void) | ||
| 5 | { | ||
| 6 | 	return &__pthread_self()->errno_val; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__errno_location, ___errno_location); | ||
lib/libc/wasi/libc-top-half/musl/src/errno/__strerror.h created+131| ... | @@ -0,0 +1,131 @@ | ||
| 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 in WASI and not musl | ||
| 128 | #else | ||
| 129 | // WASI adds this errno code. | ||
| 130 | E(ENOTCAPABLE, "Capabilities insufficient") | ||
| 131 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/errno/strerror.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 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/_Exit.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | _Noreturn void _Exit(int ec) | ||
| 5 | { | ||
| 6 | 	__syscall(SYS_exit_group, ec); | ||
| 7 | 	for (;;) __syscall(SYS_exit, ec); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/abort.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | #include "atomic.h" | ||
| 6 | #include "lock.h" | ||
| 7 | #include "ksigaction.h" | ||
| 8 | |||
| 9 | _Noreturn void abort(void) | ||
| 10 | { | ||
| 11 | 	raise(SIGABRT); | ||
| 12 | |||
| 13 | 	/* If there was a SIGABRT handler installed and it returned, or if | ||
| 14 | 	 * SIGABRT was blocked or ignored, take an AS-safe lock to prevent | ||
| 15 | 	 * sigaction from installing a new SIGABRT handler, uninstall any | ||
| 16 | 	 * handler that may be present, and re-raise the signal to generate | ||
| 17 | 	 * the default action of abnormal termination. */ | ||
| 18 | 	__block_all_sigs(0); | ||
| 19 | 	LOCK(__abort_lock); | ||
| 20 | 	__syscall(SYS_rt_sigaction, SIGABRT, | ||
| 21 | 		&(struct k_sigaction){.handler = SIG_DFL}, 0, _NSIG/8); | ||
| 22 | 	__syscall(SYS_tkill, __pthread_self()->tid, SIGABRT); | ||
| 23 | 	__syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, | ||
| 24 | 		&(long[_NSIG/(8*sizeof(long))]){1UL<<(SIGABRT-1)}, 0, _NSIG/8); | ||
| 25 | |||
| 26 | 	/* Beyond this point should be unreachable. */ | ||
| 27 | 	a_crash(); | ||
| 28 | 	raise(SIGKILL); | ||
| 29 | 	_Exit(127); | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/abort_lock.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | volatile int __abort_lock[1]; | ||
lib/libc/wasi/libc-top-half/musl/src/exit/arm/__aeabi_atexit.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | int __cxa_atexit(void (*func)(void *), void *arg, void *dso); | ||
| 2 | |||
| 3 | int __aeabi_atexit (void *obj, void (*func) (void *), void *d) | ||
| 4 | { | ||
| 5 | 	return __cxa_atexit (func, obj, d); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/assert.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | _Noreturn void __assert_fail(const char *expr, const char *file, int line, const char *func) | ||
| 5 | { | ||
| 6 | 	fprintf(stderr, "Assertion failed: %s (%s: %s: %d)\n", expr, file, func, line); | ||
| 7 | 	abort(); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/at_quick_exit.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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 created+82| ... | @@ -0,0 +1,82 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "libc.h" | ||
| 4 | #include "lock.h" | ||
| 5 | #include "fork_impl.h" | ||
| 6 | |||
| 7 | #define malloc __libc_malloc | ||
| 8 | #define calloc __libc_calloc | ||
| 9 | #define realloc undef | ||
| 10 | #define free undef | ||
| 11 | |||
| 12 | /* Ensure that at least 32 atexit handlers can be registered without malloc */ | ||
| 13 | #define COUNT 32 | ||
| 14 | |||
| 15 | static struct fl | ||
| 16 | { | ||
| 17 | 	struct fl *next; | ||
| 18 | 	void (*f[COUNT])(void *); | ||
| 19 | 	void *a[COUNT]; | ||
| 20 | } builtin, *head; | ||
| 21 | |||
| 22 | static int slot; | ||
| 23 | |||
| 24 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 25 | static volatile int lock[1]; | ||
| 26 | volatile int *const __atexit_lockptr = lock; | ||
| 27 | #endif | ||
| 28 | |||
| 29 | void __funcs_on_exit() | ||
| 30 | { | ||
| 31 | 	void (*func)(void *), *arg; | ||
| 32 | 	LOCK(lock); | ||
| 33 | 	for (; head; head=head->next, slot=COUNT) while(slot-->0) { | ||
| 34 | 		func = head->f[slot]; | ||
| 35 | 		arg = head->a[slot]; | ||
| 36 | 		UNLOCK(lock); | ||
| 37 | 		func(arg); | ||
| 38 | 		LOCK(lock); | ||
| 39 | 	} | ||
| 40 | } | ||
| 41 | |||
| 42 | void __cxa_finalize(void *dso) | ||
| 43 | { | ||
| 44 | } | ||
| 45 | |||
| 46 | int __cxa_atexit(void (*func)(void *), void *arg, void *dso) | ||
| 47 | { | ||
| 48 | 	LOCK(lock); | ||
| 49 | |||
| 50 | 	/* Defer initialization of head so it can be in BSS */ | ||
| 51 | 	if (!head) head = &builtin; | ||
| 52 | |||
| 53 | 	/* If the current function list is full, add a new one */ | ||
| 54 | 	if (slot==COUNT) { | ||
| 55 | 		struct fl *new_fl = calloc(sizeof(struct fl), 1); | ||
| 56 | 		if (!new_fl) { | ||
| 57 | 			UNLOCK(lock); | ||
| 58 | 			return -1; | ||
| 59 | 		} | ||
| 60 | 		new_fl->next = head; | ||
| 61 | 		head = new_fl; | ||
| 62 | 		slot = 0; | ||
| 63 | 	} | ||
| 64 | |||
| 65 | 	/* Append function to the list. */ | ||
| 66 | 	head->f[slot] = func; | ||
| 67 | 	head->a[slot] = arg; | ||
| 68 | 	slot++; | ||
| 69 | |||
| 70 | 	UNLOCK(lock); | ||
| 71 | 	return 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | static void call(void *p) | ||
| 75 | { | ||
| 76 | 	((void (*)(void))(uintptr_t)p)(); | ||
| 77 | } | ||
| 78 | |||
| 79 | int atexit(void (*func)(void)) | ||
| 80 | { | ||
| 81 | 	return __cxa_atexit(call, (void *)(uintptr_t)func, 0); | ||
| 82 | } | ||
lib/libc/wasi/libc-top-half/musl/src/exit/exit.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 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/exit/quick_exit.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include "libc.h" | ||
| 3 | |||
| 4 | static void dummy() { } | ||
| 5 | weak_alias(dummy, __funcs_on_quick_exit); | ||
| 6 | |||
| 7 | _Noreturn void quick_exit(int code) | ||
| 8 | { | ||
| 9 | 	__funcs_on_quick_exit(); | ||
| 10 | 	_Exit(code); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fcntl/creat.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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/fcntl/fcntl.c created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int fcntl(int fd, int cmd, ...) | ||
| 8 | { | ||
| 9 | 	unsigned long arg; | ||
| 10 | 	va_list ap; | ||
| 11 | 	va_start(ap, cmd); | ||
| 12 | 	arg = va_arg(ap, unsigned long); | ||
| 13 | 	va_end(ap); | ||
| 14 | 	if (cmd == F_SETFL) arg |= O_LARGEFILE; | ||
| 15 | 	if (cmd == F_SETLKW) return syscall_cp(SYS_fcntl, fd, cmd, (void *)arg); | ||
| 16 | 	if (cmd == F_GETOWN) { | ||
| 17 | 		struct f_owner_ex ex; | ||
| 18 | 		int ret = __syscall(SYS_fcntl, fd, F_GETOWN_EX, &ex); | ||
| 19 | 		if (ret == -EINVAL) return __syscall(SYS_fcntl, fd, cmd, (void *)arg); | ||
| 20 | 		if (ret) return __syscall_ret(ret); | ||
| 21 | 		return ex.type == F_OWNER_PGRP ? -ex.pid : ex.pid; | ||
| 22 | 	} | ||
| 23 | 	if (cmd == F_DUPFD_CLOEXEC) { | ||
| 24 | 		int ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, arg); | ||
| 25 | 		if (ret != -EINVAL) { | ||
| 26 | 			if (ret >= 0) | ||
| 27 | 				__syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); | ||
| 28 | 			return __syscall_ret(ret); | ||
| 29 | 		} | ||
| 30 | 		ret = __syscall(SYS_fcntl, fd, F_DUPFD_CLOEXEC, 0); | ||
| 31 | 		if (ret != -EINVAL) { | ||
| 32 | 			if (ret >= 0) __syscall(SYS_close, ret); | ||
| 33 | 			return __syscall_ret(-EINVAL); | ||
| 34 | 		} | ||
| 35 | 		ret = __syscall(SYS_fcntl, fd, F_DUPFD, arg); | ||
| 36 | 		if (ret >= 0) __syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); | ||
| 37 | 		return __syscall_ret(ret); | ||
| 38 | 	} | ||
| 39 | 	switch (cmd) { | ||
| 40 | 	case F_SETLK: | ||
| 41 | 	case F_GETLK: | ||
| 42 | 	case F_GETOWN_EX: | ||
| 43 | 	case F_SETOWN_EX: | ||
| 44 | 		return syscall(SYS_fcntl, fd, cmd, (void *)arg); | ||
| 45 | 	default: | ||
| 46 | 		return syscall(SYS_fcntl, fd, cmd, arg); | ||
| 47 | 	} | ||
| 48 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fcntl/open.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int open(const char *filename, int flags, ...) | ||
| 6 | { | ||
| 7 | 	mode_t mode = 0; | ||
| 8 | |||
| 9 | 	if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { | ||
| 10 | 		va_list ap; | ||
| 11 | 		va_start(ap, flags); | ||
| 12 | 		mode = va_arg(ap, mode_t); | ||
| 13 | 		va_end(ap); | ||
| 14 | 	} | ||
| 15 | |||
| 16 | 	int fd = __sys_open_cp(filename, flags, mode); | ||
| 17 | 	if (fd>=0 && (flags & O_CLOEXEC)) | ||
| 18 | 		__syscall(SYS_fcntl, fd, F_SETFD, FD_CLOEXEC); | ||
| 19 | |||
| 20 | 	return __syscall_ret(fd); | ||
| 21 | } | ||
| 22 | |||
| 23 | weak_alias(open, open64); | ||
lib/libc/wasi/libc-top-half/musl/src/fcntl/openat.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int openat(int fd, const char *filename, int flags, ...) | ||
| 6 | { | ||
| 7 | 	mode_t mode = 0; | ||
| 8 | |||
| 9 | 	if ((flags & O_CREAT) || (flags & O_TMPFILE) == O_TMPFILE) { | ||
| 10 | 		va_list ap; | ||
| 11 | 		va_start(ap, flags); | ||
| 12 | 		mode = va_arg(ap, mode_t); | ||
| 13 | 		va_end(ap); | ||
| 14 | 	} | ||
| 15 | |||
| 16 | 	return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode); | ||
| 17 | } | ||
| 18 | |||
| 19 | weak_alias(openat, openat64); | ||
lib/libc/wasi/libc-top-half/musl/src/fcntl/posix_fadvise.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int posix_fadvise(int fd, off_t base, off_t len, int advice) | ||
| 5 | { | ||
| 6 | #if defined(SYSCALL_FADVISE_6_ARG) | ||
| 7 | 	/* Some archs, at least arm and powerpc, have the syscall | ||
| 8 | 	 * arguments reordered to avoid needing 7 argument registers | ||
| 9 | 	 * due to 64-bit argument alignment. */ | ||
| 10 | 	return -__syscall(SYS_fadvise, fd, advice, | ||
| 11 | 		__SYSCALL_LL_E(base), __SYSCALL_LL_E(len)); | ||
| 12 | #else | ||
| 13 | 	return -__syscall(SYS_fadvise, fd, __SYSCALL_LL_O(base), | ||
| 14 | 		__SYSCALL_LL_E(len), advice); | ||
| 15 | #endif | ||
| 16 | } | ||
| 17 | |||
| 18 | weak_alias(posix_fadvise, posix_fadvise64); | ||
lib/libc/wasi/libc-top-half/musl/src/fcntl/posix_fallocate.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int posix_fallocate(int fd, off_t base, off_t len) | ||
| 5 | { | ||
| 6 | 	return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base), | ||
| 7 | 		__SYSCALL_LL_E(len)); | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(posix_fallocate, posix_fallocate64); | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/__flt_rounds.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <float.h> | ||
| 2 | #include <fenv.h> | ||
| 3 | |||
| 4 | int __flt_rounds() | ||
| 5 | { | ||
| 6 | 	switch (fegetround()) { | ||
| 7 | #ifdef FE_TOWARDZERO | ||
| 8 | 	case FE_TOWARDZERO: return 0; | ||
| 9 | #endif | ||
| 10 | 	case FE_TONEAREST: return 1; | ||
| 11 | #ifdef FE_UPWARD | ||
| 12 | 	case FE_UPWARD: return 2; | ||
| 13 | #endif | ||
| 14 | #ifdef FE_DOWNWARD | ||
| 15 | 	case FE_DOWNWARD: return 3; | ||
| 16 | #endif | ||
| 17 | 	} | ||
| 18 | 	return -1; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/aarch64/fenv.s created+68| ... | @@ -0,0 +1,68 @@ | ||
| 1 | .global fegetround | ||
| 2 | .type fegetround,%function | ||
| 3 | fegetround: | ||
| 4 | 	mrs x0, fpcr | ||
| 5 | 	and w0, w0, #0xc00000 | ||
| 6 | 	ret | ||
| 7 | |||
| 8 | .global __fesetround | ||
| 9 | .hidden __fesetround | ||
| 10 | .type __fesetround,%function | ||
| 11 | __fesetround: | ||
| 12 | 	mrs x1, fpcr | ||
| 13 | 	bic w1, w1, #0xc00000 | ||
| 14 | 	orr w1, w1, w0 | ||
| 15 | 	msr fpcr, x1 | ||
| 16 | 	mov w0, #0 | ||
| 17 | 	ret | ||
| 18 | |||
| 19 | .global fetestexcept | ||
| 20 | .type fetestexcept,%function | ||
| 21 | fetestexcept: | ||
| 22 | 	and w0, w0, #0x1f | ||
| 23 | 	mrs x1, fpsr | ||
| 24 | 	and w0, w0, w1 | ||
| 25 | 	ret | ||
| 26 | |||
| 27 | .global feclearexcept | ||
| 28 | .type feclearexcept,%function | ||
| 29 | feclearexcept: | ||
| 30 | 	and w0, w0, #0x1f | ||
| 31 | 	mrs x1, fpsr | ||
| 32 | 	bic w1, w1, w0 | ||
| 33 | 	msr fpsr, x1 | ||
| 34 | 	mov w0, #0 | ||
| 35 | 	ret | ||
| 36 | |||
| 37 | .global feraiseexcept | ||
| 38 | .type feraiseexcept,%function | ||
| 39 | feraiseexcept: | ||
| 40 | 	and w0, w0, #0x1f | ||
| 41 | 	mrs x1, fpsr | ||
| 42 | 	orr w1, w1, w0 | ||
| 43 | 	msr fpsr, x1 | ||
| 44 | 	mov w0, #0 | ||
| 45 | 	ret | ||
| 46 | |||
| 47 | .global fegetenv | ||
| 48 | .type fegetenv,%function | ||
| 49 | fegetenv: | ||
| 50 | 	mrs x1, fpcr | ||
| 51 | 	mrs x2, fpsr | ||
| 52 | 	stp w1, w2, [x0] | ||
| 53 | 	mov w0, #0 | ||
| 54 | 	ret | ||
| 55 | |||
| 56 | // TODO preserve some bits | ||
| 57 | .global fesetenv | ||
| 58 | .type fesetenv,%function | ||
| 59 | fesetenv: | ||
| 60 | 	mov x1, #0 | ||
| 61 | 	mov x2, #0 | ||
| 62 | 	cmn x0, #1 | ||
| 63 | 	b.eq 1f | ||
| 64 | 	ldp w1, w2, [x0] | ||
| 65 | 1:	msr fpcr, x1 | ||
| 66 | 	msr fpsr, x2 | ||
| 67 | 	mov w0, #0 | ||
| 68 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/arm/fenv-hf.S created+70| ... | @@ -0,0 +1,70 @@ | ||
| 1 | #if __ARM_PCS_VFP | ||
| 2 | |||
| 3 | .syntax unified | ||
| 4 | .fpu vfp | ||
| 5 | |||
| 6 | .global fegetround | ||
| 7 | .type fegetround,%function | ||
| 8 | fegetround: | ||
| 9 | 	fmrx r0, fpscr | ||
| 10 | 	and r0, r0, #0xc00000 | ||
| 11 | 	bx lr | ||
| 12 | |||
| 13 | .global __fesetround | ||
| 14 | .hidden __fesetround | ||
| 15 | .type __fesetround,%function | ||
| 16 | __fesetround: | ||
| 17 | 	fmrx r3, fpscr | ||
| 18 | 	bic r3, r3, #0xc00000 | ||
| 19 | 	orr r3, r3, r0 | ||
| 20 | 	fmxr fpscr, r3 | ||
| 21 | 	mov r0, #0 | ||
| 22 | 	bx lr | ||
| 23 | |||
| 24 | .global fetestexcept | ||
| 25 | .type fetestexcept,%function | ||
| 26 | fetestexcept: | ||
| 27 | 	and r0, r0, #0x1f | ||
| 28 | 	fmrx r3, fpscr | ||
| 29 | 	and r0, r0, r3 | ||
| 30 | 	bx lr | ||
| 31 | |||
| 32 | .global feclearexcept | ||
| 33 | .type feclearexcept,%function | ||
| 34 | feclearexcept: | ||
| 35 | 	and r0, r0, #0x1f | ||
| 36 | 	fmrx r3, fpscr | ||
| 37 | 	bic r3, r3, r0 | ||
| 38 | 	fmxr fpscr, r3 | ||
| 39 | 	mov r0, #0 | ||
| 40 | 	bx lr | ||
| 41 | |||
| 42 | .global feraiseexcept | ||
| 43 | .type feraiseexcept,%function | ||
| 44 | feraiseexcept: | ||
| 45 | 	and r0, r0, #0x1f | ||
| 46 | 	fmrx r3, fpscr | ||
| 47 | 	orr r3, r3, r0 | ||
| 48 | 	fmxr fpscr, r3 | ||
| 49 | 	mov r0, #0 | ||
| 50 | 	bx lr | ||
| 51 | |||
| 52 | .global fegetenv | ||
| 53 | .type fegetenv,%function | ||
| 54 | fegetenv: | ||
| 55 | 	fmrx r3, fpscr | ||
| 56 | 	str r3, [r0] | ||
| 57 | 	mov r0, #0 | ||
| 58 | 	bx lr | ||
| 59 | |||
| 60 | .global fesetenv | ||
| 61 | .type fesetenv,%function | ||
| 62 | fesetenv: | ||
| 63 | 	cmn r0, #1 | ||
| 64 | 	moveq r3, #0 | ||
| 65 | 	ldrne r3, [r0] | ||
| 66 | 	fmxr fpscr, r3 | ||
| 67 | 	mov r0, #0 | ||
| 68 | 	bx lr | ||
| 69 | |||
| 70 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/arm/fenv.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #if !__ARM_PCS_VFP | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/fegetexceptflag.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | |||
| 3 | int fegetexceptflag(fexcept_t *fp, int mask) | ||
| 4 | { | ||
| 5 | 	*fp = fetestexcept(mask); | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/feholdexcept.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | |||
| 3 | int feholdexcept(fenv_t *envp) | ||
| 4 | { | ||
| 5 | 	fegetenv(envp); | ||
| 6 | 	feclearexcept(FE_ALL_EXCEPT); | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/fenv.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | |||
| 3 | /* Dummy functions for archs lacking fenv implementation */ | ||
| 4 | |||
| 5 | int feclearexcept(int mask) | ||
| 6 | { | ||
| 7 | 	return 0; | ||
| 8 | } | ||
| 9 | |||
| 10 | int feraiseexcept(int mask) | ||
| 11 | { | ||
| 12 | 	return 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | int fetestexcept(int mask) | ||
| 16 | { | ||
| 17 | 	return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | int fegetround(void) | ||
| 21 | { | ||
| 22 | 	return FE_TONEAREST; | ||
| 23 | } | ||
| 24 | |||
| 25 | int __fesetround(int r) | ||
| 26 | { | ||
| 27 | 	return 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | int fegetenv(fenv_t *envp) | ||
| 31 | { | ||
| 32 | 	return 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | int fesetenv(const fenv_t *envp) | ||
| 36 | { | ||
| 37 | 	return 0; | ||
| 38 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/fesetexceptflag.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | |||
| 3 | int fesetexceptflag(const fexcept_t *fp, int mask) | ||
| 4 | { | ||
| 5 | 	feclearexcept(~*fp & mask); | ||
| 6 | 	feraiseexcept(*fp & mask); | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/fesetround.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | #include <features.h> | ||
| 3 | |||
| 4 | /* __fesetround wrapper for arch independent argument check */ | ||
| 5 | |||
| 6 | hidden int __fesetround(int); | ||
| 7 | |||
| 8 | int fesetround(int r) | ||
| 9 | { | ||
| 10 | 	if (r != FE_TONEAREST | ||
| 11 | #ifdef FE_DOWNWARD | ||
| 12 | 		&& r != FE_DOWNWARD | ||
| 13 | #endif | ||
| 14 | #ifdef FE_UPWARD | ||
| 15 | 		&& r != FE_UPWARD | ||
| 16 | #endif | ||
| 17 | #ifdef FE_TOWARDZERO | ||
| 18 | 		&& r != FE_TOWARDZERO | ||
| 19 | #endif | ||
| 20 | 	) | ||
| 21 | 		return -1; | ||
| 22 | 	return __fesetround(r); | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/feupdateenv.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | |||
| 3 | int feupdateenv(const fenv_t *envp) | ||
| 4 | { | ||
| 5 | 	int ex = fetestexcept(FE_ALL_EXCEPT); | ||
| 6 | 	fesetenv(envp); | ||
| 7 | 	feraiseexcept(ex); | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/i386/fenv.s created+164| ... | @@ -0,0 +1,164 @@ | ||
| 1 | .hidden __hwcap | ||
| 2 | |||
| 3 | .global feclearexcept | ||
| 4 | .type feclearexcept,@function | ||
| 5 | feclearexcept:	 | ||
| 6 | 	mov 4(%esp),%ecx | ||
| 7 | 	and $0x3f,%ecx | ||
| 8 | 	fnstsw %ax | ||
| 9 | 		# consider sse fenv as well if the cpu has XMM capability | ||
| 10 | 	call 1f | ||
| 11 | 1:	addl $__hwcap-1b,(%esp) | ||
| 12 | 	pop %edx | ||
| 13 | 	testl $0x02000000,(%edx) | ||
| 14 | 	jz 2f | ||
| 15 | 		# maintain exceptions in the sse mxcsr, clear x87 exceptions | ||
| 16 | 	test %eax,%ecx | ||
| 17 | 	jz 1f | ||
| 18 | 	fnclex | ||
| 19 | 1:	push %edx | ||
| 20 | 	stmxcsr (%esp) | ||
| 21 | 	pop %edx | ||
| 22 | 	and $0x3f,%eax | ||
| 23 | 	or %eax,%edx | ||
| 24 | 	test %edx,%ecx | ||
| 25 | 	jz 1f | ||
| 26 | 	not %ecx | ||
| 27 | 	and %ecx,%edx | ||
| 28 | 	push %edx | ||
| 29 | 	ldmxcsr (%esp) | ||
| 30 | 	pop %edx | ||
| 31 | 1:	xor %eax,%eax | ||
| 32 | 	ret | ||
| 33 | 		# only do the expensive x87 fenv load/store when needed | ||
| 34 | 2:	test %eax,%ecx | ||
| 35 | 	jz 1b | ||
| 36 | 	not %ecx | ||
| 37 | 	and %ecx,%eax | ||
| 38 | 	test $0x3f,%eax | ||
| 39 | 	jz 1f | ||
| 40 | 	fnclex | ||
| 41 | 	jmp 1b | ||
| 42 | 1:	sub $32,%esp | ||
| 43 | 	fnstenv (%esp) | ||
| 44 | 	mov %al,4(%esp) | ||
| 45 | 	fldenv (%esp) | ||
| 46 | 	add $32,%esp | ||
| 47 | 	xor %eax,%eax | ||
| 48 | 	ret | ||
| 49 | |||
| 50 | .global feraiseexcept | ||
| 51 | .type feraiseexcept,@function | ||
| 52 | feraiseexcept:	 | ||
| 53 | 	mov 4(%esp),%eax | ||
| 54 | 	and $0x3f,%eax | ||
| 55 | 	sub $32,%esp | ||
| 56 | 	fnstenv (%esp) | ||
| 57 | 	or %al,4(%esp) | ||
| 58 | 	fldenv (%esp) | ||
| 59 | 	add $32,%esp | ||
| 60 | 	xor %eax,%eax | ||
| 61 | 	ret | ||
| 62 | |||
| 63 | .global __fesetround | ||
| 64 | .hidden __fesetround | ||
| 65 | .type __fesetround,@function | ||
| 66 | __fesetround: | ||
| 67 | 	mov 4(%esp),%ecx | ||
| 68 | 	push %eax | ||
| 69 | 	xor %eax,%eax | ||
| 70 | 	fnstcw (%esp) | ||
| 71 | 	andb $0xf3,1(%esp) | ||
| 72 | 	or %ch,1(%esp) | ||
| 73 | 	fldcw (%esp) | ||
| 74 | 		# consider sse fenv as well if the cpu has XMM capability | ||
| 75 | 	call 1f | ||
| 76 | 1:	addl $__hwcap-1b,(%esp) | ||
| 77 | 	pop %edx | ||
| 78 | 	testl $0x02000000,(%edx) | ||
| 79 | 	jz 1f | ||
| 80 | 	stmxcsr (%esp) | ||
| 81 | 	shl $3,%ch | ||
| 82 | 	andb $0x9f,1(%esp) | ||
| 83 | 	or %ch,1(%esp) | ||
| 84 | 	ldmxcsr (%esp) | ||
| 85 | 1:	pop %ecx | ||
| 86 | 	ret | ||
| 87 | |||
| 88 | .global fegetround | ||
| 89 | .type fegetround,@function | ||
| 90 | fegetround: | ||
| 91 | 	push %eax | ||
| 92 | 	fnstcw (%esp) | ||
| 93 | 	pop %eax | ||
| 94 | 	and $0xc00,%eax | ||
| 95 | 	ret | ||
| 96 | |||
| 97 | .global fegetenv | ||
| 98 | .type fegetenv,@function | ||
| 99 | fegetenv: | ||
| 100 | 	mov 4(%esp),%ecx | ||
| 101 | 	xor %eax,%eax | ||
| 102 | 	fnstenv (%ecx) | ||
| 103 | 		# consider sse fenv as well if the cpu has XMM capability | ||
| 104 | 	call 1f | ||
| 105 | 1:	addl $__hwcap-1b,(%esp) | ||
| 106 | 	pop %edx | ||
| 107 | 	testl $0x02000000,(%edx) | ||
| 108 | 	jz 1f | ||
| 109 | 	push %eax | ||
| 110 | 	stmxcsr (%esp) | ||
| 111 | 	pop %edx | ||
| 112 | 	and $0x3f,%edx | ||
| 113 | 	or %edx,4(%ecx) | ||
| 114 | 1:	ret | ||
| 115 | |||
| 116 | .global fesetenv | ||
| 117 | .type fesetenv,@function | ||
| 118 | fesetenv: | ||
| 119 | 	mov 4(%esp),%ecx | ||
| 120 | 	xor %eax,%eax | ||
| 121 | 	inc %ecx | ||
| 122 | 	jz 1f | ||
| 123 | 	fldenv -1(%ecx) | ||
| 124 | 	movl -1(%ecx),%ecx | ||
| 125 | 	jmp 2f | ||
| 126 | 1:	push %eax | ||
| 127 | 	push %eax | ||
| 128 | 	push %eax | ||
| 129 | 	push %eax | ||
| 130 | 	pushl $0xffff | ||
| 131 | 	push %eax | ||
| 132 | 	pushl $0x37f | ||
| 133 | 	fldenv (%esp) | ||
| 134 | 	add $28,%esp | ||
| 135 | 		# consider sse fenv as well if the cpu has XMM capability | ||
| 136 | 2:	call 1f | ||
| 137 | 1:	addl $__hwcap-1b,(%esp) | ||
| 138 | 	pop %edx | ||
| 139 | 	testl $0x02000000,(%edx) | ||
| 140 | 	jz 1f | ||
| 141 | 		# mxcsr := same rounding mode, cleared exceptions, default mask | ||
| 142 | 	and $0xc00,%ecx | ||
| 143 | 	shl $3,%ecx | ||
| 144 | 	or $0x1f80,%ecx | ||
| 145 | 	mov %ecx,4(%esp) | ||
| 146 | 	ldmxcsr 4(%esp) | ||
| 147 | 1:	ret | ||
| 148 | |||
| 149 | .global fetestexcept | ||
| 150 | .type fetestexcept,@function | ||
| 151 | fetestexcept: | ||
| 152 | 	mov 4(%esp),%ecx | ||
| 153 | 	and $0x3f,%ecx | ||
| 154 | 	fnstsw %ax | ||
| 155 | 		# consider sse fenv as well if the cpu has XMM capability | ||
| 156 | 	call 1f | ||
| 157 | 1:	addl $__hwcap-1b,(%esp) | ||
| 158 | 	pop %edx | ||
| 159 | 	testl $0x02000000,(%edx) | ||
| 160 | 	jz 1f | ||
| 161 | 	stmxcsr 4(%esp) | ||
| 162 | 	or 4(%esp),%eax | ||
| 163 | 1:	and %ecx,%eax | ||
| 164 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/m68k/fenv.c created+85| ... | @@ -0,0 +1,85 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | #include <features.h> | ||
| 3 | |||
| 4 | #if __HAVE_68881__ || __mcffpu__ | ||
| 5 | |||
| 6 | static unsigned getsr() | ||
| 7 | { | ||
| 8 | 	unsigned v; | ||
| 9 | 	__asm__ __volatile__ ("fmove.l %%fpsr,%0" : "=dm"(v)); | ||
| 10 | 	return v; | ||
| 11 | } | ||
| 12 | |||
| 13 | static void setsr(unsigned v) | ||
| 14 | { | ||
| 15 | 	__asm__ __volatile__ ("fmove.l %0,%%fpsr" : : "dm"(v)); | ||
| 16 | } | ||
| 17 | |||
| 18 | static unsigned getcr() | ||
| 19 | { | ||
| 20 | 	unsigned v; | ||
| 21 | 	__asm__ __volatile__ ("fmove.l %%fpcr,%0" : "=dm"(v)); | ||
| 22 | 	return v; | ||
| 23 | } | ||
| 24 | |||
| 25 | static void setcr(unsigned v) | ||
| 26 | { | ||
| 27 | 	__asm__ __volatile__ ("fmove.l %0,%%fpcr" : : "dm"(v)); | ||
| 28 | } | ||
| 29 | |||
| 30 | int feclearexcept(int mask) | ||
| 31 | { | ||
| 32 | 	if (mask & ~FE_ALL_EXCEPT) return -1; | ||
| 33 | 	setsr(getsr() & ~mask); | ||
| 34 | 	return 0; | ||
| 35 | } | ||
| 36 | |||
| 37 | int feraiseexcept(int mask) | ||
| 38 | { | ||
| 39 | 	if (mask & ~FE_ALL_EXCEPT) return -1; | ||
| 40 | 	setsr(getsr() | mask); | ||
| 41 | 	return 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | int fetestexcept(int mask) | ||
| 45 | { | ||
| 46 | 	return getsr() & mask; | ||
| 47 | } | ||
| 48 | |||
| 49 | int fegetround(void) | ||
| 50 | { | ||
| 51 | 	return getcr() & FE_UPWARD; | ||
| 52 | } | ||
| 53 | |||
| 54 | hidden int __fesetround(int r) | ||
| 55 | { | ||
| 56 | 	setcr((getcr() & ~FE_UPWARD) | r); | ||
| 57 | 	return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | int fegetenv(fenv_t *envp) | ||
| 61 | { | ||
| 62 | 	envp->__control_register = getcr(); | ||
| 63 | 	envp->__status_register = getsr(); | ||
| 64 | 	__asm__ __volatile__ ("fmove.l %%fpiar,%0" | ||
| 65 | 		: "=dm"(envp->__instruction_address)); | ||
| 66 | 	return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | int fesetenv(const fenv_t *envp) | ||
| 70 | { | ||
| 71 | 	static const fenv_t default_env = { 0 }; | ||
| 72 | 	if (envp == FE_DFL_ENV) | ||
| 73 | 		envp = &default_env; | ||
| 74 | 	setcr(envp->__control_register); | ||
| 75 | 	setsr(envp->__status_register); | ||
| 76 | 	__asm__ __volatile__ ("fmove.l %0,%%fpiar" | ||
| 77 | 		: : "dm"(envp->__instruction_address)); | ||
| 78 | 	return 0; | ||
| 79 | } | ||
| 80 | |||
| 81 | #else | ||
| 82 | |||
| 83 | #include "../fenv.c" | ||
| 84 | |||
| 85 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/mips/fenv-sf.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #ifdef __mips_soft_float | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/mips/fenv.S created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | #ifndef __mips_soft_float | ||
| 2 | |||
| 3 | .set noreorder | ||
| 4 | |||
| 5 | .global feclearexcept | ||
| 6 | .type feclearexcept,@function | ||
| 7 | feclearexcept: | ||
| 8 | 	and $4, $4, 0x7c | ||
| 9 | 	cfc1 $5, $31 | ||
| 10 | 	or $5, $5, $4 | ||
| 11 | 	xor $5, $5, $4 | ||
| 12 | 	ctc1 $5, $31 | ||
| 13 | 	jr $ra | ||
| 14 | 	li $2, 0 | ||
| 15 | |||
| 16 | .global feraiseexcept | ||
| 17 | .type feraiseexcept,@function | ||
| 18 | feraiseexcept: | ||
| 19 | 	and $4, $4, 0x7c | ||
| 20 | 	cfc1 $5, $31 | ||
| 21 | 	or $5, $5, $4 | ||
| 22 | 	ctc1 $5, $31 | ||
| 23 | 	jr $ra | ||
| 24 | 	li $2, 0 | ||
| 25 | |||
| 26 | .global fetestexcept | ||
| 27 | .type fetestexcept,@function | ||
| 28 | fetestexcept: | ||
| 29 | 	and $4, $4, 0x7c | ||
| 30 | 	cfc1 $2, $31 | ||
| 31 | 	jr $ra | ||
| 32 | 	and $2, $2, $4 | ||
| 33 | |||
| 34 | .global fegetround | ||
| 35 | .type fegetround,@function | ||
| 36 | fegetround: | ||
| 37 | 	cfc1 $2, $31 | ||
| 38 | 	jr $ra | ||
| 39 | 	andi $2, $2, 3 | ||
| 40 | |||
| 41 | .global __fesetround | ||
| 42 | .hidden __fesetround | ||
| 43 | .type __fesetround,@function | ||
| 44 | __fesetround: | ||
| 45 | 	cfc1 $5, $31 | ||
| 46 | 	li $6, -4 | ||
| 47 | 	and $5, $5, $6 | ||
| 48 | 	or $5, $5, $4 | ||
| 49 | 	ctc1 $5, $31 | ||
| 50 | 	jr $ra | ||
| 51 | 	li $2, 0 | ||
| 52 | |||
| 53 | .global fegetenv | ||
| 54 | .type fegetenv,@function | ||
| 55 | fegetenv: | ||
| 56 | 	cfc1 $5, $31 | ||
| 57 | 	sw $5, 0($4) | ||
| 58 | 	jr $ra | ||
| 59 | 	li $2, 0 | ||
| 60 | |||
| 61 | .global fesetenv | ||
| 62 | .type fesetenv,@function | ||
| 63 | fesetenv: | ||
| 64 | 	addiu $5, $4, 1 | ||
| 65 | 	beq $5, $0, 1f | ||
| 66 | 	 nop | ||
| 67 | 	lw $5, 0($4) | ||
| 68 | 1:	ctc1 $5, $31 | ||
| 69 | 	jr $ra | ||
| 70 | 	li $2, 0 | ||
| 71 | |||
| 72 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/mips64/fenv-sf.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #ifdef __mips_soft_float | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/mips64/fenv.S created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | #ifndef __mips_soft_float | ||
| 2 | |||
| 3 | .set	noreorder | ||
| 4 | |||
| 5 | .global	feclearexcept | ||
| 6 | .type	feclearexcept,@function | ||
| 7 | feclearexcept: | ||
| 8 | 	and	$4, $4, 0x7c | ||
| 9 | 	cfc1	$5, $31 | ||
| 10 | 	or	$5, $5, $4 | ||
| 11 | 	xor	$5, $5, $4 | ||
| 12 | 	ctc1	$5, $31 | ||
| 13 | 	jr	$ra | ||
| 14 | 	li	$2, 0 | ||
| 15 | |||
| 16 | .global	feraiseexcept | ||
| 17 | .type	feraiseexcept,@function | ||
| 18 | feraiseexcept: | ||
| 19 | 	and	$4, $4, 0x7c | ||
| 20 | 	cfc1	$5, $31 | ||
| 21 | 	or	$5, $5, $4 | ||
| 22 | 	ctc1	$5, $31 | ||
| 23 | 	jr	$ra | ||
| 24 | 	li	$2, 0 | ||
| 25 | |||
| 26 | .global	fetestexcept | ||
| 27 | .type	fetestexcept,@function | ||
| 28 | fetestexcept: | ||
| 29 | 	and	$4, $4, 0x7c | ||
| 30 | 	cfc1	$2, $31 | ||
| 31 | 	jr	$ra | ||
| 32 | 	and	$2, $2, $4 | ||
| 33 | |||
| 34 | .global	fegetround | ||
| 35 | .type	fegetround,@function | ||
| 36 | fegetround: | ||
| 37 | 	cfc1	$2, $31 | ||
| 38 | 	jr	$ra | ||
| 39 | 	andi	$2, $2, 3 | ||
| 40 | |||
| 41 | .global	__fesetround | ||
| 42 | .hidden __fesetround | ||
| 43 | .type	__fesetround,@function | ||
| 44 | __fesetround: | ||
| 45 | 	cfc1	$5, $31 | ||
| 46 | 	li	$6, -4 | ||
| 47 | 	and	$5, $5, $6 | ||
| 48 | 	or	$5, $5, $4 | ||
| 49 | 	ctc1	$5, $31 | ||
| 50 | 	jr	$ra | ||
| 51 | 	li	$2, 0 | ||
| 52 | |||
| 53 | .global	fegetenv | ||
| 54 | .type	fegetenv,@function | ||
| 55 | fegetenv: | ||
| 56 | 	cfc1	$5, $31 | ||
| 57 | 	sw	$5, 0($4) | ||
| 58 | 	jr	$ra | ||
| 59 | 	li	$2, 0 | ||
| 60 | |||
| 61 | .global	fesetenv | ||
| 62 | .type	fesetenv,@function | ||
| 63 | fesetenv: | ||
| 64 | 	daddiu	$5, $4, 1 | ||
| 65 | 	beq	$5, $0, 1f | ||
| 66 | 	nop | ||
| 67 | 	lw	$5, 0($4) | ||
| 68 | 1:	ctc1	$5, $31 | ||
| 69 | 	jr	$ra | ||
| 70 | 	li	$2, 0 | ||
| 71 | |||
| 72 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/mipsn32/fenv-sf.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #ifdef __mips_soft_float | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/mipsn32/fenv.S created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | #ifndef __mips_soft_float | ||
| 2 | |||
| 3 | .set	noreorder | ||
| 4 | .global	feclearexcept | ||
| 5 | .type	feclearexcept,@function | ||
| 6 | feclearexcept: | ||
| 7 | 	and	$4, $4, 0x7c | ||
| 8 | 	cfc1	$5, $31 | ||
| 9 | 	or	$5, $5, $4 | ||
| 10 | 	xor	$5, $5, $4 | ||
| 11 | 	ctc1	$5, $31 | ||
| 12 | 	jr	$ra | ||
| 13 | 	li	$2, 0 | ||
| 14 | |||
| 15 | .global feraiseexcept | ||
| 16 | .type feraiseexcept,@function | ||
| 17 | feraiseexcept: | ||
| 18 | 	and	$4, $4, 0x7c | ||
| 19 | 	cfc1	$5, $31 | ||
| 20 | 	or	$5, $5, $4 | ||
| 21 | 	ctc1	$5, $31 | ||
| 22 | 	jr	$ra | ||
| 23 | 	li	$2, 0 | ||
| 24 | |||
| 25 | .global fetestexcept | ||
| 26 | .type fetestexcept,@function | ||
| 27 | fetestexcept: | ||
| 28 | 	and	$4, $4, 0x7c | ||
| 29 | 	cfc1	$2, $31 | ||
| 30 | 	jr	$ra | ||
| 31 | 	and	$2, $2, $4 | ||
| 32 | |||
| 33 | .global fegetround | ||
| 34 | .type fegetround,@function | ||
| 35 | fegetround: | ||
| 36 | 	cfc1	$2, $31 | ||
| 37 | 	jr	$ra | ||
| 38 | 	andi	$2, $2, 3 | ||
| 39 | |||
| 40 | .global __fesetround | ||
| 41 | .hidden __fesetround | ||
| 42 | .type __fesetround,@function | ||
| 43 | __fesetround: | ||
| 44 | 	cfc1	$5, $31 | ||
| 45 | 	li	$6, -4 | ||
| 46 | 	and	$5, $5, $6 | ||
| 47 | 	or	$5, $5, $4 | ||
| 48 | 	ctc1	$5, $31 | ||
| 49 | 	jr	$ra | ||
| 50 | 	li	$2, 0 | ||
| 51 | |||
| 52 | .global fegetenv | ||
| 53 | .type fegetenv,@function | ||
| 54 | fegetenv: | ||
| 55 | 	cfc1	$5, $31 | ||
| 56 | 	sw	$5, 0($4) | ||
| 57 | 	jr	$ra | ||
| 58 | 	li	$2, 0 | ||
| 59 | |||
| 60 | .global fesetenv | ||
| 61 | .type fesetenv,@function | ||
| 62 | fesetenv: | ||
| 63 | 	addiu $5, $4, 1 | ||
| 64 | 	beq	$5, $0, 1f | ||
| 65 | 	nop | ||
| 66 | 	lw	$5, 0($4) | ||
| 67 | 1:	ctc1	$5, $31 | ||
| 68 | 	jr	$ra | ||
| 69 | 	li	$2, 0 | ||
| 70 | |||
| 71 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc/fenv-sf.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #ifdef _SOFT_FLOAT | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc/fenv.S created+130| ... | @@ -0,0 +1,130 @@ | ||
| 1 | #ifndef _SOFT_FLOAT | ||
| 2 | .global feclearexcept | ||
| 3 | .type feclearexcept,@function | ||
| 4 | feclearexcept: | ||
| 5 | 	andis. 3,3,0x3e00 | ||
| 6 | 	/* if (r3 & FE_INVALID) r3 |= all_invalid_flags */ | ||
| 7 | 	andis. 0,3,0x2000 | ||
| 8 | 	stwu 1,-16(1) | ||
| 9 | 	beq- 0,1f | ||
| 10 | 	oris 3,3,0x01f8 | ||
| 11 | 	ori 3,3,0x0700 | ||
| 12 | 1: | ||
| 13 | 	/* | ||
| 14 | 	 * note: fpscr contains various fpu status and control | ||
| 15 | 	 * flags and we dont check if r3 may alter other flags | ||
| 16 | 	 * than the exception related ones | ||
| 17 | 	 * ufpscr &= ~r3 | ||
| 18 | 	 */ | ||
| 19 | 	mffs 0 | ||
| 20 | 	stfd 0,8(1) | ||
| 21 | 	lwz 9,12(1) | ||
| 22 | 	andc 9,9,3 | ||
| 23 | 	stw 9,12(1) | ||
| 24 | 	lfd 0,8(1) | ||
| 25 | 	mtfsf 255,0 | ||
| 26 | |||
| 27 | 	/* return 0 */ | ||
| 28 | 	li 3,0 | ||
| 29 | 	addi 1,1,16 | ||
| 30 | 	blr | ||
| 31 | |||
| 32 | .global feraiseexcept | ||
| 33 | .type feraiseexcept,@function | ||
| 34 | feraiseexcept: | ||
| 35 | 	andis. 3,3,0x3e00 | ||
| 36 | 	/* if (r3 & FE_INVALID) r3 |= software_invalid_flag */ | ||
| 37 | 	andis. 0,3,0x2000 | ||
| 38 | 	stwu 1,-16(1) | ||
| 39 | 	beq- 0,1f | ||
| 40 | 	ori 3,3,0x0400 | ||
| 41 | 1: | ||
| 42 | 	/* fpscr |= r3 */ | ||
| 43 | 	mffs 0 | ||
| 44 | 	stfd 0,8(1) | ||
| 45 | 	lwz 9,12(1) | ||
| 46 | 	or 9,9,3 | ||
| 47 | 	stw 9,12(1) | ||
| 48 | 	lfd 0,8(1) | ||
| 49 | 	mtfsf 255,0 | ||
| 50 | |||
| 51 | 	/* return 0 */ | ||
| 52 | 	li 3,0 | ||
| 53 | 	addi 1,1,16 | ||
| 54 | 	blr | ||
| 55 | |||
| 56 | .global fetestexcept | ||
| 57 | .type fetestexcept,@function | ||
| 58 | fetestexcept: | ||
| 59 | 	andis. 3,3,0x3e00 | ||
| 60 | 	/* return r3 & fpscr */ | ||
| 61 | 	stwu 1,-16(1) | ||
| 62 | 	mffs 0 | ||
| 63 | 	stfd 0,8(1) | ||
| 64 | 	lwz 9,12(1) | ||
| 65 | 	addi 1,1,16 | ||
| 66 | 	and 3,3,9 | ||
| 67 | 	blr | ||
| 68 | |||
| 69 | .global fegetround | ||
| 70 | .type fegetround,@function | ||
| 71 | fegetround: | ||
| 72 | 	/* return fpscr & 3 */ | ||
| 73 | 	stwu 1,-16(1) | ||
| 74 | 	mffs 0 | ||
| 75 | 	stfd 0,8(1) | ||
| 76 | 	lwz 3,12(1) | ||
| 77 | 	addi 1,1,16 | ||
| 78 | 	clrlwi 3,3,30 | ||
| 79 | 	blr | ||
| 80 | |||
| 81 | .global __fesetround | ||
| 82 | .hidden __fesetround | ||
| 83 | .type __fesetround,@function | ||
| 84 | __fesetround: | ||
| 85 | 	/* | ||
| 86 | 	 * note: invalid input is not checked, r3 < 4 must hold | ||
| 87 | 	 * fpscr = (fpscr & -4U) | r3 | ||
| 88 | 	 */ | ||
| 89 | 	stwu 1,-16(1) | ||
| 90 | 	mffs 0 | ||
| 91 | 	stfd 0,8(1) | ||
| 92 | 	lwz 9,12(1) | ||
| 93 | 	clrrwi 9,9,2 | ||
| 94 | 	or 9,9,3 | ||
| 95 | 	stw 9,12(1) | ||
| 96 | 	lfd 0,8(1) | ||
| 97 | 	mtfsf 255,0 | ||
| 98 | |||
| 99 | 	/* return 0 */ | ||
| 100 | 	li 3,0 | ||
| 101 | 	addi 1,1,16 | ||
| 102 | 	blr | ||
| 103 | |||
| 104 | .global fegetenv | ||
| 105 | .type fegetenv,@function | ||
| 106 | fegetenv: | ||
| 107 | 	/* *r3 = fpscr */ | ||
| 108 | 	mffs 0 | ||
| 109 | 	stfd 0,0(3) | ||
| 110 | 	/* return 0 */ | ||
| 111 | 	li 3,0 | ||
| 112 | 	blr | ||
| 113 | |||
| 114 | .global fesetenv | ||
| 115 | .type fesetenv,@function | ||
| 116 | fesetenv: | ||
| 117 | 	cmpwi 3, -1 | ||
| 118 | 	bne 1f | ||
| 119 | 	mflr 4 | ||
| 120 | 	bl 2f | ||
| 121 | 	.zero 8 | ||
| 122 | 2:	mflr 3 | ||
| 123 | 	mtlr 4 | ||
| 124 | 1:	/* fpscr = *r3 */ | ||
| 125 | 	lfd 0,0(3) | ||
| 126 | 	mtfsf 255,0 | ||
| 127 | 	/* return 0 */ | ||
| 128 | 	li 3,0 | ||
| 129 | 	blr | ||
| 130 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc64/fenv.c created+69| ... | @@ -0,0 +1,69 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fenv.h> | ||
| 3 | #include <features.h> | ||
| 4 | |||
| 5 | static inline double get_fpscr_f(void) | ||
| 6 | { | ||
| 7 | 	double d; | ||
| 8 | 	__asm__ __volatile__("mffs %0" : "=d"(d)); | ||
| 9 | 	return d; | ||
| 10 | } | ||
| 11 | |||
| 12 | static inline long get_fpscr(void) | ||
| 13 | { | ||
| 14 | 	return (union {double f; long i;}) {get_fpscr_f()}.i; | ||
| 15 | } | ||
| 16 | |||
| 17 | static inline void set_fpscr_f(double fpscr) | ||
| 18 | { | ||
| 19 | 	__asm__ __volatile__("mtfsf 255, %0" : : "d"(fpscr)); | ||
| 20 | } | ||
| 21 | |||
| 22 | static void set_fpscr(long fpscr) | ||
| 23 | { | ||
| 24 | 	set_fpscr_f((union {long i; double f;}) {fpscr}.f); | ||
| 25 | } | ||
| 26 | |||
| 27 | int feclearexcept(int mask) | ||
| 28 | { | ||
| 29 | 	mask &= FE_ALL_EXCEPT; | ||
| 30 | 	if (mask & FE_INVALID) mask |= FE_ALL_INVALID; | ||
| 31 | 	set_fpscr(get_fpscr() & ~mask); | ||
| 32 | 	return 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | int feraiseexcept(int mask) | ||
| 36 | { | ||
| 37 | 	mask &= FE_ALL_EXCEPT; | ||
| 38 | 	if (mask & FE_INVALID) mask |= FE_INVALID_SOFTWARE; | ||
| 39 | 	set_fpscr(get_fpscr() | mask); | ||
| 40 | 	return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | int fetestexcept(int mask) | ||
| 44 | { | ||
| 45 | 	return get_fpscr() & mask & FE_ALL_EXCEPT; | ||
| 46 | } | ||
| 47 | |||
| 48 | int fegetround(void) | ||
| 49 | { | ||
| 50 | 	return get_fpscr() & 3; | ||
| 51 | } | ||
| 52 | |||
| 53 | hidden int __fesetround(int r) | ||
| 54 | { | ||
| 55 | 	set_fpscr(get_fpscr() & ~3L | r); | ||
| 56 | 	return 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | int fegetenv(fenv_t *envp) | ||
| 60 | { | ||
| 61 | 	*envp = get_fpscr_f(); | ||
| 62 | 	return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | int fesetenv(const fenv_t *envp) | ||
| 66 | { | ||
| 67 | 	set_fpscr_f(envp != FE_DFL_ENV ? *envp : 0); | ||
| 68 | 	return 0; | ||
| 69 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/riscv64/fenv-sf.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #ifndef __riscv_flen | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/riscv64/fenv.S created+56| ... | @@ -0,0 +1,56 @@ | ||
| 1 | #ifdef __riscv_flen | ||
| 2 | |||
| 3 | .global feclearexcept | ||
| 4 | .type feclearexcept, %function | ||
| 5 | feclearexcept: | ||
| 6 | 	csrc fflags, a0 | ||
| 7 | 	li a0, 0 | ||
| 8 | 	ret | ||
| 9 | |||
| 10 | .global feraiseexcept | ||
| 11 | .type feraiseexcept, %function | ||
| 12 | feraiseexcept: | ||
| 13 | 	csrs fflags, a0 | ||
| 14 | 	li a0, 0 | ||
| 15 | 	ret | ||
| 16 | |||
| 17 | .global fetestexcept | ||
| 18 | .type fetestexcept, %function | ||
| 19 | fetestexcept: | ||
| 20 | 	frflags t0 | ||
| 21 | 	and a0, t0, a0 | ||
| 22 | 	ret | ||
| 23 | |||
| 24 | .global fegetround | ||
| 25 | .type fegetround, %function | ||
| 26 | fegetround: | ||
| 27 | 	frrm a0 | ||
| 28 | 	ret | ||
| 29 | |||
| 30 | .global __fesetround | ||
| 31 | .type __fesetround, %function | ||
| 32 | __fesetround: | ||
| 33 | 	fsrm t0, a0 | ||
| 34 | 	li a0, 0 | ||
| 35 | 	ret | ||
| 36 | |||
| 37 | .global fegetenv | ||
| 38 | .type fegetenv, %function | ||
| 39 | fegetenv: | ||
| 40 | 	frcsr t0 | ||
| 41 | 	sw t0, 0(a0) | ||
| 42 | 	li a0, 0 | ||
| 43 | 	ret | ||
| 44 | |||
| 45 | .global fesetenv | ||
| 46 | .type fesetenv, %function | ||
| 47 | fesetenv: | ||
| 48 | 	li t2, -1 | ||
| 49 | 	li t1, 0 | ||
| 50 | 	beq a0, t2, 1f | ||
| 51 | 	lw t1, 0(a0) | ||
| 52 | 1:	fscsr t1 | ||
| 53 | 	li a0, 0 | ||
| 54 | 	ret | ||
| 55 | |||
| 56 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/s390x/fenv.c created+56| ... | @@ -0,0 +1,56 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | #include <features.h> | ||
| 3 | |||
| 4 | static inline unsigned get_fpc(void) | ||
| 5 | { | ||
| 6 | 	unsigned fpc; | ||
| 7 | 	__asm__ __volatile__("efpc %0" : "=r"(fpc)); | ||
| 8 | 	return fpc; | ||
| 9 | } | ||
| 10 | |||
| 11 | static inline void set_fpc(unsigned fpc) | ||
| 12 | { | ||
| 13 | 	__asm__ __volatile__("sfpc %0" :: "r"(fpc)); | ||
| 14 | } | ||
| 15 | |||
| 16 | int feclearexcept(int mask) | ||
| 17 | { | ||
| 18 | 	mask &= FE_ALL_EXCEPT; | ||
| 19 | 	set_fpc(get_fpc() & ~mask); | ||
| 20 | 	return 0; | ||
| 21 | } | ||
| 22 | |||
| 23 | int feraiseexcept(int mask) | ||
| 24 | { | ||
| 25 | 	mask &= FE_ALL_EXCEPT; | ||
| 26 | 	set_fpc(get_fpc() | mask); | ||
| 27 | 	return 0; | ||
| 28 | } | ||
| 29 | |||
| 30 | int fetestexcept(int mask) | ||
| 31 | { | ||
| 32 | 	return get_fpc() & mask & FE_ALL_EXCEPT; | ||
| 33 | } | ||
| 34 | |||
| 35 | int fegetround(void) | ||
| 36 | { | ||
| 37 | 	return get_fpc() & 3; | ||
| 38 | } | ||
| 39 | |||
| 40 | hidden int __fesetround(int r) | ||
| 41 | { | ||
| 42 | 	set_fpc(get_fpc() & ~3L | r); | ||
| 43 | 	return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | int fegetenv(fenv_t *envp) | ||
| 47 | { | ||
| 48 | 	*envp = get_fpc(); | ||
| 49 | 	return 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | int fesetenv(const fenv_t *envp) | ||
| 53 | { | ||
| 54 | 	set_fpc(envp != FE_DFL_ENV ? *envp : 0); | ||
| 55 | 	return 0; | ||
| 56 | } | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/sh/fenv-nofpu.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #if !__SH_FPU_ANY__ && !__SH4__ | ||
| 2 | #include "../fenv.c" | ||
| 3 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/sh/fenv.S created+81| ... | @@ -0,0 +1,81 @@ | ||
| 1 | #if __SH_FPU_ANY__ || __SH4__ | ||
| 2 | |||
| 3 | .global fegetround | ||
| 4 | .type fegetround, @function | ||
| 5 | fegetround: | ||
| 6 | 	sts fpscr, r0 | ||
| 7 | 	rts | ||
| 8 | 	 and #3, r0 | ||
| 9 | |||
| 10 | .global __fesetround | ||
| 11 | .hidden __fesetround | ||
| 12 | .type __fesetround, @function | ||
| 13 | __fesetround: | ||
| 14 | 	sts fpscr, r0 | ||
| 15 | 	mov #-4, r1 | ||
| 16 | 	and r1, r0 | ||
| 17 | 	or r4, r0 | ||
| 18 | 	lds r0, fpscr | ||
| 19 | 	rts | ||
| 20 | 	 mov #0, r0 | ||
| 21 | |||
| 22 | .global fetestexcept | ||
| 23 | .type fetestexcept, @function | ||
| 24 | fetestexcept: | ||
| 25 | 	sts fpscr, r0 | ||
| 26 | 	and r4, r0 | ||
| 27 | 	rts | ||
| 28 | 	 and #0x7c, r0 | ||
| 29 | |||
| 30 | .global feclearexcept | ||
| 31 | .type feclearexcept, @function | ||
| 32 | feclearexcept: | ||
| 33 | 	mov r4, r0 | ||
| 34 | 	and #0x7c, r0 | ||
| 35 | 	not r0, r4 | ||
| 36 | 	sts fpscr, r0 | ||
| 37 | 	and r4, r0 | ||
| 38 | 	lds r0, fpscr | ||
| 39 | 	rts | ||
| 40 | 	 mov #0, r0 | ||
| 41 | |||
| 42 | .global feraiseexcept | ||
| 43 | .type feraiseexcept, @function | ||
| 44 | feraiseexcept: | ||
| 45 | 	mov r4, r0 | ||
| 46 | 	and #0x7c, r0 | ||
| 47 | 	sts fpscr, r4 | ||
| 48 | 	or r4, r0 | ||
| 49 | 	lds r0, fpscr | ||
| 50 | 	rts | ||
| 51 | 	 mov #0, r0 | ||
| 52 | |||
| 53 | .global fegetenv | ||
| 54 | .type fegetenv, @function | ||
| 55 | fegetenv: | ||
| 56 | 	sts fpscr, r0 | ||
| 57 | 	mov.l r0, @r4 | ||
| 58 | 	rts | ||
| 59 | 	 mov #0, r0 | ||
| 60 | |||
| 61 | .global fesetenv | ||
| 62 | .type fesetenv, @function | ||
| 63 | fesetenv: | ||
| 64 | 	mov r4, r0 | ||
| 65 | 	cmp/eq #-1, r0 | ||
| 66 | 	bf 1f | ||
| 67 | |||
| 68 | 	! the default environment is complicated by the fact that we need to | ||
| 69 | 	! preserve the current precision bit, which we do not know a priori | ||
| 70 | 	sts fpscr, r0 | ||
| 71 | 	mov #8, r1 | ||
| 72 | 	swap.w r1, r1 | ||
| 73 | 	bra 2f | ||
| 74 | 	 and r1, r0 | ||
| 75 | |||
| 76 | 1:	mov.l @r4, r0 ! non-default environment | ||
| 77 | 2:	lds r0, fpscr | ||
| 78 | 	rts | ||
| 79 | 	 mov #0, r0 | ||
| 80 | |||
| 81 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/x32/fenv.s created+98| ... | @@ -0,0 +1,98 @@ | ||
| 1 | .global feclearexcept | ||
| 2 | .type feclearexcept,@function | ||
| 3 | feclearexcept: | ||
| 4 | 		# maintain exceptions in the sse mxcsr, clear x87 exceptions | ||
| 5 | 	mov %edi,%ecx | ||
| 6 | 	and $0x3f,%ecx | ||
| 7 | 	fnstsw %ax | ||
| 8 | 	test %eax,%ecx | ||
| 9 | 	jz 1f | ||
| 10 | 	fnclex | ||
| 11 | 1:	stmxcsr -8(%esp) | ||
| 12 | 	and $0x3f,%eax | ||
| 13 | 	or %eax,-8(%esp) | ||
| 14 | 	test %ecx,-8(%esp) | ||
| 15 | 	jz 1f | ||
| 16 | 	not %ecx | ||
| 17 | 	and %ecx,-8(%esp) | ||
| 18 | 	ldmxcsr -8(%esp) | ||
| 19 | 1:	xor %eax,%eax | ||
| 20 | 	ret | ||
| 21 | |||
| 22 | .global feraiseexcept | ||
| 23 | .type feraiseexcept,@function | ||
| 24 | feraiseexcept: | ||
| 25 | 	and $0x3f,%edi | ||
| 26 | 	stmxcsr -8(%esp) | ||
| 27 | 	or %edi,-8(%esp) | ||
| 28 | 	ldmxcsr -8(%esp) | ||
| 29 | 	xor %eax,%eax | ||
| 30 | 	ret | ||
| 31 | |||
| 32 | .global __fesetround | ||
| 33 | .hidden __fesetround | ||
| 34 | .type __fesetround,@function | ||
| 35 | __fesetround: | ||
| 36 | 	push %rax | ||
| 37 | 	xor %eax,%eax | ||
| 38 | 	mov %edi,%ecx | ||
| 39 | 	fnstcw (%esp) | ||
| 40 | 	andb $0xf3,1(%esp) | ||
| 41 | 	or %ch,1(%esp) | ||
| 42 | 	fldcw (%esp) | ||
| 43 | 	stmxcsr (%esp) | ||
| 44 | 	shl $3,%ch | ||
| 45 | 	andb $0x9f,1(%esp) | ||
| 46 | 	or %ch,1(%esp) | ||
| 47 | 	ldmxcsr (%esp) | ||
| 48 | 	pop %rcx | ||
| 49 | 	ret | ||
| 50 | |||
| 51 | .global fegetround | ||
| 52 | .type fegetround,@function | ||
| 53 | fegetround: | ||
| 54 | 	push %rax | ||
| 55 | 	stmxcsr (%esp) | ||
| 56 | 	pop %rax | ||
| 57 | 	shr $3,%eax | ||
| 58 | 	and $0xc00,%eax | ||
| 59 | 	ret | ||
| 60 | |||
| 61 | .global fegetenv | ||
| 62 | .type fegetenv,@function | ||
| 63 | fegetenv: | ||
| 64 | 	xor %eax,%eax | ||
| 65 | 	fnstenv (%edi) | ||
| 66 | 	stmxcsr 28(%edi) | ||
| 67 | 	ret | ||
| 68 | |||
| 69 | .global fesetenv | ||
| 70 | .type fesetenv,@function | ||
| 71 | fesetenv: | ||
| 72 | 	xor %eax,%eax | ||
| 73 | 	inc %edi | ||
| 74 | 	jz 1f | ||
| 75 | 	fldenv -1(%edi) | ||
| 76 | 	ldmxcsr 27(%edi) | ||
| 77 | 	ret | ||
| 78 | 1:	push %rax | ||
| 79 | 	push %rax | ||
| 80 | 	pushq $0xffff | ||
| 81 | 	pushq $0x37f | ||
| 82 | 	fldenv (%esp) | ||
| 83 | 	pushq $0x1f80 | ||
| 84 | 	ldmxcsr (%esp) | ||
| 85 | 	add $40,%esp | ||
| 86 | 	ret | ||
| 87 | |||
| 88 | .global fetestexcept | ||
| 89 | .type fetestexcept,@function | ||
| 90 | fetestexcept: | ||
| 91 | 	and $0x3f,%edi | ||
| 92 | 	push %rax | ||
| 93 | 	stmxcsr (%esp) | ||
| 94 | 	pop %rsi | ||
| 95 | 	fnstsw %ax | ||
| 96 | 	or %esi,%eax | ||
| 97 | 	and %edi,%eax | ||
| 98 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/fenv/x86_64/fenv.s created+98| ... | @@ -0,0 +1,98 @@ | ||
| 1 | .global feclearexcept | ||
| 2 | .type feclearexcept,@function | ||
| 3 | feclearexcept: | ||
| 4 | 		# maintain exceptions in the sse mxcsr, clear x87 exceptions | ||
| 5 | 	mov %edi,%ecx | ||
| 6 | 	and $0x3f,%ecx | ||
| 7 | 	fnstsw %ax | ||
| 8 | 	test %eax,%ecx | ||
| 9 | 	jz 1f | ||
| 10 | 	fnclex | ||
| 11 | 1:	stmxcsr -8(%rsp) | ||
| 12 | 	and $0x3f,%eax | ||
| 13 | 	or %eax,-8(%rsp) | ||
| 14 | 	test %ecx,-8(%rsp) | ||
| 15 | 	jz 1f | ||
| 16 | 	not %ecx | ||
| 17 | 	and %ecx,-8(%rsp) | ||
| 18 | 	ldmxcsr -8(%rsp) | ||
| 19 | 1:	xor %eax,%eax | ||
| 20 | 	ret | ||
| 21 | |||
| 22 | .global feraiseexcept | ||
| 23 | .type feraiseexcept,@function | ||
| 24 | feraiseexcept: | ||
| 25 | 	and $0x3f,%edi | ||
| 26 | 	stmxcsr -8(%rsp) | ||
| 27 | 	or %edi,-8(%rsp) | ||
| 28 | 	ldmxcsr -8(%rsp) | ||
| 29 | 	xor %eax,%eax | ||
| 30 | 	ret | ||
| 31 | |||
| 32 | .global __fesetround | ||
| 33 | .hidden __fesetround | ||
| 34 | .type __fesetround,@function | ||
| 35 | __fesetround: | ||
| 36 | 	push %rax | ||
| 37 | 	xor %eax,%eax | ||
| 38 | 	mov %edi,%ecx | ||
| 39 | 	fnstcw (%rsp) | ||
| 40 | 	andb $0xf3,1(%rsp) | ||
| 41 | 	or %ch,1(%rsp) | ||
| 42 | 	fldcw (%rsp) | ||
| 43 | 	stmxcsr (%rsp) | ||
| 44 | 	shl $3,%ch | ||
| 45 | 	andb $0x9f,1(%rsp) | ||
| 46 | 	or %ch,1(%rsp) | ||
| 47 | 	ldmxcsr (%rsp) | ||
| 48 | 	pop %rcx | ||
| 49 | 	ret | ||
| 50 | |||
| 51 | .global fegetround | ||
| 52 | .type fegetround,@function | ||
| 53 | fegetround: | ||
| 54 | 	push %rax | ||
| 55 | 	stmxcsr (%rsp) | ||
| 56 | 	pop %rax | ||
| 57 | 	shr $3,%eax | ||
| 58 | 	and $0xc00,%eax | ||
| 59 | 	ret | ||
| 60 | |||
| 61 | .global fegetenv | ||
| 62 | .type fegetenv,@function | ||
| 63 | fegetenv: | ||
| 64 | 	xor %eax,%eax | ||
| 65 | 	fnstenv (%rdi) | ||
| 66 | 	stmxcsr 28(%rdi) | ||
| 67 | 	ret | ||
| 68 | |||
| 69 | .global fesetenv | ||
| 70 | .type fesetenv,@function | ||
| 71 | fesetenv: | ||
| 72 | 	xor %eax,%eax | ||
| 73 | 	inc %rdi | ||
| 74 | 	jz 1f | ||
| 75 | 	fldenv -1(%rdi) | ||
| 76 | 	ldmxcsr 27(%rdi) | ||
| 77 | 	ret | ||
| 78 | 1:	push %rax | ||
| 79 | 	push %rax | ||
| 80 | 	pushq $0xffff | ||
| 81 | 	pushq $0x37f | ||
| 82 | 	fldenv (%rsp) | ||
| 83 | 	pushq $0x1f80 | ||
| 84 | 	ldmxcsr (%rsp) | ||
| 85 | 	add $40,%rsp | ||
| 86 | 	ret | ||
| 87 | |||
| 88 | .global fetestexcept | ||
| 89 | .type fetestexcept,@function | ||
| 90 | fetestexcept: | ||
| 91 | 	and $0x3f,%edi | ||
| 92 | 	push %rax | ||
| 93 | 	stmxcsr (%rsp) | ||
| 94 | 	pop %rsi | ||
| 95 | 	fnstsw %ax | ||
| 96 | 	or %esi,%eax | ||
| 97 | 	and %edi,%eax | ||
| 98 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/include/arpa/inet.h created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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/crypt.h created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #ifndef CRYPT_H | ||
| 2 | #define CRYPT_H | ||
| 3 | |||
| 4 | #include "../../include/crypt.h" | ||
| 5 | |||
| 6 | #include <features.h> | ||
| 7 | |||
| 8 | hidden char *__crypt_r(const char *, const char *, struct crypt_data *); | ||
| 9 | |||
| 10 | hidden char *__crypt_des(const char *, const char *, char *); | ||
| 11 | hidden char *__crypt_md5(const char *, const char *, char *); | ||
| 12 | hidden char *__crypt_blowfish(const char *, const char *, char *); | ||
| 13 | hidden char *__crypt_sha256(const char *, const char *, char *); | ||
| 14 | hidden char *__crypt_sha512(const char *, const char *, char *); | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/errno.h created+18| ... | @@ -0,0 +1,18 @@ | ||
| 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/features.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #ifndef FEATURES_H | ||
| 2 | #define FEATURES_H | ||
| 3 | |||
| 4 | #include "../../include/features.h" | ||
| 5 | |||
| 6 | #define weak __attribute__((__weak__)) | ||
| 7 | #define hidden __attribute__((__visibility__("hidden"))) | ||
| 8 | #define weak_alias(old, new) \ | ||
| 9 | 	extern __typeof(old) new __attribute__((__weak__, __alias__(#old))) | ||
| 10 | |||
| 11 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/langinfo.h created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #ifndef LANGINFO_H | ||
| 2 | #define LANGINFO_H | ||
| 3 | |||
| 4 | #include "../../include/langinfo.h" | ||
| 5 | |||
| 6 | char *__nl_langinfo_l(nl_item, locale_t); | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/pthread.h created+29| ... | @@ -0,0 +1,29 @@ | ||
| 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 | hidden _Noreturn void __pthread_exit(void *); | ||
| 11 | hidden int __pthread_join(pthread_t, void **); | ||
| 12 | hidden int __pthread_mutex_lock(pthread_mutex_t *); | ||
| 13 | hidden int __pthread_mutex_trylock(pthread_mutex_t *); | ||
| 14 | hidden int __pthread_mutex_trylock_owner(pthread_mutex_t *); | ||
| 15 | hidden int __pthread_mutex_timedlock(pthread_mutex_t *restrict, const struct timespec *restrict); | ||
| 16 | hidden int __pthread_mutex_unlock(pthread_mutex_t *); | ||
| 17 | hidden int __private_cond_signal(pthread_cond_t *, int); | ||
| 18 | hidden int __pthread_cond_timedwait(pthread_cond_t *restrict, pthread_mutex_t *restrict, const struct timespec *restrict); | ||
| 19 | hidden int __pthread_key_create(pthread_key_t *, void (*)(void *)); | ||
| 20 | hidden int __pthread_key_delete(pthread_key_t); | ||
| 21 | hidden int __pthread_rwlock_rdlock(pthread_rwlock_t *); | ||
| 22 | hidden int __pthread_rwlock_tryrdlock(pthread_rwlock_t *); | ||
| 23 | hidden int __pthread_rwlock_timedrdlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 24 | hidden int __pthread_rwlock_wrlock(pthread_rwlock_t *); | ||
| 25 | hidden int __pthread_rwlock_trywrlock(pthread_rwlock_t *); | ||
| 26 | hidden int __pthread_rwlock_timedwrlock(pthread_rwlock_t *__restrict, const struct timespec *__restrict); | ||
| 27 | hidden int __pthread_rwlock_unlock(pthread_rwlock_t *); | ||
| 28 | |||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/resolv.h created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #ifndef RESOLV_H | ||
| 2 | #define RESOLV_H | ||
| 3 | |||
| 4 | #include "../../include/resolv.h" | ||
| 5 | |||
| 6 | hidden int __dn_expand(const unsigned char *, const unsigned char *, const unsigned char *, char *, int); | ||
| 7 | |||
| 8 | hidden int __res_mkquery(int, const char *, int, int, const unsigned char *, int, const unsigned char*, unsigned char *, int); | ||
| 9 | hidden int __res_send(const unsigned char *, int, unsigned char *, int); | ||
| 10 | hidden int __res_msend(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int); | ||
| 11 | |||
| 12 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/signal.h created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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 created+18| ... | @@ -0,0 +1,18 @@ | ||
| 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 | |||
| 12 | hidden void *__libc_malloc(size_t); | ||
| 13 | hidden void *__libc_malloc_impl(size_t); | ||
| 14 | hidden void *__libc_calloc(size_t, size_t); | ||
| 15 | hidden void *__libc_realloc(void *, size_t); | ||
| 16 | hidden void __libc_free(void *); | ||
| 17 | |||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/string.h created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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/auxv.h created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #ifndef SYS_AUXV_H | ||
| 2 | #define SYS_AUXV_H | ||
| 3 | |||
| 4 | #include "../../../include/sys/auxv.h" | ||
| 5 | |||
| 6 | #include <features.h> | ||
| 7 | |||
| 8 | hidden unsigned long __getauxval(unsigned long); | ||
| 9 | |||
| 10 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/sys/membarrier.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef SYS_MEMBARRIER_H | ||
| 2 | #define SYS_MEMBARRIER_H | ||
| 3 | |||
| 4 | #include "../../../include/sys/membarrier.h" | ||
| 5 | #include <features.h> | ||
| 6 | |||
| 7 | hidden int __membarrier(int, int); | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/sys/mman.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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/sysinfo.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef SYS_SYSINFO_H | ||
| 2 | #define SYS_SYSINFO_H | ||
| 3 | |||
| 4 | #include "../../../include/sys/sysinfo.h" | ||
| 5 | #include <features.h> | ||
| 6 | |||
| 7 | hidden int __lsysinfo(struct sysinfo *); | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/include/sys/time.h created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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 created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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 created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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 created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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/aio_impl.h created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #ifndef AIO_IMPL_H | ||
| 2 | #define AIO_IMPL_H | ||
| 3 | |||
| 4 | extern hidden volatile int __aio_fut; | ||
| 5 | |||
| 6 | extern hidden int __aio_close(int); | ||
| 7 | extern hidden void __aio_atfork(int); | ||
| 8 | |||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/atomic.h created+333| ... | @@ -0,0 +1,333 @@ | ||
| 1 | #ifndef _ATOMIC_H | ||
| 2 | #define _ATOMIC_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #include "atomic_arch.h" | ||
| 7 | |||
| 8 | #ifdef a_ll | ||
| 9 | |||
| 10 | #ifndef a_pre_llsc | ||
| 11 | #define a_pre_llsc() | ||
| 12 | #endif | ||
| 13 | |||
| 14 | #ifndef a_post_llsc | ||
| 15 | #define a_post_llsc() | ||
| 16 | #endif | ||
| 17 | |||
| 18 | #ifndef a_cas | ||
| 19 | #define a_cas a_cas | ||
| 20 | static inline int a_cas(volatile int *p, int t, int s) | ||
| 21 | { | ||
| 22 | 	int old; | ||
| 23 | 	a_pre_llsc(); | ||
| 24 | 	do old = a_ll(p); | ||
| 25 | 	while (old==t && !a_sc(p, s)); | ||
| 26 | 	a_post_llsc(); | ||
| 27 | 	return old; | ||
| 28 | } | ||
| 29 | #endif | ||
| 30 | |||
| 31 | #ifndef a_swap | ||
| 32 | #define a_swap a_swap | ||
| 33 | static inline int a_swap(volatile int *p, int v) | ||
| 34 | { | ||
| 35 | 	int old; | ||
| 36 | 	a_pre_llsc(); | ||
| 37 | 	do old = a_ll(p); | ||
| 38 | 	while (!a_sc(p, v)); | ||
| 39 | 	a_post_llsc(); | ||
| 40 | 	return old; | ||
| 41 | } | ||
| 42 | #endif | ||
| 43 | |||
| 44 | #ifndef a_fetch_add | ||
| 45 | #define a_fetch_add a_fetch_add | ||
| 46 | static inline int a_fetch_add(volatile int *p, int v) | ||
| 47 | { | ||
| 48 | 	int old; | ||
| 49 | 	a_pre_llsc(); | ||
| 50 | 	do old = a_ll(p); | ||
| 51 | 	while (!a_sc(p, (unsigned)old + v)); | ||
| 52 | 	a_post_llsc(); | ||
| 53 | 	return old; | ||
| 54 | } | ||
| 55 | #endif | ||
| 56 | |||
| 57 | #ifndef a_fetch_and | ||
| 58 | #define a_fetch_and a_fetch_and | ||
| 59 | static inline int a_fetch_and(volatile int *p, int v) | ||
| 60 | { | ||
| 61 | 	int old; | ||
| 62 | 	a_pre_llsc(); | ||
| 63 | 	do old = a_ll(p); | ||
| 64 | 	while (!a_sc(p, old & v)); | ||
| 65 | 	a_post_llsc(); | ||
| 66 | 	return old; | ||
| 67 | } | ||
| 68 | #endif | ||
| 69 | |||
| 70 | #ifndef a_fetch_or | ||
| 71 | #define a_fetch_or a_fetch_or | ||
| 72 | static inline int a_fetch_or(volatile int *p, int v) | ||
| 73 | { | ||
| 74 | 	int old; | ||
| 75 | 	a_pre_llsc(); | ||
| 76 | 	do old = a_ll(p); | ||
| 77 | 	while (!a_sc(p, old | v)); | ||
| 78 | 	a_post_llsc(); | ||
| 79 | 	return old; | ||
| 80 | } | ||
| 81 | #endif | ||
| 82 | |||
| 83 | #endif | ||
| 84 | |||
| 85 | #ifdef a_ll_p | ||
| 86 | |||
| 87 | #ifndef a_cas_p | ||
| 88 | #define a_cas_p a_cas_p | ||
| 89 | static inline void *a_cas_p(volatile void *p, void *t, void *s) | ||
| 90 | { | ||
| 91 | 	void *old; | ||
| 92 | 	a_pre_llsc(); | ||
| 93 | 	do old = a_ll_p(p); | ||
| 94 | 	while (old==t && !a_sc_p(p, s)); | ||
| 95 | 	a_post_llsc(); | ||
| 96 | 	return old; | ||
| 97 | } | ||
| 98 | #endif | ||
| 99 | |||
| 100 | #endif | ||
| 101 | |||
| 102 | #ifndef a_cas | ||
| 103 | #error missing definition of a_cas | ||
| 104 | #endif | ||
| 105 | |||
| 106 | #ifndef a_swap | ||
| 107 | #define a_swap a_swap | ||
| 108 | static inline int a_swap(volatile int *p, int v) | ||
| 109 | { | ||
| 110 | 	int old; | ||
| 111 | 	do old = *p; | ||
| 112 | 	while (a_cas(p, old, v) != old); | ||
| 113 | 	return old; | ||
| 114 | } | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #ifndef a_fetch_add | ||
| 118 | #define a_fetch_add a_fetch_add | ||
| 119 | static inline int a_fetch_add(volatile int *p, int v) | ||
| 120 | { | ||
| 121 | 	int old; | ||
| 122 | 	do old = *p; | ||
| 123 | 	while (a_cas(p, old, (unsigned)old+v) != old); | ||
| 124 | 	return old; | ||
| 125 | } | ||
| 126 | #endif | ||
| 127 | |||
| 128 | #ifndef a_fetch_and | ||
| 129 | #define a_fetch_and a_fetch_and | ||
| 130 | static inline int a_fetch_and(volatile int *p, int v) | ||
| 131 | { | ||
| 132 | 	int old; | ||
| 133 | 	do old = *p; | ||
| 134 | 	while (a_cas(p, old, old&v) != old); | ||
| 135 | 	return old; | ||
| 136 | } | ||
| 137 | #endif | ||
| 138 | #ifndef a_fetch_or | ||
| 139 | #define a_fetch_or a_fetch_or | ||
| 140 | static inline int a_fetch_or(volatile int *p, int v) | ||
| 141 | { | ||
| 142 | 	int old; | ||
| 143 | 	do old = *p; | ||
| 144 | 	while (a_cas(p, old, old|v) != old); | ||
| 145 | 	return old; | ||
| 146 | } | ||
| 147 | #endif | ||
| 148 | |||
| 149 | #ifndef a_and | ||
| 150 | #define a_and a_and | ||
| 151 | static inline void a_and(volatile int *p, int v) | ||
| 152 | { | ||
| 153 | 	a_fetch_and(p, v); | ||
| 154 | } | ||
| 155 | #endif | ||
| 156 | |||
| 157 | #ifndef a_or | ||
| 158 | #define a_or a_or | ||
| 159 | static inline void a_or(volatile int *p, int v) | ||
| 160 | { | ||
| 161 | 	a_fetch_or(p, v); | ||
| 162 | } | ||
| 163 | #endif | ||
| 164 | |||
| 165 | #ifndef a_inc | ||
| 166 | #define a_inc a_inc | ||
| 167 | static inline void a_inc(volatile int *p) | ||
| 168 | { | ||
| 169 | 	a_fetch_add(p, 1); | ||
| 170 | } | ||
| 171 | #endif | ||
| 172 | |||
| 173 | #ifndef a_dec | ||
| 174 | #define a_dec a_dec | ||
| 175 | static inline void a_dec(volatile int *p) | ||
| 176 | { | ||
| 177 | 	a_fetch_add(p, -1); | ||
| 178 | } | ||
| 179 | #endif | ||
| 180 | |||
| 181 | #ifndef a_store | ||
| 182 | #define a_store a_store | ||
| 183 | static inline void a_store(volatile int *p, int v) | ||
| 184 | { | ||
| 185 | #ifdef a_barrier | ||
| 186 | 	a_barrier(); | ||
| 187 | 	*p = v; | ||
| 188 | 	a_barrier(); | ||
| 189 | #else | ||
| 190 | 	a_swap(p, v); | ||
| 191 | #endif | ||
| 192 | } | ||
| 193 | #endif | ||
| 194 | |||
| 195 | #ifndef a_barrier | ||
| 196 | #define a_barrier a_barrier | ||
| 197 | static void a_barrier() | ||
| 198 | { | ||
| 199 | 	volatile int tmp = 0; | ||
| 200 | 	a_cas(&tmp, 0, 0); | ||
| 201 | } | ||
| 202 | #endif | ||
| 203 | |||
| 204 | #ifndef a_spin | ||
| 205 | #define a_spin a_barrier | ||
| 206 | #endif | ||
| 207 | |||
| 208 | #ifndef a_and_64 | ||
| 209 | #define a_and_64 a_and_64 | ||
| 210 | static inline void a_and_64(volatile uint64_t *p, uint64_t v) | ||
| 211 | { | ||
| 212 | 	union { uint64_t v; uint32_t r[2]; } u = { v }; | ||
| 213 | 	if (u.r[0]+1) a_and((int *)p, u.r[0]); | ||
| 214 | 	if (u.r[1]+1) a_and((int *)p+1, u.r[1]); | ||
| 215 | } | ||
| 216 | #endif | ||
| 217 | |||
| 218 | #ifndef a_or_64 | ||
| 219 | #define a_or_64 a_or_64 | ||
| 220 | static inline void a_or_64(volatile uint64_t *p, uint64_t v) | ||
| 221 | { | ||
| 222 | 	union { uint64_t v; uint32_t r[2]; } u = { v }; | ||
| 223 | 	if (u.r[0]) a_or((int *)p, u.r[0]); | ||
| 224 | 	if (u.r[1]) a_or((int *)p+1, u.r[1]); | ||
| 225 | } | ||
| 226 | #endif | ||
| 227 | |||
| 228 | #ifndef a_cas_p | ||
| 229 | typedef char a_cas_p_undefined_but_pointer_not_32bit[-sizeof(char) == 0xffffffff ? 1 : -1]; | ||
| 230 | #define a_cas_p a_cas_p | ||
| 231 | static inline void *a_cas_p(volatile void *p, void *t, void *s) | ||
| 232 | { | ||
| 233 | 	return (void *)a_cas((volatile int *)p, (int)t, (int)s); | ||
| 234 | } | ||
| 235 | #endif | ||
| 236 | |||
| 237 | #ifndef a_or_l | ||
| 238 | #define a_or_l a_or_l | ||
| 239 | static inline void a_or_l(volatile void *p, long v) | ||
| 240 | { | ||
| 241 | 	if (sizeof(long) == sizeof(int)) a_or(p, v); | ||
| 242 | 	else a_or_64(p, v); | ||
| 243 | } | ||
| 244 | #endif | ||
| 245 | |||
| 246 | #ifndef a_crash | ||
| 247 | #define a_crash a_crash | ||
| 248 | static inline void a_crash() | ||
| 249 | { | ||
| 250 | 	*(volatile char *)0=0; | ||
| 251 | } | ||
| 252 | #endif | ||
| 253 | |||
| 254 | #ifndef a_ctz_32 | ||
| 255 | #define a_ctz_32 a_ctz_32 | ||
| 256 | static inline int a_ctz_32(uint32_t x) | ||
| 257 | { | ||
| 258 | #ifdef a_clz_32 | ||
| 259 | 	return 31-a_clz_32(x&-x); | ||
| 260 | #else | ||
| 261 | 	static const char debruijn32[32] = { | ||
| 262 | 		0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, | ||
| 263 | 		31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 | ||
| 264 | 	}; | ||
| 265 | 	return debruijn32[(x&-x)*0x076be629 >> 27]; | ||
| 266 | #endif | ||
| 267 | } | ||
| 268 | #endif | ||
| 269 | |||
| 270 | #ifndef a_ctz_64 | ||
| 271 | #define a_ctz_64 a_ctz_64 | ||
| 272 | static inline int a_ctz_64(uint64_t x) | ||
| 273 | { | ||
| 274 | 	static const char debruijn64[64] = { | ||
| 275 | 		0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, | ||
| 276 | 		62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, | ||
| 277 | 		63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, | ||
| 278 | 		51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 | ||
| 279 | 	}; | ||
| 280 | 	if (sizeof(long) < 8) { | ||
| 281 | 		uint32_t y = x; | ||
| 282 | 		if (!y) { | ||
| 283 | 			y = x>>32; | ||
| 284 | 			return 32 + a_ctz_32(y); | ||
| 285 | 		} | ||
| 286 | 		return a_ctz_32(y); | ||
| 287 | 	} | ||
| 288 | 	return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; | ||
| 289 | } | ||
| 290 | #endif | ||
| 291 | |||
| 292 | static inline int a_ctz_l(unsigned long x) | ||
| 293 | { | ||
| 294 | 	return (sizeof(long) < 8) ? a_ctz_32(x) : a_ctz_64(x); | ||
| 295 | } | ||
| 296 | |||
| 297 | #ifndef a_clz_64 | ||
| 298 | #define a_clz_64 a_clz_64 | ||
| 299 | static inline int a_clz_64(uint64_t x) | ||
| 300 | { | ||
| 301 | #ifdef a_clz_32 | ||
| 302 | 	if (x>>32) | ||
| 303 | 		return a_clz_32(x>>32); | ||
| 304 | 	return a_clz_32(x) + 32; | ||
| 305 | #else | ||
| 306 | 	uint32_t y; | ||
| 307 | 	int r; | ||
| 308 | 	if (x>>32) y=x>>32, r=0; else y=x, r=32; | ||
| 309 | 	if (y>>16) y>>=16; else r |= 16; | ||
| 310 | 	if (y>>8) y>>=8; else r |= 8; | ||
| 311 | 	if (y>>4) y>>=4; else r |= 4; | ||
| 312 | 	if (y>>2) y>>=2; else r |= 2; | ||
| 313 | 	return r | !(y>>1); | ||
| 314 | #endif | ||
| 315 | } | ||
| 316 | #endif | ||
| 317 | |||
| 318 | #ifndef a_clz_32 | ||
| 319 | #define a_clz_32 a_clz_32 | ||
| 320 | static inline int a_clz_32(uint32_t x) | ||
| 321 | { | ||
| 322 | 	x >>= 1; | ||
| 323 | 	x |= x >> 1; | ||
| 324 | 	x |= x >> 2; | ||
| 325 | 	x |= x >> 4; | ||
| 326 | 	x |= x >> 8; | ||
| 327 | 	x |= x >> 16; | ||
| 328 | 	x++; | ||
| 329 | 	return 31-a_ctz_32(x); | ||
| 330 | } | ||
| 331 | #endif | ||
| 332 | |||
| 333 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/complex_impl.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 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 created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #include "libc.h" | ||
| 2 | |||
| 3 | size_t __sysinfo; | ||
lib/libc/wasi/libc-top-half/musl/src/internal/dynlink.h created+113| ... | @@ -0,0 +1,113 @@ | ||
| 1 | #ifndef _INTERNAL_RELOC_H | ||
| 2 | #define _INTERNAL_RELOC_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <elf.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stddef.h> | ||
| 8 | #include <stdarg.h> | ||
| 9 | |||
| 10 | #if UINTPTR_MAX == 0xffffffff | ||
| 11 | typedef Elf32_Ehdr Ehdr; | ||
| 12 | typedef Elf32_Phdr Phdr; | ||
| 13 | typedef Elf32_Sym Sym; | ||
| 14 | #define R_TYPE(x) ((x)&255) | ||
| 15 | #define R_SYM(x) ((x)>>8) | ||
| 16 | #define R_INFO ELF32_R_INFO | ||
| 17 | #else | ||
| 18 | typedef Elf64_Ehdr Ehdr; | ||
| 19 | typedef Elf64_Phdr Phdr; | ||
| 20 | typedef Elf64_Sym Sym; | ||
| 21 | #define R_TYPE(x) ((x)&0x7fffffff) | ||
| 22 | #define R_SYM(x) ((x)>>32) | ||
| 23 | #define R_INFO ELF64_R_INFO | ||
| 24 | #endif | ||
| 25 | |||
| 26 | /* These enum constants provide unmatchable default values for | ||
| 27 | * any relocation type the arch does not use. */ | ||
| 28 | enum { | ||
| 29 | 	REL_NONE = 0, | ||
| 30 | 	REL_SYMBOLIC = -100, | ||
| 31 | 	REL_USYMBOLIC, | ||
| 32 | 	REL_GOT, | ||
| 33 | 	REL_PLT, | ||
| 34 | 	REL_RELATIVE, | ||
| 35 | 	REL_OFFSET, | ||
| 36 | 	REL_OFFSET32, | ||
| 37 | 	REL_COPY, | ||
| 38 | 	REL_SYM_OR_REL, | ||
| 39 | 	REL_DTPMOD, | ||
| 40 | 	REL_DTPOFF, | ||
| 41 | 	REL_TPOFF, | ||
| 42 | 	REL_TPOFF_NEG, | ||
| 43 | 	REL_TLSDESC, | ||
| 44 | 	REL_FUNCDESC, | ||
| 45 | 	REL_FUNCDESC_VAL, | ||
| 46 | }; | ||
| 47 | |||
| 48 | struct fdpic_loadseg { | ||
| 49 | 	uintptr_t addr, p_vaddr, p_memsz; | ||
| 50 | }; | ||
| 51 | |||
| 52 | struct fdpic_loadmap { | ||
| 53 | 	unsigned short version, nsegs; | ||
| 54 | 	struct fdpic_loadseg segs[]; | ||
| 55 | }; | ||
| 56 | |||
| 57 | struct fdpic_dummy_loadmap { | ||
| 58 | 	unsigned short version, nsegs; | ||
| 59 | 	struct fdpic_loadseg segs[1]; | ||
| 60 | }; | ||
| 61 | |||
| 62 | #include "reloc.h" | ||
| 63 | |||
| 64 | #ifndef FDPIC_CONSTDISP_FLAG | ||
| 65 | #define FDPIC_CONSTDISP_FLAG 0 | ||
| 66 | #endif | ||
| 67 | |||
| 68 | #ifndef DL_FDPIC | ||
| 69 | #define DL_FDPIC 0 | ||
| 70 | #endif | ||
| 71 | |||
| 72 | #ifndef DL_NOMMU_SUPPORT | ||
| 73 | #define DL_NOMMU_SUPPORT 0 | ||
| 74 | #endif | ||
| 75 | |||
| 76 | #if !DL_FDPIC | ||
| 77 | #define IS_RELATIVE(x,s) ( \ | ||
| 78 | 	(R_TYPE(x) == REL_RELATIVE) || \ | ||
| 79 | 	(R_TYPE(x) == REL_SYM_OR_REL && !R_SYM(x)) ) | ||
| 80 | #else | ||
| 81 | #define IS_RELATIVE(x,s) ( ( \ | ||
| 82 | 	(R_TYPE(x) == REL_FUNCDESC_VAL) || \ | ||
| 83 | 	(R_TYPE(x) == REL_SYMBOLIC) ) \ | ||
| 84 | 	&& (((s)[R_SYM(x)].st_info & 0xf) == STT_SECTION) ) | ||
| 85 | #endif | ||
| 86 | |||
| 87 | #ifndef NEED_MIPS_GOT_RELOCS | ||
| 88 | #define NEED_MIPS_GOT_RELOCS 0 | ||
| 89 | #endif | ||
| 90 | |||
| 91 | #ifndef DT_DEBUG_INDIRECT | ||
| 92 | #define DT_DEBUG_INDIRECT 0 | ||
| 93 | #endif | ||
| 94 | |||
| 95 | #define AUX_CNT 32 | ||
| 96 | #define DYN_CNT 32 | ||
| 97 | |||
| 98 | typedef void (*stage2_func)(unsigned char *, size_t *); | ||
| 99 | |||
| 100 | hidden void *__dlsym(void *restrict, const char *restrict, void *restrict); | ||
| 101 | |||
| 102 | hidden void __dl_seterr(const char *, ...); | ||
| 103 | hidden int __dl_invalid_handle(void *); | ||
| 104 | hidden void __dl_vseterr(const char *, va_list); | ||
| 105 | |||
| 106 | hidden ptrdiff_t __tlsdesc_static(), __tlsdesc_dynamic(); | ||
| 107 | |||
| 108 | hidden extern int __malloc_replaced; | ||
| 109 | hidden extern int __aligned_alloc_replaced; | ||
| 110 | hidden void __malloc_donate(char *, char *); | ||
| 111 | hidden int __malloc_allzerop(void *); | ||
| 112 | |||
| 113 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/fdpic_crt.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <features.h> | ||
| 3 | |||
| 4 | hidden void *__fdpic_fixup(void *map, uintptr_t *a, uintptr_t *z) | ||
| 5 | { | ||
| 6 | 	/* If map is a null pointer, the program was loaded by a | ||
| 7 | 	 * non-FDPIC-aware ELF loader, and fixups are not needed, | ||
| 8 | 	 * but the value for the GOT pointer is. */ | ||
| 9 | 	if (!map) return (void *)z[-1]; | ||
| 10 | |||
| 11 | 	struct { | ||
| 12 | 		unsigned short version, nsegs; | ||
| 13 | 		struct fdpic_loadseg { | ||
| 14 | 			uintptr_t addr, p_vaddr, p_memsz; | ||
| 15 | 		} segs[]; | ||
| 16 | 	} *lm = map; | ||
| 17 | 	int nsegs = lm->nsegs, rseg = 0, vseg = 0; | ||
| 18 | 	for (;;) { | ||
| 19 | 		while (*a-lm->segs[rseg].p_vaddr >= lm->segs[rseg].p_memsz) | ||
| 20 | 			if (++rseg == nsegs) rseg = 0; | ||
| 21 | 		uintptr_t *r = (uintptr_t *) | ||
| 22 | 			(*a + lm->segs[rseg].addr - lm->segs[rseg].p_vaddr); | ||
| 23 | 		if (++a == z) return r; | ||
| 24 | 		while (*r-lm->segs[vseg].p_vaddr >= lm->segs[vseg].p_memsz) | ||
| 25 | 			if (++vseg == nsegs) vseg = 0; | ||
| 26 | 		*r += lm->segs[vseg].addr - lm->segs[vseg].p_vaddr; | ||
| 27 | 	} | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/floatscan.c created+556| ... | @@ -0,0 +1,556 @@ | ||
| 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/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 created+12| ... | @@ -0,0 +1,12 @@ | ||
| 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 created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 __dlerror_lockptr; | ||
| 7 | extern hidden volatile int *const __gettext_lockptr; | ||
| 8 | extern hidden volatile int *const __locale_lockptr; | ||
| 9 | extern hidden volatile int *const __random_lockptr; | ||
| 10 | extern hidden volatile int *const __sem_open_lockptr; | ||
| 11 | extern hidden volatile int *const __stdio_ofl_lockptr; | ||
| 12 | extern hidden volatile int *const __syslog_lockptr; | ||
| 13 | extern hidden volatile int *const __timezone_lockptr; | ||
| 14 | |||
| 15 | extern hidden volatile int *const __bump_lockptr; | ||
| 16 | |||
| 17 | extern hidden volatile int *const __vmlock_lockptr; | ||
| 18 | |||
| 19 | hidden void __malloc_atfork(int); | ||
| 20 | hidden void __ldso_atfork(int); | ||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/futex.h created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #ifndef _INTERNAL_FUTEX_H | ||
| 2 | #define _INTERNAL_FUTEX_H | ||
| 3 | |||
| 4 | #define FUTEX_WAIT		0 | ||
| 5 | #define FUTEX_WAKE		1 | ||
| 6 | #define FUTEX_FD		2 | ||
| 7 | #define FUTEX_REQUEUE		3 | ||
| 8 | #define FUTEX_CMP_REQUEUE	4 | ||
| 9 | #define FUTEX_WAKE_OP		5 | ||
| 10 | #define FUTEX_LOCK_PI		6 | ||
| 11 | #define FUTEX_UNLOCK_PI		7 | ||
| 12 | #define FUTEX_TRYLOCK_PI	8 | ||
| 13 | #define FUTEX_WAIT_BITSET	9 | ||
| 14 | |||
| 15 | #define FUTEX_PRIVATE 128 | ||
| 16 | |||
| 17 | #define FUTEX_CLOCK_REALTIME 256 | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/i386/defsysinfo.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | 1:	int $128 | ||
| 2 | 	ret | ||
| 3 | |||
| 4 | .data | ||
| 5 | .align 4 | ||
| 6 | .hidden __sysinfo | ||
| 7 | .global __sysinfo | ||
| 8 | __sysinfo: | ||
| 9 | 	.long 1b | ||
lib/libc/wasi/libc-top-half/musl/src/internal/intscan.c created+100| ... | @@ -0,0 +1,100 @@ | ||
| 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/intscan.h created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #ifndef INTSCAN_H | ||
| 2 | #define INTSCAN_H | ||
| 3 | |||
| 4 | #include <stdio.h> | ||
| 5 | |||
| 6 | hidden unsigned long long __intscan(FILE *, unsigned, int, unsigned long long); | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/ksigaction.h created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | /* This is the structure used for the rt_sigaction syscall on most archs, | ||
| 4 | * but it can be overridden by a file with the same name in the top-level | ||
| 5 | * arch dir for a given arch, if necessary. */ | ||
| 6 | struct k_sigaction { | ||
| 7 | 	void (*handler)(int); | ||
| 8 | 	unsigned long flags; | ||
| 9 | 	void (*restorer)(void); | ||
| 10 | 	unsigned mask[2]; | ||
| 11 | }; | ||
| 12 | |||
| 13 | hidden void __restore(), __restore_rt(); | ||
lib/libc/wasi/libc-top-half/musl/src/internal/libc.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 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 created+74| ... | @@ -0,0 +1,74 @@ | ||
| 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 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 22 | 	char can_do_threads; | ||
| 23 | 	char threaded; | ||
| 24 | #endif | ||
| 25 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't currently use any code that needs "secure" mode | ||
| 26 | 	char secure; | ||
| 27 | #endif | ||
| 28 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 29 | 	volatile signed char need_locks; | ||
| 30 | 	int threads_minus_1; | ||
| 31 | #endif | ||
| 32 | #ifdef __wasilibc_unmodified_upstream // WASI has no auxv | ||
| 33 | 	size_t *auxv; | ||
| 34 | #endif | ||
| 35 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 36 | 	struct tls_module *tls_head; | ||
| 37 | 	size_t tls_size, tls_align, tls_cnt; | ||
| 38 | #endif | ||
| 39 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't get the page size from auxv | ||
| 40 | 	size_t page_size; | ||
| 41 | #endif | ||
| 42 | 	struct __locale_struct global_locale; | ||
| 43 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 44 | #else | ||
| 45 | 	struct __locale_struct *current_locale; | ||
| 46 | #endif | ||
| 47 | }; | ||
| 48 | |||
| 49 | #ifndef PAGE_SIZE | ||
| 50 | #define PAGE_SIZE libc.page_size | ||
| 51 | #endif | ||
| 52 | |||
| 53 | extern hidden struct __libc __libc; | ||
| 54 | #define libc __libc | ||
| 55 | |||
| 56 | hidden void __init_libc(char **, char *); | ||
| 57 | hidden void __init_tls(size_t *); | ||
| 58 | hidden void __init_ssp(void *); | ||
| 59 | hidden void __libc_start_init(void); | ||
| 60 | hidden void __funcs_on_exit(void); | ||
| 61 | hidden void __funcs_on_quick_exit(void); | ||
| 62 | hidden void __libc_exit_fini(void); | ||
| 63 | hidden void __fork_handler(int); | ||
| 64 | |||
| 65 | extern hidden size_t __hwcap; | ||
| 66 | extern hidden size_t __sysinfo; | ||
| 67 | extern char *__progname, *__progname_full; | ||
| 68 | |||
| 69 | extern hidden const char __libc_version[]; | ||
| 70 | |||
| 71 | hidden void __synccall(void (*)(void *), void *); | ||
| 72 | hidden int __setxid(int, int, int, int); | ||
| 73 | |||
| 74 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/libm.h created+292| ... | @@ -0,0 +1,292 @@ | ||
| 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 created+65| ... | @@ -0,0 +1,65 @@ | ||
| 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 | hidden const char *__lctrans_cur(const char *); | ||
| 32 | hidden const char *__lctrans_impl(const char *, const struct __locale_map *); | ||
| 33 | hidden int __loc_is_allocated(locale_t); | ||
| 34 | hidden char *__gettextdomain(void); | ||
| 35 | |||
| 36 | #define LOC_MAP_FAILED ((const struct __locale_map *)-1) | ||
| 37 | |||
| 38 | #define LCTRANS(msg, lc, loc) __lctrans(msg, (loc)->cat[(lc)]) | ||
| 39 | #define LCTRANS_CUR(msg) __lctrans_cur(msg) | ||
| 40 | |||
| 41 | #define C_LOCALE ((locale_t)&__c_locale) | ||
| 42 | #define UTF8_LOCALE ((locale_t)&__c_dot_utf8_locale) | ||
| 43 | |||
| 44 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 45 | #define CURRENT_LOCALE (__pthread_self()->locale) | ||
| 46 | |||
| 47 | #define CURRENT_UTF8 (!!__pthread_self()->locale->cat[LC_CTYPE]) | ||
| 48 | #else | ||
| 49 | // If we haven't set up the current_local field yet, do so. Then return an | ||
| 50 | // lvalue for the current_locale field. | ||
| 51 | #define CURRENT_LOCALE \ | ||
| 52 | (*({ \ | ||
| 53 | if (!libc.current_locale) { \ | ||
| 54 | libc.current_locale = &libc.global_locale; \ | ||
| 55 | } \ | ||
| 56 | &libc.current_locale; \ | ||
| 57 | })) | ||
| 58 | |||
| 59 | #define CURRENT_UTF8 (!!libc.global_locale.cat[LC_CTYPE]) | ||
| 60 | #endif | ||
| 61 | |||
| 62 | #undef MB_CUR_MAX | ||
| 63 | #define MB_CUR_MAX (CURRENT_UTF8 ? 4 : 1) | ||
| 64 | |||
| 65 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/lock.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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/procfdname.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | void __procfdname(char *buf, unsigned fd) | ||
| 4 | { | ||
| 5 | 	unsigned i, j; | ||
| 6 | 	for (i=0; (buf[i] = "/proc/self/fd/"[i]); i++); | ||
| 7 | 	if (!fd) { | ||
| 8 | 		buf[i] = '0'; | ||
| 9 | 		buf[i+1] = 0; | ||
| 10 | 		return; | ||
| 11 | 	} | ||
| 12 | 	for (j=fd; j; j/=10, i++); | ||
| 13 | 	buf[i] = 0; | ||
| 14 | 	for (; fd; fd/=10) buf[--i] = '0' + fd%10; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/pthread_impl.h created+205| ... | @@ -0,0 +1,205 @@ | ||
| 1 | #ifndef _PTHREAD_IMPL_H | ||
| 2 | #define _PTHREAD_IMPL_H | ||
| 3 | |||
| 4 | #include <pthread.h> | ||
| 5 | #include <signal.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <limits.h> | ||
| 8 | #include <sys/mman.h> | ||
| 9 | #include "libc.h" | ||
| 10 | #include "syscall.h" | ||
| 11 | #include "atomic.h" | ||
| 12 | #include "futex.h" | ||
| 13 | |||
| 14 | #include "pthread_arch.h" | ||
| 15 | |||
| 16 | #define pthread __pthread | ||
| 17 | |||
| 18 | struct pthread { | ||
| 19 | 	/* Part 1 -- these fields may be external or | ||
| 20 | 	 * internal (accessed via asm) ABI. Do not change. */ | ||
| 21 | 	struct pthread *self; | ||
| 22 | #ifndef TLS_ABOVE_TP | ||
| 23 | 	uintptr_t *dtv; | ||
| 24 | #endif | ||
| 25 | 	struct pthread *prev, *next; /* non-ABI */ | ||
| 26 | 	uintptr_t sysinfo; | ||
| 27 | #ifndef TLS_ABOVE_TP | ||
| 28 | #ifdef CANARY_PAD | ||
| 29 | 	uintptr_t canary_pad; | ||
| 30 | #endif | ||
| 31 | 	uintptr_t canary; | ||
| 32 | #endif | ||
| 33 | |||
| 34 | 	/* Part 2 -- implementation details, non-ABI. */ | ||
| 35 | 	int tid; | ||
| 36 | 	int errno_val; | ||
| 37 | 	volatile int detach_state; | ||
| 38 | 	volatile int cancel; | ||
| 39 | 	volatile unsigned char canceldisable, cancelasync; | ||
| 40 | 	unsigned char tsd_used:1; | ||
| 41 | 	unsigned char dlerror_flag:1; | ||
| 42 | 	unsigned char *map_base; | ||
| 43 | 	size_t map_size; | ||
| 44 | 	void *stack; | ||
| 45 | 	size_t stack_size; | ||
| 46 | 	size_t guard_size; | ||
| 47 | 	void *result; | ||
| 48 | 	struct __ptcb *cancelbuf; | ||
| 49 | 	void **tsd; | ||
| 50 | 	struct { | ||
| 51 | 		volatile void *volatile head; | ||
| 52 | 		long off; | ||
| 53 | 		volatile void *volatile pending; | ||
| 54 | 	} robust_list; | ||
| 55 | 	int h_errno_val; | ||
| 56 | 	volatile int timer_id; | ||
| 57 | 	locale_t locale; | ||
| 58 | 	volatile int killlock[1]; | ||
| 59 | 	char *dlerror_buf; | ||
| 60 | 	void *stdio_locks; | ||
| 61 | |||
| 62 | 	/* Part 3 -- the positions of these fields relative to | ||
| 63 | 	 * the end of the structure is external and internal ABI. */ | ||
| 64 | #ifdef TLS_ABOVE_TP | ||
| 65 | 	uintptr_t canary; | ||
| 66 | 	uintptr_t *dtv; | ||
| 67 | #endif | ||
| 68 | }; | ||
| 69 | |||
| 70 | enum { | ||
| 71 | 	DT_EXITED = 0, | ||
| 72 | 	DT_EXITING, | ||
| 73 | 	DT_JOINABLE, | ||
| 74 | 	DT_DETACHED, | ||
| 75 | }; | ||
| 76 | |||
| 77 | #define __SU (sizeof(size_t)/sizeof(int)) | ||
| 78 | |||
| 79 | #define _a_stacksize __u.__s[0] | ||
| 80 | #define _a_guardsize __u.__s[1] | ||
| 81 | #define _a_stackaddr __u.__s[2] | ||
| 82 | #define _a_detach __u.__i[3*__SU+0] | ||
| 83 | #define _a_sched __u.__i[3*__SU+1] | ||
| 84 | #define _a_policy __u.__i[3*__SU+2] | ||
| 85 | #define _a_prio __u.__i[3*__SU+3] | ||
| 86 | #define _m_type __u.__i[0] | ||
| 87 | #define _m_lock __u.__vi[1] | ||
| 88 | #define _m_waiters __u.__vi[2] | ||
| 89 | #define _m_prev __u.__p[3] | ||
| 90 | #define _m_next __u.__p[4] | ||
| 91 | #define _m_count __u.__i[5] | ||
| 92 | #define _c_shared __u.__p[0] | ||
| 93 | #define _c_seq __u.__vi[2] | ||
| 94 | #define _c_waiters __u.__vi[3] | ||
| 95 | #define _c_clock __u.__i[4] | ||
| 96 | #define _c_lock __u.__vi[8] | ||
| 97 | #define _c_head __u.__p[1] | ||
| 98 | #define _c_tail __u.__p[5] | ||
| 99 | #define _rw_lock __u.__vi[0] | ||
| 100 | #define _rw_waiters __u.__vi[1] | ||
| 101 | #define _rw_shared __u.__i[2] | ||
| 102 | #define _b_lock __u.__vi[0] | ||
| 103 | #define _b_waiters __u.__vi[1] | ||
| 104 | #define _b_limit __u.__i[2] | ||
| 105 | #define _b_count __u.__vi[3] | ||
| 106 | #define _b_waiters2 __u.__vi[4] | ||
| 107 | #define _b_inst __u.__p[3] | ||
| 108 | |||
| 109 | #ifndef TP_OFFSET | ||
| 110 | #define TP_OFFSET 0 | ||
| 111 | #endif | ||
| 112 | |||
| 113 | #ifndef DTP_OFFSET | ||
| 114 | #define DTP_OFFSET 0 | ||
| 115 | #endif | ||
| 116 | |||
| 117 | #ifdef TLS_ABOVE_TP | ||
| 118 | #define TP_ADJ(p) ((char *)(p) + sizeof(struct pthread) + TP_OFFSET) | ||
| 119 | #define __pthread_self() ((pthread_t)(__get_tp() - sizeof(struct __pthread) - TP_OFFSET)) | ||
| 120 | #else | ||
| 121 | #define TP_ADJ(p) (p) | ||
| 122 | #define __pthread_self() ((pthread_t)__get_tp()) | ||
| 123 | #endif | ||
| 124 | |||
| 125 | #ifndef tls_mod_off_t | ||
| 126 | #define tls_mod_off_t size_t | ||
| 127 | #endif | ||
| 128 | |||
| 129 | #define SIGTIMER 32 | ||
| 130 | #define SIGCANCEL 33 | ||
| 131 | #define SIGSYNCCALL 34 | ||
| 132 | |||
| 133 | #define SIGALL_SET ((sigset_t *)(const unsigned long long [2]){ -1,-1 }) | ||
| 134 | #define SIGPT_SET \ | ||
| 135 | 	((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ | ||
| 136 | 	[sizeof(long)==4] = 3UL<<(32*(sizeof(long)>4)) }) | ||
| 137 | #define SIGTIMER_SET \ | ||
| 138 | 	((sigset_t *)(const unsigned long [_NSIG/8/sizeof(long)]){ \ | ||
| 139 | 	 0x80000000 }) | ||
| 140 | |||
| 141 | void *__tls_get_addr(tls_mod_off_t *); | ||
| 142 | hidden int __init_tp(void *); | ||
| 143 | hidden void *__copy_tls(unsigned char *); | ||
| 144 | hidden void __reset_tls(); | ||
| 145 | |||
| 146 | hidden void __membarrier_init(void); | ||
| 147 | hidden void __dl_thread_cleanup(void); | ||
| 148 | hidden void __testcancel(); | ||
| 149 | hidden void __do_cleanup_push(struct __ptcb *); | ||
| 150 | hidden void __do_cleanup_pop(struct __ptcb *); | ||
| 151 | hidden void __pthread_tsd_run_dtors(); | ||
| 152 | |||
| 153 | hidden void __pthread_key_delete_synccall(void (*)(void *), void *); | ||
| 154 | hidden int __pthread_key_delete_impl(pthread_key_t); | ||
| 155 | |||
| 156 | extern hidden volatile size_t __pthread_tsd_size; | ||
| 157 | extern hidden void *__pthread_tsd_main[]; | ||
| 158 | extern hidden volatile int __eintr_valid_flag; | ||
| 159 | |||
| 160 | hidden int __clone(int (*)(void *), void *, int, void *, ...); | ||
| 161 | hidden int __set_thread_area(void *); | ||
| 162 | hidden int __libc_sigaction(int, const struct sigaction *, struct sigaction *); | ||
| 163 | hidden void __unmapself(void *, size_t); | ||
| 164 | |||
| 165 | hidden int __timedwait(volatile int *, int, clockid_t, const struct timespec *, int); | ||
| 166 | hidden int __timedwait_cp(volatile int *, int, clockid_t, const struct timespec *, int); | ||
| 167 | hidden void __wait(volatile int *, volatile int *, int, int); | ||
| 168 | static inline void __wake(volatile void *addr, int cnt, int priv) | ||
| 169 | { | ||
| 170 | 	if (priv) priv = FUTEX_PRIVATE; | ||
| 171 | 	if (cnt<0) cnt = INT_MAX; | ||
| 172 | 	__syscall(SYS_futex, addr, FUTEX_WAKE|priv, cnt) != -ENOSYS || | ||
| 173 | 	__syscall(SYS_futex, addr, FUTEX_WAKE, cnt); | ||
| 174 | } | ||
| 175 | static inline void __futexwait(volatile void *addr, int val, int priv) | ||
| 176 | { | ||
| 177 | 	if (priv) priv = FUTEX_PRIVATE; | ||
| 178 | 	__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS || | ||
| 179 | 	__syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); | ||
| 180 | } | ||
| 181 | |||
| 182 | hidden void __acquire_ptc(void); | ||
| 183 | hidden void __release_ptc(void); | ||
| 184 | hidden void __inhibit_ptc(void); | ||
| 185 | |||
| 186 | hidden void __tl_lock(void); | ||
| 187 | hidden void __tl_unlock(void); | ||
| 188 | hidden void __tl_sync(pthread_t); | ||
| 189 | |||
| 190 | extern hidden volatile int __thread_list_lock; | ||
| 191 | |||
| 192 | extern hidden volatile int __abort_lock[1]; | ||
| 193 | |||
| 194 | extern hidden unsigned __default_stacksize; | ||
| 195 | extern hidden unsigned __default_guardsize; | ||
| 196 | |||
| 197 | #define DEFAULT_STACK_SIZE 131072 | ||
| 198 | #define DEFAULT_GUARD_SIZE 8192 | ||
| 199 | |||
| 200 | #define DEFAULT_STACK_MAX (8<<20) | ||
| 201 | #define DEFAULT_GUARD_MAX (1<<20) | ||
| 202 | |||
| 203 | #define __ATTRP_C11_THREAD ((void*)(uintptr_t)-1) | ||
| 204 | |||
| 205 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/sh/__shcall.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | hidden int __shcall(void *arg, int (*func)(void *)) | ||
| 4 | { | ||
| 5 | 	return func(arg); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/shgetc.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 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 created+32| ... | @@ -0,0 +1,32 @@ | ||
| 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 created+137| ... | @@ -0,0 +1,137 @@ | ||
| 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 created+398| ... | @@ -0,0 +1,398 @@ | ||
| 1 | #ifndef _INTERNAL_SYSCALL_H | ||
| 2 | #define _INTERNAL_SYSCALL_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <sys/syscall.h> | ||
| 7 | #include "syscall_arch.h" | ||
| 8 | |||
| 9 | #ifndef SYSCALL_RLIM_INFINITY | ||
| 10 | #define SYSCALL_RLIM_INFINITY (~0ULL) | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #ifndef SYSCALL_MMAP2_UNIT | ||
| 14 | #define SYSCALL_MMAP2_UNIT 4096ULL | ||
| 15 | #endif | ||
| 16 | |||
| 17 | #ifndef __SYSCALL_LL_PRW | ||
| 18 | #define __SYSCALL_LL_PRW(x) __SYSCALL_LL_O(x) | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #ifndef __scc | ||
| 22 | #define __scc(X) ((long) (X)) | ||
| 23 | typedef long syscall_arg_t; | ||
| 24 | #endif | ||
| 25 | |||
| 26 | hidden long __syscall_ret(unsigned long), | ||
| 27 | 	__syscall_cp(syscall_arg_t, syscall_arg_t, syscall_arg_t, syscall_arg_t, | ||
| 28 | 	 syscall_arg_t, syscall_arg_t, syscall_arg_t); | ||
| 29 | |||
| 30 | #define __syscall1(n,a) __syscall1(n,__scc(a)) | ||
| 31 | #define __syscall2(n,a,b) __syscall2(n,__scc(a),__scc(b)) | ||
| 32 | #define __syscall3(n,a,b,c) __syscall3(n,__scc(a),__scc(b),__scc(c)) | ||
| 33 | #define __syscall4(n,a,b,c,d) __syscall4(n,__scc(a),__scc(b),__scc(c),__scc(d)) | ||
| 34 | #define __syscall5(n,a,b,c,d,e) __syscall5(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e)) | ||
| 35 | #define __syscall6(n,a,b,c,d,e,f) __syscall6(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),__scc(f)) | ||
| 36 | #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)) | ||
| 37 | |||
| 38 | #define __SYSCALL_NARGS_X(a,b,c,d,e,f,g,h,n,...) n | ||
| 39 | #define __SYSCALL_NARGS(...) __SYSCALL_NARGS_X(__VA_ARGS__,7,6,5,4,3,2,1,0,) | ||
| 40 | #define __SYSCALL_CONCAT_X(a,b) a##b | ||
| 41 | #define __SYSCALL_CONCAT(a,b) __SYSCALL_CONCAT_X(a,b) | ||
| 42 | #define __SYSCALL_DISP(b,...) __SYSCALL_CONCAT(b,__SYSCALL_NARGS(__VA_ARGS__))(__VA_ARGS__) | ||
| 43 | |||
| 44 | #define __syscall(...) __SYSCALL_DISP(__syscall,__VA_ARGS__) | ||
| 45 | #define syscall(...) __syscall_ret(__syscall(__VA_ARGS__)) | ||
| 46 | |||
| 47 | #define socketcall(nm,a,b,c,d,e,f) __syscall_ret(__socketcall(nm,a,b,c,d,e,f)) | ||
| 48 | #define socketcall_cp(nm,a,b,c,d,e,f) __syscall_ret(__socketcall_cp(nm,a,b,c,d,e,f)) | ||
| 49 | |||
| 50 | #define __syscall_cp0(n) (__syscall_cp)(n,0,0,0,0,0,0) | ||
| 51 | #define __syscall_cp1(n,a) (__syscall_cp)(n,__scc(a),0,0,0,0,0) | ||
| 52 | #define __syscall_cp2(n,a,b) (__syscall_cp)(n,__scc(a),__scc(b),0,0,0,0) | ||
| 53 | #define __syscall_cp3(n,a,b,c) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),0,0,0) | ||
| 54 | #define __syscall_cp4(n,a,b,c,d) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),0,0) | ||
| 55 | #define __syscall_cp5(n,a,b,c,d,e) (__syscall_cp)(n,__scc(a),__scc(b),__scc(c),__scc(d),__scc(e),0) | ||
| 56 | #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)) | ||
| 57 | |||
| 58 | #define __syscall_cp(...) __SYSCALL_DISP(__syscall_cp,__VA_ARGS__) | ||
| 59 | #define syscall_cp(...) __syscall_ret(__syscall_cp(__VA_ARGS__)) | ||
| 60 | |||
| 61 | static inline long __alt_socketcall(int sys, int sock, int cp, long a, long b, long c, long d, long e, long f) | ||
| 62 | { | ||
| 63 | 	long r; | ||
| 64 | 	if (cp) r = __syscall_cp(sys, a, b, c, d, e, f); | ||
| 65 | 	else r = __syscall(sys, a, b, c, d, e, f); | ||
| 66 | 	if (r != -ENOSYS) return r; | ||
| 67 | #ifdef SYS_socketcall | ||
| 68 | 	if (cp) r = __syscall_cp(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f})); | ||
| 69 | 	else r = __syscall(SYS_socketcall, sock, ((long[6]){a, b, c, d, e, f})); | ||
| 70 | #endif | ||
| 71 | 	return r; | ||
| 72 | } | ||
| 73 | #define __socketcall(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 0, \ | ||
| 74 | 	(long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f)) | ||
| 75 | #define __socketcall_cp(nm, a, b, c, d, e, f) __alt_socketcall(SYS_##nm, __SC_##nm, 1, \ | ||
| 76 | 	(long)(a), (long)(b), (long)(c), (long)(d), (long)(e), (long)(f)) | ||
| 77 | |||
| 78 | /* fixup legacy 16-bit junk */ | ||
| 79 | |||
| 80 | #ifdef SYS_getuid32 | ||
| 81 | #undef SYS_lchown | ||
| 82 | #undef SYS_getuid | ||
| 83 | #undef SYS_getgid | ||
| 84 | #undef SYS_geteuid | ||
| 85 | #undef SYS_getegid | ||
| 86 | #undef SYS_setreuid | ||
| 87 | #undef SYS_setregid | ||
| 88 | #undef SYS_getgroups | ||
| 89 | #undef SYS_setgroups | ||
| 90 | #undef SYS_fchown | ||
| 91 | #undef SYS_setresuid | ||
| 92 | #undef SYS_getresuid | ||
| 93 | #undef SYS_setresgid | ||
| 94 | #undef SYS_getresgid | ||
| 95 | #undef SYS_chown | ||
| 96 | #undef SYS_setuid | ||
| 97 | #undef SYS_setgid | ||
| 98 | #undef SYS_setfsuid | ||
| 99 | #undef SYS_setfsgid | ||
| 100 | #define SYS_lchown SYS_lchown32 | ||
| 101 | #define SYS_getuid SYS_getuid32 | ||
| 102 | #define SYS_getgid SYS_getgid32 | ||
| 103 | #define SYS_geteuid SYS_geteuid32 | ||
| 104 | #define SYS_getegid SYS_getegid32 | ||
| 105 | #define SYS_setreuid SYS_setreuid32 | ||
| 106 | #define SYS_setregid SYS_setregid32 | ||
| 107 | #define SYS_getgroups SYS_getgroups32 | ||
| 108 | #define SYS_setgroups SYS_setgroups32 | ||
| 109 | #define SYS_fchown SYS_fchown32 | ||
| 110 | #define SYS_setresuid SYS_setresuid32 | ||
| 111 | #define SYS_getresuid SYS_getresuid32 | ||
| 112 | #define SYS_setresgid SYS_setresgid32 | ||
| 113 | #define SYS_getresgid SYS_getresgid32 | ||
| 114 | #define SYS_chown SYS_chown32 | ||
| 115 | #define SYS_setuid SYS_setuid32 | ||
| 116 | #define SYS_setgid SYS_setgid32 | ||
| 117 | #define SYS_setfsuid SYS_setfsuid32 | ||
| 118 | #define SYS_setfsgid SYS_setfsgid32 | ||
| 119 | #endif | ||
| 120 | |||
| 121 | |||
| 122 | /* fixup legacy 32-bit-vs-lfs64 junk */ | ||
| 123 | |||
| 124 | #ifdef SYS_fcntl64 | ||
| 125 | #undef SYS_fcntl | ||
| 126 | #define SYS_fcntl SYS_fcntl64 | ||
| 127 | #endif | ||
| 128 | |||
| 129 | #ifdef SYS_getdents64 | ||
| 130 | #undef SYS_getdents | ||
| 131 | #define SYS_getdents SYS_getdents64 | ||
| 132 | #endif | ||
| 133 | |||
| 134 | #ifdef SYS_ftruncate64 | ||
| 135 | #undef SYS_ftruncate | ||
| 136 | #undef SYS_truncate | ||
| 137 | #define SYS_ftruncate SYS_ftruncate64 | ||
| 138 | #define SYS_truncate SYS_truncate64 | ||
| 139 | #endif | ||
| 140 | |||
| 141 | #ifdef SYS_stat64 | ||
| 142 | #undef SYS_stat | ||
| 143 | #define SYS_stat SYS_stat64 | ||
| 144 | #endif | ||
| 145 | |||
| 146 | #ifdef SYS_fstat64 | ||
| 147 | #undef SYS_fstat | ||
| 148 | #define SYS_fstat SYS_fstat64 | ||
| 149 | #endif | ||
| 150 | |||
| 151 | #ifdef SYS_lstat64 | ||
| 152 | #undef SYS_lstat | ||
| 153 | #define SYS_lstat SYS_lstat64 | ||
| 154 | #endif | ||
| 155 | |||
| 156 | #ifdef SYS_statfs64 | ||
| 157 | #undef SYS_statfs | ||
| 158 | #define SYS_statfs SYS_statfs64 | ||
| 159 | #endif | ||
| 160 | |||
| 161 | #ifdef SYS_fstatfs64 | ||
| 162 | #undef SYS_fstatfs | ||
| 163 | #define SYS_fstatfs SYS_fstatfs64 | ||
| 164 | #endif | ||
| 165 | |||
| 166 | #if defined(SYS_newfstatat) | ||
| 167 | #undef SYS_fstatat | ||
| 168 | #define SYS_fstatat SYS_newfstatat | ||
| 169 | #elif defined(SYS_fstatat64) | ||
| 170 | #undef SYS_fstatat | ||
| 171 | #define SYS_fstatat SYS_fstatat64 | ||
| 172 | #endif | ||
| 173 | |||
| 174 | #ifdef SYS_ugetrlimit | ||
| 175 | #undef SYS_getrlimit | ||
| 176 | #define SYS_getrlimit SYS_ugetrlimit | ||
| 177 | #endif | ||
| 178 | |||
| 179 | #ifdef SYS__newselect | ||
| 180 | #undef SYS_select | ||
| 181 | #define SYS_select SYS__newselect | ||
| 182 | #endif | ||
| 183 | |||
| 184 | #ifdef SYS_pread64 | ||
| 185 | #undef SYS_pread | ||
| 186 | #undef SYS_pwrite | ||
| 187 | #define SYS_pread SYS_pread64 | ||
| 188 | #define SYS_pwrite SYS_pwrite64 | ||
| 189 | #endif | ||
| 190 | |||
| 191 | #ifdef SYS_fadvise64_64 | ||
| 192 | #undef SYS_fadvise | ||
| 193 | #define SYS_fadvise SYS_fadvise64_64 | ||
| 194 | #elif defined(SYS_fadvise64) | ||
| 195 | #undef SYS_fadvise | ||
| 196 | #define SYS_fadvise SYS_fadvise64 | ||
| 197 | #endif | ||
| 198 | |||
| 199 | #ifdef SYS_sendfile64 | ||
| 200 | #undef SYS_sendfile | ||
| 201 | #define SYS_sendfile SYS_sendfile64 | ||
| 202 | #endif | ||
| 203 | |||
| 204 | #ifndef SYS_timer_settime | ||
| 205 | #define SYS_timer_settime SYS_timer_settime32 | ||
| 206 | #endif | ||
| 207 | |||
| 208 | #ifndef SYS_timer_gettime | ||
| 209 | #define SYS_timer_gettime SYS_timer_gettime32 | ||
| 210 | #endif | ||
| 211 | |||
| 212 | #ifndef SYS_timerfd_settime | ||
| 213 | #define SYS_timerfd_settime SYS_timerfd_settime32 | ||
| 214 | #endif | ||
| 215 | |||
| 216 | #ifndef SYS_timerfd_gettime | ||
| 217 | #define SYS_timerfd_gettime SYS_timerfd_gettime32 | ||
| 218 | #endif | ||
| 219 | |||
| 220 | #ifndef SYS_clock_settime | ||
| 221 | #define SYS_clock_settime SYS_clock_settime32 | ||
| 222 | #endif | ||
| 223 | |||
| 224 | #ifndef SYS_clock_gettime | ||
| 225 | #define SYS_clock_gettime SYS_clock_gettime32 | ||
| 226 | #endif | ||
| 227 | |||
| 228 | #ifndef SYS_clock_getres | ||
| 229 | #define SYS_clock_getres SYS_clock_getres_time32 | ||
| 230 | #endif | ||
| 231 | |||
| 232 | #ifndef SYS_clock_nanosleep | ||
| 233 | #define SYS_clock_nanosleep SYS_clock_nanosleep_time32 | ||
| 234 | #endif | ||
| 235 | |||
| 236 | #ifndef SYS_gettimeofday | ||
| 237 | #define SYS_gettimeofday SYS_gettimeofday_time32 | ||
| 238 | #endif | ||
| 239 | |||
| 240 | #ifndef SYS_settimeofday | ||
| 241 | #define SYS_settimeofday SYS_settimeofday_time32 | ||
| 242 | #endif | ||
| 243 | |||
| 244 | /* Ensure that the plain syscall names are defined even for "time64-only" | ||
| 245 | * archs. These facilitate callers passing null time arguments, and make | ||
| 246 | * tests for establishing which to use/fallback-to more consistent when | ||
| 247 | * they do need to be called with time arguments. */ | ||
| 248 | |||
| 249 | #ifndef SYS_clock_gettime | ||
| 250 | #define SYS_clock_gettime SYS_clock_gettime64 | ||
| 251 | #endif | ||
| 252 | |||
| 253 | #ifndef SYS_clock_settime | ||
| 254 | #define SYS_clock_settime SYS_clock_settime64 | ||
| 255 | #endif | ||
| 256 | |||
| 257 | #ifndef SYS_clock_adjtime | ||
| 258 | #define SYS_clock_adjtime SYS_clock_adjtime64 | ||
| 259 | #endif | ||
| 260 | |||
| 261 | #ifndef SYS_clock_getres | ||
| 262 | #define SYS_clock_getres SYS_clock_getres_time64 | ||
| 263 | #endif | ||
| 264 | |||
| 265 | #ifndef SYS_clock_nanosleep | ||
| 266 | #define SYS_clock_nanosleep SYS_clock_nanosleep_time64 | ||
| 267 | #endif | ||
| 268 | |||
| 269 | #ifndef SYS_timer_gettime | ||
| 270 | #define SYS_timer_gettime SYS_timer_gettime64 | ||
| 271 | #endif | ||
| 272 | |||
| 273 | #ifndef SYS_timer_settime | ||
| 274 | #define SYS_timer_settime SYS_timer_settime64 | ||
| 275 | #endif | ||
| 276 | |||
| 277 | #ifndef SYS_timerfd_gettime | ||
| 278 | #define SYS_timerfd_gettime SYS_timerfd_gettime64 | ||
| 279 | #endif | ||
| 280 | |||
| 281 | #ifndef SYS_timerfd_settime | ||
| 282 | #define SYS_timerfd_settime SYS_timerfd_settime64 | ||
| 283 | #endif | ||
| 284 | |||
| 285 | #ifndef SYS_utimensat | ||
| 286 | #define SYS_utimensat SYS_utimensat_time64 | ||
| 287 | #endif | ||
| 288 | |||
| 289 | #ifndef SYS_pselect6 | ||
| 290 | #define SYS_pselect6 SYS_pselect6_time64 | ||
| 291 | #endif | ||
| 292 | |||
| 293 | #ifndef SYS_ppoll | ||
| 294 | #define SYS_ppoll SYS_ppoll_time64 | ||
| 295 | #endif | ||
| 296 | |||
| 297 | #ifndef SYS_recvmmsg | ||
| 298 | #define SYS_recvmmsg SYS_recvmmsg_time64 | ||
| 299 | #endif | ||
| 300 | |||
| 301 | #ifndef SYS_mq_timedsend | ||
| 302 | #define SYS_mq_timedsend SYS_mq_timedsend_time64 | ||
| 303 | #endif | ||
| 304 | |||
| 305 | #ifndef SYS_mq_timedreceive | ||
| 306 | #define SYS_mq_timedreceive SYS_mq_timedreceive_time64 | ||
| 307 | #endif | ||
| 308 | |||
| 309 | /* SYS_semtimedop omitted because SYS_ipc may provide it */ | ||
| 310 | |||
| 311 | #ifndef SYS_rt_sigtimedwait | ||
| 312 | #define SYS_rt_sigtimedwait SYS_rt_sigtimedwait_time64 | ||
| 313 | #endif | ||
| 314 | |||
| 315 | #ifndef SYS_futex | ||
| 316 | #define SYS_futex SYS_futex_time64 | ||
| 317 | #endif | ||
| 318 | |||
| 319 | #ifndef SYS_sched_rr_get_interval | ||
| 320 | #define SYS_sched_rr_get_interval SYS_sched_rr_get_interval_time64 | ||
| 321 | #endif | ||
| 322 | |||
| 323 | |||
| 324 | |||
| 325 | |||
| 326 | /* socketcall calls */ | ||
| 327 | |||
| 328 | #define __SC_socket 1 | ||
| 329 | #define __SC_bind 2 | ||
| 330 | #define __SC_connect 3 | ||
| 331 | #define __SC_listen 4 | ||
| 332 | #define __SC_accept 5 | ||
| 333 | #define __SC_getsockname 6 | ||
| 334 | #define __SC_getpeername 7 | ||
| 335 | #define __SC_socketpair 8 | ||
| 336 | #define __SC_send 9 | ||
| 337 | #define __SC_recv 10 | ||
| 338 | #define __SC_sendto 11 | ||
| 339 | #define __SC_recvfrom 12 | ||
| 340 | #define __SC_shutdown 13 | ||
| 341 | #define __SC_setsockopt 14 | ||
| 342 | #define __SC_getsockopt 15 | ||
| 343 | #define __SC_sendmsg 16 | ||
| 344 | #define __SC_recvmsg 17 | ||
| 345 | #define __SC_accept4 18 | ||
| 346 | #define __SC_recvmmsg 19 | ||
| 347 | #define __SC_sendmmsg 20 | ||
| 348 | |||
| 349 | /* This is valid only because all socket syscalls are made via | ||
| 350 | * socketcall, which always fills unused argument slots with zeros. */ | ||
| 351 | #ifndef SYS_accept | ||
| 352 | #define SYS_accept SYS_accept4 | ||
| 353 | #endif | ||
| 354 | |||
| 355 | #ifndef SO_RCVTIMEO_OLD | ||
| 356 | #define SO_RCVTIMEO_OLD 20 | ||
| 357 | #endif | ||
| 358 | #ifndef SO_SNDTIMEO_OLD | ||
| 359 | #define SO_SNDTIMEO_OLD 21 | ||
| 360 | #endif | ||
| 361 | |||
| 362 | #define SO_TIMESTAMP_OLD 29 | ||
| 363 | #define SO_TIMESTAMPNS_OLD 35 | ||
| 364 | #define SO_TIMESTAMPING_OLD 37 | ||
| 365 | #define SCM_TIMESTAMP_OLD SO_TIMESTAMP_OLD | ||
| 366 | #define SCM_TIMESTAMPNS_OLD SO_TIMESTAMPNS_OLD | ||
| 367 | #define SCM_TIMESTAMPING_OLD SO_TIMESTAMPING_OLD | ||
| 368 | |||
| 369 | #ifndef SIOCGSTAMP_OLD | ||
| 370 | #define SIOCGSTAMP_OLD 0x8906 | ||
| 371 | #endif | ||
| 372 | #ifndef SIOCGSTAMPNS_OLD | ||
| 373 | #define SIOCGSTAMPNS_OLD 0x8907 | ||
| 374 | #endif | ||
| 375 | |||
| 376 | #ifdef SYS_open | ||
| 377 | #define __sys_open2(x,pn,fl) __syscall2(SYS_open, pn, (fl)|O_LARGEFILE) | ||
| 378 | #define __sys_open3(x,pn,fl,mo) __syscall3(SYS_open, pn, (fl)|O_LARGEFILE, mo) | ||
| 379 | #define __sys_open_cp2(x,pn,fl) __syscall_cp2(SYS_open, pn, (fl)|O_LARGEFILE) | ||
| 380 | #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp3(SYS_open, pn, (fl)|O_LARGEFILE, mo) | ||
| 381 | #else | ||
| 382 | #define __sys_open2(x,pn,fl) __syscall3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) | ||
| 383 | #define __sys_open3(x,pn,fl,mo) __syscall4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) | ||
| 384 | #define __sys_open_cp2(x,pn,fl) __syscall_cp3(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE) | ||
| 385 | #define __sys_open_cp3(x,pn,fl,mo) __syscall_cp4(SYS_openat, AT_FDCWD, pn, (fl)|O_LARGEFILE, mo) | ||
| 386 | #endif | ||
| 387 | |||
| 388 | #define __sys_open(...) __SYSCALL_DISP(__sys_open,,__VA_ARGS__) | ||
| 389 | #define sys_open(...) __syscall_ret(__sys_open(__VA_ARGS__)) | ||
| 390 | |||
| 391 | #define __sys_open_cp(...) __SYSCALL_DISP(__sys_open_cp,,__VA_ARGS__) | ||
| 392 | #define sys_open_cp(...) __syscall_ret(__sys_open_cp(__VA_ARGS__)) | ||
| 393 | |||
| 394 | hidden void __procfdname(char __buf[static 15+3*sizeof(int)], unsigned); | ||
| 395 | |||
| 396 | hidden void *__vdsosym(const char *, const char *); | ||
| 397 | |||
| 398 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/syscall_ret.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | long __syscall_ret(unsigned long r) | ||
| 5 | { | ||
| 6 | 	if (r > -4096UL) { | ||
| 7 | 		errno = -r; | ||
| 8 | 		return -1; | ||
| 9 | 	} | ||
| 10 | 	return r; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/internal/vdso.c created+93| ... | @@ -0,0 +1,93 @@ | ||
| 1 | #include <elf.h> | ||
| 2 | #include <link.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include "libc.h" | ||
| 7 | #include "syscall.h" | ||
| 8 | |||
| 9 | #ifdef VDSO_USEFUL | ||
| 10 | |||
| 11 | #if ULONG_MAX == 0xffffffff | ||
| 12 | typedef Elf32_Ehdr Ehdr; | ||
| 13 | typedef Elf32_Phdr Phdr; | ||
| 14 | typedef Elf32_Sym Sym; | ||
| 15 | typedef Elf32_Verdef Verdef; | ||
| 16 | typedef Elf32_Verdaux Verdaux; | ||
| 17 | #else | ||
| 18 | typedef Elf64_Ehdr Ehdr; | ||
| 19 | typedef Elf64_Phdr Phdr; | ||
| 20 | typedef Elf64_Sym Sym; | ||
| 21 | typedef Elf64_Verdef Verdef; | ||
| 22 | typedef Elf64_Verdaux Verdaux; | ||
| 23 | #endif | ||
| 24 | |||
| 25 | static int checkver(Verdef *def, int vsym, const char *vername, char *strings) | ||
| 26 | { | ||
| 27 | 	vsym &= 0x7fff; | ||
| 28 | 	for (;;) { | ||
| 29 | 		if (!(def->vd_flags & VER_FLG_BASE) | ||
| 30 | 		 && (def->vd_ndx & 0x7fff) == vsym) | ||
| 31 | 			break; | ||
| 32 | 		if (def->vd_next == 0) | ||
| 33 | 			return 0; | ||
| 34 | 		def = (Verdef *)((char *)def + def->vd_next); | ||
| 35 | 	} | ||
| 36 | 	Verdaux *aux = (Verdaux *)((char *)def + def->vd_aux); | ||
| 37 | 	return !strcmp(vername, strings + aux->vda_name); | ||
| 38 | } | ||
| 39 | |||
| 40 | #define OK_TYPES (1<<STT_NOTYPE | 1<<STT_OBJECT | 1<<STT_FUNC | 1<<STT_COMMON) | ||
| 41 | #define OK_BINDS (1<<STB_GLOBAL | 1<<STB_WEAK | 1<<STB_GNU_UNIQUE) | ||
| 42 | |||
| 43 | void *__vdsosym(const char *vername, const char *name) | ||
| 44 | { | ||
| 45 | 	size_t i; | ||
| 46 | 	for (i=0; libc.auxv[i] != AT_SYSINFO_EHDR; i+=2) | ||
| 47 | 		if (!libc.auxv[i]) return 0; | ||
| 48 | 	if (!libc.auxv[i+1]) return 0; | ||
| 49 | 	Ehdr *eh = (void *)libc.auxv[i+1]; | ||
| 50 | 	Phdr *ph = (void *)((char *)eh + eh->e_phoff); | ||
| 51 | 	size_t *dynv=0, base=-1; | ||
| 52 | 	for (i=0; i<eh->e_phnum; i++, ph=(void *)((char *)ph+eh->e_phentsize)) { | ||
| 53 | 		if (ph->p_type == PT_LOAD) | ||
| 54 | 			base = (size_t)eh + ph->p_offset - ph->p_vaddr; | ||
| 55 | 		else if (ph->p_type == PT_DYNAMIC) | ||
| 56 | 			dynv = (void *)((char *)eh + ph->p_offset); | ||
| 57 | 	} | ||
| 58 | 	if (!dynv || base==(size_t)-1) return 0; | ||
| 59 | |||
| 60 | 	char *strings = 0; | ||
| 61 | 	Sym *syms = 0; | ||
| 62 | 	Elf_Symndx *hashtab = 0; | ||
| 63 | 	uint16_t *versym = 0; | ||
| 64 | 	Verdef *verdef = 0; | ||
| 65 | 	 | ||
| 66 | 	for (i=0; dynv[i]; i+=2) { | ||
| 67 | 		void *p = (void *)(base + dynv[i+1]); | ||
| 68 | 		switch(dynv[i]) { | ||
| 69 | 		case DT_STRTAB: strings = p; break; | ||
| 70 | 		case DT_SYMTAB: syms = p; break; | ||
| 71 | 		case DT_HASH: hashtab = p; break; | ||
| 72 | 		case DT_VERSYM: versym = p; break; | ||
| 73 | 		case DT_VERDEF: verdef = p; break; | ||
| 74 | 		} | ||
| 75 | 	}	 | ||
| 76 | |||
| 77 | 	if (!strings || !syms || !hashtab) return 0; | ||
| 78 | 	if (!verdef) versym = 0; | ||
| 79 | |||
| 80 | 	for (i=0; i<hashtab[1]; i++) { | ||
| 81 | 		if (!(1<<(syms[i].st_info&0xf) & OK_TYPES)) continue; | ||
| 82 | 		if (!(1<<(syms[i].st_info>>4) & OK_BINDS)) continue; | ||
| 83 | 		if (!syms[i].st_shndx) continue; | ||
| 84 | 		if (strcmp(name, strings+syms[i].st_name)) continue; | ||
| 85 | 		if (versym && !checkver(verdef, versym[i], vername, strings)) | ||
| 86 | 			continue; | ||
| 87 | 		return (void *)(base + syms[i].st_value); | ||
| 88 | 	} | ||
| 89 | |||
| 90 | 	return 0; | ||
| 91 | } | ||
| 92 | |||
| 93 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/internal/version.c created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | #include "version.h" | ||
| 2 | #include "libc.h" | ||
| 3 | |||
| 4 | const char __libc_version[] = VERSION; | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/ftok.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <sys/ipc.h> | ||
| 2 | #include <sys/stat.h> | ||
| 3 | |||
| 4 | key_t ftok(const char *path, int id) | ||
| 5 | { | ||
| 6 | 	struct stat st; | ||
| 7 | 	if (stat(path, &st) < 0) return -1; | ||
| 8 | |||
| 9 | 	return ((st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | ((id & 0xffu) << 24)); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/ipc.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | #define IPCOP_semop 1 | ||
| 4 | #define IPCOP_semget 2 | ||
| 5 | #define IPCOP_semctl 3 | ||
| 6 | #define IPCOP_semtimedop 4 | ||
| 7 | #define IPCOP_msgsnd 11 | ||
| 8 | #define IPCOP_msgrcv 12 | ||
| 9 | #define IPCOP_msgget 13 | ||
| 10 | #define IPCOP_msgctl 14 | ||
| 11 | #define IPCOP_shmat 21 | ||
| 12 | #define IPCOP_shmdt 22 | ||
| 13 | #define IPCOP_shmget 23 | ||
| 14 | #define IPCOP_shmctl 24 | ||
| 15 | |||
| 16 | #ifndef IPC_64 | ||
| 17 | #define IPC_64 0x100 | ||
| 18 | #endif | ||
| 19 | |||
| 20 | #define IPC_TIME64 (IPC_STAT & 0x100) | ||
| 21 | |||
| 22 | #define IPC_CMD(cmd) (((cmd) & ~IPC_TIME64) | IPC_64) | ||
| 23 | |||
| 24 | #define IPC_HILO(b,t) ((b)->t = (b)->__##t##_lo | 0LL+(b)->__##t##_hi<<32) | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/msgctl.c created+51| ... | @@ -0,0 +1,51 @@ | ||
| 1 | #include <sys/msg.h> | ||
| 2 | #include <endian.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "ipc.h" | ||
| 5 | |||
| 6 | #if __BYTE_ORDER != __BIG_ENDIAN | ||
| 7 | #undef SYSCALL_IPC_BROKEN_MODE | ||
| 8 | #endif | ||
| 9 | |||
| 10 | int msgctl(int q, int cmd, struct msqid_ds *buf) | ||
| 11 | { | ||
| 12 | #if IPC_TIME64 | ||
| 13 | 	struct msqid_ds out, *orig; | ||
| 14 | 	if (cmd&IPC_TIME64) { | ||
| 15 | 		out = (struct msqid_ds){0}; | ||
| 16 | 		orig = buf; | ||
| 17 | 		buf = &out; | ||
| 18 | 	} | ||
| 19 | #endif | ||
| 20 | #ifdef SYSCALL_IPC_BROKEN_MODE | ||
| 21 | 	struct msqid_ds tmp; | ||
| 22 | 	if (cmd == IPC_SET) { | ||
| 23 | 		tmp = *buf; | ||
| 24 | 		tmp.msg_perm.mode *= 0x10000U; | ||
| 25 | 		buf = &tmp; | ||
| 26 | 	} | ||
| 27 | #endif | ||
| 28 | #ifndef SYS_ipc | ||
| 29 | 	int r = __syscall(SYS_msgctl, q, IPC_CMD(cmd), buf); | ||
| 30 | #else | ||
| 31 | 	int r = __syscall(SYS_ipc, IPCOP_msgctl, q, IPC_CMD(cmd), 0, buf, 0); | ||
| 32 | #endif | ||
| 33 | #ifdef SYSCALL_IPC_BROKEN_MODE | ||
| 34 | 	if (r >= 0) switch (cmd | IPC_TIME64) { | ||
| 35 | 	case IPC_STAT: | ||
| 36 | 	case MSG_STAT: | ||
| 37 | 	case MSG_STAT_ANY: | ||
| 38 | 		buf->msg_perm.mode >>= 16; | ||
| 39 | 	} | ||
| 40 | #endif | ||
| 41 | #if IPC_TIME64 | ||
| 42 | 	if (r >= 0 && (cmd&IPC_TIME64)) { | ||
| 43 | 		buf = orig; | ||
| 44 | 		*buf = out; | ||
| 45 | 		IPC_HILO(buf, msg_stime); | ||
| 46 | 		IPC_HILO(buf, msg_rtime); | ||
| 47 | 		IPC_HILO(buf, msg_ctime); | ||
| 48 | 	} | ||
| 49 | #endif | ||
| 50 | 	return __syscall_ret(r); | ||
| 51 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/msgget.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/msg.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "ipc.h" | ||
| 4 | |||
| 5 | int msgget(key_t k, int flag) | ||
| 6 | { | ||
| 7 | #ifndef SYS_ipc | ||
| 8 | 	return syscall(SYS_msgget, k, flag); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_ipc, IPCOP_msgget, k, flag); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/msgrcv.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/msg.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "ipc.h" | ||
| 4 | |||
| 5 | ssize_t msgrcv(int q, void *m, size_t len, long type, int flag) | ||
| 6 | { | ||
| 7 | #ifndef SYS_ipc | ||
| 8 | 	return syscall_cp(SYS_msgrcv, q, m, len, type, flag); | ||
| 9 | #else | ||
| 10 | 	return syscall_cp(SYS_ipc, IPCOP_msgrcv, q, len, flag, ((long[]){ (long)m, type })); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/msgsnd.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/msg.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "ipc.h" | ||
| 4 | |||
| 5 | int msgsnd(int q, const void *m, size_t len, int flag) | ||
| 6 | { | ||
| 7 | #ifndef SYS_ipc | ||
| 8 | 	return syscall_cp(SYS_msgsnd, q, m, len, flag); | ||
| 9 | #else | ||
| 10 | 	return syscall_cp(SYS_ipc, IPCOP_msgsnd, q, len, flag, m); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/semctl.c created+69| ... | @@ -0,0 +1,69 @@ | ||
| 1 | #include <sys/sem.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <endian.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "ipc.h" | ||
| 6 | |||
| 7 | #if __BYTE_ORDER != __BIG_ENDIAN | ||
| 8 | #undef SYSCALL_IPC_BROKEN_MODE | ||
| 9 | #endif | ||
| 10 | |||
| 11 | union semun { | ||
| 12 | 	int val; | ||
| 13 | 	struct semid_ds *buf; | ||
| 14 | 	unsigned short *array; | ||
| 15 | }; | ||
| 16 | |||
| 17 | int semctl(int id, int num, int cmd, ...) | ||
| 18 | { | ||
| 19 | 	union semun arg = {0}; | ||
| 20 | 	va_list ap; | ||
| 21 | 	switch (cmd & ~IPC_TIME64) { | ||
| 22 | 	case SETVAL: case GETALL: case SETALL: case IPC_SET: | ||
| 23 | 	case IPC_INFO: case SEM_INFO: | ||
| 24 | 	case IPC_STAT & ~IPC_TIME64: | ||
| 25 | 	case SEM_STAT & ~IPC_TIME64: | ||
| 26 | 	case SEM_STAT_ANY & ~IPC_TIME64: | ||
| 27 | 		va_start(ap, cmd); | ||
| 28 | 		arg = va_arg(ap, union semun); | ||
| 29 | 		va_end(ap); | ||
| 30 | 	} | ||
| 31 | #if IPC_TIME64 | ||
| 32 | 	struct semid_ds out, *orig; | ||
| 33 | 	if (cmd&IPC_TIME64) { | ||
| 34 | 		out = (struct semid_ds){0}; | ||
| 35 | 		orig = arg.buf; | ||
| 36 | 		arg.buf = &out; | ||
| 37 | 	} | ||
| 38 | #endif | ||
| 39 | #ifdef SYSCALL_IPC_BROKEN_MODE | ||
| 40 | 	struct semid_ds tmp; | ||
| 41 | 	if (cmd == IPC_SET) { | ||
| 42 | 		tmp = *arg.buf; | ||
| 43 | 		tmp.sem_perm.mode *= 0x10000U; | ||
| 44 | 		arg.buf = &tmp; | ||
| 45 | 	} | ||
| 46 | #endif | ||
| 47 | #ifndef SYS_ipc | ||
| 48 | 	int r = __syscall(SYS_semctl, id, num, IPC_CMD(cmd), arg.buf); | ||
| 49 | #else | ||
| 50 | 	int r = __syscall(SYS_ipc, IPCOP_semctl, id, num, IPC_CMD(cmd), &arg.buf); | ||
| 51 | #endif | ||
| 52 | #ifdef SYSCALL_IPC_BROKEN_MODE | ||
| 53 | 	if (r >= 0) switch (cmd | IPC_TIME64) { | ||
| 54 | 	case IPC_STAT: | ||
| 55 | 	case SEM_STAT: | ||
| 56 | 	case SEM_STAT_ANY: | ||
| 57 | 		arg.buf->sem_perm.mode >>= 16; | ||
| 58 | 	} | ||
| 59 | #endif | ||
| 60 | #if IPC_TIME64 | ||
| 61 | 	if (r >= 0 && (cmd&IPC_TIME64)) { | ||
| 62 | 		arg.buf = orig; | ||
| 63 | 		*arg.buf = out; | ||
| 64 | 		IPC_HILO(arg.buf, sem_otime); | ||
| 65 | 		IPC_HILO(arg.buf, sem_ctime); | ||
| 66 | 	} | ||
| 67 | #endif | ||
| 68 | 	return __syscall_ret(r); | ||
| 69 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/semget.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <sys/sem.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "ipc.h" | ||
| 6 | |||
| 7 | int semget(key_t key, int n, int fl) | ||
| 8 | { | ||
| 9 | 	/* The kernel uses the wrong type for the sem_nsems member | ||
| 10 | 	 * of struct semid_ds, and thus might not check that the | ||
| 11 | 	 * n fits in the correct (per POSIX) userspace type, so | ||
| 12 | 	 * we have to check here. */ | ||
| 13 | 	if (n > USHRT_MAX) return __syscall_ret(-EINVAL); | ||
| 14 | #ifndef SYS_ipc | ||
| 15 | 	return syscall(SYS_semget, key, n, fl); | ||
| 16 | #else | ||
| 17 | 	return syscall(SYS_ipc, IPCOP_semget, key, n, fl); | ||
| 18 | #endif | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/semop.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/sem.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "ipc.h" | ||
| 4 | |||
| 5 | int semop(int id, struct sembuf *buf, size_t n) | ||
| 6 | { | ||
| 7 | #ifndef SYS_ipc | ||
| 8 | 	return syscall(SYS_semop, id, buf, n); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_ipc, IPCOP_semop, id, n, 0, buf); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/semtimedop.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/sem.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "ipc.h" | ||
| 6 | |||
| 7 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 8 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 9 | |||
| 10 | #if !defined(SYS_semtimedop) && !defined(SYS_ipc) | ||
| 11 | #define NO_TIME32 1 | ||
| 12 | #else | ||
| 13 | #define NO_TIME32 0 | ||
| 14 | #endif | ||
| 15 | |||
| 16 | int semtimedop(int id, struct sembuf *buf, size_t n, const struct timespec *ts) | ||
| 17 | { | ||
| 18 | #ifdef SYS_semtimedop_time64 | ||
| 19 | 	time_t s = ts ? ts->tv_sec : 0; | ||
| 20 | 	long ns = ts ? ts->tv_nsec : 0; | ||
| 21 | 	int r = -ENOSYS; | ||
| 22 | 	if (NO_TIME32 || !IS32BIT(s)) | ||
| 23 | 		r = __syscall(SYS_semtimedop_time64, id, buf, n, | ||
| 24 | 			ts ? ((long long[]){s, ns}) : 0); | ||
| 25 | 	if (NO_TIME32 || r!=-ENOSYS) return __syscall_ret(r); | ||
| 26 | 	ts = ts ? (void *)(long[]){CLAMP(s), ns} : 0; | ||
| 27 | #endif | ||
| 28 | #if defined(SYS_ipc) | ||
| 29 | 	return syscall(SYS_ipc, IPCOP_semtimedop, id, n, 0, buf, ts); | ||
| 30 | #elif defined(SYS_semtimedop) | ||
| 31 | 	return syscall(SYS_semtimedop, id, buf, n, ts); | ||
| 32 | #else | ||
| 33 | 	return __syscall_ret(-ENOSYS); | ||
| 34 | #endif | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/shmat.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <sys/shm.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "ipc.h" | ||
| 4 | |||
| 5 | #ifndef SYS_ipc | ||
| 6 | void *shmat(int id, const void *addr, int flag) | ||
| 7 | { | ||
| 8 | 	return (void *)syscall(SYS_shmat, id, addr, flag); | ||
| 9 | } | ||
| 10 | #else | ||
| 11 | void *shmat(int id, const void *addr, int flag) | ||
| 12 | { | ||
| 13 | 	unsigned long ret; | ||
| 14 | 	ret = syscall(SYS_ipc, IPCOP_shmat, id, flag, &addr, addr); | ||
| 15 | 	return (ret > -(unsigned long)SHMLBA) ? (void *)ret : (void *)addr; | ||
| 16 | } | ||
| 17 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/shmctl.c created+51| ... | @@ -0,0 +1,51 @@ | ||
| 1 | #include <sys/shm.h> | ||
| 2 | #include <endian.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "ipc.h" | ||
| 5 | |||
| 6 | #if __BYTE_ORDER != __BIG_ENDIAN | ||
| 7 | #undef SYSCALL_IPC_BROKEN_MODE | ||
| 8 | #endif | ||
| 9 | |||
| 10 | int shmctl(int id, int cmd, struct shmid_ds *buf) | ||
| 11 | { | ||
| 12 | #if IPC_TIME64 | ||
| 13 | 	struct shmid_ds out, *orig; | ||
| 14 | 	if (cmd&IPC_TIME64) { | ||
| 15 | 		out = (struct shmid_ds){0}; | ||
| 16 | 		orig = buf; | ||
| 17 | 		buf = &out; | ||
| 18 | 	} | ||
| 19 | #endif | ||
| 20 | #ifdef SYSCALL_IPC_BROKEN_MODE | ||
| 21 | 	struct shmid_ds tmp; | ||
| 22 | 	if (cmd == IPC_SET) { | ||
| 23 | 		tmp = *buf; | ||
| 24 | 		tmp.shm_perm.mode *= 0x10000U; | ||
| 25 | 		buf = &tmp; | ||
| 26 | 	} | ||
| 27 | #endif | ||
| 28 | #ifndef SYS_ipc | ||
| 29 | 	int r = __syscall(SYS_shmctl, id, IPC_CMD(cmd), buf); | ||
| 30 | #else | ||
| 31 | 	int r = __syscall(SYS_ipc, IPCOP_shmctl, id, IPC_CMD(cmd), 0, buf, 0); | ||
| 32 | #endif | ||
| 33 | #ifdef SYSCALL_IPC_BROKEN_MODE | ||
| 34 | 	if (r >= 0) switch (cmd | IPC_TIME64) { | ||
| 35 | 	case IPC_STAT: | ||
| 36 | 	case SHM_STAT: | ||
| 37 | 	case SHM_STAT_ANY: | ||
| 38 | 		buf->shm_perm.mode >>= 16; | ||
| 39 | 	} | ||
| 40 | #endif | ||
| 41 | #if IPC_TIME64 | ||
| 42 | 	if (r >= 0 && (cmd&IPC_TIME64)) { | ||
| 43 | 		buf = orig; | ||
| 44 | 		*buf = out; | ||
| 45 | 		IPC_HILO(buf, shm_atime); | ||
| 46 | 		IPC_HILO(buf, shm_dtime); | ||
| 47 | 		IPC_HILO(buf, shm_ctime); | ||
| 48 | 	} | ||
| 49 | #endif | ||
| 50 | 	return __syscall_ret(r); | ||
| 51 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/shmdt.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/shm.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "ipc.h" | ||
| 4 | |||
| 5 | int shmdt(const void *addr) | ||
| 6 | { | ||
| 7 | #ifndef SYS_ipc | ||
| 8 | 	return syscall(SYS_shmdt, addr); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_ipc, IPCOP_shmdt, 0, 0, 0, addr); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ipc/shmget.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <sys/shm.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "ipc.h" | ||
| 5 | |||
| 6 | int shmget(key_t key, size_t size, int flag) | ||
| 7 | { | ||
| 8 | 	if (size > PTRDIFF_MAX) size = SIZE_MAX; | ||
| 9 | #ifndef SYS_ipc | ||
| 10 | 	return syscall(SYS_shmget, key, size, flag); | ||
| 11 | #else | ||
| 12 | 	return syscall(SYS_ipc, IPCOP_shmget, key, size, flag); | ||
| 13 | #endif | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/__dlsym.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <dlfcn.h> | ||
| 2 | #include "dynlink.h" | ||
| 3 | |||
| 4 | static void *stub_dlsym(void *restrict p, const char *restrict s, void *restrict ra) | ||
| 5 | { | ||
| 6 | 	__dl_seterr("Symbol not found: %s", s); | ||
| 7 | 	return 0; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(stub_dlsym, __dlsym); | ||
| 11 | |||
| 12 | #if _REDIR_TIME64 | ||
| 13 | weak_alias(stub_dlsym, __dlsym_redir_time64); | ||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/aarch64/dlsym.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global dlsym | ||
| 2 | .hidden __dlsym | ||
| 3 | .type dlsym,%function | ||
| 4 | dlsym: | ||
| 5 | 	mov x2,x30 | ||
| 6 | 	b __dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/aarch64/tlsdesc.s created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | // size_t __tlsdesc_static(size_t *a) | ||
| 2 | // { | ||
| 3 | // 	return a[1]; | ||
| 4 | // } | ||
| 5 | .global __tlsdesc_static | ||
| 6 | .hidden __tlsdesc_static | ||
| 7 | .type __tlsdesc_static,@function | ||
| 8 | __tlsdesc_static: | ||
| 9 | 	ldr x0,[x0,#8] | ||
| 10 | 	ret | ||
| 11 | |||
| 12 | // size_t __tlsdesc_dynamic(size_t *a) | ||
| 13 | // { | ||
| 14 | // 	struct {size_t modidx,off;} *p = (void*)a[1]; | ||
| 15 | // 	size_t *dtv = *(size_t**)(tp - 8); | ||
| 16 | // 	return dtv[p->modidx] + p->off - tp; | ||
| 17 | // } | ||
| 18 | .global __tlsdesc_dynamic | ||
| 19 | .hidden __tlsdesc_dynamic | ||
| 20 | .type __tlsdesc_dynamic,@function | ||
| 21 | __tlsdesc_dynamic: | ||
| 22 | 	stp x1,x2,[sp,#-16]! | ||
| 23 | 	mrs x1,tpidr_el0 // tp | ||
| 24 | 	ldr x0,[x0,#8] // p | ||
| 25 | 	ldp x0,x2,[x0] // p->modidx, p->off | ||
| 26 | 	sub x2,x2,x1 // p->off - tp | ||
| 27 | 	ldr x1,[x1,#-8] // dtv | ||
| 28 | 	ldr x1,[x1,x0,lsl #3] // dtv[p->modidx] | ||
| 29 | 	add x0,x1,x2 // dtv[p->modidx] + p->off - tp | ||
| 30 | 	ldp x1,x2,[sp],#16 | ||
| 31 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/dlsym.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | .syntax unified | ||
| 2 | .text | ||
| 3 | .global dlsym | ||
| 4 | .hidden __dlsym | ||
| 5 | .type dlsym,%function | ||
| 6 | dlsym: | ||
| 7 | 	mov r2,lr | ||
| 8 | 	b __dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/find_exidx.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <link.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | struct find_exidx_data { | ||
| 6 | 	uintptr_t pc, exidx_start; | ||
| 7 | 	int exidx_len; | ||
| 8 | }; | ||
| 9 | |||
| 10 | static int find_exidx(struct dl_phdr_info *info, size_t size, void *ptr) | ||
| 11 | { | ||
| 12 | 	struct find_exidx_data *data = ptr; | ||
| 13 | 	const ElfW(Phdr) *phdr = info->dlpi_phdr; | ||
| 14 | 	uintptr_t addr, exidx_start = 0; | ||
| 15 | 	int i, match = 0, exidx_len = 0; | ||
| 16 | |||
| 17 | 	for (i = info->dlpi_phnum; i > 0; i--, phdr++) { | ||
| 18 | 		addr = info->dlpi_addr + phdr->p_vaddr; | ||
| 19 | 		switch (phdr->p_type) { | ||
| 20 | 		case PT_LOAD: | ||
| 21 | 			match |= data->pc >= addr && data->pc < addr + phdr->p_memsz; | ||
| 22 | 			break; | ||
| 23 | 		case PT_ARM_EXIDX: | ||
| 24 | 			exidx_start = addr; | ||
| 25 | 			exidx_len = phdr->p_memsz; | ||
| 26 | 			break; | ||
| 27 | 		} | ||
| 28 | 	} | ||
| 29 | 	data->exidx_start = exidx_start; | ||
| 30 | 	data->exidx_len = exidx_len; | ||
| 31 | 	return match; | ||
| 32 | } | ||
| 33 | |||
| 34 | uintptr_t __gnu_Unwind_Find_exidx(uintptr_t pc, int *pcount) | ||
| 35 | { | ||
| 36 | 	struct find_exidx_data data; | ||
| 37 | 	data.pc = pc; | ||
| 38 | 	if (dl_iterate_phdr(find_exidx, &data) <= 0) | ||
| 39 | 		return 0; | ||
| 40 | 	*pcount = data.exidx_len / 8; | ||
| 41 | 	return data.exidx_start; | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/arm/tlsdesc.S created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | .syntax unified | ||
| 2 | |||
| 3 | .text | ||
| 4 | .global __tlsdesc_static | ||
| 5 | .hidden __tlsdesc_static | ||
| 6 | .type __tlsdesc_static,%function | ||
| 7 | __tlsdesc_static: | ||
| 8 | 	ldr r0,[r0] | ||
| 9 | 	bx lr | ||
| 10 | |||
| 11 | .global __tlsdesc_dynamic | ||
| 12 | .hidden __tlsdesc_dynamic | ||
| 13 | .type __tlsdesc_dynamic,%function | ||
| 14 | __tlsdesc_dynamic: | ||
| 15 | 	push {r2,r3,ip,lr} | ||
| 16 | 	ldr r1,[r0] | ||
| 17 | 	ldr r2,[r1,#4] // r2 = offset | ||
| 18 | 	ldr r1,[r1] // r1 = modid | ||
| 19 | |||
| 20 | #if ((__ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ | ||
| 21 | || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 | ||
| 22 | 	mrc p15,0,r0,c13,c0,3 | ||
| 23 | #else | ||
| 24 | 	ldr r0,1f | ||
| 25 | 	add r0,r0,pc | ||
| 26 | 	ldr r0,[r0] | ||
| 27 | 2: | ||
| 28 | #if __ARM_ARCH >= 5 | ||
| 29 | 	blx r0 // r0 = tp | ||
| 30 | #else | ||
| 31 | #if __thumb__ | ||
| 32 | 	add lr,pc,#1 | ||
| 33 | #else | ||
| 34 | 	mov lr,pc | ||
| 35 | #endif | ||
| 36 | 	bx r0 | ||
| 37 | #endif | ||
| 38 | #endif | ||
| 39 | 	ldr r3,[r0,#-4] // r3 = dtv | ||
| 40 | 	ldr ip,[r3,r1,LSL #2] | ||
| 41 | 	sub r0,ip,r0 | ||
| 42 | 	add r0,r0,r2 // r0 = r3[r1]-r0+r2 | ||
| 43 | #if __ARM_ARCH >= 5 | ||
| 44 | 	pop {r2,r3,ip,pc} | ||
| 45 | #else | ||
| 46 | 	pop {r2,r3,ip,lr} | ||
| 47 | 	bx lr | ||
| 48 | #endif | ||
| 49 | |||
| 50 | #if ((__ARM_ARCH_6K__ || __ARM_ARCH_6KZ__ || __ARM_ARCH_6ZK__) && !__thumb__) \ | ||
| 51 | || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7 | ||
| 52 | #else | ||
| 53 | 	.align 2 | ||
| 54 | 1:	.word __a_gettp_ptr - 2b | ||
| 55 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dl_iterate_phdr.c created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #include <elf.h> | ||
| 2 | #include <link.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | #define AUX_CNT 38 | ||
| 6 | |||
| 7 | extern weak hidden const size_t _DYNAMIC[]; | ||
| 8 | |||
| 9 | static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size_t size, void *data), void *data) | ||
| 10 | { | ||
| 11 | 	unsigned char *p; | ||
| 12 | 	ElfW(Phdr) *phdr, *tls_phdr=0; | ||
| 13 | 	size_t base = 0; | ||
| 14 | 	size_t n; | ||
| 15 | 	struct dl_phdr_info info; | ||
| 16 | 	size_t i, aux[AUX_CNT] = {0}; | ||
| 17 | |||
| 18 | 	for (i=0; libc.auxv[i]; i+=2) | ||
| 19 | 		if (libc.auxv[i]<AUX_CNT) aux[libc.auxv[i]] = libc.auxv[i+1]; | ||
| 20 | |||
| 21 | 	for (p=(void *)aux[AT_PHDR],n=aux[AT_PHNUM]; n; n--,p+=aux[AT_PHENT]) { | ||
| 22 | 		phdr = (void *)p; | ||
| 23 | 		if (phdr->p_type == PT_PHDR) | ||
| 24 | 			base = aux[AT_PHDR] - phdr->p_vaddr; | ||
| 25 | 		if (phdr->p_type == PT_DYNAMIC && _DYNAMIC) | ||
| 26 | 			base = (size_t)_DYNAMIC - phdr->p_vaddr; | ||
| 27 | 		if (phdr->p_type == PT_TLS) | ||
| 28 | 			tls_phdr = phdr; | ||
| 29 | 	} | ||
| 30 | 	info.dlpi_addr = base; | ||
| 31 | 	info.dlpi_name = "/proc/self/exe"; | ||
| 32 | 	info.dlpi_phdr = (void *)aux[AT_PHDR]; | ||
| 33 | 	info.dlpi_phnum = aux[AT_PHNUM]; | ||
| 34 | 	info.dlpi_adds = 0; | ||
| 35 | 	info.dlpi_subs = 0; | ||
| 36 | 	if (tls_phdr) { | ||
| 37 | 		info.dlpi_tls_modid = 1; | ||
| 38 | 		info.dlpi_tls_data = (void *)(base + tls_phdr->p_vaddr); | ||
| 39 | 	} else { | ||
| 40 | 		info.dlpi_tls_modid = 0; | ||
| 41 | 		info.dlpi_tls_data = 0; | ||
| 42 | 	} | ||
| 43 | 	return (callback)(&info, sizeof (info), data); | ||
| 44 | } | ||
| 45 | |||
| 46 | weak_alias(static_dl_iterate_phdr, dl_iterate_phdr); | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dladdr.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <dlfcn.h> | ||
| 3 | |||
| 4 | static int stub_dladdr(const void *addr, Dl_info *info) | ||
| 5 | { | ||
| 6 | 	return 0; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(stub_dladdr, dladdr); | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dlclose.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <dlfcn.h> | ||
| 2 | #include "dynlink.h" | ||
| 3 | |||
| 4 | int dlclose(void *p) | ||
| 5 | { | ||
| 6 | 	return __dl_invalid_handle(p); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dlerror.c created+87| ... | @@ -0,0 +1,87 @@ | ||
| 1 | #include <dlfcn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | #include "dynlink.h" | ||
| 6 | #include "lock.h" | ||
| 7 | #include "fork_impl.h" | ||
| 8 | |||
| 9 | #define malloc __libc_malloc | ||
| 10 | #define calloc __libc_calloc | ||
| 11 | #define realloc __libc_realloc | ||
| 12 | #define free __libc_free | ||
| 13 | |||
| 14 | char *dlerror() | ||
| 15 | { | ||
| 16 | 	pthread_t self = __pthread_self(); | ||
| 17 | 	if (!self->dlerror_flag) return 0; | ||
| 18 | 	self->dlerror_flag = 0; | ||
| 19 | 	char *s = self->dlerror_buf; | ||
| 20 | 	if (s == (void *)-1) | ||
| 21 | 		return "Dynamic linker failed to allocate memory for error message"; | ||
| 22 | 	else | ||
| 23 | 		return s; | ||
| 24 | } | ||
| 25 | |||
| 26 | static volatile int freebuf_queue_lock[1]; | ||
| 27 | static void **freebuf_queue; | ||
| 28 | volatile int *const __dlerror_lockptr = freebuf_queue_lock; | ||
| 29 | |||
| 30 | void __dl_thread_cleanup(void) | ||
| 31 | { | ||
| 32 | 	pthread_t self = __pthread_self(); | ||
| 33 | 	if (self->dlerror_buf && self->dlerror_buf != (void *)-1) { | ||
| 34 | 		LOCK(freebuf_queue_lock); | ||
| 35 | 		void **p = (void **)self->dlerror_buf; | ||
| 36 | 		*p = freebuf_queue; | ||
| 37 | 		freebuf_queue = p; | ||
| 38 | 		UNLOCK(freebuf_queue_lock); | ||
| 39 | 	} | ||
| 40 | } | ||
| 41 | |||
| 42 | hidden void __dl_vseterr(const char *fmt, va_list ap) | ||
| 43 | { | ||
| 44 | 	LOCK(freebuf_queue_lock); | ||
| 45 | 	void **q = freebuf_queue; | ||
| 46 | 	freebuf_queue = 0; | ||
| 47 | 	UNLOCK(freebuf_queue_lock); | ||
| 48 | |||
| 49 | 	while (q) { | ||
| 50 | 		void **p = *q; | ||
| 51 | 		free(q); | ||
| 52 | 		q = p; | ||
| 53 | 	} | ||
| 54 | |||
| 55 | 	va_list ap2; | ||
| 56 | 	va_copy(ap2, ap); | ||
| 57 | 	pthread_t self = __pthread_self(); | ||
| 58 | 	if (self->dlerror_buf != (void *)-1) | ||
| 59 | 		free(self->dlerror_buf); | ||
| 60 | 	size_t len = vsnprintf(0, 0, fmt, ap2); | ||
| 61 | 	if (len < sizeof(void *)) len = sizeof(void *); | ||
| 62 | 	va_end(ap2); | ||
| 63 | 	char *buf = malloc(len+1); | ||
| 64 | 	if (buf) { | ||
| 65 | 		vsnprintf(buf, len+1, fmt, ap); | ||
| 66 | 	} else { | ||
| 67 | 		buf = (void *)-1;	 | ||
| 68 | 	} | ||
| 69 | 	self->dlerror_buf = buf; | ||
| 70 | 	self->dlerror_flag = 1; | ||
| 71 | } | ||
| 72 | |||
| 73 | hidden void __dl_seterr(const char *fmt, ...) | ||
| 74 | { | ||
| 75 | 	va_list ap; | ||
| 76 | 	va_start(ap, fmt); | ||
| 77 | 	__dl_vseterr(fmt, ap); | ||
| 78 | 	va_end(ap); | ||
| 79 | } | ||
| 80 | |||
| 81 | static int stub_invalid_handle(void *h) | ||
| 82 | { | ||
| 83 | 	__dl_seterr("Invalid library handle %p", (void *)h); | ||
| 84 | 	return 1; | ||
| 85 | } | ||
| 86 | |||
| 87 | weak_alias(stub_invalid_handle, __dl_invalid_handle); | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dlinfo.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <dlfcn.h> | ||
| 3 | #include "dynlink.h" | ||
| 4 | |||
| 5 | int dlinfo(void *dso, int req, void *res) | ||
| 6 | { | ||
| 7 | 	if (__dl_invalid_handle(dso)) return -1; | ||
| 8 | 	if (req != RTLD_DI_LINKMAP) { | ||
| 9 | 		__dl_seterr("Unsupported request %d", req); | ||
| 10 | 		return -1; | ||
| 11 | 	} | ||
| 12 | 	*(struct link_map **)res = dso; | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dlopen.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <dlfcn.h> | ||
| 2 | #include "dynlink.h" | ||
| 3 | |||
| 4 | static void *stub_dlopen(const char *file, int mode) | ||
| 5 | { | ||
| 6 | 	__dl_seterr("Dynamic loading not supported"); | ||
| 7 | 	return 0; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(stub_dlopen, dlopen); | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/dlsym.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <dlfcn.h> | ||
| 2 | #include "dynlink.h" | ||
| 3 | |||
| 4 | void *dlsym(void *restrict p, const char *restrict s) | ||
| 5 | { | ||
| 6 | 	return __dlsym(p, s, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/dlsym.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .text | ||
| 2 | .global dlsym | ||
| 3 | .hidden __dlsym | ||
| 4 | .type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	push (%esp) | ||
| 7 | 	push 12(%esp) | ||
| 8 | 	push 12(%esp) | ||
| 9 | 	call __dlsym | ||
| 10 | 	add $12,%esp | ||
| 11 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/i386/tlsdesc.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .text | ||
| 2 | .global __tlsdesc_static | ||
| 3 | .hidden __tlsdesc_static | ||
| 4 | .type __tlsdesc_static,@function | ||
| 5 | __tlsdesc_static: | ||
| 6 | 	mov 4(%eax),%eax | ||
| 7 | 	ret | ||
| 8 | |||
| 9 | .global __tlsdesc_dynamic | ||
| 10 | .hidden __tlsdesc_dynamic | ||
| 11 | .type __tlsdesc_dynamic,@function | ||
| 12 | __tlsdesc_dynamic: | ||
| 13 | 	mov 4(%eax),%eax | ||
| 14 | 	push %edx | ||
| 15 | 	mov %gs:4,%edx | ||
| 16 | 	push %ecx | ||
| 17 | 	mov (%eax),%ecx | ||
| 18 | 	mov 4(%eax),%eax | ||
| 19 | 	add (%edx,%ecx,4),%eax | ||
| 20 | 	pop %ecx | ||
| 21 | 	sub %gs:0,%eax | ||
| 22 | 	pop %edx | ||
| 23 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/m68k/dlsym.s created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | .text | ||
| 2 | .global dlsym | ||
| 3 | .hidden __dlsym | ||
| 4 | .type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	move.l (%sp),-(%sp) | ||
| 7 | 	move.l 12(%sp),-(%sp) | ||
| 8 | 	move.l 12(%sp),-(%sp) | ||
| 9 | 	lea __dlsym-.-8,%a1 | ||
| 10 | 	jsr (%pc,%a1) | ||
| 11 | 	add.l #12,%sp | ||
| 12 | 	rts | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/m68k/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/microblaze/dlsym.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global dlsym | ||
| 2 | .hidden __dlsym | ||
| 3 | .type dlsym,@function | ||
| 4 | dlsym: | ||
| 5 | 	brid __dlsym | ||
| 6 | 	add r7, r15, r0 | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/microblaze/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/mips/dlsym.s created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | .set noreorder | ||
| 2 | .global dlsym | ||
| 3 | .hidden __dlsym | ||
| 4 | .type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	lui $gp, %hi(_gp_disp) | ||
| 7 | 	addiu $gp, %lo(_gp_disp) | ||
| 8 | 	addu $gp, $gp, $25 | ||
| 9 | 	move $6, $ra | ||
| 10 | 	lw $25, %call16(__dlsym)($gp) | ||
| 11 | 	addiu $sp, $sp, -16 | ||
| 12 | 	sw $ra, 12($sp) | ||
| 13 | 	jalr $25 | ||
| 14 | 	nop | ||
| 15 | 	lw $ra, 12($sp) | ||
| 16 | 	jr $ra | ||
| 17 | 	addiu $sp, $sp, 16 | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/mips/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/mips64/dlsym.s created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	dlsym | ||
| 3 | .hidden	__dlsym | ||
| 4 | .type	dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	lui	$3, %hi(%neg(%gp_rel(dlsym))) | ||
| 7 | 	daddiu	$3, $3, %lo(%neg(%gp_rel(dlsym))) | ||
| 8 | 	daddu	$3, $3, $25 | ||
| 9 | 	move	$6, $ra | ||
| 10 | 	ld	$25, %got_disp(__dlsym)($3) | ||
| 11 | 	daddiu	$sp, $sp, -32 | ||
| 12 | 	sd	$ra, 24($sp) | ||
| 13 | 	jalr	$25 | ||
| 14 | 	nop | ||
| 15 | 	ld	$ra, 24($sp) | ||
| 16 | 	jr	$ra | ||
| 17 | 	daddiu	$sp, $sp, 32 | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/mipsn32/dlsym.s created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	dlsym | ||
| 3 | .hidden	__dlsym | ||
| 4 | .type	dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	lui	$3, %hi(%neg(%gp_rel(dlsym))) | ||
| 7 | 	addiu	$3, $3, %lo(%neg(%gp_rel(dlsym))) | ||
| 8 | 	addu	$3, $3, $25 | ||
| 9 | 	move	$6, $ra | ||
| 10 | 	lw	$25, %got_disp(__dlsym)($3) | ||
| 11 | 	addiu	$sp, $sp, -32 | ||
| 12 | 	sd	$ra, 16($sp) | ||
| 13 | 	jalr	$25 | ||
| 14 | 	nop | ||
| 15 | 	ld	$ra, 16($sp) | ||
| 16 | 	jr	$ra | ||
| 17 | 	addiu	$sp, $sp, 32 | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/mipsn32/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/or1k/dlsym.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global dlsym | ||
| 2 | .hidden __dlsym | ||
| 3 | .type dlsym,@function | ||
| 4 | dlsym: | ||
| 5 | 	l.j	__dlsym | ||
| 6 | 	 l.ori	r5, r9, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/or1k/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc/dlsym.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | 	.text | ||
| 2 | 	.global dlsym | ||
| 3 | 	.hidden __dlsym | ||
| 4 | 	.type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	mflr 5 # The return address is arg3. | ||
| 7 | 	b __dlsym | ||
| 8 | 	.size dlsym, .-dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/powerpc64/dlsym.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | 	.text | ||
| 2 | 	.global dlsym | ||
| 3 | 	.hidden __dlsym | ||
| 4 | 	.type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	addis 2, 12, .TOC.-dlsym@ha | ||
| 7 | 	addi 2, 2, .TOC.-dlsym@l | ||
| 8 | 	.localentry dlsym,.-dlsym | ||
| 9 | 	mflr 5 # The return address is arg3. | ||
| 10 | 	b __dlsym | ||
| 11 | 	.size dlsym, .-dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/riscv64/dlsym.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global dlsym | ||
| 2 | .hidden __dlsym | ||
| 3 | .type dlsym, %function | ||
| 4 | dlsym: | ||
| 5 | 	mv a2, ra | ||
| 6 | 	tail __dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/s390x/dlsym.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | 	.global dlsym | ||
| 2 | 	.hidden __dlsym | ||
| 3 | 	.type dlsym,@function | ||
| 4 | dlsym: | ||
| 5 | 	lgr %r4, %r14 | ||
| 6 | 	jg __dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/sh/dlsym.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .text | ||
| 2 | .global dlsym | ||
| 3 | .hidden __dlsym | ||
| 4 | .type dlsym, @function | ||
| 5 | dlsym: | ||
| 6 | 	mov.l L1, r0 | ||
| 7 | 1:	braf r0 | ||
| 8 | 	 mov.l @r15, r6 | ||
| 9 | |||
| 10 | .align 2 | ||
| 11 | L1:	.long __dlsym@PLT-(1b+4-.) | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/sh/dlsym_time64.S created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #define __dlsym __dlsym_redir_time64 | ||
| 2 | #define dlsym __dlsym_time64 | ||
| 3 | #include "dlsym.s" | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/tlsdesc.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <stddef.h> | ||
| 2 | #include <dynlink.h> | ||
| 3 | |||
| 4 | ptrdiff_t __tlsdesc_static() | ||
| 5 | { | ||
| 6 | 	return 0; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__tlsdesc_static, __tlsdesc_dynamic); | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/x32/dlsym.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .text | ||
| 2 | .global dlsym | ||
| 3 | .hidden __dlsym | ||
| 4 | .type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	mov (%rsp),%rdx | ||
| 7 | 	jmp __dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/x86_64/dlsym.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .text | ||
| 2 | .global dlsym | ||
| 3 | .hidden __dlsym | ||
| 4 | .type dlsym,@function | ||
| 5 | dlsym: | ||
| 6 | 	mov (%rsp),%rdx | ||
| 7 | 	jmp __dlsym | ||
lib/libc/wasi/libc-top-half/musl/src/ldso/x86_64/tlsdesc.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .text | ||
| 2 | .global __tlsdesc_static | ||
| 3 | .hidden __tlsdesc_static | ||
| 4 | .type __tlsdesc_static,@function | ||
| 5 | __tlsdesc_static: | ||
| 6 | 	mov 8(%rax),%rax | ||
| 7 | 	ret | ||
| 8 | |||
| 9 | .global __tlsdesc_dynamic | ||
| 10 | .hidden __tlsdesc_dynamic | ||
| 11 | .type __tlsdesc_dynamic,@function | ||
| 12 | __tlsdesc_dynamic: | ||
| 13 | 	mov 8(%rax),%rax | ||
| 14 | 	push %rdx | ||
| 15 | 	mov %fs:8,%rdx | ||
| 16 | 	push %rcx | ||
| 17 | 	mov (%rax),%rcx | ||
| 18 | 	mov 8(%rax),%rax | ||
| 19 | 	add (%rdx,%rcx,8),%rax | ||
| 20 | 	pop %rcx | ||
| 21 | 	sub %fs:0,%rax | ||
| 22 | 	pop %rdx | ||
| 23 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/cuserid.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <pwd.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | |||
| 6 | char *cuserid(char *buf) | ||
| 7 | { | ||
| 8 | 	struct passwd pw, *ppw; | ||
| 9 | 	long pwb[256]; | ||
| 10 | 	if (getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw)) | ||
| 11 | 		return 0; | ||
| 12 | 	snprintf(buf, L_cuserid, "%s", pw.pw_name); | ||
| 13 | 	return buf; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/daemon.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int daemon(int nochdir, int noclose) | ||
| 6 | { | ||
| 7 | 	if (!nochdir && chdir("/")) | ||
| 8 | 		return -1; | ||
| 9 | 	if (!noclose) { | ||
| 10 | 		int fd, failed = 0; | ||
| 11 | 		if ((fd = open("/dev/null", O_RDWR)) < 0) return -1; | ||
| 12 | 		if (dup2(fd, 0) < 0 || dup2(fd, 1) < 0 || dup2(fd, 2) < 0) | ||
| 13 | 			failed++; | ||
| 14 | 		if (fd > 2) close(fd); | ||
| 15 | 		if (failed) return -1; | ||
| 16 | 	} | ||
| 17 | |||
| 18 | 	switch(fork()) { | ||
| 19 | 	case 0: break; | ||
| 20 | 	case -1: return -1; | ||
| 21 | 	default: _exit(0); | ||
| 22 | 	} | ||
| 23 | |||
| 24 | 	if (setsid() < 0) return -1; | ||
| 25 | |||
| 26 | 	switch(fork()) { | ||
| 27 | 	case 0: break; | ||
| 28 | 	case -1: return -1; | ||
| 29 | 	default: _exit(0); | ||
| 30 | 	} | ||
| 31 | |||
| 32 | 	return 0; | ||
| 33 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/err.c created+67| ... | @@ -0,0 +1,67 @@ | ||
| 1 | #include <err.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | |||
| 6 | extern char *__progname; | ||
| 7 | |||
| 8 | void vwarn(const char *fmt, va_list ap) | ||
| 9 | { | ||
| 10 | 	fprintf (stderr, "%s: ", __progname); | ||
| 11 | 	if (fmt) { | ||
| 12 | 		vfprintf(stderr, fmt, ap); | ||
| 13 | 		fputs (": ", stderr); | ||
| 14 | 	} | ||
| 15 | 	perror(0); | ||
| 16 | } | ||
| 17 | |||
| 18 | void vwarnx(const char *fmt, va_list ap) | ||
| 19 | { | ||
| 20 | 	fprintf (stderr, "%s: ", __progname); | ||
| 21 | 	if (fmt) vfprintf(stderr, fmt, ap); | ||
| 22 | 	putc('\n', stderr); | ||
| 23 | } | ||
| 24 | |||
| 25 | _Noreturn void verr(int status, const char *fmt, va_list ap) | ||
| 26 | { | ||
| 27 | 	vwarn(fmt, ap); | ||
| 28 | 	exit(status); | ||
| 29 | } | ||
| 30 | |||
| 31 | _Noreturn void verrx(int status, const char *fmt, va_list ap) | ||
| 32 | { | ||
| 33 | 	vwarnx(fmt, ap); | ||
| 34 | 	exit(status); | ||
| 35 | } | ||
| 36 | |||
| 37 | void warn(const char *fmt, ...) | ||
| 38 | { | ||
| 39 | 	va_list ap; | ||
| 40 | 	va_start(ap, fmt); | ||
| 41 | 	vwarn(fmt, ap); | ||
| 42 | 	va_end(ap); | ||
| 43 | } | ||
| 44 | |||
| 45 | void warnx(const char *fmt, ...) | ||
| 46 | { | ||
| 47 | 	va_list ap; | ||
| 48 | 	va_start(ap, fmt); | ||
| 49 | 	vwarnx(fmt, ap); | ||
| 50 | 	va_end(ap); | ||
| 51 | } | ||
| 52 | |||
| 53 | _Noreturn void err(int status, const char *fmt, ...) | ||
| 54 | { | ||
| 55 | 	va_list ap; | ||
| 56 | 	va_start(ap, fmt); | ||
| 57 | 	verr(status, fmt, ap); | ||
| 58 | 	va_end(ap); | ||
| 59 | } | ||
| 60 | |||
| 61 | _Noreturn void errx(int status, const char *fmt, ...) | ||
| 62 | { | ||
| 63 | 	va_list ap; | ||
| 64 | 	va_start(ap, fmt); | ||
| 65 | 	verrx(status, fmt, ap); | ||
| 66 | 	va_end(ap); | ||
| 67 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/euidaccess.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | |||
| 5 | int euidaccess(const char *filename, int amode) | ||
| 6 | { | ||
| 7 | 	return faccessat(AT_FDCWD, filename, amode, AT_EACCESS); | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(euidaccess, eaccess); | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/ftw.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <ftw.h> | ||
| 2 | |||
| 3 | int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int fd_limit) | ||
| 4 | { | ||
| 5 | 	/* The following cast assumes that calling a function with one | ||
| 6 | 	 * argument more than it needs behaves as expected. This is | ||
| 7 | 	 * actually undefined, but works on all real-world machines. */ | ||
| 8 | 	return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS); | ||
| 9 | } | ||
| 10 | |||
| 11 | weak_alias(ftw, ftw64); | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/futimes.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/stat.h> | ||
| 3 | #include <sys/time.h> | ||
| 4 | |||
| 5 | int futimes(int fd, const struct timeval tv[2]) | ||
| 6 | { | ||
| 7 | 	struct timespec times[2]; | ||
| 8 | 	if (!tv) return futimens(fd, 0); | ||
| 9 | 	times[0].tv_sec = tv[0].tv_sec; | ||
| 10 | 	times[0].tv_nsec = tv[0].tv_usec * 1000; | ||
| 11 | 	times[1].tv_sec = tv[1].tv_sec; | ||
| 12 | 	times[1].tv_nsec = tv[1].tv_usec * 1000; | ||
| 13 | 	return futimens(fd, times); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/getdtablesize.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <sys/resource.h> | ||
| 5 | |||
| 6 | int getdtablesize(void) | ||
| 7 | { | ||
| 8 | 	struct rlimit rl; | ||
| 9 | 	getrlimit(RLIMIT_NOFILE, &rl); | ||
| 10 | 	return rl.rlim_cur < INT_MAX ? rl.rlim_cur : INT_MAX; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/getloadavg.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sys/sysinfo.h> | ||
| 4 | |||
| 5 | int getloadavg(double *a, int n) | ||
| 6 | { | ||
| 7 | 	struct sysinfo si; | ||
| 8 | 	if (n <= 0) return n ? -1 : 0; | ||
| 9 | 	sysinfo(&si); | ||
| 10 | 	if (n > 3) n = 3; | ||
| 11 | 	for (int i=0; i<n; i++) | ||
| 12 | 		a[i] = 1.0/(1<<SI_LOAD_SHIFT) * si.loads[i]; | ||
| 13 | 	return n; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/getpagesize.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int getpagesize(void) | ||
| 6 | { | ||
| 7 | 	return PAGE_SIZE; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/getpass.c created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <termios.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <fcntl.h> | ||
| 6 | #include <string.h> | ||
| 7 | |||
| 8 | char *getpass(const char *prompt) | ||
| 9 | { | ||
| 10 | 	int fd; | ||
| 11 | 	struct termios s, t; | ||
| 12 | 	ssize_t l; | ||
| 13 | 	static char password[128]; | ||
| 14 | |||
| 15 | 	if ((fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_CLOEXEC)) < 0) return 0; | ||
| 16 | |||
| 17 | 	tcgetattr(fd, &t); | ||
| 18 | 	s = t; | ||
| 19 | 	t.c_lflag &= ~(ECHO|ISIG); | ||
| 20 | 	t.c_lflag |= ICANON; | ||
| 21 | 	t.c_iflag &= ~(INLCR|IGNCR); | ||
| 22 | 	t.c_iflag |= ICRNL; | ||
| 23 | 	tcsetattr(fd, TCSAFLUSH, &t); | ||
| 24 | 	tcdrain(fd); | ||
| 25 | |||
| 26 | 	dprintf(fd, "%s", prompt); | ||
| 27 | |||
| 28 | 	l = read(fd, password, sizeof password); | ||
| 29 | 	if (l >= 0) { | ||
| 30 | 		if (l > 0 && password[l-1] == '\n' || l==sizeof password) l--; | ||
| 31 | 		password[l] = 0; | ||
| 32 | 	} | ||
| 33 | |||
| 34 | 	tcsetattr(fd, TCSAFLUSH, &s); | ||
| 35 | |||
| 36 | 	dprintf(fd, "\n"); | ||
| 37 | 	close(fd); | ||
| 38 | |||
| 39 | 	return l<0 ? 0 : password; | ||
| 40 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/getusershell.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | static const char defshells[] = "/bin/sh\n/bin/csh\n"; | ||
| 6 | |||
| 7 | static char *line; | ||
| 8 | static size_t linesize; | ||
| 9 | static FILE *f; | ||
| 10 | |||
| 11 | void endusershell(void) | ||
| 12 | { | ||
| 13 | 	if (f) fclose(f); | ||
| 14 | 	f = 0; | ||
| 15 | } | ||
| 16 | |||
| 17 | void setusershell(void) | ||
| 18 | { | ||
| 19 | 	if (!f) f = fopen("/etc/shells", "rbe"); | ||
| 20 | 	if (!f) f = fmemopen((void *)defshells, sizeof defshells - 1, "rb"); | ||
| 21 | } | ||
| 22 | |||
| 23 | char *getusershell(void) | ||
| 24 | { | ||
| 25 | 	ssize_t l; | ||
| 26 | 	if (!f) setusershell(); | ||
| 27 | 	if (!f) return 0; | ||
| 28 | 	l = getline(&line, &linesize, f); | ||
| 29 | 	if (l <= 0) return 0; | ||
| 30 | 	if (line[l-1]=='\n') line[l-1]=0; | ||
| 31 | 	return line; | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/isastream.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stropts.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | |||
| 4 | int isastream(int fd) | ||
| 5 | { | ||
| 6 | 	return fcntl(fd, F_GETFD) < 0 ? -1 : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/lutimes.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/stat.h> | ||
| 3 | #include <sys/time.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | |||
| 6 | int lutimes(const char *filename, const struct timeval tv[2]) | ||
| 7 | { | ||
| 8 | 	struct timespec times[2]; | ||
| 9 | 	if (tv) { | ||
| 10 | 		times[0].tv_sec = tv[0].tv_sec; | ||
| 11 | 		times[0].tv_nsec = tv[0].tv_usec * 1000; | ||
| 12 | 		times[1].tv_sec = tv[1].tv_sec; | ||
| 13 | 		times[1].tv_nsec = tv[1].tv_usec * 1000; | ||
| 14 | 	} | ||
| 15 | 	return utimensat(AT_FDCWD, filename, tv ? times : 0, AT_SYMLINK_NOFOLLOW); | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/ulimit.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <sys/resource.h> | ||
| 2 | #include <ulimit.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | |||
| 5 | long ulimit(int cmd, ...) | ||
| 6 | { | ||
| 7 | 	struct rlimit rl; | ||
| 8 | 	getrlimit(RLIMIT_FSIZE, &rl); | ||
| 9 | 	if (cmd == UL_SETFSIZE) { | ||
| 10 | 		long val; | ||
| 11 | 		va_list ap; | ||
| 12 | 		va_start(ap, cmd); | ||
| 13 | 		val = va_arg(ap, long); | ||
| 14 | 		va_end(ap); | ||
| 15 | 		rl.rlim_cur = 512ULL * val; | ||
| 16 | 		if (setrlimit(RLIMIT_FSIZE, &rl)) return -1; | ||
| 17 | 	} | ||
| 18 | 	return rl.rlim_cur / 512; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/utmpx.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <utmpx.h> | ||
| 3 | #include <stddef.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | void endutxent(void) | ||
| 7 | { | ||
| 8 | } | ||
| 9 | |||
| 10 | void setutxent(void) | ||
| 11 | { | ||
| 12 | } | ||
| 13 | |||
| 14 | struct utmpx *getutxent(void) | ||
| 15 | { | ||
| 16 | 	return NULL; | ||
| 17 | } | ||
| 18 | |||
| 19 | struct utmpx *getutxid(const struct utmpx *ut) | ||
| 20 | { | ||
| 21 | 	return NULL; | ||
| 22 | } | ||
| 23 | |||
| 24 | struct utmpx *getutxline(const struct utmpx *ut) | ||
| 25 | { | ||
| 26 | 	return NULL; | ||
| 27 | } | ||
| 28 | |||
| 29 | struct utmpx *pututxline(const struct utmpx *ut) | ||
| 30 | { | ||
| 31 | 	return NULL; | ||
| 32 | } | ||
| 33 | |||
| 34 | void updwtmpx(const char *f, const struct utmpx *u) | ||
| 35 | { | ||
| 36 | } | ||
| 37 | |||
| 38 | static int __utmpxname(const char *f) | ||
| 39 | { | ||
| 40 | 	errno = ENOTSUP; | ||
| 41 | 	return -1; | ||
| 42 | } | ||
| 43 | |||
| 44 | weak_alias(endutxent, endutent); | ||
| 45 | weak_alias(setutxent, setutent); | ||
| 46 | weak_alias(getutxent, getutent); | ||
| 47 | weak_alias(getutxid, getutid); | ||
| 48 | weak_alias(getutxline, getutline); | ||
| 49 | weak_alias(pututxline, pututline); | ||
| 50 | weak_alias(updwtmpx, updwtmp); | ||
| 51 | weak_alias(__utmpxname, utmpname); | ||
| 52 | weak_alias(__utmpxname, utmpxname); | ||
lib/libc/wasi/libc-top-half/musl/src/legacy/valloc.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | void *valloc(size_t size) | ||
| 6 | { | ||
| 7 | 	return memalign(PAGE_SIZE, size); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/adjtime.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <sys/timex.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int adjtime(const struct timeval *in, struct timeval *out) | ||
| 8 | { | ||
| 9 | 	struct timex tx = { 0 }; | ||
| 10 | 	if (in) { | ||
| 11 | 		if (in->tv_sec > 1000 || in->tv_usec > 1000000000) { | ||
| 12 | 			errno = EINVAL; | ||
| 13 | 			return -1; | ||
| 14 | 		} | ||
| 15 | 		tx.offset = in->tv_sec*1000000 + in->tv_usec; | ||
| 16 | 		tx.modes = ADJ_OFFSET_SINGLESHOT; | ||
| 17 | 	} | ||
| 18 | 	if (adjtimex(&tx) < 0) return -1; | ||
| 19 | 	if (out) { | ||
| 20 | 		out->tv_sec = tx.offset / 1000000; | ||
| 21 | 		if ((out->tv_usec = tx.offset % 1000000) < 0) { | ||
| 22 | 			out->tv_sec--; | ||
| 23 | 			out->tv_usec += 1000000; | ||
| 24 | 		} | ||
| 25 | 	} | ||
| 26 | 	return 0; | ||
| 27 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/adjtimex.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/timex.h> | ||
| 2 | #include <time.h> | ||
| 3 | |||
| 4 | int adjtimex(struct timex *tx) | ||
| 5 | { | ||
| 6 | 	return clock_adjtime(CLOCK_REALTIME, tx); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/arch_prctl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | #ifdef SYS_arch_prctl | ||
| 3 | int arch_prctl(int code, unsigned long addr) | ||
| 4 | { | ||
| 5 | 	return syscall(SYS_arch_prctl, code, addr); | ||
| 6 | } | ||
| 7 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/linux/brk.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int brk(void *end) | ||
| 7 | { | ||
| 8 | 	return __syscall_ret(-ENOMEM); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/cache.c created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "atomic.h" | ||
| 4 | |||
| 5 | #ifdef SYS_cacheflush | ||
| 6 | int _flush_cache(void *addr, int len, int op) | ||
| 7 | { | ||
| 8 | 	return syscall(SYS_cacheflush, addr, len, op); | ||
| 9 | } | ||
| 10 | weak_alias(_flush_cache, cacheflush); | ||
| 11 | #endif | ||
| 12 | |||
| 13 | #ifdef SYS_cachectl | ||
| 14 | int __cachectl(void *addr, int len, int op) | ||
| 15 | { | ||
| 16 | 	return syscall(SYS_cachectl, addr, len, op); | ||
| 17 | } | ||
| 18 | weak_alias(__cachectl, cachectl); | ||
| 19 | #endif | ||
| 20 | |||
| 21 | #ifdef SYS_riscv_flush_icache | ||
| 22 | |||
| 23 | #define VDSO_FLUSH_ICACHE_SYM "__vdso_flush_icache" | ||
| 24 | #define VDSO_FLUSH_ICACHE_VER "LINUX_4.5" | ||
| 25 | |||
| 26 | static void *volatile vdso_func; | ||
| 27 | |||
| 28 | static int flush_icache_init(void *start, void *end, unsigned long int flags) | ||
| 29 | { | ||
| 30 | 	void *p = __vdsosym(VDSO_FLUSH_ICACHE_VER, VDSO_FLUSH_ICACHE_SYM); | ||
| 31 | 	int (*f)(void *, void *, unsigned long int) = | ||
| 32 | 		(int (*)(void *, void *, unsigned long int))p; | ||
| 33 | 	a_cas_p(&vdso_func, (void *)flush_icache_init, p); | ||
| 34 | 	return f ? f(start, end, flags) : -ENOSYS; | ||
| 35 | } | ||
| 36 | |||
| 37 | static void *volatile vdso_func = (void *)flush_icache_init; | ||
| 38 | |||
| 39 | int __riscv_flush_icache(void *start, void *end, unsigned long int flags) | ||
| 40 | { | ||
| 41 | 	int (*f)(void *, void *, unsigned long int) = | ||
| 42 | 		(int (*)(void *, void *, unsigned long int))vdso_func; | ||
| 43 | 	if (f) { | ||
| 44 | 		int r = f(start, end, flags); | ||
| 45 | 		if (!r) return r; | ||
| 46 | 		if (r != -ENOSYS) return __syscall_ret(r); | ||
| 47 | 	} | ||
| 48 | } | ||
| 49 | weak_alias(__riscv_flush_icache, riscv_flush_icache); | ||
| 50 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/linux/cap.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | int capset(void *a, void *b) | ||
| 4 | { | ||
| 5 | 	return syscall(SYS_capset, a, b); | ||
| 6 | } | ||
| 7 | |||
| 8 | int capget(void *a, void *b) | ||
| 9 | { | ||
| 10 | 	return syscall(SYS_capget, a, b); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/chroot.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int chroot(const char *path) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_chroot, path); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/clock_adjtime.c created+151| ... | @@ -0,0 +1,151 @@ | ||
| 1 | #include <sys/timex.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 7 | |||
| 8 | struct ktimex64 { | ||
| 9 | 	unsigned modes; | ||
| 10 | 	int :32; | ||
| 11 | 	long long offset, freq, maxerror, esterror; | ||
| 12 | 	int status; | ||
| 13 | 	int :32; | ||
| 14 | 	long long constant, precision, tolerance; | ||
| 15 | 	long long time_sec, time_usec; | ||
| 16 | 	long long tick, ppsfreq, jitter; | ||
| 17 | 	int shift; | ||
| 18 | 	int :32; | ||
| 19 | 	long long stabil, jitcnt, calcnt, errcnt, stbcnt; | ||
| 20 | 	int tai; | ||
| 21 | 	int __padding[11]; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct ktimex { | ||
| 25 | 	unsigned modes; | ||
| 26 | 	long offset, freq, maxerror, esterror; | ||
| 27 | 	int status; | ||
| 28 | 	long constant, precision, tolerance; | ||
| 29 | 	long time_sec, time_usec; | ||
| 30 | 	long tick, ppsfreq, jitter; | ||
| 31 | 	int shift; | ||
| 32 | 	long stabil, jitcnt, calcnt, errcnt, stbcnt; | ||
| 33 | 	int tai; | ||
| 34 | 	int __padding[11]; | ||
| 35 | }; | ||
| 36 | |||
| 37 | int clock_adjtime (clockid_t clock_id, struct timex *utx) | ||
| 38 | { | ||
| 39 | 	int r = -ENOSYS; | ||
| 40 | #ifdef SYS_clock_adjtime64 | ||
| 41 | 	struct ktimex64 ktx = { | ||
| 42 | 		.modes = utx->modes, | ||
| 43 | 		.offset = utx->offset, | ||
| 44 | 		.freq = utx->freq, | ||
| 45 | 		.maxerror = utx->maxerror, | ||
| 46 | 		.esterror = utx->esterror, | ||
| 47 | 		.status = utx->status, | ||
| 48 | 		.constant = utx->constant, | ||
| 49 | 		.precision = utx->precision, | ||
| 50 | 		.tolerance = utx->tolerance, | ||
| 51 | 		.time_sec = utx->time.tv_sec, | ||
| 52 | 		.time_usec = utx->time.tv_usec, | ||
| 53 | 		.tick = utx->tick, | ||
| 54 | 		.ppsfreq = utx->ppsfreq, | ||
| 55 | 		.jitter = utx->jitter, | ||
| 56 | 		.shift = utx->shift, | ||
| 57 | 		.stabil = utx->stabil, | ||
| 58 | 		.jitcnt = utx->jitcnt, | ||
| 59 | 		.calcnt = utx->calcnt, | ||
| 60 | 		.errcnt = utx->errcnt, | ||
| 61 | 		.stbcnt = utx->stbcnt, | ||
| 62 | 		.tai = utx->tai, | ||
| 63 | 	}; | ||
| 64 | 	r = __syscall(SYS_clock_adjtime64, clock_id, &ktx); | ||
| 65 | 	if (r>=0) { | ||
| 66 | 		utx->modes = ktx.modes; | ||
| 67 | 		utx->offset = ktx.offset; | ||
| 68 | 		utx->freq = ktx.freq; | ||
| 69 | 		utx->maxerror = ktx.maxerror; | ||
| 70 | 		utx->esterror = ktx.esterror; | ||
| 71 | 		utx->status = ktx.status; | ||
| 72 | 		utx->constant = ktx.constant; | ||
| 73 | 		utx->precision = ktx.precision; | ||
| 74 | 		utx->tolerance = ktx.tolerance; | ||
| 75 | 		utx->time.tv_sec = ktx.time_sec; | ||
| 76 | 		utx->time.tv_usec = ktx.time_usec; | ||
| 77 | 		utx->tick = ktx.tick; | ||
| 78 | 		utx->ppsfreq = ktx.ppsfreq; | ||
| 79 | 		utx->jitter = ktx.jitter; | ||
| 80 | 		utx->shift = ktx.shift; | ||
| 81 | 		utx->stabil = ktx.stabil; | ||
| 82 | 		utx->jitcnt = ktx.jitcnt; | ||
| 83 | 		utx->calcnt = ktx.calcnt; | ||
| 84 | 		utx->errcnt = ktx.errcnt; | ||
| 85 | 		utx->stbcnt = ktx.stbcnt; | ||
| 86 | 		utx->tai = ktx.tai; | ||
| 87 | 	} | ||
| 88 | 	if (SYS_clock_adjtime == SYS_clock_adjtime64 || r!=-ENOSYS) | ||
| 89 | 		return __syscall_ret(r); | ||
| 90 | 	if ((utx->modes & ADJ_SETOFFSET) && !IS32BIT(utx->time.tv_sec)) | ||
| 91 | 		return __syscall_ret(-ENOTSUP); | ||
| 92 | #endif | ||
| 93 | 	if (sizeof(time_t) > sizeof(long)) { | ||
| 94 | 		struct ktimex ktx = { | ||
| 95 | 			.modes = utx->modes, | ||
| 96 | 			.offset = utx->offset, | ||
| 97 | 			.freq = utx->freq, | ||
| 98 | 			.maxerror = utx->maxerror, | ||
| 99 | 			.esterror = utx->esterror, | ||
| 100 | 			.status = utx->status, | ||
| 101 | 			.constant = utx->constant, | ||
| 102 | 			.precision = utx->precision, | ||
| 103 | 			.tolerance = utx->tolerance, | ||
| 104 | 			.time_sec = utx->time.tv_sec, | ||
| 105 | 			.time_usec = utx->time.tv_usec, | ||
| 106 | 			.tick = utx->tick, | ||
| 107 | 			.ppsfreq = utx->ppsfreq, | ||
| 108 | 			.jitter = utx->jitter, | ||
| 109 | 			.shift = utx->shift, | ||
| 110 | 			.stabil = utx->stabil, | ||
| 111 | 			.jitcnt = utx->jitcnt, | ||
| 112 | 			.calcnt = utx->calcnt, | ||
| 113 | 			.errcnt = utx->errcnt, | ||
| 114 | 			.stbcnt = utx->stbcnt, | ||
| 115 | 			.tai = utx->tai, | ||
| 116 | 		}; | ||
| 117 | #ifdef SYS_adjtimex | ||
| 118 | 		if (clock_id==CLOCK_REALTIME) r = __syscall(SYS_adjtimex, &ktx); | ||
| 119 | 		else | ||
| 120 | #endif | ||
| 121 | 		r = __syscall(SYS_clock_adjtime, clock_id, &ktx); | ||
| 122 | 		if (r>=0) { | ||
| 123 | 			utx->modes = ktx.modes; | ||
| 124 | 			utx->offset = ktx.offset; | ||
| 125 | 			utx->freq = ktx.freq; | ||
| 126 | 			utx->maxerror = ktx.maxerror; | ||
| 127 | 			utx->esterror = ktx.esterror; | ||
| 128 | 			utx->status = ktx.status; | ||
| 129 | 			utx->constant = ktx.constant; | ||
| 130 | 			utx->precision = ktx.precision; | ||
| 131 | 			utx->tolerance = ktx.tolerance; | ||
| 132 | 			utx->time.tv_sec = ktx.time_sec; | ||
| 133 | 			utx->time.tv_usec = ktx.time_usec; | ||
| 134 | 			utx->tick = ktx.tick; | ||
| 135 | 			utx->ppsfreq = ktx.ppsfreq; | ||
| 136 | 			utx->jitter = ktx.jitter; | ||
| 137 | 			utx->shift = ktx.shift; | ||
| 138 | 			utx->stabil = ktx.stabil; | ||
| 139 | 			utx->jitcnt = ktx.jitcnt; | ||
| 140 | 			utx->calcnt = ktx.calcnt; | ||
| 141 | 			utx->errcnt = ktx.errcnt; | ||
| 142 | 			utx->stbcnt = ktx.stbcnt; | ||
| 143 | 			utx->tai = ktx.tai; | ||
| 144 | 		} | ||
| 145 | 		return __syscall_ret(r); | ||
| 146 | 	} | ||
| 147 | #ifdef SYS_adjtimex | ||
| 148 | 	if (clock_id==CLOCK_REALTIME) return syscall(SYS_adjtimex, utx); | ||
| 149 | #endif | ||
| 150 | 	return syscall(SYS_clock_adjtime, clock_id, utx); | ||
| 151 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/clone.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <sched.h> | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | int clone(int (*func)(void *), void *stack, int flags, void *arg, ...) | ||
| 9 | { | ||
| 10 | 	va_list ap; | ||
| 11 | 	pid_t *ptid, *ctid; | ||
| 12 | 	void *tls; | ||
| 13 | |||
| 14 | 	va_start(ap, arg); | ||
| 15 | 	ptid = va_arg(ap, pid_t *); | ||
| 16 | 	tls = va_arg(ap, void *); | ||
| 17 | 	ctid = va_arg(ap, pid_t *); | ||
| 18 | 	va_end(ap); | ||
| 19 | |||
| 20 | 	return __syscall_ret(__clone(func, stack, flags, arg, ptid, tls, ctid)); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/copy_file_range.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t copy_file_range(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_copy_file_range, fd_in, off_in, fd_out, off_out, len, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/epoll.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include <sys/epoll.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int epoll_create(int size) | ||
| 7 | { | ||
| 8 | 	return epoll_create1(0); | ||
| 9 | } | ||
| 10 | |||
| 11 | int epoll_create1(int flags) | ||
| 12 | { | ||
| 13 | 	int r = __syscall(SYS_epoll_create1, flags); | ||
| 14 | #ifdef SYS_epoll_create | ||
| 15 | 	if (r==-ENOSYS && !flags) r = __syscall(SYS_epoll_create, 1); | ||
| 16 | #endif | ||
| 17 | 	return __syscall_ret(r); | ||
| 18 | } | ||
| 19 | |||
| 20 | int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev) | ||
| 21 | { | ||
| 22 | 	return syscall(SYS_epoll_ctl, fd, op, fd2, ev); | ||
| 23 | } | ||
| 24 | |||
| 25 | int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs) | ||
| 26 | { | ||
| 27 | 	int r = __syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8); | ||
| 28 | #ifdef SYS_epoll_wait | ||
| 29 | 	if (r==-ENOSYS && !sigs) r = __syscall(SYS_epoll_wait, fd, ev, cnt, to); | ||
| 30 | #endif | ||
| 31 | 	return __syscall_ret(r); | ||
| 32 | } | ||
| 33 | |||
| 34 | int epoll_wait(int fd, struct epoll_event *ev, int cnt, int to) | ||
| 35 | { | ||
| 36 | 	return epoll_pwait(fd, ev, cnt, to, 0); | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/eventfd.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <sys/eventfd.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int eventfd(unsigned int count, int flags) | ||
| 7 | { | ||
| 8 | 	int r = __syscall(SYS_eventfd2, count, flags); | ||
| 9 | #ifdef SYS_eventfd | ||
| 10 | 	if (r==-ENOSYS && !flags) r = __syscall(SYS_eventfd, count); | ||
| 11 | #endif | ||
| 12 | 	return __syscall_ret(r); | ||
| 13 | } | ||
| 14 | |||
| 15 | int eventfd_read(int fd, eventfd_t *value) | ||
| 16 | { | ||
| 17 | 	return (sizeof(*value) == read(fd, value, sizeof(*value))) ? 0 : -1; | ||
| 18 | } | ||
| 19 | |||
| 20 | int eventfd_write(int fd, eventfd_t value) | ||
| 21 | { | ||
| 22 | 	return (sizeof(value) == write(fd, &value, sizeof(value))) ? 0 : -1; | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/fallocate.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int fallocate(int fd, int mode, off_t base, off_t len) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base), | ||
| 8 | 		__SYSCALL_LL_E(len)); | ||
| 9 | } | ||
| 10 | |||
| 11 | #undef fallocate64 | ||
| 12 | weak_alias(fallocate, fallocate64); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/fanotify.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | #include <sys/fanotify.h> | ||
| 3 | |||
| 4 | int fanotify_init(unsigned flags, unsigned event_f_flags) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_fanotify_init, flags, event_f_flags); | ||
| 7 | } | ||
| 8 | |||
| 9 | int fanotify_mark(int fanotify_fd, unsigned flags, unsigned long long mask, | ||
| 10 | 	 int dfd, const char *pathname) | ||
| 11 | { | ||
| 12 | 	return syscall(SYS_fanotify_mark, fanotify_fd, flags, __SYSCALL_LL_E(mask), dfd, pathname); | ||
| 13 | } | ||
| 14 | |||
lib/libc/wasi/libc-top-half/musl/src/linux/flock.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/file.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int flock(int fd, int op) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_flock, fd, op); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/getdents.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <dirent.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int getdents(int fd, struct dirent *buf, size_t len) | ||
| 7 | { | ||
| 8 | 	if (len>INT_MAX) len = INT_MAX; | ||
| 9 | 	return syscall(SYS_getdents, fd, buf, len); | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(getdents, getdents64); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/getrandom.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/random.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t getrandom(void *buf, size_t buflen, unsigned flags) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_getrandom, buf, buflen, flags); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/gettid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | pid_t gettid(void) | ||
| 6 | { | ||
| 7 | 	return __pthread_self()->tid; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/inotify.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <sys/inotify.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int inotify_init() | ||
| 6 | { | ||
| 7 | 	return inotify_init1(0); | ||
| 8 | } | ||
| 9 | int inotify_init1(int flags) | ||
| 10 | { | ||
| 11 | 	int r = __syscall(SYS_inotify_init1, flags); | ||
| 12 | #ifdef SYS_inotify_init | ||
| 13 | 	if (r==-ENOSYS && !flags) r = __syscall(SYS_inotify_init); | ||
| 14 | #endif | ||
| 15 | 	return __syscall_ret(r); | ||
| 16 | } | ||
| 17 | |||
| 18 | int inotify_add_watch(int fd, const char *pathname, uint32_t mask) | ||
| 19 | { | ||
| 20 | 	return syscall(SYS_inotify_add_watch, fd, pathname, mask); | ||
| 21 | } | ||
| 22 | |||
| 23 | int inotify_rm_watch(int fd, int wd) | ||
| 24 | { | ||
| 25 | 	return syscall(SYS_inotify_rm_watch, fd, wd); | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/ioperm.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | #ifdef SYS_ioperm | ||
| 4 | #include <sys/io.h> | ||
| 5 | |||
| 6 | int ioperm(unsigned long from, unsigned long num, int turn_on) | ||
| 7 | { | ||
| 8 | 	return syscall(SYS_ioperm, from, num, turn_on); | ||
| 9 | } | ||
| 10 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/linux/iopl.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | #ifdef SYS_iopl | ||
| 4 | #include <sys/io.h> | ||
| 5 | |||
| 6 | int iopl(int level) | ||
| 7 | { | ||
| 8 | 	return syscall(SYS_iopl, level); | ||
| 9 | } | ||
| 10 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/linux/klogctl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/klog.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int klogctl (int type, char *buf, int len) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_syslog, type, buf, len); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/membarrier.c created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | #include <sys/membarrier.h> | ||
| 2 | #include <semaphore.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | static void dummy_0(void) | ||
| 9 | { | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(dummy_0, __tl_lock); | ||
| 13 | weak_alias(dummy_0, __tl_unlock); | ||
| 14 | |||
| 15 | static sem_t barrier_sem; | ||
| 16 | |||
| 17 | static void bcast_barrier(int s) | ||
| 18 | { | ||
| 19 | 	sem_post(&barrier_sem); | ||
| 20 | } | ||
| 21 | |||
| 22 | int __membarrier(int cmd, int flags) | ||
| 23 | { | ||
| 24 | 	int r = __syscall(SYS_membarrier, cmd, flags); | ||
| 25 | 	/* Emulate the private expedited command, which is needed by the | ||
| 26 | 	 * dynamic linker for installation of dynamic TLS, for older | ||
| 27 | 	 * kernels that lack the syscall. Unlike the syscall, this only | ||
| 28 | 	 * synchronizes with threads of the process, not other processes | ||
| 29 | 	 * sharing the VM, but such sharing is not a supported usage | ||
| 30 | 	 * anyway. */ | ||
| 31 | 	if (r && cmd == MEMBARRIER_CMD_PRIVATE_EXPEDITED && !flags) { | ||
| 32 | 		pthread_t self=__pthread_self(), td; | ||
| 33 | 		sigset_t set; | ||
| 34 | 		__block_app_sigs(&set); | ||
| 35 | 		__tl_lock(); | ||
| 36 | 		sem_init(&barrier_sem, 0, 0); | ||
| 37 | 		struct sigaction sa = { | ||
| 38 | 			.sa_flags = SA_RESTART, | ||
| 39 | 			.sa_handler = bcast_barrier | ||
| 40 | 		}; | ||
| 41 | 		memset(&sa.sa_mask, -1, sizeof sa.sa_mask); | ||
| 42 | 		if (!__libc_sigaction(SIGSYNCCALL, &sa, 0)) { | ||
| 43 | 			for (td=self->next; td!=self; td=td->next) | ||
| 44 | 				__syscall(SYS_tkill, td->tid, SIGSYNCCALL); | ||
| 45 | 			for (td=self->next; td!=self; td=td->next) | ||
| 46 | 				sem_wait(&barrier_sem); | ||
| 47 | 			r = 0; | ||
| 48 | 			sa.sa_handler = SIG_IGN; | ||
| 49 | 			__libc_sigaction(SIGSYNCCALL, &sa, 0); | ||
| 50 | 		} | ||
| 51 | 		sem_destroy(&barrier_sem); | ||
| 52 | 		__tl_unlock(); | ||
| 53 | 		__restore_sigs(&set); | ||
| 54 | 	} | ||
| 55 | 	return __syscall_ret(r); | ||
| 56 | } | ||
| 57 | |||
| 58 | void __membarrier_init(void) | ||
| 59 | { | ||
| 60 | 	/* If membarrier is linked, attempt to pre-register to be able to use | ||
| 61 | 	 * the private expedited command before the process becomes multi- | ||
| 62 | 	 * threaded, since registering later has bad, potentially unbounded | ||
| 63 | 	 * latency. This syscall should be essentially free, and it's arguably | ||
| 64 | 	 * a mistake in the API design that registration was even required. | ||
| 65 | 	 * For other commands, registration may impose some cost, so it's left | ||
| 66 | 	 * to the application to do so if desired. Unfortunately this means | ||
| 67 | 	 * library code initialized after the process becomes multi-threaded | ||
| 68 | 	 * cannot use these features without accepting registration latency. */ | ||
| 69 | 	__syscall(SYS_membarrier, MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED, 0); | ||
| 70 | } | ||
| 71 | |||
| 72 | weak_alias(__membarrier, membarrier); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/memfd_create.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE 1 | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int memfd_create(const char *name, unsigned flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_memfd_create, name, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/mlock2.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #define _GNU_SOURCE 1 | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int mlock2(const void *addr, size_t len, unsigned flags) | ||
| 6 | { | ||
| 7 | 	if (flags == 0) | ||
| 8 | 		return mlock(addr, len); | ||
| 9 | 	return syscall(SYS_mlock2, addr, len, flags); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/module.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | int init_module(void *a, unsigned long b, const char *c) | ||
| 4 | { | ||
| 5 | 	return syscall(SYS_init_module, a, b, c); | ||
| 6 | } | ||
| 7 | |||
| 8 | int delete_module(const char *a, unsigned b) | ||
| 9 | { | ||
| 10 | 	return syscall(SYS_delete_module, a, b); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/mount.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <sys/mount.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mount(const char *special, const char *dir, const char *fstype, unsigned long flags, const void *data) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_mount, special, dir, fstype, flags, data); | ||
| 7 | } | ||
| 8 | |||
| 9 | int umount(const char *special) | ||
| 10 | { | ||
| 11 | 	return syscall(SYS_umount2, special, 0); | ||
| 12 | } | ||
| 13 | |||
| 14 | int umount2(const char *special, int flags) | ||
| 15 | { | ||
| 16 | 	return syscall(SYS_umount2, special, flags); | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/name_to_handle_at.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int name_to_handle_at(int dirfd, const char *pathname, | ||
| 6 | 	struct file_handle *handle, int *mount_id, int flags) | ||
| 7 | { | ||
| 8 | 	return syscall(SYS_name_to_handle_at, dirfd, | ||
| 9 | 		pathname, handle, mount_id, flags); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/open_by_handle_at.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int open_by_handle_at(int mount_fd, struct file_handle *handle, int flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_open_by_handle_at, mount_fd, handle, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/personality.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <sys/personality.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #ifdef SYS_personality | ||
| 4 | int personality(unsigned long persona) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_personality, persona); | ||
| 7 | } | ||
| 8 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/linux/pivot_root.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "syscall.h" | ||
| 2 | |||
| 3 | int pivot_root(const char *new, const char *old) | ||
| 4 | { | ||
| 5 | 	return syscall(SYS_pivot_root, new, old); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/ppoll.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <poll.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 8 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 9 | |||
| 10 | int ppoll(struct pollfd *fds, nfds_t n, const struct timespec *to, const sigset_t *mask) | ||
| 11 | { | ||
| 12 | 	time_t s = to ? to->tv_sec : 0; | ||
| 13 | 	long ns = to ? to->tv_nsec : 0; | ||
| 14 | #ifdef SYS_ppoll_time64 | ||
| 15 | 	int r = -ENOSYS; | ||
| 16 | 	if (SYS_ppoll == SYS_ppoll_time64 || !IS32BIT(s)) | ||
| 17 | 		r = __syscall_cp(SYS_ppoll_time64, fds, n, | ||
| 18 | 			to ? ((long long[]){s, ns}) : 0, | ||
| 19 | 			mask, _NSIG/8); | ||
| 20 | 	if (SYS_ppoll == SYS_ppoll_time64 || r != -ENOSYS) | ||
| 21 | 		return __syscall_ret(r); | ||
| 22 | 	s = CLAMP(s); | ||
| 23 | #endif | ||
| 24 | 	return syscall_cp(SYS_ppoll, fds, n, | ||
| 25 | 		to ? ((long[]){s, ns}) : 0, mask, _NSIG/8); | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/prctl.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <sys/prctl.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int prctl(int op, ...) | ||
| 6 | { | ||
| 7 | 	unsigned long x[4]; | ||
| 8 | 	int i; | ||
| 9 | 	va_list ap; | ||
| 10 | 	va_start(ap, op); | ||
| 11 | 	for (i=0; i<4; i++) x[i] = va_arg(ap, unsigned long); | ||
| 12 | 	va_end(ap); | ||
| 13 | 	return syscall(SYS_prctl, op, x[0], x[1], x[2], x[3]); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/prlimit.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/resource.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0) | ||
| 6 | |||
| 7 | int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlimit *old_limit) | ||
| 8 | { | ||
| 9 | 	struct rlimit tmp; | ||
| 10 | 	int r; | ||
| 11 | 	if (new_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) { | ||
| 12 | 		tmp = *new_limit; | ||
| 13 | 		FIX(tmp.rlim_cur); | ||
| 14 | 		FIX(tmp.rlim_max); | ||
| 15 | 		new_limit = &tmp; | ||
| 16 | 	} | ||
| 17 | 	r = syscall(SYS_prlimit64, pid, resource, new_limit, old_limit); | ||
| 18 | 	if (!r && old_limit && SYSCALL_RLIM_INFINITY != RLIM_INFINITY) { | ||
| 19 | 		FIX(old_limit->rlim_cur); | ||
| 20 | 		FIX(old_limit->rlim_max); | ||
| 21 | 	} | ||
| 22 | 	return r; | ||
| 23 | } | ||
| 24 | |||
| 25 | #undef prlimit64 | ||
| 26 | weak_alias(prlimit, prlimit64); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/process_vm.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/uio.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t process_vm_writev(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_process_vm_writev, pid, lvec, liovcnt, rvec, riovcnt, flags); | ||
| 8 | } | ||
| 9 | |||
| 10 | ssize_t process_vm_readv(pid_t pid, const struct iovec *lvec, unsigned long liovcnt, const struct iovec *rvec, unsigned long riovcnt, unsigned long flags) | ||
| 11 | { | ||
| 12 | 	return syscall(SYS_process_vm_readv, pid, lvec, liovcnt, rvec, riovcnt, flags); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/ptrace.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <sys/ptrace.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | long ptrace(int req, ...) | ||
| 7 | { | ||
| 8 | 	va_list ap; | ||
| 9 | 	pid_t pid; | ||
| 10 | 	void *addr, *data, *addr2 = 0; | ||
| 11 | 	long ret, result; | ||
| 12 | |||
| 13 | 	va_start(ap, req); | ||
| 14 | 	pid = va_arg(ap, pid_t); | ||
| 15 | 	addr = va_arg(ap, void *); | ||
| 16 | 	data = va_arg(ap, void *); | ||
| 17 | 	/* PTRACE_{READ,WRITE}{DATA,TEXT} (16...19) are specific to SPARC. */ | ||
| 18 | #ifdef PTRACE_READDATA | ||
| 19 | 	if ((unsigned)req - PTRACE_READDATA < 4) | ||
| 20 | 		addr2 = va_arg(ap, void *); | ||
| 21 | #endif | ||
| 22 | 	va_end(ap); | ||
| 23 | |||
| 24 | 	if (req-1U < 3) data = &result; | ||
| 25 | 	ret = syscall(SYS_ptrace, req, pid, addr, data, addr2); | ||
| 26 | |||
| 27 | 	if (ret < 0 || req-1U >= 3) return ret; | ||
| 28 | 	return result; | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/quotactl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/quota.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int quotactl(int cmd, const char *special, int id, char *addr) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_quotactl, cmd, special, id, addr); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/readahead.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t readahead(int fd, off_t pos, size_t len) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_readahead, fd, __SYSCALL_LL_O(pos), len); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/reboot.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/reboot.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int reboot(int type) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_reboot, 0xfee1dead, 672274793, type); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/remap_file_pages.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int remap_file_pages(void *addr, size_t size, int prot, size_t pgoff, int flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_remap_file_pages, addr, size, prot, pgoff, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/sbrk.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | void *sbrk(intptr_t inc) | ||
| 8 | { | ||
| 9 | 	if (inc) return (void *)__syscall_ret(-ENOMEM); | ||
| 10 | 	return (void *)__syscall(SYS_brk, 0); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/sendfile.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <sys/sendfile.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t sendfile(int out_fd, int in_fd, off_t *ofs, size_t count) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_sendfile, out_fd, in_fd, ofs, count); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(sendfile, sendfile64); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/setfsgid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/fsuid.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int setfsgid(gid_t gid) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_setfsgid, gid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/setfsuid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/fsuid.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int setfsuid(uid_t uid) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_setfsuid, uid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/setgroups.c created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "libc.h" | ||
| 6 | |||
| 7 | struct ctx { | ||
| 8 | 	size_t count; | ||
| 9 | 	const gid_t *list; | ||
| 10 | 	int ret; | ||
| 11 | }; | ||
| 12 | |||
| 13 | static void do_setgroups(void *p) | ||
| 14 | { | ||
| 15 | 	struct ctx *c = p; | ||
| 16 | 	if (c->ret<0) return; | ||
| 17 | 	int ret = __syscall(SYS_setgroups, c->count, c->list); | ||
| 18 | 	if (ret && !c->ret) { | ||
| 19 | 		/* If one thread fails to set groups after another has already | ||
| 20 | 		 * succeeded, forcibly killing the process is the only safe | ||
| 21 | 		 * thing to do. State is inconsistent and dangerous. Use | ||
| 22 | 		 * SIGKILL because it is uncatchable. */ | ||
| 23 | 		__block_all_sigs(0); | ||
| 24 | 		__syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL); | ||
| 25 | 	} | ||
| 26 | 	c->ret = ret; | ||
| 27 | } | ||
| 28 | |||
| 29 | int setgroups(size_t count, const gid_t list[]) | ||
| 30 | { | ||
| 31 | 	/* ret is initially nonzero so that failure of the first thread does not | ||
| 32 | 	 * trigger the safety kill above. */ | ||
| 33 | 	struct ctx c = { .count = count, .list = list, .ret = 1 }; | ||
| 34 | 	__synccall(do_setgroups, &c); | ||
| 35 | 	return __syscall_ret(c.ret); | ||
| 36 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/sethostname.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int sethostname(const char *name, size_t len) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_sethostname, name, len); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/setns.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sched.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int setns(int fd, int nstype) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_setns, fd, nstype); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/settimeofday.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <time.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int settimeofday(const struct timeval *tv, const struct timezone *tz) | ||
| 8 | { | ||
| 9 | 	if (!tv) return 0; | ||
| 10 | 	if (tv->tv_usec >= 1000000ULL) return __syscall_ret(-EINVAL); | ||
| 11 | 	return clock_settime(CLOCK_REALTIME, &((struct timespec){ | ||
| 12 | 		.tv_sec = tv->tv_sec, .tv_nsec = tv->tv_usec * 1000})); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/signalfd.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <sys/signalfd.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int signalfd(int fd, const sigset_t *sigs, int flags) | ||
| 8 | { | ||
| 9 | 	int ret = __syscall(SYS_signalfd4, fd, sigs, _NSIG/8, flags); | ||
| 10 | #ifdef SYS_signalfd | ||
| 11 | 	if (ret != -ENOSYS) return __syscall_ret(ret); | ||
| 12 | 	ret = __syscall(SYS_signalfd, fd, sigs, _NSIG/8); | ||
| 13 | 	if (ret >= 0) { | ||
| 14 | 		if (flags & SFD_CLOEXEC) | ||
| 15 | 			__syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); | ||
| 16 | 		if (flags & SFD_NONBLOCK) | ||
| 17 | 			__syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK); | ||
| 18 | 	} | ||
| 19 | #endif | ||
| 20 | 	return __syscall_ret(ret); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/splice.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t splice(int fd_in, off_t *off_in, int fd_out, off_t *off_out, size_t len, unsigned flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_splice, fd_in, off_in, fd_out, off_out, len, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/stime.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <time.h> | ||
| 3 | #include <sys/time.h> | ||
| 4 | |||
| 5 | int stime(const time_t *t) | ||
| 6 | { | ||
| 7 | 	struct timeval tv = { .tv_sec = *t, .tv_usec = 0 }; | ||
| 8 | 	return settimeofday(&tv, (void *)0); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/swap.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/swap.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int swapon(const char *path, int flags) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_swapon, path, flags); | ||
| 7 | } | ||
| 8 | |||
| 9 | int swapoff(const char *path) | ||
| 10 | { | ||
| 11 | 	return syscall(SYS_swapoff, path); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/sync_file_range.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int sync_file_range(int fd, off_t pos, off_t len, unsigned flags) | ||
| 7 | { | ||
| 8 | #if defined(SYS_sync_file_range2) | ||
| 9 | 	return syscall(SYS_sync_file_range2, fd, flags, | ||
| 10 | 		__SYSCALL_LL_E(pos), __SYSCALL_LL_E(len)); | ||
| 11 | #elif defined(SYS_sync_file_range) | ||
| 12 | 	return syscall(SYS_sync_file_range, fd, | ||
| 13 | 		__SYSCALL_LL_O(pos), __SYSCALL_LL_E(len), flags); | ||
| 14 | #else | ||
| 15 | 	return __syscall_ret(-ENOSYS); | ||
| 16 | #endif | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/syncfs.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int syncfs(int fd) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_syncfs, fd); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/sysinfo.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <sys/sysinfo.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int __lsysinfo(struct sysinfo *info) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_sysinfo, info); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__lsysinfo, sysinfo); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/tee.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t tee(int src, int dest, size_t len, unsigned flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_tee, src, dest, len, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/timerfd.c created+59| ... | @@ -0,0 +1,59 @@ | ||
| 1 | #include <sys/timerfd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | |||
| 7 | int timerfd_create(int clockid, int flags) | ||
| 8 | { | ||
| 9 | 	return syscall(SYS_timerfd_create, clockid, flags); | ||
| 10 | } | ||
| 11 | |||
| 12 | int timerfd_settime(int fd, int flags, const struct itimerspec *new, struct itimerspec *old) | ||
| 13 | { | ||
| 14 | #ifdef SYS_timerfd_settime64 | ||
| 15 | 	time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec; | ||
| 16 | 	long ins = new->it_interval.tv_nsec, vns = new->it_value.tv_nsec; | ||
| 17 | 	int r = -ENOSYS; | ||
| 18 | 	if (SYS_timerfd_settime == SYS_timerfd_settime64 | ||
| 19 | 	 || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old)) | ||
| 20 | 		r = __syscall(SYS_timerfd_settime64, fd, flags, | ||
| 21 | 			((long long[]){is, ins, vs, vns}), old); | ||
| 22 | 	if (SYS_timerfd_settime == SYS_timerfd_settime64 || r!=-ENOSYS) | ||
| 23 | 		return __syscall_ret(r); | ||
| 24 | 	if (!IS32BIT(is) || !IS32BIT(vs)) | ||
| 25 | 		return __syscall_ret(-ENOTSUP); | ||
| 26 | 	long old32[4]; | ||
| 27 | 	r = __syscall(SYS_timerfd_settime, fd, flags, | ||
| 28 | 		((long[]){is, ins, vs, vns}), old32); | ||
| 29 | 	if (!r && old) { | ||
| 30 | 		old->it_interval.tv_sec = old32[0]; | ||
| 31 | 		old->it_interval.tv_nsec = old32[1]; | ||
| 32 | 		old->it_value.tv_sec = old32[2]; | ||
| 33 | 		old->it_value.tv_nsec = old32[3]; | ||
| 34 | 	} | ||
| 35 | 	return __syscall_ret(r); | ||
| 36 | #endif | ||
| 37 | 	return syscall(SYS_timerfd_settime, fd, flags, new, old); | ||
| 38 | } | ||
| 39 | |||
| 40 | int timerfd_gettime(int fd, struct itimerspec *cur) | ||
| 41 | { | ||
| 42 | #ifdef SYS_timerfd_gettime64 | ||
| 43 | 	int r = -ENOSYS; | ||
| 44 | 	if (sizeof(time_t) > 4) | ||
| 45 | 		r = __syscall(SYS_timerfd_gettime64, fd, cur); | ||
| 46 | 	if (SYS_timerfd_gettime == SYS_timerfd_gettime64 || r!=-ENOSYS) | ||
| 47 | 		return __syscall_ret(r); | ||
| 48 | 	long cur32[4]; | ||
| 49 | 	r = __syscall(SYS_timerfd_gettime, fd, cur32); | ||
| 50 | 	if (!r) { | ||
| 51 | 		cur->it_interval.tv_sec = cur32[0]; | ||
| 52 | 		cur->it_interval.tv_nsec = cur32[1]; | ||
| 53 | 		cur->it_value.tv_sec = cur32[2]; | ||
| 54 | 		cur->it_value.tv_nsec = cur32[3]; | ||
| 55 | 	} | ||
| 56 | 	return __syscall_ret(r); | ||
| 57 | #endif | ||
| 58 | 	return syscall(SYS_timerfd_gettime, fd, cur); | ||
| 59 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/unshare.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sched.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int unshare(int flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_unshare, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/utimes.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <sys/time.h> | ||
| 2 | #include "fcntl.h" | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int utimes(const char *path, const struct timeval times[2]) | ||
| 6 | { | ||
| 7 | 	return __futimesat(AT_FDCWD, path, times); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/vhangup.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int vhangup(void) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_vhangup); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/vmsplice.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t vmsplice(int fd, const struct iovec *iov, size_t cnt, unsigned flags) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_vmsplice, fd, iov, cnt, flags); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/wait3.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/wait.h> | ||
| 3 | #include <sys/resource.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | pid_t wait3(int *status, int options, struct rusage *usage) | ||
| 7 | { | ||
| 8 | 	return wait4(-1, status, options, usage); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/wait4.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/wait.h> | ||
| 3 | #include <sys/resource.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | pid_t wait4(pid_t pid, int *status, int options, struct rusage *ru) | ||
| 9 | { | ||
| 10 | 	int r; | ||
| 11 | #ifdef SYS_wait4_time64 | ||
| 12 | 	if (ru) { | ||
| 13 | 		long long kru64[18]; | ||
| 14 | 		r = __syscall(SYS_wait4_time64, pid, status, options, kru64); | ||
| 15 | 		if (!r) { | ||
| 16 | 			ru->ru_utime = (struct timeval) | ||
| 17 | 				{ .tv_sec = kru64[0], .tv_usec = kru64[1] }; | ||
| 18 | 			ru->ru_stime = (struct timeval) | ||
| 19 | 				{ .tv_sec = kru64[2], .tv_usec = kru64[3] }; | ||
| 20 | 			char *slots = (char *)&ru->ru_maxrss; | ||
| 21 | 			for (int i=0; i<14; i++) | ||
| 22 | 				*(long *)(slots + i*sizeof(long)) = kru64[4+i]; | ||
| 23 | 		} | ||
| 24 | 		if (SYS_wait4_time64 == SYS_wait4 || r != -ENOSYS) | ||
| 25 | 			return __syscall_ret(r); | ||
| 26 | 	} | ||
| 27 | #endif | ||
| 28 | 	char *dest = ru ? (char *)&ru->ru_maxrss - 4*sizeof(long) : 0; | ||
| 29 | 	r = __syscall(SYS_wait4, pid, status, options, dest); | ||
| 30 | 	if (r>0 && ru && sizeof(time_t) > sizeof(long)) { | ||
| 31 | 		long kru[4]; | ||
| 32 | 		memcpy(kru, dest, 4*sizeof(long)); | ||
| 33 | 		ru->ru_utime = (struct timeval) | ||
| 34 | 			{ .tv_sec = kru[0], .tv_usec = kru[1] }; | ||
| 35 | 		ru->ru_stime = (struct timeval) | ||
| 36 | 			{ .tv_sec = kru[2], .tv_usec = kru[3] }; | ||
| 37 | 	} | ||
| 38 | 	return __syscall_ret(r); | ||
| 39 | } | ||
lib/libc/wasi/libc-top-half/musl/src/linux/x32/sysinfo.c created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #include <sys/sysinfo.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | #define klong long long | ||
| 5 | #define kulong unsigned long long | ||
| 6 | |||
| 7 | struct kernel_sysinfo { | ||
| 8 | 	klong uptime; | ||
| 9 | 	kulong loads[3]; | ||
| 10 | 	kulong totalram; | ||
| 11 | 	kulong freeram; | ||
| 12 | 	kulong sharedram; | ||
| 13 | 	kulong bufferram; | ||
| 14 | 	kulong totalswap; | ||
| 15 | 	kulong freeswap; | ||
| 16 | 	short procs; | ||
| 17 | 	short pad; | ||
| 18 | 	kulong totalhigh; | ||
| 19 | 	kulong freehigh; | ||
| 20 | 	unsigned mem_unit; | ||
| 21 | }; | ||
| 22 | |||
| 23 | int __lsysinfo(struct sysinfo *info) | ||
| 24 | { | ||
| 25 | 	struct kernel_sysinfo tmp; | ||
| 26 | 	int ret = syscall(SYS_sysinfo, &tmp); | ||
| 27 | 	if(ret == -1) return ret; | ||
| 28 | 	info->uptime = tmp.uptime; | ||
| 29 | 	info->loads[0] = tmp.loads[0]; | ||
| 30 | 	info->loads[1] = tmp.loads[1]; | ||
| 31 | 	info->loads[2] = tmp.loads[2]; | ||
| 32 | 	kulong shifts; | ||
| 33 | 	kulong max = tmp.totalram | tmp.totalswap; | ||
| 34 | 	__asm__("bsr %1,%0" : "=r"(shifts) : "r"(max)); | ||
| 35 | 	shifts = shifts >= 32 ? shifts - 31 : 0; | ||
| 36 | 	info->totalram = tmp.totalram >> shifts; | ||
| 37 | 	info->freeram = tmp.freeram >> shifts; | ||
| 38 | 	info->sharedram = tmp.sharedram >> shifts; | ||
| 39 | 	info->bufferram = tmp.bufferram >> shifts; | ||
| 40 | 	info->totalswap = tmp.totalswap >> shifts; | ||
| 41 | 	info->freeswap = tmp.freeswap >> shifts; | ||
| 42 | 	info->procs = tmp.procs ; | ||
| 43 | 	info->totalhigh = tmp.totalhigh >> shifts; | ||
| 44 | 	info->freehigh = tmp.freehigh >> shifts; | ||
| 45 | 	info->mem_unit = (tmp.mem_unit ? tmp.mem_unit : 1) << shifts; | ||
| 46 | 	return ret; | ||
| 47 | } | ||
| 48 | |||
| 49 | weak_alias(__lsysinfo, sysinfo); | ||
lib/libc/wasi/libc-top-half/musl/src/linux/xattr.c created+62| ... | @@ -0,0 +1,62 @@ | ||
| 1 | #include <sys/xattr.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t getxattr(const char *path, const char *name, void *value, size_t size) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_getxattr, path, name, value, size); | ||
| 7 | } | ||
| 8 | |||
| 9 | ssize_t lgetxattr(const char *path, const char *name, void *value, size_t size) | ||
| 10 | { | ||
| 11 | 	return syscall(SYS_lgetxattr, path, name, value, size); | ||
| 12 | } | ||
| 13 | |||
| 14 | ssize_t fgetxattr(int filedes, const char *name, void *value, size_t size) | ||
| 15 | { | ||
| 16 | 	return syscall(SYS_fgetxattr, filedes, name, value, size); | ||
| 17 | } | ||
| 18 | |||
| 19 | ssize_t listxattr(const char *path, char *list, size_t size) | ||
| 20 | { | ||
| 21 | 	return syscall(SYS_listxattr, path, list, size); | ||
| 22 | } | ||
| 23 | |||
| 24 | ssize_t llistxattr(const char *path, char *list, size_t size) | ||
| 25 | { | ||
| 26 | 	return syscall(SYS_llistxattr, path, list, size); | ||
| 27 | } | ||
| 28 | |||
| 29 | ssize_t flistxattr(int filedes, char *list, size_t size) | ||
| 30 | { | ||
| 31 | 	return syscall(SYS_flistxattr, filedes, list, size); | ||
| 32 | } | ||
| 33 | |||
| 34 | int setxattr(const char *path, const char *name, const void *value, size_t size, int flags) | ||
| 35 | { | ||
| 36 | 	return syscall(SYS_setxattr, path, name, value, size, flags); | ||
| 37 | } | ||
| 38 | |||
| 39 | int lsetxattr(const char *path, const char *name, const void *value, size_t size, int flags) | ||
| 40 | { | ||
| 41 | 	return syscall(SYS_lsetxattr, path, name, value, size, flags); | ||
| 42 | } | ||
| 43 | |||
| 44 | int fsetxattr(int filedes, const char *name, const void *value, size_t size, int flags) | ||
| 45 | { | ||
| 46 | 	return syscall(SYS_fsetxattr, filedes, name, value, size, flags); | ||
| 47 | } | ||
| 48 | |||
| 49 | int removexattr(const char *path, const char *name) | ||
| 50 | { | ||
| 51 | 	return syscall(SYS_removexattr, path, name); | ||
| 52 | } | ||
| 53 | |||
| 54 | int lremovexattr(const char *path, const char *name) | ||
| 55 | { | ||
| 56 | 	return syscall(SYS_lremovexattr, path, name); | ||
| 57 | } | ||
| 58 | |||
| 59 | int fremovexattr(int fd, const char *name) | ||
| 60 | { | ||
| 61 | 	return syscall(SYS_fremovexattr, fd, name); | ||
| 62 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/__lctrans.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <locale.h> | ||
| 2 | #include "locale_impl.h" | ||
| 3 | |||
| 4 | static const char *dummy(const char *msg, const struct __locale_map *lm) | ||
| 5 | { | ||
| 6 | 	return msg; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(dummy, __lctrans_impl); | ||
| 10 | |||
| 11 | const char *__lctrans(const char *msg, const struct __locale_map *lm) | ||
| 12 | { | ||
| 13 | 	return __lctrans_impl(msg, lm); | ||
| 14 | } | ||
| 15 | |||
| 16 | const char *__lctrans_cur(const char *msg) | ||
| 17 | { | ||
| 18 | 	return __lctrans_impl(msg, CURRENT_LOCALE->cat[LC_MESSAGES]); | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/__mo_lookup.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | static inline uint32_t swapc(uint32_t x, int c) | ||
| 5 | { | ||
| 6 | 	return c ? x>>24 | x>>8&0xff00 | x<<8&0xff0000 | x<<24 : x; | ||
| 7 | } | ||
| 8 | |||
| 9 | const char *__mo_lookup(const void *p, size_t size, const char *s) | ||
| 10 | { | ||
| 11 | 	const uint32_t *mo = p; | ||
| 12 | 	int sw = *mo - 0x950412de; | ||
| 13 | 	uint32_t b = 0, n = swapc(mo[2], sw); | ||
| 14 | 	uint32_t o = swapc(mo[3], sw); | ||
| 15 | 	uint32_t t = swapc(mo[4], sw); | ||
| 16 | 	if (n>=size/4 || o>=size-4*n || t>=size-4*n || ((o|t)%4)) | ||
| 17 | 		return 0; | ||
| 18 | 	o/=4; | ||
| 19 | 	t/=4; | ||
| 20 | 	for (;;) { | ||
| 21 | 		uint32_t ol = swapc(mo[o+2*(b+n/2)], sw); | ||
| 22 | 		uint32_t os = swapc(mo[o+2*(b+n/2)+1], sw); | ||
| 23 | 		if (os >= size || ol >= size-os || ((char *)p)[os+ol]) | ||
| 24 | 			return 0; | ||
| 25 | 		int sign = strcmp(s, (char *)p + os); | ||
| 26 | 		if (!sign) { | ||
| 27 | 			uint32_t tl = swapc(mo[t+2*(b+n/2)], sw); | ||
| 28 | 			uint32_t ts = swapc(mo[t+2*(b+n/2)+1], sw); | ||
| 29 | 			if (ts >= size || tl >= size-ts || ((char *)p)[ts+tl]) | ||
| 30 | 				return 0; | ||
| 31 | 			return (char *)p + ts; | ||
| 32 | 		} | ||
| 33 | 		else if (n == 1) return 0; | ||
| 34 | 		else if (sign < 0) | ||
| 35 | 			n /= 2; | ||
| 36 | 		else { | ||
| 37 | 			b += n/2; | ||
| 38 | 			n -= n/2; | ||
| 39 | 		} | ||
| 40 | 	} | ||
| 41 | 	return 0; | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/big5.h created+1085| ... | @@ -0,0 +1,1085 @@ | ||
| 1 | 12288,65292,12289,12290,65294,8231,65307,65306,65311,65281,65072,8230,8229, | ||
| 2 | 65104,65105,65106,183,65108,65109,65110,65111,65372,8211,65073,8212,65075, | ||
| 3 | 9588,65076,65103,65288,65289,65077,65078,65371,65373,65079,65080,12308,12309, | ||
| 4 | 65081,65082,12304,12305,65083,65084,12298,12299,65085,65086,12296,12297,65087, | ||
| 5 | 65088,12300,12301,65089,65090,12302,12303,65091,65092,65113,65114,65115,65116, | ||
| 6 | 65117,65118,8216,8217,8220,8221,12317,12318,8245,8242,65283,65286,65290,8251, | ||
| 7 | 167,12291,9675,9679,9651,9650,9678,9734,9733,9671,9670,9633,9632,9661,9660, | ||
| 8 | 12963,8453,175,65507,65343,717,65097,65098,65101,65102,65099,65100,65119, | ||
| 9 | 65120,65121,65291,65293,215,247,177,8730,65308,65310,65309,8806,8807,8800, | ||
| 10 | 8734,8786,8801,65122,65123,65124,65125,65126,65374,8745,8746,8869,8736,8735, | ||
| 11 | 8895,13266,13265,8747,8750,8757,8756,9792,9794,8853,8857,8593,8595,8592,8594, | ||
| 12 | 8598,8599,8601,8600,8741,8739,65295,65340,8725,65128,65284,65509,12306,65504, | ||
| 13 | 65505,65285,65312,8451,8457,65129,65130,65131,13269,13212,13213,13214,13262, | ||
| 14 | 13217,13198,13199,13252,176,20825,20827,20830,20829,20833,20835,21991,29929, | ||
| 15 | 31950,9601,9602,9603,9604,9605,9606,9607,9608,9615,9614,9613,9612,9611,9610, | ||
| 16 | 9609,9532,9524,9516,9508,9500,9620,9472,9474,9621,9484,9488,9492,9496,9581, | ||
| 17 | 9582,9584,9583,9552,9566,9578,9569,9698,9699,9701,9700,9585,9586,9587,65296, | ||
| 18 | 65297,65298,65299,65300,65301,65302,65303,65304,65305,8544,8545,8546,8547, | ||
| 19 | 8548,8549,8550,8551,8552,8553,12321, | ||
| 20 | 12322,12323,12324,12325,12326,12327,12328,12329,21313,21316,21317,65313,65314, | ||
| 21 | 65315,65316,65317,65318,65319,65320,65321,65322,65323,65324,65325,65326,65327, | ||
| 22 | 65328,65329,65330,65331,65332,65333,65334,65335,65336,65337,65338,65345,65346, | ||
| 23 | 65347,65348,65349,65350,65351,65352,65353,65354,65355,65356,65357,65358,65359, | ||
| 24 | 65360,65361,65362,65363,65364,65365,65366,65367,65368,65369,65370,913,914,915, | ||
| 25 | 916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935, | ||
| 26 | 936,937,945,946,947,948,949,950,951,952,953,954,955,956,957,958,959,960,961, | ||
| 27 | 963,964,965,966,967,968,969,12549,12550,12551,12552,12553,12554,12555,12556, | ||
| 28 | 12557,12558,12559,12560,12561,12562,12563,12564,12565,12566,12567,12568,12569, | ||
| 29 | 12570,12571,12572,12573,12574,12575,12576,12577,12578,12579,12580,12581,12582, | ||
| 30 | 12583,12584,12585,729,713,714,711,715,9216,9217,9218,9219,9220,9221,9222,9223, | ||
| 31 | 9224,9225,9226,9227,9228,9229,9230,9231,9232,9233,9234,9235,9236,9237,9238, | ||
| 32 | 9239,9240,9241,9242,9243,9244,9245,9246,9247,9249,8364,0,0,0,0,0,0,0,0,0,0,0, | ||
| 33 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,19968,20057,19969,19971,20035,20061,20102, | ||
| 34 | 20108,20154,20799,20837,20843,20960,20992,20993,21147,21269,21313,21340,21448, | ||
| 35 | 19977,19979,19976,19978,20011,20024,20961,20037,20040,20063,20062,20110,20129, | ||
| 36 | 20800,20995,21242,21315,21449,21475,22303, | ||
| 37 | 22763,22805,22823,22899,23376,23377,23379,23544,23567,23586,23608,23665,24029, | ||
| 38 | 24037,24049,24050,24051,24062,24178,24318,24331,24339,25165,19985,19984,19981, | ||
| 39 | 20013,20016,20025,20043,23609,20104,20113,20117,20114,20116,20130,20161,20160, | ||
| 40 | 20163,20166,20167,20173,20170,20171,20164,20803,20801,20839,20845,20846,20844, | ||
| 41 | 20887,20982,20998,20999,21000,21243,21246,21247,21270,21305,21320,21319,21317, | ||
| 42 | 21342,21380,21451,21450,21453,22764,22825,22827,22826,22829,23380,23569,23588, | ||
| 43 | 23610,23663,24052,24187,24319,24340,24341,24515,25096,25142,25163,25166,25903, | ||
| 44 | 25991,26007,26020,26041,26085,26352,26376,26408,27424,27490,27513,27595,27604, | ||
| 45 | 27611,27663,27700,28779,29226,29238,29243,29255,29273,29275,29356,29579,19993, | ||
| 46 | 19990,19989,19988,19992,20027,20045,20047,20046,20197,20184,20180,20181,20182, | ||
| 47 | 20183,20195,20196,20185,20190,20805,20804,20873,20874,20908,20985,20986,20984, | ||
| 48 | 21002,21152,21151,21253,21254,21271,21277,20191,21322,21321,21345,21344,21359, | ||
| 49 | 21358,21435,21487,21476,21491,21484,21486,21481,21480,21500,21496,21493,21483, | ||
| 50 | 21478,21482,21490,21489,21488,21477,21485,21499,22235,22234,22806,22830,22833, | ||
| 51 | 22900,22902,23381,23427,23612,24040,24039,24038,24066,24067,24179,24188,24321, | ||
| 52 | 24344,24343,24517,25098,25171,25172,25170,25169,26021,26086,26414,26412,26410, | ||
| 53 | 26411,26413,27491,27597,27665,27664,27704,27713,27712,27710,29359,29572,29577, | ||
| 54 | 29916,29926,29976,29983,29992,29993,30000,30001,30002,30003,30091,30333,30382, | ||
| 55 | 30399,30446,30683,30690,30707,31034,31166,31348,31435,19998,19999,20050,20051, | ||
| 56 | 20073,20121,20132,20134,20133,20223,20233,20249,20234, | ||
| 57 | 20245,20237,20240,20241,20239,20210,20214,20219,20208,20211,20221,20225,20235, | ||
| 58 | 20809,20807,20806,20808,20840,20849,20877,20912,21015,21009,21010,21006,21014, | ||
| 59 | 21155,21256,21281,21280,21360,21361,21513,21519,21516,21514,21520,21505,21515, | ||
| 60 | 21508,21521,21517,21512,21507,21518,21510,21522,22240,22238,22237,22323,22320, | ||
| 61 | 22312,22317,22316,22319,22313,22809,22810,22839,22840,22916,22904,22915,22909, | ||
| 62 | 22905,22914,22913,23383,23384,23431,23432,23429,23433,23546,23574,23673,24030, | ||
| 63 | 24070,24182,24180,24335,24347,24537,24534,25102,25100,25101,25104,25187,25179, | ||
| 64 | 25176,25910,26089,26088,26092,26093,26354,26355,26377,26429,26420,26417,26421, | ||
| 65 | 27425,27492,27515,27670,27741,27735,27737,27743,27744,27728,27733,27745,27739, | ||
| 66 | 27725,27726,28784,29279,29277,30334,31481,31859,31992,32566,32650,32701,32769, | ||
| 67 | 32771,32780,32786,32819,32895,32905,32907,32908,33251,33258,33267,33276,33292, | ||
| 68 | 33307,33311,33390,33394,33406,34411,34880,34892,34915,35199,38433,20018,20136, | ||
| 69 | 20301,20303,20295,20311,20318,20276,20315,20309,20272,20304,20305,20285,20282, | ||
| 70 | 20280,20291,20308,20284,20294,20323,20316,20320,20271,20302,20278,20313,20317, | ||
| 71 | 20296,20314,20812,20811,20813,20853,20918,20919,21029,21028,21033,21034,21032, | ||
| 72 | 21163,21161,21162,21164,21283,21363,21365,21533,21549,21534,21566,21542,21582, | ||
| 73 | 21543,21574,21571,21555,21576,21570,21531,21545,21578,21561,21563,21560,21550, | ||
| 74 | 21557,21558,21536,21564,21568,21553,21547,21535,21548,22250,22256,22244,22251, | ||
| 75 | 22346,22353,22336,22349,22343,22350,22334,22352,22351,22331,22767,22846,22941, | ||
| 76 | 22930,22952,22942,22947,22937,22934,22925,22948,22931, | ||
| 77 | 22922,22949,23389,23388,23386,23387,23436,23435,23439,23596,23616,23617,23615, | ||
| 78 | 23614,23696,23697,23700,23692,24043,24076,24207,24199,24202,24311,24324,24351, | ||
| 79 | 24420,24418,24439,24441,24536,24524,24535,24525,24561,24555,24568,24554,25106, | ||
| 80 | 25105,25220,25239,25238,25216,25206,25225,25197,25226,25212,25214,25209,25203, | ||
| 81 | 25234,25199,25240,25198,25237,25235,25233,25222,25913,25915,25912,26097,26356, | ||
| 82 | 26463,26446,26447,26448,26449,26460,26454,26462,26441,26438,26464,26451,26455, | ||
| 83 | 27493,27599,27714,27742,27801,27777,27784,27785,27781,27803,27754,27770,27792, | ||
| 84 | 27760,27788,27752,27798,27794,27773,27779,27762,27774,27764,27782,27766,27789, | ||
| 85 | 27796,27800,27778,28790,28796,28797,28792,29282,29281,29280,29380,29378,29590, | ||
| 86 | 29996,29995,30007,30008,30338,30447,30691,31169,31168,31167,31350,31995,32597, | ||
| 87 | 32918,32915,32925,32920,32923,32922,32946,33391,33426,33419,33421,35211,35282, | ||
| 88 | 35328,35895,35910,35925,35997,36196,36208,36275,36523,36554,36763,36784,36802, | ||
| 89 | 36806,36805,36804,24033,37009,37026,37034,37030,37027,37193,37318,37324,38450, | ||
| 90 | 38446,38449,38442,38444,20006,20054,20083,20107,20123,20126,20139,20140,20335, | ||
| 91 | 20381,20365,20339,20351,20332,20379,20363,20358,20355,20336,20341,20360,20329, | ||
| 92 | 20347,20374,20350,20367,20369,20346,20820,20818,20821,20841,20855,20854,20856, | ||
| 93 | 20925,20989,21051,21048,21047,21050,21040,21038,21046,21057,21182,21179,21330, | ||
| 94 | 21332,21331,21329,21350,21367,21368,21369,21462,21460,21463,21619,21621,21654, | ||
| 95 | 21624,21653,21632,21627,21623,21636,21650,21638,21628,21648,21617,21622,21644, | ||
| 96 | 21658,21602,21608,21643,21629,21646,22266,22403,22391, | ||
| 97 | 22378,22377,22369,22374,22372,22396,22812,22857,22855,22856,22852,22868,22974, | ||
| 98 | 22971,22996,22969,22958,22993,22982,22992,22989,22987,22995,22986,22959,22963, | ||
| 99 | 22994,22981,23391,23396,23395,23447,23450,23448,23452,23449,23451,23578,23624, | ||
| 100 | 23621,23622,23735,23713,23736,23721,23723,23729,23731,24088,24090,24086,24085, | ||
| 101 | 24091,24081,24184,24218,24215,24220,24213,24214,24310,24358,24359,24361,24448, | ||
| 102 | 24449,24447,24444,24541,24544,24573,24565,24575,24591,24596,24623,24629,24598, | ||
| 103 | 24618,24597,24609,24615,24617,24619,24603,25110,25109,25151,25150,25152,25215, | ||
| 104 | 25289,25292,25284,25279,25282,25273,25298,25307,25259,25299,25300,25291,25288, | ||
| 105 | 25256,25277,25276,25296,25305,25287,25293,25269,25306,25265,25304,25302,25303, | ||
| 106 | 25286,25260,25294,25918,26023,26044,26106,26132,26131,26124,26118,26114,26126, | ||
| 107 | 26112,26127,26133,26122,26119,26381,26379,26477,26507,26517,26481,26524,26483, | ||
| 108 | 26487,26503,26525,26519,26479,26480,26495,26505,26494,26512,26485,26522,26515, | ||
| 109 | 26492,26474,26482,27427,27494,27495,27519,27667,27675,27875,27880,27891,27825, | ||
| 110 | 27852,27877,27827,27837,27838,27836,27874,27819,27861,27859,27832,27844,27833, | ||
| 111 | 27841,27822,27863,27845,27889,27839,27835,27873,27867,27850,27820,27887,27868, | ||
| 112 | 27862,27872,28821,28814,28818,28810,28825,29228,29229,29240,29256,29287,29289, | ||
| 113 | 29376,29390,29401,29399,29392,29609,29608,29599,29611,29605,30013,30109,30105, | ||
| 114 | 30106,30340,30402,30450,30452,30693,30717,31038,31040,31041,31177,31176,31354, | ||
| 115 | 31353,31482,31998,32596,32652,32651,32773,32954,32933,32930,32945,32929,32939, | ||
| 116 | 32937,32948,32938,32943,33253,33278,33293,33459,33437, | ||
| 117 | 33433,33453,33469,33439,33465,33457,33452,33445,33455,33464,33443,33456,33470, | ||
| 118 | 33463,34382,34417,21021,34920,36555,36814,36820,36817,37045,37048,37041,37046, | ||
| 119 | 37319,37329,38263,38272,38428,38464,38463,38459,38468,38466,38585,38632,38738, | ||
| 120 | 38750,20127,20141,20142,20449,20405,20399,20415,20448,20433,20431,20445,20419, | ||
| 121 | 20406,20440,20447,20426,20439,20398,20432,20420,20418,20442,20430,20446,20407, | ||
| 122 | 20823,20882,20881,20896,21070,21059,21066,21069,21068,21067,21063,21191,21193, | ||
| 123 | 21187,21185,21261,21335,21371,21402,21467,21676,21696,21672,21710,21705,21688, | ||
| 124 | 21670,21683,21703,21698,21693,21674,21697,21700,21704,21679,21675,21681,21691, | ||
| 125 | 21673,21671,21695,22271,22402,22411,22432,22435,22434,22478,22446,22419,22869, | ||
| 126 | 22865,22863,22862,22864,23004,23000,23039,23011,23016,23043,23013,23018,23002, | ||
| 127 | 23014,23041,23035,23401,23459,23462,23460,23458,23461,23553,23630,23631,23629, | ||
| 128 | 23627,23769,23762,24055,24093,24101,24095,24189,24224,24230,24314,24328,24365, | ||
| 129 | 24421,24456,24453,24458,24459,24455,24460,24457,24594,24605,24608,24613,24590, | ||
| 130 | 24616,24653,24688,24680,24674,24646,24643,24684,24683,24682,24676,25153,25308, | ||
| 131 | 25366,25353,25340,25325,25345,25326,25341,25351,25329,25335,25327,25324,25342, | ||
| 132 | 25332,25361,25346,25919,25925,26027,26045,26082,26149,26157,26144,26151,26159, | ||
| 133 | 26143,26152,26161,26148,26359,26623,26579,26609,26580,26576,26604,26550,26543, | ||
| 134 | 26613,26601,26607,26564,26577,26548,26586,26597,26552,26575,26590,26611,26544, | ||
| 135 | 26585,26594,26589,26578,27498,27523,27526,27573,27602,27607,27679,27849,27915, | ||
| 136 | 27954,27946,27969,27941,27916,27953,27934,27927,27963, | ||
| 137 | 27965,27966,27958,27931,27893,27961,27943,27960,27945,27950,27957,27918,27947, | ||
| 138 | 28843,28858,28851,28844,28847,28845,28856,28846,28836,29232,29298,29295,29300, | ||
| 139 | 29417,29408,29409,29623,29642,29627,29618,29645,29632,29619,29978,29997,30031, | ||
| 140 | 30028,30030,30027,30123,30116,30117,30114,30115,30328,30342,30343,30344,30408, | ||
| 141 | 30406,30403,30405,30465,30457,30456,30473,30475,30462,30460,30471,30684,30722, | ||
| 142 | 30740,30732,30733,31046,31049,31048,31047,31161,31162,31185,31186,31179,31359, | ||
| 143 | 31361,31487,31485,31869,32002,32005,32000,32009,32007,32004,32006,32568,32654, | ||
| 144 | 32703,32772,32784,32781,32785,32822,32982,32997,32986,32963,32964,32972,32993, | ||
| 145 | 32987,32974,32990,32996,32989,33268,33314,33511,33539,33541,33507,33499,33510, | ||
| 146 | 33540,33509,33538,33545,33490,33495,33521,33537,33500,33492,33489,33502,33491, | ||
| 147 | 33503,33519,33542,34384,34425,34427,34426,34893,34923,35201,35284,35336,35330, | ||
| 148 | 35331,35998,36000,36212,36211,36276,36557,36556,36848,36838,36834,36842,36837, | ||
| 149 | 36845,36843,36836,36840,37066,37070,37057,37059,37195,37194,37325,38274,38480, | ||
| 150 | 38475,38476,38477,38754,38761,38859,38893,38899,38913,39080,39131,39135,39318, | ||
| 151 | 39321,20056,20147,20492,20493,20515,20463,20518,20517,20472,20521,20502,20486, | ||
| 152 | 20540,20511,20506,20498,20497,20474,20480,20500,20520,20465,20513,20491,20505, | ||
| 153 | 20504,20467,20462,20525,20522,20478,20523,20489,20860,20900,20901,20898,20941, | ||
| 154 | 20940,20934,20939,21078,21084,21076,21083,21085,21290,21375,21407,21405,21471, | ||
| 155 | 21736,21776,21761,21815,21756,21733,21746,21766,21754,21780,21737,21741,21729, | ||
| 156 | 21769,21742,21738,21734,21799,21767,21757,21775,22275, | ||
| 157 | 22276,22466,22484,22475,22467,22537,22799,22871,22872,22874,23057,23064,23068, | ||
| 158 | 23071,23067,23059,23020,23072,23075,23081,23077,23052,23049,23403,23640,23472, | ||
| 159 | 23475,23478,23476,23470,23477,23481,23480,23556,23633,23637,23632,23789,23805, | ||
| 160 | 23803,23786,23784,23792,23798,23809,23796,24046,24109,24107,24235,24237,24231, | ||
| 161 | 24369,24466,24465,24464,24665,24675,24677,24656,24661,24685,24681,24687,24708, | ||
| 162 | 24735,24730,24717,24724,24716,24709,24726,25159,25331,25352,25343,25422,25406, | ||
| 163 | 25391,25429,25410,25414,25423,25417,25402,25424,25405,25386,25387,25384,25421, | ||
| 164 | 25420,25928,25929,26009,26049,26053,26178,26185,26191,26179,26194,26188,26181, | ||
| 165 | 26177,26360,26388,26389,26391,26657,26680,26696,26694,26707,26681,26690,26708, | ||
| 166 | 26665,26803,26647,26700,26705,26685,26612,26704,26688,26684,26691,26666,26693, | ||
| 167 | 26643,26648,26689,27530,27529,27575,27683,27687,27688,27686,27684,27888,28010, | ||
| 168 | 28053,28040,28039,28006,28024,28023,27993,28051,28012,28041,28014,27994,28020, | ||
| 169 | 28009,28044,28042,28025,28037,28005,28052,28874,28888,28900,28889,28872,28879, | ||
| 170 | 29241,29305,29436,29433,29437,29432,29431,29574,29677,29705,29678,29664,29674, | ||
| 171 | 29662,30036,30045,30044,30042,30041,30142,30149,30151,30130,30131,30141,30140, | ||
| 172 | 30137,30146,30136,30347,30384,30410,30413,30414,30505,30495,30496,30504,30697, | ||
| 173 | 30768,30759,30776,30749,30772,30775,30757,30765,30752,30751,30770,31061,31056, | ||
| 174 | 31072,31071,31062,31070,31069,31063,31066,31204,31203,31207,31199,31206,31209, | ||
| 175 | 31192,31364,31368,31449,31494,31505,31881,32033,32023,32011,32010,32032,32034, | ||
| 176 | 32020,32016,32021,32026,32028,32013,32025,32027,32570, | ||
| 177 | 32607,32660,32709,32705,32774,32792,32789,32793,32791,32829,32831,33009,33026, | ||
| 178 | 33008,33029,33005,33012,33030,33016,33011,33032,33021,33034,33020,33007,33261, | ||
| 179 | 33260,33280,33296,33322,33323,33320,33324,33467,33579,33618,33620,33610,33592, | ||
| 180 | 33616,33609,33589,33588,33615,33586,33593,33590,33559,33600,33585,33576,33603, | ||
| 181 | 34388,34442,34474,34451,34468,34473,34444,34467,34460,34928,34935,34945,34946, | ||
| 182 | 34941,34937,35352,35344,35342,35340,35349,35338,35351,35347,35350,35343,35345, | ||
| 183 | 35912,35962,35961,36001,36002,36215,36524,36562,36564,36559,36785,36865,36870, | ||
| 184 | 36855,36864,36858,36852,36867,36861,36869,36856,37013,37089,37085,37090,37202, | ||
| 185 | 37197,37196,37336,37341,37335,37340,37337,38275,38498,38499,38497,38491,38493, | ||
| 186 | 38500,38488,38494,38587,39138,39340,39592,39640,39717,39730,39740,20094,20602, | ||
| 187 | 20605,20572,20551,20547,20556,20570,20553,20581,20598,20558,20565,20597,20596, | ||
| 188 | 20599,20559,20495,20591,20589,20828,20885,20976,21098,21103,21202,21209,21208, | ||
| 189 | 21205,21264,21263,21273,21311,21312,21310,21443,26364,21830,21866,21862,21828, | ||
| 190 | 21854,21857,21827,21834,21809,21846,21839,21845,21807,21860,21816,21806,21852, | ||
| 191 | 21804,21859,21811,21825,21847,22280,22283,22281,22495,22533,22538,22534,22496, | ||
| 192 | 22500,22522,22530,22581,22519,22521,22816,22882,23094,23105,23113,23142,23146, | ||
| 193 | 23104,23100,23138,23130,23110,23114,23408,23495,23493,23492,23490,23487,23494, | ||
| 194 | 23561,23560,23559,23648,23644,23645,23815,23814,23822,23835,23830,23842,23825, | ||
| 195 | 23849,23828,23833,23844,23847,23831,24034,24120,24118,24115,24119,24247,24248, | ||
| 196 | 24246,24245,24254,24373,24375,24407,24428,24425,24427, | ||
| 197 | 24471,24473,24478,24472,24481,24480,24476,24703,24739,24713,24736,24744,24779, | ||
| 198 | 24756,24806,24765,24773,24763,24757,24796,24764,24792,24789,24774,24799,24760, | ||
| 199 | 24794,24775,25114,25115,25160,25504,25511,25458,25494,25506,25509,25463,25447, | ||
| 200 | 25496,25514,25457,25513,25481,25475,25499,25451,25512,25476,25480,25497,25505, | ||
| 201 | 25516,25490,25487,25472,25467,25449,25448,25466,25949,25942,25937,25945,25943, | ||
| 202 | 21855,25935,25944,25941,25940,26012,26011,26028,26063,26059,26060,26062,26205, | ||
| 203 | 26202,26212,26216,26214,26206,26361,21207,26395,26753,26799,26786,26771,26805, | ||
| 204 | 26751,26742,26801,26791,26775,26800,26755,26820,26797,26758,26757,26772,26781, | ||
| 205 | 26792,26783,26785,26754,27442,27578,27627,27628,27691,28046,28092,28147,28121, | ||
| 206 | 28082,28129,28108,28132,28155,28154,28165,28103,28107,28079,28113,28078,28126, | ||
| 207 | 28153,28088,28151,28149,28101,28114,28186,28085,28122,28139,28120,28138,28145, | ||
| 208 | 28142,28136,28102,28100,28074,28140,28095,28134,28921,28937,28938,28925,28911, | ||
| 209 | 29245,29309,29313,29468,29467,29462,29459,29465,29575,29701,29706,29699,29702, | ||
| 210 | 29694,29709,29920,29942,29943,29980,29986,30053,30054,30050,30064,30095,30164, | ||
| 211 | 30165,30133,30154,30157,30350,30420,30418,30427,30519,30526,30524,30518,30520, | ||
| 212 | 30522,30827,30787,30798,31077,31080,31085,31227,31378,31381,31520,31528,31515, | ||
| 213 | 31532,31526,31513,31518,31534,31890,31895,31893,32070,32067,32113,32046,32057, | ||
| 214 | 32060,32064,32048,32051,32068,32047,32066,32050,32049,32573,32670,32666,32716, | ||
| 215 | 32718,32722,32796,32842,32838,33071,33046,33059,33067,33065,33072,33060,33282, | ||
| 216 | 33333,33335,33334,33337,33678,33694,33688,33656,33698, | ||
| 217 | 33686,33725,33707,33682,33674,33683,33673,33696,33655,33659,33660,33670,33703, | ||
| 218 | 34389,24426,34503,34496,34486,34500,34485,34502,34507,34481,34479,34505,34899, | ||
| 219 | 34974,34952,34987,34962,34966,34957,34955,35219,35215,35370,35357,35363,35365, | ||
| 220 | 35377,35373,35359,35355,35362,35913,35930,36009,36012,36011,36008,36010,36007, | ||
| 221 | 36199,36198,36286,36282,36571,36575,36889,36877,36890,36887,36899,36895,36893, | ||
| 222 | 36880,36885,36894,36896,36879,36898,36886,36891,36884,37096,37101,37117,37207, | ||
| 223 | 37326,37365,37350,37347,37351,37357,37353,38281,38506,38517,38515,38520,38512, | ||
| 224 | 38516,38518,38519,38508,38592,38634,38633,31456,31455,38914,38915,39770,40165, | ||
| 225 | 40565,40575,40613,40635,20642,20621,20613,20633,20625,20608,20630,20632,20634, | ||
| 226 | 26368,20977,21106,21108,21109,21097,21214,21213,21211,21338,21413,21883,21888, | ||
| 227 | 21927,21884,21898,21917,21912,21890,21916,21930,21908,21895,21899,21891,21939, | ||
| 228 | 21934,21919,21822,21938,21914,21947,21932,21937,21886,21897,21931,21913,22285, | ||
| 229 | 22575,22570,22580,22564,22576,22577,22561,22557,22560,22777,22778,22880,23159, | ||
| 230 | 23194,23167,23186,23195,23207,23411,23409,23506,23500,23507,23504,23562,23563, | ||
| 231 | 23601,23884,23888,23860,23879,24061,24133,24125,24128,24131,24190,24266,24257, | ||
| 232 | 24258,24260,24380,24429,24489,24490,24488,24785,24801,24754,24758,24800,24860, | ||
| 233 | 24867,24826,24853,24816,24827,24820,24936,24817,24846,24822,24841,24832,24850, | ||
| 234 | 25119,25161,25507,25484,25551,25536,25577,25545,25542,25549,25554,25571,25552, | ||
| 235 | 25569,25558,25581,25582,25462,25588,25578,25563,25682,25562,25593,25950,25958, | ||
| 236 | 25954,25955,26001,26000,26031,26222,26224,26228,26230, | ||
| 237 | 26223,26257,26234,26238,26231,26366,26367,26399,26397,26874,26837,26848,26840, | ||
| 238 | 26839,26885,26847,26869,26862,26855,26873,26834,26866,26851,26827,26829,26893, | ||
| 239 | 26898,26894,26825,26842,26990,26875,27454,27450,27453,27544,27542,27580,27631, | ||
| 240 | 27694,27695,27692,28207,28216,28244,28193,28210,28263,28234,28192,28197,28195, | ||
| 241 | 28187,28251,28248,28196,28246,28270,28205,28198,28271,28212,28237,28218,28204, | ||
| 242 | 28227,28189,28222,28363,28297,28185,28238,28259,28228,28274,28265,28255,28953, | ||
| 243 | 28954,28966,28976,28961,28982,29038,28956,29260,29316,29312,29494,29477,29492, | ||
| 244 | 29481,29754,29738,29747,29730,29733,29749,29750,29748,29743,29723,29734,29736, | ||
| 245 | 29989,29990,30059,30058,30178,30171,30179,30169,30168,30174,30176,30331,30332, | ||
| 246 | 30358,30355,30388,30428,30543,30701,30813,30828,30831,31245,31240,31243,31237, | ||
| 247 | 31232,31384,31383,31382,31461,31459,31561,31574,31558,31568,31570,31572,31565, | ||
| 248 | 31563,31567,31569,31903,31909,32094,32080,32104,32085,32043,32110,32114,32097, | ||
| 249 | 32102,32098,32112,32115,21892,32724,32725,32779,32850,32901,33109,33108,33099, | ||
| 250 | 33105,33102,33081,33094,33086,33100,33107,33140,33298,33308,33769,33795,33784, | ||
| 251 | 33805,33760,33733,33803,33729,33775,33777,33780,33879,33802,33776,33804,33740, | ||
| 252 | 33789,33778,33738,33848,33806,33796,33756,33799,33748,33759,34395,34527,34521, | ||
| 253 | 34541,34516,34523,34532,34512,34526,34903,35009,35010,34993,35203,35222,35387, | ||
| 254 | 35424,35413,35422,35388,35393,35412,35419,35408,35398,35380,35386,35382,35414, | ||
| 255 | 35937,35970,36015,36028,36019,36029,36033,36027,36032,36020,36023,36022,36031, | ||
| 256 | 36024,36234,36229,36225,36302,36317,36299,36314,36305, | ||
| 257 | 36300,36315,36294,36603,36600,36604,36764,36910,36917,36913,36920,36914,36918, | ||
| 258 | 37122,37109,37129,37118,37219,37221,37327,37396,37397,37411,37385,37406,37389, | ||
| 259 | 37392,37383,37393,38292,38287,38283,38289,38291,38290,38286,38538,38542,38539, | ||
| 260 | 38525,38533,38534,38541,38514,38532,38593,38597,38596,38598,38599,38639,38642, | ||
| 261 | 38860,38917,38918,38920,39143,39146,39151,39145,39154,39149,39342,39341,40643, | ||
| 262 | 40653,40657,20098,20653,20661,20658,20659,20677,20670,20652,20663,20667,20655, | ||
| 263 | 20679,21119,21111,21117,21215,21222,21220,21218,21219,21295,21983,21992,21971, | ||
| 264 | 21990,21966,21980,21959,21969,21987,21988,21999,21978,21985,21957,21958,21989, | ||
| 265 | 21961,22290,22291,22622,22609,22616,22615,22618,22612,22635,22604,22637,22602, | ||
| 266 | 22626,22610,22603,22887,23233,23241,23244,23230,23229,23228,23219,23234,23218, | ||
| 267 | 23913,23919,24140,24185,24265,24264,24338,24409,24492,24494,24858,24847,24904, | ||
| 268 | 24863,24819,24859,24825,24833,24840,24910,24908,24900,24909,24894,24884,24871, | ||
| 269 | 24845,24838,24887,25121,25122,25619,25662,25630,25642,25645,25661,25644,25615, | ||
| 270 | 25628,25620,25613,25654,25622,25623,25606,25964,26015,26032,26263,26249,26247, | ||
| 271 | 26248,26262,26244,26264,26253,26371,27028,26989,26970,26999,26976,26964,26997, | ||
| 272 | 26928,27010,26954,26984,26987,26974,26963,27001,27014,26973,26979,26971,27463, | ||
| 273 | 27506,27584,27583,27603,27645,28322,28335,28371,28342,28354,28304,28317,28359, | ||
| 274 | 28357,28325,28312,28348,28346,28331,28369,28310,28316,28356,28372,28330,28327, | ||
| 275 | 28340,29006,29017,29033,29028,29001,29031,29020,29036,29030,29004,29029,29022, | ||
| 276 | 28998,29032,29014,29242,29266,29495,29509,29503,29502, | ||
| 277 | 29807,29786,29781,29791,29790,29761,29759,29785,29787,29788,30070,30072,30208, | ||
| 278 | 30192,30209,30194,30193,30202,30207,30196,30195,30430,30431,30555,30571,30566, | ||
| 279 | 30558,30563,30585,30570,30572,30556,30565,30568,30562,30702,30862,30896,30871, | ||
| 280 | 30872,30860,30857,30844,30865,30867,30847,31098,31103,31105,33836,31165,31260, | ||
| 281 | 31258,31264,31252,31263,31262,31391,31392,31607,31680,31584,31598,31591,31921, | ||
| 282 | 31923,31925,32147,32121,32145,32129,32143,32091,32622,32617,32618,32626,32681, | ||
| 283 | 32680,32676,32854,32856,32902,32900,33137,33136,33144,33125,33134,33139,33131, | ||
| 284 | 33145,33146,33126,33285,33351,33922,33911,33853,33841,33909,33894,33899,33865, | ||
| 285 | 33900,33883,33852,33845,33889,33891,33897,33901,33862,34398,34396,34399,34553, | ||
| 286 | 34579,34568,34567,34560,34558,34555,34562,34563,34566,34570,34905,35039,35028, | ||
| 287 | 35033,35036,35032,35037,35041,35018,35029,35026,35228,35299,35435,35442,35443, | ||
| 288 | 35430,35433,35440,35463,35452,35427,35488,35441,35461,35437,35426,35438,35436, | ||
| 289 | 35449,35451,35390,35432,35938,35978,35977,36042,36039,36040,36036,36018,36035, | ||
| 290 | 36034,36037,36321,36319,36328,36335,36339,36346,36330,36324,36326,36530,36611, | ||
| 291 | 36617,36606,36618,36767,36786,36939,36938,36947,36930,36948,36924,36949,36944, | ||
| 292 | 36935,36943,36942,36941,36945,36926,36929,37138,37143,37228,37226,37225,37321, | ||
| 293 | 37431,37463,37432,37437,37440,37438,37467,37451,37476,37457,37428,37449,37453, | ||
| 294 | 37445,37433,37439,37466,38296,38552,38548,38549,38605,38603,38601,38602,38647, | ||
| 295 | 38651,38649,38646,38742,38772,38774,38928,38929,38931,38922,38930,38924,39164, | ||
| 296 | 39156,39165,39166,39347,39345,39348,39649,40169,40578, | ||
| 297 | 40718,40723,40736,20711,20718,20709,20694,20717,20698,20693,20687,20689,20721, | ||
| 298 | 20686,20713,20834,20979,21123,21122,21297,21421,22014,22016,22043,22039,22013, | ||
| 299 | 22036,22022,22025,22029,22030,22007,22038,22047,22024,22032,22006,22296,22294, | ||
| 300 | 22645,22654,22659,22675,22666,22649,22661,22653,22781,22821,22818,22820,22890, | ||
| 301 | 22889,23265,23270,23273,23255,23254,23256,23267,23413,23518,23527,23521,23525, | ||
| 302 | 23526,23528,23522,23524,23519,23565,23650,23940,23943,24155,24163,24149,24151, | ||
| 303 | 24148,24275,24278,24330,24390,24432,24505,24903,24895,24907,24951,24930,24931, | ||
| 304 | 24927,24922,24920,24949,25130,25735,25688,25684,25764,25720,25695,25722,25681, | ||
| 305 | 25703,25652,25709,25723,25970,26017,26071,26070,26274,26280,26269,27036,27048, | ||
| 306 | 27029,27073,27054,27091,27083,27035,27063,27067,27051,27060,27088,27085,27053, | ||
| 307 | 27084,27046,27075,27043,27465,27468,27699,28467,28436,28414,28435,28404,28457, | ||
| 308 | 28478,28448,28460,28431,28418,28450,28415,28399,28422,28465,28472,28466,28451, | ||
| 309 | 28437,28459,28463,28552,28458,28396,28417,28402,28364,28407,29076,29081,29053, | ||
| 310 | 29066,29060,29074,29246,29330,29334,29508,29520,29796,29795,29802,29808,29805, | ||
| 311 | 29956,30097,30247,30221,30219,30217,30227,30433,30435,30596,30589,30591,30561, | ||
| 312 | 30913,30879,30887,30899,30889,30883,31118,31119,31117,31278,31281,31402,31401, | ||
| 313 | 31469,31471,31649,31637,31627,31605,31639,31645,31636,31631,31672,31623,31620, | ||
| 314 | 31929,31933,31934,32187,32176,32156,32189,32190,32160,32202,32180,32178,32177, | ||
| 315 | 32186,32162,32191,32181,32184,32173,32210,32199,32172,32624,32736,32737,32735, | ||
| 316 | 32862,32858,32903,33104,33152,33167,33160,33162,33151, | ||
| 317 | 33154,33255,33274,33287,33300,33310,33355,33993,33983,33990,33988,33945,33950, | ||
| 318 | 33970,33948,33995,33976,33984,34003,33936,33980,34001,33994,34623,34588,34619, | ||
| 319 | 34594,34597,34612,34584,34645,34615,34601,35059,35074,35060,35065,35064,35069, | ||
| 320 | 35048,35098,35055,35494,35468,35486,35491,35469,35489,35475,35492,35498,35493, | ||
| 321 | 35496,35480,35473,35482,35495,35946,35981,35980,36051,36049,36050,36203,36249, | ||
| 322 | 36245,36348,36628,36626,36629,36627,36771,36960,36952,36956,36963,36953,36958, | ||
| 323 | 36962,36957,36955,37145,37144,37150,37237,37240,37239,37236,37496,37504,37509, | ||
| 324 | 37528,37526,37499,37523,37532,37544,37500,37521,38305,38312,38313,38307,38309, | ||
| 325 | 38308,38553,38556,38555,38604,38610,38656,38780,38789,38902,38935,38936,39087, | ||
| 326 | 39089,39171,39173,39180,39177,39361,39599,39600,39654,39745,39746,40180,40182, | ||
| 327 | 40179,40636,40763,40778,20740,20736,20731,20725,20729,20738,20744,20745,20741, | ||
| 328 | 20956,21127,21128,21129,21133,21130,21232,21426,22062,22075,22073,22066,22079, | ||
| 329 | 22068,22057,22099,22094,22103,22132,22070,22063,22064,22656,22687,22686,22707, | ||
| 330 | 22684,22702,22697,22694,22893,23305,23291,23307,23285,23308,23304,23534,23532, | ||
| 331 | 23529,23531,23652,23653,23965,23956,24162,24159,24161,24290,24282,24287,24285, | ||
| 332 | 24291,24288,24392,24433,24503,24501,24950,24935,24942,24925,24917,24962,24956, | ||
| 333 | 24944,24939,24958,24999,24976,25003,24974,25004,24986,24996,24980,25006,25134, | ||
| 334 | 25705,25711,25721,25758,25778,25736,25744,25776,25765,25747,25749,25769,25746, | ||
| 335 | 25774,25773,25771,25754,25772,25753,25762,25779,25973,25975,25976,26286,26283, | ||
| 336 | 26292,26289,27171,27167,27112,27137,27166,27161,27133, | ||
| 337 | 27169,27155,27146,27123,27138,27141,27117,27153,27472,27470,27556,27589,27590, | ||
| 338 | 28479,28540,28548,28497,28518,28500,28550,28525,28507,28536,28526,28558,28538, | ||
| 339 | 28528,28516,28567,28504,28373,28527,28512,28511,29087,29100,29105,29096,29270, | ||
| 340 | 29339,29518,29527,29801,29835,29827,29822,29824,30079,30240,30249,30239,30244, | ||
| 341 | 30246,30241,30242,30362,30394,30436,30606,30599,30604,30609,30603,30923,30917, | ||
| 342 | 30906,30922,30910,30933,30908,30928,31295,31292,31296,31293,31287,31291,31407, | ||
| 343 | 31406,31661,31665,31684,31668,31686,31687,31681,31648,31692,31946,32224,32244, | ||
| 344 | 32239,32251,32216,32236,32221,32232,32227,32218,32222,32233,32158,32217,32242, | ||
| 345 | 32249,32629,32631,32687,32745,32806,33179,33180,33181,33184,33178,33176,34071, | ||
| 346 | 34109,34074,34030,34092,34093,34067,34065,34083,34081,34068,34028,34085,34047, | ||
| 347 | 34054,34690,34676,34678,34656,34662,34680,34664,34649,34647,34636,34643,34907, | ||
| 348 | 34909,35088,35079,35090,35091,35093,35082,35516,35538,35527,35524,35477,35531, | ||
| 349 | 35576,35506,35529,35522,35519,35504,35542,35533,35510,35513,35547,35916,35918, | ||
| 350 | 35948,36064,36062,36070,36068,36076,36077,36066,36067,36060,36074,36065,36205, | ||
| 351 | 36255,36259,36395,36368,36381,36386,36367,36393,36383,36385,36382,36538,36637, | ||
| 352 | 36635,36639,36649,36646,36650,36636,36638,36645,36969,36974,36968,36973,36983, | ||
| 353 | 37168,37165,37159,37169,37255,37257,37259,37251,37573,37563,37559,37610,37548, | ||
| 354 | 37604,37569,37555,37564,37586,37575,37616,37554,38317,38321,38660,38662,38663, | ||
| 355 | 38665,38752,38797,38795,38799,38945,38955,38940,39091,39178,39187,39186,39192, | ||
| 356 | 39389,39376,39391,39387,39377,39381,39378,39385,39607, | ||
| 357 | 39662,39663,39719,39749,39748,39799,39791,40198,40201,40195,40617,40638,40654, | ||
| 358 | 22696,40786,20754,20760,20756,20752,20757,20864,20906,20957,21137,21139,21235, | ||
| 359 | 22105,22123,22137,22121,22116,22136,22122,22120,22117,22129,22127,22124,22114, | ||
| 360 | 22134,22721,22718,22727,22725,22894,23325,23348,23416,23536,23566,24394,25010, | ||
| 361 | 24977,25001,24970,25037,25014,25022,25034,25032,25136,25797,25793,25803,25787, | ||
| 362 | 25788,25818,25796,25799,25794,25805,25791,25810,25812,25790,25972,26310,26313, | ||
| 363 | 26297,26308,26311,26296,27197,27192,27194,27225,27243,27224,27193,27204,27234, | ||
| 364 | 27233,27211,27207,27189,27231,27208,27481,27511,27653,28610,28593,28577,28611, | ||
| 365 | 28580,28609,28583,28595,28608,28601,28598,28582,28576,28596,29118,29129,29136, | ||
| 366 | 29138,29128,29141,29113,29134,29145,29148,29123,29124,29544,29852,29859,29848, | ||
| 367 | 29855,29854,29922,29964,29965,30260,30264,30266,30439,30437,30624,30622,30623, | ||
| 368 | 30629,30952,30938,30956,30951,31142,31309,31310,31302,31308,31307,31418,31705, | ||
| 369 | 31761,31689,31716,31707,31713,31721,31718,31957,31958,32266,32273,32264,32283, | ||
| 370 | 32291,32286,32285,32265,32272,32633,32690,32752,32753,32750,32808,33203,33193, | ||
| 371 | 33192,33275,33288,33368,33369,34122,34137,34120,34152,34153,34115,34121,34157, | ||
| 372 | 34154,34142,34691,34719,34718,34722,34701,34913,35114,35122,35109,35115,35105, | ||
| 373 | 35242,35238,35558,35578,35563,35569,35584,35548,35559,35566,35582,35585,35586, | ||
| 374 | 35575,35565,35571,35574,35580,35947,35949,35987,36084,36420,36401,36404,36418, | ||
| 375 | 36409,36405,36667,36655,36664,36659,36776,36774,36981,36980,36984,36978,36988, | ||
| 376 | 36986,37172,37266,37664,37686,37624,37683,37679,37666, | ||
| 377 | 37628,37675,37636,37658,37648,37670,37665,37653,37678,37657,38331,38567,38568, | ||
| 378 | 38570,38613,38670,38673,38678,38669,38675,38671,38747,38748,38758,38808,38960, | ||
| 379 | 38968,38971,38967,38957,38969,38948,39184,39208,39198,39195,39201,39194,39405, | ||
| 380 | 39394,39409,39608,39612,39675,39661,39720,39825,40213,40227,40230,40232,40210, | ||
| 381 | 40219,40664,40660,40845,40860,20778,20767,20769,20786,21237,22158,22144,22160, | ||
| 382 | 22149,22151,22159,22741,22739,22737,22734,23344,23338,23332,23418,23607,23656, | ||
| 383 | 23996,23994,23997,23992,24171,24396,24509,25033,25026,25031,25062,25035,25138, | ||
| 384 | 25140,25806,25802,25816,25824,25840,25830,25836,25841,25826,25837,25986,25987, | ||
| 385 | 26329,26326,27264,27284,27268,27298,27292,27355,27299,27262,27287,27280,27296, | ||
| 386 | 27484,27566,27610,27656,28632,28657,28639,28640,28635,28644,28651,28655,28544, | ||
| 387 | 28652,28641,28649,28629,28654,28656,29159,29151,29166,29158,29157,29165,29164, | ||
| 388 | 29172,29152,29237,29254,29552,29554,29865,29872,29862,29864,30278,30274,30284, | ||
| 389 | 30442,30643,30634,30640,30636,30631,30637,30703,30967,30970,30964,30959,30977, | ||
| 390 | 31143,31146,31319,31423,31751,31757,31742,31735,31756,31712,31968,31964,31966, | ||
| 391 | 31970,31967,31961,31965,32302,32318,32326,32311,32306,32323,32299,32317,32305, | ||
| 392 | 32325,32321,32308,32313,32328,32309,32319,32303,32580,32755,32764,32881,32882, | ||
| 393 | 32880,32879,32883,33222,33219,33210,33218,33216,33215,33213,33225,33214,33256, | ||
| 394 | 33289,33393,34218,34180,34174,34204,34193,34196,34223,34203,34183,34216,34186, | ||
| 395 | 34407,34752,34769,34739,34770,34758,34731,34747,34746,34760,34763,35131,35126, | ||
| 396 | 35140,35128,35133,35244,35598,35607,35609,35611,35594, | ||
| 397 | 35616,35613,35588,35600,35905,35903,35955,36090,36093,36092,36088,36091,36264, | ||
| 398 | 36425,36427,36424,36426,36676,36670,36674,36677,36671,36991,36989,36996,36993, | ||
| 399 | 36994,36992,37177,37283,37278,37276,37709,37762,37672,37749,37706,37733,37707, | ||
| 400 | 37656,37758,37740,37723,37744,37722,37716,38346,38347,38348,38344,38342,38577, | ||
| 401 | 38584,38614,38684,38686,38816,38867,38982,39094,39221,39425,39423,39854,39851, | ||
| 402 | 39850,39853,40251,40255,40587,40655,40670,40668,40669,40667,40766,40779,21474, | ||
| 403 | 22165,22190,22745,22744,23352,24413,25059,25139,25844,25842,25854,25862,25850, | ||
| 404 | 25851,25847,26039,26332,26406,27315,27308,27331,27323,27320,27330,27310,27311, | ||
| 405 | 27487,27512,27567,28681,28683,28670,28678,28666,28689,28687,29179,29180,29182, | ||
| 406 | 29176,29559,29557,29863,29887,29973,30294,30296,30290,30653,30655,30651,30652, | ||
| 407 | 30990,31150,31329,31330,31328,31428,31429,31787,31783,31786,31774,31779,31777, | ||
| 408 | 31975,32340,32341,32350,32346,32353,32338,32345,32584,32761,32763,32887,32886, | ||
| 409 | 33229,33231,33290,34255,34217,34253,34256,34249,34224,34234,34233,34214,34799, | ||
| 410 | 34796,34802,34784,35206,35250,35316,35624,35641,35628,35627,35920,36101,36441, | ||
| 411 | 36451,36454,36452,36447,36437,36544,36681,36685,36999,36995,37000,37291,37292, | ||
| 412 | 37328,37780,37770,37782,37794,37811,37806,37804,37808,37784,37786,37783,38356, | ||
| 413 | 38358,38352,38357,38626,38620,38617,38619,38622,38692,38819,38822,38829,38905, | ||
| 414 | 38989,38991,38988,38990,38995,39098,39230,39231,39229,39214,39333,39438,39617, | ||
| 415 | 39683,39686,39759,39758,39757,39882,39881,39933,39880,39872,40273,40285,40288, | ||
| 416 | 40672,40725,40748,20787,22181,22750,22751,22754,23541, | ||
| 417 | 40848,24300,25074,25079,25078,25077,25856,25871,26336,26333,27365,27357,27354, | ||
| 418 | 27347,28699,28703,28712,28698,28701,28693,28696,29190,29197,29272,29346,29560, | ||
| 419 | 29562,29885,29898,29923,30087,30086,30303,30305,30663,31001,31153,31339,31337, | ||
| 420 | 31806,31807,31800,31805,31799,31808,32363,32365,32377,32361,32362,32645,32371, | ||
| 421 | 32694,32697,32696,33240,34281,34269,34282,34261,34276,34277,34295,34811,34821, | ||
| 422 | 34829,34809,34814,35168,35167,35158,35166,35649,35676,35672,35657,35674,35662, | ||
| 423 | 35663,35654,35673,36104,36106,36476,36466,36487,36470,36460,36474,36468,36692, | ||
| 424 | 36686,36781,37002,37003,37297,37294,37857,37841,37855,37827,37832,37852,37853, | ||
| 425 | 37846,37858,37837,37848,37860,37847,37864,38364,38580,38627,38698,38695,38753, | ||
| 426 | 38876,38907,39006,39000,39003,39100,39237,39241,39446,39449,39693,39912,39911, | ||
| 427 | 39894,39899,40329,40289,40306,40298,40300,40594,40599,40595,40628,21240,22184, | ||
| 428 | 22199,22198,22196,22204,22756,23360,23363,23421,23542,24009,25080,25082,25880, | ||
| 429 | 25876,25881,26342,26407,27372,28734,28720,28722,29200,29563,29903,30306,30309, | ||
| 430 | 31014,31018,31020,31019,31431,31478,31820,31811,31821,31983,31984,36782,32381, | ||
| 431 | 32380,32386,32588,32768,33242,33382,34299,34297,34321,34298,34310,34315,34311, | ||
| 432 | 34314,34836,34837,35172,35258,35320,35696,35692,35686,35695,35679,35691,36111, | ||
| 433 | 36109,36489,36481,36485,36482,37300,37323,37912,37891,37885,38369,38704,39108, | ||
| 434 | 39250,39249,39336,39467,39472,39479,39477,39955,39949,40569,40629,40680,40751, | ||
| 435 | 40799,40803,40801,20791,20792,22209,22208,22210,22804,23660,24013,25084,25086, | ||
| 436 | 25885,25884,26005,26345,27387,27396,27386,27570,28748, | ||
| 437 | 29211,29351,29910,29908,30313,30675,31824,32399,32396,32700,34327,34349,34330, | ||
| 438 | 34851,34850,34849,34847,35178,35180,35261,35700,35703,35709,36115,36490,36493, | ||
| 439 | 36491,36703,36783,37306,37934,37939,37941,37946,37944,37938,37931,38370,38712, | ||
| 440 | 38713,38706,38911,39015,39013,39255,39493,39491,39488,39486,39631,39764,39761, | ||
| 441 | 39981,39973,40367,40372,40386,40376,40605,40687,40729,40796,40806,40807,20796, | ||
| 442 | 20795,22216,22218,22217,23423,24020,24018,24398,25087,25892,27402,27489,28753, | ||
| 443 | 28760,29568,29924,30090,30318,30316,31155,31840,31839,32894,32893,33247,35186, | ||
| 444 | 35183,35324,35712,36118,36119,36497,36499,36705,37192,37956,37969,37970,38717, | ||
| 445 | 38718,38851,38849,39019,39253,39509,39501,39634,39706,40009,39985,39998,39995, | ||
| 446 | 40403,40407,40756,40812,40810,40852,22220,24022,25088,25891,25899,25898,26348, | ||
| 447 | 27408,29914,31434,31844,31843,31845,32403,32406,32404,33250,34360,34367,34865, | ||
| 448 | 35722,37008,37007,37987,37984,37988,38760,39023,39260,39514,39515,39511,39635, | ||
| 449 | 39636,39633,40020,40023,40022,40421,40607,40692,22225,22761,25900,28766,30321, | ||
| 450 | 30322,30679,32592,32648,34870,34873,34914,35731,35730,35734,33399,36123,37312, | ||
| 451 | 37994,38722,38728,38724,38854,39024,39519,39714,39768,40031,40441,40442,40572, | ||
| 452 | 40573,40711,40823,40818,24307,27414,28771,31852,31854,34875,35264,36513,37313, | ||
| 453 | 38002,38000,39025,39262,39638,39715,40652,28772,30682,35738,38007,38857,39522, | ||
| 454 | 39525,32412,35740,36522,37317,38013,38014,38012,40055,40056,40695,35924,38015, | ||
| 455 | 40474,29224,39530,39729,40475,40478,31858,9312,9313,9314,9315,9316,9317,9318, | ||
| 456 | 9319,9320,9321,9332,9333,9334,9335,9336, | ||
| 457 | 9337,9338,9339,9340,9341,8560,8561,8562,8563,8564,8565,8566,8567,8568,8569, | ||
| 458 | 20022,20031,20101,20128,20866,20886,20907,21241,21304,21353,21430,22794,23424, | ||
| 459 | 24027,24186,24191,24308,24400,24417,25908,26080,30098,30326,36789,38582,168, | ||
| 460 | 710,12541,12542,12445,12446,0,0,12293,12294,12295,12540,65339,65341,10045, | ||
| 461 | 12353,12354,12355,12356,12357,12358,12359,12360,12361,12362,12363,12364,12365, | ||
| 462 | 12366,12367,12368,12369,12370,12371,12372,12373,12374,12375,12376,12377,12378, | ||
| 463 | 12379,12380,12381,12382,12383,12384,12385,12386,12387,12388,12389,12390,12391, | ||
| 464 | 12392,12393,12394,12395,12396,12397,12398,12399,12400,12401,12402,12403,12404, | ||
| 465 | 12405,12406,12407,12408,12409,12410,12411,12412,12413,12414,12415,12416,12417, | ||
| 466 | 12418,12419,12420,12421,12422,12423,12424,12425,12426,12427,12428,12429,12430, | ||
| 467 | 12431,12432,12433,12434,12435,12449,12450,12451,12452,12453,12454,12455,12456, | ||
| 468 | 12457,12458,12459,12460,12461,12462,12463,12464,12465,12466,12467,12468,12469, | ||
| 469 | 12470,12471,12472,12473,12474,12475,12476,12477,12478,12479,12480,12481,12482, | ||
| 470 | 12483,12484,12485,12486,12487,12488,12489,12490,12491,12492,12493,12494,12495, | ||
| 471 | 12496,12497,12498,12499,12500,12501,12502,12503,12504,12505,12506,12507,12508, | ||
| 472 | 12509,12510,12511,12512,12513,12514,12515,12516,12517,12518,12519,12520,12521, | ||
| 473 | 12522,12523,12524,12525,12526,12527,12528,12529,12530,12531,12532,12533,12534, | ||
| 474 | 1040,1041,1042,1043,1044,1045,1025,1046,1047,1048,1049,1050,1051,1052,1053, | ||
| 475 | 1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068, | ||
| 476 | 1069,1070, | ||
| 477 | 1071,1072,1073,1074,1075,1076,1077,1105,1078,1079,1080,1081,1082,1083,1084, | ||
| 478 | 1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099, | ||
| 479 | 1100,1101,1102,1103,8679,8632,8633,12751,204,20058,138,20994,17553,40880, | ||
| 480 | 20872,40881,30215,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 481 | 0,0,0,0,0,0,0,0,0,0,65506,65508,65287,65282,12849,8470,8481,12443,12444,11904, | ||
| 482 | 11908,11910,11911,11912,11914,11916,11917,11925,11932,11933,11941,11943,11946, | ||
| 483 | 11948,11950,11958,11964,11966,11974,11978,11980,11981,11983,11990,11991,11998, | ||
| 484 | 12003,0,0,0,643,592,603,596,629,339,248,331,650,618,20034,20060,20981,21274, | ||
| 485 | 21378,19975,19980,20039,20109,22231,64012,23662,24435,19983,20871,19982,20014, | ||
| 486 | 20115,20162,20169,20168,20888,21244,21356,21433,22304,22787,22828,23568,24063, | ||
| 487 | 26081,27571,27596,27668,29247,20017,20028,20200,20188,20201,20193,20189,20186, | ||
| 488 | 21004,21276,21324,22306,22307,22807,22831,23425,23428,23570,23611,23668,23667, | ||
| 489 | 24068,24192,24194,24521,25097,25168,27669,27702,27715,27711,27707,29358,29360, | ||
| 490 | 29578,31160,32906,38430,20238,20248,20268,20213,20244,20209,20224,20215,20232, | ||
| 491 | 20253,20226,20229,20258,20243,20228,20212,20242,20913,21011,21001,21008,21158, | ||
| 492 | 21282,21279,21325,21386,21511,22241,22239,22318,22314,22324,22844,22912,22908, | ||
| 493 | 22917,22907,22910,22903,22911,23382,23573,23589,23676,23674,23675, | ||
| 494 | 23678,24031,24181,24196,24322,24346,24436,24533,24532,24527,25180,25182,25188, | ||
| 495 | 25185,25190,25186,25177,25184,25178,25189,26095,26094,26430,26425,26424,26427, | ||
| 496 | 26426,26431,26428,26419,27672,27718,27730,27740,27727,27722,27732,27723,27724, | ||
| 497 | 28785,29278,29364,29365,29582,29994,30335,31349,32593,33400,33404,33408,33405, | ||
| 498 | 33407,34381,35198,37017,37015,37016,37019,37012,38434,38436,38432,38435,20310, | ||
| 499 | 20283,20322,20297,20307,20324,20286,20327,20306,20319,20289,20312,20269,20275, | ||
| 500 | 20287,20321,20879,20921,21020,21022,21025,21165,21166,21257,21347,21362,21390, | ||
| 501 | 21391,21552,21559,21546,21588,21573,21529,21532,21541,21528,21565,21583,21569, | ||
| 502 | 21544,21540,21575,22254,22247,22245,22337,22341,22348,22345,22347,22354,22790, | ||
| 503 | 22848,22950,22936,22944,22935,22926,22946,22928,22927,22951,22945,23438,23442, | ||
| 504 | 23592,23594,23693,23695,23688,23691,23689,23698,23690,23686,23699,23701,24032, | ||
| 505 | 24074,24078,24203,24201,24204,24200,24205,24325,24349,24440,24438,24530,24529, | ||
| 506 | 24528,24557,24552,24558,24563,24545,24548,24547,24570,24559,24567,24571,24576, | ||
| 507 | 24564,25146,25219,25228,25230,25231,25236,25223,25201,25211,25210,25200,25217, | ||
| 508 | 25224,25207,25213,25202,25204,25911,26096,26100,26099,26098,26101,26437,26439, | ||
| 509 | 26457,26453,26444,26440,26461,26445,26458,26443,27600,27673,27674,27768,27751, | ||
| 510 | 27755,27780,27787,27791,27761,27759,27753,27802,27757,27783,27797,27804,27750, | ||
| 511 | 27763,27749,27771,27790,28788,28794,29283,29375,29373,29379,29382,29377,29370, | ||
| 512 | 29381,29589,29591,29587,29588,29586,30010,30009,30100,30101,30337,31037,32820, | ||
| 513 | 32917,32921,32912,32914,32924,33424,33423,33413,33422, | ||
| 514 | 33425,33427,33418,33411,33412,35960,36809,36799,37023,37025,37029,37022,37031, | ||
| 515 | 37024,38448,38440,38447,38445,20019,20376,20348,20357,20349,20352,20359,20342, | ||
| 516 | 20340,20361,20356,20343,20300,20375,20330,20378,20345,20353,20344,20368,20380, | ||
| 517 | 20372,20382,20370,20354,20373,20331,20334,20894,20924,20926,21045,21042,21043, | ||
| 518 | 21062,21041,21180,21258,21259,21308,21394,21396,21639,21631,21633,21649,21634, | ||
| 519 | 21640,21611,21626,21630,21605,21612,21620,21606,21645,21615,21601,21600,21656, | ||
| 520 | 21603,21607,21604,22263,22265,22383,22386,22381,22379,22385,22384,22390,22400, | ||
| 521 | 22389,22395,22387,22388,22370,22376,22397,22796,22853,22965,22970,22991,22990, | ||
| 522 | 22962,22988,22977,22966,22972,22979,22998,22961,22973,22976,22984,22964,22983, | ||
| 523 | 23394,23397,23443,23445,23620,23623,23726,23716,23712,23733,23727,23720,23724, | ||
| 524 | 23711,23715,23725,23714,23722,23719,23709,23717,23734,23728,23718,24087,24084, | ||
| 525 | 24089,24360,24354,24355,24356,24404,24450,24446,24445,24542,24549,24621,24614, | ||
| 526 | 24601,24626,24587,24628,24586,24599,24627,24602,24606,24620,24610,24589,24592, | ||
| 527 | 24622,24595,24593,24588,24585,24604,25108,25149,25261,25268,25297,25278,25258, | ||
| 528 | 25270,25290,25262,25267,25263,25275,25257,25264,25272,25917,26024,26043,26121, | ||
| 529 | 26108,26116,26130,26120,26107,26115,26123,26125,26117,26109,26129,26128,26358, | ||
| 530 | 26378,26501,26476,26510,26514,26486,26491,26520,26502,26500,26484,26509,26508, | ||
| 531 | 26490,26527,26513,26521,26499,26493,26497,26488,26489,26516,27429,27520,27518, | ||
| 532 | 27614,27677,27795,27884,27883,27886,27865,27830,27860,27821,27879,27831,27856, | ||
| 533 | 27842,27834,27843,27846,27885,27890,27858,27869,27828, | ||
| 534 | 27786,27805,27776,27870,27840,27952,27853,27847,27824,27897,27855,27881,27857, | ||
| 535 | 28820,28824,28805,28819,28806,28804,28817,28822,28802,28826,28803,29290,29398, | ||
| 536 | 29387,29400,29385,29404,29394,29396,29402,29388,29393,29604,29601,29613,29606, | ||
| 537 | 29602,29600,29612,29597,29917,29928,30015,30016,30014,30092,30104,30383,30451, | ||
| 538 | 30449,30448,30453,30712,30716,30713,30715,30714,30711,31042,31039,31173,31352, | ||
| 539 | 31355,31483,31861,31997,32821,32911,32942,32931,32952,32949,32941,33312,33440, | ||
| 540 | 33472,33451,33434,33432,33435,33461,33447,33454,33468,33438,33466,33460,33448, | ||
| 541 | 33441,33449,33474,33444,33475,33462,33442,34416,34415,34413,34414,35926,36818, | ||
| 542 | 36811,36819,36813,36822,36821,36823,37042,37044,37039,37043,37040,38457,38461, | ||
| 543 | 38460,38458,38467,20429,20421,20435,20402,20425,20427,20417,20436,20444,20441, | ||
| 544 | 20411,20403,20443,20423,20438,20410,20416,20409,20460,21060,21065,21184,21186, | ||
| 545 | 21309,21372,21399,21398,21401,21400,21690,21665,21677,21669,21711,21699,33549, | ||
| 546 | 21687,21678,21718,21686,21701,21702,21664,21616,21692,21666,21694,21618,21726, | ||
| 547 | 21680,22453,22430,22431,22436,22412,22423,22429,22427,22420,22424,22415,22425, | ||
| 548 | 22437,22426,22421,22772,22797,22867,23009,23006,23022,23040,23025,23005,23034, | ||
| 549 | 23037,23036,23030,23012,23026,23031,23003,23017,23027,23029,23008,23038,23028, | ||
| 550 | 23021,23464,23628,23760,23768,23756,23767,23755,23771,23774,23770,23753,23751, | ||
| 551 | 23754,23766,23763,23764,23759,23752,23750,23758,23775,23800,24057,24097,24098, | ||
| 552 | 24099,24096,24100,24240,24228,24226,24219,24227,24229,24327,24366,24406,24454, | ||
| 553 | 24631,24633,24660,24690,24670,24645,24659,24647,24649, | ||
| 554 | 24667,24652,24640,24642,24671,24612,24644,24664,24678,24686,25154,25155,25295, | ||
| 555 | 25357,25355,25333,25358,25347,25323,25337,25359,25356,25336,25334,25344,25363, | ||
| 556 | 25364,25338,25365,25339,25328,25921,25923,26026,26047,26166,26145,26162,26165, | ||
| 557 | 26140,26150,26146,26163,26155,26170,26141,26164,26169,26158,26383,26384,26561, | ||
| 558 | 26610,26568,26554,26588,26555,26616,26584,26560,26551,26565,26603,26596,26591, | ||
| 559 | 26549,26573,26547,26615,26614,26606,26595,26562,26553,26574,26599,26608,26546, | ||
| 560 | 26620,26566,26605,26572,26542,26598,26587,26618,26569,26570,26563,26602,26571, | ||
| 561 | 27432,27522,27524,27574,27606,27608,27616,27680,27681,27944,27956,27949,27935, | ||
| 562 | 27964,27967,27922,27914,27866,27955,27908,27929,27962,27930,27921,27904,27933, | ||
| 563 | 27970,27905,27928,27959,27907,27919,27968,27911,27936,27948,27912,27938,27913, | ||
| 564 | 27920,28855,28831,28862,28849,28848,28833,28852,28853,28841,29249,29257,29258, | ||
| 565 | 29292,29296,29299,29294,29386,29412,29416,29419,29407,29418,29414,29411,29573, | ||
| 566 | 29644,29634,29640,29637,29625,29622,29621,29620,29675,29631,29639,29630,29635, | ||
| 567 | 29638,29624,29643,29932,29934,29998,30023,30024,30119,30122,30329,30404,30472, | ||
| 568 | 30467,30468,30469,30474,30455,30459,30458,30695,30696,30726,30737,30738,30725, | ||
| 569 | 30736,30735,30734,30729,30723,30739,31050,31052,31051,31045,31044,31189,31181, | ||
| 570 | 31183,31190,31182,31360,31358,31441,31488,31489,31866,31864,31865,31871,31872, | ||
| 571 | 31873,32003,32008,32001,32600,32657,32653,32702,32775,32782,32783,32788,32823, | ||
| 572 | 32984,32967,32992,32977,32968,32962,32976,32965,32995,32985,32988,32970,32981, | ||
| 573 | 32969,32975,32983,32998,32973,33279,33313,33428,33497, | ||
| 574 | 33534,33529,33543,33512,33536,33493,33594,33515,33494,33524,33516,33505,33522, | ||
| 575 | 33525,33548,33531,33526,33520,33514,33508,33504,33530,33523,33517,34423,34420, | ||
| 576 | 34428,34419,34881,34894,34919,34922,34921,35283,35332,35335,36210,36835,36833, | ||
| 577 | 36846,36832,37105,37053,37055,37077,37061,37054,37063,37067,37064,37332,37331, | ||
| 578 | 38484,38479,38481,38483,38474,38478,20510,20485,20487,20499,20514,20528,20507, | ||
| 579 | 20469,20468,20531,20535,20524,20470,20471,20503,20508,20512,20519,20533,20527, | ||
| 580 | 20529,20494,20826,20884,20883,20938,20932,20933,20936,20942,21089,21082,21074, | ||
| 581 | 21086,21087,21077,21090,21197,21262,21406,21798,21730,21783,21778,21735,21747, | ||
| 582 | 21732,21786,21759,21764,21768,21739,21777,21765,21745,21770,21755,21751,21752, | ||
| 583 | 21728,21774,21763,21771,22273,22274,22476,22578,22485,22482,22458,22470,22461, | ||
| 584 | 22460,22456,22454,22463,22471,22480,22457,22465,22798,22858,23065,23062,23085, | ||
| 585 | 23086,23061,23055,23063,23050,23070,23091,23404,23463,23469,23468,23555,23638, | ||
| 586 | 23636,23788,23807,23790,23793,23799,23808,23801,24105,24104,24232,24238,24234, | ||
| 587 | 24236,24371,24368,24423,24669,24666,24679,24641,24738,24712,24704,24722,24705, | ||
| 588 | 24733,24707,24725,24731,24727,24711,24732,24718,25113,25158,25330,25360,25430, | ||
| 589 | 25388,25412,25413,25398,25411,25572,25401,25419,25418,25404,25385,25409,25396, | ||
| 590 | 25432,25428,25433,25389,25415,25395,25434,25425,25400,25431,25408,25416,25930, | ||
| 591 | 25926,26054,26051,26052,26050,26186,26207,26183,26193,26386,26387,26655,26650, | ||
| 592 | 26697,26674,26675,26683,26699,26703,26646,26673,26652,26677,26667,26669,26671, | ||
| 593 | 26702,26692,26676,26653,26642,26644,26662,26664,26670, | ||
| 594 | 26701,26682,26661,26656,27436,27439,27437,27441,27444,27501,32898,27528,27622, | ||
| 595 | 27620,27624,27619,27618,27623,27685,28026,28003,28004,28022,27917,28001,28050, | ||
| 596 | 27992,28002,28013,28015,28049,28045,28143,28031,28038,27998,28007,28000,28055, | ||
| 597 | 28016,28028,27999,28034,28056,27951,28008,28043,28030,28032,28036,27926,28035, | ||
| 598 | 28027,28029,28021,28048,28892,28883,28881,28893,28875,32569,28898,28887,28882, | ||
| 599 | 28894,28896,28884,28877,28869,28870,28871,28890,28878,28897,29250,29304,29303, | ||
| 600 | 29302,29440,29434,29428,29438,29430,29427,29435,29441,29651,29657,29669,29654, | ||
| 601 | 29628,29671,29667,29673,29660,29650,29659,29652,29661,29658,29655,29656,29672, | ||
| 602 | 29918,29919,29940,29941,29985,30043,30047,30128,30145,30139,30148,30144,30143, | ||
| 603 | 30134,30138,30346,30409,30493,30491,30480,30483,30482,30499,30481,30485,30489, | ||
| 604 | 30490,30498,30503,30755,30764,30754,30773,30767,30760,30766,30763,30753,30761, | ||
| 605 | 30771,30762,30769,31060,31067,31055,31068,31059,31058,31057,31211,31212,31200, | ||
| 606 | 31214,31213,31210,31196,31198,31197,31366,31369,31365,31371,31372,31370,31367, | ||
| 607 | 31448,31504,31492,31507,31493,31503,31496,31498,31502,31497,31506,31876,31889, | ||
| 608 | 31882,31884,31880,31885,31877,32030,32029,32017,32014,32024,32022,32019,32031, | ||
| 609 | 32018,32015,32012,32604,32609,32606,32608,32605,32603,32662,32658,32707,32706, | ||
| 610 | 32704,32790,32830,32825,33018,33010,33017,33013,33025,33019,33024,33281,33327, | ||
| 611 | 33317,33587,33581,33604,33561,33617,33573,33622,33599,33601,33574,33564,33570, | ||
| 612 | 33602,33614,33563,33578,33544,33596,33613,33558,33572,33568,33591,33583,33577, | ||
| 613 | 33607,33605,33612,33619,33566,33580,33611,33575,33608, | ||
| 614 | 34387,34386,34466,34472,34454,34445,34449,34462,34439,34455,34438,34443,34458, | ||
| 615 | 34437,34469,34457,34465,34471,34453,34456,34446,34461,34448,34452,34883,34884, | ||
| 616 | 34925,34933,34934,34930,34944,34929,34943,34927,34947,34942,34932,34940,35346, | ||
| 617 | 35911,35927,35963,36004,36003,36214,36216,36277,36279,36278,36561,36563,36862, | ||
| 618 | 36853,36866,36863,36859,36868,36860,36854,37078,37088,37081,37082,37091,37087, | ||
| 619 | 37093,37080,37083,37079,37084,37092,37200,37198,37199,37333,37346,37338,38492, | ||
| 620 | 38495,38588,39139,39647,39727,20095,20592,20586,20577,20574,20576,20563,20555, | ||
| 621 | 20573,20594,20552,20557,20545,20571,20554,20578,20501,20549,20575,20585,20587, | ||
| 622 | 20579,20580,20550,20544,20590,20595,20567,20561,20944,21099,21101,21100,21102, | ||
| 623 | 21206,21203,21293,21404,21877,21878,21820,21837,21840,21812,21802,21841,21858, | ||
| 624 | 21814,21813,21808,21842,21829,21772,21810,21861,21838,21817,21832,21805,21819, | ||
| 625 | 21824,21835,22282,22279,22523,22548,22498,22518,22492,22516,22528,22509,22525, | ||
| 626 | 22536,22520,22539,22515,22479,22535,22510,22499,22514,22501,22508,22497,22542, | ||
| 627 | 22524,22544,22503,22529,22540,22513,22505,22512,22541,22532,22876,23136,23128, | ||
| 628 | 23125,23143,23134,23096,23093,23149,23120,23135,23141,23148,23123,23140,23127, | ||
| 629 | 23107,23133,23122,23108,23131,23112,23182,23102,23117,23097,23116,23152,23145, | ||
| 630 | 23111,23121,23126,23106,23132,23410,23406,23489,23488,23641,23838,23819,23837, | ||
| 631 | 23834,23840,23820,23848,23821,23846,23845,23823,23856,23826,23843,23839,23854, | ||
| 632 | 24126,24116,24241,24244,24249,24242,24243,24374,24376,24475,24470,24479,24714, | ||
| 633 | 24720,24710,24766,24752,24762,24787,24788,24783,24804, | ||
| 634 | 24793,24797,24776,24753,24795,24759,24778,24767,24771,24781,24768,25394,25445, | ||
| 635 | 25482,25474,25469,25533,25502,25517,25501,25495,25515,25486,25455,25479,25488, | ||
| 636 | 25454,25519,25461,25500,25453,25518,25468,25508,25403,25503,25464,25477,25473, | ||
| 637 | 25489,25485,25456,25939,26061,26213,26209,26203,26201,26204,26210,26392,26745, | ||
| 638 | 26759,26768,26780,26733,26734,26798,26795,26966,26735,26787,26796,26793,26741, | ||
| 639 | 26740,26802,26767,26743,26770,26748,26731,26738,26794,26752,26737,26750,26779, | ||
| 640 | 26774,26763,26784,26761,26788,26744,26747,26769,26764,26762,26749,27446,27443, | ||
| 641 | 27447,27448,27537,27535,27533,27534,27532,27690,28096,28075,28084,28083,28276, | ||
| 642 | 28076,28137,28130,28087,28150,28116,28160,28104,28128,28127,28118,28094,28133, | ||
| 643 | 28124,28125,28123,28148,28106,28093,28141,28144,28090,28117,28098,28111,28105, | ||
| 644 | 28112,28146,28115,28157,28119,28109,28131,28091,28922,28941,28919,28951,28916, | ||
| 645 | 28940,28912,28932,28915,28944,28924,28927,28934,28947,28928,28920,28918,28939, | ||
| 646 | 28930,28942,29310,29307,29308,29311,29469,29463,29447,29457,29464,29450,29448, | ||
| 647 | 29439,29455,29470,29576,29686,29688,29685,29700,29697,29693,29703,29696,29690, | ||
| 648 | 29692,29695,29708,29707,29684,29704,30052,30051,30158,30162,30159,30155,30156, | ||
| 649 | 30161,30160,30351,30345,30419,30521,30511,30509,30513,30514,30516,30515,30525, | ||
| 650 | 30501,30523,30517,30792,30802,30793,30797,30794,30796,30758,30789,30800,31076, | ||
| 651 | 31079,31081,31082,31075,31083,31073,31163,31226,31224,31222,31223,31375,31380, | ||
| 652 | 31376,31541,31559,31540,31525,31536,31522,31524,31539,31512,31530,31517,31537, | ||
| 653 | 31531,31533,31535,31538,31544,31514,31523,31892,31896, | ||
| 654 | 31894,31907,32053,32061,32056,32054,32058,32069,32044,32041,32065,32071,32062, | ||
| 655 | 32063,32074,32059,32040,32611,32661,32668,32669,32667,32714,32715,32717,32720, | ||
| 656 | 32721,32711,32719,32713,32799,32798,32795,32839,32835,32840,33048,33061,33049, | ||
| 657 | 33051,33069,33055,33068,33054,33057,33045,33063,33053,33058,33297,33336,33331, | ||
| 658 | 33338,33332,33330,33396,33680,33699,33704,33677,33658,33651,33700,33652,33679, | ||
| 659 | 33665,33685,33689,33653,33684,33705,33661,33667,33676,33693,33691,33706,33675, | ||
| 660 | 33662,33701,33711,33672,33687,33712,33663,33702,33671,33710,33654,33690,34393, | ||
| 661 | 34390,34495,34487,34498,34497,34501,34490,34480,34504,34489,34483,34488,34508, | ||
| 662 | 34484,34491,34492,34499,34493,34494,34898,34953,34965,34984,34978,34986,34970, | ||
| 663 | 34961,34977,34975,34968,34983,34969,34971,34967,34980,34988,34956,34963,34958, | ||
| 664 | 35202,35286,35289,35285,35376,35367,35372,35358,35897,35899,35932,35933,35965, | ||
| 665 | 36005,36221,36219,36217,36284,36290,36281,36287,36289,36568,36574,36573,36572, | ||
| 666 | 36567,36576,36577,36900,36875,36881,36892,36876,36897,37103,37098,37104,37108, | ||
| 667 | 37106,37107,37076,37099,37100,37097,37206,37208,37210,37203,37205,37356,37364, | ||
| 668 | 37361,37363,37368,37348,37369,37354,37355,37367,37352,37358,38266,38278,38280, | ||
| 669 | 38524,38509,38507,38513,38511,38591,38762,38916,39141,39319,20635,20629,20628, | ||
| 670 | 20638,20619,20643,20611,20620,20622,20637,20584,20636,20626,20610,20615,20831, | ||
| 671 | 20948,21266,21265,21412,21415,21905,21928,21925,21933,21879,22085,21922,21907, | ||
| 672 | 21896,21903,21941,21889,21923,21906,21924,21885,21900,21926,21887,21909,21921, | ||
| 673 | 21902,22284,22569,22583,22553,22558,22567,22563,22568, | ||
| 674 | 22517,22600,22565,22556,22555,22579,22591,22582,22574,22585,22584,22573,22572, | ||
| 675 | 22587,22881,23215,23188,23199,23162,23202,23198,23160,23206,23164,23205,23212, | ||
| 676 | 23189,23214,23095,23172,23178,23191,23171,23179,23209,23163,23165,23180,23196, | ||
| 677 | 23183,23187,23197,23530,23501,23499,23508,23505,23498,23502,23564,23600,23863, | ||
| 678 | 23875,23915,23873,23883,23871,23861,23889,23886,23893,23859,23866,23890,23869, | ||
| 679 | 23857,23897,23874,23865,23881,23864,23868,23858,23862,23872,23877,24132,24129, | ||
| 680 | 24408,24486,24485,24491,24777,24761,24780,24802,24782,24772,24852,24818,24842, | ||
| 681 | 24854,24837,24821,24851,24824,24828,24830,24769,24835,24856,24861,24848,24831, | ||
| 682 | 24836,24843,25162,25492,25521,25520,25550,25573,25576,25583,25539,25757,25587, | ||
| 683 | 25546,25568,25590,25557,25586,25589,25697,25567,25534,25565,25564,25540,25560, | ||
| 684 | 25555,25538,25543,25548,25547,25544,25584,25559,25561,25906,25959,25962,25956, | ||
| 685 | 25948,25960,25957,25996,26013,26014,26030,26064,26066,26236,26220,26235,26240, | ||
| 686 | 26225,26233,26218,26226,26369,26892,26835,26884,26844,26922,26860,26858,26865, | ||
| 687 | 26895,26838,26871,26859,26852,26870,26899,26896,26867,26849,26887,26828,26888, | ||
| 688 | 26992,26804,26897,26863,26822,26900,26872,26832,26877,26876,26856,26891,26890, | ||
| 689 | 26903,26830,26824,26845,26846,26854,26868,26833,26886,26836,26857,26901,26917, | ||
| 690 | 26823,27449,27451,27455,27452,27540,27543,27545,27541,27581,27632,27634,27635, | ||
| 691 | 27696,28156,28230,28231,28191,28233,28296,28220,28221,28229,28258,28203,28223, | ||
| 692 | 28225,28253,28275,28188,28211,28235,28224,28241,28219,28163,28206,28254,28264, | ||
| 693 | 28252,28257,28209,28200,28256,28273,28267,28217,28194, | ||
| 694 | 28208,28243,28261,28199,28280,28260,28279,28245,28281,28242,28262,28213,28214, | ||
| 695 | 28250,28960,28958,28975,28923,28974,28977,28963,28965,28962,28978,28959,28968, | ||
| 696 | 28986,28955,29259,29274,29320,29321,29318,29317,29323,29458,29451,29488,29474, | ||
| 697 | 29489,29491,29479,29490,29485,29478,29475,29493,29452,29742,29740,29744,29739, | ||
| 698 | 29718,29722,29729,29741,29745,29732,29731,29725,29737,29728,29746,29947,29999, | ||
| 699 | 30063,30060,30183,30170,30177,30182,30173,30175,30180,30167,30357,30354,30426, | ||
| 700 | 30534,30535,30532,30541,30533,30538,30542,30539,30540,30686,30700,30816,30820, | ||
| 701 | 30821,30812,30829,30833,30826,30830,30832,30825,30824,30814,30818,31092,31091, | ||
| 702 | 31090,31088,31234,31242,31235,31244,31236,31385,31462,31460,31562,31547,31556, | ||
| 703 | 31560,31564,31566,31552,31576,31557,31906,31902,31912,31905,32088,32111,32099, | ||
| 704 | 32083,32086,32103,32106,32079,32109,32092,32107,32082,32084,32105,32081,32095, | ||
| 705 | 32078,32574,32575,32613,32614,32674,32672,32673,32727,32849,32847,32848,33022, | ||
| 706 | 32980,33091,33098,33106,33103,33095,33085,33101,33082,33254,33262,33271,33272, | ||
| 707 | 33273,33284,33340,33341,33343,33397,33595,33743,33785,33827,33728,33768,33810, | ||
| 708 | 33767,33764,33788,33782,33808,33734,33736,33771,33763,33727,33793,33757,33765, | ||
| 709 | 33752,33791,33761,33739,33742,33750,33781,33737,33801,33807,33758,33809,33798, | ||
| 710 | 33730,33779,33749,33786,33735,33745,33770,33811,33731,33772,33774,33732,33787, | ||
| 711 | 33751,33762,33819,33755,33790,34520,34530,34534,34515,34531,34522,34538,34525, | ||
| 712 | 34539,34524,34540,34537,34519,34536,34513,34888,34902,34901,35002,35031,35001, | ||
| 713 | 35000,35008,35006,34998,35004,34999,35005,34994,35073, | ||
| 714 | 35017,35221,35224,35223,35293,35290,35291,35406,35405,35385,35417,35392,35415, | ||
| 715 | 35416,35396,35397,35410,35400,35409,35402,35404,35407,35935,35969,35968,36026, | ||
| 716 | 36030,36016,36025,36021,36228,36224,36233,36312,36307,36301,36295,36310,36316, | ||
| 717 | 36303,36309,36313,36296,36311,36293,36591,36599,36602,36601,36582,36590,36581, | ||
| 718 | 36597,36583,36584,36598,36587,36593,36588,36596,36585,36909,36916,36911,37126, | ||
| 719 | 37164,37124,37119,37116,37128,37113,37115,37121,37120,37127,37125,37123,37217, | ||
| 720 | 37220,37215,37218,37216,37377,37386,37413,37379,37402,37414,37391,37388,37376, | ||
| 721 | 37394,37375,37373,37382,37380,37415,37378,37404,37412,37401,37399,37381,37398, | ||
| 722 | 38267,38285,38284,38288,38535,38526,38536,38537,38531,38528,38594,38600,38595, | ||
| 723 | 38641,38640,38764,38768,38766,38919,39081,39147,40166,40697,20099,20100,20150, | ||
| 724 | 20669,20671,20678,20654,20676,20682,20660,20680,20674,20656,20673,20666,20657, | ||
| 725 | 20683,20681,20662,20664,20951,21114,21112,21115,21116,21955,21979,21964,21968, | ||
| 726 | 21963,21962,21981,21952,21972,21956,21993,21951,21970,21901,21967,21973,21986, | ||
| 727 | 21974,21960,22002,21965,21977,21954,22292,22611,22632,22628,22607,22605,22601, | ||
| 728 | 22639,22613,22606,22621,22617,22629,22619,22589,22627,22641,22780,23239,23236, | ||
| 729 | 23243,23226,23224,23217,23221,23216,23231,23240,23227,23238,23223,23232,23242, | ||
| 730 | 23220,23222,23245,23225,23184,23510,23512,23513,23583,23603,23921,23907,23882, | ||
| 731 | 23909,23922,23916,23902,23912,23911,23906,24048,24143,24142,24138,24141,24139, | ||
| 732 | 24261,24268,24262,24267,24263,24384,24495,24493,24823,24905,24906,24875,24901, | ||
| 733 | 24886,24882,24878,24902,24879,24911,24873,24896,25120, | ||
| 734 | 37224,25123,25125,25124,25541,25585,25579,25616,25618,25609,25632,25636,25651, | ||
| 735 | 25667,25631,25621,25624,25657,25655,25634,25635,25612,25638,25648,25640,25665, | ||
| 736 | 25653,25647,25610,25626,25664,25637,25639,25611,25575,25627,25646,25633,25614, | ||
| 737 | 25967,26002,26067,26246,26252,26261,26256,26251,26250,26265,26260,26232,26400, | ||
| 738 | 26982,26975,26936,26958,26978,26993,26943,26949,26986,26937,26946,26967,26969, | ||
| 739 | 27002,26952,26953,26933,26988,26931,26941,26981,26864,27000,26932,26985,26944, | ||
| 740 | 26991,26948,26998,26968,26945,26996,26956,26939,26955,26935,26972,26959,26961, | ||
| 741 | 26930,26962,26927,27003,26940,27462,27461,27459,27458,27464,27457,27547,64013, | ||
| 742 | 27643,27644,27641,27639,27640,28315,28374,28360,28303,28352,28319,28307,28308, | ||
| 743 | 28320,28337,28345,28358,28370,28349,28353,28318,28361,28343,28336,28365,28326, | ||
| 744 | 28367,28338,28350,28355,28380,28376,28313,28306,28302,28301,28324,28321,28351, | ||
| 745 | 28339,28368,28362,28311,28334,28323,28999,29012,29010,29027,29024,28993,29021, | ||
| 746 | 29026,29042,29048,29034,29025,28994,29016,28995,29003,29040,29023,29008,29011, | ||
| 747 | 28996,29005,29018,29263,29325,29324,29329,29328,29326,29500,29506,29499,29498, | ||
| 748 | 29504,29514,29513,29764,29770,29771,29778,29777,29783,29760,29775,29776,29774, | ||
| 749 | 29762,29766,29773,29780,29921,29951,29950,29949,29981,30073,30071,27011,30191, | ||
| 750 | 30223,30211,30199,30206,30204,30201,30200,30224,30203,30198,30189,30197,30205, | ||
| 751 | 30361,30389,30429,30549,30559,30560,30546,30550,30554,30569,30567,30548,30553, | ||
| 752 | 30573,30688,30855,30874,30868,30863,30852,30869,30853,30854,30881,30851,30841, | ||
| 753 | 30873,30848,30870,30843,31100,31106,31101,31097,31249, | ||
| 754 | 31256,31257,31250,31255,31253,31266,31251,31259,31248,31395,31394,31390,31467, | ||
| 755 | 31590,31588,31597,31604,31593,31602,31589,31603,31601,31600,31585,31608,31606, | ||
| 756 | 31587,31922,31924,31919,32136,32134,32128,32141,32127,32133,32122,32142,32123, | ||
| 757 | 32131,32124,32140,32148,32132,32125,32146,32621,32619,32615,32616,32620,32678, | ||
| 758 | 32677,32679,32731,32732,32801,33124,33120,33143,33116,33129,33115,33122,33138, | ||
| 759 | 26401,33118,33142,33127,33135,33092,33121,33309,33353,33348,33344,33346,33349, | ||
| 760 | 34033,33855,33878,33910,33913,33935,33933,33893,33873,33856,33926,33895,33840, | ||
| 761 | 33869,33917,33882,33881,33908,33907,33885,34055,33886,33847,33850,33844,33914, | ||
| 762 | 33859,33912,33842,33861,33833,33753,33867,33839,33858,33837,33887,33904,33849, | ||
| 763 | 33870,33868,33874,33903,33989,33934,33851,33863,33846,33843,33896,33918,33860, | ||
| 764 | 33835,33888,33876,33902,33872,34571,34564,34551,34572,34554,34518,34549,34637, | ||
| 765 | 34552,34574,34569,34561,34550,34573,34565,35030,35019,35021,35022,35038,35035, | ||
| 766 | 35034,35020,35024,35205,35227,35295,35301,35300,35297,35296,35298,35292,35302, | ||
| 767 | 35446,35462,35455,35425,35391,35447,35458,35460,35445,35459,35457,35444,35450, | ||
| 768 | 35900,35915,35914,35941,35940,35942,35974,35972,35973,36044,36200,36201,36241, | ||
| 769 | 36236,36238,36239,36237,36243,36244,36240,36242,36336,36320,36332,36337,36334, | ||
| 770 | 36304,36329,36323,36322,36327,36338,36331,36340,36614,36607,36609,36608,36613, | ||
| 771 | 36615,36616,36610,36619,36946,36927,36932,36937,36925,37136,37133,37135,37137, | ||
| 772 | 37142,37140,37131,37134,37230,37231,37448,37458,37424,37434,37478,37427,37477, | ||
| 773 | 37470,37507,37422,37450,37446,37485,37484,37455,37472, | ||
| 774 | 37479,37487,37430,37473,37488,37425,37460,37475,37456,37490,37454,37459,37452, | ||
| 775 | 37462,37426,38303,38300,38302,38299,38546,38547,38545,38551,38606,38650,38653, | ||
| 776 | 38648,38645,38771,38775,38776,38770,38927,38925,38926,39084,39158,39161,39343, | ||
| 777 | 39346,39344,39349,39597,39595,39771,40170,40173,40167,40576,40701,20710,20692, | ||
| 778 | 20695,20712,20723,20699,20714,20701,20708,20691,20716,20720,20719,20707,20704, | ||
| 779 | 20952,21120,21121,21225,21227,21296,21420,22055,22037,22028,22034,22012,22031, | ||
| 780 | 22044,22017,22035,22018,22010,22045,22020,22015,22009,22665,22652,22672,22680, | ||
| 781 | 22662,22657,22655,22644,22667,22650,22663,22673,22670,22646,22658,22664,22651, | ||
| 782 | 22676,22671,22782,22891,23260,23278,23269,23253,23274,23258,23277,23275,23283, | ||
| 783 | 23266,23264,23259,23276,23262,23261,23257,23272,23263,23415,23520,23523,23651, | ||
| 784 | 23938,23936,23933,23942,23930,23937,23927,23946,23945,23944,23934,23932,23949, | ||
| 785 | 23929,23935,24152,24153,24147,24280,24273,24279,24270,24284,24277,24281,24274, | ||
| 786 | 24276,24388,24387,24431,24502,24876,24872,24897,24926,24945,24947,24914,24915, | ||
| 787 | 24946,24940,24960,24948,24916,24954,24923,24933,24891,24938,24929,24918,25129, | ||
| 788 | 25127,25131,25643,25677,25691,25693,25716,25718,25714,25715,25725,25717,25702, | ||
| 789 | 25766,25678,25730,25694,25692,25675,25683,25696,25680,25727,25663,25708,25707, | ||
| 790 | 25689,25701,25719,25971,26016,26273,26272,26271,26373,26372,26402,27057,27062, | ||
| 791 | 27081,27040,27086,27030,27056,27052,27068,27025,27033,27022,27047,27021,27049, | ||
| 792 | 27070,27055,27071,27076,27069,27044,27092,27065,27082,27034,27087,27059,27027, | ||
| 793 | 27050,27041,27038,27097,27031,27024,27074,27061,27045, | ||
| 794 | 27078,27466,27469,27467,27550,27551,27552,27587,27588,27646,28366,28405,28401, | ||
| 795 | 28419,28453,28408,28471,28411,28462,28425,28494,28441,28442,28455,28440,28475, | ||
| 796 | 28434,28397,28426,28470,28531,28409,28398,28461,28480,28464,28476,28469,28395, | ||
| 797 | 28423,28430,28483,28421,28413,28406,28473,28444,28412,28474,28447,28429,28446, | ||
| 798 | 28424,28449,29063,29072,29065,29056,29061,29058,29071,29051,29062,29057,29079, | ||
| 799 | 29252,29267,29335,29333,29331,29507,29517,29521,29516,29794,29811,29809,29813, | ||
| 800 | 29810,29799,29806,29952,29954,29955,30077,30096,30230,30216,30220,30229,30225, | ||
| 801 | 30218,30228,30392,30593,30588,30597,30594,30574,30592,30575,30590,30595,30898, | ||
| 802 | 30890,30900,30893,30888,30846,30891,30878,30885,30880,30892,30882,30884,31128, | ||
| 803 | 31114,31115,31126,31125,31124,31123,31127,31112,31122,31120,31275,31306,31280, | ||
| 804 | 31279,31272,31270,31400,31403,31404,31470,31624,31644,31626,31633,31632,31638, | ||
| 805 | 31629,31628,31643,31630,31621,31640,21124,31641,31652,31618,31931,31935,31932, | ||
| 806 | 31930,32167,32183,32194,32163,32170,32193,32192,32197,32157,32206,32196,32198, | ||
| 807 | 32203,32204,32175,32185,32150,32188,32159,32166,32174,32169,32161,32201,32627, | ||
| 808 | 32738,32739,32741,32734,32804,32861,32860,33161,33158,33155,33159,33165,33164, | ||
| 809 | 33163,33301,33943,33956,33953,33951,33978,33998,33986,33964,33966,33963,33977, | ||
| 810 | 33972,33985,33997,33962,33946,33969,34000,33949,33959,33979,33954,33940,33991, | ||
| 811 | 33996,33947,33961,33967,33960,34006,33944,33974,33999,33952,34007,34004,34002, | ||
| 812 | 34011,33968,33937,34401,34611,34595,34600,34667,34624,34606,34590,34593,34585, | ||
| 813 | 34587,34627,34604,34625,34622,34630,34592,34610,34602, | ||
| 814 | 34605,34620,34578,34618,34609,34613,34626,34598,34599,34616,34596,34586,34608, | ||
| 815 | 34577,35063,35047,35057,35058,35066,35070,35054,35068,35062,35067,35056,35052, | ||
| 816 | 35051,35229,35233,35231,35230,35305,35307,35304,35499,35481,35467,35474,35471, | ||
| 817 | 35478,35901,35944,35945,36053,36047,36055,36246,36361,36354,36351,36365,36349, | ||
| 818 | 36362,36355,36359,36358,36357,36350,36352,36356,36624,36625,36622,36621,37155, | ||
| 819 | 37148,37152,37154,37151,37149,37146,37156,37153,37147,37242,37234,37241,37235, | ||
| 820 | 37541,37540,37494,37531,37498,37536,37524,37546,37517,37542,37530,37547,37497, | ||
| 821 | 37527,37503,37539,37614,37518,37506,37525,37538,37501,37512,37537,37514,37510, | ||
| 822 | 37516,37529,37543,37502,37511,37545,37533,37515,37421,38558,38561,38655,38744, | ||
| 823 | 38781,38778,38782,38787,38784,38786,38779,38788,38785,38783,38862,38861,38934, | ||
| 824 | 39085,39086,39170,39168,39175,39325,39324,39363,39353,39355,39354,39362,39357, | ||
| 825 | 39367,39601,39651,39655,39742,39743,39776,39777,39775,40177,40178,40181,40615, | ||
| 826 | 20735,20739,20784,20728,20742,20743,20726,20734,20747,20748,20733,20746,21131, | ||
| 827 | 21132,21233,21231,22088,22082,22092,22069,22081,22090,22089,22086,22104,22106, | ||
| 828 | 22080,22067,22077,22060,22078,22072,22058,22074,22298,22699,22685,22705,22688, | ||
| 829 | 22691,22703,22700,22693,22689,22783,23295,23284,23293,23287,23286,23299,23288, | ||
| 830 | 23298,23289,23297,23303,23301,23311,23655,23961,23959,23967,23954,23970,23955, | ||
| 831 | 23957,23968,23964,23969,23962,23966,24169,24157,24160,24156,32243,24283,24286, | ||
| 832 | 24289,24393,24498,24971,24963,24953,25009,25008,24994,24969,24987,24979,25007, | ||
| 833 | 25005,24991,24978,25002,24993,24973,24934,25011,25133, | ||
| 834 | 25710,25712,25750,25760,25733,25751,25756,25743,25739,25738,25740,25763,25759, | ||
| 835 | 25704,25777,25752,25974,25978,25977,25979,26034,26035,26293,26288,26281,26290, | ||
| 836 | 26295,26282,26287,27136,27142,27159,27109,27128,27157,27121,27108,27168,27135, | ||
| 837 | 27116,27106,27163,27165,27134,27175,27122,27118,27156,27127,27111,27200,27144, | ||
| 838 | 27110,27131,27149,27132,27115,27145,27140,27160,27173,27151,27126,27174,27143, | ||
| 839 | 27124,27158,27473,27557,27555,27554,27558,27649,27648,27647,27650,28481,28454, | ||
| 840 | 28542,28551,28614,28562,28557,28553,28556,28514,28495,28549,28506,28566,28534, | ||
| 841 | 28524,28546,28501,28530,28498,28496,28503,28564,28563,28509,28416,28513,28523, | ||
| 842 | 28541,28519,28560,28499,28555,28521,28543,28565,28515,28535,28522,28539,29106, | ||
| 843 | 29103,29083,29104,29088,29082,29097,29109,29085,29093,29086,29092,29089,29098, | ||
| 844 | 29084,29095,29107,29336,29338,29528,29522,29534,29535,29536,29533,29531,29537, | ||
| 845 | 29530,29529,29538,29831,29833,29834,29830,29825,29821,29829,29832,29820,29817, | ||
| 846 | 29960,29959,30078,30245,30238,30233,30237,30236,30243,30234,30248,30235,30364, | ||
| 847 | 30365,30366,30363,30605,30607,30601,30600,30925,30907,30927,30924,30929,30926, | ||
| 848 | 30932,30920,30915,30916,30921,31130,31137,31136,31132,31138,31131,27510,31289, | ||
| 849 | 31410,31412,31411,31671,31691,31678,31660,31694,31663,31673,31690,31669,31941, | ||
| 850 | 31944,31948,31947,32247,32219,32234,32231,32215,32225,32259,32250,32230,32246, | ||
| 851 | 32241,32240,32238,32223,32630,32684,32688,32685,32749,32747,32746,32748,32742, | ||
| 852 | 32744,32868,32871,33187,33183,33182,33173,33186,33177,33175,33302,33359,33363, | ||
| 853 | 33362,33360,33358,33361,34084,34107,34063,34048,34089, | ||
| 854 | 34062,34057,34061,34079,34058,34087,34076,34043,34091,34042,34056,34060,34036, | ||
| 855 | 34090,34034,34069,34039,34027,34035,34044,34066,34026,34025,34070,34046,34088, | ||
| 856 | 34077,34094,34050,34045,34078,34038,34097,34086,34023,34024,34032,34031,34041, | ||
| 857 | 34072,34080,34096,34059,34073,34095,34402,34646,34659,34660,34679,34785,34675, | ||
| 858 | 34648,34644,34651,34642,34657,34650,34641,34654,34669,34666,34640,34638,34655, | ||
| 859 | 34653,34671,34668,34682,34670,34652,34661,34639,34683,34677,34658,34663,34665, | ||
| 860 | 34906,35077,35084,35092,35083,35095,35096,35097,35078,35094,35089,35086,35081, | ||
| 861 | 35234,35236,35235,35309,35312,35308,35535,35526,35512,35539,35537,35540,35541, | ||
| 862 | 35515,35543,35518,35520,35525,35544,35523,35514,35517,35545,35902,35917,35983, | ||
| 863 | 36069,36063,36057,36072,36058,36061,36071,36256,36252,36257,36251,36384,36387, | ||
| 864 | 36389,36388,36398,36373,36379,36374,36369,36377,36390,36391,36372,36370,36376, | ||
| 865 | 36371,36380,36375,36378,36652,36644,36632,36634,36640,36643,36630,36631,36979, | ||
| 866 | 36976,36975,36967,36971,37167,37163,37161,37162,37170,37158,37166,37253,37254, | ||
| 867 | 37258,37249,37250,37252,37248,37584,37571,37572,37568,37593,37558,37583,37617, | ||
| 868 | 37599,37592,37609,37591,37597,37580,37615,37570,37608,37578,37576,37582,37606, | ||
| 869 | 37581,37589,37577,37600,37598,37607,37585,37587,37557,37601,37574,37556,38268, | ||
| 870 | 38316,38315,38318,38320,38564,38562,38611,38661,38664,38658,38746,38794,38798, | ||
| 871 | 38792,38864,38863,38942,38941,38950,38953,38952,38944,38939,38951,39090,39176, | ||
| 872 | 39162,39185,39188,39190,39191,39189,39388,39373,39375,39379,39380,39374,39369, | ||
| 873 | 39382,39384,39371,39383,39372,39603,39660,39659,39667, | ||
| 874 | 39666,39665,39750,39747,39783,39796,39793,39782,39798,39797,39792,39784,39780, | ||
| 875 | 39788,40188,40186,40189,40191,40183,40199,40192,40185,40187,40200,40197,40196, | ||
| 876 | 40579,40659,40719,40720,20764,20755,20759,20762,20753,20958,21300,21473,22128, | ||
| 877 | 22112,22126,22131,22118,22115,22125,22130,22110,22135,22300,22299,22728,22717, | ||
| 878 | 22729,22719,22714,22722,22716,22726,23319,23321,23323,23329,23316,23315,23312, | ||
| 879 | 23318,23336,23322,23328,23326,23535,23980,23985,23977,23975,23989,23984,23982, | ||
| 880 | 23978,23976,23986,23981,23983,23988,24167,24168,24166,24175,24297,24295,24294, | ||
| 881 | 24296,24293,24395,24508,24989,25000,24982,25029,25012,25030,25025,25036,25018, | ||
| 882 | 25023,25016,24972,25815,25814,25808,25807,25801,25789,25737,25795,25819,25843, | ||
| 883 | 25817,25907,25983,25980,26018,26312,26302,26304,26314,26315,26319,26301,26299, | ||
| 884 | 26298,26316,26403,27188,27238,27209,27239,27186,27240,27198,27229,27245,27254, | ||
| 885 | 27227,27217,27176,27226,27195,27199,27201,27242,27236,27216,27215,27220,27247, | ||
| 886 | 27241,27232,27196,27230,27222,27221,27213,27214,27206,27477,27476,27478,27559, | ||
| 887 | 27562,27563,27592,27591,27652,27651,27654,28589,28619,28579,28615,28604,28622, | ||
| 888 | 28616,28510,28612,28605,28574,28618,28584,28676,28581,28590,28602,28588,28586, | ||
| 889 | 28623,28607,28600,28578,28617,28587,28621,28591,28594,28592,29125,29122,29119, | ||
| 890 | 29112,29142,29120,29121,29131,29140,29130,29127,29135,29117,29144,29116,29126, | ||
| 891 | 29146,29147,29341,29342,29545,29542,29543,29548,29541,29547,29546,29823,29850, | ||
| 892 | 29856,29844,29842,29845,29857,29963,30080,30255,30253,30257,30269,30259,30268, | ||
| 893 | 30261,30258,30256,30395,30438,30618,30621,30625,30620, | ||
| 894 | 30619,30626,30627,30613,30617,30615,30941,30953,30949,30954,30942,30947,30939, | ||
| 895 | 30945,30946,30957,30943,30944,31140,31300,31304,31303,31414,31416,31413,31409, | ||
| 896 | 31415,31710,31715,31719,31709,31701,31717,31706,31720,31737,31700,31722,31714, | ||
| 897 | 31708,31723,31704,31711,31954,31956,31959,31952,31953,32274,32289,32279,32268, | ||
| 898 | 32287,32288,32275,32270,32284,32277,32282,32290,32267,32271,32278,32269,32276, | ||
| 899 | 32293,32292,32579,32635,32636,32634,32689,32751,32810,32809,32876,33201,33190, | ||
| 900 | 33198,33209,33205,33195,33200,33196,33204,33202,33207,33191,33266,33365,33366, | ||
| 901 | 33367,34134,34117,34155,34125,34131,34145,34136,34112,34118,34148,34113,34146, | ||
| 902 | 34116,34129,34119,34147,34110,34139,34161,34126,34158,34165,34133,34151,34144, | ||
| 903 | 34188,34150,34141,34132,34149,34156,34403,34405,34404,34715,34703,34711,34707, | ||
| 904 | 34706,34696,34689,34710,34712,34681,34695,34723,34693,34704,34705,34717,34692, | ||
| 905 | 34708,34716,34714,34697,35102,35110,35120,35117,35118,35111,35121,35106,35113, | ||
| 906 | 35107,35119,35116,35103,35313,35552,35554,35570,35572,35573,35549,35604,35556, | ||
| 907 | 35551,35568,35528,35550,35553,35560,35583,35567,35579,35985,35986,35984,36085, | ||
| 908 | 36078,36081,36080,36083,36204,36206,36261,36263,36403,36414,36408,36416,36421, | ||
| 909 | 36406,36412,36413,36417,36400,36415,36541,36662,36654,36661,36658,36665,36663, | ||
| 910 | 36660,36982,36985,36987,36998,37114,37171,37173,37174,37267,37264,37265,37261, | ||
| 911 | 37263,37671,37662,37640,37663,37638,37647,37754,37688,37692,37659,37667,37650, | ||
| 912 | 37633,37702,37677,37646,37645,37579,37661,37626,37669,37651,37625,37623,37684, | ||
| 913 | 37634,37668,37631,37673,37689,37685,37674,37652,37644, | ||
| 914 | 37643,37630,37641,37632,37627,37654,38332,38349,38334,38329,38330,38326,38335, | ||
| 915 | 38325,38333,38569,38612,38667,38674,38672,38809,38807,38804,38896,38904,38965, | ||
| 916 | 38959,38962,39204,39199,39207,39209,39326,39406,39404,39397,39396,39408,39395, | ||
| 917 | 39402,39401,39399,39609,39615,39604,39611,39670,39674,39673,39671,39731,39808, | ||
| 918 | 39813,39815,39804,39806,39803,39810,39827,39826,39824,39802,39829,39805,39816, | ||
| 919 | 40229,40215,40224,40222,40212,40233,40221,40216,40226,40208,40217,40223,40584, | ||
| 920 | 40582,40583,40622,40621,40661,40662,40698,40722,40765,20774,20773,20770,20772, | ||
| 921 | 20768,20777,21236,22163,22156,22157,22150,22148,22147,22142,22146,22143,22145, | ||
| 922 | 22742,22740,22735,22738,23341,23333,23346,23331,23340,23335,23334,23343,23342, | ||
| 923 | 23419,23537,23538,23991,24172,24170,24510,24507,25027,25013,25020,25063,25056, | ||
| 924 | 25061,25060,25064,25054,25839,25833,25827,25835,25828,25832,25985,25984,26038, | ||
| 925 | 26074,26322,27277,27286,27265,27301,27273,27295,27291,27297,27294,27271,27283, | ||
| 926 | 27278,27285,27267,27304,27300,27281,27263,27302,27290,27269,27276,27282,27483, | ||
| 927 | 27565,27657,28620,28585,28660,28628,28643,28636,28653,28647,28646,28638,28658, | ||
| 928 | 28637,28642,28648,29153,29169,29160,29170,29156,29168,29154,29555,29550,29551, | ||
| 929 | 29847,29874,29867,29840,29866,29869,29873,29861,29871,29968,29969,29970,29967, | ||
| 930 | 30084,30275,30280,30281,30279,30372,30441,30645,30635,30642,30647,30646,30644, | ||
| 931 | 30641,30632,30704,30963,30973,30978,30971,30972,30962,30981,30969,30974,30980, | ||
| 932 | 31147,31144,31324,31323,31318,31320,31316,31322,31422,31424,31425,31749,31759, | ||
| 933 | 31730,31744,31743,31739,31758,31732,31755,31731,31746, | ||
| 934 | 31753,31747,31745,31736,31741,31750,31728,31729,31760,31754,31976,32301,32316, | ||
| 935 | 32322,32307,38984,32312,32298,32329,32320,32327,32297,32332,32304,32315,32310, | ||
| 936 | 32324,32314,32581,32639,32638,32637,32756,32754,32812,33211,33220,33228,33226, | ||
| 937 | 33221,33223,33212,33257,33371,33370,33372,34179,34176,34191,34215,34197,34208, | ||
| 938 | 34187,34211,34171,34212,34202,34206,34167,34172,34185,34209,34170,34168,34135, | ||
| 939 | 34190,34198,34182,34189,34201,34205,34177,34210,34178,34184,34181,34169,34166, | ||
| 940 | 34200,34192,34207,34408,34750,34730,34733,34757,34736,34732,34745,34741,34748, | ||
| 941 | 34734,34761,34755,34754,34764,34743,34735,34756,34762,34740,34742,34751,34744, | ||
| 942 | 34749,34782,34738,35125,35123,35132,35134,35137,35154,35127,35138,35245,35247, | ||
| 943 | 35246,35314,35315,35614,35608,35606,35601,35589,35595,35618,35599,35602,35605, | ||
| 944 | 35591,35597,35592,35590,35612,35603,35610,35919,35952,35954,35953,35951,35989, | ||
| 945 | 35988,36089,36207,36430,36429,36435,36432,36428,36423,36675,36672,36997,36990, | ||
| 946 | 37176,37274,37282,37275,37273,37279,37281,37277,37280,37793,37763,37807,37732, | ||
| 947 | 37718,37703,37756,37720,37724,37750,37705,37712,37713,37728,37741,37775,37708, | ||
| 948 | 37738,37753,37719,37717,37714,37711,37745,37751,37755,37729,37726,37731,37735, | ||
| 949 | 37760,37710,37721,38343,38336,38345,38339,38341,38327,38574,38576,38572,38688, | ||
| 950 | 38687,38680,38685,38681,38810,38817,38812,38814,38813,38869,38868,38897,38977, | ||
| 951 | 38980,38986,38985,38981,38979,39205,39211,39212,39210,39219,39218,39215,39213, | ||
| 952 | 39217,39216,39320,39331,39329,39426,39418,39412,39415,39417,39416,39414,39419, | ||
| 953 | 39421,39422,39420,39427,39614,39678,39677,39681,39676, | ||
| 954 | 39752,39834,39848,39838,39835,39846,39841,39845,39844,39814,39842,39840,39855, | ||
| 955 | 40243,40257,40295,40246,40238,40239,40241,40248,40240,40261,40258,40259,40254, | ||
| 956 | 40247,40256,40253,32757,40237,40586,40585,40589,40624,40648,40666,40699,40703, | ||
| 957 | 40740,40739,40738,40788,40864,20785,20781,20782,22168,22172,22167,22170,22173, | ||
| 958 | 22169,22896,23356,23657,23658,24000,24173,24174,25048,25055,25069,25070,25073, | ||
| 959 | 25066,25072,25067,25046,25065,25855,25860,25853,25848,25857,25859,25852,26004, | ||
| 960 | 26075,26330,26331,26328,27333,27321,27325,27361,27334,27322,27318,27319,27335, | ||
| 961 | 27316,27309,27486,27593,27659,28679,28684,28685,28673,28677,28692,28686,28671, | ||
| 962 | 28672,28667,28710,28668,28663,28682,29185,29183,29177,29187,29181,29558,29880, | ||
| 963 | 29888,29877,29889,29886,29878,29883,29890,29972,29971,30300,30308,30297,30288, | ||
| 964 | 30291,30295,30298,30374,30397,30444,30658,30650,30975,30988,30995,30996,30985, | ||
| 965 | 30992,30994,30993,31149,31148,31327,31772,31785,31769,31776,31775,31789,31773, | ||
| 966 | 31782,31784,31778,31781,31792,32348,32336,32342,32355,32344,32354,32351,32337, | ||
| 967 | 32352,32343,32339,32693,32691,32759,32760,32885,33233,33234,33232,33375,33374, | ||
| 968 | 34228,34246,34240,34243,34242,34227,34229,34237,34247,34244,34239,34251,34254, | ||
| 969 | 34248,34245,34225,34230,34258,34340,34232,34231,34238,34409,34791,34790,34786, | ||
| 970 | 34779,34795,34794,34789,34783,34803,34788,34772,34780,34771,34797,34776,34787, | ||
| 971 | 34724,34775,34777,34817,34804,34792,34781,35155,35147,35151,35148,35142,35152, | ||
| 972 | 35153,35145,35626,35623,35619,35635,35632,35637,35655,35631,35644,35646,35633, | ||
| 973 | 35621,35639,35622,35638,35630,35620,35643,35645,35642, | ||
| 974 | 35906,35957,35993,35992,35991,36094,36100,36098,36096,36444,36450,36448,36439, | ||
| 975 | 36438,36446,36453,36455,36443,36442,36449,36445,36457,36436,36678,36679,36680, | ||
| 976 | 36683,37160,37178,37179,37182,37288,37285,37287,37295,37290,37813,37772,37778, | ||
| 977 | 37815,37787,37789,37769,37799,37774,37802,37790,37798,37781,37768,37785,37791, | ||
| 978 | 37773,37809,37777,37810,37796,37800,37812,37795,37797,38354,38355,38353,38579, | ||
| 979 | 38615,38618,24002,38623,38616,38621,38691,38690,38693,38828,38830,38824,38827, | ||
| 980 | 38820,38826,38818,38821,38871,38873,38870,38872,38906,38992,38993,38994,39096, | ||
| 981 | 39233,39228,39226,39439,39435,39433,39437,39428,39441,39434,39429,39431,39430, | ||
| 982 | 39616,39644,39688,39684,39685,39721,39733,39754,39756,39755,39879,39878,39875, | ||
| 983 | 39871,39873,39861,39864,39891,39862,39876,39865,39869,40284,40275,40271,40266, | ||
| 984 | 40283,40267,40281,40278,40268,40279,40274,40276,40287,40280,40282,40590,40588, | ||
| 985 | 40671,40705,40704,40726,40741,40747,40746,40745,40744,40780,40789,20788,20789, | ||
| 986 | 21142,21239,21428,22187,22189,22182,22183,22186,22188,22746,22749,22747,22802, | ||
| 987 | 23357,23358,23359,24003,24176,24511,25083,25863,25872,25869,25865,25868,25870, | ||
| 988 | 25988,26078,26077,26334,27367,27360,27340,27345,27353,27339,27359,27356,27344, | ||
| 989 | 27371,27343,27341,27358,27488,27568,27660,28697,28711,28704,28694,28715,28705, | ||
| 990 | 28706,28707,28713,28695,28708,28700,28714,29196,29194,29191,29186,29189,29349, | ||
| 991 | 29350,29348,29347,29345,29899,29893,29879,29891,29974,30304,30665,30666,30660, | ||
| 992 | 30705,31005,31003,31009,31004,30999,31006,31152,31335,31336,31795,31804,31801, | ||
| 993 | 31788,31803,31980,31978,32374,32373,32376,32368,32375, | ||
| 994 | 32367,32378,32370,32372,32360,32587,32586,32643,32646,32695,32765,32766,32888, | ||
| 995 | 33239,33237,33380,33377,33379,34283,34289,34285,34265,34273,34280,34266,34263, | ||
| 996 | 34284,34290,34296,34264,34271,34275,34268,34257,34288,34278,34287,34270,34274, | ||
| 997 | 34816,34810,34819,34806,34807,34825,34828,34827,34822,34812,34824,34815,34826, | ||
| 998 | 34818,35170,35162,35163,35159,35169,35164,35160,35165,35161,35208,35255,35254, | ||
| 999 | 35318,35664,35656,35658,35648,35667,35670,35668,35659,35669,35665,35650,35666, | ||
| 1000 | 35671,35907,35959,35958,35994,36102,36103,36105,36268,36266,36269,36267,36461, | ||
| 1001 | 36472,36467,36458,36463,36475,36546,36690,36689,36687,36688,36691,36788,37184, | ||
| 1002 | 37183,37296,37293,37854,37831,37839,37826,37850,37840,37881,37868,37836,37849, | ||
| 1003 | 37801,37862,37834,37844,37870,37859,37845,37828,37838,37824,37842,37863,38269, | ||
| 1004 | 38362,38363,38625,38697,38699,38700,38696,38694,38835,38839,38838,38877,38878, | ||
| 1005 | 38879,39004,39001,39005,38999,39103,39101,39099,39102,39240,39239,39235,39334, | ||
| 1006 | 39335,39450,39445,39461,39453,39460,39451,39458,39456,39463,39459,39454,39452, | ||
| 1007 | 39444,39618,39691,39690,39694,39692,39735,39914,39915,39904,39902,39908,39910, | ||
| 1008 | 39906,39920,39892,39895,39916,39900,39897,39909,39893,39905,39898,40311,40321, | ||
| 1009 | 40330,40324,40328,40305,40320,40312,40326,40331,40332,40317,40299,40308,40309, | ||
| 1010 | 40304,40297,40325,40307,40315,40322,40303,40313,40319,40327,40296,40596,40593, | ||
| 1011 | 40640,40700,40749,40768,40769,40781,40790,40791,40792,21303,22194,22197,22195, | ||
| 1012 | 22755,23365,24006,24007,24302,24303,24512,24513,25081,25879,25878,25877,25875, | ||
| 1013 | 26079,26344,26339,26340,27379,27376,27370,27368,27385, | ||
| 1014 | 27377,27374,27375,28732,28725,28719,28727,28724,28721,28738,28728,28735,28730, | ||
| 1015 | 28729,28736,28731,28723,28737,29203,29204,29352,29565,29564,29882,30379,30378, | ||
| 1016 | 30398,30445,30668,30670,30671,30669,30706,31013,31011,31015,31016,31012,31017, | ||
| 1017 | 31154,31342,31340,31341,31479,31817,31816,31818,31815,31813,31982,32379,32382, | ||
| 1018 | 32385,32384,32698,32767,32889,33243,33241,33291,33384,33385,34338,34303,34305, | ||
| 1019 | 34302,34331,34304,34294,34308,34313,34309,34316,34301,34841,34832,34833,34839, | ||
| 1020 | 34835,34838,35171,35174,35257,35319,35680,35690,35677,35688,35683,35685,35687, | ||
| 1021 | 35693,36270,36486,36488,36484,36697,36694,36695,36693,36696,36698,37005,37187, | ||
| 1022 | 37185,37303,37301,37298,37299,37899,37907,37883,37920,37903,37908,37886,37909, | ||
| 1023 | 37904,37928,37913,37901,37877,37888,37879,37895,37902,37910,37906,37882,37897, | ||
| 1024 | 37880,37898,37887,37884,37900,37878,37905,37894,38366,38368,38367,38702,38703, | ||
| 1025 | 38841,38843,38909,38910,39008,39010,39011,39007,39105,39106,39248,39246,39257, | ||
| 1026 | 39244,39243,39251,39474,39476,39473,39468,39466,39478,39465,39470,39480,39469, | ||
| 1027 | 39623,39626,39622,39696,39698,39697,39947,39944,39927,39941,39954,39928,40000, | ||
| 1028 | 39943,39950,39942,39959,39956,39945,40351,40345,40356,40349,40338,40344,40336, | ||
| 1029 | 40347,40352,40340,40348,40362,40343,40353,40346,40354,40360,40350,40355,40383, | ||
| 1030 | 40361,40342,40358,40359,40601,40603,40602,40677,40676,40679,40678,40752,40750, | ||
| 1031 | 40795,40800,40798,40797,40793,40849,20794,20793,21144,21143,22211,22205,22206, | ||
| 1032 | 23368,23367,24011,24015,24305,25085,25883,27394,27388,27395,27384,27392,28739, | ||
| 1033 | 28740,28746,28744,28745,28741,28742,29213,29210,29209, | ||
| 1034 | 29566,29975,30314,30672,31021,31025,31023,31828,31827,31986,32394,32391,32392, | ||
| 1035 | 32395,32390,32397,32589,32699,32816,33245,34328,34346,34342,34335,34339,34332, | ||
| 1036 | 34329,34343,34350,34337,34336,34345,34334,34341,34857,34845,34843,34848,34852, | ||
| 1037 | 34844,34859,34890,35181,35177,35182,35179,35322,35705,35704,35653,35706,35707, | ||
| 1038 | 36112,36116,36271,36494,36492,36702,36699,36701,37190,37188,37189,37305,37951, | ||
| 1039 | 37947,37942,37929,37949,37948,37936,37945,37930,37943,37932,37952,37937,38373, | ||
| 1040 | 38372,38371,38709,38714,38847,38881,39012,39113,39110,39104,39256,39254,39481, | ||
| 1041 | 39485,39494,39492,39490,39489,39482,39487,39629,39701,39703,39704,39702,39738, | ||
| 1042 | 39762,39979,39965,39964,39980,39971,39976,39977,39972,39969,40375,40374,40380, | ||
| 1043 | 40385,40391,40394,40399,40382,40389,40387,40379,40373,40398,40377,40378,40364, | ||
| 1044 | 40392,40369,40365,40396,40371,40397,40370,40570,40604,40683,40686,40685,40731, | ||
| 1045 | 40728,40730,40753,40782,40805,40804,40850,20153,22214,22213,22219,22897,23371, | ||
| 1046 | 23372,24021,24017,24306,25889,25888,25894,25890,27403,27400,27401,27661,28757, | ||
| 1047 | 28758,28759,28754,29214,29215,29353,29567,29912,29909,29913,29911,30317,30381, | ||
| 1048 | 31029,31156,31344,31345,31831,31836,31833,31835,31834,31988,31985,32401,32591, | ||
| 1049 | 32647,33246,33387,34356,34357,34355,34348,34354,34358,34860,34856,34854,34858, | ||
| 1050 | 34853,35185,35263,35262,35323,35710,35716,35714,35718,35717,35711,36117,36501, | ||
| 1051 | 36500,36506,36498,36496,36502,36503,36704,36706,37191,37964,37968,37962,37963, | ||
| 1052 | 37967,37959,37957,37960,37961,37958,38719,38883,39018,39017,39115,39252,39259, | ||
| 1053 | 39502,39507,39508,39500,39503,39496,39498,39497,39506, | ||
| 1054 | 39504,39632,39705,39723,39739,39766,39765,40006,40008,39999,40004,39993,39987, | ||
| 1055 | 40001,39996,39991,39988,39986,39997,39990,40411,40402,40414,40410,40395,40400, | ||
| 1056 | 40412,40401,40415,40425,40409,40408,40406,40437,40405,40413,40630,40688,40757, | ||
| 1057 | 40755,40754,40770,40811,40853,40866,20797,21145,22760,22759,22898,23373,24024, | ||
| 1058 | 34863,24399,25089,25091,25092,25897,25893,26006,26347,27409,27410,27407,27594, | ||
| 1059 | 28763,28762,29218,29570,29569,29571,30320,30676,31847,31846,32405,33388,34362, | ||
| 1060 | 34368,34361,34364,34353,34363,34366,34864,34866,34862,34867,35190,35188,35187, | ||
| 1061 | 35326,35724,35726,35723,35720,35909,36121,36504,36708,36707,37308,37986,37973, | ||
| 1062 | 37981,37975,37982,38852,38853,38912,39510,39513,39710,39711,39712,40018,40024, | ||
| 1063 | 40016,40010,40013,40011,40021,40025,40012,40014,40443,40439,40431,40419,40427, | ||
| 1064 | 40440,40420,40438,40417,40430,40422,40434,40432,40418,40428,40436,40435,40424, | ||
| 1065 | 40429,40642,40656,40690,40691,40710,40732,40760,40759,40758,40771,40783,40817, | ||
| 1066 | 40816,40814,40815,22227,22221,23374,23661,25901,26349,26350,27411,28767,28769, | ||
| 1067 | 28765,28768,29219,29915,29925,30677,31032,31159,31158,31850,32407,32649,33389, | ||
| 1068 | 34371,34872,34871,34869,34891,35732,35733,36510,36511,36512,36509,37310,37309, | ||
| 1069 | 37314,37995,37992,37993,38629,38726,38723,38727,38855,38885,39518,39637,39769, | ||
| 1070 | 40035,40039,40038,40034,40030,40032,40450,40446,40455,40451,40454,40453,40448, | ||
| 1071 | 40449,40457,40447,40445,40452,40608,40734,40774,40820,40821,40822,22228,25902, | ||
| 1072 | 26040,27416,27417,27415,27418,28770,29222,29354,30680,30681,31033,31849,31851, | ||
| 1073 | 31990,32410,32408,32411,32409,33248,33249,34374,34375, | ||
| 1074 | 34376,35193,35194,35196,35195,35327,35736,35737,36517,36516,36515,37998,37997, | ||
| 1075 | 37999,38001,38003,38729,39026,39263,40040,40046,40045,40459,40461,40464,40463, | ||
| 1076 | 40466,40465,40609,40693,40713,40775,40824,40827,40826,40825,22302,28774,31855, | ||
| 1077 | 34876,36274,36518,37315,38004,38008,38006,38005,39520,40052,40051,40049,40053, | ||
| 1078 | 40468,40467,40694,40714,40868,28776,28773,31991,34410,34878,34877,34879,35742, | ||
| 1079 | 35996,36521,36553,38731,39027,39028,39116,39265,39339,39524,39526,39527,39716, | ||
| 1080 | 40469,40471,40776,25095,27422,29223,34380,36520,38018,38016,38017,39529,39528, | ||
| 1081 | 39726,40473,29225,34379,35743,38019,40057,40631,30325,39531,40058,40477,28777, | ||
| 1082 | 28778,40612,40830,40777,40856,30849,37561,35023,22715,24658,31911,23290,9556, | ||
| 1083 | 9574,9559,9568,9580,9571,9562,9577,9565,9554,9572,9557,9566,9578,9569,9560, | ||
| 1084 | 9575,9563,9555,9573,9558,9567,9579,9570,9561,9576,9564,9553,9552,9581,9582, | ||
| 1085 | 9584,9583,9619, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/bind_textdomain_codeset.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <libintl.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | char *bind_textdomain_codeset(const char *domainname, const char *codeset) | ||
| 7 | { | ||
| 8 | 	if (codeset && strcasecmp(codeset, "UTF-8")) | ||
| 9 | 		errno = EINVAL; | ||
| 10 | 	return NULL; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/c_locale.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "locale_impl.h" | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | static const uint32_t empty_mo[] = { 0x950412de, 0, -1, -1, -1 }; | ||
| 5 | |||
| 6 | const struct __locale_map __c_dot_utf8 = { | ||
| 7 | 	.map = empty_mo, | ||
| 8 | 	.map_size = sizeof empty_mo, | ||
| 9 | 	.name = "C.UTF-8" | ||
| 10 | }; | ||
| 11 | |||
| 12 | const struct __locale_struct __c_locale = { 0 }; | ||
| 13 | const struct __locale_struct __c_dot_utf8_locale = { | ||
| 14 | 	.cat[LC_CTYPE] = &__c_dot_utf8 | ||
| 15 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/locale/catclose.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 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 created+44| ... | @@ -0,0 +1,44 @@ | ||
| 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 created+87| ... | @@ -0,0 +1,87 @@ | ||
| 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/codepages.h created+320| ... | @@ -0,0 +1,320 @@ | ||
| 1 | "iso88591\0" | ||
| 2 | "latin1\0" | ||
| 3 | "\0\100" | ||
| 4 | |||
| 5 | "iso88592\0" | ||
| 6 | "\0\50" | ||
| 7 | "\240\20\364\127\116\244\334\364\324\51\250\124\65\125\126\156\265\42\27\134" | ||
| 8 | "\260\24\24\230\116\264\340\4\225\137\270\130\105\225\126\157\15\66\127\134" | ||
| 9 | "\111\5\43\214\100\304\314\144\320\61\14\45\143\321\62\30\65\343\214\103" | ||
| 10 | "\20\355\364\323\64\324\24\145\315\65\115\215\245\115\131\334\164\163\325\67" | ||
| 11 | "\112\205\43\316\100\344\320\164\320\71\15\245\163\321\72\31\265\343\316\103" | ||
| 12 | "\21\361\4\324\74\364\30\145\317\75\116\221\245\217\131\374\364\203\25\140" | ||
| 13 | |||
| 14 | "iso88593\0" | ||
| 15 | "\0\50" | ||
| 16 | "\240\220\364\327\50\244\0\40\322\51\250\260\64\25\107\56\265\2\0\134" | ||
| 17 | "\260\224\44\313\54\264\324\62\322\55\270\264\104\125\107\57\365\2\100\134" | ||
| 18 | "\300\4\43\14\0\304\50\204\320\61\310\44\243\314\62\314\64\343\314\63" | ||
| 19 | "\0\104\43\315\64\324\170\144\315\65\32\145\243\315\66\334\204\25\325\67" | ||
| 20 | "\340\204\43\16\0\344\54\224\320\71\350\244\243\316\72\354\264\343\316\73" | ||
| 21 | "\0\304\43\317\74\364\174\144\317\75\33\345\243\317\76\374\210\45\25\140" | ||
| 22 | |||
| 23 | "iso88594\0" | ||
| 24 | "\0\50" | ||
| 25 | "\240\20\44\323\122\244\230\124\323\51\250\124\45\21\110\133\265\42\327\53" | ||
| 26 | "\260\24\24\30\123\264\234\144\223\137\270\130\65\121\110\134\5\65\227\120" | ||
| 27 | "\0\5\43\314\60\304\24\143\214\112\14\45\143\321\62\24\65\343\14\112" | ||
| 28 | "\20\365\64\24\114\324\124\143\315\65\330\234\245\315\66\334\164\365\325\67" | ||
| 29 | "\1\205\43\316\70\344\224\143\316\112\15\245\163\321\72\25\265\343\116\112" | ||
| 30 | "\21\371\104\124\114\364\324\143\317\75\370\240\245\317\76\374\170\5\26\140" | ||
| 31 | |||
| 32 | "iso88595\0" | ||
| 33 | "\0\50" | ||
| 34 | "\240\104\47\335\164\324\125\147\335\165\330\145\247\335\166" | ||
| 35 | "\334\265\322\235\167\337\201\27\236\170\343\221\127\236\171" | ||
| 36 | "\347\241\227\236\172\353\261\327\236\173\357\301\27\237\174" | ||
| 37 | "\363\321\127\237\175\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200" | ||
| 38 | "\3\22\130\240\201\7\42\230\240\202\13\62\330\240\203\17\102\30\241\204" | ||
| 39 | "\23\122\130\241\205\27\142\230\241\206\33\162\330\241\207\46\177\10\142\210" | ||
| 40 | "\42\216\110\142\211\46\236\210\142\212\52\236\262\42\213" | ||
| 41 | |||
| 42 | "iso88596\0" | ||
| 43 | "\0\50" | ||
| 44 | "\240\0\0\0\0\244\0\0\0\0\0\0\0\0\0\142\266\2\0\0\0\0\0\0\0\0\0\0\0\0" | ||
| 45 | "\0\0\0\300\230\0\0\0\0\231\0\224\151\346\231\150\246\251\346\232" | ||
| 46 | "\154\266\351\346\233\160\306\51\347\234\164\326\151\347\235" | ||
| 47 | "\170\346\251\347\236\174\366\351\47\0\0\0\0\0\0\177\2\32\250\240" | ||
| 48 | "\203\22\132\250\241\207\42\232\250\242\213\62\332\250\243\217\102\32\51\0" | ||
| 49 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
| 50 | |||
| 51 | "iso88597\0" | ||
| 52 | "\0\50" | ||
| 53 | "\240\114\114\361\50\44\227\154\312\51\250\244\222\330\52\254\264\2\100\304" | ||
| 54 | "\260\304\42\313\54\212\55\306\330\55\215\71\366\330\56\220\365\22\231\144" | ||
| 55 | "\223\121\126\231\145\227\141\226\231\146\233\161\326\231\147" | ||
| 56 | "\237\201\26\232\150\243\221\6\100\151\246\235\206\132\152\252\255\306\132\153" | ||
| 57 | "\256\275\6\133\154\262\315\106\133\155\266\335\206\133\156\272\355\306\133\157" | ||
| 58 | "\276\375\6\134\160\302\15\107\134\161\306\35\207\134\162\312\55\307\134\163" | ||
| 59 | "\316\75\7\35\0" | ||
| 60 | |||
| 61 | "iso88598\0" | ||
| 62 | "\0\50" | ||
| 63 | "\240\0\40\312\50\244\224\142\312\51\250\244\162\315\52\254\264\342\312\53" | ||
| 64 | "\260\304\42\313\54\264\324\142\313\55\270\344\162\317\56\274\364\342\13\0" | ||
| 65 | "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0" | ||
| 66 | "\0\0\0\200\304\102\16\111\144\221\106\36\211\144\222\112\56\311\144\223" | ||
| 67 | "\116\76\11\145\224\122\116\111\145\225\126\136\211\145\226\132\156\311\45\0" | ||
| 68 | "\0\64\354\60\0" | ||
| 69 | |||
| 70 | "iso88599\0" | ||
| 71 | "\0\64" | ||
| 72 | "\34\105\43\315\64\324\124\143\315\65\330\144\243\315\66\334\260\64\325\67" | ||
| 73 | "\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73" | ||
| 74 | "\35\305\43\317\74\364\324\143\317\75\370\344\243\317\76\374\264\104\325\77" | ||
| 75 | |||
| 76 | "iso885910\0" | ||
| 77 | "\0\50" | ||
| 78 | "\240\20\44\21\110\50\231\4\323\51\65\101\124\325\126\162\265\362\125\120" | ||
| 79 | "\260\24\64\121\110\51\235\24\323\55\66\105\144\25\127\163\105\14\226\120" | ||
| 80 | "\0\5\43\314\60\304\24\143\214\112\14\45\143\321\62\24\65\343\314\63" | ||
| 81 | "\320\364\64\324\64\324\124\143\115\127\330\234\245\315\66\334\164\343\315\67" | ||
| 82 | "\1\205\43\316\70\344\224\143\316\112\15\245\163\321\72\25\265\343\316\73" | ||
| 83 | "\360\370\104\324\74\364\324\143\217\127\370\240\245\317\76\374\364\343\217\114" | ||
| 84 | |||
| 85 | "iso885911\0" | ||
| 86 | "tis620\0" | ||
| 87 | "\0\50" | ||
| 88 | "\240\170\372\51\250\241\212\72\52\251\245\232\172\52\252\251\252\272\52\253" | ||
| 89 | "\255\272\372\52\254\261\312\72\53\255\265\332\172\53\256\271\352\272\53\257" | ||
| 90 | "\275\372\372\53\260\301\12\73\54\261\305\32\173\54\262\311\52\273\54\263" | ||
| 91 | "\315\72\373\54\264\321\112\73\55\265\325\132\173\55\0\0\0\0\0\266" | ||
| 92 | "\331\152\273\55\267\335\172\373\55\270\341\212\73\56\271\345\232\173\56\272" | ||
| 93 | "\351\252\273\56\273\355\272\373\56\274\361\312\73\57\275\0\0\0\0\0" | ||
| 94 | |||
| 95 | "iso885913\0" | ||
| 96 | "\0\50" | ||
| 97 | "\240\134\54\312\50\244\140\154\312\51\330\244\262\324\52\254\264\342\212\61" | ||
| 98 | "\260\304\42\313\54\26\327\142\313\55\370\344\302\324\56\274\364\342\213\71" | ||
| 99 | "\4\251\4\220\101\304\24\143\221\104\14\45\343\26\105\40\301\204\122\115" | ||
| 100 | "\125\355\324\323\64\103\125\143\315\65\147\345\364\324\127\334\300\45\327\67" | ||
| 101 | "\5\255\24\320\101\344\224\163\321\104\15\245\363\126\105\41\305\224\222\115" | ||
| 102 | "\126\361\344\323\74\104\325\143\317\75\150\351\4\25\130\374\304\65\27\305" | ||
| 103 | |||
| 104 | "iso885914\0" | ||
| 105 | "\0\50" | ||
| 106 | "\240\324\153\357\50\12\55\164\357\51\3\247\122\60\276\11\267\342\112\133" | ||
| 107 | "\371\352\353\321\107\373\362\153\113\277\4\373\153\360\277\12\37\214\60\300" | ||
| 108 | "\300\4\43\314\60\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63" | ||
| 109 | "\151\105\43\315\64\324\124\143\115\300\330\144\243\315\66\334\164\263\326\67" | ||
| 110 | "\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73" | ||
| 111 | "\152\305\43\317\74\364\324\143\217\300\370\344\243\317\76\374\364\303\326\77" | ||
| 112 | |||
| 113 | "iso885915\0" | ||
| 114 | "latin9\0" | ||
| 115 | "\0\51" | ||
| 116 | "\44\227\122\325\51\126\245\242\312\52\254\264\342\312\53\260\304\42\313\54" | ||
| 117 | "\162\325\142\313\55\163\345\242\313\56\107\41\325\326\57\300\4\43\314\60" | ||
| 118 | "\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63\320\104\43\315\64" | ||
| 119 | "\324\124\143\315\65\330\144\243\315\66\334\164\343\315\67\340\204\43\316\70" | ||
| 120 | "\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73\360\304\43\317\74" | ||
| 121 | "\364\324\143\317\75\370\344\243\317\76\374\364\343\317\77" | ||
| 122 | |||
| 123 | "iso885916\0" | ||
| 124 | "\0\50" | ||
| 125 | "\240\20\124\120\116\44\143\134\325\51\126\245\222\327\52\156\265\362\26\134" | ||
| 126 | "\260\304\302\220\116\162\135\154\313\55\163\65\244\327\56\107\41\325\126\134" | ||
| 127 | "\300\4\43\214\100\304\30\144\314\61\310\44\243\314\62\314\64\343\314\63" | ||
| 128 | "\20\355\44\315\64\324\24\145\315\123\145\145\243\315\66\334\130\264\327\67" | ||
| 129 | "\340\204\43\316\100\344\34\144\316\71\350\244\243\316\72\354\264\343\316\73" | ||
| 130 | "\21\361\44\317\74\364\30\145\17\124\146\345\243\317\76\374\134\304\327\77" | ||
| 131 | |||
| 132 | "cp1250\0" | ||
| 133 | "windows1250\0" | ||
| 134 | "\0\40" | ||
| 135 | "\44\3\120\61\0\30\163\234\261\306\0\164\134\225\307\117\145\45\227\133" | ||
| 136 | "\0\114\114\261\305\27\157\374\60\304\0\234\154\325\307\120\151\65\327\133" | ||
| 137 | "\240\370\365\127\116\244\20\144\312\51\250\244\62\325\52\254\264\342\12\134" | ||
| 138 | "\260\304\22\230\116\264\324\142\313\55\270\24\104\325\56\67\15\206\123\134" | ||
| 139 | "\111\5\43\214\100\304\314\144\320\61\14\45\143\321\62\30\65\343\214\103" | ||
| 140 | "\20\355\364\323\64\324\24\145\315\65\115\215\245\115\131\334\164\163\325\67" | ||
| 141 | "\112\205\43\316\100\344\320\164\320\71\15\245\163\321\72\31\265\343\316\103" | ||
| 142 | "\21\361\4\324\74\364\30\145\317\75\116\221\245\217\131\374\364\203\25\140" | ||
| 143 | |||
| 144 | "cp1251\0" | ||
| 145 | "windows1251\0" | ||
| 146 | "\0\40" | ||
| 147 | "\322\115\127\161\210\30\163\234\261\306\44\167\234\235\307\332\161\267\235\167" | ||
| 148 | "\40\116\114\261\305\27\157\374\60\304\0\234\174\342\307\50\252\230\42\213" | ||
| 149 | "\240\164\267\42\166\244\264\150\312\51\321\245\102\335\52\254\264\342\312\165" | ||
| 150 | "\260\304\142\35\211\56\326\142\313\55\37\232\54\342\56\46\126\67\142\211" | ||
| 151 | "\337\201\27\236\170\343\221\127\236\171\347\241\227\236\172" | ||
| 152 | "\353\261\327\236\173\357\301\27\237\174\363\321\127\237\175" | ||
| 153 | "\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200\3\22\130\240\201" | ||
| 154 | "\7\42\230\240\202\13\62\330\240\203\17\102\30\241\204\23\122\130\241\205" | ||
| 155 | "\27\142\230\241\206\33\162\330\241\207" | ||
| 156 | |||
| 157 | "cp1252\0" | ||
| 158 | "windows1252\0" | ||
| 159 | "\0\40" | ||
| 160 | "\44\3\120\61\135\30\163\234\261\306\175\165\134\225\307\107\1\40\27\0" | ||
| 161 | "\0\114\114\261\305\27\157\374\60\304\202\235\154\325\307\110\1\60\127\133" | ||
| 162 | "\240\204\42\312\50\244\224\142\312\51\250\244\242\312\52\254\264\342\312\53" | ||
| 163 | "\260\304\42\313\54\264\324\142\313\55\270\344\242\313\56\274\364\342\313\57" | ||
| 164 | "\300\4\43\314\60\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63" | ||
| 165 | "\320\104\43\315\64\324\124\143\315\65\330\144\243\315\66\334\164\343\315\67" | ||
| 166 | "\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73" | ||
| 167 | "\360\304\43\317\74\364\324\143\317\75\370\344\243\317\76\374\364\343\317\77" | ||
| 168 | |||
| 169 | "cp1253\0" | ||
| 170 | "windows1253\0" | ||
| 171 | "\0\40" | ||
| 172 | "\44\3\120\61\135\30\163\234\261\306\0\164\14\200\307\0\0\0\0\0" | ||
| 173 | "\0\114\114\261\305\27\157\374\60\304\0\234\14\300\307\0\0\0\0\0" | ||
| 174 | "\240\54\306\330\50\244\224\142\312\51\250\244\2\300\52\254\264\342\112\304" | ||
| 175 | "\260\304\42\313\54\212\325\142\313\55\215\71\366\330\56\220\365\22\231\144" | ||
| 176 | "\223\121\126\231\145\227\141\226\231\146\233\161\326\231\147" | ||
| 177 | "\237\201\26\232\150\243\221\6\100\151\246\235\206\132\152\252\255\306\132\153" | ||
| 178 | "\256\275\6\133\154\262\315\106\133\155\266\335\206\133\156\272\355\306\133\157" | ||
| 179 | "\276\375\6\134\160\302\15\107\134\161\306\35\207\134\162\312\55\307\134\163" | ||
| 180 | "\316\75\7\35\0" | ||
| 181 | |||
| 182 | "cp1254\0" | ||
| 183 | "windows1254\0" | ||
| 184 | "\0\40" | ||
| 185 | "\44\3\120\61\135\30\163\234\261\306\175\165\134\225\307\107\1\0\0\0" | ||
| 186 | "\0\114\114\261\305\27\157\374\60\304\202\235\154\325\307\110\1\0\100\133" | ||
| 187 | "\240\204\42\312\50\244\224\142\312\51\250\244\242\312\52\254\264\342\312\53" | ||
| 188 | "\260\304\42\313\54\264\324\142\313\55\270\344\242\313\56\274\364\342\313\57" | ||
| 189 | "\300\4\43\314\60\304\24\143\314\61\310\44\243\314\62\314\64\343\314\63" | ||
| 190 | "\34\105\43\315\64\324\124\143\315\65\330\144\243\315\66\334\260\64\325\67" | ||
| 191 | "\340\204\43\316\70\344\224\143\316\71\350\244\243\316\72\354\264\343\316\73" | ||
| 192 | "\35\305\43\317\74\364\324\143\317\75\370\344\243\317\76\374\264\104\325\77" | ||
| 193 | |||
| 194 | "cp1255\0" | ||
| 195 | "windows1255\0" | ||
| 196 | "\0\40" | ||
| 197 | "\44\3\120\61\135\30\163\234\261\306\175\165\14\200\307\0\0\0\0\0" | ||
| 198 | "\0\114\114\261\305\27\157\374\60\304\202\235\14\300\307\0\0\0\0\0" | ||
| 199 | "\240\204\42\312\50\42\227\142\312\51\250\244\162\315\52\254\264\342\312\53" | ||
| 200 | "\260\304\42\313\54\264\324\142\313\55\270\344\162\317\56\274\364\342\313\57" | ||
| 201 | "\57\302\30\243\214\63\322\130\243\215\67\342\10\100\216\72\356\310\143\217" | ||
| 202 | "\76\376\10\144\220\135\172\371\45\230\141\2\0\0\0\0\0\0\0\0\102\16\111\144\221" | ||
| 203 | "\106\36\211\144\222\112\56\311\144\223\116\76\11\145\224\122\116\111\145\225" | ||
| 204 | "\126\136\211\145\226\132\156\311\45\0\0\64\354\60\0" | ||
| 205 | |||
| 206 | "cp1256\0" | ||
| 207 | "windows1256\0" | ||
| 208 | "\0\40" | ||
| 209 | "\44\117\132\61\135\30\163\234\261\306\175\165\54\251\307\107\121\172\151\245" | ||
| 210 | "\231\116\114\261\305\27\157\374\60\304\230\236\154\351\307\110\55\314\260\246" | ||
| 211 | "\240\210\51\312\50\244\224\142\312\51\250\244\262\351\52\254\264\342\312\53" | ||
| 212 | "\260\304\42\313\54\264\324\142\313\55\270\344\62\346\56\274\364\342\13\231" | ||
| 213 | "\234\226\151\346\231\150\246\251\346\232\154\266\351\346\233" | ||
| 214 | "\160\306\51\347\234\164\326\151\347\235\170\346\251\347\65\173\362\331\247\237" | ||
| 215 | "\177\2\32\250\240\340\14\52\16\241\205\32\172\350\71\350\244\243\316\72" | ||
| 216 | "\210\46\352\316\73\212\56\312\150\243\364\70\372\350\75\220\346\23\351\76" | ||
| 217 | "\374\64\354\160\247" | ||
| 218 | |||
| 219 | "cp1257\0" | ||
| 220 | "windows1257\0" | ||
| 221 | "\0\40" | ||
| 222 | "\44\3\120\61\0\30\163\234\261\306\0\164\14\200\307\0\240\342\27\56" | ||
| 223 | "\0\114\114\261\305\27\157\374\60\304\0\234\14\300\307\0\274\22\30\0" | ||
| 224 | "\240\0\40\312\50\244\0\140\312\51\330\244\262\324\52\254\264\342\212\61" | ||
| 225 | "\260\304\42\313\54\264\324\142\313\55\370\344\302\324\56\274\364\342\213\71" | ||
| 226 | "\4\251\4\220\101\304\24\143\221\104\14\45\343\26\105\40\301\204\122\115" | ||
| 227 | "\125\355\324\323\64\103\125\143\315\65\147\345\364\324\127\334\300\45\327\67" | ||
| 228 | "\5\255\24\320\101\344\224\163\321\104\15\245\363\126\105\41\305\224\222\115" | ||
| 229 | "\126\361\344\323\74\104\325\143\317\75\150\351\4\25\130\374\304\65\27\140" | ||
| 230 | |||
| 231 | "cp1258\0" | ||
| 232 | "windows1258\0" | ||
| 233 | "\0\40" | ||
| 234 | "\44\3\120\61\135\30\163\234\261\306\175\165\14\200\307\107\1\0\0\0" | ||
| 235 | "\0\114\114\261\305\27\157\374\60\304\202\235\14\300\307\110\1\0\100\133" | ||
| 236 | "\240\204\42\312\50\244\224\142\312\51\250\244\242\312\52\254\264\342\312\53" | ||
| 237 | "\260\304\42\313\54\264\324\142\313\55\270\344\242\313\56\274\364\342\313\57" | ||
| 238 | "\300\4\43\214\100\304\24\143\314\61\310\44\243\314\62\204\65\343\314\63" | ||
| 239 | "\20\105\163\330\64\324\324\145\315\65\330\144\243\315\66\334\334\145\330\67" | ||
| 240 | "\340\204\43\316\100\344\224\143\316\71\350\244\243\316\72\205\265\343\316\73" | ||
| 241 | "\21\305\203\330\74\364\330\145\317\75\370\344\243\317\76\374\340\65\362\77" | ||
| 242 | |||
| 243 | "koi8r\0" | ||
| 244 | "\0\40" | ||
| 245 | "\63\323\134\263\315\67\343\234\263\316\73\363\334\363\326\134\167\355\365\327" | ||
| 246 | "\140\207\55\166\314\143\243\234\62\313\56\277\14\212\314\260\310\162\313\75" | ||
| 247 | "\76\377\14\364\207\101\13\75\64\321\105\33\175\64\322\111\53\275\64\323" | ||
| 248 | "\115\73\375\164\164\120\107\55\365\324\124\127\155\365\325\130\147\255\165\52" | ||
| 249 | "\35\376\7\140\205\3\22\70\241\200\24\36\210\140\202\12\56\310\140\203" | ||
| 250 | "\16\172\370\40\204\21\112\130\140\200\33\152\150\340\205\34\142\150\141\206" | ||
| 251 | "\375\175\7\136\175\343\221\67\237\170\364\235\207\136\172\352\255\307\136\173" | ||
| 252 | "\356\371\367\36\174\361\311\127\136\170\373\351\147\336\175" | ||
| 253 | "\374\341\147\137\176" | ||
| 254 | |||
| 255 | "koi8u\0" | ||
| 256 | "\0\40" | ||
| 257 | "\63\323\134\263\315\67\343\234\263\316\73\363\334\363\326\134\167\355\365\327" | ||
| 258 | "\140\207\55\166\314\143\243\234\62\313\56\277\14\212\314\260\310\162\313\75" | ||
| 259 | "\76\377\14\364\207\42\12\115\142\211\105\33\175\64\322\111\273\270\64\323" | ||
| 260 | "\115\73\375\164\164\324\105\155\335\165\124\127\155\365\325\130\267\250\165\52" | ||
| 261 | "\35\376\7\140\205\3\22\70\241\200\24\36\210\140\202\12\56\310\140\203" | ||
| 262 | "\16\172\370\40\204\21\112\130\140\200\33\152\150\340\205\34\142\150\141\206" | ||
| 263 | "\375\175\7\136\175\343\221\67\237\170\364\235\207\136\172\352\255\307\136\173" | ||
| 264 | "\356\371\367\36\174\361\311\127\136\170\373\351\147\336\175" | ||
| 265 | "\374\341\147\137\176" | ||
| 266 | |||
| 267 | "cp437\0" | ||
| 268 | "\0\40" | ||
| 269 | "\307\360\223\216\70\344\200\123\316\71\352\254\203\316\73\356\260\103\114\61" | ||
| 270 | "\311\230\143\14\75\366\310\263\117\76\377\130\303\215\50\243\224\22\62\135" | ||
| 271 | "\341\264\63\217\76\361\104\243\212\56\277\300\314\112\57\274\204\262\312\56" | ||
| 272 | "\140\207\55\66\315\72\77\15\65\321\103\107\375\163\321\113\53\235\264\315" | ||
| 273 | "\67\363\274\163\316\63\367\314\164\323\110\13\175\65\325\116\373\254\165\325" | ||
| 274 | "\126\113\75\365\321\106\3\35\164\326\130\343\134\163\327\134\173\375\365\326" | ||
| 275 | "\263\175\143\231\160\245\25\127\213\161\250\155\266\232\155\52\43\167\333\312" | ||
| 276 | "\55\307\362\262\313\61\313\174\17\313\260\240\174\113\312\40\313\62\66\50" | ||
| 277 | |||
| 278 | "cp850\0" | ||
| 279 | "\0\40" | ||
| 280 | "\307\360\223\216\70\344\200\123\316\71\352\254\203\316\73\356\260\103\114\61" | ||
| 281 | "\311\230\143\14\75\366\310\263\117\76\377\130\303\15\76\243\140\163\15\135" | ||
| 282 | "\341\264\63\217\76\361\104\243\212\56\277\270\302\112\57\274\204\262\312\56" | ||
| 283 | "\140\207\55\66\315\72\7\43\14\60\251\104\375\163\321\113\213\122\212\315" | ||
| 284 | "\67\363\274\163\316\63\367\74\316\60\110\13\175\65\325\116\373\254\65\51" | ||
| 285 | "\360\100\243\314\62\310\264\324\214\63\317\340\134\163\327\134\233\302\314\326" | ||
| 286 | "\323\174\103\215\64\365\124\123\213\77\336\150\263\115\66\375\164\363\12\55" | ||
| 287 | "\255\304\42\261\57\266\234\162\17\56\260\240\162\113\56\263\310\62\66\50" | ||
| 288 | |||
| 289 | "cp866\0" | ||
| 290 | "\0\40" | ||
| 291 | "\337\201\27\236\170\343\221\127\236\171\347\241\227\236\172" | ||
| 292 | "\353\261\327\236\173\357\301\27\237\174\363\321\127\237\175" | ||
| 293 | "\367\341\227\237\176\373\361\327\237\177\377\1\30\240\200\3\22\130\240\201" | ||
| 294 | "\7\42\230\240\202\13\62\330\240\203\140\207\55\66\315\72\77\15\65\321" | ||
| 295 | "\103\107\375\163\321\113\53\235\264\315\67\363\274\163\316\63\367\314\164\323" | ||
| 296 | "\110\13\175\65\325\116\373\254\165\325\126\113\75\365\321\106\3\35\164\326" | ||
| 297 | "\130\343\134\163\327\134\173\375\365\326\17\102\30\241\204\23\122\130\241\205" | ||
| 298 | "\27\142\230\241\206\33\162\330\241\207\321\175\110\235\210\327\225\330\335\212" | ||
| 299 | "\260\240\174\113\312\46\223\62\66\50" | ||
| 300 | |||
| 301 | "ibm1047\0" | ||
| 302 | "cp1047\0" | ||
| 303 | "\0\1" | ||
| 304 | "\234\44\140\310\37\227\64\342\310\2\14\64\340\300\3\20\104\40\301\4" | ||
| 305 | "\235\24\202\300\41\30\144\40\311\43\34\164\340\301\7\200\4\42\310\40" | ||
| 306 | "\204\50\160\301\6\210\44\242\310\42\214\24\140\300\1\220\104\142\301\44" | ||
| 307 | "\224\124\142\11\1\230\144\242\311\46\24\124\340\211\6\40\200\42\16\71" | ||
| 308 | "\340\204\63\116\71\347\304\43\212\13\74\240\260\2\37\46\244\243\316\72" | ||
| 309 | "\350\264\343\316\73\354\174\23\2\11\52\244\260\203\27\55\274\40\14\61" | ||
| 310 | "\300\4\63\114\61\307\104\143\12\13\45\174\341\303\17\370\44\243\314\62" | ||
| 311 | "\310\64\343\314\63\314\200\241\303\10\100\234\320\203\10\330\204\41\306\30" | ||
| 312 | "\144\224\141\306\31\150\244\261\312\56\360\364\343\117\54\260\250\261\6\33" | ||
| 313 | "\155\270\361\6\34\161\310\241\212\56\346\340\142\14\51\265\370\61\7\35" | ||
| 314 | "\165\330\161\7\36\171\350\21\312\57\320\154\341\215\53\254\214\122\312\55" | ||
| 315 | "\251\234\142\13\57\275\370\322\15\52\257\164\101\313\65\173\4\41\304\20" | ||
| 316 | "\104\24\141\304\21\110\44\321\12\75\366\310\63\117\75\175\50\261\4\23" | ||
| 317 | "\115\70\361\4\24\121\110\221\313\76\374\344\243\317\77\134\334\63\5\25" | ||
| 318 | "\125\130\161\5\26\131\150\41\13\65\326\110\63\115\65\60\304\40\303\14" | ||
| 319 | "\64\324\140\303\15\70\344\60\313\66\334\144\243\315\47" | ||
| 320 | |||
lib/libc/wasi/libc-top-half/musl/src/locale/dcngettext.c created+280| ... | @@ -0,0 +1,280 @@ | ||
| 1 | #include <libintl.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <sys/stat.h> | ||
| 7 | #include <sys/mman.h> | ||
| 8 | #include <ctype.h> | ||
| 9 | #include "locale_impl.h" | ||
| 10 | #include "atomic.h" | ||
| 11 | #include "pleval.h" | ||
| 12 | #include "lock.h" | ||
| 13 | #include "fork_impl.h" | ||
| 14 | |||
| 15 | #define malloc __libc_malloc | ||
| 16 | #define calloc __libc_calloc | ||
| 17 | #define realloc undef | ||
| 18 | #define free undef | ||
| 19 | |||
| 20 | struct binding { | ||
| 21 | 	struct binding *next; | ||
| 22 | 	int dirlen; | ||
| 23 | 	volatile int active; | ||
| 24 | 	char *domainname; | ||
| 25 | 	char *dirname; | ||
| 26 | 	char buf[]; | ||
| 27 | }; | ||
| 28 | |||
| 29 | static void *volatile bindings; | ||
| 30 | |||
| 31 | static char *gettextdir(const char *domainname, size_t *dirlen) | ||
| 32 | { | ||
| 33 | 	struct binding *p; | ||
| 34 | 	for (p=bindings; p; p=p->next) { | ||
| 35 | 		if (!strcmp(p->domainname, domainname) && p->active) { | ||
| 36 | 			*dirlen = p->dirlen; | ||
| 37 | 			return (char *)p->dirname; | ||
| 38 | 		} | ||
| 39 | 	} | ||
| 40 | 	return 0; | ||
| 41 | } | ||
| 42 | |||
| 43 | static volatile int lock[1]; | ||
| 44 | volatile int *const __gettext_lockptr = lock; | ||
| 45 | |||
| 46 | char *bindtextdomain(const char *domainname, const char *dirname) | ||
| 47 | { | ||
| 48 | 	struct binding *p, *q; | ||
| 49 | |||
| 50 | 	if (!domainname) return 0; | ||
| 51 | 	if (!dirname) return gettextdir(domainname, &(size_t){0}); | ||
| 52 | |||
| 53 | 	size_t domlen = strnlen(domainname, NAME_MAX+1); | ||
| 54 | 	size_t dirlen = strnlen(dirname, PATH_MAX); | ||
| 55 | 	if (domlen > NAME_MAX || dirlen >= PATH_MAX) { | ||
| 56 | 		errno = EINVAL; | ||
| 57 | 		return 0; | ||
| 58 | 	} | ||
| 59 | |||
| 60 | 	LOCK(lock); | ||
| 61 | |||
| 62 | 	for (p=bindings; p; p=p->next) { | ||
| 63 | 		if (!strcmp(p->domainname, domainname) && | ||
| 64 | 		 !strcmp(p->dirname, dirname)) { | ||
| 65 | 			break; | ||
| 66 | 		} | ||
| 67 | 	} | ||
| 68 | |||
| 69 | 	if (!p) { | ||
| 70 | 		p = calloc(sizeof *p + domlen + dirlen + 2, 1); | ||
| 71 | 		if (!p) { | ||
| 72 | 			UNLOCK(lock); | ||
| 73 | 			return 0; | ||
| 74 | 		} | ||
| 75 | 		p->next = bindings; | ||
| 76 | 		p->dirlen = dirlen; | ||
| 77 | 		p->domainname = p->buf; | ||
| 78 | 		p->dirname = p->buf + domlen + 1; | ||
| 79 | 		memcpy(p->domainname, domainname, domlen+1); | ||
| 80 | 		memcpy(p->dirname, dirname, dirlen+1); | ||
| 81 | 		a_cas_p(&bindings, bindings, p); | ||
| 82 | 	} | ||
| 83 | |||
| 84 | 	a_store(&p->active, 1); | ||
| 85 | |||
| 86 | 	for (q=bindings; q; q=q->next) { | ||
| 87 | 		if (!strcmp(q->domainname, domainname) && q != p) | ||
| 88 | 			a_store(&q->active, 0); | ||
| 89 | 	} | ||
| 90 | |||
| 91 | 	UNLOCK(lock); | ||
| 92 | 	 | ||
| 93 | 	return (char *)p->dirname; | ||
| 94 | } | ||
| 95 | |||
| 96 | static const char catnames[][12] = { | ||
| 97 | 	"LC_CTYPE", | ||
| 98 | 	"LC_NUMERIC", | ||
| 99 | 	"LC_TIME", | ||
| 100 | 	"LC_COLLATE", | ||
| 101 | 	"LC_MONETARY", | ||
| 102 | 	"LC_MESSAGES", | ||
| 103 | }; | ||
| 104 | |||
| 105 | static const char catlens[] = { 8, 10, 7, 10, 11, 11 }; | ||
| 106 | |||
| 107 | struct msgcat { | ||
| 108 | 	struct msgcat *next; | ||
| 109 | 	const void *map; | ||
| 110 | 	size_t map_size; | ||
| 111 | 	const char *plural_rule; | ||
| 112 | 	int nplurals; | ||
| 113 | 	struct binding *binding; | ||
| 114 | 	const struct __locale_map *lm; | ||
| 115 | 	int cat; | ||
| 116 | }; | ||
| 117 | |||
| 118 | static char *dummy_gettextdomain() | ||
| 119 | { | ||
| 120 | 	return "messages"; | ||
| 121 | } | ||
| 122 | |||
| 123 | weak_alias(dummy_gettextdomain, __gettextdomain); | ||
| 124 | |||
| 125 | char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n, int category) | ||
| 126 | { | ||
| 127 | 	static struct msgcat *volatile cats; | ||
| 128 | 	struct msgcat *p; | ||
| 129 | 	struct __locale_struct *loc = CURRENT_LOCALE; | ||
| 130 | 	const struct __locale_map *lm; | ||
| 131 | 	size_t domlen; | ||
| 132 | 	struct binding *q; | ||
| 133 | 	int old_errno = errno; | ||
| 134 | |||
| 135 | 	if ((unsigned)category >= LC_ALL) goto notrans; | ||
| 136 | |||
| 137 | 	if (!domainname) domainname = __gettextdomain(); | ||
| 138 | |||
| 139 | 	domlen = strnlen(domainname, NAME_MAX+1); | ||
| 140 | 	if (domlen > NAME_MAX) goto notrans; | ||
| 141 | |||
| 142 | 	for (q=bindings; q; q=q->next) | ||
| 143 | 		if (!strcmp(q->domainname, domainname) && q->active) | ||
| 144 | 			break; | ||
| 145 | 	if (!q) goto notrans; | ||
| 146 | |||
| 147 | 	lm = loc->cat[category]; | ||
| 148 | 	if (!lm) { | ||
| 149 | notrans: | ||
| 150 | 		errno = old_errno; | ||
| 151 | 		return (char *) ((n == 1) ? msgid1 : msgid2); | ||
| 152 | 	} | ||
| 153 | |||
| 154 | 	for (p=cats; p; p=p->next) | ||
| 155 | 		if (p->binding == q && p->lm == lm && p->cat == category) | ||
| 156 | 			break; | ||
| 157 | |||
| 158 | 	if (!p) { | ||
| 159 | 		const char *dirname, *locname, *catname, *modname, *locp; | ||
| 160 | 		size_t dirlen, loclen, catlen, modlen, alt_modlen; | ||
| 161 | 		void *old_cats; | ||
| 162 | 		size_t map_size; | ||
| 163 | |||
| 164 | 		dirname = q->dirname; | ||
| 165 | 		locname = lm->name; | ||
| 166 | 		catname = catnames[category]; | ||
| 167 | |||
| 168 | 		dirlen = q->dirlen; | ||
| 169 | 		loclen = strlen(locname); | ||
| 170 | 		catlen = catlens[category]; | ||
| 171 | |||
| 172 | 		/* Logically split @mod suffix from locale name. */ | ||
| 173 | 		modname = memchr(locname, '@', loclen); | ||
| 174 | 		if (!modname) modname = locname + loclen; | ||
| 175 | 		alt_modlen = modlen = loclen - (modname-locname); | ||
| 176 | 		loclen = modname-locname; | ||
| 177 | |||
| 178 | 		/* Drop .charset identifier; it is not used. */ | ||
| 179 | 		const char *csp = memchr(locname, '.', loclen); | ||
| 180 | 		if (csp) loclen = csp-locname; | ||
| 181 | |||
| 182 | 		char name[dirlen+1 + loclen+modlen+1 + catlen+1 + domlen+3 + 1]; | ||
| 183 | 		const void *map; | ||
| 184 | |||
| 185 | 		for (;;) { | ||
| 186 | 			snprintf(name, sizeof name, "%s/%.*s%.*s/%s/%s.mo\0", | ||
| 187 | 				dirname, (int)loclen, locname, | ||
| 188 | 				(int)alt_modlen, modname, catname, domainname); | ||
| 189 | 			if (map = __map_file(name, &map_size)) break; | ||
| 190 | |||
| 191 | 			/* Try dropping @mod, _YY, then both. */ | ||
| 192 | 			if (alt_modlen) { | ||
| 193 | 				alt_modlen = 0; | ||
| 194 | 			} else if ((locp = memchr(locname, '_', loclen))) { | ||
| 195 | 				loclen = locp-locname; | ||
| 196 | 				alt_modlen = modlen; | ||
| 197 | 			} else { | ||
| 198 | 				break; | ||
| 199 | 			} | ||
| 200 | 		} | ||
| 201 | 		if (!map) goto notrans; | ||
| 202 | |||
| 203 | 		p = calloc(sizeof *p, 1); | ||
| 204 | 		if (!p) { | ||
| 205 | 			__munmap((void *)map, map_size); | ||
| 206 | 			goto notrans; | ||
| 207 | 		} | ||
| 208 | 		p->cat = category; | ||
| 209 | 		p->binding = q; | ||
| 210 | 		p->lm = lm; | ||
| 211 | 		p->map = map; | ||
| 212 | 		p->map_size = map_size; | ||
| 213 | |||
| 214 | 		const char *rule = "n!=1;"; | ||
| 215 | 		unsigned long np = 2; | ||
| 216 | 		const char *r = __mo_lookup(p->map, p->map_size, ""); | ||
| 217 | 		char *z; | ||
| 218 | 		while (r && strncmp(r, "Plural-Forms:", 13)) { | ||
| 219 | 			z = strchr(r, '\n'); | ||
| 220 | 			r = z ? z+1 : 0; | ||
| 221 | 		} | ||
| 222 | 		if (r) { | ||
| 223 | 			r += 13; | ||
| 224 | 			while (isspace(*r)) r++; | ||
| 225 | 			if (!strncmp(r, "nplurals=", 9)) { | ||
| 226 | 				np = strtoul(r+9, &z, 10); | ||
| 227 | 				r = z; | ||
| 228 | 			} | ||
| 229 | 			while (*r && *r != ';') r++; | ||
| 230 | 			if (*r) { | ||
| 231 | 				r++; | ||
| 232 | 				while (isspace(*r)) r++; | ||
| 233 | 				if (!strncmp(r, "plural=", 7)) | ||
| 234 | 					rule = r+7; | ||
| 235 | 			} | ||
| 236 | 		} | ||
| 237 | 		p->nplurals = np; | ||
| 238 | 		p->plural_rule = rule; | ||
| 239 | |||
| 240 | 		do { | ||
| 241 | 			old_cats = cats; | ||
| 242 | 			p->next = old_cats; | ||
| 243 | 		} while (a_cas_p(&cats, old_cats, p) != old_cats); | ||
| 244 | 	} | ||
| 245 | |||
| 246 | 	const char *trans = __mo_lookup(p->map, p->map_size, msgid1); | ||
| 247 | 	if (!trans) goto notrans; | ||
| 248 | |||
| 249 | 	/* Non-plural-processing gettext forms pass a null pointer as | ||
| 250 | 	 * msgid2 to request that dcngettext suppress plural processing. */ | ||
| 251 | |||
| 252 | 	if (msgid2 && p->nplurals) { | ||
| 253 | 		unsigned long plural = __pleval(p->plural_rule, n); | ||
| 254 | 		if (plural > p->nplurals) goto notrans; | ||
| 255 | 		while (plural--) { | ||
| 256 | 			size_t rem = p->map_size - (trans - (char *)p->map); | ||
| 257 | 			size_t l = strnlen(trans, rem); | ||
| 258 | 			if (l+1 >= rem) | ||
| 259 | 				goto notrans; | ||
| 260 | 			trans += l+1; | ||
| 261 | 		} | ||
| 262 | 	} | ||
| 263 | 	errno = old_errno; | ||
| 264 | 	return (char *)trans; | ||
| 265 | } | ||
| 266 | |||
| 267 | char *dcgettext(const char *domainname, const char *msgid, int category) | ||
| 268 | { | ||
| 269 | 	return dcngettext(domainname, msgid, 0, 1, category); | ||
| 270 | } | ||
| 271 | |||
| 272 | char *dngettext(const char *domainname, const char *msgid1, const char *msgid2, unsigned long int n) | ||
| 273 | { | ||
| 274 | 	return dcngettext(domainname, msgid1, msgid2, n, LC_MESSAGES); | ||
| 275 | } | ||
| 276 | |||
| 277 | char *dgettext(const char *domainname, const char *msgid) | ||
| 278 | { | ||
| 279 | 	return dcngettext(domainname, msgid, 0, 1, LC_MESSAGES); | ||
| 280 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/duplocale.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | #include "libc.h" | ||
| 5 | |||
| 6 | locale_t __duplocale(locale_t old) | ||
| 7 | { | ||
| 8 | 	locale_t new = malloc(sizeof *new); | ||
| 9 | 	if (!new) return 0; | ||
| 10 | 	if (old == LC_GLOBAL_LOCALE) old = &libc.global_locale; | ||
| 11 | 	*new = *old; | ||
| 12 | 	return new; | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(__duplocale, duplocale); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/freelocale.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include "locale_impl.h" | ||
| 3 | |||
| 4 | #define malloc undef | ||
| 5 | #define calloc undef | ||
| 6 | #define realloc undef | ||
| 7 | #define free __libc_free | ||
| 8 | |||
| 9 | void freelocale(locale_t l) | ||
| 10 | { | ||
| 11 | 	if (__loc_is_allocated(l)) free(l); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(freelocale, __freelocale); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/gb18030.h created+1866| ... | @@ -0,0 +1,1866 @@ | ||
| 1 | 19970,19972,19973,19974,19983,19986,19991,19999,20000,20001,20003,20006,20009, | ||
| 2 | 20014,20015,20017,20019,20021,20023,20028,20032,20033,20034,20036,20038,20042, | ||
| 3 | 20049,20053,20055,20058,20059,20066,20067,20068,20069,20071,20072,20074,20075, | ||
| 4 | 20076,20077,20078,20079,20082,20084,20085,20086,20087,20088,20089,20090,20091, | ||
| 5 | 20092,20093,20095,20096,20097,20098,20099,20100,20101,20103,20106,20112,20118, | ||
| 6 | 20119,20121,20124,20125,20126,20131,20138,20143,20144,20145,20148,20150,20151, | ||
| 7 | 20152,20153,20156,20157,20158,20168,20172,20175,20176,20178,20186,20187,20188, | ||
| 8 | 20192,20194,20198,20199,20201,20205,20206,20207,20209,20212,20216,20217,20218, | ||
| 9 | 20220,20222,20224,20226,20227,20228,20229,20230,20231,20232,20235,20236,20242, | ||
| 10 | 20243,20244,20245,20246,20252,20253,20257,20259,20264,20265,20268,20269,20270, | ||
| 11 | 20273,20275,20277,20279,20281,20283,20286,20287,20288,20289,20290,20292,20293, | ||
| 12 | 20295,20296,20297,20298,20299,20300,20306,20308,20310,20321,20322,20326,20328, | ||
| 13 | 20330,20331,20333,20334,20337,20338,20341,20343,20344,20345,20346,20349,20352, | ||
| 14 | 20353,20354,20357,20358,20359,20362,20364,20366,20368,20370,20371,20373,20374, | ||
| 15 | 20376,20377,20378,20380,20382,20383,20385,20386,20388,20395,20397,20400,20401, | ||
| 16 | 20402,20403,20404,20406,20407,20408,20409,20410,20411,20412,20413,20414,20416, | ||
| 17 | 20417,20418,20422,20423,20424,20425,20427,20428,20429,20434,20435,20436,20437, | ||
| 18 | 20438,20441,20443,20448,20450,20452,20453,20455,20459,20460,20464,20466,20468, | ||
| 19 | 20469,20470,20471,20473,20475,20476,20477,20479,20480,20481,20482,20483,20484, | ||
| 20 | 20485,20486,20487,20488,20489,20490,20491,20494, | ||
| 21 | 20496,20497,20499,20501,20502,20503,20507,20509,20510,20512,20514,20515,20516, | ||
| 22 | 20519,20523,20527,20528,20529,20530,20531,20532,20533,20534,20535,20536,20537, | ||
| 23 | 20539,20541,20543,20544,20545,20546,20548,20549,20550,20553,20554,20555,20557, | ||
| 24 | 20560,20561,20562,20563,20564,20566,20567,20568,20569,20571,20573,20574,20575, | ||
| 25 | 20576,20577,20578,20579,20580,20582,20583,20584,20585,20586,20587,20589,20590, | ||
| 26 | 20591,20592,20593,20594,20595,20596,20597,20600,20601,20602,20604,20605,20609, | ||
| 27 | 20610,20611,20612,20614,20615,20617,20618,20619,20620,20622,20623,20624,20625, | ||
| 28 | 20626,20627,20628,20629,20630,20631,20632,20633,20634,20635,20636,20637,20638, | ||
| 29 | 20639,20640,20641,20642,20644,20646,20650,20651,20653,20654,20655,20656,20657, | ||
| 30 | 20659,20660,20661,20662,20663,20664,20665,20668,20669,20670,20671,20672,20673, | ||
| 31 | 20674,20675,20676,20677,20678,20679,20680,20681,20682,20683,20684,20685,20686, | ||
| 32 | 20688,20689,20690,20691,20692,20693,20695,20696,20697,20699,20700,20701,20702, | ||
| 33 | 20703,20704,20705,20706,20707,20708,20709,20712,20713,20714,20715,20719,20720, | ||
| 34 | 20721,20722,20724,20726,20727,20728,20729,20730,20732,20733,20734,20735,20736, | ||
| 35 | 20737,20738,20739,20740,20741,20744,20745,20746,20748,20749,20750,20751,20752, | ||
| 36 | 20753,20755,20756,20757,20758,20759,20760,20761,20762,20763,20764,20765,20766, | ||
| 37 | 20767,20768,20770,20771,20772,20773,20774,20775,20776,20777,20778,20779,20780, | ||
| 38 | 20781,20782,20783,20784,20785,20786,20787,20788,20789,20790,20791,20792,20793, | ||
| 39 | 20794,20795,20796,20797,20798,20802,20807,20810,20812,20814,20815,20816,20818, | ||
| 40 | 20819,20823,20824,20825,20827,20829,20830,20831,20832, | ||
| 41 | 20833,20835,20836,20838,20839,20841,20842,20847,20850,20858,20862,20863,20867, | ||
| 42 | 20868,20870,20871,20874,20875,20878,20879,20880,20881,20883,20884,20888,20890, | ||
| 43 | 20893,20894,20895,20897,20899,20902,20903,20904,20905,20906,20909,20910,20916, | ||
| 44 | 20920,20921,20922,20926,20927,20929,20930,20931,20933,20936,20938,20941,20942, | ||
| 45 | 20944,20946,20947,20948,20949,20950,20951,20952,20953,20954,20956,20958,20959, | ||
| 46 | 20962,20963,20965,20966,20967,20968,20969,20970,20972,20974,20977,20978,20980, | ||
| 47 | 20983,20990,20996,20997,21001,21003,21004,21007,21008,21011,21012,21013,21020, | ||
| 48 | 21022,21023,21025,21026,21027,21029,21030,21031,21034,21036,21039,21041,21042, | ||
| 49 | 21044,21045,21052,21054,21060,21061,21062,21063,21064,21065,21067,21070,21071, | ||
| 50 | 21074,21075,21077,21079,21080,21081,21082,21083,21085,21087,21088,21090,21091, | ||
| 51 | 21092,21094,21096,21099,21100,21101,21102,21104,21105,21107,21108,21109,21110, | ||
| 52 | 21111,21112,21113,21114,21115,21116,21118,21120,21123,21124,21125,21126,21127, | ||
| 53 | 21129,21130,21131,21132,21133,21134,21135,21137,21138,21140,21141,21142,21143, | ||
| 54 | 21144,21145,21146,21148,21156,21157,21158,21159,21166,21167,21168,21172,21173, | ||
| 55 | 21174,21175,21176,21177,21178,21179,21180,21181,21184,21185,21186,21188,21189, | ||
| 56 | 21190,21192,21194,21196,21197,21198,21199,21201,21203,21204,21205,21207,21209, | ||
| 57 | 21210,21211,21212,21213,21214,21216,21217,21218,21219,21221,21222,21223,21224, | ||
| 58 | 21225,21226,21227,21228,21229,21230,21231,21233,21234,21235,21236,21237,21238, | ||
| 59 | 21239,21240,21243,21244,21245,21249,21250,21251,21252,21255,21257,21258,21259, | ||
| 60 | 21260,21262,21265,21266,21267,21268,21272,21275,21276, | ||
| 61 | 21278,21279,21282,21284,21285,21287,21288,21289,21291,21292,21293,21295,21296, | ||
| 62 | 21297,21298,21299,21300,21301,21302,21303,21304,21308,21309,21312,21314,21316, | ||
| 63 | 21318,21323,21324,21325,21328,21332,21336,21337,21339,21341,21349,21352,21354, | ||
| 64 | 21356,21357,21362,21366,21369,21371,21372,21373,21374,21376,21377,21379,21383, | ||
| 65 | 21384,21386,21390,21391,21392,21393,21394,21395,21396,21398,21399,21401,21403, | ||
| 66 | 21404,21406,21408,21409,21412,21415,21418,21419,21420,21421,21423,21424,21425, | ||
| 67 | 21426,21427,21428,21429,21431,21432,21433,21434,21436,21437,21438,21440,21443, | ||
| 68 | 21444,21445,21446,21447,21454,21455,21456,21458,21459,21461,21466,21468,21469, | ||
| 69 | 21470,21473,21474,21479,21492,21498,21502,21503,21504,21506,21509,21511,21515, | ||
| 70 | 21524,21528,21529,21530,21532,21538,21540,21541,21546,21552,21555,21558,21559, | ||
| 71 | 21562,21565,21567,21569,21570,21572,21573,21575,21577,21580,21581,21582,21583, | ||
| 72 | 21585,21594,21597,21598,21599,21600,21601,21603,21605,21607,21609,21610,21611, | ||
| 73 | 21612,21613,21614,21615,21616,21620,21625,21626,21630,21631,21633,21635,21637, | ||
| 74 | 21639,21640,21641,21642,21645,21649,21651,21655,21656,21660,21662,21663,21664, | ||
| 75 | 21665,21666,21669,21678,21680,21682,21685,21686,21687,21689,21690,21692,21694, | ||
| 76 | 21699,21701,21706,21707,21718,21720,21723,21728,21729,21730,21731,21732,21739, | ||
| 77 | 21740,21743,21744,21745,21748,21749,21750,21751,21752,21753,21755,21758,21760, | ||
| 78 | 21762,21763,21764,21765,21768,21770,21771,21772,21773,21774,21778,21779,21781, | ||
| 79 | 21782,21783,21784,21785,21786,21788,21789,21790,21791,21793,21797,21798,21800, | ||
| 80 | 21801,21803,21805,21810,21812,21813,21814,21816,21817, | ||
| 81 | 21818,21819,21821,21824,21826,21829,21831,21832,21835,21836,21837,21838,21839, | ||
| 82 | 21841,21842,21843,21844,21847,21848,21849,21850,21851,21853,21854,21855,21856, | ||
| 83 | 21858,21859,21864,21865,21867,21871,21872,21873,21874,21875,21876,21881,21882, | ||
| 84 | 21885,21887,21893,21894,21900,21901,21902,21904,21906,21907,21909,21910,21911, | ||
| 85 | 21914,21915,21918,21920,21921,21922,21923,21924,21925,21926,21928,21929,21930, | ||
| 86 | 21931,21932,21933,21934,21935,21936,21938,21940,21942,21944,21946,21948,21951, | ||
| 87 | 21952,21953,21954,21955,21958,21959,21960,21962,21963,21966,21967,21968,21973, | ||
| 88 | 21975,21976,21977,21978,21979,21982,21984,21986,21991,21993,21997,21998,22000, | ||
| 89 | 22001,22004,22006,22008,22009,22010,22011,22012,22015,22018,22019,22020,22021, | ||
| 90 | 22022,22023,22026,22027,22029,22032,22033,22034,22035,22036,22037,22038,22039, | ||
| 91 | 22041,22042,22044,22045,22048,22049,22050,22053,22054,22056,22057,22058,22059, | ||
| 92 | 22062,22063,22064,22067,22069,22071,22072,22074,22076,22077,22078,22080,22081, | ||
| 93 | 22082,22083,22084,22085,22086,22087,22088,22089,22090,22091,22095,22096,22097, | ||
| 94 | 22098,22099,22101,22102,22106,22107,22109,22110,22111,22112,22113,22115,22117, | ||
| 95 | 22118,22119,22125,22126,22127,22128,22130,22131,22132,22133,22135,22136,22137, | ||
| 96 | 22138,22141,22142,22143,22144,22145,22146,22147,22148,22151,22152,22153,22154, | ||
| 97 | 22155,22156,22157,22160,22161,22162,22164,22165,22166,22167,22168,22169,22170, | ||
| 98 | 22171,22172,22173,22174,22175,22176,22177,22178,22180,22181,22182,22183,22184, | ||
| 99 | 22185,22186,22187,22188,22189,22190,22192,22193,22194,22195,22196,22197,22198, | ||
| 100 | 22200,22201,22202,22203,22205,22206,22207,22208,22209, | ||
| 101 | 22210,22211,22212,22213,22214,22215,22216,22217,22219,22220,22221,22222,22223, | ||
| 102 | 22224,22225,22226,22227,22229,22230,22232,22233,22236,22243,22245,22246,22247, | ||
| 103 | 22248,22249,22250,22252,22254,22255,22258,22259,22262,22263,22264,22267,22268, | ||
| 104 | 22272,22273,22274,22277,22279,22283,22284,22285,22286,22287,22288,22289,22290, | ||
| 105 | 22291,22292,22293,22294,22295,22296,22297,22298,22299,22301,22302,22304,22305, | ||
| 106 | 22306,22308,22309,22310,22311,22315,22321,22322,22324,22325,22326,22327,22328, | ||
| 107 | 22332,22333,22335,22337,22339,22340,22341,22342,22344,22345,22347,22354,22355, | ||
| 108 | 22356,22357,22358,22360,22361,22370,22371,22373,22375,22380,22382,22384,22385, | ||
| 109 | 22386,22388,22389,22392,22393,22394,22397,22398,22399,22400,22401,22407,22408, | ||
| 110 | 22409,22410,22413,22414,22415,22416,22417,22420,22421,22422,22423,22424,22425, | ||
| 111 | 22426,22428,22429,22430,22431,22437,22440,22442,22444,22447,22448,22449,22451, | ||
| 112 | 22453,22454,22455,22457,22458,22459,22460,22461,22462,22463,22464,22465,22468, | ||
| 113 | 22469,22470,22471,22472,22473,22474,22476,22477,22480,22481,22483,22486,22487, | ||
| 114 | 22491,22492,22494,22497,22498,22499,22501,22502,22503,22504,22505,22506,22507, | ||
| 115 | 22508,22510,22512,22513,22514,22515,22517,22518,22519,22523,22524,22526,22527, | ||
| 116 | 22529,22531,22532,22533,22536,22537,22538,22540,22542,22543,22544,22546,22547, | ||
| 117 | 22548,22550,22551,22552,22554,22555,22556,22557,22559,22562,22563,22565,22566, | ||
| 118 | 22567,22568,22569,22571,22572,22573,22574,22575,22577,22578,22579,22580,22582, | ||
| 119 | 22583,22584,22585,22586,22587,22588,22589,22590,22591,22592,22593,22594,22595, | ||
| 120 | 22597,22598,22599,22600,22601,22602,22603,22606,22607, | ||
| 121 | 22608,22610,22611,22613,22614,22615,22617,22618,22619,22620,22621,22623,22624, | ||
| 122 | 22625,22626,22627,22628,22630,22631,22632,22633,22634,22637,22638,22639,22640, | ||
| 123 | 22641,22642,22643,22644,22645,22646,22647,22648,22649,22650,22651,22652,22653, | ||
| 124 | 22655,22658,22660,22662,22663,22664,22666,22667,22668,22669,22670,22671,22672, | ||
| 125 | 22673,22676,22677,22678,22679,22680,22683,22684,22685,22688,22689,22690,22691, | ||
| 126 | 22692,22693,22694,22695,22698,22699,22700,22701,22702,22703,22704,22705,22706, | ||
| 127 | 22707,22708,22709,22710,22711,22712,22713,22714,22715,22717,22718,22719,22720, | ||
| 128 | 22722,22723,22724,22726,22727,22728,22729,22730,22731,22732,22733,22734,22735, | ||
| 129 | 22736,22738,22739,22740,22742,22743,22744,22745,22746,22747,22748,22749,22750, | ||
| 130 | 22751,22752,22753,22754,22755,22757,22758,22759,22760,22761,22762,22765,22767, | ||
| 131 | 22769,22770,22772,22773,22775,22776,22778,22779,22780,22781,22782,22783,22784, | ||
| 132 | 22785,22787,22789,22790,22792,22793,22794,22795,22796,22798,22800,22801,22802, | ||
| 133 | 22803,22807,22808,22811,22813,22814,22816,22817,22818,22819,22822,22824,22828, | ||
| 134 | 22832,22834,22835,22837,22838,22843,22845,22846,22847,22848,22851,22853,22854, | ||
| 135 | 22858,22860,22861,22864,22866,22867,22873,22875,22876,22877,22878,22879,22881, | ||
| 136 | 22883,22884,22886,22887,22888,22889,22890,22891,22892,22893,22894,22895,22896, | ||
| 137 | 22897,22898,22901,22903,22906,22907,22908,22910,22911,22912,22917,22921,22923, | ||
| 138 | 22924,22926,22927,22928,22929,22932,22933,22936,22938,22939,22940,22941,22943, | ||
| 139 | 22944,22945,22946,22950,22951,22956,22957,22960,22961,22963,22964,22965,22966, | ||
| 140 | 22967,22968,22970,22972,22973,22975,22976,22977,22978, | ||
| 141 | 22979,22980,22981,22983,22984,22985,22988,22989,22990,22991,22997,22998,23001, | ||
| 142 | 23003,23006,23007,23008,23009,23010,23012,23014,23015,23017,23018,23019,23021, | ||
| 143 | 23022,23023,23024,23025,23026,23027,23028,23029,23030,23031,23032,23034,23036, | ||
| 144 | 23037,23038,23040,23042,23050,23051,23053,23054,23055,23056,23058,23060,23061, | ||
| 145 | 23062,23063,23065,23066,23067,23069,23070,23073,23074,23076,23078,23079,23080, | ||
| 146 | 23082,23083,23084,23085,23086,23087,23088,23091,23093,23095,23096,23097,23098, | ||
| 147 | 23099,23101,23102,23103,23105,23106,23107,23108,23109,23111,23112,23115,23116, | ||
| 148 | 23117,23118,23119,23120,23121,23122,23123,23124,23126,23127,23128,23129,23131, | ||
| 149 | 23132,23133,23134,23135,23136,23137,23139,23140,23141,23142,23144,23145,23147, | ||
| 150 | 23148,23149,23150,23151,23152,23153,23154,23155,23160,23161,23163,23164,23165, | ||
| 151 | 23166,23168,23169,23170,23171,23172,23173,23174,23175,23176,23177,23178,23179, | ||
| 152 | 23180,23181,23182,23183,23184,23185,23187,23188,23189,23190,23191,23192,23193, | ||
| 153 | 23196,23197,23198,23199,23200,23201,23202,23203,23204,23205,23206,23207,23208, | ||
| 154 | 23209,23211,23212,23213,23214,23215,23216,23217,23220,23222,23223,23225,23226, | ||
| 155 | 23227,23228,23229,23231,23232,23235,23236,23237,23238,23239,23240,23242,23243, | ||
| 156 | 23245,23246,23247,23248,23249,23251,23253,23255,23257,23258,23259,23261,23262, | ||
| 157 | 23263,23266,23268,23269,23271,23272,23274,23276,23277,23278,23279,23280,23282, | ||
| 158 | 23283,23284,23285,23286,23287,23288,23289,23290,23291,23292,23293,23294,23295, | ||
| 159 | 23296,23297,23298,23299,23300,23301,23302,23303,23304,23306,23307,23308,23309, | ||
| 160 | 23310,23311,23312,23313,23314,23315,23316,23317,23320, | ||
| 161 | 23321,23322,23323,23324,23325,23326,23327,23328,23329,23330,23331,23332,23333, | ||
| 162 | 23334,23335,23336,23337,23338,23339,23340,23341,23342,23343,23344,23345,23347, | ||
| 163 | 23349,23350,23352,23353,23354,23355,23356,23357,23358,23359,23361,23362,23363, | ||
| 164 | 23364,23365,23366,23367,23368,23369,23370,23371,23372,23373,23374,23375,23378, | ||
| 165 | 23382,23390,23392,23393,23399,23400,23403,23405,23406,23407,23410,23412,23414, | ||
| 166 | 23415,23416,23417,23419,23420,23422,23423,23426,23430,23434,23437,23438,23440, | ||
| 167 | 23441,23442,23444,23446,23455,23463,23464,23465,23468,23469,23470,23471,23473, | ||
| 168 | 23474,23479,23482,23483,23484,23488,23489,23491,23496,23497,23498,23499,23501, | ||
| 169 | 23502,23503,23505,23508,23509,23510,23511,23512,23513,23514,23515,23516,23520, | ||
| 170 | 23522,23523,23526,23527,23529,23530,23531,23532,23533,23535,23537,23538,23539, | ||
| 171 | 23540,23541,23542,23543,23549,23550,23552,23554,23555,23557,23559,23560,23563, | ||
| 172 | 23564,23565,23566,23568,23570,23571,23575,23577,23579,23582,23583,23584,23585, | ||
| 173 | 23587,23590,23592,23593,23594,23595,23597,23598,23599,23600,23602,23603,23605, | ||
| 174 | 23606,23607,23619,23620,23622,23623,23628,23629,23634,23635,23636,23638,23639, | ||
| 175 | 23640,23642,23643,23644,23645,23647,23650,23652,23655,23656,23657,23658,23659, | ||
| 176 | 23660,23661,23664,23666,23667,23668,23669,23670,23671,23672,23675,23676,23677, | ||
| 177 | 23678,23680,23683,23684,23685,23686,23687,23689,23690,23691,23694,23695,23698, | ||
| 178 | 23699,23701,23709,23710,23711,23712,23713,23716,23717,23718,23719,23720,23722, | ||
| 179 | 23726,23727,23728,23730,23732,23734,23737,23738,23739,23740,23742,23744,23746, | ||
| 180 | 23747,23749,23750,23751,23752,23753,23754,23756,23757, | ||
| 181 | 23758,23759,23760,23761,23763,23764,23765,23766,23767,23768,23770,23771,23772, | ||
| 182 | 23773,23774,23775,23776,23778,23779,23783,23785,23787,23788,23790,23791,23793, | ||
| 183 | 23794,23795,23796,23797,23798,23799,23800,23801,23802,23804,23805,23806,23807, | ||
| 184 | 23808,23809,23812,23813,23816,23817,23818,23819,23820,23821,23823,23824,23825, | ||
| 185 | 23826,23827,23829,23831,23832,23833,23834,23836,23837,23839,23840,23841,23842, | ||
| 186 | 23843,23845,23848,23850,23851,23852,23855,23856,23857,23858,23859,23861,23862, | ||
| 187 | 23863,23864,23865,23866,23867,23868,23871,23872,23873,23874,23875,23876,23877, | ||
| 188 | 23878,23880,23881,23885,23886,23887,23888,23889,23890,23891,23892,23893,23894, | ||
| 189 | 23895,23897,23898,23900,23902,23903,23904,23905,23906,23907,23908,23909,23910, | ||
| 190 | 23911,23912,23914,23917,23918,23920,23921,23922,23923,23925,23926,23927,23928, | ||
| 191 | 23929,23930,23931,23932,23933,23934,23935,23936,23937,23939,23940,23941,23942, | ||
| 192 | 23943,23944,23945,23946,23947,23948,23949,23950,23951,23952,23953,23954,23955, | ||
| 193 | 23956,23957,23958,23959,23960,23962,23963,23964,23966,23967,23968,23969,23970, | ||
| 194 | 23971,23972,23973,23974,23975,23976,23977,23978,23979,23980,23981,23982,23983, | ||
| 195 | 23984,23985,23986,23987,23988,23989,23990,23992,23993,23994,23995,23996,23997, | ||
| 196 | 23998,23999,24000,24001,24002,24003,24004,24006,24007,24008,24009,24010,24011, | ||
| 197 | 24012,24014,24015,24016,24017,24018,24019,24020,24021,24022,24023,24024,24025, | ||
| 198 | 24026,24028,24031,24032,24035,24036,24042,24044,24045,24048,24053,24054,24056, | ||
| 199 | 24057,24058,24059,24060,24063,24064,24068,24071,24073,24074,24075,24077,24078, | ||
| 200 | 24082,24083,24087,24094,24095,24096,24097,24098,24099, | ||
| 201 | 24100,24101,24104,24105,24106,24107,24108,24111,24112,24114,24115,24116,24117, | ||
| 202 | 24118,24121,24122,24126,24127,24128,24129,24131,24134,24135,24136,24137,24138, | ||
| 203 | 24139,24141,24142,24143,24144,24145,24146,24147,24150,24151,24152,24153,24154, | ||
| 204 | 24156,24157,24159,24160,24163,24164,24165,24166,24167,24168,24169,24170,24171, | ||
| 205 | 24172,24173,24174,24175,24176,24177,24181,24183,24185,24190,24193,24194,24195, | ||
| 206 | 24197,24200,24201,24204,24205,24206,24210,24216,24219,24221,24225,24226,24227, | ||
| 207 | 24228,24232,24233,24234,24235,24236,24238,24239,24240,24241,24242,24244,24250, | ||
| 208 | 24251,24252,24253,24255,24256,24257,24258,24259,24260,24261,24262,24263,24264, | ||
| 209 | 24267,24268,24269,24270,24271,24272,24276,24277,24279,24280,24281,24282,24284, | ||
| 210 | 24285,24286,24287,24288,24289,24290,24291,24292,24293,24294,24295,24297,24299, | ||
| 211 | 24300,24301,24302,24303,24304,24305,24306,24307,24309,24312,24313,24315,24316, | ||
| 212 | 24317,24325,24326,24327,24329,24332,24333,24334,24336,24338,24340,24342,24345, | ||
| 213 | 24346,24348,24349,24350,24353,24354,24355,24356,24360,24363,24364,24366,24368, | ||
| 214 | 24370,24371,24372,24373,24374,24375,24376,24379,24381,24382,24383,24385,24386, | ||
| 215 | 24387,24388,24389,24390,24391,24392,24393,24394,24395,24396,24397,24398,24399, | ||
| 216 | 24401,24404,24409,24410,24411,24412,24414,24415,24416,24419,24421,24423,24424, | ||
| 217 | 24427,24430,24431,24434,24436,24437,24438,24440,24442,24445,24446,24447,24451, | ||
| 218 | 24454,24461,24462,24463,24465,24467,24468,24470,24474,24475,24477,24478,24479, | ||
| 219 | 24480,24482,24483,24484,24485,24486,24487,24489,24491,24492,24495,24496,24497, | ||
| 220 | 24498,24499,24500,24502,24504,24505,24506,24507,24510, | ||
| 221 | 24511,24512,24513,24514,24519,24520,24522,24523,24526,24531,24532,24533,24538, | ||
| 222 | 24539,24540,24542,24543,24546,24547,24549,24550,24552,24553,24556,24559,24560, | ||
| 223 | 24562,24563,24564,24566,24567,24569,24570,24572,24583,24584,24585,24587,24588, | ||
| 224 | 24592,24593,24595,24599,24600,24602,24606,24607,24610,24611,24612,24620,24621, | ||
| 225 | 24622,24624,24625,24626,24627,24628,24630,24631,24632,24633,24634,24637,24638, | ||
| 226 | 24640,24644,24645,24646,24647,24648,24649,24650,24652,24654,24655,24657,24659, | ||
| 227 | 24660,24662,24663,24664,24667,24668,24670,24671,24672,24673,24677,24678,24686, | ||
| 228 | 24689,24690,24692,24693,24695,24702,24704,24705,24706,24709,24710,24711,24712, | ||
| 229 | 24714,24715,24718,24719,24720,24721,24723,24725,24727,24728,24729,24732,24734, | ||
| 230 | 24737,24738,24740,24741,24743,24745,24746,24750,24752,24755,24757,24758,24759, | ||
| 231 | 24761,24762,24765,24766,24767,24768,24769,24770,24771,24772,24775,24776,24777, | ||
| 232 | 24780,24781,24782,24783,24784,24786,24787,24788,24790,24791,24793,24795,24798, | ||
| 233 | 24801,24802,24803,24804,24805,24810,24817,24818,24821,24823,24824,24827,24828, | ||
| 234 | 24829,24830,24831,24834,24835,24836,24837,24839,24842,24843,24844,24848,24849, | ||
| 235 | 24850,24851,24852,24854,24855,24856,24857,24859,24860,24861,24862,24865,24866, | ||
| 236 | 24869,24872,24873,24874,24876,24877,24878,24879,24880,24881,24882,24883,24884, | ||
| 237 | 24885,24886,24887,24888,24889,24890,24891,24892,24893,24894,24896,24897,24898, | ||
| 238 | 24899,24900,24901,24902,24903,24905,24907,24909,24911,24912,24914,24915,24916, | ||
| 239 | 24918,24919,24920,24921,24922,24923,24924,24926,24927,24928,24929,24931,24932, | ||
| 240 | 24933,24934,24937,24938,24939,24940,24941,24942,24943, | ||
| 241 | 24945,24946,24947,24948,24950,24952,24953,24954,24955,24956,24957,24958,24959, | ||
| 242 | 24960,24961,24962,24963,24964,24965,24966,24967,24968,24969,24970,24972,24973, | ||
| 243 | 24975,24976,24977,24978,24979,24981,24982,24983,24984,24985,24986,24987,24988, | ||
| 244 | 24990,24991,24992,24993,24994,24995,24996,24997,24998,25002,25003,25005,25006, | ||
| 245 | 25007,25008,25009,25010,25011,25012,25013,25014,25016,25017,25018,25019,25020, | ||
| 246 | 25021,25023,25024,25025,25027,25028,25029,25030,25031,25033,25036,25037,25038, | ||
| 247 | 25039,25040,25043,25045,25046,25047,25048,25049,25050,25051,25052,25053,25054, | ||
| 248 | 25055,25056,25057,25058,25059,25060,25061,25063,25064,25065,25066,25067,25068, | ||
| 249 | 25069,25070,25071,25072,25073,25074,25075,25076,25078,25079,25080,25081,25082, | ||
| 250 | 25083,25084,25085,25086,25088,25089,25090,25091,25092,25093,25095,25097,25107, | ||
| 251 | 25108,25113,25116,25117,25118,25120,25123,25126,25127,25128,25129,25131,25133, | ||
| 252 | 25135,25136,25137,25138,25141,25142,25144,25145,25146,25147,25148,25154,25156, | ||
| 253 | 25157,25158,25162,25167,25168,25173,25174,25175,25177,25178,25180,25181,25182, | ||
| 254 | 25183,25184,25185,25186,25188,25189,25192,25201,25202,25204,25205,25207,25208, | ||
| 255 | 25210,25211,25213,25217,25218,25219,25221,25222,25223,25224,25227,25228,25229, | ||
| 256 | 25230,25231,25232,25236,25241,25244,25245,25246,25251,25254,25255,25257,25258, | ||
| 257 | 25261,25262,25263,25264,25266,25267,25268,25270,25271,25272,25274,25278,25280, | ||
| 258 | 25281,25283,25291,25295,25297,25301,25309,25310,25312,25313,25316,25322,25323, | ||
| 259 | 25328,25330,25333,25336,25337,25338,25339,25344,25347,25348,25349,25350,25354, | ||
| 260 | 25355,25356,25357,25359,25360,25362,25363,25364,25365, | ||
| 261 | 25367,25368,25369,25372,25382,25383,25385,25388,25389,25390,25392,25393,25395, | ||
| 262 | 25396,25397,25398,25399,25400,25403,25404,25406,25407,25408,25409,25412,25415, | ||
| 263 | 25416,25418,25425,25426,25427,25428,25430,25431,25432,25433,25434,25435,25436, | ||
| 264 | 25437,25440,25444,25445,25446,25448,25450,25451,25452,25455,25456,25458,25459, | ||
| 265 | 25460,25461,25464,25465,25468,25469,25470,25471,25473,25475,25476,25477,25478, | ||
| 266 | 25483,25485,25489,25491,25492,25493,25495,25497,25498,25499,25500,25501,25502, | ||
| 267 | 25503,25505,25508,25510,25515,25519,25521,25522,25525,25526,25529,25531,25533, | ||
| 268 | 25535,25536,25537,25538,25539,25541,25543,25544,25546,25547,25548,25553,25555, | ||
| 269 | 25556,25557,25559,25560,25561,25562,25563,25564,25565,25567,25570,25572,25573, | ||
| 270 | 25574,25575,25576,25579,25580,25582,25583,25584,25585,25587,25589,25591,25593, | ||
| 271 | 25594,25595,25596,25598,25603,25604,25606,25607,25608,25609,25610,25613,25614, | ||
| 272 | 25617,25618,25621,25622,25623,25624,25625,25626,25629,25631,25634,25635,25636, | ||
| 273 | 25637,25639,25640,25641,25643,25646,25647,25648,25649,25650,25651,25653,25654, | ||
| 274 | 25655,25656,25657,25659,25660,25662,25664,25666,25667,25673,25675,25676,25677, | ||
| 275 | 25678,25679,25680,25681,25683,25685,25686,25687,25689,25690,25691,25692,25693, | ||
| 276 | 25695,25696,25697,25698,25699,25700,25701,25702,25704,25706,25707,25708,25710, | ||
| 277 | 25711,25712,25713,25714,25715,25716,25717,25718,25719,25723,25724,25725,25726, | ||
| 278 | 25727,25728,25729,25731,25734,25736,25737,25738,25739,25740,25741,25742,25743, | ||
| 279 | 25744,25747,25748,25751,25752,25754,25755,25756,25757,25759,25760,25761,25762, | ||
| 280 | 25763,25765,25766,25767,25768,25770,25771,25775,25777, | ||
| 281 | 25778,25779,25780,25782,25785,25787,25789,25790,25791,25793,25795,25796,25798, | ||
| 282 | 25799,25800,25801,25802,25803,25804,25807,25809,25811,25812,25813,25814,25817, | ||
| 283 | 25818,25819,25820,25821,25823,25824,25825,25827,25829,25831,25832,25833,25834, | ||
| 284 | 25835,25836,25837,25838,25839,25840,25841,25842,25843,25844,25845,25846,25847, | ||
| 285 | 25848,25849,25850,25851,25852,25853,25854,25855,25857,25858,25859,25860,25861, | ||
| 286 | 25862,25863,25864,25866,25867,25868,25869,25870,25871,25872,25873,25875,25876, | ||
| 287 | 25877,25878,25879,25881,25882,25883,25884,25885,25886,25887,25888,25889,25890, | ||
| 288 | 25891,25892,25894,25895,25896,25897,25898,25900,25901,25904,25905,25906,25907, | ||
| 289 | 25911,25914,25916,25917,25920,25921,25922,25923,25924,25926,25927,25930,25931, | ||
| 290 | 25933,25934,25936,25938,25939,25940,25943,25944,25946,25948,25951,25952,25953, | ||
| 291 | 25956,25957,25959,25960,25961,25962,25965,25966,25967,25969,25971,25973,25974, | ||
| 292 | 25976,25977,25978,25979,25980,25981,25982,25983,25984,25985,25986,25987,25988, | ||
| 293 | 25989,25990,25992,25993,25994,25997,25998,25999,26002,26004,26005,26006,26008, | ||
| 294 | 26010,26013,26014,26016,26018,26019,26022,26024,26026,26028,26030,26033,26034, | ||
| 295 | 26035,26036,26037,26038,26039,26040,26042,26043,26046,26047,26048,26050,26055, | ||
| 296 | 26056,26057,26058,26061,26064,26065,26067,26068,26069,26072,26073,26074,26075, | ||
| 297 | 26076,26077,26078,26079,26081,26083,26084,26090,26091,26098,26099,26100,26101, | ||
| 298 | 26104,26105,26107,26108,26109,26110,26111,26113,26116,26117,26119,26120,26121, | ||
| 299 | 26123,26125,26128,26129,26130,26134,26135,26136,26138,26139,26140,26142,26145, | ||
| 300 | 26146,26147,26148,26150,26153,26154,26155,26156,26158, | ||
| 301 | 26160,26162,26163,26167,26168,26169,26170,26171,26173,26175,26176,26178,26180, | ||
| 302 | 26181,26182,26183,26184,26185,26186,26189,26190,26192,26193,26200,26201,26203, | ||
| 303 | 26204,26205,26206,26208,26210,26211,26213,26215,26217,26218,26219,26220,26221, | ||
| 304 | 26225,26226,26227,26229,26232,26233,26235,26236,26237,26239,26240,26241,26243, | ||
| 305 | 26245,26246,26248,26249,26250,26251,26253,26254,26255,26256,26258,26259,26260, | ||
| 306 | 26261,26264,26265,26266,26267,26268,26270,26271,26272,26273,26274,26275,26276, | ||
| 307 | 26277,26278,26281,26282,26283,26284,26285,26287,26288,26289,26290,26291,26293, | ||
| 308 | 26294,26295,26296,26298,26299,26300,26301,26303,26304,26305,26306,26307,26308, | ||
| 309 | 26309,26310,26311,26312,26313,26314,26315,26316,26317,26318,26319,26320,26321, | ||
| 310 | 26322,26323,26324,26325,26326,26327,26328,26330,26334,26335,26336,26337,26338, | ||
| 311 | 26339,26340,26341,26343,26344,26346,26347,26348,26349,26350,26351,26353,26357, | ||
| 312 | 26358,26360,26362,26363,26365,26369,26370,26371,26372,26373,26374,26375,26380, | ||
| 313 | 26382,26383,26385,26386,26387,26390,26392,26393,26394,26396,26398,26400,26401, | ||
| 314 | 26402,26403,26404,26405,26407,26409,26414,26416,26418,26419,26422,26423,26424, | ||
| 315 | 26425,26427,26428,26430,26431,26433,26436,26437,26439,26442,26443,26445,26450, | ||
| 316 | 26452,26453,26455,26456,26457,26458,26459,26461,26466,26467,26468,26470,26471, | ||
| 317 | 26475,26476,26478,26481,26484,26486,26488,26489,26490,26491,26493,26496,26498, | ||
| 318 | 26499,26501,26502,26504,26506,26508,26509,26510,26511,26513,26514,26515,26516, | ||
| 319 | 26518,26521,26523,26527,26528,26529,26532,26534,26537,26540,26542,26545,26546, | ||
| 320 | 26548,26553,26554,26555,26556,26557,26558,26559,26560, | ||
| 321 | 26562,26565,26566,26567,26568,26569,26570,26571,26572,26573,26574,26581,26582, | ||
| 322 | 26583,26587,26591,26593,26595,26596,26598,26599,26600,26602,26603,26605,26606, | ||
| 323 | 26610,26613,26614,26615,26616,26617,26618,26619,26620,26622,26625,26626,26627, | ||
| 324 | 26628,26630,26637,26640,26642,26644,26645,26648,26649,26650,26651,26652,26654, | ||
| 325 | 26655,26656,26658,26659,26660,26661,26662,26663,26664,26667,26668,26669,26670, | ||
| 326 | 26671,26672,26673,26676,26677,26678,26682,26683,26687,26695,26699,26701,26703, | ||
| 327 | 26706,26710,26711,26712,26713,26714,26715,26716,26717,26718,26719,26730,26732, | ||
| 328 | 26733,26734,26735,26736,26737,26738,26739,26741,26744,26745,26746,26747,26748, | ||
| 329 | 26749,26750,26751,26752,26754,26756,26759,26760,26761,26762,26763,26764,26765, | ||
| 330 | 26766,26768,26769,26770,26772,26773,26774,26776,26777,26778,26779,26780,26781, | ||
| 331 | 26782,26783,26784,26785,26787,26788,26789,26793,26794,26795,26796,26798,26801, | ||
| 332 | 26802,26804,26806,26807,26808,26809,26810,26811,26812,26813,26814,26815,26817, | ||
| 333 | 26819,26820,26821,26822,26823,26824,26826,26828,26830,26831,26832,26833,26835, | ||
| 334 | 26836,26838,26839,26841,26843,26844,26845,26846,26847,26849,26850,26852,26853, | ||
| 335 | 26854,26855,26856,26857,26858,26859,26860,26861,26863,26866,26867,26868,26870, | ||
| 336 | 26871,26872,26875,26877,26878,26879,26880,26882,26883,26884,26886,26887,26888, | ||
| 337 | 26889,26890,26892,26895,26897,26899,26900,26901,26902,26903,26904,26905,26906, | ||
| 338 | 26907,26908,26909,26910,26913,26914,26915,26917,26918,26919,26920,26921,26922, | ||
| 339 | 26923,26924,26926,26927,26929,26930,26931,26933,26934,26935,26936,26938,26939, | ||
| 340 | 26940,26942,26944,26945,26947,26948,26949,26950,26951, | ||
| 341 | 26952,26953,26954,26955,26956,26957,26958,26959,26960,26961,26962,26963,26965, | ||
| 342 | 26966,26968,26969,26971,26972,26975,26977,26978,26980,26981,26983,26984,26985, | ||
| 343 | 26986,26988,26989,26991,26992,26994,26995,26996,26997,26998,27002,27003,27005, | ||
| 344 | 27006,27007,27009,27011,27013,27018,27019,27020,27022,27023,27024,27025,27026, | ||
| 345 | 27027,27030,27031,27033,27034,27037,27038,27039,27040,27041,27042,27043,27044, | ||
| 346 | 27045,27046,27049,27050,27052,27054,27055,27056,27058,27059,27061,27062,27064, | ||
| 347 | 27065,27066,27068,27069,27070,27071,27072,27074,27075,27076,27077,27078,27079, | ||
| 348 | 27080,27081,27083,27085,27087,27089,27090,27091,27093,27094,27095,27096,27097, | ||
| 349 | 27098,27100,27101,27102,27105,27106,27107,27108,27109,27110,27111,27112,27113, | ||
| 350 | 27114,27115,27116,27118,27119,27120,27121,27123,27124,27125,27126,27127,27128, | ||
| 351 | 27129,27130,27131,27132,27134,27136,27137,27138,27139,27140,27141,27142,27143, | ||
| 352 | 27144,27145,27147,27148,27149,27150,27151,27152,27153,27154,27155,27156,27157, | ||
| 353 | 27158,27161,27162,27163,27164,27165,27166,27168,27170,27171,27172,27173,27174, | ||
| 354 | 27175,27177,27179,27180,27181,27182,27184,27186,27187,27188,27190,27191,27192, | ||
| 355 | 27193,27194,27195,27196,27199,27200,27201,27202,27203,27205,27206,27208,27209, | ||
| 356 | 27210,27211,27212,27213,27214,27215,27217,27218,27219,27220,27221,27222,27223, | ||
| 357 | 27226,27228,27229,27230,27231,27232,27234,27235,27236,27238,27239,27240,27241, | ||
| 358 | 27242,27243,27244,27245,27246,27247,27248,27250,27251,27252,27253,27254,27255, | ||
| 359 | 27256,27258,27259,27261,27262,27263,27265,27266,27267,27269,27270,27271,27272, | ||
| 360 | 27273,27274,27275,27276,27277,27279,27282,27283,27284, | ||
| 361 | 27285,27286,27288,27289,27290,27291,27292,27293,27294,27295,27297,27298,27299, | ||
| 362 | 27300,27301,27302,27303,27304,27306,27309,27310,27311,27312,27313,27314,27315, | ||
| 363 | 27316,27317,27318,27319,27320,27321,27322,27323,27324,27325,27326,27327,27328, | ||
| 364 | 27329,27330,27331,27332,27333,27334,27335,27336,27337,27338,27339,27340,27341, | ||
| 365 | 27342,27343,27344,27345,27346,27347,27348,27349,27350,27351,27352,27353,27354, | ||
| 366 | 27355,27356,27357,27358,27359,27360,27361,27362,27363,27364,27365,27366,27367, | ||
| 367 | 27368,27369,27370,27371,27372,27373,27374,27375,27376,27377,27378,27379,27380, | ||
| 368 | 27381,27382,27383,27384,27385,27386,27387,27388,27389,27390,27391,27392,27393, | ||
| 369 | 27394,27395,27396,27397,27398,27399,27400,27401,27402,27403,27404,27405,27406, | ||
| 370 | 27407,27408,27409,27410,27411,27412,27413,27414,27415,27416,27417,27418,27419, | ||
| 371 | 27420,27421,27422,27423,27429,27430,27432,27433,27434,27435,27436,27437,27438, | ||
| 372 | 27439,27440,27441,27443,27444,27445,27446,27448,27451,27452,27453,27455,27456, | ||
| 373 | 27457,27458,27460,27461,27464,27466,27467,27469,27470,27471,27472,27473,27474, | ||
| 374 | 27475,27476,27477,27478,27479,27480,27482,27483,27484,27485,27486,27487,27488, | ||
| 375 | 27489,27496,27497,27499,27500,27501,27502,27503,27504,27505,27506,27507,27508, | ||
| 376 | 27509,27510,27511,27512,27514,27517,27518,27519,27520,27525,27528,27532,27534, | ||
| 377 | 27535,27536,27537,27540,27541,27543,27544,27545,27548,27549,27550,27551,27552, | ||
| 378 | 27554,27555,27556,27557,27558,27559,27560,27561,27563,27564,27565,27566,27567, | ||
| 379 | 27568,27569,27570,27574,27576,27577,27578,27579,27580,27581,27582,27584,27587, | ||
| 380 | 27588,27590,27591,27592,27593,27594,27596,27598,27600, | ||
| 381 | 27601,27608,27610,27612,27613,27614,27615,27616,27618,27619,27620,27621,27622, | ||
| 382 | 27623,27624,27625,27628,27629,27630,27632,27633,27634,27636,27638,27639,27640, | ||
| 383 | 27642,27643,27644,27646,27647,27648,27649,27650,27651,27652,27656,27657,27658, | ||
| 384 | 27659,27660,27662,27666,27671,27676,27677,27678,27680,27683,27685,27691,27692, | ||
| 385 | 27693,27697,27699,27702,27703,27705,27706,27707,27708,27710,27711,27715,27716, | ||
| 386 | 27717,27720,27723,27724,27725,27726,27727,27729,27730,27731,27734,27736,27737, | ||
| 387 | 27738,27746,27747,27749,27750,27751,27755,27756,27757,27758,27759,27761,27763, | ||
| 388 | 27765,27767,27768,27770,27771,27772,27775,27776,27780,27783,27786,27787,27789, | ||
| 389 | 27790,27793,27794,27797,27798,27799,27800,27802,27804,27805,27806,27808,27810, | ||
| 390 | 27816,27820,27823,27824,27828,27829,27830,27831,27834,27840,27841,27842,27843, | ||
| 391 | 27846,27847,27848,27851,27853,27854,27855,27857,27858,27864,27865,27866,27868, | ||
| 392 | 27869,27871,27876,27878,27879,27881,27884,27885,27890,27892,27897,27903,27904, | ||
| 393 | 27906,27907,27909,27910,27912,27913,27914,27917,27919,27920,27921,27923,27924, | ||
| 394 | 27925,27926,27928,27932,27933,27935,27936,27937,27938,27939,27940,27942,27944, | ||
| 395 | 27945,27948,27949,27951,27952,27956,27958,27959,27960,27962,27967,27968,27970, | ||
| 396 | 27972,27977,27980,27984,27989,27990,27991,27992,27995,27997,27999,28001,28002, | ||
| 397 | 28004,28005,28007,28008,28011,28012,28013,28016,28017,28018,28019,28021,28022, | ||
| 398 | 28025,28026,28027,28029,28030,28031,28032,28033,28035,28036,28038,28039,28042, | ||
| 399 | 28043,28045,28047,28048,28050,28054,28055,28056,28057,28058,28060,28066,28069, | ||
| 400 | 28076,28077,28080,28081,28083,28084,28086,28087,28089, | ||
| 401 | 28090,28091,28092,28093,28094,28097,28098,28099,28104,28105,28106,28109,28110, | ||
| 402 | 28111,28112,28114,28115,28116,28117,28119,28122,28123,28124,28127,28130,28131, | ||
| 403 | 28133,28135,28136,28137,28138,28141,28143,28144,28146,28148,28149,28150,28152, | ||
| 404 | 28154,28157,28158,28159,28160,28161,28162,28163,28164,28166,28167,28168,28169, | ||
| 405 | 28171,28175,28178,28179,28181,28184,28185,28187,28188,28190,28191,28194,28198, | ||
| 406 | 28199,28200,28202,28204,28206,28208,28209,28211,28213,28214,28215,28217,28219, | ||
| 407 | 28220,28221,28222,28223,28224,28225,28226,28229,28230,28231,28232,28233,28234, | ||
| 408 | 28235,28236,28239,28240,28241,28242,28245,28247,28249,28250,28252,28253,28254, | ||
| 409 | 28256,28257,28258,28259,28260,28261,28262,28263,28264,28265,28266,28268,28269, | ||
| 410 | 28271,28272,28273,28274,28275,28276,28277,28278,28279,28280,28281,28282,28283, | ||
| 411 | 28284,28285,28288,28289,28290,28292,28295,28296,28298,28299,28300,28301,28302, | ||
| 412 | 28305,28306,28307,28308,28309,28310,28311,28313,28314,28315,28317,28318,28320, | ||
| 413 | 28321,28323,28324,28326,28328,28329,28331,28332,28333,28334,28336,28339,28341, | ||
| 414 | 28344,28345,28348,28350,28351,28352,28355,28356,28357,28358,28360,28361,28362, | ||
| 415 | 28364,28365,28366,28368,28370,28374,28376,28377,28379,28380,28381,28387,28391, | ||
| 416 | 28394,28395,28396,28397,28398,28399,28400,28401,28402,28403,28405,28406,28407, | ||
| 417 | 28408,28410,28411,28412,28413,28414,28415,28416,28417,28419,28420,28421,28423, | ||
| 418 | 28424,28426,28427,28428,28429,28430,28432,28433,28434,28438,28439,28440,28441, | ||
| 419 | 28442,28443,28444,28445,28446,28447,28449,28450,28451,28453,28454,28455,28456, | ||
| 420 | 28460,28462,28464,28466,28468,28469,28471,28472,28473, | ||
| 421 | 28474,28475,28476,28477,28479,28480,28481,28482,28483,28484,28485,28488,28489, | ||
| 422 | 28490,28492,28494,28495,28496,28497,28498,28499,28500,28501,28502,28503,28505, | ||
| 423 | 28506,28507,28509,28511,28512,28513,28515,28516,28517,28519,28520,28521,28522, | ||
| 424 | 28523,28524,28527,28528,28529,28531,28533,28534,28535,28537,28539,28541,28542, | ||
| 425 | 28543,28544,28545,28546,28547,28549,28550,28551,28554,28555,28559,28560,28561, | ||
| 426 | 28562,28563,28564,28565,28566,28567,28568,28569,28570,28571,28573,28574,28575, | ||
| 427 | 28576,28578,28579,28580,28581,28582,28584,28585,28586,28587,28588,28589,28590, | ||
| 428 | 28591,28592,28593,28594,28596,28597,28599,28600,28602,28603,28604,28605,28606, | ||
| 429 | 28607,28609,28611,28612,28613,28614,28615,28616,28618,28619,28620,28621,28622, | ||
| 430 | 28623,28624,28627,28628,28629,28630,28631,28632,28633,28634,28635,28636,28637, | ||
| 431 | 28639,28642,28643,28644,28645,28646,28647,28648,28649,28650,28651,28652,28653, | ||
| 432 | 28656,28657,28658,28659,28660,28661,28662,28663,28664,28665,28666,28667,28668, | ||
| 433 | 28669,28670,28671,28672,28673,28674,28675,28676,28677,28678,28679,28680,28681, | ||
| 434 | 28682,28683,28684,28685,28686,28687,28688,28690,28691,28692,28693,28694,28695, | ||
| 435 | 28696,28697,28700,28701,28702,28703,28704,28705,28706,28708,28709,28710,28711, | ||
| 436 | 28712,28713,28714,28715,28716,28717,28718,28719,28720,28721,28722,28723,28724, | ||
| 437 | 28726,28727,28728,28730,28731,28732,28733,28734,28735,28736,28737,28738,28739, | ||
| 438 | 28740,28741,28742,28743,28744,28745,28746,28747,28749,28750,28752,28753,28754, | ||
| 439 | 28755,28756,28757,28758,28759,28760,28761,28762,28763,28764,28765,28767,28768, | ||
| 440 | 28769,28770,28771,28772,28773,28774,28775,28776,28777, | ||
| 441 | 28778,28782,28785,28786,28787,28788,28791,28793,28794,28795,28797,28801,28802, | ||
| 442 | 28803,28804,28806,28807,28808,28811,28812,28813,28815,28816,28817,28819,28823, | ||
| 443 | 28824,28826,28827,28830,28831,28832,28833,28834,28835,28836,28837,28838,28839, | ||
| 444 | 28840,28841,28842,28848,28850,28852,28853,28854,28858,28862,28863,28868,28869, | ||
| 445 | 28870,28871,28873,28875,28876,28877,28878,28879,28880,28881,28882,28883,28884, | ||
| 446 | 28885,28886,28887,28890,28892,28893,28894,28896,28897,28898,28899,28901,28906, | ||
| 447 | 28910,28912,28913,28914,28915,28916,28917,28918,28920,28922,28923,28924,28926, | ||
| 448 | 28927,28928,28929,28930,28931,28932,28933,28934,28935,28936,28939,28940,28941, | ||
| 449 | 28942,28943,28945,28946,28948,28951,28955,28956,28957,28958,28959,28960,28961, | ||
| 450 | 28962,28963,28964,28965,28967,28968,28969,28970,28971,28972,28973,28974,28978, | ||
| 451 | 28979,28980,28981,28983,28984,28985,28986,28987,28988,28989,28990,28991,28992, | ||
| 452 | 28993,28994,28995,28996,28998,28999,29000,29001,29003,29005,29007,29008,29009, | ||
| 453 | 29010,29011,29012,29013,29014,29015,29016,29017,29018,29019,29021,29023,29024, | ||
| 454 | 29025,29026,29027,29029,29033,29034,29035,29036,29037,29039,29040,29041,29044, | ||
| 455 | 29045,29046,29047,29049,29051,29052,29054,29055,29056,29057,29058,29059,29061, | ||
| 456 | 29062,29063,29064,29065,29067,29068,29069,29070,29072,29073,29074,29075,29077, | ||
| 457 | 29078,29079,29082,29083,29084,29085,29086,29089,29090,29091,29092,29093,29094, | ||
| 458 | 29095,29097,29098,29099,29101,29102,29103,29104,29105,29106,29108,29110,29111, | ||
| 459 | 29112,29114,29115,29116,29117,29118,29119,29120,29121,29122,29124,29125,29126, | ||
| 460 | 29127,29128,29129,29130,29131,29132,29133,29135,29136, | ||
| 461 | 29137,29138,29139,29142,29143,29144,29145,29146,29147,29148,29149,29150,29151, | ||
| 462 | 29153,29154,29155,29156,29158,29160,29161,29162,29163,29164,29165,29167,29168, | ||
| 463 | 29169,29170,29171,29172,29173,29174,29175,29176,29178,29179,29180,29181,29182, | ||
| 464 | 29183,29184,29185,29186,29187,29188,29189,29191,29192,29193,29194,29195,29196, | ||
| 465 | 29197,29198,29199,29200,29201,29202,29203,29204,29205,29206,29207,29208,29209, | ||
| 466 | 29210,29211,29212,29214,29215,29216,29217,29218,29219,29220,29221,29222,29223, | ||
| 467 | 29225,29227,29229,29230,29231,29234,29235,29236,29242,29244,29246,29248,29249, | ||
| 468 | 29250,29251,29252,29253,29254,29257,29258,29259,29262,29263,29264,29265,29267, | ||
| 469 | 29268,29269,29271,29272,29274,29276,29278,29280,29283,29284,29285,29288,29290, | ||
| 470 | 29291,29292,29293,29296,29297,29299,29300,29302,29303,29304,29307,29308,29309, | ||
| 471 | 29314,29315,29317,29318,29319,29320,29321,29324,29326,29328,29329,29331,29332, | ||
| 472 | 29333,29334,29335,29336,29337,29338,29339,29340,29341,29342,29344,29345,29346, | ||
| 473 | 29347,29348,29349,29350,29351,29352,29353,29354,29355,29358,29361,29362,29363, | ||
| 474 | 29365,29370,29371,29372,29373,29374,29375,29376,29381,29382,29383,29385,29386, | ||
| 475 | 29387,29388,29391,29393,29395,29396,29397,29398,29400,29402,29403,58566,58567, | ||
| 476 | 58568,58569,58570,58571,58572,58573,58574,58575,58576,58577,58578,58579,58580, | ||
| 477 | 58581,58582,58583,58584,58585,58586,58587,58588,58589,58590,58591,58592,58593, | ||
| 478 | 58594,58595,58596,58597,58598,58599,58600,58601,58602,58603,58604,58605,58606, | ||
| 479 | 58607,58608,58609,58610,58611,58612,58613,58614,58615,58616,58617,58618,58619, | ||
| 480 | 58620,58621,58622,58623,58624,58625,58626,58627,58628, | ||
| 481 | 58629,58630,58631,58632,58633,58634,58635,58636,58637,58638,58639,58640,58641, | ||
| 482 | 58642,58643,58644,58645,58646,58647,58648,58649,58650,58651,58652,58653,58654, | ||
| 483 | 58655,58656,58657,58658,58659,58660,58661,12288,12289,12290,183,713,711,168, | ||
| 484 | 12291,12293,8212,65374,8214,8230,8216,8217,8220,8221,12308,12309,12296,12297, | ||
| 485 | 12298,12299,12300,12301,12302,12303,12310,12311,12304,12305,177,215,247,8758, | ||
| 486 | 8743,8744,8721,8719,8746,8745,8712,8759,8730,8869,8741,8736,8978,8857,8747, | ||
| 487 | 8750,8801,8780,8776,8765,8733,8800,8814,8815,8804,8805,8734,8757,8756,9794, | ||
| 488 | 9792,176,8242,8243,8451,65284,164,65504,65505,8240,167,8470,9734,9733,9675, | ||
| 489 | 9679,9678,9671,9670,9633,9632,9651,9650,8251,8594,8592,8593,8595,12307,58662, | ||
| 490 | 58663,58664,58665,58666,58667,58668,58669,58670,58671,58672,58673,58674,58675, | ||
| 491 | 58676,58677,58678,58679,58680,58681,58682,58683,58684,58685,58686,58687,58688, | ||
| 492 | 58689,58690,58691,58692,58693,58694,58695,58696,58697,58698,58699,58700,58701, | ||
| 493 | 58702,58703,58704,58705,58706,58707,58708,58709,58710,58711,58712,58713,58714, | ||
| 494 | 58715,58716,58717,58718,58719,58720,58721,58722,58723,58724,58725,58726,58727, | ||
| 495 | 58728,58729,58730,58731,58732,58733,58734,58735,58736,58737,58738,58739,58740, | ||
| 496 | 58741,58742,58743,58744,58745,58746,58747,58748,58749,58750,58751,58752,58753, | ||
| 497 | 58754,58755,58756,58757,8560,8561,8562,8563,8564,8565,8566,8567,8568,8569, | ||
| 498 | 59238,59239,59240,59241,59242,59243,9352,9353,9354,9355,9356,9357,9358,9359, | ||
| 499 | 9360,9361,9362,9363,9364,9365,9366,9367,9368, | ||
| 500 | 9369,9370,9371,9332,9333,9334,9335,9336,9337,9338,9339,9340,9341,9342,9343, | ||
| 501 | 9344,9345,9346,9347,9348,9349,9350,9351,9312,9313,9314,9315,9316,9317,9318, | ||
| 502 | 9319,9320,9321,8364,59245,12832,12833,12834,12835,12836,12837,12838,12839, | ||
| 503 | 12840,12841,59246,59247,8544,8545,8546,8547,8548,8549,8550,8551,8552,8553, | ||
| 504 | 8554,8555,59248,59249,58758,58759,58760,58761,58762,58763,58764,58765,58766, | ||
| 505 | 58767,58768,58769,58770,58771,58772,58773,58774,58775,58776,58777,58778,58779, | ||
| 506 | 58780,58781,58782,58783,58784,58785,58786,58787,58788,58789,58790,58791,58792, | ||
| 507 | 58793,58794,58795,58796,58797,58798,58799,58800,58801,58802,58803,58804,58805, | ||
| 508 | 58806,58807,58808,58809,58810,58811,58812,58813,58814,58815,58816,58817,58818, | ||
| 509 | 58819,58820,58821,58822,58823,58824,58825,58826,58827,58828,58829,58830,58831, | ||
| 510 | 58832,58833,58834,58835,58836,58837,58838,58839,58840,58841,58842,58843,58844, | ||
| 511 | 58845,58846,58847,58848,58849,58850,58851,58852,58853,65281,65282,65283,65509, | ||
| 512 | 65285,65286,65287,65288,65289,65290,65291,65292,65293,65294,65295,65296,65297, | ||
| 513 | 65298,65299,65300,65301,65302,65303,65304,65305,65306,65307,65308,65309,65310, | ||
| 514 | 65311,65312,65313,65314,65315,65316,65317,65318,65319,65320,65321,65322,65323, | ||
| 515 | 65324,65325,65326,65327,65328,65329,65330,65331,65332,65333,65334,65335,65336, | ||
| 516 | 65337,65338,65339,65340,65341,65342,65343,65344,65345,65346,65347,65348,65349, | ||
| 517 | 65350,65351,65352,65353,65354,65355,65356,65357,65358,65359,65360,65361,65362, | ||
| 518 | 65363,65364,65365,65366,65367,65368,65369,65370,65371,65372,65373,65507,58854, | ||
| 519 | 58855,58856,58857,58858, | ||
| 520 | 58859,58860,58861,58862,58863,58864,58865,58866,58867,58868,58869,58870,58871, | ||
| 521 | 58872,58873,58874,58875,58876,58877,58878,58879,58880,58881,58882,58883,58884, | ||
| 522 | 58885,58886,58887,58888,58889,58890,58891,58892,58893,58894,58895,58896,58897, | ||
| 523 | 58898,58899,58900,58901,58902,58903,58904,58905,58906,58907,58908,58909,58910, | ||
| 524 | 58911,58912,58913,58914,58915,58916,58917,58918,58919,58920,58921,58922,58923, | ||
| 525 | 58924,58925,58926,58927,58928,58929,58930,58931,58932,58933,58934,58935,58936, | ||
| 526 | 58937,58938,58939,58940,58941,58942,58943,58944,58945,58946,58947,58948,58949, | ||
| 527 | 12353,12354,12355,12356,12357,12358,12359,12360,12361,12362,12363,12364,12365, | ||
| 528 | 12366,12367,12368,12369,12370,12371,12372,12373,12374,12375,12376,12377,12378, | ||
| 529 | 12379,12380,12381,12382,12383,12384,12385,12386,12387,12388,12389,12390,12391, | ||
| 530 | 12392,12393,12394,12395,12396,12397,12398,12399,12400,12401,12402,12403,12404, | ||
| 531 | 12405,12406,12407,12408,12409,12410,12411,12412,12413,12414,12415,12416,12417, | ||
| 532 | 12418,12419,12420,12421,12422,12423,12424,12425,12426,12427,12428,12429,12430, | ||
| 533 | 12431,12432,12433,12434,12435,59250,59251,59252,59253,59254,59255,59256,59257, | ||
| 534 | 59258,59259,59260,58950,58951,58952,58953,58954,58955,58956,58957,58958,58959, | ||
| 535 | 58960,58961,58962,58963,58964,58965,58966,58967,58968,58969,58970,58971,58972, | ||
| 536 | 58973,58974,58975,58976,58977,58978,58979,58980,58981,58982,58983,58984,58985, | ||
| 537 | 58986,58987,58988,58989,58990,58991,58992,58993,58994,58995,58996,58997,58998, | ||
| 538 | 58999,59000,59001,59002,59003,59004,59005,59006,59007,59008,59009,59010,59011, | ||
| 539 | 59012,59013,59014,59015,59016,59017,59018,59019,59020, | ||
| 540 | 59021,59022,59023,59024,59025,59026,59027,59028,59029,59030,59031,59032,59033, | ||
| 541 | 59034,59035,59036,59037,59038,59039,59040,59041,59042,59043,59044,59045,12449, | ||
| 542 | 12450,12451,12452,12453,12454,12455,12456,12457,12458,12459,12460,12461,12462, | ||
| 543 | 12463,12464,12465,12466,12467,12468,12469,12470,12471,12472,12473,12474,12475, | ||
| 544 | 12476,12477,12478,12479,12480,12481,12482,12483,12484,12485,12486,12487,12488, | ||
| 545 | 12489,12490,12491,12492,12493,12494,12495,12496,12497,12498,12499,12500,12501, | ||
| 546 | 12502,12503,12504,12505,12506,12507,12508,12509,12510,12511,12512,12513,12514, | ||
| 547 | 12515,12516,12517,12518,12519,12520,12521,12522,12523,12524,12525,12526,12527, | ||
| 548 | 12528,12529,12530,12531,12532,12533,12534,59261,59262,59263,59264,59265,59266, | ||
| 549 | 59267,59268,59046,59047,59048,59049,59050,59051,59052,59053,59054,59055,59056, | ||
| 550 | 59057,59058,59059,59060,59061,59062,59063,59064,59065,59066,59067,59068,59069, | ||
| 551 | 59070,59071,59072,59073,59074,59075,59076,59077,59078,59079,59080,59081,59082, | ||
| 552 | 59083,59084,59085,59086,59087,59088,59089,59090,59091,59092,59093,59094,59095, | ||
| 553 | 59096,59097,59098,59099,59100,59101,59102,59103,59104,59105,59106,59107,59108, | ||
| 554 | 59109,59110,59111,59112,59113,59114,59115,59116,59117,59118,59119,59120,59121, | ||
| 555 | 59122,59123,59124,59125,59126,59127,59128,59129,59130,59131,59132,59133,59134, | ||
| 556 | 59135,59136,59137,59138,59139,59140,59141,913,914,915,916,917,918,919,920,921, | ||
| 557 | 922,923,924,925,926,927,928,929,931,932,933,934,935,936,937,59269,59270,59271, | ||
| 558 | 59272,59273,59274,59275,59276,945,946,947,948,949,950,951,952,953, | ||
| 559 | 954,955,956,957,958,959,960,961,963,964,965,966,967,968,969,59277,59278,59279, | ||
| 560 | 59280,59281,59282,59283,65077,65078,65081,65082,65087,65088,65085,65086,65089, | ||
| 561 | 65090,65091,65092,59284,59285,65083,65084,65079,65080,65073,59286,65075,65076, | ||
| 562 | 59287,59288,59289,59290,59291,59292,59293,59294,59295,59142,59143,59144,59145, | ||
| 563 | 59146,59147,59148,59149,59150,59151,59152,59153,59154,59155,59156,59157,59158, | ||
| 564 | 59159,59160,59161,59162,59163,59164,59165,59166,59167,59168,59169,59170,59171, | ||
| 565 | 59172,59173,59174,59175,59176,59177,59178,59179,59180,59181,59182,59183,59184, | ||
| 566 | 59185,59186,59187,59188,59189,59190,59191,59192,59193,59194,59195,59196,59197, | ||
| 567 | 59198,59199,59200,59201,59202,59203,59204,59205,59206,59207,59208,59209,59210, | ||
| 568 | 59211,59212,59213,59214,59215,59216,59217,59218,59219,59220,59221,59222,59223, | ||
| 569 | 59224,59225,59226,59227,59228,59229,59230,59231,59232,59233,59234,59235,59236, | ||
| 570 | 59237,1040,1041,1042,1043,1044,1045,1025,1046,1047,1048,1049,1050,1051,1052, | ||
| 571 | 1053,1054,1055,1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067, | ||
| 572 | 1068,1069,1070,1071,59296,59297,59298,59299,59300,59301,59302,59303,59304, | ||
| 573 | 59305,59306,59307,59308,59309,59310,1072,1073,1074,1075,1076,1077,1105,1078, | ||
| 574 | 1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093, | ||
| 575 | 1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,59311,59312,59313,59314, | ||
| 576 | 59315,59316,59317,59318,59319,59320,59321,59322,59323,714,715,729,8211,8213, | ||
| 577 | 8229,8245,8453,8457,8598,8599,8600,8601, | ||
| 578 | 8725,8735,8739,8786,8806,8807,8895,9552,9553,9554,9555,9556,9557,9558,9559, | ||
| 579 | 9560,9561,9562,9563,9564,9565,9566,9567,9568,9569,9570,9571,9572,9573,9574, | ||
| 580 | 9575,9576,9577,9578,9579,9580,9581,9582,9583,9584,9585,9586,9587,9601,9602, | ||
| 581 | 9603,9604,9605,9606,9607,9608,9609,9610,9611,9612,9613,9614,9615,9619,9620, | ||
| 582 | 9621,9660,9661,9698,9699,9700,9701,9737,8853,12306,12317,12318,59324,59325, | ||
| 583 | 59326,59327,59328,59329,59330,59331,59332,59333,59334,257,225,462,224,275,233, | ||
| 584 | 283,232,299,237,464,236,333,243,466,242,363,250,468,249,470,472,474,476,252, | ||
| 585 | 234,593,59335,324,328,505,609,59337,59338,59339,59340,12549,12550,12551,12552, | ||
| 586 | 12553,12554,12555,12556,12557,12558,12559,12560,12561,12562,12563,12564,12565, | ||
| 587 | 12566,12567,12568,12569,12570,12571,12572,12573,12574,12575,12576,12577,12578, | ||
| 588 | 12579,12580,12581,12582,12583,12584,12585,59341,59342,59343,59344,59345,59346, | ||
| 589 | 59347,59348,59349,59350,59351,59352,59353,59354,59355,59356,59357,59358,59359, | ||
| 590 | 59360,59361,12321,12322,12323,12324,12325,12326,12327,12328,12329,12963,13198, | ||
| 591 | 13199,13212,13213,13214,13217,13252,13262,13265,13266,13269,65072,65506,65508, | ||
| 592 | 59362,8481,12849,59363,8208,59364,59365,59366,12540,12443,12444,12541,12542, | ||
| 593 | 12294,12445,12446,65097,65098,65099,65100,65101,65102,65103,65104,65105,65106, | ||
| 594 | 65108,65109,65110,65111,65113,65114,65115,65116,65117,65118,65119,65120,65121, | ||
| 595 | 65122,65123,65124,65125,65126,65128,65129,65130,65131,12350,12272,12273,12274, | ||
| 596 | 12275,12276,12277, | ||
| 597 | 12278,12279,12280,12281,12282,12283,12295,59380,59381,59382,59383,59384,59385, | ||
| 598 | 59386,59387,59388,59389,59390,59391,59392,9472,9473,9474,9475,9476,9477,9478, | ||
| 599 | 9479,9480,9481,9482,9483,9484,9485,9486,9487,9488,9489,9490,9491,9492,9493, | ||
| 600 | 9494,9495,9496,9497,9498,9499,9500,9501,9502,9503,9504,9505,9506,9507,9508, | ||
| 601 | 9509,9510,9511,9512,9513,9514,9515,9516,9517,9518,9519,9520,9521,9522,9523, | ||
| 602 | 9524,9525,9526,9527,9528,9529,9530,9531,9532,9533,9534,9535,9536,9537,9538, | ||
| 603 | 9539,9540,9541,9542,9543,9544,9545,9546,9547,59393,59394,59395,59396,59397, | ||
| 604 | 59398,59399,59400,59401,59402,59403,59404,59405,59406,59407,29404,29405,29407, | ||
| 605 | 29410,29411,29412,29413,29414,29415,29418,29419,29429,29430,29433,29437,29438, | ||
| 606 | 29439,29440,29442,29444,29445,29446,29447,29448,29449,29451,29452,29453,29455, | ||
| 607 | 29456,29457,29458,29460,29464,29465,29466,29471,29472,29475,29476,29478,29479, | ||
| 608 | 29480,29485,29487,29488,29490,29491,29493,29494,29498,29499,29500,29501,29504, | ||
| 609 | 29505,29506,29507,29508,29509,29510,29511,29512,29513,29514,29515,29516,29518, | ||
| 610 | 29519,29521,29523,29524,29525,29526,29528,29529,29530,29531,29532,29533,29534, | ||
| 611 | 29535,29537,29538,29539,29540,29541,29542,29543,29544,29545,29546,29547,29550, | ||
| 612 | 29552,29553,57344,57345,57346,57347,57348,57349,57350,57351,57352,57353,57354, | ||
| 613 | 57355,57356,57357,57358,57359,57360,57361,57362,57363,57364,57365,57366,57367, | ||
| 614 | 57368,57369,57370,57371,57372,57373,57374,57375,57376,57377,57378,57379,57380, | ||
| 615 | 57381,57382,57383,57384,57385,57386,57387,57388,57389,57390,57391,57392, | ||
| 616 | 57393,57394,57395,57396,57397,57398,57399,57400,57401,57402,57403,57404,57405, | ||
| 617 | 57406,57407,57408,57409,57410,57411,57412,57413,57414,57415,57416,57417,57418, | ||
| 618 | 57419,57420,57421,57422,57423,57424,57425,57426,57427,57428,57429,57430,57431, | ||
| 619 | 57432,57433,57434,57435,57436,57437,29554,29555,29556,29557,29558,29559,29560, | ||
| 620 | 29561,29562,29563,29564,29565,29567,29568,29569,29570,29571,29573,29574,29576, | ||
| 621 | 29578,29580,29581,29583,29584,29586,29587,29588,29589,29591,29592,29593,29594, | ||
| 622 | 29596,29597,29598,29600,29601,29603,29604,29605,29606,29607,29608,29610,29612, | ||
| 623 | 29613,29617,29620,29621,29622,29624,29625,29628,29629,29630,29631,29633,29635, | ||
| 624 | 29636,29637,29638,29639,29643,29644,29646,29650,29651,29652,29653,29654,29655, | ||
| 625 | 29656,29658,29659,29660,29661,29663,29665,29666,29667,29668,29670,29672,29674, | ||
| 626 | 29675,29676,29678,29679,29680,29681,29683,29684,29685,29686,29687,57438,57439, | ||
| 627 | 57440,57441,57442,57443,57444,57445,57446,57447,57448,57449,57450,57451,57452, | ||
| 628 | 57453,57454,57455,57456,57457,57458,57459,57460,57461,57462,57463,57464,57465, | ||
| 629 | 57466,57467,57468,57469,57470,57471,57472,57473,57474,57475,57476,57477,57478, | ||
| 630 | 57479,57480,57481,57482,57483,57484,57485,57486,57487,57488,57489,57490,57491, | ||
| 631 | 57492,57493,57494,57495,57496,57497,57498,57499,57500,57501,57502,57503,57504, | ||
| 632 | 57505,57506,57507,57508,57509,57510,57511,57512,57513,57514,57515,57516,57517, | ||
| 633 | 57518,57519,57520,57521,57522,57523,57524,57525,57526,57527,57528,57529,57530, | ||
| 634 | 57531,29688,29689,29690,29691,29692,29693,29694,29695,29696,29697,29698,29700, | ||
| 635 | 29703,29704,29707,29708,29709,29710,29713,29714,29715, | ||
| 636 | 29716,29717,29718,29719,29720,29721,29724,29725,29726,29727,29728,29729,29731, | ||
| 637 | 29732,29735,29737,29739,29741,29743,29745,29746,29751,29752,29753,29754,29755, | ||
| 638 | 29757,29758,29759,29760,29762,29763,29764,29765,29766,29767,29768,29769,29770, | ||
| 639 | 29771,29772,29773,29774,29775,29776,29777,29778,29779,29780,29782,29784,29789, | ||
| 640 | 29792,29793,29794,29795,29796,29797,29798,29799,29800,29801,29802,29803,29804, | ||
| 641 | 29806,29807,29809,29810,29811,29812,29813,29816,29817,29818,57532,57533,57534, | ||
| 642 | 57535,57536,57537,57538,57539,57540,57541,57542,57543,57544,57545,57546,57547, | ||
| 643 | 57548,57549,57550,57551,57552,57553,57554,57555,57556,57557,57558,57559,57560, | ||
| 644 | 57561,57562,57563,57564,57565,57566,57567,57568,57569,57570,57571,57572,57573, | ||
| 645 | 57574,57575,57576,57577,57578,57579,57580,57581,57582,57583,57584,57585,57586, | ||
| 646 | 57587,57588,57589,57590,57591,57592,57593,57594,57595,57596,57597,57598,57599, | ||
| 647 | 57600,57601,57602,57603,57604,57605,57606,57607,57608,57609,57610,57611,57612, | ||
| 648 | 57613,57614,57615,57616,57617,57618,57619,57620,57621,57622,57623,57624,57625, | ||
| 649 | 29819,29820,29821,29823,29826,29828,29829,29830,29832,29833,29834,29836,29837, | ||
| 650 | 29839,29841,29842,29843,29844,29845,29846,29847,29848,29849,29850,29851,29853, | ||
| 651 | 29855,29856,29857,29858,29859,29860,29861,29862,29866,29867,29868,29869,29870, | ||
| 652 | 29871,29872,29873,29874,29875,29876,29877,29878,29879,29880,29881,29883,29884, | ||
| 653 | 29885,29886,29887,29888,29889,29890,29891,29892,29893,29894,29895,29896,29897, | ||
| 654 | 29898,29899,29900,29901,29902,29903,29904,29905,29907,29908,29909,29910,29911, | ||
| 655 | 29912,29913,29914,29915,29917,29919,29921,29925,29927, | ||
| 656 | 29928,29929,29930,29931,29932,29933,29936,29937,29938,57626,57627,57628,57629, | ||
| 657 | 57630,57631,57632,57633,57634,57635,57636,57637,57638,57639,57640,57641,57642, | ||
| 658 | 57643,57644,57645,57646,57647,57648,57649,57650,57651,57652,57653,57654,57655, | ||
| 659 | 57656,57657,57658,57659,57660,57661,57662,57663,57664,57665,57666,57667,57668, | ||
| 660 | 57669,57670,57671,57672,57673,57674,57675,57676,57677,57678,57679,57680,57681, | ||
| 661 | 57682,57683,57684,57685,57686,57687,57688,57689,57690,57691,57692,57693,57694, | ||
| 662 | 57695,57696,57697,57698,57699,57700,57701,57702,57703,57704,57705,57706,57707, | ||
| 663 | 57708,57709,57710,57711,57712,57713,57714,57715,57716,57717,57718,57719,29939, | ||
| 664 | 29941,29944,29945,29946,29947,29948,29949,29950,29952,29953,29954,29955,29957, | ||
| 665 | 29958,29959,29960,29961,29962,29963,29964,29966,29968,29970,29972,29973,29974, | ||
| 666 | 29975,29979,29981,29982,29984,29985,29986,29987,29988,29990,29991,29994,29998, | ||
| 667 | 30004,30006,30009,30012,30013,30015,30017,30018,30019,30020,30022,30023,30025, | ||
| 668 | 30026,30029,30032,30033,30034,30035,30037,30038,30039,30040,30045,30046,30047, | ||
| 669 | 30048,30049,30050,30051,30052,30055,30056,30057,30059,30060,30061,30062,30063, | ||
| 670 | 30064,30065,30067,30069,30070,30071,30074,30075,30076,30077,30078,30080,30081, | ||
| 671 | 30082,30084,30085,30087,57720,57721,57722,57723,57724,57725,57726,57727,57728, | ||
| 672 | 57729,57730,57731,57732,57733,57734,57735,57736,57737,57738,57739,57740,57741, | ||
| 673 | 57742,57743,57744,57745,57746,57747,57748,57749,57750,57751,57752,57753,57754, | ||
| 674 | 57755,57756,57757,57758,57759,57760,57761,57762,57763,57764,57765,57766,57767, | ||
| 675 | 57768,57769,57770,57771,57772,57773,57774,57775,57776, | ||
| 676 | 57777,57778,57779,57780,57781,57782,57783,57784,57785,57786,57787,57788,57789, | ||
| 677 | 57790,57791,57792,57793,57794,57795,57796,57797,57798,57799,57800,57801,57802, | ||
| 678 | 57803,57804,57805,57806,57807,57808,57809,57810,57811,57812,57813,30088,30089, | ||
| 679 | 30090,30092,30093,30094,30096,30099,30101,30104,30107,30108,30110,30114,30118, | ||
| 680 | 30119,30120,30121,30122,30125,30134,30135,30138,30139,30143,30144,30145,30150, | ||
| 681 | 30155,30156,30158,30159,30160,30161,30163,30167,30169,30170,30172,30173,30175, | ||
| 682 | 30176,30177,30181,30185,30188,30189,30190,30191,30194,30195,30197,30198,30199, | ||
| 683 | 30200,30202,30203,30205,30206,30210,30212,30214,30215,30216,30217,30219,30221, | ||
| 684 | 30222,30223,30225,30226,30227,30228,30230,30234,30236,30237,30238,30241,30243, | ||
| 685 | 30247,30248,30252,30254,30255,30257,30258,30262,30263,30265,30266,30267,30269, | ||
| 686 | 30273,30274,30276,57814,57815,57816,57817,57818,57819,57820,57821,57822,57823, | ||
| 687 | 57824,57825,57826,57827,57828,57829,57830,57831,57832,57833,57834,57835,57836, | ||
| 688 | 57837,57838,57839,57840,57841,57842,57843,57844,57845,57846,57847,57848,57849, | ||
| 689 | 57850,57851,57852,57853,57854,57855,57856,57857,57858,57859,57860,57861,57862, | ||
| 690 | 57863,57864,57865,57866,57867,57868,57869,57870,57871,57872,57873,57874,57875, | ||
| 691 | 57876,57877,57878,57879,57880,57881,57882,57883,57884,57885,57886,57887,57888, | ||
| 692 | 57889,57890,57891,57892,57893,57894,57895,57896,57897,57898,57899,57900,57901, | ||
| 693 | 57902,57903,57904,57905,57906,57907,30277,30278,30279,30280,30281,30282,30283, | ||
| 694 | 30286,30287,30288,30289,30290,30291,30293,30295,30296,30297,30298,30299,30301, | ||
| 695 | 30303,30304,30305,30306,30308,30309,30310,30311,30312, | ||
| 696 | 30313,30314,30316,30317,30318,30320,30321,30322,30323,30324,30325,30326,30327, | ||
| 697 | 30329,30330,30332,30335,30336,30337,30339,30341,30345,30346,30348,30349,30351, | ||
| 698 | 30352,30354,30356,30357,30359,30360,30362,30363,30364,30365,30366,30367,30368, | ||
| 699 | 30369,30370,30371,30373,30374,30375,30376,30377,30378,30379,30380,30381,30383, | ||
| 700 | 30384,30387,30389,30390,30391,30392,30393,30394,30395,30396,30397,30398,30400, | ||
| 701 | 30401,30403,21834,38463,22467,25384,21710,21769,21696,30353,30284,34108,30702, | ||
| 702 | 33406,30861,29233,38552,38797,27688,23433,20474,25353,26263,23736,33018,26696, | ||
| 703 | 32942,26114,30414,20985,25942,29100,32753,34948,20658,22885,25034,28595,33453, | ||
| 704 | 25420,25170,21485,21543,31494,20843,30116,24052,25300,36299,38774,25226,32793, | ||
| 705 | 22365,38712,32610,29240,30333,26575,30334,25670,20336,36133,25308,31255,26001, | ||
| 706 | 29677,25644,25203,33324,39041,26495,29256,25198,25292,20276,29923,21322,21150, | ||
| 707 | 32458,37030,24110,26758,27036,33152,32465,26834,30917,34444,38225,20621,35876, | ||
| 708 | 33502,32990,21253,35090,21093,30404,30407,30409,30411,30412,30419,30421,30425, | ||
| 709 | 30426,30428,30429,30430,30432,30433,30434,30435,30436,30438,30439,30440,30441, | ||
| 710 | 30442,30443,30444,30445,30448,30451,30453,30454,30455,30458,30459,30461,30463, | ||
| 711 | 30464,30466,30467,30469,30470,30474,30476,30478,30479,30480,30481,30482,30483, | ||
| 712 | 30484,30485,30486,30487,30488,30491,30492,30493,30494,30497,30499,30500,30501, | ||
| 713 | 30503,30506,30507,30508,30510,30512,30513,30514,30515,30516,30521,30523,30525, | ||
| 714 | 30526,30527,30530,30532,30533,30534,30536,30537,30538,30539,30540,30541,30542, | ||
| 715 | 30543,30546,30547,30548,30549,30550,30551,30552,30553, | ||
| 716 | 30556,34180,38649,20445,22561,39281,23453,25265,25253,26292,35961,40077,29190, | ||
| 717 | 26479,30865,24754,21329,21271,36744,32972,36125,38049,20493,29384,22791,24811, | ||
| 718 | 28953,34987,22868,33519,26412,31528,23849,32503,29997,27893,36454,36856,36924, | ||
| 719 | 40763,27604,37145,31508,24444,30887,34006,34109,27605,27609,27606,24065,24199, | ||
| 720 | 30201,38381,25949,24330,24517,36767,22721,33218,36991,38491,38829,36793,32534, | ||
| 721 | 36140,25153,20415,21464,21342,36776,36777,36779,36941,26631,24426,33176,34920, | ||
| 722 | 40150,24971,21035,30250,24428,25996,28626,28392,23486,25672,20853,20912,26564, | ||
| 723 | 19993,31177,39292,28851,30557,30558,30559,30560,30564,30567,30569,30570,30573, | ||
| 724 | 30574,30575,30576,30577,30578,30579,30580,30581,30582,30583,30584,30586,30587, | ||
| 725 | 30588,30593,30594,30595,30598,30599,30600,30601,30602,30603,30607,30608,30611, | ||
| 726 | 30612,30613,30614,30615,30616,30617,30618,30619,30620,30621,30622,30625,30627, | ||
| 727 | 30628,30630,30632,30635,30637,30638,30639,30641,30642,30644,30646,30647,30648, | ||
| 728 | 30649,30650,30652,30654,30656,30657,30658,30659,30660,30661,30662,30663,30664, | ||
| 729 | 30665,30666,30667,30668,30670,30671,30672,30673,30674,30675,30676,30677,30678, | ||
| 730 | 30680,30681,30682,30685,30686,30687,30688,30689,30692,30149,24182,29627,33760, | ||
| 731 | 25773,25320,38069,27874,21338,21187,25615,38082,31636,20271,24091,33334,33046, | ||
| 732 | 33162,28196,27850,39539,25429,21340,21754,34917,22496,19981,24067,27493,31807, | ||
| 733 | 37096,24598,25830,29468,35009,26448,25165,36130,30572,36393,37319,24425,33756, | ||
| 734 | 34081,39184,21442,34453,27531,24813,24808,28799,33485,33329,20179,27815,34255, | ||
| 735 | 25805,31961,27133,26361,33609,21397,31574,20391,20876, | ||
| 736 | 27979,23618,36461,25554,21449,33580,33590,26597,30900,25661,23519,23700,24046, | ||
| 737 | 35815,25286,26612,35962,25600,25530,34633,39307,35863,32544,38130,20135,38416, | ||
| 738 | 39076,26124,29462,30694,30696,30698,30703,30704,30705,30706,30708,30709,30711, | ||
| 739 | 30713,30714,30715,30716,30723,30724,30725,30726,30727,30728,30730,30731,30734, | ||
| 740 | 30735,30736,30739,30741,30745,30747,30750,30752,30753,30754,30756,30760,30762, | ||
| 741 | 30763,30766,30767,30769,30770,30771,30773,30774,30781,30783,30785,30786,30787, | ||
| 742 | 30788,30790,30792,30793,30794,30795,30797,30799,30801,30803,30804,30808,30809, | ||
| 743 | 30810,30811,30812,30814,30815,30816,30817,30818,30819,30820,30821,30822,30823, | ||
| 744 | 30824,30825,30831,30832,30833,30834,30835,30836,30837,30838,30840,30841,30842, | ||
| 745 | 30843,30845,30846,30847,30848,30849,30850,30851,22330,23581,24120,38271,20607, | ||
| 746 | 32928,21378,25950,30021,21809,20513,36229,25220,38046,26397,22066,28526,24034, | ||
| 747 | 21557,28818,36710,25199,25764,25507,24443,28552,37108,33251,36784,23576,26216, | ||
| 748 | 24561,27785,38472,36225,34924,25745,31216,22478,27225,25104,21576,20056,31243, | ||
| 749 | 24809,28548,35802,25215,36894,39563,31204,21507,30196,25345,21273,27744,36831, | ||
| 750 | 24347,39536,32827,40831,20360,23610,36196,32709,26021,28861,20805,20914,34411, | ||
| 751 | 23815,23456,25277,37228,30068,36364,31264,24833,31609,20167,32504,30597,19985, | ||
| 752 | 33261,21021,20986,27249,21416,36487,38148,38607,28353,38500,26970,30852,30853, | ||
| 753 | 30854,30856,30858,30859,30863,30864,30866,30868,30869,30870,30873,30877,30878, | ||
| 754 | 30880,30882,30884,30886,30888,30889,30890,30891,30892,30893,30894,30895,30901, | ||
| 755 | 30902,30903,30904,30906,30907,30908,30909,30911,30912, | ||
| 756 | 30914,30915,30916,30918,30919,30920,30924,30925,30926,30927,30929,30930,30931, | ||
| 757 | 30934,30935,30936,30938,30939,30940,30941,30942,30943,30944,30945,30946,30947, | ||
| 758 | 30948,30949,30950,30951,30953,30954,30955,30957,30958,30959,30960,30961,30963, | ||
| 759 | 30965,30966,30968,30969,30971,30972,30973,30974,30975,30976,30978,30979,30980, | ||
| 760 | 30982,30983,30984,30985,30986,30987,30988,30784,20648,30679,25616,35302,22788, | ||
| 761 | 25571,24029,31359,26941,20256,33337,21912,20018,30126,31383,24162,24202,38383, | ||
| 762 | 21019,21561,28810,25462,38180,22402,26149,26943,37255,21767,28147,32431,34850, | ||
| 763 | 25139,32496,30133,33576,30913,38604,36766,24904,29943,35789,27492,21050,36176, | ||
| 764 | 27425,32874,33905,22257,21254,20174,19995,20945,31895,37259,31751,20419,36479, | ||
| 765 | 31713,31388,25703,23828,20652,33030,30209,31929,28140,32736,26449,23384,23544, | ||
| 766 | 30923,25774,25619,25514,25387,38169,25645,36798,31572,30249,25171,22823,21574, | ||
| 767 | 27513,20643,25140,24102,27526,20195,36151,34955,24453,36910,30989,30990,30991, | ||
| 768 | 30992,30993,30994,30996,30997,30998,30999,31000,31001,31002,31003,31004,31005, | ||
| 769 | 31007,31008,31009,31010,31011,31013,31014,31015,31016,31017,31018,31019,31020, | ||
| 770 | 31021,31022,31023,31024,31025,31026,31027,31029,31030,31031,31032,31033,31037, | ||
| 771 | 31039,31042,31043,31044,31045,31047,31050,31051,31052,31053,31054,31055,31056, | ||
| 772 | 31057,31058,31060,31061,31064,31065,31073,31075,31076,31078,31081,31082,31083, | ||
| 773 | 31084,31086,31088,31089,31090,31091,31092,31093,31094,31097,31099,31100,31101, | ||
| 774 | 31102,31103,31106,31107,31110,31111,31112,31113,31115,31116,31117,31118,31120, | ||
| 775 | 31121,31122,24608,32829,25285,20025,21333,37112,25528, | ||
| 776 | 32966,26086,27694,20294,24814,28129,35806,24377,34507,24403,25377,20826,33633, | ||
| 777 | 26723,20992,25443,36424,20498,23707,31095,23548,21040,31291,24764,36947,30423, | ||
| 778 | 24503,24471,30340,36460,28783,30331,31561,30634,20979,37011,22564,20302,28404, | ||
| 779 | 36842,25932,31515,29380,28068,32735,23265,25269,24213,22320,33922,31532,24093, | ||
| 780 | 24351,36882,32532,39072,25474,28359,30872,28857,20856,38747,22443,30005,20291, | ||
| 781 | 30008,24215,24806,22880,28096,27583,30857,21500,38613,20939,20993,25481,21514, | ||
| 782 | 38035,35843,36300,29241,30879,34678,36845,35853,21472,31123,31124,31125,31126, | ||
| 783 | 31127,31128,31129,31131,31132,31133,31134,31135,31136,31137,31138,31139,31140, | ||
| 784 | 31141,31142,31144,31145,31146,31147,31148,31149,31150,31151,31152,31153,31154, | ||
| 785 | 31156,31157,31158,31159,31160,31164,31167,31170,31172,31173,31175,31176,31178, | ||
| 786 | 31180,31182,31183,31184,31187,31188,31190,31191,31193,31194,31195,31196,31197, | ||
| 787 | 31198,31200,31201,31202,31205,31208,31210,31212,31214,31217,31218,31219,31220, | ||
| 788 | 31221,31222,31223,31225,31226,31228,31230,31231,31233,31236,31237,31239,31240, | ||
| 789 | 31241,31242,31244,31247,31248,31249,31250,31251,31253,31254,31256,31257,31259, | ||
| 790 | 31260,19969,30447,21486,38025,39030,40718,38189,23450,35746,20002,19996,20908, | ||
| 791 | 33891,25026,21160,26635,20375,24683,20923,27934,20828,25238,26007,38497,35910, | ||
| 792 | 36887,30168,37117,30563,27602,29322,29420,35835,22581,30585,36172,26460,38208, | ||
| 793 | 32922,24230,28193,22930,31471,30701,38203,27573,26029,32526,22534,20817,38431, | ||
| 794 | 23545,22697,21544,36466,25958,39039,22244,38045,30462,36929,25479,21702,22810, | ||
| 795 | 22842,22427,36530,26421,36346,33333,21057,24816,22549, | ||
| 796 | 34558,23784,40517,20420,39069,35769,23077,24694,21380,25212,36943,37122,39295, | ||
| 797 | 24681,32780,20799,32819,23572,39285,27953,20108,31261,31263,31265,31266,31268, | ||
| 798 | 31269,31270,31271,31272,31273,31274,31275,31276,31277,31278,31279,31280,31281, | ||
| 799 | 31282,31284,31285,31286,31288,31290,31294,31296,31297,31298,31299,31300,31301, | ||
| 800 | 31303,31304,31305,31306,31307,31308,31309,31310,31311,31312,31314,31315,31316, | ||
| 801 | 31317,31318,31320,31321,31322,31323,31324,31325,31326,31327,31328,31329,31330, | ||
| 802 | 31331,31332,31333,31334,31335,31336,31337,31338,31339,31340,31341,31342,31343, | ||
| 803 | 31345,31346,31347,31349,31355,31356,31357,31358,31362,31365,31367,31369,31370, | ||
| 804 | 31371,31372,31374,31375,31376,31379,31380,31385,31386,31387,31390,31393,31394, | ||
| 805 | 36144,21457,32602,31567,20240,20047,38400,27861,29648,34281,24070,30058,32763, | ||
| 806 | 27146,30718,38034,32321,20961,28902,21453,36820,33539,36137,29359,39277,27867, | ||
| 807 | 22346,33459,26041,32938,25151,38450,22952,20223,35775,32442,25918,33778,38750, | ||
| 808 | 21857,39134,32933,21290,35837,21536,32954,24223,27832,36153,33452,37210,21545, | ||
| 809 | 27675,20998,32439,22367,28954,27774,31881,22859,20221,24575,24868,31914,20016, | ||
| 810 | 23553,26539,34562,23792,38155,39118,30127,28925,36898,20911,32541,35773,22857, | ||
| 811 | 20964,20315,21542,22827,25975,32932,23413,25206,25282,36752,24133,27679,31526, | ||
| 812 | 20239,20440,26381,31395,31396,31399,31401,31402,31403,31406,31407,31408,31409, | ||
| 813 | 31410,31412,31413,31414,31415,31416,31417,31418,31419,31420,31421,31422,31424, | ||
| 814 | 31425,31426,31427,31428,31429,31430,31431,31432,31433,31434,31436,31437,31438, | ||
| 815 | 31439,31440,31441,31442,31443,31444,31445,31447,31448, | ||
| 816 | 31450,31451,31452,31453,31457,31458,31460,31463,31464,31465,31466,31467,31468, | ||
| 817 | 31470,31472,31473,31474,31475,31476,31477,31478,31479,31480,31483,31484,31486, | ||
| 818 | 31488,31489,31490,31493,31495,31497,31500,31501,31502,31504,31506,31507,31510, | ||
| 819 | 31511,31512,31514,31516,31517,31519,31521,31522,31523,31527,31529,31533,28014, | ||
| 820 | 28074,31119,34993,24343,29995,25242,36741,20463,37340,26023,33071,33105,24220, | ||
| 821 | 33104,36212,21103,35206,36171,22797,20613,20184,38428,29238,33145,36127,23500, | ||
| 822 | 35747,38468,22919,32538,21648,22134,22030,35813,25913,27010,38041,30422,28297, | ||
| 823 | 24178,29976,26438,26577,31487,32925,36214,24863,31174,25954,36195,20872,21018, | ||
| 824 | 38050,32568,32923,32434,23703,28207,26464,31705,30347,39640,33167,32660,31957, | ||
| 825 | 25630,38224,31295,21578,21733,27468,25601,25096,40509,33011,30105,21106,38761, | ||
| 826 | 33883,26684,34532,38401,38548,38124,20010,21508,32473,26681,36319,32789,26356, | ||
| 827 | 24218,32697,31535,31536,31538,31540,31541,31542,31543,31545,31547,31549,31551, | ||
| 828 | 31552,31553,31554,31555,31556,31558,31560,31562,31565,31566,31571,31573,31575, | ||
| 829 | 31577,31580,31582,31583,31585,31587,31588,31589,31590,31591,31592,31593,31594, | ||
| 830 | 31595,31596,31597,31599,31600,31603,31604,31606,31608,31610,31612,31613,31615, | ||
| 831 | 31617,31618,31619,31620,31622,31623,31624,31625,31626,31627,31628,31630,31631, | ||
| 832 | 31633,31634,31635,31638,31640,31641,31642,31643,31646,31647,31648,31651,31652, | ||
| 833 | 31653,31662,31663,31664,31666,31667,31669,31670,31671,31673,31674,31675,31676, | ||
| 834 | 31677,31678,31679,31680,31682,31683,31684,22466,32831,26775,24037,25915,21151, | ||
| 835 | 24685,40858,20379,36524,20844,23467,24339,24041,27742, | ||
| 836 | 25329,36129,20849,38057,21246,27807,33503,29399,22434,26500,36141,22815,36764, | ||
| 837 | 33735,21653,31629,20272,27837,23396,22993,40723,21476,34506,39592,35895,32929, | ||
| 838 | 25925,39038,22266,38599,21038,29916,21072,23521,25346,35074,20054,25296,24618, | ||
| 839 | 26874,20851,23448,20896,35266,31649,39302,32592,24815,28748,36143,20809,24191, | ||
| 840 | 36891,29808,35268,22317,30789,24402,40863,38394,36712,39740,35809,30328,26690, | ||
| 841 | 26588,36330,36149,21053,36746,28378,26829,38149,37101,22269,26524,35065,36807, | ||
| 842 | 21704,31685,31688,31689,31690,31691,31693,31694,31695,31696,31698,31700,31701, | ||
| 843 | 31702,31703,31704,31707,31708,31710,31711,31712,31714,31715,31716,31719,31720, | ||
| 844 | 31721,31723,31724,31725,31727,31728,31730,31731,31732,31733,31734,31736,31737, | ||
| 845 | 31738,31739,31741,31743,31744,31745,31746,31747,31748,31749,31750,31752,31753, | ||
| 846 | 31754,31757,31758,31760,31761,31762,31763,31764,31765,31767,31768,31769,31770, | ||
| 847 | 31771,31772,31773,31774,31776,31777,31778,31779,31780,31781,31784,31785,31787, | ||
| 848 | 31788,31789,31790,31791,31792,31793,31794,31795,31796,31797,31798,31799,31801, | ||
| 849 | 31802,31803,31804,31805,31806,31810,39608,23401,28023,27686,20133,23475,39559, | ||
| 850 | 37219,25000,37039,38889,21547,28085,23506,20989,21898,32597,32752,25788,25421, | ||
| 851 | 26097,25022,24717,28938,27735,27721,22831,26477,33322,22741,22158,35946,27627, | ||
| 852 | 37085,22909,32791,21495,28009,21621,21917,33655,33743,26680,31166,21644,20309, | ||
| 853 | 21512,30418,35977,38402,27827,28088,36203,35088,40548,36154,22079,40657,30165, | ||
| 854 | 24456,29408,24680,21756,20136,27178,34913,24658,36720,21700,28888,34425,40511, | ||
| 855 | 27946,23439,24344,32418,21897,20399,29492,21564,21402, | ||
| 856 | 20505,21518,21628,20046,24573,29786,22774,33899,32993,34676,29392,31946,28246, | ||
| 857 | 31811,31812,31813,31814,31815,31816,31817,31818,31819,31820,31822,31823,31824, | ||
| 858 | 31825,31826,31827,31828,31829,31830,31831,31832,31833,31834,31835,31836,31837, | ||
| 859 | 31838,31839,31840,31841,31842,31843,31844,31845,31846,31847,31848,31849,31850, | ||
| 860 | 31851,31852,31853,31854,31855,31856,31857,31858,31861,31862,31863,31864,31865, | ||
| 861 | 31866,31870,31871,31872,31873,31874,31875,31876,31877,31878,31879,31880,31882, | ||
| 862 | 31883,31884,31885,31886,31887,31888,31891,31892,31894,31897,31898,31899,31904, | ||
| 863 | 31905,31907,31910,31911,31912,31913,31915,31916,31917,31919,31920,31924,31925, | ||
| 864 | 31926,31927,31928,31930,31931,24359,34382,21804,25252,20114,27818,25143,33457, | ||
| 865 | 21719,21326,29502,28369,30011,21010,21270,35805,27088,24458,24576,28142,22351, | ||
| 866 | 27426,29615,26707,36824,32531,25442,24739,21796,30186,35938,28949,28067,23462, | ||
| 867 | 24187,33618,24908,40644,30970,34647,31783,30343,20976,24822,29004,26179,24140, | ||
| 868 | 24653,35854,28784,25381,36745,24509,24674,34516,22238,27585,24724,24935,21321, | ||
| 869 | 24800,26214,36159,31229,20250,28905,27719,35763,35826,32472,33636,26127,23130, | ||
| 870 | 39746,27985,28151,35905,27963,20249,28779,33719,25110,24785,38669,36135,31096, | ||
| 871 | 20987,22334,22522,26426,30072,31293,31215,31637,31935,31936,31938,31939,31940, | ||
| 872 | 31942,31945,31947,31950,31951,31952,31953,31954,31955,31956,31960,31962,31963, | ||
| 873 | 31965,31966,31969,31970,31971,31972,31973,31974,31975,31977,31978,31979,31980, | ||
| 874 | 31981,31982,31984,31985,31986,31987,31988,31989,31990,31991,31993,31994,31996, | ||
| 875 | 31997,31998,31999,32000,32001,32002,32003,32004,32005, | ||
| 876 | 32006,32007,32008,32009,32011,32012,32013,32014,32015,32016,32017,32018,32019, | ||
| 877 | 32020,32021,32022,32023,32024,32025,32026,32027,32028,32029,32030,32031,32033, | ||
| 878 | 32035,32036,32037,32038,32040,32041,32042,32044,32045,32046,32048,32049,32050, | ||
| 879 | 32051,32052,32053,32054,32908,39269,36857,28608,35749,40481,23020,32489,32521, | ||
| 880 | 21513,26497,26840,36753,31821,38598,21450,24613,30142,27762,21363,23241,32423, | ||
| 881 | 25380,20960,33034,24049,34015,25216,20864,23395,20238,31085,21058,24760,27982, | ||
| 882 | 23492,23490,35745,35760,26082,24524,38469,22931,32487,32426,22025,26551,22841, | ||
| 883 | 20339,23478,21152,33626,39050,36158,30002,38078,20551,31292,20215,26550,39550, | ||
| 884 | 23233,27516,30417,22362,23574,31546,38388,29006,20860,32937,33392,22904,32516, | ||
| 885 | 33575,26816,26604,30897,30839,25315,25441,31616,20461,21098,20943,33616,27099, | ||
| 886 | 37492,36341,36145,35265,38190,31661,20214,32055,32056,32057,32058,32059,32060, | ||
| 887 | 32061,32062,32063,32064,32065,32066,32067,32068,32069,32070,32071,32072,32073, | ||
| 888 | 32074,32075,32076,32077,32078,32079,32080,32081,32082,32083,32084,32085,32086, | ||
| 889 | 32087,32088,32089,32090,32091,32092,32093,32094,32095,32096,32097,32098,32099, | ||
| 890 | 32100,32101,32102,32103,32104,32105,32106,32107,32108,32109,32111,32112,32113, | ||
| 891 | 32114,32115,32116,32117,32118,32120,32121,32122,32123,32124,32125,32126,32127, | ||
| 892 | 32128,32129,32130,32131,32132,32133,32134,32135,32136,32137,32138,32139,32140, | ||
| 893 | 32141,32142,32143,32144,32145,32146,32147,32148,32149,32150,32151,32152,20581, | ||
| 894 | 33328,21073,39279,28176,28293,28071,24314,20725,23004,23558,27974,27743,30086, | ||
| 895 | 33931,26728,22870,35762,21280,37233,38477,34121,26898, | ||
| 896 | 30977,28966,33014,20132,37066,27975,39556,23047,22204,25605,38128,30699,20389, | ||
| 897 | 33050,29409,35282,39290,32564,32478,21119,25945,37237,36735,36739,21483,31382, | ||
| 898 | 25581,25509,30342,31224,34903,38454,25130,21163,33410,26708,26480,25463,30571, | ||
| 899 | 31469,27905,32467,35299,22992,25106,34249,33445,30028,20511,20171,30117,35819, | ||
| 900 | 23626,24062,31563,26020,37329,20170,27941,35167,32039,38182,20165,35880,36827, | ||
| 901 | 38771,26187,31105,36817,28908,28024,32153,32154,32155,32156,32157,32158,32159, | ||
| 902 | 32160,32161,32162,32163,32164,32165,32167,32168,32169,32170,32171,32172,32173, | ||
| 903 | 32175,32176,32177,32178,32179,32180,32181,32182,32183,32184,32185,32186,32187, | ||
| 904 | 32188,32189,32190,32191,32192,32193,32194,32195,32196,32197,32198,32199,32200, | ||
| 905 | 32201,32202,32203,32204,32205,32206,32207,32208,32209,32210,32211,32212,32213, | ||
| 906 | 32214,32215,32216,32217,32218,32219,32220,32221,32222,32223,32224,32225,32226, | ||
| 907 | 32227,32228,32229,32230,32231,32232,32233,32234,32235,32236,32237,32238,32239, | ||
| 908 | 32240,32241,32242,32243,32244,32245,32246,32247,32248,32249,32250,23613,21170, | ||
| 909 | 33606,20834,33550,30555,26230,40120,20140,24778,31934,31923,32463,20117,35686, | ||
| 910 | 26223,39048,38745,22659,25964,38236,24452,30153,38742,31455,31454,20928,28847, | ||
| 911 | 31384,25578,31350,32416,29590,38893,20037,28792,20061,37202,21417,25937,26087, | ||
| 912 | 33276,33285,21646,23601,30106,38816,25304,29401,30141,23621,39545,33738,23616, | ||
| 913 | 21632,30697,20030,27822,32858,25298,25454,24040,20855,36317,36382,38191,20465, | ||
| 914 | 21477,24807,28844,21095,25424,40515,23071,20518,30519,21367,32482,25733,25899, | ||
| 915 | 25225,25496,20500,29237,35273,20915,35776,32477,22343, | ||
| 916 | 33740,38055,20891,21531,23803,32251,32252,32253,32254,32255,32256,32257,32258, | ||
| 917 | 32259,32260,32261,32262,32263,32264,32265,32266,32267,32268,32269,32270,32271, | ||
| 918 | 32272,32273,32274,32275,32276,32277,32278,32279,32280,32281,32282,32283,32284, | ||
| 919 | 32285,32286,32287,32288,32289,32290,32291,32292,32293,32294,32295,32296,32297, | ||
| 920 | 32298,32299,32300,32301,32302,32303,32304,32305,32306,32307,32308,32309,32310, | ||
| 921 | 32311,32312,32313,32314,32316,32317,32318,32319,32320,32322,32323,32324,32325, | ||
| 922 | 32326,32328,32329,32330,32331,32332,32333,32334,32335,32336,32337,32338,32339, | ||
| 923 | 32340,32341,32342,32343,32344,32345,32346,32347,32348,32349,20426,31459,27994, | ||
| 924 | 37089,39567,21888,21654,21345,21679,24320,25577,26999,20975,24936,21002,22570, | ||
| 925 | 21208,22350,30733,30475,24247,24951,31968,25179,25239,20130,28821,32771,25335, | ||
| 926 | 28900,38752,22391,33499,26607,26869,30933,39063,31185,22771,21683,21487,28212, | ||
| 927 | 20811,21051,23458,35838,32943,21827,22438,24691,22353,21549,31354,24656,23380, | ||
| 928 | 25511,25248,21475,25187,23495,26543,21741,31391,33510,37239,24211,35044,22840, | ||
| 929 | 22446,25358,36328,33007,22359,31607,20393,24555,23485,27454,21281,31568,29378, | ||
| 930 | 26694,30719,30518,26103,20917,20111,30420,23743,31397,33909,22862,39745,20608, | ||
| 931 | 32350,32351,32352,32353,32354,32355,32356,32357,32358,32359,32360,32361,32362, | ||
| 932 | 32363,32364,32365,32366,32367,32368,32369,32370,32371,32372,32373,32374,32375, | ||
| 933 | 32376,32377,32378,32379,32380,32381,32382,32383,32384,32385,32387,32388,32389, | ||
| 934 | 32390,32391,32392,32393,32394,32395,32396,32397,32398,32399,32400,32401,32402, | ||
| 935 | 32403,32404,32405,32406,32407,32408,32409,32410,32412, | ||
| 936 | 32413,32414,32430,32436,32443,32444,32470,32484,32492,32505,32522,32528,32542, | ||
| 937 | 32567,32569,32571,32572,32573,32574,32575,32576,32577,32579,32582,32583,32584, | ||
| 938 | 32585,32586,32587,32588,32589,32590,32591,32594,32595,39304,24871,28291,22372, | ||
| 939 | 26118,25414,22256,25324,25193,24275,38420,22403,25289,21895,34593,33098,36771, | ||
| 940 | 21862,33713,26469,36182,34013,23146,26639,25318,31726,38417,20848,28572,35888, | ||
| 941 | 25597,35272,25042,32518,28866,28389,29701,27028,29436,24266,37070,26391,28010, | ||
| 942 | 25438,21171,29282,32769,20332,23013,37226,28889,28061,21202,20048,38647,38253, | ||
| 943 | 34174,30922,32047,20769,22418,25794,32907,31867,27882,26865,26974,20919,21400, | ||
| 944 | 26792,29313,40654,31729,29432,31163,28435,29702,26446,37324,40100,31036,33673, | ||
| 945 | 33620,21519,26647,20029,21385,21169,30782,21382,21033,20616,20363,20432,32598, | ||
| 946 | 32601,32603,32604,32605,32606,32608,32611,32612,32613,32614,32615,32619,32620, | ||
| 947 | 32621,32623,32624,32627,32629,32630,32631,32632,32634,32635,32636,32637,32639, | ||
| 948 | 32640,32642,32643,32644,32645,32646,32647,32648,32649,32651,32653,32655,32656, | ||
| 949 | 32657,32658,32659,32661,32662,32663,32664,32665,32667,32668,32672,32674,32675, | ||
| 950 | 32677,32678,32680,32681,32682,32683,32684,32685,32686,32689,32691,32692,32693, | ||
| 951 | 32694,32695,32698,32699,32702,32704,32706,32707,32708,32710,32711,32712,32713, | ||
| 952 | 32715,32717,32719,32720,32721,32722,32723,32726,32727,32729,32730,32731,32732, | ||
| 953 | 32733,32734,32738,32739,30178,31435,31890,27813,38582,21147,29827,21737,20457, | ||
| 954 | 32852,33714,36830,38256,24265,24604,28063,24088,25947,33080,38142,24651,28860, | ||
| 955 | 32451,31918,20937,26753,31921,33391,20004,36742,37327, | ||
| 956 | 26238,20142,35845,25769,32842,20698,30103,29134,23525,36797,28518,20102,25730, | ||
| 957 | 38243,24278,26009,21015,35010,28872,21155,29454,29747,26519,30967,38678,20020, | ||
| 958 | 37051,40158,28107,20955,36161,21533,25294,29618,33777,38646,40836,38083,20278, | ||
| 959 | 32666,20940,28789,38517,23725,39046,21478,20196,28316,29705,27060,30827,39311, | ||
| 960 | 30041,21016,30244,27969,26611,20845,40857,32843,21657,31548,31423,32740,32743, | ||
| 961 | 32744,32746,32747,32748,32749,32751,32754,32756,32757,32758,32759,32760,32761, | ||
| 962 | 32762,32765,32766,32767,32770,32775,32776,32777,32778,32782,32783,32785,32787, | ||
| 963 | 32794,32795,32797,32798,32799,32801,32803,32804,32811,32812,32813,32814,32815, | ||
| 964 | 32816,32818,32820,32825,32826,32828,32830,32832,32833,32836,32837,32839,32840, | ||
| 965 | 32841,32846,32847,32848,32849,32851,32853,32854,32855,32857,32859,32860,32861, | ||
| 966 | 32862,32863,32864,32865,32866,32867,32868,32869,32870,32871,32872,32875,32876, | ||
| 967 | 32877,32878,32879,32880,32882,32883,32884,32885,32886,32887,32888,32889,32890, | ||
| 968 | 32891,32892,32893,38534,22404,25314,38471,27004,23044,25602,31699,28431,38475, | ||
| 969 | 33446,21346,39045,24208,28809,25523,21348,34383,40065,40595,30860,38706,36335, | ||
| 970 | 36162,40575,28510,31108,24405,38470,25134,39540,21525,38109,20387,26053,23653, | ||
| 971 | 23649,32533,34385,27695,24459,29575,28388,32511,23782,25371,23402,28390,21365, | ||
| 972 | 20081,25504,30053,25249,36718,20262,20177,27814,32438,35770,33821,34746,32599, | ||
| 973 | 36923,38179,31657,39585,35064,33853,27931,39558,32476,22920,40635,29595,30721, | ||
| 974 | 34434,39532,39554,22043,21527,22475,20080,40614,21334,36808,33033,30610,39314, | ||
| 975 | 34542,28385,34067,26364,24930,28459,32894,32897,32898, | ||
| 976 | 32901,32904,32906,32909,32910,32911,32912,32913,32914,32916,32917,32919,32921, | ||
| 977 | 32926,32931,32934,32935,32936,32940,32944,32947,32949,32950,32952,32953,32955, | ||
| 978 | 32965,32967,32968,32969,32970,32971,32975,32976,32977,32978,32979,32980,32981, | ||
| 979 | 32984,32991,32992,32994,32995,32998,33006,33013,33015,33017,33019,33022,33023, | ||
| 980 | 33024,33025,33027,33028,33029,33031,33032,33035,33036,33045,33047,33049,33051, | ||
| 981 | 33052,33053,33055,33056,33057,33058,33059,33060,33061,33062,33063,33064,33065, | ||
| 982 | 33066,33067,33069,33070,33072,33075,33076,33077,33079,33081,33082,33083,33084, | ||
| 983 | 33085,33087,35881,33426,33579,30450,27667,24537,33725,29483,33541,38170,27611, | ||
| 984 | 30683,38086,21359,33538,20882,24125,35980,36152,20040,29611,26522,26757,37238, | ||
| 985 | 38665,29028,27809,30473,23186,38209,27599,32654,26151,23504,22969,23194,38376, | ||
| 986 | 38391,20204,33804,33945,27308,30431,38192,29467,26790,23391,30511,37274,38753, | ||
| 987 | 31964,36855,35868,24357,31859,31192,35269,27852,34588,23494,24130,26825,30496, | ||
| 988 | 32501,20885,20813,21193,23081,32517,38754,33495,25551,30596,34256,31186,28218, | ||
| 989 | 24217,22937,34065,28781,27665,25279,30399,25935,24751,38397,26126,34719,40483, | ||
| 990 | 38125,21517,21629,35884,25720,33088,33089,33090,33091,33092,33093,33095,33097, | ||
| 991 | 33101,33102,33103,33106,33110,33111,33112,33115,33116,33117,33118,33119,33121, | ||
| 992 | 33122,33123,33124,33126,33128,33130,33131,33132,33135,33138,33139,33141,33142, | ||
| 993 | 33143,33144,33153,33155,33156,33157,33158,33159,33161,33163,33164,33165,33166, | ||
| 994 | 33168,33170,33171,33172,33173,33174,33175,33177,33178,33182,33183,33184,33185, | ||
| 995 | 33186,33188,33189,33191,33193,33195,33196,33197,33198, | ||
| 996 | 33199,33200,33201,33202,33204,33205,33206,33207,33208,33209,33212,33213,33214, | ||
| 997 | 33215,33220,33221,33223,33224,33225,33227,33229,33230,33231,33232,33233,33234, | ||
| 998 | 33235,25721,34321,27169,33180,30952,25705,39764,25273,26411,33707,22696,40664, | ||
| 999 | 27819,28448,23518,38476,35851,29279,26576,25287,29281,20137,22982,27597,22675, | ||
| 1000 | 26286,24149,21215,24917,26408,30446,30566,29287,31302,25343,21738,21584,38048, | ||
| 1001 | 37027,23068,32435,27670,20035,22902,32784,22856,21335,30007,38590,22218,25376, | ||
| 1002 | 33041,24700,38393,28118,21602,39297,20869,23273,33021,22958,38675,20522,27877, | ||
| 1003 | 23612,25311,20320,21311,33147,36870,28346,34091,25288,24180,30910,25781,25467, | ||
| 1004 | 24565,23064,37247,40479,23615,25423,32834,23421,21870,38218,38221,28037,24744, | ||
| 1005 | 26592,29406,20957,23425,33236,33237,33238,33239,33240,33241,33242,33243,33244, | ||
| 1006 | 33245,33246,33247,33248,33249,33250,33252,33253,33254,33256,33257,33259,33262, | ||
| 1007 | 33263,33264,33265,33266,33269,33270,33271,33272,33273,33274,33277,33279,33283, | ||
| 1008 | 33287,33288,33289,33290,33291,33294,33295,33297,33299,33301,33302,33303,33304, | ||
| 1009 | 33305,33306,33309,33312,33316,33317,33318,33319,33321,33326,33330,33338,33340, | ||
| 1010 | 33341,33343,33344,33345,33346,33347,33349,33350,33352,33354,33356,33357,33358, | ||
| 1011 | 33360,33361,33362,33363,33364,33365,33366,33367,33369,33371,33372,33373,33374, | ||
| 1012 | 33376,33377,33378,33379,33380,33381,33382,33383,33385,25319,27870,29275,25197, | ||
| 1013 | 38062,32445,33043,27987,20892,24324,22900,21162,24594,22899,26262,34384,30111, | ||
| 1014 | 25386,25062,31983,35834,21734,27431,40485,27572,34261,21589,20598,27812,21866, | ||
| 1015 | 36276,29228,24085,24597,29750,25293,25490,29260,24472, | ||
| 1016 | 28227,27966,25856,28504,30424,30928,30460,30036,21028,21467,20051,24222,26049, | ||
| 1017 | 32810,32982,25243,21638,21032,28846,34957,36305,27873,21624,32986,22521,35060, | ||
| 1018 | 36180,38506,37197,20329,27803,21943,30406,30768,25256,28921,28558,24429,34028, | ||
| 1019 | 26842,30844,31735,33192,26379,40527,25447,30896,22383,30738,38713,25209,25259, | ||
| 1020 | 21128,29749,27607,33386,33387,33388,33389,33393,33397,33398,33399,33400,33403, | ||
| 1021 | 33404,33408,33409,33411,33413,33414,33415,33417,33420,33424,33427,33428,33429, | ||
| 1022 | 33430,33434,33435,33438,33440,33442,33443,33447,33458,33461,33462,33466,33467, | ||
| 1023 | 33468,33471,33472,33474,33475,33477,33478,33481,33488,33494,33497,33498,33501, | ||
| 1024 | 33506,33511,33512,33513,33514,33516,33517,33518,33520,33522,33523,33525,33526, | ||
| 1025 | 33528,33530,33532,33533,33534,33535,33536,33546,33547,33549,33552,33554,33555, | ||
| 1026 | 33558,33560,33561,33565,33566,33567,33568,33569,33570,33571,33572,33573,33574, | ||
| 1027 | 33577,33578,33582,33584,33586,33591,33595,33597,21860,33086,30130,30382,21305, | ||
| 1028 | 30174,20731,23617,35692,31687,20559,29255,39575,39128,28418,29922,31080,25735, | ||
| 1029 | 30629,25340,39057,36139,21697,32856,20050,22378,33529,33805,24179,20973,29942, | ||
| 1030 | 35780,23631,22369,27900,39047,23110,30772,39748,36843,31893,21078,25169,38138, | ||
| 1031 | 20166,33670,33889,33769,33970,22484,26420,22275,26222,28006,35889,26333,28689, | ||
| 1032 | 26399,27450,26646,25114,22971,19971,20932,28422,26578,27791,20854,26827,22855, | ||
| 1033 | 27495,30054,23822,33040,40784,26071,31048,31041,39569,36215,23682,20062,20225, | ||
| 1034 | 21551,22865,30732,22120,27668,36804,24323,27773,27875,35755,25488,33598,33599, | ||
| 1035 | 33601,33602,33604,33605,33608,33610,33611,33612,33613, | ||
| 1036 | 33614,33619,33621,33622,33623,33624,33625,33629,33634,33648,33649,33650,33651, | ||
| 1037 | 33652,33653,33654,33657,33658,33662,33663,33664,33665,33666,33667,33668,33671, | ||
| 1038 | 33672,33674,33675,33676,33677,33679,33680,33681,33684,33685,33686,33687,33689, | ||
| 1039 | 33690,33693,33695,33697,33698,33699,33700,33701,33702,33703,33708,33709,33710, | ||
| 1040 | 33711,33717,33723,33726,33727,33730,33731,33732,33734,33736,33737,33739,33741, | ||
| 1041 | 33742,33744,33745,33746,33747,33749,33751,33753,33754,33755,33758,33762,33763, | ||
| 1042 | 33764,33766,33767,33768,33771,33772,33773,24688,27965,29301,25190,38030,38085, | ||
| 1043 | 21315,36801,31614,20191,35878,20094,40660,38065,38067,21069,28508,36963,27973, | ||
| 1044 | 35892,22545,23884,27424,27465,26538,21595,33108,32652,22681,34103,24378,25250, | ||
| 1045 | 27207,38201,25970,24708,26725,30631,20052,20392,24039,38808,25772,32728,23789, | ||
| 1046 | 20431,31373,20999,33540,19988,24623,31363,38054,20405,20146,31206,29748,21220, | ||
| 1047 | 33465,25810,31165,23517,27777,38738,36731,27682,20542,21375,28165,25806,26228, | ||
| 1048 | 27696,24773,39031,35831,24198,29756,31351,31179,19992,37041,29699,27714,22234, | ||
| 1049 | 37195,27845,36235,21306,34502,26354,36527,23624,39537,28192,33774,33775,33779, | ||
| 1050 | 33780,33781,33782,33783,33786,33787,33788,33790,33791,33792,33794,33797,33799, | ||
| 1051 | 33800,33801,33802,33808,33810,33811,33812,33813,33814,33815,33817,33818,33819, | ||
| 1052 | 33822,33823,33824,33825,33826,33827,33833,33834,33835,33836,33837,33838,33839, | ||
| 1053 | 33840,33842,33843,33844,33845,33846,33847,33849,33850,33851,33854,33855,33856, | ||
| 1054 | 33857,33858,33859,33860,33861,33863,33864,33865,33866,33867,33868,33869,33870, | ||
| 1055 | 33871,33872,33874,33875,33876,33877,33878,33880,33885, | ||
| 1056 | 33886,33887,33888,33890,33892,33893,33894,33895,33896,33898,33902,33903,33904, | ||
| 1057 | 33906,33908,33911,33913,33915,33916,21462,23094,40843,36259,21435,22280,39079, | ||
| 1058 | 26435,37275,27849,20840,30154,25331,29356,21048,21149,32570,28820,30264,21364, | ||
| 1059 | 40522,27063,30830,38592,35033,32676,28982,29123,20873,26579,29924,22756,25880, | ||
| 1060 | 22199,35753,39286,25200,32469,24825,28909,22764,20161,20154,24525,38887,20219, | ||
| 1061 | 35748,20995,22922,32427,25172,20173,26085,25102,33592,33993,33635,34701,29076, | ||
| 1062 | 28342,23481,32466,20887,25545,26580,32905,33593,34837,20754,23418,22914,36785, | ||
| 1063 | 20083,27741,20837,35109,36719,38446,34122,29790,38160,38384,28070,33509,24369, | ||
| 1064 | 25746,27922,33832,33134,40131,22622,36187,19977,21441,33917,33918,33919,33920, | ||
| 1065 | 33921,33923,33924,33925,33926,33930,33933,33935,33936,33937,33938,33939,33940, | ||
| 1066 | 33941,33942,33944,33946,33947,33949,33950,33951,33952,33954,33955,33956,33957, | ||
| 1067 | 33958,33959,33960,33961,33962,33963,33964,33965,33966,33968,33969,33971,33973, | ||
| 1068 | 33974,33975,33979,33980,33982,33984,33986,33987,33989,33990,33991,33992,33995, | ||
| 1069 | 33996,33998,33999,34002,34004,34005,34007,34008,34009,34010,34011,34012,34014, | ||
| 1070 | 34017,34018,34020,34023,34024,34025,34026,34027,34029,34030,34031,34033,34034, | ||
| 1071 | 34035,34036,34037,34038,34039,34040,34041,34042,34043,34045,34046,34048,34049, | ||
| 1072 | 34050,20254,25955,26705,21971,20007,25620,39578,25195,23234,29791,33394,28073, | ||
| 1073 | 26862,20711,33678,30722,26432,21049,27801,32433,20667,21861,29022,31579,26194, | ||
| 1074 | 29642,33515,26441,23665,21024,29053,34923,38378,38485,25797,36193,33203,21892, | ||
| 1075 | 27733,25159,32558,22674,20260,21830,36175,26188,19978, | ||
| 1076 | 23578,35059,26786,25422,31245,28903,33421,21242,38902,23569,21736,37045,32461, | ||
| 1077 | 22882,36170,34503,33292,33293,36198,25668,23556,24913,28041,31038,35774,30775, | ||
| 1078 | 30003,21627,20280,36523,28145,23072,32453,31070,27784,23457,23158,29978,32958, | ||
| 1079 | 24910,28183,22768,29983,29989,29298,21319,32499,34051,34052,34053,34054,34055, | ||
| 1080 | 34056,34057,34058,34059,34061,34062,34063,34064,34066,34068,34069,34070,34072, | ||
| 1081 | 34073,34075,34076,34077,34078,34080,34082,34083,34084,34085,34086,34087,34088, | ||
| 1082 | 34089,34090,34093,34094,34095,34096,34097,34098,34099,34100,34101,34102,34110, | ||
| 1083 | 34111,34112,34113,34114,34116,34117,34118,34119,34123,34124,34125,34126,34127, | ||
| 1084 | 34128,34129,34130,34131,34132,34133,34135,34136,34138,34139,34140,34141,34143, | ||
| 1085 | 34144,34145,34146,34147,34149,34150,34151,34153,34154,34155,34156,34157,34158, | ||
| 1086 | 34159,34160,34161,34163,34165,34166,34167,34168,34172,34173,34175,34176,34177, | ||
| 1087 | 30465,30427,21097,32988,22307,24072,22833,29422,26045,28287,35799,23608,34417, | ||
| 1088 | 21313,30707,25342,26102,20160,39135,34432,23454,35782,21490,30690,20351,23630, | ||
| 1089 | 39542,22987,24335,31034,22763,19990,26623,20107,25325,35475,36893,21183,26159, | ||
| 1090 | 21980,22124,36866,20181,20365,37322,39280,27663,24066,24643,23460,35270,35797, | ||
| 1091 | 25910,25163,39318,23432,23551,25480,21806,21463,30246,20861,34092,26530,26803, | ||
| 1092 | 27530,25234,36755,21460,33298,28113,30095,20070,36174,23408,29087,34223,26257, | ||
| 1093 | 26329,32626,34560,40653,40736,23646,26415,36848,26641,26463,25101,31446,22661, | ||
| 1094 | 24246,25968,28465,34178,34179,34182,34184,34185,34186,34187,34188,34189,34190, | ||
| 1095 | 34192,34193,34194,34195,34196,34197,34198,34199,34200, | ||
| 1096 | 34201,34202,34205,34206,34207,34208,34209,34210,34211,34213,34214,34215,34217, | ||
| 1097 | 34219,34220,34221,34225,34226,34227,34228,34229,34230,34232,34234,34235,34236, | ||
| 1098 | 34237,34238,34239,34240,34242,34243,34244,34245,34246,34247,34248,34250,34251, | ||
| 1099 | 34252,34253,34254,34257,34258,34260,34262,34263,34264,34265,34266,34267,34269, | ||
| 1100 | 34270,34271,34272,34273,34274,34275,34277,34278,34279,34280,34282,34283,34284, | ||
| 1101 | 34285,34286,34287,34288,34289,34290,34291,34292,34293,34294,34295,34296,24661, | ||
| 1102 | 21047,32781,25684,34928,29993,24069,26643,25332,38684,21452,29245,35841,27700, | ||
| 1103 | 30561,31246,21550,30636,39034,33308,35828,30805,26388,28865,26031,25749,22070, | ||
| 1104 | 24605,31169,21496,19997,27515,32902,23546,21987,22235,20282,20284,39282,24051, | ||
| 1105 | 26494,32824,24578,39042,36865,23435,35772,35829,25628,33368,25822,22013,33487, | ||
| 1106 | 37221,20439,32032,36895,31903,20723,22609,28335,23487,35785,32899,37240,33948, | ||
| 1107 | 31639,34429,38539,38543,32485,39635,30862,23681,31319,36930,38567,31071,23385, | ||
| 1108 | 25439,31499,34001,26797,21766,32553,29712,32034,38145,25152,22604,20182,23427, | ||
| 1109 | 22905,22612,34297,34298,34300,34301,34302,34304,34305,34306,34307,34308,34310, | ||
| 1110 | 34311,34312,34313,34314,34315,34316,34317,34318,34319,34320,34322,34323,34324, | ||
| 1111 | 34325,34327,34328,34329,34330,34331,34332,34333,34334,34335,34336,34337,34338, | ||
| 1112 | 34339,34340,34341,34342,34344,34346,34347,34348,34349,34350,34351,34352,34353, | ||
| 1113 | 34354,34355,34356,34357,34358,34359,34361,34362,34363,34365,34366,34367,34368, | ||
| 1114 | 34369,34370,34371,34372,34373,34374,34375,34376,34377,34378,34379,34380,34386, | ||
| 1115 | 34387,34389,34390,34391,34392,34393,34395,34396,34397, | ||
| 1116 | 34399,34400,34401,34403,34404,34405,34406,34407,34408,34409,34410,29549,25374, | ||
| 1117 | 36427,36367,32974,33492,25260,21488,27888,37214,22826,24577,27760,22349,25674, | ||
| 1118 | 36138,30251,28393,22363,27264,30192,28525,35885,35848,22374,27631,34962,30899, | ||
| 1119 | 25506,21497,28845,27748,22616,25642,22530,26848,33179,21776,31958,20504,36538, | ||
| 1120 | 28108,36255,28907,25487,28059,28372,32486,33796,26691,36867,28120,38518,35752, | ||
| 1121 | 22871,29305,34276,33150,30140,35466,26799,21076,36386,38161,25552,39064,36420, | ||
| 1122 | 21884,20307,26367,22159,24789,28053,21059,23625,22825,28155,22635,30000,29980, | ||
| 1123 | 24684,33300,33094,25361,26465,36834,30522,36339,36148,38081,24086,21381,21548, | ||
| 1124 | 28867,34413,34415,34416,34418,34419,34420,34421,34422,34423,34424,34435,34436, | ||
| 1125 | 34437,34438,34439,34440,34441,34446,34447,34448,34449,34450,34452,34454,34455, | ||
| 1126 | 34456,34457,34458,34459,34462,34463,34464,34465,34466,34469,34470,34475,34477, | ||
| 1127 | 34478,34482,34483,34487,34488,34489,34491,34492,34493,34494,34495,34497,34498, | ||
| 1128 | 34499,34501,34504,34508,34509,34514,34515,34517,34518,34519,34522,34524,34525, | ||
| 1129 | 34528,34529,34530,34531,34533,34534,34535,34536,34538,34539,34540,34543,34549, | ||
| 1130 | 34550,34551,34554,34555,34556,34557,34559,34561,34564,34565,34566,34571,34572, | ||
| 1131 | 34574,34575,34576,34577,34580,34582,27712,24311,20572,20141,24237,25402,33351, | ||
| 1132 | 36890,26704,37230,30643,21516,38108,24420,31461,26742,25413,31570,32479,30171, | ||
| 1133 | 20599,25237,22836,36879,20984,31171,31361,22270,24466,36884,28034,23648,22303, | ||
| 1134 | 21520,20820,28237,22242,25512,39059,33151,34581,35114,36864,21534,23663,33216, | ||
| 1135 | 25302,25176,33073,40501,38464,39534,39548,26925,22949, | ||
| 1136 | 25299,21822,25366,21703,34521,27964,23043,29926,34972,27498,22806,35916,24367, | ||
| 1137 | 28286,29609,39037,20024,28919,23436,30871,25405,26202,30358,24779,23451,23113, | ||
| 1138 | 19975,33109,27754,29579,20129,26505,32593,24448,26106,26395,24536,22916,23041, | ||
| 1139 | 34585,34587,34589,34591,34592,34596,34598,34599,34600,34602,34603,34604,34605, | ||
| 1140 | 34607,34608,34610,34611,34613,34614,34616,34617,34618,34620,34621,34624,34625, | ||
| 1141 | 34626,34627,34628,34629,34630,34634,34635,34637,34639,34640,34641,34642,34644, | ||
| 1142 | 34645,34646,34648,34650,34651,34652,34653,34654,34655,34657,34658,34662,34663, | ||
| 1143 | 34664,34665,34666,34667,34668,34669,34671,34673,34674,34675,34677,34679,34680, | ||
| 1144 | 34681,34682,34687,34688,34689,34692,34694,34695,34697,34698,34700,34702,34703, | ||
| 1145 | 34704,34705,34706,34708,34709,34710,34712,34713,34714,34715,34716,34717,34718, | ||
| 1146 | 34720,34721,34722,34723,34724,24013,24494,21361,38886,36829,26693,22260,21807, | ||
| 1147 | 24799,20026,28493,32500,33479,33806,22996,20255,20266,23614,32428,26410,34074, | ||
| 1148 | 21619,30031,32963,21890,39759,20301,28205,35859,23561,24944,21355,30239,28201, | ||
| 1149 | 34442,25991,38395,32441,21563,31283,32010,38382,21985,32705,29934,25373,34583, | ||
| 1150 | 28065,31389,25105,26017,21351,25569,27779,24043,21596,38056,20044,27745,35820, | ||
| 1151 | 23627,26080,33436,26791,21566,21556,27595,27494,20116,25410,21320,33310,20237, | ||
| 1152 | 20398,22366,25098,38654,26212,29289,21247,21153,24735,35823,26132,29081,26512, | ||
| 1153 | 35199,30802,30717,26224,22075,21560,38177,29306,34725,34726,34727,34729,34730, | ||
| 1154 | 34734,34736,34737,34738,34740,34742,34743,34744,34745,34747,34748,34750,34751, | ||
| 1155 | 34753,34754,34755,34756,34757,34759,34760,34761,34764, | ||
| 1156 | 34765,34766,34767,34768,34772,34773,34774,34775,34776,34777,34778,34780,34781, | ||
| 1157 | 34782,34783,34785,34786,34787,34788,34790,34791,34792,34793,34795,34796,34797, | ||
| 1158 | 34799,34800,34801,34802,34803,34804,34805,34806,34807,34808,34810,34811,34812, | ||
| 1159 | 34813,34815,34816,34817,34818,34820,34821,34822,34823,34824,34825,34827,34828, | ||
| 1160 | 34829,34830,34831,34832,34833,34834,34836,34839,34840,34841,34842,34844,34845, | ||
| 1161 | 34846,34847,34848,34851,31232,24687,24076,24713,33181,22805,24796,29060,28911, | ||
| 1162 | 28330,27728,29312,27268,34989,24109,20064,23219,21916,38115,27927,31995,38553, | ||
| 1163 | 25103,32454,30606,34430,21283,38686,36758,26247,23777,20384,29421,19979,21414, | ||
| 1164 | 22799,21523,25472,38184,20808,20185,40092,32420,21688,36132,34900,33335,38386, | ||
| 1165 | 28046,24358,23244,26174,38505,29616,29486,21439,33146,39301,32673,23466,38519, | ||
| 1166 | 38480,32447,30456,21410,38262,39321,31665,35140,28248,20065,32724,31077,35814, | ||
| 1167 | 24819,21709,20139,39033,24055,27233,20687,21521,35937,33831,30813,38660,21066, | ||
| 1168 | 21742,22179,38144,28040,23477,28102,26195,34852,34853,34854,34855,34856,34857, | ||
| 1169 | 34858,34859,34860,34861,34862,34863,34864,34865,34867,34868,34869,34870,34871, | ||
| 1170 | 34872,34874,34875,34877,34878,34879,34881,34882,34883,34886,34887,34888,34889, | ||
| 1171 | 34890,34891,34894,34895,34896,34897,34898,34899,34901,34902,34904,34906,34907, | ||
| 1172 | 34908,34909,34910,34911,34912,34918,34919,34922,34925,34927,34929,34931,34932, | ||
| 1173 | 34933,34934,34936,34937,34938,34939,34940,34944,34947,34950,34951,34953,34954, | ||
| 1174 | 34956,34958,34959,34960,34961,34963,34964,34965,34967,34968,34969,34970,34971, | ||
| 1175 | 34973,34974,34975,34976,34977,34979,34981,34982,34983, | ||
| 1176 | 34984,34985,34986,23567,23389,26657,32918,21880,31505,25928,26964,20123,27463, | ||
| 1177 | 34638,38795,21327,25375,25658,37034,26012,32961,35856,20889,26800,21368,34809, | ||
| 1178 | 25032,27844,27899,35874,23633,34218,33455,38156,27427,36763,26032,24571,24515, | ||
| 1179 | 20449,34885,26143,33125,29481,24826,20852,21009,22411,24418,37026,34892,37266, | ||
| 1180 | 24184,26447,24615,22995,20804,20982,33016,21256,27769,38596,29066,20241,20462, | ||
| 1181 | 32670,26429,21957,38152,31168,34966,32483,22687,25100,38656,34394,22040,39035, | ||
| 1182 | 24464,35768,33988,37207,21465,26093,24207,30044,24676,32110,23167,32490,32493, | ||
| 1183 | 36713,21927,23459,24748,26059,29572,34988,34990,34991,34992,34994,34995,34996, | ||
| 1184 | 34997,34998,35000,35001,35002,35003,35005,35006,35007,35008,35011,35012,35015, | ||
| 1185 | 35016,35018,35019,35020,35021,35023,35024,35025,35027,35030,35031,35034,35035, | ||
| 1186 | 35036,35037,35038,35040,35041,35046,35047,35049,35050,35051,35052,35053,35054, | ||
| 1187 | 35055,35058,35061,35062,35063,35066,35067,35069,35071,35072,35073,35075,35076, | ||
| 1188 | 35077,35078,35079,35080,35081,35083,35084,35085,35086,35087,35089,35092,35093, | ||
| 1189 | 35094,35095,35096,35100,35101,35102,35103,35104,35106,35107,35108,35110,35111, | ||
| 1190 | 35112,35113,35116,35117,35118,35119,35121,35122,35123,35125,35127,36873,30307, | ||
| 1191 | 30505,32474,38772,34203,23398,31348,38634,34880,21195,29071,24490,26092,35810, | ||
| 1192 | 23547,39535,24033,27529,27739,35757,35759,36874,36805,21387,25276,40486,40493, | ||
| 1193 | 21568,20011,33469,29273,34460,23830,34905,28079,38597,21713,20122,35766,28937, | ||
| 1194 | 21693,38409,28895,28153,30416,20005,30740,34578,23721,24310,35328,39068,38414, | ||
| 1195 | 28814,27839,22852,25513,30524,34893,28436,33395,22576, | ||
| 1196 | 29141,21388,30746,38593,21761,24422,28976,23476,35866,39564,27523,22830,40495, | ||
| 1197 | 31207,26472,25196,20335,30113,32650,27915,38451,27687,20208,30162,20859,26679, | ||
| 1198 | 28478,36992,33136,22934,29814,35128,35129,35130,35131,35132,35133,35134,35135, | ||
| 1199 | 35136,35138,35139,35141,35142,35143,35144,35145,35146,35147,35148,35149,35150, | ||
| 1200 | 35151,35152,35153,35154,35155,35156,35157,35158,35159,35160,35161,35162,35163, | ||
| 1201 | 35164,35165,35168,35169,35170,35171,35172,35173,35175,35176,35177,35178,35179, | ||
| 1202 | 35180,35181,35182,35183,35184,35185,35186,35187,35188,35189,35190,35191,35192, | ||
| 1203 | 35193,35194,35196,35197,35198,35200,35202,35204,35205,35207,35208,35209,35210, | ||
| 1204 | 35211,35212,35213,35214,35215,35216,35217,35218,35219,35220,35221,35222,35223, | ||
| 1205 | 35224,35225,35226,35227,35228,35229,35230,35231,35232,35233,25671,23591,36965, | ||
| 1206 | 31377,35875,23002,21676,33280,33647,35201,32768,26928,22094,32822,29239,37326, | ||
| 1207 | 20918,20063,39029,25494,19994,21494,26355,33099,22812,28082,19968,22777,21307, | ||
| 1208 | 25558,38129,20381,20234,34915,39056,22839,36951,31227,20202,33008,30097,27778, | ||
| 1209 | 23452,23016,24413,26885,34433,20506,24050,20057,30691,20197,33402,25233,26131, | ||
| 1210 | 37009,23673,20159,24441,33222,36920,32900,30123,20134,35028,24847,27589,24518, | ||
| 1211 | 20041,30410,28322,35811,35758,35850,35793,24322,32764,32716,32462,33589,33643, | ||
| 1212 | 22240,27575,38899,38452,23035,21535,38134,28139,23493,39278,23609,24341,38544, | ||
| 1213 | 35234,35235,35236,35237,35238,35239,35240,35241,35242,35243,35244,35245,35246, | ||
| 1214 | 35247,35248,35249,35250,35251,35252,35253,35254,35255,35256,35257,35258,35259, | ||
| 1215 | 35260,35261,35262,35263,35264,35267,35277,35283,35284, | ||
| 1216 | 35285,35287,35288,35289,35291,35293,35295,35296,35297,35298,35300,35303,35304, | ||
| 1217 | 35305,35306,35308,35309,35310,35312,35313,35314,35316,35317,35318,35319,35320, | ||
| 1218 | 35321,35322,35323,35324,35325,35326,35327,35329,35330,35331,35332,35333,35334, | ||
| 1219 | 35336,35337,35338,35339,35340,35341,35342,35343,35344,35345,35346,35347,35348, | ||
| 1220 | 35349,35350,35351,35352,35353,35354,35355,35356,35357,21360,33521,27185,23156, | ||
| 1221 | 40560,24212,32552,33721,33828,33829,33639,34631,36814,36194,30408,24433,39062, | ||
| 1222 | 30828,26144,21727,25317,20323,33219,30152,24248,38605,36362,34553,21647,27891, | ||
| 1223 | 28044,27704,24703,21191,29992,24189,20248,24736,24551,23588,30001,37038,38080, | ||
| 1224 | 29369,27833,28216,37193,26377,21451,21491,20305,37321,35825,21448,24188,36802, | ||
| 1225 | 28132,20110,30402,27014,34398,24858,33286,20313,20446,36926,40060,24841,28189, | ||
| 1226 | 28180,38533,20104,23089,38632,19982,23679,31161,23431,35821,32701,29577,22495, | ||
| 1227 | 33419,37057,21505,36935,21947,23786,24481,24840,27442,29425,32946,35465,35358, | ||
| 1228 | 35359,35360,35361,35362,35363,35364,35365,35366,35367,35368,35369,35370,35371, | ||
| 1229 | 35372,35373,35374,35375,35376,35377,35378,35379,35380,35381,35382,35383,35384, | ||
| 1230 | 35385,35386,35387,35388,35389,35391,35392,35393,35394,35395,35396,35397,35398, | ||
| 1231 | 35399,35401,35402,35403,35404,35405,35406,35407,35408,35409,35410,35411,35412, | ||
| 1232 | 35413,35414,35415,35416,35417,35418,35419,35420,35421,35422,35423,35424,35425, | ||
| 1233 | 35426,35427,35428,35429,35430,35431,35432,35433,35434,35435,35436,35437,35438, | ||
| 1234 | 35439,35440,35441,35442,35443,35444,35445,35446,35447,35448,35450,35451,35452, | ||
| 1235 | 35453,35454,35455,35456,28020,23507,35029,39044,35947, | ||
| 1236 | 39533,40499,28170,20900,20803,22435,34945,21407,25588,36757,22253,21592,22278, | ||
| 1237 | 29503,28304,32536,36828,33489,24895,24616,38498,26352,32422,36234,36291,38053, | ||
| 1238 | 23731,31908,26376,24742,38405,32792,20113,37095,21248,38504,20801,36816,34164, | ||
| 1239 | 37213,26197,38901,23381,21277,30776,26434,26685,21705,28798,23472,36733,20877, | ||
| 1240 | 22312,21681,25874,26242,36190,36163,33039,33900,36973,31967,20991,34299,26531, | ||
| 1241 | 26089,28577,34468,36481,22122,36896,30338,28790,29157,36131,25321,21017,27901, | ||
| 1242 | 36156,24590,22686,24974,26366,36192,25166,21939,28195,26413,36711,35457,35458, | ||
| 1243 | 35459,35460,35461,35462,35463,35464,35467,35468,35469,35470,35471,35472,35473, | ||
| 1244 | 35474,35476,35477,35478,35479,35480,35481,35482,35483,35484,35485,35486,35487, | ||
| 1245 | 35488,35489,35490,35491,35492,35493,35494,35495,35496,35497,35498,35499,35500, | ||
| 1246 | 35501,35502,35503,35504,35505,35506,35507,35508,35509,35510,35511,35512,35513, | ||
| 1247 | 35514,35515,35516,35517,35518,35519,35520,35521,35522,35523,35524,35525,35526, | ||
| 1248 | 35527,35528,35529,35530,35531,35532,35533,35534,35535,35536,35537,35538,35539, | ||
| 1249 | 35540,35541,35542,35543,35544,35545,35546,35547,35548,35549,35550,35551,35552, | ||
| 1250 | 35553,35554,35555,38113,38392,30504,26629,27048,21643,20045,28856,35784,25688, | ||
| 1251 | 25995,23429,31364,20538,23528,30651,27617,35449,31896,27838,30415,26025,36759, | ||
| 1252 | 23853,23637,34360,26632,21344,25112,31449,28251,32509,27167,31456,24432,28467, | ||
| 1253 | 24352,25484,28072,26454,19976,24080,36134,20183,32960,30260,38556,25307,26157, | ||
| 1254 | 25214,27836,36213,29031,32617,20806,32903,21484,36974,25240,21746,34544,36761, | ||
| 1255 | 32773,38167,34071,36825,27993,29645,26015,30495,29956, | ||
| 1256 | 30759,33275,36126,38024,20390,26517,30137,35786,38663,25391,38215,38453,33976, | ||
| 1257 | 25379,30529,24449,29424,20105,24596,25972,25327,27491,25919,35556,35557,35558, | ||
| 1258 | 35559,35560,35561,35562,35563,35564,35565,35566,35567,35568,35569,35570,35571, | ||
| 1259 | 35572,35573,35574,35575,35576,35577,35578,35579,35580,35581,35582,35583,35584, | ||
| 1260 | 35585,35586,35587,35588,35589,35590,35592,35593,35594,35595,35596,35597,35598, | ||
| 1261 | 35599,35600,35601,35602,35603,35604,35605,35606,35607,35608,35609,35610,35611, | ||
| 1262 | 35612,35613,35614,35615,35616,35617,35618,35619,35620,35621,35623,35624,35625, | ||
| 1263 | 35626,35627,35628,35629,35630,35631,35632,35633,35634,35635,35636,35637,35638, | ||
| 1264 | 35639,35640,35641,35642,35643,35644,35645,35646,35647,35648,35649,35650,35651, | ||
| 1265 | 35652,35653,24103,30151,37073,35777,33437,26525,25903,21553,34584,30693,32930, | ||
| 1266 | 33026,27713,20043,32455,32844,30452,26893,27542,25191,20540,20356,22336,25351, | ||
| 1267 | 27490,36286,21482,26088,32440,24535,25370,25527,33267,33268,32622,24092,23769, | ||
| 1268 | 21046,26234,31209,31258,36136,28825,30164,28382,27835,31378,20013,30405,24544, | ||
| 1269 | 38047,34935,32456,31181,32959,37325,20210,20247,33311,21608,24030,27954,35788, | ||
| 1270 | 31909,36724,32920,24090,21650,30385,23449,26172,39588,29664,26666,34523,26417, | ||
| 1271 | 29482,35832,35803,36880,31481,28891,29038,25284,30633,22065,20027,33879,26609, | ||
| 1272 | 21161,34496,36142,38136,31569,35654,35655,35656,35657,35658,35659,35660,35661, | ||
| 1273 | 35662,35663,35664,35665,35666,35667,35668,35669,35670,35671,35672,35673,35674, | ||
| 1274 | 35675,35676,35677,35678,35679,35680,35681,35682,35683,35684,35685,35687,35688, | ||
| 1275 | 35689,35690,35691,35693,35694,35695,35696,35697,35698, | ||
| 1276 | 35699,35700,35701,35702,35703,35704,35705,35706,35707,35708,35709,35710,35711, | ||
| 1277 | 35712,35713,35714,35715,35716,35717,35718,35719,35720,35721,35722,35723,35724, | ||
| 1278 | 35725,35726,35727,35728,35729,35730,35731,35732,35733,35734,35735,35736,35737, | ||
| 1279 | 35738,35739,35740,35741,35742,35743,35756,35761,35771,35783,35792,35818,35849, | ||
| 1280 | 35870,20303,27880,31069,39547,25235,29226,25341,19987,30742,36716,25776,36186, | ||
| 1281 | 31686,26729,24196,35013,22918,25758,22766,29366,26894,38181,36861,36184,22368, | ||
| 1282 | 32512,35846,20934,25417,25305,21331,26700,29730,33537,37196,21828,30528,28796, | ||
| 1283 | 27978,20857,21672,36164,23039,28363,28100,23388,32043,20180,31869,28371,23376, | ||
| 1284 | 33258,28173,23383,39683,26837,36394,23447,32508,24635,32437,37049,36208,22863, | ||
| 1285 | 25549,31199,36275,21330,26063,31062,35781,38459,32452,38075,32386,22068,37257, | ||
| 1286 | 26368,32618,23562,36981,26152,24038,20304,26590,20570,20316,22352,24231,59408, | ||
| 1287 | 59409,59410,59411,59412,35896,35897,35898,35899,35900,35901,35902,35903,35904, | ||
| 1288 | 35906,35907,35908,35909,35912,35914,35915,35917,35918,35919,35920,35921,35922, | ||
| 1289 | 35923,35924,35926,35927,35928,35929,35931,35932,35933,35934,35935,35936,35939, | ||
| 1290 | 35940,35941,35942,35943,35944,35945,35948,35949,35950,35951,35952,35953,35954, | ||
| 1291 | 35956,35957,35958,35959,35963,35964,35965,35966,35967,35968,35969,35971,35972, | ||
| 1292 | 35974,35975,35976,35979,35981,35982,35983,35984,35985,35986,35987,35989,35990, | ||
| 1293 | 35991,35993,35994,35995,35996,35997,35998,35999,36000,36001,36002,36003,36004, | ||
| 1294 | 36005,36006,36007,36008,36009,36010,36011,36012,36013,20109,19980,20800,19984, | ||
| 1295 | 24319,21317,19989,20120,19998,39730,23404,22121,20008, | ||
| 1296 | 31162,20031,21269,20039,22829,29243,21358,27664,22239,32996,39319,27603,30590, | ||
| 1297 | 40727,20022,20127,40720,20060,20073,20115,33416,23387,21868,22031,20164,21389, | ||
| 1298 | 21405,21411,21413,21422,38757,36189,21274,21493,21286,21294,21310,36188,21350, | ||
| 1299 | 21347,20994,21000,21006,21037,21043,21055,21056,21068,21086,21089,21084,33967, | ||
| 1300 | 21117,21122,21121,21136,21139,20866,32596,20155,20163,20169,20162,20200,20193, | ||
| 1301 | 20203,20190,20251,20211,20258,20324,20213,20261,20263,20233,20267,20318,20327, | ||
| 1302 | 25912,20314,20317,36014,36015,36016,36017,36018,36019,36020,36021,36022,36023, | ||
| 1303 | 36024,36025,36026,36027,36028,36029,36030,36031,36032,36033,36034,36035,36036, | ||
| 1304 | 36037,36038,36039,36040,36041,36042,36043,36044,36045,36046,36047,36048,36049, | ||
| 1305 | 36050,36051,36052,36053,36054,36055,36056,36057,36058,36059,36060,36061,36062, | ||
| 1306 | 36063,36064,36065,36066,36067,36068,36069,36070,36071,36072,36073,36074,36075, | ||
| 1307 | 36076,36077,36078,36079,36080,36081,36082,36083,36084,36085,36086,36087,36088, | ||
| 1308 | 36089,36090,36091,36092,36093,36094,36095,36096,36097,36098,36099,36100,36101, | ||
| 1309 | 36102,36103,36104,36105,36106,36107,36108,36109,20319,20311,20274,20285,20342, | ||
| 1310 | 20340,20369,20361,20355,20367,20350,20347,20394,20348,20396,20372,20454,20456, | ||
| 1311 | 20458,20421,20442,20451,20444,20433,20447,20472,20521,20556,20467,20524,20495, | ||
| 1312 | 20526,20525,20478,20508,20492,20517,20520,20606,20547,20565,20552,20558,20588, | ||
| 1313 | 20603,20645,20647,20649,20666,20694,20742,20717,20716,20710,20718,20743,20747, | ||
| 1314 | 20189,27709,20312,20325,20430,40864,27718,31860,20846,24061,40649,39320,20865, | ||
| 1315 | 22804,21241,21261,35335,21264,20971,22809,20821,20128, | ||
| 1316 | 20822,20147,34926,34980,20149,33044,35026,31104,23348,34819,32696,20907,20913, | ||
| 1317 | 20925,20924,36110,36111,36112,36113,36114,36115,36116,36117,36118,36119,36120, | ||
| 1318 | 36121,36122,36123,36124,36128,36177,36178,36183,36191,36197,36200,36201,36202, | ||
| 1319 | 36204,36206,36207,36209,36210,36216,36217,36218,36219,36220,36221,36222,36223, | ||
| 1320 | 36224,36226,36227,36230,36231,36232,36233,36236,36237,36238,36239,36240,36242, | ||
| 1321 | 36243,36245,36246,36247,36248,36249,36250,36251,36252,36253,36254,36256,36257, | ||
| 1322 | 36258,36260,36261,36262,36263,36264,36265,36266,36267,36268,36269,36270,36271, | ||
| 1323 | 36272,36274,36278,36279,36281,36283,36285,36288,36289,36290,36293,36295,36296, | ||
| 1324 | 36297,36298,36301,36304,36306,36307,36308,20935,20886,20898,20901,35744,35750, | ||
| 1325 | 35751,35754,35764,35765,35767,35778,35779,35787,35791,35790,35794,35795,35796, | ||
| 1326 | 35798,35800,35801,35804,35807,35808,35812,35816,35817,35822,35824,35827,35830, | ||
| 1327 | 35833,35836,35839,35840,35842,35844,35847,35852,35855,35857,35858,35860,35861, | ||
| 1328 | 35862,35865,35867,35864,35869,35871,35872,35873,35877,35879,35882,35883,35886, | ||
| 1329 | 35887,35890,35891,35893,35894,21353,21370,38429,38434,38433,38449,38442,38461, | ||
| 1330 | 38460,38466,38473,38484,38495,38503,38508,38514,38516,38536,38541,38551,38576, | ||
| 1331 | 37015,37019,37021,37017,37036,37025,37044,37043,37046,37050,36309,36312,36313, | ||
| 1332 | 36316,36320,36321,36322,36325,36326,36327,36329,36333,36334,36336,36337,36338, | ||
| 1333 | 36340,36342,36348,36350,36351,36352,36353,36354,36355,36356,36358,36359,36360, | ||
| 1334 | 36363,36365,36366,36368,36369,36370,36371,36373,36374,36375,36376,36377,36378, | ||
| 1335 | 36379,36380,36384,36385,36388,36389,36390,36391,36392, | ||
| 1336 | 36395,36397,36400,36402,36403,36404,36406,36407,36408,36411,36412,36414,36415, | ||
| 1337 | 36419,36421,36422,36428,36429,36430,36431,36432,36435,36436,36437,36438,36439, | ||
| 1338 | 36440,36442,36443,36444,36445,36446,36447,36448,36449,36450,36451,36452,36453, | ||
| 1339 | 36455,36456,36458,36459,36462,36465,37048,37040,37071,37061,37054,37072,37060, | ||
| 1340 | 37063,37075,37094,37090,37084,37079,37083,37099,37103,37118,37124,37154,37150, | ||
| 1341 | 37155,37169,37167,37177,37187,37190,21005,22850,21154,21164,21165,21182,21759, | ||
| 1342 | 21200,21206,21232,21471,29166,30669,24308,20981,20988,39727,21430,24321,30042, | ||
| 1343 | 24047,22348,22441,22433,22654,22716,22725,22737,22313,22316,22314,22323,22329, | ||
| 1344 | 22318,22319,22364,22331,22338,22377,22405,22379,22406,22396,22395,22376,22381, | ||
| 1345 | 22390,22387,22445,22436,22412,22450,22479,22439,22452,22419,22432,22485,22488, | ||
| 1346 | 22490,22489,22482,22456,22516,22511,22520,22500,22493,36467,36469,36471,36472, | ||
| 1347 | 36473,36474,36475,36477,36478,36480,36482,36483,36484,36486,36488,36489,36490, | ||
| 1348 | 36491,36492,36493,36494,36497,36498,36499,36501,36502,36503,36504,36505,36506, | ||
| 1349 | 36507,36509,36511,36512,36513,36514,36515,36516,36517,36518,36519,36520,36521, | ||
| 1350 | 36522,36525,36526,36528,36529,36531,36532,36533,36534,36535,36536,36537,36539, | ||
| 1351 | 36540,36541,36542,36543,36544,36545,36546,36547,36548,36549,36550,36551,36552, | ||
| 1352 | 36553,36554,36555,36556,36557,36559,36560,36561,36562,36563,36564,36565,36566, | ||
| 1353 | 36567,36568,36569,36570,36571,36572,36573,36574,36575,36576,36577,36578,36579, | ||
| 1354 | 36580,22539,22541,22525,22509,22528,22558,22553,22596,22560,22629,22636,22657, | ||
| 1355 | 22665,22682,22656,39336,40729,25087,33401,33405,33407, | ||
| 1356 | 33423,33418,33448,33412,33422,33425,33431,33433,33451,33464,33470,33456,33480, | ||
| 1357 | 33482,33507,33432,33463,33454,33483,33484,33473,33449,33460,33441,33450,33439, | ||
| 1358 | 33476,33486,33444,33505,33545,33527,33508,33551,33543,33500,33524,33490,33496, | ||
| 1359 | 33548,33531,33491,33553,33562,33542,33556,33557,33504,33493,33564,33617,33627, | ||
| 1360 | 33628,33544,33682,33596,33588,33585,33691,33630,33583,33615,33607,33603,33631, | ||
| 1361 | 33600,33559,33632,33581,33594,33587,33638,33637,36581,36582,36583,36584,36585, | ||
| 1362 | 36586,36587,36588,36589,36590,36591,36592,36593,36594,36595,36596,36597,36598, | ||
| 1363 | 36599,36600,36601,36602,36603,36604,36605,36606,36607,36608,36609,36610,36611, | ||
| 1364 | 36612,36613,36614,36615,36616,36617,36618,36619,36620,36621,36622,36623,36624, | ||
| 1365 | 36625,36626,36627,36628,36629,36630,36631,36632,36633,36634,36635,36636,36637, | ||
| 1366 | 36638,36639,36640,36641,36642,36643,36644,36645,36646,36647,36648,36649,36650, | ||
| 1367 | 36651,36652,36653,36654,36655,36656,36657,36658,36659,36660,36661,36662,36663, | ||
| 1368 | 36664,36665,36666,36667,36668,36669,36670,36671,36672,36673,36674,36675,36676, | ||
| 1369 | 33640,33563,33641,33644,33642,33645,33646,33712,33656,33715,33716,33696,33706, | ||
| 1370 | 33683,33692,33669,33660,33718,33705,33661,33720,33659,33688,33694,33704,33722, | ||
| 1371 | 33724,33729,33793,33765,33752,22535,33816,33803,33757,33789,33750,33820,33848, | ||
| 1372 | 33809,33798,33748,33759,33807,33795,33784,33785,33770,33733,33728,33830,33776, | ||
| 1373 | 33761,33884,33873,33882,33881,33907,33927,33928,33914,33929,33912,33852,33862, | ||
| 1374 | 33897,33910,33932,33934,33841,33901,33985,33997,34000,34022,33981,34003,33994, | ||
| 1375 | 33983,33978,34016,33953,33977,33972,33943,34021,34019, | ||
| 1376 | 34060,29965,34104,34032,34105,34079,34106,36677,36678,36679,36680,36681,36682, | ||
| 1377 | 36683,36684,36685,36686,36687,36688,36689,36690,36691,36692,36693,36694,36695, | ||
| 1378 | 36696,36697,36698,36699,36700,36701,36702,36703,36704,36705,36706,36707,36708, | ||
| 1379 | 36709,36714,36736,36748,36754,36765,36768,36769,36770,36772,36773,36774,36775, | ||
| 1380 | 36778,36780,36781,36782,36783,36786,36787,36788,36789,36791,36792,36794,36795, | ||
| 1381 | 36796,36799,36800,36803,36806,36809,36810,36811,36812,36813,36815,36818,36822, | ||
| 1382 | 36823,36826,36832,36833,36835,36839,36844,36847,36849,36850,36852,36853,36854, | ||
| 1383 | 36858,36859,36860,36862,36863,36871,36872,36876,36878,36883,36885,36888,34134, | ||
| 1384 | 34107,34047,34044,34137,34120,34152,34148,34142,34170,30626,34115,34162,34171, | ||
| 1385 | 34212,34216,34183,34191,34169,34222,34204,34181,34233,34231,34224,34259,34241, | ||
| 1386 | 34268,34303,34343,34309,34345,34326,34364,24318,24328,22844,22849,32823,22869, | ||
| 1387 | 22874,22872,21263,23586,23589,23596,23604,25164,25194,25247,25275,25290,25306, | ||
| 1388 | 25303,25326,25378,25334,25401,25419,25411,25517,25590,25457,25466,25486,25524, | ||
| 1389 | 25453,25516,25482,25449,25518,25532,25586,25592,25568,25599,25540,25566,25550, | ||
| 1390 | 25682,25542,25534,25669,25665,25611,25627,25632,25612,25638,25633,25694,25732, | ||
| 1391 | 25709,25750,36889,36892,36899,36900,36901,36903,36904,36905,36906,36907,36908, | ||
| 1392 | 36912,36913,36914,36915,36916,36919,36921,36922,36925,36927,36928,36931,36933, | ||
| 1393 | 36934,36936,36937,36938,36939,36940,36942,36948,36949,36950,36953,36954,36956, | ||
| 1394 | 36957,36958,36959,36960,36961,36964,36966,36967,36969,36970,36971,36972,36975, | ||
| 1395 | 36976,36977,36978,36979,36982,36983,36984,36985,36986, | ||
| 1396 | 36987,36988,36990,36993,36996,36997,36998,36999,37001,37002,37004,37005,37006, | ||
| 1397 | 37007,37008,37010,37012,37014,37016,37018,37020,37022,37023,37024,37028,37029, | ||
| 1398 | 37031,37032,37033,37035,37037,37042,37047,37052,37053,37055,37056,25722,25783, | ||
| 1399 | 25784,25753,25786,25792,25808,25815,25828,25826,25865,25893,25902,24331,24530, | ||
| 1400 | 29977,24337,21343,21489,21501,21481,21480,21499,21522,21526,21510,21579,21586, | ||
| 1401 | 21587,21588,21590,21571,21537,21591,21593,21539,21554,21634,21652,21623,21617, | ||
| 1402 | 21604,21658,21659,21636,21622,21606,21661,21712,21677,21698,21684,21714,21671, | ||
| 1403 | 21670,21715,21716,21618,21667,21717,21691,21695,21708,21721,21722,21724,21673, | ||
| 1404 | 21674,21668,21725,21711,21726,21787,21735,21792,21757,21780,21747,21794,21795, | ||
| 1405 | 21775,21777,21799,21802,21863,21903,21941,21833,21869,21825,21845,21823,21840, | ||
| 1406 | 21820,37058,37059,37062,37064,37065,37067,37068,37069,37074,37076,37077,37078, | ||
| 1407 | 37080,37081,37082,37086,37087,37088,37091,37092,37093,37097,37098,37100,37102, | ||
| 1408 | 37104,37105,37106,37107,37109,37110,37111,37113,37114,37115,37116,37119,37120, | ||
| 1409 | 37121,37123,37125,37126,37127,37128,37129,37130,37131,37132,37133,37134,37135, | ||
| 1410 | 37136,37137,37138,37139,37140,37141,37142,37143,37144,37146,37147,37148,37149, | ||
| 1411 | 37151,37152,37153,37156,37157,37158,37159,37160,37161,37162,37163,37164,37165, | ||
| 1412 | 37166,37168,37170,37171,37172,37173,37174,37175,37176,37178,37179,37180,37181, | ||
| 1413 | 37182,37183,37184,37185,37186,37188,21815,21846,21877,21878,21879,21811,21808, | ||
| 1414 | 21852,21899,21970,21891,21937,21945,21896,21889,21919,21886,21974,21905,21883, | ||
| 1415 | 21983,21949,21950,21908,21913,21994,22007,21961,22047, | ||
| 1416 | 21969,21995,21996,21972,21990,21981,21956,21999,21989,22002,22003,21964,21965, | ||
| 1417 | 21992,22005,21988,36756,22046,22024,22028,22017,22052,22051,22014,22016,22055, | ||
| 1418 | 22061,22104,22073,22103,22060,22093,22114,22105,22108,22092,22100,22150,22116, | ||
| 1419 | 22129,22123,22139,22140,22149,22163,22191,22228,22231,22237,22241,22261,22251, | ||
| 1420 | 22265,22271,22276,22282,22281,22300,24079,24089,24084,24081,24113,24123,24124, | ||
| 1421 | 37189,37191,37192,37201,37203,37204,37205,37206,37208,37209,37211,37212,37215, | ||
| 1422 | 37216,37222,37223,37224,37227,37229,37235,37242,37243,37244,37248,37249,37250, | ||
| 1423 | 37251,37252,37254,37256,37258,37262,37263,37267,37268,37269,37270,37271,37272, | ||
| 1424 | 37273,37276,37277,37278,37279,37280,37281,37284,37285,37286,37287,37288,37289, | ||
| 1425 | 37291,37292,37296,37297,37298,37299,37302,37303,37304,37305,37307,37308,37309, | ||
| 1426 | 37310,37311,37312,37313,37314,37315,37316,37317,37318,37320,37323,37328,37330, | ||
| 1427 | 37331,37332,37333,37334,37335,37336,37337,37338,37339,37341,37342,37343,37344, | ||
| 1428 | 37345,37346,37347,37348,37349,24119,24132,24148,24155,24158,24161,23692,23674, | ||
| 1429 | 23693,23696,23702,23688,23704,23705,23697,23706,23708,23733,23714,23741,23724, | ||
| 1430 | 23723,23729,23715,23745,23735,23748,23762,23780,23755,23781,23810,23811,23847, | ||
| 1431 | 23846,23854,23844,23838,23814,23835,23896,23870,23860,23869,23916,23899,23919, | ||
| 1432 | 23901,23915,23883,23882,23913,23924,23938,23961,23965,35955,23991,24005,24435, | ||
| 1433 | 24439,24450,24455,24457,24460,24469,24473,24476,24488,24493,24501,24508,34914, | ||
| 1434 | 24417,29357,29360,29364,29367,29368,29379,29377,29390,29389,29394,29416,29423, | ||
| 1435 | 29417,29426,29428,29431,29441,29427,29443,29434,37350, | ||
| 1436 | 37351,37352,37353,37354,37355,37356,37357,37358,37359,37360,37361,37362,37363, | ||
| 1437 | 37364,37365,37366,37367,37368,37369,37370,37371,37372,37373,37374,37375,37376, | ||
| 1438 | 37377,37378,37379,37380,37381,37382,37383,37384,37385,37386,37387,37388,37389, | ||
| 1439 | 37390,37391,37392,37393,37394,37395,37396,37397,37398,37399,37400,37401,37402, | ||
| 1440 | 37403,37404,37405,37406,37407,37408,37409,37410,37411,37412,37413,37414,37415, | ||
| 1441 | 37416,37417,37418,37419,37420,37421,37422,37423,37424,37425,37426,37427,37428, | ||
| 1442 | 37429,37430,37431,37432,37433,37434,37435,37436,37437,37438,37439,37440,37441, | ||
| 1443 | 37442,37443,37444,37445,29435,29463,29459,29473,29450,29470,29469,29461,29474, | ||
| 1444 | 29497,29477,29484,29496,29489,29520,29517,29527,29536,29548,29551,29566,33307, | ||
| 1445 | 22821,39143,22820,22786,39267,39271,39272,39273,39274,39275,39276,39284,39287, | ||
| 1446 | 39293,39296,39300,39303,39306,39309,39312,39313,39315,39316,39317,24192,24209, | ||
| 1447 | 24203,24214,24229,24224,24249,24245,24254,24243,36179,24274,24273,24283,24296, | ||
| 1448 | 24298,33210,24516,24521,24534,24527,24579,24558,24580,24545,24548,24574,24581, | ||
| 1449 | 24582,24554,24557,24568,24601,24629,24614,24603,24591,24589,24617,24619,24586, | ||
| 1450 | 24639,24609,24696,24697,24699,24698,24642,37446,37447,37448,37449,37450,37451, | ||
| 1451 | 37452,37453,37454,37455,37456,37457,37458,37459,37460,37461,37462,37463,37464, | ||
| 1452 | 37465,37466,37467,37468,37469,37470,37471,37472,37473,37474,37475,37476,37477, | ||
| 1453 | 37478,37479,37480,37481,37482,37483,37484,37485,37486,37487,37488,37489,37490, | ||
| 1454 | 37491,37493,37494,37495,37496,37497,37498,37499,37500,37501,37502,37503,37504, | ||
| 1455 | 37505,37506,37507,37508,37509,37510,37511,37512,37513, | ||
| 1456 | 37514,37515,37516,37517,37519,37520,37521,37522,37523,37524,37525,37526,37527, | ||
| 1457 | 37528,37529,37530,37531,37532,37533,37534,37535,37536,37537,37538,37539,37540, | ||
| 1458 | 37541,37542,37543,24682,24701,24726,24730,24749,24733,24707,24722,24716,24731, | ||
| 1459 | 24812,24763,24753,24797,24792,24774,24794,24756,24864,24870,24853,24867,24820, | ||
| 1460 | 24832,24846,24875,24906,24949,25004,24980,24999,25015,25044,25077,24541,38579, | ||
| 1461 | 38377,38379,38385,38387,38389,38390,38396,38398,38403,38404,38406,38408,38410, | ||
| 1462 | 38411,38412,38413,38415,38418,38421,38422,38423,38425,38426,20012,29247,25109, | ||
| 1463 | 27701,27732,27740,27722,27811,27781,27792,27796,27788,27752,27753,27764,27766, | ||
| 1464 | 27782,27817,27856,27860,27821,27895,27896,27889,27863,27826,27872,27862,27898, | ||
| 1465 | 27883,27886,27825,27859,27887,27902,37544,37545,37546,37547,37548,37549,37551, | ||
| 1466 | 37552,37553,37554,37555,37556,37557,37558,37559,37560,37561,37562,37563,37564, | ||
| 1467 | 37565,37566,37567,37568,37569,37570,37571,37572,37573,37574,37575,37577,37578, | ||
| 1468 | 37579,37580,37581,37582,37583,37584,37585,37586,37587,37588,37589,37590,37591, | ||
| 1469 | 37592,37593,37594,37595,37596,37597,37598,37599,37600,37601,37602,37603,37604, | ||
| 1470 | 37605,37606,37607,37608,37609,37610,37611,37612,37613,37614,37615,37616,37617, | ||
| 1471 | 37618,37619,37620,37621,37622,37623,37624,37625,37626,37627,37628,37629,37630, | ||
| 1472 | 37631,37632,37633,37634,37635,37636,37637,37638,37639,37640,37641,27961,27943, | ||
| 1473 | 27916,27971,27976,27911,27908,27929,27918,27947,27981,27950,27957,27930,27983, | ||
| 1474 | 27986,27988,27955,28049,28015,28062,28064,27998,28051,28052,27996,28000,28028, | ||
| 1475 | 28003,28186,28103,28101,28126,28174,28095,28128,28177, | ||
| 1476 | 28134,28125,28121,28182,28075,28172,28078,28203,28270,28238,28267,28338,28255, | ||
| 1477 | 28294,28243,28244,28210,28197,28228,28383,28337,28312,28384,28461,28386,28325, | ||
| 1478 | 28327,28349,28347,28343,28375,28340,28367,28303,28354,28319,28514,28486,28487, | ||
| 1479 | 28452,28437,28409,28463,28470,28491,28532,28458,28425,28457,28553,28557,28556, | ||
| 1480 | 28536,28530,28540,28538,28625,37642,37643,37644,37645,37646,37647,37648,37649, | ||
| 1481 | 37650,37651,37652,37653,37654,37655,37656,37657,37658,37659,37660,37661,37662, | ||
| 1482 | 37663,37664,37665,37666,37667,37668,37669,37670,37671,37672,37673,37674,37675, | ||
| 1483 | 37676,37677,37678,37679,37680,37681,37682,37683,37684,37685,37686,37687,37688, | ||
| 1484 | 37689,37690,37691,37692,37693,37695,37696,37697,37698,37699,37700,37701,37702, | ||
| 1485 | 37703,37704,37705,37706,37707,37708,37709,37710,37711,37712,37713,37714,37715, | ||
| 1486 | 37716,37717,37718,37719,37720,37721,37722,37723,37724,37725,37726,37727,37728, | ||
| 1487 | 37729,37730,37731,37732,37733,37734,37735,37736,37737,37739,28617,28583,28601, | ||
| 1488 | 28598,28610,28641,28654,28638,28640,28655,28698,28707,28699,28729,28725,28751, | ||
| 1489 | 28766,23424,23428,23445,23443,23461,23480,29999,39582,25652,23524,23534,35120, | ||
| 1490 | 23536,36423,35591,36790,36819,36821,36837,36846,36836,36841,36838,36851,36840, | ||
| 1491 | 36869,36868,36875,36902,36881,36877,36886,36897,36917,36918,36909,36911,36932, | ||
| 1492 | 36945,36946,36944,36968,36952,36962,36955,26297,36980,36989,36994,37000,36995, | ||
| 1493 | 37003,24400,24407,24406,24408,23611,21675,23632,23641,23409,23651,23654,32700, | ||
| 1494 | 24362,24361,24365,33396,24380,39739,23662,22913,22915,22925,22953,22954,22947, | ||
| 1495 | 37740,37741,37742,37743,37744,37745,37746,37747,37748, | ||
| 1496 | 37749,37750,37751,37752,37753,37754,37755,37756,37757,37758,37759,37760,37761, | ||
| 1497 | 37762,37763,37764,37765,37766,37767,37768,37769,37770,37771,37772,37773,37774, | ||
| 1498 | 37776,37777,37778,37779,37780,37781,37782,37783,37784,37785,37786,37787,37788, | ||
| 1499 | 37789,37790,37791,37792,37793,37794,37795,37796,37797,37798,37799,37800,37801, | ||
| 1500 | 37802,37803,37804,37805,37806,37807,37808,37809,37810,37811,37812,37813,37814, | ||
| 1501 | 37815,37816,37817,37818,37819,37820,37821,37822,37823,37824,37825,37826,37827, | ||
| 1502 | 37828,37829,37830,37831,37832,37833,37835,37836,37837,22935,22986,22955,22942, | ||
| 1503 | 22948,22994,22962,22959,22999,22974,23045,23046,23005,23048,23011,23000,23033, | ||
| 1504 | 23052,23049,23090,23092,23057,23075,23059,23104,23143,23114,23125,23100,23138, | ||
| 1505 | 23157,33004,23210,23195,23159,23162,23230,23275,23218,23250,23252,23224,23264, | ||
| 1506 | 23267,23281,23254,23270,23256,23260,23305,23319,23318,23346,23351,23360,23573, | ||
| 1507 | 23580,23386,23397,23411,23377,23379,23394,39541,39543,39544,39546,39551,39549, | ||
| 1508 | 39552,39553,39557,39560,39562,39568,39570,39571,39574,39576,39579,39580,39581, | ||
| 1509 | 39583,39584,39586,39587,39589,39591,32415,32417,32419,32421,32424,32425,37838, | ||
| 1510 | 37839,37840,37841,37842,37843,37844,37845,37847,37848,37849,37850,37851,37852, | ||
| 1511 | 37853,37854,37855,37856,37857,37858,37859,37860,37861,37862,37863,37864,37865, | ||
| 1512 | 37866,37867,37868,37869,37870,37871,37872,37873,37874,37875,37876,37877,37878, | ||
| 1513 | 37879,37880,37881,37882,37883,37884,37885,37886,37887,37888,37889,37890,37891, | ||
| 1514 | 37892,37893,37894,37895,37896,37897,37898,37899,37900,37901,37902,37903,37904, | ||
| 1515 | 37905,37906,37907,37908,37909,37910,37911,37912,37913, | ||
| 1516 | 37914,37915,37916,37917,37918,37919,37920,37921,37922,37923,37924,37925,37926, | ||
| 1517 | 37927,37928,37929,37930,37931,37932,37933,37934,32429,32432,32446,32448,32449, | ||
| 1518 | 32450,32457,32459,32460,32464,32468,32471,32475,32480,32481,32488,32491,32494, | ||
| 1519 | 32495,32497,32498,32525,32502,32506,32507,32510,32513,32514,32515,32519,32520, | ||
| 1520 | 32523,32524,32527,32529,32530,32535,32537,32540,32539,32543,32545,32546,32547, | ||
| 1521 | 32548,32549,32550,32551,32554,32555,32556,32557,32559,32560,32561,32562,32563, | ||
| 1522 | 32565,24186,30079,24027,30014,37013,29582,29585,29614,29602,29599,29647,29634, | ||
| 1523 | 29649,29623,29619,29632,29641,29640,29669,29657,39036,29706,29673,29671,29662, | ||
| 1524 | 29626,29682,29711,29738,29787,29734,29733,29736,29744,29742,29740,37935,37936, | ||
| 1525 | 37937,37938,37939,37940,37941,37942,37943,37944,37945,37946,37947,37948,37949, | ||
| 1526 | 37951,37952,37953,37954,37955,37956,37957,37958,37959,37960,37961,37962,37963, | ||
| 1527 | 37964,37965,37966,37967,37968,37969,37970,37971,37972,37973,37974,37975,37976, | ||
| 1528 | 37977,37978,37979,37980,37981,37982,37983,37984,37985,37986,37987,37988,37989, | ||
| 1529 | 37990,37991,37992,37993,37994,37996,37997,37998,37999,38000,38001,38002,38003, | ||
| 1530 | 38004,38005,38006,38007,38008,38009,38010,38011,38012,38013,38014,38015,38016, | ||
| 1531 | 38017,38018,38019,38020,38033,38038,38040,38087,38095,38099,38100,38106,38118, | ||
| 1532 | 38139,38172,38176,29723,29722,29761,29788,29783,29781,29785,29815,29805,29822, | ||
| 1533 | 29852,29838,29824,29825,29831,29835,29854,29864,29865,29840,29863,29906,29882, | ||
| 1534 | 38890,38891,38892,26444,26451,26462,26440,26473,26533,26503,26474,26483,26520, | ||
| 1535 | 26535,26485,26536,26526,26541,26507,26487,26492,26608, | ||
| 1536 | 26633,26584,26634,26601,26544,26636,26585,26549,26586,26547,26589,26624,26563, | ||
| 1537 | 26552,26594,26638,26561,26621,26674,26675,26720,26721,26702,26722,26692,26724, | ||
| 1538 | 26755,26653,26709,26726,26689,26727,26688,26686,26698,26697,26665,26805,26767, | ||
| 1539 | 26740,26743,26771,26731,26818,26990,26876,26911,26912,26873,38183,38195,38205, | ||
| 1540 | 38211,38216,38219,38229,38234,38240,38254,38260,38261,38263,38264,38265,38266, | ||
| 1541 | 38267,38268,38269,38270,38272,38273,38274,38275,38276,38277,38278,38279,38280, | ||
| 1542 | 38281,38282,38283,38284,38285,38286,38287,38288,38289,38290,38291,38292,38293, | ||
| 1543 | 38294,38295,38296,38297,38298,38299,38300,38301,38302,38303,38304,38305,38306, | ||
| 1544 | 38307,38308,38309,38310,38311,38312,38313,38314,38315,38316,38317,38318,38319, | ||
| 1545 | 38320,38321,38322,38323,38324,38325,38326,38327,38328,38329,38330,38331,38332, | ||
| 1546 | 38333,38334,38335,38336,38337,38338,38339,38340,38341,38342,38343,38344,38345, | ||
| 1547 | 38346,38347,26916,26864,26891,26881,26967,26851,26896,26993,26937,26976,26946, | ||
| 1548 | 26973,27012,26987,27008,27032,27000,26932,27084,27015,27016,27086,27017,26982, | ||
| 1549 | 26979,27001,27035,27047,27067,27051,27053,27092,27057,27073,27082,27103,27029, | ||
| 1550 | 27104,27021,27135,27183,27117,27159,27160,27237,27122,27204,27198,27296,27216, | ||
| 1551 | 27227,27189,27278,27257,27197,27176,27224,27260,27281,27280,27305,27287,27307, | ||
| 1552 | 29495,29522,27521,27522,27527,27524,27538,27539,27533,27546,27547,27553,27562, | ||
| 1553 | 36715,36717,36721,36722,36723,36725,36726,36728,36727,36729,36730,36732,36734, | ||
| 1554 | 36737,36738,36740,36743,36747,38348,38349,38350,38351,38352,38353,38354,38355, | ||
| 1555 | 38356,38357,38358,38359,38360,38361,38362,38363,38364, | ||
| 1556 | 38365,38366,38367,38368,38369,38370,38371,38372,38373,38374,38375,38380,38399, | ||
| 1557 | 38407,38419,38424,38427,38430,38432,38435,38436,38437,38438,38439,38440,38441, | ||
| 1558 | 38443,38444,38445,38447,38448,38455,38456,38457,38458,38462,38465,38467,38474, | ||
| 1559 | 38478,38479,38481,38482,38483,38486,38487,38488,38489,38490,38492,38493,38494, | ||
| 1560 | 38496,38499,38501,38502,38507,38509,38510,38511,38512,38513,38515,38520,38521, | ||
| 1561 | 38522,38523,38524,38525,38526,38527,38528,38529,38530,38531,38532,38535,38537, | ||
| 1562 | 38538,36749,36750,36751,36760,36762,36558,25099,25111,25115,25119,25122,25121, | ||
| 1563 | 25125,25124,25132,33255,29935,29940,29951,29967,29969,29971,25908,26094,26095, | ||
| 1564 | 26096,26122,26137,26482,26115,26133,26112,28805,26359,26141,26164,26161,26166, | ||
| 1565 | 26165,32774,26207,26196,26177,26191,26198,26209,26199,26231,26244,26252,26279, | ||
| 1566 | 26269,26302,26331,26332,26342,26345,36146,36147,36150,36155,36157,36160,36165, | ||
| 1567 | 36166,36168,36169,36167,36173,36181,36185,35271,35274,35275,35276,35278,35279, | ||
| 1568 | 35280,35281,29294,29343,29277,29286,29295,29310,29311,29316,29323,29325,29327, | ||
| 1569 | 29330,25352,25394,25520,38540,38542,38545,38546,38547,38549,38550,38554,38555, | ||
| 1570 | 38557,38558,38559,38560,38561,38562,38563,38564,38565,38566,38568,38569,38570, | ||
| 1571 | 38571,38572,38573,38574,38575,38577,38578,38580,38581,38583,38584,38586,38587, | ||
| 1572 | 38591,38594,38595,38600,38602,38603,38608,38609,38611,38612,38614,38615,38616, | ||
| 1573 | 38617,38618,38619,38620,38621,38622,38623,38625,38626,38627,38628,38629,38630, | ||
| 1574 | 38631,38635,38636,38637,38638,38640,38641,38642,38644,38645,38648,38650,38651, | ||
| 1575 | 38652,38653,38655,38658,38659,38661,38666,38667,38668, | ||
| 1576 | 38672,38673,38674,38676,38677,38679,38680,38681,38682,38683,38685,38687,38688, | ||
| 1577 | 25663,25816,32772,27626,27635,27645,27637,27641,27653,27655,27654,27661,27669, | ||
| 1578 | 27672,27673,27674,27681,27689,27684,27690,27698,25909,25941,25963,29261,29266, | ||
| 1579 | 29270,29232,34402,21014,32927,32924,32915,32956,26378,32957,32945,32939,32941, | ||
| 1580 | 32948,32951,32999,33000,33001,33002,32987,32962,32964,32985,32973,32983,26384, | ||
| 1581 | 32989,33003,33009,33012,33005,33037,33038,33010,33020,26389,33042,35930,33078, | ||
| 1582 | 33054,33068,33048,33074,33096,33100,33107,33140,33113,33114,33137,33120,33129, | ||
| 1583 | 33148,33149,33133,33127,22605,23221,33160,33154,33169,28373,33187,33194,33228, | ||
| 1584 | 26406,33226,33211,38689,38690,38691,38692,38693,38694,38695,38696,38697,38699, | ||
| 1585 | 38700,38702,38703,38705,38707,38708,38709,38710,38711,38714,38715,38716,38717, | ||
| 1586 | 38719,38720,38721,38722,38723,38724,38725,38726,38727,38728,38729,38730,38731, | ||
| 1587 | 38732,38733,38734,38735,38736,38737,38740,38741,38743,38744,38746,38748,38749, | ||
| 1588 | 38751,38755,38756,38758,38759,38760,38762,38763,38764,38765,38766,38767,38768, | ||
| 1589 | 38769,38770,38773,38775,38776,38777,38778,38779,38781,38782,38783,38784,38785, | ||
| 1590 | 38786,38787,38788,38790,38791,38792,38793,38794,38796,38798,38799,38800,38803, | ||
| 1591 | 38805,38806,38807,38809,38810,38811,38812,38813,33217,33190,27428,27447,27449, | ||
| 1592 | 27459,27462,27481,39121,39122,39123,39125,39129,39130,27571,24384,27586,35315, | ||
| 1593 | 26000,40785,26003,26044,26054,26052,26051,26060,26062,26066,26070,28800,28828, | ||
| 1594 | 28822,28829,28859,28864,28855,28843,28849,28904,28874,28944,28947,28950,28975, | ||
| 1595 | 28977,29043,29020,29032,28997,29042,29002,29048,29050, | ||
| 1596 | 29080,29107,29109,29096,29088,29152,29140,29159,29177,29213,29224,28780,28952, | ||
| 1597 | 29030,29113,25150,25149,25155,25160,25161,31035,31040,31046,31049,31067,31068, | ||
| 1598 | 31059,31066,31074,31063,31072,31087,31079,31098,31109,31114,31130,31143,31155, | ||
| 1599 | 24529,24528,38814,38815,38817,38818,38820,38821,38822,38823,38824,38825,38826, | ||
| 1600 | 38828,38830,38832,38833,38835,38837,38838,38839,38840,38841,38842,38843,38844, | ||
| 1601 | 38845,38846,38847,38848,38849,38850,38851,38852,38853,38854,38855,38856,38857, | ||
| 1602 | 38858,38859,38860,38861,38862,38863,38864,38865,38866,38867,38868,38869,38870, | ||
| 1603 | 38871,38872,38873,38874,38875,38876,38877,38878,38879,38880,38881,38882,38883, | ||
| 1604 | 38884,38885,38888,38894,38895,38896,38897,38898,38900,38903,38904,38905,38906, | ||
| 1605 | 38907,38908,38909,38910,38911,38912,38913,38914,38915,38916,38917,38918,38919, | ||
| 1606 | 38920,38921,38922,38923,38924,38925,38926,24636,24669,24666,24679,24641,24665, | ||
| 1607 | 24675,24747,24838,24845,24925,25001,24989,25035,25041,25094,32896,32895,27795, | ||
| 1608 | 27894,28156,30710,30712,30720,30729,30743,30744,30737,26027,30765,30748,30749, | ||
| 1609 | 30777,30778,30779,30751,30780,30757,30764,30755,30761,30798,30829,30806,30807, | ||
| 1610 | 30758,30800,30791,30796,30826,30875,30867,30874,30855,30876,30881,30883,30898, | ||
| 1611 | 30905,30885,30932,30937,30921,30956,30962,30981,30964,30995,31012,31006,31028, | ||
| 1612 | 40859,40697,40699,40700,30449,30468,30477,30457,30471,30472,30490,30498,30489, | ||
| 1613 | 30509,30502,30517,30520,30544,30545,30535,30531,30554,30568,38927,38928,38929, | ||
| 1614 | 38930,38931,38932,38933,38934,38935,38936,38937,38938,38939,38940,38941,38942, | ||
| 1615 | 38943,38944,38945,38946,38947,38948,38949,38950,38951, | ||
| 1616 | 38952,38953,38954,38955,38956,38957,38958,38959,38960,38961,38962,38963,38964, | ||
| 1617 | 38965,38966,38967,38968,38969,38970,38971,38972,38973,38974,38975,38976,38977, | ||
| 1618 | 38978,38979,38980,38981,38982,38983,38984,38985,38986,38987,38988,38989,38990, | ||
| 1619 | 38991,38992,38993,38994,38995,38996,38997,38998,38999,39000,39001,39002,39003, | ||
| 1620 | 39004,39005,39006,39007,39008,39009,39010,39011,39012,39013,39014,39015,39016, | ||
| 1621 | 39017,39018,39019,39020,39021,39022,30562,30565,30591,30605,30589,30592,30604, | ||
| 1622 | 30609,30623,30624,30640,30645,30653,30010,30016,30030,30027,30024,30043,30066, | ||
| 1623 | 30073,30083,32600,32609,32607,35400,32616,32628,32625,32633,32641,32638,30413, | ||
| 1624 | 30437,34866,38021,38022,38023,38027,38026,38028,38029,38031,38032,38036,38039, | ||
| 1625 | 38037,38042,38043,38044,38051,38052,38059,38058,38061,38060,38063,38064,38066, | ||
| 1626 | 38068,38070,38071,38072,38073,38074,38076,38077,38079,38084,38088,38089,38090, | ||
| 1627 | 38091,38092,38093,38094,38096,38097,38098,38101,38102,38103,38105,38104,38107, | ||
| 1628 | 38110,38111,38112,38114,38116,38117,38119,38120,38122,39023,39024,39025,39026, | ||
| 1629 | 39027,39028,39051,39054,39058,39061,39065,39075,39080,39081,39082,39083,39084, | ||
| 1630 | 39085,39086,39087,39088,39089,39090,39091,39092,39093,39094,39095,39096,39097, | ||
| 1631 | 39098,39099,39100,39101,39102,39103,39104,39105,39106,39107,39108,39109,39110, | ||
| 1632 | 39111,39112,39113,39114,39115,39116,39117,39119,39120,39124,39126,39127,39131, | ||
| 1633 | 39132,39133,39136,39137,39138,39139,39140,39141,39142,39145,39146,39147,39148, | ||
| 1634 | 39149,39150,39151,39152,39153,39154,39155,39156,39157,39158,39159,39160,39161, | ||
| 1635 | 39162,39163,39164,39165,39166,39167,39168,39169,39170, | ||
| 1636 | 39171,39172,39173,39174,39175,38121,38123,38126,38127,38131,38132,38133,38135, | ||
| 1637 | 38137,38140,38141,38143,38147,38146,38150,38151,38153,38154,38157,38158,38159, | ||
| 1638 | 38162,38163,38164,38165,38166,38168,38171,38173,38174,38175,38178,38186,38187, | ||
| 1639 | 38185,38188,38193,38194,38196,38198,38199,38200,38204,38206,38207,38210,38197, | ||
| 1640 | 38212,38213,38214,38217,38220,38222,38223,38226,38227,38228,38230,38231,38232, | ||
| 1641 | 38233,38235,38238,38239,38237,38241,38242,38244,38245,38246,38247,38248,38249, | ||
| 1642 | 38250,38251,38252,38255,38257,38258,38259,38202,30695,30700,38601,31189,31213, | ||
| 1643 | 31203,31211,31238,23879,31235,31234,31262,31252,39176,39177,39178,39179,39180, | ||
| 1644 | 39182,39183,39185,39186,39187,39188,39189,39190,39191,39192,39193,39194,39195, | ||
| 1645 | 39196,39197,39198,39199,39200,39201,39202,39203,39204,39205,39206,39207,39208, | ||
| 1646 | 39209,39210,39211,39212,39213,39215,39216,39217,39218,39219,39220,39221,39222, | ||
| 1647 | 39223,39224,39225,39226,39227,39228,39229,39230,39231,39232,39233,39234,39235, | ||
| 1648 | 39236,39237,39238,39239,39240,39241,39242,39243,39244,39245,39246,39247,39248, | ||
| 1649 | 39249,39250,39251,39254,39255,39256,39257,39258,39259,39260,39261,39262,39263, | ||
| 1650 | 39264,39265,39266,39268,39270,39283,39288,39289,39291,39294,39298,39299,39305, | ||
| 1651 | 31289,31287,31313,40655,39333,31344,30344,30350,30355,30361,30372,29918,29920, | ||
| 1652 | 29996,40480,40482,40488,40489,40490,40491,40492,40498,40497,40502,40504,40503, | ||
| 1653 | 40505,40506,40510,40513,40514,40516,40518,40519,40520,40521,40523,40524,40526, | ||
| 1654 | 40529,40533,40535,40538,40539,40540,40542,40547,40550,40551,40552,40553,40554, | ||
| 1655 | 40555,40556,40561,40557,40563,30098,30100,30102,30112, | ||
| 1656 | 30109,30124,30115,30131,30132,30136,30148,30129,30128,30147,30146,30166,30157, | ||
| 1657 | 30179,30184,30182,30180,30187,30183,30211,30193,30204,30207,30224,30208,30213, | ||
| 1658 | 30220,30231,30218,30245,30232,30229,30233,39308,39310,39322,39323,39324,39325, | ||
| 1659 | 39326,39327,39328,39329,39330,39331,39332,39334,39335,39337,39338,39339,39340, | ||
| 1660 | 39341,39342,39343,39344,39345,39346,39347,39348,39349,39350,39351,39352,39353, | ||
| 1661 | 39354,39355,39356,39357,39358,39359,39360,39361,39362,39363,39364,39365,39366, | ||
| 1662 | 39367,39368,39369,39370,39371,39372,39373,39374,39375,39376,39377,39378,39379, | ||
| 1663 | 39380,39381,39382,39383,39384,39385,39386,39387,39388,39389,39390,39391,39392, | ||
| 1664 | 39393,39394,39395,39396,39397,39398,39399,39400,39401,39402,39403,39404,39405, | ||
| 1665 | 39406,39407,39408,39409,39410,39411,39412,39413,39414,39415,39416,39417,30235, | ||
| 1666 | 30268,30242,30240,30272,30253,30256,30271,30261,30275,30270,30259,30285,30302, | ||
| 1667 | 30292,30300,30294,30315,30319,32714,31462,31352,31353,31360,31366,31368,31381, | ||
| 1668 | 31398,31392,31404,31400,31405,31411,34916,34921,34930,34941,34943,34946,34978, | ||
| 1669 | 35014,34999,35004,35017,35042,35022,35043,35045,35057,35098,35068,35048,35070, | ||
| 1670 | 35056,35105,35097,35091,35099,35082,35124,35115,35126,35137,35174,35195,30091, | ||
| 1671 | 32997,30386,30388,30684,32786,32788,32790,32796,32800,32802,32805,32806,32807, | ||
| 1672 | 32809,32808,32817,32779,32821,32835,32838,32845,32850,32873,32881,35203,39032, | ||
| 1673 | 39040,39043,39418,39419,39420,39421,39422,39423,39424,39425,39426,39427,39428, | ||
| 1674 | 39429,39430,39431,39432,39433,39434,39435,39436,39437,39438,39439,39440,39441, | ||
| 1675 | 39442,39443,39444,39445,39446,39447,39448,39449,39450, | ||
| 1676 | 39451,39452,39453,39454,39455,39456,39457,39458,39459,39460,39461,39462,39463, | ||
| 1677 | 39464,39465,39466,39467,39468,39469,39470,39471,39472,39473,39474,39475,39476, | ||
| 1678 | 39477,39478,39479,39480,39481,39482,39483,39484,39485,39486,39487,39488,39489, | ||
| 1679 | 39490,39491,39492,39493,39494,39495,39496,39497,39498,39499,39500,39501,39502, | ||
| 1680 | 39503,39504,39505,39506,39507,39508,39509,39510,39511,39512,39513,39049,39052, | ||
| 1681 | 39053,39055,39060,39066,39067,39070,39071,39073,39074,39077,39078,34381,34388, | ||
| 1682 | 34412,34414,34431,34426,34428,34427,34472,34445,34443,34476,34461,34471,34467, | ||
| 1683 | 34474,34451,34473,34486,34500,34485,34510,34480,34490,34481,34479,34505,34511, | ||
| 1684 | 34484,34537,34545,34546,34541,34547,34512,34579,34526,34548,34527,34520,34513, | ||
| 1685 | 34563,34567,34552,34568,34570,34573,34569,34595,34619,34590,34597,34606,34586, | ||
| 1686 | 34622,34632,34612,34609,34601,34615,34623,34690,34594,34685,34686,34683,34656, | ||
| 1687 | 34672,34636,34670,34699,34643,34659,34684,34660,34649,34661,34707,34735,34728, | ||
| 1688 | 34770,39514,39515,39516,39517,39518,39519,39520,39521,39522,39523,39524,39525, | ||
| 1689 | 39526,39527,39528,39529,39530,39531,39538,39555,39561,39565,39566,39572,39573, | ||
| 1690 | 39577,39590,39593,39594,39595,39596,39597,39598,39599,39602,39603,39604,39605, | ||
| 1691 | 39609,39611,39613,39614,39615,39619,39620,39622,39623,39624,39625,39626,39629, | ||
| 1692 | 39630,39631,39632,39634,39636,39637,39638,39639,39641,39642,39643,39644,39645, | ||
| 1693 | 39646,39648,39650,39651,39652,39653,39655,39656,39657,39658,39660,39662,39664, | ||
| 1694 | 39665,39666,39667,39668,39669,39670,39671,39672,39674,39676,39677,39678,39679, | ||
| 1695 | 39680,39681,39682,39684,39685,39686,34758,34696,34693, | ||
| 1696 | 34733,34711,34691,34731,34789,34732,34741,34739,34763,34771,34749,34769,34752, | ||
| 1697 | 34762,34779,34794,34784,34798,34838,34835,34814,34826,34843,34849,34873,34876, | ||
| 1698 | 32566,32578,32580,32581,33296,31482,31485,31496,31491,31492,31509,31498,31531, | ||
| 1699 | 31503,31559,31544,31530,31513,31534,31537,31520,31525,31524,31539,31550,31518, | ||
| 1700 | 31576,31578,31557,31605,31564,31581,31584,31598,31611,31586,31602,31601,31632, | ||
| 1701 | 31654,31655,31672,31660,31645,31656,31621,31658,31644,31650,31659,31668,31697, | ||
| 1702 | 31681,31692,31709,31706,31717,31718,31722,31756,31742,31740,31759,31766,31755, | ||
| 1703 | 39687,39689,39690,39691,39692,39693,39694,39696,39697,39698,39700,39701,39702, | ||
| 1704 | 39703,39704,39705,39706,39707,39708,39709,39710,39712,39713,39714,39716,39717, | ||
| 1705 | 39718,39719,39720,39721,39722,39723,39724,39725,39726,39728,39729,39731,39732, | ||
| 1706 | 39733,39734,39735,39736,39737,39738,39741,39742,39743,39744,39750,39754,39755, | ||
| 1707 | 39756,39758,39760,39762,39763,39765,39766,39767,39768,39769,39770,39771,39772, | ||
| 1708 | 39773,39774,39775,39776,39777,39778,39779,39780,39781,39782,39783,39784,39785, | ||
| 1709 | 39786,39787,39788,39789,39790,39791,39792,39793,39794,39795,39796,39797,39798, | ||
| 1710 | 39799,39800,39801,39802,39803,31775,31786,31782,31800,31809,31808,33278,33281, | ||
| 1711 | 33282,33284,33260,34884,33313,33314,33315,33325,33327,33320,33323,33336,33339, | ||
| 1712 | 33331,33332,33342,33348,33353,33355,33359,33370,33375,33384,34942,34949,34952, | ||
| 1713 | 35032,35039,35166,32669,32671,32679,32687,32688,32690,31868,25929,31889,31901, | ||
| 1714 | 31900,31902,31906,31922,31932,31933,31937,31943,31948,31949,31944,31941,31959, | ||
| 1715 | 31976,33390,26280,32703,32718,32725,32741,32737,32742, | ||
| 1716 | 32745,32750,32755,31992,32119,32166,32174,32327,32411,40632,40628,36211,36228, | ||
| 1717 | 36244,36241,36273,36199,36205,35911,35913,37194,37200,37198,37199,37220,39804, | ||
| 1718 | 39805,39806,39807,39808,39809,39810,39811,39812,39813,39814,39815,39816,39817, | ||
| 1719 | 39818,39819,39820,39821,39822,39823,39824,39825,39826,39827,39828,39829,39830, | ||
| 1720 | 39831,39832,39833,39834,39835,39836,39837,39838,39839,39840,39841,39842,39843, | ||
| 1721 | 39844,39845,39846,39847,39848,39849,39850,39851,39852,39853,39854,39855,39856, | ||
| 1722 | 39857,39858,39859,39860,39861,39862,39863,39864,39865,39866,39867,39868,39869, | ||
| 1723 | 39870,39871,39872,39873,39874,39875,39876,39877,39878,39879,39880,39881,39882, | ||
| 1724 | 39883,39884,39885,39886,39887,39888,39889,39890,39891,39892,39893,39894,39895, | ||
| 1725 | 39896,39897,39898,39899,37218,37217,37232,37225,37231,37245,37246,37234,37236, | ||
| 1726 | 37241,37260,37253,37264,37261,37265,37282,37283,37290,37293,37294,37295,37301, | ||
| 1727 | 37300,37306,35925,40574,36280,36331,36357,36441,36457,36277,36287,36284,36282, | ||
| 1728 | 36292,36310,36311,36314,36318,36302,36303,36315,36294,36332,36343,36344,36323, | ||
| 1729 | 36345,36347,36324,36361,36349,36372,36381,36383,36396,36398,36387,36399,36410, | ||
| 1730 | 36416,36409,36405,36413,36401,36425,36417,36418,36433,36434,36426,36464,36470, | ||
| 1731 | 36476,36463,36468,36485,36495,36500,36496,36508,36510,35960,35970,35978,35973, | ||
| 1732 | 35992,35988,26011,35286,35294,35290,35292,39900,39901,39902,39903,39904,39905, | ||
| 1733 | 39906,39907,39908,39909,39910,39911,39912,39913,39914,39915,39916,39917,39918, | ||
| 1734 | 39919,39920,39921,39922,39923,39924,39925,39926,39927,39928,39929,39930,39931, | ||
| 1735 | 39932,39933,39934,39935,39936,39937,39938,39939,39940, | ||
| 1736 | 39941,39942,39943,39944,39945,39946,39947,39948,39949,39950,39951,39952,39953, | ||
| 1737 | 39954,39955,39956,39957,39958,39959,39960,39961,39962,39963,39964,39965,39966, | ||
| 1738 | 39967,39968,39969,39970,39971,39972,39973,39974,39975,39976,39977,39978,39979, | ||
| 1739 | 39980,39981,39982,39983,39984,39985,39986,39987,39988,39989,39990,39991,39992, | ||
| 1740 | 39993,39994,39995,35301,35307,35311,35390,35622,38739,38633,38643,38639,38662, | ||
| 1741 | 38657,38664,38671,38670,38698,38701,38704,38718,40832,40835,40837,40838,40839, | ||
| 1742 | 40840,40841,40842,40844,40702,40715,40717,38585,38588,38589,38606,38610,30655, | ||
| 1743 | 38624,37518,37550,37576,37694,37738,37834,37775,37950,37995,40063,40066,40069, | ||
| 1744 | 40070,40071,40072,31267,40075,40078,40080,40081,40082,40084,40085,40090,40091, | ||
| 1745 | 40094,40095,40096,40097,40098,40099,40101,40102,40103,40104,40105,40107,40109, | ||
| 1746 | 40110,40112,40113,40114,40115,40116,40117,40118,40119,40122,40123,40124,40125, | ||
| 1747 | 40132,40133,40134,40135,40138,40139,39996,39997,39998,39999,40000,40001,40002, | ||
| 1748 | 40003,40004,40005,40006,40007,40008,40009,40010,40011,40012,40013,40014,40015, | ||
| 1749 | 40016,40017,40018,40019,40020,40021,40022,40023,40024,40025,40026,40027,40028, | ||
| 1750 | 40029,40030,40031,40032,40033,40034,40035,40036,40037,40038,40039,40040,40041, | ||
| 1751 | 40042,40043,40044,40045,40046,40047,40048,40049,40050,40051,40052,40053,40054, | ||
| 1752 | 40055,40056,40057,40058,40059,40061,40062,40064,40067,40068,40073,40074,40076, | ||
| 1753 | 40079,40083,40086,40087,40088,40089,40093,40106,40108,40111,40121,40126,40127, | ||
| 1754 | 40128,40129,40130,40136,40137,40145,40146,40154,40155,40160,40161,40140,40141, | ||
| 1755 | 40142,40143,40144,40147,40148,40149,40151,40152,40153, | ||
| 1756 | 40156,40157,40159,40162,38780,38789,38801,38802,38804,38831,38827,38819,38834, | ||
| 1757 | 38836,39601,39600,39607,40536,39606,39610,39612,39617,39616,39621,39618,39627, | ||
| 1758 | 39628,39633,39749,39747,39751,39753,39752,39757,39761,39144,39181,39214,39253, | ||
| 1759 | 39252,39647,39649,39654,39663,39659,39675,39661,39673,39688,39695,39699,39711, | ||
| 1760 | 39715,40637,40638,32315,40578,40583,40584,40587,40594,37846,40605,40607,40667, | ||
| 1761 | 40668,40669,40672,40671,40674,40681,40679,40677,40682,40687,40738,40748,40751, | ||
| 1762 | 40761,40759,40765,40766,40772,40163,40164,40165,40166,40167,40168,40169,40170, | ||
| 1763 | 40171,40172,40173,40174,40175,40176,40177,40178,40179,40180,40181,40182,40183, | ||
| 1764 | 40184,40185,40186,40187,40188,40189,40190,40191,40192,40193,40194,40195,40196, | ||
| 1765 | 40197,40198,40199,40200,40201,40202,40203,40204,40205,40206,40207,40208,40209, | ||
| 1766 | 40210,40211,40212,40213,40214,40215,40216,40217,40218,40219,40220,40221,40222, | ||
| 1767 | 40223,40224,40225,40226,40227,40228,40229,40230,40231,40232,40233,40234,40235, | ||
| 1768 | 40236,40237,40238,40239,40240,40241,40242,40243,40244,40245,40246,40247,40248, | ||
| 1769 | 40249,40250,40251,40252,40253,40254,40255,40256,40257,40258,57908,57909,57910, | ||
| 1770 | 57911,57912,57913,57914,57915,57916,57917,57918,57919,57920,57921,57922,57923, | ||
| 1771 | 57924,57925,57926,57927,57928,57929,57930,57931,57932,57933,57934,57935,57936, | ||
| 1772 | 57937,57938,57939,57940,57941,57942,57943,57944,57945,57946,57947,57948,57949, | ||
| 1773 | 57950,57951,57952,57953,57954,57955,57956,57957,57958,57959,57960,57961,57962, | ||
| 1774 | 57963,57964,57965,57966,57967,57968,57969,57970,57971,57972,57973,57974,57975, | ||
| 1775 | 57976,57977,57978,57979,57980,57981,57982,57983,57984, | ||
| 1776 | 57985,57986,57987,57988,57989,57990,57991,57992,57993,57994,57995,57996,57997, | ||
| 1777 | 57998,57999,58000,58001,40259,40260,40261,40262,40263,40264,40265,40266,40267, | ||
| 1778 | 40268,40269,40270,40271,40272,40273,40274,40275,40276,40277,40278,40279,40280, | ||
| 1779 | 40281,40282,40283,40284,40285,40286,40287,40288,40289,40290,40291,40292,40293, | ||
| 1780 | 40294,40295,40296,40297,40298,40299,40300,40301,40302,40303,40304,40305,40306, | ||
| 1781 | 40307,40308,40309,40310,40311,40312,40313,40314,40315,40316,40317,40318,40319, | ||
| 1782 | 40320,40321,40322,40323,40324,40325,40326,40327,40328,40329,40330,40331,40332, | ||
| 1783 | 40333,40334,40335,40336,40337,40338,40339,40340,40341,40342,40343,40344,40345, | ||
| 1784 | 40346,40347,40348,40349,40350,40351,40352,40353,40354,58002,58003,58004,58005, | ||
| 1785 | 58006,58007,58008,58009,58010,58011,58012,58013,58014,58015,58016,58017,58018, | ||
| 1786 | 58019,58020,58021,58022,58023,58024,58025,58026,58027,58028,58029,58030,58031, | ||
| 1787 | 58032,58033,58034,58035,58036,58037,58038,58039,58040,58041,58042,58043,58044, | ||
| 1788 | 58045,58046,58047,58048,58049,58050,58051,58052,58053,58054,58055,58056,58057, | ||
| 1789 | 58058,58059,58060,58061,58062,58063,58064,58065,58066,58067,58068,58069,58070, | ||
| 1790 | 58071,58072,58073,58074,58075,58076,58077,58078,58079,58080,58081,58082,58083, | ||
| 1791 | 58084,58085,58086,58087,58088,58089,58090,58091,58092,58093,58094,58095,40355, | ||
| 1792 | 40356,40357,40358,40359,40360,40361,40362,40363,40364,40365,40366,40367,40368, | ||
| 1793 | 40369,40370,40371,40372,40373,40374,40375,40376,40377,40378,40379,40380,40381, | ||
| 1794 | 40382,40383,40384,40385,40386,40387,40388,40389,40390,40391,40392,40393,40394, | ||
| 1795 | 40395,40396,40397,40398,40399,40400,40401,40402,40403, | ||
| 1796 | 40404,40405,40406,40407,40408,40409,40410,40411,40412,40413,40414,40415,40416, | ||
| 1797 | 40417,40418,40419,40420,40421,40422,40423,40424,40425,40426,40427,40428,40429, | ||
| 1798 | 40430,40431,40432,40433,40434,40435,40436,40437,40438,40439,40440,40441,40442, | ||
| 1799 | 40443,40444,40445,40446,40447,40448,40449,40450,58096,58097,58098,58099,58100, | ||
| 1800 | 58101,58102,58103,58104,58105,58106,58107,58108,58109,58110,58111,58112,58113, | ||
| 1801 | 58114,58115,58116,58117,58118,58119,58120,58121,58122,58123,58124,58125,58126, | ||
| 1802 | 58127,58128,58129,58130,58131,58132,58133,58134,58135,58136,58137,58138,58139, | ||
| 1803 | 58140,58141,58142,58143,58144,58145,58146,58147,58148,58149,58150,58151,58152, | ||
| 1804 | 58153,58154,58155,58156,58157,58158,58159,58160,58161,58162,58163,58164,58165, | ||
| 1805 | 58166,58167,58168,58169,58170,58171,58172,58173,58174,58175,58176,58177,58178, | ||
| 1806 | 58179,58180,58181,58182,58183,58184,58185,58186,58187,58188,58189,40451,40452, | ||
| 1807 | 40453,40454,40455,40456,40457,40458,40459,40460,40461,40462,40463,40464,40465, | ||
| 1808 | 40466,40467,40468,40469,40470,40471,40472,40473,40474,40475,40476,40477,40478, | ||
| 1809 | 40484,40487,40494,40496,40500,40507,40508,40512,40525,40528,40530,40531,40532, | ||
| 1810 | 40534,40537,40541,40543,40544,40545,40546,40549,40558,40559,40562,40564,40565, | ||
| 1811 | 40566,40567,40568,40569,40570,40571,40572,40573,40576,40577,40579,40580,40581, | ||
| 1812 | 40582,40585,40586,40588,40589,40590,40591,40592,40593,40596,40597,40598,40599, | ||
| 1813 | 40600,40601,40602,40603,40604,40606,40608,40609,40610,40611,40612,40613,40615, | ||
| 1814 | 40616,40617,40618,58190,58191,58192,58193,58194,58195,58196,58197,58198,58199, | ||
| 1815 | 58200,58201,58202,58203,58204,58205,58206,58207,58208, | ||
| 1816 | 58209,58210,58211,58212,58213,58214,58215,58216,58217,58218,58219,58220,58221, | ||
| 1817 | 58222,58223,58224,58225,58226,58227,58228,58229,58230,58231,58232,58233,58234, | ||
| 1818 | 58235,58236,58237,58238,58239,58240,58241,58242,58243,58244,58245,58246,58247, | ||
| 1819 | 58248,58249,58250,58251,58252,58253,58254,58255,58256,58257,58258,58259,58260, | ||
| 1820 | 58261,58262,58263,58264,58265,58266,58267,58268,58269,58270,58271,58272,58273, | ||
| 1821 | 58274,58275,58276,58277,58278,58279,58280,58281,58282,58283,40619,40620,40621, | ||
| 1822 | 40622,40623,40624,40625,40626,40627,40629,40630,40631,40633,40634,40636,40639, | ||
| 1823 | 40640,40641,40642,40643,40645,40646,40647,40648,40650,40651,40652,40656,40658, | ||
| 1824 | 40659,40661,40662,40663,40665,40666,40670,40673,40675,40676,40678,40680,40683, | ||
| 1825 | 40684,40685,40686,40688,40689,40690,40691,40692,40693,40694,40695,40696,40698, | ||
| 1826 | 40701,40703,40704,40705,40706,40707,40708,40709,40710,40711,40712,40713,40714, | ||
| 1827 | 40716,40719,40721,40722,40724,40725,40726,40728,40730,40731,40732,40733,40734, | ||
| 1828 | 40735,40737,40739,40740,40741,40742,40743,40744,40745,40746,40747,40749,40750, | ||
| 1829 | 40752,40753,58284,58285,58286,58287,58288,58289,58290,58291,58292,58293,58294, | ||
| 1830 | 58295,58296,58297,58298,58299,58300,58301,58302,58303,58304,58305,58306,58307, | ||
| 1831 | 58308,58309,58310,58311,58312,58313,58314,58315,58316,58317,58318,58319,58320, | ||
| 1832 | 58321,58322,58323,58324,58325,58326,58327,58328,58329,58330,58331,58332,58333, | ||
| 1833 | 58334,58335,58336,58337,58338,58339,58340,58341,58342,58343,58344,58345,58346, | ||
| 1834 | 58347,58348,58349,58350,58351,58352,58353,58354,58355,58356,58357,58358,58359, | ||
| 1835 | 58360,58361,58362,58363,58364,58365,58366,58367,58368, | ||
| 1836 | 58369,58370,58371,58372,58373,58374,58375,58376,58377,40754,40755,40756,40757, | ||
| 1837 | 40758,40760,40762,40764,40767,40768,40769,40770,40771,40773,40774,40775,40776, | ||
| 1838 | 40777,40778,40779,40780,40781,40782,40783,40786,40787,40788,40789,40790,40791, | ||
| 1839 | 40792,40793,40794,40795,40796,40797,40798,40799,40800,40801,40802,40803,40804, | ||
| 1840 | 40805,40806,40807,40808,40809,40810,40811,40812,40813,40814,40815,40816,40817, | ||
| 1841 | 40818,40819,40820,40821,40822,40823,40824,40825,40826,40827,40828,40829,40830, | ||
| 1842 | 40833,40834,40845,40846,40847,40848,40849,40850,40851,40852,40853,40854,40855, | ||
| 1843 | 40856,40860,40861,40862,40865,40866,40867,40868,40869,63788,63865,63893,63975, | ||
| 1844 | 63985,58378,58379,58380,58381,58382,58383,58384,58385,58386,58387,58388,58389, | ||
| 1845 | 58390,58391,58392,58393,58394,58395,58396,58397,58398,58399,58400,58401,58402, | ||
| 1846 | 58403,58404,58405,58406,58407,58408,58409,58410,58411,58412,58413,58414,58415, | ||
| 1847 | 58416,58417,58418,58419,58420,58421,58422,58423,58424,58425,58426,58427,58428, | ||
| 1848 | 58429,58430,58431,58432,58433,58434,58435,58436,58437,58438,58439,58440,58441, | ||
| 1849 | 58442,58443,58444,58445,58446,58447,58448,58449,58450,58451,58452,58453,58454, | ||
| 1850 | 58455,58456,58457,58458,58459,58460,58461,58462,58463,58464,58465,58466,58467, | ||
| 1851 | 58468,58469,58470,58471,64012,64013,64014,64015,64017,64019,64020,64024,64031, | ||
| 1852 | 64032,64033,64035,64036,64039,64040,64041,11905,59414,59415,59416,11908,13427, | ||
| 1853 | 13383,11912,11915,59422,13726,13850,13838,11916,11927,14702,14616,59430,14799, | ||
| 1854 | 14815,14963,14800,59435,59436,15182,15470,15584,11943,59441,59442,11946,16470, | ||
| 1855 | 16735,11950,17207,11955,11958,11959,59451,17329,17324, | ||
| 1856 | 11963,17373,17622,18017,17996,59459,18211,18217,18300,18317,11978,18759,18810, | ||
| 1857 | 18813,18818,18819,18821,18822,18847,18843,18871,18870,59476,59477,19619,19615, | ||
| 1858 | 19616,19617,19575,19618,19731,19732,19733,19734,19735,19736,19737,19886,59492, | ||
| 1859 | 58472,58473,58474,58475,58476,58477,58478,58479,58480,58481,58482,58483,58484, | ||
| 1860 | 58485,58486,58487,58488,58489,58490,58491,58492,58493,58494,58495,58496,58497, | ||
| 1861 | 58498,58499,58500,58501,58502,58503,58504,58505,58506,58507,58508,58509,58510, | ||
| 1862 | 58511,58512,58513,58514,58515,58516,58517,58518,58519,58520,58521,58522,58523, | ||
| 1863 | 58524,58525,58526,58527,58528,58529,58530,58531,58532,58533,58534,58535,58536, | ||
| 1864 | 58537,58538,58539,58540,58541,58542,58543,58544,58545,58546,58547,58548,58549, | ||
| 1865 | 58550,58551,58552,58553,58554,58555,58556,58557,58558,58559,58560,58561,58562, | ||
| 1866 | 58563,58564,58565, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/hkscs.h created+390| ... | @@ -0,0 +1,390 @@ | ||
| 1 | 17392,19506,17923,17830,17784,29287,19831,17843,31921,19682,31941,15253,18230, | ||
| 2 | 18244,19527,19520,17087,13847,29522,28299,28882,19543,41809,18255,17882,19589, | ||
| 3 | 31852,19719,19108,18081,27427,29221,23124,6755,15878,16225,26189,22267,0, | ||
| 4 | 32149,22813,35769,15860,38708,31727,23515,7518,23204,13861,40624,23249,23479, | ||
| 5 | 23804,26478,34195,39237,29793,29853,14453,7507,13982,24609,16108,22750,15093, | ||
| 6 | 31484,40855,16737,35085,12778,2698,12894,17162,33924,40854,37935,18736,34323, | ||
| 7 | 22678,38730,37400,31184,31282,26208,27177,34973,29772,31685,26498,31276,21071, | ||
| 8 | 36934,13542,29636,23993,29894,40903,22451,18735,21580,16689,13966,22552,31346, | ||
| 9 | 31589,35727,18094,28296,16769,23961,31662,9404,40904,9409,9417,9420,40905, | ||
| 10 | 34052,13755,16564,40906,17633,44543,25281,28782,40907,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 11 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,12736,12737,12738,12739,12740,268,12741, | ||
| 12 | 209,205,12742,12743,203,8168,12744,202,12745,12746,12747,12748,270,12749, | ||
| 13 | 12750,256,193,461,192,274,201,282,200,332,211,465,210,56320,7870,56324,7872, | ||
| 14 | 202,257,225,462,224,593,275,233,283,232,299,237,464,236,333,243,466,242,363, | ||
| 15 | 250,468,249,470,472,474,476,252,56328,7871,56332,7873,234,609,9178,9179,0,0,0, | ||
| 16 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 17 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 18 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,41897,4421,0,25866,0,0,20029,28381, | ||
| 19 | 40270,37343,0,0,30517,25745,20250,20264,20392,20822,20852,20892,20964,21153, | ||
| 20 | 21160,21307,21326,21457,21464,22242,22768,22788,22791,22834,22836,23398,23454, | ||
| 21 | 23455,23706,24198,24635,25993,26622,26628,26725,27982,28860,30005,32420,32428, | ||
| 22 | 32442,32455,32463,32479,32518,32567,33402,33487,33647,35270,35774,35810,36710, | ||
| 23 | 36711,36718,29713,31996,32205,26950,31433,21031,0,0,0,0,37260,30904,37214, | ||
| 24 | 32956,0,36107,33014,2535,0,0,32927,40647,19661,40393,40460,19518,40438,28686, | ||
| 25 | 40458,41267,13761,0,28314,33342,29977,0,18705,39532,39567,40857,31111,33900, | ||
| 26 | 7626,1488,10982,20004,20097,20096,20103,20159,20203,20279,13388,20413,15944, | ||
| 27 | 20483,20616,13437,13459,13477,20870,22789,20955,20988,20997,20105,21113,21136, | ||
| 28 | 21287,13767,21417,13649,21424,13651,21442,21539,13677,13682,13953,21651,21667, | ||
| 29 | 21684,21689,21712,21743,21784,21795,21800,13720,21823,13733,13759,21975,13765, | ||
| 30 | 32132,21797,0,3138,3349,20779,21904,11462,14828,833,36422,19896,38117,16467, | ||
| 31 | 32958,30586,11320,14900,18389,33117,27122,19946,25821,3452,4020,3285,4340, | ||
| 32 | 25741,36478,3734,3083,3940,11433,33366,17619,0,3398,39501,33001,18420, | ||
| 33 | 20135,11458,39602,14951,38388,16365,13574,21191,38868,30920,11588,40302,38933, | ||
| 34 | 0,17369,24741,25780,21731,11596,11210,4215,14843,4207,26330,26390,31136,25834, | ||
| 35 | 20562,3139,36456,8609,35660,1841,0,18443,425,16378,22643,11661,0,17864,1276, | ||
| 36 | 24727,3916,3478,21881,16571,17338,0,19124,10854,4253,33194,39157,3484,25465, | ||
| 37 | 14846,10101,36288,22177,25724,15939,0,42497,3593,10959,11465,0,4296,14786, | ||
| 38 | 14738,14854,33435,13688,24137,8391,22098,3889,11442,38688,13500,27709,20027,0, | ||
| 39 | 0,30068,11915,8712,42587,36045,3706,3124,26652,32659,4303,10243,10553,13819, | ||
| 40 | 20963,3724,3981,3754,16275,3888,3399,4431,3660,0,3755,2985,3400,4288,4413, | ||
| 41 | 16377,9878,25650,4013,13300,30265,11214,3454,3455,11345,11349,14872,3736,4295, | ||
| 42 | 3886,42546,27472,36050,36249,36042,38314,21708,33476,21945,0,40643,39974, | ||
| 43 | 39606,30558,11758,28992,33133,33004,23580,25970,33076,14231,21343,32957,37302, | ||
| 44 | 3834,3599,3703,3835,13789,19947,13833,3286,22191,10165,4297,3600,3704,4216, | ||
| 45 | 4424,33287,5205,3705,20048,11684,23124,4125,4126,4341,4342,22428,3601,30356, | ||
| 46 | 33485,4021,3707,20862,14083,4022,4480,21208,41661,18906,6202,16759,33404, | ||
| 47 | 22681,21096,13850,22333,31666,23400,18432,19244,40743,18919,39967,39821,23412, | ||
| 48 | 12605,22011,13810,22153,20008,22786,7105,63608,38737,134,20059,20155,13630, | ||
| 49 | 23587,24401,24516,14586,25164,25909,27514,27701,27706,28780,29227,20012,29357, | ||
| 50 | 18665,32594,31035,31993,32595,25194,13505,0,25419,32770,32896,26130,26961, | ||
| 51 | 21341,34916,35265,30898,35744,36125,38021,38264,38271,38376, | ||
| 52 | 36367,38886,39029,39118,39134,39267,38928,40060,40479,40644,27503,63751,20023, | ||
| 53 | 135,38429,25143,38050,0,20539,28158,40051,40870,15817,34959,16718,28791,23797, | ||
| 54 | 19232,20941,13657,23856,24866,35378,36775,37366,29073,26393,29626,12929,41223, | ||
| 55 | 15499,6528,19216,30948,29698,20910,34575,16393,27235,41658,16931,34319,2671, | ||
| 56 | 31274,39239,35562,38741,28749,21284,8318,37876,30425,35299,40871,30685,20131, | ||
| 57 | 20464,20668,20015,20247,40872,21556,32139,22674,22736,7606,24210,24217,24514, | ||
| 58 | 10002,25995,13305,26905,27203,15459,27903,0,29184,17669,29580,16091,18963, | ||
| 59 | 23317,29881,35715,23716,22165,31379,31724,31939,32364,33528,34199,40873,34960, | ||
| 60 | 40874,36537,40875,36815,34143,39392,37409,40876,36281,5183,16497,17058,23066, | ||
| 61 | 0,0,0,39016,26475,17014,22333,0,34262,18811,33471,28941,19585,28020,23931, | ||
| 62 | 27413,28606,40877,40878,23446,40879,26343,32347,28247,31178,15752,17603,12886, | ||
| 63 | 10134,17306,17718,0,23765,15130,35577,23672,15634,13649,23928,40882,29015, | ||
| 64 | 17752,16620,7715,19575,14712,13386,420,27713,35532,20404,569,22975,33132, | ||
| 65 | 38998,39162,24379,2975,0,8641,35181,16642,18107,36985,16135,40883,41397,16632, | ||
| 66 | 14294,18167,27718,16764,34482,29695,17773,14548,21658,17761,17691,19849,19579, | ||
| 67 | 19830,17898,16328,19215,13921,17630,17597,16877,23870,23880,23894,15868,14351, | ||
| 68 | 23972,23993,14368,14392,24130,24253,24357,24451,14600,14612,14655,14669,24791, | ||
| 69 | 24893,23781,14729,25015,25017,25039,14776,25132,25232,25317,25368,14840,22193, | ||
| 70 | 14851,25570,25595,25607,25690,14923,25792,23829,22049,40863,14999,25990,15037, | ||
| 71 | 26111,26195,15090,26258,15138, | ||
| 72 | 26390,15170,26532,26624,15192,26698,26756,15218,15217,15227,26889,26947,29276, | ||
| 73 | 26980,27039,27013,15292,27094,15325,27237,27252,27249,27266,15340,27289,15346, | ||
| 74 | 27307,27317,27348,27382,27521,27585,27626,27765,27818,15563,27906,27910,27942, | ||
| 75 | 28033,15599,28068,28081,28181,28184,28201,28294,35264,28347,28386,28378,40831, | ||
| 76 | 28392,28393,28452,28468,15686,16193,28545,28606,15722,15733,29111,23705,15754, | ||
| 77 | 28716,15761,28752,28756,28783,28799,28809,805,17345,13809,3800,16087,22462, | ||
| 78 | 28371,28990,22496,13902,27042,35817,23412,31305,22753,38105,31333,31357,22956, | ||
| 79 | 31419,31408,31426,31427,29137,25741,16842,31450,31453,31466,16879,21682,23553, | ||
| 80 | 31499,31573,31529,21262,23806,31650,31599,33692,23476,27775,31696,33825,31634, | ||
| 81 | 0,23840,15789,23653,33938,31738,0,31797,23745,31812,31875,18562,31910,26237, | ||
| 82 | 17784,31945,31943,31974,31860,31987,31989,0,32359,17693,28228,32093,28374, | ||
| 83 | 29837,32137,32171,28981,32179,0,16471,24617,32228,15635,32245,6137,32229, | ||
| 84 | 33645,0,24865,24922,32366,32402,17195,37996,32295,32576,32577,32583,31030, | ||
| 85 | 25296,39393,32663,25425,32675,5729,104,17756,14182,17667,33594,32762,25737,0, | ||
| 86 | 32776,32797,0,32815,41095,27843,32827,32828,32865,10004,18825,26150,15843, | ||
| 87 | 26344,26405,32935,35400,33031,33050,22704,9974,27775,25752,20408,25831,5258, | ||
| 88 | 33304,6238,27219,19045,19093,17530,33321,2829,27218,15742,20473,5373,34018, | ||
| 89 | 33634,27402,18855,13616,6003,15864,33450,26907,63892,16859,34123,33488,33562, | ||
| 90 | 3606,6068,14017,12669,13658,33403,33506,33560,16011,28067,27397,27543,13774, | ||
| 91 | 15807,33565,21996,33669,17675,28069,33708, | ||
| 92 | 0,33747,13438,28372,27223,34138,13462,28226,12015,33880,23524,33905,15827, | ||
| 93 | 17636,27303,33866,15541,31064,0,27542,28279,28227,34014,0,33681,17568,33939, | ||
| 94 | 34020,23697,16960,23744,17731,34100,23282,28313,17703,34163,17686,26559,34326, | ||
| 95 | 34341,34363,34241,28808,34306,5506,28877,63922,17770,34344,13896,6306,21495, | ||
| 96 | 29594,34430,34673,41208,34798,11303,34737,34778,34831,22113,34412,26710,17935, | ||
| 97 | 34885,34886,30176,15801,30180,34910,34972,18011,34996,34997,25537,35013,30583, | ||
| 98 | 30479,35207,35210,0,0,35239,35260,35365,35303,31012,31421,35484,30611,37374, | ||
| 99 | 35472,31321,31465,31546,16271,18195,31544,29052,35596,35615,21552,21861,35647, | ||
| 100 | 35660,35661,35497,19066,35728,35739,35503,5855,17941,34895,35995,32084,32143, | ||
| 101 | 63956,14117,32083,36054,32152,32189,36114,36099,6416,36059,28764,36113,19657, | ||
| 102 | 16080,0,36265,32770,4116,18826,15228,33212,28940,31463,36525,36534,36547, | ||
| 103 | 37588,36633,36653,33637,33810,36773,37635,41631,2640,36787,18730,35294,34109, | ||
| 104 | 15803,24312,12898,36857,40980,34492,34049,8997,14720,28375,36919,34108,31422, | ||
| 105 | 36961,34156,34315,37032,34579,37060,34534,37038,0,37223,15088,37289,37316, | ||
| 106 | 31916,35123,7817,37390,27807,37441,37474,21945,0,35526,15515,35596,21979,3377, | ||
| 107 | 37676,37739,35553,35819,28815,23235,35554,35557,18789,37444,35820,35897,35839, | ||
| 108 | 37747,37979,36540,38277,38310,37926,38304,28662,17081,9850,34520,4732,15918, | ||
| 109 | 18911,27676,38523,38550,16748,38563,28373,25050,38582,30965,35552,38589,21452, | ||
| 110 | 18849,27832,628,25616,37039,37093,19153,6421,13066,38705,34370,38710,18959, | ||
| 111 | 17725,17797,19177,28789,23361,38683, | ||
| 112 | 0,37333,38743,23370,37355,38751,37925,20688,12471,12476,38793,38815,38833, | ||
| 113 | 38846,38848,38866,38880,21612,38894,29724,37939,0,38901,37917,31098,19153, | ||
| 114 | 38964,38963,38987,39014,15118,29045,15697,1584,16732,22278,39114,39095,39112, | ||
| 115 | 39111,19199,27943,5843,21936,39137,39142,39148,37752,39225,18985,19314,38999, | ||
| 116 | 39173,39413,39436,39483,39440,39512,22309,14020,37041,39893,39648,39650,39685, | ||
| 117 | 39668,19470,39700,39725,34304,20532,39732,27048,14531,12413,39760,39744,40254, | ||
| 118 | 23109,6243,39822,16971,39938,39935,39948,40552,40404,40887,41362,41387,41185, | ||
| 119 | 41251,41439,40318,40323,41268,40462,26760,40388,8539,41363,41504,6459,41523, | ||
| 120 | 40249,41145,41652,40592,40597,40606,40610,19764,40618,40623,17252,40641,15200, | ||
| 121 | 14821,15645,20274,14270,35883,40706,40712,19350,37924,28066,40727,0,40761, | ||
| 122 | 22175,22154,40773,39352,37003,38898,33919,40802,40809,31452,40846,29206,19390, | ||
| 123 | 18805,18875,29047,18936,17224,19025,29598,35802,6394,31135,35198,36406,37737, | ||
| 124 | 37875,35396,37612,37761,37835,35180,17593,29207,16107,30578,31299,28880,17523, | ||
| 125 | 17400,29054,6127,28835,6334,13721,16071,6277,21551,6136,14114,5883,6201,14049, | ||
| 126 | 6004,6353,24395,14115,5824,22363,18981,5118,4776,5062,5302,34051,13990,0, | ||
| 127 | 33877,18836,29029,15921,21852,16123,28754,17652,14062,39325,28454,26617,14131, | ||
| 128 | 15381,15847,22636,6434,26640,16471,14143,16609,16523,16655,27681,21707,22174, | ||
| 129 | 26289,22162,4063,2984,3597,37830,35603,37788,20216,20779,14361,17462,20156, | ||
| 130 | 1125,895,20299,20362,22097,23144,427,971,14745,778,1044,13365,20265,704,36531, | ||
| 131 | 629,35546,524,20120,20685, | ||
| 132 | 20749,20386,20227,18958,16010,20290,20526,20588,20609,20428,20453,20568,20732, | ||
| 133 | 0,0,0,0,28278,13717,15929,16063,28018,6276,16009,20904,20931,1504,17629,1187, | ||
| 134 | 1170,1169,36218,35484,1806,21081,21156,2163,21217,0,18042,29068,17292,3104, | ||
| 135 | 18860,4324,27089,3613,0,16094,29849,29716,29782,29592,19342,19132,16525,21456, | ||
| 136 | 13700,29199,16585,21940,837,21709,3014,22301,37469,38644,37734,22493,22413, | ||
| 137 | 22399,13886,22731,23193,35398,5882,5999,5904,23084,22968,37519,23166,23247, | ||
| 138 | 23058,22854,6643,6241,17045,14069,27909,29763,23073,24195,23169,35799,1043, | ||
| 139 | 37856,29836,4867,28933,18802,37896,35323,37821,14240,23582,23710,24158,24136, | ||
| 140 | 6550,6524,15086,24269,23375,6403,6404,14081,6304,14045,5886,14035,33066,35399, | ||
| 141 | 7610,13426,35240,24332,24334,6439,6059,23147,5947,23364,34324,30205,34912, | ||
| 142 | 24702,10336,9771,24539,16056,9647,9662,37000,28531,25024,62,70,9755,24985, | ||
| 143 | 24984,24693,11419,11527,18132,37197,25713,18021,11114,14889,11042,13392,39146, | ||
| 144 | 11896,25399,42075,25782,25393,25553,18915,11623,25252,11425,25659,25963,26994, | ||
| 145 | 15348,12430,12973,18825,12971,21773,13024,6361,37951,26318,12937,12723,15072, | ||
| 146 | 16784,21892,35618,21903,5884,21851,21541,30958,12547,6186,12852,13412,12815, | ||
| 147 | 12674,17097,26254,27940,26219,19347,26160,30832,7659,26211,13010,13025,26142, | ||
| 148 | 22642,14545,14394,14268,15257,14242,13310,29904,15254,26511,17962,26806,26654, | ||
| 149 | 15300,27326,14435,14293,17543,27187,27218,27337,27397,6418,25873,26776,27212, | ||
| 150 | 15319,27258,27479,16320,15514,37792,37618,35818,35531,37513,32798,35292,37991, | ||
| 151 | 28069,28427, | ||
| 152 | 18924,0,16255,15759,28164,16444,23101,28170,22599,27940,30786,28987,17178, | ||
| 153 | 17014,28913,29264,29319,29332,18319,18213,20857,19108,1515,29818,16120,13919, | ||
| 154 | 19018,18711,24545,16134,16049,19167,35875,16181,24743,16115,29900,29756,37767, | ||
| 155 | 29751,17567,28138,17745,30083,16227,19673,19718,16216,30037,30323,42438,15129, | ||
| 156 | 29800,35532,18859,18830,15099,15821,19022,16127,18885,18675,37370,22322,37698, | ||
| 157 | 35555,6244,20703,21025,20967,30584,12850,30478,30479,30587,18071,14209,14942, | ||
| 158 | 18672,29752,29851,16063,19130,19143,16584,19094,25006,37639,21889,30750,30861, | ||
| 159 | 30856,30930,29648,31065,30529,22243,16654,0,33942,31141,27181,16122,31290, | ||
| 160 | 31220,16750,5862,16690,37429,31217,3404,18828,665,15802,5998,13719,21867, | ||
| 161 | 13680,13994,468,3085,31458,23129,9973,23215,23196,23053,603,30960,23082,23494, | ||
| 162 | 31486,16889,31837,31853,16913,23475,24252,24230,31949,18937,6064,31886,31868, | ||
| 163 | 31918,27314,32220,32263,32211,32590,25185,24924,31560,32151,24194,17002,27509, | ||
| 164 | 2326,26582,78,13775,22468,25618,25592,18786,32733,31527,2092,23273,23875, | ||
| 165 | 31500,24078,39398,34373,39523,27164,13375,14818,18935,26029,39455,26016,33920, | ||
| 166 | 28967,27857,17642,33079,17410,32966,33033,33090,26548,39107,27202,33378,33381, | ||
| 167 | 27217,33875,28071,34320,29211,23174,16767,6208,23339,6305,23268,6360,34464, | ||
| 168 | 63932,15759,34861,29730,23042,34926,20293,34951,35007,35046,35173,35149,22147, | ||
| 169 | 35156,30597,30596,35829,35801,35740,35321,16045,33955,18165,18127,14322,35389, | ||
| 170 | 35356,37960,24397,37419,17028,26068,28969,28868,6213,40301,35999,36073,32220, | ||
| 171 | 22938,30659,23024,17262,14036,36394,36519,19465, | ||
| 172 | 36656,36682,17140,27736,28603,8993,18587,28537,28299,6106,39913,14005,18735, | ||
| 173 | 37051,0,21873,18694,37307,37892,35403,16482,35580,37927,35869,35899,34021, | ||
| 174 | 35371,38297,38311,38295,38294,36148,29765,16066,18687,19010,17386,16103,12837, | ||
| 175 | 38543,36583,36454,36453,16076,18925,19064,16366,29714,29803,16124,38721,37040, | ||
| 176 | 26695,18973,37011,22495,0,37736,35209,35878,35631,25534,37562,23313,35689, | ||
| 177 | 18748,29689,16923,38811,38769,39224,3878,24001,35781,19122,38943,38106,37622, | ||
| 178 | 38359,37349,17600,35664,19047,35684,39132,35397,16128,37418,18725,33812,39227, | ||
| 179 | 39245,31494,15869,39323,19311,39338,39516,35685,22728,27279,39457,23294,39471, | ||
| 180 | 39153,19344,39240,39356,19389,19351,37757,22642,4866,22562,18872,5352,30788, | ||
| 181 | 10015,15800,26821,15741,37976,14631,24912,10113,10603,24839,40015,40019,40059, | ||
| 182 | 39989,39952,39807,39887,40493,39839,41461,41214,40225,19630,16644,40472,19632, | ||
| 183 | 40204,41396,41197,41203,39215,40357,33981,28178,28639,27522,34300,17715,28068, | ||
| 184 | 28292,28144,33824,34286,28160,14295,24676,31202,13724,13888,18733,18910,15714, | ||
| 185 | 37851,37566,37704,703,30905,37495,37965,20452,13376,36964,21853,30781,30804, | ||
| 186 | 30902,30795,5975,12745,18753,13978,20338,28634,28633,0,28702,21524,16821, | ||
| 187 | 22459,22771,22410,40214,22487,28980,13487,16812,29163,27712,20375,0,6069, | ||
| 188 | 35401,24844,23246,23051,17084,17544,14124,19323,35324,37819,37816,6358,3869, | ||
| 189 | 33906,27840,5139,17146,11302,17345,22932,15799,26433,32168,24923,24740,18873, | ||
| 190 | 18827,35322,37605,29666,16105,29876,35683,6303,16097,19123,27352,29683,29691, | ||
| 191 | 16086,19006,19092,6105,19046,935,5156,18917,29768, | ||
| 192 | 18710,28837,18806,37508,29670,37727,1278,37681,35534,35350,37766,35815,21973, | ||
| 193 | 18741,35458,29035,18755,3327,22180,1562,3051,3256,21762,31172,6138,32254,5826, | ||
| 194 | 19024,6226,17710,37889,14090,35520,18861,22960,6335,6275,29828,23201,14050, | ||
| 195 | 15707,14000,37471,23161,35457,6242,37748,15565,2740,19094,14730,20724,15721, | ||
| 196 | 15692,5020,29045,17147,33304,28175,37092,17643,27991,32335,28775,27823,15574, | ||
| 197 | 16365,15917,28162,28428,15727,1013,30033,14012,13512,18048,16090,18545,22980, | ||
| 198 | 37486,18750,36673,35868,27584,22546,22472,14038,5202,28926,17250,19057,12259, | ||
| 199 | 4784,9149,26809,26983,5016,13541,31732,14047,35459,14294,13306,19615,27162, | ||
| 200 | 13997,27831,33854,17631,17614,27942,27985,27778,28638,28439,28937,33597,5946, | ||
| 201 | 33773,27776,28755,6107,22921,23170,6067,23137,23153,6405,16892,14125,23023, | ||
| 202 | 5948,14023,29070,37776,26266,17061,23150,23083,17043,27179,16121,30518,17499, | ||
| 203 | 17098,28957,16985,35297,20400,27944,23746,17614,32333,17341,27148,16982,4868, | ||
| 204 | 28838,28979,17385,15781,27871,63525,19023,32357,23019,23855,15859,24412,19037, | ||
| 205 | 6111,32164,33830,21637,15098,13056,532,22398,2261,1561,16357,8094,41654,28675, | ||
| 206 | 37211,23920,29583,31955,35417,37920,20424,32743,29389,29456,31476,29496,29497, | ||
| 207 | 22262,29505,29512,16041,31512,36972,29173,18674,29665,33270,16074,30476,16081, | ||
| 208 | 27810,22269,29721,29726,29727,16098,16112,16116,16122,29907,16142,16211,30018, | ||
| 209 | 30061,30066,30093,16252,30152,30172,16320,30285,16343,30324,16348,30330,20316, | ||
| 210 | 29064,22051,35200,22633,16413,30531,16441,26465,16453,13787,30616,16490,16495, | ||
| 211 | 23646,30654,30667,22770,30744,28857,30748, | ||
| 212 | 16552,30777,30791,30801,30822,33864,21813,31027,26627,31026,16643,16649,31121, | ||
| 213 | 31129,36795,31238,36796,16743,31377,16818,31420,33401,16836,31439,31451,16847, | ||
| 214 | 20001,31586,31596,31611,31762,31771,16992,17018,31867,31900,17036,31928,17044, | ||
| 215 | 31981,36755,28864,3279,32207,32212,32208,32253,32686,32692,29343,17303,32800, | ||
| 216 | 32805,31545,32814,32817,32852,15820,22452,28832,32951,33001,17389,33036,29482, | ||
| 217 | 33038,33042,30048,33044,17409,15161,33110,33113,33114,17427,22586,33148,33156, | ||
| 218 | 17445,33171,17453,33189,22511,33217,33252,33364,17551,33446,33398,33482,33496, | ||
| 219 | 33535,17584,33623,38505,27018,33797,28917,33892,24803,33928,17668,33982,34017, | ||
| 220 | 34040,34064,34104,34130,17723,34159,34160,34272,17783,34418,34450,34482,34543, | ||
| 221 | 38469,34699,17926,17943,34990,35071,35108,35143,35217,31079,35369,35384,35476, | ||
| 222 | 35508,35921,36052,36082,36124,18328,22623,36291,18413,20206,36410,21976,22356, | ||
| 223 | 36465,22005,36528,18487,36558,36578,36580,36589,36594,36791,36801,36810,36812, | ||
| 224 | 36915,39364,18605,39136,37395,18718,37416,37464,37483,37553,37550,37567,37603, | ||
| 225 | 37611,37619,37620,37629,37699,37764,37805,18757,18769,40639,37911,21249,37917, | ||
| 226 | 37933,37950,18794,37972,38009,38189,38306,18855,38388,38451,18917,26528,18980, | ||
| 227 | 38720,18997,38834,38850,22100,19172,24808,39097,19225,39153,22596,39182,39193, | ||
| 228 | 20916,39196,39223,39234,39261,39266,19312,39365,19357,39484,39695,31363,39785, | ||
| 229 | 39809,39901,39921,39924,19565,39968,14191,7106,40265,39994,40702,22096,40339, | ||
| 230 | 40381,40384,40444,38134,36790,40571,40620,40625,40637,40646,38108,40674,40689, | ||
| 231 | 40696,31432,40772,148,695,928,26906,38083,22956, | ||
| 232 | 1239,22592,38081,14265,1493,1557,1654,5818,22359,29043,2754,2765,3007,21610, | ||
| 233 | 63547,3019,21662,3067,3131,3155,3173,3196,24807,3213,22138,3253,3293,3309, | ||
| 234 | 3439,3506,3528,26965,39983,34725,3588,3598,3799,3984,3885,3699,23584,4028, | ||
| 235 | 24075,4188,4175,4214,26398,4219,4232,4246,13895,4287,4307,4399,4411,21348, | ||
| 236 | 33965,4835,4981,4918,35713,5495,5657,6083,6087,20088,28859,6189,6506,6701, | ||
| 237 | 6725,7210,7280,7340,7880,25283,7893,7957,29080,26709,8261,27113,14024,8828, | ||
| 238 | 9175,9210,10026,10353,10575,33533,10599,10643,10965,35237,10984,36768,11022, | ||
| 239 | 38840,11071,38983,39613,11340,0,11400,11447,23528,11528,11538,11703,11669, | ||
| 240 | 11842,12148,12236,12339,12390,13087,13278,24497,26184,26303,31353,13671,13811, | ||
| 241 | 0,18874,0,13850,14102,0,838,22709,26382,26904,15015,30295,24546,15889,16057, | ||
| 242 | 30206,8346,18640,19128,16665,35482,17134,17165,16443,17204,17302,19013,1482, | ||
| 243 | 20946,1553,22943,7848,15294,15615,17412,17622,22408,18036,14747,18223,34280, | ||
| 244 | 39369,14178,8643,35678,35662,0,18450,18683,18965,29193,19136,3192,22885,20133, | ||
| 245 | 20358,1913,36570,20524,21135,22335,29041,21145,21529,16202,19111,21948,21574, | ||
| 246 | 21614,27474,0,13427,21823,30258,21854,18200,21858,21862,22471,18751,22621, | ||
| 247 | 20582,13563,13260,0,22787,18300,35144,23214,23433,23558,7568,22433,29009,0, | ||
| 248 | 24834,31762,36950,25010,20378,35682,25602,25674,23899,27639,0,25732,6428, | ||
| 249 | 35562,18934,25736,16367,25874,19392,26047,26293,10011,37989,22497,24981,23079, | ||
| 250 | 63693,0,22201,17697,26364,20074,18740,38486,28047,27837,13848,35191, | ||
| 251 | 26521,26734,25617,26718,0,26823,31554,37056,2577,26918,0,26937,31301,0,27130, | ||
| 252 | 39462,27181,13919,25705,33,31107,27188,27483,23852,13593,0,27549,18128,27812, | ||
| 253 | 30011,34917,28078,22710,14108,9613,28747,29133,15444,29312,29317,37505,8570, | ||
| 254 | 29323,37680,29414,18896,27705,38047,29776,3832,34855,35061,10534,33907,6065, | ||
| 255 | 28344,18986,6176,14756,14009,0,0,17727,26294,40109,39076,35139,30668,30808, | ||
| 256 | 22230,16607,5642,14753,14127,33000,5061,29101,33638,31197,37288,0,19639,28847, | ||
| 257 | 35243,31229,31242,31499,32102,16762,31555,31102,32777,28597,41695,27139,33560, | ||
| 258 | 21410,28167,37823,26678,38749,33135,32803,27061,5101,12847,32840,23941,35888, | ||
| 259 | 32899,22293,38947,35145,23979,18824,26046,27093,21458,19109,16257,15377,26422, | ||
| 260 | 32912,33012,33070,8097,33103,33161,33199,33306,33542,33583,33674,13770,33896, | ||
| 261 | 34474,18682,25574,35158,30728,37461,35256,17394,35303,17375,35304,35654,35796, | ||
| 262 | 23032,35849,0,36805,37100,0,37136,37180,15863,37214,19146,36816,29327,22155, | ||
| 263 | 38119,38377,38320,38328,38706,39121,39241,39274,39363,39464,39694,40282,40347, | ||
| 264 | 32415,40696,40739,19620,38215,41619,29090,41727,19857,36882,42443,19868,3228, | ||
| 265 | 36798,21953,36794,9392,36793,19091,17673,32383,28502,27313,20202,13540,35628, | ||
| 266 | 30877,14138,36480,6133,32804,35692,35737,31294,26287,15851,30293,15543,22069, | ||
| 267 | 22870,20122,24193,25176,22207,3693,36366,23405,16008,19614,25566,0,6134,6267, | ||
| 268 | 25904,22061,23626,21530,21265,15814,40344,19581,22050,22046,32585,24280,22901, | ||
| 269 | 15680,34672,19996,4074,3401,14010,33047,40286,36120,30267,40005,30286,30649, | ||
| 270 | 37701,21554, | ||
| 271 | 33096,33527,22053,33074,33816,32957,21994,31074,22083,21526,3741,13774,22021, | ||
| 272 | 22001,26353,33506,13869,30004,22000,21946,21655,21874,3137,3222,24272,20808, | ||
| 273 | 3702,11362,3746,40619,32090,21982,4213,25245,38765,21652,36045,29174,37238, | ||
| 274 | 25596,25529,25598,21865,11075,40050,11955,20890,13535,3495,20903,21581,21790, | ||
| 275 | 21779,30310,36397,26762,30129,32950,34820,34694,35015,33206,33820,4289,17644, | ||
| 276 | 29444,18182,23440,33547,26771,22139,9972,32047,16803,32115,28368,29366,37232, | ||
| 277 | 4569,37384,15612,42665,3756,3833,29286,7330,18254,20418,32761,4075,16634, | ||
| 278 | 40029,25887,11680,18675,18400,40316,4076,3594,0,30115,4077,0,24648,4487,29091, | ||
| 279 | 32398,40272,19994,19972,13687,23309,27826,21351,13996,14812,21373,13989,17944, | ||
| 280 | 22682,19310,33325,21579,22442,23189,2425,0,14930,9317,29556,40620,19721,39917, | ||
| 281 | 15614,40752,19547,20393,38302,40926,33884,15798,29362,26547,14112,25390,32037, | ||
| 282 | 16119,15916,14890,36872,21196,15988,13946,17897,1166,30272,23280,3766,30842, | ||
| 283 | 32558,22695,16575,22140,39819,23924,30292,42036,40581,19681,0,14331,24857, | ||
| 284 | 12506,17394,0,22109,4777,22439,18787,40454,21044,28846,13741,0,40316,31830, | ||
| 285 | 39737,22494,5996,23635,25811,38096,25397,29028,34477,3368,27938,19170,3441,0, | ||
| 286 | 20990,7951,23950,38659,7633,40577,36940,31519,39682,23761,31651,25192,25397, | ||
| 287 | 39679,31695,39722,31870,0,31810,31878,39957,31740,39689,0,39963,18750,40794, | ||
| 288 | 21875,23491,20477,40600,20466,21088,15878,21201,22375,20566,22967,24082,38856, | ||
| 289 | 40363,36700,21609,38836,39232,38842,21292,24880,26924,21466,39946,40194,19515, | ||
| 290 | 38465,27008,20646, | ||
| 291 | 30022,5997,39386,21107,0,37209,38529,37212,0,37201,36503,25471,27939,27338, | ||
| 292 | 22033,37262,30074,25221,1020,29519,31856,23585,15613,0,18713,30422,39837, | ||
| 293 | 20010,3284,33726,34882,0,23626,27072,0,22394,21023,24053,20174,27697,498, | ||
| 294 | 20281,21660,21722,21146,36226,13822,0,13811,0,27474,37244,40869,39831,38958, | ||
| 295 | 39092,39610,40616,40580,29050,31508,0,27642,34840,32632,0,22048,42570,36471, | ||
| 296 | 40787,0,36308,36431,40476,36353,25218,33661,36392,36469,31443,19063,31294, | ||
| 297 | 30936,27882,35431,30215,35418,40742,27854,34774,30147,41650,30803,63552,36108, | ||
| 298 | 29410,29553,35629,29442,29937,36075,19131,34351,24506,34976,17591,0,6203, | ||
| 299 | 28165,0,35454,9499,0,24829,30311,39639,40260,37742,39823,34805,0,0,36087, | ||
| 300 | 29484,38689,39856,13782,29362,19463,31825,39242,24921,24921,19460,40598,24957, | ||
| 301 | 0,22367,24943,25254,25145,0,14940,25058,21418,13301,25444,26626,13778,23895, | ||
| 302 | 35778,36826,36409,0,20697,7494,30982,21298,38456,3899,16485,0,30718,0,31938, | ||
| 303 | 24346,31962,31277,32870,32867,32077,29957,29938,35220,33306,26380,32866,29830, | ||
| 304 | 32859,29936,33027,30500,35209,26572,30035,28369,34729,34766,33224,34700,35401, | ||
| 305 | 36013,35651,30507,29944,34010,13877,27058,36262,0,35241,0,28089,34753,16401, | ||
| 306 | 29927,15835,29046,24740,24988,15569,0,24695,0,32625,35629,0,24809,19326,21024, | ||
| 307 | 15384,15559,24279,30294,21809,6468,4862,39171,28124,28845,23745,25005,35343, | ||
| 308 | 13943,238,26694,20238,17762,23327,25420,40784,40614,25195,1351,37595,1503, | ||
| 309 | 16325,34124,17077,29679,20917,13897,18754,35300,37700,6619, | ||
| 310 | 33518,15560,30780,26436,25311,18739,35242,672,27571,4869,20395,9453,20488, | ||
| 311 | 27945,31364,13824,19121,9491,0,894,24484,896,839,28379,1055,0,20737,13434, | ||
| 312 | 20750,39020,14147,33814,18852,1159,20832,13236,20842,3071,8444,741,9520,1422, | ||
| 313 | 12851,6531,23426,34685,1459,15513,20914,20920,40244,20937,20943,20945,15580, | ||
| 314 | 20947,19110,20915,20962,21314,20973,33741,26942,14125,24443,21003,21030,21052, | ||
| 315 | 21173,21079,21140,21177,21189,31765,34114,21216,34317,27411,0,35550,21833, | ||
| 316 | 28377,16256,2388,16364,21299,0,3042,27851,5926,26651,29653,24650,16042,14540, | ||
| 317 | 5864,29149,17570,21357,21364,34475,21374,0,5526,5651,30694,21395,35483,21408, | ||
| 318 | 21419,21422,29607,22386,16217,29596,21441,21445,27721,20041,22526,21465,15019, | ||
| 319 | 2959,21472,16363,11683,21494,3191,21523,28793,21803,26199,27995,21613,27475, | ||
| 320 | 3444,21853,21647,21668,18342,5901,3805,15796,3405,35260,9880,21831,19693, | ||
| 321 | 21551,29719,21894,21929,0,6359,16442,17746,17461,26291,4276,22071,26317,12938, | ||
| 322 | 26276,26285,22093,22095,30961,22257,38791,21502,22272,22255,22253,35686,13859, | ||
| 323 | 4687,22342,16805,27758,28811,22338,14001,27774,22502,5142,22531,5204,17251, | ||
| 324 | 22566,19445,22620,22698,13665,22752,22748,4668,22779,23551,22339,41296,17016, | ||
| 325 | 37843,13729,22815,26790,14019,28249,5694,23076,21843,5778,34053,22985,3406, | ||
| 326 | 27777,27946,6108,23001,6139,6066,28070,28017,6184,5845,23033,28229,23211, | ||
| 327 | 23139,14054,18857,0,14088,23190,29797,23251,28577,9556,15749,6417,14130,5816, | ||
| 328 | 24195,21200,23414,25992,23420,31246,16388,18525,516,23509,24928,6708,22988, | ||
| 329 | 1445,23539, | ||
| 330 | 23453,19728,23557,6980,23571,29646,23572,7333,27432,23625,18653,23685,23785, | ||
| 331 | 23791,23947,7673,7735,23824,23832,23878,7844,23738,24023,33532,14381,18689, | ||
| 332 | 8265,8563,33415,14390,15298,24110,27274,0,24186,17596,3283,21414,20151,0, | ||
| 333 | 21416,6001,24073,24308,33922,24313,24315,14496,24316,26686,37915,24333,449, | ||
| 334 | 63636,15070,18606,4922,24378,26760,9168,0,9329,24419,38845,28270,24434,37696, | ||
| 335 | 35382,24487,23990,15711,21072,8042,28920,9832,37334,670,35369,24625,26245, | ||
| 336 | 6263,14691,15815,13881,22416,10164,31089,15936,24734,0,24755,18818,18831, | ||
| 337 | 31315,29860,20705,23200,24932,33828,24898,63654,28370,24961,20980,1622,24967, | ||
| 338 | 23466,16311,10335,25043,35741,39261,25040,14642,10624,10433,24611,24924,25886, | ||
| 339 | 25483,280,25285,6000,25301,11789,25452,18911,14871,25656,25592,5006,6140,0, | ||
| 340 | 28554,11830,38932,16524,22301,25825,25829,38011,14950,25658,14935,25933,28438, | ||
| 341 | 18984,18979,25989,25965,25951,12414,26037,18752,19255,26065,16600,6185,26080, | ||
| 342 | 26083,24543,13312,26136,12791,12792,26180,12708,12709,26187,3701,26215,20966, | ||
| 343 | 26227,0,7741,12849,34292,12744,21267,30661,10487,39332,26370,17308,18977, | ||
| 344 | 15147,27130,14274,0,26471,26466,16845,37101,26583,17641,26658,28240,37436, | ||
| 345 | 26625,13286,28064,26717,13423,27105,27147,35551,26995,26819,13773,26881,26880, | ||
| 346 | 15666,14849,13884,15232,26540,26977,35402,17148,26934,27032,15265,969,33635, | ||
| 347 | 20624,27129,13913,8490,27205,14083,27293,15347,26545,27336,37276,15373,27421, | ||
| 348 | 2339,24798,27445,27508,10189,28341,15067,949,6488,14144,21537,15194,27617, | ||
| 349 | 16124,27612,27703,9355,18673,27473, | ||
| 350 | 27738,33318,27769,15804,17605,15805,16804,18700,18688,15561,14053,15595,3378, | ||
| 351 | 39811,12793,9361,32655,26679,27941,28065,28139,28054,27996,28284,28420,18815, | ||
| 352 | 16517,28274,34099,28532,20935,0,0,33838,35617,0,15919,29779,16258,31180,28239, | ||
| 353 | 23185,12363,28664,14093,28573,15920,28410,5271,16445,17749,37872,28484,28508, | ||
| 354 | 15694,28532,37232,15675,28575,16708,28627,16529,16725,16441,16368,16308,16703, | ||
| 355 | 20959,16726,16727,16704,25053,28747,28798,28839,28801,28876,28885,28886,28895, | ||
| 356 | 16644,15848,29108,29078,17015,28971,28997,23176,29002,0,23708,17253,29007, | ||
| 357 | 37730,17089,28972,17498,18983,18978,29114,35816,28861,29198,37954,29205,22801, | ||
| 358 | 37955,29220,37697,22021,29230,29248,18804,26813,29269,29271,15957,12356,26637, | ||
| 359 | 28477,29314,0,29483,18467,34859,18669,34820,29480,29486,29647,29610,3130, | ||
| 360 | 27182,29641,29769,16866,5863,18980,26147,14021,18871,18829,18939,29687,29717, | ||
| 361 | 26883,18982,29753,1475,16087,0,10413,29792,36530,29767,29668,29814,33721, | ||
| 362 | 29804,14128,29812,37873,27180,29826,18771,19084,16735,19065,35727,23366,35843, | ||
| 363 | 6302,29896,6536,29966,0,29982,36569,6731,23511,36524,37765,30029,30026,30055, | ||
| 364 | 30062,20354,16132,19731,30094,29789,30110,30132,30210,30252,30289,30287,30319, | ||
| 365 | 30326,25589,30352,33263,14328,26897,26894,30369,30373,30391,30412,28575,33890, | ||
| 366 | 20637,20861,7708,30494,30502,30528,25775,21024,30552,12972,30639,35172,35176, | ||
| 367 | 5825,30708,0,4982,18962,26826,30895,30919,30931,38565,31022,21984,30935,31028, | ||
| 368 | 30897,30220,36792,34948,35627,24707,9756,31110,35072,26882,31104,22615,31133, | ||
| 369 | 31545,31036,31145,28202,28966, | ||
| 370 | 16040,31174,37133,31188,1312,17503,21007,47234,248,16384,43296,1102,0,0,2868, | ||
| 371 | 1,0,0,0,0,0,0,0,3072,64,0,0,0,1024,88,60,0,0,23680,56493,48115,17353,60910, | ||
| 372 | 4004,49446,30363,61426,64478,63482,12815,44868,61438,65277,24593,176,8448, | ||
| 373 | 33049,4128,43144,8544,9321,17408,50313,0,16387,53,33859,20785,26771,514,0,0,0, | ||
| 374 | 0,0,16384,256,44160,33380,35904,37025,20484,54368,53760,6186,26781,38709, | ||
| 375 | 55375,8440,33476,10268,30082,660,16440,41376,4293,19825,3524,47512,23390, | ||
| 376 | 17153,39327,30723,57888,2079,393,16585,775,39437,21136,20433,892,8450,49184, | ||
| 377 | 4974,46467,62939,30693,20368,39447,5942,12,47726,12041,21600,7680,26744,28706, | ||
| 378 | 40534,62245,46990,2839,59119,6007,7003,4289,36248,6162,53174,12545,6770,11355, | ||
| 379 | 49334,57888,23747,7042,56032,34254,16598,21673,53259,18447,16452,2320,16596, | ||
| 380 | 15278,7780,11076,2071,33414,6198,35232,40167,2139,900,55810,60560,34779,49029, | ||
| 381 | 44450,36509,39069,9504,70,40774,58239,51669,62596,19926,58118,6326,2322,0, | ||
| 382 | 1024,0,32,0,512,0,0,0,0,8192,0,0,0,0,0,0,8,36352,28280,16223,56702,63293, | ||
| 383 | 39932,44796,65490,27535,59377,47807,28334,61207,42972,46654,30645,37577,42455, | ||
| 384 | 19126,39790,33209,26445,21758,39921,65122,21103,14039,49150,17705,63873,26045, | ||
| 385 | 17062,57,16896,36704,37888,16448,45010,53719,219,39072,31666,20998,38944, | ||
| 386 | 51222,2365,0,1,0,2561,2226,128,0,34820,5152,19472,0,4,17569,16,321, | ||
| 387 | 2048,61504,20447,22582,62961,32949,26613,16512,20480,16718,33992,23040,55392, | ||
| 388 | 11009,20481,5793,16580,28402,44049,14624,49348,1800,2316,38552,39876,7184, | ||
| 389 | 27800,10886,422,4422,58733,50379,37568,8464,4630,29341,27124,5902,41514,62593, | ||
| 390 | 123,41992,36875,11280,14796,330,5872,2571,3136,59933,17420,17678,2, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/iconv.c created+685| ... | @@ -0,0 +1,685 @@ | ||
| 1 | #include <iconv.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <limits.h> | ||
| 7 | #include <stdint.h> | ||
| 8 | #include "locale_impl.h" | ||
| 9 | |||
| 10 | #define UTF_32BE 0300 | ||
| 11 | #define UTF_16LE 0301 | ||
| 12 | #define UTF_16BE 0302 | ||
| 13 | #define UTF_32LE 0303 | ||
| 14 | #define UCS2BE 0304 | ||
| 15 | #define UCS2LE 0305 | ||
| 16 | #define WCHAR_T 0306 | ||
| 17 | #define US_ASCII 0307 | ||
| 18 | #define UTF_8 0310 | ||
| 19 | #define UTF_16 0312 | ||
| 20 | #define UTF_32 0313 | ||
| 21 | #define UCS2 0314 | ||
| 22 | #define EUC_JP 0320 | ||
| 23 | #define SHIFT_JIS 0321 | ||
| 24 | #define ISO2022_JP 0322 | ||
| 25 | #define GB18030 0330 | ||
| 26 | #define GBK 0331 | ||
| 27 | #define GB2312 0332 | ||
| 28 | #define BIG5 0340 | ||
| 29 | #define EUC_KR 0350 | ||
| 30 | |||
| 31 | /* Definitions of charmaps. Each charmap consists of: | ||
| 32 | * 1. Empty-string-terminated list of null-terminated aliases. | ||
| 33 | * 2. Special type code or number of elided quads of entries. | ||
| 34 | * 3. Character table (size determined by field 2), consisting | ||
| 35 | * of 5 bytes for every 4 characters, interpreted as 10-bit | ||
| 36 | * indices into the legacy_chars table. */ | ||
| 37 | |||
| 38 | static const unsigned char charmaps[] = | ||
| 39 | "utf8\0char\0\0\310" | ||
| 40 | "wchart\0\0\306" | ||
| 41 | "ucs2be\0\0\304" | ||
| 42 | "ucs2le\0\0\305" | ||
| 43 | "utf16be\0\0\302" | ||
| 44 | "utf16le\0\0\301" | ||
| 45 | "ucs4be\0utf32be\0\0\300" | ||
| 46 | "ucs4le\0utf32le\0\0\303" | ||
| 47 | "ascii\0usascii\0iso646\0iso646us\0\0\307" | ||
| 48 | "utf16\0\0\312" | ||
| 49 | "ucs4\0utf32\0\0\313" | ||
| 50 | "ucs2\0\0\314" | ||
| 51 | "eucjp\0\0\320" | ||
| 52 | "shiftjis\0sjis\0\0\321" | ||
| 53 | "iso2022jp\0\0\322" | ||
| 54 | "gb18030\0\0\330" | ||
| 55 | "gbk\0\0\331" | ||
| 56 | "gb2312\0\0\332" | ||
| 57 | "big5\0bigfive\0cp950\0big5hkscs\0\0\340" | ||
| 58 | "euckr\0ksc5601\0ksx1001\0cp949\0\0\350" | ||
| 59 | #include "codepages.h" | ||
| 60 | ; | ||
| 61 | |||
| 62 | /* Table of characters that appear in legacy 8-bit codepages, | ||
| 63 | * limited to 1024 slots (10 bit indices). The first 256 entries | ||
| 64 | * are elided since those characters are obviously all included. */ | ||
| 65 | static const unsigned short legacy_chars[] = { | ||
| 66 | #include "legacychars.h" | ||
| 67 | }; | ||
| 68 | |||
| 69 | static const unsigned short jis0208[84][94] = { | ||
| 70 | #include "jis0208.h" | ||
| 71 | }; | ||
| 72 | |||
| 73 | static const unsigned short gb18030[126][190] = { | ||
| 74 | #include "gb18030.h" | ||
| 75 | }; | ||
| 76 | |||
| 77 | static const unsigned short big5[89][157] = { | ||
| 78 | #include "big5.h" | ||
| 79 | }; | ||
| 80 | |||
| 81 | static const unsigned short hkscs[] = { | ||
| 82 | #include "hkscs.h" | ||
| 83 | }; | ||
| 84 | |||
| 85 | static const unsigned short ksc[93][94] = { | ||
| 86 | #include "ksc.h" | ||
| 87 | }; | ||
| 88 | |||
| 89 | static const unsigned short rev_jis[] = { | ||
| 90 | #include "revjis.h" | ||
| 91 | }; | ||
| 92 | |||
| 93 | static int fuzzycmp(const unsigned char *a, const unsigned char *b) | ||
| 94 | { | ||
| 95 | 	for (; *a && *b; a++, b++) { | ||
| 96 | 		while (*a && (*a|32U)-'a'>26 && *a-'0'>10U) a++; | ||
| 97 | 		if ((*a|32U) != *b) return 1; | ||
| 98 | 	} | ||
| 99 | 	return *a != *b; | ||
| 100 | } | ||
| 101 | |||
| 102 | static size_t find_charmap(const void *name) | ||
| 103 | { | ||
| 104 | 	const unsigned char *s; | ||
| 105 | 	if (!*(char *)name) name=charmaps; /* "utf8" */ | ||
| 106 | 	for (s=charmaps; *s; ) { | ||
| 107 | 		if (!fuzzycmp(name, s)) { | ||
| 108 | 			for (; *s; s+=strlen((void *)s)+1); | ||
| 109 | 			return s+1-charmaps; | ||
| 110 | 		} | ||
| 111 | 		s += strlen((void *)s)+1; | ||
| 112 | 		if (!*s) { | ||
| 113 | 			if (s[1] > 0200) s+=2; | ||
| 114 | 			else s+=2+(64U-s[1])*5; | ||
| 115 | 		} | ||
| 116 | 	} | ||
| 117 | 	return -1; | ||
| 118 | } | ||
| 119 | |||
| 120 | struct stateful_cd { | ||
| 121 | 	iconv_t base_cd; | ||
| 122 | 	unsigned state; | ||
| 123 | }; | ||
| 124 | |||
| 125 | static iconv_t combine_to_from(size_t t, size_t f) | ||
| 126 | { | ||
| 127 | 	return (void *)(f<<16 | t<<1 | 1); | ||
| 128 | } | ||
| 129 | |||
| 130 | static size_t extract_from(iconv_t cd) | ||
| 131 | { | ||
| 132 | 	return (size_t)cd >> 16; | ||
| 133 | } | ||
| 134 | |||
| 135 | static size_t extract_to(iconv_t cd) | ||
| 136 | { | ||
| 137 | 	return (size_t)cd >> 1 & 0x7fff; | ||
| 138 | } | ||
| 139 | |||
| 140 | iconv_t iconv_open(const char *to, const char *from) | ||
| 141 | { | ||
| 142 | 	size_t f, t; | ||
| 143 | 	struct stateful_cd *scd; | ||
| 144 | |||
| 145 | 	if ((t = find_charmap(to))==-1 | ||
| 146 | 	 || (f = find_charmap(from))==-1 | ||
| 147 | 	 || (charmaps[t] >= 0330)) { | ||
| 148 | 		errno = EINVAL; | ||
| 149 | 		return (iconv_t)-1; | ||
| 150 | 	} | ||
| 151 | 	iconv_t cd = combine_to_from(t, f); | ||
| 152 | |||
| 153 | 	switch (charmaps[f]) { | ||
| 154 | 	case UTF_16: | ||
| 155 | 	case UTF_32: | ||
| 156 | 	case UCS2: | ||
| 157 | 	case ISO2022_JP: | ||
| 158 | 		scd = malloc(sizeof *scd); | ||
| 159 | 		if (!scd) return (iconv_t)-1; | ||
| 160 | 		scd->base_cd = cd; | ||
| 161 | 		scd->state = 0; | ||
| 162 | 		cd = (iconv_t)scd; | ||
| 163 | 	} | ||
| 164 | |||
| 165 | 	return cd; | ||
| 166 | } | ||
| 167 | |||
| 168 | static unsigned get_16(const unsigned char *s, int e) | ||
| 169 | { | ||
| 170 | 	e &= 1; | ||
| 171 | 	return s[e]<<8 | s[1-e]; | ||
| 172 | } | ||
| 173 | |||
| 174 | static void put_16(unsigned char *s, unsigned c, int e) | ||
| 175 | { | ||
| 176 | 	e &= 1; | ||
| 177 | 	s[e] = c>>8; | ||
| 178 | 	s[1-e] = c; | ||
| 179 | } | ||
| 180 | |||
| 181 | static unsigned get_32(const unsigned char *s, int e) | ||
| 182 | { | ||
| 183 | 	e &= 3; | ||
| 184 | 	return s[e]+0U<<24 | s[e^1]<<16 | s[e^2]<<8 | s[e^3]; | ||
| 185 | } | ||
| 186 | |||
| 187 | static void put_32(unsigned char *s, unsigned c, int e) | ||
| 188 | { | ||
| 189 | 	e &= 3; | ||
| 190 | 	s[e^0] = c>>24; | ||
| 191 | 	s[e^1] = c>>16; | ||
| 192 | 	s[e^2] = c>>8; | ||
| 193 | 	s[e^3] = c; | ||
| 194 | } | ||
| 195 | |||
| 196 | /* Adapt as needed */ | ||
| 197 | #define mbrtowc_utf8 mbrtowc | ||
| 198 | #define wctomb_utf8 wctomb | ||
| 199 | |||
| 200 | static unsigned legacy_map(const unsigned char *map, unsigned c) | ||
| 201 | { | ||
| 202 | 	if (c < 4*map[-1]) return c; | ||
| 203 | 	unsigned x = c - 4*map[-1]; | ||
| 204 | 	x = map[x*5/4]>>2*x%8 | map[x*5/4+1]<<8-2*x%8 & 1023; | ||
| 205 | 	return x < 256 ? x : legacy_chars[x-256]; | ||
| 206 | } | ||
| 207 | |||
| 208 | static unsigned uni_to_jis(unsigned c) | ||
| 209 | { | ||
| 210 | 	unsigned nel = sizeof rev_jis / sizeof *rev_jis; | ||
| 211 | 	unsigned d, j, i, b = 0; | ||
| 212 | 	for (;;) { | ||
| 213 | 		i = nel/2; | ||
| 214 | 		j = rev_jis[b+i]; | ||
| 215 | 		d = jis0208[j/256][j%256]; | ||
| 216 | 		if (d==c) return j + 0x2121; | ||
| 217 | 		else if (nel == 1) return 0; | ||
| 218 | 		else if (c < d) | ||
| 219 | 			nel /= 2; | ||
| 220 | 		else { | ||
| 221 | 			b += i; | ||
| 222 | 			nel -= nel/2; | ||
| 223 | 		} | ||
| 224 | 	} | ||
| 225 | } | ||
| 226 | |||
| 227 | size_t iconv(iconv_t cd, char **restrict in, size_t *restrict inb, char **restrict out, size_t *restrict outb) | ||
| 228 | { | ||
| 229 | 	size_t x=0; | ||
| 230 | 	struct stateful_cd *scd=0; | ||
| 231 | 	if (!((size_t)cd & 1)) { | ||
| 232 | 		scd = (void *)cd; | ||
| 233 | 		cd = scd->base_cd; | ||
| 234 | 	} | ||
| 235 | 	unsigned to = extract_to(cd); | ||
| 236 | 	unsigned from = extract_from(cd); | ||
| 237 | 	const unsigned char *map = charmaps+from+1; | ||
| 238 | 	const unsigned char *tomap = charmaps+to+1; | ||
| 239 | 	mbstate_t st = {0}; | ||
| 240 | 	wchar_t wc; | ||
| 241 | 	unsigned c, d; | ||
| 242 | 	size_t k, l; | ||
| 243 | 	int err; | ||
| 244 | 	unsigned char type = map[-1]; | ||
| 245 | 	unsigned char totype = tomap[-1]; | ||
| 246 | 	locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | ||
| 247 | |||
| 248 | 	if (!in || !*in || !*inb) return 0; | ||
| 249 | |||
| 250 | 	*ploc = UTF8_LOCALE; | ||
| 251 | |||
| 252 | 	for (; *inb; *in+=l, *inb-=l) { | ||
| 253 | 		c = *(unsigned char *)*in; | ||
| 254 | 		l = 1; | ||
| 255 | |||
| 256 | 		switch (type) { | ||
| 257 | 		case UTF_8: | ||
| 258 | 			if (c < 128) break; | ||
| 259 | 			l = mbrtowc_utf8(&wc, *in, *inb, &st); | ||
| 260 | 			if (l == (size_t)-1) goto ilseq; | ||
| 261 | 			if (l == (size_t)-2) goto starved; | ||
| 262 | 			c = wc; | ||
| 263 | 			break; | ||
| 264 | 		case US_ASCII: | ||
| 265 | 			if (c >= 128) goto ilseq; | ||
| 266 | 			break; | ||
| 267 | 		case WCHAR_T: | ||
| 268 | 			l = sizeof(wchar_t); | ||
| 269 | 			if (*inb < l) goto starved; | ||
| 270 | 			c = *(wchar_t *)*in; | ||
| 271 | 			if (0) { | ||
| 272 | 		case UTF_32BE: | ||
| 273 | 		case UTF_32LE: | ||
| 274 | 			l = 4; | ||
| 275 | 			if (*inb < 4) goto starved; | ||
| 276 | 			c = get_32((void *)*in, type); | ||
| 277 | 			} | ||
| 278 | 			if (c-0xd800u < 0x800u || c >= 0x110000u) goto ilseq; | ||
| 279 | 			break; | ||
| 280 | 		case UCS2BE: | ||
| 281 | 		case UCS2LE: | ||
| 282 | 		case UTF_16BE: | ||
| 283 | 		case UTF_16LE: | ||
| 284 | 			l = 2; | ||
| 285 | 			if (*inb < 2) goto starved; | ||
| 286 | 			c = get_16((void *)*in, type); | ||
| 287 | 			if ((unsigned)(c-0xdc00) < 0x400) goto ilseq; | ||
| 288 | 			if ((unsigned)(c-0xd800) < 0x400) { | ||
| 289 | 				if (type-UCS2BE < 2U) goto ilseq; | ||
| 290 | 				l = 4; | ||
| 291 | 				if (*inb < 4) goto starved; | ||
| 292 | 				d = get_16((void *)(*in + 2), type); | ||
| 293 | 				if ((unsigned)(d-0xdc00) >= 0x400) goto ilseq; | ||
| 294 | 				c = ((c-0xd7c0)<<10) + (d-0xdc00); | ||
| 295 | 			} | ||
| 296 | 			break; | ||
| 297 | 		case UCS2: | ||
| 298 | 		case UTF_16: | ||
| 299 | 			l = 0; | ||
| 300 | 			if (!scd->state) { | ||
| 301 | 				if (*inb < 2) goto starved; | ||
| 302 | 				c = get_16((void *)*in, 0); | ||
| 303 | 				scd->state = type==UCS2 | ||
| 304 | 					? c==0xfffe ? UCS2LE : UCS2BE | ||
| 305 | 					: c==0xfffe ? UTF_16LE : UTF_16BE; | ||
| 306 | 				if (c == 0xfffe || c == 0xfeff) | ||
| 307 | 					l = 2; | ||
| 308 | 			} | ||
| 309 | 			type = scd->state; | ||
| 310 | 			continue; | ||
| 311 | 		case UTF_32: | ||
| 312 | 			l = 0; | ||
| 313 | 			if (!scd->state) { | ||
| 314 | 				if (*inb < 4) goto starved; | ||
| 315 | 				c = get_32((void *)*in, 0); | ||
| 316 | 				scd->state = c==0xfffe0000 ? UTF_32LE : UTF_32BE; | ||
| 317 | 				if (c == 0xfffe0000 || c == 0xfeff) | ||
| 318 | 					l = 4; | ||
| 319 | 			} | ||
| 320 | 			type = scd->state; | ||
| 321 | 			continue; | ||
| 322 | 		case SHIFT_JIS: | ||
| 323 | 			if (c < 128) break; | ||
| 324 | 			if (c-0xa1 <= 0xdf-0xa1) { | ||
| 325 | 				c += 0xff61-0xa1; | ||
| 326 | 				break; | ||
| 327 | 			} | ||
| 328 | 			l = 2; | ||
| 329 | 			if (*inb < 2) goto starved; | ||
| 330 | 			d = *((unsigned char *)*in + 1); | ||
| 331 | 			if (c-129 <= 159-129) c -= 129; | ||
| 332 | 			else if (c-224 <= 239-224) c -= 193; | ||
| 333 | 			else goto ilseq; | ||
| 334 | 			c *= 2; | ||
| 335 | 			if (d-64 <= 158-64) { | ||
| 336 | 				if (d==127) goto ilseq; | ||
| 337 | 				if (d>127) d--; | ||
| 338 | 				d -= 64; | ||
| 339 | 			} else if (d-159 <= 252-159) { | ||
| 340 | 				c++; | ||
| 341 | 				d -= 159; | ||
| 342 | 			} | ||
| 343 | 			c = jis0208[c][d]; | ||
| 344 | 			if (!c) goto ilseq; | ||
| 345 | 			break; | ||
| 346 | 		case EUC_JP: | ||
| 347 | 			if (c < 128) break; | ||
| 348 | 			l = 2; | ||
| 349 | 			if (*inb < 2) goto starved; | ||
| 350 | 			d = *((unsigned char *)*in + 1); | ||
| 351 | 			if (c==0x8e) { | ||
| 352 | 				c = d; | ||
| 353 | 				if (c-0xa1 > 0xdf-0xa1) goto ilseq; | ||
| 354 | 				c += 0xff61 - 0xa1; | ||
| 355 | 				break; | ||
| 356 | 			} | ||
| 357 | 			c -= 0xa1; | ||
| 358 | 			d -= 0xa1; | ||
| 359 | 			if (c >= 84 || d >= 94) goto ilseq; | ||
| 360 | 			c = jis0208[c][d]; | ||
| 361 | 			if (!c) goto ilseq; | ||
| 362 | 			break; | ||
| 363 | 		case ISO2022_JP: | ||
| 364 | 			if (c >= 128) goto ilseq; | ||
| 365 | 			if (c == '\033') { | ||
| 366 | 				l = 3; | ||
| 367 | 				if (*inb < 3) goto starved; | ||
| 368 | 				c = *((unsigned char *)*in + 1); | ||
| 369 | 				d = *((unsigned char *)*in + 2); | ||
| 370 | 				if (c != '(' && c != '$') goto ilseq; | ||
| 371 | 				switch (128*(c=='$') + d) { | ||
| 372 | 				case 'B': scd->state=0; continue; | ||
| 373 | 				case 'J': scd->state=1; continue; | ||
| 374 | 				case 'I': scd->state=4; continue; | ||
| 375 | 				case 128+'@': scd->state=2; continue; | ||
| 376 | 				case 128+'B': scd->state=3; continue; | ||
| 377 | 				} | ||
| 378 | 				goto ilseq; | ||
| 379 | 			} | ||
| 380 | 			switch (scd->state) { | ||
| 381 | 			case 1: | ||
| 382 | 				if (c=='\\') c = 0xa5; | ||
| 383 | 				if (c=='~') c = 0x203e; | ||
| 384 | 				break; | ||
| 385 | 			case 2: | ||
| 386 | 			case 3: | ||
| 387 | 				l = 2; | ||
| 388 | 				if (*inb < 2) goto starved; | ||
| 389 | 				d = *((unsigned char *)*in + 1); | ||
| 390 | 				c -= 0x21; | ||
| 391 | 				d -= 0x21; | ||
| 392 | 				if (c >= 84 || d >= 94) goto ilseq; | ||
| 393 | 				c = jis0208[c][d]; | ||
| 394 | 				if (!c) goto ilseq; | ||
| 395 | 				break; | ||
| 396 | 			case 4: | ||
| 397 | 				if (c-0x60 < 0x1f) goto ilseq; | ||
| 398 | 				if (c-0x21 < 0x5e) c += 0xff61-0x21; | ||
| 399 | 				break; | ||
| 400 | 			} | ||
| 401 | 			break; | ||
| 402 | 		case GB2312: | ||
| 403 | 			if (c < 128) break; | ||
| 404 | 			if (c < 0xa1) goto ilseq; | ||
| 405 | 		case GBK: | ||
| 406 | 		case GB18030: | ||
| 407 | 			if (c < 128) break; | ||
| 408 | 			c -= 0x81; | ||
| 409 | 			if (c >= 126) goto ilseq; | ||
| 410 | 			l = 2; | ||
| 411 | 			if (*inb < 2) goto starved; | ||
| 412 | 			d = *((unsigned char *)*in + 1); | ||
| 413 | 			if (d < 0xa1 && type == GB2312) goto ilseq; | ||
| 414 | 			if (d-0x40>=191 || d==127) { | ||
| 415 | 				if (d-'0'>9 || type != GB18030) | ||
| 416 | 					goto ilseq; | ||
| 417 | 				l = 4; | ||
| 418 | 				if (*inb < 4) goto starved; | ||
| 419 | 				c = (10*c + d-'0') * 1260; | ||
| 420 | 				d = *((unsigned char *)*in + 2); | ||
| 421 | 				if (d-0x81>126) goto ilseq; | ||
| 422 | 				c += 10*(d-0x81); | ||
| 423 | 				d = *((unsigned char *)*in + 3); | ||
| 424 | 				if (d-'0'>9) goto ilseq; | ||
| 425 | 				c += d-'0'; | ||
| 426 | 				c += 128; | ||
| 427 | 				for (d=0; d<=c; ) { | ||
| 428 | 					k = 0; | ||
| 429 | 					for (int i=0; i<126; i++) | ||
| 430 | 						for (int j=0; j<190; j++) | ||
| 431 | 							if (gb18030[i][j]-d <= c-d) | ||
| 432 | 								k++; | ||
| 433 | 					d = c+1; | ||
| 434 | 					c += k; | ||
| 435 | 				} | ||
| 436 | 				break; | ||
| 437 | 			} | ||
| 438 | 			d -= 0x40; | ||
| 439 | 			if (d>63) d--; | ||
| 440 | 			c = gb18030[c][d]; | ||
| 441 | 			break; | ||
| 442 | 		case BIG5: | ||
| 443 | 			if (c < 128) break; | ||
| 444 | 			l = 2; | ||
| 445 | 			if (*inb < 2) goto starved; | ||
| 446 | 			d = *((unsigned char *)*in + 1); | ||
| 447 | 			if (d-0x40>=0xff-0x40 || d-0x7f<0xa1-0x7f) goto ilseq; | ||
| 448 | 			d -= 0x40; | ||
| 449 | 			if (d > 0x3e) d -= 0x22; | ||
| 450 | 			if (c-0xa1>=0xfa-0xa1) { | ||
| 451 | 				if (c-0x87>=0xff-0x87) goto ilseq; | ||
| 452 | 				if (c < 0xa1) c -= 0x87; | ||
| 453 | 				else c -= 0x87 + (0xfa-0xa1); | ||
| 454 | 				c = (hkscs[4867+(c*157+d)/16]>>(c*157+d)%16)%2<<17 | ||
| 455 | 					| hkscs[c*157+d]; | ||
| 456 | 				/* A few HKSCS characters map to pairs of UCS | ||
| 457 | 				 * characters. These are mapped to surrogate | ||
| 458 | 				 * range in the hkscs table then hard-coded | ||
| 459 | 				 * here. Ugly, yes. */ | ||
| 460 | 				if (c/256 == 0xdc) { | ||
| 461 | 					union { | ||
| 462 | 						char c[8]; | ||
| 463 | 						wchar_t wc[2]; | ||
| 464 | 					} tmp; | ||
| 465 | 					char *ptmp = tmp.c; | ||
| 466 | 					size_t tmpx = iconv(combine_to_from(to, find_charmap("utf8")), | ||
| 467 | 						&(char *){"\303\212\314\204" | ||
| 468 | 						"\303\212\314\214" | ||
| 469 | 						"\303\252\314\204" | ||
| 470 | 						"\303\252\314\214" | ||
| 471 | 						+c%256}, &(size_t){4}, | ||
| 472 | 						&ptmp, &(size_t){sizeof tmp}); | ||
| 473 | 					size_t tmplen = ptmp - tmp.c; | ||
| 474 | 					if (tmplen > *outb) goto toobig; | ||
| 475 | 					if (tmpx) x++; | ||
| 476 | 					memcpy(*out, &tmp, tmplen); | ||
| 477 | 					*out += tmplen; | ||
| 478 | 					*outb -= tmplen; | ||
| 479 | 					continue; | ||
| 480 | 				} | ||
| 481 | 				if (!c) goto ilseq; | ||
| 482 | 				break; | ||
| 483 | 			} | ||
| 484 | 			c -= 0xa1; | ||
| 485 | 			c = big5[c][d]|(c==0x27&&(d==0x3a||d==0x3c||d==0x42))<<17; | ||
| 486 | 			if (!c) goto ilseq; | ||
| 487 | 			break; | ||
| 488 | 		case EUC_KR: | ||
| 489 | 			if (c < 128) break; | ||
| 490 | 			l = 2; | ||
| 491 | 			if (*inb < 2) goto starved; | ||
| 492 | 			d = *((unsigned char *)*in + 1); | ||
| 493 | 			c -= 0xa1; | ||
| 494 | 			d -= 0xa1; | ||
| 495 | 			if (c >= 93 || d >= 94) { | ||
| 496 | 				c += (0xa1-0x81); | ||
| 497 | 				d += 0xa1; | ||
| 498 | 				if (c >= 93 || c>=0xc6-0x81 && d>0x52) | ||
| 499 | 					goto ilseq; | ||
| 500 | 				if (d-'A'<26) d = d-'A'; | ||
| 501 | 				else if (d-'a'<26) d = d-'a'+26; | ||
| 502 | 				else if (d-0x81<0xff-0x81) d = d-0x81+52; | ||
| 503 | 				else goto ilseq; | ||
| 504 | 				if (c < 0x20) c = 178*c + d; | ||
| 505 | 				else c = 178*0x20 + 84*(c-0x20) + d; | ||
| 506 | 				c += 0xac00; | ||
| 507 | 				for (d=0xac00; d<=c; ) { | ||
| 508 | 					k = 0; | ||
| 509 | 					for (int i=0; i<93; i++) | ||
| 510 | 						for (int j=0; j<94; j++) | ||
| 511 | 							if (ksc[i][j]-d <= c-d) | ||
| 512 | 								k++; | ||
| 513 | 					d = c+1; | ||
| 514 | 					c += k; | ||
| 515 | 				} | ||
| 516 | 				break; | ||
| 517 | 			} | ||
| 518 | 			c = ksc[c][d]; | ||
| 519 | 			if (!c) goto ilseq; | ||
| 520 | 			break; | ||
| 521 | 		default: | ||
| 522 | 			if (!c) break; | ||
| 523 | 			c = legacy_map(map, c); | ||
| 524 | 			if (!c) goto ilseq; | ||
| 525 | 		} | ||
| 526 | |||
| 527 | 		switch (totype) { | ||
| 528 | 		case WCHAR_T: | ||
| 529 | 			if (*outb < sizeof(wchar_t)) goto toobig; | ||
| 530 | 			*(wchar_t *)*out = c; | ||
| 531 | 			*out += sizeof(wchar_t); | ||
| 532 | 			*outb -= sizeof(wchar_t); | ||
| 533 | 			break; | ||
| 534 | 		case UTF_8: | ||
| 535 | 			if (*outb < 4) { | ||
| 536 | 				char tmp[4]; | ||
| 537 | 				k = wctomb_utf8(tmp, c); | ||
| 538 | 				if (*outb < k) goto toobig; | ||
| 539 | 				memcpy(*out, tmp, k); | ||
| 540 | 			} else k = wctomb_utf8(*out, c); | ||
| 541 | 			*out += k; | ||
| 542 | 			*outb -= k; | ||
| 543 | 			break; | ||
| 544 | 		case US_ASCII: | ||
| 545 | 			if (c > 0x7f) subst: x++, c='*'; | ||
| 546 | 		default: | ||
| 547 | 			if (*outb < 1) goto toobig; | ||
| 548 | 			if (c<256 && c==legacy_map(tomap, c)) { | ||
| 549 | 			revout: | ||
| 550 | 				if (*outb < 1) goto toobig; | ||
| 551 | 				*(*out)++ = c; | ||
| 552 | 				*outb -= 1; | ||
| 553 | 				break; | ||
| 554 | 			} | ||
| 555 | 			d = c; | ||
| 556 | 			for (c=4*totype; c<256; c++) { | ||
| 557 | 				if (d == legacy_map(tomap, c)) { | ||
| 558 | 					goto revout; | ||
| 559 | 				} | ||
| 560 | 			} | ||
| 561 | 			goto subst; | ||
| 562 | 		case SHIFT_JIS: | ||
| 563 | 			if (c < 128) goto revout; | ||
| 564 | 			if (c == 0xa5) { | ||
| 565 | 				x++; | ||
| 566 | 				c = '\\'; | ||
| 567 | 				goto revout; | ||
| 568 | 			} | ||
| 569 | 			if (c == 0x203e) { | ||
| 570 | 				x++; | ||
| 571 | 				c = '~'; | ||
| 572 | 				goto revout; | ||
| 573 | 			} | ||
| 574 | 			if (c-0xff61 <= 0xdf-0xa1) { | ||
| 575 | 				c += 0xa1 - 0xff61; | ||
| 576 | 				goto revout; | ||
| 577 | 			} | ||
| 578 | 			c = uni_to_jis(c); | ||
| 579 | 			if (!c) goto subst; | ||
| 580 | 			if (*outb < 2) goto toobig; | ||
| 581 | 			d = c%256; | ||
| 582 | 			c = c/256; | ||
| 583 | 			*(*out)++ = (c+1)/2 + (c<95 ? 112 : 176); | ||
| 584 | 			*(*out)++ = c%2 ? d + 31 + d/96 : d + 126; | ||
| 585 | 			*outb -= 2; | ||
| 586 | 			break; | ||
| 587 | 		case EUC_JP: | ||
| 588 | 			if (c < 128) goto revout; | ||
| 589 | 			if (c-0xff61 <= 0xdf-0xa1) { | ||
| 590 | 				c += 0x0e00 + 0x21 - 0xff61; | ||
| 591 | 			} else { | ||
| 592 | 				c = uni_to_jis(c); | ||
| 593 | 			} | ||
| 594 | 			if (!c) goto subst; | ||
| 595 | 			if (*outb < 2) goto toobig; | ||
| 596 | 			*(*out)++ = c/256 + 0x80; | ||
| 597 | 			*(*out)++ = c%256 + 0x80; | ||
| 598 | 			*outb -= 2; | ||
| 599 | 			break; | ||
| 600 | 		case ISO2022_JP: | ||
| 601 | 			if (c < 128) goto revout; | ||
| 602 | 			if (c-0xff61 <= 0xdf-0xa1 || c==0xa5 || c==0x203e) { | ||
| 603 | 				if (*outb < 7) goto toobig; | ||
| 604 | 				*(*out)++ = '\033'; | ||
| 605 | 				*(*out)++ = '('; | ||
| 606 | 				if (c==0xa5) { | ||
| 607 | 					*(*out)++ = 'J'; | ||
| 608 | 					*(*out)++ = '\\'; | ||
| 609 | 				} else if (c==0x203e) { | ||
| 610 | 					*(*out)++ = 'J'; | ||
| 611 | 					*(*out)++ = '~'; | ||
| 612 | 				} else { | ||
| 613 | 					*(*out)++ = 'I'; | ||
| 614 | 					*(*out)++ = c-0xff61+0x21; | ||
| 615 | 				} | ||
| 616 | 				*(*out)++ = '\033'; | ||
| 617 | 				*(*out)++ = '('; | ||
| 618 | 				*(*out)++ = 'B'; | ||
| 619 | 				*outb -= 7; | ||
| 620 | 				break; | ||
| 621 | 			} | ||
| 622 | 			c = uni_to_jis(c); | ||
| 623 | 			if (!c) goto subst; | ||
| 624 | 			if (*outb < 8) goto toobig; | ||
| 625 | 			*(*out)++ = '\033'; | ||
| 626 | 			*(*out)++ = '$'; | ||
| 627 | 			*(*out)++ = 'B'; | ||
| 628 | 			*(*out)++ = c/256; | ||
| 629 | 			*(*out)++ = c%256; | ||
| 630 | 			*(*out)++ = '\033'; | ||
| 631 | 			*(*out)++ = '('; | ||
| 632 | 			*(*out)++ = 'B'; | ||
| 633 | 			*outb -= 8; | ||
| 634 | 			break; | ||
| 635 | 		case UCS2: | ||
| 636 | 			totype = UCS2BE; | ||
| 637 | 		case UCS2BE: | ||
| 638 | 		case UCS2LE: | ||
| 639 | 		case UTF_16: | ||
| 640 | 		case UTF_16BE: | ||
| 641 | 		case UTF_16LE: | ||
| 642 | 			if (c < 0x10000 || totype-UCS2BE < 2U) { | ||
| 643 | 				if (c >= 0x10000) c = 0xFFFD; | ||
| 644 | 				if (*outb < 2) goto toobig; | ||
| 645 | 				put_16((void *)*out, c, totype); | ||
| 646 | 				*out += 2; | ||
| 647 | 				*outb -= 2; | ||
| 648 | 				break; | ||
| 649 | 			} | ||
| 650 | 			if (*outb < 4) goto toobig; | ||
| 651 | 			c -= 0x10000; | ||
| 652 | 			put_16((void *)*out, (c>>10)|0xd800, totype); | ||
| 653 | 			put_16((void *)(*out + 2), (c&0x3ff)|0xdc00, totype); | ||
| 654 | 			*out += 4; | ||
| 655 | 			*outb -= 4; | ||
| 656 | 			break; | ||
| 657 | 		case UTF_32: | ||
| 658 | 			totype = UTF_32BE; | ||
| 659 | 		case UTF_32BE: | ||
| 660 | 		case UTF_32LE: | ||
| 661 | 			if (*outb < 4) goto toobig; | ||
| 662 | 			put_32((void *)*out, c, totype); | ||
| 663 | 			*out += 4; | ||
| 664 | 			*outb -= 4; | ||
| 665 | 			break; | ||
| 666 | 		} | ||
| 667 | 	} | ||
| 668 | 	*ploc = loc; | ||
| 669 | 	return x; | ||
| 670 | ilseq: | ||
| 671 | 	err = EILSEQ; | ||
| 672 | 	x = -1; | ||
| 673 | 	goto end; | ||
| 674 | toobig: | ||
| 675 | 	err = E2BIG; | ||
| 676 | 	x = -1; | ||
| 677 | 	goto end; | ||
| 678 | starved: | ||
| 679 | 	err = EINVAL; | ||
| 680 | 	x = -1; | ||
| 681 | end: | ||
| 682 | 	errno = err; | ||
| 683 | 	*ploc = loc; | ||
| 684 | 	return x; | ||
| 685 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/iconv_close.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <iconv.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | int iconv_close(iconv_t cd) | ||
| 5 | { | ||
| 6 | 	if (!((size_t)cd & 1)) free((void *)cd); | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/jis0208.h created+563| ... | @@ -0,0 +1,563 @@ | ||
| 1 | 12288,12289,12290,65292,65294,12539,65306,65307,65311,65281,12443,12444,180, | ||
| 2 | 65344,168,65342,65507,65343,12541,12542,12445,12446,12291,20189,12293,12294, | ||
| 3 | 12295,12540,8213,8208,65295,92,12316,8214,65372,8230,8229,8216,8217,8220,8221, | ||
| 4 | 65288,65289,12308,12309,65339,65341,65371,65373,12296,12297,12298,12299,12300, | ||
| 5 | 12301,12302,12303,12304,12305,65291,8722,177,215,247,65309,8800,65308,65310, | ||
| 6 | 8806,8807,8734,8756,9794,9792,176,8242,8243,8451,65509,65284,162,163,65285, | ||
| 7 | 65283,65286,65290,65312,167,9734,9733,9675,9679,9678,9671,9670,9633,9632,9651, | ||
| 8 | 9650,9661,9660,8251,12306,8594,8592,8593,8595,12307,0,0,0,0,0,0,0,0,0,0,0, | ||
| 9 | 8712,8715,8838,8839,8834,8835,8746,8745,0,0,0,0,0,0,0,0,8743,8744,172,8658, | ||
| 10 | 8660,8704,8707,0,0,0,0,0,0,0,0,0,0,0,8736,8869,8978,8706,8711,8801,8786,8810, | ||
| 11 | 8811,8730,8765,8733,8757,8747,8748,0,0,0,0,0,0,0,8491,8240,9839,9837,9834, | ||
| 12 | 8224,8225,182,0,0,0,0,9711,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65296,65297,65298, | ||
| 13 | 65299,65300,65301,65302,65303,65304,65305,0,0,0,0,0,0,0,65313,65314,65315, | ||
| 14 | 65316,65317,65318,65319,65320,65321,65322,65323,65324,65325,65326,65327,65328, | ||
| 15 | 65329,65330,65331,65332,65333,65334,65335,65336,65337,65338,0,0,0,0,0,0,65345, | ||
| 16 | 65346,65347, | ||
| 17 | 65348,65349,65350,65351,65352,65353,65354,65355,65356,65357,65358,65359,65360, | ||
| 18 | 65361,65362,65363,65364,65365,65366,65367,65368,65369,65370,0,0,0,0,12353, | ||
| 19 | 12354,12355,12356,12357,12358,12359,12360,12361,12362,12363,12364,12365,12366, | ||
| 20 | 12367,12368,12369,12370,12371,12372,12373,12374,12375,12376,12377,12378,12379, | ||
| 21 | 12380,12381,12382,12383,12384,12385,12386,12387,12388,12389,12390,12391,12392, | ||
| 22 | 12393,12394,12395,12396,12397,12398,12399,12400,12401,12402,12403,12404,12405, | ||
| 23 | 12406,12407,12408,12409,12410,12411,12412,12413,12414,12415,12416,12417,12418, | ||
| 24 | 12419,12420,12421,12422,12423,12424,12425,12426,12427,12428,12429,12430,12431, | ||
| 25 | 12432,12433,12434,12435,0,0,0,0,0,0,0,0,0,0,0,12449,12450,12451,12452,12453, | ||
| 26 | 12454,12455,12456,12457,12458,12459,12460,12461,12462,12463,12464,12465,12466, | ||
| 27 | 12467,12468,12469,12470,12471,12472,12473,12474,12475,12476,12477,12478,12479, | ||
| 28 | 12480,12481,12482,12483,12484,12485,12486,12487,12488,12489,12490,12491,12492, | ||
| 29 | 12493,12494,12495,12496,12497,12498,12499,12500,12501,12502,12503,12504,12505, | ||
| 30 | 12506,12507,12508,12509,12510,12511,12512,12513,12514,12515,12516,12517,12518, | ||
| 31 | 12519,12520,12521,12522,12523,12524,12525,12526,12527,12528,12529,12530,12531, | ||
| 32 | 12532,12533,12534,0,0,0,0,0,0,0,0,913,914,915,916,917,918,919,920,921,922,923, | ||
| 33 | 924,925,926,927,928,929,931,932,933,934,935,936,937,0,0,0,0,0,0,0,0,945,946, | ||
| 34 | 947,948,949,950,951,952,953, | ||
| 35 | 954,955,956,957,958,959,960,961,963,964,965,966,967,968,969,0,0,0,0,0,0,0,0,0, | ||
| 36 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1040,1041,1042,1043, | ||
| 37 | 1044,1045,1025,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057, | ||
| 38 | 1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,0,0,0,0, | ||
| 39 | 0,0,0,0,0,0,0,0,0,0,0,1072,1073,1074,1075,1076,1077,1105,1078,1079,1080,1081, | ||
| 40 | 1082,1083,1084,1085,1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096, | ||
| 41 | 1097,1098,1099,1100,1101,1102,1103,0,0,0,0,0,0,0,0,0,0,0,0,0,9472,9474,9484, | ||
| 42 | 9488,9496,9492,9500,9516,9508,9524,9532,9473,9475,9487,9491,9499,9495,9507, | ||
| 43 | 9523,9515,9531,9547,9504,9519,9512,9527,9535,9501,9520,9509,9528,9538,0,0,0,0, | ||
| 44 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 45 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 46 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 47 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 48 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 49 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 50 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 51 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 52 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 53 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 54 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 55 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 56 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 57 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 58 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 59 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 60 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 61 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 62 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 63 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,20124,21782,23043,38463,21696,24859,25384,23030, | ||
| 64 | 36898,33909,33564,31312,24746,25569,28197,26093,33894,33446,39925,26771,22311, | ||
| 65 | 26017,25201,23451,22992,34427,39156,32098,32190,39822,25110,31903,34999,23433, | ||
| 66 | 24245,25353,26263,26696,38343,38797,26447,20197,20234,20301,20381,20553,22258, | ||
| 67 | 22839,22996,23041,23561,24799,24847,24944,26131,26885,28858,30031,30064,31227, | ||
| 68 | 32173,32239,32963,33806,34915,35586,36949,36986,21307,20117,20133,22495,32946, | ||
| 69 | 37057,30959,19968,22769,28322,36920,31282,33576,33419,39983,20801,21360,21693, | ||
| 70 | 21729,22240,23035,24341,39154,28139,32996,34093,38498,38512,38560,38907,21515, | ||
| 71 | 21491,23431,28879,32701,36802,38632,21359,40284,31418,19985,30867,33276,28198, | ||
| 72 | 22040,21764,27421,34074,39995,23013,21417,28006,29916,38287,22082,20113,36939, | ||
| 73 | 38642,33615,39180,21473,21942,23344,24433,26144,26355,26628,27704,27891,27945, | ||
| 74 | 29787,30408,31310,38964,33521,34907,35424,37613,28082,30123,30410,39365,24742, | ||
| 75 | 35585,36234,38322,27022,21421,20870,22290,22576,22852,23476,24310,24616,25513, | ||
| 76 | 25588,27839,28436,28814,28948,29017,29141,29503,32257,33398,33489,34199,36960, | ||
| 77 | 37467,40219,22633,26044,27738,29989,20985,22830,22885,24448,24540,25276,26106, | ||
| 78 | 27178,27431,27572,29579,32705,35158,40236,40206,40644,23713,27798,33659,20740, | ||
| 79 | 23627,25014,33222,26742,29281,20057,20474,21368,24681,28201,31311,38899,19979, | ||
| 80 | 21270,20206,20309,20285,20385,20339,21152,21487,22025,22799,23233,23478,23521, | ||
| 81 | 31185,26247,26524,26550,27468,27827,28779,29634,31117,31166,31292,31623,33457, | ||
| 82 | 33499,33540,33655,33775,33747,34662,35506,22057,36008,36838,36942,38686,34442, | ||
| 83 | 20420,23784,25105,29273,30011,33253,33469,34558,36032,38597,39187,39381,20171, | ||
| 84 | 20250,35299,22238,22602,22730,24315,24555,24618,24724,24674,25040,25106,25296, | ||
| 85 | 25913,39745,26214,26800,28023,28784,30028,30342,32117,33445,34809,38283,38542, | ||
| 86 | 35997,20977,21182,22806,21683,23475,23830,24936,27010,28079,30861,33995,34903, | ||
| 87 | 35442,37799,39608,28012,39336,34521,22435,26623,34510,37390,21123,22151,21508, | ||
| 88 | 24275,25313,25785,26684,26680,27579,29554,30906,31339,35226,35282,36203,36611, | ||
| 89 | 37101,38307,38548,38761,23398,23731,27005,38989,38990,25499,31520,27179,27263, | ||
| 90 | 26806,39949,28511,21106,21917,24688,25324,27963,28167,28369,33883,35088,36676, | ||
| 91 | 19988,39993,21494,26907,27194,38788,26666,20828,31427,33970,37340,37772,22107, | ||
| 92 | 40232,26658,33541,33841,31909,21000,33477,29926,20094, | ||
| 93 | 20355,20896,23506,21002,21208,21223,24059,21914,22570,23014,23436,23448,23515, | ||
| 94 | 24178,24185,24739,24863,24931,25022,25563,25954,26577,26707,26874,27454,27475, | ||
| 95 | 27735,28450,28567,28485,29872,29976,30435,30475,31487,31649,31777,32233,32566, | ||
| 96 | 32752,32925,33382,33694,35251,35532,36011,36996,37969,38291,38289,38306,38501, | ||
| 97 | 38867,39208,33304,20024,21547,23736,24012,29609,30284,30524,23721,32747,36107, | ||
| 98 | 38593,38929,38996,39000,20225,20238,21361,21916,22120,22522,22855,23305,23492, | ||
| 99 | 23696,24076,24190,24524,25582,26426,26071,26082,26399,26827,26820,27231,24112, | ||
| 100 | 27589,27671,27773,30079,31048,23395,31232,32000,24509,35215,35352,36020,36215, | ||
| 101 | 36556,36637,39138,39438,39740,20096,20605,20736,22931,23452,25135,25216,25836, | ||
| 102 | 27450,29344,30097,31047,32681,34811,35516,35696,25516,33738,38816,21513,21507, | ||
| 103 | 21931,26708,27224,35440,30759,26485,40653,21364,23458,33050,34384,36870,19992, | ||
| 104 | 20037,20167,20241,21450,21560,23470,24339,24613,25937,26429,27714,27762,27875, | ||
| 105 | 28792,29699,31350,31406,31496,32026,31998,32102,26087,29275,21435,23621,24040, | ||
| 106 | 25298,25312,25369,28192,34394,35377,36317,37624,28417,31142,39770,20136,20139, | ||
| 107 | 20140,20379,20384,20689,20807,31478,20849,20982,21332,21281,21375,21483,21932, | ||
| 108 | 22659,23777,24375,24394,24623,24656,24685,25375,25945,27211,27841,29378,29421, | ||
| 109 | 30703,33016,33029,33288,34126,37111,37857,38911,39255,39514,20208,20957,23597, | ||
| 110 | 26241,26989,23616,26354,26997,29577,26704,31873,20677,21220,22343,24062,37670, | ||
| 111 | 26020,27427,27453,29748,31105,31165,31563,32202,33465,33740,34943,35167,35641, | ||
| 112 | 36817,37329,21535,37504,20061,20534,21477,21306,29399, | ||
| 113 | 29590,30697,33510,36527,39366,39368,39378,20855,24858,34398,21936,31354,20598, | ||
| 114 | 23507,36935,38533,20018,27355,37351,23633,23624,25496,31391,27795,38772,36705, | ||
| 115 | 31402,29066,38536,31874,26647,32368,26705,37740,21234,21531,34219,35347,32676, | ||
| 116 | 36557,37089,21350,34952,31041,20418,20670,21009,20804,21843,22317,29674,22411, | ||
| 117 | 22865,24418,24452,24693,24950,24935,25001,25522,25658,25964,26223,26690,28179, | ||
| 118 | 30054,31293,31995,32076,32153,32331,32619,33550,33610,34509,35336,35427,35686, | ||
| 119 | 36605,38938,40335,33464,36814,39912,21127,25119,25731,28608,38553,26689,20625, | ||
| 120 | 27424,27770,28500,31348,32080,34880,35363,26376,20214,20537,20518,20581,20860, | ||
| 121 | 21048,21091,21927,22287,22533,23244,24314,25010,25080,25331,25458,26908,27177, | ||
| 122 | 29309,29356,29486,30740,30831,32121,30476,32937,35211,35609,36066,36562,36963, | ||
| 123 | 37749,38522,38997,39443,40568,20803,21407,21427,24187,24358,28187,28304,29572, | ||
| 124 | 29694,32067,33335,35328,35578,38480,20046,20491,21476,21628,22266,22993,23396, | ||
| 125 | 24049,24235,24359,25144,25925,26543,28246,29392,31946,34996,32929,32993,33776, | ||
| 126 | 34382,35463,36328,37431,38599,39015,40723,20116,20114,20237,21320,21577,21566, | ||
| 127 | 23087,24460,24481,24735,26791,27278,29786,30849,35486,35492,35703,37264,20062, | ||
| 128 | 39881,20132,20348,20399,20505,20502,20809,20844,21151,21177,21246,21402,21475, | ||
| 129 | 21521,21518,21897,22353,22434,22909,23380,23389,23439,24037,24039,24055,24184, | ||
| 130 | 24195,24218,24247,24344,24658,24908,25239,25304,25511,25915,26114,26179,26356, | ||
| 131 | 26477,26657,26775,27083,27743,27946,28009,28207,28317,30002,30343,30828,31295, | ||
| 132 | 31968,32005,32024,32094,32177,32789,32771,32943,32945, | ||
| 133 | 33108,33167,33322,33618,34892,34913,35611,36002,36092,37066,37237,37489,30783, | ||
| 134 | 37628,38308,38477,38917,39321,39640,40251,21083,21163,21495,21512,22741,25335, | ||
| 135 | 28640,35946,36703,40633,20811,21051,21578,22269,31296,37239,40288,40658,29508, | ||
| 136 | 28425,33136,29969,24573,24794,39592,29403,36796,27492,38915,20170,22256,22372, | ||
| 137 | 22718,23130,24680,25031,26127,26118,26681,26801,28151,30165,32058,33390,39746, | ||
| 138 | 20123,20304,21449,21766,23919,24038,24046,26619,27801,29811,30722,35408,37782, | ||
| 139 | 35039,22352,24231,25387,20661,20652,20877,26368,21705,22622,22971,23472,24425, | ||
| 140 | 25165,25505,26685,27507,28168,28797,37319,29312,30741,30758,31085,25998,32048, | ||
| 141 | 33756,35009,36617,38555,21092,22312,26448,32618,36001,20916,22338,38442,22586, | ||
| 142 | 27018,32948,21682,23822,22524,30869,40442,20316,21066,21643,25662,26152,26388, | ||
| 143 | 26613,31364,31574,32034,37679,26716,39853,31545,21273,20874,21047,23519,25334, | ||
| 144 | 25774,25830,26413,27578,34217,38609,30352,39894,25420,37638,39851,30399,26194, | ||
| 145 | 19977,20632,21442,23665,24808,25746,25955,26719,29158,29642,29987,31639,32386, | ||
| 146 | 34453,35715,36059,37240,39184,26028,26283,27531,20181,20180,20282,20351,21050, | ||
| 147 | 21496,21490,21987,22235,22763,22987,22985,23039,23376,23629,24066,24107,24535, | ||
| 148 | 24605,25351,25903,23388,26031,26045,26088,26525,27490,27515,27663,29509,31049, | ||
| 149 | 31169,31992,32025,32043,32930,33026,33267,35222,35422,35433,35430,35468,35566, | ||
| 150 | 36039,36060,38604,39164,27503,20107,20284,20365,20816,23383,23546,24904,25345, | ||
| 151 | 26178,27425,28363,27835,29246,29885,30164,30913,31034,32780,32819,33258,33940, | ||
| 152 | 36766,27728,40575,24335,35672,40235,31482,36600,23437, | ||
| 153 | 38635,19971,21489,22519,22833,23241,23460,24713,28287,28422,30142,36074,23455, | ||
| 154 | 34048,31712,20594,26612,33437,23649,34122,32286,33294,20889,23556,25448,36198, | ||
| 155 | 26012,29038,31038,32023,32773,35613,36554,36974,34503,37034,20511,21242,23610, | ||
| 156 | 26451,28796,29237,37196,37320,37675,33509,23490,24369,24825,20027,21462,23432, | ||
| 157 | 25163,26417,27530,29417,29664,31278,33131,36259,37202,39318,20754,21463,21610, | ||
| 158 | 23551,25480,27193,32172,38656,22234,21454,21608,23447,23601,24030,20462,24833, | ||
| 159 | 25342,27954,31168,31179,32066,32333,32722,33261,33311,33936,34886,35186,35728, | ||
| 160 | 36468,36655,36913,37195,37228,38598,37276,20160,20303,20805,21313,24467,25102, | ||
| 161 | 26580,27713,28171,29539,32294,37325,37507,21460,22809,23487,28113,31069,32302, | ||
| 162 | 31899,22654,29087,20986,34899,36848,20426,23803,26149,30636,31459,33308,39423, | ||
| 163 | 20934,24490,26092,26991,27529,28147,28310,28516,30462,32020,24033,36981,37255, | ||
| 164 | 38918,20966,21021,25152,26257,26329,28186,24246,32210,32626,26360,34223,34295, | ||
| 165 | 35576,21161,21465,22899,24207,24464,24661,37604,38500,20663,20767,21213,21280, | ||
| 166 | 21319,21484,21736,21830,21809,22039,22888,22974,23100,23477,23558,23567,23569, | ||
| 167 | 23578,24196,24202,24288,24432,25215,25220,25307,25484,25463,26119,26124,26157, | ||
| 168 | 26230,26494,26786,27167,27189,27836,28040,28169,28248,28988,28966,29031,30151, | ||
| 169 | 30465,30813,30977,31077,31216,31456,31505,31911,32057,32918,33750,33931,34121, | ||
| 170 | 34909,35059,35359,35388,35412,35443,35937,36062,37284,37478,37758,37912,38556, | ||
| 171 | 38808,19978,19976,19998,20055,20887,21104,22478,22580,22732,23330,24120,24773, | ||
| 172 | 25854,26465,26454,27972,29366,30067,31331,33976,35698, | ||
| 173 | 37304,37664,22065,22516,39166,25325,26893,27542,29165,32340,32887,33394,35302, | ||
| 174 | 39135,34645,36785,23611,20280,20449,20405,21767,23072,23517,23529,24515,24910, | ||
| 175 | 25391,26032,26187,26862,27035,28024,28145,30003,30137,30495,31070,31206,32051, | ||
| 176 | 33251,33455,34218,35242,35386,36523,36763,36914,37341,38663,20154,20161,20995, | ||
| 177 | 22645,22764,23563,29978,23613,33102,35338,36805,38499,38765,31525,35535,38920, | ||
| 178 | 37218,22259,21416,36887,21561,22402,24101,25512,27700,28810,30561,31883,32736, | ||
| 179 | 34928,36930,37204,37648,37656,38543,29790,39620,23815,23913,25968,26530,36264, | ||
| 180 | 38619,25454,26441,26905,33733,38935,38592,35070,28548,25722,23544,19990,28716, | ||
| 181 | 30045,26159,20932,21046,21218,22995,24449,24615,25104,25919,25972,26143,26228, | ||
| 182 | 26866,26646,27491,28165,29298,29983,30427,31934,32854,22768,35069,35199,35488, | ||
| 183 | 35475,35531,36893,37266,38738,38745,25993,31246,33030,38587,24109,24796,25114, | ||
| 184 | 26021,26132,26512,30707,31309,31821,32318,33034,36012,36196,36321,36447,30889, | ||
| 185 | 20999,25305,25509,25666,25240,35373,31363,31680,35500,38634,32118,33292,34633, | ||
| 186 | 20185,20808,21315,21344,23459,23554,23574,24029,25126,25159,25776,26643,26676, | ||
| 187 | 27849,27973,27927,26579,28508,29006,29053,26059,31359,31661,32218,32330,32680, | ||
| 188 | 33146,33307,33337,34214,35438,36046,36341,36984,36983,37549,37521,38275,39854, | ||
| 189 | 21069,21892,28472,28982,20840,31109,32341,33203,31950,22092,22609,23720,25514, | ||
| 190 | 26366,26365,26970,29401,30095,30094,30990,31062,31199,31895,32032,32068,34311, | ||
| 191 | 35380,38459,36961,40736,20711,21109,21452,21474,20489,21930,22766,22863,29245, | ||
| 192 | 23435,23652,21277,24803,24819,25436,25475,25407,25531, | ||
| 193 | 25805,26089,26361,24035,27085,27133,28437,29157,20105,30185,30456,31379,31967, | ||
| 194 | 32207,32156,32865,33609,33624,33900,33980,34299,35013,36208,36865,36973,37783, | ||
| 195 | 38684,39442,20687,22679,24974,33235,34101,36104,36896,20419,20596,21063,21363, | ||
| 196 | 24687,25417,26463,28204,36275,36895,20439,23646,36042,26063,32154,21330,34966, | ||
| 197 | 20854,25539,23384,23403,23562,25613,26449,36956,20182,22810,22826,27760,35409, | ||
| 198 | 21822,22549,22949,24816,25171,26561,33333,26965,38464,39364,39464,20307,22534, | ||
| 199 | 23550,32784,23729,24111,24453,24608,24907,25140,26367,27888,28382,32974,33151, | ||
| 200 | 33492,34955,36024,36864,36910,38538,40667,39899,20195,21488,22823,31532,37261, | ||
| 201 | 38988,40441,28381,28711,21331,21828,23429,25176,25246,25299,27810,28655,29730, | ||
| 202 | 35351,37944,28609,35582,33592,20967,34552,21482,21481,20294,36948,36784,22890, | ||
| 203 | 33073,24061,31466,36799,26842,35895,29432,40008,27197,35504,20025,21336,22022, | ||
| 204 | 22374,25285,25506,26086,27470,28129,28251,28845,30701,31471,31658,32187,32829, | ||
| 205 | 32966,34507,35477,37723,22243,22727,24382,26029,26262,27264,27573,30007,35527, | ||
| 206 | 20516,30693,22320,24347,24677,26234,27744,30196,31258,32622,33268,34584,36933, | ||
| 207 | 39347,31689,30044,31481,31569,33988,36880,31209,31378,33590,23265,30528,20013, | ||
| 208 | 20210,23449,24544,25277,26172,26609,27880,34411,34935,35387,37198,37619,39376, | ||
| 209 | 27159,28710,29482,33511,33879,36015,19969,20806,20939,21899,23541,24086,24115, | ||
| 210 | 24193,24340,24373,24427,24500,25074,25361,26274,26397,28526,29266,30010,30522, | ||
| 211 | 32884,33081,33144,34678,35519,35548,36229,36339,37530,38263,38914,40165,21189, | ||
| 212 | 25431,30452,26389,27784,29645,36035,37806,38515,27941, | ||
| 213 | 22684,26894,27084,36861,37786,30171,36890,22618,26626,25524,27131,20291,28460, | ||
| 214 | 26584,36795,34086,32180,37716,26943,28528,22378,22775,23340,32044,29226,21514, | ||
| 215 | 37347,40372,20141,20302,20572,20597,21059,35998,21576,22564,23450,24093,24213, | ||
| 216 | 24237,24311,24351,24716,25269,25402,25552,26799,27712,30855,31118,31243,32224, | ||
| 217 | 33351,35330,35558,36420,36883,37048,37165,37336,40718,27877,25688,25826,25973, | ||
| 218 | 28404,30340,31515,36969,37841,28346,21746,24505,25764,36685,36845,37444,20856, | ||
| 219 | 22635,22825,23637,24215,28155,32399,29980,36028,36578,39003,28857,20253,27583, | ||
| 220 | 28593,30000,38651,20814,21520,22581,22615,22956,23648,24466,26007,26460,28193, | ||
| 221 | 30331,33759,36077,36884,37117,37709,30757,30778,21162,24230,22303,22900,24594, | ||
| 222 | 20498,20826,20908,20941,20992,21776,22612,22616,22871,23445,23798,23947,24764, | ||
| 223 | 25237,25645,26481,26691,26812,26847,30423,28120,28271,28059,28783,29128,24403, | ||
| 224 | 30168,31095,31561,31572,31570,31958,32113,21040,33891,34153,34276,35342,35588, | ||
| 225 | 35910,36367,36867,36879,37913,38518,38957,39472,38360,20685,21205,21516,22530, | ||
| 226 | 23566,24999,25758,27934,30643,31461,33012,33796,36947,37509,23776,40199,21311, | ||
| 227 | 24471,24499,28060,29305,30563,31167,31716,27602,29420,35501,26627,27233,20984, | ||
| 228 | 31361,26932,23626,40182,33515,23493,37193,28702,22136,23663,24775,25958,27788, | ||
| 229 | 35930,36929,38931,21585,26311,37389,22856,37027,20869,20045,20970,34201,35598, | ||
| 230 | 28760,25466,37707,26978,39348,32260,30071,21335,26976,36575,38627,27741,20108, | ||
| 231 | 23612,24336,36841,21250,36049,32905,34425,24319,26085,20083,20837,22914,23615, | ||
| 232 | 38894,20219,22922,24525,35469,28641,31152,31074,23527, | ||
| 233 | 33905,29483,29105,24180,24565,25467,25754,29123,31896,20035,24316,20043,22492, | ||
| 234 | 22178,24745,28611,32013,33021,33075,33215,36786,35223,34468,24052,25226,25773, | ||
| 235 | 35207,26487,27874,27966,29750,30772,23110,32629,33453,39340,20467,24259,25309, | ||
| 236 | 25490,25943,26479,30403,29260,32972,32954,36649,37197,20493,22521,23186,26757, | ||
| 237 | 26995,29028,29437,36023,22770,36064,38506,36889,34687,31204,30695,33833,20271, | ||
| 238 | 21093,21338,25293,26575,27850,30333,31636,31893,33334,34180,36843,26333,28448, | ||
| 239 | 29190,32283,33707,39361,40614,20989,31665,30834,31672,32903,31560,27368,24161, | ||
| 240 | 32908,30033,30048,20843,37474,28300,30330,37271,39658,20240,32624,25244,31567, | ||
| 241 | 38309,40169,22138,22617,34532,38588,20276,21028,21322,21453,21467,24070,25644, | ||
| 242 | 26001,26495,27710,27726,29256,29359,29677,30036,32321,33324,34281,36009,31684, | ||
| 243 | 37318,29033,38930,39151,25405,26217,30058,30436,30928,34115,34542,21290,21329, | ||
| 244 | 21542,22915,24199,24444,24754,25161,25209,25259,26000,27604,27852,30130,30382, | ||
| 245 | 30865,31192,32203,32631,32933,34987,35513,36027,36991,38750,39131,27147,31800, | ||
| 246 | 20633,23614,24494,26503,27608,29749,30473,32654,40763,26570,31255,21305,30091, | ||
| 247 | 39661,24422,33181,33777,32920,24380,24517,30050,31558,36924,26727,23019,23195, | ||
| 248 | 32016,30334,35628,20469,24426,27161,27703,28418,29922,31080,34920,35413,35961, | ||
| 249 | 24287,25551,30149,31186,33495,37672,37618,33948,34541,39981,21697,24428,25996, | ||
| 250 | 27996,28693,36007,36051,38971,25935,29942,19981,20184,22496,22827,23142,23500, | ||
| 251 | 20904,24067,24220,24598,25206,25975,26023,26222,28014,29238,31526,33104,33178, | ||
| 252 | 33433,35676,36000,36070,36212,38428,38468,20398,25771, | ||
| 253 | 27494,33310,33889,34154,37096,23553,26963,39080,33914,34135,20239,21103,24489, | ||
| 254 | 24133,26381,31119,33145,35079,35206,28149,24343,25173,27832,20175,29289,39826, | ||
| 255 | 20998,21563,22132,22707,24996,25198,28954,22894,31881,31966,32027,38640,25991, | ||
| 256 | 32862,19993,20341,20853,22592,24163,24179,24330,26564,20006,34109,38281,38491, | ||
| 257 | 31859,38913,20731,22721,30294,30887,21029,30629,34065,31622,20559,22793,29255, | ||
| 258 | 31687,32232,36794,36820,36941,20415,21193,23081,24321,38829,20445,33303,37610, | ||
| 259 | 22275,25429,27497,29995,35036,36628,31298,21215,22675,24917,25098,26286,27597, | ||
| 260 | 31807,33769,20515,20472,21253,21574,22577,22857,23453,23792,23791,23849,24214, | ||
| 261 | 25265,25447,25918,26041,26379,27861,27873,28921,30770,32299,32990,33459,33804, | ||
| 262 | 34028,34562,35090,35370,35914,37030,37586,39165,40179,40300,20047,20129,20621, | ||
| 263 | 21078,22346,22952,24125,24536,24537,25151,26292,26395,26576,26834,20882,32033, | ||
| 264 | 32938,33192,35584,35980,36031,37502,38450,21536,38956,21271,20693,21340,22696, | ||
| 265 | 25778,26420,29287,30566,31302,37350,21187,27809,27526,22528,24140,22868,26412, | ||
| 266 | 32763,20961,30406,25705,30952,39764,40635,22475,22969,26151,26522,27598,21737, | ||
| 267 | 27097,24149,33180,26517,39850,26622,40018,26717,20134,20451,21448,25273,26411, | ||
| 268 | 27819,36804,20397,32365,40639,19975,24930,28288,28459,34067,21619,26410,39749, | ||
| 269 | 24051,31637,23724,23494,34588,28234,34001,31252,33032,22937,31885,27665,30496, | ||
| 270 | 21209,22818,28961,29279,30683,38695,40289,26891,23167,23064,20901,21517,21629, | ||
| 271 | 26126,30431,36855,37528,40180,23018,29277,28357,20813,26825,32191,32236,38754, | ||
| 272 | 40634,25720,27169,33538,22916,23391,27611,29467,30450, | ||
| 273 | 32178,32791,33945,20786,26408,40665,30446,26466,21247,39173,23588,25147,31870, | ||
| 274 | 36016,21839,24758,32011,38272,21249,20063,20918,22812,29242,32822,37326,24357, | ||
| 275 | 30690,21380,24441,32004,34220,35379,36493,38742,26611,34222,37971,24841,24840, | ||
| 276 | 27833,30290,35565,36664,21807,20305,20778,21191,21451,23461,24189,24736,24962, | ||
| 277 | 25558,26377,26586,28263,28044,29494,29495,30001,31056,35029,35480,36938,37009, | ||
| 278 | 37109,38596,34701,22805,20104,20313,19982,35465,36671,38928,20653,24188,22934, | ||
| 279 | 23481,24248,25562,25594,25793,26332,26954,27096,27915,28342,29076,29992,31407, | ||
| 280 | 32650,32768,33865,33993,35201,35617,36362,36965,38525,39178,24958,25233,27442, | ||
| 281 | 27779,28020,32716,32764,28096,32645,34746,35064,26469,33713,38972,38647,27931, | ||
| 282 | 32097,33853,37226,20081,21365,23888,27396,28651,34253,34349,35239,21033,21519, | ||
| 283 | 23653,26446,26792,29702,29827,30178,35023,35041,37324,38626,38520,24459,29575, | ||
| 284 | 31435,33870,25504,30053,21129,27969,28316,29705,30041,30827,31890,38534,31452, | ||
| 285 | 40845,20406,24942,26053,34396,20102,20142,20698,20001,20940,23534,26009,26753, | ||
| 286 | 28092,29471,30274,30637,31260,31975,33391,35538,36988,37327,38517,38936,21147, | ||
| 287 | 32209,20523,21400,26519,28107,29136,29747,33256,36650,38563,40023,40607,29792, | ||
| 288 | 22593,28057,32047,39006,20196,20278,20363,20919,21169,23994,24604,29618,31036, | ||
| 289 | 33491,37428,38583,38646,38666,40599,40802,26278,27508,21015,21155,28872,35010, | ||
| 290 | 24265,24651,24976,28451,29001,31806,32244,32879,34030,36899,37676,21570,39791, | ||
| 291 | 27347,28809,36034,36335,38706,21172,23105,24266,24324,26391,27004,27028,28010, | ||
| 292 | 28431,29282,29436,31725,32769,32894,34635,37070,20845, | ||
| 293 | 40595,31108,32907,37682,35542,20525,21644,35441,27498,36036,33031,24785,26528, | ||
| 294 | 40434,20121,20120,39952,35435,34241,34152,26880,28286,30871,33109,0,0,0,0,0,0, | ||
| 295 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 296 | 24332,19984,19989,20010,20017,20022,20028,20031,20034,20054,20056,20098,20101, | ||
| 297 | 35947,20106,33298,24333,20110,20126,20127,20128,20130,20144,20147,20150,20174, | ||
| 298 | 20173,20164,20166,20162,20183,20190,20205,20191,20215,20233,20314,20272,20315, | ||
| 299 | 20317,20311,20295,20342,20360,20367,20376,20347,20329,20336,20369,20335,20358, | ||
| 300 | 20374,20760,20436,20447,20430,20440,20443,20433,20442,20432,20452,20453,20506, | ||
| 301 | 20520,20500,20522,20517,20485,20252,20470,20513,20521,20524,20478,20463,20497, | ||
| 302 | 20486,20547,20551,26371,20565,20560,20552,20570,20566,20588,20600,20608,20634, | ||
| 303 | 20613,20660,20658,20681,20682,20659,20674,20694,20702,20709,20717,20707,20718, | ||
| 304 | 20729,20725,20745,20737,20738,20758,20757,20756,20762,20769,20794,20791,20796, | ||
| 305 | 20795,20799,20800,20818,20812,20820,20834,31480,20841,20842,20846,20864,20866, | ||
| 306 | 22232,20876,20873,20879,20881,20883,20885,20886,20900,20902,20898,20905,20906, | ||
| 307 | 20907,20915,20913,20914,20912,20917,20925,20933,20937,20955,20960,34389,20969, | ||
| 308 | 20973,20976,20981,20990,20996,21003,21012,21006,21031,21034,21038,21043,21049, | ||
| 309 | 21071,21060,21067,21068,21086,21076,21098,21108,21097,21107,21119,21117,21133, | ||
| 310 | 21140,21138,21105,21128,21137,36776,36775, | ||
| 311 | 21164,21165,21180,21173,21185,21197,21207,21214,21219,21222,39149,21216,21235, | ||
| 312 | 21237,21240,21241,21254,21256,30008,21261,21264,21263,21269,21274,21283,21295, | ||
| 313 | 21297,21299,21304,21312,21318,21317,19991,21321,21325,20950,21342,21353,21358, | ||
| 314 | 22808,21371,21367,21378,21398,21408,21414,21413,21422,21424,21430,21443,31762, | ||
| 315 | 38617,21471,26364,29166,21486,21480,21485,21498,21505,21565,21568,21548,21549, | ||
| 316 | 21564,21550,21558,21545,21533,21582,21647,21621,21646,21599,21617,21623,21616, | ||
| 317 | 21650,21627,21632,21622,21636,21648,21638,21703,21666,21688,21669,21676,21700, | ||
| 318 | 21704,21672,21675,21698,21668,21694,21692,21720,21733,21734,21775,21780,21757, | ||
| 319 | 21742,21741,21754,21730,21817,21824,21859,21836,21806,21852,21829,21846,21847, | ||
| 320 | 21816,21811,21853,21913,21888,21679,21898,21919,21883,21886,21912,21918,21934, | ||
| 321 | 21884,21891,21929,21895,21928,21978,21957,21983,21956,21980,21988,21972,22036, | ||
| 322 | 22007,22038,22014,22013,22043,22009,22094,22096,29151,22068,22070,22066,22072, | ||
| 323 | 22123,22116,22063,22124,22122,22150,22144,22154,22176,22164,22159,22181,22190, | ||
| 324 | 22198,22196,22210,22204,22209,22211,22208,22216,22222,22225,22227,22231,22254, | ||
| 325 | 22265,22272,22271,22276,22281,22280,22283,22285,22291,22296,22294,21959,22300, | ||
| 326 | 22310,22327,22328,22350,22331,22336,22351,22377,22464,22408,22369,22399,22409, | ||
| 327 | 22419,22432,22451,22436,22442,22448,22467,22470,22484,22482,22483,22538,22486, | ||
| 328 | 22499,22539,22553,22557,22642,22561,22626,22603,22640,27584,22610,22589,22649, | ||
| 329 | 22661,22713,22687,22699,22714,22750,22715,22712,22702,22725,22739,22737,22743, | ||
| 330 | 22745,22744,22757,22748,22756,22751,22767,22778,22777, | ||
| 331 | 22779,22780,22781,22786,22794,22800,22811,26790,22821,22828,22829,22834,22840, | ||
| 332 | 22846,31442,22869,22864,22862,22874,22872,22882,22880,22887,22892,22889,22904, | ||
| 333 | 22913,22941,20318,20395,22947,22962,22982,23016,23004,22925,23001,23002,23077, | ||
| 334 | 23071,23057,23068,23049,23066,23104,23148,23113,23093,23094,23138,23146,23194, | ||
| 335 | 23228,23230,23243,23234,23229,23267,23255,23270,23273,23254,23290,23291,23308, | ||
| 336 | 23307,23318,23346,23248,23338,23350,23358,23363,23365,23360,23377,23381,23386, | ||
| 337 | 23387,23397,23401,23408,23411,23413,23416,25992,23418,23424,23427,23462,23480, | ||
| 338 | 23491,23495,23497,23508,23504,23524,23526,23522,23518,23525,23531,23536,23542, | ||
| 339 | 23539,23557,23559,23560,23565,23571,23584,23586,23592,23608,23609,23617,23622, | ||
| 340 | 23630,23635,23632,23631,23409,23660,23662,20066,23670,23673,23692,23697,23700, | ||
| 341 | 22939,23723,23739,23734,23740,23735,23749,23742,23751,23769,23785,23805,23802, | ||
| 342 | 23789,23948,23786,23819,23829,23831,23900,23839,23835,23825,23828,23842,23834, | ||
| 343 | 23833,23832,23884,23890,23886,23883,23916,23923,23926,23943,23940,23938,23970, | ||
| 344 | 23965,23980,23982,23997,23952,23991,23996,24009,24013,24019,24018,24022,24027, | ||
| 345 | 24043,24050,24053,24075,24090,24089,24081,24091,24118,24119,24132,24131,24128, | ||
| 346 | 24142,24151,24148,24159,24162,24164,24135,24181,24182,24186,40636,24191,24224, | ||
| 347 | 24257,24258,24264,24272,24271,24278,24291,24285,24282,24283,24290,24289,24296, | ||
| 348 | 24297,24300,24305,24307,24304,24308,24312,24318,24323,24329,24413,24412,24331, | ||
| 349 | 24337,24342,24361,24365,24376,24385,24392,24396,24398,24367,24401,24406,24407, | ||
| 350 | 24409,24417,24429,24435,24439,24451,24450,24447,24458, | ||
| 351 | 24456,24465,24455,24478,24473,24472,24480,24488,24493,24508,24534,24571,24548, | ||
| 352 | 24568,24561,24541,24755,24575,24609,24672,24601,24592,24617,24590,24625,24603, | ||
| 353 | 24597,24619,24614,24591,24634,24666,24641,24682,24695,24671,24650,24646,24653, | ||
| 354 | 24675,24643,24676,24642,24684,24683,24665,24705,24717,24807,24707,24730,24708, | ||
| 355 | 24731,24726,24727,24722,24743,24715,24801,24760,24800,24787,24756,24560,24765, | ||
| 356 | 24774,24757,24792,24909,24853,24838,24822,24823,24832,24820,24826,24835,24865, | ||
| 357 | 24827,24817,24845,24846,24903,24894,24872,24871,24906,24895,24892,24876,24884, | ||
| 358 | 24893,24898,24900,24947,24951,24920,24921,24922,24939,24948,24943,24933,24945, | ||
| 359 | 24927,24925,24915,24949,24985,24982,24967,25004,24980,24986,24970,24977,25003, | ||
| 360 | 25006,25036,25034,25033,25079,25032,25027,25030,25018,25035,32633,25037,25062, | ||
| 361 | 25059,25078,25082,25076,25087,25085,25084,25086,25088,25096,25097,25101,25100, | ||
| 362 | 25108,25115,25118,25121,25130,25134,25136,25138,25139,25153,25166,25182,25187, | ||
| 363 | 25179,25184,25192,25212,25218,25225,25214,25234,25235,25238,25300,25219,25236, | ||
| 364 | 25303,25297,25275,25295,25343,25286,25812,25288,25308,25292,25290,25282,25287, | ||
| 365 | 25243,25289,25356,25326,25329,25383,25346,25352,25327,25333,25424,25406,25421, | ||
| 366 | 25628,25423,25494,25486,25472,25515,25462,25507,25487,25481,25503,25525,25451, | ||
| 367 | 25449,25534,25577,25536,25542,25571,25545,25554,25590,25540,25622,25652,25606, | ||
| 368 | 25619,25638,25654,25885,25623,25640,25615,25703,25711,25718,25678,25898,25749, | ||
| 369 | 25747,25765,25769,25736,25788,25818,25810,25797,25799,25787,25816,25794,25841, | ||
| 370 | 25831,33289,25824,25825,25260,25827,25839,25900,25846, | ||
| 371 | 25844,25842,25850,25856,25853,25880,25884,25861,25892,25891,25899,25908,25909, | ||
| 372 | 25911,25910,25912,30027,25928,25942,25941,25933,25944,25950,25949,25970,25976, | ||
| 373 | 25986,25987,35722,26011,26015,26027,26039,26051,26054,26049,26052,26060,26066, | ||
| 374 | 26075,26073,26080,26081,26097,26482,26122,26115,26107,26483,26165,26166,26164, | ||
| 375 | 26140,26191,26180,26185,26177,26206,26205,26212,26215,26216,26207,26210,26224, | ||
| 376 | 26243,26248,26254,26249,26244,26264,26269,26305,26297,26313,26302,26300,26308, | ||
| 377 | 26296,26326,26330,26336,26175,26342,26345,26352,26357,26359,26383,26390,26398, | ||
| 378 | 26406,26407,38712,26414,26431,26422,26433,26424,26423,26438,26462,26464,26457, | ||
| 379 | 26467,26468,26505,26480,26537,26492,26474,26508,26507,26534,26529,26501,26551, | ||
| 380 | 26607,26548,26604,26547,26601,26552,26596,26590,26589,26594,26606,26553,26574, | ||
| 381 | 26566,26599,27292,26654,26694,26665,26688,26701,26674,26702,26803,26667,26713, | ||
| 382 | 26723,26743,26751,26783,26767,26797,26772,26781,26779,26755,27310,26809,26740, | ||
| 383 | 26805,26784,26810,26895,26765,26750,26881,26826,26888,26840,26914,26918,26849, | ||
| 384 | 26892,26829,26836,26855,26837,26934,26898,26884,26839,26851,26917,26873,26848, | ||
| 385 | 26863,26920,26922,26906,26915,26913,26822,27001,26999,26972,27000,26987,26964, | ||
| 386 | 27006,26990,26937,26996,26941,26969,26928,26977,26974,26973,27009,26986,27058, | ||
| 387 | 27054,27088,27071,27073,27091,27070,27086,23528,27082,27101,27067,27075,27047, | ||
| 388 | 27182,27025,27040,27036,27029,27060,27102,27112,27138,27163,27135,27402,27129, | ||
| 389 | 27122,27111,27141,27057,27166,27117,27156,27115,27146,27154,27329,27171,27155, | ||
| 390 | 27204,27148,27250,27190,27256,27207,27234,27225,27238, | ||
| 391 | 27208,27192,27170,27280,27277,27296,27268,27298,27299,27287,34327,27323,27331, | ||
| 392 | 27330,27320,27315,27308,27358,27345,27359,27306,27354,27370,27387,27397,34326, | ||
| 393 | 27386,27410,27414,39729,27423,27448,27447,30428,27449,39150,27463,27459,27465, | ||
| 394 | 27472,27481,27476,27483,27487,27489,27512,27513,27519,27520,27524,27523,27533, | ||
| 395 | 27544,27541,27550,27556,27562,27563,27567,27570,27569,27571,27575,27580,27590, | ||
| 396 | 27595,27603,27615,27628,27627,27635,27631,40638,27656,27667,27668,27675,27684, | ||
| 397 | 27683,27742,27733,27746,27754,27778,27789,27802,27777,27803,27774,27752,27763, | ||
| 398 | 27794,27792,27844,27889,27859,27837,27863,27845,27869,27822,27825,27838,27834, | ||
| 399 | 27867,27887,27865,27882,27935,34893,27958,27947,27965,27960,27929,27957,27955, | ||
| 400 | 27922,27916,28003,28051,28004,27994,28025,27993,28046,28053,28644,28037,28153, | ||
| 401 | 28181,28170,28085,28103,28134,28088,28102,28140,28126,28108,28136,28114,28101, | ||
| 402 | 28154,28121,28132,28117,28138,28142,28205,28270,28206,28185,28274,28255,28222, | ||
| 403 | 28195,28267,28203,28278,28237,28191,28227,28218,28238,28196,28415,28189,28216, | ||
| 404 | 28290,28330,28312,28361,28343,28371,28349,28335,28356,28338,28372,28373,28303, | ||
| 405 | 28325,28354,28319,28481,28433,28748,28396,28408,28414,28479,28402,28465,28399, | ||
| 406 | 28466,28364,28478,28435,28407,28550,28538,28536,28545,28544,28527,28507,28659, | ||
| 407 | 28525,28546,28540,28504,28558,28561,28610,28518,28595,28579,28577,28580,28601, | ||
| 408 | 28614,28586,28639,28629,28652,28628,28632,28657,28654,28635,28681,28683,28666, | ||
| 409 | 28689,28673,28687,28670,28699,28698,28532,28701,28696,28703,28720,28734,28722, | ||
| 410 | 28753,28771,28825,28818,28847,28913,28844,28856,28851, | ||
| 411 | 28846,28895,28875,28893,28889,28937,28925,28956,28953,29029,29013,29064,29030, | ||
| 412 | 29026,29004,29014,29036,29071,29179,29060,29077,29096,29100,29143,29113,29118, | ||
| 413 | 29138,29129,29140,29134,29152,29164,29159,29173,29180,29177,29183,29197,29200, | ||
| 414 | 29211,29224,29229,29228,29232,29234,29243,29244,29247,29248,29254,29259,29272, | ||
| 415 | 29300,29310,29314,29313,29319,29330,29334,29346,29351,29369,29362,29379,29382, | ||
| 416 | 29380,29390,29394,29410,29408,29409,29433,29431,20495,29463,29450,29468,29462, | ||
| 417 | 29469,29492,29487,29481,29477,29502,29518,29519,40664,29527,29546,29544,29552, | ||
| 418 | 29560,29557,29563,29562,29640,29619,29646,29627,29632,29669,29678,29662,29858, | ||
| 419 | 29701,29807,29733,29688,29746,29754,29781,29759,29791,29785,29761,29788,29801, | ||
| 420 | 29808,29795,29802,29814,29822,29835,29854,29863,29898,29903,29908,29681,29920, | ||
| 421 | 29923,29927,29929,29934,29938,29936,29937,29944,29943,29956,29955,29957,29964, | ||
| 422 | 29966,29965,29973,29971,29982,29990,29996,30012,30020,30029,30026,30025,30043, | ||
| 423 | 30022,30042,30057,30052,30055,30059,30061,30072,30070,30086,30087,30068,30090, | ||
| 424 | 30089,30082,30100,30106,30109,30117,30115,30146,30131,30147,30133,30141,30136, | ||
| 425 | 30140,30129,30157,30154,30162,30169,30179,30174,30206,30207,30204,30209,30192, | ||
| 426 | 30202,30194,30195,30219,30221,30217,30239,30247,30240,30241,30242,30244,30260, | ||
| 427 | 30256,30267,30279,30280,30278,30300,30296,30305,30306,30312,30313,30314,30311, | ||
| 428 | 30316,30320,30322,30326,30328,30332,30336,30339,30344,30347,30350,30358,30355, | ||
| 429 | 30361,30362,30384,30388,30392,30393,30394,30402,30413,30422,30418,30430,30433, | ||
| 430 | 30437,30439,30442,34351,30459,30472,30471,30468,30505, | ||
| 431 | 30500,30494,30501,30502,30491,30519,30520,30535,30554,30568,30571,30555,30565, | ||
| 432 | 30591,30590,30585,30606,30603,30609,30624,30622,30640,30646,30649,30655,30652, | ||
| 433 | 30653,30651,30663,30669,30679,30682,30684,30691,30702,30716,30732,30738,31014, | ||
| 434 | 30752,31018,30789,30862,30836,30854,30844,30874,30860,30883,30901,30890,30895, | ||
| 435 | 30929,30918,30923,30932,30910,30908,30917,30922,30956,30951,30938,30973,30964, | ||
| 436 | 30983,30994,30993,31001,31020,31019,31040,31072,31063,31071,31066,31061,31059, | ||
| 437 | 31098,31103,31114,31133,31143,40779,31146,31150,31155,31161,31162,31177,31189, | ||
| 438 | 31207,31212,31201,31203,31240,31245,31256,31257,31264,31263,31104,31281,31291, | ||
| 439 | 31294,31287,31299,31319,31305,31329,31330,31337,40861,31344,31353,31357,31368, | ||
| 440 | 31383,31381,31384,31382,31401,31432,31408,31414,31429,31428,31423,36995,31431, | ||
| 441 | 31434,31437,31439,31445,31443,31449,31450,31453,31457,31458,31462,31469,31472, | ||
| 442 | 31490,31503,31498,31494,31539,31512,31513,31518,31541,31528,31542,31568,31610, | ||
| 443 | 31492,31565,31499,31564,31557,31605,31589,31604,31591,31600,31601,31596,31598, | ||
| 444 | 31645,31640,31647,31629,31644,31642,31627,31634,31631,31581,31641,31691,31681, | ||
| 445 | 31692,31695,31668,31686,31709,31721,31761,31764,31718,31717,31840,31744,31751, | ||
| 446 | 31763,31731,31735,31767,31757,31734,31779,31783,31786,31775,31799,31787,31805, | ||
| 447 | 31820,31811,31828,31823,31808,31824,31832,31839,31844,31830,31845,31852,31861, | ||
| 448 | 31875,31888,31908,31917,31906,31915,31905,31912,31923,31922,31921,31918,31929, | ||
| 449 | 31933,31936,31941,31938,31960,31954,31964,31970,39739,31983,31986,31988,31990, | ||
| 450 | 31994,32006,32002,32028,32021,32010,32069,32075,32046, | ||
| 451 | 32050,32063,32053,32070,32115,32086,32078,32114,32104,32110,32079,32099,32147, | ||
| 452 | 32137,32091,32143,32125,32155,32186,32174,32163,32181,32199,32189,32171,32317, | ||
| 453 | 32162,32175,32220,32184,32159,32176,32216,32221,32228,32222,32251,32242,32225, | ||
| 454 | 32261,32266,32291,32289,32274,32305,32287,32265,32267,32290,32326,32358,32315, | ||
| 455 | 32309,32313,32323,32311,32306,32314,32359,32349,32342,32350,32345,32346,32377, | ||
| 456 | 32362,32361,32380,32379,32387,32213,32381,36782,32383,32392,32393,32396,32402, | ||
| 457 | 32400,32403,32404,32406,32398,32411,32412,32568,32570,32581,32588,32589,32590, | ||
| 458 | 32592,32593,32597,32596,32600,32607,32608,32616,32617,32615,32632,32642,32646, | ||
| 459 | 32643,32648,32647,32652,32660,32670,32669,32666,32675,32687,32690,32697,32686, | ||
| 460 | 32694,32696,35697,32709,32710,32714,32725,32724,32737,32742,32745,32755,32761, | ||
| 461 | 39132,32774,32772,32779,32786,32792,32793,32796,32801,32808,32831,32827,32842, | ||
| 462 | 32838,32850,32856,32858,32863,32866,32872,32883,32882,32880,32886,32889,32893, | ||
| 463 | 32895,32900,32902,32901,32923,32915,32922,32941,20880,32940,32987,32997,32985, | ||
| 464 | 32989,32964,32986,32982,33033,33007,33009,33051,33065,33059,33071,33099,38539, | ||
| 465 | 33094,33086,33107,33105,33020,33137,33134,33125,33126,33140,33155,33160,33162, | ||
| 466 | 33152,33154,33184,33173,33188,33187,33119,33171,33193,33200,33205,33214,33208, | ||
| 467 | 33213,33216,33218,33210,33225,33229,33233,33241,33240,33224,33242,33247,33248, | ||
| 468 | 33255,33274,33275,33278,33281,33282,33285,33287,33290,33293,33296,33302,33321, | ||
| 469 | 33323,33336,33331,33344,33369,33368,33373,33370,33375,33380,33378,33384,33386, | ||
| 470 | 33387,33326,33393,33399,33400,33406,33421,33426,33451, | ||
| 471 | 33439,33467,33452,33505,33507,33503,33490,33524,33523,33530,33683,33539,33531, | ||
| 472 | 33529,33502,33542,33500,33545,33497,33589,33588,33558,33586,33585,33600,33593, | ||
| 473 | 33616,33605,33583,33579,33559,33560,33669,33690,33706,33695,33698,33686,33571, | ||
| 474 | 33678,33671,33674,33660,33717,33651,33653,33696,33673,33704,33780,33811,33771, | ||
| 475 | 33742,33789,33795,33752,33803,33729,33783,33799,33760,33778,33805,33826,33824, | ||
| 476 | 33725,33848,34054,33787,33901,33834,33852,34138,33924,33911,33899,33965,33902, | ||
| 477 | 33922,33897,33862,33836,33903,33913,33845,33994,33890,33977,33983,33951,34009, | ||
| 478 | 33997,33979,34010,34000,33985,33990,34006,33953,34081,34047,34036,34071,34072, | ||
| 479 | 34092,34079,34069,34068,34044,34112,34147,34136,34120,34113,34306,34123,34133, | ||
| 480 | 34176,34212,34184,34193,34186,34216,34157,34196,34203,34282,34183,34204,34167, | ||
| 481 | 34174,34192,34249,34234,34255,34233,34256,34261,34269,34277,34268,34297,34314, | ||
| 482 | 34323,34315,34302,34298,34310,34338,34330,34352,34367,34381,20053,34388,34399, | ||
| 483 | 34407,34417,34451,34467,34473,34474,34443,34444,34486,34479,34500,34502,34480, | ||
| 484 | 34505,34851,34475,34516,34526,34537,34540,34527,34523,34543,34578,34566,34568, | ||
| 485 | 34560,34563,34555,34577,34569,34573,34553,34570,34612,34623,34615,34619,34597, | ||
| 486 | 34601,34586,34656,34655,34680,34636,34638,34676,34647,34664,34670,34649,34643, | ||
| 487 | 34659,34666,34821,34722,34719,34690,34735,34763,34749,34752,34768,38614,34731, | ||
| 488 | 34756,34739,34759,34758,34747,34799,34802,34784,34831,34829,34814,34806,34807, | ||
| 489 | 34830,34770,34833,34838,34837,34850,34849,34865,34870,34873,34855,34875,34884, | ||
| 490 | 34882,34898,34905,34910,34914,34923,34945,34942,34974, | ||
| 491 | 34933,34941,34997,34930,34946,34967,34962,34990,34969,34978,34957,34980,34992, | ||
| 492 | 35007,34993,35011,35012,35028,35032,35033,35037,35065,35074,35068,35060,35048, | ||
| 493 | 35058,35076,35084,35082,35091,35139,35102,35109,35114,35115,35137,35140,35131, | ||
| 494 | 35126,35128,35148,35101,35168,35166,35174,35172,35181,35178,35183,35188,35191, | ||
| 495 | 35198,35203,35208,35210,35219,35224,35233,35241,35238,35244,35247,35250,35258, | ||
| 496 | 35261,35263,35264,35290,35292,35293,35303,35316,35320,35331,35350,35344,35340, | ||
| 497 | 35355,35357,35365,35382,35393,35419,35410,35398,35400,35452,35437,35436,35426, | ||
| 498 | 35461,35458,35460,35496,35489,35473,35493,35494,35482,35491,35524,35533,35522, | ||
| 499 | 35546,35563,35571,35559,35556,35569,35604,35552,35554,35575,35550,35547,35596, | ||
| 500 | 35591,35610,35553,35606,35600,35607,35616,35635,38827,35622,35627,35646,35624, | ||
| 501 | 35649,35660,35663,35662,35657,35670,35675,35674,35691,35679,35692,35695,35700, | ||
| 502 | 35709,35712,35724,35726,35730,35731,35734,35737,35738,35898,35905,35903,35912, | ||
| 503 | 35916,35918,35920,35925,35938,35948,35960,35962,35970,35977,35973,35978,35981, | ||
| 504 | 35982,35988,35964,35992,25117,36013,36010,36029,36018,36019,36014,36022,36040, | ||
| 505 | 36033,36068,36067,36058,36093,36090,36091,36100,36101,36106,36103,36111,36109, | ||
| 506 | 36112,40782,36115,36045,36116,36118,36199,36205,36209,36211,36225,36249,36290, | ||
| 507 | 36286,36282,36303,36314,36310,36300,36315,36299,36330,36331,36319,36323,36348, | ||
| 508 | 36360,36361,36351,36381,36382,36368,36383,36418,36405,36400,36404,36426,36423, | ||
| 509 | 36425,36428,36432,36424,36441,36452,36448,36394,36451,36437,36470,36466,36476, | ||
| 510 | 36481,36487,36485,36484,36491,36490,36499,36497,36500, | ||
| 511 | 36505,36522,36513,36524,36528,36550,36529,36542,36549,36552,36555,36571,36579, | ||
| 512 | 36604,36603,36587,36606,36618,36613,36629,36626,36633,36627,36636,36639,36635, | ||
| 513 | 36620,36646,36659,36667,36665,36677,36674,36670,36684,36681,36678,36686,36695, | ||
| 514 | 36700,36706,36707,36708,36764,36767,36771,36781,36783,36791,36826,36837,36834, | ||
| 515 | 36842,36847,36999,36852,36869,36857,36858,36881,36885,36897,36877,36894,36886, | ||
| 516 | 36875,36903,36918,36917,36921,36856,36943,36944,36945,36946,36878,36937,36926, | ||
| 517 | 36950,36952,36958,36968,36975,36982,38568,36978,36994,36989,36993,36992,37002, | ||
| 518 | 37001,37007,37032,37039,37041,37045,37090,37092,25160,37083,37122,37138,37145, | ||
| 519 | 37170,37168,37194,37206,37208,37219,37221,37225,37235,37234,37259,37257,37250, | ||
| 520 | 37282,37291,37295,37290,37301,37300,37306,37312,37313,37321,37323,37328,37334, | ||
| 521 | 37343,37345,37339,37372,37365,37366,37406,37375,37396,37420,37397,37393,37470, | ||
| 522 | 37463,37445,37449,37476,37448,37525,37439,37451,37456,37532,37526,37523,37531, | ||
| 523 | 37466,37583,37561,37559,37609,37647,37626,37700,37678,37657,37666,37658,37667, | ||
| 524 | 37690,37685,37691,37724,37728,37756,37742,37718,37808,37804,37805,37780,37817, | ||
| 525 | 37846,37847,37864,37861,37848,37827,37853,37840,37832,37860,37914,37908,37907, | ||
| 526 | 37891,37895,37904,37942,37931,37941,37921,37946,37953,37970,37956,37979,37984, | ||
| 527 | 37986,37982,37994,37417,38000,38005,38007,38013,37978,38012,38014,38017,38015, | ||
| 528 | 38274,38279,38282,38292,38294,38296,38297,38304,38312,38311,38317,38332,38331, | ||
| 529 | 38329,38334,38346,28662,38339,38349,38348,38357,38356,38358,38364,38369,38373, | ||
| 530 | 38370,38433,38440,38446,38447,38466,38476,38479,38475, | ||
| 531 | 38519,38492,38494,38493,38495,38502,38514,38508,38541,38552,38549,38551,38570, | ||
| 532 | 38567,38577,38578,38576,38580,38582,38584,38585,38606,38603,38601,38605,35149, | ||
| 533 | 38620,38669,38613,38649,38660,38662,38664,38675,38670,38673,38671,38678,38681, | ||
| 534 | 38692,38698,38704,38713,38717,38718,38724,38726,38728,38722,38729,38748,38752, | ||
| 535 | 38756,38758,38760,21202,38763,38769,38777,38789,38780,38785,38778,38790,38795, | ||
| 536 | 38799,38800,38812,38824,38822,38819,38835,38836,38851,38854,38856,38859,38876, | ||
| 537 | 38893,40783,38898,31455,38902,38901,38927,38924,38968,38948,38945,38967,38973, | ||
| 538 | 38982,38991,38987,39019,39023,39024,39025,39028,39027,39082,39087,39089,39094, | ||
| 539 | 39108,39107,39110,39145,39147,39171,39177,39186,39188,39192,39201,39197,39198, | ||
| 540 | 39204,39200,39212,39214,39229,39230,39234,39241,39237,39248,39243,39249,39250, | ||
| 541 | 39244,39253,39319,39320,39333,39341,39342,39356,39391,39387,39389,39384,39377, | ||
| 542 | 39405,39406,39409,39410,39419,39416,39425,39439,39429,39394,39449,39467,39479, | ||
| 543 | 39493,39490,39488,39491,39486,39509,39501,39515,39511,39519,39522,39525,39524, | ||
| 544 | 39529,39531,39530,39597,39600,39612,39616,39631,39633,39635,39636,39646,39647, | ||
| 545 | 39650,39651,39654,39663,39659,39662,39668,39665,39671,39675,39686,39704,39706, | ||
| 546 | 39711,39714,39715,39717,39719,39720,39721,39722,39726,39727,39730,39748,39747, | ||
| 547 | 39759,39757,39758,39761,39768,39796,39827,39811,39825,39830,39831,39839,39840, | ||
| 548 | 39848,39860,39872,39882,39865,39878,39887,39889,39890,39907,39906,39908,39892, | ||
| 549 | 39905,39994,39922,39921,39920,39957,39956,39945,39955,39948,39942,39944,39954, | ||
| 550 | 39946,39940,39982,39963,39973,39972,39969,39984,40007, | ||
| 551 | 39986,40006,39998,40026,40032,40039,40054,40056,40167,40172,40176,40201,40200, | ||
| 552 | 40171,40195,40198,40234,40230,40367,40227,40223,40260,40213,40210,40257,40255, | ||
| 553 | 40254,40262,40264,40285,40286,40292,40273,40272,40281,40306,40329,40327,40363, | ||
| 554 | 40303,40314,40346,40356,40361,40370,40388,40385,40379,40376,40378,40390,40399, | ||
| 555 | 40386,40409,40403,40440,40422,40429,40431,40445,40474,40475,40478,40565,40569, | ||
| 556 | 40573,40577,40584,40587,40588,40594,40597,40593,40605,40613,40617,40632,40618, | ||
| 557 | 40621,38753,40652,40654,40655,40656,40660,40668,40670,40669,40672,40677,40680, | ||
| 558 | 40687,40692,40694,40695,40697,40699,40700,40701,40711,40712,30391,40725,40737, | ||
| 559 | 40748,40766,40778,40786,40788,40803,40799,40800,40801,40806,40807,40812,40810, | ||
| 560 | 40823,40818,40822,40853,40860,40864,22575,27079,36953,29796,20956,29081,0,0,0, | ||
| 561 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 562 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 563 | 0,0,0,0,0,0,0, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/ksc.h created+650| ... | @@ -0,0 +1,650 @@ | ||
| 1 | 12288,12289,12290,183,8229,8230,168,12291,173,8213,8741,65340,8764,8216,8217, | ||
| 2 | 8220,8221,12308,12309,12296,12297,12298,12299,12300,12301,12302,12303,12304, | ||
| 3 | 12305,177,215,247,8800,8804,8805,8734,8756,176,8242,8243,8451,8491,65504, | ||
| 4 | 65505,65509,9794,9792,8736,8869,8978,8706,8711,8801,8786,167,8251,9734,9733, | ||
| 5 | 9675,9679,9678,9671,9670,9633,9632,9651,9650,9661,9660,8594,8592,8593,8595, | ||
| 6 | 8596,12307,8810,8811,8730,8765,8733,8757,8747,8748,8712,8715,8838,8839,8834, | ||
| 7 | 8835,8746,8745,8743,8744,65506,8658,8660,8704,8707,180,65374,711,728,733,730, | ||
| 8 | 729,184,731,161,191,720,8750,8721,8719,164,8457,8240,9665,9664,9655,9654,9828, | ||
| 9 | 9824,9825,9829,9831,9827,8857,9672,9635,9680,9681,9618,9636,9637,9640,9639, | ||
| 10 | 9638,9641,9832,9743,9742,9756,9758,182,8224,8225,8597,8599,8601,8598,8600, | ||
| 11 | 9837,9833,9834,9836,12927,12828,8470,13255,8482,13250,13272,8481,8364,174,0,0, | ||
| 12 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,65281,65282,65283,65284,65285,65286, | ||
| 13 | 65287,65288,65289,65290,65291,65292,65293,65294,65295,65296,65297,65298,65299, | ||
| 14 | 65300,65301,65302,65303,65304,65305,65306,65307,65308,65309,65310,65311,65312, | ||
| 15 | 65313,65314,65315,65316,65317,65318,65319,65320,65321,65322,65323,65324,65325, | ||
| 16 | 65326,65327,65328,65329,65330,65331,65332,65333,65334,65335,65336,65337,65338, | ||
| 17 | 65339,65510,65341,65342,65343,65344,65345,65346,65347, | ||
| 18 | 65348,65349,65350,65351,65352,65353,65354,65355,65356,65357,65358,65359,65360, | ||
| 19 | 65361,65362,65363,65364,65365,65366,65367,65368,65369,65370,65371,65372,65373, | ||
| 20 | 65507,12593,12594,12595,12596,12597,12598,12599,12600,12601,12602,12603,12604, | ||
| 21 | 12605,12606,12607,12608,12609,12610,12611,12612,12613,12614,12615,12616,12617, | ||
| 22 | 12618,12619,12620,12621,12622,12623,12624,12625,12626,12627,12628,12629,12630, | ||
| 23 | 12631,12632,12633,12634,12635,12636,12637,12638,12639,12640,12641,12642,12643, | ||
| 24 | 12644,12645,12646,12647,12648,12649,12650,12651,12652,12653,12654,12655,12656, | ||
| 25 | 12657,12658,12659,12660,12661,12662,12663,12664,12665,12666,12667,12668,12669, | ||
| 26 | 12670,12671,12672,12673,12674,12675,12676,12677,12678,12679,12680,12681,12682, | ||
| 27 | 12683,12684,12685,12686,8560,8561,8562,8563,8564,8565,8566,8567,8568,8569,0,0, | ||
| 28 | 0,0,0,8544,8545,8546,8547,8548,8549,8550,8551,8552,8553,0,0,0,0,0,0,0,913,914, | ||
| 29 | 915,916,917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934, | ||
| 30 | 935,936,937,0,0,0,0,0,0,0,0,945,946,947,948,949,950,951,952,953,954,955,956, | ||
| 31 | 957,958,959,960,961,963,964,965,966,967,968,969,0,0,0,0,0,0,9472,9474,9484, | ||
| 32 | 9488,9496,9492,9500,9516,9508,9524,9532,9473,9475,9487,9491,9499,9495,9507, | ||
| 33 | 9523,9515,9531,9547,9504,9519,9512,9527,9535,9501,9520,9509,9528,9538,9490, | ||
| 34 | 9489,9498,9497,9494,9493,9486,9485,9502, | ||
| 35 | 9503,9505,9506,9510,9511,9513,9514,9517,9518,9521,9522,9525,9526,9529,9530, | ||
| 36 | 9533,9534,9536,9537,9539,9540,9541,9542,9543,9544,9545,9546,0,0,0,0,0,0,0,0,0, | ||
| 37 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,13205,13206,13207,8467,13208,13252,13219, | ||
| 38 | 13220,13221,13222,13209,13210,13211,13212,13213,13214,13215,13216,13217,13218, | ||
| 39 | 13258,13197,13198,13199,13263,13192,13193,13256,13223,13224,13232,13233,13234, | ||
| 40 | 13235,13236,13237,13238,13239,13240,13241,13184,13185,13186,13187,13188,13242, | ||
| 41 | 13243,13244,13245,13246,13247,13200,13201,13202,13203,13204,8486,13248,13249, | ||
| 42 | 13194,13195,13196,13270,13253,13229,13230,13231,13275,13225,13226,13227,13228, | ||
| 43 | 13277,13264,13267,13251,13257,13276,13254,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,198, | ||
| 44 | 208,170,294,0,306,0,319,321,216,338,186,222,358,330,0,12896,12897,12898,12899, | ||
| 45 | 12900,12901,12902,12903,12904,12905,12906,12907,12908,12909,12910,12911,12912, | ||
| 46 | 12913,12914,12915,12916,12917,12918,12919,12920,12921,12922,12923,9424,9425, | ||
| 47 | 9426,9427,9428,9429,9430,9431,9432,9433,9434,9435,9436,9437,9438,9439,9440, | ||
| 48 | 9441,9442,9443,9444,9445,9446,9447,9448,9449,9312,9313,9314,9315,9316,9317, | ||
| 49 | 9318,9319,9320,9321,9322,9323,9324,9325,9326,189,8531,8532,188,190,8539,8540, | ||
| 50 | 8541,8542,230,273,240,295,305,307,312,320,322,248,339,223,254,359,331, | ||
| 51 | 329,12800,12801,12802,12803,12804,12805,12806,12807,12808,12809,12810,12811, | ||
| 52 | 12812,12813,12814,12815,12816,12817,12818,12819,12820,12821,12822,12823,12824, | ||
| 53 | 12825,12826,12827,9372,9373,9374,9375,9376,9377,9378,9379,9380,9381,9382,9383, | ||
| 54 | 9384,9385,9386,9387,9388,9389,9390,9391,9392,9393,9394,9395,9396,9397,9332, | ||
| 55 | 9333,9334,9335,9336,9337,9338,9339,9340,9341,9342,9343,9344,9345,9346,185,178, | ||
| 56 | 179,8308,8319,8321,8322,8323,8324,12353,12354,12355,12356,12357,12358,12359, | ||
| 57 | 12360,12361,12362,12363,12364,12365,12366,12367,12368,12369,12370,12371,12372, | ||
| 58 | 12373,12374,12375,12376,12377,12378,12379,12380,12381,12382,12383,12384,12385, | ||
| 59 | 12386,12387,12388,12389,12390,12391,12392,12393,12394,12395,12396,12397,12398, | ||
| 60 | 12399,12400,12401,12402,12403,12404,12405,12406,12407,12408,12409,12410,12411, | ||
| 61 | 12412,12413,12414,12415,12416,12417,12418,12419,12420,12421,12422,12423,12424, | ||
| 62 | 12425,12426,12427,12428,12429,12430,12431,12432,12433,12434,12435,0,0,0,0,0,0, | ||
| 63 | 0,0,0,0,0,12449,12450,12451,12452,12453,12454,12455,12456,12457,12458,12459, | ||
| 64 | 12460,12461,12462,12463,12464,12465,12466,12467,12468,12469,12470,12471,12472, | ||
| 65 | 12473,12474,12475,12476,12477,12478,12479,12480,12481,12482,12483,12484,12485, | ||
| 66 | 12486,12487,12488,12489,12490,12491,12492,12493,12494,12495,12496,12497,12498, | ||
| 67 | 12499,12500,12501,12502,12503,12504,12505,12506,12507,12508,12509,12510,12511, | ||
| 68 | 12512,12513,12514,12515,12516,12517,12518,12519,12520,12521,12522,12523,12524, | ||
| 69 | 12525,12526,12527,12528,12529,12530,12531, | ||
| 70 | 12532,12533,12534,0,0,0,0,0,0,0,0,1040,1041,1042,1043,1044,1045,1025,1046, | ||
| 71 | 1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060,1061, | ||
| 72 | 1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 73 | 0,1072,1073,1074,1075,1076,1077,1105,1078,1079,1080,1081,1082,1083,1084,1085, | ||
| 74 | 1086,1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100, | ||
| 75 | 1101,1102,1103,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 76 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 77 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 78 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 79 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 80 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 81 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 82 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 83 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,44032,44033,44036,44039,44040,44041,44042,44048, | ||
| 84 | 44049,44050,44051,44052,44053,44054,44055,44057,44058,44059,44060,44061,44064, | ||
| 85 | 44068,44076,44077,44079,44080,44081,44088,44089,44092,44096,44107,44109,44116, | ||
| 86 | 44120,44124,44144,44145,44148,44151,44152,44154,44160,44161,44163,44164,44165, | ||
| 87 | 44166,44169,44170,44171,44172,44176,44180,44188,44189,44191,44192,44193,44200, | ||
| 88 | 44201,44202,44204,44207,44208,44216,44217,44219,44220,44221,44225,44228,44232, | ||
| 89 | 44236,44245,44247,44256,44257,44260,44263,44264,44266,44268,44271,44272,44273, | ||
| 90 | 44275,44277,44278,44284,44285,44288,44292,44294,44300,44301,44303,44305,44312, | ||
| 91 | 44316,44320,44329,44332,44333,44340,44341,44344,44348,44356,44357,44359,44361, | ||
| 92 | 44368,44372,44376,44385,44387,44396,44397,44400,44403,44404,44405,44406,44411, | ||
| 93 | 44412,44413,44415,44417,44418,44424,44425,44428,44432,44444,44445,44452,44471, | ||
| 94 | 44480,44481,44484,44488,44496,44497,44499,44508,44512,44516,44536,44537,44540, | ||
| 95 | 44543,44544,44545,44552,44553,44555,44557,44564,44592,44593,44596,44599,44600, | ||
| 96 | 44602,44608,44609,44611,44613,44614,44618,44620,44621,44622,44624,44628,44630, | ||
| 97 | 44636,44637,44639,44640,44641,44645,44648,44649,44652,44656,44664,44665,44667, | ||
| 98 | 44668,44669,44676,44677,44684,44732,44733,44734,44736,44740,44748,44749,44751, | ||
| 99 | 44752,44753,44760,44761,44764,44776,44779,44781,44788,44792,44796,44807,44808, | ||
| 100 | 44813,44816,44844,44845,44848,44850,44852,44860,44861,44863,44865,44866,44867, | ||
| 101 | 44872,44873,44880,44892,44893,44900,44901,44921,44928,44932,44936,44944,44945, | ||
| 102 | 44949,44956,44984,44985,44988,44992,44999,45000,45001,45003,45005,45006,45012, | ||
| 103 | 45020,45032,45033,45040,45041,45044,45048,45056,45057,45060,45068,45072,45076, | ||
| 104 | 45084,45085,45096,45124,45125,45128,45130,45132,45134,45139,45140,45141,45143, | ||
| 105 | 45145,45149,45180,45181,45184,45188,45196,45197,45199,45201,45208,45209,45210, | ||
| 106 | 45212,45215,45216,45217,45218,45224,45225,45227,45228,45229,45230,45231,45233, | ||
| 107 | 45235,45236,45237,45240,45244,45252,45253,45255,45256,45257,45264,45265,45268, | ||
| 108 | 45272,45280,45285,45320,45321,45323,45324,45328,45330,45331,45336,45337,45339, | ||
| 109 | 45340,45341,45347,45348,45349,45352,45356,45364,45365,45367,45368,45369,45376, | ||
| 110 | 45377,45380,45384,45392,45393,45396,45397,45400,45404,45408,45432,45433,45436, | ||
| 111 | 45440,45442,45448,45449,45451,45453,45458,45459,45460,45464,45468,45480,45516, | ||
| 112 | 45520,45524,45532,45533,45535,45544,45545,45548,45552, | ||
| 113 | 45561,45563,45565,45572,45573,45576,45579,45580,45588,45589,45591,45593,45600, | ||
| 114 | 45620,45628,45656,45660,45664,45672,45673,45684,45685,45692,45700,45701,45705, | ||
| 115 | 45712,45713,45716,45720,45721,45722,45728,45729,45731,45733,45734,45738,45740, | ||
| 116 | 45744,45748,45768,45769,45772,45776,45778,45784,45785,45787,45789,45794,45796, | ||
| 117 | 45797,45798,45800,45803,45804,45805,45806,45807,45811,45812,45813,45815,45816, | ||
| 118 | 45817,45818,45819,45823,45824,45825,45828,45832,45840,45841,45843,45844,45845, | ||
| 119 | 45852,45908,45909,45910,45912,45915,45916,45918,45919,45924,45925,45927,45929, | ||
| 120 | 45931,45934,45936,45937,45940,45944,45952,45953,45955,45956,45957,45964,45968, | ||
| 121 | 45972,45984,45985,45992,45996,46020,46021,46024,46027,46028,46030,46032,46036, | ||
| 122 | 46037,46039,46041,46043,46045,46048,46052,46056,46076,46096,46104,46108,46112, | ||
| 123 | 46120,46121,46123,46132,46160,46161,46164,46168,46176,46177,46179,46181,46188, | ||
| 124 | 46208,46216,46237,46244,46248,46252,46261,46263,46265,46272,46276,46280,46288, | ||
| 125 | 46293,46300,46301,46304,46307,46308,46310,46316,46317,46319,46321,46328,46356, | ||
| 126 | 46357,46360,46363,46364,46372,46373,46375,46376,46377,46378,46384,46385,46388, | ||
| 127 | 46392,46400,46401,46403,46404,46405,46411,46412,46413,46416,46420,46428,46429, | ||
| 128 | 46431,46432,46433,46496,46497,46500,46504,46506,46507,46512,46513,46515,46516, | ||
| 129 | 46517,46523,46524,46525,46528,46532,46540,46541,46543,46544,46545,46552,46572, | ||
| 130 | 46608,46609,46612,46616,46629,46636,46644,46664,46692,46696,46748,46749,46752, | ||
| 131 | 46756,46763,46764,46769,46804,46832,46836,46840,46848,46849,46853,46888,46889, | ||
| 132 | 46892,46895,46896,46904,46905,46907,46916,46920,46924, | ||
| 133 | 46932,46933,46944,46948,46952,46960,46961,46963,46965,46972,46973,46976,46980, | ||
| 134 | 46988,46989,46991,46992,46993,46994,46998,46999,47000,47001,47004,47008,47016, | ||
| 135 | 47017,47019,47020,47021,47028,47029,47032,47047,47049,47084,47085,47088,47092, | ||
| 136 | 47100,47101,47103,47104,47105,47111,47112,47113,47116,47120,47128,47129,47131, | ||
| 137 | 47133,47140,47141,47144,47148,47156,47157,47159,47160,47161,47168,47172,47185, | ||
| 138 | 47187,47196,47197,47200,47204,47212,47213,47215,47217,47224,47228,47245,47272, | ||
| 139 | 47280,47284,47288,47296,47297,47299,47301,47308,47312,47316,47325,47327,47329, | ||
| 140 | 47336,47337,47340,47344,47352,47353,47355,47357,47364,47384,47392,47420,47421, | ||
| 141 | 47424,47428,47436,47439,47441,47448,47449,47452,47456,47464,47465,47467,47469, | ||
| 142 | 47476,47477,47480,47484,47492,47493,47495,47497,47498,47501,47502,47532,47533, | ||
| 143 | 47536,47540,47548,47549,47551,47553,47560,47561,47564,47566,47567,47568,47569, | ||
| 144 | 47570,47576,47577,47579,47581,47582,47585,47587,47588,47589,47592,47596,47604, | ||
| 145 | 47605,47607,47608,47609,47610,47616,47617,47624,47637,47672,47673,47676,47680, | ||
| 146 | 47682,47688,47689,47691,47693,47694,47699,47700,47701,47704,47708,47716,47717, | ||
| 147 | 47719,47720,47721,47728,47729,47732,47736,47747,47748,47749,47751,47756,47784, | ||
| 148 | 47785,47787,47788,47792,47794,47800,47801,47803,47805,47812,47816,47832,47833, | ||
| 149 | 47868,47872,47876,47885,47887,47889,47896,47900,47904,47913,47915,47924,47925, | ||
| 150 | 47926,47928,47931,47932,47933,47934,47940,47941,47943,47945,47949,47951,47952, | ||
| 151 | 47956,47960,47969,47971,47980,48008,48012,48016,48036,48040,48044,48052,48055, | ||
| 152 | 48064,48068,48072,48080,48083,48120,48121,48124,48127, | ||
| 153 | 48128,48130,48136,48137,48139,48140,48141,48143,48145,48148,48149,48150,48151, | ||
| 154 | 48152,48155,48156,48157,48158,48159,48164,48165,48167,48169,48173,48176,48177, | ||
| 155 | 48180,48184,48192,48193,48195,48196,48197,48201,48204,48205,48208,48221,48260, | ||
| 156 | 48261,48264,48267,48268,48270,48276,48277,48279,48281,48282,48288,48289,48292, | ||
| 157 | 48295,48296,48304,48305,48307,48308,48309,48316,48317,48320,48324,48333,48335, | ||
| 158 | 48336,48337,48341,48344,48348,48372,48373,48374,48376,48380,48388,48389,48391, | ||
| 159 | 48393,48400,48404,48420,48428,48448,48456,48457,48460,48464,48472,48473,48484, | ||
| 160 | 48488,48512,48513,48516,48519,48520,48521,48522,48528,48529,48531,48533,48537, | ||
| 161 | 48538,48540,48548,48560,48568,48596,48597,48600,48604,48617,48624,48628,48632, | ||
| 162 | 48640,48643,48645,48652,48653,48656,48660,48668,48669,48671,48708,48709,48712, | ||
| 163 | 48716,48718,48724,48725,48727,48729,48730,48731,48736,48737,48740,48744,48746, | ||
| 164 | 48752,48753,48755,48756,48757,48763,48764,48765,48768,48772,48780,48781,48783, | ||
| 165 | 48784,48785,48792,48793,48808,48848,48849,48852,48855,48856,48864,48867,48868, | ||
| 166 | 48869,48876,48897,48904,48905,48920,48921,48923,48924,48925,48960,48961,48964, | ||
| 167 | 48968,48976,48977,48981,49044,49072,49093,49100,49101,49104,49108,49116,49119, | ||
| 168 | 49121,49212,49233,49240,49244,49248,49256,49257,49296,49297,49300,49304,49312, | ||
| 169 | 49313,49315,49317,49324,49325,49327,49328,49331,49332,49333,49334,49340,49341, | ||
| 170 | 49343,49344,49345,49349,49352,49353,49356,49360,49368,49369,49371,49372,49373, | ||
| 171 | 49380,49381,49384,49388,49396,49397,49399,49401,49408,49412,49416,49424,49429, | ||
| 172 | 49436,49437,49438,49439,49440,49443,49444,49446,49447, | ||
| 173 | 49452,49453,49455,49456,49457,49462,49464,49465,49468,49472,49480,49481,49483, | ||
| 174 | 49484,49485,49492,49493,49496,49500,49508,49509,49511,49512,49513,49520,49524, | ||
| 175 | 49528,49541,49548,49549,49550,49552,49556,49558,49564,49565,49567,49569,49573, | ||
| 176 | 49576,49577,49580,49584,49597,49604,49608,49612,49620,49623,49624,49632,49636, | ||
| 177 | 49640,49648,49649,49651,49660,49661,49664,49668,49676,49677,49679,49681,49688, | ||
| 178 | 49689,49692,49695,49696,49704,49705,49707,49709,49711,49713,49714,49716,49736, | ||
| 179 | 49744,49745,49748,49752,49760,49765,49772,49773,49776,49780,49788,49789,49791, | ||
| 180 | 49793,49800,49801,49808,49816,49819,49821,49828,49829,49832,49836,49837,49844, | ||
| 181 | 49845,49847,49849,49884,49885,49888,49891,49892,49899,49900,49901,49903,49905, | ||
| 182 | 49910,49912,49913,49915,49916,49920,49928,49929,49932,49933,49939,49940,49941, | ||
| 183 | 49944,49948,49956,49957,49960,49961,49989,50024,50025,50028,50032,50034,50040, | ||
| 184 | 50041,50044,50045,50052,50056,50060,50112,50136,50137,50140,50143,50144,50146, | ||
| 185 | 50152,50153,50157,50164,50165,50168,50184,50192,50212,50220,50224,50228,50236, | ||
| 186 | 50237,50248,50276,50277,50280,50284,50292,50293,50297,50304,50324,50332,50360, | ||
| 187 | 50364,50409,50416,50417,50420,50424,50426,50431,50432,50433,50444,50448,50452, | ||
| 188 | 50460,50472,50473,50476,50480,50488,50489,50491,50493,50500,50501,50504,50505, | ||
| 189 | 50506,50508,50509,50510,50515,50516,50517,50519,50520,50521,50525,50526,50528, | ||
| 190 | 50529,50532,50536,50544,50545,50547,50548,50549,50556,50557,50560,50564,50567, | ||
| 191 | 50572,50573,50575,50577,50581,50583,50584,50588,50592,50601,50612,50613,50616, | ||
| 192 | 50617,50619,50620,50621,50622,50628,50629,50630,50631, | ||
| 193 | 50632,50633,50634,50636,50638,50640,50641,50644,50648,50656,50657,50659,50661, | ||
| 194 | 50668,50669,50670,50672,50676,50678,50679,50684,50685,50686,50687,50688,50689, | ||
| 195 | 50693,50694,50695,50696,50700,50704,50712,50713,50715,50716,50724,50725,50728, | ||
| 196 | 50732,50733,50734,50736,50739,50740,50741,50743,50745,50747,50752,50753,50756, | ||
| 197 | 50760,50768,50769,50771,50772,50773,50780,50781,50784,50796,50799,50801,50808, | ||
| 198 | 50809,50812,50816,50824,50825,50827,50829,50836,50837,50840,50844,50852,50853, | ||
| 199 | 50855,50857,50864,50865,50868,50872,50873,50874,50880,50881,50883,50885,50892, | ||
| 200 | 50893,50896,50900,50908,50909,50912,50913,50920,50921,50924,50928,50936,50937, | ||
| 201 | 50941,50948,50949,50952,50956,50964,50965,50967,50969,50976,50977,50980,50984, | ||
| 202 | 50992,50993,50995,50997,50999,51004,51005,51008,51012,51018,51020,51021,51023, | ||
| 203 | 51025,51026,51027,51028,51029,51030,51031,51032,51036,51040,51048,51051,51060, | ||
| 204 | 51061,51064,51068,51069,51070,51075,51076,51077,51079,51080,51081,51082,51086, | ||
| 205 | 51088,51089,51092,51094,51095,51096,51098,51104,51105,51107,51108,51109,51110, | ||
| 206 | 51116,51117,51120,51124,51132,51133,51135,51136,51137,51144,51145,51148,51150, | ||
| 207 | 51152,51160,51165,51172,51176,51180,51200,51201,51204,51208,51210,51216,51217, | ||
| 208 | 51219,51221,51222,51228,51229,51232,51236,51244,51245,51247,51249,51256,51260, | ||
| 209 | 51264,51272,51273,51276,51277,51284,51312,51313,51316,51320,51322,51328,51329, | ||
| 210 | 51331,51333,51334,51335,51339,51340,51341,51348,51357,51359,51361,51368,51388, | ||
| 211 | 51389,51396,51400,51404,51412,51413,51415,51417,51424,51425,51428,51445,51452, | ||
| 212 | 51453,51456,51460,51461,51462,51468,51469,51471,51473, | ||
| 213 | 51480,51500,51508,51536,51537,51540,51544,51552,51553,51555,51564,51568,51572, | ||
| 214 | 51580,51592,51593,51596,51600,51608,51609,51611,51613,51648,51649,51652,51655, | ||
| 215 | 51656,51658,51664,51665,51667,51669,51670,51673,51674,51676,51677,51680,51682, | ||
| 216 | 51684,51687,51692,51693,51695,51696,51697,51704,51705,51708,51712,51720,51721, | ||
| 217 | 51723,51724,51725,51732,51736,51753,51788,51789,51792,51796,51804,51805,51807, | ||
| 218 | 51808,51809,51816,51837,51844,51864,51900,51901,51904,51908,51916,51917,51919, | ||
| 219 | 51921,51923,51928,51929,51936,51948,51956,51976,51984,51988,51992,52000,52001, | ||
| 220 | 52033,52040,52041,52044,52048,52056,52057,52061,52068,52088,52089,52124,52152, | ||
| 221 | 52180,52196,52199,52201,52236,52237,52240,52244,52252,52253,52257,52258,52263, | ||
| 222 | 52264,52265,52268,52270,52272,52280,52281,52283,52284,52285,52286,52292,52293, | ||
| 223 | 52296,52300,52308,52309,52311,52312,52313,52320,52324,52326,52328,52336,52341, | ||
| 224 | 52376,52377,52380,52384,52392,52393,52395,52396,52397,52404,52405,52408,52412, | ||
| 225 | 52420,52421,52423,52425,52432,52436,52452,52460,52464,52481,52488,52489,52492, | ||
| 226 | 52496,52504,52505,52507,52509,52516,52520,52524,52537,52572,52576,52580,52588, | ||
| 227 | 52589,52591,52593,52600,52616,52628,52629,52632,52636,52644,52645,52647,52649, | ||
| 228 | 52656,52676,52684,52688,52712,52716,52720,52728,52729,52731,52733,52740,52744, | ||
| 229 | 52748,52756,52761,52768,52769,52772,52776,52784,52785,52787,52789,52824,52825, | ||
| 230 | 52828,52831,52832,52833,52840,52841,52843,52845,52852,52853,52856,52860,52868, | ||
| 231 | 52869,52871,52873,52880,52881,52884,52888,52896,52897,52899,52900,52901,52908, | ||
| 232 | 52909,52929,52964,52965,52968,52971,52972,52980,52981, | ||
| 233 | 52983,52984,52985,52992,52993,52996,53000,53008,53009,53011,53013,53020,53024, | ||
| 234 | 53028,53036,53037,53039,53040,53041,53048,53076,53077,53080,53084,53092,53093, | ||
| 235 | 53095,53097,53104,53105,53108,53112,53120,53125,53132,53153,53160,53168,53188, | ||
| 236 | 53216,53217,53220,53224,53232,53233,53235,53237,53244,53248,53252,53265,53272, | ||
| 237 | 53293,53300,53301,53304,53308,53316,53317,53319,53321,53328,53332,53336,53344, | ||
| 238 | 53356,53357,53360,53364,53372,53373,53377,53412,53413,53416,53420,53428,53429, | ||
| 239 | 53431,53433,53440,53441,53444,53448,53449,53456,53457,53459,53460,53461,53468, | ||
| 240 | 53469,53472,53476,53484,53485,53487,53488,53489,53496,53517,53552,53553,53556, | ||
| 241 | 53560,53562,53568,53569,53571,53572,53573,53580,53581,53584,53588,53596,53597, | ||
| 242 | 53599,53601,53608,53612,53628,53636,53640,53664,53665,53668,53672,53680,53681, | ||
| 243 | 53683,53685,53690,53692,53696,53720,53748,53752,53767,53769,53776,53804,53805, | ||
| 244 | 53808,53812,53820,53821,53823,53825,53832,53852,53860,53888,53889,53892,53896, | ||
| 245 | 53904,53905,53909,53916,53920,53924,53932,53937,53944,53945,53948,53951,53952, | ||
| 246 | 53954,53960,53961,53963,53972,53976,53980,53988,53989,54000,54001,54004,54008, | ||
| 247 | 54016,54017,54019,54021,54028,54029,54030,54032,54036,54038,54044,54045,54047, | ||
| 248 | 54048,54049,54053,54056,54057,54060,54064,54072,54073,54075,54076,54077,54084, | ||
| 249 | 54085,54140,54141,54144,54148,54156,54157,54159,54160,54161,54168,54169,54172, | ||
| 250 | 54176,54184,54185,54187,54189,54196,54200,54204,54212,54213,54216,54217,54224, | ||
| 251 | 54232,54241,54243,54252,54253,54256,54260,54268,54269,54271,54273,54280,54301, | ||
| 252 | 54336,54340,54364,54368,54372,54381,54383,54392,54393, | ||
| 253 | 54396,54399,54400,54402,54408,54409,54411,54413,54420,54441,54476,54480,54484, | ||
| 254 | 54492,54495,54504,54508,54512,54520,54523,54525,54532,54536,54540,54548,54549, | ||
| 255 | 54551,54588,54589,54592,54596,54604,54605,54607,54609,54616,54617,54620,54624, | ||
| 256 | 54629,54632,54633,54635,54637,54644,54645,54648,54652,54660,54661,54663,54664, | ||
| 257 | 54665,54672,54693,54728,54729,54732,54736,54738,54744,54745,54747,54749,54756, | ||
| 258 | 54757,54760,54764,54772,54773,54775,54777,54784,54785,54788,54792,54800,54801, | ||
| 259 | 54803,54804,54805,54812,54816,54820,54829,54840,54841,54844,54848,54853,54856, | ||
| 260 | 54857,54859,54861,54865,54868,54869,54872,54876,54887,54889,54896,54897,54900, | ||
| 261 | 54915,54917,54924,54925,54928,54932,54941,54943,54945,54952,54956,54960,54969, | ||
| 262 | 54971,54980,54981,54984,54988,54993,54996,54999,55001,55008,55012,55016,55024, | ||
| 263 | 55029,55036,55037,55040,55044,55057,55064,55065,55068,55072,55080,55081,55083, | ||
| 264 | 55085,55092,55093,55096,55100,55108,55111,55113,55120,55121,55124,55126,55127, | ||
| 265 | 55128,55129,55136,55137,55139,55141,55145,55148,55152,55156,55164,55165,55169, | ||
| 266 | 55176,55177,55180,55184,55192,55193,55195,55197,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 267 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 268 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, | ||
| 269 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,20285,20339,20551,20729,21152,21487,21621,21733, | ||
| 270 | 22025,23233,23478,26247,26550,26551,26607,27468,29634,30146,31292,33499,33540, | ||
| 271 | 34903,34952,35382,36040,36303,36603,36838,39381,21051,21364,21508,24682,24932, | ||
| 272 | 27580,29647,33050,35258,35282,38307,20355,21002,22718,22904,23014,24178,24185, | ||
| 273 | 25031,25536,26438,26604,26751,28567,30286,30475,30965,31240,31487,31777,32925, | ||
| 274 | 33390,33393,35563,38291,20075,21917,26359,28212,30883,31469,33883,35088,34638, | ||
| 275 | 38824,21208,22350,22570,23884,24863,25022,25121,25954,26577,27204,28187,29976, | ||
| 276 | 30131,30435,30640,32058,37039,37969,37970,40853,21283,23724,30002,32987,37440, | ||
| 277 | 38296,21083,22536,23004,23713,23831,24247,24378,24394,24951,27743,30074,30086, | ||
| 278 | 31968,32115,32177,32652,33108,33313,34193,35137,35611,37628,38477,40007,20171, | ||
| 279 | 20215,20491,20977,22607,24887,24894,24936,25913,27114,28433,30117,30342,30422, | ||
| 280 | 31623,33445,33995,63744,37799,38283,21888,23458,22353,63745,31923,32697,37301, | ||
| 281 | 20520,21435,23621,24040,25298,25454,25818,25831,28192,28844,31067,36317,36382, | ||
| 282 | 63746,36989,37445,37624,20094,20214,20581,24062,24314,24838,26967,33137,34388, | ||
| 283 | 36423,37749,39467,20062,20625,26480,26688,20745,21133,21138,27298,30652,37392, | ||
| 284 | 40660,21163,24623,36850,20552,25001,25581,25802,26684,27268,28608,33160,35233, | ||
| 285 | 38548,22533,29309,29356,29956,32121,32365,32937,35211,35700,36963,40273,25225, | ||
| 286 | 27770,28500,32080,32570,35363,20860,24906,31645,35609,37463,37772,20140,20435, | ||
| 287 | 20510,20670,20742,21185,21197,21375,22384,22659,24218,24465,24950,25004, | ||
| 288 | 25806,25964,26223,26299,26356,26775,28039,28805,28913,29855,29861,29898,30169, | ||
| 289 | 30828,30956,31455,31478,32069,32147,32789,32831,33051,33686,35686,36629,36885, | ||
| 290 | 37857,38915,38968,39514,39912,20418,21843,22586,22865,23395,23622,24760,25106, | ||
| 291 | 26690,26800,26856,28330,30028,30328,30926,31293,31995,32363,32380,35336,35489, | ||
| 292 | 35903,38542,40388,21476,21481,21578,21617,22266,22993,23396,23611,24235,25335, | ||
| 293 | 25911,25925,25970,26272,26543,27073,27837,30204,30352,30590,31295,32660,32771, | ||
| 294 | 32929,33167,33510,33533,33776,34241,34865,34996,35493,63747,36764,37678,38599, | ||
| 295 | 39015,39640,40723,21741,26011,26354,26767,31296,35895,40288,22256,22372,23825, | ||
| 296 | 26118,26801,26829,28414,29736,34974,39908,27752,63748,39592,20379,20844,20849, | ||
| 297 | 21151,23380,24037,24656,24685,25329,25511,25915,29657,31354,34467,36002,38799, | ||
| 298 | 20018,23521,25096,26524,29916,31185,33747,35463,35506,36328,36942,37707,38982, | ||
| 299 | 24275,27112,34303,37101,63749,20896,23448,23532,24931,26874,27454,28748,29743, | ||
| 300 | 29912,31649,32592,33733,35264,36011,38364,39208,21038,24669,25324,36866,20362, | ||
| 301 | 20809,21281,22745,24291,26336,27960,28826,29378,29654,31568,33009,37979,21350, | ||
| 302 | 25499,32619,20054,20608,22602,22750,24618,24871,25296,27088,39745,23439,32024, | ||
| 303 | 32945,36703,20132,20689,21676,21932,23308,23968,24039,25898,25934,26657,27211, | ||
| 304 | 29409,30350,30703,32094,32761,33184,34126,34527,36611,36686,37066,39171,39509, | ||
| 305 | 39851,19992,20037,20061,20167,20465,20855,21246,21312,21475,21477,21646,22036, | ||
| 306 | 22389,22434,23495,23943,24272,25084,25304,25937,26552,26601,27083,27472,27590, | ||
| 307 | 27628,27714,28317,28792,29399,29590,29699,30655,30697, | ||
| 308 | 31350,32127,32777,33276,33285,33290,33503,34914,35635,36092,36544,36881,37041, | ||
| 309 | 37476,37558,39378,39493,40169,40407,40860,22283,23616,33738,38816,38827,40628, | ||
| 310 | 21531,31384,32676,35033,36557,37089,22528,23624,25496,31391,23470,24339,31353, | ||
| 311 | 31406,33422,36524,20518,21048,21240,21367,22280,25331,25458,27402,28099,30519, | ||
| 312 | 21413,29527,34152,36470,38357,26426,27331,28528,35437,36556,39243,63750,26231, | ||
| 313 | 27512,36020,39740,63751,21483,22317,22862,25542,27131,29674,30789,31418,31429, | ||
| 314 | 31998,33909,35215,36211,36917,38312,21243,22343,30023,31584,33740,37406,63752, | ||
| 315 | 27224,20811,21067,21127,25119,26840,26997,38553,20677,21156,21220,25027,26020, | ||
| 316 | 26681,27135,29822,31563,33465,33771,35250,35641,36817,39241,63753,20170,22935, | ||
| 317 | 25810,26129,27278,29748,31105,31165,33449,34942,34943,35167,63754,37670,20235, | ||
| 318 | 21450,24613,25201,27762,32026,32102,20120,20834,30684,32943,20225,20238,20854, | ||
| 319 | 20864,21980,22120,22331,22522,22524,22804,22855,22931,23492,23696,23822,24049, | ||
| 320 | 24190,24524,25216,26071,26083,26398,26399,26462,26827,26820,27231,27450,27683, | ||
| 321 | 27773,27778,28103,29592,29734,29738,29826,29859,30072,30079,30849,30959,31041, | ||
| 322 | 31047,31048,31098,31637,32000,32186,32648,32774,32813,32908,35352,35663,35912, | ||
| 323 | 36215,37665,37668,39138,39249,39438,39439,39525,40594,32202,20342,21513,25326, | ||
| 324 | 26708,37329,21931,20794,63755,63756,23068,25062,63757,25295,25343,63758,63759, | ||
| 325 | 63760,63761,63762,63763,37027,63764,63765,63766,63767,63768,35582,63769,63770, | ||
| 326 | 63771,63772,26262,63773,29014,63774,63775,38627,63776,25423,25466,21335,63777, | ||
| 327 | 26511,26976,28275,63778,30007,63779,63780,63781,32013, | ||
| 328 | 63782,63783,34930,22218,23064,63784,63785,63786,63787,63788,20035,63789,20839, | ||
| 329 | 22856,26608,32784,63790,22899,24180,25754,31178,24565,24684,25288,25467,23527, | ||
| 330 | 23511,21162,63791,22900,24361,24594,63792,63793,63794,29785,63795,63796,63797, | ||
| 331 | 63798,63799,63800,39377,63801,63802,63803,63804,63805,63806,63807,63808,63809, | ||
| 332 | 63810,63811,28611,63812,63813,33215,36786,24817,63814,63815,33126,63816,63817, | ||
| 333 | 23615,63818,63819,63820,63821,63822,63823,63824,63825,23273,35365,26491,32016, | ||
| 334 | 63826,63827,63828,63829,63830,63831,33021,63832,63833,23612,27877,21311,28346, | ||
| 335 | 22810,33590,20025,20150,20294,21934,22296,22727,24406,26039,26086,27264,27573, | ||
| 336 | 28237,30701,31471,31774,32222,34507,34962,37170,37723,25787,28606,29562,30136, | ||
| 337 | 36948,21846,22349,25018,25812,26311,28129,28251,28525,28601,30192,32835,33213, | ||
| 338 | 34113,35203,35527,35674,37663,27795,30035,31572,36367,36957,21776,22530,22616, | ||
| 339 | 24162,25095,25758,26848,30070,31958,34739,40680,20195,22408,22382,22823,23565, | ||
| 340 | 23729,24118,24453,25140,25825,29619,33274,34955,36024,38538,40667,23429,24503, | ||
| 341 | 24755,20498,20992,21040,22294,22581,22615,23566,23648,23798,23947,24230,24466, | ||
| 342 | 24764,25361,25481,25623,26691,26873,27330,28120,28193,28372,28644,29182,30428, | ||
| 343 | 30585,31153,31291,33796,35241,36077,36339,36424,36867,36884,36947,37117,37709, | ||
| 344 | 38518,38876,27602,28678,29272,29346,29544,30563,31167,31716,32411,35712,22697, | ||
| 345 | 24775,25958,26109,26302,27788,28958,29129,35930,38931,20077,31361,20189,20908, | ||
| 346 | 20941,21205,21516,24999,26481,26704,26847,27934,28540,30140,30643,31461,33012, | ||
| 347 | 33891,37509,20828,26007,26460,26515,30168,31431,33651, | ||
| 348 | 63834,35910,36887,38957,23663,33216,33434,36929,36975,37389,24471,23965,27225, | ||
| 349 | 29128,30331,31561,34276,35588,37159,39472,21895,25078,63835,30313,32645,34367, | ||
| 350 | 34746,35064,37007,63836,27931,28889,29662,32097,33853,63837,37226,39409,63838, | ||
| 351 | 20098,21365,27396,27410,28734,29211,34349,40478,21068,36771,23888,25829,25900, | ||
| 352 | 27414,28651,31811,32412,34253,35172,35261,25289,33240,34847,24266,26391,28010, | ||
| 353 | 29436,29701,29807,34690,37086,20358,23821,24480,33802,20919,25504,30053,20142, | ||
| 354 | 20486,20841,20937,26753,27153,31918,31921,31975,33391,35538,36635,37327,20406, | ||
| 355 | 20791,21237,21570,24300,24942,25150,26053,27354,28670,31018,34268,34851,38317, | ||
| 356 | 39522,39530,40599,40654,21147,26310,27511,28701,31019,36706,38722,24976,25088, | ||
| 357 | 25891,28451,29001,29833,32244,32879,34030,36646,36899,37706,20925,21015,21155, | ||
| 358 | 27916,28872,35010,24265,25986,27566,28610,31806,29557,20196,20278,22265,63839, | ||
| 359 | 23738,23994,24604,29618,31533,32666,32718,32838,36894,37428,38646,38728,38936, | ||
| 360 | 40801,20363,28583,31150,37300,38583,21214,63840,25736,25796,27347,28510,28696, | ||
| 361 | 29200,30439,32769,34310,34396,36335,36613,38706,39791,40442,40565,30860,31103, | ||
| 362 | 32160,33737,37636,40575,40595,35542,22751,24324,26407,28711,29903,31840,32894, | ||
| 363 | 20769,28712,29282,30922,36034,36058,36084,38647,20102,20698,23534,24278,26009, | ||
| 364 | 29134,30274,30637,32842,34044,36988,39719,40845,22744,23105,23650,27155,28122, | ||
| 365 | 28431,30267,32047,32311,34078,35128,37860,38475,21129,26066,26611,27060,27969, | ||
| 366 | 28316,28687,29705,29792,30041,30244,30827,35628,39006,20845,25134,38520,20374, | ||
| 367 | 20523,23833,28138,32184,36650,24459,24900,26647,63841, | ||
| 368 | 38534,21202,32907,20956,20940,26974,31260,32190,33777,38517,20442,21033,21400, | ||
| 369 | 21519,21774,23653,24743,26446,26792,28012,29313,29432,29702,29827,63842,30178, | ||
| 370 | 31852,32633,32696,33673,35023,35041,37324,37328,38626,39881,21533,28542,29136, | ||
| 371 | 29848,34298,36522,38563,40023,40607,26519,28107,29747,33256,38678,30764,31435, | ||
| 372 | 31520,31890,25705,29802,30194,30908,30952,39340,39764,40635,23518,24149,28448, | ||
| 373 | 33180,33707,37000,19975,21325,23081,24018,24398,24930,25405,26217,26364,28415, | ||
| 374 | 28459,28771,30622,33836,34067,34875,36627,39237,39995,21788,25273,26411,27819, | ||
| 375 | 33545,35178,38778,20129,22916,24536,24537,26395,32178,32596,33426,33579,33725, | ||
| 376 | 36638,37017,22475,22969,23186,23504,26151,26522,26757,27599,29028,32629,36023, | ||
| 377 | 36067,36993,39749,33032,35978,38476,39488,40613,23391,27667,29467,30450,30431, | ||
| 378 | 33804,20906,35219,20813,20885,21193,26825,27796,30468,30496,32191,32236,38754, | ||
| 379 | 40629,28357,34065,20901,21517,21629,26126,26269,26919,28319,30399,30609,33559, | ||
| 380 | 33986,34719,37225,37528,40180,34946,20398,20882,21215,22982,24125,24917,25720, | ||
| 381 | 25721,26286,26576,27169,27597,27611,29279,29281,29761,30520,30683,32791,33468, | ||
| 382 | 33541,35584,35624,35980,26408,27792,29287,30446,30566,31302,40361,27519,27794, | ||
| 383 | 22818,26406,33945,21359,22675,22937,24287,25551,26164,26483,28218,29483,31447, | ||
| 384 | 33495,37672,21209,24043,25006,25035,25098,25287,25771,26080,26969,27494,27595, | ||
| 385 | 28961,29687,30045,32326,33310,33538,34154,35491,36031,38695,40289,22696,40664, | ||
| 386 | 20497,21006,21563,21839,25991,27766,32010,32011,32862,34442,38272,38639,21247, | ||
| 387 | 27797,29289,21619,23194,23614,23883,24396,24494,26410, | ||
| 388 | 26806,26979,28220,28228,30473,31859,32654,34183,35598,36855,38753,40692,23735, | ||
| 389 | 24758,24845,25003,25935,26107,26108,27665,27887,29599,29641,32225,38292,23494, | ||
| 390 | 34588,35600,21085,21338,25293,25615,25778,26420,27192,27850,29632,29854,31636, | ||
| 391 | 31893,32283,33162,33334,34180,36843,38649,39361,20276,21322,21453,21467,25292, | ||
| 392 | 25644,25856,26001,27075,27886,28504,29677,30036,30242,30436,30460,30928,30971, | ||
| 393 | 31020,32070,33324,34784,36820,38930,39151,21187,25300,25765,28196,28497,30332, | ||
| 394 | 36299,37297,37474,39662,39747,20515,20621,22346,22952,23592,24135,24439,25151, | ||
| 395 | 25918,26041,26049,26121,26507,27036,28354,30917,32033,32938,33152,33323,33459, | ||
| 396 | 33953,34444,35370,35607,37030,38450,40848,20493,20467,63843,22521,24472,25308, | ||
| 397 | 25490,26479,28227,28953,30403,32972,32986,35060,35061,35097,36064,36649,37197, | ||
| 398 | 38506,20271,20336,24091,26575,26658,30333,30334,39748,24161,27146,29033,29140, | ||
| 399 | 30058,63844,32321,34115,34281,39132,20240,31567,32624,38309,20961,24070,26805, | ||
| 400 | 27710,27726,27867,29359,31684,33539,27861,29754,20731,21128,22721,25816,27287, | ||
| 401 | 29863,30294,30887,34327,38370,38713,63845,21342,24321,35722,36776,36783,37002, | ||
| 402 | 21029,30629,40009,40712,19993,20482,20853,23643,24183,26142,26170,26564,26821, | ||
| 403 | 28851,29953,30149,31177,31453,36647,39200,39432,20445,22561,22577,23542,26222, | ||
| 404 | 27493,27921,28282,28541,29668,29995,33769,35036,35091,35676,36628,20239,20693, | ||
| 405 | 21264,21340,23443,24489,26381,31119,33145,33583,34068,35079,35206,36665,36667, | ||
| 406 | 39333,39954,26412,20086,20472,22857,23553,23791,23792,25447,26834,28925,29090, | ||
| 407 | 29739,32299,34028,34562,36898,37586,40179,19981,20184, | ||
| 408 | 20463,20613,21078,21103,21542,21648,22496,22827,23142,23386,23413,23500,24220, | ||
| 409 | 63846,25206,25975,26023,28014,28325,29238,31526,31807,32566,33104,33105,33178, | ||
| 410 | 33344,33433,33705,35331,36000,36070,36091,36212,36282,37096,37340,38428,38468, | ||
| 411 | 39385,40167,21271,20998,21545,22132,22707,22868,22894,24575,24996,25198,26128, | ||
| 412 | 27774,28954,30406,31881,31966,32027,33452,36033,38640,63847,20315,24343,24447, | ||
| 413 | 25282,23849,26379,26842,30844,32323,40300,19989,20633,21269,21290,21329,22915, | ||
| 414 | 23138,24199,24754,24970,25161,25209,26000,26503,27047,27604,27606,27607,27608, | ||
| 415 | 27832,63848,29749,30202,30738,30865,31189,31192,31875,32203,32737,32933,33086, | ||
| 416 | 33218,33778,34586,35048,35513,35692,36027,37145,38750,39131,40763,22188,23338, | ||
| 417 | 24428,25996,27315,27567,27996,28657,28693,29277,29613,36007,36051,38971,24977, | ||
| 418 | 27703,32856,39425,20045,20107,20123,20181,20282,20284,20351,20447,20735,21490, | ||
| 419 | 21496,21766,21987,22235,22763,22882,23057,23531,23546,23556,24051,24107,24473, | ||
| 420 | 24605,25448,26012,26031,26614,26619,26797,27515,27801,27863,28195,28681,29509, | ||
| 421 | 30722,31038,31040,31072,31169,31721,32023,32114,32902,33293,33678,34001,34503, | ||
| 422 | 35039,35408,35422,35613,36060,36198,36781,37034,39164,39391,40605,21066,63849, | ||
| 423 | 26388,63850,20632,21034,23665,25955,27733,29642,29987,30109,31639,33948,37240, | ||
| 424 | 38704,20087,25746,27578,29022,34217,19977,63851,26441,26862,28183,33439,34072, | ||
| 425 | 34923,25591,28545,37394,39087,19978,20663,20687,20767,21830,21930,22039,23360, | ||
| 426 | 23577,23776,24120,24202,24224,24258,24819,26705,27233,28248,29245,29248,29376, | ||
| 427 | 30456,31077,31665,32724,35059,35316,35443,35937,36062, | ||
| 428 | 38684,22622,29885,36093,21959,63852,31329,32034,33394,29298,29983,29989,63853, | ||
| 429 | 31513,22661,22779,23996,24207,24246,24464,24661,25234,25471,25933,26257,26329, | ||
| 430 | 26360,26646,26866,29312,29790,31598,32110,32214,32626,32997,33298,34223,35199, | ||
| 431 | 35475,36893,37604,40653,40736,22805,22893,24109,24796,26132,26227,26512,27728, | ||
| 432 | 28101,28511,30707,30889,33990,37323,37675,20185,20682,20808,21892,23307,23459, | ||
| 433 | 25159,25982,26059,28210,29053,29697,29764,29831,29887,30316,31146,32218,32341, | ||
| 434 | 32680,33146,33203,33337,34330,34796,35445,36323,36984,37521,37925,39245,39854, | ||
| 435 | 21352,23633,26964,27844,27945,28203,33292,34203,35131,35373,35498,38634,40807, | ||
| 436 | 21089,26297,27570,32406,34814,36109,38275,38493,25885,28041,29166,63854,22478, | ||
| 437 | 22995,23468,24615,24826,25104,26143,26207,29481,29689,30427,30465,31596,32854, | ||
| 438 | 32882,33125,35488,37266,19990,21218,27506,27927,31237,31545,32048,63855,36016, | ||
| 439 | 21484,22063,22609,23477,23567,23569,24034,25152,25475,25620,26157,26803,27836, | ||
| 440 | 28040,28335,28703,28836,29138,29990,30095,30094,30233,31505,31712,31787,32032, | ||
| 441 | 32057,34092,34157,34311,35380,36877,36961,37045,37559,38902,39479,20439,23660, | ||
| 442 | 26463,28049,31903,32396,35606,36118,36895,23403,24061,25613,33984,36956,39137, | ||
| 443 | 29575,23435,24730,26494,28126,35359,35494,36865,38924,21047,63856,28753,30862, | ||
| 444 | 37782,34928,37335,20462,21463,22013,22234,22402,22781,23234,23432,23723,23744, | ||
| 445 | 24101,24833,25101,25163,25480,25628,25910,25976,27193,27530,27700,27929,28465, | ||
| 446 | 29159,29417,29560,29703,29874,30246,30561,31168,31319,31466,31929,32143,32172, | ||
| 447 | 32353,32670,33065,33585,33936,34010,34282,34966,35504, | ||
| 448 | 35728,36664,36930,36995,37228,37526,37561,38539,38567,38568,38614,38656,38920, | ||
| 449 | 39318,39635,39706,21460,22654,22809,23408,23487,28113,28506,29087,29729,29881, | ||
| 450 | 32901,33789,24033,24455,24490,24642,26092,26642,26991,27219,27529,27957,28147, | ||
| 451 | 29667,30462,30636,31565,32020,33059,33308,33600,34036,34147,35426,35524,37255, | ||
| 452 | 37662,38918,39348,25100,34899,36848,37477,23815,23847,23913,29791,33181,34664, | ||
| 453 | 28629,25342,32722,35126,35186,19998,20056,20711,21213,21319,25215,26119,32361, | ||
| 454 | 34821,38494,20365,21273,22070,22987,23204,23608,23630,23629,24066,24337,24643, | ||
| 455 | 26045,26159,26178,26558,26612,29468,30690,31034,32709,33940,33997,35222,35430, | ||
| 456 | 35433,35553,35925,35962,22516,23508,24335,24687,25325,26893,27542,28252,29060, | ||
| 457 | 31698,34645,35672,36606,39135,39166,20280,20353,20449,21627,23072,23480,24892, | ||
| 458 | 26032,26216,29180,30003,31070,32051,33102,33251,33688,34218,34254,34563,35338, | ||
| 459 | 36523,36763,63857,36805,22833,23460,23526,24713,23529,23563,24515,27777,63858, | ||
| 460 | 28145,28683,29978,33455,35574,20160,21313,63859,38617,27663,20126,20420,20818, | ||
| 461 | 21854,23077,23784,25105,29273,33469,33706,34558,34905,35357,38463,38597,39187, | ||
| 462 | 40201,40285,22538,23731,23997,24132,24801,24853,25569,27138,28197,37122,37716, | ||
| 463 | 38990,39952,40823,23433,23736,25353,26191,26696,30524,38593,38797,38996,39839, | ||
| 464 | 26017,35585,36555,38332,21813,23721,24022,24245,26263,30284,33780,38343,22739, | ||
| 465 | 25276,29390,40232,20208,22830,24591,26171,27523,31207,40230,21395,21696,22467, | ||
| 466 | 23830,24859,26326,28079,30861,33406,38552,38724,21380,25212,25494,28082,32266, | ||
| 467 | 33099,38989,27387,32588,40367,40474,20063,20539,20918, | ||
| 468 | 22812,24825,25590,26928,29242,32822,63860,37326,24369,63861,63862,32004,33509, | ||
| 469 | 33903,33979,34277,36493,63863,20335,63864,63865,22756,23363,24665,25562,25880, | ||
| 470 | 25965,26264,63866,26954,27171,27915,28673,29036,30162,30221,31155,31344,63867, | ||
| 471 | 32650,63868,35140,63869,35731,37312,38525,63870,39178,22276,24481,26044,28417, | ||
| 472 | 30208,31142,35486,39341,39770,40812,20740,25014,25233,27277,33222,20547,22576, | ||
| 473 | 24422,28937,35328,35578,23420,34326,20474,20796,22196,22852,25513,28153,23978, | ||
| 474 | 26989,20870,20104,20313,63871,63872,63873,22914,63874,63875,27487,27741,63876, | ||
| 475 | 29877,30998,63877,33287,33349,33593,36671,36701,63878,39192,63879,63880,63881, | ||
| 476 | 20134,63882,22495,24441,26131,63883,63884,30123,32377,35695,63885,36870,39515, | ||
| 477 | 22181,22567,23032,23071,23476,63886,24310,63887,63888,25424,25403,63889,26941, | ||
| 478 | 27783,27839,28046,28051,28149,28436,63890,28895,28982,29017,63891,29123,29141, | ||
| 479 | 63892,30799,30831,63893,31605,32227,63894,32303,63895,34893,36575,63896,63897, | ||
| 480 | 63898,37467,63899,40182,63900,63901,63902,24709,28037,63903,29105,63904,63905, | ||
| 481 | 38321,21421,63906,63907,63908,26579,63909,28814,28976,29744,33398,33490,63910, | ||
| 482 | 38331,39653,40573,26308,63911,29121,33865,63912,63913,22603,63914,63915,23992, | ||
| 483 | 24433,63916,26144,26254,27001,27054,27704,27891,28214,28481,28634,28699,28719, | ||
| 484 | 29008,29151,29552,63917,29787,63918,29908,30408,31310,32403,63919,63920,33521, | ||
| 485 | 35424,36814,63921,37704,63922,38681,63923,63924,20034,20522,63925,21000,21473, | ||
| 486 | 26355,27757,28618,29450,30591,31330,33454,34269,34306,63926,35028,35427,35709, | ||
| 487 | 35947,63927,37555,63928,38675,38928,20116,20237,20425, | ||
| 488 | 20658,21320,21566,21555,21978,22626,22714,22887,23067,23524,24735,63929,25034, | ||
| 489 | 25942,26111,26212,26791,27738,28595,28879,29100,29522,31613,34568,35492,39986, | ||
| 490 | 40711,23627,27779,29508,29577,37434,28331,29797,30239,31337,32277,34314,20800, | ||
| 491 | 22725,25793,29934,29973,30320,32705,37013,38605,39252,28198,29926,31401,31402, | ||
| 492 | 33253,34521,34680,35355,23113,23436,23451,26785,26880,28003,29609,29715,29740, | ||
| 493 | 30871,32233,32747,33048,33109,33694,35916,38446,38929,26352,24448,26106,26505, | ||
| 494 | 27754,29579,20525,23043,27498,30702,22806,23916,24013,29477,30031,63930,63931, | ||
| 495 | 20709,20985,22575,22829,22934,23002,23525,63932,63933,23970,25303,25622,25747, | ||
| 496 | 25854,63934,26332,63935,27208,63936,29183,29796,63937,31368,31407,32327,32350, | ||
| 497 | 32768,33136,63938,34799,35201,35616,36953,63939,36992,39250,24958,27442,28020, | ||
| 498 | 32287,35109,36785,20433,20653,20887,21191,22471,22665,23481,24248,24898,27029, | ||
| 499 | 28044,28263,28342,29076,29794,29992,29996,32883,33592,33993,36362,37780,37854, | ||
| 500 | 63940,20110,20305,20598,20778,21448,21451,21491,23431,23507,23588,24858,24962, | ||
| 501 | 26100,29275,29591,29760,30402,31056,31121,31161,32006,32701,33419,34261,34398, | ||
| 502 | 36802,36935,37109,37354,38533,38632,38633,21206,24423,26093,26161,26671,29020, | ||
| 503 | 31286,37057,38922,20113,63941,27218,27550,28560,29065,32792,33464,34131,36939, | ||
| 504 | 38549,38642,38907,34074,39729,20112,29066,38596,20803,21407,21729,22291,22290, | ||
| 505 | 22435,23195,23236,23491,24616,24895,25588,27781,27961,28274,28304,29232,29503, | ||
| 506 | 29783,33489,34945,36677,36960,63942,38498,39000,40219,26376,36234,37470,20301, | ||
| 507 | 20553,20702,21361,22285,22996,23041,23561,24944,26256, | ||
| 508 | 28205,29234,29771,32239,32963,33806,33894,34111,34655,34907,35096,35586,36949, | ||
| 509 | 38859,39759,20083,20369,20754,20842,63943,21807,21929,23418,23461,24188,24189, | ||
| 510 | 24254,24736,24799,24840,24841,25540,25912,26377,63944,26580,26586,63945,26977, | ||
| 511 | 26978,27833,27943,63946,28216,63947,28641,29494,29495,63948,29788,30001,63949, | ||
| 512 | 30290,63950,63951,32173,33278,33848,35029,35480,35547,35565,36400,36418,36938, | ||
| 513 | 36926,36986,37193,37321,37742,63952,63953,22537,63954,27603,32905,32946,63955, | ||
| 514 | 63956,20801,22891,23609,63957,63958,28516,29607,32996,36103,63959,37399,38287, | ||
| 515 | 63960,63961,63962,63963,32895,25102,28700,32104,34701,63964,22432,24681,24903, | ||
| 516 | 27575,35518,37504,38577,20057,21535,28139,34093,38512,38899,39150,25558,27875, | ||
| 517 | 37009,20957,25033,33210,40441,20381,20506,20736,23452,24847,25087,25836,26885, | ||
| 518 | 27589,30097,30691,32681,33380,34191,34811,34915,35516,35696,37291,20108,20197, | ||
| 519 | 20234,63965,63966,22839,23016,63967,24050,24347,24411,24609,63968,63969,63970, | ||
| 520 | 63971,29246,29669,63972,30064,30157,63973,31227,63974,32780,32819,32900,33505, | ||
| 521 | 33617,63975,63976,36029,36019,36999,63977,63978,39156,39180,63979,63980,28727, | ||
| 522 | 30410,32714,32716,32764,35610,20154,20161,20995,21360,63981,21693,22240,23035, | ||
| 523 | 23493,24341,24525,28270,63982,63983,32106,33589,63984,34451,35469,63985,38765, | ||
| 524 | 38775,63986,63987,19968,20314,20350,22777,26085,28322,36920,37808,39353,20219, | ||
| 525 | 22764,22922,23001,24641,63988,63989,31252,63990,33615,36035,20837,21316,63991, | ||
| 526 | 63992,63993,20173,21097,23381,33471,20180,21050,21672,22985,23039,23376,23383, | ||
| 527 | 23388,24675,24904,28363,28825,29038,29574,29943,30133, | ||
| 528 | 30913,32043,32773,33258,33576,34071,34249,35566,36039,38604,20316,21242,22204, | ||
| 529 | 26027,26152,28796,28856,29237,32189,33421,37196,38592,40306,23409,26855,27544, | ||
| 530 | 28538,30430,23697,26283,28507,31668,31786,34870,38620,19976,20183,21280,22580, | ||
| 531 | 22715,22767,22892,23559,24115,24196,24373,25484,26290,26454,27167,27299,27404, | ||
| 532 | 28479,29254,63994,29520,29835,31456,31911,33144,33247,33255,33674,33900,34083, | ||
| 533 | 34196,34255,35037,36115,37292,38263,38556,20877,21705,22312,23472,25165,26448, | ||
| 534 | 26685,26771,28221,28371,28797,32289,35009,36001,36617,40779,40782,29229,31631, | ||
| 535 | 35533,37658,20295,20302,20786,21632,22992,24213,25269,26485,26990,27159,27822, | ||
| 536 | 28186,29401,29482,30141,31672,32053,33511,33785,33879,34295,35419,36015,36487, | ||
| 537 | 36889,37048,38606,40799,21219,21514,23265,23490,25688,25973,28404,29380,63995, | ||
| 538 | 30340,31309,31515,31821,32318,32735,33659,35627,36042,36196,36321,36447,36842, | ||
| 539 | 36857,36969,37841,20291,20346,20659,20840,20856,21069,21098,22625,22652,22880, | ||
| 540 | 23560,23637,24283,24731,25136,26643,27583,27656,28593,29006,29728,30000,30008, | ||
| 541 | 30033,30322,31564,31627,31661,31686,32399,35438,36670,36681,37439,37523,37666, | ||
| 542 | 37931,38651,39002,39019,39198,20999,25130,25240,27993,30308,31434,31680,32118, | ||
| 543 | 21344,23742,24215,28472,28857,31896,38673,39822,40670,25509,25722,34678,19969, | ||
| 544 | 20117,20141,20572,20597,21576,22979,23450,24128,24237,24311,24449,24773,25402, | ||
| 545 | 25919,25972,26060,26230,26232,26622,26984,27273,27491,27712,28096,28136,28191, | ||
| 546 | 28254,28702,28833,29582,29693,30010,30555,30855,31118,31243,31357,31934,32142, | ||
| 547 | 33351,35330,35562,35998,37165,37194,37336,37478,37580, | ||
| 548 | 37664,38662,38742,38748,38914,40718,21046,21137,21884,22564,24093,24351,24716, | ||
| 549 | 25552,26799,28639,31085,31532,33229,34234,35069,35576,36420,37261,38500,38555, | ||
| 550 | 38717,38988,40778,20430,20806,20939,21161,22066,24340,24427,25514,25805,26089, | ||
| 551 | 26177,26362,26361,26397,26781,26839,27133,28437,28526,29031,29157,29226,29866, | ||
| 552 | 30522,31062,31066,31199,31264,31381,31895,31967,32068,32368,32903,34299,34468, | ||
| 553 | 35412,35519,36249,36481,36896,36973,37347,38459,38613,40165,26063,31751,36275, | ||
| 554 | 37827,23384,23562,21330,25305,29469,20519,23447,24478,24752,24939,26837,28121, | ||
| 555 | 29742,31278,32066,32156,32305,33131,36394,36405,37758,37912,20304,22352,24038, | ||
| 556 | 24231,25387,32618,20027,20303,20367,20570,23005,32964,21610,21608,22014,22863, | ||
| 557 | 23449,24030,24282,26205,26417,26609,26666,27880,27954,28234,28557,28855,29664, | ||
| 558 | 30087,31820,32002,32044,32162,33311,34523,35387,35461,36208,36490,36659,36913, | ||
| 559 | 37198,37202,37956,39376,31481,31909,20426,20737,20934,22472,23535,23803,26201, | ||
| 560 | 27197,27994,28310,28652,28940,30063,31459,34850,36897,36981,38603,39423,33537, | ||
| 561 | 20013,20210,34886,37325,21373,27355,26987,27713,33914,22686,24974,26366,25327, | ||
| 562 | 28893,29969,30151,32338,33976,35657,36104,20043,21482,21675,22320,22336,24535, | ||
| 563 | 25345,25351,25711,25903,26088,26234,26525,26547,27490,27744,27802,28460,30693, | ||
| 564 | 30757,31049,31063,32025,32930,33026,33267,33437,33463,34584,35468,63996,36100, | ||
| 565 | 36286,36978,30452,31257,31287,32340,32887,21767,21972,22645,25391,25634,26185, | ||
| 566 | 26187,26733,27035,27524,27941,28337,29645,29800,29857,30043,30137,30433,30494, | ||
| 567 | 30603,31206,32265,32285,33275,34095,34967,35386,36049, | ||
| 568 | 36587,36784,36914,37805,38499,38515,38663,20356,21489,23018,23241,24089,26702, | ||
| 569 | 29894,30142,31209,31378,33187,34541,36074,36300,36845,26015,26389,63997,22519, | ||
| 570 | 28503,32221,36655,37878,38598,24501,25074,28548,19988,20376,20511,21449,21983, | ||
| 571 | 23919,24046,27425,27492,30923,31642,63998,36425,36554,36974,25417,25662,30528, | ||
| 572 | 31364,37679,38015,40810,25776,28591,29158,29864,29914,31428,31762,32386,31922, | ||
| 573 | 32408,35738,36106,38013,39184,39244,21049,23519,25830,26413,32046,20717,21443, | ||
| 574 | 22649,24920,24921,25082,26028,31449,35730,35734,20489,20513,21109,21809,23100, | ||
| 575 | 24288,24432,24884,25950,26124,26166,26274,27085,28356,28466,29462,30241,31379, | ||
| 576 | 33081,33369,33750,33980,20661,22512,23488,23528,24425,25505,30758,32181,33756, | ||
| 577 | 34081,37319,37365,20874,26613,31574,36012,20932,22971,24765,34389,20508,63999, | ||
| 578 | 21076,23610,24957,25114,25299,25842,26021,28364,30240,33034,36448,38495,38587, | ||
| 579 | 20191,21315,21912,22825,24029,25797,27849,28154,29588,31359,33307,34214,36068, | ||
| 580 | 36368,36983,37351,38369,38433,38854,20984,21746,21894,24505,25764,28552,32180, | ||
| 581 | 36639,36685,37941,20681,23574,27838,28155,29979,30651,31805,31844,35449,35522, | ||
| 582 | 22558,22974,24086,25463,29266,30090,30571,35548,36028,36626,24307,26228,28152, | ||
| 583 | 32893,33729,35531,38737,39894,64000,21059,26367,28053,28399,32224,35558,36910, | ||
| 584 | 36958,39636,21021,21119,21736,24980,25220,25307,26786,26898,26970,27189,28818, | ||
| 585 | 28966,30813,30977,30990,31186,31245,32918,33400,33493,33609,34121,35970,36229, | ||
| 586 | 37218,37259,37294,20419,22225,29165,30679,34560,35320,23544,24534,26449,37032, | ||
| 587 | 21474,22618,23541,24740,24961,25696,32317,32880,34085, | ||
| 588 | 37507,25774,20652,23828,26368,22684,25277,25512,26894,27000,27166,28267,30394, | ||
| 589 | 31179,33467,33833,35535,36264,36861,37138,37195,37276,37648,37656,37786,38619, | ||
| 590 | 39478,39949,19985,30044,31069,31482,31569,31689,32302,33988,36441,36468,36600, | ||
| 591 | 36880,26149,26943,29763,20986,26414,40668,20805,24544,27798,34802,34909,34935, | ||
| 592 | 24756,33205,33795,36101,21462,21561,22068,23094,23601,28810,32736,32858,33030, | ||
| 593 | 33261,36259,37257,39519,40434,20596,20164,21408,24827,28204,23652,20360,20516, | ||
| 594 | 21988,23769,24159,24677,26772,27835,28100,29118,30164,30196,30305,31258,31305, | ||
| 595 | 32199,32251,32622,33268,34473,36636,38601,39347,40786,21063,21189,39149,35242, | ||
| 596 | 19971,26578,28422,20405,23522,26517,27784,28024,29723,30759,37341,37756,34756, | ||
| 597 | 31204,31281,24555,20182,21668,21822,22702,22949,24816,25171,25302,26422,26965, | ||
| 598 | 33333,38464,39345,39389,20524,21331,21828,22396,64001,25176,64002,25826,26219, | ||
| 599 | 26589,28609,28655,29730,29752,35351,37944,21585,22022,22374,24392,24986,27470, | ||
| 600 | 28760,28845,32187,35477,22890,33067,25506,30472,32829,36010,22612,25645,27067, | ||
| 601 | 23445,24081,28271,64003,34153,20812,21488,22826,24608,24907,27526,27760,27888, | ||
| 602 | 31518,32974,33492,36294,37040,39089,64004,25799,28580,25745,25860,20814,21520, | ||
| 603 | 22303,35342,24927,26742,64005,30171,31570,32113,36890,22534,27084,33151,35114, | ||
| 604 | 36864,38969,20600,22871,22956,25237,36879,39722,24925,29305,38358,22369,23110, | ||
| 605 | 24052,25226,25773,25850,26487,27874,27966,29228,29750,30772,32631,33453,36315, | ||
| 606 | 38935,21028,22338,26495,29256,29923,36009,36774,37393,38442,20843,21485,25420, | ||
| 607 | 20329,21764,24726,25943,27803,28031,29260,29437,31255, | ||
| 608 | 35207,35997,24429,28558,28921,33192,24846,20415,20559,25153,29255,31687,32232, | ||
| 609 | 32745,36941,38829,39449,36022,22378,24179,26544,33805,35413,21536,23318,24163, | ||
| 610 | 24290,24330,25987,32954,34109,38281,38491,20296,21253,21261,21263,21638,21754, | ||
| 611 | 22275,24067,24598,25243,25265,25429,64006,27873,28006,30129,30770,32990,33071, | ||
| 612 | 33502,33889,33970,34957,35090,36875,37610,39165,39825,24133,26292,26333,28689, | ||
| 613 | 29190,64007,20469,21117,24426,24915,26451,27161,28418,29922,31080,34920,35961, | ||
| 614 | 39111,39108,39491,21697,31263,26963,35575,35914,39080,39342,24444,25259,30130, | ||
| 615 | 30382,34987,36991,38466,21305,24380,24517,27852,29644,30050,30091,31558,33534, | ||
| 616 | 39325,20047,36924,19979,20309,21414,22799,24264,26160,27827,29781,33655,34662, | ||
| 617 | 36032,36944,38686,39957,22737,23416,34384,35604,40372,23506,24680,24717,26097, | ||
| 618 | 27735,28450,28579,28698,32597,32752,38289,38290,38480,38867,21106,36676,20989, | ||
| 619 | 21547,21688,21859,21898,27323,28085,32216,33382,37532,38519,40569,21512,21704, | ||
| 620 | 30418,34532,38308,38356,38492,20130,20233,23022,23270,24055,24658,25239,26477, | ||
| 621 | 26689,27782,28207,32568,32923,33322,64008,64009,38917,20133,20565,21683,22419, | ||
| 622 | 22874,23401,23475,25032,26999,28023,28707,34809,35299,35442,35559,36994,39405, | ||
| 623 | 39608,21182,26680,20502,24184,26447,33607,34892,20139,21521,22190,29670,37141, | ||
| 624 | 38911,39177,39255,39321,22099,22687,34395,35377,25010,27382,29563,36562,27463, | ||
| 625 | 38570,39511,22869,29184,36203,38761,20436,23796,24358,25080,26203,27883,28843, | ||
| 626 | 29572,29625,29694,30505,30541,32067,32098,32291,33335,34898,64010,36066,37449, | ||
| 627 | 39023,23377,31348,34880,38913,23244,20448,21332,22846, | ||
| 628 | 23805,25406,28025,29433,33029,33031,33698,37583,38960,20136,20804,21009,22411, | ||
| 629 | 24418,27842,28366,28677,28752,28847,29074,29673,29801,33610,34722,34913,36872, | ||
| 630 | 37026,37795,39336,20846,24407,24800,24935,26291,34137,36426,37295,38795,20046, | ||
| 631 | 20114,21628,22741,22778,22909,23733,24359,25142,25160,26122,26215,27627,28009, | ||
| 632 | 28111,28246,28408,28564,28640,28649,28765,29392,29733,29786,29920,30355,31068, | ||
| 633 | 31946,32286,32993,33446,33899,33983,34382,34399,34676,35703,35946,37804,38912, | ||
| 634 | 39013,24785,25110,37239,23130,26127,28151,28222,29759,39746,24573,24794,31503, | ||
| 635 | 21700,24344,27742,27859,27946,28888,32005,34425,35340,40251,21270,21644,23301, | ||
| 636 | 27194,28779,30069,31117,31166,33457,33775,35441,35649,36008,38772,64011,25844, | ||
| 637 | 25899,30906,30907,31339,20024,21914,22864,23462,24187,24739,25563,27489,26213, | ||
| 638 | 26707,28185,29029,29872,32008,36996,39529,39973,27963,28369,29502,35905,38346, | ||
| 639 | 20976,24140,24488,24653,24822,24880,24908,26179,26180,27045,27841,28255,28361, | ||
| 640 | 28514,29004,29852,30343,31681,31783,33618,34647,36945,38541,40643,21295,22238, | ||
| 641 | 24315,24458,24674,24724,25079,26214,26371,27292,28142,28590,28784,29546,32362, | ||
| 642 | 33214,33588,34516,35496,36036,21123,29554,23446,27243,37892,21742,22150,23389, | ||
| 643 | 25928,25989,26313,26783,28045,28102,29243,32948,37237,39501,20399,20505,21402, | ||
| 644 | 21518,21564,21897,21957,24127,24460,26429,29030,29661,36869,21211,21235,22628, | ||
| 645 | 22734,28932,29071,29179,34224,35347,26248,34216,21927,26244,29002,33841,21321, | ||
| 646 | 21913,27585,24409,24509,25582,26249,28999,35569,36637,40638,20241,25658,28875, | ||
| 647 | 30054,34407,24676,35662,40440,20807,20982,21256,27958, | ||
| 648 | 33016,40657,26133,27427,28824,30165,21507,23673,32007,35350,27424,27453,27462, | ||
| 649 | 21560,24688,27965,32725,33288,20694,20958,21916,22123,22221,23020,23305,24076, | ||
| 650 | 24985,24984,25137,26206,26342,29081,29113,29114,29351,31143,31232,32690,35440, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/langinfo.c created+73| ... | @@ -0,0 +1,73 @@ | ||
| 1 | #include <locale.h> | ||
| 2 | #include <langinfo.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | static const char c_time[] = | ||
| 6 | 	"Sun\0" "Mon\0" "Tue\0" "Wed\0" "Thu\0" "Fri\0" "Sat\0" | ||
| 7 | 	"Sunday\0" "Monday\0" "Tuesday\0" "Wednesday\0" | ||
| 8 | 	"Thursday\0" "Friday\0" "Saturday\0" | ||
| 9 | 	"Jan\0" "Feb\0" "Mar\0" "Apr\0" "May\0" "Jun\0" | ||
| 10 | 	"Jul\0" "Aug\0" "Sep\0" "Oct\0" "Nov\0" "Dec\0" | ||
| 11 | 	"January\0" "February\0" "March\0" "April\0" | ||
| 12 | 	"May\0" "June\0" "July\0" "August\0" | ||
| 13 | 	"September\0" "October\0" "November\0" "December\0" | ||
| 14 | 	"AM\0" "PM\0" | ||
| 15 | 	"%a %b %e %T %Y\0" | ||
| 16 | 	"%m/%d/%y\0" | ||
| 17 | 	"%H:%M:%S\0" | ||
| 18 | 	"%I:%M:%S %p\0" | ||
| 19 | 	"\0" | ||
| 20 | 	"\0" | ||
| 21 | 	"%m/%d/%y\0" | ||
| 22 | 	"0123456789\0" | ||
| 23 | 	"%a %b %e %T %Y\0" | ||
| 24 | 	"%H:%M:%S"; | ||
| 25 | |||
| 26 | static const char c_messages[] = "^[yY]\0" "^[nN]\0" "yes\0" "no"; | ||
| 27 | static const char c_numeric[] = ".\0" ""; | ||
| 28 | |||
| 29 | char *__nl_langinfo_l(nl_item item, locale_t loc) | ||
| 30 | { | ||
| 31 | 	int cat = item >> 16; | ||
| 32 | 	int idx = item & 65535; | ||
| 33 | 	const char *str; | ||
| 34 | |||
| 35 | 	if (item == CODESET) return loc->cat[LC_CTYPE] ? "UTF-8" : "ASCII"; | ||
| 36 | |||
| 37 | 	/* _NL_LOCALE_NAME extension */ | ||
| 38 | 	if (idx == 65535 && cat < LC_ALL) | ||
| 39 | 		return loc->cat[cat] ? (char *)loc->cat[cat]->name : "C"; | ||
| 40 | 	 | ||
| 41 | 	switch (cat) { | ||
| 42 | 	case LC_NUMERIC: | ||
| 43 | 		if (idx > 1) return ""; | ||
| 44 | 		str = c_numeric; | ||
| 45 | 		break; | ||
| 46 | 	case LC_TIME: | ||
| 47 | 		if (idx > 0x31) return ""; | ||
| 48 | 		str = c_time; | ||
| 49 | 		break; | ||
| 50 | 	case LC_MONETARY: | ||
| 51 | 		if (idx > 0) return ""; | ||
| 52 | 		str = ""; | ||
| 53 | 		break; | ||
| 54 | 	case LC_MESSAGES: | ||
| 55 | 		if (idx > 3) return ""; | ||
| 56 | 		str = c_messages; | ||
| 57 | 		break; | ||
| 58 | 	default: | ||
| 59 | 		return ""; | ||
| 60 | 	} | ||
| 61 | |||
| 62 | 	for (; idx; idx--, str++) for (; *str; str++); | ||
| 63 | 	if (cat != LC_NUMERIC && *str) str = LCTRANS(str, cat, loc); | ||
| 64 | 	return (char *)str; | ||
| 65 | } | ||
| 66 | |||
| 67 | char *__nl_langinfo(nl_item item) | ||
| 68 | { | ||
| 69 | 	return __nl_langinfo_l(item, CURRENT_LOCALE); | ||
| 70 | } | ||
| 71 | |||
| 72 | weak_alias(__nl_langinfo, nl_langinfo); | ||
| 73 | weak_alias(__nl_langinfo_l, nl_langinfo_l); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/legacychars.h created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | 256,257,258,259,260,261,262,263,264,265,266,267,268,269,270,271,272,273,274, | ||
| 2 | 275,278,279,280,281,282,283,284,285,286,287,288,289,290,291,292,293,294,295, | ||
| 3 | 296,297,298,299,302,303,304,305,308,309,310,311,312,313,314,315,316,317,318, | ||
| 4 | 321,322,323,324,325,326,327,328,330,331,332,333,336,337,338,339,340,341,342, | ||
| 5 | 343,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361, | ||
| 6 | 362,363,364,365,366,367,368,369,370,371,372,373,374,375,376,377,378,379,380, | ||
| 7 | 381,382,402,416,417,431,432,536,537,538,539,710,711,728,729,731,732,733,768, | ||
| 8 | 769,771,777,803,890,900,901,902,904,905,906,908,910,911,912,913,914,915,916, | ||
| 9 | 917,918,919,920,921,922,923,924,925,926,927,928,929,931,932,933,934,935,936, | ||
| 10 | 937,938,939,940,941,942,943,944,945,946,947,948,949,950,951,952,953,954,955, | ||
| 11 | 956,957,958,959,960,961,962,963,964,965,966,967,968,969,970,971,972,973,974, | ||
| 12 | 1025,1026,1027,1028,1029,1030,1031,1032,1033,1034,1035,1036,1038,1039,1040, | ||
| 13 | 1041,1042,1043,1044,1045,1046,1047,1048,1049,1050,1051,1052,1053,1054,1055, | ||
| 14 | 1056,1057,1058,1059,1060,1061,1062,1063,1064,1065,1066,1067,1068,1069,1070, | ||
| 15 | 1071, | ||
| 16 | 1072,1073,1074,1075,1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086, | ||
| 17 | 1087,1088,1089,1090,1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101, | ||
| 18 | 1102,1103,1105,1106,1107,1108,1109,1110,1111,1112,1113,1114,1115,1116,1118, | ||
| 19 | 1119,1168,1169,1456,1457,1458,1459,1460,1461,1462,1463,1464,1465,1467,1468, | ||
| 20 | 1469,1470,1471,1472,1473,1474,1475,1488,1489,1490,1491,1492,1493,1494,1495, | ||
| 21 | 1496,1497,1498,1499,1500,1501,1502,1503,1504,1505,1506,1507,1508,1509,1510, | ||
| 22 | 1511,1512,1513,1514,1520,1521,1522,1523,1524,1548,1563,1567,1569,1570,1571, | ||
| 23 | 1572,1573,1574,1575,1576,1577,1578,1579,1580,1581,1582,1583,1584,1585,1586, | ||
| 24 | 1587,1588,1589,1590,1591,1592,1593,1594,1600,1601,1602,1603,1604,1605,1606, | ||
| 25 | 1607,1608,1609,1610,1611,1612,1613,1614,1615,1616,1617,1618,1657,1662,1670, | ||
| 26 | 1672,1681,1688,1705,1711,1722,1726,1729,1746,3585,3586,3587,3588,3589,3590, | ||
| 27 | 3591,3592,3593,3594,3595,3596,3597,3598,3599,3600,3601,3602,3603,3604,3605, | ||
| 28 | 3606,3607,3608,3609,3610,3611,3612,3613,3614,3615,3616,3617,3618,3619,3620, | ||
| 29 | 3621,3622,3623,3624,3625,3626,3627,3628,3629,3630,3631,3632,3633,3634,3635, | ||
| 30 | 3636,3637,3638,3639,3640,3641,3642,3647,3648,3649,3650,3651,3652,3653,3654, | ||
| 31 | 3655,3656,3657,3658,3659,3660,3661,3662,3663,3664,3665,3666,3667,3668,3669, | ||
| 32 | 3670,3671,3672,3673,3674,3675,7682,7683,7690,7691,7710,7711,7744,7745,7766, | ||
| 33 | 7767, | ||
| 34 | 7776,7777,7786,7787,7808,7809,7810,7811,7812,7813,7922,7923,8204,8205,8206, | ||
| 35 | 8207,8211,8212,8213,8215,8216,8217,8218,8220,8221,8222,8224,8225,8226,8230, | ||
| 36 | 8240,8249,8250,8319,8359,8362,8363,8364,8367,8470,8482,8729,8730,8734,8745, | ||
| 37 | 8776,8801,8804,8805,8976,8992,8993,9472,9474,9484,9488,9492,9496,9500,9508, | ||
| 38 | 9516,9524,9532,9552,9553,9554,9555,9556,9557,9558,9559,9560,9561,9562,9563, | ||
| 39 | 9564,9565,9566,9567,9568,9569,9570,9571,9572,9573,9574,9575,9576,9577,9578, | ||
| 40 | 9579,9580,9600,9604,9608,9612,9616,9617,9618,9619,9632, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/locale_map.c created+119| ... | @@ -0,0 +1,119 @@ | ||
| 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 | #define malloc __libc_malloc | ||
| 13 | #define calloc undef | ||
| 14 | #define realloc undef | ||
| 15 | #define free undef | ||
| 16 | |||
| 17 | const char *__lctrans_impl(const char *msg, const struct __locale_map *lm) | ||
| 18 | { | ||
| 19 | 	const char *trans = 0; | ||
| 20 | 	if (lm) trans = __mo_lookup(lm->map, lm->map_size, msg); | ||
| 21 | 	return trans ? trans : msg; | ||
| 22 | } | ||
| 23 | |||
| 24 | static const char envvars[][12] = { | ||
| 25 | 	"LC_CTYPE", | ||
| 26 | 	"LC_NUMERIC", | ||
| 27 | 	"LC_TIME", | ||
| 28 | 	"LC_COLLATE", | ||
| 29 | 	"LC_MONETARY", | ||
| 30 | 	"LC_MESSAGES", | ||
| 31 | }; | ||
| 32 | |||
| 33 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 34 | volatile int __locale_lock[1]; | ||
| 35 | volatile int *const __locale_lockptr = __locale_lock; | ||
| 36 | #endif | ||
| 37 | |||
| 38 | const struct __locale_map *__get_locale(int cat, const char *val) | ||
| 39 | { | ||
| 40 | 	static void *volatile loc_head; | ||
| 41 | 	const struct __locale_map *p; | ||
| 42 | 	struct __locale_map *new = 0; | ||
| 43 | 	const char *path = 0, *z; | ||
| 44 | 	char buf[256]; | ||
| 45 | 	size_t l, n; | ||
| 46 | |||
| 47 | 	if (!*val) { | ||
| 48 | 		(val = getenv("LC_ALL")) && *val || | ||
| 49 | 		(val = getenv(envvars[cat])) && *val || | ||
| 50 | 		(val = getenv("LANG")) && *val || | ||
| 51 | 		(val = "C.UTF-8"); | ||
| 52 | 	} | ||
| 53 | |||
| 54 | 	/* Limit name length and forbid leading dot or any slashes. */ | ||
| 55 | 	for (n=0; n<LOCALE_NAME_MAX && val[n] && val[n]!='/'; n++); | ||
| 56 | 	if (val[0]=='.' || val[n]) val = "C.UTF-8"; | ||
| 57 | 	int builtin = (val[0]=='C' && !val[1]) | ||
| 58 | 		|| !strcmp(val, "C.UTF-8") | ||
| 59 | 		|| !strcmp(val, "POSIX"); | ||
| 60 | |||
| 61 | 	if (builtin) { | ||
| 62 | 		if (cat == LC_CTYPE && val[1]=='.') | ||
| 63 | 			return (void *)&__c_dot_utf8; | ||
| 64 | 		return 0; | ||
| 65 | 	} | ||
| 66 | |||
| 67 | 	for (p=loc_head; p; p=p->next) | ||
| 68 | 		if (!strcmp(val, p->name)) return p; | ||
| 69 | |||
| 70 | #ifdef __wasilibc_unmodified_upstream // WASI has no mmap, though this code could be made to use something else | ||
| 71 | 	if (!libc.secure) path = getenv("MUSL_LOCPATH"); | ||
| 72 | 	/* FIXME: add a default path? */ | ||
| 73 | |||
| 74 | 	if (path) for (; *path; path=z+!!*z) { | ||
| 75 | 		z = __strchrnul(path, ':'); | ||
| 76 | 		l = z - path; | ||
| 77 | 		if (l >= sizeof buf - n - 2) continue; | ||
| 78 | 		memcpy(buf, path, l); | ||
| 79 | 		buf[l] = '/'; | ||
| 80 | 		memcpy(buf+l+1, val, n); | ||
| 81 | 		buf[l+1+n] = 0; | ||
| 82 | 		size_t map_size; | ||
| 83 | 		const void *map = __map_file(buf, &map_size); | ||
| 84 | 		if (map) { | ||
| 85 | 			new = malloc(sizeof *new); | ||
| 86 | 			if (!new) { | ||
| 87 | 				__munmap((void *)map, map_size); | ||
| 88 | 				break; | ||
| 89 | 			} | ||
| 90 | 			new->map = map; | ||
| 91 | 			new->map_size = map_size; | ||
| 92 | 			memcpy(new->name, val, n); | ||
| 93 | 			new->name[n] = 0; | ||
| 94 | 			new->next = loc_head; | ||
| 95 | 			loc_head = new; | ||
| 96 | 			break; | ||
| 97 | 		} | ||
| 98 | 	} | ||
| 99 | #endif | ||
| 100 | |||
| 101 | 	/* If no locale definition was found, make a locale map | ||
| 102 | 	 * object anyway to store the name, which is kept for the | ||
| 103 | 	 * sake of being able to do message translations at the | ||
| 104 | 	 * application level. */ | ||
| 105 | 	if (!new && (new = malloc(sizeof *new))) { | ||
| 106 | 		new->map = __c_dot_utf8.map; | ||
| 107 | 		new->map_size = __c_dot_utf8.map_size; | ||
| 108 | 		memcpy(new->name, val, n); | ||
| 109 | 		new->name[n] = 0; | ||
| 110 | 		new->next = loc_head; | ||
| 111 | 		loc_head = new; | ||
| 112 | 	} | ||
| 113 | |||
| 114 | 	/* For LC_CTYPE, never return a null pointer unless the | ||
| 115 | 	 * requested name was "C" or "POSIX". */ | ||
| 116 | 	if (!new && cat == LC_CTYPE) new = (void *)&__c_dot_utf8; | ||
| 117 | |||
| 118 | 	return new; | ||
| 119 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/localeconv.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include <locale.h> | ||
| 2 | #include <limits.h> | ||
| 3 | |||
| 4 | static const struct lconv posix_lconv = { | ||
| 5 | 	.decimal_point = ".", | ||
| 6 | 	.thousands_sep = "", | ||
| 7 | 	.grouping = "", | ||
| 8 | 	.int_curr_symbol = "", | ||
| 9 | 	.currency_symbol = "", | ||
| 10 | 	.mon_decimal_point = "", | ||
| 11 | 	.mon_thousands_sep = "", | ||
| 12 | 	.mon_grouping = "", | ||
| 13 | 	.positive_sign = "", | ||
| 14 | 	.negative_sign = "", | ||
| 15 | 	.int_frac_digits = CHAR_MAX, | ||
| 16 | 	.frac_digits = CHAR_MAX, | ||
| 17 | 	.p_cs_precedes = CHAR_MAX, | ||
| 18 | 	.p_sep_by_space = CHAR_MAX, | ||
| 19 | 	.n_cs_precedes = CHAR_MAX, | ||
| 20 | 	.n_sep_by_space = CHAR_MAX, | ||
| 21 | 	.p_sign_posn = CHAR_MAX, | ||
| 22 | 	.n_sign_posn = CHAR_MAX, | ||
| 23 | 	.int_p_cs_precedes = CHAR_MAX, | ||
| 24 | 	.int_p_sep_by_space = CHAR_MAX, | ||
| 25 | 	.int_n_cs_precedes = CHAR_MAX, | ||
| 26 | 	.int_n_sep_by_space = CHAR_MAX, | ||
| 27 | 	.int_p_sign_posn = CHAR_MAX, | ||
| 28 | 	.int_n_sign_posn = CHAR_MAX, | ||
| 29 | }; | ||
| 30 | |||
| 31 | struct lconv *localeconv(void) | ||
| 32 | { | ||
| 33 | 	return (void *)&posix_lconv; | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/newlocale.c created+72| ... | @@ -0,0 +1,72 @@ | ||
| 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 | #define malloc __libc_malloc | ||
| 10 | #define calloc undef | ||
| 11 | #define realloc undef | ||
| 12 | #define free undef | ||
| 13 | |||
| 14 | static int default_locale_init_done; | ||
| 15 | static struct __locale_struct default_locale, default_ctype_locale; | ||
| 16 | |||
| 17 | int __loc_is_allocated(locale_t loc) | ||
| 18 | { | ||
| 19 | 	return loc && loc != C_LOCALE && loc != UTF8_LOCALE | ||
| 20 | 		&& loc != &default_locale && loc != &default_ctype_locale; | ||
| 21 | } | ||
| 22 | |||
| 23 | static locale_t do_newlocale(int mask, const char *name, locale_t loc) | ||
| 24 | { | ||
| 25 | 	struct __locale_struct tmp; | ||
| 26 | |||
| 27 | 	for (int i=0; i<LC_ALL; i++) { | ||
| 28 | 		tmp.cat[i] = (!(mask & (1<<i)) && loc) ? loc->cat[i] : | ||
| 29 | 			__get_locale(i, (mask & (1<<i)) ? name : ""); | ||
| 30 | 		if (tmp.cat[i] == LOC_MAP_FAILED) | ||
| 31 | 			return 0; | ||
| 32 | 	} | ||
| 33 | |||
| 34 | 	/* For locales with allocated storage, modify in-place. */ | ||
| 35 | 	if (__loc_is_allocated(loc)) { | ||
| 36 | 		*loc = tmp; | ||
| 37 | 		return loc; | ||
| 38 | 	} | ||
| 39 | |||
| 40 | 	/* Otherwise, first see if we can use one of the builtin locales. | ||
| 41 | 	 * This makes the common usage case for newlocale, getting a C locale | ||
| 42 | 	 * with predictable behavior, very fast, and more importantly, fail-safe. */ | ||
| 43 | 	if (!memcmp(&tmp, C_LOCALE, sizeof tmp)) return C_LOCALE; | ||
| 44 | 	if (!memcmp(&tmp, UTF8_LOCALE, sizeof tmp)) return UTF8_LOCALE; | ||
| 45 | |||
| 46 | 	/* And provide builtins for the initial default locale, and a | ||
| 47 | 	 * variant of the C locale honoring the default locale's encoding. */ | ||
| 48 | 	if (!default_locale_init_done) { | ||
| 49 | 		for (int i=0; i<LC_ALL; i++) | ||
| 50 | 			default_locale.cat[i] = __get_locale(i, ""); | ||
| 51 | 		default_ctype_locale.cat[LC_CTYPE] = default_locale.cat[LC_CTYPE]; | ||
| 52 | 		default_locale_init_done = 1; | ||
| 53 | 	} | ||
| 54 | 	if (!memcmp(&tmp, &default_locale, sizeof tmp)) return &default_locale; | ||
| 55 | 	if (!memcmp(&tmp, &default_ctype_locale, sizeof tmp)) | ||
| 56 | 		return &default_ctype_locale; | ||
| 57 | |||
| 58 | 	/* If no builtin locale matched, attempt to allocate and copy. */ | ||
| 59 | 	if ((loc = malloc(sizeof *loc))) *loc = tmp; | ||
| 60 | |||
| 61 | 	return loc; | ||
| 62 | } | ||
| 63 | |||
| 64 | locale_t __newlocale(int mask, const char *name, locale_t loc) | ||
| 65 | { | ||
| 66 | 	LOCK(__locale_lock); | ||
| 67 | 	loc = do_newlocale(mask, name, loc); | ||
| 68 | 	UNLOCK(__locale_lock); | ||
| 69 | 	return loc; | ||
| 70 | } | ||
| 71 | |||
| 72 | weak_alias(__newlocale, newlocale); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/pleval.c created+158| ... | @@ -0,0 +1,158 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | #include "pleval.h" | ||
| 4 | |||
| 5 | /* | ||
| 6 | grammar: | ||
| 7 | |||
| 8 | Start = Expr ';' | ||
| 9 | Expr = Or | Or '?' Expr ':' Expr | ||
| 10 | Or = And | Or '||' And | ||
| 11 | And = Eq | And '&&' Eq | ||
| 12 | Eq = Rel | Eq '==' Rel | Eq '!=' Rel | ||
| 13 | Rel = Add | Rel '<=' Add | Rel '>=' Add | Rel '<' Add | Rel '>' Add | ||
| 14 | Add = Mul | Add '+' Mul | Add '-' Mul | ||
| 15 | Mul = Prim | Mul '*' Prim | Mul '/' Prim | Mul '%' Prim | ||
| 16 | Prim = '(' Expr ')' | '!' Prim | decimal | 'n' | ||
| 17 | |||
| 18 | internals: | ||
| 19 | |||
| 20 | recursive descent expression evaluator with stack depth limit. | ||
| 21 | for binary operators an operator-precedence parser is used. | ||
| 22 | eval* functions store the result of the parsed subexpression | ||
| 23 | and return a pointer to the next non-space character. | ||
| 24 | */ | ||
| 25 | |||
| 26 | struct st { | ||
| 27 | 	unsigned long r; | ||
| 28 | 	unsigned long n; | ||
| 29 | 	int op; | ||
| 30 | }; | ||
| 31 | |||
| 32 | static const char *skipspace(const char *s) | ||
| 33 | { | ||
| 34 | 	while (isspace(*s)) s++; | ||
| 35 | 	return s; | ||
| 36 | } | ||
| 37 | |||
| 38 | static const char *evalexpr(struct st *st, const char *s, int d); | ||
| 39 | |||
| 40 | static const char *evalprim(struct st *st, const char *s, int d) | ||
| 41 | { | ||
| 42 | 	char *e; | ||
| 43 | 	if (--d < 0) return ""; | ||
| 44 | 	s = skipspace(s); | ||
| 45 | 	if (isdigit(*s)) { | ||
| 46 | 		st->r = strtoul(s, &e, 10); | ||
| 47 | 		if (e == s || st->r == -1) return ""; | ||
| 48 | 		return skipspace(e); | ||
| 49 | 	} | ||
| 50 | 	if (*s == 'n') { | ||
| 51 | 		st->r = st->n; | ||
| 52 | 		return skipspace(s+1); | ||
| 53 | 	} | ||
| 54 | 	if (*s == '(') { | ||
| 55 | 		s = evalexpr(st, s+1, d); | ||
| 56 | 		if (*s != ')') return ""; | ||
| 57 | 		return skipspace(s+1); | ||
| 58 | 	} | ||
| 59 | 	if (*s == '!') { | ||
| 60 | 		s = evalprim(st, s+1, d); | ||
| 61 | 		st->r = !st->r; | ||
| 62 | 		return s; | ||
| 63 | 	} | ||
| 64 | 	return ""; | ||
| 65 | } | ||
| 66 | |||
| 67 | static int binop(struct st *st, int op, unsigned long left) | ||
| 68 | { | ||
| 69 | 	unsigned long a = left, b = st->r; | ||
| 70 | 	switch (op) { | ||
| 71 | 	case 0: st->r = a||b; return 0; | ||
| 72 | 	case 1: st->r = a&&b; return 0; | ||
| 73 | 	case 2: st->r = a==b; return 0; | ||
| 74 | 	case 3: st->r = a!=b; return 0; | ||
| 75 | 	case 4: st->r = a>=b; return 0; | ||
| 76 | 	case 5: st->r = a<=b; return 0; | ||
| 77 | 	case 6: st->r = a>b; return 0; | ||
| 78 | 	case 7: st->r = a<b; return 0; | ||
| 79 | 	case 8: st->r = a+b; return 0; | ||
| 80 | 	case 9: st->r = a-b; return 0; | ||
| 81 | 	case 10: st->r = a*b; return 0; | ||
| 82 | 	case 11: if (b) {st->r = a%b; return 0;} return 1; | ||
| 83 | 	case 12: if (b) {st->r = a/b; return 0;} return 1; | ||
| 84 | 	} | ||
| 85 | 	return 1; | ||
| 86 | } | ||
| 87 | |||
| 88 | static const char *parseop(struct st *st, const char *s) | ||
| 89 | { | ||
| 90 | 	static const char opch[11] = "|&=!><+-*%/"; | ||
| 91 | 	static const char opch2[6] = "|&===="; | ||
| 92 | 	int i; | ||
| 93 | 	for (i=0; i<11; i++) | ||
| 94 | 		if (*s == opch[i]) { | ||
| 95 | 			/* note: >,< are accepted with or without = */ | ||
| 96 | 			if (i<6 && s[1] == opch2[i]) { | ||
| 97 | 				st->op = i; | ||
| 98 | 				return s+2; | ||
| 99 | 			} | ||
| 100 | 			if (i>=4) { | ||
| 101 | 				st->op = i+2; | ||
| 102 | 				return s+1; | ||
| 103 | 			} | ||
| 104 | 			break; | ||
| 105 | 		} | ||
| 106 | 	st->op = 13; | ||
| 107 | 	return s; | ||
| 108 | } | ||
| 109 | |||
| 110 | static const char *evalbinop(struct st *st, const char *s, int minprec, int d) | ||
| 111 | { | ||
| 112 | 	static const char prec[14] = {1,2,3,3,4,4,4,4,5,5,6,6,6,0}; | ||
| 113 | 	unsigned long left; | ||
| 114 | 	int op; | ||
| 115 | 	d--; | ||
| 116 | 	s = evalprim(st, s, d); | ||
| 117 | 	s = parseop(st, s); | ||
| 118 | 	for (;;) { | ||
| 119 | 		/* | ||
| 120 | 		st->r (left hand side value) and st->op are now set, | ||
| 121 | 		get the right hand side or back out if op has low prec, | ||
| 122 | 		if op was missing then prec[op]==0 | ||
| 123 | 		*/ | ||
| 124 | 		op = st->op; | ||
| 125 | 		if (prec[op] <= minprec) | ||
| 126 | 			return s; | ||
| 127 | 		left = st->r; | ||
| 128 | 		s = evalbinop(st, s, prec[op], d); | ||
| 129 | 		if (binop(st, op, left)) | ||
| 130 | 			return ""; | ||
| 131 | 	} | ||
| 132 | } | ||
| 133 | |||
| 134 | static const char *evalexpr(struct st *st, const char *s, int d) | ||
| 135 | { | ||
| 136 | 	unsigned long a, b; | ||
| 137 | 	if (--d < 0) | ||
| 138 | 		return ""; | ||
| 139 | 	s = evalbinop(st, s, 0, d); | ||
| 140 | 	if (*s != '?') | ||
| 141 | 		return s; | ||
| 142 | 	a = st->r; | ||
| 143 | 	s = evalexpr(st, s+1, d); | ||
| 144 | 	if (*s != ':') | ||
| 145 | 		return ""; | ||
| 146 | 	b = st->r; | ||
| 147 | 	s = evalexpr(st, s+1, d); | ||
| 148 | 	st->r = a ? b : st->r; | ||
| 149 | 	return s; | ||
| 150 | } | ||
| 151 | |||
| 152 | unsigned long __pleval(const char *s, unsigned long n) | ||
| 153 | { | ||
| 154 | 	struct st st; | ||
| 155 | 	st.n = n; | ||
| 156 | 	s = evalexpr(&st, s, 100); | ||
| 157 | 	return *s == ';' ? st.r : -1; | ||
| 158 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/pleval.h created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #ifndef PLEVAL_H | ||
| 2 | #define PLEVAL_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | hidden unsigned long __pleval(const char *, unsigned long); | ||
| 7 | |||
| 8 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/locale/revjis.h created+515| ... | @@ -0,0 +1,515 @@ | ||
| 1 | 31,80,81,87,14,299,74,61,12,344,62,63,1280,1281,1282,1283,1284,1285,1286,1287, | ||
| 2 | 1288,1289,1290,1291,1292,1293,1294,1295,1296,1297,1298,1299,1300,1301,1302, | ||
| 3 | 1303,1312,1313,1314,1315,1316,1317,1318,1319,1320,1321,1322,1323,1324,1325, | ||
| 4 | 1326,1327,1328,1329,1330,1331,1332,1333,1334,1335,1542,1536,1537,1538,1539, | ||
| 5 | 1540,1541,1543,1544,1545,1546,1547,1548,1549,1550,1551,1552,1553,1554,1555, | ||
| 6 | 1556,1557,1558,1559,1560,1561,1562,1563,1564,1565,1566,1567,1568,1584,1585, | ||
| 7 | 1586,1587,1588,1589,1591,1592,1593,1594,1595,1596,1597,1598,1599,1600,1601, | ||
| 8 | 1602,1603,1604,1605,1606,1607,1608,1609,1610,1611,1612,1613,1614,1615,1616, | ||
| 9 | 1590,29,28,33,37,38,39,40,342,343,36,35,338,75,76,263,77,337,266,267,265,268, | ||
| 10 | 300,301,302,318,303,319,281,282,60,324,326,70,315,297,298,288,287,328,329,71, | ||
| 11 | 327,325,321,65,320,68,69,322,323,285,286,283,284,316,317,1792,1803,1793,1804, | ||
| 12 | 1794,1805,1795,1806,1797,1808,1796,1807,1798,1819,1814,1809,1800,1821,1816, | ||
| 13 | 1811,1799,1815,1820,1810,1801,1817,1822,1812,1802,1818,1823,1813,258,257,260, | ||
| 14 | 259,262,261,256,93,90,92,91,349,89,88,73,72,341,340,339,0,1,2,22,24,25,26,49, | ||
| 15 | 50,51,52,53,54,55,56,57,58,264,269,43,44,32, | ||
| 16 | 768,769,770,771,772,773,774,775,776,777,778,779,780,781,782,783,784,785,786, | ||
| 17 | 787,788,789,790,791,792,793,794,795,796,797,798,799,800,801,802,803,804,805, | ||
| 18 | 806,807,808,809,810,811,812,813,814,815,816,817,818,819,820,821,822,823,824, | ||
| 19 | 825,826,827,828,829,830,831,832,833,834,835,836,837,838,839,840,841,842,843, | ||
| 20 | 844,845,846,847,848,849,850,10,11,20,21,1024,1025,1026,1027,1028,1029,1030, | ||
| 21 | 1031,1032,1033,1034,1035,1036,1037,1038,1039,1040,1041,1042,1043,1044,1045, | ||
| 22 | 1046,1047,1048,1049,1050,1051,1052,1053,1054,1055,1056,1057,1058,1059,1060, | ||
| 23 | 1061,1062,1063,1064,1065,1066,1067,1068,1069,1070,1071,1072,1073,1074,1075, | ||
| 24 | 1076,1077,1078,1079,1080,1081,1082,1083,1084,1085,1086,1087,1088,1089,1090, | ||
| 25 | 1091,1092,1093,1094,1095,1096,1097,1098,1099,1100,1101,1102,1103,1104,1105, | ||
| 26 | 1106,1107,1108,1109,5,27,18,19,3915,8793,6934,10843,7493,6671,7492,4379,10291, | ||
| 27 | 11294,12033,4110,4685,12034,7939,12577,5173,10521,7494,11549,10529,12035,8773, | ||
| 28 | 12036,5465,12037,4924,8719,6982,12038,12039,12040,9748,5174,9750,9538,5922, | ||
| 29 | 10770,18472,12041,7495,12042,4372,5444,5967,11080,13573,11343,9564,4868,5140, | ||
| 30 | 12043,12044,11546,11292,8263,12046,6741,9554,12049,4125,5950,5949,3909,11818, | ||
| 31 | 11817,6418,3840,12050,12051,12052,10771,12053,5969,3910,10833,5211,5212,5213, | ||
| 32 | 9025,11547,12054,12055,12056,7724,7193,7725,12061,12059,12060,5175,6402,4431, | ||
| 33 | 12058,12057,10504,6693,6692,8477,12062,10292,8006,23,12063,12065,8516,11584, | ||
| 34 | 3881,12064,4381,5411,8774,5710,12066,9731,4938,12067,3882,5951,4939,10329, | ||
| 35 | 10001,5176,4432,12102,9248,9803,12069,10011,11585,7692,6694,6742,4383,9008, | ||
| 36 | 8705,12073,3883,9026,7194,6419,11267,8493,4382,12072,11293,12068,12070,6477, | ||
| 37 | 12071,13315,12079,12082,12080,4385,10522,12074,12078,5970,6695,4869,12083, | ||
| 38 | 12075,11586,6743,12076,12081,12084,12077,5376,3884,5377,4384,13316,10840, | ||
| 39 | 10317,5971,7694,11542,10551,5655,8452,4419,7218,12088,12093,12091,12086,8462, | ||
| 40 | 12089,12092,12090,10556,12087,7693,10834,12094,12095,7171,12108,9775,10261, | ||
| 41 | 12103,10575,4373,12107,12101,12110,8241,5923,9787,16166,12109,9276,12098,5973, | ||
| 42 | 5972,12096,6969,12104,10574,8748,12100,5712,12097,12105,12099,11568,12106, | ||
| 43 | 11808,5445,5711,12111,12112,12116,3885,10543,12115,12114,12118,12117,9027, | ||
| 44 | 5713,12119,6948,8453,9028,5461,12120,5141,12121,12123,10772,5701,6672,10070, | ||
| 45 | 12122,6436,11298,12125,12290,12124,6435,7260,5656,12291,5422,12288,12289,9486, | ||
| 46 | 8283,5378,10796,12292,11548,12293,12296,12294,8237,12295,12297,12299,12298, | ||
| 47 | 10535,5142,12301,12302,4366,12300,6995,12305,12304,12303,12085,12306,7261, | ||
| 48 | 12307,11268,11064,12309,12308,12311,12310,12312,12313,3923,5908,5658,7195, | ||
| 49 | 8794,5379,8007,5974,6221,12315,11047,9253,6744,12314,12316,9277,4692,12317, | ||
| 50 | 9565,8211,12319,12320,9995,5975,11802,12321,5381,10523,8469,5456, | ||
| 51 | 9236,5714,12322,12323,9537,4158,12326,6492,12325,6437,12327,17741,12328,10784, | ||
| 52 | 12329,12330,12331,7496,6955,4870,12334,12332,11036,12333,10297,12335,12336, | ||
| 53 | 12337,9278,12341,12339,12340,12338,6466,12342,11081,11587,12343,7943,12344, | ||
| 54 | 7225,12345,8795,11550,9279,12580,12346,21252,5412,12347,10813,7239,8539,12349, | ||
| 55 | 9539,12350,12351,4621,12352,5382,9515,4185,7215,9984,12353,9280,7726,12354, | ||
| 56 | 10507,7993,4865,4872,12355,12357,5657,12356,11602,7240,10012,10539,12358, | ||
| 57 | 11351,12359,12360,9309,12361,7944,6493,5715,12362,6696,6222,9029,12364,8454, | ||
| 58 | 6478,12365,12366,8207,12363,12368,10773,6211,12367,5716,6461,9804,12371,12369, | ||
| 59 | 10330,7497,12378,4675,12372,12370,8238,12374,12373,4643,5695,12379,11532, | ||
| 60 | 12375,12380,12377,12376,11566,5976,4386,11603,7252,9271,6212,12545,12546, | ||
| 61 | 11588,11786,12548,5977,12547,4622,12549,10805,8987,11269,10552,12550,20276, | ||
| 62 | 9487,12551,4873,11026,7424,12552,10566,12556,7945,12553,5423,12554,4874,5645, | ||
| 63 | 12557,12558,12559,12560,6970,5978,11069,11079,9558,10576,12561,12562,12564, | ||
| 64 | 12566,12565,12567,4380,10795,6491,12568,8248,7425,5384,12569,10042,12570, | ||
| 65 | 12571,12572,12573,10243,5447,3908,9502,12574,7196,8008,12576,12575,7426,5952, | ||
| 66 | 12578,10013,12579,10043,8467,8525,5383,9549,8720,9805,10797,12581,8009,5652, | ||
| 67 | 12582,12583,4107,3924,4940,8455,5168,11344,12586,4374,12585,5385,12587,11088, | ||
| 68 | 12588,11569,5979,5909,12589,12591,12590,7742,4120,4157,12592,12593,5910,12594, | ||
| 69 | 5197,6673,12595,10835,6420,5177,11270,8239,10014,7004,7206,6983, | ||
| 70 | 6996,7253,10015,12598,4130,8240,5980,5924,5446,12602,8704,8541,5386,7427, | ||
| 71 | 12603,12601,4387,8517,6935,6698,4101,4687,6213,6697,12604,12605,5160,4645, | ||
| 72 | 6214,5159,9022,4100,9488,11037,6144,11352,9254,5981,5646,12614,5442,10793, | ||
| 73 | 10044,12613,4925,12608,12609,12611,12612,5178,7744,10508,12610,12606,5954, | ||
| 74 | 12607,11779,10577,9031,5953,6223,12615,9532,12619,7005,6997,12622,12620,11010, | ||
| 75 | 12617,12626,12621,12624,5925,11038,12625,12627,12629,6479,11809,12618,12616, | ||
| 76 | 12628,12623,12631,12802,12633,12637,12800,12634,12829,6472,4624,12632,12804, | ||
| 77 | 3925,12803,3844,10281,12801,12635,12630,12636,6439,12805,3926,12814,12806, | ||
| 78 | 12807,7428,10824,12812,12811,9230,12813,12810,4115,6421,7695,12808,9281,12809, | ||
| 79 | 3841,12819,11266,7430,12825,12824,12815,8482,12816,8526,12821,7429,12818, | ||
| 80 | 11075,5659,12822,12823,12820,12826,12817,12832,12837,12833,12828,12838,8208, | ||
| 81 | 12840,6145,12830,8796,12834,12827,4876,4941,4676,12835,12831,5717,12841,12839, | ||
| 82 | 8242,5161,5387,12836,5459,4131,12845,12843,13062,12848,12842,12846,12844,6699, | ||
| 83 | 12847,12850,12855,12853,12852,8721,4388,12849,12851,7431,4114,12854,4413, | ||
| 84 | 12865,7515,12861,12859,12860,12862,4124,8216,12856,12857,4697,12864,4942, | ||
| 85 | 12867,12863,12866,10509,9524,10007,12869,12868,4644,12870,12873,12872,12871, | ||
| 86 | 9752,12874,12875,12877,12876,12879,12882,12880,12878,12881,12883,12884,12885, | ||
| 87 | 12886,12887,12324,7003,6700,4434,3927,8739,12888,6403,3886,7741,12889,5926, | ||
| 88 | 6224,12891,12890,10559,12892,13056,12893,13057,13058,5718,4159,13059,13061, | ||
| 89 | 13060, | ||
| 90 | 13063,9273,13064,3860,6462,5660,8750,13065,13066,13068,13069,6467,5424,10774, | ||
| 91 | 13067,13070,6432,6146,13074,6404,8722,13071,9017,13075,7745,13073,13076,5662, | ||
| 92 | 13077,13078,6147,4639,13080,13081,13082,13079,13072,13083,13084,10819,7498, | ||
| 93 | 13086,13087,13085,13089,9751,3911,10293,13090,7516,6936,9788,4943,6474,10808, | ||
| 94 | 9489,5719,8494,13088,13091,8483,13092,13093,13095,9032,4877,21248,4160,10578, | ||
| 95 | 7499,9255,6469,13101,10524,11580,4435,13097,8217,13100,9282,9256,9283,10008, | ||
| 96 | 9004,6440,13096,4181,9237,13098,13094,7727,13102,7213,5388,13103,10567,8284, | ||
| 97 | 8997,13105,10798,13106,13111,10510,13110,13104,13107,13109,6405,10536,13112, | ||
| 98 | 8740,4436,7500,13114,13113,6215,13115,13117,13116,13119,13108,13121,13120, | ||
| 99 | 13118,6701,7728,8243,13122,7963,3916,9795,9018,13124,13123,13125,13126,13127, | ||
| 100 | 13128,10544,13129,4389,13130,11291,4623,12584,7207,8478,13131,11082,11027, | ||
| 101 | 13133,8518,9238,8479,10294,13134,13135,4186,6937,13136,3887,13137,13138,4161, | ||
| 102 | 4944,9535,10579,13142,8244,13141,5663,10810,13140,9284,13144,13143,13146, | ||
| 103 | 13145,4187,13147,7432,13149,8708,13148,10514,7254,9274,13312,6148,13313,9728, | ||
| 104 | 10045,11056,9732,13322,5143,11300,11022,13579,13314,13317,8484,10775,9257, | ||
| 105 | 13318,10820,6441,7433,13319,6703,6702,3864,5927,7946,3888,13323,13324,13321, | ||
| 106 | 4119,4878,13320,11044,10256,3847,3928,6704,3889,3842,13329,13327,11035,13330, | ||
| 107 | 13328,13326,7696,13325,10553,5955,13334,13335,7434,13331,11787,9771,13333, | ||
| 108 | 6406,13336,10295,13337,13332,11034,9789,13338,10257,13339,13343, | ||
| 109 | 13340,4390,13342,6938,13341,5720,13355,13348,13345,8771,13344,13346,13347, | ||
| 110 | 13349,13350,4945,13352,13351,13353,7501,13356,9019,4132,13354,13357,13358, | ||
| 111 | 13361,13359,13360,6705,13362,6149,13363,6745,8471,13364,13365,6713,6150,11057, | ||
| 112 | 5127,5928,13366,4663,13367,8472,13368,13570,13369,13370,13371,13373,13374, | ||
| 113 | 13375,8527,4102,6984,3873,8246,4879,6932,6151,9285,7168,4880,8775,9033,3863, | ||
| 114 | 5144,10580,6945,5169,8010,6939,11271,13376,5179,6442,4625,4162,7435,4391, | ||
| 115 | 13377,11301,7208,6979,13378,4946,9521,11016,13379,13380,10296,13382,4871,5462, | ||
| 116 | 13381,4881,7697,13386,6656,4392,13385,13383,13387,13384,9738,15148,7698,13388, | ||
| 117 | 11551,13389,13391,8797,13390,7938,6746,8495,6998,10324,8011,6956,13392,7436, | ||
| 118 | 13393,13394,3890,8473,7729,13395,9490,7437,7438,13396,8012,7439,13397,13398, | ||
| 119 | 11071,13399,5413,7169,13400,13401,6971,7691,9555,7731,10071,9729,5416,13402, | ||
| 120 | 5198,13403,5469,9518,4367,6706,13404,13569,13568,5468,13405,9239,8463,9258, | ||
| 121 | 6951,8247,11353,13571,13572,9525,6674,13574,13575,13576,4947,13577,13578,4363, | ||
| 122 | 8218,4931,13580,11015,8497,4664,13582,13584,4926,13581,13583,13586,13585, | ||
| 123 | 13587,13588,9500,5389,4420,13589,13594,13592,10582,10581,9286,13591,7219, | ||
| 124 | 13590,7761,13595,6473,13601,13602,13596,4626,13597,13606,13605,13604,13600, | ||
| 125 | 13599,13603,10583,13610,13607,13609,11345,13608,13598,7762,13611,6422,13612, | ||
| 126 | 13613,13616,13615,13614,9287,13593,13622,13618,13617,13619,13620,13623,11589, | ||
| 127 | 13624,13621,13625,4927,13626,13628,13627,13629,13630,8013,7170, | ||
| 128 | 7235,8258,6152,6423,6153,5199,13631,6424,5929,13632,11013,9762,13633,6154, | ||
| 129 | 4875,8710,5425,6707,10298,10016,13634,4948,13637,8960,13636,13635,13638,9034, | ||
| 130 | 7746,6708,7977,8498,5121,8961,13639,13640,7502,10776,13643,13642,13641,10332, | ||
| 131 | 13650,10809,13644,13646,10826,13645,13647,9991,13648,10525,13649,4882,10526, | ||
| 132 | 9742,13651,13652,6155,4883,13653,5911,11299,11272,4949,13655,8962,6156,7440, | ||
| 133 | 10046,7441,7255,9035,10584,9240,6157,10299,13656,9272,6433,5930,9036,3874, | ||
| 134 | 7245,6158,11302,13657,13658,9776,13659,11606,11788,13661,13660,4646,13824, | ||
| 135 | 13827,13828,13826,10271,7442,13830,13829,13825,13831,13832,13833,13836,13834, | ||
| 136 | 13835,13837,4163,9037,13838,5721,4437,9749,13839,9562,10554,13840,11789,13841, | ||
| 137 | 10527,13844,12032,12048,6927,9556,13845,5180,8963,3929,13846,10501,6159,8751, | ||
| 138 | 9038,11086,5912,5931,13847,13848,13854,6980,8964,5390,13849,10250,8741,13850, | ||
| 139 | 13851,5391,13852,13853,13855,9301,13856,13857,13858,13843,13842,13859,5664, | ||
| 140 | 10246,6443,10262,8965,10282,13860,7443,4133,13861,13862,11089,10047,13865, | ||
| 141 | 4188,7947,13864,13863,5665,8499,13869,13867,13866,11526,5956,7256,13868,9259, | ||
| 142 | 7197,9503,13872,13871,13870,13873,5957,13874,10331,7226,13875,10072,9504,8966, | ||
| 143 | 9231,13876,5130,7699,10251,4950,9733,13877,6709,10777,10778,4189,13882,8776, | ||
| 144 | 13879,4438,14092,13881,9743,13880,13878,6233,13884,13890,13896,13888,9275, | ||
| 145 | 13893,10300,13887,13892,11590,6710,8500,13885,5181,13895,7948,4164,13889,4439, | ||
| 146 | 13894,5392,13891,13897,13899,13909,13907,13904,13903,11607, | ||
| 147 | 13905,5393,6160,7257,13912,13898,13902,13886,4441,13906,13908,8752,6407,4375, | ||
| 148 | 13900,13911,13910,5394,8456,4677,5666,13901,13913,13916,14080,6940,14086,9039, | ||
| 149 | 13914,14084,4440,14082,14083,13917,14081,5958,11273,4884,4152,14085,9753,3852, | ||
| 150 | 10048,13883,14091,14095,11076,14088,9288,14093,7503,14094,9526,11814,14090, | ||
| 151 | 14096,6234,7978,3891,14089,14087,8249,13915,6675,8485,14108,8250,14103,14100, | ||
| 152 | 14101,6981,14104,14107,14102,7172,14105,14099,11099,11098,14109,14110,3892, | ||
| 153 | 14098,5457,3845,4885,14106,14114,14113,14118,14119,14117,14120,14112,14116, | ||
| 154 | 14121,14122,14111,6747,14115,8501,6161,14097,7700,14135,10568,14125,14126, | ||
| 155 | 14127,14134,14133,10844,4886,14131,5668,4627,14128,11543,14130,3893,14132, | ||
| 156 | 14123,14129,14136,5667,14124,11324,11274,14139,14143,8285,11608,14144,14141, | ||
| 157 | 14138,14137,14142,10511,9491,5669,14145,14140,14146,5722,4368,14154,4887, | ||
| 158 | 14152,14153,6408,14151,14149,14148,14155,14147,14157,4442,14159,14158,8967, | ||
| 159 | 14162,14160,14150,5723,14161,14165,14164,14166,14163,14167,14168,14169,10569, | ||
| 160 | 14171,14170,7198,7949,4421,4443,14172,3870,7979,14173,19234,14336,5696,14337, | ||
| 161 | 8014,14338,14339,5145,14340,14341,14342,8502,5932,11072,10779,7241,14343,8015, | ||
| 162 | 19740,10049,6985,6444,14344,8486,10502,8528,14347,14345,14348,14346,14349, | ||
| 163 | 10512,3862,10301,10050,14350,14353,7444,5146,14351,14358,7445,14352,9763, | ||
| 164 | 11325,14354,14355,14359,9289,14356,6162,7997,14373,10003,8529,10051,14604, | ||
| 165 | 10585,9040,10836,14362,4352,8777,14371,8723,14365,14372,14367,14374,14370, | ||
| 166 | 14369,9806,14363, | ||
| 167 | 4444,14361,5200,8530,14357,14360,6163,7994,7446,14368,9777,5201,4647,4678, | ||
| 168 | 7680,14376,14381,14377,5724,14382,6657,6216,7173,14364,6748,14379,6711,14380, | ||
| 169 | 3875,14375,8968,5202,5395,14378,3846,6434,7701,9041,10035,14384,8253,8457, | ||
| 170 | 6666,14385,14387,14383,10560,8988,8251,10586,6957,14399,14398,7767,5725,14392, | ||
| 171 | 7448,9543,9744,14390,8252,6999,14395,7447,14389,14394,9778,14388,5632,4668, | ||
| 172 | 14396,11530,6445,8724,14393,7995,6164,7747,4165,8219,14391,5156,5670,9006, | ||
| 173 | 14397,8254,14400,14402,8470,14408,14403,14405,10272,9042,14406,11275,11303, | ||
| 174 | 4888,3853,14404,14401,4951,4166,14407,11304,14411,8474,14418,14412,14409, | ||
| 175 | 14416,14386,14413,14417,10017,9290,14410,14414,5671,6480,7996,14422,9221, | ||
| 176 | 14419,10815,14420,14421,11053,7937,5697,14428,6676,14425,14424,9745,9492,9232, | ||
| 177 | 14426,14427,10318,9764,6658,8016,10799,4648,14596,14429,11305,14598,14594, | ||
| 178 | 14595,8255,14593,14366,14597,14592,14602,14603,9222,14605,6659,14600,5147, | ||
| 179 | 14606,14599,14610,14609,14608,14611,14613,7504,14612,14616,14614,14615,14415, | ||
| 180 | 14618,14617,14423,14619,14607,6712,14620,14621,14623,14622,14624,4445,6165, | ||
| 181 | 10587,7950,5933,14626,14629,10289,5182,14628,14627,9779,14630,5396,14632, | ||
| 182 | 14631,4889,6677,9527,5672,7763,14633,7951,9223,10302,14634,14635,14636,10519, | ||
| 183 | 13372,7973,10283,6455,10052,10018,9260,11552,14638,6959,14639,3861,5427,7980, | ||
| 184 | 10303,14640,6689,8742,6714,7702,14641,10588,4182,6715,14644,14642,14645,11544, | ||
| 185 | 14643,8026,14646,8465,14647,4953,14649,14648,14650,14651,4954,9563, | ||
| 186 | 8725,5195,6716,8256,7227,3855,14652,4353,14656,6166,14655,6410,7449,14654, | ||
| 187 | 7450,11039,6409,3894,7981,14661,7952,4134,7220,10821,6481,7451,7942,14660, | ||
| 188 | 14658,14659,8778,14853,14665,6749,6167,14663,14664,7703,14662,6670,14667, | ||
| 189 | 14666,14671,14672,14668,4609,14669,14670,10036,10304,5673,14673,7953,7452, | ||
| 190 | 8753,5414,14674,14678,4394,14675,14677,14676,7242,8743,3876,14679,14680,8969, | ||
| 191 | 11600,6690,10570,10780,14849,14682,14685,14684,14681,14848,9533,14683,14850, | ||
| 192 | 7243,14851,11306,9815,14852,14854,14855,14856,5417,4135,6168,14857,14858,7248, | ||
| 193 | 8257,12599,8221,8220,8503,6438,12113,5709,11276,10589,10333,14859,6482,8990, | ||
| 194 | 14860,11790,10781,8970,14861,4955,14862,14863,11065,11011,10837,10811,6660, | ||
| 195 | 14865,6986,10800,14867,14870,14869,4952,5183,14866,14868,14871,7768,11354, | ||
| 196 | 3880,6463,8475,6972,7506,14874,9261,14872,8458,14873,7505,11068,14875,14876, | ||
| 197 | 11335,14881,6169,9780,14878,9291,14653,14657,5166,9766,14880,7453,10019,14886, | ||
| 198 | 10073,14877,14883,14882,7982,10828,11570,10822,4395,6717,11815,14885,7764, | ||
| 199 | 14884,14879,5934,14891,14889,4396,14887,14893,14899,8487,10528,14901,10241, | ||
| 200 | 14900,9807,10782,4890,8022,7199,9010,11277,14896,14895,14897,14894,14902, | ||
| 201 | 14892,14890,14898,14888,8779,11095,6949,6483,6425,10830,4640,9005,9513,4136, | ||
| 202 | 8017,7955,5641,14904,6170,4699,14906,4691,14912,14909,8018,4650,6411,4649, | ||
| 203 | 6446,14907,5700,5674,9292,14905,3877,14908,14910,5420,5643,4891,5162,14913, | ||
| 204 | 6488,10832,6678,14914,10255,14926,4370,14915,14932,14916,11553,14923, | ||
| 205 | 9790,14931,14918,3859,14920,6171,14922,14921,14917,14928,7454,13132,5959, | ||
| 206 | 11355,14919,9043,4610,6412,14911,14927,4672,14925,14929,9293,4957,15121,11048, | ||
| 207 | 14934,4956,14941,10783,15104,15106,15110,14936,8713,9294,15114,14939,15111, | ||
| 208 | 15105,7704,15115,7954,15113,4892,11823,14933,15109,3895,14935,11033,14940, | ||
| 209 | 7681,8998,14930,15108,7769,15118,4688,5888,15120,14937,15119,15112,14938, | ||
| 210 | 15116,15117,15134,9517,15107,15130,15132,9015,11307,10325,15127,8489,15133, | ||
| 211 | 8222,15124,15137,15136,9550,15135,9545,15139,15126,5415,15129,7228,9791,15131, | ||
| 212 | 5418,15123,15125,15122,11791,4665,15128,15138,4628,6470,4156,15155,11792, | ||
| 213 | 15158,7705,15157,15156,15153,15141,15170,15140,15159,15151,15146,15143,15144, | ||
| 214 | 15152,21249,15149,6172,8999,8259,15147,15142,15145,11308,10825,15150,15160, | ||
| 215 | 15168,15161,15174,15172,15167,15166,9007,8260,15164,15162,15169,15175,10068, | ||
| 216 | 15181,15176,15179,15173,8787,10263,15163,15171,7455,11054,15191,15178,5889, | ||
| 217 | 4354,4670,15154,7456,15183,15190,7000,4689,8717,15180,15185,15189,5397,5163, | ||
| 218 | 15187,5120,9514,15186,15188,15182,15184,4671,8744,15195,15193,5960,15192, | ||
| 219 | 15360,14903,15194,15196,15197,15371,15367,14924,15366,15365,15362,15177,15364, | ||
| 220 | 15363,15369,11781,15372,5466,15368,15370,9990,15373,15377,15374,11346,15375, | ||
| 221 | 15165,15378,15379,4116,15381,5702,6912,5428,4355,11326,15383,15382,15385,5148, | ||
| 222 | 5429,4893,15388,15387,15389,4397,8726,15390,4894,15392,15391,15393,15394, | ||
| 223 | 15395,6718,7956,6400,10319,10561,11811,6740,6447,11601,15396,15397,6719,15398, | ||
| 224 | 15399,15401,15400,10807, | ||
| 225 | 7229,6987,6691,15402,15404,7682,15403,15405,15406,15407,15408,15409,15411, | ||
| 226 | 15410,15412,4356,8745,15413,6661,4651,15414,9249,13099,5122,15415,15416,10571, | ||
| 227 | 10823,9510,15417,10053,10074,11058,15418,15420,15419,15422,15421,15424,6720, | ||
| 228 | 11024,15425,15426,5123,15427,15429,15428,7748,10264,4137,10020,9044,7200,5184, | ||
| 229 | 10021,6925,15431,4895,4183,9553,15430,6173,8754,15432,15440,15433,8480,5185, | ||
| 230 | 15441,5703,5124,15439,15437,15434,11327,8991,9528,15435,15443,15442,5634,4364, | ||
| 231 | 6426,15436,15438,10806,8531,10838,15451,15452,4398,10503,11100,15616,6914, | ||
| 232 | 7457,15447,15453,4167,5398,15444,15449,8019,9808,10054,15446,10752,15448, | ||
| 233 | 15619,15617,15450,10753,9767,5186,9220,8780,15620,15618,8504,15445,4138,11309, | ||
| 234 | 15631,15630,8021,15627,11339,9493,15621,8996,4139,6174,15624,7174,15629,15628, | ||
| 235 | 15623,15626,4679,15625,9768,11533,7507,8020,15637,15635,10284,15632,15634, | ||
| 236 | 4121,6175,11793,4636,10305,11328,4611,7706,15636,15641,7458,11279,15638,15633, | ||
| 237 | 15639,11581,9298,9505,4629,4148,15645,15648,11554,11331,15655,15649,15646, | ||
| 238 | 11571,15652,7209,15654,15659,9296,15657,15651,8727,15658,15647,15653,15660, | ||
| 239 | 3931,15650,15661,7707,7230,10500,6413,15642,15656,9241,7957,4680,6448,7459, | ||
| 240 | 15644,7201,5675,15643,15665,7244,5913,15680,15674,5203,9262,15669,15678,3854, | ||
| 241 | 4113,4376,15671,8459,15662,15664,6176,15681,15676,15668,15675,11018,15673, | ||
| 242 | 15677,5935,7460,8728,15667,11278,15670,15663,9297,15666,15672,11824,6941, | ||
| 243 | 10845,15682,9997,15694,5914,7231,15684,11534,6177,15697,3917,15695,15683, | ||
| 244 | 15689,15691,11310,15686,9229,15688,15696,15690,11046,15685,6913,15709,4681, | ||
| 245 | 15687,15692,15693,8523,8505,15701,15707,15705,9224,15874,15702,15703,15679, | ||
| 246 | 5208,10265,6942,6230,11794,15699,15873,4168,8261,9816,4896,11609,11008,9009, | ||
| 247 | 15706,15708,8209,15872,15704,15698,4898,5704,15886,15881,8023,4674,7232,15890, | ||
| 248 | 15883,8971,15880,9016,15915,15877,15876,15885,15879,15878,15884,7936,15875, | ||
| 249 | 15887,15888,4897,15893,15892,15894,15897,9250,15891,15895,5698,8536,15889, | ||
| 250 | 9754,15896,15901,15899,15902,15905,15898,6217,9735,15640,11347,15900,15904, | ||
| 251 | 8532,15903,15882,20040,15908,15912,15910,15906,15907,15911,15909,10285,15917, | ||
| 252 | 15914,15913,15916,9523,15918,8788,8524,7940,15919,15921,15920,15700,15922, | ||
| 253 | 9542,15923,4399,9299,4612,5187,6973,6449,11782,7749,4169,15925,15924,15928, | ||
| 254 | 8729,15931,15926,15930,15929,9247,3896,11604,15933,4103,15935,15934,15932, | ||
| 255 | 15927,10754,15937,15936,4170,15939,10513,15938,11028,7462,8210,7461,11610, | ||
| 256 | 15945,8024,15941,15946,4171,15944,9792,15940,15943,7463,10032,15947,6960,8025, | ||
| 257 | 15950,15942,5638,15948,11311,15951,21253,7214,15952,15953,9741,15955,15956, | ||
| 258 | 9746,9300,15958,15960,11572,15957,15959,4172,15954,12858,15961,8262,6679, | ||
| 259 | 15963,15962,7683,12600,15964,16128,15949,15965,16129,9817,16130,16131,16132, | ||
| 260 | 16133,9021,16135,16134,16136,16137,6974,10306,11083,16138,16139,8245,6915, | ||
| 261 | 16140,16141,16142,10545,10022,16143,9782,8972,16144,4422,5196,11045,11029, | ||
| 262 | 4371,11795,10801,10505,7958,16145,9506,5890,16146,6451,16148,16147,16149, | ||
| 263 | 16150,16151,5149,16152,16153, | ||
| 264 | 5891,10023,16155,7508,16154,5399,16156,16158,16157,16159,5936,16160,5448,8223, | ||
| 265 | 6236,16162,16163,16161,6988,9511,5400,16165,8715,16164,11796,9793,16168,16170, | ||
| 266 | 16167,11059,16169,16171,11555,16175,16174,8789,9740,5892,16173,16172,11280, | ||
| 267 | 11281,16176,4173,6229,6721,16177,16178,16180,7202,16182,16181,16183,4652, | ||
| 268 | 16185,16184,16187,16186,5915,11527,5419,4357,5449,4928,11591,16189,16191, | ||
| 269 | 16192,4400,16188,6680,8992,16190,16195,6989,16193,5661,10024,16194,16221, | ||
| 270 | 16200,5916,5188,16197,11356,11535,8533,16199,16201,11573,5430,10075,9769, | ||
| 271 | 16202,16204,16207,16203,16206,5961,4140,16208,7759,16205,11579,16211,21251, | ||
| 272 | 16209,16212,16198,16210,6427,16213,16214,11357,16215,16216,16196,16217,4899, | ||
| 273 | 6916,16218,16219,16220,4122,16384,10266,16385,4867,16386,16387,16388,16390, | ||
| 274 | 16391,16389,10290,16393,16392,16395,16394,16396,16397,16399,16398,6232,16401, | ||
| 275 | 16400,4900,7730,9243,16402,7959,6681,4184,16403,11312,10562,16404,9251,11282, | ||
| 276 | 6178,7708,8746,12563,8973,4423,16405,16406,16411,16409,16408,14625,4613,16407, | ||
| 277 | 3897,9993,10025,11536,16412,16410,8763,7941,9994,10252,16414,11531,5676,16415, | ||
| 278 | 16413,10037,16416,16417,3898,7509,16422,16419,9548,16418,5125,16425,16420, | ||
| 279 | 16421,16424,16423,10244,8225,8224,5150,16426,16427,16428,16430,16429,4149, | ||
| 280 | 16438,10055,16432,16434,16436,7709,16437,16435,6943,16431,16433,10273,7464, | ||
| 281 | 16440,16439,16441,6917,6414,9302,16442,9002,16444,11520,16443,8264,16449, | ||
| 282 | 16451,16452,8755,16450,16447,16445,16446,16448,16455,16453,16454,16456,16458, | ||
| 283 | 16459,16460,16461,16457, | ||
| 284 | 16463,16462,16464,11556,16467,16465,16466,4929,11101,10537,16469,16468,16470, | ||
| 285 | 16471,16475,16472,16473,16474,16476,16477,16640,16641,16642,9998,9263,16643, | ||
| 286 | 9809,10259,16644,16645,9225,4614,6179,16646,16647,16648,6664,16650,16649, | ||
| 287 | 16651,16652,10056,16653,16654,21064,16655,16656,16657,6669,16658,9781,10814, | ||
| 288 | 4141,4150,16659,16661,16660,9295,7960,15384,16662,11040,16663,4901,10038, | ||
| 289 | 16664,16665,16666,11067,11060,8989,8265,16668,7233,7465,16671,16670,16669, | ||
| 290 | 10076,4902,5896,16677,16674,7710,11025,16673,16675,16676,16672,16678,16679, | ||
| 291 | 8974,4930,8772,16680,16681,16684,7750,9507,16685,10802,16682,16683,16688, | ||
| 292 | 16687,16686,16690,16689,16691,16693,16692,10540,7221,11557,16694,9494,16695, | ||
| 293 | 16696,16700,16698,16699,16697,16701,16702,16703,16704,11030,16705,11087,16706, | ||
| 294 | 8749,9801,5450,8730,16707,5401,7983,16708,6428,16709,16710,5893,6452,16712, | ||
| 295 | 9269,6453,5165,10755,9770,9270,6203,16714,7466,11537,6180,5894,9986,16716, | ||
| 296 | 16718,5962,16717,9045,16720,4630,16715,10057,4111,6475,11825,16719,16721, | ||
| 297 | 10538,7992,16723,16724,16722,4653,16730,16729,6918,16731,16726,16732,16727, | ||
| 298 | 10039,16725,16728,16897,16896,10816,16733,3914,16899,16898,7467,16900,8226, | ||
| 299 | 16902,16901,16903,16711,16713,16905,16904,6919,11592,6961,16906,5654,5151, | ||
| 300 | 5126,6722,11283,16912,16911,8227,16908,16910,7210,7711,16909,16907,9737,7468, | ||
| 301 | 10267,6454,9303,16913,16914,16936,5431,11804,8212,16915,4401,9046,10496,16916, | ||
| 302 | 5209,16917,16919,16920,9736,16921,16922,16923,5432,4402,9508,7175,6723,16924, | ||
| 303 | 7176,4393,10274,16925, | ||
| 304 | 10058,8228,16928,16929,9800,7712,16926,8768,16927,7469,3899,5128,16930,9047, | ||
| 305 | 16931,7974,11020,10242,16932,16933,8756,11558,16935,16934,6990,16937,3919, | ||
| 306 | 16940,16938,4403,5677,16939,6181,6225,10565,16941,10803,16943,7984,4142,4377, | ||
| 307 | 3851,16942,16944,16945,7510,16946,4654,16948,5705,5189,16949,5460,16950,8027, | ||
| 308 | 9516,7999,6484,16951,8769,8266,16953,16955,16952,16954,5633,16956,5637,5190, | ||
| 309 | 11313,16958,16959,4109,16962,4693,16961,16960,16964,16957,16965,11528,16966, | ||
| 310 | 16967,13139,16969,16968,16970,16971,11540,16972,20302,7470,16973,16974,7222, | ||
| 311 | 9495,16975,8711,16976,8731,16977,5380,12318,8764,6930,4903,16978,17153,16981, | ||
| 312 | 5191,16980,17155,16979,7471,16983,16984,9226,16985,4669,7737,10307,16987,8519, | ||
| 313 | 16982,16986,16988,6490,17157,10253,9989,9304,5433,17156,17154,10004,16989, | ||
| 314 | 8765,9306,9305,6485,17175,17159,17161,17164,17165,17162,17163,17160,17158, | ||
| 315 | 17152,10542,4404,17172,17169,17174,17173,9810,11014,6682,17167,17176,17171, | ||
| 316 | 17170,17166,17168,4904,8732,8028,9985,17181,9987,8000,17178,10030,17182,10546, | ||
| 317 | 8762,17177,17179,17180,17183,6947,9509,17188,17187,17184,11797,17193,17197, | ||
| 318 | 17194,17190,17191,17196,17185,12596,17192,17186,17195,17201,4905,17198,17199, | ||
| 319 | 17200,17203,17202,10069,17204,11611,10572,17209,17206,17205,7985,17208,17210, | ||
| 320 | 17207,17214,17211,17212,17189,17213,17215,17216,10533,17217,11073,5421,5640, | ||
| 321 | 17218,10515,7751,11023,17219,11538,9811,8229,9747,7212,3871,17224,17222,17220, | ||
| 322 | 4864,7472,17225,17223,17221,17229,17228,17227,17226,17230,17231,7961,17232, | ||
| 323 | 17234, | ||
| 324 | 17233,5937,8215,17236,9307,17235,17237,10516,8267,6182,17238,11559,17240, | ||
| 325 | 17241,17242,17243,6724,17244,5678,5193,5129,17408,11090,6183,17245,17411, | ||
| 326 | 11077,9755,10258,7234,17410,6962,6184,6725,5192,10517,17409,8230,10785,6486, | ||
| 327 | 6726,9020,17414,11582,6456,17415,7713,17417,7473,6415,17416,7177,5917,8231, | ||
| 328 | 17412,17418,17413,5679,17421,17425,5706,17420,17429,6185,11340,3867,17426, | ||
| 329 | 5194,17423,17424,9308,17422,17419,4615,8003,5895,17431,17428,17430,17427,5680, | ||
| 330 | 8466,17432,8269,17445,17441,17435,17439,7001,3900,17434,17442,17446,6186, | ||
| 331 | 11061,9013,17436,17444,17433,8733,17438,3868,11049,17437,5434,10059,8268, | ||
| 332 | 11567,7246,17485,17447,8029,17443,17448,17450,9048,17453,17449,10547,4906, | ||
| 333 | 11050,3901,17452,11612,17451,4174,9547,17454,17461,17455,17462,17458,9818, | ||
| 334 | 6953,17460,17457,17463,17456,7203,10756,7211,17459,17471,17467,17470,17468, | ||
| 335 | 17472,17466,17440,7986,10026,17469,17464,8192,5681,7178,7684,8213,17475,17477, | ||
| 336 | 17478,17474,17476,17465,17473,17481,17480,10841,5642,17479,17483,17482,17486, | ||
| 337 | 17488,6683,17484,17489,17490,17491,17497,9242,17493,17492,17494,17495,17496, | ||
| 338 | 17498,17499,4907,17500,17501,17664,17665,17666,17667,17668,17669,17671,17670, | ||
| 339 | 17672,17673,17674,17677,17675,17676,6464,5682,8757,10002,7247,9772,10060, | ||
| 340 | 17678,14156,17679,17681,11332,17680,17683,17682,11314,17684,10077,17685,17688, | ||
| 341 | 17687,17686,17689,5649,8193,5152,17693,17690,17691,17694,17695,17692,4104, | ||
| 342 | 4358,17697,17698,17699,11329,7179,17701,17700,7752,17702,17703,17704,4932, | ||
| 343 | 4908,17705,17706,10812,11330, | ||
| 344 | 11315,11798,6188,17709,6963,17708,17710,6920,8496,17711,6187,11062,17712, | ||
| 345 | 17713,17714,17715,17716,6921,11084,17718,8734,17717,17720,17719,17721,7962, | ||
| 346 | 17722,17723,10520,17724,8270,17725,17726,11613,17729,17728,17727,8975,17730, | ||
| 347 | 7685,17731,17732,11799,17733,17734,17736,17735,9988,9560,11805,9992,17738, | ||
| 348 | 7474,10249,17739,17737,4909,5939,6727,10061,5897,10786,17742,17740,6189,6190, | ||
| 349 | 3912,6471,9784,3902,17747,8735,9783,8506,17749,17745,17748,17743,17746,10757, | ||
| 350 | 5940,3932,17744,17751,17752,9496,5402,17925,9756,6728,5403,7975,11813,11021, | ||
| 351 | 17750,7987,5170,17753,17755,17754,17756,8709,9757,8976,17922,17921,17757,7732, | ||
| 352 | 10308,17924,17923,6191,11826,17940,17928,17929,6991,17927,6231,17926,17930, | ||
| 353 | 8977,10497,8194,8507,17934,17935,17931,17932,17933,6192,17941,17937,10309, | ||
| 354 | 10827,10247,17936,17939,17938,10787,17942,17943,8214,17944,17946,17950,17947, | ||
| 355 | 17945,9758,17948,17949,4369,17956,17951,17952,17953,8448,17955,17954,17957, | ||
| 356 | 17958,17959,7714,4424,17960,11574,6922,7180,6729,8758,17961,17962,4112,17963, | ||
| 357 | 17964,17965,17966,17967,5404,14601,17968,8004,17969,6954,17970,12047,17971, | ||
| 358 | 10557,4923,8195,7223,10320,7181,17972,6193,17973,10027,17987,17975,8488,9812, | ||
| 359 | 5918,17974,8196,17976,9049,17978,17977,17980,17979,17981,17983,17982,4910, | ||
| 360 | 17984,17985,17986,6416,11560,17988,7686,4175,17989,17990,17991,3921,17992, | ||
| 361 | 17993,10310,6950,17995,4616,3857,17994,17997,9773,7715,4405,10758,5692,5435, | ||
| 362 | 17996,4425,4866,4176,18001,11593,8508,10275,18013,4406,18011,18009,18000, | ||
| 363 | 17998,17999, | ||
| 364 | 6978,5451,8790,9520,4144,18003,18002,18008,18004,18007,11055,18006,4407,4700, | ||
| 365 | 18010,18012,5683,18178,18187,18188,3850,18195,3920,18186,18185,18180,18179, | ||
| 366 | 18177,18176,8770,8538,18182,18181,18184,8271,5684,4128,18183,6194,8272,18201, | ||
| 367 | 18202,4408,4365,18199,18189,18197,18204,18198,18196,18005,18194,18190,4911, | ||
| 368 | 18192,18203,18193,18205,18191,9819,11336,18200,18222,18214,7770,5157,5436, | ||
| 369 | 18209,4410,7475,18212,6457,9264,18217,10573,18208,4409,5941,10248,18218,18206, | ||
| 370 | 18215,18225,18210,18211,9497,18216,18213,10759,18219,3903,18207,18221,18220, | ||
| 371 | 9802,18227,18238,4701,18241,18223,18228,11341,18237,11316,11529,8791,4682, | ||
| 372 | 10321,18243,9472,3856,18236,18232,8273,18226,18234,18239,9739,3849,18231, | ||
| 373 | 18240,10327,18235,18230,7476,7182,6923,11063,10278,18246,18255,18233,4694, | ||
| 374 | 7511,18244,18249,8274,18245,18252,8766,18253,11317,18242,4631,18248,18251, | ||
| 375 | 11019,18254,18247,18250,10760,11776,18258,18265,18257,6946,18224,10541,11009, | ||
| 376 | 18264,18263,18259,18260,4117,18262,18256,9012,18261,3933,8449,10530,18266, | ||
| 377 | 18432,10040,18269,7477,6952,18434,5405,18435,10328,18268,18229,18267,11822, | ||
| 378 | 9473,10322,18442,18448,18449,18436,9813,18446,18438,18440,18450,18439,18443, | ||
| 379 | 4177,9540,18444,18447,18437,8197,18441,6662,7716,5647,11091,11096,7249,18454, | ||
| 380 | 18452,11821,18451,11348,18453,18455,18456,18459,18457,9474,18458,10028,18445, | ||
| 381 | 7250,18460,18465,8275,18464,18433,18466,8232,18461,18463,18462,15376,15361, | ||
| 382 | 18468,18467,11349,16667,18469,18470,18471,5942,5171,18473,12348,5204,11545, | ||
| 383 | 5458,18474,18475,8781,18476, | ||
| 384 | 9561,3865,4418,18481,18482,18477,6684,18478,9761,18479,18480,18490,18484, | ||
| 385 | 18487,18483,18485,18486,6967,18488,8736,5685,4641,18491,4638,18496,18492, | ||
| 386 | 18495,10009,18493,18494,10279,10041,18497,8540,18507,18503,4426,18501,10761, | ||
| 387 | 18502,18499,18500,18505,18508,18506,18504,18498,8759,18515,11017,18513,18514, | ||
| 388 | 18509,18511,18512,18510,8005,11800,18519,18520,18688,7689,18522,18525,18517, | ||
| 389 | 18516,18689,4411,18523,18690,18524,18521,8978,18518,9799,18694,11290,18693, | ||
| 390 | 18692,18701,18695,18703,11333,18706,18697,18698,18702,18705,18704,18696,18699, | ||
| 391 | 18716,18709,18707,18708,18713,18714,4617,5153,18712,18691,18711,18715,18710, | ||
| 392 | 18717,18719,18718,18721,18720,18489,18725,18722,18723,18724,18726,5707,18728, | ||
| 393 | 18727,7183,6195,15622,18729,7216,4632,18730,4145,7478,18731,6196,18732,3904, | ||
| 394 | 10268,18733,7753,18740,18737,8782,18738,18735,5437,18734,18741,5653,8509, | ||
| 395 | 18747,18743,8468,18742,18745,18736,18746,18748,10062,18744,18749,18751,5938, | ||
| 396 | 18739,3872,18750,6458,11605,18752,18753,8276,11521,18754,11284,18755,18756, | ||
| 397 | 10563,18757,6431,11522,18762,18763,7479,18761,11334,18758,18760,7964,7773, | ||
| 398 | 18759,18764,10498,18766,18765,4683,10762,18767,18779,18769,18770,18771,18772, | ||
| 399 | 18776,18777,18775,18773,18768,18774,18778,20246,4359,18781,5438,18780,18945, | ||
| 400 | 18944,18947,18946,18948,7184,18949,18950,18951,7965,11318,18952,10499,9765, | ||
| 401 | 18953,18954,5898,5131,18955,6730,9760,18956,4655,18957,18959,11350,18958,7717, | ||
| 402 | 18960,18961,18962,4912,18963,18964,18965,18966,4656,18967,18968,18969,4433, | ||
| 403 | 7687,18970,18971,18972,5919,9050,18973, | ||
| 404 | 5686,7733,18976,9475,18975,5648,18974,8534,5132,18977,18978,7480,5708,18979, | ||
| 405 | 10763,7998,5205,11092,8233,18980,7718,8783,7481,18981,18984,18985,6429,8481, | ||
| 406 | 18983,7482,10269,18982,6731,4146,18989,5687,6733,6732,11820,18988,18987,8198, | ||
| 407 | 5164,11810,4633,7483,18986,18991,18992,18990,5943,11295,6734,9734,18995,7967, | ||
| 408 | 8737,11285,18998,5963,7966,18994,18999,5964,18996,18997,18993,8001,9512,8718, | ||
| 409 | 4412,10063,5154,8979,19002,19000,8747,7968,4913,19001,7738,11561,11807,19003, | ||
| 410 | 19014,8980,19013,19010,19018,19011,19007,9051,19006,19004,11264,6735,19008, | ||
| 411 | 19005,19012,7251,5920,8537,10788,4153,3905,9476,19016,19015,9541,19020,19009, | ||
| 412 | 19019,19021,5899,19017,6197,6964,19022,11319,19025,19028,19026,10260,19023, | ||
| 413 | 5439,19027,19029,19033,19030,19032,19031,19034,6928,19036,19035,10311,19200, | ||
| 414 | 5688,19037,19201,19202,5155,17696,7512,19203,5965,19204,19205,6685,14637, | ||
| 415 | 19206,19207,7185,19208,19209,19210,19211,19212,8714,19213,19215,19214,9477, | ||
| 416 | 19216,10764,19217,19218,19219,19220,9529,7484,19221,6218,12045,19222,19223, | ||
| 417 | 10270,19224,19232,19225,19227,19226,19228,10789,19229,19230,19231,19233,4620, | ||
| 418 | 9030,10312,6465,6198,10286,4414,10029,19236,4914,7988,19235,19240,8792,11074, | ||
| 419 | 19238,19239,5133,19241,9794,8510,10064,9244,19237,10790,4427,19243,11783,8993, | ||
| 420 | 11812,6736,19242,8464,19259,8199,9559,10287,19246,6686,6737,7485,9796,5900, | ||
| 421 | 19245,19244,10313,6944,9265,19248,19249,6199,19247,19250,19251,19253,8450, | ||
| 422 | 19252,4933,19255,19254,19256,19258,19260,19261,7989,6958,19262,4657, | ||
| 423 | 19263,8277,19264,19265,10314,5134,19266,8981,4154,19267,6992,7765,8460,19270, | ||
| 424 | 19269,19268,19276,19274,19271,19273,19272,19275,5206,19279,7990,19280,5944, | ||
| 425 | 19277,19278,11784,8982,8200,19281,19284,19282,19283,11320,9478,19287,19285, | ||
| 426 | 19286,19288,19464,19291,19292,19290,19289,9052,19456,19460,19457,19293,19458, | ||
| 427 | 19459,19466,19461,7991,19463,19465,19462,19468,7186,19467,19469,19470,19473, | ||
| 428 | 19472,19471,19475,19474,11093,19477,19476,19478,19479,19481,19480,7719,19482, | ||
| 429 | 5452,19483,19485,19486,19487,19484,19488,6965,19489,5135,5650,5901,19490,9551, | ||
| 430 | 9245,19491,19494,6931,19493,19492,5689,19495,4658,19497,6459,19496,19505, | ||
| 431 | 19499,19501,10564,19498,19500,19504,19502,5136,19503,19506,9785,11575,7187, | ||
| 432 | 19507,11265,19509,19508,19512,11296,19511,4684,19510,19515,19514,19513,9233, | ||
| 433 | 19516,19517,19518,6219,5636,19519,19520,19521,7720,19522,6924,19523,19524, | ||
| 434 | 12544,12381,19525,17487,19526,8707,7690,9759,19527,10548,9011,6237,8712,4105, | ||
| 435 | 10839,7734,5693,5440,10549,19528,19530,19529,4415,9557,19531,9814,9234,19532, | ||
| 436 | 7217,19534,11041,19549,19536,19537,9000,8511,8278,9479,19535,5172,19544,19541, | ||
| 437 | 19716,9480,8767,19538,9053,9266,19539,19543,7743,9798,9003,7969,19542,8461, | ||
| 438 | 8451,19540,3848,11777,19545,8512,7188,7721,19547,19546,3918,19548,10254,19718, | ||
| 439 | 9530,7754,8760,5463,19717,11286,4126,10550,4416,19712,19713,19714,19715,9498, | ||
| 440 | 8706,3906,19719,19720,21250,8476,19721,4178,8235,5902,11321,19722,9227,8279, | ||
| 441 | 6966,19723,19726,7236,19724,8202,8201,3907,11562,19728,10065,19730,19729, | ||
| 442 | 19727,16963,4915,19533,19732,19731,19733,11287,9536,10765,19734,6968,19735, | ||
| 443 | 19736,19737,9216,3913,6200,11801,19741,5651,19738,19739,10323,4659,11288,5406, | ||
| 444 | 9267,19742,19743,19744,9217,19746,19745,9522,19747,7189,6975,9786,8784,6993, | ||
| 445 | 7755,19748,19749,7740,19750,19751,19752,11342,7190,19754,19753,6201,6226,6687, | ||
| 446 | 19757,7237,19756,19755,8520,5966,7970,9999,7192,19758,7486,19761,19759,19760, | ||
| 447 | 19763,19762,7513,19764,19765,19766,10031,6450,6976,19767,19768,11523,7204, | ||
| 448 | 11085,11563,19769,5441,19770,9218,19773,4695,7722,19771,19772,9023,10804,5467, | ||
| 449 | 19775,19776,19774,19778,9534,4642,19782,19779,19781,19777,20014,19780,11594, | ||
| 450 | 5945,19790,9235,19785,19788,19786,19791,19792,19784,19797,4179,19783,9996, | ||
| 451 | 19787,7487,6202,10791,5443,7205,9499,8204,19795,19789,19794,11042,8983,19796, | ||
| 452 | 19793,8203,19800,19799,19798,10766,7258,19801,10558,4147,10277,8785,5207, | ||
| 453 | 19803,6204,6667,19802,7756,7757,19968,19970,7514,19969,19971,5426,10276,6977, | ||
| 454 | 11778,19805,6487,11806,19973,19972,19974,19804,9544,9268,9014,19979,8738, | ||
| 455 | 19975,19976,5644,19978,5903,19977,7488,4696,19983,6430,8280,9001,4634,19981, | ||
| 456 | 19982,8994,19980,19984,19990,19993,19992,9228,19985,19986,19989,19991,5407, | ||
| 457 | 19994,19988,19987,19998,19999,20000,19997,19996,7489,9481,19995,20004,20002, | ||
| 458 | 20003,20001,8535,20005,20006,20008,4916,20007,11097,20019,20009,20012,20010, | ||
| 459 | 20011,20013,20015,20016,20017,20020,20018,20021,20023,20022,8984,11078,20024, | ||
| 460 | 8205,20025,10531,20026,4618,4123,4918,4917,20027,20028,20029,20030,20031,4919, | ||
| 461 | 4660,6205,10005,20033,20032,20034,4155,20037,20036,20035,20038,20041,3878, | ||
| 462 | 20039,20043,20042,20045,20044,20046,9485,20047,20048,20050,20049,10315,20051, | ||
| 463 | 20052,6468,20053,20054,10792,8234,3843,8490,20055,10316,20058,20056,6206, | ||
| 464 | 20057,5921,10532,20060,20224,20061,20225,4096,7735,7259,4920,20226,9797,20228, | ||
| 465 | 4097,20227,8995,11564,9482,20059,11525,5904,11322,5464,11539,5639,8513,17920, | ||
| 466 | 20229,4619,7758,4661,20231,20232,20230,5699,6460,7490,4098,11576,20234,19725, | ||
| 467 | 20233,20237,20235,20236,20238,20239,11595,20240,20241,7976,10010,7772,4934, | ||
| 468 | 11289,4428,7191,5946,20244,20243,6738,20245,20242,6663,20249,18700,12597,7766, | ||
| 469 | 20247,11524,9552,4106,8002,6933,10518,4127,11596,11338,20250,9252,7002,20251, | ||
| 470 | 20252,7723,20253,11597,20248,20255,20257,20256,20254,20258,20259,8281,4417, | ||
| 471 | 20260,11031,20261,20262,11785,14864,20263,20264,20265,20269,20266,20267,20268, | ||
| 472 | 20270,7971,11094,7972,20271,10066,20272,21042,11051,20273,20274,20275,4662, | ||
| 473 | 20277,7736,20278,5635,20279,20283,20281,20282,4690,20280,20284,20285,3879, | ||
| 474 | 20286,20287,7491,20288,5158,20291,20290,20289,19024,10555,20292,20293,20294, | ||
| 475 | 20295,20296,20297,4921,20298,20299,9730,20301,4378,20304,20303,4099,5408, | ||
| 476 | 10534,8985,6401,6207,7238,7739,20306,20305,11297,4935,10033,9531,7771,11565, | ||
| 477 | 5690,20309,20308,10794,9483,4143,20310,20307,10288,11337,20311,20312,20314, | ||
| 478 | 8521,4666,4667,20313,4936,5905,4937,9246,11583,5947,20315,20316,20317,20480, | ||
| 479 | 20482,20481,10326,20483,20484,20485,20486,20488,20487,20489,10067,17707,7688, | ||
| 480 | 5137,20490, | ||
| 481 | 20491,12555,15386,10034,3930,3866,6739,10767,7517,20492,11070,20493,11323, | ||
| 482 | 4129,6688,20494,4429,20495,20496,20498,20499,20501,20497,20500,4922,20502, | ||
| 483 | 20503,20504,20505,20506,20508,20507,20510,20513,20509,20511,20512,20514,5409, | ||
| 484 | 6994,20515,20516,6208,20517,4637,9774,20518,20519,8761,9546,20520,9820,8491, | ||
| 485 | 4151,5453,5454,8786,20525,5455,4430,20524,20522,20523,20521,20535,20526,20527, | ||
| 486 | 20528,20529,20531,20530,7224,20532,20534,5138,20533,8282,5906,20536,8492, | ||
| 487 | 20537,9484,20538,20543,20541,20540,20542,20539,20545,20544,20547,5410,20546, | ||
| 488 | 20548,20549,20551,20550,20552,20554,20553,6235,20555,20556,4635,20557,20558, | ||
| 489 | 7760,20559,20560,20561,20562,6209,20563,20564,20565,20566,20567,10000,20569, | ||
| 490 | 10245,20570,20568,20572,20571,20573,20736,20737,20738,20739,20740,20741,20742, | ||
| 491 | 20743,20744,20745,20746,20747,20748,20749,15380,20750,17239,5139,4608,6417, | ||
| 492 | 20752,20751,11012,20754,20755,20753,20756,10817,20757,5210,11780,20758,20760, | ||
| 493 | 3869,20761,10506,20759,20762,20763,20764,20765,20766,10829,6668,6489,8206, | ||
| 494 | 20767,20770,20768,20771,5968,20769,20772,20773,20774,20778,6665,8515,20779, | ||
| 495 | 20776,20775,20777,5694,20783,20782,20781,3858,20793,20789,20790,20786,20792, | ||
| 496 | 20788,4673,11819,20791,20787,20785,20784,20795,20798,20797,20796,10280,20794, | ||
| 497 | 3922,20799,20801,4686,20780,4118,20803,20802,20800,8716,10831,11577,20804, | ||
| 498 | 20805,20806,20807,20808,8986,20809,10006,20814,20810,20811,10768,11043,9519, | ||
| 499 | 20815,20816,9501,20813,20812,4361,20824,20823,4180,20821,20820,20818,4698, | ||
| 500 | 20817,6929,4360,6210,20827,20826,20825, | ||
| 501 | 20822,20828,20829,20996,20995,20997,4108,20992,20993,6227,11032,20994,10769, | ||
| 502 | 21002,20998,21003,21000,20999,5691,21004,21005,21006,21001,20819,21007,9024, | ||
| 503 | 21011,21012,21010,21009,21015,21008,21013,21014,21017,21016,21019,21020,21021, | ||
| 504 | 11816,21018,8522,6476,21022,21023,21024,21025,21026,5907,21027,21028,6926, | ||
| 505 | 21029,21030,21031,21032,21035,21033,11803,21034,11598,21036,11578,21037,9821, | ||
| 506 | 21038,21040,21041,21039,6220,11052,10818,13654,15423,10842,4362,21043,5167, | ||
| 507 | 21044,21045,21046,6228,21047,16179,11066,8514,21048,21050,21049,21051,21052, | ||
| 508 | 21053,21054,21055,21056,21057,21058,21059,21060,21061,21062,21063,9219,5948, | ||
| 509 | 21065,8236,21066,21067,10240,21068,21069,16918,19257,20300,21070,21071,21073, | ||
| 510 | 21074,21075,11599,21072,21076,21077,21079,21078,21081,21082,21080,11541,21083, | ||
| 511 | 21084,16947,21085,9,83,79,82,84,41,42,85,59,3,4,30,527,528,529,530,531,532, | ||
| 512 | 533,534,535,536,6,7,66,64,67,8,86,544,545,546,547,548,549,550,551,552,553,554, | ||
| 513 | 555,556,557,558,559,560,561,562,563,564,565,566,567,568,569,45,46,15,17,13, | ||
| 514 | 576,577,578,579,580,581,582,583,584,585,586,587,588,589,590,591,592,593,594, | ||
| 515 | 595,596,597,598,599,600,601,47,34,48,16,78, | ||
lib/libc/wasi/libc-top-half/musl/src/locale/setlocale.c created+78| ... | @@ -0,0 +1,78 @@ | ||
| 1 | #include <locale.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "locale_impl.h" | ||
| 5 | #include "libc.h" | ||
| 6 | #include "lock.h" | ||
| 7 | |||
| 8 | static char buf[LC_ALL*(LOCALE_NAME_MAX+1)]; | ||
| 9 | |||
| 10 | char *setlocale(int cat, const char *name) | ||
| 11 | { | ||
| 12 | 	const struct __locale_map *lm; | ||
| 13 | |||
| 14 | 	if ((unsigned)cat > LC_ALL) return 0; | ||
| 15 | |||
| 16 | 	LOCK(__locale_lock); | ||
| 17 | |||
| 18 | 	/* For LC_ALL, setlocale is required to return a string which | ||
| 19 | 	 * encodes the current setting for all categories. The format of | ||
| 20 | 	 * this string is unspecified, and only the following code, which | ||
| 21 | 	 * performs both the serialization and deserialization, depends | ||
| 22 | 	 * on the format, so it can easily be changed if needed. */ | ||
| 23 | 	if (cat == LC_ALL) { | ||
| 24 | 		int i; | ||
| 25 | 		if (name) { | ||
| 26 | 			struct __locale_struct tmp_locale; | ||
| 27 | 			char part[LOCALE_NAME_MAX+1] = "C.UTF-8"; | ||
| 28 | 			const char *p = name; | ||
| 29 | 			for (i=0; i<LC_ALL; i++) { | ||
| 30 | 				const char *z = __strchrnul(p, ';'); | ||
| 31 | 				if (z-p <= LOCALE_NAME_MAX) { | ||
| 32 | 					memcpy(part, p, z-p); | ||
| 33 | 					part[z-p] = 0; | ||
| 34 | 					if (*z) p = z+1; | ||
| 35 | 				} | ||
| 36 | 				lm = __get_locale(i, part); | ||
| 37 | 				if (lm == LOC_MAP_FAILED) { | ||
| 38 | 					UNLOCK(__locale_lock); | ||
| 39 | 					return 0; | ||
| 40 | 				} | ||
| 41 | 				tmp_locale.cat[i] = lm; | ||
| 42 | 			} | ||
| 43 | 			libc.global_locale = tmp_locale; | ||
| 44 | 		} | ||
| 45 | 		char *s = buf; | ||
| 46 | 		const char *part; | ||
| 47 | 		int same = 0; | ||
| 48 | 		for (i=0; i<LC_ALL; i++) { | ||
| 49 | 			const struct __locale_map *lm = | ||
| 50 | 				libc.global_locale.cat[i]; | ||
| 51 | 			if (lm == libc.global_locale.cat[0]) same++; | ||
| 52 | 			part = lm ? lm->name : "C"; | ||
| 53 | 			size_t l = strlen(part); | ||
| 54 | 			memcpy(s, part, l); | ||
| 55 | 			s[l] = ';'; | ||
| 56 | 			s += l+1; | ||
| 57 | 		} | ||
| 58 | 		*--s = 0; | ||
| 59 | 		UNLOCK(__locale_lock); | ||
| 60 | 		return same==LC_ALL ? (char *)part : buf; | ||
| 61 | 	} | ||
| 62 | |||
| 63 | 	if (name) { | ||
| 64 | 		lm = __get_locale(cat, name); | ||
| 65 | 		if (lm == LOC_MAP_FAILED) { | ||
| 66 | 			UNLOCK(__locale_lock); | ||
| 67 | 			return 0; | ||
| 68 | 		} | ||
| 69 | 		libc.global_locale.cat[cat] = lm; | ||
| 70 | 	} else { | ||
| 71 | 		lm = libc.global_locale.cat[cat]; | ||
| 72 | 	} | ||
| 73 | 	char *ret = lm ? (char *)lm->name : "C"; | ||
| 74 | |||
| 75 | 	UNLOCK(__locale_lock); | ||
| 76 | |||
| 77 | 	return ret; | ||
| 78 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/strcoll.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <locale.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | int __strcoll_l(const char *l, const char *r, locale_t loc) | ||
| 6 | { | ||
| 7 | 	return strcmp(l, r); | ||
| 8 | } | ||
| 9 | |||
| 10 | int strcoll(const char *l, const char *r) | ||
| 11 | { | ||
| 12 | 	return __strcoll_l(l, r, CURRENT_LOCALE); | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(__strcoll_l, strcoll_l); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/strfmon.c created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include <monetary.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include "locale_impl.h" | ||
| 7 | |||
| 8 | static ssize_t vstrfmon_l(char *s, size_t n, locale_t loc, const char *fmt, va_list ap) | ||
| 9 | { | ||
| 10 | 	size_t l; | ||
| 11 | 	double x; | ||
| 12 | 	int fill, nogrp, negpar, nosym, left, intl; | ||
| 13 | 	int lp, rp, w, fw; | ||
| 14 | 	char *s0=s; | ||
| 15 | 	for (; n && *fmt; ) { | ||
| 16 | 		if (*fmt != '%') { | ||
| 17 | 		literal: | ||
| 18 | 			*s++ = *fmt++; | ||
| 19 | 			n--; | ||
| 20 | 			continue; | ||
| 21 | 		} | ||
| 22 | 		fmt++; | ||
| 23 | 		if (*fmt == '%') goto literal; | ||
| 24 | |||
| 25 | 		fill = ' '; | ||
| 26 | 		nogrp = 0; | ||
| 27 | 		negpar = 0; | ||
| 28 | 		nosym = 0; | ||
| 29 | 		left = 0; | ||
| 30 | 		for (; ; fmt++) { | ||
| 31 | 			switch (*fmt) { | ||
| 32 | 			case '=': | ||
| 33 | 				fill = *++fmt; | ||
| 34 | 				continue; | ||
| 35 | 			case '^': | ||
| 36 | 				nogrp = 1; | ||
| 37 | 				continue; | ||
| 38 | 			case '(': | ||
| 39 | 				negpar = 1; | ||
| 40 | 			case '+': | ||
| 41 | 				continue; | ||
| 42 | 			case '!': | ||
| 43 | 				nosym = 1; | ||
| 44 | 				continue; | ||
| 45 | 			case '-': | ||
| 46 | 				left = 1; | ||
| 47 | 				continue; | ||
| 48 | 			} | ||
| 49 | 			break; | ||
| 50 | 		} | ||
| 51 | |||
| 52 | 		for (fw=0; isdigit(*fmt); fmt++) | ||
| 53 | 			fw = 10*fw + (*fmt-'0'); | ||
| 54 | 		lp = 0; | ||
| 55 | 		rp = 2; | ||
| 56 | 		if (*fmt=='#') for (lp=0, fmt++; isdigit(*fmt); fmt++) | ||
| 57 | 			lp = 10*lp + (*fmt-'0'); | ||
| 58 | 		if (*fmt=='.') for (rp=0, fmt++; isdigit(*fmt); fmt++) | ||
| 59 | 			rp = 10*rp + (*fmt-'0'); | ||
| 60 | |||
| 61 | 		intl = *fmt++ == 'i'; | ||
| 62 | |||
| 63 | 		w = lp + 1 + rp; | ||
| 64 | 		if (!left && fw>w) w = fw; | ||
| 65 | |||
| 66 | 		x = va_arg(ap, double); | ||
| 67 | 		l = snprintf(s, n, "%*.*f", w, rp, x); | ||
| 68 | 		if (l >= n) { | ||
| 69 | 			errno = E2BIG; | ||
| 70 | 			return -1; | ||
| 71 | 		} | ||
| 72 | 		s += l; | ||
| 73 | 		n -= l; | ||
| 74 | 	} | ||
| 75 | 	return s-s0; | ||
| 76 | } | ||
| 77 | |||
| 78 | ssize_t strfmon_l(char *restrict s, size_t n, locale_t loc, const char *restrict fmt, ...) | ||
| 79 | { | ||
| 80 | 	va_list ap; | ||
| 81 | 	ssize_t ret; | ||
| 82 | |||
| 83 | 	va_start(ap, fmt); | ||
| 84 | 	ret = vstrfmon_l(s, n, loc, fmt, ap); | ||
| 85 | 	va_end(ap); | ||
| 86 | |||
| 87 | 	return ret; | ||
| 88 | } | ||
| 89 | |||
| 90 | |||
| 91 | ssize_t strfmon(char *restrict s, size_t n, const char *restrict fmt, ...) | ||
| 92 | { | ||
| 93 | 	va_list ap; | ||
| 94 | 	ssize_t ret; | ||
| 95 | |||
| 96 | 	va_start(ap, fmt); | ||
| 97 | 	ret = vstrfmon_l(s, n, CURRENT_LOCALE, fmt, ap); | ||
| 98 | 	va_end(ap); | ||
| 99 | |||
| 100 | 	return ret; | ||
| 101 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/strxfrm.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <locale.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | /* collate only by code points */ | ||
| 6 | size_t __strxfrm_l(char *restrict dest, const char *restrict src, size_t n, locale_t loc) | ||
| 7 | { | ||
| 8 | 	size_t l = strlen(src); | ||
| 9 | 	if (n > l) strcpy(dest, src); | ||
| 10 | 	return l; | ||
| 11 | } | ||
| 12 | |||
| 13 | size_t strxfrm(char *restrict dest, const char *restrict src, size_t n) | ||
| 14 | { | ||
| 15 | 	return __strxfrm_l(dest, src, n, CURRENT_LOCALE); | ||
| 16 | } | ||
| 17 | |||
| 18 | weak_alias(__strxfrm_l, strxfrm_l); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/textdomain.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include <libintl.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <limits.h> | ||
| 6 | |||
| 7 | static char *current_domain; | ||
| 8 | |||
| 9 | char *__gettextdomain() | ||
| 10 | { | ||
| 11 | 	return current_domain ? current_domain : "messages"; | ||
| 12 | } | ||
| 13 | |||
| 14 | char *textdomain(const char *domainname) | ||
| 15 | { | ||
| 16 | 	if (!domainname) return __gettextdomain(); | ||
| 17 | |||
| 18 | 	size_t domlen = strlen(domainname); | ||
| 19 | 	if (domlen > NAME_MAX) { | ||
| 20 | 		errno = EINVAL; | ||
| 21 | 		return 0; | ||
| 22 | 	} | ||
| 23 | |||
| 24 | 	if (!current_domain) { | ||
| 25 | 		current_domain = malloc(NAME_MAX+1); | ||
| 26 | 		if (!current_domain) return 0; | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	memcpy(current_domain, domainname, domlen+1); | ||
| 30 | |||
| 31 | 	return current_domain; | ||
| 32 | } | ||
| 33 | |||
| 34 | char *gettext(const char *msgid) | ||
| 35 | { | ||
| 36 | 	return dgettext(0, msgid); | ||
| 37 | } | ||
| 38 | |||
| 39 | char *ngettext(const char *msgid1, const char *msgid2, unsigned long int n) | ||
| 40 | { | ||
| 41 | 	return dngettext(0, msgid1, msgid2, n); | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/locale/uselocale.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 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/locale/wcscoll.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <locale.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | /* FIXME: stub */ | ||
| 6 | int __wcscoll_l(const wchar_t *l, const wchar_t *r, locale_t locale) | ||
| 7 | { | ||
| 8 | 	return wcscmp(l, r); | ||
| 9 | } | ||
| 10 | |||
| 11 | int wcscoll(const wchar_t *l, const wchar_t *r) | ||
| 12 | { | ||
| 13 | 	return __wcscoll_l(l, r, CURRENT_LOCALE); | ||
| 14 | } | ||
| 15 | |||
| 16 | weak_alias(__wcscoll_l, wcscoll_l); | ||
lib/libc/wasi/libc-top-half/musl/src/locale/wcsxfrm.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <locale.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | /* collate only by code points */ | ||
| 6 | size_t __wcsxfrm_l(wchar_t *restrict dest, const wchar_t *restrict src, size_t n, locale_t loc) | ||
| 7 | { | ||
| 8 | 	size_t l = wcslen(src); | ||
| 9 | 	if (l < n) { | ||
| 10 | 		wmemcpy(dest, src, l+1); | ||
| 11 | 	} else if (n) { | ||
| 12 | 		wmemcpy(dest, src, n-1); | ||
| 13 | 		dest[n-1] = 0; | ||
| 14 | 	} | ||
| 15 | 	return l; | ||
| 16 | } | ||
| 17 | |||
| 18 | size_t wcsxfrm(wchar_t *restrict dest, const wchar_t *restrict src, size_t n) | ||
| 19 | { | ||
| 20 | 	return __wcsxfrm_l(dest, src, n, CURRENT_LOCALE); | ||
| 21 | } | ||
| 22 | |||
| 23 | weak_alias(__wcsxfrm_l, wcsxfrm_l); | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/calloc.c created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "dynlink.h" | ||
| 6 | |||
| 7 | static size_t mal0_clear(char *p, size_t n) | ||
| 8 | { | ||
| 9 | 	const size_t pagesz = 4096; /* arbitrary */ | ||
| 10 | 	if (n < pagesz) return n; | ||
| 11 | #ifdef __GNUC__ | ||
| 12 | 	typedef uint64_t __attribute__((__may_alias__)) T; | ||
| 13 | #else | ||
| 14 | 	typedef unsigned char T; | ||
| 15 | #endif | ||
| 16 | 	char *pp = p + n; | ||
| 17 | 	size_t i = (uintptr_t)pp & (pagesz - 1); | ||
| 18 | 	for (;;) { | ||
| 19 | 		pp = memset(pp - i, 0, i); | ||
| 20 | 		if (pp - p < pagesz) return pp - p; | ||
| 21 | 		for (i = pagesz; i; i -= 2*sizeof(T), pp -= 2*sizeof(T)) | ||
| 22 | 		 if (((T *)pp)[-1] | ((T *)pp)[-2]) | ||
| 23 | 				break; | ||
| 24 | 	} | ||
| 25 | } | ||
| 26 | |||
| 27 | static int allzerop(void *p) | ||
| 28 | { | ||
| 29 | 	return 0; | ||
| 30 | } | ||
| 31 | weak_alias(allzerop, __malloc_allzerop); | ||
| 32 | |||
| 33 | void *calloc(size_t m, size_t n) | ||
| 34 | { | ||
| 35 | 	if (n && m > (size_t)-1/n) { | ||
| 36 | 		errno = ENOMEM; | ||
| 37 | 		return 0; | ||
| 38 | 	} | ||
| 39 | 	n *= m; | ||
| 40 | 	void *p = malloc(n); | ||
| 41 | 	if (!p || (!__malloc_replaced && __malloc_allzerop(p))) | ||
| 42 | 		return p; | ||
| 43 | 	n = mal0_clear(p, n); | ||
| 44 | 	return memset(p, 0, n); | ||
| 45 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/free.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | void free(void *p) | ||
| 4 | { | ||
| 5 | 	return __libc_free(p); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/libc_calloc.c created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | #define calloc __libc_calloc | ||
| 2 | #define malloc __libc_malloc | ||
| 3 | |||
| 4 | #include "calloc.c" | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/lite_malloc.c created+118| ... | @@ -0,0 +1,118 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <sys/mman.h> | ||
| 6 | #include "libc.h" | ||
| 7 | #include "lock.h" | ||
| 8 | #include "syscall.h" | ||
| 9 | #include "fork_impl.h" | ||
| 10 | |||
| 11 | #define ALIGN 16 | ||
| 12 | |||
| 13 | /* This function returns true if the interval [old,new] | ||
| 14 | * intersects the 'len'-sized interval below &libc.auxv | ||
| 15 | * (interpreted as the main-thread stack) or below &b | ||
| 16 | * (the current stack). It is used to defend against | ||
| 17 | * buggy brk implementations that can cross the stack. */ | ||
| 18 | |||
| 19 | static int traverses_stack_p(uintptr_t old, uintptr_t new) | ||
| 20 | { | ||
| 21 | 	const uintptr_t len = 8<<20; | ||
| 22 | 	uintptr_t a, b; | ||
| 23 | |||
| 24 | 	b = (uintptr_t)libc.auxv; | ||
| 25 | 	a = b > len ? b-len : 0; | ||
| 26 | 	if (new>a && old<b) return 1; | ||
| 27 | |||
| 28 | 	b = (uintptr_t)&b; | ||
| 29 | 	a = b > len ? b-len : 0; | ||
| 30 | 	if (new>a && old<b) return 1; | ||
| 31 | |||
| 32 | 	return 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | static volatile int lock[1]; | ||
| 36 | volatile int *const __bump_lockptr = lock; | ||
| 37 | |||
| 38 | static void *__simple_malloc(size_t n) | ||
| 39 | { | ||
| 40 | 	static uintptr_t brk, cur, end; | ||
| 41 | 	static unsigned mmap_step; | ||
| 42 | 	size_t align=1; | ||
| 43 | 	void *p; | ||
| 44 | |||
| 45 | 	if (n > SIZE_MAX/2) { | ||
| 46 | 		errno = ENOMEM; | ||
| 47 | 		return 0; | ||
| 48 | 	} | ||
| 49 | |||
| 50 | 	if (!n) n++; | ||
| 51 | 	while (align<n && align<ALIGN) | ||
| 52 | 		align += align; | ||
| 53 | |||
| 54 | 	LOCK(lock); | ||
| 55 | |||
| 56 | 	cur += -cur & align-1; | ||
| 57 | |||
| 58 | 	if (n > end-cur) { | ||
| 59 | 		size_t req = n - (end-cur) + PAGE_SIZE-1 & -PAGE_SIZE; | ||
| 60 | |||
| 61 | 		if (!cur) { | ||
| 62 | 			brk = __syscall(SYS_brk, 0); | ||
| 63 | 			brk += -brk & PAGE_SIZE-1; | ||
| 64 | 			cur = end = brk; | ||
| 65 | 		} | ||
| 66 | |||
| 67 | 		if (brk == end && req < SIZE_MAX-brk | ||
| 68 | 		 && !traverses_stack_p(brk, brk+req) | ||
| 69 | 		 && __syscall(SYS_brk, brk+req)==brk+req) { | ||
| 70 | 			brk = end += req; | ||
| 71 | 		} else { | ||
| 72 | 			int new_area = 0; | ||
| 73 | 			req = n + PAGE_SIZE-1 & -PAGE_SIZE; | ||
| 74 | 			/* Only make a new area rather than individual mmap | ||
| 75 | 			 * if wasted space would be over 1/8 of the map. */ | ||
| 76 | 			if (req-n > req/8) { | ||
| 77 | 				/* Geometric area size growth up to 64 pages, | ||
| 78 | 				 * bounding waste by 1/8 of the area. */ | ||
| 79 | 				size_t min = PAGE_SIZE<<(mmap_step/2); | ||
| 80 | 				if (min-n > end-cur) { | ||
| 81 | 					if (req < min) { | ||
| 82 | 						req = min; | ||
| 83 | 						if (mmap_step < 12) | ||
| 84 | 							mmap_step++; | ||
| 85 | 					} | ||
| 86 | 					new_area = 1; | ||
| 87 | 				} | ||
| 88 | 			} | ||
| 89 | 			void *mem = __mmap(0, req, PROT_READ|PROT_WRITE, | ||
| 90 | 				MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | ||
| 91 | 			if (mem == MAP_FAILED || !new_area) { | ||
| 92 | 				UNLOCK(lock); | ||
| 93 | 				return mem==MAP_FAILED ? 0 : mem; | ||
| 94 | 			} | ||
| 95 | 			cur = (uintptr_t)mem; | ||
| 96 | 			end = cur + req; | ||
| 97 | 		} | ||
| 98 | 	} | ||
| 99 | |||
| 100 | 	p = (void *)cur; | ||
| 101 | 	cur += n; | ||
| 102 | 	UNLOCK(lock); | ||
| 103 | 	return p; | ||
| 104 | } | ||
| 105 | |||
| 106 | weak_alias(__simple_malloc, __libc_malloc_impl); | ||
| 107 | |||
| 108 | void *__libc_malloc(size_t n) | ||
| 109 | { | ||
| 110 | 	return __libc_malloc_impl(n); | ||
| 111 | } | ||
| 112 | |||
| 113 | static void *default_malloc(size_t n) | ||
| 114 | { | ||
| 115 | 	return __libc_malloc_impl(n); | ||
| 116 | } | ||
| 117 | |||
| 118 | weak_alias(default_malloc, malloc); | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/aligned_alloc.c created+57| ... | @@ -0,0 +1,57 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "meta.h" | ||
| 4 | |||
| 5 | void *aligned_alloc(size_t align, size_t len) | ||
| 6 | { | ||
| 7 | 	if ((align & -align) != align) { | ||
| 8 | 		errno = EINVAL; | ||
| 9 | 		return 0; | ||
| 10 | 	} | ||
| 11 | |||
| 12 | 	if (len > SIZE_MAX - align || align >= (1ULL<<31)*UNIT) { | ||
| 13 | 		errno = ENOMEM; | ||
| 14 | 		return 0; | ||
| 15 | 	} | ||
| 16 | |||
| 17 | 	if (DISABLE_ALIGNED_ALLOC) { | ||
| 18 | 		errno = ENOMEM; | ||
| 19 | 		return 0; | ||
| 20 | 	} | ||
| 21 | |||
| 22 | 	if (align <= UNIT) align = UNIT; | ||
| 23 | |||
| 24 | 	unsigned char *p = malloc(len + align - UNIT); | ||
| 25 | 	struct meta *g = get_meta(p); | ||
| 26 | 	int idx = get_slot_index(p); | ||
| 27 | 	size_t stride = get_stride(g); | ||
| 28 | 	unsigned char *start = g->mem->storage + stride*idx; | ||
| 29 | 	unsigned char *end = g->mem->storage + stride*(idx+1) - IB; | ||
| 30 | 	size_t adj = -(uintptr_t)p & (align-1); | ||
| 31 | |||
| 32 | 	if (!adj) { | ||
| 33 | 		set_size(p, end, len); | ||
| 34 | 		return p; | ||
| 35 | 	} | ||
| 36 | 	p += adj; | ||
| 37 | 	uint32_t offset = (size_t)(p-g->mem->storage)/UNIT; | ||
| 38 | 	if (offset <= 0xffff) { | ||
| 39 | 		*(uint16_t *)(p-2) = offset; | ||
| 40 | 		p[-4] = 0; | ||
| 41 | 	} else { | ||
| 42 | 		// use a 32-bit offset if 16-bit doesn't fit. for this, | ||
| 43 | 		// 16-bit field must be zero, [-4] byte nonzero. | ||
| 44 | 		*(uint16_t *)(p-2) = 0; | ||
| 45 | 		*(uint32_t *)(p-8) = offset; | ||
| 46 | 		p[-4] = 1; | ||
| 47 | 	} | ||
| 48 | 	p[-3] = idx; | ||
| 49 | 	set_size(p, end, len); | ||
| 50 | 	// store offset to aligned enframing. this facilitates cycling | ||
| 51 | 	// offset and also iteration of heap for debugging/measurement. | ||
| 52 | 	// for extreme overalignment it won't fit but these are classless | ||
| 53 | 	// allocations anyway. | ||
| 54 | 	*(uint16_t *)(start - 2) = (size_t)(p-start)/UNIT; | ||
| 55 | 	start[-3] = 7<<5; | ||
| 56 | 	return p; | ||
| 57 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/donate.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <sys/mman.h> | ||
| 6 | #include <errno.h> | ||
| 7 | |||
| 8 | #include "meta.h" | ||
| 9 | |||
| 10 | static void donate(unsigned char *base, size_t len) | ||
| 11 | { | ||
| 12 | 	uintptr_t a = (uintptr_t)base; | ||
| 13 | 	uintptr_t b = a + len; | ||
| 14 | 	a += -a & (UNIT-1); | ||
| 15 | 	b -= b & (UNIT-1); | ||
| 16 | 	memset(base, 0, len); | ||
| 17 | 	for (int sc=47; sc>0 && b>a; sc-=4) { | ||
| 18 | 		if (b-a < (size_classes[sc]+1)*UNIT) continue; | ||
| 19 | 		struct meta *m = alloc_meta(); | ||
| 20 | 		m->avail_mask = 0; | ||
| 21 | 		m->freed_mask = 1; | ||
| 22 | 		m->mem = (void *)a; | ||
| 23 | 		m->mem->meta = m; | ||
| 24 | 		m->last_idx = 0; | ||
| 25 | 		m->freeable = 0; | ||
| 26 | 		m->sizeclass = sc; | ||
| 27 | 		m->maplen = 0; | ||
| 28 | 		*((unsigned char *)m->mem+UNIT-4) = 0; | ||
| 29 | 		*((unsigned char *)m->mem+UNIT-3) = 255; | ||
| 30 | 		m->mem->storage[size_classes[sc]*UNIT-4] = 0; | ||
| 31 | 		queue(&ctx.active[sc], m); | ||
| 32 | 		a += (size_classes[sc]+1)*UNIT; | ||
| 33 | 	} | ||
| 34 | } | ||
| 35 | |||
| 36 | void __malloc_donate(char *start, char *end) | ||
| 37 | { | ||
| 38 | 	donate((void *)start, end-start); | ||
| 39 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/free.c created+143| ... | @@ -0,0 +1,143 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sys/mman.h> | ||
| 4 | |||
| 5 | #include "meta.h" | ||
| 6 | |||
| 7 | struct mapinfo { | ||
| 8 | 	void *base; | ||
| 9 | 	size_t len; | ||
| 10 | }; | ||
| 11 | |||
| 12 | static struct mapinfo nontrivial_free(struct meta *, int); | ||
| 13 | |||
| 14 | static struct mapinfo free_group(struct meta *g) | ||
| 15 | { | ||
| 16 | 	struct mapinfo mi = { 0 }; | ||
| 17 | 	int sc = g->sizeclass; | ||
| 18 | 	if (sc < 48) { | ||
| 19 | 		ctx.usage_by_class[sc] -= g->last_idx+1; | ||
| 20 | 	} | ||
| 21 | 	if (g->maplen) { | ||
| 22 | 		step_seq(); | ||
| 23 | 		record_seq(sc); | ||
| 24 | 		mi.base = g->mem; | ||
| 25 | 		mi.len = g->maplen*4096UL; | ||
| 26 | 	} else { | ||
| 27 | 		void *p = g->mem; | ||
| 28 | 		struct meta *m = get_meta(p); | ||
| 29 | 		int idx = get_slot_index(p); | ||
| 30 | 		g->mem->meta = 0; | ||
| 31 | 		// not checking size/reserved here; it's intentionally invalid | ||
| 32 | 		mi = nontrivial_free(m, idx); | ||
| 33 | 	} | ||
| 34 | 	free_meta(g); | ||
| 35 | 	return mi; | ||
| 36 | } | ||
| 37 | |||
| 38 | static int okay_to_free(struct meta *g) | ||
| 39 | { | ||
| 40 | 	int sc = g->sizeclass; | ||
| 41 | |||
| 42 | 	if (!g->freeable) return 0; | ||
| 43 | |||
| 44 | 	// always free individual mmaps not suitable for reuse | ||
| 45 | 	if (sc >= 48 || get_stride(g) < UNIT*size_classes[sc]) | ||
| 46 | 		return 1; | ||
| 47 | |||
| 48 | 	// always free groups allocated inside another group's slot | ||
| 49 | 	// since recreating them should not be expensive and they | ||
| 50 | 	// might be blocking freeing of a much larger group. | ||
| 51 | 	if (!g->maplen) return 1; | ||
| 52 | |||
| 53 | 	// if there is another non-full group, free this one to | ||
| 54 | 	// consolidate future allocations, reduce fragmentation. | ||
| 55 | 	if (g->next != g) return 1; | ||
| 56 | |||
| 57 | 	// free any group in a size class that's not bouncing | ||
| 58 | 	if (!is_bouncing(sc)) return 1; | ||
| 59 | |||
| 60 | 	size_t cnt = g->last_idx+1; | ||
| 61 | 	size_t usage = ctx.usage_by_class[sc]; | ||
| 62 | |||
| 63 | 	// if usage is high enough that a larger count should be | ||
| 64 | 	// used, free the low-count group so a new one will be made. | ||
| 65 | 	if (9*cnt <= usage && cnt < 20) | ||
| 66 | 		return 1; | ||
| 67 | |||
| 68 | 	// otherwise, keep the last group in a bouncing class. | ||
| 69 | 	return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | static struct mapinfo nontrivial_free(struct meta *g, int i) | ||
| 73 | { | ||
| 74 | 	uint32_t self = 1u<<i; | ||
| 75 | 	int sc = g->sizeclass; | ||
| 76 | 	uint32_t mask = g->freed_mask | g->avail_mask; | ||
| 77 | |||
| 78 | 	if (mask+self == (2u<<g->last_idx)-1 && okay_to_free(g)) { | ||
| 79 | 		// any multi-slot group is necessarily on an active list | ||
| 80 | 		// here, but single-slot groups might or might not be. | ||
| 81 | 		if (g->next) { | ||
| 82 | 			assert(sc < 48); | ||
| 83 | 			int activate_new = (ctx.active[sc]==g); | ||
| 84 | 			dequeue(&ctx.active[sc], g); | ||
| 85 | 			if (activate_new && ctx.active[sc]) | ||
| 86 | 				activate_group(ctx.active[sc]); | ||
| 87 | 		} | ||
| 88 | 		return free_group(g); | ||
| 89 | 	} else if (!mask) { | ||
| 90 | 		assert(sc < 48); | ||
| 91 | 		// might still be active if there were no allocations | ||
| 92 | 		// after last available slot was taken. | ||
| 93 | 		if (ctx.active[sc] != g) { | ||
| 94 | 			queue(&ctx.active[sc], g); | ||
| 95 | 		} | ||
| 96 | 	} | ||
| 97 | 	a_or(&g->freed_mask, self); | ||
| 98 | 	return (struct mapinfo){ 0 }; | ||
| 99 | } | ||
| 100 | |||
| 101 | void free(void *p) | ||
| 102 | { | ||
| 103 | 	if (!p) return; | ||
| 104 | |||
| 105 | 	struct meta *g = get_meta(p); | ||
| 106 | 	int idx = get_slot_index(p); | ||
| 107 | 	size_t stride = get_stride(g); | ||
| 108 | 	unsigned char *start = g->mem->storage + stride*idx; | ||
| 109 | 	unsigned char *end = start + stride - IB; | ||
| 110 | 	get_nominal_size(p, end); | ||
| 111 | 	uint32_t self = 1u<<idx, all = (2u<<g->last_idx)-1; | ||
| 112 | 	((unsigned char *)p)[-3] = 255; | ||
| 113 | 	// invalidate offset to group header, and cycle offset of | ||
| 114 | 	// used region within slot if current offset is zero. | ||
| 115 | 	*(uint16_t *)((char *)p-2) = 0; | ||
| 116 | |||
| 117 | 	// release any whole pages contained in the slot to be freed | ||
| 118 | 	// unless it's a single-slot group that will be unmapped. | ||
| 119 | 	if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) { | ||
| 120 | 		unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1)); | ||
| 121 | 		size_t len = (end-base) & -PGSZ; | ||
| 122 | 		if (len) madvise(base, len, MADV_FREE); | ||
| 123 | 	} | ||
| 124 | |||
| 125 | 	// atomic free without locking if this is neither first or last slot | ||
| 126 | 	for (;;) { | ||
| 127 | 		uint32_t freed = g->freed_mask; | ||
| 128 | 		uint32_t avail = g->avail_mask; | ||
| 129 | 		uint32_t mask = freed | avail; | ||
| 130 | 		assert(!(mask&self)); | ||
| 131 | 		if (!freed || mask+self==all) break; | ||
| 132 | 		if (!MT) | ||
| 133 | 			g->freed_mask = freed+self; | ||
| 134 | 		else if (a_cas(&g->freed_mask, freed, freed+self)!=freed) | ||
| 135 | 			continue; | ||
| 136 | 		return; | ||
| 137 | 	} | ||
| 138 | |||
| 139 | 	wrlock(); | ||
| 140 | 	struct mapinfo mi = nontrivial_free(g, idx); | ||
| 141 | 	unlock(); | ||
| 142 | 	if (mi.len) munmap(mi.base, mi.len); | ||
| 143 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/glue.h created+93| ... | @@ -0,0 +1,93 @@ | ||
| 1 | #ifndef MALLOC_GLUE_H | ||
| 2 | #define MALLOC_GLUE_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <sys/mman.h> | ||
| 6 | #include <pthread.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <elf.h> | ||
| 9 | #include <string.h> | ||
| 10 | #include "atomic.h" | ||
| 11 | #include "syscall.h" | ||
| 12 | #include "libc.h" | ||
| 13 | #include "lock.h" | ||
| 14 | #include "dynlink.h" | ||
| 15 | |||
| 16 | // use macros to appropriately namespace these. | ||
| 17 | #define size_classes __malloc_size_classes | ||
| 18 | #define ctx __malloc_context | ||
| 19 | #define alloc_meta __malloc_alloc_meta | ||
| 20 | #define is_allzero __malloc_allzerop | ||
| 21 | #define dump_heap __dump_heap | ||
| 22 | |||
| 23 | #define malloc __libc_malloc_impl | ||
| 24 | #define realloc __libc_realloc | ||
| 25 | #define free __libc_free | ||
| 26 | |||
| 27 | #if USE_REAL_ASSERT | ||
| 28 | #include <assert.h> | ||
| 29 | #else | ||
| 30 | #undef assert | ||
| 31 | #define assert(x) do { if (!(x)) a_crash(); } while(0) | ||
| 32 | #endif | ||
| 33 | |||
| 34 | #define brk(p) ((uintptr_t)__syscall(SYS_brk, p)) | ||
| 35 | |||
| 36 | #define mmap __mmap | ||
| 37 | #define madvise __madvise | ||
| 38 | #define mremap __mremap | ||
| 39 | |||
| 40 | #define DISABLE_ALIGNED_ALLOC (__malloc_replaced && !__aligned_alloc_replaced) | ||
| 41 | |||
| 42 | static inline uint64_t get_random_secret() | ||
| 43 | { | ||
| 44 | 	uint64_t secret = (uintptr_t)&secret * 1103515245; | ||
| 45 | 	for (size_t i=0; libc.auxv[i]; i+=2) | ||
| 46 | 		if (libc.auxv[i]==AT_RANDOM) | ||
| 47 | 			memcpy(&secret, (char *)libc.auxv[i+1]+8, sizeof secret); | ||
| 48 | 	return secret; | ||
| 49 | } | ||
| 50 | |||
| 51 | #ifndef PAGESIZE | ||
| 52 | #define PAGESIZE PAGE_SIZE | ||
| 53 | #endif | ||
| 54 | |||
| 55 | #define MT (libc.need_locks) | ||
| 56 | |||
| 57 | #define RDLOCK_IS_EXCLUSIVE 1 | ||
| 58 | |||
| 59 | __attribute__((__visibility__("hidden"))) | ||
| 60 | extern int __malloc_lock[1]; | ||
| 61 | |||
| 62 | #define LOCK_OBJ_DEF \ | ||
| 63 | int __malloc_lock[1]; \ | ||
| 64 | void __malloc_atfork(int who) { malloc_atfork(who); } | ||
| 65 | |||
| 66 | static inline void rdlock() | ||
| 67 | { | ||
| 68 | 	if (MT) LOCK(__malloc_lock); | ||
| 69 | } | ||
| 70 | static inline void wrlock() | ||
| 71 | { | ||
| 72 | 	if (MT) LOCK(__malloc_lock); | ||
| 73 | } | ||
| 74 | static inline void unlock() | ||
| 75 | { | ||
| 76 | 	UNLOCK(__malloc_lock); | ||
| 77 | } | ||
| 78 | static inline void upgradelock() | ||
| 79 | { | ||
| 80 | } | ||
| 81 | static inline void resetlock() | ||
| 82 | { | ||
| 83 | 	__malloc_lock[0] = 0; | ||
| 84 | } | ||
| 85 | |||
| 86 | static inline void malloc_atfork(int who) | ||
| 87 | { | ||
| 88 | 	if (who<0) rdlock(); | ||
| 89 | 	else if (who>0) resetlock(); | ||
| 90 | 	else unlock(); | ||
| 91 | } | ||
| 92 | |||
| 93 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/malloc.c created+387| ... | @@ -0,0 +1,387 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <sys/mman.h> | ||
| 6 | #include <errno.h> | ||
| 7 | |||
| 8 | #include "meta.h" | ||
| 9 | |||
| 10 | LOCK_OBJ_DEF; | ||
| 11 | |||
| 12 | const uint16_t size_classes[] = { | ||
| 13 | 	1, 2, 3, 4, 5, 6, 7, 8, | ||
| 14 | 	9, 10, 12, 15, | ||
| 15 | 	18, 20, 25, 31, | ||
| 16 | 	36, 42, 50, 63, | ||
| 17 | 	72, 84, 102, 127, | ||
| 18 | 	146, 170, 204, 255, | ||
| 19 | 	292, 340, 409, 511, | ||
| 20 | 	584, 682, 818, 1023, | ||
| 21 | 	1169, 1364, 1637, 2047, | ||
| 22 | 	2340, 2730, 3276, 4095, | ||
| 23 | 	4680, 5460, 6552, 8191, | ||
| 24 | }; | ||
| 25 | |||
| 26 | static const uint8_t small_cnt_tab[][3] = { | ||
| 27 | 	{ 30, 30, 30 }, | ||
| 28 | 	{ 31, 15, 15 }, | ||
| 29 | 	{ 20, 10, 10 }, | ||
| 30 | 	{ 31, 15, 7 }, | ||
| 31 | 	{ 25, 12, 6 }, | ||
| 32 | 	{ 21, 10, 5 }, | ||
| 33 | 	{ 18, 8, 4 }, | ||
| 34 | 	{ 31, 15, 7 }, | ||
| 35 | 	{ 28, 14, 6 }, | ||
| 36 | }; | ||
| 37 | |||
| 38 | static const uint8_t med_cnt_tab[4] = { 28, 24, 20, 32 }; | ||
| 39 | |||
| 40 | struct malloc_context ctx = { 0 }; | ||
| 41 | |||
| 42 | struct meta *alloc_meta(void) | ||
| 43 | { | ||
| 44 | 	struct meta *m; | ||
| 45 | 	unsigned char *p; | ||
| 46 | 	if (!ctx.init_done) { | ||
| 47 | #ifndef PAGESIZE | ||
| 48 | 		ctx.pagesize = get_page_size(); | ||
| 49 | #endif | ||
| 50 | 		ctx.secret = get_random_secret(); | ||
| 51 | 		ctx.init_done = 1; | ||
| 52 | 	} | ||
| 53 | 	size_t pagesize = PGSZ; | ||
| 54 | 	if (pagesize < 4096) pagesize = 4096; | ||
| 55 | 	if ((m = dequeue_head(&ctx.free_meta_head))) return m; | ||
| 56 | 	if (!ctx.avail_meta_count) { | ||
| 57 | 		int need_unprotect = 1; | ||
| 58 | 		if (!ctx.avail_meta_area_count && ctx.brk!=-1) { | ||
| 59 | 			uintptr_t new = ctx.brk + pagesize; | ||
| 60 | 			int need_guard = 0; | ||
| 61 | 			if (!ctx.brk) { | ||
| 62 | 				need_guard = 1; | ||
| 63 | 				ctx.brk = brk(0); | ||
| 64 | 				// some ancient kernels returned _ebss | ||
| 65 | 				// instead of next page as initial brk. | ||
| 66 | 				ctx.brk += -ctx.brk & (pagesize-1); | ||
| 67 | 				new = ctx.brk + 2*pagesize; | ||
| 68 | 			} | ||
| 69 | 			if (brk(new) != new) { | ||
| 70 | 				ctx.brk = -1; | ||
| 71 | 			} else { | ||
| 72 | 				if (need_guard) mmap((void *)ctx.brk, pagesize, | ||
| 73 | 					PROT_NONE, MAP_ANON|MAP_PRIVATE|MAP_FIXED, -1, 0); | ||
| 74 | 				ctx.brk = new; | ||
| 75 | 				ctx.avail_meta_areas = (void *)(new - pagesize); | ||
| 76 | 				ctx.avail_meta_area_count = pagesize>>12; | ||
| 77 | 				need_unprotect = 0; | ||
| 78 | 			} | ||
| 79 | 		} | ||
| 80 | 		if (!ctx.avail_meta_area_count) { | ||
| 81 | 			size_t n = 2UL << ctx.meta_alloc_shift; | ||
| 82 | 			p = mmap(0, n*pagesize, PROT_NONE, | ||
| 83 | 				MAP_PRIVATE|MAP_ANON, -1, 0); | ||
| 84 | 			if (p==MAP_FAILED) return 0; | ||
| 85 | 			ctx.avail_meta_areas = p + pagesize; | ||
| 86 | 			ctx.avail_meta_area_count = (n-1)*(pagesize>>12); | ||
| 87 | 			ctx.meta_alloc_shift++; | ||
| 88 | 		} | ||
| 89 | 		p = ctx.avail_meta_areas; | ||
| 90 | 		if ((uintptr_t)p & (pagesize-1)) need_unprotect = 0; | ||
| 91 | 		if (need_unprotect) | ||
| 92 | 			if (mprotect(p, pagesize, PROT_READ|PROT_WRITE) | ||
| 93 | 			 && errno != ENOSYS) | ||
| 94 | 				return 0; | ||
| 95 | 		ctx.avail_meta_area_count--; | ||
| 96 | 		ctx.avail_meta_areas = p + 4096; | ||
| 97 | 		if (ctx.meta_area_tail) { | ||
| 98 | 			ctx.meta_area_tail->next = (void *)p; | ||
| 99 | 		} else { | ||
| 100 | 			ctx.meta_area_head = (void *)p; | ||
| 101 | 		} | ||
| 102 | 		ctx.meta_area_tail = (void *)p; | ||
| 103 | 		ctx.meta_area_tail->check = ctx.secret; | ||
| 104 | 		ctx.avail_meta_count = ctx.meta_area_tail->nslots | ||
| 105 | 			= (4096-sizeof(struct meta_area))/sizeof *m; | ||
| 106 | 		ctx.avail_meta = ctx.meta_area_tail->slots; | ||
| 107 | 	} | ||
| 108 | 	ctx.avail_meta_count--; | ||
| 109 | 	m = ctx.avail_meta++; | ||
| 110 | 	m->prev = m->next = 0; | ||
| 111 | 	return m; | ||
| 112 | } | ||
| 113 | |||
| 114 | static uint32_t try_avail(struct meta **pm) | ||
| 115 | { | ||
| 116 | 	struct meta *m = *pm; | ||
| 117 | 	uint32_t first; | ||
| 118 | 	if (!m) return 0; | ||
| 119 | 	uint32_t mask = m->avail_mask; | ||
| 120 | 	if (!mask) { | ||
| 121 | 		if (!m) return 0; | ||
| 122 | 		if (!m->freed_mask) { | ||
| 123 | 			dequeue(pm, m); | ||
| 124 | 			m = *pm; | ||
| 125 | 			if (!m) return 0; | ||
| 126 | 		} else { | ||
| 127 | 			m = m->next; | ||
| 128 | 			*pm = m; | ||
| 129 | 		} | ||
| 130 | |||
| 131 | 		mask = m->freed_mask; | ||
| 132 | |||
| 133 | 		// skip fully-free group unless it's the only one | ||
| 134 | 		// or it's a permanently non-freeable group | ||
| 135 | 		if (mask == (2u<<m->last_idx)-1 && m->freeable) { | ||
| 136 | 			m = m->next; | ||
| 137 | 			*pm = m; | ||
| 138 | 			mask = m->freed_mask; | ||
| 139 | 		} | ||
| 140 | |||
| 141 | 		// activate more slots in a not-fully-active group | ||
| 142 | 		// if needed, but only as a last resort. prefer using | ||
| 143 | 		// any other group with free slots. this avoids | ||
| 144 | 		// touching & dirtying as-yet-unused pages. | ||
| 145 | 		if (!(mask & ((2u<<m->mem->active_idx)-1))) { | ||
| 146 | 			if (m->next != m) { | ||
| 147 | 				m = m->next; | ||
| 148 | 				*pm = m; | ||
| 149 | 			} else { | ||
| 150 | 				int cnt = m->mem->active_idx + 2; | ||
| 151 | 				int size = size_classes[m->sizeclass]*UNIT; | ||
| 152 | 				int span = UNIT + size*cnt; | ||
| 153 | 				// activate up to next 4k boundary | ||
| 154 | 				while ((span^(span+size-1)) < 4096) { | ||
| 155 | 					cnt++; | ||
| 156 | 					span += size; | ||
| 157 | 				} | ||
| 158 | 				if (cnt > m->last_idx+1) | ||
| 159 | 					cnt = m->last_idx+1; | ||
| 160 | 				m->mem->active_idx = cnt-1; | ||
| 161 | 			} | ||
| 162 | 		} | ||
| 163 | 		mask = activate_group(m); | ||
| 164 | 		assert(mask); | ||
| 165 | 		decay_bounces(m->sizeclass); | ||
| 166 | 	} | ||
| 167 | 	first = mask&-mask; | ||
| 168 | 	m->avail_mask = mask-first; | ||
| 169 | 	return first; | ||
| 170 | } | ||
| 171 | |||
| 172 | static int alloc_slot(int, size_t); | ||
| 173 | |||
| 174 | static struct meta *alloc_group(int sc, size_t req) | ||
| 175 | { | ||
| 176 | 	size_t size = UNIT*size_classes[sc]; | ||
| 177 | 	int i = 0, cnt; | ||
| 178 | 	unsigned char *p; | ||
| 179 | 	struct meta *m = alloc_meta(); | ||
| 180 | 	if (!m) return 0; | ||
| 181 | 	size_t usage = ctx.usage_by_class[sc]; | ||
| 182 | 	size_t pagesize = PGSZ; | ||
| 183 | 	int active_idx; | ||
| 184 | 	if (sc < 9) { | ||
| 185 | 		while (i<2 && 4*small_cnt_tab[sc][i] > usage) | ||
| 186 | 			i++; | ||
| 187 | 		cnt = small_cnt_tab[sc][i]; | ||
| 188 | 	} else { | ||
| 189 | 		// lookup max number of slots fitting in power-of-two size | ||
| 190 | 		// from a table, along with number of factors of two we | ||
| 191 | 		// can divide out without a remainder or reaching 1. | ||
| 192 | 		cnt = med_cnt_tab[sc&3]; | ||
| 193 | |||
| 194 | 		// reduce cnt to avoid excessive eagar allocation. | ||
| 195 | 		while (!(cnt&1) && 4*cnt > usage) | ||
| 196 | 			cnt >>= 1; | ||
| 197 | |||
| 198 | 		// data structures don't support groups whose slot offsets | ||
| 199 | 		// in units don't fit in 16 bits. | ||
| 200 | 		while (size*cnt >= 65536*UNIT) | ||
| 201 | 			cnt >>= 1; | ||
| 202 | 	} | ||
| 203 | |||
| 204 | 	// If we selected a count of 1 above but it's not sufficient to use | ||
| 205 | 	// mmap, increase to 2. Then it might be; if not it will nest. | ||
| 206 | 	if (cnt==1 && size*cnt+UNIT <= pagesize/2) cnt = 2; | ||
| 207 | |||
| 208 | 	// All choices of size*cnt are "just below" a power of two, so anything | ||
| 209 | 	// larger than half the page size should be allocated as whole pages. | ||
| 210 | 	if (size*cnt+UNIT > pagesize/2) { | ||
| 211 | 		// check/update bounce counter to start/increase retention | ||
| 212 | 		// of freed maps, and inhibit use of low-count, odd-size | ||
| 213 | 		// small mappings and single-slot groups if activated. | ||
| 214 | 		int nosmall = is_bouncing(sc); | ||
| 215 | 		account_bounce(sc); | ||
| 216 | 		step_seq(); | ||
| 217 | |||
| 218 | 		// since the following count reduction opportunities have | ||
| 219 | 		// an absolute memory usage cost, don't overdo them. count | ||
| 220 | 		// coarse usage as part of usage. | ||
| 221 | 		if (!(sc&1) && sc<32) usage += ctx.usage_by_class[sc+1]; | ||
| 222 | |||
| 223 | 		// try to drop to a lower count if the one found above | ||
| 224 | 		// increases usage by more than 25%. these reduced counts | ||
| 225 | 		// roughly fill an integral number of pages, just not a | ||
| 226 | 		// power of two, limiting amount of unusable space. | ||
| 227 | 		if (4*cnt > usage && !nosmall) { | ||
| 228 | 			if (0); | ||
| 229 | 			else if ((sc&3)==1 && size*cnt>8*pagesize) cnt = 2; | ||
| 230 | 			else if ((sc&3)==2 && size*cnt>4*pagesize) cnt = 3; | ||
| 231 | 			else if ((sc&3)==0 && size*cnt>8*pagesize) cnt = 3; | ||
| 232 | 			else if ((sc&3)==0 && size*cnt>2*pagesize) cnt = 5; | ||
| 233 | 		} | ||
| 234 | 		size_t needed = size*cnt + UNIT; | ||
| 235 | 		needed += -needed & (pagesize-1); | ||
| 236 | |||
| 237 | 		// produce an individually-mmapped allocation if usage is low, | ||
| 238 | 		// bounce counter hasn't triggered, and either it saves memory | ||
| 239 | 		// or it avoids eagar slot allocation without wasting too much. | ||
| 240 | 		if (!nosmall && cnt<=7) { | ||
| 241 | 			req += IB + UNIT; | ||
| 242 | 			req += -req & (pagesize-1); | ||
| 243 | 			if (req<size+UNIT || (req>=4*pagesize && 2*cnt>usage)) { | ||
| 244 | 				cnt = 1; | ||
| 245 | 				needed = req; | ||
| 246 | 			} | ||
| 247 | 		} | ||
| 248 | |||
| 249 | 		p = mmap(0, needed, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); | ||
| 250 | 		if (p==MAP_FAILED) { | ||
| 251 | 			free_meta(m); | ||
| 252 | 			return 0; | ||
| 253 | 		} | ||
| 254 | 		m->maplen = needed>>12; | ||
| 255 | 		ctx.mmap_counter++; | ||
| 256 | 		active_idx = (4096-UNIT)/size-1; | ||
| 257 | 		if (active_idx > cnt-1) active_idx = cnt-1; | ||
| 258 | 		if (active_idx < 0) active_idx = 0; | ||
| 259 | 	} else { | ||
| 260 | 		int j = size_to_class(UNIT+cnt*size-IB); | ||
| 261 | 		int idx = alloc_slot(j, UNIT+cnt*size-IB); | ||
| 262 | 		if (idx < 0) { | ||
| 263 | 			free_meta(m); | ||
| 264 | 			return 0; | ||
| 265 | 		} | ||
| 266 | 		struct meta *g = ctx.active[j]; | ||
| 267 | 		p = enframe(g, idx, UNIT*size_classes[j]-IB, ctx.mmap_counter); | ||
| 268 | 		m->maplen = 0; | ||
| 269 | 		p[-3] = (p[-3]&31) | (6<<5); | ||
| 270 | 		for (int i=0; i<=cnt; i++) | ||
| 271 | 			p[UNIT+i*size-4] = 0; | ||
| 272 | 		active_idx = cnt-1; | ||
| 273 | 	} | ||
| 274 | 	ctx.usage_by_class[sc] += cnt; | ||
| 275 | 	m->avail_mask = (2u<<active_idx)-1; | ||
| 276 | 	m->freed_mask = (2u<<(cnt-1))-1 - m->avail_mask; | ||
| 277 | 	m->mem = (void *)p; | ||
| 278 | 	m->mem->meta = m; | ||
| 279 | 	m->mem->active_idx = active_idx; | ||
| 280 | 	m->last_idx = cnt-1; | ||
| 281 | 	m->freeable = 1; | ||
| 282 | 	m->sizeclass = sc; | ||
| 283 | 	return m; | ||
| 284 | } | ||
| 285 | |||
| 286 | static int alloc_slot(int sc, size_t req) | ||
| 287 | { | ||
| 288 | 	uint32_t first = try_avail(&ctx.active[sc]); | ||
| 289 | 	if (first) return a_ctz_32(first); | ||
| 290 | |||
| 291 | 	struct meta *g = alloc_group(sc, req); | ||
| 292 | 	if (!g) return -1; | ||
| 293 | |||
| 294 | 	g->avail_mask--; | ||
| 295 | 	queue(&ctx.active[sc], g); | ||
| 296 | 	return 0; | ||
| 297 | } | ||
| 298 | |||
| 299 | void *malloc(size_t n) | ||
| 300 | { | ||
| 301 | 	if (size_overflows(n)) return 0; | ||
| 302 | 	struct meta *g; | ||
| 303 | 	uint32_t mask, first; | ||
| 304 | 	int sc; | ||
| 305 | 	int idx; | ||
| 306 | 	int ctr; | ||
| 307 | |||
| 308 | 	if (n >= MMAP_THRESHOLD) { | ||
| 309 | 		size_t needed = n + IB + UNIT; | ||
| 310 | 		void *p = mmap(0, needed, PROT_READ|PROT_WRITE, | ||
| 311 | 			MAP_PRIVATE|MAP_ANON, -1, 0); | ||
| 312 | 		if (p==MAP_FAILED) return 0; | ||
| 313 | 		wrlock(); | ||
| 314 | 		step_seq(); | ||
| 315 | 		g = alloc_meta(); | ||
| 316 | 		if (!g) { | ||
| 317 | 			unlock(); | ||
| 318 | 			munmap(p, needed); | ||
| 319 | 			return 0; | ||
| 320 | 		} | ||
| 321 | 		g->mem = p; | ||
| 322 | 		g->mem->meta = g; | ||
| 323 | 		g->last_idx = 0; | ||
| 324 | 		g->freeable = 1; | ||
| 325 | 		g->sizeclass = 63; | ||
| 326 | 		g->maplen = (needed+4095)/4096; | ||
| 327 | 		g->avail_mask = g->freed_mask = 0; | ||
| 328 | 		// use a global counter to cycle offset in | ||
| 329 | 		// individually-mmapped allocations. | ||
| 330 | 		ctx.mmap_counter++; | ||
| 331 | 		idx = 0; | ||
| 332 | 		goto success; | ||
| 333 | 	} | ||
| 334 | |||
| 335 | 	sc = size_to_class(n); | ||
| 336 | |||
| 337 | 	rdlock(); | ||
| 338 | 	g = ctx.active[sc]; | ||
| 339 | |||
| 340 | 	// use coarse size classes initially when there are not yet | ||
| 341 | 	// any groups of desired size. this allows counts of 2 or 3 | ||
| 342 | 	// to be allocated at first rather than having to start with | ||
| 343 | 	// 7 or 5, the min counts for even size classes. | ||
| 344 | 	if (!g && sc>=4 && sc<32 && sc!=6 && !(sc&1) && !ctx.usage_by_class[sc]) { | ||
| 345 | 		size_t usage = ctx.usage_by_class[sc|1]; | ||
| 346 | 		// if a new group may be allocated, count it toward | ||
| 347 | 		// usage in deciding if we can use coarse class. | ||
| 348 | 		if (!ctx.active[sc|1] || (!ctx.active[sc|1]->avail_mask | ||
| 349 | 		 && !ctx.active[sc|1]->freed_mask)) | ||
| 350 | 			usage += 3; | ||
| 351 | 		if (usage <= 12) | ||
| 352 | 			sc |= 1; | ||
| 353 | 		g = ctx.active[sc]; | ||
| 354 | 	} | ||
| 355 | |||
| 356 | 	for (;;) { | ||
| 357 | 		mask = g ? g->avail_mask : 0; | ||
| 358 | 		first = mask&-mask; | ||
| 359 | 		if (!first) break; | ||
| 360 | 		if (RDLOCK_IS_EXCLUSIVE || !MT) | ||
| 361 | 			g->avail_mask = mask-first; | ||
| 362 | 		else if (a_cas(&g->avail_mask, mask, mask-first)!=mask) | ||
| 363 | 			continue; | ||
| 364 | 		idx = a_ctz_32(first); | ||
| 365 | 		goto success; | ||
| 366 | 	} | ||
| 367 | 	upgradelock(); | ||
| 368 | |||
| 369 | 	idx = alloc_slot(sc, n); | ||
| 370 | 	if (idx < 0) { | ||
| 371 | 		unlock(); | ||
| 372 | 		return 0; | ||
| 373 | 	} | ||
| 374 | 	g = ctx.active[sc]; | ||
| 375 | |||
| 376 | success: | ||
| 377 | 	ctr = ctx.mmap_counter; | ||
| 378 | 	unlock(); | ||
| 379 | 	return enframe(g, idx, n, ctr); | ||
| 380 | } | ||
| 381 | |||
| 382 | int is_allzero(void *p) | ||
| 383 | { | ||
| 384 | 	struct meta *g = get_meta(p); | ||
| 385 | 	return g->sizeclass >= 48 || | ||
| 386 | 		get_stride(g) < UNIT*size_classes[g->sizeclass]; | ||
| 387 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/malloc_usable_size.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include "meta.h" | ||
| 3 | |||
| 4 | size_t malloc_usable_size(void *p) | ||
| 5 | { | ||
| 6 | 	if (!p) return 0; | ||
| 7 | 	struct meta *g = get_meta(p); | ||
| 8 | 	int idx = get_slot_index(p); | ||
| 9 | 	size_t stride = get_stride(g); | ||
| 10 | 	unsigned char *start = g->mem->storage + stride*idx; | ||
| 11 | 	unsigned char *end = start + stride - IB; | ||
| 12 | 	return get_nominal_size(p, end); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/meta.h created+288| ... | @@ -0,0 +1,288 @@ | ||
| 1 | #ifndef MALLOC_META_H | ||
| 2 | #define MALLOC_META_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <limits.h> | ||
| 7 | #include "glue.h" | ||
| 8 | |||
| 9 | __attribute__((__visibility__("hidden"))) | ||
| 10 | extern const uint16_t size_classes[]; | ||
| 11 | |||
| 12 | #define MMAP_THRESHOLD 131052 | ||
| 13 | |||
| 14 | #define UNIT 16 | ||
| 15 | #define IB 4 | ||
| 16 | |||
| 17 | struct group { | ||
| 18 | 	struct meta *meta; | ||
| 19 | 	unsigned char active_idx:5; | ||
| 20 | 	char pad[UNIT - sizeof(struct meta *) - 1]; | ||
| 21 | 	unsigned char storage[]; | ||
| 22 | }; | ||
| 23 | |||
| 24 | struct meta { | ||
| 25 | 	struct meta *prev, *next; | ||
| 26 | 	struct group *mem; | ||
| 27 | 	volatile int avail_mask, freed_mask; | ||
| 28 | 	uintptr_t last_idx:5; | ||
| 29 | 	uintptr_t freeable:1; | ||
| 30 | 	uintptr_t sizeclass:6; | ||
| 31 | 	uintptr_t maplen:8*sizeof(uintptr_t)-12; | ||
| 32 | }; | ||
| 33 | |||
| 34 | struct meta_area { | ||
| 35 | 	uint64_t check; | ||
| 36 | 	struct meta_area *next; | ||
| 37 | 	int nslots; | ||
| 38 | 	struct meta slots[]; | ||
| 39 | }; | ||
| 40 | |||
| 41 | struct malloc_context { | ||
| 42 | 	uint64_t secret; | ||
| 43 | #ifndef PAGESIZE | ||
| 44 | 	size_t pagesize; | ||
| 45 | #endif | ||
| 46 | 	int init_done; | ||
| 47 | 	unsigned mmap_counter; | ||
| 48 | 	struct meta *free_meta_head; | ||
| 49 | 	struct meta *avail_meta; | ||
| 50 | 	size_t avail_meta_count, avail_meta_area_count, meta_alloc_shift; | ||
| 51 | 	struct meta_area *meta_area_head, *meta_area_tail; | ||
| 52 | 	unsigned char *avail_meta_areas; | ||
| 53 | 	struct meta *active[48]; | ||
| 54 | 	size_t usage_by_class[48]; | ||
| 55 | 	uint8_t unmap_seq[32], bounces[32]; | ||
| 56 | 	uint8_t seq; | ||
| 57 | 	uintptr_t brk; | ||
| 58 | }; | ||
| 59 | |||
| 60 | __attribute__((__visibility__("hidden"))) | ||
| 61 | extern struct malloc_context ctx; | ||
| 62 | |||
| 63 | #ifdef PAGESIZE | ||
| 64 | #define PGSZ PAGESIZE | ||
| 65 | #else | ||
| 66 | #define PGSZ ctx.pagesize | ||
| 67 | #endif | ||
| 68 | |||
| 69 | __attribute__((__visibility__("hidden"))) | ||
| 70 | struct meta *alloc_meta(void); | ||
| 71 | |||
| 72 | __attribute__((__visibility__("hidden"))) | ||
| 73 | int is_allzero(void *); | ||
| 74 | |||
| 75 | static inline void queue(struct meta **phead, struct meta *m) | ||
| 76 | { | ||
| 77 | 	assert(!m->next); | ||
| 78 | 	assert(!m->prev); | ||
| 79 | 	if (*phead) { | ||
| 80 | 		struct meta *head = *phead; | ||
| 81 | 		m->next = head; | ||
| 82 | 		m->prev = head->prev; | ||
| 83 | 		m->next->prev = m->prev->next = m; | ||
| 84 | 	} else { | ||
| 85 | 		m->prev = m->next = m; | ||
| 86 | 		*phead = m; | ||
| 87 | 	} | ||
| 88 | } | ||
| 89 | |||
| 90 | static inline void dequeue(struct meta **phead, struct meta *m) | ||
| 91 | { | ||
| 92 | 	if (m->next != m) { | ||
| 93 | 		m->prev->next = m->next; | ||
| 94 | 		m->next->prev = m->prev; | ||
| 95 | 		if (*phead == m) *phead = m->next; | ||
| 96 | 	} else { | ||
| 97 | 		*phead = 0; | ||
| 98 | 	} | ||
| 99 | 	m->prev = m->next = 0; | ||
| 100 | } | ||
| 101 | |||
| 102 | static inline struct meta *dequeue_head(struct meta **phead) | ||
| 103 | { | ||
| 104 | 	struct meta *m = *phead; | ||
| 105 | 	if (m) dequeue(phead, m); | ||
| 106 | 	return m; | ||
| 107 | } | ||
| 108 | |||
| 109 | static inline void free_meta(struct meta *m) | ||
| 110 | { | ||
| 111 | 	*m = (struct meta){0}; | ||
| 112 | 	queue(&ctx.free_meta_head, m); | ||
| 113 | } | ||
| 114 | |||
| 115 | static inline uint32_t activate_group(struct meta *m) | ||
| 116 | { | ||
| 117 | 	assert(!m->avail_mask); | ||
| 118 | 	uint32_t mask, act = (2u<<m->mem->active_idx)-1; | ||
| 119 | 	do mask = m->freed_mask; | ||
| 120 | 	while (a_cas(&m->freed_mask, mask, mask&~act)!=mask); | ||
| 121 | 	return m->avail_mask = mask & act; | ||
| 122 | } | ||
| 123 | |||
| 124 | static inline int get_slot_index(const unsigned char *p) | ||
| 125 | { | ||
| 126 | 	return p[-3] & 31; | ||
| 127 | } | ||
| 128 | |||
| 129 | static inline struct meta *get_meta(const unsigned char *p) | ||
| 130 | { | ||
| 131 | 	assert(!((uintptr_t)p & 15)); | ||
| 132 | 	int offset = *(const uint16_t *)(p - 2); | ||
| 133 | 	int index = get_slot_index(p); | ||
| 134 | 	if (p[-4]) { | ||
| 135 | 		assert(!offset); | ||
| 136 | 		offset = *(uint32_t *)(p - 8); | ||
| 137 | 		assert(offset > 0xffff); | ||
| 138 | 	} | ||
| 139 | 	const struct group *base = (const void *)(p - UNIT*offset - UNIT); | ||
| 140 | 	const struct meta *meta = base->meta; | ||
| 141 | 	assert(meta->mem == base); | ||
| 142 | 	assert(index <= meta->last_idx); | ||
| 143 | 	assert(!(meta->avail_mask & (1u<<index))); | ||
| 144 | 	assert(!(meta->freed_mask & (1u<<index))); | ||
| 145 | 	const struct meta_area *area = (void *)((uintptr_t)meta & -4096); | ||
| 146 | 	assert(area->check == ctx.secret); | ||
| 147 | 	if (meta->sizeclass < 48) { | ||
| 148 | 		assert(offset >= size_classes[meta->sizeclass]*index); | ||
| 149 | 		assert(offset < size_classes[meta->sizeclass]*(index+1)); | ||
| 150 | 	} else { | ||
| 151 | 		assert(meta->sizeclass == 63); | ||
| 152 | 	} | ||
| 153 | 	if (meta->maplen) { | ||
| 154 | 		assert(offset <= meta->maplen*4096UL/UNIT - 1); | ||
| 155 | 	} | ||
| 156 | 	return (struct meta *)meta; | ||
| 157 | } | ||
| 158 | |||
| 159 | static inline size_t get_nominal_size(const unsigned char *p, const unsigned char *end) | ||
| 160 | { | ||
| 161 | 	size_t reserved = p[-3] >> 5; | ||
| 162 | 	if (reserved >= 5) { | ||
| 163 | 		assert(reserved == 5); | ||
| 164 | 		reserved = *(const uint32_t *)(end-4); | ||
| 165 | 		assert(reserved >= 5); | ||
| 166 | 		assert(!end[-5]); | ||
| 167 | 	} | ||
| 168 | 	assert(reserved <= end-p); | ||
| 169 | 	assert(!*(end-reserved)); | ||
| 170 | 	// also check the slot's overflow byte | ||
| 171 | 	assert(!*end); | ||
| 172 | 	return end-reserved-p; | ||
| 173 | } | ||
| 174 | |||
| 175 | static inline size_t get_stride(const struct meta *g) | ||
| 176 | { | ||
| 177 | 	if (!g->last_idx && g->maplen) { | ||
| 178 | 		return g->maplen*4096UL - UNIT; | ||
| 179 | 	} else { | ||
| 180 | 		return UNIT*size_classes[g->sizeclass]; | ||
| 181 | 	} | ||
| 182 | } | ||
| 183 | |||
| 184 | static inline void set_size(unsigned char *p, unsigned char *end, size_t n) | ||
| 185 | { | ||
| 186 | 	int reserved = end-p-n; | ||
| 187 | 	if (reserved) end[-reserved] = 0; | ||
| 188 | 	if (reserved >= 5) { | ||
| 189 | 		*(uint32_t *)(end-4) = reserved; | ||
| 190 | 		end[-5] = 0; | ||
| 191 | 		reserved = 5; | ||
| 192 | 	} | ||
| 193 | 	p[-3] = (p[-3]&31) + (reserved<<5); | ||
| 194 | } | ||
| 195 | |||
| 196 | static inline void *enframe(struct meta *g, int idx, size_t n, int ctr) | ||
| 197 | { | ||
| 198 | 	size_t stride = get_stride(g); | ||
| 199 | 	size_t slack = (stride-IB-n)/UNIT; | ||
| 200 | 	unsigned char *p = g->mem->storage + stride*idx; | ||
| 201 | 	unsigned char *end = p+stride-IB; | ||
| 202 | 	// cycle offset within slot to increase interval to address | ||
| 203 | 	// reuse, facilitate trapping double-free. | ||
| 204 | 	int off = (p[-3] ? *(uint16_t *)(p-2) + 1 : ctr) & 255; | ||
| 205 | 	assert(!p[-4]); | ||
| 206 | 	if (off > slack) { | ||
| 207 | 		size_t m = slack; | ||
| 208 | 		m |= m>>1; m |= m>>2; m |= m>>4; | ||
| 209 | 		off &= m; | ||
| 210 | 		if (off > slack) off -= slack+1; | ||
| 211 | 		assert(off <= slack); | ||
| 212 | 	} | ||
| 213 | 	if (off) { | ||
| 214 | 		// store offset in unused header at offset zero | ||
| 215 | 		// if enframing at non-zero offset. | ||
| 216 | 		*(uint16_t *)(p-2) = off; | ||
| 217 | 		p[-3] = 7<<5; | ||
| 218 | 		p += UNIT*off; | ||
| 219 | 		// for nonzero offset there is no permanent check | ||
| 220 | 		// byte, so make one. | ||
| 221 | 		p[-4] = 0; | ||
| 222 | 	} | ||
| 223 | 	*(uint16_t *)(p-2) = (size_t)(p-g->mem->storage)/UNIT; | ||
| 224 | 	p[-3] = idx; | ||
| 225 | 	set_size(p, end, n); | ||
| 226 | 	return p; | ||
| 227 | } | ||
| 228 | |||
| 229 | static inline int size_to_class(size_t n) | ||
| 230 | { | ||
| 231 | 	n = (n+IB-1)>>4; | ||
| 232 | 	if (n<10) return n; | ||
| 233 | 	n++; | ||
| 234 | 	int i = (28-a_clz_32(n))*4 + 8; | ||
| 235 | 	if (n>size_classes[i+1]) i+=2; | ||
| 236 | 	if (n>size_classes[i]) i++; | ||
| 237 | 	return i; | ||
| 238 | } | ||
| 239 | |||
| 240 | static inline int size_overflows(size_t n) | ||
| 241 | { | ||
| 242 | 	if (n >= SIZE_MAX/2 - 4096) { | ||
| 243 | 		errno = ENOMEM; | ||
| 244 | 		return 1; | ||
| 245 | 	} | ||
| 246 | 	return 0; | ||
| 247 | } | ||
| 248 | |||
| 249 | static inline void step_seq(void) | ||
| 250 | { | ||
| 251 | 	if (ctx.seq==255) { | ||
| 252 | 		for (int i=0; i<32; i++) ctx.unmap_seq[i] = 0; | ||
| 253 | 		ctx.seq = 1; | ||
| 254 | 	} else { | ||
| 255 | 		ctx.seq++; | ||
| 256 | 	} | ||
| 257 | } | ||
| 258 | |||
| 259 | static inline void record_seq(int sc) | ||
| 260 | { | ||
| 261 | 	if (sc-7U < 32) ctx.unmap_seq[sc-7] = ctx.seq; | ||
| 262 | } | ||
| 263 | |||
| 264 | static inline void account_bounce(int sc) | ||
| 265 | { | ||
| 266 | 	if (sc-7U < 32) { | ||
| 267 | 		int seq = ctx.unmap_seq[sc-7]; | ||
| 268 | 		if (seq && ctx.seq-seq < 10) { | ||
| 269 | 			if (ctx.bounces[sc-7]+1 < 100) | ||
| 270 | 				ctx.bounces[sc-7]++; | ||
| 271 | 			else | ||
| 272 | 				ctx.bounces[sc-7] = 150; | ||
| 273 | 		} | ||
| 274 | 	} | ||
| 275 | } | ||
| 276 | |||
| 277 | static inline void decay_bounces(int sc) | ||
| 278 | { | ||
| 279 | 	if (sc-7U < 32 && ctx.bounces[sc-7]) | ||
| 280 | 		ctx.bounces[sc-7]--; | ||
| 281 | } | ||
| 282 | |||
| 283 | static inline int is_bouncing(int sc) | ||
| 284 | { | ||
| 285 | 	return (sc-7U < 32 && ctx.bounces[sc-7] >= 100); | ||
| 286 | } | ||
| 287 | |||
| 288 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/realloc.c created+51| ... | @@ -0,0 +1,51 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <sys/mman.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include "meta.h" | ||
| 6 | |||
| 7 | void *realloc(void *p, size_t n) | ||
| 8 | { | ||
| 9 | 	if (!p) return malloc(n); | ||
| 10 | 	if (size_overflows(n)) return 0; | ||
| 11 | |||
| 12 | 	struct meta *g = get_meta(p); | ||
| 13 | 	int idx = get_slot_index(p); | ||
| 14 | 	size_t stride = get_stride(g); | ||
| 15 | 	unsigned char *start = g->mem->storage + stride*idx; | ||
| 16 | 	unsigned char *end = start + stride - IB; | ||
| 17 | 	size_t old_size = get_nominal_size(p, end); | ||
| 18 | 	size_t avail_size = end-(unsigned char *)p; | ||
| 19 | 	void *new; | ||
| 20 | |||
| 21 | 	// only resize in-place if size class matches | ||
| 22 | 	if (n <= avail_size && n<MMAP_THRESHOLD | ||
| 23 | 	 && size_to_class(n)+1 >= g->sizeclass) { | ||
| 24 | 		set_size(p, end, n); | ||
| 25 | 		return p; | ||
| 26 | 	} | ||
| 27 | |||
| 28 | 	// use mremap if old and new size are both mmap-worthy | ||
| 29 | 	if (g->sizeclass>=48 && n>=MMAP_THRESHOLD) { | ||
| 30 | 		assert(g->sizeclass==63); | ||
| 31 | 		size_t base = (unsigned char *)p-start; | ||
| 32 | 		size_t needed = (n + base + UNIT + IB + 4095) & -4096; | ||
| 33 | 		new = g->maplen*4096UL == needed ? g->mem : | ||
| 34 | 			mremap(g->mem, g->maplen*4096UL, needed, MREMAP_MAYMOVE); | ||
| 35 | 		if (new!=MAP_FAILED) { | ||
| 36 | 			g->mem = new; | ||
| 37 | 			g->maplen = needed/4096; | ||
| 38 | 			p = g->mem->storage + base; | ||
| 39 | 			end = g->mem->storage + (needed - UNIT) - IB; | ||
| 40 | 			*end = 0; | ||
| 41 | 			set_size(p, end, n); | ||
| 42 | 			return p; | ||
| 43 | 		} | ||
| 44 | 	} | ||
| 45 | |||
| 46 | 	new = malloc(n); | ||
| 47 | 	if (!new) return 0; | ||
| 48 | 	memcpy(new, p, n < old_size ? n : old_size); | ||
| 49 | 	free(p); | ||
| 50 | 	return new; | ||
| 51 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/memalign.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | void *memalign(size_t align, size_t len) | ||
| 5 | { | ||
| 6 | 	return aligned_alloc(align, len); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/aligned_alloc.c created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "malloc_impl.h" | ||
| 5 | |||
| 6 | void *aligned_alloc(size_t align, size_t len) | ||
| 7 | { | ||
| 8 | 	unsigned char *mem, *new; | ||
| 9 | |||
| 10 | 	if ((align & -align) != align) { | ||
| 11 | 		errno = EINVAL; | ||
| 12 | 		return 0; | ||
| 13 | 	} | ||
| 14 | |||
| 15 | 	if (len > SIZE_MAX - align || | ||
| 16 | 	 (__malloc_replaced && !__aligned_alloc_replaced)) { | ||
| 17 | 		errno = ENOMEM; | ||
| 18 | 		return 0; | ||
| 19 | 	} | ||
| 20 | |||
| 21 | 	if (align <= SIZE_ALIGN) | ||
| 22 | 		return malloc(len); | ||
| 23 | |||
| 24 | 	if (!(mem = malloc(len + align-1))) | ||
| 25 | 		return 0; | ||
| 26 | |||
| 27 | 	new = (void *)((uintptr_t)mem + align-1 & -align); | ||
| 28 | 	if (new == mem) return mem; | ||
| 29 | |||
| 30 | 	struct chunk *c = MEM_TO_CHUNK(mem); | ||
| 31 | 	struct chunk *n = MEM_TO_CHUNK(new); | ||
| 32 | |||
| 33 | 	if (IS_MMAPPED(c)) { | ||
| 34 | 		/* Apply difference between aligned and original | ||
| 35 | 		 * address to the "extra" field of mmapped chunk. */ | ||
| 36 | 		n->psize = c->psize + (new-mem); | ||
| 37 | 		n->csize = c->csize - (new-mem); | ||
| 38 | 		return new; | ||
| 39 | 	} | ||
| 40 | |||
| 41 | 	struct chunk *t = NEXT_CHUNK(c); | ||
| 42 | |||
| 43 | 	/* Split the allocated chunk into two chunks. The aligned part | ||
| 44 | 	 * that will be used has the size in its footer reduced by the | ||
| 45 | 	 * difference between the aligned and original addresses, and | ||
| 46 | 	 * the resulting size copied to its header. A new header and | ||
| 47 | 	 * footer are written for the split-off part to be freed. */ | ||
| 48 | 	n->psize = c->csize = C_INUSE | (new-mem); | ||
| 49 | 	n->csize = t->psize -= new-mem; | ||
| 50 | |||
| 51 | 	__bin_chunk(c); | ||
| 52 | 	return new; | ||
| 53 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc.c created+552| ... | @@ -0,0 +1,552 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <sys/mman.h> | ||
| 8 | #include "libc.h" | ||
| 9 | #include "atomic.h" | ||
| 10 | #include "pthread_impl.h" | ||
| 11 | #include "malloc_impl.h" | ||
| 12 | #include "fork_impl.h" | ||
| 13 | |||
| 14 | #define malloc __libc_malloc | ||
| 15 | #define realloc __libc_realloc | ||
| 16 | #define free __libc_free | ||
| 17 | |||
| 18 | #if defined(__GNUC__) && defined(__PIC__) | ||
| 19 | #define inline inline __attribute__((always_inline)) | ||
| 20 | #endif | ||
| 21 | |||
| 22 | static struct { | ||
| 23 | 	volatile uint64_t binmap; | ||
| 24 | 	struct bin bins[64]; | ||
| 25 | 	volatile int split_merge_lock[2]; | ||
| 26 | } mal; | ||
| 27 | |||
| 28 | /* Synchronization tools */ | ||
| 29 | |||
| 30 | static inline void lock(volatile int *lk) | ||
| 31 | { | ||
| 32 | 	int need_locks = libc.need_locks; | ||
| 33 | 	if (need_locks) { | ||
| 34 | 		while(a_swap(lk, 1)) __wait(lk, lk+1, 1, 1); | ||
| 35 | 		if (need_locks < 0) libc.need_locks = 0; | ||
| 36 | 	} | ||
| 37 | } | ||
| 38 | |||
| 39 | static inline void unlock(volatile int *lk) | ||
| 40 | { | ||
| 41 | 	if (lk[0]) { | ||
| 42 | 		a_store(lk, 0); | ||
| 43 | 		if (lk[1]) __wake(lk, 1, 1); | ||
| 44 | 	} | ||
| 45 | } | ||
| 46 | |||
| 47 | static inline void lock_bin(int i) | ||
| 48 | { | ||
| 49 | 	lock(mal.bins[i].lock); | ||
| 50 | 	if (!mal.bins[i].head) | ||
| 51 | 		mal.bins[i].head = mal.bins[i].tail = BIN_TO_CHUNK(i); | ||
| 52 | } | ||
| 53 | |||
| 54 | static inline void unlock_bin(int i) | ||
| 55 | { | ||
| 56 | 	unlock(mal.bins[i].lock); | ||
| 57 | } | ||
| 58 | |||
| 59 | static int first_set(uint64_t x) | ||
| 60 | { | ||
| 61 | #if 1 | ||
| 62 | 	return a_ctz_64(x); | ||
| 63 | #else | ||
| 64 | 	static const char debruijn64[64] = { | ||
| 65 | 		0, 1, 2, 53, 3, 7, 54, 27, 4, 38, 41, 8, 34, 55, 48, 28, | ||
| 66 | 		62, 5, 39, 46, 44, 42, 22, 9, 24, 35, 59, 56, 49, 18, 29, 11, | ||
| 67 | 		63, 52, 6, 26, 37, 40, 33, 47, 61, 45, 43, 21, 23, 58, 17, 10, | ||
| 68 | 		51, 25, 36, 32, 60, 20, 57, 16, 50, 31, 19, 15, 30, 14, 13, 12 | ||
| 69 | 	}; | ||
| 70 | 	static const char debruijn32[32] = { | ||
| 71 | 		0, 1, 23, 2, 29, 24, 19, 3, 30, 27, 25, 11, 20, 8, 4, 13, | ||
| 72 | 		31, 22, 28, 18, 26, 10, 7, 12, 21, 17, 9, 6, 16, 5, 15, 14 | ||
| 73 | 	}; | ||
| 74 | 	if (sizeof(long) < 8) { | ||
| 75 | 		uint32_t y = x; | ||
| 76 | 		if (!y) { | ||
| 77 | 			y = x>>32; | ||
| 78 | 			return 32 + debruijn32[(y&-y)*0x076be629 >> 27]; | ||
| 79 | 		} | ||
| 80 | 		return debruijn32[(y&-y)*0x076be629 >> 27]; | ||
| 81 | 	} | ||
| 82 | 	return debruijn64[(x&-x)*0x022fdd63cc95386dull >> 58]; | ||
| 83 | #endif | ||
| 84 | } | ||
| 85 | |||
| 86 | static const unsigned char bin_tab[60] = { | ||
| 87 | 	 32,33,34,35,36,36,37,37,38,38,39,39, | ||
| 88 | 	40,40,40,40,41,41,41,41,42,42,42,42,43,43,43,43, | ||
| 89 | 	44,44,44,44,44,44,44,44,45,45,45,45,45,45,45,45, | ||
| 90 | 	46,46,46,46,46,46,46,46,47,47,47,47,47,47,47,47, | ||
| 91 | }; | ||
| 92 | |||
| 93 | static int bin_index(size_t x) | ||
| 94 | { | ||
| 95 | 	x = x / SIZE_ALIGN - 1; | ||
| 96 | 	if (x <= 32) return x; | ||
| 97 | 	if (x < 512) return bin_tab[x/8-4]; | ||
| 98 | 	if (x > 0x1c00) return 63; | ||
| 99 | 	return bin_tab[x/128-4] + 16; | ||
| 100 | } | ||
| 101 | |||
| 102 | static int bin_index_up(size_t x) | ||
| 103 | { | ||
| 104 | 	x = x / SIZE_ALIGN - 1; | ||
| 105 | 	if (x <= 32) return x; | ||
| 106 | 	x--; | ||
| 107 | 	if (x < 512) return bin_tab[x/8-4] + 1; | ||
| 108 | 	return bin_tab[x/128-4] + 17; | ||
| 109 | } | ||
| 110 | |||
| 111 | #if 0 | ||
| 112 | void __dump_heap(int x) | ||
| 113 | { | ||
| 114 | 	struct chunk *c; | ||
| 115 | 	int i; | ||
| 116 | 	for (c = (void *)mal.heap; CHUNK_SIZE(c); c = NEXT_CHUNK(c)) | ||
| 117 | 		fprintf(stderr, "base %p size %zu (%d) flags %d/%d\n", | ||
| 118 | 			c, CHUNK_SIZE(c), bin_index(CHUNK_SIZE(c)), | ||
| 119 | 			c->csize & 15, | ||
| 120 | 			NEXT_CHUNK(c)->psize & 15); | ||
| 121 | 	for (i=0; i<64; i++) { | ||
| 122 | 		if (mal.bins[i].head != BIN_TO_CHUNK(i) && mal.bins[i].head) { | ||
| 123 | 			fprintf(stderr, "bin %d: %p\n", i, mal.bins[i].head); | ||
| 124 | 			if (!(mal.binmap & 1ULL<<i)) | ||
| 125 | 				fprintf(stderr, "missing from binmap!\n"); | ||
| 126 | 		} else if (mal.binmap & 1ULL<<i) | ||
| 127 | 			fprintf(stderr, "binmap wrongly contains %d!\n", i); | ||
| 128 | 	} | ||
| 129 | } | ||
| 130 | #endif | ||
| 131 | |||
| 132 | /* This function returns true if the interval [old,new] | ||
| 133 | * intersects the 'len'-sized interval below &libc.auxv | ||
| 134 | * (interpreted as the main-thread stack) or below &b | ||
| 135 | * (the current stack). It is used to defend against | ||
| 136 | * buggy brk implementations that can cross the stack. */ | ||
| 137 | |||
| 138 | static int traverses_stack_p(uintptr_t old, uintptr_t new) | ||
| 139 | { | ||
| 140 | 	const uintptr_t len = 8<<20; | ||
| 141 | 	uintptr_t a, b; | ||
| 142 | |||
| 143 | 	b = (uintptr_t)libc.auxv; | ||
| 144 | 	a = b > len ? b-len : 0; | ||
| 145 | 	if (new>a && old<b) return 1; | ||
| 146 | |||
| 147 | 	b = (uintptr_t)&b; | ||
| 148 | 	a = b > len ? b-len : 0; | ||
| 149 | 	if (new>a && old<b) return 1; | ||
| 150 | |||
| 151 | 	return 0; | ||
| 152 | } | ||
| 153 | |||
| 154 | /* Expand the heap in-place if brk can be used, or otherwise via mmap, | ||
| 155 | * using an exponential lower bound on growth by mmap to make | ||
| 156 | * fragmentation asymptotically irrelevant. The size argument is both | ||
| 157 | * an input and an output, since the caller needs to know the size | ||
| 158 | * allocated, which will be larger than requested due to page alignment | ||
| 159 | * and mmap minimum size rules. The caller is responsible for locking | ||
| 160 | * to prevent concurrent calls. */ | ||
| 161 | |||
| 162 | static void *__expand_heap(size_t *pn) | ||
| 163 | { | ||
| 164 | 	static uintptr_t brk; | ||
| 165 | 	static unsigned mmap_step; | ||
| 166 | 	size_t n = *pn; | ||
| 167 | |||
| 168 | 	if (n > SIZE_MAX/2 - PAGE_SIZE) { | ||
| 169 | 		errno = ENOMEM; | ||
| 170 | 		return 0; | ||
| 171 | 	} | ||
| 172 | 	n += -n & PAGE_SIZE-1; | ||
| 173 | |||
| 174 | 	if (!brk) { | ||
| 175 | 		brk = __syscall(SYS_brk, 0); | ||
| 176 | 		brk += -brk & PAGE_SIZE-1; | ||
| 177 | 	} | ||
| 178 | |||
| 179 | 	if (n < SIZE_MAX-brk && !traverses_stack_p(brk, brk+n) | ||
| 180 | 	 && __syscall(SYS_brk, brk+n)==brk+n) { | ||
| 181 | 		*pn = n; | ||
| 182 | 		brk += n; | ||
| 183 | 		return (void *)(brk-n); | ||
| 184 | 	} | ||
| 185 | |||
| 186 | 	size_t min = (size_t)PAGE_SIZE << mmap_step/2; | ||
| 187 | 	if (n < min) n = min; | ||
| 188 | 	void *area = __mmap(0, n, PROT_READ|PROT_WRITE, | ||
| 189 | 		MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | ||
| 190 | 	if (area == MAP_FAILED) return 0; | ||
| 191 | 	*pn = n; | ||
| 192 | 	mmap_step++; | ||
| 193 | 	return area; | ||
| 194 | } | ||
| 195 | |||
| 196 | static struct chunk *expand_heap(size_t n) | ||
| 197 | { | ||
| 198 | 	static void *end; | ||
| 199 | 	void *p; | ||
| 200 | 	struct chunk *w; | ||
| 201 | |||
| 202 | 	/* The argument n already accounts for the caller's chunk | ||
| 203 | 	 * overhead needs, but if the heap can't be extended in-place, | ||
| 204 | 	 * we need room for an extra zero-sized sentinel chunk. */ | ||
| 205 | 	n += SIZE_ALIGN; | ||
| 206 | |||
| 207 | 	p = __expand_heap(&n); | ||
| 208 | 	if (!p) return 0; | ||
| 209 | |||
| 210 | 	/* If not just expanding existing space, we need to make a | ||
| 211 | 	 * new sentinel chunk below the allocated space. */ | ||
| 212 | 	if (p != end) { | ||
| 213 | 		/* Valid/safe because of the prologue increment. */ | ||
| 214 | 		n -= SIZE_ALIGN; | ||
| 215 | 		p = (char *)p + SIZE_ALIGN; | ||
| 216 | 		w = MEM_TO_CHUNK(p); | ||
| 217 | 		w->psize = 0 | C_INUSE; | ||
| 218 | 	} | ||
| 219 | |||
| 220 | 	/* Record new heap end and fill in footer. */ | ||
| 221 | 	end = (char *)p + n; | ||
| 222 | 	w = MEM_TO_CHUNK(end); | ||
| 223 | 	w->psize = n | C_INUSE; | ||
| 224 | 	w->csize = 0 | C_INUSE; | ||
| 225 | |||
| 226 | 	/* Fill in header, which may be new or may be replacing a | ||
| 227 | 	 * zero-size sentinel header at the old end-of-heap. */ | ||
| 228 | 	w = MEM_TO_CHUNK(p); | ||
| 229 | 	w->csize = n | C_INUSE; | ||
| 230 | |||
| 231 | 	return w; | ||
| 232 | } | ||
| 233 | |||
| 234 | static int adjust_size(size_t *n) | ||
| 235 | { | ||
| 236 | 	/* Result of pointer difference must fit in ptrdiff_t. */ | ||
| 237 | 	if (*n-1 > PTRDIFF_MAX - SIZE_ALIGN - PAGE_SIZE) { | ||
| 238 | 		if (*n) { | ||
| 239 | 			errno = ENOMEM; | ||
| 240 | 			return -1; | ||
| 241 | 		} else { | ||
| 242 | 			*n = SIZE_ALIGN; | ||
| 243 | 			return 0; | ||
| 244 | 		} | ||
| 245 | 	} | ||
| 246 | 	*n = (*n + OVERHEAD + SIZE_ALIGN - 1) & SIZE_MASK; | ||
| 247 | 	return 0; | ||
| 248 | } | ||
| 249 | |||
| 250 | static void unbin(struct chunk *c, int i) | ||
| 251 | { | ||
| 252 | 	if (c->prev == c->next) | ||
| 253 | 		a_and_64(&mal.binmap, ~(1ULL<<i)); | ||
| 254 | 	c->prev->next = c->next; | ||
| 255 | 	c->next->prev = c->prev; | ||
| 256 | 	c->csize |= C_INUSE; | ||
| 257 | 	NEXT_CHUNK(c)->psize |= C_INUSE; | ||
| 258 | } | ||
| 259 | |||
| 260 | static void bin_chunk(struct chunk *self, int i) | ||
| 261 | { | ||
| 262 | 	self->next = BIN_TO_CHUNK(i); | ||
| 263 | 	self->prev = mal.bins[i].tail; | ||
| 264 | 	self->next->prev = self; | ||
| 265 | 	self->prev->next = self; | ||
| 266 | 	if (self->prev == BIN_TO_CHUNK(i)) | ||
| 267 | 		a_or_64(&mal.binmap, 1ULL<<i); | ||
| 268 | } | ||
| 269 | |||
| 270 | static void trim(struct chunk *self, size_t n) | ||
| 271 | { | ||
| 272 | 	size_t n1 = CHUNK_SIZE(self); | ||
| 273 | 	struct chunk *next, *split; | ||
| 274 | |||
| 275 | 	if (n >= n1 - DONTCARE) return; | ||
| 276 | |||
| 277 | 	next = NEXT_CHUNK(self); | ||
| 278 | 	split = (void *)((char *)self + n); | ||
| 279 | |||
| 280 | 	split->psize = n | C_INUSE; | ||
| 281 | 	split->csize = n1-n; | ||
| 282 | 	next->psize = n1-n; | ||
| 283 | 	self->csize = n | C_INUSE; | ||
| 284 | |||
| 285 | 	int i = bin_index(n1-n); | ||
| 286 | 	lock_bin(i); | ||
| 287 | |||
| 288 | 	bin_chunk(split, i); | ||
| 289 | |||
| 290 | 	unlock_bin(i); | ||
| 291 | } | ||
| 292 | |||
| 293 | void *malloc(size_t n) | ||
| 294 | { | ||
| 295 | 	struct chunk *c; | ||
| 296 | 	int i, j; | ||
| 297 | 	uint64_t mask; | ||
| 298 | |||
| 299 | 	if (adjust_size(&n) < 0) return 0; | ||
| 300 | |||
| 301 | 	if (n > MMAP_THRESHOLD) { | ||
| 302 | 		size_t len = n + OVERHEAD + PAGE_SIZE - 1 & -PAGE_SIZE; | ||
| 303 | 		char *base = __mmap(0, len, PROT_READ|PROT_WRITE, | ||
| 304 | 			MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); | ||
| 305 | 		if (base == (void *)-1) return 0; | ||
| 306 | 		c = (void *)(base + SIZE_ALIGN - OVERHEAD); | ||
| 307 | 		c->csize = len - (SIZE_ALIGN - OVERHEAD); | ||
| 308 | 		c->psize = SIZE_ALIGN - OVERHEAD; | ||
| 309 | 		return CHUNK_TO_MEM(c); | ||
| 310 | 	} | ||
| 311 | |||
| 312 | 	i = bin_index_up(n); | ||
| 313 | 	if (i<63 && (mal.binmap & (1ULL<<i))) { | ||
| 314 | 		lock_bin(i); | ||
| 315 | 		c = mal.bins[i].head; | ||
| 316 | 		if (c != BIN_TO_CHUNK(i) && CHUNK_SIZE(c)-n <= DONTCARE) { | ||
| 317 | 			unbin(c, i); | ||
| 318 | 			unlock_bin(i); | ||
| 319 | 			return CHUNK_TO_MEM(c); | ||
| 320 | 		} | ||
| 321 | 		unlock_bin(i); | ||
| 322 | 	} | ||
| 323 | 	lock(mal.split_merge_lock); | ||
| 324 | 	for (mask = mal.binmap & -(1ULL<<i); mask; mask -= (mask&-mask)) { | ||
| 325 | 		j = first_set(mask); | ||
| 326 | 		lock_bin(j); | ||
| 327 | 		c = mal.bins[j].head; | ||
| 328 | 		if (c != BIN_TO_CHUNK(j)) { | ||
| 329 | 			unbin(c, j); | ||
| 330 | 			unlock_bin(j); | ||
| 331 | 			break; | ||
| 332 | 		} | ||
| 333 | 		unlock_bin(j); | ||
| 334 | 	} | ||
| 335 | 	if (!mask) { | ||
| 336 | 		c = expand_heap(n); | ||
| 337 | 		if (!c) { | ||
| 338 | 			unlock(mal.split_merge_lock); | ||
| 339 | 			return 0; | ||
| 340 | 		} | ||
| 341 | 	} | ||
| 342 | 	trim(c, n); | ||
| 343 | 	unlock(mal.split_merge_lock); | ||
| 344 | 	return CHUNK_TO_MEM(c); | ||
| 345 | } | ||
| 346 | |||
| 347 | int __malloc_allzerop(void *p) | ||
| 348 | { | ||
| 349 | 	return IS_MMAPPED(MEM_TO_CHUNK(p)); | ||
| 350 | } | ||
| 351 | |||
| 352 | void *realloc(void *p, size_t n) | ||
| 353 | { | ||
| 354 | 	struct chunk *self, *next; | ||
| 355 | 	size_t n0, n1; | ||
| 356 | 	void *new; | ||
| 357 | |||
| 358 | 	if (!p) return malloc(n); | ||
| 359 | |||
| 360 | 	if (adjust_size(&n) < 0) return 0; | ||
| 361 | |||
| 362 | 	self = MEM_TO_CHUNK(p); | ||
| 363 | 	n1 = n0 = CHUNK_SIZE(self); | ||
| 364 | |||
| 365 | 	if (n<=n0 && n0-n<=DONTCARE) return p; | ||
| 366 | |||
| 367 | 	if (IS_MMAPPED(self)) { | ||
| 368 | 		size_t extra = self->psize; | ||
| 369 | 		char *base = (char *)self - extra; | ||
| 370 | 		size_t oldlen = n0 + extra; | ||
| 371 | 		size_t newlen = n + extra; | ||
| 372 | 		/* Crash on realloc of freed chunk */ | ||
| 373 | 		if (extra & 1) a_crash(); | ||
| 374 | 		if (newlen < PAGE_SIZE && (new = malloc(n-OVERHEAD))) { | ||
| 375 | 			n0 = n; | ||
| 376 | 			goto copy_free_ret; | ||
| 377 | 		} | ||
| 378 | 		newlen = (newlen + PAGE_SIZE-1) & -PAGE_SIZE; | ||
| 379 | 		if (oldlen == newlen) return p; | ||
| 380 | 		base = __mremap(base, oldlen, newlen, MREMAP_MAYMOVE); | ||
| 381 | 		if (base == (void *)-1) | ||
| 382 | 			goto copy_realloc; | ||
| 383 | 		self = (void *)(base + extra); | ||
| 384 | 		self->csize = newlen - extra; | ||
| 385 | 		return CHUNK_TO_MEM(self); | ||
| 386 | 	} | ||
| 387 | |||
| 388 | 	next = NEXT_CHUNK(self); | ||
| 389 | |||
| 390 | 	/* Crash on corrupted footer (likely from buffer overflow) */ | ||
| 391 | 	if (next->psize != self->csize) a_crash(); | ||
| 392 | |||
| 393 | 	if (n < n0) { | ||
| 394 | 		int i = bin_index_up(n); | ||
| 395 | 		int j = bin_index(n0); | ||
| 396 | 		if (i<j && (mal.binmap & (1ULL << i))) | ||
| 397 | 			goto copy_realloc; | ||
| 398 | 		struct chunk *split = (void *)((char *)self + n); | ||
| 399 | 		self->csize = split->psize = n | C_INUSE; | ||
| 400 | 		split->csize = next->psize = n0-n | C_INUSE; | ||
| 401 | 		__bin_chunk(split); | ||
| 402 | 		return CHUNK_TO_MEM(self); | ||
| 403 | 	} | ||
| 404 | |||
| 405 | 	lock(mal.split_merge_lock); | ||
| 406 | |||
| 407 | 	size_t nsize = next->csize & C_INUSE ? 0 : CHUNK_SIZE(next); | ||
| 408 | 	if (n0+nsize >= n) { | ||
| 409 | 		int i = bin_index(nsize); | ||
| 410 | 		lock_bin(i); | ||
| 411 | 		if (!(next->csize & C_INUSE)) { | ||
| 412 | 			unbin(next, i); | ||
| 413 | 			unlock_bin(i); | ||
| 414 | 			next = NEXT_CHUNK(next); | ||
| 415 | 			self->csize = next->psize = n0+nsize | C_INUSE; | ||
| 416 | 			trim(self, n); | ||
| 417 | 			unlock(mal.split_merge_lock); | ||
| 418 | 			return CHUNK_TO_MEM(self); | ||
| 419 | 		} | ||
| 420 | 		unlock_bin(i); | ||
| 421 | 	} | ||
| 422 | 	unlock(mal.split_merge_lock); | ||
| 423 | |||
| 424 | copy_realloc: | ||
| 425 | 	/* As a last resort, allocate a new chunk and copy to it. */ | ||
| 426 | 	new = malloc(n-OVERHEAD); | ||
| 427 | 	if (!new) return 0; | ||
| 428 | copy_free_ret: | ||
| 429 | 	memcpy(new, p, (n<n0 ? n : n0) - OVERHEAD); | ||
| 430 | 	free(CHUNK_TO_MEM(self)); | ||
| 431 | 	return new; | ||
| 432 | } | ||
| 433 | |||
| 434 | void __bin_chunk(struct chunk *self) | ||
| 435 | { | ||
| 436 | 	struct chunk *next = NEXT_CHUNK(self); | ||
| 437 | |||
| 438 | 	/* Crash on corrupted footer (likely from buffer overflow) */ | ||
| 439 | 	if (next->psize != self->csize) a_crash(); | ||
| 440 | |||
| 441 | 	lock(mal.split_merge_lock); | ||
| 442 | |||
| 443 | 	size_t osize = CHUNK_SIZE(self), size = osize; | ||
| 444 | |||
| 445 | 	/* Since we hold split_merge_lock, only transition from free to | ||
| 446 | 	 * in-use can race; in-use to free is impossible */ | ||
| 447 | 	size_t psize = self->psize & C_INUSE ? 0 : CHUNK_PSIZE(self); | ||
| 448 | 	size_t nsize = next->csize & C_INUSE ? 0 : CHUNK_SIZE(next); | ||
| 449 | |||
| 450 | 	if (psize) { | ||
| 451 | 		int i = bin_index(psize); | ||
| 452 | 		lock_bin(i); | ||
| 453 | 		if (!(self->psize & C_INUSE)) { | ||
| 454 | 			struct chunk *prev = PREV_CHUNK(self); | ||
| 455 | 			unbin(prev, i); | ||
| 456 | 			self = prev; | ||
| 457 | 			size += psize; | ||
| 458 | 		} | ||
| 459 | 		unlock_bin(i); | ||
| 460 | 	} | ||
| 461 | 	if (nsize) { | ||
| 462 | 		int i = bin_index(nsize); | ||
| 463 | 		lock_bin(i); | ||
| 464 | 		if (!(next->csize & C_INUSE)) { | ||
| 465 | 			unbin(next, i); | ||
| 466 | 			next = NEXT_CHUNK(next); | ||
| 467 | 			size += nsize; | ||
| 468 | 		} | ||
| 469 | 		unlock_bin(i); | ||
| 470 | 	} | ||
| 471 | |||
| 472 | 	int i = bin_index(size); | ||
| 473 | 	lock_bin(i); | ||
| 474 | |||
| 475 | 	self->csize = size; | ||
| 476 | 	next->psize = size; | ||
| 477 | 	bin_chunk(self, i); | ||
| 478 | 	unlock(mal.split_merge_lock); | ||
| 479 | |||
| 480 | 	/* Replace middle of large chunks with fresh zero pages */ | ||
| 481 | 	if (size > RECLAIM && (size^(size-osize)) > size-osize) { | ||
| 482 | 		uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE; | ||
| 483 | 		uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE; | ||
| 484 | #if 1 | ||
| 485 | 		__madvise((void *)a, b-a, MADV_DONTNEED); | ||
| 486 | #else | ||
| 487 | 		__mmap((void *)a, b-a, PROT_READ|PROT_WRITE, | ||
| 488 | 			MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0); | ||
| 489 | #endif | ||
| 490 | 	} | ||
| 491 | |||
| 492 | 	unlock_bin(i); | ||
| 493 | } | ||
| 494 | |||
| 495 | static void unmap_chunk(struct chunk *self) | ||
| 496 | { | ||
| 497 | 	size_t extra = self->psize; | ||
| 498 | 	char *base = (char *)self - extra; | ||
| 499 | 	size_t len = CHUNK_SIZE(self) + extra; | ||
| 500 | 	/* Crash on double free */ | ||
| 501 | 	if (extra & 1) a_crash(); | ||
| 502 | 	__munmap(base, len); | ||
| 503 | } | ||
| 504 | |||
| 505 | void free(void *p) | ||
| 506 | { | ||
| 507 | 	if (!p) return; | ||
| 508 | |||
| 509 | 	struct chunk *self = MEM_TO_CHUNK(p); | ||
| 510 | |||
| 511 | 	if (IS_MMAPPED(self)) | ||
| 512 | 		unmap_chunk(self); | ||
| 513 | 	else | ||
| 514 | 		__bin_chunk(self); | ||
| 515 | } | ||
| 516 | |||
| 517 | void __malloc_donate(char *start, char *end) | ||
| 518 | { | ||
| 519 | 	size_t align_start_up = (SIZE_ALIGN-1) & (-(uintptr_t)start - OVERHEAD); | ||
| 520 | 	size_t align_end_down = (SIZE_ALIGN-1) & (uintptr_t)end; | ||
| 521 | |||
| 522 | 	/* Getting past this condition ensures that the padding for alignment | ||
| 523 | 	 * and header overhead will not overflow and will leave a nonzero | ||
| 524 | 	 * multiple of SIZE_ALIGN bytes between start and end. */ | ||
| 525 | 	if (end - start <= OVERHEAD + align_start_up + align_end_down) | ||
| 526 | 		return; | ||
| 527 | 	start += align_start_up + OVERHEAD; | ||
| 528 | 	end -= align_end_down; | ||
| 529 | |||
| 530 | 	struct chunk *c = MEM_TO_CHUNK(start), *n = MEM_TO_CHUNK(end); | ||
| 531 | 	c->psize = n->csize = C_INUSE; | ||
| 532 | 	c->csize = n->psize = C_INUSE | (end-start); | ||
| 533 | 	__bin_chunk(c); | ||
| 534 | } | ||
| 535 | |||
| 536 | void __malloc_atfork(int who) | ||
| 537 | { | ||
| 538 | 	if (who<0) { | ||
| 539 | 		lock(mal.split_merge_lock); | ||
| 540 | 		for (int i=0; i<64; i++) | ||
| 541 | 			lock(mal.bins[i].lock); | ||
| 542 | 	} else if (!who) { | ||
| 543 | 		for (int i=0; i<64; i++) | ||
| 544 | 			unlock(mal.bins[i].lock); | ||
| 545 | 		unlock(mal.split_merge_lock); | ||
| 546 | 	} else { | ||
| 547 | 		for (int i=0; i<64; i++) | ||
| 548 | 			mal.bins[i].lock[0] = mal.bins[i].lock[1] = 0; | ||
| 549 | 		mal.split_merge_lock[1] = 0; | ||
| 550 | 		mal.split_merge_lock[0] = 0; | ||
| 551 | 	} | ||
| 552 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc_impl.h created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #ifndef MALLOC_IMPL_H | ||
| 2 | #define MALLOC_IMPL_H | ||
| 3 | |||
| 4 | #include <sys/mman.h> | ||
| 5 | #include "dynlink.h" | ||
| 6 | |||
| 7 | struct chunk { | ||
| 8 | 	size_t psize, csize; | ||
| 9 | 	struct chunk *next, *prev; | ||
| 10 | }; | ||
| 11 | |||
| 12 | struct bin { | ||
| 13 | 	volatile int lock[2]; | ||
| 14 | 	struct chunk *head; | ||
| 15 | 	struct chunk *tail; | ||
| 16 | }; | ||
| 17 | |||
| 18 | #define SIZE_ALIGN (4*sizeof(size_t)) | ||
| 19 | #define SIZE_MASK (-SIZE_ALIGN) | ||
| 20 | #define OVERHEAD (2*sizeof(size_t)) | ||
| 21 | #define MMAP_THRESHOLD (0x1c00*SIZE_ALIGN) | ||
| 22 | #define DONTCARE 16 | ||
| 23 | #define RECLAIM 163840 | ||
| 24 | |||
| 25 | #define CHUNK_SIZE(c) ((c)->csize & -2) | ||
| 26 | #define CHUNK_PSIZE(c) ((c)->psize & -2) | ||
| 27 | #define PREV_CHUNK(c) ((struct chunk *)((char *)(c) - CHUNK_PSIZE(c))) | ||
| 28 | #define NEXT_CHUNK(c) ((struct chunk *)((char *)(c) + CHUNK_SIZE(c))) | ||
| 29 | #define MEM_TO_CHUNK(p) (struct chunk *)((char *)(p) - OVERHEAD) | ||
| 30 | #define CHUNK_TO_MEM(c) (void *)((char *)(c) + OVERHEAD) | ||
| 31 | #define BIN_TO_CHUNK(i) (MEM_TO_CHUNK(&mal.bins[i].head)) | ||
| 32 | |||
| 33 | #define C_INUSE ((size_t)1) | ||
| 34 | |||
| 35 | #define IS_MMAPPED(c) !((c)->csize & (C_INUSE)) | ||
| 36 | |||
| 37 | hidden void __bin_chunk(struct chunk *); | ||
| 38 | |||
| 39 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc_usable_size.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <malloc.h> | ||
| 2 | #include "malloc_impl.h" | ||
| 3 | |||
| 4 | hidden void *(*const __realloc_dep)(void *, size_t) = realloc; | ||
| 5 | |||
| 6 | size_t malloc_usable_size(void *p) | ||
| 7 | { | ||
| 8 | 	return p ? CHUNK_SIZE(MEM_TO_CHUNK(p)) - OVERHEAD : 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/posix_memalign.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int posix_memalign(void **res, size_t align, size_t len) | ||
| 5 | { | ||
| 6 | 	if (align < sizeof(void *)) return EINVAL; | ||
| 7 | 	void *mem = aligned_alloc(align, len); | ||
| 8 | 	if (!mem) return errno; | ||
| 9 | 	*res = mem; | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/realloc.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | void *realloc(void *p, size_t n) | ||
| 4 | { | ||
| 5 | 	return __libc_realloc(p, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/reallocarray.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <errno.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | |||
| 5 | void *reallocarray(void *ptr, size_t m, size_t n) | ||
| 6 | { | ||
| 7 | 	if (n && m > -1 / n) { | ||
| 8 | 		errno = ENOMEM; | ||
| 9 | 		return 0; | ||
| 10 | 	} | ||
| 11 | |||
| 12 | 	return realloc(ptr, m * n); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/malloc/replaced.c created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | #include "dynlink.h" | ||
| 2 | |||
| 3 | int __malloc_replaced; | ||
| 4 | int __aligned_alloc_replaced; | ||
lib/libc/wasi/libc-top-half/musl/src/math/__cos.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_cos.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 | /* | ||
| 13 | * __cos( x, y ) | ||
| 14 | * kernel cos function on [-pi/4, pi/4], pi/4 ~ 0.785398164 | ||
| 15 | * Input x is assumed to be bounded by ~pi/4 in magnitude. | ||
| 16 | * Input y is the tail of x. | ||
| 17 | * | ||
| 18 | * Algorithm | ||
| 19 | * 1. Since cos(-x) = cos(x), we need only to consider positive x. | ||
| 20 | * 2. if x < 2^-27 (hx<0x3e400000 0), return 1 with inexact if x!=0. | ||
| 21 | * 3. cos(x) is approximated by a polynomial of degree 14 on | ||
| 22 | * [0,pi/4] | ||
| 23 | * 4 14 | ||
| 24 | * cos(x) ~ 1 - x*x/2 + C1*x + ... + C6*x | ||
| 25 | * where the remez error is | ||
| 26 | * | ||
| 27 | * | 2 4 6 8 10 12 14 | -58 | ||
| 28 | * |cos(x)-(1-.5*x +C1*x +C2*x +C3*x +C4*x +C5*x +C6*x )| <= 2 | ||
| 29 | * | | | ||
| 30 | * | ||
| 31 | * 4 6 8 10 12 14 | ||
| 32 | * 4. let r = C1*x +C2*x +C3*x +C4*x +C5*x +C6*x , then | ||
| 33 | * cos(x) ~ 1 - x*x/2 + r | ||
| 34 | * since cos(x+y) ~ cos(x) - sin(x)*y | ||
| 35 | * ~ cos(x) - x*y, | ||
| 36 | * a correction term is necessary in cos(x) and hence | ||
| 37 | * cos(x+y) = 1 - (x*x/2 - (r - x*y)) | ||
| 38 | * For better accuracy, rearrange to | ||
| 39 | * cos(x+y) ~ w + (tmp + (r-x*y)) | ||
| 40 | * where w = 1 - x*x/2 and tmp is a tiny correction term | ||
| 41 | * (1 - x*x/2 == w + tmp exactly in infinite precision). | ||
| 42 | * The exactness of w + tmp in infinite precision depends on w | ||
| 43 | * and tmp having the same precision as x. If they have extra | ||
| 44 | * precision due to compiler bugs, then the extra precision is | ||
| 45 | * only good provided it is retained in all terms of the final | ||
| 46 | * expression for cos(). Retention happens in all cases tested | ||
| 47 | * under FreeBSD, so don't pessimize things by forcibly clipping | ||
| 48 | * any extra precision in w. | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include "libm.h" | ||
| 52 | |||
| 53 | static const double | ||
| 54 | C1 = 4.16666666666666019037e-02, /* 0x3FA55555, 0x5555554C */ | ||
| 55 | C2 = -1.38888888888741095749e-03, /* 0xBF56C16C, 0x16C15177 */ | ||
| 56 | C3 = 2.48015872894767294178e-05, /* 0x3EFA01A0, 0x19CB1590 */ | ||
| 57 | C4 = -2.75573143513906633035e-07, /* 0xBE927E4F, 0x809C52AD */ | ||
| 58 | C5 = 2.08757232129817482790e-09, /* 0x3E21EE9E, 0xBDB4B1C4 */ | ||
| 59 | C6 = -1.13596475577881948265e-11; /* 0xBDA8FAE9, 0xBE8838D4 */ | ||
| 60 | |||
| 61 | double __cos(double x, double y) | ||
| 62 | { | ||
| 63 | 	double_t hz,z,r,w; | ||
| 64 | |||
| 65 | 	z = x*x; | ||
| 66 | 	w = z*z; | ||
| 67 | 	r = z*(C1+z*(C2+z*C3)) + w*w*(C4+z*(C5+z*C6)); | ||
| 68 | 	hz = 0.5*z; | ||
| 69 | 	w = 1.0-hz; | ||
| 70 | 	return w + (((1.0-w)-hz) + (z*r-x*y)); | ||
| 71 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__cosdf.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_cosf.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 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | /* |cos(x) - c(x)| < 2**-34.1 (~[-5.37e-11, 5.295e-11]). */ | ||
| 20 | static const double | ||
| 21 | C0 = -0x1ffffffd0c5e81.0p-54, /* -0.499999997251031003120 */ | ||
| 22 | C1 = 0x155553e1053a42.0p-57, /* 0.0416666233237390631894 */ | ||
| 23 | C2 = -0x16c087e80f1e27.0p-62, /* -0.00138867637746099294692 */ | ||
| 24 | C3 = 0x199342e0ee5069.0p-68; /* 0.0000243904487962774090654 */ | ||
| 25 | |||
| 26 | float __cosdf(double x) | ||
| 27 | { | ||
| 28 | 	double_t r, w, z; | ||
| 29 | |||
| 30 | 	/* Try to optimize for parallel evaluation as in __tandf.c. */ | ||
| 31 | 	z = x*x; | ||
| 32 | 	w = z*z; | ||
| 33 | 	r = C2+z*C3; | ||
| 34 | 	return ((1.0+z*C0) + w*C1) + (w*z)*r; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__cosl.c created+96| ... | @@ -0,0 +1,96 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/ld80/k_cosl.c */ | ||
| 2 | /* origin: FreeBSD /usr/src/lib/msun/ld128/k_cosl.c */ | ||
| 3 | /* | ||
| 4 | * ==================================================== | ||
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 6 | * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. | ||
| 7 | * | ||
| 8 | * Developed at SunSoft, a Sun Microsystems, Inc. business. | ||
| 9 | * Permission to use, copy, modify, and distribute this | ||
| 10 | * software is freely granted, provided that this notice | ||
| 11 | * is preserved. | ||
| 12 | * ==================================================== | ||
| 13 | */ | ||
| 14 | |||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 19 | #if LDBL_MANT_DIG == 64 | ||
| 20 | /* | ||
| 21 | * ld80 version of __cos.c. See __cos.c for most comments. | ||
| 22 | */ | ||
| 23 | /* | ||
| 24 | * Domain [-0.7854, 0.7854], range ~[-2.43e-23, 2.425e-23]: | ||
| 25 | * |cos(x) - c(x)| < 2**-75.1 | ||
| 26 | * | ||
| 27 | * The coefficients of c(x) were generated by a pari-gp script using | ||
| 28 | * a Remez algorithm that searches for the best higher coefficients | ||
| 29 | * after rounding leading coefficients to a specified precision. | ||
| 30 | * | ||
| 31 | * Simpler methods like Chebyshev or basic Remez barely suffice for | ||
| 32 | * cos() in 64-bit precision, because we want the coefficient of x^2 | ||
| 33 | * to be precisely -0.5 so that multiplying by it is exact, and plain | ||
| 34 | * rounding of the coefficients of a good polynomial approximation only | ||
| 35 | * gives this up to about 64-bit precision. Plain rounding also gives | ||
| 36 | * a mediocre approximation for the coefficient of x^4, but a rounding | ||
| 37 | * error of 0.5 ulps for this coefficient would only contribute ~0.01 | ||
| 38 | * ulps to the final error, so this is unimportant. Rounding errors in | ||
| 39 | * higher coefficients are even less important. | ||
| 40 | * | ||
| 41 | * In fact, coefficients above the x^4 one only need to have 53-bit | ||
| 42 | * precision, and this is more efficient. We get this optimization | ||
| 43 | * almost for free from the complications needed to search for the best | ||
| 44 | * higher coefficients. | ||
| 45 | */ | ||
| 46 | static const long double | ||
| 47 | C1 = 0.0416666666666666666136L; /* 0xaaaaaaaaaaaaaa9b.0p-68 */ | ||
| 48 | static const double | ||
| 49 | C2 = -0.0013888888888888874, /* -0x16c16c16c16c10.0p-62 */ | ||
| 50 | C3 = 0.000024801587301571716, /* 0x1a01a01a018e22.0p-68 */ | ||
| 51 | C4 = -0.00000027557319215507120, /* -0x127e4fb7602f22.0p-74 */ | ||
| 52 | C5 = 0.0000000020876754400407278, /* 0x11eed8caaeccf1.0p-81 */ | ||
| 53 | C6 = -1.1470297442401303e-11, /* -0x19393412bd1529.0p-89 */ | ||
| 54 | C7 = 4.7383039476436467e-14; /* 0x1aac9d9af5c43e.0p-97 */ | ||
| 55 | #define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*C7))))))) | ||
| 56 | #elif LDBL_MANT_DIG == 113 | ||
| 57 | /* | ||
| 58 | * ld128 version of __cos.c. See __cos.c for most comments. | ||
| 59 | */ | ||
| 60 | /* | ||
| 61 | * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]: | ||
| 62 | * |cos(x) - c(x))| < 2**-122.0 | ||
| 63 | * | ||
| 64 | * 113-bit precision requires more care than 64-bit precision, since | ||
| 65 | * simple methods give a minimax polynomial with coefficient for x^2 | ||
| 66 | * that is 1 ulp below 0.5, but we want it to be precisely 0.5. See | ||
| 67 | * above for more details. | ||
| 68 | */ | ||
| 69 | static const long double | ||
| 70 | C1 = 0.04166666666666666666666666666666658424671L, | ||
| 71 | C2 = -0.001388888888888888888888888888863490893732L, | ||
| 72 | C3 = 0.00002480158730158730158730158600795304914210L, | ||
| 73 | C4 = -0.2755731922398589065255474947078934284324e-6L, | ||
| 74 | C5 = 0.2087675698786809897659225313136400793948e-8L, | ||
| 75 | C6 = -0.1147074559772972315817149986812031204775e-10L, | ||
| 76 | C7 = 0.4779477332386808976875457937252120293400e-13L; | ||
| 77 | static const double | ||
| 78 | C8 = -0.1561920696721507929516718307820958119868e-15, | ||
| 79 | C9 = 0.4110317413744594971475941557607804508039e-18, | ||
| 80 | C10 = -0.8896592467191938803288521958313920156409e-21, | ||
| 81 | C11 = 0.1601061435794535138244346256065192782581e-23; | ||
| 82 | #define POLY(z) (z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+ \ | ||
| 83 | 	z*(C8+z*(C9+z*(C10+z*C11))))))))))) | ||
| 84 | #endif | ||
| 85 | |||
| 86 | long double __cosl(long double x, long double y) | ||
| 87 | { | ||
| 88 | 	long double hz,z,r,w; | ||
| 89 | |||
| 90 | 	z = x*x; | ||
| 91 | 	r = POLY(z); | ||
| 92 | 	hz = 0.5*z; | ||
| 93 | 	w = 1.0-hz; | ||
| 94 | 	return w + (((1.0-w)-hz) + (z*r-x*y)); | ||
| 95 | } | ||
| 96 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__expo2.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 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 created+25| ... | @@ -0,0 +1,25 @@ | ||
| 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/__fpclassify.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | int __fpclassify(double x) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} u = {x}; | ||
| 7 | 	int e = u.i>>52 & 0x7ff; | ||
| 8 | 	if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO; | ||
| 9 | 	if (e==0x7ff) return u.i<<12 ? FP_NAN : FP_INFINITE; | ||
| 10 | 	return FP_NORMAL; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassifyf.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | int __fpclassifyf(float x) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} u = {x}; | ||
| 7 | 	int e = u.i>>23 & 0xff; | ||
| 8 | 	if (!e) return u.i<<1 ? FP_SUBNORMAL : FP_ZERO; | ||
| 9 | 	if (e==0xff) return u.i<<9 ? FP_NAN : FP_INFINITE; | ||
| 10 | 	return FP_NORMAL; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__fpclassifyl.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | int __fpclassifyl(long double x) | ||
| 5 | { | ||
| 6 | 	return __fpclassify(x); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | int __fpclassifyl(long double x) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	int e = u.i.se & 0x7fff; | ||
| 13 | 	int msb = u.i.m>>63; | ||
| 14 | 	if (!e && !msb) | ||
| 15 | 		return u.i.m ? FP_SUBNORMAL : FP_ZERO; | ||
| 16 | 	if (e == 0x7fff) { | ||
| 17 | 		/* The x86 variant of 80-bit extended precision only admits | ||
| 18 | 		 * one representation of each infinity, with the mantissa msb | ||
| 19 | 		 * necessarily set. The version with it clear is invalid/nan. | ||
| 20 | 		 * The m68k variant, however, allows either, and tooling uses | ||
| 21 | 		 * the version with it clear. */ | ||
| 22 | 		if (__BYTE_ORDER == __LITTLE_ENDIAN && !msb) | ||
| 23 | 			return FP_NAN; | ||
| 24 | 		return u.i.m << 1 ? FP_NAN : FP_INFINITE; | ||
| 25 | 	} | ||
| 26 | 	if (!msb) | ||
| 27 | 		return FP_NAN; | ||
| 28 | 	return FP_NORMAL; | ||
| 29 | } | ||
| 30 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 31 | int __fpclassifyl(long double x) | ||
| 32 | { | ||
| 33 | 	union ldshape u = {x}; | ||
| 34 | 	int e = u.i.se & 0x7fff; | ||
| 35 | 	u.i.se = 0; | ||
| 36 | 	if (!e) | ||
| 37 | 		return u.i2.lo | u.i2.hi ? FP_SUBNORMAL : FP_ZERO; | ||
| 38 | 	if (e == 0x7fff) | ||
| 39 | 		return u.i2.lo | u.i2.hi ? FP_NAN : FP_INFINITE; | ||
| 40 | 	return FP_NORMAL; | ||
| 41 | } | ||
| 42 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__invtrigl.c created+63| ... | @@ -0,0 +1,63 @@ | ||
| 1 | #include <float.h> | ||
| 2 | #include "__invtrigl.h" | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 5 | static const long double | ||
| 6 | pS0 = 1.66666666666666666631e-01L, | ||
| 7 | pS1 = -4.16313987993683104320e-01L, | ||
| 8 | pS2 = 3.69068046323246813704e-01L, | ||
| 9 | pS3 = -1.36213932016738603108e-01L, | ||
| 10 | pS4 = 1.78324189708471965733e-02L, | ||
| 11 | pS5 = -2.19216428382605211588e-04L, | ||
| 12 | pS6 = -7.10526623669075243183e-06L, | ||
| 13 | qS1 = -2.94788392796209867269e+00L, | ||
| 14 | qS2 = 3.27309890266528636716e+00L, | ||
| 15 | qS3 = -1.68285799854822427013e+00L, | ||
| 16 | qS4 = 3.90699412641738801874e-01L, | ||
| 17 | qS5 = -3.14365703596053263322e-02L; | ||
| 18 | |||
| 19 | const long double pio2_hi = 1.57079632679489661926L; | ||
| 20 | const long double pio2_lo = -2.50827880633416601173e-20L; | ||
| 21 | |||
| 22 | /* used in asinl() and acosl() */ | ||
| 23 | /* R(x^2) is a rational approximation of (asin(x)-x)/x^3 with Remez algorithm */ | ||
| 24 | long double __invtrigl_R(long double z) | ||
| 25 | { | ||
| 26 | 	long double p, q; | ||
| 27 | 	p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*(pS5+z*pS6)))))); | ||
| 28 | 	q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*qS5)))); | ||
| 29 | 	return p/q; | ||
| 30 | } | ||
| 31 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 32 | static const long double | ||
| 33 | pS0 = 1.66666666666666666666666666666700314e-01L, | ||
| 34 | pS1 = -7.32816946414566252574527475428622708e-01L, | ||
| 35 | pS2 = 1.34215708714992334609030036562143589e+00L, | ||
| 36 | pS3 = -1.32483151677116409805070261790752040e+00L, | ||
| 37 | pS4 = 7.61206183613632558824485341162121989e-01L, | ||
| 38 | pS5 = -2.56165783329023486777386833928147375e-01L, | ||
| 39 | pS6 = 4.80718586374448793411019434585413855e-02L, | ||
| 40 | pS7 = -4.42523267167024279410230886239774718e-03L, | ||
| 41 | pS8 = 1.44551535183911458253205638280410064e-04L, | ||
| 42 | pS9 = -2.10558957916600254061591040482706179e-07L, | ||
| 43 | qS1 = -4.84690167848739751544716485245697428e+00L, | ||
| 44 | qS2 = 9.96619113536172610135016921140206980e+00L, | ||
| 45 | qS3 = -1.13177895428973036660836798461641458e+01L, | ||
| 46 | qS4 = 7.74004374389488266169304117714658761e+00L, | ||
| 47 | qS5 = -3.25871986053534084709023539900339905e+00L, | ||
| 48 | qS6 = 8.27830318881232209752469022352928864e-01L, | ||
| 49 | qS7 = -1.18768052702942805423330715206348004e-01L, | ||
| 50 | qS8 = 8.32600764660522313269101537926539470e-03L, | ||
| 51 | qS9 = -1.99407384882605586705979504567947007e-04L; | ||
| 52 | |||
| 53 | const long double pio2_hi = 1.57079632679489661923132169163975140L; | ||
| 54 | const long double pio2_lo = 4.33590506506189051239852201302167613e-35L; | ||
| 55 | |||
| 56 | long double __invtrigl_R(long double z) | ||
| 57 | { | ||
| 58 | 	long double p, q; | ||
| 59 | 	p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*(pS5+z*(pS6+z*(pS7+z*(pS8+z*pS9))))))))); | ||
| 60 | 	q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*(qS4+z*(qS5+z*(qS6+z*(qS7+z*(qS8+z*qS9)))))))); | ||
| 61 | 	return p/q; | ||
| 62 | } | ||
| 63 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__invtrigl.h created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | /* shared by acosl, asinl and atan2l */ | ||
| 4 | #define pio2_hi __pio2_hi | ||
| 5 | #define pio2_lo __pio2_lo | ||
| 6 | hidden extern const long double pio2_hi, pio2_lo; | ||
| 7 | |||
| 8 | hidden long double __invtrigl_R(long double z); | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_divzero.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double __math_divzero(uint32_t sign) | ||
| 4 | { | ||
| 5 | 	return fp_barrier(sign ? -1.0 : 1.0) / 0.0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_divzerof.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float __math_divzerof(uint32_t sign) | ||
| 4 | { | ||
| 5 | 	return fp_barrierf(sign ? -1.0f : 1.0f) / 0.0f; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_invalid.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double __math_invalid(double x) | ||
| 4 | { | ||
| 5 | 	return (x - x) / (x - x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_invalidf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float __math_invalidf(float x) | ||
| 4 | { | ||
| 5 | 	return (x - x) / (x - x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_invalidl.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <float.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG != DBL_MANT_DIG | ||
| 5 | long double __math_invalidl(long double x) | ||
| 6 | { | ||
| 7 | 	return (x - x) / (x - x); | ||
| 8 | } | ||
| 9 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_oflow.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double __math_oflow(uint32_t sign) | ||
| 4 | { | ||
| 5 | 	return __math_xflow(sign, 0x1p769); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_oflowf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float __math_oflowf(uint32_t sign) | ||
| 4 | { | ||
| 5 | 	return __math_xflowf(sign, 0x1p97f); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_uflow.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double __math_uflow(uint32_t sign) | ||
| 4 | { | ||
| 5 | 	return __math_xflow(sign, 0x1p-767); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_uflowf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float __math_uflowf(uint32_t sign) | ||
| 4 | { | ||
| 5 | 	return __math_xflowf(sign, 0x1p-95f); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_xflow.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double __math_xflow(uint32_t sign, double y) | ||
| 4 | { | ||
| 5 | 	return eval_as_double(fp_barrier(sign ? -y : y) * y); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__math_xflowf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float __math_xflowf(uint32_t sign, float y) | ||
| 4 | { | ||
| 5 | 	return eval_as_float(fp_barrierf(sign ? -y : y) * y); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__polevll.c created+93| ... | @@ -0,0 +1,93 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/polevll.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 | /* | ||
| 18 | * Evaluate polynomial | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * int N; | ||
| 24 | * long double x, y, coef[N+1], polevl[]; | ||
| 25 | * | ||
| 26 | * y = polevll( x, coef, N ); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * Evaluates polynomial of degree N: | ||
| 32 | * | ||
| 33 | * 2 N | ||
| 34 | * y = C + C x + C x +...+ C x | ||
| 35 | * 0 1 2 N | ||
| 36 | * | ||
| 37 | * Coefficients are stored in reverse order: | ||
| 38 | * | ||
| 39 | * coef[0] = C , ..., coef[N] = C . | ||
| 40 | * N 0 | ||
| 41 | * | ||
| 42 | * The function p1evll() assumes that coef[N] = 1.0 and is | ||
| 43 | * omitted from the array. Its calling arguments are | ||
| 44 | * otherwise the same as polevll(). | ||
| 45 | * | ||
| 46 | * | ||
| 47 | * SPEED: | ||
| 48 | * | ||
| 49 | * In the interest of speed, there are no checks for out | ||
| 50 | * of bounds arithmetic. This routine is used by most of | ||
| 51 | * the functions in the library. Depending on available | ||
| 52 | * equipment features, the user may wish to rewrite the | ||
| 53 | * program in microcode or assembly language. | ||
| 54 | * | ||
| 55 | */ | ||
| 56 | |||
| 57 | #include "libm.h" | ||
| 58 | |||
| 59 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 60 | #else | ||
| 61 | /* | ||
| 62 | * Polynomial evaluator: | ||
| 63 | * P[0] x^n + P[1] x^(n-1) + ... + P[n] | ||
| 64 | */ | ||
| 65 | long double __polevll(long double x, const long double *P, int n) | ||
| 66 | { | ||
| 67 | 	long double y; | ||
| 68 | |||
| 69 | 	y = *P++; | ||
| 70 | 	do { | ||
| 71 | 		y = y * x + *P++; | ||
| 72 | 	} while (--n); | ||
| 73 | |||
| 74 | 	return y; | ||
| 75 | } | ||
| 76 | |||
| 77 | /* | ||
| 78 | * Polynomial evaluator: | ||
| 79 | * x^n + P[0] x^(n-1) + P[1] x^(n-2) + ... + P[n] | ||
| 80 | */ | ||
| 81 | long double __p1evll(long double x, const long double *P, int n) | ||
| 82 | { | ||
| 83 | 	long double y; | ||
| 84 | |||
| 85 | 	n -= 1; | ||
| 86 | 	y = x + *P++; | ||
| 87 | 	do { | ||
| 88 | 		y = y * x + *P++; | ||
| 89 | 	} while (--n); | ||
| 90 | |||
| 91 | 	return y; | ||
| 92 | } | ||
| 93 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2.c created+194| ... | @@ -0,0 +1,194 @@ | ||
| 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_pio2_large.c created+442| ... | @@ -0,0 +1,442 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_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 | /* | ||
| 13 | * __rem_pio2_large(x,y,e0,nx,prec) | ||
| 14 | * double x[],y[]; int e0,nx,prec; | ||
| 15 | * | ||
| 16 | * __rem_pio2_large return the last three digits of N with | ||
| 17 | * y = x - N*pi/2 | ||
| 18 | * so that |y| < pi/2. | ||
| 19 | * | ||
| 20 | * The method is to compute the integer (mod 8) and fraction parts of | ||
| 21 | * (2/pi)*x without doing the full multiplication. In general we | ||
| 22 | * skip the part of the product that are known to be a huge integer ( | ||
| 23 | * more accurately, = 0 mod 8 ). Thus the number of operations are | ||
| 24 | * independent of the exponent of the input. | ||
| 25 | * | ||
| 26 | * (2/pi) is represented by an array of 24-bit integers in ipio2[]. | ||
| 27 | * | ||
| 28 | * Input parameters: | ||
| 29 | * x[] The input value (must be positive) is broken into nx | ||
| 30 | * pieces of 24-bit integers in double precision format. | ||
| 31 | * x[i] will be the i-th 24 bit of x. The scaled exponent | ||
| 32 | * of x[0] is given in input parameter e0 (i.e., x[0]*2^e0 | ||
| 33 | * match x's up to 24 bits. | ||
| 34 | * | ||
| 35 | * Example of breaking a double positive z into x[0]+x[1]+x[2]: | ||
| 36 | * e0 = ilogb(z)-23 | ||
| 37 | * z = scalbn(z,-e0) | ||
| 38 | * for i = 0,1,2 | ||
| 39 | * x[i] = floor(z) | ||
| 40 | * z = (z-x[i])*2**24 | ||
| 41 | * | ||
| 42 | * | ||
| 43 | * y[] ouput result in an array of double precision numbers. | ||
| 44 | * The dimension of y[] is: | ||
| 45 | * 24-bit precision 1 | ||
| 46 | * 53-bit precision 2 | ||
| 47 | * 64-bit precision 2 | ||
| 48 | * 113-bit precision 3 | ||
| 49 | * The actual value is the sum of them. Thus for 113-bit | ||
| 50 | * precison, one may have to do something like: | ||
| 51 | * | ||
| 52 | * long double t,w,r_head, r_tail; | ||
| 53 | * t = (long double)y[2] + (long double)y[1]; | ||
| 54 | * w = (long double)y[0]; | ||
| 55 | * r_head = t+w; | ||
| 56 | * r_tail = w - (r_head - t); | ||
| 57 | * | ||
| 58 | * e0 The exponent of x[0]. Must be <= 16360 or you need to | ||
| 59 | * expand the ipio2 table. | ||
| 60 | * | ||
| 61 | * nx dimension of x[] | ||
| 62 | * | ||
| 63 | * prec an integer indicating the precision: | ||
| 64 | * 0 24 bits (single) | ||
| 65 | * 1 53 bits (double) | ||
| 66 | * 2 64 bits (extended) | ||
| 67 | * 3 113 bits (quad) | ||
| 68 | * | ||
| 69 | * External function: | ||
| 70 | * double scalbn(), floor(); | ||
| 71 | * | ||
| 72 | * | ||
| 73 | * Here is the description of some local variables: | ||
| 74 | * | ||
| 75 | * jk jk+1 is the initial number of terms of ipio2[] needed | ||
| 76 | * in the computation. The minimum and recommended value | ||
| 77 | * for jk is 3,4,4,6 for single, double, extended, and quad. | ||
| 78 | * jk+1 must be 2 larger than you might expect so that our | ||
| 79 | * recomputation test works. (Up to 24 bits in the integer | ||
| 80 | * part (the 24 bits of it that we compute) and 23 bits in | ||
| 81 | * the fraction part may be lost to cancelation before we | ||
| 82 | * recompute.) | ||
| 83 | * | ||
| 84 | * jz local integer variable indicating the number of | ||
| 85 | * terms of ipio2[] used. | ||
| 86 | * | ||
| 87 | * jx nx - 1 | ||
| 88 | * | ||
| 89 | * jv index for pointing to the suitable ipio2[] for the | ||
| 90 | * computation. In general, we want | ||
| 91 | * ( 2^e0*x[0] * ipio2[jv-1]*2^(-24jv) )/8 | ||
| 92 | * is an integer. Thus | ||
| 93 | * e0-3-24*jv >= 0 or (e0-3)/24 >= jv | ||
| 94 | * Hence jv = max(0,(e0-3)/24). | ||
| 95 | * | ||
| 96 | * jp jp+1 is the number of terms in PIo2[] needed, jp = jk. | ||
| 97 | * | ||
| 98 | * q[] double array with integral value, representing the | ||
| 99 | * 24-bits chunk of the product of x and 2/pi. | ||
| 100 | * | ||
| 101 | * q0 the corresponding exponent of q[0]. Note that the | ||
| 102 | * exponent for q[i] would be q0-24*i. | ||
| 103 | * | ||
| 104 | * PIo2[] double precision array, obtained by cutting pi/2 | ||
| 105 | * into 24 bits chunks. | ||
| 106 | * | ||
| 107 | * f[] ipio2[] in floating point | ||
| 108 | * | ||
| 109 | * iq[] integer array by breaking up q[] in 24-bits chunk. | ||
| 110 | * | ||
| 111 | * fq[] final product of x*(2/pi) in fq[0],..,fq[jk] | ||
| 112 | * | ||
| 113 | * ih integer. If >0 it indicates q[] is >= 0.5, hence | ||
| 114 | * it also indicates the *sign* of the result. | ||
| 115 | * | ||
| 116 | */ | ||
| 117 | /* | ||
| 118 | * Constants: | ||
| 119 | * The hexadecimal values are the intended ones for the following | ||
| 120 | * constants. The decimal values may be used, provided that the | ||
| 121 | * compiler will convert from decimal to binary accurately enough | ||
| 122 | * to produce the hexadecimal values shown. | ||
| 123 | */ | ||
| 124 | |||
| 125 | #include "libm.h" | ||
| 126 | |||
| 127 | static const int init_jk[] = {3,4,4,6}; /* initial value for jk */ | ||
| 128 | |||
| 129 | /* | ||
| 130 | * Table of constants for 2/pi, 396 Hex digits (476 decimal) of 2/pi | ||
| 131 | * | ||
| 132 | * integer array, contains the (24*i)-th to (24*i+23)-th | ||
| 133 | * bit of 2/pi after binary point. The corresponding | ||
| 134 | * floating value is | ||
| 135 | * | ||
| 136 | * ipio2[i] * 2^(-24(i+1)). | ||
| 137 | * | ||
| 138 | * NB: This table must have at least (e0-3)/24 + jk terms. | ||
| 139 | * For quad precision (e0 <= 16360, jk = 6), this is 686. | ||
| 140 | */ | ||
| 141 | static const int32_t ipio2[] = { | ||
| 142 | 0xA2F983, 0x6E4E44, 0x1529FC, 0x2757D1, 0xF534DD, 0xC0DB62, | ||
| 143 | 0x95993C, 0x439041, 0xFE5163, 0xABDEBB, 0xC561B7, 0x246E3A, | ||
| 144 | 0x424DD2, 0xE00649, 0x2EEA09, 0xD1921C, 0xFE1DEB, 0x1CB129, | ||
| 145 | 0xA73EE8, 0x8235F5, 0x2EBB44, 0x84E99C, 0x7026B4, 0x5F7E41, | ||
| 146 | 0x3991D6, 0x398353, 0x39F49C, 0x845F8B, 0xBDF928, 0x3B1FF8, | ||
| 147 | 0x97FFDE, 0x05980F, 0xEF2F11, 0x8B5A0A, 0x6D1F6D, 0x367ECF, | ||
| 148 | 0x27CB09, 0xB74F46, 0x3F669E, 0x5FEA2D, 0x7527BA, 0xC7EBE5, | ||
| 149 | 0xF17B3D, 0x0739F7, 0x8A5292, 0xEA6BFB, 0x5FB11F, 0x8D5D08, | ||
| 150 | 0x560330, 0x46FC7B, 0x6BABF0, 0xCFBC20, 0x9AF436, 0x1DA9E3, | ||
| 151 | 0x91615E, 0xE61B08, 0x659985, 0x5F14A0, 0x68408D, 0xFFD880, | ||
| 152 | 0x4D7327, 0x310606, 0x1556CA, 0x73A8C9, 0x60E27B, 0xC08C6B, | ||
| 153 | |||
| 154 | #if LDBL_MAX_EXP > 1024 | ||
| 155 | 0x47C419, 0xC367CD, 0xDCE809, 0x2A8359, 0xC4768B, 0x961CA6, | ||
| 156 | 0xDDAF44, 0xD15719, 0x053EA5, 0xFF0705, 0x3F7E33, 0xE832C2, | ||
| 157 | 0xDE4F98, 0x327DBB, 0xC33D26, 0xEF6B1E, 0x5EF89F, 0x3A1F35, | ||
| 158 | 0xCAF27F, 0x1D87F1, 0x21907C, 0x7C246A, 0xFA6ED5, 0x772D30, | ||
| 159 | 0x433B15, 0xC614B5, 0x9D19C3, 0xC2C4AD, 0x414D2C, 0x5D000C, | ||
| 160 | 0x467D86, 0x2D71E3, 0x9AC69B, 0x006233, 0x7CD2B4, 0x97A7B4, | ||
| 161 | 0xD55537, 0xF63ED7, 0x1810A3, 0xFC764D, 0x2A9D64, 0xABD770, | ||
| 162 | 0xF87C63, 0x57B07A, 0xE71517, 0x5649C0, 0xD9D63B, 0x3884A7, | ||
| 163 | 0xCB2324, 0x778AD6, 0x23545A, 0xB91F00, 0x1B0AF1, 0xDFCE19, | ||
| 164 | 0xFF319F, 0x6A1E66, 0x615799, 0x47FBAC, 0xD87F7E, 0xB76522, | ||
| 165 | 0x89E832, 0x60BFE6, 0xCDC4EF, 0x09366C, 0xD43F5D, 0xD7DE16, | ||
| 166 | 0xDE3B58, 0x929BDE, 0x2822D2, 0xE88628, 0x4D58E2, 0x32CAC6, | ||
| 167 | 0x16E308, 0xCB7DE0, 0x50C017, 0xA71DF3, 0x5BE018, 0x34132E, | ||
| 168 | 0x621283, 0x014883, 0x5B8EF5, 0x7FB0AD, 0xF2E91E, 0x434A48, | ||
| 169 | 0xD36710, 0xD8DDAA, 0x425FAE, 0xCE616A, 0xA4280A, 0xB499D3, | ||
| 170 | 0xF2A606, 0x7F775C, 0x83C2A3, 0x883C61, 0x78738A, 0x5A8CAF, | ||
| 171 | 0xBDD76F, 0x63A62D, 0xCBBFF4, 0xEF818D, 0x67C126, 0x45CA55, | ||
| 172 | 0x36D9CA, 0xD2A828, 0x8D61C2, 0x77C912, 0x142604, 0x9B4612, | ||
| 173 | 0xC459C4, 0x44C5C8, 0x91B24D, 0xF31700, 0xAD43D4, 0xE54929, | ||
| 174 | 0x10D5FD, 0xFCBE00, 0xCC941E, 0xEECE70, 0xF53E13, 0x80F1EC, | ||
| 175 | 0xC3E7B3, 0x28F8C7, 0x940593, 0x3E71C1, 0xB3092E, 0xF3450B, | ||
| 176 | 0x9C1288, 0x7B20AB, 0x9FB52E, 0xC29247, 0x2F327B, 0x6D550C, | ||
| 177 | 0x90A772, 0x1FE76B, 0x96CB31, 0x4A1679, 0xE27941, 0x89DFF4, | ||
| 178 | 0x9794E8, 0x84E6E2, 0x973199, 0x6BED88, 0x365F5F, 0x0EFDBB, | ||
| 179 | 0xB49A48, 0x6CA467, 0x427271, 0x325D8D, 0xB8159F, 0x09E5BC, | ||
| 180 | 0x25318D, 0x3974F7, 0x1C0530, 0x010C0D, 0x68084B, 0x58EE2C, | ||
| 181 | 0x90AA47, 0x02E774, 0x24D6BD, 0xA67DF7, 0x72486E, 0xEF169F, | ||
| 182 | 0xA6948E, 0xF691B4, 0x5153D1, 0xF20ACF, 0x339820, 0x7E4BF5, | ||
| 183 | 0x6863B2, 0x5F3EDD, 0x035D40, 0x7F8985, 0x295255, 0xC06437, | ||
| 184 | 0x10D86D, 0x324832, 0x754C5B, 0xD4714E, 0x6E5445, 0xC1090B, | ||
| 185 | 0x69F52A, 0xD56614, 0x9D0727, 0x50045D, 0xDB3BB4, 0xC576EA, | ||
| 186 | 0x17F987, 0x7D6B49, 0xBA271D, 0x296996, 0xACCCC6, 0x5414AD, | ||
| 187 | 0x6AE290, 0x89D988, 0x50722C, 0xBEA404, 0x940777, 0x7030F3, | ||
| 188 | 0x27FC00, 0xA871EA, 0x49C266, 0x3DE064, 0x83DD97, 0x973FA3, | ||
| 189 | 0xFD9443, 0x8C860D, 0xDE4131, 0x9D3992, 0x8C70DD, 0xE7B717, | ||
| 190 | 0x3BDF08, 0x2B3715, 0xA0805C, 0x93805A, 0x921110, 0xD8E80F, | ||
| 191 | 0xAF806C, 0x4BFFDB, 0x0F9038, 0x761859, 0x15A562, 0xBBCB61, | ||
| 192 | 0xB989C7, 0xBD4010, 0x04F2D2, 0x277549, 0xF6B6EB, 0xBB22DB, | ||
| 193 | 0xAA140A, 0x2F2689, 0x768364, 0x333B09, 0x1A940E, 0xAA3A51, | ||
| 194 | 0xC2A31D, 0xAEEDAF, 0x12265C, 0x4DC26D, 0x9C7A2D, 0x9756C0, | ||
| 195 | 0x833F03, 0xF6F009, 0x8C402B, 0x99316D, 0x07B439, 0x15200C, | ||
| 196 | 0x5BC3D8, 0xC492F5, 0x4BADC6, 0xA5CA4E, 0xCD37A7, 0x36A9E6, | ||
| 197 | 0x9492AB, 0x6842DD, 0xDE6319, 0xEF8C76, 0x528B68, 0x37DBFC, | ||
| 198 | 0xABA1AE, 0x3115DF, 0xA1AE00, 0xDAFB0C, 0x664D64, 0xB705ED, | ||
| 199 | 0x306529, 0xBF5657, 0x3AFF47, 0xB9F96A, 0xF3BE75, 0xDF9328, | ||
| 200 | 0x3080AB, 0xF68C66, 0x15CB04, 0x0622FA, 0x1DE4D9, 0xA4B33D, | ||
| 201 | 0x8F1B57, 0x09CD36, 0xE9424E, 0xA4BE13, 0xB52333, 0x1AAAF0, | ||
| 202 | 0xA8654F, 0xA5C1D2, 0x0F3F0B, 0xCD785B, 0x76F923, 0x048B7B, | ||
| 203 | 0x721789, 0x53A6C6, 0xE26E6F, 0x00EBEF, 0x584A9B, 0xB7DAC4, | ||
| 204 | 0xBA66AA, 0xCFCF76, 0x1D02D1, 0x2DF1B1, 0xC1998C, 0x77ADC3, | ||
| 205 | 0xDA4886, 0xA05DF7, 0xF480C6, 0x2FF0AC, 0x9AECDD, 0xBC5C3F, | ||
| 206 | 0x6DDED0, 0x1FC790, 0xB6DB2A, 0x3A25A3, 0x9AAF00, 0x9353AD, | ||
| 207 | 0x0457B6, 0xB42D29, 0x7E804B, 0xA707DA, 0x0EAA76, 0xA1597B, | ||
| 208 | 0x2A1216, 0x2DB7DC, 0xFDE5FA, 0xFEDB89, 0xFDBE89, 0x6C76E4, | ||
| 209 | 0xFCA906, 0x70803E, 0x156E85, 0xFF87FD, 0x073E28, 0x336761, | ||
| 210 | 0x86182A, 0xEABD4D, 0xAFE7B3, 0x6E6D8F, 0x396795, 0x5BBF31, | ||
| 211 | 0x48D784, 0x16DF30, 0x432DC7, 0x356125, 0xCE70C9, 0xB8CB30, | ||
| 212 | 0xFD6CBF, 0xA200A4, 0xE46C05, 0xA0DD5A, 0x476F21, 0xD21262, | ||
| 213 | 0x845CB9, 0x496170, 0xE0566B, 0x015299, 0x375550, 0xB7D51E, | ||
| 214 | 0xC4F133, 0x5F6E13, 0xE4305D, 0xA92E85, 0xC3B21D, 0x3632A1, | ||
| 215 | 0xA4B708, 0xD4B1EA, 0x21F716, 0xE4698F, 0x77FF27, 0x80030C, | ||
| 216 | 0x2D408D, 0xA0CD4F, 0x99A520, 0xD3A2B3, 0x0A5D2F, 0x42F9B4, | ||
| 217 | 0xCBDA11, 0xD0BE7D, 0xC1DB9B, 0xBD17AB, 0x81A2CA, 0x5C6A08, | ||
| 218 | 0x17552E, 0x550027, 0xF0147F, 0x8607E1, 0x640B14, 0x8D4196, | ||
| 219 | 0xDEBE87, 0x2AFDDA, 0xB6256B, 0x34897B, 0xFEF305, 0x9EBFB9, | ||
| 220 | 0x4F6A68, 0xA82A4A, 0x5AC44F, 0xBCF82D, 0x985AD7, 0x95C7F4, | ||
| 221 | 0x8D4D0D, 0xA63A20, 0x5F57A4, 0xB13F14, 0x953880, 0x0120CC, | ||
| 222 | 0x86DD71, 0xB6DEC9, 0xF560BF, 0x11654D, 0x6B0701, 0xACB08C, | ||
| 223 | 0xD0C0B2, 0x485551, 0x0EFB1E, 0xC37295, 0x3B06A3, 0x3540C0, | ||
| 224 | 0x7BDC06, 0xCC45E0, 0xFA294E, 0xC8CAD6, 0x41F3E8, 0xDE647C, | ||
| 225 | 0xD8649B, 0x31BED9, 0xC397A4, 0xD45877, 0xC5E369, 0x13DAF0, | ||
| 226 | 0x3C3ABA, 0x461846, 0x5F7555, 0xF5BDD2, 0xC6926E, 0x5D2EAC, | ||
| 227 | 0xED440E, 0x423E1C, 0x87C461, 0xE9FD29, 0xF3D6E7, 0xCA7C22, | ||
| 228 | 0x35916F, 0xC5E008, 0x8DD7FF, 0xE26A6E, 0xC6FDB0, 0xC10893, | ||
| 229 | 0x745D7C, 0xB2AD6B, 0x9D6ECD, 0x7B723E, 0x6A11C6, 0xA9CFF7, | ||
| 230 | 0xDF7329, 0xBAC9B5, 0x5100B7, 0x0DB2E2, 0x24BA74, 0x607DE5, | ||
| 231 | 0x8AD874, 0x2C150D, 0x0C1881, 0x94667E, 0x162901, 0x767A9F, | ||
| 232 | 0xBEFDFD, 0xEF4556, 0x367ED9, 0x13D9EC, 0xB9BA8B, 0xFC97C4, | ||
| 233 | 0x27A831, 0xC36EF1, 0x36C594, 0x56A8D8, 0xB5A8B4, 0x0ECCCF, | ||
| 234 | 0x2D8912, 0x34576F, 0x89562C, 0xE3CE99, 0xB920D6, 0xAA5E6B, | ||
| 235 | 0x9C2A3E, 0xCC5F11, 0x4A0BFD, 0xFBF4E1, 0x6D3B8E, 0x2C86E2, | ||
| 236 | 0x84D4E9, 0xA9B4FC, 0xD1EEEF, 0xC9352E, 0x61392F, 0x442138, | ||
| 237 | 0xC8D91B, 0x0AFC81, 0x6A4AFB, 0xD81C2F, 0x84B453, 0x8C994E, | ||
| 238 | 0xCC2254, 0xDC552A, 0xD6C6C0, 0x96190B, 0xB8701A, 0x649569, | ||
| 239 | 0x605A26, 0xEE523F, 0x0F117F, 0x11B5F4, 0xF5CBFC, 0x2DBC34, | ||
| 240 | 0xEEBC34, 0xCC5DE8, 0x605EDD, 0x9B8E67, 0xEF3392, 0xB817C9, | ||
| 241 | 0x9B5861, 0xBC57E1, 0xC68351, 0x103ED8, 0x4871DD, 0xDD1C2D, | ||
| 242 | 0xA118AF, 0x462C21, 0xD7F359, 0x987AD9, 0xC0549E, 0xFA864F, | ||
| 243 | 0xFC0656, 0xAE79E5, 0x362289, 0x22AD38, 0xDC9367, 0xAAE855, | ||
| 244 | 0x382682, 0x9BE7CA, 0xA40D51, 0xB13399, 0x0ED7A9, 0x480569, | ||
| 245 | 0xF0B265, 0xA7887F, 0x974C88, 0x36D1F9, 0xB39221, 0x4A827B, | ||
| 246 | 0x21CF98, 0xDC9F40, 0x5547DC, 0x3A74E1, 0x42EB67, 0xDF9DFE, | ||
| 247 | 0x5FD45E, 0xA4677B, 0x7AACBA, 0xA2F655, 0x23882B, 0x55BA41, | ||
| 248 | 0x086E59, 0x862A21, 0x834739, 0xE6E389, 0xD49EE5, 0x40FB49, | ||
| 249 | 0xE956FF, 0xCA0F1C, 0x8A59C5, 0x2BFA94, 0xC5C1D3, 0xCFC50F, | ||
| 250 | 0xAE5ADB, 0x86C547, 0x624385, 0x3B8621, 0x94792C, 0x876110, | ||
| 251 | 0x7B4C2A, 0x1A2C80, 0x12BF43, 0x902688, 0x893C78, 0xE4C4A8, | ||
| 252 | 0x7BDBE5, 0xC23AC4, 0xEAF426, 0x8A67F7, 0xBF920D, 0x2BA365, | ||
| 253 | 0xB1933D, 0x0B7CBD, 0xDC51A4, 0x63DD27, 0xDDE169, 0x19949A, | ||
| 254 | 0x9529A8, 0x28CE68, 0xB4ED09, 0x209F44, 0xCA984E, 0x638270, | ||
| 255 | 0x237C7E, 0x32B90F, 0x8EF5A7, 0xE75614, 0x08F121, 0x2A9DB5, | ||
| 256 | 0x4D7E6F, 0x5119A5, 0xABF9B5, 0xD6DF82, 0x61DD96, 0x023616, | ||
| 257 | 0x9F3AC4, 0xA1A283, 0x6DED72, 0x7A8D39, 0xA9B882, 0x5C326B, | ||
| 258 | 0x5B2746, 0xED3400, 0x7700D2, 0x55F4FC, 0x4D5901, 0x8071E0, | ||
| 259 | #endif | ||
| 260 | }; | ||
| 261 | |||
| 262 | static const double PIo2[] = { | ||
| 263 | 1.57079625129699707031e+00, /* 0x3FF921FB, 0x40000000 */ | ||
| 264 | 7.54978941586159635335e-08, /* 0x3E74442D, 0x00000000 */ | ||
| 265 | 5.39030252995776476554e-15, /* 0x3CF84698, 0x80000000 */ | ||
| 266 | 3.28200341580791294123e-22, /* 0x3B78CC51, 0x60000000 */ | ||
| 267 | 1.27065575308067607349e-29, /* 0x39F01B83, 0x80000000 */ | ||
| 268 | 1.22933308981111328932e-36, /* 0x387A2520, 0x40000000 */ | ||
| 269 | 2.73370053816464559624e-44, /* 0x36E38222, 0x80000000 */ | ||
| 270 | 2.16741683877804819444e-51, /* 0x3569F31D, 0x00000000 */ | ||
| 271 | }; | ||
| 272 | |||
| 273 | int __rem_pio2_large(double *x, double *y, int e0, int nx, int prec) | ||
| 274 | { | ||
| 275 | 	int32_t jz,jx,jv,jp,jk,carry,n,iq[20],i,j,k,m,q0,ih; | ||
| 276 | 	double z,fw,f[20],fq[20],q[20]; | ||
| 277 | |||
| 278 | 	/* initialize jk*/ | ||
| 279 | 	jk = init_jk[prec]; | ||
| 280 | 	jp = jk; | ||
| 281 | |||
| 282 | 	/* determine jx,jv,q0, note that 3>q0 */ | ||
| 283 | 	jx = nx-1; | ||
| 284 | 	jv = (e0-3)/24; if(jv<0) jv=0; | ||
| 285 | 	q0 = e0-24*(jv+1); | ||
| 286 | |||
| 287 | 	/* set up f[0] to f[jx+jk] where f[jx+jk] = ipio2[jv+jk] */ | ||
| 288 | 	j = jv-jx; m = jx+jk; | ||
| 289 | 	for (i=0; i<=m; i++,j++) | ||
| 290 | 		f[i] = j<0 ? 0.0 : (double)ipio2[j]; | ||
| 291 | |||
| 292 | 	/* compute q[0],q[1],...q[jk] */ | ||
| 293 | 	for (i=0; i<=jk; i++) { | ||
| 294 | 		for (j=0,fw=0.0; j<=jx; j++) | ||
| 295 | 			fw += x[j]*f[jx+i-j]; | ||
| 296 | 		q[i] = fw; | ||
| 297 | 	} | ||
| 298 | |||
| 299 | 	jz = jk; | ||
| 300 | recompute: | ||
| 301 | 	/* distill q[] into iq[] reversingly */ | ||
| 302 | 	for (i=0,j=jz,z=q[jz]; j>0; i++,j--) { | ||
| 303 | 		fw = (double)(int32_t)(0x1p-24*z); | ||
| 304 | 		iq[i] = (int32_t)(z - 0x1p24*fw); | ||
| 305 | 		z = q[j-1]+fw; | ||
| 306 | 	} | ||
| 307 | |||
| 308 | 	/* compute n */ | ||
| 309 | 	z = scalbn(z,q0); /* actual value of z */ | ||
| 310 | 	z -= 8.0*floor(z*0.125); /* trim off integer >= 8 */ | ||
| 311 | 	n = (int32_t)z; | ||
| 312 | 	z -= (double)n; | ||
| 313 | 	ih = 0; | ||
| 314 | 	if (q0 > 0) { /* need iq[jz-1] to determine n */ | ||
| 315 | 		i = iq[jz-1]>>(24-q0); n += i; | ||
| 316 | 		iq[jz-1] -= i<<(24-q0); | ||
| 317 | 		ih = iq[jz-1]>>(23-q0); | ||
| 318 | 	} | ||
| 319 | 	else if (q0 == 0) ih = iq[jz-1]>>23; | ||
| 320 | 	else if (z >= 0.5) ih = 2; | ||
| 321 | |||
| 322 | 	if (ih > 0) { /* q > 0.5 */ | ||
| 323 | 		n += 1; carry = 0; | ||
| 324 | 		for (i=0; i<jz; i++) { /* compute 1-q */ | ||
| 325 | 			j = iq[i]; | ||
| 326 | 			if (carry == 0) { | ||
| 327 | 				if (j != 0) { | ||
| 328 | 					carry = 1; | ||
| 329 | 					iq[i] = 0x1000000 - j; | ||
| 330 | 				} | ||
| 331 | 			} else | ||
| 332 | 				iq[i] = 0xffffff - j; | ||
| 333 | 		} | ||
| 334 | 		if (q0 > 0) { /* rare case: chance is 1 in 12 */ | ||
| 335 | 			switch(q0) { | ||
| 336 | 			case 1: | ||
| 337 | 				iq[jz-1] &= 0x7fffff; break; | ||
| 338 | 			case 2: | ||
| 339 | 				iq[jz-1] &= 0x3fffff; break; | ||
| 340 | 			} | ||
| 341 | 		} | ||
| 342 | 		if (ih == 2) { | ||
| 343 | 			z = 1.0 - z; | ||
| 344 | 			if (carry != 0) | ||
| 345 | 				z -= scalbn(1.0,q0); | ||
| 346 | 		} | ||
| 347 | 	} | ||
| 348 | |||
| 349 | 	/* check if recomputation is needed */ | ||
| 350 | 	if (z == 0.0) { | ||
| 351 | 		j = 0; | ||
| 352 | 		for (i=jz-1; i>=jk; i--) j |= iq[i]; | ||
| 353 | 		if (j == 0) { /* need recomputation */ | ||
| 354 | 			for (k=1; iq[jk-k]==0; k++); /* k = no. of terms needed */ | ||
| 355 | |||
| 356 | 			for (i=jz+1; i<=jz+k; i++) { /* add q[jz+1] to q[jz+k] */ | ||
| 357 | 				f[jx+i] = (double)ipio2[jv+i]; | ||
| 358 | 				for (j=0,fw=0.0; j<=jx; j++) | ||
| 359 | 					fw += x[j]*f[jx+i-j]; | ||
| 360 | 				q[i] = fw; | ||
| 361 | 			} | ||
| 362 | 			jz += k; | ||
| 363 | 			goto recompute; | ||
| 364 | 		} | ||
| 365 | 	} | ||
| 366 | |||
| 367 | 	/* chop off zero terms */ | ||
| 368 | 	if (z == 0.0) { | ||
| 369 | 		jz -= 1; | ||
| 370 | 		q0 -= 24; | ||
| 371 | 		while (iq[jz] == 0) { | ||
| 372 | 			jz--; | ||
| 373 | 			q0 -= 24; | ||
| 374 | 		} | ||
| 375 | 	} else { /* break z into 24-bit if necessary */ | ||
| 376 | 		z = scalbn(z,-q0); | ||
| 377 | 		if (z >= 0x1p24) { | ||
| 378 | 			fw = (double)(int32_t)(0x1p-24*z); | ||
| 379 | 			iq[jz] = (int32_t)(z - 0x1p24*fw); | ||
| 380 | 			jz += 1; | ||
| 381 | 			q0 += 24; | ||
| 382 | 			iq[jz] = (int32_t)fw; | ||
| 383 | 		} else | ||
| 384 | 			iq[jz] = (int32_t)z; | ||
| 385 | 	} | ||
| 386 | |||
| 387 | 	/* convert integer "bit" chunk to floating-point value */ | ||
| 388 | 	fw = scalbn(1.0,q0); | ||
| 389 | 	for (i=jz; i>=0; i--) { | ||
| 390 | 		q[i] = fw*(double)iq[i]; | ||
| 391 | 		fw *= 0x1p-24; | ||
| 392 | 	} | ||
| 393 | |||
| 394 | 	/* compute PIo2[0,...,jp]*q[jz,...,0] */ | ||
| 395 | 	for(i=jz; i>=0; i--) { | ||
| 396 | 		for (fw=0.0,k=0; k<=jp && k<=jz-i; k++) | ||
| 397 | 			fw += PIo2[k]*q[i+k]; | ||
| 398 | 		fq[jz-i] = fw; | ||
| 399 | 	} | ||
| 400 | |||
| 401 | 	/* compress fq[] into y[] */ | ||
| 402 | 	switch(prec) { | ||
| 403 | 	case 0: | ||
| 404 | 		fw = 0.0; | ||
| 405 | 		for (i=jz; i>=0; i--) | ||
| 406 | 			fw += fq[i]; | ||
| 407 | 		y[0] = ih==0 ? fw : -fw; | ||
| 408 | 		break; | ||
| 409 | 	case 1: | ||
| 410 | 	case 2: | ||
| 411 | 		fw = 0.0; | ||
| 412 | 		for (i=jz; i>=0; i--) | ||
| 413 | 			fw += fq[i]; | ||
| 414 | 		// TODO: drop excess precision here once double_t is used | ||
| 415 | 		fw = (double)fw; | ||
| 416 | 		y[0] = ih==0 ? fw : -fw; | ||
| 417 | 		fw = fq[0]-fw; | ||
| 418 | 		for (i=1; i<=jz; i++) | ||
| 419 | 			fw += fq[i]; | ||
| 420 | 		y[1] = ih==0 ? fw : -fw; | ||
| 421 | 		break; | ||
| 422 | 	case 3: /* painful */ | ||
| 423 | 		for (i=jz; i>0; i--) { | ||
| 424 | 			fw = fq[i-1]+fq[i]; | ||
| 425 | 			fq[i] += fq[i-1]-fw; | ||
| 426 | 			fq[i-1] = fw; | ||
| 427 | 		} | ||
| 428 | 		for (i=jz; i>1; i--) { | ||
| 429 | 			fw = fq[i-1]+fq[i]; | ||
| 430 | 			fq[i] += fq[i-1]-fw; | ||
| 431 | 			fq[i-1] = fw; | ||
| 432 | 		} | ||
| 433 | 		for (fw=0.0,i=jz; i>=2; i--) | ||
| 434 | 			fw += fq[i]; | ||
| 435 | 		if (ih==0) { | ||
| 436 | 			y[0] = fq[0]; y[1] = fq[1]; y[2] = fw; | ||
| 437 | 		} else { | ||
| 438 | 			y[0] = -fq[0]; y[1] = -fq[1]; y[2] = -fw; | ||
| 439 | 		} | ||
| 440 | 	} | ||
| 441 | 	return n&7; | ||
| 442 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__rem_pio2f.c created+90| ... | @@ -0,0 +1,90 @@ | ||
| 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 created+159| ... | @@ -0,0 +1,159 @@ | ||
| 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/__signbit.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | // FIXME: macro in math.h | ||
| 4 | int __signbit(double x) | ||
| 5 | { | ||
| 6 | 	union { | ||
| 7 | 		double d; | ||
| 8 | 		uint64_t i; | ||
| 9 | 	} y = { x }; | ||
| 10 | 	return y.i>>63; | ||
| 11 | } | ||
| 12 | |||
| 13 | |||
lib/libc/wasi/libc-top-half/musl/src/math/__signbitf.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | // FIXME: macro in math.h | ||
| 4 | int __signbitf(float x) | ||
| 5 | { | ||
| 6 | 	union { | ||
| 7 | 		float f; | ||
| 8 | 		uint32_t i; | ||
| 9 | 	} y = { x }; | ||
| 10 | 	return y.i>>31; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__signbitl.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 4 | int __signbitl(long double x) | ||
| 5 | { | ||
| 6 | 	union ldshape u = {x}; | ||
| 7 | 	return u.i.se >> 15; | ||
| 8 | } | ||
| 9 | #elif LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 10 | int __signbitl(long double x) | ||
| 11 | { | ||
| 12 | 	return __signbit(x); | ||
| 13 | } | ||
| 14 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__sin.c created+64| ... | @@ -0,0 +1,64 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_sin.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 | /* __sin( x, y, iy) | ||
| 13 | * kernel sin function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 | ||
| 14 | * Input x is assumed to be bounded by ~pi/4 in magnitude. | ||
| 15 | * Input y is the tail of x. | ||
| 16 | * Input iy indicates whether y is 0. (if iy=0, y assume to be 0). | ||
| 17 | * | ||
| 18 | * Algorithm | ||
| 19 | * 1. Since sin(-x) = -sin(x), we need only to consider positive x. | ||
| 20 | * 2. Callers must return sin(-0) = -0 without calling here since our | ||
| 21 | * odd polynomial is not evaluated in a way that preserves -0. | ||
| 22 | * Callers may do the optimization sin(x) ~ x for tiny x. | ||
| 23 | * 3. sin(x) is approximated by a polynomial of degree 13 on | ||
| 24 | * [0,pi/4] | ||
| 25 | * 3 13 | ||
| 26 | * sin(x) ~ x + S1*x + ... + S6*x | ||
| 27 | * where | ||
| 28 | * | ||
| 29 | * |sin(x) 2 4 6 8 10 12 | -58 | ||
| 30 | * |----- - (1+S1*x +S2*x +S3*x +S4*x +S5*x +S6*x )| <= 2 | ||
| 31 | * | x | | ||
| 32 | * | ||
| 33 | * 4. sin(x+y) = sin(x) + sin'(x')*y | ||
| 34 | * ~ sin(x) + (1-x*x/2)*y | ||
| 35 | * For better accuracy, let | ||
| 36 | * 3 2 2 2 2 | ||
| 37 | * r = x *(S2+x *(S3+x *(S4+x *(S5+x *S6)))) | ||
| 38 | * then 3 2 | ||
| 39 | * sin(x) = x + (S1*x + (x *(r-y/2)+y)) | ||
| 40 | */ | ||
| 41 | |||
| 42 | #include "libm.h" | ||
| 43 | |||
| 44 | static const double | ||
| 45 | S1 = -1.66666666666666324348e-01, /* 0xBFC55555, 0x55555549 */ | ||
| 46 | S2 = 8.33333333332248946124e-03, /* 0x3F811111, 0x1110F8A6 */ | ||
| 47 | S3 = -1.98412698298579493134e-04, /* 0xBF2A01A0, 0x19C161D5 */ | ||
| 48 | S4 = 2.75573137070700676789e-06, /* 0x3EC71DE3, 0x57B1FE7D */ | ||
| 49 | S5 = -2.50507602534068634195e-08, /* 0xBE5AE5E6, 0x8A2B9CEB */ | ||
| 50 | S6 = 1.58969099521155010221e-10; /* 0x3DE5D93A, 0x5ACFD57C */ | ||
| 51 | |||
| 52 | double __sin(double x, double y, int iy) | ||
| 53 | { | ||
| 54 | 	double_t z,r,v,w; | ||
| 55 | |||
| 56 | 	z = x*x; | ||
| 57 | 	w = z*z; | ||
| 58 | 	r = S2 + z*(S3 + z*S4) + z*w*(S5 + z*S6); | ||
| 59 | 	v = z*x; | ||
| 60 | 	if (iy == 0) | ||
| 61 | 		return x + v*(S1 + z*r); | ||
| 62 | 	else | ||
| 63 | 		return x - ((z*(0.5*y - v*r) - y) - v*S1); | ||
| 64 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__sindf.c created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_sinf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * 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 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | /* |sin(x)/x - s(x)| < 2**-37.5 (~[-4.89e-12, 4.824e-12]). */ | ||
| 20 | static const double | ||
| 21 | S1 = -0x15555554cbac77.0p-55, /* -0.166666666416265235595 */ | ||
| 22 | S2 = 0x111110896efbb2.0p-59, /* 0.0083333293858894631756 */ | ||
| 23 | S3 = -0x1a00f9e2cae774.0p-65, /* -0.000198393348360966317347 */ | ||
| 24 | S4 = 0x16cd878c3b46a7.0p-71; /* 0.0000027183114939898219064 */ | ||
| 25 | |||
| 26 | float __sindf(double x) | ||
| 27 | { | ||
| 28 | 	double_t r, s, w, z; | ||
| 29 | |||
| 30 | 	/* Try to optimize for parallel evaluation as in __tandf.c. */ | ||
| 31 | 	z = x*x; | ||
| 32 | 	w = z*z; | ||
| 33 | 	r = S3 + z*S4; | ||
| 34 | 	s = z*x; | ||
| 35 | 	return (x + s*(S1 + z*S2)) + s*w*r; | ||
| 36 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__sinl.c created+78| ... | @@ -0,0 +1,78 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/ld80/k_sinl.c */ | ||
| 2 | /* origin: FreeBSD /usr/src/lib/msun/ld128/k_sinl.c */ | ||
| 3 | /* | ||
| 4 | * ==================================================== | ||
| 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 6 | * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. | ||
| 7 | * | ||
| 8 | * Developed at SunSoft, a Sun Microsystems, Inc. business. | ||
| 9 | * Permission to use, copy, modify, and distribute this | ||
| 10 | * software is freely granted, provided that this notice | ||
| 11 | * is preserved. | ||
| 12 | * ==================================================== | ||
| 13 | */ | ||
| 14 | |||
| 15 | #include "libm.h" | ||
| 16 | |||
| 17 | #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 18 | #if LDBL_MANT_DIG == 64 | ||
| 19 | /* | ||
| 20 | * ld80 version of __sin.c. See __sin.c for most comments. | ||
| 21 | */ | ||
| 22 | /* | ||
| 23 | * Domain [-0.7854, 0.7854], range ~[-1.89e-22, 1.915e-22] | ||
| 24 | * |sin(x)/x - s(x)| < 2**-72.1 | ||
| 25 | * | ||
| 26 | * See __cosl.c for more details about the polynomial. | ||
| 27 | */ | ||
| 28 | static const long double | ||
| 29 | S1 = -0.166666666666666666671L; /* -0xaaaaaaaaaaaaaaab.0p-66 */ | ||
| 30 | static const double | ||
| 31 | S2 = 0.0083333333333333332, /* 0x11111111111111.0p-59 */ | ||
| 32 | S3 = -0.00019841269841269427, /* -0x1a01a01a019f81.0p-65 */ | ||
| 33 | S4 = 0.0000027557319223597490, /* 0x171de3a55560f7.0p-71 */ | ||
| 34 | S5 = -0.000000025052108218074604, /* -0x1ae64564f16cad.0p-78 */ | ||
| 35 | S6 = 1.6059006598854211e-10, /* 0x161242b90243b5.0p-85 */ | ||
| 36 | S7 = -7.6429779983024564e-13, /* -0x1ae42ebd1b2e00.0p-93 */ | ||
| 37 | S8 = 2.6174587166648325e-15; /* 0x179372ea0b3f64.0p-101 */ | ||
| 38 | #define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*S8)))))) | ||
| 39 | #elif LDBL_MANT_DIG == 113 | ||
| 40 | /* | ||
| 41 | * ld128 version of __sin.c. See __sin.c for most comments. | ||
| 42 | */ | ||
| 43 | /* | ||
| 44 | * Domain [-0.7854, 0.7854], range ~[-1.53e-37, 1.659e-37] | ||
| 45 | * |sin(x)/x - s(x)| < 2**-122.1 | ||
| 46 | * | ||
| 47 | * See __cosl.c for more details about the polynomial. | ||
| 48 | */ | ||
| 49 | static const long double | ||
| 50 | S1 = -0.16666666666666666666666666666666666606732416116558L, | ||
| 51 | S2 = 0.0083333333333333333333333333333331135404851288270047L, | ||
| 52 | S3 = -0.00019841269841269841269841269839935785325638310428717L, | ||
| 53 | S4 = 0.27557319223985890652557316053039946268333231205686e-5L, | ||
| 54 | S5 = -0.25052108385441718775048214826384312253862930064745e-7L, | ||
| 55 | S6 = 0.16059043836821614596571832194524392581082444805729e-9L, | ||
| 56 | S7 = -0.76471637318198151807063387954939213287488216303768e-12L, | ||
| 57 | S8 = 0.28114572543451292625024967174638477283187397621303e-14L; | ||
| 58 | static const double | ||
| 59 | S9 = -0.82206352458348947812512122163446202498005154296863e-17, | ||
| 60 | S10 = 0.19572940011906109418080609928334380560135358385256e-19, | ||
| 61 | S11 = -0.38680813379701966970673724299207480965452616911420e-22, | ||
| 62 | S12 = 0.64038150078671872796678569586315881020659912139412e-25; | ||
| 63 | #define POLY(z) (S2+z*(S3+z*(S4+z*(S5+z*(S6+z*(S7+z*(S8+ \ | ||
| 64 | 	z*(S9+z*(S10+z*(S11+z*S12)))))))))) | ||
| 65 | #endif | ||
| 66 | |||
| 67 | long double __sinl(long double x, long double y, int iy) | ||
| 68 | { | ||
| 69 | 	long double z,r,v; | ||
| 70 | |||
| 71 | 	z = x*x; | ||
| 72 | 	v = z*x; | ||
| 73 | 	r = POLY(z); | ||
| 74 | 	if (iy == 0) | ||
| 75 | 		return x+v*(S1+z*r); | ||
| 76 | 	return x-((z*(0.5*y-v*r)-y)-v*S1); | ||
| 77 | } | ||
| 78 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/__tan.c created+110| ... | @@ -0,0 +1,110 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_tan.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. | ||
| 5 | * | ||
| 6 | * Permission to use, copy, modify, and distribute this | ||
| 7 | * software is freely granted, provided that this notice | ||
| 8 | * is preserved. | ||
| 9 | * ==================================================== | ||
| 10 | */ | ||
| 11 | /* __tan( x, y, k ) | ||
| 12 | * kernel tan function on ~[-pi/4, pi/4] (except on -0), pi/4 ~ 0.7854 | ||
| 13 | * Input x is assumed to be bounded by ~pi/4 in magnitude. | ||
| 14 | * Input y is the tail of x. | ||
| 15 | * Input odd indicates whether tan (if odd = 0) or -1/tan (if odd = 1) is returned. | ||
| 16 | * | ||
| 17 | * Algorithm | ||
| 18 | * 1. Since tan(-x) = -tan(x), we need only to consider positive x. | ||
| 19 | * 2. Callers must return tan(-0) = -0 without calling here since our | ||
| 20 | * odd polynomial is not evaluated in a way that preserves -0. | ||
| 21 | * Callers may do the optimization tan(x) ~ x for tiny x. | ||
| 22 | * 3. tan(x) is approximated by a odd polynomial of degree 27 on | ||
| 23 | * [0,0.67434] | ||
| 24 | * 3 27 | ||
| 25 | * tan(x) ~ x + T1*x + ... + T13*x | ||
| 26 | * where | ||
| 27 | * | ||
| 28 | * |tan(x) 2 4 26 | -59.2 | ||
| 29 | * |----- - (1+T1*x +T2*x +.... +T13*x )| <= 2 | ||
| 30 | * | x | | ||
| 31 | * | ||
| 32 | * Note: tan(x+y) = tan(x) + tan'(x)*y | ||
| 33 | * ~ tan(x) + (1+x*x)*y | ||
| 34 | * Therefore, for better accuracy in computing tan(x+y), let | ||
| 35 | * 3 2 2 2 2 | ||
| 36 | * r = x *(T2+x *(T3+x *(...+x *(T12+x *T13)))) | ||
| 37 | * then | ||
| 38 | * 3 2 | ||
| 39 | * tan(x+y) = x + (T1*x + (x *(r+y)+y)) | ||
| 40 | * | ||
| 41 | * 4. For x in [0.67434,pi/4], let y = pi/4 - x, then | ||
| 42 | * tan(x) = tan(pi/4-y) = (1-tan(y))/(1+tan(y)) | ||
| 43 | * = 1 - 2*(tan(y) - (tan(y)^2)/(1+tan(y))) | ||
| 44 | */ | ||
| 45 | |||
| 46 | #include "libm.h" | ||
| 47 | |||
| 48 | static const double T[] = { | ||
| 49 | 3.33333333333334091986e-01, /* 3FD55555, 55555563 */ | ||
| 50 | 1.33333333333201242699e-01, /* 3FC11111, 1110FE7A */ | ||
| 51 | 5.39682539762260521377e-02, /* 3FABA1BA, 1BB341FE */ | ||
| 52 | 2.18694882948595424599e-02, /* 3F9664F4, 8406D637 */ | ||
| 53 | 8.86323982359930005737e-03, /* 3F8226E3, E96E8493 */ | ||
| 54 | 3.59207910759131235356e-03, /* 3F6D6D22, C9560328 */ | ||
| 55 | 1.45620945432529025516e-03, /* 3F57DBC8, FEE08315 */ | ||
| 56 | 5.88041240820264096874e-04, /* 3F4344D8, F2F26501 */ | ||
| 57 | 2.46463134818469906812e-04, /* 3F3026F7, 1A8D1068 */ | ||
| 58 | 7.81794442939557092300e-05, /* 3F147E88, A03792A6 */ | ||
| 59 | 7.14072491382608190305e-05, /* 3F12B80F, 32F0A7E9 */ | ||
| 60 | -1.85586374855275456654e-05, /* BEF375CB, DB605373 */ | ||
| 61 | 2.59073051863633712884e-05, /* 3EFB2A70, 74BF7AD4 */ | ||
| 62 | }, | ||
| 63 | pio4 = 7.85398163397448278999e-01, /* 3FE921FB, 54442D18 */ | ||
| 64 | pio4lo = 3.06161699786838301793e-17; /* 3C81A626, 33145C07 */ | ||
| 65 | |||
| 66 | double __tan(double x, double y, int odd) | ||
| 67 | { | ||
| 68 | 	double_t z, r, v, w, s, a; | ||
| 69 | 	double w0, a0; | ||
| 70 | 	uint32_t hx; | ||
| 71 | 	int big, sign; | ||
| 72 | |||
| 73 | 	GET_HIGH_WORD(hx,x); | ||
| 74 | 	big = (hx&0x7fffffff) >= 0x3FE59428; /* |x| >= 0.6744 */ | ||
| 75 | 	if (big) { | ||
| 76 | 		sign = hx>>31; | ||
| 77 | 		if (sign) { | ||
| 78 | 			x = -x; | ||
| 79 | 			y = -y; | ||
| 80 | 		} | ||
| 81 | 		x = (pio4 - x) + (pio4lo - y); | ||
| 82 | 		y = 0.0; | ||
| 83 | 	} | ||
| 84 | 	z = x * x; | ||
| 85 | 	w = z * z; | ||
| 86 | 	/* | ||
| 87 | 	 * Break x^5*(T[1]+x^2*T[2]+...) into | ||
| 88 | 	 * x^5(T[1]+x^4*T[3]+...+x^20*T[11]) + | ||
| 89 | 	 * x^5(x^2*(T[2]+x^4*T[4]+...+x^22*[T12])) | ||
| 90 | 	 */ | ||
| 91 | 	r = T[1] + w*(T[3] + w*(T[5] + w*(T[7] + w*(T[9] + w*T[11])))); | ||
| 92 | 	v = z*(T[2] + w*(T[4] + w*(T[6] + w*(T[8] + w*(T[10] + w*T[12]))))); | ||
| 93 | 	s = z * x; | ||
| 94 | 	r = y + z*(s*(r + v) + y) + s*T[0]; | ||
| 95 | 	w = x + r; | ||
| 96 | 	if (big) { | ||
| 97 | 		s = 1 - 2*odd; | ||
| 98 | 		v = s - 2.0 * (x + (r - w*w/(w + s))); | ||
| 99 | 		return sign ? -v : v; | ||
| 100 | 	} | ||
| 101 | 	if (!odd) | ||
| 102 | 		return w; | ||
| 103 | 	/* -1.0/(x+r) has up to 2ulp error, so compute it accurately */ | ||
| 104 | 	w0 = w; | ||
| 105 | 	SET_LOW_WORD(w0, 0); | ||
| 106 | 	v = r - (w0 - x); /* w0+v = r+x */ | ||
| 107 | 	a0 = a = -1.0 / w; | ||
| 108 | 	SET_LOW_WORD(a0, 0); | ||
| 109 | 	return a0 + a*(1.0 + a0*w0 + a0*v); | ||
| 110 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__tandf.c created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/k_tanf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * Optimized by Bruce D. Evans. | ||
| 5 | */ | ||
| 6 | /* | ||
| 7 | * ==================================================== | ||
| 8 | * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. | ||
| 9 | * | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | /* |tan(x)/x - t(x)| < 2**-25.5 (~[-2e-08, 2e-08]). */ | ||
| 19 | static const double T[] = { | ||
| 20 | 0x15554d3418c99f.0p-54, /* 0.333331395030791399758 */ | ||
| 21 | 0x1112fd38999f72.0p-55, /* 0.133392002712976742718 */ | ||
| 22 | 0x1b54c91d865afe.0p-57, /* 0.0533812378445670393523 */ | ||
| 23 | 0x191df3908c33ce.0p-58, /* 0.0245283181166547278873 */ | ||
| 24 | 0x185dadfcecf44e.0p-61, /* 0.00297435743359967304927 */ | ||
| 25 | 0x1362b9bf971bcd.0p-59, /* 0.00946564784943673166728 */ | ||
| 26 | }; | ||
| 27 | |||
| 28 | float __tandf(double x, int odd) | ||
| 29 | { | ||
| 30 | 	double_t z,r,w,s,t,u; | ||
| 31 | |||
| 32 | 	z = x*x; | ||
| 33 | 	/* | ||
| 34 | 	 * Split up the polynomial into small independent terms to give | ||
| 35 | 	 * opportunities for parallel evaluation. The chosen splitting is | ||
| 36 | 	 * micro-optimized for Athlons (XP, X64). It costs 2 multiplications | ||
| 37 | 	 * relative to Horner's method on sequential machines. | ||
| 38 | 	 * | ||
| 39 | 	 * We add the small terms from lowest degree up for efficiency on | ||
| 40 | 	 * non-sequential machines (the lowest degree terms tend to be ready | ||
| 41 | 	 * earlier). Apart from this, we don't care about order of | ||
| 42 | 	 * operations, and don't need to to care since we have precision to | ||
| 43 | 	 * spare. However, the chosen splitting is good for accuracy too, | ||
| 44 | 	 * and would give results as accurate as Horner's method if the | ||
| 45 | 	 * small terms were added from highest degree down. | ||
| 46 | 	 */ | ||
| 47 | 	r = T[4] + z*T[5]; | ||
| 48 | 	t = T[2] + z*T[3]; | ||
| 49 | 	w = z*z; | ||
| 50 | 	s = z*x; | ||
| 51 | 	u = T[0] + z*T[1]; | ||
| 52 | 	r = (x + s*u) + (s*w)*(t + w*r); | ||
| 53 | 	return odd ? -1.0/r : r; | ||
| 54 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/__tanl.c created+143| ... | @@ -0,0 +1,143 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/ld80/k_tanl.c */ | ||
| 2 | /* origin: FreeBSD /usr/src/lib/msun/ld128/k_tanl.c */ | ||
| 3 | /* | ||
| 4 | * ==================================================== | ||
| 5 | * Copyright 2004 Sun Microsystems, Inc. All Rights Reserved. | ||
| 6 | * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans. | ||
| 7 | * | ||
| 8 | * Permission to use, copy, modify, and distribute this | ||
| 9 | * software is freely granted, provided that this notice | ||
| 10 | * is preserved. | ||
| 11 | * ==================================================== | ||
| 12 | */ | ||
| 13 | |||
| 14 | #include "libm.h" | ||
| 15 | |||
| 16 | #if (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 17 | #if LDBL_MANT_DIG == 64 | ||
| 18 | /* | ||
| 19 | * ld80 version of __tan.c. See __tan.c for most comments. | ||
| 20 | */ | ||
| 21 | /* | ||
| 22 | * Domain [-0.67434, 0.67434], range ~[-2.25e-22, 1.921e-22] | ||
| 23 | * |tan(x)/x - t(x)| < 2**-71.9 | ||
| 24 | * | ||
| 25 | * See __cosl.c for more details about the polynomial. | ||
| 26 | */ | ||
| 27 | static const long double | ||
| 28 | T3 = 0.333333333333333333180L, /* 0xaaaaaaaaaaaaaaa5.0p-65 */ | ||
| 29 | T5 = 0.133333333333333372290L, /* 0x88888888888893c3.0p-66 */ | ||
| 30 | T7 = 0.0539682539682504975744L, /* 0xdd0dd0dd0dc13ba2.0p-68 */ | ||
| 31 | pio4 = 0.785398163397448309628L, /* 0xc90fdaa22168c235.0p-64 */ | ||
| 32 | pio4lo = -1.25413940316708300586e-20L; /* -0xece675d1fc8f8cbb.0p-130 */ | ||
| 33 | static const double | ||
| 34 | T9 = 0.021869488536312216, /* 0x1664f4882cc1c2.0p-58 */ | ||
| 35 | T11 = 0.0088632355256619590, /* 0x1226e355c17612.0p-59 */ | ||
| 36 | T13 = 0.0035921281113786528, /* 0x1d6d3d185d7ff8.0p-61 */ | ||
| 37 | T15 = 0.0014558334756312418, /* 0x17da354aa3f96b.0p-62 */ | ||
| 38 | T17 = 0.00059003538700862256, /* 0x13559358685b83.0p-63 */ | ||
| 39 | T19 = 0.00023907843576635544, /* 0x1f56242026b5be.0p-65 */ | ||
| 40 | T21 = 0.000097154625656538905, /* 0x1977efc26806f4.0p-66 */ | ||
| 41 | T23 = 0.000038440165747303162, /* 0x14275a09b3ceac.0p-67 */ | ||
| 42 | T25 = 0.000018082171885432524, /* 0x12f5e563e5487e.0p-68 */ | ||
| 43 | T27 = 0.0000024196006108814377, /* 0x144c0d80cc6896.0p-71 */ | ||
| 44 | T29 = 0.0000078293456938132840, /* 0x106b59141a6cb3.0p-69 */ | ||
| 45 | T31 = -0.0000032609076735050182, /* -0x1b5abef3ba4b59.0p-71 */ | ||
| 46 | T33 = 0.0000023261313142559411; /* 0x13835436c0c87f.0p-71 */ | ||
| 47 | #define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \ | ||
| 48 | 	w * (T25 + w * (T29 + w * T33))))))) | ||
| 49 | #define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \ | ||
| 50 | 	w * (T27 + w * T31)))))) | ||
| 51 | #elif LDBL_MANT_DIG == 113 | ||
| 52 | /* | ||
| 53 | * ld128 version of __tan.c. See __tan.c for most comments. | ||
| 54 | */ | ||
| 55 | /* | ||
| 56 | * Domain [-0.67434, 0.67434], range ~[-3.37e-36, 1.982e-37] | ||
| 57 | * |tan(x)/x - t(x)| < 2**-117.8 (XXX should be ~1e-37) | ||
| 58 | * | ||
| 59 | * See __cosl.c for more details about the polynomial. | ||
| 60 | */ | ||
| 61 | static const long double | ||
| 62 | T3 = 0x1.5555555555555555555555555553p-2L, | ||
| 63 | T5 = 0x1.1111111111111111111111111eb5p-3L, | ||
| 64 | T7 = 0x1.ba1ba1ba1ba1ba1ba1ba1b694cd6p-5L, | ||
| 65 | T9 = 0x1.664f4882c10f9f32d6bbe09d8bcdp-6L, | ||
| 66 | T11 = 0x1.226e355e6c23c8f5b4f5762322eep-7L, | ||
| 67 | T13 = 0x1.d6d3d0e157ddfb5fed8e84e27b37p-9L, | ||
| 68 | T15 = 0x1.7da36452b75e2b5fce9ee7c2c92ep-10L, | ||
| 69 | T17 = 0x1.355824803674477dfcf726649efep-11L, | ||
| 70 | T19 = 0x1.f57d7734d1656e0aceb716f614c2p-13L, | ||
| 71 | T21 = 0x1.967e18afcb180ed942dfdc518d6cp-14L, | ||
| 72 | T23 = 0x1.497d8eea21e95bc7e2aa79b9f2cdp-15L, | ||
| 73 | T25 = 0x1.0b132d39f055c81be49eff7afd50p-16L, | ||
| 74 | T27 = 0x1.b0f72d33eff7bfa2fbc1059d90b6p-18L, | ||
| 75 | T29 = 0x1.5ef2daf21d1113df38d0fbc00267p-19L, | ||
| 76 | T31 = 0x1.1c77d6eac0234988cdaa04c96626p-20L, | ||
| 77 | T33 = 0x1.cd2a5a292b180e0bdd701057dfe3p-22L, | ||
| 78 | T35 = 0x1.75c7357d0298c01a31d0a6f7d518p-23L, | ||
| 79 | T37 = 0x1.2f3190f4718a9a520f98f50081fcp-24L, | ||
| 80 | pio4 = 0x1.921fb54442d18469898cc51701b8p-1L, | ||
| 81 | pio4lo = 0x1.cd129024e088a67cc74020bbea60p-116L; | ||
| 82 | static const double | ||
| 83 | T39 = 0.000000028443389121318352,	/* 0x1e8a7592977938.0p-78 */ | ||
| 84 | T41 = 0.000000011981013102001973,	/* 0x19baa1b1223219.0p-79 */ | ||
| 85 | T43 = 0.0000000038303578044958070,	/* 0x107385dfb24529.0p-80 */ | ||
| 86 | T45 = 0.0000000034664378216909893,	/* 0x1dc6c702a05262.0p-81 */ | ||
| 87 | T47 = -0.0000000015090641701997785,	/* -0x19ecef3569ebb6.0p-82 */ | ||
| 88 | T49 = 0.0000000029449552300483952,	/* 0x194c0668da786a.0p-81 */ | ||
| 89 | T51 = -0.0000000022006995706097711,	/* -0x12e763b8845268.0p-81 */ | ||
| 90 | T53 = 0.0000000015468200913196612,	/* 0x1a92fc98c29554.0p-82 */ | ||
| 91 | T55 = -0.00000000061311613386849674,	/* -0x151106cbc779a9.0p-83 */ | ||
| 92 | T57 = 1.4912469681508012e-10;		/* 0x147edbdba6f43a.0p-85 */ | ||
| 93 | #define RPOLY(w) (T5 + w * (T9 + w * (T13 + w * (T17 + w * (T21 + \ | ||
| 94 | 	w * (T25 + w * (T29 + w * (T33 + w * (T37 + w * (T41 + \ | ||
| 95 | 	w * (T45 + w * (T49 + w * (T53 + w * T57))))))))))))) | ||
| 96 | #define VPOLY(w) (T7 + w * (T11 + w * (T15 + w * (T19 + w * (T23 + \ | ||
| 97 | 	w * (T27 + w * (T31 + w * (T35 + w * (T39 + w * (T43 + \ | ||
| 98 | 	w * (T47 + w * (T51 + w * T55)))))))))))) | ||
| 99 | #endif | ||
| 100 | |||
| 101 | long double __tanl(long double x, long double y, int odd) { | ||
| 102 | 	long double z, r, v, w, s, a, t; | ||
| 103 | 	int big, sign; | ||
| 104 | |||
| 105 | 	big = fabsl(x) >= 0.67434; | ||
| 106 | 	if (big) { | ||
| 107 | 		sign = 0; | ||
| 108 | 		if (x < 0) { | ||
| 109 | 			sign = 1; | ||
| 110 | 			x = -x; | ||
| 111 | 			y = -y; | ||
| 112 | 		} | ||
| 113 | 		x = (pio4 - x) + (pio4lo - y); | ||
| 114 | 		y = 0.0; | ||
| 115 | 	} | ||
| 116 | 	z = x * x; | ||
| 117 | 	w = z * z; | ||
| 118 | 	r = RPOLY(w); | ||
| 119 | 	v = z * VPOLY(w); | ||
| 120 | 	s = z * x; | ||
| 121 | 	r = y + z * (s * (r + v) + y) + T3 * s; | ||
| 122 | 	w = x + r; | ||
| 123 | 	if (big) { | ||
| 124 | 		s = 1 - 2*odd; | ||
| 125 | 		v = s - 2.0 * (x + (r - w * w / (w + s))); | ||
| 126 | 		return sign ? -v : v; | ||
| 127 | 	} | ||
| 128 | 	if (!odd) | ||
| 129 | 		return w; | ||
| 130 | 	/* | ||
| 131 | 	 * if allow error up to 2 ulp, simply return | ||
| 132 | 	 * -1.0 / (x+r) here | ||
| 133 | 	 */ | ||
| 134 | 	/* compute -1.0 / (x+r) accurately */ | ||
| 135 | 	z = w; | ||
| 136 | 	z = z + 0x1p32 - 0x1p32; | ||
| 137 | 	v = r - (z - x); /* z+v = r+x */ | ||
| 138 | 	t = a = -1.0 / w; /* a = -1.0/w */ | ||
| 139 | 	t = t + 0x1p32 - 0x1p32; | ||
| 140 | 	s = 1.0 + t * z; | ||
| 141 | 	return t + a * (s + t * v); | ||
| 142 | } | ||
| 143 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/ceil.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double ceil(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintp %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/ceilf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float ceilf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintp %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fabs.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fabs(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fabsf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fabsf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/floor.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double floor(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintm %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/floorf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float floorf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintm %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fma.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fma(double x, double y, double z) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fmadd %d0, %d1, %d2, %d3" : "=w"(x) : "w"(x), "w"(y), "w"(z)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmaf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fmaf(float x, float y, float z) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fmadd %s0, %s1, %s2, %s3" : "=w"(x) : "w"(x), "w"(y), "w"(z)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmax.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fmax(double x, double y) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fmaxnm %d0, %d1, %d2" : "=w"(x) : "w"(x), "w"(y)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmaxf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fmaxf(float x, float y) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fmaxnm %s0, %s1, %s2" : "=w"(x) : "w"(x), "w"(y)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fmin.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fmin(double x, double y) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fminnm %d0, %d1, %d2" : "=w"(x) : "w"(x), "w"(y)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/fminf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fminf(float x, float y) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fminnm %s0, %s1, %s2" : "=w"(x) : "w"(x), "w"(y)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llrint.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrint(double x) | ||
| 4 | { | ||
| 5 | 	long long n; | ||
| 6 | 	__asm__ ( | ||
| 7 | 		"frintx %d1, %d1\n" | ||
| 8 | 		"fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x)); | ||
| 9 | 	return n; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llrintf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrintf(float x) | ||
| 4 | { | ||
| 5 | 	long long n; | ||
| 6 | 	__asm__ ( | ||
| 7 | 		"frintx %s1, %s1\n" | ||
| 8 | 		"fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x)); | ||
| 9 | 	return n; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llround.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llround(double x) | ||
| 4 | { | ||
| 5 | 	long long n; | ||
| 6 | 	__asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x)); | ||
| 7 | 	return n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/llroundf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llroundf(float x) | ||
| 4 | { | ||
| 5 | 	long long n; | ||
| 6 | 	__asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x)); | ||
| 7 | 	return n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lrint.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrint(double x) | ||
| 4 | { | ||
| 5 | 	long n; | ||
| 6 | 	__asm__ ( | ||
| 7 | 		"frintx %d1, %d1\n" | ||
| 8 | 		"fcvtzs %x0, %d1\n" : "=r"(n), "+w"(x)); | ||
| 9 | 	return n; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lrintf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrintf(float x) | ||
| 4 | { | ||
| 5 | 	long n; | ||
| 6 | 	__asm__ ( | ||
| 7 | 		"frintx %s1, %s1\n" | ||
| 8 | 		"fcvtzs %x0, %s1\n" : "=r"(n), "+w"(x)); | ||
| 9 | 	return n; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lround.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lround(double x) | ||
| 4 | { | ||
| 5 | 	long n; | ||
| 6 | 	__asm__ ("fcvtas %x0, %d1" : "=r"(n) : "w"(x)); | ||
| 7 | 	return n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/lroundf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lroundf(float x) | ||
| 4 | { | ||
| 5 | 	long n; | ||
| 6 | 	__asm__ ("fcvtas %x0, %s1" : "=r"(n) : "w"(x)); | ||
| 7 | 	return n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/nearbyint.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double nearbyint(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frinti %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/nearbyintf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float nearbyintf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frinti %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/rint.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double rint(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintx %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/rintf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float rintf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintx %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/round.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double round(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frinta %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/roundf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float roundf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frinta %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/sqrt.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double sqrt(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fsqrt %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/sqrtf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float sqrtf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fsqrt %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/trunc.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double trunc(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintz %d0, %d1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/aarch64/truncf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float truncf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frintz %s0, %s1" : "=w"(x) : "w"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/acos.c created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_acos.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 | /* acos(x) | ||
| 13 | * Method : | ||
| 14 | * acos(x) = pi/2 - asin(x) | ||
| 15 | * acos(-x) = pi/2 + asin(x) | ||
| 16 | * For |x|<=0.5 | ||
| 17 | * acos(x) = pi/2 - (x + x*x^2*R(x^2)) (see asin.c) | ||
| 18 | * For x>0.5 | ||
| 19 | * acos(x) = pi/2 - (pi/2 - 2asin(sqrt((1-x)/2))) | ||
| 20 | * = 2asin(sqrt((1-x)/2)) | ||
| 21 | * = 2s + 2s*z*R(z) ...z=(1-x)/2, s=sqrt(z) | ||
| 22 | * = 2f + (2c + 2s*z*R(z)) | ||
| 23 | * where f=hi part of s, and c = (z-f*f)/(s+f) is the correction term | ||
| 24 | * for f so that f+c ~ sqrt(z). | ||
| 25 | * For x<-0.5 | ||
| 26 | * acos(x) = pi - 2asin(sqrt((1-|x|)/2)) | ||
| 27 | * = pi - 0.5*(s+s*z*R(z)), where z=(1-|x|)/2,s=sqrt(z) | ||
| 28 | * | ||
| 29 | * Special cases: | ||
| 30 | * if x is NaN, return x itself; | ||
| 31 | * if |x|>1, return NaN with invalid signal. | ||
| 32 | * | ||
| 33 | * Function needed: sqrt | ||
| 34 | */ | ||
| 35 | |||
| 36 | #include "libm.h" | ||
| 37 | |||
| 38 | static const double | ||
| 39 | pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ | ||
| 40 | pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ | ||
| 41 | pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ | ||
| 42 | pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ | ||
| 43 | pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ | ||
| 44 | pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ | ||
| 45 | pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ | ||
| 46 | pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ | ||
| 47 | qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ | ||
| 48 | qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ | ||
| 49 | qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ | ||
| 50 | qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ | ||
| 51 | |||
| 52 | static double R(double z) | ||
| 53 | { | ||
| 54 | 	double_t p, q; | ||
| 55 | 	p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); | ||
| 56 | 	q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*qS4))); | ||
| 57 | 	return p/q; | ||
| 58 | } | ||
| 59 | |||
| 60 | double acos(double x) | ||
| 61 | { | ||
| 62 | 	double z,w,s,c,df; | ||
| 63 | 	uint32_t hx,ix; | ||
| 64 | |||
| 65 | 	GET_HIGH_WORD(hx, x); | ||
| 66 | 	ix = hx & 0x7fffffff; | ||
| 67 | 	/* |x| >= 1 or nan */ | ||
| 68 | 	if (ix >= 0x3ff00000) { | ||
| 69 | 		uint32_t lx; | ||
| 70 | |||
| 71 | 		GET_LOW_WORD(lx,x); | ||
| 72 | 		if ((ix-0x3ff00000 | lx) == 0) { | ||
| 73 | 			/* acos(1)=0, acos(-1)=pi */ | ||
| 74 | 			if (hx >> 31) | ||
| 75 | 				return 2*pio2_hi + 0x1p-120f; | ||
| 76 | 			return 0; | ||
| 77 | 		} | ||
| 78 | 		return 0/(x-x); | ||
| 79 | 	} | ||
| 80 | 	/* |x| < 0.5 */ | ||
| 81 | 	if (ix < 0x3fe00000) { | ||
| 82 | 		if (ix <= 0x3c600000) /* |x| < 2**-57 */ | ||
| 83 | 			return pio2_hi + 0x1p-120f; | ||
| 84 | 		return pio2_hi - (x - (pio2_lo-x*R(x*x))); | ||
| 85 | 	} | ||
| 86 | 	/* x < -0.5 */ | ||
| 87 | 	if (hx >> 31) { | ||
| 88 | 		z = (1.0+x)*0.5; | ||
| 89 | 		s = sqrt(z); | ||
| 90 | 		w = R(z)*s-pio2_lo; | ||
| 91 | 		return 2*(pio2_hi - (s+w)); | ||
| 92 | 	} | ||
| 93 | 	/* x > 0.5 */ | ||
| 94 | 	z = (1.0-x)*0.5; | ||
| 95 | 	s = sqrt(z); | ||
| 96 | 	df = s; | ||
| 97 | 	SET_LOW_WORD(df,0); | ||
| 98 | 	c = (z-df*df)/(s+df); | ||
| 99 | 	w = R(z)*s+c; | ||
| 100 | 	return 2*(df+w); | ||
| 101 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/acosf.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_acosf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | static const float | ||
| 19 | pio2_hi = 1.5707962513e+00, /* 0x3fc90fda */ | ||
| 20 | pio2_lo = 7.5497894159e-08, /* 0x33a22168 */ | ||
| 21 | pS0 = 1.6666586697e-01, | ||
| 22 | pS1 = -4.2743422091e-02, | ||
| 23 | pS2 = -8.6563630030e-03, | ||
| 24 | qS1 = -7.0662963390e-01; | ||
| 25 | |||
| 26 | static float R(float z) | ||
| 27 | { | ||
| 28 | 	float_t p, q; | ||
| 29 | 	p = z*(pS0+z*(pS1+z*pS2)); | ||
| 30 | 	q = 1.0f+z*qS1; | ||
| 31 | 	return p/q; | ||
| 32 | } | ||
| 33 | |||
| 34 | float acosf(float x) | ||
| 35 | { | ||
| 36 | 	float z,w,s,c,df; | ||
| 37 | 	uint32_t hx,ix; | ||
| 38 | |||
| 39 | 	GET_FLOAT_WORD(hx, x); | ||
| 40 | 	ix = hx & 0x7fffffff; | ||
| 41 | 	/* |x| >= 1 or nan */ | ||
| 42 | 	if (ix >= 0x3f800000) { | ||
| 43 | 		if (ix == 0x3f800000) { | ||
| 44 | 			if (hx >> 31) | ||
| 45 | 				return 2*pio2_hi + 0x1p-120f; | ||
| 46 | 			return 0; | ||
| 47 | 		} | ||
| 48 | 		return 0/(x-x); | ||
| 49 | 	} | ||
| 50 | 	/* |x| < 0.5 */ | ||
| 51 | 	if (ix < 0x3f000000) { | ||
| 52 | 		if (ix <= 0x32800000) /* |x| < 2**-26 */ | ||
| 53 | 			return pio2_hi + 0x1p-120f; | ||
| 54 | 		return pio2_hi - (x - (pio2_lo-x*R(x*x))); | ||
| 55 | 	} | ||
| 56 | 	/* x < -0.5 */ | ||
| 57 | 	if (hx >> 31) { | ||
| 58 | 		z = (1+x)*0.5f; | ||
| 59 | 		s = sqrtf(z); | ||
| 60 | 		w = R(z)*s-pio2_lo; | ||
| 61 | 		return 2*(pio2_hi - (s+w)); | ||
| 62 | 	} | ||
| 63 | 	/* x > 0.5 */ | ||
| 64 | 	z = (1-x)*0.5f; | ||
| 65 | 	s = sqrtf(z); | ||
| 66 | 	GET_FLOAT_WORD(hx,s); | ||
| 67 | 	SET_FLOAT_WORD(df,hx&0xfffff000); | ||
| 68 | 	c = (z-df*df)/(s+df); | ||
| 69 | 	w = R(z)*s+c; | ||
| 70 | 	return 2*(df+w); | ||
| 71 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/acosh.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if FLT_EVAL_METHOD==2 | ||
| 4 | #undef sqrt | ||
| 5 | #define sqrt sqrtl | ||
| 6 | #endif | ||
| 7 | |||
| 8 | /* acosh(x) = log(x + sqrt(x*x-1)) */ | ||
| 9 | double acosh(double x) | ||
| 10 | { | ||
| 11 | 	union {double f; uint64_t i;} u = {.f = x}; | ||
| 12 | 	unsigned e = u.i >> 52 & 0x7ff; | ||
| 13 | |||
| 14 | 	/* x < 1 domain error is handled in the called functions */ | ||
| 15 | |||
| 16 | 	if (e < 0x3ff + 1) | ||
| 17 | 		/* |x| < 2, up to 2ulp error in [1,1.125] */ | ||
| 18 | 		return log1p(x-1 + sqrt((x-1)*(x-1)+2*(x-1))); | ||
| 19 | 	if (e < 0x3ff + 26) | ||
| 20 | 		/* |x| < 0x1p26 */ | ||
| 21 | 		return log(2*x - 1/(x+sqrt(x*x-1))); | ||
| 22 | 	/* |x| >= 0x1p26 or nan */ | ||
| 23 | 	return log(x) + 0.693147180559945309417232121458176568; | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/acoshf.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if FLT_EVAL_METHOD==2 | ||
| 4 | #undef sqrtf | ||
| 5 | #define sqrtf sqrtl | ||
| 6 | #elif FLT_EVAL_METHOD==1 | ||
| 7 | #undef sqrtf | ||
| 8 | #define sqrtf sqrt | ||
| 9 | #endif | ||
| 10 | |||
| 11 | /* acosh(x) = log(x + sqrt(x*x-1)) */ | ||
| 12 | float acoshf(float x) | ||
| 13 | { | ||
| 14 | 	union {float f; uint32_t i;} u = {x}; | ||
| 15 | 	uint32_t a = u.i & 0x7fffffff; | ||
| 16 | |||
| 17 | 	if (a < 0x3f800000+(1<<23)) | ||
| 18 | 		/* |x| < 2, invalid if x < 1 or nan */ | ||
| 19 | 		/* up to 2ulp error in [1,1.125] */ | ||
| 20 | 		return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1))); | ||
| 21 | 	if (a < 0x3f800000+(12<<23)) | ||
| 22 | 		/* |x| < 0x1p12 */ | ||
| 23 | 		return logf(2*x - 1/(x+sqrtf(x*x-1))); | ||
| 24 | 	/* x >= 0x1p12 */ | ||
| 25 | 	return logf(x) + 0.693147180559945309417232121458176568f; | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/acoshl.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double acoshl(long double x) | ||
| 5 | { | ||
| 6 | 	return acosh(x); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | /* acosh(x) = log(x + sqrt(x*x-1)) */ | ||
| 10 | long double acoshl(long double x) | ||
| 11 | { | ||
| 12 | 	union ldshape u = {x}; | ||
| 13 | 	int e = u.i.se & 0x7fff; | ||
| 14 | |||
| 15 | 	if (e < 0x3fff + 1) | ||
| 16 | 		/* |x| < 2, invalid if x < 1 or nan */ | ||
| 17 | 		return log1pl(x-1 + sqrtl((x-1)*(x-1)+2*(x-1))); | ||
| 18 | 	if (e < 0x3fff + 32) | ||
| 19 | 		/* |x| < 0x1p32 */ | ||
| 20 | 		return logl(2*x - 1/(x+sqrtl(x*x-1))); | ||
| 21 | 	return logl(x) + 0.693147180559945309417232121458176568L; | ||
| 22 | } | ||
| 23 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 24 | // TODO: broken implementation to make things compile | ||
| 25 | long double acoshl(long double x) | ||
| 26 | { | ||
| 27 | 	return acosh(x); | ||
| 28 | } | ||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/acosl.c created+67| ... | @@ -0,0 +1,67 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_acosl.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 | /* | ||
| 13 | * See comments in acos.c. | ||
| 14 | * Converted to long double by David Schultz <das@FreeBSD.ORG>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 20 | long double acosl(long double x) | ||
| 21 | { | ||
| 22 | 	return acos(x); | ||
| 23 | } | ||
| 24 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 25 | #include "__invtrigl.h" | ||
| 26 | #if LDBL_MANT_DIG == 64 | ||
| 27 | #define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32) | ||
| 28 | #elif LDBL_MANT_DIG == 113 | ||
| 29 | #define CLEARBOTTOM(u) (u.i.lo = 0) | ||
| 30 | #endif | ||
| 31 | |||
| 32 | long double acosl(long double x) | ||
| 33 | { | ||
| 34 | 	union ldshape u = {x}; | ||
| 35 | 	long double z, s, c, f; | ||
| 36 | 	uint16_t e = u.i.se & 0x7fff; | ||
| 37 | |||
| 38 | 	/* |x| >= 1 or nan */ | ||
| 39 | 	if (e >= 0x3fff) { | ||
| 40 | 		if (x == 1) | ||
| 41 | 			return 0; | ||
| 42 | 		if (x == -1) | ||
| 43 | 			return 2*pio2_hi + 0x1p-120f; | ||
| 44 | 		return 0/(x-x); | ||
| 45 | 	} | ||
| 46 | 	/* |x| < 0.5 */ | ||
| 47 | 	if (e < 0x3fff - 1) { | ||
| 48 | 		if (e < 0x3fff - LDBL_MANT_DIG - 1) | ||
| 49 | 			return pio2_hi + 0x1p-120f; | ||
| 50 | 		return pio2_hi - (__invtrigl_R(x*x)*x - pio2_lo + x); | ||
| 51 | 	} | ||
| 52 | 	/* x < -0.5 */ | ||
| 53 | 	if (u.i.se >> 15) { | ||
| 54 | 		z = (1 + x)*0.5; | ||
| 55 | 		s = sqrtl(z); | ||
| 56 | 		return 2*(pio2_hi - (__invtrigl_R(z)*s - pio2_lo + s)); | ||
| 57 | 	} | ||
| 58 | 	/* x > 0.5 */ | ||
| 59 | 	z = (1 - x)*0.5; | ||
| 60 | 	s = sqrtl(z); | ||
| 61 | 	u.f = s; | ||
| 62 | 	CLEARBOTTOM(u); | ||
| 63 | 	f = u.f; | ||
| 64 | 	c = (z - f*f)/(s + f); | ||
| 65 | 	return 2*(__invtrigl_R(z)*s + c + f); | ||
| 66 | } | ||
| 67 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/arm/fabs.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __ARM_PCS_VFP && __ARM_FP&8 | ||
| 4 | |||
| 5 | double fabs(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vabs.f64 %P0, %P1" : "=w"(x) : "w"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabs.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/arm/fabsf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __ARM_PCS_VFP && !BROKEN_VFP_ASM | ||
| 4 | |||
| 5 | float fabsf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vabs.f32 %0, %1" : "=t"(x) : "t"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabsf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/arm/fma.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __ARM_FEATURE_FMA && __ARM_FP&8 && !__SOFTFP__ | ||
| 4 | |||
| 5 | double fma(double x, double y, double z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vfma.f64 %P0, %P1, %P2" : "+w"(z) : "w"(x), "w"(y)); | ||
| 8 | 	return z; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fma.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/arm/fmaf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __ARM_FEATURE_FMA && __ARM_FP&4 && !__SOFTFP__ && !BROKEN_VFP_ASM | ||
| 4 | |||
| 5 | float fmaf(float x, float y, float z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vfma.f32 %0, %1, %2" : "+t"(z) : "t"(x), "t"(y)); | ||
| 8 | 	return z; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmaf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/arm/sqrt.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && (__ARM_FP&8) | ||
| 4 | |||
| 5 | double sqrt(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vsqrt.f64 %P0, %P1" : "=w"(x) : "w"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrt.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/arm/sqrtf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if (__ARM_PCS_VFP || (__VFP_FP__ && !__SOFTFP__)) && !BROKEN_VFP_ASM | ||
| 4 | |||
| 5 | float sqrtf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vsqrt.f32 %0, %1" : "=t"(x) : "t"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrtf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/asin.c created+107| ... | @@ -0,0 +1,107 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_asin.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 | /* asin(x) | ||
| 13 | * Method : | ||
| 14 | * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... | ||
| 15 | * we approximate asin(x) on [0,0.5] by | ||
| 16 | * asin(x) = x + x*x^2*R(x^2) | ||
| 17 | * where | ||
| 18 | * R(x^2) is a rational approximation of (asin(x)-x)/x^3 | ||
| 19 | * and its remez error is bounded by | ||
| 20 | * |(asin(x)-x)/x^3 - R(x^2)| < 2^(-58.75) | ||
| 21 | * | ||
| 22 | * For x in [0.5,1] | ||
| 23 | * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) | ||
| 24 | * Let y = (1-x), z = y/2, s := sqrt(z), and pio2_hi+pio2_lo=pi/2; | ||
| 25 | * then for x>0.98 | ||
| 26 | * asin(x) = pi/2 - 2*(s+s*z*R(z)) | ||
| 27 | * = pio2_hi - (2*(s+s*z*R(z)) - pio2_lo) | ||
| 28 | * For x<=0.98, let pio4_hi = pio2_hi/2, then | ||
| 29 | * f = hi part of s; | ||
| 30 | * c = sqrt(z) - f = (z-f*f)/(s+f) ...f+c=sqrt(z) | ||
| 31 | * and | ||
| 32 | * asin(x) = pi/2 - 2*(s+s*z*R(z)) | ||
| 33 | * = pio4_hi+(pio4-2s)-(2s*z*R(z)-pio2_lo) | ||
| 34 | * = pio4_hi+(pio4-2f)-(2s*z*R(z)-(pio2_lo+2c)) | ||
| 35 | * | ||
| 36 | * Special cases: | ||
| 37 | * if x is NaN, return x itself; | ||
| 38 | * if |x|>1, return NaN with invalid signal. | ||
| 39 | * | ||
| 40 | */ | ||
| 41 | |||
| 42 | #include "libm.h" | ||
| 43 | |||
| 44 | static const double | ||
| 45 | pio2_hi = 1.57079632679489655800e+00, /* 0x3FF921FB, 0x54442D18 */ | ||
| 46 | pio2_lo = 6.12323399573676603587e-17, /* 0x3C91A626, 0x33145C07 */ | ||
| 47 | /* coefficients for R(x^2) */ | ||
| 48 | pS0 = 1.66666666666666657415e-01, /* 0x3FC55555, 0x55555555 */ | ||
| 49 | pS1 = -3.25565818622400915405e-01, /* 0xBFD4D612, 0x03EB6F7D */ | ||
| 50 | pS2 = 2.01212532134862925881e-01, /* 0x3FC9C155, 0x0E884455 */ | ||
| 51 | pS3 = -4.00555345006794114027e-02, /* 0xBFA48228, 0xB5688F3B */ | ||
| 52 | pS4 = 7.91534994289814532176e-04, /* 0x3F49EFE0, 0x7501B288 */ | ||
| 53 | pS5 = 3.47933107596021167570e-05, /* 0x3F023DE1, 0x0DFDF709 */ | ||
| 54 | qS1 = -2.40339491173441421878e+00, /* 0xC0033A27, 0x1C8A2D4B */ | ||
| 55 | qS2 = 2.02094576023350569471e+00, /* 0x40002AE5, 0x9C598AC8 */ | ||
| 56 | qS3 = -6.88283971605453293030e-01, /* 0xBFE6066C, 0x1B8D0159 */ | ||
| 57 | qS4 = 7.70381505559019352791e-02; /* 0x3FB3B8C5, 0xB12E9282 */ | ||
| 58 | |||
| 59 | static double R(double z) | ||
| 60 | { | ||
| 61 | 	double_t p, q; | ||
| 62 | 	p = z*(pS0+z*(pS1+z*(pS2+z*(pS3+z*(pS4+z*pS5))))); | ||
| 63 | 	q = 1.0+z*(qS1+z*(qS2+z*(qS3+z*qS4))); | ||
| 64 | 	return p/q; | ||
| 65 | } | ||
| 66 | |||
| 67 | double asin(double x) | ||
| 68 | { | ||
| 69 | 	double z,r,s; | ||
| 70 | 	uint32_t hx,ix; | ||
| 71 | |||
| 72 | 	GET_HIGH_WORD(hx, x); | ||
| 73 | 	ix = hx & 0x7fffffff; | ||
| 74 | 	/* |x| >= 1 or nan */ | ||
| 75 | 	if (ix >= 0x3ff00000) { | ||
| 76 | 		uint32_t lx; | ||
| 77 | 		GET_LOW_WORD(lx, x); | ||
| 78 | 		if ((ix-0x3ff00000 | lx) == 0) | ||
| 79 | 			/* asin(1) = +-pi/2 with inexact */ | ||
| 80 | 			return x*pio2_hi + 0x1p-120f; | ||
| 81 | 		return 0/(x-x); | ||
| 82 | 	} | ||
| 83 | 	/* |x| < 0.5 */ | ||
| 84 | 	if (ix < 0x3fe00000) { | ||
| 85 | 		/* if 0x1p-1022 <= |x| < 0x1p-26, avoid raising underflow */ | ||
| 86 | 		if (ix < 0x3e500000 && ix >= 0x00100000) | ||
| 87 | 			return x; | ||
| 88 | 		return x + x*R(x*x); | ||
| 89 | 	} | ||
| 90 | 	/* 1 > |x| >= 0.5 */ | ||
| 91 | 	z = (1 - fabs(x))*0.5; | ||
| 92 | 	s = sqrt(z); | ||
| 93 | 	r = R(z); | ||
| 94 | 	if (ix >= 0x3fef3333) { /* if |x| > 0.975 */ | ||
| 95 | 		x = pio2_hi-(2*(s+s*r)-pio2_lo); | ||
| 96 | 	} else { | ||
| 97 | 		double f,c; | ||
| 98 | 		/* f+c = sqrt(z) */ | ||
| 99 | 		f = s; | ||
| 100 | 		SET_LOW_WORD(f,0); | ||
| 101 | 		c = (z-f*f)/(s+f); | ||
| 102 | 		x = 0.5*pio2_hi - (2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f)); | ||
| 103 | 	} | ||
| 104 | 	if (hx >> 31) | ||
| 105 | 		return -x; | ||
| 106 | 	return x; | ||
| 107 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/asinf.c created+61| ... | @@ -0,0 +1,61 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_asinf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | #include "libm.h" | ||
| 16 | |||
| 17 | static const double | ||
| 18 | pio2 = 1.570796326794896558e+00; | ||
| 19 | |||
| 20 | static const float | ||
| 21 | /* coefficients for R(x^2) */ | ||
| 22 | pS0 = 1.6666586697e-01, | ||
| 23 | pS1 = -4.2743422091e-02, | ||
| 24 | pS2 = -8.6563630030e-03, | ||
| 25 | qS1 = -7.0662963390e-01; | ||
| 26 | |||
| 27 | static float R(float z) | ||
| 28 | { | ||
| 29 | 	float_t p, q; | ||
| 30 | 	p = z*(pS0+z*(pS1+z*pS2)); | ||
| 31 | 	q = 1.0f+z*qS1; | ||
| 32 | 	return p/q; | ||
| 33 | } | ||
| 34 | |||
| 35 | float asinf(float x) | ||
| 36 | { | ||
| 37 | 	double s; | ||
| 38 | 	float z; | ||
| 39 | 	uint32_t hx,ix; | ||
| 40 | |||
| 41 | 	GET_FLOAT_WORD(hx, x); | ||
| 42 | 	ix = hx & 0x7fffffff; | ||
| 43 | 	if (ix >= 0x3f800000) { /* |x| >= 1 */ | ||
| 44 | 		if (ix == 0x3f800000) /* |x| == 1 */ | ||
| 45 | 			return x*pio2 + 0x1p-120f; /* asin(+-1) = +-pi/2 with inexact */ | ||
| 46 | 		return 0/(x-x); /* asin(|x|>1) is NaN */ | ||
| 47 | 	} | ||
| 48 | 	if (ix < 0x3f000000) { /* |x| < 0.5 */ | ||
| 49 | 		/* if 0x1p-126 <= |x| < 0x1p-12, avoid raising underflow */ | ||
| 50 | 		if (ix < 0x39800000 && ix >= 0x00800000) | ||
| 51 | 			return x; | ||
| 52 | 		return x + x*R(x*x); | ||
| 53 | 	} | ||
| 54 | 	/* 1 > |x| >= 0.5 */ | ||
| 55 | 	z = (1 - fabsf(x))*0.5f; | ||
| 56 | 	s = sqrt(z); | ||
| 57 | 	x = pio2 - 2*(s+s*R(z)); | ||
| 58 | 	if (hx >> 31) | ||
| 59 | 		return -x; | ||
| 60 | 	return x; | ||
| 61 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/asinh.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ | ||
| 4 | double asinh(double x) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} u = {.f = x}; | ||
| 7 | 	unsigned e = u.i >> 52 & 0x7ff; | ||
| 8 | 	unsigned s = u.i >> 63; | ||
| 9 | |||
| 10 | 	/* |x| */ | ||
| 11 | 	u.i &= (uint64_t)-1/2; | ||
| 12 | 	x = u.f; | ||
| 13 | |||
| 14 | 	if (e >= 0x3ff + 26) { | ||
| 15 | 		/* |x| >= 0x1p26 or inf or nan */ | ||
| 16 | 		x = log(x) + 0.693147180559945309417232121458176568; | ||
| 17 | 	} else if (e >= 0x3ff + 1) { | ||
| 18 | 		/* |x| >= 2 */ | ||
| 19 | 		x = log(2*x + 1/(sqrt(x*x+1)+x)); | ||
| 20 | 	} else if (e >= 0x3ff - 26) { | ||
| 21 | 		/* |x| >= 0x1p-26, up to 1.6ulp error in [0.125,0.5] */ | ||
| 22 | 		x = log1p(x + x*x/(sqrt(x*x+1)+1)); | ||
| 23 | 	} else { | ||
| 24 | 		/* |x| < 0x1p-26, raise inexact if x != 0 */ | ||
| 25 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 26 | 	} | ||
| 27 | 	return s ? -x : x; | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/asinhf.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ | ||
| 4 | float asinhf(float x) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} u = {.f = x}; | ||
| 7 | 	uint32_t i = u.i & 0x7fffffff; | ||
| 8 | 	unsigned s = u.i >> 31; | ||
| 9 | |||
| 10 | 	/* |x| */ | ||
| 11 | 	u.i = i; | ||
| 12 | 	x = u.f; | ||
| 13 | |||
| 14 | 	if (i >= 0x3f800000 + (12<<23)) { | ||
| 15 | 		/* |x| >= 0x1p12 or inf or nan */ | ||
| 16 | 		x = logf(x) + 0.693147180559945309417232121458176568f; | ||
| 17 | 	} else if (i >= 0x3f800000 + (1<<23)) { | ||
| 18 | 		/* |x| >= 2 */ | ||
| 19 | 		x = logf(2*x + 1/(sqrtf(x*x+1)+x)); | ||
| 20 | 	} else if (i >= 0x3f800000 - (12<<23)) { | ||
| 21 | 		/* |x| >= 0x1p-12, up to 1.6ulp error in [0.125,0.5] */ | ||
| 22 | 		x = log1pf(x + x*x/(sqrtf(x*x+1)+1)); | ||
| 23 | 	} else { | ||
| 24 | 		/* |x| < 0x1p-12, raise inexact if x!=0 */ | ||
| 25 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 26 | 	} | ||
| 27 | 	return s ? -x : x; | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/asinhl.c created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double asinhl(long double x) | ||
| 5 | { | ||
| 6 | 	return asinh(x); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | /* asinh(x) = sign(x)*log(|x|+sqrt(x*x+1)) ~= x - x^3/6 + o(x^5) */ | ||
| 10 | long double asinhl(long double x) | ||
| 11 | { | ||
| 12 | 	union ldshape u = {x}; | ||
| 13 | 	unsigned e = u.i.se & 0x7fff; | ||
| 14 | 	unsigned s = u.i.se >> 15; | ||
| 15 | |||
| 16 | 	/* |x| */ | ||
| 17 | 	u.i.se = e; | ||
| 18 | 	x = u.f; | ||
| 19 | |||
| 20 | 	if (e >= 0x3fff + 32) { | ||
| 21 | 		/* |x| >= 0x1p32 or inf or nan */ | ||
| 22 | 		x = logl(x) + 0.693147180559945309417232121458176568L; | ||
| 23 | 	} else if (e >= 0x3fff + 1) { | ||
| 24 | 		/* |x| >= 2 */ | ||
| 25 | 		x = logl(2*x + 1/(sqrtl(x*x+1)+x)); | ||
| 26 | 	} else if (e >= 0x3fff - 32) { | ||
| 27 | 		/* |x| >= 0x1p-32 */ | ||
| 28 | 		x = log1pl(x + x*x/(sqrtl(x*x+1)+1)); | ||
| 29 | 	} else { | ||
| 30 | 		/* |x| < 0x1p-32, raise inexact if x!=0 */ | ||
| 31 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 32 | 	} | ||
| 33 | 	return s ? -x : x; | ||
| 34 | } | ||
| 35 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 36 | // TODO: broken implementation to make things compile | ||
| 37 | long double asinhl(long double x) | ||
| 38 | { | ||
| 39 | 	return asinh(x); | ||
| 40 | } | ||
| 41 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/asinl.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_asinl.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 | /* | ||
| 13 | * See comments in asin.c. | ||
| 14 | * Converted to long double by David Schultz <das@FreeBSD.ORG>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 20 | long double asinl(long double x) | ||
| 21 | { | ||
| 22 | 	return asin(x); | ||
| 23 | } | ||
| 24 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 25 | #include "__invtrigl.h" | ||
| 26 | #if LDBL_MANT_DIG == 64 | ||
| 27 | #define CLOSETO1(u) (u.i.m>>56 >= 0xf7) | ||
| 28 | #define CLEARBOTTOM(u) (u.i.m &= -1ULL << 32) | ||
| 29 | #elif LDBL_MANT_DIG == 113 | ||
| 30 | #define CLOSETO1(u) (u.i.top >= 0xee00) | ||
| 31 | #define CLEARBOTTOM(u) (u.i.lo = 0) | ||
| 32 | #endif | ||
| 33 | |||
| 34 | long double asinl(long double x) | ||
| 35 | { | ||
| 36 | 	union ldshape u = {x}; | ||
| 37 | 	long double z, r, s; | ||
| 38 | 	uint16_t e = u.i.se & 0x7fff; | ||
| 39 | 	int sign = u.i.se >> 15; | ||
| 40 | |||
| 41 | 	if (e >= 0x3fff) { /* |x| >= 1 or nan */ | ||
| 42 | 		/* asin(+-1)=+-pi/2 with inexact */ | ||
| 43 | 		if (x == 1 || x == -1) | ||
| 44 | 			return x*pio2_hi + 0x1p-120f; | ||
| 45 | 		return 0/(x-x); | ||
| 46 | 	} | ||
| 47 | 	if (e < 0x3fff - 1) { /* |x| < 0.5 */ | ||
| 48 | 		if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) { | ||
| 49 | 			/* return x with inexact if x!=0 */ | ||
| 50 | 			FORCE_EVAL(x + 0x1p120f); | ||
| 51 | 			return x; | ||
| 52 | 		} | ||
| 53 | 		return x + x*__invtrigl_R(x*x); | ||
| 54 | 	} | ||
| 55 | 	/* 1 > |x| >= 0.5 */ | ||
| 56 | 	z = (1.0 - fabsl(x))*0.5; | ||
| 57 | 	s = sqrtl(z); | ||
| 58 | 	r = __invtrigl_R(z); | ||
| 59 | 	if (CLOSETO1(u)) { | ||
| 60 | 		x = pio2_hi - (2*(s+s*r)-pio2_lo); | ||
| 61 | 	} else { | ||
| 62 | 		long double f, c; | ||
| 63 | 		u.f = s; | ||
| 64 | 		CLEARBOTTOM(u); | ||
| 65 | 		f = u.f; | ||
| 66 | 		c = (z - f*f)/(s + f); | ||
| 67 | 		x = 0.5*pio2_hi-(2*s*r - (pio2_lo-2*c) - (0.5*pio2_hi-2*f)); | ||
| 68 | 	} | ||
| 69 | 	return sign ? -x : x; | ||
| 70 | } | ||
| 71 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/atan.c created+116| ... | @@ -0,0 +1,116 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_atan.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* atan(x) | ||
| 13 | * Method | ||
| 14 | * 1. Reduce x to positive by atan(x) = -atan(-x). | ||
| 15 | * 2. According to the integer k=4t+0.25 chopped, t=x, the argument | ||
| 16 | * is further reduced to one of the following intervals and the | ||
| 17 | * arctangent of t is evaluated by the corresponding formula: | ||
| 18 | * | ||
| 19 | * [0,7/16] atan(x) = t-t^3*(a1+t^2*(a2+...(a10+t^2*a11)...) | ||
| 20 | * [7/16,11/16] atan(x) = atan(1/2) + atan( (t-0.5)/(1+t/2) ) | ||
| 21 | * [11/16.19/16] atan(x) = atan( 1 ) + atan( (t-1)/(1+t) ) | ||
| 22 | * [19/16,39/16] atan(x) = atan(3/2) + atan( (t-1.5)/(1+1.5t) ) | ||
| 23 | * [39/16,INF] atan(x) = atan(INF) + atan( -1/t ) | ||
| 24 | * | ||
| 25 | * Constants: | ||
| 26 | * The hexadecimal values are the intended ones for the following | ||
| 27 | * constants. The decimal values may be used, provided that the | ||
| 28 | * compiler will convert from decimal to binary accurately enough | ||
| 29 | * to produce the hexadecimal values shown. | ||
| 30 | */ | ||
| 31 | |||
| 32 | |||
| 33 | #include "libm.h" | ||
| 34 | |||
| 35 | static const double atanhi[] = { | ||
| 36 | 4.63647609000806093515e-01, /* atan(0.5)hi 0x3FDDAC67, 0x0561BB4F */ | ||
| 37 | 7.85398163397448278999e-01, /* atan(1.0)hi 0x3FE921FB, 0x54442D18 */ | ||
| 38 | 9.82793723247329054082e-01, /* atan(1.5)hi 0x3FEF730B, 0xD281F69B */ | ||
| 39 | 1.57079632679489655800e+00, /* atan(inf)hi 0x3FF921FB, 0x54442D18 */ | ||
| 40 | }; | ||
| 41 | |||
| 42 | static const double atanlo[] = { | ||
| 43 | 2.26987774529616870924e-17, /* atan(0.5)lo 0x3C7A2B7F, 0x222F65E2 */ | ||
| 44 | 3.06161699786838301793e-17, /* atan(1.0)lo 0x3C81A626, 0x33145C07 */ | ||
| 45 | 1.39033110312309984516e-17, /* atan(1.5)lo 0x3C700788, 0x7AF0CBBD */ | ||
| 46 | 6.12323399573676603587e-17, /* atan(inf)lo 0x3C91A626, 0x33145C07 */ | ||
| 47 | }; | ||
| 48 | |||
| 49 | static const double aT[] = { | ||
| 50 | 3.33333333333329318027e-01, /* 0x3FD55555, 0x5555550D */ | ||
| 51 | -1.99999999998764832476e-01, /* 0xBFC99999, 0x9998EBC4 */ | ||
| 52 | 1.42857142725034663711e-01, /* 0x3FC24924, 0x920083FF */ | ||
| 53 | -1.11111104054623557880e-01, /* 0xBFBC71C6, 0xFE231671 */ | ||
| 54 | 9.09088713343650656196e-02, /* 0x3FB745CD, 0xC54C206E */ | ||
| 55 | -7.69187620504482999495e-02, /* 0xBFB3B0F2, 0xAF749A6D */ | ||
| 56 | 6.66107313738753120669e-02, /* 0x3FB10D66, 0xA0D03D51 */ | ||
| 57 | -5.83357013379057348645e-02, /* 0xBFADDE2D, 0x52DEFD9A */ | ||
| 58 | 4.97687799461593236017e-02, /* 0x3FA97B4B, 0x24760DEB */ | ||
| 59 | -3.65315727442169155270e-02, /* 0xBFA2B444, 0x2C6A6C2F */ | ||
| 60 | 1.62858201153657823623e-02, /* 0x3F90AD3A, 0xE322DA11 */ | ||
| 61 | }; | ||
| 62 | |||
| 63 | double atan(double x) | ||
| 64 | { | ||
| 65 | 	double_t w,s1,s2,z; | ||
| 66 | 	uint32_t ix,sign; | ||
| 67 | 	int id; | ||
| 68 | |||
| 69 | 	GET_HIGH_WORD(ix, x); | ||
| 70 | 	sign = ix >> 31; | ||
| 71 | 	ix &= 0x7fffffff; | ||
| 72 | 	if (ix >= 0x44100000) { /* if |x| >= 2^66 */ | ||
| 73 | 		if (isnan(x)) | ||
| 74 | 			return x; | ||
| 75 | 		z = atanhi[3] + 0x1p-120f; | ||
| 76 | 		return sign ? -z : z; | ||
| 77 | 	} | ||
| 78 | 	if (ix < 0x3fdc0000) { /* |x| < 0.4375 */ | ||
| 79 | 		if (ix < 0x3e400000) { /* |x| < 2^-27 */ | ||
| 80 | 			if (ix < 0x00100000) | ||
| 81 | 				/* raise underflow for subnormal x */ | ||
| 82 | 				FORCE_EVAL((float)x); | ||
| 83 | 			return x; | ||
| 84 | 		} | ||
| 85 | 		id = -1; | ||
| 86 | 	} else { | ||
| 87 | 		x = fabs(x); | ||
| 88 | 		if (ix < 0x3ff30000) { /* |x| < 1.1875 */ | ||
| 89 | 			if (ix < 0x3fe60000) { /* 7/16 <= |x| < 11/16 */ | ||
| 90 | 				id = 0; | ||
| 91 | 				x = (2.0*x-1.0)/(2.0+x); | ||
| 92 | 			} else { /* 11/16 <= |x| < 19/16 */ | ||
| 93 | 				id = 1; | ||
| 94 | 				x = (x-1.0)/(x+1.0); | ||
| 95 | 			} | ||
| 96 | 		} else { | ||
| 97 | 			if (ix < 0x40038000) { /* |x| < 2.4375 */ | ||
| 98 | 				id = 2; | ||
| 99 | 				x = (x-1.5)/(1.0+1.5*x); | ||
| 100 | 			} else { /* 2.4375 <= |x| < 2^66 */ | ||
| 101 | 				id = 3; | ||
| 102 | 				x = -1.0/x; | ||
| 103 | 			} | ||
| 104 | 		} | ||
| 105 | 	} | ||
| 106 | 	/* end of argument reduction */ | ||
| 107 | 	z = x*x; | ||
| 108 | 	w = z*z; | ||
| 109 | 	/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ | ||
| 110 | 	s1 = z*(aT[0]+w*(aT[2]+w*(aT[4]+w*(aT[6]+w*(aT[8]+w*aT[10]))))); | ||
| 111 | 	s2 = w*(aT[1]+w*(aT[3]+w*(aT[5]+w*(aT[7]+w*aT[9])))); | ||
| 112 | 	if (id < 0) | ||
| 113 | 		return x - x*(s1+s2); | ||
| 114 | 	z = atanhi[id] - (x*(s1+s2) - atanlo[id] - x); | ||
| 115 | 	return sign ? -z : z; | ||
| 116 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/atan2.c created+107| ... | @@ -0,0 +1,107 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2.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 | */ | ||
| 13 | /* atan2(y,x) | ||
| 14 | * Method : | ||
| 15 | * 1. Reduce y to positive by atan2(y,x)=-atan2(-y,x). | ||
| 16 | * 2. Reduce x to positive by (if x and y are unexceptional): | ||
| 17 | * ARG (x+iy) = arctan(y/x) ... if x > 0, | ||
| 18 | * ARG (x+iy) = pi - arctan[y/(-x)] ... if x < 0, | ||
| 19 | * | ||
| 20 | * Special cases: | ||
| 21 | * | ||
| 22 | * ATAN2((anything), NaN ) is NaN; | ||
| 23 | * ATAN2(NAN , (anything) ) is NaN; | ||
| 24 | * ATAN2(+-0, +(anything but NaN)) is +-0 ; | ||
| 25 | * ATAN2(+-0, -(anything but NaN)) is +-pi ; | ||
| 26 | * ATAN2(+-(anything but 0 and NaN), 0) is +-pi/2; | ||
| 27 | * ATAN2(+-(anything but INF and NaN), +INF) is +-0 ; | ||
| 28 | * ATAN2(+-(anything but INF and NaN), -INF) is +-pi; | ||
| 29 | * ATAN2(+-INF,+INF ) is +-pi/4 ; | ||
| 30 | * ATAN2(+-INF,-INF ) is +-3pi/4; | ||
| 31 | * ATAN2(+-INF, (anything but,0,NaN, and INF)) is +-pi/2; | ||
| 32 | * | ||
| 33 | * Constants: | ||
| 34 | * The hexadecimal values are the intended ones for the following | ||
| 35 | * constants. The decimal values may be used, provided that the | ||
| 36 | * compiler will convert from decimal to binary accurately enough | ||
| 37 | * to produce the hexadecimal values shown. | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include "libm.h" | ||
| 41 | |||
| 42 | static const double | ||
| 43 | pi = 3.1415926535897931160E+00, /* 0x400921FB, 0x54442D18 */ | ||
| 44 | pi_lo = 1.2246467991473531772E-16; /* 0x3CA1A626, 0x33145C07 */ | ||
| 45 | |||
| 46 | double atan2(double y, double x) | ||
| 47 | { | ||
| 48 | 	double z; | ||
| 49 | 	uint32_t m,lx,ly,ix,iy; | ||
| 50 | |||
| 51 | 	if (isnan(x) || isnan(y)) | ||
| 52 | 		return x+y; | ||
| 53 | 	EXTRACT_WORDS(ix, lx, x); | ||
| 54 | 	EXTRACT_WORDS(iy, ly, y); | ||
| 55 | 	if ((ix-0x3ff00000 | lx) == 0) /* x = 1.0 */ | ||
| 56 | 		return atan(y); | ||
| 57 | 	m = ((iy>>31)&1) | ((ix>>30)&2); /* 2*sign(x)+sign(y) */ | ||
| 58 | 	ix = ix & 0x7fffffff; | ||
| 59 | 	iy = iy & 0x7fffffff; | ||
| 60 | |||
| 61 | 	/* when y = 0 */ | ||
| 62 | 	if ((iy|ly) == 0) { | ||
| 63 | 		switch(m) { | ||
| 64 | 		case 0: | ||
| 65 | 		case 1: return y; /* atan(+-0,+anything)=+-0 */ | ||
| 66 | 		case 2: return pi; /* atan(+0,-anything) = pi */ | ||
| 67 | 		case 3: return -pi; /* atan(-0,-anything) =-pi */ | ||
| 68 | 		} | ||
| 69 | 	} | ||
| 70 | 	/* when x = 0 */ | ||
| 71 | 	if ((ix|lx) == 0) | ||
| 72 | 		return m&1 ? -pi/2 : pi/2; | ||
| 73 | 	/* when x is INF */ | ||
| 74 | 	if (ix == 0x7ff00000) { | ||
| 75 | 		if (iy == 0x7ff00000) { | ||
| 76 | 			switch(m) { | ||
| 77 | 			case 0: return pi/4; /* atan(+INF,+INF) */ | ||
| 78 | 			case 1: return -pi/4; /* atan(-INF,+INF) */ | ||
| 79 | 			case 2: return 3*pi/4; /* atan(+INF,-INF) */ | ||
| 80 | 			case 3: return -3*pi/4; /* atan(-INF,-INF) */ | ||
| 81 | 			} | ||
| 82 | 		} else { | ||
| 83 | 			switch(m) { | ||
| 84 | 			case 0: return 0.0; /* atan(+...,+INF) */ | ||
| 85 | 			case 1: return -0.0; /* atan(-...,+INF) */ | ||
| 86 | 			case 2: return pi; /* atan(+...,-INF) */ | ||
| 87 | 			case 3: return -pi; /* atan(-...,-INF) */ | ||
| 88 | 			} | ||
| 89 | 		} | ||
| 90 | 	} | ||
| 91 | 	/* |y/x| > 0x1p64 */ | ||
| 92 | 	if (ix+(64<<20) < iy || iy == 0x7ff00000) | ||
| 93 | 		return m&1 ? -pi/2 : pi/2; | ||
| 94 | |||
| 95 | 	/* z = atan(|y/x|) without spurious underflow */ | ||
| 96 | 	if ((m&2) && iy+(64<<20) < ix) /* |y/x| < 0x1p-64, x<0 */ | ||
| 97 | 		z = 0; | ||
| 98 | 	else | ||
| 99 | 		z = atan(fabs(y/x)); | ||
| 100 | 	switch (m) { | ||
| 101 | 	case 0: return z; /* atan(+,+) */ | ||
| 102 | 	case 1: return -z; /* atan(-,+) */ | ||
| 103 | 	case 2: return pi - (z-pi_lo); /* atan(+,-) */ | ||
| 104 | 	default: /* case 3 */ | ||
| 105 | 		return (z-pi_lo) - pi; /* atan(-,-) */ | ||
| 106 | 	} | ||
| 107 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/atan2f.c created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2f.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | static const float | ||
| 19 | pi = 3.1415927410e+00, /* 0x40490fdb */ | ||
| 20 | pi_lo = -8.7422776573e-08; /* 0xb3bbbd2e */ | ||
| 21 | |||
| 22 | float atan2f(float y, float x) | ||
| 23 | { | ||
| 24 | 	float z; | ||
| 25 | 	uint32_t m,ix,iy; | ||
| 26 | |||
| 27 | 	if (isnan(x) || isnan(y)) | ||
| 28 | 		return x+y; | ||
| 29 | 	GET_FLOAT_WORD(ix, x); | ||
| 30 | 	GET_FLOAT_WORD(iy, y); | ||
| 31 | 	if (ix == 0x3f800000) /* x=1.0 */ | ||
| 32 | 		return atanf(y); | ||
| 33 | 	m = ((iy>>31)&1) | ((ix>>30)&2); /* 2*sign(x)+sign(y) */ | ||
| 34 | 	ix &= 0x7fffffff; | ||
| 35 | 	iy &= 0x7fffffff; | ||
| 36 | |||
| 37 | 	/* when y = 0 */ | ||
| 38 | 	if (iy == 0) { | ||
| 39 | 		switch (m) { | ||
| 40 | 		case 0: | ||
| 41 | 		case 1: return y; /* atan(+-0,+anything)=+-0 */ | ||
| 42 | 		case 2: return pi; /* atan(+0,-anything) = pi */ | ||
| 43 | 		case 3: return -pi; /* atan(-0,-anything) =-pi */ | ||
| 44 | 		} | ||
| 45 | 	} | ||
| 46 | 	/* when x = 0 */ | ||
| 47 | 	if (ix == 0) | ||
| 48 | 		return m&1 ? -pi/2 : pi/2; | ||
| 49 | 	/* when x is INF */ | ||
| 50 | 	if (ix == 0x7f800000) { | ||
| 51 | 		if (iy == 0x7f800000) { | ||
| 52 | 			switch (m) { | ||
| 53 | 			case 0: return pi/4; /* atan(+INF,+INF) */ | ||
| 54 | 			case 1: return -pi/4; /* atan(-INF,+INF) */ | ||
| 55 | 			case 2: return 3*pi/4; /*atan(+INF,-INF)*/ | ||
| 56 | 			case 3: return -3*pi/4; /*atan(-INF,-INF)*/ | ||
| 57 | 			} | ||
| 58 | 		} else { | ||
| 59 | 			switch (m) { | ||
| 60 | 			case 0: return 0.0f; /* atan(+...,+INF) */ | ||
| 61 | 			case 1: return -0.0f; /* atan(-...,+INF) */ | ||
| 62 | 			case 2: return pi; /* atan(+...,-INF) */ | ||
| 63 | 			case 3: return -pi; /* atan(-...,-INF) */ | ||
| 64 | 			} | ||
| 65 | 		} | ||
| 66 | 	} | ||
| 67 | 	/* |y/x| > 0x1p26 */ | ||
| 68 | 	if (ix+(26<<23) < iy || iy == 0x7f800000) | ||
| 69 | 		return m&1 ? -pi/2 : pi/2; | ||
| 70 | |||
| 71 | 	/* z = atan(|y/x|) with correct underflow */ | ||
| 72 | 	if ((m&2) && iy+(26<<23) < ix) /*|y/x| < 0x1p-26, x < 0 */ | ||
| 73 | 		z = 0.0; | ||
| 74 | 	else | ||
| 75 | 		z = atanf(fabsf(y/x)); | ||
| 76 | 	switch (m) { | ||
| 77 | 	case 0: return z; /* atan(+,+) */ | ||
| 78 | 	case 1: return -z; /* atan(-,+) */ | ||
| 79 | 	case 2: return pi - (z-pi_lo); /* atan(+,-) */ | ||
| 80 | 	default: /* case 3 */ | ||
| 81 | 		return (z-pi_lo) - pi; /* atan(-,-) */ | ||
| 82 | 	} | ||
| 83 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/atan2l.c created+85| ... | @@ -0,0 +1,85 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_atan2l.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 | */ | ||
| 13 | /* | ||
| 14 | * See comments in atan2.c. | ||
| 15 | * Converted to long double by David Schultz <das@FreeBSD.ORG>. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "libm.h" | ||
| 19 | |||
| 20 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 21 | long double atan2l(long double y, long double x) | ||
| 22 | { | ||
| 23 | 	return atan2(y, x); | ||
| 24 | } | ||
| 25 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 26 | #include "__invtrigl.h" | ||
| 27 | |||
| 28 | long double atan2l(long double y, long double x) | ||
| 29 | { | ||
| 30 | 	union ldshape ux, uy; | ||
| 31 | 	long double z; | ||
| 32 | 	int m, ex, ey; | ||
| 33 | |||
| 34 | 	if (isnan(x) || isnan(y)) | ||
| 35 | 		return x+y; | ||
| 36 | 	if (x == 1) | ||
| 37 | 		return atanl(y); | ||
| 38 | 	ux.f = x; | ||
| 39 | 	uy.f = y; | ||
| 40 | 	ex = ux.i.se & 0x7fff; | ||
| 41 | 	ey = uy.i.se & 0x7fff; | ||
| 42 | 	m = 2*(ux.i.se>>15) | uy.i.se>>15; | ||
| 43 | 	if (y == 0) { | ||
| 44 | 		switch(m) { | ||
| 45 | 		case 0: | ||
| 46 | 		case 1: return y; /* atan(+-0,+anything)=+-0 */ | ||
| 47 | 		case 2: return 2*pio2_hi; /* atan(+0,-anything) = pi */ | ||
| 48 | 		case 3: return -2*pio2_hi; /* atan(-0,-anything) =-pi */ | ||
| 49 | 		} | ||
| 50 | 	} | ||
| 51 | 	if (x == 0) | ||
| 52 | 		return m&1 ? -pio2_hi : pio2_hi; | ||
| 53 | 	if (ex == 0x7fff) { | ||
| 54 | 		if (ey == 0x7fff) { | ||
| 55 | 			switch(m) { | ||
| 56 | 			case 0: return pio2_hi/2; /* atan(+INF,+INF) */ | ||
| 57 | 			case 1: return -pio2_hi/2; /* atan(-INF,+INF) */ | ||
| 58 | 			case 2: return 1.5*pio2_hi; /* atan(+INF,-INF) */ | ||
| 59 | 			case 3: return -1.5*pio2_hi; /* atan(-INF,-INF) */ | ||
| 60 | 			} | ||
| 61 | 		} else { | ||
| 62 | 			switch(m) { | ||
| 63 | 			case 0: return 0.0; /* atan(+...,+INF) */ | ||
| 64 | 			case 1: return -0.0; /* atan(-...,+INF) */ | ||
| 65 | 			case 2: return 2*pio2_hi; /* atan(+...,-INF) */ | ||
| 66 | 			case 3: return -2*pio2_hi; /* atan(-...,-INF) */ | ||
| 67 | 			} | ||
| 68 | 		} | ||
| 69 | 	} | ||
| 70 | 	if (ex+120 < ey || ey == 0x7fff) | ||
| 71 | 		return m&1 ? -pio2_hi : pio2_hi; | ||
| 72 | 	/* z = atan(|y/x|) without spurious underflow */ | ||
| 73 | 	if ((m&2) && ey+120 < ex) /* |y/x| < 0x1p-120, x<0 */ | ||
| 74 | 		z = 0.0; | ||
| 75 | 	else | ||
| 76 | 		z = atanl(fabsl(y/x)); | ||
| 77 | 	switch (m) { | ||
| 78 | 	case 0: return z; /* atan(+,+) */ | ||
| 79 | 	case 1: return -z; /* atan(-,+) */ | ||
| 80 | 	case 2: return 2*pio2_hi-(z-2*pio2_lo); /* atan(+,-) */ | ||
| 81 | 	default: /* case 3 */ | ||
| 82 | 		return (z-2*pio2_lo)-2*pio2_hi; /* atan(-,-) */ | ||
| 83 | 	} | ||
| 84 | } | ||
| 85 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/atanf.c created+94| ... | @@ -0,0 +1,94 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_atanf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | static const float atanhi[] = { | ||
| 20 | 4.6364760399e-01, /* atan(0.5)hi 0x3eed6338 */ | ||
| 21 | 7.8539812565e-01, /* atan(1.0)hi 0x3f490fda */ | ||
| 22 | 9.8279368877e-01, /* atan(1.5)hi 0x3f7b985e */ | ||
| 23 | 1.5707962513e+00, /* atan(inf)hi 0x3fc90fda */ | ||
| 24 | }; | ||
| 25 | |||
| 26 | static const float atanlo[] = { | ||
| 27 | 5.0121582440e-09, /* atan(0.5)lo 0x31ac3769 */ | ||
| 28 | 3.7748947079e-08, /* atan(1.0)lo 0x33222168 */ | ||
| 29 | 3.4473217170e-08, /* atan(1.5)lo 0x33140fb4 */ | ||
| 30 | 7.5497894159e-08, /* atan(inf)lo 0x33a22168 */ | ||
| 31 | }; | ||
| 32 | |||
| 33 | static const float aT[] = { | ||
| 34 | 3.3333328366e-01, | ||
| 35 | -1.9999158382e-01, | ||
| 36 | 1.4253635705e-01, | ||
| 37 | -1.0648017377e-01, | ||
| 38 | 6.1687607318e-02, | ||
| 39 | }; | ||
| 40 | |||
| 41 | float atanf(float x) | ||
| 42 | { | ||
| 43 | 	float_t w,s1,s2,z; | ||
| 44 | 	uint32_t ix,sign; | ||
| 45 | 	int id; | ||
| 46 | |||
| 47 | 	GET_FLOAT_WORD(ix, x); | ||
| 48 | 	sign = ix>>31; | ||
| 49 | 	ix &= 0x7fffffff; | ||
| 50 | 	if (ix >= 0x4c800000) { /* if |x| >= 2**26 */ | ||
| 51 | 		if (isnan(x)) | ||
| 52 | 			return x; | ||
| 53 | 		z = atanhi[3] + 0x1p-120f; | ||
| 54 | 		return sign ? -z : z; | ||
| 55 | 	} | ||
| 56 | 	if (ix < 0x3ee00000) { /* |x| < 0.4375 */ | ||
| 57 | 		if (ix < 0x39800000) { /* |x| < 2**-12 */ | ||
| 58 | 			if (ix < 0x00800000) | ||
| 59 | 				/* raise underflow for subnormal x */ | ||
| 60 | 				FORCE_EVAL(x*x); | ||
| 61 | 			return x; | ||
| 62 | 		} | ||
| 63 | 		id = -1; | ||
| 64 | 	} else { | ||
| 65 | 		x = fabsf(x); | ||
| 66 | 		if (ix < 0x3f980000) { /* |x| < 1.1875 */ | ||
| 67 | 			if (ix < 0x3f300000) { /* 7/16 <= |x| < 11/16 */ | ||
| 68 | 				id = 0; | ||
| 69 | 				x = (2.0f*x - 1.0f)/(2.0f + x); | ||
| 70 | 			} else { /* 11/16 <= |x| < 19/16 */ | ||
| 71 | 				id = 1; | ||
| 72 | 				x = (x - 1.0f)/(x + 1.0f); | ||
| 73 | 			} | ||
| 74 | 		} else { | ||
| 75 | 			if (ix < 0x401c0000) { /* |x| < 2.4375 */ | ||
| 76 | 				id = 2; | ||
| 77 | 				x = (x - 1.5f)/(1.0f + 1.5f*x); | ||
| 78 | 			} else { /* 2.4375 <= |x| < 2**26 */ | ||
| 79 | 				id = 3; | ||
| 80 | 				x = -1.0f/x; | ||
| 81 | 			} | ||
| 82 | 		} | ||
| 83 | 	} | ||
| 84 | 	/* end of argument reduction */ | ||
| 85 | 	z = x*x; | ||
| 86 | 	w = z*z; | ||
| 87 | 	/* break sum from i=0 to 10 aT[i]z**(i+1) into odd and even poly */ | ||
| 88 | 	s1 = z*(aT[0]+w*(aT[2]+w*aT[4])); | ||
| 89 | 	s2 = w*(aT[1]+w*aT[3]); | ||
| 90 | 	if (id < 0) | ||
| 91 | 		return x - x*(s1+s2); | ||
| 92 | 	z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); | ||
| 93 | 	return sign ? -z : z; | ||
| 94 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/atanh.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ | ||
| 4 | double atanh(double x) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} u = {.f = x}; | ||
| 7 | 	unsigned e = u.i >> 52 & 0x7ff; | ||
| 8 | 	unsigned s = u.i >> 63; | ||
| 9 | 	double_t y; | ||
| 10 | |||
| 11 | 	/* |x| */ | ||
| 12 | 	u.i &= (uint64_t)-1/2; | ||
| 13 | 	y = u.f; | ||
| 14 | |||
| 15 | 	if (e < 0x3ff - 1) { | ||
| 16 | 		if (e < 0x3ff - 32) { | ||
| 17 | 			/* handle underflow */ | ||
| 18 | 			if (e == 0) | ||
| 19 | 				FORCE_EVAL((float)y); | ||
| 20 | 		} else { | ||
| 21 | 			/* |x| < 0.5, up to 1.7ulp error */ | ||
| 22 | 			y = 0.5*log1p(2*y + 2*y*y/(1-y)); | ||
| 23 | 		} | ||
| 24 | 	} else { | ||
| 25 | 		/* avoid overflow */ | ||
| 26 | 		y = 0.5*log1p(2*(y/(1-y))); | ||
| 27 | 	} | ||
| 28 | 	return s ? -y : y; | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/atanhf.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ | ||
| 4 | float atanhf(float x) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} u = {.f = x}; | ||
| 7 | 	unsigned s = u.i >> 31; | ||
| 8 | 	float_t y; | ||
| 9 | |||
| 10 | 	/* |x| */ | ||
| 11 | 	u.i &= 0x7fffffff; | ||
| 12 | 	y = u.f; | ||
| 13 | |||
| 14 | 	if (u.i < 0x3f800000 - (1<<23)) { | ||
| 15 | 		if (u.i < 0x3f800000 - (32<<23)) { | ||
| 16 | 			/* handle underflow */ | ||
| 17 | 			if (u.i < (1<<23)) | ||
| 18 | 				FORCE_EVAL((float)(y*y)); | ||
| 19 | 		} else { | ||
| 20 | 			/* |x| < 0.5, up to 1.7ulp error */ | ||
| 21 | 			y = 0.5f*log1pf(2*y + 2*y*y/(1-y)); | ||
| 22 | 		} | ||
| 23 | 	} else { | ||
| 24 | 		/* avoid overflow */ | ||
| 25 | 		y = 0.5f*log1pf(2*(y/(1-y))); | ||
| 26 | 	} | ||
| 27 | 	return s ? -y : y; | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/atanhl.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double atanhl(long double x) | ||
| 5 | { | ||
| 6 | 	return atanh(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | /* atanh(x) = log((1+x)/(1-x))/2 = log1p(2x/(1-x))/2 ~= x + x^3/3 + o(x^5) */ | ||
| 10 | long double atanhl(long double x) | ||
| 11 | { | ||
| 12 | 	union ldshape u = {x}; | ||
| 13 | 	unsigned e = u.i.se & 0x7fff; | ||
| 14 | 	unsigned s = u.i.se >> 15; | ||
| 15 | |||
| 16 | 	/* |x| */ | ||
| 17 | 	u.i.se = e; | ||
| 18 | 	x = u.f; | ||
| 19 | |||
| 20 | 	if (e < 0x3ff - 1) { | ||
| 21 | 		if (e < 0x3ff - LDBL_MANT_DIG/2) { | ||
| 22 | 			/* handle underflow */ | ||
| 23 | 			if (e == 0) | ||
| 24 | 				FORCE_EVAL((float)x); | ||
| 25 | 		} else { | ||
| 26 | 			/* |x| < 0.5, up to 1.7ulp error */ | ||
| 27 | 			x = 0.5*log1pl(2*x + 2*x*x/(1-x)); | ||
| 28 | 		} | ||
| 29 | 	} else { | ||
| 30 | 		/* avoid overflow */ | ||
| 31 | 		x = 0.5*log1pl(2*(x/(1-x))); | ||
| 32 | 	} | ||
| 33 | 	return s ? -x : x; | ||
| 34 | } | ||
| 35 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/atanl.c created+184| ... | @@ -0,0 +1,184 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_atanl.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* | ||
| 13 | * See comments in atan.c. | ||
| 14 | * Converted to long double by David Schultz <das@FreeBSD.ORG>. | ||
| 15 | */ | ||
| 16 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 20 | long double atanl(long double x) | ||
| 21 | { | ||
| 22 | 	return atan(x); | ||
| 23 | } | ||
| 24 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 25 | |||
| 26 | #if LDBL_MANT_DIG == 64 | ||
| 27 | #define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | (u.i.m>>55 & 0xff)) | ||
| 28 | |||
| 29 | static const long double atanhi[] = { | ||
| 30 | 	 4.63647609000806116202e-01L, | ||
| 31 | 	 7.85398163397448309628e-01L, | ||
| 32 | 	 9.82793723247329067960e-01L, | ||
| 33 | 	 1.57079632679489661926e+00L, | ||
| 34 | }; | ||
| 35 | |||
| 36 | static const long double atanlo[] = { | ||
| 37 | 	 1.18469937025062860669e-20L, | ||
| 38 | 	-1.25413940316708300586e-20L, | ||
| 39 | 	 2.55232234165405176172e-20L, | ||
| 40 | 	-2.50827880633416601173e-20L, | ||
| 41 | }; | ||
| 42 | |||
| 43 | static const long double aT[] = { | ||
| 44 | 	 3.33333333333333333017e-01L, | ||
| 45 | 	-1.99999999999999632011e-01L, | ||
| 46 | 	 1.42857142857046531280e-01L, | ||
| 47 | 	-1.11111111100562372733e-01L, | ||
| 48 | 	 9.09090902935647302252e-02L, | ||
| 49 | 	-7.69230552476207730353e-02L, | ||
| 50 | 	 6.66661718042406260546e-02L, | ||
| 51 | 	-5.88158892835030888692e-02L, | ||
| 52 | 	 5.25499891539726639379e-02L, | ||
| 53 | 	-4.70119845393155721494e-02L, | ||
| 54 | 	 4.03539201366454414072e-02L, | ||
| 55 | 	-2.91303858419364158725e-02L, | ||
| 56 | 	 1.24822046299269234080e-02L, | ||
| 57 | }; | ||
| 58 | |||
| 59 | static long double T_even(long double x) | ||
| 60 | { | ||
| 61 | 	return aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + | ||
| 62 | 		x * (aT[8] + x * (aT[10] + x * aT[12]))))); | ||
| 63 | } | ||
| 64 | |||
| 65 | static long double T_odd(long double x) | ||
| 66 | { | ||
| 67 | 	return aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + | ||
| 68 | 		x * (aT[9] + x * aT[11])))); | ||
| 69 | } | ||
| 70 | #elif LDBL_MANT_DIG == 113 | ||
| 71 | #define EXPMAN(u) ((u.i.se & 0x7fff)<<8 | u.i.top>>8) | ||
| 72 | |||
| 73 | static const long double atanhi[] = { | ||
| 74 | 	 4.63647609000806116214256231461214397e-01L, | ||
| 75 | 	 7.85398163397448309615660845819875699e-01L, | ||
| 76 | 	 9.82793723247329067985710611014666038e-01L, | ||
| 77 | 	 1.57079632679489661923132169163975140e+00L, | ||
| 78 | }; | ||
| 79 | |||
| 80 | static const long double atanlo[] = { | ||
| 81 | 	 4.89509642257333492668618435220297706e-36L, | ||
| 82 | 	 2.16795253253094525619926100651083806e-35L, | ||
| 83 | 	-2.31288434538183565909319952098066272e-35L, | ||
| 84 | 	 4.33590506506189051239852201302167613e-35L, | ||
| 85 | }; | ||
| 86 | |||
| 87 | static const long double aT[] = { | ||
| 88 | 	 3.33333333333333333333333333333333125e-01L, | ||
| 89 | 	-1.99999999999999999999999999999180430e-01L, | ||
| 90 | 	 1.42857142857142857142857142125269827e-01L, | ||
| 91 | 	-1.11111111111111111111110834490810169e-01L, | ||
| 92 | 	 9.09090909090909090908522355708623681e-02L, | ||
| 93 | 	-7.69230769230769230696553844935357021e-02L, | ||
| 94 | 	 6.66666666666666660390096773046256096e-02L, | ||
| 95 | 	-5.88235294117646671706582985209643694e-02L, | ||
| 96 | 	 5.26315789473666478515847092020327506e-02L, | ||
| 97 | 	-4.76190476189855517021024424991436144e-02L, | ||
| 98 | 	 4.34782608678695085948531993458097026e-02L, | ||
| 99 | 	-3.99999999632663469330634215991142368e-02L, | ||
| 100 | 	 3.70370363987423702891250829918659723e-02L, | ||
| 101 | 	-3.44827496515048090726669907612335954e-02L, | ||
| 102 | 	 3.22579620681420149871973710852268528e-02L, | ||
| 103 | 	-3.03020767654269261041647570626778067e-02L, | ||
| 104 | 	 2.85641979882534783223403715930946138e-02L, | ||
| 105 | 	-2.69824879726738568189929461383741323e-02L, | ||
| 106 | 	 2.54194698498808542954187110873675769e-02L, | ||
| 107 | 	-2.35083879708189059926183138130183215e-02L, | ||
| 108 | 	 2.04832358998165364349957325067131428e-02L, | ||
| 109 | 	-1.54489555488544397858507248612362957e-02L, | ||
| 110 | 	 8.64492360989278761493037861575248038e-03L, | ||
| 111 | 	-2.58521121597609872727919154569765469e-03L, | ||
| 112 | }; | ||
| 113 | |||
| 114 | static long double T_even(long double x) | ||
| 115 | { | ||
| 116 | 	return (aT[0] + x * (aT[2] + x * (aT[4] + x * (aT[6] + x * (aT[8] + | ||
| 117 | 		x * (aT[10] + x * (aT[12] + x * (aT[14] + x * (aT[16] + | ||
| 118 | 		x * (aT[18] + x * (aT[20] + x * aT[22]))))))))))); | ||
| 119 | } | ||
| 120 | |||
| 121 | static long double T_odd(long double x) | ||
| 122 | { | ||
| 123 | 	return (aT[1] + x * (aT[3] + x * (aT[5] + x * (aT[7] + x * (aT[9] + | ||
| 124 | 		x * (aT[11] + x * (aT[13] + x * (aT[15] + x * (aT[17] + | ||
| 125 | 		x * (aT[19] + x * (aT[21] + x * aT[23]))))))))))); | ||
| 126 | } | ||
| 127 | #endif | ||
| 128 | |||
| 129 | long double atanl(long double x) | ||
| 130 | { | ||
| 131 | 	union ldshape u = {x}; | ||
| 132 | 	long double w, s1, s2, z; | ||
| 133 | 	int id; | ||
| 134 | 	unsigned e = u.i.se & 0x7fff; | ||
| 135 | 	unsigned sign = u.i.se >> 15; | ||
| 136 | 	unsigned expman; | ||
| 137 | |||
| 138 | 	if (e >= 0x3fff + LDBL_MANT_DIG + 1) { /* if |x| is large, atan(x)~=pi/2 */ | ||
| 139 | 		if (isnan(x)) | ||
| 140 | 			return x; | ||
| 141 | 		return sign ? -atanhi[3] : atanhi[3]; | ||
| 142 | 	} | ||
| 143 | 	/* Extract the exponent and the first few bits of the mantissa. */ | ||
| 144 | 	expman = EXPMAN(u); | ||
| 145 | 	if (expman < ((0x3fff - 2) << 8) + 0xc0) { /* |x| < 0.4375 */ | ||
| 146 | 		if (e < 0x3fff - (LDBL_MANT_DIG+1)/2) { /* if |x| is small, atanl(x)~=x */ | ||
| 147 | 			/* raise underflow if subnormal */ | ||
| 148 | 			if (e == 0) | ||
| 149 | 				FORCE_EVAL((float)x); | ||
| 150 | 			return x; | ||
| 151 | 		} | ||
| 152 | 		id = -1; | ||
| 153 | 	} else { | ||
| 154 | 		x = fabsl(x); | ||
| 155 | 		if (expman < (0x3fff << 8) + 0x30) { /* |x| < 1.1875 */ | ||
| 156 | 			if (expman < ((0x3fff - 1) << 8) + 0x60) { /* 7/16 <= |x| < 11/16 */ | ||
| 157 | 				id = 0; | ||
| 158 | 				x = (2.0*x-1.0)/(2.0+x); | ||
| 159 | 			} else { /* 11/16 <= |x| < 19/16 */ | ||
| 160 | 				id = 1; | ||
| 161 | 				x = (x-1.0)/(x+1.0); | ||
| 162 | 			} | ||
| 163 | 		} else { | ||
| 164 | 			if (expman < ((0x3fff + 1) << 8) + 0x38) { /* |x| < 2.4375 */ | ||
| 165 | 				id = 2; | ||
| 166 | 				x = (x-1.5)/(1.0+1.5*x); | ||
| 167 | 			} else { /* 2.4375 <= |x| */ | ||
| 168 | 				id = 3; | ||
| 169 | 				x = -1.0/x; | ||
| 170 | 			} | ||
| 171 | 		} | ||
| 172 | 	} | ||
| 173 | 	/* end of argument reduction */ | ||
| 174 | 	z = x*x; | ||
| 175 | 	w = z*z; | ||
| 176 | 	/* break sum aT[i]z**(i+1) into odd and even poly */ | ||
| 177 | 	s1 = z*T_even(w); | ||
| 178 | 	s2 = w*T_odd(w); | ||
| 179 | 	if (id < 0) | ||
| 180 | 		return x - x*(s1+s2); | ||
| 181 | 	z = atanhi[id] - ((x*(s1+s2) - atanlo[id]) - x); | ||
| 182 | 	return sign ? -z : z; | ||
| 183 | } | ||
| 184 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/cbrt.c created+103| ... | @@ -0,0 +1,103 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cbrt.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* cbrt(x) | ||
| 15 | * Return cube root of x | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include <math.h> | ||
| 19 | #include <stdint.h> | ||
| 20 | |||
| 21 | static const uint32_t | ||
| 22 | B1 = 715094163, /* B1 = (1023-1023/3-0.03306235651)*2**20 */ | ||
| 23 | B2 = 696219795; /* B2 = (1023-1023/3-54/3-0.03306235651)*2**20 */ | ||
| 24 | |||
| 25 | /* |1/cbrt(x) - p(x)| < 2**-23.5 (~[-7.93e-8, 7.929e-8]). */ | ||
| 26 | static const double | ||
| 27 | P0 = 1.87595182427177009643, /* 0x3ffe03e6, 0x0f61e692 */ | ||
| 28 | P1 = -1.88497979543377169875, /* 0xbffe28e0, 0x92f02420 */ | ||
| 29 | P2 = 1.621429720105354466140, /* 0x3ff9f160, 0x4a49d6c2 */ | ||
| 30 | P3 = -0.758397934778766047437, /* 0xbfe844cb, 0xbee751d9 */ | ||
| 31 | P4 = 0.145996192886612446982; /* 0x3fc2b000, 0xd4e4edd7 */ | ||
| 32 | |||
| 33 | double cbrt(double x) | ||
| 34 | { | ||
| 35 | 	union {double f; uint64_t i;} u = {x}; | ||
| 36 | 	double_t r,s,t,w; | ||
| 37 | 	uint32_t hx = u.i>>32 & 0x7fffffff; | ||
| 38 | |||
| 39 | 	if (hx >= 0x7ff00000) /* cbrt(NaN,INF) is itself */ | ||
| 40 | 		return x+x; | ||
| 41 | |||
| 42 | 	/* | ||
| 43 | 	 * Rough cbrt to 5 bits: | ||
| 44 | 	 * cbrt(2**e*(1+m) ~= 2**(e/3)*(1+(e%3+m)/3) | ||
| 45 | 	 * where e is integral and >= 0, m is real and in [0, 1), and "/" and | ||
| 46 | 	 * "%" are integer division and modulus with rounding towards minus | ||
| 47 | 	 * infinity. The RHS is always >= the LHS and has a maximum relative | ||
| 48 | 	 * error of about 1 in 16. Adding a bias of -0.03306235651 to the | ||
| 49 | 	 * (e%3+m)/3 term reduces the error to about 1 in 32. With the IEEE | ||
| 50 | 	 * floating point representation, for finite positive normal values, | ||
| 51 | 	 * ordinary integer divison of the value in bits magically gives | ||
| 52 | 	 * almost exactly the RHS of the above provided we first subtract the | ||
| 53 | 	 * exponent bias (1023 for doubles) and later add it back. We do the | ||
| 54 | 	 * subtraction virtually to keep e >= 0 so that ordinary integer | ||
| 55 | 	 * division rounds towards minus infinity; this is also efficient. | ||
| 56 | 	 */ | ||
| 57 | 	if (hx < 0x00100000) { /* zero or subnormal? */ | ||
| 58 | 		u.f = x*0x1p54; | ||
| 59 | 		hx = u.i>>32 & 0x7fffffff; | ||
| 60 | 		if (hx == 0) | ||
| 61 | 			return x; /* cbrt(0) is itself */ | ||
| 62 | 		hx = hx/3 + B2; | ||
| 63 | 	} else | ||
| 64 | 		hx = hx/3 + B1; | ||
| 65 | 	u.i &= 1ULL<<63; | ||
| 66 | 	u.i |= (uint64_t)hx << 32; | ||
| 67 | 	t = u.f; | ||
| 68 | |||
| 69 | 	/* | ||
| 70 | 	 * New cbrt to 23 bits: | ||
| 71 | 	 * cbrt(x) = t*cbrt(x/t**3) ~= t*P(t**3/x) | ||
| 72 | 	 * where P(r) is a polynomial of degree 4 that approximates 1/cbrt(r) | ||
| 73 | 	 * to within 2**-23.5 when |r - 1| < 1/10. The rough approximation | ||
| 74 | 	 * has produced t such than |t/cbrt(x) - 1| ~< 1/32, and cubing this | ||
| 75 | 	 * gives us bounds for r = t**3/x. | ||
| 76 | 	 * | ||
| 77 | 	 * Try to optimize for parallel evaluation as in __tanf.c. | ||
| 78 | 	 */ | ||
| 79 | 	r = (t*t)*(t/x); | ||
| 80 | 	t = t*((P0+r*(P1+r*P2))+((r*r)*r)*(P3+r*P4)); | ||
| 81 | |||
| 82 | 	/* | ||
| 83 | 	 * Round t away from zero to 23 bits (sloppily except for ensuring that | ||
| 84 | 	 * the result is larger in magnitude than cbrt(x) but not much more than | ||
| 85 | 	 * 2 23-bit ulps larger). With rounding towards zero, the error bound | ||
| 86 | 	 * would be ~5/6 instead of ~4/6. With a maximum error of 2 23-bit ulps | ||
| 87 | 	 * in the rounded t, the infinite-precision error in the Newton | ||
| 88 | 	 * approximation barely affects third digit in the final error | ||
| 89 | 	 * 0.667; the error in the rounded t can be up to about 3 23-bit ulps | ||
| 90 | 	 * before the final error is larger than 0.667 ulps. | ||
| 91 | 	 */ | ||
| 92 | 	u.f = t; | ||
| 93 | 	u.i = (u.i + 0x80000000) & 0xffffffffc0000000ULL; | ||
| 94 | 	t = u.f; | ||
| 95 | |||
| 96 | 	/* one step Newton iteration to 53 bits with error < 0.667 ulps */ | ||
| 97 | 	s = t*t; /* t*t is exact */ | ||
| 98 | 	r = x/s; /* error <= 0.5 ulps; |r| < |t| */ | ||
| 99 | 	w = t+t; /* t+t is exact */ | ||
| 100 | 	r = (r-t)/(w+r); /* r-t is exact; w+r ~= 3*t */ | ||
| 101 | 	t = t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */ | ||
| 102 | 	return t; | ||
| 103 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/cbrtf.c created+66| ... | @@ -0,0 +1,66 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtf.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 | /* cbrtf(x) | ||
| 17 | * Return cube root of x | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <math.h> | ||
| 21 | #include <stdint.h> | ||
| 22 | |||
| 23 | static const unsigned | ||
| 24 | B1 = 709958130, /* B1 = (127-127.0/3-0.03306235651)*2**23 */ | ||
| 25 | B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */ | ||
| 26 | |||
| 27 | float cbrtf(float x) | ||
| 28 | { | ||
| 29 | 	double_t r,T; | ||
| 30 | 	union {float f; uint32_t i;} u = {x}; | ||
| 31 | 	uint32_t hx = u.i & 0x7fffffff; | ||
| 32 | |||
| 33 | 	if (hx >= 0x7f800000) /* cbrt(NaN,INF) is itself */ | ||
| 34 | 		return x + x; | ||
| 35 | |||
| 36 | 	/* rough cbrt to 5 bits */ | ||
| 37 | 	if (hx < 0x00800000) { /* zero or subnormal? */ | ||
| 38 | 		if (hx == 0) | ||
| 39 | 			return x; /* cbrt(+-0) is itself */ | ||
| 40 | 		u.f = x*0x1p24f; | ||
| 41 | 		hx = u.i & 0x7fffffff; | ||
| 42 | 		hx = hx/3 + B2; | ||
| 43 | 	} else | ||
| 44 | 		hx = hx/3 + B1; | ||
| 45 | 	u.i &= 0x80000000; | ||
| 46 | 	u.i |= hx; | ||
| 47 | |||
| 48 | 	/* | ||
| 49 | 	 * First step Newton iteration (solving t*t-x/t == 0) to 16 bits. In | ||
| 50 | 	 * double precision so that its terms can be arranged for efficiency | ||
| 51 | 	 * without causing overflow or underflow. | ||
| 52 | 	 */ | ||
| 53 | 	T = u.f; | ||
| 54 | 	r = T*T*T; | ||
| 55 | 	T = T*((double_t)x+x+r)/(x+r+r); | ||
| 56 | |||
| 57 | 	/* | ||
| 58 | 	 * Second step Newton iteration to 47 bits. In double precision for | ||
| 59 | 	 * efficiency and accuracy. | ||
| 60 | 	 */ | ||
| 61 | 	r = T*T*T; | ||
| 62 | 	T = T*((double_t)x+x+r)/(x+r+r); | ||
| 63 | |||
| 64 | 	/* rounding to 24 bits is perfect in round-to-nearest mode */ | ||
| 65 | 	return T; | ||
| 66 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/cbrtl.c created+124| ... | @@ -0,0 +1,124 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cbrtl.c */ | ||
| 2 | /*- | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * Copyright (c) 2009-2011, Bruce D. Evans, Steven G. Kargl, David Schultz. | ||
| 6 | * | ||
| 7 | * Developed at SunPro, 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 | * The argument reduction and testing for exceptional cases was | ||
| 14 | * written by Steven G. Kargl with input from Bruce D. Evans | ||
| 15 | * and David A. Schultz. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #include "libm.h" | ||
| 19 | |||
| 20 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 21 | long double cbrtl(long double x) | ||
| 22 | { | ||
| 23 | 	return cbrt(x); | ||
| 24 | } | ||
| 25 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 26 | static const unsigned B1 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */ | ||
| 27 | |||
| 28 | long double cbrtl(long double x) | ||
| 29 | { | ||
| 30 | 	union ldshape u = {x}, v; | ||
| 31 | 	union {float f; uint32_t i;} uft; | ||
| 32 | 	long double r, s, t, w; | ||
| 33 | 	double_t dr, dt, dx; | ||
| 34 | 	float_t ft; | ||
| 35 | 	int e = u.i.se & 0x7fff; | ||
| 36 | 	int sign = u.i.se & 0x8000; | ||
| 37 | |||
| 38 | 	/* | ||
| 39 | 	 * If x = +-Inf, then cbrt(x) = +-Inf. | ||
| 40 | 	 * If x = NaN, then cbrt(x) = NaN. | ||
| 41 | 	 */ | ||
| 42 | 	if (e == 0x7fff) | ||
| 43 | 		return x + x; | ||
| 44 | 	if (e == 0) { | ||
| 45 | 		/* Adjust subnormal numbers. */ | ||
| 46 | 		u.f *= 0x1p120; | ||
| 47 | 		e = u.i.se & 0x7fff; | ||
| 48 | 		/* If x = +-0, then cbrt(x) = +-0. */ | ||
| 49 | 		if (e == 0) | ||
| 50 | 			return x; | ||
| 51 | 		e -= 120; | ||
| 52 | 	} | ||
| 53 | 	e -= 0x3fff; | ||
| 54 | 	u.i.se = 0x3fff; | ||
| 55 | 	x = u.f; | ||
| 56 | 	switch (e % 3) { | ||
| 57 | 	case 1: | ||
| 58 | 	case -2: | ||
| 59 | 		x *= 2; | ||
| 60 | 		e--; | ||
| 61 | 		break; | ||
| 62 | 	case 2: | ||
| 63 | 	case -1: | ||
| 64 | 		x *= 4; | ||
| 65 | 		e -= 2; | ||
| 66 | 		break; | ||
| 67 | 	} | ||
| 68 | 	v.f = 1.0; | ||
| 69 | 	v.i.se = sign | (0x3fff + e/3); | ||
| 70 | |||
| 71 | 	/* | ||
| 72 | 	 * The following is the guts of s_cbrtf, with the handling of | ||
| 73 | 	 * special values removed and extra care for accuracy not taken, | ||
| 74 | 	 * but with most of the extra accuracy not discarded. | ||
| 75 | 	 */ | ||
| 76 | |||
| 77 | 	/* ~5-bit estimate: */ | ||
| 78 | 	uft.f = x; | ||
| 79 | 	uft.i = (uft.i & 0x7fffffff)/3 + B1; | ||
| 80 | 	ft = uft.f; | ||
| 81 | |||
| 82 | 	/* ~16-bit estimate: */ | ||
| 83 | 	dx = x; | ||
| 84 | 	dt = ft; | ||
| 85 | 	dr = dt * dt * dt; | ||
| 86 | 	dt = dt * (dx + dx + dr) / (dx + dr + dr); | ||
| 87 | |||
| 88 | 	/* ~47-bit estimate: */ | ||
| 89 | 	dr = dt * dt * dt; | ||
| 90 | 	dt = dt * (dx + dx + dr) / (dx + dr + dr); | ||
| 91 | |||
| 92 | #if LDBL_MANT_DIG == 64 | ||
| 93 | 	/* | ||
| 94 | 	 * dt is cbrtl(x) to ~47 bits (after x has been reduced to 1 <= x < 8). | ||
| 95 | 	 * Round it away from zero to 32 bits (32 so that t*t is exact, and | ||
| 96 | 	 * away from zero for technical reasons). | ||
| 97 | 	 */ | ||
| 98 | 	t = dt + (0x1.0p32L + 0x1.0p-31L) - 0x1.0p32; | ||
| 99 | #elif LDBL_MANT_DIG == 113 | ||
| 100 | 	/* | ||
| 101 | 	 * Round dt away from zero to 47 bits. Since we don't trust the 47, | ||
| 102 | 	 * add 2 47-bit ulps instead of 1 to round up. Rounding is slow and | ||
| 103 | 	 * might be avoidable in this case, since on most machines dt will | ||
| 104 | 	 * have been evaluated in 53-bit precision and the technical reasons | ||
| 105 | 	 * for rounding up might not apply to either case in cbrtl() since | ||
| 106 | 	 * dt is much more accurate than needed. | ||
| 107 | 	 */ | ||
| 108 | 	t = dt + 0x2.0p-46 + 0x1.0p60L - 0x1.0p60; | ||
| 109 | #endif | ||
| 110 | |||
| 111 | 	/* | ||
| 112 | 	 * Final step Newton iteration to 64 or 113 bits with | ||
| 113 | 	 * error < 0.667 ulps | ||
| 114 | 	 */ | ||
| 115 | 	s = t*t; /* t*t is exact */ | ||
| 116 | 	r = x/s; /* error <= 0.5 ulps; |r| < |t| */ | ||
| 117 | 	w = t+t; /* t+t is exact */ | ||
| 118 | 	r = (r-t)/(w+r); /* r-t is exact; w+r ~= 3*t */ | ||
| 119 | 	t = t+t*r; /* error <= 0.5 + 0.5/3 + epsilon */ | ||
| 120 | |||
| 121 | 	t *= v.f; | ||
| 122 | 	return t; | ||
| 123 | } | ||
| 124 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/ceil.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 4 | #define EPS DBL_EPSILON | ||
| 5 | #elif FLT_EVAL_METHOD==2 | ||
| 6 | #define EPS LDBL_EPSILON | ||
| 7 | #endif | ||
| 8 | static const double_t toint = 1/EPS; | ||
| 9 | |||
| 10 | double ceil(double x) | ||
| 11 | { | ||
| 12 | 	union {double f; uint64_t i;} u = {x}; | ||
| 13 | 	int e = u.i >> 52 & 0x7ff; | ||
| 14 | 	double_t y; | ||
| 15 | |||
| 16 | 	if (e >= 0x3ff+52 || x == 0) | ||
| 17 | 		return x; | ||
| 18 | 	/* y = int(x) - x, where int(x) is an integer neighbor of x */ | ||
| 19 | 	if (u.i >> 63) | ||
| 20 | 		y = x - toint + toint - x; | ||
| 21 | 	else | ||
| 22 | 		y = x + toint - toint - x; | ||
| 23 | 	/* special case because of non-nearest rounding modes */ | ||
| 24 | 	if (e <= 0x3ff-1) { | ||
| 25 | 		FORCE_EVAL(y); | ||
| 26 | 		return u.i >> 63 ? -0.0 : 1; | ||
| 27 | 	} | ||
| 28 | 	if (y < 0) | ||
| 29 | 		return x + y + 1; | ||
| 30 | 	return x + y; | ||
| 31 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ceilf.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float ceilf(float x) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {x}; | ||
| 6 | 	int e = (int)(u.i >> 23 & 0xff) - 0x7f; | ||
| 7 | 	uint32_t m; | ||
| 8 | |||
| 9 | 	if (e >= 23) | ||
| 10 | 		return x; | ||
| 11 | 	if (e >= 0) { | ||
| 12 | 		m = 0x007fffff >> e; | ||
| 13 | 		if ((u.i & m) == 0) | ||
| 14 | 			return x; | ||
| 15 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 16 | 		if (u.i >> 31 == 0) | ||
| 17 | 			u.i += m; | ||
| 18 | 		u.i &= ~m; | ||
| 19 | 	} else { | ||
| 20 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 21 | 		if (u.i >> 31) | ||
| 22 | 			u.f = -0.0; | ||
| 23 | 		else if (u.i << 1) | ||
| 24 | 			u.f = 1.0; | ||
| 25 | 	} | ||
| 26 | 	return u.f; | ||
| 27 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ceill.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double ceill(long double x) | ||
| 5 | { | ||
| 6 | 	return ceil(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | |||
| 10 | static const long double toint = 1/LDBL_EPSILON; | ||
| 11 | |||
| 12 | long double ceill(long double x) | ||
| 13 | { | ||
| 14 | 	union ldshape u = {x}; | ||
| 15 | 	int e = u.i.se & 0x7fff; | ||
| 16 | 	long double y; | ||
| 17 | |||
| 18 | 	if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0) | ||
| 19 | 		return x; | ||
| 20 | 	/* y = int(x) - x, where int(x) is an integer neighbor of x */ | ||
| 21 | 	if (u.i.se >> 15) | ||
| 22 | 		y = x - toint + toint - x; | ||
| 23 | 	else | ||
| 24 | 		y = x + toint - toint - x; | ||
| 25 | 	/* special case because of non-nearest rounding modes */ | ||
| 26 | 	if (e <= 0x3fff-1) { | ||
| 27 | 		FORCE_EVAL(y); | ||
| 28 | 		return u.i.se >> 15 ? -0.0 : 1; | ||
| 29 | 	} | ||
| 30 | 	if (y < 0) | ||
| 31 | 		return x + y + 1; | ||
| 32 | 	return x + y; | ||
| 33 | } | ||
| 34 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/copysign.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double copysign(double x, double y) { | ||
| 4 | 	union {double f; uint64_t i;} ux={x}, uy={y}; | ||
| 5 | 	ux.i &= -1ULL/2; | ||
| 6 | 	ux.i |= uy.i & 1ULL<<63; | ||
| 7 | 	return ux.f; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/copysignf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float copysignf(float x, float y) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} ux={x}, uy={y}; | ||
| 7 | 	ux.i &= 0x7fffffff; | ||
| 8 | 	ux.i |= uy.i & 0x80000000; | ||
| 9 | 	return ux.f; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/copysignl.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double copysignl(long double x, long double y) | ||
| 5 | { | ||
| 6 | 	return copysign(x, y); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double copysignl(long double x, long double y) | ||
| 10 | { | ||
| 11 | 	union ldshape ux = {x}, uy = {y}; | ||
| 12 | 	ux.i.se &= 0x7fff; | ||
| 13 | 	ux.i.se |= uy.i.se & 0x8000; | ||
| 14 | 	return ux.f; | ||
| 15 | } | ||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/cos.c created+77| ... | @@ -0,0 +1,77 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* cos(x) | ||
| 13 | * Return cosine function of x. | ||
| 14 | * | ||
| 15 | * kernel function: | ||
| 16 | * __sin ... sine function on [-pi/4,pi/4] | ||
| 17 | * __cos ... cosine function on [-pi/4,pi/4] | ||
| 18 | * __rem_pio2 ... argument reduction routine | ||
| 19 | * | ||
| 20 | * Method. | ||
| 21 | * Let S,C and T denote the sin, cos and tan respectively on | ||
| 22 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 | ||
| 23 | * in [-pi/4 , +pi/4], and let n = k mod 4. | ||
| 24 | * We have | ||
| 25 | * | ||
| 26 | * n sin(x) cos(x) tan(x) | ||
| 27 | * ---------------------------------------------------------- | ||
| 28 | * 0 S C T | ||
| 29 | * 1 C -S -1/T | ||
| 30 | * 2 -S -C T | ||
| 31 | * 3 -C S -1/T | ||
| 32 | * ---------------------------------------------------------- | ||
| 33 | * | ||
| 34 | * Special cases: | ||
| 35 | * Let trig be any of sin, cos, or tan. | ||
| 36 | * trig(+-INF) is NaN, with signals; | ||
| 37 | * trig(NaN) is that NaN; | ||
| 38 | * | ||
| 39 | * Accuracy: | ||
| 40 | * TRIG(x) returns trig(x) nearly rounded | ||
| 41 | */ | ||
| 42 | |||
| 43 | #include "libm.h" | ||
| 44 | |||
| 45 | double cos(double x) | ||
| 46 | { | ||
| 47 | 	double y[2]; | ||
| 48 | 	uint32_t ix; | ||
| 49 | 	unsigned n; | ||
| 50 | |||
| 51 | 	GET_HIGH_WORD(ix, x); | ||
| 52 | 	ix &= 0x7fffffff; | ||
| 53 | |||
| 54 | 	/* |x| ~< pi/4 */ | ||
| 55 | 	if (ix <= 0x3fe921fb) { | ||
| 56 | 		if (ix < 0x3e46a09e) { /* |x| < 2**-27 * sqrt(2) */ | ||
| 57 | 			/* raise inexact if x!=0 */ | ||
| 58 | 			FORCE_EVAL(x + 0x1p120f); | ||
| 59 | 			return 1.0; | ||
| 60 | 		} | ||
| 61 | 		return __cos(x, 0); | ||
| 62 | 	} | ||
| 63 | |||
| 64 | 	/* cos(Inf or NaN) is NaN */ | ||
| 65 | 	if (ix >= 0x7ff00000) | ||
| 66 | 		return x-x; | ||
| 67 | |||
| 68 | 	/* argument reduction */ | ||
| 69 | 	n = __rem_pio2(x, y); | ||
| 70 | 	switch (n&3) { | ||
| 71 | 	case 0: return __cos(y[0], y[1]); | ||
| 72 | 	case 1: return -__sin(y[0], y[1], 1); | ||
| 73 | 	case 2: return -__cos(y[0], y[1]); | ||
| 74 | 	default: | ||
| 75 | 		return __sin(y[0], y[1], 1); | ||
| 76 | 	} | ||
| 77 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/cosf.c created+78| ... | @@ -0,0 +1,78 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_cosf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * 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 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | /* Small multiples of pi/2 rounded to double precision. */ | ||
| 20 | static const double | ||
| 21 | c1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ | ||
| 22 | c2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ | ||
| 23 | c3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ | ||
| 24 | c4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ | ||
| 25 | |||
| 26 | float cosf(float x) | ||
| 27 | { | ||
| 28 | 	double y; | ||
| 29 | 	uint32_t ix; | ||
| 30 | 	unsigned n, sign; | ||
| 31 | |||
| 32 | 	GET_FLOAT_WORD(ix, x); | ||
| 33 | 	sign = ix >> 31; | ||
| 34 | 	ix &= 0x7fffffff; | ||
| 35 | |||
| 36 | 	if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ | ||
| 37 | 		if (ix < 0x39800000) { /* |x| < 2**-12 */ | ||
| 38 | 			/* raise inexact if x != 0 */ | ||
| 39 | 			FORCE_EVAL(x + 0x1p120f); | ||
| 40 | 			return 1.0f; | ||
| 41 | 		} | ||
| 42 | 		return __cosdf(x); | ||
| 43 | 	} | ||
| 44 | 	if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */ | ||
| 45 | 		if (ix > 0x4016cbe3) /* |x| ~> 3*pi/4 */ | ||
| 46 | 			return -__cosdf(sign ? x+c2pio2 : x-c2pio2); | ||
| 47 | 		else { | ||
| 48 | 			if (sign) | ||
| 49 | 				return __sindf(x + c1pio2); | ||
| 50 | 			else | ||
| 51 | 				return __sindf(c1pio2 - x); | ||
| 52 | 		} | ||
| 53 | 	} | ||
| 54 | 	if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */ | ||
| 55 | 		if (ix > 0x40afeddf) /* |x| ~> 7*pi/4 */ | ||
| 56 | 			return __cosdf(sign ? x+c4pio2 : x-c4pio2); | ||
| 57 | 		else { | ||
| 58 | 			if (sign) | ||
| 59 | 				return __sindf(-x - c3pio2); | ||
| 60 | 			else | ||
| 61 | 				return __sindf(x - c3pio2); | ||
| 62 | 		} | ||
| 63 | 	} | ||
| 64 | |||
| 65 | 	/* cos(Inf or NaN) is NaN */ | ||
| 66 | 	if (ix >= 0x7f800000) | ||
| 67 | 		return x-x; | ||
| 68 | |||
| 69 | 	/* general argument reduction needed */ | ||
| 70 | 	n = __rem_pio2f(x,&y); | ||
| 71 | 	switch (n&3) { | ||
| 72 | 	case 0: return __cosdf(y); | ||
| 73 | 	case 1: return __sindf(-y); | ||
| 74 | 	case 2: return -__cosdf(y); | ||
| 75 | 	default: | ||
| 76 | 		return __sindf(y); | ||
| 77 | 	} | ||
| 78 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/cosh.c created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* cosh(x) = (exp(x) + 1/exp(x))/2 | ||
| 4 | * = 1 + 0.5*(exp(x)-1)*(exp(x)-1)/exp(x) | ||
| 5 | * = 1 + x*x/2 + o(x^4) | ||
| 6 | */ | ||
| 7 | double cosh(double x) | ||
| 8 | { | ||
| 9 | 	union {double f; uint64_t i;} u = {.f = x}; | ||
| 10 | 	uint32_t w; | ||
| 11 | 	double t; | ||
| 12 | |||
| 13 | 	/* |x| */ | ||
| 14 | 	u.i &= (uint64_t)-1/2; | ||
| 15 | 	x = u.f; | ||
| 16 | 	w = u.i >> 32; | ||
| 17 | |||
| 18 | 	/* |x| < log(2) */ | ||
| 19 | 	if (w < 0x3fe62e42) { | ||
| 20 | 		if (w < 0x3ff00000 - (26<<20)) { | ||
| 21 | 			/* raise inexact if x!=0 */ | ||
| 22 | 			FORCE_EVAL(x + 0x1p120f); | ||
| 23 | 			return 1; | ||
| 24 | 		} | ||
| 25 | 		t = expm1(x); | ||
| 26 | 		return 1 + t*t/(2*(1+t)); | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	/* |x| < log(DBL_MAX) */ | ||
| 30 | 	if (w < 0x40862e42) { | ||
| 31 | 		t = exp(x); | ||
| 32 | 		/* note: if x>log(0x1p26) then the 1/t is not needed */ | ||
| 33 | 		return 0.5*(t + 1/t); | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	/* |x| > log(DBL_MAX) or nan */ | ||
| 37 | 	/* note: the result is stored to handle overflow */ | ||
| 38 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 39 | 	t = __expo2(x, 1.0); | ||
| 40 | #else | ||
| 41 | 	t = __expo2(x); | ||
| 42 | #endif | ||
| 43 | 	return t; | ||
| 44 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/coshf.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float coshf(float x) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {.f = x}; | ||
| 6 | 	uint32_t w; | ||
| 7 | 	float t; | ||
| 8 | |||
| 9 | 	/* |x| */ | ||
| 10 | 	u.i &= 0x7fffffff; | ||
| 11 | 	x = u.f; | ||
| 12 | 	w = u.i; | ||
| 13 | |||
| 14 | 	/* |x| < log(2) */ | ||
| 15 | 	if (w < 0x3f317217) { | ||
| 16 | 		if (w < 0x3f800000 - (12<<23)) { | ||
| 17 | 			FORCE_EVAL(x + 0x1p120f); | ||
| 18 | 			return 1; | ||
| 19 | 		} | ||
| 20 | 		t = expm1f(x); | ||
| 21 | 		return 1 + t*t/(2*(1+t)); | ||
| 22 | 	} | ||
| 23 | |||
| 24 | 	/* |x| < log(FLT_MAX) */ | ||
| 25 | 	if (w < 0x42b17217) { | ||
| 26 | 		t = expf(x); | ||
| 27 | 		return 0.5f*(t + 1/t); | ||
| 28 | 	} | ||
| 29 | |||
| 30 | 	/* |x| > log(FLT_MAX) or nan */ | ||
| 31 | #ifdef __wasilibc_unmodified_upstream // Wasm doesn't have alternate rounding modes | ||
| 32 | 	t = __expo2f(x, 1.0f); | ||
| 33 | #else | ||
| 34 | 	t = __expo2f(x); | ||
| 35 | #endif | ||
| 36 | 	return t; | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/coshl.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double coshl(long double x) | ||
| 5 | { | ||
| 6 | 	return cosh(x); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | long double coshl(long double x) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	unsigned ex = u.i.se & 0x7fff; | ||
| 13 | 	uint32_t w; | ||
| 14 | 	long double t; | ||
| 15 | |||
| 16 | 	/* |x| */ | ||
| 17 | 	u.i.se = ex; | ||
| 18 | 	x = u.f; | ||
| 19 | 	w = u.i.m >> 32; | ||
| 20 | |||
| 21 | 	/* |x| < log(2) */ | ||
| 22 | 	if (ex < 0x3fff-1 || (ex == 0x3fff-1 && w < 0xb17217f7)) { | ||
| 23 | 		if (ex < 0x3fff-32) { | ||
| 24 | 			FORCE_EVAL(x + 0x1p120f); | ||
| 25 | 			return 1; | ||
| 26 | 		} | ||
| 27 | 		t = expm1l(x); | ||
| 28 | 		return 1 + t*t/(2*(1+t)); | ||
| 29 | 	} | ||
| 30 | |||
| 31 | 	/* |x| < log(LDBL_MAX) */ | ||
| 32 | 	if (ex < 0x3fff+13 || (ex == 0x3fff+13 && w < 0xb17217f7)) { | ||
| 33 | 		t = expl(x); | ||
| 34 | 		return 0.5*(t + 1/t); | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	/* |x| > log(LDBL_MAX) or nan */ | ||
| 38 | 	t = expl(0.5*x); | ||
| 39 | 	return 0.5*t*t; | ||
| 40 | } | ||
| 41 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 42 | // TODO: broken implementation to make things compile | ||
| 43 | long double coshl(long double x) | ||
| 44 | { | ||
| 45 | 	return cosh(x); | ||
| 46 | } | ||
| 47 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/cosl.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double cosl(long double x) { | ||
| 5 | 	return cos(x); | ||
| 6 | } | ||
| 7 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 8 | long double cosl(long double x) | ||
| 9 | { | ||
| 10 | 	union ldshape u = {x}; | ||
| 11 | 	unsigned n; | ||
| 12 | 	long double y[2], hi, lo; | ||
| 13 | |||
| 14 | 	u.i.se &= 0x7fff; | ||
| 15 | 	if (u.i.se == 0x7fff) | ||
| 16 | 		return x - x; | ||
| 17 | 	x = u.f; | ||
| 18 | 	if (x < M_PI_4) { | ||
| 19 | 		if (u.i.se < 0x3fff - LDBL_MANT_DIG) | ||
| 20 | 			/* raise inexact if x!=0 */ | ||
| 21 | 			return 1.0 + x; | ||
| 22 | 		return __cosl(x, 0); | ||
| 23 | 	} | ||
| 24 | 	n = __rem_pio2l(x, y); | ||
| 25 | 	hi = y[0]; | ||
| 26 | 	lo = y[1]; | ||
| 27 | 	switch (n & 3) { | ||
| 28 | 	case 0: | ||
| 29 | 		return __cosl(hi, lo); | ||
| 30 | 	case 1: | ||
| 31 | 		return -__sinl(hi, lo, 1); | ||
| 32 | 	case 2: | ||
| 33 | 		return -__cosl(hi, lo); | ||
| 34 | 	case 3: | ||
| 35 | 	default: | ||
| 36 | 		return __sinl(hi, lo, 1); | ||
| 37 | 	} | ||
| 38 | } | ||
| 39 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/erf.c created+273| ... | @@ -0,0 +1,273 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_erf.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* double erf(double x) | ||
| 13 | * double erfc(double x) | ||
| 14 | * x | ||
| 15 | * 2 |\ | ||
| 16 | * erf(x) = --------- | exp(-t*t)dt | ||
| 17 | * sqrt(pi) \| | ||
| 18 | * 0 | ||
| 19 | * | ||
| 20 | * erfc(x) = 1-erf(x) | ||
| 21 | * Note that | ||
| 22 | * erf(-x) = -erf(x) | ||
| 23 | * erfc(-x) = 2 - erfc(x) | ||
| 24 | * | ||
| 25 | * Method: | ||
| 26 | * 1. For |x| in [0, 0.84375] | ||
| 27 | * erf(x) = x + x*R(x^2) | ||
| 28 | * erfc(x) = 1 - erf(x) if x in [-.84375,0.25] | ||
| 29 | * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375] | ||
| 30 | * where R = P/Q where P is an odd poly of degree 8 and | ||
| 31 | * Q is an odd poly of degree 10. | ||
| 32 | * -57.90 | ||
| 33 | * | R - (erf(x)-x)/x | <= 2 | ||
| 34 | * | ||
| 35 | * | ||
| 36 | * Remark. The formula is derived by noting | ||
| 37 | * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....) | ||
| 38 | * and that | ||
| 39 | * 2/sqrt(pi) = 1.128379167095512573896158903121545171688 | ||
| 40 | * is close to one. The interval is chosen because the fix | ||
| 41 | * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is | ||
| 42 | * near 0.6174), and by some experiment, 0.84375 is chosen to | ||
| 43 | * guarantee the error is less than one ulp for erf. | ||
| 44 | * | ||
| 45 | * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and | ||
| 46 | * c = 0.84506291151 rounded to single (24 bits) | ||
| 47 | * erf(x) = sign(x) * (c + P1(s)/Q1(s)) | ||
| 48 | * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0 | ||
| 49 | * 1+(c+P1(s)/Q1(s)) if x < 0 | ||
| 50 | * |P1/Q1 - (erf(|x|)-c)| <= 2**-59.06 | ||
| 51 | * Remark: here we use the taylor series expansion at x=1. | ||
| 52 | * erf(1+s) = erf(1) + s*Poly(s) | ||
| 53 | * = 0.845.. + P1(s)/Q1(s) | ||
| 54 | * That is, we use rational approximation to approximate | ||
| 55 | * erf(1+s) - (c = (single)0.84506291151) | ||
| 56 | * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25] | ||
| 57 | * where | ||
| 58 | * P1(s) = degree 6 poly in s | ||
| 59 | * Q1(s) = degree 6 poly in s | ||
| 60 | * | ||
| 61 | * 3. For x in [1.25,1/0.35(~2.857143)], | ||
| 62 | * erfc(x) = (1/x)*exp(-x*x-0.5625+R1/S1) | ||
| 63 | * erf(x) = 1 - erfc(x) | ||
| 64 | * where | ||
| 65 | * R1(z) = degree 7 poly in z, (z=1/x^2) | ||
| 66 | * S1(z) = degree 8 poly in z | ||
| 67 | * | ||
| 68 | * 4. For x in [1/0.35,28] | ||
| 69 | * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0 | ||
| 70 | * = 2.0 - (1/x)*exp(-x*x-0.5625+R2/S2) if -6<x<0 | ||
| 71 | * = 2.0 - tiny (if x <= -6) | ||
| 72 | * erf(x) = sign(x)*(1.0 - erfc(x)) if x < 6, else | ||
| 73 | * erf(x) = sign(x)*(1.0 - tiny) | ||
| 74 | * where | ||
| 75 | * R2(z) = degree 6 poly in z, (z=1/x^2) | ||
| 76 | * S2(z) = degree 7 poly in z | ||
| 77 | * | ||
| 78 | * Note1: | ||
| 79 | * To compute exp(-x*x-0.5625+R/S), let s be a single | ||
| 80 | * precision number and s := x; then | ||
| 81 | * -x*x = -s*s + (s-x)*(s+x) | ||
| 82 | * exp(-x*x-0.5626+R/S) = | ||
| 83 | * exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S); | ||
| 84 | * Note2: | ||
| 85 | * Here 4 and 5 make use of the asymptotic series | ||
| 86 | * exp(-x*x) | ||
| 87 | * erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) ) | ||
| 88 | * x*sqrt(pi) | ||
| 89 | * We use rational approximation to approximate | ||
| 90 | * g(s)=f(1/x^2) = log(erfc(x)*x) - x*x + 0.5625 | ||
| 91 | * Here is the error bound for R1/S1 and R2/S2 | ||
| 92 | * |R1/S1 - f(x)| < 2**(-62.57) | ||
| 93 | * |R2/S2 - f(x)| < 2**(-61.52) | ||
| 94 | * | ||
| 95 | * 5. For inf > x >= 28 | ||
| 96 | * erf(x) = sign(x) *(1 - tiny) (raise inexact) | ||
| 97 | * erfc(x) = tiny*tiny (raise underflow) if x > 0 | ||
| 98 | * = 2 - tiny if x<0 | ||
| 99 | * | ||
| 100 | * 7. Special case: | ||
| 101 | * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1, | ||
| 102 | * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, | ||
| 103 | * erfc/erf(NaN) is NaN | ||
| 104 | */ | ||
| 105 | |||
| 106 | #include "libm.h" | ||
| 107 | |||
| 108 | static const double | ||
| 109 | erx = 8.45062911510467529297e-01, /* 0x3FEB0AC1, 0x60000000 */ | ||
| 110 | /* | ||
| 111 | * Coefficients for approximation to erf on [0,0.84375] | ||
| 112 | */ | ||
| 113 | efx8 = 1.02703333676410069053e+00, /* 0x3FF06EBA, 0x8214DB69 */ | ||
| 114 | pp0 = 1.28379167095512558561e-01, /* 0x3FC06EBA, 0x8214DB68 */ | ||
| 115 | pp1 = -3.25042107247001499370e-01, /* 0xBFD4CD7D, 0x691CB913 */ | ||
| 116 | pp2 = -2.84817495755985104766e-02, /* 0xBF9D2A51, 0xDBD7194F */ | ||
| 117 | pp3 = -5.77027029648944159157e-03, /* 0xBF77A291, 0x236668E4 */ | ||
| 118 | pp4 = -2.37630166566501626084e-05, /* 0xBEF8EAD6, 0x120016AC */ | ||
| 119 | qq1 = 3.97917223959155352819e-01, /* 0x3FD97779, 0xCDDADC09 */ | ||
| 120 | qq2 = 6.50222499887672944485e-02, /* 0x3FB0A54C, 0x5536CEBA */ | ||
| 121 | qq3 = 5.08130628187576562776e-03, /* 0x3F74D022, 0xC4D36B0F */ | ||
| 122 | qq4 = 1.32494738004321644526e-04, /* 0x3F215DC9, 0x221C1A10 */ | ||
| 123 | qq5 = -3.96022827877536812320e-06, /* 0xBED09C43, 0x42A26120 */ | ||
| 124 | /* | ||
| 125 | * Coefficients for approximation to erf in [0.84375,1.25] | ||
| 126 | */ | ||
| 127 | pa0 = -2.36211856075265944077e-03, /* 0xBF6359B8, 0xBEF77538 */ | ||
| 128 | pa1 = 4.14856118683748331666e-01, /* 0x3FDA8D00, 0xAD92B34D */ | ||
| 129 | pa2 = -3.72207876035701323847e-01, /* 0xBFD7D240, 0xFBB8C3F1 */ | ||
| 130 | pa3 = 3.18346619901161753674e-01, /* 0x3FD45FCA, 0x805120E4 */ | ||
| 131 | pa4 = -1.10894694282396677476e-01, /* 0xBFBC6398, 0x3D3E28EC */ | ||
| 132 | pa5 = 3.54783043256182359371e-02, /* 0x3FA22A36, 0x599795EB */ | ||
| 133 | pa6 = -2.16637559486879084300e-03, /* 0xBF61BF38, 0x0A96073F */ | ||
| 134 | qa1 = 1.06420880400844228286e-01, /* 0x3FBB3E66, 0x18EEE323 */ | ||
| 135 | qa2 = 5.40397917702171048937e-01, /* 0x3FE14AF0, 0x92EB6F33 */ | ||
| 136 | qa3 = 7.18286544141962662868e-02, /* 0x3FB2635C, 0xD99FE9A7 */ | ||
| 137 | qa4 = 1.26171219808761642112e-01, /* 0x3FC02660, 0xE763351F */ | ||
| 138 | qa5 = 1.36370839120290507362e-02, /* 0x3F8BEDC2, 0x6B51DD1C */ | ||
| 139 | qa6 = 1.19844998467991074170e-02, /* 0x3F888B54, 0x5735151D */ | ||
| 140 | /* | ||
| 141 | * Coefficients for approximation to erfc in [1.25,1/0.35] | ||
| 142 | */ | ||
| 143 | ra0 = -9.86494403484714822705e-03, /* 0xBF843412, 0x600D6435 */ | ||
| 144 | ra1 = -6.93858572707181764372e-01, /* 0xBFE63416, 0xE4BA7360 */ | ||
| 145 | ra2 = -1.05586262253232909814e+01, /* 0xC0251E04, 0x41B0E726 */ | ||
| 146 | ra3 = -6.23753324503260060396e+01, /* 0xC04F300A, 0xE4CBA38D */ | ||
| 147 | ra4 = -1.62396669462573470355e+02, /* 0xC0644CB1, 0x84282266 */ | ||
| 148 | ra5 = -1.84605092906711035994e+02, /* 0xC067135C, 0xEBCCABB2 */ | ||
| 149 | ra6 = -8.12874355063065934246e+01, /* 0xC0545265, 0x57E4D2F2 */ | ||
| 150 | ra7 = -9.81432934416914548592e+00, /* 0xC023A0EF, 0xC69AC25C */ | ||
| 151 | sa1 = 1.96512716674392571292e+01, /* 0x4033A6B9, 0xBD707687 */ | ||
| 152 | sa2 = 1.37657754143519042600e+02, /* 0x4061350C, 0x526AE721 */ | ||
| 153 | sa3 = 4.34565877475229228821e+02, /* 0x407B290D, 0xD58A1A71 */ | ||
| 154 | sa4 = 6.45387271733267880336e+02, /* 0x40842B19, 0x21EC2868 */ | ||
| 155 | sa5 = 4.29008140027567833386e+02, /* 0x407AD021, 0x57700314 */ | ||
| 156 | sa6 = 1.08635005541779435134e+02, /* 0x405B28A3, 0xEE48AE2C */ | ||
| 157 | sa7 = 6.57024977031928170135e+00, /* 0x401A47EF, 0x8E484A93 */ | ||
| 158 | sa8 = -6.04244152148580987438e-02, /* 0xBFAEEFF2, 0xEE749A62 */ | ||
| 159 | /* | ||
| 160 | * Coefficients for approximation to erfc in [1/.35,28] | ||
| 161 | */ | ||
| 162 | rb0 = -9.86494292470009928597e-03, /* 0xBF843412, 0x39E86F4A */ | ||
| 163 | rb1 = -7.99283237680523006574e-01, /* 0xBFE993BA, 0x70C285DE */ | ||
| 164 | rb2 = -1.77579549177547519889e+01, /* 0xC031C209, 0x555F995A */ | ||
| 165 | rb3 = -1.60636384855821916062e+02, /* 0xC064145D, 0x43C5ED98 */ | ||
| 166 | rb4 = -6.37566443368389627722e+02, /* 0xC083EC88, 0x1375F228 */ | ||
| 167 | rb5 = -1.02509513161107724954e+03, /* 0xC0900461, 0x6A2E5992 */ | ||
| 168 | rb6 = -4.83519191608651397019e+02, /* 0xC07E384E, 0x9BDC383F */ | ||
| 169 | sb1 = 3.03380607434824582924e+01, /* 0x403E568B, 0x261D5190 */ | ||
| 170 | sb2 = 3.25792512996573918826e+02, /* 0x40745CAE, 0x221B9F0A */ | ||
| 171 | sb3 = 1.53672958608443695994e+03, /* 0x409802EB, 0x189D5118 */ | ||
| 172 | sb4 = 3.19985821950859553908e+03, /* 0x40A8FFB7, 0x688C246A */ | ||
| 173 | sb5 = 2.55305040643316442583e+03, /* 0x40A3F219, 0xCEDF3BE6 */ | ||
| 174 | sb6 = 4.74528541206955367215e+02, /* 0x407DA874, 0xE79FE763 */ | ||
| 175 | sb7 = -2.24409524465858183362e+01; /* 0xC03670E2, 0x42712D62 */ | ||
| 176 | |||
| 177 | static double erfc1(double x) | ||
| 178 | { | ||
| 179 | 	double_t s,P,Q; | ||
| 180 | |||
| 181 | 	s = fabs(x) - 1; | ||
| 182 | 	P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); | ||
| 183 | 	Q = 1+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); | ||
| 184 | 	return 1 - erx - P/Q; | ||
| 185 | } | ||
| 186 | |||
| 187 | static double erfc2(uint32_t ix, double x) | ||
| 188 | { | ||
| 189 | 	double_t s,R,S; | ||
| 190 | 	double z; | ||
| 191 | |||
| 192 | 	if (ix < 0x3ff40000) /* |x| < 1.25 */ | ||
| 193 | 		return erfc1(x); | ||
| 194 | |||
| 195 | 	x = fabs(x); | ||
| 196 | 	s = 1/(x*x); | ||
| 197 | 	if (ix < 0x4006db6d) { /* |x| < 1/.35 ~ 2.85714 */ | ||
| 198 | 		R = ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( | ||
| 199 | 		 ra5+s*(ra6+s*ra7)))))); | ||
| 200 | 		S = 1.0+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( | ||
| 201 | 		 sa5+s*(sa6+s*(sa7+s*sa8))))))); | ||
| 202 | 	} else { /* |x| > 1/.35 */ | ||
| 203 | 		R = rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( | ||
| 204 | 		 rb5+s*rb6))))); | ||
| 205 | 		S = 1.0+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( | ||
| 206 | 		 sb5+s*(sb6+s*sb7)))))); | ||
| 207 | 	} | ||
| 208 | 	z = x; | ||
| 209 | 	SET_LOW_WORD(z,0); | ||
| 210 | 	return exp(-z*z-0.5625)*exp((z-x)*(z+x)+R/S)/x; | ||
| 211 | } | ||
| 212 | |||
| 213 | double erf(double x) | ||
| 214 | { | ||
| 215 | 	double r,s,z,y; | ||
| 216 | 	uint32_t ix; | ||
| 217 | 	int sign; | ||
| 218 | |||
| 219 | 	GET_HIGH_WORD(ix, x); | ||
| 220 | 	sign = ix>>31; | ||
| 221 | 	ix &= 0x7fffffff; | ||
| 222 | 	if (ix >= 0x7ff00000) { | ||
| 223 | 		/* erf(nan)=nan, erf(+-inf)=+-1 */ | ||
| 224 | 		return 1-2*sign + 1/x; | ||
| 225 | 	} | ||
| 226 | 	if (ix < 0x3feb0000) { /* |x| < 0.84375 */ | ||
| 227 | 		if (ix < 0x3e300000) { /* |x| < 2**-28 */ | ||
| 228 | 			/* avoid underflow */ | ||
| 229 | 			return 0.125*(8*x + efx8*x); | ||
| 230 | 		} | ||
| 231 | 		z = x*x; | ||
| 232 | 		r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); | ||
| 233 | 		s = 1.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); | ||
| 234 | 		y = r/s; | ||
| 235 | 		return x + x*y; | ||
| 236 | 	} | ||
| 237 | 	if (ix < 0x40180000) /* 0.84375 <= |x| < 6 */ | ||
| 238 | 		y = 1 - erfc2(ix,x); | ||
| 239 | 	else | ||
| 240 | 		y = 1 - 0x1p-1022; | ||
| 241 | 	return sign ? -y : y; | ||
| 242 | } | ||
| 243 | |||
| 244 | double erfc(double x) | ||
| 245 | { | ||
| 246 | 	double r,s,z,y; | ||
| 247 | 	uint32_t ix; | ||
| 248 | 	int sign; | ||
| 249 | |||
| 250 | 	GET_HIGH_WORD(ix, x); | ||
| 251 | 	sign = ix>>31; | ||
| 252 | 	ix &= 0x7fffffff; | ||
| 253 | 	if (ix >= 0x7ff00000) { | ||
| 254 | 		/* erfc(nan)=nan, erfc(+-inf)=0,2 */ | ||
| 255 | 		return 2*sign + 1/x; | ||
| 256 | 	} | ||
| 257 | 	if (ix < 0x3feb0000) { /* |x| < 0.84375 */ | ||
| 258 | 		if (ix < 0x3c700000) /* |x| < 2**-56 */ | ||
| 259 | 			return 1.0 - x; | ||
| 260 | 		z = x*x; | ||
| 261 | 		r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); | ||
| 262 | 		s = 1.0+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); | ||
| 263 | 		y = r/s; | ||
| 264 | 		if (sign || ix < 0x3fd00000) { /* x < 1/4 */ | ||
| 265 | 			return 1.0 - (x+x*y); | ||
| 266 | 		} | ||
| 267 | 		return 0.5 - (x - 0.5 + x*y); | ||
| 268 | 	} | ||
| 269 | 	if (ix < 0x403c0000) { /* 0.84375 <= |x| < 28 */ | ||
| 270 | 		return sign ? 2 - erfc2(ix,x) : erfc2(ix,x); | ||
| 271 | 	} | ||
| 272 | 	return sign ? 2 - 0x1p-1022 : 0x1p-1022*0x1p-1022; | ||
| 273 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/erff.c created+183| ... | @@ -0,0 +1,183 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_erff.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | static const float | ||
| 19 | erx = 8.4506291151e-01, /* 0x3f58560b */ | ||
| 20 | /* | ||
| 21 | * Coefficients for approximation to erf on [0,0.84375] | ||
| 22 | */ | ||
| 23 | efx8 = 1.0270333290e+00, /* 0x3f8375d4 */ | ||
| 24 | pp0 = 1.2837916613e-01, /* 0x3e0375d4 */ | ||
| 25 | pp1 = -3.2504209876e-01, /* 0xbea66beb */ | ||
| 26 | pp2 = -2.8481749818e-02, /* 0xbce9528f */ | ||
| 27 | pp3 = -5.7702702470e-03, /* 0xbbbd1489 */ | ||
| 28 | pp4 = -2.3763017452e-05, /* 0xb7c756b1 */ | ||
| 29 | qq1 = 3.9791721106e-01, /* 0x3ecbbbce */ | ||
| 30 | qq2 = 6.5022252500e-02, /* 0x3d852a63 */ | ||
| 31 | qq3 = 5.0813062117e-03, /* 0x3ba68116 */ | ||
| 32 | qq4 = 1.3249473704e-04, /* 0x390aee49 */ | ||
| 33 | qq5 = -3.9602282413e-06, /* 0xb684e21a */ | ||
| 34 | /* | ||
| 35 | * Coefficients for approximation to erf in [0.84375,1.25] | ||
| 36 | */ | ||
| 37 | pa0 = -2.3621185683e-03, /* 0xbb1acdc6 */ | ||
| 38 | pa1 = 4.1485610604e-01, /* 0x3ed46805 */ | ||
| 39 | pa2 = -3.7220788002e-01, /* 0xbebe9208 */ | ||
| 40 | pa3 = 3.1834661961e-01, /* 0x3ea2fe54 */ | ||
| 41 | pa4 = -1.1089469492e-01, /* 0xbde31cc2 */ | ||
| 42 | pa5 = 3.5478305072e-02, /* 0x3d1151b3 */ | ||
| 43 | pa6 = -2.1663755178e-03, /* 0xbb0df9c0 */ | ||
| 44 | qa1 = 1.0642088205e-01, /* 0x3dd9f331 */ | ||
| 45 | qa2 = 5.4039794207e-01, /* 0x3f0a5785 */ | ||
| 46 | qa3 = 7.1828655899e-02, /* 0x3d931ae7 */ | ||
| 47 | qa4 = 1.2617121637e-01, /* 0x3e013307 */ | ||
| 48 | qa5 = 1.3637083583e-02, /* 0x3c5f6e13 */ | ||
| 49 | qa6 = 1.1984500103e-02, /* 0x3c445aa3 */ | ||
| 50 | /* | ||
| 51 | * Coefficients for approximation to erfc in [1.25,1/0.35] | ||
| 52 | */ | ||
| 53 | ra0 = -9.8649440333e-03, /* 0xbc21a093 */ | ||
| 54 | ra1 = -6.9385856390e-01, /* 0xbf31a0b7 */ | ||
| 55 | ra2 = -1.0558626175e+01, /* 0xc128f022 */ | ||
| 56 | ra3 = -6.2375331879e+01, /* 0xc2798057 */ | ||
| 57 | ra4 = -1.6239666748e+02, /* 0xc322658c */ | ||
| 58 | ra5 = -1.8460508728e+02, /* 0xc3389ae7 */ | ||
| 59 | ra6 = -8.1287437439e+01, /* 0xc2a2932b */ | ||
| 60 | ra7 = -9.8143291473e+00, /* 0xc11d077e */ | ||
| 61 | sa1 = 1.9651271820e+01, /* 0x419d35ce */ | ||
| 62 | sa2 = 1.3765776062e+02, /* 0x4309a863 */ | ||
| 63 | sa3 = 4.3456588745e+02, /* 0x43d9486f */ | ||
| 64 | sa4 = 6.4538726807e+02, /* 0x442158c9 */ | ||
| 65 | sa5 = 4.2900814819e+02, /* 0x43d6810b */ | ||
| 66 | sa6 = 1.0863500214e+02, /* 0x42d9451f */ | ||
| 67 | sa7 = 6.5702495575e+00, /* 0x40d23f7c */ | ||
| 68 | sa8 = -6.0424413532e-02, /* 0xbd777f97 */ | ||
| 69 | /* | ||
| 70 | * Coefficients for approximation to erfc in [1/.35,28] | ||
| 71 | */ | ||
| 72 | rb0 = -9.8649431020e-03, /* 0xbc21a092 */ | ||
| 73 | rb1 = -7.9928326607e-01, /* 0xbf4c9dd4 */ | ||
| 74 | rb2 = -1.7757955551e+01, /* 0xc18e104b */ | ||
| 75 | rb3 = -1.6063638306e+02, /* 0xc320a2ea */ | ||
| 76 | rb4 = -6.3756646729e+02, /* 0xc41f6441 */ | ||
| 77 | rb5 = -1.0250950928e+03, /* 0xc480230b */ | ||
| 78 | rb6 = -4.8351919556e+02, /* 0xc3f1c275 */ | ||
| 79 | sb1 = 3.0338060379e+01, /* 0x41f2b459 */ | ||
| 80 | sb2 = 3.2579251099e+02, /* 0x43a2e571 */ | ||
| 81 | sb3 = 1.5367296143e+03, /* 0x44c01759 */ | ||
| 82 | sb4 = 3.1998581543e+03, /* 0x4547fdbb */ | ||
| 83 | sb5 = 2.5530502930e+03, /* 0x451f90ce */ | ||
| 84 | sb6 = 4.7452853394e+02, /* 0x43ed43a7 */ | ||
| 85 | sb7 = -2.2440952301e+01; /* 0xc1b38712 */ | ||
| 86 | |||
| 87 | static float erfc1(float x) | ||
| 88 | { | ||
| 89 | 	float_t s,P,Q; | ||
| 90 | |||
| 91 | 	s = fabsf(x) - 1; | ||
| 92 | 	P = pa0+s*(pa1+s*(pa2+s*(pa3+s*(pa4+s*(pa5+s*pa6))))); | ||
| 93 | 	Q = 1+s*(qa1+s*(qa2+s*(qa3+s*(qa4+s*(qa5+s*qa6))))); | ||
| 94 | 	return 1 - erx - P/Q; | ||
| 95 | } | ||
| 96 | |||
| 97 | static float erfc2(uint32_t ix, float x) | ||
| 98 | { | ||
| 99 | 	float_t s,R,S; | ||
| 100 | 	float z; | ||
| 101 | |||
| 102 | 	if (ix < 0x3fa00000) /* |x| < 1.25 */ | ||
| 103 | 		return erfc1(x); | ||
| 104 | |||
| 105 | 	x = fabsf(x); | ||
| 106 | 	s = 1/(x*x); | ||
| 107 | 	if (ix < 0x4036db6d) { /* |x| < 1/0.35 */ | ||
| 108 | 		R = ra0+s*(ra1+s*(ra2+s*(ra3+s*(ra4+s*( | ||
| 109 | 		 ra5+s*(ra6+s*ra7)))))); | ||
| 110 | 		S = 1.0f+s*(sa1+s*(sa2+s*(sa3+s*(sa4+s*( | ||
| 111 | 		 sa5+s*(sa6+s*(sa7+s*sa8))))))); | ||
| 112 | 	} else { /* |x| >= 1/0.35 */ | ||
| 113 | 		R = rb0+s*(rb1+s*(rb2+s*(rb3+s*(rb4+s*( | ||
| 114 | 		 rb5+s*rb6))))); | ||
| 115 | 		S = 1.0f+s*(sb1+s*(sb2+s*(sb3+s*(sb4+s*( | ||
| 116 | 		 sb5+s*(sb6+s*sb7)))))); | ||
| 117 | 	} | ||
| 118 | 	GET_FLOAT_WORD(ix, x); | ||
| 119 | 	SET_FLOAT_WORD(z, ix&0xffffe000); | ||
| 120 | 	return expf(-z*z - 0.5625f) * expf((z-x)*(z+x) + R/S)/x; | ||
| 121 | } | ||
| 122 | |||
| 123 | float erff(float x) | ||
| 124 | { | ||
| 125 | 	float r,s,z,y; | ||
| 126 | 	uint32_t ix; | ||
| 127 | 	int sign; | ||
| 128 | |||
| 129 | 	GET_FLOAT_WORD(ix, x); | ||
| 130 | 	sign = ix>>31; | ||
| 131 | 	ix &= 0x7fffffff; | ||
| 132 | 	if (ix >= 0x7f800000) { | ||
| 133 | 		/* erf(nan)=nan, erf(+-inf)=+-1 */ | ||
| 134 | 		return 1-2*sign + 1/x; | ||
| 135 | 	} | ||
| 136 | 	if (ix < 0x3f580000) { /* |x| < 0.84375 */ | ||
| 137 | 		if (ix < 0x31800000) { /* |x| < 2**-28 */ | ||
| 138 | 			/*avoid underflow */ | ||
| 139 | 			return 0.125f*(8*x + efx8*x); | ||
| 140 | 		} | ||
| 141 | 		z = x*x; | ||
| 142 | 		r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); | ||
| 143 | 		s = 1+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); | ||
| 144 | 		y = r/s; | ||
| 145 | 		return x + x*y; | ||
| 146 | 	} | ||
| 147 | 	if (ix < 0x40c00000) /* |x| < 6 */ | ||
| 148 | 		y = 1 - erfc2(ix,x); | ||
| 149 | 	else | ||
| 150 | 		y = 1 - 0x1p-120f; | ||
| 151 | 	return sign ? -y : y; | ||
| 152 | } | ||
| 153 | |||
| 154 | float erfcf(float x) | ||
| 155 | { | ||
| 156 | 	float r,s,z,y; | ||
| 157 | 	uint32_t ix; | ||
| 158 | 	int sign; | ||
| 159 | |||
| 160 | 	GET_FLOAT_WORD(ix, x); | ||
| 161 | 	sign = ix>>31; | ||
| 162 | 	ix &= 0x7fffffff; | ||
| 163 | 	if (ix >= 0x7f800000) { | ||
| 164 | 		/* erfc(nan)=nan, erfc(+-inf)=0,2 */ | ||
| 165 | 		return 2*sign + 1/x; | ||
| 166 | 	} | ||
| 167 | |||
| 168 | 	if (ix < 0x3f580000) { /* |x| < 0.84375 */ | ||
| 169 | 		if (ix < 0x23800000) /* |x| < 2**-56 */ | ||
| 170 | 			return 1.0f - x; | ||
| 171 | 		z = x*x; | ||
| 172 | 		r = pp0+z*(pp1+z*(pp2+z*(pp3+z*pp4))); | ||
| 173 | 		s = 1.0f+z*(qq1+z*(qq2+z*(qq3+z*(qq4+z*qq5)))); | ||
| 174 | 		y = r/s; | ||
| 175 | 		if (sign || ix < 0x3e800000) /* x < 1/4 */ | ||
| 176 | 			return 1.0f - (x+x*y); | ||
| 177 | 		return 0.5f - (x - 0.5f + x*y); | ||
| 178 | 	} | ||
| 179 | 	if (ix < 0x41e00000) { /* |x| < 28 */ | ||
| 180 | 		return sign ? 2 - erfc2(ix,x) : erfc2(ix,x); | ||
| 181 | 	} | ||
| 182 | 	return sign ? 2 - 0x1p-120f : 0x1p-120f*0x1p-120f; | ||
| 183 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/erfl.c created+353| ... | @@ -0,0 +1,353 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_erfl.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* | ||
| 13 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 14 | * | ||
| 15 | * Permission to use, copy, modify, and distribute this software for any | ||
| 16 | * purpose with or without fee is hereby granted, provided that the above | ||
| 17 | * copyright notice and this permission notice appear in all copies. | ||
| 18 | * | ||
| 19 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 20 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 21 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 22 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 23 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 24 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 25 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 26 | */ | ||
| 27 | /* double erf(double x) | ||
| 28 | * double erfc(double x) | ||
| 29 | * x | ||
| 30 | * 2 |\ | ||
| 31 | * erf(x) = --------- | exp(-t*t)dt | ||
| 32 | * sqrt(pi) \| | ||
| 33 | * 0 | ||
| 34 | * | ||
| 35 | * erfc(x) = 1-erf(x) | ||
| 36 | * Note that | ||
| 37 | * erf(-x) = -erf(x) | ||
| 38 | * erfc(-x) = 2 - erfc(x) | ||
| 39 | * | ||
| 40 | * Method: | ||
| 41 | * 1. For |x| in [0, 0.84375] | ||
| 42 | * erf(x) = x + x*R(x^2) | ||
| 43 | * erfc(x) = 1 - erf(x) if x in [-.84375,0.25] | ||
| 44 | * = 0.5 + ((0.5-x)-x*R) if x in [0.25,0.84375] | ||
| 45 | * Remark. The formula is derived by noting | ||
| 46 | * erf(x) = (2/sqrt(pi))*(x - x^3/3 + x^5/10 - x^7/42 + ....) | ||
| 47 | * and that | ||
| 48 | * 2/sqrt(pi) = 1.128379167095512573896158903121545171688 | ||
| 49 | * is close to one. The interval is chosen because the fix | ||
| 50 | * point of erf(x) is near 0.6174 (i.e., erf(x)=x when x is | ||
| 51 | * near 0.6174), and by some experiment, 0.84375 is chosen to | ||
| 52 | * guarantee the error is less than one ulp for erf. | ||
| 53 | * | ||
| 54 | * 2. For |x| in [0.84375,1.25], let s = |x| - 1, and | ||
| 55 | * c = 0.84506291151 rounded to single (24 bits) | ||
| 56 | * erf(x) = sign(x) * (c + P1(s)/Q1(s)) | ||
| 57 | * erfc(x) = (1-c) - P1(s)/Q1(s) if x > 0 | ||
| 58 | * 1+(c+P1(s)/Q1(s)) if x < 0 | ||
| 59 | * Remark: here we use the taylor series expansion at x=1. | ||
| 60 | * erf(1+s) = erf(1) + s*Poly(s) | ||
| 61 | * = 0.845.. + P1(s)/Q1(s) | ||
| 62 | * Note that |P1/Q1|< 0.078 for x in [0.84375,1.25] | ||
| 63 | * | ||
| 64 | * 3. For x in [1.25,1/0.35(~2.857143)], | ||
| 65 | * erfc(x) = (1/x)*exp(-x*x-0.5625+R1(z)/S1(z)) | ||
| 66 | * z=1/x^2 | ||
| 67 | * erf(x) = 1 - erfc(x) | ||
| 68 | * | ||
| 69 | * 4. For x in [1/0.35,107] | ||
| 70 | * erfc(x) = (1/x)*exp(-x*x-0.5625+R2/S2) if x > 0 | ||
| 71 | * = 2.0 - (1/x)*exp(-x*x-0.5625+R2(z)/S2(z)) | ||
| 72 | * if -6.666<x<0 | ||
| 73 | * = 2.0 - tiny (if x <= -6.666) | ||
| 74 | * z=1/x^2 | ||
| 75 | * erf(x) = sign(x)*(1.0 - erfc(x)) if x < 6.666, else | ||
| 76 | * erf(x) = sign(x)*(1.0 - tiny) | ||
| 77 | * Note1: | ||
| 78 | * To compute exp(-x*x-0.5625+R/S), let s be a single | ||
| 79 | * precision number and s := x; then | ||
| 80 | * -x*x = -s*s + (s-x)*(s+x) | ||
| 81 | * exp(-x*x-0.5626+R/S) = | ||
| 82 | * exp(-s*s-0.5625)*exp((s-x)*(s+x)+R/S); | ||
| 83 | * Note2: | ||
| 84 | * Here 4 and 5 make use of the asymptotic series | ||
| 85 | * exp(-x*x) | ||
| 86 | * erfc(x) ~ ---------- * ( 1 + Poly(1/x^2) ) | ||
| 87 | * x*sqrt(pi) | ||
| 88 | * | ||
| 89 | * 5. For inf > x >= 107 | ||
| 90 | * erf(x) = sign(x) *(1 - tiny) (raise inexact) | ||
| 91 | * erfc(x) = tiny*tiny (raise underflow) if x > 0 | ||
| 92 | * = 2 - tiny if x<0 | ||
| 93 | * | ||
| 94 | * 7. Special case: | ||
| 95 | * erf(0) = 0, erf(inf) = 1, erf(-inf) = -1, | ||
| 96 | * erfc(0) = 1, erfc(inf) = 0, erfc(-inf) = 2, | ||
| 97 | * erfc/erf(NaN) is NaN | ||
| 98 | */ | ||
| 99 | |||
| 100 | |||
| 101 | #include "libm.h" | ||
| 102 | |||
| 103 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 104 | long double erfl(long double x) | ||
| 105 | { | ||
| 106 | 	return erf(x); | ||
| 107 | } | ||
| 108 | long double erfcl(long double x) | ||
| 109 | { | ||
| 110 | 	return erfc(x); | ||
| 111 | } | ||
| 112 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 113 | static const long double | ||
| 114 | erx = 0.845062911510467529296875L, | ||
| 115 | |||
| 116 | /* | ||
| 117 | * Coefficients for approximation to erf on [0,0.84375] | ||
| 118 | */ | ||
| 119 | /* 8 * (2/sqrt(pi) - 1) */ | ||
| 120 | efx8 = 1.0270333367641005911692712249723613735048E0L, | ||
| 121 | pp[6] = { | ||
| 122 | 	1.122751350964552113068262337278335028553E6L, | ||
| 123 | 	-2.808533301997696164408397079650699163276E6L, | ||
| 124 | 	-3.314325479115357458197119660818768924100E5L, | ||
| 125 | 	-6.848684465326256109712135497895525446398E4L, | ||
| 126 | 	-2.657817695110739185591505062971929859314E3L, | ||
| 127 | 	-1.655310302737837556654146291646499062882E2L, | ||
| 128 | }, | ||
| 129 | qq[6] = { | ||
| 130 | 	8.745588372054466262548908189000448124232E6L, | ||
| 131 | 	3.746038264792471129367533128637019611485E6L, | ||
| 132 | 	7.066358783162407559861156173539693900031E5L, | ||
| 133 | 	7.448928604824620999413120955705448117056E4L, | ||
| 134 | 	4.511583986730994111992253980546131408924E3L, | ||
| 135 | 	1.368902937933296323345610240009071254014E2L, | ||
| 136 | 	/* 1.000000000000000000000000000000000000000E0 */ | ||
| 137 | }, | ||
| 138 | |||
| 139 | /* | ||
| 140 | * Coefficients for approximation to erf in [0.84375,1.25] | ||
| 141 | */ | ||
| 142 | /* erf(x+1) = 0.845062911510467529296875 + pa(x)/qa(x) | ||
| 143 | -0.15625 <= x <= +.25 | ||
| 144 | Peak relative error 8.5e-22 */ | ||
| 145 | pa[8] = { | ||
| 146 | 	-1.076952146179812072156734957705102256059E0L, | ||
| 147 | 	 1.884814957770385593365179835059971587220E2L, | ||
| 148 | 	-5.339153975012804282890066622962070115606E1L, | ||
| 149 | 	 4.435910679869176625928504532109635632618E1L, | ||
| 150 | 	 1.683219516032328828278557309642929135179E1L, | ||
| 151 | 	-2.360236618396952560064259585299045804293E0L, | ||
| 152 | 	 1.852230047861891953244413872297940938041E0L, | ||
| 153 | 	 9.394994446747752308256773044667843200719E-2L, | ||
| 154 | }, | ||
| 155 | qa[7] = { | ||
| 156 | 	4.559263722294508998149925774781887811255E2L, | ||
| 157 | 	3.289248982200800575749795055149780689738E2L, | ||
| 158 | 	2.846070965875643009598627918383314457912E2L, | ||
| 159 | 	1.398715859064535039433275722017479994465E2L, | ||
| 160 | 	6.060190733759793706299079050985358190726E1L, | ||
| 161 | 	2.078695677795422351040502569964299664233E1L, | ||
| 162 | 	4.641271134150895940966798357442234498546E0L, | ||
| 163 | 	/* 1.000000000000000000000000000000000000000E0 */ | ||
| 164 | }, | ||
| 165 | |||
| 166 | /* | ||
| 167 | * Coefficients for approximation to erfc in [1.25,1/0.35] | ||
| 168 | */ | ||
| 169 | /* erfc(1/x) = x exp (-1/x^2 - 0.5625 + ra(x^2)/sa(x^2)) | ||
| 170 | 1/2.85711669921875 < 1/x < 1/1.25 | ||
| 171 | Peak relative error 3.1e-21 */ | ||
| 172 | ra[] = { | ||
| 173 | 	1.363566591833846324191000679620738857234E-1L, | ||
| 174 | 	1.018203167219873573808450274314658434507E1L, | ||
| 175 | 	1.862359362334248675526472871224778045594E2L, | ||
| 176 | 	1.411622588180721285284945138667933330348E3L, | ||
| 177 | 	5.088538459741511988784440103218342840478E3L, | ||
| 178 | 	8.928251553922176506858267311750789273656E3L, | ||
| 179 | 	7.264436000148052545243018622742770549982E3L, | ||
| 180 | 	2.387492459664548651671894725748959751119E3L, | ||
| 181 | 	2.220916652813908085449221282808458466556E2L, | ||
| 182 | }, | ||
| 183 | sa[] = { | ||
| 184 | 	-1.382234625202480685182526402169222331847E1L, | ||
| 185 | 	-3.315638835627950255832519203687435946482E2L, | ||
| 186 | 	-2.949124863912936259747237164260785326692E3L, | ||
| 187 | 	-1.246622099070875940506391433635999693661E4L, | ||
| 188 | 	-2.673079795851665428695842853070996219632E4L, | ||
| 189 | 	-2.880269786660559337358397106518918220991E4L, | ||
| 190 | 	-1.450600228493968044773354186390390823713E4L, | ||
| 191 | 	-2.874539731125893533960680525192064277816E3L, | ||
| 192 | 	-1.402241261419067750237395034116942296027E2L, | ||
| 193 | 	/* 1.000000000000000000000000000000000000000E0 */ | ||
| 194 | }, | ||
| 195 | |||
| 196 | /* | ||
| 197 | * Coefficients for approximation to erfc in [1/.35,107] | ||
| 198 | */ | ||
| 199 | /* erfc(1/x) = x exp (-1/x^2 - 0.5625 + rb(x^2)/sb(x^2)) | ||
| 200 | 1/6.6666259765625 < 1/x < 1/2.85711669921875 | ||
| 201 | Peak relative error 4.2e-22 */ | ||
| 202 | rb[] = { | ||
| 203 | 	-4.869587348270494309550558460786501252369E-5L, | ||
| 204 | 	-4.030199390527997378549161722412466959403E-3L, | ||
| 205 | 	-9.434425866377037610206443566288917589122E-2L, | ||
| 206 | 	-9.319032754357658601200655161585539404155E-1L, | ||
| 207 | 	-4.273788174307459947350256581445442062291E0L, | ||
| 208 | 	-8.842289940696150508373541814064198259278E0L, | ||
| 209 | 	-7.069215249419887403187988144752613025255E0L, | ||
| 210 | 	-1.401228723639514787920274427443330704764E0L, | ||
| 211 | }, | ||
| 212 | sb[] = { | ||
| 213 | 	4.936254964107175160157544545879293019085E-3L, | ||
| 214 | 	1.583457624037795744377163924895349412015E-1L, | ||
| 215 | 	1.850647991850328356622940552450636420484E0L, | ||
| 216 | 	9.927611557279019463768050710008450625415E0L, | ||
| 217 | 	2.531667257649436709617165336779212114570E1L, | ||
| 218 | 	2.869752886406743386458304052862814690045E1L, | ||
| 219 | 	1.182059497870819562441683560749192539345E1L, | ||
| 220 | 	/* 1.000000000000000000000000000000000000000E0 */ | ||
| 221 | }, | ||
| 222 | /* erfc(1/x) = x exp (-1/x^2 - 0.5625 + rc(x^2)/sc(x^2)) | ||
| 223 | 1/107 <= 1/x <= 1/6.6666259765625 | ||
| 224 | Peak relative error 1.1e-21 */ | ||
| 225 | rc[] = { | ||
| 226 | 	-8.299617545269701963973537248996670806850E-5L, | ||
| 227 | 	-6.243845685115818513578933902532056244108E-3L, | ||
| 228 | 	-1.141667210620380223113693474478394397230E-1L, | ||
| 229 | 	-7.521343797212024245375240432734425789409E-1L, | ||
| 230 | 	-1.765321928311155824664963633786967602934E0L, | ||
| 231 | 	-1.029403473103215800456761180695263439188E0L, | ||
| 232 | }, | ||
| 233 | sc[] = { | ||
| 234 | 	8.413244363014929493035952542677768808601E-3L, | ||
| 235 | 	2.065114333816877479753334599639158060979E-1L, | ||
| 236 | 	1.639064941530797583766364412782135680148E0L, | ||
| 237 | 	4.936788463787115555582319302981666347450E0L, | ||
| 238 | 	5.005177727208955487404729933261347679090E0L, | ||
| 239 | 	/* 1.000000000000000000000000000000000000000E0 */ | ||
| 240 | }; | ||
| 241 | |||
| 242 | static long double erfc1(long double x) | ||
| 243 | { | ||
| 244 | 	long double s,P,Q; | ||
| 245 | |||
| 246 | 	s = fabsl(x) - 1; | ||
| 247 | 	P = pa[0] + s * (pa[1] + s * (pa[2] + | ||
| 248 | 	 s * (pa[3] + s * (pa[4] + s * (pa[5] + s * (pa[6] + s * pa[7])))))); | ||
| 249 | 	Q = qa[0] + s * (qa[1] + s * (qa[2] + | ||
| 250 | 	 s * (qa[3] + s * (qa[4] + s * (qa[5] + s * (qa[6] + s)))))); | ||
| 251 | 	return 1 - erx - P / Q; | ||
| 252 | } | ||
| 253 | |||
| 254 | static long double erfc2(uint32_t ix, long double x) | ||
| 255 | { | ||
| 256 | 	union ldshape u; | ||
| 257 | 	long double s,z,R,S; | ||
| 258 | |||
| 259 | 	if (ix < 0x3fffa000) /* 0.84375 <= |x| < 1.25 */ | ||
| 260 | 		return erfc1(x); | ||
| 261 | |||
| 262 | 	x = fabsl(x); | ||
| 263 | 	s = 1 / (x * x); | ||
| 264 | 	if (ix < 0x4000b6db) { /* 1.25 <= |x| < 2.857 ~ 1/.35 */ | ||
| 265 | 		R = ra[0] + s * (ra[1] + s * (ra[2] + s * (ra[3] + s * (ra[4] + | ||
| 266 | 		 s * (ra[5] + s * (ra[6] + s * (ra[7] + s * ra[8]))))))); | ||
| 267 | 		S = sa[0] + s * (sa[1] + s * (sa[2] + s * (sa[3] + s * (sa[4] + | ||
| 268 | 		 s * (sa[5] + s * (sa[6] + s * (sa[7] + s * (sa[8] + s)))))))); | ||
| 269 | 	} else if (ix < 0x4001d555) { /* 2.857 <= |x| < 6.6666259765625 */ | ||
| 270 | 		R = rb[0] + s * (rb[1] + s * (rb[2] + s * (rb[3] + s * (rb[4] + | ||
| 271 | 		 s * (rb[5] + s * (rb[6] + s * rb[7])))))); | ||
| 272 | 		S = sb[0] + s * (sb[1] + s * (sb[2] + s * (sb[3] + s * (sb[4] + | ||
| 273 | 		 s * (sb[5] + s * (sb[6] + s)))))); | ||
| 274 | 	} else { /* 6.666 <= |x| < 107 (erfc only) */ | ||
| 275 | 		R = rc[0] + s * (rc[1] + s * (rc[2] + s * (rc[3] + | ||
| 276 | 		 s * (rc[4] + s * rc[5])))); | ||
| 277 | 		S = sc[0] + s * (sc[1] + s * (sc[2] + s * (sc[3] + | ||
| 278 | 		 s * (sc[4] + s)))); | ||
| 279 | 	} | ||
| 280 | 	u.f = x; | ||
| 281 | 	u.i.m &= -1ULL << 40; | ||
| 282 | 	z = u.f; | ||
| 283 | 	return expl(-z*z - 0.5625) * expl((z - x) * (z + x) + R / S) / x; | ||
| 284 | } | ||
| 285 | |||
| 286 | long double erfl(long double x) | ||
| 287 | { | ||
| 288 | 	long double r, s, z, y; | ||
| 289 | 	union ldshape u = {x}; | ||
| 290 | 	uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; | ||
| 291 | 	int sign = u.i.se >> 15; | ||
| 292 | |||
| 293 | 	if (ix >= 0x7fff0000) | ||
| 294 | 		/* erf(nan)=nan, erf(+-inf)=+-1 */ | ||
| 295 | 		return 1 - 2*sign + 1/x; | ||
| 296 | 	if (ix < 0x3ffed800) { /* |x| < 0.84375 */ | ||
| 297 | 		if (ix < 0x3fde8000) { /* |x| < 2**-33 */ | ||
| 298 | 			return 0.125 * (8 * x + efx8 * x); /* avoid underflow */ | ||
| 299 | 		} | ||
| 300 | 		z = x * x; | ||
| 301 | 		r = pp[0] + z * (pp[1] + | ||
| 302 | 		 z * (pp[2] + z * (pp[3] + z * (pp[4] + z * pp[5])))); | ||
| 303 | 		s = qq[0] + z * (qq[1] + | ||
| 304 | 		 z * (qq[2] + z * (qq[3] + z * (qq[4] + z * (qq[5] + z))))); | ||
| 305 | 		y = r / s; | ||
| 306 | 		return x + x * y; | ||
| 307 | 	} | ||
| 308 | 	if (ix < 0x4001d555) /* |x| < 6.6666259765625 */ | ||
| 309 | 		y = 1 - erfc2(ix,x); | ||
| 310 | 	else | ||
| 311 | 		y = 1 - 0x1p-16382L; | ||
| 312 | 	return sign ? -y : y; | ||
| 313 | } | ||
| 314 | |||
| 315 | long double erfcl(long double x) | ||
| 316 | { | ||
| 317 | 	long double r, s, z, y; | ||
| 318 | 	union ldshape u = {x}; | ||
| 319 | 	uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; | ||
| 320 | 	int sign = u.i.se >> 15; | ||
| 321 | |||
| 322 | 	if (ix >= 0x7fff0000) | ||
| 323 | 		/* erfc(nan) = nan, erfc(+-inf) = 0,2 */ | ||
| 324 | 		return 2*sign + 1/x; | ||
| 325 | 	if (ix < 0x3ffed800) { /* |x| < 0.84375 */ | ||
| 326 | 		if (ix < 0x3fbe0000) /* |x| < 2**-65 */ | ||
| 327 | 			return 1.0 - x; | ||
| 328 | 		z = x * x; | ||
| 329 | 		r = pp[0] + z * (pp[1] + | ||
| 330 | 		 z * (pp[2] + z * (pp[3] + z * (pp[4] + z * pp[5])))); | ||
| 331 | 		s = qq[0] + z * (qq[1] + | ||
| 332 | 		 z * (qq[2] + z * (qq[3] + z * (qq[4] + z * (qq[5] + z))))); | ||
| 333 | 		y = r / s; | ||
| 334 | 		if (ix < 0x3ffd8000) /* x < 1/4 */ | ||
| 335 | 			return 1.0 - (x + x * y); | ||
| 336 | 		return 0.5 - (x - 0.5 + x * y); | ||
| 337 | 	} | ||
| 338 | 	if (ix < 0x4005d600) /* |x| < 107 */ | ||
| 339 | 		return sign ? 2 - erfc2(ix,x) : erfc2(ix,x); | ||
| 340 | 	y = 0x1p-16382L; | ||
| 341 | 	return sign ? 2 - y : y*y; | ||
| 342 | } | ||
| 343 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 344 | // TODO: broken implementation to make things compile | ||
| 345 | long double erfl(long double x) | ||
| 346 | { | ||
| 347 | 	return erf(x); | ||
| 348 | } | ||
| 349 | long double erfcl(long double x) | ||
| 350 | { | ||
| 351 | 	return erfc(x); | ||
| 352 | } | ||
| 353 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp.c created+134| ... | @@ -0,0 +1,134 @@ | ||
| 1 | /* | ||
| 2 | * Double-precision e^x function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "exp_data.h" | ||
| 12 | |||
| 13 | #define N (1 << EXP_TABLE_BITS) | ||
| 14 | #define InvLn2N __exp_data.invln2N | ||
| 15 | #define NegLn2hiN __exp_data.negln2hiN | ||
| 16 | #define NegLn2loN __exp_data.negln2loN | ||
| 17 | #define Shift __exp_data.shift | ||
| 18 | #define T __exp_data.tab | ||
| 19 | #define C2 __exp_data.poly[5 - EXP_POLY_ORDER] | ||
| 20 | #define C3 __exp_data.poly[6 - EXP_POLY_ORDER] | ||
| 21 | #define C4 __exp_data.poly[7 - EXP_POLY_ORDER] | ||
| 22 | #define C5 __exp_data.poly[8 - EXP_POLY_ORDER] | ||
| 23 | |||
| 24 | /* Handle cases that may overflow or underflow when computing the result that | ||
| 25 | is scale*(1+TMP) without intermediate rounding. The bit representation of | ||
| 26 | scale is in SBITS, however it has a computed exponent that may have | ||
| 27 | overflown into the sign bit so that needs to be adjusted before using it as | ||
| 28 | a double. (int32_t)KI is the k used in the argument reduction and exponent | ||
| 29 | adjustment of scale, positive k here means the result may overflow and | ||
| 30 | negative k means the result may underflow. */ | ||
| 31 | static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki) | ||
| 32 | { | ||
| 33 | 	double_t scale, y; | ||
| 34 | |||
| 35 | 	if ((ki & 0x80000000) == 0) { | ||
| 36 | 		/* k > 0, the exponent of scale might have overflowed by <= 460. */ | ||
| 37 | 		sbits -= 1009ull << 52; | ||
| 38 | 		scale = asdouble(sbits); | ||
| 39 | 		y = 0x1p1009 * (scale + scale * tmp); | ||
| 40 | 		return eval_as_double(y); | ||
| 41 | 	} | ||
| 42 | 	/* k < 0, need special care in the subnormal range. */ | ||
| 43 | 	sbits += 1022ull << 52; | ||
| 44 | 	scale = asdouble(sbits); | ||
| 45 | 	y = scale + scale * tmp; | ||
| 46 | 	if (y < 1.0) { | ||
| 47 | 		/* Round y to the right precision before scaling it into the subnormal | ||
| 48 | 		 range to avoid double rounding that can cause 0.5+E/2 ulp error where | ||
| 49 | 		 E is the worst-case ulp error outside the subnormal range. So this | ||
| 50 | 		 is only useful if the goal is better than 1 ulp worst-case error. */ | ||
| 51 | 		double_t hi, lo; | ||
| 52 | 		lo = scale - y + scale * tmp; | ||
| 53 | 		hi = 1.0 + y; | ||
| 54 | 		lo = 1.0 - hi + y + lo; | ||
| 55 | 		y = eval_as_double(hi + lo) - 1.0; | ||
| 56 | 		/* Avoid -0.0 with downward rounding. */ | ||
| 57 | 		if (WANT_ROUNDING && y == 0.0) | ||
| 58 | 			y = 0.0; | ||
| 59 | 		/* The underflow exception needs to be signaled explicitly. */ | ||
| 60 | 		fp_force_eval(fp_barrier(0x1p-1022) * 0x1p-1022); | ||
| 61 | 	} | ||
| 62 | 	y = 0x1p-1022 * y; | ||
| 63 | 	return eval_as_double(y); | ||
| 64 | } | ||
| 65 | |||
| 66 | /* Top 12 bits of a double (sign and exponent bits). */ | ||
| 67 | static inline uint32_t top12(double x) | ||
| 68 | { | ||
| 69 | 	return asuint64(x) >> 52; | ||
| 70 | } | ||
| 71 | |||
| 72 | double exp(double x) | ||
| 73 | { | ||
| 74 | 	uint32_t abstop; | ||
| 75 | 	uint64_t ki, idx, top, sbits; | ||
| 76 | 	double_t kd, z, r, r2, scale, tail, tmp; | ||
| 77 | |||
| 78 | 	abstop = top12(x) & 0x7ff; | ||
| 79 | 	if (predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54))) { | ||
| 80 | 		if (abstop - top12(0x1p-54) >= 0x80000000) | ||
| 81 | 			/* Avoid spurious underflow for tiny x. */ | ||
| 82 | 			/* Note: 0 is common input. */ | ||
| 83 | 			return WANT_ROUNDING ? 1.0 + x : 1.0; | ||
| 84 | 		if (abstop >= top12(1024.0)) { | ||
| 85 | 			if (asuint64(x) == asuint64(-INFINITY)) | ||
| 86 | 				return 0.0; | ||
| 87 | 			if (abstop >= top12(INFINITY)) | ||
| 88 | 				return 1.0 + x; | ||
| 89 | 			if (asuint64(x) >> 63) | ||
| 90 | 				return __math_uflow(0); | ||
| 91 | 			else | ||
| 92 | 				return __math_oflow(0); | ||
| 93 | 		} | ||
| 94 | 		/* Large x is special cased below. */ | ||
| 95 | 		abstop = 0; | ||
| 96 | 	} | ||
| 97 | |||
| 98 | 	/* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]. */ | ||
| 99 | 	/* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]. */ | ||
| 100 | 	z = InvLn2N * x; | ||
| 101 | #if TOINT_INTRINSICS | ||
| 102 | 	kd = roundtoint(z); | ||
| 103 | 	ki = converttoint(z); | ||
| 104 | #elif EXP_USE_TOINT_NARROW | ||
| 105 | 	/* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes. */ | ||
| 106 | 	kd = eval_as_double(z + Shift); | ||
| 107 | 	ki = asuint64(kd) >> 16; | ||
| 108 | 	kd = (double_t)(int32_t)ki; | ||
| 109 | #else | ||
| 110 | 	/* z - kd is in [-1, 1] in non-nearest rounding modes. */ | ||
| 111 | 	kd = eval_as_double(z + Shift); | ||
| 112 | 	ki = asuint64(kd); | ||
| 113 | 	kd -= Shift; | ||
| 114 | #endif | ||
| 115 | 	r = x + kd * NegLn2hiN + kd * NegLn2loN; | ||
| 116 | 	/* 2^(k/N) ~= scale * (1 + tail). */ | ||
| 117 | 	idx = 2 * (ki % N); | ||
| 118 | 	top = ki << (52 - EXP_TABLE_BITS); | ||
| 119 | 	tail = asdouble(T[idx]); | ||
| 120 | 	/* This is only a valid scale when -1023*N < k < 1024*N. */ | ||
| 121 | 	sbits = T[idx + 1] + top; | ||
| 122 | 	/* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1). */ | ||
| 123 | 	/* Evaluation is optimized assuming superscalar pipelined execution. */ | ||
| 124 | 	r2 = r * r; | ||
| 125 | 	/* Without fma the worst case error is 0.25/N ulp larger. */ | ||
| 126 | 	/* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp. */ | ||
| 127 | 	tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5); | ||
| 128 | 	if (predict_false(abstop == 0)) | ||
| 129 | 		return specialcase(tmp, sbits, ki); | ||
| 130 | 	scale = asdouble(sbits); | ||
| 131 | 	/* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there | ||
| 132 | 	 is no spurious underflow here even without fma. */ | ||
| 133 | 	return eval_as_double(scale + scale * tmp); | ||
| 134 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp10.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | double exp10(double x) | ||
| 6 | { | ||
| 7 | 	static const double p10[] = { | ||
| 8 | 		1e-15, 1e-14, 1e-13, 1e-12, 1e-11, 1e-10, | ||
| 9 | 		1e-9, 1e-8, 1e-7, 1e-6, 1e-5, 1e-4, 1e-3, 1e-2, 1e-1, | ||
| 10 | 		1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, | ||
| 11 | 		1e10, 1e11, 1e12, 1e13, 1e14, 1e15 | ||
| 12 | 	}; | ||
| 13 | 	double n, y = modf(x, &n); | ||
| 14 | 	union {double f; uint64_t i;} u = {n}; | ||
| 15 | 	/* fabs(n) < 16 without raising invalid on nan */ | ||
| 16 | 	if ((u.i>>52 & 0x7ff) < 0x3ff+4) { | ||
| 17 | 		if (!y) return p10[(int)n+15]; | ||
| 18 | 		y = exp2(3.32192809488736234787031942948939 * y); | ||
| 19 | 		return y * p10[(int)n+15]; | ||
| 20 | 	} | ||
| 21 | 	return pow(10.0, x); | ||
| 22 | } | ||
| 23 | |||
| 24 | weak_alias(exp10, pow10); | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp10f.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | float exp10f(float x) | ||
| 6 | { | ||
| 7 | 	static const float p10[] = { | ||
| 8 | 		1e-7f, 1e-6f, 1e-5f, 1e-4f, 1e-3f, 1e-2f, 1e-1f, | ||
| 9 | 		1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7 | ||
| 10 | 	}; | ||
| 11 | 	float n, y = modff(x, &n); | ||
| 12 | 	union {float f; uint32_t i;} u = {n}; | ||
| 13 | 	/* fabsf(n) < 8 without raising invalid on nan */ | ||
| 14 | 	if ((u.i>>23 & 0xff) < 0x7f+3) { | ||
| 15 | 		if (!y) return p10[(int)n+7]; | ||
| 16 | 		y = exp2f(3.32192809488736234787031942948939f * y); | ||
| 17 | 		return y * p10[(int)n+7]; | ||
| 18 | 	} | ||
| 19 | 	return exp2(3.32192809488736234787031942948939 * x); | ||
| 20 | } | ||
| 21 | |||
| 22 | weak_alias(exp10f, pow10f); | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp10l.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <float.h> | ||
| 3 | #include <math.h> | ||
| 4 | #include "libm.h" | ||
| 5 | |||
| 6 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 7 | long double exp10l(long double x) | ||
| 8 | { | ||
| 9 | 	return exp10(x); | ||
| 10 | } | ||
| 11 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 12 | long double exp10l(long double x) | ||
| 13 | { | ||
| 14 | 	static const long double p10[] = { | ||
| 15 | 		1e-15L, 1e-14L, 1e-13L, 1e-12L, 1e-11L, 1e-10L, | ||
| 16 | 		1e-9L, 1e-8L, 1e-7L, 1e-6L, 1e-5L, 1e-4L, 1e-3L, 1e-2L, 1e-1L, | ||
| 17 | 		1, 1e1, 1e2, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, | ||
| 18 | 		1e10, 1e11, 1e12, 1e13, 1e14, 1e15 | ||
| 19 | 	}; | ||
| 20 | 	long double n, y = modfl(x, &n); | ||
| 21 | 	union ldshape u = {n}; | ||
| 22 | 	/* fabsl(n) < 16 without raising invalid on nan */ | ||
| 23 | 	if ((u.i.se & 0x7fff) < 0x3fff+4) { | ||
| 24 | 		if (!y) return p10[(int)n+15]; | ||
| 25 | 		y = exp2l(3.32192809488736234787031942948939L * y); | ||
| 26 | 		return y * p10[(int)n+15]; | ||
| 27 | 	} | ||
| 28 | 	return powl(10.0, x); | ||
| 29 | } | ||
| 30 | #endif | ||
| 31 | |||
| 32 | weak_alias(exp10l, pow10l); | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp2.c created+121| ... | @@ -0,0 +1,121 @@ | ||
| 1 | /* | ||
| 2 | * Double-precision 2^x function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "exp_data.h" | ||
| 12 | |||
| 13 | #define N (1 << EXP_TABLE_BITS) | ||
| 14 | #define Shift __exp_data.exp2_shift | ||
| 15 | #define T __exp_data.tab | ||
| 16 | #define C1 __exp_data.exp2_poly[0] | ||
| 17 | #define C2 __exp_data.exp2_poly[1] | ||
| 18 | #define C3 __exp_data.exp2_poly[2] | ||
| 19 | #define C4 __exp_data.exp2_poly[3] | ||
| 20 | #define C5 __exp_data.exp2_poly[4] | ||
| 21 | |||
| 22 | /* Handle cases that may overflow or underflow when computing the result that | ||
| 23 | is scale*(1+TMP) without intermediate rounding. The bit representation of | ||
| 24 | scale is in SBITS, however it has a computed exponent that may have | ||
| 25 | overflown into the sign bit so that needs to be adjusted before using it as | ||
| 26 | a double. (int32_t)KI is the k used in the argument reduction and exponent | ||
| 27 | adjustment of scale, positive k here means the result may overflow and | ||
| 28 | negative k means the result may underflow. */ | ||
| 29 | static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki) | ||
| 30 | { | ||
| 31 | 	double_t scale, y; | ||
| 32 | |||
| 33 | 	if ((ki & 0x80000000) == 0) { | ||
| 34 | 		/* k > 0, the exponent of scale might have overflowed by 1. */ | ||
| 35 | 		sbits -= 1ull << 52; | ||
| 36 | 		scale = asdouble(sbits); | ||
| 37 | 		y = 2 * (scale + scale * tmp); | ||
| 38 | 		return eval_as_double(y); | ||
| 39 | 	} | ||
| 40 | 	/* k < 0, need special care in the subnormal range. */ | ||
| 41 | 	sbits += 1022ull << 52; | ||
| 42 | 	scale = asdouble(sbits); | ||
| 43 | 	y = scale + scale * tmp; | ||
| 44 | 	if (y < 1.0) { | ||
| 45 | 		/* Round y to the right precision before scaling it into the subnormal | ||
| 46 | 		 range to avoid double rounding that can cause 0.5+E/2 ulp error where | ||
| 47 | 		 E is the worst-case ulp error outside the subnormal range. So this | ||
| 48 | 		 is only useful if the goal is better than 1 ulp worst-case error. */ | ||
| 49 | 		double_t hi, lo; | ||
| 50 | 		lo = scale - y + scale * tmp; | ||
| 51 | 		hi = 1.0 + y; | ||
| 52 | 		lo = 1.0 - hi + y + lo; | ||
| 53 | 		y = eval_as_double(hi + lo) - 1.0; | ||
| 54 | 		/* Avoid -0.0 with downward rounding. */ | ||
| 55 | 		if (WANT_ROUNDING && y == 0.0) | ||
| 56 | 			y = 0.0; | ||
| 57 | 		/* The underflow exception needs to be signaled explicitly. */ | ||
| 58 | 		fp_force_eval(fp_barrier(0x1p-1022) * 0x1p-1022); | ||
| 59 | 	} | ||
| 60 | 	y = 0x1p-1022 * y; | ||
| 61 | 	return eval_as_double(y); | ||
| 62 | } | ||
| 63 | |||
| 64 | /* Top 12 bits of a double (sign and exponent bits). */ | ||
| 65 | static inline uint32_t top12(double x) | ||
| 66 | { | ||
| 67 | 	return asuint64(x) >> 52; | ||
| 68 | } | ||
| 69 | |||
| 70 | double exp2(double x) | ||
| 71 | { | ||
| 72 | 	uint32_t abstop; | ||
| 73 | 	uint64_t ki, idx, top, sbits; | ||
| 74 | 	double_t kd, r, r2, scale, tail, tmp; | ||
| 75 | |||
| 76 | 	abstop = top12(x) & 0x7ff; | ||
| 77 | 	if (predict_false(abstop - top12(0x1p-54) >= top12(512.0) - top12(0x1p-54))) { | ||
| 78 | 		if (abstop - top12(0x1p-54) >= 0x80000000) | ||
| 79 | 			/* Avoid spurious underflow for tiny x. */ | ||
| 80 | 			/* Note: 0 is common input. */ | ||
| 81 | 			return WANT_ROUNDING ? 1.0 + x : 1.0; | ||
| 82 | 		if (abstop >= top12(1024.0)) { | ||
| 83 | 			if (asuint64(x) == asuint64(-INFINITY)) | ||
| 84 | 				return 0.0; | ||
| 85 | 			if (abstop >= top12(INFINITY)) | ||
| 86 | 				return 1.0 + x; | ||
| 87 | 			if (!(asuint64(x) >> 63)) | ||
| 88 | 				return __math_oflow(0); | ||
| 89 | 			else if (asuint64(x) >= asuint64(-1075.0)) | ||
| 90 | 				return __math_uflow(0); | ||
| 91 | 		} | ||
| 92 | 		if (2 * asuint64(x) > 2 * asuint64(928.0)) | ||
| 93 | 			/* Large x is special cased below. */ | ||
| 94 | 			abstop = 0; | ||
| 95 | 	} | ||
| 96 | |||
| 97 | 	/* exp2(x) = 2^(k/N) * 2^r, with 2^r in [2^(-1/2N),2^(1/2N)]. */ | ||
| 98 | 	/* x = k/N + r, with int k and r in [-1/2N, 1/2N]. */ | ||
| 99 | 	kd = eval_as_double(x + Shift); | ||
| 100 | 	ki = asuint64(kd); /* k. */ | ||
| 101 | 	kd -= Shift; /* k/N for int k. */ | ||
| 102 | 	r = x - kd; | ||
| 103 | 	/* 2^(k/N) ~= scale * (1 + tail). */ | ||
| 104 | 	idx = 2 * (ki % N); | ||
| 105 | 	top = ki << (52 - EXP_TABLE_BITS); | ||
| 106 | 	tail = asdouble(T[idx]); | ||
| 107 | 	/* This is only a valid scale when -1023*N < k < 1024*N. */ | ||
| 108 | 	sbits = T[idx + 1] + top; | ||
| 109 | 	/* exp2(x) = 2^(k/N) * 2^r ~= scale + scale * (tail + 2^r - 1). */ | ||
| 110 | 	/* Evaluation is optimized assuming superscalar pipelined execution. */ | ||
| 111 | 	r2 = r * r; | ||
| 112 | 	/* Without fma the worst case error is 0.5/N ulp larger. */ | ||
| 113 | 	/* Worst case error is less than 0.5+0.86/N+(abs poly error * 2^53) ulp. */ | ||
| 114 | 	tmp = tail + r * C1 + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5); | ||
| 115 | 	if (predict_false(abstop == 0)) | ||
| 116 | 		return specialcase(tmp, sbits, ki); | ||
| 117 | 	scale = asdouble(sbits); | ||
| 118 | 	/* Note: tmp == 0 or |tmp| > 2^-65 and scale > 2^-928, so there | ||
| 119 | 	 is no spurious underflow here even without fma. */ | ||
| 120 | 	return eval_as_double(scale + scale * tmp); | ||
| 121 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp2f.c created+69| ... | @@ -0,0 +1,69 @@ | ||
| 1 | /* | ||
| 2 | * Single-precision 2^x function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "exp2f_data.h" | ||
| 12 | |||
| 13 | /* | ||
| 14 | EXP2F_TABLE_BITS = 5 | ||
| 15 | EXP2F_POLY_ORDER = 3 | ||
| 16 | |||
| 17 | ULP error: 0.502 (nearest rounding.) | ||
| 18 | Relative error: 1.69 * 2^-34 in [-1/64, 1/64] (before rounding.) | ||
| 19 | Wrong count: 168353 (all nearest rounding wrong results with fma.) | ||
| 20 | Non-nearest ULP error: 1 (rounded ULP error) | ||
| 21 | */ | ||
| 22 | |||
| 23 | #define N (1 << EXP2F_TABLE_BITS) | ||
| 24 | #define T __exp2f_data.tab | ||
| 25 | #define C __exp2f_data.poly | ||
| 26 | #define SHIFT __exp2f_data.shift_scaled | ||
| 27 | |||
| 28 | static inline uint32_t top12(float x) | ||
| 29 | { | ||
| 30 | 	return asuint(x) >> 20; | ||
| 31 | } | ||
| 32 | |||
| 33 | float exp2f(float x) | ||
| 34 | { | ||
| 35 | 	uint32_t abstop; | ||
| 36 | 	uint64_t ki, t; | ||
| 37 | 	double_t kd, xd, z, r, r2, y, s; | ||
| 38 | |||
| 39 | 	xd = (double_t)x; | ||
| 40 | 	abstop = top12(x) & 0x7ff; | ||
| 41 | 	if (predict_false(abstop >= top12(128.0f))) { | ||
| 42 | 		/* |x| >= 128 or x is nan. */ | ||
| 43 | 		if (asuint(x) == asuint(-INFINITY)) | ||
| 44 | 			return 0.0f; | ||
| 45 | 		if (abstop >= top12(INFINITY)) | ||
| 46 | 			return x + x; | ||
| 47 | 		if (x > 0.0f) | ||
| 48 | 			return __math_oflowf(0); | ||
| 49 | 		if (x <= -150.0f) | ||
| 50 | 			return __math_uflowf(0); | ||
| 51 | 	} | ||
| 52 | |||
| 53 | 	/* x = k/N + r with r in [-1/(2N), 1/(2N)] and int k. */ | ||
| 54 | 	kd = eval_as_double(xd + SHIFT); | ||
| 55 | 	ki = asuint64(kd); | ||
| 56 | 	kd -= SHIFT; /* k/N for int k. */ | ||
| 57 | 	r = xd - kd; | ||
| 58 | |||
| 59 | 	/* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */ | ||
| 60 | 	t = T[ki % N]; | ||
| 61 | 	t += ki << (52 - EXP2F_TABLE_BITS); | ||
| 62 | 	s = asdouble(t); | ||
| 63 | 	z = C[0] * r + C[1]; | ||
| 64 | 	r2 = r * r; | ||
| 65 | 	y = C[2] * r + 1; | ||
| 66 | 	y = z * r2 + y; | ||
| 67 | 	y = y * s; | ||
| 68 | 	return eval_as_float(y); | ||
| 69 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp2f_data.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | /* | ||
| 2 | * Shared data between expf, exp2f and powf. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "exp2f_data.h" | ||
| 9 | |||
| 10 | #define N (1 << EXP2F_TABLE_BITS) | ||
| 11 | |||
| 12 | const struct exp2f_data __exp2f_data = { | ||
| 13 | /* tab[i] = uint(2^(i/N)) - (i << 52-BITS) | ||
| 14 | used for computing 2^(k/N) for an int |k| < 150 N as | ||
| 15 | double(tab[k%N] + (k << 52-BITS)) */ | ||
| 16 | .tab = { | ||
| 17 | 0x3ff0000000000000, 0x3fefd9b0d3158574, 0x3fefb5586cf9890f, 0x3fef9301d0125b51, | ||
| 18 | 0x3fef72b83c7d517b, 0x3fef54873168b9aa, 0x3fef387a6e756238, 0x3fef1e9df51fdee1, | ||
| 19 | 0x3fef06fe0a31b715, 0x3feef1a7373aa9cb, 0x3feedea64c123422, 0x3feece086061892d, | ||
| 20 | 0x3feebfdad5362a27, 0x3feeb42b569d4f82, 0x3feeab07dd485429, 0x3feea47eb03a5585, | ||
| 21 | 0x3feea09e667f3bcd, 0x3fee9f75e8ec5f74, 0x3feea11473eb0187, 0x3feea589994cce13, | ||
| 22 | 0x3feeace5422aa0db, 0x3feeb737b0cdc5e5, 0x3feec49182a3f090, 0x3feed503b23e255d, | ||
| 23 | 0x3feee89f995ad3ad, 0x3feeff76f2fb5e47, 0x3fef199bdd85529c, 0x3fef3720dcef9069, | ||
| 24 | 0x3fef5818dcfba487, 0x3fef7c97337b9b5f, 0x3fefa4afa2a490da, 0x3fefd0765b6e4540, | ||
| 25 | }, | ||
| 26 | .shift_scaled = 0x1.8p+52 / N, | ||
| 27 | .poly = { | ||
| 28 | 0x1.c6af84b912394p-5, 0x1.ebfce50fac4f3p-3, 0x1.62e42ff0c52d6p-1, | ||
| 29 | }, | ||
| 30 | .shift = 0x1.8p+52, | ||
| 31 | .invln2_scaled = 0x1.71547652b82fep+0 * N, | ||
| 32 | .poly_scaled = { | ||
| 33 | 0x1.c6af84b912394p-5/N/N/N, 0x1.ebfce50fac4f3p-3/N/N, 0x1.62e42ff0c52d6p-1/N, | ||
| 34 | }, | ||
| 35 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp2f_data.h created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _EXP2F_DATA_H | ||
| 6 | #define _EXP2F_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | /* Shared between expf, exp2f and powf. */ | ||
| 12 | #define EXP2F_TABLE_BITS 5 | ||
| 13 | #define EXP2F_POLY_ORDER 3 | ||
| 14 | extern hidden const struct exp2f_data { | ||
| 15 | 	uint64_t tab[1 << EXP2F_TABLE_BITS]; | ||
| 16 | 	double shift_scaled; | ||
| 17 | 	double poly[EXP2F_POLY_ORDER]; | ||
| 18 | 	double shift; | ||
| 19 | 	double invln2_scaled; | ||
| 20 | 	double poly_scaled[EXP2F_POLY_ORDER]; | ||
| 21 | } __exp2f_data; | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp2l.c created+619| ... | @@ -0,0 +1,619 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/ld80/s_exp2l.c and /usr/src/lib/msun/ld128/s_exp2l.c */ | ||
| 2 | /*- | ||
| 3 | * Copyright (c) 2005-2008 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 | #include "libm.h" | ||
| 29 | |||
| 30 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 31 | long double exp2l(long double x) | ||
| 32 | { | ||
| 33 | 	return exp2(x); | ||
| 34 | } | ||
| 35 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 36 | #define TBLBITS 7 | ||
| 37 | #define TBLSIZE (1 << TBLBITS) | ||
| 38 | |||
| 39 | static const double | ||
| 40 | redux = 0x1.8p63 / TBLSIZE, | ||
| 41 | P1 = 0x1.62e42fefa39efp-1, | ||
| 42 | P2 = 0x1.ebfbdff82c58fp-3, | ||
| 43 | P3 = 0x1.c6b08d7049fap-5, | ||
| 44 | P4 = 0x1.3b2ab6fba4da5p-7, | ||
| 45 | P5 = 0x1.5d8804780a736p-10, | ||
| 46 | P6 = 0x1.430918835e33dp-13; | ||
| 47 | |||
| 48 | static const double tbl[TBLSIZE * 2] = { | ||
| 49 | 	0x1.6a09e667f3bcdp-1, -0x1.bdd3413b2648p-55, | ||
| 50 | 	0x1.6c012750bdabfp-1, -0x1.2895667ff0cp-57, | ||
| 51 | 	0x1.6dfb23c651a2fp-1, -0x1.bbe3a683c88p-58, | ||
| 52 | 	0x1.6ff7df9519484p-1, -0x1.83c0f25860fp-56, | ||
| 53 | 	0x1.71f75e8ec5f74p-1, -0x1.16e4786887bp-56, | ||
| 54 | 	0x1.73f9a48a58174p-1, -0x1.0a8d96c65d5p-55, | ||
| 55 | 	0x1.75feb564267c9p-1, -0x1.0245957316ep-55, | ||
| 56 | 	0x1.780694fde5d3fp-1, 0x1.866b80a0216p-55, | ||
| 57 | 	0x1.7a11473eb0187p-1, -0x1.41577ee0499p-56, | ||
| 58 | 	0x1.7c1ed0130c132p-1, 0x1.f124cd1164ep-55, | ||
| 59 | 	0x1.7e2f336cf4e62p-1, 0x1.05d02ba157ap-57, | ||
| 60 | 	0x1.80427543e1a12p-1, -0x1.27c86626d97p-55, | ||
| 61 | 	0x1.82589994cce13p-1, -0x1.d4c1dd41533p-55, | ||
| 62 | 	0x1.8471a4623c7adp-1, -0x1.8d684a341cep-56, | ||
| 63 | 	0x1.868d99b4492edp-1, -0x1.fc6f89bd4f68p-55, | ||
| 64 | 	0x1.88ac7d98a6699p-1, 0x1.994c2f37cb5p-55, | ||
| 65 | 	0x1.8ace5422aa0dbp-1, 0x1.6e9f156864bp-55, | ||
| 66 | 	0x1.8cf3216b5448cp-1, -0x1.0d55e32e9e4p-57, | ||
| 67 | 	0x1.8f1ae99157736p-1, 0x1.5cc13a2e397p-56, | ||
| 68 | 	0x1.9145b0b91ffc6p-1, -0x1.dd6792e5825p-55, | ||
| 69 | 	0x1.93737b0cdc5e5p-1, -0x1.75fc781b58p-58, | ||
| 70 | 	0x1.95a44cbc8520fp-1, -0x1.64b7c96a5fp-57, | ||
| 71 | 	0x1.97d829fde4e5p-1, -0x1.d185b7c1b86p-55, | ||
| 72 | 	0x1.9a0f170ca07bap-1, -0x1.173bd91cee6p-55, | ||
| 73 | 	0x1.9c49182a3f09p-1, 0x1.c7c46b071f2p-57, | ||
| 74 | 	0x1.9e86319e32323p-1, 0x1.824ca78e64cp-57, | ||
| 75 | 	0x1.a0c667b5de565p-1, -0x1.359495d1cd5p-55, | ||
| 76 | 	0x1.a309bec4a2d33p-1, 0x1.6305c7ddc368p-55, | ||
| 77 | 	0x1.a5503b23e255dp-1, -0x1.d2f6edb8d42p-55, | ||
| 78 | 	0x1.a799e1330b358p-1, 0x1.bcb7ecac564p-55, | ||
| 79 | 	0x1.a9e6b5579fdbfp-1, 0x1.0fac90ef7fdp-55, | ||
| 80 | 	0x1.ac36bbfd3f37ap-1, -0x1.f9234cae76dp-56, | ||
| 81 | 	0x1.ae89f995ad3adp-1, 0x1.7a1cd345dcc8p-55, | ||
| 82 | 	0x1.b0e07298db666p-1, -0x1.bdef54c80e4p-55, | ||
| 83 | 	0x1.b33a2b84f15fbp-1, -0x1.2805e3084d8p-58, | ||
| 84 | 	0x1.b59728de5593ap-1, -0x1.c71dfbbba6ep-55, | ||
| 85 | 	0x1.b7f76f2fb5e47p-1, -0x1.5584f7e54acp-57, | ||
| 86 | 	0x1.ba5b030a1064ap-1, -0x1.efcd30e5429p-55, | ||
| 87 | 	0x1.bcc1e904bc1d2p-1, 0x1.23dd07a2d9fp-56, | ||
| 88 | 	0x1.bf2c25bd71e09p-1, -0x1.efdca3f6b9c8p-55, | ||
| 89 | 	0x1.c199bdd85529cp-1, 0x1.11065895049p-56, | ||
| 90 | 	0x1.c40ab5fffd07ap-1, 0x1.b4537e083c6p-55, | ||
| 91 | 	0x1.c67f12e57d14bp-1, 0x1.2884dff483c8p-55, | ||
| 92 | 	0x1.c8f6d9406e7b5p-1, 0x1.1acbc48805cp-57, | ||
| 93 | 	0x1.cb720dcef9069p-1, 0x1.503cbd1e94ap-57, | ||
| 94 | 	0x1.cdf0b555dc3fap-1, -0x1.dd83b53829dp-56, | ||
| 95 | 	0x1.d072d4a07897cp-1, -0x1.cbc3743797a8p-55, | ||
| 96 | 	0x1.d2f87080d89f2p-1, -0x1.d487b719d858p-55, | ||
| 97 | 	0x1.d5818dcfba487p-1, 0x1.2ed02d75b37p-56, | ||
| 98 | 	0x1.d80e316c98398p-1, -0x1.11ec18bedep-55, | ||
| 99 | 	0x1.da9e603db3285p-1, 0x1.c2300696db5p-55, | ||
| 100 | 	0x1.dd321f301b46p-1, 0x1.2da5778f019p-55, | ||
| 101 | 	0x1.dfc97337b9b5fp-1, -0x1.1a5cd4f184b8p-55, | ||
| 102 | 	0x1.e264614f5a129p-1, -0x1.7b627817a148p-55, | ||
| 103 | 	0x1.e502ee78b3ff6p-1, 0x1.39e8980a9cdp-56, | ||
| 104 | 	0x1.e7a51fbc74c83p-1, 0x1.2d522ca0c8ep-55, | ||
| 105 | 	0x1.ea4afa2a490dap-1, -0x1.e9c23179c288p-55, | ||
| 106 | 	0x1.ecf482d8e67f1p-1, -0x1.c93f3b411ad8p-55, | ||
| 107 | 	0x1.efa1bee615a27p-1, 0x1.dc7f486a4b68p-55, | ||
| 108 | 	0x1.f252b376bba97p-1, 0x1.3a1a5bf0d8e8p-55, | ||
| 109 | 	0x1.f50765b6e454p-1, 0x1.9d3e12dd8a18p-55, | ||
| 110 | 	0x1.f7bfdad9cbe14p-1, -0x1.dbb12d00635p-55, | ||
| 111 | 	0x1.fa7c1819e90d8p-1, 0x1.74853f3a593p-56, | ||
| 112 | 	0x1.fd3c22b8f71f1p-1, 0x1.2eb74966578p-58, | ||
| 113 | 	0x1p+0, 0x0p+0, | ||
| 114 | 	0x1.0163da9fb3335p+0, 0x1.b61299ab8cd8p-54, | ||
| 115 | 	0x1.02c9a3e778061p+0, -0x1.19083535b08p-56, | ||
| 116 | 	0x1.04315e86e7f85p+0, -0x1.0a31c1977c98p-54, | ||
| 117 | 	0x1.059b0d3158574p+0, 0x1.d73e2a475b4p-55, | ||
| 118 | 	0x1.0706b29ddf6dep+0, -0x1.c91dfe2b13cp-55, | ||
| 119 | 	0x1.0874518759bc8p+0, 0x1.186be4bb284p-57, | ||
| 120 | 	0x1.09e3ecac6f383p+0, 0x1.14878183161p-54, | ||
| 121 | 	0x1.0b5586cf9890fp+0, 0x1.8a62e4adc61p-54, | ||
| 122 | 	0x1.0cc922b7247f7p+0, 0x1.01edc16e24f8p-54, | ||
| 123 | 	0x1.0e3ec32d3d1a2p+0, 0x1.03a1727c58p-59, | ||
| 124 | 	0x1.0fb66affed31bp+0, -0x1.b9bedc44ebcp-57, | ||
| 125 | 	0x1.11301d0125b51p+0, -0x1.6c51039449bp-54, | ||
| 126 | 	0x1.12abdc06c31ccp+0, -0x1.1b514b36ca8p-58, | ||
| 127 | 	0x1.1429aaea92dep+0, -0x1.32fbf9af1368p-54, | ||
| 128 | 	0x1.15a98c8a58e51p+0, 0x1.2406ab9eeabp-55, | ||
| 129 | 	0x1.172b83c7d517bp+0, -0x1.19041b9d78ap-55, | ||
| 130 | 	0x1.18af9388c8deap+0, -0x1.11023d1970f8p-54, | ||
| 131 | 	0x1.1a35beb6fcb75p+0, 0x1.e5b4c7b4969p-55, | ||
| 132 | 	0x1.1bbe084045cd4p+0, -0x1.95386352ef6p-54, | ||
| 133 | 	0x1.1d4873168b9aap+0, 0x1.e016e00a264p-54, | ||
| 134 | 	0x1.1ed5022fcd91dp+0, -0x1.1df98027bb78p-54, | ||
| 135 | 	0x1.2063b88628cd6p+0, 0x1.dc775814a85p-55, | ||
| 136 | 	0x1.21f49917ddc96p+0, 0x1.2a97e9494a6p-55, | ||
| 137 | 	0x1.2387a6e756238p+0, 0x1.9b07eb6c7058p-54, | ||
| 138 | 	0x1.251ce4fb2a63fp+0, 0x1.ac155bef4f5p-55, | ||
| 139 | 	0x1.26b4565e27cddp+0, 0x1.2bd339940eap-55, | ||
| 140 | 	0x1.284dfe1f56381p+0, -0x1.a4c3a8c3f0d8p-54, | ||
| 141 | 	0x1.29e9df51fdee1p+0, 0x1.612e8afad12p-55, | ||
| 142 | 	0x1.2b87fd0dad99p+0, -0x1.10adcd6382p-59, | ||
| 143 | 	0x1.2d285a6e4030bp+0, 0x1.0024754db42p-54, | ||
| 144 | 	0x1.2ecafa93e2f56p+0, 0x1.1ca0f45d524p-56, | ||
| 145 | 	0x1.306fe0a31b715p+0, 0x1.6f46ad23183p-55, | ||
| 146 | 	0x1.32170fc4cd831p+0, 0x1.a9ce78e1804p-55, | ||
| 147 | 	0x1.33c08b26416ffp+0, 0x1.327218436598p-54, | ||
| 148 | 	0x1.356c55f929ff1p+0, -0x1.b5cee5c4e46p-55, | ||
| 149 | 	0x1.371a7373aa9cbp+0, -0x1.63aeabf42ebp-54, | ||
| 150 | 	0x1.38cae6d05d866p+0, -0x1.e958d3c99048p-54, | ||
| 151 | 	0x1.3a7db34e59ff7p+0, -0x1.5e436d661f6p-56, | ||
| 152 | 	0x1.3c32dc313a8e5p+0, -0x1.efff8375d2ap-54, | ||
| 153 | 	0x1.3dea64c123422p+0, 0x1.ada0911f09fp-55, | ||
| 154 | 	0x1.3fa4504ac801cp+0, -0x1.7d023f956fap-54, | ||
| 155 | 	0x1.4160a21f72e2ap+0, -0x1.ef3691c309p-58, | ||
| 156 | 	0x1.431f5d950a897p+0, -0x1.1c7dde35f7ap-55, | ||
| 157 | 	0x1.44e086061892dp+0, 0x1.89b7a04ef8p-59, | ||
| 158 | 	0x1.46a41ed1d0057p+0, 0x1.c944bd1648a8p-54, | ||
| 159 | 	0x1.486a2b5c13cdp+0, 0x1.3c1a3b69062p-56, | ||
| 160 | 	0x1.4a32af0d7d3dep+0, 0x1.9cb62f3d1be8p-54, | ||
| 161 | 	0x1.4bfdad5362a27p+0, 0x1.d4397afec42p-56, | ||
| 162 | 	0x1.4dcb299fddd0dp+0, 0x1.8ecdbbc6a78p-54, | ||
| 163 | 	0x1.4f9b2769d2ca7p+0, -0x1.4b309d25958p-54, | ||
| 164 | 	0x1.516daa2cf6642p+0, -0x1.f768569bd94p-55, | ||
| 165 | 	0x1.5342b569d4f82p+0, -0x1.07abe1db13dp-55, | ||
| 166 | 	0x1.551a4ca5d920fp+0, -0x1.d689cefede6p-55, | ||
| 167 | 	0x1.56f4736b527dap+0, 0x1.9bb2c011d938p-54, | ||
| 168 | 	0x1.58d12d497c7fdp+0, 0x1.295e15b9a1ep-55, | ||
| 169 | 	0x1.5ab07dd485429p+0, 0x1.6324c0546478p-54, | ||
| 170 | 	0x1.5c9268a5946b7p+0, 0x1.c4b1b81698p-60, | ||
| 171 | 	0x1.5e76f15ad2148p+0, 0x1.ba6f93080e68p-54, | ||
| 172 | 	0x1.605e1b976dc09p+0, -0x1.3e2429b56de8p-54, | ||
| 173 | 	0x1.6247eb03a5585p+0, -0x1.383c17e40b48p-54, | ||
| 174 | 	0x1.6434634ccc32p+0, -0x1.c483c759d89p-55, | ||
| 175 | 	0x1.6623882552225p+0, -0x1.bb60987591cp-54, | ||
| 176 | 	0x1.68155d44ca973p+0, 0x1.038ae44f74p-57, | ||
| 177 | }; | ||
| 178 | |||
| 179 | /* | ||
| 180 | * exp2l(x): compute the base 2 exponential of x | ||
| 181 | * | ||
| 182 | * Accuracy: Peak error < 0.511 ulp. | ||
| 183 | * | ||
| 184 | * Method: (equally-spaced tables) | ||
| 185 | * | ||
| 186 | * Reduce x: | ||
| 187 | * x = 2**k + y, for integer k and |y| <= 1/2. | ||
| 188 | * Thus we have exp2l(x) = 2**k * exp2(y). | ||
| 189 | * | ||
| 190 | * Reduce y: | ||
| 191 | * y = i/TBLSIZE + z for integer i near y * TBLSIZE. | ||
| 192 | * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z), | ||
| 193 | * with |z| <= 2**-(TBLBITS+1). | ||
| 194 | * | ||
| 195 | * We compute exp2(i/TBLSIZE) via table lookup and exp2(z) via a | ||
| 196 | * degree-6 minimax polynomial with maximum error under 2**-69. | ||
| 197 | * The table entries each have 104 bits of accuracy, encoded as | ||
| 198 | * a pair of double precision values. | ||
| 199 | */ | ||
| 200 | long double exp2l(long double x) | ||
| 201 | { | ||
| 202 | 	union ldshape u = {x}; | ||
| 203 | 	int e = u.i.se & 0x7fff; | ||
| 204 | 	long double r, z; | ||
| 205 | 	uint32_t i0; | ||
| 206 | 	union {uint32_t u; int32_t i;} k; | ||
| 207 | |||
| 208 | 	/* Filter out exceptional cases. */ | ||
| 209 | 	if (e >= 0x3fff + 13) { /* |x| >= 8192 or x is NaN */ | ||
| 210 | 		if (u.i.se >= 0x3fff + 14 && u.i.se >> 15 == 0) | ||
| 211 | 			/* overflow */ | ||
| 212 | 			return x * 0x1p16383L; | ||
| 213 | 		if (e == 0x7fff) /* -inf or -nan */ | ||
| 214 | 			return -1/x; | ||
| 215 | 		if (x < -16382) { | ||
| 216 | 			if (x <= -16446 || x - 0x1p63 + 0x1p63 != x) | ||
| 217 | 				/* underflow */ | ||
| 218 | 				FORCE_EVAL((float)(-0x1p-149/x)); | ||
| 219 | 			if (x <= -16446) | ||
| 220 | 				return 0; | ||
| 221 | 		} | ||
| 222 | 	} else if (e < 0x3fff - 64) { | ||
| 223 | 		return 1 + x; | ||
| 224 | 	} | ||
| 225 | |||
| 226 | 	/* | ||
| 227 | 	 * Reduce x, computing z, i0, and k. The low bits of x + redux | ||
| 228 | 	 * contain the 16-bit integer part of the exponent (k) followed by | ||
| 229 | 	 * TBLBITS fractional bits (i0). We use bit tricks to extract these | ||
| 230 | 	 * as integers, then set z to the remainder. | ||
| 231 | 	 * | ||
| 232 | 	 * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8. | ||
| 233 | 	 * Then the low-order word of x + redux is 0x000abc12, | ||
| 234 | 	 * We split this into k = 0xabc and i0 = 0x12 (adjusted to | ||
| 235 | 	 * index into the table), then we compute z = 0x0.003456p0. | ||
| 236 | 	 */ | ||
| 237 | 	u.f = x + redux; | ||
| 238 | 	i0 = u.i.m + TBLSIZE / 2; | ||
| 239 | 	k.u = i0 / TBLSIZE * TBLSIZE; | ||
| 240 | 	k.i /= TBLSIZE; | ||
| 241 | 	i0 %= TBLSIZE; | ||
| 242 | 	u.f -= redux; | ||
| 243 | 	z = x - u.f; | ||
| 244 | |||
| 245 | 	/* Compute r = exp2l(y) = exp2lt[i0] * p(z). */ | ||
| 246 | 	long double t_hi = tbl[2*i0]; | ||
| 247 | 	long double t_lo = tbl[2*i0 + 1]; | ||
| 248 | 	/* XXX This gives > 1 ulp errors outside of FE_TONEAREST mode */ | ||
| 249 | 	r = t_lo + (t_hi + t_lo) * z * (P1 + z * (P2 + z * (P3 + z * (P4 | ||
| 250 | 	 + z * (P5 + z * P6))))) + t_hi; | ||
| 251 | |||
| 252 | 	return scalbnl(r, k.i); | ||
| 253 | } | ||
| 254 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 255 | #define TBLBITS 7 | ||
| 256 | #define TBLSIZE (1 << TBLBITS) | ||
| 257 | |||
| 258 | static const long double | ||
| 259 | P1 = 0x1.62e42fefa39ef35793c7673007e6p-1L, | ||
| 260 | P2 = 0x1.ebfbdff82c58ea86f16b06ec9736p-3L, | ||
| 261 | P3 = 0x1.c6b08d704a0bf8b33a762bad3459p-5L, | ||
| 262 | P4 = 0x1.3b2ab6fba4e7729ccbbe0b4f3fc2p-7L, | ||
| 263 | P5 = 0x1.5d87fe78a67311071dee13fd11d9p-10L, | ||
| 264 | P6 = 0x1.430912f86c7876f4b663b23c5fe5p-13L; | ||
| 265 | |||
| 266 | static const double | ||
| 267 | P7 = 0x1.ffcbfc588b041p-17, | ||
| 268 | P8 = 0x1.62c0223a5c7c7p-20, | ||
| 269 | P9 = 0x1.b52541ff59713p-24, | ||
| 270 | P10 = 0x1.e4cf56a391e22p-28, | ||
| 271 | redux = 0x1.8p112 / TBLSIZE; | ||
| 272 | |||
| 273 | static const long double tbl[TBLSIZE] = { | ||
| 274 | 	0x1.6a09e667f3bcc908b2fb1366dfeap-1L, | ||
| 275 | 	0x1.6c012750bdabeed76a99800f4edep-1L, | ||
| 276 | 	0x1.6dfb23c651a2ef220e2cbe1bc0d4p-1L, | ||
| 277 | 	0x1.6ff7df9519483cf87e1b4f3e1e98p-1L, | ||
| 278 | 	0x1.71f75e8ec5f73dd2370f2ef0b148p-1L, | ||
| 279 | 	0x1.73f9a48a58173bd5c9a4e68ab074p-1L, | ||
| 280 | 	0x1.75feb564267c8bf6e9aa33a489a8p-1L, | ||
| 281 | 	0x1.780694fde5d3f619ae02808592a4p-1L, | ||
| 282 | 	0x1.7a11473eb0186d7d51023f6ccb1ap-1L, | ||
| 283 | 	0x1.7c1ed0130c1327c49334459378dep-1L, | ||
| 284 | 	0x1.7e2f336cf4e62105d02ba1579756p-1L, | ||
| 285 | 	0x1.80427543e1a11b60de67649a3842p-1L, | ||
| 286 | 	0x1.82589994cce128acf88afab34928p-1L, | ||
| 287 | 	0x1.8471a4623c7acce52f6b97c6444cp-1L, | ||
| 288 | 	0x1.868d99b4492ec80e41d90ac2556ap-1L, | ||
| 289 | 	0x1.88ac7d98a669966530bcdf2d4cc0p-1L, | ||
| 290 | 	0x1.8ace5422aa0db5ba7c55a192c648p-1L, | ||
| 291 | 	0x1.8cf3216b5448bef2aa1cd161c57ap-1L, | ||
| 292 | 	0x1.8f1ae991577362b982745c72eddap-1L, | ||
| 293 | 	0x1.9145b0b91ffc588a61b469f6b6a0p-1L, | ||
| 294 | 	0x1.93737b0cdc5e4f4501c3f2540ae8p-1L, | ||
| 295 | 	0x1.95a44cbc8520ee9b483695a0e7fep-1L, | ||
| 296 | 	0x1.97d829fde4e4f8b9e920f91e8eb6p-1L, | ||
| 297 | 	0x1.9a0f170ca07b9ba3109b8c467844p-1L, | ||
| 298 | 	0x1.9c49182a3f0901c7c46b071f28dep-1L, | ||
| 299 | 	0x1.9e86319e323231824ca78e64c462p-1L, | ||
| 300 | 	0x1.a0c667b5de564b29ada8b8cabbacp-1L, | ||
| 301 | 	0x1.a309bec4a2d3358c171f770db1f4p-1L, | ||
| 302 | 	0x1.a5503b23e255c8b424491caf88ccp-1L, | ||
| 303 | 	0x1.a799e1330b3586f2dfb2b158f31ep-1L, | ||
| 304 | 	0x1.a9e6b5579fdbf43eb243bdff53a2p-1L, | ||
| 305 | 	0x1.ac36bbfd3f379c0db966a3126988p-1L, | ||
| 306 | 	0x1.ae89f995ad3ad5e8734d17731c80p-1L, | ||
| 307 | 	0x1.b0e07298db66590842acdfc6fb4ep-1L, | ||
| 308 | 	0x1.b33a2b84f15faf6bfd0e7bd941b0p-1L, | ||
| 309 | 	0x1.b59728de559398e3881111648738p-1L, | ||
| 310 | 	0x1.b7f76f2fb5e46eaa7b081ab53ff6p-1L, | ||
| 311 | 	0x1.ba5b030a10649840cb3c6af5b74cp-1L, | ||
| 312 | 	0x1.bcc1e904bc1d2247ba0f45b3d06cp-1L, | ||
| 313 | 	0x1.bf2c25bd71e088408d7025190cd0p-1L, | ||
| 314 | 	0x1.c199bdd85529c2220cb12a0916bap-1L, | ||
| 315 | 	0x1.c40ab5fffd07a6d14df820f17deap-1L, | ||
| 316 | 	0x1.c67f12e57d14b4a2137fd20f2a26p-1L, | ||
| 317 | 	0x1.c8f6d9406e7b511acbc48805c3f6p-1L, | ||
| 318 | 	0x1.cb720dcef90691503cbd1e949d0ap-1L, | ||
| 319 | 	0x1.cdf0b555dc3f9c44f8958fac4f12p-1L, | ||
| 320 | 	0x1.d072d4a07897b8d0f22f21a13792p-1L, | ||
| 321 | 	0x1.d2f87080d89f18ade123989ea50ep-1L, | ||
| 322 | 	0x1.d5818dcfba48725da05aeb66dff8p-1L, | ||
| 323 | 	0x1.d80e316c98397bb84f9d048807a0p-1L, | ||
| 324 | 	0x1.da9e603db3285708c01a5b6d480cp-1L, | ||
| 325 | 	0x1.dd321f301b4604b695de3c0630c0p-1L, | ||
| 326 | 	0x1.dfc97337b9b5eb968cac39ed284cp-1L, | ||
| 327 | 	0x1.e264614f5a128a12761fa17adc74p-1L, | ||
| 328 | 	0x1.e502ee78b3ff6273d130153992d0p-1L, | ||
| 329 | 	0x1.e7a51fbc74c834b548b2832378a4p-1L, | ||
| 330 | 	0x1.ea4afa2a490d9858f73a18f5dab4p-1L, | ||
| 331 | 	0x1.ecf482d8e67f08db0312fb949d50p-1L, | ||
| 332 | 	0x1.efa1bee615a27771fd21a92dabb6p-1L, | ||
| 333 | 	0x1.f252b376bba974e8696fc3638f24p-1L, | ||
| 334 | 	0x1.f50765b6e4540674f84b762861a6p-1L, | ||
| 335 | 	0x1.f7bfdad9cbe138913b4bfe72bd78p-1L, | ||
| 336 | 	0x1.fa7c1819e90d82e90a7e74b26360p-1L, | ||
| 337 | 	0x1.fd3c22b8f71f10975ba4b32bd006p-1L, | ||
| 338 | 	0x1.0000000000000000000000000000p+0L, | ||
| 339 | 	0x1.0163da9fb33356d84a66ae336e98p+0L, | ||
| 340 | 	0x1.02c9a3e778060ee6f7caca4f7a18p+0L, | ||
| 341 | 	0x1.04315e86e7f84bd738f9a20da442p+0L, | ||
| 342 | 	0x1.059b0d31585743ae7c548eb68c6ap+0L, | ||
| 343 | 	0x1.0706b29ddf6ddc6dc403a9d87b1ep+0L, | ||
| 344 | 	0x1.0874518759bc808c35f25d942856p+0L, | ||
| 345 | 	0x1.09e3ecac6f3834521e060c584d5cp+0L, | ||
| 346 | 	0x1.0b5586cf9890f6298b92b7184200p+0L, | ||
| 347 | 	0x1.0cc922b7247f7407b705b893dbdep+0L, | ||
| 348 | 	0x1.0e3ec32d3d1a2020742e4f8af794p+0L, | ||
| 349 | 	0x1.0fb66affed31af232091dd8a169ep+0L, | ||
| 350 | 	0x1.11301d0125b50a4ebbf1aed9321cp+0L, | ||
| 351 | 	0x1.12abdc06c31cbfb92bad324d6f84p+0L, | ||
| 352 | 	0x1.1429aaea92ddfb34101943b2588ep+0L, | ||
| 353 | 	0x1.15a98c8a58e512480d573dd562aep+0L, | ||
| 354 | 	0x1.172b83c7d517adcdf7c8c50eb162p+0L, | ||
| 355 | 	0x1.18af9388c8de9bbbf70b9a3c269cp+0L, | ||
| 356 | 	0x1.1a35beb6fcb753cb698f692d2038p+0L, | ||
| 357 | 	0x1.1bbe084045cd39ab1e72b442810ep+0L, | ||
| 358 | 	0x1.1d4873168b9aa7805b8028990be8p+0L, | ||
| 359 | 	0x1.1ed5022fcd91cb8819ff61121fbep+0L, | ||
| 360 | 	0x1.2063b88628cd63b8eeb0295093f6p+0L, | ||
| 361 | 	0x1.21f49917ddc962552fd29294bc20p+0L, | ||
| 362 | 	0x1.2387a6e75623866c1fadb1c159c0p+0L, | ||
| 363 | 	0x1.251ce4fb2a63f3582ab7de9e9562p+0L, | ||
| 364 | 	0x1.26b4565e27cdd257a673281d3068p+0L, | ||
| 365 | 	0x1.284dfe1f5638096cf15cf03c9fa0p+0L, | ||
| 366 | 	0x1.29e9df51fdee12c25d15f5a25022p+0L, | ||
| 367 | 	0x1.2b87fd0dad98ffddea46538fca24p+0L, | ||
| 368 | 	0x1.2d285a6e4030b40091d536d0733ep+0L, | ||
| 369 | 	0x1.2ecafa93e2f5611ca0f45d5239a4p+0L, | ||
| 370 | 	0x1.306fe0a31b7152de8d5a463063bep+0L, | ||
| 371 | 	0x1.32170fc4cd8313539cf1c3009330p+0L, | ||
| 372 | 	0x1.33c08b26416ff4c9c8610d96680ep+0L, | ||
| 373 | 	0x1.356c55f929ff0c94623476373be4p+0L, | ||
| 374 | 	0x1.371a7373aa9caa7145502f45452ap+0L, | ||
| 375 | 	0x1.38cae6d05d86585a9cb0d9bed530p+0L, | ||
| 376 | 	0x1.3a7db34e59ff6ea1bc9299e0a1fep+0L, | ||
| 377 | 	0x1.3c32dc313a8e484001f228b58cf0p+0L, | ||
| 378 | 	0x1.3dea64c12342235b41223e13d7eep+0L, | ||
| 379 | 	0x1.3fa4504ac801ba0bf701aa417b9cp+0L, | ||
| 380 | 	0x1.4160a21f72e29f84325b8f3dbacap+0L, | ||
| 381 | 	0x1.431f5d950a896dc704439410b628p+0L, | ||
| 382 | 	0x1.44e086061892d03136f409df0724p+0L, | ||
| 383 | 	0x1.46a41ed1d005772512f459229f0ap+0L, | ||
| 384 | 	0x1.486a2b5c13cd013c1a3b69062f26p+0L, | ||
| 385 | 	0x1.4a32af0d7d3de672d8bcf46f99b4p+0L, | ||
| 386 | 	0x1.4bfdad5362a271d4397afec42e36p+0L, | ||
| 387 | 	0x1.4dcb299fddd0d63b36ef1a9e19dep+0L, | ||
| 388 | 	0x1.4f9b2769d2ca6ad33d8b69aa0b8cp+0L, | ||
| 389 | 	0x1.516daa2cf6641c112f52c84d6066p+0L, | ||
| 390 | 	0x1.5342b569d4f81df0a83c49d86bf4p+0L, | ||
| 391 | 	0x1.551a4ca5d920ec52ec620243540cp+0L, | ||
| 392 | 	0x1.56f4736b527da66ecb004764e61ep+0L, | ||
| 393 | 	0x1.58d12d497c7fd252bc2b7343d554p+0L, | ||
| 394 | 	0x1.5ab07dd48542958c93015191e9a8p+0L, | ||
| 395 | 	0x1.5c9268a5946b701c4b1b81697ed4p+0L, | ||
| 396 | 	0x1.5e76f15ad21486e9be4c20399d12p+0L, | ||
| 397 | 	0x1.605e1b976dc08b076f592a487066p+0L, | ||
| 398 | 	0x1.6247eb03a5584b1f0fa06fd2d9eap+0L, | ||
| 399 | 	0x1.6434634ccc31fc76f8714c4ee122p+0L, | ||
| 400 | 	0x1.66238825522249127d9e29b92ea2p+0L, | ||
| 401 | 	0x1.68155d44ca973081c57227b9f69ep+0L, | ||
| 402 | }; | ||
| 403 | |||
| 404 | static const float eps[TBLSIZE] = { | ||
| 405 | 	-0x1.5c50p-101, | ||
| 406 | 	-0x1.5d00p-106, | ||
| 407 | 	 0x1.8e90p-102, | ||
| 408 | 	-0x1.5340p-103, | ||
| 409 | 	 0x1.1bd0p-102, | ||
| 410 | 	-0x1.4600p-105, | ||
| 411 | 	-0x1.7a40p-104, | ||
| 412 | 	 0x1.d590p-102, | ||
| 413 | 	-0x1.d590p-101, | ||
| 414 | 	 0x1.b100p-103, | ||
| 415 | 	-0x1.0d80p-105, | ||
| 416 | 	 0x1.6b00p-103, | ||
| 417 | 	-0x1.9f00p-105, | ||
| 418 | 	 0x1.c400p-103, | ||
| 419 | 	 0x1.e120p-103, | ||
| 420 | 	-0x1.c100p-104, | ||
| 421 | 	-0x1.9d20p-103, | ||
| 422 | 	 0x1.a800p-108, | ||
| 423 | 	 0x1.4c00p-106, | ||
| 424 | 	-0x1.9500p-106, | ||
| 425 | 	 0x1.6900p-105, | ||
| 426 | 	-0x1.29d0p-100, | ||
| 427 | 	 0x1.4c60p-103, | ||
| 428 | 	 0x1.13a0p-102, | ||
| 429 | 	-0x1.5b60p-103, | ||
| 430 | 	-0x1.1c40p-103, | ||
| 431 | 	 0x1.db80p-102, | ||
| 432 | 	 0x1.91a0p-102, | ||
| 433 | 	 0x1.dc00p-105, | ||
| 434 | 	 0x1.44c0p-104, | ||
| 435 | 	 0x1.9710p-102, | ||
| 436 | 	 0x1.8760p-103, | ||
| 437 | 	-0x1.a720p-103, | ||
| 438 | 	 0x1.ed20p-103, | ||
| 439 | 	-0x1.49c0p-102, | ||
| 440 | 	-0x1.e000p-111, | ||
| 441 | 	 0x1.86a0p-103, | ||
| 442 | 	 0x1.2b40p-103, | ||
| 443 | 	-0x1.b400p-108, | ||
| 444 | 	 0x1.1280p-99, | ||
| 445 | 	-0x1.02d8p-102, | ||
| 446 | 	-0x1.e3d0p-103, | ||
| 447 | 	-0x1.b080p-105, | ||
| 448 | 	-0x1.f100p-107, | ||
| 449 | 	-0x1.16c0p-105, | ||
| 450 | 	-0x1.1190p-103, | ||
| 451 | 	-0x1.a7d2p-100, | ||
| 452 | 	 0x1.3450p-103, | ||
| 453 | 	-0x1.67c0p-105, | ||
| 454 | 	 0x1.4b80p-104, | ||
| 455 | 	-0x1.c4e0p-103, | ||
| 456 | 	 0x1.6000p-108, | ||
| 457 | 	-0x1.3f60p-105, | ||
| 458 | 	 0x1.93f0p-104, | ||
| 459 | 	 0x1.5fe0p-105, | ||
| 460 | 	 0x1.6f80p-107, | ||
| 461 | 	-0x1.7600p-106, | ||
| 462 | 	 0x1.21e0p-106, | ||
| 463 | 	-0x1.3a40p-106, | ||
| 464 | 	-0x1.40c0p-104, | ||
| 465 | 	-0x1.9860p-105, | ||
| 466 | 	-0x1.5d40p-108, | ||
| 467 | 	-0x1.1d70p-106, | ||
| 468 | 	 0x1.2760p-105, | ||
| 469 | 	 0x0.0000p+0, | ||
| 470 | 	 0x1.21e2p-104, | ||
| 471 | 	-0x1.9520p-108, | ||
| 472 | 	-0x1.5720p-106, | ||
| 473 | 	-0x1.4810p-106, | ||
| 474 | 	-0x1.be00p-109, | ||
| 475 | 	 0x1.0080p-105, | ||
| 476 | 	-0x1.5780p-108, | ||
| 477 | 	-0x1.d460p-105, | ||
| 478 | 	-0x1.6140p-105, | ||
| 479 | 	 0x1.4630p-104, | ||
| 480 | 	 0x1.ad50p-103, | ||
| 481 | 	 0x1.82e0p-105, | ||
| 482 | 	 0x1.1d3cp-101, | ||
| 483 | 	 0x1.6100p-107, | ||
| 484 | 	 0x1.ec30p-104, | ||
| 485 | 	 0x1.f200p-108, | ||
| 486 | 	 0x1.0b40p-103, | ||
| 487 | 	 0x1.3660p-102, | ||
| 488 | 	 0x1.d9d0p-103, | ||
| 489 | 	-0x1.02d0p-102, | ||
| 490 | 	 0x1.b070p-103, | ||
| 491 | 	 0x1.b9c0p-104, | ||
| 492 | 	-0x1.01c0p-103, | ||
| 493 | 	-0x1.dfe0p-103, | ||
| 494 | 	 0x1.1b60p-104, | ||
| 495 | 	-0x1.ae94p-101, | ||
| 496 | 	-0x1.3340p-104, | ||
| 497 | 	 0x1.b3d8p-102, | ||
| 498 | 	-0x1.6e40p-105, | ||
| 499 | 	-0x1.3670p-103, | ||
| 500 | 	 0x1.c140p-104, | ||
| 501 | 	 0x1.1840p-101, | ||
| 502 | 	 0x1.1ab0p-102, | ||
| 503 | 	-0x1.a400p-104, | ||
| 504 | 	 0x1.1f00p-104, | ||
| 505 | 	-0x1.7180p-103, | ||
| 506 | 	 0x1.4ce0p-102, | ||
| 507 | 	 0x1.9200p-107, | ||
| 508 | 	-0x1.54c0p-103, | ||
| 509 | 	 0x1.1b80p-105, | ||
| 510 | 	-0x1.1828p-101, | ||
| 511 | 	 0x1.5720p-102, | ||
| 512 | 	-0x1.a060p-100, | ||
| 513 | 	 0x1.9160p-102, | ||
| 514 | 	 0x1.a280p-104, | ||
| 515 | 	 0x1.3400p-107, | ||
| 516 | 	 0x1.2b20p-102, | ||
| 517 | 	 0x1.7800p-108, | ||
| 518 | 	 0x1.cfd0p-101, | ||
| 519 | 	 0x1.2ef0p-102, | ||
| 520 | 	-0x1.2760p-99, | ||
| 521 | 	 0x1.b380p-104, | ||
| 522 | 	 0x1.0048p-101, | ||
| 523 | 	-0x1.60b0p-102, | ||
| 524 | 	 0x1.a1ccp-100, | ||
| 525 | 	-0x1.a640p-104, | ||
| 526 | 	-0x1.08a0p-101, | ||
| 527 | 	 0x1.7e60p-102, | ||
| 528 | 	 0x1.22c0p-103, | ||
| 529 | 	-0x1.7200p-106, | ||
| 530 | 	 0x1.f0f0p-102, | ||
| 531 | 	 0x1.eb4ep-99, | ||
| 532 | 	 0x1.c6e0p-103, | ||
| 533 | }; | ||
| 534 | |||
| 535 | /* | ||
| 536 | * exp2l(x): compute the base 2 exponential of x | ||
| 537 | * | ||
| 538 | * Accuracy: Peak error < 0.502 ulp. | ||
| 539 | * | ||
| 540 | * Method: (accurate tables) | ||
| 541 | * | ||
| 542 | * Reduce x: | ||
| 543 | * x = 2**k + y, for integer k and |y| <= 1/2. | ||
| 544 | * Thus we have exp2(x) = 2**k * exp2(y). | ||
| 545 | * | ||
| 546 | * Reduce y: | ||
| 547 | * y = i/TBLSIZE + z - eps[i] for integer i near y * TBLSIZE. | ||
| 548 | * Thus we have exp2(y) = exp2(i/TBLSIZE) * exp2(z - eps[i]), | ||
| 549 | * with |z - eps[i]| <= 2**-8 + 2**-98 for the table used. | ||
| 550 | * | ||
| 551 | * We compute exp2(i/TBLSIZE) via table lookup and exp2(z - eps[i]) via | ||
| 552 | * a degree-10 minimax polynomial with maximum error under 2**-120. | ||
| 553 | * The values in exp2t[] and eps[] are chosen such that | ||
| 554 | * exp2t[i] = exp2(i/TBLSIZE + eps[i]), and eps[i] is a small offset such | ||
| 555 | * that exp2t[i] is accurate to 2**-122. | ||
| 556 | * | ||
| 557 | * Note that the range of i is +-TBLSIZE/2, so we actually index the tables | ||
| 558 | * by i0 = i + TBLSIZE/2. | ||
| 559 | * | ||
| 560 | * This method is due to Gal, with many details due to Gal and Bachelis: | ||
| 561 | * | ||
| 562 | *	Gal, S. and Bachelis, B. An Accurate Elementary Mathematical Library | ||
| 563 | *	for the IEEE Floating Point Standard. TOMS 17(1), 26-46 (1991). | ||
| 564 | */ | ||
| 565 | long double | ||
| 566 | exp2l(long double x) | ||
| 567 | { | ||
| 568 | 	union ldshape u = {x}; | ||
| 569 | 	int e = u.i.se & 0x7fff; | ||
| 570 | 	long double r, z, t; | ||
| 571 | 	uint32_t i0; | ||
| 572 | 	union {uint32_t u; int32_t i;} k; | ||
| 573 | |||
| 574 | 	/* Filter out exceptional cases. */ | ||
| 575 | 	if (e >= 0x3fff + 14) { /* |x| >= 16384 or x is NaN */ | ||
| 576 | 		if (u.i.se >= 0x3fff + 15 && u.i.se >> 15 == 0) | ||
| 577 | 			/* overflow */ | ||
| 578 | 			return x * 0x1p16383L; | ||
| 579 | 		if (e == 0x7fff) /* -inf or -nan */ | ||
| 580 | 			return -1/x; | ||
| 581 | 		if (x < -16382) { | ||
| 582 | 			if (x <= -16495 || x - 0x1p112 + 0x1p112 != x) | ||
| 583 | 				/* underflow */ | ||
| 584 | 				FORCE_EVAL((float)(-0x1p-149/x)); | ||
| 585 | 			if (x <= -16446) | ||
| 586 | 				return 0; | ||
| 587 | 		} | ||
| 588 | 	} else if (e < 0x3fff - 114) { | ||
| 589 | 		return 1 + x; | ||
| 590 | 	} | ||
| 591 | |||
| 592 | 	/* | ||
| 593 | 	 * Reduce x, computing z, i0, and k. The low bits of x + redux | ||
| 594 | 	 * contain the 16-bit integer part of the exponent (k) followed by | ||
| 595 | 	 * TBLBITS fractional bits (i0). We use bit tricks to extract these | ||
| 596 | 	 * as integers, then set z to the remainder. | ||
| 597 | 	 * | ||
| 598 | 	 * Example: Suppose x is 0xabc.123456p0 and TBLBITS is 8. | ||
| 599 | 	 * Then the low-order word of x + redux is 0x000abc12, | ||
| 600 | 	 * We split this into k = 0xabc and i0 = 0x12 (adjusted to | ||
| 601 | 	 * index into the table), then we compute z = 0x0.003456p0. | ||
| 602 | 	 */ | ||
| 603 | 	u.f = x + redux; | ||
| 604 | 	i0 = u.i2.lo + TBLSIZE / 2; | ||
| 605 | 	k.u = i0 / TBLSIZE * TBLSIZE; | ||
| 606 | 	k.i /= TBLSIZE; | ||
| 607 | 	i0 %= TBLSIZE; | ||
| 608 | 	u.f -= redux; | ||
| 609 | 	z = x - u.f; | ||
| 610 | |||
| 611 | 	/* Compute r = exp2(y) = exp2t[i0] * p(z - eps[i]). */ | ||
| 612 | 	t = tbl[i0]; | ||
| 613 | 	z -= eps[i0]; | ||
| 614 | 	r = t + t * z * (P1 + z * (P2 + z * (P3 + z * (P4 + z * (P5 + z * (P6 | ||
| 615 | 	 + z * (P7 + z * (P8 + z * (P9 + z * P10))))))))); | ||
| 616 | |||
| 617 | 	return scalbnl(r, k.i); | ||
| 618 | } | ||
| 619 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp_data.c created+182| ... | @@ -0,0 +1,182 @@ | ||
| 1 | /* | ||
| 2 | * Shared data between exp, exp2 and pow. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "exp_data.h" | ||
| 9 | |||
| 10 | #define N (1 << EXP_TABLE_BITS) | ||
| 11 | |||
| 12 | const struct exp_data __exp_data = { | ||
| 13 | // N/ln2 | ||
| 14 | .invln2N = 0x1.71547652b82fep0 * N, | ||
| 15 | // -ln2/N | ||
| 16 | .negln2hiN = -0x1.62e42fefa0000p-8, | ||
| 17 | .negln2loN = -0x1.cf79abc9e3b3ap-47, | ||
| 18 | // Used for rounding when !TOINT_INTRINSICS | ||
| 19 | #if EXP_USE_TOINT_NARROW | ||
| 20 | .shift = 0x1800000000.8p0, | ||
| 21 | #else | ||
| 22 | .shift = 0x1.8p52, | ||
| 23 | #endif | ||
| 24 | // exp polynomial coefficients. | ||
| 25 | .poly = { | ||
| 26 | // abs error: 1.555*2^-66 | ||
| 27 | // ulp error: 0.509 (0.511 without fma) | ||
| 28 | // if |x| < ln2/256+eps | ||
| 29 | // abs error if |x| < ln2/256+0x1p-15: 1.09*2^-65 | ||
| 30 | // abs error if |x| < ln2/128: 1.7145*2^-56 | ||
| 31 | 0x1.ffffffffffdbdp-2, | ||
| 32 | 0x1.555555555543cp-3, | ||
| 33 | 0x1.55555cf172b91p-5, | ||
| 34 | 0x1.1111167a4d017p-7, | ||
| 35 | }, | ||
| 36 | .exp2_shift = 0x1.8p52 / N, | ||
| 37 | // exp2 polynomial coefficients. | ||
| 38 | .exp2_poly = { | ||
| 39 | // abs error: 1.2195*2^-65 | ||
| 40 | // ulp error: 0.507 (0.511 without fma) | ||
| 41 | // if |x| < 1/256 | ||
| 42 | // abs error if |x| < 1/128: 1.9941*2^-56 | ||
| 43 | 0x1.62e42fefa39efp-1, | ||
| 44 | 0x1.ebfbdff82c424p-3, | ||
| 45 | 0x1.c6b08d70cf4b5p-5, | ||
| 46 | 0x1.3b2abd24650ccp-7, | ||
| 47 | 0x1.5d7e09b4e3a84p-10, | ||
| 48 | }, | ||
| 49 | // 2^(k/N) ~= H[k]*(1 + T[k]) for int k in [0,N) | ||
| 50 | // tab[2*k] = asuint64(T[k]) | ||
| 51 | // tab[2*k+1] = asuint64(H[k]) - (k << 52)/N | ||
| 52 | .tab = { | ||
| 53 | 0x0, 0x3ff0000000000000, | ||
| 54 | 0x3c9b3b4f1a88bf6e, 0x3feff63da9fb3335, | ||
| 55 | 0xbc7160139cd8dc5d, 0x3fefec9a3e778061, | ||
| 56 | 0xbc905e7a108766d1, 0x3fefe315e86e7f85, | ||
| 57 | 0x3c8cd2523567f613, 0x3fefd9b0d3158574, | ||
| 58 | 0xbc8bce8023f98efa, 0x3fefd06b29ddf6de, | ||
| 59 | 0x3c60f74e61e6c861, 0x3fefc74518759bc8, | ||
| 60 | 0x3c90a3e45b33d399, 0x3fefbe3ecac6f383, | ||
| 61 | 0x3c979aa65d837b6d, 0x3fefb5586cf9890f, | ||
| 62 | 0x3c8eb51a92fdeffc, 0x3fefac922b7247f7, | ||
| 63 | 0x3c3ebe3d702f9cd1, 0x3fefa3ec32d3d1a2, | ||
| 64 | 0xbc6a033489906e0b, 0x3fef9b66affed31b, | ||
| 65 | 0xbc9556522a2fbd0e, 0x3fef9301d0125b51, | ||
| 66 | 0xbc5080ef8c4eea55, 0x3fef8abdc06c31cc, | ||
| 67 | 0xbc91c923b9d5f416, 0x3fef829aaea92de0, | ||
| 68 | 0x3c80d3e3e95c55af, 0x3fef7a98c8a58e51, | ||
| 69 | 0xbc801b15eaa59348, 0x3fef72b83c7d517b, | ||
| 70 | 0xbc8f1ff055de323d, 0x3fef6af9388c8dea, | ||
| 71 | 0x3c8b898c3f1353bf, 0x3fef635beb6fcb75, | ||
| 72 | 0xbc96d99c7611eb26, 0x3fef5be084045cd4, | ||
| 73 | 0x3c9aecf73e3a2f60, 0x3fef54873168b9aa, | ||
| 74 | 0xbc8fe782cb86389d, 0x3fef4d5022fcd91d, | ||
| 75 | 0x3c8a6f4144a6c38d, 0x3fef463b88628cd6, | ||
| 76 | 0x3c807a05b0e4047d, 0x3fef3f49917ddc96, | ||
| 77 | 0x3c968efde3a8a894, 0x3fef387a6e756238, | ||
| 78 | 0x3c875e18f274487d, 0x3fef31ce4fb2a63f, | ||
| 79 | 0x3c80472b981fe7f2, 0x3fef2b4565e27cdd, | ||
| 80 | 0xbc96b87b3f71085e, 0x3fef24dfe1f56381, | ||
| 81 | 0x3c82f7e16d09ab31, 0x3fef1e9df51fdee1, | ||
| 82 | 0xbc3d219b1a6fbffa, 0x3fef187fd0dad990, | ||
| 83 | 0x3c8b3782720c0ab4, 0x3fef1285a6e4030b, | ||
| 84 | 0x3c6e149289cecb8f, 0x3fef0cafa93e2f56, | ||
| 85 | 0x3c834d754db0abb6, 0x3fef06fe0a31b715, | ||
| 86 | 0x3c864201e2ac744c, 0x3fef0170fc4cd831, | ||
| 87 | 0x3c8fdd395dd3f84a, 0x3feefc08b26416ff, | ||
| 88 | 0xbc86a3803b8e5b04, 0x3feef6c55f929ff1, | ||
| 89 | 0xbc924aedcc4b5068, 0x3feef1a7373aa9cb, | ||
| 90 | 0xbc9907f81b512d8e, 0x3feeecae6d05d866, | ||
| 91 | 0xbc71d1e83e9436d2, 0x3feee7db34e59ff7, | ||
| 92 | 0xbc991919b3ce1b15, 0x3feee32dc313a8e5, | ||
| 93 | 0x3c859f48a72a4c6d, 0x3feedea64c123422, | ||
| 94 | 0xbc9312607a28698a, 0x3feeda4504ac801c, | ||
| 95 | 0xbc58a78f4817895b, 0x3feed60a21f72e2a, | ||
| 96 | 0xbc7c2c9b67499a1b, 0x3feed1f5d950a897, | ||
| 97 | 0x3c4363ed60c2ac11, 0x3feece086061892d, | ||
| 98 | 0x3c9666093b0664ef, 0x3feeca41ed1d0057, | ||
| 99 | 0x3c6ecce1daa10379, 0x3feec6a2b5c13cd0, | ||
| 100 | 0x3c93ff8e3f0f1230, 0x3feec32af0d7d3de, | ||
| 101 | 0x3c7690cebb7aafb0, 0x3feebfdad5362a27, | ||
| 102 | 0x3c931dbdeb54e077, 0x3feebcb299fddd0d, | ||
| 103 | 0xbc8f94340071a38e, 0x3feeb9b2769d2ca7, | ||
| 104 | 0xbc87deccdc93a349, 0x3feeb6daa2cf6642, | ||
| 105 | 0xbc78dec6bd0f385f, 0x3feeb42b569d4f82, | ||
| 106 | 0xbc861246ec7b5cf6, 0x3feeb1a4ca5d920f, | ||
| 107 | 0x3c93350518fdd78e, 0x3feeaf4736b527da, | ||
| 108 | 0x3c7b98b72f8a9b05, 0x3feead12d497c7fd, | ||
| 109 | 0x3c9063e1e21c5409, 0x3feeab07dd485429, | ||
| 110 | 0x3c34c7855019c6ea, 0x3feea9268a5946b7, | ||
| 111 | 0x3c9432e62b64c035, 0x3feea76f15ad2148, | ||
| 112 | 0xbc8ce44a6199769f, 0x3feea5e1b976dc09, | ||
| 113 | 0xbc8c33c53bef4da8, 0x3feea47eb03a5585, | ||
| 114 | 0xbc845378892be9ae, 0x3feea34634ccc320, | ||
| 115 | 0xbc93cedd78565858, 0x3feea23882552225, | ||
| 116 | 0x3c5710aa807e1964, 0x3feea155d44ca973, | ||
| 117 | 0xbc93b3efbf5e2228, 0x3feea09e667f3bcd, | ||
| 118 | 0xbc6a12ad8734b982, 0x3feea012750bdabf, | ||
| 119 | 0xbc6367efb86da9ee, 0x3fee9fb23c651a2f, | ||
| 120 | 0xbc80dc3d54e08851, 0x3fee9f7df9519484, | ||
| 121 | 0xbc781f647e5a3ecf, 0x3fee9f75e8ec5f74, | ||
| 122 | 0xbc86ee4ac08b7db0, 0x3fee9f9a48a58174, | ||
| 123 | 0xbc8619321e55e68a, 0x3fee9feb564267c9, | ||
| 124 | 0x3c909ccb5e09d4d3, 0x3feea0694fde5d3f, | ||
| 125 | 0xbc7b32dcb94da51d, 0x3feea11473eb0187, | ||
| 126 | 0x3c94ecfd5467c06b, 0x3feea1ed0130c132, | ||
| 127 | 0x3c65ebe1abd66c55, 0x3feea2f336cf4e62, | ||
| 128 | 0xbc88a1c52fb3cf42, 0x3feea427543e1a12, | ||
| 129 | 0xbc9369b6f13b3734, 0x3feea589994cce13, | ||
| 130 | 0xbc805e843a19ff1e, 0x3feea71a4623c7ad, | ||
| 131 | 0xbc94d450d872576e, 0x3feea8d99b4492ed, | ||
| 132 | 0x3c90ad675b0e8a00, 0x3feeaac7d98a6699, | ||
| 133 | 0x3c8db72fc1f0eab4, 0x3feeace5422aa0db, | ||
| 134 | 0xbc65b6609cc5e7ff, 0x3feeaf3216b5448c, | ||
| 135 | 0x3c7bf68359f35f44, 0x3feeb1ae99157736, | ||
| 136 | 0xbc93091fa71e3d83, 0x3feeb45b0b91ffc6, | ||
| 137 | 0xbc5da9b88b6c1e29, 0x3feeb737b0cdc5e5, | ||
| 138 | 0xbc6c23f97c90b959, 0x3feeba44cbc8520f, | ||
| 139 | 0xbc92434322f4f9aa, 0x3feebd829fde4e50, | ||
| 140 | 0xbc85ca6cd7668e4b, 0x3feec0f170ca07ba, | ||
| 141 | 0x3c71affc2b91ce27, 0x3feec49182a3f090, | ||
| 142 | 0x3c6dd235e10a73bb, 0x3feec86319e32323, | ||
| 143 | 0xbc87c50422622263, 0x3feecc667b5de565, | ||
| 144 | 0x3c8b1c86e3e231d5, 0x3feed09bec4a2d33, | ||
| 145 | 0xbc91bbd1d3bcbb15, 0x3feed503b23e255d, | ||
| 146 | 0x3c90cc319cee31d2, 0x3feed99e1330b358, | ||
| 147 | 0x3c8469846e735ab3, 0x3feede6b5579fdbf, | ||
| 148 | 0xbc82dfcd978e9db4, 0x3feee36bbfd3f37a, | ||
| 149 | 0x3c8c1a7792cb3387, 0x3feee89f995ad3ad, | ||
| 150 | 0xbc907b8f4ad1d9fa, 0x3feeee07298db666, | ||
| 151 | 0xbc55c3d956dcaeba, 0x3feef3a2b84f15fb, | ||
| 152 | 0xbc90a40e3da6f640, 0x3feef9728de5593a, | ||
| 153 | 0xbc68d6f438ad9334, 0x3feeff76f2fb5e47, | ||
| 154 | 0xbc91eee26b588a35, 0x3fef05b030a1064a, | ||
| 155 | 0x3c74ffd70a5fddcd, 0x3fef0c1e904bc1d2, | ||
| 156 | 0xbc91bdfbfa9298ac, 0x3fef12c25bd71e09, | ||
| 157 | 0x3c736eae30af0cb3, 0x3fef199bdd85529c, | ||
| 158 | 0x3c8ee3325c9ffd94, 0x3fef20ab5fffd07a, | ||
| 159 | 0x3c84e08fd10959ac, 0x3fef27f12e57d14b, | ||
| 160 | 0x3c63cdaf384e1a67, 0x3fef2f6d9406e7b5, | ||
| 161 | 0x3c676b2c6c921968, 0x3fef3720dcef9069, | ||
| 162 | 0xbc808a1883ccb5d2, 0x3fef3f0b555dc3fa, | ||
| 163 | 0xbc8fad5d3ffffa6f, 0x3fef472d4a07897c, | ||
| 164 | 0xbc900dae3875a949, 0x3fef4f87080d89f2, | ||
| 165 | 0x3c74a385a63d07a7, 0x3fef5818dcfba487, | ||
| 166 | 0xbc82919e2040220f, 0x3fef60e316c98398, | ||
| 167 | 0x3c8e5a50d5c192ac, 0x3fef69e603db3285, | ||
| 168 | 0x3c843a59ac016b4b, 0x3fef7321f301b460, | ||
| 169 | 0xbc82d52107b43e1f, 0x3fef7c97337b9b5f, | ||
| 170 | 0xbc892ab93b470dc9, 0x3fef864614f5a129, | ||
| 171 | 0x3c74b604603a88d3, 0x3fef902ee78b3ff6, | ||
| 172 | 0x3c83c5ec519d7271, 0x3fef9a51fbc74c83, | ||
| 173 | 0xbc8ff7128fd391f0, 0x3fefa4afa2a490da, | ||
| 174 | 0xbc8dae98e223747d, 0x3fefaf482d8e67f1, | ||
| 175 | 0x3c8ec3bc41aa2008, 0x3fefba1bee615a27, | ||
| 176 | 0x3c842b94c3a9eb32, 0x3fefc52b376bba97, | ||
| 177 | 0x3c8a64a931d185ee, 0x3fefd0765b6e4540, | ||
| 178 | 0xbc8e37bae43be3ed, 0x3fefdbfdad9cbe14, | ||
| 179 | 0x3c77893b4d91cd9d, 0x3fefe7c1819e90d8, | ||
| 180 | 0x3c5305c14160cc89, 0x3feff3c22b8f71f1, | ||
| 181 | }, | ||
| 182 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/exp_data.h created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _EXP_DATA_H | ||
| 6 | #define _EXP_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | |||
| 11 | #define EXP_TABLE_BITS 7 | ||
| 12 | #define EXP_POLY_ORDER 5 | ||
| 13 | #define EXP_USE_TOINT_NARROW 0 | ||
| 14 | #define EXP2_POLY_ORDER 5 | ||
| 15 | extern hidden const struct exp_data { | ||
| 16 | 	double invln2N; | ||
| 17 | 	double shift; | ||
| 18 | 	double negln2hiN; | ||
| 19 | 	double negln2loN; | ||
| 20 | 	double poly[4]; /* Last four coefficients. */ | ||
| 21 | 	double exp2_shift; | ||
| 22 | 	double exp2_poly[EXP2_POLY_ORDER]; | ||
| 23 | 	uint64_t tab[2*(1 << EXP_TABLE_BITS)]; | ||
| 24 | } __exp_data; | ||
| 25 | |||
| 26 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/expf.c created+80| ... | @@ -0,0 +1,80 @@ | ||
| 1 | /* | ||
| 2 | * Single-precision e^x function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "exp2f_data.h" | ||
| 12 | |||
| 13 | /* | ||
| 14 | EXP2F_TABLE_BITS = 5 | ||
| 15 | EXP2F_POLY_ORDER = 3 | ||
| 16 | |||
| 17 | ULP error: 0.502 (nearest rounding.) | ||
| 18 | Relative error: 1.69 * 2^-34 in [-ln2/64, ln2/64] (before rounding.) | ||
| 19 | Wrong count: 170635 (all nearest rounding wrong results with fma.) | ||
| 20 | Non-nearest ULP error: 1 (rounded ULP error) | ||
| 21 | */ | ||
| 22 | |||
| 23 | #define N (1 << EXP2F_TABLE_BITS) | ||
| 24 | #define InvLn2N __exp2f_data.invln2_scaled | ||
| 25 | #define T __exp2f_data.tab | ||
| 26 | #define C __exp2f_data.poly_scaled | ||
| 27 | |||
| 28 | static inline uint32_t top12(float x) | ||
| 29 | { | ||
| 30 | 	return asuint(x) >> 20; | ||
| 31 | } | ||
| 32 | |||
| 33 | float expf(float x) | ||
| 34 | { | ||
| 35 | 	uint32_t abstop; | ||
| 36 | 	uint64_t ki, t; | ||
| 37 | 	double_t kd, xd, z, r, r2, y, s; | ||
| 38 | |||
| 39 | 	xd = (double_t)x; | ||
| 40 | 	abstop = top12(x) & 0x7ff; | ||
| 41 | 	if (predict_false(abstop >= top12(88.0f))) { | ||
| 42 | 		/* |x| >= 88 or x is nan. */ | ||
| 43 | 		if (asuint(x) == asuint(-INFINITY)) | ||
| 44 | 			return 0.0f; | ||
| 45 | 		if (abstop >= top12(INFINITY)) | ||
| 46 | 			return x + x; | ||
| 47 | 		if (x > 0x1.62e42ep6f) /* x > log(0x1p128) ~= 88.72 */ | ||
| 48 | 			return __math_oflowf(0); | ||
| 49 | 		if (x < -0x1.9fe368p6f) /* x < log(0x1p-150) ~= -103.97 */ | ||
| 50 | 			return __math_uflowf(0); | ||
| 51 | 	} | ||
| 52 | |||
| 53 | 	/* x*N/Ln2 = k + r with r in [-1/2, 1/2] and int k. */ | ||
| 54 | 	z = InvLn2N * xd; | ||
| 55 | |||
| 56 | 	/* Round and convert z to int, the result is in [-150*N, 128*N] and | ||
| 57 | 	 ideally ties-to-even rule is used, otherwise the magnitude of r | ||
| 58 | 	 can be bigger which gives larger approximation error. */ | ||
| 59 | #if TOINT_INTRINSICS | ||
| 60 | 	kd = roundtoint(z); | ||
| 61 | 	ki = converttoint(z); | ||
| 62 | #else | ||
| 63 | # define SHIFT __exp2f_data.shift | ||
| 64 | 	kd = eval_as_double(z + SHIFT); | ||
| 65 | 	ki = asuint64(kd); | ||
| 66 | 	kd -= SHIFT; | ||
| 67 | #endif | ||
| 68 | 	r = z - kd; | ||
| 69 | |||
| 70 | 	/* exp(x) = 2^(k/N) * 2^(r/N) ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */ | ||
| 71 | 	t = T[ki % N]; | ||
| 72 | 	t += ki << (52 - EXP2F_TABLE_BITS); | ||
| 73 | 	s = asdouble(t); | ||
| 74 | 	z = C[0] * r + C[1]; | ||
| 75 | 	r2 = r * r; | ||
| 76 | 	y = C[2] * r + 1; | ||
| 77 | 	y = z * r2 + y; | ||
| 78 | 	y = y * s; | ||
| 79 | 	return eval_as_float(y); | ||
| 80 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/expl.c created+128| ... | @@ -0,0 +1,128 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_expl.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 | /* | ||
| 18 | * Exponential function, long double precision | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * long double x, y, expl(); | ||
| 24 | * | ||
| 25 | * y = expl( x ); | ||
| 26 | * | ||
| 27 | * | ||
| 28 | * DESCRIPTION: | ||
| 29 | * | ||
| 30 | * Returns e (2.71828...) raised to the x power. | ||
| 31 | * | ||
| 32 | * Range reduction is accomplished by separating the argument | ||
| 33 | * into an integer k and fraction f such that | ||
| 34 | * | ||
| 35 | * x k f | ||
| 36 | * e = 2 e. | ||
| 37 | * | ||
| 38 | * A Pade' form of degree 5/6 is used to approximate exp(f) - 1 | ||
| 39 | * in the basic range [-0.5 ln 2, 0.5 ln 2]. | ||
| 40 | * | ||
| 41 | * | ||
| 42 | * ACCURACY: | ||
| 43 | * | ||
| 44 | * Relative error: | ||
| 45 | * arithmetic domain # trials peak rms | ||
| 46 | * IEEE +-10000 50000 1.12e-19 2.81e-20 | ||
| 47 | * | ||
| 48 | * | ||
| 49 | * Error amplification in the exponential function can be | ||
| 50 | * a serious matter. The error propagation involves | ||
| 51 | * exp( X(1+delta) ) = exp(X) ( 1 + X*delta + ... ), | ||
| 52 | * which shows that a 1 lsb error in representing X produces | ||
| 53 | * a relative error of X times 1 lsb in the function. | ||
| 54 | * While the routine gives an accurate result for arguments | ||
| 55 | * that are exactly represented by a long double precision | ||
| 56 | * computer number, the result contains amplified roundoff | ||
| 57 | * error for large arguments not exactly represented. | ||
| 58 | * | ||
| 59 | * | ||
| 60 | * ERROR MESSAGES: | ||
| 61 | * | ||
| 62 | * message condition value returned | ||
| 63 | * exp underflow x < MINLOG 0.0 | ||
| 64 | * exp overflow x > MAXLOG MAXNUM | ||
| 65 | * | ||
| 66 | */ | ||
| 67 | |||
| 68 | #include "libm.h" | ||
| 69 | |||
| 70 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 71 | long double expl(long double x) | ||
| 72 | { | ||
| 73 | 	return exp(x); | ||
| 74 | } | ||
| 75 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 76 | |||
| 77 | static const long double P[3] = { | ||
| 78 | 1.2617719307481059087798E-4L, | ||
| 79 | 3.0299440770744196129956E-2L, | ||
| 80 | 9.9999999999999999991025E-1L, | ||
| 81 | }; | ||
| 82 | static const long double Q[4] = { | ||
| 83 | 3.0019850513866445504159E-6L, | ||
| 84 | 2.5244834034968410419224E-3L, | ||
| 85 | 2.2726554820815502876593E-1L, | ||
| 86 | 2.0000000000000000000897E0L, | ||
| 87 | }; | ||
| 88 | static const long double | ||
| 89 | LN2HI = 6.9314575195312500000000E-1L, | ||
| 90 | LN2LO = 1.4286068203094172321215E-6L, | ||
| 91 | LOG2E = 1.4426950408889634073599E0L; | ||
| 92 | |||
| 93 | long double expl(long double x) | ||
| 94 | { | ||
| 95 | 	long double px, xx; | ||
| 96 | 	int k; | ||
| 97 | |||
| 98 | 	if (isnan(x)) | ||
| 99 | 		return x; | ||
| 100 | 	if (x > 11356.5234062941439488L) /* x > ln(2^16384 - 0.5) */ | ||
| 101 | 		return x * 0x1p16383L; | ||
| 102 | 	if (x < -11399.4985314888605581L) /* x < ln(2^-16446) */ | ||
| 103 | 		return -0x1p-16445L/x; | ||
| 104 | |||
| 105 | 	/* Express e**x = e**f 2**k | ||
| 106 | 	 * = e**(f + k ln(2)) | ||
| 107 | 	 */ | ||
| 108 | 	px = floorl(LOG2E * x + 0.5); | ||
| 109 | 	k = px; | ||
| 110 | 	x -= px * LN2HI; | ||
| 111 | 	x -= px * LN2LO; | ||
| 112 | |||
| 113 | 	/* rational approximation of the fractional part: | ||
| 114 | 	 * e**x = 1 + 2x P(x**2)/(Q(x**2) - x P(x**2)) | ||
| 115 | 	 */ | ||
| 116 | 	xx = x * x; | ||
| 117 | 	px = x * __polevll(xx, P, 2); | ||
| 118 | 	x = px/(__polevll(xx, Q, 3) - px); | ||
| 119 | 	x = 1.0 + 2.0 * x; | ||
| 120 | 	return scalbnl(x, k); | ||
| 121 | } | ||
| 122 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 123 | // TODO: broken implementation to make things compile | ||
| 124 | long double expl(long double x) | ||
| 125 | { | ||
| 126 | 	return exp(x); | ||
| 127 | } | ||
| 128 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/expm1.c created+201| ... | @@ -0,0 +1,201 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_expm1.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* expm1(x) | ||
| 13 | * Returns exp(x)-1, the exponential of x minus 1. | ||
| 14 | * | ||
| 15 | * Method | ||
| 16 | * 1. Argument reduction: | ||
| 17 | * Given x, find r and integer k such that | ||
| 18 | * | ||
| 19 | * x = k*ln2 + r, |r| <= 0.5*ln2 ~ 0.34658 | ||
| 20 | * | ||
| 21 | * Here a correction term c will be computed to compensate | ||
| 22 | * the error in r when rounded to a floating-point number. | ||
| 23 | * | ||
| 24 | * 2. Approximating expm1(r) by a special rational function on | ||
| 25 | * the interval [0,0.34658]: | ||
| 26 | * Since | ||
| 27 | * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 - r^4/360 + ... | ||
| 28 | * we define R1(r*r) by | ||
| 29 | * r*(exp(r)+1)/(exp(r)-1) = 2+ r^2/6 * R1(r*r) | ||
| 30 | * That is, | ||
| 31 | * R1(r**2) = 6/r *((exp(r)+1)/(exp(r)-1) - 2/r) | ||
| 32 | * = 6/r * ( 1 + 2.0*(1/(exp(r)-1) - 1/r)) | ||
| 33 | * = 1 - r^2/60 + r^4/2520 - r^6/100800 + ... | ||
| 34 | * We use a special Remez algorithm on [0,0.347] to generate | ||
| 35 | * a polynomial of degree 5 in r*r to approximate R1. The | ||
| 36 | * maximum error of this polynomial approximation is bounded | ||
| 37 | * by 2**-61. In other words, | ||
| 38 | * R1(z) ~ 1.0 + Q1*z + Q2*z**2 + Q3*z**3 + Q4*z**4 + Q5*z**5 | ||
| 39 | * where Q1 = -1.6666666666666567384E-2, | ||
| 40 | * Q2 = 3.9682539681370365873E-4, | ||
| 41 | * Q3 = -9.9206344733435987357E-6, | ||
| 42 | * Q4 = 2.5051361420808517002E-7, | ||
| 43 | * Q5 = -6.2843505682382617102E-9; | ||
| 44 | * z = r*r, | ||
| 45 | * with error bounded by | ||
| 46 | * | 5 | -61 | ||
| 47 | * | 1.0+Q1*z+...+Q5*z - R1(z) | <= 2 | ||
| 48 | * | | | ||
| 49 | * | ||
| 50 | * expm1(r) = exp(r)-1 is then computed by the following | ||
| 51 | * specific way which minimize the accumulation rounding error: | ||
| 52 | * 2 3 | ||
| 53 | * r r [ 3 - (R1 + R1*r/2) ] | ||
| 54 | * expm1(r) = r + --- + --- * [--------------------] | ||
| 55 | * 2 2 [ 6 - r*(3 - R1*r/2) ] | ||
| 56 | * | ||
| 57 | * To compensate the error in the argument reduction, we use | ||
| 58 | * expm1(r+c) = expm1(r) + c + expm1(r)*c | ||
| 59 | * ~ expm1(r) + c + r*c | ||
| 60 | * Thus c+r*c will be added in as the correction terms for | ||
| 61 | * expm1(r+c). Now rearrange the term to avoid optimization | ||
| 62 | * screw up: | ||
| 63 | * ( 2 2 ) | ||
| 64 | * ({ ( r [ R1 - (3 - R1*r/2) ] ) } r ) | ||
| 65 | * expm1(r+c)~r - ({r*(--- * [--------------------]-c)-c} - --- ) | ||
| 66 | * ({ ( 2 [ 6 - r*(3 - R1*r/2) ] ) } 2 ) | ||
| 67 | * ( ) | ||
| 68 | * | ||
| 69 | * = r - E | ||
| 70 | * 3. Scale back to obtain expm1(x): | ||
| 71 | * From step 1, we have | ||
| 72 | * expm1(x) = either 2^k*[expm1(r)+1] - 1 | ||
| 73 | * = or 2^k*[expm1(r) + (1-2^-k)] | ||
| 74 | * 4. Implementation notes: | ||
| 75 | * (A). To save one multiplication, we scale the coefficient Qi | ||
| 76 | * to Qi*2^i, and replace z by (x^2)/2. | ||
| 77 | * (B). To achieve maximum accuracy, we compute expm1(x) by | ||
| 78 | * (i) if x < -56*ln2, return -1.0, (raise inexact if x!=inf) | ||
| 79 | * (ii) if k=0, return r-E | ||
| 80 | * (iii) if k=-1, return 0.5*(r-E)-0.5 | ||
| 81 | * (iv) if k=1 if r < -0.25, return 2*((r+0.5)- E) | ||
| 82 | * else return 1.0+2.0*(r-E); | ||
| 83 | * (v) if (k<-2||k>56) return 2^k(1-(E-r)) - 1 (or exp(x)-1) | ||
| 84 | * (vi) if k <= 20, return 2^k((1-2^-k)-(E-r)), else | ||
| 85 | * (vii) return 2^k(1-((E+2^-k)-r)) | ||
| 86 | * | ||
| 87 | * Special cases: | ||
| 88 | * expm1(INF) is INF, expm1(NaN) is NaN; | ||
| 89 | * expm1(-INF) is -1, and | ||
| 90 | * for finite argument, only expm1(0)=0 is exact. | ||
| 91 | * | ||
| 92 | * Accuracy: | ||
| 93 | * according to an error analysis, the error is always less than | ||
| 94 | * 1 ulp (unit in the last place). | ||
| 95 | * | ||
| 96 | * Misc. info. | ||
| 97 | * For IEEE double | ||
| 98 | * if x > 7.09782712893383973096e+02 then expm1(x) overflow | ||
| 99 | * | ||
| 100 | * Constants: | ||
| 101 | * The hexadecimal values are the intended ones for the following | ||
| 102 | * constants. The decimal values may be used, provided that the | ||
| 103 | * compiler will convert from decimal to binary accurately enough | ||
| 104 | * to produce the hexadecimal values shown. | ||
| 105 | */ | ||
| 106 | |||
| 107 | #include "libm.h" | ||
| 108 | |||
| 109 | static const double | ||
| 110 | o_threshold = 7.09782712893383973096e+02, /* 0x40862E42, 0xFEFA39EF */ | ||
| 111 | ln2_hi = 6.93147180369123816490e-01, /* 0x3fe62e42, 0xfee00000 */ | ||
| 112 | ln2_lo = 1.90821492927058770002e-10, /* 0x3dea39ef, 0x35793c76 */ | ||
| 113 | invln2 = 1.44269504088896338700e+00, /* 0x3ff71547, 0x652b82fe */ | ||
| 114 | /* Scaled Q's: Qn_here = 2**n * Qn_above, for R(2*z) where z = hxs = x*x/2: */ | ||
| 115 | Q1 = -3.33333333333331316428e-02, /* BFA11111 111110F4 */ | ||
| 116 | Q2 = 1.58730158725481460165e-03, /* 3F5A01A0 19FE5585 */ | ||
| 117 | Q3 = -7.93650757867487942473e-05, /* BF14CE19 9EAADBB7 */ | ||
| 118 | Q4 = 4.00821782732936239552e-06, /* 3ED0CFCA 86E65239 */ | ||
| 119 | Q5 = -2.01099218183624371326e-07; /* BE8AFDB7 6E09C32D */ | ||
| 120 | |||
| 121 | double expm1(double x) | ||
| 122 | { | ||
| 123 | 	double_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk; | ||
| 124 | 	union {double f; uint64_t i;} u = {x}; | ||
| 125 | 	uint32_t hx = u.i>>32 & 0x7fffffff; | ||
| 126 | 	int k, sign = u.i>>63; | ||
| 127 | |||
| 128 | 	/* filter out huge and non-finite argument */ | ||
| 129 | 	if (hx >= 0x4043687A) { /* if |x|>=56*ln2 */ | ||
| 130 | 		if (isnan(x)) | ||
| 131 | 			return x; | ||
| 132 | 		if (sign) | ||
| 133 | 			return -1; | ||
| 134 | 		if (x > o_threshold) { | ||
| 135 | 			x *= 0x1p1023; | ||
| 136 | 			return x; | ||
| 137 | 		} | ||
| 138 | 	} | ||
| 139 | |||
| 140 | 	/* argument reduction */ | ||
| 141 | 	if (hx > 0x3fd62e42) { /* if |x| > 0.5 ln2 */ | ||
| 142 | 		if (hx < 0x3FF0A2B2) { /* and |x| < 1.5 ln2 */ | ||
| 143 | 			if (!sign) { | ||
| 144 | 				hi = x - ln2_hi; | ||
| 145 | 				lo = ln2_lo; | ||
| 146 | 				k = 1; | ||
| 147 | 			} else { | ||
| 148 | 				hi = x + ln2_hi; | ||
| 149 | 				lo = -ln2_lo; | ||
| 150 | 				k = -1; | ||
| 151 | 			} | ||
| 152 | 		} else { | ||
| 153 | 			k = invln2*x + (sign ? -0.5 : 0.5); | ||
| 154 | 			t = k; | ||
| 155 | 			hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ | ||
| 156 | 			lo = t*ln2_lo; | ||
| 157 | 		} | ||
| 158 | 		x = hi-lo; | ||
| 159 | 		c = (hi-x)-lo; | ||
| 160 | 	} else if (hx < 0x3c900000) { /* |x| < 2**-54, return x */ | ||
| 161 | 		if (hx < 0x00100000) | ||
| 162 | 			FORCE_EVAL((float)x); | ||
| 163 | 		return x; | ||
| 164 | 	} else | ||
| 165 | 		k = 0; | ||
| 166 | |||
| 167 | 	/* x is now in primary range */ | ||
| 168 | 	hfx = 0.5*x; | ||
| 169 | 	hxs = x*hfx; | ||
| 170 | 	r1 = 1.0+hxs*(Q1+hxs*(Q2+hxs*(Q3+hxs*(Q4+hxs*Q5)))); | ||
| 171 | 	t = 3.0-r1*hfx; | ||
| 172 | 	e = hxs*((r1-t)/(6.0 - x*t)); | ||
| 173 | 	if (k == 0) /* c is 0 */ | ||
| 174 | 		return x - (x*e-hxs); | ||
| 175 | 	e = x*(e-c) - c; | ||
| 176 | 	e -= hxs; | ||
| 177 | 	/* exp(x) ~ 2^k (x_reduced - e + 1) */ | ||
| 178 | 	if (k == -1) | ||
| 179 | 		return 0.5*(x-e) - 0.5; | ||
| 180 | 	if (k == 1) { | ||
| 181 | 		if (x < -0.25) | ||
| 182 | 			return -2.0*(e-(x+0.5)); | ||
| 183 | 		return 1.0+2.0*(x-e); | ||
| 184 | 	} | ||
| 185 | 	u.i = (uint64_t)(0x3ff + k)<<52; /* 2^k */ | ||
| 186 | 	twopk = u.f; | ||
| 187 | 	if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */ | ||
| 188 | 		y = x - e + 1.0; | ||
| 189 | 		if (k == 1024) | ||
| 190 | 			y = y*2.0*0x1p1023; | ||
| 191 | 		else | ||
| 192 | 			y = y*twopk; | ||
| 193 | 		return y - 1.0; | ||
| 194 | 	} | ||
| 195 | 	u.i = (uint64_t)(0x3ff - k)<<52; /* 2^-k */ | ||
| 196 | 	if (k < 20) | ||
| 197 | 		y = (x-e+(1-u.f))*twopk; | ||
| 198 | 	else | ||
| 199 | 		y = (x-(e+u.f)+1)*twopk; | ||
| 200 | 	return y; | ||
| 201 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/expm1f.c created+111| ... | @@ -0,0 +1,111 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_expm1f.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | static const float | ||
| 19 | o_threshold = 8.8721679688e+01, /* 0x42b17180 */ | ||
| 20 | ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ | ||
| 21 | ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ | ||
| 22 | invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */ | ||
| 23 | /* | ||
| 24 | * Domain [-0.34568, 0.34568], range ~[-6.694e-10, 6.696e-10]: | ||
| 25 | * |6 / x * (1 + 2 * (1 / (exp(x) - 1) - 1 / x)) - q(x)| < 2**-30.04 | ||
| 26 | * Scaled coefficients: Qn_here = 2**n * Qn_for_q (see s_expm1.c): | ||
| 27 | */ | ||
| 28 | Q1 = -3.3333212137e-2, /* -0x888868.0p-28 */ | ||
| 29 | Q2 = 1.5807170421e-3; /* 0xcf3010.0p-33 */ | ||
| 30 | |||
| 31 | float expm1f(float x) | ||
| 32 | { | ||
| 33 | 	float_t y,hi,lo,c,t,e,hxs,hfx,r1,twopk; | ||
| 34 | 	union {float f; uint32_t i;} u = {x}; | ||
| 35 | 	uint32_t hx = u.i & 0x7fffffff; | ||
| 36 | 	int k, sign = u.i >> 31; | ||
| 37 | |||
| 38 | 	/* filter out huge and non-finite argument */ | ||
| 39 | 	if (hx >= 0x4195b844) { /* if |x|>=27*ln2 */ | ||
| 40 | 		if (hx > 0x7f800000) /* NaN */ | ||
| 41 | 			return x; | ||
| 42 | 		if (sign) | ||
| 43 | 			return -1; | ||
| 44 | 		if (x > o_threshold) { | ||
| 45 | 			x *= 0x1p127f; | ||
| 46 | 			return x; | ||
| 47 | 		} | ||
| 48 | 	} | ||
| 49 | |||
| 50 | 	/* argument reduction */ | ||
| 51 | 	if (hx > 0x3eb17218) { /* if |x| > 0.5 ln2 */ | ||
| 52 | 		if (hx < 0x3F851592) { /* and |x| < 1.5 ln2 */ | ||
| 53 | 			if (!sign) { | ||
| 54 | 				hi = x - ln2_hi; | ||
| 55 | 				lo = ln2_lo; | ||
| 56 | 				k = 1; | ||
| 57 | 			} else { | ||
| 58 | 				hi = x + ln2_hi; | ||
| 59 | 				lo = -ln2_lo; | ||
| 60 | 				k = -1; | ||
| 61 | 			} | ||
| 62 | 		} else { | ||
| 63 | 			k = invln2*x + (sign ? -0.5f : 0.5f); | ||
| 64 | 			t = k; | ||
| 65 | 			hi = x - t*ln2_hi; /* t*ln2_hi is exact here */ | ||
| 66 | 			lo = t*ln2_lo; | ||
| 67 | 		} | ||
| 68 | 		x = hi-lo; | ||
| 69 | 		c = (hi-x)-lo; | ||
| 70 | 	} else if (hx < 0x33000000) { /* when |x|<2**-25, return x */ | ||
| 71 | 		if (hx < 0x00800000) | ||
| 72 | 			FORCE_EVAL(x*x); | ||
| 73 | 		return x; | ||
| 74 | 	} else | ||
| 75 | 		k = 0; | ||
| 76 | |||
| 77 | 	/* x is now in primary range */ | ||
| 78 | 	hfx = 0.5f*x; | ||
| 79 | 	hxs = x*hfx; | ||
| 80 | 	r1 = 1.0f+hxs*(Q1+hxs*Q2); | ||
| 81 | 	t = 3.0f - r1*hfx; | ||
| 82 | 	e = hxs*((r1-t)/(6.0f - x*t)); | ||
| 83 | 	if (k == 0) /* c is 0 */ | ||
| 84 | 		return x - (x*e-hxs); | ||
| 85 | 	e = x*(e-c) - c; | ||
| 86 | 	e -= hxs; | ||
| 87 | 	/* exp(x) ~ 2^k (x_reduced - e + 1) */ | ||
| 88 | 	if (k == -1) | ||
| 89 | 		return 0.5f*(x-e) - 0.5f; | ||
| 90 | 	if (k == 1) { | ||
| 91 | 		if (x < -0.25f) | ||
| 92 | 			return -2.0f*(e-(x+0.5f)); | ||
| 93 | 		return 1.0f + 2.0f*(x-e); | ||
| 94 | 	} | ||
| 95 | 	u.i = (0x7f+k)<<23; /* 2^k */ | ||
| 96 | 	twopk = u.f; | ||
| 97 | 	if (k < 0 || k > 56) { /* suffice to return exp(x)-1 */ | ||
| 98 | 		y = x - e + 1.0f; | ||
| 99 | 		if (k == 128) | ||
| 100 | 			y = y*2.0f*0x1p127f; | ||
| 101 | 		else | ||
| 102 | 			y = y*twopk; | ||
| 103 | 		return y - 1.0f; | ||
| 104 | 	} | ||
| 105 | 	u.i = (0x7f-k)<<23; /* 2^-k */ | ||
| 106 | 	if (k < 23) | ||
| 107 | 		y = (x-e+(1-u.f))*twopk; | ||
| 108 | 	else | ||
| 109 | 		y = (x-(e+u.f)+1)*twopk; | ||
| 110 | 	return y; | ||
| 111 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/expm1l.c created+123| ... | @@ -0,0 +1,123 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_expm1l.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 | /* | ||
| 18 | * Exponential function, minus 1 | ||
| 19 | * Long double precision | ||
| 20 | * | ||
| 21 | * | ||
| 22 | * SYNOPSIS: | ||
| 23 | * | ||
| 24 | * long double x, y, expm1l(); | ||
| 25 | * | ||
| 26 | * y = expm1l( x ); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * Returns e (2.71828...) raised to the x power, minus 1. | ||
| 32 | * | ||
| 33 | * Range reduction is accomplished by separating the argument | ||
| 34 | * into an integer k and fraction f such that | ||
| 35 | * | ||
| 36 | * x k f | ||
| 37 | * e = 2 e. | ||
| 38 | * | ||
| 39 | * An expansion x + .5 x^2 + x^3 R(x) approximates exp(f) - 1 | ||
| 40 | * in the basic range [-0.5 ln 2, 0.5 ln 2]. | ||
| 41 | * | ||
| 42 | * | ||
| 43 | * ACCURACY: | ||
| 44 | * | ||
| 45 | * Relative error: | ||
| 46 | * arithmetic domain # trials peak rms | ||
| 47 | * IEEE -45,+maxarg 200,000 1.2e-19 2.5e-20 | ||
| 48 | */ | ||
| 49 | |||
| 50 | #include "libm.h" | ||
| 51 | |||
| 52 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 53 | long double expm1l(long double x) | ||
| 54 | { | ||
| 55 | 	return expm1(x); | ||
| 56 | } | ||
| 57 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 58 | |||
| 59 | /* exp(x) - 1 = x + 0.5 x^2 + x^3 P(x)/Q(x) | ||
| 60 | -.5 ln 2 < x < .5 ln 2 | ||
| 61 | Theoretical peak relative error = 3.4e-22 */ | ||
| 62 | static const long double | ||
| 63 | P0 = -1.586135578666346600772998894928250240826E4L, | ||
| 64 | P1 = 2.642771505685952966904660652518429479531E3L, | ||
| 65 | P2 = -3.423199068835684263987132888286791620673E2L, | ||
| 66 | P3 = 1.800826371455042224581246202420972737840E1L, | ||
| 67 | P4 = -5.238523121205561042771939008061958820811E-1L, | ||
| 68 | Q0 = -9.516813471998079611319047060563358064497E4L, | ||
| 69 | Q1 = 3.964866271411091674556850458227710004570E4L, | ||
| 70 | Q2 = -7.207678383830091850230366618190187434796E3L, | ||
| 71 | Q3 = 7.206038318724600171970199625081491823079E2L, | ||
| 72 | Q4 = -4.002027679107076077238836622982900945173E1L, | ||
| 73 | /* Q5 = 1.000000000000000000000000000000000000000E0 */ | ||
| 74 | /* C1 + C2 = ln 2 */ | ||
| 75 | C1 = 6.93145751953125E-1L, | ||
| 76 | C2 = 1.428606820309417232121458176568075500134E-6L, | ||
| 77 | /* ln 2^-65 */ | ||
| 78 | minarg = -4.5054566736396445112120088E1L, | ||
| 79 | /* ln 2^16384 */ | ||
| 80 | maxarg = 1.1356523406294143949492E4L; | ||
| 81 | |||
| 82 | long double expm1l(long double x) | ||
| 83 | { | ||
| 84 | 	long double px, qx, xx; | ||
| 85 | 	int k; | ||
| 86 | |||
| 87 | 	if (isnan(x)) | ||
| 88 | 		return x; | ||
| 89 | 	if (x > maxarg) | ||
| 90 | 		return x*0x1p16383L; /* overflow, unless x==inf */ | ||
| 91 | 	if (x == 0.0) | ||
| 92 | 		return x; | ||
| 93 | 	if (x < minarg) | ||
| 94 | 		return -1.0; | ||
| 95 | |||
| 96 | 	xx = C1 + C2; | ||
| 97 | 	/* Express x = ln 2 (k + remainder), remainder not exceeding 1/2. */ | ||
| 98 | 	px = floorl(0.5 + x / xx); | ||
| 99 | 	k = px; | ||
| 100 | 	/* remainder times ln 2 */ | ||
| 101 | 	x -= px * C1; | ||
| 102 | 	x -= px * C2; | ||
| 103 | |||
| 104 | 	/* Approximate exp(remainder ln 2).*/ | ||
| 105 | 	px = (((( P4 * x + P3) * x + P2) * x + P1) * x + P0) * x; | ||
| 106 | 	qx = (((( x + Q4) * x + Q3) * x + Q2) * x + Q1) * x + Q0; | ||
| 107 | 	xx = x * x; | ||
| 108 | 	qx = x + (0.5 * xx + xx * px / qx); | ||
| 109 | |||
| 110 | 	/* exp(x) = exp(k ln 2) exp(remainder ln 2) = 2^k exp(remainder ln 2). | ||
| 111 | 	 We have qx = exp(remainder ln 2) - 1, so | ||
| 112 | 	 exp(x) - 1 = 2^k (qx + 1) - 1 = 2^k qx + 2^k - 1. */ | ||
| 113 | 	px = scalbnl(1.0, k); | ||
| 114 | 	x = px * qx + (px - 1.0); | ||
| 115 | 	return x; | ||
| 116 | } | ||
| 117 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 118 | // TODO: broken implementation to make things compile | ||
| 119 | long double expm1l(long double x) | ||
| 120 | { | ||
| 121 | 	return expm1(x); | ||
| 122 | } | ||
| 123 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/fabs.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | double fabs(double x) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} u = {x}; | ||
| 7 | 	u.i &= -1ULL/2; | ||
| 8 | 	return u.f; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fabsf.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float fabsf(float x) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} u = {x}; | ||
| 7 | 	u.i &= 0x7fffffff; | ||
| 8 | 	return u.f; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fabsl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 3 | long double fabsl(long double x) | ||
| 4 | { | ||
| 5 | 	return fabs(x); | ||
| 6 | } | ||
| 7 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 8 | long double fabsl(long double x) | ||
| 9 | { | ||
| 10 | 	union ldshape u = {x}; | ||
| 11 | |||
| 12 | 	u.i.se &= 0x7fff; | ||
| 13 | 	return u.f; | ||
| 14 | } | ||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/fdim.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fdim(double x, double y) | ||
| 4 | { | ||
| 5 | 	if (isnan(x)) | ||
| 6 | 		return x; | ||
| 7 | 	if (isnan(y)) | ||
| 8 | 		return y; | ||
| 9 | 	return x > y ? x - y : 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fdimf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fdimf(float x, float y) | ||
| 4 | { | ||
| 5 | 	if (isnan(x)) | ||
| 6 | 		return x; | ||
| 7 | 	if (isnan(y)) | ||
| 8 | 		return y; | ||
| 9 | 	return x > y ? x - y : 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fdiml.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <float.h> | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | long double fdiml(long double x, long double y) | ||
| 6 | { | ||
| 7 | 	return fdim(x, y); | ||
| 8 | } | ||
| 9 | #else | ||
| 10 | long double fdiml(long double x, long double y) | ||
| 11 | { | ||
| 12 | 	if (isnan(x)) | ||
| 13 | 		return x; | ||
| 14 | 	if (isnan(y)) | ||
| 15 | 		return y; | ||
| 16 | 	return x > y ? x - y : 0; | ||
| 17 | } | ||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/finite.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | int finite(double x) | ||
| 5 | { | ||
| 6 | 	return isfinite(x); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/finitef.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | int finitef(float x) | ||
| 5 | { | ||
| 6 | 	return isfinite(x); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/floor.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 4 | #define EPS DBL_EPSILON | ||
| 5 | #elif FLT_EVAL_METHOD==2 | ||
| 6 | #define EPS LDBL_EPSILON | ||
| 7 | #endif | ||
| 8 | static const double_t toint = 1/EPS; | ||
| 9 | |||
| 10 | double floor(double x) | ||
| 11 | { | ||
| 12 | 	union {double f; uint64_t i;} u = {x}; | ||
| 13 | 	int e = u.i >> 52 & 0x7ff; | ||
| 14 | 	double_t y; | ||
| 15 | |||
| 16 | 	if (e >= 0x3ff+52 || x == 0) | ||
| 17 | 		return x; | ||
| 18 | 	/* y = int(x) - x, where int(x) is an integer neighbor of x */ | ||
| 19 | 	if (u.i >> 63) | ||
| 20 | 		y = x - toint + toint - x; | ||
| 21 | 	else | ||
| 22 | 		y = x + toint - toint - x; | ||
| 23 | 	/* special case because of non-nearest rounding modes */ | ||
| 24 | 	if (e <= 0x3ff-1) { | ||
| 25 | 		FORCE_EVAL(y); | ||
| 26 | 		return u.i >> 63 ? -1 : 0; | ||
| 27 | 	} | ||
| 28 | 	if (y > 0) | ||
| 29 | 		return x + y - 1; | ||
| 30 | 	return x + y; | ||
| 31 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/floorf.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float floorf(float x) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {x}; | ||
| 6 | 	int e = (int)(u.i >> 23 & 0xff) - 0x7f; | ||
| 7 | 	uint32_t m; | ||
| 8 | |||
| 9 | 	if (e >= 23) | ||
| 10 | 		return x; | ||
| 11 | 	if (e >= 0) { | ||
| 12 | 		m = 0x007fffff >> e; | ||
| 13 | 		if ((u.i & m) == 0) | ||
| 14 | 			return x; | ||
| 15 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 16 | 		if (u.i >> 31) | ||
| 17 | 			u.i += m; | ||
| 18 | 		u.i &= ~m; | ||
| 19 | 	} else { | ||
| 20 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 21 | 		if (u.i >> 31 == 0) | ||
| 22 | 			u.i = 0; | ||
| 23 | 		else if (u.i << 1) | ||
| 24 | 			u.f = -1.0; | ||
| 25 | 	} | ||
| 26 | 	return u.f; | ||
| 27 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/floorl.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double floorl(long double x) | ||
| 5 | { | ||
| 6 | 	return floor(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | |||
| 10 | static const long double toint = 1/LDBL_EPSILON; | ||
| 11 | |||
| 12 | long double floorl(long double x) | ||
| 13 | { | ||
| 14 | 	union ldshape u = {x}; | ||
| 15 | 	int e = u.i.se & 0x7fff; | ||
| 16 | 	long double y; | ||
| 17 | |||
| 18 | 	if (e >= 0x3fff+LDBL_MANT_DIG-1 || x == 0) | ||
| 19 | 		return x; | ||
| 20 | 	/* y = int(x) - x, where int(x) is an integer neighbor of x */ | ||
| 21 | 	if (u.i.se >> 15) | ||
| 22 | 		y = x - toint + toint - x; | ||
| 23 | 	else | ||
| 24 | 		y = x + toint - toint - x; | ||
| 25 | 	/* special case because of non-nearest rounding modes */ | ||
| 26 | 	if (e <= 0x3fff-1) { | ||
| 27 | 		FORCE_EVAL(y); | ||
| 28 | 		return u.i.se >> 15 ? -1 : 0; | ||
| 29 | 	} | ||
| 30 | 	if (y > 0) | ||
| 31 | 		return x + y - 1; | ||
| 32 | 	return x + y; | ||
| 33 | } | ||
| 34 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/fma.c created+183| ... | @@ -0,0 +1,183 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <float.h> | ||
| 3 | #include <math.h> | ||
| 4 | #include "atomic.h" | ||
| 5 | |||
| 6 | #define ASUINT64(x) ((union {double f; uint64_t i;}){x}).i | ||
| 7 | #define ZEROINFNAN (0x7ff-0x3ff-52-1) | ||
| 8 | |||
| 9 | struct num { uint64_t m; int e; int sign; }; | ||
| 10 | |||
| 11 | static struct num normalize(double x) | ||
| 12 | { | ||
| 13 | 	uint64_t ix = ASUINT64(x); | ||
| 14 | 	int e = ix>>52; | ||
| 15 | 	int sign = e & 0x800; | ||
| 16 | 	e &= 0x7ff; | ||
| 17 | 	if (!e) { | ||
| 18 | 		ix = ASUINT64(x*0x1p63); | ||
| 19 | 		e = ix>>52 & 0x7ff; | ||
| 20 | 		e = e ? e-63 : 0x800; | ||
| 21 | 	} | ||
| 22 | 	ix &= (1ull<<52)-1; | ||
| 23 | 	ix |= 1ull<<52; | ||
| 24 | 	ix <<= 1; | ||
| 25 | 	e -= 0x3ff + 52 + 1; | ||
| 26 | 	return (struct num){ix,e,sign}; | ||
| 27 | } | ||
| 28 | |||
| 29 | static void mul(uint64_t *hi, uint64_t *lo, uint64_t x, uint64_t y) | ||
| 30 | { | ||
| 31 | 	uint64_t t1,t2,t3; | ||
| 32 | 	uint64_t xlo = (uint32_t)x, xhi = x>>32; | ||
| 33 | 	uint64_t ylo = (uint32_t)y, yhi = y>>32; | ||
| 34 | |||
| 35 | 	t1 = xlo*ylo; | ||
| 36 | 	t2 = xlo*yhi + xhi*ylo; | ||
| 37 | 	t3 = xhi*yhi; | ||
| 38 | 	*lo = t1 + (t2<<32); | ||
| 39 | 	*hi = t3 + (t2>>32) + (t1 > *lo); | ||
| 40 | } | ||
| 41 | |||
| 42 | double fma(double x, double y, double z) | ||
| 43 | { | ||
| 44 | 	#pragma STDC FENV_ACCESS ON | ||
| 45 | |||
| 46 | 	/* normalize so top 10bits and last bit are 0 */ | ||
| 47 | 	struct num nx, ny, nz; | ||
| 48 | 	nx = normalize(x); | ||
| 49 | 	ny = normalize(y); | ||
| 50 | 	nz = normalize(z); | ||
| 51 | |||
| 52 | 	if (nx.e >= ZEROINFNAN || ny.e >= ZEROINFNAN) | ||
| 53 | 		return x*y + z; | ||
| 54 | 	if (nz.e >= ZEROINFNAN) { | ||
| 55 | 		if (nz.e > ZEROINFNAN) /* z==0 */ | ||
| 56 | 			return x*y + z; | ||
| 57 | 		return z; | ||
| 58 | 	} | ||
| 59 | |||
| 60 | 	/* mul: r = x*y */ | ||
| 61 | 	uint64_t rhi, rlo, zhi, zlo; | ||
| 62 | 	mul(&rhi, &rlo, nx.m, ny.m); | ||
| 63 | 	/* either top 20 or 21 bits of rhi and last 2 bits of rlo are 0 */ | ||
| 64 | |||
| 65 | 	/* align exponents */ | ||
| 66 | 	int e = nx.e + ny.e; | ||
| 67 | 	int d = nz.e - e; | ||
| 68 | 	/* shift bits z<<=kz, r>>=kr, so kz+kr == d, set e = e+kr (== ez-kz) */ | ||
| 69 | 	if (d > 0) { | ||
| 70 | 		if (d < 64) { | ||
| 71 | 			zlo = nz.m<<d; | ||
| 72 | 			zhi = nz.m>>64-d; | ||
| 73 | 		} else { | ||
| 74 | 			zlo = 0; | ||
| 75 | 			zhi = nz.m; | ||
| 76 | 			e = nz.e - 64; | ||
| 77 | 			d -= 64; | ||
| 78 | 			if (d == 0) { | ||
| 79 | 			} else if (d < 64) { | ||
| 80 | 				rlo = rhi<<64-d | rlo>>d | !!(rlo<<64-d); | ||
| 81 | 				rhi = rhi>>d; | ||
| 82 | 			} else { | ||
| 83 | 				rlo = 1; | ||
| 84 | 				rhi = 0; | ||
| 85 | 			} | ||
| 86 | 		} | ||
| 87 | 	} else { | ||
| 88 | 		zhi = 0; | ||
| 89 | 		d = -d; | ||
| 90 | 		if (d == 0) { | ||
| 91 | 			zlo = nz.m; | ||
| 92 | 		} else if (d < 64) { | ||
| 93 | 			zlo = nz.m>>d | !!(nz.m<<64-d); | ||
| 94 | 		} else { | ||
| 95 | 			zlo = 1; | ||
| 96 | 		} | ||
| 97 | 	} | ||
| 98 | |||
| 99 | 	/* add */ | ||
| 100 | 	int sign = nx.sign^ny.sign; | ||
| 101 | 	int samesign = !(sign^nz.sign); | ||
| 102 | 	int nonzero = 1; | ||
| 103 | 	if (samesign) { | ||
| 104 | 		/* r += z */ | ||
| 105 | 		rlo += zlo; | ||
| 106 | 		rhi += zhi + (rlo < zlo); | ||
| 107 | 	} else { | ||
| 108 | 		/* r -= z */ | ||
| 109 | 		uint64_t t = rlo; | ||
| 110 | 		rlo -= zlo; | ||
| 111 | 		rhi = rhi - zhi - (t < rlo); | ||
| 112 | 		if (rhi>>63) { | ||
| 113 | 			rlo = -rlo; | ||
| 114 | 			rhi = -rhi-!!rlo; | ||
| 115 | 			sign = !sign; | ||
| 116 | 		} | ||
| 117 | 		nonzero = !!rhi; | ||
| 118 | 	} | ||
| 119 | |||
| 120 | 	/* set rhi to top 63bit of the result (last bit is sticky) */ | ||
| 121 | 	if (nonzero) { | ||
| 122 | 		e += 64; | ||
| 123 | 		d = a_clz_64(rhi)-1; | ||
| 124 | 		/* note: d > 0 */ | ||
| 125 | 		rhi = rhi<<d | rlo>>64-d | !!(rlo<<d); | ||
| 126 | 	} else if (rlo) { | ||
| 127 | 		d = a_clz_64(rlo)-1; | ||
| 128 | 		if (d < 0) | ||
| 129 | 			rhi = rlo>>1 | (rlo&1); | ||
| 130 | 		else | ||
| 131 | 			rhi = rlo<<d; | ||
| 132 | 	} else { | ||
| 133 | 		/* exact +-0 */ | ||
| 134 | 		return x*y + z; | ||
| 135 | 	} | ||
| 136 | 	e -= d; | ||
| 137 | |||
| 138 | 	/* convert to double */ | ||
| 139 | 	int64_t i = rhi; /* i is in [1<<62,(1<<63)-1] */ | ||
| 140 | 	if (sign) | ||
| 141 | 		i = -i; | ||
| 142 | 	double r = i; /* |r| is in [0x1p62,0x1p63] */ | ||
| 143 | |||
| 144 | 	if (e < -1022-62) { | ||
| 145 | 		/* result is subnormal before rounding */ | ||
| 146 | 		if (e == -1022-63) { | ||
| 147 | 			double c = 0x1p63; | ||
| 148 | 			if (sign) | ||
| 149 | 				c = -c; | ||
| 150 | 			if (r == c) { | ||
| 151 | 				/* min normal after rounding, underflow depends | ||
| 152 | 				 on arch behaviour which can be imitated by | ||
| 153 | 				 a double to float conversion */ | ||
| 154 | 				float fltmin = 0x0.ffffff8p-63*FLT_MIN * r; | ||
| 155 | 				return DBL_MIN/FLT_MIN * fltmin; | ||
| 156 | 			} | ||
| 157 | 			/* one bit is lost when scaled, add another top bit to | ||
| 158 | 			 only round once at conversion if it is inexact */ | ||
| 159 | 			if (rhi << 53) { | ||
| 160 | 				i = rhi>>1 | (rhi&1) | 1ull<<62; | ||
| 161 | 				if (sign) | ||
| 162 | 					i = -i; | ||
| 163 | 				r = i; | ||
| 164 | 				r = 2*r - c; /* remove top bit */ | ||
| 165 | |||
| 166 | 				/* raise underflow portably, such that it | ||
| 167 | 				 cannot be optimized away */ | ||
| 168 | 				{ | ||
| 169 | 					double_t tiny = DBL_MIN/FLT_MIN * r; | ||
| 170 | 					r += (double)(tiny*tiny) * (r-r); | ||
| 171 | 				} | ||
| 172 | 			} | ||
| 173 | 		} else { | ||
| 174 | 			/* only round once when scaled */ | ||
| 175 | 			d = 10; | ||
| 176 | 			i = ( rhi>>d | !!(rhi<<64-d) ) << d; | ||
| 177 | 			if (sign) | ||
| 178 | 				i = -i; | ||
| 179 | 			r = i; | ||
| 180 | 		} | ||
| 181 | 	} | ||
| 182 | 	return scalbn(r, e); | ||
| 183 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmaf.c created+97| ... | @@ -0,0 +1,97 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_fmaf.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 | #include <fenv.h> | ||
| 29 | #include <math.h> | ||
| 30 | #include <stdint.h> | ||
| 31 | |||
| 32 | /* | ||
| 33 | * Fused multiply-add: Compute x * y + z with a single rounding error. | ||
| 34 | * | ||
| 35 | * A double has more than twice as much precision than a float, so | ||
| 36 | * direct double-precision arithmetic suffices, except where double | ||
| 37 | * rounding occurs. | ||
| 38 | */ | ||
| 39 | float fmaf(float x, float y, float z) | ||
| 40 | { | ||
| 41 | 	#pragma STDC FENV_ACCESS ON | ||
| 42 | 	double xy, result; | ||
| 43 | 	union {double f; uint64_t i;} u; | ||
| 44 | 	int e; | ||
| 45 | |||
| 46 | 	xy = (double)x * y; | ||
| 47 | 	result = xy + z; | ||
| 48 | 	u.f = result; | ||
| 49 | 	e = u.i>>52 & 0x7ff; | ||
| 50 | 	/* Common case: The double precision result is fine. */ | ||
| 51 | 	if ((u.i & 0x1fffffff) != 0x10000000 || /* not a halfway case */ | ||
| 52 | 		e == 0x7ff || /* NaN */ | ||
| 53 | 		(result - xy == z && result - z == xy) || /* exact */ | ||
| 54 | 		fegetround() != FE_TONEAREST) /* not round-to-nearest */ | ||
| 55 | 	{ | ||
| 56 | 		/* | ||
| 57 | 		underflow may not be raised correctly, example: | ||
| 58 | 		fmaf(0x1p-120f, 0x1p-120f, 0x1p-149f) | ||
| 59 | 		*/ | ||
| 60 | #if defined(FE_INEXACT) && defined(FE_UNDERFLOW) | ||
| 61 | 		if (e < 0x3ff-126 && e >= 0x3ff-149 && fetestexcept(FE_INEXACT)) { | ||
| 62 | 			feclearexcept(FE_INEXACT); | ||
| 63 | 			/* TODO: gcc and clang bug workaround */ | ||
| 64 | 			volatile float vz = z; | ||
| 65 | 			result = xy + vz; | ||
| 66 | 			if (fetestexcept(FE_INEXACT)) | ||
| 67 | 				feraiseexcept(FE_UNDERFLOW); | ||
| 68 | 			else | ||
| 69 | 				feraiseexcept(FE_INEXACT); | ||
| 70 | 		} | ||
| 71 | #endif | ||
| 72 | 		z = result; | ||
| 73 | 		return z; | ||
| 74 | 	} | ||
| 75 | |||
| 76 | 	/* | ||
| 77 | 	 * If result is inexact, and exactly halfway between two float values, | ||
| 78 | 	 * we need to adjust the low-order bit in the direction of the error. | ||
| 79 | 	 */ | ||
| 80 | #ifdef FE_TOWARDZERO | ||
| 81 | 	fesetround(FE_TOWARDZERO); | ||
| 82 | #endif | ||
| 83 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't need old GCC workarounds | ||
| 84 | 	volatile double vxy = xy; /* XXX work around gcc CSE bug */ | ||
| 85 | #else | ||
| 86 | 	double vxy = xy; | ||
| 87 | #endif | ||
| 88 | 	double adjusted_result = vxy + z; | ||
| 89 | 	fesetround(FE_TONEAREST); | ||
| 90 | 	if (result == adjusted_result) { | ||
| 91 | 		u.f = adjusted_result; | ||
| 92 | 		u.i++; | ||
| 93 | 		adjusted_result = u.f; | ||
| 94 | 	} | ||
| 95 | 	z = adjusted_result; | ||
| 96 | 	return z; | ||
| 97 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmal.c created+297| ... | @@ -0,0 +1,297 @@ | ||
| 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/fmax.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fmax(double x, double y) | ||
| 4 | { | ||
| 5 | 	if (isnan(x)) | ||
| 6 | 		return y; | ||
| 7 | 	if (isnan(y)) | ||
| 8 | 		return x; | ||
| 9 | 	/* handle signed zeros, see C99 Annex F.9.9.2 */ | ||
| 10 | 	if (signbit(x) != signbit(y)) | ||
| 11 | 		return signbit(x) ? y : x; | ||
| 12 | 	return x < y ? y : x; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmaxf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fmaxf(float x, float y) | ||
| 4 | { | ||
| 5 | 	if (isnan(x)) | ||
| 6 | 		return y; | ||
| 7 | 	if (isnan(y)) | ||
| 8 | 		return x; | ||
| 9 | 	/* handle signed zeroes, see C99 Annex F.9.9.2 */ | ||
| 10 | 	if (signbit(x) != signbit(y)) | ||
| 11 | 		return signbit(x) ? y : x; | ||
| 12 | 	return x < y ? y : x; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmaxl.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <float.h> | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | long double fmaxl(long double x, long double y) | ||
| 6 | { | ||
| 7 | 	return fmax(x, y); | ||
| 8 | } | ||
| 9 | #else | ||
| 10 | long double fmaxl(long double x, long double y) | ||
| 11 | { | ||
| 12 | 	if (isnan(x)) | ||
| 13 | 		return y; | ||
| 14 | 	if (isnan(y)) | ||
| 15 | 		return x; | ||
| 16 | 	/* handle signed zeros, see C99 Annex F.9.9.2 */ | ||
| 17 | 	if (signbit(x) != signbit(y)) | ||
| 18 | 		return signbit(x) ? y : x; | ||
| 19 | 	return x < y ? y : x; | ||
| 20 | } | ||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmin.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fmin(double x, double y) | ||
| 4 | { | ||
| 5 | 	if (isnan(x)) | ||
| 6 | 		return y; | ||
| 7 | 	if (isnan(y)) | ||
| 8 | 		return x; | ||
| 9 | 	/* handle signed zeros, see C99 Annex F.9.9.2 */ | ||
| 10 | 	if (signbit(x) != signbit(y)) | ||
| 11 | 		return signbit(x) ? x : y; | ||
| 12 | 	return x < y ? x : y; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fminf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fminf(float x, float y) | ||
| 4 | { | ||
| 5 | 	if (isnan(x)) | ||
| 6 | 		return y; | ||
| 7 | 	if (isnan(y)) | ||
| 8 | 		return x; | ||
| 9 | 	/* handle signed zeros, see C99 Annex F.9.9.2 */ | ||
| 10 | 	if (signbit(x) != signbit(y)) | ||
| 11 | 		return signbit(x) ? x : y; | ||
| 12 | 	return x < y ? x : y; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fminl.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <float.h> | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | long double fminl(long double x, long double y) | ||
| 6 | { | ||
| 7 | 	return fmin(x, y); | ||
| 8 | } | ||
| 9 | #else | ||
| 10 | long double fminl(long double x, long double y) | ||
| 11 | { | ||
| 12 | 	if (isnan(x)) | ||
| 13 | 		return y; | ||
| 14 | 	if (isnan(y)) | ||
| 15 | 		return x; | ||
| 16 | 	/* handle signed zeros, see C99 Annex F.9.9.2 */ | ||
| 17 | 	if (signbit(x) != signbit(y)) | ||
| 18 | 		return signbit(x) ? x : y; | ||
| 19 | 	return x < y ? x : y; | ||
| 20 | } | ||
| 21 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmod.c created+68| ... | @@ -0,0 +1,68 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | double fmod(double x, double y) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} ux = {x}, uy = {y}; | ||
| 7 | 	int ex = ux.i>>52 & 0x7ff; | ||
| 8 | 	int ey = uy.i>>52 & 0x7ff; | ||
| 9 | 	int sx = ux.i>>63; | ||
| 10 | 	uint64_t i; | ||
| 11 | |||
| 12 | 	/* in the followings uxi should be ux.i, but then gcc wrongly adds */ | ||
| 13 | 	/* float load/store to inner loops ruining performance and code size */ | ||
| 14 | 	uint64_t uxi = ux.i; | ||
| 15 | |||
| 16 | 	if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff) | ||
| 17 | 		return (x*y)/(x*y); | ||
| 18 | 	if (uxi<<1 <= uy.i<<1) { | ||
| 19 | 		if (uxi<<1 == uy.i<<1) | ||
| 20 | 			return 0*x; | ||
| 21 | 		return x; | ||
| 22 | 	} | ||
| 23 | |||
| 24 | 	/* normalize x and y */ | ||
| 25 | 	if (!ex) { | ||
| 26 | 		for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1); | ||
| 27 | 		uxi <<= -ex + 1; | ||
| 28 | 	} else { | ||
| 29 | 		uxi &= -1ULL >> 12; | ||
| 30 | 		uxi |= 1ULL << 52; | ||
| 31 | 	} | ||
| 32 | 	if (!ey) { | ||
| 33 | 		for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1); | ||
| 34 | 		uy.i <<= -ey + 1; | ||
| 35 | 	} else { | ||
| 36 | 		uy.i &= -1ULL >> 12; | ||
| 37 | 		uy.i |= 1ULL << 52; | ||
| 38 | 	} | ||
| 39 | |||
| 40 | 	/* x mod y */ | ||
| 41 | 	for (; ex > ey; ex--) { | ||
| 42 | 		i = uxi - uy.i; | ||
| 43 | 		if (i >> 63 == 0) { | ||
| 44 | 			if (i == 0) | ||
| 45 | 				return 0*x; | ||
| 46 | 			uxi = i; | ||
| 47 | 		} | ||
| 48 | 		uxi <<= 1; | ||
| 49 | 	} | ||
| 50 | 	i = uxi - uy.i; | ||
| 51 | 	if (i >> 63 == 0) { | ||
| 52 | 		if (i == 0) | ||
| 53 | 			return 0*x; | ||
| 54 | 		uxi = i; | ||
| 55 | 	} | ||
| 56 | 	for (; uxi>>52 == 0; uxi <<= 1, ex--); | ||
| 57 | |||
| 58 | 	/* scale result */ | ||
| 59 | 	if (ex > 0) { | ||
| 60 | 		uxi -= 1ULL << 52; | ||
| 61 | 		uxi |= (uint64_t)ex << 52; | ||
| 62 | 	} else { | ||
| 63 | 		uxi >>= -ex + 1; | ||
| 64 | 	} | ||
| 65 | 	uxi |= (uint64_t)sx << 63; | ||
| 66 | 	ux.i = uxi; | ||
| 67 | 	return ux.f; | ||
| 68 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmodf.c created+65| ... | @@ -0,0 +1,65 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float fmodf(float x, float y) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} ux = {x}, uy = {y}; | ||
| 7 | 	int ex = ux.i>>23 & 0xff; | ||
| 8 | 	int ey = uy.i>>23 & 0xff; | ||
| 9 | 	uint32_t sx = ux.i & 0x80000000; | ||
| 10 | 	uint32_t i; | ||
| 11 | 	uint32_t uxi = ux.i; | ||
| 12 | |||
| 13 | 	if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) | ||
| 14 | 		return (x*y)/(x*y); | ||
| 15 | 	if (uxi<<1 <= uy.i<<1) { | ||
| 16 | 		if (uxi<<1 == uy.i<<1) | ||
| 17 | 			return 0*x; | ||
| 18 | 		return x; | ||
| 19 | 	} | ||
| 20 | |||
| 21 | 	/* normalize x and y */ | ||
| 22 | 	if (!ex) { | ||
| 23 | 		for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1); | ||
| 24 | 		uxi <<= -ex + 1; | ||
| 25 | 	} else { | ||
| 26 | 		uxi &= -1U >> 9; | ||
| 27 | 		uxi |= 1U << 23; | ||
| 28 | 	} | ||
| 29 | 	if (!ey) { | ||
| 30 | 		for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1); | ||
| 31 | 		uy.i <<= -ey + 1; | ||
| 32 | 	} else { | ||
| 33 | 		uy.i &= -1U >> 9; | ||
| 34 | 		uy.i |= 1U << 23; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	/* x mod y */ | ||
| 38 | 	for (; ex > ey; ex--) { | ||
| 39 | 		i = uxi - uy.i; | ||
| 40 | 		if (i >> 31 == 0) { | ||
| 41 | 			if (i == 0) | ||
| 42 | 				return 0*x; | ||
| 43 | 			uxi = i; | ||
| 44 | 		} | ||
| 45 | 		uxi <<= 1; | ||
| 46 | 	} | ||
| 47 | 	i = uxi - uy.i; | ||
| 48 | 	if (i >> 31 == 0) { | ||
| 49 | 		if (i == 0) | ||
| 50 | 			return 0*x; | ||
| 51 | 		uxi = i; | ||
| 52 | 	} | ||
| 53 | 	for (; uxi>>23 == 0; uxi <<= 1, ex--); | ||
| 54 | |||
| 55 | 	/* scale result up */ | ||
| 56 | 	if (ex > 0) { | ||
| 57 | 		uxi -= 1U << 23; | ||
| 58 | 		uxi |= (uint32_t)ex << 23; | ||
| 59 | 	} else { | ||
| 60 | 		uxi >>= -ex + 1; | ||
| 61 | 	} | ||
| 62 | 	uxi |= sx; | ||
| 63 | 	ux.i = uxi; | ||
| 64 | 	return ux.f; | ||
| 65 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/fmodl.c created+105| ... | @@ -0,0 +1,105 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double fmodl(long double x, long double y) | ||
| 5 | { | ||
| 6 | 	return fmod(x, y); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double fmodl(long double x, long double y) | ||
| 10 | { | ||
| 11 | 	union ldshape ux = {x}, uy = {y}; | ||
| 12 | 	int ex = ux.i.se & 0x7fff; | ||
| 13 | 	int ey = uy.i.se & 0x7fff; | ||
| 14 | 	int sx = ux.i.se & 0x8000; | ||
| 15 | |||
| 16 | 	if (y == 0 || isnan(y) || ex == 0x7fff) | ||
| 17 | 		return (x*y)/(x*y); | ||
| 18 | 	ux.i.se = ex; | ||
| 19 | 	uy.i.se = ey; | ||
| 20 | 	if (ux.f <= uy.f) { | ||
| 21 | 		if (ux.f == uy.f) | ||
| 22 | 			return 0*x; | ||
| 23 | 		return x; | ||
| 24 | 	} | ||
| 25 | |||
| 26 | 	/* normalize x and y */ | ||
| 27 | 	if (!ex) { | ||
| 28 | 		ux.f *= 0x1p120f; | ||
| 29 | 		ex = ux.i.se - 120; | ||
| 30 | 	} | ||
| 31 | 	if (!ey) { | ||
| 32 | 		uy.f *= 0x1p120f; | ||
| 33 | 		ey = uy.i.se - 120; | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	/* x mod y */ | ||
| 37 | #if LDBL_MANT_DIG == 64 | ||
| 38 | 	uint64_t i, mx, my; | ||
| 39 | 	mx = ux.i.m; | ||
| 40 | 	my = uy.i.m; | ||
| 41 | 	for (; ex > ey; ex--) { | ||
| 42 | 		i = mx - my; | ||
| 43 | 		if (mx >= my) { | ||
| 44 | 			if (i == 0) | ||
| 45 | 				return 0*x; | ||
| 46 | 			mx = 2*i; | ||
| 47 | 		} else if (2*mx < mx) { | ||
| 48 | 			mx = 2*mx - my; | ||
| 49 | 		} else { | ||
| 50 | 			mx = 2*mx; | ||
| 51 | 		} | ||
| 52 | 	} | ||
| 53 | 	i = mx - my; | ||
| 54 | 	if (mx >= my) { | ||
| 55 | 		if (i == 0) | ||
| 56 | 			return 0*x; | ||
| 57 | 		mx = i; | ||
| 58 | 	} | ||
| 59 | 	for (; mx >> 63 == 0; mx *= 2, ex--); | ||
| 60 | 	ux.i.m = mx; | ||
| 61 | #elif LDBL_MANT_DIG == 113 | ||
| 62 | 	uint64_t hi, lo, xhi, xlo, yhi, ylo; | ||
| 63 | 	xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48; | ||
| 64 | 	yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48; | ||
| 65 | 	xlo = ux.i2.lo; | ||
| 66 | 	ylo = uy.i2.lo; | ||
| 67 | 	for (; ex > ey; ex--) { | ||
| 68 | 		hi = xhi - yhi; | ||
| 69 | 		lo = xlo - ylo; | ||
| 70 | 		if (xlo < ylo) | ||
| 71 | 			hi -= 1; | ||
| 72 | 		if (hi >> 63 == 0) { | ||
| 73 | 			if ((hi|lo) == 0) | ||
| 74 | 				return 0*x; | ||
| 75 | 			xhi = 2*hi + (lo>>63); | ||
| 76 | 			xlo = 2*lo; | ||
| 77 | 		} else { | ||
| 78 | 			xhi = 2*xhi + (xlo>>63); | ||
| 79 | 			xlo = 2*xlo; | ||
| 80 | 		} | ||
| 81 | 	} | ||
| 82 | 	hi = xhi - yhi; | ||
| 83 | 	lo = xlo - ylo; | ||
| 84 | 	if (xlo < ylo) | ||
| 85 | 		hi -= 1; | ||
| 86 | 	if (hi >> 63 == 0) { | ||
| 87 | 		if ((hi|lo) == 0) | ||
| 88 | 			return 0*x; | ||
| 89 | 		xhi = hi; | ||
| 90 | 		xlo = lo; | ||
| 91 | 	} | ||
| 92 | 	for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--); | ||
| 93 | 	ux.i2.hi = xhi; | ||
| 94 | 	ux.i2.lo = xlo; | ||
| 95 | #endif | ||
| 96 | |||
| 97 | 	/* scale result */ | ||
| 98 | 	if (ex <= 0) { | ||
| 99 | 		ux.i.se = (ex+120)|sx; | ||
| 100 | 		ux.f *= 0x1p-120f; | ||
| 101 | 	} else | ||
| 102 | 		ux.i.se = ex|sx; | ||
| 103 | 	return ux.f; | ||
| 104 | } | ||
| 105 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/frexp.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | double frexp(double x, int *e) | ||
| 5 | { | ||
| 6 | 	union { double d; uint64_t i; } y = { x }; | ||
| 7 | 	int ee = y.i>>52 & 0x7ff; | ||
| 8 | |||
| 9 | 	if (!ee) { | ||
| 10 | 		if (x) { | ||
| 11 | 			x = frexp(x*0x1p64, e); | ||
| 12 | 			*e -= 64; | ||
| 13 | 		} else *e = 0; | ||
| 14 | 		return x; | ||
| 15 | 	} else if (ee == 0x7ff) { | ||
| 16 | 		return x; | ||
| 17 | 	} | ||
| 18 | |||
| 19 | 	*e = ee - 0x3fe; | ||
| 20 | 	y.i &= 0x800fffffffffffffull; | ||
| 21 | 	y.i |= 0x3fe0000000000000ull; | ||
| 22 | 	return y.d; | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/frexpf.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float frexpf(float x, int *e) | ||
| 5 | { | ||
| 6 | 	union { float f; uint32_t i; } y = { x }; | ||
| 7 | 	int ee = y.i>>23 & 0xff; | ||
| 8 | |||
| 9 | 	if (!ee) { | ||
| 10 | 		if (x) { | ||
| 11 | 			x = frexpf(x*0x1p64, e); | ||
| 12 | 			*e -= 64; | ||
| 13 | 		} else *e = 0; | ||
| 14 | 		return x; | ||
| 15 | 	} else if (ee == 0xff) { | ||
| 16 | 		return x; | ||
| 17 | 	} | ||
| 18 | |||
| 19 | 	*e = ee - 0x7e; | ||
| 20 | 	y.i &= 0x807ffffful; | ||
| 21 | 	y.i |= 0x3f000000ul; | ||
| 22 | 	return y.f; | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/frexpl.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double frexpl(long double x, int *e) | ||
| 5 | { | ||
| 6 | 	return frexp(x, e); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double frexpl(long double x, int *e) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	int ee = u.i.se & 0x7fff; | ||
| 13 | |||
| 14 | 	if (!ee) { | ||
| 15 | 		if (x) { | ||
| 16 | 			x = frexpl(x*0x1p120, e); | ||
| 17 | 			*e -= 120; | ||
| 18 | 		} else *e = 0; | ||
| 19 | 		return x; | ||
| 20 | 	} else if (ee == 0x7fff) { | ||
| 21 | 		return x; | ||
| 22 | 	} | ||
| 23 | |||
| 24 | 	*e = ee - 0x3ffe; | ||
| 25 | 	u.i.se &= 0x8000; | ||
| 26 | 	u.i.se |= 0x3ffe; | ||
| 27 | 	return u.f; | ||
| 28 | } | ||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/hypot.c created+67| ... | @@ -0,0 +1,67 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <float.h> | ||
| 4 | |||
| 5 | #if FLT_EVAL_METHOD > 1U && LDBL_MANT_DIG == 64 | ||
| 6 | #define SPLIT (0x1p32 + 1) | ||
| 7 | #else | ||
| 8 | #define SPLIT (0x1p27 + 1) | ||
| 9 | #endif | ||
| 10 | |||
| 11 | static void sq(double_t *hi, double_t *lo, double x) | ||
| 12 | { | ||
| 13 | 	double_t xh, xl, xc; | ||
| 14 | |||
| 15 | 	xc = (double_t)x*SPLIT; | ||
| 16 | 	xh = x - xc + xc; | ||
| 17 | 	xl = x - xh; | ||
| 18 | 	*hi = (double_t)x*x; | ||
| 19 | 	*lo = xh*xh - *hi + 2*xh*xl + xl*xl; | ||
| 20 | } | ||
| 21 | |||
| 22 | double hypot(double x, double y) | ||
| 23 | { | ||
| 24 | 	union {double f; uint64_t i;} ux = {x}, uy = {y}, ut; | ||
| 25 | 	int ex, ey; | ||
| 26 | 	double_t hx, lx, hy, ly, z; | ||
| 27 | |||
| 28 | 	/* arrange |x| >= |y| */ | ||
| 29 | 	ux.i &= -1ULL>>1; | ||
| 30 | 	uy.i &= -1ULL>>1; | ||
| 31 | 	if (ux.i < uy.i) { | ||
| 32 | 		ut = ux; | ||
| 33 | 		ux = uy; | ||
| 34 | 		uy = ut; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	/* special cases */ | ||
| 38 | 	ex = ux.i>>52; | ||
| 39 | 	ey = uy.i>>52; | ||
| 40 | 	x = ux.f; | ||
| 41 | 	y = uy.f; | ||
| 42 | 	/* note: hypot(inf,nan) == inf */ | ||
| 43 | 	if (ey == 0x7ff) | ||
| 44 | 		return y; | ||
| 45 | 	if (ex == 0x7ff || uy.i == 0) | ||
| 46 | 		return x; | ||
| 47 | 	/* note: hypot(x,y) ~= x + y*y/x/2 with inexact for small y/x */ | ||
| 48 | 	/* 64 difference is enough for ld80 double_t */ | ||
| 49 | 	if (ex - ey > 64) | ||
| 50 | 		return x + y; | ||
| 51 | |||
| 52 | 	/* precise sqrt argument in nearest rounding mode without overflow */ | ||
| 53 | 	/* xh*xh must not overflow and xl*xl must not underflow in sq */ | ||
| 54 | 	z = 1; | ||
| 55 | 	if (ex > 0x3ff+510) { | ||
| 56 | 		z = 0x1p700; | ||
| 57 | 		x *= 0x1p-700; | ||
| 58 | 		y *= 0x1p-700; | ||
| 59 | 	} else if (ey < 0x3ff-450) { | ||
| 60 | 		z = 0x1p-700; | ||
| 61 | 		x *= 0x1p700; | ||
| 62 | 		y *= 0x1p700; | ||
| 63 | 	} | ||
| 64 | 	sq(&hx, &lx, x); | ||
| 65 | 	sq(&hy, &ly, y); | ||
| 66 | 	return z*sqrt(ly+lx+hy+hx); | ||
| 67 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/hypotf.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float hypotf(float x, float y) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} ux = {x}, uy = {y}, ut; | ||
| 7 | 	float_t z; | ||
| 8 | |||
| 9 | 	ux.i &= -1U>>1; | ||
| 10 | 	uy.i &= -1U>>1; | ||
| 11 | 	if (ux.i < uy.i) { | ||
| 12 | 		ut = ux; | ||
| 13 | 		ux = uy; | ||
| 14 | 		uy = ut; | ||
| 15 | 	} | ||
| 16 | |||
| 17 | 	x = ux.f; | ||
| 18 | 	y = uy.f; | ||
| 19 | 	if (uy.i == 0xff<<23) | ||
| 20 | 		return y; | ||
| 21 | 	if (ux.i >= 0xff<<23 || uy.i == 0 || ux.i - uy.i >= 25<<23) | ||
| 22 | 		return x + y; | ||
| 23 | |||
| 24 | 	z = 1; | ||
| 25 | 	if (ux.i >= (0x7f+60)<<23) { | ||
| 26 | 		z = 0x1p90f; | ||
| 27 | 		x *= 0x1p-90f; | ||
| 28 | 		y *= 0x1p-90f; | ||
| 29 | 	} else if (uy.i < (0x7f-60)<<23) { | ||
| 30 | 		z = 0x1p-90f; | ||
| 31 | 		x *= 0x1p90f; | ||
| 32 | 		y *= 0x1p90f; | ||
| 33 | 	} | ||
| 34 | 	return z*sqrtf((double)x*x + (double)y*y); | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/hypotl.c created+66| ... | @@ -0,0 +1,66 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double hypotl(long double x, long double y) | ||
| 5 | { | ||
| 6 | 	return hypot(x, y); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | #if LDBL_MANT_DIG == 64 | ||
| 10 | #define SPLIT (0x1p32L+1) | ||
| 11 | #elif LDBL_MANT_DIG == 113 | ||
| 12 | #define SPLIT (0x1p57L+1) | ||
| 13 | #endif | ||
| 14 | |||
| 15 | static void sq(long double *hi, long double *lo, long double x) | ||
| 16 | { | ||
| 17 | 	long double xh, xl, xc; | ||
| 18 | 	xc = x*SPLIT; | ||
| 19 | 	xh = x - xc + xc; | ||
| 20 | 	xl = x - xh; | ||
| 21 | 	*hi = x*x; | ||
| 22 | 	*lo = xh*xh - *hi + 2*xh*xl + xl*xl; | ||
| 23 | } | ||
| 24 | |||
| 25 | long double hypotl(long double x, long double y) | ||
| 26 | { | ||
| 27 | 	union ldshape ux = {x}, uy = {y}; | ||
| 28 | 	int ex, ey; | ||
| 29 | 	long double hx, lx, hy, ly, z; | ||
| 30 | |||
| 31 | 	ux.i.se &= 0x7fff; | ||
| 32 | 	uy.i.se &= 0x7fff; | ||
| 33 | 	if (ux.i.se < uy.i.se) { | ||
| 34 | 		ex = uy.i.se; | ||
| 35 | 		ey = ux.i.se; | ||
| 36 | 		x = uy.f; | ||
| 37 | 		y = ux.f; | ||
| 38 | 	} else { | ||
| 39 | 		ex = ux.i.se; | ||
| 40 | 		ey = uy.i.se; | ||
| 41 | 		x = ux.f; | ||
| 42 | 		y = uy.f; | ||
| 43 | 	} | ||
| 44 | |||
| 45 | 	if (ex == 0x7fff && isinf(y)) | ||
| 46 | 		return y; | ||
| 47 | 	if (ex == 0x7fff || y == 0) | ||
| 48 | 		return x; | ||
| 49 | 	if (ex - ey > LDBL_MANT_DIG) | ||
| 50 | 		return x + y; | ||
| 51 | |||
| 52 | 	z = 1; | ||
| 53 | 	if (ex > 0x3fff+8000) { | ||
| 54 | 		z = 0x1p10000L; | ||
| 55 | 		x *= 0x1p-10000L; | ||
| 56 | 		y *= 0x1p-10000L; | ||
| 57 | 	} else if (ey < 0x3fff-8000) { | ||
| 58 | 		z = 0x1p-10000L; | ||
| 59 | 		x *= 0x1p10000L; | ||
| 60 | 		y *= 0x1p10000L; | ||
| 61 | 	} | ||
| 62 | 	sq(&hx, &lx, x); | ||
| 63 | 	sq(&hy, &ly, y); | ||
| 64 | 	return z*sqrtl(ly+lx+hy+hx); | ||
| 65 | } | ||
| 66 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/__invtrigl.s createdlib/libc/wasi/libc-top-half/musl/src/math/i386/acos.s created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | # use acos(x) = atan2(fabs(sqrt((1-x)*(1+x))), x) | ||
| 2 | |||
| 3 | .global acos | ||
| 4 | .type acos,@function | ||
| 5 | acos: | ||
| 6 | 	fldl 4(%esp) | ||
| 7 | 	fld %st(0) | ||
| 8 | 	fld1 | ||
| 9 | 	fsub %st(0),%st(1) | ||
| 10 | 	fadd %st(2) | ||
| 11 | 	fmulp | ||
| 12 | 	fsqrt | ||
| 13 | 	fabs # fix sign of zero (matters in downward rounding mode) | ||
| 14 | 	fxch %st(1) | ||
| 15 | 	fpatan | ||
| 16 | 	fstpl 4(%esp) | ||
| 17 | 	fldl 4(%esp) | ||
| 18 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/acosf.s created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | .global acosf | ||
| 2 | .type acosf,@function | ||
| 3 | acosf: | ||
| 4 | 	flds 4(%esp) | ||
| 5 | 	fld %st(0) | ||
| 6 | 	fld1 | ||
| 7 | 	fsub %st(0),%st(1) | ||
| 8 | 	fadd %st(2) | ||
| 9 | 	fmulp | ||
| 10 | 	fsqrt | ||
| 11 | 	fabs # fix sign of zero (matters in downward rounding mode) | ||
| 12 | 	fxch %st(1) | ||
| 13 | 	fpatan | ||
| 14 | 	fstps 4(%esp) | ||
| 15 | 	flds 4(%esp) | ||
| 16 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/acosl.s created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | .global acosl | ||
| 2 | .type acosl,@function | ||
| 3 | acosl: | ||
| 4 | 	fldt 4(%esp) | ||
| 5 | 	fld %st(0) | ||
| 6 | 	fld1 | ||
| 7 | 	fsub %st(0),%st(1) | ||
| 8 | 	fadd %st(2) | ||
| 9 | 	fmulp | ||
| 10 | 	fsqrt | ||
| 11 | 	fabs # fix sign of zero (matters in downward rounding mode) | ||
| 12 | 	fxch %st(1) | ||
| 13 | 	fpatan | ||
| 14 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/asin.s created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | .global asin | ||
| 2 | .type asin,@function | ||
| 3 | asin: | ||
| 4 | 	fldl 4(%esp) | ||
| 5 | 	mov 8(%esp),%eax | ||
| 6 | 	add %eax,%eax | ||
| 7 | 	cmp $0x00200000,%eax | ||
| 8 | 	jb 1f | ||
| 9 | 	fld %st(0) | ||
| 10 | 	fld1 | ||
| 11 | 	fsub %st(0),%st(1) | ||
| 12 | 	fadd %st(2) | ||
| 13 | 	fmulp | ||
| 14 | 	fsqrt | ||
| 15 | 	fpatan | ||
| 16 | 	fstpl 4(%esp) | ||
| 17 | 	fldl 4(%esp) | ||
| 18 | 	ret | ||
| 19 | 		# subnormal x, return x with underflow | ||
| 20 | 1:	fsts 4(%esp) | ||
| 21 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/asinf.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .global asinf | ||
| 2 | .type asinf,@function | ||
| 3 | asinf: | ||
| 4 | 	flds 4(%esp) | ||
| 5 | 	mov 4(%esp),%eax | ||
| 6 | 	add %eax,%eax | ||
| 7 | 	cmp $0x01000000,%eax | ||
| 8 | 	jb 1f | ||
| 9 | 	fld %st(0) | ||
| 10 | 	fld1 | ||
| 11 | 	fsub %st(0),%st(1) | ||
| 12 | 	fadd %st(2) | ||
| 13 | 	fmulp | ||
| 14 | 	fsqrt | ||
| 15 | 	fpatan | ||
| 16 | 	fstps 4(%esp) | ||
| 17 | 	flds 4(%esp) | ||
| 18 | 	ret | ||
| 19 | 		# subnormal x, return x with underflow | ||
| 20 | 1:	fld %st(0) | ||
| 21 | 	fmul %st(1) | ||
| 22 | 	fstps 4(%esp) | ||
| 23 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/asinl.s created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | .global asinl | ||
| 2 | .type asinl,@function | ||
| 3 | asinl: | ||
| 4 | 	fldt 4(%esp) | ||
| 5 | 	fld %st(0) | ||
| 6 | 	fld1 | ||
| 7 | 	fsub %st(0),%st(1) | ||
| 8 | 	fadd %st(2) | ||
| 9 | 	fmulp | ||
| 10 | 	fsqrt | ||
| 11 | 	fpatan | ||
| 12 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan.s created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | .global atan | ||
| 2 | .type atan,@function | ||
| 3 | atan: | ||
| 4 | 	fldl 4(%esp) | ||
| 5 | 	mov 8(%esp),%eax | ||
| 6 | 	add %eax,%eax | ||
| 7 | 	cmp $0x00200000,%eax | ||
| 8 | 	jb 1f | ||
| 9 | 	fld1 | ||
| 10 | 	fpatan | ||
| 11 | 	fstpl 4(%esp) | ||
| 12 | 	fldl 4(%esp) | ||
| 13 | 	ret | ||
| 14 | 		# subnormal x, return x with underflow | ||
| 15 | 1:	fsts 4(%esp) | ||
| 16 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2.s created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | .global atan2 | ||
| 2 | .type atan2,@function | ||
| 3 | atan2: | ||
| 4 | 	fldl 4(%esp) | ||
| 5 | 	fldl 12(%esp) | ||
| 6 | 	fpatan | ||
| 7 | 	fstpl 4(%esp) | ||
| 8 | 	fldl 4(%esp) | ||
| 9 | 	mov 8(%esp),%eax | ||
| 10 | 	add %eax,%eax | ||
| 11 | 	cmp $0x00200000,%eax | ||
| 12 | 	jae 1f | ||
| 13 | 		# subnormal x, return x with underflow | ||
| 14 | 	fsts 4(%esp) | ||
| 15 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2f.s created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | .global atan2f | ||
| 2 | .type atan2f,@function | ||
| 3 | atan2f: | ||
| 4 | 	flds 4(%esp) | ||
| 5 | 	flds 8(%esp) | ||
| 6 | 	fpatan | ||
| 7 | 	fstps 4(%esp) | ||
| 8 | 	flds 4(%esp) | ||
| 9 | 	mov 4(%esp),%eax | ||
| 10 | 	add %eax,%eax | ||
| 11 | 	cmp $0x01000000,%eax | ||
| 12 | 	jae 1f | ||
| 13 | 		# subnormal x, return x with underflow | ||
| 14 | 	fld %st(0) | ||
| 15 | 	fmul %st(1) | ||
| 16 | 	fstps 4(%esp) | ||
| 17 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/atan2l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global atan2l | ||
| 2 | .type atan2l,@function | ||
| 3 | atan2l: | ||
| 4 | 	fldt 4(%esp) | ||
| 5 | 	fldt 16(%esp) | ||
| 6 | 	fpatan | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/atanf.s created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | .global atanf | ||
| 2 | .type atanf,@function | ||
| 3 | atanf: | ||
| 4 | 	flds 4(%esp) | ||
| 5 | 	mov 4(%esp),%eax | ||
| 6 | 	add %eax,%eax | ||
| 7 | 	cmp $0x01000000,%eax | ||
| 8 | 	jb 1f | ||
| 9 | 	fld1 | ||
| 10 | 	fpatan | ||
| 11 | 	fstps 4(%esp) | ||
| 12 | 	flds 4(%esp) | ||
| 13 | 	ret | ||
| 14 | 		# subnormal x, return x with underflow | ||
| 15 | 1:	fld %st(0) | ||
| 16 | 	fmul %st(1) | ||
| 17 | 	fstps 4(%esp) | ||
| 18 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/atanl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global atanl | ||
| 2 | .type atanl,@function | ||
| 3 | atanl: | ||
| 4 | 	fldt 4(%esp) | ||
| 5 | 	fld1 | ||
| 6 | 	fpatan | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceil.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceilf.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/ceill.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/exp2l.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see exp_ld.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/exp_ld.s created+93| ... | @@ -0,0 +1,93 @@ | ||
| 1 | .global expm1l | ||
| 2 | .type expm1l,@function | ||
| 3 | expm1l: | ||
| 4 | 	fldt 4(%esp) | ||
| 5 | 	fldl2e | ||
| 6 | 	fmulp | ||
| 7 | 	mov $0xc2820000,%eax | ||
| 8 | 	push %eax | ||
| 9 | 	flds (%esp) | ||
| 10 | 	pop %eax | ||
| 11 | 	fucomp %st(1) | ||
| 12 | 	fnstsw %ax | ||
| 13 | 	sahf | ||
| 14 | 	fld1 | ||
| 15 | 	jb 1f | ||
| 16 | 		# x*log2e < -65, return -1 without underflow | ||
| 17 | 	fstp %st(1) | ||
| 18 | 	fchs | ||
| 19 | 	ret | ||
| 20 | 1:	fld %st(1) | ||
| 21 | 	fabs | ||
| 22 | 	fucom %st(1) | ||
| 23 | 	fnstsw %ax | ||
| 24 | 	fstp %st(0) | ||
| 25 | 	fstp %st(0) | ||
| 26 | 	sahf | ||
| 27 | 	ja 1f | ||
| 28 | 	f2xm1 | ||
| 29 | 	ret | ||
| 30 | 1:	call 1f | ||
| 31 | 	fld1 | ||
| 32 | 	fsubrp | ||
| 33 | 	ret | ||
| 34 | |||
| 35 | .global exp2l | ||
| 36 | .global __exp2l | ||
| 37 | .hidden __exp2l | ||
| 38 | .type exp2l,@function | ||
| 39 | exp2l: | ||
| 40 | __exp2l: | ||
| 41 | 	fldt 4(%esp) | ||
| 42 | 1:	sub $12,%esp | ||
| 43 | 	fld %st(0) | ||
| 44 | 	fstpt (%esp) | ||
| 45 | 	mov 8(%esp),%ax | ||
| 46 | 	and $0x7fff,%ax | ||
| 47 | 	cmp $0x3fff+13,%ax | ||
| 48 | 	jb 4f # |x| < 8192 | ||
| 49 | 	cmp $0x3fff+15,%ax | ||
| 50 | 	jae 3f # |x| >= 32768 | ||
| 51 | 	fsts (%esp) | ||
| 52 | 	cmpl $0xc67ff800,(%esp) | ||
| 53 | 	jb 2f # x > -16382 | ||
| 54 | 	movl $0x5f000000,(%esp) | ||
| 55 | 	flds (%esp) # 0x1p63 | ||
| 56 | 	fld %st(1) | ||
| 57 | 	fsub %st(1) | ||
| 58 | 	faddp | ||
| 59 | 	fucomp %st(1) | ||
| 60 | 	fnstsw | ||
| 61 | 	sahf | ||
| 62 | 	je 2f # x - 0x1p63 + 0x1p63 == x | ||
| 63 | 	movl $1,(%esp) | ||
| 64 | 	flds (%esp) # 0x1p-149 | ||
| 65 | 	fdiv %st(1) | ||
| 66 | 	fstps (%esp) # raise underflow | ||
| 67 | 2:	fld1 | ||
| 68 | 	fld %st(1) | ||
| 69 | 	frndint | ||
| 70 | 	fxch %st(2) | ||
| 71 | 	fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x) | ||
| 72 | 	f2xm1 | ||
| 73 | 	faddp # 2^(x-rint(x)) | ||
| 74 | 1:	fscale | ||
| 75 | 	fstp %st(1) | ||
| 76 | 	add $12,%esp | ||
| 77 | 	ret | ||
| 78 | 3:	xor %eax,%eax | ||
| 79 | 4:	cmp $0x3fff-64,%ax | ||
| 80 | 	fld1 | ||
| 81 | 	jb 1b # |x| < 0x1p-64 | ||
| 82 | 	fstpt (%esp) | ||
| 83 | 	fistl 8(%esp) | ||
| 84 | 	fildl 8(%esp) | ||
| 85 | 	fsubrp %st(1) | ||
| 86 | 	addl $0x3fff,8(%esp) | ||
| 87 | 	f2xm1 | ||
| 88 | 	fld1 | ||
| 89 | 	faddp # 2^(x-rint(x)) | ||
| 90 | 	fldt (%esp) # 2^rint(x) | ||
| 91 | 	fmulp | ||
| 92 | 	add $12,%esp | ||
| 93 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/expl.s created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | # exp(x) = 2^hi + 2^hi (2^lo - 1) | ||
| 2 | # where hi+lo = log2e*x with 128bit precision | ||
| 3 | # exact log2e*x calculation depends on nearest rounding mode | ||
| 4 | # using the exact multiplication method of Dekker and Veltkamp | ||
| 5 | |||
| 6 | .global expl | ||
| 7 | .type expl,@function | ||
| 8 | expl: | ||
| 9 | 	fldt 4(%esp) | ||
| 10 | |||
| 11 | 		# interesting case: 0x1p-32 <= |x| < 16384 | ||
| 12 | 		# check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13] | ||
| 13 | 	mov 12(%esp), %ax | ||
| 14 | 	or $0x8000, %ax | ||
| 15 | 	sub $0xbfdf, %ax | ||
| 16 | 	cmp $45, %ax | ||
| 17 | 	jbe 2f | ||
| 18 | 	test %ax, %ax | ||
| 19 | 	fld1 | ||
| 20 | 	js 1f | ||
| 21 | 		# if |x|>=0x1p14 or nan return 2^trunc(x) | ||
| 22 | 	fscale | ||
| 23 | 	fstp %st(1) | ||
| 24 | 	ret | ||
| 25 | 		# if |x|<0x1p-32 return 1+x | ||
| 26 | 1:	faddp | ||
| 27 | 	ret | ||
| 28 | |||
| 29 | 		# should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc | ||
| 30 | 		# it will be wrong on non-nearest rounding mode | ||
| 31 | 2:	fldl2e | ||
| 32 | 	subl $44, %esp | ||
| 33 | 		# hi = log2e_hi*x | ||
| 34 | 		# 2^hi = exp2l(hi) | ||
| 35 | 	fmul %st(1),%st | ||
| 36 | 	fld %st(0) | ||
| 37 | 	fstpt (%esp) | ||
| 38 | 	fstpt 16(%esp) | ||
| 39 | 	fstpt 32(%esp) | ||
| 40 | .hidden __exp2l | ||
| 41 | 	call __exp2l | ||
| 42 | 		# if 2^hi == inf return 2^hi | ||
| 43 | 	fld %st(0) | ||
| 44 | 	fstpt (%esp) | ||
| 45 | 	cmpw $0x7fff, 8(%esp) | ||
| 46 | 	je 1f | ||
| 47 | 	fldt 32(%esp) | ||
| 48 | 	fldt 16(%esp) | ||
| 49 | 		# fpu stack: 2^hi x hi | ||
| 50 | 		# exact mult: x*log2e | ||
| 51 | 	fld %st(1) | ||
| 52 | 		# c = 0x1p32+1 | ||
| 53 | 	pushl $0x41f00000 | ||
| 54 | 	pushl $0x00100000 | ||
| 55 | 	fldl (%esp) | ||
| 56 | 		# xh = x - c*x + c*x | ||
| 57 | 		# xl = x - xh | ||
| 58 | 	fmulp | ||
| 59 | 	fld %st(2) | ||
| 60 | 	fsub %st(1), %st | ||
| 61 | 	faddp | ||
| 62 | 	fld %st(2) | ||
| 63 | 	fsub %st(1), %st | ||
| 64 | 		# yh = log2e_hi - c*log2e_hi + c*log2e_hi | ||
| 65 | 	pushl $0x3ff71547 | ||
| 66 | 	pushl $0x65200000 | ||
| 67 | 	fldl (%esp) | ||
| 68 | 		# fpu stack: 2^hi x hi xh xl yh | ||
| 69 | 		# lo = hi - xh*yh + xl*yh | ||
| 70 | 	fld %st(2) | ||
| 71 | 	fmul %st(1), %st | ||
| 72 | 	fsubp %st, %st(4) | ||
| 73 | 	fmul %st(1), %st | ||
| 74 | 	faddp %st, %st(3) | ||
| 75 | 		# yl = log2e_hi - yh | ||
| 76 | 	pushl $0x3de705fc | ||
| 77 | 	pushl $0x2f000000 | ||
| 78 | 	fldl (%esp) | ||
| 79 | 		# fpu stack: 2^hi x lo xh xl yl | ||
| 80 | 		# lo += xh*yl + xl*yl | ||
| 81 | 	fmul %st, %st(2) | ||
| 82 | 	fmulp %st, %st(1) | ||
| 83 | 	fxch %st(2) | ||
| 84 | 	faddp | ||
| 85 | 	faddp | ||
| 86 | 		# log2e_lo | ||
| 87 | 	pushl $0xbfbe | ||
| 88 | 	pushl $0x82f0025f | ||
| 89 | 	pushl $0x2dc582ee | ||
| 90 | 	fldt (%esp) | ||
| 91 | 	addl $36,%esp | ||
| 92 | 		# fpu stack: 2^hi x lo log2e_lo | ||
| 93 | 		# lo += log2e_lo*x | ||
| 94 | 		# return 2^hi + 2^hi (2^lo - 1) | ||
| 95 | 	fmulp %st, %st(2) | ||
| 96 | 	faddp | ||
| 97 | 	f2xm1 | ||
| 98 | 	fmul %st(1), %st | ||
| 99 | 	faddp | ||
| 100 | 1:	addl $44, %esp | ||
| 101 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/expm1l.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see exp_ld.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabs.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fabs(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabsf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fabsf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/fabsl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double fabsl(long double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/floor.s created+67| ... | @@ -0,0 +1,67 @@ | ||
| 1 | .global floorf | ||
| 2 | .type floorf,@function | ||
| 3 | floorf: | ||
| 4 | 	flds 4(%esp) | ||
| 5 | 	jmp 1f | ||
| 6 | |||
| 7 | .global floorl | ||
| 8 | .type floorl,@function | ||
| 9 | floorl: | ||
| 10 | 	fldt 4(%esp) | ||
| 11 | 	jmp 1f | ||
| 12 | |||
| 13 | .global floor | ||
| 14 | .type floor,@function | ||
| 15 | floor: | ||
| 16 | 	fldl 4(%esp) | ||
| 17 | 1:	mov $0x7,%al | ||
| 18 | 1:	fstcw 4(%esp) | ||
| 19 | 	mov 5(%esp),%ah | ||
| 20 | 	mov %al,5(%esp) | ||
| 21 | 	fldcw 4(%esp) | ||
| 22 | 	frndint | ||
| 23 | 	mov %ah,5(%esp) | ||
| 24 | 	fldcw 4(%esp) | ||
| 25 | 	ret | ||
| 26 | |||
| 27 | .global ceil | ||
| 28 | .type ceil,@function | ||
| 29 | ceil: | ||
| 30 | 	fldl 4(%esp) | ||
| 31 | 	mov $0xb,%al | ||
| 32 | 	jmp 1b | ||
| 33 | |||
| 34 | .global ceilf | ||
| 35 | .type ceilf,@function | ||
| 36 | ceilf: | ||
| 37 | 	flds 4(%esp) | ||
| 38 | 	mov $0xb,%al | ||
| 39 | 	jmp 1b | ||
| 40 | |||
| 41 | .global ceill | ||
| 42 | .type ceill,@function | ||
| 43 | ceill: | ||
| 44 | 	fldt 4(%esp) | ||
| 45 | 	mov $0xb,%al | ||
| 46 | 	jmp 1b | ||
| 47 | |||
| 48 | .global trunc | ||
| 49 | .type trunc,@function | ||
| 50 | trunc: | ||
| 51 | 	fldl 4(%esp) | ||
| 52 | 	mov $0xf,%al | ||
| 53 | 	jmp 1b | ||
| 54 | |||
| 55 | .global truncf | ||
| 56 | .type truncf,@function | ||
| 57 | truncf: | ||
| 58 | 	flds 4(%esp) | ||
| 59 | 	mov $0xf,%al | ||
| 60 | 	jmp 1b | ||
| 61 | |||
| 62 | .global truncl | ||
| 63 | .type truncl,@function | ||
| 64 | truncl: | ||
| 65 | 	fldt 4(%esp) | ||
| 66 | 	mov $0xf,%al | ||
| 67 | 	jmp 1b | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/floorf.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/floorl.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmod.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fmod(double x, double y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	// fprem does not introduce excess precision into x | ||
| 7 | 	do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 8 | 	while (fpsr & 0x400); | ||
| 9 | 	return x; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmodf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fmodf(float x, float y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	// fprem does not introduce excess precision into x | ||
| 7 | 	do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 8 | 	while (fpsr & 0x400); | ||
| 9 | 	return x; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/fmodl.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double fmodl(long double x, long double y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 7 | 	while (fpsr & 0x400); | ||
| 8 | 	return x; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/hypot.s created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | .global hypot | ||
| 2 | .type hypot,@function | ||
| 3 | hypot: | ||
| 4 | 	mov 8(%esp),%eax | ||
| 5 | 	mov 16(%esp),%ecx | ||
| 6 | 	add %eax,%eax | ||
| 7 | 	add %ecx,%ecx | ||
| 8 | 	and %eax,%ecx | ||
| 9 | 	cmp $0xffe00000,%ecx | ||
| 10 | 	jae 2f | ||
| 11 | 	or 4(%esp),%eax | ||
| 12 | 	jnz 1f | ||
| 13 | 	fldl 12(%esp) | ||
| 14 | 	fabs | ||
| 15 | 	ret | ||
| 16 | 1:	mov 16(%esp),%eax | ||
| 17 | 	add %eax,%eax | ||
| 18 | 	or 12(%esp),%eax | ||
| 19 | 	jnz 1f | ||
| 20 | 	fldl 4(%esp) | ||
| 21 | 	fabs | ||
| 22 | 	ret | ||
| 23 | 1:	fldl 4(%esp) | ||
| 24 | 	fld %st(0) | ||
| 25 | 	fmulp | ||
| 26 | 	fldl 12(%esp) | ||
| 27 | 	fld %st(0) | ||
| 28 | 	fmulp | ||
| 29 | 	faddp | ||
| 30 | 	fsqrt | ||
| 31 | 	ret | ||
| 32 | 2:	sub $0xffe00000,%eax | ||
| 33 | 	or 4(%esp),%eax | ||
| 34 | 	jnz 1f | ||
| 35 | 	fldl 4(%esp) | ||
| 36 | 	fabs | ||
| 37 | 	ret | ||
| 38 | 1:	mov 16(%esp),%eax | ||
| 39 | 	add %eax,%eax | ||
| 40 | 	sub $0xffe00000,%eax | ||
| 41 | 	or 12(%esp),%eax | ||
| 42 | 	fldl 12(%esp) | ||
| 43 | 	jnz 1f | ||
| 44 | 	fabs | ||
| 45 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/hypotf.s created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | .global hypotf | ||
| 2 | .type hypotf,@function | ||
| 3 | hypotf: | ||
| 4 | 	mov 4(%esp),%eax | ||
| 5 | 	mov 8(%esp),%ecx | ||
| 6 | 	add %eax,%eax | ||
| 7 | 	add %ecx,%ecx | ||
| 8 | 	and %eax,%ecx | ||
| 9 | 	cmp $0xff000000,%ecx | ||
| 10 | 	jae 2f | ||
| 11 | 	test %eax,%eax | ||
| 12 | 	jnz 1f | ||
| 13 | 	flds 8(%esp) | ||
| 14 | 	fabs | ||
| 15 | 	ret | ||
| 16 | 1:	mov 8(%esp),%eax | ||
| 17 | 	add %eax,%eax | ||
| 18 | 	jnz 1f | ||
| 19 | 	flds 4(%esp) | ||
| 20 | 	fabs | ||
| 21 | 	ret | ||
| 22 | 1:	flds 4(%esp) | ||
| 23 | 	fld %st(0) | ||
| 24 | 	fmulp | ||
| 25 | 	flds 8(%esp) | ||
| 26 | 	fld %st(0) | ||
| 27 | 	fmulp | ||
| 28 | 	faddp | ||
| 29 | 	fsqrt | ||
| 30 | 	ret | ||
| 31 | 2:	cmp $0xff000000,%eax | ||
| 32 | 	jnz 1f | ||
| 33 | 	flds 4(%esp) | ||
| 34 | 	fabs | ||
| 35 | 	ret | ||
| 36 | 1:	mov 8(%esp),%eax | ||
| 37 | 	add %eax,%eax | ||
| 38 | 	cmp $0xff000000,%eax | ||
| 39 | 	flds 8(%esp) | ||
| 40 | 	jnz 1f | ||
| 41 | 	fabs | ||
| 42 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexp.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see scalbn.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexpf.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see scalbnf.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/ldexpl.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see scalbnl.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrint.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrint(double x) | ||
| 4 | { | ||
| 5 | 	long long r; | ||
| 6 | 	__asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrintf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrintf(float x) | ||
| 4 | { | ||
| 5 | 	long long r; | ||
| 6 | 	__asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/llrintl.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrintl(long double x) | ||
| 4 | { | ||
| 5 | 	long long r; | ||
| 6 | 	__asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global log | ||
| 2 | .type log,@function | ||
| 3 | log: | ||
| 4 | 	fldln2 | ||
| 5 | 	fldl 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	fstpl 4(%esp) | ||
| 8 | 	fldl 4(%esp) | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global log10 | ||
| 2 | .type log10,@function | ||
| 3 | log10: | ||
| 4 | 	fldlg2 | ||
| 5 | 	fldl 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	fstpl 4(%esp) | ||
| 8 | 	fldl 4(%esp) | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10f.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global log10f | ||
| 2 | .type log10f,@function | ||
| 3 | log10f: | ||
| 4 | 	fldlg2 | ||
| 5 | 	flds 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	fstps 4(%esp) | ||
| 8 | 	flds 4(%esp) | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log10l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global log10l | ||
| 2 | .type log10l,@function | ||
| 3 | log10l: | ||
| 4 | 	fldlg2 | ||
| 5 | 	fldt 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1p.s created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | .global log1p | ||
| 2 | .type log1p,@function | ||
| 3 | log1p: | ||
| 4 | 	mov 8(%esp),%eax | ||
| 5 | 	fldln2 | ||
| 6 | 	and $0x7fffffff,%eax | ||
| 7 | 	fldl 4(%esp) | ||
| 8 | 	cmp $0x3fd28f00,%eax | ||
| 9 | 	ja 1f | ||
| 10 | 	cmp $0x00100000,%eax | ||
| 11 | 	jb 2f | ||
| 12 | 	fyl2xp1 | ||
| 13 | 	fstpl 4(%esp) | ||
| 14 | 	fldl 4(%esp) | ||
| 15 | 	ret | ||
| 16 | 1:	fld1 | ||
| 17 | 	faddp | ||
| 18 | 	fyl2x | ||
| 19 | 	fstpl 4(%esp) | ||
| 20 | 	fldl 4(%esp) | ||
| 21 | 	ret | ||
| 22 | 		# subnormal x, return x with underflow | ||
| 23 | 2:	fsts 4(%esp) | ||
| 24 | 	fstp %st(1) | ||
| 25 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1pf.s created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | .global log1pf | ||
| 2 | .type log1pf,@function | ||
| 3 | log1pf: | ||
| 4 | 	mov 4(%esp),%eax | ||
| 5 | 	fldln2 | ||
| 6 | 	and $0x7fffffff,%eax | ||
| 7 | 	flds 4(%esp) | ||
| 8 | 	cmp $0x3e940000,%eax | ||
| 9 | 	ja 1f | ||
| 10 | 	cmp $0x00800000,%eax | ||
| 11 | 	jb 2f | ||
| 12 | 	fyl2xp1 | ||
| 13 | 	fstps 4(%esp) | ||
| 14 | 	flds 4(%esp) | ||
| 15 | 	ret | ||
| 16 | 1:	fld1 | ||
| 17 | 	faddp | ||
| 18 | 	fyl2x | ||
| 19 | 	fstps 4(%esp) | ||
| 20 | 	flds 4(%esp) | ||
| 21 | 	ret | ||
| 22 | 		# subnormal x, return x with underflow | ||
| 23 | 2:	fxch | ||
| 24 | 	fmul %st(1) | ||
| 25 | 	fstps 4(%esp) | ||
| 26 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log1pl.s created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | .global log1pl | ||
| 2 | .type log1pl,@function | ||
| 3 | log1pl: | ||
| 4 | 	mov 10(%esp),%eax | ||
| 5 | 	fldln2 | ||
| 6 | 	and $0x7fffffff,%eax | ||
| 7 | 	fldt 4(%esp) | ||
| 8 | 	cmp $0x3ffd9400,%eax | ||
| 9 | 	ja 1f | ||
| 10 | 	fyl2xp1 | ||
| 11 | 	ret | ||
| 12 | 1:	fld1 | ||
| 13 | 	faddp | ||
| 14 | 	fyl2x | ||
| 15 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global log2 | ||
| 2 | .type log2,@function | ||
| 3 | log2: | ||
| 4 | 	fld1 | ||
| 5 | 	fldl 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	fstpl 4(%esp) | ||
| 8 | 	fldl 4(%esp) | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2f.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global log2f | ||
| 2 | .type log2f,@function | ||
| 3 | log2f: | ||
| 4 | 	fld1 | ||
| 5 | 	flds 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	fstps 4(%esp) | ||
| 8 | 	flds 4(%esp) | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/log2l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global log2l | ||
| 2 | .type log2l,@function | ||
| 3 | log2l: | ||
| 4 | 	fld1 | ||
| 5 | 	fldt 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/logf.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global logf | ||
| 2 | .type logf,@function | ||
| 3 | logf: | ||
| 4 | 	fldln2 | ||
| 5 | 	flds 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	fstps 4(%esp) | ||
| 8 | 	flds 4(%esp) | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/logl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global logl | ||
| 2 | .type logl,@function | ||
| 3 | logl: | ||
| 4 | 	fldln2 | ||
| 5 | 	fldt 4(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrint.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrint(double x) | ||
| 4 | { | ||
| 5 | 	long r; | ||
| 6 | 	__asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrintf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrintf(float x) | ||
| 4 | { | ||
| 5 | 	long r; | ||
| 6 | 	__asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/lrintl.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrintl(long double x) | ||
| 4 | { | ||
| 5 | 	long r; | ||
| 6 | 	__asm__ ("fistpl %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainder.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double remainder(double x, double y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	// fprem1 does not introduce excess precision into x | ||
| 7 | 	do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 8 | 	while (fpsr & 0x400); | ||
| 9 | 	return x; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(remainder, drem); | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainderf.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float remainderf(float x, float y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	// fprem1 does not introduce excess precision into x | ||
| 7 | 	do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 8 | 	while (fpsr & 0x400); | ||
| 9 | 	return x; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(remainderf, dremf); | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/remainderl.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double remainderl(long double x, long double y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 7 | 	while (fpsr & 0x400); | ||
| 8 | 	return x; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquo.s created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | .global remquof | ||
| 2 | .type remquof,@function | ||
| 3 | remquof: | ||
| 4 | 	mov 12(%esp),%ecx | ||
| 5 | 	flds 8(%esp) | ||
| 6 | 	flds 4(%esp) | ||
| 7 | 	mov 11(%esp),%dh | ||
| 8 | 	xor 7(%esp),%dh | ||
| 9 | 	jmp 1f | ||
| 10 | |||
| 11 | .global remquol | ||
| 12 | .type remquol,@function | ||
| 13 | remquol: | ||
| 14 | 	mov 28(%esp),%ecx | ||
| 15 | 	fldt 16(%esp) | ||
| 16 | 	fldt 4(%esp) | ||
| 17 | 	mov 25(%esp),%dh | ||
| 18 | 	xor 13(%esp),%dh | ||
| 19 | 	jmp 1f | ||
| 20 | |||
| 21 | .global remquo | ||
| 22 | .type remquo,@function | ||
| 23 | remquo: | ||
| 24 | 	mov 20(%esp),%ecx | ||
| 25 | 	fldl 12(%esp) | ||
| 26 | 	fldl 4(%esp) | ||
| 27 | 	mov 19(%esp),%dh | ||
| 28 | 	xor 11(%esp),%dh | ||
| 29 | 1:	fprem1 | ||
| 30 | 	fnstsw %ax | ||
| 31 | 	sahf | ||
| 32 | 	jp 1b | ||
| 33 | 	fstp %st(1) | ||
| 34 | 	mov %ah,%dl | ||
| 35 | 	shr %dl | ||
| 36 | 	and $1,%dl | ||
| 37 | 	mov %ah,%al | ||
| 38 | 	shr $5,%al | ||
| 39 | 	and $2,%al | ||
| 40 | 	or %al,%dl | ||
| 41 | 	mov %ah,%al | ||
| 42 | 	shl $2,%al | ||
| 43 | 	and $4,%al | ||
| 44 | 	or %al,%dl | ||
| 45 | 	test %dh,%dh | ||
| 46 | 	jns 1f | ||
| 47 | 	neg %dl | ||
| 48 | 1:	movsbl %dl,%edx | ||
| 49 | 	mov %edx,(%ecx) | ||
| 50 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquof.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see remquo.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/remquol.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see remquo.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/rint.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double rint(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frndint" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/rintf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float rintf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frndint" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/rintl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double rintl(long double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frndint" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbln.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see scalbn.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalblnf.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see scalbnf.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalblnl.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see scalbnl.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbn.s created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | .global ldexp | ||
| 2 | .type ldexp,@function | ||
| 3 | ldexp: | ||
| 4 | 	nop | ||
| 5 | |||
| 6 | .global scalbln | ||
| 7 | .type scalbln,@function | ||
| 8 | scalbln: | ||
| 9 | 	nop | ||
| 10 | |||
| 11 | .global scalbn | ||
| 12 | .type scalbn,@function | ||
| 13 | scalbn: | ||
| 14 | 	mov 12(%esp),%eax | ||
| 15 | 	add $0x3ffe,%eax | ||
| 16 | 	cmp $0x7ffd,%eax | ||
| 17 | 	jb 1f | ||
| 18 | 	sub $0x3ffe,%eax | ||
| 19 | 	sar $31,%eax | ||
| 20 | 	xor $0xfff,%eax | ||
| 21 | 	add $0x3ffe,%eax | ||
| 22 | 1:	inc %eax | ||
| 23 | 	fldl 4(%esp) | ||
| 24 | 	mov %eax,12(%esp) | ||
| 25 | 	mov $0x80000000,%eax | ||
| 26 | 	mov %eax,8(%esp) | ||
| 27 | 	xor %eax,%eax | ||
| 28 | 	mov %eax,4(%esp) | ||
| 29 | 	fldt 4(%esp) | ||
| 30 | 	fmulp | ||
| 31 | 	fstpl 4(%esp) | ||
| 32 | 	fldl 4(%esp) | ||
| 33 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbnf.s created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | .global ldexpf | ||
| 2 | .type ldexpf,@function | ||
| 3 | ldexpf: | ||
| 4 | 	nop | ||
| 5 | |||
| 6 | .global scalblnf | ||
| 7 | .type scalblnf,@function | ||
| 8 | scalblnf: | ||
| 9 | 	nop | ||
| 10 | |||
| 11 | .global scalbnf | ||
| 12 | .type scalbnf,@function | ||
| 13 | scalbnf: | ||
| 14 | 	mov 8(%esp),%eax | ||
| 15 | 	add $0x3fe,%eax | ||
| 16 | 	cmp $0x7fd,%eax | ||
| 17 | 	jb 1f | ||
| 18 | 	sub $0x3fe,%eax | ||
| 19 | 	sar $31,%eax | ||
| 20 | 	xor $0x1ff,%eax | ||
| 21 | 	add $0x3fe,%eax | ||
| 22 | 1:	inc %eax | ||
| 23 | 	shl $20,%eax | ||
| 24 | 	flds 4(%esp) | ||
| 25 | 	mov %eax,8(%esp) | ||
| 26 | 	xor %eax,%eax | ||
| 27 | 	mov %eax,4(%esp) | ||
| 28 | 	fldl 4(%esp) | ||
| 29 | 	fmulp | ||
| 30 | 	fstps 4(%esp) | ||
| 31 | 	flds 4(%esp) | ||
| 32 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/scalbnl.s created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | .global ldexpl | ||
| 2 | .type ldexpl,@function | ||
| 3 | ldexpl: | ||
| 4 | 	nop | ||
| 5 | |||
| 6 | .global scalblnl | ||
| 7 | .type scalblnl,@function | ||
| 8 | scalblnl: | ||
| 9 | 	nop | ||
| 10 | |||
| 11 | .global scalbnl | ||
| 12 | .type scalbnl,@function | ||
| 13 | scalbnl: | ||
| 14 | 	mov 16(%esp),%eax | ||
| 15 | 	add $0x3ffe,%eax | ||
| 16 | 	cmp $0x7ffd,%eax | ||
| 17 | 	jae 1f | ||
| 18 | 	inc %eax | ||
| 19 | 	fldt 4(%esp) | ||
| 20 | 	mov %eax,12(%esp) | ||
| 21 | 	mov $0x80000000,%eax | ||
| 22 | 	mov %eax,8(%esp) | ||
| 23 | 	xor %eax,%eax | ||
| 24 | 	mov %eax,4(%esp) | ||
| 25 | 	fldt 4(%esp) | ||
| 26 | 	fmulp | ||
| 27 | 	ret | ||
| 28 | 1:	fildl 16(%esp) | ||
| 29 | 	fldt 4(%esp) | ||
| 30 | 	fscale | ||
| 31 | 	fstp %st(1) | ||
| 32 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrt.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double sqrt(double x) | ||
| 4 | { | ||
| 5 | 	union ldshape ux; | ||
| 6 | 	unsigned fpsr; | ||
| 7 | 	__asm__ ("fsqrt; fnstsw %%ax": "=t"(ux.f), "=a"(fpsr) : "0"(x)); | ||
| 8 | 	if ((ux.i.m & 0x7ff) != 0x400) | ||
| 9 | 		return (double)ux.f; | ||
| 10 | 	/* Rounding to double would have encountered an exact halfway case. | ||
| 11 | 	 Adjust mantissa downwards if fsqrt rounded up, else upwards. | ||
| 12 | 	 (result of fsqrt could not have been exact) */ | ||
| 13 | 	ux.i.m ^= (fpsr & 0x200) + 0x300; | ||
| 14 | 	return (double)ux.f; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrtf.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float sqrtf(float x) | ||
| 4 | { | ||
| 5 | 	long double t; | ||
| 6 | 	/* The long double result has sufficient precision so that | ||
| 7 | 	 * second rounding to float still keeps the returned value | ||
| 8 | 	 * correctly rounded, see Pierre Roux, "Innocuous Double | ||
| 9 | 	 * Rounding of Basic Arithmetic Operations". */ | ||
| 10 | 	__asm__ ("fsqrt" : "=t"(t) : "0"(x)); | ||
| 11 | 	return (float)t; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/sqrtl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double sqrtl(long double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fsqrt" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/trunc.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/truncf.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/i386/truncl.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floor.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/ilogb.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | int ilogb(double x) | ||
| 5 | { | ||
| 6 | 	#pragma STDC FENV_ACCESS ON | ||
| 7 | 	union {double f; uint64_t i;} u = {x}; | ||
| 8 | 	uint64_t i = u.i; | ||
| 9 | 	int e = i>>52 & 0x7ff; | ||
| 10 | |||
| 11 | 	if (!e) { | ||
| 12 | 		i <<= 12; | ||
| 13 | 		if (i == 0) { | ||
| 14 | 			FORCE_EVAL(0/0.0f); | ||
| 15 | 			return FP_ILOGB0; | ||
| 16 | 		} | ||
| 17 | 		/* subnormal x */ | ||
| 18 | 		for (e = -0x3ff; i>>63 == 0; e--, i<<=1); | ||
| 19 | 		return e; | ||
| 20 | 	} | ||
| 21 | 	if (e == 0x7ff) { | ||
| 22 | 		FORCE_EVAL(0/0.0f); | ||
| 23 | 		return i<<12 ? FP_ILOGBNAN : INT_MAX; | ||
| 24 | 	} | ||
| 25 | 	return e - 0x3ff; | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ilogbf.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | int ilogbf(float x) | ||
| 5 | { | ||
| 6 | 	#pragma STDC FENV_ACCESS ON | ||
| 7 | 	union {float f; uint32_t i;} u = {x}; | ||
| 8 | 	uint32_t i = u.i; | ||
| 9 | 	int e = i>>23 & 0xff; | ||
| 10 | |||
| 11 | 	if (!e) { | ||
| 12 | 		i <<= 9; | ||
| 13 | 		if (i == 0) { | ||
| 14 | 			FORCE_EVAL(0/0.0f); | ||
| 15 | 			return FP_ILOGB0; | ||
| 16 | 		} | ||
| 17 | 		/* subnormal x */ | ||
| 18 | 		for (e = -0x7f; i>>31 == 0; e--, i<<=1); | ||
| 19 | 		return e; | ||
| 20 | 	} | ||
| 21 | 	if (e == 0xff) { | ||
| 22 | 		FORCE_EVAL(0/0.0f); | ||
| 23 | 		return i<<9 ? FP_ILOGBNAN : INT_MAX; | ||
| 24 | 	} | ||
| 25 | 	return e - 0x7f; | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ilogbl.c created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | int ilogbl(long double x) | ||
| 6 | { | ||
| 7 | 	return ilogb(x); | ||
| 8 | } | ||
| 9 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 10 | int ilogbl(long double x) | ||
| 11 | { | ||
| 12 | 	#pragma STDC FENV_ACCESS ON | ||
| 13 | 	union ldshape u = {x}; | ||
| 14 | 	uint64_t m = u.i.m; | ||
| 15 | 	int e = u.i.se & 0x7fff; | ||
| 16 | |||
| 17 | 	if (!e) { | ||
| 18 | 		if (m == 0) { | ||
| 19 | 			FORCE_EVAL(0/0.0f); | ||
| 20 | 			return FP_ILOGB0; | ||
| 21 | 		} | ||
| 22 | 		/* subnormal x */ | ||
| 23 | 		for (e = -0x3fff+1; m>>63 == 0; e--, m<<=1); | ||
| 24 | 		return e; | ||
| 25 | 	} | ||
| 26 | 	if (e == 0x7fff) { | ||
| 27 | 		FORCE_EVAL(0/0.0f); | ||
| 28 | 		return m<<1 ? FP_ILOGBNAN : INT_MAX; | ||
| 29 | 	} | ||
| 30 | 	return e - 0x3fff; | ||
| 31 | } | ||
| 32 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 33 | int ilogbl(long double x) | ||
| 34 | { | ||
| 35 | 	#pragma STDC FENV_ACCESS ON | ||
| 36 | 	union ldshape u = {x}; | ||
| 37 | 	int e = u.i.se & 0x7fff; | ||
| 38 | |||
| 39 | 	if (!e) { | ||
| 40 | 		if (x == 0) { | ||
| 41 | 			FORCE_EVAL(0/0.0f); | ||
| 42 | 			return FP_ILOGB0; | ||
| 43 | 		} | ||
| 44 | 		/* subnormal x */ | ||
| 45 | 		x *= 0x1p120; | ||
| 46 | 		return ilogbl(x) - 120; | ||
| 47 | 	} | ||
| 48 | 	if (e == 0x7fff) { | ||
| 49 | 		FORCE_EVAL(0/0.0f); | ||
| 50 | 		u.i.se = 0; | ||
| 51 | 		return u.f ? FP_ILOGBNAN : INT_MAX; | ||
| 52 | 	} | ||
| 53 | 	return e - 0x3fff; | ||
| 54 | } | ||
| 55 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/j0.c created+375| ... | @@ -0,0 +1,375 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_j0.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 | /* j0(x), y0(x) | ||
| 13 | * Bessel function of the first and second kinds of order zero. | ||
| 14 | * Method -- j0(x): | ||
| 15 | * 1. For tiny x, we use j0(x) = 1 - x^2/4 + x^4/64 - ... | ||
| 16 | * 2. Reduce x to |x| since j0(x)=j0(-x), and | ||
| 17 | * for x in (0,2) | ||
| 18 | * j0(x) = 1-z/4+ z^2*R0/S0, where z = x*x; | ||
| 19 | * (precision: |j0-1+z/4-z^2R0/S0 |<2**-63.67 ) | ||
| 20 | * for x in (2,inf) | ||
| 21 | * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)-q0(x)*sin(x0)) | ||
| 22 | * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0) | ||
| 23 | * as follow: | ||
| 24 | * cos(x0) = cos(x)cos(pi/4)+sin(x)sin(pi/4) | ||
| 25 | * = 1/sqrt(2) * (cos(x) + sin(x)) | ||
| 26 | * sin(x0) = sin(x)cos(pi/4)-cos(x)sin(pi/4) | ||
| 27 | * = 1/sqrt(2) * (sin(x) - cos(x)) | ||
| 28 | * (To avoid cancellation, use | ||
| 29 | * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) | ||
| 30 | * to compute the worse one.) | ||
| 31 | * | ||
| 32 | * 3 Special cases | ||
| 33 | * j0(nan)= nan | ||
| 34 | * j0(0) = 1 | ||
| 35 | * j0(inf) = 0 | ||
| 36 | * | ||
| 37 | * Method -- y0(x): | ||
| 38 | * 1. For x<2. | ||
| 39 | * Since | ||
| 40 | * y0(x) = 2/pi*(j0(x)*(ln(x/2)+Euler) + x^2/4 - ...) | ||
| 41 | * therefore y0(x)-2/pi*j0(x)*ln(x) is an even function. | ||
| 42 | * We use the following function to approximate y0, | ||
| 43 | * y0(x) = U(z)/V(z) + (2/pi)*(j0(x)*ln(x)), z= x^2 | ||
| 44 | * where | ||
| 45 | * U(z) = u00 + u01*z + ... + u06*z^6 | ||
| 46 | * V(z) = 1 + v01*z + ... + v04*z^4 | ||
| 47 | * with absolute approximation error bounded by 2**-72. | ||
| 48 | * Note: For tiny x, U/V = u0 and j0(x)~1, hence | ||
| 49 | * y0(tiny) = u0 + (2/pi)*ln(tiny), (choose tiny<2**-27) | ||
| 50 | * 2. For x>=2. | ||
| 51 | * y0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x0)+q0(x)*sin(x0)) | ||
| 52 | * where x0 = x-pi/4. It is better to compute sin(x0),cos(x0) | ||
| 53 | * by the method mentioned above. | ||
| 54 | * 3. Special cases: y0(0)=-inf, y0(x<0)=NaN, y0(inf)=0. | ||
| 55 | */ | ||
| 56 | |||
| 57 | #include "libm.h" | ||
| 58 | |||
| 59 | static double pzero(double), qzero(double); | ||
| 60 | |||
| 61 | static const double | ||
| 62 | invsqrtpi = 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */ | ||
| 63 | tpi = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */ | ||
| 64 | |||
| 65 | /* common method when |x|>=2 */ | ||
| 66 | static double common(uint32_t ix, double x, int y0) | ||
| 67 | { | ||
| 68 | 	double s,c,ss,cc,z; | ||
| 69 | |||
| 70 | 	/* | ||
| 71 | 	 * j0(x) = sqrt(2/(pi*x))*(p0(x)*cos(x-pi/4)-q0(x)*sin(x-pi/4)) | ||
| 72 | 	 * y0(x) = sqrt(2/(pi*x))*(p0(x)*sin(x-pi/4)+q0(x)*cos(x-pi/4)) | ||
| 73 | 	 * | ||
| 74 | 	 * sin(x-pi/4) = (sin(x) - cos(x))/sqrt(2) | ||
| 75 | 	 * cos(x-pi/4) = (sin(x) + cos(x))/sqrt(2) | ||
| 76 | 	 * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) | ||
| 77 | 	 */ | ||
| 78 | 	s = sin(x); | ||
| 79 | 	c = cos(x); | ||
| 80 | 	if (y0) | ||
| 81 | 		c = -c; | ||
| 82 | 	cc = s+c; | ||
| 83 | 	/* avoid overflow in 2*x, big ulp error when x>=0x1p1023 */ | ||
| 84 | 	if (ix < 0x7fe00000) { | ||
| 85 | 		ss = s-c; | ||
| 86 | 		z = -cos(2*x); | ||
| 87 | 		if (s*c < 0) | ||
| 88 | 			cc = z/ss; | ||
| 89 | 		else | ||
| 90 | 			ss = z/cc; | ||
| 91 | 		if (ix < 0x48000000) { | ||
| 92 | 			if (y0) | ||
| 93 | 				ss = -ss; | ||
| 94 | 			cc = pzero(x)*cc-qzero(x)*ss; | ||
| 95 | 		} | ||
| 96 | 	} | ||
| 97 | 	return invsqrtpi*cc/sqrt(x); | ||
| 98 | } | ||
| 99 | |||
| 100 | /* R0/S0 on [0, 2.00] */ | ||
| 101 | static const double | ||
| 102 | R02 = 1.56249999999999947958e-02, /* 0x3F8FFFFF, 0xFFFFFFFD */ | ||
| 103 | R03 = -1.89979294238854721751e-04, /* 0xBF28E6A5, 0xB61AC6E9 */ | ||
| 104 | R04 = 1.82954049532700665670e-06, /* 0x3EBEB1D1, 0x0C503919 */ | ||
| 105 | R05 = -4.61832688532103189199e-09, /* 0xBE33D5E7, 0x73D63FCE */ | ||
| 106 | S01 = 1.56191029464890010492e-02, /* 0x3F8FFCE8, 0x82C8C2A4 */ | ||
| 107 | S02 = 1.16926784663337450260e-04, /* 0x3F1EA6D2, 0xDD57DBF4 */ | ||
| 108 | S03 = 5.13546550207318111446e-07, /* 0x3EA13B54, 0xCE84D5A9 */ | ||
| 109 | S04 = 1.16614003333790000205e-09; /* 0x3E1408BC, 0xF4745D8F */ | ||
| 110 | |||
| 111 | double j0(double x) | ||
| 112 | { | ||
| 113 | 	double z,r,s; | ||
| 114 | 	uint32_t ix; | ||
| 115 | |||
| 116 | 	GET_HIGH_WORD(ix, x); | ||
| 117 | 	ix &= 0x7fffffff; | ||
| 118 | |||
| 119 | 	/* j0(+-inf)=0, j0(nan)=nan */ | ||
| 120 | 	if (ix >= 0x7ff00000) | ||
| 121 | 		return 1/(x*x); | ||
| 122 | 	x = fabs(x); | ||
| 123 | |||
| 124 | 	if (ix >= 0x40000000) { /* |x| >= 2 */ | ||
| 125 | 		/* large ulp error near zeros: 2.4, 5.52, 8.6537,.. */ | ||
| 126 | 		return common(ix,x,0); | ||
| 127 | 	} | ||
| 128 | |||
| 129 | 	/* 1 - x*x/4 + x*x*R(x^2)/S(x^2) */ | ||
| 130 | 	if (ix >= 0x3f200000) { /* |x| >= 2**-13 */ | ||
| 131 | 		/* up to 4ulp error close to 2 */ | ||
| 132 | 		z = x*x; | ||
| 133 | 		r = z*(R02+z*(R03+z*(R04+z*R05))); | ||
| 134 | 		s = 1+z*(S01+z*(S02+z*(S03+z*S04))); | ||
| 135 | 		return (1+x/2)*(1-x/2) + z*(r/s); | ||
| 136 | 	} | ||
| 137 | |||
| 138 | 	/* 1 - x*x/4 */ | ||
| 139 | 	/* prevent underflow */ | ||
| 140 | 	/* inexact should be raised when x!=0, this is not done correctly */ | ||
| 141 | 	if (ix >= 0x38000000) /* |x| >= 2**-127 */ | ||
| 142 | 		x = 0.25*x*x; | ||
| 143 | 	return 1 - x; | ||
| 144 | } | ||
| 145 | |||
| 146 | static const double | ||
| 147 | u00 = -7.38042951086872317523e-02, /* 0xBFB2E4D6, 0x99CBD01F */ | ||
| 148 | u01 = 1.76666452509181115538e-01, /* 0x3FC69D01, 0x9DE9E3FC */ | ||
| 149 | u02 = -1.38185671945596898896e-02, /* 0xBF8C4CE8, 0xB16CFA97 */ | ||
| 150 | u03 = 3.47453432093683650238e-04, /* 0x3F36C54D, 0x20B29B6B */ | ||
| 151 | u04 = -3.81407053724364161125e-06, /* 0xBECFFEA7, 0x73D25CAD */ | ||
| 152 | u05 = 1.95590137035022920206e-08, /* 0x3E550057, 0x3B4EABD4 */ | ||
| 153 | u06 = -3.98205194132103398453e-11, /* 0xBDC5E43D, 0x693FB3C8 */ | ||
| 154 | v01 = 1.27304834834123699328e-02, /* 0x3F8A1270, 0x91C9C71A */ | ||
| 155 | v02 = 7.60068627350353253702e-05, /* 0x3F13ECBB, 0xF578C6C1 */ | ||
| 156 | v03 = 2.59150851840457805467e-07, /* 0x3E91642D, 0x7FF202FD */ | ||
| 157 | v04 = 4.41110311332675467403e-10; /* 0x3DFE5018, 0x3BD6D9EF */ | ||
| 158 | |||
| 159 | double y0(double x) | ||
| 160 | { | ||
| 161 | 	double z,u,v; | ||
| 162 | 	uint32_t ix,lx; | ||
| 163 | |||
| 164 | 	EXTRACT_WORDS(ix, lx, x); | ||
| 165 | |||
| 166 | 	/* y0(nan)=nan, y0(<0)=nan, y0(0)=-inf, y0(inf)=0 */ | ||
| 167 | 	if ((ix<<1 | lx) == 0) | ||
| 168 | 		return -1/0.0; | ||
| 169 | 	if (ix>>31) | ||
| 170 | 		return 0/0.0; | ||
| 171 | 	if (ix >= 0x7ff00000) | ||
| 172 | 		return 1/x; | ||
| 173 | |||
| 174 | 	if (ix >= 0x40000000) { /* x >= 2 */ | ||
| 175 | 		/* large ulp errors near zeros: 3.958, 7.086,.. */ | ||
| 176 | 		return common(ix,x,1); | ||
| 177 | 	} | ||
| 178 | |||
| 179 | 	/* U(x^2)/V(x^2) + (2/pi)*j0(x)*log(x) */ | ||
| 180 | 	if (ix >= 0x3e400000) { /* x >= 2**-27 */ | ||
| 181 | 		/* large ulp error near the first zero, x ~= 0.89 */ | ||
| 182 | 		z = x*x; | ||
| 183 | 		u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); | ||
| 184 | 		v = 1.0+z*(v01+z*(v02+z*(v03+z*v04))); | ||
| 185 | 		return u/v + tpi*(j0(x)*log(x)); | ||
| 186 | 	} | ||
| 187 | 	return u00 + tpi*log(x); | ||
| 188 | } | ||
| 189 | |||
| 190 | /* The asymptotic expansions of pzero is | ||
| 191 | * 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x. | ||
| 192 | * For x >= 2, We approximate pzero by | ||
| 193 | * pzero(x) = 1 + (R/S) | ||
| 194 | * where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10 | ||
| 195 | * S = 1 + pS0*s^2 + ... + pS4*s^10 | ||
| 196 | * and | ||
| 197 | * | pzero(x)-1-R/S | <= 2 ** ( -60.26) | ||
| 198 | */ | ||
| 199 | static const double pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 200 | 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ | ||
| 201 | -7.03124999999900357484e-02, /* 0xBFB1FFFF, 0xFFFFFD32 */ | ||
| 202 | -8.08167041275349795626e+00, /* 0xC02029D0, 0xB44FA779 */ | ||
| 203 | -2.57063105679704847262e+02, /* 0xC0701102, 0x7B19E863 */ | ||
| 204 | -2.48521641009428822144e+03, /* 0xC0A36A6E, 0xCD4DCAFC */ | ||
| 205 | -5.25304380490729545272e+03, /* 0xC0B4850B, 0x36CC643D */ | ||
| 206 | }; | ||
| 207 | static const double pS8[5] = { | ||
| 208 | 1.16534364619668181717e+02, /* 0x405D2233, 0x07A96751 */ | ||
| 209 | 3.83374475364121826715e+03, /* 0x40ADF37D, 0x50596938 */ | ||
| 210 | 4.05978572648472545552e+04, /* 0x40E3D2BB, 0x6EB6B05F */ | ||
| 211 | 1.16752972564375915681e+05, /* 0x40FC810F, 0x8F9FA9BD */ | ||
| 212 | 4.76277284146730962675e+04, /* 0x40E74177, 0x4F2C49DC */ | ||
| 213 | }; | ||
| 214 | |||
| 215 | static const double pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 216 | -1.14125464691894502584e-11, /* 0xBDA918B1, 0x47E495CC */ | ||
| 217 | -7.03124940873599280078e-02, /* 0xBFB1FFFF, 0xE69AFBC6 */ | ||
| 218 | -4.15961064470587782438e+00, /* 0xC010A370, 0xF90C6BBF */ | ||
| 219 | -6.76747652265167261021e+01, /* 0xC050EB2F, 0x5A7D1783 */ | ||
| 220 | -3.31231299649172967747e+02, /* 0xC074B3B3, 0x6742CC63 */ | ||
| 221 | -3.46433388365604912451e+02, /* 0xC075A6EF, 0x28A38BD7 */ | ||
| 222 | }; | ||
| 223 | static const double pS5[5] = { | ||
| 224 | 6.07539382692300335975e+01, /* 0x404E6081, 0x0C98C5DE */ | ||
| 225 | 1.05125230595704579173e+03, /* 0x40906D02, 0x5C7E2864 */ | ||
| 226 | 5.97897094333855784498e+03, /* 0x40B75AF8, 0x8FBE1D60 */ | ||
| 227 | 9.62544514357774460223e+03, /* 0x40C2CCB8, 0xFA76FA38 */ | ||
| 228 | 2.40605815922939109441e+03, /* 0x40A2CC1D, 0xC70BE864 */ | ||
| 229 | }; | ||
| 230 | |||
| 231 | static const double pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ | ||
| 232 | -2.54704601771951915620e-09, /* 0xBE25E103, 0x6FE1AA86 */ | ||
| 233 | -7.03119616381481654654e-02, /* 0xBFB1FFF6, 0xF7C0E24B */ | ||
| 234 | -2.40903221549529611423e+00, /* 0xC00345B2, 0xAEA48074 */ | ||
| 235 | -2.19659774734883086467e+01, /* 0xC035F74A, 0x4CB94E14 */ | ||
| 236 | -5.80791704701737572236e+01, /* 0xC04D0A22, 0x420A1A45 */ | ||
| 237 | -3.14479470594888503854e+01, /* 0xC03F72AC, 0xA892D80F */ | ||
| 238 | }; | ||
| 239 | static const double pS3[5] = { | ||
| 240 | 3.58560338055209726349e+01, /* 0x4041ED92, 0x84077DD3 */ | ||
| 241 | 3.61513983050303863820e+02, /* 0x40769839, 0x464A7C0E */ | ||
| 242 | 1.19360783792111533330e+03, /* 0x4092A66E, 0x6D1061D6 */ | ||
| 243 | 1.12799679856907414432e+03, /* 0x40919FFC, 0xB8C39B7E */ | ||
| 244 | 1.73580930813335754692e+02, /* 0x4065B296, 0xFC379081 */ | ||
| 245 | }; | ||
| 246 | |||
| 247 | static const double pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 248 | -8.87534333032526411254e-08, /* 0xBE77D316, 0xE927026D */ | ||
| 249 | -7.03030995483624743247e-02, /* 0xBFB1FF62, 0x495E1E42 */ | ||
| 250 | -1.45073846780952986357e+00, /* 0xBFF73639, 0x8A24A843 */ | ||
| 251 | -7.63569613823527770791e+00, /* 0xC01E8AF3, 0xEDAFA7F3 */ | ||
| 252 | -1.11931668860356747786e+01, /* 0xC02662E6, 0xC5246303 */ | ||
| 253 | -3.23364579351335335033e+00, /* 0xC009DE81, 0xAF8FE70F */ | ||
| 254 | }; | ||
| 255 | static const double pS2[5] = { | ||
| 256 | 2.22202997532088808441e+01, /* 0x40363865, 0x908B5959 */ | ||
| 257 | 1.36206794218215208048e+02, /* 0x4061069E, 0x0EE8878F */ | ||
| 258 | 2.70470278658083486789e+02, /* 0x4070E786, 0x42EA079B */ | ||
| 259 | 1.53875394208320329881e+02, /* 0x40633C03, 0x3AB6FAFF */ | ||
| 260 | 1.46576176948256193810e+01, /* 0x402D50B3, 0x44391809 */ | ||
| 261 | }; | ||
| 262 | |||
| 263 | static double pzero(double x) | ||
| 264 | { | ||
| 265 | 	const double *p,*q; | ||
| 266 | 	double_t z,r,s; | ||
| 267 | 	uint32_t ix; | ||
| 268 | |||
| 269 | 	GET_HIGH_WORD(ix, x); | ||
| 270 | 	ix &= 0x7fffffff; | ||
| 271 | 	if (ix >= 0x40200000){p = pR8; q = pS8;} | ||
| 272 | 	else if (ix >= 0x40122E8B){p = pR5; q = pS5;} | ||
| 273 | 	else if (ix >= 0x4006DB6D){p = pR3; q = pS3;} | ||
| 274 | 	else /*ix >= 0x40000000*/ {p = pR2; q = pS2;} | ||
| 275 | 	z = 1.0/(x*x); | ||
| 276 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 277 | 	s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); | ||
| 278 | 	return 1.0 + r/s; | ||
| 279 | } | ||
| 280 | |||
| 281 | |||
| 282 | /* For x >= 8, the asymptotic expansions of qzero is | ||
| 283 | * -1/8 s + 75/1024 s^3 - ..., where s = 1/x. | ||
| 284 | * We approximate pzero by | ||
| 285 | * qzero(x) = s*(-1.25 + (R/S)) | ||
| 286 | * where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10 | ||
| 287 | * S = 1 + qS0*s^2 + ... + qS5*s^12 | ||
| 288 | * and | ||
| 289 | * | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22) | ||
| 290 | */ | ||
| 291 | static const double qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 292 | 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ | ||
| 293 | 7.32421874999935051953e-02, /* 0x3FB2BFFF, 0xFFFFFE2C */ | ||
| 294 | 1.17682064682252693899e+01, /* 0x40278952, 0x5BB334D6 */ | ||
| 295 | 5.57673380256401856059e+02, /* 0x40816D63, 0x15301825 */ | ||
| 296 | 8.85919720756468632317e+03, /* 0x40C14D99, 0x3E18F46D */ | ||
| 297 | 3.70146267776887834771e+04, /* 0x40E212D4, 0x0E901566 */ | ||
| 298 | }; | ||
| 299 | static const double qS8[6] = { | ||
| 300 | 1.63776026895689824414e+02, /* 0x406478D5, 0x365B39BC */ | ||
| 301 | 8.09834494656449805916e+03, /* 0x40BFA258, 0x4E6B0563 */ | ||
| 302 | 1.42538291419120476348e+05, /* 0x41016652, 0x54D38C3F */ | ||
| 303 | 8.03309257119514397345e+05, /* 0x412883DA, 0x83A52B43 */ | ||
| 304 | 8.40501579819060512818e+05, /* 0x4129A66B, 0x28DE0B3D */ | ||
| 305 | -3.43899293537866615225e+05, /* 0xC114FD6D, 0x2C9530C5 */ | ||
| 306 | }; | ||
| 307 | |||
| 308 | static const double qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 309 | 1.84085963594515531381e-11, /* 0x3DB43D8F, 0x29CC8CD9 */ | ||
| 310 | 7.32421766612684765896e-02, /* 0x3FB2BFFF, 0xD172B04C */ | ||
| 311 | 5.83563508962056953777e+00, /* 0x401757B0, 0xB9953DD3 */ | ||
| 312 | 1.35111577286449829671e+02, /* 0x4060E392, 0x0A8788E9 */ | ||
| 313 | 1.02724376596164097464e+03, /* 0x40900CF9, 0x9DC8C481 */ | ||
| 314 | 1.98997785864605384631e+03, /* 0x409F17E9, 0x53C6E3A6 */ | ||
| 315 | }; | ||
| 316 | static const double qS5[6] = { | ||
| 317 | 8.27766102236537761883e+01, /* 0x4054B1B3, 0xFB5E1543 */ | ||
| 318 | 2.07781416421392987104e+03, /* 0x40A03BA0, 0xDA21C0CE */ | ||
| 319 | 1.88472887785718085070e+04, /* 0x40D267D2, 0x7B591E6D */ | ||
| 320 | 5.67511122894947329769e+04, /* 0x40EBB5E3, 0x97E02372 */ | ||
| 321 | 3.59767538425114471465e+04, /* 0x40E19118, 0x1F7A54A0 */ | ||
| 322 | -5.35434275601944773371e+03, /* 0xC0B4EA57, 0xBEDBC609 */ | ||
| 323 | }; | ||
| 324 | |||
| 325 | static const double qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ | ||
| 326 | 4.37741014089738620906e-09, /* 0x3E32CD03, 0x6ADECB82 */ | ||
| 327 | 7.32411180042911447163e-02, /* 0x3FB2BFEE, 0x0E8D0842 */ | ||
| 328 | 3.34423137516170720929e+00, /* 0x400AC0FC, 0x61149CF5 */ | ||
| 329 | 4.26218440745412650017e+01, /* 0x40454F98, 0x962DAEDD */ | ||
| 330 | 1.70808091340565596283e+02, /* 0x406559DB, 0xE25EFD1F */ | ||
| 331 | 1.66733948696651168575e+02, /* 0x4064D77C, 0x81FA21E0 */ | ||
| 332 | }; | ||
| 333 | static const double qS3[6] = { | ||
| 334 | 4.87588729724587182091e+01, /* 0x40486122, 0xBFE343A6 */ | ||
| 335 | 7.09689221056606015736e+02, /* 0x40862D83, 0x86544EB3 */ | ||
| 336 | 3.70414822620111362994e+03, /* 0x40ACF04B, 0xE44DFC63 */ | ||
| 337 | 6.46042516752568917582e+03, /* 0x40B93C6C, 0xD7C76A28 */ | ||
| 338 | 2.51633368920368957333e+03, /* 0x40A3A8AA, 0xD94FB1C0 */ | ||
| 339 | -1.49247451836156386662e+02, /* 0xC062A7EB, 0x201CF40F */ | ||
| 340 | }; | ||
| 341 | |||
| 342 | static const double qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 343 | 1.50444444886983272379e-07, /* 0x3E84313B, 0x54F76BDB */ | ||
| 344 | 7.32234265963079278272e-02, /* 0x3FB2BEC5, 0x3E883E34 */ | ||
| 345 | 1.99819174093815998816e+00, /* 0x3FFFF897, 0xE727779C */ | ||
| 346 | 1.44956029347885735348e+01, /* 0x402CFDBF, 0xAAF96FE5 */ | ||
| 347 | 3.16662317504781540833e+01, /* 0x403FAA8E, 0x29FBDC4A */ | ||
| 348 | 1.62527075710929267416e+01, /* 0x403040B1, 0x71814BB4 */ | ||
| 349 | }; | ||
| 350 | static const double qS2[6] = { | ||
| 351 | 3.03655848355219184498e+01, /* 0x403E5D96, 0xF7C07AED */ | ||
| 352 | 2.69348118608049844624e+02, /* 0x4070D591, 0xE4D14B40 */ | ||
| 353 | 8.44783757595320139444e+02, /* 0x408A6645, 0x22B3BF22 */ | ||
| 354 | 8.82935845112488550512e+02, /* 0x408B977C, 0x9C5CC214 */ | ||
| 355 | 2.12666388511798828631e+02, /* 0x406A9553, 0x0E001365 */ | ||
| 356 | -5.31095493882666946917e+00, /* 0xC0153E6A, 0xF8B32931 */ | ||
| 357 | }; | ||
| 358 | |||
| 359 | static double qzero(double x) | ||
| 360 | { | ||
| 361 | 	const double *p,*q; | ||
| 362 | 	double_t s,r,z; | ||
| 363 | 	uint32_t ix; | ||
| 364 | |||
| 365 | 	GET_HIGH_WORD(ix, x); | ||
| 366 | 	ix &= 0x7fffffff; | ||
| 367 | 	if (ix >= 0x40200000){p = qR8; q = qS8;} | ||
| 368 | 	else if (ix >= 0x40122E8B){p = qR5; q = qS5;} | ||
| 369 | 	else if (ix >= 0x4006DB6D){p = qR3; q = qS3;} | ||
| 370 | 	else /*ix >= 0x40000000*/ {p = qR2; q = qS2;} | ||
| 371 | 	z = 1.0/(x*x); | ||
| 372 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 373 | 	s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); | ||
| 374 | 	return (-.125 + r/s)/x; | ||
| 375 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/j0f.c created+314| ... | @@ -0,0 +1,314 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_j0f.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #define _GNU_SOURCE | ||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | static float pzerof(float), qzerof(float); | ||
| 20 | |||
| 21 | static const float | ||
| 22 | invsqrtpi = 5.6418961287e-01, /* 0x3f106ebb */ | ||
| 23 | tpi = 6.3661974669e-01; /* 0x3f22f983 */ | ||
| 24 | |||
| 25 | static float common(uint32_t ix, float x, int y0) | ||
| 26 | { | ||
| 27 | 	float z,s,c,ss,cc; | ||
| 28 | 	/* | ||
| 29 | 	 * j0(x) = 1/sqrt(pi) * (P(0,x)*cc - Q(0,x)*ss) / sqrt(x) | ||
| 30 | 	 * y0(x) = 1/sqrt(pi) * (P(0,x)*ss + Q(0,x)*cc) / sqrt(x) | ||
| 31 | 	 */ | ||
| 32 | 	s = sinf(x); | ||
| 33 | 	c = cosf(x); | ||
| 34 | 	if (y0) | ||
| 35 | 		c = -c; | ||
| 36 | 	cc = s+c; | ||
| 37 | 	if (ix < 0x7f000000) { | ||
| 38 | 		ss = s-c; | ||
| 39 | 		z = -cosf(2*x); | ||
| 40 | 		if (s*c < 0) | ||
| 41 | 			cc = z/ss; | ||
| 42 | 		else | ||
| 43 | 			ss = z/cc; | ||
| 44 | 		if (ix < 0x58800000) { | ||
| 45 | 			if (y0) | ||
| 46 | 				ss = -ss; | ||
| 47 | 			cc = pzerof(x)*cc-qzerof(x)*ss; | ||
| 48 | 		} | ||
| 49 | 	} | ||
| 50 | 	return invsqrtpi*cc/sqrtf(x); | ||
| 51 | } | ||
| 52 | |||
| 53 | /* R0/S0 on [0, 2.00] */ | ||
| 54 | static const float | ||
| 55 | R02 = 1.5625000000e-02, /* 0x3c800000 */ | ||
| 56 | R03 = -1.8997929874e-04, /* 0xb947352e */ | ||
| 57 | R04 = 1.8295404516e-06, /* 0x35f58e88 */ | ||
| 58 | R05 = -4.6183270541e-09, /* 0xb19eaf3c */ | ||
| 59 | S01 = 1.5619102865e-02, /* 0x3c7fe744 */ | ||
| 60 | S02 = 1.1692678527e-04, /* 0x38f53697 */ | ||
| 61 | S03 = 5.1354652442e-07, /* 0x3509daa6 */ | ||
| 62 | S04 = 1.1661400734e-09; /* 0x30a045e8 */ | ||
| 63 | |||
| 64 | float j0f(float x) | ||
| 65 | { | ||
| 66 | 	float z,r,s; | ||
| 67 | 	uint32_t ix; | ||
| 68 | |||
| 69 | 	GET_FLOAT_WORD(ix, x); | ||
| 70 | 	ix &= 0x7fffffff; | ||
| 71 | 	if (ix >= 0x7f800000) | ||
| 72 | 		return 1/(x*x); | ||
| 73 | 	x = fabsf(x); | ||
| 74 | |||
| 75 | 	if (ix >= 0x40000000) { /* |x| >= 2 */ | ||
| 76 | 		/* large ulp error near zeros */ | ||
| 77 | 		return common(ix, x, 0); | ||
| 78 | 	} | ||
| 79 | 	if (ix >= 0x3a000000) { /* |x| >= 2**-11 */ | ||
| 80 | 		/* up to 4ulp error near 2 */ | ||
| 81 | 		z = x*x; | ||
| 82 | 		r = z*(R02+z*(R03+z*(R04+z*R05))); | ||
| 83 | 		s = 1+z*(S01+z*(S02+z*(S03+z*S04))); | ||
| 84 | 		return (1+x/2)*(1-x/2) + z*(r/s); | ||
| 85 | 	} | ||
| 86 | 	if (ix >= 0x21800000) /* |x| >= 2**-60 */ | ||
| 87 | 		x = 0.25f*x*x; | ||
| 88 | 	return 1 - x; | ||
| 89 | } | ||
| 90 | |||
| 91 | static const float | ||
| 92 | u00 = -7.3804296553e-02, /* 0xbd9726b5 */ | ||
| 93 | u01 = 1.7666645348e-01, /* 0x3e34e80d */ | ||
| 94 | u02 = -1.3818567619e-02, /* 0xbc626746 */ | ||
| 95 | u03 = 3.4745343146e-04, /* 0x39b62a69 */ | ||
| 96 | u04 = -3.8140706238e-06, /* 0xb67ff53c */ | ||
| 97 | u05 = 1.9559013964e-08, /* 0x32a802ba */ | ||
| 98 | u06 = -3.9820518410e-11, /* 0xae2f21eb */ | ||
| 99 | v01 = 1.2730483897e-02, /* 0x3c509385 */ | ||
| 100 | v02 = 7.6006865129e-05, /* 0x389f65e0 */ | ||
| 101 | v03 = 2.5915085189e-07, /* 0x348b216c */ | ||
| 102 | v04 = 4.4111031494e-10; /* 0x2ff280c2 */ | ||
| 103 | |||
| 104 | float y0f(float x) | ||
| 105 | { | ||
| 106 | 	float z,u,v; | ||
| 107 | 	uint32_t ix; | ||
| 108 | |||
| 109 | 	GET_FLOAT_WORD(ix, x); | ||
| 110 | 	if ((ix & 0x7fffffff) == 0) | ||
| 111 | 		return -1/0.0f; | ||
| 112 | 	if (ix>>31) | ||
| 113 | 		return 0/0.0f; | ||
| 114 | 	if (ix >= 0x7f800000) | ||
| 115 | 		return 1/x; | ||
| 116 | 	if (ix >= 0x40000000) { /* |x| >= 2.0 */ | ||
| 117 | 		/* large ulp error near zeros */ | ||
| 118 | 		return common(ix,x,1); | ||
| 119 | 	} | ||
| 120 | 	if (ix >= 0x39000000) { /* x >= 2**-13 */ | ||
| 121 | 		/* large ulp error at x ~= 0.89 */ | ||
| 122 | 		z = x*x; | ||
| 123 | 		u = u00+z*(u01+z*(u02+z*(u03+z*(u04+z*(u05+z*u06))))); | ||
| 124 | 		v = 1+z*(v01+z*(v02+z*(v03+z*v04))); | ||
| 125 | 		return u/v + tpi*(j0f(x)*logf(x)); | ||
| 126 | 	} | ||
| 127 | 	return u00 + tpi*logf(x); | ||
| 128 | } | ||
| 129 | |||
| 130 | /* The asymptotic expansions of pzero is | ||
| 131 | * 1 - 9/128 s^2 + 11025/98304 s^4 - ..., where s = 1/x. | ||
| 132 | * For x >= 2, We approximate pzero by | ||
| 133 | * pzero(x) = 1 + (R/S) | ||
| 134 | * where R = pR0 + pR1*s^2 + pR2*s^4 + ... + pR5*s^10 | ||
| 135 | * S = 1 + pS0*s^2 + ... + pS4*s^10 | ||
| 136 | * and | ||
| 137 | * | pzero(x)-1-R/S | <= 2 ** ( -60.26) | ||
| 138 | */ | ||
| 139 | static const float pR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 140 | 0.0000000000e+00, /* 0x00000000 */ | ||
| 141 | -7.0312500000e-02, /* 0xbd900000 */ | ||
| 142 | -8.0816707611e+00, /* 0xc1014e86 */ | ||
| 143 | -2.5706311035e+02, /* 0xc3808814 */ | ||
| 144 | -2.4852163086e+03, /* 0xc51b5376 */ | ||
| 145 | -5.2530439453e+03, /* 0xc5a4285a */ | ||
| 146 | }; | ||
| 147 | static const float pS8[5] = { | ||
| 148 | 1.1653436279e+02, /* 0x42e91198 */ | ||
| 149 | 3.8337448730e+03, /* 0x456f9beb */ | ||
| 150 | 4.0597855469e+04, /* 0x471e95db */ | ||
| 151 | 1.1675296875e+05, /* 0x47e4087c */ | ||
| 152 | 4.7627726562e+04, /* 0x473a0bba */ | ||
| 153 | }; | ||
| 154 | static const float pR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 155 | -1.1412546255e-11, /* 0xad48c58a */ | ||
| 156 | -7.0312492549e-02, /* 0xbd8fffff */ | ||
| 157 | -4.1596107483e+00, /* 0xc0851b88 */ | ||
| 158 | -6.7674766541e+01, /* 0xc287597b */ | ||
| 159 | -3.3123129272e+02, /* 0xc3a59d9b */ | ||
| 160 | -3.4643338013e+02, /* 0xc3ad3779 */ | ||
| 161 | }; | ||
| 162 | static const float pS5[5] = { | ||
| 163 | 6.0753936768e+01, /* 0x42730408 */ | ||
| 164 | 1.0512523193e+03, /* 0x44836813 */ | ||
| 165 | 5.9789707031e+03, /* 0x45bad7c4 */ | ||
| 166 | 9.6254453125e+03, /* 0x461665c8 */ | ||
| 167 | 2.4060581055e+03, /* 0x451660ee */ | ||
| 168 | }; | ||
| 169 | |||
| 170 | static const float pR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ | ||
| 171 | -2.5470459075e-09, /* 0xb12f081b */ | ||
| 172 | -7.0311963558e-02, /* 0xbd8fffb8 */ | ||
| 173 | -2.4090321064e+00, /* 0xc01a2d95 */ | ||
| 174 | -2.1965976715e+01, /* 0xc1afba52 */ | ||
| 175 | -5.8079170227e+01, /* 0xc2685112 */ | ||
| 176 | -3.1447946548e+01, /* 0xc1fb9565 */ | ||
| 177 | }; | ||
| 178 | static const float pS3[5] = { | ||
| 179 | 3.5856033325e+01, /* 0x420f6c94 */ | ||
| 180 | 3.6151397705e+02, /* 0x43b4c1ca */ | ||
| 181 | 1.1936077881e+03, /* 0x44953373 */ | ||
| 182 | 1.1279968262e+03, /* 0x448cffe6 */ | ||
| 183 | 1.7358093262e+02, /* 0x432d94b8 */ | ||
| 184 | }; | ||
| 185 | |||
| 186 | static const float pR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 187 | -8.8753431271e-08, /* 0xb3be98b7 */ | ||
| 188 | -7.0303097367e-02, /* 0xbd8ffb12 */ | ||
| 189 | -1.4507384300e+00, /* 0xbfb9b1cc */ | ||
| 190 | -7.6356959343e+00, /* 0xc0f4579f */ | ||
| 191 | -1.1193166733e+01, /* 0xc1331736 */ | ||
| 192 | -3.2336456776e+00, /* 0xc04ef40d */ | ||
| 193 | }; | ||
| 194 | static const float pS2[5] = { | ||
| 195 | 2.2220300674e+01, /* 0x41b1c32d */ | ||
| 196 | 1.3620678711e+02, /* 0x430834f0 */ | ||
| 197 | 2.7047027588e+02, /* 0x43873c32 */ | ||
| 198 | 1.5387539673e+02, /* 0x4319e01a */ | ||
| 199 | 1.4657617569e+01, /* 0x416a859a */ | ||
| 200 | }; | ||
| 201 | |||
| 202 | static float pzerof(float x) | ||
| 203 | { | ||
| 204 | 	const float *p,*q; | ||
| 205 | 	float_t z,r,s; | ||
| 206 | 	uint32_t ix; | ||
| 207 | |||
| 208 | 	GET_FLOAT_WORD(ix, x); | ||
| 209 | 	ix &= 0x7fffffff; | ||
| 210 | 	if (ix >= 0x41000000){p = pR8; q = pS8;} | ||
| 211 | 	else if (ix >= 0x409173eb){p = pR5; q = pS5;} | ||
| 212 | 	else if (ix >= 0x4036d917){p = pR3; q = pS3;} | ||
| 213 | 	else /*ix >= 0x40000000*/ {p = pR2; q = pS2;} | ||
| 214 | 	z = 1.0f/(x*x); | ||
| 215 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 216 | 	s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); | ||
| 217 | 	return 1.0f + r/s; | ||
| 218 | } | ||
| 219 | |||
| 220 | |||
| 221 | /* For x >= 8, the asymptotic expansions of qzero is | ||
| 222 | * -1/8 s + 75/1024 s^3 - ..., where s = 1/x. | ||
| 223 | * We approximate pzero by | ||
| 224 | * qzero(x) = s*(-1.25 + (R/S)) | ||
| 225 | * where R = qR0 + qR1*s^2 + qR2*s^4 + ... + qR5*s^10 | ||
| 226 | * S = 1 + qS0*s^2 + ... + qS5*s^12 | ||
| 227 | * and | ||
| 228 | * | qzero(x)/s +1.25-R/S | <= 2 ** ( -61.22) | ||
| 229 | */ | ||
| 230 | static const float qR8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 231 | 0.0000000000e+00, /* 0x00000000 */ | ||
| 232 | 7.3242187500e-02, /* 0x3d960000 */ | ||
| 233 | 1.1768206596e+01, /* 0x413c4a93 */ | ||
| 234 | 5.5767340088e+02, /* 0x440b6b19 */ | ||
| 235 | 8.8591972656e+03, /* 0x460a6cca */ | ||
| 236 | 3.7014625000e+04, /* 0x471096a0 */ | ||
| 237 | }; | ||
| 238 | static const float qS8[6] = { | ||
| 239 | 1.6377603149e+02, /* 0x4323c6aa */ | ||
| 240 | 8.0983447266e+03, /* 0x45fd12c2 */ | ||
| 241 | 1.4253829688e+05, /* 0x480b3293 */ | ||
| 242 | 8.0330925000e+05, /* 0x49441ed4 */ | ||
| 243 | 8.4050156250e+05, /* 0x494d3359 */ | ||
| 244 | -3.4389928125e+05, /* 0xc8a7eb69 */ | ||
| 245 | }; | ||
| 246 | |||
| 247 | static const float qR5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 248 | 1.8408595828e-11, /* 0x2da1ec79 */ | ||
| 249 | 7.3242180049e-02, /* 0x3d95ffff */ | ||
| 250 | 5.8356351852e+00, /* 0x40babd86 */ | ||
| 251 | 1.3511157227e+02, /* 0x43071c90 */ | ||
| 252 | 1.0272437744e+03, /* 0x448067cd */ | ||
| 253 | 1.9899779053e+03, /* 0x44f8bf4b */ | ||
| 254 | }; | ||
| 255 | static const float qS5[6] = { | ||
| 256 | 8.2776611328e+01, /* 0x42a58da0 */ | ||
| 257 | 2.0778142090e+03, /* 0x4501dd07 */ | ||
| 258 | 1.8847289062e+04, /* 0x46933e94 */ | ||
| 259 | 5.6751113281e+04, /* 0x475daf1d */ | ||
| 260 | 3.5976753906e+04, /* 0x470c88c1 */ | ||
| 261 | -5.3543427734e+03, /* 0xc5a752be */ | ||
| 262 | }; | ||
| 263 | |||
| 264 | static const float qR3[6] = {/* for x in [4.547,2.8571]=1/[0.2199,0.35001] */ | ||
| 265 | 4.3774099900e-09, /* 0x3196681b */ | ||
| 266 | 7.3241114616e-02, /* 0x3d95ff70 */ | ||
| 267 | 3.3442313671e+00, /* 0x405607e3 */ | ||
| 268 | 4.2621845245e+01, /* 0x422a7cc5 */ | ||
| 269 | 1.7080809021e+02, /* 0x432acedf */ | ||
| 270 | 1.6673394775e+02, /* 0x4326bbe4 */ | ||
| 271 | }; | ||
| 272 | static const float qS3[6] = { | ||
| 273 | 4.8758872986e+01, /* 0x42430916 */ | ||
| 274 | 7.0968920898e+02, /* 0x44316c1c */ | ||
| 275 | 3.7041481934e+03, /* 0x4567825f */ | ||
| 276 | 6.4604252930e+03, /* 0x45c9e367 */ | ||
| 277 | 2.5163337402e+03, /* 0x451d4557 */ | ||
| 278 | -1.4924745178e+02, /* 0xc3153f59 */ | ||
| 279 | }; | ||
| 280 | |||
| 281 | static const float qR2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 282 | 1.5044444979e-07, /* 0x342189db */ | ||
| 283 | 7.3223426938e-02, /* 0x3d95f62a */ | ||
| 284 | 1.9981917143e+00, /* 0x3fffc4bf */ | ||
| 285 | 1.4495602608e+01, /* 0x4167edfd */ | ||
| 286 | 3.1666231155e+01, /* 0x41fd5471 */ | ||
| 287 | 1.6252708435e+01, /* 0x4182058c */ | ||
| 288 | }; | ||
| 289 | static const float qS2[6] = { | ||
| 290 | 3.0365585327e+01, /* 0x41f2ecb8 */ | ||
| 291 | 2.6934811401e+02, /* 0x4386ac8f */ | ||
| 292 | 8.4478375244e+02, /* 0x44533229 */ | ||
| 293 | 8.8293585205e+02, /* 0x445cbbe5 */ | ||
| 294 | 2.1266638184e+02, /* 0x4354aa98 */ | ||
| 295 | -5.3109550476e+00, /* 0xc0a9f358 */ | ||
| 296 | }; | ||
| 297 | |||
| 298 | static float qzerof(float x) | ||
| 299 | { | ||
| 300 | 	const float *p,*q; | ||
| 301 | 	float_t s,r,z; | ||
| 302 | 	uint32_t ix; | ||
| 303 | |||
| 304 | 	GET_FLOAT_WORD(ix, x); | ||
| 305 | 	ix &= 0x7fffffff; | ||
| 306 | 	if (ix >= 0x41000000){p = qR8; q = qS8;} | ||
| 307 | 	else if (ix >= 0x409173eb){p = qR5; q = qS5;} | ||
| 308 | 	else if (ix >= 0x4036d917){p = qR3; q = qS3;} | ||
| 309 | 	else /*ix >= 0x40000000*/ {p = qR2; q = qS2;} | ||
| 310 | 	z = 1.0f/(x*x); | ||
| 311 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 312 | 	s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); | ||
| 313 | 	return (-.125f + r/s)/x; | ||
| 314 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/j1.c created+362| ... | @@ -0,0 +1,362 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_j1.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 | /* j1(x), y1(x) | ||
| 13 | * Bessel function of the first and second kinds of order zero. | ||
| 14 | * Method -- j1(x): | ||
| 15 | * 1. For tiny x, we use j1(x) = x/2 - x^3/16 + x^5/384 - ... | ||
| 16 | * 2. Reduce x to |x| since j1(x)=-j1(-x), and | ||
| 17 | * for x in (0,2) | ||
| 18 | * j1(x) = x/2 + x*z*R0/S0, where z = x*x; | ||
| 19 | * (precision: |j1/x - 1/2 - R0/S0 |<2**-61.51 ) | ||
| 20 | * for x in (2,inf) | ||
| 21 | * j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x1)-q1(x)*sin(x1)) | ||
| 22 | * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1)) | ||
| 23 | * where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1) | ||
| 24 | * as follow: | ||
| 25 | * cos(x1) = cos(x)cos(3pi/4)+sin(x)sin(3pi/4) | ||
| 26 | * = 1/sqrt(2) * (sin(x) - cos(x)) | ||
| 27 | * sin(x1) = sin(x)cos(3pi/4)-cos(x)sin(3pi/4) | ||
| 28 | * = -1/sqrt(2) * (sin(x) + cos(x)) | ||
| 29 | * (To avoid cancellation, use | ||
| 30 | * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) | ||
| 31 | * to compute the worse one.) | ||
| 32 | * | ||
| 33 | * 3 Special cases | ||
| 34 | * j1(nan)= nan | ||
| 35 | * j1(0) = 0 | ||
| 36 | * j1(inf) = 0 | ||
| 37 | * | ||
| 38 | * Method -- y1(x): | ||
| 39 | * 1. screen out x<=0 cases: y1(0)=-inf, y1(x<0)=NaN | ||
| 40 | * 2. For x<2. | ||
| 41 | * Since | ||
| 42 | * y1(x) = 2/pi*(j1(x)*(ln(x/2)+Euler)-1/x-x/2+5/64*x^3-...) | ||
| 43 | * therefore y1(x)-2/pi*j1(x)*ln(x)-1/x is an odd function. | ||
| 44 | * We use the following function to approximate y1, | ||
| 45 | * y1(x) = x*U(z)/V(z) + (2/pi)*(j1(x)*ln(x)-1/x), z= x^2 | ||
| 46 | * where for x in [0,2] (abs err less than 2**-65.89) | ||
| 47 | * U(z) = U0[0] + U0[1]*z + ... + U0[4]*z^4 | ||
| 48 | * V(z) = 1 + v0[0]*z + ... + v0[4]*z^5 | ||
| 49 | * Note: For tiny x, 1/x dominate y1 and hence | ||
| 50 | * y1(tiny) = -2/pi/tiny, (choose tiny<2**-54) | ||
| 51 | * 3. For x>=2. | ||
| 52 | * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x1)+q1(x)*cos(x1)) | ||
| 53 | * where x1 = x-3*pi/4. It is better to compute sin(x1),cos(x1) | ||
| 54 | * by method mentioned above. | ||
| 55 | */ | ||
| 56 | |||
| 57 | #include "libm.h" | ||
| 58 | |||
| 59 | static double pone(double), qone(double); | ||
| 60 | |||
| 61 | static const double | ||
| 62 | invsqrtpi = 5.64189583547756279280e-01, /* 0x3FE20DD7, 0x50429B6D */ | ||
| 63 | tpi = 6.36619772367581382433e-01; /* 0x3FE45F30, 0x6DC9C883 */ | ||
| 64 | |||
| 65 | static double common(uint32_t ix, double x, int y1, int sign) | ||
| 66 | { | ||
| 67 | 	double z,s,c,ss,cc; | ||
| 68 | |||
| 69 | 	/* | ||
| 70 | 	 * j1(x) = sqrt(2/(pi*x))*(p1(x)*cos(x-3pi/4)-q1(x)*sin(x-3pi/4)) | ||
| 71 | 	 * y1(x) = sqrt(2/(pi*x))*(p1(x)*sin(x-3pi/4)+q1(x)*cos(x-3pi/4)) | ||
| 72 | 	 * | ||
| 73 | 	 * sin(x-3pi/4) = -(sin(x) + cos(x))/sqrt(2) | ||
| 74 | 	 * cos(x-3pi/4) = (sin(x) - cos(x))/sqrt(2) | ||
| 75 | 	 * sin(x) +- cos(x) = -cos(2x)/(sin(x) -+ cos(x)) | ||
| 76 | 	 */ | ||
| 77 | 	s = sin(x); | ||
| 78 | 	if (y1) | ||
| 79 | 		s = -s; | ||
| 80 | 	c = cos(x); | ||
| 81 | 	cc = s-c; | ||
| 82 | 	if (ix < 0x7fe00000) { | ||
| 83 | 		/* avoid overflow in 2*x */ | ||
| 84 | 		ss = -s-c; | ||
| 85 | 		z = cos(2*x); | ||
| 86 | 		if (s*c > 0) | ||
| 87 | 			cc = z/ss; | ||
| 88 | 		else | ||
| 89 | 			ss = z/cc; | ||
| 90 | 		if (ix < 0x48000000) { | ||
| 91 | 			if (y1) | ||
| 92 | 				ss = -ss; | ||
| 93 | 			cc = pone(x)*cc-qone(x)*ss; | ||
| 94 | 		} | ||
| 95 | 	} | ||
| 96 | 	if (sign) | ||
| 97 | 		cc = -cc; | ||
| 98 | 	return invsqrtpi*cc/sqrt(x); | ||
| 99 | } | ||
| 100 | |||
| 101 | /* R0/S0 on [0,2] */ | ||
| 102 | static const double | ||
| 103 | r00 = -6.25000000000000000000e-02, /* 0xBFB00000, 0x00000000 */ | ||
| 104 | r01 = 1.40705666955189706048e-03, /* 0x3F570D9F, 0x98472C61 */ | ||
| 105 | r02 = -1.59955631084035597520e-05, /* 0xBEF0C5C6, 0xBA169668 */ | ||
| 106 | r03 = 4.96727999609584448412e-08, /* 0x3E6AAAFA, 0x46CA0BD9 */ | ||
| 107 | s01 = 1.91537599538363460805e-02, /* 0x3F939D0B, 0x12637E53 */ | ||
| 108 | s02 = 1.85946785588630915560e-04, /* 0x3F285F56, 0xB9CDF664 */ | ||
| 109 | s03 = 1.17718464042623683263e-06, /* 0x3EB3BFF8, 0x333F8498 */ | ||
| 110 | s04 = 5.04636257076217042715e-09, /* 0x3E35AC88, 0xC97DFF2C */ | ||
| 111 | s05 = 1.23542274426137913908e-11; /* 0x3DAB2ACF, 0xCFB97ED8 */ | ||
| 112 | |||
| 113 | double j1(double x) | ||
| 114 | { | ||
| 115 | 	double z,r,s; | ||
| 116 | 	uint32_t ix; | ||
| 117 | 	int sign; | ||
| 118 | |||
| 119 | 	GET_HIGH_WORD(ix, x); | ||
| 120 | 	sign = ix>>31; | ||
| 121 | 	ix &= 0x7fffffff; | ||
| 122 | 	if (ix >= 0x7ff00000) | ||
| 123 | 		return 1/(x*x); | ||
| 124 | 	if (ix >= 0x40000000) /* |x| >= 2 */ | ||
| 125 | 		return common(ix, fabs(x), 0, sign); | ||
| 126 | 	if (ix >= 0x38000000) { /* |x| >= 2**-127 */ | ||
| 127 | 		z = x*x; | ||
| 128 | 		r = z*(r00+z*(r01+z*(r02+z*r03))); | ||
| 129 | 		s = 1+z*(s01+z*(s02+z*(s03+z*(s04+z*s05)))); | ||
| 130 | 		z = r/s; | ||
| 131 | 	} else | ||
| 132 | 		/* avoid underflow, raise inexact if x!=0 */ | ||
| 133 | 		z = x; | ||
| 134 | 	return (0.5 + z)*x; | ||
| 135 | } | ||
| 136 | |||
| 137 | static const double U0[5] = { | ||
| 138 | -1.96057090646238940668e-01, /* 0xBFC91866, 0x143CBC8A */ | ||
| 139 | 5.04438716639811282616e-02, /* 0x3FA9D3C7, 0x76292CD1 */ | ||
| 140 | -1.91256895875763547298e-03, /* 0xBF5F55E5, 0x4844F50F */ | ||
| 141 | 2.35252600561610495928e-05, /* 0x3EF8AB03, 0x8FA6B88E */ | ||
| 142 | -9.19099158039878874504e-08, /* 0xBE78AC00, 0x569105B8 */ | ||
| 143 | }; | ||
| 144 | static const double V0[5] = { | ||
| 145 | 1.99167318236649903973e-02, /* 0x3F94650D, 0x3F4DA9F0 */ | ||
| 146 | 2.02552581025135171496e-04, /* 0x3F2A8C89, 0x6C257764 */ | ||
| 147 | 1.35608801097516229404e-06, /* 0x3EB6C05A, 0x894E8CA6 */ | ||
| 148 | 6.22741452364621501295e-09, /* 0x3E3ABF1D, 0x5BA69A86 */ | ||
| 149 | 1.66559246207992079114e-11, /* 0x3DB25039, 0xDACA772A */ | ||
| 150 | }; | ||
| 151 | |||
| 152 | double y1(double x) | ||
| 153 | { | ||
| 154 | 	double z,u,v; | ||
| 155 | 	uint32_t ix,lx; | ||
| 156 | |||
| 157 | 	EXTRACT_WORDS(ix, lx, x); | ||
| 158 | 	/* y1(nan)=nan, y1(<0)=nan, y1(0)=-inf, y1(inf)=0 */ | ||
| 159 | 	if ((ix<<1 | lx) == 0) | ||
| 160 | 		return -1/0.0; | ||
| 161 | 	if (ix>>31) | ||
| 162 | 		return 0/0.0; | ||
| 163 | 	if (ix >= 0x7ff00000) | ||
| 164 | 		return 1/x; | ||
| 165 | |||
| 166 | 	if (ix >= 0x40000000) /* x >= 2 */ | ||
| 167 | 		return common(ix, x, 1, 0); | ||
| 168 | 	if (ix < 0x3c900000) /* x < 2**-54 */ | ||
| 169 | 		return -tpi/x; | ||
| 170 | 	z = x*x; | ||
| 171 | 	u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); | ||
| 172 | 	v = 1+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); | ||
| 173 | 	return x*(u/v) + tpi*(j1(x)*log(x)-1/x); | ||
| 174 | } | ||
| 175 | |||
| 176 | /* For x >= 8, the asymptotic expansions of pone is | ||
| 177 | * 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x. | ||
| 178 | * We approximate pone by | ||
| 179 | * pone(x) = 1 + (R/S) | ||
| 180 | * where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10 | ||
| 181 | * S = 1 + ps0*s^2 + ... + ps4*s^10 | ||
| 182 | * and | ||
| 183 | * | pone(x)-1-R/S | <= 2 ** ( -60.06) | ||
| 184 | */ | ||
| 185 | |||
| 186 | static const double pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 187 | 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ | ||
| 188 | 1.17187499999988647970e-01, /* 0x3FBDFFFF, 0xFFFFFCCE */ | ||
| 189 | 1.32394806593073575129e+01, /* 0x402A7A9D, 0x357F7FCE */ | ||
| 190 | 4.12051854307378562225e+02, /* 0x4079C0D4, 0x652EA590 */ | ||
| 191 | 3.87474538913960532227e+03, /* 0x40AE457D, 0xA3A532CC */ | ||
| 192 | 7.91447954031891731574e+03, /* 0x40BEEA7A, 0xC32782DD */ | ||
| 193 | }; | ||
| 194 | static const double ps8[5] = { | ||
| 195 | 1.14207370375678408436e+02, /* 0x405C8D45, 0x8E656CAC */ | ||
| 196 | 3.65093083420853463394e+03, /* 0x40AC85DC, 0x964D274F */ | ||
| 197 | 3.69562060269033463555e+04, /* 0x40E20B86, 0x97C5BB7F */ | ||
| 198 | 9.76027935934950801311e+04, /* 0x40F7D42C, 0xB28F17BB */ | ||
| 199 | 3.08042720627888811578e+04, /* 0x40DE1511, 0x697A0B2D */ | ||
| 200 | }; | ||
| 201 | |||
| 202 | static const double pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 203 | 1.31990519556243522749e-11, /* 0x3DAD0667, 0xDAE1CA7D */ | ||
| 204 | 1.17187493190614097638e-01, /* 0x3FBDFFFF, 0xE2C10043 */ | ||
| 205 | 6.80275127868432871736e+00, /* 0x401B3604, 0x6E6315E3 */ | ||
| 206 | 1.08308182990189109773e+02, /* 0x405B13B9, 0x452602ED */ | ||
| 207 | 5.17636139533199752805e+02, /* 0x40802D16, 0xD052D649 */ | ||
| 208 | 5.28715201363337541807e+02, /* 0x408085B8, 0xBB7E0CB7 */ | ||
| 209 | }; | ||
| 210 | static const double ps5[5] = { | ||
| 211 | 5.92805987221131331921e+01, /* 0x404DA3EA, 0xA8AF633D */ | ||
| 212 | 9.91401418733614377743e+02, /* 0x408EFB36, 0x1B066701 */ | ||
| 213 | 5.35326695291487976647e+03, /* 0x40B4E944, 0x5706B6FB */ | ||
| 214 | 7.84469031749551231769e+03, /* 0x40BEA4B0, 0xB8A5BB15 */ | ||
| 215 | 1.50404688810361062679e+03, /* 0x40978030, 0x036F5E51 */ | ||
| 216 | }; | ||
| 217 | |||
| 218 | static const double pr3[6] = { | ||
| 219 | 3.02503916137373618024e-09, /* 0x3E29FC21, 0xA7AD9EDD */ | ||
| 220 | 1.17186865567253592491e-01, /* 0x3FBDFFF5, 0x5B21D17B */ | ||
| 221 | 3.93297750033315640650e+00, /* 0x400F76BC, 0xE85EAD8A */ | ||
| 222 | 3.51194035591636932736e+01, /* 0x40418F48, 0x9DA6D129 */ | ||
| 223 | 9.10550110750781271918e+01, /* 0x4056C385, 0x4D2C1837 */ | ||
| 224 | 4.85590685197364919645e+01, /* 0x4048478F, 0x8EA83EE5 */ | ||
| 225 | }; | ||
| 226 | static const double ps3[5] = { | ||
| 227 | 3.47913095001251519989e+01, /* 0x40416549, 0xA134069C */ | ||
| 228 | 3.36762458747825746741e+02, /* 0x40750C33, 0x07F1A75F */ | ||
| 229 | 1.04687139975775130551e+03, /* 0x40905B7C, 0x5037D523 */ | ||
| 230 | 8.90811346398256432622e+02, /* 0x408BD67D, 0xA32E31E9 */ | ||
| 231 | 1.03787932439639277504e+02, /* 0x4059F26D, 0x7C2EED53 */ | ||
| 232 | }; | ||
| 233 | |||
| 234 | static const double pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 235 | 1.07710830106873743082e-07, /* 0x3E7CE9D4, 0xF65544F4 */ | ||
| 236 | 1.17176219462683348094e-01, /* 0x3FBDFF42, 0xBE760D83 */ | ||
| 237 | 2.36851496667608785174e+00, /* 0x4002F2B7, 0xF98FAEC0 */ | ||
| 238 | 1.22426109148261232917e+01, /* 0x40287C37, 0x7F71A964 */ | ||
| 239 | 1.76939711271687727390e+01, /* 0x4031B1A8, 0x177F8EE2 */ | ||
| 240 | 5.07352312588818499250e+00, /* 0x40144B49, 0xA574C1FE */ | ||
| 241 | }; | ||
| 242 | static const double ps2[5] = { | ||
| 243 | 2.14364859363821409488e+01, /* 0x40356FBD, 0x8AD5ECDC */ | ||
| 244 | 1.25290227168402751090e+02, /* 0x405F5293, 0x14F92CD5 */ | ||
| 245 | 2.32276469057162813669e+02, /* 0x406D08D8, 0xD5A2DBD9 */ | ||
| 246 | 1.17679373287147100768e+02, /* 0x405D6B7A, 0xDA1884A9 */ | ||
| 247 | 8.36463893371618283368e+00, /* 0x4020BAB1, 0xF44E5192 */ | ||
| 248 | }; | ||
| 249 | |||
| 250 | static double pone(double x) | ||
| 251 | { | ||
| 252 | 	const double *p,*q; | ||
| 253 | 	double_t z,r,s; | ||
| 254 | 	uint32_t ix; | ||
| 255 | |||
| 256 | 	GET_HIGH_WORD(ix, x); | ||
| 257 | 	ix &= 0x7fffffff; | ||
| 258 | 	if (ix >= 0x40200000){p = pr8; q = ps8;} | ||
| 259 | 	else if (ix >= 0x40122E8B){p = pr5; q = ps5;} | ||
| 260 | 	else if (ix >= 0x4006DB6D){p = pr3; q = ps3;} | ||
| 261 | 	else /*ix >= 0x40000000*/ {p = pr2; q = ps2;} | ||
| 262 | 	z = 1.0/(x*x); | ||
| 263 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 264 | 	s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); | ||
| 265 | 	return 1.0+ r/s; | ||
| 266 | } | ||
| 267 | |||
| 268 | /* For x >= 8, the asymptotic expansions of qone is | ||
| 269 | * 3/8 s - 105/1024 s^3 - ..., where s = 1/x. | ||
| 270 | * We approximate pone by | ||
| 271 | * qone(x) = s*(0.375 + (R/S)) | ||
| 272 | * where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10 | ||
| 273 | * S = 1 + qs1*s^2 + ... + qs6*s^12 | ||
| 274 | * and | ||
| 275 | * | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13) | ||
| 276 | */ | ||
| 277 | |||
| 278 | static const double qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 279 | 0.00000000000000000000e+00, /* 0x00000000, 0x00000000 */ | ||
| 280 | -1.02539062499992714161e-01, /* 0xBFBA3FFF, 0xFFFFFDF3 */ | ||
| 281 | -1.62717534544589987888e+01, /* 0xC0304591, 0xA26779F7 */ | ||
| 282 | -7.59601722513950107896e+02, /* 0xC087BCD0, 0x53E4B576 */ | ||
| 283 | -1.18498066702429587167e+04, /* 0xC0C724E7, 0x40F87415 */ | ||
| 284 | -4.84385124285750353010e+04, /* 0xC0E7A6D0, 0x65D09C6A */ | ||
| 285 | }; | ||
| 286 | static const double qs8[6] = { | ||
| 287 | 1.61395369700722909556e+02, /* 0x40642CA6, 0xDE5BCDE5 */ | ||
| 288 | 7.82538599923348465381e+03, /* 0x40BE9162, 0xD0D88419 */ | ||
| 289 | 1.33875336287249578163e+05, /* 0x4100579A, 0xB0B75E98 */ | ||
| 290 | 7.19657723683240939863e+05, /* 0x4125F653, 0x72869C19 */ | ||
| 291 | 6.66601232617776375264e+05, /* 0x412457D2, 0x7719AD5C */ | ||
| 292 | -2.94490264303834643215e+05, /* 0xC111F969, 0x0EA5AA18 */ | ||
| 293 | }; | ||
| 294 | |||
| 295 | static const double qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 296 | -2.08979931141764104297e-11, /* 0xBDB6FA43, 0x1AA1A098 */ | ||
| 297 | -1.02539050241375426231e-01, /* 0xBFBA3FFF, 0xCB597FEF */ | ||
| 298 | -8.05644828123936029840e+00, /* 0xC0201CE6, 0xCA03AD4B */ | ||
| 299 | -1.83669607474888380239e+02, /* 0xC066F56D, 0x6CA7B9B0 */ | ||
| 300 | -1.37319376065508163265e+03, /* 0xC09574C6, 0x6931734F */ | ||
| 301 | -2.61244440453215656817e+03, /* 0xC0A468E3, 0x88FDA79D */ | ||
| 302 | }; | ||
| 303 | static const double qs5[6] = { | ||
| 304 | 8.12765501384335777857e+01, /* 0x405451B2, 0xFF5A11B2 */ | ||
| 305 | 1.99179873460485964642e+03, /* 0x409F1F31, 0xE77BF839 */ | ||
| 306 | 1.74684851924908907677e+04, /* 0x40D10F1F, 0x0D64CE29 */ | ||
| 307 | 4.98514270910352279316e+04, /* 0x40E8576D, 0xAABAD197 */ | ||
| 308 | 2.79480751638918118260e+04, /* 0x40DB4B04, 0xCF7C364B */ | ||
| 309 | -4.71918354795128470869e+03, /* 0xC0B26F2E, 0xFCFFA004 */ | ||
| 310 | }; | ||
| 311 | |||
| 312 | static const double qr3[6] = { | ||
| 313 | -5.07831226461766561369e-09, /* 0xBE35CFA9, 0xD38FC84F */ | ||
| 314 | -1.02537829820837089745e-01, /* 0xBFBA3FEB, 0x51AEED54 */ | ||
| 315 | -4.61011581139473403113e+00, /* 0xC01270C2, 0x3302D9FF */ | ||
| 316 | -5.78472216562783643212e+01, /* 0xC04CEC71, 0xC25D16DA */ | ||
| 317 | -2.28244540737631695038e+02, /* 0xC06C87D3, 0x4718D55F */ | ||
| 318 | -2.19210128478909325622e+02, /* 0xC06B66B9, 0x5F5C1BF6 */ | ||
| 319 | }; | ||
| 320 | static const double qs3[6] = { | ||
| 321 | 4.76651550323729509273e+01, /* 0x4047D523, 0xCCD367E4 */ | ||
| 322 | 6.73865112676699709482e+02, /* 0x40850EEB, 0xC031EE3E */ | ||
| 323 | 3.38015286679526343505e+03, /* 0x40AA684E, 0x448E7C9A */ | ||
| 324 | 5.54772909720722782367e+03, /* 0x40B5ABBA, 0xA61D54A6 */ | ||
| 325 | 1.90311919338810798763e+03, /* 0x409DBC7A, 0x0DD4DF4B */ | ||
| 326 | -1.35201191444307340817e+02, /* 0xC060E670, 0x290A311F */ | ||
| 327 | }; | ||
| 328 | |||
| 329 | static const double qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 330 | -1.78381727510958865572e-07, /* 0xBE87F126, 0x44C626D2 */ | ||
| 331 | -1.02517042607985553460e-01, /* 0xBFBA3E8E, 0x9148B010 */ | ||
| 332 | -2.75220568278187460720e+00, /* 0xC0060484, 0x69BB4EDA */ | ||
| 333 | -1.96636162643703720221e+01, /* 0xC033A9E2, 0xC168907F */ | ||
| 334 | -4.23253133372830490089e+01, /* 0xC04529A3, 0xDE104AAA */ | ||
| 335 | -2.13719211703704061733e+01, /* 0xC0355F36, 0x39CF6E52 */ | ||
| 336 | }; | ||
| 337 | static const double qs2[6] = { | ||
| 338 | 2.95333629060523854548e+01, /* 0x403D888A, 0x78AE64FF */ | ||
| 339 | 2.52981549982190529136e+02, /* 0x406F9F68, 0xDB821CBA */ | ||
| 340 | 7.57502834868645436472e+02, /* 0x4087AC05, 0xCE49A0F7 */ | ||
| 341 | 7.39393205320467245656e+02, /* 0x40871B25, 0x48D4C029 */ | ||
| 342 | 1.55949003336666123687e+02, /* 0x40637E5E, 0x3C3ED8D4 */ | ||
| 343 | -4.95949898822628210127e+00, /* 0xC013D686, 0xE71BE86B */ | ||
| 344 | }; | ||
| 345 | |||
| 346 | static double qone(double x) | ||
| 347 | { | ||
| 348 | 	const double *p,*q; | ||
| 349 | 	double_t s,r,z; | ||
| 350 | 	uint32_t ix; | ||
| 351 | |||
| 352 | 	GET_HIGH_WORD(ix, x); | ||
| 353 | 	ix &= 0x7fffffff; | ||
| 354 | 	if (ix >= 0x40200000){p = qr8; q = qs8;} | ||
| 355 | 	else if (ix >= 0x40122E8B){p = qr5; q = qs5;} | ||
| 356 | 	else if (ix >= 0x4006DB6D){p = qr3; q = qs3;} | ||
| 357 | 	else /*ix >= 0x40000000*/ {p = qr2; q = qs2;} | ||
| 358 | 	z = 1.0/(x*x); | ||
| 359 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 360 | 	s = 1.0+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); | ||
| 361 | 	return (.375 + r/s)/x; | ||
| 362 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/j1f.c created+310| ... | @@ -0,0 +1,310 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_j1f.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #define _GNU_SOURCE | ||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | static float ponef(float), qonef(float); | ||
| 20 | |||
| 21 | static const float | ||
| 22 | invsqrtpi = 5.6418961287e-01, /* 0x3f106ebb */ | ||
| 23 | tpi = 6.3661974669e-01; /* 0x3f22f983 */ | ||
| 24 | |||
| 25 | static float common(uint32_t ix, float x, int y1, int sign) | ||
| 26 | { | ||
| 27 | 	double z,s,c,ss,cc; | ||
| 28 | |||
| 29 | 	s = sinf(x); | ||
| 30 | 	if (y1) | ||
| 31 | 		s = -s; | ||
| 32 | 	c = cosf(x); | ||
| 33 | 	cc = s-c; | ||
| 34 | 	if (ix < 0x7f000000) { | ||
| 35 | 		ss = -s-c; | ||
| 36 | 		z = cosf(2*x); | ||
| 37 | 		if (s*c > 0) | ||
| 38 | 			cc = z/ss; | ||
| 39 | 		else | ||
| 40 | 			ss = z/cc; | ||
| 41 | 		if (ix < 0x58800000) { | ||
| 42 | 			if (y1) | ||
| 43 | 				ss = -ss; | ||
| 44 | 			cc = ponef(x)*cc-qonef(x)*ss; | ||
| 45 | 		} | ||
| 46 | 	} | ||
| 47 | 	if (sign) | ||
| 48 | 		cc = -cc; | ||
| 49 | 	return invsqrtpi*cc/sqrtf(x); | ||
| 50 | } | ||
| 51 | |||
| 52 | /* R0/S0 on [0,2] */ | ||
| 53 | static const float | ||
| 54 | r00 = -6.2500000000e-02, /* 0xbd800000 */ | ||
| 55 | r01 = 1.4070566976e-03, /* 0x3ab86cfd */ | ||
| 56 | r02 = -1.5995563444e-05, /* 0xb7862e36 */ | ||
| 57 | r03 = 4.9672799207e-08, /* 0x335557d2 */ | ||
| 58 | s01 = 1.9153760746e-02, /* 0x3c9ce859 */ | ||
| 59 | s02 = 1.8594678841e-04, /* 0x3942fab6 */ | ||
| 60 | s03 = 1.1771846857e-06, /* 0x359dffc2 */ | ||
| 61 | s04 = 5.0463624390e-09, /* 0x31ad6446 */ | ||
| 62 | s05 = 1.2354227016e-11; /* 0x2d59567e */ | ||
| 63 | |||
| 64 | float j1f(float x) | ||
| 65 | { | ||
| 66 | 	float z,r,s; | ||
| 67 | 	uint32_t ix; | ||
| 68 | 	int sign; | ||
| 69 | |||
| 70 | 	GET_FLOAT_WORD(ix, x); | ||
| 71 | 	sign = ix>>31; | ||
| 72 | 	ix &= 0x7fffffff; | ||
| 73 | 	if (ix >= 0x7f800000) | ||
| 74 | 		return 1/(x*x); | ||
| 75 | 	if (ix >= 0x40000000) /* |x| >= 2 */ | ||
| 76 | 		return common(ix, fabsf(x), 0, sign); | ||
| 77 | 	if (ix >= 0x39000000) { /* |x| >= 2**-13 */ | ||
| 78 | 		z = x*x; | ||
| 79 | 		r = z*(r00+z*(r01+z*(r02+z*r03))); | ||
| 80 | 		s = 1+z*(s01+z*(s02+z*(s03+z*(s04+z*s05)))); | ||
| 81 | 		z = 0.5f + r/s; | ||
| 82 | 	} else | ||
| 83 | 		z = 0.5f; | ||
| 84 | 	return z*x; | ||
| 85 | } | ||
| 86 | |||
| 87 | static const float U0[5] = { | ||
| 88 | -1.9605709612e-01, /* 0xbe48c331 */ | ||
| 89 | 5.0443872809e-02, /* 0x3d4e9e3c */ | ||
| 90 | -1.9125689287e-03, /* 0xbafaaf2a */ | ||
| 91 | 2.3525259166e-05, /* 0x37c5581c */ | ||
| 92 | -9.1909917899e-08, /* 0xb3c56003 */ | ||
| 93 | }; | ||
| 94 | static const float V0[5] = { | ||
| 95 | 1.9916731864e-02, /* 0x3ca3286a */ | ||
| 96 | 2.0255257550e-04, /* 0x3954644b */ | ||
| 97 | 1.3560879779e-06, /* 0x35b602d4 */ | ||
| 98 | 6.2274145840e-09, /* 0x31d5f8eb */ | ||
| 99 | 1.6655924903e-11, /* 0x2d9281cf */ | ||
| 100 | }; | ||
| 101 | |||
| 102 | float y1f(float x) | ||
| 103 | { | ||
| 104 | 	float z,u,v; | ||
| 105 | 	uint32_t ix; | ||
| 106 | |||
| 107 | 	GET_FLOAT_WORD(ix, x); | ||
| 108 | 	if ((ix & 0x7fffffff) == 0) | ||
| 109 | 		return -1/0.0f; | ||
| 110 | 	if (ix>>31) | ||
| 111 | 		return 0/0.0f; | ||
| 112 | 	if (ix >= 0x7f800000) | ||
| 113 | 		return 1/x; | ||
| 114 | 	if (ix >= 0x40000000) /* |x| >= 2.0 */ | ||
| 115 | 		return common(ix,x,1,0); | ||
| 116 | 	if (ix < 0x33000000) /* x < 2**-25 */ | ||
| 117 | 		return -tpi/x; | ||
| 118 | 	z = x*x; | ||
| 119 | 	u = U0[0]+z*(U0[1]+z*(U0[2]+z*(U0[3]+z*U0[4]))); | ||
| 120 | 	v = 1.0f+z*(V0[0]+z*(V0[1]+z*(V0[2]+z*(V0[3]+z*V0[4])))); | ||
| 121 | 	return x*(u/v) + tpi*(j1f(x)*logf(x)-1.0f/x); | ||
| 122 | } | ||
| 123 | |||
| 124 | /* For x >= 8, the asymptotic expansions of pone is | ||
| 125 | * 1 + 15/128 s^2 - 4725/2^15 s^4 - ..., where s = 1/x. | ||
| 126 | * We approximate pone by | ||
| 127 | * pone(x) = 1 + (R/S) | ||
| 128 | * where R = pr0 + pr1*s^2 + pr2*s^4 + ... + pr5*s^10 | ||
| 129 | * S = 1 + ps0*s^2 + ... + ps4*s^10 | ||
| 130 | * and | ||
| 131 | * | pone(x)-1-R/S | <= 2 ** ( -60.06) | ||
| 132 | */ | ||
| 133 | |||
| 134 | static const float pr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 135 | 0.0000000000e+00, /* 0x00000000 */ | ||
| 136 | 1.1718750000e-01, /* 0x3df00000 */ | ||
| 137 | 1.3239480972e+01, /* 0x4153d4ea */ | ||
| 138 | 4.1205184937e+02, /* 0x43ce06a3 */ | ||
| 139 | 3.8747453613e+03, /* 0x45722bed */ | ||
| 140 | 7.9144794922e+03, /* 0x45f753d6 */ | ||
| 141 | }; | ||
| 142 | static const float ps8[5] = { | ||
| 143 | 1.1420736694e+02, /* 0x42e46a2c */ | ||
| 144 | 3.6509309082e+03, /* 0x45642ee5 */ | ||
| 145 | 3.6956207031e+04, /* 0x47105c35 */ | ||
| 146 | 9.7602796875e+04, /* 0x47bea166 */ | ||
| 147 | 3.0804271484e+04, /* 0x46f0a88b */ | ||
| 148 | }; | ||
| 149 | |||
| 150 | static const float pr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 151 | 1.3199052094e-11, /* 0x2d68333f */ | ||
| 152 | 1.1718749255e-01, /* 0x3defffff */ | ||
| 153 | 6.8027510643e+00, /* 0x40d9b023 */ | ||
| 154 | 1.0830818176e+02, /* 0x42d89dca */ | ||
| 155 | 5.1763616943e+02, /* 0x440168b7 */ | ||
| 156 | 5.2871520996e+02, /* 0x44042dc6 */ | ||
| 157 | }; | ||
| 158 | static const float ps5[5] = { | ||
| 159 | 5.9280597687e+01, /* 0x426d1f55 */ | ||
| 160 | 9.9140142822e+02, /* 0x4477d9b1 */ | ||
| 161 | 5.3532670898e+03, /* 0x45a74a23 */ | ||
| 162 | 7.8446904297e+03, /* 0x45f52586 */ | ||
| 163 | 1.5040468750e+03, /* 0x44bc0180 */ | ||
| 164 | }; | ||
| 165 | |||
| 166 | static const float pr3[6] = { | ||
| 167 | 3.0250391081e-09, /* 0x314fe10d */ | ||
| 168 | 1.1718686670e-01, /* 0x3defffab */ | ||
| 169 | 3.9329774380e+00, /* 0x407bb5e7 */ | ||
| 170 | 3.5119403839e+01, /* 0x420c7a45 */ | ||
| 171 | 9.1055007935e+01, /* 0x42b61c2a */ | ||
| 172 | 4.8559066772e+01, /* 0x42423c7c */ | ||
| 173 | }; | ||
| 174 | static const float ps3[5] = { | ||
| 175 | 3.4791309357e+01, /* 0x420b2a4d */ | ||
| 176 | 3.3676245117e+02, /* 0x43a86198 */ | ||
| 177 | 1.0468714600e+03, /* 0x4482dbe3 */ | ||
| 178 | 8.9081134033e+02, /* 0x445eb3ed */ | ||
| 179 | 1.0378793335e+02, /* 0x42cf936c */ | ||
| 180 | }; | ||
| 181 | |||
| 182 | static const float pr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 183 | 1.0771083225e-07, /* 0x33e74ea8 */ | ||
| 184 | 1.1717621982e-01, /* 0x3deffa16 */ | ||
| 185 | 2.3685150146e+00, /* 0x401795c0 */ | ||
| 186 | 1.2242610931e+01, /* 0x4143e1bc */ | ||
| 187 | 1.7693971634e+01, /* 0x418d8d41 */ | ||
| 188 | 5.0735230446e+00, /* 0x40a25a4d */ | ||
| 189 | }; | ||
| 190 | static const float ps2[5] = { | ||
| 191 | 2.1436485291e+01, /* 0x41ab7dec */ | ||
| 192 | 1.2529022980e+02, /* 0x42fa9499 */ | ||
| 193 | 2.3227647400e+02, /* 0x436846c7 */ | ||
| 194 | 1.1767937469e+02, /* 0x42eb5bd7 */ | ||
| 195 | 8.3646392822e+00, /* 0x4105d590 */ | ||
| 196 | }; | ||
| 197 | |||
| 198 | static float ponef(float x) | ||
| 199 | { | ||
| 200 | 	const float *p,*q; | ||
| 201 | 	float_t z,r,s; | ||
| 202 | 	uint32_t ix; | ||
| 203 | |||
| 204 | 	GET_FLOAT_WORD(ix, x); | ||
| 205 | 	ix &= 0x7fffffff; | ||
| 206 | 	if (ix >= 0x41000000){p = pr8; q = ps8;} | ||
| 207 | 	else if (ix >= 0x409173eb){p = pr5; q = ps5;} | ||
| 208 | 	else if (ix >= 0x4036d917){p = pr3; q = ps3;} | ||
| 209 | 	else /*ix >= 0x40000000*/ {p = pr2; q = ps2;} | ||
| 210 | 	z = 1.0f/(x*x); | ||
| 211 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 212 | 	s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*q[4])))); | ||
| 213 | 	return 1.0f + r/s; | ||
| 214 | } | ||
| 215 | |||
| 216 | /* For x >= 8, the asymptotic expansions of qone is | ||
| 217 | * 3/8 s - 105/1024 s^3 - ..., where s = 1/x. | ||
| 218 | * We approximate pone by | ||
| 219 | * qone(x) = s*(0.375 + (R/S)) | ||
| 220 | * where R = qr1*s^2 + qr2*s^4 + ... + qr5*s^10 | ||
| 221 | * S = 1 + qs1*s^2 + ... + qs6*s^12 | ||
| 222 | * and | ||
| 223 | * | qone(x)/s -0.375-R/S | <= 2 ** ( -61.13) | ||
| 224 | */ | ||
| 225 | |||
| 226 | static const float qr8[6] = { /* for x in [inf, 8]=1/[0,0.125] */ | ||
| 227 | 0.0000000000e+00, /* 0x00000000 */ | ||
| 228 | -1.0253906250e-01, /* 0xbdd20000 */ | ||
| 229 | -1.6271753311e+01, /* 0xc1822c8d */ | ||
| 230 | -7.5960174561e+02, /* 0xc43de683 */ | ||
| 231 | -1.1849806641e+04, /* 0xc639273a */ | ||
| 232 | -4.8438511719e+04, /* 0xc73d3683 */ | ||
| 233 | }; | ||
| 234 | static const float qs8[6] = { | ||
| 235 | 1.6139537048e+02, /* 0x43216537 */ | ||
| 236 | 7.8253862305e+03, /* 0x45f48b17 */ | ||
| 237 | 1.3387534375e+05, /* 0x4802bcd6 */ | ||
| 238 | 7.1965775000e+05, /* 0x492fb29c */ | ||
| 239 | 6.6660125000e+05, /* 0x4922be94 */ | ||
| 240 | -2.9449025000e+05, /* 0xc88fcb48 */ | ||
| 241 | }; | ||
| 242 | |||
| 243 | static const float qr5[6] = { /* for x in [8,4.5454]=1/[0.125,0.22001] */ | ||
| 244 | -2.0897993405e-11, /* 0xadb7d219 */ | ||
| 245 | -1.0253904760e-01, /* 0xbdd1fffe */ | ||
| 246 | -8.0564479828e+00, /* 0xc100e736 */ | ||
| 247 | -1.8366960144e+02, /* 0xc337ab6b */ | ||
| 248 | -1.3731937256e+03, /* 0xc4aba633 */ | ||
| 249 | -2.6124443359e+03, /* 0xc523471c */ | ||
| 250 | }; | ||
| 251 | static const float qs5[6] = { | ||
| 252 | 8.1276550293e+01, /* 0x42a28d98 */ | ||
| 253 | 1.9917987061e+03, /* 0x44f8f98f */ | ||
| 254 | 1.7468484375e+04, /* 0x468878f8 */ | ||
| 255 | 4.9851425781e+04, /* 0x4742bb6d */ | ||
| 256 | 2.7948074219e+04, /* 0x46da5826 */ | ||
| 257 | -4.7191835938e+03, /* 0xc5937978 */ | ||
| 258 | }; | ||
| 259 | |||
| 260 | static const float qr3[6] = { | ||
| 261 | -5.0783124372e-09, /* 0xb1ae7d4f */ | ||
| 262 | -1.0253783315e-01, /* 0xbdd1ff5b */ | ||
| 263 | -4.6101160049e+00, /* 0xc0938612 */ | ||
| 264 | -5.7847221375e+01, /* 0xc267638e */ | ||
| 265 | -2.2824453735e+02, /* 0xc3643e9a */ | ||
| 266 | -2.1921012878e+02, /* 0xc35b35cb */ | ||
| 267 | }; | ||
| 268 | static const float qs3[6] = { | ||
| 269 | 4.7665153503e+01, /* 0x423ea91e */ | ||
| 270 | 6.7386511230e+02, /* 0x4428775e */ | ||
| 271 | 3.3801528320e+03, /* 0x45534272 */ | ||
| 272 | 5.5477290039e+03, /* 0x45ad5dd5 */ | ||
| 273 | 1.9031191406e+03, /* 0x44ede3d0 */ | ||
| 274 | -1.3520118713e+02, /* 0xc3073381 */ | ||
| 275 | }; | ||
| 276 | |||
| 277 | static const float qr2[6] = {/* for x in [2.8570,2]=1/[0.3499,0.5] */ | ||
| 278 | -1.7838172539e-07, /* 0xb43f8932 */ | ||
| 279 | -1.0251704603e-01, /* 0xbdd1f475 */ | ||
| 280 | -2.7522056103e+00, /* 0xc0302423 */ | ||
| 281 | -1.9663616180e+01, /* 0xc19d4f16 */ | ||
| 282 | -4.2325313568e+01, /* 0xc2294d1f */ | ||
| 283 | -2.1371921539e+01, /* 0xc1aaf9b2 */ | ||
| 284 | }; | ||
| 285 | static const float qs2[6] = { | ||
| 286 | 2.9533363342e+01, /* 0x41ec4454 */ | ||
| 287 | 2.5298155212e+02, /* 0x437cfb47 */ | ||
| 288 | 7.5750280762e+02, /* 0x443d602e */ | ||
| 289 | 7.3939318848e+02, /* 0x4438d92a */ | ||
| 290 | 1.5594900513e+02, /* 0x431bf2f2 */ | ||
| 291 | -4.9594988823e+00, /* 0xc09eb437 */ | ||
| 292 | }; | ||
| 293 | |||
| 294 | static float qonef(float x) | ||
| 295 | { | ||
| 296 | 	const float *p,*q; | ||
| 297 | 	float_t s,r,z; | ||
| 298 | 	uint32_t ix; | ||
| 299 | |||
| 300 | 	GET_FLOAT_WORD(ix, x); | ||
| 301 | 	ix &= 0x7fffffff; | ||
| 302 | 	if (ix >= 0x41000000){p = qr8; q = qs8;} | ||
| 303 | 	else if (ix >= 0x409173eb){p = qr5; q = qs5;} | ||
| 304 | 	else if (ix >= 0x4036d917){p = qr3; q = qs3;} | ||
| 305 | 	else /*ix >= 0x40000000*/ {p = qr2; q = qs2;} | ||
| 306 | 	z = 1.0f/(x*x); | ||
| 307 | 	r = p[0]+z*(p[1]+z*(p[2]+z*(p[3]+z*(p[4]+z*p[5])))); | ||
| 308 | 	s = 1.0f+z*(q[0]+z*(q[1]+z*(q[2]+z*(q[3]+z*(q[4]+z*q[5]))))); | ||
| 309 | 	return (.375f + r/s)/x; | ||
| 310 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/jn.c created+280| ... | @@ -0,0 +1,280 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_jn.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 | /* | ||
| 13 | * jn(n, x), yn(n, x) | ||
| 14 | * floating point Bessel's function of the 1st and 2nd kind | ||
| 15 | * of order n | ||
| 16 | * | ||
| 17 | * Special cases: | ||
| 18 | * y0(0)=y1(0)=yn(n,0) = -inf with division by zero signal; | ||
| 19 | * y0(-ve)=y1(-ve)=yn(n,-ve) are NaN with invalid signal. | ||
| 20 | * Note 2. About jn(n,x), yn(n,x) | ||
| 21 | * For n=0, j0(x) is called, | ||
| 22 | * for n=1, j1(x) is called, | ||
| 23 | * for n<=x, forward recursion is used starting | ||
| 24 | * from values of j0(x) and j1(x). | ||
| 25 | * for n>x, a continued fraction approximation to | ||
| 26 | * j(n,x)/j(n-1,x) is evaluated and then backward | ||
| 27 | * recursion is used starting from a supposed value | ||
| 28 | * for j(n,x). The resulting value of j(0,x) is | ||
| 29 | * compared with the actual value to correct the | ||
| 30 | * supposed value of j(n,x). | ||
| 31 | * | ||
| 32 | * yn(n,x) is similar in all respects, except | ||
| 33 | * that forward recursion is used for all | ||
| 34 | * values of n>1. | ||
| 35 | */ | ||
| 36 | |||
| 37 | #include "libm.h" | ||
| 38 | |||
| 39 | static const double invsqrtpi = 5.64189583547756279280e-01; /* 0x3FE20DD7, 0x50429B6D */ | ||
| 40 | |||
| 41 | double jn(int n, double x) | ||
| 42 | { | ||
| 43 | 	uint32_t ix, lx; | ||
| 44 | 	int nm1, i, sign; | ||
| 45 | 	double a, b, temp; | ||
| 46 | |||
| 47 | 	EXTRACT_WORDS(ix, lx, x); | ||
| 48 | 	sign = ix>>31; | ||
| 49 | 	ix &= 0x7fffffff; | ||
| 50 | |||
| 51 | 	if ((ix | (lx|-lx)>>31) > 0x7ff00000) /* nan */ | ||
| 52 | 		return x; | ||
| 53 | |||
| 54 | 	/* J(-n,x) = (-1)^n * J(n, x), J(n, -x) = (-1)^n * J(n, x) | ||
| 55 | 	 * Thus, J(-n,x) = J(n,-x) | ||
| 56 | 	 */ | ||
| 57 | 	/* nm1 = |n|-1 is used instead of |n| to handle n==INT_MIN */ | ||
| 58 | 	if (n == 0) | ||
| 59 | 		return j0(x); | ||
| 60 | 	if (n < 0) { | ||
| 61 | 		nm1 = -(n+1); | ||
| 62 | 		x = -x; | ||
| 63 | 		sign ^= 1; | ||
| 64 | 	} else | ||
| 65 | 		nm1 = n-1; | ||
| 66 | 	if (nm1 == 0) | ||
| 67 | 		return j1(x); | ||
| 68 | |||
| 69 | 	sign &= n; /* even n: 0, odd n: signbit(x) */ | ||
| 70 | 	x = fabs(x); | ||
| 71 | 	if ((ix|lx) == 0 || ix == 0x7ff00000) /* if x is 0 or inf */ | ||
| 72 | 		b = 0.0; | ||
| 73 | 	else if (nm1 < x) { | ||
| 74 | 		/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ | ||
| 75 | 		if (ix >= 0x52d00000) { /* x > 2**302 */ | ||
| 76 | 			/* (x >> n**2) | ||
| 77 | 			 * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) | ||
| 78 | 			 * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) | ||
| 79 | 			 * Let s=sin(x), c=cos(x), | ||
| 80 | 			 * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then | ||
| 81 | 			 * | ||
| 82 | 			 * n sin(xn)*sqt2 cos(xn)*sqt2 | ||
| 83 | 			 * ---------------------------------- | ||
| 84 | 			 * 0 s-c c+s | ||
| 85 | 			 * 1 -s-c -c+s | ||
| 86 | 			 * 2 -s+c -c-s | ||
| 87 | 			 * 3 s+c c-s | ||
| 88 | 			 */ | ||
| 89 | 			switch(nm1&3) { | ||
| 90 | 			case 0: temp = -cos(x)+sin(x); break; | ||
| 91 | 			case 1: temp = -cos(x)-sin(x); break; | ||
| 92 | 			case 2: temp = cos(x)-sin(x); break; | ||
| 93 | 			default: | ||
| 94 | 			case 3: temp = cos(x)+sin(x); break; | ||
| 95 | 			} | ||
| 96 | 			b = invsqrtpi*temp/sqrt(x); | ||
| 97 | 		} else { | ||
| 98 | 			a = j0(x); | ||
| 99 | 			b = j1(x); | ||
| 100 | 			for (i=0; i<nm1; ) { | ||
| 101 | 				i++; | ||
| 102 | 				temp = b; | ||
| 103 | 				b = b*(2.0*i/x) - a; /* avoid underflow */ | ||
| 104 | 				a = temp; | ||
| 105 | 			} | ||
| 106 | 		} | ||
| 107 | 	} else { | ||
| 108 | 		if (ix < 0x3e100000) { /* x < 2**-29 */ | ||
| 109 | 			/* x is tiny, return the first Taylor expansion of J(n,x) | ||
| 110 | 			 * J(n,x) = 1/n!*(x/2)^n - ... | ||
| 111 | 			 */ | ||
| 112 | 			if (nm1 > 32) /* underflow */ | ||
| 113 | 				b = 0.0; | ||
| 114 | 			else { | ||
| 115 | 				temp = x*0.5; | ||
| 116 | 				b = temp; | ||
| 117 | 				a = 1.0; | ||
| 118 | 				for (i=2; i<=nm1+1; i++) { | ||
| 119 | 					a *= (double)i; /* a = n! */ | ||
| 120 | 					b *= temp; /* b = (x/2)^n */ | ||
| 121 | 				} | ||
| 122 | 				b = b/a; | ||
| 123 | 			} | ||
| 124 | 		} else { | ||
| 125 | 			/* use backward recurrence */ | ||
| 126 | 			/* x x^2 x^2 | ||
| 127 | 			 * J(n,x)/J(n-1,x) = ---- ------ ------ ..... | ||
| 128 | 			 * 2n - 2(n+1) - 2(n+2) | ||
| 129 | 			 * | ||
| 130 | 			 * 1 1 1 | ||
| 131 | 			 * (for large x) = ---- ------ ------ ..... | ||
| 132 | 			 * 2n 2(n+1) 2(n+2) | ||
| 133 | 			 * -- - ------ - ------ - | ||
| 134 | 			 * x x x | ||
| 135 | 			 * | ||
| 136 | 			 * Let w = 2n/x and h=2/x, then the above quotient | ||
| 137 | 			 * is equal to the continued fraction: | ||
| 138 | 			 * 1 | ||
| 139 | 			 * = ----------------------- | ||
| 140 | 			 * 1 | ||
| 141 | 			 * w - ----------------- | ||
| 142 | 			 * 1 | ||
| 143 | 			 * w+h - --------- | ||
| 144 | 			 * w+2h - ... | ||
| 145 | 			 * | ||
| 146 | 			 * To determine how many terms needed, let | ||
| 147 | 			 * Q(0) = w, Q(1) = w(w+h) - 1, | ||
| 148 | 			 * Q(k) = (w+k*h)*Q(k-1) - Q(k-2), | ||
| 149 | 			 * When Q(k) > 1e4 good for single | ||
| 150 | 			 * When Q(k) > 1e9 good for double | ||
| 151 | 			 * When Q(k) > 1e17 good for quadruple | ||
| 152 | 			 */ | ||
| 153 | 			/* determine k */ | ||
| 154 | 			double t,q0,q1,w,h,z,tmp,nf; | ||
| 155 | 			int k; | ||
| 156 | |||
| 157 | 			nf = nm1 + 1.0; | ||
| 158 | 			w = 2*nf/x; | ||
| 159 | 			h = 2/x; | ||
| 160 | 			z = w+h; | ||
| 161 | 			q0 = w; | ||
| 162 | 			q1 = w*z - 1.0; | ||
| 163 | 			k = 1; | ||
| 164 | 			while (q1 < 1.0e9) { | ||
| 165 | 				k += 1; | ||
| 166 | 				z += h; | ||
| 167 | 				tmp = z*q1 - q0; | ||
| 168 | 				q0 = q1; | ||
| 169 | 				q1 = tmp; | ||
| 170 | 			} | ||
| 171 | 			for (t=0.0, i=k; i>=0; i--) | ||
| 172 | 				t = 1/(2*(i+nf)/x - t); | ||
| 173 | 			a = t; | ||
| 174 | 			b = 1.0; | ||
| 175 | 			/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n) | ||
| 176 | 			 * Hence, if n*(log(2n/x)) > ... | ||
| 177 | 			 * single 8.8722839355e+01 | ||
| 178 | 			 * double 7.09782712893383973096e+02 | ||
| 179 | 			 * long double 1.1356523406294143949491931077970765006170e+04 | ||
| 180 | 			 * then recurrent value may overflow and the result is | ||
| 181 | 			 * likely underflow to zero | ||
| 182 | 			 */ | ||
| 183 | 			tmp = nf*log(fabs(w)); | ||
| 184 | 			if (tmp < 7.09782712893383973096e+02) { | ||
| 185 | 				for (i=nm1; i>0; i--) { | ||
| 186 | 					temp = b; | ||
| 187 | 					b = b*(2.0*i)/x - a; | ||
| 188 | 					a = temp; | ||
| 189 | 				} | ||
| 190 | 			} else { | ||
| 191 | 				for (i=nm1; i>0; i--) { | ||
| 192 | 					temp = b; | ||
| 193 | 					b = b*(2.0*i)/x - a; | ||
| 194 | 					a = temp; | ||
| 195 | 					/* scale b to avoid spurious overflow */ | ||
| 196 | 					if (b > 0x1p500) { | ||
| 197 | 						a /= b; | ||
| 198 | 						t /= b; | ||
| 199 | 						b = 1.0; | ||
| 200 | 					} | ||
| 201 | 				} | ||
| 202 | 			} | ||
| 203 | 			z = j0(x); | ||
| 204 | 			w = j1(x); | ||
| 205 | 			if (fabs(z) >= fabs(w)) | ||
| 206 | 				b = t*z/b; | ||
| 207 | 			else | ||
| 208 | 				b = t*w/a; | ||
| 209 | 		} | ||
| 210 | 	} | ||
| 211 | 	return sign ? -b : b; | ||
| 212 | } | ||
| 213 | |||
| 214 | |||
| 215 | double yn(int n, double x) | ||
| 216 | { | ||
| 217 | 	uint32_t ix, lx, ib; | ||
| 218 | 	int nm1, sign, i; | ||
| 219 | 	double a, b, temp; | ||
| 220 | |||
| 221 | 	EXTRACT_WORDS(ix, lx, x); | ||
| 222 | 	sign = ix>>31; | ||
| 223 | 	ix &= 0x7fffffff; | ||
| 224 | |||
| 225 | 	if ((ix | (lx|-lx)>>31) > 0x7ff00000) /* nan */ | ||
| 226 | 		return x; | ||
| 227 | 	if (sign && (ix|lx)!=0) /* x < 0 */ | ||
| 228 | 		return 0/0.0; | ||
| 229 | 	if (ix == 0x7ff00000) | ||
| 230 | 		return 0.0; | ||
| 231 | |||
| 232 | 	if (n == 0) | ||
| 233 | 		return y0(x); | ||
| 234 | 	if (n < 0) { | ||
| 235 | 		nm1 = -(n+1); | ||
| 236 | 		sign = n&1; | ||
| 237 | 	} else { | ||
| 238 | 		nm1 = n-1; | ||
| 239 | 		sign = 0; | ||
| 240 | 	} | ||
| 241 | 	if (nm1 == 0) | ||
| 242 | 		return sign ? -y1(x) : y1(x); | ||
| 243 | |||
| 244 | 	if (ix >= 0x52d00000) { /* x > 2**302 */ | ||
| 245 | 		/* (x >> n**2) | ||
| 246 | 		 * Jn(x) = cos(x-(2n+1)*pi/4)*sqrt(2/x*pi) | ||
| 247 | 		 * Yn(x) = sin(x-(2n+1)*pi/4)*sqrt(2/x*pi) | ||
| 248 | 		 * Let s=sin(x), c=cos(x), | ||
| 249 | 		 * xn=x-(2n+1)*pi/4, sqt2 = sqrt(2),then | ||
| 250 | 		 * | ||
| 251 | 		 * n sin(xn)*sqt2 cos(xn)*sqt2 | ||
| 252 | 		 * ---------------------------------- | ||
| 253 | 		 * 0 s-c c+s | ||
| 254 | 		 * 1 -s-c -c+s | ||
| 255 | 		 * 2 -s+c -c-s | ||
| 256 | 		 * 3 s+c c-s | ||
| 257 | 		 */ | ||
| 258 | 		switch(nm1&3) { | ||
| 259 | 		case 0: temp = -sin(x)-cos(x); break; | ||
| 260 | 		case 1: temp = -sin(x)+cos(x); break; | ||
| 261 | 		case 2: temp = sin(x)+cos(x); break; | ||
| 262 | 		default: | ||
| 263 | 		case 3: temp = sin(x)-cos(x); break; | ||
| 264 | 		} | ||
| 265 | 		b = invsqrtpi*temp/sqrt(x); | ||
| 266 | 	} else { | ||
| 267 | 		a = y0(x); | ||
| 268 | 		b = y1(x); | ||
| 269 | 		/* quit if b is -inf */ | ||
| 270 | 		GET_HIGH_WORD(ib, b); | ||
| 271 | 		for (i=0; i<nm1 && ib!=0xfff00000; ){ | ||
| 272 | 			i++; | ||
| 273 | 			temp = b; | ||
| 274 | 			b = (2.0*i/x)*b - a; | ||
| 275 | 			GET_HIGH_WORD(ib, b); | ||
| 276 | 			a = temp; | ||
| 277 | 		} | ||
| 278 | 	} | ||
| 279 | 	return sign ? -b : b; | ||
| 280 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/jnf.c created+202| ... | @@ -0,0 +1,202 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_jnf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #define _GNU_SOURCE | ||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | float jnf(int n, float x) | ||
| 20 | { | ||
| 21 | 	uint32_t ix; | ||
| 22 | 	int nm1, sign, i; | ||
| 23 | 	float a, b, temp; | ||
| 24 | |||
| 25 | 	GET_FLOAT_WORD(ix, x); | ||
| 26 | 	sign = ix>>31; | ||
| 27 | 	ix &= 0x7fffffff; | ||
| 28 | 	if (ix > 0x7f800000) /* nan */ | ||
| 29 | 		return x; | ||
| 30 | |||
| 31 | 	/* J(-n,x) = J(n,-x), use |n|-1 to avoid overflow in -n */ | ||
| 32 | 	if (n == 0) | ||
| 33 | 		return j0f(x); | ||
| 34 | 	if (n < 0) { | ||
| 35 | 		nm1 = -(n+1); | ||
| 36 | 		x = -x; | ||
| 37 | 		sign ^= 1; | ||
| 38 | 	} else | ||
| 39 | 		nm1 = n-1; | ||
| 40 | 	if (nm1 == 0) | ||
| 41 | 		return j1f(x); | ||
| 42 | |||
| 43 | 	sign &= n; /* even n: 0, odd n: signbit(x) */ | ||
| 44 | 	x = fabsf(x); | ||
| 45 | 	if (ix == 0 || ix == 0x7f800000) /* if x is 0 or inf */ | ||
| 46 | 		b = 0.0f; | ||
| 47 | 	else if (nm1 < x) { | ||
| 48 | 		/* Safe to use J(n+1,x)=2n/x *J(n,x)-J(n-1,x) */ | ||
| 49 | 		a = j0f(x); | ||
| 50 | 		b = j1f(x); | ||
| 51 | 		for (i=0; i<nm1; ){ | ||
| 52 | 			i++; | ||
| 53 | 			temp = b; | ||
| 54 | 			b = b*(2.0f*i/x) - a; | ||
| 55 | 			a = temp; | ||
| 56 | 		} | ||
| 57 | 	} else { | ||
| 58 | 		if (ix < 0x35800000) { /* x < 2**-20 */ | ||
| 59 | 			/* x is tiny, return the first Taylor expansion of J(n,x) | ||
| 60 | 			 * J(n,x) = 1/n!*(x/2)^n - ... | ||
| 61 | 			 */ | ||
| 62 | 			if (nm1 > 8) /* underflow */ | ||
| 63 | 				nm1 = 8; | ||
| 64 | 			temp = 0.5f * x; | ||
| 65 | 			b = temp; | ||
| 66 | 			a = 1.0f; | ||
| 67 | 			for (i=2; i<=nm1+1; i++) { | ||
| 68 | 				a *= (float)i; /* a = n! */ | ||
| 69 | 				b *= temp; /* b = (x/2)^n */ | ||
| 70 | 			} | ||
| 71 | 			b = b/a; | ||
| 72 | 		} else { | ||
| 73 | 			/* use backward recurrence */ | ||
| 74 | 			/* x x^2 x^2 | ||
| 75 | 			 * J(n,x)/J(n-1,x) = ---- ------ ------ ..... | ||
| 76 | 			 * 2n - 2(n+1) - 2(n+2) | ||
| 77 | 			 * | ||
| 78 | 			 * 1 1 1 | ||
| 79 | 			 * (for large x) = ---- ------ ------ ..... | ||
| 80 | 			 * 2n 2(n+1) 2(n+2) | ||
| 81 | 			 * -- - ------ - ------ - | ||
| 82 | 			 * x x x | ||
| 83 | 			 * | ||
| 84 | 			 * Let w = 2n/x and h=2/x, then the above quotient | ||
| 85 | 			 * is equal to the continued fraction: | ||
| 86 | 			 * 1 | ||
| 87 | 			 * = ----------------------- | ||
| 88 | 			 * 1 | ||
| 89 | 			 * w - ----------------- | ||
| 90 | 			 * 1 | ||
| 91 | 			 * w+h - --------- | ||
| 92 | 			 * w+2h - ... | ||
| 93 | 			 * | ||
| 94 | 			 * To determine how many terms needed, let | ||
| 95 | 			 * Q(0) = w, Q(1) = w(w+h) - 1, | ||
| 96 | 			 * Q(k) = (w+k*h)*Q(k-1) - Q(k-2), | ||
| 97 | 			 * When Q(k) > 1e4 good for single | ||
| 98 | 			 * When Q(k) > 1e9 good for double | ||
| 99 | 			 * When Q(k) > 1e17 good for quadruple | ||
| 100 | 			 */ | ||
| 101 | 			/* determine k */ | ||
| 102 | 			float t,q0,q1,w,h,z,tmp,nf; | ||
| 103 | 			int k; | ||
| 104 | |||
| 105 | 			nf = nm1+1.0f; | ||
| 106 | 			w = 2*nf/x; | ||
| 107 | 			h = 2/x; | ||
| 108 | 			z = w+h; | ||
| 109 | 			q0 = w; | ||
| 110 | 			q1 = w*z - 1.0f; | ||
| 111 | 			k = 1; | ||
| 112 | 			while (q1 < 1.0e4f) { | ||
| 113 | 				k += 1; | ||
| 114 | 				z += h; | ||
| 115 | 				tmp = z*q1 - q0; | ||
| 116 | 				q0 = q1; | ||
| 117 | 				q1 = tmp; | ||
| 118 | 			} | ||
| 119 | 			for (t=0.0f, i=k; i>=0; i--) | ||
| 120 | 				t = 1.0f/(2*(i+nf)/x-t); | ||
| 121 | 			a = t; | ||
| 122 | 			b = 1.0f; | ||
| 123 | 			/* estimate log((2/x)^n*n!) = n*log(2/x)+n*ln(n) | ||
| 124 | 			 * Hence, if n*(log(2n/x)) > ... | ||
| 125 | 			 * single 8.8722839355e+01 | ||
| 126 | 			 * double 7.09782712893383973096e+02 | ||
| 127 | 			 * long double 1.1356523406294143949491931077970765006170e+04 | ||
| 128 | 			 * then recurrent value may overflow and the result is | ||
| 129 | 			 * likely underflow to zero | ||
| 130 | 			 */ | ||
| 131 | 			tmp = nf*logf(fabsf(w)); | ||
| 132 | 			if (tmp < 88.721679688f) { | ||
| 133 | 				for (i=nm1; i>0; i--) { | ||
| 134 | 					temp = b; | ||
| 135 | 					b = 2.0f*i*b/x - a; | ||
| 136 | 					a = temp; | ||
| 137 | 				} | ||
| 138 | 			} else { | ||
| 139 | 				for (i=nm1; i>0; i--){ | ||
| 140 | 					temp = b; | ||
| 141 | 					b = 2.0f*i*b/x - a; | ||
| 142 | 					a = temp; | ||
| 143 | 					/* scale b to avoid spurious overflow */ | ||
| 144 | 					if (b > 0x1p60f) { | ||
| 145 | 						a /= b; | ||
| 146 | 						t /= b; | ||
| 147 | 						b = 1.0f; | ||
| 148 | 					} | ||
| 149 | 				} | ||
| 150 | 			} | ||
| 151 | 			z = j0f(x); | ||
| 152 | 			w = j1f(x); | ||
| 153 | 			if (fabsf(z) >= fabsf(w)) | ||
| 154 | 				b = t*z/b; | ||
| 155 | 			else | ||
| 156 | 				b = t*w/a; | ||
| 157 | 		} | ||
| 158 | 	} | ||
| 159 | 	return sign ? -b : b; | ||
| 160 | } | ||
| 161 | |||
| 162 | float ynf(int n, float x) | ||
| 163 | { | ||
| 164 | 	uint32_t ix, ib; | ||
| 165 | 	int nm1, sign, i; | ||
| 166 | 	float a, b, temp; | ||
| 167 | |||
| 168 | 	GET_FLOAT_WORD(ix, x); | ||
| 169 | 	sign = ix>>31; | ||
| 170 | 	ix &= 0x7fffffff; | ||
| 171 | 	if (ix > 0x7f800000) /* nan */ | ||
| 172 | 		return x; | ||
| 173 | 	if (sign && ix != 0) /* x < 0 */ | ||
| 174 | 		return 0/0.0f; | ||
| 175 | 	if (ix == 0x7f800000) | ||
| 176 | 		return 0.0f; | ||
| 177 | |||
| 178 | 	if (n == 0) | ||
| 179 | 		return y0f(x); | ||
| 180 | 	if (n < 0) { | ||
| 181 | 		nm1 = -(n+1); | ||
| 182 | 		sign = n&1; | ||
| 183 | 	} else { | ||
| 184 | 		nm1 = n-1; | ||
| 185 | 		sign = 0; | ||
| 186 | 	} | ||
| 187 | 	if (nm1 == 0) | ||
| 188 | 		return sign ? -y1f(x) : y1f(x); | ||
| 189 | |||
| 190 | 	a = y0f(x); | ||
| 191 | 	b = y1f(x); | ||
| 192 | 	/* quit if b is -inf */ | ||
| 193 | 	GET_FLOAT_WORD(ib,b); | ||
| 194 | 	for (i = 0; i < nm1 && ib != 0xff800000; ) { | ||
| 195 | 		i++; | ||
| 196 | 		temp = b; | ||
| 197 | 		b = (2.0f*i/x)*b - a; | ||
| 198 | 		GET_FLOAT_WORD(ib, b); | ||
| 199 | 		a = temp; | ||
| 200 | 	} | ||
| 201 | 	return sign ? -b : b; | ||
| 202 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ldexp.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double ldexp(double x, int n) | ||
| 4 | { | ||
| 5 | 	return scalbn(x, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ldexpf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float ldexpf(float x, int n) | ||
| 4 | { | ||
| 5 | 	return scalbnf(x, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/ldexpl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double ldexpl(long double x, int n) | ||
| 4 | { | ||
| 5 | 	return scalbnl(x, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/lgamma.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | double lgamma(double x) | ||
| 5 | { | ||
| 6 | 	return __lgamma_r(x, &__signgam); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/lgamma_r.c created+283| ... | @@ -0,0 +1,283 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_lgamma_r.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 | */ | ||
| 13 | /* lgamma_r(x, signgamp) | ||
| 14 | * Reentrant version of the logarithm of the Gamma function | ||
| 15 | * with user provide pointer for the sign of Gamma(x). | ||
| 16 | * | ||
| 17 | * Method: | ||
| 18 | * 1. Argument Reduction for 0 < x <= 8 | ||
| 19 | * Since gamma(1+s)=s*gamma(s), for x in [0,8], we may | ||
| 20 | * reduce x to a number in [1.5,2.5] by | ||
| 21 | * lgamma(1+s) = log(s) + lgamma(s) | ||
| 22 | * for example, | ||
| 23 | * lgamma(7.3) = log(6.3) + lgamma(6.3) | ||
| 24 | * = log(6.3*5.3) + lgamma(5.3) | ||
| 25 | * = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3) | ||
| 26 | * 2. Polynomial approximation of lgamma around its | ||
| 27 | * minimun ymin=1.461632144968362245 to maintain monotonicity. | ||
| 28 | * On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use | ||
| 29 | * Let z = x-ymin; | ||
| 30 | * lgamma(x) = -1.214862905358496078218 + z^2*poly(z) | ||
| 31 | * where | ||
| 32 | * poly(z) is a 14 degree polynomial. | ||
| 33 | * 2. Rational approximation in the primary interval [2,3] | ||
| 34 | * We use the following approximation: | ||
| 35 | * s = x-2.0; | ||
| 36 | * lgamma(x) = 0.5*s + s*P(s)/Q(s) | ||
| 37 | * with accuracy | ||
| 38 | * |P/Q - (lgamma(x)-0.5s)| < 2**-61.71 | ||
| 39 | * Our algorithms are based on the following observation | ||
| 40 | * | ||
| 41 | * zeta(2)-1 2 zeta(3)-1 3 | ||
| 42 | * lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ... | ||
| 43 | * 2 3 | ||
| 44 | * | ||
| 45 | * where Euler = 0.5771... is the Euler constant, which is very | ||
| 46 | * close to 0.5. | ||
| 47 | * | ||
| 48 | * 3. For x>=8, we have | ||
| 49 | * lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+.... | ||
| 50 | * (better formula: | ||
| 51 | * lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...) | ||
| 52 | * Let z = 1/x, then we approximation | ||
| 53 | * f(z) = lgamma(x) - (x-0.5)(log(x)-1) | ||
| 54 | * by | ||
| 55 | * 3 5 11 | ||
| 56 | * w = w0 + w1*z + w2*z + w3*z + ... + w6*z | ||
| 57 | * where | ||
| 58 | * |w - f(z)| < 2**-58.74 | ||
| 59 | * | ||
| 60 | * 4. For negative x, since (G is gamma function) | ||
| 61 | * -x*G(-x)*G(x) = pi/sin(pi*x), | ||
| 62 | * we have | ||
| 63 | * G(x) = pi/(sin(pi*x)*(-x)*G(-x)) | ||
| 64 | * since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0 | ||
| 65 | * Hence, for x<0, signgam = sign(sin(pi*x)) and | ||
| 66 | * lgamma(x) = log(|Gamma(x)|) | ||
| 67 | * = log(pi/(|x*sin(pi*x)|)) - lgamma(-x); | ||
| 68 | * Note: one should avoid compute pi*(-x) directly in the | ||
| 69 | * computation of sin(pi*(-x)). | ||
| 70 | * | ||
| 71 | * 5. Special Cases | ||
| 72 | * lgamma(2+s) ~ s*(1-Euler) for tiny s | ||
| 73 | * lgamma(1) = lgamma(2) = 0 | ||
| 74 | * lgamma(x) ~ -log(|x|) for tiny x | ||
| 75 | * lgamma(0) = lgamma(neg.integer) = inf and raise divide-by-zero | ||
| 76 | * lgamma(inf) = inf | ||
| 77 | * lgamma(-inf) = inf (bug for bug compatible with C99!?) | ||
| 78 | * | ||
| 79 | */ | ||
| 80 | |||
| 81 | #include "libm.h" | ||
| 82 | |||
| 83 | static const double | ||
| 84 | pi = 3.14159265358979311600e+00, /* 0x400921FB, 0x54442D18 */ | ||
| 85 | a0 = 7.72156649015328655494e-02, /* 0x3FB3C467, 0xE37DB0C8 */ | ||
| 86 | a1 = 3.22467033424113591611e-01, /* 0x3FD4A34C, 0xC4A60FAD */ | ||
| 87 | a2 = 6.73523010531292681824e-02, /* 0x3FB13E00, 0x1A5562A7 */ | ||
| 88 | a3 = 2.05808084325167332806e-02, /* 0x3F951322, 0xAC92547B */ | ||
| 89 | a4 = 7.38555086081402883957e-03, /* 0x3F7E404F, 0xB68FEFE8 */ | ||
| 90 | a5 = 2.89051383673415629091e-03, /* 0x3F67ADD8, 0xCCB7926B */ | ||
| 91 | a6 = 1.19270763183362067845e-03, /* 0x3F538A94, 0x116F3F5D */ | ||
| 92 | a7 = 5.10069792153511336608e-04, /* 0x3F40B6C6, 0x89B99C00 */ | ||
| 93 | a8 = 2.20862790713908385557e-04, /* 0x3F2CF2EC, 0xED10E54D */ | ||
| 94 | a9 = 1.08011567247583939954e-04, /* 0x3F1C5088, 0x987DFB07 */ | ||
| 95 | a10 = 2.52144565451257326939e-05, /* 0x3EFA7074, 0x428CFA52 */ | ||
| 96 | a11 = 4.48640949618915160150e-05, /* 0x3F07858E, 0x90A45837 */ | ||
| 97 | tc = 1.46163214496836224576e+00, /* 0x3FF762D8, 0x6356BE3F */ | ||
| 98 | tf = -1.21486290535849611461e-01, /* 0xBFBF19B9, 0xBCC38A42 */ | ||
| 99 | /* tt = -(tail of tf) */ | ||
| 100 | tt = -3.63867699703950536541e-18, /* 0xBC50C7CA, 0xA48A971F */ | ||
| 101 | t0 = 4.83836122723810047042e-01, /* 0x3FDEF72B, 0xC8EE38A2 */ | ||
| 102 | t1 = -1.47587722994593911752e-01, /* 0xBFC2E427, 0x8DC6C509 */ | ||
| 103 | t2 = 6.46249402391333854778e-02, /* 0x3FB08B42, 0x94D5419B */ | ||
| 104 | t3 = -3.27885410759859649565e-02, /* 0xBFA0C9A8, 0xDF35B713 */ | ||
| 105 | t4 = 1.79706750811820387126e-02, /* 0x3F9266E7, 0x970AF9EC */ | ||
| 106 | t5 = -1.03142241298341437450e-02, /* 0xBF851F9F, 0xBA91EC6A */ | ||
| 107 | t6 = 6.10053870246291332635e-03, /* 0x3F78FCE0, 0xE370E344 */ | ||
| 108 | t7 = -3.68452016781138256760e-03, /* 0xBF6E2EFF, 0xB3E914D7 */ | ||
| 109 | t8 = 2.25964780900612472250e-03, /* 0x3F6282D3, 0x2E15C915 */ | ||
| 110 | t9 = -1.40346469989232843813e-03, /* 0xBF56FE8E, 0xBF2D1AF1 */ | ||
| 111 | t10 = 8.81081882437654011382e-04, /* 0x3F4CDF0C, 0xEF61A8E9 */ | ||
| 112 | t11 = -5.38595305356740546715e-04, /* 0xBF41A610, 0x9C73E0EC */ | ||
| 113 | t12 = 3.15632070903625950361e-04, /* 0x3F34AF6D, 0x6C0EBBF7 */ | ||
| 114 | t13 = -3.12754168375120860518e-04, /* 0xBF347F24, 0xECC38C38 */ | ||
| 115 | t14 = 3.35529192635519073543e-04, /* 0x3F35FD3E, 0xE8C2D3F4 */ | ||
| 116 | u0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */ | ||
| 117 | u1 = 6.32827064025093366517e-01, /* 0x3FE4401E, 0x8B005DFF */ | ||
| 118 | u2 = 1.45492250137234768737e+00, /* 0x3FF7475C, 0xD119BD6F */ | ||
| 119 | u3 = 9.77717527963372745603e-01, /* 0x3FEF4976, 0x44EA8450 */ | ||
| 120 | u4 = 2.28963728064692451092e-01, /* 0x3FCD4EAE, 0xF6010924 */ | ||
| 121 | u5 = 1.33810918536787660377e-02, /* 0x3F8B678B, 0xBF2BAB09 */ | ||
| 122 | v1 = 2.45597793713041134822e+00, /* 0x4003A5D7, 0xC2BD619C */ | ||
| 123 | v2 = 2.12848976379893395361e+00, /* 0x40010725, 0xA42B18F5 */ | ||
| 124 | v3 = 7.69285150456672783825e-01, /* 0x3FE89DFB, 0xE45050AF */ | ||
| 125 | v4 = 1.04222645593369134254e-01, /* 0x3FBAAE55, 0xD6537C88 */ | ||
| 126 | v5 = 3.21709242282423911810e-03, /* 0x3F6A5ABB, 0x57D0CF61 */ | ||
| 127 | s0 = -7.72156649015328655494e-02, /* 0xBFB3C467, 0xE37DB0C8 */ | ||
| 128 | s1 = 2.14982415960608852501e-01, /* 0x3FCB848B, 0x36E20878 */ | ||
| 129 | s2 = 3.25778796408930981787e-01, /* 0x3FD4D98F, 0x4F139F59 */ | ||
| 130 | s3 = 1.46350472652464452805e-01, /* 0x3FC2BB9C, 0xBEE5F2F7 */ | ||
| 131 | s4 = 2.66422703033638609560e-02, /* 0x3F9B481C, 0x7E939961 */ | ||
| 132 | s5 = 1.84028451407337715652e-03, /* 0x3F5E26B6, 0x7368F239 */ | ||
| 133 | s6 = 3.19475326584100867617e-05, /* 0x3F00BFEC, 0xDD17E945 */ | ||
| 134 | r1 = 1.39200533467621045958e+00, /* 0x3FF645A7, 0x62C4AB74 */ | ||
| 135 | r2 = 7.21935547567138069525e-01, /* 0x3FE71A18, 0x93D3DCDC */ | ||
| 136 | r3 = 1.71933865632803078993e-01, /* 0x3FC601ED, 0xCCFBDF27 */ | ||
| 137 | r4 = 1.86459191715652901344e-02, /* 0x3F9317EA, 0x742ED475 */ | ||
| 138 | r5 = 7.77942496381893596434e-04, /* 0x3F497DDA, 0xCA41A95B */ | ||
| 139 | r6 = 7.32668430744625636189e-06, /* 0x3EDEBAF7, 0xA5B38140 */ | ||
| 140 | w0 = 4.18938533204672725052e-01, /* 0x3FDACFE3, 0x90C97D69 */ | ||
| 141 | w1 = 8.33333333333329678849e-02, /* 0x3FB55555, 0x5555553B */ | ||
| 142 | w2 = -2.77777777728775536470e-03, /* 0xBF66C16C, 0x16B02E5C */ | ||
| 143 | w3 = 7.93650558643019558500e-04, /* 0x3F4A019F, 0x98CF38B6 */ | ||
| 144 | w4 = -5.95187557450339963135e-04, /* 0xBF4380CB, 0x8C0FE741 */ | ||
| 145 | w5 = 8.36339918996282139126e-04, /* 0x3F4B67BA, 0x4CDAD5D1 */ | ||
| 146 | w6 = -1.63092934096575273989e-03; /* 0xBF5AB89D, 0x0B9E43E4 */ | ||
| 147 | |||
| 148 | /* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */ | ||
| 149 | static double sin_pi(double x) | ||
| 150 | { | ||
| 151 | 	int n; | ||
| 152 | |||
| 153 | 	/* spurious inexact if odd int */ | ||
| 154 | 	x = 2.0*(x*0.5 - floor(x*0.5)); /* x mod 2.0 */ | ||
| 155 | |||
| 156 | 	n = (int)(x*4.0); | ||
| 157 | 	n = (n+1)/2; | ||
| 158 | 	x -= n*0.5f; | ||
| 159 | 	x *= pi; | ||
| 160 | |||
| 161 | 	switch (n) { | ||
| 162 | 	default: /* case 4: */ | ||
| 163 | 	case 0: return __sin(x, 0.0, 0); | ||
| 164 | 	case 1: return __cos(x, 0.0); | ||
| 165 | 	case 2: return __sin(-x, 0.0, 0); | ||
| 166 | 	case 3: return -__cos(x, 0.0); | ||
| 167 | 	} | ||
| 168 | } | ||
| 169 | |||
| 170 | double __lgamma_r(double x, int *signgamp) | ||
| 171 | { | ||
| 172 | 	union {double f; uint64_t i;} u = {x}; | ||
| 173 | 	double_t t,y,z,nadj,p,p1,p2,p3,q,r,w; | ||
| 174 | 	uint32_t ix; | ||
| 175 | 	int sign,i; | ||
| 176 | |||
| 177 | 	/* purge off +-inf, NaN, +-0, tiny and negative arguments */ | ||
| 178 | 	*signgamp = 1; | ||
| 179 | 	sign = u.i>>63; | ||
| 180 | 	ix = u.i>>32 & 0x7fffffff; | ||
| 181 | 	if (ix >= 0x7ff00000) | ||
| 182 | 		return x*x; | ||
| 183 | 	if (ix < (0x3ff-70)<<20) { /* |x|<2**-70, return -log(|x|) */ | ||
| 184 | 		if(sign) { | ||
| 185 | 			x = -x; | ||
| 186 | 			*signgamp = -1; | ||
| 187 | 		} | ||
| 188 | 		return -log(x); | ||
| 189 | 	} | ||
| 190 | 	if (sign) { | ||
| 191 | 		x = -x; | ||
| 192 | 		t = sin_pi(x); | ||
| 193 | 		if (t == 0.0) /* -integer */ | ||
| 194 | 			return 1.0/(x-x); | ||
| 195 | 		if (t > 0.0) | ||
| 196 | 			*signgamp = -1; | ||
| 197 | 		else | ||
| 198 | 			t = -t; | ||
| 199 | 		nadj = log(pi/(t*x)); | ||
| 200 | 	} | ||
| 201 | |||
| 202 | 	/* purge off 1 and 2 */ | ||
| 203 | 	if ((ix == 0x3ff00000 || ix == 0x40000000) && (uint32_t)u.i == 0) | ||
| 204 | 		r = 0; | ||
| 205 | 	/* for x < 2.0 */ | ||
| 206 | 	else if (ix < 0x40000000) { | ||
| 207 | 		if (ix <= 0x3feccccc) { /* lgamma(x) = lgamma(x+1)-log(x) */ | ||
| 208 | 			r = -log(x); | ||
| 209 | 			if (ix >= 0x3FE76944) { | ||
| 210 | 				y = 1.0 - x; | ||
| 211 | 				i = 0; | ||
| 212 | 			} else if (ix >= 0x3FCDA661) { | ||
| 213 | 				y = x - (tc-1.0); | ||
| 214 | 				i = 1; | ||
| 215 | 			} else { | ||
| 216 | 				y = x; | ||
| 217 | 				i = 2; | ||
| 218 | 			} | ||
| 219 | 		} else { | ||
| 220 | 			r = 0.0; | ||
| 221 | 			if (ix >= 0x3FFBB4C3) { /* [1.7316,2] */ | ||
| 222 | 				y = 2.0 - x; | ||
| 223 | 				i = 0; | ||
| 224 | 			} else if(ix >= 0x3FF3B4C4) { /* [1.23,1.73] */ | ||
| 225 | 				y = x - tc; | ||
| 226 | 				i = 1; | ||
| 227 | 			} else { | ||
| 228 | 				y = x - 1.0; | ||
| 229 | 				i = 2; | ||
| 230 | 			} | ||
| 231 | 		} | ||
| 232 | 		switch (i) { | ||
| 233 | 		case 0: | ||
| 234 | 			z = y*y; | ||
| 235 | 			p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10)))); | ||
| 236 | 			p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11))))); | ||
| 237 | 			p = y*p1+p2; | ||
| 238 | 			r += (p-0.5*y); | ||
| 239 | 			break; | ||
| 240 | 		case 1: | ||
| 241 | 			z = y*y; | ||
| 242 | 			w = z*y; | ||
| 243 | 			p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */ | ||
| 244 | 			p2 = t1+w*(t4+w*(t7+w*(t10+w*t13))); | ||
| 245 | 			p3 = t2+w*(t5+w*(t8+w*(t11+w*t14))); | ||
| 246 | 			p = z*p1-(tt-w*(p2+y*p3)); | ||
| 247 | 			r += tf + p; | ||
| 248 | 			break; | ||
| 249 | 		case 2: | ||
| 250 | 			p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5))))); | ||
| 251 | 			p2 = 1.0+y*(v1+y*(v2+y*(v3+y*(v4+y*v5)))); | ||
| 252 | 			r += -0.5*y + p1/p2; | ||
| 253 | 		} | ||
| 254 | 	} else if (ix < 0x40200000) { /* x < 8.0 */ | ||
| 255 | 		i = (int)x; | ||
| 256 | 		y = x - (double)i; | ||
| 257 | 		p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))); | ||
| 258 | 		q = 1.0+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6))))); | ||
| 259 | 		r = 0.5*y+p/q; | ||
| 260 | 		z = 1.0; /* lgamma(1+s) = log(s) + lgamma(s) */ | ||
| 261 | 		switch (i) { | ||
| 262 | 		case 7: z *= y + 6.0; /* FALLTHRU */ | ||
| 263 | 		case 6: z *= y + 5.0; /* FALLTHRU */ | ||
| 264 | 		case 5: z *= y + 4.0; /* FALLTHRU */ | ||
| 265 | 		case 4: z *= y + 3.0; /* FALLTHRU */ | ||
| 266 | 		case 3: z *= y + 2.0; /* FALLTHRU */ | ||
| 267 | 			r += log(z); | ||
| 268 | 			break; | ||
| 269 | 		} | ||
| 270 | 	} else if (ix < 0x43900000) { /* 8.0 <= x < 2**58 */ | ||
| 271 | 		t = log(x); | ||
| 272 | 		z = 1.0/x; | ||
| 273 | 		y = z*z; | ||
| 274 | 		w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6))))); | ||
| 275 | 		r = (x-0.5)*(t-1.0)+w; | ||
| 276 | 	} else /* 2**58 <= x <= inf */ | ||
| 277 | 		r = x*(log(x)-1.0); | ||
| 278 | 	if (sign) | ||
| 279 | 		r = nadj - r; | ||
| 280 | 	return r; | ||
| 281 | } | ||
| 282 | |||
| 283 | weak_alias(__lgamma_r, lgamma_r); | ||
lib/libc/wasi/libc-top-half/musl/src/math/lgammaf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | float lgammaf(float x) | ||
| 5 | { | ||
| 6 | 	return __lgammaf_r(x, &__signgam); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/lgammaf_r.c created+218| ... | @@ -0,0 +1,218 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_lgammaf_r.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include "libm.h" | ||
| 17 | |||
| 18 | static const float | ||
| 19 | pi = 3.1415927410e+00, /* 0x40490fdb */ | ||
| 20 | a0 = 7.7215664089e-02, /* 0x3d9e233f */ | ||
| 21 | a1 = 3.2246702909e-01, /* 0x3ea51a66 */ | ||
| 22 | a2 = 6.7352302372e-02, /* 0x3d89f001 */ | ||
| 23 | a3 = 2.0580807701e-02, /* 0x3ca89915 */ | ||
| 24 | a4 = 7.3855509982e-03, /* 0x3bf2027e */ | ||
| 25 | a5 = 2.8905137442e-03, /* 0x3b3d6ec6 */ | ||
| 26 | a6 = 1.1927076848e-03, /* 0x3a9c54a1 */ | ||
| 27 | a7 = 5.1006977446e-04, /* 0x3a05b634 */ | ||
| 28 | a8 = 2.2086278477e-04, /* 0x39679767 */ | ||
| 29 | a9 = 1.0801156895e-04, /* 0x38e28445 */ | ||
| 30 | a10 = 2.5214456400e-05, /* 0x37d383a2 */ | ||
| 31 | a11 = 4.4864096708e-05, /* 0x383c2c75 */ | ||
| 32 | tc = 1.4616321325e+00, /* 0x3fbb16c3 */ | ||
| 33 | tf = -1.2148628384e-01, /* 0xbdf8cdcd */ | ||
| 34 | /* tt = -(tail of tf) */ | ||
| 35 | tt = 6.6971006518e-09, /* 0x31e61c52 */ | ||
| 36 | t0 = 4.8383611441e-01, /* 0x3ef7b95e */ | ||
| 37 | t1 = -1.4758771658e-01, /* 0xbe17213c */ | ||
| 38 | t2 = 6.4624942839e-02, /* 0x3d845a15 */ | ||
| 39 | t3 = -3.2788541168e-02, /* 0xbd064d47 */ | ||
| 40 | t4 = 1.7970675603e-02, /* 0x3c93373d */ | ||
| 41 | t5 = -1.0314224288e-02, /* 0xbc28fcfe */ | ||
| 42 | t6 = 6.1005386524e-03, /* 0x3bc7e707 */ | ||
| 43 | t7 = -3.6845202558e-03, /* 0xbb7177fe */ | ||
| 44 | t8 = 2.2596477065e-03, /* 0x3b141699 */ | ||
| 45 | t9 = -1.4034647029e-03, /* 0xbab7f476 */ | ||
| 46 | t10 = 8.8108185446e-04, /* 0x3a66f867 */ | ||
| 47 | t11 = -5.3859531181e-04, /* 0xba0d3085 */ | ||
| 48 | t12 = 3.1563205994e-04, /* 0x39a57b6b */ | ||
| 49 | t13 = -3.1275415677e-04, /* 0xb9a3f927 */ | ||
| 50 | t14 = 3.3552918467e-04, /* 0x39afe9f7 */ | ||
| 51 | u0 = -7.7215664089e-02, /* 0xbd9e233f */ | ||
| 52 | u1 = 6.3282704353e-01, /* 0x3f2200f4 */ | ||
| 53 | u2 = 1.4549225569e+00, /* 0x3fba3ae7 */ | ||
| 54 | u3 = 9.7771751881e-01, /* 0x3f7a4bb2 */ | ||
| 55 | u4 = 2.2896373272e-01, /* 0x3e6a7578 */ | ||
| 56 | u5 = 1.3381091878e-02, /* 0x3c5b3c5e */ | ||
| 57 | v1 = 2.4559779167e+00, /* 0x401d2ebe */ | ||
| 58 | v2 = 2.1284897327e+00, /* 0x4008392d */ | ||
| 59 | v3 = 7.6928514242e-01, /* 0x3f44efdf */ | ||
| 60 | v4 = 1.0422264785e-01, /* 0x3dd572af */ | ||
| 61 | v5 = 3.2170924824e-03, /* 0x3b52d5db */ | ||
| 62 | s0 = -7.7215664089e-02, /* 0xbd9e233f */ | ||
| 63 | s1 = 2.1498242021e-01, /* 0x3e5c245a */ | ||
| 64 | s2 = 3.2577878237e-01, /* 0x3ea6cc7a */ | ||
| 65 | s3 = 1.4635047317e-01, /* 0x3e15dce6 */ | ||
| 66 | s4 = 2.6642270386e-02, /* 0x3cda40e4 */ | ||
| 67 | s5 = 1.8402845599e-03, /* 0x3af135b4 */ | ||
| 68 | s6 = 3.1947532989e-05, /* 0x3805ff67 */ | ||
| 69 | r1 = 1.3920053244e+00, /* 0x3fb22d3b */ | ||
| 70 | r2 = 7.2193557024e-01, /* 0x3f38d0c5 */ | ||
| 71 | r3 = 1.7193385959e-01, /* 0x3e300f6e */ | ||
| 72 | r4 = 1.8645919859e-02, /* 0x3c98bf54 */ | ||
| 73 | r5 = 7.7794247773e-04, /* 0x3a4beed6 */ | ||
| 74 | r6 = 7.3266842264e-06, /* 0x36f5d7bd */ | ||
| 75 | w0 = 4.1893854737e-01, /* 0x3ed67f1d */ | ||
| 76 | w1 = 8.3333335817e-02, /* 0x3daaaaab */ | ||
| 77 | w2 = -2.7777778450e-03, /* 0xbb360b61 */ | ||
| 78 | w3 = 7.9365057172e-04, /* 0x3a500cfd */ | ||
| 79 | w4 = -5.9518753551e-04, /* 0xba1c065c */ | ||
| 80 | w5 = 8.3633989561e-04, /* 0x3a5b3dd2 */ | ||
| 81 | w6 = -1.6309292987e-03; /* 0xbad5c4e8 */ | ||
| 82 | |||
| 83 | /* sin(pi*x) assuming x > 2^-100, if sin(pi*x)==0 the sign is arbitrary */ | ||
| 84 | static float sin_pi(float x) | ||
| 85 | { | ||
| 86 | 	double_t y; | ||
| 87 | 	int n; | ||
| 88 | |||
| 89 | 	/* spurious inexact if odd int */ | ||
| 90 | 	x = 2*(x*0.5f - floorf(x*0.5f)); /* x mod 2.0 */ | ||
| 91 | |||
| 92 | 	n = (int)(x*4); | ||
| 93 | 	n = (n+1)/2; | ||
| 94 | 	y = x - n*0.5f; | ||
| 95 | 	y *= 3.14159265358979323846; | ||
| 96 | 	switch (n) { | ||
| 97 | 	default: /* case 4: */ | ||
| 98 | 	case 0: return __sindf(y); | ||
| 99 | 	case 1: return __cosdf(y); | ||
| 100 | 	case 2: return __sindf(-y); | ||
| 101 | 	case 3: return -__cosdf(y); | ||
| 102 | 	} | ||
| 103 | } | ||
| 104 | |||
| 105 | float __lgammaf_r(float x, int *signgamp) | ||
| 106 | { | ||
| 107 | 	union {float f; uint32_t i;} u = {x}; | ||
| 108 | 	float t,y,z,nadj,p,p1,p2,p3,q,r,w; | ||
| 109 | 	uint32_t ix; | ||
| 110 | 	int i,sign; | ||
| 111 | |||
| 112 | 	/* purge off +-inf, NaN, +-0, tiny and negative arguments */ | ||
| 113 | 	*signgamp = 1; | ||
| 114 | 	sign = u.i>>31; | ||
| 115 | 	ix = u.i & 0x7fffffff; | ||
| 116 | 	if (ix >= 0x7f800000) | ||
| 117 | 		return x*x; | ||
| 118 | 	if (ix < 0x35000000) { /* |x| < 2**-21, return -log(|x|) */ | ||
| 119 | 		if (sign) { | ||
| 120 | 			*signgamp = -1; | ||
| 121 | 			x = -x; | ||
| 122 | 		} | ||
| 123 | 		return -logf(x); | ||
| 124 | 	} | ||
| 125 | 	if (sign) { | ||
| 126 | 		x = -x; | ||
| 127 | 		t = sin_pi(x); | ||
| 128 | 		if (t == 0.0f) /* -integer */ | ||
| 129 | 			return 1.0f/(x-x); | ||
| 130 | 		if (t > 0.0f) | ||
| 131 | 			*signgamp = -1; | ||
| 132 | 		else | ||
| 133 | 			t = -t; | ||
| 134 | 		nadj = logf(pi/(t*x)); | ||
| 135 | 	} | ||
| 136 | |||
| 137 | 	/* purge off 1 and 2 */ | ||
| 138 | 	if (ix == 0x3f800000 || ix == 0x40000000) | ||
| 139 | 		r = 0; | ||
| 140 | 	/* for x < 2.0 */ | ||
| 141 | 	else if (ix < 0x40000000) { | ||
| 142 | 		if (ix <= 0x3f666666) { /* lgamma(x) = lgamma(x+1)-log(x) */ | ||
| 143 | 			r = -logf(x); | ||
| 144 | 			if (ix >= 0x3f3b4a20) { | ||
| 145 | 				y = 1.0f - x; | ||
| 146 | 				i = 0; | ||
| 147 | 			} else if (ix >= 0x3e6d3308) { | ||
| 148 | 				y = x - (tc-1.0f); | ||
| 149 | 				i = 1; | ||
| 150 | 			} else { | ||
| 151 | 				y = x; | ||
| 152 | 				i = 2; | ||
| 153 | 			} | ||
| 154 | 		} else { | ||
| 155 | 			r = 0.0f; | ||
| 156 | 			if (ix >= 0x3fdda618) { /* [1.7316,2] */ | ||
| 157 | 				y = 2.0f - x; | ||
| 158 | 				i = 0; | ||
| 159 | 			} else if (ix >= 0x3F9da620) { /* [1.23,1.73] */ | ||
| 160 | 				y = x - tc; | ||
| 161 | 				i = 1; | ||
| 162 | 			} else { | ||
| 163 | 				y = x - 1.0f; | ||
| 164 | 				i = 2; | ||
| 165 | 			} | ||
| 166 | 		} | ||
| 167 | 		switch(i) { | ||
| 168 | 		case 0: | ||
| 169 | 			z = y*y; | ||
| 170 | 			p1 = a0+z*(a2+z*(a4+z*(a6+z*(a8+z*a10)))); | ||
| 171 | 			p2 = z*(a1+z*(a3+z*(a5+z*(a7+z*(a9+z*a11))))); | ||
| 172 | 			p = y*p1+p2; | ||
| 173 | 			r += p - 0.5f*y; | ||
| 174 | 			break; | ||
| 175 | 		case 1: | ||
| 176 | 			z = y*y; | ||
| 177 | 			w = z*y; | ||
| 178 | 			p1 = t0+w*(t3+w*(t6+w*(t9 +w*t12))); /* parallel comp */ | ||
| 179 | 			p2 = t1+w*(t4+w*(t7+w*(t10+w*t13))); | ||
| 180 | 			p3 = t2+w*(t5+w*(t8+w*(t11+w*t14))); | ||
| 181 | 			p = z*p1-(tt-w*(p2+y*p3)); | ||
| 182 | 			r += (tf + p); | ||
| 183 | 			break; | ||
| 184 | 		case 2: | ||
| 185 | 			p1 = y*(u0+y*(u1+y*(u2+y*(u3+y*(u4+y*u5))))); | ||
| 186 | 			p2 = 1.0f+y*(v1+y*(v2+y*(v3+y*(v4+y*v5)))); | ||
| 187 | 			r += -0.5f*y + p1/p2; | ||
| 188 | 		} | ||
| 189 | 	} else if (ix < 0x41000000) { /* x < 8.0 */ | ||
| 190 | 		i = (int)x; | ||
| 191 | 		y = x - (float)i; | ||
| 192 | 		p = y*(s0+y*(s1+y*(s2+y*(s3+y*(s4+y*(s5+y*s6)))))); | ||
| 193 | 		q = 1.0f+y*(r1+y*(r2+y*(r3+y*(r4+y*(r5+y*r6))))); | ||
| 194 | 		r = 0.5f*y+p/q; | ||
| 195 | 		z = 1.0f; /* lgamma(1+s) = log(s) + lgamma(s) */ | ||
| 196 | 		switch (i) { | ||
| 197 | 		case 7: z *= y + 6.0f; /* FALLTHRU */ | ||
| 198 | 		case 6: z *= y + 5.0f; /* FALLTHRU */ | ||
| 199 | 		case 5: z *= y + 4.0f; /* FALLTHRU */ | ||
| 200 | 		case 4: z *= y + 3.0f; /* FALLTHRU */ | ||
| 201 | 		case 3: z *= y + 2.0f; /* FALLTHRU */ | ||
| 202 | 			r += logf(z); | ||
| 203 | 			break; | ||
| 204 | 		} | ||
| 205 | 	} else if (ix < 0x5c800000) { /* 8.0 <= x < 2**58 */ | ||
| 206 | 		t = logf(x); | ||
| 207 | 		z = 1.0f/x; | ||
| 208 | 		y = z*z; | ||
| 209 | 		w = w0+z*(w1+y*(w2+y*(w3+y*(w4+y*(w5+y*w6))))); | ||
| 210 | 		r = (x-0.5f)*(t-1.0f)+w; | ||
| 211 | 	} else /* 2**58 <= x <= inf */ | ||
| 212 | 		r = x*(logf(x)-1.0f); | ||
| 213 | 	if (sign) | ||
| 214 | 		r = nadj - r; | ||
| 215 | 	return r; | ||
| 216 | } | ||
| 217 | |||
| 218 | weak_alias(__lgammaf_r, lgammaf_r); | ||
lib/libc/wasi/libc-top-half/musl/src/math/lgammal.c created+353| ... | @@ -0,0 +1,353 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_lgammal.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* | ||
| 13 | * Copyright (c) 2008 Stephen L. Moshier <steve@moshier.net> | ||
| 14 | * | ||
| 15 | * Permission to use, copy, modify, and distribute this software for any | ||
| 16 | * purpose with or without fee is hereby granted, provided that the above | ||
| 17 | * copyright notice and this permission notice appear in all copies. | ||
| 18 | * | ||
| 19 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
| 20 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
| 21 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
| 22 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
| 23 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
| 24 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
| 25 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
| 26 | */ | ||
| 27 | /* lgammal(x) | ||
| 28 | * Reentrant version of the logarithm of the Gamma function | ||
| 29 | * with user provide pointer for the sign of Gamma(x). | ||
| 30 | * | ||
| 31 | * Method: | ||
| 32 | * 1. Argument Reduction for 0 < x <= 8 | ||
| 33 | * Since gamma(1+s)=s*gamma(s), for x in [0,8], we may | ||
| 34 | * reduce x to a number in [1.5,2.5] by | ||
| 35 | * lgamma(1+s) = log(s) + lgamma(s) | ||
| 36 | * for example, | ||
| 37 | * lgamma(7.3) = log(6.3) + lgamma(6.3) | ||
| 38 | * = log(6.3*5.3) + lgamma(5.3) | ||
| 39 | * = log(6.3*5.3*4.3*3.3*2.3) + lgamma(2.3) | ||
| 40 | * 2. Polynomial approximation of lgamma around its | ||
| 41 | * minimun ymin=1.461632144968362245 to maintain monotonicity. | ||
| 42 | * On [ymin-0.23, ymin+0.27] (i.e., [1.23164,1.73163]), use | ||
| 43 | * Let z = x-ymin; | ||
| 44 | * lgamma(x) = -1.214862905358496078218 + z^2*poly(z) | ||
| 45 | * 2. Rational approximation in the primary interval [2,3] | ||
| 46 | * We use the following approximation: | ||
| 47 | * s = x-2.0; | ||
| 48 | * lgamma(x) = 0.5*s + s*P(s)/Q(s) | ||
| 49 | * Our algorithms are based on the following observation | ||
| 50 | * | ||
| 51 | * zeta(2)-1 2 zeta(3)-1 3 | ||
| 52 | * lgamma(2+s) = s*(1-Euler) + --------- * s - --------- * s + ... | ||
| 53 | * 2 3 | ||
| 54 | * | ||
| 55 | * where Euler = 0.5771... is the Euler constant, which is very | ||
| 56 | * close to 0.5. | ||
| 57 | * | ||
| 58 | * 3. For x>=8, we have | ||
| 59 | * lgamma(x)~(x-0.5)log(x)-x+0.5*log(2pi)+1/(12x)-1/(360x**3)+.... | ||
| 60 | * (better formula: | ||
| 61 | * lgamma(x)~(x-0.5)*(log(x)-1)-.5*(log(2pi)-1) + ...) | ||
| 62 | * Let z = 1/x, then we approximation | ||
| 63 | * f(z) = lgamma(x) - (x-0.5)(log(x)-1) | ||
| 64 | * by | ||
| 65 | * 3 5 11 | ||
| 66 | * w = w0 + w1*z + w2*z + w3*z + ... + w6*z | ||
| 67 | * | ||
| 68 | * 4. For negative x, since (G is gamma function) | ||
| 69 | * -x*G(-x)*G(x) = pi/sin(pi*x), | ||
| 70 | * we have | ||
| 71 | * G(x) = pi/(sin(pi*x)*(-x)*G(-x)) | ||
| 72 | * since G(-x) is positive, sign(G(x)) = sign(sin(pi*x)) for x<0 | ||
| 73 | * Hence, for x<0, signgam = sign(sin(pi*x)) and | ||
| 74 | * lgamma(x) = log(|Gamma(x)|) | ||
| 75 | * = log(pi/(|x*sin(pi*x)|)) - lgamma(-x); | ||
| 76 | * Note: one should avoid compute pi*(-x) directly in the | ||
| 77 | * computation of sin(pi*(-x)). | ||
| 78 | * | ||
| 79 | * 5. Special Cases | ||
| 80 | * lgamma(2+s) ~ s*(1-Euler) for tiny s | ||
| 81 | * lgamma(1)=lgamma(2)=0 | ||
| 82 | * lgamma(x) ~ -log(x) for tiny x | ||
| 83 | * lgamma(0) = lgamma(inf) = inf | ||
| 84 | * lgamma(-integer) = +-inf | ||
| 85 | * | ||
| 86 | */ | ||
| 87 | |||
| 88 | #define _GNU_SOURCE | ||
| 89 | #include "libm.h" | ||
| 90 | |||
| 91 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 92 | long double __lgammal_r(long double x, int *sg) | ||
| 93 | { | ||
| 94 | 	return __lgamma_r(x, sg); | ||
| 95 | } | ||
| 96 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 97 | static const long double | ||
| 98 | pi = 3.14159265358979323846264L, | ||
| 99 | |||
| 100 | /* lgam(1+x) = 0.5 x + x a(x)/b(x) | ||
| 101 | -0.268402099609375 <= x <= 0 | ||
| 102 | peak relative error 6.6e-22 */ | ||
| 103 | a0 = -6.343246574721079391729402781192128239938E2L, | ||
| 104 | a1 = 1.856560238672465796768677717168371401378E3L, | ||
| 105 | a2 = 2.404733102163746263689288466865843408429E3L, | ||
| 106 | a3 = 8.804188795790383497379532868917517596322E2L, | ||
| 107 | a4 = 1.135361354097447729740103745999661157426E2L, | ||
| 108 | a5 = 3.766956539107615557608581581190400021285E0L, | ||
| 109 | |||
| 110 | b0 = 8.214973713960928795704317259806842490498E3L, | ||
| 111 | b1 = 1.026343508841367384879065363925870888012E4L, | ||
| 112 | b2 = 4.553337477045763320522762343132210919277E3L, | ||
| 113 | b3 = 8.506975785032585797446253359230031874803E2L, | ||
| 114 | b4 = 6.042447899703295436820744186992189445813E1L, | ||
| 115 | /* b5 = 1.000000000000000000000000000000000000000E0 */ | ||
| 116 | |||
| 117 | |||
| 118 | tc = 1.4616321449683623412626595423257213284682E0L, | ||
| 119 | tf = -1.2148629053584961146050602565082954242826E-1, /* double precision */ | ||
| 120 | /* tt = (tail of tf), i.e. tf + tt has extended precision. */ | ||
| 121 | tt = 3.3649914684731379602768989080467587736363E-18L, | ||
| 122 | /* lgam ( 1.4616321449683623412626595423257213284682E0 ) = | ||
| 123 | -1.2148629053584960809551455717769158215135617312999903886372437313313530E-1 */ | ||
| 124 | |||
| 125 | /* lgam (x + tc) = tf + tt + x g(x)/h(x) | ||
| 126 | -0.230003726999612341262659542325721328468 <= x | ||
| 127 | <= 0.2699962730003876587373404576742786715318 | ||
| 128 | peak relative error 2.1e-21 */ | ||
| 129 | g0 = 3.645529916721223331888305293534095553827E-18L, | ||
| 130 | g1 = 5.126654642791082497002594216163574795690E3L, | ||
| 131 | g2 = 8.828603575854624811911631336122070070327E3L, | ||
| 132 | g3 = 5.464186426932117031234820886525701595203E3L, | ||
| 133 | g4 = 1.455427403530884193180776558102868592293E3L, | ||
| 134 | g5 = 1.541735456969245924860307497029155838446E2L, | ||
| 135 | g6 = 4.335498275274822298341872707453445815118E0L, | ||
| 136 | |||
| 137 | h0 = 1.059584930106085509696730443974495979641E4L, | ||
| 138 | h1 = 2.147921653490043010629481226937850618860E4L, | ||
| 139 | h2 = 1.643014770044524804175197151958100656728E4L, | ||
| 140 | h3 = 5.869021995186925517228323497501767586078E3L, | ||
| 141 | h4 = 9.764244777714344488787381271643502742293E2L, | ||
| 142 | h5 = 6.442485441570592541741092969581997002349E1L, | ||
| 143 | /* h6 = 1.000000000000000000000000000000000000000E0 */ | ||
| 144 | |||
| 145 | |||
| 146 | /* lgam (x+1) = -0.5 x + x u(x)/v(x) | ||
| 147 | -0.100006103515625 <= x <= 0.231639862060546875 | ||
| 148 | peak relative error 1.3e-21 */ | ||
| 149 | u0 = -8.886217500092090678492242071879342025627E1L, | ||
| 150 | u1 = 6.840109978129177639438792958320783599310E2L, | ||
| 151 | u2 = 2.042626104514127267855588786511809932433E3L, | ||
| 152 | u3 = 1.911723903442667422201651063009856064275E3L, | ||
| 153 | u4 = 7.447065275665887457628865263491667767695E2L, | ||
| 154 | u5 = 1.132256494121790736268471016493103952637E2L, | ||
| 155 | u6 = 4.484398885516614191003094714505960972894E0L, | ||
| 156 | |||
| 157 | v0 = 1.150830924194461522996462401210374632929E3L, | ||
| 158 | v1 = 3.399692260848747447377972081399737098610E3L, | ||
| 159 | v2 = 3.786631705644460255229513563657226008015E3L, | ||
| 160 | v3 = 1.966450123004478374557778781564114347876E3L, | ||
| 161 | v4 = 4.741359068914069299837355438370682773122E2L, | ||
| 162 | v5 = 4.508989649747184050907206782117647852364E1L, | ||
| 163 | /* v6 = 1.000000000000000000000000000000000000000E0 */ | ||
| 164 | |||
| 165 | |||
| 166 | /* lgam (x+2) = .5 x + x s(x)/r(x) | ||
| 167 | 0 <= x <= 1 | ||
| 168 | peak relative error 7.2e-22 */ | ||
| 169 | s0 = 1.454726263410661942989109455292824853344E6L, | ||
| 170 | s1 = -3.901428390086348447890408306153378922752E6L, | ||
| 171 | s2 = -6.573568698209374121847873064292963089438E6L, | ||
| 172 | s3 = -3.319055881485044417245964508099095984643E6L, | ||
| 173 | s4 = -7.094891568758439227560184618114707107977E5L, | ||
| 174 | s5 = -6.263426646464505837422314539808112478303E4L, | ||
| 175 | s6 = -1.684926520999477529949915657519454051529E3L, | ||
| 176 | |||
| 177 | r0 = -1.883978160734303518163008696712983134698E7L, | ||
| 178 | r1 = -2.815206082812062064902202753264922306830E7L, | ||
| 179 | r2 = -1.600245495251915899081846093343626358398E7L, | ||
| 180 | r3 = -4.310526301881305003489257052083370058799E6L, | ||
| 181 | r4 = -5.563807682263923279438235987186184968542E5L, | ||
| 182 | r5 = -3.027734654434169996032905158145259713083E4L, | ||
| 183 | r6 = -4.501995652861105629217250715790764371267E2L, | ||
| 184 | /* r6 = 1.000000000000000000000000000000000000000E0 */ | ||
| 185 | |||
| 186 | |||
| 187 | /* lgam(x) = ( x - 0.5 ) * log(x) - x + LS2PI + 1/x w(1/x^2) | ||
| 188 | x >= 8 | ||
| 189 | Peak relative error 1.51e-21 | ||
| 190 | w0 = LS2PI - 0.5 */ | ||
| 191 | w0 = 4.189385332046727417803e-1L, | ||
| 192 | w1 = 8.333333333333331447505E-2L, | ||
| 193 | w2 = -2.777777777750349603440E-3L, | ||
| 194 | w3 = 7.936507795855070755671E-4L, | ||
| 195 | w4 = -5.952345851765688514613E-4L, | ||
| 196 | w5 = 8.412723297322498080632E-4L, | ||
| 197 | w6 = -1.880801938119376907179E-3L, | ||
| 198 | w7 = 4.885026142432270781165E-3L; | ||
| 199 | |||
| 200 | /* sin(pi*x) assuming x > 2^-1000, if sin(pi*x)==0 the sign is arbitrary */ | ||
| 201 | static long double sin_pi(long double x) | ||
| 202 | { | ||
| 203 | 	int n; | ||
| 204 | |||
| 205 | 	/* spurious inexact if odd int */ | ||
| 206 | 	x *= 0.5; | ||
| 207 | 	x = 2.0*(x - floorl(x)); /* x mod 2.0 */ | ||
| 208 | |||
| 209 | 	n = (int)(x*4.0); | ||
| 210 | 	n = (n+1)/2; | ||
| 211 | 	x -= n*0.5f; | ||
| 212 | 	x *= pi; | ||
| 213 | |||
| 214 | 	switch (n) { | ||
| 215 | 	default: /* case 4: */ | ||
| 216 | 	case 0: return __sinl(x, 0.0, 0); | ||
| 217 | 	case 1: return __cosl(x, 0.0); | ||
| 218 | 	case 2: return __sinl(-x, 0.0, 0); | ||
| 219 | 	case 3: return -__cosl(x, 0.0); | ||
| 220 | 	} | ||
| 221 | } | ||
| 222 | |||
| 223 | long double __lgammal_r(long double x, int *sg) { | ||
| 224 | 	long double t, y, z, nadj, p, p1, p2, q, r, w; | ||
| 225 | 	union ldshape u = {x}; | ||
| 226 | 	uint32_t ix = (u.i.se & 0x7fffU)<<16 | u.i.m>>48; | ||
| 227 | 	int sign = u.i.se >> 15; | ||
| 228 | 	int i; | ||
| 229 | |||
| 230 | 	*sg = 1; | ||
| 231 | |||
| 232 | 	/* purge off +-inf, NaN, +-0, tiny and negative arguments */ | ||
| 233 | 	if (ix >= 0x7fff0000) | ||
| 234 | 		return x * x; | ||
| 235 | 	if (ix < 0x3fc08000) { /* |x|<2**-63, return -log(|x|) */ | ||
| 236 | 		if (sign) { | ||
| 237 | 			*sg = -1; | ||
| 238 | 			x = -x; | ||
| 239 | 		} | ||
| 240 | 		return -logl(x); | ||
| 241 | 	} | ||
| 242 | 	if (sign) { | ||
| 243 | 		x = -x; | ||
| 244 | 		t = sin_pi(x); | ||
| 245 | 		if (t == 0.0) | ||
| 246 | 			return 1.0 / (x-x); /* -integer */ | ||
| 247 | 		if (t > 0.0) | ||
| 248 | 			*sg = -1; | ||
| 249 | 		else | ||
| 250 | 			t = -t; | ||
| 251 | 		nadj = logl(pi / (t * x)); | ||
| 252 | 	} | ||
| 253 | |||
| 254 | 	/* purge off 1 and 2 (so the sign is ok with downward rounding) */ | ||
| 255 | 	if ((ix == 0x3fff8000 || ix == 0x40008000) && u.i.m == 0) { | ||
| 256 | 		r = 0; | ||
| 257 | 	} else if (ix < 0x40008000) { /* x < 2.0 */ | ||
| 258 | 		if (ix <= 0x3ffee666) { /* 8.99993896484375e-1 */ | ||
| 259 | 			/* lgamma(x) = lgamma(x+1) - log(x) */ | ||
| 260 | 			r = -logl(x); | ||
| 261 | 			if (ix >= 0x3ffebb4a) { /* 7.31597900390625e-1 */ | ||
| 262 | 				y = x - 1.0; | ||
| 263 | 				i = 0; | ||
| 264 | 			} else if (ix >= 0x3ffced33) { /* 2.31639862060546875e-1 */ | ||
| 265 | 				y = x - (tc - 1.0); | ||
| 266 | 				i = 1; | ||
| 267 | 			} else { /* x < 0.23 */ | ||
| 268 | 				y = x; | ||
| 269 | 				i = 2; | ||
| 270 | 			} | ||
| 271 | 		} else { | ||
| 272 | 			r = 0.0; | ||
| 273 | 			if (ix >= 0x3fffdda6) { /* 1.73162841796875 */ | ||
| 274 | 				/* [1.7316,2] */ | ||
| 275 | 				y = x - 2.0; | ||
| 276 | 				i = 0; | ||
| 277 | 			} else if (ix >= 0x3fff9da6) { /* 1.23162841796875 */ | ||
| 278 | 				/* [1.23,1.73] */ | ||
| 279 | 				y = x - tc; | ||
| 280 | 				i = 1; | ||
| 281 | 			} else { | ||
| 282 | 				/* [0.9, 1.23] */ | ||
| 283 | 				y = x - 1.0; | ||
| 284 | 				i = 2; | ||
| 285 | 			} | ||
| 286 | 		} | ||
| 287 | 		switch (i) { | ||
| 288 | 		case 0: | ||
| 289 | 			p1 = a0 + y * (a1 + y * (a2 + y * (a3 + y * (a4 + y * a5)))); | ||
| 290 | 			p2 = b0 + y * (b1 + y * (b2 + y * (b3 + y * (b4 + y)))); | ||
| 291 | 			r += 0.5 * y + y * p1/p2; | ||
| 292 | 			break; | ||
| 293 | 		case 1: | ||
| 294 | 			p1 = g0 + y * (g1 + y * (g2 + y * (g3 + y * (g4 + y * (g5 + y * g6))))); | ||
| 295 | 			p2 = h0 + y * (h1 + y * (h2 + y * (h3 + y * (h4 + y * (h5 + y))))); | ||
| 296 | 			p = tt + y * p1/p2; | ||
| 297 | 			r += (tf + p); | ||
| 298 | 			break; | ||
| 299 | 		case 2: | ||
| 300 | 			p1 = y * (u0 + y * (u1 + y * (u2 + y * (u3 + y * (u4 + y * (u5 + y * u6)))))); | ||
| 301 | 			p2 = v0 + y * (v1 + y * (v2 + y * (v3 + y * (v4 + y * (v5 + y))))); | ||
| 302 | 			r += (-0.5 * y + p1 / p2); | ||
| 303 | 		} | ||
| 304 | 	} else if (ix < 0x40028000) { /* 8.0 */ | ||
| 305 | 		/* x < 8.0 */ | ||
| 306 | 		i = (int)x; | ||
| 307 | 		y = x - (double)i; | ||
| 308 | 		p = y * (s0 + y * (s1 + y * (s2 + y * (s3 + y * (s4 + y * (s5 + y * s6)))))); | ||
| 309 | 		q = r0 + y * (r1 + y * (r2 + y * (r3 + y * (r4 + y * (r5 + y * (r6 + y)))))); | ||
| 310 | 		r = 0.5 * y + p / q; | ||
| 311 | 		z = 1.0; | ||
| 312 | 		/* lgamma(1+s) = log(s) + lgamma(s) */ | ||
| 313 | 		switch (i) { | ||
| 314 | 		case 7: | ||
| 315 | 			z *= (y + 6.0); /* FALLTHRU */ | ||
| 316 | 		case 6: | ||
| 317 | 			z *= (y + 5.0); /* FALLTHRU */ | ||
| 318 | 		case 5: | ||
| 319 | 			z *= (y + 4.0); /* FALLTHRU */ | ||
| 320 | 		case 4: | ||
| 321 | 			z *= (y + 3.0); /* FALLTHRU */ | ||
| 322 | 		case 3: | ||
| 323 | 			z *= (y + 2.0); /* FALLTHRU */ | ||
| 324 | 			r += logl(z); | ||
| 325 | 			break; | ||
| 326 | 		} | ||
| 327 | 	} else if (ix < 0x40418000) { /* 2^66 */ | ||
| 328 | 		/* 8.0 <= x < 2**66 */ | ||
| 329 | 		t = logl(x); | ||
| 330 | 		z = 1.0 / x; | ||
| 331 | 		y = z * z; | ||
| 332 | 		w = w0 + z * (w1 + y * (w2 + y * (w3 + y * (w4 + y * (w5 + y * (w6 + y * w7)))))); | ||
| 333 | 		r = (x - 0.5) * (t - 1.0) + w; | ||
| 334 | 	} else /* 2**66 <= x <= inf */ | ||
| 335 | 		r = x * (logl(x) - 1.0); | ||
| 336 | 	if (sign) | ||
| 337 | 		r = nadj - r; | ||
| 338 | 	return r; | ||
| 339 | } | ||
| 340 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 341 | // TODO: broken implementation to make things compile | ||
| 342 | long double __lgammal_r(long double x, int *sg) | ||
| 343 | { | ||
| 344 | 	return __lgamma_r(x, sg); | ||
| 345 | } | ||
| 346 | #endif | ||
| 347 | |||
| 348 | long double lgammal(long double x) | ||
| 349 | { | ||
| 350 | 	return __lgammal_r(x, &__signgam); | ||
| 351 | } | ||
| 352 | |||
| 353 | weak_alias(__lgammal_r, lgammal_r); | ||
lib/libc/wasi/libc-top-half/musl/src/math/llrint.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | /* uses LLONG_MAX > 2^53, see comments in lrint.c */ | ||
| 4 | |||
| 5 | long long llrint(double x) | ||
| 6 | { | ||
| 7 | 	return rint(x); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/llrintf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | /* uses LLONG_MAX > 2^24, see comments in lrint.c */ | ||
| 4 | |||
| 5 | long long llrintf(float x) | ||
| 6 | { | ||
| 7 | 	return rintf(x); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/llrintl.c created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <fenv.h> | ||
| 3 | #include "libm.h" | ||
| 4 | |||
| 5 | |||
| 6 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 7 | long long llrintl(long double x) | ||
| 8 | { | ||
| 9 | 	return llrint(x); | ||
| 10 | } | ||
| 11 | #elif defined(FE_INEXACT) | ||
| 12 | /* | ||
| 13 | see comments in lrint.c | ||
| 14 | |||
| 15 | Note that if LLONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64 | ||
| 16 | then x == 2**63 - 0.5 is the only input that overflows and | ||
| 17 | raises inexact (with tonearest or upward rounding mode) | ||
| 18 | */ | ||
| 19 | long long llrintl(long double x) | ||
| 20 | { | ||
| 21 | 	#pragma STDC FENV_ACCESS ON | ||
| 22 | 	int e; | ||
| 23 | |||
| 24 | 	e = fetestexcept(FE_INEXACT); | ||
| 25 | 	x = rintl(x); | ||
| 26 | 	if (!e && (x > LLONG_MAX || x < LLONG_MIN)) | ||
| 27 | 		feclearexcept(FE_INEXACT); | ||
| 28 | 	/* conversion */ | ||
| 29 | 	return x; | ||
| 30 | } | ||
| 31 | #else | ||
| 32 | long long llrintl(long double x) | ||
| 33 | { | ||
| 34 | 	return rintl(x); | ||
| 35 | } | ||
| 36 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/llround.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llround(double x) | ||
| 4 | { | ||
| 5 | 	return round(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/llroundf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llroundf(float x) | ||
| 4 | { | ||
| 5 | 	return roundf(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/llroundl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llroundl(long double x) | ||
| 4 | { | ||
| 5 | 	return roundl(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log.c created+112| ... | @@ -0,0 +1,112 @@ | ||
| 1 | /* | ||
| 2 | * Double-precision log(x) function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "log_data.h" | ||
| 12 | |||
| 13 | #define T __log_data.tab | ||
| 14 | #define T2 __log_data.tab2 | ||
| 15 | #define B __log_data.poly1 | ||
| 16 | #define A __log_data.poly | ||
| 17 | #define Ln2hi __log_data.ln2hi | ||
| 18 | #define Ln2lo __log_data.ln2lo | ||
| 19 | #define N (1 << LOG_TABLE_BITS) | ||
| 20 | #define OFF 0x3fe6000000000000 | ||
| 21 | |||
| 22 | /* Top 16 bits of a double. */ | ||
| 23 | static inline uint32_t top16(double x) | ||
| 24 | { | ||
| 25 | 	return asuint64(x) >> 48; | ||
| 26 | } | ||
| 27 | |||
| 28 | double log(double x) | ||
| 29 | { | ||
| 30 | 	double_t w, z, r, r2, r3, y, invc, logc, kd, hi, lo; | ||
| 31 | 	uint64_t ix, iz, tmp; | ||
| 32 | 	uint32_t top; | ||
| 33 | 	int k, i; | ||
| 34 | |||
| 35 | 	ix = asuint64(x); | ||
| 36 | 	top = top16(x); | ||
| 37 | #define LO asuint64(1.0 - 0x1p-4) | ||
| 38 | #define HI asuint64(1.0 + 0x1.09p-4) | ||
| 39 | 	if (predict_false(ix - LO < HI - LO)) { | ||
| 40 | 		/* Handle close to 1.0 inputs separately. */ | ||
| 41 | 		/* Fix sign of zero with downward rounding when x==1. */ | ||
| 42 | 		if (WANT_ROUNDING && predict_false(ix == asuint64(1.0))) | ||
| 43 | 			return 0; | ||
| 44 | 		r = x - 1.0; | ||
| 45 | 		r2 = r * r; | ||
| 46 | 		r3 = r * r2; | ||
| 47 | 		y = r3 * | ||
| 48 | 		 (B[1] + r * B[2] + r2 * B[3] + | ||
| 49 | 		 r3 * (B[4] + r * B[5] + r2 * B[6] + | ||
| 50 | 			 r3 * (B[7] + r * B[8] + r2 * B[9] + r3 * B[10]))); | ||
| 51 | 		/* Worst-case error is around 0.507 ULP. */ | ||
| 52 | 		w = r * 0x1p27; | ||
| 53 | 		double_t rhi = r + w - w; | ||
| 54 | 		double_t rlo = r - rhi; | ||
| 55 | 		w = rhi * rhi * B[0]; /* B[0] == -0.5. */ | ||
| 56 | 		hi = r + w; | ||
| 57 | 		lo = r - hi + w; | ||
| 58 | 		lo += B[0] * rlo * (rhi + r); | ||
| 59 | 		y += lo; | ||
| 60 | 		y += hi; | ||
| 61 | 		return eval_as_double(y); | ||
| 62 | 	} | ||
| 63 | 	if (predict_false(top - 0x0010 >= 0x7ff0 - 0x0010)) { | ||
| 64 | 		/* x < 0x1p-1022 or inf or nan. */ | ||
| 65 | 		if (ix * 2 == 0) | ||
| 66 | 			return __math_divzero(1); | ||
| 67 | 		if (ix == asuint64(INFINITY)) /* log(inf) == inf. */ | ||
| 68 | 			return x; | ||
| 69 | 		if ((top & 0x8000) || (top & 0x7ff0) == 0x7ff0) | ||
| 70 | 			return __math_invalid(x); | ||
| 71 | 		/* x is subnormal, normalize it. */ | ||
| 72 | 		ix = asuint64(x * 0x1p52); | ||
| 73 | 		ix -= 52ULL << 52; | ||
| 74 | 	} | ||
| 75 | |||
| 76 | 	/* x = 2^k z; where z is in range [OFF,2*OFF) and exact. | ||
| 77 | 	 The range is split into N subintervals. | ||
| 78 | 	 The ith subinterval contains z and c is near its center. */ | ||
| 79 | 	tmp = ix - OFF; | ||
| 80 | 	i = (tmp >> (52 - LOG_TABLE_BITS)) % N; | ||
| 81 | 	k = (int64_t)tmp >> 52; /* arithmetic shift */ | ||
| 82 | 	iz = ix - (tmp & 0xfffULL << 52); | ||
| 83 | 	invc = T[i].invc; | ||
| 84 | 	logc = T[i].logc; | ||
| 85 | 	z = asdouble(iz); | ||
| 86 | |||
| 87 | 	/* log(x) = log1p(z/c-1) + log(c) + k*Ln2. */ | ||
| 88 | 	/* r ~= z/c - 1, |r| < 1/(2*N). */ | ||
| 89 | #if __FP_FAST_FMA | ||
| 90 | 	/* rounding error: 0x1p-55/N. */ | ||
| 91 | 	r = __builtin_fma(z, invc, -1.0); | ||
| 92 | #else | ||
| 93 | 	/* rounding error: 0x1p-55/N + 0x1p-66. */ | ||
| 94 | 	r = (z - T2[i].chi - T2[i].clo) * invc; | ||
| 95 | #endif | ||
| 96 | 	kd = (double_t)k; | ||
| 97 | |||
| 98 | 	/* hi + lo = r + log(c) + k*Ln2. */ | ||
| 99 | 	w = kd * Ln2hi + logc; | ||
| 100 | 	hi = w + r; | ||
| 101 | 	lo = w - hi + r + kd * Ln2lo; | ||
| 102 | |||
| 103 | 	/* log(x) = lo + (log1p(r) - r) + hi. */ | ||
| 104 | 	r2 = r * r; /* rounding error: 0x1p-54/N^2. */ | ||
| 105 | 	/* Worst case error if |y| > 0x1p-5: | ||
| 106 | 	 0.5 + 4.13/N + abs-poly-error*2^57 ULP (+ 0.002 ULP without fma) | ||
| 107 | 	 Worst case error if |y| > 0x1p-4: | ||
| 108 | 	 0.5 + 2.06/N + abs-poly-error*2^56 ULP (+ 0.001 ULP without fma). */ | ||
| 109 | 	y = lo + r2 * A[0] + | ||
| 110 | 	 r * r2 * (A[1] + r * A[2] + r2 * (A[3] + r * A[4])) + hi; | ||
| 111 | 	return eval_as_double(y); | ||
| 112 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log10.c created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_log10.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 | /* | ||
| 13 | * Return the base 10 logarithm of x. See log.c for most comments. | ||
| 14 | * | ||
| 15 | * Reduce x to 2^k (1+f) and calculate r = log(1+f) - f + f*f/2 | ||
| 16 | * as in log.c, then combine and scale in extra precision: | ||
| 17 | * log10(x) = (f - f*f/2 + r)/log(10) + k*log10(2) | ||
| 18 | */ | ||
| 19 | |||
| 20 | #include <math.h> | ||
| 21 | #include <stdint.h> | ||
| 22 | |||
| 23 | static const double | ||
| 24 | ivln10hi = 4.34294481878168880939e-01, /* 0x3fdbcb7b, 0x15200000 */ | ||
| 25 | ivln10lo = 2.50829467116452752298e-11, /* 0x3dbb9438, 0xca9aadd5 */ | ||
| 26 | log10_2hi = 3.01029995663611771306e-01, /* 0x3FD34413, 0x509F6000 */ | ||
| 27 | log10_2lo = 3.69423907715893078616e-13, /* 0x3D59FEF3, 0x11F12B36 */ | ||
| 28 | Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ | ||
| 29 | Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ | ||
| 30 | Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ | ||
| 31 | Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ | ||
| 32 | Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ | ||
| 33 | Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ | ||
| 34 | Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ | ||
| 35 | |||
| 36 | double log10(double x) | ||
| 37 | { | ||
| 38 | 	union {double f; uint64_t i;} u = {x}; | ||
| 39 | 	double_t hfsq,f,s,z,R,w,t1,t2,dk,y,hi,lo,val_hi,val_lo; | ||
| 40 | 	uint32_t hx; | ||
| 41 | 	int k; | ||
| 42 | |||
| 43 | 	hx = u.i>>32; | ||
| 44 | 	k = 0; | ||
| 45 | 	if (hx < 0x00100000 || hx>>31) { | ||
| 46 | 		if (u.i<<1 == 0) | ||
| 47 | 			return -1/(x*x); /* log(+-0)=-inf */ | ||
| 48 | 		if (hx>>31) | ||
| 49 | 			return (x-x)/0.0; /* log(-#) = NaN */ | ||
| 50 | 		/* subnormal number, scale x up */ | ||
| 51 | 		k -= 54; | ||
| 52 | 		x *= 0x1p54; | ||
| 53 | 		u.f = x; | ||
| 54 | 		hx = u.i>>32; | ||
| 55 | 	} else if (hx >= 0x7ff00000) { | ||
| 56 | 		return x; | ||
| 57 | 	} else if (hx == 0x3ff00000 && u.i<<32 == 0) | ||
| 58 | 		return 0; | ||
| 59 | |||
| 60 | 	/* reduce x into [sqrt(2)/2, sqrt(2)] */ | ||
| 61 | 	hx += 0x3ff00000 - 0x3fe6a09e; | ||
| 62 | 	k += (int)(hx>>20) - 0x3ff; | ||
| 63 | 	hx = (hx&0x000fffff) + 0x3fe6a09e; | ||
| 64 | 	u.i = (uint64_t)hx<<32 | (u.i&0xffffffff); | ||
| 65 | 	x = u.f; | ||
| 66 | |||
| 67 | 	f = x - 1.0; | ||
| 68 | 	hfsq = 0.5*f*f; | ||
| 69 | 	s = f/(2.0+f); | ||
| 70 | 	z = s*s; | ||
| 71 | 	w = z*z; | ||
| 72 | 	t1 = w*(Lg2+w*(Lg4+w*Lg6)); | ||
| 73 | 	t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); | ||
| 74 | 	R = t2 + t1; | ||
| 75 | |||
| 76 | 	/* See log2.c for details. */ | ||
| 77 | 	/* hi+lo = f - hfsq + s*(hfsq+R) ~ log(1+f) */ | ||
| 78 | 	hi = f - hfsq; | ||
| 79 | 	u.f = hi; | ||
| 80 | 	u.i &= (uint64_t)-1<<32; | ||
| 81 | 	hi = u.f; | ||
| 82 | 	lo = f - hi - hfsq + s*(hfsq+R); | ||
| 83 | |||
| 84 | 	/* val_hi+val_lo ~ log10(1+f) + k*log10(2) */ | ||
| 85 | 	val_hi = hi*ivln10hi; | ||
| 86 | 	dk = k; | ||
| 87 | 	y = dk*log10_2hi; | ||
| 88 | 	val_lo = dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi; | ||
| 89 | |||
| 90 | 	/* | ||
| 91 | 	 * Extra precision in for adding y is not strictly needed | ||
| 92 | 	 * since there is no very large cancellation near x = sqrt(2) or | ||
| 93 | 	 * x = 1/sqrt(2), but we do it anyway since it costs little on CPUs | ||
| 94 | 	 * with some parallelism and it reduces the error for many args. | ||
| 95 | 	 */ | ||
| 96 | 	w = y + val_hi; | ||
| 97 | 	val_lo += (y - w) + val_hi; | ||
| 98 | 	val_hi = w; | ||
| 99 | |||
| 100 | 	return val_lo + val_hi; | ||
| 101 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log10f.c created+77| ... | @@ -0,0 +1,77 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_log10f.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* | ||
| 13 | * See comments in log10.c. | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <math.h> | ||
| 17 | #include <stdint.h> | ||
| 18 | |||
| 19 | static const float | ||
| 20 | ivln10hi = 4.3432617188e-01, /* 0x3ede6000 */ | ||
| 21 | ivln10lo = -3.1689971365e-05, /* 0xb804ead9 */ | ||
| 22 | log10_2hi = 3.0102920532e-01, /* 0x3e9a2080 */ | ||
| 23 | log10_2lo = 7.9034151668e-07, /* 0x355427db */ | ||
| 24 | /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ | ||
| 25 | Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ | ||
| 26 | Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ | ||
| 27 | Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ | ||
| 28 | Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ | ||
| 29 | |||
| 30 | float log10f(float x) | ||
| 31 | { | ||
| 32 | 	union {float f; uint32_t i;} u = {x}; | ||
| 33 | 	float_t hfsq,f,s,z,R,w,t1,t2,dk,hi,lo; | ||
| 34 | 	uint32_t ix; | ||
| 35 | 	int k; | ||
| 36 | |||
| 37 | 	ix = u.i; | ||
| 38 | 	k = 0; | ||
| 39 | 	if (ix < 0x00800000 || ix>>31) { /* x < 2**-126 */ | ||
| 40 | 		if (ix<<1 == 0) | ||
| 41 | 			return -1/(x*x); /* log(+-0)=-inf */ | ||
| 42 | 		if (ix>>31) | ||
| 43 | 			return (x-x)/0.0f; /* log(-#) = NaN */ | ||
| 44 | 		/* subnormal number, scale up x */ | ||
| 45 | 		k -= 25; | ||
| 46 | 		x *= 0x1p25f; | ||
| 47 | 		u.f = x; | ||
| 48 | 		ix = u.i; | ||
| 49 | 	} else if (ix >= 0x7f800000) { | ||
| 50 | 		return x; | ||
| 51 | 	} else if (ix == 0x3f800000) | ||
| 52 | 		return 0; | ||
| 53 | |||
| 54 | 	/* reduce x into [sqrt(2)/2, sqrt(2)] */ | ||
| 55 | 	ix += 0x3f800000 - 0x3f3504f3; | ||
| 56 | 	k += (int)(ix>>23) - 0x7f; | ||
| 57 | 	ix = (ix&0x007fffff) + 0x3f3504f3; | ||
| 58 | 	u.i = ix; | ||
| 59 | 	x = u.f; | ||
| 60 | |||
| 61 | 	f = x - 1.0f; | ||
| 62 | 	s = f/(2.0f + f); | ||
| 63 | 	z = s*s; | ||
| 64 | 	w = z*z; | ||
| 65 | 	t1= w*(Lg2+w*Lg4); | ||
| 66 | 	t2= z*(Lg1+w*Lg3); | ||
| 67 | 	R = t2 + t1; | ||
| 68 | 	hfsq = 0.5f*f*f; | ||
| 69 | |||
| 70 | 	hi = f - hfsq; | ||
| 71 | 	u.f = hi; | ||
| 72 | 	u.i &= 0xfffff000; | ||
| 73 | 	hi = u.f; | ||
| 74 | 	lo = f - hi - hfsq + s*(hfsq+R); | ||
| 75 | 	dk = k; | ||
| 76 | 	return dk*log10_2lo + (lo+hi)*ivln10lo + lo*ivln10hi + hi*ivln10hi + dk*log10_2hi; | ||
| 77 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log10l.c created+191| ... | @@ -0,0 +1,191 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log10l.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 | /* | ||
| 18 | * Common logarithm, long double precision | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * long double x, y, log10l(); | ||
| 24 | * | ||
| 25 | * y = log10l( x ); | ||
| 26 | * | ||
| 27 | * | ||
| 28 | * DESCRIPTION: | ||
| 29 | * | ||
| 30 | * Returns the base 10 logarithm of x. | ||
| 31 | * | ||
| 32 | * The argument is separated into its exponent and fractional | ||
| 33 | * parts. If the exponent is between -1 and +1, the logarithm | ||
| 34 | * of the fraction is approximated by | ||
| 35 | * | ||
| 36 | * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). | ||
| 37 | * | ||
| 38 | * Otherwise, setting z = 2(x-1)/x+1), | ||
| 39 | * | ||
| 40 | * log(x) = z + z**3 P(z)/Q(z). | ||
| 41 | * | ||
| 42 | * | ||
| 43 | * ACCURACY: | ||
| 44 | * | ||
| 45 | * Relative error: | ||
| 46 | * arithmetic domain # trials peak rms | ||
| 47 | * IEEE 0.5, 2.0 30000 9.0e-20 2.6e-20 | ||
| 48 | * IEEE exp(+-10000) 30000 6.0e-20 2.3e-20 | ||
| 49 | * | ||
| 50 | * In the tests over the interval exp(+-10000), the logarithms | ||
| 51 | * of the random arguments were uniformly distributed over | ||
| 52 | * [-10000, +10000]. | ||
| 53 | * | ||
| 54 | * ERROR MESSAGES: | ||
| 55 | * | ||
| 56 | * log singularity: x = 0; returns MINLOG | ||
| 57 | * log domain: x < 0; returns MINLOG | ||
| 58 | */ | ||
| 59 | |||
| 60 | #include "libm.h" | ||
| 61 | |||
| 62 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 63 | long double log10l(long double x) | ||
| 64 | { | ||
| 65 | 	return log10(x); | ||
| 66 | } | ||
| 67 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 68 | /* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) | ||
| 69 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 70 | * Theoretical peak relative error = 6.2e-22 | ||
| 71 | */ | ||
| 72 | static const long double P[] = { | ||
| 73 | 4.9962495940332550844739E-1L, | ||
| 74 | 1.0767376367209449010438E1L, | ||
| 75 | 7.7671073698359539859595E1L, | ||
| 76 | 2.5620629828144409632571E2L, | ||
| 77 | 4.2401812743503691187826E2L, | ||
| 78 | 3.4258224542413922935104E2L, | ||
| 79 | 1.0747524399916215149070E2L, | ||
| 80 | }; | ||
| 81 | static const long double Q[] = { | ||
| 82 | /* 1.0000000000000000000000E0,*/ | ||
| 83 | 2.3479774160285863271658E1L, | ||
| 84 | 1.9444210022760132894510E2L, | ||
| 85 | 7.7952888181207260646090E2L, | ||
| 86 | 1.6911722418503949084863E3L, | ||
| 87 | 2.0307734695595183428202E3L, | ||
| 88 | 1.2695660352705325274404E3L, | ||
| 89 | 3.2242573199748645407652E2L, | ||
| 90 | }; | ||
| 91 | |||
| 92 | /* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), | ||
| 93 | * where z = 2(x-1)/(x+1) | ||
| 94 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 95 | * Theoretical peak relative error = 6.16e-22 | ||
| 96 | */ | ||
| 97 | static const long double R[4] = { | ||
| 98 | 1.9757429581415468984296E-3L, | ||
| 99 | -7.1990767473014147232598E-1L, | ||
| 100 | 1.0777257190312272158094E1L, | ||
| 101 | -3.5717684488096787370998E1L, | ||
| 102 | }; | ||
| 103 | static const long double S[4] = { | ||
| 104 | /* 1.00000000000000000000E0L,*/ | ||
| 105 | -2.6201045551331104417768E1L, | ||
| 106 | 1.9361891836232102174846E2L, | ||
| 107 | -4.2861221385716144629696E2L, | ||
| 108 | }; | ||
| 109 | /* log10(2) */ | ||
| 110 | #define L102A 0.3125L | ||
| 111 | #define L102B -1.1470004336018804786261e-2L | ||
| 112 | /* log10(e) */ | ||
| 113 | #define L10EA 0.5L | ||
| 114 | #define L10EB -6.5705518096748172348871e-2L | ||
| 115 | |||
| 116 | #define SQRTH 0.70710678118654752440L | ||
| 117 | |||
| 118 | long double log10l(long double x) | ||
| 119 | { | ||
| 120 | 	long double y, z; | ||
| 121 | 	int e; | ||
| 122 | |||
| 123 | 	if (isnan(x)) | ||
| 124 | 		return x; | ||
| 125 | 	if(x <= 0.0) { | ||
| 126 | 		if(x == 0.0) | ||
| 127 | 			return -1.0 / (x*x); | ||
| 128 | 		return (x - x) / 0.0; | ||
| 129 | 	} | ||
| 130 | 	if (x == INFINITY) | ||
| 131 | 		return INFINITY; | ||
| 132 | 	/* separate mantissa from exponent */ | ||
| 133 | 	/* Note, frexp is used so that denormal numbers | ||
| 134 | 	 * will be handled properly. | ||
| 135 | 	 */ | ||
| 136 | 	x = frexpl(x, &e); | ||
| 137 | |||
| 138 | 	/* logarithm using log(x) = z + z**3 P(z)/Q(z), | ||
| 139 | 	 * where z = 2(x-1)/x+1) | ||
| 140 | 	 */ | ||
| 141 | 	if (e > 2 || e < -2) { | ||
| 142 | 		if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ | ||
| 143 | 			e -= 1; | ||
| 144 | 			z = x - 0.5; | ||
| 145 | 			y = 0.5 * z + 0.5; | ||
| 146 | 		} else { /* 2 (x-1)/(x+1) */ | ||
| 147 | 			z = x - 0.5; | ||
| 148 | 			z -= 0.5; | ||
| 149 | 			y = 0.5 * x + 0.5; | ||
| 150 | 		} | ||
| 151 | 		x = z / y; | ||
| 152 | 		z = x*x; | ||
| 153 | 		y = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); | ||
| 154 | 		goto done; | ||
| 155 | 	} | ||
| 156 | |||
| 157 | 	/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ | ||
| 158 | 	if (x < SQRTH) { | ||
| 159 | 		e -= 1; | ||
| 160 | 		x = 2.0*x - 1.0; | ||
| 161 | 	} else { | ||
| 162 | 		x = x - 1.0; | ||
| 163 | 	} | ||
| 164 | 	z = x*x; | ||
| 165 | 	y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 7)); | ||
| 166 | 	y = y - 0.5*z; | ||
| 167 | |||
| 168 | done: | ||
| 169 | 	/* Multiply log of fraction by log10(e) | ||
| 170 | 	 * and base 2 exponent by log10(2). | ||
| 171 | 	 * | ||
| 172 | 	 * ***CAUTION*** | ||
| 173 | 	 * | ||
| 174 | 	 * This sequence of operations is critical and it may | ||
| 175 | 	 * be horribly defeated by some compiler optimizers. | ||
| 176 | 	 */ | ||
| 177 | 	z = y * (L10EB); | ||
| 178 | 	z += x * (L10EB); | ||
| 179 | 	z += e * (L102B); | ||
| 180 | 	z += y * (L10EA); | ||
| 181 | 	z += x * (L10EA); | ||
| 182 | 	z += e * (L102A); | ||
| 183 | 	return z; | ||
| 184 | } | ||
| 185 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 186 | // TODO: broken implementation to make things compile | ||
| 187 | long double log10l(long double x) | ||
| 188 | { | ||
| 189 | 	return log10(x); | ||
| 190 | } | ||
| 191 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/log1p.c created+122| ... | @@ -0,0 +1,122 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_log1p.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* double log1p(double x) | ||
| 13 | * Return the natural logarithm of 1+x. | ||
| 14 | * | ||
| 15 | * Method : | ||
| 16 | * 1. Argument Reduction: find k and f such that | ||
| 17 | * 1+x = 2^k * (1+f), | ||
| 18 | * where sqrt(2)/2 < 1+f < sqrt(2) . | ||
| 19 | * | ||
| 20 | * Note. If k=0, then f=x is exact. However, if k!=0, then f | ||
| 21 | * may not be representable exactly. In that case, a correction | ||
| 22 | * term is need. Let u=1+x rounded. Let c = (1+x)-u, then | ||
| 23 | * log(1+x) - log(u) ~ c/u. Thus, we proceed to compute log(u), | ||
| 24 | * and add back the correction term c/u. | ||
| 25 | * (Note: when x > 2**53, one can simply return log(x)) | ||
| 26 | * | ||
| 27 | * 2. Approximation of log(1+f): See log.c | ||
| 28 | * | ||
| 29 | * 3. Finally, log1p(x) = k*ln2 + log(1+f) + c/u. See log.c | ||
| 30 | * | ||
| 31 | * Special cases: | ||
| 32 | * log1p(x) is NaN with signal if x < -1 (including -INF) ; | ||
| 33 | * log1p(+INF) is +INF; log1p(-1) is -INF with signal; | ||
| 34 | * log1p(NaN) is that NaN with no signal. | ||
| 35 | * | ||
| 36 | * Accuracy: | ||
| 37 | * according to an error analysis, the error is always less than | ||
| 38 | * 1 ulp (unit in the last place). | ||
| 39 | * | ||
| 40 | * Constants: | ||
| 41 | * The hexadecimal values are the intended ones for the following | ||
| 42 | * constants. The decimal values may be used, provided that the | ||
| 43 | * compiler will convert from decimal to binary accurately enough | ||
| 44 | * to produce the hexadecimal values shown. | ||
| 45 | * | ||
| 46 | * Note: Assuming log() return accurate answer, the following | ||
| 47 | * algorithm can be used to compute log1p(x) to within a few ULP: | ||
| 48 | * | ||
| 49 | * u = 1+x; | ||
| 50 | * if(u==1.0) return x ; else | ||
| 51 | * return log(u)*(x/(u-1.0)); | ||
| 52 | * | ||
| 53 | * See HP-15C Advanced Functions Handbook, p.193. | ||
| 54 | */ | ||
| 55 | |||
| 56 | #include "libm.h" | ||
| 57 | |||
| 58 | static const double | ||
| 59 | ln2_hi = 6.93147180369123816490e-01, /* 3fe62e42 fee00000 */ | ||
| 60 | ln2_lo = 1.90821492927058770002e-10, /* 3dea39ef 35793c76 */ | ||
| 61 | Lg1 = 6.666666666666735130e-01, /* 3FE55555 55555593 */ | ||
| 62 | Lg2 = 3.999999999940941908e-01, /* 3FD99999 9997FA04 */ | ||
| 63 | Lg3 = 2.857142874366239149e-01, /* 3FD24924 94229359 */ | ||
| 64 | Lg4 = 2.222219843214978396e-01, /* 3FCC71C5 1D8E78AF */ | ||
| 65 | Lg5 = 1.818357216161805012e-01, /* 3FC74664 96CB03DE */ | ||
| 66 | Lg6 = 1.531383769920937332e-01, /* 3FC39A09 D078C69F */ | ||
| 67 | Lg7 = 1.479819860511658591e-01; /* 3FC2F112 DF3E5244 */ | ||
| 68 | |||
| 69 | double log1p(double x) | ||
| 70 | { | ||
| 71 | 	union {double f; uint64_t i;} u = {x}; | ||
| 72 | 	double_t hfsq,f,c,s,z,R,w,t1,t2,dk; | ||
| 73 | 	uint32_t hx,hu; | ||
| 74 | 	int k; | ||
| 75 | |||
| 76 | 	hx = u.i>>32; | ||
| 77 | 	k = 1; | ||
| 78 | 	if (hx < 0x3fda827a || hx>>31) { /* 1+x < sqrt(2)+ */ | ||
| 79 | 		if (hx >= 0xbff00000) { /* x <= -1.0 */ | ||
| 80 | 			if (x == -1) | ||
| 81 | 				return x/0.0; /* log1p(-1) = -inf */ | ||
| 82 | 			return (x-x)/0.0; /* log1p(x<-1) = NaN */ | ||
| 83 | 		} | ||
| 84 | 		if (hx<<1 < 0x3ca00000<<1) { /* |x| < 2**-53 */ | ||
| 85 | 			/* underflow if subnormal */ | ||
| 86 | 			if ((hx&0x7ff00000) == 0) | ||
| 87 | 				FORCE_EVAL((float)x); | ||
| 88 | 			return x; | ||
| 89 | 		} | ||
| 90 | 		if (hx <= 0xbfd2bec4) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ | ||
| 91 | 			k = 0; | ||
| 92 | 			c = 0; | ||
| 93 | 			f = x; | ||
| 94 | 		} | ||
| 95 | 	} else if (hx >= 0x7ff00000) | ||
| 96 | 		return x; | ||
| 97 | 	if (k) { | ||
| 98 | 		u.f = 1 + x; | ||
| 99 | 		hu = u.i>>32; | ||
| 100 | 		hu += 0x3ff00000 - 0x3fe6a09e; | ||
| 101 | 		k = (int)(hu>>20) - 0x3ff; | ||
| 102 | 		/* correction term ~ log(1+x)-log(u), avoid underflow in c/u */ | ||
| 103 | 		if (k < 54) { | ||
| 104 | 			c = k >= 2 ? 1-(u.f-x) : x-(u.f-1); | ||
| 105 | 			c /= u.f; | ||
| 106 | 		} else | ||
| 107 | 			c = 0; | ||
| 108 | 		/* reduce u into [sqrt(2)/2, sqrt(2)] */ | ||
| 109 | 		hu = (hu&0x000fffff) + 0x3fe6a09e; | ||
| 110 | 		u.i = (uint64_t)hu<<32 | (u.i&0xffffffff); | ||
| 111 | 		f = u.f - 1; | ||
| 112 | 	} | ||
| 113 | 	hfsq = 0.5*f*f; | ||
| 114 | 	s = f/(2.0+f); | ||
| 115 | 	z = s*s; | ||
| 116 | 	w = z*z; | ||
| 117 | 	t1 = w*(Lg2+w*(Lg4+w*Lg6)); | ||
| 118 | 	t2 = z*(Lg1+w*(Lg3+w*(Lg5+w*Lg7))); | ||
| 119 | 	R = t2 + t1; | ||
| 120 | 	dk = k; | ||
| 121 | 	return s*(hfsq+R) + (dk*ln2_lo+c) - hfsq + f + dk*ln2_hi; | ||
| 122 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log1pf.c created+77| ... | @@ -0,0 +1,77 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_log1pf.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | |||
| 13 | #include "libm.h" | ||
| 14 | |||
| 15 | static const float | ||
| 16 | ln2_hi = 6.9313812256e-01, /* 0x3f317180 */ | ||
| 17 | ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */ | ||
| 18 | /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ | ||
| 19 | Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ | ||
| 20 | Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ | ||
| 21 | Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ | ||
| 22 | Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ | ||
| 23 | |||
| 24 | float log1pf(float x) | ||
| 25 | { | ||
| 26 | 	union {float f; uint32_t i;} u = {x}; | ||
| 27 | 	float_t hfsq,f,c,s,z,R,w,t1,t2,dk; | ||
| 28 | 	uint32_t ix,iu; | ||
| 29 | 	int k; | ||
| 30 | |||
| 31 | 	ix = u.i; | ||
| 32 | 	k = 1; | ||
| 33 | 	if (ix < 0x3ed413d0 || ix>>31) { /* 1+x < sqrt(2)+ */ | ||
| 34 | 		if (ix >= 0xbf800000) { /* x <= -1.0 */ | ||
| 35 | 			if (x == -1) | ||
| 36 | 				return x/0.0f; /* log1p(-1)=+inf */ | ||
| 37 | 			return (x-x)/0.0f; /* log1p(x<-1)=NaN */ | ||
| 38 | 		} | ||
| 39 | 		if (ix<<1 < 0x33800000<<1) { /* |x| < 2**-24 */ | ||
| 40 | 			/* underflow if subnormal */ | ||
| 41 | 			if ((ix&0x7f800000) == 0) | ||
| 42 | 				FORCE_EVAL(x*x); | ||
| 43 | 			return x; | ||
| 44 | 		} | ||
| 45 | 		if (ix <= 0xbe95f619) { /* sqrt(2)/2- <= 1+x < sqrt(2)+ */ | ||
| 46 | 			k = 0; | ||
| 47 | 			c = 0; | ||
| 48 | 			f = x; | ||
| 49 | 		} | ||
| 50 | 	} else if (ix >= 0x7f800000) | ||
| 51 | 		return x; | ||
| 52 | 	if (k) { | ||
| 53 | 		u.f = 1 + x; | ||
| 54 | 		iu = u.i; | ||
| 55 | 		iu += 0x3f800000 - 0x3f3504f3; | ||
| 56 | 		k = (int)(iu>>23) - 0x7f; | ||
| 57 | 		/* correction term ~ log(1+x)-log(u), avoid underflow in c/u */ | ||
| 58 | 		if (k < 25) { | ||
| 59 | 			c = k >= 2 ? 1-(u.f-x) : x-(u.f-1); | ||
| 60 | 			c /= u.f; | ||
| 61 | 		} else | ||
| 62 | 			c = 0; | ||
| 63 | 		/* reduce u into [sqrt(2)/2, sqrt(2)] */ | ||
| 64 | 		iu = (iu&0x007fffff) + 0x3f3504f3; | ||
| 65 | 		u.i = iu; | ||
| 66 | 		f = u.f - 1; | ||
| 67 | 	} | ||
| 68 | 	s = f/(2.0f + f); | ||
| 69 | 	z = s*s; | ||
| 70 | 	w = z*z; | ||
| 71 | 	t1= w*(Lg2+w*Lg4); | ||
| 72 | 	t2= z*(Lg1+w*Lg3); | ||
| 73 | 	R = t2 + t1; | ||
| 74 | 	hfsq = 0.5f*f*f; | ||
| 75 | 	dk = k; | ||
| 76 | 	return s*(hfsq+R) + (dk*ln2_lo+c) - hfsq + f + dk*ln2_hi; | ||
| 77 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log1pl.c created+177| ... | @@ -0,0 +1,177 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/s_log1pl.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 | /* | ||
| 18 | * Relative error logarithm | ||
| 19 | * Natural logarithm of 1+x, long double precision | ||
| 20 | * | ||
| 21 | * | ||
| 22 | * SYNOPSIS: | ||
| 23 | * | ||
| 24 | * long double x, y, log1pl(); | ||
| 25 | * | ||
| 26 | * y = log1pl( x ); | ||
| 27 | * | ||
| 28 | * | ||
| 29 | * DESCRIPTION: | ||
| 30 | * | ||
| 31 | * Returns the base e (2.718...) logarithm of 1+x. | ||
| 32 | * | ||
| 33 | * The argument 1+x is separated into its exponent and fractional | ||
| 34 | * parts. If the exponent is between -1 and +1, the logarithm | ||
| 35 | * of the fraction is approximated by | ||
| 36 | * | ||
| 37 | * log(1+x) = x - 0.5 x^2 + x^3 P(x)/Q(x). | ||
| 38 | * | ||
| 39 | * Otherwise, setting z = 2(x-1)/x+1), | ||
| 40 | * | ||
| 41 | * log(x) = z + z^3 P(z)/Q(z). | ||
| 42 | * | ||
| 43 | * | ||
| 44 | * ACCURACY: | ||
| 45 | * | ||
| 46 | * Relative error: | ||
| 47 | * arithmetic domain # trials peak rms | ||
| 48 | * IEEE -1.0, 9.0 100000 8.2e-20 2.5e-20 | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include "libm.h" | ||
| 52 | |||
| 53 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 54 | long double log1pl(long double x) | ||
| 55 | { | ||
| 56 | 	return log1p(x); | ||
| 57 | } | ||
| 58 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 59 | /* Coefficients for log(1+x) = x - x^2 / 2 + x^3 P(x)/Q(x) | ||
| 60 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 61 | * Theoretical peak relative error = 2.32e-20 | ||
| 62 | */ | ||
| 63 | static const long double P[] = { | ||
| 64 | 4.5270000862445199635215E-5L, | ||
| 65 | 4.9854102823193375972212E-1L, | ||
| 66 | 6.5787325942061044846969E0L, | ||
| 67 | 2.9911919328553073277375E1L, | ||
| 68 | 6.0949667980987787057556E1L, | ||
| 69 | 5.7112963590585538103336E1L, | ||
| 70 | 2.0039553499201281259648E1L, | ||
| 71 | }; | ||
| 72 | static const long double Q[] = { | ||
| 73 | /* 1.0000000000000000000000E0,*/ | ||
| 74 | 1.5062909083469192043167E1L, | ||
| 75 | 8.3047565967967209469434E1L, | ||
| 76 | 2.2176239823732856465394E2L, | ||
| 77 | 3.0909872225312059774938E2L, | ||
| 78 | 2.1642788614495947685003E2L, | ||
| 79 | 6.0118660497603843919306E1L, | ||
| 80 | }; | ||
| 81 | |||
| 82 | /* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), | ||
| 83 | * where z = 2(x-1)/(x+1) | ||
| 84 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 85 | * Theoretical peak relative error = 6.16e-22 | ||
| 86 | */ | ||
| 87 | static const long double R[4] = { | ||
| 88 | 1.9757429581415468984296E-3L, | ||
| 89 | -7.1990767473014147232598E-1L, | ||
| 90 | 1.0777257190312272158094E1L, | ||
| 91 | -3.5717684488096787370998E1L, | ||
| 92 | }; | ||
| 93 | static const long double S[4] = { | ||
| 94 | /* 1.00000000000000000000E0L,*/ | ||
| 95 | -2.6201045551331104417768E1L, | ||
| 96 | 1.9361891836232102174846E2L, | ||
| 97 | -4.2861221385716144629696E2L, | ||
| 98 | }; | ||
| 99 | static const long double C1 = 6.9314575195312500000000E-1L; | ||
| 100 | static const long double C2 = 1.4286068203094172321215E-6L; | ||
| 101 | |||
| 102 | #define SQRTH 0.70710678118654752440L | ||
| 103 | |||
| 104 | long double log1pl(long double xm1) | ||
| 105 | { | ||
| 106 | 	long double x, y, z; | ||
| 107 | 	int e; | ||
| 108 | |||
| 109 | 	if (isnan(xm1)) | ||
| 110 | 		return xm1; | ||
| 111 | 	if (xm1 == INFINITY) | ||
| 112 | 		return xm1; | ||
| 113 | 	if (xm1 == 0.0) | ||
| 114 | 		return xm1; | ||
| 115 | |||
| 116 | 	x = xm1 + 1.0; | ||
| 117 | |||
| 118 | 	/* Test for domain errors. */ | ||
| 119 | 	if (x <= 0.0) { | ||
| 120 | 		if (x == 0.0) | ||
| 121 | 			return -1/(x*x); /* -inf with divbyzero */ | ||
| 122 | 		return 0/0.0f; /* nan with invalid */ | ||
| 123 | 	} | ||
| 124 | |||
| 125 | 	/* Separate mantissa from exponent. | ||
| 126 | 	 Use frexp so that denormal numbers will be handled properly. */ | ||
| 127 | 	x = frexpl(x, &e); | ||
| 128 | |||
| 129 | 	/* logarithm using log(x) = z + z^3 P(z)/Q(z), | ||
| 130 | 	 where z = 2(x-1)/x+1) */ | ||
| 131 | 	if (e > 2 || e < -2) { | ||
| 132 | 		if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ | ||
| 133 | 			e -= 1; | ||
| 134 | 			z = x - 0.5; | ||
| 135 | 			y = 0.5 * z + 0.5; | ||
| 136 | 		} else { /* 2 (x-1)/(x+1) */ | ||
| 137 | 			z = x - 0.5; | ||
| 138 | 			z -= 0.5; | ||
| 139 | 			y = 0.5 * x + 0.5; | ||
| 140 | 		} | ||
| 141 | 		x = z / y; | ||
| 142 | 		z = x*x; | ||
| 143 | 		z = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); | ||
| 144 | 		z = z + e * C2; | ||
| 145 | 		z = z + x; | ||
| 146 | 		z = z + e * C1; | ||
| 147 | 		return z; | ||
| 148 | 	} | ||
| 149 | |||
| 150 | 	/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ | ||
| 151 | 	if (x < SQRTH) { | ||
| 152 | 		e -= 1; | ||
| 153 | 		if (e != 0) | ||
| 154 | 			x = 2.0 * x - 1.0; | ||
| 155 | 		else | ||
| 156 | 			x = xm1; | ||
| 157 | 	} else { | ||
| 158 | 		if (e != 0) | ||
| 159 | 			x = x - 1.0; | ||
| 160 | 		else | ||
| 161 | 			x = xm1; | ||
| 162 | 	} | ||
| 163 | 	z = x*x; | ||
| 164 | 	y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 6)); | ||
| 165 | 	y = y + e * C2; | ||
| 166 | 	z = y - 0.5 * z; | ||
| 167 | 	z = z + x; | ||
| 168 | 	z = z + e * C1; | ||
| 169 | 	return z; | ||
| 170 | } | ||
| 171 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 172 | // TODO: broken implementation to make things compile | ||
| 173 | long double log1pl(long double x) | ||
| 174 | { | ||
| 175 | 	return log1p(x); | ||
| 176 | } | ||
| 177 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2.c created+122| ... | @@ -0,0 +1,122 @@ | ||
| 1 | /* | ||
| 2 | * Double-precision log2(x) function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "log2_data.h" | ||
| 12 | |||
| 13 | #define T __log2_data.tab | ||
| 14 | #define T2 __log2_data.tab2 | ||
| 15 | #define B __log2_data.poly1 | ||
| 16 | #define A __log2_data.poly | ||
| 17 | #define InvLn2hi __log2_data.invln2hi | ||
| 18 | #define InvLn2lo __log2_data.invln2lo | ||
| 19 | #define N (1 << LOG2_TABLE_BITS) | ||
| 20 | #define OFF 0x3fe6000000000000 | ||
| 21 | |||
| 22 | /* Top 16 bits of a double. */ | ||
| 23 | static inline uint32_t top16(double x) | ||
| 24 | { | ||
| 25 | 	return asuint64(x) >> 48; | ||
| 26 | } | ||
| 27 | |||
| 28 | double log2(double x) | ||
| 29 | { | ||
| 30 | 	double_t z, r, r2, r4, y, invc, logc, kd, hi, lo, t1, t2, t3, p; | ||
| 31 | 	uint64_t ix, iz, tmp; | ||
| 32 | 	uint32_t top; | ||
| 33 | 	int k, i; | ||
| 34 | |||
| 35 | 	ix = asuint64(x); | ||
| 36 | 	top = top16(x); | ||
| 37 | #define LO asuint64(1.0 - 0x1.5b51p-5) | ||
| 38 | #define HI asuint64(1.0 + 0x1.6ab2p-5) | ||
| 39 | 	if (predict_false(ix - LO < HI - LO)) { | ||
| 40 | 		/* Handle close to 1.0 inputs separately. */ | ||
| 41 | 		/* Fix sign of zero with downward rounding when x==1. */ | ||
| 42 | 		if (WANT_ROUNDING && predict_false(ix == asuint64(1.0))) | ||
| 43 | 			return 0; | ||
| 44 | 		r = x - 1.0; | ||
| 45 | #if __FP_FAST_FMA | ||
| 46 | 		hi = r * InvLn2hi; | ||
| 47 | 		lo = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -hi); | ||
| 48 | #else | ||
| 49 | 		double_t rhi, rlo; | ||
| 50 | 		rhi = asdouble(asuint64(r) & -1ULL << 32); | ||
| 51 | 		rlo = r - rhi; | ||
| 52 | 		hi = rhi * InvLn2hi; | ||
| 53 | 		lo = rlo * InvLn2hi + r * InvLn2lo; | ||
| 54 | #endif | ||
| 55 | 		r2 = r * r; /* rounding error: 0x1p-62. */ | ||
| 56 | 		r4 = r2 * r2; | ||
| 57 | 		/* Worst-case error is less than 0.54 ULP (0.55 ULP without fma). */ | ||
| 58 | 		p = r2 * (B[0] + r * B[1]); | ||
| 59 | 		y = hi + p; | ||
| 60 | 		lo += hi - y + p; | ||
| 61 | 		lo += r4 * (B[2] + r * B[3] + r2 * (B[4] + r * B[5]) + | ||
| 62 | 			 r4 * (B[6] + r * B[7] + r2 * (B[8] + r * B[9]))); | ||
| 63 | 		y += lo; | ||
| 64 | 		return eval_as_double(y); | ||
| 65 | 	} | ||
| 66 | 	if (predict_false(top - 0x0010 >= 0x7ff0 - 0x0010)) { | ||
| 67 | 		/* x < 0x1p-1022 or inf or nan. */ | ||
| 68 | 		if (ix * 2 == 0) | ||
| 69 | 			return __math_divzero(1); | ||
| 70 | 		if (ix == asuint64(INFINITY)) /* log(inf) == inf. */ | ||
| 71 | 			return x; | ||
| 72 | 		if ((top & 0x8000) || (top & 0x7ff0) == 0x7ff0) | ||
| 73 | 			return __math_invalid(x); | ||
| 74 | 		/* x is subnormal, normalize it. */ | ||
| 75 | 		ix = asuint64(x * 0x1p52); | ||
| 76 | 		ix -= 52ULL << 52; | ||
| 77 | 	} | ||
| 78 | |||
| 79 | 	/* x = 2^k z; where z is in range [OFF,2*OFF) and exact. | ||
| 80 | 	 The range is split into N subintervals. | ||
| 81 | 	 The ith subinterval contains z and c is near its center. */ | ||
| 82 | 	tmp = ix - OFF; | ||
| 83 | 	i = (tmp >> (52 - LOG2_TABLE_BITS)) % N; | ||
| 84 | 	k = (int64_t)tmp >> 52; /* arithmetic shift */ | ||
| 85 | 	iz = ix - (tmp & 0xfffULL << 52); | ||
| 86 | 	invc = T[i].invc; | ||
| 87 | 	logc = T[i].logc; | ||
| 88 | 	z = asdouble(iz); | ||
| 89 | 	kd = (double_t)k; | ||
| 90 | |||
| 91 | 	/* log2(x) = log2(z/c) + log2(c) + k. */ | ||
| 92 | 	/* r ~= z/c - 1, |r| < 1/(2*N). */ | ||
| 93 | #if __FP_FAST_FMA | ||
| 94 | 	/* rounding error: 0x1p-55/N. */ | ||
| 95 | 	r = __builtin_fma(z, invc, -1.0); | ||
| 96 | 	t1 = r * InvLn2hi; | ||
| 97 | 	t2 = r * InvLn2lo + __builtin_fma(r, InvLn2hi, -t1); | ||
| 98 | #else | ||
| 99 | 	double_t rhi, rlo; | ||
| 100 | 	/* rounding error: 0x1p-55/N + 0x1p-65. */ | ||
| 101 | 	r = (z - T2[i].chi - T2[i].clo) * invc; | ||
| 102 | 	rhi = asdouble(asuint64(r) & -1ULL << 32); | ||
| 103 | 	rlo = r - rhi; | ||
| 104 | 	t1 = rhi * InvLn2hi; | ||
| 105 | 	t2 = rlo * InvLn2hi + r * InvLn2lo; | ||
| 106 | #endif | ||
| 107 | |||
| 108 | 	/* hi + lo = r/ln2 + log2(c) + k. */ | ||
| 109 | 	t3 = kd + logc; | ||
| 110 | 	hi = t3 + t1; | ||
| 111 | 	lo = t3 - hi + t1 + t2; | ||
| 112 | |||
| 113 | 	/* log2(r+1) = r/ln2 + r^2*poly(r). */ | ||
| 114 | 	/* Evaluation is optimized assuming superscalar pipelined execution. */ | ||
| 115 | 	r2 = r * r; /* rounding error: 0x1p-54/N^2. */ | ||
| 116 | 	r4 = r2 * r2; | ||
| 117 | 	/* Worst-case error if |y| > 0x1p-4: 0.547 ULP (0.550 ULP without fma). | ||
| 118 | 	 ~ 0.5 + 2/N/ln2 + abs-poly-error*0x1p56 ULP (+ 0.003 ULP without fma). */ | ||
| 119 | 	p = A[0] + r * A[1] + r2 * (A[2] + r * A[3]) + r4 * (A[4] + r * A[5]); | ||
| 120 | 	y = lo + r2 * p + hi; | ||
| 121 | 	return eval_as_double(y); | ||
| 122 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2_data.c created+201| ... | @@ -0,0 +1,201 @@ | ||
| 1 | /* | ||
| 2 | * Data for log2. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "log2_data.h" | ||
| 9 | |||
| 10 | #define N (1 << LOG2_TABLE_BITS) | ||
| 11 | |||
| 12 | const struct log2_data __log2_data = { | ||
| 13 | // First coefficient: 0x1.71547652b82fe1777d0ffda0d24p0 | ||
| 14 | .invln2hi = 0x1.7154765200000p+0, | ||
| 15 | .invln2lo = 0x1.705fc2eefa200p-33, | ||
| 16 | .poly1 = { | ||
| 17 | // relative error: 0x1.2fad8188p-63 | ||
| 18 | // in -0x1.5b51p-5 0x1.6ab2p-5 | ||
| 19 | -0x1.71547652b82fep-1, | ||
| 20 | 0x1.ec709dc3a03f7p-2, | ||
| 21 | -0x1.71547652b7c3fp-2, | ||
| 22 | 0x1.2776c50f05be4p-2, | ||
| 23 | -0x1.ec709dd768fe5p-3, | ||
| 24 | 0x1.a61761ec4e736p-3, | ||
| 25 | -0x1.7153fbc64a79bp-3, | ||
| 26 | 0x1.484d154f01b4ap-3, | ||
| 27 | -0x1.289e4a72c383cp-3, | ||
| 28 | 0x1.0b32f285aee66p-3, | ||
| 29 | }, | ||
| 30 | .poly = { | ||
| 31 | // relative error: 0x1.a72c2bf8p-58 | ||
| 32 | // abs error: 0x1.67a552c8p-66 | ||
| 33 | // in -0x1.f45p-8 0x1.f45p-8 | ||
| 34 | -0x1.71547652b8339p-1, | ||
| 35 | 0x1.ec709dc3a04bep-2, | ||
| 36 | -0x1.7154764702ffbp-2, | ||
| 37 | 0x1.2776c50034c48p-2, | ||
| 38 | -0x1.ec7b328ea92bcp-3, | ||
| 39 | 0x1.a6225e117f92ep-3, | ||
| 40 | }, | ||
| 41 | /* Algorithm: | ||
| 42 | |||
| 43 | 	x = 2^k z | ||
| 44 | 	log2(x) = k + log2(c) + log2(z/c) | ||
| 45 | 	log2(z/c) = poly(z/c - 1) | ||
| 46 | |||
| 47 | where z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls | ||
| 48 | into the ith one, then table entries are computed as | ||
| 49 | |||
| 50 | 	tab[i].invc = 1/c | ||
| 51 | 	tab[i].logc = (double)log2(c) | ||
| 52 | 	tab2[i].chi = (double)c | ||
| 53 | 	tab2[i].clo = (double)(c - (double)c) | ||
| 54 | |||
| 55 | where c is near the center of the subinterval and is chosen by trying +-2^29 | ||
| 56 | floating point invc candidates around 1/center and selecting one for which | ||
| 57 | |||
| 58 | 	1) the rounding error in 0x1.8p10 + logc is 0, | ||
| 59 | 	2) the rounding error in z - chi - clo is < 0x1p-64 and | ||
| 60 | 	3) the rounding error in (double)log2(c) is minimized (< 0x1p-68). | ||
| 61 | |||
| 62 | Note: 1) ensures that k + logc can be computed without rounding error, 2) | ||
| 63 | ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to a | ||
| 64 | single rounding error when there is no fast fma for z*invc - 1, 3) ensures | ||
| 65 | that logc + poly(z/c - 1) has small error, however near x == 1 when | ||
| 66 | |log2(x)| < 0x1p-4, this is not enough so that is special cased. */ | ||
| 67 | .tab = { | ||
| 68 | {0x1.724286bb1acf8p+0, -0x1.1095feecdb000p-1}, | ||
| 69 | {0x1.6e1f766d2cca1p+0, -0x1.08494bd76d000p-1}, | ||
| 70 | {0x1.6a13d0e30d48ap+0, -0x1.00143aee8f800p-1}, | ||
| 71 | {0x1.661ec32d06c85p+0, -0x1.efec5360b4000p-2}, | ||
| 72 | {0x1.623fa951198f8p+0, -0x1.dfdd91ab7e000p-2}, | ||
| 73 | {0x1.5e75ba4cf026cp+0, -0x1.cffae0cc79000p-2}, | ||
| 74 | {0x1.5ac055a214fb8p+0, -0x1.c043811fda000p-2}, | ||
| 75 | {0x1.571ed0f166e1ep+0, -0x1.b0b67323ae000p-2}, | ||
| 76 | {0x1.53909590bf835p+0, -0x1.a152f5a2db000p-2}, | ||
| 77 | {0x1.5014fed61adddp+0, -0x1.9217f5af86000p-2}, | ||
| 78 | {0x1.4cab88e487bd0p+0, -0x1.8304db0719000p-2}, | ||
| 79 | {0x1.49539b4334feep+0, -0x1.74189f9a9e000p-2}, | ||
| 80 | {0x1.460cbdfafd569p+0, -0x1.6552bb5199000p-2}, | ||
| 81 | {0x1.42d664ee4b953p+0, -0x1.56b23a29b1000p-2}, | ||
| 82 | {0x1.3fb01111dd8a6p+0, -0x1.483650f5fa000p-2}, | ||
| 83 | {0x1.3c995b70c5836p+0, -0x1.39de937f6a000p-2}, | ||
| 84 | {0x1.3991c4ab6fd4ap+0, -0x1.2baa1538d6000p-2}, | ||
| 85 | {0x1.3698e0ce099b5p+0, -0x1.1d98340ca4000p-2}, | ||
| 86 | {0x1.33ae48213e7b2p+0, -0x1.0fa853a40e000p-2}, | ||
| 87 | {0x1.30d191985bdb1p+0, -0x1.01d9c32e73000p-2}, | ||
| 88 | {0x1.2e025cab271d7p+0, -0x1.e857da2fa6000p-3}, | ||
| 89 | {0x1.2b404cf13cd82p+0, -0x1.cd3c8633d8000p-3}, | ||
| 90 | {0x1.288b02c7ccb50p+0, -0x1.b26034c14a000p-3}, | ||
| 91 | {0x1.25e2263944de5p+0, -0x1.97c1c2f4fe000p-3}, | ||
| 92 | {0x1.234563d8615b1p+0, -0x1.7d6023f800000p-3}, | ||
| 93 | {0x1.20b46e33eaf38p+0, -0x1.633a71a05e000p-3}, | ||
| 94 | {0x1.1e2eefdcda3ddp+0, -0x1.494f5e9570000p-3}, | ||
| 95 | {0x1.1bb4a580b3930p+0, -0x1.2f9e424e0a000p-3}, | ||
| 96 | {0x1.19453847f2200p+0, -0x1.162595afdc000p-3}, | ||
| 97 | {0x1.16e06c0d5d73cp+0, -0x1.f9c9a75bd8000p-4}, | ||
| 98 | {0x1.1485f47b7e4c2p+0, -0x1.c7b575bf9c000p-4}, | ||
| 99 | {0x1.12358ad0085d1p+0, -0x1.960c60ff48000p-4}, | ||
| 100 | {0x1.0fef00f532227p+0, -0x1.64ce247b60000p-4}, | ||
| 101 | {0x1.0db2077d03a8fp+0, -0x1.33f78b2014000p-4}, | ||
| 102 | {0x1.0b7e6d65980d9p+0, -0x1.0387d1a42c000p-4}, | ||
| 103 | {0x1.0953efe7b408dp+0, -0x1.a6f9208b50000p-5}, | ||
| 104 | {0x1.07325cac53b83p+0, -0x1.47a954f770000p-5}, | ||
| 105 | {0x1.05197e40d1b5cp+0, -0x1.d23a8c50c0000p-6}, | ||
| 106 | {0x1.03091c1208ea2p+0, -0x1.16a2629780000p-6}, | ||
| 107 | {0x1.0101025b37e21p+0, -0x1.720f8d8e80000p-8}, | ||
| 108 | {0x1.fc07ef9caa76bp-1, 0x1.6fe53b1500000p-7}, | ||
| 109 | {0x1.f4465d3f6f184p-1, 0x1.11ccce10f8000p-5}, | ||
| 110 | {0x1.ecc079f84107fp-1, 0x1.c4dfc8c8b8000p-5}, | ||
| 111 | {0x1.e573a99975ae8p-1, 0x1.3aa321e574000p-4}, | ||
| 112 | {0x1.de5d6f0bd3de6p-1, 0x1.918a0d08b8000p-4}, | ||
| 113 | {0x1.d77b681ff38b3p-1, 0x1.e72e9da044000p-4}, | ||
| 114 | {0x1.d0cb5724de943p-1, 0x1.1dcd2507f6000p-3}, | ||
| 115 | {0x1.ca4b2dc0e7563p-1, 0x1.476ab03dea000p-3}, | ||
| 116 | {0x1.c3f8ee8d6cb51p-1, 0x1.7074377e22000p-3}, | ||
| 117 | {0x1.bdd2b4f020c4cp-1, 0x1.98ede8ba94000p-3}, | ||
| 118 | {0x1.b7d6c006015cap-1, 0x1.c0db86ad2e000p-3}, | ||
| 119 | {0x1.b20366e2e338fp-1, 0x1.e840aafcee000p-3}, | ||
| 120 | {0x1.ac57026295039p-1, 0x1.0790ab4678000p-2}, | ||
| 121 | {0x1.a6d01bc2731ddp-1, 0x1.1ac056801c000p-2}, | ||
| 122 | {0x1.a16d3bc3ff18bp-1, 0x1.2db11d4fee000p-2}, | ||
| 123 | {0x1.9c2d14967feadp-1, 0x1.406464ec58000p-2}, | ||
| 124 | {0x1.970e4f47c9902p-1, 0x1.52dbe093af000p-2}, | ||
| 125 | {0x1.920fb3982bcf2p-1, 0x1.651902050d000p-2}, | ||
| 126 | {0x1.8d30187f759f1p-1, 0x1.771d2cdeaf000p-2}, | ||
| 127 | {0x1.886e5ebb9f66dp-1, 0x1.88e9c857d9000p-2}, | ||
| 128 | {0x1.83c97b658b994p-1, 0x1.9a80155e16000p-2}, | ||
| 129 | {0x1.7f405ffc61022p-1, 0x1.abe186ed3d000p-2}, | ||
| 130 | {0x1.7ad22181415cap-1, 0x1.bd0f2aea0e000p-2}, | ||
| 131 | {0x1.767dcf99eff8cp-1, 0x1.ce0a43dbf4000p-2}, | ||
| 132 | }, | ||
| 133 | #if !__FP_FAST_FMA | ||
| 134 | .tab2 = { | ||
| 135 | {0x1.6200012b90a8ep-1, 0x1.904ab0644b605p-55}, | ||
| 136 | {0x1.66000045734a6p-1, 0x1.1ff9bea62f7a9p-57}, | ||
| 137 | {0x1.69fffc325f2c5p-1, 0x1.27ecfcb3c90bap-55}, | ||
| 138 | {0x1.6e00038b95a04p-1, 0x1.8ff8856739326p-55}, | ||
| 139 | {0x1.71fffe09994e3p-1, 0x1.afd40275f82b1p-55}, | ||
| 140 | {0x1.7600015590e1p-1, -0x1.2fd75b4238341p-56}, | ||
| 141 | {0x1.7a00012655bd5p-1, 0x1.808e67c242b76p-56}, | ||
| 142 | {0x1.7e0003259e9a6p-1, -0x1.208e426f622b7p-57}, | ||
| 143 | {0x1.81fffedb4b2d2p-1, -0x1.402461ea5c92fp-55}, | ||
| 144 | {0x1.860002dfafcc3p-1, 0x1.df7f4a2f29a1fp-57}, | ||
| 145 | {0x1.89ffff78c6b5p-1, -0x1.e0453094995fdp-55}, | ||
| 146 | {0x1.8e00039671566p-1, -0x1.a04f3bec77b45p-55}, | ||
| 147 | {0x1.91fffe2bf1745p-1, -0x1.7fa34400e203cp-56}, | ||
| 148 | {0x1.95fffcc5c9fd1p-1, -0x1.6ff8005a0695dp-56}, | ||
| 149 | {0x1.9a0003bba4767p-1, 0x1.0f8c4c4ec7e03p-56}, | ||
| 150 | {0x1.9dfffe7b92da5p-1, 0x1.e7fd9478c4602p-55}, | ||
| 151 | {0x1.a1fffd72efdafp-1, -0x1.a0c554dcdae7ep-57}, | ||
| 152 | {0x1.a5fffde04ff95p-1, 0x1.67da98ce9b26bp-55}, | ||
| 153 | {0x1.a9fffca5e8d2bp-1, -0x1.284c9b54c13dep-55}, | ||
| 154 | {0x1.adfffddad03eap-1, 0x1.812c8ea602e3cp-58}, | ||
| 155 | {0x1.b1ffff10d3d4dp-1, -0x1.efaddad27789cp-55}, | ||
| 156 | {0x1.b5fffce21165ap-1, 0x1.3cb1719c61237p-58}, | ||
| 157 | {0x1.b9fffd950e674p-1, 0x1.3f7d94194cep-56}, | ||
| 158 | {0x1.be000139ca8afp-1, 0x1.50ac4215d9bcp-56}, | ||
| 159 | {0x1.c20005b46df99p-1, 0x1.beea653e9c1c9p-57}, | ||
| 160 | {0x1.c600040b9f7aep-1, -0x1.c079f274a70d6p-56}, | ||
| 161 | {0x1.ca0006255fd8ap-1, -0x1.a0b4076e84c1fp-56}, | ||
| 162 | {0x1.cdfffd94c095dp-1, 0x1.8f933f99ab5d7p-55}, | ||
| 163 | {0x1.d1ffff975d6cfp-1, -0x1.82c08665fe1bep-58}, | ||
| 164 | {0x1.d5fffa2561c93p-1, -0x1.b04289bd295f3p-56}, | ||
| 165 | {0x1.d9fff9d228b0cp-1, 0x1.70251340fa236p-55}, | ||
| 166 | {0x1.de00065bc7e16p-1, -0x1.5011e16a4d80cp-56}, | ||
| 167 | {0x1.e200002f64791p-1, 0x1.9802f09ef62ep-55}, | ||
| 168 | {0x1.e600057d7a6d8p-1, -0x1.e0b75580cf7fap-56}, | ||
| 169 | {0x1.ea00027edc00cp-1, -0x1.c848309459811p-55}, | ||
| 170 | {0x1.ee0006cf5cb7cp-1, -0x1.f8027951576f4p-55}, | ||
| 171 | {0x1.f2000782b7dccp-1, -0x1.f81d97274538fp-55}, | ||
| 172 | {0x1.f6000260c450ap-1, -0x1.071002727ffdcp-59}, | ||
| 173 | {0x1.f9fffe88cd533p-1, -0x1.81bdce1fda8bp-58}, | ||
| 174 | {0x1.fdfffd50f8689p-1, 0x1.7f91acb918e6ep-55}, | ||
| 175 | {0x1.0200004292367p+0, 0x1.b7ff365324681p-54}, | ||
| 176 | {0x1.05fffe3e3d668p+0, 0x1.6fa08ddae957bp-55}, | ||
| 177 | {0x1.0a0000a85a757p+0, -0x1.7e2de80d3fb91p-58}, | ||
| 178 | {0x1.0e0001a5f3fccp+0, -0x1.1823305c5f014p-54}, | ||
| 179 | {0x1.11ffff8afbaf5p+0, -0x1.bfabb6680bac2p-55}, | ||
| 180 | {0x1.15fffe54d91adp+0, -0x1.d7f121737e7efp-54}, | ||
| 181 | {0x1.1a00011ac36e1p+0, 0x1.c000a0516f5ffp-54}, | ||
| 182 | {0x1.1e00019c84248p+0, -0x1.082fbe4da5dap-54}, | ||
| 183 | {0x1.220000ffe5e6ep+0, -0x1.8fdd04c9cfb43p-55}, | ||
| 184 | {0x1.26000269fd891p+0, 0x1.cfe2a7994d182p-55}, | ||
| 185 | {0x1.2a00029a6e6dap+0, -0x1.00273715e8bc5p-56}, | ||
| 186 | {0x1.2dfffe0293e39p+0, 0x1.b7c39dab2a6f9p-54}, | ||
| 187 | {0x1.31ffff7dcf082p+0, 0x1.df1336edc5254p-56}, | ||
| 188 | {0x1.35ffff05a8b6p+0, -0x1.e03564ccd31ebp-54}, | ||
| 189 | {0x1.3a0002e0eaeccp+0, 0x1.5f0e74bd3a477p-56}, | ||
| 190 | {0x1.3e000043bb236p+0, 0x1.c7dcb149d8833p-54}, | ||
| 191 | {0x1.4200002d187ffp+0, 0x1.e08afcf2d3d28p-56}, | ||
| 192 | {0x1.460000d387cb1p+0, 0x1.20837856599a6p-55}, | ||
| 193 | {0x1.4a00004569f89p+0, -0x1.9fa5c904fbcd2p-55}, | ||
| 194 | {0x1.4e000043543f3p+0, -0x1.81125ed175329p-56}, | ||
| 195 | {0x1.51fffcc027f0fp+0, 0x1.883d8847754dcp-54}, | ||
| 196 | {0x1.55ffffd87b36fp+0, -0x1.709e731d02807p-55}, | ||
| 197 | {0x1.59ffff21df7bap+0, 0x1.7f79f68727b02p-55}, | ||
| 198 | {0x1.5dfffebfc3481p+0, -0x1.180902e30e93ep-54}, | ||
| 199 | }, | ||
| 200 | #endif | ||
| 201 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2_data.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _LOG2_DATA_H | ||
| 6 | #define _LOG2_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define LOG2_TABLE_BITS 6 | ||
| 11 | #define LOG2_POLY_ORDER 7 | ||
| 12 | #define LOG2_POLY1_ORDER 11 | ||
| 13 | extern hidden const struct log2_data { | ||
| 14 | 	double invln2hi; | ||
| 15 | 	double invln2lo; | ||
| 16 | 	double poly[LOG2_POLY_ORDER - 1]; | ||
| 17 | 	double poly1[LOG2_POLY1_ORDER - 1]; | ||
| 18 | 	struct { | ||
| 19 | 		double invc, logc; | ||
| 20 | 	} tab[1 << LOG2_TABLE_BITS]; | ||
| 21 | #if !__FP_FAST_FMA | ||
| 22 | 	struct { | ||
| 23 | 		double chi, clo; | ||
| 24 | 	} tab2[1 << LOG2_TABLE_BITS]; | ||
| 25 | #endif | ||
| 26 | } __log2_data; | ||
| 27 | |||
| 28 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2f.c created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | /* | ||
| 2 | * Single-precision log2 function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "log2f_data.h" | ||
| 12 | |||
| 13 | /* | ||
| 14 | LOG2F_TABLE_BITS = 4 | ||
| 15 | LOG2F_POLY_ORDER = 4 | ||
| 16 | |||
| 17 | ULP error: 0.752 (nearest rounding.) | ||
| 18 | Relative error: 1.9 * 2^-26 (before rounding.) | ||
| 19 | */ | ||
| 20 | |||
| 21 | #define N (1 << LOG2F_TABLE_BITS) | ||
| 22 | #define T __log2f_data.tab | ||
| 23 | #define A __log2f_data.poly | ||
| 24 | #define OFF 0x3f330000 | ||
| 25 | |||
| 26 | float log2f(float x) | ||
| 27 | { | ||
| 28 | 	double_t z, r, r2, p, y, y0, invc, logc; | ||
| 29 | 	uint32_t ix, iz, top, tmp; | ||
| 30 | 	int k, i; | ||
| 31 | |||
| 32 | 	ix = asuint(x); | ||
| 33 | 	/* Fix sign of zero with downward rounding when x==1. */ | ||
| 34 | 	if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) | ||
| 35 | 		return 0; | ||
| 36 | 	if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) { | ||
| 37 | 		/* x < 0x1p-126 or inf or nan. */ | ||
| 38 | 		if (ix * 2 == 0) | ||
| 39 | 			return __math_divzerof(1); | ||
| 40 | 		if (ix == 0x7f800000) /* log2(inf) == inf. */ | ||
| 41 | 			return x; | ||
| 42 | 		if ((ix & 0x80000000) || ix * 2 >= 0xff000000) | ||
| 43 | 			return __math_invalidf(x); | ||
| 44 | 		/* x is subnormal, normalize it. */ | ||
| 45 | 		ix = asuint(x * 0x1p23f); | ||
| 46 | 		ix -= 23 << 23; | ||
| 47 | 	} | ||
| 48 | |||
| 49 | 	/* x = 2^k z; where z is in range [OFF,2*OFF] and exact. | ||
| 50 | 	 The range is split into N subintervals. | ||
| 51 | 	 The ith subinterval contains z and c is near its center. */ | ||
| 52 | 	tmp = ix - OFF; | ||
| 53 | 	i = (tmp >> (23 - LOG2F_TABLE_BITS)) % N; | ||
| 54 | 	top = tmp & 0xff800000; | ||
| 55 | 	iz = ix - top; | ||
| 56 | 	k = (int32_t)tmp >> 23; /* arithmetic shift */ | ||
| 57 | 	invc = T[i].invc; | ||
| 58 | 	logc = T[i].logc; | ||
| 59 | 	z = (double_t)asfloat(iz); | ||
| 60 | |||
| 61 | 	/* log2(x) = log1p(z/c-1)/ln2 + log2(c) + k */ | ||
| 62 | 	r = z * invc - 1; | ||
| 63 | 	y0 = logc + (double_t)k; | ||
| 64 | |||
| 65 | 	/* Pipelined polynomial evaluation to approximate log1p(r)/ln2. */ | ||
| 66 | 	r2 = r * r; | ||
| 67 | 	y = A[1] * r + A[2]; | ||
| 68 | 	y = A[0] * r2 + y; | ||
| 69 | 	p = A[3] * r + y0; | ||
| 70 | 	y = y * r2 + p; | ||
| 71 | 	return eval_as_float(y); | ||
| 72 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2f_data.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | /* | ||
| 2 | * Data definition for log2f. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "log2f_data.h" | ||
| 9 | |||
| 10 | const struct log2f_data __log2f_data = { | ||
| 11 | .tab = { | ||
| 12 | { 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2 }, | ||
| 13 | { 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2 }, | ||
| 14 | { 0x1.49539f0f010bp+0, -0x1.7418b0a1fb77bp-2 }, | ||
| 15 | { 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2 }, | ||
| 16 | { 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2 }, | ||
| 17 | { 0x1.25e227b0b8eap+0, -0x1.97c1d1b3b7afp-3 }, | ||
| 18 | { 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3 }, | ||
| 19 | { 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4 }, | ||
| 20 | { 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5 }, | ||
| 21 | { 0x1p+0, 0x0p+0 }, | ||
| 22 | { 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4 }, | ||
| 23 | { 0x1.ca4b31f026aap-1, 0x1.476a9543891bap-3 }, | ||
| 24 | { 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3 }, | ||
| 25 | { 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2 }, | ||
| 26 | { 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2 }, | ||
| 27 | { 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2 }, | ||
| 28 | }, | ||
| 29 | .poly = { | ||
| 30 | -0x1.712b6f70a7e4dp-2, 0x1.ecabf496832ep-2, -0x1.715479ffae3dep-1, | ||
| 31 | 0x1.715475f35c8b8p0, | ||
| 32 | } | ||
| 33 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2f_data.h created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _LOG2F_DATA_H | ||
| 6 | #define _LOG2F_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define LOG2F_TABLE_BITS 4 | ||
| 11 | #define LOG2F_POLY_ORDER 4 | ||
| 12 | extern hidden const struct log2f_data { | ||
| 13 | 	struct { | ||
| 14 | 		double invc, logc; | ||
| 15 | 	} tab[1 << LOG2F_TABLE_BITS]; | ||
| 16 | 	double poly[LOG2F_POLY_ORDER]; | ||
| 17 | } __log2f_data; | ||
| 18 | |||
| 19 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/log2l.c created+182| ... | @@ -0,0 +1,182 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_log2l.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 | /* | ||
| 18 | * Base 2 logarithm, long double precision | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * long double x, y, log2l(); | ||
| 24 | * | ||
| 25 | * y = log2l( x ); | ||
| 26 | * | ||
| 27 | * | ||
| 28 | * DESCRIPTION: | ||
| 29 | * | ||
| 30 | * Returns the base 2 logarithm of x. | ||
| 31 | * | ||
| 32 | * The argument is separated into its exponent and fractional | ||
| 33 | * parts. If the exponent is between -1 and +1, the (natural) | ||
| 34 | * logarithm of the fraction is approximated by | ||
| 35 | * | ||
| 36 | * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). | ||
| 37 | * | ||
| 38 | * Otherwise, setting z = 2(x-1)/x+1), | ||
| 39 | * | ||
| 40 | * log(x) = z + z**3 P(z)/Q(z). | ||
| 41 | * | ||
| 42 | * | ||
| 43 | * ACCURACY: | ||
| 44 | * | ||
| 45 | * Relative error: | ||
| 46 | * arithmetic domain # trials peak rms | ||
| 47 | * IEEE 0.5, 2.0 30000 9.8e-20 2.7e-20 | ||
| 48 | * IEEE exp(+-10000) 70000 5.4e-20 2.3e-20 | ||
| 49 | * | ||
| 50 | * In the tests over the interval exp(+-10000), the logarithms | ||
| 51 | * of the random arguments were uniformly distributed over | ||
| 52 | * [-10000, +10000]. | ||
| 53 | */ | ||
| 54 | |||
| 55 | #include "libm.h" | ||
| 56 | |||
| 57 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 58 | long double log2l(long double x) | ||
| 59 | { | ||
| 60 | 	return log2(x); | ||
| 61 | } | ||
| 62 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 63 | /* Coefficients for ln(1+x) = x - x**2/2 + x**3 P(x)/Q(x) | ||
| 64 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 65 | * Theoretical peak relative error = 6.2e-22 | ||
| 66 | */ | ||
| 67 | static const long double P[] = { | ||
| 68 | 4.9962495940332550844739E-1L, | ||
| 69 | 1.0767376367209449010438E1L, | ||
| 70 | 7.7671073698359539859595E1L, | ||
| 71 | 2.5620629828144409632571E2L, | ||
| 72 | 4.2401812743503691187826E2L, | ||
| 73 | 3.4258224542413922935104E2L, | ||
| 74 | 1.0747524399916215149070E2L, | ||
| 75 | }; | ||
| 76 | static const long double Q[] = { | ||
| 77 | /* 1.0000000000000000000000E0,*/ | ||
| 78 | 2.3479774160285863271658E1L, | ||
| 79 | 1.9444210022760132894510E2L, | ||
| 80 | 7.7952888181207260646090E2L, | ||
| 81 | 1.6911722418503949084863E3L, | ||
| 82 | 2.0307734695595183428202E3L, | ||
| 83 | 1.2695660352705325274404E3L, | ||
| 84 | 3.2242573199748645407652E2L, | ||
| 85 | }; | ||
| 86 | |||
| 87 | /* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), | ||
| 88 | * where z = 2(x-1)/(x+1) | ||
| 89 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 90 | * Theoretical peak relative error = 6.16e-22 | ||
| 91 | */ | ||
| 92 | static const long double R[4] = { | ||
| 93 | 1.9757429581415468984296E-3L, | ||
| 94 | -7.1990767473014147232598E-1L, | ||
| 95 | 1.0777257190312272158094E1L, | ||
| 96 | -3.5717684488096787370998E1L, | ||
| 97 | }; | ||
| 98 | static const long double S[4] = { | ||
| 99 | /* 1.00000000000000000000E0L,*/ | ||
| 100 | -2.6201045551331104417768E1L, | ||
| 101 | 1.9361891836232102174846E2L, | ||
| 102 | -4.2861221385716144629696E2L, | ||
| 103 | }; | ||
| 104 | /* log2(e) - 1 */ | ||
| 105 | #define LOG2EA 4.4269504088896340735992e-1L | ||
| 106 | |||
| 107 | #define SQRTH 0.70710678118654752440L | ||
| 108 | |||
| 109 | long double log2l(long double x) | ||
| 110 | { | ||
| 111 | 	long double y, z; | ||
| 112 | 	int e; | ||
| 113 | |||
| 114 | 	if (isnan(x)) | ||
| 115 | 		return x; | ||
| 116 | 	if (x == INFINITY) | ||
| 117 | 		return x; | ||
| 118 | 	if (x <= 0.0) { | ||
| 119 | 		if (x == 0.0) | ||
| 120 | 			return -1/(x*x); /* -inf with divbyzero */ | ||
| 121 | 		return 0/0.0f; /* nan with invalid */ | ||
| 122 | 	} | ||
| 123 | |||
| 124 | 	/* separate mantissa from exponent */ | ||
| 125 | 	/* Note, frexp is used so that denormal numbers | ||
| 126 | 	 * will be handled properly. | ||
| 127 | 	 */ | ||
| 128 | 	x = frexpl(x, &e); | ||
| 129 | |||
| 130 | 	/* logarithm using log(x) = z + z**3 P(z)/Q(z), | ||
| 131 | 	 * where z = 2(x-1)/x+1) | ||
| 132 | 	 */ | ||
| 133 | 	if (e > 2 || e < -2) { | ||
| 134 | 		if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ | ||
| 135 | 			e -= 1; | ||
| 136 | 			z = x - 0.5; | ||
| 137 | 			y = 0.5 * z + 0.5; | ||
| 138 | 		} else { /* 2 (x-1)/(x+1) */ | ||
| 139 | 			z = x - 0.5; | ||
| 140 | 			z -= 0.5; | ||
| 141 | 			y = 0.5 * x + 0.5; | ||
| 142 | 		} | ||
| 143 | 		x = z / y; | ||
| 144 | 		z = x*x; | ||
| 145 | 		y = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); | ||
| 146 | 		goto done; | ||
| 147 | 	} | ||
| 148 | |||
| 149 | 	/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ | ||
| 150 | 	if (x < SQRTH) { | ||
| 151 | 		e -= 1; | ||
| 152 | 		x = 2.0*x - 1.0; | ||
| 153 | 	} else { | ||
| 154 | 		x = x - 1.0; | ||
| 155 | 	} | ||
| 156 | 	z = x*x; | ||
| 157 | 	y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 7)); | ||
| 158 | 	y = y - 0.5*z; | ||
| 159 | |||
| 160 | done: | ||
| 161 | 	/* Multiply log of fraction by log2(e) | ||
| 162 | 	 * and base 2 exponent by 1 | ||
| 163 | 	 * | ||
| 164 | 	 * ***CAUTION*** | ||
| 165 | 	 * | ||
| 166 | 	 * This sequence of operations is critical and it may | ||
| 167 | 	 * be horribly defeated by some compiler optimizers. | ||
| 168 | 	 */ | ||
| 169 | 	z = y * LOG2EA; | ||
| 170 | 	z += x * LOG2EA; | ||
| 171 | 	z += y; | ||
| 172 | 	z += x; | ||
| 173 | 	z += e; | ||
| 174 | 	return z; | ||
| 175 | } | ||
| 176 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 177 | // TODO: broken implementation to make things compile | ||
| 178 | long double log2l(long double x) | ||
| 179 | { | ||
| 180 | 	return log2(x); | ||
| 181 | } | ||
| 182 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/log_data.c created+328| ... | @@ -0,0 +1,328 @@ | ||
| 1 | /* | ||
| 2 | * Data for log. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "log_data.h" | ||
| 9 | |||
| 10 | #define N (1 << LOG_TABLE_BITS) | ||
| 11 | |||
| 12 | const struct log_data __log_data = { | ||
| 13 | .ln2hi = 0x1.62e42fefa3800p-1, | ||
| 14 | .ln2lo = 0x1.ef35793c76730p-45, | ||
| 15 | .poly1 = { | ||
| 16 | // relative error: 0x1.c04d76cp-63 | ||
| 17 | // in -0x1p-4 0x1.09p-4 (|log(1+x)| > 0x1p-4 outside the interval) | ||
| 18 | -0x1p-1, | ||
| 19 | 0x1.5555555555577p-2, | ||
| 20 | -0x1.ffffffffffdcbp-3, | ||
| 21 | 0x1.999999995dd0cp-3, | ||
| 22 | -0x1.55555556745a7p-3, | ||
| 23 | 0x1.24924a344de3p-3, | ||
| 24 | -0x1.fffffa4423d65p-4, | ||
| 25 | 0x1.c7184282ad6cap-4, | ||
| 26 | -0x1.999eb43b068ffp-4, | ||
| 27 | 0x1.78182f7afd085p-4, | ||
| 28 | -0x1.5521375d145cdp-4, | ||
| 29 | }, | ||
| 30 | .poly = { | ||
| 31 | // relative error: 0x1.926199e8p-56 | ||
| 32 | // abs error: 0x1.882ff33p-65 | ||
| 33 | // in -0x1.fp-9 0x1.fp-9 | ||
| 34 | -0x1.0000000000001p-1, | ||
| 35 | 0x1.555555551305bp-2, | ||
| 36 | -0x1.fffffffeb459p-3, | ||
| 37 | 0x1.999b324f10111p-3, | ||
| 38 | -0x1.55575e506c89fp-3, | ||
| 39 | }, | ||
| 40 | /* Algorithm: | ||
| 41 | |||
| 42 | 	x = 2^k z | ||
| 43 | 	log(x) = k ln2 + log(c) + log(z/c) | ||
| 44 | 	log(z/c) = poly(z/c - 1) | ||
| 45 | |||
| 46 | where z is in [1.6p-1; 1.6p0] which is split into N subintervals and z falls | ||
| 47 | into the ith one, then table entries are computed as | ||
| 48 | |||
| 49 | 	tab[i].invc = 1/c | ||
| 50 | 	tab[i].logc = (double)log(c) | ||
| 51 | 	tab2[i].chi = (double)c | ||
| 52 | 	tab2[i].clo = (double)(c - (double)c) | ||
| 53 | |||
| 54 | where c is near the center of the subinterval and is chosen by trying +-2^29 | ||
| 55 | floating point invc candidates around 1/center and selecting one for which | ||
| 56 | |||
| 57 | 	1) the rounding error in 0x1.8p9 + logc is 0, | ||
| 58 | 	2) the rounding error in z - chi - clo is < 0x1p-66 and | ||
| 59 | 	3) the rounding error in (double)log(c) is minimized (< 0x1p-66). | ||
| 60 | |||
| 61 | Note: 1) ensures that k*ln2hi + logc can be computed without rounding error, | ||
| 62 | 2) ensures that z/c - 1 can be computed as (z - chi - clo)*invc with close to | ||
| 63 | a single rounding error when there is no fast fma for z*invc - 1, 3) ensures | ||
| 64 | that logc + poly(z/c - 1) has small error, however near x == 1 when | ||
| 65 | |log(x)| < 0x1p-4, this is not enough so that is special cased. */ | ||
| 66 | .tab = { | ||
| 67 | {0x1.734f0c3e0de9fp+0, -0x1.7cc7f79e69000p-2}, | ||
| 68 | {0x1.713786a2ce91fp+0, -0x1.76feec20d0000p-2}, | ||
| 69 | {0x1.6f26008fab5a0p+0, -0x1.713e31351e000p-2}, | ||
| 70 | {0x1.6d1a61f138c7dp+0, -0x1.6b85b38287800p-2}, | ||
| 71 | {0x1.6b1490bc5b4d1p+0, -0x1.65d5590807800p-2}, | ||
| 72 | {0x1.69147332f0cbap+0, -0x1.602d076180000p-2}, | ||
| 73 | {0x1.6719f18224223p+0, -0x1.5a8ca86909000p-2}, | ||
| 74 | {0x1.6524f99a51ed9p+0, -0x1.54f4356035000p-2}, | ||
| 75 | {0x1.63356aa8f24c4p+0, -0x1.4f637c36b4000p-2}, | ||
| 76 | {0x1.614b36b9ddc14p+0, -0x1.49da7fda85000p-2}, | ||
| 77 | {0x1.5f66452c65c4cp+0, -0x1.445923989a800p-2}, | ||
| 78 | {0x1.5d867b5912c4fp+0, -0x1.3edf439b0b800p-2}, | ||
| 79 | {0x1.5babccb5b90dep+0, -0x1.396ce448f7000p-2}, | ||
| 80 | {0x1.59d61f2d91a78p+0, -0x1.3401e17bda000p-2}, | ||
| 81 | {0x1.5805612465687p+0, -0x1.2e9e2ef468000p-2}, | ||
| 82 | {0x1.56397cee76bd3p+0, -0x1.2941b3830e000p-2}, | ||
| 83 | {0x1.54725e2a77f93p+0, -0x1.23ec58cda8800p-2}, | ||
| 84 | {0x1.52aff42064583p+0, -0x1.1e9e129279000p-2}, | ||
| 85 | {0x1.50f22dbb2bddfp+0, -0x1.1956d2b48f800p-2}, | ||
| 86 | {0x1.4f38f4734ded7p+0, -0x1.141679ab9f800p-2}, | ||
| 87 | {0x1.4d843cfde2840p+0, -0x1.0edd094ef9800p-2}, | ||
| 88 | {0x1.4bd3ec078a3c8p+0, -0x1.09aa518db1000p-2}, | ||
| 89 | {0x1.4a27fc3e0258ap+0, -0x1.047e65263b800p-2}, | ||
| 90 | {0x1.4880524d48434p+0, -0x1.feb224586f000p-3}, | ||
| 91 | {0x1.46dce1b192d0bp+0, -0x1.f474a7517b000p-3}, | ||
| 92 | {0x1.453d9d3391854p+0, -0x1.ea4443d103000p-3}, | ||
| 93 | {0x1.43a2744b4845ap+0, -0x1.e020d44e9b000p-3}, | ||
| 94 | {0x1.420b54115f8fbp+0, -0x1.d60a22977f000p-3}, | ||
| 95 | {0x1.40782da3ef4b1p+0, -0x1.cc00104959000p-3}, | ||
| 96 | {0x1.3ee8f5d57fe8fp+0, -0x1.c202956891000p-3}, | ||
| 97 | {0x1.3d5d9a00b4ce9p+0, -0x1.b81178d811000p-3}, | ||
| 98 | {0x1.3bd60c010c12bp+0, -0x1.ae2c9ccd3d000p-3}, | ||
| 99 | {0x1.3a5242b75dab8p+0, -0x1.a45402e129000p-3}, | ||
| 100 | {0x1.38d22cd9fd002p+0, -0x1.9a877681df000p-3}, | ||
| 101 | {0x1.3755bc5847a1cp+0, -0x1.90c6d69483000p-3}, | ||
| 102 | {0x1.35dce49ad36e2p+0, -0x1.87120a645c000p-3}, | ||
| 103 | {0x1.34679984dd440p+0, -0x1.7d68fb4143000p-3}, | ||
| 104 | {0x1.32f5cceffcb24p+0, -0x1.73cb83c627000p-3}, | ||
| 105 | {0x1.3187775a10d49p+0, -0x1.6a39a9b376000p-3}, | ||
| 106 | {0x1.301c8373e3990p+0, -0x1.60b3154b7a000p-3}, | ||
| 107 | {0x1.2eb4ebb95f841p+0, -0x1.5737d76243000p-3}, | ||
| 108 | {0x1.2d50a0219a9d1p+0, -0x1.4dc7b8fc23000p-3}, | ||
| 109 | {0x1.2bef9a8b7fd2ap+0, -0x1.4462c51d20000p-3}, | ||
| 110 | {0x1.2a91c7a0c1babp+0, -0x1.3b08abc830000p-3}, | ||
| 111 | {0x1.293726014b530p+0, -0x1.31b996b490000p-3}, | ||
| 112 | {0x1.27dfa5757a1f5p+0, -0x1.2875490a44000p-3}, | ||
| 113 | {0x1.268b39b1d3bbfp+0, -0x1.1f3b9f879a000p-3}, | ||
| 114 | {0x1.2539d838ff5bdp+0, -0x1.160c8252ca000p-3}, | ||
| 115 | {0x1.23eb7aac9083bp+0, -0x1.0ce7f57f72000p-3}, | ||
| 116 | {0x1.22a012ba940b6p+0, -0x1.03cdc49fea000p-3}, | ||
| 117 | {0x1.2157996cc4132p+0, -0x1.f57bdbc4b8000p-4}, | ||
| 118 | {0x1.201201dd2fc9bp+0, -0x1.e370896404000p-4}, | ||
| 119 | {0x1.1ecf4494d480bp+0, -0x1.d17983ef94000p-4}, | ||
| 120 | {0x1.1d8f5528f6569p+0, -0x1.bf9674ed8a000p-4}, | ||
| 121 | {0x1.1c52311577e7cp+0, -0x1.adc79202f6000p-4}, | ||
| 122 | {0x1.1b17c74cb26e9p+0, -0x1.9c0c3e7288000p-4}, | ||
| 123 | {0x1.19e010c2c1ab6p+0, -0x1.8a646b372c000p-4}, | ||
| 124 | {0x1.18ab07bb670bdp+0, -0x1.78d01b3ac0000p-4}, | ||
| 125 | {0x1.1778a25efbcb6p+0, -0x1.674f145380000p-4}, | ||
| 126 | {0x1.1648d354c31dap+0, -0x1.55e0e6d878000p-4}, | ||
| 127 | {0x1.151b990275fddp+0, -0x1.4485cdea1e000p-4}, | ||
| 128 | {0x1.13f0ea432d24cp+0, -0x1.333d94d6aa000p-4}, | ||
| 129 | {0x1.12c8b7210f9dap+0, -0x1.22079f8c56000p-4}, | ||
| 130 | {0x1.11a3028ecb531p+0, -0x1.10e4698622000p-4}, | ||
| 131 | {0x1.107fbda8434afp+0, -0x1.ffa6c6ad20000p-5}, | ||
| 132 | {0x1.0f5ee0f4e6bb3p+0, -0x1.dda8d4a774000p-5}, | ||
| 133 | {0x1.0e4065d2a9fcep+0, -0x1.bbcece4850000p-5}, | ||
| 134 | {0x1.0d244632ca521p+0, -0x1.9a1894012c000p-5}, | ||
| 135 | {0x1.0c0a77ce2981ap+0, -0x1.788583302c000p-5}, | ||
| 136 | {0x1.0af2f83c636d1p+0, -0x1.5715e67d68000p-5}, | ||
| 137 | {0x1.09ddb98a01339p+0, -0x1.35c8a49658000p-5}, | ||
| 138 | {0x1.08cabaf52e7dfp+0, -0x1.149e364154000p-5}, | ||
| 139 | {0x1.07b9f2f4e28fbp+0, -0x1.e72c082eb8000p-6}, | ||
| 140 | {0x1.06ab58c358f19p+0, -0x1.a55f152528000p-6}, | ||
| 141 | {0x1.059eea5ecf92cp+0, -0x1.63d62cf818000p-6}, | ||
| 142 | {0x1.04949cdd12c90p+0, -0x1.228fb8caa0000p-6}, | ||
| 143 | {0x1.038c6c6f0ada9p+0, -0x1.c317b20f90000p-7}, | ||
| 144 | {0x1.02865137932a9p+0, -0x1.419355daa0000p-7}, | ||
| 145 | {0x1.0182427ea7348p+0, -0x1.81203c2ec0000p-8}, | ||
| 146 | {0x1.008040614b195p+0, -0x1.0040979240000p-9}, | ||
| 147 | {0x1.fe01ff726fa1ap-1, 0x1.feff384900000p-9}, | ||
| 148 | {0x1.fa11cc261ea74p-1, 0x1.7dc41353d0000p-7}, | ||
| 149 | {0x1.f6310b081992ep-1, 0x1.3cea3c4c28000p-6}, | ||
| 150 | {0x1.f25f63ceeadcdp-1, 0x1.b9fc114890000p-6}, | ||
| 151 | {0x1.ee9c8039113e7p-1, 0x1.1b0d8ce110000p-5}, | ||
| 152 | {0x1.eae8078cbb1abp-1, 0x1.58a5bd001c000p-5}, | ||
| 153 | {0x1.e741aa29d0c9bp-1, 0x1.95c8340d88000p-5}, | ||
| 154 | {0x1.e3a91830a99b5p-1, 0x1.d276aef578000p-5}, | ||
| 155 | {0x1.e01e009609a56p-1, 0x1.07598e598c000p-4}, | ||
| 156 | {0x1.dca01e577bb98p-1, 0x1.253f5e30d2000p-4}, | ||
| 157 | {0x1.d92f20b7c9103p-1, 0x1.42edd8b380000p-4}, | ||
| 158 | {0x1.d5cac66fb5ccep-1, 0x1.606598757c000p-4}, | ||
| 159 | {0x1.d272caa5ede9dp-1, 0x1.7da76356a0000p-4}, | ||
| 160 | {0x1.cf26e3e6b2ccdp-1, 0x1.9ab434e1c6000p-4}, | ||
| 161 | {0x1.cbe6da2a77902p-1, 0x1.b78c7bb0d6000p-4}, | ||
| 162 | {0x1.c8b266d37086dp-1, 0x1.d431332e72000p-4}, | ||
| 163 | {0x1.c5894bd5d5804p-1, 0x1.f0a3171de6000p-4}, | ||
| 164 | {0x1.c26b533bb9f8cp-1, 0x1.067152b914000p-3}, | ||
| 165 | {0x1.bf583eeece73fp-1, 0x1.147858292b000p-3}, | ||
| 166 | {0x1.bc4fd75db96c1p-1, 0x1.2266ecdca3000p-3}, | ||
| 167 | {0x1.b951e0c864a28p-1, 0x1.303d7a6c55000p-3}, | ||
| 168 | {0x1.b65e2c5ef3e2cp-1, 0x1.3dfc33c331000p-3}, | ||
| 169 | {0x1.b374867c9888bp-1, 0x1.4ba366b7a8000p-3}, | ||
| 170 | {0x1.b094b211d304ap-1, 0x1.5933928d1f000p-3}, | ||
| 171 | {0x1.adbe885f2ef7ep-1, 0x1.66acd2418f000p-3}, | ||
| 172 | {0x1.aaf1d31603da2p-1, 0x1.740f8ec669000p-3}, | ||
| 173 | {0x1.a82e63fd358a7p-1, 0x1.815c0f51af000p-3}, | ||
| 174 | {0x1.a5740ef09738bp-1, 0x1.8e92954f68000p-3}, | ||
| 175 | {0x1.a2c2a90ab4b27p-1, 0x1.9bb3602f84000p-3}, | ||
| 176 | {0x1.a01a01393f2d1p-1, 0x1.a8bed1c2c0000p-3}, | ||
| 177 | {0x1.9d79f24db3c1bp-1, 0x1.b5b515c01d000p-3}, | ||
| 178 | {0x1.9ae2505c7b190p-1, 0x1.c2967ccbcc000p-3}, | ||
| 179 | {0x1.9852ef297ce2fp-1, 0x1.cf635d5486000p-3}, | ||
| 180 | {0x1.95cbaeea44b75p-1, 0x1.dc1bd3446c000p-3}, | ||
| 181 | {0x1.934c69de74838p-1, 0x1.e8c01b8cfe000p-3}, | ||
| 182 | {0x1.90d4f2f6752e6p-1, 0x1.f5509c0179000p-3}, | ||
| 183 | {0x1.8e6528effd79dp-1, 0x1.00e6c121fb800p-2}, | ||
| 184 | {0x1.8bfce9fcc007cp-1, 0x1.071b80e93d000p-2}, | ||
| 185 | {0x1.899c0dabec30ep-1, 0x1.0d46b9e867000p-2}, | ||
| 186 | {0x1.87427aa2317fbp-1, 0x1.13687334bd000p-2}, | ||
| 187 | {0x1.84f00acb39a08p-1, 0x1.1980d67234800p-2}, | ||
| 188 | {0x1.82a49e8653e55p-1, 0x1.1f8ffe0cc8000p-2}, | ||
| 189 | {0x1.8060195f40260p-1, 0x1.2595fd7636800p-2}, | ||
| 190 | {0x1.7e22563e0a329p-1, 0x1.2b9300914a800p-2}, | ||
| 191 | {0x1.7beb377dcb5adp-1, 0x1.3187210436000p-2}, | ||
| 192 | {0x1.79baa679725c2p-1, 0x1.377266dec1800p-2}, | ||
| 193 | {0x1.77907f2170657p-1, 0x1.3d54ffbaf3000p-2}, | ||
| 194 | {0x1.756cadbd6130cp-1, 0x1.432eee32fe000p-2}, | ||
| 195 | }, | ||
| 196 | #if !__FP_FAST_FMA | ||
| 197 | .tab2 = { | ||
| 198 | {0x1.61000014fb66bp-1, 0x1.e026c91425b3cp-56}, | ||
| 199 | {0x1.63000034db495p-1, 0x1.dbfea48005d41p-55}, | ||
| 200 | {0x1.650000d94d478p-1, 0x1.e7fa786d6a5b7p-55}, | ||
| 201 | {0x1.67000074e6fadp-1, 0x1.1fcea6b54254cp-57}, | ||
| 202 | {0x1.68ffffedf0faep-1, -0x1.c7e274c590efdp-56}, | ||
| 203 | {0x1.6b0000763c5bcp-1, -0x1.ac16848dcda01p-55}, | ||
| 204 | {0x1.6d0001e5cc1f6p-1, 0x1.33f1c9d499311p-55}, | ||
| 205 | {0x1.6efffeb05f63ep-1, -0x1.e80041ae22d53p-56}, | ||
| 206 | {0x1.710000e86978p-1, 0x1.bff6671097952p-56}, | ||
| 207 | {0x1.72ffffc67e912p-1, 0x1.c00e226bd8724p-55}, | ||
| 208 | {0x1.74fffdf81116ap-1, -0x1.e02916ef101d2p-57}, | ||
| 209 | {0x1.770000f679c9p-1, -0x1.7fc71cd549c74p-57}, | ||
| 210 | {0x1.78ffffa7ec835p-1, 0x1.1bec19ef50483p-55}, | ||
| 211 | {0x1.7affffe20c2e6p-1, -0x1.07e1729cc6465p-56}, | ||
| 212 | {0x1.7cfffed3fc9p-1, -0x1.08072087b8b1cp-55}, | ||
| 213 | {0x1.7efffe9261a76p-1, 0x1.dc0286d9df9aep-55}, | ||
| 214 | {0x1.81000049ca3e8p-1, 0x1.97fd251e54c33p-55}, | ||
| 215 | {0x1.8300017932c8fp-1, -0x1.afee9b630f381p-55}, | ||
| 216 | {0x1.850000633739cp-1, 0x1.9bfbf6b6535bcp-55}, | ||
| 217 | {0x1.87000204289c6p-1, -0x1.bbf65f3117b75p-55}, | ||
| 218 | {0x1.88fffebf57904p-1, -0x1.9006ea23dcb57p-55}, | ||
| 219 | {0x1.8b00022bc04dfp-1, -0x1.d00df38e04b0ap-56}, | ||
| 220 | {0x1.8cfffe50c1b8ap-1, -0x1.8007146ff9f05p-55}, | ||
| 221 | {0x1.8effffc918e43p-1, 0x1.3817bd07a7038p-55}, | ||
| 222 | {0x1.910001efa5fc7p-1, 0x1.93e9176dfb403p-55}, | ||
| 223 | {0x1.9300013467bb9p-1, 0x1.f804e4b980276p-56}, | ||
| 224 | {0x1.94fffe6ee076fp-1, -0x1.f7ef0d9ff622ep-55}, | ||
| 225 | {0x1.96fffde3c12d1p-1, -0x1.082aa962638bap-56}, | ||
| 226 | {0x1.98ffff4458a0dp-1, -0x1.7801b9164a8efp-55}, | ||
| 227 | {0x1.9afffdd982e3ep-1, -0x1.740e08a5a9337p-55}, | ||
| 228 | {0x1.9cfffed49fb66p-1, 0x1.fce08c19bep-60}, | ||
| 229 | {0x1.9f00020f19c51p-1, -0x1.a3faa27885b0ap-55}, | ||
| 230 | {0x1.a10001145b006p-1, 0x1.4ff489958da56p-56}, | ||
| 231 | {0x1.a300007bbf6fap-1, 0x1.cbeab8a2b6d18p-55}, | ||
| 232 | {0x1.a500010971d79p-1, 0x1.8fecadd78793p-55}, | ||
| 233 | {0x1.a70001df52e48p-1, -0x1.f41763dd8abdbp-55}, | ||
| 234 | {0x1.a90001c593352p-1, -0x1.ebf0284c27612p-55}, | ||
| 235 | {0x1.ab0002a4f3e4bp-1, -0x1.9fd043cff3f5fp-57}, | ||
| 236 | {0x1.acfffd7ae1ed1p-1, -0x1.23ee7129070b4p-55}, | ||
| 237 | {0x1.aefffee510478p-1, 0x1.a063ee00edea3p-57}, | ||
| 238 | {0x1.b0fffdb650d5bp-1, 0x1.a06c8381f0ab9p-58}, | ||
| 239 | {0x1.b2ffffeaaca57p-1, -0x1.9011e74233c1dp-56}, | ||
| 240 | {0x1.b4fffd995badcp-1, -0x1.9ff1068862a9fp-56}, | ||
| 241 | {0x1.b7000249e659cp-1, 0x1.aff45d0864f3ep-55}, | ||
| 242 | {0x1.b8ffff987164p-1, 0x1.cfe7796c2c3f9p-56}, | ||
| 243 | {0x1.bafffd204cb4fp-1, -0x1.3ff27eef22bc4p-57}, | ||
| 244 | {0x1.bcfffd2415c45p-1, -0x1.cffb7ee3bea21p-57}, | ||
| 245 | {0x1.beffff86309dfp-1, -0x1.14103972e0b5cp-55}, | ||
| 246 | {0x1.c0fffe1b57653p-1, 0x1.bc16494b76a19p-55}, | ||
| 247 | {0x1.c2ffff1fa57e3p-1, -0x1.4feef8d30c6edp-57}, | ||
| 248 | {0x1.c4fffdcbfe424p-1, -0x1.43f68bcec4775p-55}, | ||
| 249 | {0x1.c6fffed54b9f7p-1, 0x1.47ea3f053e0ecp-55}, | ||
| 250 | {0x1.c8fffeb998fd5p-1, 0x1.383068df992f1p-56}, | ||
| 251 | {0x1.cb0002125219ap-1, -0x1.8fd8e64180e04p-57}, | ||
| 252 | {0x1.ccfffdd94469cp-1, 0x1.e7ebe1cc7ea72p-55}, | ||
| 253 | {0x1.cefffeafdc476p-1, 0x1.ebe39ad9f88fep-55}, | ||
| 254 | {0x1.d1000169af82bp-1, 0x1.57d91a8b95a71p-56}, | ||
| 255 | {0x1.d30000d0ff71dp-1, 0x1.9c1906970c7dap-55}, | ||
| 256 | {0x1.d4fffea790fc4p-1, -0x1.80e37c558fe0cp-58}, | ||
| 257 | {0x1.d70002edc87e5p-1, -0x1.f80d64dc10f44p-56}, | ||
| 258 | {0x1.d900021dc82aap-1, -0x1.47c8f94fd5c5cp-56}, | ||
| 259 | {0x1.dafffd86b0283p-1, 0x1.c7f1dc521617ep-55}, | ||
| 260 | {0x1.dd000296c4739p-1, 0x1.8019eb2ffb153p-55}, | ||
| 261 | {0x1.defffe54490f5p-1, 0x1.e00d2c652cc89p-57}, | ||
| 262 | {0x1.e0fffcdabf694p-1, -0x1.f8340202d69d2p-56}, | ||
| 263 | {0x1.e2fffdb52c8ddp-1, 0x1.b00c1ca1b0864p-56}, | ||
| 264 | {0x1.e4ffff24216efp-1, 0x1.2ffa8b094ab51p-56}, | ||
| 265 | {0x1.e6fffe88a5e11p-1, -0x1.7f673b1efbe59p-58}, | ||
| 266 | {0x1.e9000119eff0dp-1, -0x1.4808d5e0bc801p-55}, | ||
| 267 | {0x1.eafffdfa51744p-1, 0x1.80006d54320b5p-56}, | ||
| 268 | {0x1.ed0001a127fa1p-1, -0x1.002f860565c92p-58}, | ||
| 269 | {0x1.ef00007babcc4p-1, -0x1.540445d35e611p-55}, | ||
| 270 | {0x1.f0ffff57a8d02p-1, -0x1.ffb3139ef9105p-59}, | ||
| 271 | {0x1.f30001ee58ac7p-1, 0x1.a81acf2731155p-55}, | ||
| 272 | {0x1.f4ffff5823494p-1, 0x1.a3f41d4d7c743p-55}, | ||
| 273 | {0x1.f6ffffca94c6bp-1, -0x1.202f41c987875p-57}, | ||
| 274 | {0x1.f8fffe1f9c441p-1, 0x1.77dd1f477e74bp-56}, | ||
| 275 | {0x1.fafffd2e0e37ep-1, -0x1.f01199a7ca331p-57}, | ||
| 276 | {0x1.fd0001c77e49ep-1, 0x1.181ee4bceacb1p-56}, | ||
| 277 | {0x1.feffff7e0c331p-1, -0x1.e05370170875ap-57}, | ||
| 278 | {0x1.00ffff465606ep+0, -0x1.a7ead491c0adap-55}, | ||
| 279 | {0x1.02ffff3867a58p+0, -0x1.77f69c3fcb2ep-54}, | ||
| 280 | {0x1.04ffffdfc0d17p+0, 0x1.7bffe34cb945bp-54}, | ||
| 281 | {0x1.0700003cd4d82p+0, 0x1.20083c0e456cbp-55}, | ||
| 282 | {0x1.08ffff9f2cbe8p+0, -0x1.dffdfbe37751ap-57}, | ||
| 283 | {0x1.0b000010cda65p+0, -0x1.13f7faee626ebp-54}, | ||
| 284 | {0x1.0d00001a4d338p+0, 0x1.07dfa79489ff7p-55}, | ||
| 285 | {0x1.0effffadafdfdp+0, -0x1.7040570d66bcp-56}, | ||
| 286 | {0x1.110000bbafd96p+0, 0x1.e80d4846d0b62p-55}, | ||
| 287 | {0x1.12ffffae5f45dp+0, 0x1.dbffa64fd36efp-54}, | ||
| 288 | {0x1.150000dd59ad9p+0, 0x1.a0077701250aep-54}, | ||
| 289 | {0x1.170000f21559ap+0, 0x1.dfdf9e2e3deeep-55}, | ||
| 290 | {0x1.18ffffc275426p+0, 0x1.10030dc3b7273p-54}, | ||
| 291 | {0x1.1b000123d3c59p+0, 0x1.97f7980030188p-54}, | ||
| 292 | {0x1.1cffff8299eb7p+0, -0x1.5f932ab9f8c67p-57}, | ||
| 293 | {0x1.1effff48ad4p+0, 0x1.37fbf9da75bebp-54}, | ||
| 294 | {0x1.210000c8b86a4p+0, 0x1.f806b91fd5b22p-54}, | ||
| 295 | {0x1.2300003854303p+0, 0x1.3ffc2eb9fbf33p-54}, | ||
| 296 | {0x1.24fffffbcf684p+0, 0x1.601e77e2e2e72p-56}, | ||
| 297 | {0x1.26ffff52921d9p+0, 0x1.ffcbb767f0c61p-56}, | ||
| 298 | {0x1.2900014933a3cp+0, -0x1.202ca3c02412bp-56}, | ||
| 299 | {0x1.2b00014556313p+0, -0x1.2808233f21f02p-54}, | ||
| 300 | {0x1.2cfffebfe523bp+0, -0x1.8ff7e384fdcf2p-55}, | ||
| 301 | {0x1.2f0000bb8ad96p+0, -0x1.5ff51503041c5p-55}, | ||
| 302 | {0x1.30ffffb7ae2afp+0, -0x1.10071885e289dp-55}, | ||
| 303 | {0x1.32ffffeac5f7fp+0, -0x1.1ff5d3fb7b715p-54}, | ||
| 304 | {0x1.350000ca66756p+0, 0x1.57f82228b82bdp-54}, | ||
| 305 | {0x1.3700011fbf721p+0, 0x1.000bac40dd5ccp-55}, | ||
| 306 | {0x1.38ffff9592fb9p+0, -0x1.43f9d2db2a751p-54}, | ||
| 307 | {0x1.3b00004ddd242p+0, 0x1.57f6b707638e1p-55}, | ||
| 308 | {0x1.3cffff5b2c957p+0, 0x1.a023a10bf1231p-56}, | ||
| 309 | {0x1.3efffeab0b418p+0, 0x1.87f6d66b152bp-54}, | ||
| 310 | {0x1.410001532aff4p+0, 0x1.7f8375f198524p-57}, | ||
| 311 | {0x1.4300017478b29p+0, 0x1.301e672dc5143p-55}, | ||
| 312 | {0x1.44fffe795b463p+0, 0x1.9ff69b8b2895ap-55}, | ||
| 313 | {0x1.46fffe80475ep+0, -0x1.5c0b19bc2f254p-54}, | ||
| 314 | {0x1.48fffef6fc1e7p+0, 0x1.b4009f23a2a72p-54}, | ||
| 315 | {0x1.4afffe5bea704p+0, -0x1.4ffb7bf0d7d45p-54}, | ||
| 316 | {0x1.4d000171027dep+0, -0x1.9c06471dc6a3dp-54}, | ||
| 317 | {0x1.4f0000ff03ee2p+0, 0x1.77f890b85531cp-54}, | ||
| 318 | {0x1.5100012dc4bd1p+0, 0x1.004657166a436p-57}, | ||
| 319 | {0x1.530001605277ap+0, -0x1.6bfcece233209p-54}, | ||
| 320 | {0x1.54fffecdb704cp+0, -0x1.902720505a1d7p-55}, | ||
| 321 | {0x1.56fffef5f54a9p+0, 0x1.bbfe60ec96412p-54}, | ||
| 322 | {0x1.5900017e61012p+0, 0x1.87ec581afef9p-55}, | ||
| 323 | {0x1.5b00003c93e92p+0, -0x1.f41080abf0ccp-54}, | ||
| 324 | {0x1.5d0001d4919bcp+0, -0x1.8812afb254729p-54}, | ||
| 325 | {0x1.5efffe7b87a89p+0, -0x1.47eb780ed6904p-54}, | ||
| 326 | }, | ||
| 327 | #endif | ||
| 328 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/log_data.h created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _LOG_DATA_H | ||
| 6 | #define _LOG_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define LOG_TABLE_BITS 7 | ||
| 11 | #define LOG_POLY_ORDER 6 | ||
| 12 | #define LOG_POLY1_ORDER 12 | ||
| 13 | extern hidden const struct log_data { | ||
| 14 | 	double ln2hi; | ||
| 15 | 	double ln2lo; | ||
| 16 | 	double poly[LOG_POLY_ORDER - 1]; /* First coefficient is 1. */ | ||
| 17 | 	double poly1[LOG_POLY1_ORDER - 1]; | ||
| 18 | 	struct { | ||
| 19 | 		double invc, logc; | ||
| 20 | 	} tab[1 << LOG_TABLE_BITS]; | ||
| 21 | #if !__FP_FAST_FMA | ||
| 22 | 	struct { | ||
| 23 | 		double chi, clo; | ||
| 24 | 	} tab2[1 << LOG_TABLE_BITS]; | ||
| 25 | #endif | ||
| 26 | } __log_data; | ||
| 27 | |||
| 28 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/logb.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | /* | ||
| 4 | special cases: | ||
| 5 | 	logb(+-0) = -inf, and raise divbyzero | ||
| 6 | 	logb(+-inf) = +inf | ||
| 7 | 	logb(nan) = nan | ||
| 8 | */ | ||
| 9 | |||
| 10 | double logb(double x) | ||
| 11 | { | ||
| 12 | 	if (!isfinite(x)) | ||
| 13 | 		return x * x; | ||
| 14 | 	if (x == 0) | ||
| 15 | 		return -1/(x*x); | ||
| 16 | 	return ilogb(x); | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/logbf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float logbf(float x) | ||
| 4 | { | ||
| 5 | 	if (!isfinite(x)) | ||
| 6 | 		return x * x; | ||
| 7 | 	if (x == 0) | ||
| 8 | 		return -1/(x*x); | ||
| 9 | 	return ilogbf(x); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/logbl.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 3 | long double logbl(long double x) | ||
| 4 | { | ||
| 5 | 	return logb(x); | ||
| 6 | } | ||
| 7 | #else | ||
| 8 | long double logbl(long double x) | ||
| 9 | { | ||
| 10 | 	if (!isfinite(x)) | ||
| 11 | 		return x * x; | ||
| 12 | 	if (x == 0) | ||
| 13 | 		return -1/(x*x); | ||
| 14 | 	return ilogbl(x); | ||
| 15 | } | ||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/logf.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | /* | ||
| 2 | * Single-precision log function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "logf_data.h" | ||
| 12 | |||
| 13 | /* | ||
| 14 | LOGF_TABLE_BITS = 4 | ||
| 15 | LOGF_POLY_ORDER = 4 | ||
| 16 | |||
| 17 | ULP error: 0.818 (nearest rounding.) | ||
| 18 | Relative error: 1.957 * 2^-26 (before rounding.) | ||
| 19 | */ | ||
| 20 | |||
| 21 | #define T __logf_data.tab | ||
| 22 | #define A __logf_data.poly | ||
| 23 | #define Ln2 __logf_data.ln2 | ||
| 24 | #define N (1 << LOGF_TABLE_BITS) | ||
| 25 | #define OFF 0x3f330000 | ||
| 26 | |||
| 27 | float logf(float x) | ||
| 28 | { | ||
| 29 | 	double_t z, r, r2, y, y0, invc, logc; | ||
| 30 | 	uint32_t ix, iz, tmp; | ||
| 31 | 	int k, i; | ||
| 32 | |||
| 33 | 	ix = asuint(x); | ||
| 34 | 	/* Fix sign of zero with downward rounding when x==1. */ | ||
| 35 | 	if (WANT_ROUNDING && predict_false(ix == 0x3f800000)) | ||
| 36 | 		return 0; | ||
| 37 | 	if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) { | ||
| 38 | 		/* x < 0x1p-126 or inf or nan. */ | ||
| 39 | 		if (ix * 2 == 0) | ||
| 40 | 			return __math_divzerof(1); | ||
| 41 | 		if (ix == 0x7f800000) /* log(inf) == inf. */ | ||
| 42 | 			return x; | ||
| 43 | 		if ((ix & 0x80000000) || ix * 2 >= 0xff000000) | ||
| 44 | 			return __math_invalidf(x); | ||
| 45 | 		/* x is subnormal, normalize it. */ | ||
| 46 | 		ix = asuint(x * 0x1p23f); | ||
| 47 | 		ix -= 23 << 23; | ||
| 48 | 	} | ||
| 49 | |||
| 50 | 	/* x = 2^k z; where z is in range [OFF,2*OFF] and exact. | ||
| 51 | 	 The range is split into N subintervals. | ||
| 52 | 	 The ith subinterval contains z and c is near its center. */ | ||
| 53 | 	tmp = ix - OFF; | ||
| 54 | 	i = (tmp >> (23 - LOGF_TABLE_BITS)) % N; | ||
| 55 | 	k = (int32_t)tmp >> 23; /* arithmetic shift */ | ||
| 56 | 	iz = ix - (tmp & 0x1ff << 23); | ||
| 57 | 	invc = T[i].invc; | ||
| 58 | 	logc = T[i].logc; | ||
| 59 | 	z = (double_t)asfloat(iz); | ||
| 60 | |||
| 61 | 	/* log(x) = log1p(z/c-1) + log(c) + k*Ln2 */ | ||
| 62 | 	r = z * invc - 1; | ||
| 63 | 	y0 = logc + (double_t)k * Ln2; | ||
| 64 | |||
| 65 | 	/* Pipelined polynomial evaluation to approximate log1p(r). */ | ||
| 66 | 	r2 = r * r; | ||
| 67 | 	y = A[1] * r + A[2]; | ||
| 68 | 	y = A[0] * r2 + y; | ||
| 69 | 	y = y * r2 + (y0 + r); | ||
| 70 | 	return eval_as_float(y); | ||
| 71 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/logf_data.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | /* | ||
| 2 | * Data definition for logf. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "logf_data.h" | ||
| 9 | |||
| 10 | const struct logf_data __logf_data = { | ||
| 11 | .tab = { | ||
| 12 | { 0x1.661ec79f8f3bep+0, -0x1.57bf7808caadep-2 }, | ||
| 13 | { 0x1.571ed4aaf883dp+0, -0x1.2bef0a7c06ddbp-2 }, | ||
| 14 | { 0x1.49539f0f010bp+0, -0x1.01eae7f513a67p-2 }, | ||
| 15 | { 0x1.3c995b0b80385p+0, -0x1.b31d8a68224e9p-3 }, | ||
| 16 | { 0x1.30d190c8864a5p+0, -0x1.6574f0ac07758p-3 }, | ||
| 17 | { 0x1.25e227b0b8eap+0, -0x1.1aa2bc79c81p-3 }, | ||
| 18 | { 0x1.1bb4a4a1a343fp+0, -0x1.a4e76ce8c0e5ep-4 }, | ||
| 19 | { 0x1.12358f08ae5bap+0, -0x1.1973c5a611cccp-4 }, | ||
| 20 | { 0x1.0953f419900a7p+0, -0x1.252f438e10c1ep-5 }, | ||
| 21 | { 0x1p+0, 0x0p+0 }, | ||
| 22 | { 0x1.e608cfd9a47acp-1, 0x1.aa5aa5df25984p-5 }, | ||
| 23 | { 0x1.ca4b31f026aap-1, 0x1.c5e53aa362eb4p-4 }, | ||
| 24 | { 0x1.b2036576afce6p-1, 0x1.526e57720db08p-3 }, | ||
| 25 | { 0x1.9c2d163a1aa2dp-1, 0x1.bc2860d22477p-3 }, | ||
| 26 | { 0x1.886e6037841edp-1, 0x1.1058bc8a07ee1p-2 }, | ||
| 27 | { 0x1.767dcf5534862p-1, 0x1.4043057b6ee09p-2 }, | ||
| 28 | }, | ||
| 29 | .ln2 = 0x1.62e42fefa39efp-1, | ||
| 30 | .poly = { | ||
| 31 | -0x1.00ea348b88334p-2, 0x1.5575b0be00b6ap-2, -0x1.ffffef20a4123p-2, | ||
| 32 | } | ||
| 33 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/logf_data.h created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _LOGF_DATA_H | ||
| 6 | #define _LOGF_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define LOGF_TABLE_BITS 4 | ||
| 11 | #define LOGF_POLY_ORDER 4 | ||
| 12 | extern hidden const struct logf_data { | ||
| 13 | 	struct { | ||
| 14 | 		double invc, logc; | ||
| 15 | 	} tab[1 << LOGF_TABLE_BITS]; | ||
| 16 | 	double ln2; | ||
| 17 | 	double poly[LOGF_POLY_ORDER - 1]; /* First order coefficient is 1. */ | ||
| 18 | } __logf_data; | ||
| 19 | |||
| 20 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/logl.c created+175| ... | @@ -0,0 +1,175 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_logl.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 | /* | ||
| 18 | * Natural logarithm, long double precision | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * long double x, y, logl(); | ||
| 24 | * | ||
| 25 | * y = logl( x ); | ||
| 26 | * | ||
| 27 | * | ||
| 28 | * DESCRIPTION: | ||
| 29 | * | ||
| 30 | * Returns the base e (2.718...) logarithm of x. | ||
| 31 | * | ||
| 32 | * The argument is separated into its exponent and fractional | ||
| 33 | * parts. If the exponent is between -1 and +1, the logarithm | ||
| 34 | * of the fraction is approximated by | ||
| 35 | * | ||
| 36 | * log(1+x) = x - 0.5 x**2 + x**3 P(x)/Q(x). | ||
| 37 | * | ||
| 38 | * Otherwise, setting z = 2(x-1)/(x+1), | ||
| 39 | * | ||
| 40 | * log(x) = log(1+z/2) - log(1-z/2) = z + z**3 P(z)/Q(z). | ||
| 41 | * | ||
| 42 | * | ||
| 43 | * ACCURACY: | ||
| 44 | * | ||
| 45 | * Relative error: | ||
| 46 | * arithmetic domain # trials peak rms | ||
| 47 | * IEEE 0.5, 2.0 150000 8.71e-20 2.75e-20 | ||
| 48 | * IEEE exp(+-10000) 100000 5.39e-20 2.34e-20 | ||
| 49 | * | ||
| 50 | * In the tests over the interval exp(+-10000), the logarithms | ||
| 51 | * of the random arguments were uniformly distributed over | ||
| 52 | * [-10000, +10000]. | ||
| 53 | */ | ||
| 54 | |||
| 55 | #include "libm.h" | ||
| 56 | |||
| 57 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 58 | long double logl(long double x) | ||
| 59 | { | ||
| 60 | 	return log(x); | ||
| 61 | } | ||
| 62 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 63 | /* Coefficients for log(1+x) = x - x**2/2 + x**3 P(x)/Q(x) | ||
| 64 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 65 | * Theoretical peak relative error = 2.32e-20 | ||
| 66 | */ | ||
| 67 | static const long double P[] = { | ||
| 68 | 4.5270000862445199635215E-5L, | ||
| 69 | 4.9854102823193375972212E-1L, | ||
| 70 | 6.5787325942061044846969E0L, | ||
| 71 | 2.9911919328553073277375E1L, | ||
| 72 | 6.0949667980987787057556E1L, | ||
| 73 | 5.7112963590585538103336E1L, | ||
| 74 | 2.0039553499201281259648E1L, | ||
| 75 | }; | ||
| 76 | static const long double Q[] = { | ||
| 77 | /* 1.0000000000000000000000E0,*/ | ||
| 78 | 1.5062909083469192043167E1L, | ||
| 79 | 8.3047565967967209469434E1L, | ||
| 80 | 2.2176239823732856465394E2L, | ||
| 81 | 3.0909872225312059774938E2L, | ||
| 82 | 2.1642788614495947685003E2L, | ||
| 83 | 6.0118660497603843919306E1L, | ||
| 84 | }; | ||
| 85 | |||
| 86 | /* Coefficients for log(x) = z + z^3 P(z^2)/Q(z^2), | ||
| 87 | * where z = 2(x-1)/(x+1) | ||
| 88 | * 1/sqrt(2) <= x < sqrt(2) | ||
| 89 | * Theoretical peak relative error = 6.16e-22 | ||
| 90 | */ | ||
| 91 | static const long double R[4] = { | ||
| 92 | 1.9757429581415468984296E-3L, | ||
| 93 | -7.1990767473014147232598E-1L, | ||
| 94 | 1.0777257190312272158094E1L, | ||
| 95 | -3.5717684488096787370998E1L, | ||
| 96 | }; | ||
| 97 | static const long double S[4] = { | ||
| 98 | /* 1.00000000000000000000E0L,*/ | ||
| 99 | -2.6201045551331104417768E1L, | ||
| 100 | 1.9361891836232102174846E2L, | ||
| 101 | -4.2861221385716144629696E2L, | ||
| 102 | }; | ||
| 103 | static const long double C1 = 6.9314575195312500000000E-1L; | ||
| 104 | static const long double C2 = 1.4286068203094172321215E-6L; | ||
| 105 | |||
| 106 | #define SQRTH 0.70710678118654752440L | ||
| 107 | |||
| 108 | long double logl(long double x) | ||
| 109 | { | ||
| 110 | 	long double y, z; | ||
| 111 | 	int e; | ||
| 112 | |||
| 113 | 	if (isnan(x)) | ||
| 114 | 		return x; | ||
| 115 | 	if (x == INFINITY) | ||
| 116 | 		return x; | ||
| 117 | 	if (x <= 0.0) { | ||
| 118 | 		if (x == 0.0) | ||
| 119 | 			return -1/(x*x); /* -inf with divbyzero */ | ||
| 120 | 		return 0/0.0f; /* nan with invalid */ | ||
| 121 | 	} | ||
| 122 | |||
| 123 | 	/* separate mantissa from exponent */ | ||
| 124 | 	/* Note, frexp is used so that denormal numbers | ||
| 125 | 	 * will be handled properly. | ||
| 126 | 	 */ | ||
| 127 | 	x = frexpl(x, &e); | ||
| 128 | |||
| 129 | 	/* logarithm using log(x) = z + z**3 P(z)/Q(z), | ||
| 130 | 	 * where z = 2(x-1)/(x+1) | ||
| 131 | 	 */ | ||
| 132 | 	if (e > 2 || e < -2) { | ||
| 133 | 		if (x < SQRTH) { /* 2(2x-1)/(2x+1) */ | ||
| 134 | 			e -= 1; | ||
| 135 | 			z = x - 0.5; | ||
| 136 | 			y = 0.5 * z + 0.5; | ||
| 137 | 		} else { /* 2 (x-1)/(x+1) */ | ||
| 138 | 			z = x - 0.5; | ||
| 139 | 			z -= 0.5; | ||
| 140 | 			y = 0.5 * x + 0.5; | ||
| 141 | 		} | ||
| 142 | 		x = z / y; | ||
| 143 | 		z = x*x; | ||
| 144 | 		z = x * (z * __polevll(z, R, 3) / __p1evll(z, S, 3)); | ||
| 145 | 		z = z + e * C2; | ||
| 146 | 		z = z + x; | ||
| 147 | 		z = z + e * C1; | ||
| 148 | 		return z; | ||
| 149 | 	} | ||
| 150 | |||
| 151 | 	/* logarithm using log(1+x) = x - .5x**2 + x**3 P(x)/Q(x) */ | ||
| 152 | 	if (x < SQRTH) { | ||
| 153 | 		e -= 1; | ||
| 154 | 		x = 2.0*x - 1.0; | ||
| 155 | 	} else { | ||
| 156 | 		x = x - 1.0; | ||
| 157 | 	} | ||
| 158 | 	z = x*x; | ||
| 159 | 	y = x * (z * __polevll(x, P, 6) / __p1evll(x, Q, 6)); | ||
| 160 | 	y = y + e * C2; | ||
| 161 | 	z = y - 0.5*z; | ||
| 162 | 	/* Note, the sum of above terms does not exceed x/4, | ||
| 163 | 	 * so it contributes at most about 1/4 lsb to the error. | ||
| 164 | 	 */ | ||
| 165 | 	z = z + x; | ||
| 166 | 	z = z + e * C1; /* This sum has an error of 1/2 lsb. */ | ||
| 167 | 	return z; | ||
| 168 | } | ||
| 169 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 170 | // TODO: broken implementation to make things compile | ||
| 171 | long double logl(long double x) | ||
| 172 | { | ||
| 173 | 	return log(x); | ||
| 174 | } | ||
| 175 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/lrint.c created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <fenv.h> | ||
| 3 | #include <math.h> | ||
| 4 | #include "libm.h" | ||
| 5 | |||
| 6 | /* | ||
| 7 | If the result cannot be represented (overflow, nan), then | ||
| 8 | lrint raises the invalid exception. | ||
| 9 | |||
| 10 | Otherwise if the input was not an integer then the inexact | ||
| 11 | exception is raised. | ||
| 12 | |||
| 13 | C99 is a bit vague about whether inexact exception is | ||
| 14 | allowed to be raised when invalid is raised. | ||
| 15 | (F.9 explicitly allows spurious inexact exceptions, F.9.6.5 | ||
| 16 | does not make it clear if that rule applies to lrint, but | ||
| 17 | IEEE 754r 7.8 seems to forbid spurious inexact exception in | ||
| 18 | the ineger conversion functions) | ||
| 19 | |||
| 20 | So we try to make sure that no spurious inexact exception is | ||
| 21 | raised in case of an overflow. | ||
| 22 | |||
| 23 | If the bit size of long > precision of double, then there | ||
| 24 | cannot be inexact rounding in case the result overflows, | ||
| 25 | otherwise LONG_MAX and LONG_MIN can be represented exactly | ||
| 26 | as a double. | ||
| 27 | */ | ||
| 28 | |||
| 29 | #if LONG_MAX < 1U<<53 && defined(FE_INEXACT) | ||
| 30 | #include <float.h> | ||
| 31 | #include <stdint.h> | ||
| 32 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 33 | #define EPS DBL_EPSILON | ||
| 34 | #elif FLT_EVAL_METHOD==2 | ||
| 35 | #define EPS LDBL_EPSILON | ||
| 36 | #endif | ||
| 37 | #ifdef __GNUC__ | ||
| 38 | /* avoid stack frame in lrint */ | ||
| 39 | __attribute__((noinline)) | ||
| 40 | #endif | ||
| 41 | static long lrint_slow(double x) | ||
| 42 | { | ||
| 43 | 	#pragma STDC FENV_ACCESS ON | ||
| 44 | 	int e; | ||
| 45 | |||
| 46 | 	e = fetestexcept(FE_INEXACT); | ||
| 47 | 	x = rint(x); | ||
| 48 | 	if (!e && (x > LONG_MAX || x < LONG_MIN)) | ||
| 49 | 		feclearexcept(FE_INEXACT); | ||
| 50 | 	/* conversion */ | ||
| 51 | 	return x; | ||
| 52 | } | ||
| 53 | |||
| 54 | long lrint(double x) | ||
| 55 | { | ||
| 56 | 	uint32_t abstop = asuint64(x)>>32 & 0x7fffffff; | ||
| 57 | 	uint64_t sign = asuint64(x) & (1ULL << 63); | ||
| 58 | |||
| 59 | 	if (abstop < 0x41dfffff) { | ||
| 60 | 		/* |x| < 0x7ffffc00, no overflow */ | ||
| 61 | 		double_t toint = asdouble(asuint64(1/EPS) | sign); | ||
| 62 | 		double_t y = x + toint - toint; | ||
| 63 | 		return (long)y; | ||
| 64 | 	} | ||
| 65 | 	return lrint_slow(x); | ||
| 66 | } | ||
| 67 | #else | ||
| 68 | long lrint(double x) | ||
| 69 | { | ||
| 70 | 	return rint(x); | ||
| 71 | } | ||
| 72 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/lrintf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | /* uses LONG_MAX > 2^24, see comments in lrint.c */ | ||
| 4 | |||
| 5 | long lrintf(float x) | ||
| 6 | { | ||
| 7 | 	return rintf(x); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/lrintl.c created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <fenv.h> | ||
| 3 | #include "libm.h" | ||
| 4 | |||
| 5 | |||
| 6 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 7 | long lrintl(long double x) | ||
| 8 | { | ||
| 9 | 	return lrint(x); | ||
| 10 | } | ||
| 11 | #elif defined(FE_INEXACT) | ||
| 12 | /* | ||
| 13 | see comments in lrint.c | ||
| 14 | |||
| 15 | Note that if LONG_MAX == 0x7fffffffffffffff && LDBL_MANT_DIG == 64 | ||
| 16 | then x == 2**63 - 0.5 is the only input that overflows and | ||
| 17 | raises inexact (with tonearest or upward rounding mode) | ||
| 18 | */ | ||
| 19 | long lrintl(long double x) | ||
| 20 | { | ||
| 21 | 	#pragma STDC FENV_ACCESS ON | ||
| 22 | 	int e; | ||
| 23 | |||
| 24 | 	e = fetestexcept(FE_INEXACT); | ||
| 25 | 	x = rintl(x); | ||
| 26 | 	if (!e && (x > LONG_MAX || x < LONG_MIN)) | ||
| 27 | 		feclearexcept(FE_INEXACT); | ||
| 28 | 	/* conversion */ | ||
| 29 | 	return x; | ||
| 30 | } | ||
| 31 | #else | ||
| 32 | long lrintl(long double x) | ||
| 33 | { | ||
| 34 | 	return rintl(x); | ||
| 35 | } | ||
| 36 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/lround.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lround(double x) | ||
| 4 | { | ||
| 5 | 	return round(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/lroundf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lroundf(float x) | ||
| 4 | { | ||
| 5 | 	return roundf(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/lroundl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lroundl(long double x) | ||
| 4 | { | ||
| 5 | 	return roundl(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/m68k/sqrtl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __HAVE_68881__ | ||
| 4 | |||
| 5 | long double sqrtl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsqrt.x %1,%0" : "=f"(x) : "fm"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrtl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/mips/fabs.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #if !defined(__mips_soft_float) && defined(__mips_abs2008) | ||
| 2 | |||
| 3 | #include <math.h> | ||
| 4 | |||
| 5 | double fabs(double x) | ||
| 6 | { | ||
| 7 | 	double r; | ||
| 8 | 	__asm__("abs.d %0,%1" : "=f"(r) : "f"(x)); | ||
| 9 | 	return r; | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include "../fabs.c" | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/mips/fabsf.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #if !defined(__mips_soft_float) && defined(__mips_abs2008) | ||
| 2 | |||
| 3 | #include <math.h> | ||
| 4 | |||
| 5 | float fabsf(float x) | ||
| 6 | { | ||
| 7 | 	float r; | ||
| 8 | 	__asm__("abs.s %0,%1" : "=f"(r) : "f"(x)); | ||
| 9 | 	return r; | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include "../fabsf.c" | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/mips/sqrt.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #if !defined(__mips_soft_float) && __mips >= 3 | ||
| 2 | |||
| 3 | #include <math.h> | ||
| 4 | |||
| 5 | double sqrt(double x) | ||
| 6 | { | ||
| 7 | 	double r; | ||
| 8 | 	__asm__("sqrt.d %0,%1" : "=f"(r) : "f"(x)); | ||
| 9 | 	return r; | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include "../sqrt.c" | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/mips/sqrtf.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #if !defined(__mips_soft_float) && __mips >= 2 | ||
| 2 | |||
| 3 | #include <math.h> | ||
| 4 | |||
| 5 | float sqrtf(float x) | ||
| 6 | { | ||
| 7 | 	float r; | ||
| 8 | 	__asm__("sqrt.s %0,%1" : "=f"(r) : "f"(x)); | ||
| 9 | 	return r; | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include "../sqrtf.c" | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/modf.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double modf(double x, double *iptr) | ||
| 4 | { | ||
| 5 | 	union {double f; uint64_t i;} u = {x}; | ||
| 6 | 	uint64_t mask; | ||
| 7 | 	int e = (int)(u.i>>52 & 0x7ff) - 0x3ff; | ||
| 8 | |||
| 9 | 	/* no fractional part */ | ||
| 10 | 	if (e >= 52) { | ||
| 11 | 		*iptr = x; | ||
| 12 | 		if (e == 0x400 && u.i<<12 != 0) /* nan */ | ||
| 13 | 			return x; | ||
| 14 | 		u.i &= 1ULL<<63; | ||
| 15 | 		return u.f; | ||
| 16 | 	} | ||
| 17 | |||
| 18 | 	/* no integral part*/ | ||
| 19 | 	if (e < 0) { | ||
| 20 | 		u.i &= 1ULL<<63; | ||
| 21 | 		*iptr = u.f; | ||
| 22 | 		return x; | ||
| 23 | 	} | ||
| 24 | |||
| 25 | 	mask = -1ULL>>12>>e; | ||
| 26 | 	if ((u.i & mask) == 0) { | ||
| 27 | 		*iptr = x; | ||
| 28 | 		u.i &= 1ULL<<63; | ||
| 29 | 		return u.f; | ||
| 30 | 	} | ||
| 31 | 	u.i &= ~mask; | ||
| 32 | 	*iptr = u.f; | ||
| 33 | 	return x - u.f; | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/modff.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float modff(float x, float *iptr) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {x}; | ||
| 6 | 	uint32_t mask; | ||
| 7 | 	int e = (int)(u.i>>23 & 0xff) - 0x7f; | ||
| 8 | |||
| 9 | 	/* no fractional part */ | ||
| 10 | 	if (e >= 23) { | ||
| 11 | 		*iptr = x; | ||
| 12 | 		if (e == 0x80 && u.i<<9 != 0) { /* nan */ | ||
| 13 | 			return x; | ||
| 14 | 		} | ||
| 15 | 		u.i &= 0x80000000; | ||
| 16 | 		return u.f; | ||
| 17 | 	} | ||
| 18 | 	/* no integral part */ | ||
| 19 | 	if (e < 0) { | ||
| 20 | 		u.i &= 0x80000000; | ||
| 21 | 		*iptr = u.f; | ||
| 22 | 		return x; | ||
| 23 | 	} | ||
| 24 | |||
| 25 | 	mask = 0x007fffff>>e; | ||
| 26 | 	if ((u.i & mask) == 0) { | ||
| 27 | 		*iptr = x; | ||
| 28 | 		u.i &= 0x80000000; | ||
| 29 | 		return u.f; | ||
| 30 | 	} | ||
| 31 | 	u.i &= ~mask; | ||
| 32 | 	*iptr = u.f; | ||
| 33 | 	return x - u.f; | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/modfl.c created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double modfl(long double x, long double *iptr) | ||
| 5 | { | ||
| 6 | 	double d; | ||
| 7 | 	long double r; | ||
| 8 | |||
| 9 | 	r = modf(x, &d); | ||
| 10 | 	*iptr = d; | ||
| 11 | 	return r; | ||
| 12 | } | ||
| 13 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 14 | |||
| 15 | static const long double toint = 1/LDBL_EPSILON; | ||
| 16 | |||
| 17 | long double modfl(long double x, long double *iptr) | ||
| 18 | { | ||
| 19 | 	union ldshape u = {x}; | ||
| 20 | 	int e = (u.i.se & 0x7fff) - 0x3fff; | ||
| 21 | 	int s = u.i.se >> 15; | ||
| 22 | 	long double absx; | ||
| 23 | 	long double y; | ||
| 24 | |||
| 25 | 	/* no fractional part */ | ||
| 26 | 	if (e >= LDBL_MANT_DIG-1) { | ||
| 27 | 		*iptr = x; | ||
| 28 | 		if (isnan(x)) | ||
| 29 | 			return x; | ||
| 30 | 		return s ? -0.0 : 0.0; | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	/* no integral part*/ | ||
| 34 | 	if (e < 0) { | ||
| 35 | 		*iptr = s ? -0.0 : 0.0; | ||
| 36 | 		return x; | ||
| 37 | 	} | ||
| 38 | |||
| 39 | 	/* raises spurious inexact */ | ||
| 40 | 	absx = s ? -x : x; | ||
| 41 | 	y = absx + toint - toint - absx; | ||
| 42 | 	if (y == 0) { | ||
| 43 | 		*iptr = x; | ||
| 44 | 		return s ? -0.0 : 0.0; | ||
| 45 | 	} | ||
| 46 | 	if (y > 0) | ||
| 47 | 		y -= 1; | ||
| 48 | 	if (s) | ||
| 49 | 		y = -y; | ||
| 50 | 	*iptr = x + y; | ||
| 51 | 	return -y; | ||
| 52 | } | ||
| 53 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/nan.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double nan(const char *s) | ||
| 4 | { | ||
| 5 | 	return NAN; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nanf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float nanf(const char *s) | ||
| 4 | { | ||
| 5 | 	return NAN; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nanl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double nanl(const char *s) | ||
| 4 | { | ||
| 5 | 	return NAN; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nearbyint.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | /* nearbyint is the same as rint, but it must not raise the inexact exception */ | ||
| 5 | |||
| 6 | double nearbyint(double x) | ||
| 7 | { | ||
| 8 | #ifdef FE_INEXACT | ||
| 9 | 	#pragma STDC FENV_ACCESS ON | ||
| 10 | 	int e; | ||
| 11 | |||
| 12 | 	e = fetestexcept(FE_INEXACT); | ||
| 13 | #endif | ||
| 14 | 	x = rint(x); | ||
| 15 | #ifdef FE_INEXACT | ||
| 16 | 	if (!e) | ||
| 17 | 		feclearexcept(FE_INEXACT); | ||
| 18 | #endif | ||
| 19 | 	return x; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nearbyintf.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <fenv.h> | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | float nearbyintf(float x) | ||
| 5 | { | ||
| 6 | #ifdef FE_INEXACT | ||
| 7 | 	#pragma STDC FENV_ACCESS ON | ||
| 8 | 	int e; | ||
| 9 | |||
| 10 | 	e = fetestexcept(FE_INEXACT); | ||
| 11 | #endif | ||
| 12 | 	x = rintf(x); | ||
| 13 | #ifdef FE_INEXACT | ||
| 14 | 	if (!e) | ||
| 15 | 		feclearexcept(FE_INEXACT); | ||
| 16 | #endif | ||
| 17 | 	return x; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nearbyintl.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <float.h> | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | long double nearbyintl(long double x) | ||
| 6 | { | ||
| 7 | 	return nearbyint(x); | ||
| 8 | } | ||
| 9 | #else | ||
| 10 | #include <fenv.h> | ||
| 11 | long double nearbyintl(long double x) | ||
| 12 | { | ||
| 13 | #ifdef FE_INEXACT | ||
| 14 | 	#pragma STDC FENV_ACCESS ON | ||
| 15 | 	int e; | ||
| 16 | |||
| 17 | 	e = fetestexcept(FE_INEXACT); | ||
| 18 | #endif | ||
| 19 | 	x = rintl(x); | ||
| 20 | #ifdef FE_INEXACT | ||
| 21 | 	if (!e) | ||
| 22 | 		feclearexcept(FE_INEXACT); | ||
| 23 | #endif | ||
| 24 | 	return x; | ||
| 25 | } | ||
| 26 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/nextafter.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double nextafter(double x, double y) | ||
| 4 | { | ||
| 5 | 	union {double f; uint64_t i;} ux={x}, uy={y}; | ||
| 6 | 	uint64_t ax, ay; | ||
| 7 | 	int e; | ||
| 8 | |||
| 9 | 	if (isnan(x) || isnan(y)) | ||
| 10 | 		return x + y; | ||
| 11 | 	if (ux.i == uy.i) | ||
| 12 | 		return y; | ||
| 13 | 	ax = ux.i & -1ULL/2; | ||
| 14 | 	ay = uy.i & -1ULL/2; | ||
| 15 | 	if (ax == 0) { | ||
| 16 | 		if (ay == 0) | ||
| 17 | 			return y; | ||
| 18 | 		ux.i = (uy.i & 1ULL<<63) | 1; | ||
| 19 | 	} else if (ax > ay || ((ux.i ^ uy.i) & 1ULL<<63)) | ||
| 20 | 		ux.i--; | ||
| 21 | 	else | ||
| 22 | 		ux.i++; | ||
| 23 | 	e = ux.i >> 52 & 0x7ff; | ||
| 24 | 	/* raise overflow if ux.f is infinite and x is finite */ | ||
| 25 | 	if (e == 0x7ff) | ||
| 26 | 		FORCE_EVAL(x+x); | ||
| 27 | 	/* raise underflow if ux.f is subnormal or zero */ | ||
| 28 | 	if (e == 0) | ||
| 29 | 		FORCE_EVAL(x*x + ux.f*ux.f); | ||
| 30 | 	return ux.f; | ||
| 31 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nextafterf.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float nextafterf(float x, float y) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} ux={x}, uy={y}; | ||
| 6 | 	uint32_t ax, ay, e; | ||
| 7 | |||
| 8 | 	if (isnan(x) || isnan(y)) | ||
| 9 | 		return x + y; | ||
| 10 | 	if (ux.i == uy.i) | ||
| 11 | 		return y; | ||
| 12 | 	ax = ux.i & 0x7fffffff; | ||
| 13 | 	ay = uy.i & 0x7fffffff; | ||
| 14 | 	if (ax == 0) { | ||
| 15 | 		if (ay == 0) | ||
| 16 | 			return y; | ||
| 17 | 		ux.i = (uy.i & 0x80000000) | 1; | ||
| 18 | 	} else if (ax > ay || ((ux.i ^ uy.i) & 0x80000000)) | ||
| 19 | 		ux.i--; | ||
| 20 | 	else | ||
| 21 | 		ux.i++; | ||
| 22 | 	e = ux.i & 0x7f800000; | ||
| 23 | 	/* raise overflow if ux.f is infinite and x is finite */ | ||
| 24 | 	if (e == 0x7f800000) | ||
| 25 | 		FORCE_EVAL(x+x); | ||
| 26 | 	/* raise underflow if ux.f is subnormal or zero */ | ||
| 27 | 	if (e == 0) | ||
| 28 | 		FORCE_EVAL(x*x + ux.f*ux.f); | ||
| 29 | 	return ux.f; | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nextafterl.c created+75| ... | @@ -0,0 +1,75 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double nextafterl(long double x, long double y) | ||
| 5 | { | ||
| 6 | 	return nextafter(x, y); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | long double nextafterl(long double x, long double y) | ||
| 10 | { | ||
| 11 | 	union ldshape ux, uy; | ||
| 12 | |||
| 13 | 	if (isnan(x) || isnan(y)) | ||
| 14 | 		return x + y; | ||
| 15 | 	if (x == y) | ||
| 16 | 		return y; | ||
| 17 | 	ux.f = x; | ||
| 18 | 	if (x == 0) { | ||
| 19 | 		uy.f = y; | ||
| 20 | 		ux.i.m = 1; | ||
| 21 | 		ux.i.se = uy.i.se & 0x8000; | ||
| 22 | 	} else if ((x < y) == !(ux.i.se & 0x8000)) { | ||
| 23 | 		ux.i.m++; | ||
| 24 | 		if (ux.i.m << 1 == 0) { | ||
| 25 | 			ux.i.m = 1ULL << 63; | ||
| 26 | 			ux.i.se++; | ||
| 27 | 		} | ||
| 28 | 	} else { | ||
| 29 | 		if (ux.i.m << 1 == 0) { | ||
| 30 | 			ux.i.se--; | ||
| 31 | 			if (ux.i.se) | ||
| 32 | 				ux.i.m = 0; | ||
| 33 | 		} | ||
| 34 | 		ux.i.m--; | ||
| 35 | 	} | ||
| 36 | 	/* raise overflow if ux is infinite and x is finite */ | ||
| 37 | 	if ((ux.i.se & 0x7fff) == 0x7fff) | ||
| 38 | 		return x + x; | ||
| 39 | 	/* raise underflow if ux is subnormal or zero */ | ||
| 40 | 	if ((ux.i.se & 0x7fff) == 0) | ||
| 41 | 		FORCE_EVAL(x*x + ux.f*ux.f); | ||
| 42 | 	return ux.f; | ||
| 43 | } | ||
| 44 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 45 | long double nextafterl(long double x, long double y) | ||
| 46 | { | ||
| 47 | 	union ldshape ux, uy; | ||
| 48 | |||
| 49 | 	if (isnan(x) || isnan(y)) | ||
| 50 | 		return x + y; | ||
| 51 | 	if (x == y) | ||
| 52 | 		return y; | ||
| 53 | 	ux.f = x; | ||
| 54 | 	if (x == 0) { | ||
| 55 | 		uy.f = y; | ||
| 56 | 		ux.i.lo = 1; | ||
| 57 | 		ux.i.se = uy.i.se & 0x8000; | ||
| 58 | 	} else if ((x < y) == !(ux.i.se & 0x8000)) { | ||
| 59 | 		ux.i2.lo++; | ||
| 60 | 		if (ux.i2.lo == 0) | ||
| 61 | 			ux.i2.hi++; | ||
| 62 | 	} else { | ||
| 63 | 		if (ux.i2.lo == 0) | ||
| 64 | 			ux.i2.hi--; | ||
| 65 | 		ux.i2.lo--; | ||
| 66 | 	} | ||
| 67 | 	/* raise overflow if ux is infinite and x is finite */ | ||
| 68 | 	if ((ux.i.se & 0x7fff) == 0x7fff) | ||
| 69 | 		return x + x; | ||
| 70 | 	/* raise underflow if ux is subnormal or zero */ | ||
| 71 | 	if ((ux.i.se & 0x7fff) == 0) | ||
| 72 | 		FORCE_EVAL(x*x + ux.f*ux.f); | ||
| 73 | 	return ux.f; | ||
| 74 | } | ||
| 75 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/nexttoward.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | double nexttoward(double x, long double y) | ||
| 5 | { | ||
| 6 | 	return nextafter(x, y); | ||
| 7 | } | ||
| 8 | #else | ||
| 9 | double nexttoward(double x, long double y) | ||
| 10 | { | ||
| 11 | 	union {double f; uint64_t i;} ux = {x}; | ||
| 12 | 	int e; | ||
| 13 | |||
| 14 | 	if (isnan(x) || isnan(y)) | ||
| 15 | 		return x + y; | ||
| 16 | 	if (x == y) | ||
| 17 | 		return y; | ||
| 18 | 	if (x == 0) { | ||
| 19 | 		ux.i = 1; | ||
| 20 | 		if (signbit(y)) | ||
| 21 | 			ux.i |= 1ULL<<63; | ||
| 22 | 	} else if (x < y) { | ||
| 23 | 		if (signbit(x)) | ||
| 24 | 			ux.i--; | ||
| 25 | 		else | ||
| 26 | 			ux.i++; | ||
| 27 | 	} else { | ||
| 28 | 		if (signbit(x)) | ||
| 29 | 			ux.i++; | ||
| 30 | 		else | ||
| 31 | 			ux.i--; | ||
| 32 | 	} | ||
| 33 | 	e = ux.i>>52 & 0x7ff; | ||
| 34 | 	/* raise overflow if ux.f is infinite and x is finite */ | ||
| 35 | 	if (e == 0x7ff) | ||
| 36 | 		FORCE_EVAL(x+x); | ||
| 37 | 	/* raise underflow if ux.f is subnormal or zero */ | ||
| 38 | 	if (e == 0) | ||
| 39 | 		FORCE_EVAL(x*x + ux.f*ux.f); | ||
| 40 | 	return ux.f; | ||
| 41 | } | ||
| 42 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/nexttowardf.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float nexttowardf(float x, long double y) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} ux = {x}; | ||
| 6 | 	uint32_t e; | ||
| 7 | |||
| 8 | 	if (isnan(x) || isnan(y)) | ||
| 9 | 		return x + y; | ||
| 10 | 	if (x == y) | ||
| 11 | 		return y; | ||
| 12 | 	if (x == 0) { | ||
| 13 | 		ux.i = 1; | ||
| 14 | 		if (signbit(y)) | ||
| 15 | 			ux.i |= 0x80000000; | ||
| 16 | 	} else if (x < y) { | ||
| 17 | 		if (signbit(x)) | ||
| 18 | 			ux.i--; | ||
| 19 | 		else | ||
| 20 | 			ux.i++; | ||
| 21 | 	} else { | ||
| 22 | 		if (signbit(x)) | ||
| 23 | 			ux.i++; | ||
| 24 | 		else | ||
| 25 | 			ux.i--; | ||
| 26 | 	} | ||
| 27 | 	e = ux.i & 0x7f800000; | ||
| 28 | 	/* raise overflow if ux.f is infinite and x is finite */ | ||
| 29 | 	if (e == 0x7f800000) | ||
| 30 | 		FORCE_EVAL(x+x); | ||
| 31 | 	/* raise underflow if ux.f is subnormal or zero */ | ||
| 32 | 	if (e == 0) | ||
| 33 | 		FORCE_EVAL(x*x + ux.f*ux.f); | ||
| 34 | 	return ux.f; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/nexttowardl.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double nexttowardl(long double x, long double y) | ||
| 4 | { | ||
| 5 | 	return nextafterl(x, y); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/pow.c created+343| ... | @@ -0,0 +1,343 @@ | ||
| 1 | /* | ||
| 2 | * Double-precision x^y function. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include <math.h> | ||
| 9 | #include <stdint.h> | ||
| 10 | #include "libm.h" | ||
| 11 | #include "exp_data.h" | ||
| 12 | #include "pow_data.h" | ||
| 13 | |||
| 14 | /* | ||
| 15 | Worst-case error: 0.54 ULP (~= ulperr_exp + 1024*Ln2*relerr_log*2^53) | ||
| 16 | relerr_log: 1.3 * 2^-68 (Relative error of log, 1.5 * 2^-68 without fma) | ||
| 17 | ulperr_exp: 0.509 ULP (ULP error of exp, 0.511 ULP without fma) | ||
| 18 | */ | ||
| 19 | |||
| 20 | #define T __pow_log_data.tab | ||
| 21 | #define A __pow_log_data.poly | ||
| 22 | #define Ln2hi __pow_log_data.ln2hi | ||
| 23 | #define Ln2lo __pow_log_data.ln2lo | ||
| 24 | #define N (1 << POW_LOG_TABLE_BITS) | ||
| 25 | #define OFF 0x3fe6955500000000 | ||
| 26 | |||
| 27 | /* Top 12 bits of a double (sign and exponent bits). */ | ||
| 28 | static inline uint32_t top12(double x) | ||
| 29 | { | ||
| 30 | 	return asuint64(x) >> 52; | ||
| 31 | } | ||
| 32 | |||
| 33 | /* Compute y+TAIL = log(x) where the rounded result is y and TAIL has about | ||
| 34 | additional 15 bits precision. IX is the bit representation of x, but | ||
| 35 | normalized in the subnormal range using the sign bit for the exponent. */ | ||
| 36 | static inline double_t log_inline(uint64_t ix, double_t *tail) | ||
| 37 | { | ||
| 38 | 	/* double_t for better performance on targets with FLT_EVAL_METHOD==2. */ | ||
| 39 | 	double_t z, r, y, invc, logc, logctail, kd, hi, t1, t2, lo, lo1, lo2, p; | ||
| 40 | 	uint64_t iz, tmp; | ||
| 41 | 	int k, i; | ||
| 42 | |||
| 43 | 	/* x = 2^k z; where z is in range [OFF,2*OFF) and exact. | ||
| 44 | 	 The range is split into N subintervals. | ||
| 45 | 	 The ith subinterval contains z and c is near its center. */ | ||
| 46 | 	tmp = ix - OFF; | ||
| 47 | 	i = (tmp >> (52 - POW_LOG_TABLE_BITS)) % N; | ||
| 48 | 	k = (int64_t)tmp >> 52; /* arithmetic shift */ | ||
| 49 | 	iz = ix - (tmp & 0xfffULL << 52); | ||
| 50 | 	z = asdouble(iz); | ||
| 51 | 	kd = (double_t)k; | ||
| 52 | |||
| 53 | 	/* log(x) = k*Ln2 + log(c) + log1p(z/c-1). */ | ||
| 54 | 	invc = T[i].invc; | ||
| 55 | 	logc = T[i].logc; | ||
| 56 | 	logctail = T[i].logctail; | ||
| 57 | |||
| 58 | 	/* Note: 1/c is j/N or j/N/2 where j is an integer in [N,2N) and | ||
| 59 | |z/c - 1| < 1/N, so r = z/c - 1 is exactly representible. */ | ||
| 60 | #if __FP_FAST_FMA | ||
| 61 | 	r = __builtin_fma(z, invc, -1.0); | ||
| 62 | #else | ||
| 63 | 	/* Split z such that rhi, rlo and rhi*rhi are exact and |rlo| <= |r|. */ | ||
| 64 | 	double_t zhi = asdouble((iz + (1ULL << 31)) & (-1ULL << 32)); | ||
| 65 | 	double_t zlo = z - zhi; | ||
| 66 | 	double_t rhi = zhi * invc - 1.0; | ||
| 67 | 	double_t rlo = zlo * invc; | ||
| 68 | 	r = rhi + rlo; | ||
| 69 | #endif | ||
| 70 | |||
| 71 | 	/* k*Ln2 + log(c) + r. */ | ||
| 72 | 	t1 = kd * Ln2hi + logc; | ||
| 73 | 	t2 = t1 + r; | ||
| 74 | 	lo1 = kd * Ln2lo + logctail; | ||
| 75 | 	lo2 = t1 - t2 + r; | ||
| 76 | |||
| 77 | 	/* Evaluation is optimized assuming superscalar pipelined execution. */ | ||
| 78 | 	double_t ar, ar2, ar3, lo3, lo4; | ||
| 79 | 	ar = A[0] * r; /* A[0] = -0.5. */ | ||
| 80 | 	ar2 = r * ar; | ||
| 81 | 	ar3 = r * ar2; | ||
| 82 | 	/* k*Ln2 + log(c) + r + A[0]*r*r. */ | ||
| 83 | #if __FP_FAST_FMA | ||
| 84 | 	hi = t2 + ar2; | ||
| 85 | 	lo3 = __builtin_fma(ar, r, -ar2); | ||
| 86 | 	lo4 = t2 - hi + ar2; | ||
| 87 | #else | ||
| 88 | 	double_t arhi = A[0] * rhi; | ||
| 89 | 	double_t arhi2 = rhi * arhi; | ||
| 90 | 	hi = t2 + arhi2; | ||
| 91 | 	lo3 = rlo * (ar + arhi); | ||
| 92 | 	lo4 = t2 - hi + arhi2; | ||
| 93 | #endif | ||
| 94 | 	/* p = log1p(r) - r - A[0]*r*r. */ | ||
| 95 | 	p = (ar3 * (A[1] + r * A[2] + | ||
| 96 | 		 ar2 * (A[3] + r * A[4] + ar2 * (A[5] + r * A[6])))); | ||
| 97 | 	lo = lo1 + lo2 + lo3 + lo4 + p; | ||
| 98 | 	y = hi + lo; | ||
| 99 | 	*tail = hi - y + lo; | ||
| 100 | 	return y; | ||
| 101 | } | ||
| 102 | |||
| 103 | #undef N | ||
| 104 | #undef T | ||
| 105 | #define N (1 << EXP_TABLE_BITS) | ||
| 106 | #define InvLn2N __exp_data.invln2N | ||
| 107 | #define NegLn2hiN __exp_data.negln2hiN | ||
| 108 | #define NegLn2loN __exp_data.negln2loN | ||
| 109 | #define Shift __exp_data.shift | ||
| 110 | #define T __exp_data.tab | ||
| 111 | #define C2 __exp_data.poly[5 - EXP_POLY_ORDER] | ||
| 112 | #define C3 __exp_data.poly[6 - EXP_POLY_ORDER] | ||
| 113 | #define C4 __exp_data.poly[7 - EXP_POLY_ORDER] | ||
| 114 | #define C5 __exp_data.poly[8 - EXP_POLY_ORDER] | ||
| 115 | #define C6 __exp_data.poly[9 - EXP_POLY_ORDER] | ||
| 116 | |||
| 117 | /* Handle cases that may overflow or underflow when computing the result that | ||
| 118 | is scale*(1+TMP) without intermediate rounding. The bit representation of | ||
| 119 | scale is in SBITS, however it has a computed exponent that may have | ||
| 120 | overflown into the sign bit so that needs to be adjusted before using it as | ||
| 121 | a double. (int32_t)KI is the k used in the argument reduction and exponent | ||
| 122 | adjustment of scale, positive k here means the result may overflow and | ||
| 123 | negative k means the result may underflow. */ | ||
| 124 | static inline double specialcase(double_t tmp, uint64_t sbits, uint64_t ki) | ||
| 125 | { | ||
| 126 | 	double_t scale, y; | ||
| 127 | |||
| 128 | 	if ((ki & 0x80000000) == 0) { | ||
| 129 | 		/* k > 0, the exponent of scale might have overflowed by <= 460. */ | ||
| 130 | 		sbits -= 1009ull << 52; | ||
| 131 | 		scale = asdouble(sbits); | ||
| 132 | 		y = 0x1p1009 * (scale + scale * tmp); | ||
| 133 | 		return eval_as_double(y); | ||
| 134 | 	} | ||
| 135 | 	/* k < 0, need special care in the subnormal range. */ | ||
| 136 | 	sbits += 1022ull << 52; | ||
| 137 | 	/* Note: sbits is signed scale. */ | ||
| 138 | 	scale = asdouble(sbits); | ||
| 139 | 	y = scale + scale * tmp; | ||
| 140 | 	if (fabs(y) < 1.0) { | ||
| 141 | 		/* Round y to the right precision before scaling it into the subnormal | ||
| 142 | 		 range to avoid double rounding that can cause 0.5+E/2 ulp error where | ||
| 143 | 		 E is the worst-case ulp error outside the subnormal range. So this | ||
| 144 | 		 is only useful if the goal is better than 1 ulp worst-case error. */ | ||
| 145 | 		double_t hi, lo, one = 1.0; | ||
| 146 | 		if (y < 0.0) | ||
| 147 | 			one = -1.0; | ||
| 148 | 		lo = scale - y + scale * tmp; | ||
| 149 | 		hi = one + y; | ||
| 150 | 		lo = one - hi + y + lo; | ||
| 151 | 		y = eval_as_double(hi + lo) - one; | ||
| 152 | 		/* Fix the sign of 0. */ | ||
| 153 | 		if (y == 0.0) | ||
| 154 | 			y = asdouble(sbits & 0x8000000000000000); | ||
| 155 | 		/* The underflow exception needs to be signaled explicitly. */ | ||
| 156 | 		fp_force_eval(fp_barrier(0x1p-1022) * 0x1p-1022); | ||
| 157 | 	} | ||
| 158 | 	y = 0x1p-1022 * y; | ||
| 159 | 	return eval_as_double(y); | ||
| 160 | } | ||
| 161 | |||
| 162 | #define SIGN_BIAS (0x800 << EXP_TABLE_BITS) | ||
| 163 | |||
| 164 | /* Computes sign*exp(x+xtail) where |xtail| < 2^-8/N and |xtail| <= |x|. | ||
| 165 | The sign_bias argument is SIGN_BIAS or 0 and sets the sign to -1 or 1. */ | ||
| 166 | static inline double exp_inline(double_t x, double_t xtail, uint32_t sign_bias) | ||
| 167 | { | ||
| 168 | 	uint32_t abstop; | ||
| 169 | 	uint64_t ki, idx, top, sbits; | ||
| 170 | 	/* double_t for better performance on targets with FLT_EVAL_METHOD==2. */ | ||
| 171 | 	double_t kd, z, r, r2, scale, tail, tmp; | ||
| 172 | |||
| 173 | 	abstop = top12(x) & 0x7ff; | ||
| 174 | 	if (predict_false(abstop - top12(0x1p-54) >= | ||
| 175 | 			 top12(512.0) - top12(0x1p-54))) { | ||
| 176 | 		if (abstop - top12(0x1p-54) >= 0x80000000) { | ||
| 177 | 			/* Avoid spurious underflow for tiny x. */ | ||
| 178 | 			/* Note: 0 is common input. */ | ||
| 179 | 			double_t one = WANT_ROUNDING ? 1.0 + x : 1.0; | ||
| 180 | 			return sign_bias ? -one : one; | ||
| 181 | 		} | ||
| 182 | 		if (abstop >= top12(1024.0)) { | ||
| 183 | 			/* Note: inf and nan are already handled. */ | ||
| 184 | 			if (asuint64(x) >> 63) | ||
| 185 | 				return __math_uflow(sign_bias); | ||
| 186 | 			else | ||
| 187 | 				return __math_oflow(sign_bias); | ||
| 188 | 		} | ||
| 189 | 		/* Large x is special cased below. */ | ||
| 190 | 		abstop = 0; | ||
| 191 | 	} | ||
| 192 | |||
| 193 | 	/* exp(x) = 2^(k/N) * exp(r), with exp(r) in [2^(-1/2N),2^(1/2N)]. */ | ||
| 194 | 	/* x = ln2/N*k + r, with int k and r in [-ln2/2N, ln2/2N]. */ | ||
| 195 | 	z = InvLn2N * x; | ||
| 196 | #if TOINT_INTRINSICS | ||
| 197 | 	kd = roundtoint(z); | ||
| 198 | 	ki = converttoint(z); | ||
| 199 | #elif EXP_USE_TOINT_NARROW | ||
| 200 | 	/* z - kd is in [-0.5-2^-16, 0.5] in all rounding modes. */ | ||
| 201 | 	kd = eval_as_double(z + Shift); | ||
| 202 | 	ki = asuint64(kd) >> 16; | ||
| 203 | 	kd = (double_t)(int32_t)ki; | ||
| 204 | #else | ||
| 205 | 	/* z - kd is in [-1, 1] in non-nearest rounding modes. */ | ||
| 206 | 	kd = eval_as_double(z + Shift); | ||
| 207 | 	ki = asuint64(kd); | ||
| 208 | 	kd -= Shift; | ||
| 209 | #endif | ||
| 210 | 	r = x + kd * NegLn2hiN + kd * NegLn2loN; | ||
| 211 | 	/* The code assumes 2^-200 < |xtail| < 2^-8/N. */ | ||
| 212 | 	r += xtail; | ||
| 213 | 	/* 2^(k/N) ~= scale * (1 + tail). */ | ||
| 214 | 	idx = 2 * (ki % N); | ||
| 215 | 	top = (ki + sign_bias) << (52 - EXP_TABLE_BITS); | ||
| 216 | 	tail = asdouble(T[idx]); | ||
| 217 | 	/* This is only a valid scale when -1023*N < k < 1024*N. */ | ||
| 218 | 	sbits = T[idx + 1] + top; | ||
| 219 | 	/* exp(x) = 2^(k/N) * exp(r) ~= scale + scale * (tail + exp(r) - 1). */ | ||
| 220 | 	/* Evaluation is optimized assuming superscalar pipelined execution. */ | ||
| 221 | 	r2 = r * r; | ||
| 222 | 	/* Without fma the worst case error is 0.25/N ulp larger. */ | ||
| 223 | 	/* Worst case error is less than 0.5+1.11/N+(abs poly error * 2^53) ulp. */ | ||
| 224 | 	tmp = tail + r + r2 * (C2 + r * C3) + r2 * r2 * (C4 + r * C5); | ||
| 225 | 	if (predict_false(abstop == 0)) | ||
| 226 | 		return specialcase(tmp, sbits, ki); | ||
| 227 | 	scale = asdouble(sbits); | ||
| 228 | 	/* Note: tmp == 0 or |tmp| > 2^-200 and scale > 2^-739, so there | ||
| 229 | 	 is no spurious underflow here even without fma. */ | ||
| 230 | 	return eval_as_double(scale + scale * tmp); | ||
| 231 | } | ||
| 232 | |||
| 233 | /* Returns 0 if not int, 1 if odd int, 2 if even int. The argument is | ||
| 234 | the bit representation of a non-zero finite floating-point value. */ | ||
| 235 | static inline int checkint(uint64_t iy) | ||
| 236 | { | ||
| 237 | 	int e = iy >> 52 & 0x7ff; | ||
| 238 | 	if (e < 0x3ff) | ||
| 239 | 		return 0; | ||
| 240 | 	if (e > 0x3ff + 52) | ||
| 241 | 		return 2; | ||
| 242 | 	if (iy & ((1ULL << (0x3ff + 52 - e)) - 1)) | ||
| 243 | 		return 0; | ||
| 244 | 	if (iy & (1ULL << (0x3ff + 52 - e))) | ||
| 245 | 		return 1; | ||
| 246 | 	return 2; | ||
| 247 | } | ||
| 248 | |||
| 249 | /* Returns 1 if input is the bit representation of 0, infinity or nan. */ | ||
| 250 | static inline int zeroinfnan(uint64_t i) | ||
| 251 | { | ||
| 252 | 	return 2 * i - 1 >= 2 * asuint64(INFINITY) - 1; | ||
| 253 | } | ||
| 254 | |||
| 255 | double pow(double x, double y) | ||
| 256 | { | ||
| 257 | 	uint32_t sign_bias = 0; | ||
| 258 | 	uint64_t ix, iy; | ||
| 259 | 	uint32_t topx, topy; | ||
| 260 | |||
| 261 | 	ix = asuint64(x); | ||
| 262 | 	iy = asuint64(y); | ||
| 263 | 	topx = top12(x); | ||
| 264 | 	topy = top12(y); | ||
| 265 | 	if (predict_false(topx - 0x001 >= 0x7ff - 0x001 || | ||
| 266 | 			 (topy & 0x7ff) - 0x3be >= 0x43e - 0x3be)) { | ||
| 267 | 		/* Note: if |y| > 1075 * ln2 * 2^53 ~= 0x1.749p62 then pow(x,y) = inf/0 | ||
| 268 | 		 and if |y| < 2^-54 / 1075 ~= 0x1.e7b6p-65 then pow(x,y) = +-1. */ | ||
| 269 | 		/* Special cases: (x < 0x1p-126 or inf or nan) or | ||
| 270 | 		 (|y| < 0x1p-65 or |y| >= 0x1p63 or nan). */ | ||
| 271 | 		if (predict_false(zeroinfnan(iy))) { | ||
| 272 | 			if (2 * iy == 0) | ||
| 273 | 				return issignaling_inline(x) ? x + y : 1.0; | ||
| 274 | 			if (ix == asuint64(1.0)) | ||
| 275 | 				return issignaling_inline(y) ? x + y : 1.0; | ||
| 276 | 			if (2 * ix > 2 * asuint64(INFINITY) || | ||
| 277 | 			 2 * iy > 2 * asuint64(INFINITY)) | ||
| 278 | 				return x + y; | ||
| 279 | 			if (2 * ix == 2 * asuint64(1.0)) | ||
| 280 | 				return 1.0; | ||
| 281 | 			if ((2 * ix < 2 * asuint64(1.0)) == !(iy >> 63)) | ||
| 282 | 				return 0.0; /* |x|<1 && y==inf or |x|>1 && y==-inf. */ | ||
| 283 | 			return y * y; | ||
| 284 | 		} | ||
| 285 | 		if (predict_false(zeroinfnan(ix))) { | ||
| 286 | 			double_t x2 = x * x; | ||
| 287 | 			if (ix >> 63 && checkint(iy) == 1) | ||
| 288 | 				x2 = -x2; | ||
| 289 | 			/* Without the barrier some versions of clang hoist the 1/x2 and | ||
| 290 | 			 thus division by zero exception can be signaled spuriously. */ | ||
| 291 | 			return iy >> 63 ? fp_barrier(1 / x2) : x2; | ||
| 292 | 		} | ||
| 293 | 		/* Here x and y are non-zero finite. */ | ||
| 294 | 		if (ix >> 63) { | ||
| 295 | 			/* Finite x < 0. */ | ||
| 296 | 			int yint = checkint(iy); | ||
| 297 | 			if (yint == 0) | ||
| 298 | 				return __math_invalid(x); | ||
| 299 | 			if (yint == 1) | ||
| 300 | 				sign_bias = SIGN_BIAS; | ||
| 301 | 			ix &= 0x7fffffffffffffff; | ||
| 302 | 			topx &= 0x7ff; | ||
| 303 | 		} | ||
| 304 | 		if ((topy & 0x7ff) - 0x3be >= 0x43e - 0x3be) { | ||
| 305 | 			/* Note: sign_bias == 0 here because y is not odd. */ | ||
| 306 | 			if (ix == asuint64(1.0)) | ||
| 307 | 				return 1.0; | ||
| 308 | 			if ((topy & 0x7ff) < 0x3be) { | ||
| 309 | 				/* |y| < 2^-65, x^y ~= 1 + y*log(x). */ | ||
| 310 | 				if (WANT_ROUNDING) | ||
| 311 | 					return ix > asuint64(1.0) ? 1.0 + y : | ||
| 312 | 								 1.0 - y; | ||
| 313 | 				else | ||
| 314 | 					return 1.0; | ||
| 315 | 			} | ||
| 316 | 			return (ix > asuint64(1.0)) == (topy < 0x800) ? | ||
| 317 | 				 __math_oflow(0) : | ||
| 318 | 				 __math_uflow(0); | ||
| 319 | 		} | ||
| 320 | 		if (topx == 0) { | ||
| 321 | 			/* Normalize subnormal x so exponent becomes negative. */ | ||
| 322 | 			ix = asuint64(x * 0x1p52); | ||
| 323 | 			ix &= 0x7fffffffffffffff; | ||
| 324 | 			ix -= 52ULL << 52; | ||
| 325 | 		} | ||
| 326 | 	} | ||
| 327 | |||
| 328 | 	double_t lo; | ||
| 329 | 	double_t hi = log_inline(ix, &lo); | ||
| 330 | 	double_t ehi, elo; | ||
| 331 | #if __FP_FAST_FMA | ||
| 332 | 	ehi = y * hi; | ||
| 333 | 	elo = y * lo + __builtin_fma(y, hi, -ehi); | ||
| 334 | #else | ||
| 335 | 	double_t yhi = asdouble(iy & -1ULL << 27); | ||
| 336 | 	double_t ylo = y - yhi; | ||
| 337 | 	double_t lhi = asdouble(asuint64(hi) & -1ULL << 27); | ||
| 338 | 	double_t llo = hi - lhi + lo; | ||
| 339 | 	ehi = yhi * lhi; | ||
| 340 | 	elo = ylo * lhi + y * llo; /* |elo| < |ehi| * 2^-25. */ | ||
| 341 | #endif | ||
| 342 | 	return exp_inline(ehi, elo, sign_bias); | ||
| 343 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/pow_data.c created+180| ... | @@ -0,0 +1,180 @@ | ||
| 1 | /* | ||
| 2 | * Data for the log part of pow. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "pow_data.h" | ||
| 9 | |||
| 10 | #define N (1 << POW_LOG_TABLE_BITS) | ||
| 11 | |||
| 12 | const struct pow_log_data __pow_log_data = { | ||
| 13 | .ln2hi = 0x1.62e42fefa3800p-1, | ||
| 14 | .ln2lo = 0x1.ef35793c76730p-45, | ||
| 15 | .poly = { | ||
| 16 | // relative error: 0x1.11922ap-70 | ||
| 17 | // in -0x1.6bp-8 0x1.6bp-8 | ||
| 18 | // Coefficients are scaled to match the scaling during evaluation. | ||
| 19 | -0x1p-1, | ||
| 20 | 0x1.555555555556p-2 * -2, | ||
| 21 | -0x1.0000000000006p-2 * -2, | ||
| 22 | 0x1.999999959554ep-3 * 4, | ||
| 23 | -0x1.555555529a47ap-3 * 4, | ||
| 24 | 0x1.2495b9b4845e9p-3 * -8, | ||
| 25 | -0x1.0002b8b263fc3p-3 * -8, | ||
| 26 | }, | ||
| 27 | /* Algorithm: | ||
| 28 | |||
| 29 | 	x = 2^k z | ||
| 30 | 	log(x) = k ln2 + log(c) + log(z/c) | ||
| 31 | 	log(z/c) = poly(z/c - 1) | ||
| 32 | |||
| 33 | where z is in [0x1.69555p-1; 0x1.69555p0] which is split into N subintervals | ||
| 34 | and z falls into the ith one, then table entries are computed as | ||
| 35 | |||
| 36 | 	tab[i].invc = 1/c | ||
| 37 | 	tab[i].logc = round(0x1p43*log(c))/0x1p43 | ||
| 38 | 	tab[i].logctail = (double)(log(c) - logc) | ||
| 39 | |||
| 40 | where c is chosen near the center of the subinterval such that 1/c has only a | ||
| 41 | few precision bits so z/c - 1 is exactly representible as double: | ||
| 42 | |||
| 43 | 	1/c = center < 1 ? round(N/center)/N : round(2*N/center)/N/2 | ||
| 44 | |||
| 45 | Note: |z/c - 1| < 1/N for the chosen c, |log(c) - logc - logctail| < 0x1p-97, | ||
| 46 | the last few bits of logc are rounded away so k*ln2hi + logc has no rounding | ||
| 47 | error and the interval for z is selected such that near x == 1, where log(x) | ||
| 48 | is tiny, large cancellation error is avoided in logc + poly(z/c - 1). */ | ||
| 49 | .tab = { | ||
| 50 | #define A(a, b, c) {a, 0, b, c}, | ||
| 51 | A(0x1.6a00000000000p+0, -0x1.62c82f2b9c800p-2, 0x1.ab42428375680p-48) | ||
| 52 | A(0x1.6800000000000p+0, -0x1.5d1bdbf580800p-2, -0x1.ca508d8e0f720p-46) | ||
| 53 | A(0x1.6600000000000p+0, -0x1.5767717455800p-2, -0x1.362a4d5b6506dp-45) | ||
| 54 | A(0x1.6400000000000p+0, -0x1.51aad872df800p-2, -0x1.684e49eb067d5p-49) | ||
| 55 | A(0x1.6200000000000p+0, -0x1.4be5f95777800p-2, -0x1.41b6993293ee0p-47) | ||
| 56 | A(0x1.6000000000000p+0, -0x1.4618bc21c6000p-2, 0x1.3d82f484c84ccp-46) | ||
| 57 | A(0x1.5e00000000000p+0, -0x1.404308686a800p-2, 0x1.c42f3ed820b3ap-50) | ||
| 58 | A(0x1.5c00000000000p+0, -0x1.3a64c55694800p-2, 0x1.0b1c686519460p-45) | ||
| 59 | A(0x1.5a00000000000p+0, -0x1.347dd9a988000p-2, 0x1.5594dd4c58092p-45) | ||
| 60 | A(0x1.5800000000000p+0, -0x1.2e8e2bae12000p-2, 0x1.67b1e99b72bd8p-45) | ||
| 61 | A(0x1.5600000000000p+0, -0x1.2895a13de8800p-2, 0x1.5ca14b6cfb03fp-46) | ||
| 62 | A(0x1.5600000000000p+0, -0x1.2895a13de8800p-2, 0x1.5ca14b6cfb03fp-46) | ||
| 63 | A(0x1.5400000000000p+0, -0x1.22941fbcf7800p-2, -0x1.65a242853da76p-46) | ||
| 64 | A(0x1.5200000000000p+0, -0x1.1c898c1699800p-2, -0x1.fafbc68e75404p-46) | ||
| 65 | A(0x1.5000000000000p+0, -0x1.1675cababa800p-2, 0x1.f1fc63382a8f0p-46) | ||
| 66 | A(0x1.4e00000000000p+0, -0x1.1058bf9ae4800p-2, -0x1.6a8c4fd055a66p-45) | ||
| 67 | A(0x1.4c00000000000p+0, -0x1.0a324e2739000p-2, -0x1.c6bee7ef4030ep-47) | ||
| 68 | A(0x1.4a00000000000p+0, -0x1.0402594b4d000p-2, -0x1.036b89ef42d7fp-48) | ||
| 69 | A(0x1.4a00000000000p+0, -0x1.0402594b4d000p-2, -0x1.036b89ef42d7fp-48) | ||
| 70 | A(0x1.4800000000000p+0, -0x1.fb9186d5e4000p-3, 0x1.d572aab993c87p-47) | ||
| 71 | A(0x1.4600000000000p+0, -0x1.ef0adcbdc6000p-3, 0x1.b26b79c86af24p-45) | ||
| 72 | A(0x1.4400000000000p+0, -0x1.e27076e2af000p-3, -0x1.72f4f543fff10p-46) | ||
| 73 | A(0x1.4200000000000p+0, -0x1.d5c216b4fc000p-3, 0x1.1ba91bbca681bp-45) | ||
| 74 | A(0x1.4000000000000p+0, -0x1.c8ff7c79aa000p-3, 0x1.7794f689f8434p-45) | ||
| 75 | A(0x1.4000000000000p+0, -0x1.c8ff7c79aa000p-3, 0x1.7794f689f8434p-45) | ||
| 76 | A(0x1.3e00000000000p+0, -0x1.bc286742d9000p-3, 0x1.94eb0318bb78fp-46) | ||
| 77 | A(0x1.3c00000000000p+0, -0x1.af3c94e80c000p-3, 0x1.a4e633fcd9066p-52) | ||
| 78 | A(0x1.3a00000000000p+0, -0x1.a23bc1fe2b000p-3, -0x1.58c64dc46c1eap-45) | ||
| 79 | A(0x1.3a00000000000p+0, -0x1.a23bc1fe2b000p-3, -0x1.58c64dc46c1eap-45) | ||
| 80 | A(0x1.3800000000000p+0, -0x1.9525a9cf45000p-3, -0x1.ad1d904c1d4e3p-45) | ||
| 81 | A(0x1.3600000000000p+0, -0x1.87fa06520d000p-3, 0x1.bbdbf7fdbfa09p-45) | ||
| 82 | A(0x1.3400000000000p+0, -0x1.7ab890210e000p-3, 0x1.bdb9072534a58p-45) | ||
| 83 | A(0x1.3400000000000p+0, -0x1.7ab890210e000p-3, 0x1.bdb9072534a58p-45) | ||
| 84 | A(0x1.3200000000000p+0, -0x1.6d60fe719d000p-3, -0x1.0e46aa3b2e266p-46) | ||
| 85 | A(0x1.3000000000000p+0, -0x1.5ff3070a79000p-3, -0x1.e9e439f105039p-46) | ||
| 86 | A(0x1.3000000000000p+0, -0x1.5ff3070a79000p-3, -0x1.e9e439f105039p-46) | ||
| 87 | A(0x1.2e00000000000p+0, -0x1.526e5e3a1b000p-3, -0x1.0de8b90075b8fp-45) | ||
| 88 | A(0x1.2c00000000000p+0, -0x1.44d2b6ccb8000p-3, 0x1.70cc16135783cp-46) | ||
| 89 | A(0x1.2c00000000000p+0, -0x1.44d2b6ccb8000p-3, 0x1.70cc16135783cp-46) | ||
| 90 | A(0x1.2a00000000000p+0, -0x1.371fc201e9000p-3, 0x1.178864d27543ap-48) | ||
| 91 | A(0x1.2800000000000p+0, -0x1.29552f81ff000p-3, -0x1.48d301771c408p-45) | ||
| 92 | A(0x1.2600000000000p+0, -0x1.1b72ad52f6000p-3, -0x1.e80a41811a396p-45) | ||
| 93 | A(0x1.2600000000000p+0, -0x1.1b72ad52f6000p-3, -0x1.e80a41811a396p-45) | ||
| 94 | A(0x1.2400000000000p+0, -0x1.0d77e7cd09000p-3, 0x1.a699688e85bf4p-47) | ||
| 95 | A(0x1.2400000000000p+0, -0x1.0d77e7cd09000p-3, 0x1.a699688e85bf4p-47) | ||
| 96 | A(0x1.2200000000000p+0, -0x1.fec9131dbe000p-4, -0x1.575545ca333f2p-45) | ||
| 97 | A(0x1.2000000000000p+0, -0x1.e27076e2b0000p-4, 0x1.a342c2af0003cp-45) | ||
| 98 | A(0x1.2000000000000p+0, -0x1.e27076e2b0000p-4, 0x1.a342c2af0003cp-45) | ||
| 99 | A(0x1.1e00000000000p+0, -0x1.c5e548f5bc000p-4, -0x1.d0c57585fbe06p-46) | ||
| 100 | A(0x1.1c00000000000p+0, -0x1.a926d3a4ae000p-4, 0x1.53935e85baac8p-45) | ||
| 101 | A(0x1.1c00000000000p+0, -0x1.a926d3a4ae000p-4, 0x1.53935e85baac8p-45) | ||
| 102 | A(0x1.1a00000000000p+0, -0x1.8c345d631a000p-4, 0x1.37c294d2f5668p-46) | ||
| 103 | A(0x1.1a00000000000p+0, -0x1.8c345d631a000p-4, 0x1.37c294d2f5668p-46) | ||
| 104 | A(0x1.1800000000000p+0, -0x1.6f0d28ae56000p-4, -0x1.69737c93373dap-45) | ||
| 105 | A(0x1.1600000000000p+0, -0x1.51b073f062000p-4, 0x1.f025b61c65e57p-46) | ||
| 106 | A(0x1.1600000000000p+0, -0x1.51b073f062000p-4, 0x1.f025b61c65e57p-46) | ||
| 107 | A(0x1.1400000000000p+0, -0x1.341d7961be000p-4, 0x1.c5edaccf913dfp-45) | ||
| 108 | A(0x1.1400000000000p+0, -0x1.341d7961be000p-4, 0x1.c5edaccf913dfp-45) | ||
| 109 | A(0x1.1200000000000p+0, -0x1.16536eea38000p-4, 0x1.47c5e768fa309p-46) | ||
| 110 | A(0x1.1000000000000p+0, -0x1.f0a30c0118000p-5, 0x1.d599e83368e91p-45) | ||
| 111 | A(0x1.1000000000000p+0, -0x1.f0a30c0118000p-5, 0x1.d599e83368e91p-45) | ||
| 112 | A(0x1.0e00000000000p+0, -0x1.b42dd71198000p-5, 0x1.c827ae5d6704cp-46) | ||
| 113 | A(0x1.0e00000000000p+0, -0x1.b42dd71198000p-5, 0x1.c827ae5d6704cp-46) | ||
| 114 | A(0x1.0c00000000000p+0, -0x1.77458f632c000p-5, -0x1.cfc4634f2a1eep-45) | ||
| 115 | A(0x1.0c00000000000p+0, -0x1.77458f632c000p-5, -0x1.cfc4634f2a1eep-45) | ||
| 116 | A(0x1.0a00000000000p+0, -0x1.39e87b9fec000p-5, 0x1.502b7f526feaap-48) | ||
| 117 | A(0x1.0a00000000000p+0, -0x1.39e87b9fec000p-5, 0x1.502b7f526feaap-48) | ||
| 118 | A(0x1.0800000000000p+0, -0x1.f829b0e780000p-6, -0x1.980267c7e09e4p-45) | ||
| 119 | A(0x1.0800000000000p+0, -0x1.f829b0e780000p-6, -0x1.980267c7e09e4p-45) | ||
| 120 | A(0x1.0600000000000p+0, -0x1.7b91b07d58000p-6, -0x1.88d5493faa639p-45) | ||
| 121 | A(0x1.0400000000000p+0, -0x1.fc0a8b0fc0000p-7, -0x1.f1e7cf6d3a69cp-50) | ||
| 122 | A(0x1.0400000000000p+0, -0x1.fc0a8b0fc0000p-7, -0x1.f1e7cf6d3a69cp-50) | ||
| 123 | A(0x1.0200000000000p+0, -0x1.fe02a6b100000p-8, -0x1.9e23f0dda40e4p-46) | ||
| 124 | A(0x1.0200000000000p+0, -0x1.fe02a6b100000p-8, -0x1.9e23f0dda40e4p-46) | ||
| 125 | A(0x1.0000000000000p+0, 0x0.0000000000000p+0, 0x0.0000000000000p+0) | ||
| 126 | A(0x1.0000000000000p+0, 0x0.0000000000000p+0, 0x0.0000000000000p+0) | ||
| 127 | A(0x1.fc00000000000p-1, 0x1.0101575890000p-7, -0x1.0c76b999d2be8p-46) | ||
| 128 | A(0x1.f800000000000p-1, 0x1.0205658938000p-6, -0x1.3dc5b06e2f7d2p-45) | ||
| 129 | A(0x1.f400000000000p-1, 0x1.8492528c90000p-6, -0x1.aa0ba325a0c34p-45) | ||
| 130 | A(0x1.f000000000000p-1, 0x1.0415d89e74000p-5, 0x1.111c05cf1d753p-47) | ||
| 131 | A(0x1.ec00000000000p-1, 0x1.466aed42e0000p-5, -0x1.c167375bdfd28p-45) | ||
| 132 | A(0x1.e800000000000p-1, 0x1.894aa149fc000p-5, -0x1.97995d05a267dp-46) | ||
| 133 | A(0x1.e400000000000p-1, 0x1.ccb73cdddc000p-5, -0x1.a68f247d82807p-46) | ||
| 134 | A(0x1.e200000000000p-1, 0x1.eea31c006c000p-5, -0x1.e113e4fc93b7bp-47) | ||
| 135 | A(0x1.de00000000000p-1, 0x1.1973bd1466000p-4, -0x1.5325d560d9e9bp-45) | ||
| 136 | A(0x1.da00000000000p-1, 0x1.3bdf5a7d1e000p-4, 0x1.cc85ea5db4ed7p-45) | ||
| 137 | A(0x1.d600000000000p-1, 0x1.5e95a4d97a000p-4, -0x1.c69063c5d1d1ep-45) | ||
| 138 | A(0x1.d400000000000p-1, 0x1.700d30aeac000p-4, 0x1.c1e8da99ded32p-49) | ||
| 139 | A(0x1.d000000000000p-1, 0x1.9335e5d594000p-4, 0x1.3115c3abd47dap-45) | ||
| 140 | A(0x1.cc00000000000p-1, 0x1.b6ac88dad6000p-4, -0x1.390802bf768e5p-46) | ||
| 141 | A(0x1.ca00000000000p-1, 0x1.c885801bc4000p-4, 0x1.646d1c65aacd3p-45) | ||
| 142 | A(0x1.c600000000000p-1, 0x1.ec739830a2000p-4, -0x1.dc068afe645e0p-45) | ||
| 143 | A(0x1.c400000000000p-1, 0x1.fe89139dbe000p-4, -0x1.534d64fa10afdp-45) | ||
| 144 | A(0x1.c000000000000p-1, 0x1.1178e8227e000p-3, 0x1.1ef78ce2d07f2p-45) | ||
| 145 | A(0x1.be00000000000p-1, 0x1.1aa2b7e23f000p-3, 0x1.ca78e44389934p-45) | ||
| 146 | A(0x1.ba00000000000p-1, 0x1.2d1610c868000p-3, 0x1.39d6ccb81b4a1p-47) | ||
| 147 | A(0x1.b800000000000p-1, 0x1.365fcb0159000p-3, 0x1.62fa8234b7289p-51) | ||
| 148 | A(0x1.b400000000000p-1, 0x1.4913d8333b000p-3, 0x1.5837954fdb678p-45) | ||
| 149 | A(0x1.b200000000000p-1, 0x1.527e5e4a1b000p-3, 0x1.633e8e5697dc7p-45) | ||
| 150 | A(0x1.ae00000000000p-1, 0x1.6574ebe8c1000p-3, 0x1.9cf8b2c3c2e78p-46) | ||
| 151 | A(0x1.ac00000000000p-1, 0x1.6f0128b757000p-3, -0x1.5118de59c21e1p-45) | ||
| 152 | A(0x1.aa00000000000p-1, 0x1.7898d85445000p-3, -0x1.c661070914305p-46) | ||
| 153 | A(0x1.a600000000000p-1, 0x1.8beafeb390000p-3, -0x1.73d54aae92cd1p-47) | ||
| 154 | A(0x1.a400000000000p-1, 0x1.95a5adcf70000p-3, 0x1.7f22858a0ff6fp-47) | ||
| 155 | A(0x1.a000000000000p-1, 0x1.a93ed3c8ae000p-3, -0x1.8724350562169p-45) | ||
| 156 | A(0x1.9e00000000000p-1, 0x1.b31d8575bd000p-3, -0x1.c358d4eace1aap-47) | ||
| 157 | A(0x1.9c00000000000p-1, 0x1.bd087383be000p-3, -0x1.d4bc4595412b6p-45) | ||
| 158 | A(0x1.9a00000000000p-1, 0x1.c6ffbc6f01000p-3, -0x1.1ec72c5962bd2p-48) | ||
| 159 | A(0x1.9600000000000p-1, 0x1.db13db0d49000p-3, -0x1.aff2af715b035p-45) | ||
| 160 | A(0x1.9400000000000p-1, 0x1.e530effe71000p-3, 0x1.212276041f430p-51) | ||
| 161 | A(0x1.9200000000000p-1, 0x1.ef5ade4dd0000p-3, -0x1.a211565bb8e11p-51) | ||
| 162 | A(0x1.9000000000000p-1, 0x1.f991c6cb3b000p-3, 0x1.bcbecca0cdf30p-46) | ||
| 163 | A(0x1.8c00000000000p-1, 0x1.07138604d5800p-2, 0x1.89cdb16ed4e91p-48) | ||
| 164 | A(0x1.8a00000000000p-1, 0x1.0c42d67616000p-2, 0x1.7188b163ceae9p-45) | ||
| 165 | A(0x1.8800000000000p-1, 0x1.1178e8227e800p-2, -0x1.c210e63a5f01cp-45) | ||
| 166 | A(0x1.8600000000000p-1, 0x1.16b5ccbacf800p-2, 0x1.b9acdf7a51681p-45) | ||
| 167 | A(0x1.8400000000000p-1, 0x1.1bf99635a6800p-2, 0x1.ca6ed5147bdb7p-45) | ||
| 168 | A(0x1.8200000000000p-1, 0x1.214456d0eb800p-2, 0x1.a87deba46baeap-47) | ||
| 169 | A(0x1.7e00000000000p-1, 0x1.2bef07cdc9000p-2, 0x1.a9cfa4a5004f4p-45) | ||
| 170 | A(0x1.7c00000000000p-1, 0x1.314f1e1d36000p-2, -0x1.8e27ad3213cb8p-45) | ||
| 171 | A(0x1.7a00000000000p-1, 0x1.36b6776be1000p-2, 0x1.16ecdb0f177c8p-46) | ||
| 172 | A(0x1.7800000000000p-1, 0x1.3c25277333000p-2, 0x1.83b54b606bd5cp-46) | ||
| 173 | A(0x1.7600000000000p-1, 0x1.419b423d5e800p-2, 0x1.8e436ec90e09dp-47) | ||
| 174 | A(0x1.7400000000000p-1, 0x1.4718dc271c800p-2, -0x1.f27ce0967d675p-45) | ||
| 175 | A(0x1.7200000000000p-1, 0x1.4c9e09e173000p-2, -0x1.e20891b0ad8a4p-45) | ||
| 176 | A(0x1.7000000000000p-1, 0x1.522ae0738a000p-2, 0x1.ebe708164c759p-45) | ||
| 177 | A(0x1.6e00000000000p-1, 0x1.57bf753c8d000p-2, 0x1.fadedee5d40efp-46) | ||
| 178 | A(0x1.6c00000000000p-1, 0x1.5d5bddf596000p-2, -0x1.a0b2a08a465dcp-47) | ||
| 179 | }, | ||
| 180 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/pow_data.h created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _POW_DATA_H | ||
| 6 | #define _POW_DATA_H | ||
| 7 | |||
| 8 | #include <features.h> | ||
| 9 | |||
| 10 | #define POW_LOG_TABLE_BITS 7 | ||
| 11 | #define POW_LOG_POLY_ORDER 8 | ||
| 12 | extern hidden const struct pow_log_data { | ||
| 13 | 	double ln2hi; | ||
| 14 | 	double ln2lo; | ||
| 15 | 	double poly[POW_LOG_POLY_ORDER - 1]; /* First coefficient is 1. */ | ||
| 16 | 	/* Note: the pad field is unused, but allows slightly faster indexing. */ | ||
| 17 | 	struct { | ||
| 18 | 		double invc, pad, logc, logctail; | ||
| 19 | 	} tab[1 << POW_LOG_TABLE_BITS]; | ||
| 20 | } __pow_log_data; | ||
| 21 | |||
| 22 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabs.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM) | ||
| 4 | |||
| 5 | #include "../fabs.c" | ||
| 6 | |||
| 7 | #else | ||
| 8 | |||
| 9 | double fabs(double x) | ||
| 10 | { | ||
| 11 | 	__asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); | ||
| 12 | 	return x; | ||
| 13 | } | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabsf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _SOFT_FLOAT | ||
| 4 | |||
| 5 | #include "../fabsf.c" | ||
| 6 | |||
| 7 | #else | ||
| 8 | |||
| 9 | float fabsf(float x) | ||
| 10 | { | ||
| 11 | 	__asm__ ("fabs %0, %1" : "=f"(x) : "f"(x)); | ||
| 12 | 	return x; | ||
| 13 | } | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fma.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM) | ||
| 4 | |||
| 5 | #include "../fma.c" | ||
| 6 | |||
| 7 | #else | ||
| 8 | |||
| 9 | double fma(double x, double y, double z) | ||
| 10 | { | ||
| 11 | 	__asm__("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z)); | ||
| 12 | 	return x; | ||
| 13 | } | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fmaf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _SOFT_FLOAT | ||
| 4 | |||
| 5 | #include "../fmaf.c" | ||
| 6 | |||
| 7 | #else | ||
| 8 | |||
| 9 | float fmaf(float x, float y, float z) | ||
| 10 | { | ||
| 11 | 	__asm__("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z)); | ||
| 12 | 	return x; | ||
| 13 | } | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/sqrt.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if !defined _SOFT_FLOAT && defined _ARCH_PPCSQ | ||
| 4 | |||
| 5 | double sqrt(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsqrt %0, %1\n" : "=d" (x) : "d" (x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrt.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/sqrtf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if !defined _SOFT_FLOAT && defined _ARCH_PPCSQ | ||
| 4 | |||
| 5 | float sqrtf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsqrts %0, %1\n" : "=f" (x) : "f" (x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrtf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/ceil.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | double ceil(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("frip %0, %1" : "=d"(x) : "d"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../ceil.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/ceilf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | float ceilf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("frip %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../ceilf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fabs.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fabs(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs %0, %1" : "=d"(x) : "d"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fabsf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fabsf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs %0, %1" : "=f"(x) : "f"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/floor.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | double floor(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("frim %0, %1" : "=d"(x) : "d"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../floor.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/floorf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | float floorf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("frim %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../floorf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fma.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fma(double x, double y, double z) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fmadd %0, %1, %2, %3" : "=d"(x) : "d"(x), "d"(y), "d"(z)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmaf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fmaf(float x, float y, float z) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fmadds %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmax.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef __VSX__ | ||
| 4 | |||
| 5 | double fmax(double x, double y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("xsmaxdp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmax.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmaxf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef __VSX__ | ||
| 4 | |||
| 5 | float fmaxf(float x, float y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("xsmaxdp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmaxf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fmin.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef __VSX__ | ||
| 4 | |||
| 5 | double fmin(double x, double y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("xsmindp %x0, %x1, %x2" : "=ws"(x) : "ws"(x), "ws"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmin.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/fminf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef __VSX__ | ||
| 4 | |||
| 5 | float fminf(float x, float y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("xsmindp %x0, %x1, %x2" : "=ww"(x) : "ww"(x), "ww"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fminf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lrint.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | long lrint(double x) | ||
| 6 | { | ||
| 7 | 	long n; | ||
| 8 | 	__asm__ ("fctid %0, %1" : "=d"(n) : "d"(x)); | ||
| 9 | 	return n; | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include "../lrint.c" | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lrintf.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | long lrintf(float x) | ||
| 6 | { | ||
| 7 | 	long n; | ||
| 8 | 	__asm__ ("fctid %0, %1" : "=d"(n) : "f"(x)); | ||
| 9 | 	return n; | ||
| 10 | } | ||
| 11 | |||
| 12 | #else | ||
| 13 | |||
| 14 | #include "../lrintf.c" | ||
| 15 | |||
| 16 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lround.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef __VSX__ | ||
| 4 | |||
| 5 | long lround(double x) | ||
| 6 | { | ||
| 7 | 	long n; | ||
| 8 | 	__asm__ ( | ||
| 9 | 		"xsrdpi %1, %1\n" | ||
| 10 | 		"fctid %0, %1\n" : "=d"(n), "+d"(x)); | ||
| 11 | 	return n; | ||
| 12 | } | ||
| 13 | |||
| 14 | #else | ||
| 15 | |||
| 16 | #include "../lround.c" | ||
| 17 | |||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/lroundf.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef __VSX__ | ||
| 4 | |||
| 5 | long lroundf(float x) | ||
| 6 | { | ||
| 7 | 	long n; | ||
| 8 | 	__asm__ ( | ||
| 9 | 		"xsrdpi %1, %1\n" | ||
| 10 | 		"fctid %0, %1\n" : "=d"(n), "+f"(x)); | ||
| 11 | 	return n; | ||
| 12 | } | ||
| 13 | |||
| 14 | #else | ||
| 15 | |||
| 16 | #include "../lroundf.c" | ||
| 17 | |||
| 18 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/round.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | double round(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("frin %0, %1" : "=d"(x) : "d"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../round.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/roundf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | float roundf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("frin %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../roundf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/sqrt.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double sqrt(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fsqrt %0, %1" : "=d"(x) : "d"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/sqrtf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float sqrtf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fsqrts %0, %1" : "=f"(x) : "f"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/trunc.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | double trunc(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("friz %0, %1" : "=d"(x) : "d"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../trunc.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powerpc64/truncf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #ifdef _ARCH_PWR5X | ||
| 4 | |||
| 5 | float truncf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("friz %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../truncf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powf.c created+185| ... | @@ -0,0 +1,185 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include <math.h> | ||
| 7 | #include <stdint.h> | ||
| 8 | #include "libm.h" | ||
| 9 | #include "exp2f_data.h" | ||
| 10 | #include "powf_data.h" | ||
| 11 | |||
| 12 | /* | ||
| 13 | POWF_LOG2_POLY_ORDER = 5 | ||
| 14 | EXP2F_TABLE_BITS = 5 | ||
| 15 | |||
| 16 | ULP error: 0.82 (~ 0.5 + relerr*2^24) | ||
| 17 | relerr: 1.27 * 2^-26 (Relative error ~= 128*Ln2*relerr_log2 + relerr_exp2) | ||
| 18 | relerr_log2: 1.83 * 2^-33 (Relative error of logx.) | ||
| 19 | relerr_exp2: 1.69 * 2^-34 (Relative error of exp2(ylogx).) | ||
| 20 | */ | ||
| 21 | |||
| 22 | #define N (1 << POWF_LOG2_TABLE_BITS) | ||
| 23 | #define T __powf_log2_data.tab | ||
| 24 | #define A __powf_log2_data.poly | ||
| 25 | #define OFF 0x3f330000 | ||
| 26 | |||
| 27 | /* Subnormal input is normalized so ix has negative biased exponent. | ||
| 28 | Output is multiplied by N (POWF_SCALE) if TOINT_INTRINICS is set. */ | ||
| 29 | static inline double_t log2_inline(uint32_t ix) | ||
| 30 | { | ||
| 31 | 	double_t z, r, r2, r4, p, q, y, y0, invc, logc; | ||
| 32 | 	uint32_t iz, top, tmp; | ||
| 33 | 	int k, i; | ||
| 34 | |||
| 35 | 	/* x = 2^k z; where z is in range [OFF,2*OFF] and exact. | ||
| 36 | 	 The range is split into N subintervals. | ||
| 37 | 	 The ith subinterval contains z and c is near its center. */ | ||
| 38 | 	tmp = ix - OFF; | ||
| 39 | 	i = (tmp >> (23 - POWF_LOG2_TABLE_BITS)) % N; | ||
| 40 | 	top = tmp & 0xff800000; | ||
| 41 | 	iz = ix - top; | ||
| 42 | 	k = (int32_t)top >> (23 - POWF_SCALE_BITS); /* arithmetic shift */ | ||
| 43 | 	invc = T[i].invc; | ||
| 44 | 	logc = T[i].logc; | ||
| 45 | 	z = (double_t)asfloat(iz); | ||
| 46 | |||
| 47 | 	/* log2(x) = log1p(z/c-1)/ln2 + log2(c) + k */ | ||
| 48 | 	r = z * invc - 1; | ||
| 49 | 	y0 = logc + (double_t)k; | ||
| 50 | |||
| 51 | 	/* Pipelined polynomial evaluation to approximate log1p(r)/ln2. */ | ||
| 52 | 	r2 = r * r; | ||
| 53 | 	y = A[0] * r + A[1]; | ||
| 54 | 	p = A[2] * r + A[3]; | ||
| 55 | 	r4 = r2 * r2; | ||
| 56 | 	q = A[4] * r + y0; | ||
| 57 | 	q = p * r2 + q; | ||
| 58 | 	y = y * r4 + q; | ||
| 59 | 	return y; | ||
| 60 | } | ||
| 61 | |||
| 62 | #undef N | ||
| 63 | #undef T | ||
| 64 | #define N (1 << EXP2F_TABLE_BITS) | ||
| 65 | #define T __exp2f_data.tab | ||
| 66 | #define SIGN_BIAS (1 << (EXP2F_TABLE_BITS + 11)) | ||
| 67 | |||
| 68 | /* The output of log2 and thus the input of exp2 is either scaled by N | ||
| 69 | (in case of fast toint intrinsics) or not. The unscaled xd must be | ||
| 70 | in [-1021,1023], sign_bias sets the sign of the result. */ | ||
| 71 | static inline float exp2_inline(double_t xd, uint32_t sign_bias) | ||
| 72 | { | ||
| 73 | 	uint64_t ki, ski, t; | ||
| 74 | 	double_t kd, z, r, r2, y, s; | ||
| 75 | |||
| 76 | #if TOINT_INTRINSICS | ||
| 77 | #define C __exp2f_data.poly_scaled | ||
| 78 | 	/* N*x = k + r with r in [-1/2, 1/2] */ | ||
| 79 | 	kd = roundtoint(xd); /* k */ | ||
| 80 | 	ki = converttoint(xd); | ||
| 81 | #else | ||
| 82 | #define C __exp2f_data.poly | ||
| 83 | #define SHIFT __exp2f_data.shift_scaled | ||
| 84 | 	/* x = k/N + r with r in [-1/(2N), 1/(2N)] */ | ||
| 85 | 	kd = eval_as_double(xd + SHIFT); | ||
| 86 | 	ki = asuint64(kd); | ||
| 87 | 	kd -= SHIFT; /* k/N */ | ||
| 88 | #endif | ||
| 89 | 	r = xd - kd; | ||
| 90 | |||
| 91 | 	/* exp2(x) = 2^(k/N) * 2^r ~= s * (C0*r^3 + C1*r^2 + C2*r + 1) */ | ||
| 92 | 	t = T[ki % N]; | ||
| 93 | 	ski = ki + sign_bias; | ||
| 94 | 	t += ski << (52 - EXP2F_TABLE_BITS); | ||
| 95 | 	s = asdouble(t); | ||
| 96 | 	z = C[0] * r + C[1]; | ||
| 97 | 	r2 = r * r; | ||
| 98 | 	y = C[2] * r + 1; | ||
| 99 | 	y = z * r2 + y; | ||
| 100 | 	y = y * s; | ||
| 101 | 	return eval_as_float(y); | ||
| 102 | } | ||
| 103 | |||
| 104 | /* Returns 0 if not int, 1 if odd int, 2 if even int. The argument is | ||
| 105 | the bit representation of a non-zero finite floating-point value. */ | ||
| 106 | static inline int checkint(uint32_t iy) | ||
| 107 | { | ||
| 108 | 	int e = iy >> 23 & 0xff; | ||
| 109 | 	if (e < 0x7f) | ||
| 110 | 		return 0; | ||
| 111 | 	if (e > 0x7f + 23) | ||
| 112 | 		return 2; | ||
| 113 | 	if (iy & ((1 << (0x7f + 23 - e)) - 1)) | ||
| 114 | 		return 0; | ||
| 115 | 	if (iy & (1 << (0x7f + 23 - e))) | ||
| 116 | 		return 1; | ||
| 117 | 	return 2; | ||
| 118 | } | ||
| 119 | |||
| 120 | static inline int zeroinfnan(uint32_t ix) | ||
| 121 | { | ||
| 122 | 	return 2 * ix - 1 >= 2u * 0x7f800000 - 1; | ||
| 123 | } | ||
| 124 | |||
| 125 | float powf(float x, float y) | ||
| 126 | { | ||
| 127 | 	uint32_t sign_bias = 0; | ||
| 128 | 	uint32_t ix, iy; | ||
| 129 | |||
| 130 | 	ix = asuint(x); | ||
| 131 | 	iy = asuint(y); | ||
| 132 | 	if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000 || | ||
| 133 | 			 zeroinfnan(iy))) { | ||
| 134 | 		/* Either (x < 0x1p-126 or inf or nan) or (y is 0 or inf or nan). */ | ||
| 135 | 		if (predict_false(zeroinfnan(iy))) { | ||
| 136 | 			if (2 * iy == 0) | ||
| 137 | 				return issignalingf_inline(x) ? x + y : 1.0f; | ||
| 138 | 			if (ix == 0x3f800000) | ||
| 139 | 				return issignalingf_inline(y) ? x + y : 1.0f; | ||
| 140 | 			if (2 * ix > 2u * 0x7f800000 || | ||
| 141 | 			 2 * iy > 2u * 0x7f800000) | ||
| 142 | 				return x + y; | ||
| 143 | 			if (2 * ix == 2 * 0x3f800000) | ||
| 144 | 				return 1.0f; | ||
| 145 | 			if ((2 * ix < 2 * 0x3f800000) == !(iy & 0x80000000)) | ||
| 146 | 				return 0.0f; /* |x|<1 && y==inf or |x|>1 && y==-inf. */ | ||
| 147 | 			return y * y; | ||
| 148 | 		} | ||
| 149 | 		if (predict_false(zeroinfnan(ix))) { | ||
| 150 | 			float_t x2 = x * x; | ||
| 151 | 			if (ix & 0x80000000 && checkint(iy) == 1) | ||
| 152 | 				x2 = -x2; | ||
| 153 | 			/* Without the barrier some versions of clang hoist the 1/x2 and | ||
| 154 | 			 thus division by zero exception can be signaled spuriously. */ | ||
| 155 | 			return iy & 0x80000000 ? fp_barrierf(1 / x2) : x2; | ||
| 156 | 		} | ||
| 157 | 		/* x and y are non-zero finite. */ | ||
| 158 | 		if (ix & 0x80000000) { | ||
| 159 | 			/* Finite x < 0. */ | ||
| 160 | 			int yint = checkint(iy); | ||
| 161 | 			if (yint == 0) | ||
| 162 | 				return __math_invalidf(x); | ||
| 163 | 			if (yint == 1) | ||
| 164 | 				sign_bias = SIGN_BIAS; | ||
| 165 | 			ix &= 0x7fffffff; | ||
| 166 | 		} | ||
| 167 | 		if (ix < 0x00800000) { | ||
| 168 | 			/* Normalize subnormal x so exponent becomes negative. */ | ||
| 169 | 			ix = asuint(x * 0x1p23f); | ||
| 170 | 			ix &= 0x7fffffff; | ||
| 171 | 			ix -= 23 << 23; | ||
| 172 | 		} | ||
| 173 | 	} | ||
| 174 | 	double_t logx = log2_inline(ix); | ||
| 175 | 	double_t ylogx = y * logx; /* cannot overflow, y is single prec. */ | ||
| 176 | 	if (predict_false((asuint64(ylogx) >> 47 & 0xffff) >= | ||
| 177 | 			 asuint64(126.0 * POWF_SCALE) >> 47)) { | ||
| 178 | 		/* |y*log(x)| >= 126. */ | ||
| 179 | 		if (ylogx > 0x1.fffffffd1d571p+6 * POWF_SCALE) | ||
| 180 | 			return __math_oflowf(sign_bias); | ||
| 181 | 		if (ylogx <= -150.0 * POWF_SCALE) | ||
| 182 | 			return __math_uflowf(sign_bias); | ||
| 183 | 	} | ||
| 184 | 	return exp2_inline(ylogx, sign_bias); | ||
| 185 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/powf_data.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | /* | ||
| 2 | * Data definition for powf. | ||
| 3 | * | ||
| 4 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | #include "powf_data.h" | ||
| 9 | |||
| 10 | const struct powf_log2_data __powf_log2_data = { | ||
| 11 | .tab = { | ||
| 12 | { 0x1.661ec79f8f3bep+0, -0x1.efec65b963019p-2 * POWF_SCALE }, | ||
| 13 | { 0x1.571ed4aaf883dp+0, -0x1.b0b6832d4fca4p-2 * POWF_SCALE }, | ||
| 14 | { 0x1.49539f0f010bp+0, -0x1.7418b0a1fb77bp-2 * POWF_SCALE }, | ||
| 15 | { 0x1.3c995b0b80385p+0, -0x1.39de91a6dcf7bp-2 * POWF_SCALE }, | ||
| 16 | { 0x1.30d190c8864a5p+0, -0x1.01d9bf3f2b631p-2 * POWF_SCALE }, | ||
| 17 | { 0x1.25e227b0b8eap+0, -0x1.97c1d1b3b7afp-3 * POWF_SCALE }, | ||
| 18 | { 0x1.1bb4a4a1a343fp+0, -0x1.2f9e393af3c9fp-3 * POWF_SCALE }, | ||
| 19 | { 0x1.12358f08ae5bap+0, -0x1.960cbbf788d5cp-4 * POWF_SCALE }, | ||
| 20 | { 0x1.0953f419900a7p+0, -0x1.a6f9db6475fcep-5 * POWF_SCALE }, | ||
| 21 | { 0x1p+0, 0x0p+0 * POWF_SCALE }, | ||
| 22 | { 0x1.e608cfd9a47acp-1, 0x1.338ca9f24f53dp-4 * POWF_SCALE }, | ||
| 23 | { 0x1.ca4b31f026aap-1, 0x1.476a9543891bap-3 * POWF_SCALE }, | ||
| 24 | { 0x1.b2036576afce6p-1, 0x1.e840b4ac4e4d2p-3 * POWF_SCALE }, | ||
| 25 | { 0x1.9c2d163a1aa2dp-1, 0x1.40645f0c6651cp-2 * POWF_SCALE }, | ||
| 26 | { 0x1.886e6037841edp-1, 0x1.88e9c2c1b9ff8p-2 * POWF_SCALE }, | ||
| 27 | { 0x1.767dcf5534862p-1, 0x1.ce0a44eb17bccp-2 * POWF_SCALE }, | ||
| 28 | }, | ||
| 29 | .poly = { | ||
| 30 | 0x1.27616c9496e0bp-2 * POWF_SCALE, -0x1.71969a075c67ap-2 * POWF_SCALE, | ||
| 31 | 0x1.ec70a6ca7baddp-2 * POWF_SCALE, -0x1.7154748bef6c8p-1 * POWF_SCALE, | ||
| 32 | 0x1.71547652ab82bp0 * POWF_SCALE, | ||
| 33 | } | ||
| 34 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/powf_data.h created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (c) 2017-2018, Arm Limited. | ||
| 3 | * SPDX-License-Identifier: MIT | ||
| 4 | */ | ||
| 5 | #ifndef _POWF_DATA_H | ||
| 6 | #define _POWF_DATA_H | ||
| 7 | |||
| 8 | #include "libm.h" | ||
| 9 | #include "exp2f_data.h" | ||
| 10 | |||
| 11 | #define POWF_LOG2_TABLE_BITS 4 | ||
| 12 | #define POWF_LOG2_POLY_ORDER 5 | ||
| 13 | #if TOINT_INTRINSICS | ||
| 14 | #define POWF_SCALE_BITS EXP2F_TABLE_BITS | ||
| 15 | #else | ||
| 16 | #define POWF_SCALE_BITS 0 | ||
| 17 | #endif | ||
| 18 | #define POWF_SCALE ((double)(1 << POWF_SCALE_BITS)) | ||
| 19 | extern hidden const struct powf_log2_data { | ||
| 20 | 	struct { | ||
| 21 | 		double invc, logc; | ||
| 22 | 	} tab[1 << POWF_LOG2_TABLE_BITS]; | ||
| 23 | 	double poly[POWF_LOG2_POLY_ORDER]; | ||
| 24 | } __powf_log2_data; | ||
| 25 | |||
| 26 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/powl.c created+526| ... | @@ -0,0 +1,526 @@ | ||
| 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 (x == -1.0 && !isfinite(y)) | ||
| 220 | 		return 1.0; /* -1**inf = 1 */ | ||
| 221 | 	if (y == 0.0) | ||
| 222 | 		return 1.0; /* x**0 = 1, even if x is nan */ | ||
| 223 | 	if (y == 1.0) | ||
| 224 | 		return x; | ||
| 225 | 	if (y >= LDBL_MAX) { | ||
| 226 | 		if (x > 1.0 || x < -1.0) | ||
| 227 | 			return INFINITY; | ||
| 228 | 		if (x != 0.0) | ||
| 229 | 			return 0.0; | ||
| 230 | 	} | ||
| 231 | 	if (y <= -LDBL_MAX) { | ||
| 232 | 		if (x > 1.0 || x < -1.0) | ||
| 233 | 			return 0.0; | ||
| 234 | 		if (x != 0.0 || y == -INFINITY) | ||
| 235 | 			return INFINITY; | ||
| 236 | 	} | ||
| 237 | 	if (x >= LDBL_MAX) { | ||
| 238 | 		if (y > 0.0) | ||
| 239 | 			return INFINITY; | ||
| 240 | 		return 0.0; | ||
| 241 | 	} | ||
| 242 | |||
| 243 | 	w = floorl(y); | ||
| 244 | |||
| 245 | 	/* Set iyflg to 1 if y is an integer. */ | ||
| 246 | 	iyflg = 0; | ||
| 247 | 	if (w == y) | ||
| 248 | 		iyflg = 1; | ||
| 249 | |||
| 250 | 	/* Test for odd integer y. */ | ||
| 251 | 	yoddint = 0; | ||
| 252 | 	if (iyflg) { | ||
| 253 | 		ya = fabsl(y); | ||
| 254 | 		ya = floorl(0.5 * ya); | ||
| 255 | 		yb = 0.5 * fabsl(w); | ||
| 256 | 		if( ya != yb ) | ||
| 257 | 			yoddint = 1; | ||
| 258 | 	} | ||
| 259 | |||
| 260 | 	if (x <= -LDBL_MAX) { | ||
| 261 | 		if (y > 0.0) { | ||
| 262 | 			if (yoddint) | ||
| 263 | 				return -INFINITY; | ||
| 264 | 			return INFINITY; | ||
| 265 | 		} | ||
| 266 | 		if (y < 0.0) { | ||
| 267 | 			if (yoddint) | ||
| 268 | 				return -0.0; | ||
| 269 | 			return 0.0; | ||
| 270 | 		} | ||
| 271 | 	} | ||
| 272 | 	nflg = 0; /* (x<0)**(odd int) */ | ||
| 273 | 	if (x <= 0.0) { | ||
| 274 | 		if (x == 0.0) { | ||
| 275 | 			if (y < 0.0) { | ||
| 276 | 				if (signbit(x) && yoddint) | ||
| 277 | 					/* (-0.0)**(-odd int) = -inf, divbyzero */ | ||
| 278 | 					return -1.0/0.0; | ||
| 279 | 				/* (+-0.0)**(negative) = inf, divbyzero */ | ||
| 280 | 				return 1.0/0.0; | ||
| 281 | 			} | ||
| 282 | 			if (signbit(x) && yoddint) | ||
| 283 | 				return -0.0; | ||
| 284 | 			return 0.0; | ||
| 285 | 		} | ||
| 286 | 		if (iyflg == 0) | ||
| 287 | 			return (x - x) / (x - x); /* (x<0)**(non-int) is NaN */ | ||
| 288 | 		/* (x<0)**(integer) */ | ||
| 289 | 		if (yoddint) | ||
| 290 | 			nflg = 1; /* negate result */ | ||
| 291 | 		x = -x; | ||
| 292 | 	} | ||
| 293 | 	/* (+integer)**(integer) */ | ||
| 294 | 	if (iyflg && floorl(x) == x && fabsl(y) < 32768.0) { | ||
| 295 | 		w = powil(x, (int)y); | ||
| 296 | 		return nflg ? -w : w; | ||
| 297 | 	} | ||
| 298 | |||
| 299 | 	/* separate significand from exponent */ | ||
| 300 | 	x = frexpl(x, &i); | ||
| 301 | 	e = i; | ||
| 302 | |||
| 303 | 	/* find significand in antilog table A[] */ | ||
| 304 | 	i = 1; | ||
| 305 | 	if (x <= A[17]) | ||
| 306 | 		i = 17; | ||
| 307 | 	if (x <= A[i+8]) | ||
| 308 | 		i += 8; | ||
| 309 | 	if (x <= A[i+4]) | ||
| 310 | 		i += 4; | ||
| 311 | 	if (x <= A[i+2]) | ||
| 312 | 		i += 2; | ||
| 313 | 	if (x >= A[1]) | ||
| 314 | 		i = -1; | ||
| 315 | 	i += 1; | ||
| 316 | |||
| 317 | 	/* Find (x - A[i])/A[i] | ||
| 318 | 	 * in order to compute log(x/A[i]): | ||
| 319 | 	 * | ||
| 320 | 	 * log(x) = log( a x/a ) = log(a) + log(x/a) | ||
| 321 | 	 * | ||
| 322 | 	 * log(x/a) = log(1+v), v = x/a - 1 = (x-a)/a | ||
| 323 | 	 */ | ||
| 324 | 	x -= A[i]; | ||
| 325 | 	x -= B[i/2]; | ||
| 326 | 	x /= A[i]; | ||
| 327 | |||
| 328 | 	/* rational approximation for log(1+v): | ||
| 329 | 	 * | ||
| 330 | 	 * log(1+v) = v - v**2/2 + v**3 P(v) / Q(v) | ||
| 331 | 	 */ | ||
| 332 | 	z = x*x; | ||
| 333 | 	w = x * (z * __polevll(x, P, 3) / __p1evll(x, Q, 3)); | ||
| 334 | 	w = w - 0.5*z; | ||
| 335 | |||
| 336 | 	/* Convert to base 2 logarithm: | ||
| 337 | 	 * multiply by log2(e) = 1 + LOG2EA | ||
| 338 | 	 */ | ||
| 339 | 	z = LOG2EA * w; | ||
| 340 | 	z += w; | ||
| 341 | 	z += LOG2EA * x; | ||
| 342 | 	z += x; | ||
| 343 | |||
| 344 | 	/* Compute exponent term of the base 2 logarithm. */ | ||
| 345 | 	w = -i; | ||
| 346 | 	w /= NXT; | ||
| 347 | 	w += e; | ||
| 348 | 	/* Now base 2 log of x is w + z. */ | ||
| 349 | |||
| 350 | 	/* Multiply base 2 log by y, in extended precision. */ | ||
| 351 | |||
| 352 | 	/* separate y into large part ya | ||
| 353 | 	 * and small part yb less than 1/NXT | ||
| 354 | 	 */ | ||
| 355 | 	ya = reducl(y); | ||
| 356 | 	yb = y - ya; | ||
| 357 | |||
| 358 | 	/* (w+z)(ya+yb) | ||
| 359 | 	 * = w*ya + w*yb + z*y | ||
| 360 | 	 */ | ||
| 361 | 	F = z * y + w * yb; | ||
| 362 | 	Fa = reducl(F); | ||
| 363 | 	Fb = F - Fa; | ||
| 364 | |||
| 365 | 	G = Fa + w * ya; | ||
| 366 | 	Ga = reducl(G); | ||
| 367 | 	Gb = G - Ga; | ||
| 368 | |||
| 369 | 	H = Fb + Gb; | ||
| 370 | 	Ha = reducl(H); | ||
| 371 | 	w = (Ga + Ha) * NXT; | ||
| 372 | |||
| 373 | 	/* Test the power of 2 for overflow */ | ||
| 374 | 	if (w > MEXP) | ||
| 375 | 		return huge * huge; /* overflow */ | ||
| 376 | 	if (w < MNEXP) | ||
| 377 | 		return twom10000 * twom10000; /* underflow */ | ||
| 378 | |||
| 379 | 	e = w; | ||
| 380 | 	Hb = H - Ha; | ||
| 381 | |||
| 382 | 	if (Hb > 0.0) { | ||
| 383 | 		e += 1; | ||
| 384 | 		Hb -= 1.0/NXT; /*0.0625L;*/ | ||
| 385 | 	} | ||
| 386 | |||
| 387 | 	/* Now the product y * log2(x) = Hb + e/NXT. | ||
| 388 | 	 * | ||
| 389 | 	 * Compute base 2 exponential of Hb, | ||
| 390 | 	 * where -0.0625 <= Hb <= 0. | ||
| 391 | 	 */ | ||
| 392 | 	z = Hb * __polevll(Hb, R, 6); /* z = 2**Hb - 1 */ | ||
| 393 | |||
| 394 | 	/* Express e/NXT as an integer plus a negative number of (1/NXT)ths. | ||
| 395 | 	 * Find lookup table entry for the fractional power of 2. | ||
| 396 | 	 */ | ||
| 397 | 	if (e < 0) | ||
| 398 | 		i = 0; | ||
| 399 | 	else | ||
| 400 | 		i = 1; | ||
| 401 | 	i = e/NXT + i; | ||
| 402 | 	e = NXT*i - e; | ||
| 403 | 	w = A[e]; | ||
| 404 | 	z = w * z; /* 2**-e * ( 1 + (2**Hb-1) ) */ | ||
| 405 | 	z = z + w; | ||
| 406 | 	z = scalbnl(z, i); /* multiply by integer power of 2 */ | ||
| 407 | |||
| 408 | 	if (nflg) | ||
| 409 | 		z = -z; | ||
| 410 | 	return z; | ||
| 411 | } | ||
| 412 | |||
| 413 | |||
| 414 | /* Find a multiple of 1/NXT that is within 1/NXT of x. */ | ||
| 415 | static long double reducl(long double x) | ||
| 416 | { | ||
| 417 | 	long double t; | ||
| 418 | |||
| 419 | 	t = x * NXT; | ||
| 420 | 	t = floorl(t); | ||
| 421 | 	t = t / NXT; | ||
| 422 | 	return t; | ||
| 423 | } | ||
| 424 | |||
| 425 | /* | ||
| 426 | * Positive real raised to integer power, long double precision | ||
| 427 | * | ||
| 428 | * | ||
| 429 | * SYNOPSIS: | ||
| 430 | * | ||
| 431 | * long double x, y, powil(); | ||
| 432 | * int n; | ||
| 433 | * | ||
| 434 | * y = powil( x, n ); | ||
| 435 | * | ||
| 436 | * | ||
| 437 | * DESCRIPTION: | ||
| 438 | * | ||
| 439 | * Returns argument x>0 raised to the nth power. | ||
| 440 | * The routine efficiently decomposes n as a sum of powers of | ||
| 441 | * two. The desired power is a product of two-to-the-kth | ||
| 442 | * powers of x. Thus to compute the 32767 power of x requires | ||
| 443 | * 28 multiplications instead of 32767 multiplications. | ||
| 444 | * | ||
| 445 | * | ||
| 446 | * ACCURACY: | ||
| 447 | * | ||
| 448 | * Relative error: | ||
| 449 | * arithmetic x domain n domain # trials peak rms | ||
| 450 | * IEEE .001,1000 -1022,1023 50000 4.3e-17 7.8e-18 | ||
| 451 | * IEEE 1,2 -1022,1023 20000 3.9e-17 7.6e-18 | ||
| 452 | * IEEE .99,1.01 0,8700 10000 3.6e-16 7.2e-17 | ||
| 453 | * | ||
| 454 | * Returns MAXNUM on overflow, zero on underflow. | ||
| 455 | */ | ||
| 456 | |||
| 457 | static long double powil(long double x, int nn) | ||
| 458 | { | ||
| 459 | 	long double ww, y; | ||
| 460 | 	long double s; | ||
| 461 | 	int n, e, sign, lx; | ||
| 462 | |||
| 463 | 	if (nn == 0) | ||
| 464 | 		return 1.0; | ||
| 465 | |||
| 466 | 	if (nn < 0) { | ||
| 467 | 		sign = -1; | ||
| 468 | 		n = -nn; | ||
| 469 | 	} else { | ||
| 470 | 		sign = 1; | ||
| 471 | 		n = nn; | ||
| 472 | 	} | ||
| 473 | |||
| 474 | 	/* Overflow detection */ | ||
| 475 | |||
| 476 | 	/* Calculate approximate logarithm of answer */ | ||
| 477 | 	s = x; | ||
| 478 | 	s = frexpl( s, &lx); | ||
| 479 | 	e = (lx - 1)*n; | ||
| 480 | 	if ((e == 0) || (e > 64) || (e < -64)) { | ||
| 481 | 		s = (s - 7.0710678118654752e-1L) / (s + 7.0710678118654752e-1L); | ||
| 482 | 		s = (2.9142135623730950L * s - 0.5 + lx) * nn * LOGE2L; | ||
| 483 | 	} else { | ||
| 484 | 		s = LOGE2L * e; | ||
| 485 | 	} | ||
| 486 | |||
| 487 | 	if (s > MAXLOGL) | ||
| 488 | 		return huge * huge; /* overflow */ | ||
| 489 | |||
| 490 | 	if (s < MINLOGL) | ||
| 491 | 		return twom10000 * twom10000; /* underflow */ | ||
| 492 | 	/* Handle tiny denormal answer, but with less accuracy | ||
| 493 | 	 * since roundoff error in 1.0/x will be amplified. | ||
| 494 | 	 * The precise demarcation should be the gradual underflow threshold. | ||
| 495 | 	 */ | ||
| 496 | 	if (s < -MAXLOGL+2.0) { | ||
| 497 | 		x = 1.0/x; | ||
| 498 | 		sign = -sign; | ||
| 499 | 	} | ||
| 500 | |||
| 501 | 	/* First bit of the power */ | ||
| 502 | 	if (n & 1) | ||
| 503 | 		y = x; | ||
| 504 | 	else | ||
| 505 | 		y = 1.0; | ||
| 506 | |||
| 507 | 	ww = x; | ||
| 508 | 	n >>= 1; | ||
| 509 | 	while (n) { | ||
| 510 | 		ww = ww * ww; /* arg to the 2-to-the-kth power */ | ||
| 511 | 		if (n & 1) /* if that bit is set, then include in product */ | ||
| 512 | 			y *= ww; | ||
| 513 | 		n >>= 1; | ||
| 514 | 	} | ||
| 515 | |||
| 516 | 	if (sign < 0) | ||
| 517 | 		y = 1.0/y; | ||
| 518 | 	return y; | ||
| 519 | } | ||
| 520 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 521 | // TODO: broken implementation to make things compile | ||
| 522 | long double powl(long double x, long double y) | ||
| 523 | { | ||
| 524 | 	return pow(x, y); | ||
| 525 | } | ||
| 526 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/remainder.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double remainder(double x, double y) | ||
| 4 | { | ||
| 5 | 	int q; | ||
| 6 | 	return remquo(x, y, &q); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(remainder, drem); | ||
lib/libc/wasi/libc-top-half/musl/src/math/remainderf.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float remainderf(float x, float y) | ||
| 4 | { | ||
| 5 | 	int q; | ||
| 6 | 	return remquof(x, y, &q); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(remainderf, dremf); | ||
lib/libc/wasi/libc-top-half/musl/src/math/remainderl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <float.h> | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | long double remainderl(long double x, long double y) | ||
| 6 | { | ||
| 7 | 	return remainder(x, y); | ||
| 8 | } | ||
| 9 | #else | ||
| 10 | long double remainderl(long double x, long double y) | ||
| 11 | { | ||
| 12 | 	int q; | ||
| 13 | 	return remquol(x, y, &q); | ||
| 14 | } | ||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/remquo.c created+82| ... | @@ -0,0 +1,82 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | double remquo(double x, double y, int *quo) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} ux = {x}, uy = {y}; | ||
| 7 | 	int ex = ux.i>>52 & 0x7ff; | ||
| 8 | 	int ey = uy.i>>52 & 0x7ff; | ||
| 9 | 	int sx = ux.i>>63; | ||
| 10 | 	int sy = uy.i>>63; | ||
| 11 | 	uint32_t q; | ||
| 12 | 	uint64_t i; | ||
| 13 | 	uint64_t uxi = ux.i; | ||
| 14 | |||
| 15 | 	*quo = 0; | ||
| 16 | 	if (uy.i<<1 == 0 || isnan(y) || ex == 0x7ff) | ||
| 17 | 		return (x*y)/(x*y); | ||
| 18 | 	if (ux.i<<1 == 0) | ||
| 19 | 		return x; | ||
| 20 | |||
| 21 | 	/* normalize x and y */ | ||
| 22 | 	if (!ex) { | ||
| 23 | 		for (i = uxi<<12; i>>63 == 0; ex--, i <<= 1); | ||
| 24 | 		uxi <<= -ex + 1; | ||
| 25 | 	} else { | ||
| 26 | 		uxi &= -1ULL >> 12; | ||
| 27 | 		uxi |= 1ULL << 52; | ||
| 28 | 	} | ||
| 29 | 	if (!ey) { | ||
| 30 | 		for (i = uy.i<<12; i>>63 == 0; ey--, i <<= 1); | ||
| 31 | 		uy.i <<= -ey + 1; | ||
| 32 | 	} else { | ||
| 33 | 		uy.i &= -1ULL >> 12; | ||
| 34 | 		uy.i |= 1ULL << 52; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	q = 0; | ||
| 38 | 	if (ex < ey) { | ||
| 39 | 		if (ex+1 == ey) | ||
| 40 | 			goto end; | ||
| 41 | 		return x; | ||
| 42 | 	} | ||
| 43 | |||
| 44 | 	/* x mod y */ | ||
| 45 | 	for (; ex > ey; ex--) { | ||
| 46 | 		i = uxi - uy.i; | ||
| 47 | 		if (i >> 63 == 0) { | ||
| 48 | 			uxi = i; | ||
| 49 | 			q++; | ||
| 50 | 		} | ||
| 51 | 		uxi <<= 1; | ||
| 52 | 		q <<= 1; | ||
| 53 | 	} | ||
| 54 | 	i = uxi - uy.i; | ||
| 55 | 	if (i >> 63 == 0) { | ||
| 56 | 		uxi = i; | ||
| 57 | 		q++; | ||
| 58 | 	} | ||
| 59 | 	if (uxi == 0) | ||
| 60 | 		ex = -60; | ||
| 61 | 	else | ||
| 62 | 		for (; uxi>>52 == 0; uxi <<= 1, ex--); | ||
| 63 | end: | ||
| 64 | 	/* scale result and decide between |x| and |x|-|y| */ | ||
| 65 | 	if (ex > 0) { | ||
| 66 | 		uxi -= 1ULL << 52; | ||
| 67 | 		uxi |= (uint64_t)ex << 52; | ||
| 68 | 	} else { | ||
| 69 | 		uxi >>= -ex + 1; | ||
| 70 | 	} | ||
| 71 | 	ux.i = uxi; | ||
| 72 | 	x = ux.f; | ||
| 73 | 	if (sy) | ||
| 74 | 		y = -y; | ||
| 75 | 	if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { | ||
| 76 | 		x -= y; | ||
| 77 | 		q++; | ||
| 78 | 	} | ||
| 79 | 	q &= 0x7fffffff; | ||
| 80 | 	*quo = sx^sy ? -(int)q : (int)q; | ||
| 81 | 	return sx ? -x : x; | ||
| 82 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/remquof.c created+82| ... | @@ -0,0 +1,82 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float remquof(float x, float y, int *quo) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} ux = {x}, uy = {y}; | ||
| 7 | 	int ex = ux.i>>23 & 0xff; | ||
| 8 | 	int ey = uy.i>>23 & 0xff; | ||
| 9 | 	int sx = ux.i>>31; | ||
| 10 | 	int sy = uy.i>>31; | ||
| 11 | 	uint32_t q; | ||
| 12 | 	uint32_t i; | ||
| 13 | 	uint32_t uxi = ux.i; | ||
| 14 | |||
| 15 | 	*quo = 0; | ||
| 16 | 	if (uy.i<<1 == 0 || isnan(y) || ex == 0xff) | ||
| 17 | 		return (x*y)/(x*y); | ||
| 18 | 	if (ux.i<<1 == 0) | ||
| 19 | 		return x; | ||
| 20 | |||
| 21 | 	/* normalize x and y */ | ||
| 22 | 	if (!ex) { | ||
| 23 | 		for (i = uxi<<9; i>>31 == 0; ex--, i <<= 1); | ||
| 24 | 		uxi <<= -ex + 1; | ||
| 25 | 	} else { | ||
| 26 | 		uxi &= -1U >> 9; | ||
| 27 | 		uxi |= 1U << 23; | ||
| 28 | 	} | ||
| 29 | 	if (!ey) { | ||
| 30 | 		for (i = uy.i<<9; i>>31 == 0; ey--, i <<= 1); | ||
| 31 | 		uy.i <<= -ey + 1; | ||
| 32 | 	} else { | ||
| 33 | 		uy.i &= -1U >> 9; | ||
| 34 | 		uy.i |= 1U << 23; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	q = 0; | ||
| 38 | 	if (ex < ey) { | ||
| 39 | 		if (ex+1 == ey) | ||
| 40 | 			goto end; | ||
| 41 | 		return x; | ||
| 42 | 	} | ||
| 43 | |||
| 44 | 	/* x mod y */ | ||
| 45 | 	for (; ex > ey; ex--) { | ||
| 46 | 		i = uxi - uy.i; | ||
| 47 | 		if (i >> 31 == 0) { | ||
| 48 | 			uxi = i; | ||
| 49 | 			q++; | ||
| 50 | 		} | ||
| 51 | 		uxi <<= 1; | ||
| 52 | 		q <<= 1; | ||
| 53 | 	} | ||
| 54 | 	i = uxi - uy.i; | ||
| 55 | 	if (i >> 31 == 0) { | ||
| 56 | 		uxi = i; | ||
| 57 | 		q++; | ||
| 58 | 	} | ||
| 59 | 	if (uxi == 0) | ||
| 60 | 		ex = -30; | ||
| 61 | 	else | ||
| 62 | 		for (; uxi>>23 == 0; uxi <<= 1, ex--); | ||
| 63 | end: | ||
| 64 | 	/* scale result and decide between |x| and |x|-|y| */ | ||
| 65 | 	if (ex > 0) { | ||
| 66 | 		uxi -= 1U << 23; | ||
| 67 | 		uxi |= (uint32_t)ex << 23; | ||
| 68 | 	} else { | ||
| 69 | 		uxi >>= -ex + 1; | ||
| 70 | 	} | ||
| 71 | 	ux.i = uxi; | ||
| 72 | 	x = ux.f; | ||
| 73 | 	if (sy) | ||
| 74 | 		y = -y; | ||
| 75 | 	if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { | ||
| 76 | 		x -= y; | ||
| 77 | 		q++; | ||
| 78 | 	} | ||
| 79 | 	q &= 0x7fffffff; | ||
| 80 | 	*quo = sx^sy ? -(int)q : (int)q; | ||
| 81 | 	return sx ? -x : x; | ||
| 82 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/remquol.c created+124| ... | @@ -0,0 +1,124 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double remquol(long double x, long double y, int *quo) | ||
| 5 | { | ||
| 6 | 	return remquo(x, y, quo); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double remquol(long double x, long double y, int *quo) | ||
| 10 | { | ||
| 11 | 	union ldshape ux = {x}, uy = {y}; | ||
| 12 | 	int ex = ux.i.se & 0x7fff; | ||
| 13 | 	int ey = uy.i.se & 0x7fff; | ||
| 14 | 	int sx = ux.i.se >> 15; | ||
| 15 | 	int sy = uy.i.se >> 15; | ||
| 16 | 	uint32_t q; | ||
| 17 | |||
| 18 | 	*quo = 0; | ||
| 19 | 	if (y == 0 || isnan(y) || ex == 0x7fff) | ||
| 20 | 		return (x*y)/(x*y); | ||
| 21 | 	if (x == 0) | ||
| 22 | 		return x; | ||
| 23 | |||
| 24 | 	/* normalize x and y */ | ||
| 25 | 	if (!ex) { | ||
| 26 | 		ux.i.se = ex; | ||
| 27 | 		ux.f *= 0x1p120f; | ||
| 28 | 		ex = ux.i.se - 120; | ||
| 29 | 	} | ||
| 30 | 	if (!ey) { | ||
| 31 | 		uy.i.se = ey; | ||
| 32 | 		uy.f *= 0x1p120f; | ||
| 33 | 		ey = uy.i.se - 120; | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	q = 0; | ||
| 37 | 	if (ex >= ey) { | ||
| 38 | 		/* x mod y */ | ||
| 39 | #if LDBL_MANT_DIG == 64 | ||
| 40 | 		uint64_t i, mx, my; | ||
| 41 | 		mx = ux.i.m; | ||
| 42 | 		my = uy.i.m; | ||
| 43 | 		for (; ex > ey; ex--) { | ||
| 44 | 			i = mx - my; | ||
| 45 | 			if (mx >= my) { | ||
| 46 | 				mx = 2*i; | ||
| 47 | 				q++; | ||
| 48 | 				q <<= 1; | ||
| 49 | 			} else if (2*mx < mx) { | ||
| 50 | 				mx = 2*mx - my; | ||
| 51 | 				q <<= 1; | ||
| 52 | 				q++; | ||
| 53 | 			} else { | ||
| 54 | 				mx = 2*mx; | ||
| 55 | 				q <<= 1; | ||
| 56 | 			} | ||
| 57 | 		} | ||
| 58 | 		i = mx - my; | ||
| 59 | 		if (mx >= my) { | ||
| 60 | 			mx = i; | ||
| 61 | 			q++; | ||
| 62 | 		} | ||
| 63 | 		if (mx == 0) | ||
| 64 | 			ex = -120; | ||
| 65 | 		else | ||
| 66 | 			for (; mx >> 63 == 0; mx *= 2, ex--); | ||
| 67 | 		ux.i.m = mx; | ||
| 68 | #elif LDBL_MANT_DIG == 113 | ||
| 69 | 		uint64_t hi, lo, xhi, xlo, yhi, ylo; | ||
| 70 | 		xhi = (ux.i2.hi & -1ULL>>16) | 1ULL<<48; | ||
| 71 | 		yhi = (uy.i2.hi & -1ULL>>16) | 1ULL<<48; | ||
| 72 | 		xlo = ux.i2.lo; | ||
| 73 | 		ylo = ux.i2.lo; | ||
| 74 | 		for (; ex > ey; ex--) { | ||
| 75 | 			hi = xhi - yhi; | ||
| 76 | 			lo = xlo - ylo; | ||
| 77 | 			if (xlo < ylo) | ||
| 78 | 				hi -= 1; | ||
| 79 | 			if (hi >> 63 == 0) { | ||
| 80 | 				xhi = 2*hi + (lo>>63); | ||
| 81 | 				xlo = 2*lo; | ||
| 82 | 				q++; | ||
| 83 | 			} else { | ||
| 84 | 				xhi = 2*xhi + (xlo>>63); | ||
| 85 | 				xlo = 2*xlo; | ||
| 86 | 			} | ||
| 87 | 			q <<= 1; | ||
| 88 | 		} | ||
| 89 | 		hi = xhi - yhi; | ||
| 90 | 		lo = xlo - ylo; | ||
| 91 | 		if (xlo < ylo) | ||
| 92 | 			hi -= 1; | ||
| 93 | 		if (hi >> 63 == 0) { | ||
| 94 | 			xhi = hi; | ||
| 95 | 			xlo = lo; | ||
| 96 | 			q++; | ||
| 97 | 		} | ||
| 98 | 		if ((xhi|xlo) == 0) | ||
| 99 | 			ex = -120; | ||
| 100 | 		else | ||
| 101 | 			for (; xhi >> 48 == 0; xhi = 2*xhi + (xlo>>63), xlo = 2*xlo, ex--); | ||
| 102 | 		ux.i2.hi = xhi; | ||
| 103 | 		ux.i2.lo = xlo; | ||
| 104 | #endif | ||
| 105 | 	} | ||
| 106 | |||
| 107 | 	/* scale result and decide between |x| and |x|-|y| */ | ||
| 108 | 	if (ex <= 0) { | ||
| 109 | 		ux.i.se = ex + 120; | ||
| 110 | 		ux.f *= 0x1p-120f; | ||
| 111 | 	} else | ||
| 112 | 		ux.i.se = ex; | ||
| 113 | 	x = ux.f; | ||
| 114 | 	if (sy) | ||
| 115 | 		y = -y; | ||
| 116 | 	if (ex == ey || (ex+1 == ey && (2*x > y || (2*x == y && q%2)))) { | ||
| 117 | 		x -= y; | ||
| 118 | 		q++; | ||
| 119 | 	} | ||
| 120 | 	q &= 0x7fffffff; | ||
| 121 | 	*quo = sx^sy ? -(int)q : (int)q; | ||
| 122 | 	return sx ? -x : x; | ||
| 123 | } | ||
| 124 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/rint.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include <float.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 6 | #define EPS DBL_EPSILON | ||
| 7 | #elif FLT_EVAL_METHOD==2 | ||
| 8 | #define EPS LDBL_EPSILON | ||
| 9 | #endif | ||
| 10 | static const double_t toint = 1/EPS; | ||
| 11 | |||
| 12 | double rint(double x) | ||
| 13 | { | ||
| 14 | 	union {double f; uint64_t i;} u = {x}; | ||
| 15 | 	int e = u.i>>52 & 0x7ff; | ||
| 16 | 	int s = u.i>>63; | ||
| 17 | 	double_t y; | ||
| 18 | |||
| 19 | 	if (e >= 0x3ff+52) | ||
| 20 | 		return x; | ||
| 21 | 	if (s) | ||
| 22 | 		y = x - toint + toint; | ||
| 23 | 	else | ||
| 24 | 		y = x + toint - toint; | ||
| 25 | 	if (y == 0) | ||
| 26 | 		return s ? -0.0 : 0; | ||
| 27 | 	return y; | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/rintf.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <float.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | #if FLT_EVAL_METHOD==0 | ||
| 6 | #define EPS FLT_EPSILON | ||
| 7 | #elif FLT_EVAL_METHOD==1 | ||
| 8 | #define EPS DBL_EPSILON | ||
| 9 | #elif FLT_EVAL_METHOD==2 | ||
| 10 | #define EPS LDBL_EPSILON | ||
| 11 | #endif | ||
| 12 | static const float_t toint = 1/EPS; | ||
| 13 | |||
| 14 | float rintf(float x) | ||
| 15 | { | ||
| 16 | 	union {float f; uint32_t i;} u = {x}; | ||
| 17 | 	int e = u.i>>23 & 0xff; | ||
| 18 | 	int s = u.i>>31; | ||
| 19 | 	float_t y; | ||
| 20 | |||
| 21 | 	if (e >= 0x7f+23) | ||
| 22 | 		return x; | ||
| 23 | 	if (s) | ||
| 24 | 		y = x - toint + toint; | ||
| 25 | 	else | ||
| 26 | 		y = x + toint - toint; | ||
| 27 | 	if (y == 0) | ||
| 28 | 		return s ? -0.0f : 0.0f; | ||
| 29 | 	return y; | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/rintl.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double rintl(long double x) | ||
| 5 | { | ||
| 6 | 	return rint(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | |||
| 10 | static const long double toint = 1/LDBL_EPSILON; | ||
| 11 | |||
| 12 | long double rintl(long double x) | ||
| 13 | { | ||
| 14 | 	union ldshape u = {x}; | ||
| 15 | 	int e = u.i.se & 0x7fff; | ||
| 16 | 	int s = u.i.se >> 15; | ||
| 17 | 	long double y; | ||
| 18 | |||
| 19 | 	if (e >= 0x3fff+LDBL_MANT_DIG-1) | ||
| 20 | 		return x; | ||
| 21 | 	if (s) | ||
| 22 | 		y = x - toint + toint; | ||
| 23 | 	else | ||
| 24 | 		y = x + toint - toint; | ||
| 25 | 	if (y == 0) | ||
| 26 | 		return 0*x; | ||
| 27 | 	return y; | ||
| 28 | } | ||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/copysign.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 64 | ||
| 4 | |||
| 5 | double copysign(double x, double y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsgnj.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../copysign.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/copysignf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 32 | ||
| 4 | |||
| 5 | float copysignf(float x, float y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsgnj.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../copysignf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fabs.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 64 | ||
| 4 | |||
| 5 | double fabs(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fabs.d %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabs.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fabsf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 32 | ||
| 4 | |||
| 5 | float fabsf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fabs.s %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabsf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fma.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 64 | ||
| 4 | |||
| 5 | double fma(double x, double y, double z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fmadd.d %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fma.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmaf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 32 | ||
| 4 | |||
| 5 | float fmaf(float x, float y, float z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fmadd.s %0, %1, %2, %3" : "=f"(x) : "f"(x), "f"(y), "f"(z)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmaf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmax.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 64 | ||
| 4 | |||
| 5 | double fmax(double x, double y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fmax.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmax.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmaxf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 32 | ||
| 4 | |||
| 5 | float fmaxf(float x, float y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fmax.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmaxf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fmin.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 64 | ||
| 4 | |||
| 5 | double fmin(double x, double y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fmin.d %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fmin.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/fminf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 32 | ||
| 4 | |||
| 5 | float fminf(float x, float y) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fmin.s %0, %1, %2" : "=f"(x) : "f"(x), "f"(y)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fminf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/sqrt.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 64 | ||
| 4 | |||
| 5 | double sqrt(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsqrt.d %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrt.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/riscv64/sqrtf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __riscv_flen >= 32 | ||
| 4 | |||
| 5 | float sqrtf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fsqrt.s %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrtf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/round.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if FLT_EVAL_METHOD==0 || FLT_EVAL_METHOD==1 | ||
| 4 | #define EPS DBL_EPSILON | ||
| 5 | #elif FLT_EVAL_METHOD==2 | ||
| 6 | #define EPS LDBL_EPSILON | ||
| 7 | #endif | ||
| 8 | static const double_t toint = 1/EPS; | ||
| 9 | |||
| 10 | double round(double x) | ||
| 11 | { | ||
| 12 | 	union {double f; uint64_t i;} u = {x}; | ||
| 13 | 	int e = u.i >> 52 & 0x7ff; | ||
| 14 | 	double_t y; | ||
| 15 | |||
| 16 | 	if (e >= 0x3ff+52) | ||
| 17 | 		return x; | ||
| 18 | 	if (u.i >> 63) | ||
| 19 | 		x = -x; | ||
| 20 | 	if (e < 0x3ff-1) { | ||
| 21 | 		/* raise inexact if x!=0 */ | ||
| 22 | 		FORCE_EVAL(x + toint); | ||
| 23 | 		return 0*u.f; | ||
| 24 | 	} | ||
| 25 | 	y = x + toint - toint - x; | ||
| 26 | 	if (y > 0.5) | ||
| 27 | 		y = y + x - 1; | ||
| 28 | 	else if (y <= -0.5) | ||
| 29 | 		y = y + x + 1; | ||
| 30 | 	else | ||
| 31 | 		y = y + x; | ||
| 32 | 	if (u.i >> 63) | ||
| 33 | 		y = -y; | ||
| 34 | 	return y; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/roundf.c created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if FLT_EVAL_METHOD==0 | ||
| 4 | #define EPS FLT_EPSILON | ||
| 5 | #elif FLT_EVAL_METHOD==1 | ||
| 6 | #define EPS DBL_EPSILON | ||
| 7 | #elif FLT_EVAL_METHOD==2 | ||
| 8 | #define EPS LDBL_EPSILON | ||
| 9 | #endif | ||
| 10 | static const float_t toint = 1/EPS; | ||
| 11 | |||
| 12 | float roundf(float x) | ||
| 13 | { | ||
| 14 | 	union {float f; uint32_t i;} u = {x}; | ||
| 15 | 	int e = u.i >> 23 & 0xff; | ||
| 16 | 	float_t y; | ||
| 17 | |||
| 18 | 	if (e >= 0x7f+23) | ||
| 19 | 		return x; | ||
| 20 | 	if (u.i >> 31) | ||
| 21 | 		x = -x; | ||
| 22 | 	if (e < 0x7f-1) { | ||
| 23 | 		FORCE_EVAL(x + toint); | ||
| 24 | 		return 0*u.f; | ||
| 25 | 	} | ||
| 26 | 	y = x + toint - toint - x; | ||
| 27 | 	if (y > 0.5f) | ||
| 28 | 		y = y + x - 1; | ||
| 29 | 	else if (y <= -0.5f) | ||
| 30 | 		y = y + x + 1; | ||
| 31 | 	else | ||
| 32 | 		y = y + x; | ||
| 33 | 	if (u.i >> 31) | ||
| 34 | 		y = -y; | ||
| 35 | 	return y; | ||
| 36 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/roundl.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double roundl(long double x) | ||
| 5 | { | ||
| 6 | 	return round(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | |||
| 10 | static const long double toint = 1/LDBL_EPSILON; | ||
| 11 | |||
| 12 | long double roundl(long double x) | ||
| 13 | { | ||
| 14 | 	union ldshape u = {x}; | ||
| 15 | 	int e = u.i.se & 0x7fff; | ||
| 16 | 	long double y; | ||
| 17 | |||
| 18 | 	if (e >= 0x3fff+LDBL_MANT_DIG-1) | ||
| 19 | 		return x; | ||
| 20 | 	if (u.i.se >> 15) | ||
| 21 | 		x = -x; | ||
| 22 | 	if (e < 0x3fff-1) { | ||
| 23 | 		FORCE_EVAL(x + toint); | ||
| 24 | 		return 0*u.f; | ||
| 25 | 	} | ||
| 26 | 	y = x + toint - toint - x; | ||
| 27 | 	if (y > 0.5) | ||
| 28 | 		y = y + x - 1; | ||
| 29 | 	else if (y <= -0.5) | ||
| 30 | 		y = y + x + 1; | ||
| 31 | 	else | ||
| 32 | 		y = y + x; | ||
| 33 | 	if (u.i.se >> 15) | ||
| 34 | 		y = -y; | ||
| 35 | 	return y; | ||
| 36 | } | ||
| 37 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceil.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double ceil(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fidbra %0, 6, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../ceil.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceilf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float ceilf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fiebra %0, 6, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../ceilf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/ceill.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double ceill(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fixbra %0, 6, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../ceill.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabs.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double fabs(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("lpdbr %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabs.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabsf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float fabsf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("lpebr %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabsf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fabsl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double fabsl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("lpxbr %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../fabsl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floor.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double floor(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fidbra %0, 7, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../floor.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floorf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float floorf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fiebra %0, 7, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../floorf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/floorl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double floorl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fixbra %0, 7, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../floorl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fma.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fma(double x, double y, double z) | ||
| 4 | { | ||
| 5 | 	__asm__ ("madbr %0, %1, %2" : "+f"(z) : "f"(x), "f"(y)); | ||
| 6 | 	return z; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/fmaf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fmaf(float x, float y, float z) | ||
| 4 | { | ||
| 5 | 	__asm__ ("maebr %0, %1, %2" : "+f"(z) : "f"(x), "f"(y)); | ||
| 6 | 	return z; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyint.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double nearbyint(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fidbra %0, 0, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../nearbyint.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyintf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float nearbyintf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fiebra %0, 0, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../nearbyintf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/nearbyintl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double nearbyintl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fixbra %0, 0, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../nearbyintl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rint.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double rint(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fidbr %0, 0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../rint.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rintf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float rintf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fiebr %0, 0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../rintf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/rintl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double rintl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fixbr %0, 0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../rintl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/round.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double round(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fidbra %0, 1, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../round.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/roundf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float roundf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fiebra %0, 1, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../roundf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/roundl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double roundl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fixbra %0, 1, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../roundl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrt.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double sqrt(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("sqdbr %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrt.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrtf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float sqrtf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("sqebr %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrtf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/sqrtl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double sqrtl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("sqxbr %0, %1" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../sqrtl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/trunc.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | double trunc(double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fidbra %0, 5, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../trunc.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/truncf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | float truncf(float x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fiebra %0, 5, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../truncf.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/s390x/truncl.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if defined(__HTM__) || __ARCH__ >= 9 | ||
| 4 | |||
| 5 | long double truncl(long double x) | ||
| 6 | { | ||
| 7 | 	__asm__ ("fixbra %0, 5, %1, 4" : "=f"(x) : "f"(x)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #else | ||
| 12 | |||
| 13 | #include "../truncl.c" | ||
| 14 | |||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalb.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_scalb.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 | /* | ||
| 13 | * scalb(x, fn) is provide for | ||
| 14 | * passing various standard test suite. One | ||
| 15 | * should use scalbn() instead. | ||
| 16 | */ | ||
| 17 | |||
| 18 | #define _GNU_SOURCE | ||
| 19 | #include <math.h> | ||
| 20 | |||
| 21 | double scalb(double x, double fn) | ||
| 22 | { | ||
| 23 | 	if (isnan(x) || isnan(fn)) | ||
| 24 | 		return x*fn; | ||
| 25 | 	if (!isfinite(fn)) { | ||
| 26 | 		if (fn > 0.0) | ||
| 27 | 			return x*fn; | ||
| 28 | 		else | ||
| 29 | 			return x/(-fn); | ||
| 30 | 	} | ||
| 31 | 	if (rint(fn) != fn) return (fn-fn)/(fn-fn); | ||
| 32 | 	if ( fn > 65000.0) return scalbn(x, 65000); | ||
| 33 | 	if (-fn > 65000.0) return scalbn(x,-65000); | ||
| 34 | 	return scalbn(x,(int)fn); | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalbf.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/e_scalbf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | */ | ||
| 5 | /* | ||
| 6 | * ==================================================== | ||
| 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 8 | * | ||
| 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. | ||
| 10 | * Permission to use, copy, modify, and distribute this | ||
| 11 | * software is freely granted, provided that this notice | ||
| 12 | * is preserved. | ||
| 13 | * ==================================================== | ||
| 14 | */ | ||
| 15 | |||
| 16 | #define _GNU_SOURCE | ||
| 17 | #include <math.h> | ||
| 18 | |||
| 19 | float scalbf(float x, float fn) | ||
| 20 | { | ||
| 21 | 	if (isnan(x) || isnan(fn)) return x*fn; | ||
| 22 | 	if (!isfinite(fn)) { | ||
| 23 | 		if (fn > 0.0f) | ||
| 24 | 			return x*fn; | ||
| 25 | 		else | ||
| 26 | 			return x/(-fn); | ||
| 27 | 	} | ||
| 28 | 	if (rintf(fn) != fn) return (fn-fn)/(fn-fn); | ||
| 29 | 	if ( fn > 65000.0f) return scalbnf(x, 65000); | ||
| 30 | 	if (-fn > 65000.0f) return scalbnf(x,-65000); | ||
| 31 | 	return scalbnf(x,(int)fn); | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalbln.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | double scalbln(double x, long n) | ||
| 5 | { | ||
| 6 | 	if (n > INT_MAX) | ||
| 7 | 		n = INT_MAX; | ||
| 8 | 	else if (n < INT_MIN) | ||
| 9 | 		n = INT_MIN; | ||
| 10 | 	return scalbn(x, n); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalblnf.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | float scalblnf(float x, long n) | ||
| 5 | { | ||
| 6 | 	if (n > INT_MAX) | ||
| 7 | 		n = INT_MAX; | ||
| 8 | 	else if (n < INT_MIN) | ||
| 9 | 		n = INT_MIN; | ||
| 10 | 	return scalbnf(x, n); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalblnl.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <limits.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include <float.h> | ||
| 4 | |||
| 5 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 6 | long double scalblnl(long double x, long n) | ||
| 7 | { | ||
| 8 | 	return scalbln(x, n); | ||
| 9 | } | ||
| 10 | #else | ||
| 11 | long double scalblnl(long double x, long n) | ||
| 12 | { | ||
| 13 | 	if (n > INT_MAX) | ||
| 14 | 		n = INT_MAX; | ||
| 15 | 	else if (n < INT_MIN) | ||
| 16 | 		n = INT_MIN; | ||
| 17 | 	return scalbnl(x, n); | ||
| 18 | } | ||
| 19 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalbn.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | double scalbn(double x, int n) | ||
| 5 | { | ||
| 6 | 	union {double f; uint64_t i;} u; | ||
| 7 | 	double_t y = x; | ||
| 8 | |||
| 9 | 	if (n > 1023) { | ||
| 10 | 		y *= 0x1p1023; | ||
| 11 | 		n -= 1023; | ||
| 12 | 		if (n > 1023) { | ||
| 13 | 			y *= 0x1p1023; | ||
| 14 | 			n -= 1023; | ||
| 15 | 			if (n > 1023) | ||
| 16 | 				n = 1023; | ||
| 17 | 		} | ||
| 18 | 	} else if (n < -1022) { | ||
| 19 | 		/* make sure final n < -53 to avoid double | ||
| 20 | 		 rounding in the subnormal range */ | ||
| 21 | 		y *= 0x1p-1022 * 0x1p53; | ||
| 22 | 		n += 1022 - 53; | ||
| 23 | 		if (n < -1022) { | ||
| 24 | 			y *= 0x1p-1022 * 0x1p53; | ||
| 25 | 			n += 1022 - 53; | ||
| 26 | 			if (n < -1022) | ||
| 27 | 				n = -1022; | ||
| 28 | 		} | ||
| 29 | 	} | ||
| 30 | 	u.i = (uint64_t)(0x3ff+n)<<52; | ||
| 31 | 	x = y * u.f; | ||
| 32 | 	return x; | ||
| 33 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalbnf.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | float scalbnf(float x, int n) | ||
| 5 | { | ||
| 6 | 	union {float f; uint32_t i;} u; | ||
| 7 | 	float_t y = x; | ||
| 8 | |||
| 9 | 	if (n > 127) { | ||
| 10 | 		y *= 0x1p127f; | ||
| 11 | 		n -= 127; | ||
| 12 | 		if (n > 127) { | ||
| 13 | 			y *= 0x1p127f; | ||
| 14 | 			n -= 127; | ||
| 15 | 			if (n > 127) | ||
| 16 | 				n = 127; | ||
| 17 | 		} | ||
| 18 | 	} else if (n < -126) { | ||
| 19 | 		y *= 0x1p-126f * 0x1p24f; | ||
| 20 | 		n += 126 - 24; | ||
| 21 | 		if (n < -126) { | ||
| 22 | 			y *= 0x1p-126f * 0x1p24f; | ||
| 23 | 			n += 126 - 24; | ||
| 24 | 			if (n < -126) | ||
| 25 | 				n = -126; | ||
| 26 | 		} | ||
| 27 | 	} | ||
| 28 | 	u.i = (uint32_t)(0x7f+n)<<23; | ||
| 29 | 	x = y * u.f; | ||
| 30 | 	return x; | ||
| 31 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/scalbnl.c created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double scalbnl(long double x, int n) | ||
| 5 | { | ||
| 6 | 	return scalbn(x, n); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double scalbnl(long double x, int n) | ||
| 10 | { | ||
| 11 | 	union ldshape u; | ||
| 12 | |||
| 13 | 	if (n > 16383) { | ||
| 14 | 		x *= 0x1p16383L; | ||
| 15 | 		n -= 16383; | ||
| 16 | 		if (n > 16383) { | ||
| 17 | 			x *= 0x1p16383L; | ||
| 18 | 			n -= 16383; | ||
| 19 | 			if (n > 16383) | ||
| 20 | 				n = 16383; | ||
| 21 | 		} | ||
| 22 | 	} else if (n < -16382) { | ||
| 23 | 		x *= 0x1p-16382L * 0x1p113L; | ||
| 24 | 		n += 16382 - 113; | ||
| 25 | 		if (n < -16382) { | ||
| 26 | 			x *= 0x1p-16382L * 0x1p113L; | ||
| 27 | 			n += 16382 - 113; | ||
| 28 | 			if (n < -16382) | ||
| 29 | 				n = -16382; | ||
| 30 | 		} | ||
| 31 | 	} | ||
| 32 | 	u.f = 1.0; | ||
| 33 | 	u.i.se = 0x3fff + n; | ||
| 34 | 	return x * u.f; | ||
| 35 | } | ||
| 36 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/signgam.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | int __signgam = 0; | ||
| 5 | |||
| 6 | weak_alias(__signgam, signgam); | ||
lib/libc/wasi/libc-top-half/musl/src/math/significand.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | double significand(double x) | ||
| 5 | { | ||
| 6 | 	return scalbn(x, -ilogb(x)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/significandf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <math.h> | ||
| 3 | |||
| 4 | float significandf(float x) | ||
| 5 | { | ||
| 6 | 	return scalbnf(x, -ilogbf(x)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sin.c created+78| ... | @@ -0,0 +1,78 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* sin(x) | ||
| 13 | * Return sine function of x. | ||
| 14 | * | ||
| 15 | * kernel function: | ||
| 16 | * __sin ... sine function on [-pi/4,pi/4] | ||
| 17 | * __cos ... cose function on [-pi/4,pi/4] | ||
| 18 | * __rem_pio2 ... argument reduction routine | ||
| 19 | * | ||
| 20 | * Method. | ||
| 21 | * Let S,C and T denote the sin, cos and tan respectively on | ||
| 22 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 | ||
| 23 | * in [-pi/4 , +pi/4], and let n = k mod 4. | ||
| 24 | * We have | ||
| 25 | * | ||
| 26 | * n sin(x) cos(x) tan(x) | ||
| 27 | * ---------------------------------------------------------- | ||
| 28 | * 0 S C T | ||
| 29 | * 1 C -S -1/T | ||
| 30 | * 2 -S -C T | ||
| 31 | * 3 -C S -1/T | ||
| 32 | * ---------------------------------------------------------- | ||
| 33 | * | ||
| 34 | * Special cases: | ||
| 35 | * Let trig be any of sin, cos, or tan. | ||
| 36 | * trig(+-INF) is NaN, with signals; | ||
| 37 | * trig(NaN) is that NaN; | ||
| 38 | * | ||
| 39 | * Accuracy: | ||
| 40 | * TRIG(x) returns trig(x) nearly rounded | ||
| 41 | */ | ||
| 42 | |||
| 43 | #include "libm.h" | ||
| 44 | |||
| 45 | double sin(double x) | ||
| 46 | { | ||
| 47 | 	double y[2]; | ||
| 48 | 	uint32_t ix; | ||
| 49 | 	unsigned n; | ||
| 50 | |||
| 51 | 	/* High word of x. */ | ||
| 52 | 	GET_HIGH_WORD(ix, x); | ||
| 53 | 	ix &= 0x7fffffff; | ||
| 54 | |||
| 55 | 	/* |x| ~< pi/4 */ | ||
| 56 | 	if (ix <= 0x3fe921fb) { | ||
| 57 | 		if (ix < 0x3e500000) { /* |x| < 2**-26 */ | ||
| 58 | 			/* raise inexact if x != 0 and underflow if subnormal*/ | ||
| 59 | 			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); | ||
| 60 | 			return x; | ||
| 61 | 		} | ||
| 62 | 		return __sin(x, 0.0, 0); | ||
| 63 | 	} | ||
| 64 | |||
| 65 | 	/* sin(Inf or NaN) is NaN */ | ||
| 66 | 	if (ix >= 0x7ff00000) | ||
| 67 | 		return x - x; | ||
| 68 | |||
| 69 | 	/* argument reduction needed */ | ||
| 70 | 	n = __rem_pio2(x, y); | ||
| 71 | 	switch (n&3) { | ||
| 72 | 	case 0: return __sin(y[0], y[1], 1); | ||
| 73 | 	case 1: return __cos(y[0], y[1]); | ||
| 74 | 	case 2: return -__sin(y[0], y[1], 1); | ||
| 75 | 	default: | ||
| 76 | 		return -__cos(y[0], y[1]); | ||
| 77 | 	} | ||
| 78 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sincos.c created+69| ... | @@ -0,0 +1,69 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_sin.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | |||
| 13 | #define _GNU_SOURCE | ||
| 14 | #include "libm.h" | ||
| 15 | |||
| 16 | void sincos(double x, double *sin, double *cos) | ||
| 17 | { | ||
| 18 | 	double y[2], s, c; | ||
| 19 | 	uint32_t ix; | ||
| 20 | 	unsigned n; | ||
| 21 | |||
| 22 | 	GET_HIGH_WORD(ix, x); | ||
| 23 | 	ix &= 0x7fffffff; | ||
| 24 | |||
| 25 | 	/* |x| ~< pi/4 */ | ||
| 26 | 	if (ix <= 0x3fe921fb) { | ||
| 27 | 		/* if |x| < 2**-27 * sqrt(2) */ | ||
| 28 | 		if (ix < 0x3e46a09e) { | ||
| 29 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 30 | 			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); | ||
| 31 | 			*sin = x; | ||
| 32 | 			*cos = 1.0; | ||
| 33 | 			return; | ||
| 34 | 		} | ||
| 35 | 		*sin = __sin(x, 0.0, 0); | ||
| 36 | 		*cos = __cos(x, 0.0); | ||
| 37 | 		return; | ||
| 38 | 	} | ||
| 39 | |||
| 40 | 	/* sincos(Inf or NaN) is NaN */ | ||
| 41 | 	if (ix >= 0x7ff00000) { | ||
| 42 | 		*sin = *cos = x - x; | ||
| 43 | 		return; | ||
| 44 | 	} | ||
| 45 | |||
| 46 | 	/* argument reduction needed */ | ||
| 47 | 	n = __rem_pio2(x, y); | ||
| 48 | 	s = __sin(y[0], y[1], 1); | ||
| 49 | 	c = __cos(y[0], y[1]); | ||
| 50 | 	switch (n&3) { | ||
| 51 | 	case 0: | ||
| 52 | 		*sin = s; | ||
| 53 | 		*cos = c; | ||
| 54 | 		break; | ||
| 55 | 	case 1: | ||
| 56 | 		*sin = c; | ||
| 57 | 		*cos = -s; | ||
| 58 | 		break; | ||
| 59 | 	case 2: | ||
| 60 | 		*sin = -s; | ||
| 61 | 		*cos = -c; | ||
| 62 | 		break; | ||
| 63 | 	case 3: | ||
| 64 | 	default: | ||
| 65 | 		*sin = -c; | ||
| 66 | 		*cos = s; | ||
| 67 | 		break; | ||
| 68 | 	} | ||
| 69 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sincosf.c created+117| ... | @@ -0,0 +1,117 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * 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 | |||
| 17 | #define _GNU_SOURCE | ||
| 18 | #include "libm.h" | ||
| 19 | |||
| 20 | /* Small multiples of pi/2 rounded to double precision. */ | ||
| 21 | static const double | ||
| 22 | s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ | ||
| 23 | s2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ | ||
| 24 | s3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ | ||
| 25 | s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ | ||
| 26 | |||
| 27 | void sincosf(float x, float *sin, float *cos) | ||
| 28 | { | ||
| 29 | 	double y; | ||
| 30 | 	float_t s, c; | ||
| 31 | 	uint32_t ix; | ||
| 32 | 	unsigned n, sign; | ||
| 33 | |||
| 34 | 	GET_FLOAT_WORD(ix, x); | ||
| 35 | 	sign = ix >> 31; | ||
| 36 | 	ix &= 0x7fffffff; | ||
| 37 | |||
| 38 | 	/* |x| ~<= pi/4 */ | ||
| 39 | 	if (ix <= 0x3f490fda) { | ||
| 40 | 		/* |x| < 2**-12 */ | ||
| 41 | 		if (ix < 0x39800000) { | ||
| 42 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 43 | 			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); | ||
| 44 | 			*sin = x; | ||
| 45 | 			*cos = 1.0f; | ||
| 46 | 			return; | ||
| 47 | 		} | ||
| 48 | 		*sin = __sindf(x); | ||
| 49 | 		*cos = __cosdf(x); | ||
| 50 | 		return; | ||
| 51 | 	} | ||
| 52 | |||
| 53 | 	/* |x| ~<= 5*pi/4 */ | ||
| 54 | 	if (ix <= 0x407b53d1) { | ||
| 55 | 		if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */ | ||
| 56 | 			if (sign) { | ||
| 57 | 				*sin = -__cosdf(x + s1pio2); | ||
| 58 | 				*cos = __sindf(x + s1pio2); | ||
| 59 | 			} else { | ||
| 60 | 				*sin = __cosdf(s1pio2 - x); | ||
| 61 | 				*cos = __sindf(s1pio2 - x); | ||
| 62 | 			} | ||
| 63 | 			return; | ||
| 64 | 		} | ||
| 65 | 		/* -sin(x+c) is not correct if x+c could be 0: -0 vs +0 */ | ||
| 66 | 		*sin = -__sindf(sign ? x + s2pio2 : x - s2pio2); | ||
| 67 | 		*cos = -__cosdf(sign ? x + s2pio2 : x - s2pio2); | ||
| 68 | 		return; | ||
| 69 | 	} | ||
| 70 | |||
| 71 | 	/* |x| ~<= 9*pi/4 */ | ||
| 72 | 	if (ix <= 0x40e231d5) { | ||
| 73 | 		if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */ | ||
| 74 | 			if (sign) { | ||
| 75 | 				*sin = __cosdf(x + s3pio2); | ||
| 76 | 				*cos = -__sindf(x + s3pio2); | ||
| 77 | 			} else { | ||
| 78 | 				*sin = -__cosdf(x - s3pio2); | ||
| 79 | 				*cos = __sindf(x - s3pio2); | ||
| 80 | 			} | ||
| 81 | 			return; | ||
| 82 | 		} | ||
| 83 | 		*sin = __sindf(sign ? x + s4pio2 : x - s4pio2); | ||
| 84 | 		*cos = __cosdf(sign ? x + s4pio2 : x - s4pio2); | ||
| 85 | 		return; | ||
| 86 | 	} | ||
| 87 | |||
| 88 | 	/* sin(Inf or NaN) is NaN */ | ||
| 89 | 	if (ix >= 0x7f800000) { | ||
| 90 | 		*sin = *cos = x - x; | ||
| 91 | 		return; | ||
| 92 | 	} | ||
| 93 | |||
| 94 | 	/* general argument reduction needed */ | ||
| 95 | 	n = __rem_pio2f(x, &y); | ||
| 96 | 	s = __sindf(y); | ||
| 97 | 	c = __cosdf(y); | ||
| 98 | 	switch (n&3) { | ||
| 99 | 	case 0: | ||
| 100 | 		*sin = s; | ||
| 101 | 		*cos = c; | ||
| 102 | 		break; | ||
| 103 | 	case 1: | ||
| 104 | 		*sin = c; | ||
| 105 | 		*cos = -s; | ||
| 106 | 		break; | ||
| 107 | 	case 2: | ||
| 108 | 		*sin = -s; | ||
| 109 | 		*cos = -c; | ||
| 110 | 		break; | ||
| 111 | 	case 3: | ||
| 112 | 	default: | ||
| 113 | 		*sin = -c; | ||
| 114 | 		*cos = s; | ||
| 115 | 		break; | ||
| 116 | 	} | ||
| 117 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sincosl.c created+60| ... | @@ -0,0 +1,60 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "libm.h" | ||
| 3 | |||
| 4 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 5 | void sincosl(long double x, long double *sin, long double *cos) | ||
| 6 | { | ||
| 7 | 	double sind, cosd; | ||
| 8 | 	sincos(x, &sind, &cosd); | ||
| 9 | 	*sin = sind; | ||
| 10 | 	*cos = cosd; | ||
| 11 | } | ||
| 12 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 13 | void sincosl(long double x, long double *sin, long double *cos) | ||
| 14 | { | ||
| 15 | 	union ldshape u = {x}; | ||
| 16 | 	unsigned n; | ||
| 17 | 	long double y[2], s, c; | ||
| 18 | |||
| 19 | 	u.i.se &= 0x7fff; | ||
| 20 | 	if (u.i.se == 0x7fff) { | ||
| 21 | 		*sin = *cos = x - x; | ||
| 22 | 		return; | ||
| 23 | 	} | ||
| 24 | 	if (u.f < M_PI_4) { | ||
| 25 | 		if (u.i.se < 0x3fff - LDBL_MANT_DIG) { | ||
| 26 | 			/* raise underflow if subnormal */ | ||
| 27 | 			if (u.i.se == 0) FORCE_EVAL(x*0x1p-120f); | ||
| 28 | 			*sin = x; | ||
| 29 | 			/* raise inexact if x!=0 */ | ||
| 30 | 			*cos = 1.0 + x; | ||
| 31 | 			return; | ||
| 32 | 		} | ||
| 33 | 		*sin = __sinl(x, 0, 0); | ||
| 34 | 		*cos = __cosl(x, 0); | ||
| 35 | 		return; | ||
| 36 | 	} | ||
| 37 | 	n = __rem_pio2l(x, y); | ||
| 38 | 	s = __sinl(y[0], y[1], 1); | ||
| 39 | 	c = __cosl(y[0], y[1]); | ||
| 40 | 	switch (n & 3) { | ||
| 41 | 	case 0: | ||
| 42 | 		*sin = s; | ||
| 43 | 		*cos = c; | ||
| 44 | 		break; | ||
| 45 | 	case 1: | ||
| 46 | 		*sin = c; | ||
| 47 | 		*cos = -s; | ||
| 48 | 		break; | ||
| 49 | 	case 2: | ||
| 50 | 		*sin = -s; | ||
| 51 | 		*cos = -c; | ||
| 52 | 		break; | ||
| 53 | 	case 3: | ||
| 54 | 	default: | ||
| 55 | 		*sin = -c; | ||
| 56 | 		*cos = s; | ||
| 57 | 		break; | ||
| 58 | 	} | ||
| 59 | } | ||
| 60 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/sinf.c created+76| ... | @@ -0,0 +1,76 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_sinf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * 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 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | /* Small multiples of pi/2 rounded to double precision. */ | ||
| 20 | static const double | ||
| 21 | s1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ | ||
| 22 | s2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ | ||
| 23 | s3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ | ||
| 24 | s4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ | ||
| 25 | |||
| 26 | float sinf(float x) | ||
| 27 | { | ||
| 28 | 	double y; | ||
| 29 | 	uint32_t ix; | ||
| 30 | 	int n, sign; | ||
| 31 | |||
| 32 | 	GET_FLOAT_WORD(ix, x); | ||
| 33 | 	sign = ix >> 31; | ||
| 34 | 	ix &= 0x7fffffff; | ||
| 35 | |||
| 36 | 	if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ | ||
| 37 | 		if (ix < 0x39800000) { /* |x| < 2**-12 */ | ||
| 38 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 39 | 			FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f); | ||
| 40 | 			return x; | ||
| 41 | 		} | ||
| 42 | 		return __sindf(x); | ||
| 43 | 	} | ||
| 44 | 	if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */ | ||
| 45 | 		if (ix <= 0x4016cbe3) { /* |x| ~<= 3pi/4 */ | ||
| 46 | 			if (sign) | ||
| 47 | 				return -__cosdf(x + s1pio2); | ||
| 48 | 			else | ||
| 49 | 				return __cosdf(x - s1pio2); | ||
| 50 | 		} | ||
| 51 | 		return __sindf(sign ? -(x + s2pio2) : -(x - s2pio2)); | ||
| 52 | 	} | ||
| 53 | 	if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */ | ||
| 54 | 		if (ix <= 0x40afeddf) { /* |x| ~<= 7*pi/4 */ | ||
| 55 | 			if (sign) | ||
| 56 | 				return __cosdf(x + s3pio2); | ||
| 57 | 			else | ||
| 58 | 				return -__cosdf(x - s3pio2); | ||
| 59 | 		} | ||
| 60 | 		return __sindf(sign ? x + s4pio2 : x - s4pio2); | ||
| 61 | 	} | ||
| 62 | |||
| 63 | 	/* sin(Inf or NaN) is NaN */ | ||
| 64 | 	if (ix >= 0x7f800000) | ||
| 65 | 		return x - x; | ||
| 66 | |||
| 67 | 	/* general argument reduction needed */ | ||
| 68 | 	n = __rem_pio2f(x, &y); | ||
| 69 | 	switch (n&3) { | ||
| 70 | 	case 0: return __sindf(y); | ||
| 71 | 	case 1: return __cosdf(y); | ||
| 72 | 	case 2: return __sindf(-y); | ||
| 73 | 	default: | ||
| 74 | 		return -__cosdf(y); | ||
| 75 | 	} | ||
| 76 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sinh.c created+43| ... | @@ -0,0 +1,43 @@ | ||
| 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 created+35| ... | @@ -0,0 +1,35 @@ | ||
| 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/math/sinhl.c created+43| ... | @@ -0,0 +1,43 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double sinhl(long double x) | ||
| 5 | { | ||
| 6 | 	return sinh(x); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | long double sinhl(long double x) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	unsigned ex = u.i.se & 0x7fff; | ||
| 13 | 	long double h, t, absx; | ||
| 14 | |||
| 15 | 	h = 0.5; | ||
| 16 | 	if (u.i.se & 0x8000) | ||
| 17 | 		h = -h; | ||
| 18 | 	/* |x| */ | ||
| 19 | 	u.i.se = ex; | ||
| 20 | 	absx = u.f; | ||
| 21 | |||
| 22 | 	/* |x| < log(LDBL_MAX) */ | ||
| 23 | 	if (ex < 0x3fff+13 || (ex == 0x3fff+13 && u.i.m>>32 < 0xb17217f7)) { | ||
| 24 | 		t = expm1l(absx); | ||
| 25 | 		if (ex < 0x3fff) { | ||
| 26 | 			if (ex < 0x3fff-32) | ||
| 27 | 				return x; | ||
| 28 | 			return h*(2*t - t*t/(1+t)); | ||
| 29 | 		} | ||
| 30 | 		return h*(t + t/(t+1)); | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	/* |x| > log(LDBL_MAX) or nan */ | ||
| 34 | 	t = expl(0.5*absx); | ||
| 35 | 	return h*t*t; | ||
| 36 | } | ||
| 37 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 38 | // TODO: broken implementation to make things compile | ||
| 39 | long double sinhl(long double x) | ||
| 40 | { | ||
| 41 | 	return sinh(x); | ||
| 42 | } | ||
| 43 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/sinl.c created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double sinl(long double x) | ||
| 5 | { | ||
| 6 | 	return sin(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double sinl(long double x) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	unsigned n; | ||
| 13 | 	long double y[2], hi, lo; | ||
| 14 | |||
| 15 | 	u.i.se &= 0x7fff; | ||
| 16 | 	if (u.i.se == 0x7fff) | ||
| 17 | 		return x - x; | ||
| 18 | 	if (u.f < M_PI_4) { | ||
| 19 | 		if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) { | ||
| 20 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 21 | 			FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f); | ||
| 22 | 			return x; | ||
| 23 | 		} | ||
| 24 | 		return __sinl(x, 0.0, 0); | ||
| 25 | 	} | ||
| 26 | 	n = __rem_pio2l(x, y); | ||
| 27 | 	hi = y[0]; | ||
| 28 | 	lo = y[1]; | ||
| 29 | 	switch (n & 3) { | ||
| 30 | 	case 0: | ||
| 31 | 		return __sinl(hi, lo, 1); | ||
| 32 | 	case 1: | ||
| 33 | 		return __cosl(hi, lo); | ||
| 34 | 	case 2: | ||
| 35 | 		return -__sinl(hi, lo, 1); | ||
| 36 | 	case 3: | ||
| 37 | 	default: | ||
| 38 | 		return -__cosl(hi, lo); | ||
| 39 | 	} | ||
| 40 | } | ||
| 41 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/sqrt.c created+158| ... | @@ -0,0 +1,158 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include "libm.h" | ||
| 4 | #include "sqrt_data.h" | ||
| 5 | |||
| 6 | #define FENV_SUPPORT 1 | ||
| 7 | |||
| 8 | /* returns a*b*2^-32 - e, with error 0 <= e < 1. */ | ||
| 9 | static inline uint32_t mul32(uint32_t a, uint32_t b) | ||
| 10 | { | ||
| 11 | 	return (uint64_t)a*b >> 32; | ||
| 12 | } | ||
| 13 | |||
| 14 | /* returns a*b*2^-64 - e, with error 0 <= e < 3. */ | ||
| 15 | static inline uint64_t mul64(uint64_t a, uint64_t b) | ||
| 16 | { | ||
| 17 | 	uint64_t ahi = a>>32; | ||
| 18 | 	uint64_t alo = a&0xffffffff; | ||
| 19 | 	uint64_t bhi = b>>32; | ||
| 20 | 	uint64_t blo = b&0xffffffff; | ||
| 21 | 	return ahi*bhi + (ahi*blo >> 32) + (alo*bhi >> 32); | ||
| 22 | } | ||
| 23 | |||
| 24 | double sqrt(double x) | ||
| 25 | { | ||
| 26 | 	uint64_t ix, top, m; | ||
| 27 | |||
| 28 | 	/* special case handling. */ | ||
| 29 | 	ix = asuint64(x); | ||
| 30 | 	top = ix >> 52; | ||
| 31 | 	if (predict_false(top - 0x001 >= 0x7ff - 0x001)) { | ||
| 32 | 		/* x < 0x1p-1022 or inf or nan. */ | ||
| 33 | 		if (ix * 2 == 0) | ||
| 34 | 			return x; | ||
| 35 | 		if (ix == 0x7ff0000000000000) | ||
| 36 | 			return x; | ||
| 37 | 		if (ix > 0x7ff0000000000000) | ||
| 38 | 			return __math_invalid(x); | ||
| 39 | 		/* x is subnormal, normalize it. */ | ||
| 40 | 		ix = asuint64(x * 0x1p52); | ||
| 41 | 		top = ix >> 52; | ||
| 42 | 		top -= 52; | ||
| 43 | 	} | ||
| 44 | |||
| 45 | 	/* argument reduction: | ||
| 46 | 	 x = 4^e m; with integer e, and m in [1, 4) | ||
| 47 | 	 m: fixed point representation [2.62] | ||
| 48 | 	 2^e is the exponent part of the result. */ | ||
| 49 | 	int even = top & 1; | ||
| 50 | 	m = (ix << 11) | 0x8000000000000000; | ||
| 51 | 	if (even) m >>= 1; | ||
| 52 | 	top = (top + 0x3ff) >> 1; | ||
| 53 | |||
| 54 | 	/* approximate r ~ 1/sqrt(m) and s ~ sqrt(m) when m in [1,4) | ||
| 55 | |||
| 56 | 	 initial estimate: | ||
| 57 | 	 7bit table lookup (1bit exponent and 6bit significand). | ||
| 58 | |||
| 59 | 	 iterative approximation: | ||
| 60 | 	 using 2 goldschmidt iterations with 32bit int arithmetics | ||
| 61 | 	 and a final iteration with 64bit int arithmetics. | ||
| 62 | |||
| 63 | 	 details: | ||
| 64 | |||
| 65 | 	 the relative error (e = r0 sqrt(m)-1) of a linear estimate | ||
| 66 | 	 (r0 = a m + b) is |e| < 0.085955 ~ 0x1.6p-4 at best, | ||
| 67 | 	 a table lookup is faster and needs one less iteration | ||
| 68 | 	 6 bit lookup table (128b) gives |e| < 0x1.f9p-8 | ||
| 69 | 	 7 bit lookup table (256b) gives |e| < 0x1.fdp-9 | ||
| 70 | 	 for single and double prec 6bit is enough but for quad | ||
| 71 | 	 prec 7bit is needed (or modified iterations). to avoid | ||
| 72 | 	 one more iteration >=13bit table would be needed (16k). | ||
| 73 | |||
| 74 | 	 a newton-raphson iteration for r is | ||
| 75 | 	 w = r*r | ||
| 76 | 	 u = 3 - m*w | ||
| 77 | 	 r = r*u/2 | ||
| 78 | 	 can use a goldschmidt iteration for s at the end or | ||
| 79 | 	 s = m*r | ||
| 80 | |||
| 81 | 	 first goldschmidt iteration is | ||
| 82 | 	 s = m*r | ||
| 83 | 	 u = 3 - s*r | ||
| 84 | 	 r = r*u/2 | ||
| 85 | 	 s = s*u/2 | ||
| 86 | 	 next goldschmidt iteration is | ||
| 87 | 	 u = 3 - s*r | ||
| 88 | 	 r = r*u/2 | ||
| 89 | 	 s = s*u/2 | ||
| 90 | 	 and at the end r is not computed only s. | ||
| 91 | |||
| 92 | 	 they use the same amount of operations and converge at the | ||
| 93 | 	 same quadratic rate, i.e. if | ||
| 94 | 	 r1 sqrt(m) - 1 = e, then | ||
| 95 | 	 r2 sqrt(m) - 1 = -3/2 e^2 - 1/2 e^3 | ||
| 96 | 	 the advantage of goldschmidt is that the mul for s and r | ||
| 97 | 	 are independent (computed in parallel), however it is not | ||
| 98 | 	 "self synchronizing": it only uses the input m in the | ||
| 99 | 	 first iteration so rounding errors accumulate. at the end | ||
| 100 | 	 or when switching to larger precision arithmetics rounding | ||
| 101 | 	 errors dominate so the first iteration should be used. | ||
| 102 | |||
| 103 | 	 the fixed point representations are | ||
| 104 | 	 m: 2.30 r: 0.32, s: 2.30, d: 2.30, u: 2.30, three: 2.30 | ||
| 105 | 	 and after switching to 64 bit | ||
| 106 | 	 m: 2.62 r: 0.64, s: 2.62, d: 2.62, u: 2.62, three: 2.62 */ | ||
| 107 | |||
| 108 | 	static const uint64_t three = 0xc0000000; | ||
| 109 | 	uint64_t r, s, d, u, i; | ||
| 110 | |||
| 111 | 	i = (ix >> 46) % 128; | ||
| 112 | 	r = (uint32_t)__rsqrt_tab[i] << 16; | ||
| 113 | 	/* |r sqrt(m) - 1| < 0x1.fdp-9 */ | ||
| 114 | 	s = mul32(m>>32, r); | ||
| 115 | 	/* |s/sqrt(m) - 1| < 0x1.fdp-9 */ | ||
| 116 | 	d = mul32(s, r); | ||
| 117 | 	u = three - d; | ||
| 118 | 	r = mul32(r, u) << 1; | ||
| 119 | 	/* |r sqrt(m) - 1| < 0x1.7bp-16 */ | ||
| 120 | 	s = mul32(s, u) << 1; | ||
| 121 | 	/* |s/sqrt(m) - 1| < 0x1.7bp-16 */ | ||
| 122 | 	d = mul32(s, r); | ||
| 123 | 	u = three - d; | ||
| 124 | 	r = mul32(r, u) << 1; | ||
| 125 | 	/* |r sqrt(m) - 1| < 0x1.3704p-29 (measured worst-case) */ | ||
| 126 | 	r = r << 32; | ||
| 127 | 	s = mul64(m, r); | ||
| 128 | 	d = mul64(s, r); | ||
| 129 | 	u = (three<<32) - d; | ||
| 130 | 	s = mul64(s, u); /* repr: 3.61 */ | ||
| 131 | 	/* -0x1p-57 < s - sqrt(m) < 0x1.8001p-61 */ | ||
| 132 | 	s = (s - 2) >> 9; /* repr: 12.52 */ | ||
| 133 | 	/* -0x1.09p-52 < s - sqrt(m) < -0x1.fffcp-63 */ | ||
| 134 | |||
| 135 | 	/* s < sqrt(m) < s + 0x1.09p-52, | ||
| 136 | 	 compute nearest rounded result: | ||
| 137 | 	 the nearest result to 52 bits is either s or s+0x1p-52, | ||
| 138 | 	 we can decide by comparing (2^52 s + 0.5)^2 to 2^104 m. */ | ||
| 139 | 	uint64_t d0, d1, d2; | ||
| 140 | 	double y, t; | ||
| 141 | 	d0 = (m << 42) - s*s; | ||
| 142 | 	d1 = s - d0; | ||
| 143 | 	d2 = d1 + s + 1; | ||
| 144 | 	s += d1 >> 63; | ||
| 145 | 	s &= 0x000fffffffffffff; | ||
| 146 | 	s |= top << 52; | ||
| 147 | 	y = asdouble(s); | ||
| 148 | 	if (FENV_SUPPORT) { | ||
| 149 | 		/* handle rounding modes and inexact exception: | ||
| 150 | 		 only (s+1)^2 == 2^42 m case is exact otherwise | ||
| 151 | 		 add a tiny value to cause the fenv effects. */ | ||
| 152 | 		uint64_t tiny = predict_false(d2==0) ? 0 : 0x0010000000000000; | ||
| 153 | 		tiny |= (d1^d2) & 0x8000000000000000; | ||
| 154 | 		t = asdouble(tiny); | ||
| 155 | 		y = eval_as_double(y + t); | ||
| 156 | 	} | ||
| 157 | 	return y; | ||
| 158 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sqrt_data.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include "sqrt_data.h" | ||
| 2 | const uint16_t __rsqrt_tab[128] = { | ||
| 3 | 0xb451,0xb2f0,0xb196,0xb044,0xaef9,0xadb6,0xac79,0xab43, | ||
| 4 | 0xaa14,0xa8eb,0xa7c8,0xa6aa,0xa592,0xa480,0xa373,0xa26b, | ||
| 5 | 0xa168,0xa06a,0x9f70,0x9e7b,0x9d8a,0x9c9d,0x9bb5,0x9ad1, | ||
| 6 | 0x99f0,0x9913,0x983a,0x9765,0x9693,0x95c4,0x94f8,0x9430, | ||
| 7 | 0x936b,0x92a9,0x91ea,0x912e,0x9075,0x8fbe,0x8f0a,0x8e59, | ||
| 8 | 0x8daa,0x8cfe,0x8c54,0x8bac,0x8b07,0x8a64,0x89c4,0x8925, | ||
| 9 | 0x8889,0x87ee,0x8756,0x86c0,0x862b,0x8599,0x8508,0x8479, | ||
| 10 | 0x83ec,0x8361,0x82d8,0x8250,0x81c9,0x8145,0x80c2,0x8040, | ||
| 11 | 0xff02,0xfd0e,0xfb25,0xf947,0xf773,0xf5aa,0xf3ea,0xf234, | ||
| 12 | 0xf087,0xeee3,0xed47,0xebb3,0xea27,0xe8a3,0xe727,0xe5b2, | ||
| 13 | 0xe443,0xe2dc,0xe17a,0xe020,0xdecb,0xdd7d,0xdc34,0xdaf1, | ||
| 14 | 0xd9b3,0xd87b,0xd748,0xd61a,0xd4f1,0xd3cd,0xd2ad,0xd192, | ||
| 15 | 0xd07b,0xcf69,0xce5b,0xcd51,0xcc4a,0xcb48,0xca4a,0xc94f, | ||
| 16 | 0xc858,0xc764,0xc674,0xc587,0xc49d,0xc3b7,0xc2d4,0xc1f4, | ||
| 17 | 0xc116,0xc03c,0xbf65,0xbe90,0xbdbe,0xbcef,0xbc23,0xbb59, | ||
| 18 | 0xba91,0xb9cc,0xb90a,0xb84a,0xb78c,0xb6d0,0xb617,0xb560, | ||
| 19 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/math/sqrt_data.h created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #ifndef _SQRT_DATA_H | ||
| 2 | #define _SQRT_DATA_H | ||
| 3 | |||
| 4 | #include <features.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | |||
| 7 | /* if x in [1,2): i = (int)(64*x); | ||
| 8 | if x in [2,4): i = (int)(32*x-64); | ||
| 9 | __rsqrt_tab[i]*2^-16 is estimating 1/sqrt(x) with small relative error: | ||
| 10 | |__rsqrt_tab[i]*0x1p-16*sqrt(x) - 1| < -0x1.fdp-9 < 2^-8 */ | ||
| 11 | extern hidden const uint16_t __rsqrt_tab[128]; | ||
| 12 | |||
| 13 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/sqrtf.c created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include "libm.h" | ||
| 4 | #include "sqrt_data.h" | ||
| 5 | |||
| 6 | #define FENV_SUPPORT 1 | ||
| 7 | |||
| 8 | static inline uint32_t mul32(uint32_t a, uint32_t b) | ||
| 9 | { | ||
| 10 | 	return (uint64_t)a*b >> 32; | ||
| 11 | } | ||
| 12 | |||
| 13 | /* see sqrt.c for more detailed comments. */ | ||
| 14 | |||
| 15 | float sqrtf(float x) | ||
| 16 | { | ||
| 17 | 	uint32_t ix, m, m1, m0, even, ey; | ||
| 18 | |||
| 19 | 	ix = asuint(x); | ||
| 20 | 	if (predict_false(ix - 0x00800000 >= 0x7f800000 - 0x00800000)) { | ||
| 21 | 		/* x < 0x1p-126 or inf or nan. */ | ||
| 22 | 		if (ix * 2 == 0) | ||
| 23 | 			return x; | ||
| 24 | 		if (ix == 0x7f800000) | ||
| 25 | 			return x; | ||
| 26 | 		if (ix > 0x7f800000) | ||
| 27 | 			return __math_invalidf(x); | ||
| 28 | 		/* x is subnormal, normalize it. */ | ||
| 29 | 		ix = asuint(x * 0x1p23f); | ||
| 30 | 		ix -= 23 << 23; | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	/* x = 4^e m; with int e and m in [1, 4). */ | ||
| 34 | 	even = ix & 0x00800000; | ||
| 35 | 	m1 = (ix << 8) | 0x80000000; | ||
| 36 | 	m0 = (ix << 7) & 0x7fffffff; | ||
| 37 | 	m = even ? m0 : m1; | ||
| 38 | |||
| 39 | 	/* 2^e is the exponent part of the return value. */ | ||
| 40 | 	ey = ix >> 1; | ||
| 41 | 	ey += 0x3f800000 >> 1; | ||
| 42 | 	ey &= 0x7f800000; | ||
| 43 | |||
| 44 | 	/* compute r ~ 1/sqrt(m), s ~ sqrt(m) with 2 goldschmidt iterations. */ | ||
| 45 | 	static const uint32_t three = 0xc0000000; | ||
| 46 | 	uint32_t r, s, d, u, i; | ||
| 47 | 	i = (ix >> 17) % 128; | ||
| 48 | 	r = (uint32_t)__rsqrt_tab[i] << 16; | ||
| 49 | 	/* |r*sqrt(m) - 1| < 0x1p-8 */ | ||
| 50 | 	s = mul32(m, r); | ||
| 51 | 	/* |s/sqrt(m) - 1| < 0x1p-8 */ | ||
| 52 | 	d = mul32(s, r); | ||
| 53 | 	u = three - d; | ||
| 54 | 	r = mul32(r, u) << 1; | ||
| 55 | 	/* |r*sqrt(m) - 1| < 0x1.7bp-16 */ | ||
| 56 | 	s = mul32(s, u) << 1; | ||
| 57 | 	/* |s/sqrt(m) - 1| < 0x1.7bp-16 */ | ||
| 58 | 	d = mul32(s, r); | ||
| 59 | 	u = three - d; | ||
| 60 | 	s = mul32(s, u); | ||
| 61 | 	/* -0x1.03p-28 < s/sqrt(m) - 1 < 0x1.fp-31 */ | ||
| 62 | 	s = (s - 1)>>6; | ||
| 63 | 	/* s < sqrt(m) < s + 0x1.08p-23 */ | ||
| 64 | |||
| 65 | 	/* compute nearest rounded result. */ | ||
| 66 | 	uint32_t d0, d1, d2; | ||
| 67 | 	float y, t; | ||
| 68 | 	d0 = (m << 16) - s*s; | ||
| 69 | 	d1 = s - d0; | ||
| 70 | 	d2 = d1 + s + 1; | ||
| 71 | 	s += d1 >> 31; | ||
| 72 | 	s &= 0x007fffff; | ||
| 73 | 	s |= ey; | ||
| 74 | 	y = asfloat(s); | ||
| 75 | 	if (FENV_SUPPORT) { | ||
| 76 | 		/* handle rounding and inexact exception. */ | ||
| 77 | 		uint32_t tiny = predict_false(d2==0) ? 0 : 0x01000000; | ||
| 78 | 		tiny |= (d1^d2) & 0x80000000; | ||
| 79 | 		t = asfloat(tiny); | ||
| 80 | 		y = eval_as_float(y + t); | ||
| 81 | 	} | ||
| 82 | 	return y; | ||
| 83 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/sqrtl.c created+259| ... | @@ -0,0 +1,259 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <math.h> | ||
| 3 | #include <float.h> | ||
| 4 | #include "libm.h" | ||
| 5 | |||
| 6 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 7 | long double sqrtl(long double x) | ||
| 8 | { | ||
| 9 | 	return sqrt(x); | ||
| 10 | } | ||
| 11 | #elif (LDBL_MANT_DIG == 113 || LDBL_MANT_DIG == 64) && LDBL_MAX_EXP == 16384 | ||
| 12 | #include "sqrt_data.h" | ||
| 13 | |||
| 14 | #define FENV_SUPPORT 1 | ||
| 15 | |||
| 16 | typedef struct { | ||
| 17 | 	uint64_t hi; | ||
| 18 | 	uint64_t lo; | ||
| 19 | } u128; | ||
| 20 | |||
| 21 | /* top: 16 bit sign+exponent, x: significand. */ | ||
| 22 | static inline long double mkldbl(uint64_t top, u128 x) | ||
| 23 | { | ||
| 24 | 	union ldshape u; | ||
| 25 | #if LDBL_MANT_DIG == 113 | ||
| 26 | 	u.i2.hi = x.hi; | ||
| 27 | 	u.i2.lo = x.lo; | ||
| 28 | 	u.i2.hi &= 0x0000ffffffffffff; | ||
| 29 | 	u.i2.hi |= top << 48; | ||
| 30 | #elif LDBL_MANT_DIG == 64 | ||
| 31 | 	u.i.se = top; | ||
| 32 | 	u.i.m = x.lo; | ||
| 33 | 	/* force the top bit on non-zero (and non-subnormal) results. */ | ||
| 34 | 	if (top & 0x7fff) | ||
| 35 | 		u.i.m |= 0x8000000000000000; | ||
| 36 | #endif | ||
| 37 | 	return u.f; | ||
| 38 | } | ||
| 39 | |||
| 40 | /* return: top 16 bit is sign+exp and following bits are the significand. */ | ||
| 41 | static inline u128 asu128(long double x) | ||
| 42 | { | ||
| 43 | 	union ldshape u = {.f=x}; | ||
| 44 | 	u128 r; | ||
| 45 | #if LDBL_MANT_DIG == 113 | ||
| 46 | 	r.hi = u.i2.hi; | ||
| 47 | 	r.lo = u.i2.lo; | ||
| 48 | #elif LDBL_MANT_DIG == 64 | ||
| 49 | 	r.lo = u.i.m<<49; | ||
| 50 | 	/* ignore the top bit: pseudo numbers are not handled. */ | ||
| 51 | 	r.hi = u.i.m>>15; | ||
| 52 | 	r.hi &= 0x0000ffffffffffff; | ||
| 53 | 	r.hi |= (uint64_t)u.i.se << 48; | ||
| 54 | #endif | ||
| 55 | 	return r; | ||
| 56 | } | ||
| 57 | |||
| 58 | /* returns a*b*2^-32 - e, with error 0 <= e < 1. */ | ||
| 59 | static inline uint32_t mul32(uint32_t a, uint32_t b) | ||
| 60 | { | ||
| 61 | 	return (uint64_t)a*b >> 32; | ||
| 62 | } | ||
| 63 | |||
| 64 | /* returns a*b*2^-64 - e, with error 0 <= e < 3. */ | ||
| 65 | static inline uint64_t mul64(uint64_t a, uint64_t b) | ||
| 66 | { | ||
| 67 | 	uint64_t ahi = a>>32; | ||
| 68 | 	uint64_t alo = a&0xffffffff; | ||
| 69 | 	uint64_t bhi = b>>32; | ||
| 70 | 	uint64_t blo = b&0xffffffff; | ||
| 71 | 	return ahi*bhi + (ahi*blo >> 32) + (alo*bhi >> 32); | ||
| 72 | } | ||
| 73 | |||
| 74 | static inline u128 add64(u128 a, uint64_t b) | ||
| 75 | { | ||
| 76 | 	u128 r; | ||
| 77 | 	r.lo = a.lo + b; | ||
| 78 | 	r.hi = a.hi; | ||
| 79 | 	if (r.lo < a.lo) | ||
| 80 | 		r.hi++; | ||
| 81 | 	return r; | ||
| 82 | } | ||
| 83 | |||
| 84 | static inline u128 add128(u128 a, u128 b) | ||
| 85 | { | ||
| 86 | 	u128 r; | ||
| 87 | 	r.lo = a.lo + b.lo; | ||
| 88 | 	r.hi = a.hi + b.hi; | ||
| 89 | 	if (r.lo < a.lo) | ||
| 90 | 		r.hi++; | ||
| 91 | 	return r; | ||
| 92 | } | ||
| 93 | |||
| 94 | static inline u128 sub64(u128 a, uint64_t b) | ||
| 95 | { | ||
| 96 | 	u128 r; | ||
| 97 | 	r.lo = a.lo - b; | ||
| 98 | 	r.hi = a.hi; | ||
| 99 | 	if (a.lo < b) | ||
| 100 | 		r.hi--; | ||
| 101 | 	return r; | ||
| 102 | } | ||
| 103 | |||
| 104 | static inline u128 sub128(u128 a, u128 b) | ||
| 105 | { | ||
| 106 | 	u128 r; | ||
| 107 | 	r.lo = a.lo - b.lo; | ||
| 108 | 	r.hi = a.hi - b.hi; | ||
| 109 | 	if (a.lo < b.lo) | ||
| 110 | 		r.hi--; | ||
| 111 | 	return r; | ||
| 112 | } | ||
| 113 | |||
| 114 | /* a<<n, 0 <= n <= 127 */ | ||
| 115 | static inline u128 lsh(u128 a, int n) | ||
| 116 | { | ||
| 117 | 	if (n == 0) | ||
| 118 | 		return a; | ||
| 119 | 	if (n >= 64) { | ||
| 120 | 		a.hi = a.lo<<(n-64); | ||
| 121 | 		a.lo = 0; | ||
| 122 | 	} else { | ||
| 123 | 		a.hi = (a.hi<<n) | (a.lo>>(64-n)); | ||
| 124 | 		a.lo = a.lo<<n; | ||
| 125 | 	} | ||
| 126 | 	return a; | ||
| 127 | } | ||
| 128 | |||
| 129 | /* a>>n, 0 <= n <= 127 */ | ||
| 130 | static inline u128 rsh(u128 a, int n) | ||
| 131 | { | ||
| 132 | 	if (n == 0) | ||
| 133 | 		return a; | ||
| 134 | 	if (n >= 64) { | ||
| 135 | 		a.lo = a.hi>>(n-64); | ||
| 136 | 		a.hi = 0; | ||
| 137 | 	} else { | ||
| 138 | 		a.lo = (a.lo>>n) | (a.hi<<(64-n)); | ||
| 139 | 		a.hi = a.hi>>n; | ||
| 140 | 	} | ||
| 141 | 	return a; | ||
| 142 | } | ||
| 143 | |||
| 144 | /* returns a*b exactly. */ | ||
| 145 | static inline u128 mul64_128(uint64_t a, uint64_t b) | ||
| 146 | { | ||
| 147 | 	u128 r; | ||
| 148 | 	uint64_t ahi = a>>32; | ||
| 149 | 	uint64_t alo = a&0xffffffff; | ||
| 150 | 	uint64_t bhi = b>>32; | ||
| 151 | 	uint64_t blo = b&0xffffffff; | ||
| 152 | 	uint64_t lo1 = ((ahi*blo)&0xffffffff) + ((alo*bhi)&0xffffffff) + (alo*blo>>32); | ||
| 153 | 	uint64_t lo2 = (alo*blo)&0xffffffff; | ||
| 154 | 	r.hi = ahi*bhi + (ahi*blo>>32) + (alo*bhi>>32) + (lo1>>32); | ||
| 155 | 	r.lo = (lo1<<32) + lo2; | ||
| 156 | 	return r; | ||
| 157 | } | ||
| 158 | |||
| 159 | /* returns a*b*2^-128 - e, with error 0 <= e < 7. */ | ||
| 160 | static inline u128 mul128(u128 a, u128 b) | ||
| 161 | { | ||
| 162 | 	u128 hi = mul64_128(a.hi, b.hi); | ||
| 163 | 	uint64_t m1 = mul64(a.hi, b.lo); | ||
| 164 | 	uint64_t m2 = mul64(a.lo, b.hi); | ||
| 165 | 	return add64(add64(hi, m1), m2); | ||
| 166 | } | ||
| 167 | |||
| 168 | /* returns a*b % 2^128. */ | ||
| 169 | static inline u128 mul128_tail(u128 a, u128 b) | ||
| 170 | { | ||
| 171 | 	u128 lo = mul64_128(a.lo, b.lo); | ||
| 172 | 	lo.hi += a.hi*b.lo + a.lo*b.hi; | ||
| 173 | 	return lo; | ||
| 174 | } | ||
| 175 | |||
| 176 | |||
| 177 | /* see sqrt.c for detailed comments. */ | ||
| 178 | |||
| 179 | long double sqrtl(long double x) | ||
| 180 | { | ||
| 181 | 	u128 ix, ml; | ||
| 182 | 	uint64_t top; | ||
| 183 | |||
| 184 | 	ix = asu128(x); | ||
| 185 | 	top = ix.hi >> 48; | ||
| 186 | 	if (predict_false(top - 0x0001 >= 0x7fff - 0x0001)) { | ||
| 187 | 		/* x < 0x1p-16382 or inf or nan. */ | ||
| 188 | 		if (2*ix.hi == 0 && ix.lo == 0) | ||
| 189 | 			return x; | ||
| 190 | 		if (ix.hi == 0x7fff000000000000 && ix.lo == 0) | ||
| 191 | 			return x; | ||
| 192 | 		if (top >= 0x7fff) | ||
| 193 | 			return __math_invalidl(x); | ||
| 194 | 		/* x is subnormal, normalize it. */ | ||
| 195 | 		ix = asu128(x * 0x1p112); | ||
| 196 | 		top = ix.hi >> 48; | ||
| 197 | 		top -= 112; | ||
| 198 | 	} | ||
| 199 | |||
| 200 | 	/* x = 4^e m; with int e and m in [1, 4) */ | ||
| 201 | 	int even = top & 1; | ||
| 202 | 	ml = lsh(ix, 15); | ||
| 203 | 	ml.hi |= 0x8000000000000000; | ||
| 204 | 	if (even) ml = rsh(ml, 1); | ||
| 205 | 	top = (top + 0x3fff) >> 1; | ||
| 206 | |||
| 207 | 	/* r ~ 1/sqrt(m) */ | ||
| 208 | 	static const uint64_t three = 0xc0000000; | ||
| 209 | 	uint64_t r, s, d, u, i; | ||
| 210 | 	i = (ix.hi >> 42) % 128; | ||
| 211 | 	r = (uint32_t)__rsqrt_tab[i] << 16; | ||
| 212 | 	/* |r sqrt(m) - 1| < 0x1p-8 */ | ||
| 213 | 	s = mul32(ml.hi>>32, r); | ||
| 214 | 	d = mul32(s, r); | ||
| 215 | 	u = three - d; | ||
| 216 | 	r = mul32(u, r) << 1; | ||
| 217 | 	/* |r sqrt(m) - 1| < 0x1.7bp-16, switch to 64bit */ | ||
| 218 | 	r = r<<32; | ||
| 219 | 	s = mul64(ml.hi, r); | ||
| 220 | 	d = mul64(s, r); | ||
| 221 | 	u = (three<<32) - d; | ||
| 222 | 	r = mul64(u, r) << 1; | ||
| 223 | 	/* |r sqrt(m) - 1| < 0x1.a5p-31 */ | ||
| 224 | 	s = mul64(u, s) << 1; | ||
| 225 | 	d = mul64(s, r); | ||
| 226 | 	u = (three<<32) - d; | ||
| 227 | 	r = mul64(u, r) << 1; | ||
| 228 | 	/* |r sqrt(m) - 1| < 0x1.c001p-59, switch to 128bit */ | ||
| 229 | |||
| 230 | 	static const u128 threel = {.hi=three<<32, .lo=0}; | ||
| 231 | 	u128 rl, sl, dl, ul; | ||
| 232 | 	rl.hi = r; | ||
| 233 | 	rl.lo = 0; | ||
| 234 | 	sl = mul128(ml, rl); | ||
| 235 | 	dl = mul128(sl, rl); | ||
| 236 | 	ul = sub128(threel, dl); | ||
| 237 | 	sl = mul128(ul, sl); /* repr: 3.125 */ | ||
| 238 | 	/* -0x1p-116 < s - sqrt(m) < 0x3.8001p-125 */ | ||
| 239 | 	sl = rsh(sub64(sl, 4), 125-(LDBL_MANT_DIG-1)); | ||
| 240 | 	/* s < sqrt(m) < s + 1 ULP + tiny */ | ||
| 241 | |||
| 242 | 	long double y; | ||
| 243 | 	u128 d2, d1, d0; | ||
| 244 | 	d0 = sub128(lsh(ml, 2*(LDBL_MANT_DIG-1)-126), mul128_tail(sl,sl)); | ||
| 245 | 	d1 = sub128(sl, d0); | ||
| 246 | 	d2 = add128(add64(sl, 1), d1); | ||
| 247 | 	sl = add64(sl, d1.hi >> 63); | ||
| 248 | 	y = mkldbl(top, sl); | ||
| 249 | 	if (FENV_SUPPORT) { | ||
| 250 | 		/* handle rounding modes and inexact exception. */ | ||
| 251 | 		top = predict_false((d2.hi|d2.lo)==0) ? 0 : 1; | ||
| 252 | 		top |= ((d1.hi^d2.hi)&0x8000000000000000) >> 48; | ||
| 253 | 		y += mkldbl(top, (u128){0}); | ||
| 254 | 	} | ||
| 255 | 	return y; | ||
| 256 | } | ||
| 257 | #else | ||
| 258 | #error unsupported long double format | ||
| 259 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/tan.c created+70| ... | @@ -0,0 +1,70 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_tan.c */ | ||
| 2 | /* | ||
| 3 | * ==================================================== | ||
| 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | ||
| 5 | * | ||
| 6 | * Developed at SunPro, 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 | /* tan(x) | ||
| 13 | * Return tangent function of x. | ||
| 14 | * | ||
| 15 | * kernel function: | ||
| 16 | * __tan ... tangent function on [-pi/4,pi/4] | ||
| 17 | * __rem_pio2 ... argument reduction routine | ||
| 18 | * | ||
| 19 | * Method. | ||
| 20 | * Let S,C and T denote the sin, cos and tan respectively on | ||
| 21 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 | ||
| 22 | * in [-pi/4 , +pi/4], and let n = k mod 4. | ||
| 23 | * We have | ||
| 24 | * | ||
| 25 | * n sin(x) cos(x) tan(x) | ||
| 26 | * ---------------------------------------------------------- | ||
| 27 | * 0 S C T | ||
| 28 | * 1 C -S -1/T | ||
| 29 | * 2 -S -C T | ||
| 30 | * 3 -C S -1/T | ||
| 31 | * ---------------------------------------------------------- | ||
| 32 | * | ||
| 33 | * Special cases: | ||
| 34 | * Let trig be any of sin, cos, or tan. | ||
| 35 | * trig(+-INF) is NaN, with signals; | ||
| 36 | * trig(NaN) is that NaN; | ||
| 37 | * | ||
| 38 | * Accuracy: | ||
| 39 | * TRIG(x) returns trig(x) nearly rounded | ||
| 40 | */ | ||
| 41 | |||
| 42 | #include "libm.h" | ||
| 43 | |||
| 44 | double tan(double x) | ||
| 45 | { | ||
| 46 | 	double y[2]; | ||
| 47 | 	uint32_t ix; | ||
| 48 | 	unsigned n; | ||
| 49 | |||
| 50 | 	GET_HIGH_WORD(ix, x); | ||
| 51 | 	ix &= 0x7fffffff; | ||
| 52 | |||
| 53 | 	/* |x| ~< pi/4 */ | ||
| 54 | 	if (ix <= 0x3fe921fb) { | ||
| 55 | 		if (ix < 0x3e400000) { /* |x| < 2**-27 */ | ||
| 56 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 57 | 			FORCE_EVAL(ix < 0x00100000 ? x/0x1p120f : x+0x1p120f); | ||
| 58 | 			return x; | ||
| 59 | 		} | ||
| 60 | 		return __tan(x, 0.0, 0); | ||
| 61 | 	} | ||
| 62 | |||
| 63 | 	/* tan(Inf or NaN) is NaN */ | ||
| 64 | 	if (ix >= 0x7ff00000) | ||
| 65 | 		return x - x; | ||
| 66 | |||
| 67 | 	/* argument reduction */ | ||
| 68 | 	n = __rem_pio2(x, y); | ||
| 69 | 	return __tan(y[0], y[1], n&1); | ||
| 70 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/tanf.c created+64| ... | @@ -0,0 +1,64 @@ | ||
| 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_tanf.c */ | ||
| 2 | /* | ||
| 3 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. | ||
| 4 | * 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 | |||
| 17 | #include "libm.h" | ||
| 18 | |||
| 19 | /* Small multiples of pi/2 rounded to double precision. */ | ||
| 20 | static const double | ||
| 21 | t1pio2 = 1*M_PI_2, /* 0x3FF921FB, 0x54442D18 */ | ||
| 22 | t2pio2 = 2*M_PI_2, /* 0x400921FB, 0x54442D18 */ | ||
| 23 | t3pio2 = 3*M_PI_2, /* 0x4012D97C, 0x7F3321D2 */ | ||
| 24 | t4pio2 = 4*M_PI_2; /* 0x401921FB, 0x54442D18 */ | ||
| 25 | |||
| 26 | float tanf(float x) | ||
| 27 | { | ||
| 28 | 	double y; | ||
| 29 | 	uint32_t ix; | ||
| 30 | 	unsigned n, sign; | ||
| 31 | |||
| 32 | 	GET_FLOAT_WORD(ix, x); | ||
| 33 | 	sign = ix >> 31; | ||
| 34 | 	ix &= 0x7fffffff; | ||
| 35 | |||
| 36 | 	if (ix <= 0x3f490fda) { /* |x| ~<= pi/4 */ | ||
| 37 | 		if (ix < 0x39800000) { /* |x| < 2**-12 */ | ||
| 38 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 39 | 			FORCE_EVAL(ix < 0x00800000 ? x/0x1p120f : x+0x1p120f); | ||
| 40 | 			return x; | ||
| 41 | 		} | ||
| 42 | 		return __tandf(x, 0); | ||
| 43 | 	} | ||
| 44 | 	if (ix <= 0x407b53d1) { /* |x| ~<= 5*pi/4 */ | ||
| 45 | 		if (ix <= 0x4016cbe3) /* |x| ~<= 3pi/4 */ | ||
| 46 | 			return __tandf((sign ? x+t1pio2 : x-t1pio2), 1); | ||
| 47 | 		else | ||
| 48 | 			return __tandf((sign ? x+t2pio2 : x-t2pio2), 0); | ||
| 49 | 	} | ||
| 50 | 	if (ix <= 0x40e231d5) { /* |x| ~<= 9*pi/4 */ | ||
| 51 | 		if (ix <= 0x40afeddf) /* |x| ~<= 7*pi/4 */ | ||
| 52 | 			return __tandf((sign ? x+t3pio2 : x-t3pio2), 1); | ||
| 53 | 		else | ||
| 54 | 			return __tandf((sign ? x+t4pio2 : x-t4pio2), 0); | ||
| 55 | 	} | ||
| 56 | |||
| 57 | 	/* tan(Inf or NaN) is NaN */ | ||
| 58 | 	if (ix >= 0x7f800000) | ||
| 59 | 		return x - x; | ||
| 60 | |||
| 61 | 	/* argument reduction */ | ||
| 62 | 	n = __rem_pio2f(x, &y); | ||
| 63 | 	return __tandf(y, n&1); | ||
| 64 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/tanh.c created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | /* tanh(x) = (exp(x) - exp(-x))/(exp(x) + exp(-x)) | ||
| 4 | * = (exp(2*x) - 1)/(exp(2*x) - 1 + 2) | ||
| 5 | * = (1 - exp(-2*x))/(exp(-2*x) - 1 + 2) | ||
| 6 | */ | ||
| 7 | double tanh(double x) | ||
| 8 | { | ||
| 9 | 	union {double f; uint64_t i;} u = {.f = x}; | ||
| 10 | 	uint32_t w; | ||
| 11 | 	int sign; | ||
| 12 | 	double_t t; | ||
| 13 | |||
| 14 | 	/* x = |x| */ | ||
| 15 | 	sign = u.i >> 63; | ||
| 16 | 	u.i &= (uint64_t)-1/2; | ||
| 17 | 	x = u.f; | ||
| 18 | 	w = u.i >> 32; | ||
| 19 | |||
| 20 | 	if (w > 0x3fe193ea) { | ||
| 21 | 		/* |x| > log(3)/2 ~= 0.5493 or nan */ | ||
| 22 | 		if (w > 0x40340000) { | ||
| 23 | 			/* |x| > 20 or nan */ | ||
| 24 | 			/* note: this branch avoids raising overflow */ | ||
| 25 | 			t = 1 - 0/x; | ||
| 26 | 		} else { | ||
| 27 | 			t = expm1(2*x); | ||
| 28 | 			t = 1 - 2/(t+2); | ||
| 29 | 		} | ||
| 30 | 	} else if (w > 0x3fd058ae) { | ||
| 31 | 		/* |x| > log(5/3)/2 ~= 0.2554 */ | ||
| 32 | 		t = expm1(2*x); | ||
| 33 | 		t = t/(t+2); | ||
| 34 | 	} else if (w >= 0x00100000) { | ||
| 35 | 		/* |x| >= 0x1p-1022, up to 2ulp error in [0.1,0.2554] */ | ||
| 36 | 		t = expm1(-2*x); | ||
| 37 | 		t = -t/(t+2); | ||
| 38 | 	} else { | ||
| 39 | 		/* |x| is subnormal */ | ||
| 40 | 		/* note: the branch above would not raise underflow in [0x1p-1023,0x1p-1022) */ | ||
| 41 | 		FORCE_EVAL((float)x); | ||
| 42 | 		t = x; | ||
| 43 | 	} | ||
| 44 | 	return sign ? -t : t; | ||
| 45 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/tanhf.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float tanhf(float x) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {.f = x}; | ||
| 6 | 	uint32_t w; | ||
| 7 | 	int sign; | ||
| 8 | 	float t; | ||
| 9 | |||
| 10 | 	/* x = |x| */ | ||
| 11 | 	sign = u.i >> 31; | ||
| 12 | 	u.i &= 0x7fffffff; | ||
| 13 | 	x = u.f; | ||
| 14 | 	w = u.i; | ||
| 15 | |||
| 16 | 	if (w > 0x3f0c9f54) { | ||
| 17 | 		/* |x| > log(3)/2 ~= 0.5493 or nan */ | ||
| 18 | 		if (w > 0x41200000) { | ||
| 19 | 			/* |x| > 10 */ | ||
| 20 | 			t = 1 + 0/x; | ||
| 21 | 		} else { | ||
| 22 | 			t = expm1f(2*x); | ||
| 23 | 			t = 1 - 2/(t+2); | ||
| 24 | 		} | ||
| 25 | 	} else if (w > 0x3e82c578) { | ||
| 26 | 		/* |x| > log(5/3)/2 ~= 0.2554 */ | ||
| 27 | 		t = expm1f(2*x); | ||
| 28 | 		t = t/(t+2); | ||
| 29 | 	} else if (w >= 0x00800000) { | ||
| 30 | 		/* |x| >= 0x1p-126 */ | ||
| 31 | 		t = expm1f(-2*x); | ||
| 32 | 		t = -t/(t+2); | ||
| 33 | 	} else { | ||
| 34 | 		/* |x| is subnormal */ | ||
| 35 | 		FORCE_EVAL(x*x); | ||
| 36 | 		t = x; | ||
| 37 | 	} | ||
| 38 | 	return sign ? -t : t; | ||
| 39 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/tanhl.c created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double tanhl(long double x) | ||
| 5 | { | ||
| 6 | 	return tanh(x); | ||
| 7 | } | ||
| 8 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 9 | long double tanhl(long double x) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	unsigned ex = u.i.se & 0x7fff; | ||
| 13 | 	unsigned sign = u.i.se & 0x8000; | ||
| 14 | 	uint32_t w; | ||
| 15 | 	long double t; | ||
| 16 | |||
| 17 | 	/* x = |x| */ | ||
| 18 | 	u.i.se = ex; | ||
| 19 | 	x = u.f; | ||
| 20 | 	w = u.i.m >> 32; | ||
| 21 | |||
| 22 | 	if (ex > 0x3ffe || (ex == 0x3ffe && w > 0x8c9f53d5)) { | ||
| 23 | 		/* |x| > log(3)/2 ~= 0.5493 or nan */ | ||
| 24 | 		if (ex >= 0x3fff+5) { | ||
| 25 | 			/* |x| >= 32 */ | ||
| 26 | 			t = 1 + 0/(x + 0x1p-120f); | ||
| 27 | 		} else { | ||
| 28 | 			t = expm1l(2*x); | ||
| 29 | 			t = 1 - 2/(t+2); | ||
| 30 | 		} | ||
| 31 | 	} else if (ex > 0x3ffd || (ex == 0x3ffd && w > 0x82c577d4)) { | ||
| 32 | 		/* |x| > log(5/3)/2 ~= 0.2554 */ | ||
| 33 | 		t = expm1l(2*x); | ||
| 34 | 		t = t/(t+2); | ||
| 35 | 	} else { | ||
| 36 | 		/* |x| is small */ | ||
| 37 | 		t = expm1l(-2*x); | ||
| 38 | 		t = -t/(t+2); | ||
| 39 | 	} | ||
| 40 | 	return sign ? -t : t; | ||
| 41 | } | ||
| 42 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 43 | // TODO: broken implementation to make things compile | ||
| 44 | long double tanhl(long double x) | ||
| 45 | { | ||
| 46 | 	return tanh(x); | ||
| 47 | } | ||
| 48 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/tanl.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double tanl(long double x) | ||
| 5 | { | ||
| 6 | 	return tan(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | long double tanl(long double x) | ||
| 10 | { | ||
| 11 | 	union ldshape u = {x}; | ||
| 12 | 	long double y[2]; | ||
| 13 | 	unsigned n; | ||
| 14 | |||
| 15 | 	u.i.se &= 0x7fff; | ||
| 16 | 	if (u.i.se == 0x7fff) | ||
| 17 | 		return x - x; | ||
| 18 | 	if (u.f < M_PI_4) { | ||
| 19 | 		if (u.i.se < 0x3fff - LDBL_MANT_DIG/2) { | ||
| 20 | 			/* raise inexact if x!=0 and underflow if subnormal */ | ||
| 21 | 			FORCE_EVAL(u.i.se == 0 ? x*0x1p-120f : x+0x1p120f); | ||
| 22 | 			return x; | ||
| 23 | 		} | ||
| 24 | 		return __tanl(x, 0, 0); | ||
| 25 | 	} | ||
| 26 | 	n = __rem_pio2l(x, y); | ||
| 27 | 	return __tanl(y[0], y[1], n&1); | ||
| 28 | } | ||
| 29 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/tgamma.c created+222| ... | @@ -0,0 +1,222 @@ | ||
| 1 | /* | ||
| 2 | "A Precision Approximation of the Gamma Function" - Cornelius Lanczos (1964) | ||
| 3 | "Lanczos Implementation of the Gamma Function" - Paul Godfrey (2001) | ||
| 4 | "An Analysis of the Lanczos Gamma Approximation" - Glendon Ralph Pugh (2004) | ||
| 5 | |||
| 6 | approximation method: | ||
| 7 | |||
| 8 | (x - 0.5) S(x) | ||
| 9 | Gamma(x) = (x + g - 0.5) * ---------------- | ||
| 10 | exp(x + g - 0.5) | ||
| 11 | |||
| 12 | with | ||
| 13 | a1 a2 a3 aN | ||
| 14 | S(x) ~= [ a0 + ----- + ----- + ----- + ... + ----- ] | ||
| 15 | x + 1 x + 2 x + 3 x + N | ||
| 16 | |||
| 17 | with a0, a1, a2, a3,.. aN constants which depend on g. | ||
| 18 | |||
| 19 | for x < 0 the following reflection formula is used: | ||
| 20 | |||
| 21 | Gamma(x)*Gamma(-x) = -pi/(x sin(pi x)) | ||
| 22 | |||
| 23 | most ideas and constants are from boost and python | ||
| 24 | */ | ||
| 25 | #include "libm.h" | ||
| 26 | |||
| 27 | static const double pi = 3.141592653589793238462643383279502884; | ||
| 28 | |||
| 29 | /* sin(pi x) with x > 0x1p-100, if sin(pi*x)==0 the sign is arbitrary */ | ||
| 30 | static double sinpi(double x) | ||
| 31 | { | ||
| 32 | 	int n; | ||
| 33 | |||
| 34 | 	/* argument reduction: x = |x| mod 2 */ | ||
| 35 | 	/* spurious inexact when x is odd int */ | ||
| 36 | 	x = x * 0.5; | ||
| 37 | 	x = 2 * (x - floor(x)); | ||
| 38 | |||
| 39 | 	/* reduce x into [-.25,.25] */ | ||
| 40 | 	n = 4 * x; | ||
| 41 | 	n = (n+1)/2; | ||
| 42 | 	x -= n * 0.5; | ||
| 43 | |||
| 44 | 	x *= pi; | ||
| 45 | 	switch (n) { | ||
| 46 | 	default: /* case 4 */ | ||
| 47 | 	case 0: | ||
| 48 | 		return __sin(x, 0, 0); | ||
| 49 | 	case 1: | ||
| 50 | 		return __cos(x, 0); | ||
| 51 | 	case 2: | ||
| 52 | 		return __sin(-x, 0, 0); | ||
| 53 | 	case 3: | ||
| 54 | 		return -__cos(x, 0); | ||
| 55 | 	} | ||
| 56 | } | ||
| 57 | |||
| 58 | #define N 12 | ||
| 59 | //static const double g = 6.024680040776729583740234375; | ||
| 60 | static const double gmhalf = 5.524680040776729583740234375; | ||
| 61 | static const double Snum[N+1] = { | ||
| 62 | 	23531376880.410759688572007674451636754734846804940, | ||
| 63 | 	42919803642.649098768957899047001988850926355848959, | ||
| 64 | 	35711959237.355668049440185451547166705960488635843, | ||
| 65 | 	17921034426.037209699919755754458931112671403265390, | ||
| 66 | 	6039542586.3520280050642916443072979210699388420708, | ||
| 67 | 	1439720407.3117216736632230727949123939715485786772, | ||
| 68 | 	248874557.86205415651146038641322942321632125127801, | ||
| 69 | 	31426415.585400194380614231628318205362874684987640, | ||
| 70 | 	2876370.6289353724412254090516208496135991145378768, | ||
| 71 | 	186056.26539522349504029498971604569928220784236328, | ||
| 72 | 	8071.6720023658162106380029022722506138218516325024, | ||
| 73 | 	210.82427775157934587250973392071336271166969580291, | ||
| 74 | 	2.5066282746310002701649081771338373386264310793408, | ||
| 75 | }; | ||
| 76 | static const double Sden[N+1] = { | ||
| 77 | 	0, 39916800, 120543840, 150917976, 105258076, 45995730, 13339535, | ||
| 78 | 	2637558, 357423, 32670, 1925, 66, 1, | ||
| 79 | }; | ||
| 80 | /* n! for small integer n */ | ||
| 81 | static const double fact[] = { | ||
| 82 | 	1, 1, 2, 6, 24, 120, 720, 5040.0, 40320.0, 362880.0, 3628800.0, 39916800.0, | ||
| 83 | 	479001600.0, 6227020800.0, 87178291200.0, 1307674368000.0, 20922789888000.0, | ||
| 84 | 	355687428096000.0, 6402373705728000.0, 121645100408832000.0, | ||
| 85 | 	2432902008176640000.0, 51090942171709440000.0, 1124000727777607680000.0, | ||
| 86 | }; | ||
| 87 | |||
| 88 | /* S(x) rational function for positive x */ | ||
| 89 | static double S(double x) | ||
| 90 | { | ||
| 91 | 	double_t num = 0, den = 0; | ||
| 92 | 	int i; | ||
| 93 | |||
| 94 | 	/* to avoid overflow handle large x differently */ | ||
| 95 | 	if (x < 8) | ||
| 96 | 		for (i = N; i >= 0; i--) { | ||
| 97 | 			num = num * x + Snum[i]; | ||
| 98 | 			den = den * x + Sden[i]; | ||
| 99 | 		} | ||
| 100 | 	else | ||
| 101 | 		for (i = 0; i <= N; i++) { | ||
| 102 | 			num = num / x + Snum[i]; | ||
| 103 | 			den = den / x + Sden[i]; | ||
| 104 | 		} | ||
| 105 | 	return num/den; | ||
| 106 | } | ||
| 107 | |||
| 108 | double tgamma(double x) | ||
| 109 | { | ||
| 110 | 	union {double f; uint64_t i;} u = {x}; | ||
| 111 | 	double absx, y; | ||
| 112 | 	double_t dy, z, r; | ||
| 113 | 	uint32_t ix = u.i>>32 & 0x7fffffff; | ||
| 114 | 	int sign = u.i>>63; | ||
| 115 | |||
| 116 | 	/* special cases */ | ||
| 117 | 	if (ix >= 0x7ff00000) | ||
| 118 | 		/* tgamma(nan)=nan, tgamma(inf)=inf, tgamma(-inf)=nan with invalid */ | ||
| 119 | 		return x + INFINITY; | ||
| 120 | 	if (ix < (0x3ff-54)<<20) | ||
| 121 | 		/* |x| < 2^-54: tgamma(x) ~ 1/x, +-0 raises div-by-zero */ | ||
| 122 | 		return 1/x; | ||
| 123 | |||
| 124 | 	/* integer arguments */ | ||
| 125 | 	/* raise inexact when non-integer */ | ||
| 126 | 	if (x == floor(x)) { | ||
| 127 | 		if (sign) | ||
| 128 | 			return 0/0.0; | ||
| 129 | 		if (x <= sizeof fact/sizeof *fact) | ||
| 130 | 			return fact[(int)x - 1]; | ||
| 131 | 	} | ||
| 132 | |||
| 133 | 	/* x >= 172: tgamma(x)=inf with overflow */ | ||
| 134 | 	/* x =< -184: tgamma(x)=+-0 with underflow */ | ||
| 135 | 	if (ix >= 0x40670000) { /* |x| >= 184 */ | ||
| 136 | 		if (sign) { | ||
| 137 | 			FORCE_EVAL((float)(0x1p-126/x)); | ||
| 138 | 			if (floor(x) * 0.5 == floor(x * 0.5)) | ||
| 139 | 				return 0; | ||
| 140 | 			return -0.0; | ||
| 141 | 		} | ||
| 142 | 		x *= 0x1p1023; | ||
| 143 | 		return x; | ||
| 144 | 	} | ||
| 145 | |||
| 146 | 	absx = sign ? -x : x; | ||
| 147 | |||
| 148 | 	/* handle the error of x + g - 0.5 */ | ||
| 149 | 	y = absx + gmhalf; | ||
| 150 | 	if (absx > gmhalf) { | ||
| 151 | 		dy = y - absx; | ||
| 152 | 		dy -= gmhalf; | ||
| 153 | 	} else { | ||
| 154 | 		dy = y - gmhalf; | ||
| 155 | 		dy -= absx; | ||
| 156 | 	} | ||
| 157 | |||
| 158 | 	z = absx - 0.5; | ||
| 159 | 	r = S(absx) * exp(-y); | ||
| 160 | 	if (x < 0) { | ||
| 161 | 		/* reflection formula for negative x */ | ||
| 162 | 		/* sinpi(absx) is not 0, integers are already handled */ | ||
| 163 | 		r = -pi / (sinpi(absx) * absx * r); | ||
| 164 | 		dy = -dy; | ||
| 165 | 		z = -z; | ||
| 166 | 	} | ||
| 167 | 	r += dy * (gmhalf+0.5) * r / y; | ||
| 168 | 	z = pow(y, 0.5*z); | ||
| 169 | 	y = r * z * z; | ||
| 170 | 	return y; | ||
| 171 | } | ||
| 172 | |||
| 173 | #if 0 | ||
| 174 | double __lgamma_r(double x, int *sign) | ||
| 175 | { | ||
| 176 | 	double r, absx; | ||
| 177 | |||
| 178 | 	*sign = 1; | ||
| 179 | |||
| 180 | 	/* special cases */ | ||
| 181 | 	if (!isfinite(x)) | ||
| 182 | 		/* lgamma(nan)=nan, lgamma(+-inf)=inf */ | ||
| 183 | 		return x*x; | ||
| 184 | |||
| 185 | 	/* integer arguments */ | ||
| 186 | 	if (x == floor(x) && x <= 2) { | ||
| 187 | 		/* n <= 0: lgamma(n)=inf with divbyzero */ | ||
| 188 | 		/* n == 1,2: lgamma(n)=0 */ | ||
| 189 | 		if (x <= 0) | ||
| 190 | 			return 1/0.0; | ||
| 191 | 		return 0; | ||
| 192 | 	} | ||
| 193 | |||
| 194 | 	absx = fabs(x); | ||
| 195 | |||
| 196 | 	/* lgamma(x) ~ -log(|x|) for tiny |x| */ | ||
| 197 | 	if (absx < 0x1p-54) { | ||
| 198 | 		*sign = 1 - 2*!!signbit(x); | ||
| 199 | 		return -log(absx); | ||
| 200 | 	} | ||
| 201 | |||
| 202 | 	/* use tgamma for smaller |x| */ | ||
| 203 | 	if (absx < 128) { | ||
| 204 | 		x = tgamma(x); | ||
| 205 | 		*sign = 1 - 2*!!signbit(x); | ||
| 206 | 		return log(fabs(x)); | ||
| 207 | 	} | ||
| 208 | |||
| 209 | 	/* second term (log(S)-g) could be more precise here.. */ | ||
| 210 | 	/* or with stirling: (|x|-0.5)*(log(|x|)-1) + poly(1/|x|) */ | ||
| 211 | 	r = (absx-0.5)*(log(absx+gmhalf)-1) + (log(S(absx)) - (gmhalf+0.5)); | ||
| 212 | 	if (x < 0) { | ||
| 213 | 		/* reflection formula for negative x */ | ||
| 214 | 		x = sinpi(absx); | ||
| 215 | 		*sign = 2*!!signbit(x) - 1; | ||
| 216 | 		r = log(pi/(fabs(x)*absx)) - r; | ||
| 217 | 	} | ||
| 218 | 	return r; | ||
| 219 | } | ||
| 220 | |||
| 221 | weak_alias(__lgamma_r, lgamma_r); | ||
| 222 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/tgammaf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float tgammaf(float x) | ||
| 4 | { | ||
| 5 | 	return tgamma(x); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/tgammal.c created+281| ... | @@ -0,0 +1,281 @@ | ||
| 1 | /* origin: OpenBSD /usr/src/lib/libm/src/ld80/e_tgammal.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 | /* | ||
| 18 | * Gamma function | ||
| 19 | * | ||
| 20 | * | ||
| 21 | * SYNOPSIS: | ||
| 22 | * | ||
| 23 | * long double x, y, tgammal(); | ||
| 24 | * | ||
| 25 | * y = tgammal( x ); | ||
| 26 | * | ||
| 27 | * | ||
| 28 | * DESCRIPTION: | ||
| 29 | * | ||
| 30 | * Returns gamma function of the argument. The result is | ||
| 31 | * correctly signed. | ||
| 32 | * | ||
| 33 | * Arguments |x| <= 13 are reduced by recurrence and the function | ||
| 34 | * approximated by a rational function of degree 7/8 in the | ||
| 35 | * interval (2,3). Large arguments are handled by Stirling's | ||
| 36 | * formula. Large negative arguments are made positive using | ||
| 37 | * a reflection formula. | ||
| 38 | * | ||
| 39 | * | ||
| 40 | * ACCURACY: | ||
| 41 | * | ||
| 42 | * Relative error: | ||
| 43 | * arithmetic domain # trials peak rms | ||
| 44 | * IEEE -40,+40 10000 3.6e-19 7.9e-20 | ||
| 45 | * IEEE -1755,+1755 10000 4.8e-18 6.5e-19 | ||
| 46 | * | ||
| 47 | * Accuracy for large arguments is dominated by error in powl(). | ||
| 48 | * | ||
| 49 | */ | ||
| 50 | |||
| 51 | #include "libm.h" | ||
| 52 | |||
| 53 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 54 | long double tgammal(long double x) | ||
| 55 | { | ||
| 56 | 	return tgamma(x); | ||
| 57 | } | ||
| 58 | #elif LDBL_MANT_DIG == 64 && LDBL_MAX_EXP == 16384 | ||
| 59 | /* | ||
| 60 | tgamma(x+2) = tgamma(x+2) P(x)/Q(x) | ||
| 61 | 0 <= x <= 1 | ||
| 62 | Relative error | ||
| 63 | n=7, d=8 | ||
| 64 | Peak error = 1.83e-20 | ||
| 65 | Relative error spread = 8.4e-23 | ||
| 66 | */ | ||
| 67 | static const long double P[8] = { | ||
| 68 | 4.212760487471622013093E-5L, | ||
| 69 | 4.542931960608009155600E-4L, | ||
| 70 | 4.092666828394035500949E-3L, | ||
| 71 | 2.385363243461108252554E-2L, | ||
| 72 | 1.113062816019361559013E-1L, | ||
| 73 | 3.629515436640239168939E-1L, | ||
| 74 | 8.378004301573126728826E-1L, | ||
| 75 | 1.000000000000000000009E0L, | ||
| 76 | }; | ||
| 77 | static const long double Q[9] = { | ||
| 78 | -1.397148517476170440917E-5L, | ||
| 79 | 2.346584059160635244282E-4L, | ||
| 80 | -1.237799246653152231188E-3L, | ||
| 81 | -7.955933682494738320586E-4L, | ||
| 82 | 2.773706565840072979165E-2L, | ||
| 83 | -4.633887671244534213831E-2L, | ||
| 84 | -2.243510905670329164562E-1L, | ||
| 85 | 4.150160950588455434583E-1L, | ||
| 86 | 9.999999999999999999908E-1L, | ||
| 87 | }; | ||
| 88 | |||
| 89 | /* | ||
| 90 | static const long double P[] = { | ||
| 91 | -3.01525602666895735709e0L, | ||
| 92 | -3.25157411956062339893e1L, | ||
| 93 | -2.92929976820724030353e2L, | ||
| 94 | -1.70730828800510297666e3L, | ||
| 95 | -7.96667499622741999770e3L, | ||
| 96 | -2.59780216007146401957e4L, | ||
| 97 | -5.99650230220855581642e4L, | ||
| 98 | -7.15743521530849602425e4L | ||
| 99 | }; | ||
| 100 | static const long double Q[] = { | ||
| 101 | 1.00000000000000000000e0L, | ||
| 102 | -1.67955233807178858919e1L, | ||
| 103 | 8.85946791747759881659e1L, | ||
| 104 | 5.69440799097468430177e1L, | ||
| 105 | -1.98526250512761318471e3L, | ||
| 106 | 3.31667508019495079814e3L, | ||
| 107 | 1.60577839621734713377e4L, | ||
| 108 | -2.97045081369399940529e4L, | ||
| 109 | -7.15743521530849602412e4L | ||
| 110 | }; | ||
| 111 | */ | ||
| 112 | #define MAXGAML 1755.455L | ||
| 113 | /*static const long double LOGPI = 1.14472988584940017414L;*/ | ||
| 114 | |||
| 115 | /* Stirling's formula for the gamma function | ||
| 116 | tgamma(x) = sqrt(2 pi) x^(x-.5) exp(-x) (1 + 1/x P(1/x)) | ||
| 117 | z(x) = x | ||
| 118 | 13 <= x <= 1024 | ||
| 119 | Relative error | ||
| 120 | n=8, d=0 | ||
| 121 | Peak error = 9.44e-21 | ||
| 122 | Relative error spread = 8.8e-4 | ||
| 123 | */ | ||
| 124 | static const long double STIR[9] = { | ||
| 125 | 7.147391378143610789273E-4L, | ||
| 126 | -2.363848809501759061727E-5L, | ||
| 127 | -5.950237554056330156018E-4L, | ||
| 128 | 6.989332260623193171870E-5L, | ||
| 129 | 7.840334842744753003862E-4L, | ||
| 130 | -2.294719747873185405699E-4L, | ||
| 131 | -2.681327161876304418288E-3L, | ||
| 132 | 3.472222222230075327854E-3L, | ||
| 133 | 8.333333333333331800504E-2L, | ||
| 134 | }; | ||
| 135 | |||
| 136 | #define MAXSTIR 1024.0L | ||
| 137 | static const long double SQTPI = 2.50662827463100050242E0L; | ||
| 138 | |||
| 139 | /* 1/tgamma(x) = z P(z) | ||
| 140 | * z(x) = 1/x | ||
| 141 | * 0 < x < 0.03125 | ||
| 142 | * Peak relative error 4.2e-23 | ||
| 143 | */ | ||
| 144 | static const long double S[9] = { | ||
| 145 | -1.193945051381510095614E-3L, | ||
| 146 | 7.220599478036909672331E-3L, | ||
| 147 | -9.622023360406271645744E-3L, | ||
| 148 | -4.219773360705915470089E-2L, | ||
| 149 | 1.665386113720805206758E-1L, | ||
| 150 | -4.200263503403344054473E-2L, | ||
| 151 | -6.558780715202540684668E-1L, | ||
| 152 | 5.772156649015328608253E-1L, | ||
| 153 | 1.000000000000000000000E0L, | ||
| 154 | }; | ||
| 155 | |||
| 156 | /* 1/tgamma(-x) = z P(z) | ||
| 157 | * z(x) = 1/x | ||
| 158 | * 0 < x < 0.03125 | ||
| 159 | * Peak relative error 5.16e-23 | ||
| 160 | * Relative error spread = 2.5e-24 | ||
| 161 | */ | ||
| 162 | static const long double SN[9] = { | ||
| 163 | 1.133374167243894382010E-3L, | ||
| 164 | 7.220837261893170325704E-3L, | ||
| 165 | 9.621911155035976733706E-3L, | ||
| 166 | -4.219773343731191721664E-2L, | ||
| 167 | -1.665386113944413519335E-1L, | ||
| 168 | -4.200263503402112910504E-2L, | ||
| 169 | 6.558780715202536547116E-1L, | ||
| 170 | 5.772156649015328608727E-1L, | ||
| 171 | -1.000000000000000000000E0L, | ||
| 172 | }; | ||
| 173 | |||
| 174 | static const long double PIL = 3.1415926535897932384626L; | ||
| 175 | |||
| 176 | /* Gamma function computed by Stirling's formula. | ||
| 177 | */ | ||
| 178 | static long double stirf(long double x) | ||
| 179 | { | ||
| 180 | 	long double y, w, v; | ||
| 181 | |||
| 182 | 	w = 1.0/x; | ||
| 183 | 	/* For large x, use rational coefficients from the analytical expansion. */ | ||
| 184 | 	if (x > 1024.0) | ||
| 185 | 		w = (((((6.97281375836585777429E-5L * w | ||
| 186 | 		 + 7.84039221720066627474E-4L) * w | ||
| 187 | 		 - 2.29472093621399176955E-4L) * w | ||
| 188 | 		 - 2.68132716049382716049E-3L) * w | ||
| 189 | 		 + 3.47222222222222222222E-3L) * w | ||
| 190 | 		 + 8.33333333333333333333E-2L) * w | ||
| 191 | 		 + 1.0; | ||
| 192 | 	else | ||
| 193 | 		w = 1.0 + w * __polevll(w, STIR, 8); | ||
| 194 | 	y = expl(x); | ||
| 195 | 	if (x > MAXSTIR) { /* Avoid overflow in pow() */ | ||
| 196 | 		v = powl(x, 0.5L * x - 0.25L); | ||
| 197 | 		y = v * (v / y); | ||
| 198 | 	} else { | ||
| 199 | 		y = powl(x, x - 0.5L) / y; | ||
| 200 | 	} | ||
| 201 | 	y = SQTPI * y * w; | ||
| 202 | 	return y; | ||
| 203 | } | ||
| 204 | |||
| 205 | long double tgammal(long double x) | ||
| 206 | { | ||
| 207 | 	long double p, q, z; | ||
| 208 | |||
| 209 | 	if (!isfinite(x)) | ||
| 210 | 		return x + INFINITY; | ||
| 211 | |||
| 212 | 	q = fabsl(x); | ||
| 213 | 	if (q > 13.0) { | ||
| 214 | 		if (x < 0.0) { | ||
| 215 | 			p = floorl(q); | ||
| 216 | 			z = q - p; | ||
| 217 | 			if (z == 0) | ||
| 218 | 				return 0 / z; | ||
| 219 | 			if (q > MAXGAML) { | ||
| 220 | 				z = 0; | ||
| 221 | 			} else { | ||
| 222 | 				if (z > 0.5) { | ||
| 223 | 					p += 1.0; | ||
| 224 | 					z = q - p; | ||
| 225 | 				} | ||
| 226 | 				z = q * sinl(PIL * z); | ||
| 227 | 				z = fabsl(z) * stirf(q); | ||
| 228 | 				z = PIL/z; | ||
| 229 | 			} | ||
| 230 | 			if (0.5 * p == floorl(q * 0.5)) | ||
| 231 | 				z = -z; | ||
| 232 | 		} else if (x > MAXGAML) { | ||
| 233 | 			z = x * 0x1p16383L; | ||
| 234 | 		} else { | ||
| 235 | 			z = stirf(x); | ||
| 236 | 		} | ||
| 237 | 		return z; | ||
| 238 | 	} | ||
| 239 | |||
| 240 | 	z = 1.0; | ||
| 241 | 	while (x >= 3.0) { | ||
| 242 | 		x -= 1.0; | ||
| 243 | 		z *= x; | ||
| 244 | 	} | ||
| 245 | 	while (x < -0.03125L) { | ||
| 246 | 		z /= x; | ||
| 247 | 		x += 1.0; | ||
| 248 | 	} | ||
| 249 | 	if (x <= 0.03125L) | ||
| 250 | 		goto small; | ||
| 251 | 	while (x < 2.0) { | ||
| 252 | 		z /= x; | ||
| 253 | 		x += 1.0; | ||
| 254 | 	} | ||
| 255 | 	if (x == 2.0) | ||
| 256 | 		return z; | ||
| 257 | |||
| 258 | 	x -= 2.0; | ||
| 259 | 	p = __polevll(x, P, 7); | ||
| 260 | 	q = __polevll(x, Q, 8); | ||
| 261 | 	z = z * p / q; | ||
| 262 | 	return z; | ||
| 263 | |||
| 264 | small: | ||
| 265 | 	/* z==1 if x was originally +-0 */ | ||
| 266 | 	if (x == 0 && z != 1) | ||
| 267 | 		return x / x; | ||
| 268 | 	if (x < 0.0) { | ||
| 269 | 		x = -x; | ||
| 270 | 		q = z / (x * __polevll(x, SN, 8)); | ||
| 271 | 	} else | ||
| 272 | 		q = z / (x * __polevll(x, S, 8)); | ||
| 273 | 	return q; | ||
| 274 | } | ||
| 275 | #elif LDBL_MANT_DIG == 113 && LDBL_MAX_EXP == 16384 | ||
| 276 | // TODO: broken implementation to make things compile | ||
| 277 | long double tgammal(long double x) | ||
| 278 | { | ||
| 279 | 	return tgamma(x); | ||
| 280 | } | ||
| 281 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/trunc.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | double trunc(double x) | ||
| 4 | { | ||
| 5 | 	union {double f; uint64_t i;} u = {x}; | ||
| 6 | 	int e = (int)(u.i >> 52 & 0x7ff) - 0x3ff + 12; | ||
| 7 | 	uint64_t m; | ||
| 8 | |||
| 9 | 	if (e >= 52 + 12) | ||
| 10 | 		return x; | ||
| 11 | 	if (e < 12) | ||
| 12 | 		e = 1; | ||
| 13 | 	m = -1ULL >> e; | ||
| 14 | 	if ((u.i & m) == 0) | ||
| 15 | 		return x; | ||
| 16 | 	FORCE_EVAL(x + 0x1p120f); | ||
| 17 | 	u.i &= ~m; | ||
| 18 | 	return u.f; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/truncf.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | float truncf(float x) | ||
| 4 | { | ||
| 5 | 	union {float f; uint32_t i;} u = {x}; | ||
| 6 | 	int e = (int)(u.i >> 23 & 0xff) - 0x7f + 9; | ||
| 7 | 	uint32_t m; | ||
| 8 | |||
| 9 | 	if (e >= 23 + 9) | ||
| 10 | 		return x; | ||
| 11 | 	if (e < 9) | ||
| 12 | 		e = 1; | ||
| 13 | 	m = -1U >> e; | ||
| 14 | 	if ((u.i & m) == 0) | ||
| 15 | 		return x; | ||
| 16 | 	FORCE_EVAL(x + 0x1p120f); | ||
| 17 | 	u.i &= ~m; | ||
| 18 | 	return u.f; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/truncl.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include "libm.h" | ||
| 2 | |||
| 3 | #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024 | ||
| 4 | long double truncl(long double x) | ||
| 5 | { | ||
| 6 | 	return trunc(x); | ||
| 7 | } | ||
| 8 | #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384 | ||
| 9 | |||
| 10 | static const long double toint = 1/LDBL_EPSILON; | ||
| 11 | |||
| 12 | long double truncl(long double x) | ||
| 13 | { | ||
| 14 | 	union ldshape u = {x}; | ||
| 15 | 	int e = u.i.se & 0x7fff; | ||
| 16 | 	int s = u.i.se >> 15; | ||
| 17 | 	long double y; | ||
| 18 | |||
| 19 | 	if (e >= 0x3fff+LDBL_MANT_DIG-1) | ||
| 20 | 		return x; | ||
| 21 | 	if (e <= 0x3fff-1) { | ||
| 22 | 		FORCE_EVAL(x + 0x1p120f); | ||
| 23 | 		return x*0; | ||
| 24 | 	} | ||
| 25 | 	/* y = int(|x|) - |x|, where int(|x|) is an integer neighbor of |x| */ | ||
| 26 | 	if (s) | ||
| 27 | 		x = -x; | ||
| 28 | 	y = x + toint - toint - x; | ||
| 29 | 	if (y > 0) | ||
| 30 | 		y -= 1; | ||
| 31 | 	x += y; | ||
| 32 | 	return s ? -x : x; | ||
| 33 | } | ||
| 34 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/__invtrigl.s createdlib/libc/wasi/libc-top-half/musl/src/math/x32/acosl.s created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | # see ../i386/acos.s | ||
| 2 | |||
| 3 | .global acosl | ||
| 4 | .type acosl,@function | ||
| 5 | acosl: | ||
| 6 | 	fldt 8(%esp) | ||
| 7 | 1:	fld %st(0) | ||
| 8 | 	fld1 | ||
| 9 | 	fsub %st(0),%st(1) | ||
| 10 | 	fadd %st(2) | ||
| 11 | 	fmulp | ||
| 12 | 	fsqrt | ||
| 13 | 	fabs | ||
| 14 | 	fxch %st(1) | ||
| 15 | 	fpatan | ||
| 16 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/asinl.s created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | .global asinl | ||
| 2 | .type asinl,@function | ||
| 3 | asinl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 1:	fld %st(0) | ||
| 6 | 	fld1 | ||
| 7 | 	fsub %st(0),%st(1) | ||
| 8 | 	fadd %st(2) | ||
| 9 | 	fmulp | ||
| 10 | 	fsqrt | ||
| 11 | 	fpatan | ||
| 12 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/atan2l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global atan2l | ||
| 2 | .type atan2l,@function | ||
| 3 | atan2l: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	fldt 24(%esp) | ||
| 6 | 	fpatan | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/atanl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global atanl | ||
| 2 | .type atanl,@function | ||
| 3 | atanl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	fld1 | ||
| 6 | 	fpatan | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/ceill.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floorl.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/exp2l.s created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | .global expm1l | ||
| 2 | .type expm1l,@function | ||
| 3 | expm1l: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	fldl2e | ||
| 6 | 	fmulp | ||
| 7 | 	movl $0xc2820000,-4(%esp) | ||
| 8 | 	flds -4(%esp) | ||
| 9 | 	fucomip %st(1),%st | ||
| 10 | 	fld1 | ||
| 11 | 	jb 1f | ||
| 12 | 		# x*log2e <= -65, return -1 without underflow | ||
| 13 | 	fstp %st(1) | ||
| 14 | 	fchs | ||
| 15 | 	ret | ||
| 16 | 1:	fld %st(1) | ||
| 17 | 	fabs | ||
| 18 | 	fucomip %st(1),%st | ||
| 19 | 	fstp %st(0) | ||
| 20 | 	ja 1f | ||
| 21 | 	f2xm1 | ||
| 22 | 	ret | ||
| 23 | 1:	push %rax | ||
| 24 | 	call 1f | ||
| 25 | 	pop %rax | ||
| 26 | 	fld1 | ||
| 27 | 	fsubrp | ||
| 28 | 	ret | ||
| 29 | |||
| 30 | .global exp2l | ||
| 31 | .type exp2l,@function | ||
| 32 | exp2l: | ||
| 33 | 	fldt 8(%esp) | ||
| 34 | 1:	fld %st(0) | ||
| 35 | 	sub $16,%esp | ||
| 36 | 	fstpt (%esp) | ||
| 37 | 	mov 8(%esp),%ax | ||
| 38 | 	and $0x7fff,%ax | ||
| 39 | 	cmp $0x3fff+13,%ax | ||
| 40 | 	jb 4f # |x| < 8192 | ||
| 41 | 	cmp $0x3fff+15,%ax | ||
| 42 | 	jae 3f # |x| >= 32768 | ||
| 43 | 	fsts (%esp) | ||
| 44 | 	cmpl $0xc67ff800,(%esp) | ||
| 45 | 	jb 2f # x > -16382 | ||
| 46 | 	movl $0x5f000000,(%esp) | ||
| 47 | 	flds (%esp) # 0x1p63 | ||
| 48 | 	fld %st(1) | ||
| 49 | 	fsub %st(1) | ||
| 50 | 	faddp | ||
| 51 | 	fucomip %st(1),%st | ||
| 52 | 	je 2f # x - 0x1p63 + 0x1p63 == x | ||
| 53 | 	movl $1,(%esp) | ||
| 54 | 	flds (%esp) # 0x1p-149 | ||
| 55 | 	fdiv %st(1) | ||
| 56 | 	fstps (%esp) # raise underflow | ||
| 57 | 2:	fld1 | ||
| 58 | 	fld %st(1) | ||
| 59 | 	frndint | ||
| 60 | 	fxch %st(2) | ||
| 61 | 	fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x) | ||
| 62 | 	f2xm1 | ||
| 63 | 	faddp # 2^(x-rint(x)) | ||
| 64 | 1:	fscale | ||
| 65 | 	fstp %st(1) | ||
| 66 | 	add $16,%esp | ||
| 67 | 	ret | ||
| 68 | 3:	xor %eax,%eax | ||
| 69 | 4:	cmp $0x3fff-64,%ax | ||
| 70 | 	fld1 | ||
| 71 | 	jb 1b # |x| < 0x1p-64 | ||
| 72 | 	fstpt (%esp) | ||
| 73 | 	fistl 8(%esp) | ||
| 74 | 	fildl 8(%esp) | ||
| 75 | 	fsubrp %st(1) | ||
| 76 | 	addl $0x3fff,8(%esp) | ||
| 77 | 	f2xm1 | ||
| 78 | 	fld1 | ||
| 79 | 	faddp # 2^(x-rint(x)) | ||
| 80 | 	fldt (%esp) # 2^rint(x) | ||
| 81 | 	fmulp | ||
| 82 | 	add $16,%esp | ||
| 83 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/expl.s created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | # exp(x) = 2^hi + 2^hi (2^lo - 1) | ||
| 2 | # where hi+lo = log2e*x with 128bit precision | ||
| 3 | # exact log2e*x calculation depends on nearest rounding mode | ||
| 4 | # using the exact multiplication method of Dekker and Veltkamp | ||
| 5 | |||
| 6 | .global expl | ||
| 7 | .type expl,@function | ||
| 8 | expl: | ||
| 9 | 	fldt 8(%esp) | ||
| 10 | |||
| 11 | 		# interesting case: 0x1p-32 <= |x| < 16384 | ||
| 12 | 		# check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13] | ||
| 13 | 	mov 16(%esp), %ax | ||
| 14 | 	or $0x8000, %ax | ||
| 15 | 	sub $0xbfdf, %ax | ||
| 16 | 	cmp $45, %ax | ||
| 17 | 	jbe 2f | ||
| 18 | 	test %ax, %ax | ||
| 19 | 	fld1 | ||
| 20 | 	js 1f | ||
| 21 | 		# if |x|>=0x1p14 or nan return 2^trunc(x) | ||
| 22 | 	fscale | ||
| 23 | 	fstp %st(1) | ||
| 24 | 	ret | ||
| 25 | 		# if |x|<0x1p-32 return 1+x | ||
| 26 | 1:	faddp | ||
| 27 | 	ret | ||
| 28 | |||
| 29 | 		# should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc | ||
| 30 | 		# it will be wrong on non-nearest rounding mode | ||
| 31 | 2:	fldl2e | ||
| 32 | 	sub $48, %esp | ||
| 33 | 		# hi = log2e_hi*x | ||
| 34 | 		# 2^hi = exp2l(hi) | ||
| 35 | 	fmul %st(1),%st | ||
| 36 | 	fld %st(0) | ||
| 37 | 	fstpt (%esp) | ||
| 38 | 	fstpt 16(%esp) | ||
| 39 | 	fstpt 32(%esp) | ||
| 40 | 	call exp2l@PLT | ||
| 41 | 		# if 2^hi == inf return 2^hi | ||
| 42 | 	fld %st(0) | ||
| 43 | 	fstpt (%esp) | ||
| 44 | 	cmpw $0x7fff, 8(%esp) | ||
| 45 | 	je 1f | ||
| 46 | 	fldt 32(%esp) | ||
| 47 | 	fldt 16(%esp) | ||
| 48 | 		# fpu stack: 2^hi x hi | ||
| 49 | 		# exact mult: x*log2e | ||
| 50 | 	fld %st(1) | ||
| 51 | 		# c = 0x1p32+1 | ||
| 52 | 	movq $0x41f0000000100000,%rax | ||
| 53 | 	pushq %rax | ||
| 54 | 	fldl (%esp) | ||
| 55 | 		# xh = x - c*x + c*x | ||
| 56 | 		# xl = x - xh | ||
| 57 | 	fmulp | ||
| 58 | 	fld %st(2) | ||
| 59 | 	fsub %st(1), %st | ||
| 60 | 	faddp | ||
| 61 | 	fld %st(2) | ||
| 62 | 	fsub %st(1), %st | ||
| 63 | 		# yh = log2e_hi - c*log2e_hi + c*log2e_hi | ||
| 64 | 	movq $0x3ff7154765200000,%rax | ||
| 65 | 	pushq %rax | ||
| 66 | 	fldl (%esp) | ||
| 67 | 		# fpu stack: 2^hi x hi xh xl yh | ||
| 68 | 		# lo = hi - xh*yh + xl*yh | ||
| 69 | 	fld %st(2) | ||
| 70 | 	fmul %st(1), %st | ||
| 71 | 	fsubp %st, %st(4) | ||
| 72 | 	fmul %st(1), %st | ||
| 73 | 	faddp %st, %st(3) | ||
| 74 | 		# yl = log2e_hi - yh | ||
| 75 | 	movq $0x3de705fc2f000000,%rax | ||
| 76 | 	pushq %rax | ||
| 77 | 	fldl (%esp) | ||
| 78 | 		# fpu stack: 2^hi x lo xh xl yl | ||
| 79 | 		# lo += xh*yl + xl*yl | ||
| 80 | 	fmul %st, %st(2) | ||
| 81 | 	fmulp %st, %st(1) | ||
| 82 | 	fxch %st(2) | ||
| 83 | 	faddp | ||
| 84 | 	faddp | ||
| 85 | 		# log2e_lo | ||
| 86 | 	movq $0xbfbe,%rax | ||
| 87 | 	pushq %rax | ||
| 88 | 	movq $0x82f0025f2dc582ee,%rax | ||
| 89 | 	pushq %rax | ||
| 90 | 	fldt (%esp) | ||
| 91 | 	add $40,%esp | ||
| 92 | 		# fpu stack: 2^hi x lo log2e_lo | ||
| 93 | 		# lo += log2e_lo*x | ||
| 94 | 		# return 2^hi + 2^hi (2^lo - 1) | ||
| 95 | 	fmulp %st, %st(2) | ||
| 96 | 	faddp | ||
| 97 | 	f2xm1 | ||
| 98 | 	fmul %st(1), %st | ||
| 99 | 	faddp | ||
| 100 | 1:	add $48, %esp | ||
| 101 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/expm1l.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see exp2l.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabs.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .global fabs | ||
| 2 | .type fabs,@function | ||
| 3 | fabs: | ||
| 4 | 	xor %eax,%eax | ||
| 5 | 	dec %rax | ||
| 6 | 	shr %rax | ||
| 7 | 	movq %rax,%xmm1 | ||
| 8 | 	andpd %xmm1,%xmm0 | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabsf.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global fabsf | ||
| 2 | .type fabsf,@function | ||
| 3 | fabsf: | ||
| 4 | 	mov $0x7fffffff,%eax | ||
| 5 | 	movq %rax,%xmm1 | ||
| 6 | 	andps %xmm1,%xmm0 | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/fabsl.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global fabsl | ||
| 2 | .type fabsl,@function | ||
| 3 | fabsl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	fabs | ||
| 6 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/floorl.s created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | .global floorl | ||
| 2 | .type floorl,@function | ||
| 3 | floorl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 1:	mov $0x7,%al | ||
| 6 | 1:	fstcw 8(%esp) | ||
| 7 | 	mov 9(%esp),%ah | ||
| 8 | 	mov %al,9(%esp) | ||
| 9 | 	fldcw 8(%esp) | ||
| 10 | 	frndint | ||
| 11 | 	mov %ah,9(%esp) | ||
| 12 | 	fldcw 8(%esp) | ||
| 13 | 	ret | ||
| 14 | |||
| 15 | .global ceill | ||
| 16 | .type ceill,@function | ||
| 17 | ceill: | ||
| 18 | 	fldt 8(%esp) | ||
| 19 | 	mov $0xb,%al | ||
| 20 | 	jmp 1b | ||
| 21 | |||
| 22 | .global truncl | ||
| 23 | .type truncl,@function | ||
| 24 | truncl: | ||
| 25 | 	fldt 8(%esp) | ||
| 26 | 	mov $0xf,%al | ||
| 27 | 	jmp 1b | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/fma.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __FMA__ | ||
| 4 | |||
| 5 | double fma(double x, double y, double z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #elif __FMA4__ | ||
| 12 | |||
| 13 | double fma(double x, double y, double z) | ||
| 14 | { | ||
| 15 | 	__asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z)); | ||
| 16 | 	return x; | ||
| 17 | } | ||
| 18 | |||
| 19 | #else | ||
| 20 | |||
| 21 | #include "../fma.c" | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/fmaf.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __FMA__ | ||
| 4 | |||
| 5 | float fmaf(float x, float y, float z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #elif __FMA4__ | ||
| 12 | |||
| 13 | float fmaf(float x, float y, float z) | ||
| 14 | { | ||
| 15 | 	__asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z)); | ||
| 16 | 	return x; | ||
| 17 | } | ||
| 18 | |||
| 19 | #else | ||
| 20 | |||
| 21 | #include "../fmaf.c" | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/fmodl.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .global fmodl | ||
| 2 | .type fmodl,@function | ||
| 3 | fmodl: | ||
| 4 | 	fldt 24(%esp) | ||
| 5 | 	fldt 8(%esp) | ||
| 6 | 1:	fprem | ||
| 7 | 	fnstsw %ax | ||
| 8 | 	testb $4,%ah | ||
| 9 | 	jnz 1b | ||
| 10 | 	fstp %st(1) | ||
| 11 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrint.s created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | .global llrint | ||
| 2 | .type llrint,@function | ||
| 3 | llrint: | ||
| 4 | 	cvtsd2si %xmm0,%rax | ||
| 5 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrintf.s created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | .global llrintf | ||
| 2 | .type llrintf,@function | ||
| 3 | llrintf: | ||
| 4 | 	cvtss2si %xmm0,%rax | ||
| 5 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/llrintl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global llrintl | ||
| 2 | .type llrintl,@function | ||
| 3 | llrintl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	fistpll 8(%esp) | ||
| 6 | 	mov 8(%esp),%rax | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/log10l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global log10l | ||
| 2 | .type log10l,@function | ||
| 3 | log10l: | ||
| 4 | 	fldlg2 | ||
| 5 | 	fldt 8(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/log1pl.s created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | .global log1pl | ||
| 2 | .type log1pl,@function | ||
| 3 | log1pl: | ||
| 4 | 	mov 14(%esp),%eax | ||
| 5 | 	fldln2 | ||
| 6 | 	and $0x7fffffff,%eax | ||
| 7 | 	fldt 8(%esp) | ||
| 8 | 	cmp $0x3ffd9400,%eax | ||
| 9 | 	ja 1f | ||
| 10 | 	fyl2xp1 | ||
| 11 | 	ret | ||
| 12 | 1:	fld1 | ||
| 13 | 	faddp | ||
| 14 | 	fyl2x | ||
| 15 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/log2l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global log2l | ||
| 2 | .type log2l,@function | ||
| 3 | log2l: | ||
| 4 | 	fld1 | ||
| 5 | 	fldt 8(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/logl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global logl | ||
| 2 | .type logl,@function | ||
| 3 | logl: | ||
| 4 | 	fldln2 | ||
| 5 | 	fldt 8(%esp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrint.s created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | .global lrint | ||
| 2 | .type lrint,@function | ||
| 3 | lrint: | ||
| 4 | 	cvtsd2si %xmm0,%rax | ||
| 5 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrintf.s created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | .global lrintf | ||
| 2 | .type lrintf,@function | ||
| 3 | lrintf: | ||
| 4 | 	cvtss2si %xmm0,%rax | ||
| 5 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/lrintl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global lrintl | ||
| 2 | .type lrintl,@function | ||
| 3 | lrintl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	fistpl 8(%esp) | ||
| 6 | 	movl 8(%esp),%eax | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/remainderl.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .global remainderl | ||
| 2 | .type remainderl,@function | ||
| 3 | remainderl: | ||
| 4 | 	fldt 24(%esp) | ||
| 5 | 	fldt 8(%esp) | ||
| 6 | 1:	fprem1 | ||
| 7 | 	fnstsw %ax | ||
| 8 | 	testb $4,%ah | ||
| 9 | 	jnz 1b | ||
| 10 | 	fstp %st(1) | ||
| 11 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/rintl.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global rintl | ||
| 2 | .type rintl,@function | ||
| 3 | rintl: | ||
| 4 | 	fldt 8(%esp) | ||
| 5 | 	frndint | ||
| 6 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrt.s created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | .global sqrt | ||
| 2 | .type sqrt,@function | ||
| 3 | sqrt:	sqrtsd %xmm0, %xmm0 | ||
| 4 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrtf.s created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | .global sqrtf | ||
| 2 | .type sqrtf,@function | ||
| 3 | sqrtf: sqrtss %xmm0, %xmm0 | ||
| 4 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/sqrtl.s created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | .global sqrtl | ||
| 2 | .type sqrtl,@function | ||
| 3 | sqrtl:	fldt 8(%esp) | ||
| 4 | 	fsqrt | ||
| 5 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x32/truncl.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floorl.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/__invtrigl.s createdlib/libc/wasi/libc-top-half/musl/src/math/x86_64/acosl.s created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | # see ../i386/acos.s | ||
| 2 | |||
| 3 | .global acosl | ||
| 4 | .type acosl,@function | ||
| 5 | acosl: | ||
| 6 | 	fldt 8(%rsp) | ||
| 7 | 1:	fld %st(0) | ||
| 8 | 	fld1 | ||
| 9 | 	fsub %st(0),%st(1) | ||
| 10 | 	fadd %st(2) | ||
| 11 | 	fmulp | ||
| 12 | 	fsqrt | ||
| 13 | 	fabs | ||
| 14 | 	fxch %st(1) | ||
| 15 | 	fpatan | ||
| 16 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/asinl.s created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | .global asinl | ||
| 2 | .type asinl,@function | ||
| 3 | asinl: | ||
| 4 | 	fldt 8(%rsp) | ||
| 5 | 1:	fld %st(0) | ||
| 6 | 	fld1 | ||
| 7 | 	fsub %st(0),%st(1) | ||
| 8 | 	fadd %st(2) | ||
| 9 | 	fmulp | ||
| 10 | 	fsqrt | ||
| 11 | 	fpatan | ||
| 12 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/atan2l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global atan2l | ||
| 2 | .type atan2l,@function | ||
| 3 | atan2l: | ||
| 4 | 	fldt 8(%rsp) | ||
| 5 | 	fldt 24(%rsp) | ||
| 6 | 	fpatan | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/atanl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global atanl | ||
| 2 | .type atanl,@function | ||
| 3 | atanl: | ||
| 4 | 	fldt 8(%rsp) | ||
| 5 | 	fld1 | ||
| 6 | 	fpatan | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/ceill.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floorl.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/exp2l.s created+83| ... | @@ -0,0 +1,83 @@ | ||
| 1 | .global expm1l | ||
| 2 | .type expm1l,@function | ||
| 3 | expm1l: | ||
| 4 | 	fldt 8(%rsp) | ||
| 5 | 	fldl2e | ||
| 6 | 	fmulp | ||
| 7 | 	movl $0xc2820000,-4(%rsp) | ||
| 8 | 	flds -4(%rsp) | ||
| 9 | 	fucomip %st(1),%st | ||
| 10 | 	fld1 | ||
| 11 | 	jb 1f | ||
| 12 | 		# x*log2e <= -65, return -1 without underflow | ||
| 13 | 	fstp %st(1) | ||
| 14 | 	fchs | ||
| 15 | 	ret | ||
| 16 | 1:	fld %st(1) | ||
| 17 | 	fabs | ||
| 18 | 	fucomip %st(1),%st | ||
| 19 | 	fstp %st(0) | ||
| 20 | 	ja 1f | ||
| 21 | 	f2xm1 | ||
| 22 | 	ret | ||
| 23 | 1:	push %rax | ||
| 24 | 	call 1f | ||
| 25 | 	pop %rax | ||
| 26 | 	fld1 | ||
| 27 | 	fsubrp | ||
| 28 | 	ret | ||
| 29 | |||
| 30 | .global exp2l | ||
| 31 | .type exp2l,@function | ||
| 32 | exp2l: | ||
| 33 | 	fldt 8(%rsp) | ||
| 34 | 1:	fld %st(0) | ||
| 35 | 	sub $16,%rsp | ||
| 36 | 	fstpt (%rsp) | ||
| 37 | 	mov 8(%rsp),%ax | ||
| 38 | 	and $0x7fff,%ax | ||
| 39 | 	cmp $0x3fff+13,%ax | ||
| 40 | 	jb 4f # |x| < 8192 | ||
| 41 | 	cmp $0x3fff+15,%ax | ||
| 42 | 	jae 3f # |x| >= 32768 | ||
| 43 | 	fsts (%rsp) | ||
| 44 | 	cmpl $0xc67ff800,(%rsp) | ||
| 45 | 	jb 2f # x > -16382 | ||
| 46 | 	movl $0x5f000000,(%rsp) | ||
| 47 | 	flds (%rsp) # 0x1p63 | ||
| 48 | 	fld %st(1) | ||
| 49 | 	fsub %st(1) | ||
| 50 | 	faddp | ||
| 51 | 	fucomip %st(1),%st | ||
| 52 | 	je 2f # x - 0x1p63 + 0x1p63 == x | ||
| 53 | 	movl $1,(%rsp) | ||
| 54 | 	flds (%rsp) # 0x1p-149 | ||
| 55 | 	fdiv %st(1) | ||
| 56 | 	fstps (%rsp) # raise underflow | ||
| 57 | 2:	fld1 | ||
| 58 | 	fld %st(1) | ||
| 59 | 	frndint | ||
| 60 | 	fxch %st(2) | ||
| 61 | 	fsub %st(2) # st(0)=x-rint(x), st(1)=1, st(2)=rint(x) | ||
| 62 | 	f2xm1 | ||
| 63 | 	faddp # 2^(x-rint(x)) | ||
| 64 | 1:	fscale | ||
| 65 | 	fstp %st(1) | ||
| 66 | 	add $16,%rsp | ||
| 67 | 	ret | ||
| 68 | 3:	xor %eax,%eax | ||
| 69 | 4:	cmp $0x3fff-64,%ax | ||
| 70 | 	fld1 | ||
| 71 | 	jb 1b # |x| < 0x1p-64 | ||
| 72 | 	fstpt (%rsp) | ||
| 73 | 	fistl 8(%rsp) | ||
| 74 | 	fildl 8(%rsp) | ||
| 75 | 	fsubrp %st(1) | ||
| 76 | 	addl $0x3fff,8(%rsp) | ||
| 77 | 	f2xm1 | ||
| 78 | 	fld1 | ||
| 79 | 	faddp # 2^(x-rint(x)) | ||
| 80 | 	fldt (%rsp) # 2^rint(x) | ||
| 81 | 	fmulp | ||
| 82 | 	add $16,%rsp | ||
| 83 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/expl.s created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | # exp(x) = 2^hi + 2^hi (2^lo - 1) | ||
| 2 | # where hi+lo = log2e*x with 128bit precision | ||
| 3 | # exact log2e*x calculation depends on nearest rounding mode | ||
| 4 | # using the exact multiplication method of Dekker and Veltkamp | ||
| 5 | |||
| 6 | .global expl | ||
| 7 | .type expl,@function | ||
| 8 | expl: | ||
| 9 | 	fldt 8(%rsp) | ||
| 10 | |||
| 11 | 		# interesting case: 0x1p-32 <= |x| < 16384 | ||
| 12 | 		# check if (exponent|0x8000) is in [0xbfff-32, 0xbfff+13] | ||
| 13 | 	mov 16(%rsp), %ax | ||
| 14 | 	or $0x8000, %ax | ||
| 15 | 	sub $0xbfdf, %ax | ||
| 16 | 	cmp $45, %ax | ||
| 17 | 	jbe 2f | ||
| 18 | 	test %ax, %ax | ||
| 19 | 	fld1 | ||
| 20 | 	js 1f | ||
| 21 | 		# if |x|>=0x1p14 or nan return 2^trunc(x) | ||
| 22 | 	fscale | ||
| 23 | 	fstp %st(1) | ||
| 24 | 	ret | ||
| 25 | 		# if |x|<0x1p-32 return 1+x | ||
| 26 | 1:	faddp | ||
| 27 | 	ret | ||
| 28 | |||
| 29 | 		# should be 0x1.71547652b82fe178p0L == 0x3fff b8aa3b29 5c17f0bc | ||
| 30 | 		# it will be wrong on non-nearest rounding mode | ||
| 31 | 2:	fldl2e | ||
| 32 | 	subq $48, %rsp | ||
| 33 | 		# hi = log2e_hi*x | ||
| 34 | 		# 2^hi = exp2l(hi) | ||
| 35 | 	fmul %st(1),%st | ||
| 36 | 	fld %st(0) | ||
| 37 | 	fstpt (%rsp) | ||
| 38 | 	fstpt 16(%rsp) | ||
| 39 | 	fstpt 32(%rsp) | ||
| 40 | 	call exp2l@PLT | ||
| 41 | 		# if 2^hi == inf return 2^hi | ||
| 42 | 	fld %st(0) | ||
| 43 | 	fstpt (%rsp) | ||
| 44 | 	cmpw $0x7fff, 8(%rsp) | ||
| 45 | 	je 1f | ||
| 46 | 	fldt 32(%rsp) | ||
| 47 | 	fldt 16(%rsp) | ||
| 48 | 		# fpu stack: 2^hi x hi | ||
| 49 | 		# exact mult: x*log2e | ||
| 50 | 	fld %st(1) | ||
| 51 | 		# c = 0x1p32+1 | ||
| 52 | 	movq $0x41f0000000100000,%rax | ||
| 53 | 	pushq %rax | ||
| 54 | 	fldl (%rsp) | ||
| 55 | 		# xh = x - c*x + c*x | ||
| 56 | 		# xl = x - xh | ||
| 57 | 	fmulp | ||
| 58 | 	fld %st(2) | ||
| 59 | 	fsub %st(1), %st | ||
| 60 | 	faddp | ||
| 61 | 	fld %st(2) | ||
| 62 | 	fsub %st(1), %st | ||
| 63 | 		# yh = log2e_hi - c*log2e_hi + c*log2e_hi | ||
| 64 | 	movq $0x3ff7154765200000,%rax | ||
| 65 | 	pushq %rax | ||
| 66 | 	fldl (%rsp) | ||
| 67 | 		# fpu stack: 2^hi x hi xh xl yh | ||
| 68 | 		# lo = hi - xh*yh + xl*yh | ||
| 69 | 	fld %st(2) | ||
| 70 | 	fmul %st(1), %st | ||
| 71 | 	fsubp %st, %st(4) | ||
| 72 | 	fmul %st(1), %st | ||
| 73 | 	faddp %st, %st(3) | ||
| 74 | 		# yl = log2e_hi - yh | ||
| 75 | 	movq $0x3de705fc2f000000,%rax | ||
| 76 | 	pushq %rax | ||
| 77 | 	fldl (%rsp) | ||
| 78 | 		# fpu stack: 2^hi x lo xh xl yl | ||
| 79 | 		# lo += xh*yl + xl*yl | ||
| 80 | 	fmul %st, %st(2) | ||
| 81 | 	fmulp %st, %st(1) | ||
| 82 | 	fxch %st(2) | ||
| 83 | 	faddp | ||
| 84 | 	faddp | ||
| 85 | 		# log2e_lo | ||
| 86 | 	movq $0xbfbe,%rax | ||
| 87 | 	pushq %rax | ||
| 88 | 	movq $0x82f0025f2dc582ee,%rax | ||
| 89 | 	pushq %rax | ||
| 90 | 	fldt (%rsp) | ||
| 91 | 	addq $40,%rsp | ||
| 92 | 		# fpu stack: 2^hi x lo log2e_lo | ||
| 93 | 		# lo += log2e_lo*x | ||
| 94 | 		# return 2^hi + 2^hi (2^lo - 1) | ||
| 95 | 	fmulp %st, %st(2) | ||
| 96 | 	faddp | ||
| 97 | 	f2xm1 | ||
| 98 | 	fmul %st(1), %st | ||
| 99 | 	faddp | ||
| 100 | 1:	addq $48, %rsp | ||
| 101 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/expm1l.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see exp2l.s | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabs.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double fabs(double x) | ||
| 4 | { | ||
| 5 | 	double t; | ||
| 6 | 	__asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0 | ||
| 7 | 	__asm__ ("psrlq $1, %0" : "+x"(t)); // t >>= 1 | ||
| 8 | 	__asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t | ||
| 9 | 	return x; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabsf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float fabsf(float x) | ||
| 4 | { | ||
| 5 | 	float t; | ||
| 6 | 	__asm__ ("pcmpeqd %0, %0" : "=x"(t)); // t = ~0 | ||
| 7 | 	__asm__ ("psrld $1, %0" : "+x"(t)); // t >>= 1 | ||
| 8 | 	__asm__ ("andps %1, %0" : "+x"(x) : "x"(t)); // x &= t | ||
| 9 | 	return x; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fabsl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double fabsl(long double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fabs" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/floorl.s created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | .global floorl | ||
| 2 | .type floorl,@function | ||
| 3 | floorl: | ||
| 4 | 	fldt 8(%rsp) | ||
| 5 | 1:	mov $0x7,%al | ||
| 6 | 1:	fstcw 8(%rsp) | ||
| 7 | 	mov 9(%rsp),%ah | ||
| 8 | 	mov %al,9(%rsp) | ||
| 9 | 	fldcw 8(%rsp) | ||
| 10 | 	frndint | ||
| 11 | 	mov %ah,9(%rsp) | ||
| 12 | 	fldcw 8(%rsp) | ||
| 13 | 	ret | ||
| 14 | |||
| 15 | .global ceill | ||
| 16 | .type ceill,@function | ||
| 17 | ceill: | ||
| 18 | 	fldt 8(%rsp) | ||
| 19 | 	mov $0xb,%al | ||
| 20 | 	jmp 1b | ||
| 21 | |||
| 22 | .global truncl | ||
| 23 | .type truncl,@function | ||
| 24 | truncl: | ||
| 25 | 	fldt 8(%rsp) | ||
| 26 | 	mov $0xf,%al | ||
| 27 | 	jmp 1b | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fma.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __FMA__ | ||
| 4 | |||
| 5 | double fma(double x, double y, double z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vfmadd132sd %1, %2, %0" : "+x" (x) : "x" (y), "x" (z)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #elif __FMA4__ | ||
| 12 | |||
| 13 | double fma(double x, double y, double z) | ||
| 14 | { | ||
| 15 | 	__asm__ ("vfmaddsd %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z)); | ||
| 16 | 	return x; | ||
| 17 | } | ||
| 18 | |||
| 19 | #else | ||
| 20 | |||
| 21 | #include "../fma.c" | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fmaf.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | #if __FMA__ | ||
| 4 | |||
| 5 | float fmaf(float x, float y, float z) | ||
| 6 | { | ||
| 7 | 	__asm__ ("vfmadd132ss %1, %2, %0" : "+x" (x) : "x" (y), "x" (z)); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | #elif __FMA4__ | ||
| 12 | |||
| 13 | float fmaf(float x, float y, float z) | ||
| 14 | { | ||
| 15 | 	__asm__ ("vfmaddss %3, %2, %1, %0" : "=x" (x) : "x" (x), "x" (y), "x" (z)); | ||
| 16 | 	return x; | ||
| 17 | } | ||
| 18 | |||
| 19 | #else | ||
| 20 | |||
| 21 | #include "../fmaf.c" | ||
| 22 | |||
| 23 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/fmodl.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double fmodl(long double x, long double y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	do __asm__ ("fprem; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 7 | 	while (fpsr & 0x400); | ||
| 8 | 	return x; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrint.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrint(double x) | ||
| 4 | { | ||
| 5 | 	long long r; | ||
| 6 | 	__asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x)); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrintf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrintf(float x) | ||
| 4 | { | ||
| 5 | 	long long r; | ||
| 6 | 	__asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x)); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/llrintl.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long long llrintl(long double x) | ||
| 4 | { | ||
| 5 | 	long long r; | ||
| 6 | 	__asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log10l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global log10l | ||
| 2 | .type log10l,@function | ||
| 3 | log10l: | ||
| 4 | 	fldlg2 | ||
| 5 | 	fldt 8(%rsp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log1pl.s created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | .global log1pl | ||
| 2 | .type log1pl,@function | ||
| 3 | log1pl: | ||
| 4 | 	mov 14(%rsp),%eax | ||
| 5 | 	fldln2 | ||
| 6 | 	and $0x7fffffff,%eax | ||
| 7 | 	fldt 8(%rsp) | ||
| 8 | 	cmp $0x3ffd9400,%eax | ||
| 9 | 	ja 1f | ||
| 10 | 	fyl2xp1 | ||
| 11 | 	ret | ||
| 12 | 1:	fld1 | ||
| 13 | 	faddp | ||
| 14 | 	fyl2x | ||
| 15 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/log2l.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global log2l | ||
| 2 | .type log2l,@function | ||
| 3 | log2l: | ||
| 4 | 	fld1 | ||
| 5 | 	fldt 8(%rsp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/logl.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global logl | ||
| 2 | .type logl,@function | ||
| 3 | logl: | ||
| 4 | 	fldln2 | ||
| 5 | 	fldt 8(%rsp) | ||
| 6 | 	fyl2x | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrint.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrint(double x) | ||
| 4 | { | ||
| 5 | 	long r; | ||
| 6 | 	__asm__ ("cvtsd2si %1, %0" : "=r"(r) : "x"(x)); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrintf.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrintf(float x) | ||
| 4 | { | ||
| 5 | 	long r; | ||
| 6 | 	__asm__ ("cvtss2si %1, %0" : "=r"(r) : "x"(x)); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/lrintl.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long lrintl(long double x) | ||
| 4 | { | ||
| 5 | 	long r; | ||
| 6 | 	__asm__ ("fistpll %0" : "=m"(r) : "t"(x) : "st"); | ||
| 7 | 	return r; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/remainderl.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double remainderl(long double x, long double y) | ||
| 4 | { | ||
| 5 | 	unsigned short fpsr; | ||
| 6 | 	do __asm__ ("fprem1; fnstsw %%ax" : "+t"(x), "=a"(fpsr) : "u"(y)); | ||
| 7 | 	while (fpsr & 0x400); | ||
| 8 | 	return x; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/remquol.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double remquol(long double x, long double y, int *quo) | ||
| 4 | { | ||
| 5 | 	signed char *cx = (void *)&x, *cy = (void *)&y; | ||
| 6 | 	/* By ensuring that addresses of x and y cannot be discarded, | ||
| 7 | 	 * this empty asm guides GCC into representing extraction of | ||
| 8 | 	 * their sign bits as memory loads rather than making x and y | ||
| 9 | 	 * not-address-taken internally and using bitfield operations, | ||
| 10 | 	 * which in the end wouldn't work out, as extraction from FPU | ||
| 11 | 	 * registers needs to go through memory anyway. This way GCC | ||
| 12 | 	 * should manage to use incoming stack slots without spills. */ | ||
| 13 | 	__asm__ ("" :: "X"(cx), "X"(cy)); | ||
| 14 | |||
| 15 | 	long double t = x; | ||
| 16 | 	unsigned fpsr; | ||
| 17 | 	do __asm__ ("fprem1; fnstsw %%ax" : "+t"(t), "=a"(fpsr) : "u"(y)); | ||
| 18 | 	while (fpsr & 0x400); | ||
| 19 | 	/* C0, C1, C3 flags in x87 status word carry low bits of quotient: | ||
| 20 | 	 * 15 14 13 12 11 10 9 8 | ||
| 21 | 	 * . C3 . . . C2 C1 C0 | ||
| 22 | 	 * . b1 . . . 0 b0 b2 */ | ||
| 23 | 	unsigned char i = fpsr >> 8; | ||
| 24 | 	i = i>>4 | i<<4; | ||
| 25 | 	/* i[5:2] is now {b0 b2 ? b1}. Retrieve {0 b2 b1 b0} via | ||
| 26 | 	 * in-register table lookup. */ | ||
| 27 | 	unsigned qbits = 0x7575313164642020 >> (i & 60); | ||
| 28 | 	qbits &= 7; | ||
| 29 | |||
| 30 | 	*quo = (cx[9]^cy[9]) < 0 ? -qbits : qbits; | ||
| 31 | 	return t; | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/rintl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double rintl(long double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("frndint" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrt.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | double sqrt(double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("sqrtsd %1, %0" : "=x"(x) : "x"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrtf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | float sqrtf(float x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("sqrtss %1, %0" : "=x"(x) : "x"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/sqrtl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <math.h> | ||
| 2 | |||
| 3 | long double sqrtl(long double x) | ||
| 4 | { | ||
| 5 | 	__asm__ ("fsqrt" : "+t"(x)); | ||
| 6 | 	return x; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/math/x86_64/truncl.s created+1| ... | @@ -0,0 +1 @@ | ||
| 1 | # see floorl.s | ||
lib/libc/wasi/libc-top-half/musl/src/misc/a64l.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | static const char digits[] = | ||
| 6 | 	"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; | ||
| 7 | |||
| 8 | long a64l(const char *s) | ||
| 9 | { | ||
| 10 | 	int e; | ||
| 11 | 	uint32_t x = 0; | ||
| 12 | 	for (e=0; e<36 && *s; e+=6, s++) { | ||
| 13 | 		const char *d = strchr(digits, *s); | ||
| 14 | 		if (!d) break; | ||
| 15 | 		x |= (uint32_t)(d-digits)<<e; | ||
| 16 | 	} | ||
| 17 | 	return (int32_t)x; | ||
| 18 | } | ||
| 19 | |||
| 20 | char *l64a(long x0) | ||
| 21 | { | ||
| 22 | 	static char s[7]; | ||
| 23 | 	char *p; | ||
| 24 | 	uint32_t x = x0; | ||
| 25 | 	for (p=s; x; p++, x>>=6) | ||
| 26 | 		*p = digits[x&63]; | ||
| 27 | 	*p = 0; | ||
| 28 | 	return s; | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/basename.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <libgen.h> | ||
| 3 | |||
| 4 | char *basename(char *s) | ||
| 5 | { | ||
| 6 | 	size_t i; | ||
| 7 | 	if (!s || !*s) return "."; | ||
| 8 | 	i = strlen(s)-1; | ||
| 9 | 	for (; i&&s[i]=='/'; i--) s[i] = 0; | ||
| 10 | 	for (; i&&s[i-1]!='/'; i--); | ||
| 11 | 	return s+i; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(basename, __xpg_basename); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/dirname.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <libgen.h> | ||
| 3 | |||
| 4 | char *dirname(char *s) | ||
| 5 | { | ||
| 6 | 	size_t i; | ||
| 7 | 	if (!s || !*s) return "."; | ||
| 8 | 	i = strlen(s)-1; | ||
| 9 | 	for (; s[i]=='/'; i--) if (!i) return "/"; | ||
| 10 | 	for (; s[i]!='/'; i--) if (!i) return "."; | ||
| 11 | 	for (; s[i]=='/'; i--) if (!i) return "/"; | ||
| 12 | 	s[i+1] = 0; | ||
| 13 | 	return s; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/ffs.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <strings.h> | ||
| 2 | #include "atomic.h" | ||
| 3 | |||
| 4 | int ffs(int i) | ||
| 5 | { | ||
| 6 | 	return i ? a_ctz_l(i)+1 : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/ffsl.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <strings.h> | ||
| 2 | #include "atomic.h" | ||
| 3 | |||
| 4 | int ffsl(long i) | ||
| 5 | { | ||
| 6 | 	return i ? a_ctz_l(i)+1 : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/ffsll.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <strings.h> | ||
| 2 | #include "atomic.h" | ||
| 3 | |||
| 4 | int ffsll(long long i) | ||
| 5 | { | ||
| 6 | 	return i ? a_ctz_64(i)+1 : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/fmtmsg.c created+96| ... | @@ -0,0 +1,96 @@ | ||
| 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/forkpty.c created+57| ... | @@ -0,0 +1,57 @@ | ||
| 1 | #include <pty.h> | ||
| 2 | #include <utmp.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <fcntl.h> | ||
| 6 | #include <sys/wait.h> | ||
| 7 | #include <pthread.h> | ||
| 8 | |||
| 9 | int forkpty(int *pm, char *name, const struct termios *tio, const struct winsize *ws) | ||
| 10 | { | ||
| 11 | 	int m, s, ec=0, p[2], cs; | ||
| 12 | 	pid_t pid=-1; | ||
| 13 | 	sigset_t set, oldset; | ||
| 14 | |||
| 15 | 	if (openpty(&m, &s, name, tio, ws) < 0) return -1; | ||
| 16 | |||
| 17 | 	sigfillset(&set); | ||
| 18 | 	pthread_sigmask(SIG_BLOCK, &set, &oldset); | ||
| 19 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 20 | |||
| 21 | 	if (pipe2(p, O_CLOEXEC)) { | ||
| 22 | 		close(s); | ||
| 23 | 		goto out; | ||
| 24 | 	} | ||
| 25 | |||
| 26 | 	pid = fork(); | ||
| 27 | 	if (!pid) { | ||
| 28 | 		close(m); | ||
| 29 | 		close(p[0]); | ||
| 30 | 		if (login_tty(s)) { | ||
| 31 | 			write(p[1], &errno, sizeof errno); | ||
| 32 | 			_exit(127); | ||
| 33 | 		} | ||
| 34 | 		close(p[1]); | ||
| 35 | 		pthread_setcancelstate(cs, 0); | ||
| 36 | 		pthread_sigmask(SIG_SETMASK, &oldset, 0); | ||
| 37 | 		return 0; | ||
| 38 | 	} | ||
| 39 | 	close(s); | ||
| 40 | 	close(p[1]); | ||
| 41 | 	if (read(p[0], &ec, sizeof ec) > 0) { | ||
| 42 | 		int status; | ||
| 43 | 		waitpid(pid, &status, 0); | ||
| 44 | 		pid = -1; | ||
| 45 | 		errno = ec; | ||
| 46 | 	} | ||
| 47 | 	close(p[0]); | ||
| 48 | |||
| 49 | out: | ||
| 50 | 	if (pid > 0) *pm = m; | ||
| 51 | 	else close(m); | ||
| 52 | |||
| 53 | 	pthread_setcancelstate(cs, 0); | ||
| 54 | 	pthread_sigmask(SIG_SETMASK, &oldset, 0); | ||
| 55 | |||
| 56 | 	return pid; | ||
| 57 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/get_current_dir_name.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <sys/stat.h> | ||
| 7 | |||
| 8 | char *get_current_dir_name(void) { | ||
| 9 | 	struct stat a, b; | ||
| 10 | 	char *res = getenv("PWD"); | ||
| 11 | 	if (res && *res && !stat(res, &a) && !stat(".", &b) | ||
| 12 | 	 && (a.st_dev == b.st_dev) && (a.st_ino == b.st_ino)) | ||
| 13 | 		return strdup(res); | ||
| 14 | 	return getcwd(0, 0); | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getauxval.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <sys/auxv.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | unsigned long __getauxval(unsigned long item) | ||
| 6 | { | ||
| 7 | 	size_t *auxv = libc.auxv; | ||
| 8 | 	if (item == AT_SECURE) return libc.secure; | ||
| 9 | 	for (; *auxv; auxv+=2) | ||
| 10 | 		if (*auxv==item) return auxv[1]; | ||
| 11 | 	errno = ENOENT; | ||
| 12 | 	return 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(__getauxval, getauxval); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getdomainname.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <sys/utsname.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <errno.h> | ||
| 6 | |||
| 7 | int getdomainname(char *name, size_t len) | ||
| 8 | { | ||
| 9 | 	struct utsname temp; | ||
| 10 | 	uname(&temp); | ||
| 11 | 	if (!len || strlen(temp.domainname) >= len) { | ||
| 12 | 		errno = EINVAL; | ||
| 13 | 		return -1; | ||
| 14 | 	} | ||
| 15 | 	strcpy(name, temp.domainname); | ||
| 16 | 	return 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getentropy.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <sys/random.h> | ||
| 4 | #include <pthread.h> | ||
| 5 | #include <errno.h> | ||
| 6 | |||
| 7 | int getentropy(void *buffer, size_t len) | ||
| 8 | { | ||
| 9 | 	int cs, ret = 0; | ||
| 10 | 	char *pos = buffer; | ||
| 11 | |||
| 12 | 	if (len > 256) { | ||
| 13 | 		errno = EIO; | ||
| 14 | 		return -1; | ||
| 15 | 	} | ||
| 16 | |||
| 17 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 18 | |||
| 19 | 	while (len) { | ||
| 20 | 		ret = getrandom(pos, len, 0); | ||
| 21 | 		if (ret < 0) { | ||
| 22 | 			if (errno == EINTR) continue; | ||
| 23 | 			else break; | ||
| 24 | 		} | ||
| 25 | 		pos += ret; | ||
| 26 | 		len -= ret; | ||
| 27 | 		ret = 0; | ||
| 28 | 	} | ||
| 29 | |||
| 30 | 	pthread_setcancelstate(cs, 0); | ||
| 31 | |||
| 32 | 	return ret; | ||
| 33 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/gethostid.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | long gethostid() | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getopt.c created+105| ... | @@ -0,0 +1,105 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "locale_impl.h" | ||
| 8 | #include "stdio_impl.h" | ||
| 9 | |||
| 10 | char *optarg; | ||
| 11 | int optind=1, opterr=1, optopt, __optpos, __optreset=0; | ||
| 12 | |||
| 13 | #define optpos __optpos | ||
| 14 | weak_alias(__optreset, optreset); | ||
| 15 | |||
| 16 | void __getopt_msg(const char *a, const char *b, const char *c, size_t l) | ||
| 17 | { | ||
| 18 | 	FILE *f = stderr; | ||
| 19 | 	b = __lctrans_cur(b); | ||
| 20 | 	FLOCK(f); | ||
| 21 | 	fputs(a, f)>=0 | ||
| 22 | 	&& fwrite(b, strlen(b), 1, f) | ||
| 23 | 	&& fwrite(c, 1, l, f)==l | ||
| 24 | 	&& putc('\n', f); | ||
| 25 | 	FUNLOCK(f); | ||
| 26 | } | ||
| 27 | |||
| 28 | int getopt(int argc, char * const argv[], const char *optstring) | ||
| 29 | { | ||
| 30 | 	int i; | ||
| 31 | 	wchar_t c, d; | ||
| 32 | 	int k, l; | ||
| 33 | 	char *optchar; | ||
| 34 | |||
| 35 | 	if (!optind || __optreset) { | ||
| 36 | 		__optreset = 0; | ||
| 37 | 		__optpos = 0; | ||
| 38 | 		optind = 1; | ||
| 39 | 	} | ||
| 40 | |||
| 41 | 	if (optind >= argc || !argv[optind]) | ||
| 42 | 		return -1; | ||
| 43 | |||
| 44 | 	if (argv[optind][0] != '-') { | ||
| 45 | 		if (optstring[0] == '-') { | ||
| 46 | 			optarg = argv[optind++]; | ||
| 47 | 			return 1; | ||
| 48 | 		} | ||
| 49 | 		return -1; | ||
| 50 | 	} | ||
| 51 | |||
| 52 | 	if (!argv[optind][1]) | ||
| 53 | 		return -1; | ||
| 54 | |||
| 55 | 	if (argv[optind][1] == '-' && !argv[optind][2]) | ||
| 56 | 		return optind++, -1; | ||
| 57 | |||
| 58 | 	if (!optpos) optpos++; | ||
| 59 | 	if ((k = mbtowc(&c, argv[optind]+optpos, MB_LEN_MAX)) < 0) { | ||
| 60 | 		k = 1; | ||
| 61 | 		c = 0xfffd; /* replacement char */ | ||
| 62 | 	} | ||
| 63 | 	optchar = argv[optind]+optpos; | ||
| 64 | 	optpos += k; | ||
| 65 | |||
| 66 | 	if (!argv[optind][optpos]) { | ||
| 67 | 		optind++; | ||
| 68 | 		optpos = 0; | ||
| 69 | 	} | ||
| 70 | |||
| 71 | 	if (optstring[0] == '-' || optstring[0] == '+') | ||
| 72 | 		optstring++; | ||
| 73 | |||
| 74 | 	i = 0; | ||
| 75 | 	d = 0; | ||
| 76 | 	do { | ||
| 77 | 		l = mbtowc(&d, optstring+i, MB_LEN_MAX); | ||
| 78 | 		if (l>0) i+=l; else i++; | ||
| 79 | 	} while (l && d != c); | ||
| 80 | |||
| 81 | 	if (d != c || c == ':') { | ||
| 82 | 		optopt = c; | ||
| 83 | 		if (optstring[0] != ':' && opterr) | ||
| 84 | 			__getopt_msg(argv[0], ": unrecognized option: ", optchar, k); | ||
| 85 | 		return '?'; | ||
| 86 | 	} | ||
| 87 | 	if (optstring[i] == ':') { | ||
| 88 | 		optarg = 0; | ||
| 89 | 		if (optstring[i+1] != ':' || optpos) { | ||
| 90 | 			optarg = argv[optind++] + optpos; | ||
| 91 | 			optpos = 0; | ||
| 92 | 		} | ||
| 93 | 		if (optind > argc) { | ||
| 94 | 			optopt = c; | ||
| 95 | 			if (optstring[0] == ':') return ':'; | ||
| 96 | 			if (opterr) __getopt_msg(argv[0], | ||
| 97 | 				": option requires an argument: ", | ||
| 98 | 				optchar, k); | ||
| 99 | 			return '?'; | ||
| 100 | 		} | ||
| 101 | 	} | ||
| 102 | 	return c; | ||
| 103 | } | ||
| 104 | |||
| 105 | weak_alias(getopt, __posix_getopt); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getopt_long.c created+148| ... | @@ -0,0 +1,148 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stddef.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <getopt.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include "stdio_impl.h" | ||
| 9 | |||
| 10 | extern int __optpos, __optreset; | ||
| 11 | |||
| 12 | static void permute(char *const *argv, int dest, int src) | ||
| 13 | { | ||
| 14 | 	char **av = (char **)argv; | ||
| 15 | 	char *tmp = av[src]; | ||
| 16 | 	int i; | ||
| 17 | 	for (i=src; i>dest; i--) | ||
| 18 | 		av[i] = av[i-1]; | ||
| 19 | 	av[dest] = tmp; | ||
| 20 | } | ||
| 21 | |||
| 22 | static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly); | ||
| 23 | |||
| 24 | static int __getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) | ||
| 25 | { | ||
| 26 | 	int ret, skipped, resumed; | ||
| 27 | 	if (!optind || __optreset) { | ||
| 28 | 		__optreset = 0; | ||
| 29 | 		__optpos = 0; | ||
| 30 | 		optind = 1; | ||
| 31 | 	} | ||
| 32 | 	if (optind >= argc || !argv[optind]) return -1; | ||
| 33 | 	skipped = optind; | ||
| 34 | 	if (optstring[0] != '+' && optstring[0] != '-') { | ||
| 35 | 		int i; | ||
| 36 | 		for (i=optind; ; i++) { | ||
| 37 | 			if (i >= argc || !argv[i]) return -1; | ||
| 38 | 			if (argv[i][0] == '-' && argv[i][1]) break; | ||
| 39 | 		} | ||
| 40 | 		optind = i; | ||
| 41 | 	} | ||
| 42 | 	resumed = optind; | ||
| 43 | 	ret = __getopt_long_core(argc, argv, optstring, longopts, idx, longonly); | ||
| 44 | 	if (resumed > skipped) { | ||
| 45 | 		int i, cnt = optind-resumed; | ||
| 46 | 		for (i=0; i<cnt; i++) | ||
| 47 | 			permute(argv, skipped, optind-1); | ||
| 48 | 		optind = skipped + cnt; | ||
| 49 | 	} | ||
| 50 | 	return ret; | ||
| 51 | } | ||
| 52 | |||
| 53 | static int __getopt_long_core(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx, int longonly) | ||
| 54 | { | ||
| 55 | 	optarg = 0; | ||
| 56 | 	if (longopts && argv[optind][0] == '-' && | ||
| 57 | 		((longonly && argv[optind][1] && argv[optind][1] != '-') || | ||
| 58 | 		 (argv[optind][1] == '-' && argv[optind][2]))) | ||
| 59 | 	{ | ||
| 60 | 		int colon = optstring[optstring[0]=='+'||optstring[0]=='-']==':'; | ||
| 61 | 		int i, cnt, match; | ||
| 62 | 		char *arg, *opt, *start = argv[optind]+1; | ||
| 63 | 		for (cnt=i=0; longopts[i].name; i++) { | ||
| 64 | 			const char *name = longopts[i].name; | ||
| 65 | 			opt = start; | ||
| 66 | 			if (*opt == '-') opt++; | ||
| 67 | 			while (*opt && *opt != '=' && *opt == *name) | ||
| 68 | 				name++, opt++; | ||
| 69 | 			if (*opt && *opt != '=') continue; | ||
| 70 | 			arg = opt; | ||
| 71 | 			match = i; | ||
| 72 | 			if (!*name) { | ||
| 73 | 				cnt = 1; | ||
| 74 | 				break; | ||
| 75 | 			} | ||
| 76 | 			cnt++; | ||
| 77 | 		} | ||
| 78 | 		if (cnt==1 && longonly && arg-start == mblen(start, MB_LEN_MAX)) { | ||
| 79 | 			int l = arg-start; | ||
| 80 | 			for (i=0; optstring[i]; i++) { | ||
| 81 | 				int j; | ||
| 82 | 				for (j=0; j<l && start[j]==optstring[i+j]; j++); | ||
| 83 | 				if (j==l) { | ||
| 84 | 					cnt++; | ||
| 85 | 					break; | ||
| 86 | 				} | ||
| 87 | 			} | ||
| 88 | 		} | ||
| 89 | 		if (cnt==1) { | ||
| 90 | 			i = match; | ||
| 91 | 			opt = arg; | ||
| 92 | 			optind++; | ||
| 93 | 			if (*opt == '=') { | ||
| 94 | 				if (!longopts[i].has_arg) { | ||
| 95 | 					optopt = longopts[i].val; | ||
| 96 | 					if (colon || !opterr) | ||
| 97 | 						return '?'; | ||
| 98 | 					__getopt_msg(argv[0], | ||
| 99 | 						": option does not take an argument: ", | ||
| 100 | 						longopts[i].name, | ||
| 101 | 						strlen(longopts[i].name)); | ||
| 102 | 					return '?'; | ||
| 103 | 				} | ||
| 104 | 				optarg = opt+1; | ||
| 105 | 			} else if (longopts[i].has_arg == required_argument) { | ||
| 106 | 				if (!(optarg = argv[optind])) { | ||
| 107 | 					optopt = longopts[i].val; | ||
| 108 | 					if (colon) return ':'; | ||
| 109 | 					if (!opterr) return '?'; | ||
| 110 | 					__getopt_msg(argv[0], | ||
| 111 | 						": option requires an argument: ", | ||
| 112 | 						longopts[i].name, | ||
| 113 | 						strlen(longopts[i].name)); | ||
| 114 | 					return '?'; | ||
| 115 | 				} | ||
| 116 | 				optind++; | ||
| 117 | 			} | ||
| 118 | 			if (idx) *idx = i; | ||
| 119 | 			if (longopts[i].flag) { | ||
| 120 | 				*longopts[i].flag = longopts[i].val; | ||
| 121 | 				return 0; | ||
| 122 | 			} | ||
| 123 | 			return longopts[i].val; | ||
| 124 | 		} | ||
| 125 | 		if (argv[optind][1] == '-') { | ||
| 126 | 			optopt = 0; | ||
| 127 | 			if (!colon && opterr) | ||
| 128 | 				__getopt_msg(argv[0], cnt ? | ||
| 129 | 					": option is ambiguous: " : | ||
| 130 | 					": unrecognized option: ", | ||
| 131 | 					argv[optind]+2, | ||
| 132 | 					strlen(argv[optind]+2)); | ||
| 133 | 			optind++; | ||
| 134 | 			return '?'; | ||
| 135 | 		} | ||
| 136 | 	} | ||
| 137 | 	return getopt(argc, argv, optstring); | ||
| 138 | } | ||
| 139 | |||
| 140 | int getopt_long(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx) | ||
| 141 | { | ||
| 142 | 	return __getopt_long(argc, argv, optstring, longopts, idx, 0); | ||
| 143 | } | ||
| 144 | |||
| 145 | int getopt_long_only(int argc, char *const *argv, const char *optstring, const struct option *longopts, int *idx) | ||
| 146 | { | ||
| 147 | 	return __getopt_long(argc, argv, optstring, longopts, idx, 1); | ||
| 148 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getpriority.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <sys/resource.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int getpriority(int which, id_t who) | ||
| 5 | { | ||
| 6 | 	int ret = syscall(SYS_getpriority, which, who); | ||
| 7 | 	if (ret < 0) return ret; | ||
| 8 | 	return 20-ret; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getresgid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int getresgid(gid_t *rgid, gid_t *egid, gid_t *sgid) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_getresgid, rgid, egid, sgid); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getresuid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int getresuid(uid_t *ruid, uid_t *euid, uid_t *suid) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_getresuid, ruid, euid, suid); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getrlimit.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <sys/resource.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0) | ||
| 6 | |||
| 7 | int getrlimit(int resource, struct rlimit *rlim) | ||
| 8 | { | ||
| 9 | 	unsigned long k_rlim[2]; | ||
| 10 | 	int ret = syscall(SYS_prlimit64, 0, resource, 0, rlim); | ||
| 11 | 	if (!ret) { | ||
| 12 | 		FIX(rlim->rlim_cur); | ||
| 13 | 		FIX(rlim->rlim_max); | ||
| 14 | 	} | ||
| 15 | 	if (!ret || errno != ENOSYS) | ||
| 16 | 		return ret; | ||
| 17 | 	if (syscall(SYS_getrlimit, resource, k_rlim) < 0) | ||
| 18 | 		return -1; | ||
| 19 | 	rlim->rlim_cur = k_rlim[0] == -1UL ? RLIM_INFINITY : k_rlim[0]; | ||
| 20 | 	rlim->rlim_max = k_rlim[1] == -1UL ? RLIM_INFINITY : k_rlim[1]; | ||
| 21 | 	FIX(rlim->rlim_cur); | ||
| 22 | 	FIX(rlim->rlim_max); | ||
| 23 | 	return 0; | ||
| 24 | } | ||
| 25 | |||
| 26 | weak_alias(getrlimit, getrlimit64); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getrusage.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include <sys/resource.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int getrusage(int who, struct rusage *ru) | ||
| 7 | { | ||
| 8 | 	int r; | ||
| 9 | #ifdef SYS_getrusage_time64 | ||
| 10 | 	long long kru64[18]; | ||
| 11 | 	r = __syscall(SYS_getrusage_time64, who, kru64); | ||
| 12 | 	if (!r) { | ||
| 13 | 		ru->ru_utime = (struct timeval) | ||
| 14 | 			{ .tv_sec = kru64[0], .tv_usec = kru64[1] }; | ||
| 15 | 		ru->ru_stime = (struct timeval) | ||
| 16 | 			{ .tv_sec = kru64[2], .tv_usec = kru64[3] }; | ||
| 17 | 		char *slots = (char *)&ru->ru_maxrss; | ||
| 18 | 		for (int i=0; i<14; i++) | ||
| 19 | 			*(long *)(slots + i*sizeof(long)) = kru64[4+i]; | ||
| 20 | 	} | ||
| 21 | 	if (SYS_getrusage_time64 == SYS_getrusage || r != -ENOSYS) | ||
| 22 | 		return __syscall_ret(r); | ||
| 23 | #endif | ||
| 24 | 	char *dest = (char *)&ru->ru_maxrss - 4*sizeof(long); | ||
| 25 | 	r = __syscall(SYS_getrusage, who, dest); | ||
| 26 | 	if (!r && sizeof(time_t) > sizeof(long)) { | ||
| 27 | 		long kru[4]; | ||
| 28 | 		memcpy(kru, dest, 4*sizeof(long)); | ||
| 29 | 		ru->ru_utime = (struct timeval) | ||
| 30 | 			{ .tv_sec = kru[0], .tv_usec = kru[1] }; | ||
| 31 | 		ru->ru_stime = (struct timeval) | ||
| 32 | 			{ .tv_sec = kru[2], .tv_usec = kru[3] }; | ||
| 33 | 	} | ||
| 34 | 	return __syscall_ret(r); | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/getsubopt.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | int getsubopt(char **opt, char *const *keys, char **val) | ||
| 5 | { | ||
| 6 | 	char *s = *opt; | ||
| 7 | 	int i; | ||
| 8 | |||
| 9 | 	*val = NULL; | ||
| 10 | 	*opt = strchr(s, ','); | ||
| 11 | 	if (*opt) *(*opt)++ = 0; | ||
| 12 | 	else *opt = s + strlen(s); | ||
| 13 | |||
| 14 | 	for (i=0; keys[i]; i++) { | ||
| 15 | 		size_t l = strlen(keys[i]); | ||
| 16 | 		if (strncmp(keys[i], s, l)) continue; | ||
| 17 | 		if (s[l] == '=') | ||
| 18 | 			*val = s + l + 1; | ||
| 19 | 		else if (s[l]) continue; | ||
| 20 | 		return i; | ||
| 21 | 	} | ||
| 22 | 	return -1; | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/initgroups.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <grp.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | int initgroups(const char *user, gid_t gid) | ||
| 6 | { | ||
| 7 | 	gid_t groups[NGROUPS_MAX]; | ||
| 8 | 	int count = NGROUPS_MAX; | ||
| 9 | 	if (getgrouplist(user, gid, groups, &count) < 0) return -1; | ||
| 10 | 	return setgroups(count, groups); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/ioctl.c created+146| ... | @@ -0,0 +1,146 @@ | ||
| 1 | #include <sys/ioctl.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <time.h> | ||
| 5 | #include <sys/time.h> | ||
| 6 | #include <stddef.h> | ||
| 7 | #include <stdint.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include "syscall.h" | ||
| 10 | |||
| 11 | #define alignof(t) offsetof(struct { char c; t x; }, x) | ||
| 12 | |||
| 13 | #define W 1 | ||
| 14 | #define R 2 | ||
| 15 | #define WR 3 | ||
| 16 | |||
| 17 | struct ioctl_compat_map { | ||
| 18 | 	int new_req, old_req; | ||
| 19 | 	unsigned char old_size, dir, force_align, noffs; | ||
| 20 | 	unsigned char offsets[8]; | ||
| 21 | }; | ||
| 22 | |||
| 23 | #define NINTH(a,b,c,d,e,f,g,h,i,...) i | ||
| 24 | #define COUNT(...) NINTH(__VA_ARGS__,8,7,6,5,4,3,2,1,0) | ||
| 25 | #define OFFS(...) COUNT(__VA_ARGS__), { __VA_ARGS__ } | ||
| 26 | |||
| 27 | /* yields a type for a struct with original size n, with a misaligned | ||
| 28 | * timeval/timespec expanded from 32- to 64-bit. for use with ioctl | ||
| 29 | * number producing macros; only size of result is meaningful. */ | ||
| 30 | #define new_misaligned(n) struct { int i; time_t t; char c[(n)-4]; } | ||
| 31 | |||
| 32 | struct v4l2_event { | ||
| 33 | 	uint32_t a; | ||
| 34 | 	uint64_t b[8]; | ||
| 35 | 	uint32_t c[2], ts[2], d[9]; | ||
| 36 | }; | ||
| 37 | |||
| 38 | static const struct ioctl_compat_map compat_map[] = { | ||
| 39 | 	{ SIOCGSTAMP, SIOCGSTAMP_OLD, 8, R, 0, OFFS(0, 4) }, | ||
| 40 | 	{ SIOCGSTAMPNS, SIOCGSTAMPNS_OLD, 8, R, 0, OFFS(0, 4) }, | ||
| 41 | |||
| 42 | 	/* SNDRV_TIMER_IOCTL_STATUS */ | ||
| 43 | 	{ _IOR('T', 0x14, char[96]), _IOR('T', 0x14, 88), 88, R, 0, OFFS(0,4) }, | ||
| 44 | |||
| 45 | 	/* SNDRV_PCM_IOCTL_STATUS[_EXT] */ | ||
| 46 | 	{ _IOR('A', 0x20, char[128]), _IOR('A', 0x20, char[108]), 108, R, 1, OFFS(4,8,12,16,52,56,60,64) }, | ||
| 47 | 	{ _IOWR('A', 0x24, char[128]), _IOWR('A', 0x24, char[108]), 108, WR, 1, OFFS(4,8,12,16,52,56,60,64) }, | ||
| 48 | |||
| 49 | 	/* SNDRV_RAWMIDI_IOCTL_STATUS */ | ||
| 50 | 	{ _IOWR('W', 0x20, char[48]), _IOWR('W', 0x20, char[36]), 36, WR, 1, OFFS(4,8) }, | ||
| 51 | |||
| 52 | 	/* SNDRV_PCM_IOCTL_SYNC_PTR - with 3 subtables */ | ||
| 53 | 	{ _IOWR('A', 0x23, char[136]), _IOWR('A', 0x23, char[132]), 0, WR, 1, 0 }, | ||
| 54 | 	{ 0, 0, 4, WR, 1, 0 }, /* snd_pcm_sync_ptr (flags only) */ | ||
| 55 | 	{ 0, 0, 32, WR, 1, OFFS(8,12,16,24,28) }, /* snd_pcm_mmap_status */ | ||
| 56 | 	{ 0, 0, 8, WR, 1, OFFS(0,4) }, /* snd_pcm_mmap_control */ | ||
| 57 | |||
| 58 | 	/* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */ | ||
| 59 | 	{ _IOWR('V', 9, new_misaligned(68)), _IOWR('V', 9, char[68]), 68, WR, 1, OFFS(20, 24) }, | ||
| 60 | 	{ _IOWR('V', 15, new_misaligned(68)), _IOWR('V', 15, char[68]), 68, WR, 1, OFFS(20, 24) }, | ||
| 61 | 	{ _IOWR('V', 17, new_misaligned(68)), _IOWR('V', 17, char[68]), 68, WR, 1, OFFS(20, 24) }, | ||
| 62 | 	{ _IOWR('V', 93, new_misaligned(68)), _IOWR('V', 93, char[68]), 68, WR, 1, OFFS(20, 24) }, | ||
| 63 | |||
| 64 | 	/* VIDIOC_DQEVENT */ | ||
| 65 | 	{ _IOR('V', 89, new_misaligned(120)), _IOR('V', 89, struct v4l2_event), sizeof(struct v4l2_event), | ||
| 66 | 	 R, 0, OFFS(offsetof(struct v4l2_event, ts[0]), offsetof(struct v4l2_event, ts[1])) }, | ||
| 67 | |||
| 68 | 	/* VIDIOC_OMAP3ISP_STAT_REQ */ | ||
| 69 | 	{ _IOWR('V', 192+6, char[32]), _IOWR('V', 192+6, char[24]), 22, WR, 0, OFFS(0,4) }, | ||
| 70 | |||
| 71 | 	/* PPPIOCGIDLE */ | ||
| 72 | 	{ _IOR('t', 63, char[16]), _IOR('t', 63, char[8]), 8, R, 0, OFFS(0,4) }, | ||
| 73 | |||
| 74 | 	/* PPGETTIME, PPSETTIME */ | ||
| 75 | 	{ _IOR('p', 0x95, char[16]), _IOR('p', 0x95, char[8]), 8, R, 0, OFFS(0,4) }, | ||
| 76 | 	{ _IOW('p', 0x96, char[16]), _IOW('p', 0x96, char[8]), 8, W, 0, OFFS(0,4) }, | ||
| 77 | |||
| 78 | 	/* LPSETTIMEOUT */ | ||
| 79 | 	{ _IOW(0x6, 0xf, char[16]), 0x060f, 8, W, 0, OFFS(0,4) }, | ||
| 80 | }; | ||
| 81 | |||
| 82 | static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old, char *new, int dir) | ||
| 83 | { | ||
| 84 | 	int new_offset = 0; | ||
| 85 | 	int old_offset = 0; | ||
| 86 | 	int old_size = map->old_size; | ||
| 87 | 	if (!(dir & map->dir)) return; | ||
| 88 | 	if (!map->old_size) { | ||
| 89 | 		/* offsets hard-coded for SNDRV_PCM_IOCTL_SYNC_PTR; | ||
| 90 | 		 * if another exception appears this needs changing. */ | ||
| 91 | 		convert_ioctl_struct(map+1, old, new, dir); | ||
| 92 | 		convert_ioctl_struct(map+2, old+4, new+8, dir); | ||
| 93 | 		convert_ioctl_struct(map+3, old+68, new+72, dir); | ||
| 94 | 		return; | ||
| 95 | 	} | ||
| 96 | 	for (int i=0; i < map->noffs; i++) { | ||
| 97 | 		int ts_offset = map->offsets[i]; | ||
| 98 | 		int len = ts_offset-old_offset; | ||
| 99 | 		if (dir==W) memcpy(old+old_offset, new+new_offset, len); | ||
| 100 | 		else memcpy(new+new_offset, old+old_offset, len); | ||
| 101 | 		new_offset += len; | ||
| 102 | 		old_offset += len; | ||
| 103 | 		long long new_ts; | ||
| 104 | 		long old_ts; | ||
| 105 | 		int align = map->force_align ? sizeof(time_t) : alignof(time_t); | ||
| 106 | 		new_offset += (align-1) & -new_offset; | ||
| 107 | 		if (dir==W) { | ||
| 108 | 			memcpy(&new_ts, new+new_offset, sizeof new_ts); | ||
| 109 | 			old_ts = new_ts; | ||
| 110 | 			memcpy(old+old_offset, &old_ts, sizeof old_ts); | ||
| 111 | 		} else { | ||
| 112 | 			memcpy(&old_ts, old+old_offset, sizeof old_ts); | ||
| 113 | 			new_ts = old_ts; | ||
| 114 | 			memcpy(new+new_offset, &new_ts, sizeof new_ts); | ||
| 115 | 		} | ||
| 116 | 		new_offset += sizeof new_ts; | ||
| 117 | 		old_offset += sizeof old_ts; | ||
| 118 | 	} | ||
| 119 | 	if (dir==W) memcpy(old+old_offset, new+new_offset, old_size-old_offset); | ||
| 120 | 	else memcpy(new+new_offset, old+old_offset, old_size-old_offset); | ||
| 121 | } | ||
| 122 | |||
| 123 | int ioctl(int fd, int req, ...) | ||
| 124 | { | ||
| 125 | 	void *arg; | ||
| 126 | 	va_list ap; | ||
| 127 | 	va_start(ap, req); | ||
| 128 | 	arg = va_arg(ap, void *); | ||
| 129 | 	va_end(ap); | ||
| 130 | 	int r = __syscall(SYS_ioctl, fd, req, arg); | ||
| 131 | 	if (SIOCGSTAMP != SIOCGSTAMP_OLD && req && r==-ENOTTY) { | ||
| 132 | 		for (int i=0; i<sizeof compat_map/sizeof *compat_map; i++) { | ||
| 133 | 			if (compat_map[i].new_req != req) continue; | ||
| 134 | 			union { | ||
| 135 | 				long long align; | ||
| 136 | 				char buf[256]; | ||
| 137 | 			} u; | ||
| 138 | 			convert_ioctl_struct(&compat_map[i], u.buf, arg, W); | ||
| 139 | 			r = __syscall(SYS_ioctl, fd, compat_map[i].old_req, u.buf); | ||
| 140 | 			if (r<0) break; | ||
| 141 | 			convert_ioctl_struct(&compat_map[i], u.buf, arg, R); | ||
| 142 | 			break; | ||
| 143 | 		} | ||
| 144 | 	} | ||
| 145 | 	return __syscall_ret(r); | ||
| 146 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/issetugid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int issetugid(void) | ||
| 6 | { | ||
| 7 | 	return libc.secure; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/lockf.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int lockf(int fd, int op, off_t size) | ||
| 6 | { | ||
| 7 | 	struct flock l = { | ||
| 8 | 		.l_type = F_WRLCK, | ||
| 9 | 		.l_whence = SEEK_CUR, | ||
| 10 | 		.l_len = size, | ||
| 11 | 	}; | ||
| 12 | 	switch (op) { | ||
| 13 | 	case F_TEST: | ||
| 14 | 		l.l_type = F_RDLCK; | ||
| 15 | 		if (fcntl(fd, F_GETLK, &l) < 0) | ||
| 16 | 			return -1; | ||
| 17 | 		if (l.l_type == F_UNLCK || l.l_pid == getpid()) | ||
| 18 | 			return 0; | ||
| 19 | 		errno = EACCES; | ||
| 20 | 		return -1; | ||
| 21 | 	case F_ULOCK: | ||
| 22 | 		l.l_type = F_UNLCK; | ||
| 23 | 	case F_TLOCK: | ||
| 24 | 		return fcntl(fd, F_SETLK, &l); | ||
| 25 | 	case F_LOCK: | ||
| 26 | 		return fcntl(fd, F_SETLKW, &l); | ||
| 27 | 	} | ||
| 28 | 	errno = EINVAL; | ||
| 29 | 	return -1; | ||
| 30 | } | ||
| 31 | |||
| 32 | weak_alias(lockf, lockf64); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/login_tty.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <utmp.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int login_tty(int fd) | ||
| 6 | { | ||
| 7 | 	setsid(); | ||
| 8 | 	if (ioctl(fd, TIOCSCTTY, (char *)0)) return -1; | ||
| 9 | 	dup2(fd, 0); | ||
| 10 | 	dup2(fd, 1); | ||
| 11 | 	dup2(fd, 2); | ||
| 12 | 	if (fd>2) close(fd); | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/mntent.c created+77| ... | @@ -0,0 +1,77 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <mntent.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | static char *internal_buf; | ||
| 7 | static size_t internal_bufsize; | ||
| 8 | |||
| 9 | #define SENTINEL (char *)&internal_buf | ||
| 10 | |||
| 11 | FILE *setmntent(const char *name, const char *mode) | ||
| 12 | { | ||
| 13 | 	return fopen(name, mode); | ||
| 14 | } | ||
| 15 | |||
| 16 | int endmntent(FILE *f) | ||
| 17 | { | ||
| 18 | 	if (f) fclose(f); | ||
| 19 | 	return 1; | ||
| 20 | } | ||
| 21 | |||
| 22 | struct mntent *getmntent_r(FILE *f, struct mntent *mnt, char *linebuf, int buflen) | ||
| 23 | { | ||
| 24 | 	int cnt, n[8], use_internal = (linebuf == SENTINEL); | ||
| 25 | |||
| 26 | 	mnt->mnt_freq = 0; | ||
| 27 | 	mnt->mnt_passno = 0; | ||
| 28 | |||
| 29 | 	do { | ||
| 30 | 		if (use_internal) { | ||
| 31 | 			getline(&internal_buf, &internal_bufsize, f); | ||
| 32 | 			linebuf = internal_buf; | ||
| 33 | 		} else { | ||
| 34 | 			fgets(linebuf, buflen, f); | ||
| 35 | 		} | ||
| 36 | 		if (feof(f) || ferror(f)) return 0; | ||
| 37 | 		if (!strchr(linebuf, '\n')) { | ||
| 38 | 			fscanf(f, "%*[^\n]%*[\n]"); | ||
| 39 | 			errno = ERANGE; | ||
| 40 | 			return 0; | ||
| 41 | 		} | ||
| 42 | 		cnt = sscanf(linebuf, " %n%*s%n %n%*s%n %n%*s%n %n%*s%n %d %d", | ||
| 43 | 			n, n+1, n+2, n+3, n+4, n+5, n+6, n+7, | ||
| 44 | 			&mnt->mnt_freq, &mnt->mnt_passno); | ||
| 45 | 	} while (cnt < 2 || linebuf[n[0]] == '#'); | ||
| 46 | |||
| 47 | 	linebuf[n[1]] = 0; | ||
| 48 | 	linebuf[n[3]] = 0; | ||
| 49 | 	linebuf[n[5]] = 0; | ||
| 50 | 	linebuf[n[7]] = 0; | ||
| 51 | |||
| 52 | 	mnt->mnt_fsname = linebuf+n[0]; | ||
| 53 | 	mnt->mnt_dir = linebuf+n[2]; | ||
| 54 | 	mnt->mnt_type = linebuf+n[4]; | ||
| 55 | 	mnt->mnt_opts = linebuf+n[6]; | ||
| 56 | |||
| 57 | 	return mnt; | ||
| 58 | } | ||
| 59 | |||
| 60 | struct mntent *getmntent(FILE *f) | ||
| 61 | { | ||
| 62 | 	static struct mntent mnt; | ||
| 63 | 	return getmntent_r(f, &mnt, SENTINEL, 0); | ||
| 64 | } | ||
| 65 | |||
| 66 | int addmntent(FILE *f, const struct mntent *mnt) | ||
| 67 | { | ||
| 68 | 	if (fseek(f, 0, SEEK_END)) return 1; | ||
| 69 | 	return fprintf(f, "%s\t%s\t%s\t%s\t%d\t%d\n", | ||
| 70 | 		mnt->mnt_fsname, mnt->mnt_dir, mnt->mnt_type, mnt->mnt_opts, | ||
| 71 | 		mnt->mnt_freq, mnt->mnt_passno) < 0; | ||
| 72 | } | ||
| 73 | |||
| 74 | char *hasmntopt(const struct mntent *mnt, const char *opt) | ||
| 75 | { | ||
| 76 | 	return strstr(mnt->mnt_opts, opt); | ||
| 77 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/nftw.c created+148| ... | @@ -0,0 +1,148 @@ | ||
| 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 | 	if ((flags & FTW_PHYS) ? lstat(path, &st) : stat(path, &st) < 0) { | ||
| 37 | 		if (!(flags & FTW_PHYS) && errno==ENOENT && !lstat(path, &st)) | ||
| 38 | 			type = FTW_SLN; | ||
| 39 | 		else if (errno != EACCES) return -1; | ||
| 40 | 		else type = FTW_NS; | ||
| 41 | 	} else if (S_ISDIR(st.st_mode)) { | ||
| 42 | 		if (flags & FTW_DEPTH) type = FTW_DP; | ||
| 43 | 		else type = FTW_D; | ||
| 44 | 	} else if (S_ISLNK(st.st_mode)) { | ||
| 45 | 		if (flags & FTW_PHYS) type = FTW_SL; | ||
| 46 | 		else type = FTW_SLN; | ||
| 47 | 	} else { | ||
| 48 | 		type = FTW_F; | ||
| 49 | 	} | ||
| 50 | |||
| 51 | 	if ((flags & FTW_MOUNT) && h && st.st_dev != h->dev) | ||
| 52 | 		return 0; | ||
| 53 | 	 | ||
| 54 | 	new.chain = h; | ||
| 55 | 	new.dev = st.st_dev; | ||
| 56 | 	new.ino = st.st_ino; | ||
| 57 | 	new.level = h ? h->level+1 : 0; | ||
| 58 | 	new.base = j+1; | ||
| 59 | 	 | ||
| 60 | 	lev.level = new.level; | ||
| 61 | 	if (h) { | ||
| 62 | 		lev.base = h->base; | ||
| 63 | 	} else { | ||
| 64 | 		size_t k; | ||
| 65 | 		for (k=j; k && path[k]=='/'; k--); | ||
| 66 | 		for (; k && path[k-1]!='/'; k--); | ||
| 67 | 		lev.base = k; | ||
| 68 | 	} | ||
| 69 | |||
| 70 | 	if (type == FTW_D || type == FTW_DP) { | ||
| 71 | 		dfd = open(path, O_RDONLY); | ||
| 72 | 		err = errno; | ||
| 73 | 		if (dfd < 0 && err == EACCES) type = FTW_DNR; | ||
| 74 | 		if (!fd_limit) close(dfd); | ||
| 75 | 	} | ||
| 76 | |||
| 77 | 	if (!(flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) | ||
| 78 | 		return r; | ||
| 79 | |||
| 80 | 	for (; h; h = h->chain) | ||
| 81 | 		if (h->dev == st.st_dev && h->ino == st.st_ino) | ||
| 82 | 			return 0; | ||
| 83 | |||
| 84 | 	if ((type == FTW_D || type == FTW_DP) && fd_limit) { | ||
| 85 | 		if (dfd < 0) { | ||
| 86 | 			errno = err; | ||
| 87 | 			return -1; | ||
| 88 | 		} | ||
| 89 | 		DIR *d = fdopendir(dfd); | ||
| 90 | 		if (d) { | ||
| 91 | 			struct dirent *de; | ||
| 92 | 			while ((de = readdir(d))) { | ||
| 93 | 				if (de->d_name[0] == '.' | ||
| 94 | 				 && (!de->d_name[1] | ||
| 95 | 				 || (de->d_name[1]=='.' | ||
| 96 | 				 && !de->d_name[2]))) continue; | ||
| 97 | 				if (strlen(de->d_name) >= PATH_MAX-l) { | ||
| 98 | 					errno = ENAMETOOLONG; | ||
| 99 | 					closedir(d); | ||
| 100 | 					return -1; | ||
| 101 | 				} | ||
| 102 | 				path[j]='/'; | ||
| 103 | 				strcpy(path+j+1, de->d_name); | ||
| 104 | 				if ((r=do_nftw(path, fn, fd_limit-1, flags, &new))) { | ||
| 105 | 					closedir(d); | ||
| 106 | 					return r; | ||
| 107 | 				} | ||
| 108 | 			} | ||
| 109 | 			closedir(d); | ||
| 110 | 		} else { | ||
| 111 | 			close(dfd); | ||
| 112 | 			return -1; | ||
| 113 | 		} | ||
| 114 | 	} | ||
| 115 | |||
| 116 | 	path[l] = 0; | ||
| 117 | 	if ((flags & FTW_DEPTH) && (r=fn(path, &st, type, &lev))) | ||
| 118 | 		return r; | ||
| 119 | |||
| 120 | 	return 0; | ||
| 121 | } | ||
| 122 | |||
| 123 | int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, struct FTW *), int fd_limit, int flags) | ||
| 124 | { | ||
| 125 | 	int r, cs; | ||
| 126 | 	size_t l; | ||
| 127 | 	char pathbuf[PATH_MAX+1]; | ||
| 128 | |||
| 129 | 	if (fd_limit <= 0) return 0; | ||
| 130 | |||
| 131 | 	l = strlen(path); | ||
| 132 | 	if (l > PATH_MAX) { | ||
| 133 | 		errno = ENAMETOOLONG; | ||
| 134 | 		return -1; | ||
| 135 | 	} | ||
| 136 | 	memcpy(pathbuf, path, l+1); | ||
| 137 | 	 | ||
| 138 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 139 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 140 | #endif | ||
| 141 | 	r = do_nftw(pathbuf, fn, fd_limit, flags, NULL); | ||
| 142 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 143 | 	pthread_setcancelstate(cs, 0); | ||
| 144 | #endif | ||
| 145 | 	return r; | ||
| 146 | } | ||
| 147 | |||
| 148 | weak_alias(nftw, nftw64); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/openpty.c created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <pty.h> | ||
| 5 | #include <stdio.h> | ||
| 6 | #include <pthread.h> | ||
| 7 | |||
| 8 | /* Nonstandard, but vastly superior to the standard functions */ | ||
| 9 | |||
| 10 | int openpty(int *pm, int *ps, char *name, const struct termios *tio, const struct winsize *ws) | ||
| 11 | { | ||
| 12 | 	int m, s, n=0, cs; | ||
| 13 | 	char buf[20]; | ||
| 14 | |||
| 15 | 	m = open("/dev/ptmx", O_RDWR|O_NOCTTY); | ||
| 16 | 	if (m < 0) return -1; | ||
| 17 | |||
| 18 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 19 | |||
| 20 | 	if (ioctl(m, TIOCSPTLCK, &n) || ioctl (m, TIOCGPTN, &n)) | ||
| 21 | 		goto fail; | ||
| 22 | |||
| 23 | 	if (!name) name = buf; | ||
| 24 | 	snprintf(name, sizeof buf, "/dev/pts/%d", n); | ||
| 25 | 	if ((s = open(name, O_RDWR|O_NOCTTY)) < 0) | ||
| 26 | 		goto fail; | ||
| 27 | |||
| 28 | 	if (tio) tcsetattr(s, TCSANOW, tio); | ||
| 29 | 	if (ws) ioctl(s, TIOCSWINSZ, ws); | ||
| 30 | |||
| 31 | 	*pm = m; | ||
| 32 | 	*ps = s; | ||
| 33 | |||
| 34 | 	pthread_setcancelstate(cs, 0); | ||
| 35 | 	return 0; | ||
| 36 | fail: | ||
| 37 | 	close(m); | ||
| 38 | 	pthread_setcancelstate(cs, 0); | ||
| 39 | 	return -1; | ||
| 40 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/ptsname.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | char *ptsname(int fd) | ||
| 5 | { | ||
| 6 | 	static char buf[9 + sizeof(int)*3 + 1]; | ||
| 7 | 	int err = __ptsname_r(fd, buf, sizeof buf); | ||
| 8 | 	if (err) { | ||
| 9 | 		errno = err; | ||
| 10 | 		return 0; | ||
| 11 | 	} | ||
| 12 | 	return buf; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/pty.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | int posix_openpt(int flags) | ||
| 9 | { | ||
| 10 | 	int r = open("/dev/ptmx", flags); | ||
| 11 | 	if (r < 0 && errno == ENOSPC) errno = EAGAIN; | ||
| 12 | 	return r; | ||
| 13 | } | ||
| 14 | |||
| 15 | int grantpt(int fd) | ||
| 16 | { | ||
| 17 | 	return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | int unlockpt(int fd) | ||
| 21 | { | ||
| 22 | 	int unlock = 0; | ||
| 23 | 	return ioctl(fd, TIOCSPTLCK, &unlock); | ||
| 24 | } | ||
| 25 | |||
| 26 | int __ptsname_r(int fd, char *buf, size_t len) | ||
| 27 | { | ||
| 28 | 	int pty, err; | ||
| 29 | 	if (!buf) len = 0; | ||
| 30 | 	if ((err = __syscall(SYS_ioctl, fd, TIOCGPTN, &pty))) return -err; | ||
| 31 | 	if (snprintf(buf, len, "/dev/pts/%d", pty) >= len) return ERANGE; | ||
| 32 | 	return 0; | ||
| 33 | } | ||
| 34 | |||
| 35 | weak_alias(__ptsname_r, ptsname_r); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/realpath.c created+156| ... | @@ -0,0 +1,156 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | static size_t slash_len(const char *s) | ||
| 8 | { | ||
| 9 | 	const char *s0 = s; | ||
| 10 | 	while (*s == '/') s++; | ||
| 11 | 	return s-s0; | ||
| 12 | } | ||
| 13 | |||
| 14 | char *realpath(const char *restrict filename, char *restrict resolved) | ||
| 15 | { | ||
| 16 | 	char stack[PATH_MAX+1]; | ||
| 17 | 	char output[PATH_MAX]; | ||
| 18 | 	size_t p, q, l, l0, cnt=0, nup=0; | ||
| 19 | 	int check_dir=0; | ||
| 20 | |||
| 21 | 	if (!filename) { | ||
| 22 | 		errno = EINVAL; | ||
| 23 | 		return 0; | ||
| 24 | 	} | ||
| 25 | 	l = strnlen(filename, sizeof stack); | ||
| 26 | 	if (!l) { | ||
| 27 | 		errno = ENOENT; | ||
| 28 | 		return 0; | ||
| 29 | 	} | ||
| 30 | 	if (l >= PATH_MAX) goto toolong; | ||
| 31 | 	p = sizeof stack - l - 1; | ||
| 32 | 	q = 0; | ||
| 33 | 	memcpy(stack+p, filename, l+1); | ||
| 34 | |||
| 35 | 	/* Main loop. Each iteration pops the next part from stack of | ||
| 36 | 	 * remaining path components and consumes any slashes that follow. | ||
| 37 | 	 * If not a link, it's moved to output; if a link, contents are | ||
| 38 | 	 * pushed to the stack. */ | ||
| 39 | restart: | ||
| 40 | 	for (; ; p+=slash_len(stack+p)) { | ||
| 41 | 		/* If stack starts with /, the whole component is / or // | ||
| 42 | 		 * and the output state must be reset. */ | ||
| 43 | 		if (stack[p] == '/') { | ||
| 44 | 			check_dir=0; | ||
| 45 | 			nup=0; | ||
| 46 | 			q=0; | ||
| 47 | 			output[q++] = '/'; | ||
| 48 | 			p++; | ||
| 49 | 			/* Initial // is special. */ | ||
| 50 | 			if (stack[p] == '/' && stack[p+1] != '/') | ||
| 51 | 				output[q++] = '/'; | ||
| 52 | 			continue; | ||
| 53 | 		} | ||
| 54 | |||
| 55 | 		char *z = __strchrnul(stack+p, '/'); | ||
| 56 | 		l0 = l = z-(stack+p); | ||
| 57 | |||
| 58 | 		if (!l && !check_dir) break; | ||
| 59 | |||
| 60 | 		/* Skip any . component but preserve check_dir status. */ | ||
| 61 | 		if (l==1 && stack[p]=='.') { | ||
| 62 | 			p += l; | ||
| 63 | 			continue; | ||
| 64 | 		} | ||
| 65 | |||
| 66 | 		/* Copy next component onto output at least temporarily, to | ||
| 67 | 		 * call readlink, but wait to advance output position until | ||
| 68 | 		 * determining it's not a link. */ | ||
| 69 | 		if (q && output[q-1] != '/') { | ||
| 70 | 			if (!p) goto toolong; | ||
| 71 | 			stack[--p] = '/'; | ||
| 72 | 			l++; | ||
| 73 | 		} | ||
| 74 | 		if (q+l >= PATH_MAX) goto toolong; | ||
| 75 | 		memcpy(output+q, stack+p, l); | ||
| 76 | 		output[q+l] = 0; | ||
| 77 | 		p += l; | ||
| 78 | |||
| 79 | 		int up = 0; | ||
| 80 | 		if (l0==2 && stack[p-2]=='.' && stack[p-1]=='.') { | ||
| 81 | 			up = 1; | ||
| 82 | 			/* Any non-.. path components we could cancel start | ||
| 83 | 			 * after nup repetitions of the 3-byte string "../"; | ||
| 84 | 			 * if there are none, accumulate .. components to | ||
| 85 | 			 * later apply to cwd, if needed. */ | ||
| 86 | 			if (q <= 3*nup) { | ||
| 87 | 				nup++; | ||
| 88 | 				q += l; | ||
| 89 | 				continue; | ||
| 90 | 			} | ||
| 91 | 			/* When previous components are already known to be | ||
| 92 | 			 * directories, processing .. can skip readlink. */ | ||
| 93 | 			if (!check_dir) goto skip_readlink; | ||
| 94 | 		} | ||
| 95 | 		ssize_t k = readlink(output, stack, p); | ||
| 96 | 		if (k==p) goto toolong; | ||
| 97 | 		if (!k) { | ||
| 98 | 			errno = ENOENT; | ||
| 99 | 			return 0; | ||
| 100 | 		} | ||
| 101 | 		if (k<0) { | ||
| 102 | 			if (errno != EINVAL) return 0; | ||
| 103 | skip_readlink: | ||
| 104 | 			check_dir = 0; | ||
| 105 | 			if (up) { | ||
| 106 | 				while(q && output[q-1]!='/') q--; | ||
| 107 | 				if (q>1 && (q>2 || output[0]!='/')) q--; | ||
| 108 | 				continue; | ||
| 109 | 			} | ||
| 110 | 			if (l0) q += l; | ||
| 111 | 			check_dir = stack[p]; | ||
| 112 | 			continue; | ||
| 113 | 		} | ||
| 114 | 		if (++cnt == SYMLOOP_MAX) { | ||
| 115 | 			errno = ELOOP; | ||
| 116 | 			return 0; | ||
| 117 | 		} | ||
| 118 | |||
| 119 | 		/* If link contents end in /, strip any slashes already on | ||
| 120 | 		 * stack to avoid /->// or //->/// or spurious toolong. */ | ||
| 121 | 		if (stack[k-1]=='/') while (stack[p]=='/') p++; | ||
| 122 | 		p -= k; | ||
| 123 | 		memmove(stack+p, stack, k); | ||
| 124 | |||
| 125 | 		/* Skip the stack advancement in case we have a new | ||
| 126 | 		 * absolute base path. */ | ||
| 127 | 		goto restart; | ||
| 128 | 	} | ||
| 129 | |||
| 130 | 	output[q] = 0; | ||
| 131 | |||
| 132 | 	if (output[0] != '/') { | ||
| 133 | 		if (!getcwd(stack, sizeof stack)) return 0; | ||
| 134 | 		l = strlen(stack); | ||
| 135 | 		/* Cancel any initial .. components. */ | ||
| 136 | 		p = 0; | ||
| 137 | 		while (nup--) { | ||
| 138 | 			while(l>1 && stack[l-1]!='/') l--; | ||
| 139 | 			if (l>1) l--; | ||
| 140 | 			p += 2; | ||
| 141 | 			if (p<q) p++; | ||
| 142 | 		} | ||
| 143 | 		if (q-p && stack[l-1]!='/') stack[l++] = '/'; | ||
| 144 | 		if (l + (q-p) + 1 >= PATH_MAX) goto toolong; | ||
| 145 | 		memmove(output + l, output + p, q - p + 1); | ||
| 146 | 		memcpy(output, stack, l); | ||
| 147 | 		q = l + q-p; | ||
| 148 | 	} | ||
| 149 | |||
| 150 | 	if (resolved) return memcpy(resolved, output, q+1); | ||
| 151 | 	else return strdup(output); | ||
| 152 | |||
| 153 | toolong: | ||
| 154 | 	errno = ENAMETOOLONG; | ||
| 155 | 	return 0; | ||
| 156 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/setdomainname.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int setdomainname(const char *name, size_t len) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_setdomainname, name, len); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/setpriority.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/resource.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int setpriority(int which, id_t who, int prio) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_setpriority, which, who, prio); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/setrlimit.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #include <sys/resource.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "libc.h" | ||
| 5 | |||
| 6 | #define MIN(a, b) ((a)<(b) ? (a) : (b)) | ||
| 7 | #define FIX(x) do{ if ((x)>=SYSCALL_RLIM_INFINITY) (x)=RLIM_INFINITY; }while(0) | ||
| 8 | |||
| 9 | struct ctx { | ||
| 10 | 	unsigned long lim[2]; | ||
| 11 | 	int res; | ||
| 12 | 	int err; | ||
| 13 | }; | ||
| 14 | |||
| 15 | static void do_setrlimit(void *p) | ||
| 16 | { | ||
| 17 | 	struct ctx *c = p; | ||
| 18 | 	if (c->err>0) return; | ||
| 19 | 	c->err = -__syscall(SYS_setrlimit, c->res, c->lim); | ||
| 20 | } | ||
| 21 | |||
| 22 | int setrlimit(int resource, const struct rlimit *rlim) | ||
| 23 | { | ||
| 24 | 	struct rlimit tmp; | ||
| 25 | 	if (SYSCALL_RLIM_INFINITY != RLIM_INFINITY) { | ||
| 26 | 		tmp = *rlim; | ||
| 27 | 		FIX(tmp.rlim_cur); | ||
| 28 | 		FIX(tmp.rlim_max); | ||
| 29 | 		rlim = &tmp; | ||
| 30 | 	} | ||
| 31 | 	int ret = __syscall(SYS_prlimit64, 0, resource, rlim, 0); | ||
| 32 | 	if (ret != -ENOSYS) return __syscall_ret(ret); | ||
| 33 | |||
| 34 | 	struct ctx c = { | ||
| 35 | 		.lim[0] = MIN(rlim->rlim_cur, MIN(-1UL, SYSCALL_RLIM_INFINITY)), | ||
| 36 | 		.lim[1] = MIN(rlim->rlim_max, MIN(-1UL, SYSCALL_RLIM_INFINITY)), | ||
| 37 | 		.res = resource, .err = -1 | ||
| 38 | 	}; | ||
| 39 | 	__synccall(do_setrlimit, &c); | ||
| 40 | 	if (c.err) { | ||
| 41 | 		if (c.err>0) errno = c.err; | ||
| 42 | 		return -1; | ||
| 43 | 	} | ||
| 44 | 	return 0; | ||
| 45 | } | ||
| 46 | |||
| 47 | weak_alias(setrlimit, setrlimit64); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/syscall.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include <stdarg.h> | ||
| 5 | |||
| 6 | #undef syscall | ||
| 7 | |||
| 8 | long syscall(long n, ...) | ||
| 9 | { | ||
| 10 | 	va_list ap; | ||
| 11 | 	syscall_arg_t a,b,c,d,e,f; | ||
| 12 | 	va_start(ap, n); | ||
| 13 | 	a=va_arg(ap, syscall_arg_t); | ||
| 14 | 	b=va_arg(ap, syscall_arg_t); | ||
| 15 | 	c=va_arg(ap, syscall_arg_t); | ||
| 16 | 	d=va_arg(ap, syscall_arg_t); | ||
| 17 | 	e=va_arg(ap, syscall_arg_t); | ||
| 18 | 	f=va_arg(ap, syscall_arg_t); | ||
| 19 | 	va_end(ap); | ||
| 20 | 	return __syscall_ret(__syscall(n,a,b,c,d,e,f)); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/syslog.c created+162| ... | @@ -0,0 +1,162 @@ | ||
| 1 | #include <stdarg.h> | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <syslog.h> | ||
| 6 | #include <time.h> | ||
| 7 | #include <signal.h> | ||
| 8 | #include <string.h> | ||
| 9 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 10 | #include <pthread.h> | ||
| 11 | #endif | ||
| 12 | #include <errno.h> | ||
| 13 | #include <fcntl.h> | ||
| 14 | #include "lock.h" | ||
| 15 | #include "fork_impl.h" | ||
| 16 | |||
| 17 | static volatile int lock[1]; | ||
| 18 | static char log_ident[32]; | ||
| 19 | static int log_opt; | ||
| 20 | static int log_facility = LOG_USER; | ||
| 21 | static int log_mask = 0xff; | ||
| 22 | static int log_fd = -1; | ||
| 23 | volatile int *const __syslog_lockptr = lock; | ||
| 24 | |||
| 25 | int setlogmask(int maskpri) | ||
| 26 | { | ||
| 27 | 	LOCK(lock); | ||
| 28 | 	int ret = log_mask; | ||
| 29 | 	if (maskpri) log_mask = maskpri; | ||
| 30 | 	UNLOCK(lock); | ||
| 31 | 	return ret; | ||
| 32 | } | ||
| 33 | |||
| 34 | static const struct { | ||
| 35 | 	short sun_family; | ||
| 36 | 	char sun_path[9]; | ||
| 37 | } log_addr = { | ||
| 38 | 	AF_UNIX, | ||
| 39 | 	"/dev/log" | ||
| 40 | }; | ||
| 41 | |||
| 42 | void closelog(void) | ||
| 43 | { | ||
| 44 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 45 | 	int cs; | ||
| 46 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 47 | #endif | ||
| 48 | 	LOCK(lock); | ||
| 49 | 	close(log_fd); | ||
| 50 | 	log_fd = -1; | ||
| 51 | 	UNLOCK(lock); | ||
| 52 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 53 | 	pthread_setcancelstate(cs, 0); | ||
| 54 | #endif | ||
| 55 | } | ||
| 56 | |||
| 57 | static void __openlog() | ||
| 58 | { | ||
| 59 | 	log_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0); | ||
| 60 | 	if (log_fd >= 0) connect(log_fd, (void *)&log_addr, sizeof log_addr); | ||
| 61 | } | ||
| 62 | |||
| 63 | void openlog(const char *ident, int opt, int facility) | ||
| 64 | { | ||
| 65 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 66 | 	int cs; | ||
| 67 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 68 | #endif | ||
| 69 | 	LOCK(lock); | ||
| 70 | |||
| 71 | 	if (ident) { | ||
| 72 | 		size_t n = strnlen(ident, sizeof log_ident - 1); | ||
| 73 | 		memcpy(log_ident, ident, n); | ||
| 74 | 		log_ident[n] = 0; | ||
| 75 | 	} else { | ||
| 76 | 		log_ident[0] = 0; | ||
| 77 | 	} | ||
| 78 | 	log_opt = opt; | ||
| 79 | 	log_facility = facility; | ||
| 80 | |||
| 81 | 	if ((opt & LOG_NDELAY) && log_fd<0) __openlog(); | ||
| 82 | |||
| 83 | 	UNLOCK(lock); | ||
| 84 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 85 | 	pthread_setcancelstate(cs, 0); | ||
| 86 | #endif | ||
| 87 | } | ||
| 88 | |||
| 89 | static int is_lost_conn(int e) | ||
| 90 | { | ||
| 91 | 	return e==ECONNREFUSED || e==ECONNRESET || e==ENOTCONN || e==EPIPE; | ||
| 92 | } | ||
| 93 | |||
| 94 | static void _vsyslog(int priority, const char *message, va_list ap) | ||
| 95 | { | ||
| 96 | 	char timebuf[16]; | ||
| 97 | 	time_t now; | ||
| 98 | 	struct tm tm; | ||
| 99 | 	char buf[1024]; | ||
| 100 | 	int errno_save = errno; | ||
| 101 | 	int pid; | ||
| 102 | 	int l, l2; | ||
| 103 | 	int hlen; | ||
| 104 | 	int fd; | ||
| 105 | |||
| 106 | 	if (log_fd < 0) __openlog(); | ||
| 107 | |||
| 108 | 	if (!(priority & LOG_FACMASK)) priority |= log_facility; | ||
| 109 | |||
| 110 | 	now = time(NULL); | ||
| 111 | 	gmtime_r(&now, &tm); | ||
| 112 | 	strftime(timebuf, sizeof timebuf, "%b %e %T", &tm); | ||
| 113 | |||
| 114 | 	pid = (log_opt & LOG_PID) ? getpid() : 0; | ||
| 115 | 	l = snprintf(buf, sizeof buf, "<%d>%s %n%s%s%.0d%s: ", | ||
| 116 | 		priority, timebuf, &hlen, log_ident, "["+!pid, pid, "]"+!pid); | ||
| 117 | 	errno = errno_save; | ||
| 118 | 	l2 = vsnprintf(buf+l, sizeof buf - l, message, ap); | ||
| 119 | 	if (l2 >= 0) { | ||
| 120 | 		if (l2 >= sizeof buf - l) l = sizeof buf - 1; | ||
| 121 | 		else l += l2; | ||
| 122 | 		if (buf[l-1] != '\n') buf[l++] = '\n'; | ||
| 123 | 		if (send(log_fd, buf, l, 0) < 0 && (!is_lost_conn(errno) | ||
| 124 | 		 || connect(log_fd, (void *)&log_addr, sizeof log_addr) < 0 | ||
| 125 | 		 || send(log_fd, buf, l, 0) < 0) | ||
| 126 | 		 && (log_opt & LOG_CONS)) { | ||
| 127 | 			fd = open("/dev/console", O_WRONLY|O_NOCTTY|O_CLOEXEC); | ||
| 128 | 			if (fd >= 0) { | ||
| 129 | 				dprintf(fd, "%.*s", l-hlen, buf+hlen); | ||
| 130 | 				close(fd); | ||
| 131 | 			} | ||
| 132 | 		} | ||
| 133 | 		if (log_opt & LOG_PERROR) dprintf(2, "%.*s", l-hlen, buf+hlen); | ||
| 134 | 	} | ||
| 135 | } | ||
| 136 | |||
| 137 | static void __vsyslog(int priority, const char *message, va_list ap) | ||
| 138 | { | ||
| 139 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 140 | 	int cs; | ||
| 141 | #endif | ||
| 142 | 	if (!(log_mask & LOG_MASK(priority&7)) || (priority&~0x3ff)) return; | ||
| 143 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 144 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 145 | #endif | ||
| 146 | 	LOCK(lock); | ||
| 147 | 	_vsyslog(priority, message, ap); | ||
| 148 | 	UNLOCK(lock); | ||
| 149 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 150 | 	pthread_setcancelstate(cs, 0); | ||
| 151 | #endif | ||
| 152 | } | ||
| 153 | |||
| 154 | void syslog(int priority, const char *message, ...) | ||
| 155 | { | ||
| 156 | 	va_list ap; | ||
| 157 | 	va_start(ap, message); | ||
| 158 | 	__vsyslog(priority, message, ap); | ||
| 159 | 	va_end(ap); | ||
| 160 | } | ||
| 161 | |||
| 162 | weak_alias(__vsyslog, vsyslog); | ||
lib/libc/wasi/libc-top-half/musl/src/misc/uname.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <sys/utsname.h> | ||
| 2 | #ifdef __wasilibc_unmodified_upstream // Implement uname with placeholders | ||
| 3 | #include "syscall.h" | ||
| 4 | #else | ||
| 5 | #include <string.h> | ||
| 6 | #endif | ||
| 7 | |||
| 8 | int uname(struct utsname *uts) | ||
| 9 | { | ||
| 10 | #ifdef __wasilibc_unmodified_upstream // Implement uname with placeholders | ||
| 11 | 	return syscall(SYS_uname, uts); | ||
| 12 | #else | ||
| 13 | 	// Just fill in the fields with placeholder values. | ||
| 14 | 	strcpy(uts->sysname, "wasi"); | ||
| 15 | 	strcpy(uts->nodename, "(none)"); | ||
| 16 | 	strcpy(uts->release, "0.0.0"); | ||
| 17 | 	strcpy(uts->version, "0.0.0"); | ||
| 18 | #if defined(__wasm32__) | ||
| 19 | 	strcpy(uts->machine, "wasm32"); | ||
| 20 | #elif defined(__wasm64__) | ||
| 21 | 	strcpy(uts->machine, "wasm64"); | ||
| 22 | #else | ||
| 23 | 	strcpy(uts->machine, "unknown"); | ||
| 24 | #endif | ||
| 25 | #ifdef _GNU_SOURCE | ||
| 26 | 	strcpy(uts->domainname, "(none)"); | ||
| 27 | #else | ||
| 28 | 	strcpy(uts->__domainname, "(none)"); | ||
| 29 | #endif | ||
| 30 | 	return 0; | ||
| 31 | #endif | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/misc/wordexp.c created+187| ... | @@ -0,0 +1,187 @@ | ||
| 1 | #include <wordexp.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <sys/wait.h> | ||
| 9 | #include <signal.h> | ||
| 10 | #include <errno.h> | ||
| 11 | #include <fcntl.h> | ||
| 12 | #include "pthread_impl.h" | ||
| 13 | |||
| 14 | static void reap(pid_t pid) | ||
| 15 | { | ||
| 16 | 	int status; | ||
| 17 | 	while (waitpid(pid, &status, 0) < 0 && errno == EINTR); | ||
| 18 | } | ||
| 19 | |||
| 20 | static char *getword(FILE *f) | ||
| 21 | { | ||
| 22 | 	char *s = 0; | ||
| 23 | 	return getdelim(&s, (size_t [1]){0}, 0, f) < 0 ? 0 : s; | ||
| 24 | } | ||
| 25 | |||
| 26 | static int do_wordexp(const char *s, wordexp_t *we, int flags) | ||
| 27 | { | ||
| 28 | 	size_t i, l; | ||
| 29 | 	int sq=0, dq=0; | ||
| 30 | 	size_t np=0; | ||
| 31 | 	char *w, **tmp; | ||
| 32 | 	char *redir = (flags & WRDE_SHOWERR) ? "" : "2>/dev/null"; | ||
| 33 | 	int err = 0; | ||
| 34 | 	FILE *f; | ||
| 35 | 	size_t wc = 0; | ||
| 36 | 	char **wv = 0; | ||
| 37 | 	int p[2]; | ||
| 38 | 	pid_t pid; | ||
| 39 | 	sigset_t set; | ||
| 40 | |||
| 41 | 	if (flags & WRDE_REUSE) wordfree(we); | ||
| 42 | |||
| 43 | 	if (flags & WRDE_NOCMD) for (i=0; s[i]; i++) switch (s[i]) { | ||
| 44 | 	case '\\': | ||
| 45 | 		if (!sq && !s[++i]) return WRDE_SYNTAX; | ||
| 46 | 		break; | ||
| 47 | 	case '\'': | ||
| 48 | 		if (!dq) sq^=1; | ||
| 49 | 		break; | ||
| 50 | 	case '"': | ||
| 51 | 		if (!sq) dq^=1; | ||
| 52 | 		break; | ||
| 53 | 	case '(': | ||
| 54 | 		if (np) { | ||
| 55 | 			np++; | ||
| 56 | 			break; | ||
| 57 | 		} | ||
| 58 | 	case ')': | ||
| 59 | 		if (np) { | ||
| 60 | 			np--; | ||
| 61 | 			break; | ||
| 62 | 		} | ||
| 63 | 	case '\n': | ||
| 64 | 	case '|': | ||
| 65 | 	case '&': | ||
| 66 | 	case ';': | ||
| 67 | 	case '<': | ||
| 68 | 	case '>': | ||
| 69 | 	case '{': | ||
| 70 | 	case '}': | ||
| 71 | 		if (!(sq|dq|np)) return WRDE_BADCHAR; | ||
| 72 | 		break; | ||
| 73 | 	case '$': | ||
| 74 | 		if (sq) break; | ||
| 75 | 		if (s[i+1]=='(' && s[i+2]=='(') { | ||
| 76 | 			i += 2; | ||
| 77 | 			np += 2; | ||
| 78 | 			break; | ||
| 79 | 		} else if (s[i+1] != '(') break; | ||
| 80 | 	case '`': | ||
| 81 | 		if (sq) break; | ||
| 82 | 		return WRDE_CMDSUB; | ||
| 83 | 	} | ||
| 84 | |||
| 85 | 	if (flags & WRDE_APPEND) { | ||
| 86 | 		wc = we->we_wordc; | ||
| 87 | 		wv = we->we_wordv; | ||
| 88 | 	} | ||
| 89 | |||
| 90 | 	i = wc; | ||
| 91 | 	if (flags & WRDE_DOOFFS) { | ||
| 92 | 		if (we->we_offs > SIZE_MAX/sizeof(void *)/4) | ||
| 93 | 			goto nospace; | ||
| 94 | 		i += we->we_offs; | ||
| 95 | 	} else { | ||
| 96 | 		we->we_offs = 0; | ||
| 97 | 	} | ||
| 98 | |||
| 99 | 	if (pipe2(p, O_CLOEXEC) < 0) goto nospace; | ||
| 100 | 	__block_all_sigs(&set); | ||
| 101 | 	pid = fork(); | ||
| 102 | 	__restore_sigs(&set); | ||
| 103 | 	if (pid < 0) { | ||
| 104 | 		close(p[0]); | ||
| 105 | 		close(p[1]); | ||
| 106 | 		goto nospace; | ||
| 107 | 	} | ||
| 108 | 	if (!pid) { | ||
| 109 | 		if (p[1] == 1) fcntl(1, F_SETFD, 0); | ||
| 110 | 		else dup2(p[1], 1); | ||
| 111 | 		execl("/bin/sh", "sh", "-c", | ||
| 112 | 			"eval \"printf %s\\\\\\\\0 x $1 $2\"", | ||
| 113 | 			"sh", s, redir, (char *)0); | ||
| 114 | 		_exit(1); | ||
| 115 | 	} | ||
| 116 | 	close(p[1]); | ||
| 117 | 	 | ||
| 118 | 	f = fdopen(p[0], "r"); | ||
| 119 | 	if (!f) { | ||
| 120 | 		close(p[0]); | ||
| 121 | 		kill(pid, SIGKILL); | ||
| 122 | 		reap(pid); | ||
| 123 | 		goto nospace; | ||
| 124 | 	} | ||
| 125 | |||
| 126 | 	l = wv ? i+1 : 0; | ||
| 127 | |||
| 128 | 	free(getword(f)); | ||
| 129 | 	if (feof(f)) { | ||
| 130 | 		fclose(f); | ||
| 131 | 		reap(pid); | ||
| 132 | 		return WRDE_SYNTAX; | ||
| 133 | 	} | ||
| 134 | |||
| 135 | 	while ((w = getword(f))) { | ||
| 136 | 		if (i+1 >= l) { | ||
| 137 | 			l += l/2+10; | ||
| 138 | 			tmp = realloc(wv, l*sizeof(char *)); | ||
| 139 | 			if (!tmp) break; | ||
| 140 | 			wv = tmp; | ||
| 141 | 		} | ||
| 142 | 		wv[i++] = w; | ||
| 143 | 		wv[i] = 0; | ||
| 144 | 	} | ||
| 145 | 	if (!feof(f)) err = WRDE_NOSPACE; | ||
| 146 | |||
| 147 | 	fclose(f); | ||
| 148 | 	reap(pid); | ||
| 149 | |||
| 150 | 	if (!wv) wv = calloc(i+1, sizeof *wv); | ||
| 151 | |||
| 152 | 	we->we_wordv = wv; | ||
| 153 | 	we->we_wordc = i; | ||
| 154 | |||
| 155 | 	if (flags & WRDE_DOOFFS) { | ||
| 156 | 		if (wv) for (i=we->we_offs; i; i--) | ||
| 157 | 			we->we_wordv[i-1] = 0; | ||
| 158 | 		we->we_wordc -= we->we_offs; | ||
| 159 | 	} | ||
| 160 | 	return err; | ||
| 161 | |||
| 162 | nospace: | ||
| 163 | 	if (!(flags & WRDE_APPEND)) { | ||
| 164 | 		we->we_wordc = 0; | ||
| 165 | 		we->we_wordv = 0; | ||
| 166 | 	} | ||
| 167 | 	return WRDE_NOSPACE; | ||
| 168 | } | ||
| 169 | |||
| 170 | int wordexp(const char *restrict s, wordexp_t *restrict we, int flags) | ||
| 171 | { | ||
| 172 | 	int r, cs; | ||
| 173 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 174 | 	r = do_wordexp(s, we, flags); | ||
| 175 | 	pthread_setcancelstate(cs, 0); | ||
| 176 | 	return r; | ||
| 177 | } | ||
| 178 | |||
| 179 | void wordfree(wordexp_t *we) | ||
| 180 | { | ||
| 181 | 	size_t i; | ||
| 182 | 	if (!we->we_wordv) return; | ||
| 183 | 	for (i=0; i<we->we_wordc; i++) free(we->we_wordv[we->we_offs+i]); | ||
| 184 | 	free(we->we_wordv); | ||
| 185 | 	we->we_wordv = 0; | ||
| 186 | 	we->we_wordc = 0; | ||
| 187 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/madvise.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int __madvise(void *addr, size_t len, int advice) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_madvise, addr, len, advice); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__madvise, madvise); | ||
lib/libc/wasi/libc-top-half/musl/src/mman/mincore.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int mincore (void *addr, size_t len, unsigned char *vec) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_mincore, addr, len, vec); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/mlock.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mlock(const void *addr, size_t len) | ||
| 5 | { | ||
| 6 | #ifdef SYS_mlock | ||
| 7 | 	return syscall(SYS_mlock, addr, len); | ||
| 8 | #else | ||
| 9 | 	return syscall(SYS_mlock2, addr, len, 0); | ||
| 10 | #endif | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/mlockall.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mlockall(int flags) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_mlockall, flags); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/mmap.c created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <stdint.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | static void dummy(void) { } | ||
| 9 | weak_alias(dummy, __vm_wait); | ||
| 10 | |||
| 11 | #define UNIT SYSCALL_MMAP2_UNIT | ||
| 12 | #define OFF_MASK ((-0x2000ULL << (8*sizeof(syscall_arg_t)-1)) | (UNIT-1)) | ||
| 13 | |||
| 14 | void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off) | ||
| 15 | { | ||
| 16 | 	long ret; | ||
| 17 | 	if (off & OFF_MASK) { | ||
| 18 | 		errno = EINVAL; | ||
| 19 | 		return MAP_FAILED; | ||
| 20 | 	} | ||
| 21 | 	if (len >= PTRDIFF_MAX) { | ||
| 22 | 		errno = ENOMEM; | ||
| 23 | 		return MAP_FAILED; | ||
| 24 | 	} | ||
| 25 | 	if (flags & MAP_FIXED) { | ||
| 26 | 		__vm_wait(); | ||
| 27 | 	} | ||
| 28 | #ifdef SYS_mmap2 | ||
| 29 | 	ret = __syscall(SYS_mmap2, start, len, prot, flags, fd, off/UNIT); | ||
| 30 | #else | ||
| 31 | 	ret = __syscall(SYS_mmap, start, len, prot, flags, fd, off); | ||
| 32 | #endif | ||
| 33 | 	/* Fixup incorrect EPERM from kernel. */ | ||
| 34 | 	if (ret == -EPERM && !start && (flags&MAP_ANON) && !(flags&MAP_FIXED)) | ||
| 35 | 		ret = -ENOMEM; | ||
| 36 | 	return (void *)__syscall_ret(ret); | ||
| 37 | } | ||
| 38 | |||
| 39 | weak_alias(__mmap, mmap); | ||
| 40 | |||
| 41 | weak_alias(mmap, mmap64); | ||
lib/libc/wasi/libc-top-half/musl/src/mman/mprotect.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "libc.h" | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int __mprotect(void *addr, size_t len, int prot) | ||
| 6 | { | ||
| 7 | 	size_t start, end; | ||
| 8 | 	start = (size_t)addr & -PAGE_SIZE; | ||
| 9 | 	end = (size_t)((char *)addr + len + PAGE_SIZE-1) & -PAGE_SIZE; | ||
| 10 | 	return syscall(SYS_mprotect, start, end-start, prot); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__mprotect, mprotect); | ||
lib/libc/wasi/libc-top-half/musl/src/mman/mremap.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <sys/mman.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <stdarg.h> | ||
| 7 | #include "syscall.h" | ||
| 8 | |||
| 9 | static void dummy(void) { } | ||
| 10 | weak_alias(dummy, __vm_wait); | ||
| 11 | |||
| 12 | void *__mremap(void *old_addr, size_t old_len, size_t new_len, int flags, ...) | ||
| 13 | { | ||
| 14 | 	va_list ap; | ||
| 15 | 	void *new_addr = 0; | ||
| 16 | |||
| 17 | 	if (new_len >= PTRDIFF_MAX) { | ||
| 18 | 		errno = ENOMEM; | ||
| 19 | 		return MAP_FAILED; | ||
| 20 | 	} | ||
| 21 | |||
| 22 | 	if (flags & MREMAP_FIXED) { | ||
| 23 | 		__vm_wait(); | ||
| 24 | 		va_start(ap, flags); | ||
| 25 | 		new_addr = va_arg(ap, void *); | ||
| 26 | 		va_end(ap); | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	return (void *)syscall(SYS_mremap, old_addr, old_len, new_len, flags, new_addr); | ||
| 30 | } | ||
| 31 | |||
| 32 | weak_alias(__mremap, mremap); | ||
lib/libc/wasi/libc-top-half/musl/src/mman/msync.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int msync(void *start, size_t len, int flags) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_msync, start, len, flags); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/munlock.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int munlock(const void *addr, size_t len) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_munlock, addr, len); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/munlockall.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int munlockall(void) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_munlockall); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/munmap.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | static void dummy(void) { } | ||
| 5 | weak_alias(dummy, __vm_wait); | ||
| 6 | |||
| 7 | int __munmap(void *start, size_t len) | ||
| 8 | { | ||
| 9 | 	__vm_wait(); | ||
| 10 | 	return syscall(SYS_munmap, start, len); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__munmap, munmap); | ||
lib/libc/wasi/libc-top-half/musl/src/mman/posix_madvise.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int posix_madvise(void *addr, size_t len, int advice) | ||
| 6 | { | ||
| 7 | 	if (advice == MADV_DONTNEED) return 0; | ||
| 8 | 	return -__syscall(SYS_madvise, addr, len, advice); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mman/shm_open.c created+43| ... | @@ -0,0 +1,43 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <limits.h> | ||
| 7 | #include <pthread.h> | ||
| 8 | |||
| 9 | char *__shm_mapname(const char *name, char *buf) | ||
| 10 | { | ||
| 11 | 	char *p; | ||
| 12 | 	while (*name == '/') name++; | ||
| 13 | 	if (*(p = __strchrnul(name, '/')) || p==name || | ||
| 14 | 	 (p-name <= 2 && name[0]=='.' && p[-1]=='.')) { | ||
| 15 | 		errno = EINVAL; | ||
| 16 | 		return 0; | ||
| 17 | 	} | ||
| 18 | 	if (p-name > NAME_MAX) { | ||
| 19 | 		errno = ENAMETOOLONG; | ||
| 20 | 		return 0; | ||
| 21 | 	} | ||
| 22 | 	memcpy(buf, "/dev/shm/", 9); | ||
| 23 | 	memcpy(buf+9, name, p-name+1); | ||
| 24 | 	return buf; | ||
| 25 | } | ||
| 26 | |||
| 27 | int shm_open(const char *name, int flag, mode_t mode) | ||
| 28 | { | ||
| 29 | 	int cs; | ||
| 30 | 	char buf[NAME_MAX+10]; | ||
| 31 | 	if (!(name = __shm_mapname(name, buf))) return -1; | ||
| 32 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 33 | 	int fd = open(name, flag|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK, mode); | ||
| 34 | 	pthread_setcancelstate(cs, 0); | ||
| 35 | 	return fd; | ||
| 36 | } | ||
| 37 | |||
| 38 | int shm_unlink(const char *name) | ||
| 39 | { | ||
| 40 | 	char buf[NAME_MAX+10]; | ||
| 41 | 	if (!(name = __shm_mapname(name, buf))) return -1; | ||
| 42 | 	return unlink(name); | ||
| 43 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_close.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mq_close(mqd_t mqd) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_close, mqd); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_getattr.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mq_getattr(mqd_t mqd, struct mq_attr *attr) | ||
| 5 | { | ||
| 6 | 	return mq_setattr(mqd, 0, attr); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_notify.c created+73| ... | @@ -0,0 +1,73 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <sys/socket.h> | ||
| 5 | #include <signal.h> | ||
| 6 | #include <unistd.h> | ||
| 7 | #include "syscall.h" | ||
| 8 | |||
| 9 | struct args { | ||
| 10 | 	pthread_barrier_t barrier; | ||
| 11 | 	int sock; | ||
| 12 | 	const struct sigevent *sev; | ||
| 13 | }; | ||
| 14 | |||
| 15 | static void *start(void *p) | ||
| 16 | { | ||
| 17 | 	struct args *args = p; | ||
| 18 | 	char buf[32]; | ||
| 19 | 	ssize_t n; | ||
| 20 | 	int s = args->sock; | ||
| 21 | 	void (*func)(union sigval) = args->sev->sigev_notify_function; | ||
| 22 | 	union sigval val = args->sev->sigev_value; | ||
| 23 | |||
| 24 | 	pthread_barrier_wait(&args->barrier); | ||
| 25 | 	n = recv(s, buf, sizeof(buf), MSG_NOSIGNAL|MSG_WAITALL); | ||
| 26 | 	close(s); | ||
| 27 | 	if (n==sizeof buf && buf[sizeof buf - 1] == 1) | ||
| 28 | 		func(val); | ||
| 29 | 	return 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | int mq_notify(mqd_t mqd, const struct sigevent *sev) | ||
| 33 | { | ||
| 34 | 	struct args args = { .sev = sev }; | ||
| 35 | 	pthread_attr_t attr; | ||
| 36 | 	pthread_t td; | ||
| 37 | 	int s; | ||
| 38 | 	struct sigevent sev2; | ||
| 39 | 	static const char zeros[32]; | ||
| 40 | |||
| 41 | 	if (!sev || sev->sigev_notify != SIGEV_THREAD) | ||
| 42 | 		return syscall(SYS_mq_notify, mqd, sev); | ||
| 43 | |||
| 44 | 	s = socket(AF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, 0); | ||
| 45 | 	if (s < 0) return -1; | ||
| 46 | 	args.sock = s; | ||
| 47 | |||
| 48 | 	if (sev->sigev_notify_attributes) attr = *sev->sigev_notify_attributes; | ||
| 49 | 	else pthread_attr_init(&attr); | ||
| 50 | 	pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | ||
| 51 | 	pthread_barrier_init(&args.barrier, 0, 2); | ||
| 52 | |||
| 53 | 	if (pthread_create(&td, &attr, start, &args)) { | ||
| 54 | 		__syscall(SYS_close, s); | ||
| 55 | 		errno = EAGAIN; | ||
| 56 | 		return -1; | ||
| 57 | 	} | ||
| 58 | |||
| 59 | 	pthread_barrier_wait(&args.barrier); | ||
| 60 | 	pthread_barrier_destroy(&args.barrier); | ||
| 61 | |||
| 62 | 	sev2.sigev_notify = SIGEV_THREAD; | ||
| 63 | 	sev2.sigev_signo = s; | ||
| 64 | 	sev2.sigev_value.sival_ptr = (void *)&zeros; | ||
| 65 | |||
| 66 | 	if (syscall(SYS_mq_notify, mqd, &sev2) < 0) { | ||
| 67 | 		pthread_cancel(td); | ||
| 68 | 		__syscall(SYS_close, s); | ||
| 69 | 		return -1; | ||
| 70 | 	} | ||
| 71 | |||
| 72 | 	return 0; | ||
| 73 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_open.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | mqd_t mq_open(const char *name, int flags, ...) | ||
| 7 | { | ||
| 8 | 	mode_t mode = 0; | ||
| 9 | 	struct mq_attr *attr = 0; | ||
| 10 | 	if (*name == '/') name++; | ||
| 11 | 	if (flags & O_CREAT) { | ||
| 12 | 		va_list ap; | ||
| 13 | 		va_start(ap, flags); | ||
| 14 | 		mode = va_arg(ap, mode_t); | ||
| 15 | 		attr = va_arg(ap, struct mq_attr *); | ||
| 16 | 		va_end(ap); | ||
| 17 | 	} | ||
| 18 | 	return syscall(SYS_mq_open, name, flags, mode, attr); | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_receive.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | |||
| 3 | ssize_t mq_receive(mqd_t mqd, char *msg, size_t len, unsigned *prio) | ||
| 4 | { | ||
| 5 | 	return mq_timedreceive(mqd, msg, len, prio, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_send.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | |||
| 3 | int mq_send(mqd_t mqd, const char *msg, size_t len, unsigned prio) | ||
| 4 | { | ||
| 5 | 	return mq_timedsend(mqd, msg, len, prio, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_setattr.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mq_setattr(mqd_t mqd, const struct mq_attr *restrict new, struct mq_attr *restrict old) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_mq_getsetattr, mqd, new, old); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_timedreceive.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 7 | |||
| 8 | ssize_t mq_timedreceive(mqd_t mqd, char *restrict msg, size_t len, unsigned *restrict prio, const struct timespec *restrict at) | ||
| 9 | { | ||
| 10 | #ifdef SYS_mq_timedreceive_time64 | ||
| 11 | 	time_t s = at ? at->tv_sec : 0; | ||
| 12 | 	long ns = at ? at->tv_nsec : 0; | ||
| 13 | 	long r = -ENOSYS; | ||
| 14 | 	if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || !IS32BIT(s)) | ||
| 15 | 		r = __syscall_cp(SYS_mq_timedreceive_time64, mqd, msg, len, prio, | ||
| 16 | 			at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0); | ||
| 17 | 	if (SYS_mq_timedreceive == SYS_mq_timedreceive_time64 || r != -ENOSYS) | ||
| 18 | 		return __syscall_ret(r); | ||
| 19 | 	return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio, | ||
| 20 | 		at ? ((long[]){CLAMP(s), ns}) : 0); | ||
| 21 | #else | ||
| 22 | 	return syscall_cp(SYS_mq_timedreceive, mqd, msg, len, prio, at); | ||
| 23 | #endif | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_timedsend.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 7 | |||
| 8 | int mq_timedsend(mqd_t mqd, const char *msg, size_t len, unsigned prio, const struct timespec *at) | ||
| 9 | { | ||
| 10 | #ifdef SYS_mq_timedsend_time64 | ||
| 11 | 	time_t s = at ? at->tv_sec : 0; | ||
| 12 | 	long ns = at ? at->tv_nsec : 0; | ||
| 13 | 	long r = -ENOSYS; | ||
| 14 | 	if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || !IS32BIT(s)) | ||
| 15 | 		r = __syscall_cp(SYS_mq_timedsend_time64, mqd, msg, len, prio, | ||
| 16 | 			at ? ((long long []){at->tv_sec, at->tv_nsec}) : 0); | ||
| 17 | 	if (SYS_mq_timedsend == SYS_mq_timedsend_time64 || r != -ENOSYS) | ||
| 18 | 		return __syscall_ret(r); | ||
| 19 | 	return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio, | ||
| 20 | 		at ? ((long[]){CLAMP(s), ns}) : 0); | ||
| 21 | #else | ||
| 22 | 	return syscall_cp(SYS_mq_timedsend, mqd, msg, len, prio, at); | ||
| 23 | #endif | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/mq/mq_unlink.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <mqueue.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int mq_unlink(const char *name) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	if (*name == '/') name++; | ||
| 9 | 	ret = __syscall(SYS_mq_unlink, name); | ||
| 10 | 	if (ret < 0) { | ||
| 11 | 		if (ret == -EPERM) ret = -EACCES; | ||
| 12 | 		errno = -ret; | ||
| 13 | 		return -1; | ||
| 14 | 	} | ||
| 15 | 	return ret; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/btowc.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include "internal.h" | ||
| 5 | |||
| 6 | wint_t btowc(int c) | ||
| 7 | { | ||
| 8 | 	int b = (unsigned char)c; | ||
| 9 | 	return b<128U ? b : (MB_CUR_MAX==1 && c!=EOF) ? CODEUNIT(c) : WEOF; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/c16rtomb.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include <uchar.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | size_t c16rtomb(char *restrict s, char16_t c16, mbstate_t *restrict ps) | ||
| 6 | { | ||
| 7 | 	static unsigned internal_state; | ||
| 8 | 	if (!ps) ps = (void *)&internal_state; | ||
| 9 | 	unsigned *x = (unsigned *)ps; | ||
| 10 | 	wchar_t wc; | ||
| 11 | |||
| 12 | 	if (!s) { | ||
| 13 | 		if (*x) goto ilseq; | ||
| 14 | 		return 1; | ||
| 15 | 	} | ||
| 16 | |||
| 17 | 	if (!*x && c16 - 0xd800u < 0x400) { | ||
| 18 | 		*x = c16 - 0xd7c0 << 10; | ||
| 19 | 		return 0; | ||
| 20 | 	} | ||
| 21 | |||
| 22 | 	if (*x) { | ||
| 23 | 		if (c16 - 0xdc00u >= 0x400) goto ilseq; | ||
| 24 | 		else wc = *x + c16 - 0xdc00; | ||
| 25 | 		*x = 0; | ||
| 26 | 	} else { | ||
| 27 | 		wc = c16; | ||
| 28 | 	} | ||
| 29 | 	return wcrtomb(s, wc, 0); | ||
| 30 | |||
| 31 | ilseq: | ||
| 32 | 	*x = 0; | ||
| 33 | 	errno = EILSEQ; | ||
| 34 | 	return -1; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/c32rtomb.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <uchar.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | size_t c32rtomb(char *restrict s, char32_t c32, mbstate_t *restrict ps) | ||
| 5 | { | ||
| 6 | 	return wcrtomb(s, c32, ps); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/internal.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include "internal.h" | ||
| 2 | |||
| 3 | #define C(x) ( x<2 ? -1 : ( R(0x80,0xc0) | x ) ) | ||
| 4 | #define D(x) C((x+16)) | ||
| 5 | #define E(x) ( ( x==0 ? R(0xa0,0xc0) : \ | ||
| 6 | x==0xd ? R(0x80,0xa0) : \ | ||
| 7 | R(0x80,0xc0) ) \ | ||
| 8 | | ( R(0x80,0xc0) >> 6 ) \ | ||
| 9 | | x ) | ||
| 10 | #define F(x) ( ( x>=5 ? 0 : \ | ||
| 11 | x==0 ? R(0x90,0xc0) : \ | ||
| 12 | x==4 ? R(0x80,0x90) : \ | ||
| 13 | R(0x80,0xc0) ) \ | ||
| 14 | | ( R(0x80,0xc0) >> 6 ) \ | ||
| 15 | | ( R(0x80,0xc0) >> 12 ) \ | ||
| 16 | | x ) | ||
| 17 | |||
| 18 | const uint32_t bittab[] = { | ||
| 19 | 	 C(0x2),C(0x3),C(0x4),C(0x5),C(0x6),C(0x7), | ||
| 20 | 	C(0x8),C(0x9),C(0xa),C(0xb),C(0xc),C(0xd),C(0xe),C(0xf), | ||
| 21 | 	D(0x0),D(0x1),D(0x2),D(0x3),D(0x4),D(0x5),D(0x6),D(0x7), | ||
| 22 | 	D(0x8),D(0x9),D(0xa),D(0xb),D(0xc),D(0xd),D(0xe),D(0xf), | ||
| 23 | 	E(0x0),E(0x1),E(0x2),E(0x3),E(0x4),E(0x5),E(0x6),E(0x7), | ||
| 24 | 	E(0x8),E(0x9),E(0xa),E(0xb),E(0xc),E(0xd),E(0xe),E(0xf), | ||
| 25 | 	F(0x0),F(0x1),F(0x2),F(0x3),F(0x4) | ||
| 26 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/internal.h created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #define bittab __fsmu8 | ||
| 2 | |||
| 3 | #include <stdint.h> | ||
| 4 | #include <features.h> | ||
| 5 | |||
| 6 | extern hidden const uint32_t bittab[]; | ||
| 7 | |||
| 8 | /* Upper 6 state bits are a negative integer offset to bound-check next byte */ | ||
| 9 | /* equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f */ | ||
| 10 | #define OOB(c,b) (((((b)>>3)-0x10)|(((b)>>3)+((int32_t)(c)>>26))) & ~7) | ||
| 11 | |||
| 12 | /* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */ | ||
| 13 | #define R(a,b) ((uint32_t)((a==0x80 ? 0x40u-b : 0u-a) << 23)) | ||
| 14 | #define FAILSTATE R(0x80,0x80) | ||
| 15 | |||
| 16 | #define SA 0xc2u | ||
| 17 | #define SB 0xf4u | ||
| 18 | |||
| 19 | /* Arbitrary encoding for representing code units instead of characters. */ | ||
| 20 | #define CODEUNIT(c) (0xdfff & (signed char)(c)) | ||
| 21 | #define IS_CODEUNIT(c) ((unsigned)(c)-0xdf80 < 0x80) | ||
| 22 | |||
| 23 | /* Get inline definition of MB_CUR_MAX. */ | ||
| 24 | #include "locale_impl.h" | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mblen.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | int mblen(const char *s, size_t n) | ||
| 4 | { | ||
| 5 | 	return mbtowc(0, s, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbrlen.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t mbrlen(const char *restrict s, size_t n, mbstate_t *restrict st) | ||
| 4 | { | ||
| 5 | 	static unsigned internal; | ||
| 6 | 	return mbrtowc(0, s, n, st ? st : (mbstate_t *)&internal); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbrtoc16.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <uchar.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | size_t mbrtoc16(char16_t *restrict pc16, const char *restrict s, size_t n, mbstate_t *restrict ps) | ||
| 5 | { | ||
| 6 | 	static unsigned internal_state; | ||
| 7 | 	if (!ps) ps = (void *)&internal_state; | ||
| 8 | 	unsigned *pending = (unsigned *)ps; | ||
| 9 | |||
| 10 | 	if (!s) return mbrtoc16(0, "", 1, ps); | ||
| 11 | |||
| 12 | 	/* mbrtowc states for partial UTF-8 characters have the high bit set; | ||
| 13 | 	 * we use nonzero states without high bit for pending surrogates. */ | ||
| 14 | 	if ((int)*pending > 0) { | ||
| 15 | 		if (pc16) *pc16 = *pending; | ||
| 16 | 		*pending = 0; | ||
| 17 | 		return -3; | ||
| 18 | 	} | ||
| 19 | |||
| 20 | 	wchar_t wc; | ||
| 21 | 	size_t ret = mbrtowc(&wc, s, n, ps); | ||
| 22 | 	if (ret <= 4) { | ||
| 23 | 		if (wc >= 0x10000) { | ||
| 24 | 			*pending = (wc & 0x3ff) + 0xdc00; | ||
| 25 | 			wc = 0xd7c0 + (wc >> 10); | ||
| 26 | 		} | ||
| 27 | 		if (pc16) *pc16 = wc; | ||
| 28 | 	} | ||
| 29 | 	return ret; | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbrtoc32.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <uchar.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | size_t mbrtoc32(char32_t *restrict pc32, const char *restrict s, size_t n, mbstate_t *restrict ps) | ||
| 5 | { | ||
| 6 | 	static unsigned internal_state; | ||
| 7 | 	if (!ps) ps = (void *)&internal_state; | ||
| 8 | 	if (!s) return mbrtoc32(0, "", 1, ps); | ||
| 9 | 	wchar_t wc; | ||
| 10 | 	size_t ret = mbrtowc(&wc, s, n, ps); | ||
| 11 | 	if (ret <= 4 && pc32) *pc32 = wc; | ||
| 12 | 	return ret; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbrtowc.c created+51| ... | @@ -0,0 +1,51 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "internal.h" | ||
| 5 | |||
| 6 | size_t mbrtowc(wchar_t *restrict wc, const char *restrict src, size_t n, mbstate_t *restrict st) | ||
| 7 | { | ||
| 8 | 	static unsigned internal_state; | ||
| 9 | 	unsigned c; | ||
| 10 | 	const unsigned char *s = (const void *)src; | ||
| 11 | 	const unsigned N = n; | ||
| 12 | 	wchar_t dummy; | ||
| 13 | |||
| 14 | 	if (!st) st = (void *)&internal_state; | ||
| 15 | 	c = *(unsigned *)st; | ||
| 16 | 	 | ||
| 17 | 	if (!s) { | ||
| 18 | 		if (c) goto ilseq; | ||
| 19 | 		return 0; | ||
| 20 | 	} else if (!wc) wc = &dummy; | ||
| 21 | |||
| 22 | 	if (!n) return -2; | ||
| 23 | 	if (!c) { | ||
| 24 | 		if (*s < 0x80) return !!(*wc = *s); | ||
| 25 | 		if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1; | ||
| 26 | 		if (*s-SA > SB-SA) goto ilseq; | ||
| 27 | 		c = bittab[*s++-SA]; n--; | ||
| 28 | 	} | ||
| 29 | |||
| 30 | 	if (n) { | ||
| 31 | 		if (OOB(c,*s)) goto ilseq; | ||
| 32 | loop: | ||
| 33 | 		c = c<<6 | *s++-0x80; n--; | ||
| 34 | 		if (!(c&(1U<<31))) { | ||
| 35 | 			*(unsigned *)st = 0; | ||
| 36 | 			*wc = c; | ||
| 37 | 			return N-n; | ||
| 38 | 		} | ||
| 39 | 		if (n) { | ||
| 40 | 			if (*s-0x80u >= 0x40) goto ilseq; | ||
| 41 | 			goto loop; | ||
| 42 | 		} | ||
| 43 | 	} | ||
| 44 | |||
| 45 | 	*(unsigned *)st = c; | ||
| 46 | 	return -2; | ||
| 47 | ilseq: | ||
| 48 | 	*(unsigned *)st = 0; | ||
| 49 | 	errno = EILSEQ; | ||
| 50 | 	return -1; | ||
| 51 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbsinit.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int mbsinit(const mbstate_t *st) | ||
| 4 | { | ||
| 5 | 	return !st || !*(unsigned *)st; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbsnrtowcs.c created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t mbsnrtowcs(wchar_t *restrict wcs, const char **restrict src, size_t n, size_t wn, mbstate_t *restrict st) | ||
| 4 | { | ||
| 5 | 	size_t l, cnt=0, n2; | ||
| 6 | 	wchar_t *ws, wbuf[256]; | ||
| 7 | 	const char *s = *src; | ||
| 8 | 	const char *tmp_s; | ||
| 9 | |||
| 10 | 	if (!wcs) ws = wbuf, wn = sizeof wbuf / sizeof *wbuf; | ||
| 11 | 	else ws = wcs; | ||
| 12 | |||
| 13 | 	/* making sure output buffer size is at most n/4 will ensure | ||
| 14 | 	 * that mbsrtowcs never reads more than n input bytes. thus | ||
| 15 | 	 * we can use mbsrtowcs as long as it's practical.. */ | ||
| 16 | |||
| 17 | 	while ( s && wn && ( (n2=n/4)>=wn || n2>32 ) ) { | ||
| 18 | 		if (n2>=wn) n2=wn; | ||
| 19 | 		tmp_s = s; | ||
| 20 | 		l = mbsrtowcs(ws, &s, n2, st); | ||
| 21 | 		if (!(l+1)) { | ||
| 22 | 			cnt = l; | ||
| 23 | 			wn = 0; | ||
| 24 | 			break; | ||
| 25 | 		} | ||
| 26 | 		if (ws != wbuf) { | ||
| 27 | 			ws += l; | ||
| 28 | 			wn -= l; | ||
| 29 | 		} | ||
| 30 | 		n = s ? n - (s - tmp_s) : 0; | ||
| 31 | 		cnt += l; | ||
| 32 | 	} | ||
| 33 | 	if (s) while (wn && n) { | ||
| 34 | 		l = mbrtowc(ws, s, n, st); | ||
| 35 | 		if (l+2<=2) { | ||
| 36 | 			if (!(l+1)) { | ||
| 37 | 				cnt = l; | ||
| 38 | 				break; | ||
| 39 | 			} | ||
| 40 | 			if (!l) { | ||
| 41 | 				s = 0; | ||
| 42 | 				break; | ||
| 43 | 			} | ||
| 44 | 			/* have to roll back partial character */ | ||
| 45 | 			*(unsigned *)st = 0; | ||
| 46 | 			break; | ||
| 47 | 		} | ||
| 48 | 		s += l; n -= l; | ||
| 49 | 		/* safe - this loop runs fewer than sizeof(wbuf)/8 times */ | ||
| 50 | 		ws++; wn--; | ||
| 51 | 		cnt++; | ||
| 52 | 	} | ||
| 53 | 	if (wcs) *src = s; | ||
| 54 | 	return cnt; | ||
| 55 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbsrtowcs.c created+120| ... | @@ -0,0 +1,120 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include "internal.h" | ||
| 7 | |||
| 8 | size_t mbsrtowcs(wchar_t *restrict ws, const char **restrict src, size_t wn, mbstate_t *restrict st) | ||
| 9 | { | ||
| 10 | 	const unsigned char *s = (const void *)*src; | ||
| 11 | 	size_t wn0 = wn; | ||
| 12 | 	unsigned c = 0; | ||
| 13 | |||
| 14 | 	if (st && (c = *(unsigned *)st)) { | ||
| 15 | 		if (ws) { | ||
| 16 | 			*(unsigned *)st = 0; | ||
| 17 | 			goto resume; | ||
| 18 | 		} else { | ||
| 19 | 			goto resume0; | ||
| 20 | 		} | ||
| 21 | 	} | ||
| 22 | |||
| 23 | 	if (MB_CUR_MAX==1) { | ||
| 24 | 		if (!ws) return strlen((const char *)s); | ||
| 25 | 		for (;;) { | ||
| 26 | 			if (!wn) { | ||
| 27 | 				*src = (const void *)s; | ||
| 28 | 				return wn0; | ||
| 29 | 			} | ||
| 30 | 			if (!*s) break; | ||
| 31 | 			c = *s++; | ||
| 32 | 			*ws++ = CODEUNIT(c); | ||
| 33 | 			wn--; | ||
| 34 | 		} | ||
| 35 | 		*ws = 0; | ||
| 36 | 		*src = 0; | ||
| 37 | 		return wn0-wn; | ||
| 38 | 	} | ||
| 39 | |||
| 40 | 	if (!ws) for (;;) { | ||
| 41 | #ifdef __GNUC__ | ||
| 42 | 		typedef uint32_t __attribute__((__may_alias__)) w32; | ||
| 43 | 		if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { | ||
| 44 | 			while (!(( *(w32*)s | *(w32*)s-0x01010101) & 0x80808080)) { | ||
| 45 | 				s += 4; | ||
| 46 | 				wn -= 4; | ||
| 47 | 			} | ||
| 48 | 		} | ||
| 49 | #endif | ||
| 50 | 		if (*s-1u < 0x7f) { | ||
| 51 | 			s++; | ||
| 52 | 			wn--; | ||
| 53 | 			continue; | ||
| 54 | 		} | ||
| 55 | 		if (*s-SA > SB-SA) break; | ||
| 56 | 		c = bittab[*s++-SA]; | ||
| 57 | resume0: | ||
| 58 | 		if (OOB(c,*s)) { s--; break; } | ||
| 59 | 		s++; | ||
| 60 | 		if (c&(1U<<25)) { | ||
| 61 | 			if (*s-0x80u >= 0x40) { s-=2; break; } | ||
| 62 | 			s++; | ||
| 63 | 			if (c&(1U<<19)) { | ||
| 64 | 				if (*s-0x80u >= 0x40) { s-=3; break; } | ||
| 65 | 				s++; | ||
| 66 | 			} | ||
| 67 | 		} | ||
| 68 | 		wn--; | ||
| 69 | 		c = 0; | ||
| 70 | 	} else for (;;) { | ||
| 71 | 		if (!wn) { | ||
| 72 | 			*src = (const void *)s; | ||
| 73 | 			return wn0; | ||
| 74 | 		} | ||
| 75 | #ifdef __GNUC__ | ||
| 76 | 		typedef uint32_t __attribute__((__may_alias__)) w32; | ||
| 77 | 		if (*s-1u < 0x7f && (uintptr_t)s%4 == 0) { | ||
| 78 | 			while (wn>=5 && !(( *(w32*)s | *(w32*)s-0x01010101) & 0x80808080)) { | ||
| 79 | 				*ws++ = *s++; | ||
| 80 | 				*ws++ = *s++; | ||
| 81 | 				*ws++ = *s++; | ||
| 82 | 				*ws++ = *s++; | ||
| 83 | 				wn -= 4; | ||
| 84 | 			} | ||
| 85 | 		} | ||
| 86 | #endif | ||
| 87 | 		if (*s-1u < 0x7f) { | ||
| 88 | 			*ws++ = *s++; | ||
| 89 | 			wn--; | ||
| 90 | 			continue; | ||
| 91 | 		} | ||
| 92 | 		if (*s-SA > SB-SA) break; | ||
| 93 | 		c = bittab[*s++-SA]; | ||
| 94 | resume: | ||
| 95 | 		if (OOB(c,*s)) { s--; break; } | ||
| 96 | 		c = (c<<6) | *s++-0x80; | ||
| 97 | 		if (c&(1U<<31)) { | ||
| 98 | 			if (*s-0x80u >= 0x40) { s-=2; break; } | ||
| 99 | 			c = (c<<6) | *s++-0x80; | ||
| 100 | 			if (c&(1U<<31)) { | ||
| 101 | 				if (*s-0x80u >= 0x40) { s-=3; break; } | ||
| 102 | 				c = (c<<6) | *s++-0x80; | ||
| 103 | 			} | ||
| 104 | 		} | ||
| 105 | 		*ws++ = c; | ||
| 106 | 		wn--; | ||
| 107 | 		c = 0; | ||
| 108 | 	} | ||
| 109 | |||
| 110 | 	if (!c && !*s) { | ||
| 111 | 		if (ws) { | ||
| 112 | 			*ws = 0; | ||
| 113 | 			*src = 0; | ||
| 114 | 		} | ||
| 115 | 		return wn0-wn; | ||
| 116 | 	} | ||
| 117 | 	errno = EILSEQ; | ||
| 118 | 	if (ws) *src = (const void *)s; | ||
| 119 | 	return -1; | ||
| 120 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbstowcs.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | size_t mbstowcs(wchar_t *restrict ws, const char *restrict s, size_t wn) | ||
| 5 | { | ||
| 6 | 	return mbsrtowcs(ws, (void*)&s, wn, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/mbtowc.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "internal.h" | ||
| 5 | |||
| 6 | int mbtowc(wchar_t *restrict wc, const char *restrict src, size_t n) | ||
| 7 | { | ||
| 8 | 	unsigned c; | ||
| 9 | 	const unsigned char *s = (const void *)src; | ||
| 10 | 	wchar_t dummy; | ||
| 11 | |||
| 12 | 	if (!s) return 0; | ||
| 13 | 	if (!n) goto ilseq; | ||
| 14 | 	if (!wc) wc = &dummy; | ||
| 15 | |||
| 16 | 	if (*s < 0x80) return !!(*wc = *s); | ||
| 17 | 	if (MB_CUR_MAX==1) return (*wc = CODEUNIT(*s)), 1; | ||
| 18 | 	if (*s-SA > SB-SA) goto ilseq; | ||
| 19 | 	c = bittab[*s++-SA]; | ||
| 20 | |||
| 21 | 	/* Avoid excessive checks against n: If shifting the state n-1 | ||
| 22 | 	 * times does not clear the high bit, then the value of n is | ||
| 23 | 	 * insufficient to read a character */ | ||
| 24 | 	if (n<4 && ((c<<(6*n-6)) & (1U<<31))) goto ilseq; | ||
| 25 | |||
| 26 | 	if (OOB(c,*s)) goto ilseq; | ||
| 27 | 	c = c<<6 | *s++-0x80; | ||
| 28 | 	if (!(c&(1U<<31))) { | ||
| 29 | 		*wc = c; | ||
| 30 | 		return 2; | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	if (*s-0x80u >= 0x40) goto ilseq; | ||
| 34 | 	c = c<<6 | *s++-0x80; | ||
| 35 | 	if (!(c&(1U<<31))) { | ||
| 36 | 		*wc = c; | ||
| 37 | 		return 3; | ||
| 38 | 	} | ||
| 39 | |||
| 40 | 	if (*s-0x80u >= 0x40) goto ilseq; | ||
| 41 | 	*wc = c<<6 | *s++-0x80; | ||
| 42 | 	return 4; | ||
| 43 | |||
| 44 | ilseq: | ||
| 45 | 	errno = EILSEQ; | ||
| 46 | 	return -1; | ||
| 47 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/wcrtomb.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "internal.h" | ||
| 5 | |||
| 6 | size_t wcrtomb(char *restrict s, wchar_t wc, mbstate_t *restrict st) | ||
| 7 | { | ||
| 8 | 	if (!s) return 1; | ||
| 9 | 	if ((unsigned)wc < 0x80) { | ||
| 10 | 		*s = wc; | ||
| 11 | 		return 1; | ||
| 12 | 	} else if (MB_CUR_MAX == 1) { | ||
| 13 | 		if (!IS_CODEUNIT(wc)) { | ||
| 14 | 			errno = EILSEQ; | ||
| 15 | 			return -1; | ||
| 16 | 		} | ||
| 17 | 		*s = wc; | ||
| 18 | 		return 1; | ||
| 19 | 	} else if ((unsigned)wc < 0x800) { | ||
| 20 | 		*s++ = 0xc0 | (wc>>6); | ||
| 21 | 		*s = 0x80 | (wc&0x3f); | ||
| 22 | 		return 2; | ||
| 23 | 	} else if ((unsigned)wc < 0xd800 || (unsigned)wc-0xe000 < 0x2000) { | ||
| 24 | 		*s++ = 0xe0 | (wc>>12); | ||
| 25 | 		*s++ = 0x80 | ((wc>>6)&0x3f); | ||
| 26 | 		*s = 0x80 | (wc&0x3f); | ||
| 27 | 		return 3; | ||
| 28 | 	} else if ((unsigned)wc-0x10000 < 0x100000) { | ||
| 29 | 		*s++ = 0xf0 | (wc>>18); | ||
| 30 | 		*s++ = 0x80 | ((wc>>12)&0x3f); | ||
| 31 | 		*s++ = 0x80 | ((wc>>6)&0x3f); | ||
| 32 | 		*s = 0x80 | (wc&0x3f); | ||
| 33 | 		return 4; | ||
| 34 | 	} | ||
| 35 | 	errno = EILSEQ; | ||
| 36 | 	return -1; | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/wcsnrtombs.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | size_t wcsnrtombs(char *restrict dst, const wchar_t **restrict wcs, size_t wn, size_t n, mbstate_t *restrict st) | ||
| 6 | { | ||
| 7 | 	const wchar_t *ws = *wcs; | ||
| 8 | 	size_t cnt = 0; | ||
| 9 | 	if (!dst) n=0; | ||
| 10 | 	while (ws && wn) { | ||
| 11 | 		char tmp[MB_LEN_MAX]; | ||
| 12 | 		size_t l = wcrtomb(n<MB_LEN_MAX ? tmp : dst, *ws, 0); | ||
| 13 | 		if (l==-1) { | ||
| 14 | 			cnt = -1; | ||
| 15 | 			break; | ||
| 16 | 		} | ||
| 17 | 		if (dst) { | ||
| 18 | 			if (n<MB_LEN_MAX) { | ||
| 19 | 				if (l>n) break; | ||
| 20 | 				memcpy(dst, tmp, l); | ||
| 21 | 			} | ||
| 22 | 			dst += l; | ||
| 23 | 			n -= l; | ||
| 24 | 		} | ||
| 25 | 		if (!*ws) { | ||
| 26 | 			ws = 0; | ||
| 27 | 			break; | ||
| 28 | 		} | ||
| 29 | 		ws++; | ||
| 30 | 		wn--; | ||
| 31 | 		cnt += l; | ||
| 32 | 	} | ||
| 33 | 	if (dst) *wcs = ws; | ||
| 34 | 	return cnt; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/wcsrtombs.c created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t wcsrtombs(char *restrict s, const wchar_t **restrict ws, size_t n, mbstate_t *restrict st) | ||
| 4 | { | ||
| 5 | 	const wchar_t *ws2; | ||
| 6 | 	char buf[4]; | ||
| 7 | 	size_t N = n, l; | ||
| 8 | 	if (!s) { | ||
| 9 | 		for (n=0, ws2=*ws; *ws2; ws2++) { | ||
| 10 | 			if (*ws2 >= 0x80u) { | ||
| 11 | 				l = wcrtomb(buf, *ws2, 0); | ||
| 12 | 				if (!(l+1)) return -1; | ||
| 13 | 				n += l; | ||
| 14 | 			} else n++; | ||
| 15 | 		} | ||
| 16 | 		return n; | ||
| 17 | 	} | ||
| 18 | 	while (n>=4) { | ||
| 19 | 		if (**ws-1u >= 0x7fu) { | ||
| 20 | 			if (!**ws) { | ||
| 21 | 				*s = 0; | ||
| 22 | 				*ws = 0; | ||
| 23 | 				return N-n; | ||
| 24 | 			} | ||
| 25 | 			l = wcrtomb(s, **ws, 0); | ||
| 26 | 			if (!(l+1)) return -1; | ||
| 27 | 			s += l; | ||
| 28 | 			n -= l; | ||
| 29 | 		} else { | ||
| 30 | 			*s++ = **ws; | ||
| 31 | 			n--; | ||
| 32 | 		} | ||
| 33 | 		(*ws)++; | ||
| 34 | 	} | ||
| 35 | 	while (n) { | ||
| 36 | 		if (**ws-1u >= 0x7fu) { | ||
| 37 | 			if (!**ws) { | ||
| 38 | 				*s = 0; | ||
| 39 | 				*ws = 0; | ||
| 40 | 				return N-n; | ||
| 41 | 			} | ||
| 42 | 			l = wcrtomb(buf, **ws, 0); | ||
| 43 | 			if (!(l+1)) return -1; | ||
| 44 | 			if (l>n) return N-n; | ||
| 45 | 			wcrtomb(s, **ws, 0); | ||
| 46 | 			s += l; | ||
| 47 | 			n -= l; | ||
| 48 | 		} else { | ||
| 49 | 			*s++ = **ws; | ||
| 50 | 			n--; | ||
| 51 | 		} | ||
| 52 | 		(*ws)++; | ||
| 53 | 	} | ||
| 54 | 	return N; | ||
| 55 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/wcstombs.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | size_t wcstombs(char *restrict s, const wchar_t *restrict ws, size_t n) | ||
| 5 | { | ||
| 6 | 	return wcsrtombs(s, &(const wchar_t *){ws}, n, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/wctob.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include "internal.h" | ||
| 5 | |||
| 6 | int wctob(wint_t c) | ||
| 7 | { | ||
| 8 | 	if (c < 128U) return c; | ||
| 9 | 	if (MB_CUR_MAX==1 && IS_CODEUNIT(c)) return (unsigned char)c; | ||
| 10 | 	return EOF; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/multibyte/wctomb.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | int wctomb(char *s, wchar_t wc) | ||
| 5 | { | ||
| 6 | 	if (!s) return 0; | ||
| 7 | 	return wcrtomb(s, wc, 0); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/accept.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) | ||
| 5 | { | ||
| 6 | 	return socketcall_cp(accept, fd, addr, len, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/accept4.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int accept4(int fd, struct sockaddr *restrict addr, socklen_t *restrict len, int flg) | ||
| 8 | { | ||
| 9 | 	if (!flg) return accept(fd, addr, len); | ||
| 10 | 	int ret = socketcall_cp(accept4, fd, addr, len, flg, 0, 0); | ||
| 11 | 	if (ret>=0 || (errno != ENOSYS && errno != EINVAL)) return ret; | ||
| 12 | 	ret = accept(fd, addr, len); | ||
| 13 | 	if (ret<0) return ret; | ||
| 14 | 	if (flg & SOCK_CLOEXEC) | ||
| 15 | 		__syscall(SYS_fcntl, ret, F_SETFD, FD_CLOEXEC); | ||
| 16 | 	if (flg & SOCK_NONBLOCK) | ||
| 17 | 		__syscall(SYS_fcntl, ret, F_SETFL, O_NONBLOCK); | ||
| 18 | 	return ret; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/bind.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int bind(int fd, const struct sockaddr *addr, socklen_t len) | ||
| 5 | { | ||
| 6 | 	return socketcall(bind, fd, addr, len, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/connect.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int connect(int fd, const struct sockaddr *addr, socklen_t len) | ||
| 5 | { | ||
| 6 | 	return socketcall_cp(connect, fd, addr, len, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/dn_comp.c created+107| ... | @@ -0,0 +1,107 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <resolv.h> | ||
| 3 | |||
| 4 | /* RFC 1035 message compression */ | ||
| 5 | |||
| 6 | /* label start offsets of a compressed domain name s */ | ||
| 7 | static int getoffs(short *offs, const unsigned char *base, const unsigned char *s) | ||
| 8 | { | ||
| 9 | 	int i=0; | ||
| 10 | 	for (;;) { | ||
| 11 | 		while (*s & 0xc0) { | ||
| 12 | 			if ((*s & 0xc0) != 0xc0) return 0; | ||
| 13 | 			s = base + ((s[0]&0x3f)<<8 | s[1]); | ||
| 14 | 		} | ||
| 15 | 		if (!*s) return i; | ||
| 16 | 		if (s-base >= 0x4000) return 0; | ||
| 17 | 		offs[i++] = s-base; | ||
| 18 | 		s += *s + 1; | ||
| 19 | 	} | ||
| 20 | } | ||
| 21 | |||
| 22 | /* label lengths of an ascii domain name s */ | ||
| 23 | static int getlens(unsigned char *lens, const char *s, int l) | ||
| 24 | { | ||
| 25 | 	int i=0,j=0,k=0; | ||
| 26 | 	for (;;) { | ||
| 27 | 		for (; j<l && s[j]!='.'; j++); | ||
| 28 | 		if (j-k-1u > 62) return 0; | ||
| 29 | 		lens[i++] = j-k; | ||
| 30 | 		if (j==l) return i; | ||
| 31 | 		k = ++j; | ||
| 32 | 	} | ||
| 33 | } | ||
| 34 | |||
| 35 | /* longest suffix match of an ascii domain with a compressed domain name dn */ | ||
| 36 | static int match(int *offset, const unsigned char *base, const unsigned char *dn, | ||
| 37 | 	const char *end, const unsigned char *lens, int nlen) | ||
| 38 | { | ||
| 39 | 	int l, o, m=0; | ||
| 40 | 	short offs[128]; | ||
| 41 | 	int noff = getoffs(offs, base, dn); | ||
| 42 | 	if (!noff) return 0; | ||
| 43 | 	for (;;) { | ||
| 44 | 		l = lens[--nlen]; | ||
| 45 | 		o = offs[--noff]; | ||
| 46 | 		end -= l; | ||
| 47 | 		if (l != base[o] || memcmp(base+o+1, end, l)) | ||
| 48 | 			return m; | ||
| 49 | 		*offset = o; | ||
| 50 | 		m += l; | ||
| 51 | 		if (nlen) m++; | ||
| 52 | 		if (!nlen || !noff) return m; | ||
| 53 | 		end--; | ||
| 54 | 	} | ||
| 55 | } | ||
| 56 | |||
| 57 | int dn_comp(const char *src, unsigned char *dst, int space, unsigned char **dnptrs, unsigned char **lastdnptr) | ||
| 58 | { | ||
| 59 | 	int i, j, n, m=0, offset, bestlen=0, bestoff; | ||
| 60 | 	unsigned char lens[127]; | ||
| 61 | 	unsigned char **p; | ||
| 62 | 	const char *end; | ||
| 63 | 	size_t l = strnlen(src, 255); | ||
| 64 | 	if (l && src[l-1] == '.') l--; | ||
| 65 | 	if (l>253 || space<=0) return -1; | ||
| 66 | 	if (!l) { | ||
| 67 | 		*dst = 0; | ||
| 68 | 		return 1; | ||
| 69 | 	} | ||
| 70 | 	end = src+l; | ||
| 71 | 	n = getlens(lens, src, l); | ||
| 72 | 	if (!n) return -1; | ||
| 73 | |||
| 74 | 	p = dnptrs; | ||
| 75 | 	if (p && *p) for (p++; *p; p++) { | ||
| 76 | 		m = match(&offset, *dnptrs, *p, end, lens, n); | ||
| 77 | 		if (m > bestlen) { | ||
| 78 | 			bestlen = m; | ||
| 79 | 			bestoff = offset; | ||
| 80 | 			if (m == l) | ||
| 81 | 				break; | ||
| 82 | 		} | ||
| 83 | 	} | ||
| 84 | |||
| 85 | 	/* encode unmatched part */ | ||
| 86 | 	if (space < l-bestlen+2+(bestlen-1 < l-1)) return -1; | ||
| 87 | 	memcpy(dst+1, src, l-bestlen); | ||
| 88 | 	for (i=j=0; i<l-bestlen; i+=lens[j++]+1) | ||
| 89 | 		dst[i] = lens[j]; | ||
| 90 | |||
| 91 | 	/* add tail */ | ||
| 92 | 	if (bestlen) { | ||
| 93 | 		dst[i++] = 0xc0 | bestoff>>8; | ||
| 94 | 		dst[i++] = bestoff; | ||
| 95 | 	} else | ||
| 96 | 		dst[i++] = 0; | ||
| 97 | |||
| 98 | 	/* save dst pointer */ | ||
| 99 | 	if (i>2 && lastdnptr && dnptrs && *dnptrs) { | ||
| 100 | 		while (*p) p++; | ||
| 101 | 		if (p+1 < lastdnptr) { | ||
| 102 | 			*p++ = dst; | ||
| 103 | 			*p=0; | ||
| 104 | 		} | ||
| 105 | 	} | ||
| 106 | 	return i; | ||
| 107 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/dn_expand.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | |||
| 3 | int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space) | ||
| 4 | { | ||
| 5 | 	const unsigned char *p = src; | ||
| 6 | 	char *dend, *dbegin = dest; | ||
| 7 | 	int len = -1, i, j; | ||
| 8 | 	if (p==end || space <= 0) return -1; | ||
| 9 | 	dend = dest + (space > 254 ? 254 : space); | ||
| 10 | 	/* detect reference loop using an iteration counter */ | ||
| 11 | 	for (i=0; i < end-base; i+=2) { | ||
| 12 | 		/* loop invariants: p<end, dest<dend */ | ||
| 13 | 		if (*p & 0xc0) { | ||
| 14 | 			if (p+1==end) return -1; | ||
| 15 | 			j = ((p[0] & 0x3f) << 8) | p[1]; | ||
| 16 | 			if (len < 0) len = p+2-src; | ||
| 17 | 			if (j >= end-base) return -1; | ||
| 18 | 			p = base+j; | ||
| 19 | 		} else if (*p) { | ||
| 20 | 			if (dest != dbegin) *dest++ = '.'; | ||
| 21 | 			j = *p++; | ||
| 22 | 			if (j >= end-p || j >= dend-dest) return -1; | ||
| 23 | 			while (j--) *dest++ = *p++; | ||
| 24 | 		} else { | ||
| 25 | 			*dest = 0; | ||
| 26 | 			if (len < 0) len = p+1-src; | ||
| 27 | 			return len; | ||
| 28 | 		} | ||
| 29 | 	} | ||
| 30 | 	return -1; | ||
| 31 | } | ||
| 32 | |||
| 33 | weak_alias(__dn_expand, dn_expand); | ||
lib/libc/wasi/libc-top-half/musl/src/network/dn_skipname.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | |||
| 3 | int dn_skipname(const unsigned char *s, const unsigned char *end) | ||
| 4 | { | ||
| 5 | 	const unsigned char *p = s; | ||
| 6 | 	while (p < end) | ||
| 7 | 		if (!*p) return p-s+1; | ||
| 8 | 		else if (*p>=192) | ||
| 9 | 			if (p+1<end) return p-s+2; | ||
| 10 | 			else break; | ||
| 11 | 		else | ||
| 12 | 			if (end-p<*p+1) break; | ||
| 13 | 			else p += *p + 1; | ||
| 14 | 	return -1; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/dns_parse.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include "lookup.h" | ||
| 3 | |||
| 4 | int __dns_parse(const unsigned char *r, int rlen, int (*callback)(void *, int, const void *, int, const void *), void *ctx) | ||
| 5 | { | ||
| 6 | 	int qdcount, ancount; | ||
| 7 | 	const unsigned char *p; | ||
| 8 | 	int len; | ||
| 9 | |||
| 10 | 	if (rlen<12) return -1; | ||
| 11 | 	if ((r[3]&15)) return 0; | ||
| 12 | 	p = r+12; | ||
| 13 | 	qdcount = r[4]*256 + r[5]; | ||
| 14 | 	ancount = r[6]*256 + r[7]; | ||
| 15 | 	if (qdcount+ancount > 64) return -1; | ||
| 16 | 	while (qdcount--) { | ||
| 17 | 		while (p-r < rlen && *p-1U < 127) p++; | ||
| 18 | 		if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6) | ||
| 19 | 			return -1; | ||
| 20 | 		p += 5 + !!*p; | ||
| 21 | 	} | ||
| 22 | 	while (ancount--) { | ||
| 23 | 		while (p-r < rlen && *p-1U < 127) p++; | ||
| 24 | 		if (*p>193 || (*p==193 && p[1]>254) || p>r+rlen-6) | ||
| 25 | 			return -1; | ||
| 26 | 		p += 1 + !!*p; | ||
| 27 | 		len = p[8]*256 + p[9]; | ||
| 28 | 		if (p+len > r+rlen) return -1; | ||
| 29 | 		if (callback(ctx, p[1], p+10, len, r) < 0) return -1; | ||
| 30 | 		p += 10 + len; | ||
| 31 | 	} | ||
| 32 | 	return 0; | ||
| 33 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/ent.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | |||
| 3 | void sethostent(int x) | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | struct hostent *gethostent() | ||
| 8 | { | ||
| 9 | 	return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | struct netent *getnetent() | ||
| 13 | { | ||
| 14 | 	return 0; | ||
| 15 | } | ||
| 16 | |||
| 17 | void endhostent(void) | ||
| 18 | { | ||
| 19 | } | ||
| 20 | |||
| 21 | weak_alias(sethostent, setnetent); | ||
| 22 | weak_alias(endhostent, endnetent); | ||
lib/libc/wasi/libc-top-half/musl/src/network/ether.c created+58| ... | @@ -0,0 +1,58 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <netinet/ether.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a) | ||
| 6 | { | ||
| 7 | 	struct ether_addr a; | ||
| 8 | 	char *y; | ||
| 9 | 	for (int ii = 0; ii < 6; ii++) { | ||
| 10 | 		unsigned long int n; | ||
| 11 | 		if (ii != 0) { | ||
| 12 | 			if (x[0] != ':') return 0; /* bad format */ | ||
| 13 | 			else x++; | ||
| 14 | 		} | ||
| 15 | 		n = strtoul (x, &y, 16); | ||
| 16 | 		x = y; | ||
| 17 | 		if (n > 0xFF) return 0; /* bad byte */ | ||
| 18 | 		a.ether_addr_octet[ii] = n; | ||
| 19 | 	} | ||
| 20 | 	if (x[0] != 0) return 0; /* bad format */ | ||
| 21 | 	*p_a = a; | ||
| 22 | 	return p_a; | ||
| 23 | } | ||
| 24 | |||
| 25 | struct ether_addr *ether_aton (const char *x) | ||
| 26 | { | ||
| 27 | 	static struct ether_addr a; | ||
| 28 | 	return ether_aton_r (x, &a); | ||
| 29 | } | ||
| 30 | |||
| 31 | char *ether_ntoa_r (const struct ether_addr *p_a, char *x) { | ||
| 32 | 	char *y; | ||
| 33 | 	y = x; | ||
| 34 | 	for (int ii = 0; ii < 6; ii++) { | ||
| 35 | 		x += sprintf (x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]); | ||
| 36 | 	} | ||
| 37 | 	return y; | ||
| 38 | } | ||
| 39 | |||
| 40 | char *ether_ntoa (const struct ether_addr *p_a) { | ||
| 41 | 	static char x[18]; | ||
| 42 | 	return ether_ntoa_r (p_a, x); | ||
| 43 | } | ||
| 44 | |||
| 45 | int ether_line(const char *l, struct ether_addr *e, char *hostname) | ||
| 46 | { | ||
| 47 | 	return -1; | ||
| 48 | } | ||
| 49 | |||
| 50 | int ether_ntohost(char *hostname, const struct ether_addr *e) | ||
| 51 | { | ||
| 52 | 	return -1; | ||
| 53 | } | ||
| 54 | |||
| 55 | int ether_hostton(const char *hostname, struct ether_addr *e) | ||
| 56 | { | ||
| 57 | 	return -1; | ||
| 58 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/freeaddrinfo.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stddef.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | #include "lookup.h" | ||
| 5 | #include "lock.h" | ||
| 6 | |||
| 7 | void freeaddrinfo(struct addrinfo *p) | ||
| 8 | { | ||
| 9 | 	size_t cnt; | ||
| 10 | 	for (cnt=1; p->ai_next; cnt++, p=p->ai_next); | ||
| 11 | 	struct aibuf *b = (void *)((char *)p - offsetof(struct aibuf, ai)); | ||
| 12 | 	b -= b->slot; | ||
| 13 | 	LOCK(b->lock); | ||
| 14 | 	if (!(b->ref -= cnt)) free(b); | ||
| 15 | 	else UNLOCK(b->lock); | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gai_strerror.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | #include "locale_impl.h" | ||
| 3 | |||
| 4 | static const char msgs[] = | ||
| 5 | 	"Invalid flags\0" | ||
| 6 | 	"Name does not resolve\0" | ||
| 7 | 	"Try again\0" | ||
| 8 | 	"Non-recoverable error\0" | ||
| 9 | 	"Unknown error\0" | ||
| 10 | 	"Unrecognized address family or invalid length\0" | ||
| 11 | 	"Unrecognized socket type\0" | ||
| 12 | 	"Unrecognized service\0" | ||
| 13 | 	"Unknown error\0" | ||
| 14 | 	"Out of memory\0" | ||
| 15 | 	"System error\0" | ||
| 16 | 	"Overflow\0" | ||
| 17 | 	"\0Unknown error"; | ||
| 18 | |||
| 19 | const char *gai_strerror(int ecode) | ||
| 20 | { | ||
| 21 | 	const char *s; | ||
| 22 | 	for (s=msgs, ecode++; ecode && *s; ecode++, s++) for (; *s; s++); | ||
| 23 | 	if (!*s) s++; | ||
| 24 | 	return LCTRANS_CUR(s); | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getaddrinfo.c created+135| ... | @@ -0,0 +1,135 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <netinet/in.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <pthread.h> | ||
| 7 | #include <unistd.h> | ||
| 8 | #include <endian.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include "lookup.h" | ||
| 11 | |||
| 12 | int getaddrinfo(const char *restrict host, const char *restrict serv, const struct addrinfo *restrict hint, struct addrinfo **restrict res) | ||
| 13 | { | ||
| 14 | 	struct service ports[MAXSERVS]; | ||
| 15 | 	struct address addrs[MAXADDRS]; | ||
| 16 | 	char canon[256], *outcanon; | ||
| 17 | 	int nservs, naddrs, nais, canon_len, i, j, k; | ||
| 18 | 	int family = AF_UNSPEC, flags = 0, proto = 0, socktype = 0; | ||
| 19 | 	struct aibuf *out; | ||
| 20 | |||
| 21 | 	if (!host && !serv) return EAI_NONAME; | ||
| 22 | |||
| 23 | 	if (hint) { | ||
| 24 | 		family = hint->ai_family; | ||
| 25 | 		flags = hint->ai_flags; | ||
| 26 | 		proto = hint->ai_protocol; | ||
| 27 | 		socktype = hint->ai_socktype; | ||
| 28 | |||
| 29 | 		const int mask = AI_PASSIVE | AI_CANONNAME | AI_NUMERICHOST | | ||
| 30 | 			AI_V4MAPPED | AI_ALL | AI_ADDRCONFIG | AI_NUMERICSERV; | ||
| 31 | 		if ((flags & mask) != flags) | ||
| 32 | 			return EAI_BADFLAGS; | ||
| 33 | |||
| 34 | 		switch (family) { | ||
| 35 | 		case AF_INET: | ||
| 36 | 		case AF_INET6: | ||
| 37 | 		case AF_UNSPEC: | ||
| 38 | 			break; | ||
| 39 | 		default: | ||
| 40 | 			return EAI_FAMILY; | ||
| 41 | 		} | ||
| 42 | 	} | ||
| 43 | |||
| 44 | 	if (flags & AI_ADDRCONFIG) { | ||
| 45 | 		/* Define the "an address is configured" condition for address | ||
| 46 | 		 * families via ability to create a socket for the family plus | ||
| 47 | 		 * routability of the loopback address for the family. */ | ||
| 48 | 		static const struct sockaddr_in lo4 = { | ||
| 49 | 			.sin_family = AF_INET, .sin_port = 65535, | ||
| 50 | 			.sin_addr.s_addr = __BYTE_ORDER == __BIG_ENDIAN | ||
| 51 | 				? 0x7f000001 : 0x0100007f | ||
| 52 | 		}; | ||
| 53 | 		static const struct sockaddr_in6 lo6 = { | ||
| 54 | 			.sin6_family = AF_INET6, .sin6_port = 65535, | ||
| 55 | 			.sin6_addr = IN6ADDR_LOOPBACK_INIT | ||
| 56 | 		}; | ||
| 57 | 		int tf[2] = { AF_INET, AF_INET6 }; | ||
| 58 | 		const void *ta[2] = { &lo4, &lo6 }; | ||
| 59 | 		socklen_t tl[2] = { sizeof lo4, sizeof lo6 }; | ||
| 60 | 		for (i=0; i<2; i++) { | ||
| 61 | 			if (family==tf[1-i]) continue; | ||
| 62 | 			int s = socket(tf[i], SOCK_CLOEXEC|SOCK_DGRAM, | ||
| 63 | 				IPPROTO_UDP); | ||
| 64 | 			if (s>=0) { | ||
| 65 | 				int cs; | ||
| 66 | 				pthread_setcancelstate( | ||
| 67 | 					PTHREAD_CANCEL_DISABLE, &cs); | ||
| 68 | 				int r = connect(s, ta[i], tl[i]); | ||
| 69 | 				pthread_setcancelstate(cs, 0); | ||
| 70 | 				close(s); | ||
| 71 | 				if (!r) continue; | ||
| 72 | 			} | ||
| 73 | 			switch (errno) { | ||
| 74 | 			case EADDRNOTAVAIL: | ||
| 75 | 			case EAFNOSUPPORT: | ||
| 76 | 			case EHOSTUNREACH: | ||
| 77 | 			case ENETDOWN: | ||
| 78 | 			case ENETUNREACH: | ||
| 79 | 				break; | ||
| 80 | 			default: | ||
| 81 | 				return EAI_SYSTEM; | ||
| 82 | 			} | ||
| 83 | 			if (family == tf[i]) return EAI_NONAME; | ||
| 84 | 			family = tf[1-i]; | ||
| 85 | 		} | ||
| 86 | 	} | ||
| 87 | |||
| 88 | 	nservs = __lookup_serv(ports, serv, proto, socktype, flags); | ||
| 89 | 	if (nservs < 0) return nservs; | ||
| 90 | |||
| 91 | 	naddrs = __lookup_name(addrs, canon, host, family, flags); | ||
| 92 | 	if (naddrs < 0) return naddrs; | ||
| 93 | |||
| 94 | 	nais = nservs * naddrs; | ||
| 95 | 	canon_len = strlen(canon); | ||
| 96 | 	out = calloc(1, nais * sizeof(*out) + canon_len + 1); | ||
| 97 | 	if (!out) return EAI_MEMORY; | ||
| 98 | |||
| 99 | 	if (canon_len) { | ||
| 100 | 		outcanon = (void *)&out[nais]; | ||
| 101 | 		memcpy(outcanon, canon, canon_len+1); | ||
| 102 | 	} else { | ||
| 103 | 		outcanon = 0; | ||
| 104 | 	} | ||
| 105 | |||
| 106 | 	for (k=i=0; i<naddrs; i++) for (j=0; j<nservs; j++, k++) { | ||
| 107 | 		out[k].slot = k; | ||
| 108 | 		out[k].ai = (struct addrinfo){ | ||
| 109 | 			.ai_family = addrs[i].family, | ||
| 110 | 			.ai_socktype = ports[j].socktype, | ||
| 111 | 			.ai_protocol = ports[j].proto, | ||
| 112 | 			.ai_addrlen = addrs[i].family == AF_INET | ||
| 113 | 				? sizeof(struct sockaddr_in) | ||
| 114 | 				: sizeof(struct sockaddr_in6), | ||
| 115 | 			.ai_addr = (void *)&out[k].sa, | ||
| 116 | 			.ai_canonname = outcanon }; | ||
| 117 | 		if (k) out[k-1].ai.ai_next = &out[k].ai; | ||
| 118 | 		switch (addrs[i].family) { | ||
| 119 | 		case AF_INET: | ||
| 120 | 			out[k].sa.sin.sin_family = AF_INET; | ||
| 121 | 			out[k].sa.sin.sin_port = htons(ports[j].port); | ||
| 122 | 			memcpy(&out[k].sa.sin.sin_addr, &addrs[i].addr, 4); | ||
| 123 | 			break; | ||
| 124 | 		case AF_INET6: | ||
| 125 | 			out[k].sa.sin6.sin6_family = AF_INET6; | ||
| 126 | 			out[k].sa.sin6.sin6_port = htons(ports[j].port); | ||
| 127 | 			out[k].sa.sin6.sin6_scope_id = addrs[i].scopeid; | ||
| 128 | 			memcpy(&out[k].sa.sin6.sin6_addr, &addrs[i].addr, 16); | ||
| 129 | 			break;			 | ||
| 130 | 		} | ||
| 131 | 	} | ||
| 132 | 	out[0].ref = nais; | ||
| 133 | 	*res = &out->ai; | ||
| 134 | 	return 0; | ||
| 135 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyaddr.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include <netdb.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | struct hostent *gethostbyaddr(const void *a, socklen_t l, int af) | ||
| 8 | { | ||
| 9 | 	static struct hostent *h; | ||
| 10 | 	size_t size = 63; | ||
| 11 | 	struct hostent *res; | ||
| 12 | 	int err; | ||
| 13 | 	do { | ||
| 14 | 		free(h); | ||
| 15 | 		h = malloc(size+=size+1); | ||
| 16 | 		if (!h) { | ||
| 17 | 			h_errno = NO_RECOVERY; | ||
| 18 | 			return 0; | ||
| 19 | 		} | ||
| 20 | 		err = gethostbyaddr_r(a, l, af, h, | ||
| 21 | 			(void *)(h+1), size-sizeof *h, &res, &h_errno); | ||
| 22 | 	} while (err == ERANGE); | ||
| 23 | 	return err ? 0 : h; | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyaddr_r.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <netinet/in.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <inttypes.h> | ||
| 9 | |||
| 10 | int gethostbyaddr_r(const void *a, socklen_t l, int af, | ||
| 11 | 	struct hostent *h, char *buf, size_t buflen, | ||
| 12 | 	struct hostent **res, int *err) | ||
| 13 | { | ||
| 14 | 	union { | ||
| 15 | 		struct sockaddr_in sin; | ||
| 16 | 		struct sockaddr_in6 sin6; | ||
| 17 | 	} sa = { .sin.sin_family = af }; | ||
| 18 | 	socklen_t sl = af==AF_INET6 ? sizeof sa.sin6 : sizeof sa.sin; | ||
| 19 | 	int i; | ||
| 20 | |||
| 21 | 	*res = 0; | ||
| 22 | |||
| 23 | 	/* Load address argument into sockaddr structure */ | ||
| 24 | 	if (af==AF_INET6 && l==16) memcpy(&sa.sin6.sin6_addr, a, 16); | ||
| 25 | 	else if (af==AF_INET && l==4) memcpy(&sa.sin.sin_addr, a, 4); | ||
| 26 | 	else { | ||
| 27 | 		*err = NO_RECOVERY; | ||
| 28 | 		return EINVAL; | ||
| 29 | 	} | ||
| 30 | |||
| 31 | 	/* Align buffer and check for space for pointers and ip address */ | ||
| 32 | 	i = (uintptr_t)buf & sizeof(char *)-1; | ||
| 33 | 	if (!i) i = sizeof(char *); | ||
| 34 | 	if (buflen <= 5*sizeof(char *)-i + l) return ERANGE; | ||
| 35 | 	buf += sizeof(char *)-i; | ||
| 36 | 	buflen -= 5*sizeof(char *)-i + l; | ||
| 37 | |||
| 38 | 	h->h_addr_list = (void *)buf; | ||
| 39 | 	buf += 2*sizeof(char *); | ||
| 40 | 	h->h_aliases = (void *)buf; | ||
| 41 | 	buf += 2*sizeof(char *); | ||
| 42 | |||
| 43 | 	h->h_addr_list[0] = buf; | ||
| 44 | 	memcpy(h->h_addr_list[0], a, l); | ||
| 45 | 	buf += l; | ||
| 46 | 	h->h_addr_list[1] = 0; | ||
| 47 | 	h->h_aliases[0] = buf; | ||
| 48 | 	h->h_aliases[1] = 0; | ||
| 49 | |||
| 50 | 	switch (getnameinfo((void *)&sa, sl, buf, buflen, 0, 0, 0)) { | ||
| 51 | 	case EAI_AGAIN: | ||
| 52 | 		*err = TRY_AGAIN; | ||
| 53 | 		return EAGAIN; | ||
| 54 | 	case EAI_OVERFLOW: | ||
| 55 | 		return ERANGE; | ||
| 56 | 	default: | ||
| 57 | 	case EAI_MEMORY: | ||
| 58 | 	case EAI_SYSTEM: | ||
| 59 | 	case EAI_FAIL: | ||
| 60 | 		*err = NO_RECOVERY; | ||
| 61 | 		return errno; | ||
| 62 | 	case 0: | ||
| 63 | 		break; | ||
| 64 | 	} | ||
| 65 | |||
| 66 | 	h->h_addrtype = af; | ||
| 67 | 	h->h_length = l; | ||
| 68 | 	h->h_name = h->h_aliases[0]; | ||
| 69 | 	*res = h; | ||
| 70 | 	return 0; | ||
| 71 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <netinet/in.h> | ||
| 7 | |||
| 8 | struct hostent *gethostbyname(const char *name) | ||
| 9 | { | ||
| 10 | 	return gethostbyname2(name, AF_INET); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname2.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | |||
| 8 | struct hostent *gethostbyname2(const char *name, int af) | ||
| 9 | { | ||
| 10 | 	static struct hostent *h; | ||
| 11 | 	size_t size = 63; | ||
| 12 | 	struct hostent *res; | ||
| 13 | 	int err; | ||
| 14 | 	do { | ||
| 15 | 		free(h); | ||
| 16 | 		h = malloc(size+=size+1); | ||
| 17 | 		if (!h) { | ||
| 18 | 			h_errno = NO_RECOVERY; | ||
| 19 | 			return 0; | ||
| 20 | 		} | ||
| 21 | 		err = gethostbyname2_r(name, af, h, | ||
| 22 | 			(void *)(h+1), size-sizeof *h, &res, &h_errno); | ||
| 23 | 	} while (err == ERANGE); | ||
| 24 | 	return err ? 0 : h; | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname2_r.c created+80| ... | @@ -0,0 +1,80 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <netinet/in.h> | ||
| 7 | #include <errno.h> | ||
| 8 | #include <stdint.h> | ||
| 9 | #include "lookup.h" | ||
| 10 | |||
| 11 | int gethostbyname2_r(const char *name, int af, | ||
| 12 | 	struct hostent *h, char *buf, size_t buflen, | ||
| 13 | 	struct hostent **res, int *err) | ||
| 14 | { | ||
| 15 | 	struct address addrs[MAXADDRS]; | ||
| 16 | 	char canon[256]; | ||
| 17 | 	int i, cnt; | ||
| 18 | 	size_t align, need; | ||
| 19 | |||
| 20 | 	*res = 0; | ||
| 21 | 	cnt = __lookup_name(addrs, canon, name, af, AI_CANONNAME); | ||
| 22 | 	if (cnt<0) switch (cnt) { | ||
| 23 | 	case EAI_NONAME: | ||
| 24 | 		*err = HOST_NOT_FOUND; | ||
| 25 | 		return ENOENT; | ||
| 26 | 	case EAI_AGAIN: | ||
| 27 | 		*err = TRY_AGAIN; | ||
| 28 | 		return EAGAIN; | ||
| 29 | 	default: | ||
| 30 | 	case EAI_FAIL: | ||
| 31 | 		*err = NO_RECOVERY; | ||
| 32 | 		return EBADMSG; | ||
| 33 | 	case EAI_MEMORY: | ||
| 34 | 	case EAI_SYSTEM: | ||
| 35 | 		*err = NO_RECOVERY; | ||
| 36 | 		return errno; | ||
| 37 | 	} | ||
| 38 | |||
| 39 | 	h->h_addrtype = af; | ||
| 40 | 	h->h_length = af==AF_INET6 ? 16 : 4; | ||
| 41 | |||
| 42 | 	/* Align buffer */ | ||
| 43 | 	align = -(uintptr_t)buf & sizeof(char *)-1; | ||
| 44 | |||
| 45 | 	need = 4*sizeof(char *); | ||
| 46 | 	need += (cnt + 1) * (sizeof(char *) + h->h_length); | ||
| 47 | 	need += strlen(name)+1; | ||
| 48 | 	need += strlen(canon)+1; | ||
| 49 | 	need += align; | ||
| 50 | |||
| 51 | 	if (need > buflen) return ERANGE; | ||
| 52 | |||
| 53 | 	buf += align; | ||
| 54 | 	h->h_aliases = (void *)buf; | ||
| 55 | 	buf += 3*sizeof(char *); | ||
| 56 | 	h->h_addr_list = (void *)buf; | ||
| 57 | 	buf += (cnt+1)*sizeof(char *); | ||
| 58 | |||
| 59 | 	for (i=0; i<cnt; i++) { | ||
| 60 | 		h->h_addr_list[i] = (void *)buf; | ||
| 61 | 		buf += h->h_length; | ||
| 62 | 		memcpy(h->h_addr_list[i], addrs[i].addr, h->h_length); | ||
| 63 | 	} | ||
| 64 | 	h->h_addr_list[i] = 0; | ||
| 65 | |||
| 66 | 	h->h_name = h->h_aliases[0] = buf; | ||
| 67 | 	strcpy(h->h_name, canon); | ||
| 68 | 	buf += strlen(h->h_name)+1; | ||
| 69 | |||
| 70 | 	if (strcmp(h->h_name, name)) { | ||
| 71 | 		h->h_aliases[1] = buf; | ||
| 72 | 		strcpy(h->h_aliases[1], name); | ||
| 73 | 		buf += strlen(h->h_aliases[1])+1; | ||
| 74 | 	} else h->h_aliases[1] = 0; | ||
| 75 | |||
| 76 | 	h->h_aliases[2] = 0; | ||
| 77 | |||
| 78 | 	*res = h; | ||
| 79 | 	return 0; | ||
| 80 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/gethostbyname_r.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | |||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | |||
| 6 | int gethostbyname_r(const char *name, | ||
| 7 | 	struct hostent *h, char *buf, size_t buflen, | ||
| 8 | 	struct hostent **res, int *err) | ||
| 9 | { | ||
| 10 | 	return gethostbyname2_r(name, AF_INET, h, buf, buflen, res, err); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getifaddrs.c created+216| ... | @@ -0,0 +1,216 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <errno.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <ifaddrs.h> | ||
| 7 | #include <syscall.h> | ||
| 8 | #include <net/if.h> | ||
| 9 | #include <netinet/in.h> | ||
| 10 | #include "netlink.h" | ||
| 11 | |||
| 12 | #define IFADDRS_HASH_SIZE 64 | ||
| 13 | |||
| 14 | /* getifaddrs() reports hardware addresses with PF_PACKET that implies | ||
| 15 | * struct sockaddr_ll. But e.g. Infiniband socket address length is | ||
| 16 | * longer than sockaddr_ll.ssl_addr[8] can hold. Use this hack struct | ||
| 17 | * to extend ssl_addr - callers should be able to still use it. */ | ||
| 18 | struct sockaddr_ll_hack { | ||
| 19 | 	unsigned short sll_family, sll_protocol; | ||
| 20 | 	int sll_ifindex; | ||
| 21 | 	unsigned short sll_hatype; | ||
| 22 | 	unsigned char sll_pkttype, sll_halen; | ||
| 23 | 	unsigned char sll_addr[24]; | ||
| 24 | }; | ||
| 25 | |||
| 26 | union sockany { | ||
| 27 | 	struct sockaddr sa; | ||
| 28 | 	struct sockaddr_ll_hack ll; | ||
| 29 | 	struct sockaddr_in v4; | ||
| 30 | 	struct sockaddr_in6 v6; | ||
| 31 | }; | ||
| 32 | |||
| 33 | struct ifaddrs_storage { | ||
| 34 | 	struct ifaddrs ifa; | ||
| 35 | 	struct ifaddrs_storage *hash_next; | ||
| 36 | 	union sockany addr, netmask, ifu; | ||
| 37 | 	unsigned int index; | ||
| 38 | 	char name[IFNAMSIZ+1]; | ||
| 39 | }; | ||
| 40 | |||
| 41 | struct ifaddrs_ctx { | ||
| 42 | 	struct ifaddrs_storage *first; | ||
| 43 | 	struct ifaddrs_storage *last; | ||
| 44 | 	struct ifaddrs_storage *hash[IFADDRS_HASH_SIZE]; | ||
| 45 | }; | ||
| 46 | |||
| 47 | void freeifaddrs(struct ifaddrs *ifp) | ||
| 48 | { | ||
| 49 | 	struct ifaddrs *n; | ||
| 50 | 	while (ifp) { | ||
| 51 | 		n = ifp->ifa_next; | ||
| 52 | 		free(ifp); | ||
| 53 | 		ifp = n; | ||
| 54 | 	} | ||
| 55 | } | ||
| 56 | |||
| 57 | static void copy_addr(struct sockaddr **r, int af, union sockany *sa, void *addr, size_t addrlen, int ifindex) | ||
| 58 | { | ||
| 59 | 	uint8_t *dst; | ||
| 60 | 	int len; | ||
| 61 | |||
| 62 | 	switch (af) { | ||
| 63 | 	case AF_INET: | ||
| 64 | 		dst = (uint8_t*) &sa->v4.sin_addr; | ||
| 65 | 		len = 4; | ||
| 66 | 		break; | ||
| 67 | 	case AF_INET6: | ||
| 68 | 		dst = (uint8_t*) &sa->v6.sin6_addr; | ||
| 69 | 		len = 16; | ||
| 70 | 		if (IN6_IS_ADDR_LINKLOCAL(addr) || IN6_IS_ADDR_MC_LINKLOCAL(addr)) | ||
| 71 | 			sa->v6.sin6_scope_id = ifindex; | ||
| 72 | 		break; | ||
| 73 | 	default: | ||
| 74 | 		return; | ||
| 75 | 	} | ||
| 76 | 	if (addrlen < len) return; | ||
| 77 | 	sa->sa.sa_family = af; | ||
| 78 | 	memcpy(dst, addr, len); | ||
| 79 | 	*r = &sa->sa; | ||
| 80 | } | ||
| 81 | |||
| 82 | static void gen_netmask(struct sockaddr **r, int af, union sockany *sa, int prefixlen) | ||
| 83 | { | ||
| 84 | 	uint8_t addr[16] = {0}; | ||
| 85 | 	int i; | ||
| 86 | |||
| 87 | 	if (prefixlen > 8*sizeof(addr)) prefixlen = 8*sizeof(addr); | ||
| 88 | 	i = prefixlen / 8; | ||
| 89 | 	memset(addr, 0xff, i); | ||
| 90 | 	if (i < sizeof(addr)) addr[i++] = 0xff << (8 - (prefixlen % 8)); | ||
| 91 | 	copy_addr(r, af, sa, addr, sizeof(addr), 0); | ||
| 92 | } | ||
| 93 | |||
| 94 | static void copy_lladdr(struct sockaddr **r, union sockany *sa, void *addr, size_t addrlen, int ifindex, unsigned short hatype) | ||
| 95 | { | ||
| 96 | 	if (addrlen > sizeof(sa->ll.sll_addr)) return; | ||
| 97 | 	sa->ll.sll_family = AF_PACKET; | ||
| 98 | 	sa->ll.sll_ifindex = ifindex; | ||
| 99 | 	sa->ll.sll_hatype = hatype; | ||
| 100 | 	sa->ll.sll_halen = addrlen; | ||
| 101 | 	memcpy(sa->ll.sll_addr, addr, addrlen); | ||
| 102 | 	*r = &sa->sa; | ||
| 103 | } | ||
| 104 | |||
| 105 | static int netlink_msg_to_ifaddr(void *pctx, struct nlmsghdr *h) | ||
| 106 | { | ||
| 107 | 	struct ifaddrs_ctx *ctx = pctx; | ||
| 108 | 	struct ifaddrs_storage *ifs, *ifs0; | ||
| 109 | 	struct ifinfomsg *ifi = NLMSG_DATA(h); | ||
| 110 | 	struct ifaddrmsg *ifa = NLMSG_DATA(h); | ||
| 111 | 	struct rtattr *rta; | ||
| 112 | 	int stats_len = 0; | ||
| 113 | |||
| 114 | 	if (h->nlmsg_type == RTM_NEWLINK) { | ||
| 115 | 		for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { | ||
| 116 | 			if (rta->rta_type != IFLA_STATS) continue; | ||
| 117 | 			stats_len = RTA_DATALEN(rta); | ||
| 118 | 			break; | ||
| 119 | 		} | ||
| 120 | 	} else { | ||
| 121 | 		for (ifs0 = ctx->hash[ifa->ifa_index % IFADDRS_HASH_SIZE]; ifs0; ifs0 = ifs0->hash_next) | ||
| 122 | 			if (ifs0->index == ifa->ifa_index) | ||
| 123 | 				break; | ||
| 124 | 		if (!ifs0) return 0; | ||
| 125 | 	} | ||
| 126 | |||
| 127 | 	ifs = calloc(1, sizeof(struct ifaddrs_storage) + stats_len); | ||
| 128 | 	if (ifs == 0) return -1; | ||
| 129 | |||
| 130 | 	if (h->nlmsg_type == RTM_NEWLINK) { | ||
| 131 | 		ifs->index = ifi->ifi_index; | ||
| 132 | 		ifs->ifa.ifa_flags = ifi->ifi_flags; | ||
| 133 | |||
| 134 | 		for (rta = NLMSG_RTA(h, sizeof(*ifi)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { | ||
| 135 | 			switch (rta->rta_type) { | ||
| 136 | 			case IFLA_IFNAME: | ||
| 137 | 				if (RTA_DATALEN(rta) < sizeof(ifs->name)) { | ||
| 138 | 					memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta)); | ||
| 139 | 					ifs->ifa.ifa_name = ifs->name; | ||
| 140 | 				} | ||
| 141 | 				break; | ||
| 142 | 			case IFLA_ADDRESS: | ||
| 143 | 				copy_lladdr(&ifs->ifa.ifa_addr, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type); | ||
| 144 | 				break; | ||
| 145 | 			case IFLA_BROADCAST: | ||
| 146 | 				copy_lladdr(&ifs->ifa.ifa_broadaddr, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifi->ifi_index, ifi->ifi_type); | ||
| 147 | 				break; | ||
| 148 | 			case IFLA_STATS: | ||
| 149 | 				ifs->ifa.ifa_data = (void*)(ifs+1); | ||
| 150 | 				memcpy(ifs->ifa.ifa_data, RTA_DATA(rta), RTA_DATALEN(rta)); | ||
| 151 | 				break; | ||
| 152 | 			} | ||
| 153 | 		} | ||
| 154 | 		if (ifs->ifa.ifa_name) { | ||
| 155 | 			unsigned int bucket = ifs->index % IFADDRS_HASH_SIZE; | ||
| 156 | 			ifs->hash_next = ctx->hash[bucket]; | ||
| 157 | 			ctx->hash[bucket] = ifs; | ||
| 158 | 		} | ||
| 159 | 	} else { | ||
| 160 | 		ifs->ifa.ifa_name = ifs0->ifa.ifa_name; | ||
| 161 | 		ifs->ifa.ifa_flags = ifs0->ifa.ifa_flags; | ||
| 162 | 		for (rta = NLMSG_RTA(h, sizeof(*ifa)); NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { | ||
| 163 | 			switch (rta->rta_type) { | ||
| 164 | 			case IFA_ADDRESS: | ||
| 165 | 				/* If ifa_addr is already set we, received an IFA_LOCAL before | ||
| 166 | 				 * so treat this as destination address */ | ||
| 167 | 				if (ifs->ifa.ifa_addr) | ||
| 168 | 					copy_addr(&ifs->ifa.ifa_dstaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); | ||
| 169 | 				else | ||
| 170 | 					copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); | ||
| 171 | 				break; | ||
| 172 | 			case IFA_BROADCAST: | ||
| 173 | 				copy_addr(&ifs->ifa.ifa_broadaddr, ifa->ifa_family, &ifs->ifu, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); | ||
| 174 | 				break; | ||
| 175 | 			case IFA_LOCAL: | ||
| 176 | 				/* If ifa_addr is set and we get IFA_LOCAL, assume we have | ||
| 177 | 				 * a point-to-point network. Move address to correct field. */ | ||
| 178 | 				if (ifs->ifa.ifa_addr) { | ||
| 179 | 					ifs->ifu = ifs->addr; | ||
| 180 | 					ifs->ifa.ifa_dstaddr = &ifs->ifu.sa; | ||
| 181 | 					memset(&ifs->addr, 0, sizeof(ifs->addr)); | ||
| 182 | 				} | ||
| 183 | 				copy_addr(&ifs->ifa.ifa_addr, ifa->ifa_family, &ifs->addr, RTA_DATA(rta), RTA_DATALEN(rta), ifa->ifa_index); | ||
| 184 | 				break; | ||
| 185 | 			case IFA_LABEL: | ||
| 186 | 				if (RTA_DATALEN(rta) < sizeof(ifs->name)) { | ||
| 187 | 					memcpy(ifs->name, RTA_DATA(rta), RTA_DATALEN(rta)); | ||
| 188 | 					ifs->ifa.ifa_name = ifs->name; | ||
| 189 | 				} | ||
| 190 | 				break; | ||
| 191 | 			} | ||
| 192 | 		} | ||
| 193 | 		if (ifs->ifa.ifa_addr) | ||
| 194 | 			gen_netmask(&ifs->ifa.ifa_netmask, ifa->ifa_family, &ifs->netmask, ifa->ifa_prefixlen); | ||
| 195 | 	} | ||
| 196 | |||
| 197 | 	if (ifs->ifa.ifa_name) { | ||
| 198 | 		if (!ctx->first) ctx->first = ifs; | ||
| 199 | 		if (ctx->last) ctx->last->ifa.ifa_next = &ifs->ifa; | ||
| 200 | 		ctx->last = ifs; | ||
| 201 | 	} else { | ||
| 202 | 		free(ifs); | ||
| 203 | 	} | ||
| 204 | 	return 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | int getifaddrs(struct ifaddrs **ifap) | ||
| 208 | { | ||
| 209 | 	struct ifaddrs_ctx _ctx, *ctx = &_ctx; | ||
| 210 | 	int r; | ||
| 211 | 	memset(ctx, 0, sizeof *ctx); | ||
| 212 | 	r = __rtnetlink_enumerate(AF_UNSPEC, AF_UNSPEC, netlink_msg_to_ifaddr, ctx); | ||
| 213 | 	if (r == 0) *ifap = &ctx->first->ifa; | ||
| 214 | 	else freeifaddrs(&ctx->first->ifa); | ||
| 215 | 	return r; | ||
| 216 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getnameinfo.c created+200| ... | @@ -0,0 +1,200 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <sys/socket.h> | ||
| 7 | #include <netinet/in.h> | ||
| 8 | #include <arpa/inet.h> | ||
| 9 | #include <net/if.h> | ||
| 10 | #include <ctype.h> | ||
| 11 | #include <resolv.h> | ||
| 12 | #include "lookup.h" | ||
| 13 | #include "stdio_impl.h" | ||
| 14 | |||
| 15 | #define PTR_MAX (64 + sizeof ".in-addr.arpa") | ||
| 16 | #define RR_PTR 12 | ||
| 17 | |||
| 18 | static char *itoa(char *p, unsigned x) { | ||
| 19 | 	p += 3*sizeof(int); | ||
| 20 | 	*--p = 0; | ||
| 21 | 	do { | ||
| 22 | 		*--p = '0' + x % 10; | ||
| 23 | 		x /= 10; | ||
| 24 | 	} while (x); | ||
| 25 | 	return p; | ||
| 26 | } | ||
| 27 | |||
| 28 | static void mkptr4(char *s, const unsigned char *ip) | ||
| 29 | { | ||
| 30 | 	sprintf(s, "%d.%d.%d.%d.in-addr.arpa", | ||
| 31 | 		ip[3], ip[2], ip[1], ip[0]); | ||
| 32 | } | ||
| 33 | |||
| 34 | static void mkptr6(char *s, const unsigned char *ip) | ||
| 35 | { | ||
| 36 | 	static const char xdigits[] = "0123456789abcdef"; | ||
| 37 | 	int i; | ||
| 38 | 	for (i=15; i>=0; i--) { | ||
| 39 | 		*s++ = xdigits[ip[i]&15]; *s++ = '.'; | ||
| 40 | 		*s++ = xdigits[ip[i]>>4]; *s++ = '.'; | ||
| 41 | 	} | ||
| 42 | 	strcpy(s, "ip6.arpa"); | ||
| 43 | } | ||
| 44 | |||
| 45 | static void reverse_hosts(char *buf, const unsigned char *a, unsigned scopeid, int family) | ||
| 46 | { | ||
| 47 | 	char line[512], *p, *z; | ||
| 48 | 	unsigned char _buf[1032], atmp[16]; | ||
| 49 | 	struct address iplit; | ||
| 50 | 	FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); | ||
| 51 | 	if (!f) return; | ||
| 52 | 	if (family == AF_INET) { | ||
| 53 | 		memcpy(atmp+12, a, 4); | ||
| 54 | 		memcpy(atmp, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); | ||
| 55 | 		a = atmp; | ||
| 56 | 	} | ||
| 57 | 	while (fgets(line, sizeof line, f)) { | ||
| 58 | 		if ((p=strchr(line, '#'))) *p++='\n', *p=0; | ||
| 59 | |||
| 60 | 		for (p=line; *p && !isspace(*p); p++); | ||
| 61 | 		*p++ = 0; | ||
| 62 | 		if (__lookup_ipliteral(&iplit, line, AF_UNSPEC)<=0) | ||
| 63 | 			continue; | ||
| 64 | |||
| 65 | 		if (iplit.family == AF_INET) { | ||
| 66 | 			memcpy(iplit.addr+12, iplit.addr, 4); | ||
| 67 | 			memcpy(iplit.addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); | ||
| 68 | 			iplit.scopeid = 0; | ||
| 69 | 		} | ||
| 70 | |||
| 71 | 		if (memcmp(a, iplit.addr, 16) || iplit.scopeid != scopeid) | ||
| 72 | 			continue; | ||
| 73 | 			 | ||
| 74 | 		for (; *p && isspace(*p); p++); | ||
| 75 | 		for (z=p; *z && !isspace(*z); z++); | ||
| 76 | 		*z = 0; | ||
| 77 | 		if (z-p < 256) { | ||
| 78 | 			memcpy(buf, p, z-p+1); | ||
| 79 | 			break; | ||
| 80 | 		} | ||
| 81 | 	} | ||
| 82 | 	__fclose_ca(f); | ||
| 83 | } | ||
| 84 | |||
| 85 | static void reverse_services(char *buf, int port, int dgram) | ||
| 86 | { | ||
| 87 | 	unsigned long svport; | ||
| 88 | 	char line[128], *p, *z; | ||
| 89 | 	unsigned char _buf[1032]; | ||
| 90 | 	FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); | ||
| 91 | 	if (!f) return; | ||
| 92 | 	while (fgets(line, sizeof line, f)) { | ||
| 93 | 		if ((p=strchr(line, '#'))) *p++='\n', *p=0; | ||
| 94 | |||
| 95 | 		for (p=line; *p && !isspace(*p); p++); | ||
| 96 | 		if (!*p) continue; | ||
| 97 | 		*p++ = 0; | ||
| 98 | 		svport = strtoul(p, &z, 10); | ||
| 99 | |||
| 100 | 		if (svport != port || z==p) continue; | ||
| 101 | 		if (dgram && strncmp(z, "/udp", 4)) continue; | ||
| 102 | 		if (!dgram && strncmp(z, "/tcp", 4)) continue; | ||
| 103 | 		if (p-line > 32) continue; | ||
| 104 | |||
| 105 | 		memcpy(buf, line, p-line); | ||
| 106 | 		break; | ||
| 107 | 	} | ||
| 108 | 	__fclose_ca(f); | ||
| 109 | } | ||
| 110 | |||
| 111 | static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet) | ||
| 112 | { | ||
| 113 | 	if (rr != RR_PTR) return 0; | ||
| 114 | 	if (__dn_expand(packet, (const unsigned char *)packet + 512, | ||
| 115 | 	 data, c, 256) <= 0) | ||
| 116 | 		*(char *)c = 0; | ||
| 117 | 	return 0; | ||
| 118 | 	 | ||
| 119 | } | ||
| 120 | |||
| 121 | int getnameinfo(const struct sockaddr *restrict sa, socklen_t sl, | ||
| 122 | 	char *restrict node, socklen_t nodelen, | ||
| 123 | 	char *restrict serv, socklen_t servlen, | ||
| 124 | 	int flags) | ||
| 125 | { | ||
| 126 | 	char ptr[PTR_MAX]; | ||
| 127 | 	char buf[256], num[3*sizeof(int)+1]; | ||
| 128 | 	int af = sa->sa_family; | ||
| 129 | 	unsigned char *a; | ||
| 130 | 	unsigned scopeid; | ||
| 131 | |||
| 132 | 	switch (af) { | ||
| 133 | 	case AF_INET: | ||
| 134 | 		a = (void *)&((struct sockaddr_in *)sa)->sin_addr; | ||
| 135 | 		if (sl < sizeof(struct sockaddr_in)) return EAI_FAMILY; | ||
| 136 | 		mkptr4(ptr, a); | ||
| 137 | 		scopeid = 0; | ||
| 138 | 		break; | ||
| 139 | 	case AF_INET6: | ||
| 140 | 		a = (void *)&((struct sockaddr_in6 *)sa)->sin6_addr; | ||
| 141 | 		if (sl < sizeof(struct sockaddr_in6)) return EAI_FAMILY; | ||
| 142 | 		if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12)) | ||
| 143 | 			mkptr6(ptr, a); | ||
| 144 | 		else | ||
| 145 | 			mkptr4(ptr, a+12); | ||
| 146 | 		scopeid = ((struct sockaddr_in6 *)sa)->sin6_scope_id; | ||
| 147 | 		break; | ||
| 148 | 	default: | ||
| 149 | 		return EAI_FAMILY; | ||
| 150 | 	} | ||
| 151 | |||
| 152 | 	if (node && nodelen) { | ||
| 153 | 		buf[0] = 0; | ||
| 154 | 		if (!(flags & NI_NUMERICHOST)) { | ||
| 155 | 			reverse_hosts(buf, a, scopeid, af); | ||
| 156 | 		} | ||
| 157 | 		if (!*buf && !(flags & NI_NUMERICHOST)) { | ||
| 158 | 			unsigned char query[18+PTR_MAX], reply[512]; | ||
| 159 | 			int qlen = __res_mkquery(0, ptr, 1, RR_PTR, | ||
| 160 | 				0, 0, 0, query, sizeof query); | ||
| 161 | 			query[3] = 0; /* don't need AD flag */ | ||
| 162 | 			int rlen = __res_send(query, qlen, reply, sizeof reply); | ||
| 163 | 			buf[0] = 0; | ||
| 164 | 			if (rlen > 0) | ||
| 165 | 				__dns_parse(reply, rlen, dns_parse_callback, buf); | ||
| 166 | 		} | ||
| 167 | 		if (!*buf) { | ||
| 168 | 			if (flags & NI_NAMEREQD) return EAI_NONAME; | ||
| 169 | 			inet_ntop(af, a, buf, sizeof buf); | ||
| 170 | 			if (scopeid) { | ||
| 171 | 				char *p = 0, tmp[IF_NAMESIZE+1]; | ||
| 172 | 				if (!(flags & NI_NUMERICSCOPE) && | ||
| 173 | 				 (IN6_IS_ADDR_LINKLOCAL(a) || | ||
| 174 | 				 IN6_IS_ADDR_MC_LINKLOCAL(a))) | ||
| 175 | 					p = if_indextoname(scopeid, tmp+1); | ||
| 176 | 				if (!p) | ||
| 177 | 					p = itoa(num, scopeid); | ||
| 178 | 				*--p = '%'; | ||
| 179 | 				strcat(buf, p); | ||
| 180 | 			} | ||
| 181 | 		} | ||
| 182 | 		if (strlen(buf) >= nodelen) return EAI_OVERFLOW; | ||
| 183 | 		strcpy(node, buf); | ||
| 184 | 	} | ||
| 185 | |||
| 186 | 	if (serv && servlen) { | ||
| 187 | 		char *p = buf; | ||
| 188 | 		int port = ntohs(((struct sockaddr_in *)sa)->sin_port); | ||
| 189 | 		buf[0] = 0; | ||
| 190 | 		if (!(flags & NI_NUMERICSERV)) | ||
| 191 | 			reverse_services(buf, port, flags & NI_DGRAM); | ||
| 192 | 		if (!*p) | ||
| 193 | 			p = itoa(num, port); | ||
| 194 | 		if (strlen(p) >= servlen) | ||
| 195 | 			return EAI_OVERFLOW; | ||
| 196 | 		strcpy(serv, p); | ||
| 197 | 	} | ||
| 198 | |||
| 199 | 	return 0; | ||
| 200 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getpeername.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int getpeername(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) | ||
| 5 | { | ||
| 6 | 	return socketcall(getpeername, fd, addr, len, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getservbyname.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <netdb.h> | ||
| 3 | |||
| 4 | struct servent *getservbyname(const char *name, const char *prots) | ||
| 5 | { | ||
| 6 | 	static struct servent se; | ||
| 7 | 	static char *buf[2]; | ||
| 8 | 	struct servent *res; | ||
| 9 | 	if (getservbyname_r(name, prots, &se, (void *)buf, sizeof buf, &res)) | ||
| 10 | 		return 0; | ||
| 11 | 	return &se; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getservbyname_r.c created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <netinet/in.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <inttypes.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | #include "lookup.h" | ||
| 10 | |||
| 11 | #define ALIGN (sizeof(struct { char a; char *b; }) - sizeof(char *)) | ||
| 12 | |||
| 13 | int getservbyname_r(const char *name, const char *prots, | ||
| 14 | 	struct servent *se, char *buf, size_t buflen, struct servent **res) | ||
| 15 | { | ||
| 16 | 	struct service servs[MAXSERVS]; | ||
| 17 | 	int cnt, proto, align; | ||
| 18 | |||
| 19 | 	*res = 0; | ||
| 20 | |||
| 21 | 	/* Don't treat numeric port number strings as service records. */ | ||
| 22 | 	char *end = ""; | ||
| 23 | 	strtoul(name, &end, 10); | ||
| 24 | 	if (!*end) return ENOENT; | ||
| 25 | |||
| 26 | 	/* Align buffer */ | ||
| 27 | 	align = -(uintptr_t)buf & ALIGN-1; | ||
| 28 | 	if (buflen < 2*sizeof(char *)+align) | ||
| 29 | 		return ERANGE; | ||
| 30 | 	buf += align; | ||
| 31 | |||
| 32 | 	if (!prots) proto = 0; | ||
| 33 | 	else if (!strcmp(prots, "tcp")) proto = IPPROTO_TCP; | ||
| 34 | 	else if (!strcmp(prots, "udp")) proto = IPPROTO_UDP; | ||
| 35 | 	else return EINVAL; | ||
| 36 | |||
| 37 | 	cnt = __lookup_serv(servs, name, proto, 0, 0); | ||
| 38 | 	if (cnt<0) switch (cnt) { | ||
| 39 | 	case EAI_MEMORY: | ||
| 40 | 	case EAI_SYSTEM: | ||
| 41 | 		return ENOMEM; | ||
| 42 | 	default: | ||
| 43 | 		return ENOENT; | ||
| 44 | 	} | ||
| 45 | |||
| 46 | 	se->s_name = (char *)name; | ||
| 47 | 	se->s_aliases = (void *)buf; | ||
| 48 | 	se->s_aliases[0] = se->s_name; | ||
| 49 | 	se->s_aliases[1] = 0; | ||
| 50 | 	se->s_port = htons(servs[0].port); | ||
| 51 | 	se->s_proto = servs[0].proto == IPPROTO_TCP ? "tcp" : "udp"; | ||
| 52 | |||
| 53 | 	*res = se; | ||
| 54 | 	return 0; | ||
| 55 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getservbyport.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <netdb.h> | ||
| 3 | |||
| 4 | struct servent *getservbyport(int port, const char *prots) | ||
| 5 | { | ||
| 6 | 	static struct servent se; | ||
| 7 | 	static long buf[32/sizeof(long)]; | ||
| 8 | 	struct servent *res; | ||
| 9 | 	if (getservbyport_r(port, prots, &se, (void *)buf, sizeof buf, &res)) | ||
| 10 | 		return 0; | ||
| 11 | 	return &se; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getservbyport_r.c created+60| ... | @@ -0,0 +1,60 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <netinet/in.h> | ||
| 4 | #include <netdb.h> | ||
| 5 | #include <inttypes.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stdlib.h> | ||
| 9 | |||
| 10 | int getservbyport_r(int port, const char *prots, | ||
| 11 | 	struct servent *se, char *buf, size_t buflen, struct servent **res) | ||
| 12 | { | ||
| 13 | 	int i; | ||
| 14 | 	struct sockaddr_in sin = { | ||
| 15 | 		.sin_family = AF_INET, | ||
| 16 | 		.sin_port = port, | ||
| 17 | 	}; | ||
| 18 | |||
| 19 | 	if (!prots) { | ||
| 20 | 		int r = getservbyport_r(port, "tcp", se, buf, buflen, res); | ||
| 21 | 		if (r) r = getservbyport_r(port, "udp", se, buf, buflen, res); | ||
| 22 | 		return r; | ||
| 23 | 	} | ||
| 24 | 	*res = 0; | ||
| 25 | |||
| 26 | 	/* Align buffer */ | ||
| 27 | 	i = (uintptr_t)buf & sizeof(char *)-1; | ||
| 28 | 	if (!i) i = sizeof(char *); | ||
| 29 | 	if (buflen < 3*sizeof(char *)-i) | ||
| 30 | 		return ERANGE; | ||
| 31 | 	buf += sizeof(char *)-i; | ||
| 32 | 	buflen -= sizeof(char *)-i; | ||
| 33 | |||
| 34 | 	if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL; | ||
| 35 | |||
| 36 | 	se->s_port = port; | ||
| 37 | 	se->s_proto = (char *)prots; | ||
| 38 | 	se->s_aliases = (void *)buf; | ||
| 39 | 	buf += 2*sizeof(char *); | ||
| 40 | 	buflen -= 2*sizeof(char *); | ||
| 41 | 	se->s_aliases[1] = 0; | ||
| 42 | 	se->s_aliases[0] = se->s_name = buf; | ||
| 43 | |||
| 44 | 	switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen, | ||
| 45 | 		strcmp(prots, "udp") ? 0 : NI_DGRAM)) { | ||
| 46 | 	case EAI_MEMORY: | ||
| 47 | 	case EAI_SYSTEM: | ||
| 48 | 		return ENOMEM; | ||
| 49 | 	default: | ||
| 50 | 		return ENOENT; | ||
| 51 | 	case 0: | ||
| 52 | 		break; | ||
| 53 | 	} | ||
| 54 | |||
| 55 | 	/* A numeric port string is not a service record. */ | ||
| 56 | 	if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT; | ||
| 57 | |||
| 58 | 	*res = se; | ||
| 59 | 	return 0; | ||
| 60 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getsockname.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int getsockname(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) | ||
| 5 | { | ||
| 6 | 	return socketcall(getsockname, fd, addr, len, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/getsockopt.c created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int getsockopt(int fd, int level, int optname, void *restrict optval, socklen_t *restrict optlen) | ||
| 7 | { | ||
| 8 | 	long tv32[2]; | ||
| 9 | 	struct timeval *tv; | ||
| 10 | |||
| 11 | 	int r = __socketcall(getsockopt, fd, level, optname, optval, optlen, 0); | ||
| 12 | |||
| 13 | 	if (r==-ENOPROTOOPT) switch (level) { | ||
| 14 | 	case SOL_SOCKET: | ||
| 15 | 		switch (optname) { | ||
| 16 | 		case SO_RCVTIMEO: | ||
| 17 | 		case SO_SNDTIMEO: | ||
| 18 | 			if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break; | ||
| 19 | 			if (*optlen < sizeof *tv) return __syscall_ret(-EINVAL); | ||
| 20 | 			if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD; | ||
| 21 | 			if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD; | ||
| 22 | 			r = __socketcall(getsockopt, fd, level, optname, | ||
| 23 | 				tv32, (socklen_t[]){sizeof tv32}, 0); | ||
| 24 | 			if (r<0) break; | ||
| 25 | 			tv = optval; | ||
| 26 | 			tv->tv_sec = tv32[0]; | ||
| 27 | 			tv->tv_usec = tv32[1]; | ||
| 28 | 			*optlen = sizeof *tv; | ||
| 29 | 			break; | ||
| 30 | 		case SO_TIMESTAMP: | ||
| 31 | 		case SO_TIMESTAMPNS: | ||
| 32 | 			if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break; | ||
| 33 | 			if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD; | ||
| 34 | 			if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD; | ||
| 35 | 			r = __socketcall(getsockopt, fd, level, | ||
| 36 | 				optname, optval, optlen, 0); | ||
| 37 | 			break; | ||
| 38 | 		} | ||
| 39 | 	} | ||
| 40 | 	return __syscall_ret(r); | ||
| 41 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/h_errno.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | #undef h_errno | ||
| 5 | int h_errno; | ||
| 6 | |||
| 7 | int *__h_errno_location(void) | ||
| 8 | { | ||
| 9 | 	if (!__pthread_self()->stack) return &h_errno; | ||
| 10 | 	return &__pthread_self()->h_errno_val; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/herror.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | |||
| 5 | void herror(const char *msg) | ||
| 6 | { | ||
| 7 | 	fprintf(stderr, "%s%s%s\n", msg?msg:"", msg?": ":"", hstrerror(h_errno)); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/hstrerror.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <netdb.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | static const char msgs[] = | ||
| 6 | 	"Host not found\0" | ||
| 7 | 	"Try again\0" | ||
| 8 | 	"Non-recoverable error\0" | ||
| 9 | 	"Address not available\0" | ||
| 10 | 	"\0Unknown error"; | ||
| 11 | |||
| 12 | const char *hstrerror(int ecode) | ||
| 13 | { | ||
| 14 | 	const char *s; | ||
| 15 | 	for (s=msgs, ecode--; ecode && *s; ecode--, s++) for (; *s; s++); | ||
| 16 | 	if (!*s) s++; | ||
| 17 | 	return LCTRANS_CUR(s); | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/htonl.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <netinet/in.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | |||
| 4 | uint32_t htonl(uint32_t n) | ||
| 5 | { | ||
| 6 | 	union { int i; char c; } u = { 1 }; | ||
| 7 | 	return u.c ? bswap_32(n) : n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/htons.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <netinet/in.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | |||
| 4 | uint16_t htons(uint16_t n) | ||
| 5 | { | ||
| 6 | 	union { int i; char c; } u = { 1 }; | ||
| 7 | 	return u.c ? bswap_16(n) : n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/if_freenameindex.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <net/if.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | void if_freenameindex(struct if_nameindex *idx) | ||
| 5 | { | ||
| 6 | 	free(idx); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/if_indextoname.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <net/if.h> | ||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <sys/ioctl.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include "syscall.h" | ||
| 8 | |||
| 9 | char *if_indextoname(unsigned index, char *name) | ||
| 10 | { | ||
| 11 | 	struct ifreq ifr; | ||
| 12 | 	int fd, r; | ||
| 13 | |||
| 14 | 	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; | ||
| 15 | 	ifr.ifr_ifindex = index; | ||
| 16 | 	r = ioctl(fd, SIOCGIFNAME, &ifr); | ||
| 17 | 	__syscall(SYS_close, fd); | ||
| 18 | 	if (r < 0) { | ||
| 19 | 		if (errno == ENODEV) errno = ENXIO; | ||
| 20 | 		return 0; | ||
| 21 | 	} | ||
| 22 | 	return strncpy(name, ifr.ifr_name, IF_NAMESIZE); | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/if_nameindex.c created+114| ... | @@ -0,0 +1,114 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <net/if.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <pthread.h> | ||
| 8 | #include "netlink.h" | ||
| 9 | |||
| 10 | #define IFADDRS_HASH_SIZE 64 | ||
| 11 | |||
| 12 | struct ifnamemap { | ||
| 13 | 	unsigned int hash_next; | ||
| 14 | 	unsigned int index; | ||
| 15 | 	unsigned char namelen; | ||
| 16 | 	char name[IFNAMSIZ]; | ||
| 17 | }; | ||
| 18 | |||
| 19 | struct ifnameindexctx { | ||
| 20 | 	unsigned int num, allocated, str_bytes; | ||
| 21 | 	struct ifnamemap *list; | ||
| 22 | 	unsigned int hash[IFADDRS_HASH_SIZE]; | ||
| 23 | }; | ||
| 24 | |||
| 25 | static int netlink_msg_to_nameindex(void *pctx, struct nlmsghdr *h) | ||
| 26 | { | ||
| 27 | 	struct ifnameindexctx *ctx = pctx; | ||
| 28 | 	struct ifnamemap *map; | ||
| 29 | 	struct rtattr *rta; | ||
| 30 | 	unsigned int i; | ||
| 31 | 	int index, type, namelen, bucket; | ||
| 32 | |||
| 33 | 	if (h->nlmsg_type == RTM_NEWLINK) { | ||
| 34 | 		struct ifinfomsg *ifi = NLMSG_DATA(h); | ||
| 35 | 		index = ifi->ifi_index; | ||
| 36 | 		type = IFLA_IFNAME; | ||
| 37 | 		rta = NLMSG_RTA(h, sizeof(*ifi)); | ||
| 38 | 	} else { | ||
| 39 | 		struct ifaddrmsg *ifa = NLMSG_DATA(h); | ||
| 40 | 		index = ifa->ifa_index; | ||
| 41 | 		type = IFA_LABEL; | ||
| 42 | 		rta = NLMSG_RTA(h, sizeof(*ifa)); | ||
| 43 | 	} | ||
| 44 | 	for (; NLMSG_RTAOK(rta, h); rta = RTA_NEXT(rta)) { | ||
| 45 | 		if (rta->rta_type != type) continue; | ||
| 46 | |||
| 47 | 		namelen = RTA_DATALEN(rta) - 1; | ||
| 48 | 		if (namelen > IFNAMSIZ) return 0; | ||
| 49 | |||
| 50 | 		/* suppress duplicates */ | ||
| 51 | 		bucket = index % IFADDRS_HASH_SIZE; | ||
| 52 | 		i = ctx->hash[bucket]; | ||
| 53 | 		while (i) { | ||
| 54 | 			map = &ctx->list[i-1]; | ||
| 55 | 			if (map->index == index && | ||
| 56 | 			 map->namelen == namelen && | ||
| 57 | 			 memcmp(map->name, RTA_DATA(rta), namelen) == 0) | ||
| 58 | 				return 0; | ||
| 59 | 			i = map->hash_next; | ||
| 60 | 		} | ||
| 61 | |||
| 62 | 		if (ctx->num >= ctx->allocated) { | ||
| 63 | 			size_t a = ctx->allocated ? ctx->allocated * 2 + 1 : 8; | ||
| 64 | 			if (a > SIZE_MAX/sizeof *map) return -1; | ||
| 65 | 			map = realloc(ctx->list, a * sizeof *map); | ||
| 66 | 			if (!map) return -1; | ||
| 67 | 			ctx->list = map; | ||
| 68 | 			ctx->allocated = a; | ||
| 69 | 		} | ||
| 70 | 		map = &ctx->list[ctx->num]; | ||
| 71 | 		map->index = index; | ||
| 72 | 		map->namelen = namelen; | ||
| 73 | 		memcpy(map->name, RTA_DATA(rta), namelen); | ||
| 74 | 		ctx->str_bytes += namelen + 1; | ||
| 75 | 		ctx->num++; | ||
| 76 | 		map->hash_next = ctx->hash[bucket]; | ||
| 77 | 		ctx->hash[bucket] = ctx->num; | ||
| 78 | 		return 0; | ||
| 79 | 	} | ||
| 80 | 	return 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | struct if_nameindex *if_nameindex() | ||
| 84 | { | ||
| 85 | 	struct ifnameindexctx _ctx, *ctx = &_ctx; | ||
| 86 | 	struct if_nameindex *ifs = 0, *d; | ||
| 87 | 	struct ifnamemap *s; | ||
| 88 | 	char *p; | ||
| 89 | 	int i; | ||
| 90 | 	int cs; | ||
| 91 | |||
| 92 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 93 | 	memset(ctx, 0, sizeof(*ctx)); | ||
| 94 | 	if (__rtnetlink_enumerate(AF_UNSPEC, AF_INET, netlink_msg_to_nameindex, ctx) < 0) goto err; | ||
| 95 | |||
| 96 | 	ifs = malloc(sizeof(struct if_nameindex[ctx->num+1]) + ctx->str_bytes); | ||
| 97 | 	if (!ifs) goto err; | ||
| 98 | |||
| 99 | 	p = (char*)(ifs + ctx->num + 1); | ||
| 100 | 	for (i = ctx->num, d = ifs, s = ctx->list; i; i--, s++, d++) { | ||
| 101 | 		d->if_index = s->index; | ||
| 102 | 		d->if_name = p; | ||
| 103 | 		memcpy(p, s->name, s->namelen); | ||
| 104 | 		p += s->namelen; | ||
| 105 | 		*p++ = 0; | ||
| 106 | 	} | ||
| 107 | 	d->if_index = 0; | ||
| 108 | 	d->if_name = 0; | ||
| 109 | err: | ||
| 110 | 	pthread_setcancelstate(cs, 0); | ||
| 111 | 	free(ctx->list); | ||
| 112 | 	errno = ENOBUFS; | ||
| 113 | 	return ifs; | ||
| 114 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/if_nametoindex.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <net/if.h> | ||
| 3 | #include <sys/socket.h> | ||
| 4 | #include <sys/ioctl.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | unsigned if_nametoindex(const char *name) | ||
| 9 | { | ||
| 10 | 	struct ifreq ifr; | ||
| 11 | 	int fd, r; | ||
| 12 | |||
| 13 | 	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0; | ||
| 14 | 	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name); | ||
| 15 | 	r = ioctl(fd, SIOCGIFINDEX, &ifr); | ||
| 16 | 	__syscall(SYS_close, fd); | ||
| 17 | 	return r < 0 ? 0 : ifr.ifr_ifindex; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/in6addr_any.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #include <netinet/in.h> | ||
| 2 | |||
| 3 | const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT; | ||
lib/libc/wasi/libc-top-half/musl/src/network/in6addr_loopback.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #include <netinet/in.h> | ||
| 2 | |||
| 3 | const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT; | ||
lib/libc/wasi/libc-top-half/musl/src/network/inet_addr.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <netinet/in.h> | ||
| 3 | #include <arpa/inet.h> | ||
| 4 | |||
| 5 | in_addr_t inet_addr(const char *p) | ||
| 6 | { | ||
| 7 | 	struct in_addr a; | ||
| 8 | 	if (!__inet_aton(p, &a)) return -1; | ||
| 9 | 	return a.s_addr; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/inet_aton.c created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | #include <ctype.h> | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <netinet/in.h> | ||
| 4 | #include <arpa/inet.h> | ||
| 5 | #include <stdlib.h> | ||
| 6 | |||
| 7 | int __inet_aton(const char *s0, struct in_addr *dest) | ||
| 8 | { | ||
| 9 | 	const char *s = s0; | ||
| 10 | 	unsigned char *d = (void *)dest; | ||
| 11 | 	unsigned long a[4] = { 0 }; | ||
| 12 | 	char *z; | ||
| 13 | 	int i; | ||
| 14 | |||
| 15 | 	for (i=0; i<4; i++) { | ||
| 16 | 		a[i] = strtoul(s, &z, 0); | ||
| 17 | 		if (z==s || (*z && *z != '.') || !isdigit(*s)) | ||
| 18 | 			return 0; | ||
| 19 | 		if (!*z) break; | ||
| 20 | 		s=z+1; | ||
| 21 | 	} | ||
| 22 | 	if (i==4) return 0; | ||
| 23 | 	switch (i) { | ||
| 24 | 	case 0: | ||
| 25 | 		a[1] = a[0] & 0xffffff; | ||
| 26 | 		a[0] >>= 24; | ||
| 27 | 	case 1: | ||
| 28 | 		a[2] = a[1] & 0xffff; | ||
| 29 | 		a[1] >>= 16; | ||
| 30 | 	case 2: | ||
| 31 | 		a[3] = a[2] & 0xff; | ||
| 32 | 		a[2] >>= 8; | ||
| 33 | 	} | ||
| 34 | 	for (i=0; i<4; i++) { | ||
| 35 | 		if (a[i] > 255) return 0; | ||
| 36 | 		d[i] = a[i]; | ||
| 37 | 	} | ||
| 38 | 	return 1; | ||
| 39 | } | ||
| 40 | |||
| 41 | weak_alias(__inet_aton, inet_aton); | ||
lib/libc/wasi/libc-top-half/musl/src/network/inet_legacy.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <netinet/in.h> | ||
| 3 | #include <arpa/inet.h> | ||
| 4 | |||
| 5 | in_addr_t inet_network(const char *p) | ||
| 6 | { | ||
| 7 | 	return ntohl(inet_addr(p)); | ||
| 8 | } | ||
| 9 | |||
| 10 | struct in_addr inet_makeaddr(in_addr_t n, in_addr_t h) | ||
| 11 | { | ||
| 12 | 	if (n < 256) h |= n<<24; | ||
| 13 | 	else if (n < 65536) h |= n<<16; | ||
| 14 | 	else h |= n<<8; | ||
| 15 | 	return (struct in_addr){ h }; | ||
| 16 | } | ||
| 17 | |||
| 18 | in_addr_t inet_lnaof(struct in_addr in) | ||
| 19 | { | ||
| 20 | 	uint32_t h = in.s_addr; | ||
| 21 | 	if (h>>24 < 128) return h & 0xffffff; | ||
| 22 | 	if (h>>24 < 192) return h & 0xffff; | ||
| 23 | 	return h & 0xff; | ||
| 24 | } | ||
| 25 | |||
| 26 | in_addr_t inet_netof(struct in_addr in) | ||
| 27 | { | ||
| 28 | 	uint32_t h = in.s_addr; | ||
| 29 | 	if (h>>24 < 128) return h >> 24; | ||
| 30 | 	if (h>>24 < 192) return h >> 16; | ||
| 31 | 	return h >> 8; | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/inet_ntoa.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <arpa/inet.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | char *inet_ntoa(struct in_addr in) | ||
| 5 | { | ||
| 6 | 	static char buf[16]; | ||
| 7 | 	unsigned char *a = (void *)&in; | ||
| 8 | 	snprintf(buf, sizeof buf, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]); | ||
| 9 | 	return buf; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/inet_ntop.c created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <arpa/inet.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | const char *inet_ntop(int af, const void *restrict a0, char *restrict s, socklen_t l) | ||
| 8 | { | ||
| 9 | 	const unsigned char *a = a0; | ||
| 10 | 	int i, j, max, best; | ||
| 11 | 	char buf[100]; | ||
| 12 | |||
| 13 | 	switch (af) { | ||
| 14 | 	case AF_INET: | ||
| 15 | 		if (snprintf(s, l, "%d.%d.%d.%d", a[0],a[1],a[2],a[3]) < l) | ||
| 16 | 			return s; | ||
| 17 | 		break; | ||
| 18 | 	case AF_INET6: | ||
| 19 | 		if (memcmp(a, "\0\0\0\0\0\0\0\0\0\0\377\377", 12)) | ||
| 20 | 			snprintf(buf, sizeof buf, | ||
| 21 | 				"%x:%x:%x:%x:%x:%x:%x:%x", | ||
| 22 | 				256*a[0]+a[1],256*a[2]+a[3], | ||
| 23 | 				256*a[4]+a[5],256*a[6]+a[7], | ||
| 24 | 				256*a[8]+a[9],256*a[10]+a[11], | ||
| 25 | 				256*a[12]+a[13],256*a[14]+a[15]); | ||
| 26 | 		else | ||
| 27 | 			snprintf(buf, sizeof buf, | ||
| 28 | 				"%x:%x:%x:%x:%x:%x:%d.%d.%d.%d", | ||
| 29 | 				256*a[0]+a[1],256*a[2]+a[3], | ||
| 30 | 				256*a[4]+a[5],256*a[6]+a[7], | ||
| 31 | 				256*a[8]+a[9],256*a[10]+a[11], | ||
| 32 | 				a[12],a[13],a[14],a[15]); | ||
| 33 | 		/* Replace longest /(^0|:)[:0]{2,}/ with "::" */ | ||
| 34 | 		for (i=best=0, max=2; buf[i]; i++) { | ||
| 35 | 			if (i && buf[i] != ':') continue; | ||
| 36 | 			j = strspn(buf+i, ":0"); | ||
| 37 | 			if (j>max) best=i, max=j; | ||
| 38 | 		} | ||
| 39 | 		if (max>3) { | ||
| 40 | 			buf[best] = buf[best+1] = ':'; | ||
| 41 | 			memmove(buf+best+2, buf+best+max, i-best-max+1); | ||
| 42 | 		} | ||
| 43 | 		if (strlen(buf) < l) { | ||
| 44 | 			strcpy(s, buf); | ||
| 45 | 			return s; | ||
| 46 | 		} | ||
| 47 | 		break; | ||
| 48 | 	default: | ||
| 49 | 		errno = EAFNOSUPPORT; | ||
| 50 | 		return 0; | ||
| 51 | 	} | ||
| 52 | 	errno = ENOSPC; | ||
| 53 | 	return 0; | ||
| 54 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/inet_pton.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <arpa/inet.h> | ||
| 3 | #include <ctype.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <string.h> | ||
| 6 | |||
| 7 | static int hexval(unsigned c) | ||
| 8 | { | ||
| 9 | 	if (c-'0'<10) return c-'0'; | ||
| 10 | 	c |= 32; | ||
| 11 | 	if (c-'a'<6) return c-'a'+10; | ||
| 12 | 	return -1; | ||
| 13 | } | ||
| 14 | |||
| 15 | int inet_pton(int af, const char *restrict s, void *restrict a0) | ||
| 16 | { | ||
| 17 | 	uint16_t ip[8]; | ||
| 18 | 	unsigned char *a = a0; | ||
| 19 | 	int i, j, v, d, brk=-1, need_v4=0; | ||
| 20 | |||
| 21 | 	if (af==AF_INET) { | ||
| 22 | 		for (i=0; i<4; i++) { | ||
| 23 | 			for (v=j=0; j<3 && isdigit(s[j]); j++) | ||
| 24 | 				v = 10*v + s[j]-'0'; | ||
| 25 | 			if (j==0 || (j>1 && s[0]=='0') || v>255) return 0; | ||
| 26 | 			a[i] = v; | ||
| 27 | 			if (s[j]==0 && i==3) return 1; | ||
| 28 | 			if (s[j]!='.') return 0; | ||
| 29 | 			s += j+1; | ||
| 30 | 		} | ||
| 31 | 		return 0; | ||
| 32 | 	} else if (af!=AF_INET6) { | ||
| 33 | 		errno = EAFNOSUPPORT; | ||
| 34 | 		return -1; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	if (*s==':' && *++s!=':') return 0; | ||
| 38 | |||
| 39 | 	for (i=0; ; i++) { | ||
| 40 | 		if (s[0]==':' && brk<0) { | ||
| 41 | 			brk=i; | ||
| 42 | 			ip[i&7]=0; | ||
| 43 | 			if (!*++s) break; | ||
| 44 | 			if (i==7) return 0; | ||
| 45 | 			continue; | ||
| 46 | 		} | ||
| 47 | 		for (v=j=0; j<4 && (d=hexval(s[j]))>=0; j++) | ||
| 48 | 			v=16*v+d; | ||
| 49 | 		if (j==0) return 0; | ||
| 50 | 		ip[i&7] = v; | ||
| 51 | 		if (!s[j] && (brk>=0 || i==7)) break; | ||
| 52 | 		if (i==7) return 0; | ||
| 53 | 		if (s[j]!=':') { | ||
| 54 | 			if (s[j]!='.' || (i<6 && brk<0)) return 0; | ||
| 55 | 			need_v4=1; | ||
| 56 | 			i++; | ||
| 57 | 			break; | ||
| 58 | 		} | ||
| 59 | 		s += j+1; | ||
| 60 | 	} | ||
| 61 | 	if (brk>=0) { | ||
| 62 | 		memmove(ip+brk+7-i, ip+brk, 2*(i+1-brk)); | ||
| 63 | 		for (j=0; j<7-i; j++) ip[brk+j] = 0; | ||
| 64 | 	} | ||
| 65 | 	for (j=0; j<8; j++) { | ||
| 66 | 		*a++ = ip[j]>>8; | ||
| 67 | 		*a++ = ip[j]; | ||
| 68 | 	} | ||
| 69 | 	if (need_v4 && inet_pton(AF_INET, (void *)s, a-4) <= 0) return 0; | ||
| 70 | 	return 1; | ||
| 71 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/listen.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int listen(int fd, int backlog) | ||
| 5 | { | ||
| 6 | 	return socketcall(listen, fd, backlog, 0, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/lookup.h created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #ifndef LOOKUP_H | ||
| 2 | #define LOOKUP_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | #include <stddef.h> | ||
| 6 | #include <features.h> | ||
| 7 | #include <netinet/in.h> | ||
| 8 | #include <netdb.h> | ||
| 9 | |||
| 10 | struct aibuf { | ||
| 11 | 	struct addrinfo ai; | ||
| 12 | 	union sa { | ||
| 13 | 		struct sockaddr_in sin; | ||
| 14 | 		struct sockaddr_in6 sin6; | ||
| 15 | 	} sa; | ||
| 16 | 	volatile int lock[1]; | ||
| 17 | 	short slot, ref; | ||
| 18 | }; | ||
| 19 | |||
| 20 | struct address { | ||
| 21 | 	int family; | ||
| 22 | 	unsigned scopeid; | ||
| 23 | 	uint8_t addr[16]; | ||
| 24 | 	int sortkey; | ||
| 25 | }; | ||
| 26 | |||
| 27 | struct service { | ||
| 28 | 	uint16_t port; | ||
| 29 | 	unsigned char proto, socktype; | ||
| 30 | }; | ||
| 31 | |||
| 32 | #define MAXNS 3 | ||
| 33 | |||
| 34 | struct resolvconf { | ||
| 35 | 	struct address ns[MAXNS]; | ||
| 36 | 	unsigned nns, attempts, ndots; | ||
| 37 | 	unsigned timeout; | ||
| 38 | }; | ||
| 39 | |||
| 40 | /* The limit of 48 results is a non-sharp bound on the number of addresses | ||
| 41 | * that can fit in one 512-byte DNS packet full of v4 results and a second | ||
| 42 | * packet full of v6 results. Due to headers, the actual limit is lower. */ | ||
| 43 | #define MAXADDRS 48 | ||
| 44 | #define MAXSERVS 2 | ||
| 45 | |||
| 46 | hidden int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags); | ||
| 47 | hidden int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags); | ||
| 48 | hidden int __lookup_ipliteral(struct address buf[static 1], const char *name, int family); | ||
| 49 | |||
| 50 | hidden int __get_resolv_conf(struct resolvconf *, char *, size_t); | ||
| 51 | hidden int __res_msend_rc(int, const unsigned char *const *, const int *, unsigned char *const *, int *, int, const struct resolvconf *); | ||
| 52 | |||
| 53 | hidden int __dns_parse(const unsigned char *, int, int (*)(void *, int, const void *, int, const void *), void *); | ||
| 54 | |||
| 55 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/network/lookup_ipliteral.c created+55| ... | @@ -0,0 +1,55 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <netinet/in.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | #include <net/if.h> | ||
| 5 | #include <arpa/inet.h> | ||
| 6 | #include <limits.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <ctype.h> | ||
| 10 | #include "lookup.h" | ||
| 11 | |||
| 12 | int __lookup_ipliteral(struct address buf[static 1], const char *name, int family) | ||
| 13 | { | ||
| 14 | 	struct in_addr a4; | ||
| 15 | 	struct in6_addr a6; | ||
| 16 | 	if (__inet_aton(name, &a4) > 0) { | ||
| 17 | 		if (family == AF_INET6) /* wrong family */ | ||
| 18 | 			return EAI_NONAME; | ||
| 19 | 		memcpy(&buf[0].addr, &a4, sizeof a4); | ||
| 20 | 		buf[0].family = AF_INET; | ||
| 21 | 		buf[0].scopeid = 0; | ||
| 22 | 		return 1; | ||
| 23 | 	} | ||
| 24 | |||
| 25 | 	char tmp[64]; | ||
| 26 | 	char *p = strchr(name, '%'), *z; | ||
| 27 | 	unsigned long long scopeid = 0; | ||
| 28 | 	if (p && p-name < 64) { | ||
| 29 | 		memcpy(tmp, name, p-name); | ||
| 30 | 		tmp[p-name] = 0; | ||
| 31 | 		name = tmp; | ||
| 32 | 	} | ||
| 33 | |||
| 34 | 	if (inet_pton(AF_INET6, name, &a6) <= 0) | ||
| 35 | 		return 0; | ||
| 36 | 	if (family == AF_INET) /* wrong family */ | ||
| 37 | 		return EAI_NONAME; | ||
| 38 | |||
| 39 | 	memcpy(&buf[0].addr, &a6, sizeof a6); | ||
| 40 | 	buf[0].family = AF_INET6; | ||
| 41 | 	if (p) { | ||
| 42 | 		if (isdigit(*++p)) scopeid = strtoull(p, &z, 10); | ||
| 43 | 		else z = p-1; | ||
| 44 | 		if (*z) { | ||
| 45 | 			if (!IN6_IS_ADDR_LINKLOCAL(&a6) && | ||
| 46 | 			 !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) | ||
| 47 | 				return EAI_NONAME; | ||
| 48 | 			scopeid = if_nametoindex(p); | ||
| 49 | 			if (!scopeid) return EAI_NONAME; | ||
| 50 | 		} | ||
| 51 | 		if (scopeid > UINT_MAX) return EAI_NONAME; | ||
| 52 | 	} | ||
| 53 | 	buf[0].scopeid = scopeid; | ||
| 54 | 	return 1; | ||
| 55 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/lookup_name.c created+425| ... | @@ -0,0 +1,425 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <netinet/in.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | #include <net/if.h> | ||
| 5 | #include <arpa/inet.h> | ||
| 6 | #include <ctype.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <fcntl.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <pthread.h> | ||
| 12 | #include <errno.h> | ||
| 13 | #include <resolv.h> | ||
| 14 | #include "lookup.h" | ||
| 15 | #include "stdio_impl.h" | ||
| 16 | #include "syscall.h" | ||
| 17 | |||
| 18 | static int is_valid_hostname(const char *host) | ||
| 19 | { | ||
| 20 | 	const unsigned char *s; | ||
| 21 | 	if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0; | ||
| 22 | 	for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++); | ||
| 23 | 	return !*s; | ||
| 24 | } | ||
| 25 | |||
| 26 | static int name_from_null(struct address buf[static 2], const char *name, int family, int flags) | ||
| 27 | { | ||
| 28 | 	int cnt = 0; | ||
| 29 | 	if (name) return 0; | ||
| 30 | 	if (flags & AI_PASSIVE) { | ||
| 31 | 		if (family != AF_INET6) | ||
| 32 | 			buf[cnt++] = (struct address){ .family = AF_INET }; | ||
| 33 | 		if (family != AF_INET) | ||
| 34 | 			buf[cnt++] = (struct address){ .family = AF_INET6 }; | ||
| 35 | 	} else { | ||
| 36 | 		if (family != AF_INET6) | ||
| 37 | 			buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } }; | ||
| 38 | 		if (family != AF_INET) | ||
| 39 | 			buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } }; | ||
| 40 | 	} | ||
| 41 | 	return cnt; | ||
| 42 | } | ||
| 43 | |||
| 44 | static int name_from_numeric(struct address buf[static 1], const char *name, int family) | ||
| 45 | { | ||
| 46 | 	return __lookup_ipliteral(buf, name, family); | ||
| 47 | } | ||
| 48 | |||
| 49 | static int name_from_hosts(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) | ||
| 50 | { | ||
| 51 | 	char line[512]; | ||
| 52 | 	size_t l = strlen(name); | ||
| 53 | 	int cnt = 0, badfam = 0, have_canon = 0; | ||
| 54 | 	unsigned char _buf[1032]; | ||
| 55 | 	FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); | ||
| 56 | 	if (!f) switch (errno) { | ||
| 57 | 	case ENOENT: | ||
| 58 | 	case ENOTDIR: | ||
| 59 | 	case EACCES: | ||
| 60 | 		return 0; | ||
| 61 | 	default: | ||
| 62 | 		return EAI_SYSTEM; | ||
| 63 | 	} | ||
| 64 | 	while (fgets(line, sizeof line, f) && cnt < MAXADDRS) { | ||
| 65 | 		char *p, *z; | ||
| 66 | |||
| 67 | 		if ((p=strchr(line, '#'))) *p++='\n', *p=0; | ||
| 68 | 		for(p=line+1; (p=strstr(p, name)) && | ||
| 69 | 			(!isspace(p[-1]) || !isspace(p[l])); p++); | ||
| 70 | 		if (!p) continue; | ||
| 71 | |||
| 72 | 		/* Isolate IP address to parse */ | ||
| 73 | 		for (p=line; *p && !isspace(*p); p++); | ||
| 74 | 		*p++ = 0; | ||
| 75 | 		switch (name_from_numeric(buf+cnt, line, family)) { | ||
| 76 | 		case 1: | ||
| 77 | 			cnt++; | ||
| 78 | 			break; | ||
| 79 | 		case 0: | ||
| 80 | 			continue; | ||
| 81 | 		default: | ||
| 82 | 			badfam = EAI_NONAME; | ||
| 83 | 			break; | ||
| 84 | 		} | ||
| 85 | |||
| 86 | 		if (have_canon) continue; | ||
| 87 | |||
| 88 | 		/* Extract first name as canonical name */ | ||
| 89 | 		for (; *p && isspace(*p); p++); | ||
| 90 | 		for (z=p; *z && !isspace(*z); z++); | ||
| 91 | 		*z = 0; | ||
| 92 | 		if (is_valid_hostname(p)) { | ||
| 93 | 			have_canon = 1; | ||
| 94 | 			memcpy(canon, p, z-p+1); | ||
| 95 | 		} | ||
| 96 | 	} | ||
| 97 | 	__fclose_ca(f); | ||
| 98 | 	return cnt ? cnt : badfam; | ||
| 99 | } | ||
| 100 | |||
| 101 | struct dpc_ctx { | ||
| 102 | 	struct address *addrs; | ||
| 103 | 	char *canon; | ||
| 104 | 	int cnt; | ||
| 105 | }; | ||
| 106 | |||
| 107 | #define RR_A 1 | ||
| 108 | #define RR_CNAME 5 | ||
| 109 | #define RR_AAAA 28 | ||
| 110 | |||
| 111 | static int dns_parse_callback(void *c, int rr, const void *data, int len, const void *packet) | ||
| 112 | { | ||
| 113 | 	char tmp[256]; | ||
| 114 | 	struct dpc_ctx *ctx = c; | ||
| 115 | 	if (ctx->cnt >= MAXADDRS) return -1; | ||
| 116 | 	switch (rr) { | ||
| 117 | 	case RR_A: | ||
| 118 | 		if (len != 4) return -1; | ||
| 119 | 		ctx->addrs[ctx->cnt].family = AF_INET; | ||
| 120 | 		ctx->addrs[ctx->cnt].scopeid = 0; | ||
| 121 | 		memcpy(ctx->addrs[ctx->cnt++].addr, data, 4); | ||
| 122 | 		break; | ||
| 123 | 	case RR_AAAA: | ||
| 124 | 		if (len != 16) return -1; | ||
| 125 | 		ctx->addrs[ctx->cnt].family = AF_INET6; | ||
| 126 | 		ctx->addrs[ctx->cnt].scopeid = 0; | ||
| 127 | 		memcpy(ctx->addrs[ctx->cnt++].addr, data, 16); | ||
| 128 | 		break; | ||
| 129 | 	case RR_CNAME: | ||
| 130 | 		if (__dn_expand(packet, (const unsigned char *)packet + 512, | ||
| 131 | 		 data, tmp, sizeof tmp) > 0 && is_valid_hostname(tmp)) | ||
| 132 | 			strcpy(ctx->canon, tmp); | ||
| 133 | 		break; | ||
| 134 | 	} | ||
| 135 | 	return 0; | ||
| 136 | } | ||
| 137 | |||
| 138 | static int name_from_dns(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, const struct resolvconf *conf) | ||
| 139 | { | ||
| 140 | 	unsigned char qbuf[2][280], abuf[2][512]; | ||
| 141 | 	const unsigned char *qp[2] = { qbuf[0], qbuf[1] }; | ||
| 142 | 	unsigned char *ap[2] = { abuf[0], abuf[1] }; | ||
| 143 | 	int qlens[2], alens[2]; | ||
| 144 | 	int i, nq = 0; | ||
| 145 | 	struct dpc_ctx ctx = { .addrs = buf, .canon = canon }; | ||
| 146 | 	static const struct { int af; int rr; } afrr[2] = { | ||
| 147 | 		{ .af = AF_INET6, .rr = RR_A }, | ||
| 148 | 		{ .af = AF_INET, .rr = RR_AAAA }, | ||
| 149 | 	}; | ||
| 150 | |||
| 151 | 	for (i=0; i<2; i++) { | ||
| 152 | 		if (family != afrr[i].af) { | ||
| 153 | 			qlens[nq] = __res_mkquery(0, name, 1, afrr[i].rr, | ||
| 154 | 				0, 0, 0, qbuf[nq], sizeof *qbuf); | ||
| 155 | 			if (qlens[nq] == -1) | ||
| 156 | 				return EAI_NONAME; | ||
| 157 | 			qbuf[nq][3] = 0; /* don't need AD flag */ | ||
| 158 | 			nq++; | ||
| 159 | 		} | ||
| 160 | 	} | ||
| 161 | |||
| 162 | 	if (__res_msend_rc(nq, qp, qlens, ap, alens, sizeof *abuf, conf) < 0) | ||
| 163 | 		return EAI_SYSTEM; | ||
| 164 | |||
| 165 | 	for (i=0; i<nq; i++) { | ||
| 166 | 		if (alens[i] < 4 || (abuf[i][3] & 15) == 2) return EAI_AGAIN; | ||
| 167 | 		if ((abuf[i][3] & 15) == 3) return 0; | ||
| 168 | 		if ((abuf[i][3] & 15) != 0) return EAI_FAIL; | ||
| 169 | 	} | ||
| 170 | |||
| 171 | 	for (i=0; i<nq; i++) | ||
| 172 | 		__dns_parse(abuf[i], alens[i], dns_parse_callback, &ctx); | ||
| 173 | |||
| 174 | 	if (ctx.cnt) return ctx.cnt; | ||
| 175 | 	return EAI_NONAME; | ||
| 176 | } | ||
| 177 | |||
| 178 | static int name_from_dns_search(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family) | ||
| 179 | { | ||
| 180 | 	char search[256]; | ||
| 181 | 	struct resolvconf conf; | ||
| 182 | 	size_t l, dots; | ||
| 183 | 	char *p, *z; | ||
| 184 | |||
| 185 | 	if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1; | ||
| 186 | |||
| 187 | 	/* Count dots, suppress search when >=ndots or name ends in | ||
| 188 | 	 * a dot, which is an explicit request for global scope. */ | ||
| 189 | 	for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++; | ||
| 190 | 	if (dots >= conf.ndots || name[l-1]=='.') *search = 0; | ||
| 191 | |||
| 192 | 	/* Strip final dot for canon, fail if multiple trailing dots. */ | ||
| 193 | 	if (name[l-1]=='.') l--; | ||
| 194 | 	if (!l || name[l-1]=='.') return EAI_NONAME; | ||
| 195 | |||
| 196 | 	/* This can never happen; the caller already checked length. */ | ||
| 197 | 	if (l >= 256) return EAI_NONAME; | ||
| 198 | |||
| 199 | 	/* Name with search domain appended is setup in canon[]. This both | ||
| 200 | 	 * provides the desired default canonical name (if the requested | ||
| 201 | 	 * name is not a CNAME record) and serves as a buffer for passing | ||
| 202 | 	 * the full requested name to name_from_dns. */ | ||
| 203 | 	memcpy(canon, name, l); | ||
| 204 | 	canon[l] = '.'; | ||
| 205 | |||
| 206 | 	for (p=search; *p; p=z) { | ||
| 207 | 		for (; isspace(*p); p++); | ||
| 208 | 		for (z=p; *z && !isspace(*z); z++); | ||
| 209 | 		if (z==p) break; | ||
| 210 | 		if (z-p < 256 - l - 1) { | ||
| 211 | 			memcpy(canon+l+1, p, z-p); | ||
| 212 | 			canon[z-p+1+l] = 0; | ||
| 213 | 			int cnt = name_from_dns(buf, canon, canon, family, &conf); | ||
| 214 | 			if (cnt) return cnt; | ||
| 215 | 		} | ||
| 216 | 	} | ||
| 217 | |||
| 218 | 	canon[l] = 0; | ||
| 219 | 	return name_from_dns(buf, canon, name, family, &conf); | ||
| 220 | } | ||
| 221 | |||
| 222 | static const struct policy { | ||
| 223 | 	unsigned char addr[16]; | ||
| 224 | 	unsigned char len, mask; | ||
| 225 | 	unsigned char prec, label; | ||
| 226 | } defpolicy[] = { | ||
| 227 | 	{ "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\1", 15, 0xff, 50, 0 }, | ||
| 228 | 	{ "\0\0\0\0\0\0\0\0\0\0\xff\xff", 11, 0xff, 35, 4 }, | ||
| 229 | 	{ "\x20\2", 1, 0xff, 30, 2 }, | ||
| 230 | 	{ "\x20\1", 3, 0xff, 5, 5 }, | ||
| 231 | 	{ "\xfc", 0, 0xfe, 3, 13 }, | ||
| 232 | #if 0 | ||
| 233 | 	/* These are deprecated and/or returned to the address | ||
| 234 | 	 * pool, so despite the RFC, treating them as special | ||
| 235 | 	 * is probably wrong. */ | ||
| 236 | 	{ "", 11, 0xff, 1, 3 }, | ||
| 237 | 	{ "\xfe\xc0", 1, 0xc0, 1, 11 }, | ||
| 238 | 	{ "\x3f\xfe", 1, 0xff, 1, 12 }, | ||
| 239 | #endif | ||
| 240 | 	/* Last rule must match all addresses to stop loop. */ | ||
| 241 | 	{ "", 0, 0, 40, 1 }, | ||
| 242 | }; | ||
| 243 | |||
| 244 | static const struct policy *policyof(const struct in6_addr *a) | ||
| 245 | { | ||
| 246 | 	int i; | ||
| 247 | 	for (i=0; ; i++) { | ||
| 248 | 		if (memcmp(a->s6_addr, defpolicy[i].addr, defpolicy[i].len)) | ||
| 249 | 			continue; | ||
| 250 | 		if ((a->s6_addr[defpolicy[i].len] & defpolicy[i].mask) | ||
| 251 | 		 != defpolicy[i].addr[defpolicy[i].len]) | ||
| 252 | 			continue; | ||
| 253 | 		return defpolicy+i; | ||
| 254 | 	} | ||
| 255 | } | ||
| 256 | |||
| 257 | static int labelof(const struct in6_addr *a) | ||
| 258 | { | ||
| 259 | 	return policyof(a)->label; | ||
| 260 | } | ||
| 261 | |||
| 262 | static int scopeof(const struct in6_addr *a) | ||
| 263 | { | ||
| 264 | 	if (IN6_IS_ADDR_MULTICAST(a)) return a->s6_addr[1] & 15; | ||
| 265 | 	if (IN6_IS_ADDR_LINKLOCAL(a)) return 2; | ||
| 266 | 	if (IN6_IS_ADDR_LOOPBACK(a)) return 2; | ||
| 267 | 	if (IN6_IS_ADDR_SITELOCAL(a)) return 5; | ||
| 268 | 	return 14; | ||
| 269 | } | ||
| 270 | |||
| 271 | static int prefixmatch(const struct in6_addr *s, const struct in6_addr *d) | ||
| 272 | { | ||
| 273 | 	/* FIXME: The common prefix length should be limited to no greater | ||
| 274 | 	 * than the nominal length of the prefix portion of the source | ||
| 275 | 	 * address. However the definition of the source prefix length is | ||
| 276 | 	 * not clear and thus this limiting is not yet implemented. */ | ||
| 277 | 	unsigned i; | ||
| 278 | 	for (i=0; i<128 && !((s->s6_addr[i/8]^d->s6_addr[i/8])&(128>>(i%8))); i++); | ||
| 279 | 	return i; | ||
| 280 | } | ||
| 281 | |||
| 282 | #define DAS_USABLE 0x40000000 | ||
| 283 | #define DAS_MATCHINGSCOPE 0x20000000 | ||
| 284 | #define DAS_MATCHINGLABEL 0x10000000 | ||
| 285 | #define DAS_PREC_SHIFT 20 | ||
| 286 | #define DAS_SCOPE_SHIFT 16 | ||
| 287 | #define DAS_PREFIX_SHIFT 8 | ||
| 288 | #define DAS_ORDER_SHIFT 0 | ||
| 289 | |||
| 290 | static int addrcmp(const void *_a, const void *_b) | ||
| 291 | { | ||
| 292 | 	const struct address *a = _a, *b = _b; | ||
| 293 | 	return b->sortkey - a->sortkey; | ||
| 294 | } | ||
| 295 | |||
| 296 | int __lookup_name(struct address buf[static MAXADDRS], char canon[static 256], const char *name, int family, int flags) | ||
| 297 | { | ||
| 298 | 	int cnt = 0, i, j; | ||
| 299 | |||
| 300 | 	*canon = 0; | ||
| 301 | 	if (name) { | ||
| 302 | 		/* reject empty name and check len so it fits into temp bufs */ | ||
| 303 | 		size_t l = strnlen(name, 255); | ||
| 304 | 		if (l-1 >= 254) | ||
| 305 | 			return EAI_NONAME; | ||
| 306 | 		memcpy(canon, name, l+1); | ||
| 307 | 	} | ||
| 308 | |||
| 309 | 	/* Procedurally, a request for v6 addresses with the v4-mapped | ||
| 310 | 	 * flag set is like a request for unspecified family, followed | ||
| 311 | 	 * by filtering of the results. */ | ||
| 312 | 	if (flags & AI_V4MAPPED) { | ||
| 313 | 		if (family == AF_INET6) family = AF_UNSPEC; | ||
| 314 | 		else flags -= AI_V4MAPPED; | ||
| 315 | 	} | ||
| 316 | |||
| 317 | 	/* Try each backend until there's at least one result. */ | ||
| 318 | 	cnt = name_from_null(buf, name, family, flags); | ||
| 319 | 	if (!cnt) cnt = name_from_numeric(buf, name, family); | ||
| 320 | 	if (!cnt && !(flags & AI_NUMERICHOST)) { | ||
| 321 | 		cnt = name_from_hosts(buf, canon, name, family); | ||
| 322 | 		if (!cnt) cnt = name_from_dns_search(buf, canon, name, family); | ||
| 323 | 	} | ||
| 324 | 	if (cnt<=0) return cnt ? cnt : EAI_NONAME; | ||
| 325 | |||
| 326 | 	/* Filter/transform results for v4-mapped lookup, if requested. */ | ||
| 327 | 	if (flags & AI_V4MAPPED) { | ||
| 328 | 		if (!(flags & AI_ALL)) { | ||
| 329 | 			/* If any v6 results exist, remove v4 results. */ | ||
| 330 | 			for (i=0; i<cnt && buf[i].family != AF_INET6; i++); | ||
| 331 | 			if (i<cnt) { | ||
| 332 | 				for (j=0; i<cnt; i++) { | ||
| 333 | 					if (buf[i].family == AF_INET6) | ||
| 334 | 						buf[j++] = buf[i]; | ||
| 335 | 				} | ||
| 336 | 				cnt = i = j; | ||
| 337 | 			} | ||
| 338 | 		} | ||
| 339 | 		/* Translate any remaining v4 results to v6 */ | ||
| 340 | 		for (i=0; i<cnt; i++) { | ||
| 341 | 			if (buf[i].family != AF_INET) continue; | ||
| 342 | 			memcpy(buf[i].addr+12, buf[i].addr, 4); | ||
| 343 | 			memcpy(buf[i].addr, "\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); | ||
| 344 | 			buf[i].family = AF_INET6; | ||
| 345 | 		} | ||
| 346 | 	} | ||
| 347 | |||
| 348 | 	/* No further processing is needed if there are fewer than 2 | ||
| 349 | 	 * results or if there are only IPv4 results. */ | ||
| 350 | 	if (cnt<2 || family==AF_INET) return cnt; | ||
| 351 | 	for (i=0; i<cnt; i++) if (buf[i].family != AF_INET) break; | ||
| 352 | 	if (i==cnt) return cnt; | ||
| 353 | |||
| 354 | 	int cs; | ||
| 355 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 356 | |||
| 357 | 	/* The following implements a subset of RFC 3484/6724 destination | ||
| 358 | 	 * address selection by generating a single 31-bit sort key for | ||
| 359 | 	 * each address. Rules 3, 4, and 7 are omitted for having | ||
| 360 | 	 * excessive runtime and code size cost and dubious benefit. | ||
| 361 | 	 * So far the label/precedence table cannot be customized. */ | ||
| 362 | 	for (i=0; i<cnt; i++) { | ||
| 363 | 		int family = buf[i].family; | ||
| 364 | 		int key = 0; | ||
| 365 | 		struct sockaddr_in6 sa6 = { 0 }, da6 = { | ||
| 366 | 			.sin6_family = AF_INET6, | ||
| 367 | 			.sin6_scope_id = buf[i].scopeid, | ||
| 368 | 			.sin6_port = 65535 | ||
| 369 | 		}; | ||
| 370 | 		struct sockaddr_in sa4 = { 0 }, da4 = { | ||
| 371 | 			.sin_family = AF_INET, | ||
| 372 | 			.sin_port = 65535 | ||
| 373 | 		}; | ||
| 374 | 		void *sa, *da; | ||
| 375 | 		socklen_t salen, dalen; | ||
| 376 | 		if (family == AF_INET6) { | ||
| 377 | 			memcpy(da6.sin6_addr.s6_addr, buf[i].addr, 16); | ||
| 378 | 			da = &da6; dalen = sizeof da6; | ||
| 379 | 			sa = &sa6; salen = sizeof sa6; | ||
| 380 | 		} else { | ||
| 381 | 			memcpy(sa6.sin6_addr.s6_addr, | ||
| 382 | 				"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); | ||
| 383 | 			memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4); | ||
| 384 | 			memcpy(da6.sin6_addr.s6_addr, | ||
| 385 | 				"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); | ||
| 386 | 			memcpy(da6.sin6_addr.s6_addr+12, buf[i].addr, 4); | ||
| 387 | 			memcpy(&da4.sin_addr, buf[i].addr, 4); | ||
| 388 | 			da = &da4; dalen = sizeof da4; | ||
| 389 | 			sa = &sa4; salen = sizeof sa4; | ||
| 390 | 		} | ||
| 391 | 		const struct policy *dpolicy = policyof(&da6.sin6_addr); | ||
| 392 | 		int dscope = scopeof(&da6.sin6_addr); | ||
| 393 | 		int dlabel = dpolicy->label; | ||
| 394 | 		int dprec = dpolicy->prec; | ||
| 395 | 		int prefixlen = 0; | ||
| 396 | 		int fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_UDP); | ||
| 397 | 		if (fd >= 0) { | ||
| 398 | 			if (!connect(fd, da, dalen)) { | ||
| 399 | 				key |= DAS_USABLE; | ||
| 400 | 				if (!getsockname(fd, sa, &salen)) { | ||
| 401 | 					if (family == AF_INET) memcpy( | ||
| 402 | 						sa6.sin6_addr.s6_addr+12, | ||
| 403 | 						&sa4.sin_addr, 4); | ||
| 404 | 					if (dscope == scopeof(&sa6.sin6_addr)) | ||
| 405 | 						key |= DAS_MATCHINGSCOPE; | ||
| 406 | 					if (dlabel == labelof(&sa6.sin6_addr)) | ||
| 407 | 						key |= DAS_MATCHINGLABEL; | ||
| 408 | 					prefixlen = prefixmatch(&sa6.sin6_addr, | ||
| 409 | 						&da6.sin6_addr); | ||
| 410 | 				} | ||
| 411 | 			} | ||
| 412 | 			close(fd); | ||
| 413 | 		} | ||
| 414 | 		key |= dprec << DAS_PREC_SHIFT; | ||
| 415 | 		key |= (15-dscope) << DAS_SCOPE_SHIFT; | ||
| 416 | 		key |= prefixlen << DAS_PREFIX_SHIFT; | ||
| 417 | 		key |= (MAXADDRS-i) << DAS_ORDER_SHIFT; | ||
| 418 | 		buf[i].sortkey = key; | ||
| 419 | 	} | ||
| 420 | 	qsort(buf, cnt, sizeof *buf, addrcmp); | ||
| 421 | |||
| 422 | 	pthread_setcancelstate(cs, 0); | ||
| 423 | |||
| 424 | 	return cnt; | ||
| 425 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/lookup_serv.c created+114| ... | @@ -0,0 +1,114 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <netinet/in.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | #include <ctype.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <fcntl.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include "lookup.h" | ||
| 10 | #include "stdio_impl.h" | ||
| 11 | |||
| 12 | int __lookup_serv(struct service buf[static MAXSERVS], const char *name, int proto, int socktype, int flags) | ||
| 13 | { | ||
| 14 | 	char line[128]; | ||
| 15 | 	int cnt = 0; | ||
| 16 | 	char *p, *z = ""; | ||
| 17 | 	unsigned long port = 0; | ||
| 18 | |||
| 19 | 	switch (socktype) { | ||
| 20 | 	case SOCK_STREAM: | ||
| 21 | 		switch (proto) { | ||
| 22 | 		case 0: | ||
| 23 | 			proto = IPPROTO_TCP; | ||
| 24 | 		case IPPROTO_TCP: | ||
| 25 | 			break; | ||
| 26 | 		default: | ||
| 27 | 			return EAI_SERVICE; | ||
| 28 | 		} | ||
| 29 | 		break; | ||
| 30 | 	case SOCK_DGRAM: | ||
| 31 | 		switch (proto) { | ||
| 32 | 		case 0: | ||
| 33 | 			proto = IPPROTO_UDP; | ||
| 34 | 		case IPPROTO_UDP: | ||
| 35 | 			break; | ||
| 36 | 		default: | ||
| 37 | 			return EAI_SERVICE; | ||
| 38 | 		} | ||
| 39 | 	case 0: | ||
| 40 | 		break; | ||
| 41 | 	default: | ||
| 42 | 		if (name) return EAI_SERVICE; | ||
| 43 | 		buf[0].port = 0; | ||
| 44 | 		buf[0].proto = proto; | ||
| 45 | 		buf[0].socktype = socktype; | ||
| 46 | 		return 1; | ||
| 47 | 	} | ||
| 48 | |||
| 49 | 	if (name) { | ||
| 50 | 		if (!*name) return EAI_SERVICE; | ||
| 51 | 		port = strtoul(name, &z, 10); | ||
| 52 | 	} | ||
| 53 | 	if (!*z) { | ||
| 54 | 		if (port > 65535) return EAI_SERVICE; | ||
| 55 | 		if (proto != IPPROTO_UDP) { | ||
| 56 | 			buf[cnt].port = port; | ||
| 57 | 			buf[cnt].socktype = SOCK_STREAM; | ||
| 58 | 			buf[cnt++].proto = IPPROTO_TCP; | ||
| 59 | 		} | ||
| 60 | 		if (proto != IPPROTO_TCP) { | ||
| 61 | 			buf[cnt].port = port; | ||
| 62 | 			buf[cnt].socktype = SOCK_DGRAM; | ||
| 63 | 			buf[cnt++].proto = IPPROTO_UDP; | ||
| 64 | 		} | ||
| 65 | 		return cnt; | ||
| 66 | 	} | ||
| 67 | |||
| 68 | 	if (flags & AI_NUMERICSERV) return EAI_NONAME; | ||
| 69 | |||
| 70 | 	size_t l = strlen(name); | ||
| 71 | |||
| 72 | 	unsigned char _buf[1032]; | ||
| 73 | 	FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); | ||
| 74 | 	if (!f) switch (errno) { | ||
| 75 | 	case ENOENT: | ||
| 76 | 	case ENOTDIR: | ||
| 77 | 	case EACCES: | ||
| 78 | 		return EAI_SERVICE; | ||
| 79 | 	default: | ||
| 80 | 		return EAI_SYSTEM; | ||
| 81 | 	} | ||
| 82 | |||
| 83 | 	while (fgets(line, sizeof line, f) && cnt < MAXSERVS) { | ||
| 84 | 		if ((p=strchr(line, '#'))) *p++='\n', *p=0; | ||
| 85 | |||
| 86 | 		/* Find service name */ | ||
| 87 | 		for(p=line; (p=strstr(p, name)); p++) { | ||
| 88 | 			if (p>line && !isspace(p[-1])) continue; | ||
| 89 | 			if (p[l] && !isspace(p[l])) continue; | ||
| 90 | 			break; | ||
| 91 | 		} | ||
| 92 | 		if (!p) continue; | ||
| 93 | |||
| 94 | 		/* Skip past canonical name at beginning of line */ | ||
| 95 | 		for (p=line; *p && !isspace(*p); p++); | ||
| 96 | |||
| 97 | 		port = strtoul(p, &z, 10); | ||
| 98 | 		if (port > 65535 || z==p) continue; | ||
| 99 | 		if (!strncmp(z, "/udp", 4)) { | ||
| 100 | 			if (proto == IPPROTO_TCP) continue; | ||
| 101 | 			buf[cnt].port = port; | ||
| 102 | 			buf[cnt].socktype = SOCK_DGRAM; | ||
| 103 | 			buf[cnt++].proto = IPPROTO_UDP; | ||
| 104 | 		} | ||
| 105 | 		if (!strncmp(z, "/tcp", 4)) { | ||
| 106 | 			if (proto == IPPROTO_UDP) continue; | ||
| 107 | 			buf[cnt].port = port; | ||
| 108 | 			buf[cnt].socktype = SOCK_STREAM; | ||
| 109 | 			buf[cnt++].proto = IPPROTO_TCP; | ||
| 110 | 		} | ||
| 111 | 	} | ||
| 112 | 	__fclose_ca(f); | ||
| 113 | 	return cnt > 0 ? cnt : EAI_SERVICE; | ||
| 114 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/netlink.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <syscall.h> | ||
| 4 | #include <sys/socket.h> | ||
| 5 | #include "netlink.h" | ||
| 6 | |||
| 7 | static int __netlink_enumerate(int fd, unsigned int seq, int type, int af, | ||
| 8 | 	int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx) | ||
| 9 | { | ||
| 10 | 	struct nlmsghdr *h; | ||
| 11 | 	union { | ||
| 12 | 		uint8_t buf[8192]; | ||
| 13 | 		struct { | ||
| 14 | 			struct nlmsghdr nlh; | ||
| 15 | 			struct rtgenmsg g; | ||
| 16 | 		} req; | ||
| 17 | 		struct nlmsghdr reply; | ||
| 18 | 	} u; | ||
| 19 | 	int r, ret; | ||
| 20 | |||
| 21 | 	memset(&u.req, 0, sizeof(u.req)); | ||
| 22 | 	u.req.nlh.nlmsg_len = sizeof(u.req); | ||
| 23 | 	u.req.nlh.nlmsg_type = type; | ||
| 24 | 	u.req.nlh.nlmsg_flags = NLM_F_DUMP | NLM_F_REQUEST; | ||
| 25 | 	u.req.nlh.nlmsg_seq = seq; | ||
| 26 | 	u.req.g.rtgen_family = af; | ||
| 27 | 	r = send(fd, &u.req, sizeof(u.req), 0); | ||
| 28 | 	if (r < 0) return r; | ||
| 29 | |||
| 30 | 	while (1) { | ||
| 31 | 		r = recv(fd, u.buf, sizeof(u.buf), MSG_DONTWAIT); | ||
| 32 | 		if (r <= 0) return -1; | ||
| 33 | 		for (h = &u.reply; NLMSG_OK(h, (void*)&u.buf[r]); h = NLMSG_NEXT(h)) { | ||
| 34 | 			if (h->nlmsg_type == NLMSG_DONE) return 0; | ||
| 35 | 			if (h->nlmsg_type == NLMSG_ERROR) return -1; | ||
| 36 | 			ret = cb(ctx, h); | ||
| 37 | 			if (ret) return ret; | ||
| 38 | 		} | ||
| 39 | 	} | ||
| 40 | } | ||
| 41 | |||
| 42 | int __rtnetlink_enumerate(int link_af, int addr_af, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx) | ||
| 43 | { | ||
| 44 | 	int fd, r; | ||
| 45 | |||
| 46 | 	fd = socket(PF_NETLINK, SOCK_RAW|SOCK_CLOEXEC, NETLINK_ROUTE); | ||
| 47 | 	if (fd < 0) return -1; | ||
| 48 | 	r = __netlink_enumerate(fd, 1, RTM_GETLINK, link_af, cb, ctx); | ||
| 49 | 	if (!r) r = __netlink_enumerate(fd, 2, RTM_GETADDR, addr_af, cb, ctx); | ||
| 50 | 	__syscall(SYS_close,fd); | ||
| 51 | 	return r; | ||
| 52 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/netlink.h created+94| ... | @@ -0,0 +1,94 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | |||
| 3 | /* linux/netlink.h */ | ||
| 4 | |||
| 5 | #define NETLINK_ROUTE 0 | ||
| 6 | |||
| 7 | struct nlmsghdr { | ||
| 8 | 	uint32_t	nlmsg_len; | ||
| 9 | 	uint16_t	nlmsg_type; | ||
| 10 | 	uint16_t	nlmsg_flags; | ||
| 11 | 	uint32_t	nlmsg_seq; | ||
| 12 | 	uint32_t	nlmsg_pid; | ||
| 13 | }; | ||
| 14 | |||
| 15 | #define NLM_F_REQUEST	1 | ||
| 16 | #define NLM_F_MULTI	2 | ||
| 17 | #define NLM_F_ACK	4 | ||
| 18 | |||
| 19 | #define NLM_F_ROOT	0x100 | ||
| 20 | #define NLM_F_MATCH	0x200 | ||
| 21 | #define NLM_F_ATOMIC	0x400 | ||
| 22 | #define NLM_F_DUMP	(NLM_F_ROOT|NLM_F_MATCH) | ||
| 23 | |||
| 24 | #define NLMSG_NOOP	0x1 | ||
| 25 | #define NLMSG_ERROR	0x2 | ||
| 26 | #define NLMSG_DONE	0x3 | ||
| 27 | #define NLMSG_OVERRUN	0x4 | ||
| 28 | |||
| 29 | /* linux/rtnetlink.h */ | ||
| 30 | |||
| 31 | #define RTM_NEWLINK	16 | ||
| 32 | #define RTM_GETLINK	18 | ||
| 33 | #define RTM_NEWADDR	20 | ||
| 34 | #define RTM_GETADDR	22 | ||
| 35 | |||
| 36 | struct rtattr { | ||
| 37 | 	unsigned short	rta_len; | ||
| 38 | 	unsigned short	rta_type; | ||
| 39 | }; | ||
| 40 | |||
| 41 | struct rtgenmsg { | ||
| 42 | 	unsigned char	rtgen_family; | ||
| 43 | }; | ||
| 44 | |||
| 45 | struct ifinfomsg { | ||
| 46 | 	unsigned char	ifi_family; | ||
| 47 | 	unsigned char	__ifi_pad; | ||
| 48 | 	unsigned short	ifi_type; | ||
| 49 | 	int		ifi_index; | ||
| 50 | 	unsigned	ifi_flags; | ||
| 51 | 	unsigned	ifi_change; | ||
| 52 | }; | ||
| 53 | |||
| 54 | /* linux/if_link.h */ | ||
| 55 | |||
| 56 | #define IFLA_ADDRESS	1 | ||
| 57 | #define IFLA_BROADCAST	2 | ||
| 58 | #define IFLA_IFNAME	3 | ||
| 59 | #define IFLA_STATS	7 | ||
| 60 | |||
| 61 | /* linux/if_addr.h */ | ||
| 62 | |||
| 63 | struct ifaddrmsg { | ||
| 64 | 	uint8_t		ifa_family; | ||
| 65 | 	uint8_t		ifa_prefixlen; | ||
| 66 | 	uint8_t		ifa_flags; | ||
| 67 | 	uint8_t		ifa_scope; | ||
| 68 | 	uint32_t	ifa_index; | ||
| 69 | }; | ||
| 70 | |||
| 71 | #define IFA_ADDRESS	1 | ||
| 72 | #define IFA_LOCAL	2 | ||
| 73 | #define IFA_LABEL	3 | ||
| 74 | #define IFA_BROADCAST	4 | ||
| 75 | |||
| 76 | /* musl */ | ||
| 77 | |||
| 78 | #define NETLINK_ALIGN(len)	(((len)+3) & ~3) | ||
| 79 | #define NLMSG_DATA(nlh)		((void*)((char*)(nlh)+sizeof(struct nlmsghdr))) | ||
| 80 | #define NLMSG_DATALEN(nlh)	((nlh)->nlmsg_len-sizeof(struct nlmsghdr)) | ||
| 81 | #define NLMSG_DATAEND(nlh)	((char*)(nlh)+(nlh)->nlmsg_len) | ||
| 82 | #define NLMSG_NEXT(nlh)		(struct nlmsghdr*)((char*)(nlh)+NETLINK_ALIGN((nlh)->nlmsg_len)) | ||
| 83 | #define NLMSG_OK(nlh,end)	((char*)(end)-(char*)(nlh) >= sizeof(struct nlmsghdr)) | ||
| 84 | |||
| 85 | #define RTA_DATA(rta)		((void*)((char*)(rta)+sizeof(struct rtattr))) | ||
| 86 | #define RTA_DATALEN(rta)	((rta)->rta_len-sizeof(struct rtattr)) | ||
| 87 | #define RTA_DATAEND(rta)	((char*)(rta)+(rta)->rta_len) | ||
| 88 | #define RTA_NEXT(rta)		(struct rtattr*)((char*)(rta)+NETLINK_ALIGN((rta)->rta_len)) | ||
| 89 | #define RTA_OK(nlh,end)		((char*)(end)-(char*)(rta) >= sizeof(struct rtattr)) | ||
| 90 | |||
| 91 | #define NLMSG_RTA(nlh,len)	((void*)((char*)(nlh)+sizeof(struct nlmsghdr)+NETLINK_ALIGN(len))) | ||
| 92 | #define NLMSG_RTAOK(rta,nlh)	RTA_OK(rta,NLMSG_DATAEND(nlh)) | ||
| 93 | |||
| 94 | hidden int __rtnetlink_enumerate(int link_af, int addr_af, int (*cb)(void *ctx, struct nlmsghdr *h), void *ctx); | ||
lib/libc/wasi/libc-top-half/musl/src/network/netname.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | |||
| 3 | struct netent *getnetbyaddr(uint32_t net, int type) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
| 7 | |||
| 8 | struct netent *getnetbyname(const char *name) | ||
| 9 | { | ||
| 10 | 	return 0; | ||
| 11 | } | ||
| 12 | |||
lib/libc/wasi/libc-top-half/musl/src/network/ns_parse.c created+171| ... | @@ -0,0 +1,171 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <errno.h> | ||
| 3 | #include <stddef.h> | ||
| 4 | #include <resolv.h> | ||
| 5 | #include <arpa/nameser.h> | ||
| 6 | |||
| 7 | const struct _ns_flagdata _ns_flagdata[16] = { | ||
| 8 | 	{ 0x8000, 15 }, | ||
| 9 | 	{ 0x7800, 11 }, | ||
| 10 | 	{ 0x0400, 10 }, | ||
| 11 | 	{ 0x0200, 9 }, | ||
| 12 | 	{ 0x0100, 8 }, | ||
| 13 | 	{ 0x0080, 7 }, | ||
| 14 | 	{ 0x0040, 6 }, | ||
| 15 | 	{ 0x0020, 5 }, | ||
| 16 | 	{ 0x0010, 4 }, | ||
| 17 | 	{ 0x000f, 0 }, | ||
| 18 | 	{ 0x0000, 0 }, | ||
| 19 | 	{ 0x0000, 0 }, | ||
| 20 | 	{ 0x0000, 0 }, | ||
| 21 | 	{ 0x0000, 0 }, | ||
| 22 | 	{ 0x0000, 0 }, | ||
| 23 | 	{ 0x0000, 0 }, | ||
| 24 | }; | ||
| 25 | |||
| 26 | unsigned ns_get16(const unsigned char *cp) | ||
| 27 | { | ||
| 28 | 	return cp[0]<<8 | cp[1]; | ||
| 29 | } | ||
| 30 | |||
| 31 | unsigned long ns_get32(const unsigned char *cp) | ||
| 32 | { | ||
| 33 | 	return (unsigned)cp[0]<<24 | cp[1]<<16 | cp[2]<<8 | cp[3]; | ||
| 34 | } | ||
| 35 | |||
| 36 | void ns_put16(unsigned s, unsigned char *cp) | ||
| 37 | { | ||
| 38 | 	*cp++ = s>>8; | ||
| 39 | 	*cp++ = s; | ||
| 40 | } | ||
| 41 | |||
| 42 | void ns_put32(unsigned long l, unsigned char *cp) | ||
| 43 | { | ||
| 44 | 	*cp++ = l>>24; | ||
| 45 | 	*cp++ = l>>16; | ||
| 46 | 	*cp++ = l>>8; | ||
| 47 | 	*cp++ = l; | ||
| 48 | } | ||
| 49 | |||
| 50 | int ns_initparse(const unsigned char *msg, int msglen, ns_msg *handle) | ||
| 51 | { | ||
| 52 | 	int i, r; | ||
| 53 | |||
| 54 | 	handle->_msg = msg; | ||
| 55 | 	handle->_eom = msg + msglen; | ||
| 56 | 	if (msglen < (2 + ns_s_max) * NS_INT16SZ) goto bad; | ||
| 57 | 	NS_GET16(handle->_id, msg); | ||
| 58 | 	NS_GET16(handle->_flags, msg); | ||
| 59 | 	for (i = 0; i < ns_s_max; i++) NS_GET16(handle->_counts[i], msg); | ||
| 60 | 	for (i = 0; i < ns_s_max; i++) { | ||
| 61 | 		if (handle->_counts[i]) { | ||
| 62 | 			handle->_sections[i] = msg; | ||
| 63 | 			r = ns_skiprr(msg, handle->_eom, i, handle->_counts[i]); | ||
| 64 | 			if (r < 0) return -1; | ||
| 65 | 			msg += r; | ||
| 66 | 		} else { | ||
| 67 | 			handle->_sections[i] = NULL; | ||
| 68 | 		} | ||
| 69 | 	} | ||
| 70 | 	if (msg != handle->_eom) goto bad; | ||
| 71 | 	handle->_sect = ns_s_max; | ||
| 72 | 	handle->_rrnum = -1; | ||
| 73 | 	handle->_msg_ptr = NULL; | ||
| 74 | 	return 0; | ||
| 75 | bad: | ||
| 76 | 	errno = EMSGSIZE; | ||
| 77 | 	return -1; | ||
| 78 | } | ||
| 79 | |||
| 80 | int ns_skiprr(const unsigned char *ptr, const unsigned char *eom, ns_sect section, int count) | ||
| 81 | { | ||
| 82 | 	const unsigned char *p = ptr; | ||
| 83 | 	int r; | ||
| 84 | |||
| 85 | 	while (count--) { | ||
| 86 | 		r = dn_skipname(p, eom); | ||
| 87 | 		if (r < 0) goto bad; | ||
| 88 | 		if (r + 2 * NS_INT16SZ > eom - p) goto bad; | ||
| 89 | 		p += r + 2 * NS_INT16SZ; | ||
| 90 | 		if (section != ns_s_qd) { | ||
| 91 | 			if (NS_INT32SZ + NS_INT16SZ > eom - p) goto bad; | ||
| 92 | 			p += NS_INT32SZ; | ||
| 93 | 			NS_GET16(r, p); | ||
| 94 | 			if (r > eom - p) goto bad; | ||
| 95 | 			p += r; | ||
| 96 | 		} | ||
| 97 | 	} | ||
| 98 | 	return p - ptr; | ||
| 99 | bad: | ||
| 100 | 	errno = EMSGSIZE; | ||
| 101 | 	return -1; | ||
| 102 | } | ||
| 103 | |||
| 104 | int ns_parserr(ns_msg *handle, ns_sect section, int rrnum, ns_rr *rr) | ||
| 105 | { | ||
| 106 | 	int r; | ||
| 107 | |||
| 108 | 	if (section < 0 || section >= ns_s_max) goto bad; | ||
| 109 | 	if (section != handle->_sect) { | ||
| 110 | 		handle->_sect = section; | ||
| 111 | 		handle->_rrnum = 0; | ||
| 112 | 		handle->_msg_ptr = handle->_sections[section]; | ||
| 113 | 	} | ||
| 114 | 	if (rrnum == -1) rrnum = handle->_rrnum; | ||
| 115 | 	if (rrnum < 0 || rrnum >= handle->_counts[section]) goto bad; | ||
| 116 | 	if (rrnum < handle->_rrnum) { | ||
| 117 | 		handle->_rrnum = 0; | ||
| 118 | 		handle->_msg_ptr = handle->_sections[section]; | ||
| 119 | 	} | ||
| 120 | 	if (rrnum > handle->_rrnum) { | ||
| 121 | 		r = ns_skiprr(handle->_msg_ptr, handle->_eom, section, rrnum - handle->_rrnum); | ||
| 122 | 		if (r < 0) return -1; | ||
| 123 | 		handle->_msg_ptr += r; | ||
| 124 | 		handle->_rrnum = rrnum; | ||
| 125 | 	} | ||
| 126 | 	r = ns_name_uncompress(handle->_msg, handle->_eom, handle->_msg_ptr, rr->name, NS_MAXDNAME); | ||
| 127 | 	if (r < 0) return -1; | ||
| 128 | 	handle->_msg_ptr += r; | ||
| 129 | 	if (2 * NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size; | ||
| 130 | 	NS_GET16(rr->type, handle->_msg_ptr); | ||
| 131 | 	NS_GET16(rr->rr_class, handle->_msg_ptr); | ||
| 132 | 	if (section != ns_s_qd) { | ||
| 133 | 		if (NS_INT32SZ + NS_INT16SZ > handle->_eom - handle->_msg_ptr) goto size; | ||
| 134 | 		NS_GET32(rr->ttl, handle->_msg_ptr); | ||
| 135 | 		NS_GET16(rr->rdlength, handle->_msg_ptr); | ||
| 136 | 		if (rr->rdlength > handle->_eom - handle->_msg_ptr) goto size; | ||
| 137 | 		rr->rdata = handle->_msg_ptr; | ||
| 138 | 		handle->_msg_ptr += rr->rdlength; | ||
| 139 | 	} else { | ||
| 140 | 		rr->ttl = 0; | ||
| 141 | 		rr->rdlength = 0; | ||
| 142 | 		rr->rdata = NULL; | ||
| 143 | 	} | ||
| 144 | 	handle->_rrnum++; | ||
| 145 | 	if (handle->_rrnum > handle->_counts[section]) { | ||
| 146 | 		handle->_sect = section + 1; | ||
| 147 | 		if (handle->_sect == ns_s_max) { | ||
| 148 | 			handle->_rrnum = -1; | ||
| 149 | 			handle->_msg_ptr = NULL; | ||
| 150 | 		} else { | ||
| 151 | 			handle->_rrnum = 0; | ||
| 152 | 		} | ||
| 153 | 	} | ||
| 154 | 	return 0; | ||
| 155 | bad: | ||
| 156 | 	errno = ENODEV; | ||
| 157 | 	return -1; | ||
| 158 | size: | ||
| 159 | 	errno = EMSGSIZE; | ||
| 160 | 	return -1; | ||
| 161 | } | ||
| 162 | |||
| 163 | int ns_name_uncompress(const unsigned char *msg, const unsigned char *eom, | ||
| 164 | const unsigned char *src, char *dst, size_t dstsiz) | ||
| 165 | { | ||
| 166 | 	int r; | ||
| 167 | 	r = dn_expand(msg, eom, src, dst, dstsiz); | ||
| 168 | 	if (r < 0) errno = EMSGSIZE; | ||
| 169 | 	return r; | ||
| 170 | } | ||
| 171 | |||
lib/libc/wasi/libc-top-half/musl/src/network/ntohl.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <netinet/in.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | |||
| 4 | uint32_t ntohl(uint32_t n) | ||
| 5 | { | ||
| 6 | 	union { int i; char c; } u = { 1 }; | ||
| 7 | 	return u.c ? bswap_32(n) : n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/ntohs.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <netinet/in.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | |||
| 4 | uint16_t ntohs(uint16_t n) | ||
| 5 | { | ||
| 6 | 	union { int i; char c; } u = { 1 }; | ||
| 7 | 	return u.c ? bswap_16(n) : n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/proto.c created+84| ... | @@ -0,0 +1,84 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | /* do we really need all these?? */ | ||
| 5 | |||
| 6 | static int idx; | ||
| 7 | static const unsigned char protos[] = { | ||
| 8 | 	"\000ip\0" | ||
| 9 | 	"\001icmp\0" | ||
| 10 | 	"\002igmp\0" | ||
| 11 | 	"\003ggp\0" | ||
| 12 | 	"\004ipencap\0" | ||
| 13 | 	"\005st\0" | ||
| 14 | 	"\006tcp\0" | ||
| 15 | 	"\010egp\0" | ||
| 16 | 	"\014pup\0" | ||
| 17 | 	"\021udp\0" | ||
| 18 | 	"\024hmp\0" | ||
| 19 | 	"\026xns-idp\0" | ||
| 20 | 	"\033rdp\0" | ||
| 21 | 	"\035iso-tp4\0" | ||
| 22 | 	"\044xtp\0" | ||
| 23 | 	"\045ddp\0" | ||
| 24 | 	"\046idpr-cmtp\0" | ||
| 25 | 	"\051ipv6\0" | ||
| 26 | 	"\053ipv6-route\0" | ||
| 27 | 	"\054ipv6-frag\0" | ||
| 28 | 	"\055idrp\0" | ||
| 29 | 	"\056rsvp\0" | ||
| 30 | 	"\057gre\0" | ||
| 31 | 	"\062esp\0" | ||
| 32 | 	"\063ah\0" | ||
| 33 | 	"\071skip\0" | ||
| 34 | 	"\072ipv6-icmp\0" | ||
| 35 | 	"\073ipv6-nonxt\0" | ||
| 36 | 	"\074ipv6-opts\0" | ||
| 37 | 	"\111rspf\0" | ||
| 38 | 	"\121vmtp\0" | ||
| 39 | 	"\131ospf\0" | ||
| 40 | 	"\136ipip\0" | ||
| 41 | 	"\142encap\0" | ||
| 42 | 	"\147pim\0" | ||
| 43 | 	"\377raw" | ||
| 44 | }; | ||
| 45 | |||
| 46 | void endprotoent(void) | ||
| 47 | { | ||
| 48 | 	idx = 0; | ||
| 49 | } | ||
| 50 | |||
| 51 | void setprotoent(int stayopen) | ||
| 52 | { | ||
| 53 | 	idx = 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | struct protoent *getprotoent(void) | ||
| 57 | { | ||
| 58 | 	static struct protoent p; | ||
| 59 | 	static const char *aliases; | ||
| 60 | 	if (idx >= sizeof protos) return NULL; | ||
| 61 | 	p.p_proto = protos[idx]; | ||
| 62 | 	p.p_name = (char *)&protos[idx+1]; | ||
| 63 | 	p.p_aliases = (char **)&aliases; | ||
| 64 | 	idx += strlen(p.p_name) + 2; | ||
| 65 | 	return &p; | ||
| 66 | } | ||
| 67 | |||
| 68 | struct protoent *getprotobyname(const char *name) | ||
| 69 | { | ||
| 70 | 	struct protoent *p; | ||
| 71 | 	endprotoent(); | ||
| 72 | 	do p = getprotoent(); | ||
| 73 | 	while (p && strcmp(name, p->p_name)); | ||
| 74 | 	return p; | ||
| 75 | } | ||
| 76 | |||
| 77 | struct protoent *getprotobynumber(int num) | ||
| 78 | { | ||
| 79 | 	struct protoent *p; | ||
| 80 | 	endprotoent(); | ||
| 81 | 	do p = getprotoent(); | ||
| 82 | 	while (p && p->p_proto != num); | ||
| 83 | 	return p; | ||
| 84 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/recv.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | |||
| 3 | ssize_t recv(int fd, void *buf, size_t len, int flags) | ||
| 4 | { | ||
| 5 | 	return recvfrom(fd, buf, len, flags, 0, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/recvfrom.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t recvfrom(int fd, void *restrict buf, size_t len, int flags, struct sockaddr *restrict addr, socklen_t *restrict alen) | ||
| 5 | { | ||
| 6 | 	return socketcall_cp(recvfrom, fd, buf, len, flags, addr, alen); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/recvmmsg.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <time.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 9 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 10 | |||
| 11 | hidden void __convert_scm_timestamps(struct msghdr *, socklen_t); | ||
| 12 | |||
| 13 | int recvmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags, struct timespec *timeout) | ||
| 14 | { | ||
| 15 | #if LONG_MAX > INT_MAX | ||
| 16 | 	struct mmsghdr *mh = msgvec; | ||
| 17 | 	unsigned int i; | ||
| 18 | 	for (i = vlen; i; i--, mh++) | ||
| 19 | 		mh->msg_hdr.__pad1 = mh->msg_hdr.__pad2 = 0; | ||
| 20 | #endif | ||
| 21 | #ifdef SYS_recvmmsg_time64 | ||
| 22 | 	time_t s = timeout ? timeout->tv_sec : 0; | ||
| 23 | 	long ns = timeout ? timeout->tv_nsec : 0; | ||
| 24 | 	int r = __syscall_cp(SYS_recvmmsg_time64, fd, msgvec, vlen, flags, | ||
| 25 | 			timeout ? ((long long[]){s, ns}) : 0); | ||
| 26 | 	if (SYS_recvmmsg == SYS_recvmmsg_time64 || r!=-ENOSYS) | ||
| 27 | 		return __syscall_ret(r); | ||
| 28 | 	if (vlen > IOV_MAX) vlen = IOV_MAX; | ||
| 29 | 	socklen_t csize[vlen]; | ||
| 30 | 	for (int i=0; i<vlen; i++) csize[i] = msgvec[i].msg_hdr.msg_controllen; | ||
| 31 | 	r = __syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, | ||
| 32 | 		timeout ? ((long[]){CLAMP(s), ns}) : 0); | ||
| 33 | 	for (int i=0; i<r; i++) | ||
| 34 | 		__convert_scm_timestamps(&msgvec[i].msg_hdr, csize[i]); | ||
| 35 | 	return __syscall_ret(r); | ||
| 36 | #else | ||
| 37 | 	return syscall_cp(SYS_recvmmsg, fd, msgvec, vlen, flags, timeout); | ||
| 38 | #endif | ||
| 39 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/recvmsg.c created+68| ... | @@ -0,0 +1,68 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <time.h> | ||
| 4 | #include <sys/time.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include "syscall.h" | ||
| 7 | |||
| 8 | hidden void __convert_scm_timestamps(struct msghdr *, socklen_t); | ||
| 9 | |||
| 10 | void __convert_scm_timestamps(struct msghdr *msg, socklen_t csize) | ||
| 11 | { | ||
| 12 | 	if (SCM_TIMESTAMP == SCM_TIMESTAMP_OLD) return; | ||
| 13 | 	if (!msg->msg_control || !msg->msg_controllen) return; | ||
| 14 | |||
| 15 | 	struct cmsghdr *cmsg, *last=0; | ||
| 16 | 	long tmp; | ||
| 17 | 	long long tvts[2]; | ||
| 18 | 	int type = 0; | ||
| 19 | |||
| 20 | 	for (cmsg=CMSG_FIRSTHDR(msg); cmsg; cmsg=CMSG_NXTHDR(msg, cmsg)) { | ||
| 21 | 		if (cmsg->cmsg_level==SOL_SOCKET) switch (cmsg->cmsg_type) { | ||
| 22 | 		case SCM_TIMESTAMP_OLD: | ||
| 23 | 			if (type) break; | ||
| 24 | 			type = SCM_TIMESTAMP; | ||
| 25 | 			goto common; | ||
| 26 | 		case SCM_TIMESTAMPNS_OLD: | ||
| 27 | 			type = SCM_TIMESTAMPNS; | ||
| 28 | 		common: | ||
| 29 | 			memcpy(&tmp, CMSG_DATA(cmsg), sizeof tmp); | ||
| 30 | 			tvts[0] = tmp; | ||
| 31 | 			memcpy(&tmp, CMSG_DATA(cmsg) + sizeof tmp, sizeof tmp); | ||
| 32 | 			tvts[1] = tmp; | ||
| 33 | 			break; | ||
| 34 | 		} | ||
| 35 | 		last = cmsg; | ||
| 36 | 	} | ||
| 37 | 	if (!last || !type) return; | ||
| 38 | 	if (CMSG_SPACE(sizeof tvts) > csize-msg->msg_controllen) { | ||
| 39 | 		msg->msg_flags |= MSG_CTRUNC; | ||
| 40 | 		return; | ||
| 41 | 	} | ||
| 42 | 	msg->msg_controllen += CMSG_SPACE(sizeof tvts); | ||
| 43 | 	cmsg = CMSG_NXTHDR(msg, last); | ||
| 44 | 	cmsg->cmsg_level = SOL_SOCKET; | ||
| 45 | 	cmsg->cmsg_type = type; | ||
| 46 | 	cmsg->cmsg_len = CMSG_LEN(sizeof tvts); | ||
| 47 | 	memcpy(CMSG_DATA(cmsg), &tvts, sizeof tvts); | ||
| 48 | } | ||
| 49 | |||
| 50 | ssize_t recvmsg(int fd, struct msghdr *msg, int flags) | ||
| 51 | { | ||
| 52 | 	ssize_t r; | ||
| 53 | 	socklen_t orig_controllen = msg->msg_controllen; | ||
| 54 | #if LONG_MAX > INT_MAX | ||
| 55 | 	struct msghdr h, *orig = msg; | ||
| 56 | 	if (msg) { | ||
| 57 | 		h = *msg; | ||
| 58 | 		h.__pad1 = h.__pad2 = 0; | ||
| 59 | 		msg = &h; | ||
| 60 | 	} | ||
| 61 | #endif | ||
| 62 | 	r = socketcall_cp(recvmsg, fd, msg, flags, 0, 0, 0); | ||
| 63 | 	if (r >= 0) __convert_scm_timestamps(msg, orig_controllen); | ||
| 64 | #if LONG_MAX > INT_MAX | ||
| 65 | 	if (orig) *orig = h; | ||
| 66 | #endif | ||
| 67 | 	return r; | ||
| 68 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_init.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | |||
| 3 | int res_init() | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_mkquery.c created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <time.h> | ||
| 4 | |||
| 5 | int __res_mkquery(int op, const char *dname, int class, int type, | ||
| 6 | 	const unsigned char *data, int datalen, | ||
| 7 | 	const unsigned char *newrr, unsigned char *buf, int buflen) | ||
| 8 | { | ||
| 9 | 	int id, i, j; | ||
| 10 | 	unsigned char q[280]; | ||
| 11 | 	struct timespec ts; | ||
| 12 | 	size_t l = strnlen(dname, 255); | ||
| 13 | 	int n; | ||
| 14 | |||
| 15 | 	if (l && dname[l-1]=='.') l--; | ||
| 16 | 	n = 17+l+!!l; | ||
| 17 | 	if (l>253 || buflen<n || op>15u || class>255u || type>255u) | ||
| 18 | 		return -1; | ||
| 19 | |||
| 20 | 	/* Construct query template - ID will be filled later */ | ||
| 21 | 	memset(q, 0, n); | ||
| 22 | 	q[2] = op*8 + 1; | ||
| 23 | 	q[3] = 32; /* AD */ | ||
| 24 | 	q[5] = 1; | ||
| 25 | 	memcpy((char *)q+13, dname, l); | ||
| 26 | 	for (i=13; q[i]; i=j+1) { | ||
| 27 | 		for (j=i; q[j] && q[j] != '.'; j++); | ||
| 28 | 		if (j-i-1u > 62u) return -1; | ||
| 29 | 		q[i-1] = j-i; | ||
| 30 | 	} | ||
| 31 | 	q[i+1] = type; | ||
| 32 | 	q[i+3] = class; | ||
| 33 | |||
| 34 | 	/* Make a reasonably unpredictable id */ | ||
| 35 | 	clock_gettime(CLOCK_REALTIME, &ts); | ||
| 36 | 	id = ts.tv_nsec + ts.tv_nsec/65536UL & 0xffff; | ||
| 37 | 	q[0] = id/256; | ||
| 38 | 	q[1] = id; | ||
| 39 | |||
| 40 | 	memcpy(buf, q, n); | ||
| 41 | 	return n; | ||
| 42 | } | ||
| 43 | |||
| 44 | weak_alias(__res_mkquery, res_mkquery); | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_msend.c created+188| ... | @@ -0,0 +1,188 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <netinet/in.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | #include <arpa/inet.h> | ||
| 5 | #include <stdint.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <poll.h> | ||
| 8 | #include <time.h> | ||
| 9 | #include <ctype.h> | ||
| 10 | #include <unistd.h> | ||
| 11 | #include <errno.h> | ||
| 12 | #include <pthread.h> | ||
| 13 | #include "stdio_impl.h" | ||
| 14 | #include "syscall.h" | ||
| 15 | #include "lookup.h" | ||
| 16 | |||
| 17 | static void cleanup(void *p) | ||
| 18 | { | ||
| 19 | 	__syscall(SYS_close, (intptr_t)p); | ||
| 20 | } | ||
| 21 | |||
| 22 | static unsigned long mtime() | ||
| 23 | { | ||
| 24 | 	struct timespec ts; | ||
| 25 | 	clock_gettime(CLOCK_REALTIME, &ts); | ||
| 26 | 	return (unsigned long)ts.tv_sec * 1000 | ||
| 27 | 		+ ts.tv_nsec / 1000000; | ||
| 28 | } | ||
| 29 | |||
| 30 | int __res_msend_rc(int nqueries, const unsigned char *const *queries, | ||
| 31 | 	const int *qlens, unsigned char *const *answers, int *alens, int asize, | ||
| 32 | 	const struct resolvconf *conf) | ||
| 33 | { | ||
| 34 | 	int fd; | ||
| 35 | 	int timeout, attempts, retry_interval, servfail_retry; | ||
| 36 | 	union { | ||
| 37 | 		struct sockaddr_in sin; | ||
| 38 | 		struct sockaddr_in6 sin6; | ||
| 39 | 	} sa = {0}, ns[MAXNS] = {{0}}; | ||
| 40 | 	socklen_t sl = sizeof sa.sin; | ||
| 41 | 	int nns = 0; | ||
| 42 | 	int family = AF_INET; | ||
| 43 | 	int rlen; | ||
| 44 | 	int next; | ||
| 45 | 	int i, j; | ||
| 46 | 	int cs; | ||
| 47 | 	struct pollfd pfd; | ||
| 48 | 	unsigned long t0, t1, t2; | ||
| 49 | |||
| 50 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 51 | |||
| 52 | 	timeout = 1000*conf->timeout; | ||
| 53 | 	attempts = conf->attempts; | ||
| 54 | |||
| 55 | 	for (nns=0; nns<conf->nns; nns++) { | ||
| 56 | 		const struct address *iplit = &conf->ns[nns]; | ||
| 57 | 		if (iplit->family == AF_INET) { | ||
| 58 | 			memcpy(&ns[nns].sin.sin_addr, iplit->addr, 4); | ||
| 59 | 			ns[nns].sin.sin_port = htons(53); | ||
| 60 | 			ns[nns].sin.sin_family = AF_INET; | ||
| 61 | 		} else { | ||
| 62 | 			sl = sizeof sa.sin6; | ||
| 63 | 			memcpy(&ns[nns].sin6.sin6_addr, iplit->addr, 16); | ||
| 64 | 			ns[nns].sin6.sin6_port = htons(53); | ||
| 65 | 			ns[nns].sin6.sin6_scope_id = iplit->scopeid; | ||
| 66 | 			ns[nns].sin6.sin6_family = family = AF_INET6; | ||
| 67 | 		} | ||
| 68 | 	} | ||
| 69 | |||
| 70 | 	/* Get local address and open/bind a socket */ | ||
| 71 | 	sa.sin.sin_family = family; | ||
| 72 | 	fd = socket(family, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); | ||
| 73 | |||
| 74 | 	/* Handle case where system lacks IPv6 support */ | ||
| 75 | 	if (fd < 0 && family == AF_INET6 && errno == EAFNOSUPPORT) { | ||
| 76 | 		fd = socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); | ||
| 77 | 		family = AF_INET; | ||
| 78 | 	} | ||
| 79 | 	if (fd < 0 || bind(fd, (void *)&sa, sl) < 0) { | ||
| 80 | 		if (fd >= 0) close(fd); | ||
| 81 | 		pthread_setcancelstate(cs, 0); | ||
| 82 | 		return -1; | ||
| 83 | 	} | ||
| 84 | |||
| 85 | 	/* Past this point, there are no errors. Each individual query will | ||
| 86 | 	 * yield either no reply (indicated by zero length) or an answer | ||
| 87 | 	 * packet which is up to the caller to interpret. */ | ||
| 88 | |||
| 89 | 	pthread_cleanup_push(cleanup, (void *)(intptr_t)fd); | ||
| 90 | 	pthread_setcancelstate(cs, 0); | ||
| 91 | |||
| 92 | 	/* Convert any IPv4 addresses in a mixed environment to v4-mapped */ | ||
| 93 | 	if (family == AF_INET6) { | ||
| 94 | 		setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &(int){0}, sizeof 0); | ||
| 95 | 		for (i=0; i<nns; i++) { | ||
| 96 | 			if (ns[i].sin.sin_family != AF_INET) continue; | ||
| 97 | 			memcpy(ns[i].sin6.sin6_addr.s6_addr+12, | ||
| 98 | 				&ns[i].sin.sin_addr, 4); | ||
| 99 | 			memcpy(ns[i].sin6.sin6_addr.s6_addr, | ||
| 100 | 				"\0\0\0\0\0\0\0\0\0\0\xff\xff", 12); | ||
| 101 | 			ns[i].sin6.sin6_family = AF_INET6; | ||
| 102 | 			ns[i].sin6.sin6_flowinfo = 0; | ||
| 103 | 			ns[i].sin6.sin6_scope_id = 0; | ||
| 104 | 		} | ||
| 105 | 	} | ||
| 106 | |||
| 107 | 	memset(alens, 0, sizeof *alens * nqueries); | ||
| 108 | |||
| 109 | 	pfd.fd = fd; | ||
| 110 | 	pfd.events = POLLIN; | ||
| 111 | 	retry_interval = timeout / attempts; | ||
| 112 | 	next = 0; | ||
| 113 | 	t0 = t2 = mtime(); | ||
| 114 | 	t1 = t2 - retry_interval; | ||
| 115 | |||
| 116 | 	for (; t2-t0 < timeout; t2=mtime()) { | ||
| 117 | 		if (t2-t1 >= retry_interval) { | ||
| 118 | 			/* Query all configured namservers in parallel */ | ||
| 119 | 			for (i=0; i<nqueries; i++) | ||
| 120 | 				if (!alens[i]) | ||
| 121 | 					for (j=0; j<nns; j++) | ||
| 122 | 						sendto(fd, queries[i], | ||
| 123 | 							qlens[i], MSG_NOSIGNAL, | ||
| 124 | 							(void *)&ns[j], sl); | ||
| 125 | 			t1 = t2; | ||
| 126 | 			servfail_retry = 2 * nqueries; | ||
| 127 | 		} | ||
| 128 | |||
| 129 | 		/* Wait for a response, or until time to retry */ | ||
| 130 | 		if (poll(&pfd, 1, t1+retry_interval-t2) <= 0) continue; | ||
| 131 | |||
| 132 | 		while ((rlen = recvfrom(fd, answers[next], asize, 0, | ||
| 133 | 		 (void *)&sa, (socklen_t[1]){sl})) >= 0) { | ||
| 134 | |||
| 135 | 			/* Ignore non-identifiable packets */ | ||
| 136 | 			if (rlen < 4) continue; | ||
| 137 | |||
| 138 | 			/* Ignore replies from addresses we didn't send to */ | ||
| 139 | 			for (j=0; j<nns && memcmp(ns+j, &sa, sl); j++); | ||
| 140 | 			if (j==nns) continue; | ||
| 141 | |||
| 142 | 			/* Find which query this answer goes with, if any */ | ||
| 143 | 			for (i=next; i<nqueries && ( | ||
| 144 | 				answers[next][0] != queries[i][0] || | ||
| 145 | 				answers[next][1] != queries[i][1] ); i++); | ||
| 146 | 			if (i==nqueries) continue; | ||
| 147 | 			if (alens[i]) continue; | ||
| 148 | |||
| 149 | 			/* Only accept positive or negative responses; | ||
| 150 | 			 * retry immediately on server failure, and ignore | ||
| 151 | 			 * all other codes such as refusal. */ | ||
| 152 | 			switch (answers[next][3] & 15) { | ||
| 153 | 			case 0: | ||
| 154 | 			case 3: | ||
| 155 | 				break; | ||
| 156 | 			case 2: | ||
| 157 | 				if (servfail_retry && servfail_retry--) | ||
| 158 | 					sendto(fd, queries[i], | ||
| 159 | 						qlens[i], MSG_NOSIGNAL, | ||
| 160 | 						(void *)&ns[j], sl); | ||
| 161 | 			default: | ||
| 162 | 				continue; | ||
| 163 | 			} | ||
| 164 | |||
| 165 | 			/* Store answer in the right slot, or update next | ||
| 166 | 			 * available temp slot if it's already in place. */ | ||
| 167 | 			alens[i] = rlen; | ||
| 168 | 			if (i == next) | ||
| 169 | 				for (; next<nqueries && alens[next]; next++); | ||
| 170 | 			else | ||
| 171 | 				memcpy(answers[i], answers[next], rlen); | ||
| 172 | |||
| 173 | 			if (next == nqueries) goto out; | ||
| 174 | 		} | ||
| 175 | 	} | ||
| 176 | out: | ||
| 177 | 	pthread_cleanup_pop(1); | ||
| 178 | |||
| 179 | 	return 0; | ||
| 180 | } | ||
| 181 | |||
| 182 | int __res_msend(int nqueries, const unsigned char *const *queries, | ||
| 183 | 	const int *qlens, unsigned char *const *answers, int *alens, int asize) | ||
| 184 | { | ||
| 185 | 	struct resolvconf conf; | ||
| 186 | 	if (__get_resolv_conf(&conf, 0, 0) < 0) return -1; | ||
| 187 | 	return __res_msend_rc(nqueries, queries, qlens, answers, alens, asize, &conf); | ||
| 188 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_query.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <resolv.h> | ||
| 3 | #include <netdb.h> | ||
| 4 | |||
| 5 | int res_query(const char *name, int class, int type, unsigned char *dest, int len) | ||
| 6 | { | ||
| 7 | 	unsigned char q[280]; | ||
| 8 | 	int ql = __res_mkquery(0, name, class, type, 0, 0, 0, q, sizeof q); | ||
| 9 | 	if (ql < 0) return ql; | ||
| 10 | 	int r = __res_send(q, ql, dest, len); | ||
| 11 | 	if (r<12) { | ||
| 12 | 		h_errno = TRY_AGAIN; | ||
| 13 | 		return -1; | ||
| 14 | 	} | ||
| 15 | 	if ((dest[3] & 15) == 3) { | ||
| 16 | 		h_errno = HOST_NOT_FOUND; | ||
| 17 | 		return -1; | ||
| 18 | 	} | ||
| 19 | 	if ((dest[3] & 15) == 0 && !dest[6] && !dest[7]) { | ||
| 20 | 		h_errno = NO_DATA; | ||
| 21 | 		return -1; | ||
| 22 | 	} | ||
| 23 | 	return r; | ||
| 24 | } | ||
| 25 | |||
| 26 | weak_alias(res_query, res_search); | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_querydomain.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | int res_querydomain(const char *name, const char *domain, int class, int type, unsigned char *dest, int len) | ||
| 5 | { | ||
| 6 | 	char tmp[255]; | ||
| 7 | 	size_t nl = strnlen(name, 255); | ||
| 8 | 	size_t dl = strnlen(domain, 255); | ||
| 9 | 	if (nl+dl+1 > 254) return -1; | ||
| 10 | 	memcpy(tmp, name, nl); | ||
| 11 | 	tmp[nl] = '.'; | ||
| 12 | 	memcpy(tmp+nl+1, domain, dl+1); | ||
| 13 | 	return res_query(tmp, class, type, dest, len); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_send.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | |||
| 3 | int __res_send(const unsigned char *msg, int msglen, unsigned char *answer, int anslen) | ||
| 4 | { | ||
| 5 | 	int r = __res_msend(1, &msg, &msglen, &answer, &anslen, anslen); | ||
| 6 | 	return r<0 || !anslen ? -1 : anslen; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__res_send, res_send); | ||
lib/libc/wasi/libc-top-half/musl/src/network/res_state.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <resolv.h> | ||
| 2 | |||
| 3 | /* This is completely unused, and exists purely to satisfy broken apps. */ | ||
| 4 | |||
| 5 | struct __res_state *__res_state() | ||
| 6 | { | ||
| 7 | 	static struct __res_state res; | ||
| 8 | 	return &res; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/resolvconf.c created+94| ... | @@ -0,0 +1,94 @@ | ||
| 1 | #include "lookup.h" | ||
| 2 | #include "stdio_impl.h" | ||
| 3 | #include <ctype.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include <netinet/in.h> | ||
| 8 | |||
| 9 | int __get_resolv_conf(struct resolvconf *conf, char *search, size_t search_sz) | ||
| 10 | { | ||
| 11 | 	char line[256]; | ||
| 12 | 	unsigned char _buf[256]; | ||
| 13 | 	FILE *f, _f; | ||
| 14 | 	int nns = 0; | ||
| 15 | |||
| 16 | 	conf->ndots = 1; | ||
| 17 | 	conf->timeout = 5; | ||
| 18 | 	conf->attempts = 2; | ||
| 19 | 	if (search) *search = 0; | ||
| 20 | |||
| 21 | 	f = __fopen_rb_ca("/etc/resolv.conf", &_f, _buf, sizeof _buf); | ||
| 22 | 	if (!f) switch (errno) { | ||
| 23 | 	case ENOENT: | ||
| 24 | 	case ENOTDIR: | ||
| 25 | 	case EACCES: | ||
| 26 | 		goto no_resolv_conf; | ||
| 27 | 	default: | ||
| 28 | 		return -1; | ||
| 29 | 	} | ||
| 30 | |||
| 31 | 	while (fgets(line, sizeof line, f)) { | ||
| 32 | 		char *p, *z; | ||
| 33 | 		if (!strchr(line, '\n') && !feof(f)) { | ||
| 34 | 			/* Ignore lines that get truncated rather than | ||
| 35 | 			 * potentially misinterpreting them. */ | ||
| 36 | 			int c; | ||
| 37 | 			do c = getc(f); | ||
| 38 | 			while (c != '\n' && c != EOF); | ||
| 39 | 			continue; | ||
| 40 | 		} | ||
| 41 | 		if (!strncmp(line, "options", 7) && isspace(line[7])) { | ||
| 42 | 			p = strstr(line, "ndots:"); | ||
| 43 | 			if (p && isdigit(p[6])) { | ||
| 44 | 				p += 6; | ||
| 45 | 				unsigned long x = strtoul(p, &z, 10); | ||
| 46 | 				if (z != p) conf->ndots = x > 15 ? 15 : x; | ||
| 47 | 			} | ||
| 48 | 			p = strstr(line, "attempts:"); | ||
| 49 | 			if (p && isdigit(p[9])) { | ||
| 50 | 				p += 9; | ||
| 51 | 				unsigned long x = strtoul(p, &z, 10); | ||
| 52 | 				if (z != p) conf->attempts = x > 10 ? 10 : x; | ||
| 53 | 			} | ||
| 54 | 			p = strstr(line, "timeout:"); | ||
| 55 | 			if (p && (isdigit(p[8]) || p[8]=='.')) { | ||
| 56 | 				p += 8; | ||
| 57 | 				unsigned long x = strtoul(p, &z, 10); | ||
| 58 | 				if (z != p) conf->timeout = x > 60 ? 60 : x; | ||
| 59 | 			} | ||
| 60 | 			continue; | ||
| 61 | 		} | ||
| 62 | 		if (!strncmp(line, "nameserver", 10) && isspace(line[10])) { | ||
| 63 | 			if (nns >= MAXNS) continue; | ||
| 64 | 			for (p=line+11; isspace(*p); p++); | ||
| 65 | 			for (z=p; *z && !isspace(*z); z++); | ||
| 66 | 			*z=0; | ||
| 67 | 			if (__lookup_ipliteral(conf->ns+nns, p, AF_UNSPEC) > 0) | ||
| 68 | 				nns++; | ||
| 69 | 			continue; | ||
| 70 | 		} | ||
| 71 | |||
| 72 | 		if (!search) continue; | ||
| 73 | 		if ((strncmp(line, "domain", 6) && strncmp(line, "search", 6)) | ||
| 74 | 		 || !isspace(line[6])) | ||
| 75 | 			continue; | ||
| 76 | 		for (p=line+7; isspace(*p); p++); | ||
| 77 | 		size_t l = strlen(p); | ||
| 78 | 		/* This can never happen anyway with chosen buffer sizes. */ | ||
| 79 | 		if (l >= search_sz) continue; | ||
| 80 | 		memcpy(search, p, l+1); | ||
| 81 | 	} | ||
| 82 | |||
| 83 | 	__fclose_ca(f); | ||
| 84 | |||
| 85 | no_resolv_conf: | ||
| 86 | 	if (!nns) { | ||
| 87 | 		__lookup_ipliteral(conf->ns, "127.0.0.1", AF_UNSPEC); | ||
| 88 | 		nns = 1; | ||
| 89 | 	} | ||
| 90 | |||
| 91 | 	conf->nns = nns; | ||
| 92 | |||
| 93 | 	return 0; | ||
| 94 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/send.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | |||
| 3 | ssize_t send(int fd, const void *buf, size_t len, int flags) | ||
| 4 | { | ||
| 5 | 	return sendto(fd, buf, len, flags, 0, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/sendmmsg.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/socket.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int sendmmsg(int fd, struct mmsghdr *msgvec, unsigned int vlen, unsigned int flags) | ||
| 8 | { | ||
| 9 | #if LONG_MAX > INT_MAX | ||
| 10 | 	/* Can't use the syscall directly because the kernel has the wrong | ||
| 11 | 	 * idea for the types of msg_iovlen, msg_controllen, and cmsg_len, | ||
| 12 | 	 * and the cmsg blocks cannot be modified in-place. */ | ||
| 13 | 	int i; | ||
| 14 | 	if (vlen > IOV_MAX) vlen = IOV_MAX; /* This matches the kernel. */ | ||
| 15 | 	if (!vlen) return 0; | ||
| 16 | 	for (i=0; i<vlen; i++) { | ||
| 17 | 		/* As an unfortunate inconsistency, the sendmmsg API uses | ||
| 18 | 		 * unsigned int for the resulting msg_len, despite sendmsg | ||
| 19 | 		 * returning ssize_t. However Linux limits the total bytes | ||
| 20 | 		 * sent by sendmsg to INT_MAX, so the assignment is safe. */ | ||
| 21 | 		ssize_t r = sendmsg(fd, &msgvec[i].msg_hdr, flags); | ||
| 22 | 		if (r < 0) goto error; | ||
| 23 | 		msgvec[i].msg_len = r; | ||
| 24 | 	} | ||
| 25 | error: | ||
| 26 | 	return i ? i : -1; | ||
| 27 | #else | ||
| 28 | 	return syscall_cp(SYS_sendmmsg, fd, msgvec, vlen, flags); | ||
| 29 | #endif | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/sendmsg.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | ssize_t sendmsg(int fd, const struct msghdr *msg, int flags) | ||
| 8 | { | ||
| 9 | #if LONG_MAX > INT_MAX | ||
| 10 | 	struct msghdr h; | ||
| 11 | 	struct cmsghdr chbuf[1024/sizeof(struct cmsghdr)+1], *c; | ||
| 12 | 	if (msg) { | ||
| 13 | 		h = *msg; | ||
| 14 | 		h.__pad1 = h.__pad2 = 0; | ||
| 15 | 		msg = &h; | ||
| 16 | 		if (h.msg_controllen) { | ||
| 17 | 			if (h.msg_controllen > 1024) { | ||
| 18 | 				errno = ENOMEM; | ||
| 19 | 				return -1; | ||
| 20 | 			} | ||
| 21 | 			memcpy(chbuf, h.msg_control, h.msg_controllen); | ||
| 22 | 			h.msg_control = chbuf; | ||
| 23 | 			for (c=CMSG_FIRSTHDR(&h); c; c=CMSG_NXTHDR(&h,c)) | ||
| 24 | 				c->__pad1 = 0; | ||
| 25 | 		} | ||
| 26 | 	} | ||
| 27 | #endif | ||
| 28 | 	return socketcall_cp(sendmsg, fd, msg, flags, 0, 0, 0); | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/sendto.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t sendto(int fd, const void *buf, size_t len, int flags, const struct sockaddr *addr, socklen_t alen) | ||
| 5 | { | ||
| 6 | 	return socketcall_cp(sendto, fd, buf, len, flags, addr, alen); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/serv.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <netdb.h> | ||
| 2 | |||
| 3 | void endservent(void) | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | void setservent(int stayopen) | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | struct servent *getservent(void) | ||
| 12 | { | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/setsockopt.c created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 7 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 8 | |||
| 9 | int setsockopt(int fd, int level, int optname, const void *optval, socklen_t optlen) | ||
| 10 | { | ||
| 11 | 	const struct timeval *tv; | ||
| 12 | 	time_t s; | ||
| 13 | 	suseconds_t us; | ||
| 14 | |||
| 15 | 	int r = __socketcall(setsockopt, fd, level, optname, optval, optlen, 0); | ||
| 16 | |||
| 17 | 	if (r==-ENOPROTOOPT) switch (level) { | ||
| 18 | 	case SOL_SOCKET: | ||
| 19 | 		switch (optname) { | ||
| 20 | 		case SO_RCVTIMEO: | ||
| 21 | 		case SO_SNDTIMEO: | ||
| 22 | 			if (SO_RCVTIMEO == SO_RCVTIMEO_OLD) break; | ||
| 23 | 			if (optlen < sizeof *tv) return __syscall_ret(-EINVAL); | ||
| 24 | 			tv = optval; | ||
| 25 | 			s = tv->tv_sec; | ||
| 26 | 			us = tv->tv_usec; | ||
| 27 | 			if (!IS32BIT(s)) return __syscall_ret(-ENOTSUP); | ||
| 28 | |||
| 29 | 			if (optname==SO_RCVTIMEO) optname=SO_RCVTIMEO_OLD; | ||
| 30 | 			if (optname==SO_SNDTIMEO) optname=SO_SNDTIMEO_OLD; | ||
| 31 | |||
| 32 | 			r = __socketcall(setsockopt, fd, level, optname, | ||
| 33 | 				((long[]){s, CLAMP(us)}), 2*sizeof(long), 0); | ||
| 34 | 			break; | ||
| 35 | 		case SO_TIMESTAMP: | ||
| 36 | 		case SO_TIMESTAMPNS: | ||
| 37 | 			if (SO_TIMESTAMP == SO_TIMESTAMP_OLD) break; | ||
| 38 | 			if (optname==SO_TIMESTAMP) optname=SO_TIMESTAMP_OLD; | ||
| 39 | 			if (optname==SO_TIMESTAMPNS) optname=SO_TIMESTAMPNS_OLD; | ||
| 40 | 			r = __socketcall(setsockopt, fd, level, | ||
| 41 | 				optname, optval, optlen, 0); | ||
| 42 | 			break; | ||
| 43 | 		} | ||
| 44 | 	} | ||
| 45 | 	return __syscall_ret(r); | ||
| 46 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/shutdown.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int shutdown(int fd, int how) | ||
| 5 | { | ||
| 6 | 	return socketcall(shutdown, fd, how, 0, 0, 0, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/sockatmark.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | |||
| 4 | int sockatmark(int s) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	if (ioctl(s, SIOCATMARK, &ret) < 0) | ||
| 8 | 		return -1; | ||
| 9 | 	return ret; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/socket.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int socket(int domain, int type, int protocol) | ||
| 7 | { | ||
| 8 | 	int s = __socketcall(socket, domain, type, protocol, 0, 0, 0); | ||
| 9 | 	if ((s==-EINVAL || s==-EPROTONOSUPPORT) | ||
| 10 | 	 && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { | ||
| 11 | 		s = __socketcall(socket, domain, | ||
| 12 | 			type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), | ||
| 13 | 			protocol, 0, 0, 0); | ||
| 14 | 		if (s < 0) return __syscall_ret(s); | ||
| 15 | 		if (type & SOCK_CLOEXEC) | ||
| 16 | 			__syscall(SYS_fcntl, s, F_SETFD, FD_CLOEXEC); | ||
| 17 | 		if (type & SOCK_NONBLOCK) | ||
| 18 | 			__syscall(SYS_fcntl, s, F_SETFL, O_NONBLOCK); | ||
| 19 | 	} | ||
| 20 | 	return __syscall_ret(s); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/network/socketpair.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int socketpair(int domain, int type, int protocol, int fd[2]) | ||
| 7 | { | ||
| 8 | 	int r = socketcall(socketpair, domain, type, protocol, fd, 0, 0); | ||
| 9 | 	if (r<0 && (errno==EINVAL || errno==EPROTONOSUPPORT) | ||
| 10 | 	 && (type&(SOCK_CLOEXEC|SOCK_NONBLOCK))) { | ||
| 11 | 		r = socketcall(socketpair, domain, | ||
| 12 | 			type & ~(SOCK_CLOEXEC|SOCK_NONBLOCK), | ||
| 13 | 			protocol, fd, 0, 0); | ||
| 14 | 		if (r < 0) return r; | ||
| 15 | 		if (type & SOCK_CLOEXEC) { | ||
| 16 | 			__syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); | ||
| 17 | 			__syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); | ||
| 18 | 		} | ||
| 19 | 		if (type & SOCK_NONBLOCK) { | ||
| 20 | 			__syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); | ||
| 21 | 			__syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); | ||
| 22 | 		} | ||
| 23 | 	} | ||
| 24 | 	return r; | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetgrent.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pwf.h" | ||
| 3 | |||
| 4 | struct group *fgetgrent(FILE *f) | ||
| 5 | { | ||
| 6 | 	static char *line, **mem; | ||
| 7 | 	static struct group gr; | ||
| 8 | 	struct group *res; | ||
| 9 | 	size_t size=0, nmem=0; | ||
| 10 | 	__getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res); | ||
| 11 | 	return res; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetpwent.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pwf.h" | ||
| 3 | |||
| 4 | struct passwd *fgetpwent(FILE *f) | ||
| 5 | { | ||
| 6 | 	static char *line; | ||
| 7 | 	static struct passwd pw; | ||
| 8 | 	size_t size=0; | ||
| 9 | 	struct passwd *res; | ||
| 10 | 	__getpwent_a(f, &pw, &line, &size, &res); | ||
| 11 | 	return res; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/fgetspent.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | struct spwd *fgetspent(FILE *f) | ||
| 5 | { | ||
| 6 | 	static char *line; | ||
| 7 | 	static struct spwd sp; | ||
| 8 | 	size_t size = 0; | ||
| 9 | 	struct spwd *res = 0; | ||
| 10 | 	int cs; | ||
| 11 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 12 | 	if (getline(&line, &size, f) >= 0 && __parsespent(line, &sp) >= 0) res = &sp; | ||
| 13 | 	pthread_setcancelstate(cs, 0); | ||
| 14 | 	return res; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getgr_a.c created+169| ... | @@ -0,0 +1,169 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include "pwf.h" | ||
| 6 | #include "nscd.h" | ||
| 7 | |||
| 8 | static char *itoa(char *p, uint32_t x) | ||
| 9 | { | ||
| 10 | 	// number of digits in a uint32_t + NUL | ||
| 11 | 	p += 11; | ||
| 12 | 	*--p = 0; | ||
| 13 | 	do { | ||
| 14 | 		*--p = '0' + x % 10; | ||
| 15 | 		x /= 10; | ||
| 16 | 	} while (x); | ||
| 17 | 	return p; | ||
| 18 | } | ||
| 19 | |||
| 20 | int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t *size, char ***mem, size_t *nmem, struct group **res) | ||
| 21 | { | ||
| 22 | 	FILE *f; | ||
| 23 | 	int rv = 0; | ||
| 24 | 	int cs; | ||
| 25 | |||
| 26 | 	*res = 0; | ||
| 27 | |||
| 28 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 29 | 	f = fopen("/etc/group", "rbe"); | ||
| 30 | 	if (!f) { | ||
| 31 | 		rv = errno; | ||
| 32 | 		goto done; | ||
| 33 | 	} | ||
| 34 | |||
| 35 | 	while (!(rv = __getgrent_a(f, gr, buf, size, mem, nmem, res)) && *res) { | ||
| 36 | 		if (name && !strcmp(name, (*res)->gr_name) | ||
| 37 | 		|| !name && (*res)->gr_gid == gid) { | ||
| 38 | 			break; | ||
| 39 | 		} | ||
| 40 | 	} | ||
| 41 | 	fclose(f); | ||
| 42 | |||
| 43 | 	if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) { | ||
| 44 | 		int32_t req = name ? GETGRBYNAME : GETGRBYGID; | ||
| 45 | 		int32_t i; | ||
| 46 | 		const char *key; | ||
| 47 | 		int32_t groupbuf[GR_LEN] = {0}; | ||
| 48 | 		size_t len = 0; | ||
| 49 | 		size_t grlist_len = 0; | ||
| 50 | 		char gidbuf[11] = {0}; | ||
| 51 | 		int swap = 0; | ||
| 52 | 		char *ptr; | ||
| 53 | |||
| 54 | 		if (name) { | ||
| 55 | 			key = name; | ||
| 56 | 		} else { | ||
| 57 | 			if (gid < 0 || gid > UINT32_MAX) { | ||
| 58 | 				rv = 0; | ||
| 59 | 				goto done; | ||
| 60 | 			} | ||
| 61 | 			key = itoa(gidbuf, gid); | ||
| 62 | 		} | ||
| 63 | |||
| 64 | 		f = __nscd_query(req, key, groupbuf, sizeof groupbuf, &swap); | ||
| 65 | 		if (!f) { rv = errno; goto done; } | ||
| 66 | |||
| 67 | 		if (!groupbuf[GRFOUND]) { rv = 0; goto cleanup_f; } | ||
| 68 | |||
| 69 | 		if (!groupbuf[GRNAMELEN] || !groupbuf[GRPASSWDLEN]) { | ||
| 70 | 			rv = EIO; | ||
| 71 | 			goto cleanup_f; | ||
| 72 | 		} | ||
| 73 | |||
| 74 | 		if (groupbuf[GRNAMELEN] > SIZE_MAX - groupbuf[GRPASSWDLEN]) { | ||
| 75 | 			rv = ENOMEM; | ||
| 76 | 			goto cleanup_f; | ||
| 77 | 		} | ||
| 78 | 		len = groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN]; | ||
| 79 | |||
| 80 | 		for (i = 0; i < groupbuf[GRMEMCNT]; i++) { | ||
| 81 | 			uint32_t name_len; | ||
| 82 | 			if (fread(&name_len, sizeof name_len, 1, f) < 1) { | ||
| 83 | 				rv = ferror(f) ? errno : EIO; | ||
| 84 | 				goto cleanup_f; | ||
| 85 | 			} | ||
| 86 | 			if (swap) { | ||
| 87 | 				name_len = bswap_32(name_len); | ||
| 88 | 			} | ||
| 89 | 			if (name_len > SIZE_MAX - grlist_len | ||
| 90 | 			|| name_len > SIZE_MAX - len) { | ||
| 91 | 				rv = ENOMEM; | ||
| 92 | 				goto cleanup_f; | ||
| 93 | 			} | ||
| 94 | 			len += name_len; | ||
| 95 | 			grlist_len += name_len; | ||
| 96 | 		} | ||
| 97 | |||
| 98 | 		if (len > *size || !*buf) { | ||
| 99 | 			char *tmp = realloc(*buf, len); | ||
| 100 | 			if (!tmp) { | ||
| 101 | 				rv = errno; | ||
| 102 | 				goto cleanup_f; | ||
| 103 | 			} | ||
| 104 | 			*buf = tmp; | ||
| 105 | 			*size = len; | ||
| 106 | 		} | ||
| 107 | |||
| 108 | 		if (!fread(*buf, len, 1, f)) { | ||
| 109 | 			rv = ferror(f) ? errno : EIO; | ||
| 110 | 			goto cleanup_f; | ||
| 111 | 		} | ||
| 112 | |||
| 113 | 		if (groupbuf[GRMEMCNT] + 1 > *nmem) { | ||
| 114 | 			if (groupbuf[GRMEMCNT] + 1 > SIZE_MAX/sizeof(char*)) { | ||
| 115 | 				rv = ENOMEM; | ||
| 116 | 				goto cleanup_f; | ||
| 117 | 			} | ||
| 118 | 			char **tmp = realloc(*mem, (groupbuf[GRMEMCNT]+1)*sizeof(char*)); | ||
| 119 | 			if (!tmp) { | ||
| 120 | 				rv = errno; | ||
| 121 | 				goto cleanup_f; | ||
| 122 | 			} | ||
| 123 | 			*mem = tmp; | ||
| 124 | 			*nmem = groupbuf[GRMEMCNT] + 1; | ||
| 125 | 		} | ||
| 126 | |||
| 127 | 		if (groupbuf[GRMEMCNT]) { | ||
| 128 | 			mem[0][0] = *buf + groupbuf[GRNAMELEN] + groupbuf[GRPASSWDLEN]; | ||
| 129 | 			for (ptr = mem[0][0], i = 0; ptr != mem[0][0]+grlist_len; ptr++) | ||
| 130 | 				if (!*ptr) mem[0][++i] = ptr+1; | ||
| 131 | 			mem[0][i] = 0; | ||
| 132 | |||
| 133 | 			if (i != groupbuf[GRMEMCNT]) { | ||
| 134 | 				rv = EIO; | ||
| 135 | 				goto cleanup_f; | ||
| 136 | 			} | ||
| 137 | 		} else { | ||
| 138 | 			mem[0][0] = 0; | ||
| 139 | 		} | ||
| 140 | |||
| 141 | 		gr->gr_name = *buf; | ||
| 142 | 		gr->gr_passwd = gr->gr_name + groupbuf[GRNAMELEN]; | ||
| 143 | 		gr->gr_gid = groupbuf[GRGID]; | ||
| 144 | 		gr->gr_mem = *mem; | ||
| 145 | |||
| 146 | 		if (gr->gr_passwd[-1] | ||
| 147 | 		|| gr->gr_passwd[groupbuf[GRPASSWDLEN]-1]) { | ||
| 148 | 			rv = EIO; | ||
| 149 | 			goto cleanup_f; | ||
| 150 | 		} | ||
| 151 | |||
| 152 | 		if (name && strcmp(name, gr->gr_name) | ||
| 153 | 		|| !name && gid != gr->gr_gid) { | ||
| 154 | 			rv = EIO; | ||
| 155 | 			goto cleanup_f; | ||
| 156 | 		} | ||
| 157 | |||
| 158 | 		*res = gr; | ||
| 159 | |||
| 160 | cleanup_f: | ||
| 161 | 		fclose(f); | ||
| 162 | 		goto done; | ||
| 163 | 	} | ||
| 164 | |||
| 165 | done: | ||
| 166 | 	pthread_setcancelstate(cs, 0); | ||
| 167 | 	if (rv) errno = rv; | ||
| 168 | 	return rv; | ||
| 169 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getgr_r.c created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | #define FIX(x) (gr->gr_##x = gr->gr_##x-line+buf) | ||
| 5 | |||
| 6 | static int getgr_r(const char *name, gid_t gid, struct group *gr, char *buf, size_t size, struct group **res) | ||
| 7 | { | ||
| 8 | 	char *line = 0; | ||
| 9 | 	size_t len = 0; | ||
| 10 | 	char **mem = 0; | ||
| 11 | 	size_t nmem = 0; | ||
| 12 | 	int rv = 0; | ||
| 13 | 	size_t i; | ||
| 14 | 	int cs; | ||
| 15 | |||
| 16 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 17 | |||
| 18 | 	rv = __getgr_a(name, gid, gr, &line, &len, &mem, &nmem, res); | ||
| 19 | 	if (*res && size < len + (nmem+1)*sizeof(char *) + 32) { | ||
| 20 | 		*res = 0; | ||
| 21 | 		rv = ERANGE; | ||
| 22 | 	} | ||
| 23 | 	if (*res) { | ||
| 24 | 		buf += (16-(uintptr_t)buf)%16; | ||
| 25 | 		gr->gr_mem = (void *)buf; | ||
| 26 | 		buf += (nmem+1)*sizeof(char *); | ||
| 27 | 		memcpy(buf, line, len); | ||
| 28 | 		FIX(name); | ||
| 29 | 		FIX(passwd); | ||
| 30 | 		for (i=0; mem[i]; i++) | ||
| 31 | 			gr->gr_mem[i] = mem[i]-line+buf; | ||
| 32 | 		gr->gr_mem[i] = 0; | ||
| 33 | 	} | ||
| 34 | 	free(mem); | ||
| 35 | 	free(line); | ||
| 36 | 	pthread_setcancelstate(cs, 0); | ||
| 37 | 	if (rv) errno = rv; | ||
| 38 | 	return rv; | ||
| 39 | } | ||
| 40 | |||
| 41 | int getgrnam_r(const char *name, struct group *gr, char *buf, size_t size, struct group **res) | ||
| 42 | { | ||
| 43 | 	return getgr_r(name, 0, gr, buf, size, res); | ||
| 44 | } | ||
| 45 | |||
| 46 | int getgrgid_r(gid_t gid, struct group *gr, char *buf, size_t size, struct group **res) | ||
| 47 | { | ||
| 48 | 	return getgr_r(0, gid, gr, buf, size, res); | ||
| 49 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrent.c created+39| ... | @@ -0,0 +1,39 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | |||
| 3 | static FILE *f; | ||
| 4 | static char *line, **mem; | ||
| 5 | static struct group gr; | ||
| 6 | |||
| 7 | void setgrent() | ||
| 8 | { | ||
| 9 | 	if (f) fclose(f); | ||
| 10 | 	f = 0; | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(setgrent, endgrent); | ||
| 14 | |||
| 15 | struct group *getgrent() | ||
| 16 | { | ||
| 17 | 	struct group *res; | ||
| 18 | 	size_t size=0, nmem=0; | ||
| 19 | 	if (!f) f = fopen("/etc/group", "rbe"); | ||
| 20 | 	if (!f) return 0; | ||
| 21 | 	__getgrent_a(f, &gr, &line, &size, &mem, &nmem, &res); | ||
| 22 | 	return res; | ||
| 23 | } | ||
| 24 | |||
| 25 | struct group *getgrgid(gid_t gid) | ||
| 26 | { | ||
| 27 | 	struct group *res; | ||
| 28 | 	size_t size=0, nmem=0; | ||
| 29 | 	__getgr_a(0, gid, &gr, &line, &size, &mem, &nmem, &res); | ||
| 30 | 	return res; | ||
| 31 | } | ||
| 32 | |||
| 33 | struct group *getgrnam(const char *name) | ||
| 34 | { | ||
| 35 | 	struct group *res; | ||
| 36 | 	size_t size=0, nmem=0; | ||
| 37 | 	__getgr_a(name, 0, &gr, &line, &size, &mem, &nmem, &res); | ||
| 38 | 	return res; | ||
| 39 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrent_a.c created+68| ... | @@ -0,0 +1,68 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | static unsigned atou(char **s) | ||
| 5 | { | ||
| 6 | 	unsigned x; | ||
| 7 | 	for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem, struct group **res) | ||
| 12 | { | ||
| 13 | 	ssize_t l; | ||
| 14 | 	char *s, *mems; | ||
| 15 | 	size_t i; | ||
| 16 | 	int rv = 0; | ||
| 17 | 	int cs; | ||
| 18 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 19 | 	for (;;) { | ||
| 20 | 		if ((l=getline(line, size, f)) < 0) { | ||
| 21 | 			rv = ferror(f) ? errno : 0; | ||
| 22 | 			free(*line); | ||
| 23 | 			*line = 0; | ||
| 24 | 			gr = 0; | ||
| 25 | 			goto end; | ||
| 26 | 		} | ||
| 27 | 		line[0][l-1] = 0; | ||
| 28 | |||
| 29 | 		s = line[0]; | ||
| 30 | 		gr->gr_name = s++; | ||
| 31 | 		if (!(s = strchr(s, ':'))) continue; | ||
| 32 | |||
| 33 | 		*s++ = 0; gr->gr_passwd = s; | ||
| 34 | 		if (!(s = strchr(s, ':'))) continue; | ||
| 35 | |||
| 36 | 		*s++ = 0; gr->gr_gid = atou(&s); | ||
| 37 | 		if (*s != ':') continue; | ||
| 38 | |||
| 39 | 		*s++ = 0; mems = s; | ||
| 40 | 		break; | ||
| 41 | 	} | ||
| 42 | |||
| 43 | 	for (*nmem=!!*s; *s; s++) | ||
| 44 | 		if (*s==',') ++*nmem; | ||
| 45 | 	free(*mem); | ||
| 46 | 	*mem = calloc(sizeof(char *), *nmem+1); | ||
| 47 | 	if (!*mem) { | ||
| 48 | 		rv = errno; | ||
| 49 | 		free(*line); | ||
| 50 | 		*line = 0; | ||
| 51 | 		gr = 0; | ||
| 52 | 		goto end; | ||
| 53 | 	} | ||
| 54 | 	if (*mems) { | ||
| 55 | 		mem[0][0] = mems; | ||
| 56 | 		for (s=mems, i=0; *s; s++) | ||
| 57 | 			if (*s==',') *s++ = 0, mem[0][++i] = s; | ||
| 58 | 		mem[0][++i] = 0; | ||
| 59 | 	} else { | ||
| 60 | 		mem[0][0] = 0; | ||
| 61 | 	} | ||
| 62 | 	gr->gr_mem = *mem; | ||
| 63 | end: | ||
| 64 | 	pthread_setcancelstate(cs, 0); | ||
| 65 | 	*res = gr; | ||
| 66 | 	if(rv) errno = rv; | ||
| 67 | 	return rv; | ||
| 68 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getgrouplist.c created+81| ... | @@ -0,0 +1,81 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pwf.h" | ||
| 3 | #include <grp.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <stdio.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <byteswap.h> | ||
| 9 | #include <errno.h> | ||
| 10 | #include "nscd.h" | ||
| 11 | |||
| 12 | int getgrouplist(const char *user, gid_t gid, gid_t *groups, int *ngroups) | ||
| 13 | { | ||
| 14 | 	int rv, nlim, ret = -1; | ||
| 15 | 	ssize_t i, n = 1; | ||
| 16 | 	struct group gr; | ||
| 17 | 	struct group *res; | ||
| 18 | 	FILE *f; | ||
| 19 | 	int swap = 0; | ||
| 20 | 	int32_t resp[INITGR_LEN]; | ||
| 21 | 	uint32_t *nscdbuf = 0; | ||
| 22 | 	char *buf = 0; | ||
| 23 | 	char **mem = 0; | ||
| 24 | 	size_t nmem = 0; | ||
| 25 | 	size_t size; | ||
| 26 | 	nlim = *ngroups; | ||
| 27 | 	if (nlim >= 1) *groups++ = gid; | ||
| 28 | |||
| 29 | 	f = __nscd_query(GETINITGR, user, resp, sizeof resp, &swap); | ||
| 30 | 	if (!f) goto cleanup; | ||
| 31 | 	if (resp[INITGRFOUND]) { | ||
| 32 | 		nscdbuf = calloc(resp[INITGRNGRPS], sizeof(uint32_t)); | ||
| 33 | 		if (!nscdbuf) goto cleanup; | ||
| 34 | 		size_t nbytes = sizeof(*nscdbuf)*resp[INITGRNGRPS]; | ||
| 35 | 		if (nbytes && !fread(nscdbuf, nbytes, 1, f)) { | ||
| 36 | 			if (!ferror(f)) errno = EIO; | ||
| 37 | 			goto cleanup; | ||
| 38 | 		} | ||
| 39 | 		if (swap) { | ||
| 40 | 			for (i = 0; i < resp[INITGRNGRPS]; i++) | ||
| 41 | 				nscdbuf[i] = bswap_32(nscdbuf[i]); | ||
| 42 | 		} | ||
| 43 | 	} | ||
| 44 | 	fclose(f); | ||
| 45 | |||
| 46 | 	f = fopen("/etc/group", "rbe"); | ||
| 47 | 	if (!f && errno != ENOENT && errno != ENOTDIR) | ||
| 48 | 		goto cleanup; | ||
| 49 | |||
| 50 | 	if (f) { | ||
| 51 | 		while (!(rv = __getgrent_a(f, &gr, &buf, &size, &mem, &nmem, &res)) && res) { | ||
| 52 | 			if (nscdbuf) | ||
| 53 | 				for (i=0; i < resp[INITGRNGRPS]; i++) { | ||
| 54 | 					if (nscdbuf[i] == gr.gr_gid) nscdbuf[i] = gid; | ||
| 55 | 				} | ||
| 56 | 			for (i=0; gr.gr_mem[i] && strcmp(user, gr.gr_mem[i]); i++); | ||
| 57 | 			if (!gr.gr_mem[i]) continue; | ||
| 58 | 			if (++n <= nlim) *groups++ = gr.gr_gid; | ||
| 59 | 		} | ||
| 60 | 		if (rv) { | ||
| 61 | 			errno = rv; | ||
| 62 | 			goto cleanup; | ||
| 63 | 		} | ||
| 64 | 	} | ||
| 65 | 	if (nscdbuf) { | ||
| 66 | 		for(i=0; i < resp[INITGRNGRPS]; i++) { | ||
| 67 | 			if (nscdbuf[i] != gid) | ||
| 68 | 				if(++n <= nlim) *groups++ = nscdbuf[i]; | ||
| 69 | 		} | ||
| 70 | 	} | ||
| 71 | |||
| 72 | 	ret = n > nlim ? -1 : n; | ||
| 73 | 	*ngroups = n; | ||
| 74 | |||
| 75 | cleanup: | ||
| 76 | 	if (f) fclose(f); | ||
| 77 | 	free(nscdbuf); | ||
| 78 | 	free(buf); | ||
| 79 | 	free(mem); | ||
| 80 | 	return ret; | ||
| 81 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getpw_a.c created+142| ... | @@ -0,0 +1,142 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include "pwf.h" | ||
| 6 | #include "nscd.h" | ||
| 7 | |||
| 8 | static char *itoa(char *p, uint32_t x) | ||
| 9 | { | ||
| 10 | 	// number of digits in a uint32_t + NUL | ||
| 11 | 	p += 11; | ||
| 12 | 	*--p = 0; | ||
| 13 | 	do { | ||
| 14 | 		*--p = '0' + x % 10; | ||
| 15 | 		x /= 10; | ||
| 16 | 	} while (x); | ||
| 17 | 	return p; | ||
| 18 | } | ||
| 19 | |||
| 20 | int __getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf, size_t *size, struct passwd **res) | ||
| 21 | { | ||
| 22 | 	FILE *f; | ||
| 23 | 	int cs; | ||
| 24 | 	int rv = 0; | ||
| 25 | |||
| 26 | 	*res = 0; | ||
| 27 | |||
| 28 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 29 | |||
| 30 | 	f = fopen("/etc/passwd", "rbe"); | ||
| 31 | 	if (!f) { | ||
| 32 | 		rv = errno; | ||
| 33 | 		goto done; | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	while (!(rv = __getpwent_a(f, pw, buf, size, res)) && *res) { | ||
| 37 | 		if (name && !strcmp(name, (*res)->pw_name) | ||
| 38 | 		|| !name && (*res)->pw_uid == uid) | ||
| 39 | 			break; | ||
| 40 | 	} | ||
| 41 | 	fclose(f); | ||
| 42 | |||
| 43 | 	if (!*res && (rv == 0 || rv == ENOENT || rv == ENOTDIR)) { | ||
| 44 | 		int32_t req = name ? GETPWBYNAME : GETPWBYUID; | ||
| 45 | 		const char *key; | ||
| 46 | 		int32_t passwdbuf[PW_LEN] = {0}; | ||
| 47 | 		size_t len = 0; | ||
| 48 | 		char uidbuf[11] = {0}; | ||
| 49 | |||
| 50 | 		if (name) { | ||
| 51 | 			key = name; | ||
| 52 | 		} else { | ||
| 53 | 			/* uid outside of this range can't be queried with the | ||
| 54 | 			 * nscd interface, but might happen if uid_t ever | ||
| 55 | 			 * happens to be a larger type (this is not true as of | ||
| 56 | 			 * now) | ||
| 57 | 			 */ | ||
| 58 | 			if(uid < 0 || uid > UINT32_MAX) { | ||
| 59 | 				rv = 0; | ||
| 60 | 				goto done; | ||
| 61 | 			} | ||
| 62 | 			key = itoa(uidbuf, uid); | ||
| 63 | 		} | ||
| 64 | |||
| 65 | 		f = __nscd_query(req, key, passwdbuf, sizeof passwdbuf, (int[]){0}); | ||
| 66 | 		if (!f) { rv = errno; goto done; } | ||
| 67 | |||
| 68 | 		if(!passwdbuf[PWFOUND]) { rv = 0; goto cleanup_f; } | ||
| 69 | |||
| 70 | 		/* A zero length response from nscd is invalid. We ignore | ||
| 71 | 		 * invalid responses and just report an error, rather than | ||
| 72 | 		 * trying to do something with them. | ||
| 73 | 		 */ | ||
| 74 | 		if (!passwdbuf[PWNAMELEN] || !passwdbuf[PWPASSWDLEN] | ||
| 75 | 		|| !passwdbuf[PWGECOSLEN] || !passwdbuf[PWDIRLEN] | ||
| 76 | 		|| !passwdbuf[PWSHELLLEN]) { | ||
| 77 | 			rv = EIO; | ||
| 78 | 			goto cleanup_f; | ||
| 79 | 		} | ||
| 80 | |||
| 81 | 		if ((passwdbuf[PWNAMELEN]|passwdbuf[PWPASSWDLEN] | ||
| 82 | 		 |passwdbuf[PWGECOSLEN]|passwdbuf[PWDIRLEN] | ||
| 83 | 		 |passwdbuf[PWSHELLLEN]) >= SIZE_MAX/8) { | ||
| 84 | 			rv = ENOMEM; | ||
| 85 | 			goto cleanup_f; | ||
| 86 | 		} | ||
| 87 | |||
| 88 | 		len = passwdbuf[PWNAMELEN] + passwdbuf[PWPASSWDLEN] | ||
| 89 | 		 + passwdbuf[PWGECOSLEN] + passwdbuf[PWDIRLEN] | ||
| 90 | 		 + passwdbuf[PWSHELLLEN]; | ||
| 91 | |||
| 92 | 		if (len > *size || !*buf) { | ||
| 93 | 			char *tmp = realloc(*buf, len); | ||
| 94 | 			if (!tmp) { | ||
| 95 | 				rv = errno; | ||
| 96 | 				goto cleanup_f; | ||
| 97 | 			} | ||
| 98 | 			*buf = tmp; | ||
| 99 | 			*size = len; | ||
| 100 | 		} | ||
| 101 | |||
| 102 | 		if (!fread(*buf, len, 1, f)) { | ||
| 103 | 			rv = ferror(f) ? errno : EIO; | ||
| 104 | 			goto cleanup_f; | ||
| 105 | 		} | ||
| 106 | |||
| 107 | 		pw->pw_name = *buf; | ||
| 108 | 		pw->pw_passwd = pw->pw_name + passwdbuf[PWNAMELEN]; | ||
| 109 | 		pw->pw_gecos = pw->pw_passwd + passwdbuf[PWPASSWDLEN]; | ||
| 110 | 		pw->pw_dir = pw->pw_gecos + passwdbuf[PWGECOSLEN]; | ||
| 111 | 		pw->pw_shell = pw->pw_dir + passwdbuf[PWDIRLEN]; | ||
| 112 | 		pw->pw_uid = passwdbuf[PWUID]; | ||
| 113 | 		pw->pw_gid = passwdbuf[PWGID]; | ||
| 114 | |||
| 115 | 		/* Don't assume that nscd made sure to null terminate strings. | ||
| 116 | 		 * It's supposed to, but malicious nscd should be ignored | ||
| 117 | 		 * rather than causing a crash. | ||
| 118 | 		 */ | ||
| 119 | 		if (pw->pw_passwd[-1] || pw->pw_gecos[-1] || pw->pw_dir[-1] | ||
| 120 | 		|| pw->pw_shell[passwdbuf[PWSHELLLEN]-1]) { | ||
| 121 | 			rv = EIO; | ||
| 122 | 			goto cleanup_f; | ||
| 123 | 		} | ||
| 124 | |||
| 125 | 		if (name && strcmp(name, pw->pw_name) | ||
| 126 | 		|| !name && uid != pw->pw_uid) { | ||
| 127 | 			rv = EIO; | ||
| 128 | 			goto cleanup_f; | ||
| 129 | 		} | ||
| 130 | |||
| 131 | |||
| 132 | 		*res = pw; | ||
| 133 | cleanup_f: | ||
| 134 | 		fclose(f); | ||
| 135 | 		goto done; | ||
| 136 | 	} | ||
| 137 | |||
| 138 | done: | ||
| 139 | 	pthread_setcancelstate(cs, 0); | ||
| 140 | 	if (rv) errno = rv; | ||
| 141 | 	return rv; | ||
| 142 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getpw_r.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | #define FIX(x) (pw->pw_##x = pw->pw_##x-line+buf) | ||
| 5 | |||
| 6 | static int getpw_r(const char *name, uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res) | ||
| 7 | { | ||
| 8 | 	char *line = 0; | ||
| 9 | 	size_t len = 0; | ||
| 10 | 	int rv = 0; | ||
| 11 | 	int cs; | ||
| 12 | |||
| 13 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 14 | |||
| 15 | 	rv = __getpw_a(name, uid, pw, &line, &len, res); | ||
| 16 | 	if (*res && size < len) { | ||
| 17 | 		*res = 0; | ||
| 18 | 		rv = ERANGE; | ||
| 19 | 	} | ||
| 20 | 	if (*res) { | ||
| 21 | 		memcpy(buf, line, len); | ||
| 22 | 		FIX(name); | ||
| 23 | 		FIX(passwd); | ||
| 24 | 		FIX(gecos); | ||
| 25 | 		FIX(dir); | ||
| 26 | 		FIX(shell); | ||
| 27 | 	} | ||
| 28 | 	free(line); | ||
| 29 | 	pthread_setcancelstate(cs, 0); | ||
| 30 | 	if (rv) errno = rv; | ||
| 31 | 	return rv; | ||
| 32 | } | ||
| 33 | |||
| 34 | int getpwnam_r(const char *name, struct passwd *pw, char *buf, size_t size, struct passwd **res) | ||
| 35 | { | ||
| 36 | 	return getpw_r(name, 0, pw, buf, size, res); | ||
| 37 | } | ||
| 38 | |||
| 39 | int getpwuid_r(uid_t uid, struct passwd *pw, char *buf, size_t size, struct passwd **res) | ||
| 40 | { | ||
| 41 | 	return getpw_r(0, uid, pw, buf, size, res); | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getpwent.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | |||
| 3 | static FILE *f; | ||
| 4 | static char *line; | ||
| 5 | static struct passwd pw; | ||
| 6 | static size_t size; | ||
| 7 | |||
| 8 | void setpwent() | ||
| 9 | { | ||
| 10 | 	if (f) fclose(f); | ||
| 11 | 	f = 0; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(setpwent, endpwent); | ||
| 15 | |||
| 16 | struct passwd *getpwent() | ||
| 17 | { | ||
| 18 | 	struct passwd *res; | ||
| 19 | 	if (!f) f = fopen("/etc/passwd", "rbe"); | ||
| 20 | 	if (!f) return 0; | ||
| 21 | 	__getpwent_a(f, &pw, &line, &size, &res); | ||
| 22 | 	return res; | ||
| 23 | } | ||
| 24 | |||
| 25 | struct passwd *getpwuid(uid_t uid) | ||
| 26 | { | ||
| 27 | 	struct passwd *res; | ||
| 28 | 	__getpw_a(0, uid, &pw, &line, &size, &res); | ||
| 29 | 	return res; | ||
| 30 | } | ||
| 31 | |||
| 32 | struct passwd *getpwnam(const char *name) | ||
| 33 | { | ||
| 34 | 	struct passwd *res; | ||
| 35 | 	__getpw_a(name, 0, &pw, &line, &size, &res); | ||
| 36 | 	return res; | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getpwent_a.c created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | static unsigned atou(char **s) | ||
| 5 | { | ||
| 6 | 	unsigned x; | ||
| 7 | 	for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); | ||
| 8 | 	return x; | ||
| 9 | } | ||
| 10 | |||
| 11 | int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res) | ||
| 12 | { | ||
| 13 | 	ssize_t l; | ||
| 14 | 	char *s; | ||
| 15 | 	int rv = 0; | ||
| 16 | 	int cs; | ||
| 17 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 18 | 	for (;;) { | ||
| 19 | 		if ((l=getline(line, size, f)) < 0) { | ||
| 20 | 			rv = ferror(f) ? errno : 0; | ||
| 21 | 			free(*line); | ||
| 22 | 			*line = 0; | ||
| 23 | 			pw = 0; | ||
| 24 | 			break; | ||
| 25 | 		} | ||
| 26 | 		line[0][l-1] = 0; | ||
| 27 | |||
| 28 | 		s = line[0]; | ||
| 29 | 		pw->pw_name = s++; | ||
| 30 | 		if (!(s = strchr(s, ':'))) continue; | ||
| 31 | |||
| 32 | 		*s++ = 0; pw->pw_passwd = s; | ||
| 33 | 		if (!(s = strchr(s, ':'))) continue; | ||
| 34 | |||
| 35 | 		*s++ = 0; pw->pw_uid = atou(&s); | ||
| 36 | 		if (*s != ':') continue; | ||
| 37 | |||
| 38 | 		*s++ = 0; pw->pw_gid = atou(&s); | ||
| 39 | 		if (*s != ':') continue; | ||
| 40 | |||
| 41 | 		*s++ = 0; pw->pw_gecos = s; | ||
| 42 | 		if (!(s = strchr(s, ':'))) continue; | ||
| 43 | |||
| 44 | 		*s++ = 0; pw->pw_dir = s; | ||
| 45 | 		if (!(s = strchr(s, ':'))) continue; | ||
| 46 | |||
| 47 | 		*s++ = 0; pw->pw_shell = s; | ||
| 48 | 		break; | ||
| 49 | 	} | ||
| 50 | 	pthread_setcancelstate(cs, 0); | ||
| 51 | 	*res = pw; | ||
| 52 | 	if (rv) errno = rv; | ||
| 53 | 	return rv; | ||
| 54 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getspent.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | |||
| 3 | void setspent() | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | void endspent() | ||
| 8 | { | ||
| 9 | } | ||
| 10 | |||
| 11 | struct spwd *getspent() | ||
| 12 | { | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getspnam.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include "pwf.h" | ||
| 2 | |||
| 3 | #define LINE_LIM 256 | ||
| 4 | |||
| 5 | struct spwd *getspnam(const char *name) | ||
| 6 | { | ||
| 7 | 	static struct spwd sp; | ||
| 8 | 	static char *line; | ||
| 9 | 	struct spwd *res; | ||
| 10 | 	int e; | ||
| 11 | 	int orig_errno = errno; | ||
| 12 | |||
| 13 | 	if (!line) line = malloc(LINE_LIM); | ||
| 14 | 	if (!line) return 0; | ||
| 15 | 	e = getspnam_r(name, &sp, line, LINE_LIM, &res); | ||
| 16 | 	errno = e ? e : orig_errno; | ||
| 17 | 	return res; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/getspnam_r.c created+125| ... | @@ -0,0 +1,125 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <sys/stat.h> | ||
| 4 | #include <ctype.h> | ||
| 5 | #include <pthread.h> | ||
| 6 | #include "pwf.h" | ||
| 7 | |||
| 8 | /* This implementation support Openwall-style TCB passwords in place of | ||
| 9 | * traditional shadow, if the appropriate directories and files exist. | ||
| 10 | * Thus, it is careful to avoid following symlinks or blocking on fifos | ||
| 11 | * which a malicious user might create in place of his or her TCB shadow | ||
| 12 | * file. It also avoids any allocation to prevent memory-exhaustion | ||
| 13 | * attacks via huge TCB shadow files. */ | ||
| 14 | |||
| 15 | static long xatol(char **s) | ||
| 16 | { | ||
| 17 | 	long x; | ||
| 18 | 	if (**s == ':' || **s == '\n') return -1; | ||
| 19 | 	for (x=0; **s-'0'<10U; ++*s) x=10*x+(**s-'0'); | ||
| 20 | 	return x; | ||
| 21 | } | ||
| 22 | |||
| 23 | int __parsespent(char *s, struct spwd *sp) | ||
| 24 | { | ||
| 25 | 	sp->sp_namp = s; | ||
| 26 | 	if (!(s = strchr(s, ':'))) return -1; | ||
| 27 | 	*s = 0; | ||
| 28 | |||
| 29 | 	sp->sp_pwdp = ++s; | ||
| 30 | 	if (!(s = strchr(s, ':'))) return -1; | ||
| 31 | 	*s = 0; | ||
| 32 | |||
| 33 | 	s++; sp->sp_lstchg = xatol(&s); | ||
| 34 | 	if (*s != ':') return -1; | ||
| 35 | |||
| 36 | 	s++; sp->sp_min = xatol(&s); | ||
| 37 | 	if (*s != ':') return -1; | ||
| 38 | |||
| 39 | 	s++; sp->sp_max = xatol(&s); | ||
| 40 | 	if (*s != ':') return -1; | ||
| 41 | |||
| 42 | 	s++; sp->sp_warn = xatol(&s); | ||
| 43 | 	if (*s != ':') return -1; | ||
| 44 | |||
| 45 | 	s++; sp->sp_inact = xatol(&s); | ||
| 46 | 	if (*s != ':') return -1; | ||
| 47 | |||
| 48 | 	s++; sp->sp_expire = xatol(&s); | ||
| 49 | 	if (*s != ':') return -1; | ||
| 50 | |||
| 51 | 	s++; sp->sp_flag = xatol(&s); | ||
| 52 | 	if (*s != '\n') return -1; | ||
| 53 | 	return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | static void cleanup(void *p) | ||
| 57 | { | ||
| 58 | 	fclose(p); | ||
| 59 | } | ||
| 60 | |||
| 61 | int getspnam_r(const char *name, struct spwd *sp, char *buf, size_t size, struct spwd **res) | ||
| 62 | { | ||
| 63 | 	char path[20+NAME_MAX]; | ||
| 64 | 	FILE *f = 0; | ||
| 65 | 	int rv = 0; | ||
| 66 | 	int fd; | ||
| 67 | 	size_t k, l = strlen(name); | ||
| 68 | 	int skip = 0; | ||
| 69 | 	int cs; | ||
| 70 | 	int orig_errno = errno; | ||
| 71 | |||
| 72 | 	*res = 0; | ||
| 73 | |||
| 74 | 	/* Disallow potentially-malicious user names */ | ||
| 75 | 	if (*name=='.' || strchr(name, '/') || !l) | ||
| 76 | 		return errno = EINVAL; | ||
| 77 | |||
| 78 | 	/* Buffer size must at least be able to hold name, plus some.. */ | ||
| 79 | 	if (size < l+100) | ||
| 80 | 		return errno = ERANGE; | ||
| 81 | |||
| 82 | 	/* Protect against truncation */ | ||
| 83 | 	if (snprintf(path, sizeof path, "/etc/tcb/%s/shadow", name) >= sizeof path) | ||
| 84 | 		return errno = EINVAL; | ||
| 85 | |||
| 86 | 	fd = open(path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC); | ||
| 87 | 	if (fd >= 0) { | ||
| 88 | 		struct stat st = { 0 }; | ||
| 89 | 		errno = EINVAL; | ||
| 90 | 		if (fstat(fd, &st) || !S_ISREG(st.st_mode) || !(f = fdopen(fd, "rb"))) { | ||
| 91 | 			pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 92 | 			close(fd); | ||
| 93 | 			pthread_setcancelstate(cs, 0); | ||
| 94 | 			return errno; | ||
| 95 | 		} | ||
| 96 | 	} else { | ||
| 97 | 		if (errno != ENOENT && errno != ENOTDIR) | ||
| 98 | 			return errno; | ||
| 99 | 		f = fopen("/etc/shadow", "rbe"); | ||
| 100 | 		if (!f) { | ||
| 101 | 			if (errno != ENOENT && errno != ENOTDIR) | ||
| 102 | 				return errno; | ||
| 103 | 			return 0; | ||
| 104 | 		} | ||
| 105 | 	} | ||
| 106 | |||
| 107 | 	pthread_cleanup_push(cleanup, f); | ||
| 108 | 	while (fgets(buf, size, f) && (k=strlen(buf))>0) { | ||
| 109 | 		if (skip || strncmp(name, buf, l) || buf[l]!=':') { | ||
| 110 | 			skip = buf[k-1] != '\n'; | ||
| 111 | 			continue; | ||
| 112 | 		} | ||
| 113 | 		if (buf[k-1] != '\n') { | ||
| 114 | 			rv = ERANGE; | ||
| 115 | 			break; | ||
| 116 | 		} | ||
| 117 | |||
| 118 | 		if (__parsespent(buf, sp) < 0) continue; | ||
| 119 | 		*res = sp; | ||
| 120 | 		break; | ||
| 121 | 	} | ||
| 122 | 	pthread_cleanup_pop(1); | ||
| 123 | 	errno = rv ? rv : orig_errno; | ||
| 124 | 	return rv; | ||
| 125 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/lckpwdf.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <shadow.h> | ||
| 2 | |||
| 3 | int lckpwdf() | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
| 7 | |||
| 8 | int ulckpwdf() | ||
| 9 | { | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/nscd.h created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | #ifndef NSCD_H | ||
| 2 | #define NSCD_H | ||
| 3 | |||
| 4 | #include <stdint.h> | ||
| 5 | |||
| 6 | #define NSCDVERSION 2 | ||
| 7 | #define GETPWBYNAME 0 | ||
| 8 | #define GETPWBYUID 1 | ||
| 9 | #define GETGRBYNAME 2 | ||
| 10 | #define GETGRBYGID 3 | ||
| 11 | #define GETINITGR 15 | ||
| 12 | |||
| 13 | #define REQVERSION 0 | ||
| 14 | #define REQTYPE 1 | ||
| 15 | #define REQKEYLEN 2 | ||
| 16 | #define REQ_LEN 3 | ||
| 17 | |||
| 18 | #define PWVERSION 0 | ||
| 19 | #define PWFOUND 1 | ||
| 20 | #define PWNAMELEN 2 | ||
| 21 | #define PWPASSWDLEN 3 | ||
| 22 | #define PWUID 4 | ||
| 23 | #define PWGID 5 | ||
| 24 | #define PWGECOSLEN 6 | ||
| 25 | #define PWDIRLEN 7 | ||
| 26 | #define PWSHELLLEN 8 | ||
| 27 | #define PW_LEN 9 | ||
| 28 | |||
| 29 | #define GRVERSION 0 | ||
| 30 | #define GRFOUND 1 | ||
| 31 | #define GRNAMELEN 2 | ||
| 32 | #define GRPASSWDLEN 3 | ||
| 33 | #define GRGID 4 | ||
| 34 | #define GRMEMCNT 5 | ||
| 35 | #define GR_LEN 6 | ||
| 36 | |||
| 37 | #define INITGRVERSION 0 | ||
| 38 | #define INITGRFOUND 1 | ||
| 39 | #define INITGRNGRPS 2 | ||
| 40 | #define INITGR_LEN 3 | ||
| 41 | |||
| 42 | hidden FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap); | ||
| 43 | |||
| 44 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/nscd_query.c created+107| ... | @@ -0,0 +1,107 @@ | ||
| 1 | #include <sys/socket.h> | ||
| 2 | #include <byteswap.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <limits.h> | ||
| 8 | #include "nscd.h" | ||
| 9 | |||
| 10 | static const struct { | ||
| 11 | 	short sun_family; | ||
| 12 | 	char sun_path[21]; | ||
| 13 | } addr = { | ||
| 14 | 	AF_UNIX, | ||
| 15 | 	"/var/run/nscd/socket" | ||
| 16 | }; | ||
| 17 | |||
| 18 | FILE *__nscd_query(int32_t req, const char *key, int32_t *buf, size_t len, int *swap) | ||
| 19 | { | ||
| 20 | 	size_t i; | ||
| 21 | 	int fd; | ||
| 22 | 	FILE *f = 0; | ||
| 23 | 	int32_t req_buf[REQ_LEN] = { | ||
| 24 | 		NSCDVERSION, | ||
| 25 | 		req, | ||
| 26 | 		strnlen(key,LOGIN_NAME_MAX)+1 | ||
| 27 | 	}; | ||
| 28 | 	struct msghdr msg = { | ||
| 29 | 		.msg_iov = (struct iovec[]){ | ||
| 30 | 			{&req_buf, sizeof(req_buf)}, | ||
| 31 | 			{(char*)key, strlen(key)+1} | ||
| 32 | 		}, | ||
| 33 | 		.msg_iovlen = 2 | ||
| 34 | 	}; | ||
| 35 | 	int errno_save = errno; | ||
| 36 | |||
| 37 | 	*swap = 0; | ||
| 38 | retry: | ||
| 39 | 	memset(buf, 0, len); | ||
| 40 | 	buf[0] = NSCDVERSION; | ||
| 41 | |||
| 42 | 	fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0); | ||
| 43 | 	if (fd < 0) return NULL; | ||
| 44 | |||
| 45 | 	if(!(f = fdopen(fd, "r"))) { | ||
| 46 | 		close(fd); | ||
| 47 | 		return 0; | ||
| 48 | 	} | ||
| 49 | |||
| 50 | 	if (req_buf[2] > LOGIN_NAME_MAX) | ||
| 51 | 		return f; | ||
| 52 | |||
| 53 | 	if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) < 0) { | ||
| 54 | 		/* If there isn't a running nscd we simulate a "not found" | ||
| 55 | 		 * result and the caller is responsible for calling | ||
| 56 | 		 * fclose on the (unconnected) socket. The value of | ||
| 57 | 		 * errno must be left unchanged in this case. */ | ||
| 58 | 		if (errno == EACCES || errno == ECONNREFUSED || errno == ENOENT) { | ||
| 59 | 			errno = errno_save; | ||
| 60 | 			return f; | ||
| 61 | 		} | ||
| 62 | 		goto error; | ||
| 63 | 	} | ||
| 64 | |||
| 65 | 	if (sendmsg(fd, &msg, MSG_NOSIGNAL) < 0) | ||
| 66 | 		goto error; | ||
| 67 | |||
| 68 | 	if (!fread(buf, len, 1, f)) { | ||
| 69 | 		/* If the VERSION entry mismatches nscd will disconnect. The | ||
| 70 | 		 * most likely cause is that the endianness mismatched. So, we | ||
| 71 | 		 * byteswap and try once more. (if we already swapped, just | ||
| 72 | 		 * fail out) | ||
| 73 | 		 */ | ||
| 74 | 		if (ferror(f)) goto error; | ||
| 75 | 		if (!*swap) { | ||
| 76 | 			fclose(f); | ||
| 77 | 			for (i = 0; i < sizeof(req_buf)/sizeof(req_buf[0]); i++) { | ||
| 78 | 				req_buf[i] = bswap_32(req_buf[i]); | ||
| 79 | 			} | ||
| 80 | 			*swap = 1; | ||
| 81 | 			goto retry; | ||
| 82 | 		} else { | ||
| 83 | 			errno = EIO; | ||
| 84 | 			goto error; | ||
| 85 | 		} | ||
| 86 | 	} | ||
| 87 | |||
| 88 | 	if (*swap) { | ||
| 89 | 		for (i = 0; i < len/sizeof(buf[0]); i++) { | ||
| 90 | 			buf[i] = bswap_32(buf[i]); | ||
| 91 | 		} | ||
| 92 | 	} | ||
| 93 | |||
| 94 | 	/* The first entry in every nscd response is the version number. This | ||
| 95 | 	 * really shouldn't happen, and is evidence of some form of malformed | ||
| 96 | 	 * response. | ||
| 97 | 	 */ | ||
| 98 | 	if(buf[0] != NSCDVERSION) { | ||
| 99 | 		errno = EIO; | ||
| 100 | 		goto error; | ||
| 101 | 	} | ||
| 102 | |||
| 103 | 	return f; | ||
| 104 | error: | ||
| 105 | 	fclose(f); | ||
| 106 | 	return 0; | ||
| 107 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/putgrent.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <grp.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | int putgrent(const struct group *gr, FILE *f) | ||
| 6 | { | ||
| 7 | 	int r; | ||
| 8 | 	size_t i; | ||
| 9 | 	flockfile(f); | ||
| 10 | 	if ((r = fprintf(f, "%s:%s:%u:", gr->gr_name, gr->gr_passwd, gr->gr_gid))<0) goto done; | ||
| 11 | 	if (gr->gr_mem) for (i=0; gr->gr_mem[i]; i++) | ||
| 12 | 		if ((r = fprintf(f, "%s%s", i?",":"", gr->gr_mem[i]))<0) goto done; | ||
| 13 | 	r = fputc('\n', f); | ||
| 14 | done: | ||
| 15 | 	funlockfile(f); | ||
| 16 | 	return r<0 ? -1 : 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/putpwent.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <pwd.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | int putpwent(const struct passwd *pw, FILE *f) | ||
| 6 | { | ||
| 7 | 	return fprintf(f, "%s:%s:%u:%u:%s:%s:%s\n", | ||
| 8 | 		pw->pw_name, pw->pw_passwd, pw->pw_uid, pw->pw_gid, | ||
| 9 | 		pw->pw_gecos, pw->pw_dir, pw->pw_shell)<0 ? -1 : 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/putspent.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <shadow.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | #define NUM(n) ((n) == -1 ? 0 : -1), ((n) == -1 ? 0 : (n)) | ||
| 5 | #define STR(s) ((s) ? (s) : "") | ||
| 6 | |||
| 7 | int putspent(const struct spwd *sp, FILE *f) | ||
| 8 | { | ||
| 9 | 	return fprintf(f, "%s:%s:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*ld:%.*lu\n", | ||
| 10 | 		STR(sp->sp_namp), STR(sp->sp_pwdp), NUM(sp->sp_lstchg), | ||
| 11 | 		NUM(sp->sp_min), NUM(sp->sp_max), NUM(sp->sp_warn), | ||
| 12 | 		NUM(sp->sp_inact), NUM(sp->sp_expire), NUM(sp->sp_flag)) < 0 ? -1 : 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/passwd/pwf.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <pwd.h> | ||
| 2 | #include <grp.h> | ||
| 3 | #include <shadow.h> | ||
| 4 | #include <stdio.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include <string.h> | ||
| 9 | #include <limits.h> | ||
| 10 | |||
| 11 | hidden int __getpwent_a(FILE *f, struct passwd *pw, char **line, size_t *size, struct passwd **res); | ||
| 12 | hidden int __getpw_a(const char *name, uid_t uid, struct passwd *pw, char **buf, size_t *size, struct passwd **res); | ||
| 13 | hidden int __getgrent_a(FILE *f, struct group *gr, char **line, size_t *size, char ***mem, size_t *nmem, struct group **res); | ||
| 14 | hidden int __getgr_a(const char *name, gid_t gid, struct group *gr, char **buf, size_t *size, char ***mem, size_t *nmem, struct group **res); | ||
| 15 | hidden int __parsespent(char *s, struct spwd *sp); | ||
lib/libc/wasi/libc-top-half/musl/src/prng/__rand48_step.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include "rand48.h" | ||
| 3 | |||
| 4 | uint64_t __rand48_step(unsigned short *xi, unsigned short *lc) | ||
| 5 | { | ||
| 6 | 	uint64_t a, x; | ||
| 7 | 	x = xi[0] | xi[1]+0U<<16 | xi[2]+0ULL<<32; | ||
| 8 | 	a = lc[0] | lc[1]+0U<<16 | lc[2]+0ULL<<32; | ||
| 9 | 	x = a*x + lc[3]; | ||
| 10 | 	xi[0] = x; | ||
| 11 | 	xi[1] = x>>16; | ||
| 12 | 	xi[2] = x>>32; | ||
| 13 | 	return x & 0xffffffffffffull; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/__seed48.c created+3| ... | @@ -0,0 +1,3 @@ | ||
| 1 | #include "rand48.h" | ||
| 2 | |||
| 3 | unsigned short __seed48[7] = { 0, 0, 0, 0xe66d, 0xdeec, 0x5, 0xb }; | ||
lib/libc/wasi/libc-top-half/musl/src/prng/drand48.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <inttypes.h> | ||
| 3 | #include "rand48.h" | ||
| 4 | |||
| 5 | double erand48(unsigned short s[3]) | ||
| 6 | { | ||
| 7 | 	union { | ||
| 8 | 		uint64_t u; | ||
| 9 | 		double f; | ||
| 10 | 	} x = { 0x3ff0000000000000ULL | __rand48_step(s, __seed48+3)<<4 }; | ||
| 11 | 	return x.f - 1.0; | ||
| 12 | } | ||
| 13 | |||
| 14 | double drand48(void) | ||
| 15 | { | ||
| 16 | 	return erand48(__seed48); | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/lcong48.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include "rand48.h" | ||
| 4 | |||
| 5 | void lcong48(unsigned short p[7]) | ||
| 6 | { | ||
| 7 | 	memcpy(__seed48, p, sizeof __seed48); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/lrand48.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <inttypes.h> | ||
| 3 | #include "rand48.h" | ||
| 4 | |||
| 5 | long nrand48(unsigned short s[3]) | ||
| 6 | { | ||
| 7 | 	return __rand48_step(s, __seed48+3) >> 17; | ||
| 8 | } | ||
| 9 | |||
| 10 | long lrand48(void) | ||
| 11 | { | ||
| 12 | 	return nrand48(__seed48); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/mrand48.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <inttypes.h> | ||
| 3 | #include "rand48.h" | ||
| 4 | |||
| 5 | long jrand48(unsigned short s[3]) | ||
| 6 | { | ||
| 7 | 	return (int32_t)(__rand48_step(s, __seed48+3) >> 16); | ||
| 8 | } | ||
| 9 | |||
| 10 | long mrand48(void) | ||
| 11 | { | ||
| 12 | 	return jrand48(__seed48); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/rand.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | static uint64_t seed; | ||
| 5 | |||
| 6 | void srand(unsigned s) | ||
| 7 | { | ||
| 8 | 	seed = s-1; | ||
| 9 | } | ||
| 10 | |||
| 11 | int rand(void) | ||
| 12 | { | ||
| 13 | 	seed = 6364136223846793005ULL*seed + 1; | ||
| 14 | 	return seed>>33; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/rand48.h created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <features.h> | ||
| 3 | |||
| 4 | hidden uint64_t __rand48_step(unsigned short *xi, unsigned short *lc); | ||
| 5 | extern hidden unsigned short __seed48[7]; | ||
lib/libc/wasi/libc-top-half/musl/src/prng/rand_r.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | static unsigned temper(unsigned x) | ||
| 4 | { | ||
| 5 | 	x ^= x>>11; | ||
| 6 | 	x ^= x<<7 & 0x9D2C5680; | ||
| 7 | 	x ^= x<<15 & 0xEFC60000; | ||
| 8 | 	x ^= x>>18; | ||
| 9 | 	return x; | ||
| 10 | } | ||
| 11 | |||
| 12 | int rand_r(unsigned *seed) | ||
| 13 | { | ||
| 14 | 	return temper(*seed = *seed * 1103515245 + 12345)/2; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/random.c created+126| ... | @@ -0,0 +1,126 @@ | ||
| 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 | #ifdef __wasilibc_unmodified_upstream | ||
| 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/prng/seed48.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include "rand48.h" | ||
| 4 | |||
| 5 | unsigned short *seed48(unsigned short *s) | ||
| 6 | { | ||
| 7 | 	static unsigned short p[3]; | ||
| 8 | 	memcpy(p, __seed48, sizeof p); | ||
| 9 | 	memcpy(__seed48, s, sizeof p); | ||
| 10 | 	return p; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/prng/srand48.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | void srand48(long seed) | ||
| 4 | { | ||
| 5 | 	seed48((unsigned short [3]){ 0x330e, seed, seed>>16 }); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/_Fork.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "libc.h" | ||
| 5 | #include "lock.h" | ||
| 6 | #include "pthread_impl.h" | ||
| 7 | #include "aio_impl.h" | ||
| 8 | |||
| 9 | static void dummy(int x) { } | ||
| 10 | weak_alias(dummy, __aio_atfork); | ||
| 11 | |||
| 12 | pid_t _Fork(void) | ||
| 13 | { | ||
| 14 | 	pid_t ret; | ||
| 15 | 	sigset_t set; | ||
| 16 | 	__block_all_sigs(&set); | ||
| 17 | 	__aio_atfork(-1); | ||
| 18 | 	LOCK(__abort_lock); | ||
| 19 | #ifdef SYS_fork | ||
| 20 | 	ret = __syscall(SYS_fork); | ||
| 21 | #else | ||
| 22 | 	ret = __syscall(SYS_clone, SIGCHLD, 0); | ||
| 23 | #endif | ||
| 24 | 	if (!ret) { | ||
| 25 | 		pthread_t self = __pthread_self(); | ||
| 26 | 		self->tid = __syscall(SYS_gettid); | ||
| 27 | 		self->robust_list.off = 0; | ||
| 28 | 		self->robust_list.pending = 0; | ||
| 29 | 		self->next = self->prev = self; | ||
| 30 | 		__thread_list_lock = 0; | ||
| 31 | 		libc.threads_minus_1 = 0; | ||
| 32 | 		if (libc.need_locks) libc.need_locks = -1; | ||
| 33 | 	} | ||
| 34 | 	UNLOCK(__abort_lock); | ||
| 35 | 	__aio_atfork(!ret); | ||
| 36 | 	__restore_sigs(&set); | ||
| 37 | 	return __syscall_ret(ret); | ||
| 38 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/arm/vfork.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .syntax unified | ||
| 2 | .global vfork | ||
| 3 | .type vfork,%function | ||
| 4 | vfork: | ||
| 5 | 	mov ip, r7 | ||
| 6 | 	mov r7, 190 | ||
| 7 | 	svc 0 | ||
| 8 | 	mov r7, ip | ||
| 9 | 	.hidden __syscall_ret | ||
| 10 | 	b __syscall_ret | ||
lib/libc/wasi/libc-top-half/musl/src/process/execl.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int execl(const char *path, const char *argv0, ...) | ||
| 5 | { | ||
| 6 | 	int argc; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, argv0); | ||
| 9 | 	for (argc=1; va_arg(ap, const char *); argc++); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	{ | ||
| 12 | 		int i; | ||
| 13 | 		char *argv[argc+1]; | ||
| 14 | 		va_start(ap, argv0); | ||
| 15 | 		argv[0] = (char *)argv0; | ||
| 16 | 		for (i=1; i<argc; i++) | ||
| 17 | 			argv[i] = va_arg(ap, char *); | ||
| 18 | 		argv[i] = NULL; | ||
| 19 | 		va_end(ap); | ||
| 20 | 		return execv(path, argv); | ||
| 21 | 	} | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/execle.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int execle(const char *path, const char *argv0, ...) | ||
| 5 | { | ||
| 6 | 	int argc; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, argv0); | ||
| 9 | 	for (argc=1; va_arg(ap, const char *); argc++); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	{ | ||
| 12 | 		int i; | ||
| 13 | 		char *argv[argc+1]; | ||
| 14 | 		char **envp; | ||
| 15 | 		va_start(ap, argv0); | ||
| 16 | 		argv[0] = (char *)argv0; | ||
| 17 | 		for (i=1; i<=argc; i++) | ||
| 18 | 			argv[i] = va_arg(ap, char *); | ||
| 19 | 		envp = va_arg(ap, char **); | ||
| 20 | 		va_end(ap); | ||
| 21 | 		return execve(path, argv, envp); | ||
| 22 | 	} | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/execlp.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int execlp(const char *file, const char *argv0, ...) | ||
| 5 | { | ||
| 6 | 	int argc; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, argv0); | ||
| 9 | 	for (argc=1; va_arg(ap, const char *); argc++); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	{ | ||
| 12 | 		int i; | ||
| 13 | 		char *argv[argc+1]; | ||
| 14 | 		va_start(ap, argv0); | ||
| 15 | 		argv[0] = (char *)argv0; | ||
| 16 | 		for (i=1; i<argc; i++) | ||
| 17 | 			argv[i] = va_arg(ap, char *); | ||
| 18 | 		argv[i] = NULL; | ||
| 19 | 		va_end(ap); | ||
| 20 | 		return execvp(file, argv); | ||
| 21 | 	} | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/execv.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | extern char **__environ; | ||
| 4 | |||
| 5 | int execv(const char *path, char *const argv[]) | ||
| 6 | { | ||
| 7 | 	return execve(path, argv, __environ); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/execve.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int execve(const char *path, char *const argv[], char *const envp[]) | ||
| 5 | { | ||
| 6 | 	/* do we need to use environ if envp is null? */ | ||
| 7 | 	return syscall(SYS_execve, path, argv, envp); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/execvp.c created+60| ... | @@ -0,0 +1,60 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <limits.h> | ||
| 6 | |||
| 7 | extern char **__environ; | ||
| 8 | |||
| 9 | int __execvpe(const char *file, char *const argv[], char *const envp[]) | ||
| 10 | { | ||
| 11 | 	const char *p, *z, *path = getenv("PATH"); | ||
| 12 | 	size_t l, k; | ||
| 13 | 	int seen_eacces = 0; | ||
| 14 | |||
| 15 | 	errno = ENOENT; | ||
| 16 | 	if (!*file) return -1; | ||
| 17 | |||
| 18 | 	if (strchr(file, '/')) | ||
| 19 | 		return execve(file, argv, envp); | ||
| 20 | |||
| 21 | 	if (!path) path = "/usr/local/bin:/bin:/usr/bin"; | ||
| 22 | 	k = strnlen(file, NAME_MAX+1); | ||
| 23 | 	if (k > NAME_MAX) { | ||
| 24 | 		errno = ENAMETOOLONG; | ||
| 25 | 		return -1; | ||
| 26 | 	} | ||
| 27 | 	l = strnlen(path, PATH_MAX-1)+1; | ||
| 28 | |||
| 29 | 	for(p=path; ; p=z) { | ||
| 30 | 		char b[l+k+1]; | ||
| 31 | 		z = __strchrnul(p, ':'); | ||
| 32 | 		if (z-p >= l) { | ||
| 33 | 			if (!*z++) break; | ||
| 34 | 			continue; | ||
| 35 | 		} | ||
| 36 | 		memcpy(b, p, z-p); | ||
| 37 | 		b[z-p] = '/'; | ||
| 38 | 		memcpy(b+(z-p)+(z>p), file, k+1); | ||
| 39 | 		execve(b, argv, envp); | ||
| 40 | 		switch (errno) { | ||
| 41 | 		case EACCES: | ||
| 42 | 			seen_eacces = 1; | ||
| 43 | 		case ENOENT: | ||
| 44 | 		case ENOTDIR: | ||
| 45 | 			break; | ||
| 46 | 		default: | ||
| 47 | 			return -1; | ||
| 48 | 		} | ||
| 49 | 		if (!*z++) break; | ||
| 50 | 	} | ||
| 51 | 	if (seen_eacces) errno = EACCES; | ||
| 52 | 	return -1; | ||
| 53 | } | ||
| 54 | |||
| 55 | int execvp(const char *file, char *const argv[]) | ||
| 56 | { | ||
| 57 | 	return __execvpe(file, argv, __environ); | ||
| 58 | } | ||
| 59 | |||
| 60 | weak_alias(__execvpe, execvpe); | ||
lib/libc/wasi/libc-top-half/musl/src/process/fdop.h created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define FDOP_CLOSE 1 | ||
| 2 | #define FDOP_DUP2 2 | ||
| 3 | #define FDOP_OPEN 3 | ||
| 4 | #define FDOP_CHDIR 4 | ||
| 5 | #define FDOP_FCHDIR 5 | ||
| 6 | |||
| 7 | struct fdop { | ||
| 8 | 	struct fdop *next, *prev; | ||
| 9 | 	int cmd, fd, srcfd, oflag; | ||
| 10 | 	mode_t mode; | ||
| 11 | 	char path[]; | ||
| 12 | }; | ||
lib/libc/wasi/libc-top-half/musl/src/process/fexecve.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int fexecve(int fd, char *const argv[], char *const envp[]) | ||
| 8 | { | ||
| 9 | 	int r = __syscall(SYS_execveat, fd, "", argv, envp, AT_EMPTY_PATH); | ||
| 10 | 	if (r != -ENOSYS) return __syscall_ret(r); | ||
| 11 | 	char buf[15 + 3*sizeof(int)]; | ||
| 12 | 	__procfdname(buf, fd); | ||
| 13 | 	execve(buf, argv, envp); | ||
| 14 | 	if (errno == ENOENT) errno = EBADF; | ||
| 15 | 	return -1; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/fork.c created+86| ... | @@ -0,0 +1,86 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "libc.h" | ||
| 4 | #include "lock.h" | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | #include "fork_impl.h" | ||
| 7 | |||
| 8 | static volatile int *const dummy_lockptr = 0; | ||
| 9 | |||
| 10 | weak_alias(dummy_lockptr, __at_quick_exit_lockptr); | ||
| 11 | weak_alias(dummy_lockptr, __atexit_lockptr); | ||
| 12 | weak_alias(dummy_lockptr, __dlerror_lockptr); | ||
| 13 | weak_alias(dummy_lockptr, __gettext_lockptr); | ||
| 14 | weak_alias(dummy_lockptr, __locale_lockptr); | ||
| 15 | weak_alias(dummy_lockptr, __random_lockptr); | ||
| 16 | weak_alias(dummy_lockptr, __sem_open_lockptr); | ||
| 17 | weak_alias(dummy_lockptr, __stdio_ofl_lockptr); | ||
| 18 | weak_alias(dummy_lockptr, __syslog_lockptr); | ||
| 19 | weak_alias(dummy_lockptr, __timezone_lockptr); | ||
| 20 | weak_alias(dummy_lockptr, __bump_lockptr); | ||
| 21 | |||
| 22 | weak_alias(dummy_lockptr, __vmlock_lockptr); | ||
| 23 | |||
| 24 | static volatile int *const *const atfork_locks[] = { | ||
| 25 | 	&__at_quick_exit_lockptr, | ||
| 26 | 	&__atexit_lockptr, | ||
| 27 | 	&__dlerror_lockptr, | ||
| 28 | 	&__gettext_lockptr, | ||
| 29 | 	&__locale_lockptr, | ||
| 30 | 	&__random_lockptr, | ||
| 31 | 	&__sem_open_lockptr, | ||
| 32 | 	&__stdio_ofl_lockptr, | ||
| 33 | 	&__syslog_lockptr, | ||
| 34 | 	&__timezone_lockptr, | ||
| 35 | 	&__bump_lockptr, | ||
| 36 | }; | ||
| 37 | |||
| 38 | static void dummy(int x) { } | ||
| 39 | weak_alias(dummy, __fork_handler); | ||
| 40 | weak_alias(dummy, __malloc_atfork); | ||
| 41 | weak_alias(dummy, __ldso_atfork); | ||
| 42 | |||
| 43 | static void dummy_0(void) { } | ||
| 44 | weak_alias(dummy_0, __tl_lock); | ||
| 45 | weak_alias(dummy_0, __tl_unlock); | ||
| 46 | |||
| 47 | pid_t fork(void) | ||
| 48 | { | ||
| 49 | 	sigset_t set; | ||
| 50 | 	__fork_handler(-1); | ||
| 51 | 	__block_app_sigs(&set); | ||
| 52 | 	int need_locks = libc.need_locks > 0; | ||
| 53 | 	if (need_locks) { | ||
| 54 | 		__ldso_atfork(-1); | ||
| 55 | 		__inhibit_ptc(); | ||
| 56 | 		for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++) | ||
| 57 | 			if (*atfork_locks[i]) LOCK(*atfork_locks[i]); | ||
| 58 | 		__malloc_atfork(-1); | ||
| 59 | 		__tl_lock(); | ||
| 60 | 	} | ||
| 61 | 	pthread_t self=__pthread_self(), next=self->next; | ||
| 62 | 	pid_t ret = _Fork(); | ||
| 63 | 	int errno_save = errno; | ||
| 64 | 	if (need_locks) { | ||
| 65 | 		if (!ret) { | ||
| 66 | 			for (pthread_t td=next; td!=self; td=td->next) | ||
| 67 | 				td->tid = -1; | ||
| 68 | 			if (__vmlock_lockptr) { | ||
| 69 | 				__vmlock_lockptr[0] = 0; | ||
| 70 | 				__vmlock_lockptr[1] = 0; | ||
| 71 | 			} | ||
| 72 | 		} | ||
| 73 | 		__tl_unlock(); | ||
| 74 | 		__malloc_atfork(!ret); | ||
| 75 | 		for (int i=0; i<sizeof atfork_locks/sizeof *atfork_locks; i++) | ||
| 76 | 			if (*atfork_locks[i]) | ||
| 77 | 				if (ret) UNLOCK(*atfork_locks[i]); | ||
| 78 | 				else **atfork_locks[i] = 0; | ||
| 79 | 		__release_ptc(); | ||
| 80 | 		__ldso_atfork(!ret); | ||
| 81 | 	} | ||
| 82 | 	__restore_sigs(&set); | ||
| 83 | 	__fork_handler(!ret); | ||
| 84 | 	if (ret<0) errno = errno_save; | ||
| 85 | 	return ret; | ||
| 86 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/i386/vfork.s created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | .global vfork | ||
| 2 | .type vfork,@function | ||
| 3 | vfork: | ||
| 4 | 	pop %edx | ||
| 5 | 	mov $190,%eax | ||
| 6 | 	int $128 | ||
| 7 | 	push %edx | ||
| 8 | 	push %eax | ||
| 9 | 	.hidden __syscall_ret | ||
| 10 | 	call __syscall_ret | ||
| 11 | 	pop %edx | ||
| 12 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn.c created+214| ... | @@ -0,0 +1,214 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <spawn.h> | ||
| 3 | #include <sched.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <signal.h> | ||
| 6 | #include <fcntl.h> | ||
| 7 | #include <sys/wait.h> | ||
| 8 | #include "syscall.h" | ||
| 9 | #include "lock.h" | ||
| 10 | #include "pthread_impl.h" | ||
| 11 | #include "fdop.h" | ||
| 12 | |||
| 13 | struct args { | ||
| 14 | 	int p[2]; | ||
| 15 | 	sigset_t oldmask; | ||
| 16 | 	const char *path; | ||
| 17 | 	const posix_spawn_file_actions_t *fa; | ||
| 18 | 	const posix_spawnattr_t *restrict attr; | ||
| 19 | 	char *const *argv, *const *envp; | ||
| 20 | }; | ||
| 21 | |||
| 22 | static int __sys_dup2(int old, int new) | ||
| 23 | { | ||
| 24 | #ifdef SYS_dup2 | ||
| 25 | 	return __syscall(SYS_dup2, old, new); | ||
| 26 | #else | ||
| 27 | 	return __syscall(SYS_dup3, old, new, 0); | ||
| 28 | #endif | ||
| 29 | } | ||
| 30 | |||
| 31 | static int child(void *args_vp) | ||
| 32 | { | ||
| 33 | 	int i, ret; | ||
| 34 | 	struct sigaction sa = {0}; | ||
| 35 | 	struct args *args = args_vp; | ||
| 36 | 	int p = args->p[1]; | ||
| 37 | 	const posix_spawn_file_actions_t *fa = args->fa; | ||
| 38 | 	const posix_spawnattr_t *restrict attr = args->attr; | ||
| 39 | 	sigset_t hset; | ||
| 40 | |||
| 41 | 	close(args->p[0]); | ||
| 42 | |||
| 43 | 	/* All signal dispositions must be either SIG_DFL or SIG_IGN | ||
| 44 | 	 * before signals are unblocked. Otherwise a signal handler | ||
| 45 | 	 * from the parent might get run in the child while sharing | ||
| 46 | 	 * memory, with unpredictable and dangerous results. To | ||
| 47 | 	 * reduce overhead, sigaction has tracked for us which signals | ||
| 48 | 	 * potentially have a signal handler. */ | ||
| 49 | 	__get_handler_set(&hset); | ||
| 50 | 	for (i=1; i<_NSIG; i++) { | ||
| 51 | 		if ((attr->__flags & POSIX_SPAWN_SETSIGDEF) | ||
| 52 | 		 && sigismember(&attr->__def, i)) { | ||
| 53 | 			sa.sa_handler = SIG_DFL; | ||
| 54 | 		} else if (sigismember(&hset, i)) { | ||
| 55 | 			if (i-32<3U) { | ||
| 56 | 				sa.sa_handler = SIG_IGN; | ||
| 57 | 			} else { | ||
| 58 | 				__libc_sigaction(i, 0, &sa); | ||
| 59 | 				if (sa.sa_handler==SIG_IGN) continue; | ||
| 60 | 				sa.sa_handler = SIG_DFL; | ||
| 61 | 			} | ||
| 62 | 		} else { | ||
| 63 | 			continue; | ||
| 64 | 		} | ||
| 65 | 		__libc_sigaction(i, &sa, 0); | ||
| 66 | 	} | ||
| 67 | |||
| 68 | 	if (attr->__flags & POSIX_SPAWN_SETSID) | ||
| 69 | 		if ((ret=__syscall(SYS_setsid)) < 0) | ||
| 70 | 			goto fail; | ||
| 71 | |||
| 72 | 	if (attr->__flags & POSIX_SPAWN_SETPGROUP) | ||
| 73 | 		if ((ret=__syscall(SYS_setpgid, 0, attr->__pgrp))) | ||
| 74 | 			goto fail; | ||
| 75 | |||
| 76 | 	/* Use syscalls directly because the library functions attempt | ||
| 77 | 	 * to do a multi-threaded synchronized id-change, which would | ||
| 78 | 	 * trash the parent's state. */ | ||
| 79 | 	if (attr->__flags & POSIX_SPAWN_RESETIDS) | ||
| 80 | 		if ((ret=__syscall(SYS_setgid, __syscall(SYS_getgid))) || | ||
| 81 | 		 (ret=__syscall(SYS_setuid, __syscall(SYS_getuid))) ) | ||
| 82 | 			goto fail; | ||
| 83 | |||
| 84 | 	if (fa && fa->__actions) { | ||
| 85 | 		struct fdop *op; | ||
| 86 | 		int fd; | ||
| 87 | 		for (op = fa->__actions; op->next; op = op->next); | ||
| 88 | 		for (; op; op = op->prev) { | ||
| 89 | 			/* It's possible that a file operation would clobber | ||
| 90 | 			 * the pipe fd used for synchronizing with the | ||
| 91 | 			 * parent. To avoid that, we dup the pipe onto | ||
| 92 | 			 * an unoccupied fd. */ | ||
| 93 | 			if (op->fd == p) { | ||
| 94 | 				ret = __syscall(SYS_dup, p); | ||
| 95 | 				if (ret < 0) goto fail; | ||
| 96 | 				__syscall(SYS_close, p); | ||
| 97 | 				p = ret; | ||
| 98 | 			} | ||
| 99 | 			switch(op->cmd) { | ||
| 100 | 			case FDOP_CLOSE: | ||
| 101 | 				__syscall(SYS_close, op->fd); | ||
| 102 | 				break; | ||
| 103 | 			case FDOP_DUP2: | ||
| 104 | 				fd = op->srcfd; | ||
| 105 | 				if (fd == p) { | ||
| 106 | 					ret = -EBADF; | ||
| 107 | 					goto fail; | ||
| 108 | 				} | ||
| 109 | 				if (fd != op->fd) { | ||
| 110 | 					if ((ret=__sys_dup2(fd, op->fd))<0) | ||
| 111 | 						goto fail; | ||
| 112 | 				} else { | ||
| 113 | 					ret = __syscall(SYS_fcntl, fd, F_GETFD); | ||
| 114 | 					ret = __syscall(SYS_fcntl, fd, F_SETFD, | ||
| 115 | 					 ret & ~FD_CLOEXEC); | ||
| 116 | 					if (ret<0) | ||
| 117 | 						goto fail; | ||
| 118 | 				} | ||
| 119 | 				break; | ||
| 120 | 			case FDOP_OPEN: | ||
| 121 | 				fd = __sys_open(op->path, op->oflag, op->mode); | ||
| 122 | 				if ((ret=fd) < 0) goto fail; | ||
| 123 | 				if (fd != op->fd) { | ||
| 124 | 					if ((ret=__sys_dup2(fd, op->fd))<0) | ||
| 125 | 						goto fail; | ||
| 126 | 					__syscall(SYS_close, fd); | ||
| 127 | 				} | ||
| 128 | 				break; | ||
| 129 | 			case FDOP_CHDIR: | ||
| 130 | 				ret = __syscall(SYS_chdir, op->path); | ||
| 131 | 				if (ret<0) goto fail; | ||
| 132 | 				break; | ||
| 133 | 			case FDOP_FCHDIR: | ||
| 134 | 				ret = __syscall(SYS_fchdir, op->fd); | ||
| 135 | 				if (ret<0) goto fail; | ||
| 136 | 				break; | ||
| 137 | 			} | ||
| 138 | 		} | ||
| 139 | 	} | ||
| 140 | |||
| 141 | 	/* Close-on-exec flag may have been lost if we moved the pipe | ||
| 142 | 	 * to a different fd. We don't use F_DUPFD_CLOEXEC above because | ||
| 143 | 	 * it would fail on older kernels and atomicity is not needed -- | ||
| 144 | 	 * in this process there are no threads or signal handlers. */ | ||
| 145 | 	__syscall(SYS_fcntl, p, F_SETFD, FD_CLOEXEC); | ||
| 146 | |||
| 147 | 	pthread_sigmask(SIG_SETMASK, (attr->__flags & POSIX_SPAWN_SETSIGMASK) | ||
| 148 | 		? &attr->__mask : &args->oldmask, 0); | ||
| 149 | |||
| 150 | 	int (*exec)(const char *, char *const *, char *const *) = | ||
| 151 | 		attr->__fn ? (int (*)())attr->__fn : execve; | ||
| 152 | |||
| 153 | 	exec(args->path, args->argv, args->envp); | ||
| 154 | 	ret = -errno; | ||
| 155 | |||
| 156 | fail: | ||
| 157 | 	/* Since sizeof errno < PIPE_BUF, the write is atomic. */ | ||
| 158 | 	ret = -ret; | ||
| 159 | 	if (ret) while (__syscall(SYS_write, p, &ret, sizeof ret) < 0); | ||
| 160 | 	_exit(127); | ||
| 161 | } | ||
| 162 | |||
| 163 | |||
| 164 | int posix_spawn(pid_t *restrict res, const char *restrict path, | ||
| 165 | 	const posix_spawn_file_actions_t *fa, | ||
| 166 | 	const posix_spawnattr_t *restrict attr, | ||
| 167 | 	char *const argv[restrict], char *const envp[restrict]) | ||
| 168 | { | ||
| 169 | 	pid_t pid; | ||
| 170 | 	char stack[1024+PATH_MAX]; | ||
| 171 | 	int ec=0, cs; | ||
| 172 | 	struct args args; | ||
| 173 | |||
| 174 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 175 | |||
| 176 | 	args.path = path; | ||
| 177 | 	args.fa = fa; | ||
| 178 | 	args.attr = attr ? attr : &(const posix_spawnattr_t){0}; | ||
| 179 | 	args.argv = argv; | ||
| 180 | 	args.envp = envp; | ||
| 181 | 	pthread_sigmask(SIG_BLOCK, SIGALL_SET, &args.oldmask); | ||
| 182 | |||
| 183 | 	/* The lock guards both against seeing a SIGABRT disposition change | ||
| 184 | 	 * by abort and against leaking the pipe fd to fork-without-exec. */ | ||
| 185 | 	LOCK(__abort_lock); | ||
| 186 | |||
| 187 | 	if (pipe2(args.p, O_CLOEXEC)) { | ||
| 188 | 		UNLOCK(__abort_lock); | ||
| 189 | 		ec = errno; | ||
| 190 | 		goto fail; | ||
| 191 | 	} | ||
| 192 | |||
| 193 | 	pid = __clone(child, stack+sizeof stack, | ||
| 194 | 		CLONE_VM|CLONE_VFORK|SIGCHLD, &args); | ||
| 195 | 	close(args.p[1]); | ||
| 196 | 	UNLOCK(__abort_lock); | ||
| 197 | |||
| 198 | 	if (pid > 0) { | ||
| 199 | 		if (read(args.p[0], &ec, sizeof ec) != sizeof ec) ec = 0; | ||
| 200 | 		else waitpid(pid, &(int){0}, 0); | ||
| 201 | 	} else { | ||
| 202 | 		ec = -pid; | ||
| 203 | 	} | ||
| 204 | |||
| 205 | 	close(args.p[0]); | ||
| 206 | |||
| 207 | 	if (!ec && res) *res = pid; | ||
| 208 | |||
| 209 | fail: | ||
| 210 | 	pthread_sigmask(SIG_SETMASK, &args.oldmask, 0); | ||
| 211 | 	pthread_setcancelstate(cs, 0); | ||
| 212 | |||
| 213 | 	return ec; | ||
| 214 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addchdir.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "fdop.h" | ||
| 6 | |||
| 7 | int posix_spawn_file_actions_addchdir_np(posix_spawn_file_actions_t *restrict fa, const char *restrict path) | ||
| 8 | { | ||
| 9 | 	struct fdop *op = malloc(sizeof *op + strlen(path) + 1); | ||
| 10 | 	if (!op) return ENOMEM; | ||
| 11 | 	op->cmd = FDOP_CHDIR; | ||
| 12 | 	op->fd = -1; | ||
| 13 | 	strcpy(op->path, path); | ||
| 14 | 	if ((op->next = fa->__actions)) op->next->prev = op; | ||
| 15 | 	op->prev = 0; | ||
| 16 | 	fa->__actions = op; | ||
| 17 | 	return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addclose.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "fdop.h" | ||
| 5 | |||
| 6 | int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd) | ||
| 7 | { | ||
| 8 | 	struct fdop *op = malloc(sizeof *op); | ||
| 9 | 	if (!op) return ENOMEM; | ||
| 10 | 	op->cmd = FDOP_CLOSE; | ||
| 11 | 	op->fd = fd; | ||
| 12 | 	if ((op->next = fa->__actions)) op->next->prev = op; | ||
| 13 | 	op->prev = 0; | ||
| 14 | 	fa->__actions = op; | ||
| 15 | 	return 0; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_adddup2.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "fdop.h" | ||
| 5 | |||
| 6 | int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd) | ||
| 7 | { | ||
| 8 | 	struct fdop *op = malloc(sizeof *op); | ||
| 9 | 	if (!op) return ENOMEM; | ||
| 10 | 	op->cmd = FDOP_DUP2; | ||
| 11 | 	op->srcfd = srcfd; | ||
| 12 | 	op->fd = fd; | ||
| 13 | 	if ((op->next = fa->__actions)) op->next->prev = op; | ||
| 14 | 	op->prev = 0; | ||
| 15 | 	fa->__actions = op; | ||
| 16 | 	return 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addfchdir.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "fdop.h" | ||
| 6 | |||
| 7 | int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd) | ||
| 8 | { | ||
| 9 | 	struct fdop *op = malloc(sizeof *op); | ||
| 10 | 	if (!op) return ENOMEM; | ||
| 11 | 	op->cmd = FDOP_FCHDIR; | ||
| 12 | 	op->fd = fd; | ||
| 13 | 	if ((op->next = fa->__actions)) op->next->prev = op; | ||
| 14 | 	op->prev = 0; | ||
| 15 | 	fa->__actions = op; | ||
| 16 | 	return 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addopen.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "fdop.h" | ||
| 6 | |||
| 7 | int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode) | ||
| 8 | { | ||
| 9 | 	struct fdop *op = malloc(sizeof *op + strlen(path) + 1); | ||
| 10 | 	if (!op) return ENOMEM; | ||
| 11 | 	op->cmd = FDOP_OPEN; | ||
| 12 | 	op->fd = fd; | ||
| 13 | 	op->oflag = flags; | ||
| 14 | 	op->mode = mode; | ||
| 15 | 	strcpy(op->path, path); | ||
| 16 | 	if ((op->next = fa->__actions)) op->next->prev = op; | ||
| 17 | 	op->prev = 0; | ||
| 18 | 	fa->__actions = op; | ||
| 19 | 	return 0; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_destroy.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include "fdop.h" | ||
| 4 | |||
| 5 | int posix_spawn_file_actions_destroy(posix_spawn_file_actions_t *fa) | ||
| 6 | { | ||
| 7 | 	struct fdop *op = fa->__actions, *next; | ||
| 8 | 	while (op) { | ||
| 9 | 		next = op->next; | ||
| 10 | 		free(op); | ||
| 11 | 		op = next; | ||
| 12 | 	} | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawn_file_actions_init(posix_spawn_file_actions_t *fa) | ||
| 4 | { | ||
| 5 | 	fa->__actions = 0; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_destroy(posix_spawnattr_t *attr) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getflags.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_getflags(const posix_spawnattr_t *restrict attr, short *restrict flags) | ||
| 4 | { | ||
| 5 | 	*flags = attr->__flags; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getpgroup.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_getpgroup(const posix_spawnattr_t *restrict attr, pid_t *restrict pgrp) | ||
| 4 | { | ||
| 5 | 	*pgrp = attr->__pgrp; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getsigdefault.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_getsigdefault(const posix_spawnattr_t *restrict attr, sigset_t *restrict def) | ||
| 4 | { | ||
| 5 | 	*def = attr->__def; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_getsigmask.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_getsigmask(const posix_spawnattr_t *restrict attr, sigset_t *restrict mask) | ||
| 4 | { | ||
| 5 | 	*mask = attr->__mask; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_init(posix_spawnattr_t *attr) | ||
| 4 | { | ||
| 5 | 	*attr = (posix_spawnattr_t){ 0 }; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_sched.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <sched.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int posix_spawnattr_getschedparam(const posix_spawnattr_t *restrict attr, | ||
| 6 | 	struct sched_param *restrict schedparam) | ||
| 7 | { | ||
| 8 | 	return ENOSYS; | ||
| 9 | } | ||
| 10 | |||
| 11 | int posix_spawnattr_setschedparam(posix_spawnattr_t *restrict attr, | ||
| 12 | 	const struct sched_param *restrict schedparam) | ||
| 13 | { | ||
| 14 | 	return ENOSYS; | ||
| 15 | } | ||
| 16 | |||
| 17 | int posix_spawnattr_getschedpolicy(const posix_spawnattr_t *restrict attr, int *restrict policy) | ||
| 18 | { | ||
| 19 | 	return ENOSYS; | ||
| 20 | } | ||
| 21 | |||
| 22 | int posix_spawnattr_setschedpolicy(posix_spawnattr_t *attr, int policy) | ||
| 23 | { | ||
| 24 | 	return ENOSYS; | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setflags.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int posix_spawnattr_setflags(posix_spawnattr_t *attr, short flags) | ||
| 5 | { | ||
| 6 | 	const unsigned all_flags = | ||
| 7 | 		POSIX_SPAWN_RESETIDS | | ||
| 8 | 		POSIX_SPAWN_SETPGROUP | | ||
| 9 | 		POSIX_SPAWN_SETSIGDEF | | ||
| 10 | 		POSIX_SPAWN_SETSIGMASK | | ||
| 11 | 		POSIX_SPAWN_SETSCHEDPARAM | | ||
| 12 | 		POSIX_SPAWN_SETSCHEDULER | | ||
| 13 | 		POSIX_SPAWN_USEVFORK | | ||
| 14 | 		POSIX_SPAWN_SETSID; | ||
| 15 | 	if (flags & ~all_flags) return EINVAL; | ||
| 16 | 	attr->__flags = flags; | ||
| 17 | 	return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setpgroup.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_setpgroup(posix_spawnattr_t *attr, pid_t pgrp) | ||
| 4 | { | ||
| 5 | 	attr->__pgrp = pgrp; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setsigdefault.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_setsigdefault(posix_spawnattr_t *restrict attr, const sigset_t *restrict def) | ||
| 4 | { | ||
| 5 | 	attr->__def = *def; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnattr_setsigmask.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | |||
| 3 | int posix_spawnattr_setsigmask(posix_spawnattr_t *restrict attr, const sigset_t *restrict mask) | ||
| 4 | { | ||
| 5 | 	attr->__mask = *mask; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawnp.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <spawn.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | |||
| 4 | int posix_spawnp(pid_t *restrict res, const char *restrict file, | ||
| 5 | 	const posix_spawn_file_actions_t *fa, | ||
| 6 | 	const posix_spawnattr_t *restrict attr, | ||
| 7 | 	char *const argv[restrict], char *const envp[restrict]) | ||
| 8 | { | ||
| 9 | 	posix_spawnattr_t spawnp_attr = { 0 }; | ||
| 10 | 	if (attr) spawnp_attr = *attr; | ||
| 11 | 	spawnp_attr.__fn = (void *)__execvpe;	 | ||
| 12 | 	return posix_spawn(res, file, fa, &spawnp_attr, argv, envp); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/s390x/vfork.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | 	.global vfork | ||
| 2 | 	.type vfork,%function | ||
| 3 | vfork: | ||
| 4 | 	svc 190 | ||
| 5 | 	.hidden __syscall_ret | ||
| 6 | 	jg __syscall_ret | ||
lib/libc/wasi/libc-top-half/musl/src/process/sh/vfork.s created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | .global vfork | ||
| 2 | .type vfork,@function | ||
| 3 | vfork: | ||
| 4 | 	mov #95, r3 | ||
| 5 | 	add r3, r3 | ||
| 6 | |||
| 7 | 	trapa #31 | ||
| 8 | 	or r0, r0 | ||
| 9 | 	or r0, r0 | ||
| 10 | 	or r0, r0 | ||
| 11 | 	or r0, r0 | ||
| 12 | 	or r0, r0 | ||
| 13 | |||
| 14 | 	mov r0, r4 | ||
| 15 | 	mov.l 1f, r0 | ||
| 16 | 2:	braf r0 | ||
| 17 | 	 nop | ||
| 18 | 	.align 2 | ||
| 19 | 	.hidden __syscall_ret | ||
| 20 | 1:	.long __syscall_ret@PLT-(2b+4-.) | ||
lib/libc/wasi/libc-top-half/musl/src/process/system.c created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include <sys/wait.h> | ||
| 5 | #include <spawn.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include "pthread_impl.h" | ||
| 8 | |||
| 9 | extern char **__environ; | ||
| 10 | |||
| 11 | int system(const char *cmd) | ||
| 12 | { | ||
| 13 | 	pid_t pid; | ||
| 14 | 	sigset_t old, reset; | ||
| 15 | 	struct sigaction sa = { .sa_handler = SIG_IGN }, oldint, oldquit; | ||
| 16 | 	int status = -1, ret; | ||
| 17 | 	posix_spawnattr_t attr; | ||
| 18 | |||
| 19 | 	pthread_testcancel(); | ||
| 20 | |||
| 21 | 	if (!cmd) return 1; | ||
| 22 | |||
| 23 | 	sigaction(SIGINT, &sa, &oldint); | ||
| 24 | 	sigaction(SIGQUIT, &sa, &oldquit); | ||
| 25 | 	sigaddset(&sa.sa_mask, SIGCHLD); | ||
| 26 | 	sigprocmask(SIG_BLOCK, &sa.sa_mask, &old); | ||
| 27 | |||
| 28 | 	sigemptyset(&reset); | ||
| 29 | 	if (oldint.sa_handler != SIG_IGN) sigaddset(&reset, SIGINT); | ||
| 30 | 	if (oldquit.sa_handler != SIG_IGN) sigaddset(&reset, SIGQUIT); | ||
| 31 | 	posix_spawnattr_init(&attr); | ||
| 32 | 	posix_spawnattr_setsigmask(&attr, &old); | ||
| 33 | 	posix_spawnattr_setsigdefault(&attr, &reset); | ||
| 34 | 	posix_spawnattr_setflags(&attr, POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK); | ||
| 35 | 	ret = posix_spawn(&pid, "/bin/sh", 0, &attr, | ||
| 36 | 		(char *[]){"sh", "-c", (char *)cmd, 0}, __environ); | ||
| 37 | 	posix_spawnattr_destroy(&attr); | ||
| 38 | |||
| 39 | 	if (!ret) while (waitpid(pid, &status, 0)<0 && errno == EINTR); | ||
| 40 | 	sigaction(SIGINT, &oldint, NULL); | ||
| 41 | 	sigaction(SIGQUIT, &oldquit, NULL); | ||
| 42 | 	sigprocmask(SIG_SETMASK, &old, NULL); | ||
| 43 | |||
| 44 | 	if (ret) errno = ret; | ||
| 45 | 	return status; | ||
| 46 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/vfork.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | pid_t vfork(void) | ||
| 7 | { | ||
| 8 | 	/* vfork syscall cannot be made from C code */ | ||
| 9 | #ifdef SYS_fork | ||
| 10 | 	return syscall(SYS_fork); | ||
| 11 | #else | ||
| 12 | 	return syscall(SYS_clone, SIGCHLD, 0); | ||
| 13 | #endif | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/wait.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <sys/wait.h> | ||
| 2 | |||
| 3 | pid_t wait(int *status) | ||
| 4 | { | ||
| 5 | 	return waitpid((pid_t)-1, status, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/waitid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/wait.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int waitid(idtype_t type, id_t id, siginfo_t *info, int options) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_waitid, type, id, info, options, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/waitpid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/wait.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t waitpid(pid_t pid, int *status, int options) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_wait4, pid, status, options, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/process/x32/vfork.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .global vfork | ||
| 2 | .type vfork,@function | ||
| 3 | vfork: | ||
| 4 | 	pop %rdx | ||
| 5 | 	mov $0x4000003a,%eax /* SYS_vfork */ | ||
| 6 | 	syscall | ||
| 7 | 	push %rdx | ||
| 8 | 	mov %rax,%rdi | ||
| 9 | 	.hidden __syscall_ret | ||
| 10 | 	jmp __syscall_ret | ||
lib/libc/wasi/libc-top-half/musl/src/process/x86_64/vfork.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .global vfork | ||
| 2 | .type vfork,@function | ||
| 3 | vfork: | ||
| 4 | 	pop %rdx | ||
| 5 | 	mov $58,%eax | ||
| 6 | 	syscall | ||
| 7 | 	push %rdx | ||
| 8 | 	mov %rax,%rdi | ||
| 9 | 	.hidden __syscall_ret | ||
| 10 | 	jmp __syscall_ret | ||
lib/libc/wasi/libc-top-half/musl/src/regex/fnmatch.c created+321| ... | @@ -0,0 +1,321 @@ | ||
| 1 | /* | ||
| 2 | * An implementation of what I call the "Sea of Stars" algorithm for | ||
| 3 | * POSIX fnmatch(). The basic idea is that we factor the pattern into | ||
| 4 | * a head component (which we match first and can reject without ever | ||
| 5 | * measuring the length of the string), an optional tail component | ||
| 6 | * (which only exists if the pattern contains at least one star), and | ||
| 7 | * an optional "sea of stars", a set of star-separated components | ||
| 8 | * between the head and tail. After the head and tail matches have | ||
| 9 | * been removed from the input string, the components in the "sea of | ||
| 10 | * stars" are matched sequentially by searching for their first | ||
| 11 | * occurrence past the end of the previous match. | ||
| 12 | * | ||
| 13 | * - Rich Felker, April 2012 | ||
| 14 | */ | ||
| 15 | |||
| 16 | #include <string.h> | ||
| 17 | #include <fnmatch.h> | ||
| 18 | #include <stdlib.h> | ||
| 19 | #include <wchar.h> | ||
| 20 | #include <wctype.h> | ||
| 21 | #include "locale_impl.h" | ||
| 22 | |||
| 23 | #define END 0 | ||
| 24 | #define UNMATCHABLE -2 | ||
| 25 | #define BRACKET -3 | ||
| 26 | #define QUESTION -4 | ||
| 27 | #define STAR -5 | ||
| 28 | |||
| 29 | static int str_next(const char *str, size_t n, size_t *step) | ||
| 30 | { | ||
| 31 | 	if (!n) { | ||
| 32 | 		*step = 0; | ||
| 33 | 		return 0; | ||
| 34 | 	} | ||
| 35 | 	if (str[0] >= 128U) { | ||
| 36 | 		wchar_t wc; | ||
| 37 | 		int k = mbtowc(&wc, str, n); | ||
| 38 | 		if (k<0) { | ||
| 39 | 			*step = 1; | ||
| 40 | 			return -1; | ||
| 41 | 		} | ||
| 42 | 		*step = k; | ||
| 43 | 		return wc; | ||
| 44 | 	} | ||
| 45 | 	*step = 1; | ||
| 46 | 	return str[0]; | ||
| 47 | } | ||
| 48 | |||
| 49 | static int pat_next(const char *pat, size_t m, size_t *step, int flags) | ||
| 50 | { | ||
| 51 | 	int esc = 0; | ||
| 52 | 	if (!m || !*pat) { | ||
| 53 | 		*step = 0; | ||
| 54 | 		return END; | ||
| 55 | 	} | ||
| 56 | 	*step = 1; | ||
| 57 | 	if (pat[0]=='\\' && pat[1] && !(flags & FNM_NOESCAPE)) { | ||
| 58 | 		*step = 2; | ||
| 59 | 		pat++; | ||
| 60 | 		esc = 1; | ||
| 61 | 		goto escaped; | ||
| 62 | 	} | ||
| 63 | 	if (pat[0]=='[') { | ||
| 64 | 		size_t k = 1; | ||
| 65 | 		if (k<m) if (pat[k] == '^' || pat[k] == '!') k++; | ||
| 66 | 		if (k<m) if (pat[k] == ']') k++; | ||
| 67 | 		for (; k<m && pat[k] && pat[k]!=']'; k++) { | ||
| 68 | 			if (k+1<m && pat[k+1] && pat[k]=='[' && (pat[k+1]==':' || pat[k+1]=='.' || pat[k+1]=='=')) { | ||
| 69 | 				int z = pat[k+1]; | ||
| 70 | 				k+=2; | ||
| 71 | 				if (k<m && pat[k]) k++; | ||
| 72 | 				while (k<m && pat[k] && (pat[k-1]!=z || pat[k]!=']')) k++; | ||
| 73 | 				if (k==m || !pat[k]) break; | ||
| 74 | 			} | ||
| 75 | 		} | ||
| 76 | 		if (k==m || !pat[k]) { | ||
| 77 | 			*step = 1; | ||
| 78 | 			return '['; | ||
| 79 | 		} | ||
| 80 | 		*step = k+1; | ||
| 81 | 		return BRACKET; | ||
| 82 | 	} | ||
| 83 | 	if (pat[0] == '*') | ||
| 84 | 		return STAR; | ||
| 85 | 	if (pat[0] == '?') | ||
| 86 | 		return QUESTION; | ||
| 87 | escaped: | ||
| 88 | 	if (pat[0] >= 128U) { | ||
| 89 | 		wchar_t wc; | ||
| 90 | 		int k = mbtowc(&wc, pat, m); | ||
| 91 | 		if (k<0) { | ||
| 92 | 			*step = 0; | ||
| 93 | 			return UNMATCHABLE; | ||
| 94 | 		} | ||
| 95 | 		*step = k + esc; | ||
| 96 | 		return wc; | ||
| 97 | 	} | ||
| 98 | 	return pat[0]; | ||
| 99 | } | ||
| 100 | |||
| 101 | static int casefold(int k) | ||
| 102 | { | ||
| 103 | 	int c = towupper(k); | ||
| 104 | 	return c == k ? towlower(k) : c; | ||
| 105 | } | ||
| 106 | |||
| 107 | static int match_bracket(const char *p, int k, int kfold) | ||
| 108 | { | ||
| 109 | 	wchar_t wc; | ||
| 110 | 	int inv = 0; | ||
| 111 | 	p++; | ||
| 112 | 	if (*p=='^' || *p=='!') { | ||
| 113 | 		inv = 1; | ||
| 114 | 		p++; | ||
| 115 | 	} | ||
| 116 | 	if (*p==']') { | ||
| 117 | 		if (k==']') return !inv; | ||
| 118 | 		p++; | ||
| 119 | 	} else if (*p=='-') { | ||
| 120 | 		if (k=='-') return !inv; | ||
| 121 | 		p++; | ||
| 122 | 	} | ||
| 123 | 	wc = p[-1]; | ||
| 124 | 	for (; *p != ']'; p++) { | ||
| 125 | 		if (p[0]=='-' && p[1]!=']') { | ||
| 126 | 			wchar_t wc2; | ||
| 127 | 			int l = mbtowc(&wc2, p+1, 4); | ||
| 128 | 			if (l < 0) return 0; | ||
| 129 | 			if (wc <= wc2) | ||
| 130 | 				if ((unsigned)k-wc <= wc2-wc || | ||
| 131 | 				 (unsigned)kfold-wc <= wc2-wc) | ||
| 132 | 					return !inv; | ||
| 133 | 			p += l-1; | ||
| 134 | 			continue; | ||
| 135 | 		} | ||
| 136 | 		if (p[0]=='[' && (p[1]==':' || p[1]=='.' || p[1]=='=')) { | ||
| 137 | 			const char *p0 = p+2; | ||
| 138 | 			int z = p[1]; | ||
| 139 | 			p+=3; | ||
| 140 | 			while (p[-1]!=z || p[0]!=']') p++; | ||
| 141 | 			if (z == ':' && p-1-p0 < 16) { | ||
| 142 | 				char buf[16]; | ||
| 143 | 				memcpy(buf, p0, p-1-p0); | ||
| 144 | 				buf[p-1-p0] = 0; | ||
| 145 | 				if (iswctype(k, wctype(buf)) || | ||
| 146 | 				 iswctype(kfold, wctype(buf))) | ||
| 147 | 					return !inv; | ||
| 148 | 			} | ||
| 149 | 			continue; | ||
| 150 | 		} | ||
| 151 | 		if (*p < 128U) { | ||
| 152 | 			wc = (unsigned char)*p; | ||
| 153 | 		} else { | ||
| 154 | 			int l = mbtowc(&wc, p, 4); | ||
| 155 | 			if (l < 0) return 0; | ||
| 156 | 			p += l-1; | ||
| 157 | 		} | ||
| 158 | 		if (wc==k || wc==kfold) return !inv; | ||
| 159 | 	} | ||
| 160 | 	return inv; | ||
| 161 | } | ||
| 162 | |||
| 163 | static int fnmatch_internal(const char *pat, size_t m, const char *str, size_t n, int flags) | ||
| 164 | { | ||
| 165 | 	const char *p, *ptail, *endpat; | ||
| 166 | 	const char *s, *stail, *endstr; | ||
| 167 | 	size_t pinc, sinc, tailcnt=0; | ||
| 168 | 	int c, k, kfold; | ||
| 169 | |||
| 170 | 	if (flags & FNM_PERIOD) { | ||
| 171 | 		if (*str == '.' && *pat != '.') | ||
| 172 | 			return FNM_NOMATCH; | ||
| 173 | 	} | ||
| 174 | 	for (;;) { | ||
| 175 | 		switch ((c = pat_next(pat, m, &pinc, flags))) { | ||
| 176 | 		case UNMATCHABLE: | ||
| 177 | 			return FNM_NOMATCH; | ||
| 178 | 		case STAR: | ||
| 179 | 			pat++; | ||
| 180 | 			m--; | ||
| 181 | 			break; | ||
| 182 | 		default: | ||
| 183 | 			k = str_next(str, n, &sinc); | ||
| 184 | 			if (k <= 0) | ||
| 185 | 				return (c==END) ? 0 : FNM_NOMATCH; | ||
| 186 | 			str += sinc; | ||
| 187 | 			n -= sinc; | ||
| 188 | 			kfold = flags & FNM_CASEFOLD ? casefold(k) : k; | ||
| 189 | 			if (c == BRACKET) { | ||
| 190 | 				if (!match_bracket(pat, k, kfold)) | ||
| 191 | 					return FNM_NOMATCH; | ||
| 192 | 			} else if (c != QUESTION && k != c && kfold != c) { | ||
| 193 | 				return FNM_NOMATCH; | ||
| 194 | 			} | ||
| 195 | 			pat+=pinc; | ||
| 196 | 			m-=pinc; | ||
| 197 | 			continue; | ||
| 198 | 		} | ||
| 199 | 		break; | ||
| 200 | 	} | ||
| 201 | |||
| 202 | 	/* Compute real pat length if it was initially unknown/-1 */ | ||
| 203 | 	m = strnlen(pat, m); | ||
| 204 | 	endpat = pat + m; | ||
| 205 | |||
| 206 | 	/* Find the last * in pat and count chars needed after it */ | ||
| 207 | 	for (p=ptail=pat; p<endpat; p+=pinc) { | ||
| 208 | 		switch (pat_next(p, endpat-p, &pinc, flags)) { | ||
| 209 | 		case UNMATCHABLE: | ||
| 210 | 			return FNM_NOMATCH; | ||
| 211 | 		case STAR: | ||
| 212 | 			tailcnt=0; | ||
| 213 | 			ptail = p+1; | ||
| 214 | 			break; | ||
| 215 | 		default: | ||
| 216 | 			tailcnt++; | ||
| 217 | 			break; | ||
| 218 | 		} | ||
| 219 | 	} | ||
| 220 | |||
| 221 | 	/* Past this point we need not check for UNMATCHABLE in pat, | ||
| 222 | 	 * because all of pat has already been parsed once. */ | ||
| 223 | |||
| 224 | 	/* Compute real str length if it was initially unknown/-1 */ | ||
| 225 | 	n = strnlen(str, n); | ||
| 226 | 	endstr = str + n; | ||
| 227 | 	if (n < tailcnt) return FNM_NOMATCH; | ||
| 228 | |||
| 229 | 	/* Find the final tailcnt chars of str, accounting for UTF-8. | ||
| 230 | 	 * On illegal sequences we may get it wrong, but in that case | ||
| 231 | 	 * we necessarily have a matching failure anyway. */ | ||
| 232 | 	for (s=endstr; s>str && tailcnt; tailcnt--) { | ||
| 233 | 		if (s[-1] < 128U || MB_CUR_MAX==1) s--; | ||
| 234 | 		else while ((unsigned char)*--s-0x80U<0x40 && s>str); | ||
| 235 | 	} | ||
| 236 | 	if (tailcnt) return FNM_NOMATCH; | ||
| 237 | 	stail = s; | ||
| 238 | |||
| 239 | 	/* Check that the pat and str tails match */ | ||
| 240 | 	p = ptail; | ||
| 241 | 	for (;;) { | ||
| 242 | 		c = pat_next(p, endpat-p, &pinc, flags); | ||
| 243 | 		p += pinc; | ||
| 244 | 		if ((k = str_next(s, endstr-s, &sinc)) <= 0) { | ||
| 245 | 			if (c != END) return FNM_NOMATCH; | ||
| 246 | 			break; | ||
| 247 | 		} | ||
| 248 | 		s += sinc; | ||
| 249 | 		kfold = flags & FNM_CASEFOLD ? casefold(k) : k; | ||
| 250 | 		if (c == BRACKET) { | ||
| 251 | 			if (!match_bracket(p-pinc, k, kfold)) | ||
| 252 | 				return FNM_NOMATCH; | ||
| 253 | 		} else if (c != QUESTION && k != c && kfold != c) { | ||
| 254 | 			return FNM_NOMATCH; | ||
| 255 | 		} | ||
| 256 | 	} | ||
| 257 | |||
| 258 | 	/* We're all done with the tails now, so throw them out */ | ||
| 259 | 	endstr = stail; | ||
| 260 | 	endpat = ptail; | ||
| 261 | |||
| 262 | 	/* Match pattern components until there are none left */ | ||
| 263 | 	while (pat<endpat) { | ||
| 264 | 		p = pat; | ||
| 265 | 		s = str; | ||
| 266 | 		for (;;) { | ||
| 267 | 			c = pat_next(p, endpat-p, &pinc, flags); | ||
| 268 | 			p += pinc; | ||
| 269 | 			/* Encountering * completes/commits a component */ | ||
| 270 | 			if (c == STAR) { | ||
| 271 | 				pat = p; | ||
| 272 | 				str = s; | ||
| 273 | 				break; | ||
| 274 | 			} | ||
| 275 | 			k = str_next(s, endstr-s, &sinc); | ||
| 276 | 			if (!k) | ||
| 277 | 				return FNM_NOMATCH; | ||
| 278 | 			kfold = flags & FNM_CASEFOLD ? casefold(k) : k; | ||
| 279 | 			if (c == BRACKET) { | ||
| 280 | 				if (!match_bracket(p-pinc, k, kfold)) | ||
| 281 | 					break; | ||
| 282 | 			} else if (c != QUESTION && k != c && kfold != c) { | ||
| 283 | 				break; | ||
| 284 | 			} | ||
| 285 | 			s += sinc; | ||
| 286 | 		} | ||
| 287 | 		if (c == STAR) continue; | ||
| 288 | 		/* If we failed, advance str, by 1 char if it's a valid | ||
| 289 | 		 * char, or past all invalid bytes otherwise. */ | ||
| 290 | 		k = str_next(str, endstr-str, &sinc); | ||
| 291 | 		if (k > 0) str += sinc; | ||
| 292 | 		else for (str++; str_next(str, endstr-str, &sinc)<0; str++); | ||
| 293 | 	} | ||
| 294 | |||
| 295 | 	return 0; | ||
| 296 | } | ||
| 297 | |||
| 298 | int fnmatch(const char *pat, const char *str, int flags) | ||
| 299 | { | ||
| 300 | 	const char *s, *p; | ||
| 301 | 	size_t inc; | ||
| 302 | 	int c; | ||
| 303 | 	if (flags & FNM_PATHNAME) for (;;) { | ||
| 304 | 		for (s=str; *s && *s!='/'; s++); | ||
| 305 | 		for (p=pat; (c=pat_next(p, -1, &inc, flags))!=END && c!='/'; p+=inc); | ||
| 306 | 		if (c!=*s && (!*s || !(flags & FNM_LEADING_DIR))) | ||
| 307 | 			return FNM_NOMATCH; | ||
| 308 | 		if (fnmatch_internal(pat, p-pat, str, s-str, flags)) | ||
| 309 | 			return FNM_NOMATCH; | ||
| 310 | 		if (!c) return 0; | ||
| 311 | 		str = s+1; | ||
| 312 | 		pat = p+inc; | ||
| 313 | 	} else if (flags & FNM_LEADING_DIR) { | ||
| 314 | 		for (s=str; *s; s++) { | ||
| 315 | 			if (*s != '/') continue; | ||
| 316 | 			if (!fnmatch_internal(pat, -1, str, s-str, flags)) | ||
| 317 | 				return 0; | ||
| 318 | 		} | ||
| 319 | 	} | ||
| 320 | 	return fnmatch_internal(pat, -1, str, -1, flags); | ||
| 321 | } | ||
lib/libc/wasi/libc-top-half/musl/src/regex/glob.c created+317| ... | @@ -0,0 +1,317 @@ | ||
| 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 | ||
| 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 created+2953| ... | @@ -0,0 +1,2953 @@ | ||
| 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/regerror.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <regex.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include "locale_impl.h" | ||
| 5 | |||
| 6 | /* Error message strings for error codes listed in `regex.h'. This list | ||
| 7 | needs to be in sync with the codes listed there, naturally. */ | ||
| 8 | |||
| 9 | /* Converted to single string by Rich Felker to remove the need for | ||
| 10 | * data relocations at runtime, 27 Feb 2006. */ | ||
| 11 | |||
| 12 | static const char messages[] = { | ||
| 13 | "No error\0" | ||
| 14 | "No match\0" | ||
| 15 | "Invalid regexp\0" | ||
| 16 | "Unknown collating element\0" | ||
| 17 | "Unknown character class name\0" | ||
| 18 | "Trailing backslash\0" | ||
| 19 | "Invalid back reference\0" | ||
| 20 | "Missing ']'\0" | ||
| 21 | "Missing ')'\0" | ||
| 22 | "Missing '}'\0" | ||
| 23 | "Invalid contents of {}\0" | ||
| 24 | "Invalid character range\0" | ||
| 25 | "Out of memory\0" | ||
| 26 | "Repetition not preceded by valid expression\0" | ||
| 27 | "\0Unknown error" | ||
| 28 | }; | ||
| 29 | |||
| 30 | size_t regerror(int e, const regex_t *restrict preg, char *restrict buf, size_t size) | ||
| 31 | { | ||
| 32 | 	const char *s; | ||
| 33 | 	for (s=messages; e && *s; e--, s+=strlen(s)+1); | ||
| 34 | 	if (!*s) s++; | ||
| 35 | 	s = LCTRANS_CUR(s); | ||
| 36 | 	return 1+snprintf(buf, size, "%s", s); | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/regex/regexec.c created+1028| ... | @@ -0,0 +1,1028 @@ | ||
| 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 created+158| ... | @@ -0,0 +1,158 @@ | ||
| 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 created+233| ... | @@ -0,0 +1,233 @@ | ||
| 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/sched/affinity.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sched.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int sched_setaffinity(pid_t tid, size_t size, const cpu_set_t *set) | ||
| 8 | { | ||
| 9 | 	return syscall(SYS_sched_setaffinity, tid, size, set); | ||
| 10 | } | ||
| 11 | |||
| 12 | int pthread_setaffinity_np(pthread_t td, size_t size, const cpu_set_t *set) | ||
| 13 | { | ||
| 14 | 	return -__syscall(SYS_sched_setaffinity, td->tid, size, set); | ||
| 15 | } | ||
| 16 | |||
| 17 | static int do_getaffinity(pid_t tid, size_t size, cpu_set_t *set) | ||
| 18 | { | ||
| 19 | 	long ret = __syscall(SYS_sched_getaffinity, tid, size, set); | ||
| 20 | 	if (ret < 0) return ret; | ||
| 21 | 	if (ret < size) memset((char *)set+ret, 0, size-ret); | ||
| 22 | 	return 0; | ||
| 23 | } | ||
| 24 | |||
| 25 | int sched_getaffinity(pid_t tid, size_t size, cpu_set_t *set) | ||
| 26 | { | ||
| 27 | 	return __syscall_ret(do_getaffinity(tid, size, set)); | ||
| 28 | } | ||
| 29 | |||
| 30 | int pthread_getaffinity_np(pthread_t td, size_t size, cpu_set_t *set) | ||
| 31 | { | ||
| 32 | 	return -do_getaffinity(td->tid, size, set); | ||
| 33 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_cpucount.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sched.h> | ||
| 3 | |||
| 4 | int __sched_cpucount(size_t size, const cpu_set_t *set) | ||
| 5 | { | ||
| 6 | 	size_t i, j, cnt=0; | ||
| 7 | 	const unsigned char *p = (const void *)set; | ||
| 8 | 	for (i=0; i<size; i++) for (j=0; j<8; j++) | ||
| 9 | 		if (p[i] & (1<<j)) cnt++; | ||
| 10 | 	return cnt; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_get_priority_max.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int sched_get_priority_max(int policy) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_sched_get_priority_max, policy); | ||
| 7 | } | ||
| 8 | |||
| 9 | int sched_get_priority_min(int policy) | ||
| 10 | { | ||
| 11 | 	return syscall(SYS_sched_get_priority_min, policy); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getcpu.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <errno.h> | ||
| 3 | #include <sched.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "atomic.h" | ||
| 6 | |||
| 7 | #ifdef VDSO_GETCPU_SYM | ||
| 8 | |||
| 9 | static void *volatile vdso_func; | ||
| 10 | |||
| 11 | typedef long (*getcpu_f)(unsigned *, unsigned *, void *); | ||
| 12 | |||
| 13 | static long getcpu_init(unsigned *cpu, unsigned *node, void *unused) | ||
| 14 | { | ||
| 15 | 	void *p = __vdsosym(VDSO_GETCPU_VER, VDSO_GETCPU_SYM); | ||
| 16 | 	getcpu_f f = (getcpu_f)p; | ||
| 17 | 	a_cas_p(&vdso_func, (void *)getcpu_init, p); | ||
| 18 | 	return f ? f(cpu, node, unused) : -ENOSYS; | ||
| 19 | } | ||
| 20 | |||
| 21 | static void *volatile vdso_func = (void *)getcpu_init; | ||
| 22 | |||
| 23 | #endif | ||
| 24 | |||
| 25 | int sched_getcpu(void) | ||
| 26 | { | ||
| 27 | 	int r; | ||
| 28 | 	unsigned cpu; | ||
| 29 | |||
| 30 | #ifdef VDSO_GETCPU_SYM | ||
| 31 | 	getcpu_f f = (getcpu_f)vdso_func; | ||
| 32 | 	if (f) { | ||
| 33 | 		r = f(&cpu, 0, 0); | ||
| 34 | 		if (!r) return cpu; | ||
| 35 | 		if (r != -ENOSYS) return __syscall_ret(r); | ||
| 36 | 	} | ||
| 37 | #endif | ||
| 38 | |||
| 39 | 	r = __syscall(SYS_getcpu, &cpu, 0, 0); | ||
| 40 | 	if (!r) return cpu; | ||
| 41 | 	return __syscall_ret(r); | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getparam.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int sched_getparam(pid_t pid, struct sched_param *param) | ||
| 6 | { | ||
| 7 | 	return __syscall_ret(-ENOSYS); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_getscheduler.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int sched_getscheduler(pid_t pid) | ||
| 6 | { | ||
| 7 | 	return __syscall_ret(-ENOSYS); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_rr_get_interval.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int sched_rr_get_interval(pid_t pid, struct timespec *ts) | ||
| 5 | { | ||
| 6 | #ifdef SYS_sched_rr_get_interval_time64 | ||
| 7 | 	/* On a 32-bit arch, use the old syscall if it exists. */ | ||
| 8 | 	if (SYS_sched_rr_get_interval != SYS_sched_rr_get_interval_time64) { | ||
| 9 | 		long ts32[2]; | ||
| 10 | 		int r = __syscall(SYS_sched_rr_get_interval, pid, ts32); | ||
| 11 | 		if (!r) { | ||
| 12 | 			ts->tv_sec = ts32[0]; | ||
| 13 | 			ts->tv_nsec = ts32[1]; | ||
| 14 | 		} | ||
| 15 | 		return __syscall_ret(r); | ||
| 16 | 	} | ||
| 17 | #endif | ||
| 18 | 	/* If reaching this point, it's a 64-bit arch or time64-only | ||
| 19 | 	 * 32-bit arch and we can get result directly into timespec. */ | ||
| 20 | 	return syscall(SYS_sched_rr_get_interval, pid, ts); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_setparam.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int sched_setparam(pid_t pid, const struct sched_param *param) | ||
| 6 | { | ||
| 7 | 	return __syscall_ret(-ENOSYS); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_setscheduler.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int sched_setscheduler(pid_t pid, int sched, const struct sched_param *param) | ||
| 6 | { | ||
| 7 | 	return __syscall_ret(-ENOSYS); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/sched/sched_yield.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sched.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int sched_yield() | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_sched_yield); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/search/hsearch.c created+153| ... | @@ -0,0 +1,153 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <search.h> | ||
| 5 | |||
| 6 | /* | ||
| 7 | open addressing hash table with 2^n table size | ||
| 8 | quadratic probing is used in case of hash collision | ||
| 9 | tab indices and hash are size_t | ||
| 10 | after resize fails with ENOMEM the state of tab is still usable | ||
| 11 | |||
| 12 | with the posix api items cannot be iterated and length cannot be queried | ||
| 13 | */ | ||
| 14 | |||
| 15 | #define MINSIZE 8 | ||
| 16 | #define MAXSIZE ((size_t)-1/2 + 1) | ||
| 17 | |||
| 18 | struct __tab { | ||
| 19 | 	ENTRY *entries; | ||
| 20 | 	size_t mask; | ||
| 21 | 	size_t used; | ||
| 22 | }; | ||
| 23 | |||
| 24 | static struct hsearch_data htab; | ||
| 25 | |||
| 26 | static int __hcreate_r(size_t, struct hsearch_data *); | ||
| 27 | static void __hdestroy_r(struct hsearch_data *); | ||
| 28 | static int __hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *); | ||
| 29 | |||
| 30 | static size_t keyhash(char *k) | ||
| 31 | { | ||
| 32 | 	unsigned char *p = (void *)k; | ||
| 33 | 	size_t h = 0; | ||
| 34 | |||
| 35 | 	while (*p) | ||
| 36 | 		h = 31*h + *p++; | ||
| 37 | 	return h; | ||
| 38 | } | ||
| 39 | |||
| 40 | static int resize(size_t nel, struct hsearch_data *htab) | ||
| 41 | { | ||
| 42 | 	size_t newsize; | ||
| 43 | 	size_t i, j; | ||
| 44 | 	ENTRY *e, *newe; | ||
| 45 | 	ENTRY *oldtab = htab->__tab->entries; | ||
| 46 | 	ENTRY *oldend = htab->__tab->entries + htab->__tab->mask + 1; | ||
| 47 | |||
| 48 | 	if (nel > MAXSIZE) | ||
| 49 | 		nel = MAXSIZE; | ||
| 50 | 	for (newsize = MINSIZE; newsize < nel; newsize *= 2); | ||
| 51 | 	htab->__tab->entries = calloc(newsize, sizeof *htab->__tab->entries); | ||
| 52 | 	if (!htab->__tab->entries) { | ||
| 53 | 		htab->__tab->entries = oldtab; | ||
| 54 | 		return 0; | ||
| 55 | 	} | ||
| 56 | 	htab->__tab->mask = newsize - 1; | ||
| 57 | 	if (!oldtab) | ||
| 58 | 		return 1; | ||
| 59 | 	for (e = oldtab; e < oldend; e++) | ||
| 60 | 		if (e->key) { | ||
| 61 | 			for (i=keyhash(e->key),j=1; ; i+=j++) { | ||
| 62 | 				newe = htab->__tab->entries + (i & htab->__tab->mask); | ||
| 63 | 				if (!newe->key) | ||
| 64 | 					break; | ||
| 65 | 			} | ||
| 66 | 			*newe = *e; | ||
| 67 | 		} | ||
| 68 | 	free(oldtab); | ||
| 69 | 	return 1; | ||
| 70 | } | ||
| 71 | |||
| 72 | int hcreate(size_t nel) | ||
| 73 | { | ||
| 74 | 	return __hcreate_r(nel, &htab); | ||
| 75 | } | ||
| 76 | |||
| 77 | void hdestroy(void) | ||
| 78 | { | ||
| 79 | 	__hdestroy_r(&htab); | ||
| 80 | } | ||
| 81 | |||
| 82 | static ENTRY *lookup(char *key, size_t hash, struct hsearch_data *htab) | ||
| 83 | { | ||
| 84 | 	size_t i, j; | ||
| 85 | 	ENTRY *e; | ||
| 86 | |||
| 87 | 	for (i=hash,j=1; ; i+=j++) { | ||
| 88 | 		e = htab->__tab->entries + (i & htab->__tab->mask); | ||
| 89 | 		if (!e->key || strcmp(e->key, key) == 0) | ||
| 90 | 			break; | ||
| 91 | 	} | ||
| 92 | 	return e; | ||
| 93 | } | ||
| 94 | |||
| 95 | ENTRY *hsearch(ENTRY item, ACTION action) | ||
| 96 | { | ||
| 97 | 	ENTRY *e; | ||
| 98 | |||
| 99 | 	__hsearch_r(item, action, &e, &htab); | ||
| 100 | 	return e; | ||
| 101 | } | ||
| 102 | |||
| 103 | static int __hcreate_r(size_t nel, struct hsearch_data *htab) | ||
| 104 | { | ||
| 105 | 	int r; | ||
| 106 | |||
| 107 | 	htab->__tab = calloc(1, sizeof *htab->__tab); | ||
| 108 | 	if (!htab->__tab) | ||
| 109 | 		return 0; | ||
| 110 | 	r = resize(nel, htab); | ||
| 111 | 	if (r == 0) { | ||
| 112 | 		free(htab->__tab); | ||
| 113 | 		htab->__tab = 0; | ||
| 114 | 	} | ||
| 115 | 	return r; | ||
| 116 | } | ||
| 117 | weak_alias(__hcreate_r, hcreate_r); | ||
| 118 | |||
| 119 | static void __hdestroy_r(struct hsearch_data *htab) | ||
| 120 | { | ||
| 121 | 	if (htab->__tab) free(htab->__tab->entries); | ||
| 122 | 	free(htab->__tab); | ||
| 123 | 	htab->__tab = 0; | ||
| 124 | } | ||
| 125 | weak_alias(__hdestroy_r, hdestroy_r); | ||
| 126 | |||
| 127 | static int __hsearch_r(ENTRY item, ACTION action, ENTRY **retval, struct hsearch_data *htab) | ||
| 128 | { | ||
| 129 | 	size_t hash = keyhash(item.key); | ||
| 130 | 	ENTRY *e = lookup(item.key, hash, htab); | ||
| 131 | |||
| 132 | 	if (e->key) { | ||
| 133 | 		*retval = e; | ||
| 134 | 		return 1; | ||
| 135 | 	} | ||
| 136 | 	if (action == FIND) { | ||
| 137 | 		*retval = 0; | ||
| 138 | 		return 0; | ||
| 139 | 	} | ||
| 140 | 	*e = item; | ||
| 141 | 	if (++htab->__tab->used > htab->__tab->mask - htab->__tab->mask/4) { | ||
| 142 | 		if (!resize(2*htab->__tab->used, htab)) { | ||
| 143 | 			htab->__tab->used--; | ||
| 144 | 			e->key = 0; | ||
| 145 | 			*retval = 0; | ||
| 146 | 			return 0; | ||
| 147 | 		} | ||
| 148 | 		e = lookup(item.key, hash, htab); | ||
| 149 | 	} | ||
| 150 | 	*retval = e; | ||
| 151 | 	return 1; | ||
| 152 | } | ||
| 153 | weak_alias(__hsearch_r, hsearch_r); | ||
lib/libc/wasi/libc-top-half/musl/src/search/insque.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <search.h> | ||
| 2 | |||
| 3 | struct node { | ||
| 4 | 	struct node *next; | ||
| 5 | 	struct node *prev; | ||
| 6 | }; | ||
| 7 | |||
| 8 | void insque(void *element, void *pred) | ||
| 9 | { | ||
| 10 | 	struct node *e = element; | ||
| 11 | 	struct node *p = pred; | ||
| 12 | |||
| 13 | 	if (!p) { | ||
| 14 | 		e->next = e->prev = 0; | ||
| 15 | 		return; | ||
| 16 | 	} | ||
| 17 | 	e->next = p->next; | ||
| 18 | 	e->prev = p; | ||
| 19 | 	p->next = e; | ||
| 20 | 	if (e->next) | ||
| 21 | 		e->next->prev = e; | ||
| 22 | } | ||
| 23 | |||
| 24 | void remque(void *element) | ||
| 25 | { | ||
| 26 | 	struct node *e = element; | ||
| 27 | |||
| 28 | 	if (e->next) | ||
| 29 | 		e->next->prev = e->prev; | ||
| 30 | 	if (e->prev) | ||
| 31 | 		e->prev->next = e->next; | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/search/lsearch.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include <search.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | void *lsearch(const void *key, void *base, size_t *nelp, size_t width, | ||
| 5 | 	int (*compar)(const void *, const void *)) | ||
| 6 | { | ||
| 7 | 	char (*p)[width] = base; | ||
| 8 | 	size_t n = *nelp; | ||
| 9 | 	size_t i; | ||
| 10 | |||
| 11 | 	for (i = 0; i < n; i++) | ||
| 12 | 		if (compar(key, p[i]) == 0) | ||
| 13 | 			return p[i]; | ||
| 14 | 	*nelp = n+1; | ||
| 15 | 	return memcpy(p[n], key, width); | ||
| 16 | } | ||
| 17 | |||
| 18 | void *lfind(const void *key, const void *base, size_t *nelp, | ||
| 19 | 	size_t width, int (*compar)(const void *, const void *)) | ||
| 20 | { | ||
| 21 | 	char (*p)[width] = (void *)base; | ||
| 22 | 	size_t n = *nelp; | ||
| 23 | 	size_t i; | ||
| 24 | |||
| 25 | 	for (i = 0; i < n; i++) | ||
| 26 | 		if (compar(key, p[i]) == 0) | ||
| 27 | 			return p[i]; | ||
| 28 | 	return 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
lib/libc/wasi/libc-top-half/musl/src/search/tdelete.c created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <search.h> | ||
| 3 | #include "tsearch.h" | ||
| 4 | |||
| 5 | void *tdelete(const void *restrict key, void **restrict rootp, | ||
| 6 | 	int(*cmp)(const void *, const void *)) | ||
| 7 | { | ||
| 8 | 	if (!rootp) | ||
| 9 | 		return 0; | ||
| 10 | |||
| 11 | 	void **a[MAXH+1]; | ||
| 12 | 	struct node *n = *rootp; | ||
| 13 | 	struct node *parent; | ||
| 14 | 	struct node *child; | ||
| 15 | 	int i=0; | ||
| 16 | 	/* *a[0] is an arbitrary non-null pointer that is returned when | ||
| 17 | 	 the root node is deleted. */ | ||
| 18 | 	a[i++] = rootp; | ||
| 19 | 	a[i++] = rootp; | ||
| 20 | 	for (;;) { | ||
| 21 | 		if (!n) | ||
| 22 | 			return 0; | ||
| 23 | 		int c = cmp(key, n->key); | ||
| 24 | 		if (!c) | ||
| 25 | 			break; | ||
| 26 | 		a[i++] = &n->a[c>0]; | ||
| 27 | 		n = n->a[c>0]; | ||
| 28 | 	} | ||
| 29 | 	parent = *a[i-2]; | ||
| 30 | 	if (n->a[0]) { | ||
| 31 | 		/* free the preceding node instead of the deleted one. */ | ||
| 32 | 		struct node *deleted = n; | ||
| 33 | 		a[i++] = &n->a[0]; | ||
| 34 | 		n = n->a[0]; | ||
| 35 | 		while (n->a[1]) { | ||
| 36 | 			a[i++] = &n->a[1]; | ||
| 37 | 			n = n->a[1]; | ||
| 38 | 		} | ||
| 39 | 		deleted->key = n->key; | ||
| 40 | 		child = n->a[0]; | ||
| 41 | 	} else { | ||
| 42 | 		child = n->a[1]; | ||
| 43 | 	} | ||
| 44 | 	/* freed node has at most one child, move it up and rebalance. */ | ||
| 45 | 	free(n); | ||
| 46 | 	*a[--i] = child; | ||
| 47 | 	while (--i && __tsearch_balance(a[i])); | ||
| 48 | 	return parent; | ||
| 49 | } | ||
lib/libc/wasi/libc-top-half/musl/src/search/tdestroy.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <search.h> | ||
| 4 | #include "tsearch.h" | ||
| 5 | |||
| 6 | void tdestroy(void *root, void (*freekey)(void *)) | ||
| 7 | { | ||
| 8 | 	struct node *r = root; | ||
| 9 | |||
| 10 | 	if (r == 0) | ||
| 11 | 		return; | ||
| 12 | 	tdestroy(r->a[0], freekey); | ||
| 13 | 	tdestroy(r->a[1], freekey); | ||
| 14 | 	if (freekey) freekey((void *)r->key); | ||
| 15 | 	free(r); | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/search/tfind.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <search.h> | ||
| 2 | #include "tsearch.h" | ||
| 3 | |||
| 4 | void *tfind(const void *key, void *const *rootp, | ||
| 5 | 	int(*cmp)(const void *, const void *)) | ||
| 6 | { | ||
| 7 | 	if (!rootp) | ||
| 8 | 		return 0; | ||
| 9 | |||
| 10 | 	struct node *n = *rootp; | ||
| 11 | 	for (;;) { | ||
| 12 | 		if (!n) | ||
| 13 | 			break; | ||
| 14 | 		int c = cmp(key, n->key); | ||
| 15 | 		if (!c) | ||
| 16 | 			break; | ||
| 17 | 		n = n->a[c>0]; | ||
| 18 | 	} | ||
| 19 | 	return n; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/search/tsearch.c created+92| ... | @@ -0,0 +1,92 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <search.h> | ||
| 3 | #include "tsearch.h" | ||
| 4 | |||
| 5 | static inline int height(struct node *n) { return n ? n->h : 0; } | ||
| 6 | |||
| 7 | static int rot(void **p, struct node *x, int dir /* deeper side */) | ||
| 8 | { | ||
| 9 | 	struct node *y = x->a[dir]; | ||
| 10 | 	struct node *z = y->a[!dir]; | ||
| 11 | 	int hx = x->h; | ||
| 12 | 	int hz = height(z); | ||
| 13 | 	if (hz > height(y->a[dir])) { | ||
| 14 | 		/* | ||
| 15 | 		 * x | ||
| 16 | 		 * / \ dir z | ||
| 17 | 		 * A y / \ | ||
| 18 | 		 * / \ --> x y | ||
| 19 | 		 * z D /| |\ | ||
| 20 | 		 * / \ A B C D | ||
| 21 | 		 * B C | ||
| 22 | 		 */ | ||
| 23 | 		x->a[dir] = z->a[!dir]; | ||
| 24 | 		y->a[!dir] = z->a[dir]; | ||
| 25 | 		z->a[!dir] = x; | ||
| 26 | 		z->a[dir] = y; | ||
| 27 | 		x->h = hz; | ||
| 28 | 		y->h = hz; | ||
| 29 | 		z->h = hz+1; | ||
| 30 | 	} else { | ||
| 31 | 		/* | ||
| 32 | 		 * x y | ||
| 33 | 		 * / \ / \ | ||
| 34 | 		 * A y --> x D | ||
| 35 | 		 * / \ / \ | ||
| 36 | 		 * z D A z | ||
| 37 | 		 */ | ||
| 38 | 		x->a[dir] = z; | ||
| 39 | 		y->a[!dir] = x; | ||
| 40 | 		x->h = hz+1; | ||
| 41 | 		y->h = hz+2; | ||
| 42 | 		z = y; | ||
| 43 | 	} | ||
| 44 | 	*p = z; | ||
| 45 | 	return z->h - hx; | ||
| 46 | } | ||
| 47 | |||
| 48 | /* balance *p, return 0 if height is unchanged. */ | ||
| 49 | int __tsearch_balance(void **p) | ||
| 50 | { | ||
| 51 | 	struct node *n = *p; | ||
| 52 | 	int h0 = height(n->a[0]); | ||
| 53 | 	int h1 = height(n->a[1]); | ||
| 54 | 	if (h0 - h1 + 1u < 3u) { | ||
| 55 | 		int old = n->h; | ||
| 56 | 		n->h = h0<h1 ? h1+1 : h0+1; | ||
| 57 | 		return n->h - old; | ||
| 58 | 	} | ||
| 59 | 	return rot(p, n, h0<h1); | ||
| 60 | } | ||
| 61 | |||
| 62 | void *tsearch(const void *key, void **rootp, | ||
| 63 | 	int (*cmp)(const void *, const void *)) | ||
| 64 | { | ||
| 65 | 	if (!rootp) | ||
| 66 | 		return 0; | ||
| 67 | |||
| 68 | 	void **a[MAXH]; | ||
| 69 | 	struct node *n = *rootp; | ||
| 70 | 	struct node *r; | ||
| 71 | 	int i=0; | ||
| 72 | 	a[i++] = rootp; | ||
| 73 | 	for (;;) { | ||
| 74 | 		if (!n) | ||
| 75 | 			break; | ||
| 76 | 		int c = cmp(key, n->key); | ||
| 77 | 		if (!c) | ||
| 78 | 			return n; | ||
| 79 | 		a[i++] = &n->a[c>0]; | ||
| 80 | 		n = n->a[c>0]; | ||
| 81 | 	} | ||
| 82 | 	r = malloc(sizeof *r); | ||
| 83 | 	if (!r) | ||
| 84 | 		return 0; | ||
| 85 | 	r->key = key; | ||
| 86 | 	r->a[0] = r->a[1] = 0; | ||
| 87 | 	r->h = 1; | ||
| 88 | 	/* insert new node, rebalance ancestors. */ | ||
| 89 | 	*a[--i] = r; | ||
| 90 | 	while (i && __tsearch_balance(a[--i])); | ||
| 91 | 	return r; | ||
| 92 | } | ||
lib/libc/wasi/libc-top-half/musl/src/search/tsearch.h created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <search.h> | ||
| 2 | #include <features.h> | ||
| 3 | |||
| 4 | /* AVL tree height < 1.44*log2(nodes+2)-0.3, MAXH is a safe upper bound. */ | ||
| 5 | #define MAXH (sizeof(void*)*8*3/2) | ||
| 6 | |||
| 7 | struct node { | ||
| 8 | 	const void *key; | ||
| 9 | 	void *a[2]; | ||
| 10 | 	int h; | ||
| 11 | }; | ||
| 12 | |||
| 13 | hidden int __tsearch_balance(void **); | ||
lib/libc/wasi/libc-top-half/musl/src/search/twalk.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <search.h> | ||
| 2 | #include "tsearch.h" | ||
| 3 | |||
| 4 | static void walk(const struct node *r, void (*action)(const void *, VISIT, int), int d) | ||
| 5 | { | ||
| 6 | 	if (!r) | ||
| 7 | 		return; | ||
| 8 | 	if (r->h == 1) | ||
| 9 | 		action(r, leaf, d); | ||
| 10 | 	else { | ||
| 11 | 		action(r, preorder, d); | ||
| 12 | 		walk(r->a[0], action, d+1); | ||
| 13 | 		action(r, postorder, d); | ||
| 14 | 		walk(r->a[1], action, d+1); | ||
| 15 | 		action(r, endorder, d); | ||
| 16 | 	} | ||
| 17 | } | ||
| 18 | |||
| 19 | void twalk(const void *root, void (*action)(const void *, VISIT, int)) | ||
| 20 | { | ||
| 21 | 	walk(root, action, 0); | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/select/poll.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <poll.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int poll(struct pollfd *fds, nfds_t n, int timeout) | ||
| 7 | { | ||
| 8 | #ifdef SYS_poll | ||
| 9 | 	return syscall_cp(SYS_poll, fds, n, timeout); | ||
| 10 | #else | ||
| 11 | 	return syscall_cp(SYS_ppoll, fds, n, timeout>=0 ? | ||
| 12 | 		&((struct timespec){ .tv_sec = timeout/1000, | ||
| 13 | 		.tv_nsec = timeout%1000*1000000 }) : 0, 0, _NSIG/8); | ||
| 14 | #endif | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/select/pselect.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <sys/select.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 8 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 9 | |||
| 10 | int pselect(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, const struct timespec *restrict ts, const sigset_t *restrict mask) | ||
| 11 | { | ||
| 12 | 	syscall_arg_t data[2] = { (uintptr_t)mask, _NSIG/8 }; | ||
| 13 | 	time_t s = ts ? ts->tv_sec : 0; | ||
| 14 | 	long ns = ts ? ts->tv_nsec : 0; | ||
| 15 | #ifdef SYS_pselect6_time64 | ||
| 16 | 	int r = -ENOSYS; | ||
| 17 | 	if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s)) | ||
| 18 | 		r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds, | ||
| 19 | 			ts ? ((long long[]){s, ns}) : 0, data); | ||
| 20 | 	if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS) | ||
| 21 | 		return __syscall_ret(r); | ||
| 22 | 	s = CLAMP(s); | ||
| 23 | #endif | ||
| 24 | 	return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, | ||
| 25 | 		ts ? ((long[]){s, ns}) : 0, data); | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/select/select.c created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | #include <sys/select.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 8 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 9 | |||
| 10 | int select(int n, fd_set *restrict rfds, fd_set *restrict wfds, fd_set *restrict efds, struct timeval *restrict tv) | ||
| 11 | { | ||
| 12 | 	time_t s = tv ? tv->tv_sec : 0; | ||
| 13 | 	suseconds_t us = tv ? tv->tv_usec : 0; | ||
| 14 | 	long ns; | ||
| 15 | 	const time_t max_time = (1ULL<<8*sizeof(time_t)-1)-1; | ||
| 16 | |||
| 17 | 	if (s<0 || us<0) return __syscall_ret(-EINVAL); | ||
| 18 | 	if (us/1000000 > max_time - s) { | ||
| 19 | 		s = max_time; | ||
| 20 | 		us = 999999; | ||
| 21 | 		ns = 999999999; | ||
| 22 | 	} else { | ||
| 23 | 		s += us/1000000; | ||
| 24 | 		us %= 1000000; | ||
| 25 | 		ns = us*1000; | ||
| 26 | 	} | ||
| 27 | |||
| 28 | #ifdef SYS_pselect6_time64 | ||
| 29 | 	int r = -ENOSYS; | ||
| 30 | 	if (SYS_pselect6 == SYS_pselect6_time64 || !IS32BIT(s)) | ||
| 31 | 		r = __syscall_cp(SYS_pselect6_time64, n, rfds, wfds, efds, | ||
| 32 | 			tv ? ((long long[]){s, ns}) : 0, | ||
| 33 | 			((syscall_arg_t[]){ 0, _NSIG/8 })); | ||
| 34 | 	if (SYS_pselect6 == SYS_pselect6_time64 || r!=-ENOSYS) | ||
| 35 | 		return __syscall_ret(r); | ||
| 36 | #endif | ||
| 37 | #ifdef SYS_select | ||
| 38 | 	return syscall_cp(SYS_select, n, rfds, wfds, efds, | ||
| 39 | 		tv ? ((long[]){s, us}) : 0); | ||
| 40 | #else | ||
| 41 | 	return syscall_cp(SYS_pselect6, n, rfds, wfds, efds, | ||
| 42 | 		tv ? ((long[]){s, ns}) : 0, ((syscall_arg_t[]){ 0, _NSIG/8 })); | ||
| 43 | #endif | ||
| 44 | } | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/aarch64/longjmp.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .global _longjmp | ||
| 2 | .global longjmp | ||
| 3 | .type _longjmp,%function | ||
| 4 | .type longjmp,%function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	// IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers | ||
| 8 | 	ldp x19, x20, [x0,#0] | ||
| 9 | 	ldp x21, x22, [x0,#16] | ||
| 10 | 	ldp x23, x24, [x0,#32] | ||
| 11 | 	ldp x25, x26, [x0,#48] | ||
| 12 | 	ldp x27, x28, [x0,#64] | ||
| 13 | 	ldp x29, x30, [x0,#80] | ||
| 14 | 	ldr x2, [x0,#104] | ||
| 15 | 	mov sp, x2 | ||
| 16 | 	ldp d8 , d9, [x0,#112] | ||
| 17 | 	ldp d10, d11, [x0,#128] | ||
| 18 | 	ldp d12, d13, [x0,#144] | ||
| 19 | 	ldp d14, d15, [x0,#160] | ||
| 20 | |||
| 21 | 	cmp w1, 0 | ||
| 22 | 	csinc w0, w1, wzr, ne | ||
| 23 | 	br x30 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/aarch64/setjmp.s created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | .global __setjmp | ||
| 2 | .global _setjmp | ||
| 3 | .global setjmp | ||
| 4 | .type __setjmp,@function | ||
| 5 | .type _setjmp,@function | ||
| 6 | .type setjmp,@function | ||
| 7 | __setjmp: | ||
| 8 | _setjmp: | ||
| 9 | setjmp: | ||
| 10 | 	// IHI0055B_aapcs64.pdf 5.1.1, 5.1.2 callee saved registers | ||
| 11 | 	stp x19, x20, [x0,#0] | ||
| 12 | 	stp x21, x22, [x0,#16] | ||
| 13 | 	stp x23, x24, [x0,#32] | ||
| 14 | 	stp x25, x26, [x0,#48] | ||
| 15 | 	stp x27, x28, [x0,#64] | ||
| 16 | 	stp x29, x30, [x0,#80] | ||
| 17 | 	mov x2, sp | ||
| 18 | 	str x2, [x0,#104] | ||
| 19 | 	stp d8, d9, [x0,#112] | ||
| 20 | 	stp d10, d11, [x0,#128] | ||
| 21 | 	stp d12, d13, [x0,#144] | ||
| 22 | 	stp d14, d15, [x0,#160] | ||
| 23 | 	mov x0, #0 | ||
| 24 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/arm/longjmp.S created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | .syntax unified | ||
| 2 | .global _longjmp | ||
| 3 | .global longjmp | ||
| 4 | .type _longjmp,%function | ||
| 5 | .type longjmp,%function | ||
| 6 | _longjmp: | ||
| 7 | longjmp: | ||
| 8 | 	mov ip,r0 | ||
| 9 | 	movs r0,r1 | ||
| 10 | 	moveq r0,#1 | ||
| 11 | 	ldmia ip!, {v1,v2,v3,v4,v5,v6,sl,fp} | ||
| 12 | 	ldmia ip!, {r2,lr} | ||
| 13 | 	mov sp,r2 | ||
| 14 | |||
| 15 | 	adr r1,1f | ||
| 16 | 	ldr r2,1f | ||
| 17 | 	ldr r1,[r1,r2] | ||
| 18 | |||
| 19 | #if __ARM_ARCH < 8 | ||
| 20 | 	tst r1,#0x260 | ||
| 21 | 	beq 3f | ||
| 22 | 	// HWCAP_ARM_FPA | ||
| 23 | 	tst r1,#0x20 | ||
| 24 | 	beq 2f | ||
| 25 | 	ldc p2, cr4, [ip], #48 | ||
| 26 | #endif | ||
| 27 | 2:	tst r1,#0x40 | ||
| 28 | 	beq 2f | ||
| 29 | 	.fpu vfp | ||
| 30 | 	vldmia ip!, {d8-d15} | ||
| 31 | 	.fpu softvfp | ||
| 32 | 	.eabi_attribute 10, 0 | ||
| 33 | 	.eabi_attribute 27, 0 | ||
| 34 | #if __ARM_ARCH < 8 | ||
| 35 | 	// HWCAP_ARM_IWMMXT | ||
| 36 | 2:	tst r1,#0x200 | ||
| 37 | 	beq 3f | ||
| 38 | 	ldcl p1, cr10, [ip], #8 | ||
| 39 | 	ldcl p1, cr11, [ip], #8 | ||
| 40 | 	ldcl p1, cr12, [ip], #8 | ||
| 41 | 	ldcl p1, cr13, [ip], #8 | ||
| 42 | 	ldcl p1, cr14, [ip], #8 | ||
| 43 | 	ldcl p1, cr15, [ip], #8 | ||
| 44 | #endif | ||
| 45 | 2: | ||
| 46 | 3:	bx lr | ||
| 47 | |||
| 48 | .hidden __hwcap | ||
| 49 | .align 2 | ||
| 50 | 1:	.word __hwcap-1b | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/arm/setjmp.S created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | .syntax unified | ||
| 2 | .global __setjmp | ||
| 3 | .global _setjmp | ||
| 4 | .global setjmp | ||
| 5 | .type __setjmp,%function | ||
| 6 | .type _setjmp,%function | ||
| 7 | .type setjmp,%function | ||
| 8 | __setjmp: | ||
| 9 | _setjmp: | ||
| 10 | setjmp: | ||
| 11 | 	mov ip,r0 | ||
| 12 | 	stmia ip!,{v1,v2,v3,v4,v5,v6,sl,fp} | ||
| 13 | 	mov r2,sp | ||
| 14 | 	stmia ip!,{r2,lr} | ||
| 15 | 	mov r0,#0 | ||
| 16 | |||
| 17 | 	adr r1,1f | ||
| 18 | 	ldr r2,1f | ||
| 19 | 	ldr r1,[r1,r2] | ||
| 20 | |||
| 21 | #if __ARM_ARCH < 8 | ||
| 22 | 	tst r1,#0x260 | ||
| 23 | 	beq 3f | ||
| 24 | 	// HWCAP_ARM_FPA | ||
| 25 | 	tst r1,#0x20 | ||
| 26 | 	beq 2f | ||
| 27 | 	stc p2, cr4, [ip], #48 | ||
| 28 | #endif | ||
| 29 | 2:	tst r1,#0x40 | ||
| 30 | 	beq 2f | ||
| 31 | 	.fpu vfp | ||
| 32 | 	vstmia ip!, {d8-d15} | ||
| 33 | 	.fpu softvfp | ||
| 34 | 	.eabi_attribute 10, 0 | ||
| 35 | 	.eabi_attribute 27, 0 | ||
| 36 | #if __ARM_ARCH < 8 | ||
| 37 | 	// HWCAP_ARM_IWMMXT | ||
| 38 | 2:	tst r1,#0x200 | ||
| 39 | 	beq 3f | ||
| 40 | 	stcl p1, cr10, [ip], #8 | ||
| 41 | 	stcl p1, cr11, [ip], #8 | ||
| 42 | 	stcl p1, cr12, [ip], #8 | ||
| 43 | 	stcl p1, cr13, [ip], #8 | ||
| 44 | 	stcl p1, cr14, [ip], #8 | ||
| 45 | 	stcl p1, cr15, [ip], #8 | ||
| 46 | #endif | ||
| 47 | 2: | ||
| 48 | 3:	bx lr | ||
| 49 | |||
| 50 | .hidden __hwcap | ||
| 51 | .align 2 | ||
| 52 | 1:	.word __hwcap-1b | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/i386/longjmp.s created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | .global _longjmp | ||
| 2 | .global longjmp | ||
| 3 | .type _longjmp,@function | ||
| 4 | .type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	mov 4(%esp),%edx | ||
| 8 | 	mov 8(%esp),%eax | ||
| 9 | 	cmp $1,%eax | ||
| 10 | 	adc $0, %al | ||
| 11 | 	mov (%edx),%ebx | ||
| 12 | 	mov 4(%edx),%esi | ||
| 13 | 	mov 8(%edx),%edi | ||
| 14 | 	mov 12(%edx),%ebp | ||
| 15 | 	mov 16(%edx),%esp | ||
| 16 | 	jmp *20(%edx) | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/i386/setjmp.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .global ___setjmp | ||
| 2 | .hidden ___setjmp | ||
| 3 | .global __setjmp | ||
| 4 | .global _setjmp | ||
| 5 | .global setjmp | ||
| 6 | .type __setjmp,@function | ||
| 7 | .type _setjmp,@function | ||
| 8 | .type setjmp,@function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | 	mov 4(%esp), %eax | ||
| 14 | 	mov %ebx, (%eax) | ||
| 15 | 	mov %esi, 4(%eax) | ||
| 16 | 	mov %edi, 8(%eax) | ||
| 17 | 	mov %ebp, 12(%eax) | ||
| 18 | 	lea 4(%esp), %ecx | ||
| 19 | 	mov %ecx, 16(%eax) | ||
| 20 | 	mov (%esp), %ecx | ||
| 21 | 	mov %ecx, 20(%eax) | ||
| 22 | 	xor %eax, %eax | ||
| 23 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/longjmp.c createdlib/libc/wasi/libc-top-half/musl/src/setjmp/m68k/longjmp.s created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | .global _longjmp | ||
| 2 | .global longjmp | ||
| 3 | .type _longjmp,@function | ||
| 4 | .type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	movea.l 4(%sp),%a0 | ||
| 8 | 	move.l 8(%sp),%d0 | ||
| 9 | 	bne 1f | ||
| 10 | 	move.l #1,%d0 | ||
| 11 | 1:	movem.l (%a0),%d2-%d7/%a2-%a7 | ||
| 12 | 	fmovem.x 52(%a0),%fp2-%fp7 | ||
| 13 | 	move.l 48(%a0),(%sp) | ||
| 14 | 	rts | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/m68k/setjmp.s created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | .global ___setjmp | ||
| 2 | .hidden ___setjmp | ||
| 3 | .global __setjmp | ||
| 4 | .global _setjmp | ||
| 5 | .global setjmp | ||
| 6 | .type __setjmp,@function | ||
| 7 | .type _setjmp,@function | ||
| 8 | .type setjmp,@function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | 	movea.l 4(%sp),%a0 | ||
| 14 | 	movem.l %d2-%d7/%a2-%a7,(%a0) | ||
| 15 | 	move.l (%sp),48(%a0) | ||
| 16 | 	fmovem.x %fp2-%fp7,52(%a0) | ||
| 17 | 	clr.l %d0 | ||
| 18 | 	rts | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/microblaze/longjmp.s created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | .global _longjmp | ||
| 2 | .global longjmp | ||
| 3 | .type _longjmp,@function | ||
| 4 | .type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	addi r3, r6, 0 | ||
| 8 | 	bnei r3, 1f | ||
| 9 | 	addi r3, r3, 1 | ||
| 10 | 1: lwi r1, r5, 0 | ||
| 11 | 	lwi r15, r5, 4 | ||
| 12 | 	lwi r2, r5, 8 | ||
| 13 | 	lwi r13, r5, 12 | ||
| 14 | 	lwi r18, r5, 16 | ||
| 15 | 	lwi r19, r5, 20 | ||
| 16 | 	lwi r20, r5, 24 | ||
| 17 | 	lwi r21, r5, 28 | ||
| 18 | 	lwi r22, r5, 32 | ||
| 19 | 	lwi r23, r5, 36 | ||
| 20 | 	lwi r24, r5, 40 | ||
| 21 | 	lwi r25, r5, 44 | ||
| 22 | 	lwi r26, r5, 48 | ||
| 23 | 	lwi r27, r5, 52 | ||
| 24 | 	lwi r28, r5, 56 | ||
| 25 | 	lwi r29, r5, 60 | ||
| 26 | 	lwi r30, r5, 64 | ||
| 27 | 	lwi r31, r5, 68 | ||
| 28 | 	rtsd r15, 8 | ||
| 29 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/microblaze/setjmp.s created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | .global ___setjmp | ||
| 2 | .hidden ___setjmp | ||
| 3 | .global __setjmp | ||
| 4 | .global _setjmp | ||
| 5 | .global setjmp | ||
| 6 | .type __setjmp,@function | ||
| 7 | .type _setjmp,@function | ||
| 8 | .type setjmp,@function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | 	swi r1, r5, 0 | ||
| 14 | 	swi r15, r5, 4 | ||
| 15 | 	swi r2, r5, 8 | ||
| 16 | 	swi r13, r5, 12 | ||
| 17 | 	swi r18, r5, 16 | ||
| 18 | 	swi r19, r5, 20 | ||
| 19 | 	swi r20, r5, 24 | ||
| 20 | 	swi r21, r5, 28 | ||
| 21 | 	swi r22, r5, 32 | ||
| 22 | 	swi r23, r5, 36 | ||
| 23 | 	swi r24, r5, 40 | ||
| 24 | 	swi r25, r5, 44 | ||
| 25 | 	swi r26, r5, 48 | ||
| 26 | 	swi r27, r5, 52 | ||
| 27 | 	swi r28, r5, 56 | ||
| 28 | 	swi r29, r5, 60 | ||
| 29 | 	swi r30, r5, 64 | ||
| 30 | 	swi r31, r5, 68 | ||
| 31 | 	rtsd r15, 8 | ||
| 32 | 	ori r3, r0, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/mips/longjmp.S created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | .set noreorder | ||
| 2 | |||
| 3 | .global _longjmp | ||
| 4 | .global longjmp | ||
| 5 | .type _longjmp,@function | ||
| 6 | .type longjmp,@function | ||
| 7 | _longjmp: | ||
| 8 | longjmp: | ||
| 9 | 	move $2, $5 | ||
| 10 | 	bne $2, $0, 1f | ||
| 11 | 	nop | ||
| 12 | 	addu $2, $2, 1 | ||
| 13 | 1: | ||
| 14 | #ifndef __mips_soft_float | ||
| 15 | 	l.d $f20, 56($4) | ||
| 16 | 	l.d $f22, 64($4) | ||
| 17 | 	l.d $f24, 72($4) | ||
| 18 | 	l.d $f26, 80($4) | ||
| 19 | 	l.d $f28, 88($4) | ||
| 20 | 	l.d $f30, 96($4) | ||
| 21 | #endif | ||
| 22 | 	lw $ra, 0($4) | ||
| 23 | 	lw $sp, 4($4) | ||
| 24 | 	lw $16, 8($4) | ||
| 25 | 	lw $17, 12($4) | ||
| 26 | 	lw $18, 16($4) | ||
| 27 | 	lw $19, 20($4) | ||
| 28 | 	lw $20, 24($4) | ||
| 29 | 	lw $21, 28($4) | ||
| 30 | 	lw $22, 32($4) | ||
| 31 | 	lw $23, 36($4) | ||
| 32 | 	lw $30, 40($4) | ||
| 33 | 	jr $ra | ||
| 34 | 	lw $28, 44($4) | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/mips/setjmp.S created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | .set noreorder | ||
| 2 | |||
| 3 | .global __setjmp | ||
| 4 | .global _setjmp | ||
| 5 | .global setjmp | ||
| 6 | .type __setjmp,@function | ||
| 7 | .type _setjmp,@function | ||
| 8 | .type setjmp,@function | ||
| 9 | __setjmp: | ||
| 10 | _setjmp: | ||
| 11 | setjmp: | ||
| 12 | 	sw $ra, 0($4) | ||
| 13 | 	sw $sp, 4($4) | ||
| 14 | 	sw $16, 8($4) | ||
| 15 | 	sw $17, 12($4) | ||
| 16 | 	sw $18, 16($4) | ||
| 17 | 	sw $19, 20($4) | ||
| 18 | 	sw $20, 24($4) | ||
| 19 | 	sw $21, 28($4) | ||
| 20 | 	sw $22, 32($4) | ||
| 21 | 	sw $23, 36($4) | ||
| 22 | 	sw $30, 40($4) | ||
| 23 | 	sw $28, 44($4) | ||
| 24 | #ifndef __mips_soft_float | ||
| 25 | 	s.d $f20, 56($4) | ||
| 26 | 	s.d $f22, 64($4) | ||
| 27 | 	s.d $f24, 72($4) | ||
| 28 | 	s.d $f26, 80($4) | ||
| 29 | 	s.d $f28, 88($4) | ||
| 30 | 	s.d $f30, 96($4) | ||
| 31 | #endif | ||
| 32 | 	jr $ra | ||
| 33 | 	li $2, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/mips64/longjmp.S created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	_longjmp | ||
| 3 | .global	longjmp | ||
| 4 | .type	_longjmp,@function | ||
| 5 | .type	longjmp,@function | ||
| 6 | _longjmp: | ||
| 7 | longjmp: | ||
| 8 | 	move	$2, $5 | ||
| 9 | |||
| 10 | 	bne	$2, $0, 1f | ||
| 11 | 	nop | ||
| 12 | 	daddu	$2, $2, 1 | ||
| 13 | 1: | ||
| 14 | #ifndef __mips_soft_float | ||
| 15 | 	ldc1	$24, 96($4) | ||
| 16 | 	ldc1	$25, 104($4) | ||
| 17 | 	ldc1	$26, 112($4) | ||
| 18 | 	ldc1	$27, 120($4) | ||
| 19 | 	ldc1	$28, 128($4) | ||
| 20 | 	ldc1	$29, 136($4) | ||
| 21 | 	ldc1	$30, 144($4) | ||
| 22 | 	ldc1	$31, 152($4) | ||
| 23 | #endif | ||
| 24 | 	ld	$ra, 0($4) | ||
| 25 | 	ld	$sp, 8($4) | ||
| 26 | 	ld	$gp, 16($4) | ||
| 27 | 	ld	$16, 24($4) | ||
| 28 | 	ld	$17, 32($4) | ||
| 29 | 	ld	$18, 40($4) | ||
| 30 | 	ld	$19, 48($4) | ||
| 31 | 	ld	$20, 56($4) | ||
| 32 | 	ld	$21, 64($4) | ||
| 33 | 	ld	$22, 72($4) | ||
| 34 | 	ld	$23, 80($4) | ||
| 35 | 	ld	$30, 88($4) | ||
| 36 | 	jr	$ra | ||
| 37 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/mips64/setjmp.S created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__setjmp | ||
| 3 | .global	_setjmp | ||
| 4 | .global	setjmp | ||
| 5 | .type	__setjmp,@function | ||
| 6 | .type	_setjmp,@function | ||
| 7 | .type	setjmp,@function | ||
| 8 | __setjmp: | ||
| 9 | _setjmp: | ||
| 10 | setjmp: | ||
| 11 | 	sd	$ra, 0($4) | ||
| 12 | 	sd	$sp, 8($4) | ||
| 13 | 	sd	$gp, 16($4) | ||
| 14 | 	sd	$16, 24($4) | ||
| 15 | 	sd	$17, 32($4) | ||
| 16 | 	sd	$18, 40($4) | ||
| 17 | 	sd	$19, 48($4) | ||
| 18 | 	sd	$20, 56($4) | ||
| 19 | 	sd	$21, 64($4) | ||
| 20 | 	sd	$22, 72($4) | ||
| 21 | 	sd	$23, 80($4) | ||
| 22 | 	sd	$30, 88($4) | ||
| 23 | #ifndef __mips_soft_float | ||
| 24 | 	sdc1	$24, 96($4) | ||
| 25 | 	sdc1	$25, 104($4) | ||
| 26 | 	sdc1	$26, 112($4) | ||
| 27 | 	sdc1	$27, 120($4) | ||
| 28 | 	sdc1	$28, 128($4) | ||
| 29 | 	sdc1	$29, 136($4) | ||
| 30 | 	sdc1	$30, 144($4) | ||
| 31 | 	sdc1	$31, 152($4) | ||
| 32 | #endif | ||
| 33 | 	jr	$ra | ||
| 34 | 	li	$2, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/mipsn32/longjmp.S created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	_longjmp | ||
| 3 | .global	longjmp | ||
| 4 | .type	_longjmp,@function | ||
| 5 | .type	longjmp,@function | ||
| 6 | _longjmp: | ||
| 7 | longjmp: | ||
| 8 | 	move	$2, $5 | ||
| 9 | 	bne	$2, $0, 1f | ||
| 10 | 	nop | ||
| 11 | 	addu	$2, $2, 1 | ||
| 12 | 1: | ||
| 13 | #ifndef __mips_soft_float | ||
| 14 | 	ldc1	$24, 96($4) | ||
| 15 | 	ldc1	$25, 104($4) | ||
| 16 | 	ldc1	$26, 112($4) | ||
| 17 | 	ldc1	$27, 120($4) | ||
| 18 | 	ldc1	$28, 128($4) | ||
| 19 | 	ldc1	$29, 136($4) | ||
| 20 | 	ldc1	$30, 144($4) | ||
| 21 | 	ldc1	$31, 152($4) | ||
| 22 | #endif | ||
| 23 | 	ld	$ra, 0($4) | ||
| 24 | 	ld	$sp, 8($4) | ||
| 25 | 	ld	$gp, 16($4) | ||
| 26 | 	ld	$16, 24($4) | ||
| 27 | 	ld	$17, 32($4) | ||
| 28 | 	ld	$18, 40($4) | ||
| 29 | 	ld	$19, 48($4) | ||
| 30 | 	ld	$20, 56($4) | ||
| 31 | 	ld	$21, 64($4) | ||
| 32 | 	ld	$22, 72($4) | ||
| 33 | 	ld	$23, 80($4) | ||
| 34 | 	ld	$30, 88($4) | ||
| 35 | 	jr	$ra | ||
| 36 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/mipsn32/setjmp.S created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__setjmp | ||
| 3 | .global	_setjmp | ||
| 4 | .global	setjmp | ||
| 5 | .type	__setjmp,@function | ||
| 6 | .type	_setjmp,@function | ||
| 7 | .type	setjmp,@function | ||
| 8 | __setjmp: | ||
| 9 | _setjmp: | ||
| 10 | setjmp: | ||
| 11 | 	sd	$ra, 0($4) | ||
| 12 | 	sd	$sp, 8($4) | ||
| 13 | 	sd	$gp, 16($4) | ||
| 14 | 	sd	$16, 24($4) | ||
| 15 | 	sd	$17, 32($4) | ||
| 16 | 	sd	$18, 40($4) | ||
| 17 | 	sd	$19, 48($4) | ||
| 18 | 	sd	$20, 56($4) | ||
| 19 | 	sd	$21, 64($4) | ||
| 20 | 	sd	$22, 72($4) | ||
| 21 | 	sd	$23, 80($4) | ||
| 22 | 	sd	$30, 88($4) | ||
| 23 | #ifndef __mips_soft_float | ||
| 24 | 	sdc1	$24, 96($4) | ||
| 25 | 	sdc1	$25, 104($4) | ||
| 26 | 	sdc1	$26, 112($4) | ||
| 27 | 	sdc1	$27, 120($4) | ||
| 28 | 	sdc1	$28, 128($4) | ||
| 29 | 	sdc1	$29, 136($4) | ||
| 30 | 	sdc1	$30, 144($4) | ||
| 31 | 	sdc1	$31, 152($4) | ||
| 32 | #endif | ||
| 33 | 	jr	$ra | ||
| 34 | 	li	$2, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/or1k/longjmp.s created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | .global _longjmp | ||
| 2 | .global longjmp | ||
| 3 | .type _longjmp,@function | ||
| 4 | .type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	l.sfeqi	r4, 0 | ||
| 8 | 	l.bnf	1f | ||
| 9 | 	 l.addi	r11, r4,0 | ||
| 10 | 	l.ori	r11, r0, 1 | ||
| 11 | 1:	l.lwz	r1, 0(r3) | ||
| 12 | 	l.lwz	r2, 4(r3) | ||
| 13 | 	l.lwz	r9, 8(r3) | ||
| 14 | 	l.lwz	r10, 12(r3) | ||
| 15 | 	l.lwz	r14, 16(r3) | ||
| 16 | 	l.lwz	r16, 20(r3) | ||
| 17 | 	l.lwz	r18, 24(r3) | ||
| 18 | 	l.lwz	r20, 28(r3) | ||
| 19 | 	l.lwz	r22, 32(r3) | ||
| 20 | 	l.lwz	r24, 36(r3) | ||
| 21 | 	l.lwz	r26, 40(r3) | ||
| 22 | 	l.lwz	r28, 44(r3) | ||
| 23 | 	l.lwz	r30, 48(r3) | ||
| 24 | 	l.jr	r9 | ||
| 25 | 	 l.nop | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/or1k/setjmp.s created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | .global ___setjmp | ||
| 2 | .hidden ___setjmp | ||
| 3 | .global __setjmp | ||
| 4 | .global _setjmp | ||
| 5 | .global setjmp | ||
| 6 | .type __setjmp,@function | ||
| 7 | .type _setjmp,@function | ||
| 8 | .type setjmp,@function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | 	l.sw	0(r3), r1 | ||
| 14 | 	l.sw	4(r3), r2 | ||
| 15 | 	l.sw	8(r3), r9 | ||
| 16 | 	l.sw	12(r3), r10 | ||
| 17 | 	l.sw	16(r3), r14 | ||
| 18 | 	l.sw	20(r3), r16 | ||
| 19 | 	l.sw	24(r3), r18 | ||
| 20 | 	l.sw	28(r3), r20 | ||
| 21 | 	l.sw	32(r3), r22 | ||
| 22 | 	l.sw	36(r3), r24 | ||
| 23 | 	l.sw	40(r3), r26 | ||
| 24 | 	l.sw	44(r3), r28 | ||
| 25 | 	l.sw	48(r3), r30 | ||
| 26 | 	l.jr	r9 | ||
| 27 | 	 l.ori	r11,r0,0 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc/longjmp.S created+69| ... | @@ -0,0 +1,69 @@ | ||
| 1 | 	.global _longjmp | ||
| 2 | 	.global longjmp | ||
| 3 | 	.type _longjmp,@function | ||
| 4 | 	.type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	/* | ||
| 8 | 	 * void longjmp(jmp_buf env, int val); | ||
| 9 | 	 * put val into return register and restore the env saved in setjmp | ||
| 10 | 	 * if val(r4) is 0, put 1 there. | ||
| 11 | 	 */ | ||
| 12 | 	/* 0) move old return address into r0 */ | ||
| 13 | 	lwz 0, 0(3) | ||
| 14 | 	/* 1) put it into link reg */ | ||
| 15 | 	mtlr 0 | ||
| 16 | 	/* 2 ) restore stack ptr */ | ||
| 17 | 	lwz 1, 4(3) | ||
| 18 | 	/* 3) restore control reg */ | ||
| 19 | 	lwz 0, 8(3) | ||
| 20 | 	mtcr 0 | ||
| 21 | 	/* 4) restore r14-r31 */ | ||
| 22 | 	lwz 14, 12(3) | ||
| 23 | 	lwz 15, 16(3) | ||
| 24 | 	lwz 16, 20(3) | ||
| 25 | 	lwz 17, 24(3) | ||
| 26 | 	lwz 18, 28(3) | ||
| 27 | 	lwz 19, 32(3) | ||
| 28 | 	lwz 20, 36(3) | ||
| 29 | 	lwz 21, 40(3) | ||
| 30 | 	lwz 22, 44(3) | ||
| 31 | 	lwz 23, 48(3) | ||
| 32 | 	lwz 24, 52(3) | ||
| 33 | 	lwz 25, 56(3) | ||
| 34 | 	lwz 26, 60(3) | ||
| 35 | 	lwz 27, 64(3) | ||
| 36 | 	lwz 28, 68(3) | ||
| 37 | 	lwz 29, 72(3) | ||
| 38 | 	lwz 30, 76(3) | ||
| 39 | 	lwz 31, 80(3) | ||
| 40 | #ifndef _SOFT_FLOAT | ||
| 41 | 	lfd 14,88(3) | ||
| 42 | 	lfd 15,96(3) | ||
| 43 | 	lfd 16,104(3) | ||
| 44 | 	lfd 17,112(3) | ||
| 45 | 	lfd 18,120(3) | ||
| 46 | 	lfd 19,128(3) | ||
| 47 | 	lfd 20,136(3) | ||
| 48 | 	lfd 21,144(3) | ||
| 49 | 	lfd 22,152(3) | ||
| 50 | 	lfd 23,160(3) | ||
| 51 | 	lfd 24,168(3) | ||
| 52 | 	lfd 25,176(3) | ||
| 53 | 	lfd 26,184(3) | ||
| 54 | 	lfd 27,192(3) | ||
| 55 | 	lfd 28,200(3) | ||
| 56 | 	lfd 29,208(3) | ||
| 57 | 	lfd 30,216(3) | ||
| 58 | 	lfd 31,224(3) | ||
| 59 | #endif | ||
| 60 | 	/* 5) put val into return reg r3 */ | ||
| 61 | 	mr 3, 4 | ||
| 62 | |||
| 63 | 	/* 6) check if return value is 0, make it 1 in that case */ | ||
| 64 | 	cmpwi cr7, 4, 0 | ||
| 65 | 	bne cr7, 1f | ||
| 66 | 	li 3, 1 | ||
| 67 | 1: | ||
| 68 | 	blr | ||
| 69 | |||
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc/setjmp.S created+63| ... | @@ -0,0 +1,63 @@ | ||
| 1 | 	.global ___setjmp | ||
| 2 | 	.hidden ___setjmp | ||
| 3 | 	.global __setjmp | ||
| 4 | 	.global _setjmp | ||
| 5 | 	.global setjmp | ||
| 6 | 	.type __setjmp,@function | ||
| 7 | 	.type _setjmp,@function | ||
| 8 | 	.type setjmp,@function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | 	/* 0) store IP int 0, then into the jmpbuf pointed to by r3 (first arg) */ | ||
| 14 | 	mflr 0 | ||
| 15 | 	stw 0, 0(3) | ||
| 16 | 	/* 1) store reg1 (SP) */ | ||
| 17 | 	stw 1, 4(3) | ||
| 18 | 	/* 2) store cr */ | ||
| 19 | 	mfcr 0 | ||
| 20 | 	stw 0, 8(3) | ||
| 21 | 	/* 3) store r14-31 */ | ||
| 22 | 	stw 14, 12(3) | ||
| 23 | 	stw 15, 16(3) | ||
| 24 | 	stw 16, 20(3) | ||
| 25 | 	stw 17, 24(3) | ||
| 26 | 	stw 18, 28(3) | ||
| 27 | 	stw 19, 32(3) | ||
| 28 | 	stw 20, 36(3) | ||
| 29 | 	stw 21, 40(3) | ||
| 30 | 	stw 22, 44(3) | ||
| 31 | 	stw 23, 48(3) | ||
| 32 | 	stw 24, 52(3) | ||
| 33 | 	stw 25, 56(3) | ||
| 34 | 	stw 26, 60(3) | ||
| 35 | 	stw 27, 64(3) | ||
| 36 | 	stw 28, 68(3) | ||
| 37 | 	stw 29, 72(3) | ||
| 38 | 	stw 30, 76(3) | ||
| 39 | 	stw 31, 80(3) | ||
| 40 | #ifndef _SOFT_FLOAT | ||
| 41 | 	stfd 14,88(3) | ||
| 42 | 	stfd 15,96(3) | ||
| 43 | 	stfd 16,104(3) | ||
| 44 | 	stfd 17,112(3) | ||
| 45 | 	stfd 18,120(3) | ||
| 46 | 	stfd 19,128(3) | ||
| 47 | 	stfd 20,136(3) | ||
| 48 | 	stfd 21,144(3) | ||
| 49 | 	stfd 22,152(3) | ||
| 50 | 	stfd 23,160(3) | ||
| 51 | 	stfd 24,168(3) | ||
| 52 | 	stfd 25,176(3) | ||
| 53 | 	stfd 26,184(3) | ||
| 54 | 	stfd 27,192(3) | ||
| 55 | 	stfd 28,200(3) | ||
| 56 | 	stfd 29,208(3) | ||
| 57 | 	stfd 30,216(3) | ||
| 58 | 	stfd 31,224(3) | ||
| 59 | #endif | ||
| 60 | 	/* 4) set return value to 0 */ | ||
| 61 | 	li 3, 0 | ||
| 62 | 	/* 5) return */ | ||
| 63 | 	blr | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc64/longjmp.s created+81| ... | @@ -0,0 +1,81 @@ | ||
| 1 | 	.global _longjmp | ||
| 2 | 	.global longjmp | ||
| 3 | 	.type _longjmp,@function | ||
| 4 | 	.type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	# 0) move old return address into the link register | ||
| 8 | 	ld 0, 0*8(3) | ||
| 9 | 	mtlr 0 | ||
| 10 | 	# 1) restore cr | ||
| 11 | 	ld 0, 1*8(3) | ||
| 12 | 	mtcr 0 | ||
| 13 | 	# 2) restore SP | ||
| 14 | 	ld 1, 2*8(3) | ||
| 15 | 	# 3) restore TOC into both r2 and the caller's stack. | ||
| 16 | 	# Which location is required depends on whether setjmp was called | ||
| 17 | 	# locally or non-locally, but it's always safe to restore to both. | ||
| 18 | 	ld 2, 3*8(3) | ||
| 19 | 	std 2, 24(1) | ||
| 20 | 	# 4) restore r14-r31 | ||
| 21 | 	ld 14, 4*8(3) | ||
| 22 | 	ld 15, 5*8(3) | ||
| 23 | 	ld 16, 6*8(3) | ||
| 24 | 	ld 17, 7*8(3) | ||
| 25 | 	ld 18, 8*8(3) | ||
| 26 | 	ld 19, 9*8(3) | ||
| 27 | 	ld 20, 10*8(3) | ||
| 28 | 	ld 21, 11*8(3) | ||
| 29 | 	ld 22, 12*8(3) | ||
| 30 | 	ld 23, 13*8(3) | ||
| 31 | 	ld 24, 14*8(3) | ||
| 32 | 	ld 25, 15*8(3) | ||
| 33 | 	ld 26, 16*8(3) | ||
| 34 | 	ld 27, 17*8(3) | ||
| 35 | 	ld 28, 18*8(3) | ||
| 36 | 	ld 29, 19*8(3) | ||
| 37 | 	ld 30, 20*8(3) | ||
| 38 | 	ld 31, 21*8(3) | ||
| 39 | 	# 5) restore floating point registers f14-f31 | ||
| 40 | 	lfd 14, 22*8(3) | ||
| 41 | 	lfd 15, 23*8(3) | ||
| 42 | 	lfd 16, 24*8(3) | ||
| 43 | 	lfd 17, 25*8(3) | ||
| 44 | 	lfd 18, 26*8(3) | ||
| 45 | 	lfd 19, 27*8(3) | ||
| 46 | 	lfd 20, 28*8(3) | ||
| 47 | 	lfd 21, 29*8(3) | ||
| 48 | 	lfd 22, 30*8(3) | ||
| 49 | 	lfd 23, 31*8(3) | ||
| 50 | 	lfd 24, 32*8(3) | ||
| 51 | 	lfd 25, 33*8(3) | ||
| 52 | 	lfd 26, 34*8(3) | ||
| 53 | 	lfd 27, 35*8(3) | ||
| 54 | 	lfd 28, 36*8(3) | ||
| 55 | 	lfd 29, 37*8(3) | ||
| 56 | 	lfd 30, 38*8(3) | ||
| 57 | 	lfd 31, 39*8(3) | ||
| 58 | |||
| 59 | 	# 6) restore vector registers v20-v31 | ||
| 60 | 	addi 3, 3, 40*8 | ||
| 61 | 	lvx 20, 0, 3 ; addi 3, 3, 16 | ||
| 62 | 	lvx 21, 0, 3 ; addi 3, 3, 16 | ||
| 63 | 	lvx 22, 0, 3 ; addi 3, 3, 16 | ||
| 64 | 	lvx 23, 0, 3 ; addi 3, 3, 16 | ||
| 65 | 	lvx 24, 0, 3 ; addi 3, 3, 16 | ||
| 66 | 	lvx 25, 0, 3 ; addi 3, 3, 16 | ||
| 67 | 	lvx 26, 0, 3 ; addi 3, 3, 16 | ||
| 68 | 	lvx 27, 0, 3 ; addi 3, 3, 16 | ||
| 69 | 	lvx 28, 0, 3 ; addi 3, 3, 16 | ||
| 70 | 	lvx 29, 0, 3 ; addi 3, 3, 16 | ||
| 71 | 	lvx 30, 0, 3 ; addi 3, 3, 16 | ||
| 72 | 	lvx 31, 0, 3 | ||
| 73 | |||
| 74 | 	# 7) return r4 ? r4 : 1 | ||
| 75 | 	mr 3, 4 | ||
| 76 | 	cmpwi cr7, 4, 0 | ||
| 77 | 	bne cr7, 1f | ||
| 78 | 	li 3, 1 | ||
| 79 | 1: | ||
| 80 | 	blr | ||
| 81 | |||
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc64/setjmp.s created+89| ... | @@ -0,0 +1,89 @@ | ||
| 1 | 	.global __setjmp | ||
| 2 | 	.global _setjmp | ||
| 3 | 	.global setjmp | ||
| 4 | 	.type __setjmp,@function | ||
| 5 | 	.type _setjmp,@function | ||
| 6 | 	.type setjmp,@function | ||
| 7 | __setjmp: | ||
| 8 | _setjmp: | ||
| 9 | setjmp: | ||
| 10 | 	ld 5, 24(1) # load from the TOC slot in the caller's stack frame | ||
| 11 | 	b __setjmp_toc | ||
| 12 | |||
| 13 | 	.localentry __setjmp,.-__setjmp | ||
| 14 | 	.localentry _setjmp,.-_setjmp | ||
| 15 | 	.localentry setjmp,.-setjmp | ||
| 16 | 	mr 5, 2 | ||
| 17 | |||
| 18 | 	.global __setjmp_toc | ||
| 19 | 	.hidden __setjmp_toc | ||
| 20 | 	# same as normal setjmp, except TOC pointer to save is provided in r5. | ||
| 21 | 	# r4 would normally be the 2nd parameter, but we're using r5 to simplify calling from sigsetjmp. | ||
| 22 | 	# solves the problem of knowing whether to save the TOC pointer from r2 or the caller's stack frame. | ||
| 23 | __setjmp_toc: | ||
| 24 | 	# 0) store IP into 0, then into the jmpbuf pointed to by r3 (first arg) | ||
| 25 | 	mflr 0 | ||
| 26 | 	std 0, 0*8(3) | ||
| 27 | 	# 1) store cr | ||
| 28 | 	mfcr 0 | ||
| 29 | 	std 0, 1*8(3) | ||
| 30 | 	# 2) store SP and TOC | ||
| 31 | 	std 1, 2*8(3) | ||
| 32 | 	std 5, 3*8(3) | ||
| 33 | 	# 3) store r14-31 | ||
| 34 | 	std 14, 4*8(3) | ||
| 35 | 	std 15, 5*8(3) | ||
| 36 | 	std 16, 6*8(3) | ||
| 37 | 	std 17, 7*8(3) | ||
| 38 | 	std 18, 8*8(3) | ||
| 39 | 	std 19, 9*8(3) | ||
| 40 | 	std 20, 10*8(3) | ||
| 41 | 	std 21, 11*8(3) | ||
| 42 | 	std 22, 12*8(3) | ||
| 43 | 	std 23, 13*8(3) | ||
| 44 | 	std 24, 14*8(3) | ||
| 45 | 	std 25, 15*8(3) | ||
| 46 | 	std 26, 16*8(3) | ||
| 47 | 	std 27, 17*8(3) | ||
| 48 | 	std 28, 18*8(3) | ||
| 49 | 	std 29, 19*8(3) | ||
| 50 | 	std 30, 20*8(3) | ||
| 51 | 	std 31, 21*8(3) | ||
| 52 | 	# 4) store floating point registers f14-f31 | ||
| 53 | 	stfd 14, 22*8(3) | ||
| 54 | 	stfd 15, 23*8(3) | ||
| 55 | 	stfd 16, 24*8(3) | ||
| 56 | 	stfd 17, 25*8(3) | ||
| 57 | 	stfd 18, 26*8(3) | ||
| 58 | 	stfd 19, 27*8(3) | ||
| 59 | 	stfd 20, 28*8(3) | ||
| 60 | 	stfd 21, 29*8(3) | ||
| 61 | 	stfd 22, 30*8(3) | ||
| 62 | 	stfd 23, 31*8(3) | ||
| 63 | 	stfd 24, 32*8(3) | ||
| 64 | 	stfd 25, 33*8(3) | ||
| 65 | 	stfd 26, 34*8(3) | ||
| 66 | 	stfd 27, 35*8(3) | ||
| 67 | 	stfd 28, 36*8(3) | ||
| 68 | 	stfd 29, 37*8(3) | ||
| 69 | 	stfd 30, 38*8(3) | ||
| 70 | 	stfd 31, 39*8(3) | ||
| 71 | |||
| 72 | 	# 5) store vector registers v20-v31 | ||
| 73 | 	addi 3, 3, 40*8 | ||
| 74 | 	stvx 20, 0, 3 ; addi 3, 3, 16 | ||
| 75 | 	stvx 21, 0, 3 ; addi 3, 3, 16 | ||
| 76 | 	stvx 22, 0, 3 ; addi 3, 3, 16 | ||
| 77 | 	stvx 23, 0, 3 ; addi 3, 3, 16 | ||
| 78 | 	stvx 24, 0, 3 ; addi 3, 3, 16 | ||
| 79 | 	stvx 25, 0, 3 ; addi 3, 3, 16 | ||
| 80 | 	stvx 26, 0, 3 ; addi 3, 3, 16 | ||
| 81 | 	stvx 27, 0, 3 ; addi 3, 3, 16 | ||
| 82 | 	stvx 28, 0, 3 ; addi 3, 3, 16 | ||
| 83 | 	stvx 29, 0, 3 ; addi 3, 3, 16 | ||
| 84 | 	stvx 30, 0, 3 ; addi 3, 3, 16 | ||
| 85 | 	stvx 31, 0, 3 | ||
| 86 | |||
| 87 | 	# 6) return 0 | ||
| 88 | 	li 3, 0 | ||
| 89 | 	blr | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/riscv64/longjmp.S created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | .global __longjmp | ||
| 2 | .global _longjmp | ||
| 3 | .global longjmp | ||
| 4 | .type __longjmp, %function | ||
| 5 | .type _longjmp, %function | ||
| 6 | .type longjmp, %function | ||
| 7 | __longjmp: | ||
| 8 | _longjmp: | ||
| 9 | longjmp: | ||
| 10 | 	ld s0, 0(a0) | ||
| 11 | 	ld s1, 8(a0) | ||
| 12 | 	ld s2, 16(a0) | ||
| 13 | 	ld s3, 24(a0) | ||
| 14 | 	ld s4, 32(a0) | ||
| 15 | 	ld s5, 40(a0) | ||
| 16 | 	ld s6, 48(a0) | ||
| 17 | 	ld s7, 56(a0) | ||
| 18 | 	ld s8, 64(a0) | ||
| 19 | 	ld s9, 72(a0) | ||
| 20 | 	ld s10, 80(a0) | ||
| 21 | 	ld s11, 88(a0) | ||
| 22 | 	ld sp, 96(a0) | ||
| 23 | 	ld ra, 104(a0) | ||
| 24 | |||
| 25 | #ifndef __riscv_float_abi_soft | ||
| 26 | 	fld fs0, 112(a0) | ||
| 27 | 	fld fs1, 120(a0) | ||
| 28 | 	fld fs2, 128(a0) | ||
| 29 | 	fld fs3, 136(a0) | ||
| 30 | 	fld fs4, 144(a0) | ||
| 31 | 	fld fs5, 152(a0) | ||
| 32 | 	fld fs6, 160(a0) | ||
| 33 | 	fld fs7, 168(a0) | ||
| 34 | 	fld fs8, 176(a0) | ||
| 35 | 	fld fs9, 184(a0) | ||
| 36 | 	fld fs10, 192(a0) | ||
| 37 | 	fld fs11, 200(a0) | ||
| 38 | #endif | ||
| 39 | |||
| 40 | 	seqz a0, a1 | ||
| 41 | 	add a0, a0, a1 | ||
| 42 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/riscv64/setjmp.S created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | .global __setjmp | ||
| 2 | .global _setjmp | ||
| 3 | .global setjmp | ||
| 4 | .type __setjmp, %function | ||
| 5 | .type _setjmp, %function | ||
| 6 | .type setjmp, %function | ||
| 7 | __setjmp: | ||
| 8 | _setjmp: | ||
| 9 | setjmp: | ||
| 10 | 	sd s0, 0(a0) | ||
| 11 | 	sd s1, 8(a0) | ||
| 12 | 	sd s2, 16(a0) | ||
| 13 | 	sd s3, 24(a0) | ||
| 14 | 	sd s4, 32(a0) | ||
| 15 | 	sd s5, 40(a0) | ||
| 16 | 	sd s6, 48(a0) | ||
| 17 | 	sd s7, 56(a0) | ||
| 18 | 	sd s8, 64(a0) | ||
| 19 | 	sd s9, 72(a0) | ||
| 20 | 	sd s10, 80(a0) | ||
| 21 | 	sd s11, 88(a0) | ||
| 22 | 	sd sp, 96(a0) | ||
| 23 | 	sd ra, 104(a0) | ||
| 24 | |||
| 25 | #ifndef __riscv_float_abi_soft | ||
| 26 | 	fsd fs0, 112(a0) | ||
| 27 | 	fsd fs1, 120(a0) | ||
| 28 | 	fsd fs2, 128(a0) | ||
| 29 | 	fsd fs3, 136(a0) | ||
| 30 | 	fsd fs4, 144(a0) | ||
| 31 | 	fsd fs5, 152(a0) | ||
| 32 | 	fsd fs6, 160(a0) | ||
| 33 | 	fsd fs7, 168(a0) | ||
| 34 | 	fsd fs8, 176(a0) | ||
| 35 | 	fsd fs9, 184(a0) | ||
| 36 | 	fsd fs10, 192(a0) | ||
| 37 | 	fsd fs11, 200(a0) | ||
| 38 | #endif | ||
| 39 | |||
| 40 | 	li a0, 0 | ||
| 41 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/s390x/longjmp.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | 	.global _longjmp | ||
| 2 | 	.global longjmp | ||
| 3 | 	.type _longjmp,@function | ||
| 4 | 	.type longjmp,@function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | |||
| 8 | 1: | ||
| 9 | 	lmg %r6, %r15, 0(%r2) | ||
| 10 | |||
| 11 | 	ld %f8, 10*8(%r2) | ||
| 12 | 	ld %f9, 11*8(%r2) | ||
| 13 | 	ld %f10, 12*8(%r2) | ||
| 14 | 	ld %f11, 13*8(%r2) | ||
| 15 | 	ld %f12, 14*8(%r2) | ||
| 16 | 	ld %f13, 15*8(%r2) | ||
| 17 | 	ld %f14, 16*8(%r2) | ||
| 18 | 	ld %f15, 17*8(%r2) | ||
| 19 | |||
| 20 | 	ltgr %r2, %r3 | ||
| 21 | 	bnzr %r14 | ||
| 22 | 	lhi %r2, 1 | ||
| 23 | 	br %r14 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/s390x/setjmp.s created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | 	.global ___setjmp | ||
| 2 | 	.hidden ___setjmp | ||
| 3 | 	.global __setjmp | ||
| 4 | 	.global _setjmp | ||
| 5 | 	.global setjmp | ||
| 6 | 	.type __setjmp,@function | ||
| 7 | 	.type _setjmp,@function | ||
| 8 | 	.type setjmp,@function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | 	stmg %r6, %r15, 0(%r2) | ||
| 14 | |||
| 15 | 	std %f8, 10*8(%r2) | ||
| 16 | 	std %f9, 11*8(%r2) | ||
| 17 | 	std %f10, 12*8(%r2) | ||
| 18 | 	std %f11, 13*8(%r2) | ||
| 19 | 	std %f12, 14*8(%r2) | ||
| 20 | 	std %f13, 15*8(%r2) | ||
| 21 | 	std %f14, 16*8(%r2) | ||
| 22 | 	std %f15, 17*8(%r2) | ||
| 23 | |||
| 24 | 	lghi %r2, 0 | ||
| 25 | 	br %r14 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/setjmp.c createdlib/libc/wasi/libc-top-half/musl/src/setjmp/sh/longjmp.S created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | .global _longjmp | ||
| 2 | .global longjmp | ||
| 3 | .type _longjmp, @function | ||
| 4 | .type longjmp, @function | ||
| 5 | _longjmp: | ||
| 6 | longjmp: | ||
| 7 | 	mov.l @r4+, r8 | ||
| 8 | 	mov.l @r4+, r9 | ||
| 9 | 	mov.l @r4+, r10 | ||
| 10 | 	mov.l @r4+, r11 | ||
| 11 | 	mov.l @r4+, r12 | ||
| 12 | 	mov.l @r4+, r13 | ||
| 13 | 	mov.l @r4+, r14 | ||
| 14 | 	mov.l @r4+, r15 | ||
| 15 | 	lds.l @r4+, pr | ||
| 16 | #if __SH_FPU_ANY__ || __SH4__ | ||
| 17 | 	fmov.s @r4+, fr12 | ||
| 18 | 	fmov.s @r4+, fr13 | ||
| 19 | 	fmov.s @r4+, fr14 | ||
| 20 | 	fmov.s @r4+, fr15 | ||
| 21 | #endif | ||
| 22 | |||
| 23 | 	tst r5, r5 | ||
| 24 | 	movt r0 | ||
| 25 | 	add r5, r0 | ||
| 26 | |||
| 27 | 	rts | ||
| 28 | 	 nop | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/sh/setjmp.S created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | .global ___setjmp | ||
| 2 | .hidden ___setjmp | ||
| 3 | .global __setjmp | ||
| 4 | .global _setjmp | ||
| 5 | .global setjmp | ||
| 6 | .type __setjmp, @function | ||
| 7 | .type _setjmp, @function | ||
| 8 | .type setjmp, @function | ||
| 9 | ___setjmp: | ||
| 10 | __setjmp: | ||
| 11 | _setjmp: | ||
| 12 | setjmp: | ||
| 13 | #if __SH_FPU_ANY__ || __SH4__ | ||
| 14 | 	add #52, r4 | ||
| 15 | 	fmov.s fr15, @-r4 | ||
| 16 | 	fmov.s fr14, @-r4 | ||
| 17 | 	fmov.s fr13, @-r4 | ||
| 18 | 	fmov.s fr12, @-r4 | ||
| 19 | #else | ||
| 20 | 	add #36, r4 | ||
| 21 | #endif | ||
| 22 | 	sts.l pr, @-r4 | ||
| 23 | 	mov.l r15, @-r4 | ||
| 24 | 	mov.l r14, @-r4 | ||
| 25 | 	mov.l r13, @-r4 | ||
| 26 | 	mov.l r12, @-r4 | ||
| 27 | 	mov.l r11, @-r4 | ||
| 28 | 	mov.l r10, @-r4 | ||
| 29 | 	mov.l r9, @-r4 | ||
| 30 | 	mov.l r8, @-r4 | ||
| 31 | 	rts | ||
| 32 | 	 mov #0, r0 | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/x32/longjmp.s created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .global _longjmp | ||
| 3 | .global longjmp | ||
| 4 | .type _longjmp,@function | ||
| 5 | .type longjmp,@function | ||
| 6 | _longjmp: | ||
| 7 | longjmp: | ||
| 8 | 	xor %eax,%eax | ||
| 9 | 	cmp $1,%esi /* CF = val ? 0 : 1 */ | ||
| 10 | 	adc %esi,%eax /* eax = val + !val */ | ||
| 11 | 	mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */ | ||
| 12 | 	mov 8(%rdi),%rbp | ||
| 13 | 	mov 16(%rdi),%r12 | ||
| 14 | 	mov 24(%rdi),%r13 | ||
| 15 | 	mov 32(%rdi),%r14 | ||
| 16 | 	mov 40(%rdi),%r15 | ||
| 17 | 	mov 48(%rdi),%rsp | ||
| 18 | 	jmp *56(%rdi) /* goto saved address without altering rsp */ | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/x32/setjmp.s created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .global __setjmp | ||
| 3 | .global _setjmp | ||
| 4 | .global setjmp | ||
| 5 | .type __setjmp,@function | ||
| 6 | .type _setjmp,@function | ||
| 7 | .type setjmp,@function | ||
| 8 | __setjmp: | ||
| 9 | _setjmp: | ||
| 10 | setjmp: | ||
| 11 | 	mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */ | ||
| 12 | 	mov %rbp,8(%rdi) | ||
| 13 | 	mov %r12,16(%rdi) | ||
| 14 | 	mov %r13,24(%rdi) | ||
| 15 | 	mov %r14,32(%rdi) | ||
| 16 | 	mov %r15,40(%rdi) | ||
| 17 | 	lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */ | ||
| 18 | 	mov %rdx,48(%rdi) | ||
| 19 | 	mov (%rsp),%rdx /* save return addr ptr for new rip */ | ||
| 20 | 	mov %rdx,56(%rdi) | ||
| 21 | 	xor %eax,%eax /* always return 0 */ | ||
| 22 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/x86_64/longjmp.s created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .global _longjmp | ||
| 3 | .global longjmp | ||
| 4 | .type _longjmp,@function | ||
| 5 | .type longjmp,@function | ||
| 6 | _longjmp: | ||
| 7 | longjmp: | ||
| 8 | 	xor %eax,%eax | ||
| 9 | 	cmp $1,%esi /* CF = val ? 0 : 1 */ | ||
| 10 | 	adc %esi,%eax /* eax = val + !val */ | ||
| 11 | 	mov (%rdi),%rbx /* rdi is the jmp_buf, restore regs from it */ | ||
| 12 | 	mov 8(%rdi),%rbp | ||
| 13 | 	mov 16(%rdi),%r12 | ||
| 14 | 	mov 24(%rdi),%r13 | ||
| 15 | 	mov 32(%rdi),%r14 | ||
| 16 | 	mov 40(%rdi),%r15 | ||
| 17 | 	mov 48(%rdi),%rsp | ||
| 18 | 	jmp *56(%rdi) /* goto saved address without altering rsp */ | ||
lib/libc/wasi/libc-top-half/musl/src/setjmp/x86_64/setjmp.s created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .global __setjmp | ||
| 3 | .global _setjmp | ||
| 4 | .global setjmp | ||
| 5 | .type __setjmp,@function | ||
| 6 | .type _setjmp,@function | ||
| 7 | .type setjmp,@function | ||
| 8 | __setjmp: | ||
| 9 | _setjmp: | ||
| 10 | setjmp: | ||
| 11 | 	mov %rbx,(%rdi) /* rdi is jmp_buf, move registers onto it */ | ||
| 12 | 	mov %rbp,8(%rdi) | ||
| 13 | 	mov %r12,16(%rdi) | ||
| 14 | 	mov %r13,24(%rdi) | ||
| 15 | 	mov %r14,32(%rdi) | ||
| 16 | 	mov %r15,40(%rdi) | ||
| 17 | 	lea 8(%rsp),%rdx /* this is our rsp WITHOUT current ret addr */ | ||
| 18 | 	mov %rdx,48(%rdi) | ||
| 19 | 	mov (%rsp),%rdx /* save return addr ptr for new rip */ | ||
| 20 | 	mov %rdx,56(%rdi) | ||
| 21 | 	xor %eax,%eax /* always return 0 */ | ||
| 22 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/signal/aarch64/restore.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .global __restore | ||
| 2 | .hidden __restore | ||
| 3 | .type __restore,%function | ||
| 4 | __restore: | ||
| 5 | .global __restore_rt | ||
| 6 | .hidden __restore_rt | ||
| 7 | .type __restore_rt,%function | ||
| 8 | __restore_rt: | ||
| 9 | 	mov x8,#139 // SYS_rt_sigreturn | ||
| 10 | 	svc 0 | ||
lib/libc/wasi/libc-top-half/musl/src/signal/aarch64/sigsetjmp.s created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,%function | ||
| 4 | .type __sigsetjmp,%function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	cbz x1,setjmp | ||
| 8 | |||
| 9 | 	str x30,[x0,#176] | ||
| 10 | 	str x19,[x0,#176+8+8] | ||
| 11 | 	mov x19,x0 | ||
| 12 | |||
| 13 | 	bl setjmp | ||
| 14 | |||
| 15 | 	mov w1,w0 | ||
| 16 | 	mov x0,x19 | ||
| 17 | 	ldr x30,[x0,#176] | ||
| 18 | 	ldr x19,[x0,#176+8+8] | ||
| 19 | |||
| 20 | .hidden __sigsetjmp_tail | ||
| 21 | 	b __sigsetjmp_tail | ||
lib/libc/wasi/libc-top-half/musl/src/signal/arm/restore.s created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | .syntax unified | ||
| 2 | |||
| 3 | .global __restore | ||
| 4 | .hidden __restore | ||
| 5 | .type __restore,%function | ||
| 6 | __restore: | ||
| 7 | 	mov r7,#119 | ||
| 8 | 	swi 0x0 | ||
| 9 | |||
| 10 | .global __restore_rt | ||
| 11 | .hidden __restore_rt | ||
| 12 | .type __restore_rt,%function | ||
| 13 | __restore_rt: | ||
| 14 | 	mov r7,#173 | ||
| 15 | 	swi 0x0 | ||
lib/libc/wasi/libc-top-half/musl/src/signal/arm/sigsetjmp.s created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | .syntax unified | ||
| 2 | .global sigsetjmp | ||
| 3 | .global __sigsetjmp | ||
| 4 | .type sigsetjmp,%function | ||
| 5 | .type __sigsetjmp,%function | ||
| 6 | sigsetjmp: | ||
| 7 | __sigsetjmp: | ||
| 8 | 	tst r1,r1 | ||
| 9 | 	bne 1f | ||
| 10 | 	b setjmp | ||
| 11 | |||
| 12 | 1:	str lr,[r0,#256] | ||
| 13 | 	str r4,[r0,#260+8] | ||
| 14 | 	mov r4,r0 | ||
| 15 | |||
| 16 | 	bl setjmp | ||
| 17 | |||
| 18 | 	mov r1,r0 | ||
| 19 | 	mov r0,r4 | ||
| 20 | 	ldr lr,[r0,#256] | ||
| 21 | 	ldr r4,[r0,#260+8] | ||
| 22 | |||
| 23 | .hidden __sigsetjmp_tail | ||
| 24 | 	b __sigsetjmp_tail | ||
lib/libc/wasi/libc-top-half/musl/src/signal/block.c created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "syscall.h" | ||
| 3 | #include <signal.h> | ||
| 4 | |||
| 5 | static const unsigned long all_mask[] = { | ||
| 6 | #if ULONG_MAX == 0xffffffff && _NSIG == 129 | ||
| 7 | 	-1UL, -1UL, -1UL, -1UL | ||
| 8 | #elif ULONG_MAX == 0xffffffff | ||
| 9 | 	-1UL, -1UL | ||
| 10 | #else | ||
| 11 | 	-1UL | ||
| 12 | #endif | ||
| 13 | }; | ||
| 14 | |||
| 15 | static const unsigned long app_mask[] = { | ||
| 16 | #if ULONG_MAX == 0xffffffff | ||
| 17 | #if _NSIG == 65 | ||
| 18 | 	0x7fffffff, 0xfffffffc | ||
| 19 | #else | ||
| 20 | 	0x7fffffff, 0xfffffffc, -1UL, -1UL | ||
| 21 | #endif | ||
| 22 | #else | ||
| 23 | #if _NSIG == 65 | ||
| 24 | 	0xfffffffc7fffffff | ||
| 25 | #else | ||
| 26 | 	0xfffffffc7fffffff, -1UL | ||
| 27 | #endif | ||
| 28 | #endif | ||
| 29 | }; | ||
| 30 | |||
| 31 | void __block_all_sigs(void *set) | ||
| 32 | { | ||
| 33 | 	__syscall(SYS_rt_sigprocmask, SIG_BLOCK, &all_mask, set, _NSIG/8); | ||
| 34 | } | ||
| 35 | |||
| 36 | void __block_app_sigs(void *set) | ||
| 37 | { | ||
| 38 | 	__syscall(SYS_rt_sigprocmask, SIG_BLOCK, &app_mask, set, _NSIG/8); | ||
| 39 | } | ||
| 40 | |||
| 41 | void __restore_sigs(void *set) | ||
| 42 | { | ||
| 43 | 	__syscall(SYS_rt_sigprocmask, SIG_SETMASK, set, 0, _NSIG/8); | ||
| 44 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/getitimer.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <sys/time.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int getitimer(int which, struct itimerval *old) | ||
| 5 | { | ||
| 6 | 	if (sizeof(time_t) > sizeof(long)) { | ||
| 7 | 		long old32[4]; | ||
| 8 | 		int r = __syscall(SYS_getitimer, which, old32); | ||
| 9 | 		if (!r) { | ||
| 10 | 			old->it_interval.tv_sec = old32[0]; | ||
| 11 | 			old->it_interval.tv_usec = old32[1]; | ||
| 12 | 			old->it_value.tv_sec = old32[2]; | ||
| 13 | 			old->it_value.tv_usec = old32[3]; | ||
| 14 | 		} | ||
| 15 | 		return __syscall_ret(r); | ||
| 16 | 	} | ||
| 17 | 	return syscall(SYS_getitimer, which, old); | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/i386/restore.s created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | .global __restore | ||
| 2 | .hidden __restore | ||
| 3 | .type __restore,@function | ||
| 4 | __restore: | ||
| 5 | 	popl %eax | ||
| 6 | 	movl $119, %eax | ||
| 7 | 	int $0x80 | ||
| 8 | |||
| 9 | .global __restore_rt | ||
| 10 | .hidden __restore_rt | ||
| 11 | .type __restore_rt,@function | ||
| 12 | __restore_rt: | ||
| 13 | 	movl $173, %eax | ||
| 14 | 	int $0x80 | ||
lib/libc/wasi/libc-top-half/musl/src/signal/i386/sigsetjmp.s created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	mov 8(%esp),%ecx | ||
| 8 | 	jecxz 1f | ||
| 9 | |||
| 10 | 	mov 4(%esp),%eax | ||
| 11 | 	popl 24(%eax) | ||
| 12 | 	mov %ebx,28+8(%eax) | ||
| 13 | 	mov %eax,%ebx | ||
| 14 | |||
| 15 | .hidden ___setjmp | ||
| 16 | 	call ___setjmp | ||
| 17 | |||
| 18 | 	pushl 24(%ebx) | ||
| 19 | 	mov %ebx,4(%esp) | ||
| 20 | 	mov %eax,8(%esp) | ||
| 21 | 	mov 28+8(%ebx),%ebx | ||
| 22 | |||
| 23 | .hidden __sigsetjmp_tail | ||
| 24 | 	jmp __sigsetjmp_tail | ||
| 25 | |||
| 26 | 1:	jmp ___setjmp | ||
lib/libc/wasi/libc-top-half/musl/src/signal/kill.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int kill(pid_t pid, int sig) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_kill, pid, sig); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/killpg.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int killpg(pid_t pgid, int sig) | ||
| 5 | { | ||
| 6 | 	if (pgid < 0) { | ||
| 7 | 		errno = EINVAL; | ||
| 8 | 		return -1; | ||
| 9 | 	} | ||
| 10 | 	return kill(-pgid, sig); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/m68k/sigsetjmp.s created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	move.l 8(%sp),%d0 | ||
| 8 | 	beq 1f | ||
| 9 | |||
| 10 | 	movea.l 4(%sp),%a1 | ||
| 11 | 	move.l (%sp)+,156(%a1) | ||
| 12 | 	move.l %a2,156+4+8(%a1) | ||
| 13 | 	movea.l %a1,%a2 | ||
| 14 | |||
| 15 | .hidden ___setjmp | ||
| 16 | 	lea ___setjmp-.-8,%a1 | ||
| 17 | 	jsr (%pc,%a1) | ||
| 18 | |||
| 19 | 	move.l 156(%a2),-(%sp) | ||
| 20 | 	move.l %a2,4(%sp) | ||
| 21 | 	move.l %d0,8(%sp) | ||
| 22 | 	movea.l 156+4+8(%a2),%a2 | ||
| 23 | |||
| 24 | .hidden __sigsetjmp_tail | ||
| 25 | 	lea __sigsetjmp_tail-.-8,%a1 | ||
| 26 | 	jmp (%pc,%a1) | ||
| 27 | |||
| 28 | 1:	lea ___setjmp-.-8,%a1 | ||
| 29 | 	jmp (%pc,%a1) | ||
lib/libc/wasi/libc-top-half/musl/src/signal/microblaze/restore.s created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | .global __restore | ||
| 2 | .hidden __restore | ||
| 3 | .type __restore,@function | ||
| 4 | __restore: | ||
| 5 | 	ori r12, r0, 119 | ||
| 6 | 	brki r14, 0x8 | ||
| 7 | |||
| 8 | .global __restore_rt | ||
| 9 | .hidden __restore_rt | ||
| 10 | .type __restore_rt,@function | ||
| 11 | __restore_rt: | ||
| 12 | 	ori r12, r0, 173 | ||
| 13 | 	brki r14, 0x8 | ||
lib/libc/wasi/libc-top-half/musl/src/signal/microblaze/sigsetjmp.s created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | .hidden ___setjmp | ||
| 8 | 	beqi r6, ___setjmp | ||
| 9 | |||
| 10 | 	swi r15,r5,72 | ||
| 11 | 	swi r19,r5,72+4+8 | ||
| 12 | |||
| 13 | 	brlid r15,___setjmp | ||
| 14 | 	 ori r19,r5,0 | ||
| 15 | |||
| 16 | 	ori r6,r3,0 | ||
| 17 | 	ori r5,r19,0 | ||
| 18 | 	lwi r15,r5,72 | ||
| 19 | 	lwi r19,r5,72+4+8 | ||
| 20 | |||
| 21 | .hidden __sigsetjmp_tail | ||
| 22 | 	bri __sigsetjmp_tail | ||
lib/libc/wasi/libc-top-half/musl/src/signal/mips/restore.s created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | .set noreorder | ||
| 2 | |||
| 3 | .global __restore_rt | ||
| 4 | .hidden __restore_rt | ||
| 5 | .type __restore_rt,@function | ||
| 6 | __restore_rt: | ||
| 7 | 	li $2, 4193 | ||
| 8 | 	syscall | ||
| 9 | |||
| 10 | .global __restore | ||
| 11 | .hidden __restore | ||
| 12 | .type __restore,@function | ||
| 13 | __restore: | ||
| 14 | 	li $2, 4119 | ||
| 15 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/signal/mips/sigsetjmp.s created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | .set noreorder | ||
| 2 | |||
| 3 | .global sigsetjmp | ||
| 4 | .global __sigsetjmp | ||
| 5 | .type sigsetjmp,@function | ||
| 6 | .type __sigsetjmp,@function | ||
| 7 | sigsetjmp: | ||
| 8 | __sigsetjmp: | ||
| 9 | 	lui $gp, %hi(_gp_disp) | ||
| 10 | 	addiu $gp, %lo(_gp_disp) | ||
| 11 | 	beq $5, $0, 1f | ||
| 12 | 	 addu $gp, $gp, $25 | ||
| 13 | |||
| 14 | 	sw $ra, 104($4) | ||
| 15 | 	sw $16, 104+4+16($4) | ||
| 16 | |||
| 17 | 	lw $25, %call16(setjmp)($gp) | ||
| 18 | 	jalr $25 | ||
| 19 | 	 move $16, $4 | ||
| 20 | |||
| 21 | 	move $5,$2 | ||
| 22 | 	move $4,$16 | ||
| 23 | 	lw $ra, 104($4) | ||
| 24 | 	lw $16, 104+4+16($4) | ||
| 25 | |||
| 26 | .hidden __sigsetjmp_tail | ||
| 27 | 	lw $25, %call16(__sigsetjmp_tail)($gp) | ||
| 28 | 	jr $25 | ||
| 29 | 	 nop | ||
| 30 | |||
| 31 | 1:	lw $25, %call16(setjmp)($gp) | ||
| 32 | 	jr $25 | ||
| 33 | 	 nop | ||
lib/libc/wasi/libc-top-half/musl/src/signal/mips64/restore.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__restore_rt | ||
| 3 | .global	__restore | ||
| 4 | .hidden __restore_rt | ||
| 5 | .hidden __restore | ||
| 6 | .type	__restore_rt,@function | ||
| 7 | .type	__restore,@function | ||
| 8 | __restore_rt: | ||
| 9 | __restore: | ||
| 10 | 	li	$2,5211 | ||
| 11 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/signal/mips64/sigsetjmp.s created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	sigsetjmp | ||
| 3 | .global	__sigsetjmp | ||
| 4 | .type	sigsetjmp,@function | ||
| 5 | .type	__sigsetjmp,@function | ||
| 6 | sigsetjmp: | ||
| 7 | __sigsetjmp: | ||
| 8 | 	lui	$3, %hi(%neg(%gp_rel(sigsetjmp))) | ||
| 9 | 	daddiu	$3, $3, %lo(%neg(%gp_rel(sigsetjmp))) | ||
| 10 | |||
| 11 | 	# comparing save mask with 0, if equals to 0 then | ||
| 12 | 	# sigsetjmp is equal to setjmp. | ||
| 13 | 	beq	$5, $0, 1f | ||
| 14 | 	daddu	$3, $3, $25 | ||
| 15 | 	sd	$ra, 160($4) | ||
| 16 | 	sd	$16, 168($4) | ||
| 17 | |||
| 18 | 	# save base of got so that we can use it later | ||
| 19 | 	# once we return from 'longjmp' | ||
| 20 | 	sd	$3, 176($4) | ||
| 21 | 	ld	$25, %got_disp(setjmp)($3) | ||
| 22 | 	jalr	$25 | ||
| 23 | 	move	$16, $4 | ||
| 24 | |||
| 25 | 	move	$5, $2		# Return from 'setjmp' or 'longjmp' | ||
| 26 | 	move	$4, $16		# Restore the pointer-to-sigjmp_buf | ||
| 27 | 	ld	$ra, 160($4)	# Restore ra of sigsetjmp | ||
| 28 | 	ld	$16, 168($4)	# Restore $16 of sigsetjmp | ||
| 29 | 	ld	$3, 176($4)	# Restore base of got | ||
| 30 | |||
| 31 | .hidden	__sigsetjmp_tail | ||
| 32 | 	ld	$25, %got_disp(__sigsetjmp_tail)($3) | ||
| 33 | 	jr	$25 | ||
| 34 | 	nop | ||
| 35 | 1: | ||
| 36 | 	ld	$25, %got_disp(setjmp)($3) | ||
| 37 | 	jr	$25 | ||
| 38 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/signal/mipsn32/restore.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__restore_rt | ||
| 3 | .global	__restore | ||
| 4 | .hidden __restore_rt | ||
| 5 | .hidden __restore | ||
| 6 | .type	__restore_rt,@function | ||
| 7 | .type	__restore,@function | ||
| 8 | __restore_rt: | ||
| 9 | __restore: | ||
| 10 | 	li	$2,6211 | ||
| 11 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/signal/mipsn32/sigsetjmp.s created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	sigsetjmp | ||
| 3 | .global	__sigsetjmp | ||
| 4 | .type	sigsetjmp,@function | ||
| 5 | .type	__sigsetjmp,@function | ||
| 6 | sigsetjmp: | ||
| 7 | __sigsetjmp: | ||
| 8 | 	lui	$3, %hi(%neg(%gp_rel(sigsetjmp))) | ||
| 9 | 	addiu	$3, $3, %lo(%neg(%gp_rel(sigsetjmp))) | ||
| 10 | |||
| 11 | 	# comparing save mask with 0, if equals to 0 then | ||
| 12 | 	# sigsetjmp is equal to setjmp. | ||
| 13 | 	beq	$5, $0, 1f | ||
| 14 | 	addu	$3, $3, $25 | ||
| 15 | 	sd	$ra, 160($4) | ||
| 16 | 	sd	$16, 168($4) | ||
| 17 | |||
| 18 | 	# save base of got so that we can use it later | ||
| 19 | 	# once we return from 'longjmp' | ||
| 20 | 	sd	$3, 176($4) | ||
| 21 | 	lw	$25, %got_disp(setjmp)($3) | ||
| 22 | 	jalr	$25 | ||
| 23 | 	move	$16, $4 | ||
| 24 | |||
| 25 | 	move	$5, $2		# Return from 'setjmp' or 'longjmp' | ||
| 26 | 	move	$4, $16		# Restore the pointer-to-sigjmp_buf | ||
| 27 | 	ld	$ra, 160($4)	# Restore ra of sigsetjmp | ||
| 28 | 	ld	$16, 168($4)	# Restore $16 of sigsetjmp | ||
| 29 | 	ld	$3, 176($4)	# Restore base of got | ||
| 30 | |||
| 31 | .hidden	__sigsetjmp_tail | ||
| 32 | 	lw	$25, %got_disp(__sigsetjmp_tail)($3) | ||
| 33 | 	jr	$25 | ||
| 34 | 	nop | ||
| 35 | 1: | ||
| 36 | 	lw	$25, %got_disp(setjmp)($3) | ||
| 37 | 	jr	$25 | ||
| 38 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/signal/or1k/sigsetjmp.s created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	l.sfeq	r4, r0 | ||
| 8 | .hidden ___setjmp | ||
| 9 | 	l.bf	___setjmp | ||
| 10 | |||
| 11 | 	l.sw 52(r3), r9 | ||
| 12 | 	l.sw 52+4+8(r3), r20 | ||
| 13 | |||
| 14 | 	l.jal	___setjmp | ||
| 15 | 	 l.ori r20, r3, 0 | ||
| 16 | |||
| 17 | 	l.ori r4, r11, 0 | ||
| 18 | 	l.ori r3, r20, 0 | ||
| 19 | |||
| 20 | 	l.lwz r9, 52(r3) | ||
| 21 | |||
| 22 | .hidden __sigsetjmp_tail | ||
| 23 | 	l.j	__sigsetjmp_tail | ||
| 24 | 	 l.lwz r20, 52+4+8(r3) | ||
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc/restore.s created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | 	.global __restore | ||
| 2 | 	.hidden __restore | ||
| 3 | 	.type __restore,%function | ||
| 4 | __restore: | ||
| 5 | 	li 0, 119 #__NR_sigreturn | ||
| 6 | 	sc | ||
| 7 | |||
| 8 | 	.global __restore_rt | ||
| 9 | 	.hidden __restore_rt | ||
| 10 | 	.type __restore_rt,%function | ||
| 11 | __restore_rt: | ||
| 12 | 	li 0, 172 # __NR_rt_sigreturn | ||
| 13 | 	sc | ||
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc/sigsetjmp.s created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | 	.global sigsetjmp | ||
| 2 | 	.global __sigsetjmp | ||
| 3 | 	.type sigsetjmp,%function | ||
| 4 | 	.type __sigsetjmp,%function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	cmpwi cr7, 4, 0 | ||
| 8 | 	beq- cr7, 1f | ||
| 9 | |||
| 10 | 	mflr 5 | ||
| 11 | 	stw 5, 448(3) | ||
| 12 | 	stw 16, 448+4+8(3) | ||
| 13 | 	mr 16, 3 | ||
| 14 | |||
| 15 | .hidden ___setjmp | ||
| 16 | 	bl ___setjmp | ||
| 17 | |||
| 18 | 	mr 4, 3 | ||
| 19 | 	mr 3, 16 | ||
| 20 | 	lwz 5, 448(3) | ||
| 21 | 	mtlr 5 | ||
| 22 | 	lwz 16, 448+4+8(3) | ||
| 23 | |||
| 24 | .hidden __sigsetjmp_tail | ||
| 25 | 	b __sigsetjmp_tail | ||
| 26 | |||
| 27 | 1:	b ___setjmp | ||
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc64/restore.s created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | 	.global __restore | ||
| 2 | 	.hidden __restore | ||
| 3 | 	.type __restore,%function | ||
| 4 | __restore: | ||
| 5 | 	li 0, 119 #__NR_sigreturn | ||
| 6 | 	sc | ||
| 7 | |||
| 8 | 	.global __restore_rt | ||
| 9 | 	.hidden __restore_rt | ||
| 10 | 	.type __restore_rt,%function | ||
| 11 | __restore_rt: | ||
| 12 | 	li 0, 172 # __NR_rt_sigreturn | ||
| 13 | 	sc | ||
lib/libc/wasi/libc-top-half/musl/src/signal/powerpc64/sigsetjmp.s created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | 	.global sigsetjmp | ||
| 2 | 	.global __sigsetjmp | ||
| 3 | 	.type sigsetjmp,%function | ||
| 4 | 	.type __sigsetjmp,%function | ||
| 5 | 	.hidden __setjmp_toc | ||
| 6 | sigsetjmp: | ||
| 7 | __sigsetjmp: | ||
| 8 | 	addis 2, 12, .TOC.-__sigsetjmp@ha | ||
| 9 | 	addi 2, 2, .TOC.-__sigsetjmp@l | ||
| 10 | 	ld 5, 24(1) # load from the TOC slot in the caller's stack frame | ||
| 11 | 	b 1f | ||
| 12 | |||
| 13 | 	.localentry sigsetjmp,.-sigsetjmp | ||
| 14 | 	.localentry __sigsetjmp,.-__sigsetjmp | ||
| 15 | 	mr 5, 2 | ||
| 16 | |||
| 17 | 1: | ||
| 18 | 	cmpwi cr7, 4, 0 | ||
| 19 | 	beq- cr7, __setjmp_toc | ||
| 20 | |||
| 21 | 	mflr 6 | ||
| 22 | 	std 6, 512(3) | ||
| 23 | 	std 2, 512+16(3) | ||
| 24 | 	std 16, 512+24(3) | ||
| 25 | 	mr 16, 3 | ||
| 26 | |||
| 27 | 	bl __setjmp_toc | ||
| 28 | |||
| 29 | 	mr 4, 3 | ||
| 30 | 	mr 3, 16 | ||
| 31 | 	ld 5, 512(3) | ||
| 32 | 	mtlr 5 | ||
| 33 | 	ld 2, 512+16(3) | ||
| 34 | 	ld 16, 512+24(3) | ||
| 35 | |||
| 36 | .hidden __sigsetjmp_tail | ||
| 37 | 	b __sigsetjmp_tail | ||
lib/libc/wasi/libc-top-half/musl/src/signal/psiginfo.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | void psiginfo(const siginfo_t *si, const char *msg) | ||
| 4 | { | ||
| 5 | 	psignal(si->si_signo, msg); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/psignal.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | #include <signal.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | void psignal(int sig, const char *msg) | ||
| 7 | { | ||
| 8 | 	FILE *f = stderr; | ||
| 9 | 	char *s = strsignal(sig); | ||
| 10 | |||
| 11 | 	FLOCK(f); | ||
| 12 | |||
| 13 | 	/* Save stderr's orientation and encoding rule, since psignal is not | ||
| 14 | 	 * permitted to change them. Save errno and restore it if there is no | ||
| 15 | 	 * error since fprintf might change it even on success but psignal is | ||
| 16 | 	 * not permitted to do so. */ | ||
| 17 | 	void *old_locale = f->locale; | ||
| 18 | 	int old_mode = f->mode; | ||
| 19 | 	int old_errno = errno; | ||
| 20 | |||
| 21 | 	if (fprintf(f, "%s%s%s\n", msg?msg:"", msg?": ":"", s)>=0) | ||
| 22 | 		errno = old_errno; | ||
| 23 | 	f->mode = old_mode; | ||
| 24 | 	f->locale = old_locale; | ||
| 25 | |||
| 26 | 	FUNLOCK(f); | ||
| 27 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/raise.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | |||
| 6 | int raise(int sig) | ||
| 7 | { | ||
| 8 | 	sigset_t set; | ||
| 9 | 	__block_app_sigs(&set); | ||
| 10 | 	int ret = syscall(SYS_tkill, __pthread_self()->tid, sig); | ||
| 11 | 	__restore_sigs(&set); | ||
| 12 | 	return ret; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/restore.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <features.h> | ||
| 2 | |||
| 3 | /* These functions will not work, but suffice for targets where the | ||
| 4 | * kernel sigaction structure does not actually use sa_restorer. */ | ||
| 5 | |||
| 6 | hidden void __restore() | ||
| 7 | { | ||
| 8 | } | ||
| 9 | |||
| 10 | hidden void __restore_rt() | ||
| 11 | { | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/riscv64/restore.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | .global __restore | ||
| 2 | .type __restore, %function | ||
| 3 | __restore: | ||
| 4 | .global __restore_rt | ||
| 5 | .type __restore_rt, %function | ||
| 6 | __restore_rt: | ||
| 7 | 	li a7, 139 # SYS_rt_sigreturn | ||
| 8 | 	ecall | ||
lib/libc/wasi/libc-top-half/musl/src/signal/riscv64/sigsetjmp.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp, %function | ||
| 4 | .type __sigsetjmp, %function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	bnez a1, 1f | ||
| 8 | 	tail setjmp | ||
| 9 | 1: | ||
| 10 | |||
| 11 | 	sd ra, 208(a0) | ||
| 12 | 	sd s0, 224(a0) | ||
| 13 | 	mv s0, a0 | ||
| 14 | |||
| 15 | 	call setjmp | ||
| 16 | |||
| 17 | 	mv a1, a0 | ||
| 18 | 	mv a0, s0 | ||
| 19 | 	ld s0, 224(a0) | ||
| 20 | 	ld ra, 208(a0) | ||
| 21 | |||
| 22 | .hidden __sigsetjmp_tail | ||
| 23 | 	tail __sigsetjmp_tail | ||
lib/libc/wasi/libc-top-half/musl/src/signal/s390x/restore.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | 	.global __restore | ||
| 2 | 	.hidden __restore | ||
| 3 | 	.type __restore,%function | ||
| 4 | __restore: | ||
| 5 | 	svc 119 #__NR_sigreturn | ||
| 6 | |||
| 7 | 	.global __restore_rt | ||
| 8 | 	.hidden __restore_rt | ||
| 9 | 	.type __restore_rt,%function | ||
| 10 | __restore_rt: | ||
| 11 | 	svc 173 # __NR_rt_sigreturn | ||
lib/libc/wasi/libc-top-half/musl/src/signal/s390x/sigsetjmp.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | 	.global sigsetjmp | ||
| 2 | 	.global __sigsetjmp | ||
| 3 | 	.type sigsetjmp,%function | ||
| 4 | 	.type __sigsetjmp,%function | ||
| 5 | 	.hidden ___setjmp | ||
| 6 | sigsetjmp: | ||
| 7 | __sigsetjmp: | ||
| 8 | 	ltgr %r3, %r3 | ||
| 9 | 	jz ___setjmp | ||
| 10 | |||
| 11 | 	stg %r14, 18*8(%r2) | ||
| 12 | 	stg %r6, 20*8(%r2) | ||
| 13 | 	lgr %r6, %r2 | ||
| 14 | |||
| 15 | 	brasl %r14, ___setjmp | ||
| 16 | |||
| 17 | 	lgr %r3, %r2 | ||
| 18 | 	lgr %r2, %r6 | ||
| 19 | 	lg %r14, 18*8(%r2) | ||
| 20 | 	lg %r6, 20*8(%r2) | ||
| 21 | |||
| 22 | .hidden __sigsetjmp_tail | ||
| 23 | 	jg __sigsetjmp_tail | ||
lib/libc/wasi/libc-top-half/musl/src/signal/setitimer.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #include <sys/time.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | |||
| 7 | int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old) | ||
| 8 | { | ||
| 9 | 	if (sizeof(time_t) > sizeof(long)) { | ||
| 10 | 		time_t is = new->it_interval.tv_sec, vs = new->it_value.tv_sec; | ||
| 11 | 		long ius = new->it_interval.tv_usec, vus = new->it_value.tv_usec; | ||
| 12 | 		if (!IS32BIT(is) || !IS32BIT(vs)) | ||
| 13 | 			return __syscall_ret(-ENOTSUP); | ||
| 14 | 		long old32[4]; | ||
| 15 | 		int r = __syscall(SYS_setitimer, which, | ||
| 16 | 			((long[]){is, ius, vs, vus}), old32); | ||
| 17 | 		if (!r && old) { | ||
| 18 | 			old->it_interval.tv_sec = old32[0]; | ||
| 19 | 			old->it_interval.tv_usec = old32[1]; | ||
| 20 | 			old->it_value.tv_sec = old32[2]; | ||
| 21 | 			old->it_value.tv_usec = old32[3]; | ||
| 22 | 		} | ||
| 23 | 		return __syscall_ret(r); | ||
| 24 | 	} | ||
| 25 | 	return syscall(SYS_setitimer, which, new, old); | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sh/restore.s created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | .global __restore | ||
| 2 | .hidden __restore | ||
| 3 | __restore: | ||
| 4 | 	mov #119, r3 !__NR_sigreturn | ||
| 5 | 	trapa #31 | ||
| 6 | |||
| 7 | 	or r0, r0 | ||
| 8 | 	or r0, r0 | ||
| 9 | 	or r0, r0 | ||
| 10 | 	or r0, r0 | ||
| 11 | 	or r0, r0 | ||
| 12 | |||
| 13 | .global __restore_rt | ||
| 14 | .hidden __restore_rt | ||
| 15 | __restore_rt: | ||
| 16 | 	mov #100, r3 !__NR_rt_sigreturn | ||
| 17 | 	add #73, r3 | ||
| 18 | 	trapa #31 | ||
| 19 | |||
| 20 | 	or r0, r0 | ||
| 21 | 	or r0, r0 | ||
| 22 | 	or r0, r0 | ||
| 23 | 	or r0, r0 | ||
| 24 | 	or r0, r0 | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sh/sigsetjmp.s created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	tst r5, r5 | ||
| 8 | 	bt 9f | ||
| 9 | |||
| 10 | 	mov r4, r6 | ||
| 11 | 	add #60, r6 | ||
| 12 | 	sts pr, r0 | ||
| 13 | 	mov.l r0, @r6 | ||
| 14 | 	mov.l r8, @(4+8,r6) | ||
| 15 | |||
| 16 | 	mov.l 1f, r0 | ||
| 17 | 2:	bsrf r0 | ||
| 18 | 	 mov r4, r8 | ||
| 19 | |||
| 20 | 	mov r0, r5 | ||
| 21 | 	mov r8, r4 | ||
| 22 | 	mov r4, r6 | ||
| 23 | 	add #60, r6 | ||
| 24 | |||
| 25 | 	mov.l @r6, r0 | ||
| 26 | 	lds r0, pr | ||
| 27 | |||
| 28 | 	mov.l 3f, r0 | ||
| 29 | 4:	braf r0 | ||
| 30 | 	 mov.l @(4+8,r4), r8 | ||
| 31 | |||
| 32 | 9:	mov.l 5f, r0 | ||
| 33 | 6:	braf r0 | ||
| 34 | 	 nop | ||
| 35 | |||
| 36 | .align 2 | ||
| 37 | .hidden ___setjmp | ||
| 38 | 1:	.long ___setjmp@PLT-(2b+4-.) | ||
| 39 | .hidden __sigsetjmp_tail | ||
| 40 | 3:	.long __sigsetjmp_tail@PLT-(4b+4-.) | ||
| 41 | 5:	.long ___setjmp@PLT-(6b+4-.) | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigaction.c created+84| ... | @@ -0,0 +1,84 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | #include "libc.h" | ||
| 7 | #include "lock.h" | ||
| 8 | #include "ksigaction.h" | ||
| 9 | |||
| 10 | static int unmask_done; | ||
| 11 | static unsigned long handler_set[_NSIG/(8*sizeof(long))]; | ||
| 12 | |||
| 13 | void __get_handler_set(sigset_t *set) | ||
| 14 | { | ||
| 15 | 	memcpy(set, handler_set, sizeof handler_set); | ||
| 16 | } | ||
| 17 | |||
| 18 | volatile int __eintr_valid_flag; | ||
| 19 | |||
| 20 | int __libc_sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) | ||
| 21 | { | ||
| 22 | 	struct k_sigaction ksa, ksa_old; | ||
| 23 | 	if (sa) { | ||
| 24 | 		if ((uintptr_t)sa->sa_handler > 1UL) { | ||
| 25 | 			a_or_l(handler_set+(sig-1)/(8*sizeof(long)), | ||
| 26 | 				1UL<<(sig-1)%(8*sizeof(long))); | ||
| 27 | |||
| 28 | 			/* If pthread_create has not yet been called, | ||
| 29 | 			 * implementation-internal signals might not | ||
| 30 | 			 * yet have been unblocked. They must be | ||
| 31 | 			 * unblocked before any signal handler is | ||
| 32 | 			 * installed, so that an application cannot | ||
| 33 | 			 * receive an illegal sigset_t (with them | ||
| 34 | 			 * blocked) as part of the ucontext_t passed | ||
| 35 | 			 * to the signal handler. */ | ||
| 36 | 			if (!libc.threaded && !unmask_done) { | ||
| 37 | 				__syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, | ||
| 38 | 					SIGPT_SET, 0, _NSIG/8); | ||
| 39 | 				unmask_done = 1; | ||
| 40 | 			} | ||
| 41 | |||
| 42 | 			if (!(sa->sa_flags & SA_RESTART)) { | ||
| 43 | 				a_store(&__eintr_valid_flag, 1); | ||
| 44 | 			} | ||
| 45 | 		} | ||
| 46 | 		ksa.handler = sa->sa_handler; | ||
| 47 | 		ksa.flags = sa->sa_flags | SA_RESTORER; | ||
| 48 | 		ksa.restorer = (sa->sa_flags & SA_SIGINFO) ? __restore_rt : __restore; | ||
| 49 | 		memcpy(&ksa.mask, &sa->sa_mask, _NSIG/8); | ||
| 50 | 	} | ||
| 51 | 	int r = __syscall(SYS_rt_sigaction, sig, sa?&ksa:0, old?&ksa_old:0, _NSIG/8); | ||
| 52 | 	if (old && !r) { | ||
| 53 | 		old->sa_handler = ksa_old.handler; | ||
| 54 | 		old->sa_flags = ksa_old.flags; | ||
| 55 | 		memcpy(&old->sa_mask, &ksa_old.mask, _NSIG/8); | ||
| 56 | 	} | ||
| 57 | 	return __syscall_ret(r); | ||
| 58 | } | ||
| 59 | |||
| 60 | int __sigaction(int sig, const struct sigaction *restrict sa, struct sigaction *restrict old) | ||
| 61 | { | ||
| 62 | 	unsigned long set[_NSIG/(8*sizeof(long))]; | ||
| 63 | |||
| 64 | 	if (sig-32U < 3 || sig-1U >= _NSIG-1) { | ||
| 65 | 		errno = EINVAL; | ||
| 66 | 		return -1; | ||
| 67 | 	} | ||
| 68 | |||
| 69 | 	/* Doing anything with the disposition of SIGABRT requires a lock, | ||
| 70 | 	 * so that it cannot be changed while abort is terminating the | ||
| 71 | 	 * process and so any change made by abort can't be observed. */ | ||
| 72 | 	if (sig == SIGABRT) { | ||
| 73 | 		__block_all_sigs(&set); | ||
| 74 | 		LOCK(__abort_lock); | ||
| 75 | 	} | ||
| 76 | 	int r = __libc_sigaction(sig, sa, old); | ||
| 77 | 	if (sig == SIGABRT) { | ||
| 78 | 		UNLOCK(__abort_lock); | ||
| 79 | 		__restore_sigs(&set); | ||
| 80 | 	} | ||
| 81 | 	return r; | ||
| 82 | } | ||
| 83 | |||
| 84 | weak_alias(__sigaction, sigaction); | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigaddset.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int sigaddset(sigset_t *set, int sig) | ||
| 5 | { | ||
| 6 | 	unsigned s = sig-1; | ||
| 7 | 	if (s >= _NSIG-1 || sig-32U < 3) { | ||
| 8 | 		errno = EINVAL; | ||
| 9 | 		return -1; | ||
| 10 | 	} | ||
| 11 | 	set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigaltstack.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int sigaltstack(const stack_t *restrict ss, stack_t *restrict old) | ||
| 6 | { | ||
| 7 | 	if (ss) { | ||
| 8 | 		if (!(ss->ss_flags & SS_DISABLE) && ss->ss_size < MINSIGSTKSZ) { | ||
| 9 | 			errno = ENOMEM; | ||
| 10 | 			return -1; | ||
| 11 | 		} | ||
| 12 | 		if (ss->ss_flags & SS_ONSTACK) { | ||
| 13 | 			errno = EINVAL; | ||
| 14 | 			return -1; | ||
| 15 | 		} | ||
| 16 | 	} | ||
| 17 | 	return syscall(SYS_sigaltstack, ss, old); | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigandset.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <signal.h> | ||
| 3 | |||
| 4 | #define SST_SIZE (_NSIG/8/sizeof(long)) | ||
| 5 | |||
| 6 | int sigandset(sigset_t *dest, const sigset_t *left, const sigset_t *right) | ||
| 7 | { | ||
| 8 | 	unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right; | ||
| 9 | 	for(; i < SST_SIZE; i++) d[i] = l[i] & r[i]; | ||
| 10 | 	return 0; | ||
| 11 | } | ||
| 12 | |||
lib/libc/wasi/libc-top-half/musl/src/signal/sigdelset.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int sigdelset(sigset_t *set, int sig) | ||
| 5 | { | ||
| 6 | 	unsigned s = sig-1; | ||
| 7 | 	if (s >= _NSIG-1 || sig-32U < 3) { | ||
| 8 | 		errno = EINVAL; | ||
| 9 | 		return -1; | ||
| 10 | 	} | ||
| 11 | 	set->__bits[s/8/sizeof *set->__bits] &=~(1UL<<(s&8*sizeof *set->__bits-1)); | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigemptyset.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | int sigemptyset(sigset_t *set) | ||
| 5 | { | ||
| 6 | 	set->__bits[0] = 0; | ||
| 7 | 	if (sizeof(long)==4 || _NSIG > 65) set->__bits[1] = 0; | ||
| 8 | 	if (sizeof(long)==4 && _NSIG > 65) { | ||
| 9 | 		set->__bits[2] = 0; | ||
| 10 | 		set->__bits[3] = 0; | ||
| 11 | 	} | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigfillset.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <limits.h> | ||
| 3 | |||
| 4 | int sigfillset(sigset_t *set) | ||
| 5 | { | ||
| 6 | #if ULONG_MAX == 0xffffffff | ||
| 7 | 	set->__bits[0] = 0x7ffffffful; | ||
| 8 | 	set->__bits[1] = 0xfffffffcul; | ||
| 9 | 	if (_NSIG > 65) { | ||
| 10 | 		set->__bits[2] = 0xfffffffful; | ||
| 11 | 		set->__bits[3] = 0xfffffffful; | ||
| 12 | 	} | ||
| 13 | #else | ||
| 14 | 	set->__bits[0] = 0xfffffffc7ffffffful; | ||
| 15 | 	if (_NSIG > 65) set->__bits[1] = 0xfffffffffffffffful; | ||
| 16 | #endif | ||
| 17 | 	return 0; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sighold.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sighold(int sig) | ||
| 4 | { | ||
| 5 | 	sigset_t mask; | ||
| 6 | |||
| 7 | 	sigemptyset(&mask); | ||
| 8 | 	if (sigaddset(&mask, sig) < 0) return -1; | ||
| 9 | 	return sigprocmask(SIG_BLOCK, &mask, 0); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigignore.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sigignore(int sig) | ||
| 4 | { | ||
| 5 | 	struct sigaction sa; | ||
| 6 | |||
| 7 | 	sigemptyset(&sa.sa_mask); | ||
| 8 | 	sa.sa_handler = SIG_IGN; | ||
| 9 | 	sa.sa_flags = 0; | ||
| 10 | 	return sigaction(sig, &sa, 0); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/siginterrupt.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int siginterrupt(int sig, int flag) | ||
| 4 | { | ||
| 5 | 	struct sigaction sa; | ||
| 6 | |||
| 7 | 	sigaction(sig, 0, &sa); | ||
| 8 | 	if (flag) sa.sa_flags &= ~SA_RESTART; | ||
| 9 | 	else sa.sa_flags |= SA_RESTART; | ||
| 10 | |||
| 11 | 	return sigaction(sig, &sa, 0); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigisemptyset.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <signal.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int sigisemptyset(const sigset_t *set) | ||
| 6 | { | ||
| 7 | 	for (size_t i=0; i<_NSIG/8/sizeof *set->__bits; i++) | ||
| 8 | 		if (set->__bits[i]) return 0; | ||
| 9 | 	return 1; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigismember.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sigismember(const sigset_t *set, int sig) | ||
| 4 | { | ||
| 5 | 	unsigned s = sig-1; | ||
| 6 | 	if (s >= _NSIG-1) return 0; | ||
| 7 | 	return !!(set->__bits[s/8/sizeof *set->__bits] & 1UL<<(s&8*sizeof *set->__bits-1)); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/siglongjmp.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <setjmp.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | |||
| 6 | _Noreturn void siglongjmp(sigjmp_buf buf, int ret) | ||
| 7 | { | ||
| 8 | 	longjmp(buf, ret); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/signal.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | void (*signal(int sig, void (*func)(int)))(int) | ||
| 5 | { | ||
| 6 | 	struct sigaction sa_old, sa = { .sa_handler = func, .sa_flags = SA_RESTART }; | ||
| 7 | 	if (__sigaction(sig, &sa, &sa_old) < 0) | ||
| 8 | 		return SIG_ERR; | ||
| 9 | 	return sa_old.sa_handler; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(signal, bsd_signal); | ||
| 13 | weak_alias(signal, __sysv_signal); | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigorset.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <signal.h> | ||
| 3 | |||
| 4 | #define SST_SIZE (_NSIG/8/sizeof(long)) | ||
| 5 | |||
| 6 | int sigorset(sigset_t *dest, const sigset_t *left, const sigset_t *right) | ||
| 7 | { | ||
| 8 | 	unsigned long i = 0, *d = (void*) dest, *l = (void*) left, *r = (void*) right; | ||
| 9 | 	for(; i < SST_SIZE; i++) d[i] = l[i] | r[i]; | ||
| 10 | 	return 0; | ||
| 11 | } | ||
| 12 | |||
lib/libc/wasi/libc-top-half/musl/src/signal/sigpause.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sigpause(int sig) | ||
| 4 | { | ||
| 5 | 	sigset_t mask; | ||
| 6 | 	sigprocmask(0, 0, &mask); | ||
| 7 | 	sigdelset(&mask, sig); | ||
| 8 | 	return sigsuspend(&mask); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigpending.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int sigpending(sigset_t *set) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_rt_sigpending, set, _NSIG/8); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigprocmask.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int sigprocmask(int how, const sigset_t *restrict set, sigset_t *restrict old) | ||
| 5 | { | ||
| 6 | 	int r = pthread_sigmask(how, set, old); | ||
| 7 | 	if (!r) return r; | ||
| 8 | 	errno = r; | ||
| 9 | 	return -1; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigqueue.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | |||
| 7 | int sigqueue(pid_t pid, int sig, const union sigval value) | ||
| 8 | { | ||
| 9 | 	siginfo_t si; | ||
| 10 | 	sigset_t set; | ||
| 11 | 	int r; | ||
| 12 | 	memset(&si, 0, sizeof si); | ||
| 13 | 	si.si_signo = sig; | ||
| 14 | 	si.si_code = SI_QUEUE; | ||
| 15 | 	si.si_value = value; | ||
| 16 | 	si.si_uid = getuid(); | ||
| 17 | 	__block_app_sigs(&set); | ||
| 18 | 	si.si_pid = getpid(); | ||
| 19 | 	r = syscall(SYS_rt_sigqueueinfo, pid, sig, &si); | ||
| 20 | 	__restore_sigs(&set); | ||
| 21 | 	return r; | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigrelse.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sigrelse(int sig) | ||
| 4 | { | ||
| 5 | 	sigset_t mask; | ||
| 6 | |||
| 7 | 	sigemptyset(&mask); | ||
| 8 | 	if (sigaddset(&mask, sig) < 0) return -1; | ||
| 9 | 	return sigprocmask(SIG_UNBLOCK, &mask, 0); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigrtmax.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int __libc_current_sigrtmax() | ||
| 4 | { | ||
| 5 | 	return _NSIG-1; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigrtmin.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int __libc_current_sigrtmin() | ||
| 4 | { | ||
| 5 | 	return 35; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigset.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | void (*sigset(int sig, void (*handler)(int)))(int) | ||
| 4 | { | ||
| 5 | 	struct sigaction sa, sa_old; | ||
| 6 | 	sigset_t mask, mask_old; | ||
| 7 | |||
| 8 | 	sigemptyset(&mask); | ||
| 9 | 	if (sigaddset(&mask, sig) < 0) | ||
| 10 | 		return SIG_ERR; | ||
| 11 | 	 | ||
| 12 | 	if (handler == SIG_HOLD) { | ||
| 13 | 		if (sigaction(sig, 0, &sa_old) < 0) | ||
| 14 | 			return SIG_ERR; | ||
| 15 | 		if (sigprocmask(SIG_BLOCK, &mask, &mask_old) < 0) | ||
| 16 | 			return SIG_ERR; | ||
| 17 | 	} else { | ||
| 18 | 		sa.sa_handler = handler; | ||
| 19 | 		sa.sa_flags = 0; | ||
| 20 | 		sigemptyset(&sa.sa_mask); | ||
| 21 | 		if (sigaction(sig, &sa, &sa_old) < 0) | ||
| 22 | 			return SIG_ERR; | ||
| 23 | 		if (sigprocmask(SIG_UNBLOCK, &mask, &mask_old) < 0) | ||
| 24 | 			return SIG_ERR; | ||
| 25 | 	} | ||
| 26 | 	return sigismember(&mask_old, sig) ? SIG_HOLD : sa_old.sa_handler; | ||
| 27 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigsetjmp.c createdlib/libc/wasi/libc-top-half/musl/src/signal/sigsetjmp_tail.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <setjmp.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | hidden int __sigsetjmp_tail(sigjmp_buf jb, int ret) | ||
| 6 | { | ||
| 7 | 	void *p = jb->__ss; | ||
| 8 | 	__syscall(SYS_rt_sigprocmask, SIG_SETMASK, ret?p:0, ret?0:p, _NSIG/8); | ||
| 9 | 	return ret; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigsuspend.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int sigsuspend(const sigset_t *mask) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_rt_sigsuspend, mask, _NSIG/8); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigtimedwait.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 7 | |||
| 8 | static int do_sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict ts) | ||
| 9 | { | ||
| 10 | #ifdef SYS_rt_sigtimedwait_time64 | ||
| 11 | 	time_t s = ts ? ts->tv_sec : 0; | ||
| 12 | 	long ns = ts ? ts->tv_nsec : 0; | ||
| 13 | 	int r = -ENOSYS; | ||
| 14 | 	if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || !IS32BIT(s)) | ||
| 15 | 		r = __syscall_cp(SYS_rt_sigtimedwait_time64, mask, si, | ||
| 16 | 			ts ? ((long long[]){s, ns}) : 0, _NSIG/8); | ||
| 17 | 	if (SYS_rt_sigtimedwait == SYS_rt_sigtimedwait_time64 || r!=-ENOSYS) | ||
| 18 | 		return r; | ||
| 19 | 	return __syscall_cp(SYS_rt_sigtimedwait, mask, si, | ||
| 20 | 		ts ? ((long[]){CLAMP(s), ns}) : 0, _NSIG/8);; | ||
| 21 | #else | ||
| 22 | 	return __syscall_cp(SYS_rt_sigtimedwait, mask, si, ts, _NSIG/8); | ||
| 23 | #endif | ||
| 24 | } | ||
| 25 | |||
| 26 | int sigtimedwait(const sigset_t *restrict mask, siginfo_t *restrict si, const struct timespec *restrict timeout) | ||
| 27 | { | ||
| 28 | 	int ret; | ||
| 29 | 	do ret = do_sigtimedwait(mask, si, timeout); | ||
| 30 | 	while (ret==-EINTR); | ||
| 31 | 	return __syscall_ret(ret); | ||
| 32 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigwait.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sigwait(const sigset_t *restrict mask, int *restrict sig) | ||
| 4 | { | ||
| 5 | 	siginfo_t si; | ||
| 6 | 	if (sigtimedwait(mask, &si, 0) < 0) | ||
| 7 | 		return -1; | ||
| 8 | 	*sig = si.si_signo; | ||
| 9 | 	return 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/sigwaitinfo.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | |||
| 3 | int sigwaitinfo(const sigset_t *restrict mask, siginfo_t *restrict si) | ||
| 4 | { | ||
| 5 | 	return sigtimedwait(mask, si, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/x32/getitimer.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/time.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int getitimer(int which, struct itimerval *old) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_getitimer, which, old); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/x32/restore.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | 	nop | ||
| 2 | .global __restore_rt | ||
| 3 | .hidden __restore_rt | ||
| 4 | .type __restore_rt,@function | ||
| 5 | __restore_rt: | ||
| 6 | 	mov $0x40000201, %rax /* SYS_rt_sigreturn */ | ||
| 7 | 	syscall | ||
| 8 | .size __restore_rt,.-__restore_rt | ||
lib/libc/wasi/libc-top-half/musl/src/signal/x32/setitimer.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/time.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int setitimer(int which, const struct itimerval *restrict new, struct itimerval *restrict old) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_setitimer, which, new, old); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/signal/x32/sigsetjmp.s created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	test %esi,%esi | ||
| 8 | 	jz 1f | ||
| 9 | |||
| 10 | 	popq 64(%rdi) | ||
| 11 | 	mov %rbx,72+8(%rdi) | ||
| 12 | 	mov %rdi,%rbx | ||
| 13 | |||
| 14 | 	call setjmp@PLT | ||
| 15 | |||
| 16 | 	pushq 64(%rbx) | ||
| 17 | 	movl $0, 4(%rsp) | ||
| 18 | 	mov %rbx,%rdi | ||
| 19 | 	mov %eax,%esi | ||
| 20 | 	mov 72+8(%rbx),%rbx | ||
| 21 | |||
| 22 | .hidden __sigsetjmp_tail | ||
| 23 | 	jmp __sigsetjmp_tail | ||
| 24 | |||
| 25 | 1:	jmp setjmp@PLT | ||
lib/libc/wasi/libc-top-half/musl/src/signal/x86_64/restore.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | 	nop | ||
| 2 | .global __restore_rt | ||
| 3 | .hidden __restore_rt | ||
| 4 | .type __restore_rt,@function | ||
| 5 | __restore_rt: | ||
| 6 | 	mov $15, %rax | ||
| 7 | 	syscall | ||
| 8 | .size __restore_rt,.-__restore_rt | ||
lib/libc/wasi/libc-top-half/musl/src/signal/x86_64/sigsetjmp.s created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | .global sigsetjmp | ||
| 2 | .global __sigsetjmp | ||
| 3 | .type sigsetjmp,@function | ||
| 4 | .type __sigsetjmp,@function | ||
| 5 | sigsetjmp: | ||
| 6 | __sigsetjmp: | ||
| 7 | 	test %esi,%esi | ||
| 8 | 	jz 1f | ||
| 9 | |||
| 10 | 	popq 64(%rdi) | ||
| 11 | 	mov %rbx,72+8(%rdi) | ||
| 12 | 	mov %rdi,%rbx | ||
| 13 | |||
| 14 | 	call setjmp@PLT | ||
| 15 | |||
| 16 | 	pushq 64(%rbx) | ||
| 17 | 	mov %rbx,%rdi | ||
| 18 | 	mov %eax,%esi | ||
| 19 | 	mov 72+8(%rbx),%rbx | ||
| 20 | |||
| 21 | .hidden __sigsetjmp_tail | ||
| 22 | 	jmp __sigsetjmp_tail | ||
| 23 | |||
| 24 | 1:	jmp setjmp@PLT | ||
lib/libc/wasi/libc-top-half/musl/src/stat/__xstat.c created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | |||
| 3 | #if !_REDIR_TIME64 | ||
| 4 | |||
| 5 | int __fxstat(int ver, int fd, struct stat *buf) | ||
| 6 | { | ||
| 7 | 	return fstat(fd, buf); | ||
| 8 | } | ||
| 9 | |||
| 10 | int __fxstatat(int ver, int fd, const char *path, struct stat *buf, int flag) | ||
| 11 | { | ||
| 12 | 	return fstatat(fd, path, buf, flag); | ||
| 13 | } | ||
| 14 | |||
| 15 | int __lxstat(int ver, const char *path, struct stat *buf) | ||
| 16 | { | ||
| 17 | 	return lstat(path, buf); | ||
| 18 | } | ||
| 19 | |||
| 20 | int __xstat(int ver, const char *path, struct stat *buf) | ||
| 21 | { | ||
| 22 | 	return stat(path, buf); | ||
| 23 | } | ||
| 24 | |||
| 25 | weak_alias(__fxstat, __fxstat64); | ||
| 26 | weak_alias(__fxstatat, __fxstatat64); | ||
| 27 | weak_alias(__lxstat, __lxstat64); | ||
| 28 | weak_alias(__xstat, __xstat64); | ||
| 29 | |||
| 30 | #endif | ||
| 31 | |||
| 32 | int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev) | ||
| 33 | { | ||
| 34 | 	return mknod(path, mode, *dev); | ||
| 35 | } | ||
| 36 | |||
| 37 | int __xmknodat(int ver, int fd, const char *path, mode_t mode, dev_t *dev) | ||
| 38 | { | ||
| 39 | 	return mknodat(fd, path, mode, *dev); | ||
| 40 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/chmod.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int chmod(const char *path, mode_t mode) | ||
| 6 | { | ||
| 7 | #ifdef SYS_chmod | ||
| 8 | 	return syscall(SYS_chmod, path, mode); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_fchmodat, AT_FDCWD, path, mode); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/fchmod.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int fchmod(int fd, mode_t mode) | ||
| 7 | { | ||
| 8 | 	int ret = __syscall(SYS_fchmod, fd, mode); | ||
| 9 | 	if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) | ||
| 10 | 		return __syscall_ret(ret); | ||
| 11 | |||
| 12 | 	char buf[15+3*sizeof(int)]; | ||
| 13 | 	__procfdname(buf, fd); | ||
| 14 | #ifdef SYS_chmod | ||
| 15 | 	return syscall(SYS_chmod, buf, mode); | ||
| 16 | #else | ||
| 17 | 	return syscall(SYS_fchmodat, AT_FDCWD, buf, mode); | ||
| 18 | #endif | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/fchmodat.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "kstat.h" | ||
| 6 | |||
| 7 | int fchmodat(int fd, const char *path, mode_t mode, int flag) | ||
| 8 | { | ||
| 9 | 	if (!flag) return syscall(SYS_fchmodat, fd, path, mode, flag); | ||
| 10 | |||
| 11 | 	if (flag != AT_SYMLINK_NOFOLLOW) | ||
| 12 | 		return __syscall_ret(-EINVAL); | ||
| 13 | |||
| 14 | 	struct kstat st; | ||
| 15 | 	int ret, fd2; | ||
| 16 | 	char proc[15+3*sizeof(int)]; | ||
| 17 | |||
| 18 | 	if ((ret = __syscall(SYS_fstatat, fd, path, &st, flag))) | ||
| 19 | 		return __syscall_ret(ret); | ||
| 20 | 	if (S_ISLNK(st.st_mode)) | ||
| 21 | 		return __syscall_ret(-EOPNOTSUPP); | ||
| 22 | |||
| 23 | 	if ((fd2 = __syscall(SYS_openat, fd, path, O_RDONLY|O_PATH|O_NOFOLLOW|O_NOCTTY|O_CLOEXEC)) < 0) { | ||
| 24 | 		if (fd2 == -ELOOP) | ||
| 25 | 			return __syscall_ret(-EOPNOTSUPP); | ||
| 26 | 		return __syscall_ret(fd2); | ||
| 27 | 	} | ||
| 28 | |||
| 29 | 	__procfdname(proc, fd2); | ||
| 30 | 	ret = __syscall(SYS_fstatat, AT_FDCWD, proc, &st, 0); | ||
| 31 | 	if (!ret) { | ||
| 32 | 		if (S_ISLNK(st.st_mode)) ret = -EOPNOTSUPP; | ||
| 33 | 		else ret = __syscall(SYS_fchmodat, AT_FDCWD, proc, mode); | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	__syscall(SYS_close, fd2); | ||
| 37 | 	return __syscall_ret(ret); | ||
| 38 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/fstat.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <sys/stat.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int fstat(int fd, struct stat *st) | ||
| 8 | { | ||
| 9 | 	if (fd<0) return __syscall_ret(-EBADF); | ||
| 10 | 	return fstatat(fd, "", st, AT_EMPTY_PATH); | ||
| 11 | } | ||
| 12 | |||
| 13 | #if !_REDIR_TIME64 | ||
| 14 | weak_alias(fstat, fstat64); | ||
| 15 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/stat/fstatat.c created+147| ... | @@ -0,0 +1,147 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <sys/stat.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include <errno.h> | ||
| 6 | #include <stdint.h> | ||
| 7 | #include <sys/sysmacros.h> | ||
| 8 | #include "syscall.h" | ||
| 9 | #include "kstat.h" | ||
| 10 | |||
| 11 | struct statx { | ||
| 12 | 	uint32_t stx_mask; | ||
| 13 | 	uint32_t stx_blksize; | ||
| 14 | 	uint64_t stx_attributes; | ||
| 15 | 	uint32_t stx_nlink; | ||
| 16 | 	uint32_t stx_uid; | ||
| 17 | 	uint32_t stx_gid; | ||
| 18 | 	uint16_t stx_mode; | ||
| 19 | 	uint16_t pad1; | ||
| 20 | 	uint64_t stx_ino; | ||
| 21 | 	uint64_t stx_size; | ||
| 22 | 	uint64_t stx_blocks; | ||
| 23 | 	uint64_t stx_attributes_mask; | ||
| 24 | 	struct { | ||
| 25 | 		int64_t tv_sec; | ||
| 26 | 		uint32_t tv_nsec; | ||
| 27 | 		int32_t pad; | ||
| 28 | 	} stx_atime, stx_btime, stx_ctime, stx_mtime; | ||
| 29 | 	uint32_t stx_rdev_major; | ||
| 30 | 	uint32_t stx_rdev_minor; | ||
| 31 | 	uint32_t stx_dev_major; | ||
| 32 | 	uint32_t stx_dev_minor; | ||
| 33 | 	uint64_t spare[14]; | ||
| 34 | }; | ||
| 35 | |||
| 36 | static int fstatat_statx(int fd, const char *restrict path, struct stat *restrict st, int flag) | ||
| 37 | { | ||
| 38 | 	struct statx stx; | ||
| 39 | |||
| 40 | 	int ret = __syscall(SYS_statx, fd, path, flag, 0x7ff, &stx); | ||
| 41 | 	if (ret) return ret; | ||
| 42 | |||
| 43 | 	*st = (struct stat){ | ||
| 44 | 		.st_dev = makedev(stx.stx_dev_major, stx.stx_dev_minor), | ||
| 45 | 		.st_ino = stx.stx_ino, | ||
| 46 | 		.st_mode = stx.stx_mode, | ||
| 47 | 		.st_nlink = stx.stx_nlink, | ||
| 48 | 		.st_uid = stx.stx_uid, | ||
| 49 | 		.st_gid = stx.stx_gid, | ||
| 50 | 		.st_rdev = makedev(stx.stx_rdev_major, stx.stx_rdev_minor), | ||
| 51 | 		.st_size = stx.stx_size, | ||
| 52 | 		.st_blksize = stx.stx_blksize, | ||
| 53 | 		.st_blocks = stx.stx_blocks, | ||
| 54 | 		.st_atim.tv_sec = stx.stx_atime.tv_sec, | ||
| 55 | 		.st_atim.tv_nsec = stx.stx_atime.tv_nsec, | ||
| 56 | 		.st_mtim.tv_sec = stx.stx_mtime.tv_sec, | ||
| 57 | 		.st_mtim.tv_nsec = stx.stx_mtime.tv_nsec, | ||
| 58 | 		.st_ctim.tv_sec = stx.stx_ctime.tv_sec, | ||
| 59 | 		.st_ctim.tv_nsec = stx.stx_ctime.tv_nsec, | ||
| 60 | #if _REDIR_TIME64 | ||
| 61 | 		.__st_atim32.tv_sec = stx.stx_atime.tv_sec, | ||
| 62 | 		.__st_atim32.tv_nsec = stx.stx_atime.tv_nsec, | ||
| 63 | 		.__st_mtim32.tv_sec = stx.stx_mtime.tv_sec, | ||
| 64 | 		.__st_mtim32.tv_nsec = stx.stx_mtime.tv_nsec, | ||
| 65 | 		.__st_ctim32.tv_sec = stx.stx_ctime.tv_sec, | ||
| 66 | 		.__st_ctim32.tv_nsec = stx.stx_ctime.tv_nsec, | ||
| 67 | #endif | ||
| 68 | 	}; | ||
| 69 | 	return 0; | ||
| 70 | } | ||
| 71 | |||
| 72 | static int fstatat_kstat(int fd, const char *restrict path, struct stat *restrict st, int flag) | ||
| 73 | { | ||
| 74 | 	int ret; | ||
| 75 | 	struct kstat kst; | ||
| 76 | |||
| 77 | 	if (flag==AT_EMPTY_PATH && fd>=0 && !*path) { | ||
| 78 | 		ret = __syscall(SYS_fstat, fd, &kst); | ||
| 79 | 		if (ret==-EBADF && __syscall(SYS_fcntl, fd, F_GETFD)>=0) { | ||
| 80 | 			ret = __syscall(SYS_fstatat, fd, path, &kst, flag); | ||
| 81 | 			if (ret==-EINVAL) { | ||
| 82 | 				char buf[15+3*sizeof(int)]; | ||
| 83 | 				__procfdname(buf, fd); | ||
| 84 | #ifdef SYS_stat | ||
| 85 | 				ret = __syscall(SYS_stat, buf, &kst); | ||
| 86 | #else | ||
| 87 | 				ret = __syscall(SYS_fstatat, AT_FDCWD, buf, &kst, 0); | ||
| 88 | #endif | ||
| 89 | 			} | ||
| 90 | 		} | ||
| 91 | 	} | ||
| 92 | #ifdef SYS_lstat | ||
| 93 | 	else if ((fd == AT_FDCWD || *path=='/') && flag==AT_SYMLINK_NOFOLLOW) | ||
| 94 | 		ret = __syscall(SYS_lstat, path, &kst); | ||
| 95 | #endif | ||
| 96 | #ifdef SYS_stat | ||
| 97 | 	else if ((fd == AT_FDCWD || *path=='/') && !flag) | ||
| 98 | 		ret = __syscall(SYS_stat, path, &kst); | ||
| 99 | #endif | ||
| 100 | 	else ret = __syscall(SYS_fstatat, fd, path, &kst, flag); | ||
| 101 | |||
| 102 | 	if (ret) return ret; | ||
| 103 | |||
| 104 | 	*st = (struct stat){ | ||
| 105 | 		.st_dev = kst.st_dev, | ||
| 106 | 		.st_ino = kst.st_ino, | ||
| 107 | 		.st_mode = kst.st_mode, | ||
| 108 | 		.st_nlink = kst.st_nlink, | ||
| 109 | 		.st_uid = kst.st_uid, | ||
| 110 | 		.st_gid = kst.st_gid, | ||
| 111 | 		.st_rdev = kst.st_rdev, | ||
| 112 | 		.st_size = kst.st_size, | ||
| 113 | 		.st_blksize = kst.st_blksize, | ||
| 114 | 		.st_blocks = kst.st_blocks, | ||
| 115 | 		.st_atim.tv_sec = kst.st_atime_sec, | ||
| 116 | 		.st_atim.tv_nsec = kst.st_atime_nsec, | ||
| 117 | 		.st_mtim.tv_sec = kst.st_mtime_sec, | ||
| 118 | 		.st_mtim.tv_nsec = kst.st_mtime_nsec, | ||
| 119 | 		.st_ctim.tv_sec = kst.st_ctime_sec, | ||
| 120 | 		.st_ctim.tv_nsec = kst.st_ctime_nsec, | ||
| 121 | #if _REDIR_TIME64 | ||
| 122 | 		.__st_atim32.tv_sec = kst.st_atime_sec, | ||
| 123 | 		.__st_atim32.tv_nsec = kst.st_atime_nsec, | ||
| 124 | 		.__st_mtim32.tv_sec = kst.st_mtime_sec, | ||
| 125 | 		.__st_mtim32.tv_nsec = kst.st_mtime_nsec, | ||
| 126 | 		.__st_ctim32.tv_sec = kst.st_ctime_sec, | ||
| 127 | 		.__st_ctim32.tv_nsec = kst.st_ctime_nsec, | ||
| 128 | #endif | ||
| 129 | 	}; | ||
| 130 | |||
| 131 | 	return 0; | ||
| 132 | } | ||
| 133 | |||
| 134 | int fstatat(int fd, const char *restrict path, struct stat *restrict st, int flag) | ||
| 135 | { | ||
| 136 | 	int ret; | ||
| 137 | 	if (sizeof((struct kstat){0}.st_atime_sec) < sizeof(time_t)) { | ||
| 138 | 		ret = fstatat_statx(fd, path, st, flag); | ||
| 139 | 		if (ret!=-ENOSYS) return __syscall_ret(ret); | ||
| 140 | 	} | ||
| 141 | 	ret = fstatat_kstat(fd, path, st, flag); | ||
| 142 | 	return __syscall_ret(ret); | ||
| 143 | } | ||
| 144 | |||
| 145 | #if !_REDIR_TIME64 | ||
| 146 | weak_alias(fstatat, fstatat64); | ||
| 147 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/stat/futimens.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | |||
| 3 | int futimens(int fd, const struct timespec times[2]) | ||
| 4 | { | ||
| 5 | 	return utimensat(fd, 0, times, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/futimesat.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <sys/stat.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int __futimesat(int dirfd, const char *pathname, const struct timeval times[2]) | ||
| 8 | { | ||
| 9 | 	struct timespec ts[2]; | ||
| 10 | 	if (times) { | ||
| 11 | 		int i; | ||
| 12 | 		for (i=0; i<2; i++) { | ||
| 13 | 			if (times[i].tv_usec >= 1000000ULL) | ||
| 14 | 				return __syscall_ret(-EINVAL); | ||
| 15 | 			ts[i].tv_sec = times[i].tv_sec; | ||
| 16 | 			ts[i].tv_nsec = times[i].tv_usec * 1000; | ||
| 17 | 		} | ||
| 18 | 	} | ||
| 19 | 	return utimensat(dirfd, pathname, times ? ts : 0, 0); | ||
| 20 | } | ||
| 21 | |||
| 22 | weak_alias(__futimesat, futimesat); | ||
lib/libc/wasi/libc-top-half/musl/src/stat/lchmod.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <sys/stat.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | |||
| 5 | int lchmod(const char *path, mode_t mode) | ||
| 6 | { | ||
| 7 | 	return fchmodat(AT_FDCWD, path, mode, AT_SYMLINK_NOFOLLOW); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/lstat.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | |||
| 4 | int lstat(const char *restrict path, struct stat *restrict buf) | ||
| 5 | { | ||
| 6 | 	return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW); | ||
| 7 | } | ||
| 8 | |||
| 9 | #if !_REDIR_TIME64 | ||
| 10 | weak_alias(lstat, lstat64); | ||
| 11 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/stat/mkdir.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int mkdir(const char *path, mode_t mode) | ||
| 6 | { | ||
| 7 | #ifdef SYS_mkdir | ||
| 8 | 	return syscall(SYS_mkdir, path, mode); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_mkdirat, AT_FDCWD, path, mode); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/mkdirat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mkdirat(int fd, const char *path, mode_t mode) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_mkdirat, fd, path, mode); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/mkfifo.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | |||
| 3 | int mkfifo(const char *path, mode_t mode) | ||
| 4 | { | ||
| 5 | 	return mknod(path, mode | S_IFIFO, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/mkfifoat.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | |||
| 3 | int mkfifoat(int fd, const char *path, mode_t mode) | ||
| 4 | { | ||
| 5 | 	return mknodat(fd, path, mode | S_IFIFO, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/mknod.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int mknod(const char *path, mode_t mode, dev_t dev) | ||
| 6 | { | ||
| 7 | #ifdef SYS_mknod | ||
| 8 | 	return syscall(SYS_mknod, path, mode, dev); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_mknodat, AT_FDCWD, path, mode, dev); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/mknodat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int mknodat(int fd, const char *path, mode_t mode, dev_t dev) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_mknodat, fd, path, mode, dev); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/stat.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | |||
| 4 | int stat(const char *restrict path, struct stat *restrict buf) | ||
| 5 | { | ||
| 6 | 	return fstatat(AT_FDCWD, path, buf, 0); | ||
| 7 | } | ||
| 8 | |||
| 9 | #if !_REDIR_TIME64 | ||
| 10 | weak_alias(stat, stat64); | ||
| 11 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/stat/statvfs.c created+63| ... | @@ -0,0 +1,63 @@ | ||
| 1 | #include <sys/statvfs.h> | ||
| 2 | #include <sys/statfs.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | static int __statfs(const char *path, struct statfs *buf) | ||
| 6 | { | ||
| 7 | 	*buf = (struct statfs){0}; | ||
| 8 | #ifdef SYS_statfs64 | ||
| 9 | 	return syscall(SYS_statfs64, path, sizeof *buf, buf); | ||
| 10 | #else | ||
| 11 | 	return syscall(SYS_statfs, path, buf); | ||
| 12 | #endif | ||
| 13 | } | ||
| 14 | |||
| 15 | static int __fstatfs(int fd, struct statfs *buf) | ||
| 16 | { | ||
| 17 | 	*buf = (struct statfs){0}; | ||
| 18 | #ifdef SYS_fstatfs64 | ||
| 19 | 	return syscall(SYS_fstatfs64, fd, sizeof *buf, buf); | ||
| 20 | #else | ||
| 21 | 	return syscall(SYS_fstatfs, fd, buf); | ||
| 22 | #endif | ||
| 23 | } | ||
| 24 | |||
| 25 | weak_alias(__statfs, statfs); | ||
| 26 | weak_alias(__fstatfs, fstatfs); | ||
| 27 | |||
| 28 | static void fixup(struct statvfs *out, const struct statfs *in) | ||
| 29 | { | ||
| 30 | 	*out = (struct statvfs){0}; | ||
| 31 | 	out->f_bsize = in->f_bsize; | ||
| 32 | 	out->f_frsize = in->f_frsize ? in->f_frsize : in->f_bsize; | ||
| 33 | 	out->f_blocks = in->f_blocks; | ||
| 34 | 	out->f_bfree = in->f_bfree; | ||
| 35 | 	out->f_bavail = in->f_bavail; | ||
| 36 | 	out->f_files = in->f_files; | ||
| 37 | 	out->f_ffree = in->f_ffree; | ||
| 38 | 	out->f_favail = in->f_ffree; | ||
| 39 | 	out->f_fsid = in->f_fsid.__val[0]; | ||
| 40 | 	out->f_flag = in->f_flags; | ||
| 41 | 	out->f_namemax = in->f_namelen; | ||
| 42 | } | ||
| 43 | |||
| 44 | int statvfs(const char *restrict path, struct statvfs *restrict buf) | ||
| 45 | { | ||
| 46 | 	struct statfs kbuf; | ||
| 47 | 	if (__statfs(path, &kbuf)<0) return -1; | ||
| 48 | 	fixup(buf, &kbuf); | ||
| 49 | 	return 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | int fstatvfs(int fd, struct statvfs *buf) | ||
| 53 | { | ||
| 54 | 	struct statfs kbuf; | ||
| 55 | 	if (__fstatfs(fd, &kbuf)<0) return -1; | ||
| 56 | 	fixup(buf, &kbuf); | ||
| 57 | 	return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | weak_alias(statvfs, statvfs64); | ||
| 61 | weak_alias(statfs, statfs64); | ||
| 62 | weak_alias(fstatvfs, fstatvfs64); | ||
| 63 | weak_alias(fstatfs, fstatfs64); | ||
lib/libc/wasi/libc-top-half/musl/src/stat/umask.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | mode_t umask(mode_t mode) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_umask, mode); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stat/utimensat.c created+60| ... | @@ -0,0 +1,60 @@ | ||
| 1 | #include <sys/stat.h> | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 8 | #define NS_SPECIAL(ns) ((ns)==UTIME_NOW || (ns)==UTIME_OMIT) | ||
| 9 | |||
| 10 | int utimensat(int fd, const char *path, const struct timespec times[2], int flags) | ||
| 11 | { | ||
| 12 | 	int r; | ||
| 13 | 	if (times && times[0].tv_nsec==UTIME_NOW && times[1].tv_nsec==UTIME_NOW) | ||
| 14 | 		times = 0; | ||
| 15 | #ifdef SYS_utimensat_time64 | ||
| 16 | 	r = -ENOSYS; | ||
| 17 | 	time_t s0=0, s1=0; | ||
| 18 | 	long ns0=0, ns1=0; | ||
| 19 | 	if (times) { | ||
| 20 | 		ns0 = times[0].tv_nsec; | ||
| 21 | 		ns1 = times[1].tv_nsec; | ||
| 22 | 		if (!NS_SPECIAL(ns0)) s0 = times[0].tv_sec; | ||
| 23 | 		if (!NS_SPECIAL(ns1)) s1 = times[1].tv_sec; | ||
| 24 | 	} | ||
| 25 | 	if (SYS_utimensat == SYS_utimensat_time64 || !IS32BIT(s0) || !IS32BIT(s1)) | ||
| 26 | 		r = __syscall(SYS_utimensat_time64, fd, path, times ? | ||
| 27 | 			((long long[]){s0, ns0, s1, ns1}) : 0, flags); | ||
| 28 | 	if (SYS_utimensat == SYS_utimensat_time64 || r!=-ENOSYS) | ||
| 29 | 		return __syscall_ret(r); | ||
| 30 | 	if (!IS32BIT(s0) || !IS32BIT(s1)) | ||
| 31 | 		return __syscall_ret(-ENOTSUP); | ||
| 32 | 	r = __syscall(SYS_utimensat, fd, path, | ||
| 33 | 		times ? ((long[]){s0, ns0, s1, ns1}) : 0, flags); | ||
| 34 | #else | ||
| 35 | 	r = __syscall(SYS_utimensat, fd, path, times, flags); | ||
| 36 | #endif | ||
| 37 | |||
| 38 | #ifdef SYS_futimesat | ||
| 39 | 	if (r != -ENOSYS || flags) return __syscall_ret(r); | ||
| 40 | 	long *tv=0, tmp[4]; | ||
| 41 | 	if (times) { | ||
| 42 | 		int i; | ||
| 43 | 		tv = tmp; | ||
| 44 | 		for (i=0; i<2; i++) { | ||
| 45 | 			if (times[i].tv_nsec >= 1000000000ULL) { | ||
| 46 | 				if (NS_SPECIAL(times[i].tv_nsec)) | ||
| 47 | 					return __syscall_ret(-ENOSYS); | ||
| 48 | 				return __syscall_ret(-EINVAL); | ||
| 49 | 			} | ||
| 50 | 			tmp[2*i+0] = times[i].tv_sec; | ||
| 51 | 			tmp[2*i+1] = times[i].tv_nsec / 1000; | ||
| 52 | 		} | ||
| 53 | 	} | ||
| 54 | |||
| 55 | 	r = __syscall(SYS_futimesat, fd, path, tv); | ||
| 56 | 	if (r != -ENOSYS || fd != AT_FDCWD) return __syscall_ret(r); | ||
| 57 | 	r = __syscall(SYS_utimes, path, tv); | ||
| 58 | #endif | ||
| 59 | 	return __syscall_ret(r); | ||
| 60 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__fclose_ca.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int __fclose_ca(FILE *f) | ||
| 4 | { | ||
| 5 | 	return f->close(f); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__fdopen.c created+85| ... | @@ -0,0 +1,85 @@ | ||
| 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/__fmodeflags.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | int __fmodeflags(const char *mode) | ||
| 5 | { | ||
| 6 | 	int flags; | ||
| 7 | 	if (strchr(mode, '+')) flags = O_RDWR; | ||
| 8 | 	else if (*mode == 'r') flags = O_RDONLY; | ||
| 9 | 	else flags = O_WRONLY; | ||
| 10 | 	if (strchr(mode, 'x')) flags |= O_EXCL; | ||
| 11 | 	if (strchr(mode, 'e')) flags |= O_CLOEXEC; | ||
| 12 | 	if (*mode != 'r') flags |= O_CREAT; | ||
| 13 | 	if (*mode == 'w') flags |= O_TRUNC; | ||
| 14 | 	if (*mode == 'a') flags |= O_APPEND; | ||
| 15 | 	return flags; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 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/__lockfile.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | int __lockfile(FILE *f) | ||
| 5 | { | ||
| 6 | 	int owner = f->lock, tid = __pthread_self()->tid; | ||
| 7 | 	if ((owner & ~MAYBE_WAITERS) == tid) | ||
| 8 | 		return 0; | ||
| 9 | 	owner = a_cas(&f->lock, 0, tid); | ||
| 10 | 	if (!owner) return 1; | ||
| 11 | 	while ((owner = a_cas(&f->lock, 0, tid|MAYBE_WAITERS))) { | ||
| 12 | 		if ((owner & MAYBE_WAITERS) || | ||
| 13 | 		 a_cas(&f->lock, owner, owner|MAYBE_WAITERS)==owner) | ||
| 14 | 			__futexwait(&f->lock, owner|MAYBE_WAITERS, 1); | ||
| 15 | 	} | ||
| 16 | 	return 1; | ||
| 17 | } | ||
| 18 | |||
| 19 | void __unlockfile(FILE *f) | ||
| 20 | { | ||
| 21 | 	if (a_swap(&f->lock, 0) & MAYBE_WAITERS) | ||
| 22 | 		__wake(&f->lock, 1, 1); | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__overflow.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int __overflow(FILE *f, int _c) | ||
| 4 | { | ||
| 5 | 	unsigned char c = _c; | ||
| 6 | 	if (!f->wend && __towrite(f)) return EOF; | ||
| 7 | 	if (f->wpos != f->wend && c != f->lbf) return *f->wpos++ = c; | ||
| 8 | 	if (f->write(f, &c, 1)!=1) return EOF; | ||
| 9 | 	return c; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_close.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 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_exit.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | static FILE *volatile dummy_file = 0; | ||
| 4 | weak_alias(dummy_file, __stdin_used); | ||
| 5 | weak_alias(dummy_file, __stdout_used); | ||
| 6 | weak_alias(dummy_file, __stderr_used); | ||
| 7 | |||
| 8 | static void close_file(FILE *f) | ||
| 9 | { | ||
| 10 | 	if (!f) return; | ||
| 11 | 	FFINALLOCK(f); | ||
| 12 | 	if (f->wpos != f->wbase) f->write(f, 0, 0); | ||
| 13 | 	if (f->rpos != f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR); | ||
| 14 | } | ||
| 15 | |||
| 16 | void __stdio_exit(void) | ||
| 17 | { | ||
| 18 | 	FILE *f; | ||
| 19 | 	for (f=*__ofl_lock(); f; f=f->next) close_file(f); | ||
| 20 | 	close_file(__stdin_used); | ||
| 21 | 	close_file(__stdout_used); | ||
| 22 | 	close_file(__stderr_used); | ||
| 23 | } | ||
| 24 | |||
| 25 | weak_alias(__stdio_exit, __stdio_exit_needed); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__stdio_read.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 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 created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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 created+38| ... | @@ -0,0 +1,38 @@ | ||
| 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 created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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/__toread.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <stdio_impl.h> | ||
| 2 | |||
| 3 | int __toread(FILE *f) | ||
| 4 | { | ||
| 5 | 	f->mode |= f->mode-1; | ||
| 6 | 	if (f->wpos != f->wbase) f->write(f, 0, 0); | ||
| 7 | 	f->wpos = f->wbase = f->wend = 0; | ||
| 8 | 	if (f->flags & F_NORD) { | ||
| 9 | 		f->flags |= F_ERR; | ||
| 10 | 		return EOF; | ||
| 11 | 	} | ||
| 12 | 	f->rpos = f->rend = f->buf + f->buf_size; | ||
| 13 | 	return (f->flags & F_EOF) ? EOF : 0; | ||
| 14 | } | ||
| 15 | |||
| 16 | hidden void __toread_needs_stdio_exit() | ||
| 17 | { | ||
| 18 | 	__stdio_exit_needed(); | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__towrite.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int __towrite(FILE *f) | ||
| 4 | { | ||
| 5 | 	f->mode |= f->mode-1; | ||
| 6 | 	if (f->flags & F_NOWR) { | ||
| 7 | 		f->flags |= F_ERR; | ||
| 8 | 		return EOF; | ||
| 9 | 	} | ||
| 10 | 	/* Clear read buffer (easier than summoning nasal demons) */ | ||
| 11 | 	f->rpos = f->rend = 0; | ||
| 12 | |||
| 13 | 	/* Activate write through the buffer. */ | ||
| 14 | 	f->wpos = f->wbase = f->buf; | ||
| 15 | 	f->wend = f->buf + f->buf_size; | ||
| 16 | |||
| 17 | 	return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | hidden void __towrite_needs_stdio_exit() | ||
| 21 | { | ||
| 22 | 	__stdio_exit_needed(); | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/__uflow.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | /* This function assumes it will never be called if there is already | ||
| 4 | * data buffered for reading. */ | ||
| 5 | |||
| 6 | int __uflow(FILE *f) | ||
| 7 | { | ||
| 8 | 	unsigned char c; | ||
| 9 | 	if (!__toread(f) && f->read(f, &c, 1)==1) return c; | ||
| 10 | 	return EOF; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/asprintf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | |||
| 5 | int asprintf(char **s, const char *fmt, ...) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	va_list ap; | ||
| 9 | 	va_start(ap, fmt); | ||
| 10 | 	ret = vasprintf(s, fmt, ap); | ||
| 11 | 	va_end(ap); | ||
| 12 | 	return ret; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/clearerr.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | void clearerr(FILE *f) | ||
| 4 | { | ||
| 5 | 	FLOCK(f); | ||
| 6 | 	f->flags &= ~(F_EOF|F_ERR); | ||
| 7 | 	FUNLOCK(f); | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(clearerr, clearerr_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/dprintf.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int dprintf(int fd, const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vdprintf(fd, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ext.c created+57| ... | @@ -0,0 +1,57 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "stdio_impl.h" | ||
| 3 | #include <stdio_ext.h> | ||
| 4 | |||
| 5 | void _flushlbf(void) | ||
| 6 | { | ||
| 7 | 	fflush(0); | ||
| 8 | } | ||
| 9 | |||
| 10 | int __fsetlocking(FILE *f, int type) | ||
| 11 | { | ||
| 12 | 	return 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | int __fwriting(FILE *f) | ||
| 16 | { | ||
| 17 | 	return (f->flags & F_NORD) || f->wend; | ||
| 18 | } | ||
| 19 | |||
| 20 | int __freading(FILE *f) | ||
| 21 | { | ||
| 22 | 	return (f->flags & F_NOWR) || f->rend; | ||
| 23 | } | ||
| 24 | |||
| 25 | int __freadable(FILE *f) | ||
| 26 | { | ||
| 27 | 	return !(f->flags & F_NORD); | ||
| 28 | } | ||
| 29 | |||
| 30 | int __fwritable(FILE *f) | ||
| 31 | { | ||
| 32 | 	return !(f->flags & F_NOWR); | ||
| 33 | } | ||
| 34 | |||
| 35 | int __flbf(FILE *f) | ||
| 36 | { | ||
| 37 | 	return f->lbf >= 0; | ||
| 38 | } | ||
| 39 | |||
| 40 | size_t __fbufsize(FILE *f) | ||
| 41 | { | ||
| 42 | 	return f->buf_size; | ||
| 43 | } | ||
| 44 | |||
| 45 | size_t __fpending(FILE *f) | ||
| 46 | { | ||
| 47 | 	return f->wend ? f->wpos - f->wbase : 0; | ||
| 48 | } | ||
| 49 | |||
| 50 | int __fpurge(FILE *f) | ||
| 51 | { | ||
| 52 | 	f->wpos = f->wbase = f->wend = 0; | ||
| 53 | 	f->rpos = f->rend = 0; | ||
| 54 | 	return 0; | ||
| 55 | } | ||
| 56 | |||
| 57 | weak_alias(__fpurge, fpurge); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ext2.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <stdio_ext.h> | ||
| 3 | |||
| 4 | size_t __freadahead(FILE *f) | ||
| 5 | { | ||
| 6 | 	return f->rend ? f->rend - f->rpos : 0; | ||
| 7 | } | ||
| 8 | |||
| 9 | const char *__freadptr(FILE *f, size_t *sizep) | ||
| 10 | { | ||
| 11 | 	if (f->rpos == f->rend) return 0; | ||
| 12 | 	*sizep = f->rend - f->rpos; | ||
| 13 | 	return (const char *)f->rpos; | ||
| 14 | } | ||
| 15 | |||
| 16 | void __freadptrinc(FILE *f, size_t inc) | ||
| 17 | { | ||
| 18 | 	f->rpos += inc; | ||
| 19 | } | ||
| 20 | |||
| 21 | void __fseterr(FILE *f) | ||
| 22 | { | ||
| 23 | 	f->flags |= F_ERR; | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fclose.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | static void dummy(FILE *f) { } | ||
| 5 | weak_alias(dummy, __unlist_locked_file); | ||
| 6 | |||
| 7 | int fclose(FILE *f) | ||
| 8 | { | ||
| 9 | 	int r; | ||
| 10 | 	 | ||
| 11 | 	FLOCK(f); | ||
| 12 | 	r = fflush(f); | ||
| 13 | 	r |= f->close(f); | ||
| 14 | 	FUNLOCK(f); | ||
| 15 | |||
| 16 | 	/* Past this point, f is closed and any further explict access | ||
| 17 | 	 * to it is undefined. However, it still exists as an entry in | ||
| 18 | 	 * the open file list and possibly in the thread's locked files | ||
| 19 | 	 * list, if it was closed while explicitly locked. Functions | ||
| 20 | 	 * which process these lists must tolerate dead FILE objects | ||
| 21 | 	 * (which necessarily have inactive buffer pointers) without | ||
| 22 | 	 * producing any side effects. */ | ||
| 23 | |||
| 24 | 	if (f->flags & F_PERM) return r; | ||
| 25 | |||
| 26 | 	__unlist_locked_file(f); | ||
| 27 | |||
| 28 | 	FILE **head = __ofl_lock(); | ||
| 29 | 	if (f->prev) f->prev->next = f->next; | ||
| 30 | 	if (f->next) f->next->prev = f->prev; | ||
| 31 | 	if (*head == f) *head = f->next; | ||
| 32 | 	__ofl_unlock(); | ||
| 33 | |||
| 34 | 	free(f->getln_buf); | ||
| 35 | 	free(f); | ||
| 36 | |||
| 37 | 	return r; | ||
| 38 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/feof.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | #undef feof | ||
| 4 | |||
| 5 | int feof(FILE *f) | ||
| 6 | { | ||
| 7 | 	FLOCK(f); | ||
| 8 | 	int ret = !!(f->flags & F_EOF); | ||
| 9 | 	FUNLOCK(f); | ||
| 10 | 	return ret; | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(feof, feof_unlocked); | ||
| 14 | weak_alias(feof, _IO_feof_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ferror.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | #undef ferror | ||
| 4 | |||
| 5 | int ferror(FILE *f) | ||
| 6 | { | ||
| 7 | 	FLOCK(f); | ||
| 8 | 	int ret = !!(f->flags & F_ERR); | ||
| 9 | 	FUNLOCK(f); | ||
| 10 | 	return ret; | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(ferror, ferror_unlocked); | ||
| 14 | weak_alias(ferror, _IO_ferror_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fflush.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | /* stdout.c will override this if linked */ | ||
| 4 | static FILE *volatile dummy = 0; | ||
| 5 | weak_alias(dummy, __stdout_used); | ||
| 6 | weak_alias(dummy, __stderr_used); | ||
| 7 | |||
| 8 | int fflush(FILE *f) | ||
| 9 | { | ||
| 10 | 	if (!f) { | ||
| 11 | 		int r = 0; | ||
| 12 | 		if (__stdout_used) r |= fflush(__stdout_used); | ||
| 13 | 		if (__stderr_used) r |= fflush(__stderr_used); | ||
| 14 | |||
| 15 | 		for (f=*__ofl_lock(); f; f=f->next) { | ||
| 16 | 			FLOCK(f); | ||
| 17 | 			if (f->wpos != f->wbase) r |= fflush(f); | ||
| 18 | 			FUNLOCK(f); | ||
| 19 | 		} | ||
| 20 | 		__ofl_unlock(); | ||
| 21 | |||
| 22 | 		return r; | ||
| 23 | 	} | ||
| 24 | |||
| 25 | 	FLOCK(f); | ||
| 26 | |||
| 27 | 	/* If writing, flush output */ | ||
| 28 | 	if (f->wpos != f->wbase) { | ||
| 29 | 		f->write(f, 0, 0); | ||
| 30 | 		if (!f->wpos) { | ||
| 31 | 			FUNLOCK(f); | ||
| 32 | 			return EOF; | ||
| 33 | 		} | ||
| 34 | 	} | ||
| 35 | |||
| 36 | 	/* If reading, sync position, per POSIX */ | ||
| 37 | 	if (f->rpos != f->rend) f->seek(f, f->rpos-f->rend, SEEK_CUR); | ||
| 38 | |||
| 39 | 	/* Clear read and write modes */ | ||
| 40 | 	f->wpos = f->wbase = f->wend = 0; | ||
| 41 | 	f->rpos = f->rend = 0; | ||
| 42 | |||
| 43 | 	FUNLOCK(f); | ||
| 44 | 	return 0; | ||
| 45 | } | ||
| 46 | |||
| 47 | weak_alias(fflush, fflush_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetc.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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/fgetln.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "stdio_impl.h" | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | char *fgetln(FILE *f, size_t *plen) | ||
| 6 | { | ||
| 7 | 	char *ret = 0, *z; | ||
| 8 | 	ssize_t l; | ||
| 9 | 	FLOCK(f); | ||
| 10 | 	ungetc(getc_unlocked(f), f); | ||
| 11 | 	if (f->rend && (z=memchr(f->rpos, '\n', f->rend - f->rpos))) { | ||
| 12 | 		ret = (char *)f->rpos; | ||
| 13 | 		*plen = ++z - ret; | ||
| 14 | 		f->rpos = (void *)z; | ||
| 15 | 	} else if ((l = getline(&f->getln_buf, (size_t[]){0}, f)) > 0) { | ||
| 16 | 		*plen = l; | ||
| 17 | 		ret = f->getln_buf; | ||
| 18 | 	} | ||
| 19 | 	FUNLOCK(f); | ||
| 20 | 	return ret; | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetpos.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 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/fgets.c created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) | ||
| 5 | |||
| 6 | char *fgets(char *restrict s, int n, FILE *restrict f) | ||
| 7 | { | ||
| 8 | 	char *p = s; | ||
| 9 | 	unsigned char *z; | ||
| 10 | 	size_t k; | ||
| 11 | 	int c; | ||
| 12 | |||
| 13 | 	FLOCK(f); | ||
| 14 | |||
| 15 | 	if (n--<=1) { | ||
| 16 | 		f->mode |= f->mode-1; | ||
| 17 | 		FUNLOCK(f); | ||
| 18 | 		if (n) return 0; | ||
| 19 | 		*s = 0; | ||
| 20 | 		return s; | ||
| 21 | 	} | ||
| 22 | |||
| 23 | 	while (n) { | ||
| 24 | 		if (f->rpos != f->rend) { | ||
| 25 | 			z = memchr(f->rpos, '\n', f->rend - f->rpos); | ||
| 26 | 			k = z ? z - f->rpos + 1 : f->rend - f->rpos; | ||
| 27 | 			k = MIN(k, n); | ||
| 28 | 			memcpy(p, f->rpos, k); | ||
| 29 | 			f->rpos += k; | ||
| 30 | 			p += k; | ||
| 31 | 			n -= k; | ||
| 32 | 			if (z || !n) break; | ||
| 33 | 		} | ||
| 34 | 		if ((c = getc_unlocked(f)) < 0) { | ||
| 35 | 			if (p==s || !feof(f)) s = 0; | ||
| 36 | 			break; | ||
| 37 | 		} | ||
| 38 | 		n--; | ||
| 39 | 		if ((*p++ = c) == '\n') break; | ||
| 40 | 	} | ||
| 41 | 	if (s) *p = 0; | ||
| 42 | |||
| 43 | 	FUNLOCK(f); | ||
| 44 | |||
| 45 | 	return s; | ||
| 46 | } | ||
| 47 | |||
| 48 | weak_alias(fgets, fgets_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetwc.c created+68| ... | @@ -0,0 +1,68 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "locale_impl.h" | ||
| 3 | #include <wchar.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | static wint_t __fgetwc_unlocked_internal(FILE *f) | ||
| 7 | { | ||
| 8 | 	wchar_t wc; | ||
| 9 | 	int c; | ||
| 10 | 	size_t l; | ||
| 11 | |||
| 12 | 	/* Convert character from buffer if possible */ | ||
| 13 | 	if (f->rpos != f->rend) { | ||
| 14 | 		l = mbtowc(&wc, (void *)f->rpos, f->rend - f->rpos); | ||
| 15 | 		if (l+1 >= 1) { | ||
| 16 | 			f->rpos += l + !l; /* l==0 means 1 byte, null */ | ||
| 17 | 			return wc; | ||
| 18 | 		} | ||
| 19 | 	} | ||
| 20 | |||
| 21 | 	/* Convert character byte-by-byte */ | ||
| 22 | 	mbstate_t st = { 0 }; | ||
| 23 | 	unsigned char b; | ||
| 24 | 	int first = 1; | ||
| 25 | 	do { | ||
| 26 | 		b = c = getc_unlocked(f); | ||
| 27 | 		if (c < 0) { | ||
| 28 | 			if (!first) { | ||
| 29 | 				f->flags |= F_ERR; | ||
| 30 | 				errno = EILSEQ; | ||
| 31 | 			} | ||
| 32 | 			return WEOF; | ||
| 33 | 		} | ||
| 34 | 		l = mbrtowc(&wc, (void *)&b, 1, &st); | ||
| 35 | 		if (l == -1) { | ||
| 36 | 			if (!first) { | ||
| 37 | 				f->flags |= F_ERR; | ||
| 38 | 				ungetc(b, f); | ||
| 39 | 			} | ||
| 40 | 			return WEOF; | ||
| 41 | 		} | ||
| 42 | 		first = 0; | ||
| 43 | 	} while (l == -2); | ||
| 44 | |||
| 45 | 	return wc; | ||
| 46 | } | ||
| 47 | |||
| 48 | wint_t __fgetwc_unlocked(FILE *f) | ||
| 49 | { | ||
| 50 | 	locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | ||
| 51 | 	if (f->mode <= 0) fwide(f, 1); | ||
| 52 | 	*ploc = f->locale; | ||
| 53 | 	wchar_t wc = __fgetwc_unlocked_internal(f); | ||
| 54 | 	*ploc = loc; | ||
| 55 | 	return wc; | ||
| 56 | } | ||
| 57 | |||
| 58 | wint_t fgetwc(FILE *f) | ||
| 59 | { | ||
| 60 | 	wint_t c; | ||
| 61 | 	FLOCK(f); | ||
| 62 | 	c = __fgetwc_unlocked(f); | ||
| 63 | 	FUNLOCK(f); | ||
| 64 | 	return c; | ||
| 65 | } | ||
| 66 | |||
| 67 | weak_alias(__fgetwc_unlocked, fgetwc_unlocked); | ||
| 68 | weak_alias(__fgetwc_unlocked, getwc_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetws.c created+33| ... | @@ -0,0 +1,33 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | wint_t __fgetwc_unlocked(FILE *); | ||
| 6 | |||
| 7 | wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) | ||
| 8 | { | ||
| 9 | 	wchar_t *p = s; | ||
| 10 | |||
| 11 | 	if (!n--) return s; | ||
| 12 | |||
| 13 | 	FLOCK(f); | ||
| 14 | |||
| 15 | 	/* Setup a dummy errno so we can detect EILSEQ. This is | ||
| 16 | 	 * the only way to catch encoding errors in the form of a | ||
| 17 | 	 * partial character just before EOF. */ | ||
| 18 | 	errno = EAGAIN; | ||
| 19 | 	for (; n; n--) { | ||
| 20 | 		wint_t c = __fgetwc_unlocked(f); | ||
| 21 | 		if (c == WEOF) break; | ||
| 22 | 		*p++ = c; | ||
| 23 | 		if (c == '\n') break; | ||
| 24 | 	} | ||
| 25 | 	*p = 0; | ||
| 26 | 	if (ferror(f) || errno==EILSEQ) p = s; | ||
| 27 | |||
| 28 | 	FUNLOCK(f); | ||
| 29 | |||
| 30 | 	return (p == s) ? NULL : s; | ||
| 31 | } | ||
| 32 | |||
| 33 | weak_alias(fgetws, fgetws_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fileno.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int fileno(FILE *f) | ||
| 5 | { | ||
| 6 | 	FLOCK(f); | ||
| 7 | 	int fd = f->fd; | ||
| 8 | 	FUNLOCK(f); | ||
| 9 | 	if (fd < 0) { | ||
| 10 | 		errno = EBADF; | ||
| 11 | 		return -1; | ||
| 12 | 	} | ||
| 13 | 	return fd; | ||
| 14 | } | ||
| 15 | |||
| 16 | weak_alias(fileno, fileno_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/flockfile.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | void flockfile(FILE *f) | ||
| 5 | { | ||
| 6 | 	if (!ftrylockfile(f)) return; | ||
| 7 | 	__lockfile(f); | ||
| 8 | 	__register_locked_file(f, __pthread_self()); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fmemopen.c created+137| ... | @@ -0,0 +1,137 @@ | ||
| 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 created+51| ... | @@ -0,0 +1,51 @@ | ||
| 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/fopencookie.c created+135| ... | @@ -0,0 +1,135 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "stdio_impl.h" | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <sys/ioctl.h> | ||
| 5 | #include <fcntl.h> | ||
| 6 | #include <errno.h> | ||
| 7 | #include <string.h> | ||
| 8 | |||
| 9 | struct fcookie { | ||
| 10 | 	void *cookie; | ||
| 11 | 	cookie_io_functions_t iofuncs; | ||
| 12 | }; | ||
| 13 | |||
| 14 | struct cookie_FILE { | ||
| 15 | 	FILE f; | ||
| 16 | 	struct fcookie fc; | ||
| 17 | 	unsigned char buf[UNGET+BUFSIZ]; | ||
| 18 | }; | ||
| 19 | |||
| 20 | static size_t cookieread(FILE *f, unsigned char *buf, size_t len) | ||
| 21 | { | ||
| 22 | 	struct fcookie *fc = f->cookie; | ||
| 23 | 	ssize_t ret = -1; | ||
| 24 | 	size_t remain = len, readlen = 0; | ||
| 25 | 	size_t len2 = len - !!f->buf_size; | ||
| 26 | |||
| 27 | 	if (!fc->iofuncs.read) goto bail; | ||
| 28 | |||
| 29 | 	if (len2) { | ||
| 30 | 		ret = fc->iofuncs.read(fc->cookie, (char *) buf, len2); | ||
| 31 | 		if (ret <= 0) goto bail; | ||
| 32 | |||
| 33 | 		readlen += ret; | ||
| 34 | 		remain -= ret; | ||
| 35 | 	} | ||
| 36 | |||
| 37 | 	if (!f->buf_size || remain > !!f->buf_size) return readlen; | ||
| 38 | |||
| 39 | 	f->rpos = f->buf; | ||
| 40 | 	ret = fc->iofuncs.read(fc->cookie, (char *) f->rpos, f->buf_size); | ||
| 41 | 	if (ret <= 0) goto bail; | ||
| 42 | 	f->rend = f->rpos + ret; | ||
| 43 | |||
| 44 | 	buf[readlen++] = *f->rpos++; | ||
| 45 | |||
| 46 | 	return readlen; | ||
| 47 | |||
| 48 | bail: | ||
| 49 | 	f->flags |= ret == 0 ? F_EOF : F_ERR; | ||
| 50 | 	f->rpos = f->rend = f->buf; | ||
| 51 | 	return readlen; | ||
| 52 | } | ||
| 53 | |||
| 54 | static size_t cookiewrite(FILE *f, const unsigned char *buf, size_t len) | ||
| 55 | { | ||
| 56 | 	struct fcookie *fc = f->cookie; | ||
| 57 | 	ssize_t ret; | ||
| 58 | 	size_t len2 = f->wpos - f->wbase; | ||
| 59 | 	if (!fc->iofuncs.write) return len; | ||
| 60 | 	if (len2) { | ||
| 61 | 		f->wpos = f->wbase; | ||
| 62 | 		if (cookiewrite(f, f->wpos, len2) < len2) return 0; | ||
| 63 | 	} | ||
| 64 | 	ret = fc->iofuncs.write(fc->cookie, (const char *) buf, len); | ||
| 65 | 	if (ret < 0) { | ||
| 66 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 67 | 		f->flags |= F_ERR; | ||
| 68 | 		return 0; | ||
| 69 | 	} | ||
| 70 | 	return ret; | ||
| 71 | } | ||
| 72 | |||
| 73 | static off_t cookieseek(FILE *f, off_t off, int whence) | ||
| 74 | { | ||
| 75 | 	struct fcookie *fc = f->cookie; | ||
| 76 | 	int res; | ||
| 77 | 	if (whence > 2U) { | ||
| 78 | 		errno = EINVAL; | ||
| 79 | 		return -1; | ||
| 80 | 	} | ||
| 81 | 	if (!fc->iofuncs.seek) { | ||
| 82 | 		errno = ENOTSUP; | ||
| 83 | 		return -1; | ||
| 84 | 	} | ||
| 85 | 	res = fc->iofuncs.seek(fc->cookie, &off, whence); | ||
| 86 | 	if (res < 0) | ||
| 87 | 		return res; | ||
| 88 | 	return off; | ||
| 89 | } | ||
| 90 | |||
| 91 | static int cookieclose(FILE *f) | ||
| 92 | { | ||
| 93 | 	struct fcookie *fc = f->cookie; | ||
| 94 | 	if (fc->iofuncs.close) return fc->iofuncs.close(fc->cookie); | ||
| 95 | 	return 0; | ||
| 96 | } | ||
| 97 | |||
| 98 | FILE *fopencookie(void *cookie, const char *mode, cookie_io_functions_t iofuncs) | ||
| 99 | { | ||
| 100 | 	struct cookie_FILE *f; | ||
| 101 | |||
| 102 | 	/* Check for valid initial mode character */ | ||
| 103 | 	if (!strchr("rwa", *mode)) { | ||
| 104 | 		errno = EINVAL; | ||
| 105 | 		return 0; | ||
| 106 | 	} | ||
| 107 | |||
| 108 | 	/* Allocate FILE+fcookie+buffer or fail */ | ||
| 109 | 	if (!(f=malloc(sizeof *f))) return 0; | ||
| 110 | |||
| 111 | 	/* Zero-fill only the struct, not the buffer */ | ||
| 112 | 	memset(&f->f, 0, sizeof f->f); | ||
| 113 | |||
| 114 | 	/* Impose mode restrictions */ | ||
| 115 | 	if (!strchr(mode, '+')) f->f.flags = (*mode == 'r') ? F_NOWR : F_NORD; | ||
| 116 | |||
| 117 | 	/* Set up our fcookie */ | ||
| 118 | 	f->fc.cookie = cookie; | ||
| 119 | 	f->fc.iofuncs = iofuncs; | ||
| 120 | |||
| 121 | 	f->f.fd = -1; | ||
| 122 | 	f->f.cookie = &f->fc; | ||
| 123 | 	f->f.buf = f->buf + UNGET; | ||
| 124 | 	f->f.buf_size = sizeof f->buf - UNGET; | ||
| 125 | 	f->f.lbf = EOF; | ||
| 126 | |||
| 127 | 	/* Initialize op ptrs. No problem if some are unneeded. */ | ||
| 128 | 	f->f.read = cookieread; | ||
| 129 | 	f->f.write = cookiewrite; | ||
| 130 | 	f->f.seek = cookieseek; | ||
| 131 | 	f->f.close = cookieclose; | ||
| 132 | |||
| 133 | 	/* Add new FILE to open file list */ | ||
| 134 | 	return __ofl_add(&f->f); | ||
| 135 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fprintf.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int fprintf(FILE *restrict f, const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vfprintf(f, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fputc.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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/fputs.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | int fputs(const char *restrict s, FILE *restrict f) | ||
| 5 | { | ||
| 6 | 	size_t l = strlen(s); | ||
| 7 | 	return (fwrite(s, 1, l, f)==l) - 1; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(fputs, fputs_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fputwc.c created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "locale_impl.h" | ||
| 3 | #include <wchar.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <ctype.h> | ||
| 6 | |||
| 7 | wint_t __fputwc_unlocked(wchar_t c, FILE *f) | ||
| 8 | { | ||
| 9 | 	char mbc[MB_LEN_MAX]; | ||
| 10 | 	int l; | ||
| 11 | 	locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | ||
| 12 | |||
| 13 | 	if (f->mode <= 0) fwide(f, 1); | ||
| 14 | 	*ploc = f->locale; | ||
| 15 | |||
| 16 | 	if (isascii(c)) { | ||
| 17 | 		c = putc_unlocked(c, f); | ||
| 18 | 	} else if (f->wpos + MB_LEN_MAX < f->wend) { | ||
| 19 | 		l = wctomb((void *)f->wpos, c); | ||
| 20 | 		if (l < 0) c = WEOF; | ||
| 21 | 		else f->wpos += l; | ||
| 22 | 	} else { | ||
| 23 | 		l = wctomb(mbc, c); | ||
| 24 | 		if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF; | ||
| 25 | 	} | ||
| 26 | 	if (c==WEOF) f->flags |= F_ERR; | ||
| 27 | 	*ploc = loc; | ||
| 28 | 	return c; | ||
| 29 | } | ||
| 30 | |||
| 31 | wint_t fputwc(wchar_t c, FILE *f) | ||
| 32 | { | ||
| 33 | 	FLOCK(f); | ||
| 34 | 	c = __fputwc_unlocked(c, f); | ||
| 35 | 	FUNLOCK(f); | ||
| 36 | 	return c; | ||
| 37 | } | ||
| 38 | |||
| 39 | weak_alias(__fputwc_unlocked, fputwc_unlocked); | ||
| 40 | weak_alias(__fputwc_unlocked, putwc_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fputws.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "locale_impl.h" | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int fputws(const wchar_t *restrict ws, FILE *restrict f) | ||
| 6 | { | ||
| 7 | 	unsigned char buf[BUFSIZ]; | ||
| 8 | 	size_t l=0; | ||
| 9 | 	locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | ||
| 10 | |||
| 11 | 	FLOCK(f); | ||
| 12 | |||
| 13 | 	fwide(f, 1); | ||
| 14 | 	*ploc = f->locale; | ||
| 15 | |||
| 16 | 	while (ws && (l = wcsrtombs((void *)buf, (void*)&ws, sizeof buf, 0))+1 > 1) | ||
| 17 | 		if (__fwritex(buf, l, f) < l) { | ||
| 18 | 			FUNLOCK(f); | ||
| 19 | 			*ploc = loc; | ||
| 20 | 			return -1; | ||
| 21 | 		} | ||
| 22 | |||
| 23 | 	FUNLOCK(f); | ||
| 24 | |||
| 25 | 	*ploc = loc; | ||
| 26 | 	return l; /* 0 or -1 */ | ||
| 27 | } | ||
| 28 | |||
| 29 | weak_alias(fputws, fputws_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fread.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) | ||
| 5 | |||
| 6 | size_t fread(void *restrict destv, size_t size, size_t nmemb, FILE *restrict f) | ||
| 7 | { | ||
| 8 | 	unsigned char *dest = destv; | ||
| 9 | 	size_t len = size*nmemb, l = len, k; | ||
| 10 | 	if (!size) nmemb = 0; | ||
| 11 | |||
| 12 | 	FLOCK(f); | ||
| 13 | |||
| 14 | 	f->mode |= f->mode-1; | ||
| 15 | |||
| 16 | 	if (f->rpos != f->rend) { | ||
| 17 | 		/* First exhaust the buffer. */ | ||
| 18 | 		k = MIN(f->rend - f->rpos, l); | ||
| 19 | 		memcpy(dest, f->rpos, k); | ||
| 20 | 		f->rpos += k; | ||
| 21 | 		dest += k; | ||
| 22 | 		l -= k; | ||
| 23 | 	} | ||
| 24 | 	 | ||
| 25 | 	/* Read the remainder directly */ | ||
| 26 | 	for (; l; l-=k, dest+=k) { | ||
| 27 | 		k = __toread(f) ? 0 : f->read(f, dest, l); | ||
| 28 | 		if (!k) { | ||
| 29 | 			FUNLOCK(f); | ||
| 30 | 			return (len-l)/size; | ||
| 31 | 		} | ||
| 32 | 	} | ||
| 33 | |||
| 34 | 	FUNLOCK(f); | ||
| 35 | 	return nmemb; | ||
| 36 | } | ||
| 37 | |||
| 38 | weak_alias(fread, fread_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/freopen.c created+80| ... | @@ -0,0 +1,80 @@ | ||
| 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 | 	FUNLOCK(f); | ||
| 71 | 	return f; | ||
| 72 | |||
| 73 | fail2: | ||
| 74 | 	fclose(f2); | ||
| 75 | fail: | ||
| 76 | 	fclose(f); | ||
| 77 | 	return NULL; | ||
| 78 | } | ||
| 79 | |||
| 80 | weak_alias(freopen, freopen64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fscanf.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int fscanf(FILE *restrict f, const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vfscanf(f, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(fscanf, __isoc99_fscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fseek.c created+43| ... | @@ -0,0 +1,43 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int __fseeko_unlocked(FILE *f, off_t off, int whence) | ||
| 4 | { | ||
| 5 | 	/* Adjust relative offset for unread data in buffer, if any. */ | ||
| 6 | 	if (whence == SEEK_CUR && f->rend) off -= f->rend - f->rpos; | ||
| 7 | |||
| 8 | 	/* Flush write buffer, and report error on failure. */ | ||
| 9 | 	if (f->wpos != f->wbase) { | ||
| 10 | 		f->write(f, 0, 0); | ||
| 11 | 		if (!f->wpos) return -1; | ||
| 12 | 	} | ||
| 13 | |||
| 14 | 	/* Leave writing mode */ | ||
| 15 | 	f->wpos = f->wbase = f->wend = 0; | ||
| 16 | |||
| 17 | 	/* Perform the underlying seek. */ | ||
| 18 | 	if (f->seek(f, off, whence) < 0) return -1; | ||
| 19 | |||
| 20 | 	/* If seek succeeded, file is seekable and we discard read buffer. */ | ||
| 21 | 	f->rpos = f->rend = 0; | ||
| 22 | 	f->flags &= ~F_EOF; | ||
| 23 | 	 | ||
| 24 | 	return 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | int __fseeko(FILE *f, off_t off, int whence) | ||
| 28 | { | ||
| 29 | 	int result; | ||
| 30 | 	FLOCK(f); | ||
| 31 | 	result = __fseeko_unlocked(f, off, whence); | ||
| 32 | 	FUNLOCK(f); | ||
| 33 | 	return result; | ||
| 34 | } | ||
| 35 | |||
| 36 | int fseek(FILE *f, long off, int whence) | ||
| 37 | { | ||
| 38 | 	return __fseeko(f, off, whence); | ||
| 39 | } | ||
| 40 | |||
| 41 | weak_alias(__fseeko, fseeko); | ||
| 42 | |||
| 43 | weak_alias(fseeko, fseeko64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fsetpos.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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 created+41| ... | @@ -0,0 +1,41 @@ | ||
| 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/ftrylockfile.c created+46| ... | @@ -0,0 +1,46 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | void __do_orphaned_stdio_locks() | ||
| 6 | { | ||
| 7 | 	FILE *f; | ||
| 8 | 	for (f=__pthread_self()->stdio_locks; f; f=f->next_locked) | ||
| 9 | 		a_store(&f->lock, 0x40000000); | ||
| 10 | } | ||
| 11 | |||
| 12 | void __unlist_locked_file(FILE *f) | ||
| 13 | { | ||
| 14 | 	if (f->lockcount) { | ||
| 15 | 		if (f->next_locked) f->next_locked->prev_locked = f->prev_locked; | ||
| 16 | 		if (f->prev_locked) f->prev_locked->next_locked = f->next_locked; | ||
| 17 | 		else __pthread_self()->stdio_locks = f->next_locked; | ||
| 18 | 	} | ||
| 19 | } | ||
| 20 | |||
| 21 | void __register_locked_file(FILE *f, pthread_t self) | ||
| 22 | { | ||
| 23 | 	f->lockcount = 1; | ||
| 24 | 	f->prev_locked = 0; | ||
| 25 | 	f->next_locked = self->stdio_locks; | ||
| 26 | 	if (f->next_locked) f->next_locked->prev_locked = f; | ||
| 27 | 	self->stdio_locks = f; | ||
| 28 | } | ||
| 29 | |||
| 30 | int ftrylockfile(FILE *f) | ||
| 31 | { | ||
| 32 | 	pthread_t self = __pthread_self(); | ||
| 33 | 	int tid = self->tid; | ||
| 34 | 	int owner = f->lock; | ||
| 35 | 	if ((owner & ~MAYBE_WAITERS) == tid) { | ||
| 36 | 		if (f->lockcount == LONG_MAX) | ||
| 37 | 			return -1; | ||
| 38 | 		f->lockcount++; | ||
| 39 | 		return 0; | ||
| 40 | 	} | ||
| 41 | 	if (owner < 0) f->lock = owner = 0; | ||
| 42 | 	if (owner || a_cas(&f->lock, 0, tid)) | ||
| 43 | 		return -1; | ||
| 44 | 	__register_locked_file(f, self); | ||
| 45 | 	return 0; | ||
| 46 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/funlockfile.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | void funlockfile(FILE *f) | ||
| 5 | { | ||
| 6 | 	if (f->lockcount == 1) { | ||
| 7 | 		__unlist_locked_file(f); | ||
| 8 | 		f->lockcount = 0; | ||
| 9 | 		__unlockfile(f); | ||
| 10 | 	} else { | ||
| 11 | 		f->lockcount--; | ||
| 12 | 	} | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fwide.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include "stdio_impl.h" | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | int fwide(FILE *f, int mode) | ||
| 6 | { | ||
| 7 | 	FLOCK(f); | ||
| 8 | 	if (mode) { | ||
| 9 | 		if (!f->locale) f->locale = MB_CUR_MAX==1 | ||
| 10 | 			? C_LOCALE : UTF8_LOCALE; | ||
| 11 | 		if (!f->mode) f->mode = mode>0 ? 1 : -1; | ||
| 12 | 	} | ||
| 13 | 	mode = f->mode; | ||
| 14 | 	FUNLOCK(f); | ||
| 15 | 	return mode; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fwprintf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int fwprintf(FILE *restrict f, const wchar_t *restrict fmt, ...) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	va_list ap; | ||
| 9 | 	va_start(ap, fmt); | ||
| 10 | 	ret = vfwprintf(f, fmt, ap); | ||
| 11 | 	va_end(ap); | ||
| 12 | 	return ret; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fwrite.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | size_t __fwritex(const unsigned char *restrict s, size_t l, FILE *restrict f) | ||
| 5 | { | ||
| 6 | 	size_t i=0; | ||
| 7 | |||
| 8 | 	if (!f->wend && __towrite(f)) return 0; | ||
| 9 | |||
| 10 | 	if (l > f->wend - f->wpos) return f->write(f, s, l); | ||
| 11 | |||
| 12 | 	if (f->lbf >= 0) { | ||
| 13 | 		/* Match /^(.*\n|)/ */ | ||
| 14 | 		for (i=l; i && s[i-1] != '\n'; i--); | ||
| 15 | 		if (i) { | ||
| 16 | 			size_t n = f->write(f, s, i); | ||
| 17 | 			if (n < i) return n; | ||
| 18 | 			s += i; | ||
| 19 | 			l -= i; | ||
| 20 | 		} | ||
| 21 | 	} | ||
| 22 | |||
| 23 | 	memcpy(f->wpos, s, l); | ||
| 24 | 	f->wpos += l; | ||
| 25 | 	return l+i; | ||
| 26 | } | ||
| 27 | |||
| 28 | size_t fwrite(const void *restrict src, size_t size, size_t nmemb, FILE *restrict f) | ||
| 29 | { | ||
| 30 | 	size_t k, l = size*nmemb; | ||
| 31 | 	if (!size) nmemb = 0; | ||
| 32 | 	FLOCK(f); | ||
| 33 | 	k = __fwritex(src, l, f); | ||
| 34 | 	FUNLOCK(f); | ||
| 35 | 	return k==l ? nmemb : k/size; | ||
| 36 | } | ||
| 37 | |||
| 38 | weak_alias(fwrite, fwrite_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/fwscanf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int fwscanf(FILE *restrict f, const wchar_t *restrict fmt, ...) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	va_list ap; | ||
| 9 | 	va_start(ap, fmt); | ||
| 10 | 	ret = vfwscanf(f, fmt, ap); | ||
| 11 | 	va_end(ap); | ||
| 12 | 	return ret; | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(fwscanf,__isoc99_fwscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getc.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 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 created+29| ... | @@ -0,0 +1,29 @@ | ||
| 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/getc_unlocked.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int (getc_unlocked)(FILE *f) | ||
| 4 | { | ||
| 5 | 	return getc_unlocked(f); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias (getc_unlocked, fgetc_unlocked); | ||
| 9 | weak_alias (getc_unlocked, _IO_getc_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getchar.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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/getchar_unlocked.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int getchar_unlocked(void) | ||
| 4 | { | ||
| 5 | 	return getc_unlocked(stdin); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getdelim.c created+81| ... | @@ -0,0 +1,81 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <inttypes.h> | ||
| 5 | #include <errno.h> | ||
| 6 | |||
| 7 | ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restrict f) | ||
| 8 | { | ||
| 9 | 	char *tmp; | ||
| 10 | 	unsigned char *z; | ||
| 11 | 	size_t k; | ||
| 12 | 	size_t i=0; | ||
| 13 | 	int c; | ||
| 14 | |||
| 15 | 	FLOCK(f); | ||
| 16 | |||
| 17 | 	if (!n || !s) { | ||
| 18 | 		f->mode |= f->mode-1; | ||
| 19 | 		f->flags |= F_ERR; | ||
| 20 | 		FUNLOCK(f); | ||
| 21 | 		errno = EINVAL; | ||
| 22 | 		return -1; | ||
| 23 | 	} | ||
| 24 | |||
| 25 | 	if (!*s) *n=0; | ||
| 26 | |||
| 27 | 	for (;;) { | ||
| 28 | 		if (f->rpos != f->rend) { | ||
| 29 | 			z = memchr(f->rpos, delim, f->rend - f->rpos); | ||
| 30 | 			k = z ? z - f->rpos + 1 : f->rend - f->rpos; | ||
| 31 | 		} else { | ||
| 32 | 			z = 0; | ||
| 33 | 			k = 0; | ||
| 34 | 		} | ||
| 35 | 		if (i+k >= *n) { | ||
| 36 | 			size_t m = i+k+2; | ||
| 37 | 			if (!z && m < SIZE_MAX/4) m += m/2; | ||
| 38 | 			tmp = realloc(*s, m); | ||
| 39 | 			if (!tmp) { | ||
| 40 | 				m = i+k+2; | ||
| 41 | 				tmp = realloc(*s, m); | ||
| 42 | 				if (!tmp) { | ||
| 43 | 					/* Copy as much as fits and ensure no | ||
| 44 | 					 * pushback remains in the FILE buf. */ | ||
| 45 | 					k = *n-i; | ||
| 46 | 					memcpy(*s+i, f->rpos, k); | ||
| 47 | 					f->rpos += k; | ||
| 48 | 					f->mode |= f->mode-1; | ||
| 49 | 					f->flags |= F_ERR; | ||
| 50 | 					FUNLOCK(f); | ||
| 51 | 					errno = ENOMEM; | ||
| 52 | 					return -1; | ||
| 53 | 				} | ||
| 54 | 			} | ||
| 55 | 			*s = tmp; | ||
| 56 | 			*n = m; | ||
| 57 | 		} | ||
| 58 | 		memcpy(*s+i, f->rpos, k); | ||
| 59 | 		f->rpos += k; | ||
| 60 | 		i += k; | ||
| 61 | 		if (z) break; | ||
| 62 | 		if ((c = getc_unlocked(f)) == EOF) { | ||
| 63 | 			if (!i || !feof(f)) { | ||
| 64 | 				FUNLOCK(f); | ||
| 65 | 				return -1; | ||
| 66 | 			} | ||
| 67 | 			break; | ||
| 68 | 		} | ||
| 69 | 		/* If the byte read by getc won't fit without growing the | ||
| 70 | 		 * output buffer, push it back for next iteration. */ | ||
| 71 | 		if (i+1 >= *n) *--f->rpos = c; | ||
| 72 | 		else if (((*s)[i++] = c) == delim) break; | ||
| 73 | 	} | ||
| 74 | 	(*s)[i] = 0; | ||
| 75 | |||
| 76 | 	FUNLOCK(f); | ||
| 77 | |||
| 78 | 	return i; | ||
| 79 | } | ||
| 80 | |||
| 81 | weak_alias(getdelim, __getdelim); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getline.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | ssize_t getline(char **restrict s, size_t *restrict n, FILE *restrict f) | ||
| 4 | { | ||
| 5 | 	return getdelim(s, n, '\n', f); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/gets.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <limits.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | char *gets(char *s) | ||
| 6 | { | ||
| 7 | 	size_t i=0; | ||
| 8 | 	int c; | ||
| 9 | 	FLOCK(stdin); | ||
| 10 | 	while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c; | ||
| 11 | 	s[i] = 0; | ||
| 12 | 	if (c != '\n' && (!feof(stdin) || !i)) s = 0; | ||
| 13 | 	FUNLOCK(stdin); | ||
| 14 | 	return s; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getw.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | int getw(FILE *f) | ||
| 5 | { | ||
| 6 | 	int x; | ||
| 7 | 	return fread(&x, sizeof x, 1, f) ? x : EOF; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getwc.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | wint_t getwc(FILE *f) | ||
| 5 | { | ||
| 6 | 	return fgetwc(f); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/getwchar.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | wint_t getwchar(void) | ||
| 5 | { | ||
| 6 | 	return fgetwc(stdin); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(getwchar, getwchar_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ofl.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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/ofl_add.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | FILE *__ofl_add(FILE *f) | ||
| 4 | { | ||
| 5 | 	FILE **head = __ofl_lock(); | ||
| 6 | 	f->next = *head; | ||
| 7 | 	if (*head) (*head)->prev = f; | ||
| 8 | 	*head = f; | ||
| 9 | 	__ofl_unlock(); | ||
| 10 | 	return f; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/open_memstream.c created+109| ... | @@ -0,0 +1,109 @@ | ||
| 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 created+112| ... | @@ -0,0 +1,112 @@ | ||
| 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; | ||
| 52 | 	wchar_t *newbuf; | ||
| 53 | 	if (len + c->pos >= c->space) { | ||
| 54 | 		len2 = 2*c->space+1 | c->pos+len+1; | ||
| 55 | 		if (len2 > SSIZE_MAX/4) return 0; | ||
| 56 | 		newbuf = realloc(c->buf, len2*4); | ||
| 57 | 		if (!newbuf) return 0; | ||
| 58 | 		*c->bufp = c->buf = newbuf; | ||
| 59 | 		memset(c->buf + c->space, 0, 4*(len2 - c->space)); | ||
| 60 | 		c->space = len2; | ||
| 61 | 	} | ||
| 62 | 	 | ||
| 63 | 	len2 = mbsnrtowcs(c->buf+c->pos, (void *)&buf, len, c->space-c->pos, &c->mbs); | ||
| 64 | 	if (len2 == -1) return 0; | ||
| 65 | 	c->pos += len2; | ||
| 66 | 	if (c->pos >= c->len) c->len = c->pos; | ||
| 67 | 	*c->sizep = c->pos; | ||
| 68 | 	return len; | ||
| 69 | } | ||
| 70 | |||
| 71 | static int wms_close(FILE *f) | ||
| 72 | { | ||
| 73 | 	return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | FILE *open_wmemstream(wchar_t **bufp, size_t *sizep) | ||
| 77 | { | ||
| 78 | 	struct wms_FILE *f; | ||
| 79 | 	wchar_t *buf; | ||
| 80 | |||
| 81 | 	if (!(f=malloc(sizeof *f))) return 0; | ||
| 82 | 	if (!(buf=malloc(sizeof *buf))) { | ||
| 83 | 		free(f); | ||
| 84 | 		return 0; | ||
| 85 | 	} | ||
| 86 | 	memset(&f->f, 0, sizeof f->f); | ||
| 87 | 	memset(&f->c, 0, sizeof f->c); | ||
| 88 | 	f->f.cookie = &f->c; | ||
| 89 | |||
| 90 | 	f->c.bufp = bufp; | ||
| 91 | 	f->c.sizep = sizep; | ||
| 92 | 	f->c.pos = f->c.len = f->c.space = *sizep = 0; | ||
| 93 | 	f->c.buf = *bufp = buf; | ||
| 94 | 	*buf = 0; | ||
| 95 | |||
| 96 | 	f->f.flags = F_NORD; | ||
| 97 | 	f->f.fd = -1; | ||
| 98 | 	f->f.buf = f->buf; | ||
| 99 | 	f->f.buf_size = 0; | ||
| 100 | 	f->f.lbf = EOF; | ||
| 101 | 	f->f.write = wms_write; | ||
| 102 | 	f->f.seek = wms_seek; | ||
| 103 | 	f->f.close = wms_close; | ||
| 104 | |||
| 105 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 106 | 	if (!libc.threaded) f->f.lock = -1; | ||
| 107 | #endif | ||
| 108 | |||
| 109 | 	fwide(&f->f, 1); | ||
| 110 | |||
| 111 | 	return __ofl_add(&f->f); | ||
| 112 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/pclose.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | |||
| 5 | int pclose(FILE *f) | ||
| 6 | { | ||
| 7 | 	int status, r; | ||
| 8 | 	pid_t pid = f->pipe_pid; | ||
| 9 | 	fclose(f); | ||
| 10 | 	while ((r=__syscall(SYS_wait4, pid, &status, 0, 0)) == -EINTR); | ||
| 11 | 	if (r<0) return __syscall_ret(r); | ||
| 12 | 	return status; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/perror.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "stdio_impl.h" | ||
| 5 | |||
| 6 | void perror(const char *msg) | ||
| 7 | { | ||
| 8 | 	FILE *f = stderr; | ||
| 9 | 	char *errstr = strerror(errno); | ||
| 10 | |||
| 11 | 	FLOCK(f); | ||
| 12 | |||
| 13 | 	/* Save stderr's orientation and encoding rule, since perror is not | ||
| 14 | 	 * permitted to change them. */ | ||
| 15 | 	void *old_locale = f->locale; | ||
| 16 | 	int old_mode = f->mode; | ||
| 17 | 	 | ||
| 18 | 	if (msg && *msg) { | ||
| 19 | 		fwrite(msg, strlen(msg), 1, f); | ||
| 20 | 		fputc(':', f); | ||
| 21 | 		fputc(' ', f); | ||
| 22 | 	} | ||
| 23 | 	fwrite(errstr, strlen(errstr), 1, f); | ||
| 24 | 	fputc('\n', f); | ||
| 25 | |||
| 26 | 	f->mode = old_mode; | ||
| 27 | 	f->locale = old_locale; | ||
| 28 | |||
| 29 | 	FUNLOCK(f); | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/popen.c created+73| ... | @@ -0,0 +1,73 @@ | ||
| 1 | #include <fcntl.h> | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include <spawn.h> | ||
| 6 | #include "stdio_impl.h" | ||
| 7 | #include "syscall.h" | ||
| 8 | |||
| 9 | extern char **__environ; | ||
| 10 | |||
| 11 | FILE *popen(const char *cmd, const char *mode) | ||
| 12 | { | ||
| 13 | 	int p[2], op, e; | ||
| 14 | 	pid_t pid; | ||
| 15 | 	FILE *f; | ||
| 16 | 	posix_spawn_file_actions_t fa; | ||
| 17 | |||
| 18 | 	if (*mode == 'r') { | ||
| 19 | 		op = 0; | ||
| 20 | 	} else if (*mode == 'w') { | ||
| 21 | 		op = 1; | ||
| 22 | 	} else { | ||
| 23 | 		errno = EINVAL; | ||
| 24 | 		return 0; | ||
| 25 | 	} | ||
| 26 | 	 | ||
| 27 | 	if (pipe2(p, O_CLOEXEC)) return NULL; | ||
| 28 | 	f = fdopen(p[op], mode); | ||
| 29 | 	if (!f) { | ||
| 30 | 		__syscall(SYS_close, p[0]); | ||
| 31 | 		__syscall(SYS_close, p[1]); | ||
| 32 | 		return NULL; | ||
| 33 | 	} | ||
| 34 | 	FLOCK(f); | ||
| 35 | |||
| 36 | 	/* If the child's end of the pipe happens to already be on the final | ||
| 37 | 	 * fd number to which it will be assigned (either 0 or 1), it must | ||
| 38 | 	 * be moved to a different fd. Otherwise, there is no safe way to | ||
| 39 | 	 * remove the close-on-exec flag in the child without also creating | ||
| 40 | 	 * a file descriptor leak race condition in the parent. */ | ||
| 41 | 	if (p[1-op] == 1-op) { | ||
| 42 | 		int tmp = fcntl(1-op, F_DUPFD_CLOEXEC, 0); | ||
| 43 | 		if (tmp < 0) { | ||
| 44 | 			e = errno; | ||
| 45 | 			goto fail; | ||
| 46 | 		} | ||
| 47 | 		__syscall(SYS_close, p[1-op]); | ||
| 48 | 		p[1-op] = tmp; | ||
| 49 | 	} | ||
| 50 | |||
| 51 | 	e = ENOMEM; | ||
| 52 | 	if (!posix_spawn_file_actions_init(&fa)) { | ||
| 53 | 		if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) { | ||
| 54 | 			if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0, | ||
| 55 | 			 (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) { | ||
| 56 | 				posix_spawn_file_actions_destroy(&fa); | ||
| 57 | 				f->pipe_pid = pid; | ||
| 58 | 				if (!strchr(mode, 'e')) | ||
| 59 | 					fcntl(p[op], F_SETFD, 0); | ||
| 60 | 				__syscall(SYS_close, p[1-op]); | ||
| 61 | 				FUNLOCK(f); | ||
| 62 | 				return f; | ||
| 63 | 			} | ||
| 64 | 		} | ||
| 65 | 		posix_spawn_file_actions_destroy(&fa); | ||
| 66 | 	} | ||
| 67 | fail: | ||
| 68 | 	fclose(f); | ||
| 69 | 	__syscall(SYS_close, p[1-op]); | ||
| 70 | |||
| 71 | 	errno = e; | ||
| 72 | 	return 0; | ||
| 73 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/printf.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 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 created+9| ... | @@ -0,0 +1,9 @@ | ||
| 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 created+29| ... | @@ -0,0 +1,29 @@ | ||
| 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/putc_unlocked.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int (putc_unlocked)(int c, FILE *f) | ||
| 4 | { | ||
| 5 | 	return putc_unlocked(c, f); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(putc_unlocked, fputc_unlocked); | ||
| 9 | weak_alias(putc_unlocked, _IO_putc_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putchar.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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/putchar_unlocked.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int putchar_unlocked(int c) | ||
| 4 | { | ||
| 5 | 	return putc_unlocked(c, stdout); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/puts.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int puts(const char *s) | ||
| 4 | { | ||
| 5 | 	int r; | ||
| 6 | 	FLOCK(stdout); | ||
| 7 | 	r = -(fputs(s, stdout) < 0 || putc_unlocked('\n', stdout) < 0); | ||
| 8 | 	FUNLOCK(stdout); | ||
| 9 | 	return r; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putw.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | int putw(int x, FILE *f) | ||
| 5 | { | ||
| 6 | 	return (int)fwrite(&x, sizeof x, 1, f)-1; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putwc.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | wint_t putwc(wchar_t c, FILE *f) | ||
| 5 | { | ||
| 6 | 	return fputwc(c, f); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/putwchar.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | wint_t putwchar(wchar_t c) | ||
| 5 | { | ||
| 6 | 	return fputwc(c, stdout); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(putwchar, putwchar_unlocked); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/remove.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int remove(const char *path) | ||
| 7 | { | ||
| 8 | #ifdef SYS_unlink | ||
| 9 | 	int r = __syscall(SYS_unlink, path); | ||
| 10 | #else | ||
| 11 | 	int r = __syscall(SYS_unlinkat, AT_FDCWD, path, 0); | ||
| 12 | #endif | ||
| 13 | #ifdef SYS_rmdir | ||
| 14 | 	if (r==-EISDIR) r = __syscall(SYS_rmdir, path); | ||
| 15 | #else | ||
| 16 | 	if (r==-EISDIR) r = __syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); | ||
| 17 | #endif | ||
| 18 | 	return __syscall_ret(r); | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/rename.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int rename(const char *old, const char *new) | ||
| 6 | { | ||
| 7 | #if defined(SYS_rename) | ||
| 8 | 	return syscall(SYS_rename, old, new); | ||
| 9 | #elif defined(SYS_renameat) | ||
| 10 | 	return syscall(SYS_renameat, AT_FDCWD, old, AT_FDCWD, new); | ||
| 11 | #else | ||
| 12 | 	return syscall(SYS_renameat2, AT_FDCWD, old, AT_FDCWD, new, 0); | ||
| 13 | #endif | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/rewind.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | void rewind(FILE *f) | ||
| 4 | { | ||
| 5 | 	FLOCK(f); | ||
| 6 | 	__fseeko_unlocked(f, 0, SEEK_SET); | ||
| 7 | 	f->flags &= ~F_ERR; | ||
| 8 | 	FUNLOCK(f); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/scanf.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int scanf(const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vscanf(fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(scanf,__isoc99_scanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/setbuf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | void setbuf(FILE *restrict f, char *restrict buf) | ||
| 4 | { | ||
| 5 | 	setvbuf(f, buf, buf ? _IOFBF : _IONBF, BUFSIZ); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/setbuffer.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | void setbuffer(FILE *f, char *buf, size_t size) | ||
| 5 | { | ||
| 6 | 	setvbuf(f, buf, buf ? _IOFBF : _IONBF, size); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/setlinebuf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | |||
| 4 | void setlinebuf(FILE *f) | ||
| 5 | { | ||
| 6 | 	setvbuf(f, 0, _IOLBF, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/setvbuf.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | /* The behavior of this function is undefined except when it is the first | ||
| 4 | * operation on the stream, so the presence or absence of locking is not | ||
| 5 | * observable in a program whose behavior is defined. Thus no locking is | ||
| 6 | * performed here. No allocation of buffers is performed, but a buffer | ||
| 7 | * provided by the caller is used as long as it is suitably sized. */ | ||
| 8 | |||
| 9 | int setvbuf(FILE *restrict f, char *restrict buf, int type, size_t size) | ||
| 10 | { | ||
| 11 | 	f->lbf = EOF; | ||
| 12 | |||
| 13 | 	if (type == _IONBF) { | ||
| 14 | 		f->buf_size = 0; | ||
| 15 | 	} else if (type == _IOLBF || type == _IOFBF) { | ||
| 16 | 		if (buf && size >= UNGET) { | ||
| 17 | 			f->buf = (void *)(buf + UNGET); | ||
| 18 | 			f->buf_size = size - UNGET; | ||
| 19 | 		} | ||
| 20 | 		if (type == _IOLBF && f->buf_size) | ||
| 21 | 			f->lbf = '\n'; | ||
| 22 | 	} else { | ||
| 23 | 		return -1; | ||
| 24 | 	} | ||
| 25 | |||
| 26 | 	f->flags |= F_SVB; | ||
| 27 | |||
| 28 | 	return 0; | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/snprintf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int snprintf(char *restrict s, size_t n, const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vsnprintf(s, n, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | |||
lib/libc/wasi/libc-top-half/musl/src/stdio/sprintf.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int sprintf(char *restrict s, const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vsprintf(s, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/sscanf.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int sscanf(const char *restrict s, const char *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vsscanf(s, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(sscanf,__isoc99_sscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/stderr.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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 created+19| ... | @@ -0,0 +1,19 @@ | ||
| 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 created+20| ... | @@ -0,0 +1,20 @@ | ||
| 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/swprintf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdarg.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | int swprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vswprintf(s, n, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | |||
lib/libc/wasi/libc-top-half/musl/src/stdio/swscanf.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <stdarg.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | int swscanf(const wchar_t *restrict s, const wchar_t *restrict fmt, ...) | ||
| 5 | { | ||
| 6 | 	int ret; | ||
| 7 | 	va_list ap; | ||
| 8 | 	va_start(ap, fmt); | ||
| 9 | 	ret = vswscanf(s, fmt, ap); | ||
| 10 | 	va_end(ap); | ||
| 11 | 	return ret; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(swscanf,__isoc99_swscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/tempnam.c created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <sys/stat.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <stdlib.h> | ||
| 8 | #include "syscall.h" | ||
| 9 | #include "kstat.h" | ||
| 10 | |||
| 11 | #define MAXTRIES 100 | ||
| 12 | |||
| 13 | char *tempnam(const char *dir, const char *pfx) | ||
| 14 | { | ||
| 15 | 	char s[PATH_MAX]; | ||
| 16 | 	size_t l, dl, pl; | ||
| 17 | 	int try; | ||
| 18 | 	int r; | ||
| 19 | |||
| 20 | 	if (!dir) dir = P_tmpdir; | ||
| 21 | 	if (!pfx) pfx = "temp"; | ||
| 22 | |||
| 23 | 	dl = strlen(dir); | ||
| 24 | 	pl = strlen(pfx); | ||
| 25 | 	l = dl + 1 + pl + 1 + 6; | ||
| 26 | |||
| 27 | 	if (l >= PATH_MAX) { | ||
| 28 | 		errno = ENAMETOOLONG; | ||
| 29 | 		return 0; | ||
| 30 | 	} | ||
| 31 | |||
| 32 | 	memcpy(s, dir, dl); | ||
| 33 | 	s[dl] = '/'; | ||
| 34 | 	memcpy(s+dl+1, pfx, pl); | ||
| 35 | 	s[dl+1+pl] = '_'; | ||
| 36 | 	s[l] = 0; | ||
| 37 | |||
| 38 | 	for (try=0; try<MAXTRIES; try++) { | ||
| 39 | 		__randname(s+l-6); | ||
| 40 | #ifdef SYS_lstat | ||
| 41 | 		r = __syscall(SYS_lstat, s, &(struct kstat){0}); | ||
| 42 | #else | ||
| 43 | 		r = __syscall(SYS_fstatat, AT_FDCWD, s, | ||
| 44 | 			&(struct kstat){0}, AT_SYMLINK_NOFOLLOW); | ||
| 45 | #endif | ||
| 46 | 		if (r == -ENOENT) return strdup(s); | ||
| 47 | 	} | ||
| 48 | 	return 0; | ||
| 49 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/tmpfile.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include "stdio_impl.h" | ||
| 5 | |||
| 6 | #define MAXTRIES 100 | ||
| 7 | |||
| 8 | FILE *tmpfile(void) | ||
| 9 | { | ||
| 10 | 	char s[] = "/tmp/tmpfile_XXXXXX"; | ||
| 11 | 	int fd; | ||
| 12 | 	FILE *f; | ||
| 13 | 	int try; | ||
| 14 | 	for (try=0; try<MAXTRIES; try++) { | ||
| 15 | 		__randname(s+13); | ||
| 16 | 		fd = sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600); | ||
| 17 | 		if (fd >= 0) { | ||
| 18 | #ifdef SYS_unlink | ||
| 19 | 			__syscall(SYS_unlink, s); | ||
| 20 | #else | ||
| 21 | 			__syscall(SYS_unlinkat, AT_FDCWD, s, 0); | ||
| 22 | #endif | ||
| 23 | 			f = __fdopen(fd, "w+"); | ||
| 24 | 			if (!f) __syscall(SYS_close, fd); | ||
| 25 | 			return f; | ||
| 26 | 		} | ||
| 27 | 	} | ||
| 28 | 	return 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | weak_alias(tmpfile, tmpfile64); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/tmpnam.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <sys/stat.h> | ||
| 5 | #include <string.h> | ||
| 6 | #include <stdlib.h> | ||
| 7 | #include "syscall.h" | ||
| 8 | #include "kstat.h" | ||
| 9 | |||
| 10 | #define MAXTRIES 100 | ||
| 11 | |||
| 12 | char *tmpnam(char *buf) | ||
| 13 | { | ||
| 14 | 	static char internal[L_tmpnam]; | ||
| 15 | 	char s[] = "/tmp/tmpnam_XXXXXX"; | ||
| 16 | 	int try; | ||
| 17 | 	int r; | ||
| 18 | 	for (try=0; try<MAXTRIES; try++) { | ||
| 19 | 		__randname(s+12); | ||
| 20 | #ifdef SYS_lstat | ||
| 21 | 		r = __syscall(SYS_lstat, s, &(struct kstat){0}); | ||
| 22 | #else | ||
| 23 | 		r = __syscall(SYS_fstatat, AT_FDCWD, s, | ||
| 24 | 			&(struct kstat){0}, AT_SYMLINK_NOFOLLOW); | ||
| 25 | #endif | ||
| 26 | 		if (r == -ENOENT) return strcpy(buf ? buf : internal, s); | ||
| 27 | 	} | ||
| 28 | 	return 0; | ||
| 29 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ungetc.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | |||
| 3 | int ungetc(int c, FILE *f) | ||
| 4 | { | ||
| 5 | 	if (c == EOF) return c; | ||
| 6 | |||
| 7 | 	FLOCK(f); | ||
| 8 | |||
| 9 | 	if (!f->rpos) __toread(f); | ||
| 10 | 	if (!f->rpos || f->rpos <= f->buf - UNGET) { | ||
| 11 | 		FUNLOCK(f); | ||
| 12 | 		return EOF; | ||
| 13 | 	} | ||
| 14 | |||
| 15 | 	*--f->rpos = c; | ||
| 16 | 	f->flags &= ~F_EOF; | ||
| 17 | |||
| 18 | 	FUNLOCK(f); | ||
| 19 | 	return (unsigned char)c; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/ungetwc.c created+35| ... | @@ -0,0 +1,35 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "locale_impl.h" | ||
| 3 | #include <wchar.h> | ||
| 4 | #include <limits.h> | ||
| 5 | #include <ctype.h> | ||
| 6 | #include <string.h> | ||
| 7 | |||
| 8 | wint_t ungetwc(wint_t c, FILE *f) | ||
| 9 | { | ||
| 10 | 	unsigned char mbc[MB_LEN_MAX]; | ||
| 11 | 	int l; | ||
| 12 | 	locale_t *ploc = &CURRENT_LOCALE, loc = *ploc; | ||
| 13 | |||
| 14 | 	FLOCK(f); | ||
| 15 | |||
| 16 | 	if (f->mode <= 0) fwide(f, 1); | ||
| 17 | 	*ploc = f->locale; | ||
| 18 | |||
| 19 | 	if (!f->rpos) __toread(f); | ||
| 20 | 	if (!f->rpos || c == WEOF || (l = wcrtomb((void *)mbc, c, 0)) < 0 || | ||
| 21 | 	 f->rpos < f->buf - UNGET + l) { | ||
| 22 | 		FUNLOCK(f); | ||
| 23 | 		*ploc = loc; | ||
| 24 | 		return WEOF; | ||
| 25 | 	} | ||
| 26 | |||
| 27 | 	if (isascii(c)) *--f->rpos = c; | ||
| 28 | 	else memcpy(f->rpos -= l, mbc, l); | ||
| 29 | |||
| 30 | 	f->flags &= ~F_EOF; | ||
| 31 | |||
| 32 | 	FUNLOCK(f); | ||
| 33 | 	*ploc = loc; | ||
| 34 | 	return c; | ||
| 35 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vasprintf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include <stdlib.h> | ||
| 5 | |||
| 6 | int vasprintf(char **s, const char *fmt, va_list ap) | ||
| 7 | { | ||
| 8 | 	va_list ap2; | ||
| 9 | 	va_copy(ap2, ap); | ||
| 10 | 	int l = vsnprintf(0, 0, fmt, ap2); | ||
| 11 | 	va_end(ap2); | ||
| 12 | |||
| 13 | 	if (l<0 || !(*s=malloc(l+1U))) return -1; | ||
| 14 | 	return vsnprintf(*s, l+1U, fmt, ap); | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vdprintf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 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 created+737| ... | @@ -0,0 +1,737 @@ | ||
| 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') = CHAR, S('C') = INT, | ||
| 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') = INT, 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 (!(f->flags & F_ERR)) __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+3+LDBL_MANT_DIG/4]; | ||
| 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 | 				nl_type[s[1]-'0'] = INT; | ||
| 521 | 				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 | 				nl_type[s[2]-'0'] = INT; | ||
| 534 | 				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) nl_type[argpos]=st, arg=nl_arg[argpos]; | ||
| 564 | 			else if (f) pop_arg(&arg, st, ap); | ||
| 565 | 			else return 0; | ||
| 566 | 		} | ||
| 567 | |||
| 568 | 		if (!f) continue; | ||
| 569 | |||
| 570 | 		z = buf + sizeof(buf); | ||
| 571 | 		prefix = "-+ 0X0x"; | ||
| 572 | 		pl = 0; | ||
| 573 | 		t = s[-1]; | ||
| 574 | |||
| 575 | 		/* Transform ls,lc -> S,C */ | ||
| 576 | 		if (ps && (t&15)==3) t&=~32; | ||
| 577 | |||
| 578 | 		/* - and 0 flags are mutually exclusive */ | ||
| 579 | 		if (fl & LEFT_ADJ) fl &= ~ZERO_PAD; | ||
| 580 | |||
| 581 | 		switch(t) { | ||
| 582 | 		case 'n': | ||
| 583 | 			switch(ps) { | ||
| 584 | 			case BARE: *(int *)arg.p = cnt; break; | ||
| 585 | 			case LPRE: *(long *)arg.p = cnt; break; | ||
| 586 | 			case LLPRE: *(long long *)arg.p = cnt; break; | ||
| 587 | 			case HPRE: *(unsigned short *)arg.p = cnt; break; | ||
| 588 | 			case HHPRE: *(unsigned char *)arg.p = cnt; break; | ||
| 589 | 			case ZTPRE: *(size_t *)arg.p = cnt; break; | ||
| 590 | 			case JPRE: *(uintmax_t *)arg.p = cnt; break; | ||
| 591 | 			} | ||
| 592 | 			continue; | ||
| 593 | 		case 'p': | ||
| 594 | 			p = MAX(p, 2*sizeof(void*)); | ||
| 595 | 			t = 'x'; | ||
| 596 | 			fl |= ALT_FORM; | ||
| 597 | 		case 'x': case 'X': | ||
| 598 | 			a = fmt_x(arg.i, z, t&32); | ||
| 599 | 			if (arg.i && (fl & ALT_FORM)) prefix+=(t>>4), pl=2; | ||
| 600 | 			if (0) { | ||
| 601 | 		case 'o': | ||
| 602 | 			a = fmt_o(arg.i, z); | ||
| 603 | 			if ((fl&ALT_FORM) && p<z-a+1) p=z-a+1; | ||
| 604 | 			} if (0) { | ||
| 605 | 		case 'd': case 'i': | ||
| 606 | 			pl=1; | ||
| 607 | 			if (arg.i>INTMAX_MAX) { | ||
| 608 | 				arg.i=-arg.i; | ||
| 609 | 			} else if (fl & MARK_POS) { | ||
| 610 | 				prefix++; | ||
| 611 | 			} else if (fl & PAD_POS) { | ||
| 612 | 				prefix+=2; | ||
| 613 | 			} else pl=0; | ||
| 614 | 		case 'u': | ||
| 615 | 			a = fmt_u(arg.i, z); | ||
| 616 | 			} | ||
| 617 | 			if (xp && p<0) goto overflow; | ||
| 618 | 			if (xp) fl &= ~ZERO_PAD; | ||
| 619 | 			if (!arg.i && !p) { | ||
| 620 | 				a=z; | ||
| 621 | 				break; | ||
| 622 | 			} | ||
| 623 | 			p = MAX(p, z-a + !arg.i); | ||
| 624 | 			break; | ||
| 625 | 		case 'c': | ||
| 626 | 			*(a=z-(p=1))=arg.i; | ||
| 627 | 			fl &= ~ZERO_PAD; | ||
| 628 | 			break; | ||
| 629 | 		case 'm': | ||
| 630 | 			if (1) a = strerror(errno); else | ||
| 631 | 		case 's': | ||
| 632 | 			a = arg.p ? arg.p : "(null)"; | ||
| 633 | 			z = a + strnlen(a, p<0 ? INT_MAX : p); | ||
| 634 | 			if (p<0 && *z) goto overflow; | ||
| 635 | 			p = z-a; | ||
| 636 | 			fl &= ~ZERO_PAD; | ||
| 637 | 			break; | ||
| 638 | 		case 'C': | ||
| 639 | 			wc[0] = arg.i; | ||
| 640 | 			wc[1] = 0; | ||
| 641 | 			arg.p = wc; | ||
| 642 | 			p = -1; | ||
| 643 | 		case 'S': | ||
| 644 | 			ws = arg.p; | ||
| 645 | 			for (i=l=0; i<p && *ws && (l=wctomb(mb, *ws++))>=0 && l<=p-i; i+=l); | ||
| 646 | 			if (l<0) return -1; | ||
| 647 | 			if (i > INT_MAX) goto overflow; | ||
| 648 | 			p = i; | ||
| 649 | 			pad(f, ' ', w, p, fl); | ||
| 650 | 			ws = arg.p; | ||
| 651 | 			for (i=0; i<0U+p && *ws && i+(l=wctomb(mb, *ws++))<=p; i+=l) | ||
| 652 | 				out(f, mb, l); | ||
| 653 | 			pad(f, ' ', w, p, fl^LEFT_ADJ); | ||
| 654 | 			l = w>p ? w : p; | ||
| 655 | 			continue; | ||
| 656 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 657 | 		case 'e': case 'f': case 'g': case 'a': | ||
| 658 | 		case 'E': case 'F': case 'G': case 'A': | ||
| 659 | 			if (xp && p<0) goto overflow; | ||
| 660 | 			l = fmt_fp(f, arg.f, w, p, fl, t); | ||
| 661 | 			if (l<0) goto overflow; | ||
| 662 | 			continue; | ||
| 663 | #endif | ||
| 664 | 		} | ||
| 665 | |||
| 666 | 		if (p < z-a) p = z-a; | ||
| 667 | 		if (p > INT_MAX-pl) goto overflow; | ||
| 668 | 		if (w < pl+p) w = pl+p; | ||
| 669 | 		if (w > INT_MAX-cnt) goto overflow; | ||
| 670 | |||
| 671 | 		pad(f, ' ', w, pl+p, fl); | ||
| 672 | 		out(f, prefix, pl); | ||
| 673 | 		pad(f, '0', w, pl+p, fl^ZERO_PAD); | ||
| 674 | 		pad(f, '0', p, z-a, 0); | ||
| 675 | 		out(f, a, z-a); | ||
| 676 | 		pad(f, ' ', w, pl+p, fl^LEFT_ADJ); | ||
| 677 | |||
| 678 | 		l = w; | ||
| 679 | 	} | ||
| 680 | |||
| 681 | 	if (f) return cnt; | ||
| 682 | 	if (!l10n) return 0; | ||
| 683 | |||
| 684 | 	for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) | ||
| 685 | 		pop_arg(nl_arg+i, nl_type[i], ap); | ||
| 686 | 	for (; i<=NL_ARGMAX && !nl_type[i]; i++); | ||
| 687 | 	if (i<=NL_ARGMAX) goto inval; | ||
| 688 | 	return 1; | ||
| 689 | |||
| 690 | inval: | ||
| 691 | 	errno = EINVAL; | ||
| 692 | 	return -1; | ||
| 693 | overflow: | ||
| 694 | 	errno = EOVERFLOW; | ||
| 695 | 	return -1; | ||
| 696 | } | ||
| 697 | |||
| 698 | int vfprintf(FILE *restrict f, const char *restrict fmt, va_list ap) | ||
| 699 | { | ||
| 700 | 	va_list ap2; | ||
| 701 | 	int nl_type[NL_ARGMAX+1] = {0}; | ||
| 702 | 	union arg nl_arg[NL_ARGMAX+1]; | ||
| 703 | 	unsigned char internal_buf[80], *saved_buf = 0; | ||
| 704 | 	int olderr; | ||
| 705 | 	int ret; | ||
| 706 | |||
| 707 | 	/* the copy allows passing va_list* even if va_list is an array */ | ||
| 708 | 	va_copy(ap2, ap); | ||
| 709 | 	if (printf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { | ||
| 710 | 		va_end(ap2); | ||
| 711 | 		return -1; | ||
| 712 | 	} | ||
| 713 | |||
| 714 | 	FLOCK(f); | ||
| 715 | 	olderr = f->flags & F_ERR; | ||
| 716 | 	if (f->mode < 1) f->flags &= ~F_ERR; | ||
| 717 | 	if (!f->buf_size) { | ||
| 718 | 		saved_buf = f->buf; | ||
| 719 | 		f->buf = internal_buf; | ||
| 720 | 		f->buf_size = sizeof internal_buf; | ||
| 721 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 722 | 	} | ||
| 723 | 	if (!f->wend && __towrite(f)) ret = -1; | ||
| 724 | 	else ret = printf_core(f, fmt, &ap2, nl_arg, nl_type); | ||
| 725 | 	if (saved_buf) { | ||
| 726 | 		f->write(f, 0, 0); | ||
| 727 | 		if (!f->wpos) ret = -1; | ||
| 728 | 		f->buf = saved_buf; | ||
| 729 | 		f->buf_size = 0; | ||
| 730 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 731 | 	} | ||
| 732 | 	if (f->flags & F_ERR) ret = -1; | ||
| 733 | 	f->flags |= olderr; | ||
| 734 | 	FUNLOCK(f); | ||
| 735 | 	va_end(ap2); | ||
| 736 | 	return ret; | ||
| 737 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vfscanf.c created+351| ... | @@ -0,0 +1,351 @@ | ||
| 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 created+414| ... | @@ -0,0 +1,414 @@ | ||
| 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') = CHAR, S('C') = INT, | ||
| 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') = INT, 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-- && !(f->flags & F_ERR)) fputwc(*s++, f); | ||
| 148 | } | ||
| 149 | |||
| 150 | static int getint(wchar_t **s) { | ||
| 151 | 	int i; | ||
| 152 | 	for (i=0; iswdigit(**s); (*s)++) { | ||
| 153 | 		if (i > INT_MAX/10U || **s-'0' > INT_MAX-10*i) i = -1; | ||
| 154 | 		else i = 10*i + (**s-'0'); | ||
| 155 | 	} | ||
| 156 | 	return i; | ||
| 157 | } | ||
| 158 | |||
| 159 | static const char sizeprefix['y'-'a'] = { | ||
| 160 | ['a'-'a']='L', ['e'-'a']='L', ['f'-'a']='L', ['g'-'a']='L', | ||
| 161 | ['d'-'a']='j', ['i'-'a']='j', ['o'-'a']='j', ['u'-'a']='j', ['x'-'a']='j', | ||
| 162 | ['p'-'a']='j' | ||
| 163 | }; | ||
| 164 | |||
| 165 | static int wprintf_core(FILE *f, const wchar_t *fmt, va_list *ap, union arg *nl_arg, int *nl_type) | ||
| 166 | { | ||
| 167 | 	wchar_t *a, *z, *s=(wchar_t *)fmt; | ||
| 168 | 	unsigned l10n=0, fl; | ||
| 169 | 	int w, p, xp; | ||
| 170 | 	union arg arg; | ||
| 171 | 	int argpos; | ||
| 172 | 	unsigned st, ps; | ||
| 173 | 	int cnt=0, l=0; | ||
| 174 | 	int i; | ||
| 175 | 	int t; | ||
| 176 | 	char *bs; | ||
| 177 | 	char charfmt[16]; | ||
| 178 | 	wchar_t wc; | ||
| 179 | |||
| 180 | 	for (;;) { | ||
| 181 | 		/* This error is only specified for snprintf, but since it's | ||
| 182 | 		 * unspecified for other forms, do the same. Stop immediately | ||
| 183 | 		 * on overflow; otherwise %n could produce wrong results. */ | ||
| 184 | 		if (l > INT_MAX - cnt) goto overflow; | ||
| 185 | |||
| 186 | 		/* Update output count, end loop when fmt is exhausted */ | ||
| 187 | 		cnt += l; | ||
| 188 | 		if (!*s) break; | ||
| 189 | |||
| 190 | 		/* Handle literal text and %% format specifiers */ | ||
| 191 | 		for (a=s; *s && *s!='%'; s++); | ||
| 192 | 		for (z=s; s[0]=='%' && s[1]=='%'; z++, s+=2); | ||
| 193 | 		if (z-a > INT_MAX-cnt) goto overflow; | ||
| 194 | 		l = z-a; | ||
| 195 | 		if (f) out(f, a, l); | ||
| 196 | 		if (l) continue; | ||
| 197 | |||
| 198 | 		if (iswdigit(s[1]) && s[2]=='$') { | ||
| 199 | 			l10n=1; | ||
| 200 | 			argpos = s[1]-'0'; | ||
| 201 | 			s+=3; | ||
| 202 | 		} else { | ||
| 203 | 			argpos = -1; | ||
| 204 | 			s++; | ||
| 205 | 		} | ||
| 206 | |||
| 207 | 		/* Read modifier flags */ | ||
| 208 | 		for (fl=0; (unsigned)*s-' '<32 && (FLAGMASK&(1U<<*s-' ')); s++) | ||
| 209 | 			fl |= 1U<<*s-' '; | ||
| 210 | |||
| 211 | 		/* Read field width */ | ||
| 212 | 		if (*s=='*') { | ||
| 213 | 			if (iswdigit(s[1]) && s[2]=='$') { | ||
| 214 | 				l10n=1; | ||
| 215 | 				nl_type[s[1]-'0'] = INT; | ||
| 216 | 				w = nl_arg[s[1]-'0'].i; | ||
| 217 | 				s+=3; | ||
| 218 | 			} else if (!l10n) { | ||
| 219 | 				w = f ? va_arg(*ap, int) : 0; | ||
| 220 | 				s++; | ||
| 221 | 			} else goto inval; | ||
| 222 | 			if (w<0) fl|=LEFT_ADJ, w=-w; | ||
| 223 | 		} else if ((w=getint(&s))<0) goto overflow; | ||
| 224 | |||
| 225 | 		/* Read precision */ | ||
| 226 | 		if (*s=='.' && s[1]=='*') { | ||
| 227 | 			if (isdigit(s[2]) && s[3]=='$') { | ||
| 228 | 				nl_type[s[2]-'0'] = INT; | ||
| 229 | 				p = nl_arg[s[2]-'0'].i; | ||
| 230 | 				s+=4; | ||
| 231 | 			} else if (!l10n) { | ||
| 232 | 				p = f ? va_arg(*ap, int) : 0; | ||
| 233 | 				s+=2; | ||
| 234 | 			} else goto inval; | ||
| 235 | 			xp = (p>=0); | ||
| 236 | 		} else if (*s=='.') { | ||
| 237 | 			s++; | ||
| 238 | 			p = getint(&s); | ||
| 239 | 			xp = 1; | ||
| 240 | 		} else { | ||
| 241 | 			p = -1; | ||
| 242 | 			xp = 0; | ||
| 243 | 		} | ||
| 244 | |||
| 245 | 		/* Format specifier state machine */ | ||
| 246 | 		st=0; | ||
| 247 | 		do { | ||
| 248 | 			if (OOB(*s)) goto inval; | ||
| 249 | 			ps=st; | ||
| 250 | 			st=states[st]S(*s++); | ||
| 251 | 		} while (st-1<STOP); | ||
| 252 | 		if (!st) goto inval; | ||
| 253 | |||
| 254 | 		/* Check validity of argument type (nl/normal) */ | ||
| 255 | 		if (st==NOARG) { | ||
| 256 | 			if (argpos>=0) goto inval; | ||
| 257 | 		} else { | ||
| 258 | 			if (argpos>=0) nl_type[argpos]=st, arg=nl_arg[argpos]; | ||
| 259 | 			else if (f) pop_arg(&arg, st, ap); | ||
| 260 | 			else return 0; | ||
| 261 | 		} | ||
| 262 | |||
| 263 | 		if (!f) continue; | ||
| 264 | 		t = s[-1]; | ||
| 265 | 		if (ps && (t&15)==3) t&=~32; | ||
| 266 | |||
| 267 | 		switch (t) { | ||
| 268 | 		case 'n': | ||
| 269 | 			switch(ps) { | ||
| 270 | 			case BARE: *(int *)arg.p = cnt; break; | ||
| 271 | 			case LPRE: *(long *)arg.p = cnt; break; | ||
| 272 | 			case LLPRE: *(long long *)arg.p = cnt; break; | ||
| 273 | 			case HPRE: *(unsigned short *)arg.p = cnt; break; | ||
| 274 | 			case HHPRE: *(unsigned char *)arg.p = cnt; break; | ||
| 275 | 			case ZTPRE: *(size_t *)arg.p = cnt; break; | ||
| 276 | 			case JPRE: *(uintmax_t *)arg.p = cnt; break; | ||
| 277 | 			} | ||
| 278 | 			continue; | ||
| 279 | 		case 'c': | ||
| 280 | 			if (w<1) w=1; | ||
| 281 | 			if (w>1 && !(fl&LEFT_ADJ)) fprintf(f, "%*s", w-1, ""); | ||
| 282 | 			fputwc(btowc(arg.i), f); | ||
| 283 | 			if (w>1 && (fl&LEFT_ADJ)) fprintf(f, "%*s", w-1, ""); | ||
| 284 | 			l = w; | ||
| 285 | 			continue; | ||
| 286 | 		case 'C': | ||
| 287 | 			fputwc(arg.i, f); | ||
| 288 | 			l = 1; | ||
| 289 | 			continue; | ||
| 290 | 		case 'S': | ||
| 291 | 			a = arg.p; | ||
| 292 | 			z = a + wcsnlen(a, p<0 ? INT_MAX : p); | ||
| 293 | 			if (p<0 && *z) goto overflow; | ||
| 294 | 			p = z-a; | ||
| 295 | 			if (w<p) w=p; | ||
| 296 | 			if (!(fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, ""); | ||
| 297 | 			out(f, a, p); | ||
| 298 | 			if ((fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, ""); | ||
| 299 | 			l=w; | ||
| 300 | 			continue; | ||
| 301 | 		case 'm': | ||
| 302 | 			arg.p = strerror(errno); | ||
| 303 | 		case 's': | ||
| 304 | 			if (!arg.p) arg.p = "(null)"; | ||
| 305 | 			bs = arg.p; | ||
| 306 | 			for (i=l=0; l<(p<0?INT_MAX:p) && (i=mbtowc(&wc, bs, MB_LEN_MAX))>0; bs+=i, l++); | ||
| 307 | 			if (i<0) return -1; | ||
| 308 | 			if (p<0 && *bs) goto overflow; | ||
| 309 | 			p=l; | ||
| 310 | 			if (w<p) w=p; | ||
| 311 | 			if (!(fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, ""); | ||
| 312 | 			bs = arg.p; | ||
| 313 | 			while (l--) { | ||
| 314 | 				i=mbtowc(&wc, bs, MB_LEN_MAX); | ||
| 315 | 				bs+=i; | ||
| 316 | 				fputwc(wc, f); | ||
| 317 | 			} | ||
| 318 | 			if ((fl&LEFT_ADJ)) fprintf(f, "%*s", w-p, ""); | ||
| 319 | 			l=w; | ||
| 320 | 			continue; | ||
| 321 | 		} | ||
| 322 | |||
| 323 | 		if (xp && p<0) goto overflow; | ||
| 324 | #if defined(__wasilibc_printscan_no_long_double) | ||
| 325 | 		// Omit the 'L' modifier for floating-point cases. | ||
| 326 | 		switch (t|32) { | ||
| 327 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 328 | 			snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c", | ||
| 329 | 				"#"+!(fl & ALT_FORM), | ||
| 330 | 				"+"+!(fl & MARK_POS), | ||
| 331 | 				"-"+!(fl & LEFT_ADJ), | ||
| 332 | 				" "+!(fl & PAD_POS), | ||
| 333 | 				"0"+!(fl & ZERO_PAD), | ||
| 334 | 				t); | ||
| 335 | |||
| 336 | 			l = fprintf(f, charfmt, w, p, arg.f); | ||
| 337 | 			break; | ||
| 338 | 		case 'd': case 'i': case 'o': case 'u': case 'x': case 'p': | ||
| 339 | 			snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c%c", | ||
| 340 | 				"#"+!(fl & ALT_FORM), | ||
| 341 | 				"+"+!(fl & MARK_POS), | ||
| 342 | 				"-"+!(fl & LEFT_ADJ), | ||
| 343 | 				" "+!(fl & PAD_POS), | ||
| 344 | 				"0"+!(fl & ZERO_PAD), | ||
| 345 | 				sizeprefix[(t|32)-'a'], t); | ||
| 346 | |||
| 347 | 			l = fprintf(f, charfmt, w, p, arg.i); | ||
| 348 | 			break; | ||
| 349 | 		} | ||
| 350 | #else | ||
| 351 | 		snprintf(charfmt, sizeof charfmt, "%%%s%s%s%s%s*.*%c%c", | ||
| 352 | 			"#"+!(fl & ALT_FORM), | ||
| 353 | 			"+"+!(fl & MARK_POS), | ||
| 354 | 			"-"+!(fl & LEFT_ADJ), | ||
| 355 | 			" "+!(fl & PAD_POS), | ||
| 356 | 			"0"+!(fl & ZERO_PAD), | ||
| 357 | 			sizeprefix[(t|32)-'a'], t); | ||
| 358 | |||
| 359 | 		switch (t|32) { | ||
| 360 | #if !defined(__wasilibc_printscan_no_floating_point) | ||
| 361 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 362 | 			l = fprintf(f, charfmt, w, p, arg.f); | ||
| 363 | 			break; | ||
| 364 | #endif | ||
| 365 | 		case 'd': case 'i': case 'o': case 'u': case 'x': case 'p': | ||
| 366 | 			l = fprintf(f, charfmt, w, p, arg.i); | ||
| 367 | 			break; | ||
| 368 | 		} | ||
| 369 | #endif | ||
| 370 | 	} | ||
| 371 | |||
| 372 | 	if (f) return cnt; | ||
| 373 | 	if (!l10n) return 0; | ||
| 374 | |||
| 375 | 	for (i=1; i<=NL_ARGMAX && nl_type[i]; i++) | ||
| 376 | 		pop_arg(nl_arg+i, nl_type[i], ap); | ||
| 377 | 	for (; i<=NL_ARGMAX && !nl_type[i]; i++); | ||
| 378 | 	if (i<=NL_ARGMAX) return -1; | ||
| 379 | 	return 1; | ||
| 380 | |||
| 381 | inval: | ||
| 382 | 	errno = EINVAL; | ||
| 383 | 	return -1; | ||
| 384 | overflow: | ||
| 385 | 	errno = EOVERFLOW; | ||
| 386 | 	return -1; | ||
| 387 | } | ||
| 388 | |||
| 389 | int vfwprintf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) | ||
| 390 | { | ||
| 391 | 	va_list ap2; | ||
| 392 | 	int nl_type[NL_ARGMAX] = {0}; | ||
| 393 | 	union arg nl_arg[NL_ARGMAX]; | ||
| 394 | 	int olderr; | ||
| 395 | 	int ret; | ||
| 396 | |||
| 397 | 	/* the copy allows passing va_list* even if va_list is an array */ | ||
| 398 | 	va_copy(ap2, ap); | ||
| 399 | 	if (wprintf_core(0, fmt, &ap2, nl_arg, nl_type) < 0) { | ||
| 400 | 		va_end(ap2); | ||
| 401 | 		return -1; | ||
| 402 | 	} | ||
| 403 | |||
| 404 | 	FLOCK(f); | ||
| 405 | 	fwide(f, 1); | ||
| 406 | 	olderr = f->flags & F_ERR; | ||
| 407 | 	f->flags &= ~F_ERR; | ||
| 408 | 	ret = wprintf_core(f, fmt, &ap2, nl_arg, nl_type); | ||
| 409 | 	if (f->flags & F_ERR) ret = -1; | ||
| 410 | 	f->flags |= olderr; | ||
| 411 | 	FUNLOCK(f); | ||
| 412 | 	va_end(ap2); | ||
| 413 | 	return ret; | ||
| 414 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vfwscanf.c created+332| ... | @@ -0,0 +1,332 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdarg.h> | ||
| 4 | #include <ctype.h> | ||
| 5 | #include <wchar.h> | ||
| 6 | #include <wctype.h> | ||
| 7 | #include <limits.h> | ||
| 8 | #include <string.h> | ||
| 9 | |||
| 10 | #include "stdio_impl.h" | ||
| 11 | #include "shgetc.h" | ||
| 12 | #include "intscan.h" | ||
| 13 | #include "floatscan.h" | ||
| 14 | |||
| 15 | #define SIZE_hh -2 | ||
| 16 | #define SIZE_h -1 | ||
| 17 | #define SIZE_def 0 | ||
| 18 | #define SIZE_l 1 | ||
| 19 | #define SIZE_L 2 | ||
| 20 | #define SIZE_ll 3 | ||
| 21 | |||
| 22 | static void store_int(void *dest, int size, unsigned long long i) | ||
| 23 | { | ||
| 24 | 	if (!dest) return; | ||
| 25 | 	switch (size) { | ||
| 26 | 	case SIZE_hh: | ||
| 27 | 		*(char *)dest = i; | ||
| 28 | 		break; | ||
| 29 | 	case SIZE_h: | ||
| 30 | 		*(short *)dest = i; | ||
| 31 | 		break; | ||
| 32 | 	case SIZE_def: | ||
| 33 | 		*(int *)dest = i; | ||
| 34 | 		break; | ||
| 35 | 	case SIZE_l: | ||
| 36 | 		*(long *)dest = i; | ||
| 37 | 		break; | ||
| 38 | 	case SIZE_ll: | ||
| 39 | 		*(long long *)dest = i; | ||
| 40 | 		break; | ||
| 41 | 	} | ||
| 42 | } | ||
| 43 | |||
| 44 | static void *arg_n(va_list ap, unsigned int n) | ||
| 45 | { | ||
| 46 | 	void *p; | ||
| 47 | 	unsigned int i; | ||
| 48 | 	va_list ap2; | ||
| 49 | 	va_copy(ap2, ap); | ||
| 50 | 	for (i=n; i>1; i--) va_arg(ap2, void *); | ||
| 51 | 	p = va_arg(ap2, void *); | ||
| 52 | 	va_end(ap2); | ||
| 53 | 	return p; | ||
| 54 | } | ||
| 55 | |||
| 56 | static int in_set(const wchar_t *set, int c) | ||
| 57 | { | ||
| 58 | 	int j; | ||
| 59 | 	const wchar_t *p = set; | ||
| 60 | 	if (*p == '-') { | ||
| 61 | 		if (c=='-') return 1; | ||
| 62 | 		p++; | ||
| 63 | 	} else if (*p == ']') { | ||
| 64 | 		if (c==']') return 1; | ||
| 65 | 		p++; | ||
| 66 | 	} | ||
| 67 | 	for (; *p && *p != ']'; p++) { | ||
| 68 | 		if (*p=='-' && p[1] && p[1] != ']') | ||
| 69 | 			for (j=p++[-1]; j<*p; j++) | ||
| 70 | 				if (c==j) return 1; | ||
| 71 | 		if (c==*p) return 1; | ||
| 72 | 	} | ||
| 73 | 	return 0; | ||
| 74 | } | ||
| 75 | |||
| 76 | #if 1 | ||
| 77 | #undef getwc | ||
| 78 | #define getwc(f) \ | ||
| 79 | 	((f)->rpos != (f)->rend && *(f)->rpos < 128 ? *(f)->rpos++ : (getwc)(f)) | ||
| 80 | |||
| 81 | #undef ungetwc | ||
| 82 | #define ungetwc(c,f) \ | ||
| 83 | 	((f)->rend && (c)<128U ? *--(f)->rpos : ungetwc((c),(f))) | ||
| 84 | #endif | ||
| 85 | |||
| 86 | int vfwscanf(FILE *restrict f, const wchar_t *restrict fmt, va_list ap) | ||
| 87 | { | ||
| 88 | 	int width; | ||
| 89 | 	int size; | ||
| 90 | 	int alloc; | ||
| 91 | 	const wchar_t *p; | ||
| 92 | 	int c, t; | ||
| 93 | 	char *s; | ||
| 94 | 	wchar_t *wcs; | ||
| 95 | 	void *dest=NULL; | ||
| 96 | 	int invert; | ||
| 97 | 	int matches=0; | ||
| 98 | 	off_t pos = 0, cnt; | ||
| 99 | 	static const char size_pfx[][3] = { "hh", "h", "", "l", "L", "ll" }; | ||
| 100 | 	char tmp[3*sizeof(int)+10]; | ||
| 101 | 	const wchar_t *set; | ||
| 102 | 	size_t i, k; | ||
| 103 | |||
| 104 | 	FLOCK(f); | ||
| 105 | |||
| 106 | 	fwide(f, 1); | ||
| 107 | |||
| 108 | 	for (p=fmt; *p; p++) { | ||
| 109 | |||
| 110 | 		alloc = 0; | ||
| 111 | |||
| 112 | 		if (iswspace(*p)) { | ||
| 113 | 			while (iswspace(p[1])) p++; | ||
| 114 | 			while (iswspace((c=getwc(f)))) pos++; | ||
| 115 | 			ungetwc(c, f); | ||
| 116 | 			continue; | ||
| 117 | 		} | ||
| 118 | 		if (*p != '%' || p[1] == '%') { | ||
| 119 | 			if (*p == '%') { | ||
| 120 | 				p++; | ||
| 121 | 				while (iswspace((c=getwc(f)))) pos++; | ||
| 122 | 			} else { | ||
| 123 | 				c = getwc(f); | ||
| 124 | 			} | ||
| 125 | 			if (c!=*p) { | ||
| 126 | 				ungetwc(c, f); | ||
| 127 | 				if (c<0) goto input_fail; | ||
| 128 | 				goto match_fail; | ||
| 129 | 			} | ||
| 130 | 			pos++; | ||
| 131 | 			continue; | ||
| 132 | 		} | ||
| 133 | |||
| 134 | 		p++; | ||
| 135 | 		if (*p=='*') { | ||
| 136 | 			dest = 0; p++; | ||
| 137 | 		} else if (iswdigit(*p) && p[1]=='$') { | ||
| 138 | 			dest = arg_n(ap, *p-'0'); p+=2; | ||
| 139 | 		} else { | ||
| 140 | 			dest = va_arg(ap, void *); | ||
| 141 | 		} | ||
| 142 | |||
| 143 | 		for (width=0; iswdigit(*p); p++) { | ||
| 144 | 			width = 10*width + *p - '0'; | ||
| 145 | 		} | ||
| 146 | |||
| 147 | 		if (*p=='m') { | ||
| 148 | 			wcs = 0; | ||
| 149 | 			s = 0; | ||
| 150 | 			alloc = !!dest; | ||
| 151 | 			p++; | ||
| 152 | 		} else { | ||
| 153 | 			alloc = 0; | ||
| 154 | 		} | ||
| 155 | |||
| 156 | 		size = SIZE_def; | ||
| 157 | 		switch (*p++) { | ||
| 158 | 		case 'h': | ||
| 159 | 			if (*p == 'h') p++, size = SIZE_hh; | ||
| 160 | 			else size = SIZE_h; | ||
| 161 | 			break; | ||
| 162 | 		case 'l': | ||
| 163 | 			if (*p == 'l') p++, size = SIZE_ll; | ||
| 164 | 			else size = SIZE_l; | ||
| 165 | 			break; | ||
| 166 | 		case 'j': | ||
| 167 | 			size = SIZE_ll; | ||
| 168 | 			break; | ||
| 169 | 		case 'z': | ||
| 170 | 		case 't': | ||
| 171 | 			size = SIZE_l; | ||
| 172 | 			break; | ||
| 173 | 		case 'L': | ||
| 174 | 			size = SIZE_L; | ||
| 175 | 			break; | ||
| 176 | 		case 'd': case 'i': case 'o': case 'u': case 'x': | ||
| 177 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 178 | 		case 'A': case 'E': case 'F': case 'G': case 'X': | ||
| 179 | 		case 's': case 'c': case '[': | ||
| 180 | 		case 'S': case 'C': | ||
| 181 | 		case 'p': case 'n': | ||
| 182 | 			p--; | ||
| 183 | 			break; | ||
| 184 | 		default: | ||
| 185 | 			goto fmt_fail; | ||
| 186 | 		} | ||
| 187 | |||
| 188 | 		t = *p; | ||
| 189 | |||
| 190 | 		/* Transform S,C -> ls,lc */ | ||
| 191 | 		if ((t&0x2f)==3) { | ||
| 192 | 			size = SIZE_l; | ||
| 193 | 			t |= 32; | ||
| 194 | 		} | ||
| 195 | |||
| 196 | 		if (t != 'n') { | ||
| 197 | 			if (t != '[' && (t|32) != 'c') | ||
| 198 | 				while (iswspace((c=getwc(f)))) pos++; | ||
| 199 | 			else | ||
| 200 | 				c=getwc(f); | ||
| 201 | 			if (c < 0) goto input_fail; | ||
| 202 | 			ungetwc(c, f); | ||
| 203 | 		} | ||
| 204 | |||
| 205 | 		switch (t) { | ||
| 206 | 		case 'n': | ||
| 207 | 			store_int(dest, size, pos); | ||
| 208 | 			/* do not increment match count, etc! */ | ||
| 209 | 			continue; | ||
| 210 | |||
| 211 | 		case 's': | ||
| 212 | 		case 'c': | ||
| 213 | 		case '[': | ||
| 214 | 			if (t == 'c') { | ||
| 215 | 				if (width<1) width = 1; | ||
| 216 | 				invert = 1; | ||
| 217 | 				set = L""; | ||
| 218 | 			} else if (t == 's') { | ||
| 219 | 				invert = 1; | ||
| 220 | 				static const wchar_t spaces[] = { | ||
| 221 | 					' ', '\t', '\n', '\r', 11, 12, 0x0085, | ||
| 222 | 					0x2000, 0x2001, 0x2002, 0x2003, 0x2004, 0x2005, | ||
| 223 | 					0x2006, 0x2008, 0x2009, 0x200a, | ||
| 224 | 					0x2028, 0x2029, 0x205f, 0x3000, 0 }; | ||
| 225 | 				set = spaces; | ||
| 226 | 			} else { | ||
| 227 | 				if (*++p == '^') p++, invert = 1; | ||
| 228 | 				else invert = 0; | ||
| 229 | 				set = p; | ||
| 230 | 				if (*p==']') p++; | ||
| 231 | 				while (*p!=']') { | ||
| 232 | 					if (!*p) goto fmt_fail; | ||
| 233 | 					p++; | ||
| 234 | 				} | ||
| 235 | 			} | ||
| 236 | |||
| 237 | 			s = (size == SIZE_def) ? dest : 0; | ||
| 238 | 			wcs = (size == SIZE_l) ? dest : 0; | ||
| 239 | |||
| 240 | 			int gotmatch = 0; | ||
| 241 | |||
| 242 | 			if (width < 1) width = -1; | ||
| 243 | |||
| 244 | 			i = 0; | ||
| 245 | 			if (alloc) { | ||
| 246 | 				k = t=='c' ? width+1U : 31; | ||
| 247 | 				if (size == SIZE_l) { | ||
| 248 | 					wcs = malloc(k*sizeof(wchar_t)); | ||
| 249 | 					if (!wcs) goto alloc_fail; | ||
| 250 | 				} else { | ||
| 251 | 					s = malloc(k); | ||
| 252 | 					if (!s) goto alloc_fail; | ||
| 253 | 				} | ||
| 254 | 			} | ||
| 255 | 			while (width) { | ||
| 256 | 				if ((c=getwc(f))<0) break; | ||
| 257 | 				if (in_set(set, c) == invert) | ||
| 258 | 					break; | ||
| 259 | 				if (wcs) { | ||
| 260 | 					wcs[i++] = c; | ||
| 261 | 					if (alloc && i==k) { | ||
| 262 | 						k += k+1; | ||
| 263 | 						wchar_t *tmp = realloc(wcs, k*sizeof(wchar_t)); | ||
| 264 | 						if (!tmp) goto alloc_fail; | ||
| 265 | 						wcs = tmp; | ||
| 266 | 					} | ||
| 267 | 				} else if (size != SIZE_l) { | ||
| 268 | 					int l = wctomb(s?s+i:tmp, c); | ||
| 269 | 					if (l<0) goto input_fail; | ||
| 270 | 					i += l; | ||
| 271 | 					if (alloc && i > k-4) { | ||
| 272 | 						k += k+1; | ||
| 273 | 						char *tmp = realloc(s, k); | ||
| 274 | 						if (!tmp) goto alloc_fail; | ||
| 275 | 						s = tmp; | ||
| 276 | 					} | ||
| 277 | 				} | ||
| 278 | 				pos++; | ||
| 279 | 				width-=(width>0); | ||
| 280 | 				gotmatch=1; | ||
| 281 | 			} | ||
| 282 | 			if (width) { | ||
| 283 | 				ungetwc(c, f); | ||
| 284 | 				if (t == 'c' || !gotmatch) goto match_fail; | ||
| 285 | 			} | ||
| 286 | |||
| 287 | 			if (alloc) { | ||
| 288 | 				if (size == SIZE_l) *(wchar_t **)dest = wcs; | ||
| 289 | 				else *(char **)dest = s; | ||
| 290 | 			} | ||
| 291 | 			if (t != 'c') { | ||
| 292 | 				if (wcs) wcs[i] = 0; | ||
| 293 | 				if (s) s[i] = 0; | ||
| 294 | 			} | ||
| 295 | 			break; | ||
| 296 | |||
| 297 | 		case 'd': case 'i': case 'o': case 'u': case 'x': | ||
| 298 | 		case 'a': case 'e': case 'f': case 'g': | ||
| 299 | 		case 'A': case 'E': case 'F': case 'G': case 'X': | ||
| 300 | 		case 'p': | ||
| 301 | 			if (width < 1) width = 0; | ||
| 302 | 			snprintf(tmp, sizeof tmp, "%.*s%.0d%s%c%%lln", | ||
| 303 | 				1+!dest, "%*", width, size_pfx[size+2], t); | ||
| 304 | 			cnt = 0; | ||
| 305 | 			if (fscanf(f, tmp, dest?dest:&cnt, &cnt) == -1) | ||
| 306 | 				goto input_fail; | ||
| 307 | 			else if (!cnt) | ||
| 308 | 				goto match_fail; | ||
| 309 | 			pos += cnt; | ||
| 310 | 			break; | ||
| 311 | 		default: | ||
| 312 | 			goto fmt_fail; | ||
| 313 | 		} | ||
| 314 | |||
| 315 | 		if (dest) matches++; | ||
| 316 | 	} | ||
| 317 | 	if (0) { | ||
| 318 | fmt_fail: | ||
| 319 | alloc_fail: | ||
| 320 | input_fail: | ||
| 321 | 		if (!matches) matches--; | ||
| 322 | match_fail: | ||
| 323 | 		if (alloc) { | ||
| 324 | 			free(s); | ||
| 325 | 			free(wcs); | ||
| 326 | 		} | ||
| 327 | 	} | ||
| 328 | 	FUNLOCK(f); | ||
| 329 | 	return matches; | ||
| 330 | } | ||
| 331 | |||
| 332 | weak_alias(vfwscanf,__isoc99_vfwscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vprintf.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | |||
| 3 | int vprintf(const char *restrict fmt, va_list ap) | ||
| 4 | { | ||
| 5 | 	return vfprintf(stdout, fmt, ap); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vscanf.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | |||
| 4 | int vscanf(const char *restrict fmt, va_list ap) | ||
| 5 | { | ||
| 6 | 	return vfscanf(stdin, fmt, ap); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(vscanf,__isoc99_vscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vsnprintf.c created+57| ... | @@ -0,0 +1,57 @@ | ||
| 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 | 	if (n > INT_MAX) { | ||
| 51 | 		errno = EOVERFLOW; | ||
| 52 | 		return -1; | ||
| 53 | 	} | ||
| 54 | |||
| 55 | 	*c.s = 0; | ||
| 56 | 	return vfprintf(&f, fmt, ap); | ||
| 57 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vsprintf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <limits.h> | ||
| 3 | |||
| 4 | int vsprintf(char *restrict s, const char *restrict fmt, va_list ap) | ||
| 5 | { | ||
| 6 | 	return vsnprintf(s, INT_MAX, fmt, ap); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vsscanf.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 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 created+62| ... | @@ -0,0 +1,62 @@ | ||
| 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 | 		s+=i; | ||
| 22 | 		l-=i; | ||
| 23 | 		c->l--; | ||
| 24 | 		c->ws++; | ||
| 25 | 	} | ||
| 26 | 	*c->ws = 0; | ||
| 27 | 	if (i < 0) { | ||
| 28 | 		f->wpos = f->wbase = f->wend = 0; | ||
| 29 | 		f->flags |= F_ERR; | ||
| 30 | 		return i; | ||
| 31 | 	} | ||
| 32 | 	f->wend = f->buf + f->buf_size; | ||
| 33 | 	f->wpos = f->wbase = f->buf; | ||
| 34 | 	return l0; | ||
| 35 | } | ||
| 36 | |||
| 37 | int vswprintf(wchar_t *restrict s, size_t n, const wchar_t *restrict fmt, va_list ap) | ||
| 38 | { | ||
| 39 | 	int r; | ||
| 40 | 	unsigned char buf[256]; | ||
| 41 | 	struct cookie c = { s, n-1 }; | ||
| 42 | 	FILE f = { | ||
| 43 | 		.lbf = EOF, | ||
| 44 | 		.write = sw_write, | ||
| 45 | #if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT) | ||
| 46 | 		.lock = -1, | ||
| 47 | #endif | ||
| 48 | 		.buf = buf, | ||
| 49 | 		.buf_size = sizeof buf, | ||
| 50 | 		.cookie = &c, | ||
| 51 | 	}; | ||
| 52 | |||
| 53 | 	if (!n) { | ||
| 54 | 		return -1; | ||
| 55 | 	} else if (n > INT_MAX) { | ||
| 56 | 		errno = EOVERFLOW; | ||
| 57 | 		return -1; | ||
| 58 | 	} | ||
| 59 | 	r = vfwprintf(&f, fmt, ap); | ||
| 60 | 	sw_write(&f, 0, 0); | ||
| 61 | 	return r>=n ? -1 : r; | ||
| 62 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vswscanf.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 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/stdio/vwprintf.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | int vwprintf(const wchar_t *restrict fmt, va_list ap) | ||
| 5 | { | ||
| 6 | 	return vfwprintf(stdout, fmt, ap); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/vwscanf.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int vwscanf(const wchar_t *restrict fmt, va_list ap) | ||
| 6 | { | ||
| 7 | 	return vfwscanf(stdin, fmt, ap); | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(vwscanf,__isoc99_vwscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/wprintf.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int wprintf(const wchar_t *restrict fmt, ...) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	va_list ap; | ||
| 9 | 	va_start(ap, fmt); | ||
| 10 | 	ret = vwprintf(fmt, ap); | ||
| 11 | 	va_end(ap); | ||
| 12 | 	return ret; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdio/wscanf.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdarg.h> | ||
| 3 | #include <wchar.h> | ||
| 4 | |||
| 5 | int wscanf(const wchar_t *restrict fmt, ...) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	va_list ap; | ||
| 9 | 	va_start(ap, fmt); | ||
| 10 | 	ret = vwscanf(fmt, ap); | ||
| 11 | 	va_end(ap); | ||
| 12 | 	return ret; | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(wscanf,__isoc99_wscanf); | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/abs.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | int abs(int a) | ||
| 4 | { | ||
| 5 | 	return a>0 ? a : -a; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/atof.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | double atof(const char *s) | ||
| 4 | { | ||
| 5 | 	return strtod(s, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/atoi.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | |||
| 4 | int atoi(const char *s) | ||
| 5 | { | ||
| 6 | 	int n=0, neg=0; | ||
| 7 | 	while (isspace(*s)) s++; | ||
| 8 | 	switch (*s) { | ||
| 9 | 	case '-': neg=1; | ||
| 10 | 	case '+': s++; | ||
| 11 | 	} | ||
| 12 | 	/* Compute n as a negative number to avoid overflow on INT_MIN */ | ||
| 13 | 	while (isdigit(*s)) | ||
| 14 | 		n = 10*n - (*s++ - '0'); | ||
| 15 | 	return neg ? n : -n; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/atol.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | |||
| 4 | long atol(const char *s) | ||
| 5 | { | ||
| 6 | 	long n=0; | ||
| 7 | 	int neg=0; | ||
| 8 | 	while (isspace(*s)) s++; | ||
| 9 | 	switch (*s) { | ||
| 10 | 	case '-': neg=1; | ||
| 11 | 	case '+': s++; | ||
| 12 | 	} | ||
| 13 | 	/* Compute n as a negative number to avoid overflow on LONG_MIN */ | ||
| 14 | 	while (isdigit(*s)) | ||
| 15 | 		n = 10*n - (*s++ - '0'); | ||
| 16 | 	return neg ? n : -n; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/atoll.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | |||
| 4 | long long atoll(const char *s) | ||
| 5 | { | ||
| 6 | 	long long n=0; | ||
| 7 | 	int neg=0; | ||
| 8 | 	while (isspace(*s)) s++; | ||
| 9 | 	switch (*s) { | ||
| 10 | 	case '-': neg=1; | ||
| 11 | 	case '+': s++; | ||
| 12 | 	} | ||
| 13 | 	/* Compute n as a negative number to avoid overflow on LLONG_MIN */ | ||
| 14 | 	while (isdigit(*s)) | ||
| 15 | 		n = 10*n - (*s++ - '0'); | ||
| 16 | 	return neg ? n : -n; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/bsearch.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | void *bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *)) | ||
| 4 | { | ||
| 5 | 	void *try; | ||
| 6 | 	int sign; | ||
| 7 | 	while (nel > 0) { | ||
| 8 | 		try = (char *)base + width*(nel/2); | ||
| 9 | 		sign = cmp(key, try); | ||
| 10 | 		if (sign < 0) { | ||
| 11 | 			nel /= 2; | ||
| 12 | 		} else if (sign > 0) { | ||
| 13 | 			base = (char *)try + width; | ||
| 14 | 			nel -= nel/2+1; | ||
| 15 | 		} else { | ||
| 16 | 			return try; | ||
| 17 | 		} | ||
| 18 | 	} | ||
| 19 | 	return NULL; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/div.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | div_t div(int num, int den) | ||
| 4 | { | ||
| 5 | 	return (div_t){ num/den, num%den }; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/ecvt.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | char *ecvt(double x, int n, int *dp, int *sign) | ||
| 6 | { | ||
| 7 | 	static char buf[16]; | ||
| 8 | 	char tmp[32]; | ||
| 9 | 	int i, j; | ||
| 10 | |||
| 11 | 	if (n-1U > 15) n = 15; | ||
| 12 | 	sprintf(tmp, "%.*e", n-1, x); | ||
| 13 | 	i = *sign = (tmp[0]=='-'); | ||
| 14 | 	for (j=0; tmp[i]!='e'; j+=(tmp[i++]!='.')) | ||
| 15 | 		buf[j] = tmp[i]; | ||
| 16 | 	buf[j] = 0; | ||
| 17 | 	*dp = atoi(tmp+i+1)+1; | ||
| 18 | |||
| 19 | 	return buf; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/fcvt.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | #include <string.h> | ||
| 5 | |||
| 6 | char *fcvt(double x, int n, int *dp, int *sign) | ||
| 7 | { | ||
| 8 | 	char tmp[1500]; | ||
| 9 | 	int i, lz; | ||
| 10 | |||
| 11 | 	if (n > 1400U) n = 1400; | ||
| 12 | 	sprintf(tmp, "%.*f", n, x); | ||
| 13 | 	i = (tmp[0] == '-'); | ||
| 14 | 	if (tmp[i] == '0') lz = strspn(tmp+i+2, "0"); | ||
| 15 | 	else lz = -(int)strcspn(tmp+i, "."); | ||
| 16 | |||
| 17 | 	if (n<=lz) { | ||
| 18 | 		*sign = i; | ||
| 19 | 		*dp = 1; | ||
| 20 | 		if (n>14U) n = 14; | ||
| 21 | 		return "000000000000000"+14-n; | ||
| 22 | 	} | ||
| 23 | |||
| 24 | 	return ecvt(x, n-lz, dp, sign); | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/gcvt.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <stdio.h> | ||
| 4 | |||
| 5 | char *gcvt(double x, int n, char *b) | ||
| 6 | { | ||
| 7 | 	sprintf(b, "%.*g", n, x); | ||
| 8 | 	return b; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/imaxabs.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <inttypes.h> | ||
| 2 | |||
| 3 | intmax_t imaxabs(intmax_t a) | ||
| 4 | { | ||
| 5 | 	return a>0 ? a : -a; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/imaxdiv.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <inttypes.h> | ||
| 2 | |||
| 3 | imaxdiv_t imaxdiv(intmax_t num, intmax_t den) | ||
| 4 | { | ||
| 5 | 	return (imaxdiv_t){ num/den, num%den }; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/labs.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | long labs(long a) | ||
| 4 | { | ||
| 5 | 	return a>0 ? a : -a; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/ldiv.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | ldiv_t ldiv(long num, long den) | ||
| 4 | { | ||
| 5 | 	return (ldiv_t){ num/den, num%den }; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/llabs.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | long long llabs(long long a) | ||
| 4 | { | ||
| 5 | 	return a>0 ? a : -a; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/lldiv.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | lldiv_t lldiv(long long num, long long den) | ||
| 4 | { | ||
| 5 | 	return (lldiv_t){ num/den, num%den }; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/qsort.c created+218| ... | @@ -0,0 +1,218 @@ | ||
| 1 | /* Copyright (C) 2011 by Valentin Ochs | ||
| 2 | * | ||
| 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| 4 | * of this software and associated documentation files (the "Software"), to | ||
| 5 | * deal in the Software without restriction, including without limitation the | ||
| 6 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| 7 | * sell copies of the Software, and to permit persons to whom the Software is | ||
| 8 | * furnished to do so, subject to the following conditions: | ||
| 9 | * | ||
| 10 | * The above copyright notice and this permission notice shall be included in | ||
| 11 | * all copies or substantial portions of the Software. | ||
| 12 | * | ||
| 13 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| 14 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| 15 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| 16 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| 17 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 18 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| 19 | * IN THE SOFTWARE. | ||
| 20 | */ | ||
| 21 | |||
| 22 | /* Minor changes by Rich Felker for integration in musl, 2011-04-27. */ | ||
| 23 | |||
| 24 | /* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1). | ||
| 25 | Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */ | ||
| 26 | |||
| 27 | #include <stdint.h> | ||
| 28 | #include <stdlib.h> | ||
| 29 | #include <string.h> | ||
| 30 | |||
| 31 | #include "atomic.h" | ||
| 32 | #define ntz(x) a_ctz_l((x)) | ||
| 33 | |||
| 34 | typedef int (*cmpfun)(const void *, const void *); | ||
| 35 | |||
| 36 | static inline int pntz(size_t p[2]) { | ||
| 37 | 	int r = ntz(p[0] - 1); | ||
| 38 | 	if(r != 0 || (r = 8*sizeof(size_t) + ntz(p[1])) != 8*sizeof(size_t)) { | ||
| 39 | 		return r; | ||
| 40 | 	} | ||
| 41 | 	return 0; | ||
| 42 | } | ||
| 43 | |||
| 44 | static void cycle(size_t width, unsigned char* ar[], int n) | ||
| 45 | { | ||
| 46 | 	unsigned char tmp[256]; | ||
| 47 | 	size_t l; | ||
| 48 | 	int i; | ||
| 49 | |||
| 50 | 	if(n < 2) { | ||
| 51 | 		return; | ||
| 52 | 	} | ||
| 53 | |||
| 54 | 	ar[n] = tmp; | ||
| 55 | 	while(width) { | ||
| 56 | 		l = sizeof(tmp) < width ? sizeof(tmp) : width; | ||
| 57 | 		memcpy(ar[n], ar[0], l); | ||
| 58 | 		for(i = 0; i < n; i++) { | ||
| 59 | 			memcpy(ar[i], ar[i + 1], l); | ||
| 60 | 			ar[i] += l; | ||
| 61 | 		} | ||
| 62 | 		width -= l; | ||
| 63 | 	} | ||
| 64 | } | ||
| 65 | |||
| 66 | /* shl() and shr() need n > 0 */ | ||
| 67 | static inline void shl(size_t p[2], int n) | ||
| 68 | { | ||
| 69 | 	if(n >= 8 * sizeof(size_t)) { | ||
| 70 | 		n -= 8 * sizeof(size_t); | ||
| 71 | 		p[1] = p[0]; | ||
| 72 | 		p[0] = 0; | ||
| 73 | 	} | ||
| 74 | 	p[1] <<= n; | ||
| 75 | 	p[1] |= p[0] >> (sizeof(size_t) * 8 - n); | ||
| 76 | 	p[0] <<= n; | ||
| 77 | } | ||
| 78 | |||
| 79 | static inline void shr(size_t p[2], int n) | ||
| 80 | { | ||
| 81 | 	if(n >= 8 * sizeof(size_t)) { | ||
| 82 | 		n -= 8 * sizeof(size_t); | ||
| 83 | 		p[0] = p[1]; | ||
| 84 | 		p[1] = 0; | ||
| 85 | 	} | ||
| 86 | 	p[0] >>= n; | ||
| 87 | 	p[0] |= p[1] << (sizeof(size_t) * 8 - n); | ||
| 88 | 	p[1] >>= n; | ||
| 89 | } | ||
| 90 | |||
| 91 | static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[]) | ||
| 92 | { | ||
| 93 | 	unsigned char *rt, *lf; | ||
| 94 | 	unsigned char *ar[14 * sizeof(size_t) + 1]; | ||
| 95 | 	int i = 1; | ||
| 96 | |||
| 97 | 	ar[0] = head; | ||
| 98 | 	while(pshift > 1) { | ||
| 99 | 		rt = head - width; | ||
| 100 | 		lf = head - width - lp[pshift - 2]; | ||
| 101 | |||
| 102 | 		if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) { | ||
| 103 | 			break; | ||
| 104 | 		} | ||
| 105 | 		if((*cmp)(lf, rt) >= 0) { | ||
| 106 | 			ar[i++] = lf; | ||
| 107 | 			head = lf; | ||
| 108 | 			pshift -= 1; | ||
| 109 | 		} else { | ||
| 110 | 			ar[i++] = rt; | ||
| 111 | 			head = rt; | ||
| 112 | 			pshift -= 2; | ||
| 113 | 		} | ||
| 114 | 	} | ||
| 115 | 	cycle(width, ar, i); | ||
| 116 | } | ||
| 117 | |||
| 118 | static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[]) | ||
| 119 | { | ||
| 120 | 	unsigned char *stepson, | ||
| 121 | 	 *rt, *lf; | ||
| 122 | 	size_t p[2]; | ||
| 123 | 	unsigned char *ar[14 * sizeof(size_t) + 1]; | ||
| 124 | 	int i = 1; | ||
| 125 | 	int trail; | ||
| 126 | |||
| 127 | 	p[0] = pp[0]; | ||
| 128 | 	p[1] = pp[1]; | ||
| 129 | |||
| 130 | 	ar[0] = head; | ||
| 131 | 	while(p[0] != 1 || p[1] != 0) { | ||
| 132 | 		stepson = head - lp[pshift]; | ||
| 133 | 		if((*cmp)(stepson, ar[0]) <= 0) { | ||
| 134 | 			break; | ||
| 135 | 		} | ||
| 136 | 		if(!trusty && pshift > 1) { | ||
| 137 | 			rt = head - width; | ||
| 138 | 			lf = head - width - lp[pshift - 2]; | ||
| 139 | 			if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) { | ||
| 140 | 				break; | ||
| 141 | 			} | ||
| 142 | 		} | ||
| 143 | |||
| 144 | 		ar[i++] = stepson; | ||
| 145 | 		head = stepson; | ||
| 146 | 		trail = pntz(p); | ||
| 147 | 		shr(p, trail); | ||
| 148 | 		pshift += trail; | ||
| 149 | 		trusty = 0; | ||
| 150 | 	} | ||
| 151 | 	if(!trusty) { | ||
| 152 | 		cycle(width, ar, i); | ||
| 153 | 		sift(head, width, cmp, pshift, lp); | ||
| 154 | 	} | ||
| 155 | } | ||
| 156 | |||
| 157 | void qsort(void *base, size_t nel, size_t width, cmpfun cmp) | ||
| 158 | { | ||
| 159 | 	size_t lp[12*sizeof(size_t)]; | ||
| 160 | 	size_t i, size = width * nel; | ||
| 161 | 	unsigned char *head, *high; | ||
| 162 | 	size_t p[2] = {1, 0}; | ||
| 163 | 	int pshift = 1; | ||
| 164 | 	int trail; | ||
| 165 | |||
| 166 | 	if (!size) return; | ||
| 167 | |||
| 168 | 	head = base; | ||
| 169 | 	high = head + size - width; | ||
| 170 | |||
| 171 | 	/* Precompute Leonardo numbers, scaled by element width */ | ||
| 172 | 	for(lp[0]=lp[1]=width, i=2; (lp[i]=lp[i-2]+lp[i-1]+width) < size; i++); | ||
| 173 | |||
| 174 | 	while(head < high) { | ||
| 175 | 		if((p[0] & 3) == 3) { | ||
| 176 | 			sift(head, width, cmp, pshift, lp); | ||
| 177 | 			shr(p, 2); | ||
| 178 | 			pshift += 2; | ||
| 179 | 		} else { | ||
| 180 | 			if(lp[pshift - 1] >= high - head) { | ||
| 181 | 				trinkle(head, width, cmp, p, pshift, 0, lp); | ||
| 182 | 			} else { | ||
| 183 | 				sift(head, width, cmp, pshift, lp); | ||
| 184 | 			} | ||
| 185 | 			 | ||
| 186 | 			if(pshift == 1) { | ||
| 187 | 				shl(p, 1); | ||
| 188 | 				pshift = 0; | ||
| 189 | 			} else { | ||
| 190 | 				shl(p, pshift - 1); | ||
| 191 | 				pshift = 1; | ||
| 192 | 			} | ||
| 193 | 		} | ||
| 194 | 		 | ||
| 195 | 		p[0] |= 1; | ||
| 196 | 		head += width; | ||
| 197 | 	} | ||
| 198 | |||
| 199 | 	trinkle(head, width, cmp, p, pshift, 0, lp); | ||
| 200 | |||
| 201 | 	while(pshift != 1 || p[0] != 1 || p[1] != 0) { | ||
| 202 | 		if(pshift <= 1) { | ||
| 203 | 			trail = pntz(p); | ||
| 204 | 			shr(p, trail); | ||
| 205 | 			pshift += trail; | ||
| 206 | 		} else { | ||
| 207 | 			shl(p, 2); | ||
| 208 | 			pshift -= 2; | ||
| 209 | 			p[0] ^= 7; | ||
| 210 | 			shr(p, 1); | ||
| 211 | 			trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp); | ||
| 212 | 			shl(p, 1); | ||
| 213 | 			p[0] |= 1; | ||
| 214 | 			trinkle(head - width, width, cmp, p, pshift, 1, lp); | ||
| 215 | 		} | ||
| 216 | 		head -= width; | ||
| 217 | 	} | ||
| 218 | } | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/strtod.c created+69| ... | @@ -0,0 +1,69 @@ | ||
| 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 | } | ||
| 49 | |||
| 50 | #ifdef __wasilibc_unmodified_upstream // WASI doesn't support signature-changing aliases | ||
| 51 | weak_alias(strtof, strtof_l); | ||
| 52 | weak_alias(strtod, strtod_l); | ||
| 53 | weak_alias(strtold, strtold_l); | ||
| 54 | weak_alias(strtof, __strtof_l); | ||
| 55 | weak_alias(strtod, __strtod_l); | ||
| 56 | weak_alias(strtold, __strtold_l); | ||
| 57 | #else | ||
| 58 | // WebAssembly doesn't permit signature-changing aliases, so use wrapper | ||
| 59 | // functions instead. | ||
| 60 | weak float strtof_l(const char *restrict s, char **restrict p, locale_t loc) { | ||
| 61 | 	return strtof(s, p); | ||
| 62 | } | ||
| 63 | weak double strtod_l(const char *restrict s, char **restrict p, locale_t loc) { | ||
| 64 | 	return strtod(s, p); | ||
| 65 | } | ||
| 66 | weak long double strtold_l(const char *restrict s, char **restrict p, locale_t loc) { | ||
| 67 | 	return strtold(s, p); | ||
| 68 | } | ||
| 69 | #endif | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/strtol.c created+56| ... | @@ -0,0 +1,56 @@ | ||
| 1 | #include "stdio_impl.h" | ||
| 2 | #include "intscan.h" | ||
| 3 | #include "shgetc.h" | ||
| 4 | #include <inttypes.h> | ||
| 5 | #include <limits.h> | ||
| 6 | #include <ctype.h> | ||
| 7 | |||
| 8 | static unsigned long long strtox(const char *s, char **p, int base, unsigned long long lim) | ||
| 9 | { | ||
| 10 | 	FILE f; | ||
| 11 | 	sh_fromstring(&f, s); | ||
| 12 | 	shlim(&f, 0); | ||
| 13 | 	unsigned long long y = __intscan(&f, base, 1, lim); | ||
| 14 | 	if (p) { | ||
| 15 | 		size_t cnt = shcnt(&f); | ||
| 16 | 		*p = (char *)s + cnt; | ||
| 17 | 	} | ||
| 18 | 	return y; | ||
| 19 | } | ||
| 20 | |||
| 21 | unsigned long long strtoull(const char *restrict s, char **restrict p, int base) | ||
| 22 | { | ||
| 23 | 	return strtox(s, p, base, ULLONG_MAX); | ||
| 24 | } | ||
| 25 | |||
| 26 | long long strtoll(const char *restrict s, char **restrict p, int base) | ||
| 27 | { | ||
| 28 | 	return strtox(s, p, base, LLONG_MIN); | ||
| 29 | } | ||
| 30 | |||
| 31 | unsigned long strtoul(const char *restrict s, char **restrict p, int base) | ||
| 32 | { | ||
| 33 | 	return strtox(s, p, base, ULONG_MAX); | ||
| 34 | } | ||
| 35 | |||
| 36 | long strtol(const char *restrict s, char **restrict p, int base) | ||
| 37 | { | ||
| 38 | 	return strtox(s, p, base, 0UL+LONG_MIN); | ||
| 39 | } | ||
| 40 | |||
| 41 | intmax_t strtoimax(const char *restrict s, char **restrict p, int base) | ||
| 42 | { | ||
| 43 | 	return strtoll(s, p, base); | ||
| 44 | } | ||
| 45 | |||
| 46 | uintmax_t strtoumax(const char *restrict s, char **restrict p, int base) | ||
| 47 | { | ||
| 48 | 	return strtoull(s, p, base); | ||
| 49 | } | ||
| 50 | |||
| 51 | weak_alias(strtol, __strtol_internal); | ||
| 52 | weak_alias(strtoul, __strtoul_internal); | ||
| 53 | weak_alias(strtoll, __strtoll_internal); | ||
| 54 | weak_alias(strtoull, __strtoull_internal); | ||
| 55 | weak_alias(strtoimax, __strtoimax_internal); | ||
| 56 | weak_alias(strtoumax, __strtoumax_internal); | ||
lib/libc/wasi/libc-top-half/musl/src/stdlib/wcstod.c created+82| ... | @@ -0,0 +1,82 @@ | ||
| 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 created+83| ... | @@ -0,0 +1,83 @@ | ||
| 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/string/aarch64/memcpy.S created+186| ... | @@ -0,0 +1,186 @@ | ||
| 1 | /* | ||
| 2 | * memcpy - copy memory area | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012-2020, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* Assumptions: | ||
| 9 | * | ||
| 10 | * ARMv8-a, AArch64, unaligned accesses. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #define dstin x0 | ||
| 15 | #define src x1 | ||
| 16 | #define count x2 | ||
| 17 | #define dst x3 | ||
| 18 | #define srcend x4 | ||
| 19 | #define dstend x5 | ||
| 20 | #define A_l x6 | ||
| 21 | #define A_lw w6 | ||
| 22 | #define A_h x7 | ||
| 23 | #define B_l x8 | ||
| 24 | #define B_lw w8 | ||
| 25 | #define B_h x9 | ||
| 26 | #define C_l x10 | ||
| 27 | #define C_lw w10 | ||
| 28 | #define C_h x11 | ||
| 29 | #define D_l x12 | ||
| 30 | #define D_h x13 | ||
| 31 | #define E_l x14 | ||
| 32 | #define E_h x15 | ||
| 33 | #define F_l x16 | ||
| 34 | #define F_h x17 | ||
| 35 | #define G_l count | ||
| 36 | #define G_h dst | ||
| 37 | #define H_l src | ||
| 38 | #define H_h srcend | ||
| 39 | #define tmp1 x14 | ||
| 40 | |||
| 41 | /* This implementation of memcpy uses unaligned accesses and branchless | ||
| 42 | sequences to keep the code small, simple and improve performance. | ||
| 43 | |||
| 44 | Copies are split into 3 main cases: small copies of up to 32 bytes, medium | ||
| 45 | copies of up to 128 bytes, and large copies. The overhead of the overlap | ||
| 46 | check is negligible since it is only required for large copies. | ||
| 47 | |||
| 48 | Large copies use a software pipelined loop processing 64 bytes per iteration. | ||
| 49 | The destination pointer is 16-byte aligned to minimize unaligned accesses. | ||
| 50 | The loop tail is handled by always copying 64 bytes from the end. | ||
| 51 | */ | ||
| 52 | |||
| 53 | .global memcpy | ||
| 54 | .type memcpy,%function | ||
| 55 | memcpy: | ||
| 56 | 	add srcend, src, count | ||
| 57 | 	add dstend, dstin, count | ||
| 58 | 	cmp count, 128 | ||
| 59 | 	b.hi .Lcopy_long | ||
| 60 | 	cmp count, 32 | ||
| 61 | 	b.hi .Lcopy32_128 | ||
| 62 | |||
| 63 | 	/* Small copies: 0..32 bytes. */ | ||
| 64 | 	cmp count, 16 | ||
| 65 | 	b.lo .Lcopy16 | ||
| 66 | 	ldp A_l, A_h, [src] | ||
| 67 | 	ldp D_l, D_h, [srcend, -16] | ||
| 68 | 	stp A_l, A_h, [dstin] | ||
| 69 | 	stp D_l, D_h, [dstend, -16] | ||
| 70 | 	ret | ||
| 71 | |||
| 72 | 	/* Copy 8-15 bytes. */ | ||
| 73 | .Lcopy16: | ||
| 74 | 	tbz count, 3, .Lcopy8 | ||
| 75 | 	ldr A_l, [src] | ||
| 76 | 	ldr A_h, [srcend, -8] | ||
| 77 | 	str A_l, [dstin] | ||
| 78 | 	str A_h, [dstend, -8] | ||
| 79 | 	ret | ||
| 80 | |||
| 81 | 	.p2align 3 | ||
| 82 | 	/* Copy 4-7 bytes. */ | ||
| 83 | .Lcopy8: | ||
| 84 | 	tbz count, 2, .Lcopy4 | ||
| 85 | 	ldr A_lw, [src] | ||
| 86 | 	ldr B_lw, [srcend, -4] | ||
| 87 | 	str A_lw, [dstin] | ||
| 88 | 	str B_lw, [dstend, -4] | ||
| 89 | 	ret | ||
| 90 | |||
| 91 | 	/* Copy 0..3 bytes using a branchless sequence. */ | ||
| 92 | .Lcopy4: | ||
| 93 | 	cbz count, .Lcopy0 | ||
| 94 | 	lsr tmp1, count, 1 | ||
| 95 | 	ldrb A_lw, [src] | ||
| 96 | 	ldrb C_lw, [srcend, -1] | ||
| 97 | 	ldrb B_lw, [src, tmp1] | ||
| 98 | 	strb A_lw, [dstin] | ||
| 99 | 	strb B_lw, [dstin, tmp1] | ||
| 100 | 	strb C_lw, [dstend, -1] | ||
| 101 | .Lcopy0: | ||
| 102 | 	ret | ||
| 103 | |||
| 104 | 	.p2align 4 | ||
| 105 | 	/* Medium copies: 33..128 bytes. */ | ||
| 106 | .Lcopy32_128: | ||
| 107 | 	ldp A_l, A_h, [src] | ||
| 108 | 	ldp B_l, B_h, [src, 16] | ||
| 109 | 	ldp C_l, C_h, [srcend, -32] | ||
| 110 | 	ldp D_l, D_h, [srcend, -16] | ||
| 111 | 	cmp count, 64 | ||
| 112 | 	b.hi .Lcopy128 | ||
| 113 | 	stp A_l, A_h, [dstin] | ||
| 114 | 	stp B_l, B_h, [dstin, 16] | ||
| 115 | 	stp C_l, C_h, [dstend, -32] | ||
| 116 | 	stp D_l, D_h, [dstend, -16] | ||
| 117 | 	ret | ||
| 118 | |||
| 119 | 	.p2align 4 | ||
| 120 | 	/* Copy 65..128 bytes. */ | ||
| 121 | .Lcopy128: | ||
| 122 | 	ldp E_l, E_h, [src, 32] | ||
| 123 | 	ldp F_l, F_h, [src, 48] | ||
| 124 | 	cmp count, 96 | ||
| 125 | 	b.ls .Lcopy96 | ||
| 126 | 	ldp G_l, G_h, [srcend, -64] | ||
| 127 | 	ldp H_l, H_h, [srcend, -48] | ||
| 128 | 	stp G_l, G_h, [dstend, -64] | ||
| 129 | 	stp H_l, H_h, [dstend, -48] | ||
| 130 | .Lcopy96: | ||
| 131 | 	stp A_l, A_h, [dstin] | ||
| 132 | 	stp B_l, B_h, [dstin, 16] | ||
| 133 | 	stp E_l, E_h, [dstin, 32] | ||
| 134 | 	stp F_l, F_h, [dstin, 48] | ||
| 135 | 	stp C_l, C_h, [dstend, -32] | ||
| 136 | 	stp D_l, D_h, [dstend, -16] | ||
| 137 | 	ret | ||
| 138 | |||
| 139 | 	.p2align 4 | ||
| 140 | 	/* Copy more than 128 bytes. */ | ||
| 141 | .Lcopy_long: | ||
| 142 | |||
| 143 | 	/* Copy 16 bytes and then align dst to 16-byte alignment. */ | ||
| 144 | |||
| 145 | 	ldp D_l, D_h, [src] | ||
| 146 | 	and tmp1, dstin, 15 | ||
| 147 | 	bic dst, dstin, 15 | ||
| 148 | 	sub src, src, tmp1 | ||
| 149 | 	add count, count, tmp1 /* Count is now 16 too large. */ | ||
| 150 | 	ldp A_l, A_h, [src, 16] | ||
| 151 | 	stp D_l, D_h, [dstin] | ||
| 152 | 	ldp B_l, B_h, [src, 32] | ||
| 153 | 	ldp C_l, C_h, [src, 48] | ||
| 154 | 	ldp D_l, D_h, [src, 64]! | ||
| 155 | 	subs count, count, 128 + 16 /* Test and readjust count. */ | ||
| 156 | 	b.ls .Lcopy64_from_end | ||
| 157 | |||
| 158 | .Lloop64: | ||
| 159 | 	stp A_l, A_h, [dst, 16] | ||
| 160 | 	ldp A_l, A_h, [src, 16] | ||
| 161 | 	stp B_l, B_h, [dst, 32] | ||
| 162 | 	ldp B_l, B_h, [src, 32] | ||
| 163 | 	stp C_l, C_h, [dst, 48] | ||
| 164 | 	ldp C_l, C_h, [src, 48] | ||
| 165 | 	stp D_l, D_h, [dst, 64]! | ||
| 166 | 	ldp D_l, D_h, [src, 64]! | ||
| 167 | 	subs count, count, 64 | ||
| 168 | 	b.hi .Lloop64 | ||
| 169 | |||
| 170 | 	/* Write the last iteration and copy 64 bytes from the end. */ | ||
| 171 | .Lcopy64_from_end: | ||
| 172 | 	ldp E_l, E_h, [srcend, -64] | ||
| 173 | 	stp A_l, A_h, [dst, 16] | ||
| 174 | 	ldp A_l, A_h, [srcend, -48] | ||
| 175 | 	stp B_l, B_h, [dst, 32] | ||
| 176 | 	ldp B_l, B_h, [srcend, -32] | ||
| 177 | 	stp C_l, C_h, [dst, 48] | ||
| 178 | 	ldp C_l, C_h, [srcend, -16] | ||
| 179 | 	stp D_l, D_h, [dst, 64] | ||
| 180 | 	stp E_l, E_h, [dstend, -64] | ||
| 181 | 	stp A_l, A_h, [dstend, -48] | ||
| 182 | 	stp B_l, B_h, [dstend, -32] | ||
| 183 | 	stp C_l, C_h, [dstend, -16] | ||
| 184 | 	ret | ||
| 185 | |||
| 186 | .size memcpy,.-memcpy | ||
lib/libc/wasi/libc-top-half/musl/src/string/aarch64/memset.S created+115| ... | @@ -0,0 +1,115 @@ | ||
| 1 | /* | ||
| 2 | * memset - fill memory with a constant byte | ||
| 3 | * | ||
| 4 | * Copyright (c) 2012-2020, Arm Limited. | ||
| 5 | * SPDX-License-Identifier: MIT | ||
| 6 | */ | ||
| 7 | |||
| 8 | /* Assumptions: | ||
| 9 | * | ||
| 10 | * ARMv8-a, AArch64, Advanced SIMD, unaligned accesses. | ||
| 11 | * | ||
| 12 | */ | ||
| 13 | |||
| 14 | #define dstin x0 | ||
| 15 | #define val x1 | ||
| 16 | #define valw w1 | ||
| 17 | #define count x2 | ||
| 18 | #define dst x3 | ||
| 19 | #define dstend x4 | ||
| 20 | #define zva_val x5 | ||
| 21 | |||
| 22 | .global memset | ||
| 23 | .type memset,%function | ||
| 24 | memset: | ||
| 25 | |||
| 26 | 	dup v0.16B, valw | ||
| 27 | 	add dstend, dstin, count | ||
| 28 | |||
| 29 | 	cmp count, 96 | ||
| 30 | 	b.hi .Lset_long | ||
| 31 | 	cmp count, 16 | ||
| 32 | 	b.hs .Lset_medium | ||
| 33 | 	mov val, v0.D[0] | ||
| 34 | |||
| 35 | 	/* Set 0..15 bytes. */ | ||
| 36 | 	tbz count, 3, 1f | ||
| 37 | 	str val, [dstin] | ||
| 38 | 	str val, [dstend, -8] | ||
| 39 | 	ret | ||
| 40 | 	nop | ||
| 41 | 1: tbz count, 2, 2f | ||
| 42 | 	str valw, [dstin] | ||
| 43 | 	str valw, [dstend, -4] | ||
| 44 | 	ret | ||
| 45 | 2: cbz count, 3f | ||
| 46 | 	strb valw, [dstin] | ||
| 47 | 	tbz count, 1, 3f | ||
| 48 | 	strh valw, [dstend, -2] | ||
| 49 | 3: ret | ||
| 50 | |||
| 51 | 	/* Set 17..96 bytes. */ | ||
| 52 | .Lset_medium: | ||
| 53 | 	str q0, [dstin] | ||
| 54 | 	tbnz count, 6, .Lset96 | ||
| 55 | 	str q0, [dstend, -16] | ||
| 56 | 	tbz count, 5, 1f | ||
| 57 | 	str q0, [dstin, 16] | ||
| 58 | 	str q0, [dstend, -32] | ||
| 59 | 1: ret | ||
| 60 | |||
| 61 | 	.p2align 4 | ||
| 62 | 	/* Set 64..96 bytes. Write 64 bytes from the start and | ||
| 63 | 	 32 bytes from the end. */ | ||
| 64 | .Lset96: | ||
| 65 | 	str q0, [dstin, 16] | ||
| 66 | 	stp q0, q0, [dstin, 32] | ||
| 67 | 	stp q0, q0, [dstend, -32] | ||
| 68 | 	ret | ||
| 69 | |||
| 70 | 	.p2align 4 | ||
| 71 | .Lset_long: | ||
| 72 | 	and valw, valw, 255 | ||
| 73 | 	bic dst, dstin, 15 | ||
| 74 | 	str q0, [dstin] | ||
| 75 | 	cmp count, 160 | ||
| 76 | 	ccmp valw, 0, 0, hs | ||
| 77 | 	b.ne .Lno_zva | ||
| 78 | |||
| 79 | #ifndef SKIP_ZVA_CHECK | ||
| 80 | 	mrs zva_val, dczid_el0 | ||
| 81 | 	and zva_val, zva_val, 31 | ||
| 82 | 	cmp zva_val, 4 /* ZVA size is 64 bytes. */ | ||
| 83 | 	b.ne .Lno_zva | ||
| 84 | #endif | ||
| 85 | 	str q0, [dst, 16] | ||
| 86 | 	stp q0, q0, [dst, 32] | ||
| 87 | 	bic dst, dst, 63 | ||
| 88 | 	sub count, dstend, dst /* Count is now 64 too large. */ | ||
| 89 | 	sub count, count, 128 /* Adjust count and bias for loop. */ | ||
| 90 | |||
| 91 | 	.p2align 4 | ||
| 92 | .Lzva_loop: | ||
| 93 | 	add dst, dst, 64 | ||
| 94 | 	dc zva, dst | ||
| 95 | 	subs count, count, 64 | ||
| 96 | 	b.hi .Lzva_loop | ||
| 97 | 	stp q0, q0, [dstend, -64] | ||
| 98 | 	stp q0, q0, [dstend, -32] | ||
| 99 | 	ret | ||
| 100 | |||
| 101 | .Lno_zva: | ||
| 102 | 	sub count, dstend, dst /* Count is 16 too large. */ | ||
| 103 | 	sub dst, dst, 16 /* Dst is biased by -32. */ | ||
| 104 | 	sub count, count, 64 + 16 /* Adjust count and bias for loop. */ | ||
| 105 | .Lno_zva_loop: | ||
| 106 | 	stp q0, q0, [dst, 32] | ||
| 107 | 	stp q0, q0, [dst, 64]! | ||
| 108 | 	subs count, count, 64 | ||
| 109 | 	b.hi .Lno_zva_loop | ||
| 110 | 	stp q0, q0, [dstend, -64] | ||
| 111 | 	stp q0, q0, [dstend, -32] | ||
| 112 | 	ret | ||
| 113 | |||
| 114 | .size memset,.-memset | ||
| 115 | |||
lib/libc/wasi/libc-top-half/musl/src/string/arm/__aeabi_memcpy.s created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | .syntax unified | ||
| 2 | |||
| 3 | .global __aeabi_memcpy8 | ||
| 4 | .global __aeabi_memcpy4 | ||
| 5 | .global __aeabi_memcpy | ||
| 6 | .global __aeabi_memmove8 | ||
| 7 | .global __aeabi_memmove4 | ||
| 8 | .global __aeabi_memmove | ||
| 9 | |||
| 10 | .type __aeabi_memcpy8,%function | ||
| 11 | .type __aeabi_memcpy4,%function | ||
| 12 | .type __aeabi_memcpy,%function | ||
| 13 | .type __aeabi_memmove8,%function | ||
| 14 | .type __aeabi_memmove4,%function | ||
| 15 | .type __aeabi_memmove,%function | ||
| 16 | |||
| 17 | __aeabi_memmove8: | ||
| 18 | __aeabi_memmove4: | ||
| 19 | __aeabi_memmove: | ||
| 20 | 	cmp r0, r1 | ||
| 21 | 	bls 3f | ||
| 22 | 	cmp r2, #0 | ||
| 23 | 	beq 2f | ||
| 24 | 	adds r0, r0, r2 | ||
| 25 | 	adds r2, r1, r2 | ||
| 26 | 1:	subs r2, r2, #1 | ||
| 27 | 	ldrb r3, [r2] | ||
| 28 | 	subs r0, r0, #1 | ||
| 29 | 	strb r3, [r0] | ||
| 30 | 	cmp r1, r2 | ||
| 31 | 	bne 1b | ||
| 32 | 2:	bx lr | ||
| 33 | __aeabi_memcpy8: | ||
| 34 | __aeabi_memcpy4: | ||
| 35 | __aeabi_memcpy: | ||
| 36 | 3:	cmp r2, #0 | ||
| 37 | 	beq 2f | ||
| 38 | 	adds r2, r1, r2 | ||
| 39 | 1:	ldrb r3, [r1] | ||
| 40 | 	adds r1, r1, #1 | ||
| 41 | 	strb r3, [r0] | ||
| 42 | 	adds r0, r0, #1 | ||
| 43 | 	cmp r1, r2 | ||
| 44 | 	bne 1b | ||
| 45 | 2:	bx lr | ||
lib/libc/wasi/libc-top-half/musl/src/string/arm/__aeabi_memset.s created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | .syntax unified | ||
| 2 | |||
| 3 | .global __aeabi_memclr8 | ||
| 4 | .global __aeabi_memclr4 | ||
| 5 | .global __aeabi_memclr | ||
| 6 | .global __aeabi_memset8 | ||
| 7 | .global __aeabi_memset4 | ||
| 8 | .global __aeabi_memset | ||
| 9 | |||
| 10 | .type __aeabi_memclr8,%function | ||
| 11 | .type __aeabi_memclr4,%function | ||
| 12 | .type __aeabi_memclr,%function | ||
| 13 | .type __aeabi_memset8,%function | ||
| 14 | .type __aeabi_memset4,%function | ||
| 15 | .type __aeabi_memset,%function | ||
| 16 | |||
| 17 | __aeabi_memclr8: | ||
| 18 | __aeabi_memclr4: | ||
| 19 | __aeabi_memclr: | ||
| 20 | 	movs r2, #0 | ||
| 21 | __aeabi_memset8: | ||
| 22 | __aeabi_memset4: | ||
| 23 | __aeabi_memset: | ||
| 24 | 	cmp r1, #0 | ||
| 25 | 	beq 2f | ||
| 26 | 	adds r1, r0, r1 | ||
| 27 | 1:	strb r2, [r0] | ||
| 28 | 	adds r0, r0, #1 | ||
| 29 | 	cmp r1, r0 | ||
| 30 | 	bne 1b | ||
| 31 | 2:	bx lr | ||
lib/libc/wasi/libc-top-half/musl/src/string/arm/memcpy.S created+479| ... | @@ -0,0 +1,479 @@ | ||
| 1 | /* | ||
| 2 | * Copyright (C) 2008 The Android Open Source Project | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions | ||
| 7 | * are met: | ||
| 8 | * * Redistributions of source code must retain the above copyright | ||
| 9 | * notice, this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright | ||
| 11 | * notice, this list of conditions and the following disclaimer in | ||
| 12 | * the documentation and/or other materials provided with the | ||
| 13 | * distribution. | ||
| 14 | * | ||
| 15 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
| 16 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
| 17 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
| 18 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
| 19 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
| 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
| 22 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
| 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
| 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
| 25 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
| 26 | * SUCH DAMAGE. | ||
| 27 | */ | ||
| 28 | |||
| 29 | |||
| 30 | /* | ||
| 31 | * Optimized memcpy() for ARM. | ||
| 32 | * | ||
| 33 | * note that memcpy() always returns the destination pointer, | ||
| 34 | * so we have to preserve R0. | ||
| 35 | */ | ||
| 36 | |||
| 37 | /* | ||
| 38 | * This file has been modified from the original for use in musl libc. | ||
| 39 | * The main changes are: addition of .type memcpy,%function to make the | ||
| 40 | * code safely callable from thumb mode, adjusting the return | ||
| 41 | * instructions to be compatible with pre-thumb ARM cpus, removal of | ||
| 42 | * prefetch code that is not compatible with older cpus and support for | ||
| 43 | * building as thumb 2 and big-endian. | ||
| 44 | */ | ||
| 45 | |||
| 46 | .syntax unified | ||
| 47 | |||
| 48 | .global memcpy | ||
| 49 | .type memcpy,%function | ||
| 50 | memcpy: | ||
| 51 | 	/* The stack must always be 64-bits aligned to be compliant with the | ||
| 52 | 	 * ARM ABI. Since we have to save R0, we might as well save R4 | ||
| 53 | 	 * which we can use for better pipelining of the reads below | ||
| 54 | 	 */ | ||
| 55 | 	.fnstart | ||
| 56 | 	.save {r0, r4, lr} | ||
| 57 | 	stmfd sp!, {r0, r4, lr} | ||
| 58 | 	/* Making room for r5-r11 which will be spilled later */ | ||
| 59 | 	.pad #28 | ||
| 60 | 	sub sp, sp, #28 | ||
| 61 | |||
| 62 | 	/* it simplifies things to take care of len<4 early */ | ||
| 63 | 	cmp r2, #4 | ||
| 64 | 	blo copy_last_3_and_return | ||
| 65 | |||
| 66 | 	/* compute the offset to align the source | ||
| 67 | 	 * offset = (4-(src&3))&3 = -src & 3 | ||
| 68 | 	 */ | ||
| 69 | 	rsb r3, r1, #0 | ||
| 70 | 	ands r3, r3, #3 | ||
| 71 | 	beq src_aligned | ||
| 72 | |||
| 73 | 	/* align source to 32 bits. We need to insert 2 instructions between | ||
| 74 | 	 * a ldr[b|h] and str[b|h] because byte and half-word instructions | ||
| 75 | 	 * stall 2 cycles. | ||
| 76 | 	 */ | ||
| 77 | 	movs r12, r3, lsl #31 | ||
| 78 | 	sub r2, r2, r3 /* we know that r3 <= r2 because r2 >= 4 */ | ||
| 79 | 	ldrbmi r3, [r1], #1 | ||
| 80 | 	ldrbcs r4, [r1], #1 | ||
| 81 | 	ldrbcs r12,[r1], #1 | ||
| 82 | 	strbmi r3, [r0], #1 | ||
| 83 | 	strbcs r4, [r0], #1 | ||
| 84 | 	strbcs r12,[r0], #1 | ||
| 85 | |||
| 86 | src_aligned: | ||
| 87 | |||
| 88 | 	/* see if src and dst are aligned together (congruent) */ | ||
| 89 | 	eor r12, r0, r1 | ||
| 90 | 	tst r12, #3 | ||
| 91 | 	bne non_congruent | ||
| 92 | |||
| 93 | 	/* Use post-incriment mode for stm to spill r5-r11 to reserved stack | ||
| 94 | 	 * frame. Don't update sp. | ||
| 95 | 	 */ | ||
| 96 | 	stmea sp, {r5-r11} | ||
| 97 | |||
| 98 | 	/* align the destination to a cache-line */ | ||
| 99 | 	rsb r3, r0, #0 | ||
| 100 | 	ands r3, r3, #0x1C | ||
| 101 | 	beq congruent_aligned32 | ||
| 102 | 	cmp r3, r2 | ||
| 103 | 	andhi r3, r2, #0x1C | ||
| 104 | |||
| 105 | 	/* conditionnaly copies 0 to 7 words (length in r3) */ | ||
| 106 | 	movs r12, r3, lsl #28 | ||
| 107 | 	ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */ | ||
| 108 | 	ldmmi r1!, {r8, r9} /* 8 bytes */ | ||
| 109 | 	stmcs r0!, {r4, r5, r6, r7} | ||
| 110 | 	stmmi r0!, {r8, r9} | ||
| 111 | 	tst r3, #0x4 | ||
| 112 | 	ldrne r10,[r1], #4 /* 4 bytes */ | ||
| 113 | 	strne r10,[r0], #4 | ||
| 114 | 	sub r2, r2, r3 | ||
| 115 | |||
| 116 | congruent_aligned32: | ||
| 117 | 	/* | ||
| 118 | 	 * here source is aligned to 32 bytes. | ||
| 119 | 	 */ | ||
| 120 | |||
| 121 | cached_aligned32: | ||
| 122 | 	subs r2, r2, #32 | ||
| 123 | 	blo less_than_32_left | ||
| 124 | |||
| 125 | 	/* | ||
| 126 | 	 * We preload a cache-line up to 64 bytes ahead. On the 926, this will | ||
| 127 | 	 * stall only until the requested world is fetched, but the linefill | ||
| 128 | 	 * continues in the the background. | ||
| 129 | 	 * While the linefill is going, we write our previous cache-line | ||
| 130 | 	 * into the write-buffer (which should have some free space). | ||
| 131 | 	 * When the linefill is done, the writebuffer will | ||
| 132 | 	 * start dumping its content into memory | ||
| 133 | 	 * | ||
| 134 | 	 * While all this is going, we then load a full cache line into | ||
| 135 | 	 * 8 registers, this cache line should be in the cache by now | ||
| 136 | 	 * (or partly in the cache). | ||
| 137 | 	 * | ||
| 138 | 	 * This code should work well regardless of the source/dest alignment. | ||
| 139 | 	 * | ||
| 140 | 	 */ | ||
| 141 | |||
| 142 | 	/* Align the preload register to a cache-line because the cpu does | ||
| 143 | 	 * "critical word first" (the first word requested is loaded first). | ||
| 144 | 	 */ | ||
| 145 | 	@ bic r12, r1, #0x1F | ||
| 146 | 	@ add r12, r12, #64 | ||
| 147 | |||
| 148 | 1: ldmia r1!, { r4-r11 } | ||
| 149 | 	subs r2, r2, #32 | ||
| 150 | |||
| 151 | 	/* | ||
| 152 | 	 * NOTE: if r12 is more than 64 ahead of r1, the following ldrhi | ||
| 153 | 	 * for ARM9 preload will not be safely guarded by the preceding subs. | ||
| 154 | 	 * When it is safely guarded the only possibility to have SIGSEGV here | ||
| 155 | 	 * is because the caller overstates the length. | ||
| 156 | 	 */ | ||
| 157 | 	@ ldrhi r3, [r12], #32 /* cheap ARM9 preload */ | ||
| 158 | 	stmia r0!, { r4-r11 } | ||
| 159 | 	bhs 1b | ||
| 160 | |||
| 161 | 	add r2, r2, #32 | ||
| 162 | |||
| 163 | less_than_32_left: | ||
| 164 | 	/* | ||
| 165 | 	 * less than 32 bytes left at this point (length in r2) | ||
| 166 | 	 */ | ||
| 167 | |||
| 168 | 	/* skip all this if there is nothing to do, which should | ||
| 169 | 	 * be a common case (if not executed the code below takes | ||
| 170 | 	 * about 16 cycles) | ||
| 171 | 	 */ | ||
| 172 | 	tst r2, #0x1F | ||
| 173 | 	beq 1f | ||
| 174 | |||
| 175 | 	/* conditionnaly copies 0 to 31 bytes */ | ||
| 176 | 	movs r12, r2, lsl #28 | ||
| 177 | 	ldmcs r1!, {r4, r5, r6, r7} /* 16 bytes */ | ||
| 178 | 	ldmmi r1!, {r8, r9} /* 8 bytes */ | ||
| 179 | 	stmcs r0!, {r4, r5, r6, r7} | ||
| 180 | 	stmmi r0!, {r8, r9} | ||
| 181 | 	movs r12, r2, lsl #30 | ||
| 182 | 	ldrcs r3, [r1], #4 /* 4 bytes */ | ||
| 183 | 	ldrhmi r4, [r1], #2 /* 2 bytes */ | ||
| 184 | 	strcs r3, [r0], #4 | ||
| 185 | 	strhmi r4, [r0], #2 | ||
| 186 | 	tst r2, #0x1 | ||
| 187 | 	ldrbne r3, [r1] /* last byte */ | ||
| 188 | 	strbne r3, [r0] | ||
| 189 | |||
| 190 | 	/* we're done! restore everything and return */ | ||
| 191 | 1: ldmfd sp!, {r5-r11} | ||
| 192 | 	ldmfd sp!, {r0, r4, lr} | ||
| 193 | 	bx lr | ||
| 194 | |||
| 195 | 	/********************************************************************/ | ||
| 196 | |||
| 197 | non_congruent: | ||
| 198 | 	/* | ||
| 199 | 	 * here source is aligned to 4 bytes | ||
| 200 | 	 * but destination is not. | ||
| 201 | 	 * | ||
| 202 | 	 * in the code below r2 is the number of bytes read | ||
| 203 | 	 * (the number of bytes written is always smaller, because we have | ||
| 204 | 	 * partial words in the shift queue) | ||
| 205 | 	 */ | ||
| 206 | 	cmp r2, #4 | ||
| 207 | 	blo copy_last_3_and_return | ||
| 208 | |||
| 209 | 	/* Use post-incriment mode for stm to spill r5-r11 to reserved stack | ||
| 210 | 	 * frame. Don't update sp. | ||
| 211 | 	 */ | ||
| 212 | 	stmea sp, {r5-r11} | ||
| 213 | |||
| 214 | 	/* compute shifts needed to align src to dest */ | ||
| 215 | 	rsb r5, r0, #0 | ||
| 216 | 	and r5, r5, #3 /* r5 = # bytes in partial words */ | ||
| 217 | 	mov r12, r5, lsl #3 /* r12 = right */ | ||
| 218 | 	rsb lr, r12, #32 /* lr = left */ | ||
| 219 | |||
| 220 | 	/* read the first word */ | ||
| 221 | 	ldr r3, [r1], #4 | ||
| 222 | 	sub r2, r2, #4 | ||
| 223 | |||
| 224 | 	/* write a partial word (0 to 3 bytes), such that destination | ||
| 225 | 	 * becomes aligned to 32 bits (r5 = nb of words to copy for alignment) | ||
| 226 | 	 */ | ||
| 227 | 	movs r5, r5, lsl #31 | ||
| 228 | |||
| 229 | #if __ARMEB__ | ||
| 230 | 	movmi r3, r3, ror #24 | ||
| 231 | 	strbmi	r3, [r0], #1 | ||
| 232 | 	movcs r3, r3, ror #24 | ||
| 233 | 	strbcs	r3, [r0], #1 | ||
| 234 | 	movcs r3, r3, ror #24 | ||
| 235 | 	strbcs	r3, [r0], #1 | ||
| 236 | #else | ||
| 237 | 	strbmi r3, [r0], #1 | ||
| 238 | 	movmi r3, r3, lsr #8 | ||
| 239 | 	strbcs r3, [r0], #1 | ||
| 240 | 	movcs r3, r3, lsr #8 | ||
| 241 | 	strbcs r3, [r0], #1 | ||
| 242 | 	movcs r3, r3, lsr #8 | ||
| 243 | #endif | ||
| 244 | |||
| 245 | 	cmp r2, #4 | ||
| 246 | 	blo partial_word_tail | ||
| 247 | |||
| 248 | #if __ARMEB__ | ||
| 249 | 	mov	r3, r3, lsr r12 | ||
| 250 | 	mov	r3, r3, lsl r12 | ||
| 251 | #endif | ||
| 252 | |||
| 253 | 	/* Align destination to 32 bytes (cache line boundary) */ | ||
| 254 | 1: tst r0, #0x1c | ||
| 255 | 	beq 2f | ||
| 256 | 	ldr r5, [r1], #4 | ||
| 257 | 	sub r2, r2, #4 | ||
| 258 | #if __ARMEB__ | ||
| 259 | 	mov r4, r5, lsr lr | ||
| 260 | 	orr r4, r4, r3 | ||
| 261 | 	mov r3, r5, lsl r12 | ||
| 262 | #else | ||
| 263 | 	mov r4, r5, lsl lr | ||
| 264 | 	orr r4, r4, r3 | ||
| 265 | 	mov r3, r5, lsr r12 | ||
| 266 | #endif | ||
| 267 | 	str r4, [r0], #4 | ||
| 268 | 	cmp r2, #4 | ||
| 269 | 	bhs 1b | ||
| 270 | 	blo partial_word_tail | ||
| 271 | |||
| 272 | 	/* copy 32 bytes at a time */ | ||
| 273 | 2: subs r2, r2, #32 | ||
| 274 | 	blo less_than_thirtytwo | ||
| 275 | |||
| 276 | 	/* Use immediate mode for the shifts, because there is an extra cycle | ||
| 277 | 	 * for register shifts, which could account for up to 50% of | ||
| 278 | 	 * performance hit. | ||
| 279 | 	 */ | ||
| 280 | |||
| 281 | 	cmp r12, #24 | ||
| 282 | 	beq loop24 | ||
| 283 | 	cmp r12, #8 | ||
| 284 | 	beq loop8 | ||
| 285 | |||
| 286 | loop16: | ||
| 287 | 	ldr r12, [r1], #4 | ||
| 288 | 1: mov r4, r12 | ||
| 289 | 	ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} | ||
| 290 | 	subs r2, r2, #32 | ||
| 291 | 	ldrhs r12, [r1], #4 | ||
| 292 | #if __ARMEB__ | ||
| 293 | 	orr r3, r3, r4, lsr #16 | ||
| 294 | 	mov r4, r4, lsl #16 | ||
| 295 | 	orr r4, r4, r5, lsr #16 | ||
| 296 | 	mov r5, r5, lsl #16 | ||
| 297 | 	orr r5, r5, r6, lsr #16 | ||
| 298 | 	mov r6, r6, lsl #16 | ||
| 299 | 	orr r6, r6, r7, lsr #16 | ||
| 300 | 	mov r7, r7, lsl #16 | ||
| 301 | 	orr r7, r7, r8, lsr #16 | ||
| 302 | 	mov r8, r8, lsl #16 | ||
| 303 | 	orr r8, r8, r9, lsr #16 | ||
| 304 | 	mov r9, r9, lsl #16 | ||
| 305 | 	orr r9, r9, r10, lsr #16 | ||
| 306 | 	mov r10, r10, lsl #16 | ||
| 307 | 	orr r10, r10, r11, lsr #16 | ||
| 308 | 	stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} | ||
| 309 | 	mov r3, r11, lsl #16 | ||
| 310 | #else | ||
| 311 | 	orr r3, r3, r4, lsl #16 | ||
| 312 | 	mov r4, r4, lsr #16 | ||
| 313 | 	orr r4, r4, r5, lsl #16 | ||
| 314 | 	mov r5, r5, lsr #16 | ||
| 315 | 	orr r5, r5, r6, lsl #16 | ||
| 316 | 	mov r6, r6, lsr #16 | ||
| 317 | 	orr r6, r6, r7, lsl #16 | ||
| 318 | 	mov r7, r7, lsr #16 | ||
| 319 | 	orr r7, r7, r8, lsl #16 | ||
| 320 | 	mov r8, r8, lsr #16 | ||
| 321 | 	orr r8, r8, r9, lsl #16 | ||
| 322 | 	mov r9, r9, lsr #16 | ||
| 323 | 	orr r9, r9, r10, lsl #16 | ||
| 324 | 	mov r10, r10, lsr #16 | ||
| 325 | 	orr r10, r10, r11, lsl #16 | ||
| 326 | 	stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} | ||
| 327 | 	mov r3, r11, lsr #16 | ||
| 328 | #endif | ||
| 329 | 	bhs 1b | ||
| 330 | 	b less_than_thirtytwo | ||
| 331 | |||
| 332 | loop8: | ||
| 333 | 	ldr r12, [r1], #4 | ||
| 334 | 1: mov r4, r12 | ||
| 335 | 	ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} | ||
| 336 | 	subs r2, r2, #32 | ||
| 337 | 	ldrhs r12, [r1], #4 | ||
| 338 | #if __ARMEB__ | ||
| 339 | 	orr r3, r3, r4, lsr #24 | ||
| 340 | 	mov r4, r4, lsl #8 | ||
| 341 | 	orr r4, r4, r5, lsr #24 | ||
| 342 | 	mov r5, r5, lsl #8 | ||
| 343 | 	orr r5, r5, r6, lsr #24 | ||
| 344 | 	mov r6, r6, lsl #8 | ||
| 345 | 	orr r6, r6, r7, lsr #24 | ||
| 346 | 	mov r7, r7, lsl #8 | ||
| 347 | 	orr r7, r7, r8, lsr #24 | ||
| 348 | 	mov r8, r8, lsl #8 | ||
| 349 | 	orr r8, r8, r9, lsr #24 | ||
| 350 | 	mov r9, r9, lsl #8 | ||
| 351 | 	orr r9, r9, r10, lsr #24 | ||
| 352 | 	mov r10, r10, lsl #8 | ||
| 353 | 	orr r10, r10, r11, lsr #24 | ||
| 354 | 	stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} | ||
| 355 | 	mov r3, r11, lsl #8 | ||
| 356 | #else | ||
| 357 | 	orr r3, r3, r4, lsl #24 | ||
| 358 | 	mov r4, r4, lsr #8 | ||
| 359 | 	orr r4, r4, r5, lsl #24 | ||
| 360 | 	mov r5, r5, lsr #8 | ||
| 361 | 	orr r5, r5, r6, lsl #24 | ||
| 362 | 	mov r6, r6, lsr #8 | ||
| 363 | 	orr r6, r6, r7, lsl #24 | ||
| 364 | 	mov r7, r7, lsr #8 | ||
| 365 | 	orr r7, r7, r8, lsl #24 | ||
| 366 | 	mov r8, r8, lsr #8 | ||
| 367 | 	orr r8, r8, r9, lsl #24 | ||
| 368 | 	mov r9, r9, lsr #8 | ||
| 369 | 	orr r9, r9, r10, lsl #24 | ||
| 370 | 	mov r10, r10, lsr #8 | ||
| 371 | 	orr r10, r10, r11, lsl #24 | ||
| 372 | 	stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} | ||
| 373 | 	mov r3, r11, lsr #8 | ||
| 374 | #endif | ||
| 375 | 	bhs 1b | ||
| 376 | 	b less_than_thirtytwo | ||
| 377 | |||
| 378 | loop24: | ||
| 379 | 	ldr r12, [r1], #4 | ||
| 380 | 1: mov r4, r12 | ||
| 381 | 	ldmia r1!, { r5,r6,r7, r8,r9,r10,r11} | ||
| 382 | 	subs r2, r2, #32 | ||
| 383 | 	ldrhs r12, [r1], #4 | ||
| 384 | #if __ARMEB__ | ||
| 385 | 	orr r3, r3, r4, lsr #8 | ||
| 386 | 	mov r4, r4, lsl #24 | ||
| 387 | 	orr r4, r4, r5, lsr #8 | ||
| 388 | 	mov r5, r5, lsl #24 | ||
| 389 | 	orr r5, r5, r6, lsr #8 | ||
| 390 | 	mov r6, r6, lsl #24 | ||
| 391 | 	orr r6, r6, r7, lsr #8 | ||
| 392 | 	mov r7, r7, lsl #24 | ||
| 393 | 	orr r7, r7, r8, lsr #8 | ||
| 394 | 	mov r8, r8, lsl #24 | ||
| 395 | 	orr r8, r8, r9, lsr #8 | ||
| 396 | 	mov r9, r9, lsl #24 | ||
| 397 | 	orr r9, r9, r10, lsr #8 | ||
| 398 | 	mov r10, r10, lsl #24 | ||
| 399 | 	orr r10, r10, r11, lsr #8 | ||
| 400 | 	stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} | ||
| 401 | 	mov r3, r11, lsl #24 | ||
| 402 | #else | ||
| 403 | 	orr r3, r3, r4, lsl #8 | ||
| 404 | 	mov r4, r4, lsr #24 | ||
| 405 | 	orr r4, r4, r5, lsl #8 | ||
| 406 | 	mov r5, r5, lsr #24 | ||
| 407 | 	orr r5, r5, r6, lsl #8 | ||
| 408 | 	mov r6, r6, lsr #24 | ||
| 409 | 	orr r6, r6, r7, lsl #8 | ||
| 410 | 	mov r7, r7, lsr #24 | ||
| 411 | 	orr r7, r7, r8, lsl #8 | ||
| 412 | 	mov r8, r8, lsr #24 | ||
| 413 | 	orr r8, r8, r9, lsl #8 | ||
| 414 | 	mov r9, r9, lsr #24 | ||
| 415 | 	orr r9, r9, r10, lsl #8 | ||
| 416 | 	mov r10, r10, lsr #24 | ||
| 417 | 	orr r10, r10, r11, lsl #8 | ||
| 418 | 	stmia r0!, {r3,r4,r5,r6, r7,r8,r9,r10} | ||
| 419 | 	mov r3, r11, lsr #24 | ||
| 420 | #endif | ||
| 421 | 	bhs 1b | ||
| 422 | |||
| 423 | less_than_thirtytwo: | ||
| 424 | 	/* copy the last 0 to 31 bytes of the source */ | ||
| 425 | 	rsb r12, lr, #32 /* we corrupted r12, recompute it */ | ||
| 426 | 	add r2, r2, #32 | ||
| 427 | 	cmp r2, #4 | ||
| 428 | 	blo partial_word_tail | ||
| 429 | |||
| 430 | 1: ldr r5, [r1], #4 | ||
| 431 | 	sub r2, r2, #4 | ||
| 432 | #if __ARMEB__ | ||
| 433 | 	mov r4, r5, lsr lr | ||
| 434 | 	orr r4, r4, r3 | ||
| 435 | 	mov r3, r5, lsl r12 | ||
| 436 | #else | ||
| 437 | 	mov r4, r5, lsl lr | ||
| 438 | 	orr r4, r4, r3 | ||
| 439 | 	mov r3, r5, lsr r12 | ||
| 440 | #endif | ||
| 441 | 	str r4, [r0], #4 | ||
| 442 | 	cmp r2, #4 | ||
| 443 | 	bhs 1b | ||
| 444 | |||
| 445 | partial_word_tail: | ||
| 446 | 	/* we have a partial word in the input buffer */ | ||
| 447 | 	movs r5, lr, lsl #(31-3) | ||
| 448 | #if __ARMEB__ | ||
| 449 | 	movmi r3, r3, ror #24 | ||
| 450 | 	strbmi r3, [r0], #1 | ||
| 451 | 	movcs r3, r3, ror #24 | ||
| 452 | 	strbcs r3, [r0], #1 | ||
| 453 | 	movcs r3, r3, ror #24 | ||
| 454 | 	strbcs r3, [r0], #1 | ||
| 455 | #else | ||
| 456 | 	strbmi r3, [r0], #1 | ||
| 457 | 	movmi r3, r3, lsr #8 | ||
| 458 | 	strbcs r3, [r0], #1 | ||
| 459 | 	movcs r3, r3, lsr #8 | ||
| 460 | 	strbcs r3, [r0], #1 | ||
| 461 | #endif | ||
| 462 | |||
| 463 | 	/* Refill spilled registers from the stack. Don't update sp. */ | ||
| 464 | 	ldmfd sp, {r5-r11} | ||
| 465 | |||
| 466 | copy_last_3_and_return: | ||
| 467 | 	movs r2, r2, lsl #31 /* copy remaining 0, 1, 2 or 3 bytes */ | ||
| 468 | 	ldrbmi r2, [r1], #1 | ||
| 469 | 	ldrbcs r3, [r1], #1 | ||
| 470 | 	ldrbcs r12,[r1] | ||
| 471 | 	strbmi r2, [r0], #1 | ||
| 472 | 	strbcs r3, [r0], #1 | ||
| 473 | 	strbcs r12,[r0] | ||
| 474 | |||
| 475 | 	/* we're done! restore sp and spilled registers and return */ | ||
| 476 | 	add sp, sp, #28 | ||
| 477 | 	ldmfd sp!, {r0, r4, lr} | ||
| 478 | 	bx lr | ||
| 479 | |||
lib/libc/wasi/libc-top-half/musl/src/string/bcmp.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | |||
| 5 | int bcmp(const void *s1, const void *s2, size_t n) | ||
| 6 | { | ||
| 7 | 	return memcmp(s1, s2, n); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/bcopy.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | |||
| 5 | void bcopy(const void *s1, void *s2, size_t n) | ||
| 6 | { | ||
| 7 | 	memmove(s2, s1, n); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/bzero.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | |||
| 5 | void bzero(void *s, size_t n) | ||
| 6 | { | ||
| 7 | 	memset(s, 0, n); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/explicit_bzero.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | void explicit_bzero(void *d, size_t n) | ||
| 5 | { | ||
| 6 | 	d = memset(d, 0, n); | ||
| 7 | 	__asm__ __volatile__ ("" : : "r"(d) : "memory"); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/i386/memcpy.s created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | .global memcpy | ||
| 2 | .global __memcpy_fwd | ||
| 3 | .hidden __memcpy_fwd | ||
| 4 | .type memcpy,@function | ||
| 5 | memcpy: | ||
| 6 | __memcpy_fwd: | ||
| 7 | 	push %esi | ||
| 8 | 	push %edi | ||
| 9 | 	mov 12(%esp),%edi | ||
| 10 | 	mov 16(%esp),%esi | ||
| 11 | 	mov 20(%esp),%ecx | ||
| 12 | 	mov %edi,%eax | ||
| 13 | 	cmp $4,%ecx | ||
| 14 | 	jc 1f | ||
| 15 | 	test $3,%edi | ||
| 16 | 	jz 1f | ||
| 17 | 2:	movsb | ||
| 18 | 	dec %ecx | ||
| 19 | 	test $3,%edi | ||
| 20 | 	jnz 2b | ||
| 21 | 1:	mov %ecx,%edx | ||
| 22 | 	shr $2,%ecx | ||
| 23 | 	rep | ||
| 24 | 	movsl | ||
| 25 | 	and $3,%edx | ||
| 26 | 	jz 1f | ||
| 27 | 2:	movsb | ||
| 28 | 	dec %edx | ||
| 29 | 	jnz 2b | ||
| 30 | 1:	pop %edi | ||
| 31 | 	pop %esi | ||
| 32 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/string/i386/memmove.s created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | .global memmove | ||
| 2 | .type memmove,@function | ||
| 3 | memmove: | ||
| 4 | 	mov 4(%esp),%eax | ||
| 5 | 	sub 8(%esp),%eax | ||
| 6 | 	cmp 12(%esp),%eax | ||
| 7 | .hidden __memcpy_fwd | ||
| 8 | 	jae __memcpy_fwd | ||
| 9 | 	push %esi | ||
| 10 | 	push %edi | ||
| 11 | 	mov 12(%esp),%edi | ||
| 12 | 	mov 16(%esp),%esi | ||
| 13 | 	mov 20(%esp),%ecx | ||
| 14 | 	lea -1(%edi,%ecx),%edi | ||
| 15 | 	lea -1(%esi,%ecx),%esi | ||
| 16 | 	std | ||
| 17 | 	rep movsb | ||
| 18 | 	cld | ||
| 19 | 	lea 1(%edi),%eax | ||
| 20 | 	pop %edi | ||
| 21 | 	pop %esi | ||
| 22 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/string/i386/memset.s created+76| ... | @@ -0,0 +1,76 @@ | ||
| 1 | .global memset | ||
| 2 | .type memset,@function | ||
| 3 | memset: | ||
| 4 | 	mov 12(%esp),%ecx | ||
| 5 | 	cmp $62,%ecx | ||
| 6 | 	ja 2f | ||
| 7 | |||
| 8 | 	mov 8(%esp),%dl | ||
| 9 | 	mov 4(%esp),%eax | ||
| 10 | 	test %ecx,%ecx | ||
| 11 | 	jz 1f | ||
| 12 | |||
| 13 | 	mov %dl,%dh | ||
| 14 | |||
| 15 | 	mov %dl,(%eax) | ||
| 16 | 	mov %dl,-1(%eax,%ecx) | ||
| 17 | 	cmp $2,%ecx | ||
| 18 | 	jbe 1f | ||
| 19 | |||
| 20 | 	mov %dx,1(%eax) | ||
| 21 | 	mov %dx,(-1-2)(%eax,%ecx) | ||
| 22 | 	cmp $6,%ecx | ||
| 23 | 	jbe 1f | ||
| 24 | |||
| 25 | 	shl $16,%edx | ||
| 26 | 	mov 8(%esp),%dl | ||
| 27 | 	mov 8(%esp),%dh | ||
| 28 | |||
| 29 | 	mov %edx,(1+2)(%eax) | ||
| 30 | 	mov %edx,(-1-2-4)(%eax,%ecx) | ||
| 31 | 	cmp $14,%ecx | ||
| 32 | 	jbe 1f | ||
| 33 | |||
| 34 | 	mov %edx,(1+2+4)(%eax) | ||
| 35 | 	mov %edx,(1+2+4+4)(%eax) | ||
| 36 | 	mov %edx,(-1-2-4-8)(%eax,%ecx) | ||
| 37 | 	mov %edx,(-1-2-4-4)(%eax,%ecx) | ||
| 38 | 	cmp $30,%ecx | ||
| 39 | 	jbe 1f | ||
| 40 | |||
| 41 | 	mov %edx,(1+2+4+8)(%eax) | ||
| 42 | 	mov %edx,(1+2+4+8+4)(%eax) | ||
| 43 | 	mov %edx,(1+2+4+8+8)(%eax) | ||
| 44 | 	mov %edx,(1+2+4+8+12)(%eax) | ||
| 45 | 	mov %edx,(-1-2-4-8-16)(%eax,%ecx) | ||
| 46 | 	mov %edx,(-1-2-4-8-12)(%eax,%ecx) | ||
| 47 | 	mov %edx,(-1-2-4-8-8)(%eax,%ecx) | ||
| 48 | 	mov %edx,(-1-2-4-8-4)(%eax,%ecx) | ||
| 49 | |||
| 50 | 1:	ret 	 | ||
| 51 | |||
| 52 | 2:	movzbl 8(%esp),%eax | ||
| 53 | 	mov %edi,12(%esp) | ||
| 54 | 	imul $0x1010101,%eax | ||
| 55 | 	mov 4(%esp),%edi | ||
| 56 | 	test $15,%edi | ||
| 57 | 	mov %eax,-4(%edi,%ecx) | ||
| 58 | 	jnz 2f | ||
| 59 | |||
| 60 | 1:	shr $2, %ecx | ||
| 61 | 	rep | ||
| 62 | 	stosl | ||
| 63 | 	mov 4(%esp),%eax | ||
| 64 | 	mov 12(%esp),%edi | ||
| 65 | 	ret | ||
| 66 | 	 | ||
| 67 | 2:	xor %edx,%edx | ||
| 68 | 	sub %edi,%edx | ||
| 69 | 	and $15,%edx | ||
| 70 | 	mov %eax,(%edi) | ||
| 71 | 	mov %eax,4(%edi) | ||
| 72 | 	mov %eax,8(%edi) | ||
| 73 | 	mov %eax,12(%edi) | ||
| 74 | 	sub %edx,%ecx | ||
| 75 | 	add %edx,%edi | ||
| 76 | 	jmp 1b | ||
lib/libc/wasi/libc-top-half/musl/src/string/index.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | |||
| 5 | char *index(const char *s, int c) | ||
| 6 | { | ||
| 7 | 	return strchr(s, c); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memccpy.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | #define ALIGN (sizeof(size_t)-1) | ||
| 6 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 7 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 8 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 9 | |||
| 10 | void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n) | ||
| 11 | { | ||
| 12 | 	unsigned char *d = dest; | ||
| 13 | 	const unsigned char *s = src; | ||
| 14 | |||
| 15 | 	c = (unsigned char)c; | ||
| 16 | #ifdef __GNUC__ | ||
| 17 | 	typedef size_t __attribute__((__may_alias__)) word; | ||
| 18 | 	word *wd; | ||
| 19 | 	const word *ws; | ||
| 20 | 	if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { | ||
| 21 | 		for (; ((uintptr_t)s & ALIGN) && n && (*d=*s)!=c; n--, s++, d++); | ||
| 22 | 		if ((uintptr_t)s & ALIGN) goto tail; | ||
| 23 | 		size_t k = ONES * c; | ||
| 24 | 		wd=(void *)d; ws=(const void *)s; | ||
| 25 | 		for (; n>=sizeof(size_t) && !HASZERO(*ws^k); | ||
| 26 | 		 n-=sizeof(size_t), ws++, wd++) *wd = *ws; | ||
| 27 | 		d=(void *)wd; s=(const void *)ws; | ||
| 28 | 	} | ||
| 29 | #endif | ||
| 30 | 	for (; n && (*d=*s)!=c; n--, s++, d++); | ||
| 31 | tail: | ||
| 32 | 	if (n) return d+1; | ||
| 33 | 	return 0; | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memchr.c created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | #define SS (sizeof(size_t)) | ||
| 6 | #define ALIGN (sizeof(size_t)-1) | ||
| 7 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 8 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 9 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 10 | |||
| 11 | void *memchr(const void *src, int c, size_t n) | ||
| 12 | { | ||
| 13 | 	const unsigned char *s = src; | ||
| 14 | 	c = (unsigned char)c; | ||
| 15 | #ifdef __GNUC__ | ||
| 16 | 	for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--); | ||
| 17 | 	if (n && *s != c) { | ||
| 18 | 		typedef size_t __attribute__((__may_alias__)) word; | ||
| 19 | 		const word *w; | ||
| 20 | 		size_t k = ONES * c; | ||
| 21 | 		for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS); | ||
| 22 | 		s = (const void *)w; | ||
| 23 | 	} | ||
| 24 | #endif | ||
| 25 | 	for (; n && *s != c; s++, n--); | ||
| 26 | 	return n ? (void *)s : 0; | ||
| 27 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memcmp.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | int memcmp(const void *vl, const void *vr, size_t n) | ||
| 4 | { | ||
| 5 | 	const unsigned char *l=vl, *r=vr; | ||
| 6 | 	for (; n && *l == *r; n--, l++, r++); | ||
| 7 | 	return n ? *l-*r : 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memcpy.c created+124| ... | @@ -0,0 +1,124 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <endian.h> | ||
| 4 | |||
| 5 | void *memcpy(void *restrict dest, const void *restrict src, size_t n) | ||
| 6 | { | ||
| 7 | 	unsigned char *d = dest; | ||
| 8 | 	const unsigned char *s = src; | ||
| 9 | |||
| 10 | #ifdef __GNUC__ | ||
| 11 | |||
| 12 | #if __BYTE_ORDER == __LITTLE_ENDIAN | ||
| 13 | #define LS >> | ||
| 14 | #define RS << | ||
| 15 | #else | ||
| 16 | #define LS << | ||
| 17 | #define RS >> | ||
| 18 | #endif | ||
| 19 | |||
| 20 | 	typedef uint32_t __attribute__((__may_alias__)) u32; | ||
| 21 | 	uint32_t w, x; | ||
| 22 | |||
| 23 | 	for (; (uintptr_t)s % 4 && n; n--) *d++ = *s++; | ||
| 24 | |||
| 25 | 	if ((uintptr_t)d % 4 == 0) { | ||
| 26 | 		for (; n>=16; s+=16, d+=16, n-=16) { | ||
| 27 | 			*(u32 *)(d+0) = *(u32 *)(s+0); | ||
| 28 | 			*(u32 *)(d+4) = *(u32 *)(s+4); | ||
| 29 | 			*(u32 *)(d+8) = *(u32 *)(s+8); | ||
| 30 | 			*(u32 *)(d+12) = *(u32 *)(s+12); | ||
| 31 | 		} | ||
| 32 | 		if (n&8) { | ||
| 33 | 			*(u32 *)(d+0) = *(u32 *)(s+0); | ||
| 34 | 			*(u32 *)(d+4) = *(u32 *)(s+4); | ||
| 35 | 			d += 8; s += 8; | ||
| 36 | 		} | ||
| 37 | 		if (n&4) { | ||
| 38 | 			*(u32 *)(d+0) = *(u32 *)(s+0); | ||
| 39 | 			d += 4; s += 4; | ||
| 40 | 		} | ||
| 41 | 		if (n&2) { | ||
| 42 | 			*d++ = *s++; *d++ = *s++; | ||
| 43 | 		} | ||
| 44 | 		if (n&1) { | ||
| 45 | 			*d = *s; | ||
| 46 | 		} | ||
| 47 | 		return dest; | ||
| 48 | 	} | ||
| 49 | |||
| 50 | 	if (n >= 32) switch ((uintptr_t)d % 4) { | ||
| 51 | 	case 1: | ||
| 52 | 		w = *(u32 *)s; | ||
| 53 | 		*d++ = *s++; | ||
| 54 | 		*d++ = *s++; | ||
| 55 | 		*d++ = *s++; | ||
| 56 | 		n -= 3; | ||
| 57 | 		for (; n>=17; s+=16, d+=16, n-=16) { | ||
| 58 | 			x = *(u32 *)(s+1); | ||
| 59 | 			*(u32 *)(d+0) = (w LS 24) | (x RS 8); | ||
| 60 | 			w = *(u32 *)(s+5); | ||
| 61 | 			*(u32 *)(d+4) = (x LS 24) | (w RS 8); | ||
| 62 | 			x = *(u32 *)(s+9); | ||
| 63 | 			*(u32 *)(d+8) = (w LS 24) | (x RS 8); | ||
| 64 | 			w = *(u32 *)(s+13); | ||
| 65 | 			*(u32 *)(d+12) = (x LS 24) | (w RS 8); | ||
| 66 | 		} | ||
| 67 | 		break; | ||
| 68 | 	case 2: | ||
| 69 | 		w = *(u32 *)s; | ||
| 70 | 		*d++ = *s++; | ||
| 71 | 		*d++ = *s++; | ||
| 72 | 		n -= 2; | ||
| 73 | 		for (; n>=18; s+=16, d+=16, n-=16) { | ||
| 74 | 			x = *(u32 *)(s+2); | ||
| 75 | 			*(u32 *)(d+0) = (w LS 16) | (x RS 16); | ||
| 76 | 			w = *(u32 *)(s+6); | ||
| 77 | 			*(u32 *)(d+4) = (x LS 16) | (w RS 16); | ||
| 78 | 			x = *(u32 *)(s+10); | ||
| 79 | 			*(u32 *)(d+8) = (w LS 16) | (x RS 16); | ||
| 80 | 			w = *(u32 *)(s+14); | ||
| 81 | 			*(u32 *)(d+12) = (x LS 16) | (w RS 16); | ||
| 82 | 		} | ||
| 83 | 		break; | ||
| 84 | 	case 3: | ||
| 85 | 		w = *(u32 *)s; | ||
| 86 | 		*d++ = *s++; | ||
| 87 | 		n -= 1; | ||
| 88 | 		for (; n>=19; s+=16, d+=16, n-=16) { | ||
| 89 | 			x = *(u32 *)(s+3); | ||
| 90 | 			*(u32 *)(d+0) = (w LS 8) | (x RS 24); | ||
| 91 | 			w = *(u32 *)(s+7); | ||
| 92 | 			*(u32 *)(d+4) = (x LS 8) | (w RS 24); | ||
| 93 | 			x = *(u32 *)(s+11); | ||
| 94 | 			*(u32 *)(d+8) = (w LS 8) | (x RS 24); | ||
| 95 | 			w = *(u32 *)(s+15); | ||
| 96 | 			*(u32 *)(d+12) = (x LS 8) | (w RS 24); | ||
| 97 | 		} | ||
| 98 | 		break; | ||
| 99 | 	} | ||
| 100 | 	if (n&16) { | ||
| 101 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 102 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 103 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 104 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 105 | 	} | ||
| 106 | 	if (n&8) { | ||
| 107 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 108 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 109 | 	} | ||
| 110 | 	if (n&4) { | ||
| 111 | 		*d++ = *s++; *d++ = *s++; *d++ = *s++; *d++ = *s++; | ||
| 112 | 	} | ||
| 113 | 	if (n&2) { | ||
| 114 | 		*d++ = *s++; *d++ = *s++; | ||
| 115 | 	} | ||
| 116 | 	if (n&1) { | ||
| 117 | 		*d = *s; | ||
| 118 | 	} | ||
| 119 | 	return dest; | ||
| 120 | #endif | ||
| 121 | |||
| 122 | 	for (; n; n--) *d++ = *s++; | ||
| 123 | 	return dest; | ||
| 124 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memmem.c created+149| ... | @@ -0,0 +1,149 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | static char *twobyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) | ||
| 6 | { | ||
| 7 | 	uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; | ||
| 8 | 	for (h+=2, k-=2; k; k--, hw = hw<<8 | *h++) | ||
| 9 | 		if (hw == nw) return (char *)h-2; | ||
| 10 | 	return hw == nw ? (char *)h-2 : 0; | ||
| 11 | } | ||
| 12 | |||
| 13 | static char *threebyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) | ||
| 14 | { | ||
| 15 | 	uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8; | ||
| 16 | 	uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8; | ||
| 17 | 	for (h+=3, k-=3; k; k--, hw = (hw|*h++)<<8) | ||
| 18 | 		if (hw == nw) return (char *)h-3; | ||
| 19 | 	return hw == nw ? (char *)h-3 : 0; | ||
| 20 | } | ||
| 21 | |||
| 22 | static char *fourbyte_memmem(const unsigned char *h, size_t k, const unsigned char *n) | ||
| 23 | { | ||
| 24 | 	uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; | ||
| 25 | 	uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; | ||
| 26 | 	for (h+=4, k-=4; k; k--, hw = hw<<8 | *h++) | ||
| 27 | 		if (hw == nw) return (char *)h-4; | ||
| 28 | 	return hw == nw ? (char *)h-4 : 0; | ||
| 29 | } | ||
| 30 | |||
| 31 | #define MAX(a,b) ((a)>(b)?(a):(b)) | ||
| 32 | #define MIN(a,b) ((a)<(b)?(a):(b)) | ||
| 33 | |||
| 34 | #define BITOP(a,b,op) \ | ||
| 35 | ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) | ||
| 36 | |||
| 37 | static char *twoway_memmem(const unsigned char *h, const unsigned char *z, const unsigned char *n, size_t l) | ||
| 38 | { | ||
| 39 | 	size_t i, ip, jp, k, p, ms, p0, mem, mem0; | ||
| 40 | 	size_t byteset[32 / sizeof(size_t)] = { 0 }; | ||
| 41 | 	size_t shift[256]; | ||
| 42 | |||
| 43 | 	/* Computing length of needle and fill shift table */ | ||
| 44 | 	for (i=0; i<l; i++) | ||
| 45 | 		BITOP(byteset, n[i], |=), shift[n[i]] = i+1; | ||
| 46 | |||
| 47 | 	/* Compute maximal suffix */ | ||
| 48 | 	ip = -1; jp = 0; k = p = 1; | ||
| 49 | 	while (jp+k<l) { | ||
| 50 | 		if (n[ip+k] == n[jp+k]) { | ||
| 51 | 			if (k == p) { | ||
| 52 | 				jp += p; | ||
| 53 | 				k = 1; | ||
| 54 | 			} else k++; | ||
| 55 | 		} else if (n[ip+k] > n[jp+k]) { | ||
| 56 | 			jp += k; | ||
| 57 | 			k = 1; | ||
| 58 | 			p = jp - ip; | ||
| 59 | 		} else { | ||
| 60 | 			ip = jp++; | ||
| 61 | 			k = p = 1; | ||
| 62 | 		} | ||
| 63 | 	} | ||
| 64 | 	ms = ip; | ||
| 65 | 	p0 = p; | ||
| 66 | |||
| 67 | 	/* And with the opposite comparison */ | ||
| 68 | 	ip = -1; jp = 0; k = p = 1; | ||
| 69 | 	while (jp+k<l) { | ||
| 70 | 		if (n[ip+k] == n[jp+k]) { | ||
| 71 | 			if (k == p) { | ||
| 72 | 				jp += p; | ||
| 73 | 				k = 1; | ||
| 74 | 			} else k++; | ||
| 75 | 		} else if (n[ip+k] < n[jp+k]) { | ||
| 76 | 			jp += k; | ||
| 77 | 			k = 1; | ||
| 78 | 			p = jp - ip; | ||
| 79 | 		} else { | ||
| 80 | 			ip = jp++; | ||
| 81 | 			k = p = 1; | ||
| 82 | 		} | ||
| 83 | 	} | ||
| 84 | 	if (ip+1 > ms+1) ms = ip; | ||
| 85 | 	else p = p0; | ||
| 86 | |||
| 87 | 	/* Periodic needle? */ | ||
| 88 | 	if (memcmp(n, n+p, ms+1)) { | ||
| 89 | 		mem0 = 0; | ||
| 90 | 		p = MAX(ms, l-ms-1) + 1; | ||
| 91 | 	} else mem0 = l-p; | ||
| 92 | 	mem = 0; | ||
| 93 | |||
| 94 | 	/* Search loop */ | ||
| 95 | 	for (;;) { | ||
| 96 | 		/* If remainder of haystack is shorter than needle, done */ | ||
| 97 | 		if (z-h < l) return 0; | ||
| 98 | |||
| 99 | 		/* Check last byte first; advance by shift on mismatch */ | ||
| 100 | 		if (BITOP(byteset, h[l-1], &)) { | ||
| 101 | 			k = l-shift[h[l-1]]; | ||
| 102 | 			if (k) { | ||
| 103 | 				if (k < mem) k = mem; | ||
| 104 | 				h += k; | ||
| 105 | 				mem = 0; | ||
| 106 | 				continue; | ||
| 107 | 			} | ||
| 108 | 		} else { | ||
| 109 | 			h += l; | ||
| 110 | 			mem = 0; | ||
| 111 | 			continue; | ||
| 112 | 		} | ||
| 113 | |||
| 114 | 		/* Compare right half */ | ||
| 115 | 		for (k=MAX(ms+1,mem); k<l && n[k] == h[k]; k++); | ||
| 116 | 		if (k < l) { | ||
| 117 | 			h += k-ms; | ||
| 118 | 			mem = 0; | ||
| 119 | 			continue; | ||
| 120 | 		} | ||
| 121 | 		/* Compare left half */ | ||
| 122 | 		for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); | ||
| 123 | 		if (k <= mem) return (char *)h; | ||
| 124 | 		h += p; | ||
| 125 | 		mem = mem0; | ||
| 126 | 	} | ||
| 127 | } | ||
| 128 | |||
| 129 | void *memmem(const void *h0, size_t k, const void *n0, size_t l) | ||
| 130 | { | ||
| 131 | 	const unsigned char *h = h0, *n = n0; | ||
| 132 | |||
| 133 | 	/* Return immediately on empty needle */ | ||
| 134 | 	if (!l) return (void *)h; | ||
| 135 | |||
| 136 | 	/* Return immediately when needle is longer than haystack */ | ||
| 137 | 	if (k<l) return 0; | ||
| 138 | |||
| 139 | 	/* Use faster algorithms for short needles */ | ||
| 140 | 	h = memchr(h0, *n, k); | ||
| 141 | 	if (!h || l==1) return (void *)h; | ||
| 142 | 	k -= h - (const unsigned char *)h0; | ||
| 143 | 	if (k<l) return 0; | ||
| 144 | 	if (l==2) return twobyte_memmem(h, k, n); | ||
| 145 | 	if (l==3) return threebyte_memmem(h, k, n); | ||
| 146 | 	if (l==4) return fourbyte_memmem(h, k, n); | ||
| 147 | |||
| 148 | 	return twoway_memmem(h, h+k, n, l); | ||
| 149 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memmove.c created+42| ... | @@ -0,0 +1,42 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | #ifdef __GNUC__ | ||
| 5 | typedef __attribute__((__may_alias__)) size_t WT; | ||
| 6 | #define WS (sizeof(WT)) | ||
| 7 | #endif | ||
| 8 | |||
| 9 | void *memmove(void *dest, const void *src, size_t n) | ||
| 10 | { | ||
| 11 | 	char *d = dest; | ||
| 12 | 	const char *s = src; | ||
| 13 | |||
| 14 | 	if (d==s) return d; | ||
| 15 | 	if ((uintptr_t)s-(uintptr_t)d-n <= -2*n) return memcpy(d, s, n); | ||
| 16 | |||
| 17 | 	if (d<s) { | ||
| 18 | #ifdef __GNUC__ | ||
| 19 | 		if ((uintptr_t)s % WS == (uintptr_t)d % WS) { | ||
| 20 | 			while ((uintptr_t)d % WS) { | ||
| 21 | 				if (!n--) return dest; | ||
| 22 | 				*d++ = *s++; | ||
| 23 | 			} | ||
| 24 | 			for (; n>=WS; n-=WS, d+=WS, s+=WS) *(WT *)d = *(WT *)s; | ||
| 25 | 		} | ||
| 26 | #endif | ||
| 27 | 		for (; n; n--) *d++ = *s++; | ||
| 28 | 	} else { | ||
| 29 | #ifdef __GNUC__ | ||
| 30 | 		if ((uintptr_t)s % WS == (uintptr_t)d % WS) { | ||
| 31 | 			while ((uintptr_t)(d+n) % WS) { | ||
| 32 | 				if (!n--) return dest; | ||
| 33 | 				d[n] = s[n]; | ||
| 34 | 			} | ||
| 35 | 			while (n>=WS) n-=WS, *(WT *)(d+n) = *(WT *)(s+n); | ||
| 36 | 		} | ||
| 37 | #endif | ||
| 38 | 		while (n) n--, d[n] = s[n]; | ||
| 39 | 	} | ||
| 40 | |||
| 41 | 	return dest; | ||
| 42 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/mempcpy.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | void *mempcpy(void *dest, const void *src, size_t n) | ||
| 5 | { | ||
| 6 | 	return (char *)memcpy(dest, src, n) + n; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/memrchr.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | void *__memrchr(const void *m, int c, size_t n) | ||
| 4 | { | ||
| 5 | 	const unsigned char *s = m; | ||
| 6 | 	c = (unsigned char)c; | ||
| 7 | 	while (n--) if (s[n]==c) return (void *)(s+n); | ||
| 8 | 	return 0; | ||
| 9 | } | ||
| 10 | |||
| 11 | weak_alias(__memrchr, memrchr); | ||
lib/libc/wasi/libc-top-half/musl/src/string/memset.c created+90| ... | @@ -0,0 +1,90 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | void *memset(void *dest, int c, size_t n) | ||
| 5 | { | ||
| 6 | 	unsigned char *s = dest; | ||
| 7 | 	size_t k; | ||
| 8 | |||
| 9 | 	/* Fill head and tail with minimal branching. Each | ||
| 10 | 	 * conditional ensures that all the subsequently used | ||
| 11 | 	 * offsets are well-defined and in the dest region. */ | ||
| 12 | |||
| 13 | 	if (!n) return dest; | ||
| 14 | 	s[0] = c; | ||
| 15 | 	s[n-1] = c; | ||
| 16 | 	if (n <= 2) return dest; | ||
| 17 | 	s[1] = c; | ||
| 18 | 	s[2] = c; | ||
| 19 | 	s[n-2] = c; | ||
| 20 | 	s[n-3] = c; | ||
| 21 | 	if (n <= 6) return dest; | ||
| 22 | 	s[3] = c; | ||
| 23 | 	s[n-4] = c; | ||
| 24 | 	if (n <= 8) return dest; | ||
| 25 | |||
| 26 | 	/* Advance pointer to align it at a 4-byte boundary, | ||
| 27 | 	 * and truncate n to a multiple of 4. The previous code | ||
| 28 | 	 * already took care of any head/tail that get cut off | ||
| 29 | 	 * by the alignment. */ | ||
| 30 | |||
| 31 | 	k = -(uintptr_t)s & 3; | ||
| 32 | 	s += k; | ||
| 33 | 	n -= k; | ||
| 34 | 	n &= -4; | ||
| 35 | |||
| 36 | #ifdef __GNUC__ | ||
| 37 | 	typedef uint32_t __attribute__((__may_alias__)) u32; | ||
| 38 | 	typedef uint64_t __attribute__((__may_alias__)) u64; | ||
| 39 | |||
| 40 | 	u32 c32 = ((u32)-1)/255 * (unsigned char)c; | ||
| 41 | |||
| 42 | 	/* In preparation to copy 32 bytes at a time, aligned on | ||
| 43 | 	 * an 8-byte bounary, fill head/tail up to 28 bytes each. | ||
| 44 | 	 * As in the initial byte-based head/tail fill, each | ||
| 45 | 	 * conditional below ensures that the subsequent offsets | ||
| 46 | 	 * are valid (e.g. !(n<=24) implies n>=28). */ | ||
| 47 | |||
| 48 | 	*(u32 *)(s+0) = c32; | ||
| 49 | 	*(u32 *)(s+n-4) = c32; | ||
| 50 | 	if (n <= 8) return dest; | ||
| 51 | 	*(u32 *)(s+4) = c32; | ||
| 52 | 	*(u32 *)(s+8) = c32; | ||
| 53 | 	*(u32 *)(s+n-12) = c32; | ||
| 54 | 	*(u32 *)(s+n-8) = c32; | ||
| 55 | 	if (n <= 24) return dest; | ||
| 56 | 	*(u32 *)(s+12) = c32; | ||
| 57 | 	*(u32 *)(s+16) = c32; | ||
| 58 | 	*(u32 *)(s+20) = c32; | ||
| 59 | 	*(u32 *)(s+24) = c32; | ||
| 60 | 	*(u32 *)(s+n-28) = c32; | ||
| 61 | 	*(u32 *)(s+n-24) = c32; | ||
| 62 | 	*(u32 *)(s+n-20) = c32; | ||
| 63 | 	*(u32 *)(s+n-16) = c32; | ||
| 64 | |||
| 65 | 	/* Align to a multiple of 8 so we can fill 64 bits at a time, | ||
| 66 | 	 * and avoid writing the same bytes twice as much as is | ||
| 67 | 	 * practical without introducing additional branching. */ | ||
| 68 | |||
| 69 | 	k = 24 + ((uintptr_t)s & 4); | ||
| 70 | 	s += k; | ||
| 71 | 	n -= k; | ||
| 72 | |||
| 73 | 	/* If this loop is reached, 28 tail bytes have already been | ||
| 74 | 	 * filled, so any remainder when n drops below 32 can be | ||
| 75 | 	 * safely ignored. */ | ||
| 76 | |||
| 77 | 	u64 c64 = c32 | ((u64)c32 << 32); | ||
| 78 | 	for (; n >= 32; n-=32, s+=32) { | ||
| 79 | 		*(u64 *)(s+0) = c64; | ||
| 80 | 		*(u64 *)(s+8) = c64; | ||
| 81 | 		*(u64 *)(s+16) = c64; | ||
| 82 | 		*(u64 *)(s+24) = c64; | ||
| 83 | 	} | ||
| 84 | #else | ||
| 85 | 	/* Pure C fallback with no aliasing violations. */ | ||
| 86 | 	for (; n; n--, s++) *s = c; | ||
| 87 | #endif | ||
| 88 | |||
| 89 | 	return dest; | ||
| 90 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/rindex.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <strings.h> | ||
| 4 | |||
| 5 | char *rindex(const char *s, int c) | ||
| 6 | { | ||
| 7 | 	return strrchr(s, c); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/stpcpy.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | #define ALIGN (sizeof(size_t)) | ||
| 6 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 7 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 8 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 9 | |||
| 10 | char *__stpcpy(char *restrict d, const char *restrict s) | ||
| 11 | { | ||
| 12 | #ifdef __GNUC__ | ||
| 13 | 	typedef size_t __attribute__((__may_alias__)) word; | ||
| 14 | 	word *wd; | ||
| 15 | 	const word *ws; | ||
| 16 | 	if ((uintptr_t)s % ALIGN == (uintptr_t)d % ALIGN) { | ||
| 17 | 		for (; (uintptr_t)s % ALIGN; s++, d++) | ||
| 18 | 			if (!(*d=*s)) return d; | ||
| 19 | 		wd=(void *)d; ws=(const void *)s; | ||
| 20 | 		for (; !HASZERO(*ws); *wd++ = *ws++); | ||
| 21 | 		d=(void *)wd; s=(const void *)ws; | ||
| 22 | 	} | ||
| 23 | #endif | ||
| 24 | 	for (; (*d=*s); s++, d++); | ||
| 25 | |||
| 26 | 	return d; | ||
| 27 | } | ||
| 28 | |||
| 29 | weak_alias(__stpcpy, stpcpy); | ||
lib/libc/wasi/libc-top-half/musl/src/string/stpncpy.c created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | #define ALIGN (sizeof(size_t)-1) | ||
| 6 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 7 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 8 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 9 | |||
| 10 | char *__stpncpy(char *restrict d, const char *restrict s, size_t n) | ||
| 11 | { | ||
| 12 | #ifdef __GNUC__ | ||
| 13 | 	typedef size_t __attribute__((__may_alias__)) word; | ||
| 14 | 	word *wd; | ||
| 15 | 	const word *ws; | ||
| 16 | 	if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { | ||
| 17 | 		for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); | ||
| 18 | 		if (!n || !*s) goto tail; | ||
| 19 | 		wd=(void *)d; ws=(const void *)s; | ||
| 20 | 		for (; n>=sizeof(size_t) && !HASZERO(*ws); | ||
| 21 | 		 n-=sizeof(size_t), ws++, wd++) *wd = *ws; | ||
| 22 | 		d=(void *)wd; s=(const void *)ws; | ||
| 23 | 	} | ||
| 24 | #endif | ||
| 25 | 	for (; n && (*d=*s); n--, s++, d++); | ||
| 26 | tail: | ||
| 27 | 	memset(d, 0, n); | ||
| 28 | 	return d; | ||
| 29 | } | ||
| 30 | |||
| 31 | weak_alias(__stpncpy, stpncpy); | ||
| 32 | |||
lib/libc/wasi/libc-top-half/musl/src/string/strcasecmp.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <strings.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | |||
| 4 | int strcasecmp(const char *_l, const char *_r) | ||
| 5 | { | ||
| 6 | 	const unsigned char *l=(void *)_l, *r=(void *)_r; | ||
| 7 | 	for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++); | ||
| 8 | 	return tolower(*l) - tolower(*r); | ||
| 9 | } | ||
| 10 | |||
| 11 | int __strcasecmp_l(const char *l, const char *r, locale_t loc) | ||
| 12 | { | ||
| 13 | 	return strcasecmp(l, r); | ||
| 14 | } | ||
| 15 | |||
| 16 | weak_alias(__strcasecmp_l, strcasecmp_l); | ||
lib/libc/wasi/libc-top-half/musl/src/string/strcasestr.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | char *strcasestr(const char *h, const char *n) | ||
| 5 | { | ||
| 6 | 	size_t l = strlen(n); | ||
| 7 | 	for (; *h; h++) if (!strncasecmp(h, n, l)) return (char *)h; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strcat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strcat(char *restrict dest, const char *restrict src) | ||
| 4 | { | ||
| 5 | 	strcpy(dest + strlen(dest), src); | ||
| 6 | 	return dest; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strchr.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strchr(const char *s, int c) | ||
| 4 | { | ||
| 5 | 	char *r = __strchrnul(s, c); | ||
| 6 | 	return *(unsigned char *)r == (unsigned char)c ? r : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strchrnul.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | #define ALIGN (sizeof(size_t)) | ||
| 6 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 7 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 8 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 9 | |||
| 10 | char *__strchrnul(const char *s, int c) | ||
| 11 | { | ||
| 12 | 	c = (unsigned char)c; | ||
| 13 | 	if (!c) return (char *)s + strlen(s); | ||
| 14 | |||
| 15 | #ifdef __GNUC__ | ||
| 16 | 	typedef size_t __attribute__((__may_alias__)) word; | ||
| 17 | 	const word *w; | ||
| 18 | 	for (; (uintptr_t)s % ALIGN; s++) | ||
| 19 | 		if (!*s || *(unsigned char *)s == c) return (char *)s; | ||
| 20 | 	size_t k = ONES * c; | ||
| 21 | 	for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++); | ||
| 22 | 	s = (void *)w; | ||
| 23 | #endif | ||
| 24 | 	for (; *s && *(unsigned char *)s != c; s++); | ||
| 25 | 	return (char *)s; | ||
| 26 | } | ||
| 27 | |||
| 28 | weak_alias(__strchrnul, strchrnul); | ||
lib/libc/wasi/libc-top-half/musl/src/string/strcmp.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | int strcmp(const char *l, const char *r) | ||
| 4 | { | ||
| 5 | 	for (; *l==*r && *l; l++, r++); | ||
| 6 | 	return *(unsigned char *)l - *(unsigned char *)r; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strcpy.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strcpy(char *restrict dest, const char *restrict src) | ||
| 4 | { | ||
| 5 | 	__stpcpy(dest, src); | ||
| 6 | 	return dest; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strcspn.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | #define BITOP(a,b,op) \ | ||
| 4 | ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) | ||
| 5 | |||
| 6 | size_t strcspn(const char *s, const char *c) | ||
| 7 | { | ||
| 8 | 	const char *a = s; | ||
| 9 | 	size_t byteset[32/sizeof(size_t)]; | ||
| 10 | |||
| 11 | 	if (!c[0] || !c[1]) return __strchrnul(s, *c)-a; | ||
| 12 | |||
| 13 | 	memset(byteset, 0, sizeof byteset); | ||
| 14 | 	for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); | ||
| 15 | 	for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++); | ||
| 16 | 	return s-a; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strdup.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | char *strdup(const char *s) | ||
| 5 | { | ||
| 6 | 	size_t l = strlen(s); | ||
| 7 | 	char *d = malloc(l+1); | ||
| 8 | 	if (!d) return NULL; | ||
| 9 | 	return memcpy(d, s, l+1); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strerror_r.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int strerror_r(int err, char *buf, size_t buflen) | ||
| 5 | { | ||
| 6 | 	char *msg = strerror(err); | ||
| 7 | 	size_t l = strlen(msg); | ||
| 8 | 	if (l >= buflen) { | ||
| 9 | 		if (buflen) { | ||
| 10 | 			memcpy(buf, msg, buflen-1); | ||
| 11 | 			buf[buflen-1] = 0; | ||
| 12 | 		} | ||
| 13 | 		return ERANGE; | ||
| 14 | 	} | ||
| 15 | 	memcpy(buf, msg, l+1); | ||
| 16 | 	return 0; | ||
| 17 | } | ||
| 18 | |||
| 19 | weak_alias(strerror_r, __xpg_strerror_r); | ||
lib/libc/wasi/libc-top-half/musl/src/string/strlcat.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | size_t strlcat(char *d, const char *s, size_t n) | ||
| 5 | { | ||
| 6 | 	size_t l = strnlen(d, n); | ||
| 7 | 	if (l == n) return l + strlen(s); | ||
| 8 | 	return l + strlcpy(d+l, s, n-l); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strlcpy.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include <limits.h> | ||
| 5 | |||
| 6 | #define ALIGN (sizeof(size_t)-1) | ||
| 7 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 8 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 9 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 10 | |||
| 11 | size_t strlcpy(char *d, const char *s, size_t n) | ||
| 12 | { | ||
| 13 | 	char *d0 = d; | ||
| 14 | 	size_t *wd; | ||
| 15 | |||
| 16 | 	if (!n--) goto finish; | ||
| 17 | #ifdef __GNUC__ | ||
| 18 | 	typedef size_t __attribute__((__may_alias__)) word; | ||
| 19 | 	const word *ws; | ||
| 20 | 	if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { | ||
| 21 | 		for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); | ||
| 22 | 		if (n && *s) { | ||
| 23 | 			wd=(void *)d; ws=(const void *)s; | ||
| 24 | 			for (; n>=sizeof(size_t) && !HASZERO(*ws); | ||
| 25 | 			 n-=sizeof(size_t), ws++, wd++) *wd = *ws; | ||
| 26 | 			d=(void *)wd; s=(const void *)ws; | ||
| 27 | 		} | ||
| 28 | 	} | ||
| 29 | #endif | ||
| 30 | 	for (; n && (*d=*s); n--, s++, d++); | ||
| 31 | 	*d = 0; | ||
| 32 | finish: | ||
| 33 | 	return d-d0 + strlen(s); | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strlen.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | #define ALIGN (sizeof(size_t)) | ||
| 6 | #define ONES ((size_t)-1/UCHAR_MAX) | ||
| 7 | #define HIGHS (ONES * (UCHAR_MAX/2+1)) | ||
| 8 | #define HASZERO(x) ((x)-ONES & ~(x) & HIGHS) | ||
| 9 | |||
| 10 | size_t strlen(const char *s) | ||
| 11 | { | ||
| 12 | 	const char *a = s; | ||
| 13 | #ifdef __GNUC__ | ||
| 14 | 	typedef size_t __attribute__((__may_alias__)) word; | ||
| 15 | 	const word *w; | ||
| 16 | 	for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a; | ||
| 17 | 	for (w = (const void *)s; !HASZERO(*w); w++); | ||
| 18 | 	s = (const void *)w; | ||
| 19 | #endif | ||
| 20 | 	for (; *s; s++); | ||
| 21 | 	return s-a; | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strncasecmp.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <strings.h> | ||
| 2 | #include <ctype.h> | ||
| 3 | |||
| 4 | int strncasecmp(const char *_l, const char *_r, size_t n) | ||
| 5 | { | ||
| 6 | 	const unsigned char *l=(void *)_l, *r=(void *)_r; | ||
| 7 | 	if (!n--) return 0; | ||
| 8 | 	for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--); | ||
| 9 | 	return tolower(*l) - tolower(*r); | ||
| 10 | } | ||
| 11 | |||
| 12 | int __strncasecmp_l(const char *l, const char *r, size_t n, locale_t loc) | ||
| 13 | { | ||
| 14 | 	return strncasecmp(l, r, n); | ||
| 15 | } | ||
| 16 | |||
| 17 | weak_alias(__strncasecmp_l, strncasecmp_l); | ||
lib/libc/wasi/libc-top-half/musl/src/string/strncat.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strncat(char *restrict d, const char *restrict s, size_t n) | ||
| 4 | { | ||
| 5 | 	char *a = d; | ||
| 6 | 	d += strlen(d); | ||
| 7 | 	while (n && *s) n--, *d++ = *s++; | ||
| 8 | 	*d++ = 0; | ||
| 9 | 	return a; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strncmp.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | int strncmp(const char *_l, const char *_r, size_t n) | ||
| 4 | { | ||
| 5 | 	const unsigned char *l=(void *)_l, *r=(void *)_r; | ||
| 6 | 	if (!n--) return 0; | ||
| 7 | 	for (; *l && *r && n && *l == *r ; l++, r++, n--); | ||
| 8 | 	return *l - *r; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strncpy.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strncpy(char *restrict d, const char *restrict s, size_t n) | ||
| 4 | { | ||
| 5 | 	__stpncpy(d, s, n); | ||
| 6 | 	return d; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strndup.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | char *strndup(const char *s, size_t n) | ||
| 5 | { | ||
| 6 | 	size_t l = strnlen(s, n); | ||
| 7 | 	char *d = malloc(l+1); | ||
| 8 | 	if (!d) return NULL; | ||
| 9 | 	memcpy(d, s, l); | ||
| 10 | 	d[l] = 0; | ||
| 11 | 	return d; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strnlen.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | size_t strnlen(const char *s, size_t n) | ||
| 4 | { | ||
| 5 | 	const char *p = memchr(s, 0, n); | ||
| 6 | 	return p ? p-s : n; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strpbrk.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strpbrk(const char *s, const char *b) | ||
| 4 | { | ||
| 5 | 	s += strcspn(s, b); | ||
| 6 | 	return *s ? (char *)s : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strrchr.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strrchr(const char *s, int c) | ||
| 4 | { | ||
| 5 | 	return __memrchr(s, c, strlen(s) + 1); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strsep.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | char *strsep(char **str, const char *sep) | ||
| 5 | { | ||
| 6 | 	char *s = *str, *end; | ||
| 7 | 	if (!s) return NULL; | ||
| 8 | 	end = s + strcspn(s, sep); | ||
| 9 | 	if (*end) *end++ = 0; | ||
| 10 | 	else end = 0; | ||
| 11 | 	*str = end; | ||
| 12 | 	return s; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strsignal.c created+126| ... | @@ -0,0 +1,126 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include "locale_impl.h" | ||
| 4 | |||
| 5 | #if (SIGHUP == 1) && (SIGINT == 2) && (SIGQUIT == 3) && (SIGILL == 4) \ | ||
| 6 | && (SIGTRAP == 5) && (SIGABRT == 6) && (SIGBUS == 7) && (SIGFPE == 8) \ | ||
| 7 | && (SIGKILL == 9) && (SIGUSR1 == 10) && (SIGSEGV == 11) && (SIGUSR2 == 12) \ | ||
| 8 | && (SIGPIPE == 13) && (SIGALRM == 14) && (SIGTERM == 15) && (SIGSTKFLT == 16) \ | ||
| 9 | && (SIGCHLD == 17) && (SIGCONT == 18) && (SIGSTOP == 19) && (SIGTSTP == 20) \ | ||
| 10 | && (SIGTTIN == 21) && (SIGTTOU == 22) && (SIGURG == 23) && (SIGXCPU == 24) \ | ||
| 11 | && (SIGXFSZ == 25) && (SIGVTALRM == 26) && (SIGPROF == 27) && (SIGWINCH == 28) \ | ||
| 12 | && (SIGPOLL == 29) && (SIGPWR == 30) && (SIGSYS == 31) | ||
| 13 | |||
| 14 | #define sigmap(x) x | ||
| 15 | |||
| 16 | #else | ||
| 17 | |||
| 18 | static const char map[] = { | ||
| 19 | 	[SIGHUP] = 1, | ||
| 20 | 	[SIGINT] = 2, | ||
| 21 | 	[SIGQUIT] = 3, | ||
| 22 | 	[SIGILL] = 4, | ||
| 23 | 	[SIGTRAP] = 5, | ||
| 24 | 	[SIGABRT] = 6, | ||
| 25 | 	[SIGBUS] = 7, | ||
| 26 | 	[SIGFPE] = 8, | ||
| 27 | 	[SIGKILL] = 9, | ||
| 28 | 	[SIGUSR1] = 10, | ||
| 29 | 	[SIGSEGV] = 11, | ||
| 30 | 	[SIGUSR2] = 12, | ||
| 31 | 	[SIGPIPE] = 13, | ||
| 32 | 	[SIGALRM] = 14, | ||
| 33 | 	[SIGTERM] = 15, | ||
| 34 | #if defined(SIGSTKFLT) | ||
| 35 | 	[SIGSTKFLT] = 16, | ||
| 36 | #elif defined(SIGEMT) | ||
| 37 | 	[SIGEMT] = 16, | ||
| 38 | #endif | ||
| 39 | 	[SIGCHLD] = 17, | ||
| 40 | 	[SIGCONT] = 18, | ||
| 41 | 	[SIGSTOP] = 19, | ||
| 42 | 	[SIGTSTP] = 20, | ||
| 43 | 	[SIGTTIN] = 21, | ||
| 44 | 	[SIGTTOU] = 22, | ||
| 45 | 	[SIGURG] = 23, | ||
| 46 | 	[SIGXCPU] = 24, | ||
| 47 | 	[SIGXFSZ] = 25, | ||
| 48 | 	[SIGVTALRM] = 26, | ||
| 49 | 	[SIGPROF] = 27, | ||
| 50 | 	[SIGWINCH] = 28, | ||
| 51 | 	[SIGPOLL] = 29, | ||
| 52 | 	[SIGPWR] = 30, | ||
| 53 | 	[SIGSYS] = 31 | ||
| 54 | }; | ||
| 55 | |||
| 56 | #define sigmap(x) ((x) >= sizeof map ? (x) : map[(x)]) | ||
| 57 | |||
| 58 | #endif | ||
| 59 | |||
| 60 | static const char strings[] = | ||
| 61 | 	"Unknown signal\0" | ||
| 62 | 	"Hangup\0" | ||
| 63 | 	"Interrupt\0" | ||
| 64 | 	"Quit\0" | ||
| 65 | 	"Illegal instruction\0" | ||
| 66 | 	"Trace/breakpoint trap\0" | ||
| 67 | 	"Aborted\0" | ||
| 68 | 	"Bus error\0" | ||
| 69 | 	"Arithmetic exception\0" | ||
| 70 | 	"Killed\0" | ||
| 71 | 	"User defined signal 1\0" | ||
| 72 | 	"Segmentation fault\0" | ||
| 73 | 	"User defined signal 2\0" | ||
| 74 | 	"Broken pipe\0" | ||
| 75 | 	"Alarm clock\0" | ||
| 76 | 	"Terminated\0" | ||
| 77 | #if defined(SIGSTKFLT) | ||
| 78 | 	"Stack fault\0" | ||
| 79 | #elif defined(SIGEMT) | ||
| 80 | 	"Emulator trap\0" | ||
| 81 | #else | ||
| 82 | 	"Unknown signal\0" | ||
| 83 | #endif | ||
| 84 | 	"Child process status\0" | ||
| 85 | 	"Continued\0" | ||
| 86 | 	"Stopped (signal)\0" | ||
| 87 | 	"Stopped\0" | ||
| 88 | 	"Stopped (tty input)\0" | ||
| 89 | 	"Stopped (tty output)\0" | ||
| 90 | 	"Urgent I/O condition\0" | ||
| 91 | 	"CPU time limit exceeded\0" | ||
| 92 | 	"File size limit exceeded\0" | ||
| 93 | 	"Virtual timer expired\0" | ||
| 94 | 	"Profiling timer expired\0" | ||
| 95 | 	"Window changed\0" | ||
| 96 | 	"I/O possible\0" | ||
| 97 | 	"Power failure\0" | ||
| 98 | 	"Bad system call\0" | ||
| 99 | 	"RT32" | ||
| 100 | 	"\0RT33\0RT34\0RT35\0RT36\0RT37\0RT38\0RT39\0RT40" | ||
| 101 | 	"\0RT41\0RT42\0RT43\0RT44\0RT45\0RT46\0RT47\0RT48" | ||
| 102 | 	"\0RT49\0RT50\0RT51\0RT52\0RT53\0RT54\0RT55\0RT56" | ||
| 103 | 	"\0RT57\0RT58\0RT59\0RT60\0RT61\0RT62\0RT63\0RT64" | ||
| 104 | #if _NSIG > 65 | ||
| 105 | 	"\0RT65\0RT66\0RT67\0RT68\0RT69\0RT70\0RT71\0RT72" | ||
| 106 | 	"\0RT73\0RT74\0RT75\0RT76\0RT77\0RT78\0RT79\0RT80" | ||
| 107 | 	"\0RT81\0RT82\0RT83\0RT84\0RT85\0RT86\0RT87\0RT88" | ||
| 108 | 	"\0RT89\0RT90\0RT91\0RT92\0RT93\0RT94\0RT95\0RT96" | ||
| 109 | 	"\0RT97\0RT98\0RT99\0RT100\0RT101\0RT102\0RT103\0RT104" | ||
| 110 | 	"\0RT105\0RT106\0RT107\0RT108\0RT109\0RT110\0RT111\0RT112" | ||
| 111 | 	"\0RT113\0RT114\0RT115\0RT116\0RT117\0RT118\0RT119\0RT120" | ||
| 112 | 	"\0RT121\0RT122\0RT123\0RT124\0RT125\0RT126\0RT127\0RT128" | ||
| 113 | #endif | ||
| 114 | 	""; | ||
| 115 | |||
| 116 | char *strsignal(int signum) | ||
| 117 | { | ||
| 118 | 	const char *s = strings; | ||
| 119 | |||
| 120 | 	signum = sigmap(signum); | ||
| 121 | 	if (signum - 1U >= _NSIG-1) signum = 0; | ||
| 122 | |||
| 123 | 	for (; signum--; s++) for (; *s; s++); | ||
| 124 | |||
| 125 | 	return (char *)LCTRANS_CUR(s); | ||
| 126 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strspn.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | #define BITOP(a,b,op) \ | ||
| 4 | ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) | ||
| 5 | |||
| 6 | size_t strspn(const char *s, const char *c) | ||
| 7 | { | ||
| 8 | 	const char *a = s; | ||
| 9 | 	size_t byteset[32/sizeof(size_t)] = { 0 }; | ||
| 10 | |||
| 11 | 	if (!c[0]) return 0; | ||
| 12 | 	if (!c[1]) { | ||
| 13 | 		for (; *s == *c; s++); | ||
| 14 | 		return s-a; | ||
| 15 | 	} | ||
| 16 | |||
| 17 | 	for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++); | ||
| 18 | 	for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++); | ||
| 19 | 	return s-a; | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strstr.c created+154| ... | @@ -0,0 +1,154 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | static char *twobyte_strstr(const unsigned char *h, const unsigned char *n) | ||
| 5 | { | ||
| 6 | 	uint16_t nw = n[0]<<8 | n[1], hw = h[0]<<8 | h[1]; | ||
| 7 | 	for (h++; *h && hw != nw; hw = hw<<8 | *++h); | ||
| 8 | 	return *h ? (char *)h-1 : 0; | ||
| 9 | } | ||
| 10 | |||
| 11 | static char *threebyte_strstr(const unsigned char *h, const unsigned char *n) | ||
| 12 | { | ||
| 13 | 	uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8; | ||
| 14 | 	uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8; | ||
| 15 | 	for (h+=2; *h && hw != nw; hw = (hw|*++h)<<8); | ||
| 16 | 	return *h ? (char *)h-2 : 0; | ||
| 17 | } | ||
| 18 | |||
| 19 | static char *fourbyte_strstr(const unsigned char *h, const unsigned char *n) | ||
| 20 | { | ||
| 21 | 	uint32_t nw = (uint32_t)n[0]<<24 | n[1]<<16 | n[2]<<8 | n[3]; | ||
| 22 | 	uint32_t hw = (uint32_t)h[0]<<24 | h[1]<<16 | h[2]<<8 | h[3]; | ||
| 23 | 	for (h+=3; *h && hw != nw; hw = hw<<8 | *++h); | ||
| 24 | 	return *h ? (char *)h-3 : 0; | ||
| 25 | } | ||
| 26 | |||
| 27 | #define MAX(a,b) ((a)>(b)?(a):(b)) | ||
| 28 | #define MIN(a,b) ((a)<(b)?(a):(b)) | ||
| 29 | |||
| 30 | #define BITOP(a,b,op) \ | ||
| 31 | ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a)))) | ||
| 32 | |||
| 33 | static char *twoway_strstr(const unsigned char *h, const unsigned char *n) | ||
| 34 | { | ||
| 35 | 	const unsigned char *z; | ||
| 36 | 	size_t l, ip, jp, k, p, ms, p0, mem, mem0; | ||
| 37 | 	size_t byteset[32 / sizeof(size_t)] = { 0 }; | ||
| 38 | 	size_t shift[256]; | ||
| 39 | |||
| 40 | 	/* Computing length of needle and fill shift table */ | ||
| 41 | 	for (l=0; n[l] && h[l]; l++) | ||
| 42 | 		BITOP(byteset, n[l], |=), shift[n[l]] = l+1; | ||
| 43 | 	if (n[l]) return 0; /* hit the end of h */ | ||
| 44 | |||
| 45 | 	/* Compute maximal suffix */ | ||
| 46 | 	ip = -1; jp = 0; k = p = 1; | ||
| 47 | 	while (jp+k<l) { | ||
| 48 | 		if (n[ip+k] == n[jp+k]) { | ||
| 49 | 			if (k == p) { | ||
| 50 | 				jp += p; | ||
| 51 | 				k = 1; | ||
| 52 | 			} else k++; | ||
| 53 | 		} else if (n[ip+k] > n[jp+k]) { | ||
| 54 | 			jp += k; | ||
| 55 | 			k = 1; | ||
| 56 | 			p = jp - ip; | ||
| 57 | 		} else { | ||
| 58 | 			ip = jp++; | ||
| 59 | 			k = p = 1; | ||
| 60 | 		} | ||
| 61 | 	} | ||
| 62 | 	ms = ip; | ||
| 63 | 	p0 = p; | ||
| 64 | |||
| 65 | 	/* And with the opposite comparison */ | ||
| 66 | 	ip = -1; jp = 0; k = p = 1; | ||
| 67 | 	while (jp+k<l) { | ||
| 68 | 		if (n[ip+k] == n[jp+k]) { | ||
| 69 | 			if (k == p) { | ||
| 70 | 				jp += p; | ||
| 71 | 				k = 1; | ||
| 72 | 			} else k++; | ||
| 73 | 		} else if (n[ip+k] < n[jp+k]) { | ||
| 74 | 			jp += k; | ||
| 75 | 			k = 1; | ||
| 76 | 			p = jp - ip; | ||
| 77 | 		} else { | ||
| 78 | 			ip = jp++; | ||
| 79 | 			k = p = 1; | ||
| 80 | 		} | ||
| 81 | 	} | ||
| 82 | 	if (ip+1 > ms+1) ms = ip; | ||
| 83 | 	else p = p0; | ||
| 84 | |||
| 85 | 	/* Periodic needle? */ | ||
| 86 | 	if (memcmp(n, n+p, ms+1)) { | ||
| 87 | 		mem0 = 0; | ||
| 88 | 		p = MAX(ms, l-ms-1) + 1; | ||
| 89 | 	} else mem0 = l-p; | ||
| 90 | 	mem = 0; | ||
| 91 | |||
| 92 | 	/* Initialize incremental end-of-haystack pointer */ | ||
| 93 | 	z = h; | ||
| 94 | |||
| 95 | 	/* Search loop */ | ||
| 96 | 	for (;;) { | ||
| 97 | 		/* Update incremental end-of-haystack pointer */ | ||
| 98 | 		if (z-h < l) { | ||
| 99 | 			/* Fast estimate for MAX(l,63) */ | ||
| 100 | 			size_t grow = l | 63; | ||
| 101 | 			const unsigned char *z2 = memchr(z, 0, grow); | ||
| 102 | 			if (z2) { | ||
| 103 | 				z = z2; | ||
| 104 | 				if (z-h < l) return 0; | ||
| 105 | 			} else z += grow; | ||
| 106 | 		} | ||
| 107 | |||
| 108 | 		/* Check last byte first; advance by shift on mismatch */ | ||
| 109 | 		if (BITOP(byteset, h[l-1], &)) { | ||
| 110 | 			k = l-shift[h[l-1]]; | ||
| 111 | 			if (k) { | ||
| 112 | 				if (k < mem) k = mem; | ||
| 113 | 				h += k; | ||
| 114 | 				mem = 0; | ||
| 115 | 				continue; | ||
| 116 | 			} | ||
| 117 | 		} else { | ||
| 118 | 			h += l; | ||
| 119 | 			mem = 0; | ||
| 120 | 			continue; | ||
| 121 | 		} | ||
| 122 | |||
| 123 | 		/* Compare right half */ | ||
| 124 | 		for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); | ||
| 125 | 		if (n[k]) { | ||
| 126 | 			h += k-ms; | ||
| 127 | 			mem = 0; | ||
| 128 | 			continue; | ||
| 129 | 		} | ||
| 130 | 		/* Compare left half */ | ||
| 131 | 		for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); | ||
| 132 | 		if (k <= mem) return (char *)h; | ||
| 133 | 		h += p; | ||
| 134 | 		mem = mem0; | ||
| 135 | 	} | ||
| 136 | } | ||
| 137 | |||
| 138 | char *strstr(const char *h, const char *n) | ||
| 139 | { | ||
| 140 | 	/* Return immediately on empty needle */ | ||
| 141 | 	if (!n[0]) return (char *)h; | ||
| 142 | |||
| 143 | 	/* Use faster algorithms for short needles */ | ||
| 144 | 	h = strchr(h, *n); | ||
| 145 | 	if (!h || !n[1]) return (char *)h; | ||
| 146 | 	if (!h[1]) return 0; | ||
| 147 | 	if (!n[2]) return twobyte_strstr((void *)h, (void *)n); | ||
| 148 | 	if (!h[2]) return 0; | ||
| 149 | 	if (!n[3]) return threebyte_strstr((void *)h, (void *)n); | ||
| 150 | 	if (!h[3]) return 0; | ||
| 151 | 	if (!n[4]) return fourbyte_strstr((void *)h, (void *)n); | ||
| 152 | |||
| 153 | 	return twoway_strstr((void *)h, (void *)n); | ||
| 154 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strtok.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strtok(char *restrict s, const char *restrict sep) | ||
| 4 | { | ||
| 5 | 	static char *p; | ||
| 6 | 	if (!s && !(s = p)) return NULL; | ||
| 7 | 	s += strspn(s, sep); | ||
| 8 | 	if (!*s) return p = 0; | ||
| 9 | 	p = s + strcspn(s, sep); | ||
| 10 | 	if (*p) *p++ = 0; | ||
| 11 | 	else p = 0; | ||
| 12 | 	return s; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strtok_r.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <string.h> | ||
| 2 | |||
| 3 | char *strtok_r(char *restrict s, const char *restrict sep, char **restrict p) | ||
| 4 | { | ||
| 5 | 	if (!s && !(s = *p)) return NULL; | ||
| 6 | 	s += strspn(s, sep); | ||
| 7 | 	if (!*s) return *p = 0; | ||
| 8 | 	*p = s + strcspn(s, sep); | ||
| 9 | 	if (**p) *(*p)++ = 0; | ||
| 10 | 	else *p = 0; | ||
| 11 | 	return s; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/strverscmp.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <ctype.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | int strverscmp(const char *l0, const char *r0) | ||
| 6 | { | ||
| 7 | 	const unsigned char *l = (const void *)l0; | ||
| 8 | 	const unsigned char *r = (const void *)r0; | ||
| 9 | 	size_t i, dp, j; | ||
| 10 | 	int z = 1; | ||
| 11 | |||
| 12 | 	/* Find maximal matching prefix and track its maximal digit | ||
| 13 | 	 * suffix and whether those digits are all zeros. */ | ||
| 14 | 	for (dp=i=0; l[i]==r[i]; i++) { | ||
| 15 | 		int c = l[i]; | ||
| 16 | 		if (!c) return 0; | ||
| 17 | 		if (!isdigit(c)) dp=i+1, z=1; | ||
| 18 | 		else if (c!='0') z=0; | ||
| 19 | 	} | ||
| 20 | |||
| 21 | 	if (l[dp]!='0' && r[dp]!='0') { | ||
| 22 | 		/* If we're not looking at a digit sequence that began | ||
| 23 | 		 * with a zero, longest digit string is greater. */ | ||
| 24 | 		for (j=i; isdigit(l[j]); j++) | ||
| 25 | 			if (!isdigit(r[j])) return 1; | ||
| 26 | 		if (isdigit(r[j])) return -1; | ||
| 27 | 	} else if (z && dp<i && (isdigit(l[i]) || isdigit(r[i]))) { | ||
| 28 | 		/* Otherwise, if common prefix of digit sequence is | ||
| 29 | 		 * all zeros, digits order less than non-digits. */ | ||
| 30 | 		return (unsigned char)(l[i]-'0') - (unsigned char)(r[i]-'0'); | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	return l[i] - r[i]; | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/swab.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | void swab(const void *restrict _src, void *restrict _dest, ssize_t n) | ||
| 4 | { | ||
| 5 | 	const char *src = _src; | ||
| 6 | 	char *dest = _dest; | ||
| 7 | 	for (; n>1; n-=2) { | ||
| 8 | 		dest[0] = src[1]; | ||
| 9 | 		dest[1] = src[0]; | ||
| 10 | 		dest += 2; | ||
| 11 | 		src += 2; | ||
| 12 | 	} | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcpcpy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcpcpy(wchar_t *restrict d, const wchar_t *restrict s) | ||
| 4 | { | ||
| 5 | 	return wcscpy(d, s) + wcslen(s); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcpncpy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcpncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | ||
| 4 | { | ||
| 5 | 	return wcsncpy(d, s, n) + wcsnlen(s, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcscasecmp.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <wctype.h> | ||
| 3 | |||
| 4 | int wcscasecmp(const wchar_t *l, const wchar_t *r) | ||
| 5 | { | ||
| 6 | 	return wcsncasecmp(l, r, -1); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcscasecmp_l.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int wcscasecmp_l(const wchar_t *l, const wchar_t *r, locale_t locale) | ||
| 4 | { | ||
| 5 | 	return wcscasecmp(l, r); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcscat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcscat(wchar_t *restrict dest, const wchar_t *restrict src) | ||
| 4 | { | ||
| 5 | 	wcscpy(dest + wcslen(dest), src); | ||
| 6 | 	return dest; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcschr.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcschr(const wchar_t *s, wchar_t c) | ||
| 4 | { | ||
| 5 | 	if (!c) return (wchar_t *)s + wcslen(s); | ||
| 6 | 	for (; *s && *s != c; s++); | ||
| 7 | 	return *s ? (wchar_t *)s : 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcscmp.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int wcscmp(const wchar_t *l, const wchar_t *r) | ||
| 4 | { | ||
| 5 | 	for (; *l==*r && *l && *r; l++, r++); | ||
| 6 | 	return *l - *r; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcscpy.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcscpy(wchar_t *restrict d, const wchar_t *restrict s) | ||
| 4 | { | ||
| 5 | 	wchar_t *a = d; | ||
| 6 | 	while ((*d++ = *s++)); | ||
| 7 | 	return a; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcscspn.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t wcscspn(const wchar_t *s, const wchar_t *c) | ||
| 4 | { | ||
| 5 | 	const wchar_t *a; | ||
| 6 | 	if (!c[0]) return wcslen(s); | ||
| 7 | 	if (!c[1]) return (s=wcschr(a=s, *c)) ? s-a : wcslen(a); | ||
| 8 | 	for (a=s; *s && !wcschr(c, *s); s++); | ||
| 9 | 	return s-a; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsdup.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <wchar.h> | ||
| 3 | |||
| 4 | wchar_t *wcsdup(const wchar_t *s) | ||
| 5 | { | ||
| 6 | 	size_t l = wcslen(s); | ||
| 7 | 	wchar_t *d = malloc((l+1)*sizeof(wchar_t)); | ||
| 8 | 	if (!d) return NULL; | ||
| 9 | 	return wmemcpy(d, s, l+1); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcslen.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t wcslen(const wchar_t *s) | ||
| 4 | { | ||
| 5 | 	const wchar_t *a; | ||
| 6 | 	for (a=s; *s; s++); | ||
| 7 | 	return s-a; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsncasecmp.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <wctype.h> | ||
| 3 | |||
| 4 | int wcsncasecmp(const wchar_t *l, const wchar_t *r, size_t n) | ||
| 5 | { | ||
| 6 | 	if (!n--) return 0; | ||
| 7 | 	for (; *l && *r && n && (*l == *r || towlower(*l) == towlower(*r)); l++, r++, n--); | ||
| 8 | 	return towlower(*l) - towlower(*r); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsncasecmp_l.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int wcsncasecmp_l(const wchar_t *l, const wchar_t *r, size_t n, locale_t locale) | ||
| 4 | { | ||
| 5 | 	return wcsncasecmp(l, r, n); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsncat.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcsncat(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | ||
| 4 | { | ||
| 5 | 	wchar_t *a = d; | ||
| 6 | 	d += wcslen(d); | ||
| 7 | 	while (n && *s) n--, *d++ = *s++; | ||
| 8 | 	*d++ = 0; | ||
| 9 | 	return a; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsncmp.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int wcsncmp(const wchar_t *l, const wchar_t *r, size_t n) | ||
| 4 | { | ||
| 5 | 	for (; n && *l==*r && *l && *r; n--, l++, r++); | ||
| 6 | 	return n ? *l - *r : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsncpy.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcsncpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | ||
| 4 | { | ||
| 5 | 	wchar_t *a = d; | ||
| 6 | 	while (n && *s) n--, *d++ = *s++; | ||
| 7 | 	wmemset(d, 0, n); | ||
| 8 | 	return a; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsnlen.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t wcsnlen(const wchar_t *s, size_t n) | ||
| 4 | { | ||
| 5 | 	const wchar_t *z = wmemchr(s, 0, n); | ||
| 6 | 	if (z) n = z-s; | ||
| 7 | 	return n; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcspbrk.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcspbrk(const wchar_t *s, const wchar_t *b) | ||
| 4 | { | ||
| 5 | 	s += wcscspn(s, b); | ||
| 6 | 	return *s ? (wchar_t *)s : NULL; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsrchr.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcsrchr(const wchar_t *s, wchar_t c) | ||
| 4 | { | ||
| 5 | 	const wchar_t *p; | ||
| 6 | 	for (p=s+wcslen(s); p>=s && *p!=c; p--); | ||
| 7 | 	return p>=s ? (wchar_t *)p : 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsspn.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | size_t wcsspn(const wchar_t *s, const wchar_t *c) | ||
| 4 | { | ||
| 5 | 	const wchar_t *a; | ||
| 6 | 	for (a=s; *s && wcschr(c, *s); s++); | ||
| 7 | 	return s-a; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcsstr.c created+105| ... | @@ -0,0 +1,105 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | #define MAX(a,b) ((a)>(b)?(a):(b)) | ||
| 4 | #define MIN(a,b) ((a)<(b)?(a):(b)) | ||
| 5 | |||
| 6 | static wchar_t *twoway_wcsstr(const wchar_t *h, const wchar_t *n) | ||
| 7 | { | ||
| 8 | 	const wchar_t *z; | ||
| 9 | 	size_t l, ip, jp, k, p, ms, p0, mem, mem0; | ||
| 10 | |||
| 11 | 	/* Computing length of needle */ | ||
| 12 | 	for (l=0; n[l] && h[l]; l++); | ||
| 13 | 	if (n[l]) return 0; /* hit the end of h */ | ||
| 14 | |||
| 15 | 	/* Compute maximal suffix */ | ||
| 16 | 	ip = -1; jp = 0; k = p = 1; | ||
| 17 | 	while (jp+k<l) { | ||
| 18 | 		if (n[ip+k] == n[jp+k]) { | ||
| 19 | 			if (k == p) { | ||
| 20 | 				jp += p; | ||
| 21 | 				k = 1; | ||
| 22 | 			} else k++; | ||
| 23 | 		} else if (n[ip+k] > n[jp+k]) { | ||
| 24 | 			jp += k; | ||
| 25 | 			k = 1; | ||
| 26 | 			p = jp - ip; | ||
| 27 | 		} else { | ||
| 28 | 			ip = jp++; | ||
| 29 | 			k = p = 1; | ||
| 30 | 		} | ||
| 31 | 	} | ||
| 32 | 	ms = ip; | ||
| 33 | 	p0 = p; | ||
| 34 | |||
| 35 | 	/* And with the opposite comparison */ | ||
| 36 | 	ip = -1; jp = 0; k = p = 1; | ||
| 37 | 	while (jp+k<l) { | ||
| 38 | 		if (n[ip+k] == n[jp+k]) { | ||
| 39 | 			if (k == p) { | ||
| 40 | 				jp += p; | ||
| 41 | 				k = 1; | ||
| 42 | 			} else k++; | ||
| 43 | 		} else if (n[ip+k] < n[jp+k]) { | ||
| 44 | 			jp += k; | ||
| 45 | 			k = 1; | ||
| 46 | 			p = jp - ip; | ||
| 47 | 		} else { | ||
| 48 | 			ip = jp++; | ||
| 49 | 			k = p = 1; | ||
| 50 | 		} | ||
| 51 | 	} | ||
| 52 | 	if (ip+1 > ms+1) ms = ip; | ||
| 53 | 	else p = p0; | ||
| 54 | |||
| 55 | 	/* Periodic needle? */ | ||
| 56 | 	if (wmemcmp(n, n+p, ms+1)) { | ||
| 57 | 		mem0 = 0; | ||
| 58 | 		p = MAX(ms, l-ms-1) + 1; | ||
| 59 | 	} else mem0 = l-p; | ||
| 60 | 	mem = 0; | ||
| 61 | |||
| 62 | 	/* Initialize incremental end-of-haystack pointer */ | ||
| 63 | 	z = h; | ||
| 64 | |||
| 65 | 	/* Search loop */ | ||
| 66 | 	for (;;) { | ||
| 67 | 		/* Update incremental end-of-haystack pointer */ | ||
| 68 | 		if (z-h < l) { | ||
| 69 | 			/* Fast estimate for MIN(l,63) */ | ||
| 70 | 			size_t grow = l | 63; | ||
| 71 | 			const wchar_t *z2 = wmemchr(z, 0, grow); | ||
| 72 | 			if (z2) { | ||
| 73 | 				z = z2; | ||
| 74 | 				if (z-h < l) return 0; | ||
| 75 | 			} else z += grow; | ||
| 76 | 		} | ||
| 77 | |||
| 78 | 		/* Compare right half */ | ||
| 79 | 		for (k=MAX(ms+1,mem); n[k] && n[k] == h[k]; k++); | ||
| 80 | 		if (n[k]) { | ||
| 81 | 			h += k-ms; | ||
| 82 | 			mem = 0; | ||
| 83 | 			continue; | ||
| 84 | 		} | ||
| 85 | 		/* Compare left half */ | ||
| 86 | 		for (k=ms+1; k>mem && n[k-1] == h[k-1]; k--); | ||
| 87 | 		if (k <= mem) return (wchar_t *)h; | ||
| 88 | 		h += p; | ||
| 89 | 		mem = mem0; | ||
| 90 | 	} | ||
| 91 | } | ||
| 92 | |||
| 93 | wchar_t *wcsstr(const wchar_t *restrict h, const wchar_t *restrict n) | ||
| 94 | { | ||
| 95 | 	/* Return immediately on empty needle or haystack */ | ||
| 96 | 	if (!n[0]) return (wchar_t *)h; | ||
| 97 | 	if (!h[0]) return 0; | ||
| 98 | |||
| 99 | 	/* Use faster algorithms for short needles */ | ||
| 100 | 	h = wcschr(h, *n); | ||
| 101 | 	if (!h || !n[1]) return (wchar_t *)h; | ||
| 102 | 	if (!h[1]) return 0; | ||
| 103 | |||
| 104 | 	return twoway_wcsstr(h, n); | ||
| 105 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcstok.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcstok(wchar_t *restrict s, const wchar_t *restrict sep, wchar_t **restrict p) | ||
| 4 | { | ||
| 5 | 	if (!s && !(s = *p)) return NULL; | ||
| 6 | 	s += wcsspn(s, sep); | ||
| 7 | 	if (!*s) return *p = 0; | ||
| 8 | 	*p = s + wcscspn(s, sep); | ||
| 9 | 	if (**p) *(*p)++ = 0; | ||
| 10 | 	else *p = 0; | ||
| 11 | 	return s; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wcswcs.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wcswcs(const wchar_t *haystack, const wchar_t *needle) | ||
| 4 | { | ||
| 5 | 	return wcsstr(haystack, needle); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wmemchr.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wmemchr(const wchar_t *s, wchar_t c, size_t n) | ||
| 4 | { | ||
| 5 | 	for (; n && *s != c; n--, s++); | ||
| 6 | 	return n ? (wchar_t *)s : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wmemcmp.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | int wmemcmp(const wchar_t *l, const wchar_t *r, size_t n) | ||
| 4 | { | ||
| 5 | 	for (; n && *l==*r; n--, l++, r++); | ||
| 6 | 	return n ? *l-*r : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wmemcpy.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wmemcpy(wchar_t *restrict d, const wchar_t *restrict s, size_t n) | ||
| 4 | { | ||
| 5 | 	wchar_t *a = d; | ||
| 6 | 	while (n--) *d++ = *s++; | ||
| 7 | 	return a; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wmemmove.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | wchar_t *wmemmove(wchar_t *d, const wchar_t *s, size_t n) | ||
| 5 | { | ||
| 6 | 	wchar_t *d0 = d; | ||
| 7 | 	if (d == s) return d; | ||
| 8 | 	if ((uintptr_t)d-(uintptr_t)s < n * sizeof *d) | ||
| 9 | 		while (n--) d[n] = s[n]; | ||
| 10 | 	else | ||
| 11 | 		while (n--) *d++ = *s++; | ||
| 12 | 	return d0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/wmemset.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <wchar.h> | ||
| 2 | |||
| 3 | wchar_t *wmemset(wchar_t *d, wchar_t c, size_t n) | ||
| 4 | { | ||
| 5 | 	wchar_t *ret = d; | ||
| 6 | 	while (n--) *d++ = c; | ||
| 7 | 	return ret; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memcpy.s created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | .global memcpy | ||
| 2 | .global __memcpy_fwd | ||
| 3 | .hidden __memcpy_fwd | ||
| 4 | .type memcpy,@function | ||
| 5 | memcpy: | ||
| 6 | __memcpy_fwd: | ||
| 7 | 	mov %rdi,%rax | ||
| 8 | 	cmp $8,%rdx | ||
| 9 | 	jc 1f | ||
| 10 | 	test $7,%edi | ||
| 11 | 	jz 1f | ||
| 12 | 2:	movsb | ||
| 13 | 	dec %rdx | ||
| 14 | 	test $7,%edi | ||
| 15 | 	jnz 2b | ||
| 16 | 1:	mov %rdx,%rcx | ||
| 17 | 	shr $3,%rcx | ||
| 18 | 	rep | ||
| 19 | 	movsq | ||
| 20 | 	and $7,%edx | ||
| 21 | 	jz 1f | ||
| 22 | 2:	movsb | ||
| 23 | 	dec %edx | ||
| 24 | 	jnz 2b | ||
| 25 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memmove.s created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | .global memmove | ||
| 2 | .type memmove,@function | ||
| 3 | memmove: | ||
| 4 | 	mov %rdi,%rax | ||
| 5 | 	sub %rsi,%rax | ||
| 6 | 	cmp %rdx,%rax | ||
| 7 | .hidden __memcpy_fwd | ||
| 8 | 	jae __memcpy_fwd | ||
| 9 | 	mov %rdx,%rcx | ||
| 10 | 	lea -1(%rdi,%rdx),%rdi | ||
| 11 | 	lea -1(%rsi,%rdx),%rsi | ||
| 12 | 	std | ||
| 13 | 	rep movsb | ||
| 14 | 	cld | ||
| 15 | 	lea 1(%rdi),%rax | ||
| 16 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/string/x86_64/memset.s created+72| ... | @@ -0,0 +1,72 @@ | ||
| 1 | .global memset | ||
| 2 | .type memset,@function | ||
| 3 | memset: | ||
| 4 | 	movzbq %sil,%rax | ||
| 5 | 	mov $0x101010101010101,%r8 | ||
| 6 | 	imul %r8,%rax | ||
| 7 | |||
| 8 | 	cmp $126,%rdx | ||
| 9 | 	ja 2f | ||
| 10 | |||
| 11 | 	test %edx,%edx | ||
| 12 | 	jz 1f | ||
| 13 | |||
| 14 | 	mov %sil,(%rdi) | ||
| 15 | 	mov %sil,-1(%rdi,%rdx) | ||
| 16 | 	cmp $2,%edx | ||
| 17 | 	jbe 1f | ||
| 18 | |||
| 19 | 	mov %ax,1(%rdi) | ||
| 20 | 	mov %ax,(-1-2)(%rdi,%rdx) | ||
| 21 | 	cmp $6,%edx | ||
| 22 | 	jbe 1f | ||
| 23 | |||
| 24 | 	mov %eax,(1+2)(%rdi) | ||
| 25 | 	mov %eax,(-1-2-4)(%rdi,%rdx) | ||
| 26 | 	cmp $14,%edx | ||
| 27 | 	jbe 1f | ||
| 28 | |||
| 29 | 	mov %rax,(1+2+4)(%rdi) | ||
| 30 | 	mov %rax,(-1-2-4-8)(%rdi,%rdx) | ||
| 31 | 	cmp $30,%edx | ||
| 32 | 	jbe 1f | ||
| 33 | |||
| 34 | 	mov %rax,(1+2+4+8)(%rdi) | ||
| 35 | 	mov %rax,(1+2+4+8+8)(%rdi) | ||
| 36 | 	mov %rax,(-1-2-4-8-16)(%rdi,%rdx) | ||
| 37 | 	mov %rax,(-1-2-4-8-8)(%rdi,%rdx) | ||
| 38 | 	cmp $62,%edx | ||
| 39 | 	jbe 1f | ||
| 40 | |||
| 41 | 	mov %rax,(1+2+4+8+16)(%rdi) | ||
| 42 | 	mov %rax,(1+2+4+8+16+8)(%rdi) | ||
| 43 | 	mov %rax,(1+2+4+8+16+16)(%rdi) | ||
| 44 | 	mov %rax,(1+2+4+8+16+24)(%rdi) | ||
| 45 | 	mov %rax,(-1-2-4-8-16-32)(%rdi,%rdx) | ||
| 46 | 	mov %rax,(-1-2-4-8-16-24)(%rdi,%rdx) | ||
| 47 | 	mov %rax,(-1-2-4-8-16-16)(%rdi,%rdx) | ||
| 48 | 	mov %rax,(-1-2-4-8-16-8)(%rdi,%rdx) | ||
| 49 | |||
| 50 | 1:	mov %rdi,%rax | ||
| 51 | 	ret | ||
| 52 | |||
| 53 | 2:	test $15,%edi | ||
| 54 | 	mov %rdi,%r8 | ||
| 55 | 	mov %rax,-8(%rdi,%rdx) | ||
| 56 | 	mov %rdx,%rcx | ||
| 57 | 	jnz 2f | ||
| 58 | |||
| 59 | 1:	shr $3,%rcx | ||
| 60 | 	rep | ||
| 61 | 	stosq | ||
| 62 | 	mov %r8,%rax | ||
| 63 | 	ret | ||
| 64 | |||
| 65 | 2:	xor %edx,%edx | ||
| 66 | 	sub %edi,%edx | ||
| 67 | 	and $15,%edx | ||
| 68 | 	mov %rax,(%rdi) | ||
| 69 | 	mov %rax,8(%rdi) | ||
| 70 | 	sub %rdx,%rcx | ||
| 71 | 	add %rdx,%rdi | ||
| 72 | 	jmp 1b | ||
lib/libc/wasi/libc-top-half/musl/src/temp/__randname.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <stdint.h> | ||
| 3 | |||
| 4 | /* This assumes that a check for the | ||
| 5 | template size has already been made */ | ||
| 6 | char *__randname(char *template) | ||
| 7 | { | ||
| 8 | 	int i; | ||
| 9 | 	struct timespec ts; | ||
| 10 | 	unsigned long r; | ||
| 11 | |||
| 12 | 	__clock_gettime(CLOCK_REALTIME, &ts); | ||
| 13 | 	r = ts.tv_nsec*65537 ^ (uintptr_t)&ts / 16 + (uintptr_t)template; | ||
| 14 | 	for (i=0; i<6; i++, r>>=5) | ||
| 15 | 		template[i] = 'A'+(r&15)+(r&16)*2; | ||
| 16 | |||
| 17 | 	return template; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/temp/mkdtemp.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <string.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <sys/stat.h> | ||
| 5 | |||
| 6 | char *mkdtemp(char *template) | ||
| 7 | { | ||
| 8 | 	size_t l = strlen(template); | ||
| 9 | 	int retries = 100; | ||
| 10 | |||
| 11 | 	if (l<6 || memcmp(template+l-6, "XXXXXX", 6)) { | ||
| 12 | 		errno = EINVAL; | ||
| 13 | 		return 0; | ||
| 14 | 	} | ||
| 15 | |||
| 16 | 	do { | ||
| 17 | 		__randname(template+l-6); | ||
| 18 | 		if (!mkdir(template, 0700)) return template; | ||
| 19 | 	} while (--retries && errno == EEXIST); | ||
| 20 | |||
| 21 | 	memcpy(template+l-6, "XXXXXX", 6); | ||
| 22 | 	return 0; | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/temp/mkostemp.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | int mkostemp(char *template, int flags) | ||
| 5 | { | ||
| 6 | 	return __mkostemps(template, 0, flags); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(mkostemp, mkostemp64); | ||
lib/libc/wasi/libc-top-half/musl/src/temp/mkostemps.c created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <errno.h> | ||
| 7 | |||
| 8 | int __mkostemps(char *template, int len, int flags) | ||
| 9 | { | ||
| 10 | 	size_t l = strlen(template); | ||
| 11 | 	if (l<6 || len>l-6 || memcmp(template+l-len-6, "XXXXXX", 6)) { | ||
| 12 | 		errno = EINVAL; | ||
| 13 | 		return -1; | ||
| 14 | 	} | ||
| 15 | |||
| 16 | 	flags -= flags & O_ACCMODE; | ||
| 17 | 	int fd, retries = 100; | ||
| 18 | 	do { | ||
| 19 | 		__randname(template+l-len-6); | ||
| 20 | 		if ((fd = open(template, flags | O_RDWR | O_CREAT | O_EXCL, 0600))>=0) | ||
| 21 | 			return fd; | ||
| 22 | 	} while (--retries && errno == EEXIST); | ||
| 23 | |||
| 24 | 	memcpy(template+l-len-6, "XXXXXX", 6); | ||
| 25 | 	return -1; | ||
| 26 | } | ||
| 27 | |||
| 28 | weak_alias(__mkostemps, mkostemps); | ||
| 29 | weak_alias(__mkostemps, mkostemps64); | ||
lib/libc/wasi/libc-top-half/musl/src/temp/mkstemp.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | |||
| 3 | int mkstemp(char *template) | ||
| 4 | { | ||
| 5 | 	return __mkostemps(template, 0, 0); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(mkstemp, mkstemp64); | ||
lib/libc/wasi/libc-top-half/musl/src/temp/mkstemps.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | int mkstemps(char *template, int len) | ||
| 5 | { | ||
| 6 | 	return __mkostemps(template, len, 0); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(mkstemps, mkstemps64); | ||
lib/libc/wasi/libc-top-half/musl/src/temp/mktemp.c created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include <stdlib.h> | ||
| 4 | #include <errno.h> | ||
| 5 | #include <sys/stat.h> | ||
| 6 | |||
| 7 | char *mktemp(char *template) | ||
| 8 | { | ||
| 9 | 	size_t l = strlen(template); | ||
| 10 | 	int retries = 100; | ||
| 11 | 	struct stat st; | ||
| 12 | |||
| 13 | 	if (l < 6 || memcmp(template+l-6, "XXXXXX", 6)) { | ||
| 14 | 		errno = EINVAL; | ||
| 15 | 		*template = 0; | ||
| 16 | 		return template; | ||
| 17 | 	} | ||
| 18 | |||
| 19 | 	do { | ||
| 20 | 		__randname(template+l-6); | ||
| 21 | 		if (stat(template, &st)) { | ||
| 22 | 			if (errno != ENOENT) *template = 0; | ||
| 23 | 			return template; | ||
| 24 | 		} | ||
| 25 | 	} while (--retries); | ||
| 26 | |||
| 27 | 	*template = 0; | ||
| 28 | 	errno = EEXIST; | ||
| 29 | 	return template; | ||
| 30 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/cfgetospeed.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <termios.h> | ||
| 3 | #include <sys/ioctl.h> | ||
| 4 | |||
| 5 | speed_t cfgetospeed(const struct termios *tio) | ||
| 6 | { | ||
| 7 | 	return tio->c_cflag & CBAUD; | ||
| 8 | } | ||
| 9 | |||
| 10 | speed_t cfgetispeed(const struct termios *tio) | ||
| 11 | { | ||
| 12 | 	return cfgetospeed(tio); | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/cfmakeraw.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <termios.h> | ||
| 3 | |||
| 4 | void cfmakeraw(struct termios *t) | ||
| 5 | { | ||
| 6 | 	t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|ISTRIP|INLCR|IGNCR|ICRNL|IXON); | ||
| 7 | 	t->c_oflag &= ~OPOST; | ||
| 8 | 	t->c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN); | ||
| 9 | 	t->c_cflag &= ~(CSIZE|PARENB); | ||
| 10 | 	t->c_cflag |= CS8; | ||
| 11 | 	t->c_cc[VMIN] = 1; | ||
| 12 | 	t->c_cc[VTIME] = 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/cfsetospeed.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <termios.h> | ||
| 3 | #include <sys/ioctl.h> | ||
| 4 | #include <errno.h> | ||
| 5 | |||
| 6 | int cfsetospeed(struct termios *tio, speed_t speed) | ||
| 7 | { | ||
| 8 | 	if (speed & ~CBAUD) { | ||
| 9 | 		errno = EINVAL; | ||
| 10 | 		return -1; | ||
| 11 | 	} | ||
| 12 | 	tio->c_cflag &= ~CBAUD; | ||
| 13 | 	tio->c_cflag |= speed; | ||
| 14 | 	return 0; | ||
| 15 | } | ||
| 16 | |||
| 17 | int cfsetispeed(struct termios *tio, speed_t speed) | ||
| 18 | { | ||
| 19 | 	return speed ? cfsetospeed(tio, speed) : 0; | ||
| 20 | } | ||
| 21 | |||
| 22 | weak_alias(cfsetospeed, cfsetspeed); | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcdrain.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int tcdrain(int fd) | ||
| 6 | { | ||
| 7 | 	return syscall_cp(SYS_ioctl, fd, TCSBRK, 1); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcflow.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | |||
| 4 | int tcflow(int fd, int action) | ||
| 5 | { | ||
| 6 | 	return ioctl(fd, TCXONC, action); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcflush.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | |||
| 4 | int tcflush(int fd, int queue) | ||
| 5 | { | ||
| 6 | 	return ioctl(fd, TCFLSH, queue); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetattr.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | |||
| 4 | int tcgetattr(int fd, struct termios *tio) | ||
| 5 | { | ||
| 6 | 	if (ioctl(fd, TCGETS, tio)) | ||
| 7 | 		return -1; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetsid.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | |||
| 4 | pid_t tcgetsid(int fd) | ||
| 5 | { | ||
| 6 | 	int sid; | ||
| 7 | 	if (ioctl(fd, TIOCGSID, &sid) < 0) | ||
| 8 | 		return -1; | ||
| 9 | 	return sid; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcgetwinsize.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int tcgetwinsize(int fd, struct winsize *wsz) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_ioctl, fd, TIOCGWINSZ, wsz); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcsendbreak.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | |||
| 4 | int tcsendbreak(int fd, int dur) | ||
| 5 | { | ||
| 6 | 	/* nonzero duration is implementation-defined, so ignore it */ | ||
| 7 | 	return ioctl(fd, TCSBRK, 0); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcsetattr.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int tcsetattr(int fd, int act, const struct termios *tio) | ||
| 6 | { | ||
| 7 | 	if (act < 0 || act > 2) { | ||
| 8 | 		errno = EINVAL; | ||
| 9 | 		return -1; | ||
| 10 | 	} | ||
| 11 | 	return ioctl(fd, TCSETS+act, tio); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/termios/tcsetwinsize.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <termios.h> | ||
| 2 | #include <sys/ioctl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int tcsetwinsize(int fd, const struct winsize *wsz) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_ioctl, fd, TIOCSWINSZ, wsz); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__lock.c created+62| ... | @@ -0,0 +1,62 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | /* This lock primitive combines a flag (in the sign bit) and a | ||
| 4 | * congestion count (= threads inside the critical section, CS) in a | ||
| 5 | * single int that is accessed through atomic operations. The states | ||
| 6 | * of the int for value x are: | ||
| 7 | * | ||
| 8 | * x == 0: unlocked and no thread inside the critical section | ||
| 9 | * | ||
| 10 | * x < 0: locked with a congestion of x-INT_MIN, including the thread | ||
| 11 | * that holds the lock | ||
| 12 | * | ||
| 13 | * x > 0: unlocked with a congestion of x | ||
| 14 | * | ||
| 15 | * or in an equivalent formulation x is the congestion count or'ed | ||
| 16 | * with INT_MIN as a lock flag. | ||
| 17 | */ | ||
| 18 | |||
| 19 | void __lock(volatile int *l) | ||
| 20 | { | ||
| 21 | 	int need_locks = libc.need_locks; | ||
| 22 | 	if (!need_locks) return; | ||
| 23 | 	/* fast path: INT_MIN for the lock, +1 for the congestion */ | ||
| 24 | 	int current = a_cas(l, 0, INT_MIN + 1); | ||
| 25 | 	if (need_locks < 0) libc.need_locks = 0; | ||
| 26 | 	if (!current) return; | ||
| 27 | 	/* A first spin loop, for medium congestion. */ | ||
| 28 | 	for (unsigned i = 0; i < 10; ++i) { | ||
| 29 | 		if (current < 0) current -= INT_MIN + 1; | ||
| 30 | 		// assertion: current >= 0 | ||
| 31 | 		int val = a_cas(l, current, INT_MIN + (current + 1)); | ||
| 32 | 		if (val == current) return; | ||
| 33 | 		current = val; | ||
| 34 | 	} | ||
| 35 | 	// Spinning failed, so mark ourselves as being inside the CS. | ||
| 36 | 	current = a_fetch_add(l, 1) + 1; | ||
| 37 | 	/* The main lock acquisition loop for heavy congestion. The only | ||
| 38 | 	 * change to the value performed inside that loop is a successful | ||
| 39 | 	 * lock via the CAS that acquires the lock. */ | ||
| 40 | 	for (;;) { | ||
| 41 | 		/* We can only go into wait, if we know that somebody holds the | ||
| 42 | 		 * lock and will eventually wake us up, again. */ | ||
| 43 | 		if (current < 0) { | ||
| 44 | 			__futexwait(l, current, 1); | ||
| 45 | 			current -= INT_MIN + 1; | ||
| 46 | 		} | ||
| 47 | 		/* assertion: current > 0, the count includes us already. */ | ||
| 48 | 		int val = a_cas(l, current, INT_MIN + current); | ||
| 49 | 		if (val == current) return; | ||
| 50 | 		current = val; | ||
| 51 | 	} | ||
| 52 | } | ||
| 53 | |||
| 54 | void __unlock(volatile int *l) | ||
| 55 | { | ||
| 56 | 	/* Check l[0] to see if we are multi-threaded. */ | ||
| 57 | 	if (l[0] < 0) { | ||
| 58 | 		if (a_fetch_add(l, -(INT_MIN + 1)) != (INT_MIN + 1)) { | ||
| 59 | 			__wake(l, 1, 1); | ||
| 60 | 		} | ||
| 61 | 	} | ||
| 62 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__set_thread_area.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __set_thread_area(void *p) | ||
| 4 | { | ||
| 5 | #ifdef SYS_set_thread_area | ||
| 6 | 	return __syscall(SYS_set_thread_area, p); | ||
| 7 | #else | ||
| 8 | 	return -ENOSYS; | ||
| 9 | #endif | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__syscall_cp.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | hidden long __syscall_cp_c(); | ||
| 5 | |||
| 6 | static long sccp(syscall_arg_t nr, | ||
| 7 | syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, | ||
| 8 | syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) | ||
| 9 | { | ||
| 10 | 	return __syscall(nr, u, v, w, x, y, z); | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(sccp, __syscall_cp_c); | ||
| 14 | |||
| 15 | long (__syscall_cp)(syscall_arg_t nr, | ||
| 16 | syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, | ||
| 17 | syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) | ||
| 18 | { | ||
| 19 | 	return __syscall_cp_c(nr, u, v, w, x, y, z); | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__timedwait.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "futex.h" | ||
| 5 | #include "syscall.h" | ||
| 6 | #include "pthread_impl.h" | ||
| 7 | |||
| 8 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 9 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 10 | |||
| 11 | static int __futex4_cp(volatile void *addr, int op, int val, const struct timespec *to) | ||
| 12 | { | ||
| 13 | 	int r; | ||
| 14 | #ifdef SYS_futex_time64 | ||
| 15 | 	time_t s = to ? to->tv_sec : 0; | ||
| 16 | 	long ns = to ? to->tv_nsec : 0; | ||
| 17 | 	r = -ENOSYS; | ||
| 18 | 	if (SYS_futex == SYS_futex_time64 || !IS32BIT(s)) | ||
| 19 | 		r = __syscall_cp(SYS_futex_time64, addr, op, val, | ||
| 20 | 			to ? ((long long[]){s, ns}) : 0); | ||
| 21 | 	if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r; | ||
| 22 | 	to = to ? (void *)(long[]){CLAMP(s), ns} : 0; | ||
| 23 | #endif | ||
| 24 | 	r = __syscall_cp(SYS_futex, addr, op, val, to); | ||
| 25 | 	if (r != -ENOSYS) return r; | ||
| 26 | 	return __syscall_cp(SYS_futex, addr, op & ~FUTEX_PRIVATE, val, to); | ||
| 27 | } | ||
| 28 | |||
| 29 | static volatile int dummy = 0; | ||
| 30 | weak_alias(dummy, __eintr_valid_flag); | ||
| 31 | |||
| 32 | int __timedwait_cp(volatile int *addr, int val, | ||
| 33 | 	clockid_t clk, const struct timespec *at, int priv) | ||
| 34 | { | ||
| 35 | 	int r; | ||
| 36 | 	struct timespec to, *top=0; | ||
| 37 | |||
| 38 | 	if (priv) priv = FUTEX_PRIVATE; | ||
| 39 | |||
| 40 | 	if (at) { | ||
| 41 | 		if (at->tv_nsec >= 1000000000UL) return EINVAL; | ||
| 42 | 		if (__clock_gettime(clk, &to)) return EINVAL; | ||
| 43 | 		to.tv_sec = at->tv_sec - to.tv_sec; | ||
| 44 | 		if ((to.tv_nsec = at->tv_nsec - to.tv_nsec) < 0) { | ||
| 45 | 			to.tv_sec--; | ||
| 46 | 			to.tv_nsec += 1000000000; | ||
| 47 | 		} | ||
| 48 | 		if (to.tv_sec < 0) return ETIMEDOUT; | ||
| 49 | 		top = &to; | ||
| 50 | 	} | ||
| 51 | |||
| 52 | 	r = -__futex4_cp(addr, FUTEX_WAIT|priv, val, top); | ||
| 53 | 	if (r != EINTR && r != ETIMEDOUT && r != ECANCELED) r = 0; | ||
| 54 | 	/* Mitigate bug in old kernels wrongly reporting EINTR for non- | ||
| 55 | 	 * interrupting (SA_RESTART) signal handlers. This is only practical | ||
| 56 | 	 * when NO interrupting signal handlers have been installed, and | ||
| 57 | 	 * works by sigaction tracking whether that's the case. */ | ||
| 58 | 	if (r == EINTR && !__eintr_valid_flag) r = 0; | ||
| 59 | |||
| 60 | 	return r; | ||
| 61 | } | ||
| 62 | |||
| 63 | int __timedwait(volatile int *addr, int val, | ||
| 64 | 	clockid_t clk, const struct timespec *at, int priv) | ||
| 65 | { | ||
| 66 | 	int cs, r; | ||
| 67 | 	__pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 68 | 	r = __timedwait_cp(addr, val, clk, at, priv); | ||
| 69 | 	__pthread_setcancelstate(cs, 0); | ||
| 70 | 	return r; | ||
| 71 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__tls_get_addr.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | void *__tls_get_addr(tls_mod_off_t *v) | ||
| 4 | { | ||
| 5 | 	pthread_t self = __pthread_self(); | ||
| 6 | 	return (void *)(self->dtv[v[0]] + v[1]); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__unmapself.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "atomic.h" | ||
| 3 | #include "syscall.h" | ||
| 4 | /* cheat and reuse CRTJMP macro from dynlink code */ | ||
| 5 | #include "dynlink.h" | ||
| 6 | |||
| 7 | static void *unmap_base; | ||
| 8 | static size_t unmap_size; | ||
| 9 | static char shared_stack[256]; | ||
| 10 | |||
| 11 | static void do_unmap() | ||
| 12 | { | ||
| 13 | 	__syscall(SYS_munmap, unmap_base, unmap_size); | ||
| 14 | 	__syscall(SYS_exit); | ||
| 15 | } | ||
| 16 | |||
| 17 | void __unmapself(void *base, size_t size) | ||
| 18 | { | ||
| 19 | 	char *stack = shared_stack + sizeof shared_stack; | ||
| 20 | 	stack -= (uintptr_t)stack % 16; | ||
| 21 | 	unmap_base = base; | ||
| 22 | 	unmap_size = size; | ||
| 23 | 	CRTJMP(do_unmap, stack); | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/__wait.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | void __wait(volatile int *addr, volatile int *waiters, int val, int priv) | ||
| 4 | { | ||
| 5 | 	int spins=100; | ||
| 6 | 	if (priv) priv = FUTEX_PRIVATE; | ||
| 7 | 	while (spins-- && (!waiters || !*waiters)) { | ||
| 8 | 		if (*addr==val) a_spin(); | ||
| 9 | 		else return; | ||
| 10 | 	} | ||
| 11 | 	if (waiters) a_inc(waiters); | ||
| 12 | 	while (*addr==val) { | ||
| 13 | 		__syscall(SYS_futex, addr, FUTEX_WAIT|priv, val, 0) != -ENOSYS | ||
| 14 | 		|| __syscall(SYS_futex, addr, FUTEX_WAIT, val, 0); | ||
| 15 | 	} | ||
| 16 | 	if (waiters) a_dec(waiters); | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/__set_thread_area.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global __set_thread_area | ||
| 2 | .hidden __set_thread_area | ||
| 3 | .type __set_thread_area,@function | ||
| 4 | __set_thread_area: | ||
| 5 | 	msr tpidr_el0,x0 | ||
| 6 | 	mov w0,#0 | ||
| 7 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/__unmapself.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global __unmapself | ||
| 2 | .type __unmapself,%function | ||
| 3 | __unmapself: | ||
| 4 | 	mov x8,#215 // SYS_munmap | ||
| 5 | 	svc 0 | ||
| 6 | 	mov x8,#93 // SYS_exit | ||
| 7 | 	svc 0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/clone.s created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | // __clone(func, stack, flags, arg, ptid, tls, ctid) | ||
| 2 | // x0, x1, w2, x3, x4, x5, x6 | ||
| 3 | |||
| 4 | // syscall(SYS_clone, flags, stack, ptid, tls, ctid) | ||
| 5 | // x8, x0, x1, x2, x3, x4 | ||
| 6 | |||
| 7 | .global __clone | ||
| 8 | .hidden __clone | ||
| 9 | .type __clone,%function | ||
| 10 | __clone: | ||
| 11 | 	// align stack and save func,arg | ||
| 12 | 	and x1,x1,#-16 | ||
| 13 | 	stp x0,x3,[x1,#-16]! | ||
| 14 | |||
| 15 | 	// syscall | ||
| 16 | 	uxtw x0,w2 | ||
| 17 | 	mov x2,x4 | ||
| 18 | 	mov x3,x5 | ||
| 19 | 	mov x4,x6 | ||
| 20 | 	mov x8,#220 // SYS_clone | ||
| 21 | 	svc #0 | ||
| 22 | |||
| 23 | 	cbz x0,1f | ||
| 24 | 	// parent | ||
| 25 | 	ret | ||
| 26 | 	// child | ||
| 27 | 1:	ldp x1,x0,[sp],#16 | ||
| 28 | 	blr x1 | ||
| 29 | 	mov x8,#93 // SYS_exit | ||
| 30 | 	svc #0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/aarch64/syscall_cp.s created+32| ... | @@ -0,0 +1,32 @@ | ||
| 1 | // __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z) | ||
| 2 | // x0 x1 x2 x3 x4 x5 x6 x7 | ||
| 3 | |||
| 4 | // syscall(nr, u, v, w, x, y, z) | ||
| 5 | // x8 x0 x1 x2 x3 x4 x5 | ||
| 6 | |||
| 7 | .global __cp_begin | ||
| 8 | .hidden __cp_begin | ||
| 9 | .global __cp_end | ||
| 10 | .hidden __cp_end | ||
| 11 | .global __cp_cancel | ||
| 12 | .hidden __cp_cancel | ||
| 13 | .hidden __cancel | ||
| 14 | .global __syscall_cp_asm | ||
| 15 | .hidden __syscall_cp_asm | ||
| 16 | .type __syscall_cp_asm,%function | ||
| 17 | __syscall_cp_asm: | ||
| 18 | __cp_begin: | ||
| 19 | 	ldr w0,[x0] | ||
| 20 | 	cbnz w0,__cp_cancel | ||
| 21 | 	mov x8,x1 | ||
| 22 | 	mov x0,x2 | ||
| 23 | 	mov x1,x3 | ||
| 24 | 	mov x2,x4 | ||
| 25 | 	mov x3,x5 | ||
| 26 | 	mov x4,x6 | ||
| 27 | 	mov x5,x7 | ||
| 28 | 	svc 0 | ||
| 29 | __cp_end: | ||
| 30 | 	ret | ||
| 31 | __cp_cancel: | ||
| 32 | 	b __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__aeabi_read_tp.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .syntax unified | ||
| 2 | .global __aeabi_read_tp | ||
| 3 | .type __aeabi_read_tp,%function | ||
| 4 | __aeabi_read_tp: | ||
| 5 | 	ldr r0,1f | ||
| 6 | 	add r0,r0,pc | ||
| 7 | 	ldr r0,[r0] | ||
| 8 | 2:	bx r0 | ||
| 9 | 	.align 2 | ||
| 10 | 1:	.word __a_gettp_ptr - 2b | ||
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__set_thread_area.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <elf.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | #include "libc.h" | ||
| 5 | |||
| 6 | #define HWCAP_TLS (1 << 15) | ||
| 7 | |||
| 8 | extern hidden const unsigned char | ||
| 9 | 	__a_barrier_oldkuser[], __a_barrier_v6[], __a_barrier_v7[], | ||
| 10 | 	__a_cas_v6[], __a_cas_v7[], | ||
| 11 | 	__a_gettp_cp15[]; | ||
| 12 | |||
| 13 | #define __a_barrier_kuser 0xffff0fa0 | ||
| 14 | #define __a_barrier_oldkuser (uintptr_t)__a_barrier_oldkuser | ||
| 15 | #define __a_barrier_v6 (uintptr_t)__a_barrier_v6 | ||
| 16 | #define __a_barrier_v7 (uintptr_t)__a_barrier_v7 | ||
| 17 | |||
| 18 | #define __a_cas_kuser 0xffff0fc0 | ||
| 19 | #define __a_cas_v6 (uintptr_t)__a_cas_v6 | ||
| 20 | #define __a_cas_v7 (uintptr_t)__a_cas_v7 | ||
| 21 | |||
| 22 | #define __a_gettp_kuser 0xffff0fe0 | ||
| 23 | #define __a_gettp_cp15 (uintptr_t)__a_gettp_cp15 | ||
| 24 | |||
| 25 | extern hidden uintptr_t __a_barrier_ptr, __a_cas_ptr, __a_gettp_ptr; | ||
| 26 | |||
| 27 | int __set_thread_area(void *p) | ||
| 28 | { | ||
| 29 | #if !__ARM_ARCH_7A__ && !__ARM_ARCH_7R__ && __ARM_ARCH < 7 | ||
| 30 | 	if (__hwcap & HWCAP_TLS) { | ||
| 31 | 		size_t *aux; | ||
| 32 | 		__a_cas_ptr = __a_cas_v7; | ||
| 33 | 		__a_barrier_ptr = __a_barrier_v7; | ||
| 34 | 		for (aux=libc.auxv; *aux; aux+=2) { | ||
| 35 | 			if (*aux != AT_PLATFORM) continue; | ||
| 36 | 			const char *s = (void *)aux[1]; | ||
| 37 | 			if (s[0]!='v' || s[1]!='6' || s[2]-'0'<10u) break; | ||
| 38 | 			__a_cas_ptr = __a_cas_v6; | ||
| 39 | 			__a_barrier_ptr = __a_barrier_v6; | ||
| 40 | 			break; | ||
| 41 | 		} | ||
| 42 | 	} else { | ||
| 43 | 		int ver = *(int *)0xffff0ffc; | ||
| 44 | 		__a_gettp_ptr = __a_gettp_kuser; | ||
| 45 | 		__a_cas_ptr = __a_cas_kuser; | ||
| 46 | 		__a_barrier_ptr = __a_barrier_kuser; | ||
| 47 | 		if (ver < 2) a_crash(); | ||
| 48 | 		if (ver < 3) __a_barrier_ptr = __a_barrier_oldkuser; | ||
| 49 | 	} | ||
| 50 | #endif | ||
| 51 | 	return __syscall(0xf0005, p); | ||
| 52 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/arm/__unmapself.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .syntax unified | ||
| 2 | .text | ||
| 3 | .global __unmapself | ||
| 4 | .type __unmapself,%function | ||
| 5 | __unmapself: | ||
| 6 | 	mov r7,#91 | ||
| 7 | 	svc 0 | ||
| 8 | 	mov r7,#1 | ||
| 9 | 	svc 0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/arm/atomics.s created+106| ... | @@ -0,0 +1,106 @@ | ||
| 1 | .syntax unified | ||
| 2 | .text | ||
| 3 | |||
| 4 | .global __a_barrier_dummy | ||
| 5 | .hidden __a_barrier_dummy | ||
| 6 | .type __a_barrier_dummy,%function | ||
| 7 | __a_barrier_dummy: | ||
| 8 | 	bx lr | ||
| 9 | |||
| 10 | .global __a_barrier_oldkuser | ||
| 11 | .hidden __a_barrier_oldkuser | ||
| 12 | .type __a_barrier_oldkuser,%function | ||
| 13 | __a_barrier_oldkuser: | ||
| 14 | 	push {r0,r1,r2,r3,ip,lr} | ||
| 15 | 	mov r1,r0 | ||
| 16 | 	mov r2,sp | ||
| 17 | 	ldr ip,=0xffff0fc0 | ||
| 18 | 	bl 1f | ||
| 19 | 	pop {r0,r1,r2,r3,ip,lr} | ||
| 20 | 	bx lr | ||
| 21 | 1:	bx ip | ||
| 22 | |||
| 23 | .global __a_barrier_v6 | ||
| 24 | .hidden __a_barrier_v6 | ||
| 25 | .type __a_barrier_v6,%function | ||
| 26 | __a_barrier_v6: | ||
| 27 | 	.arch armv6t2 | ||
| 28 | 	mcr p15,0,r0,c7,c10,5 | ||
| 29 | 	bx lr | ||
| 30 | |||
| 31 | .global __a_barrier_v7 | ||
| 32 | .hidden __a_barrier_v7 | ||
| 33 | .type __a_barrier_v7,%function | ||
| 34 | __a_barrier_v7: | ||
| 35 | 	.arch armv7-a | ||
| 36 | 	dmb ish | ||
| 37 | 	bx lr | ||
| 38 | |||
| 39 | .global __a_cas_dummy | ||
| 40 | .hidden __a_cas_dummy | ||
| 41 | .type __a_cas_dummy,%function | ||
| 42 | __a_cas_dummy: | ||
| 43 | 	mov r3,r0 | ||
| 44 | 	ldr r0,[r2] | ||
| 45 | 	subs r0,r3,r0 | ||
| 46 | 	streq r1,[r2] | ||
| 47 | 	bx lr | ||
| 48 | |||
| 49 | .global __a_cas_v6 | ||
| 50 | .hidden __a_cas_v6 | ||
| 51 | .type __a_cas_v6,%function | ||
| 52 | __a_cas_v6: | ||
| 53 | 	.arch armv6t2 | ||
| 54 | 	mov r3,r0 | ||
| 55 | 	mcr p15,0,r0,c7,c10,5 | ||
| 56 | 1:	ldrex r0,[r2] | ||
| 57 | 	subs r0,r3,r0 | ||
| 58 | 	strexeq r0,r1,[r2] | ||
| 59 | 	teqeq r0,#1 | ||
| 60 | 	beq 1b | ||
| 61 | 	mcr p15,0,r0,c7,c10,5 | ||
| 62 | 	bx lr | ||
| 63 | |||
| 64 | .global __a_cas_v7 | ||
| 65 | .hidden __a_cas_v7 | ||
| 66 | .type __a_cas_v7,%function | ||
| 67 | __a_cas_v7: | ||
| 68 | 	.arch armv7-a | ||
| 69 | 	mov r3,r0 | ||
| 70 | 	dmb ish | ||
| 71 | 1:	ldrex r0,[r2] | ||
| 72 | 	subs r0,r3,r0 | ||
| 73 | 	strexeq r0,r1,[r2] | ||
| 74 | 	teqeq r0,#1 | ||
| 75 | 	beq 1b | ||
| 76 | 	dmb ish | ||
| 77 | 	bx lr | ||
| 78 | |||
| 79 | .global __a_gettp_cp15 | ||
| 80 | .hidden __a_gettp_cp15 | ||
| 81 | .type __a_gettp_cp15,%function | ||
| 82 | __a_gettp_cp15: | ||
| 83 | 	mrc p15,0,r0,c13,c0,3 | ||
| 84 | 	bx lr | ||
| 85 | |||
| 86 | /* Tag this file with minimum ISA level so as not to affect linking. */ | ||
| 87 | .object_arch armv4t | ||
| 88 | .eabi_attribute 6,2 | ||
| 89 | |||
| 90 | .data | ||
| 91 | .align 2 | ||
| 92 | |||
| 93 | .global __a_barrier_ptr | ||
| 94 | .hidden __a_barrier_ptr | ||
| 95 | __a_barrier_ptr: | ||
| 96 | 	.word __a_barrier_dummy | ||
| 97 | |||
| 98 | .global __a_cas_ptr | ||
| 99 | .hidden __a_cas_ptr | ||
| 100 | __a_cas_ptr: | ||
| 101 | 	.word __a_cas_dummy | ||
| 102 | |||
| 103 | .global __a_gettp_ptr | ||
| 104 | .hidden __a_gettp_ptr | ||
| 105 | __a_gettp_ptr: | ||
| 106 | 	.word __a_gettp_cp15 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/arm/clone.s created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | .syntax unified | ||
| 2 | .text | ||
| 3 | .global __clone | ||
| 4 | .hidden __clone | ||
| 5 | .type __clone,%function | ||
| 6 | __clone: | ||
| 7 | 	stmfd sp!,{r4,r5,r6,r7} | ||
| 8 | 	mov r7,#120 | ||
| 9 | 	mov r6,r3 | ||
| 10 | 	mov r5,r0 | ||
| 11 | 	mov r0,r2 | ||
| 12 | 	and r1,r1,#-16 | ||
| 13 | 	ldr r2,[sp,#16] | ||
| 14 | 	ldr r3,[sp,#20] | ||
| 15 | 	ldr r4,[sp,#24] | ||
| 16 | 	svc 0 | ||
| 17 | 	tst r0,r0 | ||
| 18 | 	beq 1f | ||
| 19 | 	ldmfd sp!,{r4,r5,r6,r7} | ||
| 20 | 	bx lr | ||
| 21 | |||
| 22 | 1:	mov r0,r6 | ||
| 23 | 	bl 3f | ||
| 24 | 2:	mov r7,#1 | ||
| 25 | 	svc 0 | ||
| 26 | 	b 2b | ||
| 27 | |||
| 28 | 3:	bx r5 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/arm/syscall_cp.s created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | .syntax unified | ||
| 2 | .global __cp_begin | ||
| 3 | .hidden __cp_begin | ||
| 4 | .global __cp_end | ||
| 5 | .hidden __cp_end | ||
| 6 | .global __cp_cancel | ||
| 7 | .hidden __cp_cancel | ||
| 8 | .hidden __cancel | ||
| 9 | .global __syscall_cp_asm | ||
| 10 | .hidden __syscall_cp_asm | ||
| 11 | .type __syscall_cp_asm,%function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | 	mov ip,sp | ||
| 14 | 	stmfd sp!,{r4,r5,r6,r7} | ||
| 15 | __cp_begin: | ||
| 16 | 	ldr r0,[r0] | ||
| 17 | 	cmp r0,#0 | ||
| 18 | 	bne __cp_cancel | ||
| 19 | 	mov r7,r1 | ||
| 20 | 	mov r0,r2 | ||
| 21 | 	mov r1,r3 | ||
| 22 | 	ldmfd ip,{r2,r3,r4,r5,r6} | ||
| 23 | 	svc 0 | ||
| 24 | __cp_end: | ||
| 25 | 	ldmfd sp!,{r4,r5,r6,r7} | ||
| 26 | 	bx lr | ||
| 27 | __cp_cancel: | ||
| 28 | 	ldmfd sp!,{r4,r5,r6,r7} | ||
| 29 | 	b __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/call_once.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | void call_once(once_flag *flag, void (*func)(void)) | ||
| 5 | { | ||
| 6 | 	__pthread_once(flag, func); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/clone.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <errno.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | int __clone(int (*func)(void *), void *stack, int flags, void *arg, ...) | ||
| 5 | { | ||
| 6 | 	return -ENOSYS; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_broadcast.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | int cnd_broadcast(cnd_t *c) | ||
| 5 | { | ||
| 6 | 	/* This internal function never fails, and always returns zero, | ||
| 7 | 	 * which matches the value thrd_success is defined with. */ | ||
| 8 | 	return __private_cond_signal((pthread_cond_t *)c, -1); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | |||
| 3 | void cnd_destroy(cnd_t *c) | ||
| 4 | { | ||
| 5 | 	/* For private cv this is a no-op */ | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | |||
| 3 | int cnd_init(cnd_t *c) | ||
| 4 | { | ||
| 5 | 	*c = (cnd_t){ 0 }; | ||
| 6 | 	return thrd_success; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_signal.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | int cnd_signal(cnd_t *c) | ||
| 5 | { | ||
| 6 | 	/* This internal function never fails, and always returns zero, | ||
| 7 | 	 * which matches the value thrd_success is defined with. */ | ||
| 8 | 	return __private_cond_signal((pthread_cond_t *)c, 1); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_timedwait.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int cnd_timedwait(cnd_t *restrict c, mtx_t *restrict m, const struct timespec *restrict ts) | ||
| 6 | { | ||
| 7 | 	int ret = __pthread_cond_timedwait((pthread_cond_t *)c, (pthread_mutex_t *)m, ts); | ||
| 8 | 	switch (ret) { | ||
| 9 | 	/* May also return EINVAL or EPERM. */ | ||
| 10 | 	default: return thrd_error; | ||
| 11 | 	case 0: return thrd_success; | ||
| 12 | 	case ETIMEDOUT: return thrd_timedout; | ||
| 13 | 	} | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/cnd_wait.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | |||
| 3 | int cnd_wait(cnd_t *c, mtx_t *m) | ||
| 4 | { | ||
| 5 | 	/* Calling cnd_timedwait with a null pointer is an extension. | ||
| 6 | 	 * It is convenient here to avoid duplication of the logic | ||
| 7 | 	 * for return values. */ | ||
| 8 | 	return cnd_timedwait(c, m, 0); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/default_attr.c created+4| ... | @@ -0,0 +1,4 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | unsigned __default_stacksize = DEFAULT_STACK_SIZE; | ||
| 4 | unsigned __default_guardsize = DEFAULT_GUARD_SIZE; | ||
lib/libc/wasi/libc-top-half/musl/src/thread/i386/__set_thread_area.s created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | .text | ||
| 2 | .global __set_thread_area | ||
| 3 | .hidden __set_thread_area | ||
| 4 | .type __set_thread_area,@function | ||
| 5 | __set_thread_area: | ||
| 6 | 	push %ebx | ||
| 7 | 	push $0x51 | ||
| 8 | 	push $0xfffff | ||
| 9 | 	push 16(%esp) | ||
| 10 | 	call 1f | ||
| 11 | 1:	addl $4f-1b,(%esp) | ||
| 12 | 	pop %ecx | ||
| 13 | 	mov (%ecx),%edx | ||
| 14 | 	push %edx | ||
| 15 | 	mov %esp,%ebx | ||
| 16 | 	xor %eax,%eax | ||
| 17 | 	mov $243,%al | ||
| 18 | 	int $128 | ||
| 19 | 	testl %eax,%eax | ||
| 20 | 	jnz 2f | ||
| 21 | 	movl (%esp),%edx | ||
| 22 | 	movl %edx,(%ecx) | ||
| 23 | 	leal 3(,%edx,8),%edx | ||
| 24 | 3:	movw %dx,%gs | ||
| 25 | 1: | ||
| 26 | 	addl $16,%esp | ||
| 27 | 	popl %ebx | ||
| 28 | 	ret | ||
| 29 | 2: | ||
| 30 | 	mov %ebx,%ecx | ||
| 31 | 	xor %eax,%eax | ||
| 32 | 	xor %ebx,%ebx | ||
| 33 | 	xor %edx,%edx | ||
| 34 | 	mov %ebx,(%esp) | ||
| 35 | 	mov $1,%bl | ||
| 36 | 	mov $16,%dl | ||
| 37 | 	mov $123,%al | ||
| 38 | 	int $128 | ||
| 39 | 	testl %eax,%eax | ||
| 40 | 	jnz 1b | ||
| 41 | 	mov $7,%dl | ||
| 42 | 	inc %al | ||
| 43 | 	jmp 3b | ||
| 44 | |||
| 45 | .data | ||
| 46 | 	.align 4 | ||
| 47 | 4:	.long -1 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/i386/__unmapself.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | .text | ||
| 2 | .global __unmapself | ||
| 3 | .type __unmapself,@function | ||
| 4 | __unmapself: | ||
| 5 | 	movl $91,%eax | ||
| 6 | 	movl 4(%esp),%ebx | ||
| 7 | 	movl 8(%esp),%ecx | ||
| 8 | 	int $128 | ||
| 9 | 	xorl %ebx,%ebx | ||
| 10 | 	movl $1,%eax | ||
| 11 | 	int $128 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/i386/clone.s created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone,@function | ||
| 5 | __clone: | ||
| 6 | 	push %ebp | ||
| 7 | 	mov %esp,%ebp | ||
| 8 | 	push %ebx | ||
| 9 | 	push %esi | ||
| 10 | 	push %edi | ||
| 11 | |||
| 12 | 	xor %eax,%eax | ||
| 13 | 	push $0x51 | ||
| 14 | 	mov %gs,%ax | ||
| 15 | 	push $0xfffff | ||
| 16 | 	shr $3,%eax | ||
| 17 | 	push 28(%ebp) | ||
| 18 | 	push %eax | ||
| 19 | 	mov $120,%al | ||
| 20 | |||
| 21 | 	mov 12(%ebp),%ecx | ||
| 22 | 	mov 16(%ebp),%ebx | ||
| 23 | 	and $-16,%ecx | ||
| 24 | 	sub $16,%ecx | ||
| 25 | 	mov 20(%ebp),%edi | ||
| 26 | 	mov %edi,(%ecx) | ||
| 27 | 	mov 24(%ebp),%edx | ||
| 28 | 	mov %esp,%esi | ||
| 29 | 	mov 32(%ebp),%edi | ||
| 30 | 	mov 8(%ebp),%ebp | ||
| 31 | 	int $128 | ||
| 32 | 	test %eax,%eax | ||
| 33 | 	jnz 1f | ||
| 34 | |||
| 35 | 	mov %ebp,%eax | ||
| 36 | 	xor %ebp,%ebp | ||
| 37 | 	call *%eax | ||
| 38 | 	mov %eax,%ebx | ||
| 39 | 	xor %eax,%eax | ||
| 40 | 	inc %eax | ||
| 41 | 	int $128 | ||
| 42 | 	hlt | ||
| 43 | |||
| 44 | 1:	add $16,%esp | ||
| 45 | 	pop %edi | ||
| 46 | 	pop %esi | ||
| 47 | 	pop %ebx | ||
| 48 | 	pop %ebp | ||
| 49 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/i386/syscall_cp.s created+41| ... | @@ -0,0 +1,41 @@ | ||
| 1 | .text | ||
| 2 | .global __cp_begin | ||
| 3 | .hidden __cp_begin | ||
| 4 | .global __cp_end | ||
| 5 | .hidden __cp_end | ||
| 6 | .global __cp_cancel | ||
| 7 | .hidden __cp_cancel | ||
| 8 | .hidden __cancel | ||
| 9 | .global __syscall_cp_asm | ||
| 10 | .hidden __syscall_cp_asm | ||
| 11 | .type __syscall_cp_asm,@function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | 	mov 4(%esp),%ecx | ||
| 14 | 	pushl %ebx | ||
| 15 | 	pushl %esi | ||
| 16 | 	pushl %edi | ||
| 17 | 	pushl %ebp | ||
| 18 | __cp_begin: | ||
| 19 | 	movl (%ecx),%eax | ||
| 20 | 	testl %eax,%eax | ||
| 21 | 	jnz __cp_cancel | ||
| 22 | 	movl 24(%esp),%eax | ||
| 23 | 	movl 28(%esp),%ebx | ||
| 24 | 	movl 32(%esp),%ecx | ||
| 25 | 	movl 36(%esp),%edx | ||
| 26 | 	movl 40(%esp),%esi | ||
| 27 | 	movl 44(%esp),%edi | ||
| 28 | 	movl 48(%esp),%ebp | ||
| 29 | 	int $128 | ||
| 30 | __cp_end: | ||
| 31 | 	popl %ebp | ||
| 32 | 	popl %edi | ||
| 33 | 	popl %esi | ||
| 34 | 	popl %ebx | ||
| 35 | 	ret | ||
| 36 | __cp_cancel: | ||
| 37 | 	popl %ebp | ||
| 38 | 	popl %edi | ||
| 39 | 	popl %esi | ||
| 40 | 	popl %ebx | ||
| 41 | 	jmp __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/i386/tls.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .text | ||
| 2 | .global ___tls_get_addr | ||
| 3 | .type ___tls_get_addr,@function | ||
| 4 | ___tls_get_addr: | ||
| 5 | 	mov %gs:4,%edx | ||
| 6 | 	mov (%eax),%ecx | ||
| 7 | 	mov 4(%eax),%eax | ||
| 8 | 	add (%edx,%ecx,4),%eax | ||
| 9 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/lock_ptc.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | |||
| 3 | static pthread_rwlock_t lock = PTHREAD_RWLOCK_INITIALIZER; | ||
| 4 | |||
| 5 | void __inhibit_ptc() | ||
| 6 | { | ||
| 7 | 	pthread_rwlock_wrlock(&lock); | ||
| 8 | } | ||
| 9 | |||
| 10 | void __acquire_ptc() | ||
| 11 | { | ||
| 12 | 	pthread_rwlock_rdlock(&lock); | ||
| 13 | } | ||
| 14 | |||
| 15 | void __release_ptc() | ||
| 16 | { | ||
| 17 | 	pthread_rwlock_unlock(&lock); | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/__m68k_read_tp.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | .text | ||
| 2 | .global __m68k_read_tp | ||
| 3 | .type __m68k_read_tp,@function | ||
| 4 | __m68k_read_tp: | ||
| 5 | 	move.l #333,%d0 | ||
| 6 | 	trap #0 | ||
| 7 | 	move.l %d0,%a0 | ||
| 8 | 	rts | ||
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/clone.s created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone,@function | ||
| 5 | __clone: | ||
| 6 | 	movem.l %d2-%d5,-(%sp) | ||
| 7 | 	move.l #120,%d0 | ||
| 8 | 	move.l 28(%sp),%d1 | ||
| 9 | 	move.l 24(%sp),%d2 | ||
| 10 | 	and.l #-16,%d2 | ||
| 11 | 	move.l 36(%sp),%d3 | ||
| 12 | 	move.l 44(%sp),%d4 | ||
| 13 | 	move.l 40(%sp),%d5 | ||
| 14 | 	move.l 20(%sp),%a0 | ||
| 15 | 	move.l 32(%sp),%a1 | ||
| 16 | 	trap #0 | ||
| 17 | 	tst.l %d0 | ||
| 18 | 	beq 1f | ||
| 19 | 	movem.l (%sp)+,%d2-%d5 | ||
| 20 | 	rts | ||
| 21 | 1:	move.l %a1,-(%sp) | ||
| 22 | 	jsr (%a0) | ||
| 23 | 	move.l #1,%d0 | ||
| 24 | 	trap #0 | ||
| 25 | 	clr.b 0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/m68k/syscall_cp.s created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | .text | ||
| 2 | .global __cp_begin | ||
| 3 | .hidden __cp_begin | ||
| 4 | .global __cp_end | ||
| 5 | .hidden __cp_end | ||
| 6 | .global __cp_cancel | ||
| 7 | .hidden __cp_cancel | ||
| 8 | .hidden __cancel | ||
| 9 | .global __syscall_cp_asm | ||
| 10 | .hidden __syscall_cp_asm | ||
| 11 | .type __syscall_cp_asm,@function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | 	movem.l %d2-%d5,-(%sp) | ||
| 14 | 	movea.l 20(%sp),%a0 | ||
| 15 | __cp_begin: | ||
| 16 | 	move.l (%a0),%d0 | ||
| 17 | 	bne __cp_cancel | ||
| 18 | 	movem.l 24(%sp),%d0-%d5/%a0 | ||
| 19 | 	trap #0 | ||
| 20 | __cp_end: | ||
| 21 | 	movem.l (%sp)+,%d2-%d5 | ||
| 22 | 	rts | ||
| 23 | __cp_cancel: | ||
| 24 | 	movem.l (%sp)+,%d2-%d5 | ||
| 25 | 	move.l __cancel-.-8,%a1 | ||
| 26 | 	jmp (%pc,%a1) | ||
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/__set_thread_area.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global __set_thread_area | ||
| 2 | .hidden __set_thread_area | ||
| 3 | .type __set_thread_area,@function | ||
| 4 | __set_thread_area: | ||
| 5 | 	ori r21, r5, 0 | ||
| 6 | 	rtsd r15, 8 | ||
| 7 | 	ori r3, r0, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/__unmapself.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | .global __unmapself | ||
| 2 | .type __unmapself,@function | ||
| 3 | __unmapself: | ||
| 4 | 	ori r12, r0, 91 | ||
| 5 | 	brki r14, 0x8 | ||
| 6 | 	ori r12, r0, 1 | ||
| 7 | 	brki r14, 0x8 | ||
| 8 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/clone.s created+30| ... | @@ -0,0 +1,30 @@ | ||
| 1 | .global __clone | ||
| 2 | .hidden __clone | ||
| 3 | .type __clone,@function | ||
| 4 | |||
| 5 | # r5, r6, r7, r8, r9, r10, stack | ||
| 6 | # fn, st, fl, ar, pt, tl, ct | ||
| 7 | # fl, st, __, pt, ct, tl | ||
| 8 | |||
| 9 | __clone: | ||
| 10 | 	andi r6, r6, -16 | ||
| 11 | 	addi r6, r6, -16 | ||
| 12 | 	swi r5, r6, 0 | ||
| 13 | 	swi r8, r6, 4 | ||
| 14 | |||
| 15 | 	ori r5, r7, 0 | ||
| 16 | 	ori r8, r9, 0 | ||
| 17 | 	lwi r9, r1, 28 | ||
| 18 | 	ori r12, r0, 120 | ||
| 19 | |||
| 20 | 	brki r14, 8 | ||
| 21 | 	beqi	r3, 1f | ||
| 22 | 	rtsd r15, 8 | ||
| 23 | 	nop | ||
| 24 | |||
| 25 | 1:	lwi r3, r1, 0 | ||
| 26 | 	lwi r5, r1, 4 | ||
| 27 | 	brald r15, r3 | ||
| 28 | 	nop | ||
| 29 | 	ori r12, r0, 1 | ||
| 30 | 	brki r14, 8 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/microblaze/syscall_cp.s created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | .global __cp_begin | ||
| 2 | .hidden __cp_begin | ||
| 3 | .global __cp_end | ||
| 4 | .hidden __cp_end | ||
| 5 | .global __cp_cancel | ||
| 6 | .hidden __cp_cancel | ||
| 7 | .hidden __cancel | ||
| 8 | .global __syscall_cp_asm | ||
| 9 | .hidden __syscall_cp_asm | ||
| 10 | .type __syscall_cp_asm,@function | ||
| 11 | __syscall_cp_asm: | ||
| 12 | __cp_begin: | ||
| 13 | 	lwi r5, r5, 0 | ||
| 14 | 	bnei r5, __cp_cancel | ||
| 15 | 	addi r12, r6, 0 | ||
| 16 | 	add r5, r7, r0 | ||
| 17 | 	add r6, r8, r0 | ||
| 18 | 	add r7, r9, r0 | ||
| 19 | 	add r8, r10, r0 | ||
| 20 | 	lwi r9, r1, 28 | ||
| 21 | 	lwi r10, r1, 32 | ||
| 22 | 	brki r14, 0x8 | ||
| 23 | __cp_end: | ||
| 24 | 	rtsd r15, 8 | ||
| 25 | 	nop | ||
| 26 | __cp_cancel: | ||
| 27 | 	bri __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mips/__unmapself.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .set noreorder | ||
| 2 | .global __unmapself | ||
| 3 | .type __unmapself,@function | ||
| 4 | __unmapself: | ||
| 5 | 	move $sp, $25 | ||
| 6 | 	li $2, 4091 | ||
| 7 | 	syscall | ||
| 8 | 	li $4, 0 | ||
| 9 | 	li $2, 4001 | ||
| 10 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mips/clone.s created+36| ... | @@ -0,0 +1,36 @@ | ||
| 1 | .set noreorder | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone,@function | ||
| 5 | __clone: | ||
| 6 | 	# Save function pointer and argument pointer on new thread stack | ||
| 7 | 	and $5, $5, -8 | ||
| 8 | 	subu $5, $5, 16 | ||
| 9 | 	sw $4, 0($5) | ||
| 10 | 	sw $7, 4($5) | ||
| 11 | 	# Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid) | ||
| 12 | 	move $4, $6 | ||
| 13 | 	lw $6, 16($sp) | ||
| 14 | 	lw $7, 20($sp) | ||
| 15 | 	lw $9, 24($sp) | ||
| 16 | 	subu $sp, $sp, 16 | ||
| 17 | 	sw $9, 16($sp) | ||
| 18 | 	li $2, 4120 | ||
| 19 | 	syscall | ||
| 20 | 	beq $7, $0, 1f | ||
| 21 | 	nop | ||
| 22 | 	addu $sp, $sp, 16 | ||
| 23 | 	jr $ra | ||
| 24 | 	subu $2, $0, $2 | ||
| 25 | 1:	beq $2, $0, 1f | ||
| 26 | 	nop | ||
| 27 | 	addu $sp, $sp, 16 | ||
| 28 | 	jr $ra | ||
| 29 | 	nop | ||
| 30 | 1:	lw $25, 0($sp) | ||
| 31 | 	lw $4, 4($sp) | ||
| 32 | 	jalr $25 | ||
| 33 | 	nop | ||
| 34 | 	move $4, $2 | ||
| 35 | 	li $2, 4001 | ||
| 36 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mips/syscall_cp.s created+53| ... | @@ -0,0 +1,53 @@ | ||
| 1 | .set noreorder | ||
| 2 | |||
| 3 | .global __cp_begin | ||
| 4 | .hidden __cp_begin | ||
| 5 | .type __cp_begin,@function | ||
| 6 | .global __cp_end | ||
| 7 | .hidden __cp_end | ||
| 8 | .type __cp_end,@function | ||
| 9 | .global __cp_cancel | ||
| 10 | .hidden __cp_cancel | ||
| 11 | .type __cp_cancel,@function | ||
| 12 | .hidden __cancel | ||
| 13 | .global __syscall_cp_asm | ||
| 14 | .hidden __syscall_cp_asm | ||
| 15 | .type __syscall_cp_asm,@function | ||
| 16 | __syscall_cp_asm: | ||
| 17 | 	subu $sp, $sp, 32 | ||
| 18 | __cp_begin: | ||
| 19 | 	lw $4, 0($4) | ||
| 20 | 	bne $4, $0, __cp_cancel | ||
| 21 | 	move $2, $5 | ||
| 22 | 	move $4, $6 | ||
| 23 | 	move $5, $7 | ||
| 24 | 	lw $6, 48($sp) | ||
| 25 | 	lw $7, 52($sp) | ||
| 26 | 	lw $8, 56($sp) | ||
| 27 | 	lw $9, 60($sp) | ||
| 28 | 	lw $10,64($sp) | ||
| 29 | 	sw $8, 16($sp) | ||
| 30 | 	sw $9, 20($sp) | ||
| 31 | 	sw $10,24($sp) | ||
| 32 | 	sw $2, 28($sp) | ||
| 33 | 	lw $2, 28($sp) | ||
| 34 | 	syscall | ||
| 35 | __cp_end: | ||
| 36 | 	beq $7, $0, 1f | ||
| 37 | 	addu $sp, $sp, 32 | ||
| 38 | 	subu $2, $0, $2 | ||
| 39 | 1:	jr $ra | ||
| 40 | 	nop | ||
| 41 | |||
| 42 | __cp_cancel: | ||
| 43 | 	move $2, $ra | ||
| 44 | 	bal 1f | ||
| 45 | 	addu $sp, $sp, 32 | ||
| 46 | 	.gpword . | ||
| 47 | 	.gpword __cancel | ||
| 48 | 1:	lw $3, ($ra) | ||
| 49 | 	subu $3, $ra, $3 | ||
| 50 | 	lw $25, 4($ra) | ||
| 51 | 	addu $25, $25, $3 | ||
| 52 | 	jr $25 | ||
| 53 | 	move $ra, $2 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/__unmapself.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__unmapself | ||
| 3 | .type	__unmapself, @function | ||
| 4 | __unmapself: | ||
| 5 | 	li	$2, 5011 | ||
| 6 | 	syscall | ||
| 7 | 	li	$4, 0 | ||
| 8 | 	li	$2, 5058 | ||
| 9 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/clone.s created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__clone | ||
| 3 | .hidden __clone | ||
| 4 | .type	__clone,@function | ||
| 5 | __clone: | ||
| 6 | 	# Save function pointer and argument pointer on new thread stack | ||
| 7 | 	and	$5, $5, -16	# aligning stack to double word | ||
| 8 | 	dsubu	$5, $5, 16 | ||
| 9 | 	sd	$4, 0($5)	# save function pointer | ||
| 10 | 	sd	$7, 8($5)	# save argument pointer | ||
| 11 | |||
| 12 | 	# Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid) | ||
| 13 | 	# sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls) | ||
| 14 | 	move	$4, $6 | ||
| 15 | 	move	$6, $8 | ||
| 16 | 	move	$7, $9 | ||
| 17 | 	move	$8, $10 | ||
| 18 | 	li	$2, 5055 | ||
| 19 | 	syscall | ||
| 20 | 	beq	$7, $0, 1f | ||
| 21 | 	nop | ||
| 22 | 	jr	$ra | ||
| 23 | 	dsubu	$2, $0, $2 | ||
| 24 | 1:	beq	$2, $0, 1f | ||
| 25 | 	nop | ||
| 26 | 	jr	$ra | ||
| 27 | 	nop | ||
| 28 | 1:	ld	$25, 0($sp)	# function pointer | ||
| 29 | 	ld	$4, 8($sp)	# argument pointer | ||
| 30 | 	jalr	$25		# call the user's function | ||
| 31 | 	nop | ||
| 32 | 	move 	$4, $2 | ||
| 33 | 	li	$2, 5058 | ||
| 34 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mips64/syscall_cp.s created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__cp_begin | ||
| 3 | .hidden	__cp_begin | ||
| 4 | .type	__cp_begin,@function | ||
| 5 | .global	__cp_end | ||
| 6 | .hidden	__cp_end | ||
| 7 | .type	__cp_end,@function | ||
| 8 | .global	__cp_cancel | ||
| 9 | .hidden	__cp_cancel | ||
| 10 | .type	__cp_cancel,@function | ||
| 11 | .global	__cp_cancel_data | ||
| 12 | .hidden	__cp_cancel_data | ||
| 13 | .type	__cp_cancel_data,@function | ||
| 14 | .hidden	__cancel | ||
| 15 | .global	__syscall_cp_asm | ||
| 16 | .hidden	__syscall_cp_asm | ||
| 17 | .type	__syscall_cp_asm,@function | ||
| 18 | __syscall_cp_asm: | ||
| 19 | __cp_begin: | ||
| 20 | 	lw	$4, 0($4) | ||
| 21 | 	bne	$4, $0, __cp_cancel | ||
| 22 | 	move	$2, $5 | ||
| 23 | 	move	$4, $6 | ||
| 24 | 	move	$5, $7 | ||
| 25 | 	move	$6, $8 | ||
| 26 | 	move	$7, $9 | ||
| 27 | 	move	$8, $10 | ||
| 28 | 	move	$9, $11 | ||
| 29 | 	ld	$10, 0($sp) | ||
| 30 | 	syscall | ||
| 31 | __cp_end: | ||
| 32 | 	beq	$7, $0, 1f | ||
| 33 | 	nop | ||
| 34 | 	dsubu	$2, $0, $2 | ||
| 35 | 1:	jr	$ra | ||
| 36 | 	nop | ||
| 37 | |||
| 38 | 	# if cancellation flag is 1 then call __cancel | ||
| 39 | __cp_cancel: | ||
| 40 | 	move	$2, $ra | ||
| 41 | .align 8 | ||
| 42 | 	bal	1f | ||
| 43 | 	nop | ||
| 44 | __cp_cancel_data: | ||
| 45 | 	.gpdword __cp_cancel_data | ||
| 46 | 	.gpdword __cancel | ||
| 47 | 1:	ld	$3, ($ra) | ||
| 48 | 	dsubu	$3, $ra, $3 | ||
| 49 | 	ld	$25, 8($ra) | ||
| 50 | 	daddu	$25, $25, $3 | ||
| 51 | 	jr	$25 | ||
| 52 | 	move	$ra, $2 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/__unmapself.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__unmapself | ||
| 3 | .type	__unmapself,@function | ||
| 4 | __unmapself: | ||
| 5 | 	li	$2, 6011 | ||
| 6 | 	syscall | ||
| 7 | 	li	$4, 0 | ||
| 8 | 	li	$2, 6058 | ||
| 9 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/clone.s created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__clone | ||
| 3 | .hidden __clone | ||
| 4 | .type	__clone,@function | ||
| 5 | __clone: | ||
| 6 | 	# Save function pointer and argument pointer on new thread stack | ||
| 7 | 	and	$5, $5, -16	# aligning stack to double word | ||
| 8 | 	subu	$5, $5, 16 | ||
| 9 | 	sw	$4, 0($5)	# save function pointer | ||
| 10 | 	sw	$7, 4($5)	# save argument pointer | ||
| 11 | |||
| 12 | 	# Shuffle (fn,sp,fl,arg,ptid,tls,ctid) to (fl,sp,ptid,tls,ctid) | ||
| 13 | 	# sys_clone(u64 flags, u64 ustack_base, u64 parent_tidptr, u64 child_tidptr, u64 tls) | ||
| 14 | 	move	$4, $6 | ||
| 15 | 	move	$6, $8 | ||
| 16 | 	move	$7, $9 | ||
| 17 | 	move	$8, $10 | ||
| 18 | 	li	$2, 6055 | ||
| 19 | 	syscall | ||
| 20 | 	beq	$7, $0, 1f | ||
| 21 | 	nop | ||
| 22 | 	jr	$ra | ||
| 23 | 	subu	$2, $0, $2 | ||
| 24 | 1:	beq	$2, $0, 1f | ||
| 25 | 	nop | ||
| 26 | 	jr	$ra | ||
| 27 | 	nop | ||
| 28 | 1:	lw	$25, 0($sp)	# function pointer | ||
| 29 | 	lw	$4, 4($sp)	# argument pointer | ||
| 30 | 	jalr	$25		# call the user's function | ||
| 31 | 	nop | ||
| 32 | 	move 	$4, $2 | ||
| 33 | 	li	$2, 6058 | ||
| 34 | 	syscall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mipsn32/syscall_cp.s created+51| ... | @@ -0,0 +1,51 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	__cp_begin | ||
| 3 | .hidden	__cp_begin | ||
| 4 | .type	__cp_begin,@function | ||
| 5 | .global	__cp_end | ||
| 6 | .hidden	__cp_end | ||
| 7 | .type	__cp_end,@function | ||
| 8 | .global	__cp_cancel | ||
| 9 | .hidden	__cp_cancel | ||
| 10 | .type	__cp_cancel,@function | ||
| 11 | .global	__cp_cancel_data | ||
| 12 | .hidden	__cp_cancel_data | ||
| 13 | .type	__cp_cancel_data,@function | ||
| 14 | .hidden	__cancel | ||
| 15 | .global	__syscall_cp_asm | ||
| 16 | .hidden	__syscall_cp_asm | ||
| 17 | .type	__syscall_cp_asm,@function | ||
| 18 | __syscall_cp_asm: | ||
| 19 | __cp_begin: | ||
| 20 | 	lw	$4, 0($4) | ||
| 21 | 	bne	$4, $0, __cp_cancel | ||
| 22 | 	move	$2, $5 | ||
| 23 | 	move	$4, $6 | ||
| 24 | 	move	$5, $7 | ||
| 25 | 	move	$6, $8 | ||
| 26 | 	move	$7, $9 | ||
| 27 | 	move	$8, $10 | ||
| 28 | 	move	$9, $11 | ||
| 29 | 	lw	$10, 0($sp) | ||
| 30 | 	syscall | ||
| 31 | __cp_end: | ||
| 32 | 	beq	$7, $0, 1f | ||
| 33 | 	nop | ||
| 34 | 	subu	$2, $0, $2 | ||
| 35 | 1:	jr	$ra | ||
| 36 | 	nop | ||
| 37 | |||
| 38 | 	# if cancellation flag is 1 then call __cancel | ||
| 39 | __cp_cancel: | ||
| 40 | 	move	$2, $ra | ||
| 41 | 	bal	1f | ||
| 42 | 	nop | ||
| 43 | __cp_cancel_data: | ||
| 44 | 	.gpword __cp_cancel_data | ||
| 45 | 	.gpword __cancel | ||
| 46 | 1:	lw	$3, 0($ra) | ||
| 47 | 	subu	$3, $ra, $3 | ||
| 48 | 	lw	$25, 4($ra) | ||
| 49 | 	addu	$25, $25, $3 | ||
| 50 | 	jr	$25 | ||
| 51 | 	move	$ra, $2 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_destroy.c created+5| ... | @@ -0,0 +1,5 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | |||
| 3 | void mtx_destroy(mtx_t *mtx) | ||
| 4 | { | ||
| 5 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_init.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | int mtx_init(mtx_t *m, int type) | ||
| 5 | { | ||
| 6 | 	*m = (mtx_t){ | ||
| 7 | 		._m_type = ((type&mtx_recursive) ? PTHREAD_MUTEX_RECURSIVE : PTHREAD_MUTEX_NORMAL), | ||
| 8 | 	}; | ||
| 9 | 	return thrd_success; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_lock.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | int mtx_lock(mtx_t *m) | ||
| 5 | { | ||
| 6 | 	if (m->_m_type == PTHREAD_MUTEX_NORMAL && !a_cas(&m->_m_lock, 0, EBUSY)) | ||
| 7 | 		return thrd_success; | ||
| 8 | 	/* Calling mtx_timedlock with a null pointer is an extension. | ||
| 9 | 	 * It is convenient, here to avoid duplication of the logic | ||
| 10 | 	 * for return values. */ | ||
| 11 | 	return mtx_timedlock(m, 0); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_timedlock.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int mtx_timedlock(mtx_t *restrict m, const struct timespec *restrict ts) | ||
| 6 | { | ||
| 7 | 	int ret = __pthread_mutex_timedlock((pthread_mutex_t *)m, ts); | ||
| 8 | 	switch (ret) { | ||
| 9 | 	default: return thrd_error; | ||
| 10 | 	case 0: return thrd_success; | ||
| 11 | 	case ETIMEDOUT: return thrd_timedout; | ||
| 12 | 	} | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_trylock.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | int mtx_trylock(mtx_t *m) | ||
| 5 | { | ||
| 6 | 	if (m->_m_type == PTHREAD_MUTEX_NORMAL) | ||
| 7 | 		return (a_cas(&m->_m_lock, 0, EBUSY) & EBUSY) ? thrd_busy : thrd_success; | ||
| 8 | |||
| 9 | 	int ret = __pthread_mutex_trylock((pthread_mutex_t *)m); | ||
| 10 | 	switch (ret) { | ||
| 11 | 	default: return thrd_error; | ||
| 12 | 	case 0: return thrd_success; | ||
| 13 | 	case EBUSY: return thrd_busy; | ||
| 14 | 	} | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/mtx_unlock.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | int mtx_unlock(mtx_t *mtx) | ||
| 5 | { | ||
| 6 | 	/* The only cases where pthread_mutex_unlock can return an | ||
| 7 | 	 * error are undefined behavior for C11 mtx_unlock, so we can | ||
| 8 | 	 * assume it does not return an error and simply tail call. */ | ||
| 9 | 	return __pthread_mutex_unlock((pthread_mutex_t *)mtx); | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/__set_thread_area.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global __set_thread_area | ||
| 2 | .hidden __set_thread_area | ||
| 3 | .type __set_thread_area,@function | ||
| 4 | __set_thread_area: | ||
| 5 | 	l.ori	r10, r3, 0 | ||
| 6 | 	l.jr	r9 | ||
| 7 | 	 l.ori	r11, r0, 0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/__unmapself.s created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | .global __unmapself | ||
| 2 | .type __unmapself,@function | ||
| 3 | __unmapself: | ||
| 4 | 	l.ori	r11, r0, 215 /* __NR_munmap */ | ||
| 5 | 	l.sys	1 | ||
| 6 | 	l.ori	r3, r0, 0 | ||
| 7 | 	l.ori	r11, r0, 93 /* __NR_exit */ | ||
| 8 | 	l.sys	1 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/clone.s created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | /* int clone(fn, stack, flags, arg, ptid, tls, ctid) | ||
| 2 | * r3 r4 r5 r6 sp+0 sp+4 sp+8 | ||
| 3 | * sys_clone(flags, stack, ptid, ctid, tls) | ||
| 4 | */ | ||
| 5 | .global __clone | ||
| 6 | .hidden __clone | ||
| 7 | .type __clone,@function | ||
| 8 | __clone: | ||
| 9 | 	l.addi	r4, r4, -8 | ||
| 10 | 	l.sw	0(r4), r3 | ||
| 11 | 	l.sw	4(r4), r6 | ||
| 12 | 	/* (fn, st, fl, ar, pt, tl, ct) => (fl, st, pt, ct, tl) */ | ||
| 13 | 	l.ori	r3, r5, 0 | ||
| 14 | 	l.lwz	r5, 0(r1) | ||
| 15 | 	l.lwz	r6, 8(r1) | ||
| 16 | 	l.lwz	r7, 4(r1) | ||
| 17 | 	l.ori	r11, r0, 220 /* __NR_clone */ | ||
| 18 | 	l.sys	1 | ||
| 19 | |||
| 20 | 	l.sfeqi	r11, 0 | ||
| 21 | 	l.bf	1f | ||
| 22 | 	 l.nop | ||
| 23 | 	l.jr	r9 | ||
| 24 | 	 l.nop | ||
| 25 | |||
| 26 | 1:	l.lwz	r11, 0(r1) | ||
| 27 | 	l.jalr	r11 | ||
| 28 | 	 l.lwz	r3, 4(r1) | ||
| 29 | |||
| 30 | 	l.ori	r11, r0, 93 /* __NR_exit */ | ||
| 31 | 	l.sys	1 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/or1k/syscall_cp.s created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | .global __cp_begin | ||
| 2 | .hidden __cp_begin | ||
| 3 | .global __cp_end | ||
| 4 | .hidden __cp_end | ||
| 5 | .global __cp_cancel | ||
| 6 | .hidden __cp_cancel | ||
| 7 | .hidden __cancel | ||
| 8 | .global __syscall_cp_asm | ||
| 9 | .hidden __syscall_cp_asm | ||
| 10 | .type __syscall_cp_asm,@function | ||
| 11 | __syscall_cp_asm: | ||
| 12 | __cp_begin: | ||
| 13 | 	l.lwz	r3, 0(r3) | ||
| 14 | 	l.sfeqi	r3, 0 | ||
| 15 | 	l.bnf	__cp_cancel | ||
| 16 | 	 l.ori	r11, r4, 0 | ||
| 17 | 	l.ori	r3, r5, 0 | ||
| 18 | 	l.ori	r4, r6, 0 | ||
| 19 | 	l.ori	r5, r7, 0 | ||
| 20 | 	l.ori	r6, r8, 0 | ||
| 21 | 	l.lwz	r7, 0(r1) | ||
| 22 | 	l.lwz	r8, 4(r1) | ||
| 23 | 	l.sys	1 | ||
| 24 | __cp_end: | ||
| 25 | 	l.jr	r9 | ||
| 26 | 	 l.nop | ||
| 27 | __cp_cancel: | ||
| 28 | 	l.j	__cancel | ||
| 29 | 	 l.nop | ||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/__set_thread_area.s created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | .text | ||
| 2 | .global __set_thread_area | ||
| 3 | .hidden __set_thread_area | ||
| 4 | .type __set_thread_area, %function | ||
| 5 | __set_thread_area: | ||
| 6 | 	# mov pointer in reg3 into r2 | ||
| 7 | 	mr 2, 3 | ||
| 8 | 	# put 0 into return reg | ||
| 9 | 	li 3, 0 | ||
| 10 | 	# return | ||
| 11 | 	blr | ||
| 12 | |||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/__unmapself.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | 	.text | ||
| 2 | 	.global __unmapself | ||
| 3 | 	.type __unmapself,%function | ||
| 4 | __unmapself: | ||
| 5 | 	li 0, 91 # __NR_munmap | ||
| 6 | 	sc | ||
| 7 | 	li 0, 1 #__NR_exit | ||
| 8 | 	sc | ||
| 9 | 	blr | ||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/clone.s created+73| ... | @@ -0,0 +1,73 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone, %function | ||
| 5 | __clone: | ||
| 6 | # int clone(fn, stack, flags, arg, ptid, tls, ctid) | ||
| 7 | # a b c d e f g | ||
| 8 | # 3 4 5 6 7 8 9 | ||
| 9 | # pseudo C code: | ||
| 10 | # tid = syscall(SYS_clone,c,b,e,f,g); | ||
| 11 | # if (!tid) syscall(SYS_exit, a(d)); | ||
| 12 | # return tid; | ||
| 13 | |||
| 14 | # SYS_clone = 120 | ||
| 15 | # SYS_exit = 1 | ||
| 16 | |||
| 17 | # store non-volatile regs r30, r31 on stack in order to put our | ||
| 18 | # start func and its arg there | ||
| 19 | stwu 30, -16(1) | ||
| 20 | stw 31, 4(1) | ||
| 21 | |||
| 22 | # save r3 (func) into r30, and r6(arg) into r31 | ||
| 23 | mr 30, 3 | ||
| 24 | mr 31, 6 | ||
| 25 | |||
| 26 | # create initial stack frame for new thread | ||
| 27 | clrrwi 4, 4, 4 | ||
| 28 | li 0, 0 | ||
| 29 | stwu 0, -16(4) | ||
| 30 | |||
| 31 | #move c into first arg | ||
| 32 | mr 3, 5 | ||
| 33 | #mr 4, 4 | ||
| 34 | mr 5, 7 | ||
| 35 | mr 6, 8 | ||
| 36 | mr 7, 9 | ||
| 37 | |||
| 38 | # move syscall number into r0 | ||
| 39 | li 0, 120 | ||
| 40 | |||
| 41 | sc | ||
| 42 | |||
| 43 | # check for syscall error | ||
| 44 | bns+ 1f # jump to label 1 if no summary overflow. | ||
| 45 | #else | ||
| 46 | neg 3, 3 #negate the result (errno) | ||
| 47 | 1: | ||
| 48 | # compare sc result with 0 | ||
| 49 | cmpwi cr7, 3, 0 | ||
| 50 | |||
| 51 | # if not 0, jump to end | ||
| 52 | bne cr7, 2f | ||
| 53 | |||
| 54 | #else: we're the child | ||
| 55 | #call funcptr: move arg (d) into r3 | ||
| 56 | mr 3, 31 | ||
| 57 | #move r30 (funcptr) into CTR reg | ||
| 58 | mtctr 30 | ||
| 59 | # call CTR reg | ||
| 60 | bctrl | ||
| 61 | # mov SYS_exit into r0 (the exit param is already in r3) | ||
| 62 | li 0, 1 | ||
| 63 | sc | ||
| 64 | |||
| 65 | 2: | ||
| 66 | |||
| 67 | # restore stack | ||
| 68 | lwz 30, 0(1) | ||
| 69 | lwz 31, 4(1) | ||
| 70 | addi 1, 1, 16 | ||
| 71 | |||
| 72 | blr | ||
| 73 | |||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc/syscall_cp.s created+59| ... | @@ -0,0 +1,59 @@ | ||
| 1 | .global __cp_begin | ||
| 2 | .hidden __cp_begin | ||
| 3 | .global __cp_end | ||
| 4 | .hidden __cp_end | ||
| 5 | .global __cp_cancel | ||
| 6 | .hidden __cp_cancel | ||
| 7 | .hidden __cancel | ||
| 8 | .global __syscall_cp_asm | ||
| 9 | .hidden __syscall_cp_asm | ||
| 10 | |||
| 11 | #r0: volatile. may be modified during linkage. | ||
| 12 | #r1: stack frame: 16 byte alignment. | ||
| 13 | #r2: tls/thread pointer on pp32 | ||
| 14 | #r3,r4: return values, first args | ||
| 15 | #r5-r10: args | ||
| 16 | #r11-r12: volatile. may be modified during linkage | ||
| 17 | #r13: "small data area" pointer | ||
| 18 | #r14 - r30: local vars | ||
| 19 | #r31: local or environment pointer | ||
| 20 | |||
| 21 | #r1, r14-31: belong to the caller, must be saved and restored | ||
| 22 | #r0, r3-r12, ctr, xer: volatile, not preserved | ||
| 23 | #r0,r11,r12: may be altered by cross-module call, | ||
| 24 | #"a func cannot depend on that these regs have the values placed by the caller" | ||
| 25 | |||
| 26 | #the fields CR2,CR2,CR4 of the cond reg must be preserved | ||
| 27 | #LR (link reg) shall contain the funcs return address | ||
| 28 | 	.text | ||
| 29 | 	.type __syscall_cp_asm,%function | ||
| 30 | __syscall_cp_asm: | ||
| 31 | 	# at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th | ||
| 32 | __cp_begin: | ||
| 33 | 	# r3 holds first argument, its a pointer to self->cancel. | ||
| 34 | 	# we must compare the dereferenced value with 0 and jump to __cancel if its not | ||
| 35 | 	 | ||
| 36 | 	lwz 0, 0(3) #deref pointer into r0 | ||
| 37 | 	 | ||
| 38 | 	cmpwi cr7, 0, 0 #compare r0 with 0, store result in cr7. | ||
| 39 | 	beq+ cr7, 1f #jump to label 1 if r0 was 0 | ||
| 40 | 	 | ||
| 41 | 	b __cp_cancel #else call cancel | ||
| 42 | 1: | ||
| 43 | 	#ok, the cancel flag was not set | ||
| 44 | 	# syscall: number goes to r0, the rest 3-8 | ||
| 45 | 	mr 0, 4 # put the system call number into r0 | ||
| 46 | 	mr 3, 5 # Shift the arguments: arg1 | ||
| 47 | 	mr 4, 6 # arg2 | ||
| 48 | 	mr 5, 7 # arg3 | ||
| 49 | 	mr 6, 8 # arg4 | ||
| 50 | 	mr 7, 9 # arg5 | ||
| 51 | 	mr 8, 10 # arg6 | ||
| 52 | 	sc | ||
| 53 | __cp_end: | ||
| 54 | 	bnslr+ # return if no summary overflow. | ||
| 55 | 	#else negate result. | ||
| 56 | 	neg 3, 3 | ||
| 57 | 	blr | ||
| 58 | __cp_cancel: | ||
| 59 | 	b __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/__set_thread_area.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | .text | ||
| 2 | .global __set_thread_area | ||
| 3 | .hidden __set_thread_area | ||
| 4 | .type __set_thread_area, %function | ||
| 5 | __set_thread_area: | ||
| 6 | 	mr 13, 3 | ||
| 7 | 	li 3, 0 | ||
| 8 | 	blr | ||
| 9 | |||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/__unmapself.s created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | 	.text | ||
| 2 | 	.global __unmapself | ||
| 3 | 	.type __unmapself,%function | ||
| 4 | __unmapself: | ||
| 5 | 	li 0, 91 # __NR_munmap | ||
| 6 | 	sc | ||
| 7 | 	li 0, 1 #__NR_exit | ||
| 8 | 	sc | ||
| 9 | 	blr | ||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/clone.s created+48| ... | @@ -0,0 +1,48 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone, %function | ||
| 5 | __clone: | ||
| 6 | 	# int clone(fn, stack, flags, arg, ptid, tls, ctid) | ||
| 7 | 	# a b c d e f g | ||
| 8 | 	# 3 4 5 6 7 8 9 | ||
| 9 | 	# pseudo C code: | ||
| 10 | 	# tid = syscall(SYS_clone,c,b,e,f,g); | ||
| 11 | 	# if (!tid) syscall(SYS_exit, a(d)); | ||
| 12 | 	# return tid; | ||
| 13 | |||
| 14 | 	# create initial stack frame for new thread | ||
| 15 | 	clrrdi 4, 4, 4 | ||
| 16 | 	li 0, 0 | ||
| 17 | 	stdu 0,-32(4) | ||
| 18 | |||
| 19 | 	# save fn and arg to child stack | ||
| 20 | 	std 3, 8(4) | ||
| 21 | 	std 6, 16(4) | ||
| 22 | |||
| 23 | 	# shuffle args into correct registers and call SYS_clone | ||
| 24 | 	mr 3, 5 | ||
| 25 | 	#mr 4, 4 | ||
| 26 | 	mr 5, 7 | ||
| 27 | 	mr 6, 8 | ||
| 28 | 	mr 7, 9 | ||
| 29 | 	li 0, 120 # SYS_clone = 120 | ||
| 30 | 	sc | ||
| 31 | |||
| 32 | 	# if error, negate return (errno) | ||
| 33 | 	bns+ 1f | ||
| 34 | 	neg 3, 3 | ||
| 35 | |||
| 36 | 1:	# if we're the parent, return | ||
| 37 | 	cmpwi cr7, 3, 0 | ||
| 38 | 	bnelr cr7 | ||
| 39 | |||
| 40 | 	# we're the child. call fn(arg) | ||
| 41 | 	ld 3, 16(1) | ||
| 42 | 	ld 12, 8(1) | ||
| 43 | 	mtctr 12 | ||
| 44 | 	bctrl | ||
| 45 | |||
| 46 | 	# call SYS_exit. exit code is already in r3 from fn return value | ||
| 47 | 	li 0, 1 # SYS_exit = 1 | ||
| 48 | 	sc | ||
lib/libc/wasi/libc-top-half/musl/src/thread/powerpc64/syscall_cp.s created+44| ... | @@ -0,0 +1,44 @@ | ||
| 1 | 	.global __cp_begin | ||
| 2 | 	.hidden __cp_begin | ||
| 3 | 	.global __cp_end | ||
| 4 | 	.hidden __cp_end | ||
| 5 | 	.global __cp_cancel | ||
| 6 | 	.hidden __cp_cancel | ||
| 7 | 	.hidden __cancel | ||
| 8 | 	.global __syscall_cp_asm | ||
| 9 | 	.hidden __syscall_cp_asm | ||
| 10 | 	.text | ||
| 11 | 	.type __syscall_cp_asm,%function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | 	# at enter: r3 = pointer to self->cancel, r4: syscall no, r5: first arg, r6: 2nd, r7: 3rd, r8: 4th, r9: 5th, r10: 6th | ||
| 14 | __cp_begin: | ||
| 15 | 	# if (self->cancel) goto __cp_cancel | ||
| 16 | 	lwz 0, 0(3) | ||
| 17 | 	cmpwi cr7, 0, 0 | ||
| 18 | 	bne- cr7, __cp_cancel | ||
| 19 | |||
| 20 | 	# make syscall | ||
| 21 | 	mr 0, 4 | ||
| 22 | 	mr 3, 5 | ||
| 23 | 	mr 4, 6 | ||
| 24 | 	mr 5, 7 | ||
| 25 | 	mr 6, 8 | ||
| 26 | 	mr 7, 9 | ||
| 27 | 	mr 8, 10 | ||
| 28 | 	sc | ||
| 29 | |||
| 30 | __cp_end: | ||
| 31 | 	# return error ? -r3 : r3 | ||
| 32 | 	bnslr+ | ||
| 33 | 	neg 3, 3 | ||
| 34 | 	blr | ||
| 35 | |||
| 36 | __cp_cancel: | ||
| 37 | 	mflr 0 | ||
| 38 | 	bl 1f | ||
| 39 | 	.long .TOC.-. | ||
| 40 | 1:	mflr 3 | ||
| 41 | 	lwa 2, 0(3) | ||
| 42 | 	add 2, 2, 3 | ||
| 43 | 	mtlr 0 | ||
| 44 | 	b __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_atfork.c created+49| ... | @@ -0,0 +1,49 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | #include "libc.h" | ||
| 3 | #include "lock.h" | ||
| 4 | |||
| 5 | static struct atfork_funcs { | ||
| 6 | 	void (*prepare)(void); | ||
| 7 | 	void (*parent)(void); | ||
| 8 | 	void (*child)(void); | ||
| 9 | 	struct atfork_funcs *prev, *next; | ||
| 10 | } *funcs; | ||
| 11 | |||
| 12 | static volatile int lock[1]; | ||
| 13 | |||
| 14 | void __fork_handler(int who) | ||
| 15 | { | ||
| 16 | 	struct atfork_funcs *p; | ||
| 17 | 	if (!funcs) return; | ||
| 18 | 	if (who < 0) { | ||
| 19 | 		LOCK(lock); | ||
| 20 | 		for (p=funcs; p; p = p->next) { | ||
| 21 | 			if (p->prepare) p->prepare(); | ||
| 22 | 			funcs = p; | ||
| 23 | 		} | ||
| 24 | 	} else { | ||
| 25 | 		for (p=funcs; p; p = p->prev) { | ||
| 26 | 			if (!who && p->parent) p->parent(); | ||
| 27 | 			else if (who && p->child) p->child(); | ||
| 28 | 			funcs = p; | ||
| 29 | 		} | ||
| 30 | 		UNLOCK(lock); | ||
| 31 | 	} | ||
| 32 | } | ||
| 33 | |||
| 34 | int pthread_atfork(void (*prepare)(void), void (*parent)(void), void (*child)(void)) | ||
| 35 | { | ||
| 36 | 	struct atfork_funcs *new = malloc(sizeof *new); | ||
| 37 | 	if (!new) return -1; | ||
| 38 | |||
| 39 | 	LOCK(lock); | ||
| 40 | 	new->next = funcs; | ||
| 41 | 	new->prev = 0; | ||
| 42 | 	new->prepare = prepare; | ||
| 43 | 	new->parent = parent; | ||
| 44 | 	new->child = child; | ||
| 45 | 	if (funcs) funcs->prev = new; | ||
| 46 | 	funcs = new; | ||
| 47 | 	UNLOCK(lock); | ||
| 48 | 	return 0; | ||
| 49 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_destroy(pthread_attr_t *a) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_get.c created+98| ... | @@ -0,0 +1,98 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_getdetachstate(const pthread_attr_t *a, int *state) | ||
| 4 | { | ||
| 5 | 	*state = a->_a_detach; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
| 8 | int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) | ||
| 9 | { | ||
| 10 | 	*size = a->_a_guardsize; | ||
| 11 | 	return 0; | ||
| 12 | } | ||
| 13 | |||
| 14 | int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit) | ||
| 15 | { | ||
| 16 | 	*inherit = a->_a_sched; | ||
| 17 | 	return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) | ||
| 21 | { | ||
| 22 | 	param->sched_priority = a->_a_prio; | ||
| 23 | 	return 0; | ||
| 24 | } | ||
| 25 | |||
| 26 | int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy) | ||
| 27 | { | ||
| 28 | 	*policy = a->_a_policy; | ||
| 29 | 	return 0; | ||
| 30 | } | ||
| 31 | |||
| 32 | int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope) | ||
| 33 | { | ||
| 34 | 	*scope = PTHREAD_SCOPE_SYSTEM; | ||
| 35 | 	return 0; | ||
| 36 | } | ||
| 37 | |||
| 38 | int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size) | ||
| 39 | { | ||
| 40 | 	if (!a->_a_stackaddr) | ||
| 41 | 		return EINVAL; | ||
| 42 | 	*size = a->_a_stacksize; | ||
| 43 | 	*addr = (void *)(a->_a_stackaddr - *size); | ||
| 44 | 	return 0; | ||
| 45 | } | ||
| 46 | |||
| 47 | int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) | ||
| 48 | { | ||
| 49 | 	*size = a->_a_stacksize; | ||
| 50 | 	return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared) | ||
| 54 | { | ||
| 55 | 	*pshared = !!a->__attr; | ||
| 56 | 	return 0; | ||
| 57 | } | ||
| 58 | |||
| 59 | int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) | ||
| 60 | { | ||
| 61 | 	*clk = a->__attr & 0x7fffffff; | ||
| 62 | 	return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared) | ||
| 66 | { | ||
| 67 | 	*pshared = a->__attr>>31; | ||
| 68 | 	return 0; | ||
| 69 | } | ||
| 70 | |||
| 71 | int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol) | ||
| 72 | { | ||
| 73 | 	*protocol = a->__attr / 8U % 2; | ||
| 74 | 	return 0; | ||
| 75 | } | ||
| 76 | int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared) | ||
| 77 | { | ||
| 78 | 	*pshared = a->__attr / 128U % 2; | ||
| 79 | 	return 0; | ||
| 80 | } | ||
| 81 | |||
| 82 | int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) | ||
| 83 | { | ||
| 84 | 	*robust = a->__attr / 4U % 2; | ||
| 85 | 	return 0; | ||
| 86 | } | ||
| 87 | |||
| 88 | int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type) | ||
| 89 | { | ||
| 90 | 	*type = a->__attr & 3; | ||
| 91 | 	return 0; | ||
| 92 | } | ||
| 93 | |||
| 94 | int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared) | ||
| 95 | { | ||
| 96 | 	*pshared = a->__attr[0]; | ||
| 97 | 	return 0; | ||
| 98 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_init.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_init(pthread_attr_t *a) | ||
| 4 | { | ||
| 5 | 	*a = (pthread_attr_t){0}; | ||
| 6 | 	__acquire_ptc(); | ||
| 7 | 	a->_a_stacksize = __default_stacksize; | ||
| 8 | 	a->_a_guardsize = __default_guardsize; | ||
| 9 | 	__release_ptc(); | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setdetachstate.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setdetachstate(pthread_attr_t *a, int state) | ||
| 4 | { | ||
| 5 | 	if (state > 1U) return EINVAL; | ||
| 6 | 	a->_a_detach = state; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setguardsize.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setguardsize(pthread_attr_t *a, size_t size) | ||
| 4 | { | ||
| 5 | 	if (size > SIZE_MAX/8) return EINVAL; | ||
| 6 | 	a->_a_guardsize = size; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setinheritsched.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int pthread_attr_setinheritsched(pthread_attr_t *a, int inherit) | ||
| 5 | { | ||
| 6 | 	if (inherit > 1U) return EINVAL; | ||
| 7 | 	a->_a_sched = inherit; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedparam.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setschedparam(pthread_attr_t *restrict a, const struct sched_param *restrict param) | ||
| 4 | { | ||
| 5 | 	a->_a_prio = param->sched_priority; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setschedpolicy.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setschedpolicy(pthread_attr_t *a, int policy) | ||
| 4 | { | ||
| 5 | 	a->_a_policy = policy; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setscope.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setscope(pthread_attr_t *a, int scope) | ||
| 4 | { | ||
| 5 | 	switch (scope) { | ||
| 6 | 	case PTHREAD_SCOPE_SYSTEM: | ||
| 7 | 		return 0; | ||
| 8 | 	case PTHREAD_SCOPE_PROCESS: | ||
| 9 | 		return ENOTSUP; | ||
| 10 | 	default: | ||
| 11 | 		return EINVAL; | ||
| 12 | 	} | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setstack.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setstack(pthread_attr_t *a, void *addr, size_t size) | ||
| 4 | { | ||
| 5 | 	if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL; | ||
| 6 | 	a->_a_stackaddr = (size_t)addr + size; | ||
| 7 | 	a->_a_stacksize = size; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_attr_setstacksize.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_attr_setstacksize(pthread_attr_t *a, size_t size) | ||
| 4 | { | ||
| 5 | 	if (size-PTHREAD_STACK_MIN > SIZE_MAX/4) return EINVAL; | ||
| 6 | 	a->_a_stackaddr = 0; | ||
| 7 | 	a->_a_stacksize = size; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_destroy.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrier_destroy(pthread_barrier_t *b) | ||
| 4 | { | ||
| 5 | 	if (b->_b_limit < 0) { | ||
| 6 | 		if (b->_b_lock) { | ||
| 7 | 			int v; | ||
| 8 | 			a_or(&b->_b_lock, INT_MIN); | ||
| 9 | 			while ((v = b->_b_lock) & INT_MAX) | ||
| 10 | 				__wait(&b->_b_lock, 0, v, 0); | ||
| 11 | 		} | ||
| 12 | 		__vm_wait(); | ||
| 13 | 	} | ||
| 14 | 	return 0; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_init.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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 | (a?a->__attr:0) }; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrier_wait.c created+111| ... | @@ -0,0 +1,111 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static int pshared_barrier_wait(pthread_barrier_t *b) | ||
| 4 | { | ||
| 5 | 	int limit = (b->_b_limit & INT_MAX) + 1; | ||
| 6 | 	int ret = 0; | ||
| 7 | 	int v, w; | ||
| 8 | |||
| 9 | 	if (limit==1) return PTHREAD_BARRIER_SERIAL_THREAD; | ||
| 10 | |||
| 11 | 	while ((v=a_cas(&b->_b_lock, 0, limit))) | ||
| 12 | 		__wait(&b->_b_lock, &b->_b_waiters, v, 0); | ||
| 13 | |||
| 14 | 	/* Wait for <limit> threads to get to the barrier */ | ||
| 15 | 	if (++b->_b_count == limit) { | ||
| 16 | 		a_store(&b->_b_count, 0); | ||
| 17 | 		ret = PTHREAD_BARRIER_SERIAL_THREAD; | ||
| 18 | 		if (b->_b_waiters2) __wake(&b->_b_count, -1, 0); | ||
| 19 | 	} else { | ||
| 20 | 		a_store(&b->_b_lock, 0); | ||
| 21 | 		if (b->_b_waiters) __wake(&b->_b_lock, 1, 0); | ||
| 22 | 		while ((v=b->_b_count)>0) | ||
| 23 | 			__wait(&b->_b_count, &b->_b_waiters2, v, 0); | ||
| 24 | 	} | ||
| 25 | |||
| 26 | 	__vm_lock(); | ||
| 27 | |||
| 28 | 	/* Ensure all threads have a vm lock before proceeding */ | ||
| 29 | 	if (a_fetch_add(&b->_b_count, -1)==1-limit) { | ||
| 30 | 		a_store(&b->_b_count, 0); | ||
| 31 | 		if (b->_b_waiters2) __wake(&b->_b_count, -1, 0); | ||
| 32 | 	} else { | ||
| 33 | 		while ((v=b->_b_count)) | ||
| 34 | 			__wait(&b->_b_count, &b->_b_waiters2, v, 0); | ||
| 35 | 	} | ||
| 36 | 	 | ||
| 37 | 	/* Perform a recursive unlock suitable for self-sync'd destruction */ | ||
| 38 | 	do { | ||
| 39 | 		v = b->_b_lock; | ||
| 40 | 		w = b->_b_waiters; | ||
| 41 | 	} while (a_cas(&b->_b_lock, v, v==INT_MIN+1 ? 0 : v-1) != v); | ||
| 42 | |||
| 43 | 	/* Wake a thread waiting to reuse or destroy the barrier */ | ||
| 44 | 	if (v==INT_MIN+1 || (v==1 && w)) | ||
| 45 | 		__wake(&b->_b_lock, 1, 0); | ||
| 46 | |||
| 47 | 	__vm_unlock(); | ||
| 48 | |||
| 49 | 	return ret; | ||
| 50 | } | ||
| 51 | |||
| 52 | struct instance | ||
| 53 | { | ||
| 54 | 	volatile int count; | ||
| 55 | 	volatile int last; | ||
| 56 | 	volatile int waiters; | ||
| 57 | 	volatile int finished; | ||
| 58 | }; | ||
| 59 | |||
| 60 | int pthread_barrier_wait(pthread_barrier_t *b) | ||
| 61 | { | ||
| 62 | 	int limit = b->_b_limit; | ||
| 63 | 	struct instance *inst; | ||
| 64 | |||
| 65 | 	/* Trivial case: count was set at 1 */ | ||
| 66 | 	if (!limit) return PTHREAD_BARRIER_SERIAL_THREAD; | ||
| 67 | |||
| 68 | 	/* Process-shared barriers require a separate, inefficient wait */ | ||
| 69 | 	if (limit < 0) return pshared_barrier_wait(b); | ||
| 70 | |||
| 71 | 	/* Otherwise we need a lock on the barrier object */ | ||
| 72 | 	while (a_swap(&b->_b_lock, 1)) | ||
| 73 | 		__wait(&b->_b_lock, &b->_b_waiters, 1, 1); | ||
| 74 | 	inst = b->_b_inst; | ||
| 75 | |||
| 76 | 	/* First thread to enter the barrier becomes the "instance owner" */ | ||
| 77 | 	if (!inst) { | ||
| 78 | 		struct instance new_inst = { 0 }; | ||
| 79 | 		int spins = 200; | ||
| 80 | 		b->_b_inst = inst = &new_inst; | ||
| 81 | 		a_store(&b->_b_lock, 0); | ||
| 82 | 		if (b->_b_waiters) __wake(&b->_b_lock, 1, 1); | ||
| 83 | 		while (spins-- && !inst->finished) | ||
| 84 | 			a_spin(); | ||
| 85 | 		a_inc(&inst->finished); | ||
| 86 | 		while (inst->finished == 1) | ||
| 87 | 			__syscall(SYS_futex,&inst->finished,FUTEX_WAIT|FUTEX_PRIVATE,1,0) != -ENOSYS | ||
| 88 | 			|| __syscall(SYS_futex,&inst->finished,FUTEX_WAIT,1,0); | ||
| 89 | 		return PTHREAD_BARRIER_SERIAL_THREAD; | ||
| 90 | 	} | ||
| 91 | |||
| 92 | 	/* Last thread to enter the barrier wakes all non-instance-owners */ | ||
| 93 | 	if (++inst->count == limit) { | ||
| 94 | 		b->_b_inst = 0; | ||
| 95 | 		a_store(&b->_b_lock, 0); | ||
| 96 | 		if (b->_b_waiters) __wake(&b->_b_lock, 1, 1); | ||
| 97 | 		a_store(&inst->last, 1); | ||
| 98 | 		if (inst->waiters) | ||
| 99 | 			__wake(&inst->last, -1, 1); | ||
| 100 | 	} else { | ||
| 101 | 		a_store(&b->_b_lock, 0); | ||
| 102 | 		if (b->_b_waiters) __wake(&b->_b_lock, 1, 1); | ||
| 103 | 		__wait(&inst->last, &inst->waiters, 0, 1); | ||
| 104 | 	} | ||
| 105 | |||
| 106 | 	/* Last thread to exit the barrier wakes the instance owner */ | ||
| 107 | 	if (a_fetch_add(&inst->count,-1)==1 && a_fetch_add(&inst->finished,1)) | ||
| 108 | 		__wake(&inst->finished, 1, 1); | ||
| 109 | |||
| 110 | 	return 0; | ||
| 111 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrierattr_destroy(pthread_barrierattr_t *a) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrierattr_init(pthread_barrierattr_t *a) | ||
| 4 | { | ||
| 5 | 	*a = (pthread_barrierattr_t){0}; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_barrierattr_setpshared.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_barrierattr_setpshared(pthread_barrierattr_t *a, int pshared) | ||
| 4 | { | ||
| 5 | 	if (pshared > 1U) return EINVAL; | ||
| 6 | 	a->__attr = pshared ? INT_MIN : 0; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cancel.c created+101| ... | @@ -0,0 +1,101 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <string.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c(); | ||
| 7 | |||
| 8 | long __cancel() | ||
| 9 | { | ||
| 10 | 	pthread_t self = __pthread_self(); | ||
| 11 | 	if (self->canceldisable == PTHREAD_CANCEL_ENABLE || self->cancelasync) | ||
| 12 | 		pthread_exit(PTHREAD_CANCELED); | ||
| 13 | 	self->canceldisable = PTHREAD_CANCEL_DISABLE; | ||
| 14 | 	return -ECANCELED; | ||
| 15 | } | ||
| 16 | |||
| 17 | long __syscall_cp_asm(volatile void *, syscall_arg_t, | ||
| 18 | syscall_arg_t, syscall_arg_t, syscall_arg_t, | ||
| 19 | syscall_arg_t, syscall_arg_t, syscall_arg_t); | ||
| 20 | |||
| 21 | long __syscall_cp_c(syscall_arg_t nr, | ||
| 22 | syscall_arg_t u, syscall_arg_t v, syscall_arg_t w, | ||
| 23 | syscall_arg_t x, syscall_arg_t y, syscall_arg_t z) | ||
| 24 | { | ||
| 25 | 	pthread_t self; | ||
| 26 | 	long r; | ||
| 27 | 	int st; | ||
| 28 | |||
| 29 | 	if ((st=(self=__pthread_self())->canceldisable) | ||
| 30 | 	 && (st==PTHREAD_CANCEL_DISABLE || nr==SYS_close)) | ||
| 31 | 		return __syscall(nr, u, v, w, x, y, z); | ||
| 32 | |||
| 33 | 	r = __syscall_cp_asm(&self->cancel, nr, u, v, w, x, y, z); | ||
| 34 | 	if (r==-EINTR && nr!=SYS_close && self->cancel && | ||
| 35 | 	 self->canceldisable != PTHREAD_CANCEL_DISABLE) | ||
| 36 | 		r = __cancel(); | ||
| 37 | 	return r; | ||
| 38 | } | ||
| 39 | |||
| 40 | static void _sigaddset(sigset_t *set, int sig) | ||
| 41 | { | ||
| 42 | 	unsigned s = sig-1; | ||
| 43 | 	set->__bits[s/8/sizeof *set->__bits] |= 1UL<<(s&8*sizeof *set->__bits-1); | ||
| 44 | } | ||
| 45 | |||
| 46 | extern hidden const char __cp_begin[1], __cp_end[1], __cp_cancel[1]; | ||
| 47 | |||
| 48 | static void cancel_handler(int sig, siginfo_t *si, void *ctx) | ||
| 49 | { | ||
| 50 | 	pthread_t self = __pthread_self(); | ||
| 51 | 	ucontext_t *uc = ctx; | ||
| 52 | 	uintptr_t pc = uc->uc_mcontext.MC_PC; | ||
| 53 | |||
| 54 | 	a_barrier(); | ||
| 55 | 	if (!self->cancel || self->canceldisable == PTHREAD_CANCEL_DISABLE) return; | ||
| 56 | |||
| 57 | 	_sigaddset(&uc->uc_sigmask, SIGCANCEL); | ||
| 58 | |||
| 59 | 	if (self->cancelasync || pc >= (uintptr_t)__cp_begin && pc < (uintptr_t)__cp_end) { | ||
| 60 | 		uc->uc_mcontext.MC_PC = (uintptr_t)__cp_cancel; | ||
| 61 | #ifdef CANCEL_GOT | ||
| 62 | 		uc->uc_mcontext.MC_GOT = CANCEL_GOT; | ||
| 63 | #endif | ||
| 64 | 		return; | ||
| 65 | 	} | ||
| 66 | |||
| 67 | 	__syscall(SYS_tkill, self->tid, SIGCANCEL); | ||
| 68 | } | ||
| 69 | |||
| 70 | void __testcancel() | ||
| 71 | { | ||
| 72 | 	pthread_t self = __pthread_self(); | ||
| 73 | 	if (self->cancel && !self->canceldisable) | ||
| 74 | 		__cancel(); | ||
| 75 | } | ||
| 76 | |||
| 77 | static void init_cancellation() | ||
| 78 | { | ||
| 79 | 	struct sigaction sa = { | ||
| 80 | 		.sa_flags = SA_SIGINFO | SA_RESTART, | ||
| 81 | 		.sa_sigaction = cancel_handler | ||
| 82 | 	}; | ||
| 83 | 	memset(&sa.sa_mask, -1, _NSIG/8); | ||
| 84 | 	__libc_sigaction(SIGCANCEL, &sa, 0); | ||
| 85 | } | ||
| 86 | |||
| 87 | int pthread_cancel(pthread_t t) | ||
| 88 | { | ||
| 89 | 	static int init; | ||
| 90 | 	if (!init) { | ||
| 91 | 		init_cancellation(); | ||
| 92 | 		init = 1; | ||
| 93 | 	} | ||
| 94 | 	a_store(&t->cancel, 1); | ||
| 95 | 	if (t == pthread_self()) { | ||
| 96 | 		if (t->canceldisable == PTHREAD_CANCEL_ENABLE && t->cancelasync) | ||
| 97 | 			pthread_exit(PTHREAD_CANCELED); | ||
| 98 | 		return 0; | ||
| 99 | 	} | ||
| 100 | 	return pthread_kill(t, SIGCANCEL); | ||
| 101 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cleanup_push.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static void dummy(struct __ptcb *cb) | ||
| 4 | { | ||
| 5 | } | ||
| 6 | weak_alias(dummy, __do_cleanup_push); | ||
| 7 | weak_alias(dummy, __do_cleanup_pop); | ||
| 8 | |||
| 9 | void _pthread_cleanup_push(struct __ptcb *cb, void (*f)(void *), void *x) | ||
| 10 | { | ||
| 11 | 	cb->__f = f; | ||
| 12 | 	cb->__x = x; | ||
| 13 | 	__do_cleanup_push(cb); | ||
| 14 | } | ||
| 15 | |||
| 16 | void _pthread_cleanup_pop(struct __ptcb *cb, int run) | ||
| 17 | { | ||
| 18 | 	__do_cleanup_pop(cb); | ||
| 19 | 	if (run) cb->__f(cb->__x); | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_broadcast.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_broadcast(pthread_cond_t *c) | ||
| 4 | { | ||
| 5 | 	if (!c->_c_shared) return __private_cond_signal(c, -1); | ||
| 6 | 	if (!c->_c_waiters) return 0; | ||
| 7 | 	a_inc(&c->_c_seq); | ||
| 8 | 	__wake(&c->_c_seq, -1, 0); | ||
| 9 | 	return 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_destroy.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_destroy(pthread_cond_t *c) | ||
| 4 | { | ||
| 5 | 	if (c->_c_shared && c->_c_waiters) { | ||
| 6 | 		int cnt; | ||
| 7 | 		a_or(&c->_c_waiters, 0x80000000); | ||
| 8 | 		a_inc(&c->_c_seq); | ||
| 9 | 		__wake(&c->_c_seq, -1, 0); | ||
| 10 | 		while ((cnt = c->_c_waiters) & 0x7fffffff) | ||
| 11 | 			__wait(&c->_c_waiters, 0, cnt, 0); | ||
| 12 | 	} | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_init.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_init(pthread_cond_t *restrict c, const pthread_condattr_t *restrict a) | ||
| 4 | { | ||
| 5 | 	*c = (pthread_cond_t){0}; | ||
| 6 | 	if (a) { | ||
| 7 | 		c->_c_clock = a->__attr & 0x7fffffff; | ||
| 8 | 		if (a->__attr>>31) c->_c_shared = (void *)-1; | ||
| 9 | 	} | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_signal.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_signal(pthread_cond_t *c) | ||
| 4 | { | ||
| 5 | 	if (!c->_c_shared) return __private_cond_signal(c, 1); | ||
| 6 | 	if (!c->_c_waiters) return 0; | ||
| 7 | 	a_inc(&c->_c_seq); | ||
| 8 | 	__wake(&c->_c_seq, 1, 0); | ||
| 9 | 	return 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_timedwait.c created+213| ... | @@ -0,0 +1,213 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | /* | ||
| 4 | * struct waiter | ||
| 5 | * | ||
| 6 | * Waiter objects have automatic storage on the waiting thread, and | ||
| 7 | * are used in building a linked list representing waiters currently | ||
| 8 | * waiting on the condition variable or a group of waiters woken | ||
| 9 | * together by a broadcast or signal; in the case of signal, this is a | ||
| 10 | * degenerate list of one member. | ||
| 11 | * | ||
| 12 | * Waiter lists attached to the condition variable itself are | ||
| 13 | * protected by the lock on the cv. Detached waiter lists are never | ||
| 14 | * modified again, but can only be traversed in reverse order, and are | ||
| 15 | * protected by the "barrier" locks in each node, which are unlocked | ||
| 16 | * in turn to control wake order. | ||
| 17 | * | ||
| 18 | * Since process-shared cond var semantics do not necessarily allow | ||
| 19 | * one thread to see another's automatic storage (they may be in | ||
| 20 | * different processes), the waiter list is not used for the | ||
| 21 | * process-shared case, but the structure is still used to store data | ||
| 22 | * needed by the cancellation cleanup handler. | ||
| 23 | */ | ||
| 24 | |||
| 25 | struct waiter { | ||
| 26 | 	struct waiter *prev, *next; | ||
| 27 | 	volatile int state, barrier; | ||
| 28 | 	volatile int *notify; | ||
| 29 | }; | ||
| 30 | |||
| 31 | /* Self-synchronized-destruction-safe lock functions */ | ||
| 32 | |||
| 33 | static inline void lock(volatile int *l) | ||
| 34 | { | ||
| 35 | 	if (a_cas(l, 0, 1)) { | ||
| 36 | 		a_cas(l, 1, 2); | ||
| 37 | 		do __wait(l, 0, 2, 1); | ||
| 38 | 		while (a_cas(l, 0, 2)); | ||
| 39 | 	} | ||
| 40 | } | ||
| 41 | |||
| 42 | static inline void unlock(volatile int *l) | ||
| 43 | { | ||
| 44 | 	if (a_swap(l, 0)==2) | ||
| 45 | 		__wake(l, 1, 1); | ||
| 46 | } | ||
| 47 | |||
| 48 | static inline void unlock_requeue(volatile int *l, volatile int *r, int w) | ||
| 49 | { | ||
| 50 | 	a_store(l, 0); | ||
| 51 | 	if (w) __wake(l, 1, 1); | ||
| 52 | 	else __syscall(SYS_futex, l, FUTEX_REQUEUE|FUTEX_PRIVATE, 0, 1, r) != -ENOSYS | ||
| 53 | 		|| __syscall(SYS_futex, l, FUTEX_REQUEUE, 0, 1, r); | ||
| 54 | } | ||
| 55 | |||
| 56 | enum { | ||
| 57 | 	WAITING, | ||
| 58 | 	SIGNALED, | ||
| 59 | 	LEAVING, | ||
| 60 | }; | ||
| 61 | |||
| 62 | int __pthread_cond_timedwait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m, const struct timespec *restrict ts) | ||
| 63 | { | ||
| 64 | 	struct waiter node = { 0 }; | ||
| 65 | 	int e, seq, clock = c->_c_clock, cs, shared=0, oldstate, tmp; | ||
| 66 | 	volatile int *fut; | ||
| 67 | |||
| 68 | 	if ((m->_m_type&15) && (m->_m_lock&INT_MAX) != __pthread_self()->tid) | ||
| 69 | 		return EPERM; | ||
| 70 | |||
| 71 | 	if (ts && ts->tv_nsec >= 1000000000UL) | ||
| 72 | 		return EINVAL; | ||
| 73 | |||
| 74 | 	__pthread_testcancel(); | ||
| 75 | |||
| 76 | 	if (c->_c_shared) { | ||
| 77 | 		shared = 1; | ||
| 78 | 		fut = &c->_c_seq; | ||
| 79 | 		seq = c->_c_seq; | ||
| 80 | 		a_inc(&c->_c_waiters); | ||
| 81 | 	} else { | ||
| 82 | 		lock(&c->_c_lock); | ||
| 83 | |||
| 84 | 		seq = node.barrier = 2; | ||
| 85 | 		fut = &node.barrier; | ||
| 86 | 		node.state = WAITING; | ||
| 87 | 		node.next = c->_c_head; | ||
| 88 | 		c->_c_head = &node; | ||
| 89 | 		if (!c->_c_tail) c->_c_tail = &node; | ||
| 90 | 		else node.next->prev = &node; | ||
| 91 | |||
| 92 | 		unlock(&c->_c_lock); | ||
| 93 | 	} | ||
| 94 | |||
| 95 | 	__pthread_mutex_unlock(m); | ||
| 96 | |||
| 97 | 	__pthread_setcancelstate(PTHREAD_CANCEL_MASKED, &cs); | ||
| 98 | 	if (cs == PTHREAD_CANCEL_DISABLE) __pthread_setcancelstate(cs, 0); | ||
| 99 | |||
| 100 | 	do e = __timedwait_cp(fut, seq, clock, ts, !shared); | ||
| 101 | 	while (*fut==seq && (!e || e==EINTR)); | ||
| 102 | 	if (e == EINTR) e = 0; | ||
| 103 | |||
| 104 | 	if (shared) { | ||
| 105 | 		/* Suppress cancellation if a signal was potentially | ||
| 106 | 		 * consumed; this is a legitimate form of spurious | ||
| 107 | 		 * wake even if not. */ | ||
| 108 | 		if (e == ECANCELED && c->_c_seq != seq) e = 0; | ||
| 109 | 		if (a_fetch_add(&c->_c_waiters, -1) == -0x7fffffff) | ||
| 110 | 			__wake(&c->_c_waiters, 1, 0); | ||
| 111 | 		oldstate = WAITING; | ||
| 112 | 		goto relock; | ||
| 113 | 	} | ||
| 114 | |||
| 115 | 	oldstate = a_cas(&node.state, WAITING, LEAVING); | ||
| 116 | |||
| 117 | 	if (oldstate == WAITING) { | ||
| 118 | 		/* Access to cv object is valid because this waiter was not | ||
| 119 | 		 * yet signaled and a new signal/broadcast cannot return | ||
| 120 | 		 * after seeing a LEAVING waiter without getting notified | ||
| 121 | 		 * via the futex notify below. */ | ||
| 122 | |||
| 123 | 		lock(&c->_c_lock); | ||
| 124 | 		 | ||
| 125 | 		if (c->_c_head == &node) c->_c_head = node.next; | ||
| 126 | 		else if (node.prev) node.prev->next = node.next; | ||
| 127 | 		if (c->_c_tail == &node) c->_c_tail = node.prev; | ||
| 128 | 		else if (node.next) node.next->prev = node.prev; | ||
| 129 | 		 | ||
| 130 | 		unlock(&c->_c_lock); | ||
| 131 | |||
| 132 | 		if (node.notify) { | ||
| 133 | 			if (a_fetch_add(node.notify, -1)==1) | ||
| 134 | 				__wake(node.notify, 1, 1); | ||
| 135 | 		} | ||
| 136 | 	} else { | ||
| 137 | 		/* Lock barrier first to control wake order. */ | ||
| 138 | 		lock(&node.barrier); | ||
| 139 | 	} | ||
| 140 | |||
| 141 | relock: | ||
| 142 | 	/* Errors locking the mutex override any existing error or | ||
| 143 | 	 * cancellation, since the caller must see them to know the | ||
| 144 | 	 * state of the mutex. */ | ||
| 145 | 	if ((tmp = pthread_mutex_lock(m))) e = tmp; | ||
| 146 | |||
| 147 | 	if (oldstate == WAITING) goto done; | ||
| 148 | |||
| 149 | 	if (!node.next && !(m->_m_type & 8)) | ||
| 150 | 		a_inc(&m->_m_waiters); | ||
| 151 | |||
| 152 | 	/* Unlock the barrier that's holding back the next waiter, and | ||
| 153 | 	 * either wake it or requeue it to the mutex. */ | ||
| 154 | 	if (node.prev) { | ||
| 155 | 		int val = m->_m_lock; | ||
| 156 | 		if (val>0) a_cas(&m->_m_lock, val, val|0x80000000); | ||
| 157 | 		unlock_requeue(&node.prev->barrier, &m->_m_lock, m->_m_type & (8|128)); | ||
| 158 | 	} else if (!(m->_m_type & 8)) { | ||
| 159 | 		a_dec(&m->_m_waiters);		 | ||
| 160 | 	} | ||
| 161 | |||
| 162 | 	/* Since a signal was consumed, cancellation is not permitted. */ | ||
| 163 | 	if (e == ECANCELED) e = 0; | ||
| 164 | |||
| 165 | done: | ||
| 166 | 	__pthread_setcancelstate(cs, 0); | ||
| 167 | |||
| 168 | 	if (e == ECANCELED) { | ||
| 169 | 		__pthread_testcancel(); | ||
| 170 | 		__pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, 0); | ||
| 171 | 	} | ||
| 172 | |||
| 173 | 	return e; | ||
| 174 | } | ||
| 175 | |||
| 176 | int __private_cond_signal(pthread_cond_t *c, int n) | ||
| 177 | { | ||
| 178 | 	struct waiter *p, *first=0; | ||
| 179 | 	volatile int ref = 0; | ||
| 180 | 	int cur; | ||
| 181 | |||
| 182 | 	lock(&c->_c_lock); | ||
| 183 | 	for (p=c->_c_tail; n && p; p=p->prev) { | ||
| 184 | 		if (a_cas(&p->state, WAITING, SIGNALED) != WAITING) { | ||
| 185 | 			ref++; | ||
| 186 | 			p->notify = &ref; | ||
| 187 | 		} else { | ||
| 188 | 			n--; | ||
| 189 | 			if (!first) first=p; | ||
| 190 | 		} | ||
| 191 | 	} | ||
| 192 | 	/* Split the list, leaving any remainder on the cv. */ | ||
| 193 | 	if (p) { | ||
| 194 | 		if (p->next) p->next->prev = 0; | ||
| 195 | 		p->next = 0; | ||
| 196 | 	} else { | ||
| 197 | 		c->_c_head = 0; | ||
| 198 | 	} | ||
| 199 | 	c->_c_tail = p; | ||
| 200 | 	unlock(&c->_c_lock); | ||
| 201 | |||
| 202 | 	/* Wait for any waiters in the LEAVING state to remove | ||
| 203 | 	 * themselves from the list before returning or allowing | ||
| 204 | 	 * signaled threads to proceed. */ | ||
| 205 | 	while ((cur = ref)) __wait(&ref, 0, cur, 1); | ||
| 206 | |||
| 207 | 	/* Allow first signaled waiter, if any, to proceed. */ | ||
| 208 | 	if (first) unlock(&first->barrier); | ||
| 209 | |||
| 210 | 	return 0; | ||
| 211 | } | ||
| 212 | |||
| 213 | weak_alias(__pthread_cond_timedwait, pthread_cond_timedwait); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_cond_wait.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_cond_wait(pthread_cond_t *restrict c, pthread_mutex_t *restrict m) | ||
| 4 | { | ||
| 5 | 	return pthread_cond_timedwait(c, m, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_condattr_destroy(pthread_condattr_t *a) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_condattr_init(pthread_condattr_t *a) | ||
| 4 | { | ||
| 5 | 	*a = (pthread_condattr_t){0}; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setclock.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_condattr_setclock(pthread_condattr_t *a, clockid_t clk) | ||
| 4 | { | ||
| 5 | 	if (clk < 0 || clk-2U < 2) return EINVAL; | ||
| 6 | 	a->__attr &= 0x80000000; | ||
| 7 | 	a->__attr |= clk; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_condattr_setpshared.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_condattr_setpshared(pthread_condattr_t *a, int pshared) | ||
| 4 | { | ||
| 5 | 	if (pshared > 1U) return EINVAL; | ||
| 6 | 	a->__attr &= 0x7fffffff; | ||
| 7 | 	a->__attr |= (unsigned)pshared<<31; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_create.c created+393| ... | @@ -0,0 +1,393 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | #include "stdio_impl.h" | ||
| 4 | #include "libc.h" | ||
| 5 | #include "lock.h" | ||
| 6 | #include <sys/mman.h> | ||
| 7 | #include <string.h> | ||
| 8 | #include <stddef.h> | ||
| 9 | |||
| 10 | static void dummy_0() | ||
| 11 | { | ||
| 12 | } | ||
| 13 | weak_alias(dummy_0, __acquire_ptc); | ||
| 14 | weak_alias(dummy_0, __release_ptc); | ||
| 15 | weak_alias(dummy_0, __pthread_tsd_run_dtors); | ||
| 16 | weak_alias(dummy_0, __do_orphaned_stdio_locks); | ||
| 17 | weak_alias(dummy_0, __dl_thread_cleanup); | ||
| 18 | weak_alias(dummy_0, __membarrier_init); | ||
| 19 | |||
| 20 | static int tl_lock_count; | ||
| 21 | static int tl_lock_waiters; | ||
| 22 | |||
| 23 | void __tl_lock(void) | ||
| 24 | { | ||
| 25 | 	int tid = __pthread_self()->tid; | ||
| 26 | 	int val = __thread_list_lock; | ||
| 27 | 	if (val == tid) { | ||
| 28 | 		tl_lock_count++; | ||
| 29 | 		return; | ||
| 30 | 	} | ||
| 31 | 	while ((val = a_cas(&__thread_list_lock, 0, tid))) | ||
| 32 | 		__wait(&__thread_list_lock, &tl_lock_waiters, val, 0); | ||
| 33 | } | ||
| 34 | |||
| 35 | void __tl_unlock(void) | ||
| 36 | { | ||
| 37 | 	if (tl_lock_count) { | ||
| 38 | 		tl_lock_count--; | ||
| 39 | 		return; | ||
| 40 | 	} | ||
| 41 | 	a_store(&__thread_list_lock, 0); | ||
| 42 | 	if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0); | ||
| 43 | } | ||
| 44 | |||
| 45 | void __tl_sync(pthread_t td) | ||
| 46 | { | ||
| 47 | 	a_barrier(); | ||
| 48 | 	int val = __thread_list_lock; | ||
| 49 | 	if (!val) return; | ||
| 50 | 	__wait(&__thread_list_lock, &tl_lock_waiters, val, 0); | ||
| 51 | 	if (tl_lock_waiters) __wake(&__thread_list_lock, 1, 0); | ||
| 52 | } | ||
| 53 | |||
| 54 | _Noreturn void __pthread_exit(void *result) | ||
| 55 | { | ||
| 56 | 	pthread_t self = __pthread_self(); | ||
| 57 | 	sigset_t set; | ||
| 58 | |||
| 59 | 	self->canceldisable = 1; | ||
| 60 | 	self->cancelasync = 0; | ||
| 61 | 	self->result = result; | ||
| 62 | |||
| 63 | 	while (self->cancelbuf) { | ||
| 64 | 		void (*f)(void *) = self->cancelbuf->__f; | ||
| 65 | 		void *x = self->cancelbuf->__x; | ||
| 66 | 		self->cancelbuf = self->cancelbuf->__next; | ||
| 67 | 		f(x); | ||
| 68 | 	} | ||
| 69 | |||
| 70 | 	__pthread_tsd_run_dtors(); | ||
| 71 | |||
| 72 | 	__block_app_sigs(&set); | ||
| 73 | |||
| 74 | 	/* This atomic potentially competes with a concurrent pthread_detach | ||
| 75 | 	 * call; the loser is responsible for freeing thread resources. */ | ||
| 76 | 	int state = a_cas(&self->detach_state, DT_JOINABLE, DT_EXITING); | ||
| 77 | |||
| 78 | 	if (state==DT_DETACHED && self->map_base) { | ||
| 79 | 		/* Since __unmapself bypasses the normal munmap code path, | ||
| 80 | 		 * explicitly wait for vmlock holders first. This must be | ||
| 81 | 		 * done before any locks are taken, to avoid lock ordering | ||
| 82 | 		 * issues that could lead to deadlock. */ | ||
| 83 | 		__vm_wait(); | ||
| 84 | 	} | ||
| 85 | |||
| 86 | 	/* Access to target the exiting thread with syscalls that use | ||
| 87 | 	 * its kernel tid is controlled by killlock. For detached threads, | ||
| 88 | 	 * any use past this point would have undefined behavior, but for | ||
| 89 | 	 * joinable threads it's a valid usage that must be handled. | ||
| 90 | 	 * Signals must be blocked since pthread_kill must be AS-safe. */ | ||
| 91 | 	LOCK(self->killlock); | ||
| 92 | |||
| 93 | 	/* The thread list lock must be AS-safe, and thus depends on | ||
| 94 | 	 * application signals being blocked above. */ | ||
| 95 | 	__tl_lock(); | ||
| 96 | |||
| 97 | 	/* If this is the only thread in the list, don't proceed with | ||
| 98 | 	 * termination of the thread, but restore the previous lock and | ||
| 99 | 	 * signal state to prepare for exit to call atexit handlers. */ | ||
| 100 | 	if (self->next == self) { | ||
| 101 | 		__tl_unlock(); | ||
| 102 | 		UNLOCK(self->killlock); | ||
| 103 | 		self->detach_state = state; | ||
| 104 | 		__restore_sigs(&set); | ||
| 105 | 		exit(0); | ||
| 106 | 	} | ||
| 107 | |||
| 108 | 	/* At this point we are committed to thread termination. */ | ||
| 109 | |||
| 110 | 	/* Process robust list in userspace to handle non-pshared mutexes | ||
| 111 | 	 * and the detached thread case where the robust list head will | ||
| 112 | 	 * be invalid when the kernel would process it. */ | ||
| 113 | 	__vm_lock(); | ||
| 114 | 	volatile void *volatile *rp; | ||
| 115 | 	while ((rp=self->robust_list.head) && rp != &self->robust_list.head) { | ||
| 116 | 		pthread_mutex_t *m = (void *)((char *)rp | ||
| 117 | 			- offsetof(pthread_mutex_t, _m_next)); | ||
| 118 | 		int waiters = m->_m_waiters; | ||
| 119 | 		int priv = (m->_m_type & 128) ^ 128; | ||
| 120 | 		self->robust_list.pending = rp; | ||
| 121 | 		self->robust_list.head = *rp; | ||
| 122 | 		int cont = a_swap(&m->_m_lock, 0x40000000); | ||
| 123 | 		self->robust_list.pending = 0; | ||
| 124 | 		if (cont < 0 || waiters) | ||
| 125 | 			__wake(&m->_m_lock, 1, priv); | ||
| 126 | 	} | ||
| 127 | 	__vm_unlock(); | ||
| 128 | |||
| 129 | 	__do_orphaned_stdio_locks(); | ||
| 130 | 	__dl_thread_cleanup(); | ||
| 131 | |||
| 132 | 	/* Last, unlink thread from the list. This change will not be visible | ||
| 133 | 	 * until the lock is released, which only happens after SYS_exit | ||
| 134 | 	 * has been called, via the exit futex address pointing at the lock. | ||
| 135 | 	 * This needs to happen after any possible calls to LOCK() that might | ||
| 136 | 	 * skip locking if process appears single-threaded. */ | ||
| 137 | 	if (!--libc.threads_minus_1) libc.need_locks = -1; | ||
| 138 | 	self->next->prev = self->prev; | ||
| 139 | 	self->prev->next = self->next; | ||
| 140 | 	self->prev = self->next = self; | ||
| 141 | |||
| 142 | 	if (state==DT_DETACHED && self->map_base) { | ||
| 143 | 		/* Detached threads must block even implementation-internal | ||
| 144 | 		 * signals, since they will not have a stack in their last | ||
| 145 | 		 * moments of existence. */ | ||
| 146 | 		__block_all_sigs(&set); | ||
| 147 | |||
| 148 | 		/* Robust list will no longer be valid, and was already | ||
| 149 | 		 * processed above, so unregister it with the kernel. */ | ||
| 150 | 		if (self->robust_list.off) | ||
| 151 | 			__syscall(SYS_set_robust_list, 0, 3*sizeof(long)); | ||
| 152 | |||
| 153 | 		/* The following call unmaps the thread's stack mapping | ||
| 154 | 		 * and then exits without touching the stack. */ | ||
| 155 | 		__unmapself(self->map_base, self->map_size); | ||
| 156 | 	} | ||
| 157 | |||
| 158 | 	/* Wake any joiner. */ | ||
| 159 | 	a_store(&self->detach_state, DT_EXITED); | ||
| 160 | 	__wake(&self->detach_state, 1, 1); | ||
| 161 | |||
| 162 | 	/* After the kernel thread exits, its tid may be reused. Clear it | ||
| 163 | 	 * to prevent inadvertent use and inform functions that would use | ||
| 164 | 	 * it that it's no longer available. */ | ||
| 165 | 	self->tid = 0; | ||
| 166 | 	UNLOCK(self->killlock); | ||
| 167 | |||
| 168 | 	for (;;) __syscall(SYS_exit, 0); | ||
| 169 | } | ||
| 170 | |||
| 171 | void __do_cleanup_push(struct __ptcb *cb) | ||
| 172 | { | ||
| 173 | 	struct pthread *self = __pthread_self(); | ||
| 174 | 	cb->__next = self->cancelbuf; | ||
| 175 | 	self->cancelbuf = cb; | ||
| 176 | } | ||
| 177 | |||
| 178 | void __do_cleanup_pop(struct __ptcb *cb) | ||
| 179 | { | ||
| 180 | 	__pthread_self()->cancelbuf = cb->__next; | ||
| 181 | } | ||
| 182 | |||
| 183 | struct start_args { | ||
| 184 | 	void *(*start_func)(void *); | ||
| 185 | 	void *start_arg; | ||
| 186 | 	volatile int control; | ||
| 187 | 	unsigned long sig_mask[_NSIG/8/sizeof(long)]; | ||
| 188 | }; | ||
| 189 | |||
| 190 | static int start(void *p) | ||
| 191 | { | ||
| 192 | 	struct start_args *args = p; | ||
| 193 | 	int state = args->control; | ||
| 194 | 	if (state) { | ||
| 195 | 		if (a_cas(&args->control, 1, 2)==1) | ||
| 196 | 			__wait(&args->control, 0, 2, 1); | ||
| 197 | 		if (args->control) { | ||
| 198 | 			__syscall(SYS_set_tid_address, &args->control); | ||
| 199 | 			for (;;) __syscall(SYS_exit, 0); | ||
| 200 | 		} | ||
| 201 | 	} | ||
| 202 | 	__syscall(SYS_rt_sigprocmask, SIG_SETMASK, &args->sig_mask, 0, _NSIG/8); | ||
| 203 | 	__pthread_exit(args->start_func(args->start_arg)); | ||
| 204 | 	return 0; | ||
| 205 | } | ||
| 206 | |||
| 207 | static int start_c11(void *p) | ||
| 208 | { | ||
| 209 | 	struct start_args *args = p; | ||
| 210 | 	int (*start)(void*) = (int(*)(void*)) args->start_func; | ||
| 211 | 	__pthread_exit((void *)(uintptr_t)start(args->start_arg)); | ||
| 212 | 	return 0; | ||
| 213 | } | ||
| 214 | |||
| 215 | #define ROUND(x) (((x)+PAGE_SIZE-1)&-PAGE_SIZE) | ||
| 216 | |||
| 217 | /* pthread_key_create.c overrides this */ | ||
| 218 | static volatile size_t dummy = 0; | ||
| 219 | weak_alias(dummy, __pthread_tsd_size); | ||
| 220 | static void *dummy_tsd[1] = { 0 }; | ||
| 221 | weak_alias(dummy_tsd, __pthread_tsd_main); | ||
| 222 | |||
| 223 | static FILE *volatile dummy_file = 0; | ||
| 224 | weak_alias(dummy_file, __stdin_used); | ||
| 225 | weak_alias(dummy_file, __stdout_used); | ||
| 226 | weak_alias(dummy_file, __stderr_used); | ||
| 227 | |||
| 228 | static void init_file_lock(FILE *f) | ||
| 229 | { | ||
| 230 | 	if (f && f->lock<0) f->lock = 0; | ||
| 231 | } | ||
| 232 | |||
| 233 | int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict attrp, void *(*entry)(void *), void *restrict arg) | ||
| 234 | { | ||
| 235 | 	int ret, c11 = (attrp == __ATTRP_C11_THREAD); | ||
| 236 | 	size_t size, guard; | ||
| 237 | 	struct pthread *self, *new; | ||
| 238 | 	unsigned char *map = 0, *stack = 0, *tsd = 0, *stack_limit; | ||
| 239 | 	unsigned flags = CLONE_VM | CLONE_FS | CLONE_FILES | CLONE_SIGHAND | ||
| 240 | 		| CLONE_THREAD | CLONE_SYSVSEM | CLONE_SETTLS | ||
| 241 | 		| CLONE_PARENT_SETTID | CLONE_CHILD_CLEARTID | CLONE_DETACHED; | ||
| 242 | 	pthread_attr_t attr = { 0 }; | ||
| 243 | 	sigset_t set; | ||
| 244 | |||
| 245 | 	if (!libc.can_do_threads) return ENOSYS; | ||
| 246 | 	self = __pthread_self(); | ||
| 247 | 	if (!libc.threaded) { | ||
| 248 | 		for (FILE *f=*__ofl_lock(); f; f=f->next) | ||
| 249 | 			init_file_lock(f); | ||
| 250 | 		__ofl_unlock(); | ||
| 251 | 		init_file_lock(__stdin_used); | ||
| 252 | 		init_file_lock(__stdout_used); | ||
| 253 | 		init_file_lock(__stderr_used); | ||
| 254 | 		__syscall(SYS_rt_sigprocmask, SIG_UNBLOCK, SIGPT_SET, 0, _NSIG/8); | ||
| 255 | 		self->tsd = (void **)__pthread_tsd_main; | ||
| 256 | 		__membarrier_init(); | ||
| 257 | 		libc.threaded = 1; | ||
| 258 | 	} | ||
| 259 | 	if (attrp && !c11) attr = *attrp; | ||
| 260 | |||
| 261 | 	__acquire_ptc(); | ||
| 262 | 	if (!attrp || c11) { | ||
| 263 | 		attr._a_stacksize = __default_stacksize; | ||
| 264 | 		attr._a_guardsize = __default_guardsize; | ||
| 265 | 	} | ||
| 266 | |||
| 267 | 	if (attr._a_stackaddr) { | ||
| 268 | 		size_t need = libc.tls_size + __pthread_tsd_size; | ||
| 269 | 		size = attr._a_stacksize; | ||
| 270 | 		stack = (void *)(attr._a_stackaddr & -16); | ||
| 271 | 		stack_limit = (void *)(attr._a_stackaddr - size); | ||
| 272 | 		/* Use application-provided stack for TLS only when | ||
| 273 | 		 * it does not take more than ~12% or 2k of the | ||
| 274 | 		 * application's stack space. */ | ||
| 275 | 		if (need < size/8 && need < 2048) { | ||
| 276 | 			tsd = stack - __pthread_tsd_size; | ||
| 277 | 			stack = tsd - libc.tls_size; | ||
| 278 | 			memset(stack, 0, need); | ||
| 279 | 		} else { | ||
| 280 | 			size = ROUND(need); | ||
| 281 | 		} | ||
| 282 | 		guard = 0; | ||
| 283 | 	} else { | ||
| 284 | 		guard = ROUND(attr._a_guardsize); | ||
| 285 | 		size = guard + ROUND(attr._a_stacksize | ||
| 286 | 			+ libc.tls_size + __pthread_tsd_size); | ||
| 287 | 	} | ||
| 288 | |||
| 289 | 	if (!tsd) { | ||
| 290 | 		if (guard) { | ||
| 291 | 			map = __mmap(0, size, PROT_NONE, MAP_PRIVATE|MAP_ANON, -1, 0); | ||
| 292 | 			if (map == MAP_FAILED) goto fail; | ||
| 293 | 			if (__mprotect(map+guard, size-guard, PROT_READ|PROT_WRITE) | ||
| 294 | 			 && errno != ENOSYS) { | ||
| 295 | 				__munmap(map, size); | ||
| 296 | 				goto fail; | ||
| 297 | 			} | ||
| 298 | 		} else { | ||
| 299 | 			map = __mmap(0, size, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANON, -1, 0); | ||
| 300 | 			if (map == MAP_FAILED) goto fail; | ||
| 301 | 		} | ||
| 302 | 		tsd = map + size - __pthread_tsd_size; | ||
| 303 | 		if (!stack) { | ||
| 304 | 			stack = tsd - libc.tls_size; | ||
| 305 | 			stack_limit = map + guard; | ||
| 306 | 		} | ||
| 307 | 	} | ||
| 308 | |||
| 309 | 	new = __copy_tls(tsd - libc.tls_size); | ||
| 310 | 	new->map_base = map; | ||
| 311 | 	new->map_size = size; | ||
| 312 | 	new->stack = stack; | ||
| 313 | 	new->stack_size = stack - stack_limit; | ||
| 314 | 	new->guard_size = guard; | ||
| 315 | 	new->self = new; | ||
| 316 | 	new->tsd = (void *)tsd; | ||
| 317 | 	new->locale = &libc.global_locale; | ||
| 318 | 	if (attr._a_detach) { | ||
| 319 | 		new->detach_state = DT_DETACHED; | ||
| 320 | 	} else { | ||
| 321 | 		new->detach_state = DT_JOINABLE; | ||
| 322 | 	} | ||
| 323 | 	new->robust_list.head = &new->robust_list.head; | ||
| 324 | 	new->canary = self->canary; | ||
| 325 | 	new->sysinfo = self->sysinfo; | ||
| 326 | |||
| 327 | 	/* Setup argument structure for the new thread on its stack. | ||
| 328 | 	 * It's safe to access from the caller only until the thread | ||
| 329 | 	 * list is unlocked. */ | ||
| 330 | 	stack -= (uintptr_t)stack % sizeof(uintptr_t); | ||
| 331 | 	stack -= sizeof(struct start_args); | ||
| 332 | 	struct start_args *args = (void *)stack; | ||
| 333 | 	args->start_func = entry; | ||
| 334 | 	args->start_arg = arg; | ||
| 335 | 	args->control = attr._a_sched ? 1 : 0; | ||
| 336 | |||
| 337 | 	/* Application signals (but not the synccall signal) must be | ||
| 338 | 	 * blocked before the thread list lock can be taken, to ensure | ||
| 339 | 	 * that the lock is AS-safe. */ | ||
| 340 | 	__block_app_sigs(&set); | ||
| 341 | |||
| 342 | 	/* Ensure SIGCANCEL is unblocked in new thread. This requires | ||
| 343 | 	 * working with a copy of the set so we can restore the | ||
| 344 | 	 * original mask in the calling thread. */ | ||
| 345 | 	memcpy(&args->sig_mask, &set, sizeof args->sig_mask); | ||
| 346 | 	args->sig_mask[(SIGCANCEL-1)/8/sizeof(long)] &= | ||
| 347 | 		~(1UL<<((SIGCANCEL-1)%(8*sizeof(long)))); | ||
| 348 | |||
| 349 | 	__tl_lock(); | ||
| 350 | 	if (!libc.threads_minus_1++) libc.need_locks = 1; | ||
| 351 | 	ret = __clone((c11 ? start_c11 : start), stack, flags, args, &new->tid, TP_ADJ(new), &__thread_list_lock); | ||
| 352 | |||
| 353 | 	/* All clone failures translate to EAGAIN. If explicit scheduling | ||
| 354 | 	 * was requested, attempt it before unlocking the thread list so | ||
| 355 | 	 * that the failed thread is never exposed and so that we can | ||
| 356 | 	 * clean up all transient resource usage before returning. */ | ||
| 357 | 	if (ret < 0) { | ||
| 358 | 		ret = -EAGAIN; | ||
| 359 | 	} else if (attr._a_sched) { | ||
| 360 | 		ret = __syscall(SYS_sched_setscheduler, | ||
| 361 | 			new->tid, attr._a_policy, &attr._a_prio); | ||
| 362 | 		if (a_swap(&args->control, ret ? 3 : 0)==2) | ||
| 363 | 			__wake(&args->control, 1, 1); | ||
| 364 | 		if (ret) | ||
| 365 | 			__wait(&args->control, 0, 3, 0); | ||
| 366 | 	} | ||
| 367 | |||
| 368 | 	if (ret >= 0) { | ||
| 369 | 		new->next = self->next; | ||
| 370 | 		new->prev = self; | ||
| 371 | 		new->next->prev = new; | ||
| 372 | 		new->prev->next = new; | ||
| 373 | 	} else { | ||
| 374 | 		if (!--libc.threads_minus_1) libc.need_locks = 0; | ||
| 375 | 	} | ||
| 376 | 	__tl_unlock(); | ||
| 377 | 	__restore_sigs(&set); | ||
| 378 | 	__release_ptc(); | ||
| 379 | |||
| 380 | 	if (ret < 0) { | ||
| 381 | 		if (map) __munmap(map, size); | ||
| 382 | 		return -ret; | ||
| 383 | 	} | ||
| 384 | |||
| 385 | 	*res = new; | ||
| 386 | 	return 0; | ||
| 387 | fail: | ||
| 388 | 	__release_ptc(); | ||
| 389 | 	return EAGAIN; | ||
| 390 | } | ||
| 391 | |||
| 392 | weak_alias(__pthread_exit, pthread_exit); | ||
| 393 | weak_alias(__pthread_create, pthread_create); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_detach.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | static int __pthread_detach(pthread_t t) | ||
| 5 | { | ||
| 6 | 	/* If the cas fails, detach state is either already-detached | ||
| 7 | 	 * or exiting/exited, and pthread_join will trap or cleanup. */ | ||
| 8 | 	if (a_cas(&t->detach_state, DT_JOINABLE, DT_DETACHED) != DT_JOINABLE) | ||
| 9 | 		return __pthread_join(t, 0); | ||
| 10 | 	return 0; | ||
| 11 | } | ||
| 12 | |||
| 13 | weak_alias(__pthread_detach, pthread_detach); | ||
| 14 | weak_alias(__pthread_detach, thrd_detach); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_equal.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | static int __pthread_equal(pthread_t a, pthread_t b) | ||
| 5 | { | ||
| 6 | 	return a==b; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__pthread_equal, pthread_equal); | ||
| 10 | weak_alias(__pthread_equal, thrd_equal); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getattr_np.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | #include "libc.h" | ||
| 4 | #include <sys/mman.h> | ||
| 5 | |||
| 6 | int pthread_getattr_np(pthread_t t, pthread_attr_t *a) | ||
| 7 | { | ||
| 8 | 	*a = (pthread_attr_t){0}; | ||
| 9 | 	a->_a_detach = t->detach_state>=DT_DETACHED; | ||
| 10 | 	a->_a_guardsize = t->guard_size; | ||
| 11 | 	if (t->stack) { | ||
| 12 | 		a->_a_stackaddr = (uintptr_t)t->stack; | ||
| 13 | 		a->_a_stacksize = t->stack_size; | ||
| 14 | 	} else { | ||
| 15 | 		char *p = (void *)libc.auxv; | ||
| 16 | 		size_t l = PAGE_SIZE; | ||
| 17 | 		p += -(uintptr_t)p & PAGE_SIZE-1; | ||
| 18 | 		a->_a_stackaddr = (uintptr_t)p; | ||
| 19 | 		while (mremap(p-l-PAGE_SIZE, PAGE_SIZE, 2*PAGE_SIZE, 0)==MAP_FAILED && errno==ENOMEM) | ||
| 20 | 			l += PAGE_SIZE; | ||
| 21 | 		a->_a_stacksize = l; | ||
| 22 | 	} | ||
| 23 | 	return 0; | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getconcurrency.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | |||
| 3 | int pthread_getconcurrency() | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getcpuclockid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_getcpuclockid(pthread_t t, clockid_t *clockid) | ||
| 4 | { | ||
| 5 | 	*clockid = (-t->tid-1)*8U + 6; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getschedparam.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "lock.h" | ||
| 3 | |||
| 4 | int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param *restrict param) | ||
| 5 | { | ||
| 6 | 	int r; | ||
| 7 | 	sigset_t set; | ||
| 8 | 	__block_app_sigs(&set); | ||
| 9 | 	LOCK(t->killlock); | ||
| 10 | 	if (!t->tid) { | ||
| 11 | 		r = ESRCH; | ||
| 12 | 	} else { | ||
| 13 | 		r = -__syscall(SYS_sched_getparam, t->tid, param); | ||
| 14 | 		if (!r) { | ||
| 15 | 			*policy = __syscall(SYS_sched_getscheduler, t->tid); | ||
| 16 | 		} | ||
| 17 | 	} | ||
| 18 | 	UNLOCK(t->killlock); | ||
| 19 | 	__restore_sigs(&set); | ||
| 20 | 	return r; | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_getspecific.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | static void *__pthread_getspecific(pthread_key_t k) | ||
| 5 | { | ||
| 6 | 	struct pthread *self = __pthread_self(); | ||
| 7 | 	return self->tsd[k]; | ||
| 8 | } | ||
| 9 | |||
| 10 | weak_alias(__pthread_getspecific, pthread_getspecific); | ||
| 11 | weak_alias(__pthread_getspecific, tss_get); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_join.c created+40| ... | @@ -0,0 +1,40 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | #include <sys/mman.h> | ||
| 4 | |||
| 5 | static void dummy1(pthread_t t) | ||
| 6 | { | ||
| 7 | } | ||
| 8 | weak_alias(dummy1, __tl_sync); | ||
| 9 | |||
| 10 | static int __pthread_timedjoin_np(pthread_t t, void **res, const struct timespec *at) | ||
| 11 | { | ||
| 12 | 	int state, cs, r = 0; | ||
| 13 | 	__pthread_testcancel(); | ||
| 14 | 	__pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 15 | 	if (cs == PTHREAD_CANCEL_ENABLE) __pthread_setcancelstate(cs, 0); | ||
| 16 | 	while ((state = t->detach_state) && r != ETIMEDOUT && r != EINVAL) { | ||
| 17 | 		if (state >= DT_DETACHED) a_crash(); | ||
| 18 | 		r = __timedwait_cp(&t->detach_state, state, CLOCK_REALTIME, at, 1); | ||
| 19 | 	} | ||
| 20 | 	__pthread_setcancelstate(cs, 0); | ||
| 21 | 	if (r == ETIMEDOUT || r == EINVAL) return r; | ||
| 22 | 	__tl_sync(t); | ||
| 23 | 	if (res) *res = t->result; | ||
| 24 | 	if (t->map_base) __munmap(t->map_base, t->map_size); | ||
| 25 | 	return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | int __pthread_join(pthread_t t, void **res) | ||
| 29 | { | ||
| 30 | 	return __pthread_timedjoin_np(t, res, 0); | ||
| 31 | } | ||
| 32 | |||
| 33 | static int __pthread_tryjoin_np(pthread_t t, void **res) | ||
| 34 | { | ||
| 35 | 	return t->detach_state==DT_JOINABLE ? EBUSY : __pthread_join(t, res); | ||
| 36 | } | ||
| 37 | |||
| 38 | weak_alias(__pthread_tryjoin_np, pthread_tryjoin_np); | ||
| 39 | weak_alias(__pthread_timedjoin_np, pthread_timedjoin_np); | ||
| 40 | weak_alias(__pthread_join, pthread_join); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_key_create.c created+91| ... | @@ -0,0 +1,91 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | volatile size_t __pthread_tsd_size = sizeof(void *) * PTHREAD_KEYS_MAX; | ||
| 4 | void *__pthread_tsd_main[PTHREAD_KEYS_MAX] = { 0 }; | ||
| 5 | |||
| 6 | static void (*keys[PTHREAD_KEYS_MAX])(void *); | ||
| 7 | |||
| 8 | static pthread_rwlock_t key_lock = PTHREAD_RWLOCK_INITIALIZER; | ||
| 9 | |||
| 10 | static pthread_key_t next_key; | ||
| 11 | |||
| 12 | static void nodtor(void *dummy) | ||
| 13 | { | ||
| 14 | } | ||
| 15 | |||
| 16 | static void dummy_0(void) | ||
| 17 | { | ||
| 18 | } | ||
| 19 | |||
| 20 | weak_alias(dummy_0, __tl_lock); | ||
| 21 | weak_alias(dummy_0, __tl_unlock); | ||
| 22 | |||
| 23 | int __pthread_key_create(pthread_key_t *k, void (*dtor)(void *)) | ||
| 24 | { | ||
| 25 | 	pthread_t self = __pthread_self(); | ||
| 26 | |||
| 27 | 	/* This can only happen in the main thread before | ||
| 28 | 	 * pthread_create has been called. */ | ||
| 29 | 	if (!self->tsd) self->tsd = __pthread_tsd_main; | ||
| 30 | |||
| 31 | 	/* Purely a sentinel value since null means slot is free. */ | ||
| 32 | 	if (!dtor) dtor = nodtor; | ||
| 33 | |||
| 34 | 	__pthread_rwlock_wrlock(&key_lock); | ||
| 35 | 	pthread_key_t j = next_key; | ||
| 36 | 	do { | ||
| 37 | 		if (!keys[j]) { | ||
| 38 | 			keys[next_key = *k = j] = dtor; | ||
| 39 | 			__pthread_rwlock_unlock(&key_lock); | ||
| 40 | 			return 0; | ||
| 41 | 		} | ||
| 42 | 	} while ((j=(j+1)%PTHREAD_KEYS_MAX) != next_key); | ||
| 43 | |||
| 44 | 	__pthread_rwlock_unlock(&key_lock); | ||
| 45 | 	return EAGAIN; | ||
| 46 | } | ||
| 47 | |||
| 48 | int __pthread_key_delete(pthread_key_t k) | ||
| 49 | { | ||
| 50 | 	sigset_t set; | ||
| 51 | 	pthread_t self = __pthread_self(), td=self; | ||
| 52 | |||
| 53 | 	__block_app_sigs(&set); | ||
| 54 | 	__pthread_rwlock_wrlock(&key_lock); | ||
| 55 | |||
| 56 | 	__tl_lock(); | ||
| 57 | 	do td->tsd[k] = 0; | ||
| 58 | 	while ((td=td->next)!=self); | ||
| 59 | 	__tl_unlock(); | ||
| 60 | |||
| 61 | 	keys[k] = 0; | ||
| 62 | |||
| 63 | 	__pthread_rwlock_unlock(&key_lock); | ||
| 64 | 	__restore_sigs(&set); | ||
| 65 | |||
| 66 | 	return 0; | ||
| 67 | } | ||
| 68 | |||
| 69 | void __pthread_tsd_run_dtors() | ||
| 70 | { | ||
| 71 | 	pthread_t self = __pthread_self(); | ||
| 72 | 	int i, j; | ||
| 73 | 	for (j=0; self->tsd_used && j<PTHREAD_DESTRUCTOR_ITERATIONS; j++) { | ||
| 74 | 		__pthread_rwlock_rdlock(&key_lock); | ||
| 75 | 		self->tsd_used = 0; | ||
| 76 | 		for (i=0; i<PTHREAD_KEYS_MAX; i++) { | ||
| 77 | 			void *val = self->tsd[i]; | ||
| 78 | 			void (*dtor)(void *) = keys[i]; | ||
| 79 | 			self->tsd[i] = 0; | ||
| 80 | 			if (val && dtor && dtor != nodtor) { | ||
| 81 | 				__pthread_rwlock_unlock(&key_lock); | ||
| 82 | 				dtor(val); | ||
| 83 | 				__pthread_rwlock_rdlock(&key_lock); | ||
| 84 | 			} | ||
| 85 | 		} | ||
| 86 | 		__pthread_rwlock_unlock(&key_lock); | ||
| 87 | 	} | ||
| 88 | } | ||
| 89 | |||
| 90 | weak_alias(__pthread_key_create, pthread_key_create); | ||
| 91 | weak_alias(__pthread_key_delete, pthread_key_delete); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_kill.c created+18| ... | @@ -0,0 +1,18 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "lock.h" | ||
| 3 | |||
| 4 | int pthread_kill(pthread_t t, int sig) | ||
| 5 | { | ||
| 6 | 	int r; | ||
| 7 | 	sigset_t set; | ||
| 8 | 	/* Block not just app signals, but internal ones too, since | ||
| 9 | 	 * pthread_kill is used to implement pthread_cancel, which | ||
| 10 | 	 * must be async-cancel-safe. */ | ||
| 11 | 	__block_all_sigs(&set); | ||
| 12 | 	LOCK(t->killlock); | ||
| 13 | 	r = t->tid ? -__syscall(SYS_tkill, t->tid, sig) | ||
| 14 | 		: (sig+0U >= _NSIG ? EINVAL : 0); | ||
| 15 | 	UNLOCK(t->killlock); | ||
| 16 | 	__restore_sigs(&set); | ||
| 17 | 	return r; | ||
| 18 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_consistent.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "atomic.h" | ||
| 3 | |||
| 4 | int pthread_mutex_consistent(pthread_mutex_t *m) | ||
| 5 | { | ||
| 6 | 	int old = m->_m_lock; | ||
| 7 | 	int own = old & 0x3fffffff; | ||
| 8 | 	if (!(m->_m_type & 4) || !own || !(old & 0x40000000)) | ||
| 9 | 		return EINVAL; | ||
| 10 | 	if (own != __pthread_self()->tid) | ||
| 11 | 		return EPERM; | ||
| 12 | 	a_and(&m->_m_lock, ~0x40000000); | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_destroy.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutex_destroy(pthread_mutex_t *mutex) | ||
| 4 | { | ||
| 5 | 	/* If the mutex being destroyed is process-shared and has nontrivial | ||
| 6 | 	 * type (tracking ownership), it might be in the pending slot of a | ||
| 7 | 	 * robust_list; wait for quiescence. */ | ||
| 8 | 	if (mutex->_m_type > 128) __vm_wait(); | ||
| 9 | 	return 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_getprioceiling.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 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/libc-top-half/musl/src/thread/pthread_mutex_init.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutex_init(pthread_mutex_t *restrict m, const pthread_mutexattr_t *restrict a) | ||
| 4 | { | ||
| 5 | 	*m = (pthread_mutex_t){0}; | ||
| 6 | 	if (a) m->_m_type = a->__attr; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_lock.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_lock(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL | ||
| 6 | 	 && !a_cas(&m->_m_lock, 0, EBUSY)) | ||
| 7 | 		return 0; | ||
| 8 | |||
| 9 | 	return __pthread_mutex_timedlock(m, 0); | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(__pthread_mutex_lock, pthread_mutex_lock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_setprioceiling.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutex_setprioceiling(pthread_mutex_t *restrict m, int ceiling, int *restrict old) | ||
| 4 | { | ||
| 5 | 	return EINVAL; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_timedlock.c created+92| ... | @@ -0,0 +1,92 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 4 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 5 | |||
| 6 | static int __futex4(volatile void *addr, int op, int val, const struct timespec *to) | ||
| 7 | { | ||
| 8 | #ifdef SYS_futex_time64 | ||
| 9 | 	time_t s = to ? to->tv_sec : 0; | ||
| 10 | 	long ns = to ? to->tv_nsec : 0; | ||
| 11 | 	int r = -ENOSYS; | ||
| 12 | 	if (SYS_futex == SYS_futex_time64 || !IS32BIT(s)) | ||
| 13 | 		r = __syscall(SYS_futex_time64, addr, op, val, | ||
| 14 | 			to ? ((long long[]){s, ns}) : 0); | ||
| 15 | 	if (SYS_futex == SYS_futex_time64 || r!=-ENOSYS) return r; | ||
| 16 | 	to = to ? (void *)(long[]){CLAMP(s), ns} : 0; | ||
| 17 | #endif | ||
| 18 | 	return __syscall(SYS_futex, addr, op, val, to); | ||
| 19 | } | ||
| 20 | |||
| 21 | static int pthread_mutex_timedlock_pi(pthread_mutex_t *restrict m, const struct timespec *restrict at) | ||
| 22 | { | ||
| 23 | 	int type = m->_m_type; | ||
| 24 | 	int priv = (type & 128) ^ 128; | ||
| 25 | 	pthread_t self = __pthread_self(); | ||
| 26 | 	int e; | ||
| 27 | |||
| 28 | 	if (!priv) self->robust_list.pending = &m->_m_next; | ||
| 29 | |||
| 30 | 	do e = -__futex4(&m->_m_lock, FUTEX_LOCK_PI|priv, 0, at); | ||
| 31 | 	while (e==EINTR); | ||
| 32 | 	if (e) self->robust_list.pending = 0; | ||
| 33 | |||
| 34 | 	switch (e) { | ||
| 35 | 	case 0: | ||
| 36 | 		/* Catch spurious success for non-robust mutexes. */ | ||
| 37 | 		if (!(type&4) && ((m->_m_lock & 0x40000000) || m->_m_waiters)) { | ||
| 38 | 			a_store(&m->_m_waiters, -1); | ||
| 39 | 			__syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv); | ||
| 40 | 			self->robust_list.pending = 0; | ||
| 41 | 			break; | ||
| 42 | 		} | ||
| 43 | 		/* Signal to trylock that we already have the lock. */ | ||
| 44 | 		m->_m_count = -1; | ||
| 45 | 		return __pthread_mutex_trylock(m); | ||
| 46 | 	case ETIMEDOUT: | ||
| 47 | 		return e; | ||
| 48 | 	case EDEADLK: | ||
| 49 | 		if ((type&3) == PTHREAD_MUTEX_ERRORCHECK) return e; | ||
| 50 | 	} | ||
| 51 | 	do e = __timedwait(&(int){0}, 0, CLOCK_REALTIME, at, 1); | ||
| 52 | 	while (e != ETIMEDOUT); | ||
| 53 | 	return e; | ||
| 54 | } | ||
| 55 | |||
| 56 | int __pthread_mutex_timedlock(pthread_mutex_t *restrict m, const struct timespec *restrict at) | ||
| 57 | { | ||
| 58 | 	if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL | ||
| 59 | 	 && !a_cas(&m->_m_lock, 0, EBUSY)) | ||
| 60 | 		return 0; | ||
| 61 | |||
| 62 | 	int type = m->_m_type; | ||
| 63 | 	int r, t, priv = (type & 128) ^ 128; | ||
| 64 | |||
| 65 | 	r = __pthread_mutex_trylock(m); | ||
| 66 | 	if (r != EBUSY) return r; | ||
| 67 | |||
| 68 | 	if (type&8) return pthread_mutex_timedlock_pi(m, at); | ||
| 69 | 	 | ||
| 70 | 	int spins = 100; | ||
| 71 | 	while (spins-- && m->_m_lock && !m->_m_waiters) a_spin(); | ||
| 72 | |||
| 73 | 	while ((r=__pthread_mutex_trylock(m)) == EBUSY) { | ||
| 74 | 		r = m->_m_lock; | ||
| 75 | 		int own = r & 0x3fffffff; | ||
| 76 | 		if (!own && (!r || (type&4))) | ||
| 77 | 			continue; | ||
| 78 | 		if ((type&3) == PTHREAD_MUTEX_ERRORCHECK | ||
| 79 | 		 && own == __pthread_self()->tid) | ||
| 80 | 			return EDEADLK; | ||
| 81 | |||
| 82 | 		a_inc(&m->_m_waiters); | ||
| 83 | 		t = r | 0x80000000; | ||
| 84 | 		a_cas(&m->_m_lock, r, t); | ||
| 85 | 		r = __timedwait(&m->_m_lock, t, CLOCK_REALTIME, at, priv); | ||
| 86 | 		a_dec(&m->_m_waiters); | ||
| 87 | 		if (r && r != EINTR) break; | ||
| 88 | 	} | ||
| 89 | 	return r; | ||
| 90 | } | ||
| 91 | |||
| 92 | weak_alias(__pthread_mutex_timedlock, pthread_mutex_timedlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_trylock.c created+74| ... | @@ -0,0 +1,74 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_trylock_owner(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	int old, own; | ||
| 6 | 	int type = m->_m_type; | ||
| 7 | 	pthread_t self = __pthread_self(); | ||
| 8 | 	int tid = self->tid; | ||
| 9 | |||
| 10 | 	old = m->_m_lock; | ||
| 11 | 	own = old & 0x3fffffff; | ||
| 12 | 	if (own == tid) { | ||
| 13 | 		if ((type&8) && m->_m_count<0) { | ||
| 14 | 			old &= 0x40000000; | ||
| 15 | 			m->_m_count = 0; | ||
| 16 | 			goto success; | ||
| 17 | 		} | ||
| 18 | 		if ((type&3) == PTHREAD_MUTEX_RECURSIVE) { | ||
| 19 | 			if ((unsigned)m->_m_count >= INT_MAX) return EAGAIN; | ||
| 20 | 			m->_m_count++; | ||
| 21 | 			return 0; | ||
| 22 | 		} | ||
| 23 | 	} | ||
| 24 | 	if (own == 0x3fffffff) return ENOTRECOVERABLE; | ||
| 25 | 	if (own || (old && !(type & 4))) return EBUSY; | ||
| 26 | |||
| 27 | 	if (type & 128) { | ||
| 28 | 		if (!self->robust_list.off) { | ||
| 29 | 			self->robust_list.off = (char*)&m->_m_lock-(char *)&m->_m_next; | ||
| 30 | 			__syscall(SYS_set_robust_list, &self->robust_list, 3*sizeof(long)); | ||
| 31 | 		} | ||
| 32 | 		if (m->_m_waiters) tid |= 0x80000000; | ||
| 33 | 		self->robust_list.pending = &m->_m_next; | ||
| 34 | 	} | ||
| 35 | 	tid |= old & 0x40000000; | ||
| 36 | |||
| 37 | 	if (a_cas(&m->_m_lock, old, tid) != old) { | ||
| 38 | 		self->robust_list.pending = 0; | ||
| 39 | 		if ((type&12)==12 && m->_m_waiters) return ENOTRECOVERABLE; | ||
| 40 | 		return EBUSY; | ||
| 41 | 	} | ||
| 42 | |||
| 43 | success: | ||
| 44 | 	if ((type&8) && m->_m_waiters) { | ||
| 45 | 		int priv = (type & 128) ^ 128; | ||
| 46 | 		__syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv); | ||
| 47 | 		self->robust_list.pending = 0; | ||
| 48 | 		return (type&4) ? ENOTRECOVERABLE : EBUSY; | ||
| 49 | 	} | ||
| 50 | |||
| 51 | 	volatile void *next = self->robust_list.head; | ||
| 52 | 	m->_m_next = next; | ||
| 53 | 	m->_m_prev = &self->robust_list.head; | ||
| 54 | 	if (next != &self->robust_list.head) *(volatile void *volatile *) | ||
| 55 | 		((char *)next - sizeof(void *)) = &m->_m_next; | ||
| 56 | 	self->robust_list.head = &m->_m_next; | ||
| 57 | 	self->robust_list.pending = 0; | ||
| 58 | |||
| 59 | 	if (old) { | ||
| 60 | 		m->_m_count = 0; | ||
| 61 | 		return EOWNERDEAD; | ||
| 62 | 	} | ||
| 63 | |||
| 64 | 	return 0; | ||
| 65 | } | ||
| 66 | |||
| 67 | int __pthread_mutex_trylock(pthread_mutex_t *m) | ||
| 68 | { | ||
| 69 | 	if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL) | ||
| 70 | 		return a_cas(&m->_m_lock, 0, EBUSY) & EBUSY; | ||
| 71 | 	return __pthread_mutex_trylock_owner(m); | ||
| 72 | } | ||
| 73 | |||
| 74 | weak_alias(__pthread_mutex_trylock, pthread_mutex_trylock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutex_unlock.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_mutex_unlock(pthread_mutex_t *m) | ||
| 4 | { | ||
| 5 | 	pthread_t self; | ||
| 6 | 	int waiters = m->_m_waiters; | ||
| 7 | 	int cont; | ||
| 8 | 	int type = m->_m_type & 15; | ||
| 9 | 	int priv = (m->_m_type & 128) ^ 128; | ||
| 10 | 	int new = 0; | ||
| 11 | 	int old; | ||
| 12 | |||
| 13 | 	if (type != PTHREAD_MUTEX_NORMAL) { | ||
| 14 | 		self = __pthread_self(); | ||
| 15 | 		old = m->_m_lock; | ||
| 16 | 		int own = old & 0x3fffffff; | ||
| 17 | 		if (own != self->tid) | ||
| 18 | 			return EPERM; | ||
| 19 | 		if ((type&3) == PTHREAD_MUTEX_RECURSIVE && m->_m_count) | ||
| 20 | 			return m->_m_count--, 0; | ||
| 21 | 		if ((type&4) && (old&0x40000000)) | ||
| 22 | 			new = 0x7fffffff; | ||
| 23 | 		if (!priv) { | ||
| 24 | 			self->robust_list.pending = &m->_m_next; | ||
| 25 | 			__vm_lock(); | ||
| 26 | 		} | ||
| 27 | 		volatile void *prev = m->_m_prev; | ||
| 28 | 		volatile void *next = m->_m_next; | ||
| 29 | 		*(volatile void *volatile *)prev = next; | ||
| 30 | 		if (next != &self->robust_list.head) *(volatile void *volatile *) | ||
| 31 | 			((char *)next - sizeof(void *)) = prev; | ||
| 32 | 	} | ||
| 33 | 	if (type&8) { | ||
| 34 | 		if (old<0 || a_cas(&m->_m_lock, old, new)!=old) { | ||
| 35 | 			if (new) a_store(&m->_m_waiters, -1); | ||
| 36 | 			__syscall(SYS_futex, &m->_m_lock, FUTEX_UNLOCK_PI|priv); | ||
| 37 | 		} | ||
| 38 | 		cont = 0; | ||
| 39 | 		waiters = 0; | ||
| 40 | 	} else { | ||
| 41 | 		cont = a_swap(&m->_m_lock, new); | ||
| 42 | 	} | ||
| 43 | 	if (type != PTHREAD_MUTEX_NORMAL && !priv) { | ||
| 44 | 		self->robust_list.pending = 0; | ||
| 45 | 		__vm_unlock(); | ||
| 46 | 	} | ||
| 47 | 	if (waiters || cont<0) | ||
| 48 | 		__wake(&m->_m_lock, 1, priv); | ||
| 49 | 	return 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | weak_alias(__pthread_mutex_unlock, pthread_mutex_unlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutexattr_destroy(pthread_mutexattr_t *a) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutexattr_init(pthread_mutexattr_t *a) | ||
| 4 | { | ||
| 5 | 	*a = (pthread_mutexattr_t){0}; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setprotocol.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 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 | 		r = check_pi_result; | ||
| 15 | 		if (r < 0) { | ||
| 16 | 			volatile int lk = 0; | ||
| 17 | 			r = -__syscall(SYS_futex, &lk, FUTEX_LOCK_PI, 0, 0); | ||
| 18 | 			a_store(&check_pi_result, r); | ||
| 19 | 		} | ||
| 20 | 		if (r) return r; | ||
| 21 | 		a->__attr |= 8; | ||
| 22 | 		return 0; | ||
| 23 | 	case PTHREAD_PRIO_PROTECT: | ||
| 24 | 		return ENOTSUP; | ||
| 25 | 	default: | ||
| 26 | 		return EINVAL; | ||
| 27 | 	} | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setpshared.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutexattr_setpshared(pthread_mutexattr_t *a, int pshared) | ||
| 4 | { | ||
| 5 | 	if (pshared > 1U) return EINVAL; | ||
| 6 | 	a->__attr &= ~128U; | ||
| 7 | 	a->__attr |= pshared<<7; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_setrobust.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 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 | 	if (robust > 1U) return EINVAL; | ||
| 9 | 	if (robust) { | ||
| 10 | 		int r = check_robust_result; | ||
| 11 | 		if (r < 0) { | ||
| 12 | 			void *p; | ||
| 13 | 			size_t l; | ||
| 14 | 			r = -__syscall(SYS_get_robust_list, 0, &p, &l); | ||
| 15 | 			a_store(&check_robust_result, r); | ||
| 16 | 		} | ||
| 17 | 		if (r) return r; | ||
| 18 | 		a->__attr |= 4; | ||
| 19 | 		return 0; | ||
| 20 | 	} | ||
| 21 | 	a->__attr &= ~4; | ||
| 22 | 	return 0; | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_mutexattr_settype.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_mutexattr_settype(pthread_mutexattr_t *a, int type) | ||
| 4 | { | ||
| 5 | 	if ((unsigned)type > 2) return EINVAL; | ||
| 6 | 	a->__attr = (a->__attr & ~3) | type; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_once.c created+50| ... | @@ -0,0 +1,50 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static void undo(void *control) | ||
| 4 | { | ||
| 5 | 	/* Wake all waiters, since the waiter status is lost when | ||
| 6 | 	 * resetting control to the initial state. */ | ||
| 7 | 	if (a_swap(control, 0) == 3) | ||
| 8 | 		__wake(control, -1, 1); | ||
| 9 | } | ||
| 10 | |||
| 11 | hidden int __pthread_once_full(pthread_once_t *control, void (*init)(void)) | ||
| 12 | { | ||
| 13 | 	/* Try to enter initializing state. Four possibilities: | ||
| 14 | 	 * 0 - we're the first or the other cancelled; run init | ||
| 15 | 	 * 1 - another thread is running init; wait | ||
| 16 | 	 * 2 - another thread finished running init; just return | ||
| 17 | 	 * 3 - another thread is running init, waiters present; wait */ | ||
| 18 | |||
| 19 | 	for (;;) switch (a_cas(control, 0, 1)) { | ||
| 20 | 	case 0: | ||
| 21 | 		pthread_cleanup_push(undo, control); | ||
| 22 | 		init(); | ||
| 23 | 		pthread_cleanup_pop(0); | ||
| 24 | |||
| 25 | 		if (a_swap(control, 2) == 3) | ||
| 26 | 			__wake(control, -1, 1); | ||
| 27 | 		return 0; | ||
| 28 | 	case 1: | ||
| 29 | 		/* If this fails, so will __wait. */ | ||
| 30 | 		a_cas(control, 1, 3); | ||
| 31 | 	case 3: | ||
| 32 | 		__wait(control, 0, 3, 1); | ||
| 33 | 		continue; | ||
| 34 | 	case 2: | ||
| 35 | 		return 0; | ||
| 36 | 	} | ||
| 37 | } | ||
| 38 | |||
| 39 | int __pthread_once(pthread_once_t *control, void (*init)(void)) | ||
| 40 | { | ||
| 41 | 	/* Return immediately if init finished before, but ensure that | ||
| 42 | 	 * effects of the init routine are visible to the caller. */ | ||
| 43 | 	if (*(volatile int *)control == 2) { | ||
| 44 | 		a_barrier(); | ||
| 45 | 		return 0; | ||
| 46 | 	} | ||
| 47 | 	return __pthread_once_full(control, init); | ||
| 48 | } | ||
| 49 | |||
| 50 | weak_alias(__pthread_once, pthread_once); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_rwlock_destroy(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_init.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_rwlock_init(pthread_rwlock_t *restrict rw, const pthread_rwlockattr_t *restrict a) | ||
| 4 | { | ||
| 5 | 	*rw = (pthread_rwlock_t){0}; | ||
| 6 | 	if (a) rw->_rw_shared = a->__attr[0]*128; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_rdlock.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_rdlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	return __pthread_rwlock_timedrdlock(rw, 0); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(__pthread_rwlock_rdlock, pthread_rwlock_rdlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_timedrdlock.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_timedrdlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) | ||
| 4 | { | ||
| 5 | 	int r, t; | ||
| 6 | |||
| 7 | 	r = pthread_rwlock_tryrdlock(rw); | ||
| 8 | 	if (r != EBUSY) return r; | ||
| 9 | 	 | ||
| 10 | 	int spins = 100; | ||
| 11 | 	while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin(); | ||
| 12 | |||
| 13 | 	while ((r=__pthread_rwlock_tryrdlock(rw))==EBUSY) { | ||
| 14 | 		if (!(r=rw->_rw_lock) || (r&0x7fffffff)!=0x7fffffff) continue; | ||
| 15 | 		t = r | 0x80000000; | ||
| 16 | 		a_inc(&rw->_rw_waiters); | ||
| 17 | 		a_cas(&rw->_rw_lock, r, t); | ||
| 18 | 		r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128); | ||
| 19 | 		a_dec(&rw->_rw_waiters); | ||
| 20 | 		if (r && r != EINTR) return r; | ||
| 21 | 	} | ||
| 22 | 	return r; | ||
| 23 | } | ||
| 24 | |||
| 25 | weak_alias(__pthread_rwlock_timedrdlock, pthread_rwlock_timedrdlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_timedwrlock.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_timedwrlock(pthread_rwlock_t *restrict rw, const struct timespec *restrict at) | ||
| 4 | { | ||
| 5 | 	int r, t; | ||
| 6 | 	 | ||
| 7 | 	r = pthread_rwlock_trywrlock(rw); | ||
| 8 | 	if (r != EBUSY) return r; | ||
| 9 | 	 | ||
| 10 | 	int spins = 100; | ||
| 11 | 	while (spins-- && rw->_rw_lock && !rw->_rw_waiters) a_spin(); | ||
| 12 | |||
| 13 | 	while ((r=__pthread_rwlock_trywrlock(rw))==EBUSY) { | ||
| 14 | 		if (!(r=rw->_rw_lock)) continue; | ||
| 15 | 		t = r | 0x80000000; | ||
| 16 | 		a_inc(&rw->_rw_waiters); | ||
| 17 | 		a_cas(&rw->_rw_lock, r, t); | ||
| 18 | 		r = __timedwait(&rw->_rw_lock, t, CLOCK_REALTIME, at, rw->_rw_shared^128); | ||
| 19 | 		a_dec(&rw->_rw_waiters); | ||
| 20 | 		if (r && r != EINTR) return r; | ||
| 21 | 	} | ||
| 22 | 	return r; | ||
| 23 | } | ||
| 24 | |||
| 25 | weak_alias(__pthread_rwlock_timedwrlock, pthread_rwlock_timedwrlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_tryrdlock.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_tryrdlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	int val, cnt; | ||
| 6 | 	do { | ||
| 7 | 		val = rw->_rw_lock; | ||
| 8 | 		cnt = val & 0x7fffffff; | ||
| 9 | 		if (cnt == 0x7fffffff) return EBUSY; | ||
| 10 | 		if (cnt == 0x7ffffffe) return EAGAIN; | ||
| 11 | 	} while (a_cas(&rw->_rw_lock, val, val+1) != val); | ||
| 12 | 	return 0; | ||
| 13 | } | ||
| 14 | |||
| 15 | weak_alias(__pthread_rwlock_tryrdlock, pthread_rwlock_tryrdlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_trywrlock.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_trywrlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	if (a_cas(&rw->_rw_lock, 0, 0x7fffffff)) return EBUSY; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__pthread_rwlock_trywrlock, pthread_rwlock_trywrlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_unlock.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_unlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	int val, cnt, waiters, new, priv = rw->_rw_shared^128; | ||
| 6 | |||
| 7 | 	do { | ||
| 8 | 		val = rw->_rw_lock; | ||
| 9 | 		cnt = val & 0x7fffffff; | ||
| 10 | 		waiters = rw->_rw_waiters; | ||
| 11 | 		new = (cnt == 0x7fffffff || cnt == 1) ? 0 : val-1; | ||
| 12 | 	} while (a_cas(&rw->_rw_lock, val, new) != val); | ||
| 13 | |||
| 14 | 	if (!new && (waiters || val<0)) | ||
| 15 | 		__wake(&rw->_rw_lock, cnt, priv); | ||
| 16 | |||
| 17 | 	return 0; | ||
| 18 | } | ||
| 19 | |||
| 20 | weak_alias(__pthread_rwlock_unlock, pthread_rwlock_unlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlock_wrlock.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_rwlock_wrlock(pthread_rwlock_t *rw) | ||
| 4 | { | ||
| 5 | 	return __pthread_rwlock_timedwrlock(rw, 0); | ||
| 6 | } | ||
| 7 | |||
| 8 | weak_alias(__pthread_rwlock_wrlock, pthread_rwlock_wrlock); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_rwlockattr_destroy(pthread_rwlockattr_t *a) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_init.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_rwlockattr_init(pthread_rwlockattr_t *a) | ||
| 4 | { | ||
| 5 | 	*a = (pthread_rwlockattr_t){0}; | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_rwlockattr_setpshared.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_rwlockattr_setpshared(pthread_rwlockattr_t *a, int pshared) | ||
| 4 | { | ||
| 5 | 	if (pshared > 1U) return EINVAL; | ||
| 6 | 	a->__attr[0] = pshared; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_self.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | static pthread_t __pthread_self_internal() | ||
| 5 | { | ||
| 6 | 	return __pthread_self(); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(__pthread_self_internal, pthread_self); | ||
| 10 | weak_alias(__pthread_self_internal, thrd_current); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setattr_default_np.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | #define MIN(a,b) ((a)<(b) ? (a) : (b)) | ||
| 6 | #define MAX(a,b) ((a)>(b) ? (a) : (b)) | ||
| 7 | |||
| 8 | int pthread_setattr_default_np(const pthread_attr_t *attrp) | ||
| 9 | { | ||
| 10 | 	/* Reject anything in the attr object other than stack/guard size. */ | ||
| 11 | 	pthread_attr_t tmp = *attrp, zero = { 0 }; | ||
| 12 | 	tmp._a_stacksize = 0; | ||
| 13 | 	tmp._a_guardsize = 0; | ||
| 14 | 	if (memcmp(&tmp, &zero, sizeof tmp)) | ||
| 15 | 		return EINVAL; | ||
| 16 | |||
| 17 | 	unsigned stack = MIN(attrp->_a_stacksize, DEFAULT_STACK_MAX); | ||
| 18 | 	unsigned guard = MIN(attrp->_a_guardsize, DEFAULT_GUARD_MAX); | ||
| 19 | |||
| 20 | 	__inhibit_ptc(); | ||
| 21 | 	__default_stacksize = MAX(__default_stacksize, stack); | ||
| 22 | 	__default_guardsize = MAX(__default_guardsize, guard); | ||
| 23 | 	__release_ptc(); | ||
| 24 | |||
| 25 | 	return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | int pthread_getattr_default_np(pthread_attr_t *attrp) | ||
| 29 | { | ||
| 30 | 	__acquire_ptc(); | ||
| 31 | 	*attrp = (pthread_attr_t) { | ||
| 32 | 		._a_stacksize = __default_stacksize, | ||
| 33 | 		._a_guardsize = __default_guardsize, | ||
| 34 | 	}; | ||
| 35 | 	__release_ptc(); | ||
| 36 | 	return 0; | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setcancelstate.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int __pthread_setcancelstate(int new, int *old) | ||
| 4 | { | ||
| 5 | 	if (new > 2U) return EINVAL; | ||
| 6 | 	struct pthread *self = __pthread_self(); | ||
| 7 | 	if (old) *old = self->canceldisable; | ||
| 8 | 	self->canceldisable = new; | ||
| 9 | 	return 0; | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(__pthread_setcancelstate, pthread_setcancelstate); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setcanceltype.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_setcanceltype(int new, int *old) | ||
| 4 | { | ||
| 5 | 	struct pthread *self = __pthread_self(); | ||
| 6 | 	if (new > 1U) return EINVAL; | ||
| 7 | 	if (old) *old = self->cancelasync; | ||
| 8 | 	self->cancelasync = new; | ||
| 9 | 	if (new) pthread_testcancel(); | ||
| 10 | 	return 0; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setconcurrency.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <pthread.h> | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int pthread_setconcurrency(int val) | ||
| 5 | { | ||
| 6 | 	if (val < 0) return EINVAL; | ||
| 7 | 	if (val > 0) return EAGAIN; | ||
| 8 | 	return 0; | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setname_np.c created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <unistd.h> | ||
| 5 | #include <sys/prctl.h> | ||
| 6 | |||
| 7 | #include "pthread_impl.h" | ||
| 8 | |||
| 9 | int pthread_setname_np(pthread_t thread, const char *name) | ||
| 10 | { | ||
| 11 | 	int fd, cs, status = 0; | ||
| 12 | 	char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)]; | ||
| 13 | 	size_t len; | ||
| 14 | |||
| 15 | 	if ((len = strnlen(name, 16)) > 15) return ERANGE; | ||
| 16 | |||
| 17 | 	if (thread == pthread_self()) | ||
| 18 | 		return prctl(PR_SET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0; | ||
| 19 | |||
| 20 | 	snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid); | ||
| 21 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 22 | 	if ((fd = open(f, O_WRONLY)) < 0 || write(fd, name, len) < 0) status = errno; | ||
| 23 | 	if (fd >= 0) close(fd); | ||
| 24 | 	pthread_setcancelstate(cs, 0); | ||
| 25 | 	return status; | ||
| 26 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setschedparam.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "lock.h" | ||
| 3 | |||
| 4 | int pthread_setschedparam(pthread_t t, int policy, const struct sched_param *param) | ||
| 5 | { | ||
| 6 | 	int r; | ||
| 7 | 	sigset_t set; | ||
| 8 | 	__block_app_sigs(&set); | ||
| 9 | 	LOCK(t->killlock); | ||
| 10 | 	r = !t->tid ? ESRCH : -__syscall(SYS_sched_setscheduler, t->tid, policy, param); | ||
| 11 | 	UNLOCK(t->killlock); | ||
| 12 | 	__restore_sigs(&set); | ||
| 13 | 	return r; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setschedprio.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "lock.h" | ||
| 3 | |||
| 4 | int pthread_setschedprio(pthread_t t, int prio) | ||
| 5 | { | ||
| 6 | 	int r; | ||
| 7 | 	sigset_t set; | ||
| 8 | 	__block_app_sigs(&set); | ||
| 9 | 	LOCK(t->killlock); | ||
| 10 | 	r = !t->tid ? ESRCH : -__syscall(SYS_sched_setparam, t->tid, &prio); | ||
| 11 | 	UNLOCK(t->killlock); | ||
| 12 | 	__restore_sigs(&set); | ||
| 13 | 	return r; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setspecific.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_setspecific(pthread_key_t k, const void *x) | ||
| 4 | { | ||
| 5 | 	struct pthread *self = __pthread_self(); | ||
| 6 | 	/* Avoid unnecessary COW */ | ||
| 7 | 	if (self->tsd[k] != x) { | ||
| 8 | 		self->tsd[k] = (void *)x; | ||
| 9 | 		self->tsd_used = 1; | ||
| 10 | 	} | ||
| 11 | 	return 0; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_sigmask.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <signal.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int pthread_sigmask(int how, const sigset_t *restrict set, sigset_t *restrict old) | ||
| 6 | { | ||
| 7 | 	int ret; | ||
| 8 | 	if (set && (unsigned)how - SIG_BLOCK > 2U) return EINVAL; | ||
| 9 | 	ret = -__syscall(SYS_rt_sigprocmask, how, set, old, _NSIG/8); | ||
| 10 | 	if (!ret && old) { | ||
| 11 | 		if (sizeof old->__bits[0] == 8) { | ||
| 12 | 			old->__bits[0] &= ~0x380000000ULL; | ||
| 13 | 		} else { | ||
| 14 | 			old->__bits[0] &= ~0x80000000UL; | ||
| 15 | 			old->__bits[1] &= ~0x3UL; | ||
| 16 | 		} | ||
| 17 | 	} | ||
| 18 | 	return ret; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_spin_destroy(pthread_spinlock_t *s) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_init.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_spin_init(pthread_spinlock_t *s, int shared) | ||
| 4 | { | ||
| 5 | 	return *s = 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_lock.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int pthread_spin_lock(pthread_spinlock_t *s) | ||
| 5 | { | ||
| 6 | 	while (*(volatile int *)s || a_cas(s, 0, EBUSY)) a_spin(); | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_trylock.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <errno.h> | ||
| 3 | |||
| 4 | int pthread_spin_trylock(pthread_spinlock_t *s) | ||
| 5 | { | ||
| 6 | 	return a_cas(s, 0, EBUSY); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_spin_unlock.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | int pthread_spin_unlock(pthread_spinlock_t *s) | ||
| 4 | { | ||
| 5 | 	a_store(s, 0); | ||
| 6 | 	return 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_testcancel.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | static void dummy() | ||
| 4 | { | ||
| 5 | } | ||
| 6 | |||
| 7 | weak_alias(dummy, __testcancel); | ||
| 8 | |||
| 9 | void __pthread_testcancel() | ||
| 10 | { | ||
| 11 | 	__testcancel(); | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__pthread_testcancel, pthread_testcancel); | ||
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/__set_thread_area.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .global __set_thread_area | ||
| 2 | .type __set_thread_area, %function | ||
| 3 | __set_thread_area: | ||
| 4 | 	mv tp, a0 | ||
| 5 | 	li a0, 0 | ||
| 6 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/__unmapself.s created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | .global __unmapself | ||
| 2 | .type __unmapself, %function | ||
| 3 | __unmapself: | ||
| 4 | 	li a7, 215 # SYS_munmap | ||
| 5 | 	ecall | ||
| 6 | 	li a7, 93 # SYS_exit | ||
| 7 | 	ecall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/clone.s created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | # __clone(func, stack, flags, arg, ptid, tls, ctid) | ||
| 2 | # a0, a1, a2, a3, a4, a5, a6 | ||
| 3 | |||
| 4 | # syscall(SYS_clone, flags, stack, ptid, tls, ctid) | ||
| 5 | # a7 a0, a1, a2, a3, a4 | ||
| 6 | |||
| 7 | .global __clone | ||
| 8 | .type __clone, %function | ||
| 9 | __clone: | ||
| 10 | 	# Save func and arg to stack | ||
| 11 | 	addi a1, a1, -16 | ||
| 12 | 	sd a0, 0(a1) | ||
| 13 | 	sd a3, 8(a1) | ||
| 14 | |||
| 15 | 	# Call SYS_clone | ||
| 16 | 	mv a0, a2 | ||
| 17 | 	mv a2, a4 | ||
| 18 | 	mv a3, a5 | ||
| 19 | 	mv a4, a6 | ||
| 20 | 	li a7, 220 # SYS_clone | ||
| 21 | 	ecall | ||
| 22 | |||
| 23 | 	beqz a0, 1f | ||
| 24 | 	# Parent | ||
| 25 | 	ret | ||
| 26 | |||
| 27 | 	# Child | ||
| 28 | 1: ld a1, 0(sp) | ||
| 29 | 	ld a0, 8(sp) | ||
| 30 | 	jalr a1 | ||
| 31 | |||
| 32 | 	# Exit | ||
| 33 | 	li a7, 93 # SYS_exit | ||
| 34 | 	ecall | ||
lib/libc/wasi/libc-top-half/musl/src/thread/riscv64/syscall_cp.s created+29| ... | @@ -0,0 +1,29 @@ | ||
| 1 | .global __cp_begin | ||
| 2 | .hidden __cp_begin | ||
| 3 | .global __cp_end | ||
| 4 | .hidden __cp_end | ||
| 5 | .global __cp_cancel | ||
| 6 | .hidden __cp_cancel | ||
| 7 | .hidden __cancel | ||
| 8 | .global __syscall_cp_asm | ||
| 9 | .hidden __syscall_cp_asm | ||
| 10 | .type __syscall_cp_asm, %function | ||
| 11 | __syscall_cp_asm: | ||
| 12 | __cp_begin: | ||
| 13 | 	lw t0, 0(a0) | ||
| 14 | 	bnez t0, __cp_cancel | ||
| 15 | |||
| 16 | 	mv t0, a1 | ||
| 17 | 	mv a0, a2 | ||
| 18 | 	mv a1, a3 | ||
| 19 | 	mv a2, a4 | ||
| 20 | 	mv a3, a5 | ||
| 21 | 	mv a4, a6 | ||
| 22 | 	mv a5, a7 | ||
| 23 | 	ld a6, 0(sp) | ||
| 24 | 	mv a7, t0 | ||
| 25 | 	ecall | ||
| 26 | __cp_end: | ||
| 27 | 	ret | ||
| 28 | __cp_cancel: | ||
| 29 | 	tail __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__set_thread_area.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | .text | ||
| 2 | .global __set_thread_area | ||
| 3 | .hidden __set_thread_area | ||
| 4 | .type __set_thread_area, %function | ||
| 5 | __set_thread_area: | ||
| 6 | 	sar %a1, %r2 | ||
| 7 | 	srlg %r2, %r2, 32 | ||
| 8 | 	sar %a0, %r2 | ||
| 9 | 	lghi %r2, 0 | ||
| 10 | 	br %r14 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__tls_get_offset.s created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | 	.global __tls_get_offset | ||
| 2 | 	.type __tls_get_offset,%function | ||
| 3 | __tls_get_offset: | ||
| 4 | 	stmg %r14, %r15, 112(%r15) | ||
| 5 | 	aghi %r15, -160 | ||
| 6 | |||
| 7 | 	la %r2, 0(%r2, %r12) | ||
| 8 | 	brasl %r14, __tls_get_addr | ||
| 9 | |||
| 10 | 	ear %r1, %a0 | ||
| 11 | 	sllg %r1, %r1, 32 | ||
| 12 | 	ear %r1, %a1 | ||
| 13 | |||
| 14 | 	sgr %r2, %r1 | ||
| 15 | |||
| 16 | 	lmg %r14, %r15, 272(%r15) | ||
| 17 | 	br %r14 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/__unmapself.s created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | .text | ||
| 2 | .global __unmapself | ||
| 3 | .type __unmapself, @function | ||
| 4 | __unmapself: | ||
| 5 | 	svc 91 # SYS_munmap | ||
| 6 | 	svc 1 # SYS_exit | ||
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/clone.s created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone, %function | ||
| 5 | __clone: | ||
| 6 | 	# int clone( | ||
| 7 | 	# fn, a = r2 | ||
| 8 | 	# stack, b = r3 | ||
| 9 | 	# flags, c = r4 | ||
| 10 | 	# arg, d = r5 | ||
| 11 | 	# ptid, e = r6 | ||
| 12 | 	# tls, f = *(r15+160) | ||
| 13 | 	# ctid) g = *(r15+168) | ||
| 14 | 	# | ||
| 15 | 	# pseudo C code: | ||
| 16 | 	# tid = syscall(SYS_clone,b,c,e,g,f); | ||
| 17 | 	# if (!tid) syscall(SYS_exit, a(d)); | ||
| 18 | 	# return tid; | ||
| 19 | |||
| 20 | 	# preserve call-saved register used as syscall arg | ||
| 21 | 	stg %r6, 48(%r15) | ||
| 22 | |||
| 23 | 	# create initial stack frame for new thread | ||
| 24 | 	nill %r3, 0xfff8 | ||
| 25 | 	aghi %r3, -160 | ||
| 26 | 	lghi %r0, 0 | ||
| 27 | 	stg %r0, 0(%r3) | ||
| 28 | |||
| 29 | 	# save fn and arg to child stack | ||
| 30 | 	stg %r2, 8(%r3) | ||
| 31 | 	stg %r5, 16(%r3) | ||
| 32 | |||
| 33 | 	# shuffle args into correct registers and call SYS_clone | ||
| 34 | 	lgr %r2, %r3 | ||
| 35 | 	lgr %r3, %r4 | ||
| 36 | 	lgr %r4, %r6 | ||
| 37 | 	lg %r5, 168(%r15) | ||
| 38 | 	lg %r6, 160(%r15) | ||
| 39 | 	svc 120 | ||
| 40 | |||
| 41 | 	# restore call-saved register | ||
| 42 | 	lg %r6, 48(%r15) | ||
| 43 | |||
| 44 | 	# if error or if we're the parent, return | ||
| 45 | 	ltgr %r2, %r2 | ||
| 46 | 	bnzr %r14 | ||
| 47 | |||
| 48 | 	# we're the child. call fn(arg) | ||
| 49 | 	lg %r1, 8(%r15) | ||
| 50 | 	lg %r2, 16(%r15) | ||
| 51 | 	basr %r14, %r1 | ||
| 52 | |||
| 53 | 	# call SYS_exit. exit code is already in r2 from fn return value | ||
| 54 | 	svc 1 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/s390x/syscall_cp.s created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | 	.global __cp_begin | ||
| 2 | 	.hidden __cp_begin | ||
| 3 | 	.global __cp_end | ||
| 4 | 	.hidden __cp_end | ||
| 5 | 	.global __cp_cancel | ||
| 6 | 	.hidden __cp_cancel | ||
| 7 | 	.hidden __cancel | ||
| 8 | 	.global __syscall_cp_asm | ||
| 9 | 	.hidden __syscall_cp_asm | ||
| 10 | 	.text | ||
| 11 | 	.type __syscall_cp_asm,%function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | __cp_begin: | ||
| 14 | 	icm %r2, 15, 0(%r2) | ||
| 15 | 	jne __cp_cancel | ||
| 16 | |||
| 17 | 	stg %r6, 48(%r15) | ||
| 18 | 	stg %r7, 56(%r15) | ||
| 19 | 	lgr %r1, %r3 | ||
| 20 | 	lgr %r2, %r4 | ||
| 21 | 	lgr %r3, %r5 | ||
| 22 | 	lgr %r4, %r6 | ||
| 23 | 	lg %r5, 160(%r15) | ||
| 24 | 	lg %r6, 168(%r15) | ||
| 25 | 	lg %r7, 176(%r15) | ||
| 26 | 	svc 0 | ||
| 27 | |||
| 28 | __cp_end: | ||
| 29 | 	lg %r7, 56(%r15) | ||
| 30 | 	lg %r6, 48(%r15) | ||
| 31 | 	br %r14 | ||
| 32 | |||
| 33 | __cp_cancel: | ||
| 34 | 	jg __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_destroy.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | |||
| 3 | int sem_destroy(sem_t *sem) | ||
| 4 | { | ||
| 5 | 	return 0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_getvalue.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | |||
| 3 | int sem_getvalue(sem_t *restrict sem, int *restrict valp) | ||
| 4 | { | ||
| 5 | 	int val = sem->__val[0]; | ||
| 6 | 	*valp = val < 0 ? 0 : val; | ||
| 7 | 	return 0; | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_init.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int sem_init(sem_t *sem, int pshared, unsigned value) | ||
| 6 | { | ||
| 7 | 	if (value > SEM_VALUE_MAX) { | ||
| 8 | 		errno = EINVAL; | ||
| 9 | 		return -1; | ||
| 10 | 	} | ||
| 11 | 	sem->__val[0] = value; | ||
| 12 | 	sem->__val[1] = 0; | ||
| 13 | 	sem->__val[2] = pshared ? 0 : 128; | ||
| 14 | 	return 0; | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_open.c created+182| ... | @@ -0,0 +1,182 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | #include <sys/mman.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include <unistd.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <stdarg.h> | ||
| 8 | #include <errno.h> | ||
| 9 | #include <time.h> | ||
| 10 | #include <stdio.h> | ||
| 11 | #include <sys/stat.h> | ||
| 12 | #include <stdlib.h> | ||
| 13 | #include <pthread.h> | ||
| 14 | #include "lock.h" | ||
| 15 | #include "fork_impl.h" | ||
| 16 | |||
| 17 | #define malloc __libc_malloc | ||
| 18 | #define calloc __libc_calloc | ||
| 19 | #define realloc undef | ||
| 20 | #define free undef | ||
| 21 | |||
| 22 | static struct { | ||
| 23 | 	ino_t ino; | ||
| 24 | 	sem_t *sem; | ||
| 25 | 	int refcnt; | ||
| 26 | } *semtab; | ||
| 27 | static volatile int lock[1]; | ||
| 28 | volatile int *const __sem_open_lockptr = lock; | ||
| 29 | |||
| 30 | #define FLAGS (O_RDWR|O_NOFOLLOW|O_CLOEXEC|O_NONBLOCK) | ||
| 31 | |||
| 32 | sem_t *sem_open(const char *name, int flags, ...) | ||
| 33 | { | ||
| 34 | 	va_list ap; | ||
| 35 | 	mode_t mode; | ||
| 36 | 	unsigned value; | ||
| 37 | 	int fd, i, e, slot, first=1, cnt, cs; | ||
| 38 | 	sem_t newsem; | ||
| 39 | 	void *map; | ||
| 40 | 	char tmp[64]; | ||
| 41 | 	struct timespec ts; | ||
| 42 | 	struct stat st; | ||
| 43 | 	char buf[NAME_MAX+10]; | ||
| 44 | |||
| 45 | 	if (!(name = __shm_mapname(name, buf))) | ||
| 46 | 		return SEM_FAILED; | ||
| 47 | |||
| 48 | 	LOCK(lock); | ||
| 49 | 	/* Allocate table if we don't have one yet */ | ||
| 50 | 	if (!semtab && !(semtab = calloc(sizeof *semtab, SEM_NSEMS_MAX))) { | ||
| 51 | 		UNLOCK(lock); | ||
| 52 | 		return SEM_FAILED; | ||
| 53 | 	} | ||
| 54 | |||
| 55 | 	/* Reserve a slot in case this semaphore is not mapped yet; | ||
| 56 | 	 * this is necessary because there is no way to handle | ||
| 57 | 	 * failures after creation of the file. */ | ||
| 58 | 	slot = -1; | ||
| 59 | 	for (cnt=i=0; i<SEM_NSEMS_MAX; i++) { | ||
| 60 | 		cnt += semtab[i].refcnt; | ||
| 61 | 		if (!semtab[i].sem && slot < 0) slot = i; | ||
| 62 | 	} | ||
| 63 | 	/* Avoid possibility of overflow later */ | ||
| 64 | 	if (cnt == INT_MAX || slot < 0) { | ||
| 65 | 		errno = EMFILE; | ||
| 66 | 		UNLOCK(lock); | ||
| 67 | 		return SEM_FAILED; | ||
| 68 | 	} | ||
| 69 | 	/* Dummy pointer to make a reservation */ | ||
| 70 | 	semtab[slot].sem = (sem_t *)-1; | ||
| 71 | 	UNLOCK(lock); | ||
| 72 | |||
| 73 | 	flags &= (O_CREAT|O_EXCL); | ||
| 74 | |||
| 75 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 76 | |||
| 77 | 	/* Early failure check for exclusive open; otherwise the case | ||
| 78 | 	 * where the semaphore already exists is expensive. */ | ||
| 79 | 	if (flags == (O_CREAT|O_EXCL) && access(name, F_OK) == 0) { | ||
| 80 | 		errno = EEXIST; | ||
| 81 | 		goto fail; | ||
| 82 | 	} | ||
| 83 | |||
| 84 | 	for (;;) { | ||
| 85 | 		/* If exclusive mode is not requested, try opening an | ||
| 86 | 		 * existing file first and fall back to creation. */ | ||
| 87 | 		if (flags != (O_CREAT|O_EXCL)) { | ||
| 88 | 			fd = open(name, FLAGS); | ||
| 89 | 			if (fd >= 0) { | ||
| 90 | 				if (fstat(fd, &st) < 0 || | ||
| 91 | 				 (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { | ||
| 92 | 					close(fd); | ||
| 93 | 					goto fail; | ||
| 94 | 				} | ||
| 95 | 				close(fd); | ||
| 96 | 				break; | ||
| 97 | 			} | ||
| 98 | 			if (errno != ENOENT) | ||
| 99 | 				goto fail; | ||
| 100 | 		} | ||
| 101 | 		if (!(flags & O_CREAT)) | ||
| 102 | 			goto fail; | ||
| 103 | 		if (first) { | ||
| 104 | 			first = 0; | ||
| 105 | 			va_start(ap, flags); | ||
| 106 | 			mode = va_arg(ap, mode_t) & 0666; | ||
| 107 | 			value = va_arg(ap, unsigned); | ||
| 108 | 			va_end(ap); | ||
| 109 | 			if (value > SEM_VALUE_MAX) { | ||
| 110 | 				errno = EINVAL; | ||
| 111 | 				goto fail; | ||
| 112 | 			} | ||
| 113 | 			sem_init(&newsem, 1, value); | ||
| 114 | 		} | ||
| 115 | 		/* Create a temp file with the new semaphore contents | ||
| 116 | 		 * and attempt to atomically link it as the new name */ | ||
| 117 | 		clock_gettime(CLOCK_REALTIME, &ts); | ||
| 118 | 		snprintf(tmp, sizeof(tmp), "/dev/shm/tmp-%d", (int)ts.tv_nsec); | ||
| 119 | 		fd = open(tmp, O_CREAT|O_EXCL|FLAGS, mode); | ||
| 120 | 		if (fd < 0) { | ||
| 121 | 			if (errno == EEXIST) continue; | ||
| 122 | 			goto fail; | ||
| 123 | 		} | ||
| 124 | 		if (write(fd, &newsem, sizeof newsem) != sizeof newsem || fstat(fd, &st) < 0 || | ||
| 125 | 		 (map = mmap(0, sizeof(sem_t), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == MAP_FAILED) { | ||
| 126 | 			close(fd); | ||
| 127 | 			unlink(tmp); | ||
| 128 | 			goto fail; | ||
| 129 | 		} | ||
| 130 | 		close(fd); | ||
| 131 | 		e = link(tmp, name) ? errno : 0; | ||
| 132 | 		unlink(tmp); | ||
| 133 | 		if (!e) break; | ||
| 134 | 		munmap(map, sizeof(sem_t)); | ||
| 135 | 		/* Failure is only fatal when doing an exclusive open; | ||
| 136 | 		 * otherwise, next iteration will try to open the | ||
| 137 | 		 * existing file. */ | ||
| 138 | 		if (e != EEXIST || flags == (O_CREAT|O_EXCL)) | ||
| 139 | 			goto fail; | ||
| 140 | 	} | ||
| 141 | |||
| 142 | 	/* See if the newly mapped semaphore is already mapped. If | ||
| 143 | 	 * so, unmap the new mapping and use the existing one. Otherwise, | ||
| 144 | 	 * add it to the table of mapped semaphores. */ | ||
| 145 | 	LOCK(lock); | ||
| 146 | 	for (i=0; i<SEM_NSEMS_MAX && semtab[i].ino != st.st_ino; i++); | ||
| 147 | 	if (i<SEM_NSEMS_MAX) { | ||
| 148 | 		munmap(map, sizeof(sem_t)); | ||
| 149 | 		semtab[slot].sem = 0; | ||
| 150 | 		slot = i; | ||
| 151 | 		map = semtab[i].sem; | ||
| 152 | 	} | ||
| 153 | 	semtab[slot].refcnt++; | ||
| 154 | 	semtab[slot].sem = map; | ||
| 155 | 	semtab[slot].ino = st.st_ino; | ||
| 156 | 	UNLOCK(lock); | ||
| 157 | 	pthread_setcancelstate(cs, 0); | ||
| 158 | 	return map; | ||
| 159 | |||
| 160 | fail: | ||
| 161 | 	pthread_setcancelstate(cs, 0); | ||
| 162 | 	LOCK(lock); | ||
| 163 | 	semtab[slot].sem = 0; | ||
| 164 | 	UNLOCK(lock); | ||
| 165 | 	return SEM_FAILED; | ||
| 166 | } | ||
| 167 | |||
| 168 | int sem_close(sem_t *sem) | ||
| 169 | { | ||
| 170 | 	int i; | ||
| 171 | 	LOCK(lock); | ||
| 172 | 	for (i=0; i<SEM_NSEMS_MAX && semtab[i].sem != sem; i++); | ||
| 173 | 	if (--semtab[i].refcnt) { | ||
| 174 | 		UNLOCK(lock); | ||
| 175 | 		return 0; | ||
| 176 | 	} | ||
| 177 | 	semtab[i].sem = 0; | ||
| 178 | 	semtab[i].ino = 0; | ||
| 179 | 	UNLOCK(lock); | ||
| 180 | 	munmap(sem, sizeof *sem); | ||
| 181 | 	return 0; | ||
| 182 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_post.c created+17| ... | @@ -0,0 +1,17 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | int sem_post(sem_t *sem) | ||
| 5 | { | ||
| 6 | 	int val, waiters, priv = sem->__val[2]; | ||
| 7 | 	do { | ||
| 8 | 		val = sem->__val[0]; | ||
| 9 | 		waiters = sem->__val[1]; | ||
| 10 | 		if (val == SEM_VALUE_MAX) { | ||
| 11 | 			errno = EOVERFLOW; | ||
| 12 | 			return -1; | ||
| 13 | 		} | ||
| 14 | 	} while (a_cas(sem->__val, val, val+1+(val<0)) != val); | ||
| 15 | 	if (val<0 || waiters) __wake(sem->__val, 1, priv); | ||
| 16 | 	return 0; | ||
| 17 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_timedwait.c created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | static void cleanup(void *p) | ||
| 5 | { | ||
| 6 | 	a_dec(p); | ||
| 7 | } | ||
| 8 | |||
| 9 | int sem_timedwait(sem_t *restrict sem, const struct timespec *restrict at) | ||
| 10 | { | ||
| 11 | 	pthread_testcancel(); | ||
| 12 | |||
| 13 | 	if (!sem_trywait(sem)) return 0; | ||
| 14 | |||
| 15 | 	int spins = 100; | ||
| 16 | 	while (spins-- && sem->__val[0] <= 0 && !sem->__val[1]) a_spin(); | ||
| 17 | |||
| 18 | 	while (sem_trywait(sem)) { | ||
| 19 | 		int r; | ||
| 20 | 		a_inc(sem->__val+1); | ||
| 21 | 		a_cas(sem->__val, 0, -1); | ||
| 22 | 		pthread_cleanup_push(cleanup, (void *)(sem->__val+1)); | ||
| 23 | 		r = __timedwait_cp(sem->__val, -1, CLOCK_REALTIME, at, sem->__val[2]); | ||
| 24 | 		pthread_cleanup_pop(1); | ||
| 25 | 		if (r) { | ||
| 26 | 			errno = r; | ||
| 27 | 			return -1; | ||
| 28 | 		} | ||
| 29 | 	} | ||
| 30 | 	return 0; | ||
| 31 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_trywait.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | #include "pthread_impl.h" | ||
| 3 | |||
| 4 | int sem_trywait(sem_t *sem) | ||
| 5 | { | ||
| 6 | 	int val; | ||
| 7 | 	while ((val=sem->__val[0]) > 0) { | ||
| 8 | 		int new = val-1-(val==1 && sem->__val[1]); | ||
| 9 | 		if (a_cas(sem->__val, val, new)==val) return 0; | ||
| 10 | 	} | ||
| 11 | 	errno = EAGAIN; | ||
| 12 | 	return -1; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_unlink.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | #include <sys/mman.h> | ||
| 3 | |||
| 4 | int sem_unlink(const char *name) | ||
| 5 | { | ||
| 6 | 	return shm_unlink(name); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sem_wait.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <semaphore.h> | ||
| 2 | |||
| 3 | int sem_wait(sem_t *sem) | ||
| 4 | { | ||
| 5 | 	return sem_timedwait(sem, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__set_thread_area.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "libc.h" | ||
| 3 | #include <elf.h> | ||
| 4 | |||
| 5 | /* Also perform sh-specific init */ | ||
| 6 | |||
| 7 | #define CPU_HAS_LLSC 0x0040 | ||
| 8 | #define CPU_HAS_CAS_L 0x0400 | ||
| 9 | |||
| 10 | extern hidden const char __sh_cas_gusa[], __sh_cas_llsc[], __sh_cas_imask[], __sh_cas_cas_l[]; | ||
| 11 | |||
| 12 | hidden const void *__sh_cas_ptr; | ||
| 13 | |||
| 14 | hidden unsigned __sh_nommu; | ||
| 15 | |||
| 16 | int __set_thread_area(void *p) | ||
| 17 | { | ||
| 18 | 	size_t *aux; | ||
| 19 | 	__asm__ __volatile__ ( "ldc %0, gbr" : : "r"(p) : "memory" ); | ||
| 20 | #ifndef __SH4A__ | ||
| 21 | 	__sh_cas_ptr = __sh_cas_gusa; | ||
| 22 | #if !defined(__SH3__) && !defined(__SH4__) | ||
| 23 | 	for (aux=libc.auxv; *aux; aux+=2) { | ||
| 24 | 		if (*aux != AT_PLATFORM) continue; | ||
| 25 | 		const char *s = (void *)aux[1]; | ||
| 26 | 		if (s[0]!='s' || s[1]!='h' || s[2]!='2' || s[3]-'0'<10u) break; | ||
| 27 | 		__sh_cas_ptr = __sh_cas_imask; | ||
| 28 | 		__sh_nommu = 1; | ||
| 29 | 	} | ||
| 30 | #endif | ||
| 31 | 	if (__hwcap & CPU_HAS_CAS_L) | ||
| 32 | 		__sh_cas_ptr = __sh_cas_cas_l; | ||
| 33 | 	else if (__hwcap & CPU_HAS_LLSC) | ||
| 34 | 		__sh_cas_ptr = __sh_cas_llsc; | ||
| 35 | #endif | ||
| 36 | 	return 0; | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__unmapself.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | |||
| 3 | hidden void __unmapself_sh_mmu(void *, size_t); | ||
| 4 | hidden void __unmapself_sh_nommu(void *, size_t); | ||
| 5 | |||
| 6 | #if !defined(__SH3__) && !defined(__SH4__) | ||
| 7 | #define __unmapself __unmapself_sh_nommu | ||
| 8 | #include "dynlink.h" | ||
| 9 | #undef CRTJMP | ||
| 10 | #define CRTJMP(pc,sp) __asm__ __volatile__( \ | ||
| 11 | 	"mov.l @%0+,r0 ; mov.l @%0,r12 ; jmp @r0 ; mov %1,r15" \ | ||
| 12 | 	: : "r"(pc), "r"(sp) : "r0", "memory" ) | ||
| 13 | #include "../__unmapself.c" | ||
| 14 | #undef __unmapself | ||
| 15 | extern hidden unsigned __sh_nommu; | ||
| 16 | #else | ||
| 17 | #define __sh_nommu 0 | ||
| 18 | #endif | ||
| 19 | |||
| 20 | void __unmapself(void *base, size_t size) | ||
| 21 | { | ||
| 22 | 	if (__sh_nommu) __unmapself_sh_nommu(base, size); | ||
| 23 | 	else __unmapself_sh_mmu(base, size); | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sh/__unmapself_mmu.s created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | .text | ||
| 2 | .global __unmapself_sh_mmu | ||
| 3 | .hidden __unmapself_sh_mmu | ||
| 4 | .type __unmapself_sh_mmu, @function | ||
| 5 | __unmapself_sh_mmu: | ||
| 6 | 	mov #91, r3 ! SYS_munmap | ||
| 7 | 	trapa #31 | ||
| 8 | |||
| 9 | 	or r0, r0 | ||
| 10 | 	or r0, r0 | ||
| 11 | 	or r0, r0 | ||
| 12 | 	or r0, r0 | ||
| 13 | 	or r0, r0 | ||
| 14 | |||
| 15 | 	mov #1, r3 ! SYS_exit | ||
| 16 | 	mov #0, r4 | ||
| 17 | 	trapa #31 | ||
| 18 | |||
| 19 | 	or r0, r0 | ||
| 20 | 	or r0, r0 | ||
| 21 | 	or r0, r0 | ||
| 22 | 	or r0, r0 | ||
| 23 | 	or r0, r0 | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sh/atomics.s created+65| ... | @@ -0,0 +1,65 @@ | ||
| 1 | /* Contract for all versions is same as cas.l r2,r3,@r0 | ||
| 2 | * pr and r1 are also clobbered (by jsr & r1 as temp). | ||
| 3 | * r0,r2,r4-r15 must be preserved. | ||
| 4 | * r3 contains result (==r2 iff cas succeeded). */ | ||
| 5 | |||
| 6 | 	.align 2 | ||
| 7 | .global __sh_cas_gusa | ||
| 8 | .hidden __sh_cas_gusa | ||
| 9 | __sh_cas_gusa: | ||
| 10 | 	mov.l r5,@-r15 | ||
| 11 | 	mov.l r4,@-r15 | ||
| 12 | 	mov r0,r4 | ||
| 13 | 	mova 1f,r0 | ||
| 14 | 	mov r15,r1 | ||
| 15 | 	mov #(0f-1f),r15 | ||
| 16 | 0:	mov.l @r4,r5 | ||
| 17 | 	cmp/eq r5,r2 | ||
| 18 | 	bf 1f | ||
| 19 | 	mov.l r3,@r4 | ||
| 20 | 1:	mov r1,r15 | ||
| 21 | 	mov r5,r3 | ||
| 22 | 	mov r4,r0 | ||
| 23 | 	mov.l @r15+,r4 | ||
| 24 | 	rts | ||
| 25 | 	 mov.l @r15+,r5 | ||
| 26 | |||
| 27 | .global __sh_cas_llsc | ||
| 28 | .hidden __sh_cas_llsc | ||
| 29 | __sh_cas_llsc: | ||
| 30 | 	mov r0,r1 | ||
| 31 | 	.word 0x00ab /* synco */ | ||
| 32 | 0:	.word 0x0163 /* movli.l @r1,r0 */ | ||
| 33 | 	cmp/eq r0,r2 | ||
| 34 | 	bf 1f | ||
| 35 | 	mov r3,r0 | ||
| 36 | 	.word 0x0173 /* movco.l r0,@r1 */ | ||
| 37 | 	bf 0b | ||
| 38 | 	mov r2,r0 | ||
| 39 | 1:	.word 0x00ab /* synco */ | ||
| 40 | 	mov r0,r3 | ||
| 41 | 	rts | ||
| 42 | 	 mov r1,r0 | ||
| 43 | |||
| 44 | .global __sh_cas_imask | ||
| 45 | .hidden __sh_cas_imask | ||
| 46 | __sh_cas_imask: | ||
| 47 | 	mov r0,r1 | ||
| 48 | 	stc sr,r0 | ||
| 49 | 	mov.l r0,@-r15 | ||
| 50 | 	or #0xf0,r0 | ||
| 51 | 	ldc r0,sr | ||
| 52 | 	mov.l @r1,r0 | ||
| 53 | 	cmp/eq r0,r2 | ||
| 54 | 	bf 1f | ||
| 55 | 	mov.l r3,@r1 | ||
| 56 | 1:	ldc.l @r15+,sr | ||
| 57 | 	mov r0,r3 | ||
| 58 | 	rts | ||
| 59 | 	 mov r1,r0 | ||
| 60 | |||
| 61 | .global __sh_cas_cas_l | ||
| 62 | .hidden __sh_cas_cas_l | ||
| 63 | __sh_cas_cas_l: | ||
| 64 | 	rts | ||
| 65 | 	 .word 0x2323 /* cas.l r2,r3,@r0 */ | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sh/clone.s created+54| ... | @@ -0,0 +1,54 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone, @function | ||
| 5 | __clone: | ||
| 6 | ! incoming: fn stack flags arg ptid tls ctid | ||
| 7 | ! r4 r5 r6 r7 @r15 @(4,r15) @(8,r15) | ||
| 8 | |||
| 9 | 	mov #-16, r0 | ||
| 10 | 	and r0, r5 | ||
| 11 | |||
| 12 | 	mov r4, r1 ! r1 = fn | ||
| 13 | 	mov r7, r2 ! r2 = arg | ||
| 14 | |||
| 15 | 	mov #120, r3 ! r3 = __NR_clone | ||
| 16 | 	mov r6, r4 ! r4 = flags | ||
| 17 | 	!mov r5, r5 ! r5 = stack | ||
| 18 | 	mov.l @r15, r6 ! r6 = ptid | ||
| 19 | 	mov.l @(8,r15), r7 ! r7 = ctid | ||
| 20 | 	mov.l @(4,r15), r0 ! r0 = tls | ||
| 21 | 	trapa #31 | ||
| 22 | |||
| 23 | 	or r0, r0 | ||
| 24 | 	or r0, r0 | ||
| 25 | 	or r0, r0 | ||
| 26 | 	or r0, r0 | ||
| 27 | 	or r0, r0 | ||
| 28 | |||
| 29 | 	cmp/eq #0, r0 | ||
| 30 | 	bt 1f | ||
| 31 | |||
| 32 | 	! we are the parent, return | ||
| 33 | 	rts | ||
| 34 | 	 nop | ||
| 35 | |||
| 36 | 1:	! we are the child, call fn(arg) | ||
| 37 | 	mov.l 1f, r0 | ||
| 38 | 	mov r1, r5 | ||
| 39 | 	bsrf r0 | ||
| 40 | 	 mov r2, r4 | ||
| 41 | |||
| 42 | 2:	mov #1, r3 ! __NR_exit | ||
| 43 | 	mov r0, r4 | ||
| 44 | 	trapa #31 | ||
| 45 | |||
| 46 | 	or r0, r0 | ||
| 47 | 	or r0, r0 | ||
| 48 | 	or r0, r0 | ||
| 49 | 	or r0, r0 | ||
| 50 | 	or r0, r0 | ||
| 51 | |||
| 52 | .align 2 | ||
| 53 | .hidden __shcall | ||
| 54 | 1:	.long __shcall@PCREL+(.-2b) | ||
lib/libc/wasi/libc-top-half/musl/src/thread/sh/syscall_cp.s created+45| ... | @@ -0,0 +1,45 @@ | ||
| 1 | .text | ||
| 2 | .global __cp_begin | ||
| 3 | .hidden __cp_begin | ||
| 4 | .global __cp_end | ||
| 5 | .hidden __cp_end | ||
| 6 | .global __cp_cancel | ||
| 7 | .hidden __cp_cancel | ||
| 8 | .hidden __cancel | ||
| 9 | .global __syscall_cp_asm | ||
| 10 | .hidden __syscall_cp_asm | ||
| 11 | .type __syscall_cp_asm, @function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | |||
| 14 | __cp_begin: | ||
| 15 | 	mov.l @r4, r4 | ||
| 16 | 	tst r4, r4 | ||
| 17 | 	bf __cp_cancel | ||
| 18 | 	mov r5, r3 | ||
| 19 | 	mov r6, r4 | ||
| 20 | 	mov r7, r5 | ||
| 21 | 	mov.l @r15, r6 | ||
| 22 | 	mov.l @(4,r15), r7 | ||
| 23 | 	mov.l @(8,r15), r0 | ||
| 24 | 	mov.l @(12,r15), r1 | ||
| 25 | 	trapa #31 | ||
| 26 | |||
| 27 | __cp_end: | ||
| 28 | 	! work around hardware bug | ||
| 29 | 	or r0, r0 | ||
| 30 | 	or r0, r0 | ||
| 31 | 	or r0, r0 | ||
| 32 | 	or r0, r0 | ||
| 33 | 	or r0, r0 | ||
| 34 | |||
| 35 | 	rts | ||
| 36 | 	 nop | ||
| 37 | |||
| 38 | __cp_cancel: | ||
| 39 | 	mov.l 2f, r0 | ||
| 40 | 	braf r0 | ||
| 41 | 	 nop | ||
| 42 | 1: | ||
| 43 | |||
| 44 | .align 2 | ||
| 45 | 2:	.long __cancel@PCREL-(1b-.) | ||
lib/libc/wasi/libc-top-half/musl/src/thread/synccall.c created+120| ... | @@ -0,0 +1,120 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <semaphore.h> | ||
| 3 | #include <string.h> | ||
| 4 | |||
| 5 | static void dummy_0(void) | ||
| 6 | { | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(dummy_0, __tl_lock); | ||
| 10 | weak_alias(dummy_0, __tl_unlock); | ||
| 11 | |||
| 12 | static int target_tid; | ||
| 13 | static void (*callback)(void *), *context; | ||
| 14 | static sem_t target_sem, caller_sem; | ||
| 15 | |||
| 16 | static void dummy(void *p) | ||
| 17 | { | ||
| 18 | } | ||
| 19 | |||
| 20 | static void handler(int sig) | ||
| 21 | { | ||
| 22 | 	if (__pthread_self()->tid != target_tid) return; | ||
| 23 | |||
| 24 | 	int old_errno = errno; | ||
| 25 | |||
| 26 | 	/* Inform caller we have received signal and wait for | ||
| 27 | 	 * the caller to let us make the callback. */ | ||
| 28 | 	sem_post(&caller_sem); | ||
| 29 | 	sem_wait(&target_sem); | ||
| 30 | |||
| 31 | 	callback(context); | ||
| 32 | |||
| 33 | 	/* Inform caller we've complered the callback and wait | ||
| 34 | 	 * for the caller to release us to return. */ | ||
| 35 | 	sem_post(&caller_sem); | ||
| 36 | 	sem_wait(&target_sem); | ||
| 37 | |||
| 38 | 	/* Inform caller we are returning and state is destroyable. */ | ||
| 39 | 	sem_post(&caller_sem); | ||
| 40 | |||
| 41 | 	errno = old_errno; | ||
| 42 | } | ||
| 43 | |||
| 44 | void __synccall(void (*func)(void *), void *ctx) | ||
| 45 | { | ||
| 46 | 	sigset_t oldmask; | ||
| 47 | 	int cs, i, r; | ||
| 48 | 	struct sigaction sa = { .sa_flags = SA_RESTART, .sa_handler = handler }; | ||
| 49 | 	pthread_t self = __pthread_self(), td; | ||
| 50 | 	int count = 0; | ||
| 51 | |||
| 52 | 	/* Blocking signals in two steps, first only app-level signals | ||
| 53 | 	 * before taking the lock, then all signals after taking the lock, | ||
| 54 | 	 * is necessary to achieve AS-safety. Blocking them all first would | ||
| 55 | 	 * deadlock if multiple threads called __synccall. Waiting to block | ||
| 56 | 	 * any until after the lock would allow re-entry in the same thread | ||
| 57 | 	 * with the lock already held. */ | ||
| 58 | 	__block_app_sigs(&oldmask); | ||
| 59 | 	__tl_lock(); | ||
| 60 | 	__block_all_sigs(0); | ||
| 61 | 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); | ||
| 62 | |||
| 63 | 	sem_init(&target_sem, 0, 0); | ||
| 64 | 	sem_init(&caller_sem, 0, 0); | ||
| 65 | |||
| 66 | 	if (!libc.threads_minus_1 || __syscall(SYS_gettid) != self->tid) | ||
| 67 | 		goto single_threaded; | ||
| 68 | |||
| 69 | 	callback = func; | ||
| 70 | 	context = ctx; | ||
| 71 | |||
| 72 | 	/* Block even implementation-internal signals, so that nothing | ||
| 73 | 	 * interrupts the SIGSYNCCALL handlers. The main possible source | ||
| 74 | 	 * of trouble is asynchronous cancellation. */ | ||
| 75 | 	memset(&sa.sa_mask, -1, sizeof sa.sa_mask); | ||
| 76 | 	__libc_sigaction(SIGSYNCCALL, &sa, 0); | ||
| 77 | |||
| 78 | |||
| 79 | 	for (td=self->next; td!=self; td=td->next) { | ||
| 80 | 		target_tid = td->tid; | ||
| 81 | 		while ((r = -__syscall(SYS_tkill, td->tid, SIGSYNCCALL)) == EAGAIN); | ||
| 82 | 		if (r) { | ||
| 83 | 			/* If we failed to signal any thread, nop out the | ||
| 84 | 			 * callback to abort the synccall and just release | ||
| 85 | 			 * any threads already caught. */ | ||
| 86 | 			callback = func = dummy; | ||
| 87 | 			break; | ||
| 88 | 		} | ||
| 89 | 		sem_wait(&caller_sem); | ||
| 90 | 		count++; | ||
| 91 | 	} | ||
| 92 | 	target_tid = 0; | ||
| 93 | |||
| 94 | 	/* Serialize execution of callback in caught threads, or just | ||
| 95 | 	 * release them all if synccall is being aborted. */ | ||
| 96 | 	for (i=0; i<count; i++) { | ||
| 97 | 		sem_post(&target_sem); | ||
| 98 | 		sem_wait(&caller_sem); | ||
| 99 | 	} | ||
| 100 | |||
| 101 | 	sa.sa_handler = SIG_IGN; | ||
| 102 | 	__libc_sigaction(SIGSYNCCALL, &sa, 0); | ||
| 103 | |||
| 104 | single_threaded: | ||
| 105 | 	func(ctx); | ||
| 106 | |||
| 107 | 	/* Only release the caught threads once all threads, including the | ||
| 108 | 	 * caller, have returned from the callback function. */ | ||
| 109 | 	for (i=0; i<count; i++) | ||
| 110 | 		sem_post(&target_sem); | ||
| 111 | 	for (i=0; i<count; i++) | ||
| 112 | 		sem_wait(&caller_sem); | ||
| 113 | |||
| 114 | 	sem_destroy(&caller_sem); | ||
| 115 | 	sem_destroy(&target_sem); | ||
| 116 | |||
| 117 | 	pthread_setcancelstate(cs, 0); | ||
| 118 | 	__tl_unlock(); | ||
| 119 | 	__restore_sigs(&oldmask); | ||
| 120 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/syscall_cp.c createdlib/libc/wasi/libc-top-half/musl/src/thread/thrd_create.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | int thrd_create(thrd_t *thr, thrd_start_t func, void *arg) | ||
| 5 | { | ||
| 6 | 	int ret = __pthread_create(thr, __ATTRP_C11_THREAD, (void *(*)(void *))func, arg); | ||
| 7 | 	switch (ret) { | ||
| 8 | 	case 0: return thrd_success; | ||
| 9 | 	case EAGAIN: return thrd_nomem; | ||
| 10 | 	default: return thrd_error; | ||
| 11 | 	} | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_exit.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | |||
| 5 | _Noreturn void thrd_exit(int result) | ||
| 6 | { | ||
| 7 | 	__pthread_exit((void*)(intptr_t)result); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_join.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <stdint.h> | ||
| 2 | #include <threads.h> | ||
| 3 | #include <pthread.h> | ||
| 4 | |||
| 5 | int thrd_join(thrd_t t, int *res) | ||
| 6 | { | ||
| 7 | void *pthread_res; | ||
| 8 | __pthread_join(t, &pthread_res); | ||
| 9 | if (res) *res = (int)(intptr_t)pthread_res; | ||
| 10 | return thrd_success; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_sleep.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <time.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int thrd_sleep(const struct timespec *req, struct timespec *rem) | ||
| 7 | { | ||
| 8 | 	int ret = -__clock_nanosleep(CLOCK_REALTIME, 0, req, rem); | ||
| 9 | 	switch (ret) { | ||
| 10 | 	case 0: return 0; | ||
| 11 | 	case -EINTR: return -1; /* value specified by C11 */ | ||
| 12 | 	default: return -2; | ||
| 13 | 	} | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/thrd_yield.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | void thrd_yield() | ||
| 5 | { | ||
| 6 | 	__syscall(SYS_sched_yield); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/tls.c createdlib/libc/wasi/libc-top-half/musl/src/thread/tss_create.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | int tss_create(tss_t *tss, tss_dtor_t dtor) | ||
| 5 | { | ||
| 6 | 	/* Different error returns are possible. C glues them together into | ||
| 7 | 	 * just failure notification. Can't be optimized to a tail call, | ||
| 8 | 	 * unless thrd_error equals EAGAIN. */ | ||
| 9 | 	return __pthread_key_create(tss, dtor) ? thrd_error : thrd_success; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/tss_delete.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <threads.h> | ||
| 2 | #include <pthread.h> | ||
| 3 | |||
| 4 | void tss_delete(tss_t key) | ||
| 5 | { | ||
| 6 | 	__pthread_key_delete(key); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/tss_set.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include <threads.h> | ||
| 3 | |||
| 4 | int tss_set(tss_t k, void *x) | ||
| 5 | { | ||
| 6 | 	struct pthread *self = __pthread_self(); | ||
| 7 | 	/* Avoid unnecessary COW */ | ||
| 8 | 	if (self->tsd[k] != x) { | ||
| 9 | 		self->tsd[k] = x; | ||
| 10 | 		self->tsd_used = 1; | ||
| 11 | 	} | ||
| 12 | 	return thrd_success; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/vmlock.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include "pthread_impl.h" | ||
| 2 | #include "fork_impl.h" | ||
| 3 | |||
| 4 | static volatile int vmlock[2]; | ||
| 5 | volatile int *const __vmlock_lockptr = vmlock; | ||
| 6 | |||
| 7 | void __vm_wait() | ||
| 8 | { | ||
| 9 | 	int tmp; | ||
| 10 | 	while ((tmp=vmlock[0])) | ||
| 11 | 		__wait(vmlock, vmlock+1, tmp, 1); | ||
| 12 | } | ||
| 13 | |||
| 14 | void __vm_lock() | ||
| 15 | { | ||
| 16 | 	a_inc(vmlock); | ||
| 17 | } | ||
| 18 | |||
| 19 | void __vm_unlock() | ||
| 20 | { | ||
| 21 | 	if (a_fetch_add(vmlock, -1)==1 && vmlock[1]) | ||
| 22 | 		__wake(vmlock, -1, 1); | ||
| 23 | } | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x32/__set_thread_area.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .text | ||
| 3 | .global __set_thread_area | ||
| 4 | .hidden __set_thread_area | ||
| 5 | .type __set_thread_area,@function | ||
| 6 | __set_thread_area: | ||
| 7 | 	mov %edi,%esi /* shift for syscall */ | ||
| 8 | 	movl $0x1002,%edi /* SET_FS register */ | ||
| 9 | 	movl $0x4000009e,%eax /* set fs segment to */ | ||
| 10 | 	syscall /* arch_prctl(SET_FS, arg)*/ | ||
| 11 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x32/__unmapself.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .text | ||
| 3 | .global __unmapself | ||
| 4 | .type __unmapself,@function | ||
| 5 | __unmapself: | ||
| 6 | 	movl $0x4000000b,%eax /* SYS_munmap */ | ||
| 7 | 	syscall /* munmap(arg2,arg3) */ | ||
| 8 | 	xor %rdi,%rdi /* exit() args: always return success */ | ||
| 9 | 	movl $0x4000003c,%eax /* SYS_exit */ | ||
| 10 | 	syscall /* exit(0) */ | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x32/clone.s created+26| ... | @@ -0,0 +1,26 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone,@function | ||
| 5 | __clone: | ||
| 6 | 	movl $0x40000038,%eax /* SYS_clone */ | ||
| 7 | 	mov %rdi,%r11 | ||
| 8 | 	mov %rdx,%rdi | ||
| 9 | 	mov %r8,%rdx | ||
| 10 | 	mov %r9,%r8 | ||
| 11 | 	mov 8(%rsp),%r10 | ||
| 12 | 	mov %r11,%r9 | ||
| 13 | 	and $-16,%rsi | ||
| 14 | 	sub $8,%rsi | ||
| 15 | 	mov %rcx,(%rsi) | ||
| 16 | 	syscall | ||
| 17 | 	test %eax,%eax | ||
| 18 | 	jnz 1f | ||
| 19 | 	xor %ebp,%ebp | ||
| 20 | 	pop %rdi | ||
| 21 | 	call *%r9 | ||
| 22 | 	mov %eax,%edi | ||
| 23 | 	movl $0x4000003c,%eax /* SYS_exit */ | ||
| 24 | 	syscall | ||
| 25 | 	hlt | ||
| 26 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x32/syscall_cp.s created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | .text | ||
| 2 | .global __cp_begin | ||
| 3 | .hidden __cp_begin | ||
| 4 | .global __cp_end | ||
| 5 | .hidden __cp_end | ||
| 6 | .global __cp_cancel | ||
| 7 | .hidden __cp_cancel | ||
| 8 | .hidden __cancel | ||
| 9 | .global __syscall_cp_asm | ||
| 10 | .hidden __syscall_cp_asm | ||
| 11 | .type __syscall_cp_asm,@function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | |||
| 14 | __cp_begin: | ||
| 15 | 	mov (%rdi),%eax | ||
| 16 | 	test %eax,%eax | ||
| 17 | 	jnz __cp_cancel | ||
| 18 | 	mov %rdi,%r11 | ||
| 19 | 	mov %rsi,%rax | ||
| 20 | 	mov %rdx,%rdi | ||
| 21 | 	mov %rcx,%rsi | ||
| 22 | 	mov %r8,%rdx | ||
| 23 | 	mov %r9,%r10 | ||
| 24 | 	mov 8(%rsp),%r8 | ||
| 25 | 	mov 16(%rsp),%r9 | ||
| 26 | 	mov %r11,8(%rsp) | ||
| 27 | 	syscall | ||
| 28 | __cp_end: | ||
| 29 | 	ret | ||
| 30 | __cp_cancel: | ||
| 31 | 	jmp __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/__set_thread_area.s created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .text | ||
| 3 | .global __set_thread_area | ||
| 4 | .hidden __set_thread_area | ||
| 5 | .type __set_thread_area,@function | ||
| 6 | __set_thread_area: | ||
| 7 | 	mov %rdi,%rsi /* shift for syscall */ | ||
| 8 | 	movl $0x1002,%edi /* SET_FS register */ | ||
| 9 | 	movl $158,%eax /* set fs segment to */ | ||
| 10 | 	syscall /* arch_prctl(SET_FS, arg)*/ | ||
| 11 | 	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/__unmapself.s created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | /* Copyright 2011-2012 Nicholas J. Kain, licensed under standard MIT license */ | ||
| 2 | .text | ||
| 3 | .global __unmapself | ||
| 4 | .type __unmapself,@function | ||
| 5 | __unmapself: | ||
| 6 | 	movl $11,%eax /* SYS_munmap */ | ||
| 7 | 	syscall /* munmap(arg2,arg3) */ | ||
| 8 | 	xor %rdi,%rdi /* exit() args: always return success */ | ||
| 9 | 	movl $60,%eax /* SYS_exit */ | ||
| 10 | 	syscall /* exit(0) */ | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/clone.s created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | .text | ||
| 2 | .global __clone | ||
| 3 | .hidden __clone | ||
| 4 | .type __clone,@function | ||
| 5 | __clone: | ||
| 6 | 	xor %eax,%eax | ||
| 7 | 	mov $56,%al | ||
| 8 | 	mov %rdi,%r11 | ||
| 9 | 	mov %rdx,%rdi | ||
| 10 | 	mov %r8,%rdx | ||
| 11 | 	mov %r9,%r8 | ||
| 12 | 	mov 8(%rsp),%r10 | ||
| 13 | 	mov %r11,%r9 | ||
| 14 | 	and $-16,%rsi | ||
| 15 | 	sub $8,%rsi | ||
| 16 | 	mov %rcx,(%rsi) | ||
| 17 | 	syscall | ||
| 18 | 	test %eax,%eax | ||
| 19 | 	jnz 1f | ||
| 20 | 	xor %ebp,%ebp | ||
| 21 | 	pop %rdi | ||
| 22 | 	call *%r9 | ||
| 23 | 	mov %eax,%edi | ||
| 24 | 	xor %eax,%eax | ||
| 25 | 	mov $60,%al | ||
| 26 | 	syscall | ||
| 27 | 	hlt | ||
| 28 | 1:	ret | ||
lib/libc/wasi/libc-top-half/musl/src/thread/x86_64/syscall_cp.s created+31| ... | @@ -0,0 +1,31 @@ | ||
| 1 | .text | ||
| 2 | .global __cp_begin | ||
| 3 | .hidden __cp_begin | ||
| 4 | .global __cp_end | ||
| 5 | .hidden __cp_end | ||
| 6 | .global __cp_cancel | ||
| 7 | .hidden __cp_cancel | ||
| 8 | .hidden __cancel | ||
| 9 | .global __syscall_cp_asm | ||
| 10 | .hidden __syscall_cp_asm | ||
| 11 | .type __syscall_cp_asm,@function | ||
| 12 | __syscall_cp_asm: | ||
| 13 | |||
| 14 | __cp_begin: | ||
| 15 | 	mov (%rdi),%eax | ||
| 16 | 	test %eax,%eax | ||
| 17 | 	jnz __cp_cancel | ||
| 18 | 	mov %rdi,%r11 | ||
| 19 | 	mov %rsi,%rax | ||
| 20 | 	mov %rdx,%rdi | ||
| 21 | 	mov %rcx,%rsi | ||
| 22 | 	mov %r8,%rdx | ||
| 23 | 	mov %r9,%r10 | ||
| 24 | 	mov 8(%rsp),%r8 | ||
| 25 | 	mov 16(%rsp),%r9 | ||
| 26 | 	mov %r11,8(%rsp) | ||
| 27 | 	syscall | ||
| 28 | __cp_end: | ||
| 29 | 	ret | ||
| 30 | __cp_cancel: | ||
| 31 | 	jmp __cancel | ||
lib/libc/wasi/libc-top-half/musl/src/time/__map_file.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <sys/mman.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <sys/stat.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "kstat.h" | ||
| 6 | |||
| 7 | const char unsigned *__map_file(const char *pathname, size_t *size) | ||
| 8 | { | ||
| 9 | 	struct kstat st; | ||
| 10 | 	const unsigned char *map = MAP_FAILED; | ||
| 11 | 	int fd = sys_open(pathname, O_RDONLY|O_CLOEXEC|O_NONBLOCK); | ||
| 12 | 	if (fd < 0) return 0; | ||
| 13 | 	if (!syscall(SYS_fstat, fd, &st)) { | ||
| 14 | 		map = __mmap(0, st.st_size, PROT_READ, MAP_SHARED, fd, 0); | ||
| 15 | 		*size = st.st_size; | ||
| 16 | 	} | ||
| 17 | 	__syscall(SYS_close, fd); | ||
| 18 | 	return map == MAP_FAILED ? 0 : map; | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/__month_to_secs.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | int __month_to_secs(int month, int is_leap) | ||
| 2 | { | ||
| 3 | 	static const int secs_through_month[] = { | ||
| 4 | 		0, 31*86400, 59*86400, 90*86400, | ||
| 5 | 		120*86400, 151*86400, 181*86400, 212*86400, | ||
| 6 | 		243*86400, 273*86400, 304*86400, 334*86400 }; | ||
| 7 | 	int t = secs_through_month[month]; | ||
| 8 | 	if (is_leap && month >= 2) t+=86400; | ||
| 9 | 	return t; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/__secs_to_tm.c created+82| ... | @@ -0,0 +1,82 @@ | ||
| 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 created+24| ... | @@ -0,0 +1,24 @@ | ||
| 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 created+446| ... | @@ -0,0 +1,446 @@ | ||
| 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 | #endif | ||
| 9 | #include "libc.h" | ||
| 10 | #include "lock.h" | ||
| 11 | #include "fork_impl.h" | ||
| 12 | |||
| 13 | #define malloc __libc_malloc | ||
| 14 | #define calloc undef | ||
| 15 | #define realloc undef | ||
| 16 | #define free undef | ||
| 17 | |||
| 18 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 19 | long __timezone = 0; | ||
| 20 | int __daylight = 0; | ||
| 21 | char *__tzname[2] = { 0, 0 }; | ||
| 22 | |||
| 23 | weak_alias(__timezone, timezone); | ||
| 24 | weak_alias(__daylight, daylight); | ||
| 25 | weak_alias(__tzname, tzname); | ||
| 26 | |||
| 27 | static char std_name[TZNAME_MAX+1]; | ||
| 28 | static char dst_name[TZNAME_MAX+1]; | ||
| 29 | #endif | ||
| 30 | const char __utc[] = "UTC"; | ||
| 31 | |||
| 32 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 33 | static int dst_off; | ||
| 34 | static int r0[5], r1[5]; | ||
| 35 | |||
| 36 | static const unsigned char *zi, *trans, *index, *types, *abbrevs, *abbrevs_end; | ||
| 37 | static size_t map_size; | ||
| 38 | |||
| 39 | static char old_tz_buf[32]; | ||
| 40 | static char *old_tz = old_tz_buf; | ||
| 41 | static size_t old_tz_size = sizeof old_tz_buf; | ||
| 42 | |||
| 43 | static volatile int lock[1]; | ||
| 44 | volatile int *const __timezone_lockptr = lock; | ||
| 45 | |||
| 46 | static int getint(const char **p) | ||
| 47 | { | ||
| 48 | 	unsigned x; | ||
| 49 | 	for (x=0; **p-'0'<10U; (*p)++) x = **p-'0' + 10*x; | ||
| 50 | 	return x; | ||
| 51 | } | ||
| 52 | |||
| 53 | static int getoff(const char **p) | ||
| 54 | { | ||
| 55 | 	int neg = 0; | ||
| 56 | 	if (**p == '-') { | ||
| 57 | 		++*p; | ||
| 58 | 		neg = 1; | ||
| 59 | 	} else if (**p == '+') { | ||
| 60 | 		++*p; | ||
| 61 | 	} | ||
| 62 | 	int off = 3600*getint(p); | ||
| 63 | 	if (**p == ':') { | ||
| 64 | 		++*p; | ||
| 65 | 		off += 60*getint(p); | ||
| 66 | 		if (**p == ':') { | ||
| 67 | 			++*p; | ||
| 68 | 			off += getint(p); | ||
| 69 | 		} | ||
| 70 | 	} | ||
| 71 | 	return neg ? -off : off; | ||
| 72 | } | ||
| 73 | |||
| 74 | static void getrule(const char **p, int rule[5]) | ||
| 75 | { | ||
| 76 | 	int r = rule[0] = **p; | ||
| 77 | |||
| 78 | 	if (r!='M') { | ||
| 79 | 		if (r=='J') ++*p; | ||
| 80 | 		else rule[0] = 0; | ||
| 81 | 		rule[1] = getint(p); | ||
| 82 | 	} else { | ||
| 83 | 		++*p; rule[1] = getint(p); | ||
| 84 | 		++*p; rule[2] = getint(p); | ||
| 85 | 		++*p; rule[3] = getint(p); | ||
| 86 | 	} | ||
| 87 | |||
| 88 | 	if (**p=='/') { | ||
| 89 | 		++*p; | ||
| 90 | 		rule[4] = getoff(p); | ||
| 91 | 	} else { | ||
| 92 | 		rule[4] = 7200; | ||
| 93 | 	} | ||
| 94 | } | ||
| 95 | |||
| 96 | static void getname(char *d, const char **p) | ||
| 97 | { | ||
| 98 | 	int i; | ||
| 99 | 	if (**p == '<') { | ||
| 100 | 		++*p; | ||
| 101 | 		for (i=0; (*p)[i] && (*p)[i]!='>'; i++) | ||
| 102 | 			if (i<TZNAME_MAX) d[i] = (*p)[i]; | ||
| 103 | 		if ((*p)[i]) ++*p; | ||
| 104 | 	} else { | ||
| 105 | 		for (i=0; ((*p)[i]|32)-'a'<26U; i++) | ||
| 106 | 			if (i<TZNAME_MAX) d[i] = (*p)[i]; | ||
| 107 | 	} | ||
| 108 | 	*p += i; | ||
| 109 | 	d[i<TZNAME_MAX?i:TZNAME_MAX] = 0; | ||
| 110 | } | ||
| 111 | |||
| 112 | #define VEC(...) ((const unsigned char[]){__VA_ARGS__}) | ||
| 113 | |||
| 114 | static uint32_t zi_read32(const unsigned char *z) | ||
| 115 | { | ||
| 116 | 	return (unsigned)z[0]<<24 | z[1]<<16 | z[2]<<8 | z[3]; | ||
| 117 | } | ||
| 118 | |||
| 119 | static size_t zi_dotprod(const unsigned char *z, const unsigned char *v, size_t n) | ||
| 120 | { | ||
| 121 | 	size_t y; | ||
| 122 | 	uint32_t x; | ||
| 123 | 	for (y=0; n; n--, z+=4, v++) { | ||
| 124 | 		x = zi_read32(z); | ||
| 125 | 		y += x * *v; | ||
| 126 | 	} | ||
| 127 | 	return y; | ||
| 128 | } | ||
| 129 | |||
| 130 | static void do_tzset() | ||
| 131 | { | ||
| 132 | 	char buf[NAME_MAX+25], *pathname=buf+24; | ||
| 133 | 	const char *try, *s, *p; | ||
| 134 | 	const unsigned char *map = 0; | ||
| 135 | 	size_t i; | ||
| 136 | 	static const char search[] = | ||
| 137 | 		"/usr/share/zoneinfo/\0/share/zoneinfo/\0/etc/zoneinfo/\0"; | ||
| 138 | |||
| 139 | 	s = getenv("TZ"); | ||
| 140 | 	if (!s) s = "/etc/localtime"; | ||
| 141 | 	if (!*s) s = __utc; | ||
| 142 | |||
| 143 | 	if (old_tz && !strcmp(s, old_tz)) return; | ||
| 144 | |||
| 145 | 	for (i=0; i<5; i++) r0[i] = r1[i] = 0; | ||
| 146 | |||
| 147 | 	if (zi) __munmap((void *)zi, map_size); | ||
| 148 | |||
| 149 | 	/* Cache the old value of TZ to check if it has changed. Avoid | ||
| 150 | 	 * free so as not to pull it into static programs. Growth | ||
| 151 | 	 * strategy makes it so free would have minimal benefit anyway. */ | ||
| 152 | 	i = strlen(s); | ||
| 153 | 	if (i > PATH_MAX+1) s = __utc, i = 3; | ||
| 154 | 	if (i >= old_tz_size) { | ||
| 155 | 		old_tz_size *= 2; | ||
| 156 | 		if (i >= old_tz_size) old_tz_size = i+1; | ||
| 157 | 		if (old_tz_size > PATH_MAX+2) old_tz_size = PATH_MAX+2; | ||
| 158 | 		old_tz = malloc(old_tz_size); | ||
| 159 | 	} | ||
| 160 | 	if (old_tz) memcpy(old_tz, s, i+1); | ||
| 161 | |||
| 162 | 	/* Non-suid can use an absolute tzfile pathname or a relative | ||
| 163 | 	 * pathame beginning with "."; in secure mode, only the | ||
| 164 | 	 * standard path will be searched. */ | ||
| 165 | 	if (*s == ':' || ((p=strchr(s, '/')) && !memchr(s, ',', p-s))) { | ||
| 166 | 		if (*s == ':') s++; | ||
| 167 | 		if (*s == '/' || *s == '.') { | ||
| 168 | 			if (!libc.secure || !strcmp(s, "/etc/localtime")) | ||
| 169 | 				map = __map_file(s, &map_size); | ||
| 170 | 		} else { | ||
| 171 | 			size_t l = strlen(s); | ||
| 172 | 			if (l <= NAME_MAX && !strchr(s, '.')) { | ||
| 173 | 				memcpy(pathname, s, l+1); | ||
| 174 | 				pathname[l] = 0; | ||
| 175 | 				for (try=search; !map && *try; try+=l+1) { | ||
| 176 | 					l = strlen(try); | ||
| 177 | 					memcpy(pathname-l, try, l); | ||
| 178 | 					map = __map_file(pathname-l, &map_size); | ||
| 179 | 				} | ||
| 180 | 			} | ||
| 181 | 		} | ||
| 182 | 		if (!map) s = __utc; | ||
| 183 | 	} | ||
| 184 | 	if (map && (map_size < 44 || memcmp(map, "TZif", 4))) { | ||
| 185 | 		__munmap((void *)map, map_size); | ||
| 186 | 		map = 0; | ||
| 187 | 		s = __utc; | ||
| 188 | 	} | ||
| 189 | |||
| 190 | 	zi = map; | ||
| 191 | 	if (map) { | ||
| 192 | 		int scale = 2; | ||
| 193 | 		if (map[4]!='1') { | ||
| 194 | 			size_t skip = zi_dotprod(zi+20, VEC(1,1,8,5,6,1), 6); | ||
| 195 | 			trans = zi+skip+44+44; | ||
| 196 | 			scale++; | ||
| 197 | 		} else { | ||
| 198 | 			trans = zi+44; | ||
| 199 | 		} | ||
| 200 | 		index = trans + (zi_read32(trans-12) << scale); | ||
| 201 | 		types = index + zi_read32(trans-12); | ||
| 202 | 		abbrevs = types + 6*zi_read32(trans-8); | ||
| 203 | 		abbrevs_end = abbrevs + zi_read32(trans-4); | ||
| 204 | 		if (zi[map_size-1] == '\n') { | ||
| 205 | 			for (s = (const char *)zi+map_size-2; *s!='\n'; s--); | ||
| 206 | 			s++; | ||
| 207 | 		} else { | ||
| 208 | 			const unsigned char *p; | ||
| 209 | 			__tzname[0] = __tzname[1] = 0; | ||
| 210 | 			__daylight = __timezone = dst_off = 0; | ||
| 211 | 			for (p=types; p<abbrevs; p+=6) { | ||
| 212 | 				if (!p[4] && !__tzname[0]) { | ||
| 213 | 					__tzname[0] = (char *)abbrevs + p[5]; | ||
| 214 | 					__timezone = -zi_read32(p); | ||
| 215 | 				} | ||
| 216 | 				if (p[4] && !__tzname[1]) { | ||
| 217 | 					__tzname[1] = (char *)abbrevs + p[5]; | ||
| 218 | 					dst_off = -zi_read32(p); | ||
| 219 | 					__daylight = 1; | ||
| 220 | 				} | ||
| 221 | 			} | ||
| 222 | 			if (!__tzname[0]) __tzname[0] = __tzname[1]; | ||
| 223 | 			if (!__tzname[0]) __tzname[0] = (char *)__utc; | ||
| 224 | 			if (!__daylight) { | ||
| 225 | 				__tzname[1] = __tzname[0]; | ||
| 226 | 				dst_off = __timezone; | ||
| 227 | 			} | ||
| 228 | 			return; | ||
| 229 | 		} | ||
| 230 | 	} | ||
| 231 | |||
| 232 | 	if (!s) s = __utc; | ||
| 233 | 	getname(std_name, &s); | ||
| 234 | 	__tzname[0] = std_name; | ||
| 235 | 	__timezone = getoff(&s); | ||
| 236 | 	getname(dst_name, &s); | ||
| 237 | 	__tzname[1] = dst_name; | ||
| 238 | 	if (dst_name[0]) { | ||
| 239 | 		__daylight = 1; | ||
| 240 | 		if (*s == '+' || *s=='-' || *s-'0'<10U) | ||
| 241 | 			dst_off = getoff(&s); | ||
| 242 | 		else | ||
| 243 | 			dst_off = __timezone - 3600; | ||
| 244 | 	} else { | ||
| 245 | 		__daylight = 0; | ||
| 246 | 		dst_off = __timezone; | ||
| 247 | 	} | ||
| 248 | |||
| 249 | 	if (*s == ',') s++, getrule(&s, r0); | ||
| 250 | 	if (*s == ',') s++, getrule(&s, r1); | ||
| 251 | } | ||
| 252 | |||
| 253 | /* Search zoneinfo rules to find the one that applies to the given time, | ||
| 254 | * and determine alternate opposite-DST-status rule that may be needed. */ | ||
| 255 | |||
| 256 | static size_t scan_trans(long long t, int local, size_t *alt) | ||
| 257 | { | ||
| 258 | 	int scale = 3 - (trans == zi+44); | ||
| 259 | 	uint64_t x; | ||
| 260 | 	int off = 0; | ||
| 261 | |||
| 262 | 	size_t a = 0, n = (index-trans)>>scale, m; | ||
| 263 | |||
| 264 | 	if (!n) { | ||
| 265 | 		if (alt) *alt = 0; | ||
| 266 | 		return 0; | ||
| 267 | 	} | ||
| 268 | |||
| 269 | 	/* Binary search for 'most-recent rule before t'. */ | ||
| 270 | 	while (n > 1) { | ||
| 271 | 		m = a + n/2; | ||
| 272 | 		x = zi_read32(trans + (m<<scale)); | ||
| 273 | 		if (scale == 3) x = x<<32 | zi_read32(trans + (m<<scale) + 4); | ||
| 274 | 		else x = (int32_t)x; | ||
| 275 | 		if (local) off = (int32_t)zi_read32(types + 6 * index[m-1]); | ||
| 276 | 		if (t - off < (int64_t)x) { | ||
| 277 | 			n /= 2; | ||
| 278 | 		} else { | ||
| 279 | 			a = m; | ||
| 280 | 			n -= n/2; | ||
| 281 | 		} | ||
| 282 | 	} | ||
| 283 | |||
| 284 | 	/* First and last entry are special. First means to use lowest-index | ||
| 285 | 	 * non-DST type. Last means to apply POSIX-style rule if available. */ | ||
| 286 | 	n = (index-trans)>>scale; | ||
| 287 | 	if (a == n-1) return -1; | ||
| 288 | 	if (a == 0) { | ||
| 289 | 		x = zi_read32(trans + (a<<scale)); | ||
| 290 | 		if (scale == 3) x = x<<32 | zi_read32(trans + (a<<scale) + 4); | ||
| 291 | 		else x = (int32_t)x; | ||
| 292 | 		if (local) off = (int32_t)zi_read32(types + 6 * index[a-1]); | ||
| 293 | 		if (t - off < (int64_t)x) { | ||
| 294 | 			for (a=0; a<(abbrevs-types)/6; a++) { | ||
| 295 | 				if (types[6*a+4] != types[4]) break; | ||
| 296 | 			} | ||
| 297 | 			if (a == (abbrevs-types)/6) a = 0; | ||
| 298 | 			if (types[6*a+4]) { | ||
| 299 | 				*alt = a; | ||
| 300 | 				return 0; | ||
| 301 | 			} else { | ||
| 302 | 				*alt = 0; | ||
| 303 | 				return a; | ||
| 304 | 			} | ||
| 305 | 		} | ||
| 306 | 	} | ||
| 307 | |||
| 308 | 	/* Try to find a neighboring opposite-DST-status rule. */ | ||
| 309 | 	if (alt) { | ||
| 310 | 		if (a && types[6*index[a-1]+4] != types[6*index[a]+4]) | ||
| 311 | 			*alt = index[a-1]; | ||
| 312 | 		else if (a+1<n && types[6*index[a+1]+4] != types[6*index[a]+4]) | ||
| 313 | 			*alt = index[a+1]; | ||
| 314 | 		else | ||
| 315 | 			*alt = index[a]; | ||
| 316 | 	} | ||
| 317 | |||
| 318 | 	return index[a]; | ||
| 319 | } | ||
| 320 | |||
| 321 | static int days_in_month(int m, int is_leap) | ||
| 322 | { | ||
| 323 | 	if (m==2) return 28+is_leap; | ||
| 324 | 	else return 30+((0xad5>>(m-1))&1); | ||
| 325 | } | ||
| 326 | |||
| 327 | /* Convert a POSIX DST rule plus year to seconds since epoch. */ | ||
| 328 | |||
| 329 | static long long rule_to_secs(const int *rule, int year) | ||
| 330 | { | ||
| 331 | 	int is_leap; | ||
| 332 | 	long long t = __year_to_secs(year, &is_leap); | ||
| 333 | 	int x, m, n, d; | ||
| 334 | 	if (rule[0]!='M') { | ||
| 335 | 		x = rule[1]; | ||
| 336 | 		if (rule[0]=='J' && (x < 60 || !is_leap)) x--; | ||
| 337 | 		t += 86400 * x; | ||
| 338 | 	} else { | ||
| 339 | 		m = rule[1]; | ||
| 340 | 		n = rule[2]; | ||
| 341 | 		d = rule[3]; | ||
| 342 | 		t += __month_to_secs(m-1, is_leap); | ||
| 343 | 		int wday = (int)((t + 4*86400) % (7*86400)) / 86400; | ||
| 344 | 		int days = d - wday; | ||
| 345 | 		if (days < 0) days += 7; | ||
| 346 | 		if (n == 5 && days+28 >= days_in_month(m, is_leap)) n = 4; | ||
| 347 | 		t += 86400 * (days + 7*(n-1)); | ||
| 348 | 	} | ||
| 349 | 	t += rule[4]; | ||
| 350 | 	return t; | ||
| 351 | } | ||
| 352 | |||
| 353 | /* Determine the time zone in effect for a given time in seconds since the | ||
| 354 | * epoch. It can be given in local or universal time. The results will | ||
| 355 | * indicate whether DST is in effect at the queried time, and will give both | ||
| 356 | * the GMT offset for the active zone/DST rule and the opposite DST. This | ||
| 357 | * enables a caller to efficiently adjust for the case where an explicit | ||
| 358 | * DST specification mismatches what would be in effect at the time. */ | ||
| 359 | |||
| 360 | void __secs_to_zone(long long t, int local, int *isdst, long *offset, long *oppoff, const char **zonename) | ||
| 361 | { | ||
| 362 | 	LOCK(lock); | ||
| 363 | |||
| 364 | 	do_tzset(); | ||
| 365 | |||
| 366 | 	if (zi) { | ||
| 367 | 		size_t alt, i = scan_trans(t, local, &alt); | ||
| 368 | 		if (i != -1) { | ||
| 369 | 			*isdst = types[6*i+4]; | ||
| 370 | 			*offset = (int32_t)zi_read32(types+6*i); | ||
| 371 | 			*zonename = (const char *)abbrevs + types[6*i+5]; | ||
| 372 | 			if (oppoff) *oppoff = (int32_t)zi_read32(types+6*alt); | ||
| 373 | 			UNLOCK(lock); | ||
| 374 | 			return; | ||
| 375 | 		} | ||
| 376 | 	} | ||
| 377 | |||
| 378 | 	if (!__daylight) goto std; | ||
| 379 | |||
| 380 | 	/* FIXME: may be broken if DST changes right at year boundary? | ||
| 381 | 	 * Also, this could be more efficient.*/ | ||
| 382 | 	long long y = t / 31556952 + 70; | ||
| 383 | 	while (__year_to_secs(y, 0) > t) y--; | ||
| 384 | 	while (__year_to_secs(y+1, 0) < t) y++; | ||
| 385 | |||
| 386 | 	long long t0 = rule_to_secs(r0, y); | ||
| 387 | 	long long t1 = rule_to_secs(r1, y); | ||
| 388 | |||
| 389 | 	if (!local) { | ||
| 390 | 		t0 += __timezone; | ||
| 391 | 		t1 += dst_off; | ||
| 392 | 	} | ||
| 393 | 	if (t0 < t1) { | ||
| 394 | 		if (t >= t0 && t < t1) goto dst; | ||
| 395 | 		goto std; | ||
| 396 | 	} else { | ||
| 397 | 		if (t >= t1 && t < t0) goto std; | ||
| 398 | 		goto dst; | ||
| 399 | 	} | ||
| 400 | std: | ||
| 401 | 	*isdst = 0; | ||
| 402 | 	*offset = -__timezone; | ||
| 403 | 	if (oppoff) *oppoff = -dst_off; | ||
| 404 | 	*zonename = __tzname[0]; | ||
| 405 | 	UNLOCK(lock); | ||
| 406 | 	return; | ||
| 407 | dst: | ||
| 408 | 	*isdst = 1; | ||
| 409 | 	*offset = -dst_off; | ||
| 410 | 	if (oppoff) *oppoff = -__timezone; | ||
| 411 | 	*zonename = __tzname[1]; | ||
| 412 | 	UNLOCK(lock); | ||
| 413 | } | ||
| 414 | |||
| 415 | static void __tzset() | ||
| 416 | { | ||
| 417 | 	LOCK(lock); | ||
| 418 | 	do_tzset(); | ||
| 419 | 	UNLOCK(lock); | ||
| 420 | } | ||
| 421 | |||
| 422 | weak_alias(__tzset, tzset); | ||
| 423 | #else | ||
| 424 | void __secs_to_zone(long long t, int local, int *isdst, int *offset, long *oppoff, const char **zonename) | ||
| 425 | { | ||
| 426 | 	// Minimalist implementation for now. | ||
| 427 | 	*isdst = 0; | ||
| 428 | 	*offset = 0; | ||
| 429 | 	*oppoff = 0; | ||
| 430 | 	*zonename = __utc; | ||
| 431 | } | ||
| 432 | #endif | ||
| 433 | |||
| 434 | const char *__tm_to_tzname(const struct tm *tm) | ||
| 435 | { | ||
| 436 | 	const void *p = tm->__tm_zone; | ||
| 437 | #ifdef __wasilibc_unmodified_upstream // timezone data | ||
| 438 | 	LOCK(lock); | ||
| 439 | 	do_tzset(); | ||
| 440 | 	if (p != __utc && p != __tzname[0] && p != __tzname[1] && | ||
| 441 | 	 (!zi || (uintptr_t)p-(uintptr_t)abbrevs >= abbrevs_end - abbrevs)) | ||
| 442 | 		p = ""; | ||
| 443 | 	UNLOCK(lock); | ||
| 444 | #endif | ||
| 445 | 	return p; | ||
| 446 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/__year_to_secs.c created+47| ... | @@ -0,0 +1,47 @@ | ||
| 1 | long long __year_to_secs(long long year, int *is_leap) | ||
| 2 | { | ||
| 3 | 	if (year-2ULL <= 136) { | ||
| 4 | 		int y = year; | ||
| 5 | 		int leaps = (y-68)>>2; | ||
| 6 | 		if (!((y-68)&3)) { | ||
| 7 | 			leaps--; | ||
| 8 | 			if (is_leap) *is_leap = 1; | ||
| 9 | 		} else if (is_leap) *is_leap = 0; | ||
| 10 | 		return 31536000*(y-70) + 86400*leaps; | ||
| 11 | 	} | ||
| 12 | |||
| 13 | 	int cycles, centuries, leaps, rem; | ||
| 14 | |||
| 15 | 	if (!is_leap) is_leap = &(int){0}; | ||
| 16 | 	cycles = (year-100) / 400; | ||
| 17 | 	rem = (year-100) % 400; | ||
| 18 | 	if (rem < 0) { | ||
| 19 | 		cycles--; | ||
| 20 | 		rem += 400; | ||
| 21 | 	} | ||
| 22 | 	if (!rem) { | ||
| 23 | 		*is_leap = 1; | ||
| 24 | 		centuries = 0; | ||
| 25 | 		leaps = 0; | ||
| 26 | 	} else { | ||
| 27 | 		if (rem >= 200) { | ||
| 28 | 			if (rem >= 300) centuries = 3, rem -= 300; | ||
| 29 | 			else centuries = 2, rem -= 200; | ||
| 30 | 		} else { | ||
| 31 | 			if (rem >= 100) centuries = 1, rem -= 100; | ||
| 32 | 			else centuries = 0; | ||
| 33 | 		} | ||
| 34 | 		if (!rem) { | ||
| 35 | 			*is_leap = 0; | ||
| 36 | 			leaps = 0; | ||
| 37 | 		} else { | ||
| 38 | 			leaps = rem / 4U; | ||
| 39 | 			rem %= 4U; | ||
| 40 | 			*is_leap = !rem; | ||
| 41 | 		} | ||
| 42 | 	} | ||
| 43 | |||
| 44 | 	leaps += 97*cycles + 24*centuries - *is_leap; | ||
| 45 | |||
| 46 | 	return (year-100) * 31536000LL + leaps * 86400LL + 946684800 + 86400; | ||
| 47 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/asctime.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <time.h> | ||
| 2 | |||
| 3 | char *asctime(const struct tm *tm) | ||
| 4 | { | ||
| 5 | 	static char buf[26]; | ||
| 6 | 	return __asctime_r(tm, buf); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/asctime_r.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <stdio.h> | ||
| 3 | #include <langinfo.h> | ||
| 4 | #include "locale_impl.h" | ||
| 5 | #include "atomic.h" | ||
| 6 | |||
| 7 | char *__asctime_r(const struct tm *restrict tm, char *restrict buf) | ||
| 8 | { | ||
| 9 | 	if (snprintf(buf, 26, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n", | ||
| 10 | 		__nl_langinfo_l(ABDAY_1+tm->tm_wday, C_LOCALE), | ||
| 11 | 		__nl_langinfo_l(ABMON_1+tm->tm_mon, C_LOCALE), | ||
| 12 | 		tm->tm_mday, tm->tm_hour, | ||
| 13 | 		tm->tm_min, tm->tm_sec, | ||
| 14 | 		1900 + tm->tm_year) >= 26) | ||
| 15 | 	{ | ||
| 16 | 		/* ISO C requires us to use the above format string, | ||
| 17 | 		 * even if it will not fit in the buffer. Thus asctime_r | ||
| 18 | 		 * is _supposed_ to crash if the fields in tm are too large. | ||
| 19 | 		 * We follow this behavior and crash "gracefully" to warn | ||
| 20 | 		 * application developers that they may not be so lucky | ||
| 21 | 		 * on other implementations (e.g. stack smashing..). | ||
| 22 | 		 */ | ||
| 23 | 		a_crash(); | ||
| 24 | 	} | ||
| 25 | 	return buf; | ||
| 26 | } | ||
| 27 | |||
| 28 | weak_alias(__asctime_r, asctime_r); | ||
lib/libc/wasi/libc-top-half/musl/src/time/clock.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <limits.h> | ||
| 3 | |||
| 4 | clock_t clock() | ||
| 5 | { | ||
| 6 | 	struct timespec ts; | ||
| 7 | |||
| 8 | 	if (__clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts)) | ||
| 9 | 		return -1; | ||
| 10 | |||
| 11 | 	if (ts.tv_sec > LONG_MAX/1000000 | ||
| 12 | 	 || ts.tv_nsec/1000 > LONG_MAX-1000000*ts.tv_sec) | ||
| 13 | 		return -1; | ||
| 14 | |||
| 15 | 	return ts.tv_sec*1000000 + ts.tv_nsec/1000; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/clock_getcpuclockid.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int clock_getcpuclockid(pid_t pid, clockid_t *clk) | ||
| 7 | { | ||
| 8 | 	struct timespec ts; | ||
| 9 | 	clockid_t id = (-pid-1)*8U + 2; | ||
| 10 | 	int ret = __syscall(SYS_clock_getres, id, &ts); | ||
| 11 | 	if (ret) return -ret; | ||
| 12 | 	*clk = id; | ||
| 13 | 	return 0; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/clock_getres.c created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int clock_getres(clockid_t clk, struct timespec *ts) | ||
| 5 | { | ||
| 6 | #ifdef SYS_clock_getres_time64 | ||
| 7 | 	/* On a 32-bit arch, use the old syscall if it exists. */ | ||
| 8 | 	if (SYS_clock_getres != SYS_clock_getres_time64) { | ||
| 9 | 		long ts32[2]; | ||
| 10 | 		int r = __syscall(SYS_clock_getres, clk, ts32); | ||
| 11 | 		if (!r && ts) { | ||
| 12 | 			ts->tv_sec = ts32[0]; | ||
| 13 | 			ts->tv_nsec = ts32[1]; | ||
| 14 | 		} | ||
| 15 | 		return __syscall_ret(r); | ||
| 16 | 	} | ||
| 17 | #endif | ||
| 18 | 	/* If reaching this point, it's a 64-bit arch or time64-only | ||
| 19 | 	 * 32-bit arch and we can get result directly into timespec. */ | ||
| 20 | 	return syscall(SYS_clock_getres, clk, ts); | ||
| 21 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/clock_gettime.c created+107| ... | @@ -0,0 +1,107 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <stdint.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "atomic.h" | ||
| 6 | |||
| 7 | #ifdef VDSO_CGT_SYM | ||
| 8 | |||
| 9 | static void *volatile vdso_func; | ||
| 10 | |||
| 11 | #ifdef VDSO_CGT32_SYM | ||
| 12 | static void *volatile vdso_func_32; | ||
| 13 | static int cgt_time32_wrap(clockid_t clk, struct timespec *ts) | ||
| 14 | { | ||
| 15 | 	long ts32[2]; | ||
| 16 | 	int (*f)(clockid_t, long[2]) = | ||
| 17 | 		(int (*)(clockid_t, long[2]))vdso_func_32; | ||
| 18 | 	int r = f(clk, ts32); | ||
| 19 | 	if (!r) { | ||
| 20 | 		/* Fallback to syscalls if time32 overflowed. Maybe | ||
| 21 | 		 * we lucked out and somehow migrated to a kernel with | ||
| 22 | 		 * time64 syscalls available. */ | ||
| 23 | 		if (ts32[0] < 0) { | ||
| 24 | 			a_cas_p(&vdso_func, (void *)cgt_time32_wrap, 0); | ||
| 25 | 			return -ENOSYS; | ||
| 26 | 		} | ||
| 27 | 		ts->tv_sec = ts32[0]; | ||
| 28 | 		ts->tv_nsec = ts32[1]; | ||
| 29 | 	} | ||
| 30 | 	return r; | ||
| 31 | } | ||
| 32 | #endif | ||
| 33 | |||
| 34 | static int cgt_init(clockid_t clk, struct timespec *ts) | ||
| 35 | { | ||
| 36 | 	void *p = __vdsosym(VDSO_CGT_VER, VDSO_CGT_SYM); | ||
| 37 | #ifdef VDSO_CGT32_SYM | ||
| 38 | 	if (!p) { | ||
| 39 | 		void *q = __vdsosym(VDSO_CGT32_VER, VDSO_CGT32_SYM); | ||
| 40 | 		if (q) { | ||
| 41 | 			a_cas_p(&vdso_func_32, 0, q); | ||
| 42 | 			p = cgt_time32_wrap; | ||
| 43 | 		} | ||
| 44 | 	} | ||
| 45 | #endif | ||
| 46 | 	int (*f)(clockid_t, struct timespec *) = | ||
| 47 | 		(int (*)(clockid_t, struct timespec *))p; | ||
| 48 | 	a_cas_p(&vdso_func, (void *)cgt_init, p); | ||
| 49 | 	return f ? f(clk, ts) : -ENOSYS; | ||
| 50 | } | ||
| 51 | |||
| 52 | static void *volatile vdso_func = (void *)cgt_init; | ||
| 53 | |||
| 54 | #endif | ||
| 55 | |||
| 56 | int __clock_gettime(clockid_t clk, struct timespec *ts) | ||
| 57 | { | ||
| 58 | 	int r; | ||
| 59 | |||
| 60 | #ifdef VDSO_CGT_SYM | ||
| 61 | 	int (*f)(clockid_t, struct timespec *) = | ||
| 62 | 		(int (*)(clockid_t, struct timespec *))vdso_func; | ||
| 63 | 	if (f) { | ||
| 64 | 		r = f(clk, ts); | ||
| 65 | 		if (!r) return r; | ||
| 66 | 		if (r == -EINVAL) return __syscall_ret(r); | ||
| 67 | 		/* Fall through on errors other than EINVAL. Some buggy | ||
| 68 | 		 * vdso implementations return ENOSYS for clocks they | ||
| 69 | 		 * can't handle, rather than making the syscall. This | ||
| 70 | 		 * also handles the case where cgt_init fails to find | ||
| 71 | 		 * a vdso function to use. */ | ||
| 72 | 	} | ||
| 73 | #endif | ||
| 74 | |||
| 75 | #ifdef SYS_clock_gettime64 | ||
| 76 | 	r = -ENOSYS; | ||
| 77 | 	if (sizeof(time_t) > 4) | ||
| 78 | 		r = __syscall(SYS_clock_gettime64, clk, ts); | ||
| 79 | 	if (SYS_clock_gettime == SYS_clock_gettime64 || r!=-ENOSYS) | ||
| 80 | 		return __syscall_ret(r); | ||
| 81 | 	long ts32[2]; | ||
| 82 | 	r = __syscall(SYS_clock_gettime, clk, ts32); | ||
| 83 | 	if (r==-ENOSYS && clk==CLOCK_REALTIME) { | ||
| 84 | 		r = __syscall(SYS_gettimeofday, ts32, 0); | ||
| 85 | 		ts32[1] *= 1000; | ||
| 86 | 	} | ||
| 87 | 	if (!r) { | ||
| 88 | 		ts->tv_sec = ts32[0]; | ||
| 89 | 		ts->tv_nsec = ts32[1]; | ||
| 90 | 		return r; | ||
| 91 | 	} | ||
| 92 | 	return __syscall_ret(r); | ||
| 93 | #else | ||
| 94 | 	r = __syscall(SYS_clock_gettime, clk, ts); | ||
| 95 | 	if (r == -ENOSYS) { | ||
| 96 | 		if (clk == CLOCK_REALTIME) { | ||
| 97 | 			__syscall(SYS_gettimeofday, ts, 0); | ||
| 98 | 			ts->tv_nsec = (int)ts->tv_nsec * 1000; | ||
| 99 | 			return 0; | ||
| 100 | 		} | ||
| 101 | 		r = -EINVAL; | ||
| 102 | 	} | ||
| 103 | 	return __syscall_ret(r); | ||
| 104 | #endif | ||
| 105 | } | ||
| 106 | |||
| 107 | weak_alias(__clock_gettime, clock_gettime); | ||
lib/libc/wasi/libc-top-half/musl/src/time/clock_nanosleep.c created+38| ... | @@ -0,0 +1,38 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | #define CLAMP(x) (int)(IS32BIT(x) ? (x) : 0x7fffffffU+((0ULL+(x))>>63)) | ||
| 7 | |||
| 8 | int __clock_nanosleep(clockid_t clk, int flags, const struct timespec *req, struct timespec *rem) | ||
| 9 | { | ||
| 10 | 	if (clk == CLOCK_THREAD_CPUTIME_ID) return EINVAL; | ||
| 11 | #ifdef SYS_clock_nanosleep_time64 | ||
| 12 | 	time_t s = req->tv_sec; | ||
| 13 | 	long ns = req->tv_nsec; | ||
| 14 | 	int r = -ENOSYS; | ||
| 15 | 	if (SYS_clock_nanosleep == SYS_clock_nanosleep_time64 || !IS32BIT(s)) | ||
| 16 | 		r = __syscall_cp(SYS_clock_nanosleep_time64, clk, flags, | ||
| 17 | 			((long long[]){s, ns}), rem); | ||
| 18 | 	if (SYS_clock_nanosleep == SYS_clock_nanosleep_time64 || r!=-ENOSYS) | ||
| 19 | 		return -r; | ||
| 20 | 	long long extra = s - CLAMP(s); | ||
| 21 | 	long ts32[2] = { CLAMP(s), ns }; | ||
| 22 | 	if (clk == CLOCK_REALTIME && !flags) | ||
| 23 | 		r = __syscall_cp(SYS_nanosleep, &ts32, &ts32); | ||
| 24 | 	else | ||
| 25 | 		r = __syscall_cp(SYS_clock_nanosleep, clk, flags, &ts32, &ts32); | ||
| 26 | 	if (r==-EINTR && rem && !(flags & TIMER_ABSTIME)) { | ||
| 27 | 		rem->tv_sec = ts32[0] + extra; | ||
| 28 | 		rem->tv_nsec = ts32[1]; | ||
| 29 | 	} | ||
| 30 | 	return -r; | ||
| 31 | #else | ||
| 32 | 	if (clk == CLOCK_REALTIME && !flags) | ||
| 33 | 		return -__syscall_cp(SYS_nanosleep, req, rem); | ||
| 34 | 	return -__syscall_cp(SYS_clock_nanosleep, clk, flags, req, rem); | ||
| 35 | #endif | ||
| 36 | } | ||
| 37 | |||
| 38 | weak_alias(__clock_nanosleep, clock_nanosleep); | ||
lib/libc/wasi/libc-top-half/musl/src/time/clock_settime.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | |||
| 7 | int clock_settime(clockid_t clk, const struct timespec *ts) | ||
| 8 | { | ||
| 9 | #ifdef SYS_clock_settime64 | ||
| 10 | 	time_t s = ts->tv_sec; | ||
| 11 | 	long ns = ts->tv_nsec; | ||
| 12 | 	int r = -ENOSYS; | ||
| 13 | 	if (SYS_clock_settime == SYS_clock_settime64 || !IS32BIT(s)) | ||
| 14 | 		r = __syscall(SYS_clock_settime64, clk, | ||
| 15 | 			((long long[]){s, ns})); | ||
| 16 | 	if (SYS_clock_settime == SYS_clock_settime64 || r!=-ENOSYS) | ||
| 17 | 		return __syscall_ret(r); | ||
| 18 | 	if (!IS32BIT(s)) | ||
| 19 | 		return __syscall_ret(-ENOTSUP); | ||
| 20 | 	return syscall(SYS_clock_settime, clk, ((long[]){s, ns})); | ||
| 21 | #else | ||
| 22 | 	return syscall(SYS_clock_settime, clk, ts); | ||
| 23 | #endif | ||
| 24 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/ctime.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <time.h> | ||
| 2 | |||
| 3 | char *ctime(const time_t *t) | ||
| 4 | { | ||
| 5 | 	struct tm *tm = localtime(t); | ||
| 6 | 	if (!tm) return 0; | ||
| 7 | 	return asctime(tm); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/ctime_r.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <time.h> | ||
| 2 | |||
| 3 | char *ctime_r(const time_t *t, char *buf) | ||
| 4 | { | ||
| 5 | 	struct tm tm, *tm_p = localtime_r(t, &tm); | ||
| 6 | 	return tm_p ? asctime_r(tm_p, buf) : 0; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/difftime.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <time.h> | ||
| 2 | |||
| 3 | double difftime(time_t t1, time_t t0) | ||
| 4 | { | ||
| 5 | 	return t1-t0; | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/ftime.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <sys/timeb.h> | ||
| 2 | #include <time.h> | ||
| 3 | |||
| 4 | int ftime(struct timeb *tp) | ||
| 5 | { | ||
| 6 | 	struct timespec ts; | ||
| 7 | 	clock_gettime(CLOCK_REALTIME, &ts); | ||
| 8 | 	tp->time = ts.tv_sec; | ||
| 9 | 	tp->millitm = ts.tv_nsec / 1000000; | ||
| 10 | 	tp->timezone = tp->dstflag = 0; | ||
| 11 | 	return 0; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/getdate.c created+52| ... | @@ -0,0 +1,52 @@ | ||
| 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/gettimeofday.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int gettimeofday(struct timeval *restrict tv, void *restrict tz) | ||
| 6 | { | ||
| 7 | 	struct timespec ts; | ||
| 8 | 	if (!tv) return 0; | ||
| 9 | 	clock_gettime(CLOCK_REALTIME, &ts); | ||
| 10 | 	tv->tv_sec = ts.tv_sec; | ||
| 11 | 	tv->tv_usec = (int)ts.tv_nsec / 1000; | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/gmtime.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 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 created+16| ... | @@ -0,0 +1,16 @@ | ||
| 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 created+7| ... | @@ -0,0 +1,7 @@ | ||
| 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 created+21| ... | @@ -0,0 +1,21 @@ | ||
| 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 created+28| ... | @@ -0,0 +1,28 @@ | ||
| 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/nanosleep.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int nanosleep(const struct timespec *req, struct timespec *rem) | ||
| 5 | { | ||
| 6 | 	return __syscall_ret(-__clock_nanosleep(CLOCK_REALTIME, 0, req, rem)); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/strftime.c created+285| ... | @@ -0,0 +1,285 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | #include <string.h> | ||
| 4 | #include <langinfo.h> | ||
| 5 | #include <locale.h> | ||
| 6 | #include <time.h> | ||
| 7 | #include <limits.h> | ||
| 8 | #include "locale_impl.h" | ||
| 9 | #include "time_impl.h" | ||
| 10 | |||
| 11 | static int is_leap(int y) | ||
| 12 | { | ||
| 13 | 	/* Avoid overflow */ | ||
| 14 | 	if (y>INT_MAX-1900) y -= 2000; | ||
| 15 | 	y += 1900; | ||
| 16 | 	return !(y%4) && ((y%100) || !(y%400)); | ||
| 17 | } | ||
| 18 | |||
| 19 | static int week_num(const struct tm *tm) | ||
| 20 | { | ||
| 21 | 	int val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; | ||
| 22 | 	/* If 1 Jan is just 1-3 days past Monday, | ||
| 23 | 	 * the previous week is also in this year. */ | ||
| 24 | 	if ((tm->tm_wday + 371U - tm->tm_yday - 2) % 7 <= 2) | ||
| 25 | 		val++; | ||
| 26 | 	if (!val) { | ||
| 27 | 		val = 52; | ||
| 28 | 		/* If 31 December of prev year a Thursday, | ||
| 29 | 		 * or Friday of a leap year, then the | ||
| 30 | 		 * prev year has 53 weeks. */ | ||
| 31 | 		int dec31 = (tm->tm_wday + 7U - tm->tm_yday - 1) % 7; | ||
| 32 | 		if (dec31 == 4 || (dec31 == 5 && is_leap(tm->tm_year%400-1))) | ||
| 33 | 			val++; | ||
| 34 | 	} else if (val == 53) { | ||
| 35 | 		/* If 1 January is not a Thursday, and not | ||
| 36 | 		 * a Wednesday of a leap year, then this | ||
| 37 | 		 * year has only 52 weeks. */ | ||
| 38 | 		int jan1 = (tm->tm_wday + 371U - tm->tm_yday) % 7; | ||
| 39 | 		if (jan1 != 4 && (jan1 != 3 || !is_leap(tm->tm_year))) | ||
| 40 | 			val = 1; | ||
| 41 | 	} | ||
| 42 | 	return val; | ||
| 43 | } | ||
| 44 | |||
| 45 | const char *__strftime_fmt_1(char (*s)[100], size_t *l, int f, const struct tm *tm, locale_t loc, int pad) | ||
| 46 | { | ||
| 47 | 	nl_item item; | ||
| 48 | 	long long val; | ||
| 49 | 	const char *fmt = "-"; | ||
| 50 | 	int width = 2, def_pad = '0'; | ||
| 51 | |||
| 52 | 	switch (f) { | ||
| 53 | 	case 'a': | ||
| 54 | 		if (tm->tm_wday > 6U) goto string; | ||
| 55 | 		item = ABDAY_1 + tm->tm_wday; | ||
| 56 | 		goto nl_strcat; | ||
| 57 | 	case 'A': | ||
| 58 | 		if (tm->tm_wday > 6U) goto string; | ||
| 59 | 		item = DAY_1 + tm->tm_wday; | ||
| 60 | 		goto nl_strcat; | ||
| 61 | 	case 'h': | ||
| 62 | 	case 'b': | ||
| 63 | 		if (tm->tm_mon > 11U) goto string; | ||
| 64 | 		item = ABMON_1 + tm->tm_mon; | ||
| 65 | 		goto nl_strcat; | ||
| 66 | 	case 'B': | ||
| 67 | 		if (tm->tm_mon > 11U) goto string; | ||
| 68 | 		item = MON_1 + tm->tm_mon; | ||
| 69 | 		goto nl_strcat; | ||
| 70 | 	case 'c': | ||
| 71 | 		item = D_T_FMT; | ||
| 72 | 		goto nl_strftime; | ||
| 73 | 	case 'C': | ||
| 74 | 		val = (1900LL+tm->tm_year) / 100; | ||
| 75 | 		goto number; | ||
| 76 | 	case 'e': | ||
| 77 | 		def_pad = '_'; | ||
| 78 | 	case 'd': | ||
| 79 | 		val = tm->tm_mday; | ||
| 80 | 		goto number; | ||
| 81 | 	case 'D': | ||
| 82 | 		fmt = "%m/%d/%y"; | ||
| 83 | 		goto recu_strftime; | ||
| 84 | 	case 'F': | ||
| 85 | 		fmt = "%Y-%m-%d"; | ||
| 86 | 		goto recu_strftime; | ||
| 87 | 	case 'g': | ||
| 88 | 	case 'G': | ||
| 89 | 		val = tm->tm_year + 1900LL; | ||
| 90 | 		if (tm->tm_yday < 3 && week_num(tm) != 1) val--; | ||
| 91 | 		else if (tm->tm_yday > 360 && week_num(tm) == 1) val++; | ||
| 92 | 		if (f=='g') val %= 100; | ||
| 93 | 		else width = 4; | ||
| 94 | 		goto number; | ||
| 95 | 	case 'H': | ||
| 96 | 		val = tm->tm_hour; | ||
| 97 | 		goto number; | ||
| 98 | 	case 'I': | ||
| 99 | 		val = tm->tm_hour; | ||
| 100 | 		if (!val) val = 12; | ||
| 101 | 		else if (val > 12) val -= 12; | ||
| 102 | 		goto number; | ||
| 103 | 	case 'j': | ||
| 104 | 		val = tm->tm_yday+1; | ||
| 105 | 		width = 3; | ||
| 106 | 		goto number; | ||
| 107 | 	case 'm': | ||
| 108 | 		val = tm->tm_mon+1; | ||
| 109 | 		goto number; | ||
| 110 | 	case 'M': | ||
| 111 | 		val = tm->tm_min; | ||
| 112 | 		goto number; | ||
| 113 | 	case 'n': | ||
| 114 | 		*l = 1; | ||
| 115 | 		return "\n"; | ||
| 116 | 	case 'p': | ||
| 117 | 		item = tm->tm_hour >= 12 ? PM_STR : AM_STR; | ||
| 118 | 		goto nl_strcat; | ||
| 119 | 	case 'r': | ||
| 120 | 		item = T_FMT_AMPM; | ||
| 121 | 		goto nl_strftime; | ||
| 122 | 	case 'R': | ||
| 123 | 		fmt = "%H:%M"; | ||
| 124 | 		goto recu_strftime; | ||
| 125 | 	case 's': | ||
| 126 | 		val = __tm_to_secs(tm) - tm->__tm_gmtoff; | ||
| 127 | 		width = 1; | ||
| 128 | 		goto number; | ||
| 129 | 	case 'S': | ||
| 130 | 		val = tm->tm_sec; | ||
| 131 | 		goto number; | ||
| 132 | 	case 't': | ||
| 133 | 		*l = 1; | ||
| 134 | 		return "\t"; | ||
| 135 | 	case 'T': | ||
| 136 | 		fmt = "%H:%M:%S"; | ||
| 137 | 		goto recu_strftime; | ||
| 138 | 	case 'u': | ||
| 139 | 		val = tm->tm_wday ? tm->tm_wday : 7; | ||
| 140 | 		width = 1; | ||
| 141 | 		goto number; | ||
| 142 | 	case 'U': | ||
| 143 | 		val = (tm->tm_yday + 7U - tm->tm_wday) / 7; | ||
| 144 | 		goto number; | ||
| 145 | 	case 'W': | ||
| 146 | 		val = (tm->tm_yday + 7U - (tm->tm_wday+6U)%7) / 7; | ||
| 147 | 		goto number; | ||
| 148 | 	case 'V': | ||
| 149 | 		val = week_num(tm); | ||
| 150 | 		goto number; | ||
| 151 | 	case 'w': | ||
| 152 | 		val = tm->tm_wday; | ||
| 153 | 		width = 1; | ||
| 154 | 		goto number; | ||
| 155 | 	case 'x': | ||
| 156 | 		item = D_FMT; | ||
| 157 | 		goto nl_strftime; | ||
| 158 | 	case 'X': | ||
| 159 | 		item = T_FMT; | ||
| 160 | 		goto nl_strftime; | ||
| 161 | 	case 'y': | ||
| 162 | 		val = (tm->tm_year + 1900LL) % 100; | ||
| 163 | 		if (val < 0) val = -val; | ||
| 164 | 		goto number; | ||
| 165 | 	case 'Y': | ||
| 166 | 		val = tm->tm_year + 1900LL; | ||
| 167 | 		if (val >= 10000) { | ||
| 168 | 			*l = snprintf(*s, sizeof *s, "+%lld", val); | ||
| 169 | 			return *s; | ||
| 170 | 		} | ||
| 171 | 		width = 4; | ||
| 172 | 		goto number; | ||
| 173 | 	case 'z': | ||
| 174 | 		if (tm->tm_isdst < 0) { | ||
| 175 | 			*l = 0; | ||
| 176 | 			return ""; | ||
| 177 | 		} | ||
| 178 | #ifdef __wasilibc_unmodified_upstream // wasi-libc's __tm_gmtoff is an int | ||
| 179 | 		*l = snprintf(*s, sizeof *s, "%+.4ld", | ||
| 180 | #else | ||
| 181 | 		*l = snprintf(*s, sizeof *s, "%+.4d", | ||
| 182 | #endif | ||
| 183 | 			tm->__tm_gmtoff/3600*100 + tm->__tm_gmtoff%3600/60); | ||
| 184 | 		return *s; | ||
| 185 | 	case 'Z': | ||
| 186 | 		if (tm->tm_isdst < 0) { | ||
| 187 | 			*l = 0; | ||
| 188 | 			return ""; | ||
| 189 | 		} | ||
| 190 | 		fmt = __tm_to_tzname(tm); | ||
| 191 | 		goto string; | ||
| 192 | 	case '%': | ||
| 193 | 		*l = 1; | ||
| 194 | 		return "%"; | ||
| 195 | 	default: | ||
| 196 | 		return 0; | ||
| 197 | 	} | ||
| 198 | number: | ||
| 199 | 	switch (pad ? pad : def_pad) { | ||
| 200 | 	case '-': *l = snprintf(*s, sizeof *s, "%lld", val); break; | ||
| 201 | 	case '_': *l = snprintf(*s, sizeof *s, "%*lld", width, val); break; | ||
| 202 | 	case '0': | ||
| 203 | 	default: *l = snprintf(*s, sizeof *s, "%0*lld", width, val); break; | ||
| 204 | 	} | ||
| 205 | 	return *s; | ||
| 206 | nl_strcat: | ||
| 207 | 	fmt = __nl_langinfo_l(item, loc); | ||
| 208 | string: | ||
| 209 | 	*l = strlen(fmt); | ||
| 210 | 	return fmt; | ||
| 211 | nl_strftime: | ||
| 212 | 	fmt = __nl_langinfo_l(item, loc); | ||
| 213 | recu_strftime: | ||
| 214 | 	*l = __strftime_l(*s, sizeof *s, fmt, tm, loc); | ||
| 215 | 	if (!*l) return 0; | ||
| 216 | 	return *s; | ||
| 217 | } | ||
| 218 | |||
| 219 | size_t __strftime_l(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm, locale_t loc) | ||
| 220 | { | ||
| 221 | 	size_t l, k; | ||
| 222 | 	char buf[100]; | ||
| 223 | 	char *p; | ||
| 224 | 	const char *t; | ||
| 225 | 	int pad, plus; | ||
| 226 | 	unsigned long width; | ||
| 227 | 	for (l=0; l<n; f++) { | ||
| 228 | 		if (!*f) { | ||
| 229 | 			s[l] = 0; | ||
| 230 | 			return l; | ||
| 231 | 		} | ||
| 232 | 		if (*f != '%') { | ||
| 233 | 			s[l++] = *f; | ||
| 234 | 			continue; | ||
| 235 | 		} | ||
| 236 | 		f++; | ||
| 237 | 		pad = 0; | ||
| 238 | 		if (*f == '-' || *f == '_' || *f == '0') pad = *f++; | ||
| 239 | 		if ((plus = (*f == '+'))) f++; | ||
| 240 | 		width = strtoul(f, &p, 10); | ||
| 241 | 		if (*p == 'C' || *p == 'F' || *p == 'G' || *p == 'Y') { | ||
| 242 | 			if (!width && p!=f) width = 1; | ||
| 243 | 		} else { | ||
| 244 | 			width = 0; | ||
| 245 | 		} | ||
| 246 | 		f = p; | ||
| 247 | 		if (*f == 'E' || *f == 'O') f++; | ||
| 248 | 		t = __strftime_fmt_1(&buf, &k, *f, tm, loc, pad); | ||
| 249 | 		if (!t) break; | ||
| 250 | 		if (width) { | ||
| 251 | 			/* Trim off any sign and leading zeros, then | ||
| 252 | 			 * count remaining digits to determine behavior | ||
| 253 | 			 * for the + flag. */ | ||
| 254 | 			if (*t=='+' || *t=='-') t++, k--; | ||
| 255 | 			for (; *t=='0' && t[1]-'0'<10U; t++, k--); | ||
| 256 | 			if (width < k) width = k; | ||
| 257 | 			size_t d; | ||
| 258 | 			for (d=0; t[d]-'0'<10U; d++); | ||
| 259 | 			if (tm->tm_year < -1900) { | ||
| 260 | 				s[l++] = '-'; | ||
| 261 | 				width--; | ||
| 262 | 			} else if (plus && d+(width-k) >= (*p=='C'?3:5)) { | ||
| 263 | 				s[l++] = '+'; | ||
| 264 | 				width--; | ||
| 265 | 			} | ||
| 266 | 			for (; width > k && l < n; width--) | ||
| 267 | 				s[l++] = '0'; | ||
| 268 | 		} | ||
| 269 | 		if (k > n-l) k = n-l; | ||
| 270 | 		memcpy(s+l, t, k); | ||
| 271 | 		l += k; | ||
| 272 | 	} | ||
| 273 | 	if (n) { | ||
| 274 | 		if (l==n) l=n-1; | ||
| 275 | 		s[l] = 0; | ||
| 276 | 	} | ||
| 277 | 	return 0; | ||
| 278 | } | ||
| 279 | |||
| 280 | size_t strftime(char *restrict s, size_t n, const char *restrict f, const struct tm *restrict tm) | ||
| 281 | { | ||
| 282 | 	return __strftime_l(s, n, f, tm, CURRENT_LOCALE); | ||
| 283 | } | ||
| 284 | |||
| 285 | weak_alias(__strftime_l, strftime_l); | ||
lib/libc/wasi/libc-top-half/musl/src/time/strptime.c created+206| ... | @@ -0,0 +1,206 @@ | ||
| 1 | #include <stdlib.h> | ||
| 2 | #include <langinfo.h> | ||
| 3 | #include <time.h> | ||
| 4 | #include <ctype.h> | ||
| 5 | #include <stddef.h> | ||
| 6 | #include <string.h> | ||
| 7 | #include <strings.h> | ||
| 8 | |||
| 9 | char *strptime(const char *restrict s, const char *restrict f, struct tm *restrict tm) | ||
| 10 | { | ||
| 11 | 	int i, w, neg, adj, min, range, *dest, dummy; | ||
| 12 | 	const char *ex; | ||
| 13 | 	size_t len; | ||
| 14 | 	int want_century = 0, century = 0, relyear = 0; | ||
| 15 | 	while (*f) { | ||
| 16 | 		if (*f != '%') { | ||
| 17 | 			if (isspace(*f)) for (; *s && isspace(*s); s++); | ||
| 18 | 			else if (*s != *f) return 0; | ||
| 19 | 			else s++; | ||
| 20 | 			f++; | ||
| 21 | 			continue; | ||
| 22 | 		} | ||
| 23 | 		f++; | ||
| 24 | 		if (*f == '+') f++; | ||
| 25 | 		if (isdigit(*f)) { | ||
| 26 | 			char *new_f; | ||
| 27 | 			w=strtoul(f, &new_f, 10); | ||
| 28 | 			f = new_f; | ||
| 29 | 		} else { | ||
| 30 | 			w=-1; | ||
| 31 | 		} | ||
| 32 | 		adj=0; | ||
| 33 | 		switch (*f++) { | ||
| 34 | 		case 'a': case 'A': | ||
| 35 | 			dest = &tm->tm_wday; | ||
| 36 | 			min = ABDAY_1; | ||
| 37 | 			range = 7; | ||
| 38 | 			goto symbolic_range; | ||
| 39 | 		case 'b': case 'B': case 'h': | ||
| 40 | 			dest = &tm->tm_mon; | ||
| 41 | 			min = ABMON_1; | ||
| 42 | 			range = 12; | ||
| 43 | 			goto symbolic_range; | ||
| 44 | 		case 'c': | ||
| 45 | 			s = strptime(s, nl_langinfo(D_T_FMT), tm); | ||
| 46 | 			if (!s) return 0; | ||
| 47 | 			break; | ||
| 48 | 		case 'C': | ||
| 49 | 			dest = &century; | ||
| 50 | 			if (w<0) w=2; | ||
| 51 | 			want_century |= 2; | ||
| 52 | 			goto numeric_digits; | ||
| 53 | 		case 'd': case 'e': | ||
| 54 | 			dest = &tm->tm_mday; | ||
| 55 | 			min = 1; | ||
| 56 | 			range = 31; | ||
| 57 | 			goto numeric_range; | ||
| 58 | 		case 'D': | ||
| 59 | 			s = strptime(s, "%m/%d/%y", tm); | ||
| 60 | 			if (!s) return 0; | ||
| 61 | 			break; | ||
| 62 | 		case 'H': | ||
| 63 | 			dest = &tm->tm_hour; | ||
| 64 | 			min = 0; | ||
| 65 | 			range = 24; | ||
| 66 | 			goto numeric_range; | ||
| 67 | 		case 'I': | ||
| 68 | 			dest = &tm->tm_hour; | ||
| 69 | 			min = 1; | ||
| 70 | 			range = 12; | ||
| 71 | 			goto numeric_range; | ||
| 72 | 		case 'j': | ||
| 73 | 			dest = &tm->tm_yday; | ||
| 74 | 			min = 1; | ||
| 75 | 			range = 366; | ||
| 76 | 			adj = 1; | ||
| 77 | 			goto numeric_range; | ||
| 78 | 		case 'm': | ||
| 79 | 			dest = &tm->tm_mon; | ||
| 80 | 			min = 1; | ||
| 81 | 			range = 12; | ||
| 82 | 			adj = 1; | ||
| 83 | 			goto numeric_range; | ||
| 84 | 		case 'M': | ||
| 85 | 			dest = &tm->tm_min; | ||
| 86 | 			min = 0; | ||
| 87 | 			range = 60; | ||
| 88 | 			goto numeric_range; | ||
| 89 | 		case 'n': case 't': | ||
| 90 | 			for (; *s && isspace(*s); s++); | ||
| 91 | 			break; | ||
| 92 | 		case 'p': | ||
| 93 | 			ex = nl_langinfo(AM_STR); | ||
| 94 | 			len = strlen(ex); | ||
| 95 | 			if (!strncasecmp(s, ex, len)) { | ||
| 96 | 				tm->tm_hour %= 12; | ||
| 97 | 				s += len; | ||
| 98 | 				break; | ||
| 99 | 			} | ||
| 100 | 			ex = nl_langinfo(PM_STR); | ||
| 101 | 			len = strlen(ex); | ||
| 102 | 			if (!strncasecmp(s, ex, len)) { | ||
| 103 | 				tm->tm_hour %= 12; | ||
| 104 | 				tm->tm_hour += 12; | ||
| 105 | 				s += len; | ||
| 106 | 				break; | ||
| 107 | 			} | ||
| 108 | 			return 0; | ||
| 109 | 		case 'r': | ||
| 110 | 			s = strptime(s, nl_langinfo(T_FMT_AMPM), tm); | ||
| 111 | 			if (!s) return 0; | ||
| 112 | 			break; | ||
| 113 | 		case 'R': | ||
| 114 | 			s = strptime(s, "%H:%M", tm); | ||
| 115 | 			if (!s) return 0; | ||
| 116 | 			break; | ||
| 117 | 		case 'S': | ||
| 118 | 			dest = &tm->tm_sec; | ||
| 119 | 			min = 0; | ||
| 120 | 			range = 61; | ||
| 121 | 			goto numeric_range; | ||
| 122 | 		case 'T': | ||
| 123 | 			s = strptime(s, "%H:%M:%S", tm); | ||
| 124 | 			if (!s) return 0; | ||
| 125 | 			break; | ||
| 126 | 		case 'U': | ||
| 127 | 		case 'W': | ||
| 128 | 			/* Throw away result, for now. (FIXME?) */ | ||
| 129 | 			dest = &dummy; | ||
| 130 | 			min = 0; | ||
| 131 | 			range = 54; | ||
| 132 | 			goto numeric_range; | ||
| 133 | 		case 'w': | ||
| 134 | 			dest = &tm->tm_wday; | ||
| 135 | 			min = 0; | ||
| 136 | 			range = 7; | ||
| 137 | 			goto numeric_range; | ||
| 138 | 		case 'x': | ||
| 139 | 			s = strptime(s, nl_langinfo(D_FMT), tm); | ||
| 140 | 			if (!s) return 0; | ||
| 141 | 			break; | ||
| 142 | 		case 'X': | ||
| 143 | 			s = strptime(s, nl_langinfo(T_FMT), tm); | ||
| 144 | 			if (!s) return 0; | ||
| 145 | 			break; | ||
| 146 | 		case 'y': | ||
| 147 | 			dest = &relyear; | ||
| 148 | 			w = 2; | ||
| 149 | 			want_century |= 1; | ||
| 150 | 			goto numeric_digits; | ||
| 151 | 		case 'Y': | ||
| 152 | 			dest = &tm->tm_year; | ||
| 153 | 			if (w<0) w=4; | ||
| 154 | 			adj = 1900; | ||
| 155 | 			want_century = 0; | ||
| 156 | 			goto numeric_digits; | ||
| 157 | 		case '%': | ||
| 158 | 			if (*s++ != '%') return 0; | ||
| 159 | 			break; | ||
| 160 | 		default: | ||
| 161 | 			return 0; | ||
| 162 | 		numeric_range: | ||
| 163 | 			if (!isdigit(*s)) return 0; | ||
| 164 | 			*dest = 0; | ||
| 165 | 			for (i=1; i<=min+range && isdigit(*s); i*=10) | ||
| 166 | 				*dest = *dest * 10 + *s++ - '0'; | ||
| 167 | 			if (*dest - min >= (unsigned)range) return 0; | ||
| 168 | 			*dest -= adj; | ||
| 169 | 			switch((char *)dest - (char *)tm) { | ||
| 170 | 			case offsetof(struct tm, tm_yday): | ||
| 171 | 				; | ||
| 172 | 			} | ||
| 173 | 			goto update; | ||
| 174 | 		numeric_digits: | ||
| 175 | 			neg = 0; | ||
| 176 | 			if (*s == '+') s++; | ||
| 177 | 			else if (*s == '-') neg=1, s++; | ||
| 178 | 			if (!isdigit(*s)) return 0; | ||
| 179 | 			for (*dest=i=0; i<w && isdigit(*s); i++) | ||
| 180 | 				*dest = *dest * 10 + *s++ - '0'; | ||
| 181 | 			if (neg) *dest = -*dest; | ||
| 182 | 			*dest -= adj; | ||
| 183 | 			goto update; | ||
| 184 | 		symbolic_range: | ||
| 185 | 			for (i=2*range-1; i>=0; i--) { | ||
| 186 | 				ex = nl_langinfo(min+i); | ||
| 187 | 				len = strlen(ex); | ||
| 188 | 				if (strncasecmp(s, ex, len)) continue; | ||
| 189 | 				s += len; | ||
| 190 | 				*dest = i % range; | ||
| 191 | 				break; | ||
| 192 | 			} | ||
| 193 | 			if (i<0) return 0; | ||
| 194 | 			goto update; | ||
| 195 | 		update: | ||
| 196 | 			//FIXME | ||
| 197 | 			; | ||
| 198 | 		} | ||
| 199 | 	} | ||
| 200 | 	if (want_century) { | ||
| 201 | 		tm->tm_year = relyear; | ||
| 202 | 		if (want_century & 2) tm->tm_year += century * 100 - 1900; | ||
| 203 | 		else if (tm->tm_year <= 68) tm->tm_year += 100; | ||
| 204 | 	} | ||
| 205 | 	return (char *)s; | ||
| 206 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/time.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | time_t time(time_t *t) | ||
| 5 | { | ||
| 6 | 	struct timespec ts; | ||
| 7 | 	__clock_gettime(CLOCK_REALTIME, &ts); | ||
| 8 | 	if (t) *t = ts.tv_sec; | ||
| 9 | 	return ts.tv_sec; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/time_impl.h created+15| ... | @@ -0,0 +1,15 @@ | ||
| 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 created+18| ... | @@ -0,0 +1,18 @@ | ||
| 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/timer_create.c created+129| ... | @@ -0,0 +1,129 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <setjmp.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include "pthread_impl.h" | ||
| 5 | #include "atomic.h" | ||
| 6 | |||
| 7 | struct ksigevent { | ||
| 8 | 	union sigval sigev_value; | ||
| 9 | 	int sigev_signo; | ||
| 10 | 	int sigev_notify; | ||
| 11 | 	int sigev_tid; | ||
| 12 | }; | ||
| 13 | |||
| 14 | struct start_args { | ||
| 15 | 	pthread_barrier_t b; | ||
| 16 | 	struct sigevent *sev; | ||
| 17 | }; | ||
| 18 | |||
| 19 | static void dummy_0() | ||
| 20 | { | ||
| 21 | } | ||
| 22 | weak_alias(dummy_0, __pthread_tsd_run_dtors); | ||
| 23 | |||
| 24 | static void cleanup_fromsig(void *p) | ||
| 25 | { | ||
| 26 | 	pthread_t self = __pthread_self(); | ||
| 27 | 	__pthread_tsd_run_dtors(); | ||
| 28 | 	self->cancel = 0; | ||
| 29 | 	self->cancelbuf = 0; | ||
| 30 | 	self->canceldisable = 0; | ||
| 31 | 	self->cancelasync = 0; | ||
| 32 | 	__reset_tls(); | ||
| 33 | 	longjmp(p, 1); | ||
| 34 | } | ||
| 35 | |||
| 36 | static void *start(void *arg) | ||
| 37 | { | ||
| 38 | 	pthread_t self = __pthread_self(); | ||
| 39 | 	struct start_args *args = arg; | ||
| 40 | 	jmp_buf jb; | ||
| 41 | |||
| 42 | 	void (*notify)(union sigval) = args->sev->sigev_notify_function; | ||
| 43 | 	union sigval val = args->sev->sigev_value; | ||
| 44 | |||
| 45 | 	pthread_barrier_wait(&args->b); | ||
| 46 | 	for (;;) { | ||
| 47 | 		siginfo_t si; | ||
| 48 | 		while (sigwaitinfo(SIGTIMER_SET, &si) < 0); | ||
| 49 | 		if (si.si_code == SI_TIMER && !setjmp(jb)) { | ||
| 50 | 			pthread_cleanup_push(cleanup_fromsig, jb); | ||
| 51 | 			notify(val); | ||
| 52 | 			pthread_cleanup_pop(1); | ||
| 53 | 		} | ||
| 54 | 		if (self->timer_id < 0) break; | ||
| 55 | 	} | ||
| 56 | 	__syscall(SYS_timer_delete, self->timer_id & INT_MAX); | ||
| 57 | 	return 0; | ||
| 58 | } | ||
| 59 | |||
| 60 | int timer_create(clockid_t clk, struct sigevent *restrict evp, timer_t *restrict res) | ||
| 61 | { | ||
| 62 | 	volatile static int init = 0; | ||
| 63 | 	pthread_t td; | ||
| 64 | 	pthread_attr_t attr; | ||
| 65 | 	int r; | ||
| 66 | 	struct start_args args; | ||
| 67 | 	struct ksigevent ksev, *ksevp=0; | ||
| 68 | 	int timerid; | ||
| 69 | 	sigset_t set; | ||
| 70 | |||
| 71 | 	switch (evp ? evp->sigev_notify : SIGEV_SIGNAL) { | ||
| 72 | 	case SIGEV_NONE: | ||
| 73 | 	case SIGEV_SIGNAL: | ||
| 74 | 	case SIGEV_THREAD_ID: | ||
| 75 | 		if (evp) { | ||
| 76 | 			ksev.sigev_value = evp->sigev_value; | ||
| 77 | 			ksev.sigev_signo = evp->sigev_signo; | ||
| 78 | 			ksev.sigev_notify = evp->sigev_notify; | ||
| 79 | 			if (evp->sigev_notify == SIGEV_THREAD_ID) | ||
| 80 | 				ksev.sigev_tid = evp->sigev_notify_thread_id; | ||
| 81 | 			else | ||
| 82 | 				ksev.sigev_tid = 0; | ||
| 83 | 			ksevp = &ksev; | ||
| 84 | 		} | ||
| 85 | 		if (syscall(SYS_timer_create, clk, ksevp, &timerid) < 0) | ||
| 86 | 			return -1; | ||
| 87 | 		*res = (void *)(intptr_t)timerid; | ||
| 88 | 		break; | ||
| 89 | 	case SIGEV_THREAD: | ||
| 90 | 		if (!init) { | ||
| 91 | 			struct sigaction sa = { .sa_handler = SIG_DFL }; | ||
| 92 | 			__libc_sigaction(SIGTIMER, &sa, 0); | ||
| 93 | 			a_store(&init, 1); | ||
| 94 | 		} | ||
| 95 | 		if (evp->sigev_notify_attributes) | ||
| 96 | 			attr = *evp->sigev_notify_attributes; | ||
| 97 | 		else | ||
| 98 | 			pthread_attr_init(&attr); | ||
| 99 | 		pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); | ||
| 100 | 		pthread_barrier_init(&args.b, 0, 2); | ||
| 101 | 		args.sev = evp; | ||
| 102 | |||
| 103 | 		__block_app_sigs(&set); | ||
| 104 | 		__syscall(SYS_rt_sigprocmask, SIG_BLOCK, SIGTIMER_SET, 0, _NSIG/8); | ||
| 105 | 		r = pthread_create(&td, &attr, start, &args); | ||
| 106 | 		__restore_sigs(&set); | ||
| 107 | 		if (r) { | ||
| 108 | 			errno = r; | ||
| 109 | 			return -1; | ||
| 110 | 		} | ||
| 111 | |||
| 112 | 		ksev.sigev_value.sival_ptr = 0; | ||
| 113 | 		ksev.sigev_signo = SIGTIMER; | ||
| 114 | 		ksev.sigev_notify = SIGEV_THREAD_ID; | ||
| 115 | 		ksev.sigev_tid = td->tid; | ||
| 116 | 		if (syscall(SYS_timer_create, clk, &ksev, &timerid) < 0) | ||
| 117 | 			timerid = -1; | ||
| 118 | 		td->timer_id = timerid; | ||
| 119 | 		pthread_barrier_wait(&args.b); | ||
| 120 | 		if (timerid < 0) return -1; | ||
| 121 | 		*res = (void *)(INTPTR_MIN | (uintptr_t)td>>1); | ||
| 122 | 		break; | ||
| 123 | 	default: | ||
| 124 | 		errno = EINVAL; | ||
| 125 | 		return -1; | ||
| 126 | 	} | ||
| 127 | |||
| 128 | 	return 0; | ||
| 129 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/timer_delete.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | int timer_delete(timer_t t) | ||
| 6 | { | ||
| 7 | 	if ((intptr_t)t < 0) { | ||
| 8 | 		pthread_t td = (void *)((uintptr_t)t << 1); | ||
| 9 | 		a_store(&td->timer_id, td->timer_id | INT_MIN); | ||
| 10 | 		__syscall(SYS_tkill, td->tid, SIGTIMER); | ||
| 11 | 		return 0; | ||
| 12 | 	} | ||
| 13 | 	return __syscall(SYS_timer_delete, t); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/timer_getoverrun.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | int timer_getoverrun(timer_t t) | ||
| 6 | { | ||
| 7 | 	if ((intptr_t)t < 0) { | ||
| 8 | 		pthread_t td = (void *)((uintptr_t)t << 1); | ||
| 9 | 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX); | ||
| 10 | 	} | ||
| 11 | 	return syscall(SYS_timer_getoverrun, t); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/timer_gettime.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | int timer_gettime(timer_t t, struct itimerspec *val) | ||
| 6 | { | ||
| 7 | 	if ((intptr_t)t < 0) { | ||
| 8 | 		pthread_t td = (void *)((uintptr_t)t << 1); | ||
| 9 | 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX); | ||
| 10 | 	} | ||
| 11 | #ifdef SYS_timer_gettime64 | ||
| 12 | 	int r = -ENOSYS; | ||
| 13 | 	if (sizeof(time_t) > 4) | ||
| 14 | 		r = __syscall(SYS_timer_gettime64, t, val); | ||
| 15 | 	if (SYS_timer_gettime == SYS_timer_gettime64 || r!=-ENOSYS) | ||
| 16 | 		return __syscall_ret(r); | ||
| 17 | 	long val32[4]; | ||
| 18 | 	r = __syscall(SYS_timer_gettime, t, val32); | ||
| 19 | 	if (!r) { | ||
| 20 | 		val->it_interval.tv_sec = val32[0]; | ||
| 21 | 		val->it_interval.tv_nsec = val32[1]; | ||
| 22 | 		val->it_value.tv_sec = val32[2]; | ||
| 23 | 		val->it_value.tv_nsec = val32[3]; | ||
| 24 | 	} | ||
| 25 | 	return __syscall_ret(r); | ||
| 26 | #endif | ||
| 27 | 	return syscall(SYS_timer_gettime, t, val); | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/timer_settime.c created+37| ... | @@ -0,0 +1,37 @@ | ||
| 1 | #include <time.h> | ||
| 2 | #include <limits.h> | ||
| 3 | #include "pthread_impl.h" | ||
| 4 | |||
| 5 | #define IS32BIT(x) !((x)+0x80000000ULL>>32) | ||
| 6 | |||
| 7 | int timer_settime(timer_t t, int flags, const struct itimerspec *restrict val, struct itimerspec *restrict old) | ||
| 8 | { | ||
| 9 | 	if ((intptr_t)t < 0) { | ||
| 10 | 		pthread_t td = (void *)((uintptr_t)t << 1); | ||
| 11 | 		t = (void *)(uintptr_t)(td->timer_id & INT_MAX); | ||
| 12 | 	} | ||
| 13 | #ifdef SYS_timer_settime64 | ||
| 14 | 	time_t is = val->it_interval.tv_sec, vs = val->it_value.tv_sec; | ||
| 15 | 	long ins = val->it_interval.tv_nsec, vns = val->it_value.tv_nsec; | ||
| 16 | 	int r = -ENOSYS; | ||
| 17 | 	if (SYS_timer_settime == SYS_timer_settime64 | ||
| 18 | 	 || !IS32BIT(is) || !IS32BIT(vs) || (sizeof(time_t)>4 && old)) | ||
| 19 | 		r = __syscall(SYS_timer_settime64, t, flags, | ||
| 20 | 			((long long[]){is, ins, vs, vns}), old); | ||
| 21 | 	if (SYS_timer_settime == SYS_timer_settime64 || r!=-ENOSYS) | ||
| 22 | 		return __syscall_ret(r); | ||
| 23 | 	if (!IS32BIT(is) || !IS32BIT(vs)) | ||
| 24 | 		return __syscall_ret(-ENOTSUP); | ||
| 25 | 	long old32[4]; | ||
| 26 | 	r = __syscall(SYS_timer_settime, t, flags, | ||
| 27 | 		((long[]){is, ins, vs, vns}), old32); | ||
| 28 | 	if (!r && old) { | ||
| 29 | 		old->it_interval.tv_sec = old32[0]; | ||
| 30 | 		old->it_interval.tv_nsec = old32[1]; | ||
| 31 | 		old->it_value.tv_sec = old32[2]; | ||
| 32 | 		old->it_value.tv_nsec = old32[3]; | ||
| 33 | 	} | ||
| 34 | 	return __syscall_ret(r); | ||
| 35 | #endif | ||
| 36 | 	return syscall(SYS_timer_settime, t, flags, val, old); | ||
| 37 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/times.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/times.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | clock_t times(struct tms *tms) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_times, tms); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/timespec_get.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <time.h> | ||
| 2 | |||
| 3 | /* There is no other implemented value than TIME_UTC; all other values | ||
| 4 | * are considered erroneous. */ | ||
| 5 | int timespec_get(struct timespec * ts, int base) | ||
| 6 | { | ||
| 7 | 	if (base != TIME_UTC) return 0; | ||
| 8 | 	int ret = __clock_gettime(CLOCK_REALTIME, ts); | ||
| 9 | 	return ret < 0 ? 0 : base; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/utime.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <utime.h> | ||
| 2 | #include <sys/stat.h> | ||
| 3 | #include <time.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | |||
| 6 | int utime(const char *path, const struct utimbuf *times) | ||
| 7 | { | ||
| 8 | 	return utimensat(AT_FDCWD, path, times ? ((struct timespec [2]){ | ||
| 9 | 		{ .tv_sec = times->actime }, { .tv_sec = times->modtime }}) | ||
| 10 | 		: 0, 0); | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/time/wcsftime.c created+71| ... | @@ -0,0 +1,71 @@ | ||
| 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/musl/src/unistd/_exit.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | _Noreturn void _exit(int status) | ||
| 5 | { | ||
| 6 | 	_Exit(status); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/access.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int access(const char *filename, int amode) | ||
| 6 | { | ||
| 7 | #ifdef SYS_access | ||
| 8 | 	return syscall(SYS_access, filename, amode); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_faccessat, AT_FDCWD, filename, amode, 0); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/acct.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int acct(const char *filename) | ||
| 6 | { | ||
| 7 | 	return syscall(SYS_acct, filename); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/alarm.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <sys/time.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | unsigned alarm(unsigned seconds) | ||
| 6 | { | ||
| 7 | 	struct itimerval it = { .it_value.tv_sec = seconds }, old = { 0 }; | ||
| 8 | 	setitimer(ITIMER_REAL, &it, &old); | ||
| 9 | 	return old.it_value.tv_sec + !!old.it_value.tv_usec; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/chdir.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int chdir(const char *path) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_chdir, path); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/chown.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int chown(const char *path, uid_t uid, gid_t gid) | ||
| 6 | { | ||
| 7 | #ifdef SYS_chown | ||
| 8 | 	return syscall(SYS_chown, path, uid, gid); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, 0); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/close.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include "aio_impl.h" | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | static int dummy(int fd) | ||
| 7 | { | ||
| 8 | 	return fd; | ||
| 9 | } | ||
| 10 | |||
| 11 | weak_alias(dummy, __aio_close); | ||
| 12 | |||
| 13 | int close(int fd) | ||
| 14 | { | ||
| 15 | 	fd = __aio_close(fd); | ||
| 16 | 	int r = __syscall_cp(SYS_close, fd); | ||
| 17 | 	if (r == -EINTR) r = 0; | ||
| 18 | 	return __syscall_ret(r); | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/ctermid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include <string.h> | ||
| 3 | |||
| 4 | char *ctermid(char *s) | ||
| 5 | { | ||
| 6 | 	return s ? strcpy(s, "/dev/tty") : "/dev/tty"; | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/dup.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int dup(int fd) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_dup, fd); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/dup2.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int dup2(int old, int new) | ||
| 7 | { | ||
| 8 | 	int r; | ||
| 9 | #ifdef SYS_dup2 | ||
| 10 | 	while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); | ||
| 11 | #else | ||
| 12 | 	if (old==new) { | ||
| 13 | 		r = __syscall(SYS_fcntl, old, F_GETFD); | ||
| 14 | 		if (r >= 0) return old; | ||
| 15 | 	} else { | ||
| 16 | 		while ((r=__syscall(SYS_dup3, old, new, 0))==-EBUSY); | ||
| 17 | 	} | ||
| 18 | #endif | ||
| 19 | 	return __syscall_ret(r); | ||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/dup3.c created+24| ... | @@ -0,0 +1,24 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <errno.h> | ||
| 4 | #include <fcntl.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | int __dup3(int old, int new, int flags) | ||
| 8 | { | ||
| 9 | 	int r; | ||
| 10 | #ifdef SYS_dup2 | ||
| 11 | 	if (old==new) return __syscall_ret(-EINVAL); | ||
| 12 | 	if (flags & O_CLOEXEC) { | ||
| 13 | 		while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); | ||
| 14 | 		if (r!=-ENOSYS) return __syscall_ret(r); | ||
| 15 | 	} | ||
| 16 | 	while ((r=__syscall(SYS_dup2, old, new))==-EBUSY); | ||
| 17 | 	if (flags & O_CLOEXEC) __syscall(SYS_fcntl, new, F_SETFD, FD_CLOEXEC); | ||
| 18 | #else | ||
| 19 | 	while ((r=__syscall(SYS_dup3, old, new, flags))==-EBUSY); | ||
| 20 | #endif | ||
| 21 | 	return __syscall_ret(r); | ||
| 22 | } | ||
| 23 | |||
| 24 | weak_alias(__dup3, dup3); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/faccessat.c created+61| ... | @@ -0,0 +1,61 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include <sys/wait.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | #include "pthread_impl.h" | ||
| 6 | |||
| 7 | struct ctx { | ||
| 8 | 	int fd; | ||
| 9 | 	const char *filename; | ||
| 10 | 	int amode; | ||
| 11 | 	int p; | ||
| 12 | }; | ||
| 13 | |||
| 14 | static int checker(void *p) | ||
| 15 | { | ||
| 16 | 	struct ctx *c = p; | ||
| 17 | 	int ret; | ||
| 18 | 	if (__syscall(SYS_setregid, __syscall(SYS_getegid), -1) | ||
| 19 | 	 || __syscall(SYS_setreuid, __syscall(SYS_geteuid), -1)) | ||
| 20 | 		__syscall(SYS_exit, 1); | ||
| 21 | 	ret = __syscall(SYS_faccessat, c->fd, c->filename, c->amode, 0); | ||
| 22 | 	__syscall(SYS_write, c->p, &ret, sizeof ret); | ||
| 23 | 	return 0; | ||
| 24 | } | ||
| 25 | |||
| 26 | int faccessat(int fd, const char *filename, int amode, int flag) | ||
| 27 | { | ||
| 28 | 	if (flag) { | ||
| 29 | 		int ret = __syscall(SYS_faccessat2, fd, filename, amode, flag); | ||
| 30 | 		if (ret != -ENOSYS) return __syscall_ret(ret); | ||
| 31 | 	} | ||
| 32 | |||
| 33 | 	if (flag & ~AT_EACCESS) | ||
| 34 | 		return __syscall_ret(-EINVAL); | ||
| 35 | |||
| 36 | 	if (!flag || (getuid()==geteuid() && getgid()==getegid())) | ||
| 37 | 		return syscall(SYS_faccessat, fd, filename, amode); | ||
| 38 | |||
| 39 | 	char stack[1024]; | ||
| 40 | 	sigset_t set; | ||
| 41 | 	pid_t pid; | ||
| 42 | 	int status; | ||
| 43 | 	int ret, p[2]; | ||
| 44 | |||
| 45 | 	if (pipe2(p, O_CLOEXEC)) return __syscall_ret(-EBUSY); | ||
| 46 | 	struct ctx c = { .fd = fd, .filename = filename, .amode = amode, .p = p[1] }; | ||
| 47 | |||
| 48 | 	__block_all_sigs(&set); | ||
| 49 | 	 | ||
| 50 | 	pid = __clone(checker, stack+sizeof stack, 0, &c); | ||
| 51 | 	__syscall(SYS_close, p[1]); | ||
| 52 | |||
| 53 | 	if (pid<0 || __syscall(SYS_read, p[0], &ret, sizeof ret) != sizeof(ret)) | ||
| 54 | 		ret = -EBUSY; | ||
| 55 | 	__syscall(SYS_close, p[0]); | ||
| 56 | 	__syscall(SYS_wait4, pid, &status, __WCLONE, 0); | ||
| 57 | |||
| 58 | 	__restore_sigs(&set); | ||
| 59 | |||
| 60 | 	return __syscall_ret(ret); | ||
| 61 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/fchdir.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int fchdir(int fd) | ||
| 7 | { | ||
| 8 | 	int ret = __syscall(SYS_fchdir, fd); | ||
| 9 | 	if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) | ||
| 10 | 		return __syscall_ret(ret); | ||
| 11 | |||
| 12 | 	char buf[15+3*sizeof(int)]; | ||
| 13 | 	__procfdname(buf, fd); | ||
| 14 | 	return syscall(SYS_chdir, buf); | ||
| 15 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/fchown.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int fchown(int fd, uid_t uid, gid_t gid) | ||
| 7 | { | ||
| 8 | 	int ret = __syscall(SYS_fchown, fd, uid, gid); | ||
| 9 | 	if (ret != -EBADF || __syscall(SYS_fcntl, fd, F_GETFD) < 0) | ||
| 10 | 		return __syscall_ret(ret); | ||
| 11 | |||
| 12 | 	char buf[15+3*sizeof(int)]; | ||
| 13 | 	__procfdname(buf, fd); | ||
| 14 | #ifdef SYS_chown | ||
| 15 | 	return syscall(SYS_chown, buf, uid, gid); | ||
| 16 | #else | ||
| 17 | 	return syscall(SYS_fchownat, AT_FDCWD, buf, uid, gid, 0); | ||
| 18 | #endif | ||
| 19 | |||
| 20 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/fchownat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int fchownat(int fd, const char *path, uid_t uid, gid_t gid, int flag) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_fchownat, fd, path, uid, gid, flag); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/fdatasync.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int fdatasync(int fd) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_fdatasync, fd); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/fsync.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int fsync(int fd) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_fsync, fd); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/ftruncate.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int ftruncate(int fd, off_t length) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length)); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(ftruncate, ftruncate64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getcwd.c created+25| ... | @@ -0,0 +1,25 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include <string.h> | ||
| 5 | #include "syscall.h" | ||
| 6 | |||
| 7 | char *getcwd(char *buf, size_t size) | ||
| 8 | { | ||
| 9 | 	char tmp[buf ? 1 : PATH_MAX]; | ||
| 10 | 	if (!buf) { | ||
| 11 | 		buf = tmp; | ||
| 12 | 		size = sizeof tmp; | ||
| 13 | 	} else if (!size) { | ||
| 14 | 		errno = EINVAL; | ||
| 15 | 		return 0; | ||
| 16 | 	} | ||
| 17 | 	long ret = syscall(SYS_getcwd, buf, size); | ||
| 18 | 	if (ret < 0) | ||
| 19 | 		return 0; | ||
| 20 | 	if (ret == 0 || buf[0] != '/') { | ||
| 21 | 		errno = ENOENT; | ||
| 22 | 		return 0; | ||
| 23 | 	} | ||
| 24 | 	return buf == tmp ? strdup(buf) : buf; | ||
| 25 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getegid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | gid_t getegid(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_getegid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/geteuid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | uid_t geteuid(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_geteuid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getgid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | gid_t getgid(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_getgid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getgroups.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int getgroups(int count, gid_t list[]) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_getgroups, count, list); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/gethostname.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <sys/utsname.h> | ||
| 3 | |||
| 4 | int gethostname(char *name, size_t len) | ||
| 5 | { | ||
| 6 | 	size_t i; | ||
| 7 | 	struct utsname uts; | ||
| 8 | 	if (uname(&uts)) return -1; | ||
| 9 | 	if (len > sizeof uts.nodename) len = sizeof uts.nodename; | ||
| 10 | 	for (i=0; i<len && (name[i] = uts.nodename[i]); i++); | ||
| 11 | 	if (i && i==len) name[i-1] = 0; | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getlogin.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <stdlib.h> | ||
| 3 | |||
| 4 | char *getlogin(void) | ||
| 5 | { | ||
| 6 | 	return getenv("LOGNAME"); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getlogin_r.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <string.h> | ||
| 3 | #include <errno.h> | ||
| 4 | |||
| 5 | int getlogin_r(char *name, size_t size) | ||
| 6 | { | ||
| 7 | 	char *logname = getlogin(); | ||
| 8 | 	if (!logname) return ENXIO; /* or...? */ | ||
| 9 | 	if (strlen(logname) >= size) return ERANGE; | ||
| 10 | 	strcpy(name, logname); | ||
| 11 | 	return 0; | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getpgid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t getpgid(pid_t pid) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_getpgid, pid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getpgrp.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t getpgrp(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_getpgid, 0); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getpid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t getpid(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_getpid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getppid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t getppid(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_getppid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getsid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t getsid(pid_t pid) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_getsid, pid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/getuid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | uid_t getuid(void) | ||
| 5 | { | ||
| 6 | 	return __syscall(SYS_getuid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/isatty.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <sys/ioctl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int isatty(int fd) | ||
| 7 | { | ||
| 8 | 	struct winsize wsz; | ||
| 9 | 	unsigned long r = syscall(SYS_ioctl, fd, TIOCGWINSZ, &wsz); | ||
| 10 | 	if (r == 0) return 1; | ||
| 11 | 	if (errno != EBADF) errno = ENOTTY; | ||
| 12 | 	return 0; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/lchown.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int lchown(const char *path, uid_t uid, gid_t gid) | ||
| 6 | { | ||
| 7 | #ifdef SYS_lchown | ||
| 8 | 	return syscall(SYS_lchown, path, uid, gid); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_fchownat, AT_FDCWD, path, uid, gid, AT_SYMLINK_NOFOLLOW); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/link.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int link(const char *existing, const char *new) | ||
| 6 | { | ||
| 7 | #ifdef SYS_link | ||
| 8 | 	return syscall(SYS_link, existing, new); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_linkat, AT_FDCWD, existing, AT_FDCWD, new, 0); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/linkat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int linkat(int fd1, const char *existing, int fd2, const char *new, int flag) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_linkat, fd1, existing, fd2, new, flag); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/lseek.c created+23| ... | @@ -0,0 +1,23 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | off_t __lseek(int fd, off_t offset, int whence) | ||
| 5 | { | ||
| 6 | #ifdef SYS__llseek | ||
| 7 | 	off_t result; | ||
| 8 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 9 | 	return syscall(SYS__llseek, fd, offset>>32, offset, &result, whence) ? -1 : result; | ||
| 10 | #else | ||
| 11 | 	return llseek(fd, offset>>32, offset, &result, whence) ? -1 : result; | ||
| 12 | #endif | ||
| 13 | #else | ||
| 14 | #ifdef __wasilibc_unmodified_upstream // WASI has no syscall | ||
| 15 | 	return syscall(SYS_lseek, fd, offset, whence); | ||
| 16 | #else | ||
| 17 | 	return lseek(fd, offset, whence); | ||
| 18 | #endif | ||
| 19 | #endif | ||
| 20 | } | ||
| 21 | |||
| 22 | weak_alias(__lseek, lseek); | ||
| 23 | weak_alias(__lseek, lseek64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/mips/pipe.s created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | .set noreorder | ||
| 2 | |||
| 3 | .global pipe | ||
| 4 | .type pipe,@function | ||
| 5 | pipe: | ||
| 6 | 	lui $gp, %hi(_gp_disp) | ||
| 7 | 	addiu $gp, %lo(_gp_disp) | ||
| 8 | 	addu $gp, $gp, $25 | ||
| 9 | 	li $2, 4042 | ||
| 10 | 	syscall | ||
| 11 | 	beq $7, $0, 1f | ||
| 12 | 	nop | ||
| 13 | 	lw $25, %call16(__syscall_ret)($gp) | ||
| 14 | 	jr $25 | ||
| 15 | 	subu $4, $0, $2 | ||
| 16 | 1:	sw $2, 0($4) | ||
| 17 | 	sw $3, 4($4) | ||
| 18 | 	move $2, $0 | ||
| 19 | 	jr $ra | ||
| 20 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/mips64/pipe.s created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	pipe | ||
| 3 | .type	pipe,@function | ||
| 4 | pipe: | ||
| 5 | 	lui	$3, %hi(%neg(%gp_rel(pipe))) | ||
| 6 | 	daddiu	$3, $3, %lo(%neg(%gp_rel(pipe))) | ||
| 7 | 	daddu	$3, $3, $25 | ||
| 8 | 	li	$2, 5021 | ||
| 9 | 	syscall | ||
| 10 | 	beq	$7, $0, 1f | ||
| 11 | 	nop | ||
| 12 | 	ld	$25, %got_disp(__syscall_ret)($3) | ||
| 13 | 	jr	$25 | ||
| 14 | 	dsubu	$4, $0, $2 | ||
| 15 | 1:	sw	$2, 0($4) | ||
| 16 | 	sw	$3, 4($4) | ||
| 17 | 	move	$2, $0 | ||
| 18 | 	jr	$ra | ||
| 19 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/mipsn32/lseek.c created+20| ... | @@ -0,0 +1,20 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | off_t __lseek(int fd, off_t offset, int whence) | ||
| 5 | { | ||
| 6 | 	register long long r4 __asm__("$4") = fd; | ||
| 7 | 	register long long r5 __asm__("$5") = offset; | ||
| 8 | 	register long long r6 __asm__("$6") = whence; | ||
| 9 | 	register long long r7 __asm__("$7"); | ||
| 10 | 	register long long r2 __asm__("$2") = SYS_lseek; | ||
| 11 | 	__asm__ __volatile__ ( | ||
| 12 | 		"syscall" | ||
| 13 | 		: "+&r"(r2), "=r"(r7) | ||
| 14 | 		: "r"(r4), "r"(r5), "r"(r6) | ||
| 15 | 		: SYSCALL_CLOBBERLIST); | ||
| 16 | 	return r7 ? __syscall_ret(-r2) : r2; | ||
| 17 | } | ||
| 18 | |||
| 19 | weak_alias(__lseek, lseek); | ||
| 20 | weak_alias(__lseek, lseek64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/mipsn32/pipe.s created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | .set	noreorder | ||
| 2 | .global	pipe | ||
| 3 | .type	pipe,@function | ||
| 4 | pipe: | ||
| 5 | 	lui	$3, %hi(%neg(%gp_rel(pipe))) | ||
| 6 | 	addiu	$3, $3, %lo(%neg(%gp_rel(pipe))) | ||
| 7 | 	addu	$3, $3, $25 | ||
| 8 | 	li	$2, 6021 | ||
| 9 | 	syscall | ||
| 10 | 	beq	$7, $0, 1f | ||
| 11 | 	nop | ||
| 12 | 	lw	$25, %got_disp(__syscall_ret)($3) | ||
| 13 | 	jr	$25 | ||
| 14 | 	subu	$4, $0, $2 | ||
| 15 | 1:	sw	$2, 0($4) | ||
| 16 | 	sw	$3, 4($4) | ||
| 17 | 	move	$2, $0 | ||
| 18 | 	jr	$ra | ||
| 19 | 	nop | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/nice.c created+16| ... | @@ -0,0 +1,16 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <sys/resource.h> | ||
| 3 | #include <limits.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int nice(int inc) | ||
| 7 | { | ||
| 8 | 	int prio = inc; | ||
| 9 | 	// Only query old priority if it can affect the result. | ||
| 10 | 	// This also avoids issues with integer overflow. | ||
| 11 | 	if (inc > -2*NZERO && inc < 2*NZERO) | ||
| 12 | 		prio += getpriority(PRIO_PROCESS, 0); | ||
| 13 | 	if (prio > NZERO-1) prio = NZERO-1; | ||
| 14 | 	if (prio < -NZERO) prio = -NZERO; | ||
| 15 | 	return setpriority(PRIO_PROCESS, 0, prio) ? -1 : prio; | ||
| 16 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/pause.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int pause(void) | ||
| 5 | { | ||
| 6 | #ifdef SYS_pause | ||
| 7 | 	return syscall_cp(SYS_pause); | ||
| 8 | #else | ||
| 9 | 	return syscall_cp(SYS_ppoll, 0, 0, 0, 0); | ||
| 10 | #endif | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/pipe.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int pipe(int fd[2]) | ||
| 5 | { | ||
| 6 | #ifdef SYS_pipe | ||
| 7 | 	return syscall(SYS_pipe, fd); | ||
| 8 | #else | ||
| 9 | 	return syscall(SYS_pipe2, fd, 0); | ||
| 10 | #endif | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/pipe2.c created+22| ... | @@ -0,0 +1,22 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <fcntl.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int pipe2(int fd[2], int flag) | ||
| 7 | { | ||
| 8 | 	if (!flag) return pipe(fd); | ||
| 9 | 	int ret = __syscall(SYS_pipe2, fd, flag); | ||
| 10 | 	if (ret != -ENOSYS) return __syscall_ret(ret); | ||
| 11 | 	ret = pipe(fd); | ||
| 12 | 	if (ret) return ret; | ||
| 13 | 	if (flag & O_CLOEXEC) { | ||
| 14 | 		__syscall(SYS_fcntl, fd[0], F_SETFD, FD_CLOEXEC); | ||
| 15 | 		__syscall(SYS_fcntl, fd[1], F_SETFD, FD_CLOEXEC); | ||
| 16 | 	} | ||
| 17 | 	if (flag & O_NONBLOCK) { | ||
| 18 | 		__syscall(SYS_fcntl, fd[0], F_SETFL, O_NONBLOCK); | ||
| 19 | 		__syscall(SYS_fcntl, fd[1], F_SETFL, O_NONBLOCK); | ||
| 20 | 	} | ||
| 21 | 	return 0; | ||
| 22 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/posix_close.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | int posix_close(int fd, int flags) | ||
| 4 | { | ||
| 5 | 	return close(fd); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/pread.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t pread(int fd, void *buf, size_t size, off_t ofs) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs)); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(pread, pread64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/preadv.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <sys/uio.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs) | ||
| 7 | { | ||
| 8 | 	return syscall_cp(SYS_preadv, fd, iov, count, | ||
| 9 | 		(long)(ofs), (long)(ofs>>32)); | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(preadv, preadv64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/pwrite.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs)); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(pwrite, pwrite64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/pwritev.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _BSD_SOURCE | ||
| 2 | #include <sys/uio.h> | ||
| 3 | #include <unistd.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs) | ||
| 7 | { | ||
| 8 | 	return syscall_cp(SYS_pwritev, fd, iov, count, | ||
| 9 | 		(long)(ofs), (long)(ofs>>32)); | ||
| 10 | } | ||
| 11 | |||
| 12 | weak_alias(pwritev, pwritev64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/read.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t read(int fd, void *buf, size_t count) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_read, fd, buf, count); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/readlink.c created+19| ... | @@ -0,0 +1,19 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize) | ||
| 6 | { | ||
| 7 | 	char dummy[1]; | ||
| 8 | 	if (!bufsize) { | ||
| 9 | 		buf = dummy; | ||
| 10 | 		bufsize = 1; | ||
| 11 | 	} | ||
| 12 | #ifdef SYS_readlink | ||
| 13 | 	int r = __syscall(SYS_readlink, path, buf, bufsize); | ||
| 14 | #else | ||
| 15 | 	int r = __syscall(SYS_readlinkat, AT_FDCWD, path, buf, bufsize); | ||
| 16 | #endif | ||
| 17 | 	if (buf == dummy && r > 0) r = 0; | ||
| 18 | 	return __syscall_ret(r); | ||
| 19 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/readlinkat.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t readlinkat(int fd, const char *restrict path, char *restrict buf, size_t bufsize) | ||
| 5 | { | ||
| 6 | 	char dummy[1]; | ||
| 7 | 	if (!bufsize) { | ||
| 8 | 		buf = dummy; | ||
| 9 | 		bufsize = 1; | ||
| 10 | 	} | ||
| 11 | 	int r = __syscall(SYS_readlinkat, fd, path, buf, bufsize); | ||
| 12 | 	if (buf == dummy && r > 0) r = 0; | ||
| 13 | 	return __syscall_ret(r); | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/readv.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/uio.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t readv(int fd, const struct iovec *iov, int count) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_readv, fd, iov, count); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/renameat.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <stdio.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int renameat(int oldfd, const char *old, int newfd, const char *new) | ||
| 5 | { | ||
| 6 | #ifdef SYS_renameat | ||
| 7 | 	return syscall(SYS_renameat, oldfd, old, newfd, new); | ||
| 8 | #else | ||
| 9 | 	return syscall(SYS_renameat2, oldfd, old, newfd, new, 0); | ||
| 10 | #endif | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/rmdir.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int rmdir(const char *path) | ||
| 6 | { | ||
| 7 | #ifdef SYS_rmdir | ||
| 8 | 	return syscall(SYS_rmdir, path); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setegid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "libc.h" | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int setegid(gid_t egid) | ||
| 6 | { | ||
| 7 | 	return __setxid(SYS_setresgid, -1, egid, -1); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/seteuid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int seteuid(uid_t euid) | ||
| 6 | { | ||
| 7 | 	return __setxid(SYS_setresuid, -1, euid, -1); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setgid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int setgid(gid_t gid) | ||
| 6 | { | ||
| 7 | 	return __setxid(SYS_setgid, gid, 0, 0); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setpgid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int setpgid(pid_t pid, pid_t pgid) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_setpgid, pid, pgid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setpgrp.c created+6| ... | @@ -0,0 +1,6 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | |||
| 3 | pid_t setpgrp(void) | ||
| 4 | { | ||
| 5 | 	return setpgid(0, 0); | ||
| 6 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setregid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int setregid(gid_t rgid, gid_t egid) | ||
| 6 | { | ||
| 7 | 	return __setxid(SYS_setregid, rgid, egid, 0); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setresgid.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "libc.h" | ||
| 5 | |||
| 6 | int setresgid(gid_t rgid, gid_t egid, gid_t sgid) | ||
| 7 | { | ||
| 8 | 	return __setxid(SYS_setresgid, rgid, egid, sgid); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setresuid.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "libc.h" | ||
| 5 | |||
| 6 | int setresuid(uid_t ruid, uid_t euid, uid_t suid) | ||
| 7 | { | ||
| 8 | 	return __setxid(SYS_setresuid, ruid, euid, suid); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setreuid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int setreuid(uid_t ruid, uid_t euid) | ||
| 6 | { | ||
| 7 | 	return __setxid(SYS_setreuid, ruid, euid, 0); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setsid.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | pid_t setsid(void) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_setsid); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setuid.c created+8| ... | @@ -0,0 +1,8 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | #include "libc.h" | ||
| 4 | |||
| 5 | int setuid(uid_t uid) | ||
| 6 | { | ||
| 7 | 	return __setxid(SYS_setuid, uid, 0, 0); | ||
| 8 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/setxid.c created+34| ... | @@ -0,0 +1,34 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <signal.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | #include "libc.h" | ||
| 5 | |||
| 6 | struct ctx { | ||
| 7 | 	int id, eid, sid; | ||
| 8 | 	int nr, ret; | ||
| 9 | }; | ||
| 10 | |||
| 11 | static void do_setxid(void *p) | ||
| 12 | { | ||
| 13 | 	struct ctx *c = p; | ||
| 14 | 	if (c->ret<0) return; | ||
| 15 | 	int ret = __syscall(c->nr, c->id, c->eid, c->sid); | ||
| 16 | 	if (ret && !c->ret) { | ||
| 17 | 		/* If one thread fails to set ids after another has already | ||
| 18 | 		 * succeeded, forcibly killing the process is the only safe | ||
| 19 | 		 * thing to do. State is inconsistent and dangerous. Use | ||
| 20 | 		 * SIGKILL because it is uncatchable. */ | ||
| 21 | 		__block_all_sigs(0); | ||
| 22 | 		__syscall(SYS_kill, __syscall(SYS_getpid), SIGKILL); | ||
| 23 | 	} | ||
| 24 | 	c->ret = ret; | ||
| 25 | } | ||
| 26 | |||
| 27 | int __setxid(int nr, int id, int eid, int sid) | ||
| 28 | { | ||
| 29 | 	/* ret is initially nonzero so that failure of the first thread does not | ||
| 30 | 	 * trigger the safety kill above. */ | ||
| 31 | 	struct ctx c = { .nr = nr, .id = id, .eid = eid, .sid = sid, .ret = 1 }; | ||
| 32 | 	__synccall(do_setxid, &c); | ||
| 33 | 	return __syscall_ret(c.ret); | ||
| 34 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/sh/pipe.s created+27| ... | @@ -0,0 +1,27 @@ | ||
| 1 | .global pipe | ||
| 2 | .type pipe, @function | ||
| 3 | pipe: | ||
| 4 | 	mov #42, r3 | ||
| 5 | 	trapa #31 | ||
| 6 | |||
| 7 | 	! work around hardware bug | ||
| 8 | 	or r0, r0 | ||
| 9 | 	or r0, r0 | ||
| 10 | 	or r0, r0 | ||
| 11 | 	or r0, r0 | ||
| 12 | 	or r0, r0 | ||
| 13 | |||
| 14 | 	cmp/pz r0 | ||
| 15 | 	bt 1f | ||
| 16 | |||
| 17 | 	mov.l L1, r1 | ||
| 18 | 	braf r1 | ||
| 19 | 	 mov r0, r4 | ||
| 20 | |||
| 21 | 1:	mov.l r0, @(0,r4) | ||
| 22 | 	mov.l r1, @(4,r4) | ||
| 23 | 	rts | ||
| 24 | 	 mov #0, r0 | ||
| 25 | |||
| 26 | .align 2 | ||
| 27 | L1:	.long __syscall_ret@PLT-(1b-.) | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/sleep.c created+10| ... | @@ -0,0 +1,10 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <time.h> | ||
| 3 | |||
| 4 | unsigned sleep(unsigned seconds) | ||
| 5 | { | ||
| 6 | 	struct timespec tv = { .tv_sec = seconds, .tv_nsec = 0 }; | ||
| 7 | 	if (nanosleep(&tv, &tv)) | ||
| 8 | 		return tv.tv_sec; | ||
| 9 | 	return 0; | ||
| 10 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/symlink.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int symlink(const char *existing, const char *new) | ||
| 6 | { | ||
| 7 | #ifdef SYS_symlink | ||
| 8 | 	return syscall(SYS_symlink, existing, new); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_symlinkat, existing, AT_FDCWD, new); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/symlinkat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int symlinkat(const char *existing, int fd, const char *new) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_symlinkat, existing, fd, new); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/sync.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | void sync(void) | ||
| 5 | { | ||
| 6 | 	__syscall(SYS_sync); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/tcgetpgrp.c created+11| ... | @@ -0,0 +1,11 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <termios.h> | ||
| 3 | #include <sys/ioctl.h> | ||
| 4 | |||
| 5 | pid_t tcgetpgrp(int fd) | ||
| 6 | { | ||
| 7 | 	int pgrp; | ||
| 8 | 	if (ioctl(fd, TIOCGPGRP, &pgrp) < 0) | ||
| 9 | 		return -1; | ||
| 10 | 	return pgrp; | ||
| 11 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/tcsetpgrp.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <termios.h> | ||
| 3 | #include <sys/ioctl.h> | ||
| 4 | |||
| 5 | int tcsetpgrp(int fd, pid_t pgrp) | ||
| 6 | { | ||
| 7 | 	int pgrp_int = pgrp; | ||
| 8 | 	return ioctl(fd, TIOCSPGRP, &pgrp_int); | ||
| 9 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/truncate.c created+9| ... | @@ -0,0 +1,9 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int truncate(const char *path, off_t length) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_truncate, path, __SYSCALL_LL_O(length)); | ||
| 7 | } | ||
| 8 | |||
| 9 | weak_alias(truncate, truncate64); | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/ttyname.c created+14| ... | @@ -0,0 +1,14 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <limits.h> | ||
| 4 | |||
| 5 | char *ttyname(int fd) | ||
| 6 | { | ||
| 7 | 	static char buf[TTY_NAME_MAX]; | ||
| 8 | 	int result; | ||
| 9 | 	if ((result = ttyname_r(fd, buf, sizeof buf))) { | ||
| 10 | 		errno = result; | ||
| 11 | 		return NULL; | ||
| 12 | 	} | ||
| 13 | 	return buf; | ||
| 14 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/ttyname_r.c created+28| ... | @@ -0,0 +1,28 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <errno.h> | ||
| 3 | #include <sys/stat.h> | ||
| 4 | #include "syscall.h" | ||
| 5 | |||
| 6 | int ttyname_r(int fd, char *name, size_t size) | ||
| 7 | { | ||
| 8 | 	struct stat st1, st2; | ||
| 9 | 	char procname[sizeof "/proc/self/fd/" + 3*sizeof(int) + 2]; | ||
| 10 | 	ssize_t l; | ||
| 11 | |||
| 12 | 	if (!isatty(fd)) return errno; | ||
| 13 | |||
| 14 | 	__procfdname(procname, fd); | ||
| 15 | 	l = readlink(procname, name, size); | ||
| 16 | |||
| 17 | 	if (l < 0) return errno; | ||
| 18 | 	else if (l == size) return ERANGE; | ||
| 19 | |||
| 20 | 	name[l] = 0; | ||
| 21 | |||
| 22 | 	if (stat(name, &st1) || fstat(fd, &st2)) | ||
| 23 | 		return errno; | ||
| 24 | 	if (st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino) | ||
| 25 | 		return ENODEV; | ||
| 26 | |||
| 27 | 	return 0; | ||
| 28 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/ualarm.c created+13| ... | @@ -0,0 +1,13 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <sys/time.h> | ||
| 4 | |||
| 5 | unsigned ualarm(unsigned value, unsigned interval) | ||
| 6 | { | ||
| 7 | 	struct itimerval it = { | ||
| 8 | 		.it_interval.tv_usec = interval, | ||
| 9 | 		.it_value.tv_usec = value | ||
| 10 | 	}, it_old; | ||
| 11 | 	setitimer(ITIMER_REAL, &it, &it_old); | ||
| 12 | 	return it_old.it_value.tv_sec*1000000 + it_old.it_value.tv_usec; | ||
| 13 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/unlink.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include <fcntl.h> | ||
| 3 | #include "syscall.h" | ||
| 4 | |||
| 5 | int unlink(const char *path) | ||
| 6 | { | ||
| 7 | #ifdef SYS_unlink | ||
| 8 | 	return syscall(SYS_unlink, path); | ||
| 9 | #else | ||
| 10 | 	return syscall(SYS_unlinkat, AT_FDCWD, path, 0); | ||
| 11 | #endif | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/unlinkat.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | int unlinkat(int fd, const char *path, int flag) | ||
| 5 | { | ||
| 6 | 	return syscall(SYS_unlinkat, fd, path, flag); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/usleep.c created+12| ... | @@ -0,0 +1,12 @@ | ||
| 1 | #define _GNU_SOURCE | ||
| 2 | #include <unistd.h> | ||
| 3 | #include <time.h> | ||
| 4 | |||
| 5 | int usleep(unsigned useconds) | ||
| 6 | { | ||
| 7 | 	struct timespec tv = { | ||
| 8 | 		.tv_sec = useconds/1000000, | ||
| 9 | 		.tv_nsec = (useconds%1000000)*1000 | ||
| 10 | 	}; | ||
| 11 | 	return nanosleep(&tv, &tv); | ||
| 12 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/write.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t write(int fd, const void *buf, size_t count) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_write, fd, buf, count); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/writev.c created+7| ... | @@ -0,0 +1,7 @@ | ||
| 1 | #include <sys/uio.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | ssize_t writev(int fd, const struct iovec *iov, int count) | ||
| 5 | { | ||
| 6 | 	return syscall_cp(SYS_writev, fd, iov, count); | ||
| 7 | } | ||
lib/libc/wasi/libc-top-half/musl/src/unistd/x32/lseek.c created+15| ... | @@ -0,0 +1,15 @@ | ||
| 1 | #include <unistd.h> | ||
| 2 | #include "syscall.h" | ||
| 3 | |||
| 4 | off_t __lseek(int fd, off_t offset, int whence) | ||
| 5 | { | ||
| 6 | 	off_t ret; | ||
| 7 | 	__asm__ __volatile__ ("syscall" | ||
| 8 | 		: "=a"(ret) | ||
| 9 | 		: "a"(SYS_lseek), "D"(fd), "S"(offset), "d"(whence) | ||
| 10 | 		: "rcx", "r11", "memory"); | ||
| 11 | 	return ret < 0 ? __syscall_ret(ret) : ret; | ||
| 12 | } | ||
| 13 | |||
| 14 | weak_alias(__lseek, lseek); | ||
| 15 | weak_alias(__lseek, lseek64); | ||
lib/libc/wasi/libc-top-half/sources/arc4random.c created+160| ... | @@ -0,0 +1,160 @@ | ||
| 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/std/target.zig-3| ... | @@ -1307,9 +1307,6 @@ pub const Target = struct { | ... | @@ -1307,9 +1307,6 @@ pub const Target = struct { |
| 1307 | } | 1307 | } |
| 1308 | 1308 | ||
| 1309 | pub fn libPrefix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { | 1309 | pub fn libPrefix_cpu_arch_abi(cpu_arch: Cpu.Arch, abi: Abi) [:0]const u8 { |
| 1310 | if (cpu_arch.isWasm()) { | ||
| 1311 | return ""; | ||
| 1312 | } | ||
| 1313 | switch (abi) { | 1310 | switch (abi) { |
| 1314 | .msvc => return "", | 1311 | .msvc => return "", |
| 1315 | else => return "lib", | 1312 | else => return "lib", |
lib/std/zig.zig+8-1| ... | @@ -160,8 +160,15 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro | ... | @@ -160,8 +160,15 @@ pub fn binNameAlloc(allocator: *std.mem.Allocator, options: BinNameOptions) erro |
| 160 | }, | 160 | }, |
| 161 | .wasm => switch (options.output_mode) { | 161 | .wasm => switch (options.output_mode) { |
| 162 | .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), | 162 | .Exe => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.exeFileExt() }), |
| 163 | .Lib => { | ||
| 164 | switch (options.link_mode orelse .Static) { | ||
| 165 | .Static => return std.fmt.allocPrint(allocator, "{s}{s}.a", .{ | ||
| 166 | target.libPrefix(), root_name, | ||
| 167 | }), | ||
| 168 | .Dynamic => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}), | ||
| 169 | } | ||
| 170 | }, | ||
| 163 | .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), | 171 | .Obj => return std.fmt.allocPrint(allocator, "{s}{s}", .{ root_name, target.oFileExt() }), |
| 164 | .Lib => return std.fmt.allocPrint(allocator, "{s}.wasm", .{root_name}), | ||
| 165 | }, | 172 | }, |
| 166 | .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}), | 173 | .c => return std.fmt.allocPrint(allocator, "{s}.c", .{root_name}), |
| 167 | .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}), | 174 | .spirv => return std.fmt.allocPrint(allocator, "{s}.spv", .{root_name}), |
src/Compilation.zig+30-9| ... | @@ -21,6 +21,7 @@ const musl = @import("musl.zig"); | ... | @@ -21,6 +21,7 @@ const musl = @import("musl.zig"); |
| 21 | const mingw = @import("mingw.zig"); | 21 | const mingw = @import("mingw.zig"); |
| 22 | const libunwind = @import("libunwind.zig"); | 22 | const libunwind = @import("libunwind.zig"); |
| 23 | const libcxx = @import("libcxx.zig"); | 23 | const libcxx = @import("libcxx.zig"); |
| 24 | const wasi_libc = @import("wasi_libc.zig"); | ||
| 24 | const fatal = @import("main.zig").fatal; | 25 | const fatal = @import("main.zig").fatal; |
| 25 | const Module = @import("Module.zig"); | 26 | const Module = @import("Module.zig"); |
| 26 | const Cache = @import("Cache.zig"); | 27 | const Cache = @import("Cache.zig"); |
| ... | @@ -202,6 +203,8 @@ const Job = union(enum) { | ... | @@ -202,6 +203,8 @@ const Job = union(enum) { |
| 202 | /// needed when not linking libc and using LLVM for code generation because it generates | 203 | /// needed when not linking libc and using LLVM for code generation because it generates |
| 203 | /// calls to, for example, memcpy and memset. | 204 | /// calls to, for example, memcpy and memset. |
| 204 | zig_libc: void, | 205 | zig_libc: void, |
| 206 | /// WASI libc sysroot | ||
| 207 | wasi_libc_sysroot: void, | ||
| 205 | 208 | ||
| 206 | /// Use stage1 C++ code to compile zig code into an object file. | 209 | /// Use stage1 C++ code to compile zig code into an object file. |
| 207 | stage1_module: void, | 210 | stage1_module: void, |
| ... | @@ -276,6 +279,7 @@ pub const MiscTask = enum { | ... | @@ -276,6 +279,7 @@ pub const MiscTask = enum { |
| 276 | libcxx, | 279 | libcxx, |
| 277 | libcxxabi, | 280 | libcxxabi, |
| 278 | libtsan, | 281 | libtsan, |
| 282 | wasi_libc_sysroot, | ||
| 279 | compiler_rt, | 283 | compiler_rt, |
| 280 | libssp, | 284 | libssp, |
| 281 | zig_libc, | 285 | zig_libc, |
| ... | @@ -769,8 +773,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -769,8 +773,8 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 769 | .Lib => is_dyn_lib, | 773 | .Lib => is_dyn_lib, |
| 770 | .Exe => true, | 774 | .Exe => true, |
| 771 | }; | 775 | }; |
| 772 | const needs_c_symbols = !options.skip_linker_dependencies and | 776 | |
| 773 | (is_exe_or_dyn_lib or (options.target.isWasm() and options.output_mode != .Obj)); | 777 | const needs_c_symbols = !options.skip_linker_dependencies and is_exe_or_dyn_lib; |
| 774 | 778 | ||
| 775 | const comp: *Compilation = comp: { | 779 | const comp: *Compilation = comp: { |
| 776 | // For allocations that have the same lifetime as Compilation. This arena is used only during this | 780 | // For allocations that have the same lifetime as Compilation. This arena is used only during this |
| ... | @@ -1417,6 +1421,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1417,6 +1421,9 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1417 | }, | 1421 | }, |
| 1418 | }); | 1422 | }); |
| 1419 | } | 1423 | } |
| 1424 | if (comp.wantBuildWasiLibcSysrootFromSource()) { | ||
| 1425 | try comp.work_queue.write(&[_]Job{.{ .wasi_libc_sysroot = {} }}); | ||
| 1426 | } | ||
| 1420 | if (comp.wantBuildMinGWFromSource()) { | 1427 | if (comp.wantBuildMinGWFromSource()) { |
| 1421 | const static_lib_jobs = [_]Job{ | 1428 | const static_lib_jobs = [_]Job{ |
| 1422 | .{ .mingw_crt_file = .mingw32_lib }, | 1429 | .{ .mingw_crt_file = .mingw32_lib }, |
| ... | @@ -1458,7 +1465,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { | ... | @@ -1458,7 +1465,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation { |
| 1458 | // Once it is capable this condition should be removed. | 1465 | // Once it is capable this condition should be removed. |
| 1459 | if (build_options.is_stage1) { | 1466 | if (build_options.is_stage1) { |
| 1460 | if (comp.bin_file.options.include_compiler_rt) { | 1467 | if (comp.bin_file.options.include_compiler_rt) { |
| 1461 | if (is_exe_or_dyn_lib or comp.getTarget().isWasm()) { | 1468 | if (is_exe_or_dyn_lib) { |
| 1462 | try comp.work_queue.writeItem(.{ .compiler_rt_lib = {} }); | 1469 | try comp.work_queue.writeItem(.{ .compiler_rt_lib = {} }); |
| 1463 | } else { | 1470 | } else { |
| 1464 | try comp.work_queue.writeItem(.{ .compiler_rt_obj = {} }); | 1471 | try comp.work_queue.writeItem(.{ .compiler_rt_obj = {} }); |
| ... | @@ -2142,6 +2149,16 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor | ... | @@ -2142,6 +2149,16 @@ pub fn performAllTheWork(self: *Compilation) error{ TimerUnsupported, OutOfMemor |
| 2142 | ); | 2149 | ); |
| 2143 | }; | 2150 | }; |
| 2144 | }, | 2151 | }, |
| 2152 | .wasi_libc_sysroot => { | ||
| 2153 | wasi_libc.buildWasiLibcSysroot(self) catch |err| { | ||
| 2154 | // TODO Surface more error details. | ||
| 2155 | try self.setMiscFailure( | ||
| 2156 | .wasi_libc_sysroot, | ||
| 2157 | "unable to build WASI libc sysroot: {s}", | ||
| 2158 | .{@errorName(err)}, | ||
| 2159 | ); | ||
| 2160 | }; | ||
| 2161 | }, | ||
| 2145 | .compiler_rt_lib => { | 2162 | .compiler_rt_lib => { |
| 2146 | self.buildOutputFromZig( | 2163 | self.buildOutputFromZig( |
| 2147 | "compiler_rt.zig", | 2164 | "compiler_rt.zig", |
| ... | @@ -2882,7 +2899,7 @@ pub fn addCCArgs( | ... | @@ -2882,7 +2899,7 @@ pub fn addCCArgs( |
| 2882 | try argv.append("-D_DEBUG"); | 2899 | try argv.append("-D_DEBUG"); |
| 2883 | try argv.append("-Og"); | 2900 | try argv.append("-Og"); |
| 2884 | 2901 | ||
| 2885 | if (comp.bin_file.options.link_libc) { | 2902 | if (comp.bin_file.options.link_libc and target.os.tag != .wasi) { |
| 2886 | try argv.append("-fstack-protector-strong"); | 2903 | try argv.append("-fstack-protector-strong"); |
| 2887 | try argv.append("--param"); | 2904 | try argv.append("--param"); |
| 2888 | try argv.append("ssp-buffer-size=4"); | 2905 | try argv.append("ssp-buffer-size=4"); |
| ... | @@ -2894,7 +2911,7 @@ pub fn addCCArgs( | ... | @@ -2894,7 +2911,7 @@ pub fn addCCArgs( |
| 2894 | // See the comment in the BuildModeFastRelease case for why we pass -O2 rather | 2911 | // See the comment in the BuildModeFastRelease case for why we pass -O2 rather |
| 2895 | // than -O3 here. | 2912 | // than -O3 here. |
| 2896 | try argv.append("-O2"); | 2913 | try argv.append("-O2"); |
| 2897 | if (comp.bin_file.options.link_libc) { | 2914 | if (comp.bin_file.options.link_libc and target.os.tag != .wasi) { |
| 2898 | try argv.append("-D_FORTIFY_SOURCE=2"); | 2915 | try argv.append("-D_FORTIFY_SOURCE=2"); |
| 2899 | try argv.append("-fstack-protector-strong"); | 2916 | try argv.append("-fstack-protector-strong"); |
| 2900 | try argv.append("--param"); | 2917 | try argv.append("--param"); |
| ... | @@ -3248,7 +3265,8 @@ fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const | ... | @@ -3248,7 +3265,8 @@ fn detectLibCFromLibCInstallation(arena: *Allocator, target: Target, lci: *const |
| 3248 | pub fn get_libc_crt_file(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 { | 3265 | pub fn get_libc_crt_file(comp: *Compilation, arena: *Allocator, basename: []const u8) ![]const u8 { |
| 3249 | if (comp.wantBuildGLibCFromSource() or | 3266 | if (comp.wantBuildGLibCFromSource() or |
| 3250 | comp.wantBuildMuslFromSource() or | 3267 | comp.wantBuildMuslFromSource() or |
| 3251 | comp.wantBuildMinGWFromSource()) | 3268 | comp.wantBuildMinGWFromSource() or |
| 3269 | comp.wantBuildWasiLibcSysrootFromSource()) | ||
| 3252 | { | 3270 | { |
| 3253 | return comp.crt_files.get(basename).?.full_object_path; | 3271 | return comp.crt_files.get(basename).?.full_object_path; |
| 3254 | } | 3272 | } |
| ... | @@ -3288,6 +3306,10 @@ fn wantBuildMuslFromSource(comp: Compilation) bool { | ... | @@ -3288,6 +3306,10 @@ fn wantBuildMuslFromSource(comp: Compilation) bool { |
| 3288 | !comp.getTarget().isWasm(); | 3306 | !comp.getTarget().isWasm(); |
| 3289 | } | 3307 | } |
| 3290 | 3308 | ||
| 3309 | fn wantBuildWasiLibcSysrootFromSource(comp: Compilation) bool { | ||
| 3310 | return comp.wantBuildLibCFromSource() and comp.getTarget().isWasm(); | ||
| 3311 | } | ||
| 3312 | |||
| 3291 | fn wantBuildMinGWFromSource(comp: Compilation) bool { | 3313 | fn wantBuildMinGWFromSource(comp: Compilation) bool { |
| 3292 | return comp.wantBuildLibCFromSource() and comp.getTarget().isMinGW(); | 3314 | return comp.wantBuildLibCFromSource() and comp.getTarget().isMinGW(); |
| 3293 | } | 3315 | } |
| ... | @@ -3591,11 +3613,10 @@ fn buildOutputFromZig( | ... | @@ -3591,11 +3613,10 @@ fn buildOutputFromZig( |
| 3591 | }; | 3613 | }; |
| 3592 | const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; | 3614 | const root_name = src_basename[0 .. src_basename.len - std.fs.path.extension(src_basename).len]; |
| 3593 | const target = comp.getTarget(); | 3615 | const target = comp.getTarget(); |
| 3594 | const fixed_output_mode = if (target.cpu.arch.isWasm()) .Obj else output_mode; | ||
| 3595 | const bin_basename = try std.zig.binNameAlloc(comp.gpa, .{ | 3616 | const bin_basename = try std.zig.binNameAlloc(comp.gpa, .{ |
| 3596 | .root_name = root_name, | 3617 | .root_name = root_name, |
| 3597 | .target = target, | 3618 | .target = target, |
| 3598 | .output_mode = fixed_output_mode, | 3619 | .output_mode = output_mode, |
| 3599 | }); | 3620 | }); |
| 3600 | defer comp.gpa.free(bin_basename); | 3621 | defer comp.gpa.free(bin_basename); |
| 3601 | 3622 | ||
| ... | @@ -3610,7 +3631,7 @@ fn buildOutputFromZig( | ... | @@ -3610,7 +3631,7 @@ fn buildOutputFromZig( |
| 3610 | .target = target, | 3631 | .target = target, |
| 3611 | .root_name = root_name, | 3632 | .root_name = root_name, |
| 3612 | .root_pkg = &root_pkg, | 3633 | .root_pkg = &root_pkg, |
| 3613 | .output_mode = fixed_output_mode, | 3634 | .output_mode = output_mode, |
| 3614 | .thread_pool = comp.thread_pool, | 3635 | .thread_pool = comp.thread_pool, |
| 3615 | .libc_installation = comp.bin_file.options.libc_installation, | 3636 | .libc_installation = comp.bin_file.options.libc_installation, |
| 3616 | .emit_bin = emit_bin, | 3637 | .emit_bin = emit_bin, |
src/link.zig+1-3| ... | @@ -412,9 +412,7 @@ pub const File = struct { | ... | @@ -412,9 +412,7 @@ pub const File = struct { |
| 412 | return; | 412 | return; |
| 413 | } | 413 | } |
| 414 | const use_lld = build_options.have_llvm and base.options.use_lld; | 414 | const use_lld = build_options.have_llvm and base.options.use_lld; |
| 415 | if (use_lld and base.options.output_mode == .Lib and base.options.link_mode == .Static and | 415 | if (use_lld and base.options.output_mode == .Lib and base.options.link_mode == .Static) { |
| 416 | !base.options.target.isWasm()) | ||
| 417 | { | ||
| 418 | return base.linkAsArchive(comp); | 416 | return base.linkAsArchive(comp); |
| 419 | } | 417 | } |
| 420 | switch (base.tag) { | 418 | switch (base.tag) { |
src/link/Wasm.zig+13| ... | @@ -573,6 +573,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -573,6 +573,7 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 573 | null; | 573 | null; |
| 574 | 574 | ||
| 575 | const target = self.base.options.target; | 575 | const target = self.base.options.target; |
| 576 | const link_in_crt = self.base.options.link_libc and self.base.options.output_mode == .Exe; | ||
| 576 | 577 | ||
| 577 | const id_symlink_basename = "lld.id"; | 578 | const id_symlink_basename = "lld.id"; |
| 578 | 579 | ||
| ... | @@ -695,6 +696,18 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { | ... | @@ -695,6 +696,18 @@ fn linkWithLLD(self: *Wasm, comp: *Compilation) !void { |
| 695 | full_out_path, | 696 | full_out_path, |
| 696 | }); | 697 | }); |
| 697 | 698 | ||
| 699 | if (link_in_crt) { | ||
| 700 | // TODO work out if we want standard crt, a reactor or a command | ||
| 701 | try argv.append(try comp.get_libc_crt_file(arena, "crt.o.wasm")); | ||
| 702 | } | ||
| 703 | |||
| 704 | if (!is_obj and self.base.options.link_libc) { | ||
| 705 | try argv.append(try comp.get_libc_crt_file(arena, switch (self.base.options.link_mode) { | ||
| 706 | .Static => "libc.a", | ||
| 707 | .Dynamic => unreachable, | ||
| 708 | })); | ||
| 709 | } | ||
| 710 | |||
| 698 | // Positional arguments to the linker such as object files. | 711 | // Positional arguments to the linker such as object files. |
| 699 | try argv.appendSlice(self.base.options.objects); | 712 | try argv.appendSlice(self.base.options.objects); |
| 700 | 713 |
src/main.zig+6| ... | @@ -1548,6 +1548,12 @@ fn buildOutputType( | ... | @@ -1548,6 +1548,12 @@ fn buildOutputType( |
| 1548 | link_libcpp = true; | 1548 | link_libcpp = true; |
| 1549 | } | 1549 | } |
| 1550 | 1550 | ||
| 1551 | if (cross_target.getCpuArch().isWasm() and output_mode == .Lib and link_mode == null) { | ||
| 1552 | // If link_mode is unspecified, always link as dynamic library when targeting Wasm, | ||
| 1553 | // so that wasm-ld is invoked rather than standard archiver. | ||
| 1554 | link_mode = .Dynamic; | ||
| 1555 | } | ||
| 1556 | |||
| 1551 | // Now that we have target info, we can find out if any of the system libraries | 1557 | // Now that we have target info, we can find out if any of the system libraries |
| 1552 | // are part of libc or libc++. We remove them from the list and communicate their | 1558 | // are part of libc or libc++. We remove them from the list and communicate their |
| 1553 | // existence via flags instead. | 1559 | // existence via flags instead. |
src/target.zig+2| ... | @@ -57,6 +57,7 @@ pub const available_libcs = [_]ArchOsAbi{ | ... | @@ -57,6 +57,7 @@ pub const available_libcs = [_]ArchOsAbi{ |
| 57 | .{ .arch = .sparc, .os = .linux, .abi = .gnu }, | 57 | .{ .arch = .sparc, .os = .linux, .abi = .gnu }, |
| 58 | .{ .arch = .sparcv9, .os = .linux, .abi = .gnu }, | 58 | .{ .arch = .sparcv9, .os = .linux, .abi = .gnu }, |
| 59 | .{ .arch = .wasm32, .os = .freestanding, .abi = .musl }, | 59 | .{ .arch = .wasm32, .os = .freestanding, .abi = .musl }, |
| 60 | .{ .arch = .wasm32, .os = .wasi, .abi = .musl }, | ||
| 60 | .{ .arch = .x86_64, .os = .linux, .abi = .gnu }, | 61 | .{ .arch = .x86_64, .os = .linux, .abi = .gnu }, |
| 61 | .{ .arch = .x86_64, .os = .linux, .abi = .gnux32 }, | 62 | .{ .arch = .x86_64, .os = .linux, .abi = .gnux32 }, |
| 62 | .{ .arch = .x86_64, .os = .linux, .abi = .musl }, | 63 | .{ .arch = .x86_64, .os = .linux, .abi = .musl }, |
| ... | @@ -145,6 +146,7 @@ pub fn libcNeedsLibUnwind(target: std.Target) bool { | ... | @@ -145,6 +146,7 @@ pub fn libcNeedsLibUnwind(target: std.Target) bool { |
| 145 | .watchos, | 146 | .watchos, |
| 146 | .tvos, | 147 | .tvos, |
| 147 | .freestanding, | 148 | .freestanding, |
| 149 | .wasi, // Wasm/WASI currently doesn't offer support for libunwind, so don't link it. | ||
| 148 | => false, | 150 | => false, |
| 149 | 151 | ||
| 150 | .windows => target.abi != .msvc, | 152 | .windows => target.abi != .msvc, |
src/wasi_libc.zig created+1026| ... | @@ -0,0 +1,1026 @@ | ||
| 1 | const std = @import("std"); | ||
| 2 | const path = std.fs.path; | ||
| 3 | |||
| 4 | const Allocator = std.mem.Allocator; | ||
| 5 | const Compilation = @import("Compilation.zig"); | ||
| 6 | const build_options = @import("build_options"); | ||
| 7 | const target_util = @import("target.zig"); | ||
| 8 | |||
| 9 | pub fn buildWasiLibcSysroot(comp: *Compilation) !void { | ||
| 10 | if (!build_options.have_llvm) { | ||
| 11 | return error.ZigCompilerNotBuiltWithLLVMExtensions; | ||
| 12 | } | ||
| 13 | |||
| 14 | const gpa = comp.gpa; | ||
| 15 | var arena_allocator = std.heap.ArenaAllocator.init(gpa); | ||
| 16 | defer arena_allocator.deinit(); | ||
| 17 | const arena = &arena_allocator.allocator; | ||
| 18 | |||
| 19 | { | ||
| 20 | // Compile crt sources. | ||
| 21 | var args = std.ArrayList([]const u8).init(arena); | ||
| 22 | try addCCArgs(comp, arena, &args, false); | ||
| 23 | try args.appendSlice(&[_][]const u8{ | ||
| 24 | "-I", | ||
| 25 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 26 | "libc", | ||
| 27 | "wasi", | ||
| 28 | "libc-bottom-half", | ||
| 29 | "headers", | ||
| 30 | "private", | ||
| 31 | }), | ||
| 32 | |||
| 33 | "-I", | ||
| 34 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 35 | "libc", | ||
| 36 | "wasi", | ||
| 37 | "libc-bottom-half", | ||
| 38 | "cloudlibc", | ||
| 39 | "src", | ||
| 40 | "include", | ||
| 41 | }), | ||
| 42 | |||
| 43 | "-I", | ||
| 44 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 45 | "libc", | ||
| 46 | "wasi", | ||
| 47 | "libc-bottom-half", | ||
| 48 | "cloudlibc", | ||
| 49 | "src", | ||
| 50 | }), | ||
| 51 | }); | ||
| 52 | |||
| 53 | var comp_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | ||
| 54 | for (crt_src_files) |file_path| { | ||
| 55 | try comp_sources.append(.{ | ||
| 56 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 57 | "libc", try sanitize(arena, file_path), | ||
| 58 | }), | ||
| 59 | .extra_flags = args.items, | ||
| 60 | }); | ||
| 61 | } | ||
| 62 | try comp.build_crt_file("crt", .Obj, comp_sources.items); | ||
| 63 | } | ||
| 64 | |||
| 65 | { | ||
| 66 | // Compile WASI libc (sysroot). | ||
| 67 | var comp_sources = std.ArrayList(Compilation.CSourceFile).init(arena); | ||
| 68 | |||
| 69 | { | ||
| 70 | // Compile dlmalloc. | ||
| 71 | var args = std.ArrayList([]const u8).init(arena); | ||
| 72 | try addCCArgs(comp, arena, &args, true); | ||
| 73 | try args.appendSlice(&[_][]const u8{ | ||
| 74 | "-I", | ||
| 75 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 76 | "libc", | ||
| 77 | "wasi", | ||
| 78 | "dlmalloc", | ||
| 79 | "include", | ||
| 80 | }), | ||
| 81 | }); | ||
| 82 | |||
| 83 | for (dlmalloc_src_files) |file_path| { | ||
| 84 | try comp_sources.append(.{ | ||
| 85 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 86 | "libc", try sanitize(arena, file_path), | ||
| 87 | }), | ||
| 88 | .extra_flags = args.items, | ||
| 89 | }); | ||
| 90 | } | ||
| 91 | } | ||
| 92 | |||
| 93 | { | ||
| 94 | // Compile libc-bottom-half. | ||
| 95 | var args = std.ArrayList([]const u8).init(arena); | ||
| 96 | try addCCArgs(comp, arena, &args, true); | ||
| 97 | try args.appendSlice(&[_][]const u8{ | ||
| 98 | "-I", | ||
| 99 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 100 | "libc", | ||
| 101 | "wasi", | ||
| 102 | "libc-bottom-half", | ||
| 103 | "headers", | ||
| 104 | "private", | ||
| 105 | }), | ||
| 106 | |||
| 107 | "-I", | ||
| 108 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 109 | "libc", | ||
| 110 | "wasi", | ||
| 111 | "libc-bottom-half", | ||
| 112 | "cloudlibc", | ||
| 113 | "src", | ||
| 114 | }), | ||
| 115 | |||
| 116 | "-I", | ||
| 117 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 118 | "libc", | ||
| 119 | "wasi", | ||
| 120 | "libc-bottom-half", | ||
| 121 | "cloudlibc", | ||
| 122 | "src", | ||
| 123 | "include", | ||
| 124 | }), | ||
| 125 | }); | ||
| 126 | |||
| 127 | for (libc_bottom_half_src_files) |file_path| { | ||
| 128 | try comp_sources.append(.{ | ||
| 129 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 130 | "libc", try sanitize(arena, file_path), | ||
| 131 | }), | ||
| 132 | .extra_flags = args.items, | ||
| 133 | }); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | { | ||
| 138 | // Compile libc-top-half. | ||
| 139 | var args = std.ArrayList([]const u8).init(arena); | ||
| 140 | try addCCArgs(comp, arena, &args, true); | ||
| 141 | try args.appendSlice(&[_][]const u8{ | ||
| 142 | "-I", | ||
| 143 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 144 | "libc", | ||
| 145 | "wasi", | ||
| 146 | "libc-top-half", | ||
| 147 | "musl", | ||
| 148 | "src", | ||
| 149 | "include", | ||
| 150 | }), | ||
| 151 | |||
| 152 | "-I", | ||
| 153 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 154 | "libc", | ||
| 155 | "wasi", | ||
| 156 | "libc-top-half", | ||
| 157 | "musl", | ||
| 158 | "src", | ||
| 159 | "internal", | ||
| 160 | }), | ||
| 161 | |||
| 162 | "-I", | ||
| 163 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 164 | "libc", | ||
| 165 | "wasi", | ||
| 166 | "libc-top-half", | ||
| 167 | "musl", | ||
| 168 | "arch", | ||
| 169 | "wasm32", | ||
| 170 | }), | ||
| 171 | |||
| 172 | "-I", | ||
| 173 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 174 | "libc", | ||
| 175 | "wasi", | ||
| 176 | "libc-top-half", | ||
| 177 | "musl", | ||
| 178 | "arch", | ||
| 179 | "generic", | ||
| 180 | }), | ||
| 181 | |||
| 182 | "-I", | ||
| 183 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 184 | "libc", | ||
| 185 | "wasi", | ||
| 186 | "libc-top-half", | ||
| 187 | "headers", | ||
| 188 | "private", | ||
| 189 | }), | ||
| 190 | }); | ||
| 191 | |||
| 192 | for (libc_top_half_src_files) |file_path| { | ||
| 193 | try comp_sources.append(.{ | ||
| 194 | .src_path = try comp.zig_lib_directory.join(arena, &[_][]const u8{ | ||
| 195 | "libc", try sanitize(arena, file_path), | ||
| 196 | }), | ||
| 197 | .extra_flags = args.items, | ||
| 198 | }); | ||
| 199 | } | ||
| 200 | } | ||
| 201 | |||
| 202 | try comp.build_crt_file("c", .Lib, comp_sources.items); | ||
| 203 | } | ||
| 204 | } | ||
| 205 | |||
| 206 | fn sanitize(arena: *Allocator, file_path: []const u8) ![]const u8 { | ||
| 207 | // TODO do this at comptime on the comptime data rather than at runtime | ||
| 208 | // probably best to wait until self-hosted is done and our comptime execution | ||
| 209 | // is faster and uses less memory. | ||
| 210 | const out_path = if (path.sep != '/') blk: { | ||
| 211 | const mutable_file_path = try arena.dupe(u8, file_path); | ||
| 212 | for (mutable_file_path) |*c| { | ||
| 213 | if (c.* == '/') { | ||
| 214 | c.* = path.sep; | ||
| 215 | } | ||
| 216 | } | ||
| 217 | break :blk mutable_file_path; | ||
| 218 | } else file_path; | ||
| 219 | return out_path; | ||
| 220 | } | ||
| 221 | |||
| 222 | fn addCCArgs( | ||
| 223 | comp: *Compilation, | ||
| 224 | arena: *Allocator, | ||
| 225 | args: *std.ArrayList([]const u8), | ||
| 226 | want_O3: bool, | ||
| 227 | ) error{OutOfMemory}!void { | ||
| 228 | const target = comp.getTarget(); | ||
| 229 | const arch_name = target_util.archMuslName(target.cpu.arch); | ||
| 230 | const os_name = @tagName(target.os.tag); | ||
| 231 | const triple = try std.fmt.allocPrint(arena, "{s}-{s}-musl", .{ arch_name, os_name }); | ||
| 232 | const o_arg = if (want_O3) "-O3" else "-Os"; | ||
| 233 | |||
| 234 | try args.appendSlice(&[_][]const u8{ | ||
| 235 | "-std=gnu17", | ||
| 236 | "-fno-trapping-math", | ||
| 237 | "-fno-stack-protector", | ||
| 238 | "-w", // ignore all warnings | ||
| 239 | |||
| 240 | o_arg, | ||
| 241 | |||
| 242 | "-mthread-model", | ||
| 243 | "single", | ||
| 244 | |||
| 245 | "-iwithsysroot", | ||
| 246 | try comp.zig_lib_directory.join(arena, &[_][]const u8{ "libc", "include", triple }), | ||
| 247 | }); | ||
| 248 | } | ||
| 249 | |||
| 250 | const dlmalloc_src_files = [_][]const u8{ | ||
| 251 | "wasi/dlmalloc/src/dlmalloc.c", | ||
| 252 | }; | ||
| 253 | |||
| 254 | const libc_bottom_half_src_files = [_][]const u8{ | ||
| 255 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/closedir.c", | ||
| 256 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/dirfd.c", | ||
| 257 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdopendir.c", | ||
| 258 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/readdir.c", | ||
| 259 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/scandirat.c", | ||
| 260 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/telldir.c", | ||
| 261 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/fdclosedir.c", | ||
| 262 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/opendirat.c", | ||
| 263 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/rewinddir.c", | ||
| 264 | "wasi/libc-bottom-half/cloudlibc/src/libc/dirent/seekdir.c", | ||
| 265 | "wasi/libc-bottom-half/cloudlibc/src/libc/errno/errno.c", | ||
| 266 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/fcntl.c", | ||
| 267 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/openat.c", | ||
| 268 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fadvise.c", | ||
| 269 | "wasi/libc-bottom-half/cloudlibc/src/libc/fcntl/posix_fallocate.c", | ||
| 270 | "wasi/libc-bottom-half/cloudlibc/src/libc/poll/poll.c", | ||
| 271 | "wasi/libc-bottom-half/cloudlibc/src/libc/sched/sched_yield.c", | ||
| 272 | "wasi/libc-bottom-half/cloudlibc/src/libc/stdio/renameat.c", | ||
| 273 | "wasi/libc-bottom-half/cloudlibc/src/libc/stdlib/_Exit.c", | ||
| 274 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/ioctl/ioctl.c", | ||
| 275 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/pselect.c", | ||
| 276 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/select/select.c", | ||
| 277 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/getsockopt.c", | ||
| 278 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/recv.c", | ||
| 279 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/send.c", | ||
| 280 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/socket/shutdown.c", | ||
| 281 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstatat.c", | ||
| 282 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/fstat.c", | ||
| 283 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/futimens.c", | ||
| 284 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/mkdirat.c", | ||
| 285 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/utimensat.c", | ||
| 286 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c", | ||
| 287 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/preadv.c", | ||
| 288 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/pwritev.c", | ||
| 289 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/readv.c", | ||
| 290 | "wasi/libc-bottom-half/cloudlibc/src/libc/sys/uio/writev.c", | ||
| 291 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_getres.c", | ||
| 292 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_gettime.c", | ||
| 293 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_MONOTONIC.c", | ||
| 294 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/clock_nanosleep.c", | ||
| 295 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_PROCESS_CPUTIME_ID.c", | ||
| 296 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_REALTIME.c", | ||
| 297 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/CLOCK_THREAD_CPUTIME_ID.c", | ||
| 298 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/nanosleep.c", | ||
| 299 | "wasi/libc-bottom-half/cloudlibc/src/libc/time/time.c", | ||
| 300 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/close.c", | ||
| 301 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/faccessat.c", | ||
| 302 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fdatasync.c", | ||
| 303 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/fsync.c", | ||
| 304 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/ftruncate.c", | ||
| 305 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/linkat.c", | ||
| 306 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/lseek.c", | ||
| 307 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pread.c", | ||
| 308 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/pwrite.c", | ||
| 309 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/read.c", | ||
| 310 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/readlinkat.c", | ||
| 311 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/sleep.c", | ||
| 312 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/symlinkat.c", | ||
| 313 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/unlinkat.c", | ||
| 314 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/usleep.c", | ||
| 315 | "wasi/libc-bottom-half/cloudlibc/src/libc/unistd/write.c", | ||
| 316 | "wasi/libc-bottom-half/sources/abort.c", | ||
| 317 | "wasi/libc-bottom-half/sources/at_fdcwd.c", | ||
| 318 | "wasi/libc-bottom-half/sources/complex-builtins.c", | ||
| 319 | "wasi/libc-bottom-half/sources/environ.c", | ||
| 320 | "wasi/libc-bottom-half/sources/errno.c", | ||
| 321 | "wasi/libc-bottom-half/sources/getcwd.c", | ||
| 322 | "wasi/libc-bottom-half/sources/getentropy.c", | ||
| 323 | "wasi/libc-bottom-half/sources/isatty.c", | ||
| 324 | "wasi/libc-bottom-half/sources/__main_argc_argv.c", | ||
| 325 | "wasi/libc-bottom-half/sources/__main_void.c", | ||
| 326 | "wasi/libc-bottom-half/sources/__original_main.c", | ||
| 327 | "wasi/libc-bottom-half/sources/posix.c", | ||
| 328 | "wasi/libc-bottom-half/sources/preopens.c", | ||
| 329 | "wasi/libc-bottom-half/sources/reallocarray.c", | ||
| 330 | "wasi/libc-bottom-half/sources/sbrk.c", | ||
| 331 | "wasi/libc-bottom-half/sources/truncate.c", | ||
| 332 | "wasi/libc-bottom-half/sources/__wasilibc_fd_renumber.c", | ||
| 333 | "wasi/libc-bottom-half/sources/__wasilibc_initialize_environ.c", | ||
| 334 | "wasi/libc-bottom-half/sources/__wasilibc_real.c", | ||
| 335 | "wasi/libc-bottom-half/sources/__wasilibc_rmdirat.c", | ||
| 336 | "wasi/libc-bottom-half/sources/__wasilibc_tell.c", | ||
| 337 | "wasi/libc-bottom-half/sources/__wasilibc_unlinkat.c", | ||
| 338 | "wasi/libc-bottom-half/sources/math/fmin-fmax.c", | ||
| 339 | "wasi/libc-bottom-half/sources/math/math-builtins.c", | ||
| 340 | // TODO apparently, due to a bug in LLD, the weak refs are garbled | ||
| 341 | // unless chdir.c is last in the archive | ||
| 342 | // https://reviews.llvm.org/D85567 | ||
| 343 | "wasi/libc-bottom-half/sources/chdir.c", | ||
| 344 | }; | ||
| 345 | |||
| 346 | const libc_top_half_src_files = [_][]const u8{ | ||
| 347 | "wasi/libc-top-half/musl/src/misc/a64l.c", | ||
| 348 | "wasi/libc-top-half/musl/src/misc/basename.c", | ||
| 349 | "wasi/libc-top-half/musl/src/misc/dirname.c", | ||
| 350 | "wasi/libc-top-half/musl/src/misc/ffs.c", | ||
| 351 | "wasi/libc-top-half/musl/src/misc/ffsl.c", | ||
| 352 | "wasi/libc-top-half/musl/src/misc/ffsll.c", | ||
| 353 | "wasi/libc-top-half/musl/src/misc/fmtmsg.c", | ||
| 354 | "wasi/libc-top-half/musl/src/misc/getdomainname.c", | ||
| 355 | "wasi/libc-top-half/musl/src/misc/gethostid.c", | ||
| 356 | "wasi/libc-top-half/musl/src/misc/getopt.c", | ||
| 357 | "wasi/libc-top-half/musl/src/misc/getopt_long.c", | ||
| 358 | "wasi/libc-top-half/musl/src/misc/getsubopt.c", | ||
| 359 | "wasi/libc-top-half/musl/src/misc/uname.c", | ||
| 360 | "wasi/libc-top-half/musl/src/misc/nftw.c", | ||
| 361 | "wasi/libc-top-half/musl/src/errno/strerror.c", | ||
| 362 | "wasi/libc-top-half/musl/src/network/htonl.c", | ||
| 363 | "wasi/libc-top-half/musl/src/network/htons.c", | ||
| 364 | "wasi/libc-top-half/musl/src/network/ntohl.c", | ||
| 365 | "wasi/libc-top-half/musl/src/network/ntohs.c", | ||
| 366 | "wasi/libc-top-half/musl/src/network/inet_ntop.c", | ||
| 367 | "wasi/libc-top-half/musl/src/network/inet_pton.c", | ||
| 368 | "wasi/libc-top-half/musl/src/network/inet_aton.c", | ||
| 369 | "wasi/libc-top-half/musl/src/network/in6addr_any.c", | ||
| 370 | "wasi/libc-top-half/musl/src/network/in6addr_loopback.c", | ||
| 371 | "wasi/libc-top-half/musl/src/fenv/fenv.c", | ||
| 372 | "wasi/libc-top-half/musl/src/fenv/fesetround.c", | ||
| 373 | "wasi/libc-top-half/musl/src/fenv/feupdateenv.c", | ||
| 374 | "wasi/libc-top-half/musl/src/fenv/fesetexceptflag.c", | ||
| 375 | "wasi/libc-top-half/musl/src/fenv/fegetexceptflag.c", | ||
| 376 | "wasi/libc-top-half/musl/src/fenv/feholdexcept.c", | ||
| 377 | "wasi/libc-top-half/musl/src/exit/exit.c", | ||
| 378 | "wasi/libc-top-half/musl/src/exit/atexit.c", | ||
| 379 | "wasi/libc-top-half/musl/src/exit/assert.c", | ||
| 380 | "wasi/libc-top-half/musl/src/exit/quick_exit.c", | ||
| 381 | "wasi/libc-top-half/musl/src/exit/at_quick_exit.c", | ||
| 382 | "wasi/libc-top-half/musl/src/time/strftime.c", | ||
| 383 | "wasi/libc-top-half/musl/src/time/asctime.c", | ||
| 384 | "wasi/libc-top-half/musl/src/time/asctime_r.c", | ||
| 385 | "wasi/libc-top-half/musl/src/time/ctime.c", | ||
| 386 | "wasi/libc-top-half/musl/src/time/ctime_r.c", | ||
| 387 | "wasi/libc-top-half/musl/src/time/wcsftime.c", | ||
| 388 | "wasi/libc-top-half/musl/src/time/strptime.c", | ||
| 389 | "wasi/libc-top-half/musl/src/time/difftime.c", | ||
| 390 | "wasi/libc-top-half/musl/src/time/timegm.c", | ||
| 391 | "wasi/libc-top-half/musl/src/time/ftime.c", | ||
| 392 | "wasi/libc-top-half/musl/src/time/gmtime.c", | ||
| 393 | "wasi/libc-top-half/musl/src/time/gmtime_r.c", | ||
| 394 | "wasi/libc-top-half/musl/src/time/timespec_get.c", | ||
| 395 | "wasi/libc-top-half/musl/src/time/getdate.c", | ||
| 396 | "wasi/libc-top-half/musl/src/time/localtime.c", | ||
| 397 | "wasi/libc-top-half/musl/src/time/localtime_r.c", | ||
| 398 | "wasi/libc-top-half/musl/src/time/mktime.c", | ||
| 399 | "wasi/libc-top-half/musl/src/time/__tm_to_secs.c", | ||
| 400 | "wasi/libc-top-half/musl/src/time/__month_to_secs.c", | ||
| 401 | "wasi/libc-top-half/musl/src/time/__secs_to_tm.c", | ||
| 402 | "wasi/libc-top-half/musl/src/time/__year_to_secs.c", | ||
| 403 | "wasi/libc-top-half/musl/src/time/__tz.c", | ||
| 404 | "wasi/libc-top-half/musl/src/fcntl/creat.c", | ||
| 405 | "wasi/libc-top-half/musl/src/dirent/alphasort.c", | ||
| 406 | "wasi/libc-top-half/musl/src/dirent/versionsort.c", | ||
| 407 | "wasi/libc-top-half/musl/src/env/clearenv.c", | ||
| 408 | "wasi/libc-top-half/musl/src/env/getenv.c", | ||
| 409 | "wasi/libc-top-half/musl/src/env/putenv.c", | ||
| 410 | "wasi/libc-top-half/musl/src/env/setenv.c", | ||
| 411 | "wasi/libc-top-half/musl/src/env/unsetenv.c", | ||
| 412 | "wasi/libc-top-half/musl/src/unistd/posix_close.c", | ||
| 413 | "wasi/libc-top-half/musl/src/internal/defsysinfo.c", | ||
| 414 | "wasi/libc-top-half/musl/src/internal/floatscan.c", | ||
| 415 | "wasi/libc-top-half/musl/src/internal/intscan.c", | ||
| 416 | "wasi/libc-top-half/musl/src/internal/libc.c", | ||
| 417 | "wasi/libc-top-half/musl/src/internal/shgetc.c", | ||
| 418 | "wasi/libc-top-half/musl/src/stdio/asprintf.c", | ||
| 419 | "wasi/libc-top-half/musl/src/stdio/clearerr.c", | ||
| 420 | "wasi/libc-top-half/musl/src/stdio/dprintf.c", | ||
| 421 | "wasi/libc-top-half/musl/src/stdio/ext2.c", | ||
| 422 | "wasi/libc-top-half/musl/src/stdio/ext.c", | ||
| 423 | "wasi/libc-top-half/musl/src/stdio/fclose.c", | ||
| 424 | "wasi/libc-top-half/musl/src/stdio/__fclose_ca.c", | ||
| 425 | "wasi/libc-top-half/musl/src/stdio/__fdopen.c", | ||
| 426 | "wasi/libc-top-half/musl/src/stdio/feof.c", | ||
| 427 | "wasi/libc-top-half/musl/src/stdio/ferror.c", | ||
| 428 | "wasi/libc-top-half/musl/src/stdio/fflush.c", | ||
| 429 | "wasi/libc-top-half/musl/src/stdio/fgetc.c", | ||
| 430 | "wasi/libc-top-half/musl/src/stdio/fgetln.c", | ||
| 431 | "wasi/libc-top-half/musl/src/stdio/fgetpos.c", | ||
| 432 | "wasi/libc-top-half/musl/src/stdio/fgets.c", | ||
| 433 | "wasi/libc-top-half/musl/src/stdio/fgetwc.c", | ||
| 434 | "wasi/libc-top-half/musl/src/stdio/fgetws.c", | ||
| 435 | "wasi/libc-top-half/musl/src/stdio/fileno.c", | ||
| 436 | "wasi/libc-top-half/musl/src/stdio/fmemopen.c", | ||
| 437 | "wasi/libc-top-half/musl/src/stdio/__fmodeflags.c", | ||
| 438 | "wasi/libc-top-half/musl/src/stdio/fopen.c", | ||
| 439 | "wasi/libc-top-half/musl/src/stdio/fopencookie.c", | ||
| 440 | "wasi/libc-top-half/musl/src/stdio/__fopen_rb_ca.c", | ||
| 441 | "wasi/libc-top-half/musl/src/stdio/fprintf.c", | ||
| 442 | "wasi/libc-top-half/musl/src/stdio/fputc.c", | ||
| 443 | "wasi/libc-top-half/musl/src/stdio/fputs.c", | ||
| 444 | "wasi/libc-top-half/musl/src/stdio/fputwc.c", | ||
| 445 | "wasi/libc-top-half/musl/src/stdio/fputws.c", | ||
| 446 | "wasi/libc-top-half/musl/src/stdio/fread.c", | ||
| 447 | "wasi/libc-top-half/musl/src/stdio/freopen.c", | ||
| 448 | "wasi/libc-top-half/musl/src/stdio/fscanf.c", | ||
| 449 | "wasi/libc-top-half/musl/src/stdio/fseek.c", | ||
| 450 | "wasi/libc-top-half/musl/src/stdio/fsetpos.c", | ||
| 451 | "wasi/libc-top-half/musl/src/stdio/ftell.c", | ||
| 452 | "wasi/libc-top-half/musl/src/stdio/fwide.c", | ||
| 453 | "wasi/libc-top-half/musl/src/stdio/fwprintf.c", | ||
| 454 | "wasi/libc-top-half/musl/src/stdio/fwrite.c", | ||
| 455 | "wasi/libc-top-half/musl/src/stdio/fwscanf.c", | ||
| 456 | "wasi/libc-top-half/musl/src/stdio/getc.c", | ||
| 457 | "wasi/libc-top-half/musl/src/stdio/getchar.c", | ||
| 458 | "wasi/libc-top-half/musl/src/stdio/getchar_unlocked.c", | ||
| 459 | "wasi/libc-top-half/musl/src/stdio/getc_unlocked.c", | ||
| 460 | "wasi/libc-top-half/musl/src/stdio/getdelim.c", | ||
| 461 | "wasi/libc-top-half/musl/src/stdio/getline.c", | ||
| 462 | "wasi/libc-top-half/musl/src/stdio/getw.c", | ||
| 463 | "wasi/libc-top-half/musl/src/stdio/getwc.c", | ||
| 464 | "wasi/libc-top-half/musl/src/stdio/getwchar.c", | ||
| 465 | "wasi/libc-top-half/musl/src/stdio/ofl_add.c", | ||
| 466 | "wasi/libc-top-half/musl/src/stdio/ofl.c", | ||
| 467 | "wasi/libc-top-half/musl/src/stdio/open_memstream.c", | ||
| 468 | "wasi/libc-top-half/musl/src/stdio/open_wmemstream.c", | ||
| 469 | "wasi/libc-top-half/musl/src/stdio/__overflow.c", | ||
| 470 | "wasi/libc-top-half/musl/src/stdio/perror.c", | ||
| 471 | "wasi/libc-top-half/musl/src/stdio/printf.c", | ||
| 472 | "wasi/libc-top-half/musl/src/stdio/putc.c", | ||
| 473 | "wasi/libc-top-half/musl/src/stdio/putchar.c", | ||
| 474 | "wasi/libc-top-half/musl/src/stdio/putchar_unlocked.c", | ||
| 475 | "wasi/libc-top-half/musl/src/stdio/putc_unlocked.c", | ||
| 476 | "wasi/libc-top-half/musl/src/stdio/puts.c", | ||
| 477 | "wasi/libc-top-half/musl/src/stdio/putw.c", | ||
| 478 | "wasi/libc-top-half/musl/src/stdio/putwc.c", | ||
| 479 | "wasi/libc-top-half/musl/src/stdio/putwchar.c", | ||
| 480 | "wasi/libc-top-half/musl/src/stdio/rewind.c", | ||
| 481 | "wasi/libc-top-half/musl/src/stdio/scanf.c", | ||
| 482 | "wasi/libc-top-half/musl/src/stdio/setbuf.c", | ||
| 483 | "wasi/libc-top-half/musl/src/stdio/setbuffer.c", | ||
| 484 | "wasi/libc-top-half/musl/src/stdio/setlinebuf.c", | ||
| 485 | "wasi/libc-top-half/musl/src/stdio/setvbuf.c", | ||
| 486 | "wasi/libc-top-half/musl/src/stdio/snprintf.c", | ||
| 487 | "wasi/libc-top-half/musl/src/stdio/sprintf.c", | ||
| 488 | "wasi/libc-top-half/musl/src/stdio/sscanf.c", | ||
| 489 | "wasi/libc-top-half/musl/src/stdio/stderr.c", | ||
| 490 | "wasi/libc-top-half/musl/src/stdio/stdin.c", | ||
| 491 | "wasi/libc-top-half/musl/src/stdio/__stdio_close.c", | ||
| 492 | "wasi/libc-top-half/musl/src/stdio/__stdio_exit.c", | ||
| 493 | "wasi/libc-top-half/musl/src/stdio/__stdio_read.c", | ||
| 494 | "wasi/libc-top-half/musl/src/stdio/__stdio_seek.c", | ||
| 495 | "wasi/libc-top-half/musl/src/stdio/__stdio_write.c", | ||
| 496 | "wasi/libc-top-half/musl/src/stdio/stdout.c", | ||
| 497 | "wasi/libc-top-half/musl/src/stdio/__stdout_write.c", | ||
| 498 | "wasi/libc-top-half/musl/src/stdio/swprintf.c", | ||
| 499 | "wasi/libc-top-half/musl/src/stdio/swscanf.c", | ||
| 500 | "wasi/libc-top-half/musl/src/stdio/__toread.c", | ||
| 501 | "wasi/libc-top-half/musl/src/stdio/__towrite.c", | ||
| 502 | "wasi/libc-top-half/musl/src/stdio/__uflow.c", | ||
| 503 | "wasi/libc-top-half/musl/src/stdio/ungetc.c", | ||
| 504 | "wasi/libc-top-half/musl/src/stdio/ungetwc.c", | ||
| 505 | "wasi/libc-top-half/musl/src/stdio/vasprintf.c", | ||
| 506 | "wasi/libc-top-half/musl/src/stdio/vdprintf.c", | ||
| 507 | "wasi/libc-top-half/musl/src/stdio/vfprintf.c", | ||
| 508 | "wasi/libc-top-half/musl/src/stdio/vfscanf.c", | ||
| 509 | "wasi/libc-top-half/musl/src/stdio/vfwprintf.c", | ||
| 510 | "wasi/libc-top-half/musl/src/stdio/vfwscanf.c", | ||
| 511 | "wasi/libc-top-half/musl/src/stdio/vprintf.c", | ||
| 512 | "wasi/libc-top-half/musl/src/stdio/vscanf.c", | ||
| 513 | "wasi/libc-top-half/musl/src/stdio/vsnprintf.c", | ||
| 514 | "wasi/libc-top-half/musl/src/stdio/vsprintf.c", | ||
| 515 | "wasi/libc-top-half/musl/src/stdio/vsscanf.c", | ||
| 516 | "wasi/libc-top-half/musl/src/stdio/vswprintf.c", | ||
| 517 | "wasi/libc-top-half/musl/src/stdio/vswscanf.c", | ||
| 518 | "wasi/libc-top-half/musl/src/stdio/vwprintf.c", | ||
| 519 | "wasi/libc-top-half/musl/src/stdio/vwscanf.c", | ||
| 520 | "wasi/libc-top-half/musl/src/stdio/wprintf.c", | ||
| 521 | "wasi/libc-top-half/musl/src/stdio/wscanf.c", | ||
| 522 | "wasi/libc-top-half/musl/src/string/bcmp.c", | ||
| 523 | "wasi/libc-top-half/musl/src/string/bcopy.c", | ||
| 524 | "wasi/libc-top-half/musl/src/string/bzero.c", | ||
| 525 | "wasi/libc-top-half/musl/src/string/explicit_bzero.c", | ||
| 526 | "wasi/libc-top-half/musl/src/string/index.c", | ||
| 527 | "wasi/libc-top-half/musl/src/string/memccpy.c", | ||
| 528 | "wasi/libc-top-half/musl/src/string/memchr.c", | ||
| 529 | "wasi/libc-top-half/musl/src/string/memcmp.c", | ||
| 530 | "wasi/libc-top-half/musl/src/string/memcpy.c", | ||
| 531 | "wasi/libc-top-half/musl/src/string/memmem.c", | ||
| 532 | "wasi/libc-top-half/musl/src/string/memmove.c", | ||
| 533 | "wasi/libc-top-half/musl/src/string/mempcpy.c", | ||
| 534 | "wasi/libc-top-half/musl/src/string/memrchr.c", | ||
| 535 | "wasi/libc-top-half/musl/src/string/memset.c", | ||
| 536 | "wasi/libc-top-half/musl/src/string/rindex.c", | ||
| 537 | "wasi/libc-top-half/musl/src/string/stpcpy.c", | ||
| 538 | "wasi/libc-top-half/musl/src/string/stpncpy.c", | ||
| 539 | "wasi/libc-top-half/musl/src/string/strcasecmp.c", | ||
| 540 | "wasi/libc-top-half/musl/src/string/strcasestr.c", | ||
| 541 | "wasi/libc-top-half/musl/src/string/strcat.c", | ||
| 542 | "wasi/libc-top-half/musl/src/string/strchr.c", | ||
| 543 | "wasi/libc-top-half/musl/src/string/strchrnul.c", | ||
| 544 | "wasi/libc-top-half/musl/src/string/strcmp.c", | ||
| 545 | "wasi/libc-top-half/musl/src/string/strcpy.c", | ||
| 546 | "wasi/libc-top-half/musl/src/string/strcspn.c", | ||
| 547 | "wasi/libc-top-half/musl/src/string/strdup.c", | ||
| 548 | "wasi/libc-top-half/musl/src/string/strerror_r.c", | ||
| 549 | "wasi/libc-top-half/musl/src/string/strlcat.c", | ||
| 550 | "wasi/libc-top-half/musl/src/string/strlcpy.c", | ||
| 551 | "wasi/libc-top-half/musl/src/string/strlen.c", | ||
| 552 | "wasi/libc-top-half/musl/src/string/strncasecmp.c", | ||
| 553 | "wasi/libc-top-half/musl/src/string/strncat.c", | ||
| 554 | "wasi/libc-top-half/musl/src/string/strncmp.c", | ||
| 555 | "wasi/libc-top-half/musl/src/string/strncpy.c", | ||
| 556 | "wasi/libc-top-half/musl/src/string/strndup.c", | ||
| 557 | "wasi/libc-top-half/musl/src/string/strnlen.c", | ||
| 558 | "wasi/libc-top-half/musl/src/string/strpbrk.c", | ||
| 559 | "wasi/libc-top-half/musl/src/string/strrchr.c", | ||
| 560 | "wasi/libc-top-half/musl/src/string/strsep.c", | ||
| 561 | "wasi/libc-top-half/musl/src/string/strspn.c", | ||
| 562 | "wasi/libc-top-half/musl/src/string/strstr.c", | ||
| 563 | "wasi/libc-top-half/musl/src/string/strtok.c", | ||
| 564 | "wasi/libc-top-half/musl/src/string/strtok_r.c", | ||
| 565 | "wasi/libc-top-half/musl/src/string/strverscmp.c", | ||
| 566 | "wasi/libc-top-half/musl/src/string/swab.c", | ||
| 567 | "wasi/libc-top-half/musl/src/string/wcpcpy.c", | ||
| 568 | "wasi/libc-top-half/musl/src/string/wcpncpy.c", | ||
| 569 | "wasi/libc-top-half/musl/src/string/wcscasecmp.c", | ||
| 570 | "wasi/libc-top-half/musl/src/string/wcscasecmp_l.c", | ||
| 571 | "wasi/libc-top-half/musl/src/string/wcscat.c", | ||
| 572 | "wasi/libc-top-half/musl/src/string/wcschr.c", | ||
| 573 | "wasi/libc-top-half/musl/src/string/wcscmp.c", | ||
| 574 | "wasi/libc-top-half/musl/src/string/wcscpy.c", | ||
| 575 | "wasi/libc-top-half/musl/src/string/wcscspn.c", | ||
| 576 | "wasi/libc-top-half/musl/src/string/wcsdup.c", | ||
| 577 | "wasi/libc-top-half/musl/src/string/wcslen.c", | ||
| 578 | "wasi/libc-top-half/musl/src/string/wcsncasecmp.c", | ||
| 579 | "wasi/libc-top-half/musl/src/string/wcsncasecmp_l.c", | ||
| 580 | "wasi/libc-top-half/musl/src/string/wcsncat.c", | ||
| 581 | "wasi/libc-top-half/musl/src/string/wcsncmp.c", | ||
| 582 | "wasi/libc-top-half/musl/src/string/wcsncpy.c", | ||
| 583 | "wasi/libc-top-half/musl/src/string/wcsnlen.c", | ||
| 584 | "wasi/libc-top-half/musl/src/string/wcspbrk.c", | ||
| 585 | "wasi/libc-top-half/musl/src/string/wcsrchr.c", | ||
| 586 | "wasi/libc-top-half/musl/src/string/wcsspn.c", | ||
| 587 | "wasi/libc-top-half/musl/src/string/wcsstr.c", | ||
| 588 | "wasi/libc-top-half/musl/src/string/wcstok.c", | ||
| 589 | "wasi/libc-top-half/musl/src/string/wcswcs.c", | ||
| 590 | "wasi/libc-top-half/musl/src/string/wmemchr.c", | ||
| 591 | "wasi/libc-top-half/musl/src/string/wmemcmp.c", | ||
| 592 | "wasi/libc-top-half/musl/src/string/wmemcpy.c", | ||
| 593 | "wasi/libc-top-half/musl/src/string/wmemmove.c", | ||
| 594 | "wasi/libc-top-half/musl/src/string/wmemset.c", | ||
| 595 | "wasi/libc-top-half/musl/src/locale/catclose.c", | ||
| 596 | "wasi/libc-top-half/musl/src/locale/catgets.c", | ||
| 597 | "wasi/libc-top-half/musl/src/locale/catopen.c", | ||
| 598 | "wasi/libc-top-half/musl/src/locale/c_locale.c", | ||
| 599 | "wasi/libc-top-half/musl/src/locale/duplocale.c", | ||
| 600 | "wasi/libc-top-half/musl/src/locale/freelocale.c", | ||
| 601 | "wasi/libc-top-half/musl/src/locale/iconv.c", | ||
| 602 | "wasi/libc-top-half/musl/src/locale/iconv_close.c", | ||
| 603 | "wasi/libc-top-half/musl/src/locale/langinfo.c", | ||
| 604 | "wasi/libc-top-half/musl/src/locale/__lctrans.c", | ||
| 605 | "wasi/libc-top-half/musl/src/locale/localeconv.c", | ||
| 606 | "wasi/libc-top-half/musl/src/locale/locale_map.c", | ||
| 607 | "wasi/libc-top-half/musl/src/locale/__mo_lookup.c", | ||
| 608 | "wasi/libc-top-half/musl/src/locale/newlocale.c", | ||
| 609 | "wasi/libc-top-half/musl/src/locale/pleval.c", | ||
| 610 | "wasi/libc-top-half/musl/src/locale/setlocale.c", | ||
| 611 | "wasi/libc-top-half/musl/src/locale/strcoll.c", | ||
| 612 | "wasi/libc-top-half/musl/src/locale/strfmon.c", | ||
| 613 | "wasi/libc-top-half/musl/src/locale/strxfrm.c", | ||
| 614 | "wasi/libc-top-half/musl/src/locale/uselocale.c", | ||
| 615 | "wasi/libc-top-half/musl/src/locale/wcscoll.c", | ||
| 616 | "wasi/libc-top-half/musl/src/locale/wcsxfrm.c", | ||
| 617 | "wasi/libc-top-half/musl/src/stdlib/abs.c", | ||
| 618 | "wasi/libc-top-half/musl/src/stdlib/atof.c", | ||
| 619 | "wasi/libc-top-half/musl/src/stdlib/atoi.c", | ||
| 620 | "wasi/libc-top-half/musl/src/stdlib/atol.c", | ||
| 621 | "wasi/libc-top-half/musl/src/stdlib/atoll.c", | ||
| 622 | "wasi/libc-top-half/musl/src/stdlib/bsearch.c", | ||
| 623 | "wasi/libc-top-half/musl/src/stdlib/div.c", | ||
| 624 | "wasi/libc-top-half/musl/src/stdlib/ecvt.c", | ||
| 625 | "wasi/libc-top-half/musl/src/stdlib/fcvt.c", | ||
| 626 | "wasi/libc-top-half/musl/src/stdlib/gcvt.c", | ||
| 627 | "wasi/libc-top-half/musl/src/stdlib/imaxabs.c", | ||
| 628 | "wasi/libc-top-half/musl/src/stdlib/imaxdiv.c", | ||
| 629 | "wasi/libc-top-half/musl/src/stdlib/labs.c", | ||
| 630 | "wasi/libc-top-half/musl/src/stdlib/ldiv.c", | ||
| 631 | "wasi/libc-top-half/musl/src/stdlib/llabs.c", | ||
| 632 | "wasi/libc-top-half/musl/src/stdlib/lldiv.c", | ||
| 633 | "wasi/libc-top-half/musl/src/stdlib/qsort.c", | ||
| 634 | "wasi/libc-top-half/musl/src/stdlib/strtod.c", | ||
| 635 | "wasi/libc-top-half/musl/src/stdlib/strtol.c", | ||
| 636 | "wasi/libc-top-half/musl/src/stdlib/wcstod.c", | ||
| 637 | "wasi/libc-top-half/musl/src/stdlib/wcstol.c", | ||
| 638 | "wasi/libc-top-half/musl/src/search/hsearch.c", | ||
| 639 | "wasi/libc-top-half/musl/src/search/insque.c", | ||
| 640 | "wasi/libc-top-half/musl/src/search/lsearch.c", | ||
| 641 | "wasi/libc-top-half/musl/src/search/tdelete.c", | ||
| 642 | "wasi/libc-top-half/musl/src/search/tdestroy.c", | ||
| 643 | "wasi/libc-top-half/musl/src/search/tfind.c", | ||
| 644 | "wasi/libc-top-half/musl/src/search/tsearch.c", | ||
| 645 | "wasi/libc-top-half/musl/src/search/twalk.c", | ||
| 646 | "wasi/libc-top-half/musl/src/multibyte/btowc.c", | ||
| 647 | "wasi/libc-top-half/musl/src/multibyte/c16rtomb.c", | ||
| 648 | "wasi/libc-top-half/musl/src/multibyte/c32rtomb.c", | ||
| 649 | "wasi/libc-top-half/musl/src/multibyte/internal.c", | ||
| 650 | "wasi/libc-top-half/musl/src/multibyte/mblen.c", | ||
| 651 | "wasi/libc-top-half/musl/src/multibyte/mbrlen.c", | ||
| 652 | "wasi/libc-top-half/musl/src/multibyte/mbrtoc16.c", | ||
| 653 | "wasi/libc-top-half/musl/src/multibyte/mbrtoc32.c", | ||
| 654 | "wasi/libc-top-half/musl/src/multibyte/mbrtowc.c", | ||
| 655 | "wasi/libc-top-half/musl/src/multibyte/mbsinit.c", | ||
| 656 | "wasi/libc-top-half/musl/src/multibyte/mbsnrtowcs.c", | ||
| 657 | "wasi/libc-top-half/musl/src/multibyte/mbsrtowcs.c", | ||
| 658 | "wasi/libc-top-half/musl/src/multibyte/mbstowcs.c", | ||
| 659 | "wasi/libc-top-half/musl/src/multibyte/mbtowc.c", | ||
| 660 | "wasi/libc-top-half/musl/src/multibyte/wcrtomb.c", | ||
| 661 | "wasi/libc-top-half/musl/src/multibyte/wcsnrtombs.c", | ||
| 662 | "wasi/libc-top-half/musl/src/multibyte/wcsrtombs.c", | ||
| 663 | "wasi/libc-top-half/musl/src/multibyte/wcstombs.c", | ||
| 664 | "wasi/libc-top-half/musl/src/multibyte/wctob.c", | ||
| 665 | "wasi/libc-top-half/musl/src/multibyte/wctomb.c", | ||
| 666 | "wasi/libc-top-half/musl/src/regex/fnmatch.c", | ||
| 667 | "wasi/libc-top-half/musl/src/regex/glob.c", | ||
| 668 | "wasi/libc-top-half/musl/src/regex/regcomp.c", | ||
| 669 | "wasi/libc-top-half/musl/src/regex/regerror.c", | ||
| 670 | "wasi/libc-top-half/musl/src/regex/regexec.c", | ||
| 671 | "wasi/libc-top-half/musl/src/regex/tre-mem.c", | ||
| 672 | "wasi/libc-top-half/musl/src/prng/drand48.c", | ||
| 673 | "wasi/libc-top-half/musl/src/prng/lcong48.c", | ||
| 674 | "wasi/libc-top-half/musl/src/prng/lrand48.c", | ||
| 675 | "wasi/libc-top-half/musl/src/prng/mrand48.c", | ||
| 676 | "wasi/libc-top-half/musl/src/prng/__rand48_step.c", | ||
| 677 | "wasi/libc-top-half/musl/src/prng/rand.c", | ||
| 678 | "wasi/libc-top-half/musl/src/prng/random.c", | ||
| 679 | "wasi/libc-top-half/musl/src/prng/rand_r.c", | ||
| 680 | "wasi/libc-top-half/musl/src/prng/__seed48.c", | ||
| 681 | "wasi/libc-top-half/musl/src/prng/seed48.c", | ||
| 682 | "wasi/libc-top-half/musl/src/prng/srand48.c", | ||
| 683 | "wasi/libc-top-half/musl/src/conf/confstr.c", | ||
| 684 | "wasi/libc-top-half/musl/src/conf/fpathconf.c", | ||
| 685 | "wasi/libc-top-half/musl/src/conf/legacy.c", | ||
| 686 | "wasi/libc-top-half/musl/src/conf/pathconf.c", | ||
| 687 | "wasi/libc-top-half/musl/src/conf/sysconf.c", | ||
| 688 | "wasi/libc-top-half/musl/src/ctype/__ctype_b_loc.c", | ||
| 689 | "wasi/libc-top-half/musl/src/ctype/__ctype_get_mb_cur_max.c", | ||
| 690 | "wasi/libc-top-half/musl/src/ctype/__ctype_tolower_loc.c", | ||
| 691 | "wasi/libc-top-half/musl/src/ctype/__ctype_toupper_loc.c", | ||
| 692 | "wasi/libc-top-half/musl/src/ctype/isalnum.c", | ||
| 693 | "wasi/libc-top-half/musl/src/ctype/isalpha.c", | ||
| 694 | "wasi/libc-top-half/musl/src/ctype/isascii.c", | ||
| 695 | "wasi/libc-top-half/musl/src/ctype/isblank.c", | ||
| 696 | "wasi/libc-top-half/musl/src/ctype/iscntrl.c", | ||
| 697 | "wasi/libc-top-half/musl/src/ctype/isdigit.c", | ||
| 698 | "wasi/libc-top-half/musl/src/ctype/isgraph.c", | ||
| 699 | "wasi/libc-top-half/musl/src/ctype/islower.c", | ||
| 700 | "wasi/libc-top-half/musl/src/ctype/isprint.c", | ||
| 701 | "wasi/libc-top-half/musl/src/ctype/ispunct.c", | ||
| 702 | "wasi/libc-top-half/musl/src/ctype/isspace.c", | ||
| 703 | "wasi/libc-top-half/musl/src/ctype/isupper.c", | ||
| 704 | "wasi/libc-top-half/musl/src/ctype/iswalnum.c", | ||
| 705 | "wasi/libc-top-half/musl/src/ctype/iswalpha.c", | ||
| 706 | "wasi/libc-top-half/musl/src/ctype/iswblank.c", | ||
| 707 | "wasi/libc-top-half/musl/src/ctype/iswcntrl.c", | ||
| 708 | "wasi/libc-top-half/musl/src/ctype/iswctype.c", | ||
| 709 | "wasi/libc-top-half/musl/src/ctype/iswdigit.c", | ||
| 710 | "wasi/libc-top-half/musl/src/ctype/iswgraph.c", | ||
| 711 | "wasi/libc-top-half/musl/src/ctype/iswlower.c", | ||
| 712 | "wasi/libc-top-half/musl/src/ctype/iswprint.c", | ||
| 713 | "wasi/libc-top-half/musl/src/ctype/iswpunct.c", | ||
| 714 | "wasi/libc-top-half/musl/src/ctype/iswspace.c", | ||
| 715 | "wasi/libc-top-half/musl/src/ctype/iswupper.c", | ||
| 716 | "wasi/libc-top-half/musl/src/ctype/iswxdigit.c", | ||
| 717 | "wasi/libc-top-half/musl/src/ctype/isxdigit.c", | ||
| 718 | "wasi/libc-top-half/musl/src/ctype/toascii.c", | ||
| 719 | "wasi/libc-top-half/musl/src/ctype/tolower.c", | ||
| 720 | "wasi/libc-top-half/musl/src/ctype/toupper.c", | ||
| 721 | "wasi/libc-top-half/musl/src/ctype/towctrans.c", | ||
| 722 | "wasi/libc-top-half/musl/src/ctype/wcswidth.c", | ||
| 723 | "wasi/libc-top-half/musl/src/ctype/wctrans.c", | ||
| 724 | "wasi/libc-top-half/musl/src/ctype/wcwidth.c", | ||
| 725 | "wasi/libc-top-half/musl/src/math/acos.c", | ||
| 726 | "wasi/libc-top-half/musl/src/math/acosf.c", | ||
| 727 | "wasi/libc-top-half/musl/src/math/acosh.c", | ||
| 728 | "wasi/libc-top-half/musl/src/math/acoshf.c", | ||
| 729 | "wasi/libc-top-half/musl/src/math/acoshl.c", | ||
| 730 | "wasi/libc-top-half/musl/src/math/acosl.c", | ||
| 731 | "wasi/libc-top-half/musl/src/math/asin.c", | ||
| 732 | "wasi/libc-top-half/musl/src/math/asinf.c", | ||
| 733 | "wasi/libc-top-half/musl/src/math/asinh.c", | ||
| 734 | "wasi/libc-top-half/musl/src/math/asinhf.c", | ||
| 735 | "wasi/libc-top-half/musl/src/math/asinhl.c", | ||
| 736 | "wasi/libc-top-half/musl/src/math/asinl.c", | ||
| 737 | "wasi/libc-top-half/musl/src/math/atan2.c", | ||
| 738 | "wasi/libc-top-half/musl/src/math/atan2f.c", | ||
| 739 | "wasi/libc-top-half/musl/src/math/atan2l.c", | ||
| 740 | "wasi/libc-top-half/musl/src/math/atan.c", | ||
| 741 | "wasi/libc-top-half/musl/src/math/atanf.c", | ||
| 742 | "wasi/libc-top-half/musl/src/math/atanh.c", | ||
| 743 | "wasi/libc-top-half/musl/src/math/atanhf.c", | ||
| 744 | "wasi/libc-top-half/musl/src/math/atanhl.c", | ||
| 745 | "wasi/libc-top-half/musl/src/math/atanl.c", | ||
| 746 | "wasi/libc-top-half/musl/src/math/cbrt.c", | ||
| 747 | "wasi/libc-top-half/musl/src/math/cbrtf.c", | ||
| 748 | "wasi/libc-top-half/musl/src/math/cbrtl.c", | ||
| 749 | "wasi/libc-top-half/musl/src/math/ceill.c", | ||
| 750 | "wasi/libc-top-half/musl/src/math/copysignl.c", | ||
| 751 | "wasi/libc-top-half/musl/src/math/__cos.c", | ||
| 752 | "wasi/libc-top-half/musl/src/math/cos.c", | ||
| 753 | "wasi/libc-top-half/musl/src/math/__cosdf.c", | ||
| 754 | "wasi/libc-top-half/musl/src/math/cosf.c", | ||
| 755 | "wasi/libc-top-half/musl/src/math/cosh.c", | ||
| 756 | "wasi/libc-top-half/musl/src/math/coshf.c", | ||
| 757 | "wasi/libc-top-half/musl/src/math/coshl.c", | ||
| 758 | "wasi/libc-top-half/musl/src/math/__cosl.c", | ||
| 759 | "wasi/libc-top-half/musl/src/math/cosl.c", | ||
| 760 | "wasi/libc-top-half/musl/src/math/erf.c", | ||
| 761 | "wasi/libc-top-half/musl/src/math/erff.c", | ||
| 762 | "wasi/libc-top-half/musl/src/math/erfl.c", | ||
| 763 | "wasi/libc-top-half/musl/src/math/exp10.c", | ||
| 764 | "wasi/libc-top-half/musl/src/math/exp10f.c", | ||
| 765 | "wasi/libc-top-half/musl/src/math/exp10l.c", | ||
| 766 | "wasi/libc-top-half/musl/src/math/exp2.c", | ||
| 767 | "wasi/libc-top-half/musl/src/math/exp2f.c", | ||
| 768 | "wasi/libc-top-half/musl/src/math/exp2f_data.c", | ||
| 769 | "wasi/libc-top-half/musl/src/math/exp2l.c", | ||
| 770 | "wasi/libc-top-half/musl/src/math/exp.c", | ||
| 771 | "wasi/libc-top-half/musl/src/math/exp_data.c", | ||
| 772 | "wasi/libc-top-half/musl/src/math/expf.c", | ||
| 773 | "wasi/libc-top-half/musl/src/math/expl.c", | ||
| 774 | "wasi/libc-top-half/musl/src/math/expm1.c", | ||
| 775 | "wasi/libc-top-half/musl/src/math/expm1f.c", | ||
| 776 | "wasi/libc-top-half/musl/src/math/expm1l.c", | ||
| 777 | "wasi/libc-top-half/musl/src/math/__expo2.c", | ||
| 778 | "wasi/libc-top-half/musl/src/math/__expo2f.c", | ||
| 779 | "wasi/libc-top-half/musl/src/math/fabsl.c", | ||
| 780 | "wasi/libc-top-half/musl/src/math/fdim.c", | ||
| 781 | "wasi/libc-top-half/musl/src/math/fdimf.c", | ||
| 782 | "wasi/libc-top-half/musl/src/math/fdiml.c", | ||
| 783 | "wasi/libc-top-half/musl/src/math/finite.c", | ||
| 784 | "wasi/libc-top-half/musl/src/math/finitef.c", | ||
| 785 | "wasi/libc-top-half/musl/src/math/floorl.c", | ||
| 786 | "wasi/libc-top-half/musl/src/math/fma.c", | ||
| 787 | "wasi/libc-top-half/musl/src/math/fmaf.c", | ||
| 788 | "wasi/libc-top-half/musl/src/math/fmal.c", | ||
| 789 | "wasi/libc-top-half/musl/src/math/fmaxl.c", | ||
| 790 | "wasi/libc-top-half/musl/src/math/fminl.c", | ||
| 791 | "wasi/libc-top-half/musl/src/math/fmod.c", | ||
| 792 | "wasi/libc-top-half/musl/src/math/fmodf.c", | ||
| 793 | "wasi/libc-top-half/musl/src/math/fmodl.c", | ||
| 794 | "wasi/libc-top-half/musl/src/math/frexp.c", | ||
| 795 | "wasi/libc-top-half/musl/src/math/frexpf.c", | ||
| 796 | "wasi/libc-top-half/musl/src/math/frexpl.c", | ||
| 797 | "wasi/libc-top-half/musl/src/math/hypot.c", | ||
| 798 | "wasi/libc-top-half/musl/src/math/hypotf.c", | ||
| 799 | "wasi/libc-top-half/musl/src/math/hypotl.c", | ||
| 800 | "wasi/libc-top-half/musl/src/math/ilogb.c", | ||
| 801 | "wasi/libc-top-half/musl/src/math/ilogbf.c", | ||
| 802 | "wasi/libc-top-half/musl/src/math/ilogbl.c", | ||
| 803 | "wasi/libc-top-half/musl/src/math/__invtrigl.c", | ||
| 804 | "wasi/libc-top-half/musl/src/math/j0.c", | ||
| 805 | "wasi/libc-top-half/musl/src/math/j0f.c", | ||
| 806 | "wasi/libc-top-half/musl/src/math/j1.c", | ||
| 807 | "wasi/libc-top-half/musl/src/math/j1f.c", | ||
| 808 | "wasi/libc-top-half/musl/src/math/jn.c", | ||
| 809 | "wasi/libc-top-half/musl/src/math/jnf.c", | ||
| 810 | "wasi/libc-top-half/musl/src/math/ldexp.c", | ||
| 811 | "wasi/libc-top-half/musl/src/math/ldexpf.c", | ||
| 812 | "wasi/libc-top-half/musl/src/math/ldexpl.c", | ||
| 813 | "wasi/libc-top-half/musl/src/math/lgamma.c", | ||
| 814 | "wasi/libc-top-half/musl/src/math/lgammaf.c", | ||
| 815 | "wasi/libc-top-half/musl/src/math/lgammaf_r.c", | ||
| 816 | "wasi/libc-top-half/musl/src/math/lgammal.c", | ||
| 817 | "wasi/libc-top-half/musl/src/math/lgamma_r.c", | ||
| 818 | "wasi/libc-top-half/musl/src/math/llrint.c", | ||
| 819 | "wasi/libc-top-half/musl/src/math/llrintf.c", | ||
| 820 | "wasi/libc-top-half/musl/src/math/llrintl.c", | ||
| 821 | "wasi/libc-top-half/musl/src/math/llround.c", | ||
| 822 | "wasi/libc-top-half/musl/src/math/llroundf.c", | ||
| 823 | "wasi/libc-top-half/musl/src/math/llroundl.c", | ||
| 824 | "wasi/libc-top-half/musl/src/math/log10.c", | ||
| 825 | "wasi/libc-top-half/musl/src/math/log10f.c", | ||
| 826 | "wasi/libc-top-half/musl/src/math/log10l.c", | ||
| 827 | "wasi/libc-top-half/musl/src/math/log1p.c", | ||
| 828 | "wasi/libc-top-half/musl/src/math/log1pf.c", | ||
| 829 | "wasi/libc-top-half/musl/src/math/log1pl.c", | ||
| 830 | "wasi/libc-top-half/musl/src/math/log2.c", | ||
| 831 | "wasi/libc-top-half/musl/src/math/log2_data.c", | ||
| 832 | "wasi/libc-top-half/musl/src/math/log2f.c", | ||
| 833 | "wasi/libc-top-half/musl/src/math/log2f_data.c", | ||
| 834 | "wasi/libc-top-half/musl/src/math/log2l.c", | ||
| 835 | "wasi/libc-top-half/musl/src/math/logb.c", | ||
| 836 | "wasi/libc-top-half/musl/src/math/logbf.c", | ||
| 837 | "wasi/libc-top-half/musl/src/math/logbl.c", | ||
| 838 | "wasi/libc-top-half/musl/src/math/log.c", | ||
| 839 | "wasi/libc-top-half/musl/src/math/log_data.c", | ||
| 840 | "wasi/libc-top-half/musl/src/math/logf.c", | ||
| 841 | "wasi/libc-top-half/musl/src/math/logf_data.c", | ||
| 842 | "wasi/libc-top-half/musl/src/math/logl.c", | ||
| 843 | "wasi/libc-top-half/musl/src/math/lrint.c", | ||
| 844 | "wasi/libc-top-half/musl/src/math/lrintf.c", | ||
| 845 | "wasi/libc-top-half/musl/src/math/lrintl.c", | ||
| 846 | "wasi/libc-top-half/musl/src/math/lround.c", | ||
| 847 | "wasi/libc-top-half/musl/src/math/lroundf.c", | ||
| 848 | "wasi/libc-top-half/musl/src/math/lroundl.c", | ||
| 849 | "wasi/libc-top-half/musl/src/math/__math_divzero.c", | ||
| 850 | "wasi/libc-top-half/musl/src/math/__math_divzerof.c", | ||
| 851 | "wasi/libc-top-half/musl/src/math/__math_invalid.c", | ||
| 852 | "wasi/libc-top-half/musl/src/math/__math_invalidf.c", | ||
| 853 | "wasi/libc-top-half/musl/src/math/__math_invalidl.c", | ||
| 854 | "wasi/libc-top-half/musl/src/math/__math_oflow.c", | ||
| 855 | "wasi/libc-top-half/musl/src/math/__math_oflowf.c", | ||
| 856 | "wasi/libc-top-half/musl/src/math/__math_uflow.c", | ||
| 857 | "wasi/libc-top-half/musl/src/math/__math_uflowf.c", | ||
| 858 | "wasi/libc-top-half/musl/src/math/__math_xflow.c", | ||
| 859 | "wasi/libc-top-half/musl/src/math/__math_xflowf.c", | ||
| 860 | "wasi/libc-top-half/musl/src/math/modf.c", | ||
| 861 | "wasi/libc-top-half/musl/src/math/modff.c", | ||
| 862 | "wasi/libc-top-half/musl/src/math/modfl.c", | ||
| 863 | "wasi/libc-top-half/musl/src/math/nan.c", | ||
| 864 | "wasi/libc-top-half/musl/src/math/nanf.c", | ||
| 865 | "wasi/libc-top-half/musl/src/math/nanl.c", | ||
| 866 | "wasi/libc-top-half/musl/src/math/nearbyintl.c", | ||
| 867 | "wasi/libc-top-half/musl/src/math/nextafter.c", | ||
| 868 | "wasi/libc-top-half/musl/src/math/nextafterf.c", | ||
| 869 | "wasi/libc-top-half/musl/src/math/nextafterl.c", | ||
| 870 | "wasi/libc-top-half/musl/src/math/nexttoward.c", | ||
| 871 | "wasi/libc-top-half/musl/src/math/nexttowardf.c", | ||
| 872 | "wasi/libc-top-half/musl/src/math/nexttowardl.c", | ||
| 873 | "wasi/libc-top-half/musl/src/math/__polevll.c", | ||
| 874 | "wasi/libc-top-half/musl/src/math/pow.c", | ||
| 875 | "wasi/libc-top-half/musl/src/math/pow_data.c", | ||
| 876 | "wasi/libc-top-half/musl/src/math/powf.c", | ||
| 877 | "wasi/libc-top-half/musl/src/math/powf_data.c", | ||
| 878 | "wasi/libc-top-half/musl/src/math/powl.c", | ||
| 879 | "wasi/libc-top-half/musl/src/math/remainder.c", | ||
| 880 | "wasi/libc-top-half/musl/src/math/remainderf.c", | ||
| 881 | "wasi/libc-top-half/musl/src/math/remainderl.c", | ||
| 882 | "wasi/libc-top-half/musl/src/math/__rem_pio2.c", | ||
| 883 | "wasi/libc-top-half/musl/src/math/__rem_pio2f.c", | ||
| 884 | "wasi/libc-top-half/musl/src/math/__rem_pio2_large.c", | ||
| 885 | "wasi/libc-top-half/musl/src/math/__rem_pio2l.c", | ||
| 886 | "wasi/libc-top-half/musl/src/math/remquo.c", | ||
| 887 | "wasi/libc-top-half/musl/src/math/remquof.c", | ||
| 888 | "wasi/libc-top-half/musl/src/math/remquol.c", | ||
| 889 | "wasi/libc-top-half/musl/src/math/rintl.c", | ||
| 890 | "wasi/libc-top-half/musl/src/math/round.c", | ||
| 891 | "wasi/libc-top-half/musl/src/math/roundf.c", | ||
| 892 | "wasi/libc-top-half/musl/src/math/roundl.c", | ||
| 893 | "wasi/libc-top-half/musl/src/math/scalb.c", | ||
| 894 | "wasi/libc-top-half/musl/src/math/scalbf.c", | ||
| 895 | "wasi/libc-top-half/musl/src/math/scalbln.c", | ||
| 896 | "wasi/libc-top-half/musl/src/math/scalblnf.c", | ||
| 897 | "wasi/libc-top-half/musl/src/math/scalblnl.c", | ||
| 898 | "wasi/libc-top-half/musl/src/math/scalbn.c", | ||
| 899 | "wasi/libc-top-half/musl/src/math/scalbnf.c", | ||
| 900 | "wasi/libc-top-half/musl/src/math/scalbnl.c", | ||
| 901 | "wasi/libc-top-half/musl/src/math/signgam.c", | ||
| 902 | "wasi/libc-top-half/musl/src/math/significand.c", | ||
| 903 | "wasi/libc-top-half/musl/src/math/significandf.c", | ||
| 904 | "wasi/libc-top-half/musl/src/math/__sin.c", | ||
| 905 | "wasi/libc-top-half/musl/src/math/sin.c", | ||
| 906 | "wasi/libc-top-half/musl/src/math/sincos.c", | ||
| 907 | "wasi/libc-top-half/musl/src/math/sincosf.c", | ||
| 908 | "wasi/libc-top-half/musl/src/math/sincosl.c", | ||
| 909 | "wasi/libc-top-half/musl/src/math/__sindf.c", | ||
| 910 | "wasi/libc-top-half/musl/src/math/sinf.c", | ||
| 911 | "wasi/libc-top-half/musl/src/math/sinh.c", | ||
| 912 | "wasi/libc-top-half/musl/src/math/sinhf.c", | ||
| 913 | "wasi/libc-top-half/musl/src/math/sinhl.c", | ||
| 914 | "wasi/libc-top-half/musl/src/math/__sinl.c", | ||
| 915 | "wasi/libc-top-half/musl/src/math/sinl.c", | ||
| 916 | "wasi/libc-top-half/musl/src/math/sqrt_data.c", | ||
| 917 | "wasi/libc-top-half/musl/src/math/sqrtl.c", | ||
| 918 | "wasi/libc-top-half/musl/src/math/__tan.c", | ||
| 919 | "wasi/libc-top-half/musl/src/math/tan.c", | ||
| 920 | "wasi/libc-top-half/musl/src/math/__tandf.c", | ||
| 921 | "wasi/libc-top-half/musl/src/math/tanf.c", | ||
| 922 | "wasi/libc-top-half/musl/src/math/tanh.c", | ||
| 923 | "wasi/libc-top-half/musl/src/math/tanhf.c", | ||
| 924 | "wasi/libc-top-half/musl/src/math/tanhl.c", | ||
| 925 | "wasi/libc-top-half/musl/src/math/__tanl.c", | ||
| 926 | "wasi/libc-top-half/musl/src/math/tanl.c", | ||
| 927 | "wasi/libc-top-half/musl/src/math/tgamma.c", | ||
| 928 | "wasi/libc-top-half/musl/src/math/tgammaf.c", | ||
| 929 | "wasi/libc-top-half/musl/src/math/tgammal.c", | ||
| 930 | "wasi/libc-top-half/musl/src/math/truncl.c", | ||
| 931 | "wasi/libc-top-half/musl/src/complex/cabs.c", | ||
| 932 | "wasi/libc-top-half/musl/src/complex/cabsf.c", | ||
| 933 | "wasi/libc-top-half/musl/src/complex/cabsl.c", | ||
| 934 | "wasi/libc-top-half/musl/src/complex/cacos.c", | ||
| 935 | "wasi/libc-top-half/musl/src/complex/cacosf.c", | ||
| 936 | "wasi/libc-top-half/musl/src/complex/cacosh.c", | ||
| 937 | "wasi/libc-top-half/musl/src/complex/cacoshf.c", | ||
| 938 | "wasi/libc-top-half/musl/src/complex/cacoshl.c", | ||
| 939 | "wasi/libc-top-half/musl/src/complex/cacosl.c", | ||
| 940 | "wasi/libc-top-half/musl/src/complex/carg.c", | ||
| 941 | "wasi/libc-top-half/musl/src/complex/cargf.c", | ||
| 942 | "wasi/libc-top-half/musl/src/complex/cargl.c", | ||
| 943 | "wasi/libc-top-half/musl/src/complex/casin.c", | ||
| 944 | "wasi/libc-top-half/musl/src/complex/casinf.c", | ||
| 945 | "wasi/libc-top-half/musl/src/complex/casinh.c", | ||
| 946 | "wasi/libc-top-half/musl/src/complex/casinhf.c", | ||
| 947 | "wasi/libc-top-half/musl/src/complex/casinhl.c", | ||
| 948 | "wasi/libc-top-half/musl/src/complex/casinl.c", | ||
| 949 | "wasi/libc-top-half/musl/src/complex/catan.c", | ||
| 950 | "wasi/libc-top-half/musl/src/complex/catanf.c", | ||
| 951 | "wasi/libc-top-half/musl/src/complex/catanh.c", | ||
| 952 | "wasi/libc-top-half/musl/src/complex/catanhf.c", | ||
| 953 | "wasi/libc-top-half/musl/src/complex/catanhl.c", | ||
| 954 | "wasi/libc-top-half/musl/src/complex/catanl.c", | ||
| 955 | "wasi/libc-top-half/musl/src/complex/ccos.c", | ||
| 956 | "wasi/libc-top-half/musl/src/complex/ccosf.c", | ||
| 957 | "wasi/libc-top-half/musl/src/complex/ccosh.c", | ||
| 958 | "wasi/libc-top-half/musl/src/complex/ccoshf.c", | ||
| 959 | "wasi/libc-top-half/musl/src/complex/ccoshl.c", | ||
| 960 | "wasi/libc-top-half/musl/src/complex/ccosl.c", | ||
| 961 | "wasi/libc-top-half/musl/src/complex/__cexp.c", | ||
| 962 | "wasi/libc-top-half/musl/src/complex/cexp.c", | ||
| 963 | "wasi/libc-top-half/musl/src/complex/__cexpf.c", | ||
| 964 | "wasi/libc-top-half/musl/src/complex/cexpf.c", | ||
| 965 | "wasi/libc-top-half/musl/src/complex/cexpl.c", | ||
| 966 | "wasi/libc-top-half/musl/src/complex/clog.c", | ||
| 967 | "wasi/libc-top-half/musl/src/complex/clogf.c", | ||
| 968 | "wasi/libc-top-half/musl/src/complex/clogl.c", | ||
| 969 | "wasi/libc-top-half/musl/src/complex/conj.c", | ||
| 970 | "wasi/libc-top-half/musl/src/complex/conjf.c", | ||
| 971 | "wasi/libc-top-half/musl/src/complex/conjl.c", | ||
| 972 | "wasi/libc-top-half/musl/src/complex/cpow.c", | ||
| 973 | "wasi/libc-top-half/musl/src/complex/cpowf.c", | ||
| 974 | "wasi/libc-top-half/musl/src/complex/cpowl.c", | ||
| 975 | "wasi/libc-top-half/musl/src/complex/cproj.c", | ||
| 976 | "wasi/libc-top-half/musl/src/complex/cprojf.c", | ||
| 977 | "wasi/libc-top-half/musl/src/complex/cprojl.c", | ||
| 978 | "wasi/libc-top-half/musl/src/complex/csin.c", | ||
| 979 | "wasi/libc-top-half/musl/src/complex/csinf.c", | ||
| 980 | "wasi/libc-top-half/musl/src/complex/csinh.c", | ||
| 981 | "wasi/libc-top-half/musl/src/complex/csinhf.c", | ||
| 982 | "wasi/libc-top-half/musl/src/complex/csinhl.c", | ||
| 983 | "wasi/libc-top-half/musl/src/complex/csinl.c", | ||
| 984 | "wasi/libc-top-half/musl/src/complex/csqrt.c", | ||
| 985 | "wasi/libc-top-half/musl/src/complex/csqrtf.c", | ||
| 986 | "wasi/libc-top-half/musl/src/complex/csqrtl.c", | ||
| 987 | "wasi/libc-top-half/musl/src/complex/ctan.c", | ||
| 988 | "wasi/libc-top-half/musl/src/complex/ctanf.c", | ||
| 989 | "wasi/libc-top-half/musl/src/complex/ctanh.c", | ||
| 990 | "wasi/libc-top-half/musl/src/complex/ctanhf.c", | ||
| 991 | "wasi/libc-top-half/musl/src/complex/ctanhl.c", | ||
| 992 | "wasi/libc-top-half/musl/src/complex/ctanl.c", | ||
| 993 | "wasi/libc-top-half/musl/src/crypt/crypt_blowfish.c", | ||
| 994 | "wasi/libc-top-half/musl/src/crypt/crypt.c", | ||
| 995 | "wasi/libc-top-half/musl/src/crypt/crypt_des.c", | ||
| 996 | "wasi/libc-top-half/musl/src/crypt/crypt_md5.c", | ||
| 997 | "wasi/libc-top-half/musl/src/crypt/crypt_r.c", | ||
| 998 | "wasi/libc-top-half/musl/src/crypt/crypt_sha256.c", | ||
| 999 | "wasi/libc-top-half/musl/src/crypt/crypt_sha512.c", | ||
| 1000 | "wasi/libc-top-half/musl/src/crypt/encrypt.c", | ||
| 1001 | "wasi/libc-top-half/sources/arc4random.c", | ||
| 1002 | }; | ||
| 1003 | |||
| 1004 | const crt_src_files = &[_][]const u8{ | ||
| 1005 | "wasi/libc-bottom-half/crt/crt1.c", | ||
| 1006 | "wasi/libc-bottom-half/crt/crt1-command.c", | ||
| 1007 | "wasi/libc-bottom-half/crt/crt1-reactor.c", | ||
| 1008 | }; | ||
| 1009 | |||
| 1010 | const emulated_process_clocks_src_files = &[_][]const u8{ | ||
| 1011 | "wasi/libc-bottom-half/clocks/clock.c", | ||
| 1012 | "wasi/libc-bottom-half/clocks/getrusage.c", | ||
| 1013 | "wasi/libc-bottom-half/clocks/times.c", | ||
| 1014 | }; | ||
| 1015 | |||
| 1016 | const emulated_getpid_src_files = &[_][]const u8{ | ||
| 1017 | "wasi/libc-bottom-half/getpid/getpid.c", | ||
| 1018 | }; | ||
| 1019 | |||
| 1020 | const emulated_mman_src_files = &[_][]const u8{ | ||
| 1021 | "wasi/libc-bottom-half/mman/mman.c", | ||
| 1022 | }; | ||
| 1023 | |||
| 1024 | const emulated_signal_src_files = &[_][]const u8{ | ||
| 1025 | "wasi/libc-bottom-half/signal/signal.c", | ||
| 1026 | }; | ||