brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 6eaba7e Raw
38 lines · cpp
1// Test that a module constructor can not map memory over the MSan heap2// (without MAP_FIXED, of course). Current implementation ensures this by3// mapping the heap early, in __msan_init.4//5// RUN: %clangxx_msan -O0 %s -o %t_16// RUN: %run %t_1 > %t.heap_address7// RUN: %clangxx_msan -O0 -DHEAP_ADDRESS=%{readfile:%t.heap_address} %s -o %t_2 && %run %t_28//9// This test only makes sense for the 64-bit allocator. The 32-bit allocator10// does not have a fixed mapping. Exclude platforms that use the 32-bit11// allocator.12// UNSUPPORTED: target-is-mips64,target-is-mips64el,target=aarch64{{.*}}13 14#include <assert.h>15#include <stdio.h>16#include <sys/mman.h>17#include <stdlib.h>18 19#ifdef HEAP_ADDRESS20struct A {21  A() {22    void *const hint = reinterpret_cast<void *>(HEAP_ADDRESS);23    void *p = mmap(hint, 4096, PROT_READ | PROT_WRITE,24                   MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);25    // This address must be already mapped. Check that mmap() succeeds, but at a26    // different address.27    assert(p != reinterpret_cast<void *>(-1));28    assert(p != hint);29  }30} a;31#endif32 33int main() {34  void *p = malloc(10);35  printf("0x%zx\n", reinterpret_cast<size_t>(p) & (~0xfff));36  free(p);37}38