diff --git a/compiler-rt/lib/asan/asan_intercepted_functions.h b/compiler-rt/lib/asan/asan_intercepted_functions.h index 06dfdb6f8cc5..2bd069c27efe 100644 --- a/compiler-rt/lib/asan/asan_intercepted_functions.h +++ b/compiler-rt/lib/asan/asan_intercepted_functions.h @@ -153,11 +153,16 @@ DECLARE_FUNCTION_AND_WRAPPER(long long, atoll, const char *nptr); // NOLINT DECLARE_FUNCTION_AND_WRAPPER(long long, strtoll, const char *nptr, char **endptr, int base); // NOLINT # endif +// unistd.h DECLARE_FUNCTION_AND_WRAPPER(SSIZE_T, read, int fd, void *buf, SIZE_T count); +# if SANITIZER_INTERCEPT_PREAD DECLARE_FUNCTION_AND_WRAPPER(SSIZE_T, pread, int fd, void *buf, SIZE_T count, OFF_T offset); +# endif +# if SANITIZER_INTERCEPT_PREAD64 DECLARE_FUNCTION_AND_WRAPPER(SSIZE_T, pread64, int fd, void *buf, SIZE_T count, OFF64_T offset); +# endif # if ASAN_INTERCEPT_MLOCKX // mlock/munlock diff --git a/compiler-rt/lib/asan/tests/asan_test.cc b/compiler-rt/lib/asan/tests/asan_test.cc index 75a7f494f885..3698ff007ecc 100644 --- a/compiler-rt/lib/asan/tests/asan_test.cc +++ b/compiler-rt/lib/asan/tests/asan_test.cc @@ -1606,7 +1606,7 @@ TEST(AddressSanitizer, pread) { delete x; } -#ifndef ANDROID +# if !defined(ANDROID) && !defined(__ANDROID__) TEST(AddressSanitizer, pread64) { char *x = new char[10]; int fd = open("/proc/self/stat", O_RDONLY); @@ -1618,7 +1618,7 @@ TEST(AddressSanitizer, pread64) { close(fd); delete x; } -#endif // ANDROID +# endif // !defined(ANDROID) && !defined(__ANDROID__) TEST(AddressSanitizer, read) { char *x = new char[10]; diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h index a7f433c8465c..10a9ded8ca50 100644 --- a/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h +++ b/compiler-rt/lib/sanitizer_common/sanitizer_common_interceptors.h @@ -22,6 +22,12 @@ #include "interception/interception.h" +#if !defined(_WIN32) +# define SANITIZER_INTERCEPT_PREAD 1 +#else +# define SANITIZER_INTERCEPT_PREAD 0 +#endif + #if defined(__linux__) && !defined(ANDROID) # define SANITIZER_INTERCEPT_PREAD64 1 #else @@ -36,6 +42,7 @@ INTERCEPTOR(SSIZE_T, read, int fd, void *ptr, SIZE_T count) { return res; } +#if SANITIZER_INTERCEPT_PREAD INTERCEPTOR(SSIZE_T, pread, int fd, void *ptr, SIZE_T count, OFF_T offset) { COMMON_INTERCEPTOR_ENTER(pread, fd, ptr, count, offset); SSIZE_T res = REAL(pread)(fd, ptr, count, offset); @@ -43,6 +50,7 @@ INTERCEPTOR(SSIZE_T, pread, int fd, void *ptr, SIZE_T count, OFF_T offset) { COMMON_INTERCEPTOR_WRITE_RANGE(ptr, res); return res; } +#endif #if SANITIZER_INTERCEPT_PREAD64 INTERCEPTOR(SSIZE_T, pread64, int fd, void *ptr, SIZE_T count, OFF64_T offset) { @@ -54,15 +62,21 @@ INTERCEPTOR(SSIZE_T, pread64, int fd, void *ptr, SIZE_T count, OFF64_T offset) { } #endif -#if SANITIZER_INTERCEPT_PREAD64 -#define INIT_PREAD64 CHECK(INTERCEPT_FUNCTION(pread64)) +#if SANITIZER_INTERCEPT_PREAD +# define INIT_PREAD CHECK(INTERCEPT_FUNCTION(pread)) #else -#define INIT_PREAD64 +# define INIT_PREAD +#endif + +#if SANITIZER_INTERCEPT_PREAD64 +# define INIT_PREAD64 CHECK(INTERCEPT_FUNCTION(pread64)) +#else +# define INIT_PREAD64 #endif #define SANITIZER_COMMON_INTERCEPTORS_INIT \ CHECK(INTERCEPT_FUNCTION(read)); \ - CHECK(INTERCEPT_FUNCTION(pread)); \ + INIT_PREAD; \ INIT_PREAD64; \ #endif // SANITIZER_COMMON_INTERCEPTORS_H