forked from OSchip/llvm-project
[NFC][sanitizer] Move GET_MALLOC_STACK_TRACE closer to the use
This commit is contained in:
parent
a86ef2c827
commit
651797f488
|
@ -83,17 +83,17 @@ void *__sanitizer_pvalloc(uptr size) {
|
|||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void __sanitizer_free(void *ptr) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr)))
|
||||
return;
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
hwasan_free(ptr, &stack);
|
||||
}
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void __sanitizer_cfree(void *ptr) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr)))
|
||||
return;
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
hwasan_free(ptr, &stack);
|
||||
}
|
||||
|
||||
|
@ -119,16 +119,15 @@ void __sanitizer_malloc_stats(void) {
|
|||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void *__sanitizer_calloc(uptr nmemb, uptr size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (UNLIKELY(!hwasan_inited))
|
||||
// Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
|
||||
return AllocateFromLocalPool(nmemb * size);
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
return hwasan_calloc(nmemb, size, &stack);
|
||||
}
|
||||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void *__sanitizer_realloc(void *ptr, uptr size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (UNLIKELY(IsInDlsymAllocPool(ptr))) {
|
||||
uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
|
||||
uptr copy_size = Min(size, kDlsymAllocPoolSize - offset);
|
||||
|
@ -137,11 +136,13 @@ void *__sanitizer_realloc(void *ptr, uptr size) {
|
|||
new_ptr = AllocateFromLocalPool(copy_size);
|
||||
} else {
|
||||
copy_size = size;
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
new_ptr = hwasan_malloc(copy_size, &stack);
|
||||
}
|
||||
internal_memcpy(new_ptr, ptr, copy_size);
|
||||
return new_ptr;
|
||||
}
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
return hwasan_realloc(ptr, size, &stack);
|
||||
}
|
||||
|
||||
|
@ -153,12 +154,12 @@ void *__sanitizer_reallocarray(void *ptr, uptr nmemb, uptr size) {
|
|||
|
||||
SANITIZER_INTERFACE_ATTRIBUTE
|
||||
void *__sanitizer_malloc(uptr size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (UNLIKELY(!hwasan_init_is_running))
|
||||
ENSURE_HWASAN_INITED();
|
||||
if (UNLIKELY(!hwasan_inited))
|
||||
// Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym.
|
||||
return AllocateFromLocalPool(size);
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
return hwasan_malloc(size, &stack);
|
||||
}
|
||||
|
||||
|
|
|
@ -102,19 +102,19 @@ static void *ReallocFromLocalPool(void *ptr, uptr size) {
|
|||
}
|
||||
|
||||
INTERCEPTOR(void, free, void *ptr) {
|
||||
GET_STACK_TRACE_FREE;
|
||||
if (UNLIKELY(IsInDlsymAllocPool(ptr))) {
|
||||
DeallocateFromLocalPool(ptr);
|
||||
return;
|
||||
}
|
||||
GET_STACK_TRACE_FREE;
|
||||
memprof_free(ptr, &stack, FROM_MALLOC);
|
||||
}
|
||||
|
||||
#if SANITIZER_INTERCEPT_CFREE
|
||||
INTERCEPTOR(void, cfree, void *ptr) {
|
||||
GET_STACK_TRACE_FREE;
|
||||
if (UNLIKELY(IsInDlsymAllocPool(ptr)))
|
||||
return;
|
||||
GET_STACK_TRACE_FREE;
|
||||
memprof_free(ptr, &stack, FROM_MALLOC);
|
||||
}
|
||||
#endif // SANITIZER_INTERCEPT_CFREE
|
||||
|
|
|
@ -221,18 +221,18 @@ INTERCEPTOR(void *, pvalloc, SIZE_T size) {
|
|||
#endif
|
||||
|
||||
INTERCEPTOR(void, free, void *ptr) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return;
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
MsanDeallocate(&stack, ptr);
|
||||
}
|
||||
|
||||
#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD
|
||||
INTERCEPTOR(void, cfree, void *ptr) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (!ptr || UNLIKELY(IsInDlsymAllocPool(ptr))) return;
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
MsanDeallocate(&stack, ptr);
|
||||
}
|
||||
#define MSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree)
|
||||
# define MSAN_MAYBE_INTERCEPT_CFREE INTERCEPT_FUNCTION(cfree)
|
||||
#else
|
||||
#define MSAN_MAYBE_INTERCEPT_CFREE
|
||||
#endif
|
||||
|
@ -886,7 +886,6 @@ INTERCEPTOR(void *, calloc, SIZE_T nmemb, SIZE_T size) {
|
|||
}
|
||||
|
||||
INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (UNLIKELY(IsInDlsymAllocPool(ptr))) {
|
||||
uptr offset = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
|
||||
uptr copy_size = Min(size, kDlsymAllocPoolSize - offset);
|
||||
|
@ -895,11 +894,13 @@ INTERCEPTOR(void *, realloc, void *ptr, SIZE_T size) {
|
|||
new_ptr = AllocateFromLocalPool(copy_size);
|
||||
} else {
|
||||
copy_size = size;
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
new_ptr = msan_malloc(copy_size, &stack);
|
||||
}
|
||||
internal_memcpy(new_ptr, ptr, copy_size);
|
||||
return new_ptr;
|
||||
}
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
return msan_realloc(ptr, size, &stack);
|
||||
}
|
||||
|
||||
|
@ -909,16 +910,16 @@ INTERCEPTOR(void *, reallocarray, void *ptr, SIZE_T nmemb, SIZE_T size) {
|
|||
}
|
||||
|
||||
INTERCEPTOR(void *, malloc, SIZE_T size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (UNLIKELY(!msan_inited))
|
||||
// Hack: dlsym calls malloc before REAL(malloc) is retrieved from dlsym.
|
||||
return AllocateFromLocalPool(size);
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
return msan_malloc(size, &stack);
|
||||
}
|
||||
|
||||
void __msan_allocated_memory(const void *data, uptr size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (flags()->poison_in_malloc) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
stack.tag = STACK_TRACE_TAG_POISON;
|
||||
PoisonMemory(data, size, &stack);
|
||||
}
|
||||
|
@ -930,8 +931,8 @@ void __msan_copy_shadow(void *dest, const void *src, uptr n) {
|
|||
}
|
||||
|
||||
void __sanitizer_dtor_callback(const void *data, uptr size) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
if (flags()->poison_in_dtor) {
|
||||
GET_MALLOC_STACK_TRACE;
|
||||
stack.tag = STACK_TRACE_TAG_POISON;
|
||||
PoisonMemory(data, size, &stack);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue