diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_dlsym.h b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_dlsym.h index b360478a058a5..6e6cdbd9eeaed 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_allocator_dlsym.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_allocator_dlsym.h @@ -36,21 +36,19 @@ struct DlSymAllocator { static void *Allocate(uptr size_in_bytes, uptr align = kWordSize) { void *ptr = InternalAlloc(size_in_bytes, nullptr, align); CHECK(internal_allocator()->FromPrimary(ptr)); - Details::OnAllocate(ptr, - internal_allocator()->GetActuallyAllocatedSize(ptr)); + Details::OnAllocate(ptr, GetSize(ptr)); return ptr; } static void *Callocate(usize nmemb, usize size) { void *ptr = InternalCalloc(nmemb, size); CHECK(internal_allocator()->FromPrimary(ptr)); - Details::OnAllocate(ptr, - internal_allocator()->GetActuallyAllocatedSize(ptr)); + Details::OnAllocate(ptr, GetSize(ptr)); return ptr; } static void Free(void *ptr) { - uptr size = internal_allocator()->GetActuallyAllocatedSize(ptr); + uptr size = GetSize(ptr); Details::OnFree(ptr, size); InternalFree(ptr); } @@ -63,7 +61,7 @@ struct DlSymAllocator { Free(ptr); return nullptr; } - uptr size = internal_allocator()->GetActuallyAllocatedSize(ptr); + uptr size = GetSize(ptr); uptr memcpy_size = Min(new_size, size); void *new_ptr = Allocate(new_size); if (new_ptr) @@ -77,6 +75,10 @@ struct DlSymAllocator { return Realloc(ptr, count * size); } + static uptr GetSize(void *ptr) { + return internal_allocator()->GetActuallyAllocatedSize(ptr); + } + static void OnAllocate(const void *ptr, uptr size) {} static void OnFree(const void *ptr, uptr size) {} }; diff --git a/compiler-rt/lib/tysan/tysan_interceptors.cpp b/compiler-rt/lib/tysan/tysan_interceptors.cpp index 08b1010a48ecf..a9c55a3ae0cf0 100644 --- a/compiler-rt/lib/tysan/tysan_interceptors.cpp +++ b/compiler-rt/lib/tysan/tysan_interceptors.cpp @@ -108,6 +108,14 @@ INTERCEPTOR(void *, malloc, uptr size) { return res; } +#if SANITIZER_APPLE +INTERCEPTOR(uptr, malloc_size, void *ptr) { + if (DlsymAlloc::PointerIsMine(ptr)) + return DlsymAlloc::GetSize(ptr); + return REAL(malloc_size)(ptr); +} +#endif + INTERCEPTOR(void *, realloc, void *ptr, uptr size) { if (DlsymAlloc::Use() || DlsymAlloc::PointerIsMine(ptr)) return DlsymAlloc::Realloc(ptr, size);