From f097a8484d5a2c0732108351440984b93fdaa13d Mon Sep 17 00:00:00 2001 From: Kuba Mracek Date: Thu, 14 Dec 2017 00:04:30 +0000 Subject: [sanitizer] Use MADV_FREE on Darwin/BSD to release pages to the OS MADV_DONTNEED on Linux actually mark the pages as free to be overwritten with zeroes, but on Darwin and BSD, it's just an advisory flag (the OS cannot discard the content). We should use MADV_FREE on Darwin and BSD. Differential Revision: https://reviews.llvm.org/D40666 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@320659 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/sanitizer_common/sanitizer_platform.h | 5 +++++ lib/sanitizer_common/sanitizer_posix_libcdep.cc | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/sanitizer_common/sanitizer_platform.h b/lib/sanitizer_common/sanitizer_platform.h index d549827b4..e4e00bdfc 100644 --- a/lib/sanitizer_common/sanitizer_platform.h +++ b/lib/sanitizer_common/sanitizer_platform.h @@ -282,5 +282,10 @@ # define SANITIZER_SUPPRESS_LEAK_ON_PTHREAD_EXIT 0 #endif +#if SANITIZER_FREEBSD || SANITIZER_MAC || SANITIZER_NETBSD +# define SANITIZER_MADVISE_DONTNEED MADV_FREE +#else +# define SANITIZER_MADVISE_DONTNEED MADV_DONTNEED +#endif #endif // SANITIZER_PLATFORM_H diff --git a/lib/sanitizer_common/sanitizer_posix_libcdep.cc b/lib/sanitizer_common/sanitizer_posix_libcdep.cc index 710fdf3d6..935b80a5b 100644 --- a/lib/sanitizer_common/sanitizer_posix_libcdep.cc +++ b/lib/sanitizer_common/sanitizer_posix_libcdep.cc @@ -62,7 +62,8 @@ void ReleaseMemoryPagesToOS(uptr beg, uptr end) { uptr beg_aligned = RoundUpTo(beg, page_size); uptr end_aligned = RoundDownTo(end, page_size); if (beg_aligned < end_aligned) - madvise((void*)beg_aligned, end_aligned - beg_aligned, MADV_DONTNEED); + madvise((void *)beg_aligned, end_aligned - beg_aligned, + SANITIZER_MADVISE_DONTNEED); } void NoHugePagesInRegion(uptr addr, uptr size) { -- cgit v1.2.3