From: Peter Collingbourne Date: Wed, 16 Dec 2020 19:24:30 +0000 (-0800) Subject: scudo: Adjust test to use correct check for primary allocations. X-Git-Tag: llvmorg-13-init~3060 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e22d802e587b8954748e2b2193195a946ba105e8;p=platform%2Fupstream%2Fllvm.git scudo: Adjust test to use correct check for primary allocations. 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. Furthermore the test was incorrect when MTE is enabled because MTE does not pattern fill primary allocations. Fix it. Differential Revision: https://reviews.llvm.org/D93437 --- diff --git a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp index 7df4594..b0ab024 100644 --- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp +++ b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp @@ -34,12 +34,7 @@ UNUSED static void disableDebuggerdMaybe() { } template -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; @@ -50,6 +45,14 @@ bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr Size, } template +bool isTaggedAllocation(AllocatorT *Allocator, scudo::uptr Size, + scudo::uptr Alignment) { + return Allocator->useMemoryTagging() && + scudo::systemDetectsMemoryTagFaultsTestOnly() && + isPrimaryAllocation(Size, Alignment); +} + +template void checkMemoryTaggingMaybe(AllocatorT *Allocator, void *P, scudo::uptr Size, scudo::uptr Alignment) { if (!isTaggedAllocation(Allocator, Size, Alignment)) @@ -147,9 +150,9 @@ template static void testAllocator() { } Allocator->releaseToOS(); - // Ensure that specifying PatternOrZeroFill returns a pattern-filled block in - // the primary allocator, and either pattern or zero filled block in the - // secondary. + // Ensure that specifying PatternOrZeroFill returns a pattern or zero filled + // block. The primary allocator only produces pattern filled blocks if MTE + // is disabled, so we only require pattern filled blocks in that case. Allocator->setFillContents(scudo::PatternOrZeroFill); for (scudo::uptr SizeLog = 0U; SizeLog <= 20U; SizeLog++) { for (scudo::uptr Delta = 0U; Delta <= 4U; Delta++) { @@ -158,7 +161,8 @@ template static void testAllocator() { EXPECT_NE(P, nullptr); for (scudo::uptr I = 0; I < Size; I++) { unsigned char V = (reinterpret_cast(P))[I]; - if (AllocatorT::PrimaryT::canAllocate(Size)) + if (isPrimaryAllocation(Size, 1U << MinAlignLog) && + !Allocator->useMemoryTagging()) ASSERT_EQ(V, scudo::PatternFillByte); else ASSERT_TRUE(V == scudo::PatternFillByte || V == 0);