Skip to content

Commit b84673b

Browse files
committed
[NFC][sanitizer] Remove unnececary HOOK macros
1 parent f8a3850 commit b84673b

File tree

8 files changed

+29
-73
lines changed

8 files changed

+29
-73
lines changed

compiler-rt/lib/asan/asan_allocator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,9 @@ struct Allocator {
597597
CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg);
598598
reinterpret_cast<LargeChunkHeader *>(alloc_beg)->Set(m);
599599
}
600-
ASAN_MALLOC_HOOK(res, size);
600+
if (&__sanitizer_malloc_hook)
601+
__sanitizer_malloc_hook(res, size);
602+
RunMallocHooks(res, size);
601603
return res;
602604
}
603605

@@ -678,7 +680,9 @@ struct Allocator {
678680
return;
679681
}
680682

681-
ASAN_FREE_HOOK(ptr);
683+
if (&__sanitizer_free_hook)
684+
__sanitizer_free_hook(ptr);
685+
RunFreeHooks(ptr);
682686

683687
// Must mark the chunk as quarantined before any changes to its metadata.
684688
// Do not quarantine given chunk if we failed to set CHUNK_QUARANTINE flag.

compiler-rt/lib/asan/asan_internal.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -125,22 +125,6 @@ bool HandleDlopenInit();
125125

126126
void InstallAtExitCheckLeaks();
127127

128-
// Add convenient macro for interface functions that may be represented as
129-
// weak hooks.
130-
#define ASAN_MALLOC_HOOK(ptr, size) \
131-
do { \
132-
if (&__sanitizer_malloc_hook) \
133-
__sanitizer_malloc_hook(ptr, size); \
134-
RunMallocHooks(ptr, size); \
135-
} while (false)
136-
137-
#define ASAN_FREE_HOOK(ptr) \
138-
do { \
139-
if (&__sanitizer_free_hook) \
140-
__sanitizer_free_hook(ptr); \
141-
RunFreeHooks(ptr); \
142-
} while (false)
143-
144128
#define ASAN_ON_ERROR() \
145129
if (&__asan_on_error) \
146130
__asan_on_error()

compiler-rt/lib/hwasan/hwasan.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -172,22 +172,6 @@ void HwasanTagMismatch(uptr addr, uptr access_info, uptr *registers_frame,
172172

173173
} // namespace __hwasan
174174

175-
#define HWASAN_MALLOC_HOOK(ptr, size) \
176-
do { \
177-
if (&__sanitizer_malloc_hook) { \
178-
__sanitizer_malloc_hook(ptr, size); \
179-
} \
180-
RunMallocHooks(ptr, size); \
181-
} while (false)
182-
183-
#define HWASAN_FREE_HOOK(ptr) \
184-
do { \
185-
if (&__sanitizer_free_hook) { \
186-
__sanitizer_free_hook(ptr); \
187-
} \
188-
RunFreeHooks(ptr); \
189-
} while (false)
190-
191175
#if HWASAN_WITH_INTERCEPTORS
192176
// For both bionic and glibc __sigset_t is an unsigned long.
193177
typedef unsigned long __hw_sigset_t;

compiler-rt/lib/hwasan/hwasan_allocator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,9 @@ static void *HwasanAllocate(StackTrace *stack, uptr orig_size, uptr alignment,
199199
}
200200
}
201201

202-
HWASAN_MALLOC_HOOK(user_ptr, size);
202+
if (&__sanitizer_malloc_hook)
203+
__sanitizer_malloc_hook(user_ptr, size);
204+
RunMallocHooks(user_ptr, size);
203205
return user_ptr;
204206
}
205207

