[PATCH] D84806: [scudo][standalone] Add new mallopt options.

Christopher Ferris via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jul 28 15:05:08 PDT 2020


cferris created this revision.
cferris added a reviewer: cryptoad.
Herald added a project: Sanitizers.
Herald added a subscriber: Sanitizers.
cferris requested review of this revision.

This adds the code to support calling mallopt and converting the
options to the internal Option enum.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D84806

Files:
  compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
  compiler-rt/lib/scudo/standalone/wrappers_c.inc


Index: compiler-rt/lib/scudo/standalone/wrappers_c.inc
===================================================================
--- compiler-rt/lib/scudo/standalone/wrappers_c.inc
+++ compiler-rt/lib/scudo/standalone/wrappers_c.inc
@@ -155,7 +155,7 @@
                  SCUDO_PREFIX(malloc_enable));
 }
 
-INTERFACE WEAK int SCUDO_PREFIX(mallopt)(int param, UNUSED int value) {
+INTERFACE WEAK int SCUDO_PREFIX(mallopt)(int param, int value) {
   if (param == M_DECAY_TIME) {
     if (SCUDO_ANDROID) {
       if (value == 0) {
@@ -173,11 +173,26 @@
   } else if (param == M_PURGE) {
     SCUDO_ALLOCATOR.releaseToOS();
     return 1;
-  } else if (param == M_MEMTAG_TUNING) {
-    return SCUDO_ALLOCATOR.setOption(scudo::Option::MemtagTuning,
-                                     static_cast<scudo::sptr>(value));
+  } else {
+    enum Option option;
+    switch (param) {
+    case M_MEMTAG_TUNING:
+      option = scudo::Option::MemtagTuning;
+      break;
+    case M_CACHE_COUNT_MAX:
+      option = scudo::Option::MaxCacheEntriesCount;
+      break;
+    case M_CACHE_SIZE_MAX:
+      option = scudo::Option::MaxCacheEntrySize;
+      break;
+    case M_TSDS_COUNT_MAX:
+      option = scudo::Option::MaxTSDsCount;
+      break;
+    default:
+      return 0;
+    }
+    return SCUDO_ALLOCATOR.setOption(option, static_cast<scudo::sptr>(value));
   }
-  return 0;
 }
 
 INTERFACE WEAK void *SCUDO_PREFIX(aligned_alloc)(size_t alignment,
Index: compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
===================================================================
--- compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -202,6 +202,10 @@
   EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
   EXPECT_EQ(mallopt(M_DECAY_TIME, 1), 1);
   EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
+
+  EXPECT_EQ(mallopt(M_CACHE_COUNT_MAX, 100), 1);
+  EXPECT_EQ(mallopt(M_CACHE_SIZE_MAX, 1024 * 1024 * 2), 1);
+  EXPECT_EQ(mallopt(M_TSDS_COUNT_MAX, 10), 1);
 }
 #endif
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D84806.281375.patch
Type: text/x-patch
Size: 2023 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200728/6dfd50a0/attachment.bin>


More information about the llvm-commits mailing list