diff options
author | Sergey Matveev <earthdok@google.com> | 2014-12-05 16:53:58 +0000 |
---|---|---|
committer | Sergey Matveev <earthdok@google.com> | 2014-12-05 16:53:58 +0000 |
commit | 207b4560b859d2cf364d620f50b7a5c8bd11bd97 (patch) | |
tree | d33437877b98f16b54e41a3d3ba24bcc74ea7363 | |
parent | c47045205d67866591855e567a2e95a1c2a162ee (diff) |
[ASan] Fix Win build following r223419.
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@223477 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/asan/asan_interceptors.cc | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/asan/asan_interceptors.cc b/lib/asan/asan_interceptors.cc index 74087dbf0..460b8cc28 100644 --- a/lib/asan/asan_interceptors.cc +++ b/lib/asan/asan_interceptors.cc @@ -731,13 +731,25 @@ INTERCEPTOR_WINAPI(DWORD, CreateThread, if (flags()->strict_init_order) StopInitOrderChecking(); GET_STACK_TRACE_THREAD; - u32 current_tid = GetCurrentTidOrInvalid(); - AsanThread *t = AsanThread::Create(start_routine, arg); - CreateThreadContextArgs args = { t, &stack }; bool detached = false; // FIXME: how can we determine it on Windows? - asanThreadRegistry().CreateThread(*(uptr*)t, detached, current_tid, &args); - return REAL(CreateThread)(security, stack_size, - asan_thread_start, t, thr_flags, tid); + ThreadStartParam param; + atomic_store(¶m.t, 0, memory_order_relaxed); + atomic_store(¶m.is_registered, 0, memory_order_relaxed); + DWORD result = REAL(CreateThread)(security, stack_size, asan_thread_start, + ¶m, thr_flags, tid); + if (result) { + u32 current_tid = GetCurrentTidOrInvalid(); + AsanThread *t = AsanThread::Create(start_routine, arg); + CreateThreadContextArgs args = { t, &stack }; + asanThreadRegistry().CreateThread(*reinterpret_cast<uptr *>(t), detached, + current_tid, &args); + atomic_store(¶m.t, reinterpret_cast<uptr>(t), memory_order_release); + // The pthread_create interceptor waits here, so we do the same for + // consistency. + while (atomic_load(¶m.is_registered, memory_order_acquire) == 0) + internal_sched_yield(); + } + return result; } namespace __asan { |