diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index a01354781272d..9908a9e3d3dc6 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -46,6 +46,9 @@ void OSSpinLockLock(volatile OSSpinLock *__lock); #include #include #include +#if SANITIZER_LINUX +#include +#endif #include #include #include @@ -1130,6 +1133,39 @@ INTERCEPTOR(int, kevent64, int kq, const struct kevent64_s *changelist, #define RTSAN_MAYBE_INTERCEPT_KEVENT64 #endif // SANITIZER_INTERCEPT_KQUEUE +#if SANITIZER_LINUX +INTERCEPTOR(int, inotify_init) { + __rtsan_notify_intercepted_call("inotify_init"); + return REAL(inotify_init)(); +} + +INTERCEPTOR(int, inotify_init1, int flags) { + __rtsan_notify_intercepted_call("inotify_init1"); + return REAL(inotify_init1)(flags); +} + +INTERCEPTOR(int, inotify_add_watch, int fd, const char *path, uint32_t mask) { + __rtsan_notify_intercepted_call("inotify_add_watch"); + return REAL(inotify_add_watch)(fd, path, mask); +} + +INTERCEPTOR(int, inotify_rm_watch, int fd, int wd) { + __rtsan_notify_intercepted_call("inotify_rm_watch"); + return REAL(inotify_rm_watch)(fd, wd); +} +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT INTERCEPT_FUNCTION(inotify_init) +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1 INTERCEPT_FUNCTION(inotify_init1) +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH \ + INTERCEPT_FUNCTION(inotify_add_watch) +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH \ + INTERCEPT_FUNCTION(inotify_rm_watch) +#else +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1 +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH +#define RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH +#endif + INTERCEPTOR(int, pipe, int pipefd[2]) { __rtsan_notify_intercepted_call("pipe"); return REAL(pipe)(pipefd); @@ -1367,6 +1403,11 @@ void __rtsan::InitializeInterceptors() { RTSAN_MAYBE_INTERCEPT_KEVENT; RTSAN_MAYBE_INTERCEPT_KEVENT64; + RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT; + RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1; + RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH; + RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH; + INTERCEPT_FUNCTION(pipe); INTERCEPT_FUNCTION(mkfifo); 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 981766c85f965..a5cf0f31a4ea4 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -43,6 +43,9 @@ #include #include #include +#if SANITIZER_LINUX +#include +#endif #include #include #include @@ -1481,6 +1484,38 @@ TEST_F(KqueueTest, Kevent64DiesWhenRealtime) { } #endif // SANITIZER_INTERCEPT_KQUEUE +#if SANITIZER_LINUX +TEST(TestRtsanInterceptors, InotifyInitDiesWhenRealtime) { + auto Func = []() { inotify_init(); }; + ExpectRealtimeDeath(Func, "inotify_init"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, InotifyInit1DiesWhenRealtime) { + auto Func = []() { inotify_init1(0); }; + ExpectRealtimeDeath(Func, "inotify_init1"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, InotifyAddWatchDiesWhenRealtime) { + int fd = inotify_init(); + EXPECT_THAT(fd, Ne(-1)); + auto Func = [fd]() { + inotify_add_watch(fd, "/tmp/rtsan_inotify", IN_CREATE); + }; + ExpectRealtimeDeath(Func, "inotify_add_watch"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, InotifyRmWatchDiesWhenRealtime) { + int fd = inotify_init(); + EXPECT_THAT(fd, Ne(-1)); + auto Func = [fd]() { inotify_rm_watch(fd, -1); }; + ExpectRealtimeDeath(Func, "inotify_rm_watch"); + ExpectNonRealtimeSurvival(Func); +} +#endif + TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) { auto Func = []() { mkfifo("/tmp/rtsan_test_fifo", 0); }; ExpectRealtimeDeath(Func, "mkfifo");