parent
							
								
									86e2470a5b
								
							
						
					
					
						commit
						b9e31d7fcd
					
				| 
						 | 
					@ -281,7 +281,7 @@ void ReInitializeAllocator() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void *Allocate(uptr size, uptr alignment, StackTrace *stack,
 | 
					static void *Allocate(uptr size, uptr alignment, StackTrace *stack,
 | 
				
			||||||
                      AllocType alloc_type, bool can_fill) {
 | 
					                      AllocType alloc_type, bool can_fill) {
 | 
				
			||||||
  if (!asan_inited)
 | 
					  if (UNLIKELY(!asan_inited))
 | 
				
			||||||
    AsanInitFromRtl();
 | 
					    AsanInitFromRtl();
 | 
				
			||||||
  Flags &fl = *flags();
 | 
					  Flags &fl = *flags();
 | 
				
			||||||
  CHECK(stack);
 | 
					  CHECK(stack);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -119,10 +119,12 @@ DECLARE_REAL_AND_INTERCEPTOR(void, free, void *)
 | 
				
			||||||
#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) ASAN_READ_RANGE(ptr, size)
 | 
					#define COMMON_INTERCEPTOR_READ_RANGE(ctx, ptr, size) ASAN_READ_RANGE(ptr, size)
 | 
				
			||||||
#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                               \
 | 
					#define COMMON_INTERCEPTOR_ENTER(ctx, func, ...)                               \
 | 
				
			||||||
  do {                                                                         \
 | 
					  do {                                                                         \
 | 
				
			||||||
    if (asan_init_is_running) return REAL(func)(__VA_ARGS__);          \
 | 
					    if (asan_init_is_running)                                                  \
 | 
				
			||||||
 | 
					      return REAL(func)(__VA_ARGS__);                                          \
 | 
				
			||||||
    ctx = 0;                                                                   \
 | 
					    ctx = 0;                                                                   \
 | 
				
			||||||
    (void) ctx;                                                                \
 | 
					    (void) ctx;                                                                \
 | 
				
			||||||
    if (SANITIZER_MAC && !asan_inited) return REAL(func)(__VA_ARGS__); \
 | 
					    if (SANITIZER_MAC && UNLIKELY(!asan_inited))                               \
 | 
				
			||||||
 | 
					      return REAL(func)(__VA_ARGS__);                                          \
 | 
				
			||||||
    ENSURE_ASAN_INITED();                                                      \
 | 
					    ENSURE_ASAN_INITED();                                                      \
 | 
				
			||||||
  } while (false)
 | 
					  } while (false)
 | 
				
			||||||
#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
 | 
					#define COMMON_INTERCEPTOR_FD_ACQUIRE(ctx, fd) \
 | 
				
			||||||
| 
						 | 
					@ -328,7 +330,7 @@ static inline int CharCmp(unsigned char c1, unsigned char c2) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
 | 
					INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
 | 
				
			||||||
  if (!asan_inited) return internal_memcmp(a1, a2, size);
 | 
					  if (UNLIKELY(!asan_inited)) return internal_memcmp(a1, a2, size);
 | 
				
			||||||
  ENSURE_ASAN_INITED();
 | 
					  ENSURE_ASAN_INITED();
 | 
				
			||||||
  if (flags()->replace_intrin) {
 | 
					  if (flags()->replace_intrin) {
 | 
				
			||||||
    if (flags()->strict_memcmp) {
 | 
					    if (flags()->strict_memcmp) {
 | 
				
			||||||
| 
						 | 
					@ -356,7 +358,7 @@ INTERCEPTOR(int, memcmp, const void *a1, const void *a2, uptr size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *__asan_memcpy(void *to, const void *from, uptr size) {
 | 
					void *__asan_memcpy(void *to, const void *from, uptr size) {
 | 
				
			||||||
  if (!asan_inited) return internal_memcpy(to, from, size);
 | 
					  if (UNLIKELY(!asan_inited)) return internal_memcpy(to, from, size);
 | 
				
			||||||
  // memcpy is called during __asan_init() from the internals
 | 
					  // memcpy is called during __asan_init() from the internals
 | 
				
			||||||
  // of printf(...).
 | 
					  // of printf(...).
 | 
				
			||||||
  if (asan_init_is_running) {
 | 
					  if (asan_init_is_running) {
 | 
				
			||||||
| 
						 | 
					@ -376,7 +378,7 @@ void *__asan_memcpy(void *to, const void *from, uptr size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *__asan_memset(void *block, int c, uptr size) {
 | 
					void *__asan_memset(void *block, int c, uptr size) {
 | 
				
			||||||
  if (!asan_inited) return internal_memset(block, c, size);
 | 
					  if (UNLIKELY(!asan_inited)) return internal_memset(block, c, size);
 | 
				
			||||||
  // memset is called inside Printf.
 | 
					  // memset is called inside Printf.
 | 
				
			||||||
  if (asan_init_is_running) {
 | 
					  if (asan_init_is_running) {
 | 
				
			||||||
    return REAL(memset)(block, c, size);
 | 
					    return REAL(memset)(block, c, size);
 | 
				
			||||||
| 
						 | 
					@ -389,7 +391,7 @@ void *__asan_memset(void *block, int c, uptr size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *__asan_memmove(void *to, const void *from, uptr size) {
 | 
					void *__asan_memmove(void *to, const void *from, uptr size) {
 | 
				
			||||||
  if (!asan_inited)
 | 
					  if (UNLIKELY(!asan_inited))
 | 
				
			||||||
    return internal_memmove(to, from, size);
 | 
					    return internal_memmove(to, from, size);
 | 
				
			||||||
  ENSURE_ASAN_INITED();
 | 
					  ENSURE_ASAN_INITED();
 | 
				
			||||||
  if (flags()->replace_intrin) {
 | 
					  if (flags()->replace_intrin) {
 | 
				
			||||||
| 
						 | 
					@ -422,7 +424,7 @@ INTERCEPTOR(void*, memset, void *block, int c, uptr size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(char*, strchr, const char *str, int c) {
 | 
					INTERCEPTOR(char*, strchr, const char *str, int c) {
 | 
				
			||||||
  if (!asan_inited) return internal_strchr(str, c);
 | 
					  if (UNLIKELY(!asan_inited)) return internal_strchr(str, c);
 | 
				
			||||||
  // strchr is called inside create_purgeable_zone() when MallocGuardEdges=1 is
 | 
					  // strchr is called inside create_purgeable_zone() when MallocGuardEdges=1 is
 | 
				
			||||||
  // used.
 | 
					  // used.
 | 
				
			||||||
  if (asan_init_is_running) {
 | 
					  if (asan_init_is_running) {
 | 
				
			||||||
| 
						 | 
					@ -491,7 +493,7 @@ INTERCEPTOR(char*, strncat, char *to, const char *from, uptr size) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(char*, strcpy, char *to, const char *from) {  // NOLINT
 | 
					INTERCEPTOR(char*, strcpy, char *to, const char *from) {  // NOLINT
 | 
				
			||||||
#if SANITIZER_MAC
 | 
					#if SANITIZER_MAC
 | 
				
			||||||
  if (!asan_inited) return REAL(strcpy)(to, from);  // NOLINT
 | 
					  if (UNLIKELY(!asan_inited)) return REAL(strcpy)(to, from);  // NOLINT
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  // strcpy is called from malloc_default_purgeable_zone()
 | 
					  // strcpy is called from malloc_default_purgeable_zone()
 | 
				
			||||||
  // in __asan::ReplaceSystemAlloc() on Mac.
 | 
					  // in __asan::ReplaceSystemAlloc() on Mac.
 | 
				
			||||||
| 
						 | 
					@ -510,7 +512,7 @@ INTERCEPTOR(char*, strcpy, char *to, const char *from) {  // NOLINT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#if ASAN_INTERCEPT_STRDUP
 | 
					#if ASAN_INTERCEPT_STRDUP
 | 
				
			||||||
INTERCEPTOR(char*, strdup, const char *s) {
 | 
					INTERCEPTOR(char*, strdup, const char *s) {
 | 
				
			||||||
  if (!asan_inited) return internal_strdup(s);
 | 
					  if (UNLIKELY(!asan_inited)) return internal_strdup(s);
 | 
				
			||||||
  ENSURE_ASAN_INITED();
 | 
					  ENSURE_ASAN_INITED();
 | 
				
			||||||
  uptr length = REAL(strlen)(s);
 | 
					  uptr length = REAL(strlen)(s);
 | 
				
			||||||
  if (flags()->replace_str) {
 | 
					  if (flags()->replace_str) {
 | 
				
			||||||
| 
						 | 
					@ -524,7 +526,7 @@ INTERCEPTOR(char*, strdup, const char *s) {
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(uptr, strlen, const char *s) {
 | 
					INTERCEPTOR(uptr, strlen, const char *s) {
 | 
				
			||||||
  if (!asan_inited) return internal_strlen(s);
 | 
					  if (UNLIKELY(!asan_inited)) return internal_strlen(s);
 | 
				
			||||||
  // strlen is called from malloc_default_purgeable_zone()
 | 
					  // strlen is called from malloc_default_purgeable_zone()
 | 
				
			||||||
  // in __asan::ReplaceSystemAlloc() on Mac.
 | 
					  // in __asan::ReplaceSystemAlloc() on Mac.
 | 
				
			||||||
  if (asan_init_is_running) {
 | 
					  if (asan_init_is_running) {
 | 
				
			||||||
| 
						 | 
					@ -606,7 +608,7 @@ INTERCEPTOR(long, strtol, const char *nptr,  // NOLINT
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(int, atoi, const char *nptr) {
 | 
					INTERCEPTOR(int, atoi, const char *nptr) {
 | 
				
			||||||
#if SANITIZER_MAC
 | 
					#if SANITIZER_MAC
 | 
				
			||||||
  if (!asan_inited) return REAL(atoi)(nptr);
 | 
					  if (UNLIKELY(!asan_inited)) return REAL(atoi)(nptr);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  ENSURE_ASAN_INITED();
 | 
					  ENSURE_ASAN_INITED();
 | 
				
			||||||
  if (!flags()->replace_str) {
 | 
					  if (!flags()->replace_str) {
 | 
				
			||||||
| 
						 | 
					@ -625,7 +627,7 @@ INTERCEPTOR(int, atoi, const char *nptr) {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(long, atol, const char *nptr) {  // NOLINT
 | 
					INTERCEPTOR(long, atol, const char *nptr) {  // NOLINT
 | 
				
			||||||
#if SANITIZER_MAC
 | 
					#if SANITIZER_MAC
 | 
				
			||||||
  if (!asan_inited) return REAL(atol)(nptr);
 | 
					  if (UNLIKELY(!asan_inited)) return REAL(atol)(nptr);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  ENSURE_ASAN_INITED();
 | 
					  ENSURE_ASAN_INITED();
 | 
				
			||||||
  if (!flags()->replace_str) {
 | 
					  if (!flags()->replace_str) {
 | 
				
			||||||
| 
						 | 
					@ -682,7 +684,7 @@ static void AtCxaAtexit(void *unused) {
 | 
				
			||||||
INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
 | 
					INTERCEPTOR(int, __cxa_atexit, void (*func)(void *), void *arg,
 | 
				
			||||||
            void *dso_handle) {
 | 
					            void *dso_handle) {
 | 
				
			||||||
#if SANITIZER_MAC
 | 
					#if SANITIZER_MAC
 | 
				
			||||||
  if (!asan_inited) return REAL(__cxa_atexit)(func, arg, dso_handle);
 | 
					  if (UNLIKELY(!asan_inited)) return REAL(__cxa_atexit)(func, arg, dso_handle);
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
  ENSURE_ASAN_INITED();
 | 
					  ENSURE_ASAN_INITED();
 | 
				
			||||||
  int res = REAL(__cxa_atexit)(func, arg, dso_handle);
 | 
					  int res = REAL(__cxa_atexit)(func, arg, dso_handle);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -96,7 +96,7 @@ void InitializeAsanInterceptors();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define ENSURE_ASAN_INITED() do { \
 | 
					#define ENSURE_ASAN_INITED() do { \
 | 
				
			||||||
  CHECK(!asan_init_is_running); \
 | 
					  CHECK(!asan_init_is_running); \
 | 
				
			||||||
  if (!asan_inited) { \
 | 
					  if (UNLIKELY(!asan_inited)) { \
 | 
				
			||||||
    AsanInitFromRtl(); \
 | 
					    AsanInitFromRtl(); \
 | 
				
			||||||
  } \
 | 
					  } \
 | 
				
			||||||
} while (0)
 | 
					} while (0)
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -77,7 +77,7 @@ INTERCEPTOR(void*, malloc, uptr size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
 | 
					INTERCEPTOR(void*, calloc, uptr nmemb, uptr size) {
 | 
				
			||||||
  if (!asan_inited) {
 | 
					  if (UNLIKELY(!asan_inited)) {
 | 
				
			||||||
    // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
 | 
					    // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
 | 
				
			||||||
    const uptr kCallocPoolSize = 1024;
 | 
					    const uptr kCallocPoolSize = 1024;
 | 
				
			||||||
    static uptr calloc_memory_for_dlsym[kCallocPoolSize];
 | 
					    static uptr calloc_memory_for_dlsym[kCallocPoolSize];
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -159,7 +159,7 @@ size_t mz_size(malloc_zone_t* zone, const void* ptr) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *mz_malloc(malloc_zone_t *zone, size_t size) {
 | 
					void *mz_malloc(malloc_zone_t *zone, size_t size) {
 | 
				
			||||||
  if (!asan_inited) {
 | 
					  if (UNLIKELY(!asan_inited)) {
 | 
				
			||||||
    CHECK(system_malloc_zone);
 | 
					    CHECK(system_malloc_zone);
 | 
				
			||||||
    return malloc_zone_malloc(system_malloc_zone, size);
 | 
					    return malloc_zone_malloc(system_malloc_zone, size);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -168,7 +168,7 @@ void *mz_malloc(malloc_zone_t *zone, size_t size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *mz_calloc(malloc_zone_t *zone, size_t nmemb, size_t size) {
 | 
					void *mz_calloc(malloc_zone_t *zone, size_t nmemb, size_t size) {
 | 
				
			||||||
  if (!asan_inited) {
 | 
					  if (UNLIKELY(!asan_inited)) {
 | 
				
			||||||
    // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
 | 
					    // Hack: dlsym calls calloc before REAL(calloc) is retrieved from dlsym.
 | 
				
			||||||
    const size_t kCallocPoolSize = 1024;
 | 
					    const size_t kCallocPoolSize = 1024;
 | 
				
			||||||
    static uptr calloc_memory_for_dlsym[kCallocPoolSize];
 | 
					    static uptr calloc_memory_for_dlsym[kCallocPoolSize];
 | 
				
			||||||
| 
						 | 
					@ -184,7 +184,7 @@ void *mz_calloc(malloc_zone_t *zone, size_t nmemb, size_t size) {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
void *mz_valloc(malloc_zone_t *zone, size_t size) {
 | 
					void *mz_valloc(malloc_zone_t *zone, size_t size) {
 | 
				
			||||||
  if (!asan_inited) {
 | 
					  if (UNLIKELY(!asan_inited)) {
 | 
				
			||||||
    CHECK(system_malloc_zone);
 | 
					    CHECK(system_malloc_zone);
 | 
				
			||||||
    return malloc_zone_valloc(system_malloc_zone, size);
 | 
					    return malloc_zone_valloc(system_malloc_zone, size);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					@ -242,7 +242,7 @@ void mz_destroy(malloc_zone_t* zone) {
 | 
				
			||||||
#if defined(MAC_OS_X_VERSION_10_6) && \
 | 
					#if defined(MAC_OS_X_VERSION_10_6) && \
 | 
				
			||||||
    MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
 | 
					    MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
 | 
				
			||||||
void *mz_memalign(malloc_zone_t *zone, size_t align, size_t size) {
 | 
					void *mz_memalign(malloc_zone_t *zone, size_t align, size_t size) {
 | 
				
			||||||
  if (!asan_inited) {
 | 
					  if (UNLIKELY(!asan_inited)) {
 | 
				
			||||||
    CHECK(system_malloc_zone);
 | 
					    CHECK(system_malloc_zone);
 | 
				
			||||||
    return malloc_zone_memalign(system_malloc_zone, align, size);
 | 
					    return malloc_zone_memalign(system_malloc_zone, align, size);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -552,7 +552,7 @@ static void PrintAddressSpaceLayout() {
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static void AsanInitInternal() {
 | 
					static void AsanInitInternal() {
 | 
				
			||||||
  if (asan_inited) return;
 | 
					  if (LIKELY(asan_inited)) return;
 | 
				
			||||||
  SanitizerToolName = "AddressSanitizer";
 | 
					  SanitizerToolName = "AddressSanitizer";
 | 
				
			||||||
  CHECK(!asan_init_is_running && "ASan init calls itself!");
 | 
					  CHECK(!asan_init_is_running && "ASan init calls itself!");
 | 
				
			||||||
  asan_init_is_running = true;
 | 
					  asan_init_is_running = true;
 | 
				
			||||||
| 
						 | 
					@ -708,7 +708,7 @@ public:  // NOLINT
 | 
				
			||||||
  AsanInitializer() {
 | 
					  AsanInitializer() {
 | 
				
			||||||
    AsanCheckIncompatibleRT();
 | 
					    AsanCheckIncompatibleRT();
 | 
				
			||||||
    AsanCheckDynamicRTPrereqs();
 | 
					    AsanCheckDynamicRTPrereqs();
 | 
				
			||||||
    if (!asan_inited)
 | 
					    if (UNLIKELY(!asan_inited))
 | 
				
			||||||
      __asan_init();
 | 
					      __asan_init();
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -32,7 +32,7 @@ void GetStackTraceWithPcBpAndContext(StackTrace *stack, uptr max_depth, uptr pc,
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
  AsanThread *t;
 | 
					  AsanThread *t;
 | 
				
			||||||
  stack->size = 0;
 | 
					  stack->size = 0;
 | 
				
			||||||
  if (asan_inited) {
 | 
					  if (LIKELY(asan_inited)) {
 | 
				
			||||||
    if ((t = GetCurrentThread()) && !t->isUnwinding()) {
 | 
					    if ((t = GetCurrentThread()) && !t->isUnwinding()) {
 | 
				
			||||||
      uptr stack_top = t->stack_top();
 | 
					      uptr stack_top = t->stack_top();
 | 
				
			||||||
      uptr stack_bottom = t->stack_bottom();
 | 
					      uptr stack_bottom = t->stack_bottom();
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -199,7 +199,7 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// Check macro
 | 
					// Check macro
 | 
				
			||||||
#define RAW_CHECK_MSG(expr, msg) do { \
 | 
					#define RAW_CHECK_MSG(expr, msg) do { \
 | 
				
			||||||
  if (!(expr)) { \
 | 
					  if (UNLIKELY(!(expr))) { \
 | 
				
			||||||
    RawWrite(msg); \
 | 
					    RawWrite(msg); \
 | 
				
			||||||
    Die(); \
 | 
					    Die(); \
 | 
				
			||||||
  } \
 | 
					  } \
 | 
				
			||||||
| 
						 | 
					@ -211,7 +211,7 @@ void NORETURN CheckFailed(const char *file, int line, const char *cond,
 | 
				
			||||||
  do { \
 | 
					  do { \
 | 
				
			||||||
    __sanitizer::u64 v1 = (u64)(c1); \
 | 
					    __sanitizer::u64 v1 = (u64)(c1); \
 | 
				
			||||||
    __sanitizer::u64 v2 = (u64)(c2); \
 | 
					    __sanitizer::u64 v2 = (u64)(c2); \
 | 
				
			||||||
    if (!(v1 op v2)) \
 | 
					    if (UNLIKELY(!(v1 op v2))) \
 | 
				
			||||||
      __sanitizer::CheckFailed(__FILE__, __LINE__, \
 | 
					      __sanitizer::CheckFailed(__FILE__, __LINE__, \
 | 
				
			||||||
        "(" #c1 ") " #op " (" #c2 ")", v1, v2); \
 | 
					        "(" #c1 ") " #op " (" #c2 ")", v1, v2); \
 | 
				
			||||||
  } while (false) \
 | 
					  } while (false) \
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue