[compiler-rt] 59354a8 - [compiler-rt][rtsan] intercept fflush. (#121643)
via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 4 12:15:08 PST 2025
Author: David CARLIER
Date: 2025-01-04T20:15:05Z
New Revision: 59354a865fe408749634456e10bd76a50d785c2b
URL: https://github.com/llvm/llvm-project/commit/59354a865fe408749634456e10bd76a50d785c2b
DIFF: https://github.com/llvm/llvm-project/commit/59354a865fe408749634456e10bd76a50d785c2b.diff
LOG: [compiler-rt][rtsan] intercept fflush. (#121643)
Added:
Modified:
compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Removed:
################################################################################
diff --git a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
index 9f89ab6bf1fc7d..f1fe20b255d9c9 100644
--- a/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
@@ -292,6 +292,18 @@ 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);
+}
+
+#if SANITIZER_APPLE
+INTERCEPTOR(int, fpurge, FILE *stream) {
+ __rtsan_notify_intercepted_call("fpurge");
+ return REAL(fpurge)(stream);
+}
+#endif
+
INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
__rtsan_notify_intercepted_call("fdopen");
return REAL(fdopen)(fd, mode);
@@ -981,6 +993,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 5adbf0fb63de80..15dfc1af016251 100644
--- a/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
+++ b/compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
@@ -604,6 +604,34 @@ TEST_F(RtsanOpenedFileTest, FputsDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}
+TEST_F(RtsanFileTest, FflushDiesWhenRealtime) {
+ FILE *f = fopen(GetTemporaryFilePath(), "w");
+ EXPECT_THAT(f, Ne(nullptr));
+ int written = fwrite("abc", 1, 3, f);
+ EXPECT_THAT(written, Eq(3));
+ auto Func = [&f]() {
+ int res = fflush(f);
+ EXPECT_THAT(res, Eq(0));
+ };
+ ExpectRealtimeDeath(Func, "fflush");
+ ExpectNonRealtimeSurvival(Func);
+}
+
+#if SANITIZER_APPLE
+TEST_F(RtsanFileTest, FpurgeDiesWhenRealtime) {
+ FILE *f = fopen(GetTemporaryFilePath(), "w");
+ EXPECT_THAT(f, Ne(nullptr));
+ int written = fwrite("abc", 1, 3, f);
+ EXPECT_THAT(written, Eq(3));
+ auto Func = [&f]() {
+ int res = fpurge(f);
+ EXPECT_THAT(res, Eq(0));
+ };
+ ExpectRealtimeDeath(Func, "fpurge");
+ ExpectNonRealtimeSurvival(Func);
+}
+#endif
+
TEST_F(RtsanOpenedFileTest, ReadDiesWhenRealtime) {
auto Func = [this]() {
char c{};
More information about the llvm-commits
mailing list