diff --git a/expected/wasm32-wasi-pthread/defined-symbols.txt b/expected/wasm32-wasi-pthread/defined-symbols.txt index 6bd0fae4e..887abe201 100644 --- a/expected/wasm32-wasi-pthread/defined-symbols.txt +++ b/expected/wasm32-wasi-pthread/defined-symbols.txt @@ -354,6 +354,7 @@ __wasi_sock_accept __wasi_sock_recv __wasi_sock_send __wasi_sock_shutdown +__wasi_thread_exit __wasi_thread_spawn __wasilibc_access __wasilibc_cwd diff --git a/expected/wasm32-wasi-pthread/undefined-symbols.txt b/expected/wasm32-wasi-pthread/undefined-symbols.txt index 7def0a9f4..50ad4890e 100644 --- a/expected/wasm32-wasi-pthread/undefined-symbols.txt +++ b/expected/wasm32-wasi-pthread/undefined-symbols.txt @@ -56,6 +56,7 @@ __imported_wasi_snapshot_preview1_sock_accept __imported_wasi_snapshot_preview1_sock_recv __imported_wasi_snapshot_preview1_sock_send __imported_wasi_snapshot_preview1_sock_shutdown +__imported_wasi_thread_exit __imported_wasi_thread_spawn __letf2 __lttf2 diff --git a/libc-bottom-half/headers/public/wasi/api.h b/libc-bottom-half/headers/public/wasi/api.h index 45a6506e2..90f3d9b3a 100644 --- a/libc-bottom-half/headers/public/wasi/api.h +++ b/libc-bottom-half/headers/public/wasi/api.h @@ -2106,6 +2106,10 @@ int32_t __wasi_thread_spawn( */ void *start_arg ) __attribute__((__warn_unused_result__)); +/** + * Terminate the calling thread. + */ +_Noreturn void __wasi_thread_exit(void); #endif #ifdef __cplusplus diff --git a/libc-bottom-half/sources/__wasilibc_real.c b/libc-bottom-half/sources/__wasilibc_real.c index d2e6b71c6..9aff3be8c 100644 --- a/libc-bottom-half/sources/__wasilibc_real.c +++ b/libc-bottom-half/sources/__wasilibc_real.c @@ -668,4 +668,14 @@ int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__(( int32_t __wasi_thread_spawn(void* start_arg) { return __imported_wasi_thread_spawn((int32_t) start_arg); } + +_Noreturn void __imported_wasi_thread_exit(void) __attribute__(( + __import_module__("wasi"), + __import_name__("thread_exit") +)); + +_Noreturn void __wasi_thread_exit(void) +{ + __imported_wasi_thread_exit(); +} #endif diff --git a/libc-top-half/musl/src/thread/pthread_create.c b/libc-top-half/musl/src/thread/pthread_create.c index 3b3a2642e..5ee9c5255 100644 --- a/libc-top-half/musl/src/thread/pthread_create.c +++ b/libc-top-half/musl/src/thread/pthread_create.c @@ -191,7 +191,7 @@ _Noreturn void __pthread_exit(void *result) __tl_unlock(); free(self->map_base); // Can't use `exit()` here, because it is too high level - for (;;) __wasi_proc_exit(0); + for (;;) __wasi_thread_exit(); } #endif @@ -212,7 +212,7 @@ _Noreturn void __pthread_exit(void *result) // do it manually here __tl_unlock(); // Can't use `exit()` here, because it is too high level - for (;;) __wasi_proc_exit(0); + for (;;) __wasi_thread_exit(); #endif }