Skip to content

Commit 945d1f7

Browse files
committed
[compiler-rt][rtsan] intercept fflush.
1 parent 95db111 commit 945d1f7

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,11 @@ INTERCEPTOR(int, fputs, const char *s, FILE *stream) {
292292
return REAL(fputs)(s, stream);
293293
}
294294

295+
INTERCEPTOR(int, fflush, FILE *stream) {
296+
__rtsan_notify_intercepted_call("fflush");
297+
return REAL(fflush)(stream);
298+
}
299+
295300
INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
296301
__rtsan_notify_intercepted_call("fdopen");
297302
return REAL(fdopen)(fd, mode);
@@ -1012,6 +1017,7 @@ void __rtsan::InitializeInterceptors() {
10121017
RTSAN_MAYBE_INTERCEPT_CREAT64;
10131018
INTERCEPT_FUNCTION(puts);
10141019
INTERCEPT_FUNCTION(fputs);
1020+
INTERCEPT_FUNCTION(fflush);
10151021
INTERCEPT_FUNCTION(fdopen);
10161022
INTERCEPT_FUNCTION(freopen);
10171023
RTSAN_MAYBE_INTERCEPT_FOPENCOOKIE;

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -654,6 +654,19 @@ TEST_F(RtsanOpenedFileTest, FputsDiesWhenRealtime) {
654654
ExpectNonRealtimeSurvival(Func);
655655
}
656656

657+
TEST_F(RtsanFileTest, FflushDiesWhenRealtime) {
658+
FILE *f = fopen(GetTemporaryFilePath(), "w");
659+
EXPECT_THAT(f, Ne(nullptr));
660+
int r = fwrite("abc", 1, 3, f);
661+
EXPECT_THAT(r, Eq(3));
662+
auto Func = [&f]() {
663+
int r = fflush(f);
664+
EXPECT_THAT(r, Eq(0));
665+
};
666+
ExpectRealtimeDeath(Func, "fflush");
667+
ExpectNonRealtimeSurvival(Func);
668+
}
669+
657670
TEST_F(RtsanOpenedFileTest, ReadDiesWhenRealtime) {
658671
auto Func = [this]() {
659672
char c{};

0 commit comments

Comments
 (0)