Skip to content

Commit ff07950

Browse files
committed
Properly stub out pthread cancellation
Although it is not supported in WASI, thread cancellation is an important feature of pthreads with wide-ranging implications. Provide the best stubs we can within the limitations by allowing cancellation type and state to be set, even though they will have no effect as pthread_cancel is stubbed to always return ENOTSUP Remove the THREAD_MODEL=single guard as it's currently not being compiled in that case, and because we intend to provide single-threaded stub implementations in the future. Incidentally replace the existing pthread_setcancelstate stub with one which actually correctly writes a value to the old parameter.
1 parent 2373829 commit ff07950

File tree

4 files changed

+11
-2
lines changed

4 files changed

+11
-2
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
300300
thread/pthread_barrierattr_init.c \
301301
thread/pthread_barrierattr_setpshared.c \
302302
thread/pthread_cleanup_push.c \
303+
thread/pthread_cancel.c \
303304
thread/pthread_cond_broadcast.c \
304305
thread/pthread_cond_destroy.c \
305306
thread/pthread_cond_init.c \
@@ -345,6 +346,7 @@ LIBC_TOP_HALF_MUSL_SOURCES += \
345346
thread/pthread_rwlockattr_init.c \
346347
thread/pthread_rwlockattr_setpshared.c \
347348
thread/pthread_setcancelstate.c \
349+
thread/pthread_setcanceltype.c \
348350
thread/pthread_setspecific.c \
349351
thread/pthread_self.c \
350352
thread/pthread_spin_destroy.c \

expected/wasm32-wasip1-threads/defined-symbols.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,6 +1002,7 @@ pthread_barrierattr_destroy
10021002
pthread_barrierattr_getpshared
10031003
pthread_barrierattr_init
10041004
pthread_barrierattr_setpshared
1005+
pthread_cancel
10051006
pthread_cond_broadcast
10061007
pthread_cond_destroy
10071008
pthread_cond_init
@@ -1056,6 +1057,7 @@ pthread_rwlockattr_init
10561057
pthread_rwlockattr_setpshared
10571058
pthread_self
10581059
pthread_setcancelstate
1060+
pthread_setcanceltype
10591061
pthread_setspecific
10601062
pthread_spin_destroy
10611063
pthread_spin_init

libc-top-half/musl/src/thread/pthread_cancel.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "pthread_impl.h"
44
#include "syscall.h"
55

6+
#ifdef __wasilibc_unmodified_upstream
67
hidden long __cancel(), __syscall_cp_asm(), __syscall_cp_c();
78

89
long __cancel()
@@ -99,3 +100,9 @@ int pthread_cancel(pthread_t t)
99100
}
100101
return pthread_kill(t, SIGCANCEL);
101102
}
103+
#else
104+
int pthread_cancel(pthread_t t)
105+
{
106+
return ENOTSUP;
107+
}
108+
#endif

libc-top-half/musl/src/thread/pthread_setcancelstate.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
int __pthread_setcancelstate(int new, int *old)
44
{
5-
#if defined(__wasilibc_unmodified_upstream) || defined(_REENTRANT)
65
if (new > 2U) return EINVAL;
76
struct pthread *self = __pthread_self();
87
if (old) *old = self->canceldisable;
98
self->canceldisable = new;
10-
#endif
119
return 0;
1210
}
1311

0 commit comments

Comments
 (0)