[compiler-rt] r370008 - [Sanitizer] Using huge page on FreeBSD for shadow mapping
David Carlier via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 26 21:02:20 PDT 2019
Author: devnexen
Date: Mon Aug 26 21:02:19 2019
New Revision: 370008
URL: http://llvm.org/viewvc/llvm-project?rev=370008&view=rev
Log:
[Sanitizer] Using huge page on FreeBSD for shadow mapping
- Unless explicit configuration, using FreeBSD super pages feature for shadow mapping.
- asan only for now.
Reviewers: dim, emaste, vitalybuka
Reviewed By: vitalybuka
Differential Revision: https://reviews.llvm.org/D65851
Modified:
compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp
compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp
Modified: compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp?rev=370008&r1=370007&r2=370008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp (original)
+++ compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp Mon Aug 26 21:02:19 2019
@@ -30,14 +30,13 @@ void ReserveShadowMemoryRange(uptr beg,
CHECK_EQ(((end + 1) % GetMmapGranularity()), 0);
uptr size = end - beg + 1;
DecreaseTotalMmap(size); // Don't count the shadow against mmap_limit_mb.
- if (!MmapFixedNoReserve(beg, size, name)) {
+ if (!MmapFixedSuperNoReserve(beg, size, name)) {
Report(
"ReserveShadowMemoryRange failed while trying to map 0x%zx bytes. "
"Perhaps you're using ulimit -v\n",
size);
Abort();
}
- SetShadowRegionHugePageMode(beg, size);
if (common_flags()->use_madv_dontdump) DontDumpShadowMemory(beg, size);
}
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h?rev=370008&r1=370007&r2=370008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h Mon Aug 26 21:02:19 2019
@@ -100,6 +100,8 @@ void UnmapOrDie(void *addr, uptr size);
void *MmapOrDieOnFatalError(uptr size, const char *mem_type);
bool MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name = nullptr)
WARN_UNUSED_RESULT;
+bool MmapFixedSuperNoReserve(uptr fixed_addr, uptr size, const char *name = nullptr)
+ WARN_UNUSED_RESULT;
void *MmapNoReserveOrDie(uptr size, const char *mem_type);
void *MmapFixedOrDie(uptr fixed_addr, uptr size, const char *name = nullptr);
// Behaves just like MmapFixedOrDie, but tolerates out of memory condition, in
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp?rev=370008&r1=370007&r2=370008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp Mon Aug 26 21:02:19 2019
@@ -304,11 +304,11 @@ void PlatformPrepareForSandboxing(__sani
MemoryMappingLayout::CacheMemoryMappings();
}
-bool MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name) {
+static bool MmapFixed(uptr fixed_addr, uptr size, int additional_flags, const char *name) {
size = RoundUpTo(size, GetPageSizeCached());
fixed_addr = RoundDownTo(fixed_addr, GetPageSizeCached());
uptr p = MmapNamed((void *)fixed_addr, size, PROT_READ | PROT_WRITE,
- MAP_PRIVATE | MAP_FIXED | MAP_NORESERVE | MAP_ANON, name);
+ MAP_PRIVATE | MAP_FIXED | additional_flags | MAP_ANON, name);
int reserrno;
if (internal_iserror(p, &reserrno)) {
Report("ERROR: %s failed to "
@@ -320,6 +320,25 @@ bool MmapFixedNoReserve(uptr fixed_addr,
return true;
}
+bool MmapFixedNoReserve(uptr fixed_addr, uptr size, const char *name) {
+ return MmapFixed(fixed_addr, size, MAP_NORESERVE, name);
+}
+
+bool MmapFixedSuperNoReserve(uptr fixed_addr, uptr size, const char *name) {
+#if SANITIZER_FREEBSD
+ int flags = 0;
+ if (common_flags()->no_huge_pages_for_shadow)
+ return MmapFixedNoReserve(fixed_addr, size, name);
+ // MAP_NORESERVE is implicit with FreeBSD
+ return MmapFixed(fixed_addr, size, MAP_ALIGNED_SUPER, name);
+#else
+ bool r = MmapFixedNoReserve(fixed_addr, size, name);
+ if (r)
+ SetShadowRegionHugePageMode(fixed_addr,size);
+ return r;
+#endif
+}
+
uptr ReservedAddressRange::Init(uptr size, const char *name, uptr fixed_addr) {
base_ = fixed_addr ? MmapFixedNoAccess(fixed_addr, size, name)
: MmapNoAccess(size);
Modified: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp?rev=370008&r1=370007&r2=370008&view=diff
==============================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp (original)
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp Mon Aug 26 21:02:19 2019
@@ -239,6 +239,11 @@ bool MmapFixedNoReserve(uptr fixed_addr,
return true;
}
+bool MmapFixedSuperNoReserve(uptr fixed_addr, uptr size, const char *name) {
+ // FIXME: Windows support large pages too. Might be worth checking
+ return MmapFixedNoReserve(fixed_addr, size, name);
+}
+
// Memory space mapped by 'MmapFixedOrDie' must have been reserved by
// 'MmapFixedNoAccess'.
void *MmapFixedOrDie(uptr fixed_addr, uptr size, const char *name) {
More information about the llvm-commits
mailing list