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