@@ -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>
@@ -850,6 +851,32 @@ INTERCEPTOR(void *, mmap64, void *addr, size_t length, int prot, int flags,
850851#define RTSAN_MAYBE_INTERCEPT_MMAP64
851852#endif // SANITIZER_INTERCEPT_MMAP64
852853
854+ #if SANITIZER_LINUX
855+ // Note that even if rtsan is ported to netbsd, it has a different signature
856+ // still
857+ INTERCEPTOR (void *, mremap, void *oaddr, size_t olength, size_t nlength,
858+ int flags, ...) {
859+ __rtsan_notify_intercepted_call (" mremap" );
860+
861+ void *naddr = nullptr ;
862+
863+ // the last optional argument is only used in this case
864+ // as the new page region will be assigned to. Is ignored otherwise.
865+ if (flags & MREMAP_FIXED) {
866+ va_list args;
867+
868+ va_start (args, flags);
869+ naddr = va_arg (args, void *);
870+ va_end (args);
871+ }
872+
873+ return REAL (mremap)(oaddr, olength, nlength, flags, naddr);
874+ }
875+ #define RTSAN_MAYBE_INTERCEPT_MREMAP INTERCEPT_FUNCTION (mremap)
876+ #else
877+ #define RTSAN_MAYBE_INTERCEPT_MREMAP
878+ #endif
879+
853880INTERCEPTOR (int , munmap, void *addr, size_t length) {
854881 __rtsan_notify_intercepted_call (" munmap" );
855882 return REAL (munmap)(addr, length);
@@ -1321,6 +1348,7 @@ void __rtsan::InitializeInterceptors() {
13211348 INTERCEPT_FUNCTION (posix_memalign);
13221349 INTERCEPT_FUNCTION (mmap);
13231350 RTSAN_MAYBE_INTERCEPT_MMAP64;
1351+ RTSAN_MAYBE_INTERCEPT_MREMAP;
13241352 INTERCEPT_FUNCTION (munmap);
13251353 RTSAN_MAYBE_INTERCEPT_MADVISE;
13261354 RTSAN_MAYBE_INTERCEPT_POSIX_MADVISE;
0 commit comments