summaryrefslogtreecommitdiff
path: root/lib/sanitizer_common/sanitizer_allocator_primary32.h
diff options
context:
space:
mode:
authorKostya Kortchinsky <kostyak@google.com>2017-06-30 16:05:40 +0000
committerKostya Kortchinsky <kostyak@google.com>2017-06-30 16:05:40 +0000
commit63de5fcd7287d033a1667de42831c293137e00e4 (patch)
tree9ed37f9dc6c6ac3b02a5e60f2f602266c363b6e3 /lib/sanitizer_common/sanitizer_allocator_primary32.h
parentcf40d9536af9ddc8da4f8d0a919cacc1a57888a5 (diff)
[sanitizer] Small tweaks and fixes to allocator related functions
Summary: In `sanitizer_allocator_primary32.h`: - rounding up in `MapWithCallback` is not needed as `MmapOrDie` does it. Note that the 64-bit counterpart doesn't round up, this keeps the behavior consistent; - since `IsAligned` exists, use it in `AllocateRegion`; - in `PopulateFreeList`: - checking `b->Count` to be greater than 0 when `b->Count() == max_count` is redundant when done more than once. Just check that `max_count` is greater than 0 out of the loop; the compiler (at least on ARM) didn't optimize it; - mark the batch creation failure as `UNLIKELY`; In `sanitizer_allocator_primary64.h`: - in `MapWithCallback`, mark the failure condition as `UNLIKELY`; In `sanitizer_posix.h`: - mark a bunch of Mmap related failure conditions as `UNLIKELY`; - in `MmapAlignedOrDieOnFatalError`, we have `IsAligned`, so use it; rearrange the conditions as one test was redudant; - in `MmapFixedImpl`, 30 chars was not large enough to hold the message and a full 64-bit address (or at least a 48-bit usermode address), increase to 40. Reviewers: alekseyshl Reviewed By: alekseyshl Subscribers: aemerson, kubamracek, kristof.beyls, llvm-commits Differential Revision: https://reviews.llvm.org/D34840 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@306834 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/sanitizer_common/sanitizer_allocator_primary32.h')
-rw-r--r--lib/sanitizer_common/sanitizer_allocator_primary32.h7
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/sanitizer_common/sanitizer_allocator_primary32.h b/lib/sanitizer_common/sanitizer_allocator_primary32.h
index d3949cc05..e85821543 100644
--- a/lib/sanitizer_common/sanitizer_allocator_primary32.h
+++ b/lib/sanitizer_common/sanitizer_allocator_primary32.h
@@ -118,7 +118,6 @@ class SizeClassAllocator32 {
}
void *MapWithCallback(uptr size) {
- size = RoundUpTo(size, GetPageSizeCached());
void *res = MmapOrDie(size, "SizeClassAllocator32");
MapUnmapCallback().OnMap((uptr)res, size);
return res;
@@ -285,7 +284,7 @@ class SizeClassAllocator32 {
return 0;
MapUnmapCallback().OnMap(res, kRegionSize);
stat->Add(AllocatorStatMapped, kRegionSize);
- CHECK_EQ(0U, (res & (kRegionSize - 1)));
+ CHECK(IsAligned(res, kRegionSize));
possible_regions.set(ComputeRegionId(res), static_cast<u8>(class_id));
return res;
}
@@ -303,17 +302,17 @@ class SizeClassAllocator32 {
return false;
uptr n_chunks = kRegionSize / (size + kMetadataSize);
uptr max_count = TransferBatch::MaxCached(class_id);
+ CHECK_GT(max_count, 0);
TransferBatch *b = nullptr;
for (uptr i = reg; i < reg + n_chunks * size; i += size) {
if (!b) {
b = c->CreateBatch(class_id, this, (TransferBatch*)i);
- if (!b)
+ if (UNLIKELY(!b))
return false;
b->Clear();
}
b->Add((void*)i);
if (b->Count() == max_count) {
- CHECK_GT(b->Count(), 0);
sci->free_list.push_back(b);
b = nullptr;
}