diff options
author | Fangrui Song <maskray@google.com> | 2019-08-02 06:07:05 +0000 |
---|---|---|
committer | Fangrui Song <maskray@google.com> | 2019-08-02 06:07:05 +0000 |
commit | d21b3d346af2f6189638d853182e389555e7ccb9 (patch) | |
tree | ef89086fd1492736105e73e06b3623df3b01df45 /compiler-rt/test/msan/allocator_mapping.cpp | |
parent | 6db8c59f210af60d882f7aedc7c9dc95d41d9696 (diff) | |
download | bcm5719-llvm-d21b3d346af2f6189638d853182e389555e7ccb9.tar.gz bcm5719-llvm-d21b3d346af2f6189638d853182e389555e7ccb9.zip |
compiler-rt: Rename .cc file in test/msan to .cpp
Like r367463, but for test/msan.
llvm-svn: 367653
Diffstat (limited to 'compiler-rt/test/msan/allocator_mapping.cpp')
-rw-r--r-- | compiler-rt/test/msan/allocator_mapping.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/compiler-rt/test/msan/allocator_mapping.cpp b/compiler-rt/test/msan/allocator_mapping.cpp new file mode 100644 index 00000000000..533128f9a0f --- /dev/null +++ b/compiler-rt/test/msan/allocator_mapping.cpp @@ -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: target-is-mips64,target-is-mips64el,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); +} |