1// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2
3// UNSUPPORTED: ios
4
5#include <stdint.h>
6#include <stdio.h>
7#include <errno.h>
8#include <sys/mman.h>
9
10#if defined(__FreeBSD__)
11// The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before
12// that, it was never implemented. So just define it to zero.
13#undef MAP_NORESERVE
14#define MAP_NORESERVE 0
15#endif
16
17int main() {
18#ifdef __x86_64__
19 const size_t kLog2Size = 39;
20#elif defined(__mips64) || defined(__aarch64__)
21 const size_t kLog2Size = 32;
22#elif defined(__powerpc64__)
23 const size_t kLog2Size = 39;
24#endif
25 const uintptr_t kLocation = 0x40ULL << kLog2Size;
26 void *p = mmap(
27 reinterpret_cast<void*>(kLocation),
28 1ULL << kLog2Size,
29 PROT_READ|PROT_WRITE,
30 MAP_PRIVATE|MAP_ANON|MAP_NORESERVE,
31 -1, 0);
32 fprintf(stderr, "DONE %p %d\n", p, errno);
33 return p == MAP_FAILED;
34}
35
36// CHECK: DONE
37