Skip to content
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

Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5 #19614

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 0 additions & 5 deletions lib/libc/include/wasm-wasi-musl/__errno.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,11 @@
extern "C" {
#endif

#ifdef __cplusplus
extern thread_local int errno;
#else
extern _Thread_local int errno;
#endif

#define errno errno

#ifdef __cplusplus
}
#endif

#endif
13 changes: 10 additions & 3 deletions lib/libc/include/wasm-wasi-musl/__header_dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,26 @@
#define DT_REG __WASI_FILETYPE_REGULAR_FILE
#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN

// DT_SOCK is not supported in WASI Preview 1 (but will be in Preview 2). We
// define it regardless so that libc++'s `<filesystem>` implementation builds.
// The exact value is mostly arbitrary, but chosen so it doesn't conflict with
// any of the existing `__WASI_FILETYPE_*` flags. We do not expect any new
// flags to be added to WASI Preview 1, so that should be sufficient.
#define DT_SOCK 20

#define IFTODT(x) (__wasilibc_iftodt(x))
#define DTTOIF(x) (__wasilibc_dttoif(x))

int __wasilibc_iftodt(int x);
int __wasilibc_dttoif(int x);

#include <__struct_dirent.h>
#include <__typedef_DIR.h>

#ifdef __cplusplus
extern "C" {
#endif

int __wasilibc_iftodt(int x);
int __wasilibc_dttoif(int x);

int closedir(DIR *);
DIR *opendir(const char *);
DIR *fdopendir(int);
Expand Down
46 changes: 42 additions & 4 deletions lib/libc/include/wasm-wasi-musl/__header_sys_socket.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef __wasilibc___header_sys_socket_h
#define __wasilibc___header_sys_socket_h

#include <__wasi_snapshot.h>
#include <__struct_msghdr.h>
#include <__struct_sockaddr.h>
#include <__struct_sockaddr_storage.h>
Expand All @@ -11,9 +12,42 @@
#define SHUT_WR __WASI_SDFLAGS_WR
#define SHUT_RDWR (SHUT_RD | SHUT_WR)

#ifdef __wasilibc_use_wasip2
#define MSG_DONTWAIT 0x0040
#define MSG_NOSIGNAL 0x4000
#define MSG_PEEK 0x0002
#define MSG_WAITALL 0x0100
#define MSG_TRUNC 0x0020

#define SOL_IP 0
#define SOL_TCP 6
#define SOL_UDP 17
#define SOL_IPV6 41

#define SOMAXCONN 128

#define SO_REUSEADDR 2
#define SO_ERROR 4
#define SO_SNDBUF 7
#define SO_RCVBUF 8
#define SO_KEEPALIVE 9
#define SO_ACCEPTCONN 30
#define SO_PROTOCOL 38
#define SO_DOMAIN 39

#if __LONG_MAX == 0x7fffffff
#define SO_RCVTIMEO 66
#define SO_SNDTIMEO 67
#else
#define SO_RCVTIMEO 20
#define SO_SNDTIMEO 21
#endif

#else // __wasilibc_use_wasip2
#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK
#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL
#define MSG_TRUNC __WASI_RIFLAGS_RECV_DATA_TRUNCATED
#define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED
#endif // __wasilibc_use_wasip2

#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM
#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM
Expand All @@ -25,9 +59,13 @@

#define SO_TYPE 3

#define AF_UNSPEC 0
#define AF_INET 1
#define AF_INET6 2
#define PF_UNSPEC 0
#define PF_INET 1
#define PF_INET6 2

#define AF_UNSPEC PF_UNSPEC
#define AF_INET PF_INET
#define AF_INET6 PF_INET6
#define AF_UNIX 3

#ifdef __cplusplus
Expand Down
2 changes: 1 addition & 1 deletion lib/libc/include/wasm-wasi-musl/__mode_t.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#define S_IFLNK (0xa000)
#define S_IFREG (0x8000)
#define S_IFSOCK (0xc000)
#define S_IFIFO (0xc000)
#define S_IFIFO (0x1000)

#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
Expand Down
3 changes: 0 additions & 3 deletions lib/libc/include/wasm-wasi-musl/__struct_sockaddr.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#ifndef __wasilibc___struct_sockaddr_h
#define __wasilibc___struct_sockaddr_h

#define __need_STDDEF_H_misc
#include <stddef.h>

#include <__typedef_sa_family_t.h>

struct sockaddr {
Expand Down
5 changes: 1 addition & 4 deletions lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#ifndef __wasilibc___struct_sockaddr_in_h
#define __wasilibc___struct_sockaddr_in_h

#define __need_STDDEF_H_misc
#include <stddef.h>

#include <__typedef_sa_family_t.h>
#include <__typedef_in_port_t.h>
#include <__struct_in_addr.h>

struct sockaddr_in {
_Alignas(max_align_t) sa_family_t sin_family;
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin_family;
in_port_t sin_port;
struct in_addr sin_addr;
};
Expand Down
5 changes: 1 addition & 4 deletions lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#ifndef __wasilibc___struct_sockaddr_in6_h
#define __wasilibc___struct_sockaddr_in6_h

#define __need_STDDEF_H_misc
#include <stddef.h>

#include <__typedef_sa_family_t.h>
#include <__typedef_in_port_t.h>
#include <__struct_in6_addr.h>

struct sockaddr_in6 {
_Alignas(max_align_t) sa_family_t sin6_family;
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin6_family;
in_port_t sin6_port;
unsigned sin6_flowinfo;
struct in6_addr sin6_addr;
Expand Down
5 changes: 1 addition & 4 deletions lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#ifndef __wasilibc___struct_sockaddr_storage_h
#define __wasilibc___struct_sockaddr_storage_h

#define __need_STDDEF_H_misc
#include <stddef.h>

#include <__typedef_sa_family_t.h>

struct sockaddr_storage {
_Alignas(max_align_t) sa_family_t ss_family;
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t ss_family;
char __ss_data[32];
};

Expand Down
5 changes: 1 addition & 4 deletions lib/libc/include/wasm-wasi-musl/__struct_sockaddr_un.h
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
#ifndef __wasilibc___struct_sockaddr_un_h
#define __wasilibc___struct_sockaddr_un_h

#define __need_STDDEF_H_misc
#include <stddef.h>

#include <__typedef_sa_family_t.h>

struct sockaddr_un {
_Alignas(max_align_t) sa_family_t sun_family;
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sun_family;
};

#endif
Empty file.
1 change: 1 addition & 0 deletions lib/libc/include/wasm-wasi-musl/bits/setjmp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
typedef unsigned long __jmp_buf[8];
56 changes: 56 additions & 0 deletions lib/libc/include/wasm-wasi-musl/dlfcn.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef _DLFCN_H
#define _DLFCN_H

#ifdef __cplusplus
extern "C" {
#endif

#include <features.h>

#define RTLD_LAZY 1
#define RTLD_NOW 2
#define RTLD_NOLOAD 4
#define RTLD_NODELETE 4096
#define RTLD_GLOBAL 256
#ifdef __wasilibc_unmodified_upstream
#define RTLD_LOCAL 0
#else
/* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and
* allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL`
* should be the default when neither is specified.
*/
#define RTLD_LOCAL 8
#endif

#define RTLD_NEXT ((void *)-1)
#define RTLD_DEFAULT ((void *)0)

#ifdef __wasilibc_unmodified_upstream
#define RTLD_DI_LINKMAP 2
#endif

int dlclose(void *);
char *dlerror(void);
void *dlopen(const char *, int);
void *dlsym(void *__restrict, const char *__restrict);

#if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE))
typedef struct {
const char *dli_fname;
void *dli_fbase;
const char *dli_sname;
void *dli_saddr;
} Dl_info;
int dladdr(const void *, Dl_info *);
int dlinfo(void *, int, void *);
#endif

#if _REDIR_TIME64
__REDIR(dlsym, __dlsym_time64);
#endif

#ifdef __cplusplus
}
#endif

#endif
55 changes: 55 additions & 0 deletions lib/libc/include/wasm-wasi-musl/setjmp.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef _SETJMP_H
#define _SETJMP_H

#ifdef __cplusplus
extern "C" {
#endif

#include <features.h>

#ifndef __wasilibc_unmodified_upstream
/* WASI has no setjmp */
#if !defined(__wasm_exception_handling__)
#error Setjmp/longjmp support requires Exception handling support, which is [not yet standardized](https://github.com/WebAssembly/proposals?tab=readme-ov-file#phase-3---implementation-phase-cg--wg). To enable it, compile with `-mllvm -wasm-enable-sjlj` and use an engine that implements the Exception handling proposal.
#endif
#endif
#include <bits/setjmp.h>

typedef struct __jmp_buf_tag {
__jmp_buf __jb;
unsigned long __fl;
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) __setjmp_attr;
_Noreturn void siglongjmp (sigjmp_buf, int);
#endif

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

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

#define setjmp setjmp

#undef __setjmp_attr

#ifdef __cplusplus
}
#endif

#endif
2 changes: 0 additions & 2 deletions lib/libc/include/wasm-wasi-musl/stdlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,7 @@ int rand_r (unsigned *);

#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
|| defined(_BSD_SOURCE)
#ifdef __wasilibc_unmodified_upstream /* WASI has no absolute paths */
char *realpath (const char *__restrict, char *__restrict);
#endif
long int random (void);
void srandom (unsigned int);
char *initstate (unsigned int, char *, size_t);
Expand Down
18 changes: 12 additions & 6 deletions lib/libc/include/wasm-wasi-musl/sys/socket.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#ifndef _SYS_SOCKET_H
#define _SYS_SOCKET_H

#include <__wasi_snapshot.h>

#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
#else
#include <__header_sys_socket.h>
Expand Down Expand Up @@ -395,30 +398,33 @@ struct sockaddr_storage {
#include <__struct_sockaddr_storage.h>
#endif

#ifdef __wasilibc_unmodified_upstream /* WASI has no socket/socketpair */
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
int socket (int, int, int);
#endif

#ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */
int socketpair (int, int, int, int [2]);
#endif

int shutdown (int, int);

#ifdef __wasilibc_unmodified_upstream /* WASI has no bind/connect/listen/accept */
int bind (int, const struct sockaddr *, socklen_t);
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
int connect (int, const struct sockaddr *, socklen_t);
int bind (int, const struct sockaddr *, socklen_t);
int listen (int, int);
#endif

int accept (int, struct sockaddr *__restrict, socklen_t *__restrict);
int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);

#ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict);
#endif

ssize_t send (int, const void *, size_t, int);
ssize_t recv (int, void *, size_t, int);
#ifdef __wasilibc_unmodified_upstream /* WASI has no sendto/recvfrom */
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
#endif
Expand All @@ -428,7 +434,7 @@ ssize_t recvmsg (int, struct msghdr *, int);
#endif

int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);
#ifdef __wasilibc_unmodified_upstream /* WASI has no setsockopt */
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
int setsockopt (int, int, int, const void *, socklen_t);
#endif

Expand Down
2 changes: 0 additions & 2 deletions lib/libc/include/wasm-wasi-musl/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,9 @@ int stat(const char *__restrict, struct stat *__restrict);
int fstat(int, struct stat *);
int lstat(const char *__restrict, struct stat *__restrict);
int fstatat(int, const char *__restrict, struct stat *__restrict, int);
#ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */
int chmod(const char *, mode_t);
int fchmod(int, mode_t);
int fchmodat(int, const char *, mode_t, int);
#endif
#ifdef __wasilibc_unmodified_upstream /* WASI has no umask */
mode_t umask(mode_t);
#endif
Expand Down
Loading