diff options
-rw-r--r-- | lib/asan/asan_interceptors_memintrinsics.cc | 3 | ||||
-rw-r--r-- | lib/asan/asan_interceptors_memintrinsics.h | 81 | ||||
-rw-r--r-- | lib/msan/msan_interceptors.cc | 6 | ||||
-rw-r--r-- | lib/sanitizer_common/sanitizer_common_interceptors.inc | 62 |
4 files changed, 65 insertions, 87 deletions
diff --git a/lib/asan/asan_interceptors_memintrinsics.cc b/lib/asan/asan_interceptors_memintrinsics.cc index 349578697..e17f9ba4a 100644 --- a/lib/asan/asan_interceptors_memintrinsics.cc +++ b/lib/asan/asan_interceptors_memintrinsics.cc @@ -20,17 +20,14 @@ using namespace __asan; // NOLINT void *__asan_memcpy(void *to, const void *from, uptr size) { ASAN_MEMCPY_IMPL(nullptr, to, from, size); - return to; } void *__asan_memset(void *block, int c, uptr size) { ASAN_MEMSET_IMPL(nullptr, block, c, size); - return block; } void *__asan_memmove(void *to, const void *from, uptr size) { ASAN_MEMMOVE_IMPL(nullptr, to, from, size); - return to; } #if SANITIZER_FUCHSIA || SANITIZER_RTEMS diff --git a/lib/asan/asan_interceptors_memintrinsics.h b/lib/asan/asan_interceptors_memintrinsics.h index 805736677..1fd65fe24 100644 --- a/lib/asan/asan_interceptors_memintrinsics.h +++ b/lib/asan/asan_interceptors_memintrinsics.h @@ -78,57 +78,46 @@ struct AsanInterceptorContext { // memcpy is called during __asan_init() from the internals of printf(...). // We do not treat memcpy with to==from as a bug. // See http://llvm.org/bugs/show_bug.cgi?id=11763. -#define ASAN_MEMCPY_IMPL(ctx, to, from, size) \ - do { \ - if (UNLIKELY(!asan_inited)) { \ - internal_memcpy(to, from, size); \ - break; \ - } \ - if (asan_init_is_running) { \ - REAL(memcpy)(to, from, size); \ - break; \ - } \ - ENSURE_ASAN_INITED(); \ - if (flags()->replace_intrin) { \ - if (to != from) { \ - CHECK_RANGES_OVERLAP("memcpy", to, size, from, size); \ - } \ - ASAN_READ_RANGE(ctx, from, size); \ - ASAN_WRITE_RANGE(ctx, to, size); \ - } \ - REAL(memcpy)(to, from, size); \ +#define ASAN_MEMCPY_IMPL(ctx, to, from, size) \ + do { \ + if (UNLIKELY(!asan_inited)) return internal_memcpy(to, from, size); \ + if (asan_init_is_running) { \ + return REAL(memcpy)(to, from, size); \ + } \ + ENSURE_ASAN_INITED(); \ + if (flags()->replace_intrin) { \ + if (to != from) { \ + CHECK_RANGES_OVERLAP("memcpy", to, size, from, size); \ + } \ + ASAN_READ_RANGE(ctx, from, size); \ + ASAN_WRITE_RANGE(ctx, to, size); \ + } \ + return REAL(memcpy)(to, from, size); \ } while (0) // memset is called inside Printf. -#define ASAN_MEMSET_IMPL(ctx, block, c, size) \ - do { \ - if (UNLIKELY(!asan_inited)) { \ - internal_memset(block, c, size); \ - break; \ - } \ - if (asan_init_is_running) { \ - REAL(memset)(block, c, size); \ - break; \ - } \ - ENSURE_ASAN_INITED(); \ - if (flags()->replace_intrin) { \ - ASAN_WRITE_RANGE(ctx, block, size); \ - } \ - REAL(memset)(block, c, size); \ +#define ASAN_MEMSET_IMPL(ctx, block, c, size) \ + do { \ + if (UNLIKELY(!asan_inited)) return internal_memset(block, c, size); \ + if (asan_init_is_running) { \ + return REAL(memset)(block, c, size); \ + } \ + ENSURE_ASAN_INITED(); \ + if (flags()->replace_intrin) { \ + ASAN_WRITE_RANGE(ctx, block, size); \ + } \ + return REAL(memset)(block, c, size); \ } while (0) -#define ASAN_MEMMOVE_IMPL(ctx, to, from, size) \ - do { \ - if (UNLIKELY(!asan_inited)) { \ - internal_memmove(to, from, size); \ - break; \ - } \ - ENSURE_ASAN_INITED(); \ - if (flags()->replace_intrin) { \ - ASAN_READ_RANGE(ctx, from, size); \ - ASAN_WRITE_RANGE(ctx, to, size); \ - } \ - internal_memmove(to, from, size); \ +#define ASAN_MEMMOVE_IMPL(ctx, to, from, size) \ + do { \ + if (UNLIKELY(!asan_inited)) return internal_memmove(to, from, size); \ + ENSURE_ASAN_INITED(); \ + if (flags()->replace_intrin) { \ + ASAN_READ_RANGE(ctx, from, size); \ + ASAN_WRITE_RANGE(ctx, to, size); \ + } \ + return internal_memmove(to, from, size); \ } while (0) #define ASAN_READ_RANGE(ctx, offset, size) \ diff --git a/lib/msan/msan_interceptors.cc b/lib/msan/msan_interceptors.cc index ab1582fac..58b9c39e3 100644 --- a/lib/msan/msan_interceptors.cc +++ b/lib/msan/msan_interceptors.cc @@ -1311,17 +1311,17 @@ int OnExit() { #define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size) \ { \ (void)ctx; \ - __msan_memset(block, c, size); \ + return __msan_memset(block, c, size); \ } #define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size) \ { \ (void)ctx; \ - __msan_memmove(to, from, size); \ + return __msan_memmove(to, from, size); \ } #define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size) \ { \ (void)ctx; \ - __msan_memcpy(to, from, size); \ + return __msan_memcpy(to, from, size); \ } #define COMMON_INTERCEPTOR_COPY_STRING(ctx, to, from, size) \ diff --git a/lib/sanitizer_common/sanitizer_common_interceptors.inc b/lib/sanitizer_common/sanitizer_common_interceptors.inc index 759247b3b..abe487e83 100644 --- a/lib/sanitizer_common/sanitizer_common_interceptors.inc +++ b/lib/sanitizer_common/sanitizer_common_interceptors.inc @@ -238,48 +238,43 @@ bool PlatformHasDifferentMemcpyAndMemmove(); #ifndef COMMON_INTERCEPTOR_MEMSET_IMPL #define COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, dst, v, size) \ - do { \ - if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { \ - internal_memset(dst, v, size); \ - break; \ - } \ + { \ + if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \ + return internal_memset(dst, v, size); \ COMMON_INTERCEPTOR_ENTER(ctx, memset, dst, v, size); \ if (common_flags()->intercept_intrin) \ COMMON_INTERCEPTOR_WRITE_RANGE(ctx, dst, size); \ - REAL(memset)(dst, v, size); \ - } while (0) + return REAL(memset)(dst, v, size); \ + } #endif #ifndef COMMON_INTERCEPTOR_MEMMOVE_IMPL #define COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, dst, src, size) \ - do { \ - if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { \ - internal_memmove(dst, src, size); \ - break; \ - } \ + { \ + if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) \ + return internal_memmove(dst, src, size); \ 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); \ } \ - REAL(memmove)(dst, src, size); \ - } while (0) + return REAL(memmove)(dst, src, size); \ + } #endif #ifndef COMMON_INTERCEPTOR_MEMCPY_IMPL #define COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, dst, src, size) \ - do { \ + { \ if (COMMON_INTERCEPTOR_NOTHING_IS_INITIALIZED) { \ - internal_memmove(dst, src, size); \ - break; \ + return internal_memmove(dst, src, size); \ } \ 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); \ } \ - REAL(memcpy)(dst, src, size); \ - } while (0) + return REAL(memcpy)(dst, src, size); \ + } #endif #ifndef COMMON_INTERCEPTOR_MMAP_IMPL @@ -776,7 +771,6 @@ INTERCEPTOR(char *, strpbrk, const char *s1, const char *s2) { INTERCEPTOR(void *, memset, void *dst, int v, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, dst, v, size); - return dst; } #define INIT_MEMSET COMMON_INTERCEPT_FUNCTION(memset) @@ -788,7 +782,6 @@ INTERCEPTOR(void *, memset, void *dst, int v, uptr size) { INTERCEPTOR(void *, memmove, void *dst, const void *src, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, dst, src, size); - return dst; } #define INIT_MEMMOVE COMMON_INTERCEPT_FUNCTION(memmove) @@ -809,7 +802,6 @@ INTERCEPTOR(void *, memcpy, void *dst, const void *src, uptr size) { } else { COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, dst, src, size); } - return dst; } #define INIT_MEMCPY \ @@ -5454,63 +5446,63 @@ INTERCEPTOR(int, capset, void *hdrp, const void *datap) { #endif #if SANITIZER_INTERCEPT_AEABI_MEM -INTERCEPTOR(void, __aeabi_memmove, void *to, const void *from, uptr size) { +INTERCEPTOR(void *, __aeabi_memmove, void *to, const void *from, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size); } -INTERCEPTOR(void, __aeabi_memmove4, void *to, const void *from, uptr size) { +INTERCEPTOR(void *, __aeabi_memmove4, void *to, const void *from, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size); } -INTERCEPTOR(void, __aeabi_memmove8, void *to, const void *from, uptr size) { +INTERCEPTOR(void *, __aeabi_memmove8, void *to, const void *from, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMMOVE_IMPL(ctx, to, from, size); } -INTERCEPTOR(void, __aeabi_memcpy, void *to, const void *from, uptr size) { +INTERCEPTOR(void *, __aeabi_memcpy, void *to, const void *from, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size); } -INTERCEPTOR(void, __aeabi_memcpy4, void *to, const void *from, uptr size) { +INTERCEPTOR(void *, __aeabi_memcpy4, void *to, const void *from, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size); } -INTERCEPTOR(void, __aeabi_memcpy8, void *to, const void *from, uptr size) { +INTERCEPTOR(void *, __aeabi_memcpy8, void *to, const void *from, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMCPY_IMPL(ctx, to, from, size); } // Note the argument order. -INTERCEPTOR(void, __aeabi_memset, void *block, uptr size, int c) { +INTERCEPTOR(void *, __aeabi_memset, void *block, uptr size, int c) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size); } -INTERCEPTOR(void, __aeabi_memset4, void *block, uptr size, int c) { +INTERCEPTOR(void *, __aeabi_memset4, void *block, uptr size, int c) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size); } -INTERCEPTOR(void, __aeabi_memset8, void *block, uptr size, int c) { +INTERCEPTOR(void *, __aeabi_memset8, void *block, uptr size, int c) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, c, size); } -INTERCEPTOR(void, __aeabi_memclr, void *block, uptr size) { +INTERCEPTOR(void *, __aeabi_memclr, void *block, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, 0, size); } -INTERCEPTOR(void, __aeabi_memclr4, void *block, uptr size) { +INTERCEPTOR(void *, __aeabi_memclr4, void *block, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, 0, size); } -INTERCEPTOR(void, __aeabi_memclr8, void *block, uptr size) { +INTERCEPTOR(void *, __aeabi_memclr8, void *block, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, 0, size); } @@ -5533,7 +5525,7 @@ INTERCEPTOR(void, __aeabi_memclr8, void *block, uptr size) { #endif // SANITIZER_INTERCEPT_AEABI_MEM #if SANITIZER_INTERCEPT___BZERO -INTERCEPTOR(void, __bzero, void *block, uptr size) { +INTERCEPTOR(void *, __bzero, void *block, uptr size) { void *ctx; COMMON_INTERCEPTOR_MEMSET_IMPL(ctx, block, 0, size); } |