[compiler-rt] 1fb6a03 - [scudo] Add unmapTestOnly() to secondary.

Mitch Phillips via llvm-commits llvm-commits at lists.llvm.org
Mon May 24 16:15:37 PDT 2021


Author: Mitch Phillips
Date: 2021-05-24T16:09:02-07:00
New Revision: 1fb6a0307240b0c543ec5babb35e39db2c39052b

URL: https://github.com/llvm/llvm-project/commit/1fb6a0307240b0c543ec5babb35e39db2c39052b
DIFF: https://github.com/llvm/llvm-project/commit/1fb6a0307240b0c543ec5babb35e39db2c39052b.diff

LOG: [scudo] Add unmapTestOnly() to secondary.

When trying to track down a vaddr-poisoning bug, I found that that the
secondary cache isn't emptied on test teardown. We should probably do
that to make the tests hermetic. Otherwise, repeating the tests lots of
times using --gtest_repeat fails after the mmap vaddr space is
exhausted.

To repro:
$ ninja check-scudo_standalone # build
$ ./projects/compiler-rt/lib/scudo/standalone/tests/ScudoUnitTest-x86_64-Test \
--gtest_filter=ScudoSecondaryTest.*:-ScudoSecondaryTest.SecondaryCombinations \
--gtest_repeat=10000

Reviewed By: cryptoad

Differential Revision: https://reviews.llvm.org/D102874

Added: 
    

Modified: 
    compiler-rt/lib/scudo/standalone/combined.h
    compiler-rt/lib/scudo/standalone/secondary.h
    compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp

Removed: 
    


################################################################################
diff  --git a/compiler-rt/lib/scudo/standalone/combined.h b/compiler-rt/lib/scudo/standalone/combined.h
index 8080d677d7be..f17c371af825 100644
--- a/compiler-rt/lib/scudo/standalone/combined.h
+++ b/compiler-rt/lib/scudo/standalone/combined.h
@@ -215,6 +215,7 @@ class Allocator {
   void unmapTestOnly() {
     TSDRegistry.unmapTestOnly();
     Primary.unmapTestOnly();
+    Secondary.unmapTestOnly();
 #ifdef GWP_ASAN_HOOKS
     if (getFlags()->GWP_ASAN_InstallSignalHandlers)
       gwp_asan::segv_handler::uninstallSignalHandlers();

diff  --git a/compiler-rt/lib/scudo/standalone/secondary.h b/compiler-rt/lib/scudo/standalone/secondary.h
index 77db873375a8..3894b01c0a4f 100644
--- a/compiler-rt/lib/scudo/standalone/secondary.h
+++ b/compiler-rt/lib/scudo/standalone/secondary.h
@@ -83,6 +83,7 @@ class MapAllocatorNoCache {
   void enable() {}
   void releaseToOS() {}
   void disableMemoryTagging() {}
+  void unmapTestOnly() {}
   bool setOption(Option O, UNUSED sptr Value) {
     if (O == Option::ReleaseInterval || O == Option::MaxCacheEntriesCount ||
         O == Option::MaxCacheEntrySize)
@@ -326,6 +327,8 @@ template <typename Config> class MapAllocatorCache {
 
   void enable() { Mutex.unlock(); }
 
+  void unmapTestOnly() { empty(); }
+
 private:
   void empty() {
     struct {
@@ -456,6 +459,8 @@ template <typename Config> class MapAllocator {
 
   void disableMemoryTagging() { Cache.disableMemoryTagging(); }
 
+  void unmapTestOnly() { Cache.unmapTestOnly(); }
+
 private:
   typename Config::SecondaryCache Cache;
 

diff  --git a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
index c50101a6d535..2320a4d546ab 100644
--- a/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
+++ b/compiler-rt/lib/scudo/standalone/tests/secondary_test.cpp
@@ -67,6 +67,7 @@ template <typename Config> static void testSecondaryBasic(void) {
   scudo::ScopedString Str(1024);
   L->getStats(&Str);
   Str.output();
+  L->unmapTestOnly();
 }
 
 struct NoCacheConfig {
@@ -124,6 +125,7 @@ TEST(ScudoSecondaryTest, SecondaryCombinations) {
   scudo::ScopedString Str(1024);
   L->getStats(&Str);
   Str.output();
+  L->unmapTestOnly();
 }
 
 TEST(ScudoSecondaryTest, SecondaryIterate) {
@@ -147,6 +149,7 @@ TEST(ScudoSecondaryTest, SecondaryIterate) {
   scudo::ScopedString Str(1024);
   L->getStats(&Str);
   Str.output();
+  L->unmapTestOnly();
 }
 
 TEST(ScudoSecondaryTest, SecondaryOptions) {
@@ -170,6 +173,7 @@ TEST(ScudoSecondaryTest, SecondaryOptions) {
     EXPECT_TRUE(L->setOption(scudo::Option::MaxCacheEntrySize, 1UL << 20));
     EXPECT_TRUE(L->canCache(1UL << 16));
   }
+  L->unmapTestOnly();
 }
 
 static std::mutex Mutex;
@@ -216,4 +220,5 @@ TEST(ScudoSecondaryTest, SecondaryThreadsRace) {
   scudo::ScopedString Str(1024);
   L->getStats(&Str);
   Str.output();
+  L->unmapTestOnly();
 }


        


More information about the llvm-commits mailing list