Skip to content

Commit 75bbf76

Browse files
authored
[compiler-rt][rtsan] Linux's eventfd interception. (#132836)
1 parent a641910 commit 75bbf76

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1359,6 +1359,12 @@ INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {
13591359
__rtsan_notify_intercepted_call("timerfd_gettime");
13601360
return REAL(timerfd_gettime)(fd, val);
13611361
}
1362+
1363+
/* eventfd wrappers calls SYS_eventfd2 down the line */
1364+
INTERCEPTOR(int, eventfd, unsigned int count, int flags) {
1365+
__rtsan_notify_intercepted_call("eventfd");
1366+
return REAL(eventfd)(count, flags);
1367+
}
13621368
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT INTERCEPT_FUNCTION(inotify_init)
13631369
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1 INTERCEPT_FUNCTION(inotify_init1)
13641370
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_ADD_WATCH \
@@ -1370,6 +1376,7 @@ INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {
13701376
INTERCEPT_FUNCTION(timerfd_settime)
13711377
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME \
13721378
INTERCEPT_FUNCTION(timerfd_gettime)
1379+
#define RTSAN_MAYBE_INTERCEPT_EVENTFD INTERCEPT_FUNCTION(eventfd)
13731380
#else
13741381
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT
13751382
#define RTSAN_MAYBE_INTERCEPT_INOTIFY_INIT1
@@ -1378,6 +1385,7 @@ INTERCEPTOR(int, timerfd_gettime, int fd, struct itimerspec *val) {
13781385
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE
13791386
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME
13801387
#define RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME
1388+
#define RTSAN_MAYBE_INTERCEPT_EVENTFD
13811389
#endif
13821390

13831391
INTERCEPTOR(int, pipe, int pipefd[2]) {
@@ -1644,6 +1652,7 @@ void __rtsan::InitializeInterceptors() {
16441652
RTSAN_MAYBE_INTERCEPT_TIMERFD_CREATE;
16451653
RTSAN_MAYBE_INTERCEPT_TIMERFD_SETTIME;
16461654
RTSAN_MAYBE_INTERCEPT_TIMERFD_GETTIME;
1655+
RTSAN_MAYBE_INTERCEPT_EVENTFD;
16471656

16481657
INTERCEPT_FUNCTION(pipe);
16491658
INTERCEPT_FUNCTION(mkfifo);

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
#include <pthread.h>
4545
#include <stdio.h>
4646
#if SANITIZER_LINUX
47+
#include <sys/eventfd.h>
4748
#include <sys/inotify.h>
4849
#include <sys/timerfd.h>
4950
#endif
@@ -1677,6 +1678,12 @@ TEST(TestRtsanInterceptors, TimerfdGettimeDiesWhenRealtime) {
16771678
ExpectRealtimeDeath(Func, "timerfd_gettime");
16781679
ExpectNonRealtimeSurvival(Func);
16791680
}
1681+
1682+
TEST(TestRtsanInterceptors, EventfdDiesWhenRealtime) {
1683+
auto Func = []() { eventfd(EFD_CLOEXEC, 0); };
1684+
ExpectRealtimeDeath(Func, "eventfd");
1685+
ExpectNonRealtimeSurvival(Func);
1686+
}
16801687
#endif
16811688

16821689
TEST(TestRtsanInterceptors, MkfifoDiesWhenRealtime) {

0 commit comments

Comments
 (0)