aboutsummaryrefslogtreecommitdiff
path: root/test/msan/allocator_mapping.cc
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
committerDimitry Andric <dim@FreeBSD.org>2015-12-30 11:52:19 +0000
commit5c909fa013fc285f010a95e8d387e0ef3412da9c (patch)
tree1059d068ad281f4776ff44cd414574f99a460023 /test/msan/allocator_mapping.cc
parentf31bcc68c72371a2bf63aead9f3373a1ff2053b6 (diff)
downloadsrc-5c909fa013fc285f010a95e8d387e0ef3412da9c.tar.gz
src-5c909fa013fc285f010a95e8d387e0ef3412da9c.zip
Vendor import of compiler-rt trunk r256633:vendor/compiler-rt/compiler-rt-trunk-r256633
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=292925 svn path=/vendor/compiler-rt/compiler-rt-trunk-r256633/; revision=292926; tag=vendor/compiler-rt/compiler-rt-trunk-r256633
Diffstat (limited to 'test/msan/allocator_mapping.cc')
-rw-r--r--test/msan/allocator_mapping.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/msan/allocator_mapping.cc b/test/msan/allocator_mapping.cc
new file mode 100644
index 000000000000..f47d9a63e09f
--- /dev/null
+++ b/test/msan/allocator_mapping.cc
@@ -0,0 +1,36 @@
+// Test that a module constructor can not map memory over the MSan heap
+// (without MAP_FIXED, of course). Current implementation ensures this by
+// mapping the heap early, in __msan_init.
+//
+// RUN: %clangxx_msan -O0 %s -o %t_1
+// RUN: %clangxx_msan -O0 -DHEAP_ADDRESS=$(%run %t_1) %s -o %t_2 && %run %t_2
+//
+// This test only makes sense for the 64-bit allocator. The 32-bit allocator
+// does not have a fixed mapping. Exclude platforms that use the 32-bit
+// allocator.
+// UNSUPPORTED: mips64,aarch64
+
+#include <assert.h>
+#include <stdio.h>
+#include <sys/mman.h>
+#include <stdlib.h>
+
+#ifdef HEAP_ADDRESS
+struct A {
+ A() {
+ void *const hint = reinterpret_cast<void *>(HEAP_ADDRESS);
+ void *p = mmap(hint, 4096, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+ // This address must be already mapped. Check that mmap() succeeds, but at a
+ // different address.
+ assert(p != reinterpret_cast<void *>(-1));
+ assert(p != hint);
+ }
+} a;
+#endif
+
+int main() {
+ void *p = malloc(10);
+ printf("0x%zx\n", reinterpret_cast<size_t>(p) & (~0xfff));
+ free(p);
+}