Skip to content

Commit 7802b20

Browse files
committed
[compiler-rt][rtsan] intercept fflush.
1 parent 4a7c0b8 commit 7802b20

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);
@@ -981,6 +986,7 @@ void __rtsan::InitializeInterceptors() {
981986
RTSAN_MAYBE_INTERCEPT_CREAT64;
982987
INTERCEPT_FUNCTION(puts);
983988
INTERCEPT_FUNCTION(fputs);
989+
INTERCEPT_FUNCTION(fflush);
984990
INTERCEPT_FUNCTION(fdopen);
985991
INTERCEPT_FUNCTION(freopen);
986992
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
@@ -604,6 +604,19 @@ TEST_F(RtsanOpenedFileTest, FputsDiesWhenRealtime) {
604604
ExpectNonRealtimeSurvival(Func);
605605
}
606606

607+
TEST_F(RtsanFileTest, FflushDiesWhenRealtime) {
608+
FILE *f = fopen(GetTemporaryFilePath(), "w");
609+
EXPECT_THAT(f, Ne(nullptr));
610+
int r = fwrite("abc", 1, 3, f);
611+
EXPECT_THAT(r, Eq(3));
612+
auto Func = [&f]() {
613+
int r = fflush(f);
614+
EXPECT_THAT(r, Eq(0));
615+
};
616+
ExpectRealtimeDeath(Func, "fflush");
617+
ExpectNonRealtimeSurvival(Func);
618+
}
619+
607620
TEST_F(RtsanOpenedFileTest, ReadDiesWhenRealtime) {
608621
auto Func = [this]() {
609622
char c{};

0 commit comments

Comments
 (0)