-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[compiler-rt][rtsan] intercept fflush. #121643
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: David CARLIER (devnexen) ChangesFull diff: https://github.com/llvm/llvm-project/pull/121643.diff 2 Files Affected:
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{};
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
TEST_F(RtsanFileTest, FflushDiesWhenRealtime) { | ||
FILE *f = fopen(GetTemporaryFilePath(), "w"); | ||
EXPECT_THAT(f, Ne(nullptr)); | ||
int r = fwrite("abc", 1, 3, f); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Could have a more descriptive name bytes_written
/num_written
/written
or similar
@@ -292,6 +292,11 @@ INTERCEPTOR(int, fputs, const char *s, FILE *stream) { | |||
return REAL(fputs)(s, stream); | |||
} | |||
|
|||
INTERCEPTOR(int, fflush, FILE *stream) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you plan to add fpurge
as well? man fflush
on Darwin also contains details for fpurge
- it might be nice to do them both at the same time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
did not think of it sure I would need to switch to my m3 to try it.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/73/builds/11150 Here is the relevant piece of the build log for the reference
|
No description provided.