Skip to content

Commit acd0a6e

Browse files
authored
include pthread.h for all targets (#504)
Per #501, this restores the pre-WASI-SDK-22 behavior of including a copy of pthread.h for all targets -- not just the `*-threads` targets. This helps minimize the number of preprocessor guards required to port existing POSIX software to WASI. It also make it easier for projects using WASI-SDK versions earlier than 22 to upgrade. Note that this includes the pthread.h header, but no stub function definitions to link against. We should probably provide the latter as well, but I'll leave that for a separate PR. Signed-off-by: Joel Dice <[email protected]>
1 parent 7528b13 commit acd0a6e

File tree

5 files changed

+69
-6
lines changed

5 files changed

+69
-6
lines changed

Makefile

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -539,11 +539,6 @@ ifeq ($(WASI_SNAPSHOT), p1)
539539
MUSL_OMIT_HEADERS += "netdb.h"
540540
endif
541541

542-
ifeq ($(THREAD_MODEL), single)
543-
# Remove headers not supported in single-threaded mode.
544-
MUSL_OMIT_HEADERS += "pthread.h"
545-
endif
546-
547542
default: finish
548543

549544
LIBC_SO_OBJS = $(patsubst %.o,%.pic.o,$(filter-out $(MUSL_PRINTSCAN_OBJS),$(LIBC_OBJS)))

expected/wasm32-wasip1/include-all.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
#include <netpacket/packet.h>
115115
#include <nl_types.h>
116116
#include <poll.h>
117+
#include <pthread.h>
117118
#include <regex.h>
118119
#include <sched.h>
119120
#include <search.h>

expected/wasm32-wasip1/predefined-macros.txt

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1419,6 +1419,35 @@
14191419
#define PRIxLEAST8 __UINT_LEAST8_FMTx__
14201420
#define PRIxMAX __UINTMAX_FMTx__
14211421
#define PRIxPTR __UINTPTR_FMTx__
1422+
#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
1423+
#define PTHREAD_CANCELED ((void *)-1)
1424+
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
1425+
#define PTHREAD_CANCEL_DEFERRED 0
1426+
#define PTHREAD_CANCEL_DISABLE 1
1427+
#define PTHREAD_CANCEL_ENABLE 0
1428+
#define PTHREAD_CANCEL_MASKED 2
1429+
#define PTHREAD_COND_INITIALIZER {{{0}}}
1430+
#define PTHREAD_CREATE_DETACHED 1
1431+
#define PTHREAD_CREATE_JOINABLE 0
1432+
#define PTHREAD_EXPLICIT_SCHED 1
1433+
#define PTHREAD_INHERIT_SCHED 0
1434+
#define PTHREAD_MUTEX_DEFAULT 0
1435+
#define PTHREAD_MUTEX_ERRORCHECK 2
1436+
#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
1437+
#define PTHREAD_MUTEX_NORMAL 0
1438+
#define PTHREAD_MUTEX_RECURSIVE 1
1439+
#define PTHREAD_MUTEX_ROBUST 1
1440+
#define PTHREAD_MUTEX_STALLED 0
1441+
#define PTHREAD_NULL ((pthread_t)0)
1442+
#define PTHREAD_ONCE_INIT 0
1443+
#define PTHREAD_PRIO_INHERIT 1
1444+
#define PTHREAD_PRIO_NONE 0
1445+
#define PTHREAD_PRIO_PROTECT 2
1446+
#define PTHREAD_PROCESS_PRIVATE 0
1447+
#define PTHREAD_PROCESS_SHARED 1
1448+
#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
1449+
#define PTHREAD_SCOPE_PROCESS 1
1450+
#define PTHREAD_SCOPE_SYSTEM 0
14221451
#define PTRBITS (sizeof(char *) * 8)
14231452
#define PTRDIFF_MAX INT32_MAX
14241453
#define PTRDIFF_MIN INT32_MIN
@@ -2163,6 +2192,7 @@
21632192
#define _POSIX_V7_ILP32_OFFBIG (1)
21642193
#define _POSIX_VDISABLE 0
21652194
#define _POSIX_VERSION 200809L
2195+
#define _PTHREAD_H
21662196
#define _PTRDIFF_T
21672197
#define _REGEX_H
21682198
#define _SCHED_H
@@ -3006,7 +3036,7 @@
30063036
#define __tg_real_remquo(x,y,z) (__RETCAST_2(x, y)( __FLT(x) && __FLT(y) ? remquof(x, y, z) : __LDBL((x)+(y)) ? remquol(x, y, z) : remquo(x, y, z) ))
30073037
#define __tm_gmtoff tm_gmtoff
30083038
#define __tm_zone tm_zone
3009-
#define __va_copy(d,s) __builtin_va_copy(d,s)
3039+
#define __va_copy(d,s) __builtin_va_copy(d, s)
30103040
#define __wasi__ 1
30113041
#define __wasi_api_h
30123042
#define __wasi_libc_environ_h
@@ -3312,6 +3342,9 @@
33123342
#define powerof2(n) !(((n)-1) & (n))
33133343
#define pread64 pread
33143344
#define preadv64 preadv
3345+
#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
3346+
#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
3347+
#define pthread_equal(x,y) ((x)==(y))
33153348
#define pwrite64 pwrite
33163349
#define pwritev64 pwritev
33173350
#define readdir64 readdir

expected/wasm32-wasip2/include-all.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
#include <netpacket/packet.h>
116116
#include <nl_types.h>
117117
#include <poll.h>
118+
#include <pthread.h>
118119
#include <regex.h>
119120
#include <sched.h>
120121
#include <search.h>

expected/wasm32-wasip2/predefined-macros.txt

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1550,6 +1550,35 @@
15501550
#define PRIxLEAST8 __UINT_LEAST8_FMTx__
15511551
#define PRIxMAX __UINTMAX_FMTx__
15521552
#define PRIxPTR __UINTPTR_FMTx__
1553+
#define PTHREAD_BARRIER_SERIAL_THREAD (-1)
1554+
#define PTHREAD_CANCELED ((void *)-1)
1555+
#define PTHREAD_CANCEL_ASYNCHRONOUS 1
1556+
#define PTHREAD_CANCEL_DEFERRED 0
1557+
#define PTHREAD_CANCEL_DISABLE 1
1558+
#define PTHREAD_CANCEL_ENABLE 0
1559+
#define PTHREAD_CANCEL_MASKED 2
1560+
#define PTHREAD_COND_INITIALIZER {{{0}}}
1561+
#define PTHREAD_CREATE_DETACHED 1
1562+
#define PTHREAD_CREATE_JOINABLE 0
1563+
#define PTHREAD_EXPLICIT_SCHED 1
1564+
#define PTHREAD_INHERIT_SCHED 0
1565+
#define PTHREAD_MUTEX_DEFAULT 0
1566+
#define PTHREAD_MUTEX_ERRORCHECK 2
1567+
#define PTHREAD_MUTEX_INITIALIZER {{{0}}}
1568+
#define PTHREAD_MUTEX_NORMAL 0
1569+
#define PTHREAD_MUTEX_RECURSIVE 1
1570+
#define PTHREAD_MUTEX_ROBUST 1
1571+
#define PTHREAD_MUTEX_STALLED 0
1572+
#define PTHREAD_NULL ((pthread_t)0)
1573+
#define PTHREAD_ONCE_INIT 0
1574+
#define PTHREAD_PRIO_INHERIT 1
1575+
#define PTHREAD_PRIO_NONE 0
1576+
#define PTHREAD_PRIO_PROTECT 2
1577+
#define PTHREAD_PROCESS_PRIVATE 0
1578+
#define PTHREAD_PROCESS_SHARED 1
1579+
#define PTHREAD_RWLOCK_INITIALIZER {{{0}}}
1580+
#define PTHREAD_SCOPE_PROCESS 1
1581+
#define PTHREAD_SCOPE_SYSTEM 0
15531582
#define PTRBITS (sizeof(char *) * 8)
15541583
#define PTRDIFF_MAX INT32_MAX
15551584
#define PTRDIFF_MIN INT32_MIN
@@ -2314,6 +2343,7 @@
23142343
#define _POSIX_V7_ILP32_OFFBIG (1)
23152344
#define _POSIX_VDISABLE 0
23162345
#define _POSIX_VERSION 200809L
2346+
#define _PTHREAD_H
23172347
#define _PTRDIFF_T
23182348
#define _REGEX_H
23192349
#define _SCHED_H
@@ -3467,6 +3497,9 @@
34673497
#define powerof2(n) !(((n)-1) & (n))
34683498
#define pread64 pread
34693499
#define preadv64 preadv
3500+
#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0)
3501+
#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x);
3502+
#define pthread_equal(x,y) ((x)==(y))
34703503
#define pwrite64 pwrite
34713504
#define pwritev64 pwritev
34723505
#define readdir64 readdir

0 commit comments

Comments
 (0)