Skip to content

Commit eef39f4

Browse files
authored
[NFC][asan] Inline ENSURE_ASAN_INITED macro (llvm#74174)
1 parent b83289b commit eef39f4

File tree

4 files changed

+20
-19
lines changed

4 files changed

+20
-19
lines changed

compiler-rt/lib/asan/asan_interceptors.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,10 @@ static int munmap_interceptor(Munmap real_munmap, void *addr, SIZE_T length) {
196196
__lsan::ScopedInterceptorDisabler disabler
197197
#endif
198198

199-
# define SIGNAL_INTERCEPTOR_ENTER() ENSURE_ASAN_INITED()
199+
# define SIGNAL_INTERCEPTOR_ENTER() \
200+
do { \
201+
AsanInitFromRtl(); \
202+
} while (false)
200203

201204
# include "sanitizer_common/sanitizer_common_interceptors.inc"
202205
# include "sanitizer_common/sanitizer_signal_interceptors.inc"
@@ -496,7 +499,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
496499
INTERCEPTOR(char *, strcat, char *to, const char *from) {
497500
void *ctx;
498501
ASAN_INTERCEPTOR_ENTER(ctx, strcat);
499-
ENSURE_ASAN_INITED();
502+
AsanInitFromRtl();
500503
if (flags()->replace_str) {
501504
uptr from_length = internal_strlen(from);
502505
ASAN_READ_RANGE(ctx, from, from_length + 1);
@@ -517,7 +520,7 @@ DEFINE_REAL(char*, index, const char *string, int c)
517520
INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) {
518521
void *ctx;
519522
ASAN_INTERCEPTOR_ENTER(ctx, strncat);
520-
ENSURE_ASAN_INITED();
523+
AsanInitFromRtl();
521524
if (flags()->replace_str) {
522525
uptr from_length = MaybeRealStrnlen(from, size);
523526
uptr copy_length = Min(size, from_length + 1);
@@ -594,7 +597,7 @@ INTERCEPTOR(char*, __strdup, const char *s) {
594597
INTERCEPTOR(char*, strncpy, char *to, const char *from, uptr size) {
595598
void *ctx;
596599
ASAN_INTERCEPTOR_ENTER(ctx, strncpy);
597-
ENSURE_ASAN_INITED();
600+
AsanInitFromRtl();
598601
if (flags()->replace_str) {
599602
uptr from_size = Min(size, MaybeRealStrnlen(from, size) + 1);
600603
CHECK_RANGES_OVERLAP("strncpy", to, from_size, from, from_size);
@@ -620,7 +623,7 @@ static ALWAYS_INLINE auto StrtolImpl(void *ctx, Fn real, const char *nptr,
620623
INTERCEPTOR(ret_type, func, const char *nptr, char **endptr, int base) { \
621624
void *ctx; \
622625
ASAN_INTERCEPTOR_ENTER(ctx, func); \
623-
ENSURE_ASAN_INITED(); \
626+
AsanInitFromRtl(); \
624627
return StrtolImpl(ctx, REAL(func), nptr, endptr, base); \
625628
}
626629

@@ -637,7 +640,7 @@ INTERCEPTOR(int, atoi, const char *nptr) {
637640
ASAN_INTERCEPTOR_ENTER(ctx, atoi);
638641
if (SANITIZER_APPLE && UNLIKELY(!AsanInited()))
639642
return REAL(atoi)(nptr);
640-
ENSURE_ASAN_INITED();
643+
AsanInitFromRtl();
641644
if (!flags()->replace_str) {
642645
return REAL(atoi)(nptr);
643646
}
@@ -657,7 +660,7 @@ INTERCEPTOR(long, atol, const char *nptr) {
657660
ASAN_INTERCEPTOR_ENTER(ctx, atol);
658661
if (SANITIZER_APPLE && UNLIKELY(!AsanInited()))
659662
return REAL(atol)(nptr);
660-
ENSURE_ASAN_INITED();
663+
AsanInitFromRtl();
661664
if (!flags()->replace_str) {
662665
return REAL(atol)(nptr);
663666
}
@@ -671,7 +674,7 @@ INTERCEPTOR(long, atol, const char *nptr) {
671674
INTERCEPTOR(long long, atoll, const char *nptr) {
672675
void *ctx;
673676
ASAN_INTERCEPTOR_ENTER(ctx, atoll);
674-
ENSURE_ASAN_INITED();
677+
AsanInitFromRtl();
675678
if (!flags()->replace_str) {
676679
return REAL(atoll)(nptr);
677680
}
@@ -694,8 +697,8 @@ INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
694697
void *dso_handle) {
695698
if (SANITIZER_APPLE && UNLIKELY(!AsanInited()))
696699
return REAL(__cxa_atexit)(func, arg, dso_handle);
697-
ENSURE_ASAN_INITED();
698-
#if CAN_SANITIZE_LEAKS
700+
AsanInitFromRtl();
701+
# if CAN_SANITIZE_LEAKS
699702
__lsan::ScopedInterceptorDisabler disabler;
700703
#endif
701704
int res = REAL(__cxa_atexit)(func, arg, dso_handle);
@@ -706,8 +709,8 @@ INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
706709

707710
#if ASAN_INTERCEPT_ATEXIT
708711
INTERCEPTOR(int, atexit, void (*func)()) {
709-
ENSURE_ASAN_INITED();
710-
#if CAN_SANITIZE_LEAKS
712+
AsanInitFromRtl();
713+
# if CAN_SANITIZE_LEAKS
711714
__lsan::ScopedInterceptorDisabler disabler;
712715
#endif
713716
// Avoid calling real atexit as it is unreachable on at least on Linux.

compiler-rt/lib/asan/asan_interceptors.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ namespace __asan {
2424
void InitializeAsanInterceptors();
2525
void InitializePlatformInterceptors();
2626

27-
#define ENSURE_ASAN_INITED() \
28-
do { \
29-
AsanInitFromRtl(); \
30-
} while (0)
31-
3227
} // namespace __asan
3328

3429
// There is no general interception at all on Fuchsia.

compiler-rt/lib/asan/asan_malloc_linux.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ INTERCEPTOR(void*, realloc, void *ptr, uptr size) {
8585

8686
#if SANITIZER_INTERCEPT_REALLOCARRAY
8787
INTERCEPTOR(void*, reallocarray, void *ptr, uptr nmemb, uptr size) {
88-
ENSURE_ASAN_INITED();
88+
AsanInitFromRtl();
8989
GET_STACK_TRACE_MALLOC;
9090
return asan_reallocarray(ptr, nmemb, size, &stack);
9191
}

compiler-rt/lib/asan/asan_malloc_mac.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,10 @@
2222

2323
using namespace __asan;
2424
#define COMMON_MALLOC_ZONE_NAME "asan"
25-
#define COMMON_MALLOC_ENTER() ENSURE_ASAN_INITED()
25+
# define COMMON_MALLOC_ENTER() \
26+
do { \
27+
AsanInitFromRtl(); \
28+
} while (false)
2629
# define COMMON_MALLOC_SANITIZER_INITIALIZED AsanInited()
2730
# define COMMON_MALLOC_FORCE_LOCK() asan_mz_force_lock()
2831
# define COMMON_MALLOC_FORCE_UNLOCK() asan_mz_force_unlock()

0 commit comments

Comments
 (0)