@@ -47,6 +47,7 @@ void OSSpinLockLock(volatile OSSpinLock *__lock);
4747#include < stdarg.h>
4848#include < stdio.h>
4949#if SANITIZER_LINUX
50+ #include < linux/mman.h>
5051#include < sys/inotify.h>
5152#endif
5253#include < sys/select.h>
@@ -870,6 +871,32 @@ INTERCEPTOR(void *, mmap64, void *addr, size_t length, int prot, int flags,
870871#define RTSAN_MAYBE_INTERCEPT_MMAP64
871872#endif // SANITIZER_INTERCEPT_MMAP64
872873
874+ #if SANITIZER_LINUX
875+ // Note that even if rtsan is ported to netbsd, it has a slighty different
876+ // and non-variadic signature
877+ INTERCEPTOR (void *, mremap, void *oaddr, size_t olength, size_t nlength,
878+ int flags, ...) {
879+ __rtsan_notify_intercepted_call (" mremap" );
880+
881+ // the last optional argument is only used in this case
882+ // as the new page region will be assigned to. Is ignored otherwise.
883+ if (flags & MREMAP_FIXED) {
884+ va_list args;
885+
886+ va_start (args, flags);
887+ void *naddr = va_arg (args, void *);
888+ va_end (args);
889+
890+ return REAL (mremap)(oaddr, olength, nlength, flags, naddr);
891+ }
892+
893+ return REAL (mremap)(oaddr, olength, nlength, flags);
894+ }
895+ #define RTSAN_MAYBE_INTERCEPT_MREMAP INTERCEPT_FUNCTION (mremap)
896+ #else
897+ #define RTSAN_MAYBE_INTERCEPT_MREMAP
898+ #endif
899+
873900INTERCEPTOR (int , munmap, void *addr, size_t length) {
874901 __rtsan_notify_intercepted_call (" munmap" );
875902 return REAL (munmap)(addr, length);
@@ -1346,6 +1373,7 @@ void __rtsan::InitializeInterceptors() {
13461373 INTERCEPT_FUNCTION (posix_memalign);
13471374 INTERCEPT_FUNCTION (mmap);
13481375 RTSAN_MAYBE_INTERCEPT_MMAP64;
1376+ RTSAN_MAYBE_INTERCEPT_MREMAP;
13491377 INTERCEPT_FUNCTION (munmap);
13501378 RTSAN_MAYBE_INTERCEPT_MADVISE;
13511379 RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE;
0 commit comments