Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ INTERCEPTOR(int, munmap, void *addr, size_t length) {
return REAL(munmap)(addr, length);
}

#if !SANITIZER_APPLE
INTERCEPTOR(int, madvise, void *addr, size_t length, int flag) {
__rtsan_notify_intercepted_call("madvise");
return REAL(madvise)(addr, length, flag);
Expand All @@ -817,6 +818,12 @@ INTERCEPTOR(int, posix_madvise, void *addr, size_t length, int flag) {
__rtsan_notify_intercepted_call("posix_madvise");
return REAL(posix_madvise)(addr, length, flag);
}
#define RTSAN_MAYBE_INTERCEPT_MADVISE INTERCEPT_FUNCTION(madvise)
#define RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE INTERCEPT_FUNCTION(posix_madvise)
#else
#define RTSAN_MAYBE_INTERCEPT_MADVISE
#define RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE
#endif

INTERCEPTOR(int, mprotect, void *addr, size_t length, int prot) {
__rtsan_notify_intercepted_call("mprotect");
Expand Down Expand Up @@ -1216,8 +1223,8 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(mmap);
RTSAN_MAYBE_INTERCEPT_MMAP64;
INTERCEPT_FUNCTION(munmap);
INTERCEPT_FUNCTION(madvise);
INTERCEPT_FUNCTION(posix_madvise);
RTSAN_MAYBE_INTERCEPT_MADVISE;
RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE;
INTERCEPT_FUNCTION(mprotect);
INTERCEPT_FUNCTION(msync);
INTERCEPT_FUNCTION(mincore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,17 +238,21 @@ class RtsanOpenedMmapTest : public RtsanFileTest {
int fd = -1;
};

#if !SANITIZER_APPLE
TEST_F(RtsanOpenedMmapTest, MadviseDiesWhenRealtime) {
auto Func = [this]() { madvise(GetAddr(), GetSize(), MADV_NORMAL); };
ExpectRealtimeDeath(Func, "madvise");
ExpectNonRealtimeSurvival(Func);
}

TEST_F(RtsanOpenedMmapTest, PosixMadviseDiesWhenRealtime) {
auto Func = [this]() { posix_madvise(GetAddr(), GetSize(), MADV_NORMAL); };
auto Func = [this]() {
posix_madvise(GetAddr(), GetSize(), POSIX_MADV_NORMAL);
};
ExpectRealtimeDeath(Func, "posix_madvise");
ExpectNonRealtimeSurvival(Func);
}
#endif

TEST_F(RtsanOpenedMmapTest, MprotectDiesWhenRealtime) {
auto Func = [this]() { mprotect(GetAddr(), GetSize(), PROT_READ); };
Expand Down
Loading