Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use wasi thread_exit instead of proc_exit where appropriate #364

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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