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 defined(__loongarch_lp64) || (defined(__riscv) && __riscv_xlen == 64)
22 const size_t kLog2Size = 32;
23#elif defined(__powerpc64__)
24 const size_t kLog2Size = 39;
25#elif defined(__s390x__)
26 const size_t kLog2Size = 43;
27#endif
28 const uintptr_t kLocation = 0x40ULL << kLog2Size;
29 void *p = mmap(
30 addr: reinterpret_cast<void*>(kLocation),
31 len: 1ULL << kLog2Size,
32 PROT_READ|PROT_WRITE,
33 MAP_PRIVATE|MAP_ANON|MAP_NORESERVE,
34 fd: -1, offset: 0);
35 fprintf(stderr, format: "DONE %p %d\n", p, errno);
36 return p == MAP_FAILED;
37}
38
39// CHECK: DONE
40

source code of compiler-rt/test/tsan/mmap_large.cpp