diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index d18ebb57fc2f75..5ef52d72fceb31 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -736,6 +736,26 @@ INTERCEPTOR(int, kevent64, int kq, const struct kevent64_s *changelist, #define RTSAN_MAYBE_INTERCEPT_KEVENT64 #endif // SANITIZER_INTERCEPT_KQUEUE +INTERCEPTOR(int, pipe, int pipefd[2]) { + __rtsan_notify_intercepted_call("pipe"); + return REAL(pipe)(pipefd); +} + +INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) { + __rtsan_notify_intercepted_call("mkfifo"); + return REAL(mkfifo)(pathname, mode); +} + +// see comment above about -Wunguarded-availability-new +// and why we disable it here +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunguarded-availability-new" +INTERCEPTOR(int, mkfifoat, int dirfd, const char *pathname, mode_t mode) { + __rtsan_notify_intercepted_call("mkfifoat"); + return REAL(mkfifoat)(dirfd, pathname, mode); +} +#pragma clang diagnostic pop + // Preinit void __rtsan::InitializeInterceptors() { INTERCEPT_FUNCTION(calloc); @@ -836,6 +856,10 @@ void __rtsan::InitializeInterceptors() { RTSAN_MAYBE_INTERCEPT_KQUEUE; RTSAN_MAYBE_INTERCEPT_KEVENT; RTSAN_MAYBE_INTERCEPT_KEVENT64; + + INTERCEPT_FUNCTION(pipe); + INTERCEPT_FUNCTION(mkfifo); + INTERCEPT_FUNCTION(mkfifoat); } #endif // SANITIZER_POSIX 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 ab02b44187d89e..72f6d819b216c0 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -965,4 +965,32 @@ TEST_F(KqueueTest, Kevent64DiesWhenRealtime) { } #endif // SANITIZER_INTERCEPT_KQUEUE +TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) { + auto Func = []() { mkfifo("/tmp/rtsan_test_fifo", 0); }; + ExpectRealtimeDeath(Func, "mkfifo"); + ExpectNonRealtimeSurvival(Func); +} + +#if __has_builtin(__builtin_available) && SANITIZER_APPLE +#define MKFIFOAT_AVAILABLE() (__builtin_available(macOS 10.13, *)) +#else +// We are going to assume this is true until we hit systems where it isn't +#define MKFIFOAT_AVAILABLE() (true) +#endif + +TEST(TestRtsanInterceptors, MkfifoatDiesWhenRealtime) { + if (MKFIFOAT_AVAILABLE()) { + auto Func = []() { mkfifoat(0, "/tmp/rtsan_test_fifo", 0); }; + ExpectRealtimeDeath(Func, "mkfifoat"); + ExpectNonRealtimeSurvival(Func); + } +} + +TEST(TestRtsanInterceptors, PipeDiesWhenRealtime) { + int fds[2]; + auto Func = [&fds]() { pipe(fds); }; + ExpectRealtimeDeath(Func, "pipe"); + ExpectNonRealtimeSurvival(Func); +} + #endif // SANITIZER_POSIX