diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2020-08-05 01:11:38 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2020-08-05 01:11:38 +0000 |
commit | 7c7110cb7d60132b74aa9c0e048658075c803230 (patch) | |
tree | 5716dfc9cf52fc2e12bd3969df8c76f992c9fe27 | |
parent | 3e6a45d60d4090b9f462fd3efaa863cff684d361 (diff) | |
parent | 44f0faa247d9345bfd94472ee7d6b003f4c7864e (diff) | |
download | bionic-android11-d1-s1-release.tar.gz |
Snap for 6736502 from 44f0faa247d9345bfd94472ee7d6b003f4c7864e to rvc-d1-releaseandroid-11.0.0_r9android-11.0.0_r8android-11.0.0_r7android-11.0.0_r15android-11.0.0_r14android-11.0.0_r13android-11.0.0_r12android-11.0.0_r11android-11.0.0_r10android11-d1-s7-releaseandroid11-d1-s6-releaseandroid11-d1-s5-releaseandroid11-d1-s1-releaseandroid11-d1-release
Change-Id: I73806898e3de84ca433f5eb59f668ec4b501518b
-rw-r--r-- | libc/include/malloc.h | 22 | ||||
-rw-r--r-- | tests/malloc_test.cpp | 40 |
2 files changed, 62 insertions, 0 deletions
diff --git a/libc/include/malloc.h b/libc/include/malloc.h index ba0af3ca3..833fa59b5 100644 --- a/libc/include/malloc.h +++ b/libc/include/malloc.h @@ -170,6 +170,28 @@ int malloc_info(int __must_be_zero, FILE* __fp) __INTRODUCED_IN(23); * Available since API level 28. */ #define M_PURGE (-101) +/** + * mallopt() option to set the maximum number of items in the secondary + * cache of the scudo allocator. + * + * Available since API level 31. + */ +#define M_CACHE_COUNT_MAX (-200) +/** + * mallopt() option to set the maximum size in bytes of a cacheable item in + * the secondary cache of the scudo allocator. + * + * Available since API level 31. + */ +#define M_CACHE_SIZE_MAX (-201) +/** + * mallopt() option to increase the maximum number of shared thread-specific + * data structures that can be created. This number cannot be decreased, + * only increased and only applies to the scudo allocator. + * + * Available since API level 31. + */ +#define M_TSDS_COUNT_MAX (-202) /** * [mallopt(3)](http://man7.org/linux/man-pages/man3/mallopt.3.html) modifies diff --git a/tests/malloc_test.cpp b/tests/malloc_test.cpp index 594441487..bd0daddbd 100644 --- a/tests/malloc_test.cpp +++ b/tests/malloc_test.cpp @@ -662,6 +662,46 @@ TEST(malloc, mallopt_purge) { #endif } +#if defined(__BIONIC__) +static void GetAllocatorVersion(bool* allocator_scudo) { + TemporaryFile tf; + ASSERT_TRUE(tf.fd != -1); + FILE* fp = fdopen(tf.fd, "w+"); + tf.release(); + ASSERT_TRUE(fp != nullptr); + ASSERT_EQ(0, malloc_info(0, fp)); + ASSERT_EQ(0, fclose(fp)); + + std::string contents; + ASSERT_TRUE(android::base::ReadFileToString(tf.path, &contents)); + + tinyxml2::XMLDocument doc; + ASSERT_EQ(tinyxml2::XML_SUCCESS, doc.Parse(contents.c_str())); + + auto root = doc.FirstChildElement(); + ASSERT_NE(nullptr, root); + ASSERT_STREQ("malloc", root->Name()); + std::string version(root->Attribute("version")); + *allocator_scudo = (version == "scudo-1"); +} +#endif + +TEST(malloc, mallopt_scudo_only_options) { +#if defined(__BIONIC__) + SKIP_WITH_HWASAN << "hwasan does not implement mallopt"; + bool allocator_scudo; + GetAllocatorVersion(&allocator_scudo); + if (!allocator_scudo) { + GTEST_SKIP() << "scudo allocator only test"; + } + ASSERT_EQ(1, mallopt(M_CACHE_COUNT_MAX, 100)); + ASSERT_EQ(1, mallopt(M_CACHE_SIZE_MAX, 1024 * 1024 * 2)); + ASSERT_EQ(1, mallopt(M_TSDS_COUNT_MAX, 8)); +#else + GTEST_SKIP() << "bionic-only test"; +#endif +} + TEST(malloc, reallocarray_overflow) { #if HAVE_REALLOCARRAY // Values that cause overflow to a result small enough (8 on LP64) that malloc would "succeed". |