From 3f6840745cd56517274da2edfa7d3683c7728001 Mon Sep 17 00:00:00 2001 From: Evgeniy Stepanov Date: Thu, 19 Jan 2012 13:57:45 +0000 Subject: [PATCH] Make the Android TSD workaround more reliable. By scanning the thread list backwards. llvm-svn: 148476 --- compiler-rt/lib/asan/asan_thread_registry.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/asan/asan_thread_registry.cc b/compiler-rt/lib/asan/asan_thread_registry.cc index a47fe61d7304..c905201d0a30 100644 --- a/compiler-rt/lib/asan/asan_thread_registry.cc +++ b/compiler-rt/lib/asan/asan_thread_registry.cc @@ -136,7 +136,10 @@ AsanThreadSummary *AsanThreadRegistry::FindByTid(int tid) { AsanThread *AsanThreadRegistry::FindThreadByStackAddress(uintptr_t addr) { ScopedLock lock(&mu_); - for (int tid = 0; tid < n_threads_; tid++) { + // Main thread (tid = 0) stack limits are pretty much guessed; for the other + // threads we ask libpthread, so their limits must be correct. + // Scanning the thread list backwards makes this function more reliable. + for (int tid = n_threads_ - 1; tid >= 0; tid--) { AsanThread *t = thread_summaries_[tid]->thread(); if (!t) continue; if (t->fake_stack().AddrIsInFakeStack(addr) || t->AddrIsInStack(addr)) {