Skip to content

Commit 02909a4

Browse files
authored
[compiler-rt] rtsan pipe2 interception for Linux. (#123517)
completing fpurge interception for mac too.
1 parent 5c6db8c commit 02909a4

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,9 @@ INTERCEPTOR(int, fpurge, FILE *stream) {
302302
__rtsan_notify_intercepted_call("fpurge");
303303
return REAL(fpurge)(stream);
304304
}
305+
#define RTSAN_MAYBE_INTERCEPT_FPURGE INTERCEPT_FUNCTION(fpurge)
306+
#else
307+
#define RTSAN_MAYBE_INTERCEPT_FPURGE
305308
#endif
306309

307310
INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
@@ -1031,6 +1034,16 @@ INTERCEPTOR(int, pipe, int pipefd[2]) {
10311034
return REAL(pipe)(pipefd);
10321035
}
10331036

1037+
#if !SANITIZER_APPLE
1038+
INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {
1039+
__rtsan_notify_intercepted_call("pipe2");
1040+
return REAL(pipe2)(pipefd, flags);
1041+
}
1042+
#define RTSAN_MAYBE_INTERCEPT_PIPE2 INTERCEPT_FUNCTION(pipe2)
1043+
#else
1044+
#define RTSAN_MAYBE_INTERCEPT_PIPE2
1045+
#endif
1046+
10341047
INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) {
10351048
__rtsan_notify_intercepted_call("mkfifo");
10361049
return REAL(mkfifo)(pathname, mode);
@@ -1133,6 +1146,8 @@ void __rtsan::InitializeInterceptors() {
11331146
INTERCEPT_FUNCTION(puts);
11341147
INTERCEPT_FUNCTION(fputs);
11351148
INTERCEPT_FUNCTION(fflush);
1149+
RTSAN_MAYBE_INTERCEPT_FPURGE;
1150+
RTSAN_MAYBE_INTERCEPT_PIPE2;
11361151
INTERCEPT_FUNCTION(fdopen);
11371152
INTERCEPT_FUNCTION(freopen);
11381153
RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,15 @@ TEST(TestRtsanInterceptors, PipeDiesWhenRealtime) {
13491349
ExpectNonRealtimeSurvival(Func);
13501350
}
13511351

1352+
#if !SANITIZER_APPLE
1353+
TEST(TestRtsanInterceptors, Pipe2DiesWhenRealtime) {
1354+
int fds[2];
1355+
auto Func = [&fds]() { pipe2(fds, O_CLOEXEC); };
1356+
ExpectRealtimeDeath(Func, "pipe2");
1357+
ExpectNonRealtimeSurvival(Func);
1358+
}
1359+
#endif
1360+
13521361
#pragma clang diagnostic push
13531362
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
13541363
TEST(TestRtsanInterceptors, SyscallDiesWhenRealtime) {

0 commit comments

Comments
 (0)