Skip to content

Commit 2f577a8

Browse files
committed
fix: pthread_exit for WASI
Can't use `exit()` because it is too high level. Have to unlock the thread list. Signed-off-by: Harald Hoyer <[email protected]>
1 parent e755b1e commit 2f577a8

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,15 @@ _Noreturn void __pthread_exit(void *result)
182182
* and then exits without touching the stack. */
183183
__unmapself(self->map_base, self->map_size);
184184
}
185+
#else
186+
if (state==DT_DETACHED && self->map_base) {
187+
// __syscall(SYS_exit) would unlock the thread, list
188+
// do it manually here
189+
__tl_unlock();
190+
free(self->map_base);
191+
// Can't use `exit()` here, because it is too high level
192+
for (;;) __wasi_proc_exit(0);
193+
}
185194
#endif
186195

187196
/* Wake any joiner. */
@@ -197,7 +206,11 @@ _Noreturn void __pthread_exit(void *result)
197206
#ifdef __wasilibc_unmodified_upstream
198207
for (;;) __syscall(SYS_exit, 0);
199208
#else
200-
for (;;) exit(0);
209+
// __syscall(SYS_exit) would unlock the thread, list
210+
// do it manually here
211+
__tl_unlock();
212+
// Can't use `exit()` here, because it is too high level
213+
for (;;) __wasi_proc_exit(0);
201214
#endif
202215
}
203216

0 commit comments

Comments
 (0)