[NFC][sanitizer] Remove unnececary HOOK macros

This commit is contained in:
Vitaly Buka 2022-04-12 19:19:44 -07:00
parent f8a38500e3
commit b84673b3f4
8 changed files with 29 additions and 73 deletions

View File

@ -597,7 +597,9 @@ struct Allocator {
CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg);
reinterpret_cast<LargeChunkHeader *>(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.

View File

@ -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()

View File

@ -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;

View File

@ -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<uptr>(tagged_ptr));

View File

@ -430,7 +430,9 @@ struct Allocator {
CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg);
reinterpret_cast<LargeChunkHeader *>(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<MemprofChunk *>(chunk_beg);

View File

@ -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;

View File

@ -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

View File

@ -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<Metadata *>(allocator.GetMetaData(p));
uptr size = meta->requested_size;
meta->requested_size = 0;