[scudo] Fix size of MaxNumCachedHint Trusty Config
Also add a test for TrustyConfig to ensure it'll be awared of any scudo
configuration change.
Differential Revision: https://reviews.llvm.org/D136732
GitOrigin-RevId: 4383aa0336e6edbb1a284849aa1c24e5111d975c
diff --git a/lib/scudo/standalone/size_class_map.h b/lib/scudo/standalone/size_class_map.h
index cc369ff..7665624 100644
--- a/lib/scudo/standalone/size_class_map.h
+++ b/lib/scudo/standalone/size_class_map.h
@@ -318,7 +318,7 @@
static const uptr MinSizeLog = 7;
static const uptr MidSizeLog = 7;
static const uptr MaxSizeLog = 7;
- static const u16 MaxNumCachedHint = 8;
+ static const u16 MaxNumCachedHint = 12;
static const uptr MaxBytesCachedLog = 10;
static const uptr SizeDelta = 0;
};
diff --git a/lib/scudo/standalone/tests/combined_test.cpp b/lib/scudo/standalone/tests/combined_test.cpp
index a0c48b0..41c91b3 100644
--- a/lib/scudo/standalone/tests/combined_test.cpp
+++ b/lib/scudo/standalone/tests/combined_test.cpp
@@ -10,6 +10,7 @@
#include "tests/scudo_unit_test.h"
#include "allocator_config.h"
+#include "chunk.h"
#include "combined.h"
#include <condition_variable>
@@ -700,3 +701,33 @@
Allocator->deallocate(Ptrs[i], Origin);
}
}
+
+#if SCUDO_CAN_USE_PRIMARY64
+#if SCUDO_TRUSTY
+
+// TrustyConfig is designed for a domain-specific allocator. Add a basic test
+// which covers only simple operations and ensure the configuration is able to
+// compile.
+TEST(ScudoCombinedTest, BasicTrustyConfig) {
+ using AllocatorT = scudo::Allocator<scudo::TrustyConfig>;
+ auto Allocator = std::unique_ptr<AllocatorT>(new AllocatorT());
+
+ for (scudo::uptr ClassId = 1U;
+ ClassId <= scudo::TrustyConfig::SizeClassMap::LargestClassId;
+ ClassId++) {
+ const scudo::uptr Size =
+ scudo::TrustyConfig::SizeClassMap::getSizeByClassId(ClassId);
+ void *p = Allocator->allocate(Size - scudo::Chunk::getHeaderSize(), Origin);
+ ASSERT_NE(p, nullptr);
+ free(p);
+ }
+
+ bool UnlockRequired;
+ auto *TSD = Allocator->getTSDRegistry()->getTSDAndLock(&UnlockRequired);
+ TSD->Cache.drain();
+
+ Allocator->releaseToOS();
+}
+
+#endif
+#endif