summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDynamic Tools Team <dynamic-tools@google.com>2020-03-20 23:14:39 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-03-20 23:14:39 +0000
commitcf58978f4d6b5b512ba05193178c27f670343ec8 (patch)
tree4d332b77cd1bcd8d692c083b29306cd5e6a1ef15
parent9a371087149e3002a89e089d76744ef2dc3aa7dd (diff)
parent01727940b431ed42f6dbd79ac798f3b31b53050c (diff)
downloadscudo-cf58978f4d6b5b512ba05193178c27f670343ec8.tar.gz
Imported Scudo Standalone changes: am: 01727940b4
Change-Id: I2bf354ca12cfbab298eef417a60b854d9f7897b9
-rw-r--r--standalone/combined.h21
-rw-r--r--standalone/tests/combined_test.cpp31
2 files changed, 25 insertions, 27 deletions
diff --git a/standalone/combined.h b/standalone/combined.h
index 8456dc82d20..1aa93510d22 100644
--- a/standalone/combined.h
+++ b/standalone/combined.h
@@ -260,8 +260,8 @@ public:
}
DCHECK_LE(Size, NeededSize);
- void *Block;
- uptr ClassId;
+ void *Block = nullptr;
+ uptr ClassId = 0;
uptr SecondaryBlockEnd;
if (LIKELY(PrimaryT::canAllocate(NeededSize))) {
ClassId = SizeClassMap::getClassIdBySize(NeededSize);
@@ -273,20 +273,19 @@ public:
// is the region being full. In that event, retry once using the
// immediately larger class (except if the failing class was already the
// largest). This will waste some memory but will allow the application to
- // not fail.
- if (SCUDO_ANDROID) {
- if (UNLIKELY(!Block)) {
- if (ClassId < SizeClassMap::LargestClassId)
- Block = TSD->Cache.allocate(++ClassId);
- }
+ // not fail. If dealing with the largest class, fallback to the Secondary.
+ if (UNLIKELY(!Block)) {
+ if (ClassId < SizeClassMap::LargestClassId)
+ Block = TSD->Cache.allocate(++ClassId);
+ else
+ ClassId = 0;
}
if (UnlockRequired)
TSD->unlock();
- } else {
- ClassId = 0;
+ }
+ if (UNLIKELY(ClassId == 0))
Block = Secondary.allocate(NeededSize, Alignment, &SecondaryBlockEnd,
ZeroContents);
- }
if (UNLIKELY(!Block)) {
if (Options.MayReturnNull)
diff --git a/standalone/tests/combined_test.cpp b/standalone/tests/combined_test.cpp
index ce1b2824788..a6f29a2610e 100644
--- a/standalone/tests/combined_test.cpp
+++ b/standalone/tests/combined_test.cpp
@@ -417,7 +417,7 @@ TEST(ScudoCombinedTest, ReleaseToOS) {
Allocator->releaseToOS();
}
-// Verify that when a region gets full, Android will still manage to
+// Verify that when a region gets full, the allocator will still manage to
// fulfill the allocation through a larger size class.
TEST(ScudoCombinedTest, FullRegion) {
using AllocatorT = scudo::Allocator<DeathConfig>;
@@ -429,26 +429,25 @@ TEST(ScudoCombinedTest, FullRegion) {
Deleter);
Allocator->reset();
- const scudo::uptr Size = 1000U;
- const scudo::uptr MaxNumberOfChunks =
- (1U << DeathRegionSizeLog) /
- DeathConfig::DeathSizeClassMap::getSizeByClassId(1U);
- void *P;
std::vector<void *> V;
scudo::uptr FailedAllocationsCount = 0;
- for (scudo::uptr I = 0; I <= MaxNumberOfChunks; I++) {
- P = Allocator->allocate(Size, Origin);
- if (!P)
- FailedAllocationsCount++;
- else
- V.push_back(P);
+ for (scudo::uptr ClassId = 1U;
+ ClassId <= DeathConfig::DeathSizeClassMap::LargestClassId; ClassId++) {
+ const scudo::uptr Size =
+ DeathConfig::DeathSizeClassMap::getSizeByClassId(ClassId);
+ const scudo::uptr MaxNumberOfChunks = (1U << DeathRegionSizeLog) / Size;
+ void *P;
+ for (scudo::uptr I = 0; I <= MaxNumberOfChunks; I++) {
+ P = Allocator->allocate(Size - 64U, Origin);
+ if (!P)
+ FailedAllocationsCount++;
+ else
+ V.push_back(P);
+ }
}
while (!V.empty()) {
Allocator->deallocate(V.back(), Origin);
V.pop_back();
}
- if (SCUDO_ANDROID)
- EXPECT_EQ(FailedAllocationsCount, 0U);
- else
- EXPECT_GT(FailedAllocationsCount, 0U);
+ EXPECT_EQ(FailedAllocationsCount, 0U);
}