[compiler-rt] [scudo] Change tests that use setrlimit to cause mmap to fail. (PR #87004)

via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 16:09:52 PDT 2024


================
@@ -129,16 +129,30 @@ TEST(ScudoStringsTest, Padding) {
 }
 
 #if defined(__linux__)
+
+#include <sys/mman.h>
 #include <sys/resource.h>
 
 TEST(ScudoStringsTest, CapacityIncreaseFails) {
   scudo::ScopedString Str;
 
   rlimit Limit = {};
   EXPECT_EQ(0, getrlimit(RLIMIT_AS, &Limit));
+
   rlimit EmptyLimit = {.rlim_cur = 0, .rlim_max = Limit.rlim_max};
   EXPECT_EQ(0, setrlimit(RLIMIT_AS, &EmptyLimit));
 
+#if !SCUDO_ANDROID
+  // qemu does not honor the setrlimit, so verify before proceeding.
+  void *ptr = mmap(nullptr, 100, PROT_READ | PROT_WRITE,
+                   MAP_ANONYMOUS | MAP_PRIVATE, -1, 0);
+  if (ptr != MAP_FAILED) {
+    munmap(ptr, 100);
+    setrlimit(RLIMIT_AS, &Limit);
+    GTEST_SKIP() << "Limiting address space does not prevent mmap.";
+  }
----------------
ChiaHungDuan wrote:

Just a minor suggestion. I know this test is linux specific, but can we use MemMap interface instead? It may be more consistent while allocating pages through out the project. If you agree with this, we have to change the map size to be page aligned (MemMap requires that)

https://github.com/llvm/llvm-project/pull/87004


More information about the llvm-commits mailing list