Skip to content

Commit 16aa39a

Browse files
authored
[scudo] Update error handling for seondary cache entry count (#95595)
Initially, the scudo allocator would return an error if the user attempted to set the cache capacity (i.e. the number of possible entries in the cache) above the maximum cache capacity. Now the allocator will resort to using the maximum cache capacity in this event. An error will still be returned if the user attempts to set the number of entries to a negative value.
1 parent a50bcc0 commit 16aa39a

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

compiler-rt/lib/scudo/standalone/secondary.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,10 +391,11 @@ template <typename Config> class MapAllocatorCache {
391391
return true;
392392
}
393393
if (O == Option::MaxCacheEntriesCount) {
394-
const u32 MaxCount = static_cast<u32>(Value);
395-
if (MaxCount > Config::getEntriesArraySize())
394+
if (Value < 0)
396395
return false;
397-
atomic_store_relaxed(&MaxEntriesCount, MaxCount);
396+
atomic_store_relaxed(
397+
&MaxEntriesCount,
398+
Min<u32>(static_cast<u32>(Value), Config::getEntriesArraySize()));
398399
return true;
399400
}
400401
if (O == Option::MaxCacheEntrySize) {

compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -192,9 +192,9 @@ TEST_F(MapAllocatorTest, SecondaryIterate) {
192192

193193
TEST_F(MapAllocatorTest, SecondaryOptions) {
194194
// Attempt to set a maximum number of entries higher than the array size.
195-
EXPECT_FALSE(
196-
Allocator->setOption(scudo::Option::MaxCacheEntriesCount, 4096U));
197-
// A negative number will be cast to a scudo::u32, and fail.
195+
EXPECT_TRUE(Allocator->setOption(scudo::Option::MaxCacheEntriesCount, 4096U));
196+
197+
// Attempt to set an invalid (negative) number of entries
198198
EXPECT_FALSE(Allocator->setOption(scudo::Option::MaxCacheEntriesCount, -1));
199199
if (Allocator->canCache(0U)) {
200200
// Various valid combinations.

0 commit comments

Comments
 (0)