diff --git a/compiler-rt/lib/asan/asan_activation.cc b/compiler-rt/lib/asan/asan_activation.cc index 743b928ceb0b..0fad714a0c4f 100644 --- a/compiler-rt/lib/asan/asan_activation.cc +++ b/compiler-rt/lib/asan/asan_activation.cc @@ -29,7 +29,7 @@ static struct AsanDeactivatedFlags { static bool asan_is_deactivated; void AsanStartDeactivated() { - VReport(1, "Deactivating asan\n"); + VReport(1, "Deactivating ASan\n"); // Save flag values. asan_deactivated_flags.quarantine_size = flags()->quarantine_size; asan_deactivated_flags.max_redzone = flags()->max_redzone; @@ -47,7 +47,7 @@ void AsanStartDeactivated() { void AsanActivate() { if (!asan_is_deactivated) return; - VReport(1, "Activating asan\n"); + VReport(1, "Activating ASan\n"); // Restore flag values. // FIXME: this is not atomic, and there may be other threads alive. @@ -66,4 +66,4 @@ void AsanActivate() { common_flags()->malloc_context_size); } -} // namespace __asan +} // namespace __asan diff --git a/compiler-rt/lib/asan/asan_activation.h b/compiler-rt/lib/asan/asan_activation.h index 8ab76380f415..dafb840a6042 100644 --- a/compiler-rt/lib/asan/asan_activation.h +++ b/compiler-rt/lib/asan/asan_activation.h @@ -18,6 +18,6 @@ namespace __asan { void AsanStartDeactivated(); void AsanActivate(); -} // namespace __asan +} // namespace __asan -#endif // ASAN_ACTIVATION_H +#endif // ASAN_ACTIVATION_H diff --git a/compiler-rt/lib/asan/asan_interceptors.cc b/compiler-rt/lib/asan/asan_interceptors.cc index f808c432513d..a626de643df5 100644 --- a/compiler-rt/lib/asan/asan_interceptors.cc +++ b/compiler-rt/lib/asan/asan_interceptors.cc @@ -70,13 +70,6 @@ static inline bool RangesOverlap(const char *offset1, uptr length1, } \ } while (0) -#define ENSURE_ASAN_INITED() do { \ - CHECK(!asan_init_is_running); \ - if (!asan_inited) { \ - AsanInitFromRtl(); \ - } \ -} while (0) - static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) { #if ASAN_INTERCEPT_STRNLEN if (REAL(strnlen) != 0) { diff --git a/compiler-rt/lib/asan/asan_interceptors.h b/compiler-rt/lib/asan/asan_interceptors.h index 6f410ed9964e..2a8c04366c96 100644 --- a/compiler-rt/lib/asan/asan_interceptors.h +++ b/compiler-rt/lib/asan/asan_interceptors.h @@ -94,6 +94,13 @@ namespace __asan { void InitializeAsanInterceptors(); +#define ENSURE_ASAN_INITED() do { \ + CHECK(!asan_init_is_running); \ + if (!asan_inited) { \ + AsanInitFromRtl(); \ + } \ +} while (0) + } // namespace __asan #endif // ASAN_INTERCEPTORS_H diff --git a/compiler-rt/lib/asan/asan_malloc_mac.cc b/compiler-rt/lib/asan/asan_malloc_mac.cc index 521ee667df4d..2eb3a982388a 100644 --- a/compiler-rt/lib/asan/asan_malloc_mac.cc +++ b/compiler-rt/lib/asan/asan_malloc_mac.cc @@ -41,7 +41,7 @@ static malloc_zone_t asan_zone; INTERCEPTOR(malloc_zone_t *, malloc_create_zone, vm_size_t start_size, unsigned zone_flags) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); GET_STACK_TRACE_MALLOC; uptr page_size = GetPageSizeCached(); uptr allocated_size = RoundUpTo(sizeof(asan_zone), page_size); @@ -60,34 +60,34 @@ INTERCEPTOR(malloc_zone_t *, malloc_create_zone, } INTERCEPTOR(malloc_zone_t *, malloc_default_zone, void) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); return &asan_zone; } INTERCEPTOR(malloc_zone_t *, malloc_default_purgeable_zone, void) { // FIXME: ASan should support purgeable allocations. // https://code.google.com/p/address-sanitizer/issues/detail?id=139 - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); return &asan_zone; } INTERCEPTOR(void, malloc_make_purgeable, void *ptr) { // FIXME: ASan should support purgeable allocations. Ignoring them is fine // for now. - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); } INTERCEPTOR(int, malloc_make_nonpurgeable, void *ptr) { // FIXME: ASan should support purgeable allocations. Ignoring them is fine // for now. - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); // Must return 0 if the contents were not purged since the last call to // malloc_make_purgeable(). return 0; } INTERCEPTOR(void, malloc_set_zone_name, malloc_zone_t *zone, const char *name) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); // Allocate |strlen("asan-") + 1 + internal_strlen(name)| bytes. size_t buflen = 6 + (name ? internal_strlen(name) : 0); InternalScopedBuffer new_name(buflen); @@ -102,44 +102,44 @@ INTERCEPTOR(void, malloc_set_zone_name, malloc_zone_t *zone, const char *name) { } INTERCEPTOR(void *, malloc, size_t size) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); GET_STACK_TRACE_MALLOC; void *res = asan_malloc(size, &stack); return res; } INTERCEPTOR(void, free, void *ptr) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); if (!ptr) return; GET_STACK_TRACE_FREE; asan_free(ptr, &stack, FROM_MALLOC); } INTERCEPTOR(void *, realloc, void *ptr, size_t size) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); GET_STACK_TRACE_MALLOC; return asan_realloc(ptr, size, &stack); } INTERCEPTOR(void *, calloc, size_t nmemb, size_t size) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); GET_STACK_TRACE_MALLOC; return asan_calloc(nmemb, size, &stack); } INTERCEPTOR(void *, valloc, size_t size) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); GET_STACK_TRACE_MALLOC; return asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC); } INTERCEPTOR(size_t, malloc_good_size, size_t size) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); return asan_zone.introspect->good_size(&asan_zone, size); } INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) { - if (!asan_inited) AsanInitFromRtl(); + ENSURE_ASAN_INITED(); CHECK(memptr); GET_STACK_TRACE_MALLOC; void *result = asan_memalign(alignment, size, &stack, FROM_MALLOC);