[PATCH] D93437: scudo: Adjust test to use correct check for primary allocations.
Peter Collingbourne via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 16 17:48:32 PST 2020
pcc created this revision.
pcc added reviewers: cryptoad, eugenis, hctim.
pcc requested review of this revision.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.
canAllocate() does not take into account the header size so it does
not return the right answer in borderline cases. There was already
code handling this correctly in isTaggedAllocation() so split it out
into a separate function and call it from the test.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D93437
Files:
compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
Index: compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
@@ -34,12 +34,7 @@
}
template <class AllocatorT>
-bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr Size,
- scudo::uptr Alignment) {
- if (!Allocator->useMemoryTagging() ||
- !scudo::systemDetectsMemoryTagFaultsTestOnly())
- return false;
-
+bool isPrimaryAllocation(scudo::uptr Size, scudo::uptr Alignment) {
const scudo::uptr MinAlignment = 1UL << SCUDO_MIN_ALIGNMENT_LOG;
if (Alignment < MinAlignment)
Alignment = MinAlignment;
@@ -49,6 +44,14 @@
return AllocatorT::PrimaryT::canAllocate(NeededSize);
}
+template <class AllocatorT>
+bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr Size,
+ scudo::uptr Alignment) {
+ return Allocator->useMemoryTagging() &&
+ scudo::systemDetectsMemoryTagFaultsTestOnly() &&
+ isPrimaryAllocation<AllocatorT>(Size, Alignment);
+}
+
template <class AllocatorT>
void checkMemoryTaggingMaybe(AllocatorT *Allocator, void *P, scudo::uptr Size,
scudo::uptr Alignment) {
@@ -158,7 +161,7 @@
EXPECT_NE(P, nullptr);
for (scudo::uptr I = 0; I < Size; I++) {
unsigned char V = (reinterpret_cast<unsigned char *>(P))[I];
- if (AllocatorT::PrimaryT::canAllocate(Size))
+ if (isPrimaryAllocation<AllocatorT>(Size, 1U << MinAlignLog))
ASSERT_EQ(V, scudo::PatternFillByte);
else
ASSERT_TRUE(V == scudo::PatternFillByte || V == 0);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D93437.312351.patch
Type: text/x-patch
Size: 1717 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201217/bf16cf36/attachment.bin>
More information about the llvm-commits
mailing list