pthread_exit should call __NR_exit with status 0.

We shouldn't have been passing the bottom 32 bits of the address used
for pthread_join to the kernel.

Change-Id: I487e5002d60c27adba51173719213abbee0f183f
diff --git a/libc/bionic/bionic_clone.c b/libc/bionic/bionic_clone.c
index 8412057..b603a3a 100644
--- a/libc/bionic/bionic_clone.c
+++ b/libc/bionic/bionic_clone.c
@@ -39,21 +39,17 @@
                            int            (*fn)(void *),
                            void          *arg);
 
-extern void _exit_thread(int  retCode);
+extern void _exit_thread(int status);
 
 /* this function is called from the __bionic_clone
  * assembly fragment to call the thread function
  * then exit. */
-extern void
-__bionic_clone_entry( int (*fn)(void *), void *arg )
-{
-    int  ret = (*fn)(arg);
-    _exit_thread(ret);
+extern void __bionic_clone_entry(int (*fn)(void*), void* arg) {
+  int status = (*fn)(arg);
+  _exit_thread(status);
 }
 
-int
-clone(int (*fn)(void *), void *child_stack, int flags, void*  arg, ...)
-{
+int clone(int (*fn)(void*), void* child_stack, int flags, void* arg, ...) {
     va_list  args;
     int     *parent_tidptr = NULL;
     void    *new_tls = NULL;
diff --git a/libc/bionic/pthread.c b/libc/bionic/pthread.c
index 755b0ac..ab806c0 100644
--- a/libc/bionic/pthread.c
+++ b/libc/bionic/pthread.c
@@ -44,8 +44,8 @@
 extern void pthread_debug_mutex_lock_check(pthread_mutex_t *mutex);
 extern void pthread_debug_mutex_unlock_check(pthread_mutex_t *mutex);
 
-extern void _exit_with_stack_teardown(void * stackBase, int stackSize, int retCode);
-extern void _exit_thread(int  retCode);
+extern void _exit_with_stack_teardown(void * stackBase, int stackSize, int status);
+extern void _exit_thread(int status);
 
 int  __futex_wake_ex(volatile void *ftx, int pshared, int val)
 {
@@ -143,15 +143,15 @@
 
     sigfillset(&mask);
     sigdelset(&mask, SIGSEGV);
-    (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL);
+    sigprocmask(SIG_SETMASK, &mask, NULL);
 
-    // destroy the thread stack
     if (user_stack) {
-        _exit_thread((int)retval);
+        // Cleaning up this thread's stack is the creator's responsibility, not ours.
+        _exit_thread(0);
     } 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);
+        _exit_with_stack_teardown(stack_base, stack_size, 0);
     }
 }