[compiler-rt] [ASan][Windows] Synchronizing ASAN init on Windows (PR #71833)

Zack Johnson via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 10 06:49:18 PST 2023


================
@@ -93,6 +97,11 @@ AsanThreadContext *GetThreadContextByTidLocked(u32 tid) {
 AsanThread *AsanThread::Create(const void *start_data, uptr data_size,
                                u32 parent_tid, StackTrace *stack,
                                bool detached) {
+#if SANITIZER_WINDOWS
----------------
zacklj89 wrote:

>From .NET, if a worker thread loads an ASAN instrumented binary, we can see all of the checks in the PR description fail based on timing.

For the check `((!asan_init_is_running && "ASan init calls itself!")) != (0)`, this can happen when one thread is initializing ASan and has already intercepted `malloc` or `Rtl*` APIs. While it's still initializing, another thread calls the intercepted API, which results in the `__asan::Allocator` making another call to `AsanInitInternal`, and the check fires.

For the main thread creation, this happens less frequently since the call to `CreateMainThread` is nearly at the end of `AsanInitInternal` shortly after `CreateThread` has been intercepted. After it's intercepted, the thread registry can attempt to create another thread before the call to create the main thread. I'm not sure how ASan can be dynamically loaded on other platforms besides Windows, so this might not be an issue outside of Windows.

https://github.com/llvm/llvm-project/pull/71833


More information about the llvm-commits mailing list