aboutsummaryrefslogtreecommitdiff
path: root/compiler-rt
diff options
context:
space:
mode:
authorJoshua Baehring <98630690+JoshuaMBa@users.noreply.github.com>2024-06-17 14:06:31 -0700
committerGitHub <noreply@github.com>2024-06-17 14:06:31 -0700
commit16aa39ad94350670f4d72dace0a4866fbe10d716 (patch)
treebd16311ecd5a8dba301ee73f2c052d4dd4074a0f /compiler-rt
parenta50bcc03cbaecf6473c6bf41f4497758a7876f3d (diff)
downloadllvm-16aa39ad94350670f4d72dace0a4866fbe10d716.zip
llvm-16aa39ad94350670f4d72dace0a4866fbe10d716.tar.gz
llvm-16aa39ad94350670f4d72dace0a4866fbe10d716.tar.bz2
[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.
Diffstat (limited to 'compiler-rt')
-rw-r--r--compiler-rt/lib/scudo/standalone/secondary.h7
-rw-r--r--compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp6
2 files changed, 7 insertions, 6 deletions
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index d8c9f5b..9a8e53b 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -391,10 +391,11 @@ public:
return true;
}
if (O == Option::MaxCacheEntriesCount) {
- const u32 MaxCount = static_cast<u32>(Value);
- if (MaxCount > Config::getEntriesArraySize())
+ if (Value < 0)
return false;
- atomic_store_relaxed(&MaxEntriesCount, MaxCount);
+ atomic_store_relaxed(
+ &MaxEntriesCount,
+ Min<u32>(static_cast<u32>(Value), Config::getEntriesArraySize()));
return true;
}
if (O == Option::MaxCacheEntrySize) {
diff --git a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
index 8f0250e..af69313 100644
--- a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
@@ -192,9 +192,9 @@ TEST_F(MapAllocatorTest, SecondaryIterate) {
TEST_F(MapAllocatorTest, SecondaryOptions) {
// Attempt to set a maximum number of entries higher than the array size.
- EXPECT_FALSE(
- Allocator->setOption(scudo::Option::MaxCacheEntriesCount, 4096U));
- // A negative number will be cast to a scudo::u32, and fail.
+ EXPECT_TRUE(Allocator->setOption(scudo::Option::MaxCacheEntriesCount, 4096U));
+
+ // Attempt to set an invalid (negative) number of entries
EXPECT_FALSE(Allocator->setOption(scudo::Option::MaxCacheEntriesCount, -1));
if (Allocator->canCache(0U)) {
// Various valid combinations.