diff options
Diffstat (limited to 'compiler-rt/lib/asan')
| -rw-r--r-- | compiler-rt/lib/asan/asan_intercepted_functions.h | 9 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_interceptors.cc | 33 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/tests/asan_test.cc | 46 |
3 files changed, 32 insertions, 56 deletions
diff --git a/compiler-rt/lib/asan/asan_intercepted_functions.h b/compiler-rt/lib/asan/asan_intercepted_functions.h index 1d82940530e..25eec8b5d14 100644 --- a/compiler-rt/lib/asan/asan_intercepted_functions.h +++ b/compiler-rt/lib/asan/asan_intercepted_functions.h @@ -42,10 +42,8 @@ using __sanitizer::uptr; #if defined(__linux__) # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 1 -# define ASAN_INTERCEPT_PRCTL 1 #else # define ASAN_USE_ALIAS_ATTRIBUTE_FOR_INDEX 0 -# define ASAN_INTERCEPT_PRCTL 0 #endif #if !defined(__APPLE__) @@ -167,6 +165,13 @@ DECLARE_FUNCTION_AND_WRAPPER(SSIZE_T, pread64, int fd, void *buf, SIZE_T count, OFF64_T offset); # endif +#if SANITIZER_INTERCEPT_WRITE +DECLARE_FUNCTION_AND_WRAPPER(SSIZE_T, write, int fd, void *ptr, SIZE_T count); +#endif +#if SANITIZER_INTERCEPT_PWRITE +DECLARE_FUNCTION_AND_WRAPPER(SSIZE_T, pwrite, int fd, void *ptr, SIZE_T count); +#endif + # if ASAN_INTERCEPT_MLOCKX // mlock/munlock DECLARE_FUNCTION_AND_WRAPPER(int, mlock, const void *addr, SIZE_T len); diff --git a/compiler-rt/lib/asan/asan_interceptors.cc b/compiler-rt/lib/asan/asan_interceptors.cc index ef0fde340dd..b858fd48f91 100644 --- a/compiler-rt/lib/asan/asan_interceptors.cc +++ b/compiler-rt/lib/asan/asan_interceptors.cc @@ -75,6 +75,12 @@ static inline uptr MaybeRealStrnlen(const char *s, uptr maxlen) { return internal_strnlen(s, maxlen); } +void SetThreadName(const char *name) { + AsanThread *t = asanThreadRegistry().GetCurrent(); + if (t) + t->summary()->set_name(name); +} + } // namespace __asan // ---------------------- Wrappers ---------------- {{{1 @@ -83,8 +89,9 @@ using namespace __asan; // NOLINT #define COMMON_INTERCEPTOR_WRITE_RANGE(ptr, size) ASAN_WRITE_RANGE(ptr, size) #define COMMON_INTERCEPTOR_READ_RANGE(ptr, size) ASAN_READ_RANGE(ptr, size) #define COMMON_INTERCEPTOR_ENTER(func, ...) ENSURE_ASAN_INITED() -#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) -#define COMMON_INTERCEPTOR_FD_RELEASE(fd) +#define COMMON_INTERCEPTOR_FD_ACQUIRE(fd) do { } while (false) +#define COMMON_INTERCEPTOR_FD_RELEASE(fd) do { } while (false) +#define COMMON_INTERCEPTOR_SET_THREAD_NAME(name) SetThreadName(name) #include "sanitizer_common/sanitizer_common_interceptors.h" static thread_return_t THREAD_CALLING_CONV asan_thread_start(void *arg) { @@ -180,25 +187,6 @@ INTERCEPTOR(void, siglongjmp, void *env, int val) { } #endif -#if ASAN_INTERCEPT_PRCTL -#define PR_SET_NAME 15 -INTERCEPTOR(int, prctl, int option, - unsigned long arg2, unsigned long arg3, // NOLINT - unsigned long arg4, unsigned long arg5) { // NOLINT - int res = REAL(prctl(option, arg2, arg3, arg4, arg5)); - if (option == PR_SET_NAME) { - AsanThread *t = asanThreadRegistry().GetCurrent(); - if (t) { - char buff[17]; - internal_strncpy(buff, (char*)arg2, 16); - buff[16] = 0; - t->summary()->set_name(buff); - } - } - return res; -} -#endif - #if ASAN_INTERCEPT___CXA_THROW INTERCEPTOR(void, __cxa_throw, void *a, void *b, void *c) { CHECK(REAL(__cxa_throw)); @@ -745,9 +733,6 @@ void InitializeAsanInterceptors() { #if ASAN_INTERCEPT_SIGLONGJMP ASAN_INTERCEPT_FUNC(siglongjmp); #endif -#if ASAN_INTERCEPT_PRCTL - ASAN_INTERCEPT_FUNC(prctl); -#endif // Intercept exception handling functions. #if ASAN_INTERCEPT___CXA_THROW diff --git a/compiler-rt/lib/asan/tests/asan_test.cc b/compiler-rt/lib/asan/tests/asan_test.cc index f9abc31ae51..ef7846dbc0d 100644 --- a/compiler-rt/lib/asan/tests/asan_test.cc +++ b/compiler-rt/lib/asan/tests/asan_test.cc @@ -1667,44 +1667,30 @@ TEST(AddressSanitizer, DISABLED_MemIntrinsicCallByPointerTest) { CallMemTransferByPointer(&memmove); } -#if defined(__linux__) && !defined(ANDROID) && !defined(__ANDROID__) +#if defined(__linux__) && !defined(ANDROID) +#define READ_TEST(READ_N_BYTES) \ + char *x = new char[10]; \ + int fd = open("/proc/self/stat", O_RDONLY); \ + ASSERT_GT(fd, 0); \ + EXPECT_DEATH(READ_N_BYTES, \ + ASAN_PCRE_DOTALL \ + "AddressSanitizer: heap-buffer-overflow" \ + ".* is located 0 bytes to the right of 10-byte region"); \ + close(fd); \ + delete [] x; \ + TEST(AddressSanitizer, pread) { - char *x = new char[10]; - int fd = open("/proc/self/stat", O_RDONLY); - ASSERT_GT(fd, 0); - EXPECT_DEATH(pread(fd, x, 15, 0), - ASAN_PCRE_DOTALL - "AddressSanitizer: heap-buffer-overflow" - ".* is located 0 bytes to the right of 10-byte region"); - close(fd); - delete [] x; + READ_TEST(pread(fd, x, 15, 0)); } TEST(AddressSanitizer, pread64) { - char *x = new char[10]; - int fd = open("/proc/self/stat", O_RDONLY); - ASSERT_GT(fd, 0); - EXPECT_DEATH(pread64(fd, x, 15, 0), - ASAN_PCRE_DOTALL - "AddressSanitizer: heap-buffer-overflow" - ".* is located 0 bytes to the right of 10-byte region"); - close(fd); - delete [] x; + READ_TEST(pread64(fd, x, 15, 0)); } TEST(AddressSanitizer, read) { - char *x = new char[10]; - int fd = open("/proc/self/stat", O_RDONLY); - ASSERT_GT(fd, 0); - EXPECT_DEATH(read(fd, x, 15), - ASAN_PCRE_DOTALL - "AddressSanitizer: heap-buffer-overflow" - ".* is located 0 bytes to the right of 10-byte region"); - close(fd); - delete [] x; + READ_TEST(read(fd, x, 15)); } - -#endif // defined(__linux__) && !defined(ANDROID) && !defined(__ANDROID__) +#endif // defined(__linux__) && !defined(ANDROID) // This test case fails // Clang optimizes memcpy/memset calls which lead to unaligned access |

