1 //===-- asan_thread.cpp ---------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file is a part of AddressSanitizer, an address sanity checker.
10 //
11 // Thread-related code.
12 //===----------------------------------------------------------------------===//
13 #include "asan_thread.h"
14 
15 #include "asan_allocator.h"
16 #include "asan_interceptors.h"
17 #include "asan_mapping.h"
18 #include "asan_poisoning.h"
19 #include "asan_stack.h"
20 #include "lsan/lsan_common.h"
21 #include "sanitizer_common/sanitizer_common.h"
22 #include "sanitizer_common/sanitizer_placement_new.h"
23 #include "sanitizer_common/sanitizer_stackdepot.h"
24 #include "sanitizer_common/sanitizer_tls_get_addr.h"
25 
26 namespace __asan {
27 
28 // AsanThreadContext implementation.
29 
30 void AsanThreadContext::OnCreated(void *arg) {
31   CreateThreadContextArgs *args = static_cast<CreateThreadContextArgs *>(arg);
32   if (args->stack)
33     stack_id = StackDepotPut(*args->stack);
34   thread = args->thread;
35   thread->set_context(this);
36 }
37 
38 void AsanThreadContext::OnFinished() {
39   // Drop the link to the AsanThread object.
40   thread = nullptr;
41 }
42 
43 static ThreadRegistry *asan_thread_registry;
44 static ThreadArgRetval *thread_data;
45 
46 static Mutex mu_for_thread_context;
47 static LowLevelAllocator allocator_for_thread_context;
48 
49 static ThreadContextBase *GetAsanThreadContext(u32 tid) {
50   Lock lock(&mu_for_thread_context);
51   return new (allocator_for_thread_context) AsanThreadContext(tid);
52 }
53 
54 static void InitThreads() {
55   static bool initialized;
56   // Don't worry about thread_safety - this should be called when there is
57   // a single thread.
58   if (LIKELY(initialized))
59     return;
60   // Never reuse ASan threads: we store pointer to AsanThreadContext
61   // in TSD and can't reliably tell when no more TSD destructors will
62   // be called. It would be wrong to reuse AsanThreadContext for another
63   // thread before all TSD destructors will be called for it.
64 
65   // MIPS requires aligned address
66   static ALIGNED(alignof(
67       ThreadRegistry)) char thread_registry_placeholder[sizeof(ThreadRegistry)];
68   static ALIGNED(alignof(
69       ThreadArgRetval)) char thread_data_placeholder[sizeof(ThreadArgRetval)];
70 
71   asan_thread_registry =
72       new (thread_registry_placeholder) ThreadRegistry(GetAsanThreadContext);
73   thread_data = new (thread_data_placeholder) ThreadArgRetval();
74   initialized = true;
75 }
76 
77 ThreadRegistry &asanThreadRegistry() {
78   InitThreads();
79   return *asan_thread_registry;
80 }
81 
82 ThreadArgRetval &asanThreadArgRetval() {
83   InitThreads();
84   return *thread_data;
85 }
86 
87 AsanThreadContext *GetThreadContextByTidLocked(u32 tid) {
88   return static_cast<AsanThreadContext *>(
89       asanThreadRegistry().GetThreadLocked(tid));
90 }
91 
92 // AsanThread implementation.
93 
94 AsanThread *AsanThread::Create(thread_callback_t start_routine, void *arg,
95                                u32 parent_tid, StackTrace *stack,
96                                bool detached) {
97   uptr PageSize = GetPageSizeCached();
98   uptr size = RoundUpTo(sizeof(AsanThread), PageSize);
99   AsanThread *thread = (AsanThread *)MmapOrDie(size, __func__);
100   thread->start_routine_ = start_routine;
101   thread->arg_ = arg;
102   AsanThreadContext::CreateThreadContextArgs args = {thread, stack};
103   asanThreadRegistry().CreateThread(0, detached, parent_tid, &args);
104 
105   return thread;
106 }
107 
108 void AsanThread::TSDDtor(void *tsd) {
109   AsanThreadContext *context = (AsanThreadContext *)tsd;
110   VReport(1, "T%d TSDDtor\n", context->tid);
111   if (context->thread)
112     context->thread->Destroy();
113 }
114 
115 void AsanThread::Destroy() {
116   int tid = this->tid();
117   VReport(1, "T%d exited\n", tid);
118 
119   bool was_running =
120       (asanThreadRegistry().FinishThread(tid) == ThreadStatusRunning);
121   if (was_running) {
122     if (AsanThread *thread = GetCurrentThread())
123       CHECK_EQ(this, thread);
124     malloc_storage().CommitBack();
125     if (common_flags()->use_sigaltstack)
126       UnsetAlternateSignalStack();
127     FlushToDeadThreadStats(&stats_);
128     // We also clear the shadow on thread destruction because
129     // some code may still be executing in later TSD destructors
130     // and we don't want it to have any poisoned stack.
131     ClearShadowForThreadStackAndTLS();
132     DeleteFakeStack(tid);
133   } else {
134     CHECK_NE(this, GetCurrentThread());
135   }
136   uptr size = RoundUpTo(sizeof(AsanThread), GetPageSizeCached());
137   UnmapOrDie(this, size);
138   if (was_running)
139     DTLS_Destroy();
140 }
141 
142 void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
143                                   uptr size) {
144   if (atomic_load(&stack_switching_, memory_order_relaxed)) {
145     Report("ERROR: starting fiber switch while in fiber switch\n");
146     Die();
147   }
148 
149   next_stack_bottom_ = bottom;
150   next_stack_top_ = bottom + size;
151   atomic_store(&stack_switching_, 1, memory_order_release);
152 
153   FakeStack *current_fake_stack = fake_stack_;
154   if (fake_stack_save)
155     *fake_stack_save = fake_stack_;
156   fake_stack_ = nullptr;
157   SetTLSFakeStack(nullptr);
158   // if fake_stack_save is null, the fiber will die, delete the fakestack
159   if (!fake_stack_save && current_fake_stack)
160     current_fake_stack->Destroy(this->tid());
161 }
162 
163 void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
164                                    uptr *size_old) {
165   if (!atomic_load(&stack_switching_, memory_order_relaxed)) {
166     Report("ERROR: finishing a fiber switch that has not started\n");
167     Die();
168   }
169 
170   if (fake_stack_save) {
171     SetTLSFakeStack(fake_stack_save);
172     fake_stack_ = fake_stack_save;
173   }
174 
175   if (bottom_old)
176     *bottom_old = stack_bottom_;
177   if (size_old)
178     *size_old = stack_top_ - stack_bottom_;
179   stack_bottom_ = next_stack_bottom_;
180   stack_top_ = next_stack_top_;
181   atomic_store(&stack_switching_, 0, memory_order_release);
182   next_stack_top_ = 0;
183   next_stack_bottom_ = 0;
184 }
185 
186 inline AsanThread::StackBounds AsanThread::GetStackBounds() const {
187   if (!atomic_load(&stack_switching_, memory_order_acquire)) {
188     // Make sure the stack bounds are fully initialized.
189     if (stack_bottom_ >= stack_top_)
190       return {0, 0};
191     return {stack_bottom_, stack_top_};
192   }
193   char local;
194   const uptr cur_stack = (uptr)&local;
195   // Note: need to check next stack first, because FinishSwitchFiber
196   // may be in process of overwriting stack_top_/bottom_. But in such case
197   // we are already on the next stack.
198   if (cur_stack >= next_stack_bottom_ && cur_stack < next_stack_top_)
199     return {next_stack_bottom_, next_stack_top_};
200   return {stack_bottom_, stack_top_};
201 }
202 
203 uptr AsanThread::stack_top() { return GetStackBounds().top; }
204 
205 uptr AsanThread::stack_bottom() { return GetStackBounds().bottom; }
206 
207 uptr AsanThread::stack_size() {
208   const auto bounds = GetStackBounds();
209   return bounds.top - bounds.bottom;
210 }
211 
212 // We want to create the FakeStack lazily on the first use, but not earlier
213 // than the stack size is known and the procedure has to be async-signal safe.
214 FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
215   uptr stack_size = this->stack_size();
216   if (stack_size == 0)  // stack_size is not yet available, don't use FakeStack.
217     return nullptr;
218   uptr old_val = 0;
219   // fake_stack_ has 3 states:
220   // 0   -- not initialized
221   // 1   -- being initialized
222   // ptr -- initialized
223   // This CAS checks if the state was 0 and if so changes it to state 1,
224   // if that was successful, it initializes the pointer.
225   if (atomic_compare_exchange_strong(
226           reinterpret_cast<atomic_uintptr_t *>(&fake_stack_), &old_val, 1UL,
227           memory_order_relaxed)) {
228     uptr stack_size_log = Log2(RoundUpToPowerOfTwo(stack_size));
229     CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
230     stack_size_log =
231         Min(stack_size_log, static_cast<uptr>(flags()->max_uar_stack_size_log));
232     stack_size_log =
233         Max(stack_size_log, static_cast<uptr>(flags()->min_uar_stack_size_log));
234     fake_stack_ = FakeStack::Create(stack_size_log);
235     DCHECK_EQ(GetCurrentThread(), this);
236     SetTLSFakeStack(fake_stack_);
237     return fake_stack_;
238   }
239   return nullptr;
240 }
241 
242 void AsanThread::Init(const InitOptions *options) {
243   DCHECK_NE(tid(), kInvalidTid);
244   next_stack_top_ = next_stack_bottom_ = 0;
245   atomic_store(&stack_switching_, false, memory_order_release);
246   CHECK_EQ(this->stack_size(), 0U);
247   SetThreadStackAndTls(options);
248   if (stack_top_ != stack_bottom_) {
249     CHECK_GT(this->stack_size(), 0U);
250     CHECK(AddrIsInMem(stack_bottom_));
251     CHECK(AddrIsInMem(stack_top_ - 1));
252   }
253   ClearShadowForThreadStackAndTLS();
254   fake_stack_ = nullptr;
255   if (__asan_option_detect_stack_use_after_return &&
256       tid() == GetCurrentTidOrInvalid()) {
257     // AsyncSignalSafeLazyInitFakeStack makes use of threadlocals and must be
258     // called from the context of the thread it is initializing, not its parent.
259     // Most platforms call AsanThread::Init on the newly-spawned thread, but
260     // Fuchsia calls this function from the parent thread.  To support that
261     // approach, we avoid calling AsyncSignalSafeLazyInitFakeStack here; it will
262     // be called by the new thread when it first attempts to access the fake
263     // stack.
264     AsyncSignalSafeLazyInitFakeStack();
265   }
266   int local = 0;
267   VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(),
268           (void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_,
269           (void *)&local);
270 }
271 
272 // Fuchsia doesn't use ThreadStart.
273 // asan_fuchsia.c definies CreateMainThread and SetThreadStackAndTls.
274 #if !SANITIZER_FUCHSIA
275 
276 thread_return_t AsanThread::ThreadStart(tid_t os_id) {
277   Init();
278   asanThreadRegistry().StartThread(tid(), os_id, ThreadType::Regular, nullptr);
279 
280   if (common_flags()->use_sigaltstack)
281     SetAlternateSignalStack();
282 
283   if (!start_routine_) {
284     // start_routine_ == 0 if we're on the main thread or on one of the
285     // OS X libdispatch worker threads. But nobody is supposed to call
286     // ThreadStart() for the worker threads.
287     CHECK_EQ(tid(), 0);
288     return 0;
289   }
290 
291   thread_return_t res = start_routine_(arg_);
292 
293   // On POSIX systems we defer this to the TSD destructor. LSan will consider
294   // the thread's memory as non-live from the moment we call Destroy(), even
295   // though that memory might contain pointers to heap objects which will be
296   // cleaned up by a user-defined TSD destructor. Thus, calling Destroy() before
297   // the TSD destructors have run might cause false positives in LSan.
298   if (!SANITIZER_POSIX)
299     this->Destroy();
300 
301   return res;
302 }
303 
304 AsanThread *CreateMainThread() {
305   AsanThread *main_thread = AsanThread::Create(
306       /* start_routine */ nullptr, /* arg */ nullptr, /* parent_tid */ kMainTid,
307       /* stack */ nullptr, /* detached */ true);
308   SetCurrentThread(main_thread);
309   main_thread->ThreadStart(internal_getpid());
310   return main_thread;
311 }
312 
313 // This implementation doesn't use the argument, which is just passed down
314 // from the caller of Init (which see, above).  It's only there to support
315 // OS-specific implementations that need more information passed through.
316 void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
317   DCHECK_EQ(options, nullptr);
318   uptr tls_size = 0;
319   uptr stack_size = 0;
320   GetThreadStackAndTls(tid() == kMainTid, &stack_bottom_, &stack_size,
321                        &tls_begin_, &tls_size);
322   stack_top_ = RoundDownTo(stack_bottom_ + stack_size, ASAN_SHADOW_GRANULARITY);
323   stack_bottom_ = RoundDownTo(stack_bottom_, ASAN_SHADOW_GRANULARITY);
324   tls_end_ = tls_begin_ + tls_size;
325   dtls_ = DTLS_Get();
326 
327   if (stack_top_ != stack_bottom_) {
328     int local;
329     CHECK(AddrIsInStack((uptr)&local));
330   }
331 }
332 
333 #endif  // !SANITIZER_FUCHSIA
334 
335 void AsanThread::ClearShadowForThreadStackAndTLS() {
336   if (stack_top_ != stack_bottom_)
337     PoisonShadow(stack_bottom_, stack_top_ - stack_bottom_, 0);
338   if (tls_begin_ != tls_end_) {
339     uptr tls_begin_aligned = RoundDownTo(tls_begin_, ASAN_SHADOW_GRANULARITY);
340     uptr tls_end_aligned = RoundUpTo(tls_end_, ASAN_SHADOW_GRANULARITY);
341     FastPoisonShadow(tls_begin_aligned, tls_end_aligned - tls_begin_aligned, 0);
342   }
343 }
344 
345 bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
346                                            StackFrameAccess *access) {
347   if (stack_top_ == stack_bottom_)
348     return false;
349 
350   uptr bottom = 0;
351   if (AddrIsInStack(addr)) {
352     bottom = stack_bottom();
353   } else if (FakeStack *fake_stack = get_fake_stack()) {
354     bottom = fake_stack->AddrIsInFakeStack(addr);
355     CHECK(bottom);
356     access->offset = addr - bottom;
357     access->frame_pc = ((uptr *)bottom)[2];
358     access->frame_descr = (const char *)((uptr *)bottom)[1];
359     return true;
360   }
361   uptr aligned_addr = RoundDownTo(addr, SANITIZER_WORDSIZE / 8);  // align addr.
362   uptr mem_ptr = RoundDownTo(aligned_addr, ASAN_SHADOW_GRANULARITY);
363   u8 *shadow_ptr = (u8 *)MemToShadow(aligned_addr);
364   u8 *shadow_bottom = (u8 *)MemToShadow(bottom);
365 
366   while (shadow_ptr >= shadow_bottom &&
367          *shadow_ptr != kAsanStackLeftRedzoneMagic) {
368     shadow_ptr--;
369     mem_ptr -= ASAN_SHADOW_GRANULARITY;
370   }
371 
372   while (shadow_ptr >= shadow_bottom &&
373          *shadow_ptr == kAsanStackLeftRedzoneMagic) {
374     shadow_ptr--;
375     mem_ptr -= ASAN_SHADOW_GRANULARITY;
376   }
377 
378   if (shadow_ptr < shadow_bottom) {
379     return false;
380   }
381 
382   uptr *ptr = (uptr *)(mem_ptr + ASAN_SHADOW_GRANULARITY);
383   CHECK(ptr[0] == kCurrentStackFrameMagic);
384   access->offset = addr - (uptr)ptr;
385   access->frame_pc = ptr[2];
386   access->frame_descr = (const char *)ptr[1];
387   return true;
388 }
389 
390 uptr AsanThread::GetStackVariableShadowStart(uptr addr) {
391   uptr bottom = 0;
392   if (AddrIsInStack(addr)) {
393     bottom = stack_bottom();
394   } else if (FakeStack *fake_stack = get_fake_stack()) {
395     bottom = fake_stack->AddrIsInFakeStack(addr);
396     if (bottom == 0) {
397       return 0;
398     }
399   } else {
400     return 0;
401   }
402 
403   uptr aligned_addr = RoundDownTo(addr, SANITIZER_WORDSIZE / 8);  // align addr.
404   u8 *shadow_ptr = (u8 *)MemToShadow(aligned_addr);
405   u8 *shadow_bottom = (u8 *)MemToShadow(bottom);
406 
407   while (shadow_ptr >= shadow_bottom &&
408          (*shadow_ptr != kAsanStackLeftRedzoneMagic &&
409           *shadow_ptr != kAsanStackMidRedzoneMagic &&
410           *shadow_ptr != kAsanStackRightRedzoneMagic))
411     shadow_ptr--;
412 
413   return (uptr)shadow_ptr + 1;
414 }
415 
416 bool AsanThread::AddrIsInStack(uptr addr) {
417   const auto bounds = GetStackBounds();
418   return addr >= bounds.bottom && addr < bounds.top;
419 }
420 
421 static bool ThreadStackContainsAddress(ThreadContextBase *tctx_base,
422                                        void *addr) {
423   AsanThreadContext *tctx = static_cast<AsanThreadContext *>(tctx_base);
424   AsanThread *t = tctx->thread;
425   if (!t)
426     return false;
427   if (t->AddrIsInStack((uptr)addr))
428     return true;
429   FakeStack *fake_stack = t->get_fake_stack();
430   if (!fake_stack)
431     return false;
432   return fake_stack->AddrIsInFakeStack((uptr)addr);
433 }
434 
435 AsanThread *GetCurrentThread() {
436   AsanThreadContext *context =
437       reinterpret_cast<AsanThreadContext *>(AsanTSDGet());
438   if (!context) {
439     if (SANITIZER_ANDROID) {
440       // On Android, libc constructor is called _after_ asan_init, and cleans up
441       // TSD. Try to figure out if this is still the main thread by the stack
442       // address. We are not entirely sure that we have correct main thread
443       // limits, so only do this magic on Android, and only if the found thread
444       // is the main thread.
445       AsanThreadContext *tctx = GetThreadContextByTidLocked(kMainTid);
446       if (tctx && ThreadStackContainsAddress(tctx, &context)) {
447         SetCurrentThread(tctx->thread);
448         return tctx->thread;
449       }
450     }
451     return nullptr;
452   }
453   return context->thread;
454 }
455 
456 void SetCurrentThread(AsanThread *t) {
457   CHECK(t->context());
458   VReport(2, "SetCurrentThread: %p for thread %p\n", (void *)t->context(),
459           (void *)GetThreadSelf());
460   // Make sure we do not reset the current AsanThread.
461   CHECK_EQ(0, AsanTSDGet());
462   AsanTSDSet(t->context());
463   CHECK_EQ(t->context(), AsanTSDGet());
464 }
465 
466 u32 GetCurrentTidOrInvalid() {
467   AsanThread *t = GetCurrentThread();
468   return t ? t->tid() : kInvalidTid;
469 }
470 
471 AsanThread *FindThreadByStackAddress(uptr addr) {
472   asanThreadRegistry().CheckLocked();
473   AsanThreadContext *tctx = static_cast<AsanThreadContext *>(
474       asanThreadRegistry().FindThreadContextLocked(ThreadStackContainsAddress,
475                                                    (void *)addr));
476   return tctx ? tctx->thread : nullptr;
477 }
478 
479 void EnsureMainThreadIDIsCorrect() {
480   AsanThreadContext *context =
481       reinterpret_cast<AsanThreadContext *>(AsanTSDGet());
482   if (context && (context->tid == kMainTid))
483     context->os_id = GetTid();
484 }
485 
486 __asan::AsanThread *GetAsanThreadByOsIDLocked(tid_t os_id) {
487   __asan::AsanThreadContext *context = static_cast<__asan::AsanThreadContext *>(
488       __asan::asanThreadRegistry().FindThreadContextByOsIDLocked(os_id));
489   if (!context)
490     return nullptr;
491   return context->thread;
492 }
493 }  // namespace __asan
494 
495 // --- Implementation of LSan-specific functions --- {{{1
496 namespace __lsan {
497 void LockThreads() {
498   __asan::asanThreadRegistry().Lock();
499   __asan::asanThreadArgRetval().Lock();
500 }
501 
502 void UnlockThreads() {
503   __asan::asanThreadArgRetval().Unlock();
504   __asan::asanThreadRegistry().Unlock();
505 }
506 
507 static ThreadRegistry *GetAsanThreadRegistryLocked() {
508   __asan::asanThreadRegistry().CheckLocked();
509   return &__asan::asanThreadRegistry();
510 }
511 
512 void EnsureMainThreadIDIsCorrect() { __asan::EnsureMainThreadIDIsCorrect(); }
513 
514 bool GetThreadRangesLocked(tid_t os_id, uptr *stack_begin, uptr *stack_end,
515                            uptr *tls_begin, uptr *tls_end, uptr *cache_begin,
516                            uptr *cache_end, DTLS **dtls) {
517   __asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
518   if (!t)
519     return false;
520   *stack_begin = t->stack_bottom();
521   *stack_end = t->stack_top();
522   *tls_begin = t->tls_begin();
523   *tls_end = t->tls_end();
524   // ASan doesn't keep allocator caches in TLS, so these are unused.
525   *cache_begin = 0;
526   *cache_end = 0;
527   *dtls = t->dtls();
528   return true;
529 }
530 
531 void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {}
532 
533 void GetThreadExtraStackRangesLocked(tid_t os_id,
534                                      InternalMmapVector<Range> *ranges) {
535   __asan::AsanThread *t = __asan::GetAsanThreadByOsIDLocked(os_id);
536   if (!t)
537     return;
538   __asan::FakeStack *fake_stack = t->get_fake_stack();
539   if (!fake_stack)
540     return;
541 
542   fake_stack->ForEachFakeFrame(
543       [](uptr begin, uptr end, void *arg) {
544         reinterpret_cast<InternalMmapVector<Range> *>(arg)->push_back(
545             {begin, end});
546       },
547       ranges);
548 }
549 
550 void GetThreadExtraStackRangesLocked(InternalMmapVector<Range> *ranges) {
551   GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(
552       [](ThreadContextBase *tctx, void *arg) {
553         GetThreadExtraStackRangesLocked(
554             tctx->os_id, reinterpret_cast<InternalMmapVector<Range> *>(arg));
555       },
556       ranges);
557 }
558 
559 void GetAdditionalThreadContextPtrsLocked(InternalMmapVector<uptr> *ptrs) {
560   __asan::asanThreadArgRetval().GetAllPtrsLocked(ptrs);
561 }
562 
563 void GetRunningThreadsLocked(InternalMmapVector<tid_t> *threads) {
564   GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(
565       [](ThreadContextBase *tctx, void *threads) {
566         if (tctx->status == ThreadStatusRunning)
567           reinterpret_cast<InternalMmapVector<tid_t> *>(threads)->push_back(
568               tctx->os_id);
569       },
570       threads);
571 }
572 
573 }  // namespace __lsan
574 
575 // ---------------------- Interface ---------------- {{{1
576 using namespace __asan;
577 
578 extern "C" {
579 SANITIZER_INTERFACE_ATTRIBUTE
580 void __sanitizer_start_switch_fiber(void **fakestacksave, const void *bottom,
581                                     uptr size) {
582   AsanThread *t = GetCurrentThread();
583   if (!t) {
584     VReport(1, "__asan_start_switch_fiber called from unknown thread\n");
585     return;
586   }
587   t->StartSwitchFiber((FakeStack **)fakestacksave, (uptr)bottom, size);
588 }
589 
590 SANITIZER_INTERFACE_ATTRIBUTE
591 void __sanitizer_finish_switch_fiber(void *fakestack, const void **bottom_old,
592                                      uptr *size_old) {
593   AsanThread *t = GetCurrentThread();
594   if (!t) {
595     VReport(1, "__asan_finish_switch_fiber called from unknown thread\n");
596     return;
597   }
598   t->FinishSwitchFiber((FakeStack *)fakestack, (uptr *)bottom_old,
599                        (uptr *)size_old);
600 }
601 }
602