asan_rtl.cc revision ae51c273d55fa172908cf940c238eacec0f73223
1//===-- asan_rtl.cc -------------------------------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This file is a part of AddressSanitizer, an address sanity checker. 11// 12// Main file of the ASan run-time library. 13//===----------------------------------------------------------------------===// 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_thread.h" 24#include "sanitizer_common/sanitizer_atomic.h" 25#include "sanitizer_common/sanitizer_flags.h" 26#include "sanitizer_common/sanitizer_libc.h" 27#include "sanitizer_common/sanitizer_symbolizer.h" 28#include "lsan/lsan_common.h" 29 30int __asan_option_detect_stack_use_after_return; // Global interface symbol. 31 32namespace __asan { 33 34uptr AsanMappingProfile[kAsanMappingProfileSize]; 35 36static void AsanDie() { 37 static atomic_uint32_t num_calls; 38 if (atomic_fetch_add(&num_calls, 1, memory_order_relaxed) != 0) { 39 // Don't die twice - run a busy loop. 40 while (1) { } 41 } 42 if (flags()->sleep_before_dying) { 43 Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying); 44 SleepForSeconds(flags()->sleep_before_dying); 45 } 46 if (flags()->unmap_shadow_on_exit) { 47 if (kMidMemBeg) { 48 UnmapOrDie((void*)kLowShadowBeg, kMidMemBeg - kLowShadowBeg); 49 UnmapOrDie((void*)kMidMemEnd, kHighShadowEnd - kMidMemEnd); 50 } else { 51 UnmapOrDie((void*)kLowShadowBeg, kHighShadowEnd - kLowShadowBeg); 52 } 53 } 54 if (death_callback) 55 death_callback(); 56 if (flags()->abort_on_error) 57 Abort(); 58 internal__exit(flags()->exitcode); 59} 60 61static void AsanCheckFailed(const char *file, int line, const char *cond, 62 u64 v1, u64 v2) { 63 Report("AddressSanitizer CHECK failed: %s:%d \"%s\" (0x%zx, 0x%zx)\n", 64 file, line, cond, (uptr)v1, (uptr)v2); 65 // FIXME: check for infinite recursion without a thread-local counter here. 66 PRINT_CURRENT_STACK(); 67 Die(); 68} 69 70// -------------------------- Flags ------------------------- {{{1 71static const int kDefaultMallocContextSize = 30; 72 73Flags asan_flags_dont_use_directly; // use via flags(). 74 75static const char *MaybeCallAsanDefaultOptions() { 76 return (&__asan_default_options) ? __asan_default_options() : ""; 77} 78 79static const char *MaybeUseAsanDefaultOptionsCompileDefiniton() { 80#ifdef ASAN_DEFAULT_OPTIONS 81// Stringize the macro value. 82# define ASAN_STRINGIZE(x) #x 83# define ASAN_STRINGIZE_OPTIONS(options) ASAN_STRINGIZE(options) 84 return ASAN_STRINGIZE_OPTIONS(ASAN_DEFAULT_OPTIONS); 85#else 86 return ""; 87#endif 88} 89 90static void ParseFlagsFromString(Flags *f, const char *str) { 91 ParseCommonFlagsFromString(str); 92 CHECK((uptr)common_flags()->malloc_context_size <= kStackTraceMax); 93 94 ParseFlag(str, &f->quarantine_size, "quarantine_size"); 95 ParseFlag(str, &f->redzone, "redzone"); 96 CHECK_GE(f->redzone, 16); 97 CHECK(IsPowerOfTwo(f->redzone)); 98 99 ParseFlag(str, &f->debug, "debug"); 100 ParseFlag(str, &f->report_globals, "report_globals"); 101 ParseFlag(str, &f->check_initialization_order, "check_initialization_order"); 102 103 ParseFlag(str, &f->replace_str, "replace_str"); 104 ParseFlag(str, &f->replace_intrin, "replace_intrin"); 105 ParseFlag(str, &f->mac_ignore_invalid_free, "mac_ignore_invalid_free"); 106 ParseFlag(str, &f->detect_stack_use_after_return, 107 "detect_stack_use_after_return"); 108 ParseFlag(str, &f->uar_stack_size_log, "uar_stack_size_log"); 109 ParseFlag(str, &f->max_malloc_fill_size, "max_malloc_fill_size"); 110 ParseFlag(str, &f->malloc_fill_byte, "malloc_fill_byte"); 111 ParseFlag(str, &f->exitcode, "exitcode"); 112 ParseFlag(str, &f->allow_user_poisoning, "allow_user_poisoning"); 113 ParseFlag(str, &f->sleep_before_dying, "sleep_before_dying"); 114 ParseFlag(str, &f->handle_segv, "handle_segv"); 115 ParseFlag(str, &f->allow_user_segv_handler, "allow_user_segv_handler"); 116 ParseFlag(str, &f->use_sigaltstack, "use_sigaltstack"); 117 ParseFlag(str, &f->check_malloc_usable_size, "check_malloc_usable_size"); 118 ParseFlag(str, &f->unmap_shadow_on_exit, "unmap_shadow_on_exit"); 119 ParseFlag(str, &f->abort_on_error, "abort_on_error"); 120 ParseFlag(str, &f->print_stats, "print_stats"); 121 ParseFlag(str, &f->print_legend, "print_legend"); 122 ParseFlag(str, &f->atexit, "atexit"); 123 ParseFlag(str, &f->disable_core, "disable_core"); 124 ParseFlag(str, &f->allow_reexec, "allow_reexec"); 125 ParseFlag(str, &f->print_full_thread_history, "print_full_thread_history"); 126 ParseFlag(str, &f->poison_heap, "poison_heap"); 127 ParseFlag(str, &f->poison_partial, "poison_partial"); 128 ParseFlag(str, &f->alloc_dealloc_mismatch, "alloc_dealloc_mismatch"); 129 ParseFlag(str, &f->strict_memcmp, "strict_memcmp"); 130 ParseFlag(str, &f->strict_init_order, "strict_init_order"); 131} 132 133void InitializeFlags(Flags *f, const char *env) { 134 CommonFlags *cf = common_flags(); 135 SetCommonFlagDefaults(); 136 cf->external_symbolizer_path = GetEnv("ASAN_SYMBOLIZER_PATH"); 137 cf->malloc_context_size = kDefaultMallocContextSize; 138 139 internal_memset(f, 0, sizeof(*f)); 140 f->quarantine_size = (ASAN_LOW_MEMORY) ? 1UL << 26 : 1UL << 28; 141 f->redzone = 16; 142 f->debug = false; 143 f->report_globals = 1; 144 f->check_initialization_order = false; 145 f->replace_str = true; 146 f->replace_intrin = true; 147 f->mac_ignore_invalid_free = false; 148 f->detect_stack_use_after_return = false; // Also needs the compiler flag. 149 f->uar_stack_size_log = 0; 150 f->max_malloc_fill_size = 0x1000; // By default, fill only the first 4K. 151 f->malloc_fill_byte = 0xbe; 152 f->exitcode = ASAN_DEFAULT_FAILURE_EXITCODE; 153 f->allow_user_poisoning = true; 154 f->sleep_before_dying = 0; 155 f->handle_segv = ASAN_NEEDS_SEGV; 156 f->allow_user_segv_handler = false; 157 f->use_sigaltstack = false; 158 f->check_malloc_usable_size = true; 159 f->unmap_shadow_on_exit = false; 160 f->abort_on_error = false; 161 f->print_stats = false; 162 f->print_legend = true; 163 f->atexit = false; 164 f->disable_core = (SANITIZER_WORDSIZE == 64); 165 f->allow_reexec = true; 166 f->print_full_thread_history = true; 167 f->poison_heap = true; 168 f->poison_partial = true; 169 // Turn off alloc/dealloc mismatch checker on Mac and Windows for now. 170 // TODO(glider,timurrrr): Fix known issues and enable this back. 171 f->alloc_dealloc_mismatch = (SANITIZER_MAC == 0) && (SANITIZER_WINDOWS == 0); 172 f->strict_memcmp = true; 173 f->strict_init_order = false; 174 175 // Override from compile definition. 176 ParseFlagsFromString(f, MaybeUseAsanDefaultOptionsCompileDefiniton()); 177 178 // Override from user-specified string. 179 ParseFlagsFromString(f, MaybeCallAsanDefaultOptions()); 180 if (common_flags()->verbosity) { 181 Report("Using the defaults from __asan_default_options: %s\n", 182 MaybeCallAsanDefaultOptions()); 183 } 184 185 // Override from command line. 186 ParseFlagsFromString(f, env); 187 188#if !CAN_SANITIZE_LEAKS 189 if (cf->detect_leaks) { 190 Report("%s: detect_leaks is not supported on this platform.\n", 191 SanitizerToolName); 192 cf->detect_leaks = false; 193 } 194#endif 195 196 // Make "strict_init_order" imply "check_initialization_order". 197 // TODO(samsonov): Use a single runtime flag for an init-order checker. 198 if (f->strict_init_order) { 199 f->check_initialization_order = true; 200 } 201} 202 203// -------------------------- Globals --------------------- {{{1 204int asan_inited; 205bool asan_init_is_running; 206void (*death_callback)(void); 207 208#if !ASAN_FIXED_MAPPING 209uptr kHighMemEnd, kMidMemBeg, kMidMemEnd; 210#endif 211 212// -------------------------- Misc ---------------- {{{1 213void ShowStatsAndAbort() { 214 __asan_print_accumulated_stats(); 215 Die(); 216} 217 218// ---------------------- mmap -------------------- {{{1 219// Reserve memory range [beg, end]. 220static void ReserveShadowMemoryRange(uptr beg, uptr end) { 221 CHECK_EQ((beg % GetPageSizeCached()), 0); 222 CHECK_EQ(((end + 1) % GetPageSizeCached()), 0); 223 uptr size = end - beg + 1; 224 void *res = MmapFixedNoReserve(beg, size); 225 if (res != (void*)beg) { 226 Report("ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. " 227 "Perhaps you're using ulimit -v\n", size); 228 Abort(); 229 } 230} 231 232// --------------- LowLevelAllocateCallbac ---------- {{{1 233static void OnLowLevelAllocate(uptr ptr, uptr size) { 234 PoisonShadow(ptr, size, kAsanInternalHeapMagic); 235} 236 237// -------------------------- Run-time entry ------------------- {{{1 238// exported functions 239#define ASAN_REPORT_ERROR(type, is_write, size) \ 240extern "C" NOINLINE INTERFACE_ATTRIBUTE \ 241void __asan_report_ ## type ## size(uptr addr); \ 242void __asan_report_ ## type ## size(uptr addr) { \ 243 GET_CALLER_PC_BP_SP; \ 244 __asan_report_error(pc, bp, sp, addr, is_write, size); \ 245} 246 247ASAN_REPORT_ERROR(load, false, 1) 248ASAN_REPORT_ERROR(load, false, 2) 249ASAN_REPORT_ERROR(load, false, 4) 250ASAN_REPORT_ERROR(load, false, 8) 251ASAN_REPORT_ERROR(load, false, 16) 252ASAN_REPORT_ERROR(store, true, 1) 253ASAN_REPORT_ERROR(store, true, 2) 254ASAN_REPORT_ERROR(store, true, 4) 255ASAN_REPORT_ERROR(store, true, 8) 256ASAN_REPORT_ERROR(store, true, 16) 257 258#define ASAN_REPORT_ERROR_N(type, is_write) \ 259extern "C" NOINLINE INTERFACE_ATTRIBUTE \ 260void __asan_report_ ## type ## _n(uptr addr, uptr size); \ 261void __asan_report_ ## type ## _n(uptr addr, uptr size) { \ 262 GET_CALLER_PC_BP_SP; \ 263 __asan_report_error(pc, bp, sp, addr, is_write, size); \ 264} 265 266ASAN_REPORT_ERROR_N(load, false) 267ASAN_REPORT_ERROR_N(store, true) 268 269// Force the linker to keep the symbols for various ASan interface functions. 270// We want to keep those in the executable in order to let the instrumented 271// dynamic libraries access the symbol even if it is not used by the executable 272// itself. This should help if the build system is removing dead code at link 273// time. 274static NOINLINE void force_interface_symbols() { 275 volatile int fake_condition = 0; // prevent dead condition elimination. 276 // __asan_report_* functions are noreturn, so we need a switch to prevent 277 // the compiler from removing any of them. 278 switch (fake_condition) { 279 case 1: __asan_report_load1(0); break; 280 case 2: __asan_report_load2(0); break; 281 case 3: __asan_report_load4(0); break; 282 case 4: __asan_report_load8(0); break; 283 case 5: __asan_report_load16(0); break; 284 case 6: __asan_report_store1(0); break; 285 case 7: __asan_report_store2(0); break; 286 case 8: __asan_report_store4(0); break; 287 case 9: __asan_report_store8(0); break; 288 case 10: __asan_report_store16(0); break; 289 case 12: __asan_register_globals(0, 0); break; 290 case 13: __asan_unregister_globals(0, 0); break; 291 case 14: __asan_set_death_callback(0); break; 292 case 15: __asan_set_error_report_callback(0); break; 293 case 16: __asan_handle_no_return(); break; 294 case 17: __asan_address_is_poisoned(0); break; 295 case 18: __asan_get_allocated_size(0); break; 296 case 19: __asan_get_current_allocated_bytes(); break; 297 case 20: __asan_get_estimated_allocated_size(0); break; 298 case 21: __asan_get_free_bytes(); break; 299 case 22: __asan_get_heap_size(); break; 300 case 23: __asan_get_ownership(0); break; 301 case 24: __asan_get_unmapped_bytes(); break; 302 case 25: __asan_poison_memory_region(0, 0); break; 303 case 26: __asan_unpoison_memory_region(0, 0); break; 304 case 27: __asan_set_error_exit_code(0); break; 305 case 30: __asan_before_dynamic_init(0); break; 306 case 31: __asan_after_dynamic_init(); break; 307 case 32: __asan_poison_stack_memory(0, 0); break; 308 case 33: __asan_unpoison_stack_memory(0, 0); break; 309 case 34: __asan_region_is_poisoned(0, 0); break; 310 case 35: __asan_describe_address(0); break; 311 } 312} 313 314static void asan_atexit() { 315 Printf("AddressSanitizer exit stats:\n"); 316 __asan_print_accumulated_stats(); 317 // Print AsanMappingProfile. 318 for (uptr i = 0; i < kAsanMappingProfileSize; i++) { 319 if (AsanMappingProfile[i] == 0) continue; 320 Printf("asan_mapping.h:%zd -- %zd\n", i, AsanMappingProfile[i]); 321 } 322} 323 324static void InitializeHighMemEnd() { 325#if !ASAN_FIXED_MAPPING 326 kHighMemEnd = GetMaxVirtualAddress(); 327 // Increase kHighMemEnd to make sure it's properly 328 // aligned together with kHighMemBeg: 329 kHighMemEnd |= SHADOW_GRANULARITY * GetPageSizeCached() - 1; 330#endif // !ASAN_FIXED_MAPPING 331 CHECK_EQ((kHighMemBeg % GetPageSizeCached()), 0); 332} 333 334static void ProtectGap(uptr a, uptr size) { 335 CHECK_EQ(a, (uptr)Mprotect(a, size)); 336} 337 338static void PrintAddressSpaceLayout() { 339 Printf("|| `[%p, %p]` || HighMem ||\n", 340 (void*)kHighMemBeg, (void*)kHighMemEnd); 341 Printf("|| `[%p, %p]` || HighShadow ||\n", 342 (void*)kHighShadowBeg, (void*)kHighShadowEnd); 343 if (kMidMemBeg) { 344 Printf("|| `[%p, %p]` || ShadowGap3 ||\n", 345 (void*)kShadowGap3Beg, (void*)kShadowGap3End); 346 Printf("|| `[%p, %p]` || MidMem ||\n", 347 (void*)kMidMemBeg, (void*)kMidMemEnd); 348 Printf("|| `[%p, %p]` || ShadowGap2 ||\n", 349 (void*)kShadowGap2Beg, (void*)kShadowGap2End); 350 Printf("|| `[%p, %p]` || MidShadow ||\n", 351 (void*)kMidShadowBeg, (void*)kMidShadowEnd); 352 } 353 Printf("|| `[%p, %p]` || ShadowGap ||\n", 354 (void*)kShadowGapBeg, (void*)kShadowGapEnd); 355 if (kLowShadowBeg) { 356 Printf("|| `[%p, %p]` || LowShadow ||\n", 357 (void*)kLowShadowBeg, (void*)kLowShadowEnd); 358 Printf("|| `[%p, %p]` || LowMem ||\n", 359 (void*)kLowMemBeg, (void*)kLowMemEnd); 360 } 361 Printf("MemToShadow(shadow): %p %p %p %p", 362 (void*)MEM_TO_SHADOW(kLowShadowBeg), 363 (void*)MEM_TO_SHADOW(kLowShadowEnd), 364 (void*)MEM_TO_SHADOW(kHighShadowBeg), 365 (void*)MEM_TO_SHADOW(kHighShadowEnd)); 366 if (kMidMemBeg) { 367 Printf(" %p %p", 368 (void*)MEM_TO_SHADOW(kMidShadowBeg), 369 (void*)MEM_TO_SHADOW(kMidShadowEnd)); 370 } 371 Printf("\n"); 372 Printf("red_zone=%zu\n", (uptr)flags()->redzone); 373 Printf("quarantine_size=%zuM\n", (uptr)flags()->quarantine_size >> 20); 374 Printf("malloc_context_size=%zu\n", 375 (uptr)common_flags()->malloc_context_size); 376 377 Printf("SHADOW_SCALE: %zx\n", (uptr)SHADOW_SCALE); 378 Printf("SHADOW_GRANULARITY: %zx\n", (uptr)SHADOW_GRANULARITY); 379 Printf("SHADOW_OFFSET: %zx\n", (uptr)SHADOW_OFFSET); 380 CHECK(SHADOW_SCALE >= 3 && SHADOW_SCALE <= 7); 381 if (kMidMemBeg) 382 CHECK(kMidShadowBeg > kLowShadowEnd && 383 kMidMemBeg > kMidShadowEnd && 384 kHighShadowBeg > kMidMemEnd); 385} 386 387} // namespace __asan 388 389// ---------------------- Interface ---------------- {{{1 390using namespace __asan; // NOLINT 391 392#if !SANITIZER_SUPPORTS_WEAK_HOOKS 393extern "C" { 394SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE 395const char* __asan_default_options() { return ""; } 396} // extern "C" 397#endif 398 399int NOINLINE __asan_set_error_exit_code(int exit_code) { 400 int old = flags()->exitcode; 401 flags()->exitcode = exit_code; 402 return old; 403} 404 405void NOINLINE __asan_handle_no_return() { 406 int local_stack; 407 AsanThread *curr_thread = GetCurrentThread(); 408 CHECK(curr_thread); 409 uptr PageSize = GetPageSizeCached(); 410 uptr top = curr_thread->stack_top(); 411 uptr bottom = ((uptr)&local_stack - PageSize) & ~(PageSize-1); 412 static const uptr kMaxExpectedCleanupSize = 64 << 20; // 64M 413 if (top - bottom > kMaxExpectedCleanupSize) { 414 static bool reported_warning = false; 415 if (reported_warning) 416 return; 417 reported_warning = true; 418 Report("WARNING: ASan is ignoring requested __asan_handle_no_return: " 419 "stack top: %p; bottom %p; size: %p (%zd)\n" 420 "False positive error reports may follow\n" 421 "For details see " 422 "http://code.google.com/p/address-sanitizer/issues/detail?id=189\n", 423 top, bottom, top - bottom, top - bottom); 424 return; 425 } 426 PoisonShadow(bottom, top - bottom, 0); 427 if (curr_thread->has_fake_stack()) 428 curr_thread->fake_stack()->HandleNoReturn(); 429} 430 431void NOINLINE __asan_set_death_callback(void (*callback)(void)) { 432 death_callback = callback; 433} 434 435void __asan_init() { 436 if (asan_inited) return; 437 SanitizerToolName = "AddressSanitizer"; 438 CHECK(!asan_init_is_running && "ASan init calls itself!"); 439 asan_init_is_running = true; 440 InitializeHighMemEnd(); 441 442 // Make sure we are not statically linked. 443 AsanDoesNotSupportStaticLinkage(); 444 445 // Install tool-specific callbacks in sanitizer_common. 446 SetDieCallback(AsanDie); 447 SetCheckFailedCallback(AsanCheckFailed); 448 SetPrintfAndReportCallback(AppendToErrorMessageBuffer); 449 450 // Initialize flags. This must be done early, because most of the 451 // initialization steps look at flags(). 452 const char *options = GetEnv("ASAN_OPTIONS"); 453 InitializeFlags(flags(), options); 454 __sanitizer_set_report_path(common_flags()->log_path); 455 __asan_option_detect_stack_use_after_return = 456 flags()->detect_stack_use_after_return; 457 458 if (common_flags()->verbosity && options) { 459 Report("Parsed ASAN_OPTIONS: %s\n", options); 460 } 461 462 // Re-exec ourselves if we need to set additional env or command line args. 463 MaybeReexec(); 464 465 // Setup internal allocator callback. 466 SetLowLevelAllocateCallback(OnLowLevelAllocate); 467 468 InitializeAsanInterceptors(); 469 470 ReplaceSystemMalloc(); 471 ReplaceOperatorsNewAndDelete(); 472 473 uptr shadow_start = kLowShadowBeg; 474 if (kLowShadowBeg) 475 shadow_start -= GetMmapGranularity(); 476 bool full_shadow_is_available = 477 MemoryRangeIsAvailable(shadow_start, kHighShadowEnd); 478 479#if SANITIZER_LINUX && defined(__x86_64__) && !ASAN_FIXED_MAPPING 480 if (!full_shadow_is_available) { 481 kMidMemBeg = kLowMemEnd < 0x3000000000ULL ? 0x3000000000ULL : 0; 482 kMidMemEnd = kLowMemEnd < 0x3000000000ULL ? 0x4fffffffffULL : 0; 483 } 484#endif 485 486 if (common_flags()->verbosity) 487 PrintAddressSpaceLayout(); 488 489 if (flags()->disable_core) { 490 DisableCoreDumper(); 491 } 492 493 if (full_shadow_is_available) { 494 // mmap the low shadow plus at least one page at the left. 495 if (kLowShadowBeg) 496 ReserveShadowMemoryRange(shadow_start, kLowShadowEnd); 497 // mmap the high shadow. 498 ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd); 499 // protect the gap. 500 ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1); 501 } else if (kMidMemBeg && 502 MemoryRangeIsAvailable(shadow_start, kMidMemBeg - 1) && 503 MemoryRangeIsAvailable(kMidMemEnd + 1, kHighShadowEnd)) { 504 CHECK(kLowShadowBeg != kLowShadowEnd); 505 // mmap the low shadow plus at least one page at the left. 506 ReserveShadowMemoryRange(shadow_start, kLowShadowEnd); 507 // mmap the mid shadow. 508 ReserveShadowMemoryRange(kMidShadowBeg, kMidShadowEnd); 509 // mmap the high shadow. 510 ReserveShadowMemoryRange(kHighShadowBeg, kHighShadowEnd); 511 // protect the gaps. 512 ProtectGap(kShadowGapBeg, kShadowGapEnd - kShadowGapBeg + 1); 513 ProtectGap(kShadowGap2Beg, kShadowGap2End - kShadowGap2Beg + 1); 514 ProtectGap(kShadowGap3Beg, kShadowGap3End - kShadowGap3Beg + 1); 515 } else { 516 Report("Shadow memory range interleaves with an existing memory mapping. " 517 "ASan cannot proceed correctly. ABORTING.\n"); 518 DumpProcessMap(); 519 Die(); 520 } 521 522 AsanTSDInit(PlatformTSDDtor); 523 InstallSignalHandlers(); 524 525 // Allocator should be initialized before starting external symbolizer, as 526 // fork() on Mac locks the allocator. 527 InitializeAllocator(); 528 529 // Start symbolizer process if necessary. 530 if (common_flags()->symbolize) { 531 Symbolizer::Init(common_flags()->external_symbolizer_path); 532 } else { 533 Symbolizer::Disable(); 534 } 535 536 // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited 537 // should be set to 1 prior to initializing the threads. 538 asan_inited = 1; 539 asan_init_is_running = false; 540 541 if (flags()->atexit) 542 Atexit(asan_atexit); 543 544 // interceptors 545 InitTlsSize(); 546 547 // Create main thread. 548 AsanThread *main_thread = AsanThread::Create(0, 0); 549 CreateThreadContextArgs create_main_args = { main_thread, 0 }; 550 u32 main_tid = asanThreadRegistry().CreateThread( 551 0, true, 0, &create_main_args); 552 CHECK_EQ(0, main_tid); 553 SetCurrentThread(main_thread); 554 main_thread->ThreadStart(internal_getpid()); 555 force_interface_symbols(); // no-op. 556 557#if CAN_SANITIZE_LEAKS 558 __lsan::InitCommonLsan(); 559 if (common_flags()->detect_leaks && common_flags()->leak_check_at_exit) { 560 Atexit(__lsan::DoLeakCheck); 561 } 562#endif // CAN_SANITIZE_LEAKS 563 564 if (common_flags()->verbosity) { 565 Report("AddressSanitizer Init done\n"); 566 } 567} 568