tsan: madvise(DONTNEED) shadow memory on munmap()
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@177278 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/tsan/rtl/tsan_interceptors.cc b/lib/tsan/rtl/tsan_interceptors.cc
index 352c7bb..0bc4c73 100644
--- a/lib/tsan/rtl/tsan_interceptors.cc
+++ b/lib/tsan/rtl/tsan_interceptors.cc
@@ -619,6 +619,11 @@
TSAN_INTERCEPTOR(int, munmap, void *addr, long_t sz) {
SCOPED_TSAN_INTERCEPTOR(munmap, addr, sz);
+ // We are about to unmap a chunk of user memory.
+ // Mark the corresponding shadow memory as not needed.
+ uptr shadow_beg = MemToShadow((uptr)addr);
+ uptr shadow_end = MemToShadow((uptr)addr + sz);
+ FlushUnneededShadowMemory(shadow_beg, shadow_end - shadow_beg);
int res = REAL(munmap)(addr, sz);
return res;
}