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