diff options
author | Sergey Matveev <earthdok@google.com> | 2013-07-08 12:57:24 +0000 |
---|---|---|
committer | Sergey Matveev <earthdok@google.com> | 2013-07-08 12:57:24 +0000 |
commit | c6ac98d7fcc81768b2ef7ddc785c27e3fc1bdef6 (patch) | |
tree | bfbbc7b8f485db6067bb87d41e007c97bb5c7f33 /lib/asan/asan_thread.cc | |
parent | 99560bf109ca14b1a48e1ae1206bcc11cdb7eae4 (diff) |
[lsan] Handle fork() correctly.
Update the main thread's os_id on every pthread_create, and before
initiating leak checking. This ensures that we have the correct os_id even if we
have forked after Init().
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@185815 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/asan/asan_thread.cc')
-rw-r--r-- | lib/asan/asan_thread.cc | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/asan/asan_thread.cc b/lib/asan/asan_thread.cc index 39153bf87..1253ff196 100644 --- a/lib/asan/asan_thread.cc +++ b/lib/asan/asan_thread.cc @@ -211,7 +211,8 @@ static bool ThreadStackContainsAddress(ThreadContextBase *tctx_base, } AsanThread *GetCurrentThread() { - AsanThreadContext *context = (AsanThreadContext*)AsanTSDGet(); + AsanThreadContext *context = + reinterpret_cast<AsanThreadContext *>(AsanTSDGet()); if (!context) { if (SANITIZER_ANDROID) { // On Android, libc constructor is called _after_ asan_init, and cleans up @@ -254,6 +255,13 @@ AsanThread *FindThreadByStackAddress(uptr addr) { (void *)addr)); return tctx ? tctx->thread : 0; } + +void EnsureMainThreadIDIsCorrect() { + AsanThreadContext *context = + reinterpret_cast<AsanThreadContext *>(AsanTSDGet()); + if (context && (context->tid == 0)) + context->os_id = GetTid(); +} } // namespace __asan // --- Implementation of LSan-specific functions --- {{{1 @@ -283,4 +291,8 @@ void LockThreadRegistry() { void UnlockThreadRegistry() { __asan::asanThreadRegistry().Unlock(); } + +void EnsureMainThreadIDIsCorrect() { + __asan::EnsureMainThreadIDIsCorrect(); +} } // namespace __lsan |