[compiler-rt] 02a3004 - [compiler-rt][rtsan] preadv(64)/pwritev(64) interception. (#124115)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 23 21:07:36 PST 2025
Author: David CARLIER
Date: 2025-01-24T05:07:33Z
New Revision: 02a30049926bac042a7ee33fa587a4446c9c816f
URL: https://github.com/llvm/llvm-project/commit/02a30049926bac042a7ee33fa587a4446c9c816f
DIFF: https://github.com/llvm/llvm-project/commit/02a30049926bac042a7ee33fa587a4446c9c816f.diff
LOG: [compiler-rt][rtsan] preadv(64)/pwritev(64) interception. (#124115)
Added:
Modified:
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index a01354781272d5..28369c51e1269f 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -520,6 +520,50 @@ INTERCEPTOR(ssize_t, pwrite64, int fd, const void *buf, size_t count,
#define RTSAN_MAYBE_INTERCEPT_PWRITE64
#endif // SANITIZER_INTERCEPT_PWRITE64
+#if SANITIZER_INTERCEPT_PREADV
+INTERCEPTOR(ssize_t, preadv, int fd, const struct iovec *iov, int count,
+ off_t offset) {
+ __rtsan_notify_intercepted_call("preadv");
+ return REAL(preadv)(fd, iov, count, offset);
+}
+#define RTSAN_MAYBE_INTERCEPT_PREADV INTERCEPT_FUNCTION(preadv)
+#else
+#define RTSAN_MAYBE_INTERCEPT_PREADV
+#endif
+
+#if SANITIZER_INTERCEPT_PREADV64
+INTERCEPTOR(ssize_t, preadv64, int fd, const struct iovec *iov, int count,
+ off_t offset) {
+ __rtsan_notify_intercepted_call("preadv64");
+ return REAL(preadv)(fd, iov, count, offset);
+}
+#define RTSAN_MAYBE_INTERCEPT_PREADV64 INTERCEPT_FUNCTION(preadv64)
+#else
+#define RTSAN_MAYBE_INTERCEPT_PREADV64
+#endif
+
+#if SANITIZER_INTERCEPT_PWRITEV
+INTERCEPTOR(ssize_t, pwritev, int fd, const struct iovec *iov, int count,
+ off_t offset) {
+ __rtsan_notify_intercepted_call("pwritev");
+ return REAL(pwritev)(fd, iov, count, offset);
+}
+#define RTSAN_MAYBE_INTERCEPT_PWRITEV INTERCEPT_FUNCTION(pwritev)
+#else
+#define RTSAN_MAYBE_INTERCEPT_PWRITEV
+#endif
+
+#if SANITIZER_INTERCEPT_PWRITEV64
+INTERCEPTOR(ssize_t, pwritev64, int fd, const struct iovec *iov, int count,
+ off_t offset) {
+ __rtsan_notify_intercepted_call("pwritev64");
+ return REAL(pwritev64)(fd, iov, count, offset);
+}
+#define RTSAN_MAYBE_INTERCEPT_PWRITEV64 INTERCEPT_FUNCTION(pwritev64)
+#else
+#define RTSAN_MAYBE_INTERCEPT_PWRITEV64
+#endif
+
INTERCEPTOR(ssize_t, writev, int fd, const struct iovec *iov, int iovcnt) {
__rtsan_notify_intercepted_call("writev");
return REAL(writev)(fd, iov, iovcnt);
@@ -1265,9 +1309,13 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(write);
INTERCEPT_FUNCTION(pread);
RTSAN_MAYBE_INTERCEPT_PREAD64;
+ RTSAN_MAYBE_INTERCEPT_PREADV;
+ RTSAN_MAYBE_INTERCEPT_PREADV64;
INTERCEPT_FUNCTION(readv);
INTERCEPT_FUNCTION(pwrite);
RTSAN_MAYBE_INTERCEPT_PWRITE64;
+ RTSAN_MAYBE_INTERCEPT_PWRITEV;
+ RTSAN_MAYBE_INTERCEPT_PWRITEV64;
INTERCEPT_FUNCTION(writev);
INTERCEPT_FUNCTION(fwrite);
INTERCEPT_FUNCTION(fclose);
diff --git a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
index 981766c85f965e..cd62a3c57c6f9c 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -879,6 +879,30 @@ TEST_F(RtsanOpenedFileTest, PreadDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+#if SANITIZER_INTERCEPT_PREADV
+TEST_F(RtsanOpenedFileTest, PreadvDiesWhenRealtime) {
+ auto Func = [this]() {
+ char c{};
+ iovec iov{&c, sizeof(c)};
+ preadv(GetOpenFd(), &iov, 1, 0);
+ };
+ ExpectRealtimeDeath(Func, MAYBE_APPEND_64("preadv"));
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
+#if SANITIZER_INTERCEPT_PWRITEV
+TEST_F(RtsanOpenedFileTest, PwritevDiesWhenRealtime) {
+ auto Func = [this]() {
+ char c{};
+ iovec iov{&c, sizeof(c)};
+ pwritev(GetOpenFd(), &iov, 1, 0);
+ };
+ ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pwritev"));
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
TEST_F(RtsanOpenedFileTest, ReadvDiesWhenRealtime) {
auto Func = [this]() {
char c{};
More information about the llvm-commits
mailing list