Add initial qualcomm support.
[official-gcc.git] / libsanitizer / asan / asan_rtl.cc
blob551fea5b0c7818ab0bec451731040cabfa98441b
1 //===-- asan_rtl.cc -------------------------------------------------------===//
2 //
3 // This file is distributed under the University of Illinois Open Source
4 // License. See LICENSE.TXT for details.
5 //
6 //===----------------------------------------------------------------------===//
7 //
8 // This file is a part of AddressSanitizer, an address sanity checker.
9 //
10 // Main file of the ASan run-time library.
11 //===----------------------------------------------------------------------===//
13 #include "asan_activation.h"
14 #include "asan_allocator.h"
15 #include "asan_interceptors.h"
16 #include "asan_interface_internal.h"
17 #include "asan_internal.h"
18 #include "asan_mapping.h"
19 #include "asan_poisoning.h"
20 #include "asan_report.h"
21 #include "asan_stack.h"
22 #include "asan_stats.h"
23 #include "asan_suppressions.h"
24 #include "asan_thread.h"
25 #include "sanitizer_common/sanitizer_atomic.h"
26 #include "sanitizer_common/sanitizer_flags.h"
27 #include "sanitizer_common/sanitizer_libc.h"
28 #include "sanitizer_common/sanitizer_symbolizer.h"
29 #include "lsan/lsan_common.h"
30 #include "ubsan/ubsan_init.h"
31 #include "ubsan/ubsan_platform.h"
33 int __asan_option_detect_stack_use_after_return; // Global interface symbol.
34 uptr *__asan_test_only_reported_buggy_pointer; // Used only for testing asan.
36 namespace __asan {
38 uptr AsanMappingProfile[kAsanMappingProfileSize];
40 static void AsanDie() {
41 static atomic_uint32_t num_calls;
42 if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) {
43 // Don't die twice - run a busy loop.
44 while (1) { }
46 if (flags()->sleep_before_dying) {
47 Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying);
48 SleepForSeconds(flags()->sleep_before_dying);
50 if (flags()->unmap_shadow_on_exit) {
51 if (kMidMemBeg) {
52 UnmapOrDie((void*)kLowShadowBeg, kMidMemBeg - kLowShadowBeg);
53 UnmapOrDie((void*)kMidMemEnd, kHighShadowEnd - kMidMemEnd);
54 } else {
55 UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg);
60 static void AsanCheckFailed(const char *file, int line, const char *cond,
61 u64 v1, u64 v2) {
62 Report("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", file,
63 line, cond, (uptr)v1, (uptr)v2);
64 // FIXME: check for infinite recursion without a thread-local counter here.
65 PRINT_CURRENT_STACK_CHECK();
66 Die();
69 // -------------------------- Globals --------------------- {{{1
70 int asan_inited;
71 bool asan_init_is_running;
73 #if !ASAN_FIXED_MAPPING
74 uptr kHighMemEnd, kMidMemBeg, kMidMemEnd;
75 #endif
77 // -------------------------- Misc ---------------- {{{1
78 void ShowStatsAndAbort() {
79 __asan_print_accumulated_stats();
80 Die();
83 // ---------------------- mmap -------------------- {{{1
84 // Reserve memory range [beg, end].
85 // We need to use inclusive range because end+1 may not be representable.
86 void ReserveShadowMemoryRange(uptr beg, uptr end, const char *name) {
87 CHECK_EQ((beg % GetPageSizeCached()), 0);
88 CHECK_EQ(((end + 1) % GetPageSizeCached()), 0);
89 uptr size = end - beg + 1;
90 DecreaseTotalMmap(size); // Don't count the shadow against mmap_limit_mb.
91 void *res = MmapFixedNoReserve(beg, size, name);
92 if (res != (void*)beg) {
93 Report("ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. "
94 "Perhaps you're using ulimit -v\n", size);
95 Abort();
97 if (common_flags()->no_huge_pages_for_shadow)
98 NoHugePagesInRegion(beg, size);
99 if (common_flags()->use_madv_dontdump)
100 DontDumpShadowMemory(beg, size);
103 // --------------- LowLevelAllocateCallbac ---------- {{{1
104 static void OnLowLevelAllocate(uptr ptr, uptr size) {
105 PoisonShadow(ptr, size, kAsanInternalHeapMagic);
108 // -------------------------- Run-time entry ------------------- {{{1
109 // exported functions
110 #define ASAN_REPORT_ERROR(type, is_write, size) \
111 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
112 void __asan_report_ ## type ## size(uptr addr) { \
113 GET_CALLER_PC_BP_SP; \
114 __asan_report_error(pc, bp, sp, addr, is_write, size, 0); \
116 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
117 void __asan_report_exp_ ## type ## size(uptr addr, u32 exp) { \
118 GET_CALLER_PC_BP_SP; \
119 __asan_report_error(pc, bp, sp, addr, is_write, size, exp); \
122 ASAN_REPORT_ERROR(load, false, 1)
123 ASAN_REPORT_ERROR(load, false, 2)
124 ASAN_REPORT_ERROR(load, false, 4)
125 ASAN_REPORT_ERROR(load, false, 8)
126 ASAN_REPORT_ERROR(load, false, 16)
127 ASAN_REPORT_ERROR(store, true, 1)
128 ASAN_REPORT_ERROR(store, true, 2)
129 ASAN_REPORT_ERROR(store, true, 4)
130 ASAN_REPORT_ERROR(store, true, 8)
131 ASAN_REPORT_ERROR(store, true, 16)
133 #define ASAN_REPORT_ERROR_N(type, is_write) \
134 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
135 void __asan_report_ ## type ## _n(uptr addr, uptr size) { \
136 GET_CALLER_PC_BP_SP; \
137 __asan_report_error(pc, bp, sp, addr, is_write, size, 0); \
139 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
140 void __asan_report_exp_ ## type ## _n(uptr addr, uptr size, u32 exp) { \
141 GET_CALLER_PC_BP_SP; \
142 __asan_report_error(pc, bp, sp, addr, is_write, size, exp); \
145 ASAN_REPORT_ERROR_N(load, false)
146 ASAN_REPORT_ERROR_N(store, true)
148 #define ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, exp_arg) \
149 uptr sp = MEM_TO_SHADOW(addr); \
150 uptr s = size <= SHADOW_GRANULARITY ? *reinterpret_cast<u8 *>(sp) \
151 : *reinterpret_cast<u16 *>(sp); \
152 if (UNLIKELY(s)) { \
153 if (UNLIKELY(size >= SHADOW_GRANULARITY || \
154 ((s8)((addr & (SHADOW_GRANULARITY - 1)) + size - 1)) >= \
155 (s8)s)) { \
156 if (__asan_test_only_reported_buggy_pointer) { \
157 *__asan_test_only_reported_buggy_pointer = addr; \
158 } else { \
159 GET_CALLER_PC_BP_SP; \
160 __asan_report_error(pc, bp, sp, addr, is_write, size, exp_arg); \
165 #define ASAN_MEMORY_ACCESS_CALLBACK(type, is_write, size) \
166 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
167 void __asan_##type##size(uptr addr) { \
168 ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, 0) \
170 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
171 void __asan_exp_##type##size(uptr addr, u32 exp) { \
172 ASAN_MEMORY_ACCESS_CALLBACK_BODY(type, is_write, size, exp) \
175 ASAN_MEMORY_ACCESS_CALLBACK(load, false, 1)
176 ASAN_MEMORY_ACCESS_CALLBACK(load, false, 2)
177 ASAN_MEMORY_ACCESS_CALLBACK(load, false, 4)
178 ASAN_MEMORY_ACCESS_CALLBACK(load, false, 8)
179 ASAN_MEMORY_ACCESS_CALLBACK(load, false, 16)
180 ASAN_MEMORY_ACCESS_CALLBACK(store, true, 1)
181 ASAN_MEMORY_ACCESS_CALLBACK(store, true, 2)
182 ASAN_MEMORY_ACCESS_CALLBACK(store, true, 4)
183 ASAN_MEMORY_ACCESS_CALLBACK(store, true, 8)
184 ASAN_MEMORY_ACCESS_CALLBACK(store, true, 16)
186 extern "C"
187 NOINLINE INTERFACE_ATTRIBUTE
188 void __asan_loadN(uptr addr, uptr size) {
189 if (__asan_region_is_poisoned(addr, size)) {
190 GET_CALLER_PC_BP_SP;
191 __asan_report_error(pc, bp, sp, addr, false, size, 0);
195 extern "C"
196 NOINLINE INTERFACE_ATTRIBUTE
197 void __asan_exp_loadN(uptr addr, uptr size, u32 exp) {
198 if (__asan_region_is_poisoned(addr, size)) {
199 GET_CALLER_PC_BP_SP;
200 __asan_report_error(pc, bp, sp, addr, false, size, exp);
204 extern "C"
205 NOINLINE INTERFACE_ATTRIBUTE
206 void __asan_storeN(uptr addr, uptr size) {
207 if (__asan_region_is_poisoned(addr, size)) {
208 GET_CALLER_PC_BP_SP;
209 __asan_report_error(pc, bp, sp, addr, true, size, 0);
213 extern "C"
214 NOINLINE INTERFACE_ATTRIBUTE
215 void __asan_exp_storeN(uptr addr, uptr size, u32 exp) {
216 if (__asan_region_is_poisoned(addr, size)) {
217 GET_CALLER_PC_BP_SP;
218 __asan_report_error(pc, bp, sp, addr, true, size, exp);
222 // Force the linker to keep the symbols for various ASan interface functions.
223 // We want to keep those in the executable in order to let the instrumented
224 // dynamic libraries access the symbol even if it is not used by the executable
225 // itself. This should help if the build system is removing dead code at link
226 // time.
227 static NOINLINE void force_interface_symbols() {
228 volatile int fake_condition = 0; // prevent dead condition elimination.
229 // __asan_report_* functions are noreturn, so we need a switch to prevent
230 // the compiler from removing any of them.
231 switch (fake_condition) {
232 case 1: __asan_report_load1(0); break;
233 case 2: __asan_report_load2(0); break;
234 case 3: __asan_report_load4(0); break;
235 case 4: __asan_report_load8(0); break;
236 case 5: __asan_report_load16(0); break;
237 case 6: __asan_report_load_n(0, 0); break;
238 case 7: __asan_report_store1(0); break;
239 case 8: __asan_report_store2(0); break;
240 case 9: __asan_report_store4(0); break;
241 case 10: __asan_report_store8(0); break;
242 case 11: __asan_report_store16(0); break;
243 case 12: __asan_report_store_n(0, 0); break;
244 case 13: __asan_report_exp_load1(0, 0); break;
245 case 14: __asan_report_exp_load2(0, 0); break;
246 case 15: __asan_report_exp_load4(0, 0); break;
247 case 16: __asan_report_exp_load8(0, 0); break;
248 case 17: __asan_report_exp_load16(0, 0); break;
249 case 18: __asan_report_exp_load_n(0, 0, 0); break;
250 case 19: __asan_report_exp_store1(0, 0); break;
251 case 20: __asan_report_exp_store2(0, 0); break;
252 case 21: __asan_report_exp_store4(0, 0); break;
253 case 22: __asan_report_exp_store8(0, 0); break;
254 case 23: __asan_report_exp_store16(0, 0); break;
255 case 24: __asan_report_exp_store_n(0, 0, 0); break;
256 case 25: __asan_register_globals(nullptr, 0); break;
257 case 26: __asan_unregister_globals(nullptr, 0); break;
258 case 27: __asan_set_death_callback(nullptr); break;
259 case 28: __asan_set_error_report_callback(nullptr); break;
260 case 29: __asan_handle_no_return(); break;
261 case 30: __asan_address_is_poisoned(nullptr); break;
262 case 31: __asan_poison_memory_region(nullptr, 0); break;
263 case 32: __asan_unpoison_memory_region(nullptr, 0); break;
264 case 34: __asan_before_dynamic_init(nullptr); break;
265 case 35: __asan_after_dynamic_init(); break;
266 case 36: __asan_poison_stack_memory(0, 0); break;
267 case 37: __asan_unpoison_stack_memory(0, 0); break;
268 case 38: __asan_region_is_poisoned(0, 0); break;
269 case 39: __asan_describe_address(0); break;
273 static void asan_atexit() {
274 Printf("AddressSanitizer exit stats:\n");
275 __asan_print_accumulated_stats();
276 // Print AsanMappingProfile.
277 for (uptr i = 0; i < kAsanMappingProfileSize; i++) {
278 if (AsanMappingProfile[i] == 0) continue;
279 Printf("asan_mapping.h:%zd -- %zd\n", i, AsanMappingProfile[i]);
283 static void InitializeHighMemEnd() {
284 #if !ASAN_FIXED_MAPPING
285 kHighMemEnd = GetMaxVirtualAddress();
286 // Increase kHighMemEnd to make sure it's properly
287 // aligned together with kHighMemBeg:
288 kHighMemEnd |= SHADOW_GRANULARITY * GetPageSizeCached() - 1;
289 #endif // !ASAN_FIXED_MAPPING
290 CHECK_EQ((kHighMemBeg % GetPageSizeCached()), 0);
293 static void ProtectGap(uptr addr, uptr size) {
294 void *res = MmapNoAccess(addr, size, "shadow gap");
295 if (addr == (uptr)res)
296 return;
297 // A few pages at the start of the address space can not be protected.
298 // But we really want to protect as much as possible, to prevent this memory
299 // being returned as a result of a non-FIXED mmap().
300 if (addr == kZeroBaseShadowStart) {
301 uptr step = GetPageSizeCached();
302 while (size > step && addr < kZeroBaseMaxShadowStart) {
303 addr += step;
304 size -= step;
305 void *res = MmapNoAccess(addr, size, "shadow gap");
306 if (addr == (uptr)res)
307 return;
311 Report("ERROR: Failed to protect the shadow gap. "
312 "ASan cannot proceed correctly. ABORTING.\n");
313 DumpProcessMap();
314 Die();
317 static void PrintAddressSpaceLayout() {
318 Printf("|| `[%p, %p]` || HighMem ||\n",
319 (void*)kHighMemBeg, (void*)kHighMemEnd);
320 Printf("|| `[%p, %p]` || HighShadow ||\n",
321 (void*)kHighShadowBeg, (void*)kHighShadowEnd);
322 if (kMidMemBeg) {
323 Printf("|| `[%p, %p]` || ShadowGap3 ||\n",
324 (void*)kShadowGap3Beg, (void*)kShadowGap3End);
325 Printf("|| `[%p, %p]` || MidMem ||\n",
326 (void*)kMidMemBeg, (void*)kMidMemEnd);
327 Printf("|| `[%p, %p]` || ShadowGap2 ||\n",
328 (void*)kShadowGap2Beg, (void*)kShadowGap2End);
329 Printf("|| `[%p, %p]` || MidShadow ||\n",
330 (void*)kMidShadowBeg, (void*)kMidShadowEnd);
332 Printf("|| `[%p, %p]` || ShadowGap ||\n",
333 (void*)kShadowGapBeg, (void*)kShadowGapEnd);
334 if (kLowShadowBeg) {
335 Printf("|| `[%p, %p]` || LowShadow ||\n",
336 (void*)kLowShadowBeg, (void*)kLowShadowEnd);
337 Printf("|| `[%p, %p]` || LowMem ||\n",
338 (void*)kLowMemBeg, (void*)kLowMemEnd);
340 Printf("MemToShadow(shadow): %p %p %p %p",
341 (void*)MEM_TO_SHADOW(kLowShadowBeg),
342 (void*)MEM_TO_SHADOW(kLowShadowEnd),
343 (void*)MEM_TO_SHADOW(kHighShadowBeg),
344 (void*)MEM_TO_SHADOW(kHighShadowEnd));
345 if (kMidMemBeg) {
346 Printf(" %p %p",
347 (void*)MEM_TO_SHADOW(kMidShadowBeg),
348 (void*)MEM_TO_SHADOW(kMidShadowEnd));
350 Printf("\n");
351 Printf("redzone=%zu\n", (uptr)flags()->redzone);
352 Printf("max_redzone=%zu\n", (uptr)flags()->max_redzone);
353 Printf("quarantine_size_mb=%zuM\n", (uptr)flags()->quarantine_size_mb);
354 Printf("malloc_context_size=%zu\n",
355 (uptr)common_flags()->malloc_context_size);
357 Printf("SHADOW_SCALE: %d\n", (int)SHADOW_SCALE);
358 Printf("SHADOW_GRANULARITY: %d\n", (int)SHADOW_GRANULARITY);
359 Printf("SHADOW_OFFSET: 0x%zx\n", (uptr)SHADOW_OFFSET);
360 CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7);
361 if (kMidMemBeg)
362 CHECK(kMidShadowBeg > kLowShadowEnd &&
363 kMidMemBeg > kMidShadowEnd &&
364 kHighShadowBeg > kMidMemEnd);
367 static void AsanInitInternal() {
368 if (LIKELY(asan_inited)) return;
369 SanitizerToolName = "AddressSanitizer";
370 CHECK(!asan_init_is_running && "ASan init calls itself!");
371 asan_init_is_running = true;
373 CacheBinaryName();
375 // Initialize flags. This must be done early, because most of the
376 // initialization steps look at flags().
377 InitializeFlags();
379 CheckVMASize();
381 AsanCheckIncompatibleRT();
382 AsanCheckDynamicRTPrereqs();
384 SetCanPoisonMemory(flags()->poison_heap);
385 SetMallocContextSize(common_flags()->malloc_context_size);
387 InitializeHighMemEnd();
389 // Make sure we are not statically linked.
390 AsanDoesNotSupportStaticLinkage();
392 // Install tool-specific callbacks in sanitizer_common.
393 AddDieCallback(AsanDie);
394 SetCheckFailedCallback(AsanCheckFailed);
395 SetPrintfAndReportCallback(AppendToErrorMessageBuffer);
397 __sanitizer_set_report_path(common_flags()->log_path);
399 // Enable UAR detection, if required.
400 __asan_option_detect_stack_use_after_return =
401 flags()->detect_stack_use_after_return;
403 // Re-exec ourselves if we need to set additional env or command line args.
404 MaybeReexec();
406 // Setup internal allocator callback.
407 SetLowLevelAllocateCallback(OnLowLevelAllocate);
409 InitializeAsanInterceptors();
411 // Enable system log ("adb logcat") on Android.
412 // Doing this before interceptors are initialized crashes in:
413 // AsanInitInternal -> android_log_write -> __interceptor_strcmp
414 AndroidLogInit();
416 ReplaceSystemMalloc();
418 uptr shadow_start = kLowShadowBeg;
419 if (kLowShadowBeg)
420 shadow_start -= GetMmapGranularity();
421 bool full_shadow_is_available =
422 MemoryRangeIsAvailable(shadow_start, kHighShadowEnd);
424 #if SANITIZER_LINUX && defined(__x86_64__) && defined(_LP64) && \
425 !ASAN_FIXED_MAPPING
426 if (!full_shadow_is_available) {
427 kMidMemBeg = kLowMemEnd < 0x3000000000ULL ? 0x3000000000ULL : 0;
428 kMidMemEnd = kLowMemEnd < 0x3000000000ULL ? 0x4fffffffffULL : 0;
430 #endif
432 if (Verbosity()) PrintAddressSpaceLayout();
434 DisableCoreDumperIfNecessary();
436 if (full_shadow_is_available) {
437 // mmap the low shadow plus at least one page at the left.
438 if (kLowShadowBeg)
439 ReserveShadowMemoryRange(shadow_start, kLowShadowEnd, "low shadow");
440 // mmap the high shadow.
441 ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd, "high shadow");
442 // protect the gap.
443 ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
444 CHECK_EQ(kShadowGapEnd, kHighShadowBeg - 1);
445 } else if (kMidMemBeg &&
446 MemoryRangeIsAvailable(shadow_start, kMidMemBeg - 1) &&
447 MemoryRangeIsAvailable(kMidMemEnd + 1, kHighShadowEnd)) {
448 CHECK(kLowShadowBeg != kLowShadowEnd);
449 // mmap the low shadow plus at least one page at the left.
450 ReserveShadowMemoryRange(shadow_start, kLowShadowEnd, "low shadow");
451 // mmap the mid shadow.
452 ReserveShadowMemoryRange(kMidShadowBeg, kMidShadowEnd, "mid shadow");
453 // mmap the high shadow.
454 ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd, "high shadow");
455 // protect the gaps.
456 ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1);
457 ProtectGap(kShadowGap2Beg, kShadowGap2End - kShadowGap2Beg + 1);
458 ProtectGap(kShadowGap3Beg, kShadowGap3End - kShadowGap3Beg + 1);
459 } else {
460 Report("Shadow memory range interleaves with an existing memory mapping. "
461 "ASan cannot proceed correctly. ABORTING.\n");
462 Report("ASan shadow was supposed to be located in the [%p-%p] range.\n",
463 shadow_start, kHighShadowEnd);
464 DumpProcessMap();
465 Die();
468 AsanTSDInit(PlatformTSDDtor);
469 InstallDeadlySignalHandlers(AsanOnDeadlySignal);
471 AllocatorOptions allocator_options;
472 allocator_options.SetFrom(flags(), common_flags());
473 InitializeAllocator(allocator_options);
475 MaybeStartBackgroudThread();
476 SetSoftRssLimitExceededCallback(AsanSoftRssLimitExceededCallback);
478 // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
479 // should be set to 1 prior to initializing the threads.
480 asan_inited = 1;
481 asan_init_is_running = false;
483 if (flags()->atexit)
484 Atexit(asan_atexit);
486 InitializeCoverage(common_flags()->coverage, common_flags()->coverage_dir);
488 // Now that ASan runtime is (mostly) initialized, deactivate it if
489 // necessary, so that it can be re-activated when requested.
490 if (flags()->start_deactivated)
491 AsanDeactivate();
493 // interceptors
494 InitTlsSize();
496 // Create main thread.
497 AsanThread *main_thread = AsanThread::Create(
498 /* start_routine */ nullptr, /* arg */ nullptr, /* parent_tid */ 0,
499 /* stack */ nullptr, /* detached */ true);
500 CHECK_EQ(0, main_thread->tid());
501 SetCurrentThread(main_thread);
502 main_thread->ThreadStart(internal_getpid(),
503 /* signal_thread_is_registered */ nullptr);
504 force_interface_symbols(); // no-op.
505 SanitizerInitializeUnwinder();
507 #if CAN_SANITIZE_LEAKS
508 __lsan::InitCommonLsan();
509 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) {
510 Atexit(__lsan::DoLeakCheck);
512 #endif // CAN_SANITIZE_LEAKS
514 #if CAN_SANITIZE_UB
515 __ubsan::InitAsPlugin();
516 #endif
518 InitializeSuppressions();
520 VReport(1, "AddressSanitizer Init done\n");
523 // Initialize as requested from some part of ASan runtime library (interceptors,
524 // allocator, etc).
525 void AsanInitFromRtl() {
526 AsanInitInternal();
529 #if ASAN_DYNAMIC
530 // Initialize runtime in case it's LD_PRELOAD-ed into unsanitized executable
531 // (and thus normal initializers from .preinit_array or modules haven't run).
533 class AsanInitializer {
534 public: // NOLINT
535 AsanInitializer() {
536 AsanInitFromRtl();
540 static AsanInitializer asan_initializer;
541 #endif // ASAN_DYNAMIC
543 } // namespace __asan
545 // ---------------------- Interface ---------------- {{{1
546 using namespace __asan; // NOLINT
548 void NOINLINE __asan_handle_no_return() {
549 int local_stack;
550 AsanThread *curr_thread = GetCurrentThread();
551 uptr PageSize = GetPageSizeCached();
552 uptr top, bottom;
553 if (curr_thread) {
554 top = curr_thread->stack_top();
555 bottom = ((uptr)&local_stack - PageSize) & ~(PageSize - 1);
556 } else {
557 // If we haven't seen this thread, try asking the OS for stack bounds.
558 uptr tls_addr, tls_size, stack_size;
559 GetThreadStackAndTls(/*main=*/false, &bottom, &stack_size, &tls_addr,
560 &tls_size);
561 top = bottom + stack_size;
563 static const uptr kMaxExpectedCleanupSize = 64 << 20; // 64M
564 if (top - bottom > kMaxExpectedCleanupSize) {
565 static bool reported_warning = false;
566 if (reported_warning)
567 return;
568 reported_warning = true;
569 Report("WARNING: ASan is ignoring requested __asan_handle_no_return: "
570 "stack top: %p; bottom %p; size: %p (%zd)\n"
571 "False positive error reports may follow\n"
572 "For details see "
573 "http://code.google.com/p/address-sanitizer/issues/detail?id=189\n",
574 top, bottom, top - bottom, top - bottom);
575 return;
577 PoisonShadow(bottom, top - bottom, 0);
578 if (curr_thread && curr_thread->has_fake_stack())
579 curr_thread->fake_stack()->HandleNoReturn();
582 void NOINLINE __asan_set_death_callback(void (*callback)(void)) {
583 SetUserDieCallback(callback);
586 // Initialize as requested from instrumented application code.
587 // We use this call as a trigger to wake up ASan from deactivated state.
588 void __asan_init() {
589 AsanActivate();
590 AsanInitInternal();
593 void __asan_version_mismatch_check() {
594 // Do nothing.