[PATCH] D52242: [sanitizer][fuchsia] Fix VMAR leak

Kostya Kortchinsky via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 19 12:51:59 PDT 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT342584: [sanitizer][fuchsia] Fix VMAR leak (authored by cryptoad, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52242?vs=166036&id=166171#toc

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D52242

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
@@ -277,14 +277,22 @@
 
 void ReservedAddressRange::Unmap(uptr addr, uptr size) {
   CHECK_LE(size, size_);
-  if (addr == reinterpret_cast<uptr>(base_))
-    // If we unmap the whole range, just null out the base.
-    base_ = (size == size_) ? nullptr : reinterpret_cast<void*>(addr + size);
-  else
+  const zx_handle_t vmar = static_cast<zx_handle_t>(os_handle_);
+  if (addr == reinterpret_cast<uptr>(base_)) {
+    if (size == size_) {
+      // Destroying the vmar effectively unmaps the whole mapping.
+      _zx_vmar_destroy(vmar);
+      _zx_handle_close(vmar);
+      os_handle_ = static_cast<uptr>(ZX_HANDLE_INVALID);
+      DecreaseTotalMmap(size);
+      return;
+    }
+  } else {
     CHECK_EQ(addr + size, reinterpret_cast<uptr>(base_) + size_);
-  size_ -= size;
-  UnmapOrDieVmar(reinterpret_cast<void *>(addr), size,
-                 static_cast<zx_handle_t>(os_handle_));
+  }
+  // Partial unmapping does not affect the fact that the initial range is still
+  // reserved, and the resulting unmapped memory can't be reused.
+  UnmapOrDieVmar(reinterpret_cast<void *>(addr), size, vmar);
 }
 
 // This should never be called.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52242.166171.patch
Type: text/x-patch
Size: 1357 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180919/542e61aa/attachment.bin>


More information about the llvm-commits mailing list