1 //===-- asan_rtl.cc -------------------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file is a part of AddressSanitizer, an address sanity checker.
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"
30 int __asan_option_detect_stack_use_after_return
; // Global interface symbol.
34 uptr AsanMappingProfile
[kAsanMappingProfileSize
];
36 static 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.
42 if (flags()->sleep_before_dying
) {
43 Report("Sleeping for %d second(s)\n", flags()->sleep_before_dying
);
44 SleepForSeconds(flags()->sleep_before_dying
);
46 if (flags()->unmap_shadow_on_exit
) {
48 UnmapOrDie((void*)kLowShadowBeg
, kMidMemBeg
- kLowShadowBeg
);
49 UnmapOrDie((void*)kMidMemEnd
, kHighShadowEnd
- kMidMemEnd
);
51 UnmapOrDie((void*)kLowShadowBeg
, kHighShadowEnd
- kLowShadowBeg
);
56 if (flags()->abort_on_error
)
58 internal__exit(flags()->exitcode
);
61 static void AsanCheckFailed(const char *file
, int line
, const char *cond
,
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();
70 // -------------------------- Flags ------------------------- {{{1
71 static const int kDefaultMallocContextSize
= 30;
73 Flags asan_flags_dont_use_directly
; // use via flags().
75 static const char *MaybeCallAsanDefaultOptions() {
76 return (&__asan_default_options
) ? __asan_default_options() : "";
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
);
90 static void ParseFlagsFromString(Flags
*f
, const char *str
) {
91 ParseCommonFlagsFromString(str
);
92 CHECK((uptr
)common_flags()->malloc_context_size
<= kStackTraceMax
);
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
));
99 ParseFlag(str
, &f
->debug
, "debug");
100 ParseFlag(str
, &f
->report_globals
, "report_globals");
101 ParseFlag(str
, &f
->check_initialization_order
, "check_initialization_order");
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
->alloc_dealloc_mismatch
, "alloc_dealloc_mismatch");
128 ParseFlag(str
, &f
->use_stack_depot
, "use_stack_depot");
129 ParseFlag(str
, &f
->strict_memcmp
, "strict_memcmp");
130 ParseFlag(str
, &f
->strict_init_order
, "strict_init_order");
133 void InitializeFlags(Flags
*f
, const char *env
) {
134 CommonFlags
*cf
= common_flags();
135 cf
->external_symbolizer_path
= GetEnv("ASAN_SYMBOLIZER_PATH");
136 cf
->symbolize
= true;
137 cf
->malloc_context_size
= kDefaultMallocContextSize
;
138 cf
->fast_unwind_on_fatal
= false;
139 cf
->fast_unwind_on_malloc
= true;
140 cf
->strip_path_prefix
= "";
141 cf
->handle_ioctl
= false;
143 cf
->detect_leaks
= false;
144 cf
->leak_check_at_exit
= true;
146 internal_memset(f
, 0, sizeof(*f
));
147 f
->quarantine_size
= (ASAN_LOW_MEMORY
) ? 1UL << 26 : 1UL << 28;
150 f
->report_globals
= 1;
151 f
->check_initialization_order
= false;
152 f
->replace_str
= true;
153 f
->replace_intrin
= true;
154 f
->mac_ignore_invalid_free
= false;
155 f
->detect_stack_use_after_return
= false; // Also needs the compiler flag.
156 f
->uar_stack_size_log
= 0;
157 f
->max_malloc_fill_size
= 0x1000; // By default, fill only the first 4K.
158 f
->malloc_fill_byte
= 0xbe;
159 f
->exitcode
= ASAN_DEFAULT_FAILURE_EXITCODE
;
160 f
->allow_user_poisoning
= true;
161 f
->sleep_before_dying
= 0;
162 f
->handle_segv
= ASAN_NEEDS_SEGV
;
163 f
->allow_user_segv_handler
= false;
164 f
->use_sigaltstack
= false;
165 f
->check_malloc_usable_size
= true;
166 f
->unmap_shadow_on_exit
= false;
167 f
->abort_on_error
= false;
168 f
->print_stats
= false;
169 f
->print_legend
= true;
171 f
->disable_core
= (SANITIZER_WORDSIZE
== 64);
172 f
->allow_reexec
= true;
173 f
->print_full_thread_history
= true;
174 f
->poison_heap
= true;
175 // Turn off alloc/dealloc mismatch checker on Mac and Windows for now.
176 // TODO(glider,timurrrr): Fix known issues and enable this back.
177 f
->alloc_dealloc_mismatch
= (SANITIZER_MAC
== 0) && (SANITIZER_WINDOWS
== 0);
178 f
->use_stack_depot
= true;
179 f
->strict_memcmp
= true;
180 f
->strict_init_order
= false;
182 // Override from compile definition.
183 ParseFlagsFromString(f
, MaybeUseAsanDefaultOptionsCompileDefiniton());
185 // Override from user-specified string.
186 ParseFlagsFromString(f
, MaybeCallAsanDefaultOptions());
187 if (common_flags()->verbosity
) {
188 Report("Using the defaults from __asan_default_options: %s\n",
189 MaybeCallAsanDefaultOptions());
192 // Override from command line.
193 ParseFlagsFromString(f
, env
);
195 #if !CAN_SANITIZE_LEAKS
196 if (cf
->detect_leaks
) {
197 Report("%s: detect_leaks is not supported on this platform.\n",
199 cf
->detect_leaks
= false;
203 if (cf
->detect_leaks
&& !f
->use_stack_depot
) {
204 Report("%s: detect_leaks is ignored (requires use_stack_depot).\n",
206 cf
->detect_leaks
= false;
210 // -------------------------- Globals --------------------- {{{1
212 bool asan_init_is_running
;
213 void (*death_callback
)(void);
215 #if !ASAN_FIXED_MAPPING
216 uptr kHighMemEnd
, kMidMemBeg
, kMidMemEnd
;
219 // -------------------------- Misc ---------------- {{{1
220 void ShowStatsAndAbort() {
221 __asan_print_accumulated_stats();
225 // ---------------------- mmap -------------------- {{{1
226 // Reserve memory range [beg, end].
227 static void ReserveShadowMemoryRange(uptr beg
, uptr end
) {
228 CHECK_EQ((beg
% GetPageSizeCached()), 0);
229 CHECK_EQ(((end
+ 1) % GetPageSizeCached()), 0);
230 uptr size
= end
- beg
+ 1;
231 void *res
= MmapFixedNoReserve(beg
, size
);
232 if (res
!= (void*)beg
) {
233 Report("ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. "
234 "Perhaps you're using ulimit -v\n", size
);
239 // --------------- LowLevelAllocateCallbac ---------- {{{1
240 static void OnLowLevelAllocate(uptr ptr
, uptr size
) {
241 PoisonShadow(ptr
, size
, kAsanInternalHeapMagic
);
244 // -------------------------- Run-time entry ------------------- {{{1
245 // exported functions
246 #define ASAN_REPORT_ERROR(type, is_write, size) \
247 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
248 void __asan_report_ ## type ## size(uptr addr); \
249 void __asan_report_ ## type ## size(uptr addr) { \
250 GET_CALLER_PC_BP_SP; \
251 __asan_report_error(pc, bp, sp, addr, is_write, size); \
254 ASAN_REPORT_ERROR(load
, false, 1)
255 ASAN_REPORT_ERROR(load
, false, 2)
256 ASAN_REPORT_ERROR(load
, false, 4)
257 ASAN_REPORT_ERROR(load
, false, 8)
258 ASAN_REPORT_ERROR(load
, false, 16)
259 ASAN_REPORT_ERROR(store
, true, 1)
260 ASAN_REPORT_ERROR(store
, true, 2)
261 ASAN_REPORT_ERROR(store
, true, 4)
262 ASAN_REPORT_ERROR(store
, true, 8)
263 ASAN_REPORT_ERROR(store
, true, 16)
265 #define ASAN_REPORT_ERROR_N(type, is_write) \
266 extern "C" NOINLINE INTERFACE_ATTRIBUTE \
267 void __asan_report_ ## type ## _n(uptr addr, uptr size); \
268 void __asan_report_ ## type ## _n(uptr addr, uptr size) { \
269 GET_CALLER_PC_BP_SP; \
270 __asan_report_error(pc, bp, sp, addr, is_write, size); \
273 ASAN_REPORT_ERROR_N(load
, false)
274 ASAN_REPORT_ERROR_N(store
, true)
276 // Force the linker to keep the symbols for various ASan interface functions.
277 // We want to keep those in the executable in order to let the instrumented
278 // dynamic libraries access the symbol even if it is not used by the executable
279 // itself. This should help if the build system is removing dead code at link
281 static NOINLINE
void force_interface_symbols() {
282 volatile int fake_condition
= 0; // prevent dead condition elimination.
283 // __asan_report_* functions are noreturn, so we need a switch to prevent
284 // the compiler from removing any of them.
285 switch (fake_condition
) {
286 case 1: __asan_report_load1(0); break;
287 case 2: __asan_report_load2(0); break;
288 case 3: __asan_report_load4(0); break;
289 case 4: __asan_report_load8(0); break;
290 case 5: __asan_report_load16(0); break;
291 case 6: __asan_report_store1(0); break;
292 case 7: __asan_report_store2(0); break;
293 case 8: __asan_report_store4(0); break;
294 case 9: __asan_report_store8(0); break;
295 case 10: __asan_report_store16(0); break;
296 case 12: __asan_register_globals(0, 0); break;
297 case 13: __asan_unregister_globals(0, 0); break;
298 case 14: __asan_set_death_callback(0); break;
299 case 15: __asan_set_error_report_callback(0); break;
300 case 16: __asan_handle_no_return(); break;
301 case 17: __asan_address_is_poisoned(0); break;
302 case 18: __asan_get_allocated_size(0); break;
303 case 19: __asan_get_current_allocated_bytes(); break;
304 case 20: __asan_get_estimated_allocated_size(0); break;
305 case 21: __asan_get_free_bytes(); break;
306 case 22: __asan_get_heap_size(); break;
307 case 23: __asan_get_ownership(0); break;
308 case 24: __asan_get_unmapped_bytes(); break;
309 case 25: __asan_poison_memory_region(0, 0); break;
310 case 26: __asan_unpoison_memory_region(0, 0); break;
311 case 27: __asan_set_error_exit_code(0); break;
312 case 30: __asan_before_dynamic_init(0); break;
313 case 31: __asan_after_dynamic_init(); break;
314 case 32: __asan_poison_stack_memory(0, 0); break;
315 case 33: __asan_unpoison_stack_memory(0, 0); break;
316 case 34: __asan_region_is_poisoned(0, 0); break;
317 case 35: __asan_describe_address(0); break;
321 static void asan_atexit() {
322 Printf("AddressSanitizer exit stats:\n");
323 __asan_print_accumulated_stats();
324 // Print AsanMappingProfile.
325 for (uptr i
= 0; i
< kAsanMappingProfileSize
; i
++) {
326 if (AsanMappingProfile
[i
] == 0) continue;
327 Printf("asan_mapping.h:%zd -- %zd\n", i
, AsanMappingProfile
[i
]);
331 static void InitializeHighMemEnd() {
332 #if !ASAN_FIXED_MAPPING
333 kHighMemEnd
= GetMaxVirtualAddress();
334 // Increase kHighMemEnd to make sure it's properly
335 // aligned together with kHighMemBeg:
336 kHighMemEnd
|= SHADOW_GRANULARITY
* GetPageSizeCached() - 1;
337 #endif // !ASAN_FIXED_MAPPING
338 CHECK_EQ((kHighMemBeg
% GetPageSizeCached()), 0);
341 static void ProtectGap(uptr a
, uptr size
) {
342 CHECK_EQ(a
, (uptr
)Mprotect(a
, size
));
345 static void PrintAddressSpaceLayout() {
346 Printf("|| `[%p, %p]` || HighMem ||\n",
347 (void*)kHighMemBeg
, (void*)kHighMemEnd
);
348 Printf("|| `[%p, %p]` || HighShadow ||\n",
349 (void*)kHighShadowBeg
, (void*)kHighShadowEnd
);
351 Printf("|| `[%p, %p]` || ShadowGap3 ||\n",
352 (void*)kShadowGap3Beg
, (void*)kShadowGap3End
);
353 Printf("|| `[%p, %p]` || MidMem ||\n",
354 (void*)kMidMemBeg
, (void*)kMidMemEnd
);
355 Printf("|| `[%p, %p]` || ShadowGap2 ||\n",
356 (void*)kShadowGap2Beg
, (void*)kShadowGap2End
);
357 Printf("|| `[%p, %p]` || MidShadow ||\n",
358 (void*)kMidShadowBeg
, (void*)kMidShadowEnd
);
360 Printf("|| `[%p, %p]` || ShadowGap ||\n",
361 (void*)kShadowGapBeg
, (void*)kShadowGapEnd
);
363 Printf("|| `[%p, %p]` || LowShadow ||\n",
364 (void*)kLowShadowBeg
, (void*)kLowShadowEnd
);
365 Printf("|| `[%p, %p]` || LowMem ||\n",
366 (void*)kLowMemBeg
, (void*)kLowMemEnd
);
368 Printf("MemToShadow(shadow): %p %p %p %p",
369 (void*)MEM_TO_SHADOW(kLowShadowBeg
),
370 (void*)MEM_TO_SHADOW(kLowShadowEnd
),
371 (void*)MEM_TO_SHADOW(kHighShadowBeg
),
372 (void*)MEM_TO_SHADOW(kHighShadowEnd
));
375 (void*)MEM_TO_SHADOW(kMidShadowBeg
),
376 (void*)MEM_TO_SHADOW(kMidShadowEnd
));
379 Printf("red_zone=%zu\n", (uptr
)flags()->redzone
);
380 Printf("quarantine_size=%zuM\n", (uptr
)flags()->quarantine_size
>> 20);
381 Printf("malloc_context_size=%zu\n",
382 (uptr
)common_flags()->malloc_context_size
);
384 Printf("SHADOW_SCALE: %zx\n", (uptr
)SHADOW_SCALE
);
385 Printf("SHADOW_GRANULARITY: %zx\n", (uptr
)SHADOW_GRANULARITY
);
386 Printf("SHADOW_OFFSET: %zx\n", (uptr
)SHADOW_OFFSET
);
387 CHECK(SHADOW_SCALE
>= 3 && SHADOW_SCALE
<= 7);
389 CHECK(kMidShadowBeg
> kLowShadowEnd
&&
390 kMidMemBeg
> kMidShadowEnd
&&
391 kHighShadowBeg
> kMidMemEnd
);
394 } // namespace __asan
396 // ---------------------- Interface ---------------- {{{1
397 using namespace __asan
; // NOLINT
399 #if !SANITIZER_SUPPORTS_WEAK_HOOKS
401 SANITIZER_INTERFACE_ATTRIBUTE SANITIZER_WEAK_ATTRIBUTE
402 const char* __asan_default_options() { return ""; }
406 int NOINLINE
__asan_set_error_exit_code(int exit_code
) {
407 int old
= flags()->exitcode
;
408 flags()->exitcode
= exit_code
;
412 void NOINLINE
__asan_handle_no_return() {
414 AsanThread
*curr_thread
= GetCurrentThread();
416 uptr PageSize
= GetPageSizeCached();
417 uptr top
= curr_thread
->stack_top();
418 uptr bottom
= ((uptr
)&local_stack
- PageSize
) & ~(PageSize
-1);
419 static const uptr kMaxExpectedCleanupSize
= 64 << 20; // 64M
420 if (top
- bottom
> kMaxExpectedCleanupSize
) {
421 static bool reported_warning
= false;
422 if (reported_warning
)
424 reported_warning
= true;
425 Report("WARNING: ASan is ignoring requested __asan_handle_no_return: "
426 "stack top: %p; bottom %p; size: %p (%zd)\n"
427 "False positive error reports may follow\n"
429 "http://code.google.com/p/address-sanitizer/issues/detail?id=189\n",
430 top
, bottom
, top
- bottom
, top
- bottom
);
433 PoisonShadow(bottom
, top
- bottom
, 0);
434 if (curr_thread
->has_fake_stack())
435 curr_thread
->fake_stack()->HandleNoReturn();
438 void NOINLINE
__asan_set_death_callback(void (*callback
)(void)) {
439 death_callback
= callback
;
443 if (asan_inited
) return;
444 SanitizerToolName
= "AddressSanitizer";
445 CHECK(!asan_init_is_running
&& "ASan init calls itself!");
446 asan_init_is_running
= true;
447 InitializeHighMemEnd();
449 // Make sure we are not statically linked.
450 AsanDoesNotSupportStaticLinkage();
452 // Install tool-specific callbacks in sanitizer_common.
453 SetDieCallback(AsanDie
);
454 SetCheckFailedCallback(AsanCheckFailed
);
455 SetPrintfAndReportCallback(AppendToErrorMessageBuffer
);
457 // Initialize flags. This must be done early, because most of the
458 // initialization steps look at flags().
459 const char *options
= GetEnv("ASAN_OPTIONS");
460 InitializeFlags(flags(), options
);
461 __sanitizer_set_report_path(common_flags()->log_path
);
462 __asan_option_detect_stack_use_after_return
=
463 flags()->detect_stack_use_after_return
;
465 if (common_flags()->verbosity
&& options
) {
466 Report("Parsed ASAN_OPTIONS: %s\n", options
);
469 // Re-exec ourselves if we need to set additional env or command line args.
472 // Setup internal allocator callback.
473 SetLowLevelAllocateCallback(OnLowLevelAllocate
);
475 if (flags()->atexit
) {
480 InitializeAsanInterceptors();
482 ReplaceSystemMalloc();
483 ReplaceOperatorsNewAndDelete();
485 uptr shadow_start
= kLowShadowBeg
;
487 shadow_start
-= GetMmapGranularity();
488 bool full_shadow_is_available
=
489 MemoryRangeIsAvailable(shadow_start
, kHighShadowEnd
);
491 #if SANITIZER_LINUX && defined(__x86_64__) && !ASAN_FIXED_MAPPING
492 if (!full_shadow_is_available
) {
493 kMidMemBeg
= kLowMemEnd
< 0x3000000000ULL
? 0x3000000000ULL
: 0;
494 kMidMemEnd
= kLowMemEnd
< 0x3000000000ULL
? 0x4fffffffffULL
: 0;
498 if (common_flags()->verbosity
)
499 PrintAddressSpaceLayout();
501 if (flags()->disable_core
) {
505 if (full_shadow_is_available
) {
506 // mmap the low shadow plus at least one page at the left.
508 ReserveShadowMemoryRange(shadow_start
, kLowShadowEnd
);
509 // mmap the high shadow.
510 ReserveShadowMemoryRange(kHighShadowBeg
, kHighShadowEnd
);
512 ProtectGap(kShadowGapBeg
, kShadowGapEnd
- kShadowGapBeg
+ 1);
513 } else if (kMidMemBeg
&&
514 MemoryRangeIsAvailable(shadow_start
, kMidMemBeg
- 1) &&
515 MemoryRangeIsAvailable(kMidMemEnd
+ 1, kHighShadowEnd
)) {
516 CHECK(kLowShadowBeg
!= kLowShadowEnd
);
517 // mmap the low shadow plus at least one page at the left.
518 ReserveShadowMemoryRange(shadow_start
, kLowShadowEnd
);
519 // mmap the mid shadow.
520 ReserveShadowMemoryRange(kMidShadowBeg
, kMidShadowEnd
);
521 // mmap the high shadow.
522 ReserveShadowMemoryRange(kHighShadowBeg
, kHighShadowEnd
);
524 ProtectGap(kShadowGapBeg
, kShadowGapEnd
- kShadowGapBeg
+ 1);
525 ProtectGap(kShadowGap2Beg
, kShadowGap2End
- kShadowGap2Beg
+ 1);
526 ProtectGap(kShadowGap3Beg
, kShadowGap3End
- kShadowGap3Beg
+ 1);
528 Report("Shadow memory range interleaves with an existing memory mapping. "
529 "ASan cannot proceed correctly. ABORTING.\n");
534 InstallSignalHandlers();
536 AsanTSDInit(PlatformTSDDtor
);
537 // Allocator should be initialized before starting external symbolizer, as
538 // fork() on Mac locks the allocator.
539 InitializeAllocator();
541 // Start symbolizer process if necessary.
542 if (common_flags()->symbolize
&& &getSymbolizer
) {
544 ->InitializeExternal(common_flags()->external_symbolizer_path
);
547 // On Linux AsanThread::ThreadStart() calls malloc() that's why asan_inited
548 // should be set to 1 prior to initializing the threads.
550 asan_init_is_running
= false;
554 // Create main thread.
555 AsanThread
*main_thread
= AsanThread::Create(0, 0);
556 CreateThreadContextArgs create_main_args
= { main_thread
, 0 };
557 u32 main_tid
= asanThreadRegistry().CreateThread(
558 0, true, 0, &create_main_args
);
559 CHECK_EQ(0, main_tid
);
560 SetCurrentThread(main_thread
);
561 main_thread
->ThreadStart(internal_getpid());
562 force_interface_symbols(); // no-op.
564 #if CAN_SANITIZE_LEAKS
565 __lsan::InitCommonLsan();
566 if (common_flags()->detect_leaks
&& common_flags()->leak_check_at_exit
) {
567 Atexit(__lsan::DoLeakCheck
);
569 #endif // CAN_SANITIZE_LEAKS
571 if (common_flags()->verbosity
) {
572 Report("AddressSanitizer Init done\n");