[PATCH] D52242: [sanitizer] Destroy and close a range's vmar if all its memory was unmapped
Kostya Kortchinsky via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 18 12:42:30 PDT 2018
cryptoad updated this revision to Diff 166020.
cryptoad marked an inline comment as done.
cryptoad added a comment.
Skip the `UnmapOrDieVmar` call when unmapping the whole mapping, as
`vmar_destroy` will take care of this. We still have to do some bookkeeping
via `DecreaseTotalMmap`.
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,23 @@
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_) {
+ // Unmap the whole mapping by destroying and closing the vmar.
+ _zx_vmar_destroy(vmar);
+ _zx_handle_close(vmar);
+ os_handle_ = static_cast<uptr>(ZX_HANDLE_INVALID);
+ DecreaseTotalMmap(size);
+ return;
+ } else {
+ base_ = reinterpret_cast<void*>(addr + size);
+ }
+ } 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_));
+ UnmapOrDieVmar(reinterpret_cast<void *>(addr), size, vmar);
}
// This should never be called.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52242.166020.patch
Type: text/x-patch
Size: 1278 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180918/d06106ad/attachment.bin>
More information about the llvm-commits
mailing list