[PATCH] D36803: Create new VMARs on calls to MmapNoAccess.

Julia Hansbrough via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 16 11:49:21 PDT 2017


flowerhack created this revision.
Herald added a subscriber: kubamracek.

The scudo allocator also uses MmapNoACcess; thus, we need to allow
it to create new VMARs rather than check-failing upon being called.


https://reviews.llvm.org/D36803

Files:
  lib/sanitizer_common/sanitizer_fuchsia.cc


Index: lib/sanitizer_common/sanitizer_fuchsia.cc
===================================================================
--- lib/sanitizer_common/sanitizer_fuchsia.cc
+++ lib/sanitizer_common/sanitizer_fuchsia.cc
@@ -232,18 +232,27 @@
   return DoAnonymousMmapOrDie(size, mem_type, false, false);
 }
 
-// MmapNoAccess and MmapFixedOrDie are used only by sanitizer_allocator.
-// Instead of doing exactly what they say, we make MmapNoAccess actually
-// just allocate a VMAR to reserve the address space.  Then MmapFixedOrDie
-// uses that VMAR instead of the root.
+// MmapNoAccess and MmapFixedOrDie are used only by sanitizer_allocator
+// and scudo_allocator. Instead of doing exactly what they say, we make
+// MmapNoAccess actually just allocate a VMAR to reserve the address space.
+// Then MmapFixedOrDie uses that VMAR instead of the root.
+// TODO: Refactor this API to give callers precisely what they need.
+// In this case, scudo_allocator is using MmapNoAccess+MmapFixed to get a
+// single mapping with guard ranges around it, whereas the sanitizer
+// allocator is doing a large allocation and then doling out portions of
+// that range. These needs can probably be better managed.
 
 mx_handle_t allocator_vmar = MX_HANDLE_INVALID;
 uintptr_t allocator_vmar_base;
 size_t allocator_vmar_size;
 
 void *MmapNoAccess(uptr size) {
   size = RoundUpTo(size, PAGE_SIZE);
-  CHECK_EQ(allocator_vmar, MX_HANDLE_INVALID);
+  if (allocator_vmar != MX_HANDLE_INVALID) {
+      _mx_handle_close(allocator_vmar);
+      allocator_vmar = MX_HANDLE_INVALID;
+      allocator_vmar_base = 0;
+      allocator_vmar_size = 0;
   uintptr_t base;
   mx_status_t status =
       _mx_vmar_allocate(_mx_vmar_root_self(), 0, size,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36803.111391.patch
Type: text/x-patch
Size: 1720 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170816/50a96291/attachment.bin>


More information about the llvm-commits mailing list