Skip to content

Commit

Permalink
Use wasi thread_exit instead of proc_exit where appropriate
Browse files Browse the repository at this point in the history
  • Loading branch information
yamt committed Dec 16, 2022
1 parent fb9c922 commit 9a1530e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions expected/wasm32-wasi-pthread/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasi-pthread/undefined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions libc-bottom-half/headers/public/wasi/api.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions libc-bottom-half/sources/__wasilibc_real.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions libc-top-half/musl/src/thread/pthread_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
}

Expand Down

0 comments on commit 9a1530e

Please sign in to comment.