[PATCH] D65851: [Sanitizer] Using huge page on FreeBSD for shadow mapping

David CARLIER via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 21:19:09 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL370008: [Sanitizer] Using huge page on FreeBSD for shadow mapping (authored by devnexen, committed by ).
Herald added a subscriber: delcypher.

Changed prior to commit:
  https://reviews.llvm.org/D65851?vs=217241&id=217303#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65851/new/

https://reviews.llvm.org/D65851

Files:
  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


Index: compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp
===================================================================
--- compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp
+++ compiler-rt/trunk/lib/asan/asan_shadow_setup.cpp
@@ -30,14 +30,13 @@
   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);
 }
 
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_win.cpp
@@ -239,6 +239,11 @@
   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) {
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_posix_libcdep.cpp
@@ -304,11 +304,11 @@
   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 @@
   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);
Index: compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
===================================================================
--- compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
+++ compiler-rt/trunk/lib/sanitizer_common/sanitizer_common.h
@@ -100,6 +100,8 @@
 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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D65851.217303.patch
Type: text/x-patch
Size: 4066 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/dd30e758/attachment.bin>


More information about the llvm-commits mailing list