Revert "Use mmap to create the pthread_internal_t."

Unfortunately, this change provokes random crashes for ART, and
I have seen libc crashes on the device that might be related to it.

Reverting it fixes the ART crashes. there is unfortunately no
stack trace for the crashes, but just a "Segmentation fault" message.


This reverts commit cc5f6543e3f91385b9a912438965b7e8265df54a.

Change-Id: I68dca8e1e9b9edcce7eb84596e8db619e40e8052
diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp
index 4790880..6cd5311 100644
--- a/libc/bionic/pthread_exit.cpp
+++ b/libc/bionic/pthread_exit.cpp
@@ -37,7 +37,6 @@
 extern "C" __noreturn void _exit_with_stack_teardown(void*, size_t);
 extern "C" __noreturn void __exit(int);
 extern "C" int __set_tid_address(int*);
-extern "C" void __set_tls(void*);
 
 /* CAVEAT: our implementation of pthread_cleanup_push/pop doesn't support C++ exceptions
  *         and thread cancelation
@@ -76,9 +75,6 @@
   // space (see pthread_key_delete).
   pthread_key_clean_all();
 
-  // Clear tls to prevent further use of __get_tls(), see b/16847284.
-  __set_tls(NULL);
-
   if (thread->alternate_signal_stack != NULL) {
     // Tell the kernel to stop using the alternate signal stack.
     stack_t ss;
@@ -116,6 +112,12 @@
   }
   pthread_mutex_unlock(&g_thread_list_lock);
 
+  // Perform a second key cleanup. When using jemalloc, a call to free from
+  // _pthread_internal_remove_locked causes the memory associated with a key
+  // to be reallocated.
+  // TODO: When b/16847284 is fixed this call can be removed.
+  pthread_key_clean_all();
+
   if (user_allocated_stack) {
     // Cleaning up this thread's stack is the creator's responsibility, not ours.
     __exit(0);