Skip to content

Commit ba155fe

Browse files
committed
adding fpurge
1 parent 7802b20 commit ba155fe

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,13 @@ INTERCEPTOR(int, fflush, FILE *stream) {
297297
return REAL(fflush)(stream);
298298
}
299299

300+
#if SANITIZER_APPLE
301+
INTERCEPTOR(int, fpurge, FILE *stream) {
302+
__rtsan_notify_intercepted_call("fpurge");
303+
return REAL(fpurge)(stream);
304+
}
305+
#endif
306+
300307
INTERCEPTOR(FILE *, fdopen, int fd, const char *mode) {
301308
__rtsan_notify_intercepted_call("fdopen");
302309
return REAL(fdopen)(fd, mode);

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -607,16 +607,31 @@ TEST_F(RtsanOpenedFileTest, FputsDiesWhenRealtime) {
607607
TEST_F(RtsanFileTest, FflushDiesWhenRealtime) {
608608
FILE *f = fopen(GetTemporaryFilePath(), "w");
609609
EXPECT_THAT(f, Ne(nullptr));
610-
int r = fwrite("abc", 1, 3, f);
611-
EXPECT_THAT(r, Eq(3));
610+
int written = fwrite("abc", 1, 3, f);
611+
EXPECT_THAT(written, Eq(3));
612612
auto Func = [&f]() {
613-
int r = fflush(f);
614-
EXPECT_THAT(r, Eq(0));
613+
int res = fflush(f);
614+
EXPECT_THAT(res, Eq(0));
615615
};
616616
ExpectRealtimeDeath(Func, "fflush");
617617
ExpectNonRealtimeSurvival(Func);
618618
}
619619

620+
#if SANITIZER_APPLE
621+
TEST_F(RtsanFileTest, FpurgeDiesWhenRealtime) {
622+
FILE *f = fopen(GetTemporaryFilePath(), "w");
623+
EXPECT_THAT(f, Ne(nullptr));
624+
int written = fwrite("abc", 1, 3, f);
625+
EXPECT_THAT(written, Eq(3));
626+
auto Func = [&f]() {
627+
int res = fpurge(f);
628+
EXPECT_THAT(res, Eq(0));
629+
};
630+
ExpectRealtimeDeath(Func, "fpurge");
631+
ExpectNonRealtimeSurvival(Func);
632+
}
633+
#endif
634+
620635
TEST_F(RtsanOpenedFileTest, ReadDiesWhenRealtime) {
621636
auto Func = [this]() {
622637
char c{};

0 commit comments

Comments
 (0)