diff options
author | Alexey Samsonov <samsonov@google.com> | 2013-03-20 09:23:28 +0000 |
---|---|---|
committer | Alexey Samsonov <samsonov@google.com> | 2013-03-20 09:23:28 +0000 |
commit | 89c1384464848c1ad041becf8b97936fa10de21b (patch) | |
tree | 62f5694942fee0011a9ee02e75a2666a8fe063d1 /lib/asan/asan_thread.cc | |
parent | 4ff1f6023ac2f34acea54387998c6fa972aa03b8 (diff) |
[ASan] Move GetCurrentThread/SetCurrentThread from AsanThreadRegistry class into plain functions: they don't actually use registry
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177501 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_thread.cc')
-rw-r--r-- | lib/asan/asan_thread.cc | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index 778e91932..8f5a8df56 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -152,4 +152,42 @@ const char *AsanThread::GetFrameNameByAddr(uptr addr, uptr *offset) { return (const char*)ptr[1]; } +AsanThread *GetCurrentThread() { + AsanThreadSummary *summary = (AsanThreadSummary *)AsanTSDGet(); + if (!summary) { +#if SANITIZER_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 = + asanThreadRegistry().FindThreadByStackAddress((uptr)&summary); + if (thread && thread->tid() == 0) { + SetCurrentThread(thread); + return thread; + } +#endif + return 0; + } + return summary->thread(); +} + +void SetCurrentThread(AsanThread *t) { + CHECK(t->summary()); + if (flags()->verbosity >= 2) { + Report("SetCurrentThread: %p for thread %p\n", + t->summary(), (void*)GetThreadSelf()); + } + // Make sure we do not reset the current AsanThread. + CHECK(AsanTSDGet() == 0); + AsanTSDSet(t->summary()); + CHECK(AsanTSDGet() == t->summary()); +} + +u32 GetCurrentTidOrInvalid() { + AsanThread *t = GetCurrentThread(); + return t ? t->tid() : kInvalidTid; +} + } // namespace __asan |