authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2022-06-15 12:33:17+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2022-06-15 12:33:17+02:00
logd3caacfab70736b43719b92391c9d343b54a03fd
tree48c83d2764be807835c1e1d53a45f1d16ae63fac
parent27610b0a0f0b2fc0695b0687d1e93ce910c155db
parent8c630376952546ddd09e76fcc72d3d2a8d12e0b6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #11864 from jedisct1/wasi-libc-update

Update the WASI libc to 30094b6ed05f19cee102115215863d185f2db4f0

81 files changed, 581 insertions(+), 225 deletions(-)

lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h+6
......@@ -75,14 +75,18 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
7575 if (times == NULL) {
7676 // Update both timestamps.
7777 *flags = __WASI_FSTFLAGS_ATIM_NOW | __WASI_FSTFLAGS_MTIM_NOW;
78 *st_atim = (__wasi_timestamp_t) { 0 };
79 *st_mtim = (__wasi_timestamp_t) { 0 };
7880 } else {
7981 // Set individual timestamps.
8082 *flags = 0;
8183 switch (times[0].tv_nsec) {
8284 case UTIME_NOW:
8385 *flags |= __WASI_FSTFLAGS_ATIM_NOW;
86 *st_atim = (__wasi_timestamp_t) { 0 };
8487 break;
8588 case UTIME_OMIT:
89 *st_atim = (__wasi_timestamp_t) { 0 };
8690 break;
8791 default:
8892 *flags |= __WASI_FSTFLAGS_ATIM;
......@@ -94,8 +98,10 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
9498 switch (times[1].tv_nsec) {
9599 case UTIME_NOW:
96100 *flags |= __WASI_FSTFLAGS_MTIM_NOW;
101 *st_mtim = (__wasi_timestamp_t) { 0 };
97102 break;
98103 case UTIME_OMIT:
104 *st_mtim = (__wasi_timestamp_t) { 0 };
99105 break;
100106 default:
101107 *flags |= __WASI_FSTFLAGS_MTIM;
lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/time/gettimeofday.c+5-3
......@@ -9,8 +9,10 @@
99#include <wasi/api.h>
1010
1111int 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);
12 if (tp != NULL) {
13 __wasi_timestamp_t ts = 0;
14 (void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
15 *tp = timestamp_to_timeval(ts);
16 }
1517 return 0;
1618}
lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c-12
......@@ -574,18 +574,6 @@ _Noreturn void __wasi_proc_exit(
574574 __imported_wasi_snapshot_preview1_proc_exit((int32_t) rval);
575575}
576576
577int32_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
589577int32_t __imported_wasi_snapshot_preview1_sched_yield() __attribute__((
590578 __import_module__("wasi_snapshot_preview1"),
591579 __import_name__("sched_yield")
lib/libc/wasi/libc-bottom-half/sources/accept.c created+51
......@@ -0,0 +1,51 @@
1// SPDX-License-Identifier: BSD-2-Clause
2
3#include <sys/socket.h>
4
5#include <assert.h>
6#include <wasi/api.h>
7#include <errno.h>
8#include <string.h>
9
10int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) {
11 int ret = -1;
12
13 __wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret);
14
15 if (error != 0) {
16 errno = error;
17 return -1;
18 }
19
20 // Clear sockaddr to indicate undefined address
21 memset(addr, 0, *addrlen);
22 // might be AF_UNIX or AF_INET
23 addr->sa_family = AF_UNSPEC;
24 *addrlen = sizeof(struct sockaddr);
25
26 return ret;
27}
28
29int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) {
30 int ret = -1;
31
32 if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) {
33 errno = EINVAL;
34 return -1;
35 }
36
37 __wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret);
38
39 if (error != 0) {
40 errno = error;
41 return -1;
42 }
43
44 // Clear sockaddr to indicate undefined address
45 memset(addr, 0, *addrlen);
46 // might be AF_UNIX or AF_INET
47 addr->sa_family = AF_UNSPEC;
48 *addrlen = sizeof(struct sockaddr);
49
50 return ret;
51}
lib/libc/wasi/libc-bottom-half/sources/chdir.c+5-4
......@@ -46,7 +46,7 @@ int chdir(const char *path)
4646 size_t len = strlen(abs) + 1;
4747 int copy_relative = strcmp(relative_buf, ".") != 0;
4848 int mid = copy_relative && abs[0] != 0;
49 char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0));
49 char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0)+1);
5050 if (new_cwd == NULL) {
5151 errno = ENOMEM;
5252 return -1;
......@@ -54,7 +54,7 @@ int chdir(const char *path)
5454 new_cwd[0] = '/';
5555 strcpy(new_cwd + 1, abs);
5656 if (mid)
57 new_cwd[strlen(abs) + 1] = '/';
57 new_cwd[len] = '/';
5858 if (copy_relative)
5959 strcpy(new_cwd + 1 + mid + strlen(abs), relative_buf);
6060
......@@ -95,9 +95,10 @@ static const char *make_absolute(const char *path) {
9595 int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1;
9696 size_t alloc_len = cwd_len + path_len + 1 + need_slash;
9797 if (alloc_len > make_absolute_len) {
98 make_absolute_buf = realloc(make_absolute_buf, alloc_len);
99 if (make_absolute_buf == NULL)
98 char *tmp = realloc(make_absolute_buf, alloc_len);
99 if (tmp == NULL)
100100 return NULL;
101 make_absolute_buf = tmp;
101102 make_absolute_len = alloc_len;
102103 }
103104 strcpy(make_absolute_buf, __wasilibc_cwd);
lib/libc/wasi/libc-bottom-half/sources/posix.c+28-2
......@@ -31,16 +31,20 @@ static int find_relpath2(
3131static int find_relpath(const char *path, char **relative) {
3232 static __thread char *relative_buf = NULL;
3333 static __thread size_t relative_buf_len = 0;
34 int fd = find_relpath2(path, &relative_buf, &relative_buf_len);
35 // find_relpath2 can update relative_buf, so assign it after the call
3436 *relative = relative_buf;
35 return find_relpath2(path, relative, &relative_buf_len);
37 return fd;
3638}
3739
3840// same as `find_relpath`, but uses another set of static variables to cache
3941static int find_relpath_alt(const char *path, char **relative) {
4042 static __thread char *relative_buf = NULL;
4143 static __thread size_t relative_buf_len = 0;
44 int fd = find_relpath2(path, &relative_buf, &relative_buf_len);
45 // find_relpath2 can update relative_buf, so assign it after the call
4246 *relative = relative_buf;
43 return find_relpath2(path, relative, &relative_buf_len);
47 return fd;
4448}
4549
4650int open(const char *path, int oflag, ...) {
......@@ -139,6 +143,28 @@ int utime(const char *path, const struct utimbuf *times) {
139143 0);
140144}
141145
146int utimes(const char *path, const struct timeval times[2]) {
147 char *relative_path;
148 int dirfd = find_relpath(path, &relative_path);
149
150 // If we can't find a preopen for it, indicate that we lack capabilities.
151 if (dirfd == -1) {
152 errno = ENOTCAPABLE;
153 return -1;
154 }
155
156 return __wasilibc_nocwd_utimensat(
157 dirfd, relative_path,
158 times ? ((struct timespec [2]) {
159 { .tv_sec = times[0].tv_sec,
160 .tv_nsec = times[0].tv_usec * 1000 },
161 { .tv_sec = times[1].tv_sec,
162 .tv_nsec = times[1].tv_usec * 1000 },
163 })
164 : NULL,
165 0);
166}
167
142168int unlink(const char *path) {
143169 char *relative_path;
144170 int dirfd = find_relpath(path, &relative_path);
lib/libc/wasi/libc-top-half/musl/include/ctype.h+2
......@@ -64,7 +64,9 @@ int isascii(int);
6464int toascii(int);
6565#define _tolower(a) ((a)|0x20)
6666#define _toupper(a) ((a)&0x5f)
67#ifndef __cplusplus
6768#define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128)
69#endif
6870
6971#endif
7072
lib/libc/wasi/libc-top-half/musl/include/elf.h+2
......@@ -686,6 +686,8 @@ typedef struct {
686686#define NT_ARM_PAC_MASK 0x406
687687#define NT_ARM_PACA_KEYS 0x407
688688#define NT_ARM_PACG_KEYS 0x408
689#define NT_ARM_TAGGED_ADDR_CTRL 0x409
690#define NT_ARM_PAC_ENABLED_KEYS 0x40a
689691#define NT_METAG_CBUF 0x500
690692#define NT_METAG_RPIPE 0x501
691693#define NT_METAG_TLS 0x502
lib/libc/wasi/libc-top-half/musl/include/locale.h+3-1
......@@ -8,7 +8,9 @@ extern "C" {
88#include <features.h>
99
1010#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
11#ifdef __cplusplus
11#if __cplusplus >= 201103L
12#define NULL nullptr
13#elif defined(__cplusplus)
1214#define NULL 0L
1315#else
1416#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/include/netinet/if_ether.h+1
......@@ -66,6 +66,7 @@
6666#define ETH_P_1588 0x88F7
6767#define ETH_P_NCSI 0x88F8
6868#define ETH_P_PRP 0x88FB
69#define ETH_P_CFM 0x8902
6970#define ETH_P_FCOE 0x8906
7071#define ETH_P_TDLS 0x890D
7172#define ETH_P_FIP 0x8914
lib/libc/wasi/libc-top-half/musl/include/netinet/in.h+1
......@@ -60,6 +60,7 @@ struct ipv6_mreq {
6060#define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
6161#define INADDR_NONE ((in_addr_t) 0xffffffff)
6262#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001)
63#define INADDR_DUMMY ((in_addr_t) 0xc0000008)
6364
6465#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000)
6566#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001)
lib/libc/wasi/libc-top-half/musl/include/netinet/tcp.h+11
......@@ -80,6 +80,8 @@ enum {
8080 TCP_NLA_SRTT,
8181 TCP_NLA_TIMEOUT_REHASH,
8282 TCP_NLA_BYTES_NOTSENT,
83 TCP_NLA_EDT,
84 TCP_NLA_TTL,
8385};
8486
8587#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
......@@ -281,12 +283,21 @@ struct tcp_repair_window {
281283 uint32_t rcv_wup;
282284};
283285
286#define TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT 0x1
287
284288struct tcp_zerocopy_receive {
285289 uint64_t address;
286290 uint32_t length;
287291 uint32_t recv_skip_hint;
288292 uint32_t inq;
289293 int32_t err;
294 uint64_t copybuf_address;
295 int32_t copybuf_len;
296 uint32_t flags;
297 uint64_t msg_control;
298 uint64_t msg_controllen;
299 uint32_t msg_flags;
300 uint32_t reserved;
290301};
291302
292303#endif
lib/libc/wasi/libc-top-half/musl/include/pthread.h+1
......@@ -227,6 +227,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
227227int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
228228int pthread_getattr_np(pthread_t, pthread_attr_t *);
229229int pthread_setname_np(pthread_t, const char *);
230int pthread_getname_np(pthread_t, char *, size_t);
230231int pthread_getattr_default_np(pthread_attr_t *);
231232int pthread_setattr_default_np(const pthread_attr_t *);
232233int pthread_tryjoin_np(pthread_t, void **);
lib/libc/wasi/libc-top-half/musl/include/setjmp.h+11-3
......@@ -16,21 +16,27 @@ typedef struct __jmp_buf_tag {
1616 unsigned long __ss[128/sizeof(long)];
1717} jmp_buf[1];
1818
19#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
20#define __setjmp_attr __attribute__((__returns_twice__))
21#else
22#define __setjmp_attr
23#endif
24
1925#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
2026 || defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
2127 || defined(_BSD_SOURCE)
2228typedef jmp_buf sigjmp_buf;
23int sigsetjmp (sigjmp_buf, int);
29int sigsetjmp (sigjmp_buf, int) __setjmp_attr;
2430_Noreturn void siglongjmp (sigjmp_buf, int);
2531#endif
2632
2733#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
2834 || defined(_BSD_SOURCE)
29int _setjmp (jmp_buf);
35int _setjmp (jmp_buf) __setjmp_attr;
3036_Noreturn void _longjmp (jmp_buf, int);
3137#endif
3238
33int setjmp (jmp_buf);
39int setjmp (jmp_buf) __setjmp_attr;
3440_Noreturn void longjmp (jmp_buf, int);
3541
3642#define setjmp setjmp
......@@ -38,6 +44,8 @@ _Noreturn void longjmp (jmp_buf, int);
3844#warning setjmp is not yet implemented for WASI
3945#endif
4046
47#undef __setjmp_attr
48
4149#ifdef __cplusplus
4250}
4351#endif
lib/libc/wasi/libc-top-half/musl/include/signal.h+8
......@@ -82,6 +82,8 @@ typedef struct sigaltstack stack_t;
8282#define SEGV_ACCERR 2
8383#define SEGV_BNDERR 3
8484#define SEGV_PKUERR 4
85#define SEGV_MTEAERR 8
86#define SEGV_MTESERR 9
8587
8688#define BUS_ADRALN 1
8789#define BUS_ADRERR 2
......@@ -183,6 +185,9 @@ struct sigaction {
183185#define sa_handler __sa_handler.sa_handler
184186#define sa_sigaction __sa_handler.sa_sigaction
185187
188#define SA_UNSUPPORTED 0x00000400
189#define SA_EXPOSE_TAGBITS 0x00000800
190
186191struct sigevent {
187192 union sigval sigev_value;
188193 int sigev_signo;
......@@ -277,6 +282,9 @@ void (*sigset(int, void (*)(int)))(int);
277282#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
278283#define NSIG _NSIG
279284typedef void (*sig_t)(int);
285
286#define SYS_SECCOMP 1
287#define SYS_USER_DISPATCH 2
280288#endif
281289
282290#ifdef _GNU_SOURCE
lib/libc/wasi/libc-top-half/musl/include/stdc-predef.h+3
......@@ -7,4 +7,7 @@
77#define __STDC_IEC_559__ 1
88#endif
99
10#define __STDC_UTF_16__ 1
11#define __STDC_UTF_32__ 1
12
1013#endif
lib/libc/wasi/libc-top-half/musl/include/stddef.h+3-1
......@@ -1,7 +1,9 @@
11#ifndef _STDDEF_H
22#define _STDDEF_H
33
4#ifdef __cplusplus
4#if __cplusplus >= 201103L
5#define NULL nullptr
6#elif defined(__cplusplus)
57#define NULL 0L
68#else
79#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/include/stdio.h+3-1
......@@ -28,7 +28,9 @@ extern "C" {
2828#include <bits/alltypes.h>
2929
3030#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
31#ifdef __cplusplus
31#if __cplusplus >= 201103L
32#define NULL nullptr
33#elif defined(__cplusplus)
3234#define NULL 0L
3335#else
3436#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/include/stdlib.h+4-1
......@@ -13,7 +13,9 @@ extern "C" {
1313#include <features.h>
1414
1515#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
16#ifdef __cplusplus
16#if __cplusplus >= 201103L
17#define NULL nullptr
18#elif defined(__cplusplus)
1719#define NULL 0L
1820#else
1921#define NULL ((void*)0)
......@@ -171,6 +173,7 @@ int clearenv(void);
171173#define WCOREDUMP(s) ((s) & 0x80)
172174#define WIFCONTINUED(s) ((s) == 0xffff)
173175void *reallocarray (void *, size_t, size_t);
176void qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
174177#endif
175178#endif
176179
lib/libc/wasi/libc-top-half/musl/include/string.h+3-1
......@@ -12,7 +12,9 @@ extern "C" {
1212#include <features.h>
1313
1414#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
15#ifdef __cplusplus
15#if __cplusplus >= 201103L
16#define NULL nullptr
17#elif defined(__cplusplus)
1618#define NULL 0L
1719#else
1820#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/include/sys/membarrier.h+4
......@@ -9,9 +9,13 @@
99#define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED 16
1010#define MEMBARRIER_CMD_PRIVATE_EXPEDITED_SYNC_CORE 32
1111#define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_SYNC_CORE 64
12#define MEMBARRIER_CMD_PRIVATE_EXPEDITED_RSEQ 128
13#define MEMBARRIER_CMD_REGISTER_PRIVATE_EXPEDITED_RSEQ 256
1214
1315#define MEMBARRIER_CMD_SHARED MEMBARRIER_CMD_GLOBAL
1416
17#define MEMBARRIER_CMD_FLAG_CPU 1
18
1519int membarrier(int, int);
1620
1721#endif
lib/libc/wasi/libc-top-half/musl/include/sys/mman.h+1
......@@ -44,6 +44,7 @@ extern "C" {
4444
4545#define MAP_HUGE_SHIFT 26
4646#define MAP_HUGE_MASK 0x3f
47#define MAP_HUGE_16KB (14 << 26)
4748#define MAP_HUGE_64KB (16 << 26)
4849#define MAP_HUGE_512KB (19 << 26)
4950#define MAP_HUGE_1MB (20 << 26)
lib/libc/wasi/libc-top-half/musl/include/sys/mount.h+1
......@@ -31,6 +31,7 @@ extern "C" {
3131#define MS_REMOUNT 32
3232#define MS_MANDLOCK 64
3333#define MS_DIRSYNC 128
34#define MS_NOSYMFOLLOW 256
3435#define MS_NOATIME 1024
3536#define MS_NODIRATIME 2048
3637#define MS_BIND 4096
lib/libc/wasi/libc-top-half/musl/include/sys/prctl.h+16
......@@ -157,10 +157,26 @@ struct prctl_mm_map {
157157#define PR_SET_TAGGED_ADDR_CTRL 55
158158#define PR_GET_TAGGED_ADDR_CTRL 56
159159#define PR_TAGGED_ADDR_ENABLE (1UL << 0)
160#define PR_MTE_TCF_SHIFT 1
161#define PR_MTE_TCF_NONE (0UL << 1)
162#define PR_MTE_TCF_SYNC (1UL << 1)
163#define PR_MTE_TCF_ASYNC (2UL << 1)
164#define PR_MTE_TCF_MASK (3UL << 1)
165#define PR_MTE_TAG_SHIFT 3
166#define PR_MTE_TAG_MASK (0xffffUL << 3)
160167
161168#define PR_SET_IO_FLUSHER 57
162169#define PR_GET_IO_FLUSHER 58
163170
171#define PR_SET_SYSCALL_USER_DISPATCH 59
172#define PR_SYS_DISPATCH_OFF 0
173#define PR_SYS_DISPATCH_ON 1
174#define SYSCALL_DISPATCH_FILTER_ALLOW 0
175#define SYSCALL_DISPATCH_FILTER_BLOCK 1
176
177#define PR_PAC_SET_ENABLED_KEYS 60
178#define PR_PAC_GET_ENABLED_KEYS 61
179
164180int prctl (int, ...);
165181
166182#ifdef __cplusplus
lib/libc/wasi/libc-top-half/musl/include/sys/ptrace.h+9
......@@ -42,6 +42,7 @@ extern "C" {
4242#define PTRACE_SECCOMP_GET_FILTER 0x420c
4343#define PTRACE_SECCOMP_GET_METADATA 0x420d
4444#define PTRACE_GET_SYSCALL_INFO 0x420e
45#define PTRACE_GET_RSEQ_CONFIGURATION 0x420f
4546
4647#define PT_READ_I PTRACE_PEEKTEXT
4748#define PT_READ_D PTRACE_PEEKDATA
......@@ -130,6 +131,14 @@ struct __ptrace_syscall_info {
130131 };
131132};
132133
134struct __ptrace_rseq_configuration {
135 uint64_t rseq_abi_pointer;
136 uint32_t rseq_abi_size;
137 uint32_t signature;
138 uint32_t flags;
139 uint32_t pad;
140};
141
133142long ptrace(int, ...);
134143
135144#ifdef __cplusplus
lib/libc/wasi/libc-top-half/musl/include/sys/socket.h+4-1
......@@ -298,6 +298,8 @@ struct linger {
298298#define SCM_TXTIME SO_TXTIME
299299#define SO_BINDTOIFINDEX 62
300300#define SO_DETACH_REUSEPORT_BPF 68
301#define SO_PREFER_BUSY_POLL 69
302#define SO_BUSY_POLL_BUDGET 70
301303
302304#ifndef SOL_SOCKET
303305#define SOL_SOCKET 1
......@@ -404,9 +406,10 @@ int shutdown (int, int);
404406int bind (int, const struct sockaddr *, socklen_t);
405407int connect (int, const struct sockaddr *, socklen_t);
406408int listen (int, int);
409#endif
410
407411int accept (int, struct sockaddr *__restrict, socklen_t *__restrict);
408412int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
409#endif
410413
411414#ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */
412415int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
lib/libc/wasi/libc-top-half/musl/include/sys/time.h+2-2
......@@ -23,9 +23,7 @@ struct itimerval {
2323int getitimer (int, struct itimerval *);
2424int setitimer (int, const struct itimerval *__restrict, struct itimerval *__restrict);
2525#endif
26#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
2726int utimes (const char *, const struct timeval [2]);
28#endif
2927
3028#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
3129struct timezone {
......@@ -34,7 +32,9 @@ struct timezone {
3432};
3533#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
3634int futimes(int, const struct timeval [2]);
35#endif
3736int futimesat(int, const char *, const struct timeval [2]);
37#ifdef __wasilibc_unmodified_upstream /* WASI libc doesn't build the legacy functions */
3838int lutimes(const char *, const struct timeval [2]);
3939#endif
4040#ifdef __wasilibc_unmodified_upstream /* WASI has no way to set the time */
lib/libc/wasi/libc-top-half/musl/include/time.h+3-1
......@@ -8,7 +8,9 @@ extern "C" {
88#include <features.h>
99
1010#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
11#ifdef __cplusplus
11#if __cplusplus >= 201103L
12#define NULL nullptr
13#elif defined(__cplusplus)
1214#define NULL 0L
1315#else
1416#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/include/unistd.h+5-1
......@@ -15,12 +15,16 @@ extern "C" {
1515#define SEEK_SET 0
1616#define SEEK_CUR 1
1717#define SEEK_END 2
18#define SEEK_DATA 3
19#define SEEK_HOLE 4
1820#else
1921#include <__header_unistd.h>
2022#endif
2123
2224#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
23#ifdef __cplusplus
25#if __cplusplus >= 201103L
26#define NULL nullptr
27#elif defined(__cplusplus)
2428#define NULL 0L
2529#else
2630#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/include/wchar.h+3-1
......@@ -41,7 +41,9 @@ extern "C" {
4141#endif
4242
4343#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
44#ifdef __cplusplus
44#if __cplusplus >= 201103L
45#define NULL nullptr
46#elif defined(__cplusplus)
4547#define NULL 0L
4648#else
4749#define NULL ((void*)0)
lib/libc/wasi/libc-top-half/musl/src/complex/cacosf.c+3-1
......@@ -2,8 +2,10 @@
22
33// FIXME
44
5static const float float_pi_2 = M_PI_2;
6
57float complex cacosf(float complex z)
68{
79 z = casinf(z);
8 return CMPLXF((float)M_PI_2 - crealf(z), -cimagf(z));
10 return CMPLXF(float_pi_2 - crealf(z), -cimagf(z));
911}
lib/libc/wasi/libc-top-half/musl/src/complex/catanf.c+3-1
......@@ -61,13 +61,15 @@ static const double DP1 = 3.140625;
6161static const double DP2 = 9.67502593994140625E-4;
6262static const double DP3 = 1.509957990978376432E-7;
6363
64static const float float_pi = M_PI;
65
6466static float _redupif(float xx)
6567{
6668 float x, t;
6769 long i;
6870
6971 x = xx;
70 t = x/(float)M_PI;
72 t = x/float_pi;
7173 if (t >= 0.0f)
7274 t += 0.5f;
7375 else
lib/libc/wasi/libc-top-half/musl/src/complex/cproj.c+1-1
......@@ -3,6 +3,6 @@
33double complex cproj(double complex z)
44{
55 if (isinf(creal(z)) || isinf(cimag(z)))
6 return CMPLX(INFINITY, copysign(0.0, creal(z)));
6 return CMPLX(INFINITY, copysign(0.0, cimag(z)));
77 return z;
88}
lib/libc/wasi/libc-top-half/musl/src/complex/cprojf.c+1-1
......@@ -3,6 +3,6 @@
33float complex cprojf(float complex z)
44{
55 if (isinf(crealf(z)) || isinf(cimagf(z)))
6 return CMPLXF(INFINITY, copysignf(0.0, crealf(z)));
6 return CMPLXF(INFINITY, copysignf(0.0, cimagf(z)));
77 return z;
88}
lib/libc/wasi/libc-top-half/musl/src/complex/cprojl.c+1-1
......@@ -9,7 +9,7 @@ long double complex cprojl(long double complex z)
99long double complex cprojl(long double complex z)
1010{
1111 if (isinf(creall(z)) || isinf(cimagl(z)))
12 return CMPLXL(INFINITY, copysignl(0.0, creall(z)));
12 return CMPLXL(INFINITY, copysignl(0.0, cimagl(z)));
1313 return z;
1414}
1515#endif
lib/libc/wasi/libc-top-half/musl/src/ctype/nonspacing.h+60-58
......@@ -1,23 +1,23 @@
116,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,
236,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,
116,16,16,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,16,33,16,16,16,34,35,36,
237,38,39,40,16,16,41,16,16,16,16,16,16,16,16,16,16,16,42,43,16,16,44,16,16,16,
3316,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,
4416,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,
5516,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,
6616,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,
716,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,
716,16,16,16,16,16,16,16,16,16,45,16,46,47,48,49,16,16,16,16,16,16,16,16,16,16,
8816,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,
916,16,16,16,16,16,16,50,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1016,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,51,16,16,52,
1153,16,54,55,56,16,16,16,16,16,16,57,16,16,58,16,59,60,61,62,63,64,65,66,67,68,
1269,70,16,71,72,73,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1316,74,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
91416,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,
1016,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,49,16,16,50,
1151,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,
1267,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,
1316,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,
1516,16,16,75,76,16,16,16,77,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
141616,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,
1516,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,
161716,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,
1716,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,
1816,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,
1916,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,
2084,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1816,16,16,16,16,16,16,78,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
1916,16,79,80,16,16,16,16,16,16,16,81,16,16,16,16,16,82,83,84,16,16,16,16,16,85,
2086,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
212116,0,0,0,0,0,0,0,0,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,
2222255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
2323255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,
......@@ -35,55 +35,57 @@
3535242,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,
36362,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,
37370,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,
380,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,
390,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,
400,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,
410,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,
42229,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,
430,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,
440,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,
450,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,
380,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,255,255,255,
39255,255,255,255,255,255,255,0,0,0,0,0,0,0,0,0,0,0,224,0,0,0,0,0,0,0,0,0,0,0,0,
400,0,0,0,0,0,0,0,0,0,28,0,0,0,28,0,0,0,12,0,0,0,12,0,0,0,0,0,0,0,176,63,64,254,
4115,32,0,0,0,0,0,120,0,0,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,
420,0,0,0,0,0,135,1,4,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
43128,9,0,0,0,0,0,0,64,127,229,31,248,159,0,0,0,0,0,0,255,127,0,0,0,0,0,0,0,0,
4415,0,0,0,0,0,208,23,4,0,0,0,0,248,15,0,3,0,0,0,60,59,0,0,0,0,0,0,64,163,3,0,0,
450,0,0,0,240,207,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,247,255,253,33,16,
463,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,255,
4647251,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,
4748255,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,
48490,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,
49500,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,
50510,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,
51520,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,
520,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,
530,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64,
540,0,0,0,0,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,
550,0,0,0,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,
560,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,
570,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,
580,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,
590,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,
600,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,
610,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,
620,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,
63127,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,
640,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,
650,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,
6631,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,
670,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,
680,60,176,1,0,0,48,0,0,0,
690,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,
700,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,
71128,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,
720,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,
73126,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,
740,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,
750,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,
760,0,0,0,0,0,0,0,0,0,0,0,0,0,24,
770,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,
780,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,
790,0,0,0,0,0,0,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,
800,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,
810,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,
820,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,
830,0,0,255,255,255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,
84254,255,0,0,0,0,0,0,0,0,0,
850,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,
860,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,
870,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,
880,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,
890,0,0,0,0,0,0,0,0,0,0,0,0,0,
530,0,0,0,7,0,0,0,0,0,200,51,0,0,0,0,32,0,0,
540,0,0,0,0,0,126,102,0,8,16,0,0,0,0,0,16,0,0,0,0,0,0,157,193,2,0,0,0,0,48,64,0,
550,0,0,0,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,0,0,0,
560,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,255,255,255,255,255,255,255,255,255,255,0,0,0,
5764,0,0,0,0,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,
58255,0,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,
590,0,0,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,
600,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,
610,0,0,0,0,0,1,0,0,
620,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,0,110,240,0,
630,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,0,0,0,0,0,240,0,0,
640,0,0,0,0,0,0,0,0,0,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,1,0,
650,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,127,0,0,0,0,0,0,128,
663,0,0,0,0,0,120,38,0,32,0,0,0,0,0,0,7,0,0,0,128,239,31,0,0,0,0,0,0,0,8,0,3,0,
670,0,0,0,192,127,0,30,0,0,0,0,0,0,0,0,0,0,0,128,211,64,0,0,0,0,0,0,0,0,0,0,0,0,
680,0,0,0,0,0,0,128,248,7,0,0,3,0,0,0,0,0,0,24,1,0,0,0,192,31,31,0,0,0,0,0,0,0,
690,0,0,0,0,0,0,0,0,
700,0,0,0,0,0,0,0,255,92,0,0,64,0,0,0,0,0,0,0,0,0,0,248,133,13,0,0,0,0,0,0,0,0,
710,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,60,176,1,0,0,48,0,0,0,0,0,0,0,0,0,0,
72248,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,0,224,188,15,0,
730,0,0,0,0,0,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,6,0,0,0,0,
740,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
750,0,0,0,0,0,0,240,12,1,0,0,0,254,7,0,0,0,0,248,121,128,0,126,14,0,0,0,0,0,252,
76127,3,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,127,191,0,0,0,0,0,0,0,0,0,0,252,255,
77255,252,109,0,0,0,0,0,0,0,0,
780,0,0,0,0,0,0,126,180,191,0,0,0,0,0,0,0,0,0,163,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
790,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,24,0,0,0,0,0,0,0,255,
801,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
810,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,0,0,0,0,0,0,0,0,0,
820,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,128,7,0,0,0,0,0,
830,0,0,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,0,0,0,0,0,0,0,0,0,
840,0,0,0,0,0,0,0,0,0,0,0,0,0,128,3,248,255,231,15,0,0,0,60,0,0,0,0,0,0,0,0,0,
850,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,0,0,0,255,255,
86255,255,255,255,127,248,255,255,255,255,255,31,32,0,16,0,0,248,254,255,0,0,0,
870,0,0,0,0,0,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,
880,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,0,0,0,0,0,0,0,
890,0,0,0,0,0,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,
900,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,0,0,0,0,0,0,240,7,0,0,
910,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
lib/libc/wasi/libc-top-half/musl/src/env/__libc_start_main.c+2-1
......@@ -69,7 +69,8 @@ weak_alias(libc_start_init, __libc_start_init);
6969typedef int lsm2_fn(int (*)(int,char **,char **), int, char **);
7070static lsm2_fn libc_start_main_stage2;
7171
72int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv)
72int __libc_start_main(int (*main)(int,char **,char **), int argc, char **argv,
73 void (*init_dummy)(), void(*fini_dummy)(), void(*ldso_dummy)())
7374{
7475 char **envp = argv+argc+1;
7576
lib/libc/wasi/libc-top-half/musl/src/env/__stack_chk_fail.c+9
......@@ -9,6 +9,15 @@ void __init_ssp(void *entropy)
99 if (entropy) memcpy(&__stack_chk_guard, entropy, sizeof(uintptr_t));
1010 else __stack_chk_guard = (uintptr_t)&__stack_chk_guard * 1103515245;
1111
12#if UINTPTR_MAX >= 0xffffffffffffffff
13 /* Sacrifice 8 bits of entropy on 64bit to prevent leaking/
14 * overwriting the canary via string-manipulation functions.
15 * The NULL byte is on the second byte so that off-by-ones can
16 * still be detected. Endianness is taken care of
17 * automatically. */
18 ((char *)&__stack_chk_guard)[1] = 0;
19#endif
20
1221 __pthread_self()->canary = __stack_chk_guard;
1322}
1423
lib/libc/wasi/libc-top-half/musl/src/errno/__strerror.h+6
......@@ -124,6 +124,12 @@ E(ENOMEDIUM, "No medium found")
124124E(EMEDIUMTYPE, "Wrong medium type")
125125#endif
126126E(EMULTIHOP, "Multihop attempted")
127#ifdef __wasilibc_unmodified_upstream // errno value not in WASI
128E(ENOKEY, "Required key not available")
129E(EKEYEXPIRED, "Key has expired")
130E(EKEYREVOKED, "Key has been revoked")
131E(EKEYREJECTED, "Key was rejected by service")
132#endif
127133#ifdef __wasilibc_unmodified_upstream // errno value in WASI and not musl
128134#else
129135// WASI adds this errno code.
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc/fenv-sf.c+1-1
......@@ -1,3 +1,3 @@
1#ifdef _SOFT_FLOAT
1#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
22#include "../fenv.c"
33#endif
lib/libc/wasi/libc-top-half/musl/src/fenv/powerpc/fenv.S+1-1
......@@ -1,4 +1,4 @@
1#ifndef _SOFT_FLOAT
1#if !defined(_SOFT_FLOAT) && !defined(__NO_FPRS__)
22.global feclearexcept
33.type feclearexcept,@function
44feclearexcept:
lib/libc/wasi/libc-top-half/musl/src/include/stdlib.h+1
......@@ -8,6 +8,7 @@ hidden void __env_rm_add(char *, char *);
88hidden int __mkostemps(char *, int, int);
99hidden int __ptsname_r(int, char *, size_t);
1010hidden char *__randname(char *);
11hidden void __qsort_r (void *, size_t, size_t, int (*)(const void *, const void *, void *), void *);
1112
1213hidden void *__libc_malloc(size_t);
1314hidden void *__libc_malloc_impl(size_t);
lib/libc/wasi/libc-top-half/musl/src/ldso/dl_iterate_phdr.c+2-1
......@@ -1,5 +1,6 @@
11#include <elf.h>
22#include <link.h>
3#include "pthread_impl.h"
34#include "libc.h"
45
56#define AUX_CNT 38
......@@ -35,7 +36,7 @@ static int static_dl_iterate_phdr(int(*callback)(struct dl_phdr_info *info, size
3536 info.dlpi_subs = 0;
3637 if (tls_phdr) {
3738 info.dlpi_tls_modid = 1;
38 info.dlpi_tls_data = (void *)(base + tls_phdr->p_vaddr);
39 info.dlpi_tls_data = __tls_get_addr((tls_mod_off_t[]){1,0});
3940 } else {
4041 info.dlpi_tls_modid = 0;
4142 info.dlpi_tls_data = 0;
lib/libc/wasi/libc-top-half/musl/src/legacy/cuserid.c+11-3
......@@ -2,13 +2,21 @@
22#include <pwd.h>
33#include <stdio.h>
44#include <unistd.h>
5#include <string.h>
56
67char *cuserid(char *buf)
78{
9 static char usridbuf[L_cuserid];
810 struct passwd pw, *ppw;
911 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);
12 if (buf) *buf = 0;
13 getpwuid_r(geteuid(), &pw, (void *)pwb, sizeof pwb, &ppw);
14 if (!ppw)
15 return buf;
16 size_t len = strnlen(pw.pw_name, L_cuserid);
17 if (len == L_cuserid)
18 return buf;
19 if (!buf) buf = usridbuf;
20 memcpy(buf, pw.pw_name, len+1);
1321 return buf;
1422}
lib/libc/wasi/libc-top-half/musl/src/linux/epoll.c+2-2
......@@ -24,9 +24,9 @@ int epoll_ctl(int fd, int op, int fd2, struct epoll_event *ev)
2424
2525int epoll_pwait(int fd, struct epoll_event *ev, int cnt, int to, const sigset_t *sigs)
2626{
27 int r = __syscall(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
27 int r = __syscall_cp(SYS_epoll_pwait, fd, ev, cnt, to, sigs, _NSIG/8);
2828#ifdef SYS_epoll_wait
29 if (r==-ENOSYS && !sigs) r = __syscall(SYS_epoll_wait, fd, ev, cnt, to);
29 if (r==-ENOSYS && !sigs) r = __syscall_cp(SYS_epoll_wait, fd, ev, cnt, to);
3030#endif
3131 return __syscall_ret(r);
3232}
lib/libc/wasi/libc-top-half/musl/src/locale/dcngettext.c+3
......@@ -132,6 +132,9 @@ char *dcngettext(const char *domainname, const char *msgid1, const char *msgid2,
132132 struct binding *q;
133133 int old_errno = errno;
134134
135 /* match gnu gettext behaviour */
136 if (!msgid1) goto notrans;
137
135138 if ((unsigned)category >= LC_ALL) goto notrans;
136139
137140 if (!domainname) domainname = __gettextdomain();
lib/libc/wasi/libc-top-half/musl/src/locale/duplocale.c+5
......@@ -3,6 +3,11 @@
33#include "locale_impl.h"
44#include "libc.h"
55
6#define malloc __libc_malloc
7#define calloc undef
8#define realloc undef
9#define free undef
10
611locale_t __duplocale(locale_t old)
712{
813 locale_t new = malloc(sizeof *new);
lib/libc/wasi/libc-top-half/musl/src/locale/strtod_l.c created+22
......@@ -0,0 +1,22 @@
1#define _GNU_SOURCE
2#include <stdlib.h>
3#include <locale.h>
4
5float strtof_l(const char *restrict s, char **restrict p, locale_t l)
6{
7 return strtof(s, p);
8}
9
10double strtod_l(const char *restrict s, char **restrict p, locale_t l)
11{
12 return strtod(s, p);
13}
14
15long double strtold_l(const char *restrict s, char **restrict p, locale_t l)
16{
17 return strtold(s, p);
18}
19
20weak_alias(strtof_l, __strtof_l);
21weak_alias(strtod_l, __strtod_l);
22weak_alias(strtold_l, __strtold_l);
lib/libc/wasi/libc-top-half/musl/src/malloc/free.c+1-1
......@@ -2,5 +2,5 @@
22
33void free(void *p)
44{
5 return __libc_free(p);
5 __libc_free(p);
66}
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/aligned_alloc.c+3
......@@ -22,6 +22,9 @@ void *aligned_alloc(size_t align, size_t len)
2222 if (align <= UNIT) align = UNIT;
2323
2424 unsigned char *p = malloc(len + align - UNIT);
25 if (!p)
26 return 0;
27
2528 struct meta *g = get_meta(p);
2629 int idx = get_slot_index(p);
2730 size_t stride = get_stride(g);
lib/libc/wasi/libc-top-half/musl/src/malloc/mallocng/free.c+10-2
......@@ -119,7 +119,11 @@ void free(void *p)
119119 if (((uintptr_t)(start-1) ^ (uintptr_t)end) >= 2*PGSZ && g->last_idx) {
120120 unsigned char *base = start + (-(uintptr_t)start & (PGSZ-1));
121121 size_t len = (end-base) & -PGSZ;
122 if (len) madvise(base, len, MADV_FREE);
122 if (len) {
123 int e = errno;
124 madvise(base, len, MADV_FREE);
125 errno = e;
126 }
123127 }
124128
125129 // atomic free without locking if this is neither first or last slot
......@@ -139,5 +143,9 @@ void free(void *p)
139143 wrlock();
140144 struct mapinfo mi = nontrivial_free(g, idx);
141145 unlock();
142 if (mi.len) munmap(mi.base, mi.len);
146 if (mi.len) {
147 int e = errno;
148 munmap(mi.base, mi.len);
149 errno = e;
150 }
143151}
lib/libc/wasi/libc-top-half/musl/src/malloc/oldmalloc/malloc.c+5-1
......@@ -11,7 +11,7 @@
1111#include "malloc_impl.h"
1212#include "fork_impl.h"
1313
14#define malloc __libc_malloc
14#define malloc __libc_malloc_impl
1515#define realloc __libc_realloc
1616#define free __libc_free
1717
......@@ -481,12 +481,14 @@ void __bin_chunk(struct chunk *self)
481481 if (size > RECLAIM && (size^(size-osize)) > size-osize) {
482482 uintptr_t a = (uintptr_t)self + SIZE_ALIGN+PAGE_SIZE-1 & -PAGE_SIZE;
483483 uintptr_t b = (uintptr_t)next - SIZE_ALIGN & -PAGE_SIZE;
484 int e = errno;
484485#if 1
485486 __madvise((void *)a, b-a, MADV_DONTNEED);
486487#else
487488 __mmap((void *)a, b-a, PROT_READ|PROT_WRITE,
488489 MAP_PRIVATE|MAP_ANONYMOUS|MAP_FIXED, -1, 0);
489490#endif
491 errno = e;
490492 }
491493
492494 unlock_bin(i);
......@@ -499,7 +501,9 @@ static void unmap_chunk(struct chunk *self)
499501 size_t len = CHUNK_SIZE(self) + extra;
500502 /* Crash on double free */
501503 if (extra & 1) a_crash();
504 int e = errno;
502505 __munmap(base, len);
506 errno = e;
503507}
504508
505509void free(void *p)
lib/libc/wasi/libc-top-half/musl/src/math/acoshf.c+4-4
......@@ -15,12 +15,12 @@ float acoshf(float x)
1515 uint32_t a = u.i & 0x7fffffff;
1616
1717 if (a < 0x3f800000+(1<<23))
18 /* |x| < 2, invalid if x < 1 or nan */
18 /* |x| < 2, invalid if x < 1 */
1919 /* up to 2ulp error in [1,1.125] */
2020 return log1pf(x-1 + sqrtf((x-1)*(x-1)+2*(x-1)));
21 if (a < 0x3f800000+(12<<23))
22 /* |x| < 0x1p12 */
21 if (u.i < 0x3f800000+(12<<23))
22 /* 2 <= x < 0x1p12 */
2323 return logf(2*x - 1/(x+sqrtf(x*x-1)));
24 /* x >= 0x1p12 */
24 /* x >= 0x1p12 or x <= -2 or nan */
2525 return logf(x) + 0.693147180559945309417232121458176568f;
2626}
lib/libc/wasi/libc-top-half/musl/src/math/expm1f.c+1-2
......@@ -16,7 +16,6 @@
1616#include "libm.h"
1717
1818static const float
19o_threshold = 8.8721679688e+01, /* 0x42b17180 */
2019ln2_hi = 6.9313812256e-01, /* 0x3f317180 */
2120ln2_lo = 9.0580006145e-06, /* 0x3717f7d1 */
2221invln2 = 1.4426950216e+00, /* 0x3fb8aa3b */
......@@ -41,7 +40,7 @@ float expm1f(float x)
4140 return x;
4241 if (sign)
4342 return -1;
44 if (x > o_threshold) {
43 if (hx > 0x42b17217) { /* x > log(FLT_MAX) */
4544 x *= 0x1p127f;
4645 return x;
4746 }
lib/libc/wasi/libc-top-half/musl/src/math/fmaf.c+10-15
......@@ -77,21 +77,16 @@ float fmaf(float x, float y, float z)
7777 * If result is inexact, and exactly halfway between two float values,
7878 * we need to adjust the low-order bit in the direction of the error.
7979 */
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;
80 double err;
81 int neg = u.i >> 63;
82 if (neg == (z > xy))
83 err = xy - result + z;
84 else
85 err = z - result + xy;
86 if (neg == (err < 0))
9287 u.i++;
93 adjusted_result = u.f;
94 }
95 z = adjusted_result;
88 else
89 u.i--;
90 z = u.f;
9691 return z;
9792}
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabs.c+1-1
......@@ -1,6 +1,6 @@
11#include <math.h>
22
3#if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM)
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
44
55#include "../fabs.c"
66
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fabsf.c+1-1
......@@ -1,6 +1,6 @@
11#include <math.h>
22
3#ifdef _SOFT_FLOAT
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
44
55#include "../fabsf.c"
66
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fma.c+1-1
......@@ -1,6 +1,6 @@
11#include <math.h>
22
3#if defined(_SOFT_FLOAT) || defined(BROKEN_PPC_D_ASM)
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__) || defined(BROKEN_PPC_D_ASM)
44
55#include "../fma.c"
66
lib/libc/wasi/libc-top-half/musl/src/math/powerpc/fmaf.c+1-1
......@@ -1,6 +1,6 @@
11#include <math.h>
22
3#ifdef _SOFT_FLOAT
3#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
44
55#include "../fmaf.c"
66
lib/libc/wasi/libc-top-half/musl/src/misc/ioctl.c+7-2
......@@ -6,6 +6,7 @@
66#include <stddef.h>
77#include <stdint.h>
88#include <string.h>
9#include <endian.h>
910#include "syscall.h"
1011
1112#define alignof(t) offsetof(struct { char c; t x; }, x)
......@@ -53,7 +54,7 @@ static const struct ioctl_compat_map compat_map[] = {
5354 { _IOWR('A', 0x23, char[136]), _IOWR('A', 0x23, char[132]), 0, WR, 1, 0 },
5455 { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_sync_ptr (flags only) */
5556 { 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 { 0, 0, 4, WR, 1, 0 }, /* snd_pcm_mmap_control (each member) */
5758
5859 /* VIDIOC_QUERYBUF, VIDIOC_QBUF, VIDIOC_DQBUF, VIDIOC_PREPARE_BUF */
5960 { _IOWR('V', 9, new_misaligned(68)), _IOWR('V', 9, char[68]), 68, WR, 1, OFFS(20, 24) },
......@@ -90,7 +91,11 @@ static void convert_ioctl_struct(const struct ioctl_compat_map *map, char *old,
9091 * if another exception appears this needs changing. */
9192 convert_ioctl_struct(map+1, old, new, dir);
9293 convert_ioctl_struct(map+2, old+4, new+8, dir);
93 convert_ioctl_struct(map+3, old+68, new+72, dir);
94 /* snd_pcm_mmap_control, special-cased due to kernel
95 * type definition having been botched. */
96 int adj = BYTE_ORDER==BIG_ENDIAN ? 4 : 0;
97 convert_ioctl_struct(map+3, old+68, new+72+adj, dir);
98 convert_ioctl_struct(map+3, old+72, new+76+3*adj, dir);
9499 return;
95100 }
96101 for (int i=0; i < map->noffs; i++) {
lib/libc/wasi/libc-top-half/musl/src/passwd/nscd_query.c+9-1
......@@ -40,7 +40,15 @@ retry:
4040 buf[0] = NSCDVERSION;
4141
4242 fd = socket(PF_UNIX, SOCK_STREAM | SOCK_CLOEXEC, 0);
43 if (fd < 0) return NULL;
43 if (fd < 0) {
44 if (errno == EAFNOSUPPORT) {
45 f = fopen("/dev/null", "re");
46 if (f)
47 errno = errno_save;
48 return f;
49 }
50 return 0;
51 }
4452
4553 if(!(f = fdopen(fd, "r"))) {
4654 close(fd);
lib/libc/wasi/libc-top-half/musl/src/process/fdop.h+5
......@@ -10,3 +10,8 @@ struct fdop {
1010 mode_t mode;
1111 char path[];
1212};
13
14#define malloc __libc_malloc
15#define calloc __libc_calloc
16#define realloc undef
17#define free __libc_free
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addclose.c+1
......@@ -5,6 +5,7 @@
55
66int posix_spawn_file_actions_addclose(posix_spawn_file_actions_t *fa, int fd)
77{
8 if (fd < 0) return EBADF;
89 struct fdop *op = malloc(sizeof *op);
910 if (!op) return ENOMEM;
1011 op->cmd = FDOP_CLOSE;
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_adddup2.c+1
......@@ -5,6 +5,7 @@
55
66int posix_spawn_file_actions_adddup2(posix_spawn_file_actions_t *fa, int srcfd, int fd)
77{
8 if (srcfd < 0 || fd < 0) return EBADF;
89 struct fdop *op = malloc(sizeof *op);
910 if (!op) return ENOMEM;
1011 op->cmd = FDOP_DUP2;
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addfchdir.c+1
......@@ -6,6 +6,7 @@
66
77int posix_spawn_file_actions_addfchdir_np(posix_spawn_file_actions_t *fa, int fd)
88{
9 if (fd < 0) return EBADF;
910 struct fdop *op = malloc(sizeof *op);
1011 if (!op) return ENOMEM;
1112 op->cmd = FDOP_FCHDIR;
lib/libc/wasi/libc-top-half/musl/src/process/posix_spawn_file_actions_addopen.c+1
......@@ -6,6 +6,7 @@
66
77int posix_spawn_file_actions_addopen(posix_spawn_file_actions_t *restrict fa, int fd, const char *restrict path, int flags, mode_t mode)
88{
9 if (fd < 0) return EBADF;
910 struct fdop *op = malloc(sizeof *op + strlen(path) + 1);
1011 if (!op) return ENOMEM;
1112 op->cmd = FDOP_OPEN;
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc/longjmp.S+31-1
......@@ -37,7 +37,37 @@ longjmp:
3737 lwz 29, 72(3)
3838 lwz 30, 76(3)
3939 lwz 31, 80(3)
40#ifndef _SOFT_FLOAT
40#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
41 mflr 0
42 bl 1f
43 .hidden __hwcap
44 .long __hwcap-.
451: mflr 4
46 lwz 5, 0(4)
47 lwzx 4, 4, 5
48 andis. 4, 4, 0x80
49 beq 1f
50 .long 0x11c35b01 /* evldd 14,88(3) */
51 .long 0x11e36301 /* ... */
52 .long 0x12036b01
53 .long 0x12237301
54 .long 0x12437b01
55 .long 0x12638301
56 .long 0x12838b01
57 .long 0x12a39301
58 .long 0x12c39b01
59 .long 0x12e3a301
60 .long 0x1303ab01
61 .long 0x1323b301
62 .long 0x1343bb01
63 .long 0x1363c301
64 .long 0x1383cb01
65 .long 0x13a3d301
66 .long 0x13c3db01
67 .long 0x13e3e301 /* evldd 31,224(3) */
68 .long 0x11a3eb01 /* evldd 13,232(3) */
691: mtlr 0
70#else
4171 lfd 14,88(3)
4272 lfd 15,96(3)
4373 lfd 16,104(3)
lib/libc/wasi/libc-top-half/musl/src/setjmp/powerpc/setjmp.S+31-1
......@@ -37,7 +37,37 @@ setjmp:
3737 stw 29, 72(3)
3838 stw 30, 76(3)
3939 stw 31, 80(3)
40#ifndef _SOFT_FLOAT
40#if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
41 mflr 0
42 bl 1f
43 .hidden __hwcap
44 .long __hwcap-.
451: mflr 4
46 lwz 5, 0(4)
47 lwzx 4, 4, 5
48 andis. 4, 4, 0x80
49 beq 1f
50 .long 0x11c35b21 /* evstdd 14,88(3) */
51 .long 0x11e36321 /* ... */
52 .long 0x12036b21
53 .long 0x12237321
54 .long 0x12437b21
55 .long 0x12638321
56 .long 0x12838b21
57 .long 0x12a39321
58 .long 0x12c39b21
59 .long 0x12e3a321
60 .long 0x1303ab21
61 .long 0x1323b321
62 .long 0x1343bb21
63 .long 0x1363c321
64 .long 0x1383cb21
65 .long 0x13a3d321
66 .long 0x13c3db21
67 .long 0x13e3e321 /* evstdd 31,224(3) */
68 .long 0x11a3eb21 /* evstdd 13,232(3) */
691: mtlr 0
70#else
4171 stfd 14,88(3)
4272 stfd 15,96(3)
4373 stfd 16,104(3)
lib/libc/wasi/libc-top-half/musl/src/signal/block.c+2-2
......@@ -3,9 +3,9 @@
33#include <signal.h>
44
55static const unsigned long all_mask[] = {
6#if ULONG_MAX == 0xffffffff && _NSIG == 129
6#if ULONG_MAX == 0xffffffff && _NSIG > 65
77 -1UL, -1UL, -1UL, -1UL
8#elif ULONG_MAX == 0xffffffff
8#elif ULONG_MAX == 0xffffffff || _NSIG > 65
99 -1UL, -1UL
1010#else
1111 -1UL
lib/libc/wasi/libc-top-half/musl/src/stat/futimesat.c+9
......@@ -2,7 +2,9 @@
22#include <sys/time.h>
33#include <sys/stat.h>
44#include <errno.h>
5#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
56#include "syscall.h"
7#endif
68
79int __futimesat(int dirfd, const char *pathname, const struct timeval times[2])
810{
......@@ -10,8 +12,15 @@ int __futimesat(int dirfd, const char *pathname, const struct timeval times[2])
1012 if (times) {
1113 int i;
1214 for (i=0; i<2; i++) {
15#ifdef __wasilibc_unmodified_upstream // WASI has no syscall
1316 if (times[i].tv_usec >= 1000000ULL)
1417 return __syscall_ret(-EINVAL);
18#else
19 if (times[i].tv_usec >= 1000000ULL) {
20 errno = EINVAL;
21 return -1;
22 }
23#endif
1524 ts[i].tv_sec = times[i].tv_sec;
1625 ts[i].tv_nsec = times[i].tv_usec * 1000;
1726 }
lib/libc/wasi/libc-top-half/musl/src/stdio/fgetws.c+1-6
......@@ -1,6 +1,5 @@
11#include "stdio_impl.h"
22#include <wchar.h>
3#include <errno.h>
43
54wint_t __fgetwc_unlocked(FILE *);
65
......@@ -12,10 +11,6 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
1211
1312 FLOCK(f);
1413
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;
1914 for (; n; n--) {
2015 wint_t c = __fgetwc_unlocked(f);
2116 if (c == WEOF) break;
......@@ -23,7 +18,7 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
2318 if (c == '\n') break;
2419 }
2520 *p = 0;
26 if (ferror(f) || errno==EILSEQ) p = s;
21 if (ferror(f)) p = s;
2722
2823 FUNLOCK(f);
2924
lib/libc/wasi/libc-top-half/musl/src/stdio/fseek.c+7
......@@ -1,7 +1,14 @@
11#include "stdio_impl.h"
2#include <errno.h>
23
34int __fseeko_unlocked(FILE *f, off_t off, int whence)
45{
6 /* Fail immediately for invalid whence argument. */
7 if (whence != SEEK_CUR && whence != SEEK_SET && whence != SEEK_END) {
8 errno = EINVAL;
9 return -1;
10 }
11
512 /* Adjust relative offset for unread data in buffer, if any. */
613 if (whence == SEEK_CUR && f->rend) off -= f->rend - f->rpos;
714
lib/libc/wasi/libc-top-half/musl/src/stdio/getdelim.c+5-3
......@@ -55,9 +55,11 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
5555 *s = tmp;
5656 *n = m;
5757 }
58 memcpy(*s+i, f->rpos, k);
59 f->rpos += k;
60 i += k;
58 if (k) {
59 memcpy(*s+i, f->rpos, k);
60 f->rpos += k;
61 i += k;
62 }
6163 if (z) break;
6264 if ((c = getc_unlocked(f)) == EOF) {
6365 if (!i || !feof(f)) {
lib/libc/wasi/libc-top-half/musl/src/stdio/popen.c+6-18
......@@ -31,25 +31,12 @@ FILE *popen(const char *cmd, const char *mode)
3131 __syscall(SYS_close, p[1]);
3232 return NULL;
3333 }
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 }
5034
5135 e = ENOMEM;
5236 if (!posix_spawn_file_actions_init(&fa)) {
37 for (FILE *l = *__ofl_lock(); l; l=l->next)
38 if (l->pipe_pid && posix_spawn_file_actions_addclose(&fa, l->fd))
39 goto fail;
5340 if (!posix_spawn_file_actions_adddup2(&fa, p[1-op], 1-op)) {
5441 if (!(e = posix_spawn(&pid, "/bin/sh", &fa, 0,
5542 (char *[]){ "sh", "-c", (char *)cmd, 0 }, __environ))) {
......@@ -58,13 +45,14 @@ FILE *popen(const char *cmd, const char *mode)
5845 if (!strchr(mode, 'e'))
5946 fcntl(p[op], F_SETFD, 0);
6047 __syscall(SYS_close, p[1-op]);
61 FUNLOCK(f);
48 __ofl_unlock();
6249 return f;
6350 }
6451 }
52fail:
53 __ofl_unlock();
6554 posix_spawn_file_actions_destroy(&fa);
6655 }
67fail:
6856 fclose(f);
6957 __syscall(SYS_close, p[1-op]);
7058
lib/libc/wasi/libc-top-half/musl/src/stdlib/qsort.c+20-17
......@@ -24,6 +24,7 @@
2424/* Smoothsort, an adaptive variant of Heapsort. Memory usage: O(1).
2525 Run time: Worst case O(n log n), close to O(n) in the mostly-sorted case. */
2626
27#define _BSD_SOURCE
2728#include <stdint.h>
2829#include <stdlib.h>
2930#include <string.h>
......@@ -31,7 +32,7 @@
3132#include "atomic.h"
3233#define ntz(x) a_ctz_l((x))
3334
34typedef int (*cmpfun)(const void *, const void *);
35typedef int (*cmpfun)(const void *, const void *, void *);
3536
3637static inline int pntz(size_t p[2]) {
3738 int r = ntz(p[0] - 1);
......@@ -88,7 +89,7 @@ static inline void shr(size_t p[2], int n)
8889 p[1] >>= n;
8990}
9091
91static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size_t lp[])
92static void sift(unsigned char *head, size_t width, cmpfun cmp, void *arg, int pshift, size_t lp[])
9293{
9394 unsigned char *rt, *lf;
9495 unsigned char *ar[14 * sizeof(size_t) + 1];
......@@ -99,10 +100,10 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size
99100 rt = head - width;
100101 lf = head - width - lp[pshift - 2];
101102
102 if((*cmp)(ar[0], lf) >= 0 && (*cmp)(ar[0], rt) >= 0) {
103 if(cmp(ar[0], lf, arg) >= 0 && cmp(ar[0], rt, arg) >= 0) {
103104 break;
104105 }
105 if((*cmp)(lf, rt) >= 0) {
106 if(cmp(lf, rt, arg) >= 0) {
106107 ar[i++] = lf;
107108 head = lf;
108109 pshift -= 1;
......@@ -115,7 +116,7 @@ static void sift(unsigned char *head, size_t width, cmpfun cmp, int pshift, size
115116 cycle(width, ar, i);
116117}
117118
118static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2], int pshift, int trusty, size_t lp[])
119static void trinkle(unsigned char *head, size_t width, cmpfun cmp, void *arg, size_t pp[2], int pshift, int trusty, size_t lp[])
119120{
120121 unsigned char *stepson,
121122 *rt, *lf;
......@@ -130,13 +131,13 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2],
130131 ar[0] = head;
131132 while(p[0] != 1 || p[1] != 0) {
132133 stepson = head - lp[pshift];
133 if((*cmp)(stepson, ar[0]) <= 0) {
134 if(cmp(stepson, ar[0], arg) <= 0) {
134135 break;
135136 }
136137 if(!trusty && pshift > 1) {
137138 rt = head - width;
138139 lf = head - width - lp[pshift - 2];
139 if((*cmp)(rt, stepson) >= 0 || (*cmp)(lf, stepson) >= 0) {
140 if(cmp(rt, stepson, arg) >= 0 || cmp(lf, stepson, arg) >= 0) {
140141 break;
141142 }
142143 }
......@@ -150,11 +151,11 @@ static void trinkle(unsigned char *head, size_t width, cmpfun cmp, size_t pp[2],
150151 }
151152 if(!trusty) {
152153 cycle(width, ar, i);
153 sift(head, width, cmp, pshift, lp);
154 sift(head, width, cmp, arg, pshift, lp);
154155 }
155156}
156157
157void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
158void __qsort_r(void *base, size_t nel, size_t width, cmpfun cmp, void *arg)
158159{
159160 size_t lp[12*sizeof(size_t)];
160161 size_t i, size = width * nel;
......@@ -173,16 +174,16 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
173174
174175 while(head < high) {
175176 if((p[0] & 3) == 3) {
176 sift(head, width, cmp, pshift, lp);
177 sift(head, width, cmp, arg, pshift, lp);
177178 shr(p, 2);
178179 pshift += 2;
179180 } else {
180181 if(lp[pshift - 1] >= high - head) {
181 trinkle(head, width, cmp, p, pshift, 0, lp);
182 trinkle(head, width, cmp, arg, p, pshift, 0, lp);
182183 } else {
183 sift(head, width, cmp, pshift, lp);
184 sift(head, width, cmp, arg, pshift, lp);
184185 }
185
186
186187 if(pshift == 1) {
187188 shl(p, 1);
188189 pshift = 0;
......@@ -191,12 +192,12 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
191192 pshift = 1;
192193 }
193194 }
194
195
195196 p[0] |= 1;
196197 head += width;
197198 }
198199
199 trinkle(head, width, cmp, p, pshift, 0, lp);
200 trinkle(head, width, cmp, arg, p, pshift, 0, lp);
200201
201202 while(pshift != 1 || p[0] != 1 || p[1] != 0) {
202203 if(pshift <= 1) {
......@@ -208,11 +209,13 @@ void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
208209 pshift -= 2;
209210 p[0] ^= 7;
210211 shr(p, 1);
211 trinkle(head - lp[pshift] - width, width, cmp, p, pshift + 1, 1, lp);
212 trinkle(head - lp[pshift] - width, width, cmp, arg, p, pshift + 1, 1, lp);
212213 shl(p, 1);
213214 p[0] |= 1;
214 trinkle(head - width, width, cmp, p, pshift, 1, lp);
215 trinkle(head - width, width, cmp, arg, p, pshift, 1, lp);
215216 }
216217 head -= width;
217218 }
218219}
220
221weak_alias(__qsort_r, qsort_r);
lib/libc/wasi/libc-top-half/musl/src/stdlib/qsort_nr.c created+14
......@@ -0,0 +1,14 @@
1#define _BSD_SOURCE
2#include <stdlib.h>
3
4typedef int (*cmpfun)(const void *, const void *);
5
6static int wrapper_cmp(const void *v1, const void *v2, void *cmp)
7{
8 return ((cmpfun)cmp)(v1, v2);
9}
10
11void qsort(void *base, size_t nel, size_t width, cmpfun cmp)
12{
13 __qsort_r(base, nel, width, wrapper_cmp, cmp);
14}
lib/libc/wasi/libc-top-half/musl/src/stdlib/strtod.c-21
......@@ -46,24 +46,3 @@ long double strtold(const char *restrict s, char **restrict p)
4646 return strtox(s, p, 2);
4747#endif
4848}
49
50#ifdef __wasilibc_unmodified_upstream // WASI doesn't support signature-changing aliases
51weak_alias(strtof, strtof_l);
52weak_alias(strtod, strtod_l);
53weak_alias(strtold, strtold_l);
54weak_alias(strtof, __strtof_l);
55weak_alias(strtod, __strtod_l);
56weak_alias(strtold, __strtold_l);
57#else
58// WebAssembly doesn't permit signature-changing aliases, so use wrapper
59// functions instead.
60weak float strtof_l(const char *restrict s, char **restrict p, locale_t loc) {
61 return strtof(s, p);
62}
63weak double strtod_l(const char *restrict s, char **restrict p, locale_t loc) {
64 return strtod(s, p);
65}
66weak 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/thread/pthread_getname_np.c created+25
......@@ -0,0 +1,25 @@
1#define _GNU_SOURCE
2#include <fcntl.h>
3#include <unistd.h>
4#include <sys/prctl.h>
5
6#include "pthread_impl.h"
7
8int pthread_getname_np(pthread_t thread, char *name, size_t len)
9{
10 int fd, cs, status = 0;
11 char f[sizeof "/proc/self/task//comm" + 3*sizeof(int)];
12
13 if (len < 16) return ERANGE;
14
15 if (thread == pthread_self())
16 return prctl(PR_GET_NAME, (unsigned long)name, 0UL, 0UL, 0UL) ? errno : 0;
17
18 snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
19 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
20 if ((fd = open(f, O_RDONLY|O_CLOEXEC)) < 0 || (len = read(fd, name, len)) == -1) status = errno;
21 else name[len-1] = 0; /* remove trailing new line only if successful */
22 if (fd >= 0) close(fd);
23 pthread_setcancelstate(cs, 0);
24 return status;
25}
lib/libc/wasi/libc-top-half/musl/src/thread/pthread_setname_np.c+1-1
......@@ -19,7 +19,7 @@ int pthread_setname_np(pthread_t thread, const char *name)
1919
2020 snprintf(f, sizeof f, "/proc/self/task/%d/comm", thread->tid);
2121 pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs);
22 if ((fd = open(f, O_WRONLY)) < 0 || write(fd, name, len) < 0) status = errno;
22 if ((fd = open(f, O_WRONLY|O_CLOEXEC)) < 0 || write(fd, name, len) < 0) status = errno;
2323 if (fd >= 0) close(fd);
2424 pthread_setcancelstate(cs, 0);
2525 return status;
lib/libc/wasi/libc-top-half/musl/src/time/__tz.c+25-15
......@@ -5,6 +5,7 @@
55#include <string.h>
66#ifdef __wasilibc_unmodified_upstream // timezone data
77#include <sys/mman.h>
8#include <ctype.h>
89#endif
910#include "libc.h"
1011#include "lock.h"
......@@ -159,10 +160,21 @@ static void do_tzset()
159160 }
160161 if (old_tz) memcpy(old_tz, s, i+1);
161162
163 int posix_form = 0;
164 if (*s != ':') {
165 p = s;
166 char dummy_name[TZNAME_MAX+1];
167 getname(dummy_name, &p);
168 if (p!=s && (*p == '+' || *p == '-' || isdigit(*p)
169 || !strcmp(dummy_name, "UTC")
170 || !strcmp(dummy_name, "GMT")))
171 posix_form = 1;
172 }
173
162174 /* Non-suid can use an absolute tzfile pathname or a relative
163175 * pathame beginning with "."; in secure mode, only the
164176 * standard path will be searched. */
165 if (*s == ':' || ((p=strchr(s, '/')) && !memchr(s, ',', p-s))) {
177 if (!posix_form) {
166178 if (*s == ':') s++;
167179 if (*s == '/' || *s == '.') {
168180 if (!libc.secure || !strcmp(s, "/etc/localtime"))
......@@ -286,22 +298,20 @@ static size_t scan_trans(long long t, int local, size_t *alt)
286298 n = (index-trans)>>scale;
287299 if (a == n-1) return -1;
288300 if (a == 0) {
289 x = zi_read32(trans + (a<<scale));
290 if (scale == 3) x = x<<32 | zi_read32(trans + (a<<scale) + 4);
301 x = zi_read32(trans);
302 if (scale == 3) x = x<<32 | zi_read32(trans + 4);
291303 else x = (int32_t)x;
292 if (local) off = (int32_t)zi_read32(types + 6 * index[a-1]);
304 /* Find the lowest non-DST type, or 0 if none. */
305 size_t j = 0;
306 for (size_t i=abbrevs-types; i; i-=6) {
307 if (!types[i-6+4]) j = i-6;
308 }
309 if (local) off = (int32_t)zi_read32(types + j);
310 /* If t is before first transition, use the above-found type
311 * and the index-zero (after transition) type as the alt. */
293312 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 }
313 if (alt) *alt = index[0];
314 return j/6;
305315 }
306316 }
307317
lib/libc/wasi/libc-top-half/musl/src/unistd/nice.c+8-1
......@@ -1,4 +1,5 @@
11#include <unistd.h>
2#include <errno.h>
23#include <sys/resource.h>
34#include <limits.h>
45#include "syscall.h"
......@@ -12,5 +13,11 @@ int nice(int inc)
1213 prio += getpriority(PRIO_PROCESS, 0);
1314 if (prio > NZERO-1) prio = NZERO-1;
1415 if (prio < -NZERO) prio = -NZERO;
15 return setpriority(PRIO_PROCESS, 0, prio) ? -1 : prio;
16 if (setpriority(PRIO_PROCESS, 0, prio)) {
17 if (errno == EACCES)
18 errno = EPERM;
19 return -1;
20 } else {
21 return prio;
22 }
1623}