Skip to content

[compiler-rt] rtsan pipe2 interception for Linux. #123517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,9 @@ INTERCEPTOR(int, fpurge, FILE *stream) {
__rtsan_notify_intercepted_call("fpurge");
return REAL(fpurge)(stream);
}
#define RTSAN_MAYBE_INTERCEPT_FPURGE INTERCEPT_FUNCTION(fpurge)
#else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would split this into its own ifdef, I think fpurge and pipe2 are unrelated to one another

#define RTSAN_MAYBE_INTERCEPT_FPURGE
#endif

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

#if !SANITIZER_APPLE
INTERCEPTOR(int, pipe2, int pipefd[2], int flags) {
__rtsan_notify_intercepted_call("pipe2");
return REAL(pipe2)(pipefd, flags);
}
#define RTSAN_MAYBE_INTERCEPT_PIPE2 INTERCEPT_FUNCTION(pipe2)
#else
#define RTSAN_MAYBE_INTERCEPT_PIPE2
#endif

INTERCEPTOR(int, mkfifo, const char *pathname, mode_t mode) {
__rtsan_notify_intercepted_call("mkfifo");
return REAL(mkfifo)(pathname, mode);
Expand Down Expand Up @@ -1133,6 +1146,8 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(puts);
INTERCEPT_FUNCTION(fputs);
INTERCEPT_FUNCTION(fflush);
RTSAN_MAYBE_INTERCEPT_FPURGE;
RTSAN_MAYBE_INTERCEPT_PIPE2;
INTERCEPT_FUNCTION(fdopen);
INTERCEPT_FUNCTION(freopen);
RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;
Expand Down
9 changes: 9 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1349,6 +1349,15 @@ TEST(TestRtsanInterceptors, PipeDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if !SANITIZER_APPLE
TEST(TestRtsanInterceptors, Pipe2DiesWhenRealtime) {
int fds[2];
auto Func = [&fds]() { pipe2(fds, O_CLOEXEC); };
ExpectRealtimeDeath(Func, "pipe2");
ExpectNonRealtimeSurvival(Func);
}
#endif

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
TEST(TestRtsanInterceptors, SyscallDiesWhenRealtime) {
Expand Down
Loading