@@ -226,7 +228,9 @@ static bool CheckInvalidFree(StackTrace *stack, void *untagged_ptr,
226228

227229
static void HwasanDeallocate(StackTrace *stack, void *tagged_ptr) {
228230
CHECK(tagged_ptr);
229-
HWASAN_FREE_HOOK(tagged_ptr);
231+
if (&__sanitizer_free_hook)
232+
__sanitizer_free_hook(tagged_ptr);
233+
RunFreeHooks(tagged_ptr);
230234

231235
bool in_taggable_region =
232236
InTaggableRegion(reinterpret_cast<uptr>(tagged_ptr));

compiler-rt/lib/memprof/memprof_allocator.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ struct Allocator {
430430
CHECK_LE(alloc_beg + sizeof(LargeChunkHeader), chunk_beg);
431431
reinterpret_cast<LargeChunkHeader *>(alloc_beg)->Set(m);
432432
}
433-
MEMPROF_MALLOC_HOOK(res, size);
433+
if (&__sanitizer_malloc_hook)
434+
__sanitizer_malloc_hook(res, size);
435+
RunMallocHooks(res, size);
434436
return res;
435437
}
436438

@@ -440,7 +442,9 @@ struct Allocator {
440442
if (p == 0)
441443
return;
442444

443-
MEMPROF_FREE_HOOK(ptr);
445+
if (&__sanitizer_free_hook)
446+
__sanitizer_free_hook(ptr);
447+
RunFreeHooks(ptr);
444448

445449
uptr chunk_beg = p - kChunkHeaderSize;
446450
MemprofChunk *m = reinterpret_cast<MemprofChunk *>(chunk_beg);

compiler-rt/lib/memprof/memprof_internal.h

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -76,22 +76,6 @@ void PlatformTSDDtor(void *tsd);
7676

7777
void *MemprofDlSymNext(const char *sym);
7878

79-
// Add convenient macro for interface functions that may be represented as
80-
// weak hooks.
81-
#define MEMPROF_MALLOC_HOOK(ptr, size) \
82-
do { \
83-
if (&__sanitizer_malloc_hook) \
84-
__sanitizer_malloc_hook(ptr, size); \
85-
RunMallocHooks(ptr, size); \
86-
} while (false)
87-
88-
#define MEMPROF_FREE_HOOK(ptr) \
89-
do { \
90-
if (&__sanitizer_free_hook) \
91-
__sanitizer_free_hook(ptr); \
92-
RunFreeHooks(ptr); \
93-
} while (false)
94-
9579
extern int memprof_inited;
9680
extern int memprof_timestamp_inited;
9781
extern int memprof_init_done;

compiler-rt/lib/msan/msan.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -375,21 +375,4 @@ void MsanTSDDtor(void *tsd);
375375

376376
} // namespace __msan
377377

378-
#define MSAN_MALLOC_HOOK(ptr, size) \
379-
do { \
380-
if (&__sanitizer_malloc_hook) { \
381-
UnpoisonParam(2); \
382-
__sanitizer_malloc_hook(ptr, size); \
383-
} \
384-
RunMallocHooks(ptr, size); \
385-
} while (false)
386-
#define MSAN_FREE_HOOK(ptr) \
387-
do { \
388-
if (&__sanitizer_free_hook) { \
389-
UnpoisonParam(1); \
390-
__sanitizer_free_hook(ptr); \
391-
} \
392-
RunFreeHooks(ptr); \
393-
} while (false)
394-
395378
#endif // MSAN_H

compiler-rt/lib/msan/msan_allocator.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,22 @@ static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
194194
__msan_set_origin(allocated, size, o.raw_id());
195195
}
196196
}
197-
MSAN_MALLOC_HOOK(allocated, size);
197+
if (&__sanitizer_malloc_hook) {
198+
UnpoisonParam(2);
199+
__sanitizer_malloc_hook(allocated, size);
200+
}
201+
RunMallocHooks(allocated, size);
198202
return allocated;
199203
}
200204

201205
void MsanDeallocate(StackTrace *stack, void *p) {
202206
CHECK(p);
203-
MSAN_FREE_HOOK(p);
207+
if (&__sanitizer_free_hook) {
208+
UnpoisonParam(1);
209+
__sanitizer_free_hook(p);
210+
}
211+
RunFreeHooks(p);
212+
204213
Metadata *meta = reinterpret_cast<Metadata *>(allocator.GetMetaData(p));
205214
uptr size = meta->requested_size;
206215
meta->requested_size = 0;

0 commit comments

Comments
 (0)