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
28 changes: 28 additions & 0 deletions compiler-rt/lib/rtsan/rtsan_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void OSSpinLockLock(volatile OSSpinLock *__lock);
#include <stdarg.h>
#include <stdio.h>
#if SANITIZER_LINUX
#include <linux/mman.h>
#include <sys/inotify.h>
#endif
#include <sys/select.h>
Expand Down Expand Up @@ -850,6 +851,32 @@ INTERCEPTOR(void *, mmap64, void *addr, size_t length, int prot, int flags,
#define RTSAN_MAYBE_INTERCEPT_MMAP64
#endif // SANITIZER_INTERCEPT_MMAP64

#if SANITIZER_LINUX
// Note that even if rtsan is ported to netbsd, it has a slighty different
// and non-variadic signature
INTERCEPTOR(void *, mremap, void *oaddr, size_t olength, size_t nlength,
int flags, ...) {
__rtsan_notify_intercepted_call("mremap");

// the last optional argument is only used in this case
// as the new page region will be assigned to. Is ignored otherwise.
if (flags & MREMAP_FIXED) {
va_list args;

va_start(args, flags);
void *naddr = va_arg(args, void *);
va_end(args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this will you follow the pattern set forth in our open/openat interceptor? that is, call REAL in two places so we don't have to pass in nullptr on 873?


return REAL(mremap)(oaddr, olength, nlength, flags, naddr);
}

return REAL(mremap)(oaddr, olength, nlength, flags);
}
#define RTSAN_MAYBE_INTERCEPT_MREMAP INTERCEPT_FUNCTION(mremap)
#else
#define RTSAN_MAYBE_INTERCEPT_MREMAP
#endif

INTERCEPTOR(int, munmap, void *addr, size_t length) {
__rtsan_notify_intercepted_call("munmap");
return REAL(munmap)(addr, length);
Expand Down Expand Up @@ -1321,6 +1348,7 @@ void __rtsan::InitializeInterceptors() {
INTERCEPT_FUNCTION(posix_memalign);
INTERCEPT_FUNCTION(mmap);
RTSAN_MAYBE_INTERCEPT_MMAP64;
RTSAN_MAYBE_INTERCEPT_MREMAP;
INTERCEPT_FUNCTION(munmap);
RTSAN_MAYBE_INTERCEPT_MADVISE;
RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE;
Expand Down
10 changes: 10 additions & 0 deletions compiler-rt/lib/rtsan/tests/rtsan_test_interceptors_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ TEST(TestRtsanInterceptors, MmapDiesWhenRealtime) {
ExpectNonRealtimeSurvival(Func);
}

#if SANITIZER_LINUX
TEST(TestRtsanInterceptors, MremapDiesWhenRealtime) {
void *addr = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
auto Func = [addr]() { void *_ = mremap(addr, 8, 16, 0); };
ExpectRealtimeDeath(Func, "mremap");
ExpectNonRealtimeSurvival(Func);
}
#endif

TEST(TestRtsanInterceptors, MunmapDiesWhenRealtime) {
void *ptr = mmap(nullptr, 8, PROT_READ | PROT_WRITE,
MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
Expand Down
Loading