diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp index b139f628703f..9d1a689a5a07 100644 --- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp @@ -1343,17 +1343,41 @@ INTERCEPTOR(int, inotify_rm_watch, int fd, int wd) { __rtsan_notify_intercepted_call("inotify_rm_watch"); return REAL(inotify_rm_watch)(fd, wd); } + +INTERCEPTOR(int, timerfd_create, int clockid, int flags) { + __rtsan_notify_intercepted_call("timerfd_create"); + return REAL(timerfd_create)(clockid, flags); +} + +INTERCEPTOR(int, timerfd_settime, int fd, int flags, const itimerspec *newval, + struct itimerspec *oldval) { + __rtsan_notify_intercepted_call("timerfd_settime"); + return REAL(timerfd_settime)(fd, flags, newval, oldval); +} + +INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) { + __rtsan_notify_intercepted_call("timerfd_gettime"); + return REAL(timerfd_gettime)(fd, val); +} #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) +#define RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE INTERCEPT_FUNCTION(timerfd_create) +#define RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME \ + INTERCEPT_FUNCTION(timerfd_settime) +#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME \ + INTERCEPT_FUNCTION(timerfd_gettime) #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 +#define RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE +#define RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME +#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME #endif INTERCEPTOR(int, pipe, int pipefd[2]) { @@ -1617,6 +1641,10 @@ void __rtsan::InitializeInterceptors() { RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH; RTSAN_MAYBE_INTERCEPT_INOTIFY_RM_WATCH; + RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE; + RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME; + RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME; + 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 321cc4f0c78f..f12df9ea9085 100644 --- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp +++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp @@ -45,6 +45,7 @@ #include #if SANITIZER_LINUX #include +#include #endif #include #include @@ -1652,6 +1653,30 @@ TEST(TestRtsanInterceptors, InotifyRmWatchDiesWhenRealtime) { ExpectRealtimeDeath(Func, "inotify_rm_watch"); ExpectNonRealtimeSurvival(Func); } + +TEST(TestRtsanInterceptors, TimerfdCreateDiesWhenRealtime) { + auto Func = []() { timerfd_create(CLOCK_MONOTONIC, 0); }; + ExpectRealtimeDeath(Func, "timerfd_create"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, TimerfdSettimeDiesWhenRealtime) { + int fd = timerfd_create(CLOCK_MONOTONIC, 0); + EXPECT_THAT(fd, Ne(-1)); + auto ts = itimerspec{{0, 0}, {0, 0}}; + auto Func = [fd, ts]() { timerfd_settime(fd, 0, &ts, NULL); }; + ExpectRealtimeDeath(Func, "timerfd_settime"); + ExpectNonRealtimeSurvival(Func); +} + +TEST(TestRtsanInterceptors, TimerfdGettimeDiesWhenRealtime) { + int fd = timerfd_create(CLOCK_MONOTONIC, 0); + EXPECT_THAT(fd, Ne(-1)); + itimerspec ts{}; + auto Func = [fd, &ts]() { timerfd_gettime(fd, &ts); }; + ExpectRealtimeDeath(Func, "timerfd_gettime"); + ExpectNonRealtimeSurvival(Func); +} #endif TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) {