Index: lib/sanitizer_common/sanitizer_common_interceptors.inc =================================================================== --- lib/sanitizer_common/sanitizer_common_interceptors.inc +++ lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -564,58 +564,70 @@ #define INIT_STRPBRK #endif +#define MEMSET_INTERCEPTOR_IMPL(dst, v, size) \ + { \ + if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \ + return internal_memset(dst, v, size); \ + void *ctx; \ + COMMON_INTERCEPTOR_ENTER(ctx, memset, dst, v, size); \ + if (common_flags()->intercept_intrin) \ + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \ + return REAL(memset)(dst, v, size); \ + } + #if SANITIZER_INTERCEPT_MEMSET -INTERCEPTOR(void*, memset, void *dst, int v, uptr size) { - if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) - return internal_memset(dst, v, size); - void *ctx; - COMMON_INTERCEPTOR_ENTER(ctx, memset, dst, v, size); - if (common_flags()->intercept_intrin) - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); - return REAL(memset)(dst, v, size); -} +INTERCEPTOR(void *, memset, void *dst, int v, uptr size) +MEMSET_INTERCEPTOR_IMPL(dst, v, size) #define INIT_MEMSET COMMON_INTERCEPT_FUNCTION(memset) #else #define INIT_MEMSET #endif -#if SANITIZER_INTERCEPT_MEMMOVE -INTERCEPTOR(void*, memmove, void *dst, const void *src, uptr size) { - if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) - return internal_memmove(dst, src, size); - void *ctx; - COMMON_INTERCEPTOR_ENTER(ctx, memmove, dst, src, size); - if (common_flags()->intercept_intrin) { - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); - COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); +#define MEMMOVE_INTERCEPTOR_IMPL(dst, src, size) \ + { \ + if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \ + return internal_memmove(dst, src, size); \ + void *ctx; \ + COMMON_INTERCEPTOR_ENTER(ctx, memmove, dst, src, size); \ + if (common_flags()->intercept_intrin) { \ + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \ + COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); \ + } \ + return REAL(memmove)(dst, src, size); \ } - return REAL(memmove)(dst, src, size); -} + +#if SANITIZER_INTERCEPT_MEMMOVE +INTERCEPTOR(void *, memmove, void *dst, const void *src, uptr size) +MEMMOVE_INTERCEPTOR_IMPL(dst, src, size) #define INIT_MEMMOVE COMMON_INTERCEPT_FUNCTION(memmove) #else #define INIT_MEMMOVE #endif -#if SANITIZER_INTERCEPT_MEMCPY -INTERCEPTOR(void*, memcpy, void *dst, const void *src, uptr size) { - if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { - // On OS X, calling internal_memcpy here will cause memory corruptions, - // because memcpy and memmove are actually aliases of the same - // implementation. We need to use internal_memmove here. - return internal_memmove(dst, src, size); - } - void *ctx; - COMMON_INTERCEPTOR_ENTER(ctx, memcpy, dst, src, size); - if (common_flags()->intercept_intrin) { - COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); - COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); +// On OS X, calling internal_memcpy here will cause memory corruptions, +// because memcpy and memmove are actually aliases of the same +// implementation. We need to use internal_memmove here. +// N.B.: If we switch this to internal_ we'll have to use internal_memmove +// due to memcpy being an alias of memmove on OS X. +#define MEMCPY_INTERCEPTOR_IMPL(dst, src, size) \ + { \ + if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { \ + return internal_memmove(dst, src, size); \ + } \ + void *ctx; \ + COMMON_INTERCEPTOR_ENTER(ctx, memcpy, dst, src, size); \ + if (common_flags()->intercept_intrin) { \ + COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \ + COMMON_INTERCEPTOR_READ_RANGE(ctx, src, size); \ + } \ + return REAL(memcpy)(dst, src, size); \ } - // N.B.: If we switch this to internal_ we'll have to use internal_memmove - // due to memcpy being an alias of memmove on OS X. - return REAL(memcpy)(dst, src, size); -} + +#if SANITIZER_INTERCEPT_MEMCPY +INTERCEPTOR(void *, memcpy, void *dst, const void *src, uptr size) +MEMCPY_INTERCEPTOR_IMPL(dst, src, size) #define INIT_MEMCPY COMMON_INTERCEPT_FUNCTION(memcpy) #else @@ -4837,47 +4849,43 @@ #endif #if SANITIZER_INTERCEPT_AEABI_MEM -DECLARE_REAL_AND_INTERCEPTOR(void *, memmove, void *, const void *, uptr) -DECLARE_REAL_AND_INTERCEPTOR(void *, memcpy, void *, const void *, uptr) -DECLARE_REAL_AND_INTERCEPTOR(void *, memset, void *, int, uptr) +INTERCEPTOR(void *, __aeabi_memmove, void *to, const void *from, uptr size) +MEMMOVE_INTERCEPTOR_IMPL(to, from, size) + +INTERCEPTOR(void *, __aeabi_memmove4, void *to, const void *from, uptr size) +MEMMOVE_INTERCEPTOR_IMPL(to, from, size) + +INTERCEPTOR(void *, __aeabi_memmove8, void *to, const void *from, uptr size) +MEMMOVE_INTERCEPTOR_IMPL(to, from, size) + +INTERCEPTOR(void *, __aeabi_memcpy, void *to, const void *from, uptr size) +MEMCPY_INTERCEPTOR_IMPL(to, from, size) + +INTERCEPTOR(void *, __aeabi_memcpy4, void *to, const void *from, uptr size) +MEMCPY_INTERCEPTOR_IMPL(to, from, size) + +INTERCEPTOR(void *, __aeabi_memcpy8, void *to, const void *from, uptr size) +MEMCPY_INTERCEPTOR_IMPL(to, from, size) -INTERCEPTOR(void *, __aeabi_memmove, void *to, const void *from, uptr size) { - return WRAP(memmove)(to, from, size); -} -INTERCEPTOR(void *, __aeabi_memmove4, void *to, const void *from, uptr size) { - return WRAP(memmove)(to, from, size); -} -INTERCEPTOR(void *, __aeabi_memmove8, void *to, const void *from, uptr size) { - return WRAP(memmove)(to, from, size); -} -INTERCEPTOR(void *, __aeabi_memcpy, void *to, const void *from, uptr size) { - return WRAP(memcpy)(to, from, size); -} -INTERCEPTOR(void *, __aeabi_memcpy4, void *to, const void *from, uptr size) { - return WRAP(memcpy)(to, from, size); -} -INTERCEPTOR(void *, __aeabi_memcpy8, void *to, const void *from, uptr size) { - return WRAP(memcpy)(to, from, size); -} // Note the argument order. -INTERCEPTOR(void *, __aeabi_memset, void *block, uptr size, int c) { - return WRAP(memset)(block, c, size); -} -INTERCEPTOR(void *, __aeabi_memset4, void *block, uptr size, int c) { - return WRAP(memset)(block, c, size); -} -INTERCEPTOR(void *, __aeabi_memset8, void *block, uptr size, int c) { - return WRAP(memset)(block, c, size); -} -INTERCEPTOR(void *, __aeabi_memclr, void *block, uptr size) { - return WRAP(memset)(block, 0, size); -} -INTERCEPTOR(void *, __aeabi_memclr4, void *block, uptr size) { - return WRAP(memset)(block, 0, size); -} -INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) { - return WRAP(memset)(block, 0, size); -} +INTERCEPTOR(void *, __aeabi_memset, void *block, uptr size, int c) +MEMSET_INTERCEPTOR_IMPL(block, c, size) + +INTERCEPTOR(void *, __aeabi_memset4, void *block, uptr size, int c) +MEMSET_INTERCEPTOR_IMPL(block, c, size) + +INTERCEPTOR(void *, __aeabi_memset8, void *block, uptr size, int c) +MEMSET_INTERCEPTOR_IMPL(block, c, size) + +INTERCEPTOR(void *, __aeabi_memclr, void *block, uptr size) +MEMSET_INTERCEPTOR_IMPL(block, 0, size) + +INTERCEPTOR(void *, __aeabi_memclr4, void *block, uptr size) +MEMSET_INTERCEPTOR_IMPL(block, 0, size) + +INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) +MEMSET_INTERCEPTOR_IMPL(block, 0, size) + #define INIT_AEABI_MEM \ COMMON_INTERCEPT_FUNCTION(__aeabi_memmove); \ COMMON_INTERCEPT_FUNCTION(__aeabi_memmove4); \ @@ -4896,11 +4904,9 @@ #endif // SANITIZER_INTERCEPT_AEABI_MEM #if SANITIZER_INTERCEPT___BZERO -DECLARE_REAL_AND_INTERCEPTOR(void *, memset, void *, int, uptr); +INTERCEPTOR(void *, __bzero, void *block, uptr size) +MEMSET_INTERCEPTOR_IMPL(block, 0, size) -INTERCEPTOR(void *, __bzero, void *block, uptr size) { - return WRAP(memset)(block, 0, size); -} #define INIT___BZERO COMMON_INTERCEPT_FUNCTION(__bzero); #else #define INIT___BZERO