Skip to content

Commit 02a3004

Browse files
authored
[compiler-rt][rtsan] preadv(64)/pwritev(64) interception. (#124115)
1 parent fd174f0 commit 02a3004

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,50 @@ INTERCEPTOR(ssize_t, pwrite64, int fd, const void *buf, size_t count,
520520
#define RTSAN_MAYBE_INTERCEPT_PWRITE64
521521
#endif // SANITIZER_INTERCEPT_PWRITE64
522522

523+
#if SANITIZER_INTERCEPT_PREADV
524+
INTERCEPTOR(ssize_t, preadv, int fd, const struct iovec *iov, int count,
525+
off_t offset) {
526+
__rtsan_notify_intercepted_call("preadv");
527+
return REAL(preadv)(fd, iov, count, offset);
528+
}
529+
#define RTSAN_MAYBE_INTERCEPT_PREADV INTERCEPT_FUNCTION(preadv)
530+
#else
531+
#define RTSAN_MAYBE_INTERCEPT_PREADV
532+
#endif
533+
534+
#if SANITIZER_INTERCEPT_PREADV64
535+
INTERCEPTOR(ssize_t, preadv64, int fd, const struct iovec *iov, int count,
536+
off_t offset) {
537+
__rtsan_notify_intercepted_call("preadv64");
538+
return REAL(preadv)(fd, iov, count, offset);
539+
}
540+
#define RTSAN_MAYBE_INTERCEPT_PREADV64 INTERCEPT_FUNCTION(preadv64)
541+
#else
542+
#define RTSAN_MAYBE_INTERCEPT_PREADV64
543+
#endif
544+
545+
#if SANITIZER_INTERCEPT_PWRITEV
546+
INTERCEPTOR(ssize_t, pwritev, int fd, const struct iovec *iov, int count,
547+
off_t offset) {
548+
__rtsan_notify_intercepted_call("pwritev");
549+
return REAL(pwritev)(fd, iov, count, offset);
550+
}
551+
#define RTSAN_MAYBE_INTERCEPT_PWRITEV INTERCEPT_FUNCTION(pwritev)
552+
#else
553+
#define RTSAN_MAYBE_INTERCEPT_PWRITEV
554+
#endif
555+
556+
#if SANITIZER_INTERCEPT_PWRITEV64
557+
INTERCEPTOR(ssize_t, pwritev64, int fd, const struct iovec *iov, int count,
558+
off_t offset) {
559+
__rtsan_notify_intercepted_call("pwritev64");
560+
return REAL(pwritev64)(fd, iov, count, offset);
561+
}
562+
#define RTSAN_MAYBE_INTERCEPT_PWRITEV64 INTERCEPT_FUNCTION(pwritev64)
563+
#else
564+
#define RTSAN_MAYBE_INTERCEPT_PWRITEV64
565+
#endif
566+
523567
INTERCEPTOR(ssize_t, writev, int fd, const struct iovec *iov, int iovcnt) {
524568
__rtsan_notify_intercepted_call("writev");
525569
return REAL(writev)(fd, iov, iovcnt);
@@ -1265,9 +1309,13 @@ void __rtsan::InitializeInterceptors() {
12651309
INTERCEPT_FUNCTION(write);
12661310
INTERCEPT_FUNCTION(pread);
12671311
RTSAN_MAYBE_INTERCEPT_PREAD64;
1312+
RTSAN_MAYBE_INTERCEPT_PREADV;
1313+
RTSAN_MAYBE_INTERCEPT_PREADV64;
12681314
INTERCEPT_FUNCTION(readv);
12691315
INTERCEPT_FUNCTION(pwrite);
12701316
RTSAN_MAYBE_INTERCEPT_PWRITE64;
1317+
RTSAN_MAYBE_INTERCEPT_PWRITEV;
1318+
RTSAN_MAYBE_INTERCEPT_PWRITEV64;
12711319
INTERCEPT_FUNCTION(writev);
12721320
INTERCEPT_FUNCTION(fwrite);
12731321
INTERCEPT_FUNCTION(fclose);

compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -879,6 +879,30 @@ TEST_F(RtsanOpenedFileTest, PreadDiesWhenRealtime) {
879879
ExpectNonRealtimeSurvival(Func);
880880
}
881881

882+
#if SANITIZER_INTERCEPT_PREADV
883+
TEST_F(RtsanOpenedFileTest, PreadvDiesWhenRealtime) {
884+
auto Func = [this]() {
885+
char c{};
886+
iovec iov{&c, sizeof(c)};
887+
preadv(GetOpenFd(), &iov, 1, 0);
888+
};
889+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("preadv"));
890+
ExpectNonRealtimeSurvival(Func);
891+
}
892+
#endif
893+
894+
#if SANITIZER_INTERCEPT_PWRITEV
895+
TEST_F(RtsanOpenedFileTest, PwritevDiesWhenRealtime) {
896+
auto Func = [this]() {
897+
char c{};
898+
iovec iov{&c, sizeof(c)};
899+
pwritev(GetOpenFd(), &iov, 1, 0);
900+
};
901+
ExpectRealtimeDeath(Func, MAYBE_APPEND_64("pwritev"));
902+
ExpectNonRealtimeSurvival(Func);
903+
}
904+
#endif
905+
882906
TEST_F(RtsanOpenedFileTest, ReadvDiesWhenRealtime) {
883907
auto Func = [this]() {
884908
char c{};

0 commit comments

Comments
 (0)