Skip to content

Update the WASI libc to 30094b6ed05f19cee102115215863d185f2db4f0 #11864

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,18 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
if (times == NULL) {
// Update both timestamps.
*flags = __WASI_FSTFLAGS_ATIM_NOW | __WASI_FSTFLAGS_MTIM_NOW;
*st_atim = (__wasi_timestamp_t) { 0 };
*st_mtim = (__wasi_timestamp_t) { 0 };
} else {
// Set individual timestamps.
*flags = 0;
switch (times[0].tv_nsec) {
case UTIME_NOW:
*flags |= __WASI_FSTFLAGS_ATIM_NOW;
*st_atim = (__wasi_timestamp_t) { 0 };
break;
case UTIME_OMIT:
*st_atim = (__wasi_timestamp_t) { 0 };
break;
default:
*flags |= __WASI_FSTFLAGS_ATIM;
Expand All @@ -94,8 +98,10 @@ static inline bool utimens_get_timestamps(const struct timespec *times,
switch (times[1].tv_nsec) {
case UTIME_NOW:
*flags |= __WASI_FSTFLAGS_MTIM_NOW;
*st_mtim = (__wasi_timestamp_t) { 0 };
break;
case UTIME_OMIT:
*st_mtim = (__wasi_timestamp_t) { 0 };
break;
default:
*flags |= __WASI_FSTFLAGS_MTIM;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
#include <wasi/api.h>

int gettimeofday(struct timeval *restrict tp, void *tz) {
__wasi_timestamp_t ts = 0;
(void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
*tp = timestamp_to_timeval(ts);
if (tp != NULL) {
__wasi_timestamp_t ts = 0;
(void)__wasi_clock_time_get(__WASI_CLOCKID_REALTIME, 1000, &ts);
*tp = timestamp_to_timeval(ts);
}
return 0;
}
12 changes: 0 additions & 12 deletions lib/libc/wasi/libc-bottom-half/sources/__wasilibc_real.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,18 +574,6 @@ _Noreturn void __wasi_proc_exit(
__imported_wasi_snapshot_preview1_proc_exit((int32_t) rval);
}

int32_t __imported_wasi_snapshot_preview1_proc_raise(int32_t arg0) __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("proc_raise")
));

__wasi_errno_t __wasi_proc_raise(
__wasi_signal_t sig
){
int32_t ret = __imported_wasi_snapshot_preview1_proc_raise((int32_t) sig);
return (uint16_t) ret;
}

int32_t __imported_wasi_snapshot_preview1_sched_yield() __attribute__((
__import_module__("wasi_snapshot_preview1"),
__import_name__("sched_yield")
Expand Down
51 changes: 51 additions & 0 deletions lib/libc/wasi/libc-bottom-half/sources/accept.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: BSD-2-Clause

#include <sys/socket.h>

#include <assert.h>
#include <wasi/api.h>
#include <errno.h>
#include <string.h>

int accept(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen) {
int ret = -1;

__wasi_errno_t error = __wasi_sock_accept(socket, 0, &ret);

if (error != 0) {
errno = error;
return -1;
}

// Clear sockaddr to indicate undefined address
memset(addr, 0, *addrlen);
// might be AF_UNIX or AF_INET
addr->sa_family = AF_UNSPEC;
*addrlen = sizeof(struct sockaddr);

return ret;
}

int accept4(int socket, struct sockaddr *restrict addr, socklen_t *restrict addrlen, int flags) {
int ret = -1;

if (flags & ~(SOCK_NONBLOCK | SOCK_CLOEXEC)) {
errno = EINVAL;
return -1;
}

__wasi_errno_t error = __wasi_sock_accept(socket, (flags & SOCK_NONBLOCK) ? __WASI_FDFLAGS_NONBLOCK : 0, &ret);

if (error != 0) {
errno = error;
return -1;
}

// Clear sockaddr to indicate undefined address
memset(addr, 0, *addrlen);
// might be AF_UNIX or AF_INET
addr->sa_family = AF_UNSPEC;
*addrlen = sizeof(struct sockaddr);

return ret;
}
9 changes: 5 additions & 4 deletions lib/libc/wasi/libc-bottom-half/sources/chdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ int chdir(const char *path)
size_t len = strlen(abs) + 1;
int copy_relative = strcmp(relative_buf, ".") != 0;
int mid = copy_relative && abs[0] != 0;
char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0));
char *new_cwd = malloc(len + (copy_relative ? strlen(relative_buf) + mid: 0)+1);
if (new_cwd == NULL) {
errno = ENOMEM;
return -1;
}
new_cwd[0] = '/';
strcpy(new_cwd + 1, abs);
if (mid)
new_cwd[strlen(abs) + 1] = '/';
new_cwd[len] = '/';
if (copy_relative)
strcpy(new_cwd + 1 + mid + strlen(abs), relative_buf);

Expand Down Expand Up @@ -95,9 +95,10 @@ static const char *make_absolute(const char *path) {
int need_slash = __wasilibc_cwd[cwd_len - 1] == '/' ? 0 : 1;
size_t alloc_len = cwd_len + path_len + 1 + need_slash;
if (alloc_len > make_absolute_len) {
make_absolute_buf = realloc(make_absolute_buf, alloc_len);
if (make_absolute_buf == NULL)
char *tmp = realloc(make_absolute_buf, alloc_len);
if (tmp == NULL)
return NULL;
make_absolute_buf = tmp;
make_absolute_len = alloc_len;
}
strcpy(make_absolute_buf, __wasilibc_cwd);
Expand Down
30 changes: 28 additions & 2 deletions lib/libc/wasi/libc-bottom-half/sources/posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,20 @@ static int find_relpath2(
static int find_relpath(const char *path, char **relative) {
static __thread char *relative_buf = NULL;
static __thread size_t relative_buf_len = 0;
int fd = find_relpath2(path, &relative_buf, &relative_buf_len);
// find_relpath2 can update relative_buf, so assign it after the call
*relative = relative_buf;
return find_relpath2(path, relative, &relative_buf_len);
return fd;
}

// same as `find_relpath`, but uses another set of static variables to cache
static int find_relpath_alt(const char *path, char **relative) {
static __thread char *relative_buf = NULL;
static __thread size_t relative_buf_len = 0;
int fd = find_relpath2(path, &relative_buf, &relative_buf_len);
// find_relpath2 can update relative_buf, so assign it after the call
*relative = relative_buf;
return find_relpath2(path, relative, &relative_buf_len);
return fd;
}

int open(const char *path, int oflag, ...) {
Expand Down Expand Up @@ -139,6 +143,28 @@ int utime(const char *path, const struct utimbuf *times) {
0);
}

int utimes(const char *path, const struct timeval times[2]) {
char *relative_path;
int dirfd = find_relpath(path, &relative_path);

// If we can't find a preopen for it, indicate that we lack capabilities.
if (dirfd == -1) {
errno = ENOTCAPABLE;
return -1;
}

return __wasilibc_nocwd_utimensat(
dirfd, relative_path,
times ? ((struct timespec [2]) {
{ .tv_sec = times[0].tv_sec,
.tv_nsec = times[0].tv_usec * 1000 },
{ .tv_sec = times[1].tv_sec,
.tv_nsec = times[1].tv_usec * 1000 },
})
: NULL,
0);
}

int unlink(const char *path) {
char *relative_path;
int dirfd = find_relpath(path, &relative_path);
Expand Down
2 changes: 2 additions & 0 deletions lib/libc/wasi/libc-top-half/musl/include/ctype.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ int isascii(int);
int toascii(int);
#define _tolower(a) ((a)|0x20)
#define _toupper(a) ((a)&0x5f)
#ifndef __cplusplus
#define isascii(a) (0 ? isascii(a) : (unsigned)(a) < 128)
#endif

#endif

Expand Down
2 changes: 2 additions & 0 deletions lib/libc/wasi/libc-top-half/musl/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,8 @@ typedef struct {
#define NT_ARM_PAC_MASK 0x406
#define NT_ARM_PACA_KEYS 0x407
#define NT_ARM_PACG_KEYS 0x408
#define NT_ARM_TAGGED_ADDR_CTRL 0x409
#define NT_ARM_PAC_ENABLED_KEYS 0x40a
#define NT_METAG_CBUF 0x500
#define NT_METAG_RPIPE 0x501
#define NT_METAG_TLS 0x502
Expand Down
4 changes: 3 additions & 1 deletion lib/libc/wasi/libc-top-half/musl/include/locale.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ extern "C" {
#include <features.h>

#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
#ifdef __cplusplus
#if __cplusplus >= 201103L
#define NULL nullptr
#elif defined(__cplusplus)
#define NULL 0L
#else
#define NULL ((void*)0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
#define ETH_P_1588 0x88F7
#define ETH_P_NCSI 0x88F8
#define ETH_P_PRP 0x88FB
#define ETH_P_CFM 0x8902
#define ETH_P_FCOE 0x8906
#define ETH_P_TDLS 0x890D
#define ETH_P_FIP 0x8914
Expand Down
1 change: 1 addition & 0 deletions lib/libc/wasi/libc-top-half/musl/include/netinet/in.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ struct ipv6_mreq {
#define INADDR_BROADCAST ((in_addr_t) 0xffffffff)
#define INADDR_NONE ((in_addr_t) 0xffffffff)
#define INADDR_LOOPBACK ((in_addr_t) 0x7f000001)
#define INADDR_DUMMY ((in_addr_t) 0xc0000008)

#define INADDR_UNSPEC_GROUP ((in_addr_t) 0xe0000000)
#define INADDR_ALLHOSTS_GROUP ((in_addr_t) 0xe0000001)
Expand Down
11 changes: 11 additions & 0 deletions lib/libc/wasi/libc-top-half/musl/include/netinet/tcp.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ enum {
TCP_NLA_SRTT,
TCP_NLA_TIMEOUT_REHASH,
TCP_NLA_BYTES_NOTSENT,
TCP_NLA_EDT,
TCP_NLA_TTL,
};

#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
Expand Down Expand Up @@ -281,12 +283,21 @@ struct tcp_repair_window {
uint32_t rcv_wup;
};

#define TCP_RECEIVE_ZEROCOPY_FLAG_TLB_CLEAN_HINT 0x1

struct tcp_zerocopy_receive {
uint64_t address;
uint32_t length;
uint32_t recv_skip_hint;
uint32_t inq;
int32_t err;
uint64_t copybuf_address;
int32_t copybuf_len;
uint32_t flags;
uint64_t msg_control;
uint64_t msg_controllen;
uint32_t msg_flags;
uint32_t reserved;
};

#endif
Expand Down
1 change: 1 addition & 0 deletions lib/libc/wasi/libc-top-half/musl/include/pthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ int pthread_getaffinity_np(pthread_t, size_t, struct cpu_set_t *);
int pthread_setaffinity_np(pthread_t, size_t, const struct cpu_set_t *);
int pthread_getattr_np(pthread_t, pthread_attr_t *);
int pthread_setname_np(pthread_t, const char *);
int pthread_getname_np(pthread_t, char *, size_t);
int pthread_getattr_default_np(pthread_attr_t *);
int pthread_setattr_default_np(const pthread_attr_t *);
int pthread_tryjoin_np(pthread_t, void **);
Expand Down
14 changes: 11 additions & 3 deletions lib/libc/wasi/libc-top-half/musl/include/setjmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,36 @@ typedef struct __jmp_buf_tag {
unsigned long __ss[128/sizeof(long)];
} jmp_buf[1];

#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
#define __setjmp_attr __attribute__((__returns_twice__))
#else
#define __setjmp_attr
#endif

#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
typedef jmp_buf sigjmp_buf;
int sigsetjmp (sigjmp_buf, int);
int sigsetjmp (sigjmp_buf, int) __setjmp_attr;
_Noreturn void siglongjmp (sigjmp_buf, int);
#endif

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
int _setjmp (jmp_buf);
int _setjmp (jmp_buf) __setjmp_attr;
_Noreturn void _longjmp (jmp_buf, int);
#endif

int setjmp (jmp_buf);
int setjmp (jmp_buf) __setjmp_attr;
_Noreturn void longjmp (jmp_buf, int);

#define setjmp setjmp
#else
#warning setjmp is not yet implemented for WASI
#endif

#undef __setjmp_attr

#ifdef __cplusplus
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions lib/libc/wasi/libc-top-half/musl/include/signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ typedef struct sigaltstack stack_t;
#define SEGV_ACCERR 2
#define SEGV_BNDERR 3
#define SEGV_PKUERR 4
#define SEGV_MTEAERR 8
#define SEGV_MTESERR 9

#define BUS_ADRALN 1
#define BUS_ADRERR 2
Expand Down Expand Up @@ -183,6 +185,9 @@ struct sigaction {
#define sa_handler __sa_handler.sa_handler
#define sa_sigaction __sa_handler.sa_sigaction

#define SA_UNSUPPORTED 0x00000400
#define SA_EXPOSE_TAGBITS 0x00000800

struct sigevent {
union sigval sigev_value;
int sigev_signo;
Expand Down Expand Up @@ -277,6 +282,9 @@ void (*sigset(int, void (*)(int)))(int);
#if defined(_BSD_SOURCE) || defined(_GNU_SOURCE)
#define NSIG _NSIG
typedef void (*sig_t)(int);

#define SYS_SECCOMP 1
#define SYS_USER_DISPATCH 2
#endif

#ifdef _GNU_SOURCE
Expand Down
3 changes: 3 additions & 0 deletions lib/libc/wasi/libc-top-half/musl/include/stdc-predef.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
#define __STDC_IEC_559__ 1
#endif

#define __STDC_UTF_16__ 1
#define __STDC_UTF_32__ 1

#endif
4 changes: 3 additions & 1 deletion lib/libc/wasi/libc-top-half/musl/include/stddef.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#ifndef _STDDEF_H
#define _STDDEF_H

#ifdef __cplusplus
#if __cplusplus >= 201103L
#define NULL nullptr
#elif defined(__cplusplus)
#define NULL 0L
#else
#define NULL ((void*)0)
Expand Down
4 changes: 3 additions & 1 deletion lib/libc/wasi/libc-top-half/musl/include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ extern "C" {
#include <bits/alltypes.h>

#ifdef __wasilibc_unmodified_upstream /* Use the compiler's definition of NULL */
#ifdef __cplusplus
#if __cplusplus >= 201103L
#define NULL nullptr
#elif defined(__cplusplus)
#define NULL 0L
#else
#define NULL ((void*)0)
Expand Down
Loading