[PATCH] D91615: [sanitizer_common] Don't try to unmap unaligned memory
Rainer Orth via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 17 04:35:49 PST 2020
ro created this revision.
ro added a reviewer: vitalybuka.
ro added a project: Sanitizers.
Herald added subscribers: Sanitizers, fedor.sergeev, jyknight.
ro requested review of this revision.
Enabling `sanitizer_common` tests on Solaris (D91606 <https://reviews.llvm.org/D91606>) and SPARC (D91608 <https://reviews.llvm.org/D91608>) uncovered a sparcv9 failure
SanitizerCommon-Unit :: ./Sanitizer-sparcv9-Test/CompactRingBuffer.int64
like this:
[ RUN ] CompactRingBuffer.int64
==24576==ERROR: SanitizerTool failed to deallocate 0x2000 (8192) bytes at address 0xffffffff7f59b000
==24576==Sanitizer CHECK failed: /vol/llvm/src/llvm-project/local/compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp:61 (("unable to unmap" && 0)) != (0) (0, 0)
The problemis that the original allocation via `MmapAlignedOrDieOnFatalError` is for 4 kB, but the Solaris/sparcv9 pagesize is 8 kB. So the initial allocation is for 12 kB, rounded to a multiple of the pagesize. Afterwards, the unneeded rest is unmapped again, but this fails since the address is not pagesize-aligned.
This patch avoids this by only unmapping correctly aligned memory.
The patch still `FAIL`s, but for a different reason, and this part of the issue is generic.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D91615
Files:
compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
Index: compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
===================================================================
--- compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
+++ compiler-rt/lib/sanitizer_common/sanitizer_posix.cpp
@@ -92,10 +92,11 @@
uptr res = map_res;
if (!IsAligned(res, alignment)) {
res = (map_res + alignment - 1) & ~(alignment - 1);
- UnmapOrDie((void*)map_res, res - map_res);
+ if (IsAligned(map_res, GetPageSizeCached()))
+ UnmapOrDie((void*)map_res, res - map_res);
}
uptr end = res + size;
- if (end != map_end)
+ if (end != map_end && IsAligned(end, GetPageSizeCached()))
UnmapOrDie((void*)end, map_end - end);
return (void*)res;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91615.305736.patch
Type: text/x-patch
Size: 712 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201117/ca9fe2bd/attachment.bin>
More information about the llvm-commits
mailing list