Clean up the x86 and x86_64 _exit_with_stack_teardown implementations.
Change-Id: I4bcbbc53893612bd94643ef07722becb00f91792
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 92e2c27..755b0ac 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -146,10 +146,13 @@
(void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
// destroy the thread stack
- if (user_stack)
+ if (user_stack) {
_exit_thread((int)retval);
- else
+ } else {
+ // We need to munmap the stack we're running on before calling exit.
+ // That's not something we can do in C.
_exit_with_stack_teardown(stack_base, stack_size, (int)retval);
+ }
}
/* a mutex is implemented as a 32-bit integer holding the following fields