brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.1 KiB · 02220cb Raw
34 lines · c
1// RUN: %clang %s -pie -fPIE -o %t && %run %t2// REQUIRES: x86_64-target-arch3 4// FIXME: Fails Asan, as expected, with 5lvl page tables.5// UNSUPPORTED: x86_64-target-arch6 7#include <assert.h>8#include <stdio.h>9#include <sys/mman.h>10 11int main() {12    for (int j = 0; j < 1024; j++) {13        // Try 1TB offsets. This attempts to find memory addresses where the14        // shadow mappings - which assume a 47-bit address space - are invalid.15        unsigned long long target = (1ULL << 56) - (2 * 4096) - (j * (1ULL << 40));16 17        // Since we don't use MAP_FIXED, mmap might return an address that is18        // lower in the address space (due to sanitizer and/or kernel limits).19        // That is fine - if the app is also restricted from making high20        // allocations, then they are safe.21        char* ptr = (char*) mmap ((void*) target, 4096, PROT_READ | PROT_WRITE,22                                  MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);23        printf ("Allocated at %p\n", ptr);24 25        assert (ptr != MAP_FAILED);26        for (int i = 0; i < 100; i++) {27            ptr [i] = 0;28        }29        munmap (ptr, 4096);30    }31 32    return 0;33}34