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_thread_history.h"
25#include "sanitizer_common/sanitizer_tls_get_addr.h"
26
27namespace __asan {
28
29// AsanThreadContext implementation.
30
31void AsanThreadContext::OnCreated(void *arg) {
32 thread = static_cast<AsanThread *>(arg);
33 thread->set_context(this);
34}
35
36void AsanThreadContext::OnFinished() {
37 // Drop the link to the AsanThread object.
38 thread = nullptr;
39}
40
41static ThreadRegistry *asan_thread_registry;
42static ThreadArgRetval *thread_data;
43
44static Mutex mu_for_thread_context;
45// TODO(leonardchan@): It should be possible to make LowLevelAllocator
46// threadsafe and consolidate this one into the GlobalLoweLevelAllocator.
47// We should be able to do something similar to what's in
48// sanitizer_stack_store.cpp.
49static LowLevelAllocator allocator_for_thread_context;
50
51static ThreadContextBase *GetAsanThreadContext(u32 tid) {
52 Lock lock(&mu_for_thread_context);
53 return new (allocator_for_thread_context) AsanThreadContext(tid);
54}
55
56static void InitThreads() {
57 static bool initialized;
58 // Don't worry about thread_safety - this should be called when there is
59 // a single thread.
60 if (LIKELY(initialized))
61 return;
62 // Never reuse ASan threads: we store pointer to AsanThreadContext
63 // in TSD and can't reliably tell when no more TSD destructors will
64 // be called. It would be wrong to reuse AsanThreadContext for another
65 // thread before all TSD destructors will be called for it.
66
67 // MIPS requires aligned address
68 alignas(alignof(ThreadRegistry)) static char
69 thread_registry_placeholder[sizeof(ThreadRegistry)];
70 alignas(alignof(ThreadArgRetval)) static char
71 thread_data_placeholder[sizeof(ThreadArgRetval)];
72
73 asan_thread_registry =
74 new (thread_registry_placeholder) ThreadRegistry(GetAsanThreadContext);
75 thread_data = new (thread_data_placeholder) ThreadArgRetval();
76 initialized = true;
77}
78
79ThreadRegistry &asanThreadRegistry() {
80 InitThreads();
81 return *asan_thread_registry;
82}
83
84ThreadArgRetval &asanThreadArgRetval() {
85 InitThreads();
86 return *thread_data;
87}
88
89AsanThreadContext *GetThreadContextByTidLocked(u32 tid) {
90 return static_cast<AsanThreadContext *>(
91 asanThreadRegistry().GetThreadLocked(tid));
92}
93
94// AsanThread implementation.
95
96AsanThread *AsanThread::Create(const void *start_data, uptr data_size,
97 u32 parent_tid, StackTrace *stack,
98 bool detached) {
99 uptr PageSize = GetPageSizeCached();
100 uptr size = RoundUpTo(size: sizeof(AsanThread), boundary: PageSize);
101 AsanThread *thread = (AsanThread *)MmapOrDie(size, mem_type: __func__);
102 if (data_size) {
103 uptr availible_size = (uptr)thread + size - (uptr)(thread->start_data_);
104 CHECK_LE(data_size, availible_size);
105 internal_memcpy(dest: thread->start_data_, src: start_data, n: data_size);
106 }
107 asanThreadRegistry().CreateThread(user_id: 0, detached, parent_tid,
108 stack_tid: stack ? StackDepotPut(stack: *stack) : 0, arg: thread);
109
110 return thread;
111}
112
113void AsanThread::GetStartData(void *out, uptr out_size) const {
114 internal_memcpy(dest: out, src: start_data_, n: out_size);
115}
116
117void AsanThread::TSDDtor(void *tsd) {
118 AsanThreadContext *context = (AsanThreadContext *)tsd;
119 VReport(1, "T%d TSDDtor\n", context->tid);
120 if (context->thread)
121 context->thread->Destroy();
122}
123
124void AsanThread::Destroy() {
125 int tid = this->tid();
126 VReport(1, "T%d exited\n", tid);
127
128 bool was_running =
129 (asanThreadRegistry().FinishThread(tid) == ThreadStatusRunning);
130 if (was_running) {
131 if (AsanThread *thread = GetCurrentThread())
132 CHECK_EQ(this, thread);
133 malloc_storage().CommitBack();
134 if (common_flags()->use_sigaltstack)
135 UnsetAlternateSignalStack();
136 FlushToDeadThreadStats(stats: &stats_);
137 // We also clear the shadow on thread destruction because
138 // some code may still be executing in later TSD destructors
139 // and we don't want it to have any poisoned stack.
140 ClearShadowForThreadStackAndTLS();
141 DeleteFakeStack(tid);
142 } else {
143 CHECK_NE(this, GetCurrentThread());
144 }
145 uptr size = RoundUpTo(size: sizeof(AsanThread), boundary: GetPageSizeCached());
146 UnmapOrDie(addr: this, size);
147 if (was_running)
148 DTLS_Destroy();
149}
150
151void AsanThread::StartSwitchFiber(FakeStack **fake_stack_save, uptr bottom,
152 uptr size) {
153 if (atomic_load(a: &stack_switching_, mo: memory_order_relaxed)) {
154 Report(format: "ERROR: starting fiber switch while in fiber switch\n");
155 Die();
156 }
157
158 next_stack_bottom_ = bottom;
159 next_stack_top_ = bottom + size;
160 atomic_store(a: &stack_switching_, v: 1, mo: memory_order_release);
161
162 FakeStack *current_fake_stack = fake_stack_;
163 if (fake_stack_save)
164 *fake_stack_save = fake_stack_;
165 fake_stack_ = nullptr;
166 ResetTLSFakeStack();
167 // if fake_stack_save is null, the fiber will die, delete the fakestack
168 if (!fake_stack_save && current_fake_stack)
169 current_fake_stack->Destroy(tid: this->tid());
170}
171
172void AsanThread::FinishSwitchFiber(FakeStack *fake_stack_save, uptr *bottom_old,
173 uptr *size_old) {
174 if (!atomic_load(a: &stack_switching_, mo: memory_order_relaxed)) {
175 Report(format: "ERROR: finishing a fiber switch that has not started\n");
176 Die();
177 }
178
179 if (fake_stack_save) {
180 fake_stack_ = fake_stack_save;
181 ResetTLSFakeStack();
182 }
183
184 if (bottom_old)
185 *bottom_old = stack_bottom_;
186 if (size_old)
187 *size_old = stack_top_ - stack_bottom_;
188 stack_bottom_ = next_stack_bottom_;
189 stack_top_ = next_stack_top_;
190 atomic_store(a: &stack_switching_, v: 0, mo: memory_order_release);
191 next_stack_top_ = 0;
192 next_stack_bottom_ = 0;
193}
194
195inline AsanThread::StackBounds AsanThread::GetStackBounds() const {
196 if (!atomic_load(a: &stack_switching_, mo: memory_order_acquire)) {
197 // Make sure the stack bounds are fully initialized.
198 if (stack_bottom_ >= stack_top_)
199 return {.bottom: 0, .top: 0};
200 return {.bottom: stack_bottom_, .top: stack_top_};
201 }
202 char local;
203 const uptr cur_stack = (uptr)&local;
204 // Note: need to check next stack first, because FinishSwitchFiber
205 // may be in process of overwriting stack_top_/bottom_. But in such case
206 // we are already on the next stack.
207 if (cur_stack >= next_stack_bottom_ && cur_stack < next_stack_top_)
208 return {.bottom: next_stack_bottom_, .top: next_stack_top_};
209 return {.bottom: stack_bottom_, .top: stack_top_};
210}
211
212uptr AsanThread::stack_top() { return GetStackBounds().top; }
213
214uptr AsanThread::stack_bottom() { return GetStackBounds().bottom; }
215
216uptr AsanThread::stack_size() {
217 const auto bounds = GetStackBounds();
218 return bounds.top - bounds.bottom;
219}
220
221// We want to create the FakeStack lazily on the first use, but not earlier
222// than the stack size is known and the procedure has to be async-signal safe.
223FakeStack *AsanThread::AsyncSignalSafeLazyInitFakeStack() {
224 uptr stack_size = this->stack_size();
225 if (stack_size == 0) // stack_size is not yet available, don't use FakeStack.
226 return nullptr;
227 uptr old_val = 0;
228 // fake_stack_ has 3 states:
229 // 0 -- not initialized
230 // 1 -- being initialized
231 // ptr -- initialized
232 // This CAS checks if the state was 0 and if so changes it to state 1,
233 // if that was successful, it initializes the pointer.
234 if (atomic_compare_exchange_strong(
235 a: reinterpret_cast<atomic_uintptr_t *>(&fake_stack_), cmp: &old_val, xchg: 1UL,
236 mo: memory_order_relaxed)) {
237 uptr stack_size_log = Log2(x: RoundUpToPowerOfTwo(size: stack_size));
238 CHECK_LE(flags()->min_uar_stack_size_log, flags()->max_uar_stack_size_log);
239 stack_size_log =
240 Min(a: stack_size_log, b: static_cast<uptr>(flags()->max_uar_stack_size_log));
241 stack_size_log =
242 Max(a: stack_size_log, b: static_cast<uptr>(flags()->min_uar_stack_size_log));
243 fake_stack_ = FakeStack::Create(stack_size_log);
244 DCHECK_EQ(GetCurrentThread(), this);
245 ResetTLSFakeStack();
246 return fake_stack_;
247 }
248 return nullptr;
249}
250
251void AsanThread::Init(const InitOptions *options) {
252 DCHECK_NE(tid(), kInvalidTid);
253 next_stack_top_ = next_stack_bottom_ = 0;
254 fake_stack_suppression_counter_ = 0;
255 atomic_store(a: &stack_switching_, v: false, mo: memory_order_release);
256 CHECK_EQ(this->stack_size(), 0U);
257 SetThreadStackAndTls(options);
258 if (stack_top_ != stack_bottom_) {
259 CHECK_GT(this->stack_size(), 0U);
260 CHECK(AddrIsInMem(stack_bottom_));
261 CHECK(AddrIsInMem(stack_top_ - 1));
262 }
263 ClearShadowForThreadStackAndTLS();
264 fake_stack_ = nullptr;
265 if (__asan_option_detect_stack_use_after_return &&
266 tid() == GetCurrentTidOrInvalid()) {
267 // AsyncSignalSafeLazyInitFakeStack makes use of threadlocals and must be
268 // called from the context of the thread it is initializing, not its parent.
269 // Most platforms call AsanThread::Init on the newly-spawned thread, but
270 // Fuchsia calls this function from the parent thread. To support that
271 // approach, we avoid calling AsyncSignalSafeLazyInitFakeStack here; it will
272 // be called by the new thread when it first attempts to access the fake
273 // stack.
274 AsyncSignalSafeLazyInitFakeStack();
275 }
276 int local = 0;
277 VReport(1, "T%d: stack [%p,%p) size 0x%zx; local=%p\n", tid(),
278 (void *)stack_bottom_, (void *)stack_top_, stack_top_ - stack_bottom_,
279 (void *)&local);
280}
281
282// Fuchsia doesn't use ThreadStart.
283// asan_fuchsia.c definies CreateMainThread and SetThreadStackAndTls.
284#if !SANITIZER_FUCHSIA
285
286void AsanThread::ThreadStart(ThreadID os_id) {
287 Init();
288 asanThreadRegistry().StartThread(tid: tid(), os_id, thread_type: ThreadType::Regular, arg: nullptr);
289
290 if (common_flags()->use_sigaltstack)
291 SetAlternateSignalStack();
292}
293
294AsanThread *CreateMainThread() {
295 AsanThread *main_thread = AsanThread::Create(
296 /* parent_tid */ kMainTid,
297 /* stack */ nullptr, /* detached */ true);
298 SetCurrentThread(main_thread);
299 main_thread->ThreadStart(os_id: internal_getpid());
300 return main_thread;
301}
302
303// This implementation doesn't use the argument, which is just passed down
304// from the caller of Init (which see, above). It's only there to support
305// OS-specific implementations that need more information passed through.
306void AsanThread::SetThreadStackAndTls(const InitOptions *options) {
307 DCHECK_EQ(options, nullptr);
308 GetThreadStackAndTls(main: tid() == kMainTid, stk_begin: &stack_bottom_, stk_end: &stack_top_,
309 tls_begin: &tls_begin_, tls_end: &tls_end_);
310 stack_top_ = RoundDownTo(x: stack_top_, ASAN_SHADOW_GRANULARITY);
311 stack_bottom_ = RoundDownTo(x: stack_bottom_, ASAN_SHADOW_GRANULARITY);
312 dtls_ = DTLS_Get();
313
314 if (stack_top_ != stack_bottom_) {
315 int local;
316 CHECK(AddrIsInStack((uptr)&local));
317 }
318}
319
320#endif // !SANITIZER_FUCHSIA
321
322void AsanThread::ClearShadowForThreadStackAndTLS() {
323 if (stack_top_ != stack_bottom_)
324 PoisonShadow(addr: stack_bottom_, size: stack_top_ - stack_bottom_, value: 0);
325 if (tls_begin_ != tls_end_) {
326 uptr tls_begin_aligned = RoundDownTo(x: tls_begin_, ASAN_SHADOW_GRANULARITY);
327 uptr tls_end_aligned = RoundUpTo(size: tls_end_, ASAN_SHADOW_GRANULARITY);
328 FastPoisonShadow(aligned_beg: tls_begin_aligned, aligned_size: tls_end_aligned - tls_begin_aligned, value: 0);
329 }
330}
331
332bool AsanThread::GetStackFrameAccessByAddr(uptr addr,
333 StackFrameAccess *access) {
334 if (stack_top_ == stack_bottom_)
335 return false;
336
337 uptr bottom = 0;
338 if (AddrIsInStack(addr)) {
339 bottom = stack_bottom();
340 } else if (FakeStack *fake_stack = get_fake_stack()) {
341 bottom = fake_stack->AddrIsInFakeStack(addr);
342 CHECK(bottom);
343 access->offset = addr - bottom;
344 access->frame_pc = ((uptr *)bottom)[2];
345 access->frame_descr = (const char *)((uptr *)bottom)[1];
346 return true;
347 }
348 uptr aligned_addr = RoundDownTo(x: addr, SANITIZER_WORDSIZE / 8); // align addr.
349 uptr mem_ptr = RoundDownTo(x: aligned_addr, ASAN_SHADOW_GRANULARITY);
350 u8 *shadow_ptr = (u8 *)MemToShadow(p: aligned_addr);
351 u8 *shadow_bottom = (u8 *)MemToShadow(p: bottom);
352
353 while (shadow_ptr >= shadow_bottom &&
354 *shadow_ptr != kAsanStackLeftRedzoneMagic) {
355 shadow_ptr--;
356 mem_ptr -= ASAN_SHADOW_GRANULARITY;
357 }
358
359 while (shadow_ptr >= shadow_bottom &&
360 *shadow_ptr == kAsanStackLeftRedzoneMagic) {
361 shadow_ptr--;
362 mem_ptr -= ASAN_SHADOW_GRANULARITY;
363 }
364
365 if (shadow_ptr < shadow_bottom) {
366 return false;
367 }
368
369 uptr *ptr = (uptr *)(mem_ptr + ASAN_SHADOW_GRANULARITY);
370 CHECK(ptr[0] == kCurrentStackFrameMagic);
371 access->offset = addr - (uptr)ptr;
372 access->frame_pc = ptr[2];
373 access->frame_descr = (const char *)ptr[1];
374 return true;
375}
376
377uptr AsanThread::GetStackVariableShadowStart(uptr addr) {
378 uptr bottom = 0;
379 if (AddrIsInStack(addr)) {
380 bottom = stack_bottom();
381 } else if (FakeStack *fake_stack = get_fake_stack()) {
382 bottom = fake_stack->AddrIsInFakeStack(addr);
383 if (bottom == 0) {
384 return 0;
385 }
386 } else {
387 return 0;
388 }
389
390 uptr aligned_addr = RoundDownTo(x: addr, SANITIZER_WORDSIZE / 8); // align addr.
391 u8 *shadow_ptr = (u8 *)MemToShadow(p: aligned_addr);
392 u8 *shadow_bottom = (u8 *)MemToShadow(p: bottom);
393
394 while (shadow_ptr >= shadow_bottom &&
395 (*shadow_ptr != kAsanStackLeftRedzoneMagic &&
396 *shadow_ptr != kAsanStackMidRedzoneMagic &&
397 *shadow_ptr != kAsanStackRightRedzoneMagic))
398 shadow_ptr--;
399
400 return (uptr)shadow_ptr + 1;
401}
402
403bool AsanThread::AddrIsInStack(uptr addr) {
404 const auto bounds = GetStackBounds();
405 return addr >= bounds.bottom && addr < bounds.top;
406}
407
408void AsanThread::SuppressFakeStack() {
409 ++fake_stack_suppression_counter_;
410 ResetTLSFakeStack();
411}
412
413void AsanThread::UnsuppressFakeStack() {
414 if (fake_stack_suppression_counter_ == 0) {
415 Report(format: "ERROR: Unmatched call to __asan_unsuppress_fake_stack().\n");
416 Die();
417 }
418 --fake_stack_suppression_counter_;
419}
420
421static 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(addr: (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(addr: (uptr)addr);
433}
434
435AsanThread *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(tid: kMainTid);
446 if (tctx && ThreadStackContainsAddress(tctx_base: tctx, addr: &context)) {
447 SetCurrentThread(tctx->thread);
448 return tctx->thread;
449 }
450 }
451 return nullptr;
452 }
453 return context->thread;
454}
455
456void 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(tsd: t->context());
463 CHECK_EQ(t->context(), AsanTSDGet());
464}
465
466u32 GetCurrentTidOrInvalid() {
467 AsanThread *t = GetCurrentThread();
468 return t ? t->tid() : kInvalidTid;
469}
470
471AsanThread *FindThreadByStackAddress(uptr addr) {
472 asanThreadRegistry().CheckLocked();
473 AsanThreadContext *tctx = static_cast<AsanThreadContext *>(
474 asanThreadRegistry().FindThreadContextLocked(cb: ThreadStackContainsAddress,
475 arg: (void *)addr));
476 return tctx ? tctx->thread : nullptr;
477}
478
479void 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(ThreadID 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
496namespace __lsan {
497void LockThreads() {
498 __asan::asanThreadRegistry().Lock();
499 __asan::asanThreadArgRetval().Lock();
500}
501
502void UnlockThreads() {
503 __asan::asanThreadArgRetval().Unlock();
504 __asan::asanThreadRegistry().Unlock();
505}
506
507static ThreadRegistry *GetAsanThreadRegistryLocked() {
508 __asan::asanThreadRegistry().CheckLocked();
509 return &__asan::asanThreadRegistry();
510}
511
512void EnsureMainThreadIDIsCorrect() { __asan::EnsureMainThreadIDIsCorrect(); }
513
514bool GetThreadRangesLocked(ThreadID 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
531void GetAllThreadAllocatorCachesLocked(InternalMmapVector<uptr> *caches) {}
532
533void GetThreadExtraStackRangesLocked(ThreadID 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 callback: [](uptr begin, uptr end, void *arg) {
544 reinterpret_cast<InternalMmapVector<Range> *>(arg)->push_back(
545 element: {.begin: begin, .end: end});
546 },
547 arg: ranges);
548}
549
550void GetThreadExtraStackRangesLocked(InternalMmapVector<Range> *ranges) {
551 GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(
552 cb: [](ThreadContextBase *tctx, void *arg) {
553 GetThreadExtraStackRangesLocked(
554 os_id: tctx->os_id, ranges: reinterpret_cast<InternalMmapVector<Range> *>(arg));
555 },
556 arg: ranges);
557}
558
559void GetAdditionalThreadContextPtrsLocked(InternalMmapVector<uptr> *ptrs) {
560 __asan::asanThreadArgRetval().GetAllPtrsLocked(ptrs);
561}
562
563void GetRunningThreadsLocked(InternalMmapVector<ThreadID> *threads) {
564 GetAsanThreadRegistryLocked()->RunCallbackForEachThreadLocked(
565 cb: [](ThreadContextBase *tctx, void *threads) {
566 if (tctx->status == ThreadStatusRunning)
567 reinterpret_cast<InternalMmapVector<ThreadID> *>(threads)->push_back(
568 element: tctx->os_id);
569 },
570 arg: threads);
571}
572
573void PrintThreads() {
574 InternalScopedString out;
575 PrintThreadHistory(registry&: __asan::asanThreadRegistry(), out);
576 Report(format: "%s\n", out.data());
577}
578
579} // namespace __lsan
580
581// ---------------------- Interface ---------------- {{{1
582using namespace __asan;
583
584extern "C" {
585SANITIZER_INTERFACE_ATTRIBUTE
586void __sanitizer_start_switch_fiber(void **fakestacksave, const void *bottom,
587 uptr size) {
588 AsanThread *t = GetCurrentThread();
589 if (!t) {
590 VReport(1, "__asan_start_switch_fiber called from unknown thread\n");
591 return;
592 }
593 t->StartSwitchFiber(fake_stack_save: (FakeStack **)fakestacksave, bottom: (uptr)bottom, size);
594}
595
596SANITIZER_INTERFACE_ATTRIBUTE
597void __sanitizer_finish_switch_fiber(void *fakestack, const void **bottom_old,
598 uptr *size_old) {
599 AsanThread *t = GetCurrentThread();
600 if (!t) {
601 VReport(1, "__asan_finish_switch_fiber called from unknown thread\n");
602 return;
603 }
604 t->FinishSwitchFiber(fake_stack_save: (FakeStack *)fakestack, bottom_old: (uptr *)bottom_old,
605 size_old: (uptr *)size_old);
606}
607}
608