[compiler-rt] 4383aa0 - [scudo] Fix size of MaxNumCachedHint Trusty Config

Chia-hung Duan via llvm-commits llvm-commits at lists.llvm.org
Wed Oct 26 11:16:56 PDT 2022


Author: Chia-hung Duan
Date: 2022-10-26T18:07:22Z
New Revision: 4383aa0336e6edbb1a284849aa1c24e5111d975c

URL: https://github.com/llvm/llvm-project/commit/4383aa0336e6edbb1a284849aa1c24e5111d975c
DIFF: https://github.com/llvm/llvm-project/commit/4383aa0336e6edbb1a284849aa1c24e5111d975c.diff

LOG: [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

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/size_class_map.h
    compiler-rt/lib/scudo/standalone/tests/combined_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/size_class_map.h b/compiler-rt/lib/scudo/standalone/size_class_map.h
index cc369ff5797fa..766562495ec7a 100644
--- a/compiler-rt/lib/scudo/standalone/size_class_map.h
+++ b/compiler-rt/lib/scudo/standalone/size_class_map.h
@@ -318,7 +318,7 @@ struct TrustySizeClassConfig {
   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/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp b/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
index a0c48b0cdfa85..41c91b3e1f125 100644
--- a/compiler-rt/lib/scudo/standalone/tests/combined_test.cpp
+++ b/compiler-rt/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 @@ SCUDO_TYPED_TEST(ScudoCombinedTest, ReallocateInPlaceStress) {
       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


        


More information about the llvm-commits mailing list