forked from OSchip/llvm-project
parent
fe906a1df6
commit
364bfdf4c9
|
@ -29,7 +29,7 @@ static struct AsanDeactivatedFlags {
|
||||||
static bool asan_is_deactivated;
|
static bool asan_is_deactivated;
|
||||||
|
|
||||||
void AsanStartDeactivated() {
|
void AsanStartDeactivated() {
|
||||||
VReport(1, "Deactivating asan\n");
|
VReport(1, "Deactivating ASan\n");
|
||||||
// Save flag values.
|
// Save flag values.
|
||||||
asan_deactivated_flags.quarantine_size = flags()->quarantine_size;
|
asan_deactivated_flags.quarantine_size = flags()->quarantine_size;
|
||||||
asan_deactivated_flags.max_redzone = flags()->max_redzone;
|
asan_deactivated_flags.max_redzone = flags()->max_redzone;
|
||||||
|
@ -47,7 +47,7 @@ void AsanStartDeactivated() {
|
||||||
|
|
||||||
void AsanActivate() {
|
void AsanActivate() {
|
||||||
if (!asan_is_deactivated) return;
|
if (!asan_is_deactivated) return;
|
||||||
VReport(1, "Activating asan\n");
|
VReport(1, "Activating ASan\n");
|
||||||
|
|
||||||
// Restore flag values.
|
// Restore flag values.
|
||||||
// FIXME: this is not atomic, and there may be other threads alive.
|
// FIXME: this is not atomic, and there may be other threads alive.
|
||||||
|
@ -66,4 +66,4 @@ void AsanActivate() {
|
||||||
common_flags()->malloc_context_size);
|
common_flags()->malloc_context_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace __asan
|
} // namespace __asan
|
||||||
|
|
|
@ -18,6 +18,6 @@
|
||||||
namespace __asan {
|
namespace __asan {
|
||||||
void AsanStartDeactivated();
|
void AsanStartDeactivated();
|
||||||
void AsanActivate();
|
void AsanActivate();
|
||||||
} // namespace __asan
|
} // namespace __asan
|
||||||
|
|
||||||
#endif // ASAN_ACTIVATION_H
|
#endif // ASAN_ACTIVATION_H
|
||||||
|
|
|
@ -70,13 +70,6 @@ static inline bool RangesOverlap(const char *offset1, uptr length1,
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} 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) {
|
static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) {
|
||||||
#if ASAN_INTERCEPT_STRNLEN
|
#if ASAN_INTERCEPT_STRNLEN
|
||||||
if (REAL(strnlen) != 0) {
|
if (REAL(strnlen) != 0) {
|
||||||
|
|
|
@ -94,6 +94,13 @@ namespace __asan {
|
||||||
|
|
||||||
void InitializeAsanInterceptors();
|
void InitializeAsanInterceptors();
|
||||||
|
|
||||||
|
#define ENSURE_ASAN_INITED() do { \
|
||||||
|
CHECK(!asan_init_is_running); \
|
||||||
|
if (!asan_inited) { \
|
||||||
|
AsanInitFromRtl(); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
} // namespace __asan
|
} // namespace __asan
|
||||||
|
|
||||||
#endif // ASAN_INTERCEPTORS_H
|
#endif // ASAN_INTERCEPTORS_H
|
||||||
|
|
|
@ -41,7 +41,7 @@ static malloc_zone_t asan_zone;
|
||||||
|
|
||||||
INTERCEPTOR(malloc_zone_t *, malloc_create_zone,
|
INTERCEPTOR(malloc_zone_t *, malloc_create_zone,
|
||||||
vm_size_t start_size, unsigned zone_flags) {
|
vm_size_t start_size, unsigned zone_flags) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
GET_STACK_TRACE_MALLOC;
|
GET_STACK_TRACE_MALLOC;
|
||||||
uptr page_size = GetPageSizeCached();
|
uptr page_size = GetPageSizeCached();
|
||||||
uptr allocated_size = RoundUpTo(sizeof(asan_zone), page_size);
|
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) {
|
INTERCEPTOR(malloc_zone_t *, malloc_default_zone, void) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
return &asan_zone;
|
return &asan_zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(malloc_zone_t *, malloc_default_purgeable_zone, void) {
|
INTERCEPTOR(malloc_zone_t *, malloc_default_purgeable_zone, void) {
|
||||||
// FIXME: ASan should support purgeable allocations.
|
// FIXME: ASan should support purgeable allocations.
|
||||||
// https://code.google.com/p/address-sanitizer/issues/detail?id=139
|
// https://code.google.com/p/address-sanitizer/issues/detail?id=139
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
return &asan_zone;
|
return &asan_zone;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(void, malloc_make_purgeable, void *ptr) {
|
INTERCEPTOR(void, malloc_make_purgeable, void *ptr) {
|
||||||
// FIXME: ASan should support purgeable allocations. Ignoring them is fine
|
// FIXME: ASan should support purgeable allocations. Ignoring them is fine
|
||||||
// for now.
|
// for now.
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(int, malloc_make_nonpurgeable, void *ptr) {
|
INTERCEPTOR(int, malloc_make_nonpurgeable, void *ptr) {
|
||||||
// FIXME: ASan should support purgeable allocations. Ignoring them is fine
|
// FIXME: ASan should support purgeable allocations. Ignoring them is fine
|
||||||
// for now.
|
// for now.
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
// Must return 0 if the contents were not purged since the last call to
|
// Must return 0 if the contents were not purged since the last call to
|
||||||
// malloc_make_purgeable().
|
// malloc_make_purgeable().
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(void, malloc_set_zone_name, malloc_zone_t *zone, const char *name) {
|
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.
|
// Allocate |strlen("asan-") + 1 + internal_strlen(name)| bytes.
|
||||||
size_t buflen = 6 + (name ? internal_strlen(name) : 0);
|
size_t buflen = 6 + (name ? internal_strlen(name) : 0);
|
||||||
InternalScopedBuffer<char> new_name(buflen);
|
InternalScopedBuffer<char> 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) {
|
INTERCEPTOR(void *, malloc, size_t size) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
GET_STACK_TRACE_MALLOC;
|
GET_STACK_TRACE_MALLOC;
|
||||||
void *res = asan_malloc(size, &stack);
|
void *res = asan_malloc(size, &stack);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(void, free, void *ptr) {
|
INTERCEPTOR(void, free, void *ptr) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
if (!ptr) return;
|
if (!ptr) return;
|
||||||
GET_STACK_TRACE_FREE;
|
GET_STACK_TRACE_FREE;
|
||||||
asan_free(ptr, &stack, FROM_MALLOC);
|
asan_free(ptr, &stack, FROM_MALLOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(void *, realloc, void *ptr, size_t size) {
|
INTERCEPTOR(void *, realloc, void *ptr, size_t size) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
GET_STACK_TRACE_MALLOC;
|
GET_STACK_TRACE_MALLOC;
|
||||||
return asan_realloc(ptr, size, &stack);
|
return asan_realloc(ptr, size, &stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(void *, calloc, size_t nmemb, size_t size) {
|
INTERCEPTOR(void *, calloc, size_t nmemb, size_t size) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
GET_STACK_TRACE_MALLOC;
|
GET_STACK_TRACE_MALLOC;
|
||||||
return asan_calloc(nmemb, size, &stack);
|
return asan_calloc(nmemb, size, &stack);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(void *, valloc, size_t size) {
|
INTERCEPTOR(void *, valloc, size_t size) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
GET_STACK_TRACE_MALLOC;
|
GET_STACK_TRACE_MALLOC;
|
||||||
return asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC);
|
return asan_memalign(GetPageSizeCached(), size, &stack, FROM_MALLOC);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(size_t, malloc_good_size, size_t size) {
|
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);
|
return asan_zone.introspect->good_size(&asan_zone, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) {
|
INTERCEPTOR(int, posix_memalign, void **memptr, size_t alignment, size_t size) {
|
||||||
if (!asan_inited) AsanInitFromRtl();
|
ENSURE_ASAN_INITED();
|
||||||
CHECK(memptr);
|
CHECK(memptr);
|
||||||
GET_STACK_TRACE_MALLOC;
|
GET_STACK_TRACE_MALLOC;
|
||||||
void *result = asan_memalign(alignment, size, &stack, FROM_MALLOC);
|
void *result = asan_memalign(alignment, size, &stack, FROM_MALLOC);
|
||||||
|
|
Loading…
Reference in New Issue