From 8e5c22a7a03c7b9c16a9bc60c55a5624170194ea Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 28 May 2024 11:18:04 -0600 Subject: [PATCH] include pthread.h for all targets 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 --- Makefile | 5 --- expected/wasm32-wasip1/include-all.c | 1 + expected/wasm32-wasip1/predefined-macros.txt | 35 +++++++++++++++++++- expected/wasm32-wasip2/include-all.c | 1 + expected/wasm32-wasip2/predefined-macros.txt | 33 ++++++++++++++++++ 5 files changed, 69 insertions(+), 6 deletions(-) diff --git a/Makefile b/Makefile index 812790f0..76fc2df9 100644 --- a/Makefile +++ b/Makefile @@ -539,11 +539,6 @@ ifeq ($(WASI_SNAPSHOT), p1) MUSL_OMIT_HEADERS += "netdb.h" endif -ifeq ($(THREAD_MODEL), single) -# Remove headers not supported in single-threaded mode. -MUSL_OMIT_HEADERS += "pthread.h" -endif - default: finish LIBC_SO_OBJS = $(patsubst %.o,%.pic.o,$(filter-out $(MUSL_PRINTSCAN_OBJS),$(LIBC_OBJS))) diff --git a/expected/wasm32-wasip1/include-all.c b/expected/wasm32-wasip1/include-all.c index cd3b8172..50733743 100644 --- a/expected/wasm32-wasip1/include-all.c +++ b/expected/wasm32-wasip1/include-all.c @@ -114,6 +114,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasip1/predefined-macros.txt b/expected/wasm32-wasip1/predefined-macros.txt index fe5a2993..2fb588ce 100644 --- a/expected/wasm32-wasip1/predefined-macros.txt +++ b/expected/wasm32-wasip1/predefined-macros.txt @@ -1419,6 +1419,35 @@ #define PRIxLEAST8 __UINT_LEAST8_FMTx__ #define PRIxMAX __UINTMAX_FMTx__ #define PRIxPTR __UINTPTR_FMTx__ +#define PTHREAD_BARRIER_SERIAL_THREAD (-1) +#define PTHREAD_CANCELED ((void *)-1) +#define PTHREAD_CANCEL_ASYNCHRONOUS 1 +#define PTHREAD_CANCEL_DEFERRED 0 +#define PTHREAD_CANCEL_DISABLE 1 +#define PTHREAD_CANCEL_ENABLE 0 +#define PTHREAD_CANCEL_MASKED 2 +#define PTHREAD_COND_INITIALIZER {{{0}}} +#define PTHREAD_CREATE_DETACHED 1 +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_EXPLICIT_SCHED 1 +#define PTHREAD_INHERIT_SCHED 0 +#define PTHREAD_MUTEX_DEFAULT 0 +#define PTHREAD_MUTEX_ERRORCHECK 2 +#define PTHREAD_MUTEX_INITIALIZER {{{0}}} +#define PTHREAD_MUTEX_NORMAL 0 +#define PTHREAD_MUTEX_RECURSIVE 1 +#define PTHREAD_MUTEX_ROBUST 1 +#define PTHREAD_MUTEX_STALLED 0 +#define PTHREAD_NULL ((pthread_t)0) +#define PTHREAD_ONCE_INIT 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_PROTECT 2 +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 +#define PTHREAD_RWLOCK_INITIALIZER {{{0}}} +#define PTHREAD_SCOPE_PROCESS 1 +#define PTHREAD_SCOPE_SYSTEM 0 #define PTRBITS (sizeof(char *) * 8) #define PTRDIFF_MAX INT32_MAX #define PTRDIFF_MIN INT32_MIN @@ -2163,6 +2192,7 @@ #define _POSIX_V7_ILP32_OFFBIG (1) #define _POSIX_VDISABLE 0 #define _POSIX_VERSION 200809L +#define _PTHREAD_H #define _PTRDIFF_T #define _REGEX_H #define _SCHED_H @@ -3006,7 +3036,7 @@ #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) )) #define __tm_gmtoff tm_gmtoff #define __tm_zone tm_zone -#define __va_copy(d,s) __builtin_va_copy(d,s) +#define __va_copy(d,s) __builtin_va_copy(d, s) #define __wasi__ 1 #define __wasi_api_h #define __wasi_libc_environ_h @@ -3312,6 +3342,9 @@ #define powerof2(n) !(((n)-1) & (n)) #define pread64 pread #define preadv64 preadv +#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) +#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); +#define pthread_equal(x,y) ((x)==(y)) #define pwrite64 pwrite #define pwritev64 pwritev #define readdir64 readdir diff --git a/expected/wasm32-wasip2/include-all.c b/expected/wasm32-wasip2/include-all.c index b2fd79b1..2efa2ded 100644 --- a/expected/wasm32-wasip2/include-all.c +++ b/expected/wasm32-wasip2/include-all.c @@ -115,6 +115,7 @@ #include #include #include +#include #include #include #include diff --git a/expected/wasm32-wasip2/predefined-macros.txt b/expected/wasm32-wasip2/predefined-macros.txt index 1a4f9691..ea346a9d 100644 --- a/expected/wasm32-wasip2/predefined-macros.txt +++ b/expected/wasm32-wasip2/predefined-macros.txt @@ -1550,6 +1550,35 @@ #define PRIxLEAST8 __UINT_LEAST8_FMTx__ #define PRIxMAX __UINTMAX_FMTx__ #define PRIxPTR __UINTPTR_FMTx__ +#define PTHREAD_BARRIER_SERIAL_THREAD (-1) +#define PTHREAD_CANCELED ((void *)-1) +#define PTHREAD_CANCEL_ASYNCHRONOUS 1 +#define PTHREAD_CANCEL_DEFERRED 0 +#define PTHREAD_CANCEL_DISABLE 1 +#define PTHREAD_CANCEL_ENABLE 0 +#define PTHREAD_CANCEL_MASKED 2 +#define PTHREAD_COND_INITIALIZER {{{0}}} +#define PTHREAD_CREATE_DETACHED 1 +#define PTHREAD_CREATE_JOINABLE 0 +#define PTHREAD_EXPLICIT_SCHED 1 +#define PTHREAD_INHERIT_SCHED 0 +#define PTHREAD_MUTEX_DEFAULT 0 +#define PTHREAD_MUTEX_ERRORCHECK 2 +#define PTHREAD_MUTEX_INITIALIZER {{{0}}} +#define PTHREAD_MUTEX_NORMAL 0 +#define PTHREAD_MUTEX_RECURSIVE 1 +#define PTHREAD_MUTEX_ROBUST 1 +#define PTHREAD_MUTEX_STALLED 0 +#define PTHREAD_NULL ((pthread_t)0) +#define PTHREAD_ONCE_INIT 0 +#define PTHREAD_PRIO_INHERIT 1 +#define PTHREAD_PRIO_NONE 0 +#define PTHREAD_PRIO_PROTECT 2 +#define PTHREAD_PROCESS_PRIVATE 0 +#define PTHREAD_PROCESS_SHARED 1 +#define PTHREAD_RWLOCK_INITIALIZER {{{0}}} +#define PTHREAD_SCOPE_PROCESS 1 +#define PTHREAD_SCOPE_SYSTEM 0 #define PTRBITS (sizeof(char *) * 8) #define PTRDIFF_MAX INT32_MAX #define PTRDIFF_MIN INT32_MIN @@ -2314,6 +2343,7 @@ #define _POSIX_V7_ILP32_OFFBIG (1) #define _POSIX_VDISABLE 0 #define _POSIX_VERSION 200809L +#define _PTHREAD_H #define _PTRDIFF_T #define _REGEX_H #define _SCHED_H @@ -3467,6 +3497,9 @@ #define powerof2(n) !(((n)-1) & (n)) #define pread64 pread #define preadv64 preadv +#define pthread_cleanup_pop(r) _pthread_cleanup_pop(&__cb, (r)); } while(0) +#define pthread_cleanup_push(f,x) do { struct __ptcb __cb; _pthread_cleanup_push(&__cb, f, x); +#define pthread_equal(x,y) ((x)==(y)) #define pwrite64 pwrite #define pwritev64 pwritev #define readdir64 readdir