[compiler-rt] [compiler-rt][rtsan] intercept fflush. (PR #121643)
David CARLIER via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 4 04:01:41 PST 2025
https://github.com/devnexen created https://github.com/llvm/llvm-project/pull/121643
None
>From 945d1f75f9160becb50d8655b26fdfde14131d50 Mon Sep 17 00:00:00 2001
From: David Carlier <devnexen at gmail.com>
Date: Sat, 4 Jan 2025 12:00:59 +0000
Subject: [PATCH] [compiler-rt][rtsan] intercept fflush.
---
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp | 6 ++++++
.../rtsan/tests/rtsan_test_interceptors_posix.cpp | 13 +++++++++++++
2 files changed, 19 insertions(+)
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 227d077290af71..d1988c3ace04c4 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -292,6 +292,11 @@ INTERCEPTOR(int, fputs, const char *s, FILE *stream) {
return REAL(fputs)(s, stream);
}
+INTERCEPTOR(int, fflush, FILE *stream) {
+ __rtsan_notify_intercepted_call("fflush");
+ return REAL(fflush)(stream);
+}
+
INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
__rtsan_notify_intercepted_call("fdopen");
return REAL(fdopen)(fd, mode);
@@ -1012,6 +1017,7 @@ void __rtsan::InitializeInterceptors() {
RTSAN_MAYBE_INTERCEPT_CREAT64;
INTERCEPT_FUNCTION(puts);
INTERCEPT_FUNCTION(fputs);
+ INTERCEPT_FUNCTION(fflush);
INTERCEPT_FUNCTION(fdopen);
INTERCEPT_FUNCTION(freopen);
RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;
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 2947510b2cfde8..042fa49a638330 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -654,6 +654,19 @@ TEST_F(RtsanOpenedFileTest, FputsDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+TEST_F(RtsanFileTest, FflushDiesWhenRealtime) {
+ FILE *f = fopen(GetTemporaryFilePath(), "w");
+ EXPECT_THAT(f, Ne(nullptr));
+ int r = fwrite("abc", 1, 3, f);
+ EXPECT_THAT(r, Eq(3));
+ auto Func = [&f]() {
+ int r = fflush(f);
+ EXPECT_THAT(r, Eq(0));
+ };
+ ExpectRealtimeDeath(Func, "fflush");
+ ExpectNonRealtimeSurvival(Func);
+}
+
TEST_F(RtsanOpenedFileTest, ReadDiesWhenRealtime) {
auto Func = [this]() {
char c{};
More information about the llvm-commits
mailing list