Skip to content

Commit 1a1389c

Browse files
authored
Merge pull request #19614 from jedisct1/wasi-libc-update
Update wasi-libc to d03829489904d38c624f6de9983190f1e5e7c9c5
2 parents ff55137 + e600726 commit 1a1389c

Some content is hidden

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

129 files changed

+1062
-8304
lines changed

lib/libc/include/wasm-wasi-musl/__errno.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,11 @@
55
extern "C" {
66
#endif
77

8-
#ifdef __cplusplus
9-
extern thread_local int errno;
10-
#else
118
extern _Thread_local int errno;
12-
#endif
139

1410
#define errno errno
1511

1612
#ifdef __cplusplus
1713
}
1814
#endif
19-
2015
#endif

lib/libc/include/wasm-wasi-musl/__header_dirent.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,26 @@
1111
#define DT_REG __WASI_FILETYPE_REGULAR_FILE
1212
#define DT_UNKNOWN __WASI_FILETYPE_UNKNOWN
1313

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

17-
int __wasilibc_iftodt(int x);
18-
int __wasilibc_dttoif(int x);
19-
2024
#include <__struct_dirent.h>
2125
#include <__typedef_DIR.h>
2226

2327
#ifdef __cplusplus
2428
extern "C" {
2529
#endif
2630

31+
int __wasilibc_iftodt(int x);
32+
int __wasilibc_dttoif(int x);
33+
2734
int closedir(DIR *);
2835
DIR *opendir(const char *);
2936
DIR *fdopendir(int);

lib/libc/include/wasm-wasi-musl/__header_sys_socket.h

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#ifndef __wasilibc___header_sys_socket_h
22
#define __wasilibc___header_sys_socket_h
33

4+
#include <__wasi_snapshot.h>
45
#include <__struct_msghdr.h>
56
#include <__struct_sockaddr.h>
67
#include <__struct_sockaddr_storage.h>
@@ -11,9 +12,42 @@
1112
#define SHUT_WR __WASI_SDFLAGS_WR
1213
#define SHUT_RDWR (SHUT_RD | SHUT_WR)
1314

15+
#ifdef __wasilibc_use_wasip2
16+
#define MSG_DONTWAIT 0x0040
17+
#define MSG_NOSIGNAL 0x4000
18+
#define MSG_PEEK 0x0002
19+
#define MSG_WAITALL 0x0100
20+
#define MSG_TRUNC 0x0020
21+
22+
#define SOL_IP 0
23+
#define SOL_TCP 6
24+
#define SOL_UDP 17
25+
#define SOL_IPV6 41
26+
27+
#define SOMAXCONN 128
28+
29+
#define SO_REUSEADDR 2
30+
#define SO_ERROR 4
31+
#define SO_SNDBUF 7
32+
#define SO_RCVBUF 8
33+
#define SO_KEEPALIVE 9
34+
#define SO_ACCEPTCONN 30
35+
#define SO_PROTOCOL 38
36+
#define SO_DOMAIN 39
37+
38+
#if __LONG_MAX == 0x7fffffff
39+
#define SO_RCVTIMEO 66
40+
#define SO_SNDTIMEO 67
41+
#else
42+
#define SO_RCVTIMEO 20
43+
#define SO_SNDTIMEO 21
44+
#endif
45+
46+
#else // __wasilibc_use_wasip2
1447
#define MSG_PEEK __WASI_RIFLAGS_RECV_PEEK
1548
#define MSG_WAITALL __WASI_RIFLAGS_RECV_WAITALL
16-
#define MSG_TRUNC __WASI_RIFLAGS_RECV_DATA_TRUNCATED
49+
#define MSG_TRUNC __WASI_ROFLAGS_RECV_DATA_TRUNCATED
50+
#endif // __wasilibc_use_wasip2
1751

1852
#define SOCK_DGRAM __WASI_FILETYPE_SOCKET_DGRAM
1953
#define SOCK_STREAM __WASI_FILETYPE_SOCKET_STREAM
@@ -25,9 +59,13 @@
2559

2660
#define SO_TYPE 3
2761

28-
#define AF_UNSPEC 0
29-
#define AF_INET 1
30-
#define AF_INET6 2
62+
#define PF_UNSPEC 0
63+
#define PF_INET 1
64+
#define PF_INET6 2
65+
66+
#define AF_UNSPEC PF_UNSPEC
67+
#define AF_INET PF_INET
68+
#define AF_INET6 PF_INET6
3169
#define AF_UNIX 3
3270

3371
#ifdef __cplusplus

lib/libc/include/wasm-wasi-musl/__mode_t.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#define S_IFLNK (0xa000)
1010
#define S_IFREG (0x8000)
1111
#define S_IFSOCK (0xc000)
12-
#define S_IFIFO (0xc000)
12+
#define S_IFIFO (0x1000)
1313

1414
#define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
1515
#define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)

lib/libc/include/wasm-wasi-musl/__struct_sockaddr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#ifndef __wasilibc___struct_sockaddr_h
22
#define __wasilibc___struct_sockaddr_h
33

4-
#define __need_STDDEF_H_misc
5-
#include <stddef.h>
6-
74
#include <__typedef_sa_family_t.h>
85

96
struct sockaddr {

lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#ifndef __wasilibc___struct_sockaddr_in_h
22
#define __wasilibc___struct_sockaddr_in_h
33

4-
#define __need_STDDEF_H_misc
5-
#include <stddef.h>
6-
74
#include <__typedef_sa_family_t.h>
85
#include <__typedef_in_port_t.h>
96
#include <__struct_in_addr.h>
107

118
struct sockaddr_in {
12-
_Alignas(max_align_t) sa_family_t sin_family;
9+
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin_family;
1310
in_port_t sin_port;
1411
struct in_addr sin_addr;
1512
};

lib/libc/include/wasm-wasi-musl/__struct_sockaddr_in6.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
#ifndef __wasilibc___struct_sockaddr_in6_h
22
#define __wasilibc___struct_sockaddr_in6_h
33

4-
#define __need_STDDEF_H_misc
5-
#include <stddef.h>
6-
74
#include <__typedef_sa_family_t.h>
85
#include <__typedef_in_port_t.h>
96
#include <__struct_in6_addr.h>
107

118
struct sockaddr_in6 {
12-
_Alignas(max_align_t) sa_family_t sin6_family;
9+
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sin6_family;
1310
in_port_t sin6_port;
1411
unsigned sin6_flowinfo;
1512
struct in6_addr sin6_addr;

lib/libc/include/wasm-wasi-musl/__struct_sockaddr_storage.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#ifndef __wasilibc___struct_sockaddr_storage_h
22
#define __wasilibc___struct_sockaddr_storage_h
33

4-
#define __need_STDDEF_H_misc
5-
#include <stddef.h>
6-
74
#include <__typedef_sa_family_t.h>
85

96
struct sockaddr_storage {
10-
_Alignas(max_align_t) sa_family_t ss_family;
7+
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t ss_family;
118
char __ss_data[32];
129
};
1310

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
#ifndef __wasilibc___struct_sockaddr_un_h
22
#define __wasilibc___struct_sockaddr_un_h
33

4-
#define __need_STDDEF_H_misc
5-
#include <stddef.h>
6-
74
#include <__typedef_sa_family_t.h>
85

96
struct sockaddr_un {
10-
_Alignas(max_align_t) sa_family_t sun_family;
7+
__attribute__((aligned(__BIGGEST_ALIGNMENT__))) sa_family_t sun_family;
118
};
129

1310
#endif

lib/libc/include/wasm-wasi-musl/__wasi_snapshot.h

Whitespace-only changes.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
typedef unsigned long __jmp_buf[8];
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#ifndef _DLFCN_H
2+
#define _DLFCN_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <features.h>
9+
10+
#define RTLD_LAZY 1
11+
#define RTLD_NOW 2
12+
#define RTLD_NOLOAD 4
13+
#define RTLD_NODELETE 4096
14+
#define RTLD_GLOBAL 256
15+
#ifdef __wasilibc_unmodified_upstream
16+
#define RTLD_LOCAL 0
17+
#else
18+
/* For WASI, we give `RTLD_LOCAL` a non-zero value, avoiding ambiguity and
19+
* allowing us to defer the decision of whether `RTLD_LOCAL` or `RTLD_GLOBAL`
20+
* should be the default when neither is specified.
21+
*/
22+
#define RTLD_LOCAL 8
23+
#endif
24+
25+
#define RTLD_NEXT ((void *)-1)
26+
#define RTLD_DEFAULT ((void *)0)
27+
28+
#ifdef __wasilibc_unmodified_upstream
29+
#define RTLD_DI_LINKMAP 2
30+
#endif
31+
32+
int dlclose(void *);
33+
char *dlerror(void);
34+
void *dlopen(const char *, int);
35+
void *dlsym(void *__restrict, const char *__restrict);
36+
37+
#if defined(__wasilibc_unmodified_upstream) && (defined(_GNU_SOURCE) || defined(_BSD_SOURCE))
38+
typedef struct {
39+
const char *dli_fname;
40+
void *dli_fbase;
41+
const char *dli_sname;
42+
void *dli_saddr;
43+
} Dl_info;
44+
int dladdr(const void *, Dl_info *);
45+
int dlinfo(void *, int, void *);
46+
#endif
47+
48+
#if _REDIR_TIME64
49+
__REDIR(dlsym, __dlsym_time64);
50+
#endif
51+
52+
#ifdef __cplusplus
53+
}
54+
#endif
55+
56+
#endif
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
#ifndef _SETJMP_H
2+
#define _SETJMP_H
3+
4+
#ifdef __cplusplus
5+
extern "C" {
6+
#endif
7+
8+
#include <features.h>
9+
10+
#ifndef __wasilibc_unmodified_upstream
11+
/* WASI has no setjmp */
12+
#if !defined(__wasm_exception_handling__)
13+
#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.
14+
#endif
15+
#endif
16+
#include <bits/setjmp.h>
17+
18+
typedef struct __jmp_buf_tag {
19+
__jmp_buf __jb;
20+
unsigned long __fl;
21+
unsigned long __ss[128/sizeof(long)];
22+
} jmp_buf[1];
23+
24+
#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)
25+
#define __setjmp_attr __attribute__((__returns_twice__))
26+
#else
27+
#define __setjmp_attr
28+
#endif
29+
30+
#if defined(_POSIX_SOURCE) || defined(_POSIX_C_SOURCE) \
31+
|| defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
32+
|| defined(_BSD_SOURCE)
33+
typedef jmp_buf sigjmp_buf;
34+
int sigsetjmp (sigjmp_buf, int) __setjmp_attr;
35+
_Noreturn void siglongjmp (sigjmp_buf, int);
36+
#endif
37+
38+
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
39+
|| defined(_BSD_SOURCE)
40+
int _setjmp (jmp_buf) __setjmp_attr;
41+
_Noreturn void _longjmp (jmp_buf, int);
42+
#endif
43+
44+
int setjmp (jmp_buf) __setjmp_attr;
45+
_Noreturn void longjmp (jmp_buf, int);
46+
47+
#define setjmp setjmp
48+
49+
#undef __setjmp_attr
50+
51+
#ifdef __cplusplus
52+
}
53+
#endif
54+
55+
#endif

lib/libc/include/wasm-wasi-musl/stdlib.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,9 +128,7 @@ int rand_r (unsigned *);
128128

129129
#if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \
130130
|| defined(_BSD_SOURCE)
131-
#ifdef __wasilibc_unmodified_upstream /* WASI has no absolute paths */
132131
char *realpath (const char *__restrict, char *__restrict);
133-
#endif
134132
long int random (void);
135133
void srandom (unsigned int);
136134
char *initstate (unsigned int, char *, size_t);

lib/libc/include/wasm-wasi-musl/sys/socket.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#ifndef _SYS_SOCKET_H
22
#define _SYS_SOCKET_H
3+
4+
#include <__wasi_snapshot.h>
5+
36
#ifdef __wasilibc_unmodified_upstream /* Use alternate WASI libc headers */
47
#else
58
#include <__header_sys_socket.h>
@@ -395,30 +398,33 @@ struct sockaddr_storage {
395398
#include <__struct_sockaddr_storage.h>
396399
#endif
397400

398-
#ifdef __wasilibc_unmodified_upstream /* WASI has no socket/socketpair */
401+
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
399402
int socket (int, int, int);
403+
#endif
404+
405+
#ifdef __wasilibc_unmodified_upstream /* WASI has no socketpair */
400406
int socketpair (int, int, int, int [2]);
401407
#endif
402408

403409
int shutdown (int, int);
404410

405-
#ifdef __wasilibc_unmodified_upstream /* WASI has no bind/connect/listen/accept */
406-
int bind (int, const struct sockaddr *, socklen_t);
411+
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
407412
int connect (int, const struct sockaddr *, socklen_t);
413+
int bind (int, const struct sockaddr *, socklen_t);
408414
int listen (int, int);
409415
#endif
410416

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

414-
#ifdef __wasilibc_unmodified_upstream /* WASI has no getsockname/getpeername */
420+
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
415421
int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
416422
int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict);
417423
#endif
418424

419425
ssize_t send (int, const void *, size_t, int);
420426
ssize_t recv (int, void *, size_t, int);
421-
#ifdef __wasilibc_unmodified_upstream /* WASI has no sendto/recvfrom */
427+
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
422428
ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
423429
ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
424430
#endif
@@ -428,7 +434,7 @@ ssize_t recvmsg (int, struct msghdr *, int);
428434
#endif
429435

430436
int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);
431-
#ifdef __wasilibc_unmodified_upstream /* WASI has no setsockopt */
437+
#if (defined __wasilibc_unmodified_upstream) || (defined __wasilibc_use_wasip2)
432438
int setsockopt (int, int, int, const void *, socklen_t);
433439
#endif
434440

lib/libc/include/wasm-wasi-musl/sys/stat.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,9 @@ int stat(const char *__restrict, struct stat *__restrict);
7878
int fstat(int, struct stat *);
7979
int lstat(const char *__restrict, struct stat *__restrict);
8080
int fstatat(int, const char *__restrict, struct stat *__restrict, int);
81-
#ifdef __wasilibc_unmodified_upstream /* WASI has no chmod */
8281
int chmod(const char *, mode_t);
8382
int fchmod(int, mode_t);
8483
int fchmodat(int, const char *, mode_t, int);
85-
#endif
8684
#ifdef __wasilibc_unmodified_upstream /* WASI has no umask */
8785
mode_t umask(mode_t);
8886
#endif

0 commit comments

Comments
 (0)