Skip to content

Commit 9a1530e

Browse files
committed
Use wasi thread_exit instead of proc_exit where appropriate
WebAssembly/wasi-threads#7 WebAssembly/wasi-threads#17
1 parent fb9c922 commit 9a1530e

File tree

5 files changed

+18
-2
lines changed

5 files changed

+18
-2
lines changed

expected/wasm32-wasi-pthread/defined-symbols.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ __wasi_sock_accept
354354
__wasi_sock_recv
355355
__wasi_sock_send
356356
__wasi_sock_shutdown
357+
__wasi_thread_exit
357358
__wasi_thread_spawn
358359
__wasilibc_access
359360
__wasilibc_cwd

expected/wasm32-wasi-pthread/undefined-symbols.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ __imported_wasi_snapshot_preview1_sock_accept
5656
__imported_wasi_snapshot_preview1_sock_recv
5757
__imported_wasi_snapshot_preview1_sock_send
5858
__imported_wasi_snapshot_preview1_sock_shutdown
59+
__imported_wasi_thread_exit
5960
__imported_wasi_thread_spawn
6061
__letf2
6162
__lttf2

libc-bottom-half/headers/public/wasi/api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,10 @@ int32_t __wasi_thread_spawn(
21062106
*/
21072107
void *start_arg
21082108
) __attribute__((__warn_unused_result__));
2109+
/**
2110+
* Terminate the calling thread.
2111+
*/
2112+
_Noreturn void __wasi_thread_exit(void);
21092113
#endif
21102114

21112115
#ifdef __cplusplus

libc-bottom-half/sources/__wasilibc_real.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -668,4 +668,14 @@ int32_t __imported_wasi_thread_spawn(int32_t arg0) __attribute__((
668668
int32_t __wasi_thread_spawn(void* start_arg) {
669669
return __imported_wasi_thread_spawn((int32_t) start_arg);
670670
}
671+
672+
_Noreturn void __imported_wasi_thread_exit(void) __attribute__((
673+
__import_module__("wasi"),
674+
__import_name__("thread_exit")
675+
));
676+
677+
_Noreturn void __wasi_thread_exit(void)
678+
{
679+
__imported_wasi_thread_exit();
680+
}
671681
#endif

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ _Noreturn void __pthread_exit(void *result)
191191
__tl_unlock();
192192
free(self->map_base);
193193
// Can't use `exit()` here, because it is too high level
194-
for (;;) __wasi_proc_exit(0);
194+
for (;;) __wasi_thread_exit();
195195
}
196196
#endif
197197

@@ -212,7 +212,7 @@ _Noreturn void __pthread_exit(void *result)
212212
// do it manually here
213213
__tl_unlock();
214214
// Can't use `exit()` here, because it is too high level
215-
for (;;) __wasi_proc_exit(0);
215+
for (;;) __wasi_thread_exit();
216216
#endif
217217
}
218218

0 commit comments

Comments
 (0)