[compiler-rt] f14472a - [scudo][standalone] Add new mallopt options.
Kostya Kortchinsky via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 28 16:28:46 PDT 2020
Author: Christopher Ferris
Date: 2020-07-28T16:28:16-07:00
New Revision: f14472a2e327a393d4795a141b901be1dd397505
URL: https://github.com/llvm/llvm-project/commit/f14472a2e327a393d4795a141b901be1dd397505
DIFF: https://github.com/llvm/llvm-project/commit/f14472a2e327a393d4795a141b901be1dd397505.diff
LOG: [scudo][standalone] Add new mallopt options.
This adds the code to support calling mallopt and converting the
options to the internal Option enum.
Reviewed By: cryptoad
Differential Revision: https://reviews.llvm.org/D84806
Added:
Modified:
compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
compiler-rt/lib/scudo/standalone/wrappers_c.inc
Removed:
################################################################################
diff --git a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
index ed5b64c20336..3ddc4ec81832 100644
--- a/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/wrappers_c_test.cpp
@@ -202,6 +202,12 @@ TEST(ScudoWrappersCTest, MallOpt) {
EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
EXPECT_EQ(mallopt(M_DECAY_TIME, 1), 1);
EXPECT_EQ(mallopt(M_DECAY_TIME, 0), 1);
+
+ if (SCUDO_ANDROID) {
+ 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
diff --git a/compiler-rt/lib/scudo/standalone/wrappers_c.inc b/compiler-rt/lib/scudo/standalone/wrappers_c.inc
index da5a170569d7..b25135b1ce1b 100644
--- a/compiler-rt/lib/scudo/standalone/wrappers_c.inc
+++ b/compiler-rt/lib/scudo/standalone/wrappers_c.inc
@@ -155,7 +155,7 @@ void SCUDO_PREFIX(malloc_postinit)() {
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 @@ INTERFACE WEAK int SCUDO_PREFIX(mallopt)(int param, UNUSED int value) {
} 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 {
+ scudo::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,
More information about the llvm-commits
mailing list