[PATCH] D41649: [scudo] Touch memory to count as RSS

Jonas Hahnfeld via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Dec 31 15:53:16 PST 2017


Hahnfeld created this revision.
Hahnfeld added reviewers: cryptoad, alekseyshl.
Herald added subscribers: Sanitizers, llvm-commits.

This should fix the test from https://reviews.llvm.org/D41128.


Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D41649

Files:
  test/scudo/interface.cpp


Index: test/scudo/interface.cpp
===================================================================
--- test/scudo/interface.cpp
+++ test/scudo/interface.cpp
@@ -4,7 +4,6 @@
 // RUN:                                                   %run %t heap-size          2>&1
 // RUN: %env_scudo_opts="allocator_may_return_null=1"     %run %t soft-limit         2>&1
 // RUN: %env_scudo_opts="allocator_may_return_null=1" not %run %t hard-limit         2>&1
-// UNSUPPORTED: armhf-linux
 
 // Tests that the sanitizer interface functions behave appropriately.
 
@@ -18,6 +17,17 @@
 #include <sanitizer/allocator_interface.h>
 #include <sanitizer/scudo_interface.h>
 
+static void touch(void *m, size_t size) {
+  long *p = (long *)m;
+  long *e = (long *)((char *)m + size - sizeof(long));
+  // We don't care if size is a multiple of sizeof(long), just touch as many
+  // pages as possible and stay in the memory area...
+  while (p <= e) {
+    *p = 0;
+    p++;
+  }
+}
+
 int main(int argc, char **argv)
 {
   assert(argc == 2);
@@ -51,8 +61,11 @@
     // Verifies that setting the soft RSS limit at runtime works as expected.
     std::vector<void *> pointers;
     size_t size = 1 << 19;  // 512Kb
-    for (int i = 0; i < 5; i++)
-      pointers.push_back(malloc(size));
+    for (int i = 0; i < 5; i++) {
+      void *m = malloc(size);
+      touch(m, size);
+      pointers.push_back(m);
+    }
     // Set the soft RSS limit to 1Mb.
     __scudo_set_rss_limit(1, 0);
     usleep(20000);
@@ -74,8 +87,11 @@
     // Verifies that setting the hard RSS limit at runtime works as expected.
     std::vector<void *> pointers;
     size_t size = 1 << 19;  // 512Kb
-    for (int i = 0; i < 5; i++)
-      pointers.push_back(malloc(size));
+    for (int i = 0; i < 5; i++) {
+      void *m = malloc(size);
+      touch(m, size);
+      pointers.push_back(m);
+    }
     // Set the hard RSS limit to 1Mb
     __scudo_set_rss_limit(1, 1);
     usleep(20000);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D41649.128376.patch
Type: text/x-patch
Size: 1950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171231/116674d6/attachment.bin>


More information about the llvm-commits mailing list