diff --git a/compiler-rt/lib/asan/asan_thread.cpp b/compiler-rt/lib/asan/asan_thread.cpp --- a/compiler-rt/lib/asan/asan_thread.cpp +++ b/compiler-rt/lib/asan/asan_thread.cpp @@ -507,15 +507,29 @@ void GetAllThreadAllocatorCachesLocked(InternalMmapVector *caches) {} -void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback, - void *arg) { +void GetThreadExtraStackRanges(tid_t os_id, InternalMmapVector *ranges) { __asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id); if (!t) return; __asan::FakeStack *fake_stack = t->get_fake_stack(); if (!fake_stack) return; - fake_stack->ForEachFakeFrame(callback, arg); + + fake_stack->ForEachFakeFrame( + [](uptr begin, uptr end, void *arg) { + auto *ranges = reinterpret_cast *>(arg); + ranges->push_back({begin : begin, end : end}); + }, + ranges); +} + +void GetAllThreadsExtraStackRanges(InternalMmapVector *ranges) { + GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked( + [](ThreadContextBase *tctx, void *arg) { + GetThreadExtraStackRanges( + tctx->os_id, reinterpret_cast *>(arg)); + }, + ranges); } void GetAdditionalThreadContextPtrsLocked(InternalMmapVector *ptrs) { diff --git a/compiler-rt/lib/hwasan/hwasan_thread.cpp b/compiler-rt/lib/hwasan/hwasan_thread.cpp --- a/compiler-rt/lib/hwasan/hwasan_thread.cpp +++ b/compiler-rt/lib/hwasan/hwasan_thread.cpp @@ -194,8 +194,8 @@ void GetAllThreadAllocatorCachesLocked(InternalMmapVector *caches) {} -void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback, - void *arg) {} +void GetThreadExtraStackRanges(tid_t, InternalMmapVector *) {} +void GetAllThreadsExtraStackRanges(InternalMmapVector *) {} void GetAdditionalThreadContextPtrsLocked(InternalMmapVector *ptrs) {} void GetRunningThreadsLocked(InternalMmapVector *threads) {} diff --git a/compiler-rt/lib/lsan/lsan_common.h b/compiler-rt/lib/lsan/lsan_common.h --- a/compiler-rt/lib/lsan/lsan_common.h +++ b/compiler-rt/lib/lsan/lsan_common.h @@ -77,6 +77,11 @@ kIgnoreObjectInvalid }; +struct Range { + uptr begin; + uptr end; +}; + //// -------------------------------------------------------------------------- //// Poisoning prototypes. //// -------------------------------------------------------------------------- @@ -103,8 +108,8 @@ uptr *tls_begin, uptr *tls_end, uptr *cache_begin, uptr *cache_end, DTLS **dtls); void GetAllThreadAllocatorCachesLocked(InternalMmapVector *caches); -void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback, - void *arg); +void GetThreadExtraStackRanges(tid_t os_id, InternalMmapVector *ranges); +void GetAllThreadsExtraStackRanges(InternalMmapVector *ranges); void GetAdditionalThreadContextPtrsLocked(InternalMmapVector *ptrs); void GetRunningThreadsLocked(InternalMmapVector *threads); @@ -248,7 +253,6 @@ InternalMmapVectorNoCtor const *GetRootRegions(); void ScanRootRegion(Frontier *frontier, RootRegion const ®ion, uptr region_begin, uptr region_end, bool is_readable); -void ForEachExtraStackRangeCb(uptr begin, uptr end, void *arg); // Run stoptheworld while holding any platform-specific locks, as well as the // allocator and thread registry locks. void LockStuffAndStopTheWorld(StopTheWorldCallback callback, diff --git a/compiler-rt/lib/lsan/lsan_common.cpp b/compiler-rt/lib/lsan/lsan_common.cpp --- a/compiler-rt/lib/lsan/lsan_common.cpp +++ b/compiler-rt/lib/lsan/lsan_common.cpp @@ -350,11 +350,6 @@ } } -void ForEachExtraStackRangeCb(uptr begin, uptr end, void *arg) { - Frontier *frontier = reinterpret_cast(arg); - ScanRangeForPointers(begin, end, frontier, "FAKE STACK", kReachable); -} - # if SANITIZER_FUCHSIA // Fuchsia handles all threads together with its own callback. @@ -454,7 +449,12 @@ } ScanRangeForPointers(stack_begin, stack_end, frontier, "STACK", kReachable); - ForEachExtraStackRange(os_id, ForEachExtraStackRangeCb, frontier); + InternalMmapVector ranges; + GetThreadExtraStackRanges(os_id, &ranges); + for (i = 0; i < ranges.size(); i++) { + ScanRangeForPointers(ranges[i].begin, ranges[i].end, frontier, + "FAKE STACK", kReachable); + } } if (flags()->use_tls) { diff --git a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp --- a/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp +++ b/compiler-rt/lib/lsan/lsan_common_fuchsia.cpp @@ -147,12 +147,13 @@ // just for the allocator cache, and to call ForEachExtraStackRange, // which ASan needs. if (flags()->use_stacks) { - GetLsanThreadRegistryLocked()->RunCallbackForEachThreadLocked( - [](ThreadContextBase *tctx, void *arg) { - ForEachExtraStackRange(tctx->os_id, ForEachExtraStackRangeCb, - arg); - }, - ¶ms->argument->frontier); + InternalMmapVector ranges; + GetAllThreadsExtraStackRanges(os_id, &ranges); + for (i = 0; i < ranges.size(); i++) { + ScanRangeForPointers(ranges[i].begin, ranges[i].end, + params->argument->frontier, "FAKE STACK", + kReachable); + } } params->callback(SuspendedThreadsListFuchsia(), params->argument); diff --git a/compiler-rt/lib/lsan/lsan_thread.cpp b/compiler-rt/lib/lsan/lsan_thread.cpp --- a/compiler-rt/lib/lsan/lsan_thread.cpp +++ b/compiler-rt/lib/lsan/lsan_thread.cpp @@ -75,8 +75,8 @@ ///// Interface to the common LSan module. ///// -void ForEachExtraStackRange(tid_t os_id, RangeIteratorCallback callback, - void *arg) {} +void GetThreadExtraStackRanges(tid_t, InternalMmapVector *) {} +void GetAllThreadsExtraStackRanges(InternalMmapVector *) {} void LockThreadRegistry() { thread_registry->Lock(); }