Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s |
| 2 | #include <stdint.h> |
| 3 | #include <stdio.h> |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 4 | #include <errno.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | #include <sys/mman.h> |
| 6 | |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 7 | #if defined(__FreeBSD__) |
| 8 | // The MAP_NORESERVE define has been removed in FreeBSD 11.x, and even before |
| 9 | // that, it was never implemented. So just define it to zero. |
| 10 | #undef MAP_NORESERVE |
| 11 | #define MAP_NORESERVE 0 |
| 12 | #endif |
| 13 | |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 14 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 15 | #ifdef __x86_64__ |
| 16 | const size_t kLog2Size = 39; |
| 17 | #elif defined(__mips64) |
| 18 | const size_t kLog2Size = 32; |
| 19 | #endif |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 20 | const uintptr_t kLocation = 0x40ULL << kLog2Size; |
| 21 | void *p = mmap( |
| 22 | reinterpret_cast<void*>(kLocation), |
| 23 | 1ULL << kLog2Size, |
| 24 | PROT_READ|PROT_WRITE, |
| 25 | MAP_PRIVATE|MAP_ANONYMOUS|MAP_NORESERVE, |
| 26 | -1, 0); |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 27 | fprintf(stderr, "DONE %p %d\n", p, errno); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 28 | return p == MAP_FAILED; |
| 29 | } |
| 30 | |
| 31 | // CHECK: DONE |