-
Notifications
You must be signed in to change notification settings - Fork 11.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[scudo] Update error handling for secondary cache entry count #95595
Conversation
…e option handler. 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.
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write If you have received no comments on your PR for a week, you can request a review If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Joshua Baehring (JoshuaMBa) Changes…e option handler. 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. Full diff: https://github.com/llvm/llvm-project/pull/95595.diff 2 Files Affected:
diff --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index d8c9f5bcfcaf6..0e0788f830431 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -391,10 +391,10 @@ template <typename Config> class MapAllocatorCache {
return true;
}
if (O == Option::MaxCacheEntriesCount) {
- const u32 MaxCount = static_cast<u32>(Value);
- if (MaxCount > Config::getEntriesArraySize())
- return false;
- atomic_store_relaxed(&MaxEntriesCount, MaxCount);
+ if (Value < 0) return false;
+ 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 8f0250e88ebf3..af69313214ea6 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.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@JoshuaMBa Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested Please check whether problems have been caused by your change specifically, as How to do this, and the rest of the post-merge process, is covered in detail here. If your change does cause a problem, it may be reverted, or you can revert it yourself. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! |
Configs that use `MapAllocatorNoCache` for its secondary cache will return `false` if `setOption` is called with some [specific options](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/secondary.h#L104), and this breaks with the `SecondaryOptions` test. This change will gate testing all `setOption` expectations for cache options only if the allocator cache is enabled. This will unblock [github.com//pull/95595 ](#95595) from merging into Fuchsia.
Configs that use `MapAllocatorNoCache` for its secondary cache will return `false` if `setOption` is called with some [specific options](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/secondary.h#L104), and this breaks with the `SecondaryOptions` test. This change will gate testing all `setOption` expectations for cache options only if the allocator cache is enabled. This will unblock [github.com/llvm/llvm-project/pull/95595 ](llvm/llvm-project#95595) from merging into Fuchsia. GitOrigin-RevId: 6f13f0b3fe57d2f59b8d456446fe87f3fef686d0 Change-Id: I3751320a700d1b4ac629cd7901f5bc51f3f47f2f
Configs that use `MapAllocatorNoCache` for its secondary cache will return `false` if `setOption` is called with some [specific options](https://github.com/llvm/llvm-project/blob/main/compiler-rt/lib/scudo/standalone/secondary.h#L104), and this breaks with the `SecondaryOptions` test. This change will gate testing all `setOption` expectations for cache options only if the allocator cache is enabled. This will unblock [github.com/llvm/pull/95595 ](llvm#95595) from merging into Fuchsia.
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.