Skip to content

Commit 66b8eb0

Browse files
committed
[rtsan] Add pipe, mkfifo interceptors
1 parent 944478d commit 66b8eb0

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,26 @@ INTERCEPTOR(int, kevent64, int kq, const struct kevent64_s *changelist,
736736
#define RTSAN_MAYBE_INTERCEPT_KEVENT64
737737
#endif // SANITIZER_INTERCEPT_KQUEUE
738738

739+
INTERCEPTOR(int, pipe, int pipefd[2]) {
740+
__rtsan_notify_intercepted_call("pipe");
741+
return REAL(pipe)(pipefd);
742+
}
743+
744+
INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) {
745+
__rtsan_notify_intercepted_call("mkfifo");
746+
return REAL(mkfifo)(pathname, mode);
747+
}
748+
749+
// see comment above about -Wunguarded-availability-new
750+
// and why we disable it here
751+
#pragma clang diagnostic push
752+
#pragma clang diagnostic ignored "-Wunguarded-availability-new"
753+
INTERCEPTOR(int, mkfifoat, int dirfd, const char *pathname, mode_t mode) {
754+
__rtsan_notify_intercepted_call("mkfifoat");
755+
return REAL(mkfifoat)(dirfd, pathname, mode);
756+
}
757+
#pragma clang diagnostic pop
758+
739759
// Preinit
740760
void __rtsan::InitializeInterceptors() {
741761
INTERCEPT_FUNCTION(calloc);
@@ -836,6 +856,10 @@ void __rtsan::InitializeInterceptors() {
836856
RTSAN_MAYBE_INTERCEPT_KQUEUE;
837857
RTSAN_MAYBE_INTERCEPT_KEVENT;
838858
RTSAN_MAYBE_INTERCEPT_KEVENT64;
859+
860+
INTERCEPT_FUNCTION(pipe);
861+
INTERCEPT_FUNCTION(mkfifo);
862+
INTERCEPT_FUNCTION(mkfifoat);
839863
}
840864

841865
#endif // SANITIZER_POSIX

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -965,4 +965,32 @@ TEST_F(KqueueTest, Kevent64DiesWhenRealtime) {
965965
}
966966
#endif // SANITIZER_INTERCEPT_KQUEUE
967967

968+
TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) {
969+
auto Func = []() { mkfifo("/tmp/rtsan_test_fifo", 0); };
970+
ExpectRealtimeDeath(Func, "mkfifo");
971+
ExpectNonRealtimeSurvival(Func);
972+
}
973+
974+
#if __has_builtin(__builtin_available) && SANITIZER_APPLE
975+
#define MKFIFOAT_AVAILABLE() (__builtin_available(macOS 10.13, *))
976+
#else
977+
// We are going to assume this is true until we hit systems where it isn't
978+
#define MKFIFOAT_AVAILABLE() (true)
979+
#endif
980+
981+
TEST(TestRtsanInterceptors, MkfifoatDiesWhenRealtime) {
982+
if (MKFIFOAT_AVAILABLE()) {
983+
auto Func = []() { mkfifoat(0, "/tmp/rtsan_test_fifo", 0); };
984+
ExpectRealtimeDeath(Func, "mkfifoat");
985+
ExpectNonRealtimeSurvival(Func);
986+
}
987+
}
988+
989+
TEST(TestRtsanInterceptors, PipeDiesWhenRealtime) {
990+
int fds[2];
991+
auto Func = [&fds]() { pipe(fds); };
992+
ExpectRealtimeDeath(Func, "pipe");
993+
ExpectNonRealtimeSurvival(Func);
994+
}
995+
968996
#endif // SANITIZER_POSIX

0 commit comments

Comments
 (0)