Skip to content

Commit 8c63037

Browse files
committed
Update the WASI libc
Update our copy of wasi-libc up to the commit 30094b6ed05f19cee102115215863d185f2db4f0 from the upstream repository.
1 parent 47c4d44 commit 8c63037

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

81 files changed

+581
-225
lines changed

lib/libc/wasi/libc-bottom-half/cloudlibc/src/libc/sys/stat/stat_impl.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
#include <wasi/api.h>
1010

1111
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);
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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -574,18 +574,6 @@ _Noreturn void __wasi_proc_exit(
574574
__imported_wasi_snapshot_preview1_proc_exit((int32_t) rval);
575575
}
576576

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-
589577
int32_t __imported_wasi_snapshot_preview1_sched_yield() __attribute__((
590578
__import_module__("wasi_snapshot_preview1"),
591579
__import_name__("sched_yield")
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
10+
int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) {
11+
int ret = -1;
12+
13+
__wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret);
14+
15+
if (error != 0) {
16+
errno = error;
17+
return -1;
18+
}
19+
20+
// Clear sockaddr to indicate undefined address
21+
memset(addr, 0, *addrlen);
22+
// might be AF_UNIX or AF_INET
23+
addr->sa_family = AF_UNSPEC;
24+
*addrlen = sizeof(struct sockaddr);
25+
26+
return ret;
27+
}
28+
29+
int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) {
30+
int ret = -1;
31+
32+
if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) {
33+
errno = EINVAL;
34+
return -1;
35+
}
36+
37+
__wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret);
38+
39+
if (error != 0) {
40+
errno = error;
41+
return -1;
42+
}
43+
44+
// Clear sockaddr to indicate undefined address
45+
memset(addr, 0, *addrlen);
46+
// might be AF_UNIX or AF_INET
47+
addr->sa_family = AF_UNSPEC;
48+
*addrlen = sizeof(struct sockaddr);
49+
50+
return ret;
51+
}

lib/libc/wasi/libc-bottom-half/sources/chdir.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ 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;
5353
}
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

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,20 @@ static int find_relpath2(
3131
static 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
3941
static 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

4650
int open(const char *path, int oflag, ...) {
@@ -139,6 +143,28 @@ int utime(const char *path, const struct utimbuf *times) {
139143
0);
140144
}
141145

146+
int 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+
142168
int 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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ int isascii(int);
6464
int 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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
284288
struct 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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
227227
int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
228228
int pthread_getattr_np(pthread_t, pthread_attr_t *);
229229
int pthread_setname_np(pthread_t, const char *);
230+
int pthread_getname_np(pthread_t, char *, size_t);
230231
int pthread_getattr_default_np(pthread_attr_t *);
231232
int pthread_setattr_default_np(const pthread_attr_t *);
232233
int pthread_tryjoin_np(pthread_t, void **);

lib/libc/wasi/libc-top-half/musl/include/setjmp.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,36 @@ 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)
2228
typedef jmp_buf sigjmp_buf;
23-
int sigsetjmp (sigjmp_buf, int);
29+
int 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)
29-
int _setjmp (jmp_buf);
35+
int _setjmp (jmp_buf) __setjmp_attr;
3036
_Noreturn void _longjmp (jmp_buf, int);
3137
#endif
3238

33-
int setjmp (jmp_buf);
39+
int setjmp (jmp_buf) __setjmp_attr;
3440
_Noreturn void longjmp (jmp_buf, int);
3541

3642
#define setjmp setjmp
3743
#else
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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
186191
struct 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
279284
typedef 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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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)

0 commit comments

Comments
 (0)