Skip to content

Commit 6d42b34

Browse files
committed
[compiler-rt] rtsan pipe2 interception for Linux.
completing fpurge interception for mac too.
1 parent 6adeda8 commit 6d42b34

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ 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+
#define RTSAN_MAYBE_INTERCEPT_PIPE2
307+
#else
308+
INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {
309+
__rtsan_notify_intercepted_call("pipe2");
310+
return REAL(pipe2)(pipefd, flags);
311+
}
312+
#define RTSAN_MAYBE_INTERCEPT_FPURGE
313+
#define RTSAN_MAYBE_INTERCEPT_PIPE2 INTERCEPT_FUNCTION(pipe2)
305314
#endif
306315

307316
INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
@@ -1133,6 +1142,8 @@ void __rtsan::InitializeInterceptors() {
11331142
INTERCEPT_FUNCTION(puts);
11341143
INTERCEPT_FUNCTION(fputs);
11351144
INTERCEPT_FUNCTION(fflush);
1145+
RTSAN_MAYBE_INTERCEPT_FPURGE;
1146+
RTSAN_MAYBE_INTERCEPT_PIPE2;
11361147
INTERCEPT_FUNCTION(fdopen);
11371148
INTERCEPT_FUNCTION(freopen);
11381149
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)