From b84673b3f424882c4c1961fb2c49b6302b68f344 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Tue, 12 Apr 2022 19:19:44 -0700 Subject: [PATCH] [NFC][sanitizer] Remove unnececary HOOK macros --- compiler-rt/lib/asan/asan_allocator.cpp | 8 ++++++-- compiler-rt/lib/asan/asan_internal.h | 16 ---------------- compiler-rt/lib/hwasan/hwasan.h | 16 ---------------- compiler-rt/lib/hwasan/hwasan_allocator.cpp | 8 ++++++-- compiler-rt/lib/memprof/memprof_allocator.cpp | 8 ++++++-- compiler-rt/lib/memprof/memprof_internal.h | 16 ---------------- compiler-rt/lib/msan/msan.h | 17 ----------------- compiler-rt/lib/msan/msan_allocator.cpp | 13 +++++++++++-- 8 files changed, 29 insertions(+), 73 deletions(-) diff --git a/compiler-rt/lib/asan/asan_allocator.cpp b/compiler-rt/lib/asan/asan_allocator.cpp index f9f1cfcd9f87..e6a22585eeb4 100644 --- a/compiler-rt/lib/asan/asan_allocator.cpp +++ b/compiler-rt/lib/asan/asan_allocator.cpp @@ -597,7 +597,9 @@ struct Allocator { CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg); reinterpret_cast(alloc_beg)->Set(m); } - ASAN_MALLOC_HOOK(res, size); + if (&__sanitizer_malloc_hook) + __sanitizer_malloc_hook(res, size); + RunMallocHooks(res, size); return res; } @@ -678,7 +680,9 @@ struct Allocator { return; } - ASAN_FREE_HOOK(ptr); + if (&__sanitizer_free_hook) + __sanitizer_free_hook(ptr); + RunFreeHooks(ptr); // Must mark the chunk as quarantined before any changes to its metadata. // Do not quarantine given chunk if we failed to set CHUNK_QUARANTINE flag. diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index 27f8949ffdb0..7468f126d37b 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -125,22 +125,6 @@ bool HandleDlopenInit(); void InstallAtExitCheckLeaks(); -// Add convenient macro for interface functions that may be represented as -// weak hooks. -#define ASAN_MALLOC_HOOK(ptr, size) \ - do { \ - if (&__sanitizer_malloc_hook) \ - __sanitizer_malloc_hook(ptr, size); \ - RunMallocHooks(ptr, size); \ - } while (false) - -#define ASAN_FREE_HOOK(ptr) \ - do { \ - if (&__sanitizer_free_hook) \ - __sanitizer_free_hook(ptr); \ - RunFreeHooks(ptr); \ - } while (false) - #define ASAN_ON_ERROR() \ if (&__asan_on_error) \ __asan_on_error() diff --git a/compiler-rt/lib/hwasan/hwasan.h b/compiler-rt/lib/hwasan/hwasan.h index 6c5c0b6986c7..3cc2fc40b5f6 100644 --- a/compiler-rt/lib/hwasan/hwasan.h +++ b/compiler-rt/lib/hwasan/hwasan.h @@ -172,22 +172,6 @@ void HwasanTagMismatch(uptr addr, uptr access_info, uptr *registers_frame, } // namespace __hwasan -#define HWASAN_MALLOC_HOOK(ptr, size) \ - do { \ - if (&__sanitizer_malloc_hook) { \ - __sanitizer_malloc_hook(ptr, size); \ - } \ - RunMallocHooks(ptr, size); \ - } while (false) - -#define HWASAN_FREE_HOOK(ptr) \ - do { \ - if (&__sanitizer_free_hook) { \ - __sanitizer_free_hook(ptr); \ - } \ - RunFreeHooks(ptr); \ - } while (false) - #if HWASAN_WITH_INTERCEPTORS // For both bionic and glibc __sigset_t is an unsigned long. typedef unsigned long __hw_sigset_t; diff --git a/compiler-rt/lib/hwasan/hwasan_allocator.cpp b/compiler-rt/lib/hwasan/hwasan_allocator.cpp index 84e183f2384f..787ac7da66f0 100644 --- a/compiler-rt/lib/hwasan/hwasan_allocator.cpp +++ b/compiler-rt/lib/hwasan/hwasan_allocator.cpp @@ -199,7 +199,9 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment, } } - HWASAN_MALLOC_HOOK(user_ptr, size); + if (&__sanitizer_malloc_hook) + __sanitizer_malloc_hook(user_ptr, size); + RunMallocHooks(user_ptr, size); return user_ptr; } @@ -226,7 +228,9 @@ static bool CheckInvalidFree(StackTrace *stack, void *untagged_ptr, static void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) { CHECK(tagged_ptr); - HWASAN_FREE_HOOK(tagged_ptr); + if (&__sanitizer_free_hook) + __sanitizer_free_hook(tagged_ptr); + RunFreeHooks(tagged_ptr); bool in_taggable_region = InTaggableRegion(reinterpret_cast(tagged_ptr)); diff --git a/compiler-rt/lib/memprof/memprof_allocator.cpp b/compiler-rt/lib/memprof/memprof_allocator.cpp index 1475e2cf36bd..d41640eeeca4 100644 --- a/compiler-rt/lib/memprof/memprof_allocator.cpp +++ b/compiler-rt/lib/memprof/memprof_allocator.cpp @@ -430,7 +430,9 @@ struct Allocator { CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg); reinterpret_cast(alloc_beg)->Set(m); } - MEMPROF_MALLOC_HOOK(res, size); + if (&__sanitizer_malloc_hook) + __sanitizer_malloc_hook(res, size); + RunMallocHooks(res, size); return res; } @@ -440,7 +442,9 @@ struct Allocator { if (p == 0) return; - MEMPROF_FREE_HOOK(ptr); + if (&__sanitizer_free_hook) + __sanitizer_free_hook(ptr); + RunFreeHooks(ptr); uptr chunk_beg = p - kChunkHeaderSize; MemprofChunk *m = reinterpret_cast(chunk_beg); diff --git a/compiler-rt/lib/memprof/memprof_internal.h b/compiler-rt/lib/memprof/memprof_internal.h index 0ebf9e0bbeee..1adb368e3e41 100644 --- a/compiler-rt/lib/memprof/memprof_internal.h +++ b/compiler-rt/lib/memprof/memprof_internal.h @@ -76,22 +76,6 @@ void PlatformTSDDtor(void *tsd); void *MemprofDlSymNext(const char *sym); -// Add convenient macro for interface functions that may be represented as -// weak hooks. -#define MEMPROF_MALLOC_HOOK(ptr, size) \ - do { \ - if (&__sanitizer_malloc_hook) \ - __sanitizer_malloc_hook(ptr, size); \ - RunMallocHooks(ptr, size); \ - } while (false) - -#define MEMPROF_FREE_HOOK(ptr) \ - do { \ - if (&__sanitizer_free_hook) \ - __sanitizer_free_hook(ptr); \ - RunFreeHooks(ptr); \ - } while (false) - extern int memprof_inited; extern int memprof_timestamp_inited; extern int memprof_init_done; diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h index b018b1337b3f..30efce94af54 100644 --- a/compiler-rt/lib/msan/msan.h +++ b/compiler-rt/lib/msan/msan.h @@ -375,21 +375,4 @@ void MsanTSDDtor(void *tsd); } // namespace __msan -#define MSAN_MALLOC_HOOK(ptr, size) \ - do { \ - if (&__sanitizer_malloc_hook) { \ - UnpoisonParam(2); \ - __sanitizer_malloc_hook(ptr, size); \ - } \ - RunMallocHooks(ptr, size); \ - } while (false) -#define MSAN_FREE_HOOK(ptr) \ - do { \ - if (&__sanitizer_free_hook) { \ - UnpoisonParam(1); \ - __sanitizer_free_hook(ptr); \ - } \ - RunFreeHooks(ptr); \ - } while (false) - #endif // MSAN_H diff --git a/compiler-rt/lib/msan/msan_allocator.cpp b/compiler-rt/lib/msan/msan_allocator.cpp index dc006457a59f..6b50ac10754f 100644 --- a/compiler-rt/lib/msan/msan_allocator.cpp +++ b/compiler-rt/lib/msan/msan_allocator.cpp @@ -194,13 +194,22 @@ static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment, __msan_set_origin(allocated, size, o.raw_id()); } } - MSAN_MALLOC_HOOK(allocated, size); + if (&__sanitizer_malloc_hook) { + UnpoisonParam(2); + __sanitizer_malloc_hook(allocated, size); + } + RunMallocHooks(allocated, size); return allocated; } void MsanDeallocate(StackTrace *stack, void *p) { CHECK(p); - MSAN_FREE_HOOK(p); + if (&__sanitizer_free_hook) { + UnpoisonParam(1); + __sanitizer_free_hook(p); + } + RunFreeHooks(p); + Metadata *meta = reinterpret_cast(allocator.GetMetaData(p)); uptr size = meta->requested_size; meta->requested_size = 0;