Skip to content

Commit

Permalink
include pthread.h for all targets
Browse files Browse the repository at this point in the history
Per WebAssembly#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]>
  • Loading branch information
dicej committed May 28, 2024
1 parent 7528b13 commit 8e5c22a
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 6 deletions.
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
#include <netpacket/packet.h>
#include <nl_types.h>
#include <poll.h>
#include <pthread.h>
#include <regex.h>
#include <sched.h>
#include <search.h>
Expand Down
35 changes: 34 additions & 1 deletion expected/wasm32-wasip1/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
#include <netpacket/packet.h>
#include <nl_types.h>
#include <poll.h>
#include <pthread.h>
#include <regex.h>
#include <sched.h>
#include <search.h>
Expand Down
33 changes: 33 additions & 0 deletions expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 8e5c22a

Please sign in to comment.