[llvm-commits] [compiler-rt] r148475 - /compiler-rt/trunk/lib/asan/asan_thread_registry.cc

Evgeniy Stepanov eugeni.stepanov at gmail.com
Thu Jan 19 05:37:32 PST 2012


Author: eugenis
Date: Thu Jan 19 07:37:31 2012
New Revision: 148475

URL: http://llvm.org/viewvc/llvm-project?rev=148475&view=rev
Log:
Workaround the self-cleaning TSD on Android.

Modified:
    compiler-rt/trunk/lib/asan/asan_thread_registry.cc

Modified: compiler-rt/trunk/lib/asan/asan_thread_registry.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_thread_registry.cc?rev=148475&r1=148474&r2=148475&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_thread_registry.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_thread_registry.cc Thu Jan 19 07:37:31 2012
@@ -65,7 +65,21 @@
 
 AsanThread *AsanThreadRegistry::GetCurrent() {
   AsanThreadSummary *summary = (AsanThreadSummary *)AsanTSDGet();
-  if (!summary) return 0;
+  if (!summary) {
+#ifdef ANDROID
+    // On Android, libc constructor is called _after_ asan_init, and cleans up
+    // TSD. Try to figure out if this is still the main thread by the stack
+    // address. We are not entirely sure that we have correct main thread
+    // limits, so only do this magic on Android, and only if the found thread is
+    // the main thread.
+    AsanThread* thread = FindThreadByStackAddress((uintptr_t)&summary);
+    if (thread->tid() == 0) {
+      SetCurrent(thread);
+      return thread;
+    }
+#endif
+    return 0;
+  }
   return summary->thread();
 }
 





More information about the llvm-commits mailing list